Bluetooth: Move HCI command buffer user data into separate array

The HCI command buffers are the only ones with more than 4 bytes of
required user data. Move the user data into a separate array and do
the mapping with the help of net_buf_id(). After this, it will be
possible to reduce the default net_buf user data size from 8 to 4.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2018-02-10 15:40:07 +02:00 committed by Johan Hedberg
commit 0ad6dbd80d
2 changed files with 8 additions and 8 deletions

View file

@ -25,10 +25,10 @@ BUILD_ASSERT(CONFIG_SYSTEM_WORKQUEUE_PRIORITY < 0);
*/
BUILD_ASSERT(CONFIG_BT_HCI_TX_PRIO < CONFIG_BT_RX_PRIO);
/* The Bluetooth subsystem requires network buffers to have at least 8 bytes
/* The Bluetooth subsystem requires network buffers to have at least 4 bytes
* reserved for user data.
*/
BUILD_ASSERT(CONFIG_NET_BUF_USER_DATA_SIZE >= 8);
BUILD_ASSERT(CONFIG_NET_BUF_USER_DATA_SIZE >= 4);
#if defined(CONFIG_BT_CTLR)
/* The Bluetooth Controller's priority receive thread priority shall be higher

View file

@ -93,9 +93,6 @@ static size_t discovery_results_count;
#endif /* CONFIG_BT_BREDR */
struct cmd_data {
/** BT_BUF_CMD */
u8_t type;
/** HCI status of the command completion */
u8_t status;
@ -117,7 +114,9 @@ struct acl_data {
u16_t handle;
};
#define cmd(buf) ((struct cmd_data *)net_buf_user_data(buf))
static struct cmd_data cmd_data[CONFIG_BT_HCI_CMD_COUNT];
#define cmd(buf) (&cmd_data[net_buf_id(buf)])
#define acl(buf) ((struct acl_data *)net_buf_user_data(buf))
/* HCI command buffers. Derive the needed size from BT_BUF_RX_SIZE since
@ -125,7 +124,7 @@ struct acl_data {
*/
#define CMD_BUF_SIZE BT_BUF_RX_SIZE
NET_BUF_POOL_DEFINE(hci_cmd_pool, CONFIG_BT_HCI_CMD_COUNT,
CMD_BUF_SIZE, sizeof(struct cmd_data), NULL);
CMD_BUF_SIZE, BT_BUF_USER_DATA_MIN, NULL);
NET_BUF_POOL_DEFINE(hci_rx_pool, CONFIG_BT_RX_BUF_COUNT,
BT_BUF_RX_SIZE, BT_BUF_USER_DATA_MIN, NULL);
@ -199,7 +198,8 @@ struct net_buf *bt_hci_cmd_create(u16_t opcode, u8_t param_len)
net_buf_reserve(buf, CONFIG_BT_HCI_RESERVE);
cmd(buf)->type = BT_BUF_CMD;
bt_buf_set_type(buf, BT_BUF_CMD);
cmd(buf)->opcode = opcode;
cmd(buf)->sync = NULL;