bluetooth: host: Add a check for num of bt_conn_tx and ACL/ISO bufs

After https://github.com/zephyrproject-rtos/zephyr/pull/72090, each
packet to be sent (wether ACL or ISO data) has a corresponding
`bt_conn_tx` object, regardless of whether a callback is used.

This means that number of packets Host can send to Controller is limited
by the smaller of two values: ACL/ISO packets Controller can receive,
and the number of `bt_conn_tx` objects allocated by Host.

A mismatch between these numbers may lead to inefficient resource usage
on either Host or Controller side. If Host allocates fewer `bt_conn_tx`
objects than the number of buffers available on Controller for a given
data type, some Controller buffers may go unused. Conversely, if Host
allocates more `bt_conn_tx` objects than Controller can consume, the
excess objects remain unused.

This commit adds a check and issues a warning if the number of
`bt_conn_tx` objects is not aligned with the number of ACL/ISO buffers
reported by Controller via the LE Read Buffer Size v1 or v2 command.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
This commit is contained in:
Pavel Vasilyev 2025-04-29 12:36:03 +02:00 committed by Henrik Brix Andersen
commit ddeeecd0b4

View file

@ -92,6 +92,26 @@ BUILD_ASSERT(IS_ENABLED(CONFIG_ZTEST), "Missing DT chosen property for HCI");
#define BT_HCI_QUIRKS 0
#endif
/* These checks are added to warn if the number of ACL or ISO packets in Controller is not equal to
* the number of bt_conn_tx contexts allocated by Host. The inequality of these two values can lead
* to inefficient resources usage either on Host's or Controller's side.
*/
#define CHECK_NUM_OF_ACL_PKTS(_num) \
do { \
if (CONFIG_BT_BUF_ACL_TX_COUNT != (_num)) { \
LOG_WRN("Num of Controller's ACL packets != ACL bt_conn_tx contexts" \
" (%u != %u)", (_num), CONFIG_BT_BUF_ACL_TX_COUNT); \
} \
} while (0)
#define CHECK_NUM_OF_ISO_PKTS(_num) \
do { \
if (CONFIG_BT_ISO_TX_BUF_COUNT != (_num)) { \
LOG_WRN("Num of Controller's ISO packets != ISO bt_conn_tx contexts" \
"(%u != %u)", (_num), CONFIG_BT_ISO_TX_BUF_COUNT); \
} \
} while (0)
void bt_tx_irq_raise(void);
#define HCI_CMD_TIMEOUT K_SECONDS(10)
@ -3145,6 +3165,8 @@ static void le_read_buffer_size_complete(struct net_buf *buf)
LOG_DBG("ACL LE buffers: pkts %u mtu %u", rp->le_max_num, bt_dev.le.acl_mtu);
CHECK_NUM_OF_ACL_PKTS(rp->le_max_num);
k_sem_init(&bt_dev.le.acl_pkts, rp->le_max_num, rp->le_max_num);
#endif /* CONFIG_BT_CONN */
}
@ -3164,6 +3186,8 @@ static void read_buffer_size_v2_complete(struct net_buf *buf)
LOG_DBG("ACL LE buffers: pkts %u mtu %u", rp->acl_max_num, bt_dev.le.acl_mtu);
k_sem_init(&bt_dev.le.acl_pkts, rp->acl_max_num, rp->acl_max_num);
CHECK_NUM_OF_ACL_PKTS(rp->acl_max_num);
}
#endif /* CONFIG_BT_CONN */
@ -3180,6 +3204,8 @@ static void read_buffer_size_v2_complete(struct net_buf *buf)
k_sem_init(&bt_dev.le.iso_pkts, rp->iso_max_num, rp->iso_max_num);
bt_dev.le.iso_limit = rp->iso_max_num;
CHECK_NUM_OF_ISO_PKTS(rp->iso_max_num);
#endif /* CONFIG_BT_ISO */
}