Skip to contentSkip to conversation

Disable bus's drivers_autoprobe before rootfs has mounted

DISCUSSION Peter Chen 4 participants 18 messages Jun 11, 2014 – Jun 17, 2014 USB

lore
Share & tools
lore

Peter Chen

author
#0 lore raw

Hi Greg,

Currently, we can't disable auto probe function during booting if both device and device driver register code are built in due to .drivers_autoprobe is a private value for bus core and this value can only be changed by sys entry.

It causes we can't implement feature that the user can choose manual binding and auto binding through module parameters. Eg, the default binding is automatic, but the user can override it by module parameter.

Let's take USB peripheral as an example, there is a device for udc, and a device driver for usb gadget driver, at default, we want the device to be bound to driver automatically, this is what we have done now. But if there are more than one udcs and gadget drivers (eg one B port for mass storage, another B port for usb ethernet), the user may want to have specific binding (eg, udc-0 -> mass storage, udc-1 -> usb ethernet), so the binding will be established after rootfs has mounted. (This feature is implementing)

Quoted 1 line

From what I read code, we can't implement above feature, but I may

be wrong, if you have some solutions, give me some hints please. If there is no solution for above feature, do we agree with exporting .drivers_autoprobe for bus driver or something similar?

Signature · 2 lines
Best Regards,
Peter Chen
maintainer
#1 lore raw
Quoted 6 lines · Peter Chen

Hi Greg,

Currently, we can't disable auto probe function during booting if both device and device driver register code are built in due to .drivers_autoprobe is a private value for bus core and this value can only be changed by sys entry.

Then don't build them into the kernel :)

Quoted 2 lines

It causes we can't implement feature that the user can choose manual binding and auto binding through module parameters.

Wait, you just asked about building the stuff into the kernel, not a module.

Quoted 2 lines

Eg, the default binding is automatic, but the user can override it by module parameter.

Do we do that for any other "bus" anywhere?

Quoted 8 lines

Let's take USB peripheral as an example, there is a device for udc, and a device driver for usb gadget driver, at default, we want the device to be bound to driver automatically, this is what we have done now. But if there are more than one udcs and gadget drivers (eg one B port for mass storage, another B port for usb ethernet), the user may want to have specific binding (eg, udc-0 -> mass storage, udc-1 -> usb ethernet), so the binding will be established after rootfs has mounted. (This feature is implementing)

Then there better be a way to describe this on the kernel command line (i.e. module paramaters), right? Which is a total mess, why not just not bind anything in this case and let the user pick what they want?

Quoted 4 lines

From what I read code, we can't implement above feature, but I may be wrong, if you have some solutions, give me some hints please. If there is no solution for above feature, do we agree with exporting .drivers_autoprobe for bus driver or something similar?

I don't understand what you mean by this, care to show me with code?

thanks,

greg k-h

#2 lore raw

Hi,

Quoted 9 lines · Greg KH
Quoted 8 lines

Let's take USB peripheral as an example, there is a device for udc, and a device driver for usb gadget driver, at default, we want the device to be bound to driver automatically, this is what we have done now. But if there are more than one udcs and gadget drivers (eg one B port for mass storage, another B port for usb ethernet), the user may want to have specific binding (eg, udc-0 -> mass storage, udc-1 -> usb ethernet), so the binding will be established after rootfs has mounted. (This feature is implementing)

Quoted 3 lines

Then there better be a way to describe this on the kernel command line (i.e. module paramaters), right? Which is a total mess, why not just not bind anything in this case and let the user pick what they want?

you can also blacklist all gadget drivers and manually probe them or - get this - you can refrain from using gadget drivers and use libusbg to build the gadget drivers out of raw usb functions, then bind them to the UDC of your liking.

Signature · 1 line
balbi
author
#3 lore raw
Quoted 12 lines · Felipe Balbi

Hi,

Quoted 9 lines · Greg KH
Quoted 8 lines

Let's take USB peripheral as an example, there is a device for udc, and a device driver for usb gadget driver, at default, we want the device to be bound to driver automatically, this is what we have done now. But if there are more than one udcs and gadget drivers (eg one B port for mass storage, another B port for usb ethernet), the user may want to have specific binding (eg, udc-0 -> mass storage, udc-1 -> usb ethernet), so the binding will be established after rootfs has mounted. (This feature is implementing)

Quoted 9 lines
Quoted 3 lines

Then there better be a way to describe this on the kernel command line (i.e. module paramaters), right? Which is a total mess, why not just not bind anything in this case and let the user pick what they want?

you can also blacklist all gadget drivers and manually probe them or - get this - you can refrain from using gadget drivers and use libusbg to build the gadget drivers out of raw usb functions, then bind them to the UDC of your liking.

I am just worried if we change the behaviour of using gadget driver, can it be accepted by user? If you think it can be accepted if we can have some docs, we can implement manually binding for gadget driver from now on.

Signature · 2 lines
Best Regards,
Peter Chen
#4 lore raw
Quoted 23 lines · Peter Chen
Quoted 12 lines · Felipe Balbi

Hi,

Quoted 9 lines · Greg KH
Quoted 8 lines

Let's take USB peripheral as an example, there is a device for udc, and a device driver for usb gadget driver, at default, we want the device to be bound to driver automatically, this is what we have done now. But if there are more than one udcs and gadget drivers (eg one B port for mass storage, another B port for usb ethernet), the user may want to have specific binding (eg, udc-0 -> mass storage, udc-1 -> usb ethernet), so the binding will be established after rootfs has mounted. (This feature is implementing)

Quoted 9 lines
Quoted 3 lines

Then there better be a way to describe this on the kernel command line (i.e. module paramaters), right? Which is a total mess, why not just not bind anything in this case and let the user pick what they want?

you can also blacklist all gadget drivers and manually probe them or - get this - you can refrain from using gadget drivers and use libusbg to build the gadget drivers out of raw usb functions, then bind them to the UDC of your liking.

Quoted 4 lines

I am just worried if we change the behaviour of using gadget driver, can it be accepted by user? If you think it can be accepted if we can have some docs, we can implement manually binding for gadget driver from now on.

user shouldn't have to deal with direct module insertion/removal (unless he's a developer and actually *wants* to do that). Docs are already in tree. The entire configfs interface has been documented, it's based on those documents that Matt started writing libusbg.

Signature · 1 line
balbi
author
#5 lore raw
Quoted 29 lines · Felipe Balbi
Quoted 23 lines · Peter Chen
Quoted 12 lines · Felipe Balbi

Hi,

Quoted 9 lines · Greg KH
Quoted 8 lines

Let's take USB peripheral as an example, there is a device for udc, and a device driver for usb gadget driver, at default, we want the device to be bound to driver automatically, this is what we have done now. But if there are more than one udcs and gadget drivers (eg one B port for mass storage, another B port for usb ethernet), the user may want to have specific binding (eg, udc-0 -> mass storage, udc-1 -> usb ethernet), so the binding will be established after rootfs has mounted. (This feature is implementing)

Quoted 9 lines
Quoted 3 lines

Then there better be a way to describe this on the kernel command line (i.e. module paramaters), right? Which is a total mess, why not just not bind anything in this case and let the user pick what they want?

you can also blacklist all gadget drivers and manually probe them or - get this - you can refrain from using gadget drivers and use libusbg to build the gadget drivers out of raw usb functions, then bind them to the UDC of your liking.

Quoted 4 lines

I am just worried if we change the behaviour of using gadget driver, can it be accepted by user? If you think it can be accepted if we can have some docs, we can implement manually binding for gadget driver from now on.

Quoted 7 lines

user shouldn't have to deal with direct module insertion/removal (unless he's a developer and actually *wants* to do that). Docs are already in tree. The entire configfs interface has been documented, it's based on those documents that Matt started writing libusbg.

Signature · 1 line
balbi

Yes, gadget-configfs is a good direction.

I would like to know your plan for other gadget drivers (g_mass_storage, g_webcam, etc)

All functions will be supported by configfs in future, and current driver will be deleted?
- If yes, how to cover the user who still use the old file system?
- If no, which binding way for udc and gadget driver will be used? Current binding way for non-configfs gadgets is auto-binding, if we don't want break user's current system, we need to keep auto-binding as the default binding way. With more, we can support manual binding with udc core.

I am implementing gadget bus[1], it may not be benefit for gadget-configfs, but is benefit for other gadgets, eg, support loading gadget driver before udc driver, manual-binding between udc and gadget drivers, etc. So, I would like to know if you agree to keep auto-binding for current non-configfs gadget driver as default way (in that way, we can keep current system with no change), and manual-binding can be used by user with module parameters and /sys entry.

[1] http://www.spinics.net/lists/linux-usb/msg109015.html

Signature · 2 lines
Best Regards,
Peter Chen
#6 lore raw
Quoted 35 lines · Peter Chen
Quoted 34 lines · Felipe Balbi
Quoted 23 lines · Peter Chen
Quoted 12 lines · Felipe Balbi

Hi,

Quoted 9 lines · Greg KH
Quoted 8 lines

Let's take USB peripheral as an example, there is a device for udc, and a device driver for usb gadget driver, at default, we want the device to be bound to driver automatically, this is what we have done now. But if there are more than one udcs and gadget drivers (eg one B port for mass storage, another B port for usb ethernet), the user may want to have specific binding (eg, udc-0 -> mass storage, udc-1 -> usb ethernet), so the binding will be established after rootfs has mounted. (This feature is implementing)

Quoted 9 lines
Quoted 3 lines

Then there better be a way to describe this on the kernel command line (i.e. module paramaters), right? Which is a total mess, why not just not bind anything in this case and let the user pick what they want?

you can also blacklist all gadget drivers and manually probe them or - get this - you can refrain from using gadget drivers and use libusbg to build the gadget drivers out of raw usb functions, then bind them to the UDC of your liking.

Quoted 4 lines

I am just worried if we change the behaviour of using gadget driver, can it be accepted by user? If you think it can be accepted if we can have some docs, we can implement manually binding for gadget driver from now on.

user shouldn't have to deal with direct module insertion/removal (unless he's a developer and actually *wants* to do that). Docs are already in tree. The entire configfs interface has been documented, it's based on those documents that Matt started writing libusbg.

Quoted 7 lines
Quoted 2 lines
Signature · 1 line
balbi

Yes, gadget-configfs is a good direction.

I would like to know your plan for other gadget drivers (g_mass_storage, g_webcam, etc)

they can be built dynamically too. We only provided a version of g_mass_storage in order to avoid regressions. We can't simply remove that driver from the kernel.

Quoted 2 lines

All functions will be supported by configfs in future, and current driver will be deleted?

I don't think we will be able to delete legacy drivers, but they're all supported through configfs. I guess only webcam is missing.

Quoted 2 lines

- If yes, how to cover the user who still use the old file system?
- If no, which binding way for udc and gadget driver will be used?

going forward, we want to stick with configfs.

Signature · 1 line
balbi
author
#7 lore raw
Quoted 26 lines
Quoted 11 lines
Quoted 11 lines
Quoted 5 lines

I am just worried if we change the behaviour of using gadget driver, can it be accepted by user? If you think it can be accepted if we can have some docs, we can implement manually binding for gadget driver from now on.

user shouldn't have to deal with direct module insertion/removal (unless he's a developer and actually *wants* to do that). Docs are already in tree. The entire configfs interface has been documented, it's based on those documents that Matt started writing libusbg.

Quoted 7 lines
Quoted 2 lines

--
balbi

Yes, gadget-configfs is a good direction.

I would like to know your plan for other gadget drivers (g_mass_storage, g_webcam, etc)

they can be built dynamically too. We only provided a version of g_mass_storage in order to avoid regressions. We can't simply remove that driver from the kernel.

Quoted 2 lines

All functions will be supported by configfs in future, and current driver will be deleted?

Quoted 8 lines

I don't think we will be able to delete legacy drivers, but they're all supported through configfs. I guess only webcam is missing.

Quoted 2 lines

- If yes, how to cover the user who still use the old file system?
- If no, which binding way for udc and gadget driver will be used?

going forward, we want to stick with configfs.

ok, then, what's the plan for current bug for legacy gadget driver (eg, we can't load gadget driver before udc is ready)? I know this bug is existed from 3.10, we may need to at least 1 year for switch to configfs, it includes lots of user habit problems. The user will complaint this problem for more than 2 years.

If you think we should fix this bug before we totally switch to configfs, I will continue to enhancement my gadget bus implementation,
and let it support configfs and legacy gadget driver well.

Peter

author
#8 lore raw
In reply to Greg KH
Quoted 8 lines · Greg KH
Quoted 6 lines · Peter Chen

Hi Greg,

Currently, we can't disable auto probe function during booting if both device and device driver register code are built in due to .drivers_autoprobe is a private value for bus core and this value can only be changed by sys entry.

Quoted 7 lines

Then don't build them into the kernel :)

Quoted 2 lines

It causes we can't implement feature that the user can choose manual binding and auto binding through module parameters.

Wait, you just asked about building the stuff into the kernel, not a module.

Yes, build the code into the kernel.

Quoted 5 lines
Quoted 3 lines

Eg, the default binding is automatic, but the user can override it by module parameter.

Do we do that for any other "bus" anywhere?

I don't know.

Quoted 10 lines
Quoted 9 lines

Let's take USB peripheral as an example, there is a device for udc, and a device driver for usb gadget driver, at default, we want the device to be bound to driver automatically, this is what we have done now. But if there are more than one udcs and gadget drivers (eg one B port for mass storage, another B port for usb ethernet), the user may want to have specific binding (eg, udc-0 -> mass storage, udc-1 -> usb ethernet), so the binding will be established after rootfs has mounted. (This feature is implementing)

Quoted 3 lines

Then there better be a way to describe this on the kernel command line (i.e. module paramaters), right? Which is a total mess, why not just not bind anything in this case and let the user pick what they want?

If the user is used to do nothing at rootfs for current or earlier kernel, Is it ok we change the driver's behaviour and a sys entry is mandatory for user?

Quoted 7 lines
Quoted 5 lines

From what I read code, we can't implement above feature, but I may be wrong, if you have some solutions, give me some hints please. If there is no solution for above feature, do we agree with exporting .drivers_autoprobe for bus driver or something similar?

I don't understand what you mean by this, care to show me with code?

I mean the individual bus driver can't change bus->p->drivers_autoprobe? bus->p->drivers_autoprobe is handled at drivers/base/bus.c.

If the individual bus driver can change bus->p->drivers_autoprobe, we can disable autoprobe (auto-binding) during booting.

Signature · 2 lines
Best Regards,
Peter Chen
maintainer
#9 lore raw
Quoted 36 lines · Peter Chen
Quoted 8 lines · Greg KH
Quoted 6 lines · Peter Chen

Hi Greg,

Currently, we can't disable auto probe function during booting if both device and device driver register code are built in due to .drivers_autoprobe is a private value for bus core and this value can only be changed by sys entry.

Quoted 7 lines

Then don't build them into the kernel :)

Quoted 2 lines

It causes we can't implement feature that the user can choose manual binding and auto binding through module parameters.

Wait, you just asked about building the stuff into the kernel, not a module.

Yes, build the code into the kernel.

Quoted 5 lines
Quoted 3 lines

Eg, the default binding is automatic, but the user can override it by module parameter.

Do we do that for any other "bus" anywhere?

I don't know.

Quoted 10 lines
Quoted 9 lines

Let's take USB peripheral as an example, there is a device for udc, and a device driver for usb gadget driver, at default, we want the device to be bound to driver automatically, this is what we have done now. But if there are more than one udcs and gadget drivers (eg one B port for mass storage, another B port for usb ethernet), the user may want to have specific binding (eg, udc-0 -> mass storage, udc-1 -> usb ethernet), so the binding will be established after rootfs has mounted. (This feature is implementing)

Quoted 7 lines
Quoted 3 lines

Then there better be a way to describe this on the kernel command line (i.e. module paramaters), right? Which is a total mess, why not just not bind anything in this case and let the user pick what they want?

If the user is used to do nothing at rootfs for current or earlier kernel, Is it ok we change the driver's behaviour and a sys entry is mandatory for user?

We can't break existing systems, so I don't understand the issue here. Just don't configure your kernel for a system you don't have / want, right?

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

From what I read code, we can't implement above feature, but I may be wrong, if you have some solutions, give me some hints please. If there is no solution for above feature, do we agree with exporting .drivers_autoprobe for bus driver or something similar?

Quoted 7 lines
Quoted 1 line

I don't understand what you mean by this, care to show me with code?

I mean the individual bus driver can't change bus->p->drivers_autoprobe? bus->p->drivers_autoprobe is handled at drivers/base/bus.c.

If the individual bus driver can change bus->p->drivers_autoprobe, we can disable autoprobe (auto-binding) during booting.

No, that's a core only thing.

greg k-h

#10 lore raw
Quoted 11 lines · Greg KH

We can't break existing systems, so I don't understand the issue here. Just don't configure your kernel for a system you don't have / want, right?

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

From what I read code, we can't implement above feature, but I may be wrong, if you have some solutions, give me some hints please. If there is no solution for above feature, do we agree with exporting .drivers_autoprobe for bus driver or something similar?

I don't understand what you mean by this, care to show me with code?

Quoted 7 lines
Quoted 5 lines

I mean the individual bus driver can't change bus->p->drivers_autoprobe? bus->p->drivers_autoprobe is handled at drivers/base/bus.c.

If the individual bus driver can change bus->p->drivers_autoprobe, we can disable autoprobe (auto-binding) during booting.

No, that's a core only thing.

Peter, correct me if this is wrong. It sounds like you want to have a way for the user to control which gadget driver gets bound to which UDC driver when everything is compiled into the kernel, nothing is built as a separate module. Is that the basic idea?

This shouldn't be a problem if you use configfs or libusbg.

Alan Stern

author
#11 lore raw
Quoted 19 lines · Alan Stern
Quoted 17 lines · Greg KH

We can't break existing systems, so I don't understand the issue here. Just don't configure your kernel for a system you don't have / want, right?

Quoted 12 lines
Quoted 6 lines
Quoted 4 lines

From what I read code, we can't implement above feature, but I may be wrong, if you have some solutions, give me some hints please. If there is no solution for above feature, do we agree with exporting .drivers_autoprobe for bus driver or something similar?

I don't understand what you mean by this, care to show me with code?

I mean the individual bus driver can't change bus->p->drivers_autoprobe? bus->p->drivers_autoprobe is handled at drivers/base/bus.c.

If the individual bus driver can change bus->p->drivers_autoprobe, we can disable autoprobe (auto-binding) during booting.

Quoted 6 lines
Quoted 1 line

No, that's a core only thing.

Peter, correct me if this is wrong. It sounds like you want to have a way for the user to control which gadget driver gets bound to which UDC driver when everything is compiled into the kernel, nothing is built as a separate module. Is that the basic idea?

Yes, I know it can be done by gadget-configfs, but how about the user chooses other gadgets, eg: g_webcam, g_audio?

I forget to introduce the background of this topic, I have this issue when I implement gadget bus patch set.
(http://www.spinics.net/lists/linux-usb/msg107797.html)
The current behaviour for other gadgets is auto-binding, so I want to keep auto-binding at my gadget bus implementation, but manual-binding is also a feature we need to support for other gadgets, so I want auto-binding is the default binding way, and the user can switch the two binding ways, eg, module parameters or sys entry.

But if both udc driver and gadget driver are built in, the user can't let manual-binding work during the boot since the device-model will do probe, and do auto-binding.

My v1 patch set [3/4] do a tricky way to work around it, I would like to know if it can be supported by device model framework?

Quoted 5 lines

This shouldn't be a problem if you use configfs or libusbg.

Alan Stern

Signature · 2 lines
Best Regards,
Peter Chen
#12 lore raw
Quoted 17 lines · Peter Chen
Quoted 4 lines

Peter, correct me if this is wrong. It sounds like you want to have a way for the user to control which gadget driver gets bound to which UDC driver when everything is compiled into the kernel, nothing is built as a separate module. Is that the basic idea?

Yes, I know it can be done by gadget-configfs, but how about the user chooses other gadgets, eg: g_webcam, g_audio?

I forget to introduce the background of this topic, I have this issue when I implement gadget bus patch set.
(http://www.spinics.net/lists/linux-usb/msg107797.html)
The current behaviour for other gadgets is auto-binding, so I want to keep auto-binding at my gadget bus implementation, but manual-binding is also a feature we need to support for other gadgets, so I want auto-binding is the default binding way, and the user can switch the two binding ways, eg, module parameters or sys entry.

Quoted 6 lines

But if both udc driver and gadget driver are built in, the user can't let manual-binding work during the boot since the device-model will do probe, and do auto-binding.

My v1 patch set [3/4] do a tricky way to work around it, I would like to know if it can be supported by device model framework?

I think we can keep everything a lot simpler. Let's agree that the old non-composite gadget drivers (like g_ether, g_mass_storage, and so on) should only be used one at a time. That is, there should never be more than one of them compiled into the kernel or loaded as a module, and they shouldn't be used if there is more than one unbound UDC.

If a user wants to work with more than one UDC or more than one gadget driver then he should use function drivers with the configfs interface (or functionfs or gadgetfs or whatever).

Does that seem reasonable? It doesn't solve your problem so much as declare it an unsupported case, but I don't think there is any reasonable way to solve the problem without using something like configfs.

Alan Stern

author
#13 lore raw
Quoted 32 lines
Quoted 19 lines
Quoted 6 lines

Peter, correct me if this is wrong. It sounds like you want to have a way for the user to control which gadget driver gets bound to which UDC driver when everything is compiled into the kernel, nothing is built as a separate module. Is that the basic idea?

Yes, I know it can be done by gadget-configfs, but how about the user chooses other gadgets, eg: g_webcam, g_audio?

I forget to introduce the background of this topic, I have this issue when I implement gadget bus patch set.
(http://www.spinics.net/lists/linux-usb/msg107797.html)
The current behaviour for other gadgets is auto-binding, so I want to keep auto-binding at my gadget bus implementation, but manual-binding is also a feature we need to support for other gadgets, so I want auto-binding is the default binding way, and the user can switch the two binding ways, eg, module parameters or sys entry.

Quoted 6 lines

But if both udc driver and gadget driver are built in, the user can't let manual-binding work during the boot since the device-model will do probe, and do auto-binding.

My v1 patch set [3/4] do a tricky way to work around it, I would like to know if it can be supported by device model framework?

I think we can keep everything a lot simpler. Let's agree that the old non-composite gadget drivers (like g_ether, g_mass_storage, and so on) should only be used one at a time. That is, there should never be more than one of them compiled into the kernel or loaded as a module, and they shouldn't be used if there is more than one unbound UDC.

Quoted 8 lines

If a user wants to work with more than one UDC or more than one gadget driver then he should use function drivers with the configfs interface (or functionfs or gadgetfs or whatever).

Does that seem reasonable? It doesn't solve your problem so much as declare it an unsupported case, but I don't think there is any reasonable way to solve the problem without using something like configfs.

OK, we can keep our g_xxx gadget driver just support the basic feature. But the bug that causes gadget driver load fail due to udc is probed deferral should be fixed, do you think so, we can't wait until configfs has total been ready.

Peter

#14 lore raw
Quoted 3 lines · Peter Chen

OK, we can keep our g_xxx gadget driver just support the basic feature. But the bug that causes gadget driver load fail due to udc is probed deferral should be fixed, do you think so, we can't wait until configfs has total been ready.

That problem has always existed. There never has been a time when a gadget driver could be loaded before the UDC driver was ready. Does it really need to be fixed now?

If you do want to fix the problem, there's a much easier way than what you posted. See below.

Alan Stern

include/linux/usb/gadget.h +2 -0
Index: usb-3.15/include/linux/usb/gadget.h
===================================================================
@@ -821,6 +821,7 @@ static inline int usb_gadget_disconnect(
  * @suspend: Invoked on USB suspend.  May be called in_interrupt.
  * @resume: Invoked on USB resume.  May be called in_interrupt.
  * @driver: Driver model state for this driver.
+ * @probe_list: List of drivers waiting to be probed.
  *
  * Devices are disabled till a gadget driver successfully bind()s, which
  * means the driver will handle setup() requests needed to enumerate (and
@@ -881,6 +882,7 @@ struct usb_gadget_driver {
 
 	/* FIXME support safe rmmod */
 	struct device_driver	driver;
+	struct list_head	probe_list;
 };
 
 
drivers/usb/gadget/udc-core.c +18 -1
Index: usb-3.15/drivers/usb/gadget/udc-core.c
===================================================================
@@ -47,8 +47,12 @@ struct usb_udc {
 
 static struct class *udc_class;
 static LIST_HEAD(udc_list);
+static LIST_HEAD(pending_drivers);
 static DEFINE_MUTEX(udc_lock);
 
+static int udc_bind_to_driver(struct usb_udc *udc,
+		struct usb_gadget_driver *driver);
+
 /* ------------------------------------------------------------------------- */
 
 #ifdef	CONFIG_HAS_DMA
@@ -242,6 +246,15 @@ int usb_add_gadget_udc_release(struct de
 
 	usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED);
 
+	while (!list_empty(&pending_drivers)) {
+		struct usb_gadget_driver *driver;
+
+		driver = list_first_entry(&pending_drivers,
+				struct usb_gadget_driver, probe_list);
+		if (udc_bind_to_driver(udc, driver) == 0)
+			break;
+	}
+
 	mutex_unlock(&udc_lock);
 
 	return 0;
@@ -338,6 +351,7 @@ static int udc_bind_to_driver(struct usb
 
 	dev_dbg(&udc->dev, "registering UDC driver [%s]\n",
 			driver->function);
+	list_del_init(&driver->probe_list);
 
 	udc->driver = driver;
 	udc->dev.driver = &driver->driver;
@@ -400,6 +414,7 @@ int usb_gadget_probe_driver(struct usb_g
 		return -EINVAL;
 
 	mutex_lock(&udc_lock);
+	INIT_LIST_HEAD(&driver->probe_list);
 	list_for_each_entry(udc, &udc_list, list) {
 		/* For now we take the first one */
 		if (!udc->driver)
@@ -407,8 +422,9 @@ int usb_gadget_probe_driver(struct usb_g
 	}
 
 	pr_debug("couldn't find an available UDC\n");
+	list_add_tail(&driver->probe_list, &pending_drivers);
 	mutex_unlock(&udc_lock);
-	return -ENODEV;
+	return 0;
 found:
 	ret = udc_bind_to_driver(udc, driver);
 	mutex_unlock(&udc_lock);
@@ -425,6 +441,7 @@ int usb_gadget_unregister_driver(struct
 		return -EINVAL;
 
 	mutex_lock(&udc_lock);
+	list_del(&driver->probe_list);
 	list_for_each_entry(udc, &udc_list, list)
 		if (udc->driver == driver) {
 			usb_gadget_remove_driver(udc);
author
#15 lore raw
Quoted 10 lines · Alan Stern
Quoted 3 lines · Peter Chen

OK, we can keep our g_xxx gadget driver just support the basic feature. But the bug that causes gadget driver load fail due to udc is probed deferral should be fixed, do you think so, we can't wait until configfs has total been ready.

That problem has always existed. There never has been a time when a gadget driver could be loaded before the UDC driver was ready. Does it really need to be fixed now?

Yes, otherwise, the device which the udc is probed deferral and the gadget driver is build-in will never work. If we skip fixing it, this problem will exist for more than 2 years, it is too long.

I have a support request from android team that usb peripheral function never works from 3.10.x kernel at one device, I think it is a common problem, no only I meet it.

Below are links which this problem reports:

http://marc.info/?l=linux-usb&m=139380872501745&w=2
http://marc.info/?l=linux-usb&m=137706435611447&w=2

Quoted 3 lines

If you do want to fix the problem, there's a much easier way than what you posted. See below.

Robert Baldyga posts the similar solution, but seems Felipe doesn't agree it.
http://www.spinics.net/lists/linux-usb/msg102795.html

Then, you and Felipe has a discussion for this problem:
http://www.spinics.net/lists/linux-usb/msg106760.html

Quoted 91 lines

Index: usb-3.15/include/linux/usb/gadget.h
===================================================================

include/linux/usb/gadget.h +2 -0
@@ -821,6 +821,7 @@ static inline int usb_gadget_disconnect(
  * @suspend: Invoked on USB suspend.  May be called in_interrupt.
  * @resume: Invoked on USB resume.  May be called in_interrupt.
  * @driver: Driver model state for this driver.
+ * @probe_list: List of drivers waiting to be probed.
  *
  * Devices are disabled till a gadget driver successfully bind()s, which
  * means the driver will handle setup() requests needed to enumerate (and
@@ -881,6 +882,7 @@ struct usb_gadget_driver {
 
 	/* FIXME support safe rmmod */
 	struct device_driver	driver;
+	struct list_head	probe_list;
 };
 
 

Index: usb-3.15/drivers/usb/gadget/udc-core.c
===================================================================

drivers/usb/gadget/udc-core.c +18 -1
@@ -47,8 +47,12 @@ struct usb_udc {
 
 static struct class *udc_class;
 static LIST_HEAD(udc_list);
+static LIST_HEAD(pending_drivers);
 static DEFINE_MUTEX(udc_lock);
 
+static int udc_bind_to_driver(struct usb_udc *udc,
+		struct usb_gadget_driver *driver);
+
 /* ------------------------------------------------------------------------- */
 
 #ifdef	CONFIG_HAS_DMA
@@ -242,6 +246,15 @@ int usb_add_gadget_udc_release(struct de
 
 	usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED);
 
+	while (!list_empty(&pending_drivers)) {
+		struct usb_gadget_driver *driver;
+
+		driver = list_first_entry(&pending_drivers,
+				struct usb_gadget_driver, probe_list);
+		if (udc_bind_to_driver(udc, driver) == 0)
+			break;
+	}
+
 	mutex_unlock(&udc_lock);
 
 	return 0;
@@ -338,6 +351,7 @@ static int udc_bind_to_driver(struct usb
 
 	dev_dbg(&udc->dev, "registering UDC driver [%s]\n",
 			driver->function);
+	list_del_init(&driver->probe_list);
 
 	udc->driver = driver;
 	udc->dev.driver = &driver->driver;
@@ -400,6 +414,7 @@ int usb_gadget_probe_driver(struct usb_g
 		return -EINVAL;
 
 	mutex_lock(&udc_lock);
+	INIT_LIST_HEAD(&driver->probe_list);
 	list_for_each_entry(udc, &udc_list, list) {
 		/* For now we take the first one */
 		if (!udc->driver)
@@ -407,8 +422,9 @@ int usb_gadget_probe_driver(struct usb_g
 	}
 
 	pr_debug("couldn't find an available UDC\n");
+	list_add_tail(&driver->probe_list, &pending_drivers);
 	mutex_unlock(&udc_lock);
-	return -ENODEV;
+	return 0;
 found:
 	ret = udc_bind_to_driver(udc, driver);
 	mutex_unlock(&udc_lock);
@@ -425,6 +441,7 @@ int usb_gadget_unregister_driver(struct
 		return -EINVAL;
 
 	mutex_lock(&udc_lock);
+	list_del(&driver->probe_list);
 	list_for_each_entry(udc, &udc_list, list)
 		if (udc->driver == driver) {
 			usb_gadget_remove_driver(udc);
Signature · 2 lines
Best Regards,
Peter Chen
#16 lore raw
Quoted 28 lines · Peter Chen
Quoted 10 lines · Alan Stern
Quoted 3 lines · Peter Chen

OK, we can keep our g_xxx gadget driver just support the basic feature. But the bug that causes gadget driver load fail due to udc is probed deferral should be fixed, do you think so, we can't wait until configfs has total been ready.

That problem has always existed. There never has been a time when a gadget driver could be loaded before the UDC driver was ready. Does it really need to be fixed now?

Yes, otherwise, the device which the udc is probed deferral and the gadget driver is build-in will never work. If we skip fixing it, this problem will exist for more than 2 years, it is too long.

I have a support request from android team that usb peripheral function never works from 3.10.x kernel at one device, I think it is a common problem, no only I meet it.

Below are links which this problem reports:

http://marc.info/?l=linux-usb&m=139380872501745&w=2
http://marc.info/?l=linux-usb&m=137706435611447&w=2

Quoted 3 lines

If you do want to fix the problem, there's a much easier way than what you posted. See below.

Quoted 6 lines

Robert Baldyga posts the similar solution, but seems Felipe doesn't agree it.
http://www.spinics.net/lists/linux-usb/msg102795.html

Then, you and Felipe has a discussion for this problem:
http://www.spinics.net/lists/linux-usb/msg106760.html

Okay, I get it. Felipe didn't want to do this because you might end up loading a gadget driver that never gets bound. There might not even be any UDC devices at all.

Felipe, I think the problem of having unbound gadget drivers isn't so bad. It's just like having unbound drivers of any sort. For example, the Fedora kernels have ohci-hcd and uhci-hcd built-in. Relatively few systems have both OHCI and UHCI controllers (lots of current machines have neither); everybody else ends up with at least one unused driver and no way to remove it. If Fedora can do this, I think we can allow users to have unnecessary gadget drivers.

In fact, I don't know of any other kind of driver module whose init routine will fail if there's no hardware to bind to.

I suggest you go ahead and accept Robert Baldyga's original patch -- except for one little problem: The patch forgets to add driver->list to the global driver_list if the driver gets bound immediately. The

	list_add_tail(&driver->list, &driver_list);

call needs to be moved up near the start of usb_gadget_probe_driver().

Alan Stern

author
#17 lore raw
Quoted 39 lines
Quoted 17 lines

Yes, otherwise, the device which the udc is probed deferral and the gadget driver is build-in will never work. If we skip fixing it, this problem will exist for more than 2 years, it is too long.

I have a support request from android team that usb peripheral function never works from 3.10.x kernel at one device, I think it is a common problem, no only I meet it.

Below are links which this problem reports:

http://marc.info/?l=linux-usb&m=139380872501745&w=2
http://marc.info/?l=linux-usb&m=137706435611447&w=2

Quoted 3 lines

If you do want to fix the problem, there's a much easier way than what you posted. See below.

Quoted 6 lines

Robert Baldyga posts the similar solution, but seems Felipe doesn't agree it.
http://www.spinics.net/lists/linux-usb/msg102795.html

Then, you and Felipe has a discussion for this problem:
http://www.spinics.net/lists/linux-usb/msg106760.html

Okay, I get it. Felipe didn't want to do this because you might end up loading a gadget driver that never gets bound. There might not even be any UDC devices at all.

Felipe, I think the problem of having unbound gadget drivers isn't so bad. It's just like having unbound drivers of any sort. For example, the Fedora kernels have ohci-hcd and uhci-hcd built-in. Relatively few systems have both OHCI and UHCI controllers (lots of current machines have neither); everybody else ends up with at least one unused driver and no way to remove it. If Fedora can do this, I think we can allow users to have unnecessary gadget drivers.

In fact, I don't know of any other kind of driver module whose init routine will fail if there's no hardware to bind to.

Quoted 8 lines

I suggest you go ahead and accept Robert Baldyga's original patch -- except for one little problem: The patch forgets to add driver->list to the global driver_list if the driver gets bound immediately. The

	list_add_tail(&driver->list, &driver_list);

call needs to be moved up near the start of usb_gadget_probe_driver().

Thanks, Alan.

The another improvement is: set driver->attached as true at udc_bind_to_driver.

Peter