Bluetooth: Consolidate bt_buf_get* functions
We may soon want to have a _wait() variant of bt_buf_get, so to avoid the number of 'get' function growing too large consolidate the existing get() and get_reserve() functions into a single one. The new consolidated function also takes the type as input parameter so that we know this from the very start and thereby plan for the split into multiple buffer pools. Change-Id: Ia09448565349def2be9bc08d9510fedd029480b4 Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
4e65d0aac2
commit
d829fe9755
5 changed files with 20 additions and 26 deletions
|
@ -142,19 +142,21 @@ void bt_uart_isr(void *unused)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = bt_buf_get();
|
|
||||||
if (!buf) {
|
|
||||||
BT_ERR("Cannot get free buffer\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case H4_EVT:
|
case H4_EVT:
|
||||||
buf->type = BT_EVT;
|
buf = bt_buf_get(BT_EVT, 0);
|
||||||
|
if (!buf) {
|
||||||
|
BT_ERR("No event buffers!\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
remaining = bt_uart_evt_recv(buf);
|
remaining = bt_uart_evt_recv(buf);
|
||||||
break;
|
break;
|
||||||
case H4_ACL:
|
case H4_ACL:
|
||||||
buf->type = BT_ACL_IN;
|
buf = bt_buf_get(BT_ACL_IN, 0);
|
||||||
|
if (!buf) {
|
||||||
|
BT_ERR("No ACL buffers!\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
remaining = bt_uart_acl_recv(buf);
|
remaining = bt_uart_acl_recv(buf);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -65,11 +65,10 @@ struct bt_buf {
|
||||||
uint8_t buf[BT_BUF_MAX_DATA];
|
uint8_t buf[BT_BUF_MAX_DATA];
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Get buffer from the available buffers pool */
|
/* Get buffer from the available buffers pool with specified type and
|
||||||
struct bt_buf *bt_buf_get(void);
|
* reserved headroom.
|
||||||
|
*/
|
||||||
/* Same as bt_buf_get, but also reserve headroom for potential headers */
|
struct bt_buf *bt_buf_get(enum bt_buf_type type, size_t reserve_head);
|
||||||
struct bt_buf *bt_buf_get_reserve(size_t reserve_head);
|
|
||||||
|
|
||||||
/* Place buffer back into the available buffers pool */
|
/* Place buffer back into the available buffers pool */
|
||||||
void bt_buf_put(struct bt_buf *buf);
|
void bt_buf_put(struct bt_buf *buf);
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
static struct bt_buf buffers[NUM_BUFS];
|
static struct bt_buf buffers[NUM_BUFS];
|
||||||
static struct nano_fifo free_bufs;
|
static struct nano_fifo free_bufs;
|
||||||
|
|
||||||
struct bt_buf *bt_buf_get_reserve(size_t reserve_head)
|
struct bt_buf *bt_buf_get(enum bt_buf_type type, size_t reserve_head)
|
||||||
{
|
{
|
||||||
struct bt_buf *buf;
|
struct bt_buf *buf;
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ struct bt_buf *bt_buf_get_reserve(size_t reserve_head)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buf->type = type;
|
||||||
buf->data = buf->buf + reserve_head;
|
buf->data = buf->buf + reserve_head;
|
||||||
buf->len = 0;
|
buf->len = 0;
|
||||||
buf->sync = NULL;
|
buf->sync = NULL;
|
||||||
|
@ -64,11 +65,6 @@ struct bt_buf *bt_buf_get_reserve(size_t reserve_head)
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct bt_buf *bt_buf_get(void)
|
|
||||||
{
|
|
||||||
return bt_buf_get_reserve(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void bt_buf_put(struct bt_buf *buf)
|
void bt_buf_put(struct bt_buf *buf)
|
||||||
{
|
{
|
||||||
BT_DBG("buf %p\n", buf);
|
BT_DBG("buf %p\n", buf);
|
||||||
|
|
|
@ -267,8 +267,8 @@ void bt_conn_del(struct bt_conn *conn)
|
||||||
conn->state = BT_CONN_DISCONNECTED;
|
conn->state = BT_CONN_DISCONNECTED;
|
||||||
|
|
||||||
/* Send dummy buffers to wake up and kill the fibers */
|
/* Send dummy buffers to wake up and kill the fibers */
|
||||||
nano_fifo_put(&conn->tx_queue, bt_buf_get());
|
nano_fifo_put(&conn->tx_queue, bt_buf_get(BT_ACL_OUT, 0));
|
||||||
nano_fifo_put(&conn->rx_queue, bt_buf_get());
|
nano_fifo_put(&conn->rx_queue, bt_buf_get(BT_ACL_IN, 0));
|
||||||
|
|
||||||
bt_conn_put(conn);
|
bt_conn_put(conn);
|
||||||
}
|
}
|
||||||
|
@ -314,12 +314,10 @@ struct bt_buf *bt_conn_create_pdu(struct bt_conn *conn, size_t len)
|
||||||
struct bt_hci_acl_hdr *hdr;
|
struct bt_hci_acl_hdr *hdr;
|
||||||
struct bt_buf *buf;
|
struct bt_buf *buf;
|
||||||
|
|
||||||
buf = bt_buf_get_reserve(dev->drv->head_reserve);
|
buf = bt_buf_get(BT_ACL_OUT, dev->drv->head_reserve);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
buf->type = BT_ACL_OUT;
|
|
||||||
|
|
||||||
hdr = (void *)bt_buf_add(buf, sizeof(*hdr));
|
hdr = (void *)bt_buf_add(buf, sizeof(*hdr));
|
||||||
hdr->handle = sys_cpu_to_le16(conn->handle);
|
hdr->handle = sys_cpu_to_le16(conn->handle);
|
||||||
hdr->len = len;
|
hdr->len = len;
|
||||||
|
|
|
@ -57,7 +57,7 @@ static struct bt_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len)
|
||||||
|
|
||||||
BT_DBG("opcode %x param_len %u\n", opcode, param_len);
|
BT_DBG("opcode %x param_len %u\n", opcode, param_len);
|
||||||
|
|
||||||
buf = bt_buf_get_reserve(dev.drv->head_reserve);
|
buf = bt_buf_get(BT_CMD, dev.drv->head_reserve);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
BT_ERR("Cannot get free buffer\n");
|
BT_ERR("Cannot get free buffer\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -65,7 +65,6 @@ static struct bt_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len)
|
||||||
|
|
||||||
BT_DBG("buf %p\n", buf);
|
BT_DBG("buf %p\n", buf);
|
||||||
|
|
||||||
buf->type = BT_CMD;
|
|
||||||
buf->opcode = opcode;
|
buf->opcode = opcode;
|
||||||
buf->sync = NULL;
|
buf->sync = NULL;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue