diff mbox series

btusb: CSR chip hangs when unbound

Message ID 20220429114113.356263-1-jtornosm@redhat.com
State New
Headers show
Series btusb: CSR chip hangs when unbound | expand

Commit Message

Jose Ignacio Tornos Martinez April 29, 2022, 11:41 a.m. UTC
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.

Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com>
---
 drivers/bluetooth/btusb.c  |  6 ++++++
 drivers/usb/core/generic.c |  2 +-
 drivers/usb/core/sysfs.c   | 36 ++++++++++++++++++++++++++++++++++++
 include/linux/usb.h        |  2 ++
 4 files changed, 45 insertions(+), 1 deletion(-)

Comments

bluez.test.bot@gmail.com April 29, 2022, 12:02 p.m. UTC | #1
This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=636921

---Test result---

Test Summary:
CheckPatch                    FAIL      2.40 seconds
GitLint                       FAIL      0.98 seconds
SubjectPrefix                 FAIL      0.83 seconds
BuildKernel                   PASS      40.73 seconds
BuildKernel32                 PASS      36.23 seconds
Incremental Build with patchesPASS      48.50 seconds
TestRunner: Setup             PASS      588.54 seconds
TestRunner: l2cap-tester      PASS      19.99 seconds
TestRunner: bnep-tester       PASS      7.46 seconds
TestRunner: mgmt-tester       PASS      116.45 seconds
TestRunner: rfcomm-tester     PASS      11.38 seconds
TestRunner: sco-tester        PASS      11.05 seconds
TestRunner: smp-tester        PASS      11.04 seconds
TestRunner: userchan-tester   PASS      7.56 seconds

Details
##############################
Test: CheckPatch - FAIL - 2.40 seconds
Run checkpatch.pl script with rule in .checkpatch.conf
btusb: CSR chip hangs when unbound\WARNING:COMMIT_LOG_LONG_LINE: Possible unwrapped commit description (prefer a maximum 75 chars per line)
#72: 
for CSR chip when usb device is unbound. Besides, "skip_unconfigure"  sysfs 

ERROR:OPEN_BRACE: that open brace { should be on the previous line
#94: FILE: drivers/bluetooth/btusb.c:4837:
 		if (le16_to_cpu(udev->descriptor.idVendor)  == 0x0a12 &&
 		    le16_to_cpu(udev->descriptor.idProduct) == 0x0001)
+		{

ERROR:CODE_INDENT: code indent should use tabs where possible
#99: FILE: drivers/bluetooth/btusb.c:4842:
+                         * index 0 (unconfigure) is sent, avoid this at least$

ERROR:CODE_INDENT: code indent should use tabs where possible
#100: FILE: drivers/bluetooth/btusb.c:4843:
+                         * if it is unbound */$

WARNING:BLOCK_COMMENT_STYLE: Block comments use a trailing */ on a separate line
#100: FILE: drivers/bluetooth/btusb.c:4843:
+                         * if it is unbound */

ERROR:CODE_INDENT: code indent should use tabs where possible
#128: FILE: drivers/usb/core/sysfs.c:1193:
+                                      struct device_attribute *attr, char *buf)$

WARNING:LEADING_SPACE: please, no spaces at the start of a line
#128: FILE: drivers/usb/core/sysfs.c:1193:
+                                      struct device_attribute *attr, char *buf)$

ERROR:CODE_INDENT: code indent should use tabs where possible
#143: FILE: drivers/usb/core/sysfs.c:1208:
+                                      struct device_attribute *attr,$

WARNING:LEADING_SPACE: please, no spaces at the start of a line
#143: FILE: drivers/usb/core/sysfs.c:1208:
+                                      struct device_attribute *attr,$

ERROR:CODE_INDENT: code indent should use tabs where possible
#144: FILE: drivers/usb/core/sysfs.c:1209:
+                                      const char *buf, size_t count)$

WARNING:LEADING_SPACE: please, no spaces at the start of a line
#144: FILE: drivers/usb/core/sysfs.c:1209:
+                                      const char *buf, size_t count)$

WARNING:SSCANF_TO_KSTRTO: Prefer kstrto<type> to single variable sscanf
#150: FILE: drivers/usb/core/sysfs.c:1215:
+	if (sscanf(buf, "%d", &val) != 1 || val < 0 || val > 1)
+		return -EINVAL;

total: 6 errors, 6 warnings, 83 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

NOTE: Whitespace errors detected.
      You may wish to use scripts/cleanpatch or scripts/cleanfile

/github/workspace/src/12831884.patch has style problems, please review.

NOTE: Ignored message types: UNKNOWN_COMMIT_ID

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.


##############################
Test: GitLint - FAIL - 0.98 seconds
Run gitlint with rule in .gitlint
btusb: CSR chip hangs when unbound
7: B2 Line has trailing whitespace: "The reason is CSR chip hangs when usb configuration command with index 0 "
10: B2 Line has trailing whitespace: "To avoid this unwanted result, it is necessary not to send this command "
11: B2 Line has trailing whitespace: "for CSR chip when usb device is unbound. Besides, "skip_unconfigure"  sysfs "
16: B2 Line has trailing whitespace: "On the other hand, this is not important if usb device is going to be bound "


##############################
Test: SubjectPrefix - FAIL - 0.83 seconds
Check subject contains "Bluetooth" prefix
"Bluetooth: " is not specified in the subject



---
Regards,
Linux Bluetooth
Marcel Holtmann April 29, 2022, 2:49 p.m. UTC | #2
Hi Jose,

> 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.
> 
> Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com>
> ---
> drivers/bluetooth/btusb.c  |  6 ++++++
> drivers/usb/core/generic.c |  2 +-
> drivers/usb/core/sysfs.c   | 36 ++++++++++++++++++++++++++++++++++++
> include/linux/usb.h        |  2 ++
> 4 files changed, 45 insertions(+), 1 deletion(-)

send this to the USB guys first and get their ACK.

Regards

Marcel
diff mbox series

Patch

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index b7c72eb96c87..7eb951e47dc2 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -4836,7 +4836,13 @@  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)
+		{
 			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) {
diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c
index 26f9fb9f67ca..f25171284119 100644
--- a/drivers/usb/core/generic.c
+++ b/drivers/usb/core/generic.c
@@ -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);
 }
 
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index fa2e49d432ff..7cecc558e2c4 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -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);
+	int 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);
+	int val;
+
+	if (sscanf(buf, "%d", &val) != 1 || val < 0 || 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 = {
diff --git a/include/linux/usb.h b/include/linux/usb.h
index 86a73d834e38..55828cd0a0d1 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -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)