From bf54bc2ff1c3833ca3c49d0720e712bfec679653 Mon Sep 17 00:00:00 2001 From: sakumisu <1203593632@qq.com> Date: Tue, 11 Jun 2024 21:59:37 +0800 Subject: [PATCH] update(port/ehci): use static iso pool for iso urb to reduce alloc time --- common/usb_hc.h | 1 + port/ehci/usb_ehci_priv.h | 16 ++++++++++++---- port/ehci/usb_hc_ehci.c | 6 +++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/common/usb_hc.h b/common/usb_hc.h index adfddbea..c4e2a16d 100644 --- a/common/usb_hc.h +++ b/common/usb_hc.h @@ -34,6 +34,7 @@ struct usbh_iso_frame_packet { * Structure containing the USB Urb configuration. */ struct usbh_urb { + usb_slist_t list; void *hcpriv; struct usbh_hubport *hport; struct usb_endpoint_descriptor *ep; diff --git a/port/ehci/usb_ehci_priv.h b/port/ehci/usb_ehci_priv.h index 03fa270c..ba1d3510 100644 --- a/port/ehci/usb_ehci_priv.h +++ b/port/ehci/usb_ehci_priv.h @@ -25,7 +25,10 @@ #define CONFIG_USB_EHCI_QTD_NUM 3 #endif #ifndef CONFIG_USB_EHCI_ITD_NUM -#define CONFIG_USB_EHCI_ITD_NUM 20 +#define CONFIG_USB_EHCI_ITD_NUM 5 +#endif +#ifndef CONFIG_USB_EHCI_ISO_NUM +#define CONFIG_USB_EHCI_ISO_NUM 4 #endif extern uint8_t usbh_get_port_speed(struct usbh_bus *bus, const uint8_t port); @@ -52,12 +55,17 @@ struct ehci_itd_hw { uint8_t mf_unmask; uint8_t mf_valid; uint32_t pkt_idx[8]; - usb_slist_t list; } __attribute__((aligned(32))); +struct ehci_iso_hw +{ + struct ehci_itd_hw itd_pool[CONFIG_USB_EHCI_ITD_NUM]; + uint32_t itd_num; +}; + struct ehci_hcd { bool ehci_qh_used[CONFIG_USB_EHCI_QH_NUM]; - bool ehci_itd_used[CONFIG_USB_EHCI_ITD_NUM]; + bool ehci_iso_used[CONFIG_USB_EHCI_ISO_NUM]; bool ppc; /* Port Power Control */ bool has_tt; /* if use tt instead of Companion Controller */ uint8_t n_cc; /* Number of Companion Controller */ @@ -70,7 +78,7 @@ extern struct ehci_hcd g_ehci_hcd[CONFIG_USBHOST_MAX_BUS]; extern uint32_t g_framelist[CONFIG_USBHOST_MAX_BUS][USB_ALIGN_UP(CONFIG_USB_EHCI_FRAME_LIST_SIZE, 1024)]; int ehci_iso_urb_init(struct usbh_bus *bus, struct usbh_urb *urb); -void ehci_remove_itd_urb(struct usbh_bus *bus, struct usbh_urb *urb); +void ehci_kill_iso_urb(struct usbh_bus *bus, struct usbh_urb *urb); void ehci_scan_isochronous_list(struct usbh_bus *bus); #endif diff --git a/port/ehci/usb_hc_ehci.c b/port/ehci/usb_hc_ehci.c index 41c8f46d..a79cd606 100644 --- a/port/ehci/usb_hc_ehci.c +++ b/port/ehci/usb_hc_ehci.c @@ -1245,7 +1245,7 @@ int usbh_kill_urb(struct usbh_urb *urb) } } else { #ifdef CONFIG_USB_EHCI_ISO - ehci_remove_itd_urb(bus, urb); + ehci_kill_iso_urb(bus, urb); EHCI_HCOR->usbcmd |= (EHCI_USBCMD_PSEN | EHCI_USBCMD_ASEN); usb_osal_leave_critical_section(flags); return 0; @@ -1346,8 +1346,8 @@ void USBH_IRQHandler(uint8_t busid) for (uint8_t index = 0; index < CONFIG_USB_EHCI_QH_NUM; index++) { g_ehci_hcd[bus->hcd.hcd_id].ehci_qh_used[index] = false; } - for (uint8_t index = 0; index < CONFIG_USB_EHCI_ITD_NUM; index++) { - g_ehci_hcd[bus->hcd.hcd_id].ehci_itd_used[index] = false; + for (uint8_t index = 0; index < CONFIG_USB_EHCI_ISO_NUM; index++) { + g_ehci_hcd[bus->hcd.hcd_id].ehci_iso_used[index] = false; } }