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
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
|
From e478ab518612f1a821968e1bb5b08b01b10085b0 Mon Sep 17 00:00:00 2001
From: Po Liu <Po.Liu@nxp.com>
Date: Tue, 15 Oct 2019 16:11:40 +0800
Subject: [PATCH] net:tsn: netlink interface for APP layer to config TSN
capability hardware ports
This patch provids netlink method to configure the TSN protocols hardwares.
TSN guaranteed packet transport with bounded low latency, low packet delay
variation, and low packet loss by hardware and software methods.
The three basic components of TSN are:
1. Time synchronization: This was implement by 8021AS which base on the
IEEE1588 precision Time Protocol. This is configured by the other way
in kernel.
8021AS not included in this patch.
2. Scheduling and traffic shaping and per-stream filter policing:
This patch support Qbv/Qci/Qbu/8021CB/Qav etc.
3. Selection of communication paths:
This patch not support the pure software only TSN protocols(like Qcc)
but hardware related configuration.
TSN Protocols supports by this patch: Qbv/Qci/Qbu/Credit-base Shaper(Qav).
This patch verified on NXP ls1028ardb board.
Signed-off-by: Po Liu <Po.Liu@nxp.com>
---
include/net/tsn.h | 114 ++
include/uapi/linux/tsn.h | 1207 +++++++++++++++
net/Kconfig | 1 +
net/Makefile | 3 +
net/tsn/Kconfig | 15 +
net/tsn/Makefile | 1 +
net/tsn/genl_tsn.c | 3696 ++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 5037 insertions(+)
create mode 100644 include/net/tsn.h
create mode 100644 include/uapi/linux/tsn.h
create mode 100644 net/tsn/Kconfig
create mode 100644 net/tsn/Makefile
create mode 100644 net/tsn/genl_tsn.c
--- /dev/null
+++ b/include/net/tsn.h
@@ -0,0 +1,114 @@
+/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
+/* Copyright 2017-2019 NXP */
+
+#ifndef __TSN_H__
+#define __TSN_H__
+
+#include <linux/notifier.h>
+#include <uapi/linux/tsn.h>
+
+enum tsn_notifier_type {
+ TSN_QBV_CONFIGCHANGETIME_ARRIVE = 1,
+};
+
+struct tsn_notifier_info {
+ struct net_device *dev;
+ union {
+ struct tsn_qbv_conf qbv_notify;
+ struct tsn_qci_psfp_sgi_conf qci_notify;
+ } ntdata;
+};
+
+static inline struct net_device *
+tsn_notifier_info_to_dev(const struct tsn_notifier_info *info)
+{
+ return info->dev;
+}
+
+struct tsn_ops {
+ void (*device_init)(struct net_device *ndev);
+ void (*device_deinit)(struct net_device *ndev);
+ u32 (*get_capability)(struct net_device *ndev);
+ /* Qbv standard */
+ int (*qbv_set)(struct net_device *ndev, struct tsn_qbv_conf *qbvconf);
+ int (*qbv_get)(struct net_device *ndev, struct tsn_qbv_conf *qbvconf);
+ int (*qbv_get_status)(struct net_device *ndev,
+ struct tsn_qbv_status *qbvstat);
+ int (*cb_streamid_set)(struct net_device *ndev, u32 index,
+ bool enable, struct tsn_cb_streamid *sid);
+ int (*cb_streamid_get)(struct net_device *ndev, u32 index,
+ struct tsn_cb_streamid *sid);
+ int (*cb_streamid_counters_get)(struct net_device *ndev, u32 index,
+ struct tsn_cb_streamid_counters *sidcounter);
+ int (*qci_get_maxcap)(struct net_device *ndev,
+ struct tsn_qci_psfp_stream_param *qcicapa);
+ int (*qci_sfi_set)(struct net_device *ndev, u32 index, bool enable,
+ struct tsn_qci_psfp_sfi_conf *sficonf);
+ /* return: 0 stream filter instance not valid
+ * 1 stream filter instance valid
+ * -1 error happened
+ */
+ int (*qci_sfi_get)(struct net_device *ndev, u32 index,
+ struct tsn_qci_psfp_sfi_conf *sficonf);
+ int (*qci_sfi_counters_get)(struct net_device *ndev, u32 index,
+ struct tsn_qci_psfp_sfi_counters *sficounter);
+ int (*qci_sgi_set)(struct net_device *ndev, u32 index,
+ struct tsn_qci_psfp_sgi_conf *sgiconf);
+ int (*qci_sgi_get)(struct net_device *ndev, u32 index,
+ struct tsn_qci_psfp_sgi_conf *sgiconf);
+ int (*qci_sgi_status_get)(struct net_device *ndev, u16 index,
+ struct tsn_psfp_sgi_status *sgistat);
+ int (*qci_fmi_set)(struct net_device *ndev, u32 index, bool enable,
+ struct tsn_qci_psfp_fmi *fmi);
+ int (*qci_fmi_get)(struct net_device *ndev, u32 index,
+ struct tsn_qci_psfp_fmi *fmi,
+ struct tsn_qci_psfp_fmi_counters *counters);
+ int (*cbs_set)(struct net_device *ndev, u8 tc, u8 bw);
+ int (*cbs_get)(struct net_device *ndev, u8 tc);
+ /* To set a 8 bits vector shows 8 traffic classes
+ * preemtable(1) or express(0)
+ */
+ int (*qbu_set)(struct net_device *ndev, u8 ptvector);
+ /* To get port preemtion status */
+ int (*qbu_get)(struct net_device *ndev,
+ struct tsn_preempt_status *preemptstat);
+ int (*tsd_set)(struct net_device *ndev, struct tsn_tsd *tsd);
+ int (*tsd_get)(struct net_device *ndev, struct tsn_tsd_status *stats);
+ int (*ct_set)(struct net_device *ndev, u8 cut_thru);
+ int (*cbgen_set)(struct net_device *ndev, u32 index,
+ struct tsn_seq_gen_conf *seqgen);
+ int (*cbrec_set)(struct net_device *ndev, u32 index,
+ struct tsn_seq_rec_conf *seqrec);
+ int (*cb_get)(struct net_device *ndev, u32 index,
+ struct tsn_cb_status *c);
+ int (*dscp_set)(struct net_device *ndev, bool enable,
+ const u8 dscp_ix,
+ struct tsn_qos_switch_dscp_conf *c);
+};
+
+enum ethdev_type {
+ TSN_SWITCH,
+ TSN_ENDPOINT,
+};
+
+#define GROUP_OFFSET_SWITCH 256
+
+struct tsn_port {
+ u16 groupid;
+ struct tsn_ops *tsnops;
+ struct net_device *netdev;
+ struct list_head list;
+ enum ethdev_type type;
+ u8 tc_nums;
+ struct tsn_notifier_info nd;
+};
+
+struct tsn_port *tsn_get_port(struct net_device *ndev);
+int register_tsn_notifier(struct notifier_block *nb);
+int unregister_tsn_notifier(struct notifier_block *nb);
+int call_tsn_notifiers(unsigned long val, struct net_device *dev,
+ struct tsn_notifier_info *info);
+int tsn_port_register(struct net_device *netdev,
+ struct tsn_ops *tsnops, u16 groupid);
+void tsn_port_unregister(struct net_device *netdev);
+#endif
--- /dev/null
+++ b/include/uapi/linux/tsn.h
@@ -0,0 +1,1207 @@
+/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
+/* Copyright 2017-2019 NXP */
+
+#ifndef __UAPI_GENL_TSN_H
+#define __UAPI_GENL_TSN_H
+
+#define TSN_GENL_NAME "TSN_GEN_CTRL"
+#define TSN_GENL_VERSION 0x1
+
+#define MAX_USER_SIZE 0
+#define MAX_ATTR_SIZE 3072
+#define MAX_TOTAL_MSG_SIZE (MAX_USER_SIZE + MAX_ATTR_SIZE)
+#define MAX_ENTRY_SIZE 2048
+#define MAX_ENTRY_NUMBER 128
+#define MAX_IFNAME_COUNT 64
+
+#define TSN_MULTICAST_GROUP_QBV "qbv"
+#define TSN_MULTICAST_GROUP_QCI "qci"
+
+/* multicast groups */
+enum tsn_multicast_groups {
+ TSN_MCGRP_QBV,
+ TSN_MCGRP_QCI,
+ TSN_MCGRP_MAX
+};
+
+enum tsn_capability {
+ TSN_CAP_QBV = 0x1,
+ TSN_CAP_QCI = 0x2,
+ TSN_CAP_QBU = 0x4,
+ TSN_CAP_CBS = 0x8, /* Credit-based Shapter Qav */
+ TSN_CAP_CB = 0x10, /* 8021CB redundancy and replication */
+ TSN_CAP_TBS = 0x20, /* Time Based schedule */
+ TSN_CAP_CTH = 0x40, /* cut through */
+};
+
+/*
+ * Commands sent from userspace
+ * Not versioned. New commands should only be inserted at the enum's end
+ * prior to __TSN_CMD_MAX
+ */
+
+enum {
+ TSN_CMD_UNSPEC = 0, /* Reserved */
+ TSN_CMD_QBV_SET,
+ TSN_CMD_QBV_GET,
+ TSN_CMD_QBV_GET_STATUS,
+ TSN_CMD_CB_STREAMID_SET,
+ TSN_CMD_CB_STREAMID_GET,
+ TSN_CMD_CB_STREAMID_GET_COUNTS,
+ TSN_CMD_QCI_CAP_GET, /* Qci capability get length capability get */
+ TSN_CMD_QCI_SFI_SET,
+ TSN_CMD_QCI_SFI_GET,
+ TSN_CMD_QCI_SFI_GET_COUNTS,
+ TSN_CMD_QCI_SGI_SET,
+ TSN_CMD_QCI_SGI_GET,
+ TSN_CMD_QCI_SGI_GET_STATUS,
+ TSN_CMD_QCI_FMI_SET,
+ TSN_CMD_QCI_FMI_GET,
+ TSN_CMD_CBS_SET,
+ TSN_CMD_CBS_GET,
+ TSN_CMD_QBU_SET,
+ TSN_CMD_QBU_GET_STATUS,
+ TSN_CMD_QAV_SET_CBS,
+ TSN_CMD_QAV_GET_CBS,
+ TSN_CMD_TSD_SET,
+ TSN_CMD_TSD_GET,
+ TSN_CMD_CT_SET,
+ TSN_CMD_CBGEN_SET,
+ TSN_CMD_CBREC_SET,
+ TSN_CMD_CBSTAT_GET,
+ TSN_CMD_PCPMAP_SET_UNUSE,
+ TSN_CMD_DSCP_SET,
+ TSN_CMD_ECHO, /* user->kernel request/get-response */
+ TSN_CMD_REPLY, /* kernel->user event */
+ TSN_CMD_CAP_GET,
+ __TSN_CMD_MAX,
+};
+#define TSN_CMD_MAX (__TSN_CMD_MAX - 1)
+
+
+enum {
+ TSN_CMD_ATTR_UNSPEC = 0,
+ TSN_CMD_ATTR_MESG, /* demo message */
+ TSN_CMD_ATTR_DATA, /* demo data */
+ TSN_ATTR_IFNAME,
+ TSN_ATTR_PORT_NUMBER,
+ TSN_ATTR_QBV,
+ TSN_ATTR_STREAM_IDENTIFY, /* stream identify */
+ TSN_ATTR_QCI_SP, /* psfp port capbility parameters */
+ TSN_ATTR_QCI_SFI, /* psfp stream filter instance */
+ TSN_ATTR_QCI_SGI, /* psfp stream gate instance */
+ TSN_ATTR_QCI_FMI, /* psfp flow meter instance */
+ TSN_ATTR_CBS, /* credit-based shaper */
+ TSN_ATTR_TSD, /* Time Specific Departure */
+ TSN_ATTR_QBU, /* preemption */
+ TSN_ATTR_CT, /* cut through */
+ TSN_ATTR_CBGEN, /* 802.1CB sequence generate */
+ TSN_ATTR_CBREC, /* 802.1CB sequence recover */
+ TSN_ATTR_CBSTAT, /* 802.1CB status */
+ TSN_ATTR_PCPMAP_UNUSE,
+ TSN_ATTR_DSCP,
+ TSN_ATTR_CAP, /* TSN capbility */
+ __TSN_CMD_ATTR_MAX,
+};
+#define TSN_CMD_ATTR_MAX (__TSN_CMD_ATTR_MAX - 1)
+
+enum {
+ TSN_CAP_ATTR_UNSPEC,
+ TSN_CAP_ATTR_QBV,
+ TSN_CAP_ATTR_QCI,
+ TSN_CAP_ATTR_QBU,
+ TSN_CAP_ATTR_CBS,
+ TSN_CAP_ATTR_CB,
+ TSN_CAP_ATTR_TBS,
+ TSN_CAP_ATTR_CTH,
+ __TSN_CAP_ATTR_MAX,
+ TSN_CAP_ATTR_MAX = __TSN_CAP_ATTR_MAX - 1,
+};
+
+enum {
+ TSN_QBU_ATTR_UNSPEC,
+ TSN_QBU_ATTR_ADMIN_STATE,
+ TSN_QBU_ATTR_HOLD_ADVANCE,
+ TSN_QBU_ATTR_RELEASE_ADVANCE,
+ TSN_QBU_ATTR_ACTIVE,
+ TSN_QBU_ATTR_HOLD_REQUEST,
+ __TSN_QBU_ATTR_MAX,
+ TSN_QBU_ATTR_MAX = __TSN_QBU_ATTR_MAX - 1,
+};
+
+enum {
+ TSN_CBS_ATTR_UNSPEC,
+ TSN_CBS_ATTR_TC_INDEX,
+ TSN_CBS_ATTR_BW,
+ __TSN_CBS_ATTR_MAX,
+ TSN_CBS_ATTR_MAX = __TSN_CBS_ATTR_MAX - 1,
+};
+
+enum {
+ TSN_TSD_ATTR_UNSPEC,
+ TSN_TSD_ATTR_DISABLE,
+ TSN_TSD_ATTR_ENABLE,
+ TSN_TSD_ATTR_PERIOD,
+ TSN_TSD_ATTR_MAX_FRM_NUM,
+ TSN_TSD_ATTR_CYCLE_NUM,
+ TSN_TSD_ATTR_LOSS_STEPS,
+ TSN_TSD_ATTR_SYN_IMME,
+ __TSN_TSD_ATTR_MAX,
+ TSN_TSD_ATTR_MAX = __TSN_TSD_ATTR_MAX - 1,
+};
+
+enum {
+ TSN_STREAMID_ATTR_UNSPEC,
+ TSN_STREAMID_ATTR_INDEX,
+ TSN_STREAMID_ATTR_ENABLE,
+ TSN_STREAMID_ATTR_DISABLE,
+ TSN_STREAMID_ATTR_STREAM_HANDLE,
+ TSN_STREAMID_ATTR_IFOP,
+ TSN_STREAMID_ATTR_OFOP,
+ TSN_STREAMID_ATTR_IFIP,
+ TSN_STREAMID_ATTR_OFIP,
+ TSN_STREAMID_ATTR_TYPE,
+ TSN_STREAMID_ATTR_NDMAC,
+ TSN_STREAMID_ATTR_NTAGGED,
+ TSN_STREAMID_ATTR_NVID,
+ TSN_STREAMID_ATTR_SMAC,
+ TSN_STREAMID_ATTR_STAGGED,
+ TSN_STREAMID_ATTR_SVID,
+ TSN_STREAMID_ATTR_COUNTERS_PSI,
+ TSN_STREAMID_ATTR_COUNTERS_PSO,
+ TSN_STREAMID_ATTR_COUNTERS_PSPPI,
+ TSN_STREAMID_ATTR_COUNTERS_PSPPO,
+ __TSN_STREAMID_ATTR_MAX,
+ TSN_STREAMID_ATTR_MAX = __TSN_STREAMID_ATTR_MAX - 1,
+};
+
+enum {
+ TSN_QCI_STREAM_ATTR_UNSPEC = 0,
+ TSN_QCI_STREAM_ATTR_MAX_SFI,
+ TSN_QCI_STREAM_ATTR_MAX_SGI,
+ TSN_QCI_STREAM_ATTR_MAX_FMI,
+ TSN_QCI_STREAM_ATTR_SLM,
+ __TSN_QCI_STREAM_ATTR_MAX,
+ TSN_QCI_STREAM_ATTR_MAX = __TSN_QCI_STREAM_ATTR_MAX - 1,
+};
+
+enum {
+ TSN_QCI_SFI_ATTR_UNSPEC = 0,
+ TSN_QCI_SFI_ATTR_INDEX,
+ TSN_QCI_SFI_ATTR_ENABLE,
+ TSN_QCI_SFI_ATTR_DISABLE,
+ TSN_QCI_SFI_ATTR_STREAM_HANDLE,
+ TSN_QCI_SFI_ATTR_PRIO_SPEC,
+ TSN_QCI_SFI_ATTR_GATE_ID,
+ TSN_QCI_SFI_ATTR_FILTER_TYPE,
+ TSN_QCI_SFI_ATTR_FLOW_ID,
+ TSN_QCI_SFI_ATTR_MAXSDU,
+ TSN_QCI_SFI_ATTR_COUNTERS,
+ TSN_QCI_SFI_ATTR_OVERSIZE_ENABLE,
+ TSN_QCI_SFI_ATTR_OVERSIZE,
+ __TSN_QCI_SFI_ATTR_MAX,
+ TSN_QCI_SFI_ATTR_MAX = __TSN_QCI_SFI_ATTR_MAX - 1,
+};
+
+enum {
+ TSN_QCI_SFI_ATTR_COUNTERS_UNSPEC = 0,
+ TSN_QCI_SFI_ATTR_MATCH,
+ TSN_QCI_SFI_ATTR_PASS,
+ TSN_QCI_SFI_ATTR_DROP,
+ TSN_QCI_SFI_ATTR_SDU_DROP,
+ TSN_QCI_SFI_ATTR_SDU_PASS,
+ TSN_QCI_SFI_ATTR_RED,
+ __TSN_QCI_SFI_ATTR_COUNT_MAX,
+ TSN_QCI_SFI_ATTR_COUNT_MAX = __TSN_QCI_SFI_ATTR_COUNT_MAX - 1,
+};
+
+enum {
+ TSN_QCI_SGI_ATTR_UNSPEC = 0,
+ TSN_QCI_SGI_ATTR_INDEX,
+ TSN_QCI_SGI_ATTR_ENABLE,
+ TSN_QCI_SGI_ATTR_DISABLE,
+ TSN_QCI_SGI_ATTR_CONFCHANGE,
+ TSN_QCI_SGI_ATTR_IRXEN, /* Invalid rx enable*/
+ TSN_QCI_SGI_ATTR_IRX,
+ TSN_QCI_SGI_ATTR_OEXEN, /* Octet exceed enable */
+ TSN_QCI_SGI_ATTR_OEX,
+ TSN_QCI_SGI_ATTR_ADMINENTRY,
+ TSN_QCI_SGI_ATTR_OPERENTRY,
+ TSN_QCI_SGI_ATTR_CCTIME, /* config change time */
+ TSN_QCI_SGI_ATTR_TICKG,
+ TSN_QCI_SGI_ATTR_CUTIME,
+ TSN_QCI_SGI_ATTR_CPENDING,
+ TSN_QCI_SGI_ATTR_CCERROR,
+ __TSN_QCI_SGI_ATTR_MAX,
+ TSN_QCI_SGI_ATTR_MAX = __TSN_QCI_SGI_ATTR_MAX - 1,
+};
+
+enum {
+ TSN_SGI_ATTR_CTRL_UNSPEC = 0,
+ TSN_SGI_ATTR_CTRL_INITSTATE,
+ TSN_SGI_ATTR_CTRL_LEN,
+ TSN_SGI_ATTR_CTRL_CYTIME,
+ TSN_SGI_ATTR_CTRL_CYTIMEEX,
+ TSN_SGI_ATTR_CTRL_BTIME,
+ TSN_SGI_ATTR_CTRL_INITIPV,
+ TSN_SGI_ATTR_CTRL_GCLENTRY,
+ __TSN_SGI_ATTR_CTRL_MAX,
+ TSN_SGI_ATTR_CTRL_MAX = __TSN_SGI_ATTR_CTRL_MAX - 1,
+};
+
+enum {
+ TSN_SGI_ATTR_GCL_UNSPEC = 0,
+ TSN_SGI_ATTR_GCL_GATESTATE,
+ TSN_SGI_ATTR_GCL_IPV,
+ TSN_SGI_ATTR_GCL_INTERVAL,
+ TSN_SGI_ATTR_GCL_OCTMAX,
+ __TSN_SGI_ATTR_GCL_MAX,
+ TSN_SGI_ATTR_GCL_MAX = __TSN_SGI_ATTR_GCL_MAX - 1,
+};
+
+enum {
+ TSN_QCI_FMI_ATTR_UNSPEC = 0,
+ TSN_QCI_FMI_ATTR_INDEX,
+ TSN_QCI_FMI_ATTR_ENABLE,
+ TSN_QCI_FMI_ATTR_DISABLE,
+ TSN_QCI_FMI_ATTR_CIR,
+ TSN_QCI_FMI_ATTR_CBS,
+ TSN_QCI_FMI_ATTR_EIR,
+ TSN_QCI_FMI_ATTR_EBS,
+ TSN_QCI_FMI_ATTR_CF,
+ TSN_QCI_FMI_ATTR_CM,
+ TSN_QCI_FMI_ATTR_DROPYL,
+ TSN_QCI_FMI_ATTR_MAREDEN,
+ TSN_QCI_FMI_ATTR_MARED,
+ TSN_QCI_FMI_ATTR_COUNTERS,
+ __TSN_QCI_FMI_ATTR_MAX,
+ TSN_QCI_FMI_ATTR_MAX = __TSN_QCI_FMI_ATTR_MAX - 1,
+};
+
+enum {
+ TSN_QBV_ATTR_UNSPEC,
+ TSN_QBV_ATTR_ENABLE,
+ TSN_QBV_ATTR_DISABLE,
+ TSN_QBV_ATTR_CONFIGCHANGE,
+ TSN_QBV_ATTR_CONFIGCHANGETIME,
+ TSN_QBV_ATTR_MAXSDU,
+ TSN_QBV_ATTR_GRANULARITY,
+ TSN_QBV_ATTR_CURRENTTIME,
+ TSN_QBV_ATTR_CONFIGPENDING,
+ TSN_QBV_ATTR_CONFIGCHANGEERROR,
+ TSN_QBV_ATTR_ADMINENTRY,
+ TSN_QBV_ATTR_OPERENTRY,
+ TSN_QBV_ATTR_LISTMAX,
+ __TSN_QBV_ATTR_MAX,
+ TSN_QBV_ATTR_MAX = __TSN_QBV_ATTR_MAX - 1,
+};
+
+enum {
+ TSN_QBV_ATTR_CTRL_UNSPEC,
+ TSN_QBV_ATTR_CTRL_LISTCOUNT,
+ TSN_QBV_ATTR_CTRL_GATESTATE,
+ TSN_QBV_ATTR_CTRL_CYCLETIME,
+ TSN_QBV_ATTR_CTRL_CYCLETIMEEXT,
+ TSN_QBV_ATTR_CTRL_BASETIME,
+ TSN_QBV_ATTR_CTRL_LISTENTRY,
+ __TSN_QBV_ATTR_CTRL_MAX,
+ TSN_QBV_ATTR_CTRL_MAX = __TSN_QBV_ATTR_CTRL_MAX - 1,
+};
+
+enum {
+ TSN_QBV_ATTR_ENTRY_UNSPEC,
+ TSN_QBV_ATTR_ENTRY_ID,
+ TSN_QBV_ATTR_ENTRY_GC,
+ TSN_QBV_ATTR_ENTRY_TM,
+ __TSN_QBV_ATTR_ENTRY_MAX,
+ TSN_QBV_ATTR_ENTRY_MAX = __TSN_QBV_ATTR_ENTRY_MAX - 1,
+};
+
+enum {
+ TSN_CT_ATTR_UNSPEC,
+ TSN_CT_ATTR_QUEUE_STATE,
+ __TSN_CT_ATTR_MAX,
+ TSN_CT_ATTR_MAX = __TSN_CT_ATTR_MAX - 1,
+};
+
+enum {
+ TSN_CBGEN_ATTR_UNSPEC,
+ TSN_CBGEN_ATTR_INDEX,
+ TSN_CBGEN_ATTR_PORT_MASK,
+ TSN_CBGEN_ATTR_SPLIT_MASK,
+ TSN_CBGEN_ATTR_SEQ_LEN,
+ TSN_CBGEN_ATTR_SEQ_NUM,
+ __TSN_CBGEN_ATTR_MAX,
+ TSN_CBGEN_ATTR_MAX = __TSN_CBGEN_ATTR_MAX - 1,
+};
+
+enum {
+ TSN_CBREC_ATTR_UNSPEC,
+ TSN_CBREC_ATTR_INDEX,
+ TSN_CBREC_ATTR_SEQ_LEN,
+ TSN_CBREC_ATTR_HIS_LEN,
+ TSN_CBREC_ATTR_TAG_POP_EN,
+ __TSN_CBREC_ATTR_MAX,
+ TSN_CBREC_ATTR_MAX = __TSN_CBREC_ATTR_MAX - 1,
+};
+
+enum {
+ TSN_CBSTAT_ATTR_UNSPEC,
+ TSN_CBSTAT_ATTR_INDEX,
+ TSN_CBSTAT_ATTR_GEN_REC,
+ TSN_CBSTAT_ATTR_ERR,
+ TSN_CBSTAT_ATTR_SEQ_NUM,
+ TSN_CBSTAT_ATTR_SEQ_LEN,
+ TSN_CBSTAT_ATTR_SPLIT_MASK,
+ TSN_CBSTAT_ATTR_PORT_MASK,
+ TSN_CBSTAT_ATTR_HIS_LEN,
+ TSN_CBSTAT_ATTR_SEQ_HIS,
+ __TSN_CBSTAT_ATTR_MAX,
+ TSN_CBSTAT_ATTR_MAX = __TSN_CBSTAT_ATTR_MAX - 1,
+};
+
+enum {
+ TSN_DSCP_ATTR_UNSPEC,
+ TSN_DSCP_ATTR_DISABLE,
+ TSN_DSCP_ATTR_INDEX,
+ TSN_DSCP_ATTR_COS,
+ TSN_DSCP_ATTR_DPL,
+ __TSN_DSCP_ATTR_MAX,
+ TSN_DSCP_ATTR_MAX = __TSN_DSCP_ATTR_MAX - 1,
+};
+
+#define ptptime_t __u64
+
+#define MAX_QUEUE_CNT 8
+
+struct tsn_preempt_status {
+ /* The value of admin_state shows a 8-bits vector value for showing
+ * the framePreemptionAdminStatus parameter and PreemptionPriority
+ * for the traffic class. Bit-7 is the highest priority traffic class
+ * and the bit-0 is the lowest priority traffic class.
+ * The bit is express (0) and is preemptible (1).
+ */
+ __u8 admin_state;
+ /* The value of the holdAdvance parameter for the port in nanoseconds.
+ * There is no default value; the holdAdvance is a property of the
+ * underlying MAC." This parameter corresponds to the holdAdvance
+ * parameter in 802.1Qbu.
+ */
+ __u32 hold_advance;
+
+ /* The value of the releaseAdvance parameter for the port in
+ * nanoseconds. There is no default value; the releaseAdvance is a
+ * property of the underlying MAC." This parameter corresponds to the
+ * releaseAdvance parameter in 802.1Qbu.
+ */
+ __u32 release_advance;
+
+ /* The value is active (TRUE) when preemption is operationally active
+ * for the port, and idle (FALSE) otherwise. This parameter corresponds
+ * to the preemptionActive parameter in 802.1Qbu.
+ */
+ __u8 preemption_active;
+
+ /* The value is hold (1) when the sequence of gate operations for
+ * the port has executed a Set-And-Hold-MAC operation, and release
+ * (2) when the sequence of gate operations has executed a
+ * Set-And-Release-MAC operation. The value of this object is release
+ * (FALSE) on system initialization. This parameter corresponds to the
+ * holdRequest parameter in 802.1Qbu.
+ */
+ __u8 hold_request;
+};
+
+enum tsn_tx_mode {
+ TX_MODE_STRICT,
+ TX_MODE_CBS,
+ TX_MODE_ETS,
+ TX_MODE_VENDOR_DEFINE = 255,
+};
+
+#define QUEUE_TX_MASK ((1 << TX_MODE_STRICT) | (1 << TX_MODE_CBS) \
+ | (1 << TX_MODE_ETS) | (1 << TX_MODE_VENDOR_DEFINE))
+
+struct cbs_status {
+ __u8 delta_bw; /* percentage, 0~100 */
+ __u32 idleslope;
+ __s32 sendslope;
+ __u32 maxframesize;
+ __u32 hicredit;
+ __s32 locredit;
+ __u32 maxninference;
+};
+
+struct tx_queue {
+ /* tx_queue_capbility shows the queue's capability mask.
+ * refer the enum tsn_tx_mode
+ */
+ __u8 capability;
+
+ /* tx_queue_mode is current queue working mode */
+ __u8 mode;
+
+ /* prio is showing the queue priority */
+ __u8 prio;
+
+ /* mstat shows the status data of cbs or priority */
+ union {
+ struct cbs_status cbs;
+ };
+};
+
+struct port_status {
+ /* txqueue_cnt shows how many queues in this port */
+ __u8 queue_cnt;
+
+ /* max_rate(Mbit/s) is the port transmit rate current port is setting */
+ __u32 max_rate;
+
+ /* tsn_capability mask the tsn capability */
+ __u32 tsn_capability;
+};
+
+enum tsn_cb_streamid_type {
+ STREAMID_RESERVED = 0,
+ /* Null Stream identification */
+ STREAMID_NULL,
+ /* Source MAC and VLAN Stream identification */
+ STREAMID_SMAC_VLAN,
+ /* Active Destination MAC and VLAN stream identification */
+ STREAMID_DMAC_VLAN,
+ /* IP stream identification */
+ STREAMID_IP,
+};
+
+/* When instantiating an instance of the Null Stream identification function
+ * 8021CB(6.4) for a particular input Stream, the managed objects in the
+ * following subsections serve as the tsnStreamIdParameters managed object
+ * 8021CB claus(9.1.1.7).
+ */
+struct tsn_cb_null_streamid {
+ /* tsnCpeNullDownDestMac. Specifies the destination_address that
+ * identifies a packet in an Enhanced Internal Sublayer Service (EISS)
+ * indication primitive, to the Null Stream identification function.
+ */
+ __u64 dmac;
+
+ /* tsnCpeNullDownTagged. It can take the following values:
+ * 1 tagged: A frame must have a VLAN tag to be recognized as belonging
+ * to the Stream.
+ * 2 priority: A frame must be untagged, or have a VLAN tag with a VLAN
+ * ID = 0 to be recognized as belonging to the Stream.
+ * 3 all: A frame is recognized as belonging to the Stream whether
+ * tagged or not.
+ */
+ __u8 tagged;
+
+ /* tsnCpeNullDownVlan. Specifies the vlan_identifier parameter that
+ * identifies a packet in an EISS indication primitive to the Null
+ * Stream identification function. A value of 0 indicates that the vlan
+ * _identifier parameter is ignored on EISS indication primitives.
+ */
+ __u16 vid;
+};
+
+struct tsn_cb_source_streamid {
+ __u64 smac;
+ __u8 tagged;
+ __u16 vid;
+};
+
+struct tsn_cb_dest_streamid {
+ __u64 down_dmac;
+ __u8 down_tagged;
+ __u16 down_vid;
+ __u8 down_prio;
+ __u64 up_dmac;
+ __u8 up_tagged;
+ __u16 up_vid;
+ __u8 up_prio;
+};
+
+struct tsn_cb_ip_streamid {
+ __u64 dmac;
+ __u8 tagged;
+ __u16 vid;
+ __u64 siph;
+ __u64 sipl;
+ __u64 diph;
+ __u64 dipl;
+ __u8 dscp;
+ __u8 npt;
+ __u16 sport;
+ __u16 dport;
+};
+
+/* 802.1CB stream identify table clause 9.1 */
+struct tsn_cb_streamid {
+ /* The objects in a given entry of the Stream identity table are used
+ * to control packets whose stream_handle subparameter is equal to the
+ * entry tsnStreamIdHandle object.
+ */
+ __s32 handle;
+
+ /* The list of ports on which an in-facing Stream identification
+ * function in the output (towards the system forwarding function)
+ * direction Only Active Destination MAC and VLAN Stream identification
+ * (or nothing) can be configured.
+ */
+ __u32 ifac_oport;
+
+ /* The list of ports on which an out-facing Stream identification
+ * function in the output (towards the physical interface) direction.
+ * Only Active Destination MAC and VLAN Stream identification
+ * (or nothing) can be configured.
+ */
+ __u32 ofac_oport;
+
+ /* The list of ports on which an in-facing Stream identification
+ * function in the input (coming from the system forwarding function)
+ * direction
+ */
+ __u32 ifac_iport;
+
+ /* The list of ports on which an out-facing Stream identification
+ * function in the input (coming from the physical interface) direction
+ * .
+ */
+ __u32 ofac_iport;
+
+ /* An enumerated value indicating the method used to identify packets
+ * belonging to the Stream.
+ * The Organizationally Unique Identifier (OUI) or Company Identifier
+ * (CID) to identify the organization defining the enumerated type
+ * should be: 00-80-C2
+ * 1: null stream identification
+ * 2: source mac and vlan stream identification
+ * 3: activ destination mac and vlan stream identification
+ * 4: ip stream identifaciton
+ */
+ __u8 type;
+
+ /* tsnStreamIdParameters The number of controlling parameters for a
+ * Stream identification method, their types and values, are specific
+ * to the tsnStreamIdIdentificationType
+ */
+ union {
+ struct tsn_cb_null_streamid nid;
+ struct tsn_cb_source_streamid sid;
+ struct tsn_cb_dest_streamid did;
+ struct tsn_cb_ip_streamid iid;
+ } para;
+};
+
+/* Following counters are instantiated for each port on which the Stream
+ * identification function (6.2) is configured. The counters are indexed by
+ * port number, facing (in-facing or out-facing), and stream_handle value
+ * (tsnStreamIdHandle, 9.1.1.1).
+ */
+struct tsn_cb_streamid_counters {
+ struct {
+ __u64 input;
+ __u64 output;
+ } per_stream;
+
+ struct {
+ __u64 input;
+ __u64 output;
+ } per_streamport[32];
+};
+
+/* 802.1Qci Stream Parameter Table, read from port */
+struct tsn_qci_psfp_stream_param {
+ /* MaxStreamFilterInstances.
+ * The maximum number of Stream Filter instances supported by this
+ * Bridge component.
+ */
+ __s32 max_sf_instance;
+
+ /* MaxStreamGateInstances
+ * The maximum number of Stream Gate instances supported by this Bridge
+ * component.
+ */
+ __s32 max_sg_instance;
+
+ /* MaxFlowMeterInstances
+ * The maximum number of Flow Meter instances supported by this Bridge
+ * component.
+ */
+ __s32 max_fm_instance;
+
+ /* SupportedListMax
+ * The maximum value supported by this Bridge component of the
+ * AdminControlListLength and OperControlListLength parameters.
+ */
+ __s32 supported_list_max;
+};
+
+/* 802.1Qci Stream Filter Instance Table, counters part only. */
+struct tsn_qci_psfp_sfi_counters {
+ /* The MatchingFramesCount counter counts received frames that match
+ * this stream filter.
+ */
+ __u64 matching_frames_count;
+
+ /* The PassingFramesCount counter counts received frames that pass the
+ * gate associated with this stream filter.
+ */
+ __u64 passing_frames_count;
+
+ /* The NotPassingFramesCount counter counts received frames that do not
+ * pass the gate associated with this stream filter.
+ */
+ __u64 not_passing_frames_count;
+
+ /* The PassingSDUCount counter counts received frames that pass the SDU
+ * size filter specification associated with this stream filter.
+ */
+ __u64 passing_sdu_count;
+
+ /* The NotPassingSDUCount counter counts received frames that do not
+ * pass the SDU size filter specification associated with this stream
+ * filter.
+ */
+ __u64 not_passing_sdu_count;
+
+ /* The REDFramesCount counter counts received random early detection
+ * (RED) frames associated with this stream filter.
+ */
+ __u64 red_frames_count;
+};
+
+/* 802.1Qci Stream Filter Instance Table, configuration part only. */
+struct tsn_qci_psfp_sfi_conf {
+
+ /* The StreamHandleSpec parameter contains a stream identifier
+ * specification value. A value of -1 denotes the wild card value; zero
+ * or positive values denote stream identifier values.
+ */
+ __s32 stream_handle_spec;
+
+ /* The PrioritySpec parameter contains a priority specification value.
+ * A value of -1 denotes the wild card value; zero or positive values
+ * denote priority values.
+ */
+ __s8 priority_spec;
+
+ /* The StreamGateInstanceID parameter contains the index of an entry in
+ * the Stream Gate Table.
+ */
+ __u32 stream_gate_instance_id;
+
+ /* The filter specifications. The actions specified in a filter
+ * specification can result in a frame passing or failing the specified
+ * filter. Frames that fail a filter are discarded.
+ */
+ struct {
+ /* The MaximumSDUSize parameter specifies the maximum allowed
+ * frame size for the stream. Any frame exceeding this value
+ * will be dropped. A value of 0 denote that the MaximumSDUSize
+ * filter is disabled for this stream.
+ */
+ __u16 maximum_sdu_size;
+
+ /* The FlowMeterInstanceID parameter contains the index of an
+ * entry in the Flow Meter Table. A value of -1 denotes that
+ * no flow meter is assigned; zero or positive values denote
+ * flow meter IDs.
+ */
+ __s32 flow_meter_instance_id;
+ } stream_filter;
+
+ /* The StreamBlockedDueToOversizeFrameEnable object contains a Boolean
+ * value that indicates whether the StreamBlockedDueToOversizeFrame
+ * function is enabled (TRUE) or disabled (FALSE).
+ */
+ __u8 block_oversize_enable;
+
+ /* The StreamBlockedDueToOversizeFrame object contains a Boolean value
+ * that indicates whether, if the StreamBlockedDueToOversizeFrame
+ * function is enabled, all frames are to be discarded (TRUE) or not
+ * (FALSE).
+ */
+ __u8 block_oversize;
+};
+
+/* 802.1Qci Stream Gate Control List Entry. */
+struct tsn_qci_psfp_gcl {
+ /* The GateState parameter specifies a desired state, open (true) or
+ * closed (false), for the stream gate.
+ */
+ __u8 gate_state;
+
+ /* An IPV is encoded as a signed integer. A negative denotes the null
+ * value; zero or positive values denote internal priority values.
+ */
+ __s8 ipv;
+
+ /* A TimeInterval is encoded in 4 octets as a 32-bit unsigned integer,
+ * representing a number of nanoseconds.
+ */
+ __u32 time_interval;
+
+ /* The maximum number of octets that are permitted to pass the gate
+ * during the specified TimeInterval. If zero, there is no maximum.
+ */
+ __u32 octet_max;
+
+};
+
+/* 802.1Qci Stream Gate Admin/Operation common list control parameters */
+struct tsn_qci_sg_control {
+ /* The administrative/operation value of the GateStates parameter
+ * for the stream gate. A value of false indicates closed;
+ * a value of true indicates open.
+ */
+ __u8 gate_states;
+
+ /* The administrative/operation value of the ListMax parameter for the
+ * gate. The integer value indicates the number of entries (TLVs) in
+ * the AdminControlList/OperControlList.
+ */
+ __u8 control_list_length;
+
+ /* The administrative/operation value of the CycleTime parameter for
+ * the gate. The value is an unsigned integer number of nanoseconds.
+ */
+ __u32 cycle_time;
+
+ /* The administrative/operation value of the CycleTimeExtension
+ * parameter for the gate. The value is an unsigned integer number
+ * of nanoseconds.
+ */
+ __u32 cycle_time_extension;
+
+ /* The administrative/operation value of the BaseTime parameter for the
+ * gate. The value is a representation of a PTPtime value, consisting
+ * of a 48-bit integer number of seconds and a 32-bit integer number of
+ * nanoseconds.
+ */
+ ptptime_t base_time;
+
+ /* The administrative/operation value of the IPV parameter for the gate.
+ * A value of -1 denotes the null value; zero or positive values denote
+ * internal priority values.
+ */
+ __s8 init_ipv;
+
+ /* control_list contend the gate control list of
+ * administrative/operation
+ */
+ struct tsn_qci_psfp_gcl *gcl;
+};
+
+/* 802.1Qci Stream Gate Instance Table, configuration part only. */
+struct tsn_qci_psfp_sgi_conf {
+ /* The GateEnabled parameter determines whether the stream gate is
+ * active (true) or inactive (false).
+ */
+ __u8 gate_enabled;
+
+ /* The ConfigChange parameter signals the start of a configuration
+ * change when it is set to TRUE. This should only be done when the
+ * various administrative parameters are all set to appropriate values.
+ */
+ __u8 config_change;
+
+ /* admin control parameters with admin control list */
+ struct tsn_qci_sg_control admin;
+
+ /* The GateClosedDueToInvalidRxEnable object contains a Boolean value
+ * that indicates whether the GateClosedDueToInvalidRx function is
+ * enabled (TRUE) or disabled (FALSE).
+ */
+ __u8 block_invalid_rx_enable;
+
+ /* The GateClosedDueToInvalidRx object contains a Boolean value that
+ * indicates whether, if the GateClosedDueToInvalidRx function is
+ * enabled, all frames are to be discarded (TRUE) or not (FALSE).
+ */
+ __u8 block_invalid_rx;
+
+ /* The GateClosedDueToOctetsExceededEnable object contains a Boolean
+ * value that indicates whether the GateClosedDueToOctetsExceeded
+ * function is enabled (TRUE) or disabled (FALSE).
+ */
+ __u8 block_octets_exceeded_enable;
+
+ /* The GateClosedDueToOctetsExceeded object contains a Boolean value
+ * that indicates whether, if the GateClosedDueToOctetsExceeded
+ * function is enabled, all frames are to be discarded (TRUE) or not
+ * (FALSE).
+ */
+ __u8 block_octets_exceeded;
+};
+
+/* 802.1Qci Stream Gate Instance Table, status part only. */
+struct tsn_psfp_sgi_status {
+
+ /* admin control parameters with admin control list */
+ struct tsn_qci_sg_control oper;
+
+ /* The PTPtime at which the next config change is scheduled to occur.
+ * The value is a representation of a PTPtime value, consisting of a
+ * 48-bit integer number of seconds and a 32-bit integer number of
+ * nanoseconds.
+ */
+ ptptime_t config_change_time;
+
+ /* The granularity of the cycle time clock, represented as an unsigned
+ * number of tenths of nanoseconds.
+ */
+ __u32 tick_granularity;
+
+ /* The current time, in PTPtime, as maintained by the local system.
+ * The value is a representation of a PTPtime value, consisting of a
+ * 48-bit integer number of seconds and a 32-bit integer number of
+ * nanoseconds.
+ */
+ ptptime_t current_time;
+
+ /* The value of the ConfigPending state machine variable. The value is
+ * TRUE if a configuration change is in progress but has not yet
+ * completed.
+ */
+ __u8 config_pending;
+
+ /* A counter of the number of times that a re-configuration of the
+ * traffic schedule has been requested with the old schedule still
+ * running and the requested base time was in the past.
+ */
+ __u64 config_change_error;
+
+};
+
+/* 802.1Qci Flow Meter Instance Table. */
+struct tsn_qci_psfp_fmi {
+ /* The FlowMeterCIR parameter contains an integer value that represents
+ * the CIR value for the flow meter, in kbit/s.
+ */
+ __u32 cir;
+
+ /* The FlowMeterCBS parameter contains an integer value that represents
+ * the CBS value for the flow meter, in octets.
+ */
+ __u32 cbs;
+
+ /* The FlowMeterEIR parameter contains an integer value that represents
+ * the EIR value for the flow meter, in kbit/s.
+ */
+ __u32 eir;
+
+ /* The FlowMeterEBS parameter contains an integer value that represents
+ * the EBS value for the flow meter, in octets.
+ */
+ __u32 ebs;
+
+ /* The FlowMeterCF parameter contains a Boolean value that represents
+ * the CF value for the flow meter, as a Boolean value indicating no
+ * coupling (FALSE) or coupling (TRUE).
+ */
+ __u8 cf;
+
+ /* The FlowMeterCM parameter contains a Boolean value that represents
+ * the CM value for the flow meter, as a Boolean value indicating
+ * colorBlind (FALSE) or colorAware (TRUE).
+ */
+ __u8 cm;
+
+ /* The FlowMeterDropOnYellow parameter contains a Boolean value that
+ * indicates whether yellow frames are dropped (TRUE) or have
+ * drop_eligible set to TRUE (FALSE).
+ */
+ __u8 drop_on_yellow;
+
+ /* The FlowMeterMarkAllFramesRedEnable parameter contains a Boolean
+ * value that indicates whether the MarkAllFramesRed function
+ * is enabled (TRUE) or disabled (FALSE).
+ */
+ __u8 mark_red_enable;
+
+ /* The FlowMeterMarkAllFramesRed parameter contains a Boolean value
+ * that indicates whether, if the MarkAllFramesRed function is enabled,
+ * all frames are to be discarded (TRUE) or not (FALSE).
+ */
+ __u8 mark_red;
+};
+
+struct tsn_qci_psfp_fmi_counters {
+ __u64 bytecount;
+ __u64 drop;
+ __u64 dr0_green;
+ __u64 dr1_green;
+ __u64 dr2_yellow;
+ __u64 remark_yellow;
+ __u64 dr3_red;
+ __u64 remark_red;
+};
+
+/* 802.1cb */
+struct tsn_seq_gen_conf {
+
+ /* The InputPortMask parameter contains a port mask.
+ * If the packet is from input port belonging to this
+ * port mask then it's on known stream and sequence
+ * generation parameters can be applied.
+ */
+ __u8 iport_mask;
+
+ /* The SplitMask parameter contains a output port mask
+ * used to add redundant paths.
+ */
+ __u8 split_mask;
+
+ /* The SequenceSpaceLenLog parameter is a value to specifies
+ * number of bits to be used for sequence number.
+ */
+ __u8 seq_len;
+
+ /* The SequenceNumber parameter is a value to used for
+ * outgoing packet's sequence number generation.
+ */
+ __u32 seq_num;
+};
+
+struct tsn_seq_rec_conf {
+
+ /* The SequenceSpaceLenLog parameter is a value to specifies
+ * number of bits to be used for sequence number.
+ */
+ __u8 seq_len;
+
+ /* The HistorySpaceLenLog parameter is a value to specifies
+ * number of bits to be used for history register.
+ */
+ __u8 his_len;
+
+ /* The RTagPopEnable parameter contains a __u8 to enable removal
+ * of redundancy tag from the packet.
+ */
+ __u8 rtag_pop_en;
+};
+
+struct tsn_cb_status {
+
+ /* The GenRecover parameter contains a value specifies type
+ * of stream sequence parameters:
+ * 0: Stream sequence parameters are for generation.
+ * 1: Stream sequence parameters are for recovery.
+ */
+ __u8 gen_rec;
+
+ /* The ErrStatus parameter indicates stream's error status
+ * 1: This switch is expected to sequence the stream,
+ * but the incoming packet has sequence number.
+ * 2: This switch is expected to recover the stream,
+ * but the incoming packet is NONSEQ.
+ */
+ __u8 err;
+
+ /* The SequenceNumber parameter is a value to used for
+ * outgoing packet's sequence number generation.
+ */
+ __u32 seq_num;
+
+ /* The SequenceSpaceLenLog parameter is a value to specifies
+ * number of bits to be used for sequence number.
+ */
+ __u8 seq_len;
+
+ /* The SplitMask parameter contains a output port mask
+ * used to add redundant paths.
+ */
+ __u8 split_mask;
+
+ /* The InputPortMask parameter contains a port mask.
+ * If the packet is from input port belonging to this
+ * port mask then it's on known stream and sequence
+ * generation parameters can be applied.
+ */
+ __u8 iport_mask;
+
+ /* The HistorySpaceLenLog parameter is a value to specifies
+ * number of bits to be used for history register.
+ */
+ __u8 his_len;
+
+ /* The SequenceHistory parameter Maintains history of sequence
+ * numbers of received packets.
+ */
+ __u32 seq_his;
+};
+
+/* An entry for gate control list */
+struct tsn_qbv_entry {
+ /* Octet represent the gate states for the corresponding traffic
+ * classes.
+ * The MS bit corresponds to traffic class 7.
+ * The LS bit to traffic class 0.
+ * A bit value of 0 indicates closed;
+ * A bit value of 1 indicates open.
+ */
+ __u8 gate_state;
+
+ /* A TimeInterval is encoded in 4 octets as a 32-bit unsigned integer,
+ * representing a number of nanoseconds.
+ */
+ __u32 time_interval;
+};
+
+/* The administrative/operation time and gate list */
+struct tsn_qbv_basic {
+ /* The administrative/operation value of the GateStates parameter for
+ * the Port.
+ * The bits of the octet represent the gate states for the
+ * corresponding traffic classes; the MS bit corresponds to traffic
+ * class 7, the LS bit to traffic class 0. A bit value of 0 indicates
+ * closed; a bit value of 1 indicates open.
+ * The value of this object MUST be retained
+ * across reinitializations of the management system.
+ */
+ __u8 gate_states;
+
+ /* The administrative/operation value of the ListMax parameter for the
+ * port. The integer value indicates the number of entries (TLVs) in
+ * the AdminControlList. The value of this object MUST be retained
+ * across reinitializations of the management system.
+ */
+ __u32 control_list_length;
+
+ /* The administrative/operation value of the AdminCycleTime
+ * parameter for the Port. The numerator and denominator together
+ * represent the cycle time as a rational number of seconds. The value
+ * of this object MUST be retained across reinitializations of the
+ * management system.
+ */
+ __u32 cycle_time;
+
+ /* The administrative/operation value of the CycleTimeExtension
+ * parameter for the Port. The value is an unsigned integer number of
+ * nanoseconds.
+ * The value of this object MUST be retained across reinitializations
+ * of the management system.
+ */
+
+ __u32 cycle_time_extension;
+
+ /* The administrative/operation value of the BaseTime parameter for the
+ * Port. The value is a representation of a PTPtime value, consisting
+ * of a 48-bit integer number of seconds and a 32-bit integer number of
+ * nanoseconds.
+ * The value of this object MUST be retained across reinitializations of
+ * the management system.
+ */
+ ptptime_t base_time;
+
+ /* admin_control_list represent the AdminControlList/OperControlList.
+ * The administrative version of the gate control list for the Port.
+ */
+ struct tsn_qbv_entry *control_list;
+};
+
+struct tsn_qbv_conf {
+ /* The GateEnabled parameter determines whether traffic scheduling is
+ * active (true) or inactive (false). The value of this object MUST be
+ * retained across reinitializations of the management system.
+ */
+ __u8 gate_enabled;
+
+ /* The maxsdu parameter denoting the maximum SDU size supported by the
+ * queue.
+ */
+ __u32 maxsdu;
+
+ /* The ConfigChange parameter signals the start of a configuration
+ * change when it is set to TRUE. This should only be done when the
+ * various administrative parameters are all set to appropriate values.
+ */
+ __u8 config_change;
+
+ /* The admin parameter signals the admin relate cycletime, basictime,
+ * gatelist paraters.
+ */
+ struct tsn_qbv_basic admin;
+};
+
+/* 802.1Qbv (Time Aware Shaper) port status */
+struct tsn_qbv_status {
+ /* The PTPtime at which the next config change is scheduled to occur.
+ * The value is a representation of a PTPtime value, consisting of a
+ * 48-bit integer number of seconds and a 32-bit integer number of
+ * nanoseconds. The value of this object MUST be retained across
+ * reinitializations of the management system.
+ */
+ ptptime_t config_change_time;
+
+ /* The granularity of the cycle time clock, represented as an unsigned
+ * number of tenths of nanoseconds. The value of this object MUST be
+ * retained across reinitializations of the management system.
+ */
+ __u32 tick_granularity;
+
+ /* The current time, in PTPtime, as maintained by the local system.
+ * The value is a representation of a PTPtime value, consisting of a
+ * 48-bit integer number of seconds and a 32-bit integer number of
+ * nanoseconds.
+ */
+ ptptime_t current_time;
+
+ /* The value of the ConfigPending state machine variable. The value is
+ * TRUE if a configuration change is in progress but has not yet
+ * completed.
+ */
+ __u8 config_pending;
+
+ /* A counter of the number of times that a re-configuration of the
+ * traffic schedule has been requested with the old schedule still
+ * running and the requested base time was in the past.
+ */
+ __u64 config_change_error;
+
+ /* The maximum value supported by this Port of the
+ * AdminControlListLength and OperControlListLength parameters.
+ */
+ __u32 supported_list_max;
+
+ /* Operation settings parameters and Oper gate list */
+ struct tsn_qbv_basic oper;
+};
+
+/* Time Specific Departure parameters */
+struct tsn_tsd {
+ __u8 enable;
+
+ /* The cycle time, in units of microsecond(us)*/
+ __u32 period;
+
+ /* The maximum number of frames which could be transmitted on one cycle
+ * The exceeding frames will be transmitted on next cycle.
+ */
+ __u32 maxFrameNum;
+
+ /* Specify the time of the first cycle begins.
+ * 1: begin when the queue get the first frame to transmit.
+ * 2: begin immediately at the end of setting function.
+ */
+ __u32 syn_flag;
+};
+
+struct tsn_tsd_status {
+ __u8 enable;
+ __u32 period;
+ __u32 maxFrameNum;
+ __u32 flag;
+ __u32 cycleNum;
+ __u32 loss_steps;
+};
+
+struct tsn_qos_switch_dscp_conf {
+ __u8 trust;
+ __u8 cos;
+ __u8 dpl;
+ __u8 remark;
+ __u8 dscp; /* New ingress translated DSCP value */
+};
+
+#endif /* _UAPI_GENL_TSN_H */
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -240,6 +240,7 @@ source "net/ieee802154/Kconfig"
source "net/mac802154/Kconfig"
source "net/sched/Kconfig"
source "net/dcb/Kconfig"
+source "net/tsn/Kconfig"
source "net/dns_resolver/Kconfig"
source "net/batman-adv/Kconfig"
source "net/openvswitch/Kconfig"
--- a/net/Makefile
+++ b/net/Makefile
@@ -59,6 +59,9 @@ obj-$(CONFIG_CAIF) += caif/
ifneq ($(CONFIG_DCB),)
obj-y += dcb/
endif
+ifneq ($(CONFIG_TSN),)
+obj-y += tsn/
+endif
obj-$(CONFIG_6LOWPAN) += 6lowpan/
obj-$(CONFIG_IEEE802154) += ieee802154/
obj-$(CONFIG_MAC802154) += mac802154/
--- /dev/null
+++ b/net/tsn/Kconfig
@@ -0,0 +1,15 @@
+config TSN
+ bool "802.1 Time-Sensitive Networking support"
+ default n
+ depends on VLAN_8021Q && PTP_1588_CLOCK
+ help
+ This enables support for TSN(time sensitive networking)
+ TSN features include:
+ 802.1Qav:
+ 802.1Qbv:
+ 802.1Qci:
+ 802.1Qbu:
+ 802.1AS:
+ 802.1CB:
+
+ If unsure, say N.
--- /dev/null
+++ b/net/tsn/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_TSN) += genl_tsn.o
--- /dev/null
+++ b/net/tsn/genl_tsn.c
@@ -0,0 +1,3696 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
+/* Copyright 2017-2019 NXP */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/netdevice.h>
+#include <linux/if_vlan.h>
+#include <net/genetlink.h>
+#include <net/netlink.h>
+#include <linux/version.h>
+#include <net/tsn.h>
+
+#define NLA_PARSE_NESTED(a, b, c, d) \
+ nla_parse_nested_deprecated(a, b, c, d, NULL)
+#define NLA_PUT_U64(a, b, c) nla_put_u64_64bit(a, b, c, NLA_U64)
+
+static struct genl_family tsn_family;
+
+LIST_HEAD(port_list);
+
+static const struct nla_policy tsn_cmd_policy[TSN_CMD_ATTR_MAX + 1] = {
+ [TSN_CMD_ATTR_MESG] = { .type = NLA_STRING },
+ [TSN_CMD_ATTR_DATA] = { .type = NLA_S32 },
+ [TSN_ATTR_IFNAME] = { .type = NLA_STRING },
+ [TSN_ATTR_PORT_NUMBER] = { .type = NLA_U8 },
+ [TSN_ATTR_CAP] = { .type = NLA_NESTED },
+ [TSN_ATTR_QBV] = { .type = NLA_NESTED },
+ [TSN_ATTR_STREAM_IDENTIFY] = { .type = NLA_NESTED },
+ [TSN_ATTR_QCI_SP] = { .type = NLA_NESTED },
+ [TSN_ATTR_QCI_SFI] = { .type = NLA_NESTED },
+ [TSN_ATTR_QCI_SGI] = { .type = NLA_NESTED },
+ [TSN_ATTR_QCI_FMI] = { .type = NLA_NESTED },
+ [TSN_ATTR_CBS] = { .type = NLA_NESTED },
+ [TSN_ATTR_TSD] = { .type = NLA_NESTED },
+ [TSN_ATTR_QBU] = { .type = NLA_NESTED },
+ [TSN_ATTR_CT] = { .type = NLA_NESTED },
+ [TSN_ATTR_CBGEN] = { .type = NLA_NESTED },
+ [TSN_ATTR_CBREC] = { .type = NLA_NESTED },
+ [TSN_ATTR_CBSTAT] = { .type = NLA_NESTED },
+ [TSN_ATTR_DSCP] = { .type = NLA_NESTED },
+};
+
+static const struct nla_policy tsn_cap_policy[TSN_CAP_ATTR_MAX + 1] = {
+ [TSN_CAP_ATTR_QBV] = { .type = NLA_FLAG },
+ [TSN_CAP_ATTR_QCI] = { .type = NLA_FLAG },
+ [TSN_CAP_ATTR_QBU] = { .type = NLA_FLAG },
+ [TSN_CAP_ATTR_CBS] = { .type = NLA_FLAG },
+ [TSN_CAP_ATTR_CB] = { .type = NLA_FLAG },
+ [TSN_CAP_ATTR_TBS] = { .type = NLA_FLAG },
+ [TSN_CAP_ATTR_CTH] = { .type = NLA_FLAG },
+};
+
+static const struct nla_policy qci_cap_policy[TSN_QCI_STREAM_ATTR_MAX + 1] = {
+ [TSN_QCI_STREAM_ATTR_MAX_SFI] = { .type = NLA_U32 },
+ [TSN_QCI_STREAM_ATTR_MAX_SGI] = { .type = NLA_U32 },
+ [TSN_QCI_STREAM_ATTR_MAX_FMI] = { .type = NLA_U32 },
+ [TSN_QCI_STREAM_ATTR_SLM] = { .type = NLA_U32 },
+};
+
+static const struct nla_policy ct_policy[TSN_CT_ATTR_MAX + 1] = {
+ [TSN_CT_ATTR_QUEUE_STATE] = { .type = NLA_U8 }
+};
+
+static const struct nla_policy cbgen_policy[TSN_CBGEN_ATTR_MAX + 1] = {
+ [TSN_CBGEN_ATTR_INDEX] = { .type = NLA_U32 },
+ [TSN_CBGEN_ATTR_PORT_MASK] = { .type = NLA_U8 },
+ [TSN_CBGEN_ATTR_SPLIT_MASK] = { .type = NLA_U8 },
+ [TSN_CBGEN_ATTR_SEQ_LEN] = { .type = NLA_U8 },
+ [TSN_CBGEN_ATTR_SEQ_NUM] = { .type = NLA_U32 },
+};
+
+static const struct nla_policy cbrec_policy[TSN_CBREC_ATTR_MAX + 1] = {
+ [TSN_CBREC_ATTR_INDEX] = { .type = NLA_U32 },
+ [TSN_CBREC_ATTR_SEQ_LEN] = { .type = NLA_U8 },
+ [TSN_CBREC_ATTR_HIS_LEN] = { .type = NLA_U8 },
+ [TSN_CBREC_ATTR_TAG_POP_EN] = { .type = NLA_FLAG },
+};
+
+static const struct nla_policy cbstat_policy[TSN_CBSTAT_ATTR_MAX + 1] = {
+ [TSN_CBSTAT_ATTR_INDEX] = { .type = NLA_U32 },
+ [TSN_CBSTAT_ATTR_GEN_REC] = { .type = NLA_U8 },
+ [TSN_CBSTAT_ATTR_ERR] = { .type = NLA_U8 },
+ [TSN_CBSTAT_ATTR_SEQ_NUM] = { .type = NLA_U32 },
+ [TSN_CBSTAT_ATTR_SEQ_LEN] = { .type = NLA_U8 },
+ [TSN_CBSTAT_ATTR_SPLIT_MASK] = { .type = NLA_U8 },
+ [TSN_CBSTAT_ATTR_PORT_MASK] = { .type = NLA_U8 },
+ [TSN_CBSTAT_ATTR_HIS_LEN] = { .type = NLA_U8 },
+ [TSN_CBSTAT_ATTR_SEQ_HIS] = { .type = NLA_U32 },
+};
+
+static const struct nla_policy qbu_policy[TSN_QBU_ATTR_MAX + 1] = {
+ [TSN_QBU_ATTR_ADMIN_STATE] = { .type = NLA_U8 },
+ [TSN_QBU_ATTR_HOLD_ADVANCE] = { .type = NLA_U32},
+ [TSN_QBU_ATTR_RELEASE_ADVANCE] = { .type = NLA_U32},
+ [TSN_QBU_ATTR_ACTIVE] = { .type = NLA_FLAG},
+ [TSN_QBU_ATTR_HOLD_REQUEST] = { .type = NLA_U8},
+};
+
+static const struct nla_policy cbs_policy[TSN_CBS_ATTR_MAX + 1] = {
+ [TSN_CBS_ATTR_TC_INDEX] = { .type = NLA_U8},
+ [TSN_CBS_ATTR_BW] = { .type = NLA_U8},
+};
+
+static const struct nla_policy tsd_policy[TSN_TSD_ATTR_MAX + 1] = {
+ [TSN_TSD_ATTR_ENABLE] = { .type = NLA_FLAG},
+ [TSN_TSD_ATTR_DISABLE] = { .type = NLA_FLAG},
+ [TSN_TSD_ATTR_PERIOD] = { .type = NLA_U32},
+ [TSN_TSD_ATTR_MAX_FRM_NUM] = { .type = NLA_U32},
+ [TSN_TSD_ATTR_CYCLE_NUM] = { .type = NLA_U32},
+ [TSN_TSD_ATTR_LOSS_STEPS] = { .type = NLA_U32},
+ [TSN_TSD_ATTR_SYN_IMME] = { .type = NLA_FLAG},
+};
+
+static const struct nla_policy qbv_policy[TSN_QBV_ATTR_MAX + 1] = {
+ [TSN_QBV_ATTR_ADMINENTRY] = { .type = NLA_NESTED},
+ [TSN_QBV_ATTR_OPERENTRY] = { .type = NLA_NESTED},
+ [TSN_QBV_ATTR_ENABLE] = { .type = NLA_FLAG},
+ [TSN_QBV_ATTR_DISABLE] = { .type = NLA_FLAG},
+ [TSN_QBV_ATTR_CONFIGCHANGE] = { .type = NLA_FLAG},
+ [TSN_QBV_ATTR_CONFIGCHANGETIME] = { .type = NLA_U64},
+ [TSN_QBV_ATTR_MAXSDU] = { .type = NLA_U32},
+ [TSN_QBV_ATTR_GRANULARITY] = { .type = NLA_U32},
+ [TSN_QBV_ATTR_CURRENTTIME] = { .type = NLA_U64},
+ [TSN_QBV_ATTR_CONFIGPENDING] = {.type = NLA_FLAG},
+ [TSN_QBV_ATTR_CONFIGCHANGEERROR] = { .type = NLA_U64},
+ [TSN_QBV_ATTR_LISTMAX] = { .type = NLA_U32},
+};
+
+static const struct nla_policy qbv_ctrl_policy[TSN_QBV_ATTR_CTRL_MAX + 1] = {
+ [TSN_QBV_ATTR_CTRL_LISTCOUNT] = { .type = NLA_U32},
+ [TSN_QBV_ATTR_CTRL_GATESTATE] = { .type = NLA_U8},
+ [TSN_QBV_ATTR_CTRL_CYCLETIME] = { .type = NLA_U32},
+ [TSN_QBV_ATTR_CTRL_CYCLETIMEEXT] = { .type = NLA_U32},
+ [TSN_QBV_ATTR_CTRL_BASETIME] = { .type = NLA_U64},
+ [TSN_QBV_ATTR_CTRL_LISTENTRY] = { .type = NLA_NESTED},
+};
+
+static const struct nla_policy qbv_entry_policy[TSN_QBV_ATTR_ENTRY_MAX + 1] = {
+ [TSN_QBV_ATTR_ENTRY_ID] = { .type = NLA_U32},
+ [TSN_QBV_ATTR_ENTRY_GC] = { .type = NLA_U8},
+ [TSN_QBV_ATTR_ENTRY_TM] = { .type = NLA_U32},
+};
+
+static const struct nla_policy cb_streamid_policy[TSN_STREAMID_ATTR_MAX + 1] = {
+ [TSN_STREAMID_ATTR_INDEX] = { .type = NLA_U32},
+ [TSN_STREAMID_ATTR_ENABLE] = { .type = NLA_FLAG},
+ [TSN_STREAMID_ATTR_DISABLE] = { .type = NLA_FLAG},
+ [TSN_STREAMID_ATTR_STREAM_HANDLE] = { .type = NLA_S32},
+ [TSN_STREAMID_ATTR_IFOP] = { .type = NLA_U32},
+ [TSN_STREAMID_ATTR_OFOP] = { .type = NLA_U32},
+ [TSN_STREAMID_ATTR_IFIP] = { .type = NLA_U32},
+ [TSN_STREAMID_ATTR_OFIP] = { .type = NLA_U32},
+ [TSN_STREAMID_ATTR_TYPE] = { .type = NLA_U8},
+ [TSN_STREAMID_ATTR_NDMAC] = { .type = NLA_U64},
+ [TSN_STREAMID_ATTR_NTAGGED] = { .type = NLA_U8},
+ [TSN_STREAMID_ATTR_NVID] = { .type = NLA_U16},
+ [TSN_STREAMID_ATTR_SMAC] = { .type = NLA_U64},
+ [TSN_STREAMID_ATTR_STAGGED] = { .type = NLA_U8},
+ [TSN_STREAMID_ATTR_SVID] = { .type = NLA_U16},
+ [TSN_STREAMID_ATTR_COUNTERS_PSI] = { .type = NLA_U64},
+ [TSN_STREAMID_ATTR_COUNTERS_PSO] = { .type = NLA_U64},
+ [TSN_STREAMID_ATTR_COUNTERS_PSPPI] = { .type = NLA_U64},
+ [TSN_STREAMID_ATTR_COUNTERS_PSPPO] = { .type = NLA_U64},
+};
+
+static const struct nla_policy qci_sfi_policy[TSN_QCI_SFI_ATTR_MAX + 1] = {
+ [TSN_QCI_SFI_ATTR_INDEX] = { .type = NLA_U32},
+ [TSN_QCI_SFI_ATTR_ENABLE] = { .type = NLA_FLAG},
+ [TSN_QCI_SFI_ATTR_DISABLE] = { .type = NLA_FLAG},
+ [TSN_QCI_SFI_ATTR_STREAM_HANDLE] = { .type = NLA_S32},
+ [TSN_QCI_SFI_ATTR_PRIO_SPEC] = { .type = NLA_S8},
+ [TSN_QCI_SFI_ATTR_GATE_ID] = { .type = NLA_U32},
+ [TSN_QCI_SFI_ATTR_FILTER_TYPE] = { .type = NLA_U8},
+ [TSN_QCI_SFI_ATTR_FLOW_ID] = { .type = NLA_S32},
+ [TSN_QCI_SFI_ATTR_MAXSDU] = { .type = NLA_U16},
+ [TSN_QCI_SFI_ATTR_COUNTERS] = {
+ .len = sizeof(struct tsn_qci_psfp_sfi_counters)},
+ [TSN_QCI_SFI_ATTR_OVERSIZE_ENABLE] = { .type = NLA_FLAG},
+ [TSN_QCI_SFI_ATTR_OVERSIZE] = { .type = NLA_FLAG},
+};
+
+static const struct nla_policy qci_sgi_policy[] = {
+ [TSN_QCI_SGI_ATTR_INDEX] = { .type = NLA_U32},
+ [TSN_QCI_SGI_ATTR_ENABLE] = { .type = NLA_FLAG},
+ [TSN_QCI_SGI_ATTR_DISABLE] = { .type = NLA_FLAG},
+ [TSN_QCI_SGI_ATTR_CONFCHANGE] = { .type = NLA_FLAG},
+ [TSN_QCI_SGI_ATTR_IRXEN] = { .type = NLA_FLAG},
+ [TSN_QCI_SGI_ATTR_IRX] = { .type = NLA_FLAG},
+ [TSN_QCI_SGI_ATTR_OEXEN] = { .type = NLA_FLAG},
+ [TSN_QCI_SGI_ATTR_OEX] = { .type = NLA_FLAG},
+ [TSN_QCI_SGI_ATTR_ADMINENTRY] = { .type = NLA_NESTED},
+ [TSN_QCI_SGI_ATTR_OPERENTRY] = { .type = NLA_NESTED},
+ [TSN_QCI_SGI_ATTR_CCTIME] = { .type = NLA_U64},
+ [TSN_QCI_SGI_ATTR_TICKG] = { .type = NLA_U32},
+ [TSN_QCI_SGI_ATTR_CUTIME] = { .type = NLA_U64},
+ [TSN_QCI_SGI_ATTR_CPENDING] = { .type = NLA_FLAG},
+ [TSN_QCI_SGI_ATTR_CCERROR] = { .type = NLA_U64},
+};
+
+static const struct nla_policy qci_sgi_ctrl_policy[] = {
+ [TSN_SGI_ATTR_CTRL_INITSTATE] = { .type = NLA_FLAG},
+ [TSN_SGI_ATTR_CTRL_LEN] = { .type = NLA_U8},
+ [TSN_SGI_ATTR_CTRL_CYTIME] = { .type = NLA_U32},
+ [TSN_SGI_ATTR_CTRL_CYTIMEEX] = { .type = NLA_U32},
+ [TSN_SGI_ATTR_CTRL_BTIME] = { .type = NLA_U64},
+ [TSN_SGI_ATTR_CTRL_INITIPV] = { .type = NLA_S8},
+ [TSN_SGI_ATTR_CTRL_GCLENTRY] = { .type = NLA_NESTED},
+};
+
+static const struct nla_policy qci_sgi_gcl_policy[] = {
+ [TSN_SGI_ATTR_GCL_GATESTATE] = { .type = NLA_FLAG},
+ [TSN_SGI_ATTR_GCL_IPV] = { .type = NLA_S8},
+ [TSN_SGI_ATTR_GCL_INTERVAL] = { .type = NLA_U32},
+ [TSN_SGI_ATTR_GCL_OCTMAX] = { .type = NLA_U32},
+};
+
+static const struct nla_policy qci_fmi_policy[] = {
+ [TSN_QCI_FMI_ATTR_INDEX] = { .type = NLA_U32},
+ [TSN_QCI_FMI_ATTR_ENABLE] = { .type = NLA_FLAG},
+ [TSN_QCI_FMI_ATTR_DISABLE] = { .type = NLA_FLAG},
+ [TSN_QCI_FMI_ATTR_CIR] = { .type = NLA_U32},
+ [TSN_QCI_FMI_ATTR_CBS] = { .type = NLA_U32},
+ [TSN_QCI_FMI_ATTR_EIR] = { .type = NLA_U32},
+ [TSN_QCI_FMI_ATTR_EBS] = { .type = NLA_U32},
+ [TSN_QCI_FMI_ATTR_CF] = { .type = NLA_FLAG},
+ [TSN_QCI_FMI_ATTR_CM] = { .type = NLA_FLAG},
+ [TSN_QCI_FMI_ATTR_DROPYL] = { .type = NLA_FLAG},
+ [TSN_QCI_FMI_ATTR_MAREDEN] = { .type = NLA_FLAG},
+ [TSN_QCI_FMI_ATTR_MARED] = { .type = NLA_FLAG},
+ [TSN_QCI_FMI_ATTR_COUNTERS] = {
+ .len = sizeof(struct tsn_qci_psfp_fmi_counters)},
+};
+
+static const struct nla_policy dscp_policy[] = {
+ [TSN_DSCP_ATTR_INDEX] = { .type = NLA_U32},
+ [TSN_DSCP_ATTR_DISABLE] = { .type = NLA_FLAG},
+ [TSN_DSCP_ATTR_COS] = { .type = NLA_U8},
+ [TSN_DSCP_ATTR_DPL] = { .type = NLA_U8},
+};
+
+static ATOMIC_NOTIFIER_HEAD(tsn_notif_chain);
+
+/**
+ * register_tsn_notifier - Register notifier
+ * @nb: notifier_block
+ *
+ * Register switch device notifier.
+ */
+int register_tsn_notifier(struct notifier_block *nb)
+{
+ return atomic_notifier_chain_register(&tsn_notif_chain, nb);
+}
+EXPORT_SYMBOL_GPL(register_tsn_notifier);
+
+/**
+ * unregister_tsn_notifier - Unregister notifier
+ * @nb: notifier_block
+ *
+ * Unregister switch device notifier.
+ */
+int unregister_tsn_notifier(struct notifier_block *nb)
+{
+ return atomic_notifier_chain_unregister(&tsn_notif_chain, nb);
+}
+EXPORT_SYMBOL_GPL(unregister_tsn_notifier);
+
+/**
+ * call_tsn_notifiers - Call notifiers
+ * @val: value passed unmodified to notifier function
+ * @dev: port device
+ * @info: notifier information data
+ *
+ * Call all network notifier blocks.
+ */
+int call_tsn_notifiers(unsigned long val, struct net_device *dev,
+ struct tsn_notifier_info *info)
+{
+ info->dev = dev;
+ return atomic_notifier_call_chain(&tsn_notif_chain, val, info);
+}
+EXPORT_SYMBOL_GPL(call_tsn_notifiers);
+
+struct tsn_port *tsn_get_port(struct net_device *ndev)
+{
+ struct tsn_port *port;
+ bool tsn_found = false;
+
+ list_for_each_entry(port, &port_list, list) {
+ if (port->netdev == ndev) {
+ tsn_found = true;
+ break;
+ }
+ }
+
+ if (!tsn_found)
+ return NULL;
+
+ return port;
+}
+EXPORT_SYMBOL_GPL(tsn_get_port);
+
+static int tsn_prepare_reply(struct genl_info *info, u8 cmd,
+ struct sk_buff **skbp, size_t size)
+{
+ struct sk_buff *skb;
+ void *reply;
+
+ /* If new attributes are added, please revisit this allocation
+ */
+ skb = genlmsg_new(size, GFP_KERNEL);
+ if (!skb)
+ return -ENOMEM;
+
+ if (!info) {
+ nlmsg_free(skb);
+ return -EINVAL;
+ }
+
+ reply = genlmsg_put_reply(skb, info, &tsn_family, 0, cmd);
+ if (!reply) {
+ nlmsg_free(skb);
+ return -EINVAL;
+ }
+
+ *skbp = skb;
+ return 0;
+}
+
+static int tsn_mk_reply(struct sk_buff *skb, int aggr, void *data, int len)
+{
+ /* add a netlink attribute to a socket buffer */
+ return nla_put(skb, aggr, len, data);
+}
+
+static int tsn_send_reply(struct sk_buff *skb, struct genl_info *info)
+{
+ struct genlmsghdr *genlhdr = nlmsg_data(nlmsg_hdr(skb));
+ void *reply = genlmsg_data(genlhdr);
+
+ genlmsg_end(skb, reply);
+
+ return genlmsg_reply(skb, info);
+}
+
+static int cmd_attr_echo_message(struct genl_info *info)
+{
+ struct nlattr *na;
+ char *msg;
+ struct sk_buff *rep_skb;
+ size_t size;
+ int ret;
+
+ na = info->attrs[TSN_CMD_ATTR_MESG];
+ if (!na)
+ return -EINVAL;
+
+ msg = (char *)nla_data(na);
+ pr_info("tsn generic netlink receive echo mesg %s\n", msg);
+
+ size = nla_total_size(strlen(msg) + 1);
+
+ ret = tsn_prepare_reply(info, TSN_CMD_REPLY, &rep_skb,
+ size + NLMSG_ALIGN(MAX_USER_SIZE));
+ if (ret < 0)
+ return ret;
+
+ ret = tsn_mk_reply(rep_skb, TSN_CMD_ATTR_MESG, msg, size);
+ if (ret < 0)
+ goto err;
+
+ return tsn_send_reply(rep_skb, info);
+
+err:
+ nlmsg_free(rep_skb);
+ return ret;
+}
+
+static int cmd_attr_echo_data(struct genl_info *info)
+{
+ struct nlattr *na;
+ s32 data;
+ struct sk_buff *rep_skb;
+ size_t size;
+ int ret;
+
+ /*read data */
+ na = info->attrs[TSN_CMD_ATTR_DATA];
+ if (!na)
+ return -EINVAL;
+
+ data = nla_get_s32(info->attrs[TSN_CMD_ATTR_DATA]);
+ pr_info("tsn generic netlink receive echo data %d\n", data);
+
+ /* send back */
+ size = nla_total_size(sizeof(s32));
+
+ ret = tsn_prepare_reply(info, TSN_CMD_REPLY, &rep_skb,
+ size + NLMSG_ALIGN(MAX_USER_SIZE));
+ if (ret < 0)
+ return ret;
+
+ /* netlink lib func */
+ ret = nla_put_s32(rep_skb, TSN_CMD_ATTR_DATA, data);
+ if (ret < 0)
+ goto err;
+
+ return tsn_send_reply(rep_skb, info);
+
+err:
+ nlmsg_free(rep_skb);
+ return ret;
+}
+
+static int tsn_echo_cmd(struct sk_buff *skb, struct genl_info *info)
+{
+ if (info->attrs[TSN_CMD_ATTR_MESG])
+ return cmd_attr_echo_message(info);
+ else if (info->attrs[TSN_CMD_ATTR_DATA])
+ return cmd_attr_echo_data(info);
+
+ return -EINVAL;
+}
+
+static int tsn_simple_reply(struct genl_info *info, u32 cmd,
+ char *portname, s32 retvalue)
+{
+ struct sk_buff *rep_skb;
+ size_t size;
+ int ret;
+
+ /* send back */
+ size = nla_total_size(strlen(portname) + 1);
+ size += nla_total_size(sizeof(s32));
+
+ ret = tsn_prepare_reply(info, cmd,
+ &rep_skb, size + NLMSG_ALIGN(MAX_USER_SIZE));
+ if (ret < 0)
+ return ret;
+
+ /* netlink lib func */
+ ret = nla_put_string(rep_skb, TSN_ATTR_IFNAME, portname);
+ if (ret < 0)
+ return ret;
+
+ ret = nla_put_s32(rep_skb, TSN_CMD_ATTR_DATA, retvalue);
+ if (ret < 0)
+ return ret;
+
+ return tsn_send_reply(rep_skb, info);
+}
+
+struct tsn_port *tsn_init_check(struct genl_info *info,
+ struct net_device **ndev)
+{
+ struct nlattr *na;
+ char *portname;
+ struct net_device *netdev;
+ struct tsn_port *port;
+ bool tsn_found = false;
+
+ if (!info->attrs[TSN_ATTR_IFNAME]) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ "no portname", -EINVAL);
+ return NULL;
+ }
+
+ na = info->attrs[TSN_ATTR_IFNAME];
+
+ portname = (char *)nla_data(na);
+
+ netdev = __dev_get_by_name(genl_info_net(info), portname);
+ if (!netdev) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ "error device", -ENODEV);
+ return NULL;
+ }
+
+ list_for_each_entry(port, &port_list, list) {
+ if (port->netdev == netdev) {
+ tsn_found = true;
+ break;
+ }
+ }
+
+ if (!tsn_found) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -ENODEV);
+ return NULL;
+ }
+
+ *ndev = netdev;
+
+ return port;
+}
+
+static int tsn_cap_get(struct sk_buff *skb, struct genl_info *info)
+{
+ struct sk_buff *rep_skb;
+ struct nlattr *tsn_cap_attr;
+ int ret;
+ u32 cap = 0;
+ struct net_device *netdev;
+ struct genlmsghdr *genlhdr;
+ const struct tsn_ops *tsnops;
+ struct tsn_port *port;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port) {
+ ret = -ENODEV;
+ goto out;
+ }
+
+ tsnops = port->tsnops;
+ genlhdr = info->genlhdr;
+ if (!tsnops->get_capability) {
+ ret = -EOPNOTSUPP;
+ goto out;
+ }
+
+ cap = tsnops->get_capability(netdev);
+ if (cap < 0) {
+ ret = cap;
+ goto out;
+ }
+
+ /* Pad netlink reply data */
+ ret = tsn_prepare_reply(info, genlhdr->cmd,
+ &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE));
+ if (ret < 0)
+ goto out;
+
+ if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name)) {
+ ret = -EMSGSIZE;
+ goto err;
+ }
+
+ tsn_cap_attr = nla_nest_start_noflag(rep_skb, TSN_ATTR_CAP);
+ if (!tsn_cap_attr) {
+ ret = -EMSGSIZE;
+ goto err;
+ }
+
+ if (cap & TSN_CAP_QBV) {
+ if (nla_put_flag(rep_skb, TSN_CAP_ATTR_QBV))
+ goto err;
+ }
+
+ if (cap & TSN_CAP_QCI) {
+ if (nla_put_flag(rep_skb, TSN_CAP_ATTR_QCI))
+ goto err;
+ }
+
+ if (cap & TSN_CAP_QBU) {
+ if (nla_put_flag(rep_skb, TSN_CAP_ATTR_QBU))
+ goto err;
+ }
+
+ if (cap & TSN_CAP_CBS) {
+ if (nla_put_flag(rep_skb, TSN_CAP_ATTR_CBS))
+ goto err;
+ }
+
+ if (cap & TSN_CAP_CB) {
+ if (nla_put_flag(rep_skb, TSN_CAP_ATTR_CB))
+ goto err;
+ }
+
+ if (cap & TSN_CAP_TBS) {
+ if (nla_put_flag(rep_skb, TSN_CAP_ATTR_TBS))
+ goto err;
+ }
+
+ if (cap & TSN_CAP_CTH) {
+ if (nla_put_flag(rep_skb, TSN_CAP_ATTR_CTH))
+ goto err;
+ }
+
+ nla_nest_end(rep_skb, tsn_cap_attr);
+
+ tsn_send_reply(rep_skb, info);
+ return 0;
+err:
+ nlmsg_free(rep_skb);
+out:
+ if (ret < 0)
+ tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret);
+ return ret;
+}
+
+static int cmd_cb_streamid_set(struct genl_info *info)
+{
+ struct nlattr *na, *sid[TSN_STREAMID_ATTR_MAX + 1];
+ u32 sid_index;
+ u8 iden_type = 1;
+ bool enable;
+ int ret;
+ struct net_device *netdev;
+ struct tsn_cb_streamid sidconf;
+ const struct tsn_ops *tsnops;
+ struct tsn_port *port;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port)
+ return -ENODEV;
+
+ tsnops = port->tsnops;
+
+ memset(&sidconf, 0, sizeof(struct tsn_cb_streamid));
+
+ if (!info->attrs[TSN_ATTR_STREAM_IDENTIFY])
+ return -EINVAL;
+
+ na = info->attrs[TSN_ATTR_STREAM_IDENTIFY];
+
+ ret = NLA_PARSE_NESTED(sid, TSN_STREAMID_ATTR_MAX,
+ na, cb_streamid_policy);
+ if (ret)
+ return -EINVAL;
+
+ if (!sid[TSN_STREAMID_ATTR_INDEX])
+ return -EINVAL;
+
+ sid_index = nla_get_u32(sid[TSN_STREAMID_ATTR_INDEX]);
+
+ if (sid[TSN_STREAMID_ATTR_ENABLE])
+ enable = true;
+ else if (sid[TSN_STREAMID_ATTR_DISABLE])
+ enable = false;
+ else
+ return -EINVAL;
+
+ if (!enable)
+ goto loaddev;
+
+ if (sid[TSN_STREAMID_ATTR_TYPE])
+ iden_type = nla_get_u8(sid[TSN_STREAMID_ATTR_TYPE]);
+ else
+ return -EINVAL;
+
+ sidconf.type = iden_type;
+ switch (iden_type) {
+ case STREAMID_NULL:
+ if (!sid[TSN_STREAMID_ATTR_NDMAC] ||
+ !sid[TSN_STREAMID_ATTR_NTAGGED] ||
+ !sid[TSN_STREAMID_ATTR_NVID]) {
+ return -EINVAL;
+ }
+
+ sidconf.para.nid.dmac =
+ nla_get_u64(sid[TSN_STREAMID_ATTR_NDMAC]);
+ sidconf.para.nid.tagged =
+ nla_get_u8(sid[TSN_STREAMID_ATTR_NTAGGED]);
+ sidconf.para.nid.vid =
+ nla_get_u16(sid[TSN_STREAMID_ATTR_NVID]);
+ break;
+ case STREAMID_SMAC_VLAN:
+ /* TODO: not supportted yet */
+ if (!sid[TSN_STREAMID_ATTR_SMAC] ||
+ !sid[TSN_STREAMID_ATTR_STAGGED] ||
+ !sid[TSN_STREAMID_ATTR_SVID]) {
+ return -EINVAL;
+ }
+
+ sidconf.para.sid.smac =
+ nla_get_u64(sid[TSN_STREAMID_ATTR_SMAC]);
+ sidconf.para.sid.tagged =
+ nla_get_u8(sid[TSN_STREAMID_ATTR_STAGGED]);
+ sidconf.para.sid.vid =
+ nla_get_u16(sid[TSN_STREAMID_ATTR_SVID]);
+ break;
+ case STREAMID_DMAC_VLAN:
+
+ case STREAMID_IP:
+
+ default:
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ if (sid[TSN_STREAMID_ATTR_STREAM_HANDLE])
+ sidconf.handle =
+ nla_get_s32(sid[TSN_STREAMID_ATTR_STREAM_HANDLE]);
+
+ if (sid[TSN_STREAMID_ATTR_IFOP])
+ sidconf.ifac_oport = nla_get_u32(sid[TSN_STREAMID_ATTR_IFOP]);
+ if (sid[TSN_STREAMID_ATTR_OFOP])
+ sidconf.ofac_oport = nla_get_u32(sid[TSN_STREAMID_ATTR_OFOP]);
+ if (sid[TSN_STREAMID_ATTR_IFIP])
+ sidconf.ifac_iport = nla_get_u32(sid[TSN_STREAMID_ATTR_IFIP]);
+ if (sid[TSN_STREAMID_ATTR_OFIP])
+ sidconf.ofac_iport = nla_get_u32(sid[TSN_STREAMID_ATTR_OFIP]);
+
+loaddev:
+ if (!tsnops->cb_streamid_set) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EPERM);
+ return -EOPNOTSUPP;
+ }
+
+ ret = tsnops->cb_streamid_set(netdev, sid_index, enable, &sidconf);
+ if (ret < 0) {
+ tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret);
+ return ret;
+ }
+
+ /* simple reply here. To be continue */
+ if (tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, 0))
+ return -1;
+
+ return 0;
+}
+
+static int tsn_cb_streamid_set(struct sk_buff *skb, struct genl_info *info)
+{
+ if (info->attrs[TSN_ATTR_IFNAME]) {
+ cmd_cb_streamid_set(info);
+ return 0;
+ }
+
+ return -1;
+}
+
+static int cmd_cb_streamid_get(struct genl_info *info)
+{
+ struct nlattr *na, *sidattr, *sid[TSN_STREAMID_ATTR_MAX + 1];
+ u32 sid_index;
+ struct genlmsghdr *genlhdr;
+ struct sk_buff *rep_skb;
+ int ret, i;
+ int valid;
+ struct net_device *netdev;
+ struct tsn_cb_streamid sidconf;
+ struct tsn_cb_streamid_counters sidcounts;
+ const struct tsn_ops *tsnops;
+ struct tsn_port *port;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port)
+ return -ENODEV;
+
+ tsnops = port->tsnops;
+
+ memset(&sidconf, 0, sizeof(struct tsn_cb_streamid));
+ memset(&sidcounts, 0, sizeof(struct tsn_cb_streamid_counters));
+
+ if (!info->attrs[TSN_ATTR_STREAM_IDENTIFY])
+ return -EINVAL;
+
+ na = info->attrs[TSN_ATTR_STREAM_IDENTIFY];
+
+ ret = NLA_PARSE_NESTED(sid, TSN_STREAMID_ATTR_MAX,
+ na, cb_streamid_policy);
+ if (ret)
+ return -EINVAL;
+
+ if (!sid[TSN_STREAMID_ATTR_INDEX])
+ return -EINVAL;
+
+ sid_index = nla_get_u32(sid[TSN_STREAMID_ATTR_INDEX]);
+
+ if (!tsnops->cb_streamid_get) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EPERM);
+ ret = -EINVAL;
+ goto exit;
+ } else {
+ valid = tsnops->cb_streamid_get(netdev, sid_index, &sidconf);
+ if (valid < 0) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, valid);
+ return valid;
+ }
+ }
+
+ /* send back */
+ genlhdr = info->genlhdr;
+ ret = tsn_prepare_reply(info, genlhdr->cmd, &rep_skb,
+ NLMSG_ALIGN(MAX_ATTR_SIZE));
+ if (ret < 0)
+ return ret;
+
+ /* input netlink the parameters */
+ sidattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_STREAM_IDENTIFY);
+ if (!sidattr) {
+ ret = -EINVAL;
+ goto err;
+ }
+
+ if (nla_put_u32(rep_skb, TSN_STREAMID_ATTR_INDEX, sid_index))
+ return -EMSGSIZE;
+
+ if (valid == 1) {
+ nla_put_flag(rep_skb, TSN_STREAMID_ATTR_ENABLE);
+ } else if (valid == 0) {
+ nla_put_flag(rep_skb, TSN_STREAMID_ATTR_DISABLE);
+ } else {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ goto err;
+ }
+
+ if (nla_put_s32(rep_skb,
+ TSN_STREAMID_ATTR_STREAM_HANDLE, sidconf.handle) ||
+ nla_put_u32(rep_skb, TSN_STREAMID_ATTR_IFOP, sidconf.ifac_oport) ||
+ nla_put_u32(rep_skb, TSN_STREAMID_ATTR_OFOP, sidconf.ofac_oport) ||
+ nla_put_u32(rep_skb, TSN_STREAMID_ATTR_IFIP, sidconf.ifac_iport) ||
+ nla_put_u32(rep_skb, TSN_STREAMID_ATTR_OFIP, sidconf.ofac_iport) ||
+ nla_put_u8(rep_skb, TSN_STREAMID_ATTR_TYPE, sidconf.type))
+ return -EMSGSIZE;
+
+ switch (sidconf.type) {
+ case STREAMID_NULL:
+ if (NLA_PUT_U64(rep_skb, TSN_STREAMID_ATTR_NDMAC,
+ sidconf.para.nid.dmac) ||
+ nla_put_u16(rep_skb, TSN_STREAMID_ATTR_NVID,
+ sidconf.para.nid.vid) ||
+ nla_put_u8(rep_skb, TSN_STREAMID_ATTR_NTAGGED,
+ sidconf.para.nid.tagged))
+ return -EMSGSIZE;
+ break;
+ case STREAMID_SMAC_VLAN:
+ if (NLA_PUT_U64(rep_skb, TSN_STREAMID_ATTR_SMAC,
+ sidconf.para.sid.smac) ||
+ nla_put_u16(rep_skb, TSN_STREAMID_ATTR_SVID,
+ sidconf.para.sid.vid) ||
+ nla_put_u8(rep_skb, TSN_STREAMID_ATTR_STAGGED,
+ sidconf.para.sid.tagged))
+ return -EMSGSIZE;
+ break;
+ case STREAMID_DMAC_VLAN:
+ case STREAMID_IP:
+ default:
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ goto err;
+ }
+
+ if (!tsnops->cb_streamid_counters_get) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EPERM);
+ goto err;
+ } else {
+ ret = tsnops->cb_streamid_counters_get(netdev,
+ sid_index,
+ &sidcounts);
+ if (ret < 0) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, ret);
+ goto err;
+ }
+ }
+
+ if (NLA_PUT_U64(rep_skb, TSN_STREAMID_ATTR_COUNTERS_PSI,
+ sidcounts.per_stream.input) ||
+ NLA_PUT_U64(rep_skb, TSN_STREAMID_ATTR_COUNTERS_PSO,
+ sidcounts.per_stream.output))
+ return -EMSGSIZE;
+
+ for (i = 0; i < 32; i++) {
+ if (NLA_PUT_U64(rep_skb, TSN_STREAMID_ATTR_COUNTERS_PSPPI,
+ sidcounts.per_streamport[i].input) ||
+ NLA_PUT_U64(rep_skb, TSN_STREAMID_ATTR_COUNTERS_PSPPO,
+ sidcounts.per_streamport[i].output))
+ return -EMSGSIZE;
+ }
+
+ nla_nest_end(rep_skb, sidattr);
+ /* end netlink input the parameters */
+
+ /* netlink lib func */
+ ret = nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name);
+ if (ret < 0)
+ goto err;
+
+ ret = nla_put_s32(rep_skb, TSN_CMD_ATTR_DATA, 0);
+ if (ret < 0)
+ goto err;
+
+ return tsn_send_reply(rep_skb, info);
+
+err:
+ nlmsg_free(rep_skb);
+exit:
+ return ret;
+}
+
+static int tsn_cb_streamid_get(struct sk_buff *skb, struct genl_info *info)
+{
+ if (info->attrs[TSN_ATTR_IFNAME]) {
+ cmd_cb_streamid_get(info);
+ return 0;
+ }
+
+ return -1;
+}
+
+static int cmb_cb_streamid_counters_get(struct genl_info *info)
+{
+ return 0;
+}
+
+static int tsn_cb_streamid_counters_get(struct sk_buff *skb,
+ struct genl_info *info)
+{
+ if (info->attrs[TSN_ATTR_IFNAME]) {
+ cmb_cb_streamid_counters_get(info);
+ return 0;
+ }
+
+ return -1;
+}
+
+static int tsn_qci_cap_get(struct sk_buff *skb, struct genl_info *info)
+{
+ struct nlattr *qci_cap;
+ struct sk_buff *rep_skb;
+ int ret;
+ struct net_device *netdev;
+ struct genlmsghdr *genlhdr;
+ struct tsn_qci_psfp_stream_param qci_cap_status;
+ const struct tsn_ops *tsnops;
+ struct tsn_port *port;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port) {
+ ret = -EINVAL;
+ goto out;
+ }
+
+ tsnops = port->tsnops;
+
+ genlhdr = info->genlhdr;
+
+ memset(&qci_cap_status, 0, sizeof(qci_cap_status));
+
+ if (!tsnops->qci_get_maxcap) {
+ ret = -EOPNOTSUPP;
+ goto out;
+ }
+
+ ret = tsnops->qci_get_maxcap(netdev, &qci_cap_status);
+ if (ret < 0)
+ goto out;
+
+ /* Pad netlink reply data */
+ ret = tsn_prepare_reply(info, genlhdr->cmd,
+ &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE));
+ if (ret < 0)
+ goto out;
+
+ if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name)) {
+ ret = -EMSGSIZE;
+ goto err;
+ }
+
+ qci_cap = nla_nest_start_noflag(rep_skb, TSN_ATTR_QCI_SP);
+ if (!qci_cap) {
+ ret = -EMSGSIZE;
+ goto err;
+ }
+
+ if (nla_put_u32(rep_skb, TSN_QCI_STREAM_ATTR_MAX_SFI,
+ qci_cap_status.max_sf_instance) ||
+ nla_put_u32(rep_skb, TSN_QCI_STREAM_ATTR_MAX_SGI,
+ qci_cap_status.max_sg_instance) ||
+ nla_put_u32(rep_skb, TSN_QCI_STREAM_ATTR_MAX_FMI,
+ qci_cap_status.max_fm_instance) ||
+ nla_put_u32(rep_skb, TSN_QCI_STREAM_ATTR_SLM,
+ qci_cap_status.supported_list_max)) {
+ ret = -EMSGSIZE;
+ goto err;
+ }
+
+ nla_nest_end(rep_skb, qci_cap);
+
+ tsn_send_reply(rep_skb, info);
+
+ return 0;
+err:
+ nlmsg_free(rep_skb);
+out:
+ if (ret < 0)
+ tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret);
+
+ return ret;
+}
+
+static int cmd_qci_sfi_set(struct genl_info *info)
+{
+ struct nlattr *na, *sfi[TSN_QCI_SFI_ATTR_MAX + 1];
+ u32 sfi_handle;
+ bool enable;
+ int ret;
+ struct net_device *netdev;
+ struct tsn_qci_psfp_sfi_conf sficonf;
+ const struct tsn_ops *tsnops;
+ struct tsn_port *port;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port)
+ return -ENODEV;
+
+ tsnops = port->tsnops;
+
+ memset(&sficonf, 0, sizeof(struct tsn_qci_psfp_sfi_conf));
+
+ if (!info->attrs[TSN_ATTR_QCI_SFI])
+ return -EINVAL;
+
+ na = info->attrs[TSN_ATTR_QCI_SFI];
+
+ ret = NLA_PARSE_NESTED(sfi, TSN_QCI_SFI_ATTR_MAX, na, qci_sfi_policy);
+ if (ret) {
+ pr_info("tsn: parse value TSN_QCI_SFI_ATTR_MAX error.");
+ return -EINVAL;
+ }
+
+ if (!sfi[TSN_QCI_SFI_ATTR_INDEX])
+ return -EINVAL;
+
+ sfi_handle = nla_get_u32(sfi[TSN_QCI_SFI_ATTR_INDEX]);
+
+ if (sfi[TSN_QCI_SFI_ATTR_ENABLE]) {
+ enable = true;
+ } else if (sfi[TSN_QCI_SFI_ATTR_DISABLE]) {
+ enable = false;
+ goto loaddrive;
+ } else {
+ pr_err("tsn: must provde ENABLE or DISABLE attribute.\n");
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ if (!sfi[TSN_QCI_SFI_ATTR_GATE_ID]) {
+ pr_err("tsn: must provide stream gate index\n");
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ if (!sfi[TSN_QCI_SFI_ATTR_STREAM_HANDLE])
+ sficonf.stream_handle_spec = -1;
+ else
+ sficonf.stream_handle_spec =
+ nla_get_s32(sfi[TSN_QCI_SFI_ATTR_STREAM_HANDLE]);
+
+ if (!sfi[TSN_QCI_SFI_ATTR_PRIO_SPEC])
+ sficonf.priority_spec = -1;
+ else
+ sficonf.priority_spec =
+ nla_get_s8(sfi[TSN_QCI_SFI_ATTR_PRIO_SPEC]);
+
+ sficonf.stream_gate_instance_id =
+ nla_get_u32(sfi[TSN_QCI_SFI_ATTR_GATE_ID]);
+
+ if (sfi[TSN_QCI_SFI_ATTR_MAXSDU])
+ sficonf.stream_filter.maximum_sdu_size =
+ nla_get_u16(sfi[TSN_QCI_SFI_ATTR_MAXSDU]);
+ else
+ sficonf.stream_filter.maximum_sdu_size = 0;
+
+ if (sfi[TSN_QCI_SFI_ATTR_FLOW_ID])
+ sficonf.stream_filter.flow_meter_instance_id =
+ nla_get_s32(sfi[TSN_QCI_SFI_ATTR_FLOW_ID]);
+ else
+ sficonf.stream_filter.flow_meter_instance_id = -1;
+
+ if (sfi[TSN_QCI_SFI_ATTR_OVERSIZE_ENABLE])
+ sficonf.block_oversize_enable = true;
+
+ if (sfi[TSN_QCI_SFI_ATTR_OVERSIZE])
+ sficonf.block_oversize = true;
+
+loaddrive:
+ if (!tsnops->qci_sfi_set) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EPERM);
+ return -EINVAL;
+ }
+
+ ret = tsnops->qci_sfi_set(netdev, sfi_handle, enable, &sficonf);
+ if (ret < 0) {
+ tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret);
+ return ret;
+ }
+
+ ret = tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, 0);
+
+ if (ret)
+ return ret;
+ return 0;
+}
+
+static int tsn_qci_sfi_set(struct sk_buff *skb, struct genl_info *info)
+{
+ if (info->attrs[TSN_ATTR_IFNAME]) {
+ cmd_qci_sfi_set(info);
+ return 0;
+ }
+
+ return -1;
+}
+
+static int cmd_qci_sfi_get(struct genl_info *info)
+{
+ struct nlattr *na, *sfiattr;
+ struct nlattr *sfi[TSN_QCI_SFI_ATTR_MAX + 1];
+ u32 sfi_handle;
+ struct sk_buff *rep_skb;
+ int ret, valid = 0;
+ struct net_device *netdev;
+ struct genlmsghdr *genlhdr;
+ struct tsn_qci_psfp_sfi_conf sficonf;
+ struct tsn_qci_psfp_sfi_counters sficount;
+ const struct tsn_ops *tsnops;
+ struct tsn_port *port;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port)
+ return -ENODEV;
+
+ tsnops = port->tsnops;
+
+ genlhdr = info->genlhdr;
+
+ if (!info->attrs[TSN_ATTR_QCI_SFI])
+ return -EINVAL;
+
+ na = info->attrs[TSN_ATTR_QCI_SFI];
+
+ ret = NLA_PARSE_NESTED(sfi, TSN_QCI_SFI_ATTR_MAX,
+ na, qci_sfi_policy);
+ if (ret)
+ return -EINVAL;
+
+ if (!sfi[TSN_QCI_SFI_ATTR_INDEX])
+ return -EINVAL;
+
+ sfi_handle = nla_get_u32(sfi[TSN_QCI_SFI_ATTR_INDEX]);
+
+ memset(&sficonf, 0, sizeof(struct tsn_qci_psfp_sfi_conf));
+ memset(&sficount, 0, sizeof(struct tsn_qci_psfp_sfi_counters));
+
+ if (!tsnops->qci_sfi_get || !tsnops->qci_sfi_counters_get) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EPERM);
+ ret = -EINVAL;
+ goto exit;
+ } else {
+ valid = tsnops->qci_sfi_get(netdev, sfi_handle, &sficonf);
+ if (valid < 0) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, valid);
+ return valid;
+ }
+
+ valid = tsnops->qci_sfi_counters_get(netdev, sfi_handle,
+ &sficount);
+ if (valid < 0) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, valid);
+ return valid;
+ }
+ }
+
+ ret = tsn_prepare_reply(info, genlhdr->cmd,
+ &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE));
+ if (ret < 0)
+ return ret;
+
+ if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name))
+ goto err;
+
+ sfiattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_QCI_SFI);
+ if (!sfiattr) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ ret = -EINVAL;
+ goto err;
+ }
+
+ if (nla_put_u32(rep_skb, TSN_QCI_SFI_ATTR_INDEX, sfi_handle))
+ return -EMSGSIZE;
+
+ if (valid) {
+ if (nla_put_flag(rep_skb, TSN_QCI_SFI_ATTR_ENABLE))
+ return -EMSGSIZE;
+ } else {
+ if (nla_put_flag(rep_skb, TSN_QCI_SFI_ATTR_DISABLE))
+ return -EMSGSIZE;
+ }
+
+ if (nla_put_s32(rep_skb, TSN_QCI_SFI_ATTR_STREAM_HANDLE,
+ sficonf.stream_handle_spec) ||
+ nla_put_s8(rep_skb, TSN_QCI_SFI_ATTR_PRIO_SPEC,
+ sficonf.priority_spec) ||
+ nla_put_u32(rep_skb, TSN_QCI_SFI_ATTR_GATE_ID,
+ sficonf.stream_gate_instance_id))
+ return -EMSGSIZE;
+
+ if (sficonf.stream_filter.maximum_sdu_size)
+ if (nla_put_u16(rep_skb, TSN_QCI_SFI_ATTR_MAXSDU,
+ sficonf.stream_filter.maximum_sdu_size))
+ return -EMSGSIZE;
+
+ if (sficonf.stream_filter.flow_meter_instance_id >= 0)
+ if (nla_put_s32(rep_skb, TSN_QCI_SFI_ATTR_FLOW_ID,
+ sficonf.stream_filter.flow_meter_instance_id))
+ return -EMSGSIZE;
+
+ if (sficonf.block_oversize_enable)
+ if (nla_put_flag(rep_skb, TSN_QCI_SFI_ATTR_OVERSIZE_ENABLE))
+ return -EMSGSIZE;
+ if (sficonf.block_oversize)
+ if (nla_put_flag(rep_skb, TSN_QCI_SFI_ATTR_OVERSIZE))
+ return -EMSGSIZE;
+
+ if (nla_put(rep_skb, TSN_QCI_SFI_ATTR_COUNTERS,
+ sizeof(struct tsn_qci_psfp_sfi_counters), &sficount))
+ return -EMSGSIZE;
+
+ nla_nest_end(rep_skb, sfiattr);
+
+ return tsn_send_reply(rep_skb, info);
+err:
+ nlmsg_free(rep_skb);
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+exit:
+ return ret;
+}
+
+static int tsn_qci_sfi_get(struct sk_buff *skb, struct genl_info *info)
+{
+ if (info->attrs[TSN_ATTR_IFNAME]) {
+ cmd_qci_sfi_get(info);
+ return 0;
+ }
+
+ return -1;
+}
+
+static int cmd_qci_sfi_counters_get(struct genl_info *info)
+{
+ struct nlattr *na, *sfiattr;
+ struct nlattr *sfi[TSN_QCI_SFI_ATTR_MAX + 1];
+ u32 sfi_handle;
+ struct sk_buff *rep_skb;
+ int ret;
+ struct net_device *netdev;
+ struct genlmsghdr *genlhdr;
+ struct tsn_qci_psfp_sfi_counters sficount;
+ const struct tsn_ops *tsnops;
+ struct tsn_port *port;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port)
+ return -ENODEV;
+
+ tsnops = port->tsnops;
+
+ genlhdr = info->genlhdr;
+
+ if (!info->attrs[TSN_ATTR_QCI_SFI])
+ return -EINVAL;
+
+ na = info->attrs[TSN_ATTR_QCI_SFI];
+
+ ret = NLA_PARSE_NESTED(sfi, TSN_QCI_SFI_ATTR_MAX,
+ na, qci_sfi_policy);
+ if (ret)
+ return -EINVAL;
+
+ if (!sfi[TSN_QCI_SFI_ATTR_INDEX])
+ return -EINVAL;
+
+ sfi_handle = nla_get_u32(sfi[TSN_QCI_SFI_ATTR_INDEX]);
+
+ memset(&sficount, 0, sizeof(struct tsn_qci_psfp_sfi_counters));
+ if (!tsnops->qci_sfi_counters_get) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EPERM);
+ return -1;
+ }
+
+ ret = tsnops->qci_sfi_counters_get(netdev, sfi_handle, &sficount);
+ if (ret < 0) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, ret);
+ return ret;
+ }
+
+ ret = tsn_prepare_reply(info, genlhdr->cmd, &rep_skb,
+ NLMSG_ALIGN(MAX_ATTR_SIZE));
+ if (ret < 0)
+ return ret;
+
+ if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name))
+ goto err;
+
+ sfiattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_QCI_SFI);
+ if (!sfiattr) {
+ ret = -EINVAL;
+ goto err;
+ }
+
+ if (nla_put_u32(rep_skb, TSN_QCI_SFI_ATTR_INDEX, sfi_handle))
+ return -EMSGSIZE;
+
+ ret = tsnops->qci_sfi_counters_get(netdev, sfi_handle, &sficount);
+ if (ret < 0) {
+ tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret);
+ return ret;
+ }
+
+ if (nla_put(rep_skb, TSN_QCI_SFI_ATTR_COUNTERS,
+ sizeof(struct tsn_qci_psfp_sfi_counters), &sficount))
+ return -EMSGSIZE;
+
+ nla_nest_end(rep_skb, sfiattr);
+
+ return tsn_send_reply(rep_skb, info);
+err:
+ nlmsg_free(rep_skb);
+ tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, -EINVAL);
+ return ret;
+}
+
+static int tsn_qci_sfi_counters_get(struct sk_buff *skb, struct genl_info *info)
+{
+ if (info->attrs[TSN_ATTR_IFNAME]) {
+ cmd_qci_sfi_counters_get(info);
+ return 0;
+ }
+
+ return -1;
+}
+
+static int cmd_qci_sgi_set(struct genl_info *info)
+{
+ struct nlattr *na;
+ struct nlattr *sgia[TSN_QCI_SGI_ATTR_MAX + 1];
+ struct nlattr *admin[TSN_SGI_ATTR_CTRL_MAX + 1];
+ int ret = 0;
+ struct net_device *netdev;
+ const struct tsn_ops *tsnops;
+ struct tsn_qci_psfp_sgi_conf sgi;
+ struct tsn_qci_psfp_gcl *gcl = NULL;
+ u16 sgi_handle = 0;
+ u16 listcount = 0;
+ struct tsn_port *port;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port)
+ return -ENODEV;
+
+ tsnops = port->tsnops;
+
+ memset(&sgi, 0, sizeof(struct tsn_qci_psfp_sgi_conf));
+
+ if (!info->attrs[TSN_ATTR_QCI_SGI]) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ na = info->attrs[TSN_ATTR_QCI_SGI];
+
+ ret = NLA_PARSE_NESTED(sgia, TSN_QCI_SGI_ATTR_MAX,
+ na, qci_sgi_policy);
+ if (ret) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ if (sgia[TSN_QCI_SGI_ATTR_ENABLE] && sgia[TSN_QCI_SGI_ATTR_DISABLE]) {
+ pr_err("tsn: enable or disable?\n");
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -1;
+ }
+
+ if (sgia[TSN_QCI_SGI_ATTR_INDEX])
+ sgi_handle = nla_get_u32(sgia[TSN_QCI_SGI_ATTR_INDEX]);
+
+ if (sgia[TSN_QCI_SGI_ATTR_DISABLE]) {
+ sgi.gate_enabled = 0;
+ goto loaddev;
+ } else {
+ /* set default to be enable*/
+ sgi.gate_enabled = 1;
+ }
+
+ if (sgia[TSN_QCI_SGI_ATTR_CONFCHANGE])
+ sgi.config_change = 1;
+
+ if (sgia[TSN_QCI_SGI_ATTR_IRXEN])
+ sgi.block_invalid_rx_enable = 1;
+
+ if (sgia[TSN_QCI_SGI_ATTR_IRX])
+ sgi.block_invalid_rx = 1;
+
+ if (sgia[TSN_QCI_SGI_ATTR_OEXEN])
+ sgi.block_octets_exceeded_enable = 1;
+
+ if (sgia[TSN_QCI_SGI_ATTR_OEX])
+ sgi.block_octets_exceeded = 1;
+
+ if (sgia[TSN_QCI_SGI_ATTR_ADMINENTRY]) {
+ struct nlattr *entry;
+ int rem;
+ int count = 0;
+
+ na = sgia[TSN_QCI_SGI_ATTR_ADMINENTRY];
+ ret = NLA_PARSE_NESTED(admin, TSN_SGI_ATTR_CTRL_MAX,
+ na, qci_sgi_ctrl_policy);
+
+ /* Other parameters in admin control */
+ if (admin[TSN_SGI_ATTR_CTRL_INITSTATE])
+ sgi.admin.gate_states = 1;
+
+ if (admin[TSN_SGI_ATTR_CTRL_CYTIME])
+ sgi.admin.cycle_time =
+ nla_get_u32(admin[TSN_SGI_ATTR_CTRL_CYTIME]);
+
+ if (admin[TSN_SGI_ATTR_CTRL_CYTIMEEX])
+ sgi.admin.cycle_time_extension =
+ nla_get_u32(admin[TSN_SGI_ATTR_CTRL_CYTIMEEX]);
+
+ if (admin[TSN_SGI_ATTR_CTRL_BTIME])
+ sgi.admin.base_time =
+ nla_get_u64(admin[TSN_SGI_ATTR_CTRL_BTIME]);
+
+ if (admin[TSN_SGI_ATTR_CTRL_INITIPV])
+ sgi.admin.init_ipv =
+ nla_get_s8(admin[TSN_SGI_ATTR_CTRL_INITIPV]);
+ else
+ sgi.admin.init_ipv = -1;
+
+ if (admin[TSN_SGI_ATTR_CTRL_LEN]) {
+ sgi.admin.control_list_length =
+ nla_get_u8(admin[TSN_SGI_ATTR_CTRL_LEN]);
+ listcount = sgi.admin.control_list_length;
+ }
+
+ if (!listcount)
+ goto loaddev;
+
+ gcl = kmalloc_array(listcount, sizeof(*gcl), GFP_KERNEL);
+
+ memset(gcl, 0, listcount * sizeof(struct tsn_qci_psfp_gcl));
+
+ /* Check the whole admin attrs,
+ * checkout the TSN_SGI_ATTR_CTRL_GCLENTRY attributes
+ */
+ nla_for_each_nested(entry, na, rem) {
+ struct nlattr *gcl_entry[TSN_SGI_ATTR_GCL_MAX + 1];
+ struct nlattr *ti, *om;
+
+ if (nla_type(entry) != TSN_SGI_ATTR_CTRL_GCLENTRY)
+ continue;
+
+ /* parse each TSN_SGI_ATTR_CTRL_GCLENTRY */
+ ret = NLA_PARSE_NESTED(gcl_entry, TSN_SGI_ATTR_GCL_MAX,
+ entry, qci_sgi_gcl_policy);
+ /* Parse gate control list */
+ if (gcl_entry[TSN_SGI_ATTR_GCL_GATESTATE])
+ (gcl + count)->gate_state = 1;
+
+ if (gcl_entry[TSN_SGI_ATTR_GCL_IPV])
+ (gcl + count)->ipv =
+ nla_get_s8(gcl_entry[TSN_SGI_ATTR_GCL_IPV]);
+
+ if (gcl_entry[TSN_SGI_ATTR_GCL_INTERVAL]) {
+ ti = gcl_entry[TSN_SGI_ATTR_GCL_INTERVAL];
+ (gcl + count)->time_interval = nla_get_u32(ti);
+ }
+
+ if (gcl_entry[TSN_SGI_ATTR_GCL_OCTMAX]) {
+ om = gcl_entry[TSN_SGI_ATTR_GCL_OCTMAX];
+ (gcl + count)->octet_max = nla_get_u32(om);
+ }
+
+ count++;
+
+ if (count >= listcount)
+ break;
+ }
+
+ if (count < listcount) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ pr_err("tsn: count less than TSN_SGI_ATTR_CTRL_LEN\n");
+ kfree(gcl);
+ return -EINVAL;
+ }
+
+ } else {
+ pr_info("tsn: no admin list parameters setting\n");
+ }
+
+loaddev:
+ if (!tsnops->qci_sgi_set) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EPERM);
+ kfree(gcl);
+ return -EINVAL;
+ }
+
+ sgi.admin.gcl = gcl;
+
+ ret = tsnops->qci_sgi_set(netdev, sgi_handle, &sgi);
+ kfree(gcl);
+ if (!ret)
+ return tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, 0);
+
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, ret);
+ return ret;
+}
+
+static int tsn_qci_sgi_set(struct sk_buff *skb, struct genl_info *info)
+{
+ if (info->attrs[TSN_ATTR_IFNAME]) {
+ cmd_qci_sgi_set(info);
+ return 0;
+ }
+
+ return -1;
+}
+
+static int cmd_qci_sgi_get(struct genl_info *info)
+{
+ struct nlattr *na, *sgiattr, *adminattr, *sglattr;
+ struct nlattr *sgi[TSN_QCI_SGI_ATTR_MAX + 1];
+ struct sk_buff *rep_skb;
+ int ret;
+ struct net_device *netdev;
+ struct genlmsghdr *genlhdr;
+ struct tsn_qci_psfp_sgi_conf sgiadmin;
+ struct tsn_qci_psfp_gcl *gcl = NULL;
+ const struct tsn_ops *tsnops;
+ u16 sgi_handle;
+ u8 listcount, i;
+ struct tsn_port *port;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port)
+ return -ENODEV;
+
+ tsnops = port->tsnops;
+
+ if (!info->attrs[TSN_ATTR_QCI_SGI]) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ pr_err("tsn: no sgi handle input\n");
+ return -EINVAL;
+ }
+
+ na = info->attrs[TSN_ATTR_QCI_SGI];
+
+ ret = NLA_PARSE_NESTED(sgi, TSN_QCI_SGI_ATTR_MAX,
+ na, qci_sgi_policy);
+ if (ret)
+ return -EINVAL;
+
+ if (!sgi[TSN_QCI_SGI_ATTR_INDEX]) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ pr_err("tsn: no sgi handle input\n");
+ return -EINVAL;
+ }
+
+ sgi_handle = nla_get_u32(sgi[TSN_QCI_SGI_ATTR_INDEX]);
+
+ /* Get config data from device */
+ genlhdr = info->genlhdr;
+
+ memset(&sgiadmin, 0, sizeof(struct tsn_qci_psfp_sgi_conf));
+
+ if (!tsnops->qci_sgi_get) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EPERM);
+ return -1;
+ }
+
+ ret = tsnops->qci_sgi_get(netdev, sgi_handle, &sgiadmin);
+ if (ret < 0) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, ret);
+ return ret;
+ }
+
+ /* Form netlink reply data */
+ ret = tsn_prepare_reply(info, genlhdr->cmd,
+ &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE));
+ if (ret < 0)
+ return ret;
+
+ if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name))
+ return -EMSGSIZE;
+
+ sgiattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_QCI_SGI);
+ if (!sgiattr)
+ return -EMSGSIZE;
+
+ if (nla_put_u32(rep_skb, TSN_QCI_SGI_ATTR_INDEX, sgi_handle))
+ return -EMSGSIZE;
+
+ /* Gate enable? sgiadmin.gate_enabled */
+ if (sgiadmin.gate_enabled) {
+ if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_ENABLE))
+ return -EMSGSIZE;
+ } else {
+ if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_DISABLE))
+ return -EMSGSIZE;
+ }
+
+ if (sgiadmin.config_change)
+ if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_CONFCHANGE))
+ return -EMSGSIZE;
+
+ if (sgiadmin.block_invalid_rx_enable)
+ if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_IRXEN))
+ return -EMSGSIZE;
+
+ if (sgiadmin.block_invalid_rx)
+ if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_IRX))
+ return -EMSGSIZE;
+
+ if (sgiadmin.block_octets_exceeded_enable)
+ if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_OEXEN))
+ return -EMSGSIZE;
+
+ if (sgiadmin.block_octets_exceeded)
+ if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_OEX))
+ return -EMSGSIZE;
+
+ /* Administration */
+ adminattr = nla_nest_start_noflag(rep_skb, TSN_QCI_SGI_ATTR_ADMINENTRY);
+ if (!adminattr)
+ return -EMSGSIZE;
+
+ if (sgiadmin.admin.gate_states)
+ if (nla_put_flag(rep_skb, TSN_SGI_ATTR_CTRL_INITSTATE))
+ return -EMSGSIZE;
+
+ if (nla_put_u32(rep_skb, TSN_SGI_ATTR_CTRL_CYTIME,
+ sgiadmin.admin.cycle_time) ||
+ nla_put_u32(rep_skb, TSN_SGI_ATTR_CTRL_CYTIMEEX,
+ sgiadmin.admin.cycle_time_extension) ||
+ NLA_PUT_U64(rep_skb, TSN_SGI_ATTR_CTRL_BTIME,
+ sgiadmin.admin.base_time) ||
+ nla_put_u8(rep_skb, TSN_SGI_ATTR_CTRL_INITIPV,
+ sgiadmin.admin.init_ipv))
+ return -EMSGSIZE;
+
+ listcount = sgiadmin.admin.control_list_length;
+ if (!listcount)
+ goto out1;
+
+ if (!sgiadmin.admin.gcl) {
+ pr_err("error: no gate control list\n");
+ ret = -EINVAL;
+ goto err;
+ }
+
+ gcl = sgiadmin.admin.gcl;
+
+ /* loop list */
+ for (i = 0; i < listcount; i++) {
+ s8 ipv;
+ u32 ti, omax;
+
+ if (!(gcl + i)) {
+ pr_err("error: list count too big\n");
+ ret = -EINVAL;
+ kfree(sgiadmin.admin.gcl);
+ goto err;
+ }
+
+ /* Adminastration entry */
+ sglattr = nla_nest_start_noflag(rep_skb,
+ TSN_SGI_ATTR_CTRL_GCLENTRY);
+ if (!sglattr)
+ return -EMSGSIZE;
+ ipv = (gcl + i)->ipv;
+ ti = (gcl + i)->time_interval;
+ omax = (gcl + i)->octet_max;
+
+ if ((gcl + i)->gate_state)
+ if (nla_put_flag(rep_skb, TSN_SGI_ATTR_GCL_GATESTATE))
+ return -EMSGSIZE;
+
+ if (nla_put_s8(rep_skb, TSN_SGI_ATTR_GCL_IPV, ipv) ||
+ nla_put_u32(rep_skb, TSN_SGI_ATTR_GCL_INTERVAL, ti) ||
+ nla_put_u32(rep_skb, TSN_SGI_ATTR_GCL_OCTMAX, omax))
+ return -EMSGSIZE;
+
+ /* End administration entry */
+ nla_nest_end(rep_skb, sglattr);
+ }
+
+ kfree(sgiadmin.admin.gcl);
+ if (nla_put_u8(rep_skb, TSN_SGI_ATTR_CTRL_LEN, listcount))
+ return -EMSGSIZE;
+
+out1:
+ /* End adminastration */
+ nla_nest_end(rep_skb, adminattr);
+
+ nla_nest_end(rep_skb, sgiattr);
+
+ return tsn_send_reply(rep_skb, info);
+err:
+ nlmsg_free(rep_skb);
+ tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret);
+ return ret;
+}
+
+static int tsn_qci_sgi_get(struct sk_buff *skb, struct genl_info *info)
+{
+ if (info->attrs[TSN_ATTR_IFNAME]) {
+ cmd_qci_sgi_get(info);
+ return 0;
+ }
+
+ return -1;
+}
+
+static int cmd_qci_sgi_status_get(struct genl_info *info)
+{
+ struct nlattr *na, *sgiattr, *operattr, *sglattr;
+ struct nlattr *sgi[TSN_QCI_SGI_ATTR_MAX + 1];
+ struct sk_buff *rep_skb;
+ int ret;
+ struct net_device *netdev;
+ struct genlmsghdr *genlhdr;
+ struct tsn_psfp_sgi_status sgistat;
+ struct tsn_qci_psfp_gcl *gcl = NULL;
+ const struct tsn_ops *tsnops;
+ u16 sgi_handle;
+ u8 listcount;
+ int valid, i;
+ struct tsn_port *port;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port)
+ return -ENODEV;
+
+ tsnops = port->tsnops;
+
+ if (!info->attrs[TSN_ATTR_QCI_SGI]) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ pr_err("tsn: no sgi handle input\n");
+ return -EINVAL;
+ }
+
+ na = info->attrs[TSN_ATTR_QCI_SGI];
+
+ ret = NLA_PARSE_NESTED(sgi, TSN_QCI_SGI_ATTR_MAX,
+ na, qci_sgi_policy);
+ if (ret)
+ return -EINVAL;
+
+ if (!sgi[TSN_QCI_SGI_ATTR_INDEX]) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ pr_err("tsn: no sgi handle input\n");
+ return -EINVAL;
+ }
+
+ sgi_handle = nla_get_u32(sgi[TSN_QCI_SGI_ATTR_INDEX]);
+
+ /* Get status data from device */
+ genlhdr = info->genlhdr;
+
+ memset(&sgistat, 0, sizeof(struct tsn_psfp_sgi_status));
+
+ if (!tsnops->qci_sgi_status_get) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EPERM);
+ return -1;
+ }
+
+ valid = tsnops->qci_sgi_status_get(netdev, sgi_handle, &sgistat);
+ if (valid < 0) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, valid);
+ return valid;
+ }
+
+ /* Form netlink reply data */
+ ret = tsn_prepare_reply(info, genlhdr->cmd,
+ &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE));
+ if (ret < 0)
+ return ret;
+
+ if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name))
+ return -EMSGSIZE;
+
+ /* Down one netlink attribute level */
+ sgiattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_QCI_SGI);
+ if (!sgiattr)
+ return -EMSGSIZE;
+
+ if (nla_put_u32(rep_skb, TSN_QCI_SGI_ATTR_INDEX, sgi_handle))
+ return -EMSGSIZE;
+
+ /* Gate enable */
+ if (valid == 1) {
+ if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_ENABLE))
+ return -EMSGSIZE;
+ } else {
+ if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_DISABLE))
+ return -EMSGSIZE;
+ }
+
+ if (nla_put_u32(rep_skb, TSN_QCI_SGI_ATTR_TICKG,
+ sgistat.tick_granularity) ||
+ NLA_PUT_U64(rep_skb, TSN_QCI_SGI_ATTR_CCTIME,
+ sgistat.config_change_time) ||
+ NLA_PUT_U64(rep_skb, TSN_QCI_SGI_ATTR_CUTIME,
+ sgistat.current_time) ||
+ NLA_PUT_U64(rep_skb, TSN_QCI_SGI_ATTR_CCERROR,
+ sgistat.config_change_error))
+ return -EMSGSIZE;
+
+ if (sgistat.config_pending)
+ if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_CPENDING))
+ return -EMSGSIZE;
+
+ /* operation data */
+ operattr = nla_nest_start_noflag(rep_skb, TSN_QCI_SGI_ATTR_OPERENTRY);
+ if (!operattr)
+ return -EMSGSIZE;
+
+ if (sgistat.oper.gate_states)
+ if (nla_put_flag(rep_skb, TSN_SGI_ATTR_CTRL_INITSTATE))
+ return -EMSGSIZE;
+
+ if (nla_put_u32(rep_skb, TSN_SGI_ATTR_CTRL_CYTIME,
+ sgistat.oper.cycle_time) ||
+ nla_put_u32(rep_skb, TSN_SGI_ATTR_CTRL_CYTIMEEX,
+ sgistat.oper.cycle_time_extension) ||
+ NLA_PUT_U64(rep_skb, TSN_SGI_ATTR_CTRL_BTIME,
+ sgistat.oper.base_time) ||
+ nla_put_u8(rep_skb, TSN_SGI_ATTR_CTRL_INITIPV,
+ sgistat.oper.init_ipv))
+ return -EMSGSIZE;
+
+ /* Loop list */
+ listcount = sgistat.oper.control_list_length;
+ if (!listcount)
+ goto out1;
+
+ if (!sgistat.oper.gcl) {
+ pr_err("error: list lenghth is not zero!\n");
+ ret = -EINVAL;
+ goto err;
+ }
+
+ gcl = sgistat.oper.gcl;
+
+ /* loop list */
+ for (i = 0; i < listcount; i++) {
+ s8 ipv;
+ u32 ti, omax;
+
+ if (!(gcl + i)) {
+ pr_err("error: list count too big\n");
+ ret = -EINVAL;
+ kfree(sgistat.oper.gcl);
+ goto err;
+ }
+
+ /* Operation entry */
+ sglattr = nla_nest_start_noflag(rep_skb,
+ TSN_SGI_ATTR_CTRL_GCLENTRY);
+ if (!sglattr)
+ return -EMSGSIZE;
+ ipv = (gcl + i)->ipv;
+ ti = (gcl + i)->time_interval;
+ omax = (gcl + i)->octet_max;
+
+ if ((gcl + i)->gate_state)
+ if (nla_put_flag(rep_skb, TSN_SGI_ATTR_GCL_GATESTATE))
+ return -EMSGSIZE;
+
+ if (nla_put_s8(rep_skb, TSN_SGI_ATTR_GCL_IPV, ipv) ||
+ nla_put_u32(rep_skb, TSN_SGI_ATTR_GCL_INTERVAL, ti) ||
+ nla_put_u32(rep_skb, TSN_SGI_ATTR_GCL_OCTMAX, omax))
+ return -EMSGSIZE;
+
+ /* End operation entry */
+ nla_nest_end(rep_skb, sglattr);
+ }
+
+ kfree(sgistat.oper.gcl);
+ if (nla_put_u8(rep_skb, TSN_SGI_ATTR_CTRL_LEN, listcount))
+ return -EMSGSIZE;
+out1:
+ /* End operation */
+ nla_nest_end(rep_skb, operattr);
+
+ nla_nest_end(rep_skb, sgiattr);
+
+ return tsn_send_reply(rep_skb, info);
+err:
+ nlmsg_free(rep_skb);
+ tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret);
+ return ret;
+}
+
+static int tsn_qci_sgi_status_get(struct sk_buff *skb, struct genl_info *info)
+{
+ if (info->attrs[TSN_ATTR_IFNAME]) {
+ cmd_qci_sgi_status_get(info);
+ return 0;
+ }
+
+ return -1;
+}
+
+static int cmd_qci_fmi_set(struct genl_info *info)
+{
+ struct nlattr *na, *fmi[TSN_QCI_FMI_ATTR_MAX + 1];
+ u32 index;
+ int ret;
+ struct net_device *netdev;
+ struct tsn_qci_psfp_fmi fmiconf;
+ const struct tsn_ops *tsnops;
+ bool enable = 0;
+ struct tsn_port *port;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port)
+ return -ENODEV;
+
+ tsnops = port->tsnops;
+
+ memset(&fmiconf, 0, sizeof(struct tsn_qci_psfp_fmi));
+
+ if (!info->attrs[TSN_ATTR_QCI_FMI])
+ return -EINVAL;
+
+ na = info->attrs[TSN_ATTR_QCI_FMI];
+
+ ret = NLA_PARSE_NESTED(fmi, TSN_QCI_FMI_ATTR_MAX, na, qci_fmi_policy);
+ if (ret) {
+ pr_info("tsn: parse value TSN_QCI_FMI_ATTR_MAX error.");
+ return -EINVAL;
+ }
+
+ if (!fmi[TSN_QCI_FMI_ATTR_INDEX])
+ return -EINVAL;
+
+ index = nla_get_u32(fmi[TSN_QCI_FMI_ATTR_INDEX]);
+
+ if (fmi[TSN_QCI_FMI_ATTR_DISABLE])
+ goto loaddev;
+
+ enable = 1;
+
+ if (fmi[TSN_QCI_FMI_ATTR_CIR])
+ fmiconf.cir = nla_get_u32(fmi[TSN_QCI_FMI_ATTR_CIR]);
+
+ if (fmi[TSN_QCI_FMI_ATTR_CBS])
+ fmiconf.cbs = nla_get_u32(fmi[TSN_QCI_FMI_ATTR_CBS]);
+
+ if (fmi[TSN_QCI_FMI_ATTR_EIR])
+ fmiconf.eir = nla_get_u32(fmi[TSN_QCI_FMI_ATTR_EIR]);
+
+ if (fmi[TSN_QCI_FMI_ATTR_EBS])
+ fmiconf.ebs = nla_get_u32(fmi[TSN_QCI_FMI_ATTR_EBS]);
+
+ if (fmi[TSN_QCI_FMI_ATTR_CF])
+ fmiconf.cf = 1;
+
+ if (fmi[TSN_QCI_FMI_ATTR_CM])
+ fmiconf.cm = 1;
+
+ if (fmi[TSN_QCI_FMI_ATTR_DROPYL])
+ fmiconf.drop_on_yellow = 1;
+
+ if (fmi[TSN_QCI_FMI_ATTR_MAREDEN])
+ fmiconf.mark_red_enable = 1;
+
+ if (fmi[TSN_QCI_FMI_ATTR_MARED])
+ fmiconf.mark_red = 1;
+
+loaddev:
+
+ if (!tsnops->qci_fmi_set) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EPERM);
+ return -EINVAL;
+ }
+
+ ret = tsnops->qci_fmi_set(netdev, index, enable, &fmiconf);
+ if (ret < 0) {
+ tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret);
+ return ret;
+ }
+
+ ret = tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, 0);
+
+ if (ret)
+ return ret;
+ return 0;
+}
+
+static int tsn_qci_fmi_set(struct sk_buff *skb, struct genl_info *info)
+{
+ if (info->attrs[TSN_ATTR_IFNAME]) {
+ cmd_qci_fmi_set(info);
+ return 0;
+ }
+
+ return -1;
+}
+
+static int cmd_qci_fmi_get(struct genl_info *info)
+{
+ struct nlattr *na, *fmi[TSN_QCI_FMI_ATTR_MAX + 1], *fmiattr;
+ u32 index;
+ struct sk_buff *rep_skb;
+ int ret;
+ struct net_device *netdev;
+ struct tsn_qci_psfp_fmi fmiconf;
+ struct tsn_qci_psfp_fmi_counters counters;
+ const struct tsn_ops *tsnops;
+ struct genlmsghdr *genlhdr;
+ struct tsn_port *port;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port)
+ return -ENODEV;
+
+ tsnops = port->tsnops;
+
+ if (!info->attrs[TSN_ATTR_QCI_FMI])
+ return -EINVAL;
+
+ na = info->attrs[TSN_ATTR_QCI_FMI];
+
+ ret = NLA_PARSE_NESTED(fmi, TSN_QCI_FMI_ATTR_MAX,
+ na, qci_fmi_policy);
+ if (ret) {
+ pr_info("tsn: parse value TSN_QCI_FMI_ATTR_MAX error.");
+ return -EINVAL;
+ }
+
+ if (!fmi[TSN_QCI_FMI_ATTR_INDEX])
+ return -EINVAL;
+
+ index = nla_get_u32(fmi[TSN_QCI_FMI_ATTR_INDEX]);
+
+ /* Get data from device */
+ memset(&fmiconf, 0, sizeof(struct tsn_qci_psfp_fmi));
+ memset(&counters, 0, sizeof(struct tsn_qci_psfp_fmi_counters));
+
+ if (!tsnops->qci_fmi_get) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EPERM);
+ return -EINVAL;
+ }
+
+ ret = tsnops->qci_fmi_get(netdev, index, &fmiconf, &counters);
+ if (ret < 0) {
+ tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret);
+ return ret;
+ }
+
+ genlhdr = info->genlhdr;
+
+ /* Form netlink reply data */
+ ret = tsn_prepare_reply(info, genlhdr->cmd,
+ &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE));
+ if (ret < 0)
+ return ret;
+
+ if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name))
+ return -EMSGSIZE;
+
+ fmiattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_QCI_FMI);
+ if (!fmiattr)
+ return -EMSGSIZE;
+
+ if (nla_put_u32(rep_skb, TSN_QCI_FMI_ATTR_INDEX, index) ||
+ nla_put_u32(rep_skb, TSN_QCI_FMI_ATTR_CIR, fmiconf.cir) ||
+ nla_put_u32(rep_skb, TSN_QCI_FMI_ATTR_CBS, fmiconf.cbs) ||
+ nla_put_u32(rep_skb, TSN_QCI_FMI_ATTR_EIR, fmiconf.eir) ||
+ nla_put_u32(rep_skb, TSN_QCI_FMI_ATTR_EBS, fmiconf.ebs))
+ return -EMSGSIZE;
+
+ if (fmiconf.cf)
+ if (nla_put_flag(rep_skb, TSN_QCI_FMI_ATTR_CF))
+ return -EMSGSIZE;
+
+ if (fmiconf.cm)
+ if (nla_put_flag(rep_skb, TSN_QCI_FMI_ATTR_CM))
+ return -EMSGSIZE;
+
+ if (fmiconf.drop_on_yellow)
+ if (nla_put_flag(rep_skb, TSN_QCI_FMI_ATTR_DROPYL))
+ return -EMSGSIZE;
+
+ if (fmiconf.mark_red_enable)
+ if (nla_put_flag(rep_skb, TSN_QCI_FMI_ATTR_MAREDEN))
+ return -EMSGSIZE;
+
+ if (fmiconf.mark_red)
+ if (nla_put_flag(rep_skb, TSN_QCI_FMI_ATTR_MAREDEN))
+ return -EMSGSIZE;
+
+ if (nla_put(rep_skb, TSN_QCI_FMI_ATTR_COUNTERS,
+ sizeof(struct tsn_qci_psfp_fmi_counters), &counters))
+ return -EMSGSIZE;
+
+ nla_nest_end(rep_skb, fmiattr);
+
+ tsn_send_reply(rep_skb, info);
+
+ return 0;
+}
+
+static int tsn_qci_fmi_get(struct sk_buff *skb, struct genl_info *info)
+{
+ if (info->attrs[TSN_ATTR_IFNAME]) {
+ cmd_qci_fmi_get(info);
+ return 0;
+ }
+
+ return -1;
+}
+
+static int cmd_qbv_set(struct genl_info *info)
+{
+ struct nlattr *na, *na1;
+ struct nlattr *qbv_table;
+ struct nlattr *qbv[TSN_QBV_ATTR_MAX + 1];
+ struct nlattr *qbvctrl[TSN_QBV_ATTR_CTRL_MAX + 1];
+ int rem;
+ int ret = 0;
+ struct net_device *netdev;
+ struct tsn_qbv_conf qbvconfig;
+ const struct tsn_ops *tsnops;
+ struct tsn_qbv_entry *gatelist = NULL;
+ int count = 0;
+ struct tsn_port *port;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port)
+ return -ENODEV;
+
+ tsnops = port->tsnops;
+
+ memset(&qbvconfig, 0, sizeof(struct tsn_qbv_conf));
+
+ if (!info->attrs[TSN_ATTR_QBV])
+ return -EINVAL;
+
+ na = info->attrs[TSN_ATTR_QBV];
+
+ ret = NLA_PARSE_NESTED(qbv, TSN_QBV_ATTR_MAX, na, qbv_policy);
+ if (ret)
+ return -EINVAL;
+
+ if (qbv[TSN_QBV_ATTR_ENABLE])
+ qbvconfig.gate_enabled = 1;
+ else
+ goto setdrive;
+
+ if (qbv[TSN_QBV_ATTR_CONFIGCHANGE])
+ qbvconfig.config_change = 1;
+
+ if (!qbv[TSN_QBV_ATTR_ADMINENTRY]) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -1;
+ }
+
+ na1 = qbv[TSN_QBV_ATTR_ADMINENTRY];
+ NLA_PARSE_NESTED(qbvctrl, TSN_QBV_ATTR_CTRL_MAX,
+ na1, qbv_ctrl_policy);
+
+ if (qbvctrl[TSN_QBV_ATTR_CTRL_CYCLETIME]) {
+ qbvconfig.admin.cycle_time =
+ nla_get_u32(qbvctrl[TSN_QBV_ATTR_CTRL_CYCLETIME]);
+ }
+
+ if (qbvctrl[TSN_QBV_ATTR_CTRL_CYCLETIMEEXT]) {
+ qbvconfig.admin.cycle_time_extension =
+ nla_get_u32(qbvctrl[TSN_QBV_ATTR_CTRL_CYCLETIMEEXT]);
+ }
+
+ if (qbvctrl[TSN_QBV_ATTR_CTRL_BASETIME]) {
+ qbvconfig.admin.base_time =
+ nla_get_u64(qbvctrl[TSN_QBV_ATTR_CTRL_BASETIME]);
+ }
+
+ if (qbvctrl[TSN_QBV_ATTR_CTRL_GATESTATE]) {
+ qbvconfig.admin.gate_states =
+ nla_get_u8(qbvctrl[TSN_QBV_ATTR_CTRL_GATESTATE]);
+ }
+
+ if (qbvctrl[TSN_QBV_ATTR_CTRL_LISTCOUNT]) {
+ int listcount;
+
+ listcount = nla_get_u32(qbvctrl[TSN_QBV_ATTR_CTRL_LISTCOUNT]);
+
+ qbvconfig.admin.control_list_length = listcount;
+
+ gatelist = kmalloc_array(listcount,
+ sizeof(*gatelist),
+ GFP_KERNEL);
+
+ nla_for_each_nested(qbv_table, na1, rem) {
+ struct nlattr *qbv_entry[TSN_QBV_ATTR_ENTRY_MAX + 1];
+
+ if (nla_type(qbv_table) != TSN_QBV_ATTR_CTRL_LISTENTRY)
+ continue;
+
+ ret = NLA_PARSE_NESTED(qbv_entry,
+ TSN_QBV_ATTR_ENTRY_MAX,
+ qbv_table, qbv_entry_policy);
+ if (ret)
+ return -EINVAL;
+
+ (gatelist + count)->gate_state =
+ nla_get_u8(qbv_entry[TSN_QBV_ATTR_ENTRY_GC]);
+ (gatelist + count)->time_interval =
+ nla_get_u32(qbv_entry[TSN_QBV_ATTR_ENTRY_TM]);
+ count++;
+ if (count > listcount)
+ break;
+ }
+ }
+
+ if (gatelist)
+ qbvconfig.admin.control_list = gatelist;
+
+setdrive:
+ if (!tsnops->qbv_set) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EPERM);
+ goto err;
+ }
+
+ ret = tsnops->qbv_set(netdev, &qbvconfig);
+
+ /* send back */
+ if (ret < 0)
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, ret);
+ else
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, 0);
+
+err:
+ kfree(gatelist);
+ return ret;
+}
+
+static int tsn_qbv_set(struct sk_buff *skb, struct genl_info *info)
+{
+ if (info->attrs[TSN_ATTR_IFNAME]) {
+ cmd_qbv_set(info);
+ return 0;
+ }
+
+ return -1;
+}
+
+static int cmd_qbv_get(struct genl_info *info)
+{
+ struct nlattr *qbv, *qbvadminattr;
+ struct sk_buff *rep_skb;
+ int ret;
+ int len = 0, i = 0;
+ struct net_device *netdev;
+ struct genlmsghdr *genlhdr;
+ struct tsn_qbv_conf qbvconf;
+ const struct tsn_ops *tsnops;
+ struct tsn_port *port;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port)
+ return -ENODEV;
+
+ tsnops = port->tsnops;
+
+ genlhdr = info->genlhdr;
+
+ memset(&qbvconf, 0, sizeof(struct tsn_qbv_conf));
+
+ if (!tsnops->qbv_get) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EPERM);
+ return -1;
+ }
+
+ ret = tsnops->qbv_get(netdev, &qbvconf);
+ if (ret < 0) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, ret);
+ return ret;
+ }
+
+ ret = tsn_prepare_reply(info, genlhdr->cmd,
+ &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE));
+ if (ret < 0)
+ return ret;
+
+ if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name))
+ return -EMSGSIZE;
+
+ qbv = nla_nest_start_noflag(rep_skb, TSN_ATTR_QBV);
+ if (!qbv)
+ return -EMSGSIZE;
+
+ qbvadminattr = nla_nest_start_noflag(rep_skb, TSN_QBV_ATTR_ADMINENTRY);
+ if (!qbvadminattr)
+ return -EMSGSIZE;
+
+ if (qbvconf.admin.control_list) {
+ len = qbvconf.admin.control_list_length;
+ if (nla_put_u32(rep_skb, TSN_QBV_ATTR_CTRL_LISTCOUNT, len))
+ return -EMSGSIZE;
+
+ for (i = 0; i < len; i++) {
+ struct nlattr *qbv_table;
+ u8 gs;
+ u32 tp;
+ int glisttype = TSN_QBV_ATTR_CTRL_LISTENTRY;
+
+ gs = (qbvconf.admin.control_list + i)->gate_state;
+ tp = (qbvconf.admin.control_list + i)->time_interval;
+
+ qbv_table =
+ nla_nest_start_noflag(rep_skb, glisttype);
+ if (!qbv_table)
+ return -EMSGSIZE;
+
+ if (nla_put_u32(rep_skb, TSN_QBV_ATTR_ENTRY_ID, i) ||
+ nla_put_u8(rep_skb, TSN_QBV_ATTR_ENTRY_GC, gs) ||
+ nla_put_u32(rep_skb, TSN_QBV_ATTR_ENTRY_TM, tp))
+ return -EMSGSIZE;
+ nla_nest_end(rep_skb, qbv_table);
+ }
+
+ if (qbvconf.admin.gate_states)
+ if (nla_put_u8(rep_skb, TSN_QBV_ATTR_CTRL_GATESTATE,
+ qbvconf.admin.gate_states))
+ return -EMSGSIZE;
+
+ if (qbvconf.admin.cycle_time)
+ if (nla_put_u32(rep_skb, TSN_QBV_ATTR_CTRL_CYCLETIME,
+ qbvconf.admin.cycle_time))
+ return -EMSGSIZE;
+
+ if (qbvconf.admin.cycle_time_extension)
+ if (nla_put_u32(rep_skb, TSN_QBV_ATTR_CTRL_CYCLETIMEEXT,
+ qbvconf.admin.cycle_time_extension))
+ return -EMSGSIZE;
+
+ if (qbvconf.admin.base_time)
+ if (NLA_PUT_U64(rep_skb, TSN_QBV_ATTR_CTRL_BASETIME,
+ qbvconf.admin.base_time))
+ return -EMSGSIZE;
+
+ kfree(qbvconf.admin.control_list);
+
+ } else {
+ pr_info("tsn: error get administrator data.");
+ }
+
+ nla_nest_end(rep_skb, qbvadminattr);
+
+ if (qbvconf.gate_enabled) {
+ if (nla_put_flag(rep_skb, TSN_QBV_ATTR_ENABLE))
+ return -EMSGSIZE;
+ } else {
+ if (nla_put_flag(rep_skb, TSN_QBV_ATTR_DISABLE))
+ return -EMSGSIZE;
+ }
+
+ if (qbvconf.maxsdu)
+ if (nla_put_u32(rep_skb, TSN_QBV_ATTR_MAXSDU, qbvconf.maxsdu))
+ return -EMSGSIZE;
+
+ if (qbvconf.config_change)
+ if (nla_put_flag(rep_skb, TSN_QBV_ATTR_CONFIGCHANGE))
+ return -EMSGSIZE;
+
+ nla_nest_end(rep_skb, qbv);
+
+ tsn_send_reply(rep_skb, info);
+
+ return ret;
+}
+
+static int cmd_qbv_status_get(struct genl_info *info)
+{
+ struct nlattr *qbv, *qbvoperattr;
+ struct sk_buff *rep_skb;
+ int ret;
+ int len = 0, i = 0;
+ struct net_device *netdev;
+ struct genlmsghdr *genlhdr;
+ struct tsn_qbv_status qbvstatus;
+ const struct tsn_ops *tsnops;
+ struct tsn_port *port;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port)
+ return -ENODEV;
+
+ tsnops = port->tsnops;
+
+ genlhdr = info->genlhdr;
+
+ memset(&qbvstatus, 0, sizeof(struct tsn_qbv_status));
+
+ if (!tsnops->qbv_get_status) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EPERM);
+ return -1;
+ }
+
+ ret = tsnops->qbv_get_status(netdev, &qbvstatus);
+ if (ret < 0) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, ret);
+ return ret;
+ }
+
+ ret = tsn_prepare_reply(info, genlhdr->cmd,
+ &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE));
+ if (ret < 0)
+ return ret;
+
+ if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name))
+ return -EMSGSIZE;
+
+ qbv = nla_nest_start_noflag(rep_skb, TSN_ATTR_QBV);
+ if (!qbv)
+ return -EMSGSIZE;
+
+ qbvoperattr = nla_nest_start_noflag(rep_skb, TSN_QBV_ATTR_OPERENTRY);
+ if (!qbvoperattr)
+ return -EMSGSIZE;
+
+ if (qbvstatus.oper.control_list) {
+ len = qbvstatus.oper.control_list_length;
+ if (nla_put_u32(rep_skb, TSN_QBV_ATTR_CTRL_LISTCOUNT, len)) {
+ nla_nest_cancel(rep_skb, qbvoperattr);
+ return -EMSGSIZE;
+ }
+
+ for (i = 0; i < len; i++) {
+ struct nlattr *qbv_table;
+ u8 gs;
+ u32 tp;
+ int glisttype = TSN_QBV_ATTR_CTRL_LISTENTRY;
+
+ gs = (qbvstatus.oper.control_list + i)->gate_state;
+ tp = (qbvstatus.oper.control_list + i)->time_interval;
+
+ qbv_table = nla_nest_start_noflag(rep_skb, glisttype);
+ if (!qbv_table)
+ return -EMSGSIZE;
+
+ if (nla_put_u32(rep_skb, TSN_QBV_ATTR_ENTRY_ID, i) ||
+ nla_put_u8(rep_skb, TSN_QBV_ATTR_ENTRY_GC, gs) ||
+ nla_put_u32(rep_skb, TSN_QBV_ATTR_ENTRY_TM, tp)) {
+ nla_nest_cancel(rep_skb, qbv_table);
+ return -EMSGSIZE;
+ }
+
+ nla_nest_end(rep_skb, qbv_table);
+ }
+
+ if (qbvstatus.oper.gate_states) {
+ if (nla_put_u8(rep_skb, TSN_QBV_ATTR_CTRL_GATESTATE,
+ qbvstatus.oper.gate_states))
+ return -EMSGSIZE;
+ }
+
+ if (qbvstatus.oper.cycle_time) {
+ if (nla_put_u32(rep_skb, TSN_QBV_ATTR_CTRL_CYCLETIME,
+ qbvstatus.oper.cycle_time))
+ return -EMSGSIZE;
+ }
+
+ if (qbvstatus.oper.cycle_time_extension) {
+ if (nla_put_u32(rep_skb, TSN_QBV_ATTR_CTRL_CYCLETIMEEXT,
+ qbvstatus.oper.cycle_time_extension))
+ return -EMSGSIZE;
+ }
+
+ if (qbvstatus.oper.base_time) {
+ if (NLA_PUT_U64(rep_skb, TSN_QBV_ATTR_CTRL_BASETIME,
+ qbvstatus.oper.base_time))
+ return -EMSGSIZE;
+ }
+
+ kfree(qbvstatus.oper.control_list);
+ } else {
+ pr_info("tsn: error get operation list data.");
+ }
+
+ nla_nest_end(rep_skb, qbvoperattr);
+
+ if (qbvstatus.config_change_time) {
+ if (NLA_PUT_U64(rep_skb, TSN_QBV_ATTR_CONFIGCHANGETIME,
+ qbvstatus.config_change_time))
+ return -EMSGSIZE;
+ }
+
+ if (qbvstatus.tick_granularity) {
+ if (nla_put_u32(rep_skb, TSN_QBV_ATTR_GRANULARITY,
+ qbvstatus.tick_granularity))
+ return -EMSGSIZE;
+ }
+
+ if (qbvstatus.current_time) {
+ if (NLA_PUT_U64(rep_skb, TSN_QBV_ATTR_CURRENTTIME,
+ qbvstatus.current_time))
+ return -EMSGSIZE;
+ }
+
+ if (qbvstatus.config_pending) {
+ if (nla_put_flag(rep_skb, TSN_QBV_ATTR_CONFIGPENDING))
+ return -EMSGSIZE;
+ }
+
+ if (qbvstatus.config_change_error) {
+ if (NLA_PUT_U64(rep_skb, TSN_QBV_ATTR_CONFIGCHANGEERROR,
+ qbvstatus.config_change_error))
+ return -EMSGSIZE;
+ }
+
+ if (qbvstatus.supported_list_max) {
+ if (nla_put_u32(rep_skb, TSN_QBV_ATTR_LISTMAX,
+ qbvstatus.supported_list_max))
+ return -EMSGSIZE;
+ }
+
+ nla_nest_end(rep_skb, qbv);
+
+ tsn_send_reply(rep_skb, info);
+
+ return ret;
+}
+
+static int tsn_qbv_status_get(struct sk_buff *skb, struct genl_info *info)
+{
+ if (info->attrs[TSN_ATTR_IFNAME])
+ cmd_qbv_status_get(info);
+
+ return 0;
+}
+
+static int tsn_qbv_get(struct sk_buff *skb, struct genl_info *info)
+{
+ if (info->attrs[TSN_ATTR_IFNAME])
+ cmd_qbv_get(info);
+
+ return 0;
+}
+
+static int tsn_cbs_set(struct sk_buff *skb, struct genl_info *info)
+{
+ struct nlattr *na;
+ struct nlattr *cbsa[TSN_CBS_ATTR_MAX + 1];
+ struct net_device *netdev;
+ const struct tsn_ops *tsnops;
+ int ret;
+ u8 tc, bw;
+ struct tsn_port *port;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port)
+ return -ENODEV;
+
+ tsnops = port->tsnops;
+
+ if (!info->attrs[TSN_ATTR_CBS]) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ na = info->attrs[TSN_ATTR_CBS];
+
+ if (!tsnops->cbs_set) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EPERM);
+ return -1;
+ }
+
+ ret = NLA_PARSE_NESTED(cbsa, TSN_CBS_ATTR_MAX, na, cbs_policy);
+ if (ret) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ if (!cbsa[TSN_CBS_ATTR_TC_INDEX]) {
+ pr_err("tsn: no TSN_CBS_ATTR_TC_INDEX input\n");
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+ tc = nla_get_u8(cbsa[TSN_CBS_ATTR_TC_INDEX]);
+
+ if (!cbsa[TSN_CBS_ATTR_BW]) {
+ pr_err("tsn: no TSN_CBS_ATTR_BW input\n");
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ bw = nla_get_u8(cbsa[TSN_CBS_ATTR_BW]);
+ if (bw > 100) {
+ pr_err("tsn: TSN_CBS_ATTR_BW isn't in the range of 0~100\n");
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ ret = tsnops->cbs_set(netdev, tc, bw);
+ if (ret < 0) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, ret);
+ return ret;
+ }
+
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, 0);
+ return 0;
+}
+
+static int tsn_cbs_get(struct sk_buff *skb, struct genl_info *info)
+{
+ struct nlattr *na, *cbsattr;
+ struct nlattr *cbsa[TSN_CBS_ATTR_MAX + 1];
+ struct net_device *netdev;
+ const struct tsn_ops *tsnops;
+ struct sk_buff *rep_skb;
+ int ret;
+ struct genlmsghdr *genlhdr;
+ u8 tc;
+ struct tsn_port *port;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port)
+ return -ENODEV;
+
+ tsnops = port->tsnops;
+
+ if (!info->attrs[TSN_ATTR_CBS]) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ if (!tsnops->cbs_get) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EPERM);
+ return -1;
+ }
+
+ na = info->attrs[TSN_ATTR_CBS];
+ ret = NLA_PARSE_NESTED(cbsa, TSN_CBS_ATTR_MAX, na, cbs_policy);
+ if (ret) {
+ pr_err("tsn: parse value TSN_CBS_ATTR_MAX error.");
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ /* Get status data from device */
+ genlhdr = info->genlhdr;
+
+ /* Form netlink reply data */
+ ret = tsn_prepare_reply(info, genlhdr->cmd, &rep_skb,
+ NLMSG_ALIGN(MAX_ATTR_SIZE));
+ if (ret < 0)
+ return ret;
+
+ if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name))
+ return -EMSGSIZE;
+
+ cbsattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_CBS);
+ if (!cbsattr)
+ return -EMSGSIZE;
+
+ if (!cbsa[TSN_CBS_ATTR_TC_INDEX]) {
+ pr_err("tsn: must to specify the TSN_CBS_ATTR_TC_INDEX\n");
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+ tc = nla_get_u8(cbsa[TSN_CBS_ATTR_TC_INDEX]);
+
+ ret = tsnops->cbs_get(netdev, tc);
+ if (ret < 0) {
+ pr_err("tsn: cbs_get return error\n");
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, ret);
+ return ret;
+ }
+
+ if (nla_put_u8(rep_skb, TSN_CBS_ATTR_BW, ret & 0XF))
+ return -EMSGSIZE;
+
+ nla_nest_end(rep_skb, cbsattr);
+ return tsn_send_reply(rep_skb, info);
+}
+
+static int cmd_qbu_set(struct genl_info *info)
+{
+ struct nlattr *na;
+ struct nlattr *qbua[TSN_QBU_ATTR_MAX + 1];
+ struct net_device *netdev;
+ const struct tsn_ops *tsnops;
+ int ret;
+ u8 preemptible = 0;
+ struct tsn_port *port;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port)
+ return -ENODEV;
+
+ tsnops = port->tsnops;
+
+ if (!info->attrs[TSN_ATTR_QBU]) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ na = info->attrs[TSN_ATTR_QBU];
+
+ ret = NLA_PARSE_NESTED(qbua, TSN_QBU_ATTR_MAX, na, qbu_policy);
+ if (ret) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ if (qbua[TSN_QBU_ATTR_ADMIN_STATE])
+ preemptible = nla_get_u8(qbua[TSN_QBU_ATTR_ADMIN_STATE]);
+ else
+ pr_info("No preemptible TSN_QBU_ATTR_ADMIN_STATE config!\n");
+
+ if (!tsnops->qbu_set) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EPERM);
+ return -EINVAL;
+ }
+
+ ret = tsnops->qbu_set(netdev, preemptible);
+ if (ret < 0) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, ret);
+ return ret;
+ }
+
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, 0);
+ return 0;
+}
+
+static int tsn_qbu_set(struct sk_buff *skb, struct genl_info *info)
+{
+ if (info->attrs[TSN_ATTR_IFNAME])
+ return cmd_qbu_set(info);
+
+ return -1;
+}
+
+static int cmd_qbu_get_status(struct genl_info *info)
+{
+ struct nlattr *qbuattr;
+ struct net_device *netdev;
+ const struct tsn_ops *tsnops;
+ struct sk_buff *rep_skb;
+ int ret;
+ struct genlmsghdr *genlhdr;
+ struct tsn_preempt_status pps;
+ struct tsn_port *port;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port)
+ return -ENODEV;
+
+ tsnops = port->tsnops;
+
+ /* Get status data from device */
+ genlhdr = info->genlhdr;
+
+ memset(&pps, 0, sizeof(struct tsn_preempt_status));
+
+ if (!tsnops->qbu_get) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EPERM);
+ return -1;
+ }
+
+ ret = tsnops->qbu_get(netdev, &pps);
+ if (ret < 0) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, ret);
+ return ret;
+ }
+
+ /* Form netlink reply data */
+ ret = tsn_prepare_reply(info, genlhdr->cmd,
+ &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE));
+ if (ret < 0)
+ return ret;
+
+ if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name))
+ return -EMSGSIZE;
+
+ qbuattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_QBU);
+ if (!qbuattr)
+ return -EMSGSIZE;
+
+ if (nla_put_u8(rep_skb, TSN_QBU_ATTR_ADMIN_STATE, pps.admin_state) ||
+ nla_put_u32(rep_skb,
+ TSN_QBU_ATTR_HOLD_ADVANCE, pps.hold_advance) ||
+ nla_put_u32(rep_skb,
+ TSN_QBU_ATTR_RELEASE_ADVANCE, pps.release_advance))
+ return -EMSGSIZE;
+
+ if (pps.preemption_active) {
+ if (nla_put_flag(rep_skb, TSN_QBU_ATTR_ACTIVE))
+ return -EMSGSIZE;
+ }
+
+ if (nla_put_u8(rep_skb, TSN_QBU_ATTR_HOLD_REQUEST, pps.hold_request))
+ return -EMSGSIZE;
+
+ nla_nest_end(rep_skb, qbuattr);
+
+ return tsn_send_reply(rep_skb, info);
+}
+
+static int tsn_qbu_get_status(struct sk_buff *skb, struct genl_info *info)
+{
+ if (info->attrs[TSN_ATTR_IFNAME])
+ return cmd_qbu_get_status(info);
+
+ return -1;
+}
+
+static int tsn_tsd_set(struct sk_buff *skb, struct genl_info *info)
+{
+ struct nlattr *na;
+ struct nlattr *ntsd[TSN_TSD_ATTR_MAX + 1];
+ struct net_device *netdev;
+ const struct tsn_ops *tsnops;
+ struct tsn_tsd tsd;
+ int ret;
+ struct tsn_port *port;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port)
+ return -ENODEV;
+
+ tsnops = port->tsnops;
+
+ memset(&tsd, 0, sizeof(struct tsn_tsd));
+
+ if (!info->attrs[TSN_ATTR_TSD]) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ na = info->attrs[TSN_ATTR_TSD];
+
+ ret = NLA_PARSE_NESTED(ntsd, TSN_TSD_ATTR_MAX, na, tsd_policy);
+ if (ret) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ if (!tsnops->tsd_set) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EPERM);
+ return -EINVAL;
+ }
+
+ if (nla_get_flag(ntsd[TSN_TSD_ATTR_DISABLE])) {
+ tsd.enable = false;
+ } else {
+ if (ntsd[TSN_TSD_ATTR_PERIOD])
+ tsd.period = nla_get_u32(ntsd[TSN_TSD_ATTR_PERIOD]);
+
+ if (!tsd.period) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ if (ntsd[TSN_TSD_ATTR_MAX_FRM_NUM])
+ tsd.maxFrameNum =
+ nla_get_u32(ntsd[TSN_TSD_ATTR_MAX_FRM_NUM]);
+
+ if (ntsd[TSN_TSD_ATTR_SYN_IMME])
+ tsd.syn_flag = 2;
+ else
+ tsd.syn_flag = 1;
+
+ tsd.enable = true;
+ }
+
+ ret = tsnops->tsd_set(netdev, &tsd);
+ if (ret < 0) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, ret);
+ return ret;
+ }
+
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, 0);
+ return 0;
+}
+
+static int tsn_tsd_get(struct sk_buff *skb, struct genl_info *info)
+{
+ struct nlattr *na, *tsdattr;
+ struct nlattr *tsda[TSN_TSD_ATTR_MAX + 1];
+ struct net_device *netdev;
+ const struct tsn_ops *tsnops;
+ struct sk_buff *rep_skb;
+ int ret;
+ struct genlmsghdr *genlhdr;
+ struct tsn_tsd_status tts;
+ struct tsn_port *port;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port)
+ return -ENODEV;
+
+ tsnops = port->tsnops;
+
+ if (!info->attrs[TSN_ATTR_TSD]) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ if (!tsnops->tsd_get) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EPERM);
+ return -1;
+ }
+
+ ret = tsnops->tsd_get(netdev, &tts);
+ if (ret < 0) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, ret);
+ return ret;
+ }
+
+ na = info->attrs[TSN_ATTR_TSD];
+
+ ret = NLA_PARSE_NESTED(tsda, TSN_TSD_ATTR_MAX,
+ na, tsd_policy);
+ if (ret) {
+ pr_err("tsn: parse value TSN_TSD_ATTR_MAX error.");
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ /* Get status data from device */
+ genlhdr = info->genlhdr;
+
+ /* Form netlink reply data */
+ ret = tsn_prepare_reply(info, genlhdr->cmd, &rep_skb,
+ NLMSG_ALIGN(MAX_ATTR_SIZE));
+ if (ret < 0)
+ return ret;
+
+ if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name))
+ return -EMSGSIZE;
+
+ tsdattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_TSD);
+ if (!tsdattr)
+ return -EMSGSIZE;
+
+ if (nla_put_u32(rep_skb, TSN_TSD_ATTR_PERIOD, tts.period) ||
+ nla_put_u32(rep_skb, TSN_TSD_ATTR_MAX_FRM_NUM, tts.maxFrameNum) ||
+ nla_put_u32(rep_skb, TSN_TSD_ATTR_CYCLE_NUM, tts.cycleNum) ||
+ nla_put_u32(rep_skb, TSN_TSD_ATTR_LOSS_STEPS, tts.loss_steps) ||
+ nla_put_u32(rep_skb, TSN_TSD_ATTR_MAX_FRM_NUM, tts.maxFrameNum))
+ return -EMSGSIZE;
+
+ if (!tts.enable) {
+ if (nla_put_flag(rep_skb, TSN_TSD_ATTR_DISABLE))
+ return -EMSGSIZE;
+ } else {
+ if (nla_put_flag(rep_skb, TSN_TSD_ATTR_ENABLE))
+ return -EMSGSIZE;
+ }
+
+ if (tts.flag == 2)
+ if (nla_put_flag(rep_skb, TSN_TSD_ATTR_SYN_IMME))
+ return -EMSGSIZE;
+
+ nla_nest_end(rep_skb, tsdattr);
+ return tsn_send_reply(rep_skb, info);
+}
+
+static int tsn_ct_set(struct sk_buff *skb, struct genl_info *info)
+{
+ struct nlattr *na;
+ struct nlattr *cta[TSN_CT_ATTR_MAX + 1];
+ struct net_device *netdev;
+ const struct tsn_ops *tsnops;
+ int ret;
+ u8 queue_stat;
+ struct tsn_port *port;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port)
+ return -ENODEV;
+
+ tsnops = port->tsnops;
+
+ if (!info->attrs[TSN_ATTR_CT]) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ na = info->attrs[TSN_ATTR_CT];
+
+ if (!tsnops->ct_set) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EPERM);
+ return -1;
+ }
+
+ ret = NLA_PARSE_NESTED(cta, TSN_CT_ATTR_MAX,
+ na, ct_policy);
+ if (ret) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ queue_stat = nla_get_u8(cta[TSN_CT_ATTR_QUEUE_STATE]);
+
+ ret = tsnops->ct_set(netdev, queue_stat);
+ if (ret < 0) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, ret);
+ return ret;
+ }
+
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, 0);
+ return 0;
+}
+
+static int tsn_cbgen_set(struct sk_buff *skb, struct genl_info *info)
+{
+ struct nlattr *na;
+ struct nlattr *cbgena[TSN_CBGEN_ATTR_MAX + 1];
+ struct net_device *netdev;
+ const struct tsn_ops *tsnops;
+ int ret;
+ u32 index;
+ struct tsn_seq_gen_conf sg_conf;
+ struct tsn_port *port;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port)
+ return -ENODEV;
+
+ tsnops = port->tsnops;
+
+ if (!info->attrs[TSN_ATTR_CBGEN]) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ na = info->attrs[TSN_ATTR_CBGEN];
+
+ if (!tsnops->cbgen_set) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EPERM);
+ return -1;
+ }
+
+ ret = NLA_PARSE_NESTED(cbgena, TSN_CBGEN_ATTR_MAX,
+ na, cbgen_policy);
+ if (ret) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ index = nla_get_u32(cbgena[TSN_CBGEN_ATTR_INDEX]);
+
+ memset(&sg_conf, 0, sizeof(struct tsn_seq_gen_conf));
+ sg_conf.iport_mask = nla_get_u8(cbgena[TSN_CBGEN_ATTR_PORT_MASK]);
+ sg_conf.split_mask = nla_get_u8(cbgena[TSN_CBGEN_ATTR_SPLIT_MASK]);
+ sg_conf.seq_len = nla_get_u8(cbgena[TSN_CBGEN_ATTR_SEQ_LEN]);
+ sg_conf.seq_num = nla_get_u32(cbgena[TSN_CBGEN_ATTR_SEQ_NUM]);
+
+ ret = tsnops->cbgen_set(netdev, index, &sg_conf);
+ if (ret < 0) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, ret);
+ return ret;
+ }
+
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, 0);
+ return 0;
+}
+
+static int tsn_cbrec_set(struct sk_buff *skb, struct genl_info *info)
+{
+ struct nlattr *na;
+ struct nlattr *cbreca[TSN_CBREC_ATTR_MAX + 1];
+ struct net_device *netdev;
+ const struct tsn_ops *tsnops;
+ int ret;
+ u32 index;
+ struct tsn_seq_rec_conf sr_conf;
+ struct tsn_port *port;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port)
+ return -ENODEV;
+
+ tsnops = port->tsnops;
+
+ if (!info->attrs[TSN_ATTR_CBREC]) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ na = info->attrs[TSN_ATTR_CBREC];
+
+ if (!tsnops->cbrec_set) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EPERM);
+ return -1;
+ }
+
+ ret = NLA_PARSE_NESTED(cbreca, TSN_CBREC_ATTR_MAX,
+ na, cbrec_policy);
+ if (ret) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ index = nla_get_u32(cbreca[TSN_CBREC_ATTR_INDEX]);
+
+ memset(&sr_conf, 0, sizeof(struct tsn_seq_rec_conf));
+ sr_conf.seq_len = nla_get_u8(cbreca[TSN_CBREC_ATTR_SEQ_LEN]);
+ sr_conf.his_len = nla_get_u8(cbreca[TSN_CBREC_ATTR_HIS_LEN]);
+ sr_conf.rtag_pop_en = nla_get_flag(cbreca[TSN_CBREC_ATTR_TAG_POP_EN]);
+
+ ret = tsnops->cbrec_set(netdev, index, &sr_conf);
+ if (ret < 0) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, ret);
+ return ret;
+ }
+
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, 0);
+ return 0;
+}
+
+static int tsn_cbstatus_get(struct sk_buff *skb, struct genl_info *info)
+{
+ struct nlattr *na;
+ struct nlattr *cba[TSN_CBSTAT_ATTR_MAX + 1];
+ struct nlattr *cbattr;
+ struct net_device *netdev;
+ const struct tsn_ops *tsnops;
+ struct sk_buff *rep_skb;
+ int ret;
+ unsigned int index;
+ struct genlmsghdr *genlhdr;
+ struct tsn_cb_status cbstat;
+ struct tsn_port *port;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port)
+ return -ENODEV;
+
+ tsnops = port->tsnops;
+
+ /* Get status data from device */
+ genlhdr = info->genlhdr;
+
+ memset(&cbstat, 0, sizeof(struct tsn_cb_status));
+
+ if (!tsnops->cb_get) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EPERM);
+ return -1;
+ }
+
+ na = info->attrs[TSN_ATTR_CBSTAT];
+ ret = NLA_PARSE_NESTED(cba, TSN_CBSTAT_ATTR_MAX,
+ na, cbstat_policy);
+ if (ret) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ index = nla_get_u32(cba[TSN_CBSTAT_ATTR_INDEX]);
+
+ ret = tsnops->cb_get(netdev, index, &cbstat);
+ if (ret < 0) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, ret);
+ return ret;
+ }
+
+ /* Form netlink reply data */
+ ret = tsn_prepare_reply(info, genlhdr->cmd,
+ &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE));
+ if (ret < 0)
+ return ret;
+
+ if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name))
+ return -EMSGSIZE;
+
+ cbattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_CBSTAT);
+ if (!cbattr)
+ return -EMSGSIZE;
+
+ if (nla_put_u8(rep_skb, TSN_CBSTAT_ATTR_GEN_REC, cbstat.gen_rec) ||
+ nla_put_u8(rep_skb, TSN_CBSTAT_ATTR_ERR, cbstat.err) ||
+ nla_put_u32(rep_skb, TSN_CBSTAT_ATTR_SEQ_NUM,
+ cbstat.seq_num) ||
+ nla_put_u8(rep_skb, TSN_CBSTAT_ATTR_SEQ_LEN, cbstat.seq_len) ||
+ nla_put_u8(rep_skb, TSN_CBSTAT_ATTR_SPLIT_MASK,
+ cbstat.split_mask) ||
+ nla_put_u8(rep_skb, TSN_CBSTAT_ATTR_PORT_MASK,
+ cbstat.iport_mask) ||
+ nla_put_u8(rep_skb, TSN_CBSTAT_ATTR_HIS_LEN, cbstat.his_len) ||
+ nla_put_u32(rep_skb, TSN_CBSTAT_ATTR_SEQ_HIS,
+ cbstat.seq_his))
+ return -EMSGSIZE;
+
+ nla_nest_end(rep_skb, cbattr);
+
+ return tsn_send_reply(rep_skb, info);
+}
+
+static int tsn_dscp_set(struct sk_buff *skb, struct genl_info *info)
+{
+ struct nlattr *na;
+ struct nlattr *dscpa[TSN_DSCP_ATTR_MAX + 1];
+ struct net_device *netdev;
+ const struct tsn_ops *tsnops;
+ int ret;
+ bool enable = 0;
+ struct tsn_port *port;
+ int dscp_ix;
+ struct tsn_qos_switch_dscp_conf dscp_conf;
+
+ port = tsn_init_check(info, &netdev);
+ if (!port)
+ return -ENODEV;
+
+ tsnops = port->tsnops;
+
+ if (!info->attrs[TSN_ATTR_DSCP]) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ na = info->attrs[TSN_ATTR_DSCP];
+
+ if (!tsnops->dscp_set) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EPERM);
+ return -1;
+ }
+
+ ret = NLA_PARSE_NESTED(dscpa, TSN_DSCP_ATTR_MAX,
+ na, dscp_policy);
+ if (ret) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, -EINVAL);
+ return -EINVAL;
+ }
+
+ enable = 1;
+ if (dscpa[TSN_DSCP_ATTR_DISABLE])
+ enable = 0;
+ dscp_ix = nla_get_u32(dscpa[TSN_DSCP_ATTR_INDEX]);
+ dscp_conf.cos = nla_get_u32(dscpa[TSN_DSCP_ATTR_COS]);
+ dscp_conf.dpl = nla_get_u32(dscpa[TSN_DSCP_ATTR_DPL]);
+ ret = tsnops->dscp_set(netdev, enable, dscp_ix, &dscp_conf);
+ if (ret < 0) {
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, ret);
+ return ret;
+ }
+
+ tsn_simple_reply(info, TSN_CMD_REPLY,
+ netdev->name, 0);
+
+ return 0;
+}
+
+static const struct genl_ops tsnnl_ops[] = {
+ {
+ .cmd = TSN_CMD_ECHO,
+ .doit = tsn_echo_cmd,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_CAP_GET,
+ .doit = tsn_cap_get,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_QBV_SET,
+ .doit = tsn_qbv_set,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_QBV_GET,
+ .doit = tsn_qbv_get,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_QBV_GET_STATUS,
+ .doit = tsn_qbv_status_get,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_CB_STREAMID_SET,
+ .doit = tsn_cb_streamid_set,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_CB_STREAMID_GET,
+ .doit = tsn_cb_streamid_get,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_CB_STREAMID_GET_COUNTS,
+ .doit = tsn_cb_streamid_counters_get,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_QCI_CAP_GET,
+ .doit = tsn_qci_cap_get,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_QCI_SFI_SET,
+ .doit = tsn_qci_sfi_set,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_QCI_SFI_GET,
+ .doit = tsn_qci_sfi_get,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_QCI_SFI_GET_COUNTS,
+ .doit = tsn_qci_sfi_counters_get,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_QCI_SGI_SET,
+ .doit = tsn_qci_sgi_set,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_QCI_SGI_GET,
+ .doit = tsn_qci_sgi_get,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_QCI_SGI_GET_STATUS,
+ .doit = tsn_qci_sgi_status_get,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_QCI_FMI_SET,
+ .doit = tsn_qci_fmi_set,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_QCI_FMI_GET,
+ .doit = tsn_qci_fmi_get,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_CBS_SET,
+ .doit = tsn_cbs_set,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_CBS_GET,
+ .doit = tsn_cbs_get,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_QBU_SET,
+ .doit = tsn_qbu_set,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_QBU_GET_STATUS,
+ .doit = tsn_qbu_get_status,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_TSD_SET,
+ .doit = tsn_tsd_set,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_TSD_GET,
+ .doit = tsn_tsd_get,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_CT_SET,
+ .doit = tsn_ct_set,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_CBGEN_SET,
+ .doit = tsn_cbgen_set,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_CBREC_SET,
+ .doit = tsn_cbrec_set,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_CBSTAT_GET,
+ .doit = tsn_cbstatus_get,
+ .flags = GENL_ADMIN_PERM,
+ },
+ {
+ .cmd = TSN_CMD_DSCP_SET,
+ .doit = tsn_dscp_set,
+ .flags = GENL_ADMIN_PERM,
+ },
+};
+
+static const struct genl_multicast_group tsn_mcgrps[] = {
+ [TSN_MCGRP_QBV] = { .name = TSN_MULTICAST_GROUP_QBV},
+ [TSN_MCGRP_QCI] = { .name = TSN_MULTICAST_GROUP_QCI},
+};
+
+static struct genl_family tsn_family = {
+ .name = TSN_GENL_NAME,
+ .version = TSN_GENL_VERSION,
+ .maxattr = TSN_CMD_ATTR_MAX,
+ .module = THIS_MODULE,
+ .netnsok = true,
+ .ops = tsnnl_ops,
+ .n_ops = ARRAY_SIZE(tsnnl_ops),
+ .mcgrps = tsn_mcgrps,
+ .n_mcgrps = ARRAY_SIZE(tsn_mcgrps),
+};
+
+int tsn_port_register(struct net_device *netdev,
+ struct tsn_ops *tsnops, u16 groupid)
+{
+ struct tsn_port *port;
+
+ if (list_empty(&port_list)) {
+ INIT_LIST_HEAD(&port_list);
+ } else {
+ list_for_each_entry(port, &port_list, list) {
+ if (port->netdev == netdev) {
+ pr_info("TSN device already registered!\n");
+ return -1;
+ }
+ }
+ }
+
+ port = kzalloc(sizeof(*port), GFP_KERNEL);
+ if (!port)
+ return -1;
+
+ port->netdev = netdev;
+ port->groupid = groupid;
+ port->tsnops = tsnops;
+ port->nd.dev = netdev;
+
+ if (groupid < GROUP_OFFSET_SWITCH)
+ port->type = TSN_ENDPOINT;
+ else
+ port->type = TSN_SWITCH;
+
+ list_add_tail(&port->list, &port_list);
+
+ if (tsnops && tsnops->device_init)
+ port->tsnops->device_init(netdev);
+
+ return 0;
+}
+EXPORT_SYMBOL(tsn_port_register);
+
+void tsn_port_unregister(struct net_device *netdev)
+{
+ struct tsn_port *p;
+
+ list_for_each_entry(p, &port_list, list) {
+ if (!p || !p->netdev)
+ continue;
+ if (p->netdev == netdev) {
+ if (p->tsnops->device_deinit)
+ p->tsnops->device_deinit(netdev);
+ list_del(&p->list);
+ kfree(p);
+ break;
+ }
+ }
+}
+EXPORT_SYMBOL(tsn_port_unregister);
+
+static int tsn_multicast_to_user(unsigned long event,
+ struct tsn_notifier_info *tsn_info)
+{
+ struct sk_buff *skb;
+ struct genlmsghdr *nlh;
+ int res;
+ struct tsn_qbv_conf *qbvdata;
+
+ /* If new attributes are added, please revisit this allocation */
+ skb = genlmsg_new(sizeof(*tsn_info), GFP_KERNEL);
+ if (!skb) {
+ pr_err("Allocation failure.\n");
+ return -ENOMEM;
+ }
+
+ switch (event) {
+ case TSN_QBV_CONFIGCHANGETIME_ARRIVE:
+ nlh = genlmsg_put(skb, 0, 1, &tsn_family,
+ GFP_KERNEL, TSN_CMD_QBV_SET);
+ qbvdata = &tsn_info->ntdata.qbv_notify;
+ res = NLA_PUT_U64(skb, TSN_QBV_ATTR_CTRL_BASETIME,
+ qbvdata->admin.base_time);
+
+ if (res) {
+ pr_err("put data failure!\n");
+ goto done;
+ }
+
+ res = nla_put_u32(skb, TSN_QBV_ATTR_CTRL_CYCLETIME,
+ qbvdata->admin.cycle_time);
+ if (res) {
+ pr_err("put data failure!\n");
+ goto done;
+ }
+
+ if (qbvdata->gate_enabled)
+ res = nla_put_flag(skb, TSN_QBV_ATTR_ENABLE +
+ TSN_QBV_ATTR_CTRL_MAX);
+ else
+ res = nla_put_flag(skb, TSN_QBV_ATTR_DISABLE +
+ TSN_QBV_ATTR_CTRL_MAX);
+ if (res) {
+ pr_err("put data failure!\n");
+ goto done;
+ }
+
+ res = nla_put_u32(skb, TSN_QBV_ATTR_CTRL_UNSPEC,
+ tsn_info->dev->ifindex);
+ if (res) {
+ pr_err("put data failure!\n");
+ goto done;
+ }
+
+ break;
+ default:
+ pr_info("event not supportted!\n");
+ break;
+ }
+
+ (void)genlmsg_end(skb, nlh);
+
+ res = genlmsg_multicast_allns(&tsn_family, skb, 0,
+ TSN_MCGRP_QBV, GFP_KERNEL);
+ skb = NULL;
+ if (res && res != -ESRCH) {
+ pr_err("genlmsg_multicast_allns error: %d\n", res);
+ goto done;
+ }
+
+ if (res == -ESRCH)
+ res = 0;
+
+done:
+ if (skb) {
+ nlmsg_free(skb);
+ skb = NULL;
+ }
+
+ return res;
+}
+
+/* called with RTNL or RCU */
+static int tsn_event(struct notifier_block *unused,
+ unsigned long event, void *ptr)
+{
+ struct tsn_notifier_info *tsn_info;
+ int err = NOTIFY_DONE;
+
+ switch (event) {
+ case TSN_QBV_CONFIGCHANGETIME_ARRIVE:
+ tsn_info = ptr;
+ err = tsn_multicast_to_user(event, tsn_info);
+ if (err) {
+ err = notifier_from_errno(err);
+ break;
+ }
+ break;
+ default:
+ pr_info("event not supportted!\n");
+ break;
+ }
+
+ return err;
+}
+
+static struct notifier_block tsn_notifier = {
+ .notifier_call = tsn_event,
+};
+
+static int __init tsn_genetlink_init(void)
+{
+ int ret;
+
+ pr_info("tsn generic netlink module v%d init...\n", TSN_GENL_VERSION);
+
+ ret = genl_register_family(&tsn_family);
+
+ if (ret != 0) {
+ pr_info("failed to init tsn generic netlink example module\n");
+ return ret;
+ }
+
+ register_tsn_notifier(&tsn_notifier);
+
+ return 0;
+}
+
+static void __exit tsn_genetlink_exit(void)
+{
+ int ret;
+
+ ret = genl_unregister_family(&tsn_family);
+ if (ret != 0)
+ pr_info("failed to unregister family:%i\n", ret);
+
+ unregister_tsn_notifier(&tsn_notifier);
+}
+
+module_init(tsn_genetlink_init);
+module_exit(tsn_genetlink_exit);
+MODULE_LICENSE("GPL");
|