diff --git a/subsys/bluetooth/Kconfig b/subsys/bluetooth/Kconfig index 40404921f8e..659e458c437 100644 --- a/subsys/bluetooth/Kconfig +++ b/subsys/bluetooth/Kconfig @@ -69,6 +69,22 @@ config BLUETOOTH_MAX_CONN Maximum number of simultaneous Bluetooth connections 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 # Virtual/hidden option to make the conditions more intuitive bool diff --git a/subsys/bluetooth/controller/Kconfig b/subsys/bluetooth/controller/Kconfig index 03770378e26..7c9338e18c9 100644 --- a/subsys/bluetooth/controller/Kconfig +++ b/subsys/bluetooth/controller/Kconfig @@ -39,15 +39,6 @@ config BLUETOOTH_CONTROLLER_TO_HOST_UART_DEV_NAME to connect to an external Bluetooth Host when Zephyr is 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 prompt "Number of addresses in the scan duplicate filter" int diff --git a/subsys/bluetooth/controller/hci/hci.c b/subsys/bluetooth/controller/hci/hci.c index eeb38d91d10..648ff08741b 100644 --- a/subsys/bluetooth/controller/hci/hci.c +++ b/subsys/bluetooth/controller/hci/hci.c @@ -47,7 +47,7 @@ static s32_t dup_count; static u32_t dup_curr; #endif -#if defined(CONFIG_BLUETOOTH_CONTROLLER_TO_HOST_FC) +#if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL) s32_t hci_hbuf_total; u32_t hci_hbuf_sent; 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->status = 0x00; } -#if defined(CONFIG_BLUETOOTH_CONTROLLER_TO_HOST_FC) +#if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL) hci_hbuf_total = 0; hci_hbuf_sent = 0; hci_hbuf_acked = 0; @@ -194,7 +194,7 @@ static void reset(struct net_buf *buf, struct net_buf **evt) #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) { 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); 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): set_ctl_to_host_flow(cmd, evt); break; @@ -344,7 +344,7 @@ static void read_supported_commands(struct net_buf *buf, struct net_buf **evt) rp->commands[0] = (1 << 5); /* Set Event Mask, and Reset. */ 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 */ rp->commands[10] = (1 << 5) | (1 << 6) | (1 << 7); #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); data = (void *)net_buf_add(buf, 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) { LL_ASSERT((hci_hbuf_sent - hci_hbuf_acked) < 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) { -#if defined(CONFIG_BLUETOOTH_CONTROLLER_TO_HOST_FC) +#if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL) hbuf_signal = signal_host_buf; #endif reset(NULL, NULL); diff --git a/subsys/bluetooth/controller/hci/hci_driver.c b/subsys/bluetooth/controller/hci/hci_driver.c index 42423af219a..05b3618fb59 100644 --- a/subsys/bluetooth/controller/hci/hci_driver.c +++ b/subsys/bluetooth/controller/hci/hci_driver.c @@ -55,7 +55,7 @@ static u32_t prio_ts; static u32_t rx_ts; #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 sys_slist_t hbuf_pend; 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); 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) { 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; } -#if defined(CONFIG_BLUETOOTH_CONTROLLER_TO_HOST_FC) +#if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL) static inline struct net_buf *process_hbuf(void) { /* 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) { -#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 */ static struct k_poll_event events[2] = { 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; BT_DBG("blocking"); -#if defined(CONFIG_BLUETOOTH_CONTROLLER_TO_HOST_FC) +#if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL) int err; err = k_poll(events, 2, K_FOREVER); @@ -390,7 +390,7 @@ static int hci_driver_open(void) return err; } -#if defined(CONFIG_BLUETOOTH_CONTROLLER_TO_HOST_FC) +#if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL) hci_init(&hbuf_signal); #else hci_init(NULL); diff --git a/subsys/bluetooth/controller/hci/hci_internal.h b/subsys/bluetooth/controller/hci/hci_internal.h index eba9198b21b..48c68f240ef 100644 --- a/subsys/bluetooth/controller/hci/hci_internal.h +++ b/subsys/bluetooth/controller/hci/hci_internal.h @@ -8,7 +8,7 @@ #ifndef _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 u32_t hci_hbuf_sent; extern u32_t hci_hbuf_acked; diff --git a/subsys/bluetooth/host/Kconfig b/subsys/bluetooth/host/Kconfig index 935f9ecb77a..bf770f5fd9f 100644 --- a/subsys/bluetooth/host/Kconfig +++ b/subsys/bluetooth/host/Kconfig @@ -103,17 +103,8 @@ config BLUETOOTH_INTERNAL_STORAGE an internal default handler is used for this. 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 int "Number of incoming ACL data buffers" default 6 @@ -131,7 +122,7 @@ config BLUETOOTH_L2CAP_RX_MTU range 65 1300 if BLUETOOTH_SMP help Maximum size of each incoming L2CAP PDU. -endif # BLUETOOTH_HOST_FLOW_CONTROL +endif # BLUETOOTH_HCI_ACL_FLOW_CONTROL config BLUETOOTH_L2CAP_TX_BUF_COUNT int "Number of L2CAP TX buffers" @@ -429,10 +420,10 @@ config BLUETOOTH_RFCOMM config BLUETOOTH_RFCOMM_L2CAP_MTU int "L2CAP MTU for RFCOMM frames" 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 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 Maximum size of L2CAP PDU for RFCOMM frames. diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 0d38a00edf8..98b0d20723d 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -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, 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) { @@ -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) NET_BUF_POOL_DEFINE(acl_in_pool, CONFIG_BLUETOOTH_ACL_RX_COUNT, ACL_IN_SIZE, 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) const char *bt_addr_str(const bt_addr_t *addr) @@ -1014,7 +1014,7 @@ failed: 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) { 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); 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 */ #if defined(CONFIG_BLUETOOTH_BREDR) @@ -3070,7 +3070,7 @@ static int common_init(void) read_supported_commands_complete(rsp); net_buf_unref(rsp); -#if defined(CONFIG_BLUETOOTH_HOST_FLOW_CONTROL) +#if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL) err = set_flow_control(); if (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, "Invalid buffer type requested"); -#if defined(CONFIG_BLUETOOTH_HOST_FLOW_CONTROL) +#if defined(CONFIG_BLUETOOTH_HCI_ACL_FLOW_CONTROL) if (type == BT_BUF_EVT) { buf = net_buf_alloc(&hci_rx_pool, timeout); } else { diff --git a/subsys/bluetooth/host/l2cap.c b/subsys/bluetooth/host/l2cap.c index b272187e4a9..0e4f5e8d8be 100644 --- a/subsys/bluetooth/host/l2cap.c +++ b/subsys/bluetooth/host/l2cap.c @@ -28,7 +28,7 @@ #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) #else #define L2CAP_LE_MAX_CREDITS (CONFIG_BLUETOOTH_RX_BUF_COUNT - 1) diff --git a/subsys/bluetooth/host/l2cap_internal.h b/subsys/bluetooth/host/l2cap_internal.h index 5474a4678ab..3ba2aa2e4af 100644 --- a/subsys/bluetooth/host/l2cap_internal.h +++ b/subsys/bluetooth/host/l2cap_internal.h @@ -192,7 +192,7 @@ struct bt_l2cap_le_credits { #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 #else #define BT_L2CAP_RX_MTU (CONFIG_BLUETOOTH_RX_BUF_LEN - \ diff --git a/subsys/bluetooth/host/rfcomm.c b/subsys/bluetooth/host/rfcomm.c index c0ace8e1de3..722c50301d8 100644 --- a/subsys/bluetooth/host/rfcomm.c +++ b/subsys/bluetooth/host/rfcomm.c @@ -34,7 +34,7 @@ #define RFCOMM_MIN_MTU BT_RFCOMM_SIG_MIN_MTU #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) #else #define RFCOMM_MAX_CREDITS (CONFIG_BLUETOOTH_RX_BUF_COUNT - 1) diff --git a/tests/bluetooth/init/prj_controller.conf b/tests/bluetooth/init/prj_controller.conf index 31da4392155..29593e230f4 100644 --- a/tests/bluetooth/init/prj_controller.conf +++ b/tests/bluetooth/init/prj_controller.conf @@ -4,7 +4,7 @@ CONFIG_BLUETOOTH_CONTROLLER_WORKER_PRIO=0 CONFIG_BLUETOOTH_CONTROLLER_JOB_PRIO=0 CONFIG_BLUETOOTH_CONTROLLER_XTAL_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_CENTRAL=y CONFIG_BLUETOOTH_SMP=y