diff mbox series

Bluetooth: Move shutdown callback before flushing tx and rx queue

Message ID 20210809174358.163525-1-kai.heng.feng@canonical.com
State Accepted
Commit 0ea53674d07fb6db2dd7a7ec2fdc85a12eb246c2
Headers show
Series Bluetooth: Move shutdown callback before flushing tx and rx queue | expand

Commit Message

Kai-Heng Feng Aug. 9, 2021, 5:43 p.m. UTC
Commit 0ea9fd001a14 ("Bluetooth: Shutdown controller after workqueues
are flushed or cancelled") introduced a regression that makes mtkbtsdio
driver stops working:
[   36.593956] Bluetooth: hci0: Firmware already downloaded
[   46.814613] Bluetooth: hci0: Execution of wmt command timed out
[   46.814619] Bluetooth: hci0: Failed to send wmt func ctrl (-110)

The shutdown callback depends on the result of hdev->rx_work, so we
should call it before flushing rx_work:
-> btmtksdio_shutdown()
 -> mtk_hci_wmt_sync()
  -> __hci_cmd_send()
   -> wait for BTMTKSDIO_TX_WAIT_VND_EVT gets cleared

-> btmtksdio_recv_event()
 -> hci_recv_frame()
  -> queue_work(hdev->workqueue, &hdev->rx_work)
   -> clears BTMTKSDIO_TX_WAIT_VND_EVT

So move the shutdown callback before flushing TX/RX queue to resolve the
issue.

Reported-and-tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Tested-by: Hsin-Yi Wang <hsinyi@chromium.org>
Cc: Guenter Roeck <linux@roeck-us.net>
Fixes: 0ea9fd001a14 ("Bluetooth: Shutdown controller after workqueues are flushed or cancelled")
Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
 net/bluetooth/hci_core.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

Comments

Hsin-Yi Wang Aug. 10, 2021, 4:10 a.m. UTC | #1
On Tue, Aug 10, 2021 at 1:44 AM Kai-Heng Feng
<kai.heng.feng@canonical.com> wrote:
>

> Commit 0ea9fd001a14 ("Bluetooth: Shutdown controller after workqueues

> are flushed or cancelled") introduced a regression that makes mtkbtsdio

> driver stops working:

> [   36.593956] Bluetooth: hci0: Firmware already downloaded

> [   46.814613] Bluetooth: hci0: Execution of wmt command timed out

> [   46.814619] Bluetooth: hci0: Failed to send wmt func ctrl (-110)

>

> The shutdown callback depends on the result of hdev->rx_work, so we

> should call it before flushing rx_work:

> -> btmtksdio_shutdown()

>  -> mtk_hci_wmt_sync()

>   -> __hci_cmd_send()

>    -> wait for BTMTKSDIO_TX_WAIT_VND_EVT gets cleared

>

> -> btmtksdio_recv_event()

>  -> hci_recv_frame()

>   -> queue_work(hdev->workqueue, &hdev->rx_work)

>    -> clears BTMTKSDIO_TX_WAIT_VND_EVT

>

> So move the shutdown callback before flushing TX/RX queue to resolve the

> issue.

>

> Reported-and-tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

> Tested-by: Hsin-Yi Wang <hsinyi@chromium.org>


Hello,

Sorry for confusion, but the version I tested is this one:
https://lkml.org/lkml/2021/8/4/486 (shutdown is prior to the
test_and_clear HCI_UP)
I tested this version and still see the error I've seen before.




> Cc: Guenter Roeck <linux@roeck-us.net>

> Fixes: 0ea9fd001a14 ("Bluetooth: Shutdown controller after workqueues are flushed or cancelled")

> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>

> ---

>  net/bluetooth/hci_core.c | 16 ++++++++--------

>  1 file changed, 8 insertions(+), 8 deletions(-)

>

> diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c

> index cb2e9e513907..8da04c899197 100644

> --- a/net/bluetooth/hci_core.c

> +++ b/net/bluetooth/hci_core.c

> @@ -1735,6 +1735,14 @@ int hci_dev_do_close(struct hci_dev *hdev)

>

>         hci_leds_update_powered(hdev, false);

>

> +       if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) &&

> +           !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&

> +           test_bit(HCI_UP, &hdev->flags)) {

> +               /* Execute vendor specific shutdown routine */

> +               if (hdev->shutdown)

> +                       hdev->shutdown(hdev);

> +       }

> +

>         /* Flush RX and TX works */

>         flush_work(&hdev->tx_work);

>         flush_work(&hdev->rx_work);

> @@ -1798,14 +1806,6 @@ int hci_dev_do_close(struct hci_dev *hdev)

>                 clear_bit(HCI_INIT, &hdev->flags);

>         }

>

> -       if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) &&

> -           !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&

> -           test_bit(HCI_UP, &hdev->flags)) {

> -               /* Execute vendor specific shutdown routine */

> -               if (hdev->shutdown)

> -                       hdev->shutdown(hdev);

> -       }

> -

>         /* flush cmd  work */

>         flush_work(&hdev->cmd_work);

>

> --

> 2.31.1

>
Kai-Heng Feng Aug. 10, 2021, 4:37 a.m. UTC | #2
On Tue, Aug 10, 2021 at 12:10 PM Hsin-Yi Wang <hsinyi@chromium.org> wrote:
>

> On Tue, Aug 10, 2021 at 1:44 AM Kai-Heng Feng

> <kai.heng.feng@canonical.com> wrote:

> >

> > Commit 0ea9fd001a14 ("Bluetooth: Shutdown controller after workqueues

> > are flushed or cancelled") introduced a regression that makes mtkbtsdio

> > driver stops working:

> > [   36.593956] Bluetooth: hci0: Firmware already downloaded

> > [   46.814613] Bluetooth: hci0: Execution of wmt command timed out

> > [   46.814619] Bluetooth: hci0: Failed to send wmt func ctrl (-110)

> >

> > The shutdown callback depends on the result of hdev->rx_work, so we

> > should call it before flushing rx_work:

> > -> btmtksdio_shutdown()

> >  -> mtk_hci_wmt_sync()

> >   -> __hci_cmd_send()

> >    -> wait for BTMTKSDIO_TX_WAIT_VND_EVT gets cleared

> >

> > -> btmtksdio_recv_event()

> >  -> hci_recv_frame()

> >   -> queue_work(hdev->workqueue, &hdev->rx_work)

> >    -> clears BTMTKSDIO_TX_WAIT_VND_EVT

> >

> > So move the shutdown callback before flushing TX/RX queue to resolve the

> > issue.

> >

> > Reported-and-tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

> > Tested-by: Hsin-Yi Wang <hsinyi@chromium.org>

>

> Hello,

>

> Sorry for confusion, but the version I tested is this one:

> https://lkml.org/lkml/2021/8/4/486 (shutdown is prior to the

> test_and_clear HCI_UP)

> I tested this version and still see the error I've seen before.


Ah, sorry for causing your trouble, I am the one who got confused :(
HCI_UP is obviously required for hci_req_sync() to work.

Let me resend one, and sorry again!

Kai-Heng

>

>

>

>

> > Cc: Guenter Roeck <linux@roeck-us.net>

> > Fixes: 0ea9fd001a14 ("Bluetooth: Shutdown controller after workqueues are flushed or cancelled")

> > Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>

> > ---

> >  net/bluetooth/hci_core.c | 16 ++++++++--------

> >  1 file changed, 8 insertions(+), 8 deletions(-)

> >

> > diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c

> > index cb2e9e513907..8da04c899197 100644

> > --- a/net/bluetooth/hci_core.c

> > +++ b/net/bluetooth/hci_core.c

> > @@ -1735,6 +1735,14 @@ int hci_dev_do_close(struct hci_dev *hdev)

> >

> >         hci_leds_update_powered(hdev, false);

> >

> > +       if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) &&

> > +           !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&

> > +           test_bit(HCI_UP, &hdev->flags)) {

> > +               /* Execute vendor specific shutdown routine */

> > +               if (hdev->shutdown)

> > +                       hdev->shutdown(hdev);

> > +       }

> > +

> >         /* Flush RX and TX works */

> >         flush_work(&hdev->tx_work);

> >         flush_work(&hdev->rx_work);

> > @@ -1798,14 +1806,6 @@ int hci_dev_do_close(struct hci_dev *hdev)

> >                 clear_bit(HCI_INIT, &hdev->flags);

> >         }

> >

> > -       if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) &&

> > -           !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&

> > -           test_bit(HCI_UP, &hdev->flags)) {

> > -               /* Execute vendor specific shutdown routine */

> > -               if (hdev->shutdown)

> > -                       hdev->shutdown(hdev);

> > -       }

> > -

> >         /* flush cmd  work */

> >         flush_work(&hdev->cmd_work);

> >

> > --

> > 2.31.1

> >
diff mbox series

Patch

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index cb2e9e513907..8da04c899197 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1735,6 +1735,14 @@  int hci_dev_do_close(struct hci_dev *hdev)
 
 	hci_leds_update_powered(hdev, false);
 
+	if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) &&
+	    !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&
+	    test_bit(HCI_UP, &hdev->flags)) {
+		/* Execute vendor specific shutdown routine */
+		if (hdev->shutdown)
+			hdev->shutdown(hdev);
+	}
+
 	/* Flush RX and TX works */
 	flush_work(&hdev->tx_work);
 	flush_work(&hdev->rx_work);
@@ -1798,14 +1806,6 @@  int hci_dev_do_close(struct hci_dev *hdev)
 		clear_bit(HCI_INIT, &hdev->flags);
 	}
 
-	if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) &&
-	    !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&
-	    test_bit(HCI_UP, &hdev->flags)) {
-		/* Execute vendor specific shutdown routine */
-		if (hdev->shutdown)
-			hdev->shutdown(hdev);
-	}
-
 	/* flush cmd  work */
 	flush_work(&hdev->cmd_work);