Skip to content

Commit 7835776

Browse files
committed
Bluetooth: Host: Fix redundant ACL Rx buffer allocation
HCI ACL Rx buffer count is not required in addition, the calculated BT_BUF_ACL_RX_COUNT is sufficient for L2CAP recombination. But it is required to have additional Rx buffers for the HCI ACL Rx that can happen due to the generated HCI Host Number of Completed packets events. Fixes commit d382fca ("Bluetooth: Controller: Fix HCI command buffer allocation failure"). Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
1 parent 77aff10 commit 7835776

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

include/zephyr/bluetooth/buf.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,20 @@ static inline enum bt_buf_type bt_buf_type_from_h4(uint8_t h4_type, enum bt_buf_
151151
* re-assembly into, and if all links are re-assembling, there will be no buffer
152152
* available for the HCI driver to allocate from.
153153
*/
154-
#define BT_BUF_ACL_RX_COUNT_EXTRA CONFIG_BT_BUF_ACL_RX_COUNT_EXTRA
155-
#define BT_BUF_ACL_RX_COUNT (1 + BT_BUF_ACL_RX_COUNT_EXTRA)
154+
#define BT_BUF_ACL_RX_COUNT_RESERVED 1
155+
156+
/* Host will block unreferencing one Rx buffer per active ACL connection and generate HCI Host
157+
* Number of Completed packets for the rest. This means new HCI data packets will be generated by
158+
* the Controller.
159+
*/
160+
#define BT_BUF_ACL_RX_COUNT_BLOCKED_MIN 1
161+
#define BT_BUF_ACL_RX_COUNT_BLOCKED_MAX CONFIG_BT_MAX_CONN
162+
163+
/* To avoid deadlock account for maximum Rx buffers blocked in the Host */
164+
#define BT_BUF_ACL_RX_COUNT_EXTRA MAX(BT_BUF_ACL_RX_COUNT_BLOCKED_MAX, \
165+
CONFIG_BT_BUF_ACL_RX_COUNT_EXTRA)
166+
/* ACL Rx Buffers being processed by the Host */
167+
#define BT_BUF_ACL_RX_COUNT (BT_BUF_ACL_RX_COUNT_RESERVED + BT_BUF_ACL_RX_COUNT_EXTRA)
156168
#else
157169
#define BT_BUF_ACL_RX_COUNT_EXTRA 0
158170
#define BT_BUF_ACL_RX_COUNT 0

subsys/bluetooth/common/hci_common_internal.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,9 @@ BUILD_ASSERT((CONFIG_BT_BUF_CMD_TX_COUNT == CONFIG_BT_CTLR_HCI_NUM_CMD_PKT_MAX),
4141
*
4242
* Host keeps the first, and subsequent, Rx buffers (that comes from the driver) for each connection
4343
* to do re-assembly into, up to the L2CAP SDU length required number of Rx buffers.
44-
* BT_BUF_ACL_RX_COUNT_EXTRA holds the application configured number of buffers across active
44+
* BT_BUF_ACL_RX_COUNT_BLOCKED_MAX holds the application configured number of buffers across active
4545
* connections for recombination of HCI data packets to L2CAP SDUs.
4646
*
47-
* BT_BUF_HCI_EVT_RX_COUNT defines the number of available buffers reserved for "synchronous"
48-
* processing of HCI events like Number of Completed Packets, disconnection complete etc.
49-
*
5047
* BT_BUF_HCI_ACL_RX_COUNT defines the number of available buffers for Controller to Host data
5148
* flow control; keeping the application configured BT_BUF_ACL_RX_COUNT_EXTRA number of buffers
5249
* available for L2CAP recombination, and a reserved number of buffers for processing HCI events.
@@ -67,12 +64,13 @@ BUILD_ASSERT((CONFIG_BT_BUF_CMD_TX_COUNT == CONFIG_BT_CTLR_HCI_NUM_CMD_PKT_MAX),
6764
* control to restrict buffers required on resource constraint devices, i.e. if these events are not
6865
* processed "synchronous".
6966
*/
70-
#define BT_BUF_HCI_EVT_RX_COUNT 1
71-
#define BT_BUF_HCI_ACL_RX_COUNT (BT_BUF_RX_COUNT - BT_BUF_HCI_EVT_RX_COUNT - \
72-
BT_BUF_ACL_RX_COUNT_EXTRA)
67+
#define BT_BUF_HCI_ACL_RX_COUNT (BT_BUF_RX_COUNT - BT_BUF_ACL_RX_COUNT_EXTRA)
68+
#define BT_BUF_HCI_ACL_RX_COUNT_EXTRA (BT_BUF_HCI_ACL_RX_COUNT - BT_BUF_ACL_RX_COUNT_RESERVED - \
69+
BT_BUF_ACL_RX_COUNT_BLOCKED_MIN)
7370
#define BT_BUF_CMD_TX_HOST_NUM_CMPLT_PKT (BT_BUF_HCI_ACL_RX_COUNT)
7471

7572
#else /* !CONFIG_BT_HCI_ACL_FLOW_CONTROL */
73+
#define BT_BUF_HCI_ACL_RX_COUNT_EXTRA 0
7674
#define BT_BUF_CMD_TX_HOST_NUM_CMPLT_PKT 0
7775
#endif /* !CONFIG_BT_HCI_ACL_FLOW_CONTROL */
7876

subsys/bluetooth/host/buf.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ static void evt_pool_destroy(struct net_buf *buf)
8383
buf_rx_freed_notify(BT_BUF_EVT);
8484
}
8585

86-
NET_BUF_POOL_DEFINE(acl_in_pool, (BT_BUF_ACL_RX_COUNT_EXTRA + BT_BUF_HCI_ACL_RX_COUNT),
87-
BT_BUF_ACL_SIZE(CONFIG_BT_BUF_ACL_RX_SIZE), sizeof(struct bt_conn_rx),
88-
acl_in_pool_destroy);
86+
NET_BUF_POOL_DEFINE(acl_in_pool, (BT_BUF_ACL_RX_COUNT_EXTRA + BT_BUF_HCI_ACL_RX_COUNT_EXTRA),
87+
BT_BUF_ACL_SIZE(CONFIG_BT_BUF_ACL_RX_SIZE),
88+
sizeof(struct bt_conn_rx), acl_in_pool_destroy);
8989

9090
NET_BUF_POOL_FIXED_DEFINE(evt_pool, CONFIG_BT_BUF_EVT_RX_COUNT, BT_BUF_EVT_RX_SIZE, 0,
9191
evt_pool_destroy);

0 commit comments

Comments
 (0)