Skip to content

Commit 2c507e5

Browse files
committed
Bluetooth: Controller: Fix HCI command buffer allocation failure
Fix HCI command buffer allocation failure, that can cause loss of Host Number of Completed Packets command. Fail by rejecting the HCI Host Buffer Size command if the required number of HCI command buffers are not allocated in the Controller implementation. When Controller to Host data flow control is supported in the Controller only build, ensure that BT_BUF_CMD_TX_COUNT is greater than or equal to (BT_BUF_RX_COUNT + Ncmd), where Ncmd is supported maximum Num_HCI_Command_Packets in the Controller implementation. Relates to commit 8161430 ("Bluetooth: Add workaround for no command buffer available")'. Relates to commit 297f4f4 ("Bluetooth: Split HCI command & event buffers to two pools"). Signed-off-by: Vinayak Kariappa Chettimada <[email protected]> (cherry picked from commit d382fca) Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent 2a5a711 commit 2c507e5

File tree

30 files changed

+280
-98
lines changed

30 files changed

+280
-98
lines changed

include/zephyr/bluetooth/buf.h

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ struct bt_buf_data {
100100
* available for the HCI driver to allocate from.
101101
*
102102
* TODO: When CONFIG_BT_BUF_ACL_RX_COUNT is removed,
103-
* remove the MAX and only keep (CONFIG_BT_MAX_CONN + 1)
103+
* remove the MAX and only keep the 1.
104104
*/
105-
#define BT_BUF_ACL_RX_COUNT \
106-
(MAX(CONFIG_BT_BUF_ACL_RX_COUNT, (CONFIG_BT_MAX_CONN + 1)) + \
107-
CONFIG_BT_BUF_ACL_RX_COUNT_EXTRA)
105+
#define BT_BUF_ACL_RX_COUNT_EXTRA CONFIG_BT_BUF_ACL_RX_COUNT_EXTRA
106+
#define BT_BUF_ACL_RX_COUNT (MAX(CONFIG_BT_BUF_ACL_RX_COUNT, 1) + BT_BUF_ACL_RX_COUNT_EXTRA)
108107
#else
109-
#define BT_BUF_ACL_RX_COUNT 0
108+
#define BT_BUF_ACL_RX_COUNT_EXTRA 0
109+
#define BT_BUF_ACL_RX_COUNT 0
110110
#endif /* CONFIG_BT_CONN && CONFIG_BT_HCI_HOST */
111111

112112
#if defined(CONFIG_BT_BUF_ACL_RX_COUNT) && CONFIG_BT_BUF_ACL_RX_COUNT > 0
@@ -120,10 +120,15 @@ BUILD_ASSERT(BT_BUF_ACL_RX_COUNT <= BT_BUF_ACL_RX_COUNT_MAX,
120120
#define BT_BUF_RX_SIZE (MAX(MAX(BT_BUF_ACL_RX_SIZE, BT_BUF_EVT_RX_SIZE), \
121121
BT_BUF_ISO_RX_SIZE))
122122

123-
/** Buffer count needed for HCI ACL, HCI ISO or Event RX buffers */
124-
#define BT_BUF_RX_COUNT (MAX(MAX(CONFIG_BT_BUF_EVT_RX_COUNT, \
125-
BT_BUF_ACL_RX_COUNT), \
126-
BT_BUF_ISO_RX_COUNT))
123+
/* Controller can generate up to CONFIG_BT_BUF_ACL_TX_COUNT number of unique HCI Number of Completed
124+
* Packets events.
125+
*/
126+
BUILD_ASSERT(CONFIG_BT_BUF_EVT_RX_COUNT > CONFIG_BT_BUF_ACL_TX_COUNT,
127+
"Increase Event RX buffer count to be greater than ACL TX buffer count");
128+
129+
/** Buffer count needed for HCI ACL or HCI ISO plus Event RX buffers */
130+
#define BT_BUF_RX_COUNT (CONFIG_BT_BUF_EVT_RX_COUNT + \
131+
MAX(BT_BUF_ACL_RX_COUNT, BT_BUF_ISO_RX_COUNT))
127132

128133
/** Data size needed for HCI Command buffers. */
129134
#define BT_BUF_CMD_TX_SIZE BT_BUF_CMD_SIZE(CONFIG_BT_BUF_CMD_TX_SIZE)

samples/bluetooth/hci_ipc/nrf5340_cpunet_bis-bt_ll_sw_split.conf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ CONFIG_BT_HCI_RAW=y
1313
CONFIG_BT_HCI_RAW_RESERVE=1
1414
CONFIG_BT_MAX_CONN=2
1515

16-
# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
17-
# Host number of completed commands does not follow normal flow control.
18-
CONFIG_BT_BUF_CMD_TX_COUNT=10
19-
2016
CONFIG_BT_BUF_EVT_RX_COUNT=16
21-
2217
CONFIG_BT_BUF_EVT_RX_SIZE=255
2318
CONFIG_BT_BUF_ACL_RX_SIZE=255
2419
CONFIG_BT_BUF_ACL_TX_SIZE=251

samples/bluetooth/hci_ipc/nrf5340_cpunet_bt_mesh-bt_ll_sw_split.conf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ CONFIG_BT_HCI_RAW=y
1111
CONFIG_BT_HCI_RAW_RESERVE=1
1212
CONFIG_BT_MAX_CONN=16
1313

14-
15-
# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
16-
# Host number of completed commands does not follow normal flow control.
17-
CONFIG_BT_BUF_CMD_TX_COUNT=10
18-
1914
# Controller
2015
CONFIG_BT_LL_SW_SPLIT=y
2116

samples/bluetooth/hci_ipc/nrf5340_cpunet_cis-bt_ll_sw_split.conf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ CONFIG_BT_HCI_RAW=y
1313
CONFIG_BT_HCI_RAW_RESERVE=1
1414
CONFIG_BT_MAX_CONN=2
1515

16-
# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
17-
# Host number of completed commands does not follow normal flow control.
18-
CONFIG_BT_BUF_CMD_TX_COUNT=10
19-
2016
CONFIG_BT_BUF_EVT_RX_COUNT=16
21-
2217
CONFIG_BT_BUF_EVT_RX_SIZE=255
2318
CONFIG_BT_BUF_ACL_RX_SIZE=255
2419
CONFIG_BT_BUF_ACL_TX_SIZE=251

samples/bluetooth/hci_ipc/nrf5340_cpunet_df-bt_ll_sw_split.conf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ CONFIG_BT_HCI_RAW=y
1313
CONFIG_BT_HCI_RAW_RESERVE=1
1414
CONFIG_BT_MAX_CONN=2
1515

16-
# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
17-
# Host number of completed commands does not follow normal flow control.
18-
CONFIG_BT_BUF_CMD_TX_COUNT=10
19-
2016
CONFIG_BT_BUF_EVT_RX_COUNT=16
21-
2217
CONFIG_BT_BUF_EVT_RX_SIZE=255
2318
CONFIG_BT_BUF_ACL_RX_SIZE=255
2419
CONFIG_BT_BUF_ACL_TX_SIZE=251

samples/bluetooth/hci_ipc/nrf5340_cpunet_iso-bt_ll_sw_split.conf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ CONFIG_BT_HCI_RAW=y
1313
CONFIG_BT_HCI_RAW_RESERVE=1
1414
CONFIG_BT_MAX_CONN=2
1515

16-
# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
17-
# Host number of completed commands does not follow normal flow control.
18-
CONFIG_BT_BUF_CMD_TX_COUNT=10
19-
2016
CONFIG_BT_BUF_EVT_RX_COUNT=16
21-
2217
CONFIG_BT_BUF_EVT_RX_SIZE=255
2318
CONFIG_BT_BUF_ACL_RX_SIZE=255
2419
CONFIG_BT_BUF_ACL_TX_SIZE=251

samples/bluetooth/hci_ipc/nrf5340_cpunet_iso_central-bt_ll_sw_split.conf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ CONFIG_BT=y
1212
CONFIG_BT_HCI_RAW=y
1313
CONFIG_BT_HCI_RAW_RESERVE=1
1414

15-
# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
16-
# Host number of completed commands does not follow normal flow control.
17-
CONFIG_BT_BUF_CMD_TX_COUNT=10
18-
1915
CONFIG_BT_BUF_EVT_RX_SIZE=255
2016
CONFIG_BT_BUF_ACL_RX_SIZE=255
2117
CONFIG_BT_BUF_ACL_TX_SIZE=251

samples/bluetooth/hci_ipc/nrf5340_cpunet_iso_peripheral-bt_ll_sw_split.conf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ CONFIG_BT=y
1212
CONFIG_BT_HCI_RAW=y
1313
CONFIG_BT_HCI_RAW_RESERVE=1
1414

15-
# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
16-
# Host number of completed commands does not follow normal flow control.
17-
CONFIG_BT_BUF_CMD_TX_COUNT=10
18-
1915
CONFIG_BT_BUF_EVT_RX_SIZE=255
2016
CONFIG_BT_BUF_ACL_RX_SIZE=255
2117
CONFIG_BT_BUF_ACL_TX_SIZE=251

samples/bluetooth/hci_ipc/prj.conf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ CONFIG_BT_HCI_RAW=y
1111
CONFIG_BT_HCI_RAW_RESERVE=1
1212
CONFIG_BT_MAX_CONN=16
1313

14-
15-
# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
16-
# Host number of completed commands does not follow normal flow control.
17-
CONFIG_BT_BUF_CMD_TX_COUNT=10
18-
1914
# Enable and adjust the below value as necessary
2015
# CONFIG_BT_BUF_EVT_RX_COUNT=16
2116
# CONFIG_BT_BUF_EVT_RX_SIZE=255

samples/bluetooth/hci_uart/prj.conf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,3 @@ CONFIG_BT_TINYCRYPT_ECC=n
1717
CONFIG_BT_CTLR_DTM_HCI=y
1818

1919
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512
20-
21-
# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
22-
# Host number of completed commands does not follow normal flow control.
23-
CONFIG_BT_BUF_CMD_TX_COUNT=10

0 commit comments

Comments
 (0)