From 1fcb0d0b5e3f268cd9082a317908e6c7874fd5e6 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Sun, 6 Sep 2020 14:07:36 +0530 Subject: [PATCH] Bluetooth: controller: Add force MD bit feature Add force Md bit feature wherein connection events can be extended to match the rate at which applications provide new Tx data. Fixes #27981. Signed-off-by: Vinayak Kariappa Chettimada --- .../bluetooth/controller/Kconfig.ll_sw_split | 12 ++++++ .../controller/ll_sw/nordic/lll/lll_conn.c | 42 ++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/controller/Kconfig.ll_sw_split b/subsys/bluetooth/controller/Kconfig.ll_sw_split index 9fbf1ebbb56..fe34f87ebbc 100644 --- a/subsys/bluetooth/controller/Kconfig.ll_sw_split +++ b/subsys/bluetooth/controller/Kconfig.ll_sw_split @@ -385,6 +385,18 @@ config BT_CTLR_TX_RETRY_DISABLE would happen in the next connection event instead of repeated retries in the current connection event. +config BT_CTLR_FORCE_MD_COUNT + int "Forced MD bit count" + range 0 255 + default 0 + help + No. of times to force MD bit to be set in Tx PDU after a successful + transmission of non-empty PDU. + + This will prolong the connection event to from being closed in cases + where applications want to send data in same connection event but are + slow in providing new Tx data. + config BT_CTLR_CONN_RSSI_EVENT bool "Connection RSSI event" depends on BT_CTLR_CONN_RSSI diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c index a7a4d53670b..9c42ff41a08 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c @@ -51,6 +51,11 @@ static uint16_t trx_cnt; static uint8_t mic_state; #endif /* CONFIG_BT_CTLR_LE_ENC */ +#if defined(CONFIG_BT_CTLR_FORCE_MD_COUNT) && \ + (CONFIG_BT_CTLR_FORCE_MD_COUNT > 0) +static uint8_t force_md_cnt; +#endif /* CONFIG_BT_CTLR_FORCE_MD_COUNT */ + int lll_conn_init(void) { int err; @@ -74,6 +79,11 @@ int lll_conn_reset(void) return err; } +#if defined(CONFIG_BT_CTLR_FORCE_MD_COUNT) && \ + (CONFIG_BT_CTLR_FORCE_MD_COUNT > 0) + force_md_cnt = 0U; +#endif /* CONFIG_BT_CTLR_FORCE_MD_COUNT */ + return 0; } @@ -355,6 +365,13 @@ lll_conn_isr_rx_exit: #if defined(CONFIG_BT_CTLR_PROFILE_ISR) lll_prof_send(); #endif /* CONFIG_BT_CTLR_PROFILE_ISR */ + +#if defined(CONFIG_BT_CTLR_FORCE_MD_COUNT) && \ + (CONFIG_BT_CTLR_FORCE_MD_COUNT > 0) + if (force_md_cnt && crc_ok) { + force_md_cnt--; + } +#endif /* CONFIG_BT_CTLR_FORCE_MD_COUNT */ } void lll_conn_isr_tx(void *param) @@ -519,7 +536,15 @@ void lll_conn_pdu_tx_prep(struct lll_conn *lll, struct pdu_data **pdu_data_tx) if (link) { p->md = 1U; } else { - p->md = 0U; +#if defined(CONFIG_BT_CTLR_FORCE_MD_COUNT) && \ + (CONFIG_BT_CTLR_FORCE_MD_COUNT > 0) + if (force_md_cnt) { + p->md = 1U; + } else +#endif /* CONFIG_BT_CTLR_FORCE_MD_COUNT */ + { + p->md = 0U; + } } } else { uint16_t max_tx_octets; @@ -544,7 +569,15 @@ void lll_conn_pdu_tx_prep(struct lll_conn *lll, struct pdu_data **pdu_data_tx) } else if (link->next != lll->memq_tx.tail) { p->md = 1U; } else { - p->md = 0U; +#if defined(CONFIG_BT_CTLR_FORCE_MD_COUNT) && \ + (CONFIG_BT_CTLR_FORCE_MD_COUNT > 0) + if (force_md_cnt) { + p->md = 1U; + } else +#endif /* CONFIG_BT_CTLR_FORCE_MD_COUNT */ + { + p->md = 0U; + } } p->rfu = 0U; @@ -700,6 +733,11 @@ static inline int isr_rx_pdu(struct lll_conn *lll, struct pdu_data *pdu_data_rx, tx->next = link; *tx_release = tx; + +#if defined(CONFIG_BT_CTLR_FORCE_MD_COUNT) && \ + (CONFIG_BT_CTLR_FORCE_MD_COUNT > 0) + force_md_cnt = CONFIG_BT_CTLR_FORCE_MD_COUNT; +#endif /* CONFIG_BT_CTLR_FORCE_MD_COUNT */ } if (IS_ENABLED(CONFIG_BT_CENTRAL) && !lll->role) {