All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marcel Ziswiler <marcel.ziswiler@toradex.com>
To: "neeraj.sanjaykale@nxp.com" <neeraj.sanjaykale@nxp.com>,
	"linux-bluetooth@vger.kernel.org"
	<linux-bluetooth@vger.kernel.org>
Cc: "luiz.dentz@gmail.com" <luiz.dentz@gmail.com>,
	"sherry.sun@nxp.com" <sherry.sun@nxp.com>,
	"johan.hedberg@gmail.com" <johan.hedberg@gmail.com>,
	"amitkumar.karwar@nxp.com" <amitkumar.karwar@nxp.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"marcel@holtmann.org" <marcel@holtmann.org>,
	"ilpo.jarvinen@linux.intel.com" <ilpo.jarvinen@linux.intel.com>
Subject: Re: [PATCH v1 2/2] Bluetooth: btnxpuart: Fix nxp_setup
Date: Wed, 18 Oct 2023 16:41:41 +0000	[thread overview]
Message-ID: <dca8bc7fec5f527cac2e280cd8ed4edae1f473ea.camel@toradex.com> (raw)
In-Reply-To: <AM9PR04MB860351E818A6DD715A7F88FDE7D5A@AM9PR04MB8603.eurprd04.prod.outlook.com>

Hi Neeraj

On Wed, 2023-10-18 at 15:28 +0000, Neeraj sanjay kale wrote:
> Hi Marcel,
> 
> Thank you for your patch. This change looks good to me.
> 
> I think the scenario you are testing/resolving is:
> 1) Load btnxpuart.ko first (which "may" load BT-only FW if chip is powered on)
> 2) Power cycle or power on chip
> 3) Load WLAN driver with combo FW
> Right?

Yes, kinda, but there are really a slew of issues with this driver or the combination of it with mwifiex_sdio:

1. Shared power-down pin (PD#) between Bluetooth and Wi-Fi
Issue: There is currently no concept in the Linux kernel to achieve this. Last failed attempt [1].
Workaround: Instead of using mmc-pwrseq tied to the Wi-Fi driver (mwifiex_sdio) this could be hogged at boot.
However, then it may no longer easily be controlled e.g. for a (manual) power-cycle.
A novel approach might be using a regulator which could be shared, however, this would require us implementing
regulator support in btnxpuart. Not sure whether you would actually approve us doing so.

2. Bluetooth driver (btnxpuart) vs. Wi-Fi driver (mwifiex) load order
Issue: By default, the Bluetooth driver (btnxpuart) loads before the Wi-Fi driver (mwifiex) and using regular
mmc-pwrseq for mwifiex_sdio will only power-on the module late.
Workaround: The install directive in modprobe.conf could be (ab-)used to enforce mwifiex/mwifiex_sdio to be
loaded first. However, doing so adds an unnecessary dependency with user space and is in general discouraged.

3. Distinguish powered-on vs. powered-off state
Issue: Without that knowledge the driver has a hard time figuring out whether or not it needs to load the
firmware as only if it is powered-on (and/or without firmware) will the Bluetooth part of the module send its
boot signature. So the absence of such boot signature may mean either firmware is already loaded or module
powered-off.
Workaround: The Bluetooth UART RTS pin seems to activate an internal pull-up upon the module being powered on.
However, programmatically it is rather hard to determine this as the regular UART driver (now driving RTS)
usually gets loaded.

4. Determine whether or not to load the firmware
Issue: If it is without firmware (and powered-on) the boot loader will send its boot signature. If there is no
boot signature it could as well also still be powered-off.
Workaround: Also check CTS as it goes up if the firmware is loaded. Unfortunately, integrating this in
btnxpuart is not so trivial as serdev introduces its own asynchronous concurrency which is already used in
existing checks.

5. Deploy separate firmware
Issue: Does not really solve anything resp. as the power-down pin is shared this seems kinda pointless.

Your input on any of those topics is much appreciated.

Thanks!

> Thanks,
> Neeraj

Cheers

Marcel

> > From: Marcel Ziswiler <marcel@ziswiler.com>
> > Sent: Wednesday, October 18, 2023 8:26 PM
> > To: linux-bluetooth@vger.kernel.org
> > Cc: Sherry Sun <sherry.sun@nxp.com>; Johan Hedberg
> > <johan.hedberg@gmail.com>; Luiz Augusto von Dentz
> > <luiz.dentz@gmail.com>; Neeraj sanjay kale <neeraj.sanjaykale@nxp.com>;
> > linux-kernel@vger.kernel.org; Marcel Holtmann <marcel@holtmann.org>;
> > Marcel Ziswiler <marcel.ziswiler@toradex.com>; Amitkumar Karwar
> > <amitkumar.karwar@nxp.com>; Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> > Subject: [PATCH v1 2/2] Bluetooth: btnxpuart: Fix nxp_setup
> > 
> > From: Marcel Ziswiler <marcel.ziswiler@toradex.com>
> > 
> > Unfortunately, nxp_setup() may inadvertently assume that the firmware is
> > already running while the module is not even powered yet.
> > Fix this by waiting up to 10 seconds for the CTS to go up as the combo
> > firmware might be loaded by the Wi-Fi driver over SDIO (mwifiex_sdio).
> > 
> > Fixes: 689ca16e5232 ("Bluetooth: NXP: Add protocol support for NXP
> > Bluetooth chipsets")
> > 
> > Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
> > 
> > ---
> > This is what may happen without this fix:
> > [  284.588177] Bluetooth: hci0: Opcode 0x0c03 failed: -110 [  286.636167]
> > Bluetooth: hci0: Setting wake-up method failed (-110) Unfortunately, even
> > re-loading the btnxpuart kernel module would not recover from this
> > condition.
> > 
> >  drivers/bluetooth/btnxpuart.c | 10 ++++++++++
> >  1 file changed, 10 insertions(+)
> > 
> > diff --git a/drivers/bluetooth/btnxpuart.c b/drivers/bluetooth/btnxpuart.c
> > index 9cb7529eef09..4b83a0aa3459 100644
> > --- a/drivers/bluetooth/btnxpuart.c
> > +++ b/drivers/bluetooth/btnxpuart.c
> > @@ -1021,6 +1021,16 @@ static int nxp_setup(struct hci_dev *hdev)
> >                 if (err < 0)
> >                         return err;
> >         } else {
> > +               /* The combo firmware might be loaded by the Wi-Fi driver over
> > SDIO (mwifiex_sdio).
> > +                * We wait up to 10s for the CTS to go up. Afterwards, we know that
> > the firmware is
> > +                * really ready.
> > +                */
> > +               err = serdev_device_wait_for_cts(nxpdev->serdev, true, 10000);
> > +               if (err) {
> > +                       bt_dev_err(nxpdev->hdev, "Wait for CTS failed with %d", err);
> > +                       return err;
> > +               }
> > +
> >                 bt_dev_dbg(hdev, "FW already running.");
> >                 clear_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state);
> >         }
> > --
> > 2.36.1

  reply	other threads:[~2023-10-18 16:41 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-18 14:55 [PATCH v1 0/2] Bluetooth: btnxpuart: Fixes Marcel Ziswiler
2023-10-18 14:55 ` [PATCH v1 1/2] Bluetooth: btnxpuart: Fix btnxpuart_close Marcel Ziswiler
2023-10-18 15:36   ` Neeraj sanjay kale
2023-10-18 16:23     ` Marcel Ziswiler
2023-10-19  9:41       ` Neeraj sanjay kale
2023-10-18 15:42   ` Bluetooth: btnxpuart: Fixes bluez.test.bot
2023-11-24 20:26   ` [PATCH v1 1/2] Bluetooth: btnxpuart: Fix btnxpuart_close Francesco Dolcini
2024-03-04 16:52     ` Francesco Dolcini
2024-03-04 17:34       ` Luiz Augusto von Dentz
2023-10-18 14:55 ` [PATCH v1 2/2] Bluetooth: btnxpuart: Fix nxp_setup Marcel Ziswiler
2023-10-18 15:28   ` Neeraj sanjay kale
2023-10-18 16:41     ` Marcel Ziswiler [this message]
2023-10-19  9:58       ` Neeraj sanjay kale
2024-01-17  5:18       ` Neeraj Sanjay Kale
2023-10-19 16:44   ` Paul Menzel
2023-10-20  7:56     ` Marcel Ziswiler
2023-10-20 10:39   ` Sherry Sun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=dca8bc7fec5f527cac2e280cd8ed4edae1f473ea.camel@toradex.com \
    --to=marcel.ziswiler@toradex.com \
    --cc=amitkumar.karwar@nxp.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=johan.hedberg@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    --cc=neeraj.sanjaykale@nxp.com \
    --cc=sherry.sun@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.