Skip to contentSkip to conversation

Bluetooth: qca: fix device-address endianness

PATCH Applied Johan Hovold 5 participants 9 messages Mar 20, 2024 – Mar 26, 2024

Subsystems (10)
lore
Share & tools
lore
#0 lore raw

v4 cover Bluetooth: qca: fix device-address endianness

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/[email protected]/

Also note that the devicetree patch (patch 2/4) is expected to be merged through the Qualcomm SoC tree once the other three patches have been picked up by the Bluetooth maintainers.

An alternative would be if Bjorn could ack the DT patch so that everything can go in through the Bluetooth tree.

Johan

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

Changes in v4
- add the missing type for the new vendor property to the binding
- move the Trogdor DT patch after the binding patch and combine the endianness fix and Chromium workaround to avoid having any point in the series where the address is reversed on those platforms as requested by Doug

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 (4):
dt-bindings: bluetooth: add 'qcom,local-bd-address-broken'
arm64: dts: qcom: sc7180-trogdor: mark bluetooth address as broken
Bluetooth: add quirk for broken address properties
Bluetooth: qca: fix device-address endianness

 .../bindings/net/bluetooth/qualcomm-bluetooth.yaml     |  4 ++++
 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, 35 insertions(+), 3 deletions(-)
Signature · 1 line
2.43.2
#1 lore raw

PATCH v4 1/4 dt-bindings: bluetooth: add 'qcom,local-bd-address-broken'

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.

---
 .../devicetree/bindings/net/bluetooth/qualcomm-bluetooth.yaml | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/net/bluetooth/qualcomm-bluetooth.yaml +4 -0
index eba2f3026ab0..fdaea08e7442 100644
@@ -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
Signature · 1 line
2.43.2
#2 lore raw

This is an automated email and please do not reply to this email.

Dear Submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
While preparing the CI tests, the patches you submitted couldn't be applied to the current HEAD of the repository.

----- Output -----

error: patch failed: drivers/bluetooth/hci_qca.c:1904
error: drivers/bluetooth/hci_qca.c: patch does not apply
hint: Use 'git am --show-current-patch' to see the failed patch

Please resolve the issue and submit the patches again.

---
Regards,
Linux Bluetooth

maintainer Reviewed-by on v4 1/4
#3 lore raw

Re: [PATCH v4 1/4] dt-bindings: bluetooth: add 'qcom,local-bd-address-broken'

In reply to Johan Hovold
Quoted 20 lines · 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.

Quoted 6 lines
---
 .../devicetree/bindings/net/bluetooth/qualcomm-bluetooth.yaml | 4 ++++
 1 file changed, 4 insertions(+)
#4 lore raw

PATCH v4 2/4 arm64: dts: qcom: sc7180-trogdor: mark bluetooth address as broken

In reply to 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 boot firmware in SC7180 Trogdor Chromebooks is known to be affected so mark the 'local-bd-address' property as broken to maintain backwards compatibility with older firmware when fixing the underlying driver bug.

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

Fixes 7ec3e67307f8 ("arm64: dts: qcom: sc7180-trogdor: add initial trogdor and lazor dt")
Cc Rob Clark <[email protected]>
---
 arch/arm64/boot/dts/qcom/sc7180-trogdor.dtsi | 2 ++
 1 file changed, 2 insertions(+)
arch/arm64/boot/dts/qcom/sc7180-trogdor.dtsi +2 -0
index 46aaeba28604..ebe37678102f 100644
@@ -943,6 +943,8 @@ bluetooth: bluetooth {
 		vddrf-supply = <&pp1300_l2c>;
 		vddch0-supply = <&pp3300_l10c>;
 		max-speed = <3200000>;
+
+		qcom,local-bd-address-broken;
 	};
 };
 
Signature · 1 line
2.43.2
maintainer Acked-by Reviewed-by on v4 2/4
#5 lore raw

Re: [PATCH v4 2/4] arm64: dts: qcom: sc7180-trogdor: mark bluetooth address as broken

Quoted 17 lines · 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 boot firmware in SC7180 Trogdor Chromebooks is known to be affected so mark the 'local-bd-address' property as broken to maintain backwards compatibility with older firmware when fixing the underlying driver bug.

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

Quoted 5 lines
Fixes 7ec3e67307f8 ("arm64: dts: qcom: sc7180-trogdor: add initial trogdor and lazor dt")
Cc Rob Clark <[email protected]>

Please merge this through the BT tree, together with the other patches.

Regards,
Bjorn

Quoted 20 lines
---
 arch/arm64/boot/dts/qcom/sc7180-trogdor.dtsi | 2 ++
 1 file changed, 2 insertions(+)
arch/arm64/boot/dts/qcom/sc7180-trogdor.dtsi +2 -0
index 46aaeba28604..ebe37678102f 100644
@@ -943,6 +943,8 @@ bluetooth: bluetooth {
 		vddrf-supply = <&pp1300_l2c>;
 		vddch0-supply = <&pp3300_l10c>;
 		max-speed = <3200000>;
+
+		qcom,local-bd-address-broken;
 	};
 };
 
Signature · 1 line
2.43.2
#6 lore raw

PATCH v4 3/4 Bluetooth: add quirk for broken address properties

In reply to Johan Hovold

Some 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 devicetree 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.

Add a new quirk that can be set on platforms with broken firmware and use it to reverse the address when parsing the property so that the underlying driver bug can be fixed.

Fixes 5c0a1001c8be ("Bluetooth: hci_qca: Add helper to set device address")
---
 include/net/bluetooth/hci.h | 9 +++++++++
 net/bluetooth/hci_sync.c    | 5 ++++-
 2 files changed, 13 insertions(+), 1 deletion(-)
include/net/bluetooth/hci.h +9 -0
index bdee5d649cc6..191077d8d578 100644
@@ -176,6 +176,15 @@ enum {
 	 */
 	HCI_QUIRK_USE_BDADDR_PROPERTY,
 
+	/* When this quirk is set, the Bluetooth Device Address provided by
+	 * the 'local-bd-address' fwnode property is incorrectly specified in
+	 * big-endian order.
+	 *
+	 * This quirk can be set before hci_register_dev is called or
+	 * during the hdev->setup vendor callback.
+	 */
+	HCI_QUIRK_BDADDR_PROPERTY_BROKEN,
+
 	/* When this quirk is set, the duplicate filtering during
 	 * scanning is based on Bluetooth devices addresses. To allow
 	 * RSSI based updates, restart scanning if needed.
net/bluetooth/hci_sync.c +4 -1
index 5716345a26df..283ae8edc1e5 100644
@@ -3215,7 +3215,10 @@ static void hci_dev_get_bd_addr_from_property(struct hci_dev *hdev)
 	if (ret < 0 || !bacmp(&ba, BDADDR_ANY))
 		return;
 
-	bacpy(&hdev->public_addr, &ba);
+	if (test_bit(HCI_QUIRK_BDADDR_PROPERTY_BROKEN, &hdev->quirks))
+		baswap(&hdev->public_addr, &ba);
+	else
+		bacpy(&hdev->public_addr, &ba);
 }
 
 struct hci_init_stage {
Signature · 1 line
2.43.2
#7 lore raw

PATCH v4 4/4 Bluetooth: qca: fix device-address endianness

In reply to Johan Hovold

The WCN6855 firmware on the Lenovo ThinkPad X13s expects the Bluetooth device address in big-endian 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 little-endian 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 big-endian order.

The only device affected by this should be the WCN3991 used in some Chromebooks. As ChromeOS updates the kernel and devicetree in lockstep, the new 'qcom,local-bd-address-broken' property can be used to determine if the firmware is buggy so that the underlying driver bug can be fixed without breaking backwards compatibility.

Set the HCI_QUIRK_BDADDR_PROPERTY_BROKEN quirk for such platforms so that the address is reversed when parsing the address property.

Fixes 5c0a1001c8be ("Bluetooth: hci_qca: Add helper to set device address")
Cc Balakrishna Godavarthi <[email protected]>
Cc Matthias Kaehlcke <[email protected]>
---
 drivers/bluetooth/btqca.c   |  8 ++++++--
 drivers/bluetooth/hci_qca.c | 10 ++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)
drivers/bluetooth/btqca.c +6 -2
index b40b32fa7f1c..19cfc342fc7b 100644
@@ -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);
drivers/bluetooth/hci_qca.c +10 -0
index f989c05f8177..c73481c57741 100644
@@ -225,6 +225,7 @@ struct qca_serdev {
 	struct qca_power *bt_power;
 	u32 init_speed;
 	u32 oper_speed;
+	bool bdaddr_property_broken;
 	const char *firmware_name;
 };
 
@@ -1842,6 +1843,7 @@ static int qca_setup(struct hci_uart *hu)
 	const char *firmware_name = qca_get_firmware_name(hu);
 	int ret;
 	struct qca_btsoc_version ver;
+	struct qca_serdev *qcadev;
 	const char *soc_name;
 
 	ret = qca_check_speeds(hu);
@@ -1904,6 +1906,11 @@ static int qca_setup(struct hci_uart *hu)
 	case QCA_WCN6855:
 	case QCA_WCN7850:
 		set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks);
+
+		qcadev = serdev_device_get_drvdata(hu->serdev);
+		if (qcadev->bdaddr_property_broken)
+			set_bit(HCI_QUIRK_BDADDR_PROPERTY_BROKEN, &hdev->quirks);
+
 		hci_set_aosp_capable(hdev);
 
 		ret = qca_read_soc_version(hdev, &ver, soc_type);
@@ -2284,6 +2291,9 @@ static int qca_serdev_probe(struct serdev_device *serdev)
 	if (!qcadev->oper_speed)
 		BT_DBG("UART will pick default operating speed");
 
+	qcadev->bdaddr_property_broken = device_property_read_bool(&serdev->dev,
+			"qcom,local-bd-address-broken");
+
 	if (data)
 		qcadev->btsoc_type = data->soc_type;
 	else
Signature · 1 line
2.43.2
#8 lore raw
In reply to Johan Hovold
This series was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This series was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 11 lines · On Wed, 20 Mar 2024 08:55:50 +0100 you wrote:

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.

[...]

Here is the summary with links:
- [v4,1/4] dt-bindings: bluetooth: add 'qcom,local-bd-address-broken'

    https://git.kernel.org/bluetooth/bluetooth-next/c/ea56aab91231
  - [v4,2/4] arm64: dts: qcom: sc7180-trogdor: mark bluetooth address as broken
    https://git.kernel.org/bluetooth/bluetooth-next/c/c4406d97b78c
  - [v4,3/4] Bluetooth: add quirk for broken address properties
    https://git.kernel.org/bluetooth/bluetooth-next/c/ddaa064664fe
  - [v4,4/4] Bluetooth: qca: fix device-address endianness
    https://git.kernel.org/bluetooth/bluetooth-next/c/ff2ed85c0122

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html