Bluetooth: host: Add lower bound for CONFIG_BT_BUF_ACL_RX_COUNT

See comment above assert for more.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
This commit is contained in:
Jonathan Rico 2024-07-08 14:52:07 +02:00 committed by Anas Nashif
commit 4afe745a1d
16 changed files with 55 additions and 11 deletions

View file

@ -806,6 +806,12 @@ Bluetooth Host
(:github:`75065`) (:github:`75065`)
* :kconfig:option:`CONFIG_BT_BUF_ACL_RX_COUNT` now needs to be larger than
:kconfig:option:`CONFIG_BT_MAX_CONN`. This was always the case due to the design of the HCI
interface. It is now being enforced through a build-time assertion.
(:github:`75592`)
Bluetooth Crypto Bluetooth Crypto
================ ================

View file

@ -4,6 +4,7 @@ CONFIG_BT_AUTO_PHY_UPDATE=n
CONFIG_BT_PRIVACY=y CONFIG_BT_PRIVACY=y
CONFIG_BT_MAX_CONN=62 CONFIG_BT_MAX_CONN=62
CONFIG_BT_BUF_ACL_RX_COUNT=63
# CONFIG_BT_GATT_CLIENT=y # CONFIG_BT_GATT_CLIENT=y

View file

@ -10,6 +10,7 @@ CONFIG_BT_HCI_RAW_H4_ENABLE=y
# Controller configuration. Modify these for your application's needs. # Controller configuration. Modify these for your application's needs.
CONFIG_BT_MAX_CONN=16 CONFIG_BT_MAX_CONN=16
CONFIG_BT_BUF_ACL_RX_COUNT=17
CONFIG_BT_BUF_ACL_RX_SIZE=255 CONFIG_BT_BUF_ACL_RX_SIZE=255
CONFIG_BT_BUF_CMD_TX_SIZE=255 CONFIG_BT_BUF_CMD_TX_SIZE=255
CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=255 CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=255

View file

@ -8,6 +8,7 @@ CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n
CONFIG_BT_MAX_CONN=62 CONFIG_BT_MAX_CONN=62
CONFIG_BT_ID_MAX=62 CONFIG_BT_ID_MAX=62
CONFIG_BT_BUF_ACL_RX_COUNT=63
# CONFIG_BT_SMP=y # CONFIG_BT_SMP=y
# CONFIG_BT_MAX_PAIRED=62 # CONFIG_BT_MAX_PAIRED=62

View file

@ -80,7 +80,7 @@ config BT_BUF_ACL_RX_SIZE
config BT_BUF_ACL_RX_COUNT config BT_BUF_ACL_RX_COUNT
int "Number of incoming ACL data buffers" int "Number of incoming ACL data buffers"
default 6 default 6
range 1 64 range 2 256
help help
Number or incoming ACL data buffers sent from the Controller to the Number or incoming ACL data buffers sent from the Controller to the
Host. Host.
@ -94,6 +94,10 @@ config BT_BUF_ACL_RX_COUNT
When Controller to Host flow control is not enabled the Controller When Controller to Host flow control is not enabled the Controller
can assume that the Host has infinite amount of buffers. can assume that the Host has infinite amount of buffers.
For both configurations, there is an additional requirement that is
enforced by a build-time check: BT_BUF_ACL_RX_COUNT needs to be at
least one greater than BT_MAX_CONN.
config BT_BUF_EVT_RX_SIZE config BT_BUF_EVT_RX_SIZE
int "Maximum supported HCI Event buffer length" int "Maximum supported HCI Event buffer length"
default 255 if (BT_EXT_ADV && BT_OBSERVER) || BT_PER_ADV_SYNC || BT_DF_CONNECTION_CTE_RX || BT_CLASSIC default 255 if (BT_EXT_ADV && BT_OBSERVER) || BT_PER_ADV_SYNC || BT_DF_CONNECTION_CTE_RX || BT_CLASSIC

View file

@ -13,6 +13,7 @@
#include <zephyr/kernel.h> #include <zephyr/kernel.h>
#include <zephyr/bluetooth/bluetooth.h> #include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/buf.h>
/* /*
* The unpacked structs below are used inside __packed structures that reflect * The unpacked structs below are used inside __packed structures that reflect
@ -59,3 +60,27 @@ BUILD_ASSERT(!IS_ENABLED(CONFIG_LOG_MODE_IMMEDIATE), "Immediate logging "
"on selected backend(s) not " "on selected backend(s) not "
"supported with the software Link Layer"); "supported with the software Link Layer");
#endif #endif
#if defined(CONFIG_BT_CONN) && defined(CONFIG_BT_HCI_HOST)
/* The host needs more ACL buffers than maximum ACL links. This is because of
* the way we re-assemble ACL packets into L2CAP PDUs.
*
* We keep around the first buffer (that comes from the driver) to do
* re-assembly into, and if all links are re-assembling, there will be no buffer
* available for the HCI driver to allocate from.
*
* Fixing it properly involves a re-design of the HCI driver interface.
*/
#if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL)
BUILD_ASSERT(CONFIG_BT_BUF_ACL_RX_COUNT > CONFIG_BT_MAX_CONN);
#else /* !CONFIG_BT_HCI_ACL_FLOW_CONTROL */
/* BT_BUF_RX_COUNT is defined in include/zephyr/bluetooth/buf.h */
BUILD_ASSERT(BT_BUF_RX_COUNT > CONFIG_BT_MAX_CONN,
"BT_BUF_RX_COUNT needs to be greater than CONFIG_BT_MAX_CONN. "
"In order to do that, increase CONFIG_BT_BUF_ACL_RX_COUNT.");
#endif /* CONFIG_BT_HCI_ACL_FLOW_CONTROL */
#endif /* CONFIG_BT_CONN */

View file

@ -1,4 +1,5 @@
CONFIG_BT_MAX_CONN=16 CONFIG_BT_MAX_CONN=16
CONFIG_BT_BUF_ACL_RX_COUNT=17
# debug options # debug options
# CONFIG_UART_CONSOLE=y # CONFIG_UART_CONSOLE=y

View file

@ -1,4 +1,5 @@
CONFIG_BT_MAX_CONN=16 CONFIG_BT_MAX_CONN=16
CONFIG_BT_BUF_ACL_RX_COUNT=17
# debug options # debug options
# CONFIG_UART_CONSOLE=y # CONFIG_UART_CONSOLE=y

View file

@ -3,7 +3,7 @@ CONFIG_ASSERT=y
CONFIG_BT=y CONFIG_BT=y
CONFIG_BT_HCI_RAW=y CONFIG_BT_HCI_RAW=y
CONFIG_BT_MAX_CONN=16 CONFIG_BT_MAX_CONN=1
CONFIG_BT_BUF_CMD_TX_COUNT=10 CONFIG_BT_BUF_CMD_TX_COUNT=10

View file

@ -42,6 +42,7 @@ CONFIG_BT_CTLR_DATA_LENGTH_MAX=27
CONFIG_BT_CTLR_RX_BUFFERS=10 CONFIG_BT_CTLR_RX_BUFFERS=10
CONFIG_BT_MAX_CONN=10 CONFIG_BT_MAX_CONN=10
CONFIG_BT_BUF_ACL_RX_COUNT=11
CONFIG_LOG=y CONFIG_LOG=y
CONFIG_ASSERT=y CONFIG_ASSERT=y

View file

@ -34,6 +34,7 @@ CONFIG_BT_CTLR_DATA_LENGTH_MAX=81
CONFIG_BT_CTLR_RX_BUFFERS=10 CONFIG_BT_CTLR_RX_BUFFERS=10
CONFIG_BT_MAX_CONN=10 CONFIG_BT_MAX_CONN=10
CONFIG_BT_BUF_ACL_RX_COUNT=11
CONFIG_LOG=y CONFIG_LOG=y
CONFIG_ASSERT=y CONFIG_ASSERT=y

View file

@ -42,6 +42,7 @@ CONFIG_BT_CTLR_DATA_LENGTH_MAX=27
CONFIG_BT_CTLR_RX_BUFFERS=10 CONFIG_BT_CTLR_RX_BUFFERS=10
CONFIG_BT_MAX_CONN=10 CONFIG_BT_MAX_CONN=10
CONFIG_BT_BUF_ACL_RX_COUNT=11
CONFIG_LOG=y CONFIG_LOG=y
CONFIG_ASSERT=y CONFIG_ASSERT=y

View file

@ -2,6 +2,7 @@ CONFIG_BT=y
CONFIG_LOG=y CONFIG_LOG=y
CONFIG_BT_CENTRAL=y CONFIG_BT_CENTRAL=y
CONFIG_BT_MAX_CONN=12 CONFIG_BT_MAX_CONN=12
CONFIG_BT_BUF_ACL_RX_COUNT=13
CONFIG_BT_MAX_PAIRED=12 CONFIG_BT_MAX_PAIRED=12
CONFIG_BT_SMP=y CONFIG_BT_SMP=y
CONFIG_BT_PRIVACY=y CONFIG_BT_PRIVACY=y

View file

@ -26,11 +26,10 @@ CONFIG_BT_AUTO_PHY_UPDATE=n
CONFIG_BT_AUTO_DATA_LEN_UPDATE=n CONFIG_BT_AUTO_DATA_LEN_UPDATE=n
CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n
# As many host buffers as connection slots
# The whole test hinges on bufs <= links, which is a valid
# configuration at the time of writing this test.
CONFIG_BT_MAX_CONN=3 CONFIG_BT_MAX_CONN=3
CONFIG_BT_BUF_ACL_RX_COUNT=3 CONFIG_BT_BUF_ACL_RX_COUNT=4
# It passes with 4
# CONFIG_BT_BUF_ACL_RX_COUNT=4 # This test will fail when CONFIG_BT_MAX_CONN == CONFIG_BT_BUF_ACL_RX_COUNT
# CONFIG_BT_BUF_ACL_RX_COUNT=3
CONFIG_BT_HCI_ACL_FLOW_CONTROL=y CONFIG_BT_HCI_ACL_FLOW_CONTROL=y

View file

@ -23,8 +23,8 @@ LOG_MODULE_REGISTER(dut, CONFIG_APP_LOG_LEVEL);
#define NUM_TESTERS CONFIG_BT_MAX_CONN #define NUM_TESTERS CONFIG_BT_MAX_CONN
/* This test will fail when CONFIG_BT_MAX_CONN == CONFIG_BT_BUF_ACL_RX_COUNT */ /* Build with the minimum possible amount of RX buffers */
BUILD_ASSERT(CONFIG_BT_BUF_ACL_RX_COUNT == CONFIG_BT_MAX_CONN); BUILD_ASSERT(CONFIG_BT_BUF_ACL_RX_COUNT == (CONFIG_BT_MAX_CONN + 1));
struct tester { struct tester {
size_t sdu_count; size_t sdu_count;
@ -151,7 +151,7 @@ void entrypoint_dut(void)
* Test purpose: * Test purpose:
* *
* Verifies that we are able to do L2CAP recombination on multiple links * Verifies that we are able to do L2CAP recombination on multiple links
* when we only have as many buffers as links. * when we have the smallest possible amount of ACL buffers.
* *
* Devices: * Devices:
* - `dut`: receives L2CAP PDUs from testers * - `dut`: receives L2CAP PDUs from testers

View file

@ -12,6 +12,7 @@ CONFIG_BT_AUTO_DATA_LEN_UPDATE=y
CONFIG_BT_MAX_CONN=250 CONFIG_BT_MAX_CONN=250
CONFIG_BT_ID_MAX=250 CONFIG_BT_ID_MAX=250
CONFIG_BT_BUF_ACL_RX_COUNT=251
# L2CAP, ATT and SMP usage cause data transmission deadlock due to shortage # L2CAP, ATT and SMP usage cause data transmission deadlock due to shortage
# of buffers when transactions crossover amongst the connections in the same # of buffers when transactions crossover amongst the connections in the same