On Wednesday 16 May 2007 18:25, Alan Stern wrote:
> On Wed, 16 May 2007, Hans Petter Selasky wrote:
> > It is very clear to me that non-blocking memory allocation at the point
> > of starting an USB transfer will require extra error handling in the USB
> > device driver code!
>
> It's not so clear to me.
In my new USB stack, I pass all endpoint and buffer size information
to "usbd_transfer_setup()" at attach time:
For example:
static const struct usbd_config umodem_config_data[UMODEM_N_DATA_TRANSFER] = {
[0] = {
.type = UE_BULK,
.endpoint = -1, /* any */
.direction = UE_DIR_OUT,
.bufsize = UMODEM_BUF_SIZE,
.flags = 0,
.callback = &umodem_write_callback,
},
[1] = {
.type = UE_BULK,
.endpoint = -1, /* any */
.direction = UE_DIR_IN,
.bufsize = UMODEM_BUF_SIZE,
.flags = USBD_SHORT_XFER_OK,
.callback = &umodem_read_callback,
},
[2] = {
.type = UE_CONTROL,
.endpoint = 0x00, /* Control pipe */
.direction = -1,
.bufsize = sizeof(usb_device_request_t),
.callback = &umodem_write_clear_stall_callback,
.timeout = 1000, /* 1 second */
},
[3] = {
.type = UE_CONTROL,
.endpoint = 0x00, /* Control pipe */
.direction = -1,
.bufsize = sizeof(usb_device_request_t),
.callback = &umodem_read_clear_stall_callback,
.timeout = 1000, /* 1 second */
},
};
error = usbd_transfer_setup(uaa->device, sc->sc_data_iface_index,
sc->sc_xfer_data, umodem_config_data,
UMODEM_N_DATA_TRANSFER,
sc, &Giant);
if (error) {
goto detach;
}
>
> > My "usbd_transfer_start()" returns "void". Your "usb_submit_urb()"
> > returns "int".
>
> URB submission has other failure possibilities than lack of memory.
> Those other things have to be checked for regardless.
Yes, but that is because you allow too many parameters in the URB to be
changed between USB transfers.
>
> > Pre-allocating everything you need simply saves code, hence you only
> > check once if you got the memory or not.
>
> It doesn't save code. You need to check for the memory when you
> allocate it, no matter when that is done.
Yes, but it is a difference doing it once at attach or doing it every time you
start a transfer.
> One allocation = one check.
> The total code size is the same if you do the allocation early and only
> once or if you do it late and many times.
>
> It does save execution time. But that's a different matter; it also
> wastes data space.
Yes, it wastes some memory, but that is just how it is. Get used to it :-)
I have some times been thinking that USB endpoint descriptors should have
supplied some information on the maximum bandwidth supported, so that the USB
devices can allocate appropriate buffers.
--HPS
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel