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