Skip to content

Commit 2a5a711

Browse files
theob-procvinayak
authored andcommitted
Bluetooth: Host: Deprecate BT_BUF_ACL_RX_COUNT symbol
Because the number of ACL RX buffers must be at least the number of maximum connections plus one, increasing `CONFIG_BT_MAX_CONN` could inadvertently lead to a build failure if the number of ACL RX buffers is not also increased. This dependency may not be obvious to users. To address this issue, this commit deprecates the `CONFIG_BT_BUF_RX_COUNT` Kconfig symbol and computes the value in `buf.h` using the new `BT_BUF_RX_COUNT` define. Note that the default value and the minimum range value have been changed to 0 to "disable" the option. Additionally, to allow users to increase the number of ACL RX buffers, this commit introduces the new `CONFIG_BT_BUF_RX_COUNT_EXTRA` Kconfig symbol. The value of this symbol will be added to the computed value of `BT_BUF_RX_COUNT`. The configurations of tests and samples have been updated to reflect these changes. Signed-off-by: Théo Battrel <[email protected]> (cherry picked from commit 66ff97e) Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent 1e9d7b6 commit 2a5a711

File tree

8 files changed

+48
-12
lines changed

8 files changed

+48
-12
lines changed

include/zephyr/bluetooth/buf.h

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,41 @@ struct bt_buf_data {
8888
#define BT_BUF_ISO_RX_COUNT 0
8989
#endif /* CONFIG_BT_ISO */
9090

91+
/* see Core Spec v6.0 vol.4 part E 7.4.5 */
92+
#define BT_BUF_ACL_RX_COUNT_MAX 65535
93+
94+
#if defined(CONFIG_BT_CONN) && defined(CONFIG_BT_HCI_HOST)
95+
/* The host needs more ACL buffers than maximum ACL links. This is because of
96+
* the way we re-assemble ACL packets into L2CAP PDUs.
97+
*
98+
* We keep around the first buffer (that comes from the driver) to do
99+
* re-assembly into, and if all links are re-assembling, there will be no buffer
100+
* available for the HCI driver to allocate from.
101+
*
102+
* TODO: When CONFIG_BT_BUF_ACL_RX_COUNT is removed,
103+
* remove the MAX and only keep (CONFIG_BT_MAX_CONN + 1)
104+
*/
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)
108+
#else
109+
#define BT_BUF_ACL_RX_COUNT 0
110+
#endif /* CONFIG_BT_CONN && CONFIG_BT_HCI_HOST */
111+
112+
#if defined(CONFIG_BT_BUF_ACL_RX_COUNT) && CONFIG_BT_BUF_ACL_RX_COUNT > 0
113+
#warning "CONFIG_BT_BUF_ACL_RX_COUNT is deprecated, see Zephyr 4.1 migration guide"
114+
#endif /* CONFIG_BT_BUF_ACL_RX_COUNT && CONFIG_BT_BUF_ACL_RX_COUNT > 0 */
115+
116+
BUILD_ASSERT(BT_BUF_ACL_RX_COUNT <= BT_BUF_ACL_RX_COUNT_MAX,
117+
"Maximum number of ACL RX buffer is 65535, reduce CONFIG_BT_BUF_ACL_RX_COUNT_EXTRA");
118+
91119
/** Data size needed for HCI ACL, HCI ISO or Event RX buffers */
92120
#define BT_BUF_RX_SIZE (MAX(MAX(BT_BUF_ACL_RX_SIZE, BT_BUF_EVT_RX_SIZE), \
93121
BT_BUF_ISO_RX_SIZE))
94122

95123
/** Buffer count needed for HCI ACL, HCI ISO or Event RX buffers */
96124
#define BT_BUF_RX_COUNT (MAX(MAX(CONFIG_BT_BUF_EVT_RX_COUNT, \
97-
CONFIG_BT_BUF_ACL_RX_COUNT), \
125+
BT_BUF_ACL_RX_COUNT), \
98126
BT_BUF_ISO_RX_COUNT))
99127

100128
/** Data size needed for HCI Command buffers. */

samples/bluetooth/mesh/boards/bbc_microbit.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ CONFIG_BT_PERIPHERAL=n
1313
CONFIG_BT_EXT_ADV=n
1414
CONFIG_BT_RX_STACK_SIZE=1100
1515
CONFIG_BT_BUF_EVT_RX_COUNT=3
16-
CONFIG_BT_BUF_ACL_RX_COUNT=3
16+
CONFIG_BT_BUF_ACL_RX_COUNT_EXTRA=1
1717
CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT=3
1818

1919
CONFIG_BT_CTLR_ADV_EXT=n

samples/bluetooth/peripheral_hr/prj_minimal.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ CONFIG_BT_CTLR_PHY_2M=n
101101
# Reduce Bluetooth buffers
102102
CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT=1
103103
CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=45
104-
CONFIG_BT_BUF_ACL_RX_COUNT=2
105104
CONFIG_BT_BUF_EVT_RX_COUNT=2
106105

107106
CONFIG_BT_CONN_TX_MAX=2

subsys/bluetooth/common/Kconfig

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,21 @@ config BT_BUF_ACL_RX_SIZE
9292
An L2CAP SDU is also referred to as an L2CAP Credit-based frame or
9393
K-frame.
9494

95+
config BT_BUF_ACL_RX_COUNT_EXTRA
96+
int "Number of extra incoming ACL data buffers"
97+
default 0
98+
range 0 65535
99+
help
100+
Number of incoming extra ACL data buffers sent from the Controller to
101+
the Host.
102+
103+
By default, the number of incoming ACL data buffers is equal to
104+
CONFIG_BT_MAX_CONN + 1.
105+
95106
config BT_BUF_ACL_RX_COUNT
96-
int "Number of incoming ACL data buffers"
97-
default NET_BUF_RX_COUNT if NET_L2_BT
98-
default 3 if BT_RECV_BLOCKING
99-
default 6
100-
range 1 64
107+
int "[DEPRECATED] Number of incoming ACL data buffers"
108+
default 0
109+
range 0 256
101110
help
102111
Number or incoming ACL data buffers sent from the Controller to the
103112
Host.

subsys/bluetooth/host/buf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ NET_BUF_POOL_FIXED_DEFINE(discardable_pool, CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT,
3636
sizeof(struct bt_buf_data), NULL);
3737

3838
#if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL)
39-
NET_BUF_POOL_DEFINE(acl_in_pool, CONFIG_BT_BUF_ACL_RX_COUNT,
39+
NET_BUF_POOL_DEFINE(acl_in_pool, BT_BUF_ACL_RX_COUNT,
4040
BT_BUF_ACL_SIZE(CONFIG_BT_BUF_ACL_RX_SIZE),
4141
sizeof(struct acl_data), bt_hci_host_num_completed_packets);
4242

subsys/bluetooth/host/hci_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1922,7 +1922,7 @@ static int set_flow_control(void)
19221922
hbs = net_buf_add(buf, sizeof(*hbs));
19231923
(void)memset(hbs, 0, sizeof(*hbs));
19241924
hbs->acl_mtu = sys_cpu_to_le16(CONFIG_BT_BUF_ACL_RX_SIZE);
1925-
hbs->acl_pkts = sys_cpu_to_le16(CONFIG_BT_BUF_ACL_RX_COUNT);
1925+
hbs->acl_pkts = sys_cpu_to_le16(BT_BUF_ACL_RX_COUNT);
19261926

19271927
err = bt_hci_cmd_send_sync(BT_HCI_OP_HOST_BUFFER_SIZE, buf, NULL);
19281928
if (err) {

subsys/bluetooth/host/l2cap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ LOG_MODULE_REGISTER(bt_l2cap, CONFIG_BT_L2CAP_LOG_LEVEL);
3939
#define L2CAP_LE_MIN_MTU 23
4040
#define L2CAP_ECRED_MIN_MTU 64
4141

42-
#define L2CAP_LE_MAX_CREDITS (CONFIG_BT_BUF_ACL_RX_COUNT - 1)
42+
#define L2CAP_LE_MAX_CREDITS (BT_BUF_ACL_RX_COUNT - 1)
4343

4444
#define L2CAP_LE_CID_DYN_START 0x0040
4545
#define L2CAP_LE_CID_DYN_END 0x007f

subsys/bluetooth/host/rfcomm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ LOG_MODULE_REGISTER(bt_rfcomm);
3737
#define RFCOMM_MIN_MTU BT_RFCOMM_SIG_MIN_MTU
3838
#define RFCOMM_DEFAULT_MTU 127
3939

40-
#define RFCOMM_MAX_CREDITS (CONFIG_BT_BUF_ACL_RX_COUNT - 1)
40+
#define RFCOMM_MAX_CREDITS (BT_BUF_ACL_RX_COUNT - 1)
4141
#define RFCOMM_CREDITS_THRESHOLD (RFCOMM_MAX_CREDITS / 2)
4242
#define RFCOMM_DEFAULT_CREDIT RFCOMM_MAX_CREDITS
4343

0 commit comments

Comments
 (0)