From e9ceedcff75cba01c5f70e305f34980e48e1a125 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Thu, 29 Oct 2015 14:45:02 +0200 Subject: [PATCH] Bluetooth: Introduce config options for buffer counts/sizes Introduce dedicate Kconfig options for ACL & HCI buffer counts and sizes. Change-Id: I96796058f70998e1e721849422c4bc4e950b6d93 Signed-off-by: Johan Hedberg --- net/bluetooth/Kconfig | 48 ++++++++++++++++++++++++++++++++++++++++ net/bluetooth/att.h | 2 +- net/bluetooth/hci_core.c | 11 ++++----- net/bluetooth/hci_core.h | 11 --------- net/bluetooth/l2cap.c | 5 ++--- 5 files changed, 57 insertions(+), 20 deletions(-) diff --git a/net/bluetooth/Kconfig b/net/bluetooth/Kconfig index 887614a273b..d494d8e7375 100644 --- a/net/bluetooth/Kconfig +++ b/net/bluetooth/Kconfig @@ -55,6 +55,54 @@ config BLUETOOTH_DEBUG_HCI_CORE This option enables debug support for Bluetooth HCI core. +config BLUETOOTH_HCI_COUNT + int "Number of HCI buffers" + default 8 + range 2 64 + help + Number of buffers available for HCI commands and events. + +config BLUETOOTH_HCI_SIZE + int "Size of HCI buffers" + default 72 + range 72 260 + help + Maximum size of each HCI buffer. + +if BLUETOOTH_CONN +config BLUETOOTH_ACL_IN_COUNT + int "Number of incoming ACL data buffers" + default 7 + range 1 16 + help + Number of buffers available for incoming ACL data. + +config BLUETOOTH_ACL_IN_SIZE + int "Size of incoming ACL data buffers" + default 74 if BLUETOOTH_SMP + default 32 if !BLUETOOTH_SMP + range 74 1300 if BLUETOOTH_SMP + range 32 1300 if !BLUETOOTH_SMP + help + Maximum size of each incoming ACL data buffer. + +config BLUETOOTH_ACL_OUT_COUNT + int "Number of incoming ACL data buffers" + default 7 + range 1 16 + help + Number of buffers available for incoming ACL data. + +config BLUETOOTH_ACL_OUT_SIZE + int "Size of incoming ACL data buffers" + default 74 if BLUETOOTH_SMP + default 32 if !BLUETOOTH_SMP + range 74 1300 if BLUETOOTH_SMP + range 32 1300 if !BLUETOOTH_SMP + help + Maximum size of each outgoing ACL data buffer. +endif # BLUETOOTH_CONN + if BLUETOOTH_PERIPHERAL || BLUETOOTH_CENTRAL config BLUETOOTH_SMP bool "Security Manager Protocol support" diff --git a/net/bluetooth/att.h b/net/bluetooth/att.h index 65ca3bed94a..66d7f0dffa3 100644 --- a/net/bluetooth/att.h +++ b/net/bluetooth/att.h @@ -21,7 +21,7 @@ /* Size of MTU is based on the maximum amount of data the buffer can hold * excluding L2CAP, ACL and driver headers. */ -#define BT_ATT_MAX_LE_MTU (BT_BUF_MAX_DATA - \ +#define BT_ATT_MAX_LE_MTU (CONFIG_BLUETOOTH_ACL_IN_SIZE - \ sizeof(struct bt_l2cap_hdr) - \ sizeof(struct bt_hci_acl_hdr) - \ bt_dev.drv->recv_reserve) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index e60b8f1aa47..327c630739b 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -76,7 +76,8 @@ struct bt_acl_data { /* Available (free) buffers queues */ static struct nano_fifo avail_hci; -static NET_BUF_POOL(hci_pool, 8, BT_BUF_MAX_DATA, &avail_hci, NULL, +static NET_BUF_POOL(hci_pool, CONFIG_BLUETOOTH_HCI_COUNT, + CONFIG_BLUETOOTH_HCI_SIZE, &avail_hci, NULL, sizeof(struct bt_hci_data)); #if defined(CONFIG_BLUETOOTH_CONN) @@ -108,9 +109,9 @@ static void report_completed_packet(struct net_buf *buf) #define BT_BUF_ACL_IN_MAX 7 static struct nano_fifo avail_acl_in; -static NET_BUF_POOL(acl_in_pool, BT_BUF_ACL_IN_MAX, BT_BUF_MAX_DATA, - &avail_acl_in, report_completed_packet, - sizeof(struct bt_acl_data)); +static NET_BUF_POOL(acl_in_pool, CONFIG_BLUETOOTH_ACL_IN_COUNT, + CONFIG_BLUETOOTH_ACL_IN_SIZE, &avail_acl_in, + report_completed_packet, sizeof(struct bt_acl_data)); #endif /* CONFIG_BLUETOOTH_CONN */ /* Incoming buffer type lookup helper */ @@ -731,7 +732,7 @@ static int set_flow_control(void) hbs = net_buf_add(buf, sizeof(*hbs)); memset(hbs, 0, sizeof(*hbs)); - hbs->acl_mtu = sys_cpu_to_le16(BT_BUF_MAX_DATA - + hbs->acl_mtu = sys_cpu_to_le16(CONFIG_BLUETOOTH_ACL_IN_SIZE - sizeof(struct bt_hci_acl_hdr) - bt_dev.drv->recv_reserve); hbs->acl_pkts = sys_cpu_to_le16(BT_BUF_ACL_IN_MAX); diff --git a/net/bluetooth/hci_core.h b/net/bluetooth/hci_core.h index 231c3194e11..6d25be7abd5 100644 --- a/net/bluetooth/hci_core.h +++ b/net/bluetooth/hci_core.h @@ -175,14 +175,3 @@ const char *bt_addr_le_str(const bt_addr_le_t *addr); #endif int bt_le_scan_update(void); - -/** @def BT_BUF_MAX_DATA - * @brief Maximum amount of data that can fit in a buffer. - * - * The biggest foreseeable buffer size requirement right now comes from - * the Bluetooth 4.2 SMP MTU which is 65. This then become 65 + 4 (L2CAP - * header) + 4 (ACL header) + 1 (H4 header) = 74. This also covers the - * biggest HCI commands and events which are a bit under the 70 byte - * mark. - */ -#define BT_BUF_MAX_DATA 74 diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c index c05b270feaa..510bba485b3 100644 --- a/net/bluetooth/l2cap.c +++ b/net/bluetooth/l2cap.c @@ -62,10 +62,9 @@ struct bt_l2cap { static struct bt_l2cap bt_l2cap_pool[CONFIG_BLUETOOTH_MAX_CONN]; -#define BT_BUF_ACL_OUT_MAX 7 static struct nano_fifo avail_acl_out; -static NET_BUF_POOL(acl_out_pool, BT_BUF_ACL_OUT_MAX, BT_BUF_MAX_DATA, - &avail_acl_out, NULL, 0); +static NET_BUF_POOL(acl_out_pool, CONFIG_BLUETOOTH_ACL_OUT_COUNT, + CONFIG_BLUETOOTH_ACL_OUT_SIZE, &avail_acl_out, NULL, 0); static struct bt_l2cap *l2cap_chan_get(struct bt_conn *conn) {