1 /*
2 * Copyright (c) 2018-2021 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #if defined(CONFIG_BT_CTLR_RX_PDU_META)
8 #include "lll_meta.h"
9 #endif /* CONFIG_BT_CTLR_RX_PDU_META */
10
11 #define TICKER_INSTANCE_ID_CTLR 0
12 #define TICKER_USER_ID_LLL MAYFLY_CALL_ID_0
13 #define TICKER_USER_ID_ULL_HIGH MAYFLY_CALL_ID_1
14 #define TICKER_USER_ID_ULL_LOW MAYFLY_CALL_ID_2
15 #define TICKER_USER_ID_THREAD MAYFLY_CALL_ID_PROGRAM
16
17 #define EVENT_PIPELINE_MAX 7
18 #if defined(CONFIG_BT_CTLR_LOW_LAT_ULL)
19 #define EVENT_DONE_LINK_CNT 0
20 #else
21 #define EVENT_DONE_LINK_CNT 1
22 #endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */
23
24 #define ADV_INT_UNIT_US 625U
25 #define SCAN_INT_UNIT_US 625U
26 #define CONN_INT_UNIT_US 1250U
27 #define ISO_INT_UNIT_US CONN_INT_UNIT_US
28 #define PERIODIC_INT_UNIT_US 1250U
29
30 /* Timeout for Host to accept/reject cis create request */
31 /* See BTCore5.3, 4.E.6.7 - Default value 0x1f40 * 625us */
32 #define DEFAULT_CONNECTION_ACCEPT_TIMEOUT_US (5 * USEC_PER_SEC)
33
34 /* Intervals after which connection or sync establishment is considered lost */
35 #define CONN_ESTAB_COUNTDOWN 6U
36
37 #if defined(CONFIG_BT_CTLR_XTAL_ADVANCED)
38 #define XON_BITMASK BIT(31) /* XTAL has been retained from previous prepare */
39 #endif /* CONFIG_BT_CTLR_XTAL_ADVANCED */
40
41 #if defined(CONFIG_BT_BROADCASTER)
42 #if defined(CONFIG_BT_CTLR_ADV_SET)
43 #define BT_CTLR_ADV_SET CONFIG_BT_CTLR_ADV_SET
44 #else /* CONFIG_BT_CTLR_ADV_SET */
45 #define BT_CTLR_ADV_SET 1
46 #endif /* CONFIG_BT_CTLR_ADV_SET */
47 #else /* !CONFIG_BT_BROADCASTER */
48 #define BT_CTLR_ADV_SET 0
49 #endif /* !CONFIG_BT_BROADCASTER */
50
51 #if defined(CONFIG_BT_OBSERVER)
52 #if defined(CONFIG_BT_CTLR_ADV_EXT)
53 #if defined(CONFIG_BT_CTLR_PHY_CODED)
54 #define BT_CTLR_SCAN_SET 2
55 #else /* !CONFIG_BT_CTLR_PHY_CODED */
56 #define BT_CTLR_SCAN_SET 1
57 #endif /* !CONFIG_BT_CTLR_PHY_CODED */
58 #else /* !CONFIG_BT_CTLR_ADV_EXT */
59 #define BT_CTLR_SCAN_SET 1
60 #endif /* !CONFIG_BT_CTLR_ADV_EXT */
61 #else /* !CONFIG_BT_OBSERVER */
62 #define BT_CTLR_SCAN_SET 0
63 #endif /* !CONFIG_BT_OBSERVER */
64
65 enum {
66 TICKER_ID_LLL_PREEMPT = 0,
67
68 #if defined(CONFIG_BT_BROADCASTER)
69 TICKER_ID_ADV_STOP,
70 TICKER_ID_ADV_BASE,
71 #if defined(CONFIG_BT_CTLR_ADV_EXT) || defined(CONFIG_BT_HCI_MESH_EXT)
72 TICKER_ID_ADV_LAST = ((TICKER_ID_ADV_BASE) + (BT_CTLR_ADV_SET) - 1),
73 #if defined(CONFIG_BT_CTLR_ADV_EXT)
74 #if (CONFIG_BT_CTLR_ADV_AUX_SET > 0)
75 TICKER_ID_ADV_AUX_BASE,
76 TICKER_ID_ADV_AUX_LAST = ((TICKER_ID_ADV_AUX_BASE) +
77 (CONFIG_BT_CTLR_ADV_AUX_SET) - 1),
78 #if defined(CONFIG_BT_CTLR_ADV_PERIODIC)
79 TICKER_ID_ADV_SYNC_BASE,
80 TICKER_ID_ADV_SYNC_LAST = ((TICKER_ID_ADV_SYNC_BASE) +
81 (CONFIG_BT_CTLR_ADV_SYNC_SET) - 1),
82 #if defined(CONFIG_BT_CTLR_ADV_ISO)
83 TICKER_ID_ADV_ISO_BASE,
84 TICKER_ID_ADV_ISO_LAST = ((TICKER_ID_ADV_ISO_BASE) +
85 (CONFIG_BT_CTLR_ADV_ISO_SET) - 1),
86 #endif /* CONFIG_BT_CTLR_ADV_ISO */
87 #endif /* CONFIG_BT_CTLR_ADV_PERIODIC */
88 #endif /* CONFIG_BT_CTLR_ADV_AUX_SET > 0 */
89 #endif /* CONFIG_BT_CTLR_ADV_EXT */
90 #endif /* !CONFIG_BT_CTLR_ADV_EXT || !CONFIG_BT_HCI_MESH_EXT */
91 #endif /* CONFIG_BT_BROADCASTER */
92
93 #if defined(CONFIG_BT_OBSERVER)
94 TICKER_ID_SCAN_STOP,
95 TICKER_ID_SCAN_BASE,
96 TICKER_ID_SCAN_LAST = ((TICKER_ID_SCAN_BASE) + (BT_CTLR_SCAN_SET) - 1),
97 #if defined(CONFIG_BT_CTLR_ADV_EXT)
98 TICKER_ID_SCAN_AUX_BASE,
99 TICKER_ID_SCAN_AUX_LAST = ((TICKER_ID_SCAN_AUX_BASE) +
100 (CONFIG_BT_CTLR_SCAN_AUX_SET) - 1),
101 #if defined(CONFIG_BT_CTLR_SYNC_PERIODIC)
102 TICKER_ID_SCAN_SYNC_BASE,
103 TICKER_ID_SCAN_SYNC_LAST = ((TICKER_ID_SCAN_SYNC_BASE) +
104 (CONFIG_BT_PER_ADV_SYNC_MAX) - 1),
105 #if defined(CONFIG_BT_CTLR_SYNC_ISO)
106 TICKER_ID_SCAN_SYNC_ISO_BASE,
107 TICKER_ID_SCAN_SYNC_ISO_LAST = ((TICKER_ID_SCAN_SYNC_ISO_BASE) +
108 (CONFIG_BT_CTLR_SCAN_SYNC_ISO_SET) - 1),
109 #endif /* CONFIG_BT_CTLR_SYNC_ISO */
110 #endif /* CONFIG_BT_CTLR_ADV_PERIODIC */
111 #endif /* CONFIG_BT_CTLR_ADV_EXT */
112 #endif /* CONFIG_BT_OBSERVER */
113
114 #if defined(CONFIG_BT_CONN)
115 TICKER_ID_CONN_BASE,
116 TICKER_ID_CONN_LAST = ((TICKER_ID_CONN_BASE) + (CONFIG_BT_MAX_CONN) -
117 1),
118 #endif /* CONFIG_BT_CONN */
119
120 #if defined(CONFIG_BT_CTLR_CONN_ISO)
121 TICKER_ID_CONN_ISO_BASE,
122 TICKER_ID_CONN_ISO_LAST = ((TICKER_ID_CONN_ISO_BASE) +
123 (CONFIG_BT_CTLR_CONN_ISO_GROUPS) - 1),
124 TICKER_ID_CONN_ISO_RESUME_BASE,
125 TICKER_ID_CONN_ISO_RESUME_LAST = ((TICKER_ID_CONN_ISO_RESUME_BASE) +
126 (CONFIG_BT_CTLR_CONN_ISO_GROUPS) - 1),
127 #endif /* CONFIG_BT_CTLR_CONN_ISO */
128
129 #if defined(CONFIG_BT_CTLR_USER_EXT) && \
130 (CONFIG_BT_CTLR_USER_TICKER_ID_RANGE > 0)
131 TICKER_ID_USER_BASE,
132 TICKER_ID_USER_LAST = (TICKER_ID_USER_BASE +
133 CONFIG_BT_CTLR_USER_TICKER_ID_RANGE - 1),
134 #endif /* CONFIG_BT_CTLR_USER_EXT */
135
136 TICKER_ID_MAX,
137 };
138
139 #if defined(CONFIG_BT_BROADCASTER) && !defined(CONFIG_BT_CTLR_ADV_EXT) && \
140 !defined(CONFIG_BT_HCI_MESH_EXT)
141 #define TICKER_ID_ADV_LAST TICKER_ID_ADV_BASE
142 #endif
143
144 /* Define the Broadcast ISO Stream Handle base value */
145 #if defined(CONFIG_BT_CTLR_ADV_ISO)
146 #define BT_CTLR_ADV_ISO_STREAM_MAX CONFIG_BT_CTLR_ADV_ISO_STREAM_MAX
147 #if defined(CONFIG_BT_MAX_CONN)
148 #define BT_CTLR_ADV_ISO_STREAM_HANDLE_BASE (CONFIG_BT_MAX_CONN)
149 #else /* !CONFIG_BT_MAX_CONN */
150 #define BT_CTLR_ADV_ISO_STREAM_HANDLE_BASE 0
151 #endif /* !CONFIG_BT_MAX_CONN */
152 #define LL_BIS_ADV_HANDLE_FROM_IDX(stream_handle) \
153 ((stream_handle) + (BT_CTLR_ADV_ISO_STREAM_HANDLE_BASE))
154 #else /* !CONFIG_BT_CTLR_ADV_ISO */
155 #define BT_CTLR_ADV_ISO_STREAM_MAX 0
156 #endif /* CONFIG_BT_CTLR_ADV_ISO */
157
158 /* Define the ISO Synchronized Receiver Stream Handle base value */
159 #if defined(CONFIG_BT_CTLR_SYNC_ISO)
160 #define BT_CTLR_SYNC_ISO_STREAM_MAX CONFIG_BT_CTLR_SYNC_ISO_STREAM_MAX
161 #if defined(CONFIG_BT_CTLR_ADV_ISO)
162 #define BT_CTLR_SYNC_ISO_STREAM_HANDLE_BASE \
163 (BT_CTLR_ADV_ISO_STREAM_HANDLE_BASE + \
164 CONFIG_BT_CTLR_ADV_ISO_STREAM_COUNT)
165 #elif defined(CONFIG_BT_MAX_CONN)
166 #define BT_CTLR_SYNC_ISO_STREAM_HANDLE_BASE (CONFIG_BT_MAX_CONN)
167 #else /* !CONFIG_BT_MAX_CONN */
168 #define BT_CTLR_SYNC_ISO_STREAM_HANDLE_BASE 0
169 #endif /* !CONFIG_BT_MAX_CONN */
170 #define LL_BIS_SYNC_HANDLE_FROM_IDX(stream_handle) \
171 ((stream_handle) + (BT_CTLR_SYNC_ISO_STREAM_HANDLE_BASE))
172 #else /* !CONFIG_BT_CTLR_SYNC_ISO */
173 #define BT_CTLR_SYNC_ISO_STREAM_MAX 0
174 #endif /* !CONFIG_BT_CTLR_SYNC_ISO */
175
176 /* Define the ISO Connections Stream Handle base value */
177 #if defined(CONFIG_BT_CTLR_CONN_ISO)
178 #if defined(CONFIG_BT_CTLR_SYNC_ISO)
179 #define BT_CTLR_CONN_ISO_STREAM_HANDLE_BASE \
180 (BT_CTLR_SYNC_ISO_STREAM_HANDLE_BASE + \
181 CONFIG_BT_CTLR_SYNC_ISO_STREAM_COUNT)
182 #elif defined(CONFIG_BT_CTLR_ADV_ISO)
183 #define BT_CTLR_CONN_ISO_STREAM_HANDLE_BASE \
184 (BT_CTLR_ADV_ISO_STREAM_HANDLE_BASE + \
185 CONFIG_BT_CTLR_ADV_ISO_STREAM_COUNT)
186 #else /* !CONFIG_BT_CTLR_ADV_ISO && !CONFIG_BT_CTLR_SYNC_ISO */
187 #define BT_CTLR_CONN_ISO_STREAM_HANDLE_BASE (CONFIG_BT_MAX_CONN)
188 #endif /* !CONFIG_BT_CTLR_ADV_ISO && !CONFIG_BT_CTLR_SYNC_ISO */
189 #define LL_CIS_HANDLE_BASE (BT_CTLR_CONN_ISO_STREAM_HANDLE_BASE)
190 #define LL_CIS_IDX_FROM_HANDLE(handle) \
191 ((handle) - LL_CIS_HANDLE_BASE)
192 #endif /* CONFIG_BT_CTLR_CONN_ISO */
193
194 #define TICKER_ID_ULL_BASE ((TICKER_ID_LLL_PREEMPT) + 1)
195
196 enum done_result {
197 DONE_COMPLETED,
198 DONE_ABORTED,
199 DONE_LATE
200 };
201
202 /* Forward declaration data type to store CTE IQ samples report related data */
203 struct cte_conn_iq_report;
204
205 struct ull_hdr {
206 uint8_t volatile ref; /* Number of ongoing (between Prepare and Done)
207 * events
208 */
209
210 /* Event parameters */
211 /* TODO: The intention is to use the greater of the
212 * ticks_prepare_to_start or ticks_active_to_start as the prepare
213 * offset. At the prepare tick generate a software interrupt
214 * serviceable by application as the per role configurable advance
215 * radio event notification, usable for data acquisitions.
216 * ticks_preempt_to_start is the per role dynamic preempt offset,
217 * which shall be based on role's preparation CPU usage
218 * requirements.
219 */
220 struct {
221 uint32_t ticks_active_to_start;
222 uint32_t ticks_prepare_to_start;
223 uint32_t ticks_preempt_to_start;
224 uint32_t ticks_slot;
225 };
226
227 /* ULL context disabled callback and its parameter */
228 void (*disabled_cb)(void *param);
229 void *disabled_param;
230 };
231
232 struct lll_hdr {
233 void *parent;
234 #if defined(CONFIG_BT_CTLR_JIT_SCHEDULING)
235 uint8_t score;
236 uint8_t latency;
237 int8_t prio;
238 #endif /* CONFIG_BT_CTLR_JIT_SCHEDULING */
239 };
240
241 #define HDR_LLL2ULL(p) (((struct lll_hdr *)(p))->parent)
242
243 struct lll_prepare_param {
244 uint32_t ticks_at_expire;
245 uint32_t remainder;
246 uint16_t lazy;
247 #if defined(CONFIG_BT_CTLR_JIT_SCHEDULING)
248 int8_t prio;
249 #endif /* CONFIG_BT_CTLR_JIT_SCHEDULING */
250 uint8_t force;
251 void *param;
252 };
253
254 typedef int (*lll_prepare_cb_t)(struct lll_prepare_param *prepare_param);
255 typedef int (*lll_is_abort_cb_t)(void *next, void *curr,
256 lll_prepare_cb_t *resume_cb);
257 typedef void (*lll_abort_cb_t)(struct lll_prepare_param *prepare_param,
258 void *param);
259
260 struct lll_event {
261 struct lll_prepare_param prepare_param;
262 lll_prepare_cb_t prepare_cb;
263 lll_is_abort_cb_t is_abort_cb;
264 lll_abort_cb_t abort_cb;
265 uint8_t is_resume:1;
266 uint8_t is_aborted:1;
267 };
268
269 #define DEFINE_NODE_RX_USER_TYPE(i, _) NODE_RX_TYPE_##i
270
271 enum node_rx_type {
272 /* Unused */
273 NODE_RX_TYPE_NONE = 0x00,
274 /* Signals release of node */
275 NODE_RX_TYPE_RELEASE,
276 /* Signals completion of RX event */
277 NODE_RX_TYPE_EVENT_DONE,
278 /* Signals arrival of RX Data Channel payload */
279 NODE_RX_TYPE_DC_PDU,
280 /* Signals arrival of isochronous payload */
281 NODE_RX_TYPE_ISO_PDU,
282 /* Advertisement report from scanning */
283 NODE_RX_TYPE_REPORT,
284 NODE_RX_TYPE_EXT_1M_REPORT,
285 NODE_RX_TYPE_EXT_2M_REPORT,
286 NODE_RX_TYPE_EXT_CODED_REPORT,
287 NODE_RX_TYPE_EXT_AUX_REPORT,
288 NODE_RX_TYPE_EXT_AUX_RELEASE,
289 NODE_RX_TYPE_EXT_SCAN_TERMINATE,
290 NODE_RX_TYPE_SYNC,
291 NODE_RX_TYPE_SYNC_REPORT,
292 NODE_RX_TYPE_SYNC_LOST,
293 NODE_RX_TYPE_SYNC_CHM_COMPLETE,
294 NODE_RX_TYPE_SYNC_ISO,
295 NODE_RX_TYPE_SYNC_ISO_LOST,
296 NODE_RX_TYPE_EXT_ADV_TERMINATE,
297 NODE_RX_TYPE_BIG_COMPLETE,
298 NODE_RX_TYPE_BIG_CHM_COMPLETE,
299 NODE_RX_TYPE_BIG_TERMINATE,
300 NODE_RX_TYPE_SCAN_REQ,
301 NODE_RX_TYPE_CONNECTION,
302 NODE_RX_TYPE_TERMINATE,
303 NODE_RX_TYPE_CONN_UPDATE,
304 NODE_RX_TYPE_ENC_REFRESH,
305 NODE_RX_TYPE_APTO,
306 NODE_RX_TYPE_CHAN_SEL_ALGO,
307 NODE_RX_TYPE_PHY_UPDATE,
308 NODE_RX_TYPE_RSSI,
309 NODE_RX_TYPE_PROFILE,
310 NODE_RX_TYPE_ADV_INDICATION,
311 NODE_RX_TYPE_SCAN_INDICATION,
312 NODE_RX_TYPE_CIS_REQUEST,
313 NODE_RX_TYPE_CIS_ESTABLISHED,
314 NODE_RX_TYPE_REQ_PEER_SCA_COMPLETE,
315 NODE_RX_TYPE_MESH_ADV_CPLT,
316 NODE_RX_TYPE_MESH_REPORT,
317 NODE_RX_TYPE_SYNC_IQ_SAMPLE_REPORT,
318 NODE_RX_TYPE_CONN_IQ_SAMPLE_REPORT,
319 NODE_RX_TYPE_DTM_IQ_SAMPLE_REPORT,
320 NODE_RX_TYPE_IQ_SAMPLE_REPORT_ULL_RELEASE,
321 NODE_RX_TYPE_IQ_SAMPLE_REPORT_LLL_RELEASE,
322 /* Signals retention (ie non-release) of rx node */
323 NODE_RX_TYPE_RETAIN,
324
325 #if defined(CONFIG_BT_CTLR_USER_EXT)
326 /* No entries shall be added after the NODE_RX_TYPE_USER_START/END */
327 NODE_RX_TYPE_USER_START,
328 LISTIFY(CONFIG_BT_CTLR_USER_EVT_RANGE, DEFINE_NODE_RX_USER_TYPE, (,), _),
329 NODE_RX_TYPE_USER_END,
330 #endif /* CONFIG_BT_CTLR_USER_EXT */
331 };
332
333 /* Footer of node_rx_hdr */
334 struct node_rx_ftr {
335 union {
336 void *param;
337 struct {
338 uint8_t status;
339 uint8_t num_events;
340 uint16_t conn_handle;
341 } param_adv_term;
342 };
343 union {
344 void *extra; /* Used as next pointer for extended PDU
345 * chaining, to reserve node_rx for CSA#2 event
346 * generation etc.
347 */
348 void *aux_ptr;
349 uint8_t aux_phy;
350 struct cte_conn_iq_report *iq_report;
351 };
352 uint32_t ticks_anchor;
353 uint32_t radio_end_us;
354 uint8_t rssi;
355
356 #if defined(CONFIG_BT_CTLR_PRIVACY)
357 uint8_t rl_idx;
358 uint8_t lrpa_used:1;
359 #endif /* CONFIG_BT_CTLR_PRIVACY */
360
361 #if defined(CONFIG_BT_CTLR_EXT_SCAN_FP)
362 uint8_t direct:1;
363 #endif /* CONFIG_BT_CTLR_EXT_SCAN_FP */
364
365 #if defined(CONFIG_BT_CTLR_ADV_EXT) && defined(CONFIG_BT_OBSERVER)
366 uint8_t phy_flags:1;
367 uint8_t scan_req:1;
368 uint8_t scan_rsp:1;
369
370 #if defined(CONFIG_BT_CTLR_PRIVACY)
371 uint8_t direct_resolved:1;
372 #endif /* CONFIG_BT_CTLR_PRIVACY */
373
374 #if defined(CONFIG_BT_CTLR_SYNC_PERIODIC)
375 uint8_t sync_status:2;
376 uint8_t sync_rx_enabled:1;
377 #if defined(CONFIG_BT_CTLR_FILTER_ACCEPT_LIST)
378 uint8_t devmatch:1;
379 #endif /* CONFIG_BT_CTLR_FILTER_ACCEPT_LIST */
380 #endif /* CONFIG_BT_CTLR_SYNC_PERIODIC */
381
382 uint8_t aux_sched:1;
383 uint8_t aux_lll_sched:1;
384 uint8_t aux_failed:1;
385
386 uint16_t aux_data_len;
387 #endif /* CONFIG_BT_CTLR_ADV_EXT && CONFIG_BT_OBSERVER */
388
389 #if defined(CONFIG_BT_HCI_MESH_EXT)
390 uint8_t chan_idx;
391 #endif /* CONFIG_BT_HCI_MESH_EXT */
392 };
393
394 /* Meta-information for isochronous PDUs in node_rx_hdr */
395 struct node_rx_iso_meta {
396 uint64_t payload_number:39; /* cisPayloadNumber */
397 uint64_t status:8; /* Status of reception (OK/not OK) */
398 uint32_t timestamp; /* Time of reception */
399 };
400
401 /* Define invalid/unassigned Controller state/role instance handle */
402 #define NODE_RX_HANDLE_INVALID 0xFFFF
403
404 /* Define invalid/unassigned Controller LLL context handle */
405 #define LLL_HANDLE_INVALID 0xFFFF
406
407 /* Define invalid/unassigned Controller Advertising LLL context handle */
408 #define LLL_ADV_HANDLE_INVALID 0xFF
409
410 /* Header of node_rx_pdu */
411 struct node_rx_hdr {
412 union {
413 void *next; /* For slist, by hci module */
414 memq_link_t *link; /* Supply memq_link from ULL to LLL */
415 uint8_t ack_last; /* Tx ack queue index at this node rx */
416 };
417
418 enum node_rx_type type;
419 uint8_t user_meta; /* User metadata */
420 uint16_t handle; /* State/Role instance handle */
421
422 union {
423 struct node_rx_ftr rx_ftr;
424 #if defined(CONFIG_BT_CTLR_SYNC_ISO) || defined(CONFIG_BT_CTLR_CONN_ISO)
425 struct node_rx_iso_meta rx_iso_meta;
426 #endif
427 #if defined(CONFIG_BT_CTLR_RX_PDU_META)
428 lll_rx_pdu_meta_t rx_pdu_meta;
429 #endif /* CONFIG_BT_CTLR_RX_PDU_META */
430 };
431 };
432
433 /* Template node rx type with memory aligned offset to PDU buffer.
434 * NOTE: offset to memory aligned pdu buffer location is used to reference
435 * node rx type specific information, like, terminate or sync lost reason
436 * from a dedicated node rx structure storage location.
437 */
438 struct node_rx_pdu {
439 struct node_rx_hdr hdr;
440 union {
441 uint8_t pdu[0] __aligned(4);
442 };
443 };
444
445 enum {
446 EVENT_DONE_EXTRA_TYPE_NONE,
447
448 #if defined(CONFIG_BT_CONN)
449 EVENT_DONE_EXTRA_TYPE_CONN,
450 #endif /* CONFIG_BT_CONN */
451
452 #if defined(CONFIG_BT_CTLR_ADV_EXT) || defined(CONFIG_BT_CTLR_JIT_SCHEDULING)
453 #if defined(CONFIG_BT_BROADCASTER)
454 EVENT_DONE_EXTRA_TYPE_ADV,
455 EVENT_DONE_EXTRA_TYPE_ADV_AUX,
456 #if defined(CONFIG_BT_CTLR_ADV_ISO)
457 EVENT_DONE_EXTRA_TYPE_ADV_ISO_COMPLETE,
458 EVENT_DONE_EXTRA_TYPE_ADV_ISO_TERMINATE,
459 #endif /* CONFIG_BT_CTLR_ADV_ISO */
460 #endif /* CONFIG_BT_BROADCASTER */
461 #endif /* CONFIG_BT_CTLR_ADV_EXT || CONFIG_BT_CTLR_JIT_SCHEDULING */
462
463 #if defined(CONFIG_BT_OBSERVER)
464 #if defined(CONFIG_BT_CTLR_ADV_EXT)
465 EVENT_DONE_EXTRA_TYPE_SCAN,
466 EVENT_DONE_EXTRA_TYPE_SCAN_AUX,
467 #if defined(CONFIG_BT_CTLR_SYNC_PERIODIC)
468 EVENT_DONE_EXTRA_TYPE_SYNC,
469 #if defined(CONFIG_BT_CTLR_SYNC_ISO)
470 EVENT_DONE_EXTRA_TYPE_SYNC_ISO_ESTAB,
471 EVENT_DONE_EXTRA_TYPE_SYNC_ISO,
472 EVENT_DONE_EXTRA_TYPE_SYNC_ISO_TERMINATE,
473 #endif /* CONFIG_BT_CTLR_SYNC_ISO */
474 #endif /* CONFIG_BT_CTLR_SYNC_PERIODIC */
475 #endif /* CONFIG_BT_CTLR_ADV_EXT */
476 #endif /* CONFIG_BT_OBSERVER */
477
478 #if defined(CONFIG_BT_CTLR_CONN_ISO)
479 EVENT_DONE_EXTRA_TYPE_CIS,
480 #endif /* CONFIG_BT_CTLR_CONN_ISO */
481
482 /* Following proprietary defines must be at end of enum range */
483 #if defined(CONFIG_BT_CTLR_USER_EXT)
484 EVENT_DONE_EXTRA_TYPE_USER_START,
485 EVENT_DONE_EXTRA_TYPE_USER_END = EVENT_DONE_EXTRA_TYPE_USER_START +
486 CONFIG_BT_CTLR_USER_EVT_RANGE,
487 #endif /* CONFIG_BT_CTLR_USER_EXT */
488
489 };
490
491 struct event_done_extra_drift {
492 uint32_t start_to_address_actual_us;
493 uint32_t window_widening_event_us;
494 uint32_t preamble_to_addr_us;
495 };
496
497 struct event_done_extra {
498 uint8_t type;
499 #if defined(CONFIG_BT_CTLR_JIT_SCHEDULING)
500 uint8_t result;
501 #endif /* CONFIG_BT_CTLR_JIT_SCHEDULING */
502 union {
503 struct {
504 union {
505 #if defined(CONFIG_BT_CTLR_CONN_ISO)
506 uint32_t trx_performed_bitmask;
507 #endif /* CONFIG_BT_CTLR_CONN_ISO */
508
509 struct {
510 uint16_t trx_cnt;
511 uint8_t crc_valid:1;
512 #if defined(CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING) && \
513 defined(CONFIG_BT_CTLR_CTEINLINE_SUPPORT)
514 /* Used to inform ULL that periodic
515 * advertising sync scan should be
516 * terminated.
517 */
518 uint8_t sync_term:1;
519 #endif /* CONFIG_BT_CTLR_SYNC_PERIODIC_CTE_TYPE_FILTERING && \
520 * CONFIG_BT_CTLR_CTEINLINE_SUPPORT
521 */
522 };
523 };
524
525 #if defined(CONFIG_BT_CTLR_LE_ENC)
526 uint8_t mic_state;
527 #endif /* CONFIG_BT_CTLR_LE_ENC */
528
529 #if defined(CONFIG_BT_PERIPHERAL) || defined(CONFIG_BT_CTLR_SYNC_PERIODIC)
530 union {
531 struct event_done_extra_drift drift;
532 };
533 #endif /* CONFIG_BT_PERIPHERAL || CONFIG_BT_CTLR_SYNC_PERIODIC */
534 };
535 };
536 };
537
538 struct node_rx_event_done {
539 struct node_rx_hdr hdr;
540 void *param;
541 struct event_done_extra extra;
542 };
543
lll_hdr_init(void * lll,void * parent)544 static inline void lll_hdr_init(void *lll, void *parent)
545 {
546 struct lll_hdr *hdr = lll;
547
548 hdr->parent = parent;
549
550 #if defined(CONFIG_BT_CTLR_JIT_SCHEDULING)
551 hdr->score = 0U;
552 hdr->latency = 0U;
553 #endif /* CONFIG_BT_CTLR_JIT_SCHEDULING */
554 }
555
556 /* If ISO vendor data path is not used, queue directly to ll_iso_rx */
557 #if defined(CONFIG_BT_CTLR_ISO_VENDOR_DATA_PATH)
558 #define iso_rx_put(link, rx) ull_iso_rx_put(link, rx)
559 #define iso_rx_sched() ull_iso_rx_sched()
560 #else
561 #define iso_rx_put(link, rx) ll_iso_rx_put(link, rx)
562 #define iso_rx_sched() ll_rx_sched()
563 #endif /* CONFIG_BT_CTLR_ISO_VENDOR_DATA_PATH */
564
565 struct node_tx_iso;
566
567 void lll_done_score(void *param, uint8_t result);
568
569 int lll_init(void);
570 int lll_deinit(void);
571 int lll_reset(void);
572 void lll_resume(void *param);
573 void lll_disable(void *param);
574 void lll_done_ull_inc(void);
575 uint32_t lll_radio_is_idle(void);
576 uint32_t lll_radio_tx_ready_delay_get(uint8_t phy, uint8_t flags);
577 uint32_t lll_radio_rx_ready_delay_get(uint8_t phy, uint8_t flags);
578 int8_t lll_radio_tx_pwr_min_get(void);
579 int8_t lll_radio_tx_pwr_max_get(void);
580 int8_t lll_radio_tx_pwr_floor(int8_t tx_pwr_lvl);
581
582 int lll_csrand_get(void *buf, size_t len);
583 int lll_csrand_isr_get(void *buf, size_t len);
584 int lll_rand_get(void *buf, size_t len);
585 int lll_rand_isr_get(void *buf, size_t len);
586
587 struct lll_event *ull_prepare_enqueue(lll_is_abort_cb_t is_abort_cb,
588 lll_abort_cb_t abort_cb,
589 struct lll_prepare_param *prepare_param,
590 lll_prepare_cb_t prepare_cb,
591 uint8_t is_resume);
592 void *ull_prepare_dequeue_get(void);
593 void *ull_prepare_dequeue_iter(uint8_t *idx);
594 void ull_prepare_dequeue(uint8_t caller_id);
595 void *ull_pdu_rx_alloc_peek(uint8_t count);
596 void *ull_pdu_rx_alloc_peek_iter(uint8_t *idx);
597 void *ull_pdu_rx_alloc(void);
598 void *ull_iso_pdu_rx_alloc_peek(uint8_t count);
599 void *ull_iso_pdu_rx_alloc(void);
600 void ull_rx_put(memq_link_t *link, void *rx);
601 void ull_rx_put_done(memq_link_t *link, void *done);
602 void ull_rx_sched(void);
603 void ull_rx_sched_done(void);
604 void ull_rx_put_sched(memq_link_t *link, void *rx);
605 void ull_iso_rx_put(memq_link_t *link, void *rx);
606 void ull_iso_rx_sched(void);
607 void *ull_iso_tx_ack_dequeue(void);
608 void ull_iso_lll_ack_enqueue(uint16_t handle, struct node_tx_iso *tx);
609 void ull_iso_lll_event_prepare(uint16_t handle, uint64_t event_count);
610 struct event_done_extra *ull_event_done_extra_get(void);
611 struct event_done_extra *ull_done_extra_type_set(uint8_t type);
612 void *ull_event_done(void *param);
613
614 int lll_prepare(lll_is_abort_cb_t is_abort_cb,
615 lll_abort_cb_t abort_cb,
616 lll_prepare_cb_t prepare_cb, int8_t event_prio,
617 struct lll_prepare_param *prepare_param);
618 int lll_resume_enqueue(lll_prepare_cb_t resume_cb, int resume_prio);
619 int lll_prepare_resolve(lll_is_abort_cb_t is_abort_cb, lll_abort_cb_t abort_cb,
620 lll_prepare_cb_t prepare_cb,
621 struct lll_prepare_param *prepare_param,
622 uint8_t is_resume, uint8_t is_dequeue);
623