Skip to content

Commit a178aa9

Browse files
cvinayakcarlescufi
authored andcommitted
Bluetooth: Controller: Review rework flush timeout support
Review rework changed related to flush timeout support. Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent 27c92fe commit a178aa9

File tree

9 files changed

+183
-130
lines changed

9 files changed

+183
-130
lines changed

subsys/bluetooth/controller/hci/hci.c

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5762,6 +5762,18 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt)
57625762
/* Catch up local pkt_seq_num with internal pkt_seq_num */
57635763
event_count = cis->lll.event_count;
57645764
pkt_seq_num = event_count + 1U;
5765+
/* If pb_flag is BT_ISO_START (0b00) or BT_ISO_SINGLE (0b10)
5766+
* then we simply check that the pb_flag is an even value, and
5767+
* then pkt_seq_num is a future sequence number value compare
5768+
* to last recorded number in cis->pkt_seq_num.
5769+
*
5770+
* When (pkt_seq_num - stream->pkt_seq_num) is negative then
5771+
* BIT64(39) will be set (2's compliment value). The diff value
5772+
* less than or equal to BIT64_MASK(38) means the diff value is
5773+
* positive and hence pkt_seq_num is greater than
5774+
* stream->pkt_seq_num. This calculation is valid for when value
5775+
* rollover too.
5776+
*/
57655777
if (!(pb_flag & 0x01) &&
57665778
(((pkt_seq_num - cis->pkt_seq_num) &
57675779
BIT64_MASK(39)) <= BIT64_MASK(38))) {
@@ -5770,12 +5782,17 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt)
57705782
pkt_seq_num = cis->pkt_seq_num;
57715783
}
57725784

5773-
/* Pre-increment, for next ISO data packet seq num comparison */
5785+
/* Pre-increment, when pg_flag is BT_ISO_SINGLE (0b10) or
5786+
* BT_ISO_END (0b11) then we simple check if pb_flag has bit 1
5787+
* is set, for next ISO data packet seq num comparison.
5788+
*/
57745789
if (pb_flag & 0x10) {
57755790
cis->pkt_seq_num++;
57765791
}
57775792

5778-
/* Target next event to avoid overlapping with current event */
5793+
/* Target next ISO event to avoid overlapping with, if any,
5794+
* current ISO event
5795+
*/
57795796
pkt_seq_num++;
57805797
sdu_frag_tx.target_event = pkt_seq_num;
57815798
sdu_frag_tx.grp_ref_point =
@@ -5817,7 +5834,7 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt)
58175834
#endif /* !CONFIG_BT_CTLR_ISOAL_PSN_IGNORE */
58185835

58195836
/* Get controller's input data path for CIS */
5820-
hdr = &(cis->hdr);
5837+
hdr = &cis->hdr;
58215838
dp_in = hdr->datapath_in;
58225839
if (!dp_in || dp_in->path_id != BT_HCI_DATAPATH_ID_HCI) {
58235840
LOG_ERR("Input data path not set for HCI");
@@ -5884,6 +5901,18 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt)
58845901
/* Catch up local pkt_seq_num with internal pkt_seq_num */
58855902
event_count = lll_iso->payload_count / lll_iso->bn;
58865903
pkt_seq_num = event_count;
5904+
/* If pb_flag is BT_ISO_START (0b00) or BT_ISO_SINGLE (0b10)
5905+
* then we simply check that the pb_flag is an even value, and
5906+
* then pkt_seq_num is a future sequence number value compare
5907+
* to last recorded number in cis->pkt_seq_num.
5908+
*
5909+
* When (pkt_seq_num - stream->pkt_seq_num) is negative then
5910+
* BIT64(39) will be set (2's compliment value). The diff value
5911+
* less than or equal to BIT64_MASK(38) means the diff value is
5912+
* positive and hence pkt_seq_num is greater than
5913+
* stream->pkt_seq_num. This calculation is valid for when value
5914+
* rollover too.
5915+
*/
58875916
if (!(pb_flag & 0x01) &&
58885917
(((pkt_seq_num - stream->pkt_seq_num) &
58895918
BIT64_MASK(39)) <= BIT64_MASK(38))) {
@@ -5892,12 +5921,17 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt)
58925921
pkt_seq_num = stream->pkt_seq_num;
58935922
}
58945923

5895-
/* Pre-increment, for next ISO data packet seq num comparison */
5924+
/* Pre-increment, when pg_flag is BT_ISO_SINGLE (0b10) or
5925+
* BT_ISO_END (0b11) then we simple check if pb_flag has bit 1
5926+
* is set, for next ISO data packet seq num comparison.
5927+
*/
58965928
if (pb_flag & 0x10) {
58975929
stream->pkt_seq_num++;
58985930
}
58995931

5900-
/* Target next event to avoid overlapping with current event */
5932+
/* Target next ISO event to avoid overlapping with, if any,
5933+
* current ISO event
5934+
*/
59015935
/* FIXME: Implement ISO Tx ack generation early in done compared
59025936
* to currently only in prepare. I.e. to ensure upper
59035937
* layer has the number of completed packet before the

subsys/bluetooth/controller/ll_sw/lll_conn_iso.h

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ struct lll_conn_iso_stream_rxtx {
1515
uint64_t ft:8; /* Flush timeout (FT) */
1616
uint64_t bn:4; /* Burst number (BN) */
1717
uint64_t phy:3; /* PHY */
18-
uint64_t rfu:1;
19-
uint8_t bn_curr:4; /* Current burst number */
18+
uint64_t rfu0:1;
19+
20+
uint8_t bn_curr:4; /* Current burst number */
21+
uint8_t rfu1:4;
2022

2123
#if defined(CONFIG_BT_CTLR_LE_ENC)
2224
struct ccm ccm;
@@ -73,20 +75,26 @@ struct lll_conn_iso_group {
7375
struct lll_hdr hdr;
7476

7577
uint16_t handle; /* CIG handle (internal) */
76-
uint8_t num_cis:5; /* Number of CISes in this CIG */
77-
uint8_t role:1; /* 0: CENTRAL, 1: PERIPHERAL*/
78-
uint8_t paused:1; /* 1: CIG is paused */
7978

80-
/* ISO interval to calculate timestamp under FT > 1 */
81-
uint32_t iso_interval_us;
79+
/* Resumption information */
80+
uint16_t resume_cis; /* CIS handle to schedule at resume */
81+
82+
/* ISO group information */
83+
uint32_t num_cis:5; /* Number of CISes in this CIG */
84+
uint32_t role:1; /* 0: CENTRAL, 1: PERIPHERAL*/
85+
uint32_t paused:1; /* 1: CIG is paused */
86+
uint32_t rfu0:1;
87+
88+
/* ISO interval to calculate timestamp under FT > 1,
89+
* maximum ISO interval of 4 seconds can be represented in 22-bits.
90+
*/
91+
uint32_t iso_interval_us:22;
92+
uint32_t rfu1:2;
8293

8394
/* Accumulates LLL prepare callback latencies */
8495
uint16_t latency_prepare;
8596
uint16_t latency_event;
8697

87-
/* Resumption information */
88-
uint16_t resume_cis; /* CIS handle to schedule at resume */
89-
9098
#if defined(CONFIG_BT_CTLR_PERIPHERAL_ISO)
9199
/* Window widening. Relies on vendor specific conversion macros, e.g.
92100
* EVENT_US_FRAC_TO_TICKS().

subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static void isr_prepare_subevent(void *param);
4848
static void isr_done(void *param);
4949
static void payload_count_flush(struct lll_conn_iso_stream *cis_lll);
5050
static void payload_count_flush_or_inc_on_close(struct lll_conn_iso_stream *cis_lll);
51-
static void payload_count_lazy(struct lll_conn_iso_stream *cis_lll, uint16_t lazy);
51+
static void payload_count_lazy_update(struct lll_conn_iso_stream *cis_lll, uint16_t lazy);
5252

5353
static uint16_t next_cis_chan_remap_idx;
5454
static uint16_t next_cis_chan_prn_s;
@@ -183,7 +183,7 @@ static int prepare_cb(struct lll_prepare_param *p)
183183
se_curr = 1U;
184184

185185
/* Adjust the SN and NESN for skipped CIG events */
186-
payload_count_lazy(cis_lll, lazy);
186+
payload_count_lazy_update(cis_lll, lazy);
187187

188188
/* Start setting up of Radio h/w */
189189
radio_reset();
@@ -370,7 +370,7 @@ static int prepare_cb(struct lll_prepare_param *p)
370370
cis_lll = ull_conn_iso_lll_stream_get_by_group(cig_lll, &cis_handle);
371371
if (cis_lll && cis_lll->active) {
372372
/* Adjust sn and nesn for skipped CIG events */
373-
payload_count_lazy(cis_lll, lazy);
373+
payload_count_lazy_update(cis_lll, lazy);
374374

375375
/* Adjust sn and nesn for canceled events */
376376
if (err) {
@@ -676,11 +676,20 @@ static void isr_rx(void *param)
676676
/* No Rx */
677677
if (!trx_done ||
678678
#if defined(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS)
679+
/* Used by test code,
680+
* to skip a number of events in every 3 event count when current subevent is less than
681+
* or equal to 2 or when current subevent has completed all its NSE number of subevents.
682+
* OR
683+
* to skip a (number + 1) of events in every 3 event count when current subevent is less
684+
* than or equal to 1 or when current subevent has completed all its NSE number of
685+
* subevents.
686+
*/
679687
((((cis_lll->event_count % 3U) < CONFIG_TEST_FT_CEN_SKIP_EVENTS_COUNT) &&
680688
((se_curr > cis_lll->nse) || (se_curr <= 2U))) ||
689+
681690
(((cis_lll->event_count % 3U) < (CONFIG_TEST_FT_CEN_SKIP_EVENTS_COUNT + 1U)) &&
682691
((se_curr > cis_lll->nse) || (se_curr <= 1U)))) ||
683-
#endif
692+
#endif /* CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS */
684693
false) {
685694
payload_count_flush(cis_lll);
686695

@@ -1230,7 +1239,7 @@ static void payload_count_flush_or_inc_on_close(struct lll_conn_iso_stream *cis_
12301239
}
12311240
}
12321241

1233-
static void payload_count_lazy(struct lll_conn_iso_stream *cis_lll, uint16_t lazy)
1242+
static void payload_count_lazy_update(struct lll_conn_iso_stream *cis_lll, uint16_t lazy)
12341243
{
12351244
if (cis_lll->tx.bn) {
12361245
uint16_t tx_lazy;

subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,14 @@ static void isr_rx(void *param)
474474
/* No Rx */
475475
if (!trx_done ||
476476
#if defined(CONFIG_TEST_FT_PER_SKIP_SUBEVENTS)
477+
/* Used by test code,
478+
* to skip a number of events in every 3 event count when current subevent is less than
479+
* or equal to 2 or when current subevent has completed all its NSE number of subevents.
480+
* OR
481+
* to skip a (number + 1) of events in every 3 event count when current subevent is less
482+
* than or equal to 1 or when current subevent has completed all its NSE number of
483+
* subevents.
484+
*/
477485
((((cis_lll->event_count % 3U) < CONFIG_TEST_FT_PER_SKIP_EVENTS_COUNT) &&
478486
((se_curr > cis_lll->nse) || (se_curr <= 2U))) ||
479487
(((cis_lll->event_count % 3U) < (CONFIG_TEST_FT_PER_SKIP_EVENTS_COUNT + 1U)) &&

0 commit comments

Comments
 (0)