Skip to contentSkip to conversation

Bluetooth: btusb/btqca/hci_sync: Clean up btusb and fix several bugs

PATCH In review Zijun Hu 4 participants 16 messages Jun 26 – Jun 30

Subsystems (4)
lore
Share & tools
lore

Zijun Hu

author
#0 lore raw

v2 cover Bluetooth: btusb/btqca/hci_sync: Clean up btusb and fix several bugs

This series cleans up btusb in preparation for adding a new chip, QCC2072, and fixes several pre-existing bugs found along the way.

Bug fixes:
- qca_set_bdaddr() waited for HCI_EV_VENDOR, but the controller replies with a Command Complete event.
- btusb_set_bdaddr_wcn6855() sent the BD_ADDR without byte-swapping it.
- btusb QCA populated devcoredump fields on devices where devcoredump is not enabled.
- BTUSB_IGNORE is a bitmask and must be tested with '&', not '=='.

Cleanups:
- Add __hci_reset_sync() helper and use it in qca_send_reset() and btusb_shutdown_qca() to drop open-coded HCI reset boilerplate.
- Simplify hci_reset_sync() and log an error in hci_cc_reset() on a non-zero reset status.
- Record the matched usb_device_id in struct btusb_data and move qca_dump into a dedicated struct btqca_data.
- Reduce a redundant assignment in btusb_probe().

---
Changes in v2:
- Reorder the series so each helper is introduced before its users and
related changes are grouped together.
- btqca: reword "Fix qca_set_bdaddr()", add the btmon (WCN7850) trace,
and add Bartosz's Reviewed-by.
- btusb: add the btmon (WCN6855) trace to the BD_ADDR byte-order fix.
- btusb: rename and reword the devcoredump fix.
- hci_sync: simplify __hci_reset_sync() to return __hci_cmd_sync_status() directly; rename the patch to "Introduce __hci_reset_sync()".
- hci_sync: "Simplify hci_reset_sync()" now returns the status directly;
drop the separate "Fix return value of hci_reset_sync()" patch.
- btqca: replace "Fix undetected error HCI status in qca_send_reset()"
with "Simplify qca_send_reset() by using __hci_reset_sync()" (cleanup,
not a fix; dropped the Fixes tag).
- btusb: reword "Simplify btusb_shutdown_qca()".
- btusb: rename "Initialize @priv_size at declaration" -> "Reduce a
redundant assignment in btusb_probe()".
- New patch: "hci_event: Log error for HCI reset status error in hci_cc_reset()".
- Drop "Move struct btusb_data and macros into btusb.h"; deferred to a follow-up series.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Zijun Hu (12):
Bluetooth: btqca: Fix qca_set_bdaddr() waiting for wrong HCI event
Bluetooth: btusb: Fix BD_ADDR byte order in btusb_set_bdaddr_wcn6855()
Bluetooth: btusb: Record matched usb_device_id into btusb_data
Bluetooth: btusb: QCA: Fix populating devcoredump fields on unenabled devices
Bluetooth: btusb: QCA: move qca_dump out of struct btusb_data
Bluetooth: hci_sync: Introduce __hci_reset_sync() for device drivers
Bluetooth: btqca: Simplify qca_send_reset() by using __hci_reset_sync()
Bluetooth: btusb: Simplify btusb_shutdown_qca() by using __hci_reset_sync()
Bluetooth: hci_sync: Simplify hci_reset_sync()
Bluetooth: hci_event: Log error for HCI reset status error in hci_cc_reset()
Bluetooth: btusb: Reduce a redundant assignment in btusb_probe()
Bluetooth: btusb: Use & instead of == to test bitflag BTUSB_IGNORE

 drivers/bluetooth/btqca.c        | 25 ++----------
 drivers/bluetooth/btusb.c        | 86 +++++++++++++++++++++++-----------------
 include/net/bluetooth/hci_sync.h |  1 +
 net/bluetooth/hci_event.c        |  5 ++-
 net/bluetooth/hci_sync.c         | 16 ++++----
 5 files changed, 66 insertions(+), 67 deletions(-)

---
base-commit: cb20f6afc25b2b54c0fec61b45ac0ec9eb875d59
change-id: 20260622-bt_bugfix-fbb216ca1ff9

Best regards,

Signature · 1 line
Zijun Hu <[email protected]>
author
#1 lore raw

PATCH v2 1/12 Bluetooth: btqca: Fix qca_set_bdaddr() waiting for wrong HCI event

qca_set_bdaddr() waits for HCI_EV_VENDOR when sending EDL_WRITE_BD_ADDR_OPCODE (0xFC14), but the controller responds with Command Complete event as confirmed by btmon on WCN7850:

< HCI Command: Vendor (0x3f|0x0014) plen 6 #3 [hci0]

          11 22 33 44 55 66
Quoted 1 line

HCI Event: Command Complete (0x0e) plen 4 #4 [hci0]

        Vendor (0x3f|0x0014) ncmd 1
          Status: Success (0x00)

Fix by passing 0 as the event parameter to __hci_cmd_sync_ev() to wait for the command complete event instead.

Fixes 5c0a1001c8be ("Bluetooth: hci_qca: Add helper to set device address")
---
 drivers/bluetooth/btqca.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/bluetooth/btqca.c +1 -2
index 04ebe290bc78..27f03690af54 100644
@@ -1029,8 +1029,7 @@ int qca_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
 	baswap(&bdaddr_swapped, bdaddr);
 
 	skb = __hci_cmd_sync_ev(hdev, EDL_WRITE_BD_ADDR_OPCODE, 6,
-				&bdaddr_swapped, HCI_EV_VENDOR,
-				HCI_INIT_TIMEOUT);
+				&bdaddr_swapped, 0, HCI_INIT_TIMEOUT);
 	if (IS_ERR(skb)) {
 		err = PTR_ERR(skb);
 		bt_dev_err(hdev, "QCA Change address cmd failed (%d)", err);
Signature · 1 line
2.34.1
#2 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1116853

---Test result---

Test Summary:

CheckPatch                    PASS      14.56 seconds
VerifyFixes                   PASS      0.39 seconds
VerifySignedoff               PASS      0.30 seconds
GitLint                       FAIL      6.75 seconds
SubjectPrefix                 PASS      3.22 seconds
BuildKernel                   PASS      26.93 seconds
CheckAllWarning               PASS      29.60 seconds
CheckSparse                   PASS      31.00 seconds
BuildKernel32                 PASS      25.89 seconds
CheckKernelLLVM               SKIP      0.00 seconds
TestRunnerSetup               PASS      503.08 seconds
TestRunner_l2cap-tester       FAIL      60.66 seconds
TestRunner_iso-tester         PASS      80.79 seconds
TestRunner_bnep-tester        PASS      18.64 seconds
TestRunner_mgmt-tester        FAIL      206.27 seconds
TestRunner_rfcomm-tester      PASS      25.66 seconds
TestRunner_sco-tester         PASS      32.94 seconds
TestRunner_ioctl-tester       PASS      25.81 seconds
TestRunner_mesh-tester        FAIL      26.24 seconds
TestRunner_smp-tester         PASS      23.77 seconds
TestRunner_userchan-tester    PASS      20.22 seconds
TestRunner_6lowpan-tester     PASS      22.61 seconds
IncrementalBuild              PASS      73.79 seconds

Details
##############################
Test: GitLint - FAIL
Desc: Run gitlint
Output:
[v2,02/12] Bluetooth: btusb: Fix BD_ADDR byte order in btusb_set_bdaddr_wcn6855()

1: T1 Title exceeds max length (81>80): "[v2,02/12] Bluetooth: btusb: Fix BD_ADDR byte order in btusb_set_bdaddr_wcn6855()" [v2,04/12] Bluetooth: btusb: QCA: Fix populating devcoredump fields on unenabled devices

1: T1 Title exceeds max length (88>80): "[v2,04/12] Bluetooth: btusb: QCA: Fix populating devcoredump fields on unenabled devices" [v2,07/12] Bluetooth: btqca: Simplify qca_send_reset() by using __hci_reset_sync()

1: T1 Title exceeds max length (82>80): "[v2,07/12] Bluetooth: btqca: Simplify qca_send_reset() by using __hci_reset_sync()" [v2,08/12] Bluetooth: btusb: Simplify btusb_shutdown_qca() by using __hci_reset_sync()

1: T1 Title exceeds max length (86>80): "[v2,08/12] Bluetooth: btusb: Simplify btusb_shutdown_qca() by using __hci_reset_sync()" [v2,10/12] Bluetooth: hci_event: Log error for HCI reset status error in hci_cc_reset()

1: T1 Title exceeds max length (87>80): "[v2,10/12] Bluetooth: hci_event: Log error for HCI reset status error in hci_cc_reset()"
##############################
Test: CheckKernelLLVM - SKIP
Desc: Build kernel with LLVM + context analysis
Output:
Clang not found
##############################
Test: TestRunner_l2cap-tester - FAIL
Desc: Run l2cap-tester with test-runner
Output:
Total: 96, Passed: 95 (99.0%), Failed: 1, Not Run: 0

Failed Test Cases
L2CAP BR/EDR Server - Set PHY 3M Failed 0.268 seconds
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner Output:
Total: 494, Passed: 488 (98.8%), Failed: 2, Not Run: 4

Failed Test Cases

Read Exp Feature - Success                           Failed       0.236 seconds
LL Privacy - Add Device 3 (AL is full)               Failed       0.456 seconds

##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner Output:
Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0

Failed Test Cases

Mesh - Send cancel - 1                               Timed out    2.604 seconds
Mesh - Send cancel - 2                               Timed out    1.984 seconds

https://github.com/bluez/bluetooth-next/pull/354

---
Regards,
Linux Bluetooth

author
#3 lore raw

PATCH v2 2/12 Bluetooth: btusb: Fix BD_ADDR byte order in btusb_set_bdaddr_wcn6855()

In reply to Zijun Hu

btusb_set_bdaddr_wcn6855() sends the address without swapping byte order for VSC 0xFC14, but the command expects the address in reversed byte order compared to other HCI commands like HCI_Create_Connection, resulting in a wrong BD_ADDR being set.

btmon log on WCN6855 shows VSC 0xFC14 is sent with swapped bytes 11 22 33 44 55 66, and Read BD ADDR returns the expected address 11:22:33:44:55:66:

< HCI Command: Vendor (0x3f|0x0014) plen 6 #3 [hci0]

          11 22 33 44 55 66
Quoted 1 line

HCI Event: Command Complete (0x0e) plen 4 #4 [hci0]

        Vendor (0x3f|0x0014) ncmd 1
          Status: Success (0x00)

< HCI Command: Read BD ADDR (0x04|0x0009) plen 0 #11 [hci0]

Quoted 1 line

HCI Event: Command Complete (0x0e) plen 10 #12 [hci0]

        Read BD ADDR (0x04|0x0009) ncmd 1
          Status: Success (0x00)
          Address: 11:22:33:44:55:66 (OUI 11-22-33)

Fix by swapping the input address before issuing the command.

Fixes b40f58b97386 ("Bluetooth: btusb: Add Qualcomm Bluetooth SoC WCN6855 support")
---
 drivers/bluetooth/btusb.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/bluetooth/btusb.c +5 -4
index 7f14ce96319b..17573749adda 100644
@@ -3072,14 +3072,15 @@ static int btusb_set_bdaddr_ath3012(struct hci_dev *hdev,
 static int btusb_set_bdaddr_wcn6855(struct hci_dev *hdev,
 				const bdaddr_t *bdaddr)
 {
+	bdaddr_t bdaddr_swapped;
 	struct sk_buff *skb;
-	u8 buf[6];
 	long ret;
 
-	memcpy(buf, bdaddr, sizeof(bdaddr_t));
+	baswap(&bdaddr_swapped, bdaddr);
 
-	skb = __hci_cmd_sync_ev(hdev, 0xfc14, sizeof(buf), buf,
-				HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT);
+	skb = __hci_cmd_sync_ev(hdev, 0xfc14, sizeof(bdaddr_swapped),
+				&bdaddr_swapped, HCI_EV_CMD_COMPLETE,
+				HCI_INIT_TIMEOUT);
 	if (IS_ERR(skb)) {
 		ret = PTR_ERR(skb);
 		bt_dev_err(hdev, "Change address command failed (%ld)", ret);
Signature · 1 line
2.34.1
author
#4 lore raw

PATCH v2 3/12 Bluetooth: btusb: Record matched usb_device_id into btusb_data

In reply to Zijun Hu

Add @match_id to btusb_data to record the matched usb_device_id which will be used later.

---
 drivers/bluetooth/btusb.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/bluetooth/btusb.c +2 -0
index 17573749adda..31cbe075edc9 100644
@@ -1012,6 +1012,7 @@ struct btusb_data {
 	bool usb_alt6_packet_flow;
 	int isoc_altsetting;
 	int suspend_count;
+	const struct usb_device_id *match_id;
 
 	int (*recv_event)(struct hci_dev *hdev, struct sk_buff *skb);
 	int (*recv_acl)(struct hci_dev *hdev, struct sk_buff *skb);
@@ -4120,6 +4121,7 @@ static int btusb_probe(struct usb_interface *intf,
 	if (!data)
 		return -ENOMEM;
 
+	data->match_id = id;
 	err = usb_find_common_endpoints(intf->cur_altsetting, &data->bulk_rx_ep,
 					&data->bulk_tx_ep, &data->intr_ep, NULL);
 	if (err)
Signature · 1 line
2.34.1
author
#5 lore raw

PATCH v2 4/12 Bluetooth: btusb: QCA: Fix populating devcoredump fields on unenabled devices

In reply to Zijun Hu

Devcoredump is not enabled for ATH3012 or QCA_ROME, but they unconditionally populate devcoredump fields in btusb_setup_qca().

Fix by populating devcoredump fields only when BTUSB_QCA_WCN6855 is set, which marks the first generation of QCA BT SoCs for which devcoredump is enabled.

Fixes 20981ce2d5a5 ("Bluetooth: btusb: Add WCN6855 devcoredump support")
---
 drivers/bluetooth/btusb.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/bluetooth/btusb.c +4 -2
index 31cbe075edc9..0bc7d7b61b25 100644
@@ -3709,8 +3709,10 @@ static int btusb_setup_qca(struct hci_dev *hdev)
 	if (err < 0)
 		return err;
 
-	btdata->qca_dump.fw_version = le32_to_cpu(ver.patch_version);
-	btdata->qca_dump.controller_id = le32_to_cpu(ver.rom_version);
+	if (btdata->match_id->driver_info & BTUSB_QCA_WCN6855) {
+		btdata->qca_dump.fw_version = le32_to_cpu(ver.patch_version);
+		btdata->qca_dump.controller_id = le32_to_cpu(ver.rom_version);
+	}
 
 	if (!(status & QCA_SYSCFG_UPDATED)) {
 		err = btusb_setup_qca_load_nvm(hdev, &ver, info);
Signature · 1 line
2.34.1
author
#6 lore raw

PATCH v2 5/12 Bluetooth: btusb: QCA: move qca_dump out of struct btusb_data

In reply to Zijun Hu

'struct btusb_data' ideally should not include vendor specific fields, but it currently includes the QCA devcoredump member 'struct qca_dump_info qca_dump'.

Fix by moving it into hci_dev private area accessed by hci_get_priv().

---
 drivers/bluetooth/btusb.c | 56 ++++++++++++++++++++++++++++-------------------
 1 file changed, 34 insertions(+), 22 deletions(-)
drivers/bluetooth/btusb.c +34 -22
index 0bc7d7b61b25..a5ff4af90675 100644
@@ -939,6 +939,10 @@ struct qca_dump_info {
 	u16 ram_dump_seqno;
 };
 
+struct btqca_data {
+	struct qca_dump_info qca_dump;
+};
+
 #define BTUSB_MAX_ISOC_FRAMES	10
 
 #define BTUSB_INTR_RUNNING	0
@@ -1025,8 +1029,6 @@ struct btusb_data {
 	int (*disconnect)(struct hci_dev *hdev);
 
 	int oob_wake_irq;   /* irq for out-of-band wake-on-bt */
-
-	struct qca_dump_info qca_dump;
 };
 
 static void btusb_reset(struct hci_dev *hdev)
@@ -3117,14 +3119,15 @@ struct qca_dump_hdr {
 static void btusb_dump_hdr_qca(struct hci_dev *hdev, struct sk_buff *skb)
 {
 	char buf[128];
-	struct btusb_data *btdata = hci_get_drvdata(hdev);
+	struct btqca_data *btqca_data = hci_get_priv(hdev);
+	struct qca_dump_info *qca_dump_ptr = &btqca_data->qca_dump;
 
 	snprintf(buf, sizeof(buf), "Controller Name: 0x%x\n",
-			btdata->qca_dump.controller_id);
+			qca_dump_ptr->controller_id);
 	skb_put_data(skb, buf, strlen(buf));
 
 	snprintf(buf, sizeof(buf), "Firmware Version: 0x%x\n",
-			btdata->qca_dump.fw_version);
+			qca_dump_ptr->fw_version);
 	skb_put_data(skb, buf, strlen(buf));
 
 	snprintf(buf, sizeof(buf), "Driver: %s\nVendor: qca\n",
@@ -3132,7 +3135,7 @@ static void btusb_dump_hdr_qca(struct hci_dev *hdev, struct sk_buff *skb)
 	skb_put_data(skb, buf, strlen(buf));
 
 	snprintf(buf, sizeof(buf), "VID: 0x%x\nPID:0x%x\n",
-			btdata->qca_dump.id_vendor, btdata->qca_dump.id_product);
+			qca_dump_ptr->id_vendor, qca_dump_ptr->id_product);
 	skb_put_data(skb, buf, strlen(buf));
 
 	snprintf(buf, sizeof(buf), "Lmp Subversion: 0x%x\n",
@@ -3161,6 +3164,8 @@ static int handle_dump_pkt_qca(struct hci_dev *hdev, struct sk_buff *skb)
 
 	struct qca_dump_hdr *dump_hdr;
 	struct btusb_data *btdata = hci_get_drvdata(hdev);
+	struct btqca_data *btqca_data = hci_get_priv(hdev);
+	struct qca_dump_info *qca_dump_ptr = &btqca_data->qca_dump;
 	struct usb_device *udev = btdata->udev;
 
 	pkt_type = hci_skb_pkt_type(skb);
@@ -3188,8 +3193,8 @@ static int handle_dump_pkt_qca(struct hci_dev *hdev, struct sk_buff *skb)
 			goto out;
 		}
 
-		btdata->qca_dump.ram_dump_size = dump_size;
-		btdata->qca_dump.ram_dump_seqno = 0;
+		qca_dump_ptr->ram_dump_size = dump_size;
+		qca_dump_ptr->ram_dump_seqno = 0;
 
 		skb_pull(skb, offsetof(struct qca_dump_hdr, data0));
 
@@ -3201,29 +3206,29 @@ static int handle_dump_pkt_qca(struct hci_dev *hdev, struct sk_buff *skb)
 		skb_pull(skb, offsetof(struct qca_dump_hdr, data));
 	}
 
-	if (!btdata->qca_dump.ram_dump_size) {
+	if (!qca_dump_ptr->ram_dump_size) {
 		ret = -EINVAL;
 		bt_dev_err(hdev, "memdump is not active");
 		goto out;
 	}
 
-	if ((seqno > btdata->qca_dump.ram_dump_seqno + 1) && (seqno != QCA_LAST_SEQUENCE_NUM)) {
-		dump_size = QCA_MEMDUMP_PKT_SIZE * (seqno - btdata->qca_dump.ram_dump_seqno - 1);
+	if ((seqno > qca_dump_ptr->ram_dump_seqno + 1) && seqno != QCA_LAST_SEQUENCE_NUM) {
+		dump_size = QCA_MEMDUMP_PKT_SIZE * (seqno - qca_dump_ptr->ram_dump_seqno - 1);
 		hci_devcd_append_pattern(hdev, 0x0, dump_size);
 		bt_dev_err(hdev,
 			   "expected memdump seqno(%u) is not received(%u)\n",
-			   btdata->qca_dump.ram_dump_seqno, seqno);
-		btdata->qca_dump.ram_dump_seqno = seqno;
+			   qca_dump_ptr->ram_dump_seqno, seqno);
+		qca_dump_ptr->ram_dump_seqno = seqno;
 		kfree_skb(skb);
 		return ret;
 	}
 
 	hci_devcd_append(hdev, skb);
-	btdata->qca_dump.ram_dump_seqno++;
+	qca_dump_ptr->ram_dump_seqno++;
 	if (seqno == QCA_LAST_SEQUENCE_NUM) {
 		bt_dev_info(hdev,
 				"memdump done: pkts(%u), total(%u)\n",
-				btdata->qca_dump.ram_dump_seqno, btdata->qca_dump.ram_dump_size);
+				qca_dump_ptr->ram_dump_seqno, qca_dump_ptr->ram_dump_size);
 
 		hci_devcd_complete(hdev);
 		goto out;
@@ -3231,10 +3236,10 @@ static int handle_dump_pkt_qca(struct hci_dev *hdev, struct sk_buff *skb)
 	return ret;
 
 out:
-	if (btdata->qca_dump.ram_dump_size)
+	if (qca_dump_ptr->ram_dump_size)
 		usb_enable_autosuspend(udev);
-	btdata->qca_dump.ram_dump_size = 0;
-	btdata->qca_dump.ram_dump_seqno = 0;
+	qca_dump_ptr->ram_dump_size = 0;
+	qca_dump_ptr->ram_dump_seqno = 0;
 	clear_bit(BTUSB_HW_SSR_ACTIVE, &btdata->flags);
 
 	if (ret < 0)
@@ -3710,8 +3715,10 @@ static int btusb_setup_qca(struct hci_dev *hdev)
 		return err;
 
 	if (btdata->match_id->driver_info & BTUSB_QCA_WCN6855) {
-		btdata->qca_dump.fw_version = le32_to_cpu(ver.patch_version);
-		btdata->qca_dump.controller_id = le32_to_cpu(ver.rom_version);
+		struct btqca_data *btqca_data = hci_get_priv(hdev);
+
+		btqca_data->qca_dump.fw_version = le32_to_cpu(ver.patch_version);
+		btqca_data->qca_dump.controller_id = le32_to_cpu(ver.rom_version);
 	}
 
 	if (!(status & QCA_SYSCFG_UPDATED)) {
@@ -4177,6 +4184,9 @@ static int btusb_probe(struct usb_interface *intf,
 	} else if (id->driver_info & BTUSB_MEDIATEK) {
 		/* Allocate extra space for Mediatek device */
 		priv_size += sizeof(struct btmtk_data);
+	} else if (id->driver_info & BTUSB_QCA_WCN6855) {
+		/* Allocate extra space for QCA WCN6855 device */
+		priv_size += sizeof(struct btqca_data);
 	}
 
 	data->recv_acl = hci_recv_frame;
@@ -4319,8 +4329,10 @@ static int btusb_probe(struct usb_interface *intf,
 	}
 
 	if (id->driver_info & BTUSB_QCA_WCN6855) {
-		data->qca_dump.id_vendor = id->idVendor;
-		data->qca_dump.id_product = id->idProduct;
+		struct btqca_data *btqca_data = hci_get_priv(hdev);
+
+		btqca_data->qca_dump.id_vendor = id->idVendor;
+		btqca_data->qca_dump.id_product = id->idProduct;
 		data->recv_event = btusb_recv_evt_qca;
 		data->recv_acl = btusb_recv_acl_qca;
 		hci_devcd_register(hdev, btusb_coredump_qca, btusb_dump_hdr_qca, NULL);
Signature · 1 line
2.34.1
author
#7 lore raw

PATCH v2 6/12 Bluetooth: hci_sync: Introduce __hci_reset_sync() for device drivers

In reply to Zijun Hu

Several vendor drivers have a requirement to send a synchronous raw HCI reset with HCI_INIT_TIMEOUT.

Add a dedicated __hci_reset_sync() for them to use.

---
 include/net/bluetooth/hci_sync.h | 1 +
 net/bluetooth/hci_sync.c         | 8 ++++++++
 2 files changed, 9 insertions(+)
include/net/bluetooth/hci_sync.h +1 -0
index 73e494b2591d..7005fc9f257a 100644
@@ -59,6 +59,7 @@ int __hci_cmd_sync_status(struct hci_dev *hdev, u16 opcode, u32 plen,
 int __hci_cmd_sync_status_sk(struct hci_dev *hdev, u16 opcode, u32 plen,
 			     const void *param, u8 event, u32 timeout,
 			     struct sock *sk);
+int __hci_reset_sync(struct hci_dev *hdev);
 int hci_cmd_sync_status(struct hci_dev *hdev, u16 opcode, u32 plen,
 			const void *param, u32 timeout);
 
net/bluetooth/hci_sync.c +8 -0
index 3be8c3581c6c..ca1ee6c89739 100644
@@ -3684,6 +3684,14 @@ int hci_reset_sync(struct hci_dev *hdev)
 	return 0;
 }
 
+/* Send a raw HCI reset for use by vendor drivers */
+int __hci_reset_sync(struct hci_dev *hdev)
+{
+	return __hci_cmd_sync_status(hdev, HCI_OP_RESET, 0, NULL,
+				     HCI_INIT_TIMEOUT);
+}
+EXPORT_SYMBOL(__hci_reset_sync);
+
 static int hci_init0_sync(struct hci_dev *hdev)
 {
 	int err;
Signature · 1 line
2.34.1
author
#8 lore raw

PATCH v2 7/12 Bluetooth: btqca: Simplify qca_send_reset() by using __hci_reset_sync()

In reply to Zijun Hu

qca_send_reset() is functionally equivalent to the newly added __hci_reset_sync().

Drop qca_send_reset() and call __hci_reset_sync() directly.

---
 drivers/bluetooth/btqca.c | 22 ++--------------------
 1 file changed, 2 insertions(+), 20 deletions(-)
drivers/bluetooth/btqca.c +2 -20
index 27f03690af54..a940fa48179b 100644
@@ -190,25 +190,6 @@ static int qca_send_patch_config_cmd(struct hci_dev *hdev)
 	return err;
 }
 
-static int qca_send_reset(struct hci_dev *hdev)
-{
-	struct sk_buff *skb;
-	int err;
-
-	bt_dev_dbg(hdev, "QCA HCI_RESET");
-
-	skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
-	if (IS_ERR(skb)) {
-		err = PTR_ERR(skb);
-		bt_dev_err(hdev, "QCA Reset failed (%d)", err);
-		return err;
-	}
-
-	kfree_skb(skb);
-
-	return 0;
-}
-
 static int qca_read_fw_board_id(struct hci_dev *hdev, u16 *bid)
 {
 	u8 cmd;
@@ -990,11 +971,12 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
 	}
 
 	/* Perform HCI reset */
-	err = qca_send_reset(hdev);
+	err = __hci_reset_sync(hdev);
 	if (err < 0) {
 		bt_dev_err(hdev, "QCA Failed to run HCI_RESET (%d)", err);
 		return err;
 	}
+	bt_dev_dbg(hdev, "QCA HCI_RESET succeed");
 
 	switch (soc_type) {
 	case QCA_WCN3991:
Signature · 1 line
2.34.1
author
#9 lore raw

PATCH v2 8/12 Bluetooth: btusb: Simplify btusb_shutdown_qca() by using __hci_reset_sync()

In reply to Zijun Hu

btusb_shutdown_qca() open-codes a synchronous raw HCI reset that is functionally equivalent to the newly added __hci_reset_sync().

Replace it with __hci_reset_sync() and return its result directly.

---
 drivers/bluetooth/btusb.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/bluetooth/btusb.c +4 -7
index a5ff4af90675..25bbee8f5d93 100644
@@ -3900,16 +3900,13 @@ static bool btusb_wakeup(struct hci_dev *hdev)
 
 static int btusb_shutdown_qca(struct hci_dev *hdev)
 {
-	struct sk_buff *skb;
+	int err;
 
-	skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
-	if (IS_ERR(skb)) {
+	err = __hci_reset_sync(hdev);
+	if (err)
 		bt_dev_err(hdev, "HCI reset during shutdown failed");
-		return PTR_ERR(skb);
-	}
-	kfree_skb(skb);
 
-	return 0;
+	return err;
 }
 
 static ssize_t force_poll_sync_read(struct file *file, char __user *user_buf,
Signature · 1 line
2.34.1
author
#10 lore raw

PATCH v2 9/12 Bluetooth: hci_sync: Simplify hci_reset_sync()

In reply to Zijun Hu

Return the reset command status directly instead of storing it in a local variable and using an if/return pattern.

---
 net/bluetooth/hci_sync.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
net/bluetooth/hci_sync.c +2 -8
index ca1ee6c89739..97caac7a1963 100644
@@ -3672,16 +3672,10 @@ static const struct hci_init_stage hci_init0[] = {
 
 int hci_reset_sync(struct hci_dev *hdev)
 {
-	int err;
-
 	set_bit(HCI_RESET, &hdev->flags);
 
-	err = __hci_cmd_sync_status(hdev, HCI_OP_RESET, 0, NULL,
-				    HCI_CMD_TIMEOUT);
-	if (err)
-		return err;
-
-	return 0;
+	return __hci_cmd_sync_status(hdev, HCI_OP_RESET, 0, NULL,
+				     HCI_CMD_TIMEOUT);
 }
 
 /* Send a raw HCI reset for use by vendor drivers */
Signature · 1 line
2.34.1
author
#11 lore raw

PATCH v2 10/12 Bluetooth: hci_event: Log error for HCI reset status error in hci_cc_reset()

In reply to Zijun Hu

HCI_Reset is a critical command, but hci_cc_reset() uses bt_dev_dbg() to log it, so a non-zero error status response may not be noticed.

Fix by using bt_dev_err() when a status error occurs.

---
 net/bluetooth/hci_event.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/bluetooth/hci_event.c +4 -1
index b6d963ce26d0..a90d2c6a6e59 100644
@@ -269,7 +269,10 @@ static u8 hci_cc_reset(struct hci_dev *hdev, void *data, struct sk_buff *skb)
 {
 	struct hci_ev_status *rp = data;
 
-	bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
+	if (rp->status)
+		bt_dev_err(hdev, "HCI reset failed (status 0x%2.2x)", rp->status);
+	else
+		bt_dev_dbg(hdev, "HCI reset succeeded");
 
 	clear_bit(HCI_RESET, &hdev->flags);
 
Signature · 1 line
2.34.1
maintainer Reviewed-by on v2 10/12
#12 lore raw

Re: [PATCH v2 10/12] Bluetooth: hci_event: Log error for HCI reset status error in hci_cc_reset()

Quoted 28 lines · Zijun Hu

HCI_Reset is a critical command, but hci_cc_reset() uses bt_dev_dbg() to log it, so a non-zero error status response may not be noticed.

Fix by using bt_dev_err() when a status error occurs.

---
 net/bluetooth/hci_event.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/bluetooth/hci_event.c +4 -2
index b6d963ce26d0..a90d2c6a6e59 100644
@@ -269,7 +269,10 @@ static u8 hci_cc_reset(struct hci_dev *hdev, void *data, struct sk_buff *skb)
 {
 	struct hci_ev_status *rp = data;
 
-	bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
+	if (rp->status)
+		bt_dev_err(hdev, "HCI reset failed (status 0x%2.2x)", rp->status);
+	else
+		bt_dev_dbg(hdev, "HCI reset succeeded");
 
 	clear_bit(HCI_RESET, &hdev->flags);
 
 
--
Quoted 3 lines

2.34.1

author
#13 lore raw

PATCH v2 11/12 Bluetooth: btusb: Reduce a redundant assignment in btusb_probe()

In reply to Zijun Hu

Initialize @priv_size at declaration rather than separately:
- Simpler: one statement completes both declaration and assignment.
- More flexible: the variable is immediately usable from that point, so any new priv_size += can be freely inserted without caring about where the separate priv_size = 0 sits.

---
 drivers/bluetooth/btusb.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/bluetooth/btusb.c +1 -3
index 25bbee8f5d93..d2e15a91584f 100644
@@ -4090,7 +4090,7 @@ static int btusb_probe(struct usb_interface *intf,
 	struct btusb_data *data;
 	struct hci_dev *hdev;
 	unsigned ifnum_base;
-	int err, priv_size;
+	int err, priv_size = 0;
 
 	BT_DBG("intf %p id %p", intf, id);
 
@@ -4161,8 +4161,6 @@ static int btusb_probe(struct usb_interface *intf,
 	init_usb_anchor(&data->ctrl_anchor);
 	spin_lock_init(&data->rxlock);
 
-	priv_size = 0;
-
 	data->recv_event = hci_recv_frame;
 	data->recv_bulk = btusb_recv_bulk;
 
Signature · 1 line
2.34.1
author
#14 lore raw

PATCH v2 12/12 Bluetooth: btusb: Use & instead of == to test bitflag BTUSB_IGNORE

In reply to Zijun Hu

The driver_info field is a bitmask, so use & instead of == to test the BTUSB_IGNORE bitflag against it, which is consistent with how the other flags are tested.

---
 drivers/bluetooth/btusb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/bluetooth/btusb.c +1 -1
index d2e15a91584f..21e125db1b1f 100644
@@ -4109,7 +4109,7 @@ static int btusb_probe(struct usb_interface *intf,
 			id = match;
 	}
 
-	if (id->driver_info == BTUSB_IGNORE)
+	if (id->driver_info & BTUSB_IGNORE)
 		return -ENODEV;
 
 	if (id->driver_info & BTUSB_ATH3012) {
Signature · 1 line
2.34.1
#15 lore raw
In reply to Zijun Hu
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 Thu, 25 Jun 2026 22:19:45 -0700 you wrote:

This series cleans up btusb in preparation for adding a new chip, QCC2072, and fixes several pre-existing bugs found along the way.

Bug fixes:
- qca_set_bdaddr() waited for HCI_EV_VENDOR, but the controller replies with a Command Complete event.
- btusb_set_bdaddr_wcn6855() sent the BD_ADDR without byte-swapping it.
- btusb QCA populated devcoredump fields on devices where devcoredump is not enabled.
- BTUSB_IGNORE is a bitmask and must be tested with '&', not '=='.

Quoted 1 line

[...]

Here is the summary with links:
- [v2,01/12] Bluetooth: btqca: Fix qca_set_bdaddr() waiting for wrong HCI event

    https://git.kernel.org/bluetooth/bluetooth-next/c/1718f3a121dd
  - [v2,02/12] Bluetooth: btusb: Fix BD_ADDR byte order in btusb_set_bdaddr_wcn6855()
    https://git.kernel.org/bluetooth/bluetooth-next/c/cb9fed45d399
  - [v2,03/12] Bluetooth: btusb: Record matched usb_device_id into btusb_data
    https://git.kernel.org/bluetooth/bluetooth-next/c/97138867591e
  - [v2,04/12] Bluetooth: btusb: QCA: Fix populating devcoredump fields on unenabled devices
    https://git.kernel.org/bluetooth/bluetooth-next/c/0a7575521e2e
  - [v2,05/12] Bluetooth: btusb: QCA: move qca_dump out of struct btusb_data
    https://git.kernel.org/bluetooth/bluetooth-next/c/bafbbfe43876
  - [v2,06/12] Bluetooth: hci_sync: Introduce __hci_reset_sync() for device drivers
    https://git.kernel.org/bluetooth/bluetooth-next/c/dc4d5e617358
  - [v2,07/12] Bluetooth: btqca: Simplify qca_send_reset() by using __hci_reset_sync()
    https://git.kernel.org/bluetooth/bluetooth-next/c/6ccd5c9a56dd
  - [v2,08/12] Bluetooth: btusb: Simplify btusb_shutdown_qca() by using __hci_reset_sync()
    https://git.kernel.org/bluetooth/bluetooth-next/c/738df2031c56
  - [v2,09/12] Bluetooth: hci_sync: Simplify hci_reset_sync()
    https://git.kernel.org/bluetooth/bluetooth-next/c/a16a8312f80f
  - [v2,10/12] Bluetooth: hci_event: Log error for HCI reset status error in hci_cc_reset()
    (no matching commit)
  - [v2,11/12] Bluetooth: btusb: Reduce a redundant assignment in btusb_probe()
    https://git.kernel.org/bluetooth/bluetooth-next/c/37ecdbcfd7cb
  - [v2,12/12] Bluetooth: btusb: Use & instead of == to test bitflag BTUSB_IGNORE
    https://git.kernel.org/bluetooth/bluetooth-next/c/5d490bc8bda1

You are awesome, thank you!

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