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
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
|
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
/*
* Copyright (C) 2024-2025 Intel Corporation
*/
#include <net/mac80211.h>
#include <linux/ip.h>
#include "mld.h"
#include "mac80211.h"
#include "phy.h"
#include "iface.h"
#include "power.h"
#include "sta.h"
#include "agg.h"
#include "scan.h"
#include "d3.h"
#include "tlc.h"
#include "key.h"
#include "ap.h"
#include "tx.h"
#include "roc.h"
#include "mlo.h"
#include "stats.h"
#include "ftm-initiator.h"
#include "low_latency.h"
#include "fw/api/scan.h"
#include "fw/api/context.h"
#include "fw/api/filter.h"
#include "fw/api/sta.h"
#include "fw/api/tdls.h"
#ifdef CONFIG_PM_SLEEP
#include "fw/api/d3.h"
#endif /* CONFIG_PM_SLEEP */
#include "iwl-trans.h"
#define IWL_MLD_LIMITS(ap) \
{ \
.max = 2, \
.types = BIT(NL80211_IFTYPE_STATION), \
}, \
{ \
.max = 1, \
.types = ap | \
BIT(NL80211_IFTYPE_P2P_CLIENT) | \
BIT(NL80211_IFTYPE_P2P_GO), \
}, \
{ \
.max = 1, \
.types = BIT(NL80211_IFTYPE_P2P_DEVICE), \
}
static const struct ieee80211_iface_limit iwl_mld_limits[] = {
IWL_MLD_LIMITS(0)
};
static const struct ieee80211_iface_limit iwl_mld_limits_ap[] = {
IWL_MLD_LIMITS(BIT(NL80211_IFTYPE_AP))
};
static const struct ieee80211_iface_combination
iwl_mld_iface_combinations[] = {
{
.num_different_channels = 2,
.max_interfaces = 4,
.limits = iwl_mld_limits,
.n_limits = ARRAY_SIZE(iwl_mld_limits),
},
{
.num_different_channels = 1,
.max_interfaces = 4,
.limits = iwl_mld_limits_ap,
.n_limits = ARRAY_SIZE(iwl_mld_limits_ap),
},
};
static const u8 if_types_ext_capa_sta[] = {
[0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
[2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT,
[7] = WLAN_EXT_CAPA8_OPMODE_NOTIF |
WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB,
[8] = WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB,
[9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT,
};
#define IWL_MLD_EMLSR_CAPA (IEEE80211_EML_CAP_EMLSR_SUPP | \
IEEE80211_EML_CAP_EMLSR_PADDING_DELAY_32US << \
__bf_shf(IEEE80211_EML_CAP_EMLSR_PADDING_DELAY) | \
IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY_64US << \
__bf_shf(IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY))
#define IWL_MLD_CAPA_OPS (FIELD_PREP_CONST( \
IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP, \
IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP_SAME) | \
IEEE80211_MLD_CAP_OP_LINK_RECONF_SUPPORT)
static const struct wiphy_iftype_ext_capab iftypes_ext_capa[] = {
{
.iftype = NL80211_IFTYPE_STATION,
.extended_capabilities = if_types_ext_capa_sta,
.extended_capabilities_mask = if_types_ext_capa_sta,
.extended_capabilities_len = sizeof(if_types_ext_capa_sta),
/* relevant only if EHT is supported */
.eml_capabilities = IWL_MLD_EMLSR_CAPA,
.mld_capa_and_ops = IWL_MLD_CAPA_OPS,
},
};
static void iwl_mld_hw_set_addresses(struct iwl_mld *mld)
{
struct wiphy *wiphy = mld->wiphy;
int num_addrs = 1;
/* Extract MAC address */
memcpy(mld->addresses[0].addr, mld->nvm_data->hw_addr, ETH_ALEN);
wiphy->addresses = mld->addresses;
wiphy->n_addresses = 1;
/* Extract additional MAC addresses if available */
if (mld->nvm_data->n_hw_addrs > 1)
num_addrs = min(mld->nvm_data->n_hw_addrs,
IWL_MLD_MAX_ADDRESSES);
for (int i = 1; i < num_addrs; i++) {
memcpy(mld->addresses[i].addr,
mld->addresses[i - 1].addr,
ETH_ALEN);
mld->addresses[i].addr[ETH_ALEN - 1]++;
wiphy->n_addresses++;
}
}
static void iwl_mld_hw_set_channels(struct iwl_mld *mld)
{
struct wiphy *wiphy = mld->wiphy;
struct ieee80211_supported_band *bands = mld->nvm_data->bands;
wiphy->bands[NL80211_BAND_2GHZ] = &bands[NL80211_BAND_2GHZ];
wiphy->bands[NL80211_BAND_5GHZ] = &bands[NL80211_BAND_5GHZ];
if (bands[NL80211_BAND_6GHZ].n_channels)
wiphy->bands[NL80211_BAND_6GHZ] = &bands[NL80211_BAND_6GHZ];
}
static void iwl_mld_hw_set_security(struct iwl_mld *mld)
{
struct ieee80211_hw *hw = mld->hw;
static const u32 mld_ciphers[] = {
WLAN_CIPHER_SUITE_WEP40,
WLAN_CIPHER_SUITE_WEP104,
WLAN_CIPHER_SUITE_TKIP,
WLAN_CIPHER_SUITE_CCMP,
WLAN_CIPHER_SUITE_GCMP,
WLAN_CIPHER_SUITE_GCMP_256,
WLAN_CIPHER_SUITE_AES_CMAC,
WLAN_CIPHER_SUITE_BIP_GMAC_128,
WLAN_CIPHER_SUITE_BIP_GMAC_256
};
hw->wiphy->n_cipher_suites = ARRAY_SIZE(mld_ciphers);
hw->wiphy->cipher_suites = mld_ciphers;
ieee80211_hw_set(hw, MFP_CAPABLE);
wiphy_ext_feature_set(hw->wiphy,
NL80211_EXT_FEATURE_BEACON_PROTECTION);
}
static void iwl_mld_hw_set_antennas(struct iwl_mld *mld)
{
struct wiphy *wiphy = mld->wiphy;
wiphy->available_antennas_tx = iwl_mld_get_valid_tx_ant(mld);
wiphy->available_antennas_rx = iwl_mld_get_valid_rx_ant(mld);
}
static void iwl_mld_hw_set_pm(struct iwl_mld *mld)
{
#ifdef CONFIG_PM_SLEEP
struct wiphy *wiphy = mld->wiphy;
if (!device_can_wakeup(mld->trans->dev))
return;
mld->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
WIPHY_WOWLAN_DISCONNECT |
WIPHY_WOWLAN_EAP_IDENTITY_REQ |
WIPHY_WOWLAN_RFKILL_RELEASE |
WIPHY_WOWLAN_NET_DETECT |
WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
WIPHY_WOWLAN_GTK_REKEY_FAILURE |
WIPHY_WOWLAN_4WAY_HANDSHAKE;
mld->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
mld->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
mld->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
mld->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES_V2;
wiphy->wowlan = &mld->wowlan;
#endif /* CONFIG_PM_SLEEP */
}
static void iwl_mac_hw_set_radiotap(struct iwl_mld *mld)
{
struct ieee80211_hw *hw = mld->hw;
hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
IEEE80211_RADIOTAP_MCS_HAVE_STBC;
hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
hw->radiotap_timestamp.units_pos =
IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
/* this is the case for CCK frames, it's better (only 8) for OFDM */
hw->radiotap_timestamp.accuracy = 22;
}
static void iwl_mac_hw_set_flags(struct iwl_mld *mld)
{
struct ieee80211_hw *hw = mld->hw;
ieee80211_hw_set(hw, USES_RSS);
ieee80211_hw_set(hw, HANDLES_QUIET_CSA);
ieee80211_hw_set(hw, AP_LINK_PS);
ieee80211_hw_set(hw, SIGNAL_DBM);
ieee80211_hw_set(hw, SPECTRUM_MGMT);
ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
ieee80211_hw_set(hw, WANT_MONITOR_VIF);
ieee80211_hw_set(hw, SUPPORTS_PS);
ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
ieee80211_hw_set(hw, AMPDU_AGGREGATION);
ieee80211_hw_set(hw, CONNECTION_MONITOR);
ieee80211_hw_set(hw, CHANCTX_STA_CSA);
ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
ieee80211_hw_set(hw, BUFF_MMPDU_TXQ);
ieee80211_hw_set(hw, STA_MMPDU_TXQ);
ieee80211_hw_set(hw, TX_AMSDU);
ieee80211_hw_set(hw, TX_FRAG_LIST);
ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
ieee80211_hw_set(hw, HAS_RATE_CONTROL);
ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
ieee80211_hw_set(hw, DISALLOW_PUNCTURING_5GHZ);
ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
ieee80211_hw_set(hw, TDLS_WIDER_BW);
}
static void iwl_mac_hw_set_wiphy(struct iwl_mld *mld)
{
struct ieee80211_hw *hw = mld->hw;
struct wiphy *wiphy = hw->wiphy;
const struct iwl_ucode_capabilities *ucode_capa = &mld->fw->ucode_capa;
snprintf(wiphy->fw_version,
sizeof(wiphy->fw_version),
"%.31s", mld->fw->fw_version);
wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
BIT(NL80211_IFTYPE_P2P_CLIENT) |
BIT(NL80211_IFTYPE_AP) |
BIT(NL80211_IFTYPE_P2P_GO) |
BIT(NL80211_IFTYPE_P2P_DEVICE) |
BIT(NL80211_IFTYPE_ADHOC);
wiphy->features |= NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
NL80211_FEATURE_ND_RANDOM_MAC_ADDR |
NL80211_FEATURE_HT_IBSS |
NL80211_FEATURE_P2P_GO_CTWIN |
NL80211_FEATURE_LOW_PRIORITY_SCAN |
NL80211_FEATURE_P2P_GO_OPPPS |
NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
NL80211_FEATURE_SUPPORTS_WMM_ADMISSION |
NL80211_FEATURE_TX_POWER_INSERTION |
NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
wiphy->flags |= WIPHY_FLAG_IBSS_RSN |
WIPHY_FLAG_AP_UAPSD |
WIPHY_FLAG_HAS_CHANNEL_SWITCH |
WIPHY_FLAG_SPLIT_SCAN_6GHZ |
WIPHY_FLAG_SUPPORTS_TDLS |
WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK;
if (mld->nvm_data->sku_cap_11be_enable &&
!iwlwifi_mod_params.disable_11ax &&
!iwlwifi_mod_params.disable_11be)
wiphy->flags |= WIPHY_FLAG_SUPPORTS_MLO;
/* the firmware uses u8 for num of iterations, but 0xff is saved for
* infinite loop, so the maximum number of iterations is actually 254.
*/
wiphy->max_sched_scan_plan_iterations = 254;
wiphy->max_sched_scan_ie_len = iwl_mld_scan_max_template_size();
wiphy->max_scan_ie_len = iwl_mld_scan_max_template_size();
wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
wiphy->max_scan_ssids = PROBE_OPTION_MAX;
wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
wiphy->max_sched_scan_reqs = 1;
wiphy->max_sched_scan_plan_interval = U16_MAX;
wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES_V2;
wiphy->max_remain_on_channel_duration = 10000;
wiphy->hw_version = mld->trans->hw_id;
wiphy->hw_timestamp_max_peers = 1;
wiphy->iface_combinations = iwl_mld_iface_combinations;
wiphy->n_iface_combinations = ARRAY_SIZE(iwl_mld_iface_combinations);
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_DFS_CONCURRENT);
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_BEACON_RATE_LEGACY);
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_SCAN_START_TIME);
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_BSS_PARENT_TSF);
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT);
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP);
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME);
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE);
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_SPP_AMSDU_SUPPORT);
if (fw_has_capa(ucode_capa, IWL_UCODE_TLV_CAPA_PROTECTED_TWT))
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_PROTECTED_TWT);
wiphy->iftype_ext_capab = NULL;
wiphy->num_iftype_ext_capab = 0;
if (!iwlwifi_mod_params.disable_11ax) {
wiphy->iftype_ext_capab = iftypes_ext_capa;
wiphy->num_iftype_ext_capab = ARRAY_SIZE(iftypes_ext_capa);
ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID);
ieee80211_hw_set(hw, SUPPORTS_ONLY_HE_MULTI_BSSID);
}
if (iwlmld_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
else
wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
}
static void iwl_mac_hw_set_misc(struct iwl_mld *mld)
{
struct ieee80211_hw *hw = mld->hw;
hw->queues = IEEE80211_NUM_ACS;
hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
hw->netdev_features |= mld->cfg->features;
hw->max_tx_fragments = mld->trans->max_skb_frags;
hw->max_listen_interval = IWL_MLD_CONN_LISTEN_INTERVAL;
hw->uapsd_max_sp_len = IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL;
hw->uapsd_queues = IEEE80211_WMM_IE_STA_QOSINFO_AC_VO |
IEEE80211_WMM_IE_STA_QOSINFO_AC_VI |
IEEE80211_WMM_IE_STA_QOSINFO_AC_BK |
IEEE80211_WMM_IE_STA_QOSINFO_AC_BE;
hw->chanctx_data_size = sizeof(struct iwl_mld_phy);
hw->vif_data_size = sizeof(struct iwl_mld_vif);
hw->sta_data_size = sizeof(struct iwl_mld_sta);
hw->txq_data_size = sizeof(struct iwl_mld_txq);
/* TODO: Remove this division when IEEE80211_MAX_AMPDU_BUF_EHT size
* is supported.
* Note: ensure that IWL_DEFAULT_QUEUE_SIZE_EHT is updated accordingly.
*/
hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF_EHT / 2;
}
static int iwl_mld_hw_verify_preconditions(struct iwl_mld *mld)
{
/* 11ax is expected to be enabled for all supported devices */
if (WARN_ON(!mld->nvm_data->sku_cap_11ax_enable))
return -EINVAL;
/* LAR is expected to be enabled for all supported devices */
if (WARN_ON(!mld->nvm_data->lar_enabled))
return -EINVAL;
/* All supported devices are currently using version 3 of the cmd.
* Since version 3, IWL_SCAN_MAX_PROFILES_V2 shall be used where
* necessary.
*/
if (WARN_ON(iwl_fw_lookup_cmd_ver(mld->fw,
SCAN_OFFLOAD_UPDATE_PROFILES_CMD,
IWL_FW_CMD_VER_UNKNOWN) != 3))
return -EINVAL;
return 0;
}
int iwl_mld_register_hw(struct iwl_mld *mld)
{
/* verify once essential preconditions required for setting
* the hw capabilities
*/
if (iwl_mld_hw_verify_preconditions(mld))
return -EINVAL;
iwl_mld_hw_set_addresses(mld);
iwl_mld_hw_set_channels(mld);
iwl_mld_hw_set_security(mld);
iwl_mld_hw_set_pm(mld);
iwl_mld_hw_set_antennas(mld);
iwl_mac_hw_set_radiotap(mld);
iwl_mac_hw_set_flags(mld);
iwl_mac_hw_set_wiphy(mld);
iwl_mac_hw_set_misc(mld);
SET_IEEE80211_DEV(mld->hw, mld->trans->dev);
return ieee80211_register_hw(mld->hw);
}
static void
iwl_mld_mac80211_tx(struct ieee80211_hw *hw,
struct ieee80211_tx_control *control, struct sk_buff *skb)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
struct ieee80211_sta *sta = control->sta;
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
struct ieee80211_hdr *hdr = (void *)skb->data;
u32 link_id = u32_get_bits(info->control.flags,
IEEE80211_TX_CTRL_MLO_LINK);
/* In AP mode, mgmt frames are sent on the bcast station,
* so the FW can't translate the MLD addr to the link addr. Do it here
*/
if (ieee80211_is_mgmt(hdr->frame_control) && sta &&
link_id != IEEE80211_LINK_UNSPECIFIED &&
!ieee80211_is_probe_resp(hdr->frame_control)) {
/* translate MLD addresses to LINK addresses */
struct ieee80211_link_sta *link_sta =
rcu_dereference(sta->link[link_id]);
struct ieee80211_bss_conf *link_conf =
rcu_dereference(info->control.vif->link_conf[link_id]);
struct ieee80211_mgmt *mgmt;
if (WARN_ON(!link_sta || !link_conf)) {
ieee80211_free_txskb(hw, skb);
return;
}
mgmt = (void *)hdr;
memcpy(mgmt->da, link_sta->addr, ETH_ALEN);
memcpy(mgmt->sa, link_conf->addr, ETH_ALEN);
memcpy(mgmt->bssid, link_conf->bssid, ETH_ALEN);
}
iwl_mld_tx_skb(mld, skb, NULL);
}
static void
iwl_mld_restart_cleanup(struct iwl_mld *mld)
{
iwl_cleanup_mld(mld);
ieee80211_iterate_interfaces(mld->hw, IEEE80211_IFACE_ITER_ACTIVE,
iwl_mld_cleanup_vif, NULL);
ieee80211_iterate_stations_atomic(mld->hw,
iwl_mld_cleanup_sta, NULL);
iwl_mld_ftm_restart_cleanup(mld);
}
static
int iwl_mld_mac80211_start(struct ieee80211_hw *hw)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
bool in_d3 = false;
int ret = 0;
lockdep_assert_wiphy(mld->wiphy);
#ifdef CONFIG_PM_SLEEP
/* Unless the host goes into hibernate the FW always stays on and
* the d3_resume flow is used. When wowlan is configured, mac80211
* would call it's resume callback and the wowlan_resume flow
* would be used.
*/
in_d3 = mld->fw_status.in_d3;
if (in_d3) {
/* mac80211 already cleaned up the state, no need for cleanup */
ret = iwl_mld_no_wowlan_resume(mld);
if (ret)
iwl_mld_stop_fw(mld);
}
#endif /* CONFIG_PM_SLEEP */
if (mld->fw_status.in_hw_restart) {
iwl_mld_stop_fw(mld);
iwl_mld_restart_cleanup(mld);
}
if (!in_d3 || ret) {
ret = iwl_mld_start_fw(mld);
if (ret)
goto error;
}
mld->scan.last_start_time_jiffies = jiffies;
iwl_dbg_tlv_time_point(&mld->fwrt, IWL_FW_INI_TIME_POINT_POST_INIT,
NULL);
iwl_dbg_tlv_time_point(&mld->fwrt, IWL_FW_INI_TIME_POINT_PERIODIC,
NULL);
return 0;
error:
/* If we failed to restart the hw, there is nothing useful
* we can do but indicate we are no longer in restart.
*/
mld->fw_status.in_hw_restart = false;
return ret;
}
static
void iwl_mld_mac80211_stop(struct ieee80211_hw *hw, bool suspend)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
lockdep_assert_wiphy(mld->wiphy);
wiphy_work_cancel(mld->wiphy, &mld->add_txqs_wk);
/* if the suspend flow fails the fw is in error. Stop it here, and it
* will be started upon wakeup
*/
if (!suspend ||
(IS_ENABLED(CONFIG_PM_SLEEP) && iwl_mld_no_wowlan_suspend(mld)))
iwl_mld_stop_fw(mld);
/* HW is stopped, no more coming RX. OTOH, the worker can't run as the
* wiphy lock is held. Cancel it in case it was scheduled just before
* we stopped the HW.
*/
wiphy_work_cancel(mld->wiphy, &mld->async_handlers_wk);
/* Empty out the list, as the worker won't do that */
iwl_mld_purge_async_handlers_list(mld);
/* Clear in_hw_restart flag when stopping the hw, as mac80211 won't
* execute the restart.
*/
mld->fw_status.in_hw_restart = false;
/* We shouldn't have any UIDs still set. Loop over all the UIDs to
* make sure there's nothing left there and warn if any is found.
*/
for (int i = 0; i < ARRAY_SIZE(mld->scan.uid_status); i++)
if (WARN_ONCE(mld->scan.uid_status[i],
"UMAC scan UID %d status was not cleaned (0x%x 0x%x)\n",
i, mld->scan.uid_status[i], mld->scan.status))
mld->scan.uid_status[i] = 0;
}
static
int iwl_mld_mac80211_config(struct ieee80211_hw *hw, u32 changed)
{
return 0;
}
static
int iwl_mld_mac80211_add_interface(struct ieee80211_hw *hw,
struct ieee80211_vif *vif)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
int ret;
lockdep_assert_wiphy(mld->wiphy);
/* Construct mld_vif, add it to fw, and map its ID to ieee80211_vif */
ret = iwl_mld_add_vif(mld, vif);
if (ret)
return ret;
/*
* Add the default link, but not if this is an MLD vif as that implies
* the HW is restarting and it will be configured by change_vif_links.
*/
if (!ieee80211_vif_is_mld(vif))
ret = iwl_mld_add_link(mld, &vif->bss_conf);
if (ret)
goto err;
if (vif->type == NL80211_IFTYPE_STATION) {
vif->driver_flags |= IEEE80211_VIF_REMOVE_AP_AFTER_DISASSOC;
if (!vif->p2p)
vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
IEEE80211_VIF_SUPPORTS_CQM_RSSI;
}
if (vif->p2p || iwl_fw_lookup_cmd_ver(mld->fw, PHY_CONTEXT_CMD, 0) < 5)
vif->driver_flags |= IEEE80211_VIF_IGNORE_OFDMA_WIDER_BW;
/*
* For an MLD vif (in restart) we may not have a link; delay the call
* the initial change_vif_links.
*/
if (vif->type == NL80211_IFTYPE_STATION &&
!ieee80211_vif_is_mld(vif))
iwl_mld_update_mac_power(mld, vif, false);
if (vif->type == NL80211_IFTYPE_MONITOR) {
mld->monitor.on = true;
ieee80211_hw_set(mld->hw, RX_INCLUDES_FCS);
}
if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
mld->p2p_device_vif = vif;
return 0;
err:
iwl_mld_rm_vif(mld, vif);
return ret;
}
static
void iwl_mld_mac80211_remove_interface(struct ieee80211_hw *hw,
struct ieee80211_vif *vif)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
lockdep_assert_wiphy(mld->wiphy);
if (ieee80211_vif_type_p2p(vif) == NL80211_IFTYPE_STATION)
vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
IEEE80211_VIF_SUPPORTS_CQM_RSSI);
if (vif->type == NL80211_IFTYPE_MONITOR) {
__clear_bit(IEEE80211_HW_RX_INCLUDES_FCS, mld->hw->flags);
mld->monitor.on = false;
}
if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
mld->p2p_device_vif = NULL;
iwl_mld_remove_link(mld, &vif->bss_conf);
#ifdef CONFIG_IWLWIFI_DEBUGFS
debugfs_remove(iwl_mld_vif_from_mac80211(vif)->dbgfs_slink);
#endif
iwl_mld_rm_vif(mld, vif);
}
struct iwl_mld_mc_iter_data {
struct iwl_mld *mld;
int port_id;
};
static void iwl_mld_mc_iface_iterator(void *data, u8 *mac,
struct ieee80211_vif *vif)
{
struct iwl_mld_mc_iter_data *mc_data = data;
struct iwl_mld *mld = mc_data->mld;
struct iwl_mcast_filter_cmd *cmd = mld->mcast_filter_cmd;
struct iwl_host_cmd hcmd = {
.id = MCAST_FILTER_CMD,
.dataflags[0] = IWL_HCMD_DFL_NOCOPY,
};
int ret, len;
/* If we don't have free ports, mcast frames will be dropped */
if (WARN_ON_ONCE(mc_data->port_id >= MAX_PORT_ID_NUM))
return;
if (vif->type != NL80211_IFTYPE_STATION || !vif->cfg.assoc)
return;
cmd->port_id = mc_data->port_id++;
ether_addr_copy(cmd->bssid, vif->bss_conf.bssid);
len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
hcmd.len[0] = len;
hcmd.data[0] = cmd;
ret = iwl_mld_send_cmd(mld, &hcmd);
if (ret)
IWL_ERR(mld, "mcast filter cmd error. ret=%d\n", ret);
}
void iwl_mld_recalc_multicast_filter(struct iwl_mld *mld)
{
struct iwl_mld_mc_iter_data iter_data = {
.mld = mld,
};
if (WARN_ON_ONCE(!mld->mcast_filter_cmd))
return;
ieee80211_iterate_active_interfaces(mld->hw,
IEEE80211_IFACE_ITER_NORMAL,
iwl_mld_mc_iface_iterator,
&iter_data);
}
static u64
iwl_mld_mac80211_prepare_multicast(struct ieee80211_hw *hw,
struct netdev_hw_addr_list *mc_list)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
struct iwl_mcast_filter_cmd *cmd;
struct netdev_hw_addr *addr;
int addr_count = netdev_hw_addr_list_count(mc_list);
bool pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES;
int len;
if (pass_all)
addr_count = 0;
/* len must be a multiple of 4 */
len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
cmd = kzalloc(len, GFP_ATOMIC);
if (!cmd)
return 0;
if (pass_all) {
cmd->pass_all = 1;
goto out;
}
netdev_hw_addr_list_for_each(addr, mc_list) {
IWL_DEBUG_MAC80211(mld, "mcast addr (%d): %pM\n",
cmd->count, addr->addr);
ether_addr_copy(&cmd->addr_list[cmd->count * ETH_ALEN],
addr->addr);
cmd->count++;
}
out:
return (u64)(unsigned long)cmd;
}
static
void iwl_mld_mac80211_configure_filter(struct ieee80211_hw *hw,
unsigned int changed_flags,
unsigned int *total_flags,
u64 multicast)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
/* Replace previous configuration */
kfree(mld->mcast_filter_cmd);
mld->mcast_filter_cmd = cmd;
if (!cmd)
goto out;
if (changed_flags & FIF_ALLMULTI)
cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
if (cmd->pass_all)
cmd->count = 0;
iwl_mld_recalc_multicast_filter(mld);
out:
*total_flags = 0;
}
static
void iwl_mld_mac80211_wake_tx_queue(struct ieee80211_hw *hw,
struct ieee80211_txq *txq)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
struct iwl_mld_txq *mld_txq = iwl_mld_txq_from_mac80211(txq);
if (likely(mld_txq->status.allocated) || !txq->sta) {
iwl_mld_tx_from_txq(mld, txq);
return;
}
/* We don't support TSPEC tids. %IEEE80211_NUM_TIDS is for mgmt */
if (txq->tid != IEEE80211_NUM_TIDS && txq->tid >= IWL_MAX_TID_COUNT) {
IWL_DEBUG_MAC80211(mld, "TID %d is not supported\n", txq->tid);
return;
}
/* The worker will handle any packets we leave on the txq now */
spin_lock_bh(&mld->add_txqs_lock);
/* The list is being deleted only after the queue is fully allocated. */
if (list_empty(&mld_txq->list) &&
/* recheck under lock, otherwise it can be added twice */
!mld_txq->status.allocated) {
list_add_tail(&mld_txq->list, &mld->txqs_to_add);
wiphy_work_queue(mld->wiphy, &mld->add_txqs_wk);
}
spin_unlock_bh(&mld->add_txqs_lock);
}
static void iwl_mld_teardown_tdls_peers(struct iwl_mld *mld)
{
lockdep_assert_wiphy(mld->wiphy);
for (int i = 0; i < mld->fw->ucode_capa.num_stations; i++) {
struct ieee80211_link_sta *link_sta;
struct iwl_mld_sta *mld_sta;
link_sta = wiphy_dereference(mld->wiphy,
mld->fw_id_to_link_sta[i]);
if (IS_ERR_OR_NULL(link_sta))
continue;
if (!link_sta->sta->tdls)
continue;
mld_sta = iwl_mld_sta_from_mac80211(link_sta->sta);
ieee80211_tdls_oper_request(mld_sta->vif, link_sta->addr,
NL80211_TDLS_TEARDOWN,
WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED,
GFP_KERNEL);
}
}
static
int iwl_mld_add_chanctx(struct ieee80211_hw *hw,
struct ieee80211_chanctx_conf *ctx)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
struct iwl_mld_phy *phy = iwl_mld_phy_from_mac80211(ctx);
int fw_id = iwl_mld_allocate_fw_phy_id(mld);
int ret;
if (fw_id < 0)
return fw_id;
phy->mld = mld;
phy->fw_id = fw_id;
phy->chandef = *iwl_mld_get_chandef_from_chanctx(mld, ctx);
ret = iwl_mld_phy_fw_action(mld, ctx, FW_CTXT_ACTION_ADD);
if (ret) {
mld->used_phy_ids &= ~BIT(phy->fw_id);
return ret;
}
if (hweight8(mld->used_phy_ids) > 1)
iwl_mld_teardown_tdls_peers(mld);
return 0;
}
static
void iwl_mld_remove_chanctx(struct ieee80211_hw *hw,
struct ieee80211_chanctx_conf *ctx)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
struct iwl_mld_phy *phy = iwl_mld_phy_from_mac80211(ctx);
iwl_mld_phy_fw_action(mld, ctx, FW_CTXT_ACTION_REMOVE);
mld->used_phy_ids &= ~BIT(phy->fw_id);
}
static
void iwl_mld_change_chanctx(struct ieee80211_hw *hw,
struct ieee80211_chanctx_conf *ctx, u32 changed)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
struct iwl_mld_phy *phy = iwl_mld_phy_from_mac80211(ctx);
struct cfg80211_chan_def *chandef =
iwl_mld_get_chandef_from_chanctx(mld, ctx);
/* We don't care about these */
if (!(changed & ~(IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
IEEE80211_CHANCTX_CHANGE_RADAR |
IEEE80211_CHANCTX_CHANGE_CHANNEL)))
return;
/* Check if a FW update is required */
if (changed & IEEE80211_CHANCTX_CHANGE_AP)
goto update;
if (chandef->chan == phy->chandef.chan &&
chandef->center_freq1 == phy->chandef.center_freq1 &&
chandef->punctured == phy->chandef.punctured) {
/* Check if we are toggling between HT and non-HT, no-op */
if (phy->chandef.width == chandef->width ||
(phy->chandef.width <= NL80211_CHAN_WIDTH_20 &&
chandef->width <= NL80211_CHAN_WIDTH_20))
return;
}
update:
phy->chandef = *chandef;
iwl_mld_phy_fw_action(mld, ctx, FW_CTXT_ACTION_MODIFY);
}
static u8
iwl_mld_chandef_get_primary_80(struct cfg80211_chan_def *chandef)
{
int data_start;
int control_start;
int bw;
if (chandef->width == NL80211_CHAN_WIDTH_320)
bw = 320;
else if (chandef->width == NL80211_CHAN_WIDTH_160)
bw = 160;
else
return 0;
/* data is bw wide so the start is half the width */
data_start = chandef->center_freq1 - bw / 2;
/* control is 20Mhz width */
control_start = chandef->chan->center_freq - 10;
return (control_start - data_start) / 80;
}
static bool iwl_mld_can_activate_link(struct iwl_mld *mld,
struct ieee80211_vif *vif,
struct ieee80211_bss_conf *link)
{
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
struct iwl_mld_sta *mld_sta;
struct iwl_mld_link_sta *link_sta;
/* In association, we activate the assoc link before adding the STA. */
if (!mld_vif->ap_sta || !vif->cfg.assoc)
return true;
mld_sta = iwl_mld_sta_from_mac80211(mld_vif->ap_sta);
/* When switching links, we need to wait with the activation until the
* STA was added to the FW. It'll be activated in
* iwl_mld_update_link_stas
*/
link_sta = wiphy_dereference(mld->wiphy, mld_sta->link[link->link_id]);
/* In restart we can have a link_sta that doesn't exist in FW yet */
return link_sta && link_sta->in_fw;
}
static
int iwl_mld_assign_vif_chanctx(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_bss_conf *link,
struct ieee80211_chanctx_conf *ctx)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
struct iwl_mld_link *mld_link = iwl_mld_link_from_mac80211(link);
unsigned int n_active = iwl_mld_count_active_links(mld, vif);
int ret;
lockdep_assert_wiphy(mld->wiphy);
if (WARN_ON(!mld_link))
return -EINVAL;
/* if the assigned one was not counted yet, count it now */
if (!rcu_access_pointer(mld_link->chan_ctx)) {
n_active++;
/* Track addition of non-BSS link */
if (ieee80211_vif_type_p2p(vif) != NL80211_IFTYPE_STATION) {
ret = iwl_mld_emlsr_check_non_bss_block(mld, 1);
if (ret)
return ret;
}
}
/* for AP, mac parameters such as HE support are updated at this stage. */
if (vif->type == NL80211_IFTYPE_AP) {
ret = iwl_mld_mac_fw_action(mld, vif, FW_CTXT_ACTION_MODIFY);
if (ret) {
IWL_ERR(mld, "failed to update MAC %pM\n", vif->addr);
return -EINVAL;
}
}
rcu_assign_pointer(mld_link->chan_ctx, ctx);
if (n_active > 1) {
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
iwl_mld_leave_omi_bw_reduction(mld);
/* Indicate to mac80211 that EML is enabled */
vif->driver_flags |= IEEE80211_VIF_EML_ACTIVE;
if (vif->active_links & BIT(mld_vif->emlsr.selected_links))
mld_vif->emlsr.primary = mld_vif->emlsr.selected_primary;
else
mld_vif->emlsr.primary = __ffs(vif->active_links);
iwl_dbg_tlv_time_point(&mld->fwrt, IWL_FW_INI_TIME_ESR_LINK_UP,
NULL);
}
/* First send the link command with the phy context ID.
* Now that we have the phy, we know the band so also the rates
*/
ret = iwl_mld_change_link_in_fw(mld, link,
LINK_CONTEXT_MODIFY_RATES_INFO);
if (ret)
goto err;
/* TODO: Initialize rate control for the AP station, since we might be
* doing a link switch here - we cannot initialize it before since
* this needs the phy context assigned (and in FW?), and we cannot
* do it later because it needs to be initialized as soon as we're
* able to TX on the link, i.e. when active. (task=link-switch)
*/
/* Now activate the link */
if (iwl_mld_can_activate_link(mld, vif, link)) {
ret = iwl_mld_activate_link(mld, link);
if (ret)
goto err;
}
if (vif->type == NL80211_IFTYPE_STATION)
iwl_mld_send_ap_tx_power_constraint_cmd(mld, vif, link);
if (vif->type == NL80211_IFTYPE_MONITOR) {
/* TODO: task=sniffer add sniffer station */
mld->monitor.p80 =
iwl_mld_chandef_get_primary_80(&vif->bss_conf.chanreq.oper);
}
return 0;
err:
RCU_INIT_POINTER(mld_link->chan_ctx, NULL);
return ret;
}
static
void iwl_mld_unassign_vif_chanctx(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_bss_conf *link,
struct ieee80211_chanctx_conf *ctx)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
struct iwl_mld_link *mld_link = iwl_mld_link_from_mac80211(link);
unsigned int n_active = iwl_mld_count_active_links(mld, vif);
if (WARN_ON(!mld_link))
return;
/* Track removal of non-BSS link */
if (ieee80211_vif_type_p2p(vif) != NL80211_IFTYPE_STATION)
iwl_mld_emlsr_check_non_bss_block(mld, -1);
iwl_mld_deactivate_link(mld, link);
/* TODO: task=sniffer remove sniffer station */
if (n_active > 1) {
/* Indicate to mac80211 that EML is disabled */
vif->driver_flags &= ~IEEE80211_VIF_EML_ACTIVE;
iwl_dbg_tlv_time_point(&mld->fwrt,
IWL_FW_INI_TIME_ESR_LINK_DOWN,
NULL);
}
RCU_INIT_POINTER(mld_link->chan_ctx, NULL);
/* in the non-MLO case, remove/re-add the link to clean up FW state.
* In MLO, it'll be done in drv_change_vif_link
*/
if (!ieee80211_vif_is_mld(vif) && !mld_vif->ap_sta &&
!WARN_ON_ONCE(vif->cfg.assoc) &&
vif->type != NL80211_IFTYPE_AP && !mld->fw_status.in_hw_restart) {
iwl_mld_remove_link(mld, link);
iwl_mld_add_link(mld, link);
}
}
static
int iwl_mld_mac80211_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
{
return 0;
}
static void
iwl_mld_link_info_changed_ap_ibss(struct iwl_mld *mld,
struct ieee80211_vif *vif,
struct ieee80211_bss_conf *link,
u64 changes)
{
u32 link_changes = 0;
if (changes & BSS_CHANGED_ERP_SLOT)
link_changes |= LINK_CONTEXT_MODIFY_RATES_INFO;
if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT))
link_changes |= LINK_CONTEXT_MODIFY_PROTECT_FLAGS;
if (changes & (BSS_CHANGED_QOS | BSS_CHANGED_BANDWIDTH))
link_changes |= LINK_CONTEXT_MODIFY_QOS_PARAMS;
if (changes & BSS_CHANGED_HE_BSS_COLOR)
link_changes |= LINK_CONTEXT_MODIFY_HE_PARAMS;
if (link_changes)
iwl_mld_change_link_in_fw(mld, link, link_changes);
if (changes & BSS_CHANGED_BEACON)
iwl_mld_update_beacon_template(mld, vif, link);
}
static
u32 iwl_mld_link_changed_mapping(struct iwl_mld *mld,
struct ieee80211_vif *vif,
struct ieee80211_bss_conf *link_conf,
u64 changes)
{
u32 link_changes = 0;
bool has_he, has_eht;
if (changes & BSS_CHANGED_QOS && vif->cfg.assoc && link_conf->qos)
link_changes |= LINK_CONTEXT_MODIFY_QOS_PARAMS;
if (changes & (BSS_CHANGED_ERP_PREAMBLE | BSS_CHANGED_BASIC_RATES |
BSS_CHANGED_ERP_SLOT))
link_changes |= LINK_CONTEXT_MODIFY_RATES_INFO;
if (changes & (BSS_CHANGED_HT | BSS_CHANGED_ERP_CTS_PROT))
link_changes |= LINK_CONTEXT_MODIFY_PROTECT_FLAGS;
/* TODO: task=MLO check mac80211's HE flags and if command is needed
* every time there's a link change. Currently used flags are
* BSS_CHANGED_HE_OBSS_PD and BSS_CHANGED_HE_BSS_COLOR.
*/
has_he = link_conf->he_support && !iwlwifi_mod_params.disable_11ax;
has_eht = link_conf->eht_support && !iwlwifi_mod_params.disable_11be;
if (vif->cfg.assoc && (has_he || has_eht)) {
IWL_DEBUG_MAC80211(mld, "Associated in HE mode\n");
link_changes |= LINK_CONTEXT_MODIFY_HE_PARAMS;
}
return link_changes;
}
static void
iwl_mld_mac80211_link_info_changed_sta(struct iwl_mld *mld,
struct ieee80211_vif *vif,
struct ieee80211_bss_conf *link_conf,
u64 changes)
{
u32 link_changes = iwl_mld_link_changed_mapping(mld, vif, link_conf,
changes);
if (link_changes)
iwl_mld_change_link_in_fw(mld, link_conf, link_changes);
if (changes & BSS_CHANGED_TPE)
iwl_mld_send_ap_tx_power_constraint_cmd(mld, vif, link_conf);
if (changes & BSS_CHANGED_BEACON_INFO)
iwl_mld_update_mac_power(mld, vif, false);
/* The firmware will wait quite a while after association before it
* starts filtering the beacons. We can safely enable beacon filtering
* upon CQM configuration, even if we didn't get a beacon yet.
*/
if (changes & (BSS_CHANGED_CQM | BSS_CHANGED_BEACON_INFO))
iwl_mld_enable_beacon_filter(mld, link_conf, false);
/* If we have used OMI before to reduce bandwidth to 80 MHz and then
* increased to 160 MHz again, and then the AP changes to 320 MHz, it
* will think that we're limited to 160 MHz right now. Update it by
* requesting a new OMI bandwidth.
*/
if (changes & BSS_CHANGED_BANDWIDTH) {
enum ieee80211_sta_rx_bandwidth bw;
bw = ieee80211_chan_width_to_rx_bw(link_conf->chanreq.oper.width);
iwl_mld_omi_ap_changed_bw(mld, link_conf, bw);
}
if (changes & BSS_CHANGED_BANDWIDTH)
iwl_mld_retry_emlsr(mld, vif);
}
static int iwl_mld_update_mu_groups(struct iwl_mld *mld,
struct ieee80211_bss_conf *link_conf)
{
struct iwl_mu_group_mgmt_cmd cmd = {};
BUILD_BUG_ON(sizeof(cmd.membership_status) !=
sizeof(link_conf->mu_group.membership));
BUILD_BUG_ON(sizeof(cmd.user_position) !=
sizeof(link_conf->mu_group.position));
memcpy(cmd.membership_status, link_conf->mu_group.membership,
WLAN_MEMBERSHIP_LEN);
memcpy(cmd.user_position, link_conf->mu_group.position,
WLAN_USER_POSITION_LEN);
return iwl_mld_send_cmd_pdu(mld,
WIDE_ID(DATA_PATH_GROUP,
UPDATE_MU_GROUPS_CMD),
&cmd);
}
static void
iwl_mld_mac80211_link_info_changed(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_bss_conf *link_conf,
u64 changes)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
switch (vif->type) {
case NL80211_IFTYPE_STATION:
iwl_mld_mac80211_link_info_changed_sta(mld, vif, link_conf,
changes);
break;
case NL80211_IFTYPE_AP:
case NL80211_IFTYPE_ADHOC:
iwl_mld_link_info_changed_ap_ibss(mld, vif, link_conf,
changes);
break;
case NL80211_IFTYPE_MONITOR:
/* The firmware tracks this on its own in STATION mode, but
* obviously not in sniffer mode.
*/
if (changes & BSS_CHANGED_MU_GROUPS)
iwl_mld_update_mu_groups(mld, link_conf);
break;
default:
/* shouldn't happen */
WARN_ON_ONCE(1);
}
/* We now know our BSSID, we can configure the MAC context with
* eht_support if needed.
*/
if (changes & BSS_CHANGED_BSSID)
iwl_mld_mac_fw_action(mld, vif, FW_CTXT_ACTION_MODIFY);
if (changes & BSS_CHANGED_TXPOWER)
iwl_mld_set_tx_power(mld, link_conf, link_conf->txpower);
}
static void
iwl_mld_smps_wa(struct iwl_mld *mld, struct ieee80211_vif *vif, bool enable)
{
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
/* Send the device-level power commands since the
* firmware checks the POWER_TABLE_CMD's POWER_SAVE_EN bit to
* determine SMPS mode.
*/
if (mld_vif->ps_disabled == !enable)
return;
mld_vif->ps_disabled = !enable;
iwl_mld_update_device_power(mld, false);
}
static
void iwl_mld_mac80211_vif_cfg_changed(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
u64 changes)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
int ret;
lockdep_assert_wiphy(mld->wiphy);
if (vif->type != NL80211_IFTYPE_STATION)
return;
if (changes & BSS_CHANGED_ASSOC) {
ret = iwl_mld_mac_fw_action(mld, vif, FW_CTXT_ACTION_MODIFY);
if (ret)
IWL_ERR(mld, "failed to update context\n");
if (vif->cfg.assoc) {
/* Clear statistics to get clean beacon counter, and
* ask for periodic statistics, as they are needed for
* link selection and RX OMI decisions.
*/
iwl_mld_clear_stats_in_fw(mld);
iwl_mld_request_periodic_fw_stats(mld, true);
iwl_mld_set_vif_associated(mld, vif);
} else {
iwl_mld_request_periodic_fw_stats(mld, false);
}
}
if (changes & BSS_CHANGED_PS) {
iwl_mld_smps_wa(mld, vif, vif->cfg.ps);
iwl_mld_update_mac_power(mld, vif, false);
}
/* TODO: task=MLO BSS_CHANGED_MLD_VALID_LINKS/CHANGED_MLD_TTLM */
}
static int
iwl_mld_mac80211_hw_scan(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_scan_request *hw_req)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
if (WARN_ON(!hw_req->req.n_channels ||
hw_req->req.n_channels >
mld->fw->ucode_capa.n_scan_channels))
return -EINVAL;
return iwl_mld_regular_scan_start(mld, vif, &hw_req->req, &hw_req->ies);
}
static void
iwl_mld_mac80211_cancel_hw_scan(struct ieee80211_hw *hw,
struct ieee80211_vif *vif)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
/* Due to a race condition, it's possible that mac80211 asks
* us to stop a hw_scan when it's already stopped. This can
* happen, for instance, if we stopped the scan ourselves,
* called ieee80211_scan_completed() and the userspace called
* cancel scan before ieee80211_scan_work() could run.
* To handle that, simply return if the scan is not running.
*/
if (mld->scan.status & IWL_MLD_SCAN_REGULAR)
iwl_mld_scan_stop(mld, IWL_MLD_SCAN_REGULAR, true);
}
static int
iwl_mld_mac80211_sched_scan_start(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct cfg80211_sched_scan_request *req,
struct ieee80211_scan_ies *ies)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
return iwl_mld_sched_scan_start(mld, vif, req, ies, IWL_MLD_SCAN_SCHED);
}
static int
iwl_mld_mac80211_sched_scan_stop(struct ieee80211_hw *hw,
struct ieee80211_vif *vif)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
/* Due to a race condition, it's possible that mac80211 asks
* us to stop a sched_scan when it's already stopped. This
* can happen, for instance, if we stopped the scan ourselves,
* called ieee80211_sched_scan_stopped() and the userspace called
* stop sched scan before ieee80211_sched_scan_stopped_work()
* could run. To handle this, simply return if the scan is
* not running.
*/
if (!(mld->scan.status & IWL_MLD_SCAN_SCHED))
return 0;
return iwl_mld_scan_stop(mld, IWL_MLD_SCAN_SCHED, false);
}
static void
iwl_mld_restart_complete_vif(void *data, u8 *mac, struct ieee80211_vif *vif)
{
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
struct ieee80211_bss_conf *link_conf;
struct iwl_mld *mld = data;
int link_id;
for_each_vif_active_link(vif, link_conf, link_id) {
enum ieee80211_sta_rx_bandwidth bw;
struct iwl_mld_link *mld_link;
mld_link = wiphy_dereference(mld->wiphy,
mld_vif->link[link_id]);
if (WARN_ON_ONCE(!mld_link))
continue;
bw = mld_link->rx_omi.bw_in_progress;
if (bw)
iwl_mld_change_link_omi_bw(mld, link_conf, bw);
}
}
static void
iwl_mld_mac80211_reconfig_complete(struct ieee80211_hw *hw,
enum ieee80211_reconfig_type reconfig_type)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
switch (reconfig_type) {
case IEEE80211_RECONFIG_TYPE_RESTART:
mld->fw_status.in_hw_restart = false;
iwl_mld_send_recovery_cmd(mld, ERROR_RECOVERY_END_OF_RECOVERY);
ieee80211_iterate_interfaces(mld->hw,
IEEE80211_IFACE_ITER_NORMAL,
iwl_mld_restart_complete_vif, mld);
iwl_trans_finish_sw_reset(mld->trans);
/* no need to lock, adding in parallel would schedule too */
if (!list_empty(&mld->txqs_to_add))
wiphy_work_queue(mld->wiphy, &mld->add_txqs_wk);
IWL_INFO(mld, "restart completed\n");
break;
case IEEE80211_RECONFIG_TYPE_SUSPEND:
break;
}
}
static
void iwl_mld_mac80211_mgd_prepare_tx(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_prep_tx_info *info)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
u32 duration = IWL_MLD_SESSION_PROTECTION_ASSOC_TIME_MS;
/* After a successful association the connection is etalibeshed
* and we can rely on the quota to send the disassociation frame.
*/
if (info->was_assoc)
return;
if (info->duration > duration)
duration = info->duration;
iwl_mld_schedule_session_protection(mld, vif, duration,
IWL_MLD_SESSION_PROTECTION_MIN_TIME_MS,
info->link_id);
}
static
void iwl_mld_mac_mgd_complete_tx(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_prep_tx_info *info)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
/* Successful authentication is the only case that requires to let
* the session protection go. We'll need it for the upcoming
* association. For all the other cases, we need to cancel the session
* protection.
* After successful association the connection is established and
* further mgd tx can rely on the quota.
*/
if (info->success && info->subtype == IEEE80211_STYPE_AUTH)
return;
/* The firmware will be on medium after we configure the vif as
* associated. Removing the session protection allows the firmware
* to stop being on medium. In order to ensure the continuity of our
* presence on medium, we need first to configure the vif as associated
* and only then, remove the session protection.
* Currently, mac80211 calls vif_cfg_changed() first and then,
* drv_mgd_complete_tx(). Ensure that this assumption stays true by
* a warning.
*/
WARN_ON(info->success &&
(info->subtype == IEEE80211_STYPE_ASSOC_REQ ||
info->subtype == IEEE80211_STYPE_REASSOC_REQ) &&
!vif->cfg.assoc);
iwl_mld_cancel_session_protection(mld, vif, info->link_id);
}
static int
iwl_mld_mac80211_conf_tx(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
unsigned int link_id, u16 ac,
const struct ieee80211_tx_queue_params *params)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
struct iwl_mld_link *link;
lockdep_assert_wiphy(mld->wiphy);
link = iwl_mld_link_dereference_check(mld_vif, link_id);
if (!link)
return -EINVAL;
link->queue_params[ac] = *params;
/* No need to update right away, we'll get BSS_CHANGED_QOS
* The exception is P2P_DEVICE interface which needs immediate update.
*/
if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
iwl_mld_change_link_in_fw(mld, &vif->bss_conf,
LINK_CONTEXT_MODIFY_QOS_PARAMS);
return 0;
}
static void iwl_mld_set_uapsd(struct iwl_mld *mld, struct ieee80211_vif *vif)
{
vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
if (vif->type != NL80211_IFTYPE_STATION)
return;
if (vif->p2p &&
!(iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_P2P_CLIENT))
vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
if (!vif->p2p &&
!(iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS))
vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
}
int iwl_mld_tdls_sta_count(struct iwl_mld *mld)
{
int count = 0;
lockdep_assert_wiphy(mld->wiphy);
for (int i = 0; i < mld->fw->ucode_capa.num_stations; i++) {
struct ieee80211_link_sta *link_sta;
link_sta = wiphy_dereference(mld->wiphy,
mld->fw_id_to_link_sta[i]);
if (IS_ERR_OR_NULL(link_sta))
continue;
if (!link_sta->sta->tdls)
continue;
count++;
}
return count;
}
static void iwl_mld_check_he_obss_narrow_bw_ru_iter(struct wiphy *wiphy,
struct cfg80211_bss *bss,
void *_data)
{
bool *tolerated = _data;
const struct cfg80211_bss_ies *ies;
const struct element *elem;
rcu_read_lock();
ies = rcu_dereference(bss->ies);
elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, ies->data,
ies->len);
if (!elem || elem->datalen < 10 ||
!(elem->data[10] &
WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT)) {
*tolerated = false;
}
rcu_read_unlock();
}
static void
iwl_mld_check_he_obss_narrow_bw_ru(struct iwl_mld *mld,
struct iwl_mld_link *mld_link,
struct ieee80211_bss_conf *link_conf)
{
bool tolerated = true;
if (WARN_ON_ONCE(!link_conf->chanreq.oper.chan))
return;
if (!(link_conf->chanreq.oper.chan->flags & IEEE80211_CHAN_RADAR)) {
mld_link->he_ru_2mhz_block = false;
return;
}
cfg80211_bss_iter(mld->wiphy, &link_conf->chanreq.oper,
iwl_mld_check_he_obss_narrow_bw_ru_iter, &tolerated);
/* If there is at least one AP on radar channel that cannot
* tolerate 26-tone RU UL OFDMA transmissions using HE TB PPDU.
*/
mld_link->he_ru_2mhz_block = !tolerated;
}
static void iwl_mld_link_set_2mhz_block(struct iwl_mld *mld,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta)
{
struct ieee80211_link_sta *link_sta;
unsigned int link_id;
for_each_sta_active_link(vif, sta, link_sta, link_id) {
struct ieee80211_bss_conf *link_conf =
link_conf_dereference_protected(vif, link_id);
struct iwl_mld_link *mld_link =
iwl_mld_link_from_mac80211(link_conf);
if (WARN_ON(!link_conf || !mld_link))
continue;
if (link_sta->he_cap.has_he)
iwl_mld_check_he_obss_narrow_bw_ru(mld, mld_link,
link_conf);
}
}
static int iwl_mld_move_sta_state_up(struct iwl_mld *mld,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta,
enum ieee80211_sta_state old_state,
enum ieee80211_sta_state new_state)
{
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
int tdls_count = 0;
int ret;
if (old_state == IEEE80211_STA_NOTEXIST &&
new_state == IEEE80211_STA_NONE) {
if (sta->tdls) {
if (vif->p2p || hweight8(mld->used_phy_ids) != 1)
return -EBUSY;
tdls_count = iwl_mld_tdls_sta_count(mld);
if (tdls_count >= IWL_TDLS_STA_COUNT)
return -EBUSY;
}
/*
* If this is the first STA (i.e. the AP) it won't do
* anything, otherwise must leave for any new STA on
* any other interface, or for TDLS, etc.
* Need to call this _before_ adding the STA so it can
* look up the one STA to use to ask mac80211 to leave
* OMI; in the unlikely event that adding the new STA
* then fails we'll just re-enter OMI later (via the
* statistics notification handling.)
*/
iwl_mld_leave_omi_bw_reduction(mld);
ret = iwl_mld_add_sta(mld, sta, vif, STATION_TYPE_PEER);
if (ret)
return ret;
/* just added first TDLS STA, so disable PM */
if (sta->tdls && tdls_count == 0)
iwl_mld_update_mac_power(mld, vif, false);
if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
mld_vif->ap_sta = sta;
/* Initialize TLC here already - this really tells
* the firmware only what the supported legacy rates are
* (may be) since it's initialized already from what the
* AP advertised in the beacon/probe response. This will
* allow the firmware to send auth/assoc frames with one
* of the supported rates already, rather than having to
* use a mandatory rate.
* If we're the AP, we'll just assume mandatory rates at
* this point, but we know nothing about the STA anyway.
*/
iwl_mld_config_tlc(mld, vif, sta);
return ret;
} else if (old_state == IEEE80211_STA_NONE &&
new_state == IEEE80211_STA_AUTH) {
iwl_mld_set_uapsd(mld, vif);
return 0;
} else if (old_state == IEEE80211_STA_AUTH &&
new_state == IEEE80211_STA_ASSOC) {
ret = iwl_mld_update_all_link_stations(mld, sta);
if (vif->type == NL80211_IFTYPE_STATION)
iwl_mld_link_set_2mhz_block(mld, vif, sta);
/* Now the link_sta's capabilities are set, update the FW */
iwl_mld_config_tlc(mld, vif, sta);
if (vif->type == NL80211_IFTYPE_AP) {
/* Update MAC_CFG_FILTER_ACCEPT_BEACON if at least
* one sta is associated
*/
if (++mld_vif->num_associated_stas == 1)
ret = iwl_mld_mac_fw_action(mld, vif,
FW_CTXT_ACTION_MODIFY);
}
return ret;
} else if (old_state == IEEE80211_STA_ASSOC &&
new_state == IEEE80211_STA_AUTHORIZED) {
ret = 0;
if (!sta->tdls) {
mld_vif->authorized = true;
/* Ensure any block due to a non-BSS link is synced */
iwl_mld_emlsr_check_non_bss_block(mld, 0);
/* Block EMLSR until a certain throughput it reached */
if (!mld->fw_status.in_hw_restart &&
IWL_MLD_ENTER_EMLSR_TPT_THRESH > 0)
iwl_mld_block_emlsr(mld_vif->mld, vif,
IWL_MLD_EMLSR_BLOCKED_TPT,
0);
/* clear COEX_HIGH_PRIORITY_ENABLE */
ret = iwl_mld_mac_fw_action(mld, vif,
FW_CTXT_ACTION_MODIFY);
if (ret)
return ret;
iwl_mld_smps_wa(mld, vif, vif->cfg.ps);
}
/* MFP is set by default before the station is authorized.
* Clear it here in case it's not used.
*/
if (!sta->mfp)
ret = iwl_mld_update_all_link_stations(mld, sta);
/* We can use wide bandwidth now, not only 20 MHz */
iwl_mld_config_tlc(mld, vif, sta);
return ret;
} else {
return -EINVAL;
}
}
static int iwl_mld_move_sta_state_down(struct iwl_mld *mld,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta,
enum ieee80211_sta_state old_state,
enum ieee80211_sta_state new_state)
{
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
if (old_state == IEEE80211_STA_AUTHORIZED &&
new_state == IEEE80211_STA_ASSOC) {
if (!sta->tdls) {
mld_vif->authorized = false;
memset(&mld_vif->emlsr.zeroed_on_not_authorized, 0,
sizeof(mld_vif->emlsr.zeroed_on_not_authorized));
wiphy_delayed_work_cancel(mld->wiphy,
&mld_vif->emlsr.prevent_done_wk);
wiphy_delayed_work_cancel(mld->wiphy,
&mld_vif->emlsr.tmp_non_bss_done_wk);
wiphy_work_cancel(mld->wiphy, &mld_vif->emlsr.unblock_tpt_wk);
wiphy_delayed_work_cancel(mld->wiphy,
&mld_vif->emlsr.check_tpt_wk);
iwl_mld_reset_cca_40mhz_workaround(mld, vif);
iwl_mld_smps_wa(mld, vif, true);
}
/* once we move into assoc state, need to update the FW to
* stop using wide bandwidth
*/
iwl_mld_config_tlc(mld, vif, sta);
} else if (old_state == IEEE80211_STA_ASSOC &&
new_state == IEEE80211_STA_AUTH) {
if (vif->type == NL80211_IFTYPE_AP &&
!WARN_ON(!mld_vif->num_associated_stas)) {
/* Update MAC_CFG_FILTER_ACCEPT_BEACON if the last sta
* is disassociating
*/
if (--mld_vif->num_associated_stas == 0)
iwl_mld_mac_fw_action(mld, vif,
FW_CTXT_ACTION_MODIFY);
}
} else if (old_state == IEEE80211_STA_AUTH &&
new_state == IEEE80211_STA_NONE) {
/* nothing */
} else if (old_state == IEEE80211_STA_NONE &&
new_state == IEEE80211_STA_NOTEXIST) {
iwl_mld_remove_sta(mld, sta);
if (sta->tdls && iwl_mld_tdls_sta_count(mld) == 0) {
/* just removed last TDLS STA, so enable PM */
iwl_mld_update_mac_power(mld, vif, false);
}
} else {
return -EINVAL;
}
return 0;
}
static int iwl_mld_mac80211_sta_state(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta,
enum ieee80211_sta_state old_state,
enum ieee80211_sta_state new_state)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
struct iwl_mld_sta *mld_sta = iwl_mld_sta_from_mac80211(sta);
IWL_DEBUG_MAC80211(mld, "station %pM state change %d->%d\n",
sta->addr, old_state, new_state);
mld_sta->sta_state = new_state;
if (old_state < new_state)
return iwl_mld_move_sta_state_up(mld, vif, sta, old_state,
new_state);
else
return iwl_mld_move_sta_state_down(mld, vif, sta, old_state,
new_state);
}
static void iwl_mld_mac80211_flush(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
u32 queues, bool drop)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
/* Make sure we're done with the deferred traffic before flushing */
iwl_mld_add_txq_list(mld);
for (int i = 0; i < mld->fw->ucode_capa.num_stations; i++) {
struct ieee80211_link_sta *link_sta =
wiphy_dereference(mld->wiphy,
mld->fw_id_to_link_sta[i]);
if (IS_ERR_OR_NULL(link_sta))
continue;
/* Check that the sta belongs to the given vif */
if (vif && vif != iwl_mld_sta_from_mac80211(link_sta->sta)->vif)
continue;
if (drop)
iwl_mld_flush_sta_txqs(mld, link_sta->sta);
else
iwl_mld_wait_sta_txqs_empty(mld, link_sta->sta);
}
}
static void iwl_mld_mac80211_flush_sta(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
iwl_mld_flush_sta_txqs(mld, sta);
}
static int
iwl_mld_mac80211_ampdu_action(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_ampdu_params *params)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
struct ieee80211_sta *sta = params->sta;
enum ieee80211_ampdu_mlme_action action = params->action;
u16 tid = params->tid;
u16 ssn = params->ssn;
u16 buf_size = params->buf_size;
u16 timeout = params->timeout;
int ret;
IWL_DEBUG_HT(mld, "A-MPDU action on addr %pM tid: %d action: %d\n",
sta->addr, tid, action);
switch (action) {
case IEEE80211_AMPDU_RX_START:
ret = iwl_mld_ampdu_rx_start(mld, sta, tid, ssn, buf_size,
timeout);
break;
case IEEE80211_AMPDU_RX_STOP:
ret = iwl_mld_ampdu_rx_stop(mld, sta, tid);
break;
default:
/* The mac80211 TX_AMPDU_SETUP_IN_HW flag is set for all
* devices, since all support TX A-MPDU offload in hardware.
* Therefore, no TX action should be requested here.
*/
WARN_ON_ONCE(1);
return -EINVAL;
}
return ret;
}
static bool iwl_mld_can_hw_csum(struct sk_buff *skb)
{
u8 protocol = ip_hdr(skb)->protocol;
return protocol == IPPROTO_TCP || protocol == IPPROTO_UDP;
}
static bool iwl_mld_mac80211_can_aggregate(struct ieee80211_hw *hw,
struct sk_buff *head,
struct sk_buff *skb)
{
if (!IS_ENABLED(CONFIG_INET))
return false;
/* For now don't aggregate IPv6 in AMSDU */
if (skb->protocol != htons(ETH_P_IP))
return false;
/* Allow aggregation only if both frames have the same HW csum offload
* capability, ensuring consistent HW or SW csum handling in A-MSDU.
*/
return iwl_mld_can_hw_csum(skb) == iwl_mld_can_hw_csum(head);
}
static void iwl_mld_mac80211_sync_rx_queues(struct ieee80211_hw *hw)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
iwl_mld_sync_rx_queues(mld, IWL_MLD_RXQ_EMPTY, NULL, 0);
}
static void iwl_mld_sta_rc_update(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_link_sta *link_sta,
u32 changed)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
if (changed & (IEEE80211_RC_BW_CHANGED |
IEEE80211_RC_SUPP_RATES_CHANGED |
IEEE80211_RC_NSS_CHANGED)) {
struct ieee80211_bss_conf *link =
link_conf_dereference_check(vif, link_sta->link_id);
if (WARN_ON(!link))
return;
iwl_mld_config_tlc_link(mld, vif, link, link_sta);
}
}
#ifdef CONFIG_PM_SLEEP
static void iwl_mld_set_wakeup(struct ieee80211_hw *hw, bool enabled)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
device_set_wakeup_enable(mld->trans->dev, enabled);
}
/* Returns 0 on success. 1 if failed to suspend with wowlan:
* If the circumstances didn't satisfy the conditions for suspension
* with wowlan, mac80211 would use the no_wowlan flow.
* If an error had occurred we update the trans status and state here
* and the result will be stopping the FW.
*/
static int
iwl_mld_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
int ret;
iwl_fw_runtime_suspend(&mld->fwrt);
ret = iwl_mld_wowlan_suspend(mld, wowlan);
if (ret) {
if (ret < 0) {
mld->trans->state = IWL_TRANS_NO_FW;
set_bit(STATUS_FW_ERROR, &mld->trans->status);
}
return 1;
}
if (iwl_mld_no_wowlan_suspend(mld))
return 1;
return 0;
}
static int iwl_mld_resume(struct ieee80211_hw *hw)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
int ret;
ret = iwl_mld_wowlan_resume(mld);
if (ret)
return ret;
iwl_fw_runtime_resume(&mld->fwrt);
iwl_mld_low_latency_restart(mld);
return 0;
}
#endif
static int iwl_mld_alloc_ptk_pn(struct iwl_mld *mld,
struct iwl_mld_sta *mld_sta,
struct ieee80211_key_conf *key,
struct iwl_mld_ptk_pn **ptk_pn)
{
u8 num_rx_queues = mld->trans->num_rx_queues;
int keyidx = key->keyidx;
struct ieee80211_key_seq seq;
if (WARN_ON(keyidx >= ARRAY_SIZE(mld_sta->ptk_pn)))
return -EINVAL;
WARN_ON(rcu_access_pointer(mld_sta->ptk_pn[keyidx]));
*ptk_pn = kzalloc(struct_size(*ptk_pn, q, num_rx_queues),
GFP_KERNEL);
if (!*ptk_pn)
return -ENOMEM;
for (u8 tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
ieee80211_get_key_rx_seq(key, tid, &seq);
for (u8 q = 0; q < num_rx_queues; q++)
memcpy((*ptk_pn)->q[q].pn[tid], seq.ccmp.pn,
IEEE80211_CCMP_PN_LEN);
}
rcu_assign_pointer(mld_sta->ptk_pn[keyidx], *ptk_pn);
return 0;
}
static int iwl_mld_set_key_add(struct iwl_mld *mld,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta,
struct ieee80211_key_conf *key)
{
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
struct iwl_mld_sta *mld_sta =
sta ? iwl_mld_sta_from_mac80211(sta) : NULL;
struct iwl_mld_ptk_pn *ptk_pn = NULL;
int keyidx = key->keyidx;
int ret;
/* Will be set to 0 if added successfully */
key->hw_key_idx = STA_KEY_IDX_INVALID;
switch (key->cipher) {
case WLAN_CIPHER_SUITE_WEP40:
case WLAN_CIPHER_SUITE_WEP104:
IWL_DEBUG_MAC80211(mld, "Use SW encryption for WEP\n");
return -EOPNOTSUPP;
case WLAN_CIPHER_SUITE_TKIP:
if (vif->type == NL80211_IFTYPE_STATION) {
key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE;
break;
}
IWL_DEBUG_MAC80211(mld, "Use SW encryption for TKIP\n");
return -EOPNOTSUPP;
case WLAN_CIPHER_SUITE_CCMP:
case WLAN_CIPHER_SUITE_GCMP:
case WLAN_CIPHER_SUITE_GCMP_256:
case WLAN_CIPHER_SUITE_AES_CMAC:
case WLAN_CIPHER_SUITE_BIP_GMAC_128:
case WLAN_CIPHER_SUITE_BIP_GMAC_256:
break;
default:
return -EOPNOTSUPP;
}
if (vif->type == NL80211_IFTYPE_STATION &&
(keyidx == 6 || keyidx == 7))
rcu_assign_pointer(mld_vif->bigtks[keyidx - 6], key);
/* After exiting from RFKILL, hostapd configures GTK/ITGK before the
* AP is started, but those keys can't be sent to the FW before the
* MCAST/BCAST STAs are added to it (which happens upon AP start).
* Store it here to be sent later when the AP is started.
*/
if ((vif->type == NL80211_IFTYPE_ADHOC ||
vif->type == NL80211_IFTYPE_AP) && !sta &&
!mld_vif->ap_ibss_active)
return iwl_mld_store_ap_early_key(mld, key, mld_vif);
if (!mld->fw_status.in_hw_restart && mld_sta &&
key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
(key->cipher == WLAN_CIPHER_SUITE_CCMP ||
key->cipher == WLAN_CIPHER_SUITE_GCMP ||
key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
ret = iwl_mld_alloc_ptk_pn(mld, mld_sta, key, &ptk_pn);
if (ret)
return ret;
}
IWL_DEBUG_MAC80211(mld, "set hwcrypto key (sta:%pM, id:%d)\n",
sta ? sta->addr : NULL, keyidx);
ret = iwl_mld_add_key(mld, vif, sta, key);
if (ret) {
IWL_WARN(mld, "set key failed (%d)\n", ret);
if (ptk_pn) {
RCU_INIT_POINTER(mld_sta->ptk_pn[keyidx], NULL);
kfree(ptk_pn);
}
return -EOPNOTSUPP;
}
return 0;
}
static void iwl_mld_set_key_remove(struct iwl_mld *mld,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta,
struct ieee80211_key_conf *key)
{
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
struct iwl_mld_sta *mld_sta =
sta ? iwl_mld_sta_from_mac80211(sta) : NULL;
int keyidx = key->keyidx;
if (vif->type == NL80211_IFTYPE_STATION &&
(keyidx == 6 || keyidx == 7))
RCU_INIT_POINTER(mld_vif->bigtks[keyidx - 6], NULL);
if (mld_sta && key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
(key->cipher == WLAN_CIPHER_SUITE_CCMP ||
key->cipher == WLAN_CIPHER_SUITE_GCMP ||
key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
struct iwl_mld_ptk_pn *ptk_pn;
if (WARN_ON(keyidx >= ARRAY_SIZE(mld_sta->ptk_pn)))
return;
ptk_pn = wiphy_dereference(mld->wiphy,
mld_sta->ptk_pn[keyidx]);
RCU_INIT_POINTER(mld_sta->ptk_pn[keyidx], NULL);
if (!WARN_ON(!ptk_pn))
kfree_rcu(ptk_pn, rcu_head);
}
/* if this key was stored to be added later to the FW - free it here */
if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
iwl_mld_free_ap_early_key(mld, key, mld_vif);
/* We already removed it */
if (key->hw_key_idx == STA_KEY_IDX_INVALID)
return;
IWL_DEBUG_MAC80211(mld, "disable hwcrypto key\n");
iwl_mld_remove_key(mld, vif, sta, key);
}
static int iwl_mld_mac80211_set_key(struct ieee80211_hw *hw,
enum set_key_cmd cmd,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta,
struct ieee80211_key_conf *key)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
int ret;
switch (cmd) {
case SET_KEY:
ret = iwl_mld_set_key_add(mld, vif, sta, key);
if (ret)
ret = -EOPNOTSUPP;
break;
case DISABLE_KEY:
iwl_mld_set_key_remove(mld, vif, sta, key);
ret = 0;
break;
default:
ret = -EINVAL;
break;
}
return ret;
}
static int
iwl_mld_pre_channel_switch(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_channel_switch *chsw)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
struct iwl_mld_link *mld_link =
iwl_mld_link_dereference_check(mld_vif, chsw->link_id);
u8 primary;
int selected;
lockdep_assert_wiphy(mld->wiphy);
if (WARN_ON(!mld_link))
return -EINVAL;
IWL_DEBUG_MAC80211(mld, "pre CSA to freq %d\n",
chsw->chandef.center_freq1);
if (!iwl_mld_emlsr_active(vif))
return 0;
primary = iwl_mld_get_primary_link(vif);
/* stay on the primary link unless it is undergoing a CSA with quiet */
if (chsw->link_id == primary && chsw->block_tx)
selected = iwl_mld_get_other_link(vif, primary);
else
selected = primary;
/* Remember to tell the firmware that this link can't tx
* Note that this logic seems to be unrelated to emlsr, but it
* really is needed only when emlsr is active. When we have a
* single link, the firmware will handle all this on its own.
* In multi-link scenarios, we can learn about the CSA from
* another link and this logic is too complex for the firmware
* to track.
* Since we want to de-activate the link that got a CSA with mode=1,
* we need to tell the firmware not to send any frame on that link
* as the firmware may not be aware that link is under a CSA
* with mode=1 (no Tx allowed).
*/
mld_link->silent_deactivation = chsw->block_tx;
iwl_mld_exit_emlsr(mld, vif, IWL_MLD_EMLSR_EXIT_CSA, selected);
return 0;
}
static void
iwl_mld_channel_switch(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_channel_switch *chsw)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
/* By implementing this operation, we prevent mac80211 from
* starting its own channel switch timer, so that we can call
* ieee80211_chswitch_done() ourselves at the right time
* (Upon receiving the channel_switch_start notification from the fw)
*/
IWL_DEBUG_MAC80211(mld,
"dummy channel switch op\n");
}
static int
iwl_mld_post_channel_switch(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_bss_conf *link_conf)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
struct iwl_mld_link *mld_link = iwl_mld_link_from_mac80211(link_conf);
lockdep_assert_wiphy(mld->wiphy);
WARN_ON(mld_link->silent_deactivation);
return 0;
}
static void
iwl_mld_abort_channel_switch(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_bss_conf *link_conf)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
struct iwl_mld_link *mld_link = iwl_mld_link_from_mac80211(link_conf);
IWL_DEBUG_MAC80211(mld,
"abort channel switch op\n");
mld_link->silent_deactivation = false;
}
static int
iwl_mld_switch_vif_chanctx_swap(struct ieee80211_hw *hw,
struct ieee80211_vif_chanctx_switch *vifs)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
int ret;
iwl_mld_unassign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf,
vifs[0].old_ctx);
iwl_mld_remove_chanctx(hw, vifs[0].old_ctx);
ret = iwl_mld_add_chanctx(hw, vifs[0].new_ctx);
if (ret) {
IWL_ERR(mld, "failed to add new_ctx during channel switch\n");
goto out_reassign;
}
ret = iwl_mld_assign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf,
vifs[0].new_ctx);
if (ret) {
IWL_ERR(mld,
"failed to assign new_ctx during channel switch\n");
goto out_remove;
}
return 0;
out_remove:
iwl_mld_remove_chanctx(hw, vifs[0].new_ctx);
out_reassign:
if (iwl_mld_add_chanctx(hw, vifs[0].old_ctx)) {
IWL_ERR(mld, "failed to add old_ctx after failure\n");
return ret;
}
if (iwl_mld_assign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf,
vifs[0].old_ctx))
IWL_ERR(mld, "failed to reassign old_ctx after failure\n");
return ret;
}
static int
iwl_mld_switch_vif_chanctx_reassign(struct ieee80211_hw *hw,
struct ieee80211_vif_chanctx_switch *vifs)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
int ret;
iwl_mld_unassign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf,
vifs[0].old_ctx);
ret = iwl_mld_assign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf,
vifs[0].new_ctx);
if (ret) {
IWL_ERR(mld,
"failed to assign new_ctx during channel switch\n");
goto out_reassign;
}
return 0;
out_reassign:
if (iwl_mld_assign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf,
vifs[0].old_ctx))
IWL_ERR(mld, "failed to reassign old_ctx after failure\n");
return ret;
}
static int
iwl_mld_switch_vif_chanctx(struct ieee80211_hw *hw,
struct ieee80211_vif_chanctx_switch *vifs,
int n_vifs,
enum ieee80211_chanctx_switch_mode mode)
{
int ret;
/* we only support a single-vif right now */
if (n_vifs > 1)
return -EOPNOTSUPP;
switch (mode) {
case CHANCTX_SWMODE_SWAP_CONTEXTS:
ret = iwl_mld_switch_vif_chanctx_swap(hw, vifs);
break;
case CHANCTX_SWMODE_REASSIGN_VIF:
ret = iwl_mld_switch_vif_chanctx_reassign(hw, vifs);
break;
default:
ret = -EOPNOTSUPP;
break;
}
return ret;
}
static void iwl_mld_sta_pre_rcu_remove(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
struct iwl_mld_sta *mld_sta = iwl_mld_sta_from_mac80211(sta);
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
struct iwl_mld_link_sta *mld_link_sta;
u8 link_id;
lockdep_assert_wiphy(mld->wiphy);
/* This is called before mac80211 does RCU synchronisation,
* so here we already invalidate our internal RCU-protected
* station pointer. The rest of the code will thus no longer
* be able to find the station this way, and we don't rely
* on further RCU synchronisation after the sta_state()
* callback deleted the station.
*/
for_each_mld_link_sta(mld_sta, mld_link_sta, link_id)
RCU_INIT_POINTER(mld->fw_id_to_link_sta[mld_link_sta->fw_id],
NULL);
if (sta == mld_vif->ap_sta)
mld_vif->ap_sta = NULL;
}
static void
iwl_mld_mac80211_mgd_protect_tdls_discover(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
unsigned int link_id)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
struct ieee80211_bss_conf *link_conf;
u32 duration;
int ret;
link_conf = wiphy_dereference(hw->wiphy, vif->link_conf[link_id]);
if (WARN_ON_ONCE(!link_conf))
return;
/* Protect the session to hear the TDLS setup response on the channel */
duration = 2 * link_conf->dtim_period * link_conf->beacon_int;
ret = iwl_mld_start_session_protection(mld, vif, duration, duration,
link_id, HZ / 5);
if (ret)
IWL_ERR(mld,
"Failed to start session protection for TDLS: %d\n",
ret);
}
static bool iwl_mld_can_activate_links(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
u16 desired_links)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
int n_links = hweight16(desired_links);
/* Check if HW supports the wanted number of links */
return n_links <= iwl_mld_max_active_links(mld, vif);
}
static int
iwl_mld_change_vif_links(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
u16 old_links, u16 new_links,
struct ieee80211_bss_conf *old[IEEE80211_MLD_MAX_NUM_LINKS])
{
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
struct ieee80211_bss_conf *link_conf;
u16 removed = old_links & ~new_links;
u16 added = new_links & ~old_links;
int err;
lockdep_assert_wiphy(mld->wiphy);
/*
* No bits designate non-MLO mode. We can handle MLO exit/enter by
* simply mapping that to link ID zero internally.
* Note that mac80211 does such a non-MLO to MLO switch during restart
* if it was in MLO before. In that case, we do not have a link to
* remove.
*/
if (old_links == 0 && !mld->fw_status.in_hw_restart)
removed |= BIT(0);
if (new_links == 0)
added |= BIT(0);
for (int i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
if (removed & BIT(i))
iwl_mld_remove_link(mld, old[i]);
}
for (int i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
if (added & BIT(i)) {
link_conf = link_conf_dereference_protected(vif, i);
if (WARN_ON(!link_conf))
return -EINVAL;
err = iwl_mld_add_link(mld, link_conf);
if (err)
goto remove_added_links;
}
}
/*
* Ensure we always have a valid primary_link. When using multiple
* links the proper value is set in assign_vif_chanctx.
*/
mld_vif->emlsr.primary = new_links ? __ffs(new_links) : 0;
/*
* Special MLO restart case. We did not have a link when the interface
* was added, so do the power configuration now.
*/
if (old_links == 0 && mld->fw_status.in_hw_restart)
iwl_mld_update_mac_power(mld, vif, false);
return 0;
remove_added_links:
for (int i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
if (!(added & BIT(i)))
continue;
link_conf = link_conf_dereference_protected(vif, i);
if (!link_conf || !iwl_mld_link_from_mac80211(link_conf))
continue;
iwl_mld_remove_link(mld, link_conf);
}
return err;
}
static int iwl_mld_change_sta_links(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta,
u16 old_links, u16 new_links)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
return iwl_mld_update_link_stas(mld, vif, sta, old_links, new_links);
}
static int iwl_mld_mac80211_join_ibss(struct ieee80211_hw *hw,
struct ieee80211_vif *vif)
{
return iwl_mld_start_ap_ibss(hw, vif, &vif->bss_conf);
}
static void iwl_mld_mac80211_leave_ibss(struct ieee80211_hw *hw,
struct ieee80211_vif *vif)
{
return iwl_mld_stop_ap_ibss(hw, vif, &vif->bss_conf);
}
static int iwl_mld_mac80211_tx_last_beacon(struct ieee80211_hw *hw)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
return mld->ibss_manager;
}
#define IWL_MLD_EMLSR_BLOCKED_TMP_NON_BSS_TIMEOUT (5 * HZ)
static void iwl_mld_vif_iter_emlsr_block_tmp_non_bss(void *_data, u8 *mac,
struct ieee80211_vif *vif)
{
struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
int ret;
if (!iwl_mld_vif_has_emlsr_cap(vif))
return;
ret = iwl_mld_block_emlsr_sync(mld_vif->mld, vif,
IWL_MLD_EMLSR_BLOCKED_TMP_NON_BSS,
iwl_mld_get_primary_link(vif));
if (ret)
return;
wiphy_delayed_work_queue(mld_vif->mld->wiphy,
&mld_vif->emlsr.tmp_non_bss_done_wk,
IWL_MLD_EMLSR_BLOCKED_TMP_NON_BSS_TIMEOUT);
}
static void iwl_mld_prep_add_interface(struct ieee80211_hw *hw,
enum nl80211_iftype type)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
IWL_DEBUG_MAC80211(mld, "prep_add_interface: type=%u\n", type);
if (!(type == NL80211_IFTYPE_AP ||
type == NL80211_IFTYPE_P2P_GO ||
type == NL80211_IFTYPE_P2P_CLIENT))
return;
ieee80211_iterate_active_interfaces_mtx(mld->hw,
IEEE80211_IFACE_ITER_NORMAL,
iwl_mld_vif_iter_emlsr_block_tmp_non_bss,
NULL);
}
static int iwl_mld_set_hw_timestamp(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct cfg80211_set_hw_timestamp *hwts)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
u32 protocols = 0;
/* HW timestamping is only supported for a specific station */
if (!hwts->macaddr)
return -EOPNOTSUPP;
if (hwts->enable)
protocols =
IWL_TIME_SYNC_PROTOCOL_TM | IWL_TIME_SYNC_PROTOCOL_FTM;
return iwl_mld_time_sync_config(mld, hwts->macaddr, protocols);
}
static int iwl_mld_start_pmsr(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct cfg80211_pmsr_request *request)
{
struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
return iwl_mld_ftm_start(mld, vif, request);
}
const struct ieee80211_ops iwl_mld_hw_ops = {
.tx = iwl_mld_mac80211_tx,
.start = iwl_mld_mac80211_start,
.stop = iwl_mld_mac80211_stop,
.config = iwl_mld_mac80211_config,
.add_interface = iwl_mld_mac80211_add_interface,
.remove_interface = iwl_mld_mac80211_remove_interface,
.conf_tx = iwl_mld_mac80211_conf_tx,
.prepare_multicast = iwl_mld_mac80211_prepare_multicast,
.configure_filter = iwl_mld_mac80211_configure_filter,
.reconfig_complete = iwl_mld_mac80211_reconfig_complete,
.wake_tx_queue = iwl_mld_mac80211_wake_tx_queue,
.add_chanctx = iwl_mld_add_chanctx,
.remove_chanctx = iwl_mld_remove_chanctx,
.change_chanctx = iwl_mld_change_chanctx,
.assign_vif_chanctx = iwl_mld_assign_vif_chanctx,
.unassign_vif_chanctx = iwl_mld_unassign_vif_chanctx,
.set_rts_threshold = iwl_mld_mac80211_set_rts_threshold,
.link_info_changed = iwl_mld_mac80211_link_info_changed,
.vif_cfg_changed = iwl_mld_mac80211_vif_cfg_changed,
.set_key = iwl_mld_mac80211_set_key,
.hw_scan = iwl_mld_mac80211_hw_scan,
.cancel_hw_scan = iwl_mld_mac80211_cancel_hw_scan,
.sched_scan_start = iwl_mld_mac80211_sched_scan_start,
.sched_scan_stop = iwl_mld_mac80211_sched_scan_stop,
.mgd_prepare_tx = iwl_mld_mac80211_mgd_prepare_tx,
.mgd_complete_tx = iwl_mld_mac_mgd_complete_tx,
.sta_state = iwl_mld_mac80211_sta_state,
.sta_statistics = iwl_mld_mac80211_sta_statistics,
.flush = iwl_mld_mac80211_flush,
.flush_sta = iwl_mld_mac80211_flush_sta,
.ampdu_action = iwl_mld_mac80211_ampdu_action,
.can_aggregate_in_amsdu = iwl_mld_mac80211_can_aggregate,
.sync_rx_queues = iwl_mld_mac80211_sync_rx_queues,
.link_sta_rc_update = iwl_mld_sta_rc_update,
.start_ap = iwl_mld_start_ap_ibss,
.stop_ap = iwl_mld_stop_ap_ibss,
.pre_channel_switch = iwl_mld_pre_channel_switch,
.channel_switch = iwl_mld_channel_switch,
.post_channel_switch = iwl_mld_post_channel_switch,
.abort_channel_switch = iwl_mld_abort_channel_switch,
.switch_vif_chanctx = iwl_mld_switch_vif_chanctx,
.sta_pre_rcu_remove = iwl_mld_sta_pre_rcu_remove,
.remain_on_channel = iwl_mld_start_roc,
.cancel_remain_on_channel = iwl_mld_cancel_roc,
.can_activate_links = iwl_mld_can_activate_links,
.change_vif_links = iwl_mld_change_vif_links,
.change_sta_links = iwl_mld_change_sta_links,
#ifdef CONFIG_PM_SLEEP
.suspend = iwl_mld_suspend,
.resume = iwl_mld_resume,
.set_wakeup = iwl_mld_set_wakeup,
.set_rekey_data = iwl_mld_set_rekey_data,
#if IS_ENABLED(CONFIG_IPV6)
.ipv6_addr_change = iwl_mld_ipv6_addr_change,
#endif /* IS_ENABLED(CONFIG_IPV6) */
#endif /* CONFIG_PM_SLEEP */
#ifdef CONFIG_IWLWIFI_DEBUGFS
.vif_add_debugfs = iwl_mld_add_vif_debugfs,
.link_add_debugfs = iwl_mld_add_link_debugfs,
.link_sta_add_debugfs = iwl_mld_add_link_sta_debugfs,
#endif
.mgd_protect_tdls_discover = iwl_mld_mac80211_mgd_protect_tdls_discover,
.join_ibss = iwl_mld_mac80211_join_ibss,
.leave_ibss = iwl_mld_mac80211_leave_ibss,
.tx_last_beacon = iwl_mld_mac80211_tx_last_beacon,
.prep_add_interface = iwl_mld_prep_add_interface,
.set_hw_timestamp = iwl_mld_set_hw_timestamp,
.start_pmsr = iwl_mld_start_pmsr,
};
|