Skip to content

Commit d382fca

Browse files
cvinayakfabiobaltieri
authored andcommitted
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 <vich@nordicsemi.no>
1 parent cc1b534 commit d382fca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+336
-135
lines changed

include/zephyr/bluetooth/buf.h

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ struct bt_buf_data {
9797
* available for the HCI driver to allocate from.
9898
*
9999
* TODO: When CONFIG_BT_BUF_ACL_RX_COUNT is removed,
100-
* remove the MAX and only keep (CONFIG_BT_MAX_CONN + 1)
100+
* remove the MAX and only keep the 1.
101101
*/
102-
#define BT_BUF_ACL_RX_COUNT \
103-
(MAX(CONFIG_BT_BUF_ACL_RX_COUNT, (CONFIG_BT_MAX_CONN + 1)) + \
104-
CONFIG_BT_BUF_ACL_RX_COUNT_EXTRA)
102+
#define BT_BUF_ACL_RX_COUNT_EXTRA CONFIG_BT_BUF_ACL_RX_COUNT_EXTRA
103+
#define BT_BUF_ACL_RX_COUNT (MAX(CONFIG_BT_BUF_ACL_RX_COUNT, 1) + BT_BUF_ACL_RX_COUNT_EXTRA)
105104
#else
106-
#define BT_BUF_ACL_RX_COUNT 0
105+
#define BT_BUF_ACL_RX_COUNT_EXTRA 0
106+
#define BT_BUF_ACL_RX_COUNT 0
107107
#endif /* CONFIG_BT_CONN && CONFIG_BT_HCI_HOST */
108108

109109
#if defined(CONFIG_BT_BUF_ACL_RX_COUNT) && CONFIG_BT_BUF_ACL_RX_COUNT > 0
@@ -117,10 +117,15 @@ BUILD_ASSERT(BT_BUF_ACL_RX_COUNT <= BT_BUF_ACL_RX_COUNT_MAX,
117117
#define BT_BUF_RX_SIZE (MAX(MAX(BT_BUF_ACL_RX_SIZE, BT_BUF_EVT_RX_SIZE), \
118118
BT_BUF_ISO_RX_SIZE))
119119

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

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

samples/bluetooth/central_hr/prj_minimal.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ CONFIG_BT_CTLR_PHY_2M=n
9494
# Reduce Bluetooth buffers
9595
CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT=1
9696
CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=45
97-
CONFIG_BT_BUF_EVT_RX_COUNT=2
97+
CONFIG_BT_BUF_EVT_RX_COUNT=4
9898

9999
CONFIG_BT_L2CAP_TX_BUF_COUNT=2
100100
CONFIG_BT_CTLR_RX_BUFFERS=1

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
@@ -10,12 +10,7 @@ CONFIG_HEAP_MEM_POOL_SIZE=4096
1010
CONFIG_BT=y
1111
CONFIG_BT_HCI_RAW=y
1212

13-
# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
14-
# Host number of completed commands does not follow normal flow control.
15-
CONFIG_BT_BUF_CMD_TX_COUNT=10
16-
1713
CONFIG_BT_BUF_EVT_RX_COUNT=16
18-
1914
CONFIG_BT_BUF_EVT_RX_SIZE=255
2015
CONFIG_BT_BUF_ACL_RX_SIZE=255
2116
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
@@ -10,11 +10,6 @@ CONFIG_BT=y
1010
CONFIG_BT_HCI_RAW=y
1111
CONFIG_BT_MAX_CONN=16
1212

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

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
@@ -10,12 +10,7 @@ CONFIG_HEAP_MEM_POOL_SIZE=4096
1010
CONFIG_BT=y
1111
CONFIG_BT_HCI_RAW=y
1212

13-
# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
14-
# Host number of completed commands does not follow normal flow control.
15-
CONFIG_BT_BUF_CMD_TX_COUNT=10
16-
1713
CONFIG_BT_BUF_EVT_RX_COUNT=16
18-
1914
CONFIG_BT_BUF_EVT_RX_SIZE=255
2015
CONFIG_BT_BUF_ACL_RX_SIZE=255
2116
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
@@ -10,12 +10,7 @@ CONFIG_HEAP_MEM_POOL_SIZE=4096
1010
CONFIG_BT=y
1111
CONFIG_BT_HCI_RAW=y
1212

13-
# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
14-
# Host number of completed commands does not follow normal flow control.
15-
CONFIG_BT_BUF_CMD_TX_COUNT=10
16-
1713
CONFIG_BT_BUF_EVT_RX_COUNT=16
18-
1914
CONFIG_BT_BUF_EVT_RX_SIZE=255
2015
CONFIG_BT_BUF_ACL_RX_SIZE=255
2116
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
@@ -14,12 +14,7 @@ CONFIG_LTO=y
1414
CONFIG_BT=y
1515
CONFIG_BT_HCI_RAW=y
1616

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

samples/bluetooth/hci_ipc/nrf5340_cpunet_iso_broadcast-bt_ll_sw_split.conf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ CONFIG_HEAP_MEM_POOL_SIZE=4096
1010
CONFIG_BT=y
1111
CONFIG_BT_HCI_RAW=y
1212

13-
# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
14-
# Host number of completed commands does not follow normal flow control.
15-
CONFIG_BT_BUF_CMD_TX_COUNT=10
16-
1713
# Host and Controller common dependencies
1814
CONFIG_BT_BROADCASTER=y
1915
CONFIG_BT_OBSERVER=n

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
@@ -10,10 +10,6 @@ CONFIG_HEAP_MEM_POOL_SIZE=4096
1010
CONFIG_BT=y
1111
CONFIG_BT_HCI_RAW=y
1212

13-
# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
14-
# Host number of completed commands does not follow normal flow control.
15-
CONFIG_BT_BUF_CMD_TX_COUNT=10
16-
1713
CONFIG_BT_BUF_EVT_RX_SIZE=255
1814
CONFIG_BT_BUF_ACL_RX_SIZE=255
1915
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
@@ -10,10 +10,6 @@ CONFIG_HEAP_MEM_POOL_SIZE=4096
1010
CONFIG_BT=y
1111
CONFIG_BT_HCI_RAW=y
1212

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

0 commit comments

Comments
 (0)