Skip to content

Commit 297f4f4

Browse files
Johan Hedbergnashif
authored andcommitted
Bluetooth: Split HCI command & event buffers to two pools
The HCI commands and events have slightly different requirements (e.g. max sizes, or the fact that events don't need any user data) so it makes sense to keep them separate. The total count is kept at 8 (2 + 6) but the ACL_OUT count is modified to not exceed the event count (to avoid inability of handling bursts of Number of Completed Packets events). The ACL_IN count is also modified to keep these symmetric for now. Change-Id: Ia1915a596424425525b6df67e0ddce47a7f618f3 Signed-off-by: Johan Hedberg <[email protected]>
1 parent eaa34b0 commit 297f4f4

File tree

2 files changed

+40
-17
lines changed

2 files changed

+40
-17
lines changed

net/bluetooth/Kconfig

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,41 @@ config BLUETOOTH_DEBUG_HCI_CORE
5555
This option enables debug support for Bluetooth HCI
5656
core.
5757

58-
config BLUETOOTH_HCI_COUNT
59-
int "Number of HCI buffers"
60-
default 8
58+
config BLUETOOTH_HCI_CMD_COUNT
59+
int "Number of HCI command buffers"
60+
default 2
6161
range 2 64
6262
help
63-
Number of buffers available for HCI commands and events.
63+
Number of buffers available for HCI commands.
6464

65-
config BLUETOOTH_HCI_SIZE
66-
int "Size of HCI buffers"
65+
config BLUETOOTH_HCI_CMD_SIZE
66+
int "Size of HCI command buffers"
6767
default 72
6868
range 72 260
6969
help
70-
Maximum size of each HCI buffer.
70+
Maximum size of each HCI command buffer.
71+
72+
config BLUETOOTH_HCI_EVT_COUNT
73+
int "Number of HCI event buffers"
74+
default 6
75+
range 2 64
76+
help
77+
Number of buffers available for HCI events. This number should
78+
ideally be at least as large as BLUETOOTH_ACL_OUT_COUNT to make
79+
sure we've got enough buffers to handle bursts of Number of
80+
Completed Packets HCI events.
81+
82+
config BLUETOOTH_HCI_EVT_SIZE
83+
int "Size of HCI event buffers"
84+
default 72
85+
range 72 260
86+
help
87+
Maximum size of each HCI event buffer.
7188

7289
if BLUETOOTH_CONN
7390
config BLUETOOTH_ACL_IN_COUNT
7491
int "Number of incoming ACL data buffers"
75-
default 7
92+
default 5
7693
range 1 16
7794
help
7895
Number of buffers available for incoming ACL data.
@@ -88,7 +105,7 @@ config BLUETOOTH_ACL_IN_SIZE
88105

89106
config BLUETOOTH_ACL_OUT_COUNT
90107
int "Number of incoming ACL data buffers"
91-
default 7
108+
default 5
92109
range 1 16
93110
help
94111
Number of buffers available for incoming ACL data.

net/bluetooth/hci_core.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,17 @@ struct bt_acl_data {
7474
#define bt_hci(buf) ((struct bt_hci_data *)net_buf_user_data(buf))
7575
#define bt_acl(buf) ((struct bt_acl_data *)net_buf_user_data(buf))
7676

77-
/* Available (free) buffers queues */
78-
static struct nano_fifo avail_hci;
79-
static NET_BUF_POOL(hci_pool, CONFIG_BLUETOOTH_HCI_COUNT,
80-
CONFIG_BLUETOOTH_HCI_SIZE, &avail_hci, NULL,
77+
/* HCI command buffers */
78+
static struct nano_fifo avail_hci_cmd;
79+
static NET_BUF_POOL(hci_cmd_pool, CONFIG_BLUETOOTH_HCI_CMD_COUNT,
80+
CONFIG_BLUETOOTH_HCI_CMD_SIZE, &avail_hci_cmd, NULL,
8181
sizeof(struct bt_hci_data));
8282

83+
/* HCI event buffers */
84+
static struct nano_fifo avail_hci_evt;
85+
static NET_BUF_POOL(hci_evt_pool, CONFIG_BLUETOOTH_HCI_EVT_COUNT,
86+
CONFIG_BLUETOOTH_HCI_EVT_SIZE, &avail_hci_evt, NULL, 0);
87+
8388
#if defined(CONFIG_BLUETOOTH_CONN)
8489
static void report_completed_packet(struct net_buf *buf)
8590
{
@@ -116,7 +121,7 @@ static NET_BUF_POOL(acl_in_pool, CONFIG_BLUETOOTH_ACL_IN_COUNT,
116121
/* Incoming buffer type lookup helper */
117122
static enum bt_buf_type bt_type(struct net_buf *buf)
118123
{
119-
if (buf->free == &avail_hci) {
124+
if (buf->free == &avail_hci_evt) {
120125
return BT_EVT;
121126
} else {
122127
return BT_ACL_IN;
@@ -158,7 +163,7 @@ struct net_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len)
158163

159164
BT_DBG("opcode %x param_len %u\n", opcode, param_len);
160165

161-
buf = net_buf_get(&avail_hci, bt_dev.drv->send_reserve);
166+
buf = net_buf_get(&avail_hci_cmd, bt_dev.drv->send_reserve);
162167
if (!buf) {
163168
BT_ERR("Cannot get free buffer\n");
164169
return NULL;
@@ -1595,7 +1600,8 @@ int bt_enable(bt_ready_cb_t cb)
15951600
}
15961601

15971602
/* Initialize the buffer pools */
1598-
net_buf_pool_init(hci_pool);
1603+
net_buf_pool_init(hci_cmd_pool);
1604+
net_buf_pool_init(hci_evt_pool);
15991605
#if defined(CONFIG_BLUETOOTH_CONN)
16001606
net_buf_pool_init(acl_in_pool);
16011607
#endif /* CONFIG_BLUETOOTH_CONN */
@@ -1782,7 +1788,7 @@ int bt_stop_scanning(void)
17821788

17831789
struct net_buf *bt_buf_get_evt(void)
17841790
{
1785-
return net_buf_get(&avail_hci, bt_dev.drv->recv_reserve);
1791+
return net_buf_get(&avail_hci_evt, bt_dev.drv->recv_reserve);
17861792
}
17871793

17881794
struct net_buf *bt_buf_get_acl(void)

0 commit comments

Comments
 (0)