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