public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcel Holtmann <marcel@holtmann.org>
To: Andre Heider <a.heider@gmail.com>
Cc: Johan Hedberg <johan.hedberg@gmail.com>,
	linux-bluetooth@vger.kernel.org,
	Ondrej Jirman <megous@megous.com>,
	Jernej Skrabec <jernej.skrabec@siol.net>
Subject: Re: [PATCH v2] bluetooth: bcm: Use HCI_QUIRK_USE_BDADDR_PROPERTY
Date: Tue, 19 Nov 2019 09:16:03 +0100	[thread overview]
Message-ID: <F632534C-C9CC-4F4F-AA58-F4FC053D4226@holtmann.org> (raw)
In-Reply-To: <e813a126-f0fc-afe8-ad4c-5296f0a2dc06@gmail.com>

Hi Andre,

>>> Some devices ship with the controller default address, like the
>>> Orange Pi 3 (BCM4345C5).
>>> 
>>> Allow the bootloader to set a valid address through the device tree.
>>> 
>>> Signed-off-by: Andre Heider <a.heider@gmail.com>
>>> ---
>>> drivers/bluetooth/btbcm.c | 1 +
>>> 1 file changed, 1 insertion(+)
>>> 
>>> diff --git a/drivers/bluetooth/btbcm.c b/drivers/bluetooth/btbcm.c
>>> index 2d2e6d862068..9d16162d01ea 100644
>>> --- a/drivers/bluetooth/btbcm.c
>>> +++ b/drivers/bluetooth/btbcm.c
>>> @@ -439,6 +439,7 @@ int btbcm_finalize(struct hci_dev *hdev)
>>> 	btbcm_check_bdaddr(hdev);
>>> 
>>> 	set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
>>> +	set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks);
>>> 
>>> 	return 0;
>>> }
>> have you actually tested this? I might be mistaken, but the code that I read in hci_dev_do_open() would drop this into unconfigured state since HCI_QURIK_INVALID_BDADDR is still set.
> 
> I thought so, but double-checking something obviously failed...
> 
> What would be an acceptable solution to this HCI_QUIRK_USE_BDADDR_PROPERTY|HCI_QUIRK_INVALID_BDADDR situation?
> 
> Getting rid of the quirk in the driver in e.g. set_bdaddr() doesn't sound right.
> 
> How about:
> 
> diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
> index 04bc79359a17..7bc384be89f8 100644
> --- a/net/bluetooth/hci_core.c
> +++ b/net/bluetooth/hci_core.c
> @@ -1470,7 +1470,8 @@ static int hci_dev_do_open(struct hci_dev *hdev)
>         * start up as unconfigured.
>         */
>        if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) ||
> -           test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks))
> +           (test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) &&
> +            !test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)))
>            hci_dev_set_flag(hdev, HCI_UNCONFIGURED);
> 
>        /* For an unconfigured controller it is required to
> 
> That works for me (double-checked this time ;)

I am not sure yet. I mean we define what HCI_QUIRK_USE_BDADDR_PROPERTY actually means. Right now it means this:

1) Run though ->setup
2) If no public BD_ADDR is set, then try to read from DT
3) If found, try to set, if set fails, abort dev_up

Now there is also another problem that no public BD_ADDR means BDADDR_ANY right now. Which means, for Broadcom chips that is never the case. So HCI_QUIRK_USE_BDADDR_PROPERTY doesn’t even work since their invalid addresses are not BDDADDR_ANY.

The first change needs to be something along these lines:

                if (test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) {
-                       if (!bacmp(&hdev->public_addr, BDADDR_ANY))
+                       if (!bacmp(&hdev->public_addr, BDADDR_ANY) ||
+                           test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks))
                                hci_dev_get_bd_addr_from_property(hdev);

But that is not fully correct either. We also have to consider HCI_QUIRK_NON_PERSISTENT_SETUP.

So this is not an easy fix since we need to spell out the semantics of the interactions of these 3 quirks first.

Regards

Marcel


  reply	other threads:[~2019-11-19  8:16 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-19  6:02 [PATCH v2] bluetooth: bcm: Use HCI_QUIRK_USE_BDADDR_PROPERTY Andre Heider
2019-11-19  6:16 ` Marcel Holtmann
2019-11-19  7:44   ` Andre Heider
2019-11-19  8:16     ` Marcel Holtmann [this message]
2019-11-19  9:21       ` Andre Heider
2019-11-19 12:30         ` Marcel Holtmann
2019-11-20 10:13           ` Andre Heider
2019-11-21  8:28             ` Marcel Holtmann
2019-11-21 11:03               ` Andre Heider
2019-11-21 11:47                 ` Marcel Holtmann
2019-11-21 12:30                   ` Andre Heider
2019-11-21 14:05                     ` Marcel Holtmann
2019-11-21 14:23                       ` Andre Heider
2019-11-21 22:50                         ` Marcel Holtmann

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=F632534C-C9CC-4F4F-AA58-F4FC053D4226@holtmann.org \
    --to=marcel@holtmann.org \
    --cc=a.heider@gmail.com \
    --cc=jernej.skrabec@siol.net \
    --cc=johan.hedberg@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=megous@megous.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox