From 25be47e7a4d3c3679631ac5d350a47b9ecd52d22 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Fri, 8 Jan 2021 11:27:54 +0100 Subject: [PATCH] Bluetooth: hci_raw: Move BT_ISO to common Kconfig and fix ISO buffers This commit moves the BT_ISO to a common (host and controller) Kconfig and fixes the ISO buffers in hci_raw.c Signed-off-by: Emil Gydesen --- subsys/bluetooth/Kconfig | 58 ++++++++++++++++++++ subsys/bluetooth/host/Kconfig | 6 ++ subsys/bluetooth/host/audio/Kconfig | 64 ---------------------- subsys/bluetooth/host/audio/iso.c | 18 +++--- subsys/bluetooth/host/audio/iso_internal.h | 8 +-- subsys/bluetooth/host/hci_core.c | 2 +- subsys/bluetooth/host/hci_raw.c | 15 ++--- 7 files changed, 86 insertions(+), 85 deletions(-) diff --git a/subsys/bluetooth/Kconfig b/subsys/bluetooth/Kconfig index 6f41d6f44f2..4cac0607612 100644 --- a/subsys/bluetooth/Kconfig +++ b/subsys/bluetooth/Kconfig @@ -222,6 +222,64 @@ config BT_DATA_LEN_UPDATE Enable support for Bluetooth v4.2 LE Data Length Update procedure. endif # BT_CONN + +config BT_ISO + bool "Bluetooth Isochronous Channel Support [EXPERIMENTAL]" + help + Select this to enable Isochronous Channel support. + +if BT_ISO + +config BT_ISO_MAX_CHAN + int "Maximum number of simultaneous ISO channels" + depends on BT_ISO + default BT_MAX_CONN + range 1 64 + help + Maximum number of simultaneous Bluetooth isochronous channels + supported. + +config BT_ISO_TX_BUF_COUNT + int "Number of Isochronous TX buffers" + default 1 + range 1 255 + help + Number of buffers available for outgoing Isochronous channel SDUs. + +config BT_ISO_TX_FRAG_COUNT + int "Number of ISO TX fragment buffers" + default 2 + range 0 255 + help + Number of buffers available for fragments of TX buffers. Warning: + setting this to 0 means that the application must ensure that + queued TX buffers never need to be fragmented, i.e. that the + controller's buffer size is large enough. If this is not ensured, + and there are no dedicated fragment buffers, a deadlock may occur. + In most cases the default value of 2 is a safe bet. + +config BT_ISO_TX_MTU + int "Maximum supported MTU for Isochronous TX buffers" + default 251 + range 23 4095 + help + Maximum MTU for Isochronous channels TX buffers. + +config BT_ISO_RX_BUF_COUNT + int "Number of Isochronous RX buffers" + default 1 + range 1 255 + help + Number of buffers available for incoming Isochronous channel SDUs. + +config BT_ISO_RX_MTU + int "Maximum supported MTU for Isochronous RX buffers" + default 251 + range 23 4095 + help + Maximum MTU for Isochronous channels RX buffers. +endif # BT_ISO + # Workaround for not being able to have commas in macro arguments DT_CHOSEN_Z_BT_C2H_UART := zephyr,bt-c2h-uart diff --git a/subsys/bluetooth/host/Kconfig b/subsys/bluetooth/host/Kconfig index cc072b295a6..cd400d4c01f 100644 --- a/subsys/bluetooth/host/Kconfig +++ b/subsys/bluetooth/host/Kconfig @@ -668,6 +668,12 @@ config BT_DEBUG_CONN This option enables debug support for Bluetooth connection handling. +config BT_DEBUG_ISO + bool "ISO channel debug" + help + Use this option to enable ISO channels debug logs for the + Bluetooth Audio functionality. + config BT_DEBUG_KEYS bool "Bluetooth security keys debug" depends on BT_HCI_HOST diff --git a/subsys/bluetooth/host/audio/Kconfig b/subsys/bluetooth/host/audio/Kconfig index a1f710def6a..277bf5f2af6 100644 --- a/subsys/bluetooth/host/audio/Kconfig +++ b/subsys/bluetooth/host/audio/Kconfig @@ -17,9 +17,6 @@ menuconfig BT_AUDIO if BT_AUDIO -config BT_ISO - bool - if BT_CONN config BT_AUDIO_UNICAST @@ -35,58 +32,6 @@ config BT_AUDIO_UNICAST This option enables support for Bluetooth Unicast Audio using Isochronous channels. -if BT_AUDIO_UNICAST - -config BT_MAX_ISO_CONN - int "Maximum number of simultaneous ISO connections" - depends on BT_ISO - default BT_MAX_CONN - range 1 64 - help - Maximum number of simultaneous Bluetooth isochronous connections - supported. - -config BT_ISO_TX_BUF_COUNT - int "Numer of Isochronous TX buffers" - default 1 - range 1 255 - help - Number of buffers available for outgoing Isochronous channel packets. - -config BT_ISO_TX_FRAG_COUNT - int "Number of ISO TX fragment buffers" - default 2 - range 0 255 - help - Number of buffers available for fragments of TX buffers. Warning: - setting this to 0 means that the application must ensure that - queued TX buffers never need to be fragmented, i.e. that the - controller's buffer size is large enough. If this is not ensured, - and there are no dedicated fragment buffers, a deadlock may occur. - In most cases the default value of 2 is a safe bet. - -config BT_ISO_TX_MTU - int "Maximum supported MTU for Isochronous TX buffers" - default 251 - range 23 2000 - help - Maximum MTU for Isochronous channels TX buffers. - -config BT_ISO_RX_BUF_COUNT - int "Numer of Isochronous RX buffers" - default 1 - range 1 255 - help - Number of buffers available for incoming Isochronous channel packets. - -config BT_ISO_RX_MTU - int "Maximum supported MTU for Isochronous RX buffers" - default 251 - range 23 2000 - help - Maximum MTU for Isochronous channels RX buffers. - -endif # BT_AUDIO_UNICAST endif # BT_CONN config BT_AUDIO_DEBUG @@ -96,13 +41,4 @@ config BT_AUDIO_DEBUG Use this option to enable debug logs for the Bluetooth Audio functionality. -if BT_AUDIO_DEBUG - -config BT_AUDIO_DEBUG_ISO - bool "ISO channel debug" - help - Use this option to enable ISO channels debug logs for the - Bluetooth Audio functionality. - -endif # BT_AUDIO_DEBUG endif # BT_AUDIO diff --git a/subsys/bluetooth/host/audio/iso.c b/subsys/bluetooth/host/audio/iso.c index 71dd52a757a..31a3aeb7543 100644 --- a/subsys/bluetooth/host/audio/iso.c +++ b/subsys/bluetooth/host/audio/iso.c @@ -18,7 +18,7 @@ #include "host/conn_internal.h" #include "iso_internal.h" -#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_AUDIO_DEBUG_ISO) +#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_ISO) #define LOG_MODULE_NAME bt_iso #include "common/log.h" @@ -34,7 +34,7 @@ NET_BUF_POOL_FIXED_DEFINE(iso_frag_pool, CONFIG_BT_ISO_TX_FRAG_COUNT, /* TODO: Allow more than one server? */ static struct bt_iso_server *iso_server; -struct bt_conn iso_conns[CONFIG_BT_MAX_ISO_CONN]; +struct bt_conn iso_conns[CONFIG_BT_ISO_MAX_CHAN]; struct bt_iso_data_path { @@ -257,7 +257,7 @@ void bt_iso_cleanup(struct bt_conn *conn) conn->iso.acl = NULL; /* Check if conn is last of CIG */ - for (i = 0; i < CONFIG_BT_MAX_ISO_CONN; i++) { + for (i = 0; i < CONFIG_BT_ISO_MAX_CHAN; i++) { if (conn == &iso_conns[i]) { continue; } @@ -268,7 +268,7 @@ void bt_iso_cleanup(struct bt_conn *conn) } } - if (i == CONFIG_BT_MAX_ISO_CONN) { + if (i == CONFIG_BT_ISO_MAX_CHAN) { hci_le_remove_cig(conn->iso.cig_id); } @@ -417,7 +417,7 @@ int bt_conn_bind_iso(struct bt_iso_create_param *param) return -ENOTSUP; } - if (!param->num_conns || param->num_conns > CONFIG_BT_MAX_ISO_CONN) { + if (!param->num_conns || param->num_conns > CONFIG_BT_ISO_MAX_CHAN) { return -EINVAL; } @@ -520,7 +520,7 @@ int bt_conn_connect_iso(struct bt_conn **conns, uint8_t num_conns) return -ENOTSUP; } - if (num_conns > CONFIG_BT_MAX_ISO_CONN) { + if (num_conns > CONFIG_BT_ISO_MAX_CHAN) { return -EINVAL; } @@ -783,7 +783,7 @@ int bt_iso_server_register(struct bt_iso_server *server) return 0; } -#if defined(CONFIG_BT_AUDIO_DEBUG_ISO) +#if defined(CONFIG_BT_DEBUG_ISO) const char *bt_iso_chan_state_str(uint8_t state) { switch (state) { @@ -847,7 +847,7 @@ void bt_iso_chan_set_state(struct bt_iso_chan *chan, uint8_t state) { chan->state = state; } -#endif /* CONFIG_BT_AUDIO_DEBUG_ISO */ +#endif /* CONFIG_BT_DEBUG_ISO */ void bt_iso_chan_remove(struct bt_conn *conn, struct bt_iso_chan *chan) { @@ -898,7 +898,7 @@ int bt_iso_chan_bind(struct bt_conn **conns, uint8_t num_conns, int bt_iso_chan_connect(struct bt_iso_chan **chans, uint8_t num_chans) { - struct bt_conn *conns[CONFIG_BT_MAX_ISO_CONN]; + struct bt_conn *conns[CONFIG_BT_ISO_MAX_CHAN]; int i, err; __ASSERT_NO_MSG(chans); diff --git a/subsys/bluetooth/host/audio/iso_internal.h b/subsys/bluetooth/host/audio/iso_internal.h index 4c1d22ec3f7..f98be6c0fc0 100644 --- a/subsys/bluetooth/host/audio/iso_internal.h +++ b/subsys/bluetooth/host/audio/iso_internal.h @@ -28,8 +28,8 @@ struct iso_data { #define iso(buf) ((struct iso_data *)net_buf_user_data(buf)) -#if defined(CONFIG_BT_MAX_ISO_CONN) -extern struct bt_conn iso_conns[CONFIG_BT_MAX_ISO_CONN]; +#if defined(CONFIG_BT_ISO_MAX_CHAN) +extern struct bt_conn iso_conns[CONFIG_BT_ISO_MAX_CHAN]; #endif /* Process ISO buffer */ @@ -97,14 +97,14 @@ struct net_buf *bt_iso_create_frag_timeout(size_t reserve, k_timeout_t timeout); bt_iso_create_frag_timeout(_reserve, K_FOREVER) #endif -#if defined(CONFIG_BT_AUDIO_DEBUG_ISO) +#if defined(CONFIG_BT_DEBUG_ISO) void bt_iso_chan_set_state_debug(struct bt_iso_chan *chan, uint8_t state, const char *func, int line); #define bt_iso_chan_set_state(_chan, _state) \ bt_iso_chan_set_state_debug(_chan, _state, __func__, __LINE__) #else void bt_iso_chan_set_state(struct bt_iso_chan *chan, uint8_t state); -#endif /* CONFIG_BT_AUDIO_DEBUG_ISO */ +#endif /* CONFIG_BT_DEBUG_ISO */ /* Process incoming data for a connection */ void bt_iso_recv(struct bt_conn *conn, struct net_buf *buf, uint8_t flags); diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 8a44507fc28..7c9ea433c7a 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -5206,7 +5206,7 @@ static void process_events(struct k_poll_event *ev, int count) #if defined(CONFIG_BT_CONN) #if defined(CONFIG_BT_ISO) /* command FIFO + conn_change signal + MAX_CONN + MAX_ISO_CONN */ -#define EV_COUNT (2 + CONFIG_BT_MAX_CONN + CONFIG_BT_MAX_ISO_CONN) +#define EV_COUNT (2 + CONFIG_BT_MAX_CONN + CONFIG_BT_ISO_MAX_CHAN) #else /* command FIFO + conn_change signal + MAX_CONN */ #define EV_COUNT (2 + CONFIG_BT_MAX_CONN) diff --git a/subsys/bluetooth/host/hci_raw.c b/subsys/bluetooth/host/hci_raw.c index c8b433e7dcf..0be6db2638c 100644 --- a/subsys/bluetooth/host/hci_raw.c +++ b/subsys/bluetooth/host/hci_raw.c @@ -43,9 +43,9 @@ NET_BUF_POOL_FIXED_DEFINE(hci_cmd_pool, CONFIG_BT_HCI_CMD_COUNT, NET_BUF_POOL_FIXED_DEFINE(hci_acl_pool, BT_HCI_ACL_COUNT, BT_BUF_ACL_SIZE, NULL); #if defined(CONFIG_BT_ISO) -NET_BUF_POOL_FIXED_DEFINE(hci_iso_pool, BT_ISO_TX_BUF_COUNT, - BT_ISO_TX_MTU, NULL); -#endif +NET_BUF_POOL_FIXED_DEFINE(hci_iso_pool, CONFIG_BT_ISO_TX_BUF_COUNT, + CONFIG_BT_ISO_TX_MTU, NULL); +#endif /* CONFIG_BT_ISO */ struct bt_dev_raw bt_dev; struct bt_hci_raw_cmd_ext *cmd_ext; @@ -78,9 +78,10 @@ struct net_buf *bt_buf_get_rx(enum bt_buf_type type, k_timeout_t timeout) switch (type) { case BT_BUF_EVT: case BT_BUF_ACL_IN: + case BT_BUF_ISO_IN: break; default: - BT_ERR("Invalid type: %u", type); + BT_ERR("Invalid rx type: %u", type); return NULL; } @@ -112,7 +113,7 @@ struct net_buf *bt_buf_get_tx(enum bt_buf_type type, k_timeout_t timeout, case BT_BUF_ISO_OUT: pool = &hci_iso_pool; break; -#endif +#endif /* CONFIG_BT_ISO */ case BT_BUF_H4: if (IS_ENABLED(CONFIG_BT_HCI_RAW_H4) && raw_mode == BT_HCI_RAW_MODE_H4) { @@ -130,7 +131,7 @@ struct net_buf *bt_buf_get_tx(enum bt_buf_type type, k_timeout_t timeout, type = BT_BUF_ISO_OUT; pool = &hci_iso_pool; break; -#endif +#endif /* CONFIG_BT_ISO */ default: LOG_ERR("Unknown H4 type %u", type); return NULL; @@ -143,7 +144,7 @@ struct net_buf *bt_buf_get_tx(enum bt_buf_type type, k_timeout_t timeout, } __fallthrough; default: - BT_ERR("Invalid type: %u", type); + BT_ERR("Invalid tx type: %u", type); return NULL; }