Skip to contentSkip to conversation

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

PATCH Superseded Zijun Hu 5 participants 33 messages Jun 22 – Jun 25

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Zijun Hu

author
#0 lore raw

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

This series originated as a cleanup of btusb in preparation for adding support for a new chip, QCC2072: specifically, moving struct btusb_data and the BTUSB_* macros into a new btusb.h header so that the forthcoming QCC2072 driver can share them without duplicating definitions.

While doing that cleanup, several pre-existing bugs were found and fixed.

Preparatory cleanups:
- Initialize priv_size to 0 at declaration in btusb_probe() to remove a redundant assignment a few lines below.
- Move struct btusb_data and the BTUSB_* macros into a new btusb.h header so that btqca.c (and future drivers) can access them without duplicating definitions.
- Record the matched usb_device_id pointer in struct btusb_data so that downstream code (e.g. qca_setup) can inspect driver_info without needing to re-scan the id table.
- Move qca_dump out of struct btusb_data into a dedicated struct btqca_data stored in hci priv, decoupling the QCA coredump state from the generic btusb driver data.
- Simplify the hci_reset_sync() return path (trivial two-liner to one).
- Add __hci_reset_sync() as an exported helper for vendor drivers; it sends HCI_OP_RESET and returns a proper errno.
- Use __hci_reset_sync() in btusb_shutdown_qca() to remove open-coded __hci_cmd_sync() boilerplate.

Bug fixes found during the cleanup:
- BTUSB_IGNORE is a bitmask flag and must be tested with '&', not '=='. The '==' test would miss any device whose driver_info word carries additional flags alongside BTUSB_IGNORE.
- qca_setup() unconditionally populated devcoredump fw_version and controller_id fields even on ATH3012 and QCA_ROME devices where those fields are meaningless. Guard the assignment behind a WCN6855 check.
- btusb_set_bdaddr_wcn6855() passed the raw bdaddr pointer to the HCI command without byte-swapping it first; use baswap() as other set_bdaddr implementations do.
- hci_reset_sync() returned the raw HCI status byte instead of a negative errno on error. Add the bt_to_errno() conversion.
- qca_send_reset() used __hci_cmd_sync() which only checks transport-level errors and silently ignores a non-zero HCI status in the response. The function is replaced by a call to the new __hci_reset_sync() which does the right conversion.
- qca_set_bdaddr() passed HCI_EV_VENDOR as the expected event type; the correct value is 0 (any), matching how other set_bdaddr callers behave.

---
Zijun Hu (13):
Bluetooth: btusb: Initialize @priv_size at declaration in btusb_probe()
Bluetooth: btusb: Use & instead of == to test bitflag BTUSB_IGNORE
Bluetooth: btusb: Record matched usb_device_id into btusb_data
Bluetooth: btusb: QCA: Do not populate devcoredump fields on ATH3012 or QCA_ROME
Bluetooth: btusb: QCA: move qca_dump out of struct btusb_data
Bluetooth: btusb: Fix BD_ADDR byte order in btusb_set_bdaddr_wcn6855()
Bluetooth: hci_sync: Simplify hci_reset_sync()
Bluetooth: hci_sync: Fix return value of hci_reset_sync()
Bluetooth: hci_sync: Add __hci_reset_sync() for device driver
Bluetooth: btusb: Simplify btusb_shutdown_qca() by using __hci_reset_sync()
Bluetooth: btusb: Move struct btusb_data and macros into btusb.h
Bluetooth: btqca: Fix undetected error HCI status in qca_send_reset()
Bluetooth: btqca: Fix qca_set_bdaddr() using wrong HCI event type

 drivers/bluetooth/btqca.c        |  25 +----
 drivers/bluetooth/btusb.c        | 197 +++++++++------------------------------
 drivers/bluetooth/btusb.h        | 139 +++++++++++++++++++++++++++
 include/net/bluetooth/hci_sync.h |   1 +
 net/bluetooth/hci_sync.c         |  18 +++-
 5 files changed, 205 insertions(+), 175 deletions(-)

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

Best regards,

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

PATCH 1/13 Bluetooth: btusb: Initialize @priv_size at declaration in btusb_probe()

Initialize @priv_size at declaration to reduce a redundant assignment.

---
 drivers/bluetooth/btusb.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/bluetooth/btusb.c +1 -3
index 7f14ce96319b..5209e2418493 100644
@@ -4082,7 +4082,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);
 
@@ -4152,8 +4152,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
#6 lore raw

PATCH 2/13 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 5209e2418493..fa6a223d472d 100644
@@ -4101,7 +4101,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
author
#9 lore raw

PATCH 3/13 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 fa6a223d472d..6a90f012b226 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);
@@ -4119,6 +4120,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
#10 lore raw

PATCH 4/13 Bluetooth: btusb: QCA: Do not populate devcoredump fields on ATH3012 or QCA_ROME

In reply to Zijun Hu

Devcoredump is disabled on ATH3012 or QCA_ROME, but btusb_setup_qca() used by both unconditionally populates those two devcoredump fields.

Fix by populating devcoredump fields only for BTUSB_QCA_WCN6855 devices, which are the only ones that enable devcoredump.

---
 drivers/bluetooth/btusb.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/bluetooth/btusb.c +4 -2
index 6a90f012b226..184a87d1234c 100644
@@ -3708,8 +3708,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
#13 lore raw

PATCH 5/13 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 184a87d1234c..6f965c313dff 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)
@@ -3116,14 +3118,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",
@@ -3131,7 +3134,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",
@@ -3160,6 +3163,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);
@@ -3187,8 +3192,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));
 
@@ -3200,29 +3205,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;
@@ -3230,10 +3235,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)
@@ -3709,8 +3714,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)) {
@@ -4174,6 +4181,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;
@@ -4316,8 +4326,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
#14 lore raw

PATCH 6/13 Bluetooth: btusb: Fix BD_ADDR byte order in btusb_set_bdaddr_wcn6855()

In reply to Zijun Hu

For VSC 0xfc14 to set BD_ADDR, the endianness of the BDA parameter is opposite to other HCI commands like HCI_Create_Connection, but btusb_set_bdaddr_wcn6855() sends the address without swapping byte order, resulting in a wrong BD_ADDR being set.

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 6f965c313dff..e78277e24cd8 100644
@@ -3075,14 +3075,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
#15 lore raw

PATCH 7/13 Bluetooth: hci_sync: Simplify hci_reset_sync()

In reply to Zijun Hu

Return err directly instead of using an if/return pattern.

---
 net/bluetooth/hci_sync.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
net/bluetooth/hci_sync.c +1 -3
index 3be8c3581c6c..fce9f9526cb5 100644
@@ -3678,10 +3678,8 @@ int hci_reset_sync(struct hci_dev *hdev)
 
 	err = __hci_cmd_sync_status(hdev, HCI_OP_RESET, 0, NULL,
 				    HCI_CMD_TIMEOUT);
-	if (err)
-		return err;
 
-	return 0;
+	return err;
 }
 
 static int hci_init0_sync(struct hci_dev *hdev)
Signature · 1 line
2.34.1
author
#17 lore raw

PATCH 8/13 Bluetooth: hci_sync: Fix return value of hci_reset_sync()

In reply to Zijun Hu

hci_reset_sync() may return positive HCI status byte as-is, but callers in the chain hci_reset_sync() -> hci_init0_sync() -> hci_unconf_init_sync() check errors with < 0, so a positive status is silently ignored.

Fix by converting positive HCI status to a negative errno using bt_to_errno().

Fixes d0b137062b2d ("Bluetooth: hci_sync: Rework init stages")
---
 net/bluetooth/hci_sync.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/bluetooth/hci_sync.c +3 -1
index fce9f9526cb5..601d44ef975f 100644
@@ -3678,8 +3678,10 @@ int hci_reset_sync(struct hci_dev *hdev)
 
 	err = __hci_cmd_sync_status(hdev, HCI_OP_RESET, 0, NULL,
 				    HCI_CMD_TIMEOUT);
+	if (err < 0)
+		return err;
 
-	return err;
+	return -bt_to_errno(err);
 }
 
 static int hci_init0_sync(struct hci_dev *hdev)
Signature · 1 line
2.34.1
author
#20 lore raw

PATCH 9/13 Bluetooth: hci_sync: Add __hci_reset_sync() for device driver

In reply to Zijun Hu

Many vendor drivers have requirements to send a raw HCI reset synchronously with HCI_INIT_TIMEOUT.

Add a dedicated API for them to use.

---
 include/net/bluetooth/hci_sync.h |  1 +
 net/bluetooth/hci_sync.c         | 14 ++++++++++++++
 2 files changed, 15 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 +14 -0
index 601d44ef975f..40c9725585cb 100644
@@ -3684,6 +3684,20 @@ int hci_reset_sync(struct hci_dev *hdev)
 	return -bt_to_errno(err);
 }
 
+/* Send a raw HCI reset for use by vendor drivers */
+int __hci_reset_sync(struct hci_dev *hdev)
+{
+	int err;
+
+	err = __hci_cmd_sync_status(hdev, HCI_OP_RESET, 0, NULL,
+				    HCI_INIT_TIMEOUT);
+	if (err < 0)
+		return err;
+
+	return -bt_to_errno(err);
+}
+EXPORT_SYMBOL(__hci_reset_sync);
+
 static int hci_init0_sync(struct hci_dev *hdev)
 {
 	int err;
Signature · 1 line
2.34.1
author
#21 lore raw

PATCH 10/13 Bluetooth: btusb: Simplify btusb_shutdown_qca() by using __hci_reset_sync()

In reply to Zijun Hu

Use the new __hci_reset_sync() API instead of open-coding the HCI reset.

---
 drivers/bluetooth/btusb.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/bluetooth/btusb.c +4 -7
index e78277e24cd8..21e125db1b1f 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
#22 lore raw

PATCH 11/13 Bluetooth: btusb: Move struct btusb_data and macros into btusb.h

In reply to Zijun Hu

btusb.c is growing large as vendor-specific code accumulates. Ideally, btusb.c contains only the default implementation while vendor-specific code lives in separate files for easier maintenance.

The newly added btusb.h also reduces unnecessary data copies in hooks like btusb_mtk_setup().

---
 drivers/bluetooth/btusb.c | 119 +--------------------------------------
 drivers/bluetooth/btusb.h | 139 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 140 insertions(+), 118 deletions(-)
drivers/bluetooth/btusb.c +1 -118
index 21e125db1b1f..0d0bd7b559c6 100644
@@ -23,6 +23,7 @@
 #include <net/bluetooth/hci_core.h>
 #include <net/bluetooth/hci_drv.h>
 
+#include "btusb.h"
 #include "btintel.h"
 #include "btbcm.h"
 #include "btrtl.h"
@@ -38,36 +39,6 @@ static bool reset = true;
 
 static struct usb_driver btusb_driver;
 
-#define BTUSB_IGNORE			BIT(0)
-#define BTUSB_DIGIANSWER		BIT(1)
-#define BTUSB_CSR			BIT(2)
-#define BTUSB_SNIFFER			BIT(3)
-#define BTUSB_BCM92035			BIT(4)
-#define BTUSB_BROKEN_ISOC		BIT(5)
-#define BTUSB_WRONG_SCO_MTU		BIT(6)
-#define BTUSB_ATH3012			BIT(7)
-#define BTUSB_INTEL_COMBINED		BIT(8)
-#define BTUSB_INTEL_BOOT		BIT(9)
-#define BTUSB_BCM_PATCHRAM		BIT(10)
-#define BTUSB_MARVELL			BIT(11)
-#define BTUSB_SWAVE			BIT(12)
-#define BTUSB_AMP			BIT(13)
-#define BTUSB_QCA_ROME			BIT(14)
-#define BTUSB_BCM_APPLE			BIT(15)
-#define BTUSB_REALTEK			BIT(16)
-#define BTUSB_BCM2045			BIT(17)
-#define BTUSB_IFNUM_2			BIT(18)
-#define BTUSB_CW6622			BIT(19)
-#define BTUSB_MEDIATEK			BIT(20)
-#define BTUSB_WIDEBAND_SPEECH		BIT(21)
-#define BTUSB_INVALID_LE_STATES		BIT(22)
-#define BTUSB_QCA_WCN6855		BIT(23)
-#define BTUSB_INTEL_BROKEN_SHUTDOWN_LED	BIT(24)
-#define BTUSB_INTEL_BROKEN_INITIAL_NCMD BIT(25)
-#define BTUSB_INTEL_NO_WBS_SUPPORT	BIT(26)
-#define BTUSB_ACTIONS_SEMI		BIT(27)
-#define BTUSB_BARROT			BIT(28)
-
 static const struct usb_device_id btusb_table[] = {
 	/* Generic Bluetooth USB device */
 	{ USB_DEVICE_INFO(0xe0, 0x01, 0x01) },
@@ -943,94 +914,6 @@ struct btqca_data {
 	struct qca_dump_info qca_dump;
 };
 
-#define BTUSB_MAX_ISOC_FRAMES	10
-
-#define BTUSB_INTR_RUNNING	0
-#define BTUSB_BULK_RUNNING	1
-#define BTUSB_ISOC_RUNNING	2
-#define BTUSB_SUSPENDING	3
-#define BTUSB_DID_ISO_RESUME	4
-#define BTUSB_BOOTLOADER	5
-#define BTUSB_DOWNLOADING	6
-#define BTUSB_FIRMWARE_LOADED	7
-#define BTUSB_FIRMWARE_FAILED	8
-#define BTUSB_BOOTING		9
-#define BTUSB_DIAG_RUNNING	10
-#define BTUSB_OOB_WAKE_ENABLED	11
-#define BTUSB_HW_RESET_ACTIVE	12
-#define BTUSB_TX_WAIT_VND_EVT	13
-#define BTUSB_WAKEUP_AUTOSUSPEND	14
-#define BTUSB_USE_ALT3_FOR_WBS	15
-#define BTUSB_ALT6_CONTINUOUS_TX	16
-#define BTUSB_HW_SSR_ACTIVE	17
-
-struct btusb_data {
-	struct hci_dev       *hdev;
-	struct usb_device    *udev;
-	struct usb_interface *intf;
-	struct usb_interface *isoc;
-	struct usb_interface *diag;
-	unsigned isoc_ifnum;
-
-	unsigned long flags;
-
-	bool poll_sync;
-	int intr_interval;
-	struct work_struct  work;
-	struct work_struct  waker;
-	struct delayed_work rx_work;
-
-	struct sk_buff_head acl_q;
-
-	struct usb_anchor deferred;
-	struct usb_anchor tx_anchor;
-	int tx_in_flight;
-	spinlock_t txlock;
-
-	struct usb_anchor intr_anchor;
-	struct usb_anchor bulk_anchor;
-	struct usb_anchor isoc_anchor;
-	struct usb_anchor diag_anchor;
-	struct usb_anchor ctrl_anchor;
-	spinlock_t rxlock;
-
-	struct sk_buff *evt_skb;
-	struct sk_buff *acl_skb;
-	struct sk_buff *sco_skb;
-
-	struct usb_endpoint_descriptor *intr_ep;
-	struct usb_endpoint_descriptor *bulk_tx_ep;
-	struct usb_endpoint_descriptor *bulk_rx_ep;
-	struct usb_endpoint_descriptor *isoc_tx_ep;
-	struct usb_endpoint_descriptor *isoc_rx_ep;
-	struct usb_endpoint_descriptor *diag_tx_ep;
-	struct usb_endpoint_descriptor *diag_rx_ep;
-
-	struct gpio_desc *reset_gpio;
-
-	__u8 cmdreq_type;
-	__u8 cmdreq;
-
-	unsigned int sco_num;
-	unsigned int air_mode;
-	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);
-	int (*recv_bulk)(struct btusb_data *data, void *buffer, int count);
-
-	int (*setup_on_usb)(struct hci_dev *hdev);
-
-	int (*suspend)(struct hci_dev *hdev);
-	int (*resume)(struct hci_dev *hdev);
-	int (*disconnect)(struct hci_dev *hdev);
-
-	int oob_wake_irq;   /* irq for out-of-band wake-on-bt */
-};
-
 static void btusb_reset(struct hci_dev *hdev)
 {
 	struct btusb_data *data;
drivers/bluetooth/btusb.h new file +139 -0

139 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#25 lore raw

PATCH 12/13 Bluetooth: btqca: Fix undetected error HCI status in qca_send_reset()

In reply to Zijun Hu

qca_send_reset() uses __hci_cmd_sync() which returns an skb but never reads the HCI status byte from skb->data[0], so a non-zero error status returned by the controller is silently ignored.

Fix by replacing qca_send_reset() with __hci_reset_sync() which properly extracts and converts the HCI status byte to a negative errno.

Fixes 83e81961ff7e ("Bluetooth: btqca: Introduce generic QCA ROME support")
---
 drivers/bluetooth/btqca.c | 22 ++--------------------
 1 file changed, 2 insertions(+), 20 deletions(-)
drivers/bluetooth/btqca.c +2 -20
index 04ebe290bc78..875216e15603 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,7 +971,8 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
 	}
 
 	/* Perform HCI reset */
-	err = qca_send_reset(hdev);
+	bt_dev_dbg(hdev, "QCA HCI_RESET");
+	err = __hci_reset_sync(hdev);
 	if (err < 0) {
 		bt_dev_err(hdev, "QCA Failed to run HCI_RESET (%d)", err);
 		return err;
Signature · 1 line
2.34.1
author
#30 lore raw

PATCH 13/13 Bluetooth: btqca: Fix qca_set_bdaddr() using wrong HCI event type

In reply to Zijun Hu

EDL_WRITE_BD_ADDR_OPCODE (0xFC14) returns a command complete event, not a VSE, but qca_set_bdaddr() waits for HCI_EV_VENDOR.

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 875216e15603..f3487de813c2 100644
@@ -1011,8 +1011,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

Re: [PATCH 01/13] Bluetooth: btusb: Initialize @priv_size at declaration in btusb_probe()

In reply to Zijun Hu
Quoted 1 line · Zijun Hu

Initialize @priv_size at declaration to reduce a redundant assignment.

This is obvious from the commit. Please tell us, why?

Quoted 32 lines
---
 drivers/bluetooth/btusb.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/bluetooth/btusb.c +1 -3
index 7f14ce96319b..5209e2418493 100644
@@ -4082,7 +4082,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);
 
@@ -4152,8 +4152,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 · 2 lines
-- 
2.34.1
Signature · 2 lines
With best wishes
Dmitry
Reviewed-by on v1 2/13
#7 lore raw

Re: [PATCH 02/13] Bluetooth: btusb: Use & instead of == to test bitflag BTUSB_IGNORE

In reply to Zijun Hu
Quoted 9 lines · 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(-)
Signature · 2 lines
With best wishes
Dmitry
#11 lore raw

Re: [PATCH 04/13] Bluetooth: btusb: QCA: Do not populate devcoredump fields on ATH3012 or QCA_ROME

In reply to Zijun Hu
Quoted 5 lines · Zijun Hu

Devcoredump is disabled on ATH3012 or QCA_ROME, but btusb_setup_qca() used by both unconditionally populates those two devcoredump fields.

Fix by populating devcoredump fields only for BTUSB_QCA_WCN6855 devices, which are the only ones that enable devcoredump.

Why? Wouldn't it be better to enable devcoredump for all platforms?

Quoted 27 lines
---
 drivers/bluetooth/btusb.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/bluetooth/btusb.c +4 -2
index 6a90f012b226..184a87d1234c 100644
@@ -3708,8 +3708,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 · 2 lines
-- 
2.34.1
Signature · 2 lines
With best wishes
Dmitry
#18 lore raw

Re: [PATCH 08/13] Bluetooth: hci_sync: Fix return value of hci_reset_sync()

In reply to Zijun Hu

Hi Zijun,

Quoted 19 lines · Zijun Hu

hci_reset_sync() may return positive HCI status byte as-is, but callers in the chain hci_reset_sync() -> hci_init0_sync() -> hci_unconf_init_sync() check errors with < 0, so a positive status is silently ignored.

Fix by converting positive HCI status to a negative errno using bt_to_errno().

Fixes d0b137062b2d ("Bluetooth: hci_sync: Rework init stages")
---
 net/bluetooth/hci_sync.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/bluetooth/hci_sync.c +0 -0
index fce9f9526cb5..601d44ef975f 100644

net/bluetooth/hci_sync.c int hci_reset_sync(struct hci_dev *hdev) · line 3685

Quoted 9 lines
net/bluetooth/hci_sync.c +3 -1
@@ -3678,8 +3678,10 @@ int hci_reset_sync(struct hci_dev *hdev)
 
        err = __hci_cmd_sync_status(hdev, HCI_OP_RESET, 0, NULL,
                                    HCI_CMD_TIMEOUT);
+       if (err < 0)
+               return err;
 
-       return err;
+       return -bt_to_errno(err);
 }

There seem to be 2 consecutive changes to hci_reset_sync that conflict with each other, also the expectation should be that positive errors are HCI errors and negative errors are stack generated ones, so the callers should really check err and not err < 0.

Quoted 5 lines
net/bluetooth/hci_sync.c +0 -1
 static int hci_init0_sync(struct hci_dev *hdev)
 
--

2.34.1

Signature · 1 line
Luiz Augusto von Dentz
#5 lore raw
In reply to Zijun Hu

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=1114806

---Test result---

Test Summary:

CheckPatch                    FAIL      14.74 seconds
VerifyFixes                   PASS      0.31 seconds
VerifySignedoff               PASS      0.30 seconds
GitLint                       FAIL      9.09 seconds
SubjectPrefix                 PASS      3.49 seconds
BuildKernel                   PASS      25.01 seconds
CheckAllWarning               PASS      27.84 seconds
CheckSparse                   PASS      29.36 seconds
BuildKernel32                 PASS      24.64 seconds
CheckKernelLLVM               SKIP      0.00 seconds
TestRunnerSetup               PASS      522.56 seconds
TestRunner_l2cap-tester       PASS      57.21 seconds
TestRunner_iso-tester         PASS      77.02 seconds
TestRunner_bnep-tester        PASS      18.82 seconds
TestRunner_mgmt-tester        FAIL      205.87 seconds
TestRunner_rfcomm-tester      PASS      25.34 seconds
TestRunner_sco-tester         PASS      34.70 seconds
TestRunner_ioctl-tester       PASS      25.44 seconds
TestRunner_mesh-tester        FAIL      29.97 seconds
TestRunner_smp-tester         PASS      22.99 seconds
TestRunner_userchan-tester    PASS      20.16 seconds
TestRunner_6lowpan-tester     PASS      22.20 seconds
IncrementalBuild              PASS      74.92 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[11/13] Bluetooth: btusb: Move struct btusb_data and macros into btusb.h
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #322:
new file mode 100644

total: 0 errors, 1 warnings, 276 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/patch/14639541.patch has style problems, please review.

NOTE: Ignored message types: UNKNOWN_COMMIT_ID

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

##############################
Test: GitLint - FAIL
Desc: Run gitlint
Output:
[04/13] Bluetooth: btusb: QCA: Do not populate devcoredump fields on ATH3012 or QCA_ROME

1: T1 Title exceeds max length (88>80): "[04/13] Bluetooth: btusb: QCA: Do not populate devcoredump fields on ATH3012 or QCA_ROME" [10/13] Bluetooth: btusb: Simplify btusb_shutdown_qca() by using __hci_reset_sync()

1: T1 Title exceeds max length (83>80): "[10/13] Bluetooth: btusb: Simplify btusb_shutdown_qca() by using __hci_reset_sync()"
##############################
Test: CheckKernelLLVM - SKIP
Desc: Build kernel with LLVM + context analysis
Output:
Clang not found
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 494, Passed: 489 (99.0%), Failed: 1, Not Run: 4

Failed Test Cases
Read Exp Feature - Success Failed 0.234 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    1.978 seconds
Mesh - Send cancel - 2                               Timed out    1.988 seconds

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

---
Regards,
Linux Bluetooth

maintainer Reviewed-by
#3 lore raw

Re: [PATCH 01/13] Bluetooth: btusb: Initialize @priv_size at declaration in btusb_probe()

In reply to Dmitry Baryshkov
Quoted 5 lines · Dmitry Baryshkov
Quoted 1 line · Zijun Hu

Initialize @priv_size at declaration to reduce a redundant assignment.

This is obvious from the commit. Please tell us, why?

I think this is what "to reduce a redundant assignment" says.

maintainer Reviewed-by on v1 7/13
#16 lore raw

Re: [PATCH 07/13] Bluetooth: hci_sync: Simplify hci_reset_sync()

In reply to Zijun Hu
Quoted 25 lines · Zijun Hu

Return err directly instead of using an if/return pattern.

---
 net/bluetooth/hci_sync.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
net/bluetooth/hci_sync.c +1 -4
index 3be8c3581c6c..fce9f9526cb5 100644
@@ -3678,10 +3678,8 @@ int hci_reset_sync(struct hci_dev *hdev)
 
 	err = __hci_cmd_sync_status(hdev, HCI_OP_RESET, 0, NULL,
 				    HCI_CMD_TIMEOUT);
-	if (err)
-		return err;
 
-	return 0;
+	return err;
 }
 
 static int hci_init0_sync(struct hci_dev *hdev)
 
--
Quoted 3 lines

2.34.1

#23 lore raw

Re: [PATCH 11/13] Bluetooth: btusb: Move struct btusb_data and macros into btusb.h

In reply to Zijun Hu
Quoted 9 lines · Zijun Hu

btusb.c is growing large as vendor-specific code accumulates. Ideally, btusb.c contains only the default implementation while vendor-specific code lives in separate files for easier maintenance.

The newly added btusb.h also reduces unnecessary data copies in hooks like btusb_mtk_setup().

---

I would be ok with this if you added a user of this new header in the subsequent patches but I don't see these so I'll hold off my R-b until you can show the need for one.

Bart

#26 lore raw

Re: [PATCH 12/13] Bluetooth: btqca: Fix undetected error HCI status in qca_send_reset()

In reply to Zijun Hu
Quoted 10 lines · Zijun Hu

qca_send_reset() uses __hci_cmd_sync() which returns an skb but never reads the HCI status byte from skb->data[0], so a non-zero error status returned by the controller is silently ignored.

Fix by replacing qca_send_reset() with __hci_reset_sync() which properly extracts and converts the HCI status byte to a negative errno.

Fixes 83e81961ff7e ("Bluetooth: btqca: Introduce generic QCA ROME support")

---

I think the fix should go in the front of the series. Even if it requires the new function.

Bart

maintainer Reviewed-by on v1 13/13
#31 lore raw

Re: [PATCH 13/13] Bluetooth: btqca: Fix qca_set_bdaddr() using wrong HCI event type

In reply to Zijun Hu
Quoted 28 lines · Zijun Hu

EDL_WRITE_BD_ADDR_OPCODE (0xFC14) returns a command complete event, not a VSE, but qca_set_bdaddr() waits for HCI_EV_VENDOR.

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 -3
index 875216e15603..f3487de813c2 100644
@@ -1011,8 +1011,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);
 
--
Quoted 3 lines

2.34.1

Looks good but should go in the front of the series and land upstream earlier.

Bart

author
#4 lore raw

Re: [PATCH 01/13] Bluetooth: btusb: Initialize @priv_size at declaration in btusb_probe()

In reply to Dmitry Baryshkov
Quoted 3 lines · Dmitry Baryshkov
Quoted 1 line · Zijun Hu

Initialize @priv_size at declaration to reduce a redundant assignment.

This is obvious from the commit. Please tell us, why?

It is simpler: one statement completes both declaration and assignment. More flexible: initializing at declaration makes the variable immediately usable from that point, so any new priv_size += can be freely inserted without caring about where the separate priv_size = 0 sits.

Will improve the commit message in v2.

author
#12 lore raw

Re: [PATCH 04/13] Bluetooth: btusb: QCA: Do not populate devcoredump fields on ATH3012 or QCA_ROME

In reply to Dmitry Baryshkov
Quoted 6 lines · Dmitry Baryshkov
Quoted 5 lines

Devcoredump is disabled on ATH3012 or QCA_ROME, but btusb_setup_qca() used by both unconditionally populates those two devcoredump fields.

Fix by populating devcoredump fields only for BTUSB_QCA_WCN6855 devices, which are the only ones that enable devcoredump.

Why? Wouldn't it be better to enable devcoredump for all platforms?

BTUSB_QCA_WCN6855 marks the first generation of QCA BT SoCs for which devcoredump is enabled; all later generations are enabled too. ATH3012 and QCA_ROME are much older chips that predate devcoredump in the Bluetooth core driver — there is no requirement to enable it for them and it is not clear whether they even support it.

Will optimize the commit message in v2.

author
#24 lore raw

Re: [PATCH 11/13] Bluetooth: btusb: Move struct btusb_data and macros into btusb.h

In reply to Bartosz Golaszewski
Quoted 5 lines · Bartosz Golaszewski
Quoted 4 lines · Zijun Hu

btusb.c is growing large as vendor-specific code accumulates. Ideally, btusb.c contains only the default implementation while vendor-specific code lives in separate files for easier maintenance.

Quoted 8 lines
Quoted 5 lines

The newly added btusb.h also reduces unnecessary data copies in hooks like btusb_mtk_setup().

---

I would be ok with this if you added a user of this new header in the subsequent patches but I don't see these so I'll hold off my R-b until you can show the need for one.

Right. Will drop this patch in v2 and bring it back together with its user when necessary.

author
#27 lore raw

Re: [PATCH 12/13] Bluetooth: btqca: Fix undetected error HCI status in qca_send_reset()

In reply to Bartosz Golaszewski
Quoted 5 lines · Bartosz Golaszewski
Quoted 3 lines
Fixes 83e81961ff7e ("Bluetooth: btqca: Introduce generic QCA ROME support")

---

I think the fix should go in the front of the series. Even if it requires the new function.

Agreed on the reordering. However, handling HCI status errors for the reset command needs more discussion before we can finalize the approach, so the fix may be further optimized accordingly.

author
#19 lore raw

Re: [PATCH 08/13] Bluetooth: hci_sync: Fix return value of hci_reset_sync()

In reply to Luiz Augusto von Dentz
Quoted 11 lines · Luiz Augusto von Dentz
Quoted 11 lines
net/bluetooth/hci_sync.c +2 -0
index fce9f9526cb5..601d44ef975f 100644
@@ -3678,8 +3678,10 @@ int hci_reset_sync(struct hci_dev *hdev)
 
        err = __hci_cmd_sync_status(hdev, HCI_OP_RESET, 0, NULL,
                                    HCI_CMD_TIMEOUT);
+       if (err < 0)
+               return err;
 
Quoted 7 lines

net/bluetooth/hci_sync.c int hci_reset_sync(struct hci_dev *hdev) · line 3685

Quoted 3 lines
net/bluetooth/hci_sync.c +1 -1
-       return err;
+       return -bt_to_errno(err);
 }

There seem to be 2 consecutive changes to hci_reset_sync that conflict with each other, also the expectation should be that positive errors are HCI errors and negative errors are stack generated ones, so the callers should really check err and not err < 0.

Hi Luiz,

Checking the full call chains:

- hci_reset_sync() → hci_init0_sync() [if (err)] → hci_unconf_init_sync() [if (err < 0)]
- hci_reset_sync() → hci_init1_sync() [if (err)] → hci_init_sync() [if (err < 0)]

A positive HCI status from hci_reset_sync() propagates through hci_init0_sync()/hci_init1_sync() but is then silently ignored by hci_unconf_init_sync()/hci_init_sync() due to their if (err < 0) checks.

Will not change hci_reset_sync(). Any suggestion on how to fix it?

#28 lore raw

Re: [PATCH 12/13] Bluetooth: btqca: Fix undetected error HCI status in qca_send_reset()

In reply to Zijun Hu

Hi Zijun,

Quoted 45 lines · Zijun Hu

qca_send_reset() uses __hci_cmd_sync() which returns an skb but never reads the HCI status byte from skb->data[0], so a non-zero error status returned by the controller is silently ignored.

Fix by replacing qca_send_reset() with __hci_reset_sync() which properly extracts and converts the HCI status byte to a negative errno.

Fixes 83e81961ff7e ("Bluetooth: btqca: Introduce generic QCA ROME support")
---
 drivers/bluetooth/btqca.c | 22 ++--------------------
 1 file changed, 2 insertions(+), 20 deletions(-)
drivers/bluetooth/btqca.c +0 -19
index 04ebe290bc78..875216e15603 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;

drivers/bluetooth/btqca.c int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate, · line 975

Quoted 6 lines
drivers/bluetooth/btqca.c +2 -1
@@ -990,7 +971,8 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
        }
 
        /* Perform HCI reset */
-       err = qca_send_reset(hdev);
+       bt_dev_dbg(hdev, "QCA HCI_RESET");
+       err = __hci_reset_sync(hdev);

So All the fuss about the reset is just to use it here? Actually the distinction between -err and status is rather important. The first means the command didn't run (timeout, cancel, etc), or it did run but returned a status != 0. If you want to capture both then you must use if (err). And yes there are parts of the code that test for < 0, but that is either a bug or they are intentionally ignoring the reset status as it is probably a non-recoverable error at that point.

Quoted 7 lines
drivers/bluetooth/btqca.c +0 -1
        if (err < 0) {
                bt_dev_err(hdev, "QCA Failed to run HCI_RESET (%d)", err);
                return err;
 
--

2.34.1

Signature · 1 line
Luiz Augusto von Dentz
author
#29 lore raw

Re: [PATCH 12/13] Bluetooth: btqca: Fix undetected error HCI status in qca_send_reset()

Quoted 4 lines · Luiz Augusto von Dentz
Quoted 4 lines
        u8 cmd;
(quoted diff) +0 -0
@@ -990,7 +971,8 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
        }
 
Quoted 11 lines

drivers/bluetooth/btqca.c int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate, · line 975

Quoted 4 lines
drivers/bluetooth/btqca.c +2 -1
        /* Perform HCI reset */
-       err = qca_send_reset(hdev);
+       bt_dev_dbg(hdev, "QCA HCI_RESET");
+       err = __hci_reset_sync(hdev);

So All the fuss about the reset is just to use it here? Actually the distinction between -err and status is rather important. The first means the command didn't run (timeout, cancel, etc), or it did run but returned a status != 0. If you want to capture both then you must use if (err). And yes there are parts of the code that test for < 0, but that is either a bug or they are intentionally ignoring the reset status as it is probably a non-recoverable error at that point.

1. Agree: > 0 for HCI status code (controller-side error), < 0 for command not executed (timeout, cancel, transport failure). __hci_reset_sync() was introduced in this series and will be refactored to follow this convention in v2.
2. Looking at drivers/bluetooth/, 7 out of 12 HCI reset call sites in the init/setup phase silently ignore the controller status — not sure if this is intentional or not.
3. qca_set_bdaddr() and qca_send_reset() will be fixed to return the HCI status code and let the caller decide whether to ignore it.

Will address all of the above in v2.