Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 | /* * Copyright (c) 2017-2021 Nordic Semiconductor ASA * * SPDX-License-Identifier: Apache-2.0 */ #include <stddef.h> #include <stdbool.h> #include <errno.h> #include <zephyr.h> #include <soc.h> #include <device.h> #include <drivers/entropy.h> #include <bluetooth/hci.h> #include "hal/cpu.h" #include "hal/ccm.h" #include "hal/cntr.h" #include "hal/ticker.h" #include "util/util.h" #include "util/mem.h" #include "util/mfifo.h" #include "util/memq.h" #include "util/mayfly.h" #include "ticker/ticker.h" #include "pdu.h" #include "lll.h" #include "lll/lll_vendor.h" #include "lll/lll_adv_types.h" #include "lll_adv.h" #include "lll/lll_adv_pdu.h" #include "lll_chan.h" #include "lll_scan.h" #include "lll/lll_df_types.h" #include "lll_sync.h" #include "lll_sync_iso.h" #include "lll_conn.h" #include "lll_df.h" #include "ull_adv_types.h" #include "ull_scan_types.h" #include "ull_sync_types.h" #include "ull_conn_types.h" #include "ull_filter.h" #include "ull_df_types.h" #include "ull_df_internal.h" #include "isoal.h" #include "ull_internal.h" #include "ull_iso_internal.h" #include "ull_adv_internal.h" #include "ull_scan_internal.h" #include "ull_sync_internal.h" #include "ull_sync_iso_internal.h" #include "ull_central_internal.h" #include "ull_conn_internal.h" #include "lll_conn_iso.h" #include "ull_conn_iso_types.h" #include "ull_iso_types.h" #include "ull_central_iso_internal.h" #include "ull_conn_iso_internal.h" #include "ull_peripheral_iso_internal.h" #if defined(CONFIG_BT_CTLR_USER_EXT) #include "ull_vendor.h" #endif /* CONFIG_BT_CTLR_USER_EXT */ #include "ll.h" #include "ll_feat.h" #include "ll_test.h" #include "ll_settings.h" #define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER) #define LOG_MODULE_NAME bt_ctlr_ull #include "common/log.h" #include "hal/debug.h" #if defined(CONFIG_BT_BROADCASTER) #define BT_ADV_TICKER_NODES ((TICKER_ID_ADV_LAST) - (TICKER_ID_ADV_STOP) + 1) #if defined(CONFIG_BT_CTLR_ADV_EXT) && (CONFIG_BT_CTLR_ADV_AUX_SET > 0) #define BT_ADV_AUX_TICKER_NODES ((TICKER_ID_ADV_AUX_LAST) - \ (TICKER_ID_ADV_AUX_BASE) + 1) #if defined(CONFIG_BT_CTLR_ADV_PERIODIC) #define BT_ADV_SYNC_TICKER_NODES ((TICKER_ID_ADV_SYNC_LAST) - \ (TICKER_ID_ADV_SYNC_BASE) + 1) #if defined(CONFIG_BT_CTLR_ADV_ISO) #define BT_ADV_ISO_TICKER_NODES ((TICKER_ID_ADV_ISO_LAST) - \ (TICKER_ID_ADV_ISO_BASE) + 1) #else /* !CONFIG_BT_CTLR_ADV_ISO */ #define BT_ADV_ISO_TICKER_NODES 0 #endif /* !CONFIG_BT_CTLR_ADV_ISO */ #else /* !CONFIG_BT_CTLR_ADV_PERIODIC */ #define BT_ADV_SYNC_TICKER_NODES 0 #define BT_ADV_ISO_TICKER_NODES 0 #endif /* !CONFIG_BT_CTLR_ADV_PERIODIC */ #else /* (CONFIG_BT_CTLR_ADV_AUX_SET > 0) */ #define BT_ADV_AUX_TICKER_NODES 0 #define BT_ADV_SYNC_TICKER_NODES 0 #define BT_ADV_ISO_TICKER_NODES 0 #endif /* (CONFIG_BT_CTLR_ADV_AUX_SET > 0) */ #else /* !CONFIG_BT_BROADCASTER */ #define BT_ADV_TICKER_NODES 0 #define BT_ADV_AUX_TICKER_NODES 0 #define BT_ADV_SYNC_TICKER_NODES 0 #define BT_ADV_ISO_TICKER_NODES 0 #endif /* !CONFIG_BT_BROADCASTER */ #if defined(CONFIG_BT_OBSERVER) #define BT_SCAN_TICKER_NODES ((TICKER_ID_SCAN_LAST) - (TICKER_ID_SCAN_STOP) + 1) #if defined(CONFIG_BT_CTLR_ADV_EXT) #define BT_SCAN_AUX_TICKER_NODES ((TICKER_ID_SCAN_AUX_LAST) - \ (TICKER_ID_SCAN_AUX_BASE) + 1) #if defined(CONFIG_BT_CTLR_SYNC_PERIODIC) #define BT_SCAN_SYNC_TICKER_NODES ((TICKER_ID_SCAN_SYNC_LAST) - \ (TICKER_ID_SCAN_SYNC_BASE) + 1) #if defined(CONFIG_BT_CTLR_SYNC_ISO) #define BT_SCAN_SYNC_ISO_TICKER_NODES ((TICKER_ID_SCAN_SYNC_ISO_LAST) - \ (TICKER_ID_SCAN_SYNC_ISO_BASE) + 1) #else /* !CONFIG_BT_CTLR_SYNC_ISO */ #define BT_SCAN_SYNC_ISO_TICKER_NODES 0 #endif /* !CONFIG_BT_CTLR_SYNC_ISO */ #else /* !CONFIG_BT_CTLR_SYNC_PERIODIC */ #define BT_SCAN_SYNC_TICKER_NODES 0 #define BT_SCAN_SYNC_ISO_TICKER_NODES 0 #endif /* !CONFIG_BT_CTLR_SYNC_PERIODIC */ #else /* !CONFIG_BT_CTLR_ADV_EXT */ #define BT_SCAN_AUX_TICKER_NODES 0 #define BT_SCAN_SYNC_TICKER_NODES 0 #define BT_SCAN_SYNC_ISO_TICKER_NODES 0 #endif /* !CONFIG_BT_CTLR_ADV_EXT */ #else #define BT_SCAN_TICKER_NODES 0 #define BT_SCAN_AUX_TICKER_NODES 0 #define BT_SCAN_SYNC_TICKER_NODES 0 #define BT_SCAN_SYNC_ISO_TICKER_NODES 0 #endif #if defined(CONFIG_BT_CONN) #define BT_CONN_TICKER_NODES ((TICKER_ID_CONN_LAST) - (TICKER_ID_CONN_BASE) + 1) #else #define BT_CONN_TICKER_NODES 0 #endif #if defined(CONFIG_BT_CTLR_CONN_ISO) #define BT_CIG_TICKER_NODES ((TICKER_ID_CONN_ISO_LAST) - \ (TICKER_ID_CONN_ISO_BASE) + 1 + \ (TICKER_ID_CONN_ISO_RESUME_LAST) - \ (TICKER_ID_CONN_ISO_RESUME_BASE) + 1) #else #define BT_CIG_TICKER_NODES 0 #endif #if defined(CONFIG_BT_CTLR_USER_EXT) #define USER_TICKER_NODES CONFIG_BT_CTLR_USER_TICKER_ID_RANGE #else #define USER_TICKER_NODES 0 #endif #if defined(CONFIG_SOC_FLASH_NRF_RADIO_SYNC_TICKER) #define FLASH_TICKER_NODES 2 /* No. of tickers reserved for flash * driver */ #define TICKER_USER_ULL_HIGH_FLASH_OPS 1 /* No. of additional ticker ULL_HIGH * context operations */ #define TICKER_USER_THREAD_FLASH_OPS 1 /* No. of additional ticker thread * context operations */ #else #define FLASH_TICKER_NODES 0 #define TICKER_USER_ULL_HIGH_FLASH_OPS 0 #define TICKER_USER_THREAD_FLASH_OPS 0 #endif /* Define ticker nodes */ /* NOTE: FLASH_TICKER_NODES shall be after Link Layer's list of ticker id * allocations, refer to ll_timeslice_ticker_id_get on how ticker id * used by flash driver is returned. */ #define TICKER_NODES (TICKER_ID_ULL_BASE + \ BT_ADV_TICKER_NODES + \ BT_ADV_AUX_TICKER_NODES + \ BT_ADV_SYNC_TICKER_NODES + \ BT_ADV_ISO_TICKER_NODES + \ BT_SCAN_TICKER_NODES + \ BT_SCAN_AUX_TICKER_NODES + \ BT_SCAN_SYNC_TICKER_NODES + \ BT_SCAN_SYNC_ISO_TICKER_NODES + \ BT_CONN_TICKER_NODES + \ BT_CIG_TICKER_NODES + \ USER_TICKER_NODES + \ FLASH_TICKER_NODES) /* When both central and peripheral are supported, one each Rx node will be * needed by connectable advertising and the initiator to generate connection * complete event, hence conditionally set the count. */ #if defined(CONFIG_BT_MAX_CONN) #if defined(CONFIG_BT_CENTRAL) && defined(CONFIG_BT_PERIPHERAL) #define BT_CTLR_MAX_CONNECTABLE 2 #else #define BT_CTLR_MAX_CONNECTABLE 1 #endif #define BT_CTLR_MAX_CONN CONFIG_BT_MAX_CONN #else #define BT_CTLR_MAX_CONNECTABLE 0 #define BT_CTLR_MAX_CONN 0 #endif #if defined(CONFIG_BT_CTLR_ADV_EXT) && defined(CONFIG_BT_OBSERVER) #if defined(CONFIG_BT_CTLR_DF_CTE_RX) /* Note: Need node for PDU and CTE sample */ #define BT_CTLR_ADV_EXT_RX_CNT (CONFIG_BT_CTLR_SCAN_AUX_SET * \ CONFIG_BT_CTLR_DF_PER_SCAN_CTE_NUM_MAX * 2) #else /* Note: Assume up to 7 PDUs per advertising train (max data length) */ #define BT_CTLR_ADV_EXT_RX_CNT (CONFIG_BT_CTLR_SCAN_AUX_SET * 7) #endif #else #define BT_CTLR_ADV_EXT_RX_CNT 0 #endif #if !defined(TICKER_USER_LLL_VENDOR_OPS) #define TICKER_USER_LLL_VENDOR_OPS 0 #endif /* TICKER_USER_LLL_VENDOR_OPS */ #if !defined(TICKER_USER_ULL_HIGH_VENDOR_OPS) #define TICKER_USER_ULL_HIGH_VENDOR_OPS 0 #endif /* TICKER_USER_ULL_HIGH_VENDOR_OPS */ #if !defined(TICKER_USER_THREAD_VENDOR_OPS) #define TICKER_USER_THREAD_VENDOR_OPS 0 #endif /* TICKER_USER_THREAD_VENDOR_OPS */ /* Define ticker user operations */ #if defined(CONFIG_BT_CTLR_LOW_LAT) && \ (CONFIG_BT_CTLR_LLL_PRIO == CONFIG_BT_CTLR_ULL_LOW_PRIO) /* NOTE: When ticker job is disabled inside radio events then all advertising, * scanning, and peripheral latency cancel ticker operations will be deferred, * requiring increased ticker thread context operation queue count. */ #define TICKER_USER_THREAD_OPS (BT_CTLR_ADV_SET + BT_CTLR_SCAN_SET + \ BT_CTLR_MAX_CONN + \ TICKER_USER_THREAD_VENDOR_OPS + \ TICKER_USER_THREAD_FLASH_OPS + \ 1) #else /* !CONFIG_BT_CTLR_LOW_LAT */ /* NOTE: As ticker job is not disabled inside radio events, no need for extra * thread operations queue element for flash driver. */ #define TICKER_USER_THREAD_OPS (1 + TICKER_USER_THREAD_VENDOR_OPS + 1) #endif /* !CONFIG_BT_CTLR_LOW_LAT */ #define TICKER_USER_ULL_LOW_OPS (1 + 1) /* NOTE: When ULL_LOW priority is configured to lower than ULL_HIGH, then extra * ULL_HIGH operations queue elements are required to buffer the * requested ticker operations. */ #if defined(CONFIG_BT_CENTRAL) && defined(CONFIG_BT_CTLR_ADV_EXT) && \ defined(CONFIG_BT_CTLR_PHY_CODED) #define TICKER_USER_ULL_HIGH_OPS (4 + TICKER_USER_ULL_HIGH_VENDOR_OPS + \ TICKER_USER_ULL_HIGH_FLASH_OPS + 1) #else /* !CONFIG_BT_CENTRAL || !CONFIG_BT_CTLR_ADV_EXT || * !CONFIG_BT_CTLR_PHY_CODED */ #define TICKER_USER_ULL_HIGH_OPS (3 + TICKER_USER_ULL_HIGH_VENDOR_OPS + \ TICKER_USER_ULL_HIGH_FLASH_OPS + 1) #endif /* !CONFIG_BT_CENTRAL || !CONFIG_BT_CTLR_ADV_EXT || * !CONFIG_BT_CTLR_PHY_CODED */ #define TICKER_USER_LLL_OPS (3 + TICKER_USER_LLL_VENDOR_OPS + 1) #define TICKER_USER_OPS (TICKER_USER_LLL_OPS + \ TICKER_USER_ULL_HIGH_OPS + \ TICKER_USER_ULL_LOW_OPS + \ TICKER_USER_THREAD_OPS) /* Memory for ticker nodes/instances */ static uint8_t MALIGN(4) ticker_nodes[TICKER_NODES][TICKER_NODE_T_SIZE]; /* Memory for users/contexts operating on ticker module */ static uint8_t MALIGN(4) ticker_users[MAYFLY_CALLER_COUNT][TICKER_USER_T_SIZE]; /* Memory for user/context simultaneous API operations */ static uint8_t MALIGN(4) ticker_user_ops[TICKER_USER_OPS][TICKER_USER_OP_T_SIZE]; /* Semaphire to wakeup thread on ticker API callback */ static struct k_sem sem_ticker_api_cb; /* Semaphore to wakeup thread on Rx-ed objects */ static struct k_sem *sem_recv; /* Declare prepare-event FIFO: mfifo_prep. * Queue of struct node_rx_event_done */ static MFIFO_DEFINE(prep, sizeof(struct lll_event), EVENT_PIPELINE_MAX); /* Declare done-event FIFO: mfifo_done. * Queue of pointers to struct node_rx_event_done. * The actual backing behind these pointers is mem_done. * * When there are radio events with time reservations lower than the preemption * timeout of 1.5 ms, the pipeline has to account for the maximum radio events * that can be enqueued during the preempt timeout duration. All these enqueued * events could be aborted in case of late scheduling, needing as many done * event buffers. * * During continuous scanning, there can be 1 active radio event, 1 scan resume * and 1 new scan prepare. If there are peripheral prepares in addition, and due * to late scheduling all these will abort needing 4 done buffers. * * If there are additional peripheral prepares enqueued, which are apart by * their time reservations, these are not yet late and hence no more additional * done buffers are needed. * * If Extended Scanning is supported, then an additional auxiliary scan event's * prepare could be enqueued in the pipeline during the preemption duration. */ #if !defined(VENDOR_EVENT_DONE_MAX) #if defined(CONFIG_BT_CTLR_ADV_EXT) && defined(CONFIG_BT_OBSERVER) #define EVENT_DONE_MAX 5 #else /* !CONFIG_BT_CTLR_ADV_EXT || !CONFIG_BT_OBSERVER */ #define EVENT_DONE_MAX 4 #endif /* !CONFIG_BT_CTLR_ADV_EXT || !CONFIG_BT_OBSERVER */ #else #define EVENT_DONE_MAX VENDOR_EVENT_DONE_MAX #endif static MFIFO_DEFINE(done, sizeof(struct node_rx_event_done *), EVENT_DONE_MAX); /* Backing storage for elements in mfifo_done */ static struct { void *free; uint8_t pool[sizeof(struct node_rx_event_done) * EVENT_DONE_MAX]; } mem_done; static struct { void *free; uint8_t pool[sizeof(memq_link_t) * (EVENT_DONE_MAX + EVENT_DONE_LINK_CNT)]; } mem_link_done; /* Minimum number of node rx for ULL to LL/HCI thread per connection. * Increasing this by times the max. simultaneous connection count will permit * simultaneous parallel PHY update or Connection Update procedures amongst * active connections. * Minimum node rx of 2 that can be reserved happens when local central * initiated PHY Update reserves 2 node rx, one for PHY update complete and * another for Data Length Update complete notification. Otherwise, a * peripheral only needs 1 additional node rx to generate Data Length Update * complete when PHY Update completes; node rx for PHY update complete is * reserved as the received PHY Update Ind PDU. */ #if defined(CONFIG_BT_CENTRAL) && defined(CONFIG_BT_CTLR_PHY) && \ defined(CONFIG_BT_CTLR_DATA_LENGTH) #define LL_PDU_RX_CNT (2 * (CONFIG_BT_CTLR_LLCP_CONN)) #elif defined(CONFIG_BT_CONN) #define LL_PDU_RX_CNT (CONFIG_BT_CTLR_LLCP_CONN) #else #define LL_PDU_RX_CNT 0 #endif /* No. of node rx for LLL to ULL. * Reserve 3, 1 for adv data, 1 for scan response and 1 for empty PDU reception. */ #define PDU_RX_CNT (3 + BT_CTLR_ADV_EXT_RX_CNT + CONFIG_BT_CTLR_RX_BUFFERS) /* Part sum of LLL to ULL and ULL to LL/HCI thread node rx count. * Will be used below in allocating node rx pool. */ #define RX_CNT (PDU_RX_CNT + LL_PDU_RX_CNT) static MFIFO_DEFINE(pdu_rx_free, sizeof(void *), PDU_RX_CNT); #if defined(CONFIG_BT_RX_USER_PDU_LEN) #define PDU_RX_USER_PDU_OCTETS_MAX (CONFIG_BT_RX_USER_PDU_LEN) #else #define PDU_RX_USER_PDU_OCTETS_MAX 0 #endif #define PDU_ADV_SIZE MAX(PDU_AC_LL_SIZE_MAX, \ (PDU_AC_LL_HEADER_SIZE + LL_EXT_OCTETS_RX_MAX)) #define PDU_DATA_SIZE MAX((PDU_DC_LL_HEADER_SIZE + LL_LENGTH_OCTETS_RX_MAX), \ (PDU_BIS_LL_HEADER_SIZE + LL_BIS_OCTETS_RX_MAX)) #define NODE_RX_HEADER_SIZE (offsetof(struct node_rx_pdu, pdu)) #define PDU_RX_NODE_POOL_ELEMENT_SIZE MROUND(NODE_RX_HEADER_SIZE + \ MAX(MAX(PDU_ADV_SIZE, \ PDU_DATA_SIZE), \ PDU_RX_USER_PDU_OCTETS_MAX)) #if defined(CONFIG_BT_PER_ADV_SYNC_MAX) #define BT_CTLR_SCAN_SYNC_SET CONFIG_BT_PER_ADV_SYNC_MAX #else #define BT_CTLR_SCAN_SYNC_SET 0 #endif #if defined(CONFIG_BT_CTLR_SCAN_SYNC_ISO_SET) #define BT_CTLR_SCAN_SYNC_ISO_SET CONFIG_BT_CTLR_SCAN_SYNC_ISO_SET #else #define BT_CTLR_SCAN_SYNC_ISO_SET 0 #endif #define PDU_RX_POOL_SIZE (PDU_RX_NODE_POOL_ELEMENT_SIZE * \ (RX_CNT + BT_CTLR_MAX_CONNECTABLE + \ BT_CTLR_ADV_SET + BT_CTLR_SCAN_SYNC_SET)) static struct { void *free; uint8_t pool[PDU_RX_POOL_SIZE]; } mem_pdu_rx; /* NOTE: Two memq_link structures are reserved in the case of periodic sync, * one each for sync established and sync lost respectively. Where as in * comparison to a connection, the connection established uses incoming Rx-ed * CONNECT_IND PDU to piggy back generation of connection complete, and hence * only one is reserved for the generation of disconnection event (which can * happen due to supervision timeout and other reasons that dont have an * incoming Rx-ed PDU). */ #define LINK_RX_POOL_SIZE \ (sizeof(memq_link_t) * \ (RX_CNT + 2 + BT_CTLR_MAX_CONN + BT_CTLR_ADV_SET + \ (BT_CTLR_SCAN_SYNC_SET * 2) + (BT_CTLR_SCAN_SYNC_ISO_SET * 2) + \ (IQ_REPORT_CNT))) static struct { uint8_t quota_pdu; /* Number of un-utilized buffers */ void *free; uint8_t pool[LINK_RX_POOL_SIZE]; } mem_link_rx; static MEMQ_DECLARE(ull_rx); static MEMQ_DECLARE(ll_rx); #if !defined(CONFIG_BT_CTLR_LOW_LAT_ULL) static MEMQ_DECLARE(ull_done); #endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ #if defined(CONFIG_BT_CONN) static MFIFO_DEFINE(ll_pdu_rx_free, sizeof(void *), LL_PDU_RX_CNT); static MFIFO_DEFINE(tx_ack, sizeof(struct lll_tx), CONFIG_BT_BUF_ACL_TX_COUNT); static void *mark_update; #endif /* CONFIG_BT_CONN */ static void *mark_disable; static inline int init_reset(void); static void perform_lll_reset(void *param); static inline void *mark_set(void **m, void *param); static inline void *mark_unset(void **m, void *param); static inline void *mark_get(void *m); static inline void done_alloc(void); static inline void rx_alloc(uint8_t max); static void rx_demux(void *param); #if defined(CONFIG_BT_CTLR_LOW_LAT_ULL) static void rx_demux_yield(void); #endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ #if defined(CONFIG_BT_CONN) static uint8_t tx_cmplt_get(uint16_t *handle, uint8_t *first, uint8_t last); static inline void rx_demux_conn_tx_ack(uint8_t ack_last, uint16_t handle, memq_link_t *link, struct node_tx *node_tx); #endif /* CONFIG_BT_CONN */ static inline int rx_demux_rx(memq_link_t *link, struct node_rx_hdr *rx); static inline void rx_demux_event_done(memq_link_t *link, struct node_rx_hdr *rx); static inline void ll_rx_link_inc_quota(int8_t delta); static void disabled_cb(void *param); #if !defined(CONFIG_BT_CTLR_LOW_LAT_ULL) static void ull_done(void *param); #endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ int ll_init(struct k_sem *sem_rx) { int err; /* Store the semaphore to be used to wakeup Thread context */ sem_recv = sem_rx; /* Initialize counter */ /* TODO: Bind and use counter driver? */ cntr_init(); /* Initialize Mayfly */ mayfly_init(); /* Initialize Ticker */ ticker_users[MAYFLY_CALL_ID_0][0] = TICKER_USER_LLL_OPS; ticker_users[MAYFLY_CALL_ID_1][0] = TICKER_USER_ULL_HIGH_OPS; ticker_users[MAYFLY_CALL_ID_2][0] = TICKER_USER_ULL_LOW_OPS; ticker_users[MAYFLY_CALL_ID_PROGRAM][0] = TICKER_USER_THREAD_OPS; err = ticker_init(TICKER_INSTANCE_ID_CTLR, TICKER_NODES, &ticker_nodes[0], MAYFLY_CALLER_COUNT, &ticker_users[0], TICKER_USER_OPS, &ticker_user_ops[0], hal_ticker_instance0_caller_id_get, hal_ticker_instance0_sched, hal_ticker_instance0_trigger_set); LL_ASSERT(!err); /* Initialize semaphore for ticker API blocking wait */ k_sem_init(&sem_ticker_api_cb, 0, 1); /* Initialize LLL */ err = lll_init(); if (err) { return err; } /* Initialize ULL internals */ /* TODO: globals? */ /* Common to init and reset */ err = init_reset(); if (err) { return err; } #if defined(CONFIG_BT_BROADCASTER) err = lll_adv_init(); if (err) { return err; } err = ull_adv_init(); if (err) { return err; } #endif /* CONFIG_BT_BROADCASTER */ #if defined(CONFIG_BT_OBSERVER) err = lll_scan_init(); if (err) { return err; } err = ull_scan_init(); if (err) { return err; } #endif /* CONFIG_BT_OBSERVER */ #if defined(CONFIG_BT_CTLR_SYNC_PERIODIC) err = lll_sync_init(); if (err) { return err; } err = ull_sync_init(); if (err) { return err; } #if defined(CONFIG_BT_CTLR_SYNC_ISO) err = ull_sync_iso_init(); if (err) { return err; } #endif /* CONFIG_BT_CTLR_SYNC_ISO */ #endif /* CONFIG_BT_CTLR_SYNC_PERIODIC */ #if defined(CONFIG_BT_CONN) err = lll_conn_init(); if (err) { return err; } err = ull_conn_init(); if (err) { return err; } #endif /* CONFIG_BT_CONN */ #if defined(CONFIG_BT_CTLR_DF) err = ull_df_init(); if (err) { return err; } #endif #if defined(CONFIG_BT_CTLR_ISO) err = ull_iso_init(); if (err) { return err; } #endif /* CONFIG_BT_CTLR_ISO */ #if defined(CONFIG_BT_CTLR_CONN_ISO) err = ull_conn_iso_init(); if (err) { return err; } #endif /* CONFIG_BT_CTLR_CONN_ISO */ #if defined(CONFIG_BT_CTLR_PERIPHERAL_ISO) err = ull_peripheral_iso_init(); if (err) { return err; } #endif /* CONFIG_BT_CTLR_PERIPHERAL_ISO */ #if defined(CONFIG_BT_CTLR_CENTRAL_ISO) err = ull_central_iso_init(); if (err) { return err; } #endif /* CONFIG_BT_CTLR_CENTRAL_ISO */ #if defined(CONFIG_BT_CTLR_ADV_ISO) err = ull_adv_iso_init(); if (err) { return err; } #endif /* CONFIG_BT_CTLR_ADV_ISO */ #if defined(CONFIG_BT_CTLR_DF) err = lll_df_init(); if (err) { return err; } #endif #if defined(CONFIG_BT_CTLR_USER_EXT) err = ull_user_init(); if (err) { return err; } #endif /* CONFIG_BT_CTLR_USER_EXT */ /* reset filter accept list, resolving list and initialise RPA timeout*/ if (IS_ENABLED(CONFIG_BT_CTLR_FILTER_ACCEPT_LIST)) { ull_filter_reset(true); } #if defined(CONFIG_BT_CTLR_TEST) lll_chan_sel_2_ut(); #endif /* CONFIG_BT_CTLR_TEST */ return 0; } void ll_reset(void) { int err; /* Note: The sequence of reset control flow is as follows: * - Reset ULL context, i.e. stop ULL scheduling, abort LLL events etc. * - Reset LLL context, i.e. post LLL event abort, let LLL cleanup its * variables, if any. * - Reset ULL static variables (which otherwise was mem-zeroed in cases * if power-on reset wherein architecture startup mem-zeroes .bss * sections. * - Initialize ULL context variable, similar to on-power-up. */ #if defined(CONFIG_BT_BROADCASTER) /* Reset adv state */ err = ull_adv_reset(); LL_ASSERT(!err); #endif /* CONFIG_BT_BROADCASTER */ #if defined(CONFIG_BT_OBSERVER) /* Reset scan state */ err = ull_scan_reset(); LL_ASSERT(!err); #endif /* CONFIG_BT_OBSERVER */ #if defined(CONFIG_BT_CTLR_SYNC_PERIODIC) /* Reset periodic sync sets */ err = ull_sync_reset(); LL_ASSERT(!err); #if defined(CONFIG_BT_CTLR_SYNC_ISO) /* Reset periodic sync sets */ err = ull_sync_iso_reset(); LL_ASSERT(!err); #endif /* CONFIG_BT_CTLR_SYNC_PERIODIC */ #endif /* CONFIG_BT_CTLR_SYNC_PERIODIC */ #if defined(CONFIG_BT_CTLR_ISO) err = ull_iso_reset(); LL_ASSERT(!err); #endif /* CONFIG_BT_CTLR_ISO */ #if defined(CONFIG_BT_CTLR_CONN_ISO) err = ull_conn_iso_reset(); LL_ASSERT(!err); #endif /* CONFIG_BT_CTLR_CONN_ISO */ #if defined(CONFIG_BT_CTLR_PERIPHERAL_ISO) err = ull_peripheral_iso_reset(); LL_ASSERT(!err); #endif /* CONFIG_BT_CTLR_PERIPHERAL_ISO */ #if defined(CONFIG_BT_CTLR_CENTRAL_ISO) err = ull_central_iso_reset(); LL_ASSERT(!err); #endif /* CONFIG_BT_CTLR_CENTRAL_ISO */ #if defined(CONFIG_BT_CTLR_ADV_ISO) /* Reset periodic sync sets */ err = ull_adv_iso_reset(); LL_ASSERT(!err); #endif /* CONFIG_BT_CTLR_ADV_ISO */ #if defined(CONFIG_BT_CONN) /* Reset conn role */ err = ull_conn_reset(); LL_ASSERT(!err); MFIFO_INIT(tx_ack); #endif /* CONFIG_BT_CONN */ /* reset filter accept list and resolving list */ if (IS_ENABLED(CONFIG_BT_CTLR_FILTER_ACCEPT_LIST)) { ull_filter_reset(false); } /* Re-initialize ULL internals */ /* Re-initialize the prep mfifo */ MFIFO_INIT(prep); /* Re-initialize the free done mfifo */ MFIFO_INIT(done); /* Re-initialize the free rx mfifo */ MFIFO_INIT(pdu_rx_free); #if defined(CONFIG_BT_CONN) /* Re-initialize the free ll rx mfifo */ MFIFO_INIT(ll_pdu_rx_free); #endif /* CONFIG_BT_CONN */ /* Reset LLL via mayfly */ { static memq_link_t link; static struct mayfly mfy = {0, 0, &link, NULL, perform_lll_reset}; uint32_t retval; /* NOTE: If Zero Latency Interrupt is used, then LLL context * will be the highest priority IRQ in the system, hence * mayfly_enqueue will be done running the callee inline * (vector to the callee function) in this function. Else * we use semaphore to wait for perform_lll_reset to * complete. */ #if !defined(CONFIG_BT_CTLR_ZLI) struct k_sem sem; k_sem_init(&sem, 0, 1); mfy.param = &sem; #endif /* !CONFIG_BT_CTLR_ZLI */ retval = mayfly_enqueue(TICKER_USER_ID_THREAD, TICKER_USER_ID_LLL, 0, &mfy); LL_ASSERT(!retval); #if !defined(CONFIG_BT_CTLR_ZLI) /* LLL reset must complete before returning - wait for * reset completion in LLL mayfly thread */ k_sem_take(&sem, K_FOREVER); #endif /* !CONFIG_BT_CTLR_ZLI */ } #if defined(CONFIG_BT_BROADCASTER) /* Finalize after adv state LLL context reset */ err = ull_adv_reset_finalize(); LL_ASSERT(!err); #endif /* CONFIG_BT_BROADCASTER */ /* Reset/End DTM Tx or Rx commands */ if (IS_ENABLED(CONFIG_BT_CTLR_DTM)) { uint16_t num_rx; (void)ll_test_end(&num_rx); ARG_UNUSED(num_rx); } /* Common to init and reset */ err = init_reset(); LL_ASSERT(!err); #if defined(CONFIG_BT_CTLR_DF) /* Direction Finding has to be reset after ull init_reset call because * it uses mem_link_rx for node_rx_iq_report. The mem_linx_rx is reset * in common ull init_reset. */ err = ull_df_reset(); LL_ASSERT(!err); #endif } /** * @brief Peek the next node_rx to send up to Host * @details Tightly coupled with prio_recv_thread() * Execution context: Controller thread * * @param node_rx[out] Pointer to rx node at head of queue * @param handle[out] Connection handle * @return TX completed */ uint8_t ll_rx_get(void **node_rx, uint16_t *handle) { struct node_rx_hdr *rx; memq_link_t *link; uint8_t cmplt = 0U; #if defined(CONFIG_BT_CONN) || \ (defined(CONFIG_BT_OBSERVER) && defined(CONFIG_BT_CTLR_ADV_EXT)) || \ defined(CONFIG_BT_CTLR_ADV_PERIODIC) ll_rx_get_again: #endif /* CONFIG_BT_CONN || * (CONFIG_BT_OBSERVER && CONFIG_BT_CTLR_ADV_EXT) || * CONFIG_BT_CTLR_ADV_PERIODIC */ *node_rx = NULL; link = memq_peek(memq_ll_rx.head, memq_ll_rx.tail, (void **)&rx); if (link) { #if defined(CONFIG_BT_CONN) cmplt = tx_cmplt_get(handle, &mfifo_tx_ack.f, rx->ack_last); if (!cmplt) { uint8_t f, cmplt_prev, cmplt_curr; uint16_t h; cmplt_curr = 0U; f = mfifo_tx_ack.f; do { cmplt_prev = cmplt_curr; cmplt_curr = tx_cmplt_get(&h, &f, mfifo_tx_ack.l); } while ((cmplt_prev != 0U) || (cmplt_prev != cmplt_curr)); #endif /* CONFIG_BT_CONN */ if (0) { #if defined(CONFIG_BT_CONN) || \ (defined(CONFIG_BT_OBSERVER) && defined(CONFIG_BT_CTLR_ADV_EXT)) /* Do not send up buffers to Host thread that are * marked for release */ } else if (rx->type == NODE_RX_TYPE_RELEASE) { (void)memq_dequeue(memq_ll_rx.tail, &memq_ll_rx.head, NULL); mem_release(link, &mem_link_rx.free); ll_rx_link_inc_quota(1); mem_release(rx, &mem_pdu_rx.free); rx_alloc(1); goto ll_rx_get_again; #endif /* CONFIG_BT_CONN || * (CONFIG_BT_OBSERVER && CONFIG_BT_CTLR_ADV_EXT) */ #if defined(CONFIG_BT_CTLR_ADV_PERIODIC) } else if (rx->type == NODE_RX_TYPE_SYNC_CHM_COMPLETE) { (void)memq_dequeue(memq_ll_rx.tail, &memq_ll_rx.head, NULL); mem_release(link, &mem_link_rx.free); ll_rx_link_inc_quota(1); /* Remove Channel Map Update Indication from * ACAD. */ ull_adv_sync_chm_complete(rx); mem_release(rx, &mem_pdu_rx.free); rx_alloc(1); goto ll_rx_get_again; #endif /* CONFIG_BT_CTLR_ADV_PERIODIC */ } *node_rx = rx; #if defined(CONFIG_BT_CONN) } } else { cmplt = tx_cmplt_get(handle, &mfifo_tx_ack.f, mfifo_tx_ack.l); #endif /* CONFIG_BT_CONN */ } return cmplt; } /** * @brief Commit the dequeue from memq_ll_rx, where ll_rx_get() did the peek * @details Execution context: Controller thread */ void ll_rx_dequeue(void) { struct node_rx_hdr *rx = NULL; memq_link_t *link; link = memq_dequeue(memq_ll_rx.tail, &memq_ll_rx.head, (void **)&rx); LL_ASSERT(link); mem_release(link, &mem_link_rx.free); /* handle object specific clean up */ switch (rx->type) { #if defined(CONFIG_BT_CTLR_ADV_EXT) #if defined(CONFIG_BT_OBSERVER) case NODE_RX_TYPE_EXT_1M_REPORT: case NODE_RX_TYPE_EXT_2M_REPORT: case NODE_RX_TYPE_EXT_CODED_REPORT: #if defined(CONFIG_BT_CTLR_SYNC_PERIODIC) case NODE_RX_TYPE_SYNC_REPORT: #endif /* CONFIG_BT_CTLR_SYNC_PERIODIC */ { struct node_rx_hdr *rx_curr; struct pdu_adv *adv; adv = (void *)((struct node_rx_pdu *)rx)->pdu; if (adv->type != PDU_ADV_TYPE_EXT_IND) { break; } rx_curr = rx->rx_ftr.extra; while (rx_curr) { memq_link_t *link_free; link_free = rx_curr->link; rx_curr = rx_curr->rx_ftr.extra; mem_release(link_free, &mem_link_rx.free); } } break; case NODE_RX_TYPE_EXT_SCAN_TERMINATE: { ull_scan_term_dequeue(rx->handle); } break; #endif /* CONFIG_BT_OBSERVER */ #if defined(CONFIG_BT_BROADCASTER) case NODE_RX_TYPE_EXT_ADV_TERMINATE: { struct ll_adv_set *adv; struct lll_adv_aux *lll_aux; adv = ull_adv_set_get(rx->handle); LL_ASSERT(adv); lll_aux = adv->lll.aux; if (lll_aux) { struct ll_adv_aux_set *aux; aux = HDR_LLL2ULL(lll_aux); aux->is_started = 0U; } #if defined(CONFIG_BT_PERIPHERAL) struct lll_conn *lll_conn = adv->lll.conn; if (!lll_conn) { adv->is_enabled = 0U; break; } LL_ASSERT(!lll_conn->link_tx_free); memq_link_t *link = memq_deinit(&lll_conn->memq_tx.head, &lll_conn->memq_tx.tail); LL_ASSERT(link); lll_conn->link_tx_free = link; struct ll_conn *conn = HDR_LLL2ULL(lll_conn); ll_conn_release(conn); adv->lll.conn = NULL; ll_rx_release(adv->node_rx_cc_free); adv->node_rx_cc_free = NULL; ll_rx_link_release(adv->link_cc_free); adv->link_cc_free = NULL; #endif /* CONFIG_BT_PERIPHERAL */ adv->is_enabled = 0U; } break; #endif /* CONFIG_BT_BROADCASTER */ #endif /* CONFIG_BT_CTLR_ADV_EXT */ #if defined(CONFIG_BT_CONN) case NODE_RX_TYPE_CONNECTION: { struct node_rx_cc *cc = (void *)((struct node_rx_pdu *)rx)->pdu; struct node_rx_ftr *ftr = &(rx->rx_ftr); if (0) { #if defined(CONFIG_BT_PERIPHERAL) } else if ((cc->status == BT_HCI_ERR_ADV_TIMEOUT) || cc->role) { struct ll_adv_set *adv; struct lll_adv *lll; /* Get reference to ULL context */ lll = ftr->param; adv = HDR_LLL2ULL(lll); if (cc->status == BT_HCI_ERR_ADV_TIMEOUT) { struct lll_conn *conn_lll; struct ll_conn *conn; memq_link_t *link; conn_lll = lll->conn; LL_ASSERT(conn_lll); lll->conn = NULL; LL_ASSERT(!conn_lll->link_tx_free); link = memq_deinit(&conn_lll->memq_tx.head, &conn_lll->memq_tx.tail); LL_ASSERT(link); conn_lll->link_tx_free = link; conn = HDR_LLL2ULL(conn_lll); ll_conn_release(conn); } else { /* Release un-utilized node rx */ if (adv->node_rx_cc_free) { void *rx_free; rx_free = adv->node_rx_cc_free; adv->node_rx_cc_free = NULL; mem_release(rx_free, &mem_pdu_rx.free); } } #if defined(CONFIG_BT_CTLR_ADV_EXT) if (lll->aux) { struct ll_adv_aux_set *aux; aux = HDR_LLL2ULL(lll->aux); aux->is_started = 0U; } #endif /* CONFIG_BT_CTLR_ADV_EXT */ adv->is_enabled = 0U; #else /* !CONFIG_BT_PERIPHERAL */ ARG_UNUSED(cc); #endif /* !CONFIG_BT_PERIPHERAL */ #if defined(CONFIG_BT_CENTRAL) } else { struct ll_scan_set *scan = HDR_LLL2ULL(ftr->param); #if defined(CONFIG_BT_CTLR_ADV_EXT) && defined(CONFIG_BT_CTLR_PHY_CODED) struct ll_scan_set *scan_other = ull_scan_is_enabled_get(SCAN_HANDLE_PHY_CODED); if (scan_other) { if (scan_other == scan) { scan_other = ull_scan_is_enabled_get(SCAN_HANDLE_1M); } if (scan_other) { scan_other->lll.conn = NULL; scan_other->is_enabled = 0U; } } #endif /* CONFIG_BT_CTLR_ADV_EXT && CONFIG_BT_CTLR_PHY_CODED */ scan->lll.conn = NULL; scan->is_enabled = 0U; #else /* !CONFIG_BT_CENTRAL */ } else { LL_ASSERT(0); #endif /* !CONFIG_BT_CENTRAL */ } if (IS_ENABLED(CONFIG_BT_CTLR_PRIVACY)) { uint8_t bm; /* FIXME: use the correct adv and scan set to get * enabled status bitmask */ bm = (IS_ENABLED(CONFIG_BT_OBSERVER) && (ull_scan_is_enabled(0) << 1)) | (IS_ENABLED(CONFIG_BT_BROADCASTER) && ull_adv_is_enabled(0)); if (!bm) { ull_filter_adv_scan_state_cb(0); } } } break; case NODE_RX_TYPE_TERMINATE: case NODE_RX_TYPE_DC_PDU: #endif /* CONFIG_BT_CONN */ #if defined(CONFIG_BT_OBSERVER) case NODE_RX_TYPE_REPORT: #if defined(CONFIG_BT_CTLR_SYNC_PERIODIC) /* fall through */ case NODE_RX_TYPE_SYNC: case NODE_RX_TYPE_SYNC_LOST: #endif /* CONFIG_BT_CTLR_SYNC_PERIODIC */ #endif /* CONFIG_BT_OBSERVER */ #if defined(CONFIG_BT_CTLR_SCAN_REQ_NOTIFY) case NODE_RX_TYPE_SCAN_REQ: #endif /* CONFIG_BT_CTLR_SCAN_REQ_NOTIFY */ #if defined(CONFIG_BT_CONN) case NODE_RX_TYPE_CONN_UPDATE: case NODE_RX_TYPE_ENC_REFRESH: #if defined(CONFIG_BT_CTLR_LE_PING) case NODE_RX_TYPE_APTO: #endif /* CONFIG_BT_CTLR_LE_PING */ case NODE_RX_TYPE_CHAN_SEL_ALGO: #if defined(CONFIG_BT_CTLR_PHY) case NODE_RX_TYPE_PHY_UPDATE: #endif /* CONFIG_BT_CTLR_PHY */ #if defined(CONFIG_BT_CTLR_CONN_RSSI_EVENT) case NODE_RX_TYPE_RSSI: #endif /* CONFIG_BT_CTLR_CONN_RSSI_EVENT */ #endif /* CONFIG_BT_CONN */ #if defined(CONFIG_BT_CTLR_PROFILE_ISR) case NODE_RX_TYPE_PROFILE: #endif /* CONFIG_BT_CTLR_PROFILE_ISR */ #if defined(CONFIG_BT_CTLR_ADV_INDICATION) case NODE_RX_TYPE_ADV_INDICATION: #endif /* CONFIG_BT_CTLR_ADV_INDICATION */ #if defined(CONFIG_BT_CTLR_SCAN_INDICATION) case NODE_RX_TYPE_SCAN_INDICATION: #endif /* CONFIG_BT_CTLR_SCAN_INDICATION */ #if defined(CONFIG_BT_HCI_MESH_EXT) case NODE_RX_TYPE_MESH_ADV_CPLT: case NODE_RX_TYPE_MESH_REPORT: #endif /* CONFIG_BT_HCI_MESH_EXT */ #if CONFIG_BT_CTLR_USER_EVT_RANGE > 0 case NODE_RX_TYPE_USER_START ... NODE_RX_TYPE_USER_END - 1: __fallthrough; #endif /* CONFIG_BT_CTLR_USER_EVT_RANGE > 0 */ #if defined(CONFIG_BT_CTLR_PERIPHERAL_ISO) case NODE_RX_TYPE_CIS_REQUEST: #endif /* CONFIG_BT_CTLR_PERIPHERAL_ISO */ #if defined(CONFIG_BT_CTLR_CONN_ISO) case NODE_RX_TYPE_CIS_ESTABLISHED: #endif /* CONFIG_BT_CTLR_CONN_ISO */ #if defined(CONFIG_BT_CTLR_ISO) case NODE_RX_TYPE_ISO_PDU: #endif #if defined(CONFIG_BT_CTLR_DF_SCAN_CTE_RX) case NODE_RX_TYPE_IQ_SAMPLE_REPORT: #endif /* CONFIG_BT_CTLR_DF_SCAN_CTE_RX */ /* Ensure that at least one 'case' statement is present for this * code block. */ case NODE_RX_TYPE_NONE: LL_ASSERT(rx->type != NODE_RX_TYPE_NONE); break; default: LL_ASSERT(0); break; } /* FIXME: clean up when porting Mesh Ext. */ if (0) { #if defined(CONFIG_BT_HCI_MESH_EXT) } else if (rx->type == NODE_RX_TYPE_MESH_ADV_CPLT) { struct ll_adv_set *adv; struct ll_scan_set *scan; adv = ull_adv_is_enabled_get(0); LL_ASSERT(adv); adv->is_enabled = 0U; scan = ull_scan_is_enabled_get(0); LL_ASSERT(scan); scan->is_enabled = 0U; ll_adv_scan_state_cb(0); #endif /* CONFIG_BT_HCI_MESH_EXT */ } } void ll_rx_mem_release(void **node_rx) { struct node_rx_hdr *rx; rx = *node_rx; while (rx) { struct node_rx_hdr *rx_free; rx_free = rx; rx = rx->next; switch (rx_free->type) { #if defined(CONFIG_BT_BROADCASTER) #if defined(CONFIG_BT_CTLR_ADV_EXT) case NODE_RX_TYPE_EXT_ADV_TERMINATE: mem_release(rx_free, &mem_pdu_rx.free); break; #endif /* CONFIG_BT_CTLR_ADV_EXT */ #endif /* CONFIG_BT_BROADCASTER */ #if defined(CONFIG_BT_OBSERVER) #if defined(CONFIG_BT_CTLR_ADV_EXT) case NODE_RX_TYPE_EXT_SCAN_TERMINATE: { mem_release(rx_free, &mem_pdu_rx.free); } break; #endif /* CONFIG_BT_CTLR_ADV_EXT */ #endif /* CONFIG_BT_OBSERVER */ #if defined(CONFIG_BT_CONN) case NODE_RX_TYPE_CONNECTION: { struct node_rx_cc *cc = (void *)((struct node_rx_pdu *)rx_free)->pdu; if (0) { #if defined(CONFIG_BT_PERIPHERAL) } else if (cc->status == BT_HCI_ERR_ADV_TIMEOUT) { mem_release(rx_free, &mem_pdu_rx.free); break; #endif /* !CONFIG_BT_PERIPHERAL */ #if defined(CONFIG_BT_CENTRAL) } else if (cc->status == BT_HCI_ERR_UNKNOWN_CONN_ID) { ull_central_cleanup(rx_free); #if defined(CONFIG_BT_CTLR_PRIVACY) #if defined(CONFIG_BT_BROADCASTER) if (!ull_adv_is_enabled_get(0)) #endif /* CONFIG_BT_BROADCASTER */ { ull_filter_adv_scan_state_cb(0); } #endif /* CONFIG_BT_CTLR_PRIVACY */ break; #endif /* CONFIG_BT_CENTRAL */ } else { LL_ASSERT(!cc->status); } } __fallthrough; case NODE_RX_TYPE_DC_PDU: #endif /* CONFIG_BT_CONN */ #if defined(CONFIG_BT_OBSERVER) case NODE_RX_TYPE_REPORT: #if defined(CONFIG_BT_CTLR_ADV_EXT) __fallthrough; case NODE_RX_TYPE_EXT_1M_REPORT: case NODE_RX_TYPE_EXT_2M_REPORT: case NODE_RX_TYPE_EXT_CODED_REPORT: #if defined(CONFIG_BT_CTLR_SYNC_PERIODIC) case NODE_RX_TYPE_SYNC_REPORT: #endif /* CONFIG_BT_CTLR_SYNC_PERIODIC */ #endif /* CONFIG_BT_CTLR_ADV_EXT */ #endif /* CONFIG_BT_OBSERVER */ #if defined(CONFIG_BT_CTLR_SCAN_REQ_NOTIFY) case NODE_RX_TYPE_SCAN_REQ: #endif /* CONFIG_BT_CTLR_SCAN_REQ_NOTIFY */ #if defined(CONFIG_BT_CONN) case NODE_RX_TYPE_CONN_UPDATE: case NODE_RX_TYPE_ENC_REFRESH: #if defined(CONFIG_BT_CTLR_LE_PING) case NODE_RX_TYPE_APTO: #endif /* CONFIG_BT_CTLR_LE_PING */ case NODE_RX_TYPE_CHAN_SEL_ALGO: #if defined(CONFIG_BT_CTLR_PHY) case NODE_RX_TYPE_PHY_UPDATE: #endif /* CONFIG_BT_CTLR_PHY */ #if defined(CONFIG_BT_CTLR_CONN_RSSI_EVENT) case NODE_RX_TYPE_RSSI: #endif /* CONFIG_BT_CTLR_CONN_RSSI_EVENT */ #endif /* CONFIG_BT_CONN */ #if defined(CONFIG_BT_CTLR_PROFILE_ISR) case NODE_RX_TYPE_PROFILE: #endif /* CONFIG_BT_CTLR_PROFILE_ISR */ #if defined(CONFIG_BT_CTLR_ADV_INDICATION) case NODE_RX_TYPE_ADV_INDICATION: #endif /* CONFIG_BT_CTLR_ADV_INDICATION */ #if defined(CONFIG_BT_CTLR_SCAN_INDICATION) case NODE_RX_TYPE_SCAN_INDICATION: #endif /* CONFIG_BT_CTLR_SCAN_INDICATION */ #if defined(CONFIG_BT_HCI_MESH_EXT) case NODE_RX_TYPE_MESH_ADV_CPLT: case NODE_RX_TYPE_MESH_REPORT: #endif /* CONFIG_BT_HCI_MESH_EXT */ #if CONFIG_BT_CTLR_USER_EVT_RANGE > 0 case NODE_RX_TYPE_USER_START ... NODE_RX_TYPE_USER_END - 1: #endif /* CONFIG_BT_CTLR_USER_EVT_RANGE > 0 */ #if defined(CONFIG_BT_CTLR_PERIPHERAL_ISO) case NODE_RX_TYPE_CIS_REQUEST: #endif /* CONFIG_BT_CTLR_PERIPHERAL_ISO */ #if defined(CONFIG_BT_CTLR_CONN_ISO) case NODE_RX_TYPE_CIS_ESTABLISHED: #endif /* CONFIG_BT_CTLR_CONN_ISO */ #if defined(CONFIG_BT_CTLR_ISO) case NODE_RX_TYPE_ISO_PDU: #endif /* Ensure that at least one 'case' statement is present for this * code block. */ case NODE_RX_TYPE_NONE: LL_ASSERT(rx_free->type != NODE_RX_TYPE_NONE); ll_rx_link_inc_quota(1); mem_release(rx_free, &mem_pdu_rx.free); break; #if defined(CONFIG_BT_CTLR_SYNC_PERIODIC) case NODE_RX_TYPE_SYNC: { struct node_rx_sync *se = (void *)((struct node_rx_pdu *)rx_free)->pdu; if (!se->status) { mem_release(rx_free, &mem_pdu_rx.free); break; } } /* Pass through */ case NODE_RX_TYPE_SYNC_LOST: { struct ll_sync_set *sync = (void *)rx_free->rx_ftr.param; sync->timeout_reload = 0U; ull_sync_release(sync); } break; #if defined(CONFIG_BT_CTLR_DF_SCAN_CTE_RX) case NODE_RX_TYPE_IQ_SAMPLE_REPORT: { ull_iq_report_link_inc_quota(1); ull_df_iq_report_mem_release(rx_free); ull_df_rx_iq_report_alloc(1); } break; #endif /* CONFIG_BT_CTLR_DF_SCAN_CTE_RX */ #endif /* CONFIG_BT_CTLR_SYNC_PERIODIC */ #if defined(CONFIG_BT_CONN) case NODE_RX_TYPE_TERMINATE: { struct ll_conn *conn; memq_link_t *link; conn = ll_conn_get(rx_free->handle); LL_ASSERT(!conn->lll.link_tx_free); link = memq_deinit(&conn->lll.memq_tx.head, &conn->lll.memq_tx.tail); LL_ASSERT(link); conn->lll.link_tx_free = link; ll_conn_release(conn); } break; #endif /* CONFIG_BT_CONN */ case NODE_RX_TYPE_EVENT_DONE: default: LL_ASSERT(0); break; } } *node_rx = rx; rx_alloc(UINT8_MAX); } static inline void ll_rx_link_inc_quota(int8_t delta) { LL_ASSERT(delta <= 0 || mem_link_rx.quota_pdu < RX_CNT); mem_link_rx.quota_pdu += delta; } void *ll_rx_link_alloc(void) { return mem_acquire(&mem_link_rx.free); } void ll_rx_link_release(void *link) { mem_release(link, &mem_link_rx.free); } void *ll_rx_alloc(void) { return mem_acquire(&mem_pdu_rx.free); } void ll_rx_release(void *node_rx) { mem_release(node_rx, &mem_pdu_rx.free); } void ll_rx_put(memq_link_t *link, void *rx) { #if defined(CONFIG_BT_CONN) struct node_rx_hdr *rx_hdr = rx; /* Serialize Tx ack with Rx enqueue by storing reference to * last element index in Tx ack FIFO. */ rx_hdr->ack_last = mfifo_tx_ack.l; #endif /* CONFIG_BT_CONN */ /* Enqueue the Rx object */ memq_enqueue(link, rx, &memq_ll_rx.tail); } /** * @brief Permit another loop in the controller thread (prio_recv_thread) * @details Execution context: ULL mayfly */ void ll_rx_sched(void) { /* sem_recv references the same semaphore (sem_prio_recv) * in prio_recv_thread */ k_sem_give(sem_recv); } #if defined(CONFIG_BT_CONN) void *ll_pdu_rx_alloc_peek(uint8_t count) { if (count > MFIFO_AVAIL_COUNT_GET(ll_pdu_rx_free)) { return NULL; } return MFIFO_DEQUEUE_PEEK(ll_pdu_rx_free); } void *ll_pdu_rx_alloc(void) { return MFIFO_DEQUEUE(ll_pdu_rx_free); } void ll_tx_ack_put(uint16_t handle, struct node_tx *node_tx) { struct lll_tx *tx; uint8_t idx; idx = MFIFO_ENQUEUE_GET(tx_ack, (void **)&tx); LL_ASSERT(tx); tx->handle = handle; tx->node = node_tx; MFIFO_ENQUEUE(tx_ack, idx); } #endif /* CONFIG_BT_CONN */ void ll_timeslice_ticker_id_get(uint8_t * const instance_index, uint8_t * const ticker_id) { *instance_index = TICKER_INSTANCE_ID_CTLR; *ticker_id = (TICKER_NODES - FLASH_TICKER_NODES); } void ll_radio_state_abort(void) { static memq_link_t link; static struct mayfly mfy = {0, 0, &link, NULL, lll_disable}; uint32_t ret; ret = mayfly_enqueue(TICKER_USER_ID_ULL_HIGH, TICKER_USER_ID_LLL, 0, &mfy); LL_ASSERT(!ret); } uint32_t ll_radio_state_is_idle(void) { return lll_radio_is_idle(); } void ull_ticker_status_give(uint32_t status, void *param) { *((uint32_t volatile *)param) = status; k_sem_give(&sem_ticker_api_cb); } uint32_t ull_ticker_status_take(uint32_t ret, uint32_t volatile *ret_cb) { if (ret == TICKER_STATUS_BUSY) { /* TODO: Enable ticker job in case of CONFIG_BT_CTLR_LOW_LAT */ } else { /* Check for ticker operation enqueue failed, in which case * function return value (ret) will be TICKER_STATUS_FAILURE * and callback return value (ret_cb) will remain as * TICKER_STATUS_BUSY. * This assert check will avoid waiting forever to take the * semaphore that will never be given when the ticker operation * callback does not get called due to enqueue failure. */ LL_ASSERT((ret == TICKER_STATUS_SUCCESS) || (*ret_cb != TICKER_STATUS_BUSY)); } k_sem_take(&sem_ticker_api_cb, K_FOREVER); return *ret_cb; } void *ull_disable_mark(void *param) { return mark_set(&mark_disable, param); } void *ull_disable_unmark(void *param) { return mark_unset(&mark_disable, param); } void *ull_disable_mark_get(void) { return mark_get(mark_disable); } /** * @brief Stops a specified ticker using the ull_disable_(un)mark functions. * * @param ticker_handle The handle of the ticker. * @param param The object to mark. * @param lll_disable Optional object when calling @ref ull_disable * * @return 0 if success, else ERRNO. */ int ull_ticker_stop_with_mark(uint8_t ticker_handle, void *param, void *lll_disable) { uint32_t volatile ret_cb; uint32_t ret; void *mark; mark = ull_disable_mark(param); if (mark != param) { return -ENOLCK; } ret_cb = TICKER_STATUS_BUSY; ret = ticker_stop(TICKER_INSTANCE_ID_CTLR, TICKER_USER_ID_THREAD, ticker_handle, ull_ticker_status_give, (void *)&ret_cb); ret = ull_ticker_status_take(ret, &ret_cb); if (ret) { mark = ull_disable_unmark(param); if (mark != param) { return -ENOLCK; } return -EALREADY; } ret = ull_disable(lll_disable); if (ret) { return -EBUSY; } mark = ull_disable_unmark(param); if (mark != param) { return -ENOLCK; } return 0; } #if defined(CONFIG_BT_CONN) void *ull_update_mark(void *param) { return mark_set(&mark_update, param); } void *ull_update_unmark(void *param) { return mark_unset(&mark_update, param); } void *ull_update_mark_get(void) { return mark_get(mark_update); } #endif /* CONFIG_BT_CONN */ int ull_disable(void *lll) { static memq_link_t link; static struct mayfly mfy = {0, 0, &link, NULL, lll_disable}; struct ull_hdr *hdr; struct k_sem sem; uint32_t ret; hdr = HDR_LLL2ULL(lll); if (!hdr || !ull_ref_get(hdr)) { return 0; } k_sem_init(&sem, 0, 1); hdr->disabled_param = &sem; hdr->disabled_cb = disabled_cb; /* ULL_HIGH can run after we have call `ull_ref_get` and it can * decrement the ref count. Hence, handle this race condition by * ensuring that `disabled_cb` has been set while the ref count is still * set. * No need to call `lll_disable` and take the semaphore thereafter if * reference count is zero. * If the `sem` is given when reference count was decremented, we do not * care. */ if (!ull_ref_get(hdr)) { return 0; } mfy.param = lll; ret = mayfly_enqueue(TICKER_USER_ID_THREAD, TICKER_USER_ID_LLL, 0, &mfy); LL_ASSERT(!ret); return k_sem_take(&sem, K_FOREVER); } void *ull_pdu_rx_alloc_peek(uint8_t count) { if (count > MFIFO_AVAIL_COUNT_GET(pdu_rx_free)) { return NULL; } return MFIFO_DEQUEUE_PEEK(pdu_rx_free); } void *ull_pdu_rx_alloc_peek_iter(uint8_t *idx) { return *(void **)MFIFO_DEQUEUE_ITER_GET(pdu_rx_free, idx); } void *ull_pdu_rx_alloc(void) { return MFIFO_DEQUEUE(pdu_rx_free); } void ull_rx_put(memq_link_t *link, void *rx) { #if defined(CONFIG_BT_CONN) struct node_rx_hdr *rx_hdr = rx; /* Serialize Tx ack with Rx enqueue by storing reference to * last element index in Tx ack FIFO. */ rx_hdr->ack_last = ull_conn_ack_last_idx_get(); #endif /* CONFIG_BT_CONN */ /* Enqueue the Rx object */ memq_enqueue(link, rx, &memq_ull_rx.tail); } void ull_rx_sched(void) { static memq_link_t link; static struct mayfly mfy = {0, 0, &link, NULL, rx_demux}; /* Kick the ULL (using the mayfly, tailchain it) */ mayfly_enqueue(TICKER_USER_ID_LLL, TICKER_USER_ID_ULL_HIGH, 1, &mfy); } #if !defined(CONFIG_BT_CTLR_LOW_LAT_ULL) void ull_rx_put_done(memq_link_t *link, void *done) { /* Enqueue the done object */ memq_enqueue(link, done, &memq_ull_done.tail); } void ull_rx_sched_done(void) { static memq_link_t link; static struct mayfly mfy = {0, 0, &link, NULL, ull_done}; /* Kick the ULL (using the mayfly, tailchain it) */ mayfly_enqueue(TICKER_USER_ID_LLL, TICKER_USER_ID_ULL_HIGH, 1, &mfy); } #endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ struct lll_event *ull_prepare_enqueue(lll_is_abort_cb_t is_abort_cb, lll_abort_cb_t abort_cb, struct lll_prepare_param *prepare_param, lll_prepare_cb_t prepare_cb, uint8_t is_resume) { struct lll_event *e; uint8_t idx; idx = MFIFO_ENQUEUE_GET(prep, (void **)&e); if (!e) { return NULL; } memcpy(&e->prepare_param, prepare_param, sizeof(e->prepare_param)); e->prepare_cb = prepare_cb; e->is_abort_cb = is_abort_cb; e->abort_cb = abort_cb; e->is_resume = is_resume; e->is_aborted = 0U; MFIFO_ENQUEUE(prep, idx); return e; } void *ull_prepare_dequeue_get(void) { return MFIFO_DEQUEUE_GET(prep); } void *ull_prepare_dequeue_iter(uint8_t *idx) { return MFIFO_DEQUEUE_ITER_GET(prep, idx); } void ull_prepare_dequeue(uint8_t caller_id) { struct lll_event *next; next = ull_prepare_dequeue_get(); while (next) { uint8_t is_aborted = next->is_aborted; uint8_t is_resume = next->is_resume; if (!is_aborted) { static memq_link_t link; static struct mayfly mfy = {0, 0, &link, NULL, lll_resume}; uint32_t ret; mfy.param = next; ret = mayfly_enqueue(caller_id, TICKER_USER_ID_LLL, 0, &mfy); LL_ASSERT(!ret); } MFIFO_DEQUEUE(prep); next = ull_prepare_dequeue_get(); if (!next || (!is_aborted && (!is_resume || next->is_resume))) { break; } } } struct event_done_extra *ull_event_done_extra_get(void) { struct node_rx_event_done *evdone; evdone = MFIFO_DEQUEUE_PEEK(done); if (!evdone) { return NULL; } return &evdone->extra; } struct event_done_extra *ull_done_extra_type_set(uint8_t type) { struct event_done_extra *extra; extra = ull_event_done_extra_get(); if (!extra) { return NULL; } extra->type = type; return extra; } void *ull_event_done(void *param) { struct node_rx_event_done *evdone; memq_link_t *link; /* Obtain new node that signals "Done of an RX-event". * Obtain this by dequeuing from the global 'mfifo_done' queue. * Note that 'mfifo_done' is a queue of pointers, not of * struct node_rx_event_done */ evdone = MFIFO_DEQUEUE(done); if (!evdone) { /* Not fatal if we can not obtain node, though * we will loose the packets in software stack. * If this happens during Conn Upd, this could cause LSTO */ return NULL; } link = evdone->hdr.link; evdone->hdr.link = NULL; evdone->hdr.type = NODE_RX_TYPE_EVENT_DONE; evdone->param = param; #if !defined(CONFIG_BT_CTLR_LOW_LAT_ULL) ull_rx_put_done(link, evdone); ull_rx_sched_done(); #else ull_rx_put(link, evdone); ull_rx_sched(); #endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ return evdone; } #if defined(CONFIG_BT_PERIPHERAL) || defined(CONFIG_BT_CTLR_SYNC_PERIODIC) /** * @brief Extract timing from completed event * * @param node_rx_event_done[in] Done event containing fresh timing information * @param ticks_drift_plus[out] Positive part of drift uncertainty window * @param ticks_drift_minus[out] Negative part of drift uncertainty window */ void ull_drift_ticks_get(struct node_rx_event_done *done, uint32_t *ticks_drift_plus, uint32_t *ticks_drift_minus) { uint32_t start_to_address_expected_us; uint32_t start_to_address_actual_us; uint32_t window_widening_event_us; uint32_t preamble_to_addr_us; start_to_address_actual_us = done->extra.drift.start_to_address_actual_us; window_widening_event_us = done->extra.drift.window_widening_event_us; preamble_to_addr_us = done->extra.drift.preamble_to_addr_us; start_to_address_expected_us = EVENT_JITTER_US + EVENT_TICKER_RES_MARGIN_US + window_widening_event_us + preamble_to_addr_us; if (start_to_address_actual_us <= start_to_address_expected_us) { *ticks_drift_plus = HAL_TICKER_US_TO_TICKS(window_widening_event_us); *ticks_drift_minus = HAL_TICKER_US_TO_TICKS((start_to_address_expected_us - start_to_address_actual_us)); } else { *ticks_drift_plus = HAL_TICKER_US_TO_TICKS(start_to_address_actual_us); *ticks_drift_minus = HAL_TICKER_US_TO_TICKS(EVENT_JITTER_US + EVENT_TICKER_RES_MARGIN_US + preamble_to_addr_us); } } #endif /* CONFIG_BT_PERIPHERAL || CONFIG_BT_CTLR_SYNC_PERIODIC */ static inline int init_reset(void) { memq_link_t *link; /* Initialize done pool. */ mem_init(mem_done.pool, sizeof(struct node_rx_event_done), EVENT_DONE_MAX, &mem_done.free); /* Initialize done link pool. */ mem_init(mem_link_done.pool, sizeof(memq_link_t), EVENT_DONE_MAX + EVENT_DONE_LINK_CNT, &mem_link_done.free); /* Allocate done buffers */ done_alloc(); /* Initialize rx pool. */ mem_init(mem_pdu_rx.pool, (PDU_RX_NODE_POOL_ELEMENT_SIZE), sizeof(mem_pdu_rx.pool) / (PDU_RX_NODE_POOL_ELEMENT_SIZE), &mem_pdu_rx.free); /* Initialize rx link pool. */ mem_init(mem_link_rx.pool, sizeof(memq_link_t), sizeof(mem_link_rx.pool) / sizeof(memq_link_t), &mem_link_rx.free); /* Acquire a link to initialize ull rx memq */ link = mem_acquire(&mem_link_rx.free); LL_ASSERT(link); /* Initialize ull rx memq */ MEMQ_INIT(ull_rx, link); #if !defined(CONFIG_BT_CTLR_LOW_LAT_ULL) /* Acquire a link to initialize ull done memq */ link = mem_acquire(&mem_link_done.free); LL_ASSERT(link); /* Initialize ull done memq */ MEMQ_INIT(ull_done, link); #endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ /* Acquire a link to initialize ll rx memq */ link = mem_acquire(&mem_link_rx.free); LL_ASSERT(link); /* Initialize ll rx memq */ MEMQ_INIT(ll_rx, link); /* Allocate rx free buffers */ mem_link_rx.quota_pdu = RX_CNT; rx_alloc(UINT8_MAX); return 0; } static void perform_lll_reset(void *param) { int err; /* Reset LLL */ err = lll_reset(); LL_ASSERT(!err); #if defined(CONFIG_BT_BROADCASTER) /* Reset adv state */ err = lll_adv_reset(); LL_ASSERT(!err); #endif /* CONFIG_BT_BROADCASTER */ #if defined(CONFIG_BT_OBSERVER) /* Reset scan state */ err = lll_scan_reset(); LL_ASSERT(!err); #endif /* CONFIG_BT_OBSERVER */ #if defined(CONFIG_BT_CONN) /* Reset conn role */ err = lll_conn_reset(); LL_ASSERT(!err); #endif /* CONFIG_BT_CONN */ #if defined(CONFIG_BT_CTLR_DF) err = lll_df_reset(); LL_ASSERT(!err); #endif /* CONFIG_BT_CTLR_DF */ #if !defined(CONFIG_BT_CTLR_ZLI) k_sem_give(param); #endif /* !CONFIG_BT_CTLR_ZLI */ } static inline void *mark_set(void **m, void *param) { if (!*m) { *m = param; } return *m; } static inline void *mark_unset(void **m, void *param) { if (*m && *m == param) { *m = NULL; return param; } return NULL; } static inline void *mark_get(void *m) { return m; } /** * @brief Allocate buffers for done events */ static inline void done_alloc(void) { uint8_t idx; /* mfifo_done is a queue of pointers */ while (MFIFO_ENQUEUE_IDX_GET(done, &idx)) { memq_link_t *link; struct node_rx_hdr *rx; link = mem_acquire(&mem_link_done.free); if (!link) { break; } rx = mem_acquire(&mem_done.free); if (!rx) { mem_release(link, &mem_link_done.free); break; } rx->link = link; MFIFO_BY_IDX_ENQUEUE(done, idx, rx); } } static inline void *done_release(memq_link_t *link, struct node_rx_event_done *done) { uint8_t idx; if (!MFIFO_ENQUEUE_IDX_GET(done, &idx)) { return NULL; } done->hdr.link = link; MFIFO_BY_IDX_ENQUEUE(done, idx, done); return done; } static inline void rx_alloc(uint8_t max) { uint8_t idx; if (max > mem_link_rx.quota_pdu) { max = mem_link_rx.quota_pdu; } while (max && MFIFO_ENQUEUE_IDX_GET(pdu_rx_free, &idx)) { memq_link_t *link; struct node_rx_hdr *rx; link = mem_acquire(&mem_link_rx.free); if (!link) { return; } rx = mem_acquire(&mem_pdu_rx.free); if (!rx) { mem_release(link, &mem_link_rx.free); return; } rx->link = link; MFIFO_BY_IDX_ENQUEUE(pdu_rx_free, idx, rx); ll_rx_link_inc_quota(-1); max--; } #if defined(CONFIG_BT_CONN) if (!max) { return; } /* Replenish the ULL to LL/HCI free Rx PDU queue after LLL to ULL free * Rx PDU queue has been filled. */ while (mem_link_rx.quota_pdu && MFIFO_ENQUEUE_IDX_GET(ll_pdu_rx_free, &idx)) { memq_link_t *link; struct node_rx_hdr *rx; link = mem_acquire(&mem_link_rx.free); if (!link) { return; } rx = mem_acquire(&mem_pdu_rx.free); if (!rx) { mem_release(link, &mem_link_rx.free); return; } link->mem = NULL; rx->link = link; MFIFO_BY_IDX_ENQUEUE(ll_pdu_rx_free, idx, rx); ll_rx_link_inc_quota(-1); } #endif /* CONFIG_BT_CONN */ } static void rx_demux(void *param) { memq_link_t *link; #if !defined(CONFIG_BT_CTLR_LOW_LAT_ULL) do { #endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ struct node_rx_hdr *rx; link = memq_peek(memq_ull_rx.head, memq_ull_rx.tail, (void **)&rx); if (link) { #if defined(CONFIG_BT_CONN) struct node_tx *node_tx; memq_link_t *link_tx; uint16_t handle; /* Handle to Ack TX */ #endif /* CONFIG_BT_CONN */ int nack = 0; LL_ASSERT(rx); #if defined(CONFIG_BT_CONN) link_tx = ull_conn_ack_by_last_peek(rx->ack_last, &handle, &node_tx); if (link_tx) { rx_demux_conn_tx_ack(rx->ack_last, handle, link_tx, node_tx); } else #endif /* CONFIG_BT_CONN */ { nack = rx_demux_rx(link, rx); } #if defined(CONFIG_BT_CTLR_LOW_LAT_ULL) if (!nack) { rx_demux_yield(); } #else /* !CONFIG_BT_CTLR_LOW_LAT_ULL */ if (nack) { break; } #endif /* !CONFIG_BT_CTLR_LOW_LAT_ULL */ #if defined(CONFIG_BT_CONN) } else { struct node_tx *node_tx; uint8_t ack_last; uint16_t handle; link = ull_conn_ack_peek(&ack_last, &handle, &node_tx); if (link) { rx_demux_conn_tx_ack(ack_last, handle, link, node_tx); #if defined(CONFIG_BT_CTLR_LOW_LAT_ULL) rx_demux_yield(); #endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ } #endif /* CONFIG_BT_CONN */ } #if !defined(CONFIG_BT_CTLR_LOW_LAT_ULL) } while (link); #endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ } #if defined(CONFIG_BT_CTLR_LOW_LAT_ULL) static void rx_demux_yield(void) { static memq_link_t link; static struct mayfly mfy = {0, 0, &link, NULL, rx_demux}; struct node_rx_hdr *rx; memq_link_t *link_peek; link_peek = memq_peek(memq_ull_rx.head, memq_ull_rx.tail, (void **)&rx); if (!link_peek) { #if defined(CONFIG_BT_CONN) struct node_tx *node_tx; uint8_t ack_last; uint16_t handle; link_peek = ull_conn_ack_peek(&ack_last, &handle, &node_tx); if (!link_peek) { return; } #else /* !CONFIG_BT_CONN */ return; #endif /* !CONFIG_BT_CONN */ } /* Kick the ULL (using the mayfly, tailchain it) */ mayfly_enqueue(TICKER_USER_ID_ULL_HIGH, TICKER_USER_ID_ULL_HIGH, 1, &mfy); } #endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ #if defined(CONFIG_BT_CONN) static uint8_t tx_cmplt_get(uint16_t *handle, uint8_t *first, uint8_t last) { struct lll_tx *tx; uint8_t cmplt; tx = mfifo_dequeue_iter_get(mfifo_tx_ack.m, mfifo_tx_ack.s, mfifo_tx_ack.n, mfifo_tx_ack.f, last, first); if (!tx) { return 0; } *handle = tx->handle; cmplt = 0U; do { struct node_tx *node_tx; struct pdu_data *p; node_tx = tx->node; p = (void *)node_tx->pdu; if (!node_tx || (node_tx == (void *)1) || (((uint32_t)node_tx & ~3) && (p->ll_id == PDU_DATA_LLID_DATA_START || p->ll_id == PDU_DATA_LLID_DATA_CONTINUE))) { /* data packet, hence count num cmplt */ tx->node = (void *)1; cmplt++; } else { /* ctrl packet or flushed, hence dont count num cmplt */ tx->node = (void *)2; } if (((uint32_t)node_tx & ~3)) { ll_tx_mem_release(node_tx); } tx = mfifo_dequeue_iter_get(mfifo_tx_ack.m, mfifo_tx_ack.s, mfifo_tx_ack.n, mfifo_tx_ack.f, last, first); } while (tx && tx->handle == *handle); return cmplt; } static inline void rx_demux_conn_tx_ack(uint8_t ack_last, uint16_t handle, memq_link_t *link, struct node_tx *node_tx) { #if !defined(CONFIG_BT_CTLR_LOW_LAT_ULL) do { #endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ /* Dequeue node */ ull_conn_ack_dequeue(); /* Process Tx ack */ ull_conn_tx_ack(handle, link, node_tx); /* Release link mem */ ull_conn_link_tx_release(link); /* check for more rx ack */ link = ull_conn_ack_by_last_peek(ack_last, &handle, &node_tx); #if defined(CONFIG_BT_CTLR_LOW_LAT_ULL) if (!link) #else /* CONFIG_BT_CTLR_LOW_LAT_ULL */ } while (link); #endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ { /* trigger thread to call ll_rx_get() */ ll_rx_sched(); } } #endif /* CONFIG_BT_CONN */ #if !defined(CONFIG_BT_CTLR_LOW_LAT_ULL) static void ull_done(void *param) { memq_link_t *link; struct node_rx_hdr *done; do { link = memq_peek(memq_ull_done.head, memq_ull_done.tail, (void **)&done); if (link) { /* Process done event */ (void)memq_dequeue(memq_ull_done.tail, &memq_ull_done.head, NULL); rx_demux_event_done(link, done); } } while (link); } #endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ /** * @brief Dispatch rx objects * @details Rx objects are only peeked, not dequeued yet. * Execution context: ULL high priority Mayfly */ static inline int rx_demux_rx(memq_link_t *link, struct node_rx_hdr *rx) { /* Demux Rx objects */ switch (rx->type) { #if defined(CONFIG_BT_CTLR_LOW_LAT_ULL) case NODE_RX_TYPE_EVENT_DONE: { (void)memq_dequeue(memq_ull_rx.tail, &memq_ull_rx.head, NULL); rx_demux_event_done(link, rx); } break; #endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ #if defined(CONFIG_BT_OBSERVER) #if defined(CONFIG_BT_CTLR_ADV_EXT) case NODE_RX_TYPE_EXT_1M_REPORT: case NODE_RX_TYPE_EXT_CODED_REPORT: case NODE_RX_TYPE_EXT_AUX_REPORT: #if defined(CONFIG_BT_CTLR_SYNC_PERIODIC) case NODE_RX_TYPE_SYNC_REPORT: #endif /* CONFIG_BT_CTLR_SYNC_PERIODIC */ { struct pdu_adv *adv; (void)memq_dequeue(memq_ull_rx.tail, &memq_ull_rx.head, NULL); adv = (void *)((struct node_rx_pdu *)rx)->pdu; if (adv->type != PDU_ADV_TYPE_EXT_IND) { ll_rx_put(link, rx); ll_rx_sched(); break; } ull_scan_aux_setup(link, rx); } break; case NODE_RX_TYPE_EXT_AUX_RELEASE: { (void)memq_dequeue(memq_ull_rx.tail, &memq_ull_rx.head, NULL); ull_scan_aux_release(link, rx); } break; #if defined(CONFIG_BT_CTLR_SYNC_PERIODIC) case NODE_RX_TYPE_SYNC: { (void)memq_dequeue(memq_ull_rx.tail, &memq_ull_rx.head, NULL); ull_sync_established_report(link, rx); } break; #if defined(CONFIG_BT_CTLR_DF_SCAN_CTE_RX) case NODE_RX_TYPE_IQ_SAMPLE_REPORT: { (void)memq_dequeue(memq_ull_rx.tail, &memq_ull_rx.head, NULL); ll_rx_put(link, rx); ll_rx_sched(); } break; #endif /* CONFIG_BT_CTLR_DF_SCAN_CTE_RX */ #endif /* CONFIG_BT_CTLR_SYNC_PERIODIC */ #endif /* CONFIG_BT_CTLR_ADV_EXT */ #endif /* CONFIG_BT_OBSERVER */ #if defined(CONFIG_BT_CONN) case NODE_RX_TYPE_CONNECTION: { (void)memq_dequeue(memq_ull_rx.tail, &memq_ull_rx.head, NULL); ull_conn_setup(link, rx); } break; case NODE_RX_TYPE_DC_PDU: { int nack; nack = ull_conn_rx(link, (void *)&rx); if (nack) { return nack; } (void)memq_dequeue(memq_ull_rx.tail, &memq_ull_rx.head, NULL); if (rx) { ll_rx_put(link, rx); ll_rx_sched(); } } break; case NODE_RX_TYPE_TERMINATE: #endif /* CONFIG_BT_CONN */ #if defined(CONFIG_BT_OBSERVER) || \ defined(CONFIG_BT_CTLR_ADV_PERIODIC) || \ defined(CONFIG_BT_CTLR_SCAN_REQ_NOTIFY) || \ defined(CONFIG_BT_CTLR_PROFILE_ISR) || \ defined(CONFIG_BT_CTLR_ADV_INDICATION) || \ defined(CONFIG_BT_CTLR_SCAN_INDICATION) || \ defined(CONFIG_BT_CONN) #if defined(CONFIG_BT_CTLR_ADV_PERIODIC) case NODE_RX_TYPE_SYNC_CHM_COMPLETE: #endif /* CONFIG_BT_CTLR_ADV_PERIODIC */ #if defined(CONFIG_BT_OBSERVER) case NODE_RX_TYPE_REPORT: #endif /* CONFIG_BT_OBSERVER */ #if defined(CONFIG_BT_CTLR_SCAN_REQ_NOTIFY) case NODE_RX_TYPE_SCAN_REQ: #endif /* CONFIG_BT_CTLR_SCAN_REQ_NOTIFY */ #if defined(CONFIG_BT_CTLR_PROFILE_ISR) case NODE_RX_TYPE_PROFILE: #endif /* CONFIG_BT_CTLR_PROFILE_ISR */ #if defined(CONFIG_BT_CTLR_ADV_INDICATION) case NODE_RX_TYPE_ADV_INDICATION: #endif /* CONFIG_BT_CTLR_ADV_INDICATION */ #if defined(CONFIG_BT_CTLR_SCAN_INDICATION) case NODE_RX_TYPE_SCAN_INDICATION: #endif /* CONFIG_BT_CTLR_SCAN_INDICATION */ case NODE_RX_TYPE_RELEASE: { (void)memq_dequeue(memq_ull_rx.tail, &memq_ull_rx.head, NULL); ll_rx_put(link, rx); ll_rx_sched(); } break; #endif /* CONFIG_BT_OBSERVER || * CONFIG_BT_CTLR_ADV_PERIODIC || * CONFIG_BT_CTLR_SCAN_REQ_NOTIFY || * CONFIG_BT_CTLR_PROFILE_ISR || * CONFIG_BT_CTLR_ADV_INDICATION || * CONFIG_BT_CTLR_SCAN_INDICATION || * CONFIG_BT_CONN */ #if defined(CONFIG_BT_CTLR_ISO) case NODE_RX_TYPE_ISO_PDU: { /* Remove from receive-queue; ULL has received this now */ (void)memq_dequeue(memq_ull_rx.tail, &memq_ull_rx.head, NULL); #if defined(CONFIG_BT_CTLR_CONN_ISO) struct node_rx_pdu *rx_pdu = (struct node_rx_pdu *)rx; struct ll_conn_iso_stream *cis = ll_conn_iso_stream_get(rx_pdu->hdr.handle); struct ll_iso_datapath *dp = cis->datapath_out; isoal_sink_handle_t sink = dp->sink_hdl; if (dp->path_id != BT_HCI_DATAPATH_ID_HCI) { /* If vendor specific datapath pass to ISO AL here, * in case of HCI destination it will be passed in * HCI context. */ struct isoal_pdu_rx pckt_meta = { .meta = &rx_pdu->hdr.rx_iso_meta, .pdu = (union isoal_pdu *) &rx_pdu->pdu[0] }; /* Pass the ISO PDU through ISO-AL */ isoal_status_t err = isoal_rx_pdu_recombine(sink, &pckt_meta); LL_ASSERT(err == ISOAL_STATUS_OK); /* TODO handle err */ } #endif /* Let ISO PDU start its long journey upwards */ ll_rx_put(link, rx); ll_rx_sched(); } break; #endif default: { #if defined(CONFIG_BT_CTLR_USER_EXT) /* Try proprietary demuxing */ rx_demux_rx_proprietary(link, rx, memq_ull_rx.tail, &memq_ull_rx.head); #else LL_ASSERT(0); #endif /* CONFIG_BT_CTLR_USER_EXT */ } break; } return 0; } static inline void rx_demux_event_done(memq_link_t *link, struct node_rx_hdr *rx) { struct node_rx_event_done *done = (void *)rx; struct ull_hdr *ull_hdr; void *release; /* Decrement prepare reference if ULL will not resume */ ull_hdr = done->param; if (ull_hdr) { LL_ASSERT(ull_ref_get(ull_hdr)); ull_ref_dec(ull_hdr); } /* Process role dependent event done */ switch (done->extra.type) { #if defined(CONFIG_BT_CONN) case EVENT_DONE_EXTRA_TYPE_CONN: ull_conn_done(done); break; #endif /* CONFIG_BT_CONN */ #if defined(CONFIG_BT_BROADCASTER) #if defined(CONFIG_BT_CTLR_ADV_EXT) || \ defined(CONFIG_BT_CTLR_JIT_SCHEDULING) case EVENT_DONE_EXTRA_TYPE_ADV: ull_adv_done(done); break; #if defined(CONFIG_BT_CTLR_ADV_EXT) case EVENT_DONE_EXTRA_TYPE_ADV_AUX: ull_adv_aux_done(done); break; #endif /* CONFIG_BT_CTLR_ADV_EXT */ #endif /* CONFIG_BT_CTLR_ADV_EXT || CONFIG_BT_CTLR_JIT_SCHEDULING */ #endif /* CONFIG_BT_BROADCASTER */ #if defined(CONFIG_BT_CTLR_ADV_EXT) #if defined(CONFIG_BT_OBSERVER) case EVENT_DONE_EXTRA_TYPE_SCAN: ull_scan_done(done); break; case EVENT_DONE_EXTRA_TYPE_SCAN_AUX: ull_scan_aux_done(done); break; #if defined(CONFIG_BT_CTLR_SYNC_PERIODIC) case EVENT_DONE_EXTRA_TYPE_SYNC: ull_sync_done(done); break; #endif /* CONFIG_BT_CTLR_SYNC_PERIODIC */ #endif /* CONFIG_BT_OBSERVER */ #endif /* CONFIG_BT_CTLR_ADV_EXT */ #if defined(CONFIG_BT_CTLR_CONN_ISO) case EVENT_DONE_EXTRA_TYPE_CIS: ull_conn_iso_done(done); break; #endif /* CONFIG_BT_CTLR_CONN_ISO */ #if defined(CONFIG_BT_CTLR_USER_EXT) case EVENT_DONE_EXTRA_TYPE_USER_START ... EVENT_DONE_EXTRA_TYPE_USER_END: ull_proprietary_done(done); break; #endif /* CONFIG_BT_CTLR_USER_EXT */ case EVENT_DONE_EXTRA_TYPE_NONE: /* ignore */ break; default: LL_ASSERT(0); break; } /* release done */ done->extra.type = 0U; release = done_release(link, done); LL_ASSERT(release == done); #if defined(CONFIG_BT_CTLR_LOW_LAT_ULL_DONE) /* dequeue prepare pipeline */ ull_prepare_dequeue(TICKER_USER_ID_ULL_HIGH); /* LLL done synchronized */ lll_done_sync(); #endif /* CONFIG_BT_CTLR_LOW_LAT_ULL_DONE */ /* If disable initiated, signal the semaphore */ if (ull_hdr && !ull_ref_get(ull_hdr) && ull_hdr->disabled_cb) { ull_hdr->disabled_cb(ull_hdr->disabled_param); } } static void disabled_cb(void *param) { k_sem_give(param); } |