linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] Bluetooth: btusb: Reset port on cmd timeout
@ 2020-06-24 18:11 Abhishek Pandit-Subedi
  2020-06-24 18:27 ` Marcel Holtmann
  2020-06-25 10:22 ` Oliver Neukum
  0 siblings, 2 replies; 4+ messages in thread
From: Abhishek Pandit-Subedi @ 2020-06-24 18:11 UTC (permalink / raw)
  To: rjliao, marcel, linux-bluetooth
  Cc: chromeos-bluetooth-upstreaming, linux-usb, linux-pm,
	Abhishek Pandit-Subedi, Johan Hedberg, linux-kernel

QCA_ROME sometimes gets into a state where it is unresponsive to
commands. Since it doesn't have support for a reset gpio, reset the usb
port when this occurs instead.

Signed-off-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
---
On Chromebooks with this chipset, we encountered cmd_timeout after
running suspend stress test for hundreds of iterations. Without
a recovery mechanism, continued cmd_timeout failures eventually caused
the suspend stress test to fail.

This change will just reset the port that the Bluetooth chip is on when
cmd_timeout is encountered. At the very least, the driver will unload
and stop affecting suspend. It doesn't seem to restore the BT controller
to a good state however (this still requires a power cycle).

Changes in v2:
- Renamed btusb_generic_usb_cmd_timeout to btusb_qca_cmd_timeout
- Updated commit note

 drivers/bluetooth/btusb.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index e42fdd625eb023..df46b2a34c1803 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -573,6 +573,22 @@ static void btusb_rtl_cmd_timeout(struct hci_dev *hdev)
 	gpiod_set_value_cansleep(reset_gpio, 0);
 }
 
+static void btusb_qca_cmd_timeout(struct hci_dev *hdev)
+{
+	struct btusb_data *data = hci_get_drvdata(hdev);
+	int err;
+
+	if (++data->cmd_timeout_cnt < 5)
+		return;
+
+	bt_dev_err(hdev, "Multiple cmd timeouts seen. Resetting usb device.");
+	err = usb_autopm_get_interface(data->intf);
+	if (!err)
+		usb_queue_reset_device(data->intf);
+	else
+		bt_dev_err(hdev, "Failed usb_autopm_get_interface with %d", err);
+}
+
 static inline void btusb_free_frags(struct btusb_data *data)
 {
 	unsigned long flags;
@@ -3964,6 +3980,7 @@ static int btusb_probe(struct usb_interface *intf,
 	if (id->driver_info & BTUSB_QCA_ROME) {
 		data->setup_on_usb = btusb_setup_qca;
 		hdev->set_bdaddr = btusb_set_bdaddr_ath3012;
+		hdev->cmd_timeout = btusb_qca_cmd_timeout;
 		set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
 		btusb_check_needs_reset_resume(intf);
 	}
-- 
2.27.0.111.gc72c7da667-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] Bluetooth: btusb: Reset port on cmd timeout
  2020-06-24 18:11 [PATCH v2] Bluetooth: btusb: Reset port on cmd timeout Abhishek Pandit-Subedi
@ 2020-06-24 18:27 ` Marcel Holtmann
  2020-06-25 10:22 ` Oliver Neukum
  1 sibling, 0 replies; 4+ messages in thread
From: Marcel Holtmann @ 2020-06-24 18:27 UTC (permalink / raw)
  To: Abhishek Pandit-Subedi
  Cc: Rocky Liao, BlueZ, ChromeOS Bluetooth Upstreaming, linux-usb,
	linux-pm, Johan Hedberg, linux-kernel

Hi Abhishek,

> QCA_ROME sometimes gets into a state where it is unresponsive to
> commands. Since it doesn't have support for a reset gpio, reset the usb
> port when this occurs instead.
> 
> Signed-off-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
> ---
> On Chromebooks with this chipset, we encountered cmd_timeout after
> running suspend stress test for hundreds of iterations. Without
> a recovery mechanism, continued cmd_timeout failures eventually caused
> the suspend stress test to fail.
> 
> This change will just reset the port that the Bluetooth chip is on when
> cmd_timeout is encountered. At the very least, the driver will unload
> and stop affecting suspend. It doesn't seem to restore the BT controller
> to a good state however (this still requires a power cycle).
> 
> Changes in v2:
> - Renamed btusb_generic_usb_cmd_timeout to btusb_qca_cmd_timeout
> - Updated commit note
> 
> drivers/bluetooth/btusb.c | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)

patch has been applied to bluetooth-next tree.

Regards

Marcel


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] Bluetooth: btusb: Reset port on cmd timeout
  2020-06-24 18:11 [PATCH v2] Bluetooth: btusb: Reset port on cmd timeout Abhishek Pandit-Subedi
  2020-06-24 18:27 ` Marcel Holtmann
@ 2020-06-25 10:22 ` Oliver Neukum
  2020-06-25 23:18   ` Abhishek Pandit-Subedi
  1 sibling, 1 reply; 4+ messages in thread
From: Oliver Neukum @ 2020-06-25 10:22 UTC (permalink / raw)
  To: Abhishek Pandit-Subedi, rjliao, marcel, linux-bluetooth
  Cc: chromeos-bluetooth-upstreaming, linux-usb, linux-pm,
	Johan Hedberg, linux-kernel

Am Mittwoch, den 24.06.2020, 11:11 -0700 schrieb Abhishek Pandit-
Subedi:
> QCA_ROME sometimes gets into a state where it is unresponsive to
> commands. Since it doesn't have support for a reset gpio, reset the usb
> port when this occurs instead.

Hi,

on first glance this looks like an unbalanced PM reference. It is not
because the operation is suicidal, but this deserves a comment, unless
you want to get a note telling you that you caused an imbalance every
few weeks.

	Regards
		Oliver


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] Bluetooth: btusb: Reset port on cmd timeout
  2020-06-25 10:22 ` Oliver Neukum
@ 2020-06-25 23:18   ` Abhishek Pandit-Subedi
  0 siblings, 0 replies; 4+ messages in thread
From: Abhishek Pandit-Subedi @ 2020-06-25 23:18 UTC (permalink / raw)
  To: Oliver Neukum
  Cc: Rocky Liao, Marcel Holtmann, Bluez mailing list,
	ChromeOS Bluetooth Upstreaming, linux-usb, Linux PM,
	Johan Hedberg, LKML

Thanks for the heads up Oliver -- I will send a patch with a comment on this.

On Thu, Jun 25, 2020 at 3:22 AM Oliver Neukum <oneukum@suse.com> wrote:
>
> Am Mittwoch, den 24.06.2020, 11:11 -0700 schrieb Abhishek Pandit-
> Subedi:
> > QCA_ROME sometimes gets into a state where it is unresponsive to
> > commands. Since it doesn't have support for a reset gpio, reset the usb
> > port when this occurs instead.
>
> Hi,
>
> on first glance this looks like an unbalanced PM reference. It is not
> because the operation is suicidal, but this deserves a comment, unless
> you want to get a note telling you that you caused an imbalance every
> few weeks.
>
>         Regards
>                 Oliver
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-06-25 23:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-24 18:11 [PATCH v2] Bluetooth: btusb: Reset port on cmd timeout Abhishek Pandit-Subedi
2020-06-24 18:27 ` Marcel Holtmann
2020-06-25 10:22 ` Oliver Neukum
2020-06-25 23:18   ` Abhishek Pandit-Subedi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).