Skip to content

Bluetooth: Controller: Fix stuck forced continuation under throughput #92819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion subsys/bluetooth/controller/ll_sw/lll.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ struct lll_prepare_param {
#if defined(CONFIG_BT_CTLR_JIT_SCHEDULING)
int8_t prio;
#endif /* CONFIG_BT_CTLR_JIT_SCHEDULING */
uint8_t force;
uint8_t force:1;
uint8_t defer:1;
void *param;
};

Expand Down
2 changes: 2 additions & 0 deletions subsys/bluetooth/controller/ll_sw/lll_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ int lll_prepare(lll_is_abort_cb_t is_abort_cb, lll_abort_cb_t abort_cb,
prepare_param->prio = prio;
#endif /* CONFIG_BT_CTLR_JIT_SCHEDULING */

prepare_param->defer = 0U;

err = lll_prepare_resolve(is_abort_cb, abort_cb, prepare_cb, prepare_param, 0U, 0U);

return err;
Expand Down
6 changes: 5 additions & 1 deletion subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,8 @@ void lll_isr_early_abort(void *param)
{
int err;

radio_status_reset();

radio_isr_set(isr_race, param);
if (!radio_is_idle()) {
radio_disable();
Expand Down Expand Up @@ -1316,7 +1318,9 @@ static void preempt(void *param)
/* Returns -EBUSY when same curr and next state/role, do not
* abort same curr and next event.
*/
if (err != -EBUSY) {
if (err == -EBUSY) {
ready->prepare_param.defer = 1U;
} else {
/* Let preemptor LLL know about the cancelled prepare */
ready->is_aborted = 1;
ready->abort_cb(&ready->prepare_param, ready->prepare_param.param);
Expand Down
16 changes: 14 additions & 2 deletions subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,24 @@ static int prepare_cb(struct lll_prepare_param *p)
overhead = lll_preempt_calc(ull, (TICKER_ID_CONN_BASE + lll->handle), ticks_at_event);
/* check if preempt to start has changed */
if (overhead) {
LL_ASSERT_OVERHEAD(overhead);
int err;

if (p->defer == 1U) {
/* We accept the overhead and abort the event; previous event has decided to
* continue and has deferred this event beyond the real time threshold to
* have the radio prepared for this event.
*/
err = 0;
} else {
LL_ASSERT_OVERHEAD(overhead);

err = -ECANCELED;
}

radio_isr_set(lll_isr_abort, lll);
radio_disable();

return -ECANCELED;
return err;
}
#endif /* !CONFIG_BT_CTLR_XTAL_ADVANCED */

Expand Down
54 changes: 38 additions & 16 deletions subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ static uint8_t crc_valid;
static uint8_t is_aborted;
static uint16_t tx_cnt;
static uint16_t trx_cnt;
static uint8_t trx_busy_iteration;

#if defined(CONFIG_BT_CTLR_LE_ENC)
static uint8_t mic_state;
Expand Down Expand Up @@ -153,27 +154,38 @@ void lll_conn_prepare_reset(void)
crc_valid = 0U;
crc_expire = 0U;
is_aborted = 0U;
trx_busy_iteration = 0U;

#if defined(CONFIG_BT_CTLR_LE_ENC)
mic_state = LLL_CONN_MIC_NONE;
#endif /* CONFIG_BT_CTLR_LE_ENC */
}

#if defined(CONFIG_BT_CENTRAL)
/* Number of times central event being aborted by same event instance be skipped */
/* FIXME: Increasing this causes event pipeline overflow assertion, add LLL implementation to
* gracefully abort the deferred next event when -EBUSY is returned in this is_abort_cb
* interface.
*/
#define CENTRAL_TRX_BUSY_ITERATION_MAX 1

int lll_conn_central_is_abort_cb(void *next, void *curr,
lll_prepare_cb_t *resume_cb)
{
struct lll_conn *lll = curr;

/* Do not abort if near supervision timeout */
if (lll->forced) {
return 0;
}
if (next != curr) {
/* Do not be aborted by a different event if near supervision timeout */
if ((lll->forced == 1U) && (trx_cnt < 1U)) {
return 0;
}

/* Do not be aborted by same event if a single central trx has not been
* exchanged.
*/
if ((next == curr) && (trx_cnt < 1U)) {
} else if ((trx_cnt < 1U) && (trx_busy_iteration < CENTRAL_TRX_BUSY_ITERATION_MAX)) {
trx_busy_iteration++;

/* Do not be aborted by same event if a single central's Rx has not completed.
* Cases where single trx duration can be greater than connection interval.
*/
return -EBUSY;
}

Expand All @@ -182,20 +194,30 @@ int lll_conn_central_is_abort_cb(void *next, void *curr,
#endif /* CONFIG_BT_CENTRAL */

#if defined(CONFIG_BT_PERIPHERAL)
/* Number of times peripheral event being aborted by same event instance be skipped */
/* FIXME: Increasing this causes event pipeline overflow assertion, add LLL implementation to
* gracefully abort the deferred next event when -EBUSY is returned in this is_abort_cb
* interface.
*/
#define PERIPHERAL_TRX_BUSY_ITERATION_MAX 1

int lll_conn_peripheral_is_abort_cb(void *next, void *curr,
lll_prepare_cb_t *resume_cb)
{
struct lll_conn *lll = curr;

/* Do not abort if near supervision timeout */
if (lll->forced) {
return 0;
}
if (next != curr) {
/* Do not be aborted by a different event if near supervision timeout */
if ((lll->forced == 1U) && (tx_cnt < 1U)) {
return 0;
}

/* Do not be aborted by same event if a single peripheral trx has not
* been exchanged.
*/
if ((next == curr) && (tx_cnt < 1U)) {
} else if ((tx_cnt < 1U) && (trx_busy_iteration < PERIPHERAL_TRX_BUSY_ITERATION_MAX)) {
trx_busy_iteration++;

/* Do not be aborted by same event if a single peripheral's Tx has not completed.
* Cases where single trx duration can be greater than connection interval.
*/
return -EBUSY;
}

Expand Down
16 changes: 14 additions & 2 deletions subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,24 @@ static int prepare_cb(struct lll_prepare_param *p)
overhead = lll_preempt_calc(ull, (TICKER_ID_CONN_BASE + lll->handle), ticks_at_event);
/* check if preempt to start has changed */
if (overhead) {
LL_ASSERT_OVERHEAD(overhead);
int err;

if (p->defer == 1U) {
/* We accept the overhead and abort the event; previous event has decided to
* continue and has deferred this event beyond the real time threshold to
* have the radio prepared for this event.
*/
err = 0;
} else {
LL_ASSERT_OVERHEAD(overhead);

err = -ECANCELED;
}

radio_isr_set(lll_isr_abort, lll);
radio_disable();

return -ECANCELED;
return err;
}
#endif /* CONFIG_BT_CTLR_XTAL_ADVANCED */

Expand Down