usb: fix get_max_packet_size is called before endpoints are allocated
rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]> Mon, 4 May 2026 16:48:18 -0400
| Newsgroups | gmane.comp.systems.archos.rockbox.cvs |
|---|---|
| Message-ID | <[email protected]> |
commit 142e1864efd4a826fc3439cc992c0dbeb0ab16b2 Author: mojyack <[email protected]> Date: Wed Jan 7 13:31:49 2026 +0900 usb: fix get_max_packet_size is called before endpoints are allocated retrive the requirements like others rather than callback Change-Id: I20efce76a418ebd7aa6943f02e53b3f7a8fd2797 diff --git a/firmware/usbstack/usb_audio.c b/firmware/usbstack/usb_audio.c index aceb3bf5a5..2b633e34b1 100644 --- a/firmware/usbstack/usb_audio.c +++ b/firmware/usbstack/usb_audio.c @@ -299,9 +299,9 @@ static int as_playback_freq_idx; /* audio playback streaming frequency index (in static struct usb_class_driver_ep_allocation ep_allocs[2] = { /* output isochronous endpoint */ - {.type = USB_ENDPOINT_XFER_ISOC, .dir = DIR_OUT, .optional = false}, + {.type = USB_ENDPOINT_XFER_ISOC, .dir = DIR_OUT, .optional = false, .mps = -1}, /* input feedback isochronous endpoint */ - {.type = USB_ENDPOINT_XFER_ISOC, .dir = DIR_IN, .optional = false}, + {.type = USB_ENDPOINT_XFER_ISOC, .dir = DIR_IN, .optional = false, .mps = -1}, }; #define EP_ISO_OUT (ep_allocs[0].ep) diff --git a/firmware/usbstack/usb_class_driver.h b/firmware/usbstack/usb_class_driver.h index a48d19ac62..b6e5c16941 100644 --- a/firmware/usbstack/usb_class_driver.h +++ b/firmware/usbstack/usb_class_driver.h @@ -30,10 +30,11 @@ /* Common api, implemented by all class drivers */ struct usb_class_driver_ep_allocation { - uint8_t type; /* by driver, required ep type. USB_ENDPOINT_XFER_* */ - uint8_t dir; /* by driver, required ep dir. DIR_{IN,OUT} */ - uint8_t ep; /* by core, allocated ep. > 0 are valid but can be 0 if optional==true */ - bool optional; /* by driver, set true to mark this requirement to be optional */ + uint8_t ep; /* by core, allocated ep. > 0 are valid but can be 0 if optional==true */ + uint8_t type:2; /* by driver, required ep type. USB_ENDPOINT_XFER_* */ + uint8_t dir:1; /* by driver, required ep dir. DIR_{IN,OUT} */ + bool optional:1; /* by driver, set true to mark this requirement to be optional */ + int16_t mps; /* by driver, desired max packet size, or -1 for device driver default */ }; struct usb_class_driver { @@ -130,11 +131,6 @@ struct usb_class_driver { * Mandatory function if alternate interface support is needed */ int (*get_interface)(int interface); - /* Asks the driver max packet size for the endpoint. - * Drivers can returns desired value in bytes, - * or -1 to use the device controller default */ - int (*get_max_packet_size)(int ep); - /* Invoked by USB_NOTIFY_CLASS_DRIVER Optional function */ void (*notify_event)(intptr_t data); diff --git a/firmware/usbstack/usb_core.c b/firmware/usbstack/usb_core.c index c498ee4cbf..4961f653f3 100644 --- a/firmware/usbstack/usb_core.c +++ b/firmware/usbstack/usb_core.c @@ -651,8 +651,7 @@ retry: /* driver specific check */ const int ep = epnum | (req->dir == DIR_OUT ? USB_DIR_OUT : USB_DIR_IN); - const int ps = driver->get_max_packet_size ? driver->get_max_packet_size(ep) : -1; - if(!usb_drv_ep_allocate(&cstate->ep_alloc_ctx, ep, req->type, ps)) { + if(!usb_drv_ep_allocate(&cstate->ep_alloc_ctx, ep, req->type, req->mps)) { continue; } diff --git a/firmware/usbstack/usb_hid.c b/firmware/usbstack/usb_hid.c index fef3ef45aa..bd0e590a04 100644 --- a/firmware/usbstack/usb_hid.c +++ b/firmware/usbstack/usb_hid.c @@ -122,7 +122,7 @@ static bool currently_sending = false; static int usb_interface; static struct usb_class_driver_ep_allocation ep_allocs[1] = { - {.type = USB_ENDPOINT_XFER_INT, .dir = DIR_IN, .optional = false}, + {.type = USB_ENDPOINT_XFER_INT, .dir = DIR_IN, .optional = false, .mps = -1}, }; #define EP_IN (ep_allocs[0].ep) diff --git a/firmware/usbstack/usb_iap.c b/firmware/usbstack/usb_iap.c index df847fc8ad..df2a0e575c 100644 --- a/firmware/usbstack/usb_iap.c +++ b/firmware/usbstack/usb_iap.c @@ -40,9 +40,9 @@ struct usb_class_driver_ep_allocation usb_iap_ep_allocs[2] = { /* uac input */ - {.type = USB_ENDPOINT_XFER_ISOC, .dir = DIR_IN, .optional = false}, + {.type = USB_ENDPOINT_XFER_ISOC, .dir = DIR_IN, .optional = false, .mps = 1024}, /* hid input */ - {.type = USB_ENDPOINT_XFER_INT, .dir = DIR_IN, .optional = false}, + {.type = USB_ENDPOINT_XFER_INT, .dir = DIR_IN, .optional = false, .mps = 64}, }; /* interface 0 (audio control) */ @@ -442,17 +442,6 @@ static int usb_iap_get_interface(int intf) { return stream.alt; } -static int usb_iap_get_max_packet_size(int ep) { - if(ep == AS_EP_IN) { - return 1024; - } else if(ep == HID_EP_IN) { - return 64; - } else { - panicf("unexpected endpoint number %d", ep); - return 0; - } -} - static void usb_iap_init(void) { LOG("init"); } @@ -706,6 +695,5 @@ struct usb_class_driver usb_cdrv_iap = { .control_request = usb_iap_control_request, .set_interface = usb_iap_set_interface, .get_interface = usb_iap_get_interface, - .get_max_packet_size = usb_iap_get_max_packet_size, .notify_event = usb_iap_notify_event, }; diff --git a/firmware/usbstack/usb_serial.c b/firmware/usbstack/usb_serial.c index d23df7f19b..3dbf41828b 100644 --- a/firmware/usbstack/usb_serial.c +++ b/firmware/usbstack/usb_serial.c @@ -207,9 +207,9 @@ static int buffer_transitlength; static bool active = false; static struct usb_class_driver_ep_allocation ep_allocs[3] = { - {.type = USB_ENDPOINT_XFER_BULK, .dir = DIR_IN, .optional = false}, - {.type = USB_ENDPOINT_XFER_BULK, .dir = DIR_OUT, .optional = false}, - {.type = USB_ENDPOINT_XFER_INT, .dir = DIR_IN, .optional = true}, + {.type = USB_ENDPOINT_XFER_BULK, .dir = DIR_IN, .optional = false, .mps = -1}, + {.type = USB_ENDPOINT_XFER_BULK, .dir = DIR_OUT, .optional = false, .mps = -1}, + {.type = USB_ENDPOINT_XFER_INT, .dir = DIR_IN, .optional = true, .mps = -1}, }; #define EP_IN (ep_allocs[0].ep) diff --git a/firmware/usbstack/usb_storage.c b/firmware/usbstack/usb_storage.c index 055668a56f..2a24f71f36 100644 --- a/firmware/usbstack/usb_storage.c +++ b/firmware/usbstack/usb_storage.c @@ -323,8 +323,8 @@ static bool locked[NUM_DRIVES]; static int usb_interface; static struct usb_class_driver_ep_allocation ep_allocs[2] = { - {.type = USB_ENDPOINT_XFER_BULK, .dir = DIR_IN, .optional = false}, - {.type = USB_ENDPOINT_XFER_BULK, .dir = DIR_OUT, .optional = false}, + {.type = USB_ENDPOINT_XFER_BULK, .dir = DIR_IN, .optional = false, .mps = -1}, + {.type = USB_ENDPOINT_XFER_BULK, .dir = DIR_OUT, .optional = false, .mps = -1}, }; #define EP_IN (ep_allocs[0].ep) -- rockbox-cvs mailing list [email protected] https://lists.haxx.se/mailman/listinfo/rockbox-cvs