Bluetooth: Consolidate flow control Kconfig

Since Controller to Host flow control is a feature that affects both
sides equally, move it to the top-level Kconfig file and consolidate its
use in both Controller and Host.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
This commit is contained in:
Carles Cufi 2017-05-04 16:09:53 +02:00 committed by Johan Hedberg
commit a1ff1a0933
11 changed files with 44 additions and 46 deletions

View file

@ -69,6 +69,22 @@ config BLUETOOTH_MAX_CONN
Maximum number of simultaneous Bluetooth connections Maximum number of simultaneous Bluetooth connections
supported. supported.
if BLUETOOTH_CONN
config BLUETOOTH_HCI_ACL_FLOW_CONTROL
bool "Controller to Host ACL flow control support"
default n
# Enable if building a Host-only build
default y if !BLUETOOTH_CONTROLLER
# Enable if building a Controller-only build
default y if BLUETOOTH_HCI_RAW
select POLL
help
Enable support for throttling ACL buffers from the controller
to the host. This is particularly useful when the host and
controller are on separate cores since it ensures that we do
not run out of incoming ACL buffers.
endif # BLUETOOTH_CONN
config BLUETOOTH_DEBUG config BLUETOOTH_DEBUG
# Virtual/hidden option to make the conditions more intuitive # Virtual/hidden option to make the conditions more intuitive
bool bool

View file

@ -39,15 +39,6 @@ config BLUETOOTH_CONTROLLER_TO_HOST_UART_DEV_NAME
to connect to an external Bluetooth Host when Zephyr is to connect to an external Bluetooth Host when Zephyr is
acting as a Bluetooth Controller. acting as a Bluetooth Controller.
config BLUETOOTH_CONTROLLER_TO_HOST_FC
bool "Controller to Host Flow Control"
depends on BLUETOOTH_CONN
default n
default y if BLUETOOTH_HCI_RAW
select POLL
help
Enable Controller to Host flow control.
config BLUETOOTH_CONTROLLER_DUP_FILTER_LEN config BLUETOOTH_CONTROLLER_DUP_FILTER_LEN
prompt "Number of addresses in the scan duplicate filter" prompt "Number of addresses in the scan duplicate filter"
int int

View file

@ -47,7 +47,7 @@ static s32_t dup_count;
static u32_t dup_curr; static u32_t dup_curr;
#endif #endif
#if defined(CONFIG_BLUETOOTH_CONTROLLER_TO_HOST_FC) #if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL)
s32_t hci_hbuf_total; s32_t hci_hbuf_total;
u32_t hci_hbuf_sent; u32_t hci_hbuf_sent;
u32_t hci_hbuf_acked; u32_t hci_hbuf_acked;
@ -184,7 +184,7 @@ static void reset(struct net_buf *buf, struct net_buf **evt)
ccst = cmd_complete(evt, sizeof(*ccst)); ccst = cmd_complete(evt, sizeof(*ccst));
ccst->status = 0x00; ccst->status = 0x00;
} }
#if defined(CONFIG_BLUETOOTH_CONTROLLER_TO_HOST_FC) #if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL)
hci_hbuf_total = 0; hci_hbuf_total = 0;
hci_hbuf_sent = 0; hci_hbuf_sent = 0;
hci_hbuf_acked = 0; hci_hbuf_acked = 0;
@ -194,7 +194,7 @@ static void reset(struct net_buf *buf, struct net_buf **evt)
#endif #endif
} }
#if defined(CONFIG_BLUETOOTH_CONTROLLER_TO_HOST_FC) #if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL)
static void set_ctl_to_host_flow(struct net_buf *buf, struct net_buf **evt) static void set_ctl_to_host_flow(struct net_buf *buf, struct net_buf **evt)
{ {
struct bt_hci_cp_set_ctl_to_host_flow *cmd = (void *)buf->data; struct bt_hci_cp_set_ctl_to_host_flow *cmd = (void *)buf->data;
@ -298,7 +298,7 @@ static int ctrl_bb_cmd_handle(u8_t ocf, struct net_buf *cmd,
reset(cmd, evt); reset(cmd, evt);
break; break;
#if defined(CONFIG_BLUETOOTH_CONTROLLER_TO_HOST_FC) #if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL)
case BT_OCF(BT_HCI_OP_SET_CTL_TO_HOST_FLOW): case BT_OCF(BT_HCI_OP_SET_CTL_TO_HOST_FLOW):
set_ctl_to_host_flow(cmd, evt); set_ctl_to_host_flow(cmd, evt);
break; break;
@ -344,7 +344,7 @@ static void read_supported_commands(struct net_buf *buf, struct net_buf **evt)
rp->commands[0] = (1 << 5); rp->commands[0] = (1 << 5);
/* Set Event Mask, and Reset. */ /* Set Event Mask, and Reset. */
rp->commands[5] = (1 << 6) | (1 << 7); rp->commands[5] = (1 << 6) | (1 << 7);
#if defined(CONFIG_BLUETOOTH_CONTROLLER_TO_HOST_FC) #if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL)
/* Set FC, Host Buffer Size and Host Num Completed */ /* Set FC, Host Buffer Size and Host Num Completed */
rp->commands[10] = (1 << 5) | (1 << 6) | (1 << 7); rp->commands[10] = (1 << 5) | (1 << 6) | (1 << 7);
#endif #endif
@ -1624,7 +1624,7 @@ void hci_acl_encode(struct radio_pdu_node_rx *node_rx, struct net_buf *buf)
acl->len = sys_cpu_to_le16(pdu_data->len); acl->len = sys_cpu_to_le16(pdu_data->len);
data = (void *)net_buf_add(buf, pdu_data->len); data = (void *)net_buf_add(buf, pdu_data->len);
memcpy(data, &pdu_data->payload.lldata[0], pdu_data->len); memcpy(data, &pdu_data->payload.lldata[0], pdu_data->len);
#if defined(CONFIG_BLUETOOTH_CONTROLLER_TO_HOST_FC) #if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL)
if (hci_hbuf_total > 0) { if (hci_hbuf_total > 0) {
LL_ASSERT((hci_hbuf_sent - hci_hbuf_acked) < LL_ASSERT((hci_hbuf_sent - hci_hbuf_acked) <
hci_hbuf_total); hci_hbuf_total);
@ -1728,7 +1728,7 @@ s8_t hci_get_class(struct radio_pdu_node_rx *node_rx)
void hci_init(struct k_poll_signal *signal_host_buf) void hci_init(struct k_poll_signal *signal_host_buf)
{ {
#if defined(CONFIG_BLUETOOTH_CONTROLLER_TO_HOST_FC) #if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL)
hbuf_signal = signal_host_buf; hbuf_signal = signal_host_buf;
#endif #endif
reset(NULL, NULL); reset(NULL, NULL);

View file

@ -55,7 +55,7 @@ static u32_t prio_ts;
static u32_t rx_ts; static u32_t rx_ts;
#endif #endif
#if defined(CONFIG_BLUETOOTH_CONTROLLER_TO_HOST_FC) #if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL)
static struct k_poll_signal hbuf_signal = K_POLL_SIGNAL_INITIALIZER(); static struct k_poll_signal hbuf_signal = K_POLL_SIGNAL_INITIALIZER();
static sys_slist_t hbuf_pend; static sys_slist_t hbuf_pend;
static s32_t hbuf_count; static s32_t hbuf_count;
@ -148,7 +148,7 @@ static inline struct net_buf *process_node(struct radio_pdu_node_rx *node_rx)
s8_t class = hci_get_class(node_rx); s8_t class = hci_get_class(node_rx);
struct net_buf *buf = NULL; struct net_buf *buf = NULL;
#if defined(CONFIG_BLUETOOTH_CONTROLLER_TO_HOST_FC) #if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL)
if (hbuf_count != -1) { if (hbuf_count != -1) {
bool pend = !sys_slist_is_empty(&hbuf_pend); bool pend = !sys_slist_is_empty(&hbuf_pend);
@ -181,7 +181,7 @@ static inline struct net_buf *process_node(struct radio_pdu_node_rx *node_rx)
return buf; return buf;
} }
#if defined(CONFIG_BLUETOOTH_CONTROLLER_TO_HOST_FC) #if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL)
static inline struct net_buf *process_hbuf(void) static inline struct net_buf *process_hbuf(void)
{ {
/* shadow total count in case of preemption */ /* shadow total count in case of preemption */
@ -262,7 +262,7 @@ static inline struct net_buf *process_hbuf(void)
static void recv_thread(void *p1, void *p2, void *p3) static void recv_thread(void *p1, void *p2, void *p3)
{ {
#if defined(CONFIG_BLUETOOTH_CONTROLLER_TO_HOST_FC) #if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL)
/* @todo: check if the events structure really needs to be static */ /* @todo: check if the events structure really needs to be static */
static struct k_poll_event events[2] = { static struct k_poll_event events[2] = {
K_POLL_EVENT_STATIC_INITIALIZER(K_POLL_TYPE_SIGNAL, K_POLL_EVENT_STATIC_INITIALIZER(K_POLL_TYPE_SIGNAL,
@ -279,7 +279,7 @@ static void recv_thread(void *p1, void *p2, void *p3)
struct net_buf *buf = NULL; struct net_buf *buf = NULL;
BT_DBG("blocking"); BT_DBG("blocking");
#if defined(CONFIG_BLUETOOTH_CONTROLLER_TO_HOST_FC) #if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL)
int err; int err;
err = k_poll(events, 2, K_FOREVER); err = k_poll(events, 2, K_FOREVER);
@ -390,7 +390,7 @@ static int hci_driver_open(void)
return err; return err;
} }
#if defined(CONFIG_BLUETOOTH_CONTROLLER_TO_HOST_FC) #if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL)
hci_init(&hbuf_signal); hci_init(&hbuf_signal);
#else #else
hci_init(NULL); hci_init(NULL);

View file

@ -8,7 +8,7 @@
#ifndef _HCI_CONTROLLER_H_ #ifndef _HCI_CONTROLLER_H_
#define _HCI_CONTROLLER_H_ #define _HCI_CONTROLLER_H_
#if defined(CONFIG_BLUETOOTH_CONTROLLER_TO_HOST_FC) #if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL)
extern s32_t hci_hbuf_total; extern s32_t hci_hbuf_total;
extern u32_t hci_hbuf_sent; extern u32_t hci_hbuf_sent;
extern u32_t hci_hbuf_acked; extern u32_t hci_hbuf_acked;

View file

@ -103,17 +103,8 @@ config BLUETOOTH_INTERNAL_STORAGE
an internal default handler is used for this. an internal default handler is used for this.
if BLUETOOTH_CONN if BLUETOOTH_CONN
config BLUETOOTH_HOST_FLOW_CONTROL
bool "Controller to Host ACL flow control support"
default n
default y if !BLUETOOTH_CONTROLLER
help
Enable support for throttling ACL buffers from the controller
to the host. This is particularly useful when the host and
controller are on separate cores since it ensures that we do
not run out of incoming ACL buffers.
if BLUETOOTH_HOST_FLOW_CONTROL if BLUETOOTH_HCI_ACL_FLOW_CONTROL
config BLUETOOTH_ACL_RX_COUNT config BLUETOOTH_ACL_RX_COUNT
int "Number of incoming ACL data buffers" int "Number of incoming ACL data buffers"
default 6 default 6
@ -131,7 +122,7 @@ config BLUETOOTH_L2CAP_RX_MTU
range 65 1300 if BLUETOOTH_SMP range 65 1300 if BLUETOOTH_SMP
help help
Maximum size of each incoming L2CAP PDU. Maximum size of each incoming L2CAP PDU.
endif # BLUETOOTH_HOST_FLOW_CONTROL endif # BLUETOOTH_HCI_ACL_FLOW_CONTROL
config BLUETOOTH_L2CAP_TX_BUF_COUNT config BLUETOOTH_L2CAP_TX_BUF_COUNT
int "Number of L2CAP TX buffers" int "Number of L2CAP TX buffers"
@ -429,10 +420,10 @@ config BLUETOOTH_RFCOMM
config BLUETOOTH_RFCOMM_L2CAP_MTU config BLUETOOTH_RFCOMM_L2CAP_MTU
int "L2CAP MTU for RFCOMM frames" int "L2CAP MTU for RFCOMM frames"
default BLUETOOTH_RX_BUF_LEN default BLUETOOTH_RX_BUF_LEN
default BLUETOOTH_L2CAP_RX_MTU if BLUETOOTH_HOST_FLOW_CONTROL default BLUETOOTH_L2CAP_RX_MTU if BLUETOOTH_HCI_ACL_FLOW_CONTROL
depends on BLUETOOTH_RFCOMM depends on BLUETOOTH_RFCOMM
range BLUETOOTH_RX_BUF_LEN 32767 range BLUETOOTH_RX_BUF_LEN 32767
range BLUETOOTH_L2CAP_RX_MTU 32767 if BLUETOOTH_HOST_FLOW_CONTROL range BLUETOOTH_L2CAP_RX_MTU 32767 if BLUETOOTH_HCI_ACL_FLOW_CONTROL
help help
Maximum size of L2CAP PDU for RFCOMM frames. Maximum size of L2CAP PDU for RFCOMM frames.

View file

@ -125,7 +125,7 @@ NET_BUF_POOL_DEFINE(hci_cmd_pool, CONFIG_BLUETOOTH_HCI_CMD_COUNT,
NET_BUF_POOL_DEFINE(hci_rx_pool, CONFIG_BLUETOOTH_RX_BUF_COUNT, NET_BUF_POOL_DEFINE(hci_rx_pool, CONFIG_BLUETOOTH_RX_BUF_COUNT,
BT_BUF_RX_SIZE, BT_BUF_USER_DATA_MIN, NULL); BT_BUF_RX_SIZE, BT_BUF_USER_DATA_MIN, NULL);
#if defined(CONFIG_BLUETOOTH_HOST_FLOW_CONTROL) #if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL)
static void report_completed_packet(struct net_buf *buf) static void report_completed_packet(struct net_buf *buf)
{ {
@ -162,7 +162,7 @@ static void report_completed_packet(struct net_buf *buf)
#define ACL_IN_SIZE BT_L2CAP_BUF_SIZE(CONFIG_BLUETOOTH_L2CAP_RX_MTU) #define ACL_IN_SIZE BT_L2CAP_BUF_SIZE(CONFIG_BLUETOOTH_L2CAP_RX_MTU)
NET_BUF_POOL_DEFINE(acl_in_pool, CONFIG_BLUETOOTH_ACL_RX_COUNT, ACL_IN_SIZE, NET_BUF_POOL_DEFINE(acl_in_pool, CONFIG_BLUETOOTH_ACL_RX_COUNT, ACL_IN_SIZE,
BT_BUF_USER_DATA_MIN, report_completed_packet); BT_BUF_USER_DATA_MIN, report_completed_packet);
#endif /* CONFIG_BLUETOOTH_HOST_FLOW_CONTROL */ #endif /* CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL */
#if defined(CONFIG_BLUETOOTH_DEBUG) #if defined(CONFIG_BLUETOOTH_DEBUG)
const char *bt_addr_str(const bt_addr_t *addr) const char *bt_addr_str(const bt_addr_t *addr)
@ -1014,7 +1014,7 @@ failed:
bt_le_scan_update(false); bt_le_scan_update(false);
} }
#if defined(CONFIG_BLUETOOTH_HOST_FLOW_CONTROL) #if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL)
static int set_flow_control(void) static int set_flow_control(void)
{ {
struct bt_hci_cp_host_buffer_size *hbs; struct bt_hci_cp_host_buffer_size *hbs;
@ -1052,7 +1052,7 @@ static int set_flow_control(void)
net_buf_add_u8(buf, BT_HCI_CTL_TO_HOST_FLOW_ENABLE); net_buf_add_u8(buf, BT_HCI_CTL_TO_HOST_FLOW_ENABLE);
return bt_hci_cmd_send_sync(BT_HCI_OP_SET_CTL_TO_HOST_FLOW, buf, NULL); return bt_hci_cmd_send_sync(BT_HCI_OP_SET_CTL_TO_HOST_FLOW, buf, NULL);
} }
#endif /* CONFIG_BLUETOOTH_HOST_FLOW_CONTROL */ #endif /* CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL */
#endif /* CONFIG_BLUETOOTH_CONN */ #endif /* CONFIG_BLUETOOTH_CONN */
#if defined(CONFIG_BLUETOOTH_BREDR) #if defined(CONFIG_BLUETOOTH_BREDR)
@ -3070,7 +3070,7 @@ static int common_init(void)
read_supported_commands_complete(rsp); read_supported_commands_complete(rsp);
net_buf_unref(rsp); net_buf_unref(rsp);
#if defined(CONFIG_BLUETOOTH_HOST_FLOW_CONTROL) #if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL)
err = set_flow_control(); err = set_flow_control();
if (err) { if (err) {
return err; return err;
@ -4195,7 +4195,7 @@ struct net_buf *bt_buf_get_rx(enum bt_buf_type type, s32_t timeout)
__ASSERT(type == BT_BUF_EVT || type == BT_BUF_ACL_IN, __ASSERT(type == BT_BUF_EVT || type == BT_BUF_ACL_IN,
"Invalid buffer type requested"); "Invalid buffer type requested");
#if defined(CONFIG_BLUETOOTH_HOST_FLOW_CONTROL) #if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL)
if (type == BT_BUF_EVT) { if (type == BT_BUF_EVT) {
buf = net_buf_alloc(&hci_rx_pool, timeout); buf = net_buf_alloc(&hci_rx_pool, timeout);
} else { } else {

View file

@ -28,7 +28,7 @@
#define L2CAP_LE_MIN_MTU 23 #define L2CAP_LE_MIN_MTU 23
#if defined(CONFIG_BLUETOOTH_HOST_FLOW_CONTROL) #if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL)
#define L2CAP_LE_MAX_CREDITS (CONFIG_BLUETOOTH_ACL_RX_COUNT - 1) #define L2CAP_LE_MAX_CREDITS (CONFIG_BLUETOOTH_ACL_RX_COUNT - 1)
#else #else
#define L2CAP_LE_MAX_CREDITS (CONFIG_BLUETOOTH_RX_BUF_COUNT - 1) #define L2CAP_LE_MAX_CREDITS (CONFIG_BLUETOOTH_RX_BUF_COUNT - 1)

View file

@ -192,7 +192,7 @@ struct bt_l2cap_le_credits {
#define BT_L2CAP_SDU_HDR_LEN 2 #define BT_L2CAP_SDU_HDR_LEN 2
#if defined(CONFIG_BLUETOOTH_HOST_FLOW_CONTROL) #if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL)
#define BT_L2CAP_RX_MTU CONFIG_BLUETOOTH_L2CAP_RX_MTU #define BT_L2CAP_RX_MTU CONFIG_BLUETOOTH_L2CAP_RX_MTU
#else #else
#define BT_L2CAP_RX_MTU (CONFIG_BLUETOOTH_RX_BUF_LEN - \ #define BT_L2CAP_RX_MTU (CONFIG_BLUETOOTH_RX_BUF_LEN - \

View file

@ -34,7 +34,7 @@
#define RFCOMM_MIN_MTU BT_RFCOMM_SIG_MIN_MTU #define RFCOMM_MIN_MTU BT_RFCOMM_SIG_MIN_MTU
#define RFCOMM_DEFAULT_MTU 127 #define RFCOMM_DEFAULT_MTU 127
#if defined(CONFIG_BLUETOOTH_HOST_FLOW_CONTROL) #if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL)
#define RFCOMM_MAX_CREDITS (CONFIG_BLUETOOTH_ACL_RX_COUNT - 1) #define RFCOMM_MAX_CREDITS (CONFIG_BLUETOOTH_ACL_RX_COUNT - 1)
#else #else
#define RFCOMM_MAX_CREDITS (CONFIG_BLUETOOTH_RX_BUF_COUNT - 1) #define RFCOMM_MAX_CREDITS (CONFIG_BLUETOOTH_RX_BUF_COUNT - 1)

View file

@ -4,7 +4,7 @@ CONFIG_BLUETOOTH_CONTROLLER_WORKER_PRIO=0
CONFIG_BLUETOOTH_CONTROLLER_JOB_PRIO=0 CONFIG_BLUETOOTH_CONTROLLER_JOB_PRIO=0
CONFIG_BLUETOOTH_CONTROLLER_XTAL_ADVANCED=y CONFIG_BLUETOOTH_CONTROLLER_XTAL_ADVANCED=y
CONFIG_BLUETOOTH_CONTROLLER_SCHED_ADVANCED=y CONFIG_BLUETOOTH_CONTROLLER_SCHED_ADVANCED=y
CONFIG_BLUETOOTH_CONTROLLER_TO_HOST_FC=y CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL=y
CONFIG_BLUETOOTH_PERIPHERAL=y CONFIG_BLUETOOTH_PERIPHERAL=y
CONFIG_BLUETOOTH_CENTRAL=y CONFIG_BLUETOOTH_CENTRAL=y
CONFIG_BLUETOOTH_SMP=y CONFIG_BLUETOOTH_SMP=y