diff options
| author | sakumisu <[email protected]> | 2026-12-02 21:57:55 +0800 |
|---|---|---|
| committer | sakumisu <[email protected]> | 2026-12-02 21:57:55 +0800 |
| commit | 6a683fae2eb0f42b4f65174e9aae9bb1d5d42dce (patch) | |
| tree | 5023b1c0dfb845c14abf0953967f1de0ceaac6bd | |
| parent | b0c4569f29032a1e05e268d41155f79009c630b8 (diff) | |
update(port/ehci): support more frame binterval
Signed-off-by: sakumisu <[email protected]>
| -rw-r--r-- | port/ehci/usb_hc_ehci.c | 105 |
1 files changed, 68 insertions, 37 deletions
diff --git a/port/ehci/usb_hc_ehci.c b/port/ehci/usb_hc_ehci.c index be80dbf7..1e8300dd 100644 --- a/port/ehci/usb_hc_ehci.c +++ b/port/ehci/usb_hc_ehci.c @@ -26,6 +26,14 @@ int usbh_ehci_kill_urb(struct usbh_urb *urb); #define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */ #define EHCI_TUNE_MULT_TT 1 +#if CONFIG_USB_EHCI_FRAME_LIST_SIZE == 1024 +#define EHCI_PERIODIC_QH_NUM 11 +#elif CONFIG_USB_EHCI_FRAME_LIST_SIZE == 512 +#define EHCI_PERIODIC_QH_NUM 10 +#else +#define EHCI_PERIODIC_QH_NUM 9 +#endif + struct ehci_hcd g_ehci_hcd[CONFIG_USBHOST_MAX_BUS]; USB_NOCACHE_RAM_SECTION struct ehci_qh_hw ehci_qh_pool[CONFIG_USBHOST_MAX_BUS][CONFIG_USB_EHCI_QH_NUM]; @@ -34,7 +42,7 @@ USB_NOCACHE_RAM_SECTION struct ehci_qtd_hw ehci_qtd_pool[CONFIG_USBHOST_MAX_BUS] /* The head of the asynchronous queue */ USB_NOCACHE_RAM_SECTION struct ehci_qh_hw g_async_qh_head[CONFIG_USBHOST_MAX_BUS]; /* The head of the periodic queue */ -USB_NOCACHE_RAM_SECTION struct ehci_qh_hw g_periodic_qh_head[CONFIG_USBHOST_MAX_BUS]; +USB_NOCACHE_RAM_SECTION struct ehci_qh_hw g_periodic_qh_head[CONFIG_USBHOST_MAX_BUS][EHCI_PERIODIC_QH_NUM]; /* The frame list */ USB_NOCACHE_RAM_SECTION uint32_t g_framelist[CONFIG_USBHOST_MAX_BUS][USB_ALIGN_UP(CONFIG_USB_EHCI_FRAME_LIST_SIZE, 1024)] __attribute__((aligned(4096))); @@ -189,24 +197,35 @@ static inline void ehci_qh_remove(struct ehci_qh_hw *head, struct ehci_qh_hw *n) static int ehci_caculate_smask(int binterval) { - int order, interval; - - interval = 1; - while (binterval > 1) { - interval *= 2; - binterval--; - } - - if (interval < 2) /* interval 1 */ + if (binterval <= 1) { return 0xFF; - if (interval < 4) /* interval 2 */ + } + if (binterval == 2) { return 0x55; - if (interval < 8) /* interval 4 */ + } + if (binterval == 3) { return 0x22; - for (order = 0; (interval > 1); order++) { - interval >>= 1; } - return (0x1 << (order % 8)); + return 0x01; +} + +static struct ehci_qh_hw *ehci_periodic_qh_head(struct usbh_bus *bus, struct usbh_urb *urb) +{ + unsigned int order = 0; + unsigned int interval = urb->ep->bInterval; + + if (urb->hport->speed == USB_SPEED_HIGH) { + order = interval > 4 ? interval - 4 : 0; + } else { + while (interval > 1) { + interval >>= 1; + order++; + } + } + if (order >= EHCI_PERIODIC_QH_NUM) { + order = EHCI_PERIODIC_QH_NUM - 1; + } + return &g_periodic_qh_head[bus->hcd.hcd_id][order]; } static void ehci_qh_fill(struct ehci_qh_hw *qh, @@ -608,7 +627,7 @@ static void ehci_intr_urb_init(struct usbh_bus *bus, struct usbh_urb *urb, uint8 if (!qh->urb) { qh->urb = urb; - ehci_qh_add_head(&g_periodic_qh_head[bus->hcd.hcd_id], qh); + ehci_qh_add_head(ehci_periodic_qh_head(bus, urb), qh); } else { usb_ehci_qh_qtd_flush(qh); } @@ -760,6 +779,31 @@ static int usbh_reset_port(struct usbh_bus *bus, const uint8_t port) return 0; } +static void ehci_periodic_list_init(struct usbh_bus *bus) +{ + struct ehci_qh_hw *head = g_periodic_qh_head[bus->hcd.hcd_id]; + + memset(head, 0, sizeof(g_periodic_qh_head[bus->hcd.hcd_id])); + for (uint32_t i = 0; i < EHCI_PERIODIC_QH_NUM; i++) { + head[i].hw.hlp = i ? QH_HLP_QH(&head[i - 1]) : QH_HLP_END; + head[i].hw.overlay.next_qtd = QTD_LIST_END; + head[i].hw.overlay.alt_next_qtd = QTD_LIST_END; + head[i].hw.overlay.token = QTD_TOKEN_STATUS_HALTED; + head[i].first_qtd = QTD_LIST_END; + + /* Longer periods share the shorter-period suffix. */ + for (uint32_t j = (1U << i) - 1; j < CONFIG_USB_EHCI_FRAME_LIST_SIZE; j += 1U << i) { + g_framelist[bus->hcd.hcd_id][j] = QH_HLP_QH(&head[i]); + } +#if defined(CONFIG_USB_EHCI_DESC_DCACHE_ENABLE) + usb_dcache_clean((uintptr_t)&head[i].hw, USB_ALIGN_UP(sizeof(struct ehci_qh), CONFIG_USB_EHCI_ALIGN_SIZE)); +#endif + } +#if defined(CONFIG_USB_EHCI_DESC_DCACHE_ENABLE) + usb_dcache_clean((uintptr_t)g_framelist[bus->hcd.hcd_id], sizeof(uint32_t) * CONFIG_USB_EHCI_FRAME_LIST_SIZE); +#endif +} + extern void usb_hc_low_level_init(struct usbh_bus *bus); extern void usb_hc_low_level_deinit(struct usbh_bus *bus); @@ -817,24 +861,10 @@ int usb_hc_init(struct usbh_bus *bus) g_async_qh_head[bus->hcd.hcd_id].hw.overlay.token = QTD_TOKEN_STATUS_HALTED; g_async_qh_head[bus->hcd.hcd_id].first_qtd = QTD_LIST_END; - memset(g_framelist[bus->hcd.hcd_id], 0, sizeof(uint32_t) * CONFIG_USB_EHCI_FRAME_LIST_SIZE); - - memset(&g_periodic_qh_head[bus->hcd.hcd_id], 0, sizeof(struct ehci_qh_hw)); - g_periodic_qh_head[bus->hcd.hcd_id].hw.hlp = QH_HLP_END; - g_periodic_qh_head[bus->hcd.hcd_id].hw.epchar = QH_EPCAPS_SSMASK(1); - g_periodic_qh_head[bus->hcd.hcd_id].hw.overlay.next_qtd = QTD_LIST_END; - g_periodic_qh_head[bus->hcd.hcd_id].hw.overlay.alt_next_qtd = QTD_LIST_END; - g_periodic_qh_head[bus->hcd.hcd_id].hw.overlay.token = QTD_TOKEN_STATUS_HALTED; - g_periodic_qh_head[bus->hcd.hcd_id].first_qtd = QTD_LIST_END; - - for (uint32_t i = 0; i < CONFIG_USB_EHCI_FRAME_LIST_SIZE; i++) { - g_framelist[bus->hcd.hcd_id][i] = QH_HLP_QH(&g_periodic_qh_head[bus->hcd.hcd_id]); - } + ehci_periodic_list_init(bus); #if defined(CONFIG_USB_EHCI_DESC_DCACHE_ENABLE) usb_dcache_clean((uintptr_t)&g_async_qh_head[bus->hcd.hcd_id].hw, USB_ALIGN_UP(sizeof(struct ehci_qh), CONFIG_USB_EHCI_ALIGN_SIZE)); - usb_dcache_clean((uintptr_t)&g_periodic_qh_head[bus->hcd.hcd_id].hw, USB_ALIGN_UP(sizeof(struct ehci_qh), CONFIG_USB_EHCI_ALIGN_SIZE)); - usb_dcache_clean((uintptr_t)g_framelist[bus->hcd.hcd_id], sizeof(uint32_t) * CONFIG_USB_EHCI_FRAME_LIST_SIZE); #endif usb_hc_low_level_init(bus); @@ -1371,7 +1401,7 @@ int usbh_kill_urb(struct usbh_urb *urb) if (ep_type == USB_ENDPOINT_TYPE_CONTROL || ep_type == USB_ENDPOINT_TYPE_BULK) { ehci_qh_remove(&g_async_qh_head[bus->hcd.hcd_id], qh); } else { - ehci_qh_remove(&g_periodic_qh_head[bus->hcd.hcd_id], qh); + ehci_qh_remove(ehci_periodic_qh_head(bus, urb), qh); } /* URB is not completed yet */ @@ -1428,15 +1458,16 @@ static void ehci_scan_async_list(struct usbh_bus *bus) static void ehci_scan_periodic_list(struct usbh_bus *bus) { - struct ehci_qh_hw *qh; + struct ehci_qh_hw *head = &g_periodic_qh_head[bus->hcd.hcd_id][EHCI_PERIODIC_QH_NUM - 1]; + struct ehci_qh_hw *qh = head; + /* The longest-period chain contains every periodic QH once. */ + while (qh) { #if defined(CONFIG_USB_EHCI_DESC_DCACHE_ENABLE) - usb_dcache_invalidate((uintptr_t)&g_periodic_qh_head[bus->hcd.hcd_id].hw, USB_ALIGN_UP(sizeof(struct ehci_qh), CONFIG_USB_EHCI_ALIGN_SIZE)); + usb_dcache_invalidate((uintptr_t)&qh->hw, USB_ALIGN_UP(sizeof(struct ehci_qh), CONFIG_USB_EHCI_ALIGN_SIZE)); #endif - qh = EHCI_ADDR2QH(g_periodic_qh_head[bus->hcd.hcd_id].hw.hlp); - while (qh) { if (qh->urb) { - ehci_check_qh(bus, &g_periodic_qh_head[bus->hcd.hcd_id], qh); + ehci_check_qh(bus, head, qh); } qh = EHCI_ADDR2QH(qh->hw.hlp); } |
