All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/5] Bluetooth: qca: fix device-address endianness
@ 2024-03-19 15:29 Johan Hovold
  2024-03-19 15:29 ` [PATCH v3 1/5] dt-bindings: bluetooth: add 'qcom,local-bd-address-broken' Johan Hovold
                   ` (4 more replies)
  0 siblings, 5 replies; 26+ messages in thread
From: Johan Hovold @ 2024-03-19 15:29 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz, Bjorn Andersson
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	cros-qcom-dts-watchers, Konrad Dybcio, Johan Hedberg,
	Balakrishna Godavarthi, Matthias Kaehlcke, Douglas Anderson,
	Rocky Liao, Dmitry Baryshkov, linux-bluetooth, netdev, devicetree,
	linux-arm-msm, linux-kernel, Johan Hovold

The Qualcomm Bluetooth driver is configuring the device address in
reverse order for none-ROME devices, which breaks user space tools like
btmgmt and the 'local-bd-address' devicetree property.

As these Qualcomm controllers lack persistent storage for the device
address, boot firmware can use the 'local-bd-address' devicetree
property to provide a valid address. The property should specify the
address in little endian order but instead some boot firmware has been
reversing the address to match the buggy Qualcomm driver.

This specifically affects some Chromebook devices for which we now need
to maintain compatibility with the current boot firmware. As ChromeOS
updates the kernel and devicetree in lockstep, this can be done by
adding a new 'qcom,local-bd-address-broken' property that can be used to
determine if the firmware passes the address in the wrong byte order.
[1][2]

Note that this series depends on the following revert:

	https://lore.kernel.org/lkml/20240314084412.1127-1-johan+linaro@kernel.org/

Also note that the final patch is expected to be merged through the
Qualcomm SoC tree once the first four patches have been picked up by the
Bluetooth maintainers.

Johan


[1] https://lore.kernel.org/lkml/ZcuWQkmYK4Ax9kam@google.com/
[2] https://lore.kernel.org/lkml/CAD=FV=WCzrh926mkiyBnKRG_+KGuOkGN6v0DgPiXhQCD3PSQ9w@mail.gmail.com/


Changes in v3
 - add a 'qcom,local-bd-address-broken' property instead of deprecating
   the current WCN3991 binding
 - mark the bluetooth address on SC7180 Trogdor Chromebooks as broken

Changes in v2
 - add quirk to handle deprecated devicetree compatibles that expect
   broken address properties
 - deprecate 'qcom,wcn3991-bt' and mark it as broken



Johan Hovold (5):
  dt-bindings: bluetooth: add 'qcom,local-bd-address-broken'
  Bluetooth: add quirk for broken address properties
  Bluetooth: qca: fix device-address endianness
  Bluetooth: qca: add workaround for broken address properties
  arm64: dts: qcom: sc7180-trogdor: mark bluetooth address as broken

 .../bindings/net/bluetooth/qualcomm-bluetooth.yaml     |  3 +++
 arch/arm64/boot/dts/qcom/sc7180-trogdor.dtsi           |  2 ++
 drivers/bluetooth/btqca.c                              |  8 ++++++--
 drivers/bluetooth/hci_qca.c                            | 10 ++++++++++
 include/net/bluetooth/hci.h                            |  9 +++++++++
 net/bluetooth/hci_sync.c                               |  5 ++++-
 6 files changed, 34 insertions(+), 3 deletions(-)

-- 
2.43.2


^ permalink raw reply	[flat|nested] 26+ messages in thread
* [PATCH v4 1/4] dt-bindings: bluetooth: add 'qcom,local-bd-address-broken'
@ 2024-03-20  7:55 Johan Hovold
  2024-03-20  8:15 ` Bluetooth: qca: fix device-address endianness bluez.test.bot
  0 siblings, 1 reply; 26+ messages in thread
From: Johan Hovold @ 2024-03-20  7:55 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz, Bjorn Andersson
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	cros-qcom-dts-watchers, Konrad Dybcio, Johan Hedberg,
	Balakrishna Godavarthi, Matthias Kaehlcke, Douglas Anderson,
	Rocky Liao, Dmitry Baryshkov, linux-bluetooth, netdev, devicetree,
	linux-arm-msm, linux-kernel, Johan Hovold

Several Qualcomm Bluetooth controllers lack persistent storage for the
device address and instead one can be provided by the boot firmware
using the 'local-bd-address' devicetree property.

The Bluetooth bindings clearly states that the address should be
specified in little-endian order, but due to a long-standing bug in the
Qualcomm driver which reversed the address some boot firmware has been
providing the address in big-endian order instead.

The only device out there that should be affected by this is the WCN3991
used in some Chromebooks.

Add a 'qcom,local-bd-address-broken' property which can be set on these
platforms to indicate that the boot firmware is using the wrong byte
order.

Note that ChromeOS always updates the kernel and devicetree in lockstep
so that there is no need to handle backwards compatibility with older
devicetrees.

Reviewed-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
---
 .../devicetree/bindings/net/bluetooth/qualcomm-bluetooth.yaml | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/bluetooth/qualcomm-bluetooth.yaml b/Documentation/devicetree/bindings/net/bluetooth/qualcomm-bluetooth.yaml
index eba2f3026ab0..fdaea08e7442 100644
--- a/Documentation/devicetree/bindings/net/bluetooth/qualcomm-bluetooth.yaml
+++ b/Documentation/devicetree/bindings/net/bluetooth/qualcomm-bluetooth.yaml
@@ -94,6 +94,10 @@ properties:
 
   local-bd-address: true
 
+  qcom,local-bd-address-broken:
+    type: boolean
+    description:
+      boot firmware is incorrectly passing the address in big-endian order
 
 required:
   - compatible
-- 
2.43.2


^ permalink raw reply related	[flat|nested] 26+ messages in thread
* [PATCH v2 1/4] dt-bindings: bluetooth: add new wcn3991 compatible to fix bd_addr
@ 2024-03-18 11:08 Johan Hovold
  2024-03-18 11:36 ` Bluetooth: qca: fix device-address endianness bluez.test.bot
  0 siblings, 1 reply; 26+ messages in thread
From: Johan Hovold @ 2024-03-18 11:08 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Johan Hedberg,
	Matthias Kaehlcke, Doug Anderson, Bjorn Andersson, Konrad Dybcio,
	linux-bluetooth, linux-arm-msm, netdev, devicetree, linux-kernel,
	Johan Hovold

Several Qualcomm Bluetooth controllers lack persistent storage for the
device address and instead one can be provided by the boot firmware
using the 'local-bd-address' devicetree property.

The Bluetooth bindings clearly says that the address should be specified
in little-endian order, but due to a long-standing bug in the Qualcomm
driver which reversed the address some bootloaders have been providing
the address in big-endian order instead.

The only device out there that should be affected by this is the WCN3991
used in some Chromebooks. To maintain backwards compatibility, mark the
current compatible string as deprecated and add a new
'qcom,wcn3991-bt-bdaddr-le' for firmware which conforms with the
binding.

Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
---
 .../net/bluetooth/qualcomm-bluetooth.yaml     | 29 +++++++++++--------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/bluetooth/qualcomm-bluetooth.yaml b/Documentation/devicetree/bindings/net/bluetooth/qualcomm-bluetooth.yaml
index eba2f3026ab0..b6fce6d02138 100644
--- a/Documentation/devicetree/bindings/net/bluetooth/qualcomm-bluetooth.yaml
+++ b/Documentation/devicetree/bindings/net/bluetooth/qualcomm-bluetooth.yaml
@@ -15,18 +15,22 @@ description:
 
 properties:
   compatible:
-    enum:
-      - qcom,qca2066-bt
-      - qcom,qca6174-bt
-      - qcom,qca9377-bt
-      - qcom,wcn3988-bt
-      - qcom,wcn3990-bt
-      - qcom,wcn3991-bt
-      - qcom,wcn3998-bt
-      - qcom,qca6390-bt
-      - qcom,wcn6750-bt
-      - qcom,wcn6855-bt
-      - qcom,wcn7850-bt
+    oneOf:
+      - enum:
+          - qcom,qca2066-bt
+          - qcom,qca6174-bt
+          - qcom,qca9377-bt
+          - qcom,wcn3988-bt
+          - qcom,wcn3990-bt
+          - qcom,wcn3991-bt-bdaddr-le
+          - qcom,wcn3998-bt
+          - qcom,qca6390-bt
+          - qcom,wcn6750-bt
+          - qcom,wcn6855-bt
+          - qcom,wcn7850-bt
+      - enum:
+          - qcom,wcn3991-bt
+        deprecated: true
 
   enable-gpios:
     maxItems: 1
@@ -122,6 +126,7 @@ allOf:
               - qcom,wcn3988-bt
               - qcom,wcn3990-bt
               - qcom,wcn3991-bt
+              - qcom,wcn3991-bt-bdaddr-le
               - qcom,wcn3998-bt
     then:
       required:
-- 
2.43.2


^ permalink raw reply related	[flat|nested] 26+ messages in thread
* [PATCH] Bluetooth: qca: fix device-address endianness
@ 2023-12-27 18:03 Johan Hovold
  2023-12-27 18:34 ` bluez.test.bot
  0 siblings, 1 reply; 26+ messages in thread
From: Johan Hovold @ 2023-12-27 18:03 UTC (permalink / raw)
  To: Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz
  Cc: Bjorn Andersson, Konrad Dybcio, linux-bluetooth, linux-arm-msm,
	linux-kernel, Johan Hovold, stable, Balakrishna Godavarthi,
	Matthias Kaehlcke

The WCN6855 firmware on the Lenovo ThinkPad X13s expects the Bluetooth
device address in MSB order when setting it using the
EDL_WRITE_BD_ADDR_OPCODE command.

Presumably, this is the case for all non-ROME devices which all use the
EDL_WRITE_BD_ADDR_OPCODE command for this (unlike the ROME devices which
use a different command and expect the address in LSB order).

Reverse the little-endian address before setting it to make sure that
the address can be configured using tools like btmgmt or using the
'local-bd-address' devicetree property.

Note that this can potentially break systems with boot firmware which
has started relying on the broken behaviour and is incorrectly passing
the address via devicetree in MSB order.

Fixes: 5c0a1001c8be ("Bluetooth: hci_qca: Add helper to set device address")
Cc: stable@vger.kernel.org      # 5.1
Cc: Balakrishna Godavarthi <quic_bgodavar@quicinc.com>
Cc: Matthias Kaehlcke <mka@chromium.org>
Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
---

Hi Qualcomm people,

Could you please verify with your documentation that all non-ROME
devices expect the address provided in the EDL_WRITE_BD_ADDR_OPCODE
command in MSB order?

I assume this is not something that anyone would change between firmware
revisions, but if that turns out to be the case, we'd need to reverse
the address based on firmware revision or similar.

Johan


 drivers/bluetooth/btqca.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/bluetooth/btqca.c b/drivers/bluetooth/btqca.c
index fdb0fae88d1c..29035daf21bc 100644
--- a/drivers/bluetooth/btqca.c
+++ b/drivers/bluetooth/btqca.c
@@ -826,11 +826,15 @@ EXPORT_SYMBOL_GPL(qca_uart_setup);
 
 int qca_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
 {
+	bdaddr_t bdaddr_swapped;
 	struct sk_buff *skb;
 	int err;
 
-	skb = __hci_cmd_sync_ev(hdev, EDL_WRITE_BD_ADDR_OPCODE, 6, bdaddr,
-				HCI_EV_VENDOR, HCI_INIT_TIMEOUT);
+	baswap(&bdaddr_swapped, bdaddr);
+
+	skb = __hci_cmd_sync_ev(hdev, EDL_WRITE_BD_ADDR_OPCODE, 6,
+				&bdaddr_swapped, HCI_EV_VENDOR,
+				HCI_INIT_TIMEOUT);
 	if (IS_ERR(skb)) {
 		err = PTR_ERR(skb);
 		bt_dev_err(hdev, "QCA Change address cmd failed (%d)", err);
-- 
2.41.0


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

end of thread, other threads:[~2024-03-20  8:15 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-19 15:29 [PATCH v3 0/5] Bluetooth: qca: fix device-address endianness Johan Hovold
2024-03-19 15:29 ` [PATCH v3 1/5] dt-bindings: bluetooth: add 'qcom,local-bd-address-broken' Johan Hovold
2024-03-19 15:37   ` Bluetooth: qca: fix device-address endianness bluez.test.bot
2024-03-19 16:10   ` [PATCH v3 1/5] dt-bindings: bluetooth: add 'qcom,local-bd-address-broken' Doug Anderson
2024-03-19 16:22     ` Johan Hovold
2024-03-19 20:02   ` Rob Herring
2024-03-19 15:29 ` [PATCH v3 2/5] Bluetooth: add quirk for broken address properties Johan Hovold
2024-03-19 16:10   ` Doug Anderson
2024-03-19 16:16     ` Konrad Dybcio
2024-03-19 16:26     ` Johan Hovold
2024-03-19 17:01       ` Dmitry Baryshkov
2024-03-19 17:38         ` Johan Hovold
2024-03-19 17:02       ` Luiz Augusto von Dentz
2024-03-19 17:04         ` Luiz Augusto von Dentz
2024-03-19 15:29 ` [PATCH v3 3/5] Bluetooth: qca: fix device-address endianness Johan Hovold
2024-03-19 16:10   ` Doug Anderson
2024-03-19 16:38     ` Johan Hovold
2024-03-19 17:12       ` Doug Anderson
2024-03-19 17:28         ` Johan Hovold
2024-03-19 17:33           ` Doug Anderson
2024-03-19 15:29 ` [PATCH v3 4/5] Bluetooth: qca: add workaround for broken address properties Johan Hovold
2024-03-19 15:29 ` [PATCH v3 5/5] arm64: dts: qcom: sc7180-trogdor: mark bluetooth address as broken Johan Hovold
2024-03-19 16:10   ` Doug Anderson
  -- strict thread matches above, loose matches on Subject: below --
2024-03-20  7:55 [PATCH v4 1/4] dt-bindings: bluetooth: add 'qcom,local-bd-address-broken' Johan Hovold
2024-03-20  8:15 ` Bluetooth: qca: fix device-address endianness bluez.test.bot
2024-03-18 11:08 [PATCH v2 1/4] dt-bindings: bluetooth: add new wcn3991 compatible to fix bd_addr Johan Hovold
2024-03-18 11:36 ` Bluetooth: qca: fix device-address endianness bluez.test.bot
2023-12-27 18:03 [PATCH] " Johan Hovold
2023-12-27 18:34 ` bluez.test.bot

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.