Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions include/zephyr/bluetooth/buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ struct bt_buf_data {
* available for the HCI driver to allocate from.
*
* TODO: When CONFIG_BT_BUF_ACL_RX_COUNT is removed,
* remove the MAX and only keep the 1.
* remove the MAX and only keep (CONFIG_BT_MAX_CONN + 1)
*/
#define BT_BUF_ACL_RX_COUNT_EXTRA CONFIG_BT_BUF_ACL_RX_COUNT_EXTRA
#define BT_BUF_ACL_RX_COUNT (MAX(CONFIG_BT_BUF_ACL_RX_COUNT, 1) + BT_BUF_ACL_RX_COUNT_EXTRA)
#define BT_BUF_ACL_RX_COUNT \
(MAX(CONFIG_BT_BUF_ACL_RX_COUNT, (CONFIG_BT_MAX_CONN + 1)) + \
CONFIG_BT_BUF_ACL_RX_COUNT_EXTRA)
#else
#define BT_BUF_ACL_RX_COUNT_EXTRA 0
#define BT_BUF_ACL_RX_COUNT 0
#define BT_BUF_ACL_RX_COUNT 0
#endif /* CONFIG_BT_CONN && CONFIG_BT_HCI_HOST */

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

/* Controller can generate up to CONFIG_BT_BUF_ACL_TX_COUNT number of unique HCI Number of Completed
* Packets events.
*/
BUILD_ASSERT(CONFIG_BT_BUF_EVT_RX_COUNT > CONFIG_BT_BUF_ACL_TX_COUNT,
"Increase Event RX buffer count to be greater than ACL TX buffer count");

/** Buffer count needed for HCI ACL or HCI ISO plus Event RX buffers */
#define BT_BUF_RX_COUNT (CONFIG_BT_BUF_EVT_RX_COUNT + \
MAX(BT_BUF_ACL_RX_COUNT, BT_BUF_ISO_RX_COUNT))
/** Buffer count needed for HCI ACL, HCI ISO or Event RX buffers */
#define BT_BUF_RX_COUNT (MAX(MAX(CONFIG_BT_BUF_EVT_RX_COUNT, \
BT_BUF_ACL_RX_COUNT), \
BT_BUF_ISO_RX_COUNT))

/** Data size needed for HCI Command buffers. */
#define BT_BUF_CMD_TX_SIZE BT_BUF_CMD_SIZE(CONFIG_BT_BUF_CMD_TX_SIZE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ CONFIG_BT_HCI_RAW=y
CONFIG_BT_HCI_RAW_RESERVE=1
CONFIG_BT_MAX_CONN=2

# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
# Host number of completed commands does not follow normal flow control.
CONFIG_BT_BUF_CMD_TX_COUNT=10

CONFIG_BT_BUF_EVT_RX_COUNT=16

CONFIG_BT_BUF_EVT_RX_SIZE=255
CONFIG_BT_BUF_ACL_RX_SIZE=255
CONFIG_BT_BUF_ACL_TX_SIZE=251
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ CONFIG_BT_HCI_RAW=y
CONFIG_BT_HCI_RAW_RESERVE=1
CONFIG_BT_MAX_CONN=16


# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
# Host number of completed commands does not follow normal flow control.
CONFIG_BT_BUF_CMD_TX_COUNT=10

# Controller
CONFIG_BT_LL_SW_SPLIT=y

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ CONFIG_BT_HCI_RAW=y
CONFIG_BT_HCI_RAW_RESERVE=1
CONFIG_BT_MAX_CONN=2

# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
# Host number of completed commands does not follow normal flow control.
CONFIG_BT_BUF_CMD_TX_COUNT=10

CONFIG_BT_BUF_EVT_RX_COUNT=16

CONFIG_BT_BUF_EVT_RX_SIZE=255
CONFIG_BT_BUF_ACL_RX_SIZE=255
CONFIG_BT_BUF_ACL_TX_SIZE=251
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ CONFIG_BT_HCI_RAW=y
CONFIG_BT_HCI_RAW_RESERVE=1
CONFIG_BT_MAX_CONN=2

# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
# Host number of completed commands does not follow normal flow control.
CONFIG_BT_BUF_CMD_TX_COUNT=10

CONFIG_BT_BUF_EVT_RX_COUNT=16

CONFIG_BT_BUF_EVT_RX_SIZE=255
CONFIG_BT_BUF_ACL_RX_SIZE=255
CONFIG_BT_BUF_ACL_TX_SIZE=251
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ CONFIG_BT_HCI_RAW=y
CONFIG_BT_HCI_RAW_RESERVE=1
CONFIG_BT_MAX_CONN=2

# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
# Host number of completed commands does not follow normal flow control.
CONFIG_BT_BUF_CMD_TX_COUNT=10

CONFIG_BT_BUF_EVT_RX_COUNT=16

CONFIG_BT_BUF_EVT_RX_SIZE=255
CONFIG_BT_BUF_ACL_RX_SIZE=255
CONFIG_BT_BUF_ACL_TX_SIZE=251
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ CONFIG_BT=y
CONFIG_BT_HCI_RAW=y
CONFIG_BT_HCI_RAW_RESERVE=1

# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
# Host number of completed commands does not follow normal flow control.
CONFIG_BT_BUF_CMD_TX_COUNT=10

CONFIG_BT_BUF_EVT_RX_SIZE=255
CONFIG_BT_BUF_ACL_RX_SIZE=255
CONFIG_BT_BUF_ACL_TX_SIZE=251
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ CONFIG_BT=y
CONFIG_BT_HCI_RAW=y
CONFIG_BT_HCI_RAW_RESERVE=1

# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
# Host number of completed commands does not follow normal flow control.
CONFIG_BT_BUF_CMD_TX_COUNT=10

CONFIG_BT_BUF_EVT_RX_SIZE=255
CONFIG_BT_BUF_ACL_RX_SIZE=255
CONFIG_BT_BUF_ACL_TX_SIZE=251
Expand Down
5 changes: 5 additions & 0 deletions samples/bluetooth/hci_ipc/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ CONFIG_BT_HCI_RAW=y
CONFIG_BT_HCI_RAW_RESERVE=1
CONFIG_BT_MAX_CONN=16


# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
# Host number of completed commands does not follow normal flow control.
CONFIG_BT_BUF_CMD_TX_COUNT=10

# Enable and adjust the below value as necessary
# CONFIG_BT_BUF_EVT_RX_COUNT=16
# CONFIG_BT_BUF_EVT_RX_SIZE=255
Expand Down
4 changes: 4 additions & 0 deletions samples/bluetooth/hci_uart/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ CONFIG_BT_TINYCRYPT_ECC=n
CONFIG_BT_CTLR_DTM_HCI=y

CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512

# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
# Host number of completed commands does not follow normal flow control.
CONFIG_BT_BUF_CMD_TX_COUNT=10
4 changes: 4 additions & 0 deletions samples/bluetooth/hci_usb/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
CONFIG_SERIAL=n
CONFIG_CONSOLE=n
CONFIG_UART_CONSOLE=n

# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
# Host number of completed commands does not follow normal flow control.
CONFIG_BT_BUF_CMD_TX_COUNT=10
4 changes: 1 addition & 3 deletions samples/bluetooth/mesh/boards/bbc_microbit.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ CONFIG_BT_PERIPHERAL=n
CONFIG_BT_EXT_ADV=n
CONFIG_BT_RX_STACK_SIZE=1100
CONFIG_BT_BUF_EVT_RX_COUNT=3
CONFIG_BT_BUF_ACL_RX_COUNT_EXTRA=1
CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT=3

# CONFIG_BT_BUF_ACL_TX_COUNT has to be less than CONFIG_BT_BUF_EVT_RX_COUNT
CONFIG_BT_BUF_ACL_TX_COUNT=1

CONFIG_BT_CTLR_ADV_EXT=n

CONFIG_BT_MESH_ADV_BUF_COUNT=3
Expand Down
2 changes: 1 addition & 1 deletion samples/bluetooth/peripheral_hr/prj_minimal.conf
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ CONFIG_BT_CTLR_PHY_2M=n
# Reduce Bluetooth buffers
CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT=1
CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=45
CONFIG_BT_BUF_EVT_RX_COUNT=4
CONFIG_BT_BUF_EVT_RX_COUNT=2

CONFIG_BT_CONN_TX_MAX=2
CONFIG_BT_L2CAP_TX_BUF_COUNT=2
Expand Down
61 changes: 8 additions & 53 deletions subsys/bluetooth/common/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,15 @@ config BT_BUF_ACL_RX_SIZE
K-frame.

config BT_BUF_ACL_RX_COUNT_EXTRA
# As Host implementation unconditionally references this Kconfig, we
# hide it for !BT_CONN and default to 0.
int "Number of extra incoming ACL data buffers" if BT_CONN
range 1 65535 if BT_CONN
default BT_MAX_CONN if BT_CONN
range 0 0
int "Number of extra incoming ACL data buffers"
default 0
range 0 65535
help
Number of incoming extra ACL data buffers sent from the Controller to
the Host.

By default, the total number of incoming ACL data buffers is equal to
CONFIG_BT_MAX_CONN + 1, to support L2CAP recombination.

The L2CAP recombination in the Host keeps the first Rx buffer for each
connection and uses one Rx buffer across all connections to receive a
fragment from the Controller.
By default, the number of incoming ACL data buffers is equal to
CONFIG_BT_MAX_CONN + 1.

config BT_BUF_ACL_RX_COUNT
int "[DEPRECATED] Number of incoming ACL data buffers"
Expand Down Expand Up @@ -143,8 +135,7 @@ config BT_BUF_EVT_RX_SIZE

config BT_BUF_EVT_RX_COUNT
int "Number of HCI Event buffers"
default 8 if BT_HCI_RAW
default 4 if BT_RECV_BLOCKING
default 3 if BT_RECV_BLOCKING
default 20 if (BT_MESH && !(BT_BUF_EVT_DISCARDABLE_COUNT > 0))
default 10
range 2 255
Expand Down Expand Up @@ -201,48 +192,12 @@ config BT_BUF_CMD_TX_SIZE
to the maximum of 255.

config BT_BUF_CMD_TX_COUNT
# This option is only visible for a user when Host and Controller are build together, or for
# Host-only builds.
int "Number of HCI command buffers" if !BT_HCI_RAW || !BT_CTLR
# This option is present when Host and Controller are build together, or
# for Host only builds, or when Controller-to-Host ACL data flow control
# is disabled.
depends on !BT_HCI_RAW || !BT_CTLR || !BT_HCI_ACL_FLOW_CONTROL
# The Mesh stack usage in applications and tests can start both advertising and scanning in
# parallel. Also, when BT_MESH_WORKQ_SYS is enabled, the Mesh stack is starting Extended
# Advertising in the receive callback run in the system work queue and as the Host also uses
# the system work queue for HCI command Tx towards the Controller, one additional HCI
# command buffer is needed.
range 2 64 if BT_MESH
range 1 64
default 2 if BT_MESH
default 1
int "Number of HCI command buffers"
default 2
range 2 64
help
Number of buffers available for outgoing HCI commands from the Host.

HCI Controllers may not support Num_HCI_Command_Packets > 1, hence they default to 1 when
not enabling Controller to Host data flow control (BT_HCI_ACL_FLOW_CONTROL), Read Remote
Version Information (BT_REMOTE_VERSION), Auto-Initiate PHY update (BT_AUTO_PHY_UPDATE), or
Auto-Initiate Data Length Update (BT_AUTO_DATA_LEN_UPDATE).

Normal HCI commands follow the HCI command flow control using Num_HCI_Command_Packets
return in HCI command complete and status.

The Host Number of Completed Packets command does not follow normal flow control of HCI
commands and the Controller side HCI drivers that allocates HCI command buffers with
K_NO_WAIT can end up running out of command buffers.

When Controller to Host data flow control is enabled in the Host-only or combined
Host plus Controller build, the internal BT_BUF_CMD_TX_COUNT is adjusted accordingly
taking into considerations the enabled auto-initiated procedures, and to follow the normal
HCI command flow control to be able to send Ncmd normal HCI commands and
BT_BUF_ACL_RX_COUNT of Host Number of Completed Packets command down to the Controller.

When Controller to Host data flow control is supported in the Controller-only build,
the internal BT_BUF_CMD_TX_COUNT is adjusted to be equal to (BT_BUF_RX_COUNT + Ncmd).

Where Ncmd is supported maximum Num_HCI_Command_Packets in the Controller implementation.

endmenu

config BT_HAS_HCI_VS
Expand Down
100 changes: 0 additions & 100 deletions subsys/bluetooth/common/hci_common_internal.h

This file was deleted.

9 changes: 0 additions & 9 deletions subsys/bluetooth/controller/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,6 @@ endchoice

comment "BLE Controller configuration"

config BT_CTLR_HCI_NUM_CMD_PKT_MAX
# Hidden Controller implementation supported Num_HCI_Command_Packets value.
# This value will be used to calculate the total number of HCI command buffers to be
# allocated, BT_BUF_CMD_TX_COUNT, dependent on HCI Controller to Host data flow control
# being enabled.
int
default 1 if BT_LL_SW_SPLIT
default 1

config BT_CTLR_CRYPTO
bool "Crypto functions in Controller"
default y
Expand Down
Loading
Loading