Bluetooth: btusb: CSR chip hangs when unbound
Subsystems (2)
PATCH 1/1 Bluetooth: btusb: CSR chip hangs when unbound
Bluetooth Dongles with CSR chip (i.e. USB Bluetooth V4.0 Dongle by Trust) hang when they are unbound from 'unbind' sysfs entry and can not be bound again.
The reason is CSR chip hangs when usb configuration command with index 0 (used to unconfigure) is sent during disconnection.
To avoid this unwanted result, it is necessary not to send this command for CSR chip when usb device is unbound. Besides, "skip_unconfigure" sysfs entry has been created for testing purposes with these or other devices.
Athough device is not unconfigured, it is better to avoid device hanging to be able to operate. Even bluetooth can be previously turned off.
On the other hand, this is not important if usb device is going to be bound again (normal behavior), i.e. with usbip.
--- drivers/bluetooth/btusb.c | 8 +++++++- drivers/usb/core/generic.c | 2 +- drivers/usb/core/sysfs.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/usb.h | 2 ++ 4 files changed, 46 insertions(+), 2 deletions(-)
drivers/bluetooth/btusb.c +7 -1
@@ -4835,8 +4835,14 @@ static int btusb_probe(struct usb_interface *intf,/* Fake CSR devices with broken commands */ if (le16_to_cpu (udev->descriptor.idVendor) ==0x0a12 && -le16_to_cpu (udev->descriptor.idProduct) ==0x0001 ) +le16_to_cpu (udev->descriptor.idProduct) ==0x0001 ) { hdev->setup = btusb_setup_csr; +/* This device hangs when configuration command with +* index 0 (unconfigure) is sent, avoid this at least +* if it is unbound. +*/ + udev->skip_unconfigure =1 ; + } }if (id->driver_info &BTUSB_SNIFFER ) {
drivers/usb/core/generic.c +1 -1
@@ -256,7 +256,7 @@ void usb_generic_driver_disconnect(struct usb_device *udev)/* if this is only an unbind, not a physical disconnect, then * unconfigure the device */ -if (udev->actconfig) +if (!udev->skip_unconfigure && udev->actconfig)usb_set_configuration (udev,-1 ); }
drivers/usb/core/sysfs.c +36 -0
@@ -1189,6 +1189,41 @@ static struct device_attribute dev_attr_interface_authorized =__ATTR (authorized,S_IRUGO |S_IWUSR , interface_authorized_show, interface_authorized_store); +static ssize_t skip_unconfigure_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct usb_interface *intf =to_usb_interface (dev); +struct usb_device *udev =interface_to_usbdev (intf); +u8 val; + +if (usb_lock_device_interruptible (udev) <0 ) +return -EINTR ; + val = udev->skip_unconfigure; +usb_unlock_device (udev); + +return sprintf (buf,"%d\n" , val); +} + +static ssize_t skip_unconfigure_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct usb_interface *intf =to_usb_interface (dev); +struct usb_device *udev =interface_to_usbdev (intf); +u8 val; + +if (kstrtou8 (buf,0 , &val) || val >1 ) +return -EINVAL ; + +if (usb_lock_device_interruptible (udev) <0 ) +return -EINTR ; + udev->skip_unconfigure = val; +usb_unlock_device (udev); + +return count; +} +static DEVICE_ATTR_RW (skip_unconfigure); +static struct attribute *intf_attrs[] = { &dev_attr_bInterfaceNumber.attr, &dev_attr_bAlternateSetting.attr,
@@ -1199,6 +1234,7 @@ static struct attribute *intf_attrs[] = { &dev_attr_modalias.attr, &dev_attr_supports_autosuspend.attr, &dev_attr_interface_authorized.attr, + &dev_attr_skip_unconfigure.attr, NULL, }; static const struct attribute_group intf_attr_grp = {
include/linux/usb.h +2 -0
@@ -618,6 +618,7 @@ struct usb3_lpm_parameters {* parent->hub_delay + wHubDelay + tTPTransmissionDelay (40ns) * Will be used as wValue for SetIsochDelay requests. * @use_generic_driver: ask driver core to reprobe using the generic driver. +* @skip_unconfigure: disable unconfigure operation for devices without support. * * Notes: * Usbcore drivers should not set usbdev->state directly. Instead use
@@ -704,6 +705,7 @@ struct usb_device {u16 hub_delay; unsigned use_generic_driver:1; + unsigned skip_unconfigure:1; };#define to_usb_device (d) container_of(d, struct usb_device, dev)
Signature · 1 line
2.27.0
Greg KH
maintainerQuoted 18 lines · Jose Ignacio Tornos Martinez
Bluetooth Dongles with CSR chip (i.e. USB Bluetooth V4.0 Dongle by Trust) hang when they are unbound from 'unbind' sysfs entry and can not be bound again.
The reason is CSR chip hangs when usb configuration command with index 0 (used to unconfigure) is sent during disconnection.
To avoid this unwanted result, it is necessary not to send this command for CSR chip when usb device is unbound. Besides, "
skip_unconfigure" sysfs entry has been created for testing purposes with these or other devices.Athough device is not unconfigured, it is better to avoid device hanging to be able to operate. Even bluetooth can be previously turned off.
On the other hand, this is not important if usb device is going to be bound again (normal behavior), i.e. with usbip.
Quoted 7 lines
Signed-off-by Jose Ignacio Tornos Martinez <[email protected]>--- drivers/bluetooth/btusb.c | 8 +++++++- drivers/usb/core/generic.c | 2 +- drivers/usb/core/sysfs.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/usb.h | 2 ++ 4 files changed, 46 insertions(+), 2 deletions(-)
No documentation for this new sysfs attribute you wish to create? That's not going to help us with review :(
thanks,
greg k-h
Quoted 11 lines · Jose Ignacio Tornos Martinez
Bluetooth Dongles with CSR chip (i.e. USB Bluetooth V4.0 Dongle by Trust) hang when they are unbound from 'unbind' sysfs entry and can not be bound again.
The reason is CSR chip hangs when usb configuration command with index 0 (used to unconfigure) is sent during disconnection.
To avoid this unwanted result, it is necessary not to send this command for CSR chip when usb device is unbound. Besides, "
skip_unconfigure" sysfs entry has been created for testing purposes with these or other devices.
I don't see any good reason for adding this sysfs entry. Normal users won't want to do it, and developers can add their own quirks to their kernels. Also, see below.
Quoted 27 lines
Athough device is not unconfigured, it is better to avoid device hanging to be able to operate. Even bluetooth can be previously turned off.
On the other hand, this is not important if usb device is going to be bound again (normal behavior), i.e. with usbip.Signed-off-by Jose Ignacio Tornos Martinez <[email protected]>--- drivers/bluetooth/btusb.c | 8 +++++++- drivers/usb/core/generic.c | 2 +- drivers/usb/core/sysfs.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/usb.h | 2 ++ 4 files changed, 46 insertions(+), 2 deletions(-)include/linux/usb.h +1
-0@@ -618,6 +618,7 @@ struct usb3_lpm_parameters {* parent->hub_delay + wHubDelay + tTPTransmissionDelay (40ns) * Will be used as wValue for SetIsochDelay requests. * @use_generic_driver: ask driver core to reprobe using the generic driver. +* @skip_unconfigure: disable unconfigure operation for devices without support. * * Notes: * Usbcore drivers should not set usbdev->state directly. Instead use
include/linux/usb.h struct usb_device { · line 710
Quoted 6 lines
include/linux/usb.h +1
-0@@ -704,6 +705,7 @@ struct usb_device {u16 hub_delay; unsigned use_generic_driver:1; + unsigned skip_unconfigure:1; };#define to_usb_device (d) container_of(d, struct usb_device, dev)
This is not a good way to do it. Instead you should create a new USB device quirk bit. An advantage of this is that there is already a mechanism for users to manually set a quirk flag for a device (the "quirks" sysfs module file).
Alan Stern
Hello Alan,
Ok, I will prepare a new patch in that way.
Thanks
Best regards
José Ignacio
Quoted 59 lines · Alan Stern
Quoted 11 lines · Jose Ignacio Tornos Martinez
Bluetooth Dongles with CSR chip (i.e. USB Bluetooth V4.0 Dongle by Trust) hang when they are unbound from 'unbind' sysfs entry and can not be bound again.
The reason is CSR chip hangs when usb configuration command with index 0 (used to unconfigure) is sent during disconnection.
To avoid this unwanted result, it is necessary not to send this command for CSR chip when usb device is unbound. Besides, "
skip_unconfigure" sysfs entry has been created for testing purposes with these or other devices.I don't see any good reason for adding this sysfs entry. Normal users won't want to do it, and developers can add their own quirks to their kernels. Also, see below.
Quoted 27 lines
Athough device is not unconfigured, it is better to avoid device hanging to be able to operate. Even bluetooth can be previously turned off.
On the other hand, this is not important if usb device is going to be bound again (normal behavior), i.e. with usbip.Signed-off-by Jose Ignacio Tornos Martinez <[email protected]>--- drivers/bluetooth/btusb.c | 8 +++++++- drivers/usb/core/generic.c | 2 +- drivers/usb/core/sysfs.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/usb.h | 2 ++ 4 files changed, 46 insertions(+), 2 deletions(-)include/linux/usb.h +1
-0@@ -618,6 +618,7 @@ struct usb3_lpm_parameters {* parent->hub_delay + wHubDelay + tTPTransmissionDelay (40ns) * Will be used as wValue for SetIsochDelay requests. * @use_generic_driver: ask driver core to reprobe using the generic driver. +* @skip_unconfigure: disable unconfigure operation for devices without support. * * Notes: * Usbcore drivers should not set usbdev->state directly. Instead use include/linux/usb.h struct usb_device { · line 710
Quoted 6 lines
include/linux/usb.h +1
-0@@ -704,6 +705,7 @@ struct usb_device {u16 hub_delay; unsigned use_generic_driver:1; + unsigned skip_unconfigure:1; };#define to_usb_device (d) container_of(d, struct usb_device, dev)This is not a good way to do it. Instead you should create a new USB device quirk bit. An advantage of this is that there is already a mechanism for users to manually set a quirk flag for a device (the "quirks" sysfs module file).
Alan Stern