I've got a plan for reorganizing usb_reset_device(), 
usb_set_configuration(), and parts of the hub driver and core.  Although 
it's a bit elaborate, it shouldn't have any visible consequences for 
drivers -- except that these routines will start working the way people 
want.

Before doing any real programming, I wanted to get some feedback to see if
this plan makes any sense.

Start by adding a flag to struct usb_device, called state_change_pending.  
Also, there needs to be a mutex protecting this flag and the 'state'
member.  (The 'serialize' mutex seems to be available; AFAICT it's only
used in usbfs in the unbind-interface-from-driver call.  Or another one
could be added.)

The idea is that when usb_reset_device() sees a change in the descriptors 
after the reset, or when usb_set_configuration() succeeds, they set the 
state_change_pending flag and post a request to the khubd queue.  This 
request will include the device and the old configuration.  When the hub 
thread processes the request, it will unbind all the interfaces for that 
configuration and then restart the device initialization procedure at the 
spot corresponding to the device's current state.  If the state is 
DISCONNECTED, the device structure is deleted in the usual way; if the 
state is DEFAULT, an address is assigned; if the state is ADDRESS, a 
configuration is selected; if the state is CONFIGURED, all the interfaces 
are probed.

Only one state_change request may be queued for a device, and if
usb_device_reset() or usb_set_configuration() see that one is already
pending they will refuse to do anything (just return -EBUSY).  Also, to
prevent races against hardware disconnects, the hub disconnect handler
will check to see if state_change_pending is set before doing anything.  
If it is set, all the disconnect handler needs to do is change the state
to USB_STATE_DISCONNECTED.

After usb_device_reset() and usb_set_configuration() carry out their
physical actions, they merely need to disable all the endpoints on the
device (except maybe ep0), set the state to the correct value, and post
the state_change request.  The hub thread will handle all the rest.

Comments are invited.

Alan Stern



-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to