Bluetooth: ISO: Don't initiate CIS connections if there are no buffers
Subsystems (2)
Luiz Augusto von Dentz
maintainerPATCH v4 1/5 Bluetooth: ISO: Don't initiate CIS connections if there are no buffers
From: Luiz Augusto von Dentz <[email protected]>
If the controller has no buffers left return -ENOBUFF to indicate that iso_cnt might be out of sync.
--- net/bluetooth/iso.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/bluetooth/iso.c +7 -0
@@ -458,6 +458,13 @@ static int iso_connect_cis(struct sock *sk) goto unlock; } +/* Check if there are available buffers for output/TX. */ +if (iso_pi (sk)->qos.ucast.out.sdu && !hci_conn_num (hdev,CIS_LINK ) && + (hdev->iso_pkts && !hdev->iso_cnt)) { + err = -ENOBUFS ; + goto unlock; + } +/* Just bind if DEFER_SETUP has been set */ if (test_bit (BT_SK_DEFER_SETUP , &bt_sk (sk)->flags)) { hcon = hci_bind_cis(hdev, &iso_pi(sk)->dst,
Signature · 1 line
2.50.1
Luiz Augusto von Dentz
maintainerPATCH v4 2/5 Bluetooth: HCI: Fix using LE/ACL buffers for ISO packets
From: Luiz Augusto von Dentz <[email protected]>
ISO packets shall not use LE/ACL buffer pool, that feature seem to be exclusive to LE-ACL only.
--- net/bluetooth/hci_conn.c | 33 ++++++++++++++------------------- net/bluetooth/hci_core.c | 6 ++---- net/bluetooth/hci_event.c | 16 +++------------- 3 files changed, 19 insertions(+), 36 deletions(-)
net/bluetooth/hci_conn.c +14 -19
@@ -926,10 +926,9 @@ static struct hci_conn *__hci_conn_add(struct hci_dev *hdev, int type, bdaddr_tcase CIS_LINK :case BIS_LINK :case PA_LINK : -if (hdev->iso_mtu) -/* Dedicated ISO Buffer exists */ -break ; - fallthrough; +if (!hdev->iso_mtu) +return ERR_PTR (-ECONNREFUSED ); +break ;case LE_LINK :if (hdev->le_mtu && hdev->le_mtu <HCI_MIN_LE_MTU )return ERR_PTR (-ECONNREFUSED );
@@ -1152,28 +1151,24 @@ void hci_conn_del(struct hci_conn *conn)disable_delayed_work_sync (&conn->auto_accept_work);disable_delayed_work_sync (&conn->idle_work); -if (conn->type ==ACL_LINK ) { -/* Unacked frames */ +/* Handle unnacked frames */ +switch (conn->type) { +case ACL_LINK : hdev->acl_cnt += conn->sent; - }else if (conn->type ==LE_LINK ) { +break ; +case LE_LINK :cancel_delayed_work (&conn->le_conn_timeout);if (hdev->le_pkts) hdev->le_cnt += conn->sent;else hdev->acl_cnt += conn->sent; - }else { -/* Unacked ISO frames */ -if (conn->type ==CIS_LINK || - conn->type ==BIS_LINK || - conn->type ==PA_LINK ) { -if (hdev->iso_pkts) - hdev->iso_cnt += conn->sent; -else if (hdev->le_pkts) - hdev->le_cnt += conn->sent; -else - hdev->acl_cnt += conn->sent; - } +break ; +case CIS_LINK : +case BIS_LINK : +case PA_LINK : + hdev->iso_cnt += conn->sent; +break ; }skb_queue_purge (&conn->data_q);
net/bluetooth/hci_core.c +2 -4
@@ -3399,8 +3399,7 @@ static inline void hci_quote_sent(struct hci_conn *conn, int num, int *quote)case CIS_LINK :case BIS_LINK :case PA_LINK : - cnt = hdev->iso_mtu ? hdev->iso_cnt : - hdev->le_mtu ? hdev->le_cnt : hdev->acl_cnt; + cnt = hdev->iso_cnt;break ;default : cnt =0 ;
@@ -3759,8 +3758,7 @@ static void hci_sched_iso(struct hci_dev *hdev, __u8 type)if (!hci_conn_num (hdev, type))return ; - cnt = hdev->iso_pkts ? &hdev->iso_cnt : - hdev->le_pkts ? &hdev->le_cnt : &hdev->acl_cnt; + cnt = &hdev->iso_cnt;while (*cnt && (conn =hci_low_sent (hdev, type, "e))) {while (quote-- && (skb =skb_dequeue (&conn->data_q))) {BT_DBG ("skb %p len %d" , skb, skb->len);
net/bluetooth/hci_event.c +3 -13
@@ -4433,19 +4433,9 @@ static void hci_num_comp_pkts_evt(struct hci_dev *hdev, void *data,case CIS_LINK :case BIS_LINK :case PA_LINK : -if (hdev->iso_pkts) { - hdev->iso_cnt += count; -if (hdev->iso_cnt > hdev->iso_pkts) - hdev->iso_cnt = hdev->iso_pkts; - }else if (hdev->le_pkts) { - hdev->le_cnt += count; -if (hdev->le_cnt > hdev->le_pkts) - hdev->le_cnt = hdev->le_pkts; - }else { - hdev->acl_cnt += count; -if (hdev->acl_cnt > hdev->acl_pkts) - hdev->acl_cnt = hdev->acl_pkts; - } + hdev->iso_cnt += count; +if (hdev->iso_cnt > hdev->iso_pkts) + hdev->iso_cnt = hdev->iso_pkts;break ;default :
Signature · 1 line
2.50.1
Luiz Augusto von Dentz
maintainerPATCH v4 3/5 Bluetooth: hci_conn: Make unacked packet handling more robust
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This attempts to make unacked packet handling more robust by detecting if there are no connections left then restore all buffers of the respective pool.
--- net/bluetooth/hci_conn.c | 41 ++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-)
net/bluetooth/hci_conn.c +33 -8
@@ -149,8 +149,6 @@ static void hci_conn_cleanup(struct hci_conn *conn)hci_chan_list_flush (conn); -hci_conn_hash_del (hdev, conn); -if (HCI_CONN_HANDLE_UNSET (conn->handle))ida_free (&hdev->unset_handle_ida, conn->handle);
@@ -1151,22 +1149,49 @@ void hci_conn_del(struct hci_conn *conn)disable_delayed_work_sync (&conn->auto_accept_work);disable_delayed_work_sync (&conn->idle_work); -/* Handle unnacked frames */ +/* Remove the connection from the list so unacked logic can detect when +* a certain pool is not being utilized. +*/ +hci_conn_hash_del (hdev, conn); + +/* Handle unacked frames: +* +* - In case there are no connection restore all buffers to the pool +* - Otherwise restore just the buffers considered in transit for the +* hci_conn +*/ switch (conn->type) {case ACL_LINK : - hdev->acl_cnt += conn->sent; +if (!hci_conn_num (hdev,ACL_LINK )) + hdev->acl_cnt = hdev->acl_pkts; +else + hdev->acl_cnt += conn->sent;break ;case LE_LINK :cancel_delayed_work (&conn->le_conn_timeout); -if (hdev->le_pkts) - hdev->le_cnt += conn->sent; -else - hdev->acl_cnt += conn->sent; +if (hdev->le_pkts) { +if (!hci_conn_num (hdev,LE_LINK )) + hdev->le_cnt = hdev->le_pkts; +else + hdev->le_cnt += conn->sent; + }else { +if (!hci_conn_num (hdev,LE_LINK ) && + !hci_conn_num (hdev,ACL_LINK )) + hdev->acl_cnt = hdev->acl_pkts; +else + hdev->acl_cnt += conn->sent; + }break ;case CIS_LINK :case BIS_LINK :case PA_LINK : +if (!hci_conn_num (hdev,CIS_LINK ) && + !hci_conn_num (hdev,BIS_LINK ) && + !hci_conn_num (hdev,PA_LINK )) + hdev->iso_cnt = hdev->iso_pkts; +else + hdev->iso_cnt += conn->sent; hdev->iso_cnt += conn->sent;break ; }
Signature · 1 line
2.50.1
Luiz Augusto von Dentz
maintainerPATCH v4 4/5 Bluetooth: ISO: Use sk_sndtimeo as conn_timeout
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This aligns the usage of socket sk_sndtimeo as conn_timeout when initiating a connection and then use it when scheduling the resulting HCI command, similar to what has been done in bf98feea5b65 ("Bluetooth: hci_conn: Always use sk_timeo as conn_timeout").
--- include/net/bluetooth/hci_core.h | 10 ++++++---- net/bluetooth/hci_conn.c | 20 ++++++++++++-------- net/bluetooth/iso.c | 16 ++++++++++------ 3 files changed, 28 insertions(+), 18 deletions(-)
include/net/bluetooth/hci_core.h +6 -4
@@ -1546,16 +1546,18 @@ struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst, __u16 setting, struct bt_codec *codec, u16 timeout);struct hci_conn *hci_bind_cis (struct hci_dev *hdev,bdaddr_t *dst, -__u8 dst_type,struct bt_iso_qos *qos); +__u8 dst_type,struct bt_iso_qos *qos, +u16 timeout);struct hci_conn *hci_bind_bis (struct hci_dev *hdev,bdaddr_t *dst,__u8 sid,struct bt_iso_qos *qos, -__u8 base_len,__u8 *base); +__u8 base_len,__u8 *base,u16 timeout);struct hci_conn *hci_connect_cis (struct hci_dev *hdev,bdaddr_t *dst, -__u8 dst_type,struct bt_iso_qos *qos); +__u8 dst_type,struct bt_iso_qos *qos, +u16 timeout);struct hci_conn *hci_connect_bis (struct hci_dev *hdev,bdaddr_t *dst,__u8 dst_type,__u8 sid,struct bt_iso_qos *qos, -__u8 data_len,__u8 *data); +__u8 data_len,__u8 *data,u16 timeout);struct hci_conn *hci_pa_create_sync (struct hci_dev *hdev,bdaddr_t *dst,__u8 dst_type,__u8 sid,struct bt_iso_qos *qos); int hci_conn_big_create_sync(struct hci_dev *hdev, struct hci_conn *hcon,
net/bluetooth/hci_conn.c +12 -8
@@ -1536,7 +1536,7 @@ static int qos_set_bis(struct hci_dev *hdev, struct bt_iso_qos *qos)/* This function requires the caller holds hdev->lock */ static struct hci_conn *hci_add_bis (struct hci_dev *hdev,bdaddr_t *dst,__u8 sid,struct bt_iso_qos *qos, -__u8 base_len,__u8 *base) +__u8 base_len,__u8 *base,u16 timeout) {struct hci_conn *conn;int err;
@@ -1578,6 +1578,7 @@ static struct hci_conn *hci_add_bis(struct hci_dev *hdev, bdaddr_t *dst, conn->state =BT_CONNECT ; conn->sid = sid; + conn->conn_timeout = timeout;hci_conn_hold (conn);return conn;
@@ -1918,7 +1919,8 @@ static bool hci_le_set_cig_params(struct hci_conn *conn, struct bt_iso_qos *qos) }struct hci_conn *hci_bind_cis (struct hci_dev *hdev,bdaddr_t *dst, -__u8 dst_type,struct bt_iso_qos *qos) +__u8 dst_type,struct bt_iso_qos *qos, +u16 timeout) {struct hci_conn *cis;
@@ -1933,6 +1935,7 @@ struct hci_conn *hci_bind_cis(struct hci_dev *hdev, bdaddr_t *dst, cis->dst_type = dst_type; cis->iso_qos.ucast.cig =BT_ISO_QOS_CIG_UNSET ; cis->iso_qos.ucast.cis =BT_ISO_QOS_CIS_UNSET ; + cis->conn_timeout = timeout; }if (cis->state ==BT_CONNECTED )
@@ -2172,7 +2175,7 @@ static void create_big_complete(struct hci_dev *hdev, void *data, int err)struct hci_conn *hci_bind_bis (struct hci_dev *hdev,bdaddr_t *dst,__u8 sid,struct bt_iso_qos *qos, -__u8 base_len,__u8 *base) +__u8 base_len,__u8 *base,u16 timeout) {struct hci_conn *conn;struct hci_conn *parent;
@@ -2193,7 +2196,7 @@ struct hci_conn *hci_bind_bis(struct hci_dev *hdev, bdaddr_t *dst, __u8 sid, base, base_len);/* We need hci_conn object using the BDADDR_ANY as dst */ - conn =hci_add_bis (hdev, dst, sid, qos, base_len, eir); + conn =hci_add_bis (hdev, dst, sid, qos, base_len, eir, timeout);if (IS_ERR (conn))return conn;
@@ -2246,13 +2249,13 @@ static void bis_mark_per_adv(struct hci_conn *conn, void *data)struct hci_conn *hci_connect_bis (struct hci_dev *hdev,bdaddr_t *dst,__u8 dst_type,__u8 sid,struct bt_iso_qos *qos, -__u8 base_len,__u8 *base) +__u8 base_len,__u8 *base,u16 timeout) {struct hci_conn *conn;int err;struct iso_list_data data; - conn =hci_bind_bis (hdev, dst, sid, qos, base_len, base); + conn =hci_bind_bis (hdev, dst, sid, qos, base_len, base, timeout);if (IS_ERR (conn))return conn;
@@ -2295,7 +2298,8 @@ struct hci_conn *hci_connect_bis(struct hci_dev *hdev, bdaddr_t *dst, }struct hci_conn *hci_connect_cis (struct hci_dev *hdev,bdaddr_t *dst, -__u8 dst_type,struct bt_iso_qos *qos) +__u8 dst_type,struct bt_iso_qos *qos, +u16 timeout) {struct hci_conn *le;struct hci_conn *cis;
@@ -2319,7 +2323,7 @@ struct hci_conn *hci_connect_cis(struct hci_dev *hdev, bdaddr_t *dst,hci_iso_qos_setup (hdev, le, &qos->ucast.in, le->le_rx_phy ? le->le_rx_phy : hdev->le_rx_def_phys); - cis =hci_bind_cis (hdev, dst, dst_type, qos); + cis =hci_bind_cis (hdev, dst, dst_type, qos, timeout);if (IS_ERR (cis)) {hci_conn_drop (le);return cis;
net/bluetooth/iso.c +10 -6
@@ -91,8 +91,8 @@ static struct sock *iso_get_sock(bdaddr_t *src, bdaddr_t *dst, iso_sock_match_t match, void *data);/* ---- ISO timers ---- */ -#define ISO_CONN_TIMEOUT (HZ * 40) -#define ISO_DISCONN_TIMEOUT (HZ * 2) +#define ISO_CONN_TIMEOUT secs_to_jiffies(20) +#define ISO_DISCONN_TIMEOUT secs_to_jiffies(2)static void iso_conn_free (struct kref *ref) {
@@ -367,7 +367,8 @@ static int iso_connect_bis(struct sock *sk)if (test_bit (BT_SK_DEFER_SETUP , &bt_sk (sk)->flags)) { hcon =hci_bind_bis (hdev, &iso_pi (sk)->dst,iso_pi (sk)->bc_sid, &iso_pi (sk)->qos,iso_pi (sk)->base_len, -iso_pi (sk)->base); +iso_pi (sk)->base, +READ_ONCE (sk->sk_sndtimeo));if (IS_ERR (hcon)) { err =PTR_ERR (hcon); goto unlock;
@@ -376,7 +377,8 @@ static int iso_connect_bis(struct sock *sk) hcon =hci_connect_bis (hdev, &iso_pi (sk)->dst,le_addr_type (iso_pi (sk)->dst_type),iso_pi (sk)->bc_sid, &iso_pi (sk)->qos, -iso_pi (sk)->base_len,iso_pi (sk)->base); +iso_pi (sk)->base_len,iso_pi (sk)->base, +READ_ONCE (sk->sk_sndtimeo));if (IS_ERR (hcon)) { err =PTR_ERR (hcon); goto unlock;
@@ -469,7 +471,8 @@ static int iso_connect_cis(struct sock *sk)if (test_bit (BT_SK_DEFER_SETUP , &bt_sk (sk)->flags)) { hcon =hci_bind_cis (hdev, &iso_pi (sk)->dst,le_addr_type (iso_pi (sk)->dst_type), - &iso_pi (sk)->qos); + &iso_pi (sk)->qos, +READ_ONCE (sk->sk_sndtimeo));if (IS_ERR (hcon)) { err =PTR_ERR (hcon); goto unlock;
@@ -477,7 +480,8 @@ static int iso_connect_cis(struct sock *sk) }else { hcon =hci_connect_cis (hdev, &iso_pi (sk)->dst,le_addr_type (iso_pi (sk)->dst_type), - &iso_pi (sk)->qos); + &iso_pi (sk)->qos, +READ_ONCE (sk->sk_sndtimeo));if (IS_ERR (hcon)) { err =PTR_ERR (hcon); goto unlock;
Signature · 1 line
2.50.1
Luiz Augusto von Dentz
maintainerPATCH v4 5/5 Bluetooth: hci_core: Detect if an ISO link has stalled
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This attempts to detect if an ISO link has been waiting for an ISO buffer for longer than the maximum allowed transport latency then proceed to use hci_link_tx_to which prints an error and disconnects.
--- include/net/bluetooth/hci.h | 1 + include/net/bluetooth/hci_core.h | 1 + net/bluetooth/hci_core.c | 34 ++++++++++++++++++++++++-------- 3 files changed, 28 insertions(+), 8 deletions(-)
include/net/bluetooth/hci.h +1 -0
@@ -488,6 +488,7 @@ enum {#define HCI_AUTO_OFF_TIMEOUT msecs_to_jiffies(2000)/* 2 seconds */ #define HCI_ACL_CONN_TIMEOUT msecs_to_jiffies(20000)/* 20 seconds */ #define HCI_LE_CONN_TIMEOUT msecs_to_jiffies(20000)/* 20 seconds */ +#define HCI_ISO_TX_TIMEOUT usecs_to_jiffies(0x7fffff)/* 8388607 usecs */ /* HCI data types */ #define HCI_COMMAND_PKT 0x01
include/net/bluetooth/hci_core.h +1 -0
@@ -485,6 +485,7 @@ struct hci_dev {unsigned long acl_last_tx;unsigned long le_last_tx; +unsigned long iso_last_tx;__u8 le_tx_def_phys;__u8 le_rx_def_phys;
net/bluetooth/hci_core.c +26 -8
@@ -3585,24 +3585,37 @@ static void hci_prio_recalculate(struct hci_dev *hdev, __u8 type)static void __check_timeout (struct hci_dev *hdev,unsigned int cnt,u8 type) { -unsigned long last_tx; +unsigned long timeout;if (hci_dev_test_flag (hdev,HCI_UNCONFIGURED ))return ;switch (type) { +case ACL_LINK : +/* tx timeout must be longer than maximum link supervision +* timeout (40.9 seconds) +*/ + timeout = hdev->acl_last_tx +HCI_ACL_TX_TIMEOUT ; +break ;case LE_LINK : - last_tx = hdev->le_last_tx; +/* tx timeout must be longer than maximum link supervision +* timeout (40.9 seconds) +*/ + timeout = hdev->le_last_tx +HCI_ACL_TX_TIMEOUT ; +break ; +case CIS_LINK : +case BIS_LINK : +case PA_LINK : +/* tx timeout must be longer than the maximum transport latency +* (8.388607 seconds) +*/ + timeout = hdev->iso_last_tx +HCI_ISO_TX_TIMEOUT ;break ;default : - last_tx = hdev->acl_last_tx; -break ; +return ; } -/* tx timeout must be longer than maximum link supervision timeout -* (40.9 seconds) -*/ -if (!cnt &&time_after (jiffies, last_tx +HCI_ACL_TX_TIMEOUT )) +if (!cnt &&time_after (jiffies, timeout))hci_link_tx_to (hdev, type); }
@@ -3759,10 +3772,15 @@ static void hci_sched_iso(struct hci_dev *hdev, __u8 type)return ; cnt = &hdev->iso_cnt; + +__check_timeout (hdev, *cnt, type); +while (*cnt && (conn =hci_low_sent (hdev, type, "e))) {while (quote-- && (skb =skb_dequeue (&conn->data_q))) {BT_DBG ("skb %p len %d" , skb, skb->len); +hci_send_conn_frame (hdev, conn, skb); + hdev->iso_last_tx = jiffies; conn->sent++;if (conn->sent == ~0 )
Signature · 1 line
2.50.1
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 8 lines · On Thu, 14 Aug 2025 11:42:04 -0400 you wrote:
From: Luiz Augusto von Dentz <[email protected]>
If the controller has no buffers left return
-ENOBUFFto indicate thatiso_cntmight be out of sync.Signed-off-by Luiz Augusto von Dentz <[email protected]>[...]
Here is the summary with links:
- [v4,1/5] Bluetooth: ISO: Don't initiate CIS connections if there are no buffers (no matching commit)
- [v4,2/5] Bluetooth: HCI: Fix using LE/ACL buffers for ISO packets
https://git.kernel.org/bluetooth/bluetooth-next/c/bd32dcfede57
- [v4,3/5] Bluetooth: hci_conn: Make unacked packet handling more robust (no matching commit)
- [v4,4/5] Bluetooth: ISO: Use sk_sndtimeo as conn_timeout
https://git.kernel.org/bluetooth/bluetooth-next/c/2ecd48de96ba
- [v4,5/5] Bluetooth: hci_core: Detect if an ISO link has stalled
https://git.kernel.org/bluetooth/bluetooth-next/c/64a73bcf8b27
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html