diff --git a/include/bluetooth/avdtp.h b/include/bluetooth/avdtp.h index 574b2cd05b3..d17da9079af 100644 --- a/include/bluetooth/avdtp.h +++ b/include/bluetooth/avdtp.h @@ -14,6 +14,8 @@ extern "C" { #endif +#include + /** @brief AVDTP SEID Information */ struct bt_avdtp_seid_info { /** Stream End Point ID */ diff --git a/include/bluetooth/buf.h b/include/bluetooth/buf.h index 2c076177c75..2c98fc25a8f 100644 --- a/include/bluetooth/buf.h +++ b/include/bluetooth/buf.h @@ -64,8 +64,17 @@ struct bt_buf_data { /** Helper to calculate needed buffer size for HCI Command packets. */ #define BT_BUF_CMD_SIZE(size) BT_BUF_SIZE(BT_HCI_CMD_HDR_SIZE + (size)) -/** Data size neeed for HCI RX buffers */ -#define BT_BUF_RX_SIZE (BT_BUF_SIZE(CONFIG_BT_RX_BUF_LEN)) +/** Data size needed for HCI ACL RX buffers */ +#define BT_BUF_ACL_RX_SIZE BT_BUF_ACL_SIZE(CONFIG_BT_BUF_ACL_RX_SIZE) + +/** Data size needed for HCI Event RX buffers */ +#define BT_BUF_EVT_RX_SIZE BT_BUF_EVT_SIZE(CONFIG_BT_BUF_EVT_RX_SIZE) + +/** Data size needed for HCI ACL or Event RX buffers */ +#define BT_BUF_RX_SIZE (MAX(BT_BUF_ACL_RX_SIZE, BT_BUF_EVT_RX_SIZE)) + +/** Data size needed for HCI Command buffers. */ +#define BT_BUF_CMD_TX_SIZE BT_BUF_CMD_SIZE(CONFIG_BT_BUF_CMD_TX_SIZE) /** Allocate a buffer for incoming data * diff --git a/include/bluetooth/hci_raw.h b/include/bluetooth/hci_raw.h index d7f2fa2cca4..7f660454b2f 100644 --- a/include/bluetooth/hci_raw.h +++ b/include/bluetooth/hci_raw.h @@ -21,19 +21,6 @@ extern "C" { #endif -#define _BT_ACL_BUF_SIZE(len) (BT_BUF_RESERVE + \ - BT_HCI_ACL_HDR_SIZE + \ - (len)) - -/** Data size needed for ACL buffers */ -#define BT_BUF_ACL_SIZE _BT_ACL_BUF_SIZE(CONFIG_BT_HCI_ACL_DATA_SIZE) - -#if defined(CONFIG_BT_CTLR_TX_BUFFERS) -#define BT_HCI_ACL_COUNT CONFIG_BT_CTLR_TX_BUFFERS -#else -#define BT_HCI_ACL_COUNT 6 -#endif - /** @brief Send packet to the Bluetooth controller * * Send packet to the Bluetooth controller. Caller needs to diff --git a/include/bluetooth/l2cap.h b/include/bluetooth/l2cap.h index 322afd34995..b3d0725fffc 100644 --- a/include/bluetooth/l2cap.h +++ b/include/bluetooth/l2cap.h @@ -29,6 +29,12 @@ extern "C" { /** L2CAP header size, used for buffer size calculations */ #define BT_L2CAP_HDR_SIZE 4 +/** Maximum Transmission Unit (MTU) for an outgoing L2CAP PDU. */ +#define BT_L2CAP_TX_MTU (CONFIG_BT_L2CAP_TX_MTU) + +/** Maximum Transmission Unit (MTU) for an incoming L2CAP PDU. */ +#define BT_L2CAP_RX_MTU (CONFIG_BT_BUF_ACL_RX_SIZE - BT_L2CAP_HDR_SIZE) + /** @def BT_L2CAP_BUF_SIZE * * @brief Helper to calculate needed buffer size for L2CAP PDUs. diff --git a/samples/bluetooth/hci_spi/prj.conf b/samples/bluetooth/hci_spi/prj.conf index a0864b08bec..83c808ac5d7 100644 --- a/samples/bluetooth/hci_spi/prj.conf +++ b/samples/bluetooth/hci_spi/prj.conf @@ -6,6 +6,6 @@ CONFIG_BT=y CONFIG_BT_HCI_RAW=y CONFIG_BT_MAX_CONN=20 CONFIG_BT_TINYCRYPT_ECC=n -CONFIG_BT_RX_BUF_COUNT=10 -CONFIG_BT_RX_BUF_LEN=255 +CONFIG_BT_BUF_ACL_RX_COUNT=10 +CONFIG_BT_BUF_ACL_RX_SIZE=251 CONFIG_BT_HCI_RAW_RESERVE=1 diff --git a/samples/bluetooth/hci_uart/boards/bbc_microbit.conf b/samples/bluetooth/hci_uart/boards/bbc_microbit.conf index 01b4251c63c..4ec62e167cc 100644 --- a/samples/bluetooth/hci_uart/boards/bbc_microbit.conf +++ b/samples/bluetooth/hci_uart/boards/bbc_microbit.conf @@ -2,5 +2,7 @@ CONFIG_MAIN_STACK_SIZE=512 CONFIG_IDLE_STACK_SIZE=256 CONFIG_ISR_STACK_SIZE=512 CONFIG_BT_MAX_CONN=10 -CONFIG_BT_RX_BUF_LEN=76 -CONFIG_BT_DISCARDABLE_BUF_SIZE=45 +# Revert values set in prj.conf, set them to their Kconfig default value +CONFIG_BT_BUF_CMD_TX_SIZE=65 +CONFIG_BT_BUF_ACL_RX_SIZE=69 +CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=43 diff --git a/samples/bluetooth/hci_uart/boards/nrf51_blenano.conf b/samples/bluetooth/hci_uart/boards/nrf51_blenano.conf index ba200902b2b..ca09bb80723 100644 --- a/samples/bluetooth/hci_uart/boards/nrf51_blenano.conf +++ b/samples/bluetooth/hci_uart/boards/nrf51_blenano.conf @@ -2,5 +2,7 @@ CONFIG_MAIN_STACK_SIZE=512 CONFIG_BT_MAX_CONN=10 CONFIG_IDLE_STACK_SIZE=256 CONFIG_ISR_STACK_SIZE=512 -CONFIG_BT_RX_BUF_LEN=76 -CONFIG_BT_DISCARDABLE_BUF_SIZE=45 +# Revert values set in prj.conf, set them to their Kconfig default value +CONFIG_BT_BUF_CMD_TX_SIZE=65 +CONFIG_BT_BUF_ACL_RX_SIZE=69 +CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=43 diff --git a/samples/bluetooth/hci_uart/prj.conf b/samples/bluetooth/hci_uart/prj.conf index e5cb75ac991..0bdcc2cf885 100644 --- a/samples/bluetooth/hci_uart/prj.conf +++ b/samples/bluetooth/hci_uart/prj.conf @@ -8,8 +8,9 @@ CONFIG_BT=y CONFIG_BT_HCI_RAW=y CONFIG_BT_HCI_RAW_H4=y CONFIG_BT_HCI_RAW_H4_ENABLE=y -CONFIG_BT_RX_BUF_LEN=258 -CONFIG_BT_DISCARDABLE_BUF_SIZE=257 +CONFIG_BT_BUF_ACL_RX_SIZE=255 +CONFIG_BT_BUF_CMD_TX_SIZE=255 +CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=255 CONFIG_BT_CTLR_ASSERT_HANDLER=y CONFIG_BT_MAX_CONN=16 CONFIG_BT_TINYCRYPT_ECC=n diff --git a/samples/bluetooth/mesh/microbit_gatt.conf b/samples/bluetooth/mesh/microbit_gatt.conf index 96c6ba97e77..c62c5d53e76 100644 --- a/samples/bluetooth/mesh/microbit_gatt.conf +++ b/samples/bluetooth/mesh/microbit_gatt.conf @@ -15,8 +15,6 @@ CONFIG_BT=y CONFIG_BT_DEVICE_NAME="Zephyr Mesh" CONFIG_BT_TINYCRYPT_ECC=y CONFIG_BT_RX_STACK_SIZE=1400 -CONFIG_BT_L2CAP_RX_MTU=69 -CONFIG_BT_L2CAP_TX_MTU=69 CONFIG_BT_L2CAP_TX_BUF_COUNT=5 CONFIG_BT_CTLR_DUP_FILTER_LEN=0 diff --git a/samples/bluetooth/mesh/prj.conf b/samples/bluetooth/mesh/prj.conf index 78e5a30eb4c..968d00ba4d1 100644 --- a/samples/bluetooth/mesh/prj.conf +++ b/samples/bluetooth/mesh/prj.conf @@ -20,8 +20,6 @@ CONFIG_BT_PERIPHERAL=y CONFIG_BT=y CONFIG_BT_TINYCRYPT_ECC=y -CONFIG_BT_L2CAP_RX_MTU=69 -CONFIG_BT_L2CAP_TX_MTU=69 CONFIG_BT_L2CAP_TX_BUF_COUNT=5 CONFIG_BT_MESH=y diff --git a/samples/bluetooth/mesh/prj_bbc_microbit.conf b/samples/bluetooth/mesh/prj_bbc_microbit.conf index 34a3cf7ae59..4679c511c33 100644 --- a/samples/bluetooth/mesh/prj_bbc_microbit.conf +++ b/samples/bluetooth/mesh/prj_bbc_microbit.conf @@ -19,8 +19,9 @@ CONFIG_SETTINGS=y CONFIG_BT=y CONFIG_BT_TINYCRYPT_ECC=y CONFIG_BT_RX_STACK_SIZE=1100 -CONFIG_BT_RX_BUF_COUNT=3 -CONFIG_BT_DISCARDABLE_BUF_COUNT=3 +CONFIG_BT_BUF_EVT_RX_COUNT=3 +CONFIG_BT_BUF_ACL_RX_COUNT=3 +CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT=3 CONFIG_BT_CTLR_DUP_FILTER_LEN=0 CONFIG_BT_OBSERVER=y diff --git a/samples/boards/nrf/mesh/onoff-app/prj.conf b/samples/boards/nrf/mesh/onoff-app/prj.conf index 828e22444a3..4fce259d392 100644 --- a/samples/boards/nrf/mesh/onoff-app/prj.conf +++ b/samples/boards/nrf/mesh/onoff-app/prj.conf @@ -30,8 +30,6 @@ CONFIG_BT_PERIPHERAL=y CONFIG_BT=y CONFIG_BT_TINYCRYPT_ECC=y -CONFIG_BT_L2CAP_RX_MTU=69 -CONFIG_BT_L2CAP_TX_MTU=69 CONFIG_BT_L2CAP_TX_BUF_COUNT=8 CONFIG_BT_MESH=y @@ -95,8 +93,8 @@ CONFIG_BT_RX_STACK_SIZE=4096 CONFIG_BT_MAX_CONN=1 CONFIG_BT_CTLR_RX_BUFFERS=6 -CONFIG_BT_CTLR_TX_BUFFERS=4 -CONFIG_BT_HCI_CMD_COUNT=4 +CONFIG_BT_BUF_ACL_TX_COUNT=4 +CONFIG_BT_BUF_CMD_TX_COUNT=4 CONFIG_BT_ATT_PREPARE_COUNT=2 diff --git a/samples/boards/nrf/mesh/onoff_level_lighting_vnd_app/prj.conf b/samples/boards/nrf/mesh/onoff_level_lighting_vnd_app/prj.conf index 81f647e11a3..f94fc0a528b 100644 --- a/samples/boards/nrf/mesh/onoff_level_lighting_vnd_app/prj.conf +++ b/samples/boards/nrf/mesh/onoff_level_lighting_vnd_app/prj.conf @@ -26,8 +26,6 @@ CONFIG_BT_PERIPHERAL=y CONFIG_BT=y CONFIG_BT_TINYCRYPT_ECC=y CONFIG_BT_RX_STACK_SIZE=4096 -CONFIG_BT_L2CAP_RX_MTU=69 -CONFIG_BT_L2CAP_TX_MTU=69 CONFIG_BT_L2CAP_TX_BUF_COUNT=8 CONFIG_BT_MESH=y @@ -81,7 +79,6 @@ CONFIG_BT_MESH_LABEL_COUNT=3 CONFIG_GPIO=y CONFIG_BT_CTLR_ADVANCED_FEATURES=y -CONFIG_BT_RX_BUF_COUNT=5 CONFIG_BT_HCI_TX_STACK_SIZE=1024 #CONFIG_BT_DEBUG_HCI_CORE=y #CONFIG_BT_DEBUG_HCI_DRIVER=y diff --git a/samples/boards/nrf/mesh/onoff_level_lighting_vnd_app/prj_smp_svr.conf b/samples/boards/nrf/mesh/onoff_level_lighting_vnd_app/prj_smp_svr.conf index 42eeb4fce89..1e4ada2163c 100644 --- a/samples/boards/nrf/mesh/onoff_level_lighting_vnd_app/prj_smp_svr.conf +++ b/samples/boards/nrf/mesh/onoff_level_lighting_vnd_app/prj_smp_svr.conf @@ -6,8 +6,7 @@ CONFIG_BOOTLOADER_MCUBOOT=y # Allow for large Bluetooth data packets. CONFIG_BT_L2CAP_TX_MTU=252 -CONFIG_BT_L2CAP_RX_MTU=252 -CONFIG_BT_RX_BUF_LEN=260 +CONFIG_BT_BUF_ACL_RX_SIZE=256 # Enable the Bluetooth (unauthenticated) and shell mcumgr transports. CONFIG_MCUMGR_SMP_BT=y diff --git a/samples/boards/reel_board/mesh_badge/prj.conf b/samples/boards/reel_board/mesh_badge/prj.conf index d3d6a91e83a..e8ded16f6b4 100644 --- a/samples/boards/reel_board/mesh_badge/prj.conf +++ b/samples/boards/reel_board/mesh_badge/prj.conf @@ -19,8 +19,6 @@ CONFIG_BT_MESH_DEBUG=y CONFIG_BT_OBSERVER=y CONFIG_BT_BROADCASTER=y -CONFIG_BT_L2CAP_RX_MTU=69 -CONFIG_BT_L2CAP_TX_MTU=69 CONFIG_BT_L2CAP_TX_BUF_COUNT=8 CONFIG_BT_MESH=y diff --git a/samples/net/lwm2m_client/overlay-bt.conf b/samples/net/lwm2m_client/overlay-bt.conf index 3c6f2bfb549..746c3912f8c 100644 --- a/samples/net/lwm2m_client/overlay-bt.conf +++ b/samples/net/lwm2m_client/overlay-bt.conf @@ -9,6 +9,5 @@ CONFIG_NET_L2_BT=y CONFIG_NET_CONFIG_BT_NODE=y # raise bluetooth RX buffer settings for 6lowpan traffic -CONFIG_BT_RX_BUF_COUNT=20 -CONFIG_BT_RX_BUF_LEN=128 -CONFIG_BT_L2CAP_RX_MTU=120 +CONFIG_BT_BUF_ACL_RX_COUNT=20 +CONFIG_BT_BUF_ACL_RX_SIZE=124 diff --git a/samples/subsys/mgmt/mcumgr/smp_svr/overlay-bt-tiny.conf b/samples/subsys/mgmt/mcumgr/smp_svr/overlay-bt-tiny.conf index df5794c7a30..375bf18c90c 100644 --- a/samples/subsys/mgmt/mcumgr/smp_svr/overlay-bt-tiny.conf +++ b/samples/subsys/mgmt/mcumgr/smp_svr/overlay-bt-tiny.conf @@ -4,8 +4,7 @@ # Allow for large Bluetooth data packets. CONFIG_BT_L2CAP_TX_MTU=252 -CONFIG_BT_L2CAP_RX_MTU=252 -CONFIG_BT_RX_BUF_LEN=260 +CONFIG_BT_BUF_ACL_RX_SIZE=256 # Enable the Bluetooth (unauthenticated) and UART mcumgr transports. CONFIG_MCUMGR_SMP_BT=y diff --git a/samples/subsys/mgmt/mcumgr/smp_svr/overlay-bt.conf b/samples/subsys/mgmt/mcumgr/smp_svr/overlay-bt.conf index 99019b5ea56..401f06fe163 100644 --- a/samples/subsys/mgmt/mcumgr/smp_svr/overlay-bt.conf +++ b/samples/subsys/mgmt/mcumgr/smp_svr/overlay-bt.conf @@ -1,7 +1,6 @@ # Allow for large Bluetooth data packets. CONFIG_BT_L2CAP_TX_MTU=252 -CONFIG_BT_L2CAP_RX_MTU=252 -CONFIG_BT_RX_BUF_LEN=260 +CONFIG_BT_BUF_ACL_RX_SIZE=256 # Enable the Bluetooth (unauthenticated) and shell mcumgr transports. CONFIG_MCUMGR_SMP_BT=y diff --git a/subsys/bluetooth/audio/aics_client.c b/subsys/bluetooth/audio/aics_client.c index 3cfe4114064..733b9474538 100644 --- a/subsys/bluetooth/audio/aics_client.c +++ b/subsys/bluetooth/audio/aics_client.c @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -86,7 +87,7 @@ uint8_t aics_client_notify_handler(struct bt_conn *conn, struct bt_gatt_subscrib } } } else if (handle == inst->cli.desc_handle) { - char desc[MIN(CONFIG_BT_L2CAP_RX_MTU, BT_ATT_MAX_ATTRIBUTE_LEN) + 1]; + char desc[MIN(BT_L2CAP_RX_MTU, BT_ATT_MAX_ATTRIBUTE_LEN) + 1]; /* Truncate if too large */ if (length > sizeof(desc) - 1) { @@ -464,7 +465,7 @@ static uint8_t aics_client_read_desc_cb(struct bt_conn *conn, uint8_t err, const void *data, uint16_t length) { int cb_err = err; - char desc[MIN(CONFIG_BT_L2CAP_RX_MTU, BT_ATT_MAX_ATTRIBUTE_LEN) + 1]; + char desc[MIN(BT_L2CAP_RX_MTU, BT_ATT_MAX_ATTRIBUTE_LEN) + 1]; struct bt_aics *inst = lookup_aics_by_handle(conn, params->single.handle); memset(params, 0, sizeof(*params)); diff --git a/subsys/bluetooth/audio/vocs_client.c b/subsys/bluetooth/audio/vocs_client.c index c787a6bcab8..954f24fcdaa 100644 --- a/subsys/bluetooth/audio/vocs_client.c +++ b/subsys/bluetooth/audio/vocs_client.c @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -71,7 +72,7 @@ uint8_t vocs_client_notify_handler(struct bt_conn *conn, struct bt_gatt_subscrib BT_DBG("Invalid state length %u", length); } } else if (handle == inst->cli.desc_handle) { - char desc[MIN(CONFIG_BT_L2CAP_RX_MTU, BT_ATT_MAX_ATTRIBUTE_LEN) + 1]; + char desc[MIN(BT_L2CAP_RX_MTU, BT_ATT_MAX_ATTRIBUTE_LEN) + 1]; /* Truncate if too large */ @@ -289,7 +290,7 @@ static uint8_t vcs_client_read_output_desc_cb(struct bt_conn *conn, uint8_t err, { int cb_err = err; struct bt_vocs *inst = lookup_vocs_by_handle(conn, params->single.handle); - char desc[MIN(CONFIG_BT_L2CAP_RX_MTU, BT_ATT_MAX_ATTRIBUTE_LEN) + 1]; + char desc[MIN(BT_L2CAP_RX_MTU, BT_ATT_MAX_ATTRIBUTE_LEN) + 1]; memset(params, 0, sizeof(*params)); diff --git a/subsys/bluetooth/common/Kconfig b/subsys/bluetooth/common/Kconfig index 2b51293047a..c09cc593b5c 100644 --- a/subsys/bluetooth/common/Kconfig +++ b/subsys/bluetooth/common/Kconfig @@ -4,6 +4,187 @@ # Copyright (c) 2016 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +config BT_BUF_ACL_TX_SIZE + int "Maximum supported ACL size for outgoing data" + range 27 251 + default 27 + help + Maximum supported ACL size of data packets sent from the Host to the + Controller. This value does not include the HCI ACL header. + The Host will segment the data transmitted to the Controller so that + packets sent to the Controller will contain data up to this size. + In a combined build this value will be set in both the Host and the + Controller. + In a Host-only build the Host will read the maximum ACL size supported + by the Controller and use the smallest value supported by both the + Bost and the Controller. + The Host supports sending of larger L2CAP PDUs than the ACL size and + will fragment L2CAP PDUs into ACL data packets. + The Controller will return this value in the HCI LE Read Buffer + Size command response. If this size if greater than effective Link + Layer transmission size then the Controller will perform + fragmentation before transmitting the packet(s) on air. + If this value is less than the effective Link Layer transmission size + then this will restrict the maximum Link Layer transmission size. + Maximum is set to 251 due to implementation limitations (use of + uint8_t for length field in PDU buffer structure). + +config BT_BUF_ACL_TX_COUNT + int "Number of outgoing ACL data buffers" + default 7 if BT_HCI_RAW + default 3 + range 1 255 + help + Number of outgoing ACL data buffers sent from the Host to the + Controller. This determines the maximum amount of data packets the + Host can have queued in the Controller before waiting for the + to notify the Host that more packets can be queued with the Number of + Completed Packets event. + The buffers are shared between all of the connections and the Host + determines how to divide the buffers between the connections. + The Controller will return this value in the HCI LE Read Buffer Size + command response. + +config BT_BUF_ACL_RX_SIZE + int "Maximum supported ACL size for incoming data" + default 200 if BT_BREDR + # Mesh Proxy Recommended: 64 Pkey + 2 Bytes Mesh header. + # Overhead: ATT Write command Header (3) in an L2CAP PDU (4). + default 73 if BT_MESH_PROXY + default 70 if BT_EATT + default 69 if BT_SMP + default 27 + range 70 1300 if BT_EATT + range 69 1300 if BT_SMP + range 27 1300 + help + Maximum support ACL size of data packets sent from the Controller to + the Host. This value does not include the HCI ACL header. + In a combined Host and Controller build the buffer sizes in both the + Host and the Controller will use this value for buffer sizes, and + therefore Controller to Host flow Controller is not needed. + In a Host only build with Controller to Host flow control enabled + the Host will inform the Controller about the maximum ACL data size it + can send by setting this value in the Host Buffer Size command. + If Controller to Host flow control is not enabled then the Controller + can assume the Host has infinite buffer size so this value should then + be set to something that is guaranteed the Controller will not exceed + or the data packets will be dropped. + In a Controller only build this will determine the maximum ACL size + that the Controller will send to the Host. + The Host supports reassembling of L2CAP PDUs from ACL data packets, + but the maximum supported L2CAP PDU size is limited by the maximum + supported ACL size. + This means the maximum L2CAP PDU MTU is restricted by the maximum ACL + size subtracting the 4 byte header of an L2CAP PDU. + When using L2CAP Connection oriented Channels without segmentation + then the L2CAP SDU MTU is also restricetd by the maximum ACL size + subtracting the 4 Byte header of an L2CAP PDU plus the 2 byte header + of an L2CAP SDU. + + With Enhanced ATT enabled the minimum of 70 is needed to support the + minimum ATT_MTU of 64 octets in an L2CAP SDU without segmentation. + With SMP LE Secure Connections enabled the minimum of 69 is needed to + support the minimum SMP MTU of 65 octets (public key + opcode) in an + L2CAP PDU. + + An L2CAP PDU is also referred to as an L2CAP basic frame or B-frame. + An L2CAP SDU is also referred to as an L2CAP Credit-based frame or + K-frame. + +config BT_BUF_ACL_RX_COUNT + int "Number of incoming ACL data buffers" + default NET_BUF_RX_COUNT if NET_L2_BT + default 3 if BT_RECV_IS_RX_THREAD + default 6 + range 1 64 + help + Number or incoming ACL data buffers sent from the Controller to the + Host. + In a combined Host and Controller build the buffers are shared and + therefore Controller to Host flow control is not needed. + In a Host only build with Controller to Host flow control enabled + the Host will inform the Controller about the maximum number of + buffers by setting this value in the Host Buffer Size command. + When Controller to Host flow control is not enabled the Controller + can assume that the Host has infinite amount of buffers. + +config BT_BUF_EVT_RX_SIZE + int "Maximum supported HCI Event buffer length" + default 255 if (BT_EXT_ADV && !(BT_BUF_EVT_DISCARDABLE_COUNT > 0)) + # LE Read Supported Commands command complete event. + default 68 + range 68 255 + help + Maximum supported HCI event buffer size. This value does not include + the HCI Event header. + This value is used by both the Host and the Controller for buffer + sizes that include HCI events. It should be set according to the + expected HCI events that can be generated from the configuration. + If the subset of possible HCI events is unknown, this should be set to + the maximum of 255. + +config BT_BUF_EVT_RX_COUNT + int "Number of HCI Event buffers" + default 3 if BT_RECV_IS_RX_THREAD + default 20 if (BT_MESH && !(BT_BUF_EVT_DISCARDABLE_COUNT > 0)) + default 10 + range 2 255 + help + Number of buffers available for incoming HCI events from the + Controller. + +config BT_BUF_EVT_DISCARDABLE_SIZE + int "Maximum supported discardable HCI Event buffer length" + range 43 255 + # LE Extended Advertising Report event + default 255 if BT_BREDR || BT_EXT_ADV + # Le Advertising Report event + default 43 + help + Maximum support discardable HCI event size of buffers in the separate + discardable event buffer pool. This value does not include the + HCI Event header. + The minimum size is set based on the Advertising Report. Setting + the buffer size different than BT_BUF_EVT_RX_SIZE can save memory. + +config BT_BUF_EVT_DISCARDABLE_COUNT + int "Number of discardable HCI Event buffers" + range 1 255 + default 20 if BT_MESH + default 3 + depends on !BT_HCI_RAW + help + Number of buffers in a separate buffer pool for events which + the HCI driver considers discardable. Examples of such events + could be e.g. Advertising Reports. The benefit of having such + a pool is that the if there is a heavy inflow of such events + it will not cause the allocation for other critical events to + block and may even eliminate deadlocks in some cases. + +config BT_BUF_CMD_TX_SIZE + int "Maximum support HCI Command buffer length" + # LE Set Extended Advertising Data command + default 255 if (BT_EXT_ADV || BT_BREDR) + # LE Generate DHKey v2 command + default 65 + range 65 255 + help + Maximum data size for each HCI Command buffer. This value does not + include the HCI Command header. + This value is used by both the Host and the Controller for buffer + sizes that include HCI commands. It should be set according to the + expected HCI commands that can be sent from the configuration. + If the subset of possible HCI commands is unknown, this should be set + to the maximum of 255. + +config BT_BUF_CMD_TX_COUNT + int "Number of HCI command buffers" + default 2 + range 2 64 + help + Number of buffers available for outgoing HCI commands from the Host. + config BT_HAS_HCI_VS bool help diff --git a/subsys/bluetooth/controller/Kconfig b/subsys/bluetooth/controller/Kconfig index 9f208eb4b00..a8a86f85b0f 100644 --- a/subsys/bluetooth/controller/Kconfig +++ b/subsys/bluetooth/controller/Kconfig @@ -172,29 +172,6 @@ config BT_CTLR_RX_BUFFERS connection interval and 2M PHY, maximum 18 packets with L2CAP payload size of 1 byte can be received. -config BT_CTLR_TX_BUFFERS - int "Number of Tx buffers" - default 7 if BT_HCI_RAW - default 3 - range 1 19 - help - Set the number of Tx PDUs to be queued for transmission in the - controller. In a 7.5ms connection interval and 2M PHY, maximum 19 - packets can be enqueued, with 18 packets with L2CAP payload size of 1 - byte can be acknowledged. - -config BT_CTLR_TX_BUFFER_SIZE - int "Tx buffer size" - range 27 251 - default 27 - help - Size of the Tx buffers and the value returned in HCI LE Read Buffer - Size command response. If this size if greater than effective PDU size - then controller will perform fragmentation before transmitting on the - the packet on air. - Maximum is set to 251 due to implementation limitations (use of - uint8_t for length field in PDU buffer structure). - config BT_CTLR_ISO_TX_BUFFERS int "Number of Isochronous Tx buffers" default 3 @@ -345,6 +322,7 @@ config BT_CTLR_DATA_LENGTH_MAX int "Maximum data length supported" depends on BT_CTLR_DATA_LENGTH default 27 + range 27 BT_BUF_ACL_RX_SIZE if BT_BUF_ACL_RX_SIZE < 251 range 27 251 help Set the maximum data length of PDU supported in the Controller. diff --git a/subsys/bluetooth/controller/hci/hci.c b/subsys/bluetooth/controller/hci/hci.c index b7392c70700..8ab84015fa5 100644 --- a/subsys/bluetooth/controller/hci/hci.c +++ b/subsys/bluetooth/controller/hci/hci.c @@ -124,6 +124,11 @@ static uint32_t conn_count; static uint32_t cis_pending_count; #endif +#if !defined(CONFIG_BT_HCI_RAW) && defined(CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT) +#define ADV_REPORT_EVT_MAX_LEN CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE +#else +#define ADV_REPORT_EVT_MAX_LEN CONFIG_BT_BUF_EVT_RX_SIZE +#endif #define DEFAULT_EVENT_MASK 0x1fffffffffff #define DEFAULT_EVENT_MASK_PAGE_2 0x0 @@ -1152,8 +1157,8 @@ static void le_read_buffer_size(struct net_buf *buf, struct net_buf **evt) rp->status = 0x00; - rp->le_max_len = sys_cpu_to_le16(CONFIG_BT_CTLR_TX_BUFFER_SIZE); - rp->le_max_num = CONFIG_BT_CTLR_TX_BUFFERS; + rp->le_max_len = sys_cpu_to_le16(CONFIG_BT_BUF_ACL_TX_SIZE); + rp->le_max_num = CONFIG_BT_BUF_ACL_TX_COUNT; } static void le_read_local_features(struct net_buf *buf, struct net_buf **evt) @@ -3770,7 +3775,7 @@ static void vs_read_build_info(struct net_buf *buf, struct net_buf **evt) sizeof(struct bt_hci_rp_vs_read_build_info) + \ sizeof(build_info)) - BUILD_ASSERT(CONFIG_BT_RX_BUF_LEN >= BUILD_INFO_EVT_LEN); + BUILD_ASSERT(CONFIG_BT_BUF_EVT_RX_SIZE >= BUILD_INFO_EVT_LEN); rp = hci_cmd_complete(evt, sizeof(*rp) + sizeof(build_info)); rp->status = 0x00; @@ -4165,7 +4170,7 @@ int hci_acl_handle(struct net_buf *buf, struct net_buf **evt) return -EINVAL; } - if (len > CONFIG_BT_CTLR_TX_BUFFER_SIZE) { + if (len > CONFIG_BT_BUF_ACL_TX_SIZE) { BT_ERR("Invalid HCI ACL Data length"); return -EINVAL; } @@ -4932,8 +4937,7 @@ no_ext_hdr: if (!data_status) { uint8_t data_max_len; - data_max_len = CONFIG_BT_DISCARDABLE_BUF_SIZE - - BT_HCI_ACL_HDR_SIZE - sizeof(*sep) - + data_max_len = ADV_REPORT_EVT_MAX_LEN - sizeof(*sep) - sizeof(*adv_info); /* if data cannot fit the event, mark it as incomplete */ @@ -5268,8 +5272,7 @@ no_ext_hdr: if (!data_status) { uint8_t data_max_len; - data_max_len = CONFIG_BT_DISCARDABLE_BUF_SIZE - - BT_HCI_ACL_HDR_SIZE - sizeof(*sep); + data_max_len = ADV_REPORT_EVT_MAX_LEN - sizeof(*sep); /* if data cannot fit the event, mark it as incomplete */ if (data_len > data_max_len) { diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c index fdbbb235cb1..5ed9a0a4bb8 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c @@ -78,7 +78,7 @@ static uint8_t force_md_cnt; #define FORCE_MD_CNT_SET() \ do { \ if (force_md_cnt || \ - (trx_cnt >= ((CONFIG_BT_CTLR_TX_BUFFERS) - 1))) { \ + (trx_cnt >= ((CONFIG_BT_BUF_ACL_TX_COUNT) - 1))) { \ force_md_cnt = BT_CTLR_FORCE_MD_COUNT; \ } \ } while (0) diff --git a/subsys/bluetooth/controller/ll_sw/ull.c b/subsys/bluetooth/controller/ll_sw/ull.c index fcf84dc1a19..904e6793ffa 100644 --- a/subsys/bluetooth/controller/ll_sw/ull.c +++ b/subsys/bluetooth/controller/ll_sw/ull.c @@ -388,7 +388,7 @@ static MEMQ_DECLARE(ull_done); #if defined(CONFIG_BT_CONN) static MFIFO_DEFINE(ll_pdu_rx_free, sizeof(void *), LL_PDU_RX_CNT); static MFIFO_DEFINE(tx_ack, sizeof(struct lll_tx), - CONFIG_BT_CTLR_TX_BUFFERS); + CONFIG_BT_BUF_ACL_TX_COUNT); static void *mark_update; #endif /* CONFIG_BT_CONN */ diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn.c b/subsys/bluetooth/controller/ll_sw/ull_conn.c index 049f4dcc376..e0528089af5 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn.c @@ -152,7 +152,7 @@ static uint8_t force_md_cnt_calc(struct lll_conn *lll_conn, uint32_t tx_rate); #define CONN_TX_BUF_SIZE MROUND(offsetof(struct node_tx, pdu) + \ offsetof(struct pdu_data, lldata) + \ - (CONFIG_BT_CTLR_TX_BUFFER_SIZE + \ + (CONFIG_BT_BUF_ACL_TX_SIZE + \ BT_CTLR_USER_TX_BUFFER_OVERHEAD)) /** @@ -169,13 +169,13 @@ static uint8_t force_md_cnt_calc(struct lll_conn *lll_conn, uint32_t tx_rate); #define TERM_REQ 1 #define TERM_ACKED 3 -static MFIFO_DEFINE(conn_tx, sizeof(struct lll_tx), CONFIG_BT_CTLR_TX_BUFFERS); +static MFIFO_DEFINE(conn_tx, sizeof(struct lll_tx), CONFIG_BT_BUF_ACL_TX_COUNT); static MFIFO_DEFINE(conn_ack, sizeof(struct lll_tx), - (CONFIG_BT_CTLR_TX_BUFFERS + CONN_TX_CTRL_BUFFERS)); + (CONFIG_BT_BUF_ACL_TX_COUNT + CONN_TX_CTRL_BUFFERS)); static struct { void *free; - uint8_t pool[CONN_TX_BUF_SIZE * CONFIG_BT_CTLR_TX_BUFFERS]; + uint8_t pool[CONN_TX_BUF_SIZE * CONFIG_BT_BUF_ACL_TX_COUNT]; } mem_conn_tx; static struct { @@ -186,7 +186,7 @@ static struct { static struct { void *free; uint8_t pool[sizeof(memq_link_t) * - (CONFIG_BT_CTLR_TX_BUFFERS + CONN_TX_CTRL_BUFFERS)]; + (CONFIG_BT_BUF_ACL_TX_COUNT + CONN_TX_CTRL_BUFFERS)]; } mem_link_tx; #if defined(CONFIG_BT_CTLR_DATA_LENGTH) @@ -280,7 +280,7 @@ int ll_tx_mem_enqueue(uint16_t handle, void *tx) static struct mayfly mfy = {0, 0, &link, NULL, tx_demux}; #if defined(CONFIG_BT_CTLR_FORCE_MD_AUTO) - if (tx_cnt >= CONFIG_BT_CTLR_TX_BUFFERS) { + if (tx_cnt >= CONFIG_BT_BUF_ACL_TX_COUNT) { uint8_t previous, force_md_cnt; force_md_cnt = force_md_cnt_calc(&conn->lll, tx_rate); @@ -1761,7 +1761,7 @@ static int init_reset(void) sizeof(conn_pool) / sizeof(struct ll_conn), &conn_free); /* Initialize tx pool. */ - mem_init(mem_conn_tx.pool, CONN_TX_BUF_SIZE, CONFIG_BT_CTLR_TX_BUFFERS, + mem_init(mem_conn_tx.pool, CONN_TX_BUF_SIZE, CONFIG_BT_BUF_ACL_TX_COUNT, &mem_conn_tx.free); /* Initialize tx ctrl pool. */ @@ -1770,7 +1770,7 @@ static int init_reset(void) /* Initialize tx link pool. */ mem_init(mem_link_tx.pool, sizeof(memq_link_t), - CONFIG_BT_CTLR_TX_BUFFERS + CONN_TX_CTRL_BUFFERS, + CONFIG_BT_BUF_ACL_TX_COUNT + CONN_TX_CTRL_BUFFERS, &mem_link_tx.free); #if defined(CONFIG_BT_CTLR_DATA_LENGTH) diff --git a/subsys/bluetooth/host/Kconfig b/subsys/bluetooth/host/Kconfig index 51b6aa9c588..48a49398e75 100644 --- a/subsys/bluetooth/host/Kconfig +++ b/subsys/bluetooth/host/Kconfig @@ -13,63 +13,6 @@ config BT_HCI_HOST depends on !BT_HCI_RAW select POLL -config BT_HCI_CMD_COUNT - int "Number of HCI command buffers" - default 2 - range 2 64 - help - Number of buffers available for HCI commands. - -config BT_RX_BUF_COUNT - int "Number of HCI RX buffers" - default NET_BUF_RX_COUNT if NET_L2_BT - default 3 if BT_RECV_IS_RX_THREAD - default 20 if (BT_MESH && !(BT_DISCARDABLE_BUF_COUNT > 0)) - default 10 - range 2 255 - help - Number of buffers available for incoming ACL packets or HCI events - from the controller. - -config BT_RX_BUF_LEN - int "Maximum supported HCI RX buffer length" - default 264 if BT_BREDR - default 258 if BT_EXT_ADV - default 77 if BT_MESH_PROXY - default 76 - range 73 2000 - help - Maximum data size for each HCI RX buffer. This size includes - everything starting with the ACL or HCI event headers. Note that - buffer sizes are always rounded up to the nearest multiple of 4, - so if this Kconfig value is something else then there will be some - wasted space. The minimum of 73 has been taken for LE SC which has - an L2CAP MTU of 65 bytes. On top of this there's the L2CAP header - (4 bytes) and the ACL header (also 4 bytes) which yields 73 bytes. - -config BT_DISCARDABLE_BUF_COUNT - int "Number of discardable event buffers" - range 1 255 - default 20 if BT_MESH - default 3 - depends on !BT_HCI_RAW - help - Number of buffers in a separate buffer pool for events which - the HCI driver considers discardable. Examples of such events - could be e.g. Advertising Reports. The benefit of having such - a pool means that the if there is a heavy inflow of such events - it will not cause the allocation for other critical events to - block and may even eliminate deadlocks in some cases. - -config BT_DISCARDABLE_BUF_SIZE - int "Size of discardable event buffers" - range 45 257 - default 257 if BT_BREDR || BT_EXT_ADV - default 45 - help - Size of buffers in the separate discardable event buffer pool. - The minimum size is set based on the Advertising Report. Setting - the buffer size different than BT_RX_BUF_LEN can save memory. config BT_HCI_TX_STACK_SIZE # NOTE: This value is derived from other symbols and should only be @@ -127,16 +70,6 @@ config BT_HCI_RESERVE Headroom that the driver needs for sending and receiving buffers. Add a new 'default' entry for each new driver. -config BT_HCI_ACL_DATA_SIZE - int - prompt "ACL data buffer size" if !BT_CTLR - depends on BT_HCI_RAW - range 27 251 - default BT_CTLR_DATA_LENGTH_MAX if BT_CTLR_DATA_LENGTH - default 27 - help - Maximum ACL data payload in HCI packets, excluding HCI header. - config BT_RECV_IS_RX_THREAD # Hidden option set by the HCI driver to indicate that there's # no need for the host to have its own RX thread. @@ -259,16 +192,6 @@ config BT_WHITELIST if BT_CONN -config BT_ACL_RX_COUNT - int "Number of incoming ACL data buffers" - default BT_CTLR_RX_BUFFERS if BT_CTLR - default NET_BUF_RX_COUNT if NET_L2_BT - default 6 - range 1 64 - depends on BT_HCI_ACL_FLOW_CONTROL - help - Number of buffers available for incoming ACL data. - config BT_CONN_TX_MAX int "Maximum number of pending TX buffers with a callback" default BT_L2CAP_TX_BUF_COUNT @@ -830,11 +753,10 @@ config BT_RFCOMM config BT_RFCOMM_L2CAP_MTU int "L2CAP MTU for RFCOMM frames" - default BT_L2CAP_RX_MTU if BT_HCI_ACL_FLOW_CONTROL - default BT_RX_BUF_LEN depends on BT_RFCOMM - range BT_L2CAP_RX_MTU 32767 if BT_HCI_ACL_FLOW_CONTROL - range BT_RX_BUF_LEN 32767 + # RX MTU will be truncated to account for the L2CAP PDU header. + default BT_BUF_ACL_RX_SIZE + range 23 32767 help Maximum size of L2CAP PDU for RFCOMM frames. diff --git a/subsys/bluetooth/host/Kconfig.gatt b/subsys/bluetooth/host/Kconfig.gatt index 54a0f208792..2c218105035 100644 --- a/subsys/bluetooth/host/Kconfig.gatt +++ b/subsys/bluetooth/host/Kconfig.gatt @@ -42,18 +42,6 @@ config BT_EATT_MAX help Number of Enhanced ATT bearers available. -config BT_EATT_RX_MTU - int "Maximum supported Enhanced ATT MTU for incoming data" - default 70 - range 70 519 - depends on BT_EATT - help - Maximum size incoming PDUs on EATT bearers, value shall include L2CAP - headers and SDU length, maximum is limited to 512 bytes payload, which - is the maximum size for a GATT attribute, plus 1 byte for ATT opcode. - This option influences the stack buffer size and by that may also - limit the outgoing MTU. - config BT_EATT_SEC_LEVEL int "Enhanced ATT bearer security level" default 1 diff --git a/subsys/bluetooth/host/Kconfig.l2cap b/subsys/bluetooth/host/Kconfig.l2cap index bb84625225e..96f48d72b65 100644 --- a/subsys/bluetooth/host/Kconfig.l2cap +++ b/subsys/bluetooth/host/Kconfig.l2cap @@ -5,23 +5,10 @@ menu "L2CAP Options" -config BT_L2CAP_RX_MTU - int "Maximum supported L2CAP MTU for incoming data" - default 200 if BT_BREDR - default BT_EATT_RX_MTU if BT_EATT - default 65 if BT_SMP - default 23 - range 70 1300 if BT_EATT - range 65 1300 if BT_SMP - range 23 1300 - help - Maximum size of each incoming L2CAP PDU. - config BT_L2CAP_TX_BUF_COUNT int "Number of L2CAP TX buffers" default NET_BUF_TX_COUNT if NET_L2_BT - default BT_CTLR_TX_BUFFERS if BT_CTLR - default 3 + default BT_BUF_ACL_TX_COUNT range 2 255 help Number of buffers available for outgoing L2CAP packets. diff --git a/subsys/bluetooth/host/att_internal.h b/subsys/bluetooth/host/att_internal.h index c44e6b7e67a..e794351be3d 100644 --- a/subsys/bluetooth/host/att_internal.h +++ b/subsys/bluetooth/host/att_internal.h @@ -11,11 +11,7 @@ #define BT_ATT_TIMEOUT K_SECONDS(30) /* ATT MTU must be equal for RX and TX, so select the smallest value */ -#if CONFIG_BT_L2CAP_RX_MTU < CONFIG_BT_L2CAP_TX_MTU -#define BT_ATT_MTU CONFIG_BT_L2CAP_RX_MTU -#else -#define BT_ATT_MTU CONFIG_BT_L2CAP_TX_MTU -#endif +#define BT_ATT_MTU (MIN(BT_L2CAP_RX_MTU, BT_L2CAP_TX_MTU)) struct bt_att_hdr { uint8_t code; diff --git a/subsys/bluetooth/host/avdtp_internal.h b/subsys/bluetooth/host/avdtp_internal.h index 1212d488ded..accab9769cf 100644 --- a/subsys/bluetooth/host/avdtp_internal.h +++ b/subsys/bluetooth/host/avdtp_internal.h @@ -82,7 +82,7 @@ #define BT_AVDTP_ERR_UNSUPPORTED_CONFIGURAION 0x29 #define BT_AVDTP_ERR_BAD_STATE 0x31 -#define BT_AVDTP_MAX_MTU CONFIG_BT_L2CAP_RX_MTU +#define BT_AVDTP_MAX_MTU BT_L2CAP_RX_MTU #define BT_AVDTP_MIN_SEID 0x01 #define BT_AVDTP_MAX_SEID 0x3E diff --git a/subsys/bluetooth/host/buf.c b/subsys/bluetooth/host/buf.c index dd57859a81c..394f0a29c54 100644 --- a/subsys/bluetooth/host/buf.c +++ b/subsys/bluetooth/host/buf.c @@ -16,9 +16,6 @@ #define LOG_MODULE_NAME bt_buf #include "common/log.h" -NET_BUF_POOL_FIXED_DEFINE(hci_rx_pool, CONFIG_BT_RX_BUF_COUNT, - BT_BUF_RX_SIZE, NULL); - #if defined(CONFIG_BT_CONN) #define NUM_COMLETE_EVENT_SIZE BT_BUF_EVT_SIZE( \ sizeof(struct bt_hci_cp_host_num_completed_packets) + \ @@ -31,16 +28,25 @@ NET_BUF_POOL_FIXED_DEFINE(hci_rx_pool, CONFIG_BT_RX_BUF_COUNT, NET_BUF_POOL_FIXED_DEFINE(num_complete_pool, 1, NUM_COMLETE_EVENT_SIZE, NULL); #endif /* CONFIG_BT_CONN */ -#if defined(CONFIG_BT_DISCARDABLE_BUF_COUNT) -#define DISCARDABLE_EVENT_SIZE BT_BUF_SIZE(CONFIG_BT_DISCARDABLE_BUF_SIZE) -NET_BUF_POOL_FIXED_DEFINE(discardable_pool, CONFIG_BT_DISCARDABLE_BUF_COUNT, - DISCARDABLE_EVENT_SIZE, NULL); -#endif /* CONFIG_BT_DISCARDABLE_BUF_COUNT */ +#if defined(CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT) +NET_BUF_POOL_FIXED_DEFINE(discardable_pool, CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT, + BT_BUF_EVT_SIZE(CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE), + NULL); +#endif /* CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT */ #if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL) -#define ACL_IN_SIZE BT_L2CAP_BUF_SIZE(CONFIG_BT_L2CAP_RX_MTU) -NET_BUF_POOL_DEFINE(acl_in_pool, CONFIG_BT_ACL_RX_COUNT, ACL_IN_SIZE, +NET_BUF_POOL_DEFINE(acl_in_pool, CONFIG_BT_BUF_ACL_RX_COUNT, + BT_BUF_ACL_SIZE(CONFIG_BT_BUF_ACL_RX_SIZE), sizeof(struct acl_data), bt_hci_host_num_completed_packets); + +NET_BUF_POOL_FIXED_DEFINE(evt_pool, CONFIG_BT_BUF_EVT_RX_COUNT, + BT_BUF_EVT_RX_SIZE, + NULL); +#else +#define BT_BUF_RX_COUNT MAX(CONFIG_BT_BUF_EVT_RX_COUNT, CONFIG_BT_BUF_ACL_RX_COUNT) +NET_BUF_POOL_FIXED_DEFINE(hci_rx_pool, BT_BUF_RX_COUNT, + BT_BUF_RX_SIZE, + NULL); #endif /* CONFIG_BT_HCI_ACL_FLOW_CONTROL */ struct net_buf *bt_buf_get_rx(enum bt_buf_type type, k_timeout_t timeout) @@ -56,7 +62,7 @@ struct net_buf *bt_buf_get_rx(enum bt_buf_type type, k_timeout_t timeout) #if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL) if (type == BT_BUF_EVT) { - buf = net_buf_alloc(&hci_rx_pool, timeout); + buf = net_buf_alloc(&evt_pool, timeout); } else { buf = net_buf_alloc(&acl_in_pool, timeout); } @@ -117,7 +123,7 @@ struct net_buf *bt_buf_get_evt(uint8_t evt, bool discardable, case BT_HCI_EVT_CMD_STATUS: return bt_buf_get_cmd_complete(timeout); default: -#if defined(CONFIG_BT_DISCARDABLE_BUF_COUNT) +#if defined(CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT) if (discardable) { struct net_buf *buf; @@ -129,7 +135,7 @@ struct net_buf *bt_buf_get_evt(uint8_t evt, bool discardable, return buf; } -#endif /* CONFIG_BT_DISCARDABLE_BUF_COUNT */ +#endif /* CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT */ return bt_buf_get_rx(BT_BUF_EVT, timeout); } diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index 6f7ca4960ed..a3bcff4af0e 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -53,21 +53,14 @@ NET_BUF_POOL_DEFINE(acl_tx_pool, CONFIG_BT_L2CAP_TX_BUF_COUNT, sizeof(struct tx_meta), NULL); #if CONFIG_BT_L2CAP_TX_FRAG_COUNT > 0 - -#if defined(CONFIG_BT_CTLR_TX_BUFFER_SIZE) -#define FRAG_SIZE BT_L2CAP_BUF_SIZE(CONFIG_BT_CTLR_TX_BUFFER_SIZE - 4) -#else -#define FRAG_SIZE BT_L2CAP_BUF_SIZE(CONFIG_BT_L2CAP_TX_MTU) -#endif - /* Dedicated pool for fragment buffers in case queued up TX buffers don't * fit the controllers buffer size. We can't use the acl_tx_pool for the * fragmentation, since it's possible that pool is empty and all buffers * are queued up in the TX queue. In such a situation, trying to allocate * another buffer from the acl_tx_pool would result in a deadlock. */ -NET_BUF_POOL_FIXED_DEFINE(frag_pool, CONFIG_BT_L2CAP_TX_FRAG_COUNT, FRAG_SIZE, - NULL); +NET_BUF_POOL_FIXED_DEFINE(frag_pool, CONFIG_BT_L2CAP_TX_FRAG_COUNT, + BT_BUF_ACL_SIZE(CONFIG_BT_BUF_ACL_TX_SIZE), NULL); #endif /* CONFIG_BT_L2CAP_TX_FRAG_COUNT > 0 */ diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 24c132af26d..3d24743b5f5 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -112,7 +112,7 @@ struct cmd_data { struct k_sem *sync; }; -static struct cmd_data cmd_data[CONFIG_BT_HCI_CMD_COUNT]; +static struct cmd_data cmd_data[CONFIG_BT_BUF_CMD_TX_COUNT]; #define cmd(buf) (&cmd_data[net_buf_id(buf)]) #define acl(buf) ((struct acl_data *)net_buf_user_data(buf)) @@ -127,11 +127,12 @@ void bt_hci_cmd_state_set_init(struct net_buf *buf, cmd(buf)->state = state; } -/* HCI command buffers. Derive the needed size from BT_BUF_RX_SIZE since - * the same buffer is also used for the response. +/* HCI command buffers. Derive the needed size from both Command and Event + * buffer length since the buffer is also used for the response event i.e + * command complete or command status. */ -#define CMD_BUF_SIZE BT_BUF_RX_SIZE -NET_BUF_POOL_FIXED_DEFINE(hci_cmd_pool, CONFIG_BT_HCI_CMD_COUNT, +#define CMD_BUF_SIZE MAX(BT_BUF_EVT_RX_SIZE, BT_BUF_CMD_TX_SIZE) +NET_BUF_POOL_FIXED_DEFINE(hci_cmd_pool, CONFIG_BT_BUF_CMD_TX_COUNT, CMD_BUF_SIZE, NULL); struct event_handler { @@ -1534,9 +1535,8 @@ static int set_flow_control(void) hbs = net_buf_add(buf, sizeof(*hbs)); (void)memset(hbs, 0, sizeof(*hbs)); - hbs->acl_mtu = sys_cpu_to_le16(CONFIG_BT_L2CAP_RX_MTU + - sizeof(struct bt_l2cap_hdr)); - hbs->acl_pkts = sys_cpu_to_le16(CONFIG_BT_ACL_RX_COUNT); + hbs->acl_mtu = sys_cpu_to_le16(CONFIG_BT_BUF_ACL_RX_SIZE); + hbs->acl_pkts = sys_cpu_to_le16(CONFIG_BT_BUF_ACL_RX_COUNT); err = bt_hci_cmd_send_sync(BT_HCI_OP_HOST_BUFFER_SIZE, buf, NULL); if (err) { diff --git a/subsys/bluetooth/host/hci_raw.c b/subsys/bluetooth/host/hci_raw.c index 0be6db2638c..503c49e0ae4 100644 --- a/subsys/bluetooth/host/hci_raw.c +++ b/subsys/bluetooth/host/hci_raw.c @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -36,12 +37,13 @@ static uint8_t raw_mode = BT_HCI_RAW_MODE_H4; static uint8_t raw_mode; #endif -NET_BUF_POOL_FIXED_DEFINE(hci_rx_pool, CONFIG_BT_RX_BUF_COUNT, +#define BT_BUF_RX_COUNT MAX(CONFIG_BT_BUF_EVT_RX_COUNT, CONFIG_BT_BUF_ACL_RX_COUNT) +NET_BUF_POOL_FIXED_DEFINE(hci_rx_pool, BT_BUF_RX_COUNT, BT_BUF_RX_SIZE, NULL); -NET_BUF_POOL_FIXED_DEFINE(hci_cmd_pool, CONFIG_BT_HCI_CMD_COUNT, - BT_BUF_RX_SIZE, NULL); -NET_BUF_POOL_FIXED_DEFINE(hci_acl_pool, BT_HCI_ACL_COUNT, - BT_BUF_ACL_SIZE, NULL); +NET_BUF_POOL_FIXED_DEFINE(hci_cmd_pool, CONFIG_BT_BUF_CMD_TX_COUNT, + BT_BUF_CMD_SIZE(CONFIG_BT_BUF_CMD_TX_SIZE), NULL); +NET_BUF_POOL_FIXED_DEFINE(hci_acl_pool, CONFIG_BT_BUF_ACL_TX_COUNT, + BT_BUF_ACL_SIZE(CONFIG_BT_BUF_ACL_TX_SIZE), NULL); #if defined(CONFIG_BT_ISO) NET_BUF_POOL_FIXED_DEFINE(hci_iso_pool, CONFIG_BT_ISO_TX_BUF_COUNT, CONFIG_BT_ISO_TX_MTU, NULL); diff --git a/subsys/bluetooth/host/l2cap.c b/subsys/bluetooth/host/l2cap.c index 0c15b949c1b..f4abf65d2de 100644 --- a/subsys/bluetooth/host/l2cap.c +++ b/subsys/bluetooth/host/l2cap.c @@ -32,11 +32,7 @@ #define L2CAP_LE_MIN_MTU 23 #define L2CAP_ECRED_MIN_MTU 64 -#if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL) -#define L2CAP_LE_MAX_CREDITS (CONFIG_BT_ACL_RX_COUNT - 1) -#else -#define L2CAP_LE_MAX_CREDITS (CONFIG_BT_RX_BUF_COUNT - 1) -#endif +#define L2CAP_LE_MAX_CREDITS (CONFIG_BT_BUF_ACL_RX_COUNT - 1) #define L2CAP_LE_CID_DYN_START 0x0040 #define L2CAP_LE_CID_DYN_END 0x007f @@ -64,7 +60,8 @@ NET_BUF_POOL_FIXED_DEFINE(disc_pool, 1, sizeof(struct bt_l2cap_disconn_req)), NULL); -#define L2CAP_MAX_LE_MPS CONFIG_BT_L2CAP_RX_MTU +/* Maximum Packet Size (MPS) is defined as the MTU of an L2CAP Basic Frame. */ +#define L2CAP_MAX_LE_MPS BT_L2CAP_RX_MTU /* For now use MPS - SDU length to disable segmentation */ #define L2CAP_MAX_LE_MTU (L2CAP_MAX_LE_MPS - BT_L2CAP_SDU_HDR_SIZE) diff --git a/subsys/bluetooth/host/l2cap_br.c b/subsys/bluetooth/host/l2cap_br.c index 7151b0f0519..e3946c08c54 100644 --- a/subsys/bluetooth/host/l2cap_br.c +++ b/subsys/bluetooth/host/l2cap_br.c @@ -753,8 +753,7 @@ static void l2cap_br_conn_req(struct bt_l2cap_br *l2cap, uint8_t ident, atomic_set_bit(BR_CHAN(chan)->flags, L2CAP_FLAG_CONN_ACCEPTOR); /* Disable fragmentation of l2cap rx pdu */ - BR_CHAN(chan)->rx.mtu = MIN(BR_CHAN(chan)->rx.mtu, - CONFIG_BT_L2CAP_RX_MTU); + BR_CHAN(chan)->rx.mtu = MIN(BR_CHAN(chan)->rx.mtu, BT_L2CAP_RX_MTU); switch (l2cap_br_conn_security(chan, psm)) { case L2CAP_CONN_SECURITY_PENDING: diff --git a/subsys/bluetooth/host/rfcomm.c b/subsys/bluetooth/host/rfcomm.c index e16d6d4a3a9..2277778be84 100644 --- a/subsys/bluetooth/host/rfcomm.c +++ b/subsys/bluetooth/host/rfcomm.c @@ -37,12 +37,7 @@ #define RFCOMM_MIN_MTU BT_RFCOMM_SIG_MIN_MTU #define RFCOMM_DEFAULT_MTU 127 -#if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL) -#define RFCOMM_MAX_CREDITS (CONFIG_BT_ACL_RX_COUNT - 1) -#else -#define RFCOMM_MAX_CREDITS (CONFIG_BT_RX_BUF_COUNT - 1) -#endif - +#define RFCOMM_MAX_CREDITS (CONFIG_BT_BUF_ACL_RX_COUNT - 1) #define RFCOMM_CREDITS_THRESHOLD (RFCOMM_MAX_CREDITS / 2) #define RFCOMM_DEFAULT_CREDIT RFCOMM_MAX_CREDITS diff --git a/subsys/bluetooth/services/ots/Kconfig b/subsys/bluetooth/services/ots/Kconfig index 15a09d3bf5e..61ba70ea048 100644 --- a/subsys/bluetooth/services/ots/Kconfig +++ b/subsys/bluetooth/services/ots/Kconfig @@ -55,10 +55,9 @@ config BT_OTS_OLCP_GO_TO_SUPPORT config BT_OTS_L2CAP_CHAN_RX_MTU int "Size of RX MTU for Object Transfer Channel" - default BT_L2CAP_RX_MTU if BT_HCI_ACL_FLOW_CONTROL - default 23 - range 23 BT_L2CAP_RX_MTU if BT_HCI_ACL_FLOW_CONTROL - range 23 BT_RX_BUF_LEN + # RX MTU will be truncated to account for the L2CAP PDU and SDU header. + default BT_BUF_ACL_RX_SIZE + range 21 BT_BUF_ACL_RX_SIZE module = BT_OTS module-str = BT_OTS diff --git a/subsys/usb/Kconfig b/subsys/usb/Kconfig index 9c6d266519a..e80093b9264 100644 --- a/subsys/usb/Kconfig +++ b/subsys/usb/Kconfig @@ -64,12 +64,21 @@ config USB_MAX_NUM_TRANSFERS Allocates buffers used for parallel transfers. Increase this number according to USB devices count. +config USB_DEVICE_BLUETOOTH_BIG_BUF + bool + # Hidden option to simplify bluetooth buffer requirement + # TODO: Add BUF reserve in H4 mode and ISO? + default y if BT_BUF_ACL_RX_SIZE > 123 # 4 byte header + default y if BT_BUF_ACL_TX_SIZE > 123 # 4 byte header + default y if BT_BUF_EVT_RX_SIZE > 125 # 2 byte header + default y if BT_BUF_CMD_TX_SIZE > 124 # 3 byte header + config USB_REQUEST_BUFFER_SIZE int "Set buffer size for Standard, Class and Vendor request handlers" range 256 65536 if USB_DEVICE_NETWORK_RNDIS range 8 65536 default 256 if USB_DEVICE_NETWORK_RNDIS - default 266 if (BT_RX_BUF_LEN > 127 && USB_DEVICE_BLUETOOTH) + default 266 if (USB_DEVICE_BLUETOOTH && USB_DEVICE_BLUETOOTH_BIG_BUF) default 1024 if USB_DEVICE_LOOPBACK default 128 diff --git a/tests/bluetooth/bsim_bt/edtt_ble_test_app/gatt_test_app/prj.conf b/tests/bluetooth/bsim_bt/edtt_ble_test_app/gatt_test_app/prj.conf index 3f501faa7bd..bd1d139e91e 100644 --- a/tests/bluetooth/bsim_bt/edtt_ble_test_app/gatt_test_app/prj.conf +++ b/tests/bluetooth/bsim_bt/edtt_ble_test_app/gatt_test_app/prj.conf @@ -16,7 +16,7 @@ CONFIG_BT_CTLR=y CONFIG_BT_LL_SW_SPLIT=y CONFIG_BT_HCI_ACL_FLOW_CONTROL=y -CONFIG_BT_L2CAP_RX_MTU=512 +CONFIG_BT_BUF_ACL_RX_SIZE=516 CONFIG_BT_L2CAP_TX_MTU=512 CONFIG_BT_DEBUG_LOG=y diff --git a/tests/bluetooth/bsim_bt/edtt_ble_test_app/hci_test_app/prj.conf b/tests/bluetooth/bsim_bt/edtt_ble_test_app/hci_test_app/prj.conf index c88be4f70d8..3f46aac81b2 100644 --- a/tests/bluetooth/bsim_bt/edtt_ble_test_app/hci_test_app/prj.conf +++ b/tests/bluetooth/bsim_bt/edtt_ble_test_app/hci_test_app/prj.conf @@ -19,7 +19,8 @@ CONFIG_BT_CTLR_LE_ENC=y CONFIG_BT_CTLR_PRIVACY=y CONFIG_BT_CTLR_FILTER=y CONFIG_BT_CTLR_DTM_HCI=y -CONFIG_BT_CTLR_TX_BUFFER_SIZE=60 +CONFIG_BT_BUF_ACL_TX_SIZE=60 +CONFIG_BT_BUF_ACL_RX_SIZE=60 CONFIG_BT_CTLR_DATA_LENGTH_MAX=60 CONFIG_PM=y diff --git a/tests/bluetooth/bsim_bt/edtt_ble_test_app/hci_test_app/src/main.c b/tests/bluetooth/bsim_bt/edtt_ble_test_app/hci_test_app/src/main.c index 199b941a33a..50daf5fc2d9 100644 --- a/tests/bluetooth/bsim_bt/edtt_ble_test_app/hci_test_app/src/main.c +++ b/tests/bluetooth/bsim_bt/edtt_ble_test_app/hci_test_app/src/main.c @@ -157,7 +157,7 @@ NET_BUF_POOL_FIXED_DEFINE(event_pool, 32, BT_BUF_RX_SIZE + 4, NULL); static K_FIFO_DEFINE(event_queue); static K_FIFO_DEFINE(rx_queue); NET_BUF_POOL_FIXED_DEFINE(data_pool, CONFIG_BT_CTLR_RX_BUFFERS + 14, - BT_BUF_ACL_SIZE + 4, NULL); + BT_BUF_ACL_SIZE(CONFIG_BT_BUF_ACL_TX_SIZE) + 4, NULL); static K_FIFO_DEFINE(data_queue); /** diff --git a/tests/bluetooth/hci_prop_evt/src/main.c b/tests/bluetooth/hci_prop_evt/src/main.c index 8afc16c1db0..e257a372c26 100644 --- a/tests/bluetooth/hci_prop_evt/src/main.c +++ b/tests/bluetooth/hci_prop_evt/src/main.c @@ -233,7 +233,7 @@ struct bt_recv_job_data { struct k_work work; /* Work item */ struct k_sem *sync; /* Semaphore to synchronize with */ struct net_buf *buf; /* Net buffer to be passed to bt_recv() */ -} job_data[CONFIG_BT_RX_BUF_COUNT]; +} job_data[CONFIG_BT_BUF_EVT_RX_COUNT]; #define job(buf) (&job_data[net_buf_id(buf)]) diff --git a/tests/bluetooth/mesh/dbg.conf b/tests/bluetooth/mesh/dbg.conf index 0adeaea82e4..b513b13e82e 100644 --- a/tests/bluetooth/mesh/dbg.conf +++ b/tests/bluetooth/mesh/dbg.conf @@ -19,8 +19,6 @@ CONFIG_BT_PERIPHERAL=y CONFIG_BT=y CONFIG_BT_TINYCRYPT_ECC=y -CONFIG_BT_L2CAP_RX_MTU=69 -CONFIG_BT_L2CAP_TX_MTU=69 CONFIG_BT_MESH=y CONFIG_BT_MESH_RELAY=y diff --git a/tests/bluetooth/mesh/ext_adv.conf b/tests/bluetooth/mesh/ext_adv.conf index 4d87fd75c3d..a37aab17fb8 100644 --- a/tests/bluetooth/mesh/ext_adv.conf +++ b/tests/bluetooth/mesh/ext_adv.conf @@ -18,8 +18,6 @@ CONFIG_BT_PERIPHERAL=y CONFIG_BT=y CONFIG_BT_TINYCRYPT_ECC=y -CONFIG_BT_L2CAP_RX_MTU=69 -CONFIG_BT_L2CAP_TX_MTU=69 CONFIG_BT_MESH=y CONFIG_BT_MESH_RELAY=y diff --git a/tests/bluetooth/mesh/gatt.conf b/tests/bluetooth/mesh/gatt.conf index 85e769747fa..f3e575236a0 100644 --- a/tests/bluetooth/mesh/gatt.conf +++ b/tests/bluetooth/mesh/gatt.conf @@ -19,8 +19,6 @@ CONFIG_BT_PERIPHERAL=y CONFIG_BT=y CONFIG_BT_TINYCRYPT_ECC=y -CONFIG_BT_L2CAP_RX_MTU=69 -CONFIG_BT_L2CAP_TX_MTU=69 CONFIG_BT_MESH=y CONFIG_BT_MESH_RELAY=y diff --git a/tests/bluetooth/mesh/lpn.conf b/tests/bluetooth/mesh/lpn.conf index 11ad46a3f2d..b3a858c4630 100644 --- a/tests/bluetooth/mesh/lpn.conf +++ b/tests/bluetooth/mesh/lpn.conf @@ -19,8 +19,6 @@ CONFIG_BT_PERIPHERAL=y CONFIG_BT=y CONFIG_BT_TINYCRYPT_ECC=y -CONFIG_BT_L2CAP_RX_MTU=69 -CONFIG_BT_L2CAP_TX_MTU=69 CONFIG_BT_MESH=y CONFIG_BT_MESH_RELAY=n diff --git a/tests/bluetooth/mesh/microbit_gatt.conf b/tests/bluetooth/mesh/microbit_gatt.conf index 88dcd82399c..daa5c083637 100644 --- a/tests/bluetooth/mesh/microbit_gatt.conf +++ b/tests/bluetooth/mesh/microbit_gatt.conf @@ -13,8 +13,6 @@ CONFIG_BT_MESH_PB_ADV=n CONFIG_BT=y CONFIG_BT_TINYCRYPT_ECC=y CONFIG_BT_RX_STACK_SIZE=1400 -CONFIG_BT_L2CAP_RX_MTU=69 -CONFIG_BT_L2CAP_TX_MTU=69 CONFIG_BT_L2CAP_TX_BUF_COUNT=4 CONFIG_BT_CTLR_DUP_FILTER_LEN=0 diff --git a/tests/bluetooth/mesh/pb_gatt.conf b/tests/bluetooth/mesh/pb_gatt.conf index 8bbffb7eac8..db9a522d64c 100644 --- a/tests/bluetooth/mesh/pb_gatt.conf +++ b/tests/bluetooth/mesh/pb_gatt.conf @@ -19,8 +19,6 @@ CONFIG_BT_PERIPHERAL=y CONFIG_BT=y CONFIG_BT_TINYCRYPT_ECC=y -CONFIG_BT_L2CAP_RX_MTU=69 -CONFIG_BT_L2CAP_TX_MTU=69 CONFIG_BT_MESH=y CONFIG_BT_MESH_RELAY=y diff --git a/tests/bluetooth/mesh/prj.conf b/tests/bluetooth/mesh/prj.conf index 179cc5d2222..643a467debc 100644 --- a/tests/bluetooth/mesh/prj.conf +++ b/tests/bluetooth/mesh/prj.conf @@ -19,8 +19,6 @@ CONFIG_BT_PERIPHERAL=y CONFIG_BT=y CONFIG_BT_TINYCRYPT_ECC=y -CONFIG_BT_L2CAP_RX_MTU=69 -CONFIG_BT_L2CAP_TX_MTU=69 CONFIG_BT_MESH=y CONFIG_BT_MESH_RELAY=y diff --git a/tests/bluetooth/mesh/proxy.conf b/tests/bluetooth/mesh/proxy.conf index 346d17238a8..3c4c51cde3d 100644 --- a/tests/bluetooth/mesh/proxy.conf +++ b/tests/bluetooth/mesh/proxy.conf @@ -19,8 +19,6 @@ CONFIG_BT_PERIPHERAL=y CONFIG_BT=y CONFIG_BT_TINYCRYPT_ECC=y -CONFIG_BT_L2CAP_RX_MTU=69 -CONFIG_BT_L2CAP_TX_MTU=69 CONFIG_BT_MESH=y CONFIG_BT_MESH_RELAY=n diff --git a/tests/bluetooth/mesh_shell/prj.conf b/tests/bluetooth/mesh_shell/prj.conf index 318f55ed540..a63c3cc70ce 100644 --- a/tests/bluetooth/mesh_shell/prj.conf +++ b/tests/bluetooth/mesh_shell/prj.conf @@ -39,8 +39,6 @@ CONFIG_BT_CTLR_SLAVE_FEAT_REQ=n CONFIG_BT_CTLR_ADVANCED_FEATURES=y CONFIG_BT_CTLR_FILTER=n -CONFIG_BT_L2CAP_RX_MTU=69 -CONFIG_BT_L2CAP_TX_MTU=69 CONFIG_BT_L2CAP_TX_BUF_COUNT=4 CONFIG_BT_MESH=y diff --git a/tests/bluetooth/shell/mesh.conf b/tests/bluetooth/shell/mesh.conf index caddf5ea8a3..7b98c380183 100644 --- a/tests/bluetooth/shell/mesh.conf +++ b/tests/bluetooth/shell/mesh.conf @@ -20,9 +20,6 @@ CONFIG_BT_DEVICE_NAME="test shell" CONFIG_BT_L2CAP_TX_BUF_COUNT=6 CONFIG_BT_HRS=y -CONFIG_BT_L2CAP_RX_MTU=69 -CONFIG_BT_L2CAP_TX_MTU=69 - CONFIG_BT_MESH=y CONFIG_BT_MESH_SHELL=y CONFIG_BT_MESH_RELAY=y