* [PATCH v3] Bluetooth: hci_core: Enable buffer flow control for SCO/eSCO
@ 2025-02-21 20:49 Luiz Augusto von Dentz
2025-02-21 21:37 ` [v3] " bluez.test.bot
2025-02-25 9:02 ` [PATCH v3] " Dan Carpenter
0 siblings, 2 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2025-02-21 20:49 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This enables buffer flow control for SCO/eSCO
(see: Bluetooth Core 6.0 spec: 6.22. Synchronous Flow Control Enable),
recently this has caused the following problem and is actually a nice
addition for the likes of Socket TX complete:
< HCI Command: Read Buffer Size (0x04|0x0005) plen 0
> HCI Event: Command Complete (0x0e) plen 11
Read Buffer Size (0x04|0x0005) ncmd 1
Status: Success (0x00)
ACL MTU: 1021 ACL max packet: 5
SCO MTU: 240 SCO max packet: 8
...
< SCO Data TX: Handle 257 flags 0x00 dlen 120
< SCO Data TX: Handle 257 flags 0x00 dlen 120
< SCO Data TX: Handle 257 flags 0x00 dlen 120
< SCO Data TX: Handle 257 flags 0x00 dlen 120
< SCO Data TX: Handle 257 flags 0x00 dlen 120
< SCO Data TX: Handle 257 flags 0x00 dlen 120
< SCO Data TX: Handle 257 flags 0x00 dlen 120
< SCO Data TX: Handle 257 flags 0x00 dlen 120
< SCO Data TX: Handle 257 flags 0x00 dlen 120
> HCI Event: Hardware Error (0x10) plen 1
Code: 0x0a
Fixes: 7fedd3bb6b77 ("Bluetooth: Prioritize SCO traffic")
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
include/net/bluetooth/hci.h | 6 ++++++
include/net/bluetooth/hci_core.h | 1 +
net/bluetooth/hci_core.c | 28 ++++++++++++++++++++++++++++
net/bluetooth/hci_sync.c | 23 +++++++++++++++++++++++
4 files changed, 58 insertions(+)
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 0d51970d809f..a6a375cf97f9 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -432,6 +432,7 @@ enum {
HCI_WIDEBAND_SPEECH_ENABLED,
HCI_EVENT_FILTER_CONFIGURED,
HCI_PA_SYNC,
+ HCI_SCO_FLOWCTL,
HCI_DUT_MODE,
HCI_VENDOR_DIAG,
@@ -1528,6 +1529,11 @@ struct hci_rp_read_tx_power {
__s8 tx_power;
} __packed;
+#define HCI_OP_WRITE_SYNC_FLOWCTL 0x0c2f
+struct hci_cp_write_sync_flowctl {
+ __u8 enable;
+} __packed;
+
#define HCI_OP_READ_PAGE_SCAN_TYPE 0x0c46
struct hci_rp_read_page_scan_type {
__u8 status;
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 05919848ea95..6247ae1802e5 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -1857,6 +1857,7 @@ void hci_conn_del_sysfs(struct hci_conn *conn);
#define lmp_hold_capable(dev) ((dev)->features[0][0] & LMP_HOLD)
#define lmp_sniff_capable(dev) ((dev)->features[0][0] & LMP_SNIFF)
#define lmp_park_capable(dev) ((dev)->features[0][1] & LMP_PARK)
+#define lmp_sco_capable(dev) ((dev)->features[0][1] & LMP_SCO)
#define lmp_inq_rssi_capable(dev) ((dev)->features[0][3] & LMP_RSSI_INQ)
#define lmp_esco_capable(dev) ((dev)->features[0][3] & LMP_ESCO)
#define lmp_bredr_capable(dev) (!((dev)->features[0][4] & LMP_NO_BREDR))
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index e7ec12437c8b..18da9a466327 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -3564,11 +3564,25 @@ static void hci_sched_sco(struct hci_dev *hdev)
BT_DBG("skb %p len %d", skb, skb->len);
hci_send_frame(hdev, skb);
+ hdev->sco_cnt--;
conn->sent++;
if (conn->sent == ~0)
conn->sent = 0;
}
}
+
+ /* Restore sco_cnt if flow control has not been enabled as
+ * HCI_EV_NUM_COMP_PKTS won't be generated.
+ */
+ if (!hci_dev_test_flag(hdev, HCI_SCO_FLOWCTL)) {
+ hdev->sco_cnt = hdev->sco_pkts;
+
+ /* As flow control is disabled force tx_work to run if there are
+ * still packets left in the queue.
+ */
+ if (!skb_queue_empty(&conn->data_q))
+ queue_work(hdev->workqueue, &hdev->tx_work);
+ }
}
static void hci_sched_esco(struct hci_dev *hdev)
@@ -3588,11 +3602,25 @@ static void hci_sched_esco(struct hci_dev *hdev)
BT_DBG("skb %p len %d", skb, skb->len);
hci_send_frame(hdev, skb);
+ hdev->sco_cnt--;
conn->sent++;
if (conn->sent == ~0)
conn->sent = 0;
}
}
+
+ /* Restore sco_cnt if flow control has not been enabled as
+ * HCI_EV_NUM_COMP_PKTS won't be generated.
+ */
+ if (!hci_dev_test_flag(hdev, HCI_SCO_FLOWCTL)) {
+ hdev->sco_cnt = hdev->sco_pkts;
+
+ /* As flow control is disabled force tx_work to run if there are
+ * still packets left in the queue.
+ */
+ if (!skb_queue_empty(&conn->data_q))
+ queue_work(hdev->workqueue, &hdev->tx_work);
+ }
}
static void hci_sched_acl_pkt(struct hci_dev *hdev)
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index a43749aebf76..727b6e3c1b7f 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -3766,6 +3766,27 @@ static int hci_write_ca_timeout_sync(struct hci_dev *hdev)
sizeof(param), ¶m, HCI_CMD_TIMEOUT);
}
+/* Enable SCO flow control if supported */
+static int hci_write_sync_flowctl_sync(struct hci_dev *hdev)
+{
+ struct hci_cp_write_sync_flowctl cp;
+ int err;
+
+ /* Check if the controller supports SCO and HCI_OP_WRITE_SYNC_FLOWCTL */
+ if (!lmp_sco_capable(hdev) || !(hdev->commands[10] & BIT(4)))
+ return 0;
+
+ memset(&cp, 0, sizeof(cp));
+ cp.enable = 0x01;
+
+ err = __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SYNC_FLOWCTL,
+ sizeof(cp), &cp, HCI_CMD_TIMEOUT);
+ if (!err)
+ hci_dev_set_flag(hdev, HCI_SCO_FLOWCTL);
+
+ return err;
+}
+
/* BR Controller init stage 2 command sequence */
static const struct hci_init_stage br_init2[] = {
/* HCI_OP_READ_BUFFER_SIZE */
@@ -3784,6 +3805,8 @@ static const struct hci_init_stage br_init2[] = {
HCI_INIT(hci_clear_event_filter_sync),
/* HCI_OP_WRITE_CA_TIMEOUT */
HCI_INIT(hci_write_ca_timeout_sync),
+ /* HCI_OP_WRITE_SYNC_FLOWCTL */
+ HCI_INIT(hci_write_sync_flowctl_sync),
{}
};
--
2.48.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: [v3] Bluetooth: hci_core: Enable buffer flow control for SCO/eSCO
2025-02-21 20:49 [PATCH v3] Bluetooth: hci_core: Enable buffer flow control for SCO/eSCO Luiz Augusto von Dentz
@ 2025-02-21 21:37 ` bluez.test.bot
2025-02-25 9:02 ` [PATCH v3] " Dan Carpenter
1 sibling, 0 replies; 3+ messages in thread
From: bluez.test.bot @ 2025-02-21 21:37 UTC (permalink / raw)
To: linux-bluetooth, luiz.dentz
[-- Attachment #1: Type: text/plain, Size: 887 bytes --]
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: include/net/bluetooth/hci.h:432
error: include/net/bluetooth/hci.h: patch does not apply
error: patch failed: include/net/bluetooth/hci_core.h:1857
error: include/net/bluetooth/hci_core.h: patch does not apply
error: patch failed: net/bluetooth/hci_core.c:3564
error: net/bluetooth/hci_core.c: patch does not apply
error: patch failed: net/bluetooth/hci_sync.c:3766
error: net/bluetooth/hci_sync.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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] Bluetooth: hci_core: Enable buffer flow control for SCO/eSCO
2025-02-21 20:49 [PATCH v3] Bluetooth: hci_core: Enable buffer flow control for SCO/eSCO Luiz Augusto von Dentz
2025-02-21 21:37 ` [v3] " bluez.test.bot
@ 2025-02-25 9:02 ` Dan Carpenter
1 sibling, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2025-02-25 9:02 UTC (permalink / raw)
To: oe-kbuild, Luiz Augusto von Dentz; +Cc: lkp, oe-kbuild-all
Hi Luiz,
kernel test robot noticed the following build warnings:
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Luiz-Augusto-von-Dentz/Bluetooth-hci_core-Enable-buffer-flow-control-for-SCO-eSCO/20250222-045019
base: https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
patch link: https://lore.kernel.org/r/20250221204916.2217628-1-luiz.dentz%40gmail.com
patch subject: [PATCH v3] Bluetooth: hci_core: Enable buffer flow control for SCO/eSCO
config: i386-randconfig-141-20250223 (https://download.01.org/0day-ci/archive/20250223/202502231103.loPGnZml-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
| Closes: https://lore.kernel.org/r/202502231103.loPGnZml-lkp@intel.com/
New smatch warnings:
net/bluetooth/hci_core.c:3583 hci_sched_sco() error: uninitialized symbol 'conn'.
net/bluetooth/hci_core.c:3583 hci_sched_sco() error: we previously assumed 'conn' could be null (see line 3562)
net/bluetooth/hci_core.c:3621 hci_sched_esco() error: uninitialized symbol 'conn'.
net/bluetooth/hci_core.c:3621 hci_sched_esco() error: we previously assumed 'conn' could be null (see line 3599)
Old smatch warnings:
net/bluetooth/hci_core.c:2595 hci_register_dev() warn: 'hdev->rfkill' is an error pointer or valid
vim +/conn +3583 net/bluetooth/hci_core.c
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3551 static void hci_sched_sco(struct hci_dev *hdev)
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3552 {
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3553 struct hci_conn *conn;
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3554 struct sk_buff *skb;
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3555 int quote;
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3556
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3557 BT_DBG("%s", hdev->name);
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3558
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3559 if (!hci_conn_num(hdev, SCO_LINK))
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3560 return;
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3561
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 @3562 while (hdev->sco_cnt && (conn = hci_low_sent(hdev, SCO_LINK, "e))) {
Can hdev->sco_cnt be zero at the start? That would make "conn"
uninitialized. This loop can exit with conn set to NULL.
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3563 while (quote-- && (skb = skb_dequeue(&conn->data_q))) {
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3564 BT_DBG("skb %p len %d", skb, skb->len);
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3565 hci_send_frame(hdev, skb);
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3566
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3567 hdev->sco_cnt--;
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3568 conn->sent++;
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3569 if (conn->sent == ~0)
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3570 conn->sent = 0;
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3571 }
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3572 }
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3573
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3574 /* Restore sco_cnt if flow control has not been enabled as
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3575 * HCI_EV_NUM_COMP_PKTS won't be generated.
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3576 */
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3577 if (!hci_dev_test_flag(hdev, HCI_SCO_FLOWCTL)) {
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3578 hdev->sco_cnt = hdev->sco_pkts;
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3579
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3580 /* As flow control is disabled force tx_work to run if there are
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3581 * still packets left in the queue.
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3582 */
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 @3583 if (!skb_queue_empty(&conn->data_q))
^^^^
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3584 queue_work(hdev->workqueue, &hdev->tx_work);
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3585 }
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3586 }
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3587
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3588 static void hci_sched_esco(struct hci_dev *hdev)
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3589 {
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3590 struct hci_conn *conn;
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3591 struct sk_buff *skb;
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3592 int quote;
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3593
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3594 BT_DBG("%s", hdev->name);
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3595
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3596 if (!hci_conn_num(hdev, ESCO_LINK))
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3597 return;
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3598
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 @3599 while (hdev->sco_cnt && (conn = hci_low_sent(hdev, ESCO_LINK,
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3600 "e))) {
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3601 while (quote-- && (skb = skb_dequeue(&conn->data_q))) {
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3602 BT_DBG("skb %p len %d", skb, skb->len);
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3603 hci_send_frame(hdev, skb);
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3604
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3605 hdev->sco_cnt--;
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3606 conn->sent++;
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3607 if (conn->sent == ~0)
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3608 conn->sent = 0;
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3609 }
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3610 }
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3611
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3612 /* Restore sco_cnt if flow control has not been enabled as
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3613 * HCI_EV_NUM_COMP_PKTS won't be generated.
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3614 */
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3615 if (!hci_dev_test_flag(hdev, HCI_SCO_FLOWCTL)) {
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3616 hdev->sco_cnt = hdev->sco_pkts;
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3617
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3618 /* As flow control is disabled force tx_work to run if there are
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3619 * still packets left in the queue.
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3620 */
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 @3621 if (!skb_queue_empty(&conn->data_q))
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3622 queue_work(hdev->workqueue, &hdev->tx_work);
efee7ae7cd85cf7 Luiz Augusto von Dentz 2025-02-21 3623 }
7fedd3bb6b77f9b Abhishek Pandit-Subedi 2020-03-23 3624 }
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-02-25 9:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-21 20:49 [PATCH v3] Bluetooth: hci_core: Enable buffer flow control for SCO/eSCO Luiz Augusto von Dentz
2025-02-21 21:37 ` [v3] " bluez.test.bot
2025-02-25 9:02 ` [PATCH v3] " Dan Carpenter
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.