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
|
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright 2008 Cisco Systems, Inc. All rights reserved.
* Copyright 2007 Nuova Systems, Inc. All rights reserved.
*/
#include <linux/workqueue.h>
#include "fnic.h"
#include "fdls_fc.h"
#include "fnic_fdls.h"
#include <scsi/fc/fc_fcp.h>
#include <scsi/scsi_transport_fc.h>
#include <linux/utsname.h>
#define FC_FC4_TYPE_SCSI 0x08
#define PORT_SPEED_BIT_8 8
#define PORT_SPEED_BIT_9 9
#define PORT_SPEED_BIT_14 14
#define PORT_SPEED_BIT_15 15
/* FNIC FDMI Register HBA Macros */
#define FNIC_FDMI_NUM_PORTS 1
#define FNIC_FDMI_NUM_HBA_ATTRS 9
#define FNIC_FDMI_TYPE_NODE_NAME 0X1
#define FNIC_FDMI_TYPE_MANUFACTURER 0X2
#define FNIC_FDMI_MANUFACTURER "Cisco Systems"
#define FNIC_FDMI_TYPE_SERIAL_NUMBER 0X3
#define FNIC_FDMI_TYPE_MODEL 0X4
#define FNIC_FDMI_TYPE_MODEL_DES 0X5
#define FNIC_FDMI_MODEL_DESCRIPTION "Cisco Virtual Interface Card"
#define FNIC_FDMI_TYPE_HARDWARE_VERSION 0X6
#define FNIC_FDMI_TYPE_DRIVER_VERSION 0X7
#define FNIC_FDMI_TYPE_ROM_VERSION 0X8
#define FNIC_FDMI_TYPE_FIRMWARE_VERSION 0X9
#define FNIC_FDMI_NN_LEN 8
#define FNIC_FDMI_MANU_LEN 20
#define FNIC_FDMI_SERIAL_LEN 16
#define FNIC_FDMI_MODEL_LEN 12
#define FNIC_FDMI_MODEL_DES_LEN 56
#define FNIC_FDMI_HW_VER_LEN 16
#define FNIC_FDMI_DR_VER_LEN 28
#define FNIC_FDMI_ROM_VER_LEN 8
#define FNIC_FDMI_FW_VER_LEN 16
/* FNIC FDMI Register PA Macros */
#define FNIC_FDMI_TYPE_FC4_TYPES 0X1
#define FNIC_FDMI_TYPE_SUPPORTED_SPEEDS 0X2
#define FNIC_FDMI_TYPE_CURRENT_SPEED 0X3
#define FNIC_FDMI_TYPE_MAX_FRAME_SIZE 0X4
#define FNIC_FDMI_TYPE_OS_NAME 0X5
#define FNIC_FDMI_TYPE_HOST_NAME 0X6
#define FNIC_FDMI_NUM_PORT_ATTRS 6
#define FNIC_FDMI_FC4_LEN 32
#define FNIC_FDMI_SUPP_SPEED_LEN 4
#define FNIC_FDMI_CUR_SPEED_LEN 4
#define FNIC_FDMI_MFS_LEN 4
#define FNIC_FDMI_MFS 0x800
#define FNIC_FDMI_OS_NAME_LEN 16
#define FNIC_FDMI_HN_LEN 24
#define FDLS_FDMI_PLOGI_PENDING 0x1
#define FDLS_FDMI_REG_HBA_PENDING 0x2
#define FDLS_FDMI_RPA_PENDING 0x4
#define FDLS_FDMI_ABORT_PENDING 0x8
#define FDLS_FDMI_MAX_RETRY 3
#define RETRIES_EXHAUSTED(iport) \
(iport->fabric.retry_counter == FABRIC_LOGO_MAX_RETRY)
#define FNIC_TPORT_MAX_NEXUS_RESTART (8)
#define SCHEDULE_OXID_FREE_RETRY_TIME (300)
/* Private Functions */
static void fdls_fdmi_register_hba(struct fnic_iport_s *iport);
static void fdls_fdmi_register_pa(struct fnic_iport_s *iport);
static void fdls_send_rpn_id(struct fnic_iport_s *iport);
static void fdls_process_flogi_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr,
void *rx_frame);
static void fnic_fdls_start_plogi(struct fnic_iport_s *iport);
static void fnic_fdls_start_flogi(struct fnic_iport_s *iport);
static struct fnic_tport_s *fdls_create_tport(struct fnic_iport_s *iport,
uint32_t fcid,
uint64_t wwpn);
static void fdls_target_restart_nexus(struct fnic_tport_s *tport);
static void fdls_start_tport_timer(struct fnic_iport_s *iport,
struct fnic_tport_s *tport, int timeout);
static void fdls_tport_timer_callback(struct timer_list *t);
static void fdls_send_fdmi_plogi(struct fnic_iport_s *iport);
static void fdls_start_fabric_timer(struct fnic_iport_s *iport,
int timeout);
static void fdls_init_plogi_frame(uint8_t *frame, struct fnic_iport_s *iport);
static void fdls_init_els_acc_frame(uint8_t *frame, struct fnic_iport_s *iport);
static void fdls_init_els_rjt_frame(uint8_t *frame, struct fnic_iport_s *iport);
static void fdls_init_logo_frame(uint8_t *frame, struct fnic_iport_s *iport);
static void fdls_init_fabric_abts_frame(uint8_t *frame,
struct fnic_iport_s *iport);
uint8_t *fdls_alloc_frame(struct fnic_iport_s *iport)
{
struct fnic *fnic = iport->fnic;
uint8_t *frame = NULL;
frame = mempool_alloc(fnic->frame_pool, GFP_ATOMIC);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame");
return NULL;
}
memset(frame, 0, FNIC_FCOE_FRAME_MAXSZ);
return frame;
}
/**
* fdls_alloc_oxid - Allocate an oxid from the bitmap based oxid pool
* @iport: Handle to iport instance
* @oxid_frame_type: Type of frame to allocate
* @active_oxid: the oxid which is in use
*
* Called with fnic lock held
*/
uint16_t fdls_alloc_oxid(struct fnic_iport_s *iport, int oxid_frame_type,
uint16_t *active_oxid)
{
struct fnic *fnic = iport->fnic;
struct fnic_oxid_pool_s *oxid_pool = &iport->oxid_pool;
int idx;
uint16_t oxid;
lockdep_assert_held(&fnic->fnic_lock);
/*
* Allocate next available oxid from bitmap
*/
idx = find_next_zero_bit(oxid_pool->bitmap, FNIC_OXID_POOL_SZ, oxid_pool->next_idx);
if (idx == FNIC_OXID_POOL_SZ) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Alloc oxid: all oxid slots are busy iport state:%d\n",
iport->state);
return FNIC_UNASSIGNED_OXID;
}
WARN_ON(test_and_set_bit(idx, oxid_pool->bitmap));
oxid_pool->next_idx = (idx + 1) % FNIC_OXID_POOL_SZ; /* cycle through the bitmap */
oxid = FNIC_OXID_ENCODE(idx, oxid_frame_type);
*active_oxid = oxid;
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"alloc oxid: 0x%x, iport state: %d\n",
oxid, iport->state);
return oxid;
}
/**
* fdls_free_oxid_idx - Free the oxid using the idx
* @iport: Handle to iport instance
* @oxid_idx: The index to free
*
* Free the oxid immediately and make it available for new requests
* Called with fnic lock held
*/
static void fdls_free_oxid_idx(struct fnic_iport_s *iport, uint16_t oxid_idx)
{
struct fnic *fnic = iport->fnic;
struct fnic_oxid_pool_s *oxid_pool = &iport->oxid_pool;
lockdep_assert_held(&fnic->fnic_lock);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"free oxid idx: 0x%x\n", oxid_idx);
WARN_ON(!test_and_clear_bit(oxid_idx, oxid_pool->bitmap));
}
/**
* fdls_reclaim_oxid_handler - Callback handler for delayed_oxid_work
* @work: Handle to work_struct
*
* Scheduled when an oxid is to be freed later
* After freeing expired oxid(s), the handler schedules
* another callback with the remaining time
* of next unexpired entry in the reclaim list.
*/
void fdls_reclaim_oxid_handler(struct work_struct *work)
{
struct fnic_oxid_pool_s *oxid_pool = container_of(work,
struct fnic_oxid_pool_s, oxid_reclaim_work.work);
struct fnic_iport_s *iport = container_of(oxid_pool,
struct fnic_iport_s, oxid_pool);
struct fnic *fnic = iport->fnic;
struct reclaim_entry_s *reclaim_entry, *next;
unsigned long delay_j, cur_jiffies;
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Reclaim oxid callback\n");
spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags);
/* Though the work was scheduled for one entry,
* walk through and free the expired entries which might have been scheduled
* at around the same time as the first entry
*/
list_for_each_entry_safe(reclaim_entry, next,
&(oxid_pool->oxid_reclaim_list), links) {
/* The list is always maintained in the order of expiry time */
cur_jiffies = jiffies;
if (time_before(cur_jiffies, reclaim_entry->expires))
break;
list_del(&reclaim_entry->links);
fdls_free_oxid_idx(iport, reclaim_entry->oxid_idx);
kfree(reclaim_entry);
}
/* schedule to free up the next entry */
if (!list_empty(&oxid_pool->oxid_reclaim_list)) {
reclaim_entry = list_first_entry(&oxid_pool->oxid_reclaim_list,
struct reclaim_entry_s, links);
delay_j = reclaim_entry->expires - cur_jiffies;
schedule_delayed_work(&oxid_pool->oxid_reclaim_work, delay_j);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Scheduling next callback at:%ld jiffies\n", delay_j);
}
spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
}
/**
* fdls_free_oxid - Helper function to free the oxid
* @iport: Handle to iport instance
* @oxid: oxid to free
* @active_oxid: the oxid which is in use
*
* Called with fnic lock held
*/
void fdls_free_oxid(struct fnic_iport_s *iport,
uint16_t oxid, uint16_t *active_oxid)
{
fdls_free_oxid_idx(iport, FNIC_OXID_IDX(oxid));
*active_oxid = FNIC_UNASSIGNED_OXID;
}
/**
* fdls_schedule_oxid_free - Schedule oxid to be freed later
* @iport: Handle to iport instance
* @active_oxid: the oxid which is in use
*
* Gets called in a rare case scenario when both a command
* (fdls or target discovery) timed out and the following ABTS
* timed out as well, without a link change.
*
* Called with fnic lock held
*/
void fdls_schedule_oxid_free(struct fnic_iport_s *iport, uint16_t *active_oxid)
{
struct fnic *fnic = iport->fnic;
struct fnic_oxid_pool_s *oxid_pool = &iport->oxid_pool;
struct reclaim_entry_s *reclaim_entry;
unsigned long delay_j = msecs_to_jiffies(OXID_RECLAIM_TOV(iport));
int oxid_idx = FNIC_OXID_IDX(*active_oxid);
lockdep_assert_held(&fnic->fnic_lock);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Schedule oxid free. oxid: 0x%x\n", *active_oxid);
*active_oxid = FNIC_UNASSIGNED_OXID;
reclaim_entry = (struct reclaim_entry_s *)
kzalloc(sizeof(struct reclaim_entry_s), GFP_ATOMIC);
if (!reclaim_entry) {
FNIC_FCS_DBG(KERN_WARNING, fnic->host, fnic->fnic_num,
"Failed to allocate memory for reclaim struct for oxid idx: %d\n",
oxid_idx);
/* Retry the scheduling */
WARN_ON(test_and_set_bit(oxid_idx, oxid_pool->pending_schedule_free));
schedule_delayed_work(&oxid_pool->schedule_oxid_free_retry, 0);
return;
}
reclaim_entry->oxid_idx = oxid_idx;
reclaim_entry->expires = round_jiffies(jiffies + delay_j);
list_add_tail(&reclaim_entry->links, &oxid_pool->oxid_reclaim_list);
schedule_delayed_work(&oxid_pool->oxid_reclaim_work, delay_j);
}
/**
* fdls_schedule_oxid_free_retry_work - Thread to schedule the
* oxid to be freed later
*
* @work: Handle to the work struct
*/
void fdls_schedule_oxid_free_retry_work(struct work_struct *work)
{
struct fnic_oxid_pool_s *oxid_pool = container_of(work,
struct fnic_oxid_pool_s, schedule_oxid_free_retry.work);
struct fnic_iport_s *iport = container_of(oxid_pool,
struct fnic_iport_s, oxid_pool);
struct fnic *fnic = iport->fnic;
struct reclaim_entry_s *reclaim_entry;
unsigned long delay_j = msecs_to_jiffies(OXID_RECLAIM_TOV(iport));
unsigned long flags;
int idx;
for_each_set_bit(idx, oxid_pool->pending_schedule_free, FNIC_OXID_POOL_SZ) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Schedule oxid free. oxid idx: %d\n", idx);
reclaim_entry = kzalloc(sizeof(*reclaim_entry), GFP_KERNEL);
if (!reclaim_entry) {
schedule_delayed_work(&oxid_pool->schedule_oxid_free_retry,
msecs_to_jiffies(SCHEDULE_OXID_FREE_RETRY_TIME));
return;
}
clear_bit(idx, oxid_pool->pending_schedule_free);
reclaim_entry->oxid_idx = idx;
reclaim_entry->expires = round_jiffies(jiffies + delay_j);
spin_lock_irqsave(&fnic->fnic_lock, flags);
list_add_tail(&reclaim_entry->links, &oxid_pool->oxid_reclaim_list);
spin_unlock_irqrestore(&fnic->fnic_lock, flags);
schedule_delayed_work(&oxid_pool->oxid_reclaim_work, delay_j);
}
}
static bool fdls_is_oxid_fabric_req(uint16_t oxid)
{
int oxid_frame_type = FNIC_FRAME_TYPE(oxid);
switch (oxid_frame_type) {
case FNIC_FRAME_TYPE_FABRIC_FLOGI:
case FNIC_FRAME_TYPE_FABRIC_PLOGI:
case FNIC_FRAME_TYPE_FABRIC_RPN:
case FNIC_FRAME_TYPE_FABRIC_RFT:
case FNIC_FRAME_TYPE_FABRIC_RFF:
case FNIC_FRAME_TYPE_FABRIC_GPN_FT:
case FNIC_FRAME_TYPE_FABRIC_LOGO:
break;
default:
return false;
}
return true;
}
static bool fdls_is_oxid_fdmi_req(uint16_t oxid)
{
int oxid_frame_type = FNIC_FRAME_TYPE(oxid);
switch (oxid_frame_type) {
case FNIC_FRAME_TYPE_FDMI_PLOGI:
case FNIC_FRAME_TYPE_FDMI_RHBA:
case FNIC_FRAME_TYPE_FDMI_RPA:
break;
default:
return false;
}
return true;
}
static bool fdls_is_oxid_tgt_req(uint16_t oxid)
{
int oxid_frame_type = FNIC_FRAME_TYPE(oxid);
switch (oxid_frame_type) {
case FNIC_FRAME_TYPE_TGT_PLOGI:
case FNIC_FRAME_TYPE_TGT_PRLI:
case FNIC_FRAME_TYPE_TGT_ADISC:
case FNIC_FRAME_TYPE_TGT_LOGO:
break;
default:
return false;
}
return true;
}
static void fdls_reset_oxid_pool(struct fnic_iport_s *iport)
{
struct fnic_oxid_pool_s *oxid_pool = &iport->oxid_pool;
oxid_pool->next_idx = 0;
}
void fnic_del_fabric_timer_sync(struct fnic *fnic)
{
fnic->iport.fabric.del_timer_inprogress = 1;
spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
timer_delete_sync(&fnic->iport.fabric.retry_timer);
spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags);
fnic->iport.fabric.del_timer_inprogress = 0;
}
void fnic_del_tport_timer_sync(struct fnic *fnic,
struct fnic_tport_s *tport)
{
tport->del_timer_inprogress = 1;
spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
timer_delete_sync(&tport->retry_timer);
spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags);
tport->del_timer_inprogress = 0;
}
static void
fdls_start_fabric_timer(struct fnic_iport_s *iport, int timeout)
{
u64 fabric_tov;
struct fnic *fnic = iport->fnic;
if (iport->fabric.timer_pending) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"iport fcid: 0x%x: Canceling fabric disc timer\n",
iport->fcid);
fnic_del_fabric_timer_sync(fnic);
iport->fabric.timer_pending = 0;
}
if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED))
iport->fabric.retry_counter++;
fabric_tov = jiffies + msecs_to_jiffies(timeout);
mod_timer(&iport->fabric.retry_timer, round_jiffies(fabric_tov));
iport->fabric.timer_pending = 1;
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"fabric timer is %d ", timeout);
}
static void
fdls_start_tport_timer(struct fnic_iport_s *iport,
struct fnic_tport_s *tport, int timeout)
{
u64 fabric_tov;
struct fnic *fnic = iport->fnic;
if (tport->timer_pending) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"tport fcid 0x%x: Canceling disc timer\n",
tport->fcid);
fnic_del_tport_timer_sync(fnic, tport);
tport->timer_pending = 0;
}
if (!(tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED))
tport->retry_counter++;
fabric_tov = jiffies + msecs_to_jiffies(timeout);
mod_timer(&tport->retry_timer, round_jiffies(fabric_tov));
tport->timer_pending = 1;
}
void fdls_init_plogi_frame(uint8_t *frame,
struct fnic_iport_s *iport)
{
struct fc_std_flogi *pplogi;
uint8_t s_id[3];
pplogi = (struct fc_std_flogi *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
*pplogi = (struct fc_std_flogi) {
.fchdr = {.fh_r_ctl = FC_RCTL_ELS_REQ, .fh_d_id = {0xFF, 0xFF, 0xFC},
.fh_type = FC_TYPE_ELS, .fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0},
.fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)},
.els = {
.fl_cmd = ELS_PLOGI,
.fl_csp = {.sp_hi_ver = FNIC_FC_PH_VER_HI,
.sp_lo_ver = FNIC_FC_PH_VER_LO,
.sp_bb_cred = cpu_to_be16(FNIC_FC_B2B_CREDIT),
.sp_features = cpu_to_be16(FC_SP_FT_CIRO),
.sp_bb_data = cpu_to_be16(FNIC_FC_B2B_RDF_SZ),
.sp_tot_seq = cpu_to_be16(FNIC_FC_CONCUR_SEQS),
.sp_rel_off = cpu_to_be16(FNIC_FC_RO_INFO),
.sp_e_d_tov = cpu_to_be32(FC_DEF_E_D_TOV)},
.fl_cssp[2].cp_class = cpu_to_be16(FC_CPC_VALID | FC_CPC_SEQ),
.fl_cssp[2].cp_rdfs = cpu_to_be16(0x800),
.fl_cssp[2].cp_con_seq = cpu_to_be16(0xFF),
.fl_cssp[2].cp_open_seq = 1}
};
FNIC_STD_SET_NPORT_NAME(&pplogi->els.fl_wwpn, iport->wwpn);
FNIC_STD_SET_NODE_NAME(&pplogi->els.fl_wwnn, iport->wwnn);
FNIC_LOGI_SET_RDF_SIZE(pplogi->els, iport->max_payload_size);
hton24(s_id, iport->fcid);
FNIC_STD_SET_S_ID(pplogi->fchdr, s_id);
}
static void fdls_init_els_acc_frame(uint8_t *frame,
struct fnic_iport_s *iport)
{
struct fc_std_els_acc_rsp *pels_acc;
uint8_t s_id[3];
pels_acc = (struct fc_std_els_acc_rsp *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
*pels_acc = (struct fc_std_els_acc_rsp) {
.fchdr = {.fh_r_ctl = FC_RCTL_ELS_REP,
.fh_type = FC_TYPE_ELS, .fh_f_ctl = {FNIC_ELS_REP_FCTL, 0, 0}},
.acc.la_cmd = ELS_LS_ACC,
};
hton24(s_id, iport->fcid);
FNIC_STD_SET_S_ID(pels_acc->fchdr, s_id);
FNIC_STD_SET_RX_ID(pels_acc->fchdr, FNIC_UNASSIGNED_RXID);
}
static void fdls_init_els_rjt_frame(uint8_t *frame,
struct fnic_iport_s *iport)
{
struct fc_std_els_rjt_rsp *pels_rjt;
pels_rjt = (struct fc_std_els_rjt_rsp *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
*pels_rjt = (struct fc_std_els_rjt_rsp) {
.fchdr = {.fh_r_ctl = FC_RCTL_ELS_REP, .fh_type = FC_TYPE_ELS,
.fh_f_ctl = {FNIC_ELS_REP_FCTL, 0, 0}},
.rej.er_cmd = ELS_LS_RJT,
};
FNIC_STD_SET_RX_ID(pels_rjt->fchdr, FNIC_UNASSIGNED_RXID);
}
static void fdls_init_logo_frame(uint8_t *frame,
struct fnic_iport_s *iport)
{
struct fc_std_logo *plogo;
uint8_t s_id[3];
plogo = (struct fc_std_logo *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
*plogo = (struct fc_std_logo) {
.fchdr = {.fh_r_ctl = FC_RCTL_ELS_REQ, .fh_type = FC_TYPE_ELS,
.fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0}},
.els.fl_cmd = ELS_LOGO,
};
hton24(s_id, iport->fcid);
FNIC_STD_SET_S_ID(plogo->fchdr, s_id);
memcpy(plogo->els.fl_n_port_id, s_id, 3);
FNIC_STD_SET_NPORT_NAME(&plogo->els.fl_n_port_wwn,
iport->wwpn);
}
static void fdls_init_fabric_abts_frame(uint8_t *frame,
struct fnic_iport_s *iport)
{
struct fc_frame_header *pfabric_abts;
pfabric_abts = (struct fc_frame_header *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
*pfabric_abts = (struct fc_frame_header) {
.fh_r_ctl = FC_RCTL_BA_ABTS, /* ABTS */
.fh_s_id = {0x00, 0x00, 0x00},
.fh_cs_ctl = 0x00, .fh_type = FC_TYPE_BLS,
.fh_f_ctl = {FNIC_REQ_ABTS_FCTL, 0, 0}, .fh_seq_id = 0x00,
.fh_df_ctl = 0x00, .fh_seq_cnt = 0x0000,
.fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID),
.fh_parm_offset = 0x00000000, /* bit:0 = 0 Abort a exchange */
};
}
static void
fdls_send_rscn_resp(struct fnic_iport_s *iport,
struct fc_frame_header *rscn_fchdr)
{
uint8_t *frame;
struct fc_std_els_acc_rsp *pels_acc;
struct fnic *fnic = iport->fnic;
uint16_t oxid;
uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
sizeof(struct fc_std_els_acc_rsp);
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame to send RSCN response");
return;
}
pels_acc = (struct fc_std_els_acc_rsp *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
fdls_init_els_acc_frame(frame, iport);
FNIC_STD_SET_D_ID(pels_acc->fchdr, rscn_fchdr->fh_s_id);
oxid = FNIC_STD_GET_OX_ID(rscn_fchdr);
FNIC_STD_SET_OX_ID(pels_acc->fchdr, oxid);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS send RSCN response with oxid: 0x%x",
iport->fcid, oxid);
fnic_send_fcoe_frame(iport, frame, frame_size);
}
static void
fdls_send_logo_resp(struct fnic_iport_s *iport,
struct fc_frame_header *req_fchdr)
{
uint8_t *frame;
struct fc_std_els_acc_rsp *plogo_resp;
struct fnic *fnic = iport->fnic;
uint16_t oxid;
uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
sizeof(struct fc_std_els_acc_rsp);
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame to send LOGO response");
return;
}
plogo_resp = (struct fc_std_els_acc_rsp *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
fdls_init_els_acc_frame(frame, iport);
FNIC_STD_SET_D_ID(plogo_resp->fchdr, req_fchdr->fh_s_id);
oxid = FNIC_STD_GET_OX_ID(req_fchdr);
FNIC_STD_SET_OX_ID(plogo_resp->fchdr, oxid);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS send LOGO response with oxid: 0x%x",
iport->fcid, oxid);
fnic_send_fcoe_frame(iport, frame, frame_size);
}
void
fdls_send_tport_abts(struct fnic_iport_s *iport,
struct fnic_tport_s *tport)
{
uint8_t *frame;
uint8_t s_id[3];
uint8_t d_id[3];
struct fnic *fnic = iport->fnic;
struct fc_frame_header *ptport_abts;
uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
sizeof(struct fc_frame_header);
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame to send tport ABTS");
return;
}
ptport_abts = (struct fc_frame_header *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
*ptport_abts = (struct fc_frame_header) {
.fh_r_ctl = FC_RCTL_BA_ABTS, /* ABTS */
.fh_cs_ctl = 0x00, .fh_type = FC_TYPE_BLS,
.fh_f_ctl = {FNIC_REQ_ABTS_FCTL, 0, 0}, .fh_seq_id = 0x00,
.fh_df_ctl = 0x00, .fh_seq_cnt = 0x0000,
.fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID),
.fh_parm_offset = 0x00000000, /* bit:0 = 0 Abort a exchange */
};
hton24(s_id, iport->fcid);
hton24(d_id, tport->fcid);
FNIC_STD_SET_S_ID(*ptport_abts, s_id);
FNIC_STD_SET_D_ID(*ptport_abts, d_id);
tport->flags |= FNIC_FDLS_TGT_ABORT_ISSUED;
FNIC_STD_SET_OX_ID(*ptport_abts, tport->active_oxid);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS send tport abts: tport->state: %d ",
iport->fcid, tport->state);
fnic_send_fcoe_frame(iport, frame, frame_size);
/* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
fdls_start_tport_timer(iport, tport, 2 * iport->e_d_tov);
}
static void fdls_send_fabric_abts(struct fnic_iport_s *iport)
{
uint8_t *frame;
uint8_t s_id[3];
uint8_t d_id[3];
struct fnic *fnic = iport->fnic;
struct fc_frame_header *pfabric_abts;
uint16_t oxid;
uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
sizeof(struct fc_frame_header);
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame to send fabric ABTS");
return;
}
pfabric_abts = (struct fc_frame_header *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
fdls_init_fabric_abts_frame(frame, iport);
hton24(s_id, iport->fcid);
switch (iport->fabric.state) {
case FDLS_STATE_FABRIC_LOGO:
hton24(d_id, FC_FID_FLOGI);
FNIC_STD_SET_D_ID(*pfabric_abts, d_id);
break;
case FDLS_STATE_FABRIC_FLOGI:
hton24(d_id, FC_FID_FLOGI);
FNIC_STD_SET_D_ID(*pfabric_abts, d_id);
break;
case FDLS_STATE_FABRIC_PLOGI:
FNIC_STD_SET_S_ID(*pfabric_abts, s_id);
hton24(d_id, FC_FID_DIR_SERV);
FNIC_STD_SET_D_ID(*pfabric_abts, d_id);
break;
case FDLS_STATE_RPN_ID:
FNIC_STD_SET_S_ID(*pfabric_abts, s_id);
hton24(d_id, FC_FID_DIR_SERV);
FNIC_STD_SET_D_ID(*pfabric_abts, d_id);
break;
case FDLS_STATE_SCR:
FNIC_STD_SET_S_ID(*pfabric_abts, s_id);
hton24(d_id, FC_FID_FCTRL);
FNIC_STD_SET_D_ID(*pfabric_abts, d_id);
break;
case FDLS_STATE_REGISTER_FC4_TYPES:
FNIC_STD_SET_S_ID(*pfabric_abts, s_id);
hton24(d_id, FC_FID_DIR_SERV);
FNIC_STD_SET_D_ID(*pfabric_abts, d_id);
break;
case FDLS_STATE_REGISTER_FC4_FEATURES:
FNIC_STD_SET_S_ID(*pfabric_abts, s_id);
hton24(d_id, FC_FID_DIR_SERV);
FNIC_STD_SET_D_ID(*pfabric_abts, d_id);
break;
case FDLS_STATE_GPN_FT:
FNIC_STD_SET_S_ID(*pfabric_abts, s_id);
hton24(d_id, FC_FID_DIR_SERV);
FNIC_STD_SET_D_ID(*pfabric_abts, d_id);
break;
default:
return;
}
oxid = iport->active_oxid_fabric_req;
FNIC_STD_SET_OX_ID(*pfabric_abts, oxid);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS send fabric abts. iport->fabric.state: %d oxid: 0x%x",
iport->fcid, iport->fabric.state, oxid);
iport->fabric.flags |= FNIC_FDLS_FABRIC_ABORT_ISSUED;
fnic_send_fcoe_frame(iport, frame, frame_size);
/* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
fdls_start_fabric_timer(iport, 2 * iport->e_d_tov);
iport->fabric.timer_pending = 1;
}
static void fdls_send_fdmi_abts(struct fnic_iport_s *iport)
{
uint8_t *frame;
uint8_t d_id[3];
struct fnic *fnic = iport->fnic;
struct fc_frame_header *pfabric_abts;
unsigned long fdmi_tov;
uint16_t oxid;
uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
sizeof(struct fc_frame_header);
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame to send FDMI ABTS");
return;
}
pfabric_abts = (struct fc_frame_header *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
fdls_init_fabric_abts_frame(frame, iport);
hton24(d_id, FC_FID_MGMT_SERV);
FNIC_STD_SET_D_ID(*pfabric_abts, d_id);
if (iport->fabric.fdmi_pending & FDLS_FDMI_PLOGI_PENDING) {
oxid = iport->active_oxid_fdmi_plogi;
FNIC_STD_SET_OX_ID(*pfabric_abts, oxid);
fnic_send_fcoe_frame(iport, frame, frame_size);
} else {
if (iport->fabric.fdmi_pending & FDLS_FDMI_REG_HBA_PENDING) {
oxid = iport->active_oxid_fdmi_rhba;
FNIC_STD_SET_OX_ID(*pfabric_abts, oxid);
fnic_send_fcoe_frame(iport, frame, frame_size);
}
if (iport->fabric.fdmi_pending & FDLS_FDMI_RPA_PENDING) {
oxid = iport->active_oxid_fdmi_rpa;
FNIC_STD_SET_OX_ID(*pfabric_abts, oxid);
fnic_send_fcoe_frame(iport, frame, frame_size);
}
}
fdmi_tov = jiffies + msecs_to_jiffies(2 * iport->e_d_tov);
mod_timer(&iport->fabric.fdmi_timer, round_jiffies(fdmi_tov));
iport->fabric.fdmi_pending |= FDLS_FDMI_ABORT_PENDING;
}
static void fdls_send_fabric_flogi(struct fnic_iport_s *iport)
{
uint8_t *frame;
struct fc_std_flogi *pflogi;
struct fnic *fnic = iport->fnic;
uint16_t oxid;
uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
sizeof(struct fc_std_flogi);
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame to send FLOGI");
iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME;
goto err_out;
}
pflogi = (struct fc_std_flogi *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
*pflogi = (struct fc_std_flogi) {
.fchdr = {.fh_r_ctl = FC_RCTL_ELS_REQ, .fh_d_id = {0xFF, 0xFF, 0xFE},
.fh_type = FC_TYPE_ELS, .fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0},
.fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)},
.els.fl_cmd = ELS_FLOGI,
.els.fl_csp = {.sp_hi_ver = FNIC_FC_PH_VER_HI,
.sp_lo_ver = FNIC_FC_PH_VER_LO,
.sp_bb_cred = cpu_to_be16(FNIC_FC_B2B_CREDIT),
.sp_bb_data = cpu_to_be16(FNIC_FC_B2B_RDF_SZ)},
.els.fl_cssp[2].cp_class = cpu_to_be16(FC_CPC_VALID | FC_CPC_SEQ)
};
FNIC_STD_SET_NPORT_NAME(&pflogi->els.fl_wwpn, iport->wwpn);
FNIC_STD_SET_NODE_NAME(&pflogi->els.fl_wwnn, iport->wwnn);
FNIC_LOGI_SET_RDF_SIZE(pflogi->els, iport->max_payload_size);
FNIC_LOGI_SET_R_A_TOV(pflogi->els, iport->r_a_tov);
FNIC_LOGI_SET_E_D_TOV(pflogi->els, iport->e_d_tov);
oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FABRIC_FLOGI,
&iport->active_oxid_fabric_req);
if (oxid == FNIC_UNASSIGNED_OXID) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: Failed to allocate OXID to send FLOGI",
iport->fcid);
mempool_free(frame, fnic->frame_pool);
iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME;
goto err_out;
}
FNIC_STD_SET_OX_ID(pflogi->fchdr, oxid);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS send fabric FLOGI with oxid: 0x%x", iport->fcid,
oxid);
fnic_send_fcoe_frame(iport, frame, frame_size);
atomic64_inc(&iport->iport_stats.fabric_flogi_sent);
err_out:
/* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
fdls_start_fabric_timer(iport, 2 * iport->e_d_tov);
}
static void fdls_send_fabric_plogi(struct fnic_iport_s *iport)
{
uint8_t *frame;
struct fc_std_flogi *pplogi;
struct fnic *fnic = iport->fnic;
uint16_t oxid;
uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
sizeof(struct fc_std_flogi);
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame to send PLOGI");
iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME;
goto err_out;
}
pplogi = (struct fc_std_flogi *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
fdls_init_plogi_frame(frame, iport);
oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FABRIC_PLOGI,
&iport->active_oxid_fabric_req);
if (oxid == FNIC_UNASSIGNED_OXID) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: Failed to allocate OXID to send fabric PLOGI",
iport->fcid);
mempool_free(frame, fnic->frame_pool);
iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME;
goto err_out;
}
FNIC_STD_SET_OX_ID(pplogi->fchdr, oxid);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS send fabric PLOGI with oxid: 0x%x", iport->fcid,
oxid);
fnic_send_fcoe_frame(iport, frame, frame_size);
atomic64_inc(&iport->iport_stats.fabric_plogi_sent);
err_out:
/* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
fdls_start_fabric_timer(iport, 2 * iport->e_d_tov);
}
static void fdls_send_fdmi_plogi(struct fnic_iport_s *iport)
{
uint8_t *frame;
struct fc_std_flogi *pplogi;
struct fnic *fnic = iport->fnic;
uint16_t oxid;
uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
sizeof(struct fc_std_flogi);
uint8_t d_id[3];
u64 fdmi_tov;
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame to send FDMI PLOGI");
goto err_out;
}
pplogi = (struct fc_std_flogi *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
fdls_init_plogi_frame(frame, iport);
oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FDMI_PLOGI,
&iport->active_oxid_fdmi_plogi);
if (oxid == FNIC_UNASSIGNED_OXID) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: Failed to allocate OXID to send FDMI PLOGI",
iport->fcid);
mempool_free(frame, fnic->frame_pool);
goto err_out;
}
FNIC_STD_SET_OX_ID(pplogi->fchdr, oxid);
hton24(d_id, FC_FID_MGMT_SERV);
FNIC_STD_SET_D_ID(pplogi->fchdr, d_id);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS send FDMI PLOGI with oxid: 0x%x",
iport->fcid, oxid);
fnic_send_fcoe_frame(iport, frame, frame_size);
err_out:
fdmi_tov = jiffies + msecs_to_jiffies(2 * iport->e_d_tov);
mod_timer(&iport->fabric.fdmi_timer, round_jiffies(fdmi_tov));
iport->fabric.fdmi_pending = FDLS_FDMI_PLOGI_PENDING;
}
static void fdls_send_rpn_id(struct fnic_iport_s *iport)
{
uint8_t *frame;
struct fc_std_rpn_id *prpn_id;
struct fnic *fnic = iport->fnic;
uint16_t oxid;
uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
sizeof(struct fc_std_rpn_id);
uint8_t fcid[3];
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame to send RPN_ID");
iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME;
goto err_out;
}
prpn_id = (struct fc_std_rpn_id *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
*prpn_id = (struct fc_std_rpn_id) {
.fchdr = {.fh_r_ctl = FC_RCTL_DD_UNSOL_CTL,
.fh_d_id = {0xFF, 0xFF, 0xFC}, .fh_type = FC_TYPE_CT,
.fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0},
.fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)},
.fc_std_ct_hdr = {.ct_rev = FC_CT_REV, .ct_fs_type = FC_FST_DIR,
.ct_fs_subtype = FC_NS_SUBTYPE,
.ct_cmd = cpu_to_be16(FC_NS_RPN_ID)}
};
hton24(fcid, iport->fcid);
FNIC_STD_SET_S_ID(prpn_id->fchdr, fcid);
FNIC_STD_SET_PORT_ID(prpn_id->rpn_id, fcid);
FNIC_STD_SET_PORT_NAME(prpn_id->rpn_id, iport->wwpn);
oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FABRIC_RPN,
&iport->active_oxid_fabric_req);
if (oxid == FNIC_UNASSIGNED_OXID) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: Failed to allocate OXID to send RPN_ID",
iport->fcid);
mempool_free(frame, fnic->frame_pool);
iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME;
goto err_out;
}
FNIC_STD_SET_OX_ID(prpn_id->fchdr, oxid);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS send RPN ID with oxid: 0x%x", iport->fcid,
oxid);
fnic_send_fcoe_frame(iport, frame, frame_size);
err_out:
/* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
fdls_start_fabric_timer(iport, 2 * iport->e_d_tov);
}
static void fdls_send_scr(struct fnic_iport_s *iport)
{
uint8_t *frame;
struct fc_std_scr *pscr;
struct fnic *fnic = iport->fnic;
uint16_t oxid;
uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
sizeof(struct fc_std_scr);
uint8_t fcid[3];
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame to send SCR");
iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME;
goto err_out;
}
pscr = (struct fc_std_scr *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
*pscr = (struct fc_std_scr) {
.fchdr = {.fh_r_ctl = FC_RCTL_ELS_REQ,
.fh_d_id = {0xFF, 0xFF, 0xFD}, .fh_type = FC_TYPE_ELS,
.fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0},
.fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)},
.scr = {.scr_cmd = ELS_SCR,
.scr_reg_func = ELS_SCRF_FULL}
};
hton24(fcid, iport->fcid);
FNIC_STD_SET_S_ID(pscr->fchdr, fcid);
oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FABRIC_SCR,
&iport->active_oxid_fabric_req);
if (oxid == FNIC_UNASSIGNED_OXID) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: Failed to allocate OXID to send SCR",
iport->fcid);
mempool_free(frame, fnic->frame_pool);
iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME;
goto err_out;
}
FNIC_STD_SET_OX_ID(pscr->fchdr, oxid);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS send SCR with oxid: 0x%x", iport->fcid,
oxid);
fnic_send_fcoe_frame(iport, frame, frame_size);
atomic64_inc(&iport->iport_stats.fabric_scr_sent);
err_out:
/* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
fdls_start_fabric_timer(iport, 2 * iport->e_d_tov);
}
static void fdls_send_gpn_ft(struct fnic_iport_s *iport, int fdls_state)
{
uint8_t *frame;
struct fc_std_gpn_ft *pgpn_ft;
struct fnic *fnic = iport->fnic;
uint16_t oxid;
uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
sizeof(struct fc_std_gpn_ft);
uint8_t fcid[3];
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame to send GPN FT");
iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME;
goto err_out;
}
pgpn_ft = (struct fc_std_gpn_ft *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
*pgpn_ft = (struct fc_std_gpn_ft) {
.fchdr = {.fh_r_ctl = FC_RCTL_DD_UNSOL_CTL,
.fh_d_id = {0xFF, 0xFF, 0xFC}, .fh_type = FC_TYPE_CT,
.fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0},
.fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)},
.fc_std_ct_hdr = {.ct_rev = FC_CT_REV, .ct_fs_type = FC_FST_DIR,
.ct_fs_subtype = FC_NS_SUBTYPE,
.ct_cmd = cpu_to_be16(FC_NS_GPN_FT)},
.gpn_ft.fn_fc4_type = 0x08
};
hton24(fcid, iport->fcid);
FNIC_STD_SET_S_ID(pgpn_ft->fchdr, fcid);
oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FABRIC_GPN_FT,
&iport->active_oxid_fabric_req);
if (oxid == FNIC_UNASSIGNED_OXID) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: Failed to allocate OXID to send GPN FT",
iport->fcid);
mempool_free(frame, fnic->frame_pool);
iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME;
goto err_out;
}
FNIC_STD_SET_OX_ID(pgpn_ft->fchdr, oxid);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS send GPN FT with oxid: 0x%x", iport->fcid,
oxid);
fnic_send_fcoe_frame(iport, frame, frame_size);
err_out:
/* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
fdls_start_fabric_timer(iport, 2 * iport->e_d_tov);
fdls_set_state((&iport->fabric), fdls_state);
}
static void
fdls_send_tgt_adisc(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
{
uint8_t *frame;
struct fc_std_els_adisc *padisc;
uint8_t s_id[3];
uint8_t d_id[3];
uint16_t oxid;
struct fnic *fnic = iport->fnic;
uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
sizeof(struct fc_std_els_adisc);
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame to send TGT ADISC");
tport->flags |= FNIC_FDLS_RETRY_FRAME;
goto err_out;
}
padisc = (struct fc_std_els_adisc *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
hton24(s_id, iport->fcid);
hton24(d_id, tport->fcid);
memcpy(padisc->els.adisc_port_id, s_id, 3);
FNIC_STD_SET_S_ID(padisc->fchdr, s_id);
FNIC_STD_SET_D_ID(padisc->fchdr, d_id);
FNIC_STD_SET_F_CTL(padisc->fchdr, FNIC_ELS_REQ_FCTL << 16);
FNIC_STD_SET_R_CTL(padisc->fchdr, FC_RCTL_ELS_REQ);
FNIC_STD_SET_TYPE(padisc->fchdr, FC_TYPE_ELS);
oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_TGT_ADISC, &tport->active_oxid);
if (oxid == FNIC_UNASSIGNED_OXID) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: Failed to allocate OXID to send TGT ADISC",
iport->fcid);
mempool_free(frame, fnic->frame_pool);
tport->flags |= FNIC_FDLS_RETRY_FRAME;
goto err_out;
}
FNIC_STD_SET_OX_ID(padisc->fchdr, oxid);
FNIC_STD_SET_RX_ID(padisc->fchdr, FNIC_UNASSIGNED_RXID);
tport->flags &= ~FNIC_FDLS_TGT_ABORT_ISSUED;
FNIC_STD_SET_NPORT_NAME(&padisc->els.adisc_wwpn,
iport->wwpn);
FNIC_STD_SET_NODE_NAME(&padisc->els.adisc_wwnn,
iport->wwnn);
padisc->els.adisc_cmd = ELS_ADISC;
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS send ADISC to tgt fcid: 0x%x",
iport->fcid, tport->fcid);
atomic64_inc(&iport->iport_stats.tport_adisc_sent);
fnic_send_fcoe_frame(iport, frame, frame_size);
err_out:
/* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
fdls_start_tport_timer(iport, tport, 2 * iport->e_d_tov);
}
bool fdls_delete_tport(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
{
struct fnic_tport_event_s *tport_del_evt;
struct fnic *fnic = iport->fnic;
if ((tport->state == FDLS_TGT_STATE_OFFLINING)
|| (tport->state == FDLS_TGT_STATE_OFFLINE)) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"tport fcid 0x%x: tport state is offlining/offline\n",
tport->fcid);
return false;
}
fdls_set_tport_state(tport, FDLS_TGT_STATE_OFFLINING);
/*
* By setting this flag, the tport will not be seen in a look-up
* in an RSCN. Even if we move to multithreaded model, this tport
* will be destroyed and a new RSCN will have to create a new one
*/
tport->flags |= FNIC_FDLS_TPORT_TERMINATING;
if (tport->timer_pending) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"tport fcid 0x%x: Canceling disc timer\n",
tport->fcid);
fnic_del_tport_timer_sync(fnic, tport);
tport->timer_pending = 0;
}
spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
fnic_rport_exch_reset(iport->fnic, tport->fcid);
spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags);
if (tport->flags & FNIC_FDLS_SCSI_REGISTERED) {
tport_del_evt =
kzalloc(sizeof(struct fnic_tport_event_s), GFP_ATOMIC);
if (!tport_del_evt) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Failed to allocate memory for tport fcid: 0x%0x\n",
tport->fcid);
return false;
}
tport_del_evt->event = TGT_EV_RPORT_DEL;
tport_del_evt->arg1 = (void *) tport;
list_add_tail(&tport_del_evt->links, &fnic->tport_event_list);
queue_work(fnic_event_queue, &fnic->tport_work);
} else {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"tport 0x%x not reg with scsi_transport. Freeing locally",
tport->fcid);
list_del(&tport->links);
kfree(tport);
}
return true;
}
static void
fdls_send_tgt_plogi(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
{
uint8_t *frame;
struct fc_std_flogi *pplogi;
struct fnic *fnic = iport->fnic;
uint16_t oxid;
uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
sizeof(struct fc_std_flogi);
uint8_t d_id[3];
uint32_t timeout;
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame to send TGT PLOGI");
tport->flags |= FNIC_FDLS_RETRY_FRAME;
goto err_out;
}
pplogi = (struct fc_std_flogi *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
fdls_init_plogi_frame(frame, iport);
oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_TGT_PLOGI, &tport->active_oxid);
if (oxid == FNIC_UNASSIGNED_OXID) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: Failed to allocate oxid to send PLOGI to fcid: 0x%x",
iport->fcid, tport->fcid);
mempool_free(frame, fnic->frame_pool);
tport->flags |= FNIC_FDLS_RETRY_FRAME;
goto err_out;
}
FNIC_STD_SET_OX_ID(pplogi->fchdr, oxid);
tport->flags &= ~FNIC_FDLS_TGT_ABORT_ISSUED;
hton24(d_id, tport->fcid);
FNIC_STD_SET_D_ID(pplogi->fchdr, d_id);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS send tgt PLOGI to tgt: 0x%x with oxid: 0x%x",
iport->fcid, tport->fcid, oxid);
fnic_send_fcoe_frame(iport, frame, frame_size);
atomic64_inc(&iport->iport_stats.tport_plogi_sent);
err_out:
timeout = max(2 * iport->e_d_tov, iport->plogi_timeout);
/* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
fdls_start_tport_timer(iport, tport, timeout);
}
static uint16_t
fnic_fc_plogi_rsp_rdf(struct fnic_iport_s *iport,
struct fc_std_flogi *plogi_rsp)
{
uint16_t b2b_rdf_size =
be16_to_cpu(FNIC_LOGI_RDF_SIZE(plogi_rsp->els));
uint16_t spc3_rdf_size =
be16_to_cpu(plogi_rsp->els.fl_cssp[2].cp_rdfs) & FNIC_FC_C3_RDF;
struct fnic *fnic = iport->fnic;
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"MFS: b2b_rdf_size: 0x%x spc3_rdf_size: 0x%x",
b2b_rdf_size, spc3_rdf_size);
return min(b2b_rdf_size, spc3_rdf_size);
}
static void fdls_send_register_fc4_types(struct fnic_iport_s *iport)
{
uint8_t *frame;
struct fc_std_rft_id *prft_id;
struct fnic *fnic = iport->fnic;
uint16_t oxid;
uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
sizeof(struct fc_std_rft_id);
uint8_t fcid[3];
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame to send RFT");
return;
}
prft_id = (struct fc_std_rft_id *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
*prft_id = (struct fc_std_rft_id) {
.fchdr = {.fh_r_ctl = FC_RCTL_DD_UNSOL_CTL,
.fh_d_id = {0xFF, 0xFF, 0xFC}, .fh_type = FC_TYPE_CT,
.fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0},
.fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)},
.fc_std_ct_hdr = {.ct_rev = FC_CT_REV, .ct_fs_type = FC_FST_DIR,
.ct_fs_subtype = FC_NS_SUBTYPE,
.ct_cmd = cpu_to_be16(FC_NS_RFT_ID)}
};
hton24(fcid, iport->fcid);
FNIC_STD_SET_S_ID(prft_id->fchdr, fcid);
FNIC_STD_SET_PORT_ID(prft_id->rft_id, fcid);
oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FABRIC_RFT,
&iport->active_oxid_fabric_req);
if (oxid == FNIC_UNASSIGNED_OXID) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: Failed to allocate OXID to send RFT",
iport->fcid);
mempool_free(frame, fnic->frame_pool);
return;
}
FNIC_STD_SET_OX_ID(prft_id->fchdr, oxid);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS send RFT with oxid: 0x%x", iport->fcid,
oxid);
prft_id->rft_id.fr_fts.ff_type_map[0] =
cpu_to_be32(1 << FC_TYPE_FCP);
prft_id->rft_id.fr_fts.ff_type_map[1] =
cpu_to_be32(1 << (FC_TYPE_CT % FC_NS_BPW));
fnic_send_fcoe_frame(iport, frame, frame_size);
/* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
fdls_start_fabric_timer(iport, 2 * iport->e_d_tov);
}
static void fdls_send_register_fc4_features(struct fnic_iport_s *iport)
{
uint8_t *frame;
struct fc_std_rff_id *prff_id;
struct fnic *fnic = iport->fnic;
uint16_t oxid;
uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
sizeof(struct fc_std_rff_id);
uint8_t fcid[3];
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame to send RFF");
return;
}
prff_id = (struct fc_std_rff_id *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
*prff_id = (struct fc_std_rff_id) {
.fchdr = {.fh_r_ctl = FC_RCTL_DD_UNSOL_CTL,
.fh_d_id = {0xFF, 0xFF, 0xFC}, .fh_type = FC_TYPE_CT,
.fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0},
.fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)},
.fc_std_ct_hdr = {.ct_rev = FC_CT_REV, .ct_fs_type = FC_FST_DIR,
.ct_fs_subtype = FC_NS_SUBTYPE,
.ct_cmd = cpu_to_be16(FC_NS_RFF_ID)},
.rff_id.fr_feat = 0x2,
.rff_id.fr_type = FC_TYPE_FCP
};
hton24(fcid, iport->fcid);
FNIC_STD_SET_S_ID(prff_id->fchdr, fcid);
FNIC_STD_SET_PORT_ID(prff_id->rff_id, fcid);
oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FABRIC_RFF,
&iport->active_oxid_fabric_req);
if (oxid == FNIC_UNASSIGNED_OXID) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: Failed to allocate OXID to send RFF",
iport->fcid);
mempool_free(frame, fnic->frame_pool);
return;
}
FNIC_STD_SET_OX_ID(prff_id->fchdr, oxid);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS send RFF with oxid: 0x%x", iport->fcid,
oxid);
prff_id->rff_id.fr_type = FC_TYPE_FCP;
fnic_send_fcoe_frame(iport, frame, frame_size);
/* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
fdls_start_fabric_timer(iport, 2 * iport->e_d_tov);
}
static void
fdls_send_tgt_prli(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
{
uint8_t *frame;
struct fc_std_els_prli *pprli;
struct fnic *fnic = iport->fnic;
uint16_t oxid;
uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
sizeof(struct fc_std_els_prli);
uint8_t s_id[3];
uint8_t d_id[3];
uint32_t timeout;
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame to send TGT PRLI");
tport->flags |= FNIC_FDLS_RETRY_FRAME;
goto err_out;
}
pprli = (struct fc_std_els_prli *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
*pprli = (struct fc_std_els_prli) {
.fchdr = {.fh_r_ctl = FC_RCTL_ELS_REQ, .fh_type = FC_TYPE_ELS,
.fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0},
.fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)},
.els_prli = {.prli_cmd = ELS_PRLI,
.prli_spp_len = 16,
.prli_len = cpu_to_be16(0x14)},
.sp = {.spp_type = 0x08, .spp_flags = 0x0020,
.spp_params = cpu_to_be32(0xA2)}
};
oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_TGT_PRLI, &tport->active_oxid);
if (oxid == FNIC_UNASSIGNED_OXID) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"0x%x: Failed to allocate OXID to send TGT PRLI to 0x%x",
iport->fcid, tport->fcid);
mempool_free(frame, fnic->frame_pool);
tport->flags |= FNIC_FDLS_RETRY_FRAME;
goto err_out;
}
tport->flags &= ~FNIC_FDLS_TGT_ABORT_ISSUED;
hton24(s_id, iport->fcid);
hton24(d_id, tport->fcid);
FNIC_STD_SET_OX_ID(pprli->fchdr, oxid);
FNIC_STD_SET_S_ID(pprli->fchdr, s_id);
FNIC_STD_SET_D_ID(pprli->fchdr, d_id);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS send PRLI to tgt: 0x%x with oxid: 0x%x",
iport->fcid, tport->fcid, oxid);
fnic_send_fcoe_frame(iport, frame, frame_size);
atomic64_inc(&iport->iport_stats.tport_prli_sent);
err_out:
timeout = max(2 * iport->e_d_tov, iport->plogi_timeout);
/* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
fdls_start_tport_timer(iport, tport, timeout);
}
/**
* fdls_send_fabric_logo - Send flogo to the fcf
* @iport: Handle to fnic iport
*
* This function does not change or check the fabric state.
* It the caller's responsibility to set the appropriate iport fabric
* state when this is called. Normally it is FDLS_STATE_FABRIC_LOGO.
* Currently this assumes to be called with fnic lock held.
*/
void fdls_send_fabric_logo(struct fnic_iport_s *iport)
{
uint8_t *frame;
struct fc_std_logo *plogo;
struct fnic *fnic = iport->fnic;
uint8_t d_id[3];
uint16_t oxid;
uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
sizeof(struct fc_std_logo);
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame to send fabric LOGO");
return;
}
plogo = (struct fc_std_logo *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
fdls_init_logo_frame(frame, iport);
oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FABRIC_LOGO,
&iport->active_oxid_fabric_req);
if (oxid == FNIC_UNASSIGNED_OXID) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: Failed to allocate OXID to send fabric LOGO",
iport->fcid);
mempool_free(frame, fnic->frame_pool);
return;
}
FNIC_STD_SET_OX_ID(plogo->fchdr, oxid);
hton24(d_id, FC_FID_FLOGI);
FNIC_STD_SET_D_ID(plogo->fchdr, d_id);
iport->fabric.flags &= ~FNIC_FDLS_FABRIC_ABORT_ISSUED;
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS send fabric LOGO with oxid: 0x%x",
iport->fcid, oxid);
fnic_send_fcoe_frame(iport, frame, frame_size);
fdls_start_fabric_timer(iport, 2 * iport->e_d_tov);
}
/**
* fdls_tgt_logout - Send plogo to the remote port
* @iport: Handle to fnic iport
* @tport: Handle to remote port
*
* This function does not change or check the fabric/tport state.
* It the caller's responsibility to set the appropriate tport/fabric
* state when this is called. Normally that is fdls_tgt_state_plogo.
* This could be used to send plogo to nameserver process
* also not just target processes
*/
void fdls_tgt_logout(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
{
uint8_t *frame;
struct fc_std_logo *plogo;
struct fnic *fnic = iport->fnic;
uint8_t d_id[3];
uint16_t oxid;
uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
sizeof(struct fc_std_logo);
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame to send fabric LOGO");
return;
}
plogo = (struct fc_std_logo *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
fdls_init_logo_frame(frame, iport);
oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_TGT_LOGO, &tport->active_oxid);
if (oxid == FNIC_UNASSIGNED_OXID) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: Failed to allocate OXID to send tgt LOGO",
iport->fcid);
mempool_free(frame, fnic->frame_pool);
return;
}
FNIC_STD_SET_OX_ID(plogo->fchdr, oxid);
hton24(d_id, tport->fcid);
FNIC_STD_SET_D_ID(plogo->fchdr, d_id);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS send tgt LOGO with oxid: 0x%x",
iport->fcid, oxid);
fnic_send_fcoe_frame(iport, frame, frame_size);
atomic64_inc(&iport->iport_stats.tport_logo_sent);
}
static void fdls_tgt_discovery_start(struct fnic_iport_s *iport)
{
struct fnic_tport_s *tport, *next;
u32 old_link_down_cnt = iport->fnic->link_down_cnt;
struct fnic *fnic = iport->fnic;
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: Starting FDLS target discovery", iport->fcid);
list_for_each_entry_safe(tport, next, &iport->tport_list, links) {
if ((old_link_down_cnt != iport->fnic->link_down_cnt)
|| (iport->state != FNIC_IPORT_STATE_READY)) {
break;
}
/* if we marked the tport as deleted due to GPN_FT
* We should not send ADISC anymore
*/
if ((tport->state == FDLS_TGT_STATE_OFFLINING) ||
(tport->state == FDLS_TGT_STATE_OFFLINE))
continue;
/* For tports which have received RSCN */
if (tport->flags & FNIC_FDLS_TPORT_SEND_ADISC) {
tport->retry_counter = 0;
fdls_set_tport_state(tport, FDLS_TGT_STATE_ADISC);
tport->flags &= ~FNIC_FDLS_TPORT_SEND_ADISC;
fdls_send_tgt_adisc(iport, tport);
continue;
}
if (fdls_get_tport_state(tport) != FDLS_TGT_STATE_INIT) {
/* Not a new port, skip */
continue;
}
tport->retry_counter = 0;
fdls_set_tport_state(tport, FDLS_TGT_STATE_PLOGI);
fdls_send_tgt_plogi(iport, tport);
}
fdls_set_state((&iport->fabric), FDLS_STATE_TGT_DISCOVERY);
}
/*
* Function to restart the IT nexus if we received any out of
* sequence PLOGI/PRLI response from the target.
* The memory for the new tport structure is allocated
* inside fdls_create_tport and added to the iport's tport list.
* This will get freed later during tport_offline/linkdown
* or module unload. The new_tport pointer will go out of scope
* safely since the memory it is
* pointing to it will be freed later
*/
static void fdls_target_restart_nexus(struct fnic_tport_s *tport)
{
struct fnic_iport_s *iport = tport->iport;
struct fnic_tport_s *new_tport = NULL;
uint32_t fcid;
uint64_t wwpn;
int nexus_restart_count;
struct fnic *fnic = iport->fnic;
bool retval = true;
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"tport fcid: 0x%x state: %d restart_count: %d",
tport->fcid, tport->state, tport->nexus_restart_count);
fcid = tport->fcid;
wwpn = tport->wwpn;
nexus_restart_count = tport->nexus_restart_count;
retval = fdls_delete_tport(iport, tport);
if (retval != true) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Error deleting tport: 0x%x", fcid);
return;
}
if (nexus_restart_count >= FNIC_TPORT_MAX_NEXUS_RESTART) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Exceeded nexus restart retries tport: 0x%x",
fcid);
return;
}
/*
* Allocate memory for the new tport and add it to
* iport's tport list.
* This memory will be freed during tport_offline/linkdown
* or module unload. The pointer new_tport is safe to go
* out of scope when this function returns, since the memory
* it is pointing to is guaranteed to be freed later
* as mentioned above.
*/
new_tport = fdls_create_tport(iport, fcid, wwpn);
if (!new_tport) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Error creating new tport: 0x%x", fcid);
return;
}
new_tport->nexus_restart_count = nexus_restart_count + 1;
fdls_send_tgt_plogi(iport, new_tport);
fdls_set_tport_state(new_tport, FDLS_TGT_STATE_PLOGI);
}
struct fnic_tport_s *fnic_find_tport_by_fcid(struct fnic_iport_s *iport,
uint32_t fcid)
{
struct fnic_tport_s *tport, *next;
list_for_each_entry_safe(tport, next, &(iport->tport_list), links) {
if ((tport->fcid == fcid)
&& !(tport->flags & FNIC_FDLS_TPORT_TERMINATING))
return tport;
}
return NULL;
}
static struct fnic_tport_s *fdls_create_tport(struct fnic_iport_s *iport,
uint32_t fcid, uint64_t wwpn)
{
struct fnic_tport_s *tport;
struct fnic *fnic = iport->fnic;
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"FDLS create tport: fcid: 0x%x wwpn: 0x%llx", fcid, wwpn);
tport = kzalloc(sizeof(struct fnic_tport_s), GFP_ATOMIC);
if (!tport) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Memory allocation failure while creating tport: 0x%x\n",
fcid);
return NULL;
}
tport->max_payload_size = FNIC_FCOE_MAX_FRAME_SZ;
tport->r_a_tov = FC_DEF_R_A_TOV;
tport->e_d_tov = FC_DEF_E_D_TOV;
tport->fcid = fcid;
tport->wwpn = wwpn;
tport->iport = iport;
FNIC_FCS_DBG(KERN_DEBUG, fnic->host, fnic->fnic_num,
"Need to setup tport timer callback");
timer_setup(&tport->retry_timer, fdls_tport_timer_callback, 0);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Added tport 0x%x", tport->fcid);
fdls_set_tport_state(tport, FDLS_TGT_STATE_INIT);
list_add_tail(&tport->links, &iport->tport_list);
atomic_set(&tport->in_flight, 0);
return tport;
}
struct fnic_tport_s *fnic_find_tport_by_wwpn(struct fnic_iport_s *iport,
uint64_t wwpn)
{
struct fnic_tport_s *tport, *next;
list_for_each_entry_safe(tport, next, &(iport->tport_list), links) {
if ((tport->wwpn == wwpn)
&& !(tport->flags & FNIC_FDLS_TPORT_TERMINATING))
return tport;
}
return NULL;
}
static void
fnic_fdmi_attr_set(void *attr_start, u16 type, u16 len,
void *data, u32 *off)
{
u16 size = len + FC_FDMI_ATTR_ENTRY_HEADER_LEN;
struct fc_fdmi_attr_entry *fdmi_attr = (struct fc_fdmi_attr_entry *)
((u8 *)attr_start + *off);
put_unaligned_be16(type, &fdmi_attr->type);
put_unaligned_be16(size, &fdmi_attr->len);
memcpy(fdmi_attr->value, data, len);
*off += size;
}
static void fdls_fdmi_register_hba(struct fnic_iport_s *iport)
{
uint8_t *frame;
struct fc_std_fdmi_rhba *prhba;
struct fc_fdmi_attr_entry *fdmi_attr;
uint8_t fcid[3];
int err;
struct fnic *fnic = iport->fnic;
struct vnic_devcmd_fw_info *fw_info = NULL;
uint16_t oxid;
u32 attr_off_bytes, len;
u8 data[64];
uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET;
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame to send FDMI RHBA");
return;
}
prhba = (struct fc_std_fdmi_rhba *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
*prhba = (struct fc_std_fdmi_rhba) {
.fchdr = {
.fh_r_ctl = FC_RCTL_DD_UNSOL_CTL,
.fh_d_id = {0xFF, 0XFF, 0XFA},
.fh_type = FC_TYPE_CT,
.fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0},
.fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)
},
.fc_std_ct_hdr = {
.ct_rev = FC_CT_REV, .ct_fs_type = FC_FST_MGMT,
.ct_fs_subtype = FC_FDMI_SUBTYPE,
.ct_cmd = cpu_to_be16(FC_FDMI_RHBA)
},
};
hton24(fcid, iport->fcid);
FNIC_STD_SET_S_ID(prhba->fchdr, fcid);
oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FDMI_RHBA,
&iport->active_oxid_fdmi_rhba);
if (oxid == FNIC_UNASSIGNED_OXID) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: Failed to allocate OXID to send FDMI RHBA",
iport->fcid);
mempool_free(frame, fnic->frame_pool);
return;
}
FNIC_STD_SET_OX_ID(prhba->fchdr, oxid);
put_unaligned_be64(iport->wwpn, &prhba->rhba.hbaid.id);
put_unaligned_be32(FNIC_FDMI_NUM_PORTS, &prhba->rhba.port.numport);
put_unaligned_be64(iport->wwpn, &prhba->rhba.port.port[0].portname);
put_unaligned_be32(FNIC_FDMI_NUM_HBA_ATTRS,
&prhba->rhba.hba_attrs.numattrs);
fdmi_attr = prhba->rhba.hba_attrs.attr;
attr_off_bytes = 0;
put_unaligned_be64(iport->wwnn, data);
fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_NODE_NAME,
FNIC_FDMI_NN_LEN, data, &attr_off_bytes);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"NN set, off=%d", attr_off_bytes);
strscpy_pad(data, FNIC_FDMI_MANUFACTURER, FNIC_FDMI_MANU_LEN);
fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_MANUFACTURER,
FNIC_FDMI_MANU_LEN, data, &attr_off_bytes);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"MFG set <%s>, off=%d", data, attr_off_bytes);
err = vnic_dev_fw_info(fnic->vdev, &fw_info);
if (!err) {
strscpy_pad(data, fw_info->hw_serial_number,
FNIC_FDMI_SERIAL_LEN);
fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_SERIAL_NUMBER,
FNIC_FDMI_SERIAL_LEN, data, &attr_off_bytes);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"SERIAL set <%s>, off=%d", data, attr_off_bytes);
}
if (fnic->subsys_desc_len >= FNIC_FDMI_MODEL_LEN)
fnic->subsys_desc_len = FNIC_FDMI_MODEL_LEN - 1;
strscpy_pad(data, fnic->subsys_desc, FNIC_FDMI_MODEL_LEN);
fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_MODEL, FNIC_FDMI_MODEL_LEN,
data, &attr_off_bytes);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"MODEL set <%s>, off=%d", data, attr_off_bytes);
strscpy_pad(data, FNIC_FDMI_MODEL_DESCRIPTION, FNIC_FDMI_MODEL_DES_LEN);
fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_MODEL_DES,
FNIC_FDMI_MODEL_DES_LEN, data, &attr_off_bytes);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"MODEL_DESC set <%s>, off=%d", data, attr_off_bytes);
if (!err) {
strscpy_pad(data, fw_info->hw_version, FNIC_FDMI_HW_VER_LEN);
fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_HARDWARE_VERSION,
FNIC_FDMI_HW_VER_LEN, data, &attr_off_bytes);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"HW_VER set <%s>, off=%d", data, attr_off_bytes);
}
strscpy_pad(data, DRV_VERSION, FNIC_FDMI_DR_VER_LEN);
fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_DRIVER_VERSION,
FNIC_FDMI_DR_VER_LEN, data, &attr_off_bytes);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"DRV_VER set <%s>, off=%d", data, attr_off_bytes);
strscpy_pad(data, "N/A", FNIC_FDMI_ROM_VER_LEN);
fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_ROM_VERSION,
FNIC_FDMI_ROM_VER_LEN, data, &attr_off_bytes);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"ROM_VER set <%s>, off=%d", data, attr_off_bytes);
if (!err) {
strscpy_pad(data, fw_info->fw_version, FNIC_FDMI_FW_VER_LEN);
fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_FIRMWARE_VERSION,
FNIC_FDMI_FW_VER_LEN, data, &attr_off_bytes);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"FW_VER set <%s>, off=%d", data, attr_off_bytes);
}
len = sizeof(struct fc_std_fdmi_rhba) + attr_off_bytes;
frame_size += len;
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS send FDMI RHBA with oxid: 0x%x fs: %d", iport->fcid,
oxid, frame_size);
fnic_send_fcoe_frame(iport, frame, frame_size);
iport->fabric.fdmi_pending |= FDLS_FDMI_REG_HBA_PENDING;
}
static void fdls_fdmi_register_pa(struct fnic_iport_s *iport)
{
uint8_t *frame;
struct fc_std_fdmi_rpa *prpa;
struct fc_fdmi_attr_entry *fdmi_attr;
uint8_t fcid[3];
struct fnic *fnic = iport->fnic;
u32 port_speed_bm;
u32 port_speed = vnic_dev_port_speed(fnic->vdev);
uint16_t oxid;
u32 attr_off_bytes, len;
u8 tmp_data[16], data[64];
uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET;
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame to send FDMI RPA");
return;
}
prpa = (struct fc_std_fdmi_rpa *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
*prpa = (struct fc_std_fdmi_rpa) {
.fchdr = {
.fh_r_ctl = FC_RCTL_DD_UNSOL_CTL,
.fh_d_id = {0xFF, 0xFF, 0xFA},
.fh_type = FC_TYPE_CT,
.fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0},
.fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)
},
.fc_std_ct_hdr = {
.ct_rev = FC_CT_REV, .ct_fs_type = FC_FST_MGMT,
.ct_fs_subtype = FC_FDMI_SUBTYPE,
.ct_cmd = cpu_to_be16(FC_FDMI_RPA)
},
};
hton24(fcid, iport->fcid);
FNIC_STD_SET_S_ID(prpa->fchdr, fcid);
oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FDMI_RPA,
&iport->active_oxid_fdmi_rpa);
if (oxid == FNIC_UNASSIGNED_OXID) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: Failed to allocate OXID to send FDMI RPA",
iport->fcid);
mempool_free(frame, fnic->frame_pool);
return;
}
FNIC_STD_SET_OX_ID(prpa->fchdr, oxid);
put_unaligned_be64(iport->wwpn, &prpa->rpa.port.portname);
put_unaligned_be32(FNIC_FDMI_NUM_PORT_ATTRS,
&prpa->rpa.hba_attrs.numattrs);
/* MDS does not support GIGE speed.
* Bit shift standard definitions from scsi_transport_fc.h to
* match FC spec.
*/
switch (port_speed) {
case DCEM_PORTSPEED_10G:
case DCEM_PORTSPEED_20G:
/* There is no bit for 20G */
port_speed_bm = FC_PORTSPEED_10GBIT << PORT_SPEED_BIT_14;
break;
case DCEM_PORTSPEED_25G:
port_speed_bm = FC_PORTSPEED_25GBIT << PORT_SPEED_BIT_8;
break;
case DCEM_PORTSPEED_40G:
case DCEM_PORTSPEED_4x10G:
port_speed_bm = FC_PORTSPEED_40GBIT << PORT_SPEED_BIT_9;
break;
case DCEM_PORTSPEED_100G:
port_speed_bm = FC_PORTSPEED_100GBIT << PORT_SPEED_BIT_8;
break;
default:
port_speed_bm = FC_PORTSPEED_1GBIT << PORT_SPEED_BIT_15;
break;
}
attr_off_bytes = 0;
fdmi_attr = prpa->rpa.hba_attrs.attr;
put_unaligned_be64(iport->wwnn, data);
memset(data, 0, FNIC_FDMI_FC4_LEN);
data[2] = 1;
fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_FC4_TYPES,
FNIC_FDMI_FC4_LEN, data, &attr_off_bytes);
put_unaligned_be32(port_speed_bm, data);
fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_SUPPORTED_SPEEDS,
FNIC_FDMI_SUPP_SPEED_LEN, data, &attr_off_bytes);
put_unaligned_be32(port_speed_bm, data);
fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_CURRENT_SPEED,
FNIC_FDMI_CUR_SPEED_LEN, data, &attr_off_bytes);
put_unaligned_be32(FNIC_FDMI_MFS, data);
fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_MAX_FRAME_SIZE,
FNIC_FDMI_MFS_LEN, data, &attr_off_bytes);
snprintf(tmp_data, FNIC_FDMI_OS_NAME_LEN - 1, "host%d",
fnic->host->host_no);
strscpy_pad(data, tmp_data, FNIC_FDMI_OS_NAME_LEN);
fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_OS_NAME,
FNIC_FDMI_OS_NAME_LEN, data, &attr_off_bytes);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"OS name set <%s>, off=%d", data, attr_off_bytes);
sprintf(fc_host_system_hostname(fnic->host), "%s", utsname()->nodename);
strscpy_pad(data, fc_host_system_hostname(fnic->host),
FNIC_FDMI_HN_LEN);
fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_HOST_NAME,
FNIC_FDMI_HN_LEN, data, &attr_off_bytes);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Host name set <%s>, off=%d", data, attr_off_bytes);
len = sizeof(struct fc_std_fdmi_rpa) + attr_off_bytes;
frame_size += len;
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS send FDMI RPA with oxid: 0x%x fs: %d", iport->fcid,
oxid, frame_size);
fnic_send_fcoe_frame(iport, frame, frame_size);
iport->fabric.fdmi_pending |= FDLS_FDMI_RPA_PENDING;
}
void fdls_fabric_timer_callback(struct timer_list *t)
{
struct fnic_fdls_fabric_s *fabric = from_timer(fabric, t, retry_timer);
struct fnic_iport_s *iport =
container_of(fabric, struct fnic_iport_s, fabric);
struct fnic *fnic = iport->fnic;
unsigned long flags;
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"tp: %d fab state: %d fab retry counter: %d max_flogi_retries: %d",
iport->fabric.timer_pending, iport->fabric.state,
iport->fabric.retry_counter, iport->max_flogi_retries);
spin_lock_irqsave(&fnic->fnic_lock, flags);
if (!iport->fabric.timer_pending) {
spin_unlock_irqrestore(&fnic->fnic_lock, flags);
return;
}
if (iport->fabric.del_timer_inprogress) {
iport->fabric.del_timer_inprogress = 0;
spin_unlock_irqrestore(&fnic->fnic_lock, flags);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"fabric_del_timer inprogress(%d). Skip timer cb",
iport->fabric.del_timer_inprogress);
return;
}
iport->fabric.timer_pending = 0;
/* The fabric state indicates which frames have time out, and we retry */
switch (iport->fabric.state) {
case FDLS_STATE_FABRIC_FLOGI:
/* Flogi received a LS_RJT with busy we retry from here */
if ((iport->fabric.flags & FNIC_FDLS_RETRY_FRAME)
&& (iport->fabric.retry_counter < iport->max_flogi_retries)) {
iport->fabric.flags &= ~FNIC_FDLS_RETRY_FRAME;
fdls_send_fabric_flogi(iport);
} else if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED)) {
/* Flogi has time out 2*ed_tov send abts */
fdls_send_fabric_abts(iport);
} else {
/* ABTS has timed out
* Mark the OXID to be freed after 2 * r_a_tov and retry the req
*/
fdls_schedule_oxid_free(iport, &iport->active_oxid_fabric_req);
if (iport->fabric.retry_counter < iport->max_flogi_retries) {
iport->fabric.flags &= ~FNIC_FDLS_FABRIC_ABORT_ISSUED;
fdls_send_fabric_flogi(iport);
} else
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Exceeded max FLOGI retries");
}
break;
case FDLS_STATE_FABRIC_PLOGI:
/* Plogi received a LS_RJT with busy we retry from here */
if ((iport->fabric.flags & FNIC_FDLS_RETRY_FRAME)
&& (iport->fabric.retry_counter < iport->max_plogi_retries)) {
iport->fabric.flags &= ~FNIC_FDLS_RETRY_FRAME;
fdls_send_fabric_plogi(iport);
} else if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED)) {
/* Plogi has timed out 2*ed_tov send abts */
fdls_send_fabric_abts(iport);
} else {
/* ABTS has timed out
* Mark the OXID to be freed after 2 * r_a_tov and retry the req
*/
fdls_schedule_oxid_free(iport, &iport->active_oxid_fabric_req);
if (iport->fabric.retry_counter < iport->max_plogi_retries) {
iport->fabric.flags &= ~FNIC_FDLS_FABRIC_ABORT_ISSUED;
fdls_send_fabric_plogi(iport);
} else
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Exceeded max PLOGI retries");
}
break;
case FDLS_STATE_RPN_ID:
/* Rpn_id received a LS_RJT with busy we retry from here */
if ((iport->fabric.flags & FNIC_FDLS_RETRY_FRAME)
&& (iport->fabric.retry_counter < FDLS_RETRY_COUNT)) {
iport->fabric.flags &= ~FNIC_FDLS_RETRY_FRAME;
fdls_send_rpn_id(iport);
} else if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED))
/* RPN has timed out. Send abts */
fdls_send_fabric_abts(iport);
else {
/* ABTS has timed out */
fdls_schedule_oxid_free(iport, &iport->active_oxid_fabric_req);
fnic_fdls_start_plogi(iport); /* go back to fabric Plogi */
}
break;
case FDLS_STATE_SCR:
/* scr received a LS_RJT with busy we retry from here */
if ((iport->fabric.flags & FNIC_FDLS_RETRY_FRAME)
&& (iport->fabric.retry_counter < FDLS_RETRY_COUNT)) {
iport->fabric.flags &= ~FNIC_FDLS_RETRY_FRAME;
fdls_send_scr(iport);
} else if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED))
/* scr has timed out. Send abts */
fdls_send_fabric_abts(iport);
else {
/* ABTS has timed out */
fdls_schedule_oxid_free(iport, &iport->active_oxid_fabric_req);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"ABTS timed out. Starting PLOGI: %p", iport);
fnic_fdls_start_plogi(iport);
}
break;
case FDLS_STATE_REGISTER_FC4_TYPES:
/* scr received a LS_RJT with busy we retry from here */
if ((iport->fabric.flags & FNIC_FDLS_RETRY_FRAME)
&& (iport->fabric.retry_counter < FDLS_RETRY_COUNT)) {
iport->fabric.flags &= ~FNIC_FDLS_RETRY_FRAME;
fdls_send_register_fc4_types(iport);
} else if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED)) {
/* RFT_ID timed out send abts */
fdls_send_fabric_abts(iport);
} else {
/* ABTS has timed out */
fdls_schedule_oxid_free(iport, &iport->active_oxid_fabric_req);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"ABTS timed out. Starting PLOGI: %p", iport);
fnic_fdls_start_plogi(iport); /* go back to fabric Plogi */
}
break;
case FDLS_STATE_REGISTER_FC4_FEATURES:
/* scr received a LS_RJT with busy we retry from here */
if ((iport->fabric.flags & FNIC_FDLS_RETRY_FRAME)
&& (iport->fabric.retry_counter < FDLS_RETRY_COUNT)) {
iport->fabric.flags &= ~FNIC_FDLS_RETRY_FRAME;
fdls_send_register_fc4_features(iport);
} else if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED))
/* SCR has timed out. Send abts */
fdls_send_fabric_abts(iport);
else {
/* ABTS has timed out */
fdls_schedule_oxid_free(iport, &iport->active_oxid_fabric_req);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"ABTS timed out. Starting PLOGI %p", iport);
fnic_fdls_start_plogi(iport); /* go back to fabric Plogi */
}
break;
case FDLS_STATE_RSCN_GPN_FT:
case FDLS_STATE_SEND_GPNFT:
case FDLS_STATE_GPN_FT:
/* GPN_FT received a LS_RJT with busy we retry from here */
if ((iport->fabric.flags & FNIC_FDLS_RETRY_FRAME)
&& (iport->fabric.retry_counter < FDLS_RETRY_COUNT)) {
iport->fabric.flags &= ~FNIC_FDLS_RETRY_FRAME;
fdls_send_gpn_ft(iport, iport->fabric.state);
} else if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED)) {
/* gpn_ft has timed out. Send abts */
fdls_send_fabric_abts(iport);
} else {
/* ABTS has timed out */
fdls_schedule_oxid_free(iport, &iport->active_oxid_fabric_req);
if (iport->fabric.retry_counter < FDLS_RETRY_COUNT) {
fdls_send_gpn_ft(iport, iport->fabric.state);
} else {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"ABTS timeout for fabric GPN_FT. Check name server: %p",
iport);
}
}
break;
default:
break;
}
spin_unlock_irqrestore(&fnic->fnic_lock, flags);
}
void fdls_fdmi_timer_callback(struct timer_list *t)
{
struct fnic_fdls_fabric_s *fabric = from_timer(fabric, t, fdmi_timer);
struct fnic_iport_s *iport =
container_of(fabric, struct fnic_iport_s, fabric);
struct fnic *fnic = iport->fnic;
unsigned long flags;
spin_lock_irqsave(&fnic->fnic_lock, flags);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"fdmi timer callback : 0x%x\n", iport->fabric.fdmi_pending);
if (!iport->fabric.fdmi_pending) {
/* timer expired after fdmi responses received. */
spin_unlock_irqrestore(&fnic->fnic_lock, flags);
return;
}
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"fdmi timer callback : 0x%x\n", iport->fabric.fdmi_pending);
/* if not abort pending, send an abort */
if (!(iport->fabric.fdmi_pending & FDLS_FDMI_ABORT_PENDING)) {
fdls_send_fdmi_abts(iport);
spin_unlock_irqrestore(&fnic->fnic_lock, flags);
return;
}
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"fdmi timer callback : 0x%x\n", iport->fabric.fdmi_pending);
/* ABTS pending for an active fdmi request that is pending.
* That means FDMI ABTS timed out
* Schedule to free the OXID after 2*r_a_tov and proceed
*/
if (iport->fabric.fdmi_pending & FDLS_FDMI_PLOGI_PENDING) {
fdls_schedule_oxid_free(iport, &iport->active_oxid_fdmi_plogi);
} else {
if (iport->fabric.fdmi_pending & FDLS_FDMI_REG_HBA_PENDING)
fdls_schedule_oxid_free(iport, &iport->active_oxid_fdmi_rhba);
if (iport->fabric.fdmi_pending & FDLS_FDMI_RPA_PENDING)
fdls_schedule_oxid_free(iport, &iport->active_oxid_fdmi_rpa);
}
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"fdmi timer callback : 0x%x\n", iport->fabric.fdmi_pending);
iport->fabric.fdmi_pending = 0;
/* If max retries not exhaused, start over from fdmi plogi */
if (iport->fabric.fdmi_retry < FDLS_FDMI_MAX_RETRY) {
iport->fabric.fdmi_retry++;
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"retry fdmi timer %d", iport->fabric.fdmi_retry);
fdls_send_fdmi_plogi(iport);
}
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"fdmi timer callback : 0x%x\n", iport->fabric.fdmi_pending);
spin_unlock_irqrestore(&fnic->fnic_lock, flags);
}
static void fdls_send_delete_tport_msg(struct fnic_tport_s *tport)
{
struct fnic_iport_s *iport = (struct fnic_iport_s *) tport->iport;
struct fnic *fnic = iport->fnic;
struct fnic_tport_event_s *tport_del_evt;
tport_del_evt = kzalloc(sizeof(struct fnic_tport_event_s), GFP_ATOMIC);
if (!tport_del_evt) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Failed to allocate memory for tport event fcid: 0x%x",
tport->fcid);
return;
}
tport_del_evt->event = TGT_EV_TPORT_DELETE;
tport_del_evt->arg1 = (void *) tport;
list_add_tail(&tport_del_evt->links, &fnic->tport_event_list);
queue_work(fnic_event_queue, &fnic->tport_work);
}
static void fdls_tport_timer_callback(struct timer_list *t)
{
struct fnic_tport_s *tport = from_timer(tport, t, retry_timer);
struct fnic_iport_s *iport = (struct fnic_iport_s *) tport->iport;
struct fnic *fnic = iport->fnic;
uint16_t oxid;
unsigned long flags;
spin_lock_irqsave(&fnic->fnic_lock, flags);
if (!tport->timer_pending) {
spin_unlock_irqrestore(&fnic->fnic_lock, flags);
return;
}
if (iport->state != FNIC_IPORT_STATE_READY) {
spin_unlock_irqrestore(&fnic->fnic_lock, flags);
return;
}
if (tport->del_timer_inprogress) {
tport->del_timer_inprogress = 0;
spin_unlock_irqrestore(&fnic->fnic_lock, flags);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"tport_del_timer inprogress. Skip timer cb tport fcid: 0x%x\n",
tport->fcid);
return;
}
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"tport fcid: 0x%x timer pending: %d state: %d retry counter: %d",
tport->fcid, tport->timer_pending, tport->state,
tport->retry_counter);
tport->timer_pending = 0;
oxid = tport->active_oxid;
/* We retry plogi/prli/adisc frames depending on the tport state */
switch (tport->state) {
case FDLS_TGT_STATE_PLOGI:
/* PLOGI frame received a LS_RJT with busy, we retry from here */
if ((tport->flags & FNIC_FDLS_RETRY_FRAME)
&& (tport->retry_counter < iport->max_plogi_retries)) {
tport->flags &= ~FNIC_FDLS_RETRY_FRAME;
fdls_send_tgt_plogi(iport, tport);
} else if (!(tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED)) {
/* Plogi frame has timed out, send abts */
fdls_send_tport_abts(iport, tport);
} else if (tport->retry_counter < iport->max_plogi_retries) {
/*
* ABTS has timed out
*/
fdls_schedule_oxid_free(iport, &tport->active_oxid);
fdls_send_tgt_plogi(iport, tport);
} else {
/* exceeded plogi retry count */
fdls_schedule_oxid_free(iport, &tport->active_oxid);
fdls_send_delete_tport_msg(tport);
}
break;
case FDLS_TGT_STATE_PRLI:
/* PRLI received a LS_RJT with busy , hence we retry from here */
if ((tport->flags & FNIC_FDLS_RETRY_FRAME)
&& (tport->retry_counter < FDLS_RETRY_COUNT)) {
tport->flags &= ~FNIC_FDLS_RETRY_FRAME;
fdls_send_tgt_prli(iport, tport);
} else if (!(tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED)) {
/* PRLI has time out, send abts */
fdls_send_tport_abts(iport, tport);
} else {
/* ABTS has timed out for prli, we go back to PLOGI */
fdls_schedule_oxid_free(iport, &tport->active_oxid);
fdls_send_tgt_plogi(iport, tport);
fdls_set_tport_state(tport, FDLS_TGT_STATE_PLOGI);
}
break;
case FDLS_TGT_STATE_ADISC:
/* ADISC timed out send an ABTS */
if (!(tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED)) {
fdls_send_tport_abts(iport, tport);
} else if ((tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED)
&& (tport->retry_counter < FDLS_RETRY_COUNT)) {
/*
* ABTS has timed out
*/
fdls_schedule_oxid_free(iport, &tport->active_oxid);
fdls_send_tgt_adisc(iport, tport);
} else {
/* exceeded retry count */
fdls_schedule_oxid_free(iport, &tport->active_oxid);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"ADISC not responding. Deleting target port: 0x%x",
tport->fcid);
fdls_send_delete_tport_msg(tport);
}
break;
default:
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"oxid: 0x%x Unknown tport state: 0x%x", oxid, tport->state);
break;
}
spin_unlock_irqrestore(&fnic->fnic_lock, flags);
}
static void fnic_fdls_start_flogi(struct fnic_iport_s *iport)
{
iport->fabric.retry_counter = 0;
fdls_send_fabric_flogi(iport);
fdls_set_state((&iport->fabric), FDLS_STATE_FABRIC_FLOGI);
iport->fabric.flags = 0;
}
static void fnic_fdls_start_plogi(struct fnic_iport_s *iport)
{
iport->fabric.retry_counter = 0;
fdls_send_fabric_plogi(iport);
fdls_set_state((&iport->fabric), FDLS_STATE_FABRIC_PLOGI);
iport->fabric.flags &= ~FNIC_FDLS_FABRIC_ABORT_ISSUED;
if ((fnic_fdmi_support == 1) && (!(iport->flags & FNIC_FDMI_ACTIVE))) {
/* we can do FDMI at the same time */
iport->fabric.fdmi_retry = 0;
timer_setup(&iport->fabric.fdmi_timer, fdls_fdmi_timer_callback,
0);
fdls_send_fdmi_plogi(iport);
iport->flags |= FNIC_FDMI_ACTIVE;
}
}
static void
fdls_process_tgt_adisc_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
{
uint32_t tgt_fcid;
struct fnic_tport_s *tport;
uint8_t *fcid;
uint64_t frame_wwnn;
uint64_t frame_wwpn;
uint16_t oxid;
struct fc_std_els_adisc *adisc_rsp = (struct fc_std_els_adisc *)fchdr;
struct fc_std_els_rjt_rsp *els_rjt = (struct fc_std_els_rjt_rsp *)fchdr;
struct fnic *fnic = iport->fnic;
fcid = FNIC_STD_GET_S_ID(fchdr);
tgt_fcid = ntoh24(fcid);
tport = fnic_find_tport_by_fcid(iport, tgt_fcid);
if (!tport) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Tgt ADISC response tport not found: 0x%x", tgt_fcid);
return;
}
if ((iport->state != FNIC_IPORT_STATE_READY)
|| (tport->state != FDLS_TGT_STATE_ADISC)
|| (tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED)) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Dropping this ADISC response");
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"iport state: %d tport state: %d Is abort issued on PRLI? %d",
iport->state, tport->state,
(tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED));
return;
}
if (FNIC_STD_GET_OX_ID(fchdr) != tport->active_oxid) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Dropping frame from target: 0x%x",
tgt_fcid);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Reason: Stale ADISC/Aborted ADISC/OOO frame delivery");
return;
}
oxid = FNIC_STD_GET_OX_ID(fchdr);
fdls_free_oxid(iport, oxid, &tport->active_oxid);
switch (adisc_rsp->els.adisc_cmd) {
case ELS_LS_ACC:
atomic64_inc(&iport->iport_stats.tport_adisc_ls_accepts);
if (tport->timer_pending) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"tport 0x%p Canceling fabric disc timer\n",
tport);
fnic_del_tport_timer_sync(fnic, tport);
}
tport->timer_pending = 0;
tport->retry_counter = 0;
frame_wwnn = get_unaligned_be64(&adisc_rsp->els.adisc_wwnn);
frame_wwpn = get_unaligned_be64(&adisc_rsp->els.adisc_wwpn);
if ((frame_wwnn == tport->wwnn) && (frame_wwpn == tport->wwpn)) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"ADISC accepted from target: 0x%x. Target logged in",
tgt_fcid);
fdls_set_tport_state(tport, FDLS_TGT_STATE_READY);
} else {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Error mismatch frame: ADISC");
}
break;
case ELS_LS_RJT:
atomic64_inc(&iport->iport_stats.tport_adisc_ls_rejects);
if (((els_rjt->rej.er_reason == ELS_RJT_BUSY)
|| (els_rjt->rej.er_reason == ELS_RJT_UNAB))
&& (tport->retry_counter < FDLS_RETRY_COUNT)) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"ADISC ret ELS_LS_RJT BUSY. Retry from timer routine: 0x%x",
tgt_fcid);
/* Retry ADISC again from the timer routine. */
tport->flags |= FNIC_FDLS_RETRY_FRAME;
} else {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"ADISC returned ELS_LS_RJT from target: 0x%x",
tgt_fcid);
fdls_delete_tport(iport, tport);
}
break;
}
}
static void
fdls_process_tgt_plogi_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
{
uint32_t tgt_fcid;
struct fnic_tport_s *tport;
uint8_t *fcid;
uint16_t oxid;
struct fc_std_flogi *plogi_rsp = (struct fc_std_flogi *)fchdr;
struct fc_std_els_rjt_rsp *els_rjt = (struct fc_std_els_rjt_rsp *)fchdr;
uint16_t max_payload_size;
struct fnic *fnic = iport->fnic;
fcid = FNIC_STD_GET_S_ID(fchdr);
tgt_fcid = ntoh24(fcid);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"FDLS processing target PLOGI response: tgt_fcid: 0x%x",
tgt_fcid);
tport = fnic_find_tport_by_fcid(iport, tgt_fcid);
if (!tport) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"tport not found: 0x%x", tgt_fcid);
return;
}
if ((iport->state != FNIC_IPORT_STATE_READY)
|| (tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED)) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Dropping frame! iport state: %d tport state: %d",
iport->state, tport->state);
return;
}
if (tport->state != FDLS_TGT_STATE_PLOGI) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"PLOGI rsp recvd in wrong state. Drop the frame and restart nexus");
fdls_target_restart_nexus(tport);
return;
}
if (FNIC_STD_GET_OX_ID(fchdr) != tport->active_oxid) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"PLOGI response from target: 0x%x. Dropping frame",
tgt_fcid);
return;
}
oxid = FNIC_STD_GET_OX_ID(fchdr);
fdls_free_oxid(iport, oxid, &tport->active_oxid);
switch (plogi_rsp->els.fl_cmd) {
case ELS_LS_ACC:
atomic64_inc(&iport->iport_stats.tport_plogi_ls_accepts);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"PLOGI accepted by target: 0x%x", tgt_fcid);
break;
case ELS_LS_RJT:
atomic64_inc(&iport->iport_stats.tport_plogi_ls_rejects);
if (((els_rjt->rej.er_reason == ELS_RJT_BUSY)
|| (els_rjt->rej.er_reason == ELS_RJT_UNAB))
&& (tport->retry_counter < iport->max_plogi_retries)) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"PLOGI ret ELS_LS_RJT BUSY. Retry from timer routine: 0x%x",
tgt_fcid);
/* Retry plogi again from the timer routine. */
tport->flags |= FNIC_FDLS_RETRY_FRAME;
return;
}
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"PLOGI returned ELS_LS_RJT from target: 0x%x",
tgt_fcid);
fdls_delete_tport(iport, tport);
return;
default:
atomic64_inc(&iport->iport_stats.tport_plogi_misc_rejects);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"PLOGI not accepted from target fcid: 0x%x",
tgt_fcid);
return;
}
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Found the PLOGI target: 0x%x and state: %d",
(unsigned int) tgt_fcid, tport->state);
if (tport->timer_pending) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"tport fcid 0x%x: Canceling disc timer\n",
tport->fcid);
fnic_del_tport_timer_sync(fnic, tport);
}
tport->timer_pending = 0;
tport->wwpn = get_unaligned_be64(&FNIC_LOGI_PORT_NAME(plogi_rsp->els));
tport->wwnn = get_unaligned_be64(&FNIC_LOGI_NODE_NAME(plogi_rsp->els));
/* Learn the Service Params */
/* Max frame size - choose the lowest */
max_payload_size = fnic_fc_plogi_rsp_rdf(iport, plogi_rsp);
tport->max_payload_size =
min(max_payload_size, iport->max_payload_size);
if (tport->max_payload_size < FNIC_MIN_DATA_FIELD_SIZE) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"MFS: tport max frame size below spec bounds: %d",
tport->max_payload_size);
tport->max_payload_size = FNIC_MIN_DATA_FIELD_SIZE;
}
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"MAX frame size: %u iport max_payload_size: %d tport mfs: %d",
max_payload_size, iport->max_payload_size,
tport->max_payload_size);
tport->max_concur_seqs = FNIC_FC_PLOGI_RSP_CONCUR_SEQ(plogi_rsp);
tport->retry_counter = 0;
fdls_set_tport_state(tport, FDLS_TGT_STATE_PRLI);
fdls_send_tgt_prli(iport, tport);
}
static void
fdls_process_tgt_prli_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
{
uint32_t tgt_fcid;
struct fnic_tport_s *tport;
uint8_t *fcid;
uint16_t oxid;
struct fc_std_els_prli *prli_rsp = (struct fc_std_els_prli *)fchdr;
struct fc_std_els_rjt_rsp *els_rjt = (struct fc_std_els_rjt_rsp *)fchdr;
struct fnic_tport_event_s *tport_add_evt;
struct fnic *fnic = iport->fnic;
bool mismatched_tgt = false;
fcid = FNIC_STD_GET_S_ID(fchdr);
tgt_fcid = ntoh24(fcid);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"FDLS process tgt PRLI response: 0x%x", tgt_fcid);
tport = fnic_find_tport_by_fcid(iport, tgt_fcid);
if (!tport) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"tport not found: 0x%x", tgt_fcid);
/* Handle or just drop? */
return;
}
if ((iport->state != FNIC_IPORT_STATE_READY)
|| (tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED)) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Dropping frame! iport st: %d tport st: %d tport fcid: 0x%x",
iport->state, tport->state, tport->fcid);
return;
}
if (tport->state != FDLS_TGT_STATE_PRLI) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"PRLI rsp recvd in wrong state. Drop frame. Restarting nexus");
fdls_target_restart_nexus(tport);
return;
}
if (FNIC_STD_GET_OX_ID(fchdr) != tport->active_oxid) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Dropping PRLI response from target: 0x%x ",
tgt_fcid);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Reason: Stale PRLI response/Aborted PDISC/OOO frame delivery");
return;
}
oxid = FNIC_STD_GET_OX_ID(fchdr);
fdls_free_oxid(iport, oxid, &tport->active_oxid);
switch (prli_rsp->els_prli.prli_cmd) {
case ELS_LS_ACC:
atomic64_inc(&iport->iport_stats.tport_prli_ls_accepts);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"PRLI accepted from target: 0x%x", tgt_fcid);
if (prli_rsp->sp.spp_type != FC_FC4_TYPE_SCSI) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"mismatched target zoned with FC SCSI initiator: 0x%x",
tgt_fcid);
mismatched_tgt = true;
}
if (mismatched_tgt) {
fdls_tgt_logout(iport, tport);
fdls_delete_tport(iport, tport);
return;
}
break;
case ELS_LS_RJT:
atomic64_inc(&iport->iport_stats.tport_prli_ls_rejects);
if (((els_rjt->rej.er_reason == ELS_RJT_BUSY)
|| (els_rjt->rej.er_reason == ELS_RJT_UNAB))
&& (tport->retry_counter < FDLS_RETRY_COUNT)) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"PRLI ret ELS_LS_RJT BUSY. Retry from timer routine: 0x%x",
tgt_fcid);
/*Retry Plogi again from the timer routine. */
tport->flags |= FNIC_FDLS_RETRY_FRAME;
return;
}
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"PRLI returned ELS_LS_RJT from target: 0x%x",
tgt_fcid);
fdls_tgt_logout(iport, tport);
fdls_delete_tport(iport, tport);
return;
default:
atomic64_inc(&iport->iport_stats.tport_prli_misc_rejects);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"PRLI not accepted from target: 0x%x", tgt_fcid);
return;
}
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Found the PRLI target: 0x%x and state: %d",
(unsigned int) tgt_fcid, tport->state);
if (tport->timer_pending) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"tport fcid 0x%x: Canceling disc timer\n",
tport->fcid);
fnic_del_tport_timer_sync(fnic, tport);
}
tport->timer_pending = 0;
/* Learn Service Params */
tport->fcp_csp = be32_to_cpu(prli_rsp->sp.spp_params);
tport->retry_counter = 0;
if (tport->fcp_csp & FCP_SPPF_RETRY)
tport->tgt_flags |= FNIC_FC_RP_FLAGS_RETRY;
/* Check if the device plays Target Mode Function */
if (!(tport->fcp_csp & FCP_PRLI_FUNC_TARGET)) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Remote port(0x%x): no target support. Deleting it\n",
tgt_fcid);
fdls_tgt_logout(iport, tport);
fdls_delete_tport(iport, tport);
return;
}
fdls_set_tport_state(tport, FDLS_TGT_STATE_READY);
/* Inform the driver about new target added */
tport_add_evt = kzalloc(sizeof(struct fnic_tport_event_s), GFP_ATOMIC);
if (!tport_add_evt) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"tport event memory allocation failure: 0x%0x\n",
tport->fcid);
return;
}
tport_add_evt->event = TGT_EV_RPORT_ADD;
tport_add_evt->arg1 = (void *) tport;
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"iport fcid: 0x%x add tport event fcid: 0x%x\n",
tport->fcid, iport->fcid);
list_add_tail(&tport_add_evt->links, &fnic->tport_event_list);
queue_work(fnic_event_queue, &fnic->tport_work);
}
static void
fdls_process_rff_id_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
{
struct fnic *fnic = iport->fnic;
struct fnic_fdls_fabric_s *fdls = &iport->fabric;
struct fc_std_rff_id *rff_rsp = (struct fc_std_rff_id *) fchdr;
uint16_t rsp;
uint8_t reason_code;
uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr);
if (fdls_get_state(fdls) != FDLS_STATE_REGISTER_FC4_FEATURES) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"RFF_ID resp recvd in state(%d). Dropping.",
fdls_get_state(fdls));
return;
}
if (iport->active_oxid_fabric_req != oxid) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n",
fdls_get_state(fdls), oxid, iport->active_oxid_fabric_req);
return;
}
rsp = FNIC_STD_GET_FC_CT_CMD((&rff_rsp->fc_std_ct_hdr));
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS process RFF ID response: 0x%04x", iport->fcid,
(uint32_t) rsp);
fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req);
switch (rsp) {
case FC_FS_ACC:
if (iport->fabric.timer_pending) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Canceling fabric disc timer %p\n", iport);
fnic_del_fabric_timer_sync(fnic);
}
iport->fabric.timer_pending = 0;
fdls->retry_counter = 0;
fdls_set_state((&iport->fabric), FDLS_STATE_SCR);
fdls_send_scr(iport);
break;
case FC_FS_RJT:
reason_code = rff_rsp->fc_std_ct_hdr.ct_reason;
if (((reason_code == FC_FS_RJT_BSY)
|| (reason_code == FC_FS_RJT_UNABL))
&& (fdls->retry_counter < FDLS_RETRY_COUNT)) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"RFF_ID ret ELS_LS_RJT BUSY. Retry from timer routine %p",
iport);
/* Retry again from the timer routine */
fdls->flags |= FNIC_FDLS_RETRY_FRAME;
} else {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"RFF_ID returned ELS_LS_RJT. Halting discovery %p",
iport);
if (iport->fabric.timer_pending) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Canceling fabric disc timer %p\n", iport);
fnic_del_fabric_timer_sync(fnic);
}
fdls->timer_pending = 0;
fdls->retry_counter = 0;
}
break;
default:
break;
}
}
static void
fdls_process_rft_id_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
{
struct fnic_fdls_fabric_s *fdls = &iport->fabric;
struct fc_std_rft_id *rft_rsp = (struct fc_std_rft_id *) fchdr;
uint16_t rsp;
uint8_t reason_code;
struct fnic *fnic = iport->fnic;
uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr);
if (fdls_get_state(fdls) != FDLS_STATE_REGISTER_FC4_TYPES) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"RFT_ID resp recvd in state(%d). Dropping.",
fdls_get_state(fdls));
return;
}
if (iport->active_oxid_fabric_req != oxid) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n",
fdls_get_state(fdls), oxid, iport->active_oxid_fabric_req);
return;
}
rsp = FNIC_STD_GET_FC_CT_CMD((&rft_rsp->fc_std_ct_hdr));
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS process RFT ID response: 0x%04x", iport->fcid,
(uint32_t) rsp);
fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req);
switch (rsp) {
case FC_FS_ACC:
if (iport->fabric.timer_pending) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Canceling fabric disc timer %p\n", iport);
fnic_del_fabric_timer_sync(fnic);
}
iport->fabric.timer_pending = 0;
fdls->retry_counter = 0;
fdls_send_register_fc4_features(iport);
fdls_set_state((&iport->fabric), FDLS_STATE_REGISTER_FC4_FEATURES);
break;
case FC_FS_RJT:
reason_code = rft_rsp->fc_std_ct_hdr.ct_reason;
if (((reason_code == FC_FS_RJT_BSY)
|| (reason_code == FC_FS_RJT_UNABL))
&& (fdls->retry_counter < FDLS_RETRY_COUNT)) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: RFT_ID ret ELS_LS_RJT BUSY. Retry from timer routine",
iport->fcid);
/* Retry again from the timer routine */
fdls->flags |= FNIC_FDLS_RETRY_FRAME;
} else {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: RFT_ID REJ. Halting discovery reason %d expl %d",
iport->fcid, reason_code,
rft_rsp->fc_std_ct_hdr.ct_explan);
if (iport->fabric.timer_pending) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Canceling fabric disc timer %p\n", iport);
fnic_del_fabric_timer_sync(fnic);
}
fdls->timer_pending = 0;
fdls->retry_counter = 0;
}
break;
default:
break;
}
}
static void
fdls_process_rpn_id_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
{
struct fnic_fdls_fabric_s *fdls = &iport->fabric;
struct fc_std_rpn_id *rpn_rsp = (struct fc_std_rpn_id *) fchdr;
uint16_t rsp;
uint8_t reason_code;
struct fnic *fnic = iport->fnic;
uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr);
if (fdls_get_state(fdls) != FDLS_STATE_RPN_ID) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"RPN_ID resp recvd in state(%d). Dropping.",
fdls_get_state(fdls));
return;
}
if (iport->active_oxid_fabric_req != oxid) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n",
fdls_get_state(fdls), oxid, iport->active_oxid_fabric_req);
return;
}
rsp = FNIC_STD_GET_FC_CT_CMD((&rpn_rsp->fc_std_ct_hdr));
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS process RPN ID response: 0x%04x", iport->fcid,
(uint32_t) rsp);
fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req);
switch (rsp) {
case FC_FS_ACC:
if (iport->fabric.timer_pending) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Canceling fabric disc timer %p\n", iport);
fnic_del_fabric_timer_sync(fnic);
}
iport->fabric.timer_pending = 0;
fdls->retry_counter = 0;
fdls_send_register_fc4_types(iport);
fdls_set_state((&iport->fabric), FDLS_STATE_REGISTER_FC4_TYPES);
break;
case FC_FS_RJT:
reason_code = rpn_rsp->fc_std_ct_hdr.ct_reason;
if (((reason_code == FC_FS_RJT_BSY)
|| (reason_code == FC_FS_RJT_UNABL))
&& (fdls->retry_counter < FDLS_RETRY_COUNT)) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"RPN_ID returned REJ BUSY. Retry from timer routine %p",
iport);
/* Retry again from the timer routine */
fdls->flags |= FNIC_FDLS_RETRY_FRAME;
} else {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"RPN_ID ELS_LS_RJT. Halting discovery %p", iport);
if (iport->fabric.timer_pending) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Canceling fabric disc timer %p\n", iport);
fnic_del_fabric_timer_sync(fnic);
}
fdls->timer_pending = 0;
fdls->retry_counter = 0;
}
break;
default:
break;
}
}
static void
fdls_process_scr_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
{
struct fnic_fdls_fabric_s *fdls = &iport->fabric;
struct fc_std_scr *scr_rsp = (struct fc_std_scr *) fchdr;
struct fc_std_els_rjt_rsp *els_rjt = (struct fc_std_els_rjt_rsp *) fchdr;
struct fnic *fnic = iport->fnic;
uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"FDLS process SCR response: 0x%04x",
(uint32_t) scr_rsp->scr.scr_cmd);
if (fdls_get_state(fdls) != FDLS_STATE_SCR) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"SCR resp recvd in state(%d). Dropping.",
fdls_get_state(fdls));
return;
}
if (iport->active_oxid_fabric_req != oxid) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n",
fdls_get_state(fdls), oxid, iport->active_oxid_fabric_req);
}
fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req);
switch (scr_rsp->scr.scr_cmd) {
case ELS_LS_ACC:
atomic64_inc(&iport->iport_stats.fabric_scr_ls_accepts);
if (iport->fabric.timer_pending) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Canceling fabric disc timer %p\n", iport);
fnic_del_fabric_timer_sync(fnic);
}
iport->fabric.timer_pending = 0;
iport->fabric.retry_counter = 0;
fdls_send_gpn_ft(iport, FDLS_STATE_GPN_FT);
break;
case ELS_LS_RJT:
atomic64_inc(&iport->iport_stats.fabric_scr_ls_rejects);
if (((els_rjt->rej.er_reason == ELS_RJT_BUSY)
|| (els_rjt->rej.er_reason == ELS_RJT_UNAB))
&& (fdls->retry_counter < FDLS_RETRY_COUNT)) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"SCR ELS_LS_RJT BUSY. Retry from timer routine %p",
iport);
/* Retry again from the timer routine */
fdls->flags |= FNIC_FDLS_RETRY_FRAME;
} else {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"SCR returned ELS_LS_RJT. Halting discovery %p",
iport);
if (iport->fabric.timer_pending) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Canceling fabric disc timer %p\n",
iport);
fnic_del_fabric_timer_sync(fnic);
}
fdls->timer_pending = 0;
fdls->retry_counter = 0;
}
break;
default:
atomic64_inc(&iport->iport_stats.fabric_scr_misc_rejects);
break;
}
}
static void
fdls_process_gpn_ft_tgt_list(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr, int len)
{
struct fc_gpn_ft_rsp_iu *gpn_ft_tgt;
struct fnic_tport_s *tport, *next;
uint32_t fcid;
uint64_t wwpn;
int rem_len = len;
u32 old_link_down_cnt = iport->fnic->link_down_cnt;
struct fnic *fnic = iport->fnic;
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS process GPN_FT tgt list", iport->fcid);
gpn_ft_tgt =
(struct fc_gpn_ft_rsp_iu *)((uint8_t *) fchdr +
sizeof(struct fc_frame_header)
+ sizeof(struct fc_ct_hdr));
len -= sizeof(struct fc_frame_header) + sizeof(struct fc_ct_hdr);
while (rem_len > 0) {
fcid = ntoh24(gpn_ft_tgt->fcid);
wwpn = be64_to_cpu(gpn_ft_tgt->wwpn);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"tport: 0x%x: ctrl:0x%x", fcid, gpn_ft_tgt->ctrl);
if (fcid == iport->fcid) {
if (gpn_ft_tgt->ctrl & FC_NS_FID_LAST)
break;
gpn_ft_tgt++;
rem_len -= sizeof(struct fc_gpn_ft_rsp_iu);
continue;
}
tport = fnic_find_tport_by_wwpn(iport, wwpn);
if (!tport) {
/*
* New port registered with the switch or first time query
*/
tport = fdls_create_tport(iport, fcid, wwpn);
if (!tport)
return;
}
/*
* check if this was an existing tport with same fcid
* but whose wwpn has changed now ,then remove it and
* create a new one
*/
if (tport->fcid != fcid) {
fdls_delete_tport(iport, tport);
tport = fdls_create_tport(iport, fcid, wwpn);
if (!tport)
return;
}
/*
* If this GPN_FT rsp is after RSCN then mark the tports which
* matches with the new GPN_FT list, if some tport is not
* found in GPN_FT we went to delete that tport later.
*/
if (fdls_get_state((&iport->fabric)) == FDLS_STATE_RSCN_GPN_FT)
tport->flags |= FNIC_FDLS_TPORT_IN_GPN_FT_LIST;
if (gpn_ft_tgt->ctrl & FC_NS_FID_LAST)
break;
gpn_ft_tgt++;
rem_len -= sizeof(struct fc_gpn_ft_rsp_iu);
}
if (rem_len <= 0) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"GPN_FT response: malformed/corrupt frame rxlen: %d remlen: %d",
len, rem_len);
}
/*remove those ports which was not listed in GPN_FT */
if (fdls_get_state((&iport->fabric)) == FDLS_STATE_RSCN_GPN_FT) {
list_for_each_entry_safe(tport, next, &iport->tport_list, links) {
if (!(tport->flags & FNIC_FDLS_TPORT_IN_GPN_FT_LIST)) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Remove port: 0x%x not found in GPN_FT list",
tport->fcid);
fdls_delete_tport(iport, tport);
} else {
tport->flags &= ~FNIC_FDLS_TPORT_IN_GPN_FT_LIST;
}
if ((old_link_down_cnt != iport->fnic->link_down_cnt)
|| (iport->state != FNIC_IPORT_STATE_READY)) {
return;
}
}
}
}
static void
fdls_process_gpn_ft_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr, int len)
{
struct fnic_fdls_fabric_s *fdls = &iport->fabric;
struct fc_std_gpn_ft *gpn_ft_rsp = (struct fc_std_gpn_ft *) fchdr;
uint16_t rsp;
uint8_t reason_code;
int count = 0;
struct fnic_tport_s *tport, *next;
u32 old_link_down_cnt = iport->fnic->link_down_cnt;
struct fnic *fnic = iport->fnic;
uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"FDLS process GPN_FT response: iport state: %d len: %d",
iport->state, len);
/*
* GPNFT response :-
* FDLS_STATE_GPN_FT : GPNFT send after SCR state
* during fabric discovery(FNIC_IPORT_STATE_FABRIC_DISC)
* FDLS_STATE_RSCN_GPN_FT : GPNFT send in response to RSCN
* FDLS_STATE_SEND_GPNFT : GPNFT send after deleting a Target,
* e.g. after receiving Target LOGO
* FDLS_STATE_TGT_DISCOVERY :Target discovery is currently in progress
* from previous GPNFT response,a new GPNFT response has come.
*/
if (!(((iport->state == FNIC_IPORT_STATE_FABRIC_DISC)
&& (fdls_get_state(fdls) == FDLS_STATE_GPN_FT))
|| ((iport->state == FNIC_IPORT_STATE_READY)
&& ((fdls_get_state(fdls) == FDLS_STATE_RSCN_GPN_FT)
|| (fdls_get_state(fdls) == FDLS_STATE_SEND_GPNFT)
|| (fdls_get_state(fdls) == FDLS_STATE_TGT_DISCOVERY))))) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"GPNFT resp recvd in fab state(%d) iport_state(%d). Dropping.",
fdls_get_state(fdls), iport->state);
return;
}
if (iport->active_oxid_fabric_req != oxid) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n",
fdls_get_state(fdls), oxid, iport->active_oxid_fabric_req);
}
fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req);
iport->state = FNIC_IPORT_STATE_READY;
rsp = FNIC_STD_GET_FC_CT_CMD((&gpn_ft_rsp->fc_std_ct_hdr));
switch (rsp) {
case FC_FS_ACC:
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: GPNFT_RSP accept", iport->fcid);
if (iport->fabric.timer_pending) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: Canceling fabric disc timer\n",
iport->fcid);
fnic_del_fabric_timer_sync(fnic);
}
iport->fabric.timer_pending = 0;
iport->fabric.retry_counter = 0;
fdls_process_gpn_ft_tgt_list(iport, fchdr, len);
/*
* iport state can change only if link down event happened
* We don't need to undo fdls_process_gpn_ft_tgt_list,
* that will be taken care in next link up event
*/
if (iport->state != FNIC_IPORT_STATE_READY) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Halting target discovery: fab st: %d iport st: %d ",
fdls_get_state(fdls), iport->state);
break;
}
fdls_tgt_discovery_start(iport);
break;
case FC_FS_RJT:
reason_code = gpn_ft_rsp->fc_std_ct_hdr.ct_reason;
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: GPNFT_RSP Reject reason: %d", iport->fcid, reason_code);
if (((reason_code == FC_FS_RJT_BSY)
|| (reason_code == FC_FS_RJT_UNABL))
&& (fdls->retry_counter < FDLS_RETRY_COUNT)) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: GPNFT_RSP ret REJ/BSY. Retry from timer routine",
iport->fcid);
/* Retry again from the timer routine */
fdls->flags |= FNIC_FDLS_RETRY_FRAME;
} else {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: GPNFT_RSP reject", iport->fcid);
if (iport->fabric.timer_pending) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: Canceling fabric disc timer\n",
iport->fcid);
fnic_del_fabric_timer_sync(fnic);
}
iport->fabric.timer_pending = 0;
iport->fabric.retry_counter = 0;
/*
* If GPN_FT ls_rjt then we should delete
* all existing tports
*/
count = 0;
list_for_each_entry_safe(tport, next, &iport->tport_list,
links) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"GPN_FT_REJECT: Remove port: 0x%x",
tport->fcid);
fdls_delete_tport(iport, tport);
if ((old_link_down_cnt != iport->fnic->link_down_cnt)
|| (iport->state != FNIC_IPORT_STATE_READY)) {
return;
}
count++;
}
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"GPN_FT_REJECT: Removed (0x%x) ports", count);
}
break;
default:
break;
}
}
/**
* fdls_process_fabric_logo_rsp - Handle an flogo response from the fcf
* @iport: Handle to fnic iport
* @fchdr: Incoming frame
*/
static void
fdls_process_fabric_logo_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
{
struct fc_std_flogi *flogo_rsp = (struct fc_std_flogi *) fchdr;
struct fnic_fdls_fabric_s *fdls = &iport->fabric;
struct fnic *fnic = iport->fnic;
uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr);
if (iport->active_oxid_fabric_req != oxid) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n",
fdls_get_state(fdls), oxid, iport->active_oxid_fabric_req);
}
fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req);
switch (flogo_rsp->els.fl_cmd) {
case ELS_LS_ACC:
if (iport->fabric.state != FDLS_STATE_FABRIC_LOGO) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Flogo response. Fabric not in LOGO state. Dropping! %p",
iport);
return;
}
iport->fabric.state = FDLS_STATE_FLOGO_DONE;
iport->state = FNIC_IPORT_STATE_LINK_WAIT;
if (iport->fabric.timer_pending) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"iport 0x%p Canceling fabric disc timer\n",
iport);
fnic_del_fabric_timer_sync(fnic);
}
iport->fabric.timer_pending = 0;
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Flogo response from Fabric for did: 0x%x",
ntoh24(fchdr->fh_d_id));
return;
case ELS_LS_RJT:
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Flogo response from Fabric for did: 0x%x returned ELS_LS_RJT",
ntoh24(fchdr->fh_d_id));
return;
default:
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"FLOGO response not accepted or rejected: 0x%x",
flogo_rsp->els.fl_cmd);
}
}
static void
fdls_process_flogi_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr, void *rx_frame)
{
struct fnic_fdls_fabric_s *fabric = &iport->fabric;
struct fc_std_flogi *flogi_rsp = (struct fc_std_flogi *) fchdr;
uint8_t *fcid;
uint16_t rdf_size;
uint8_t fcmac[6] = { 0x0E, 0XFC, 0x00, 0x00, 0x00, 0x00 };
struct fnic *fnic = iport->fnic;
uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS processing FLOGI response", iport->fcid);
if (fdls_get_state(fabric) != FDLS_STATE_FABRIC_FLOGI) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"FLOGI response received in state (%d). Dropping frame",
fdls_get_state(fabric));
return;
}
if (iport->active_oxid_fabric_req != oxid) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n",
fdls_get_state(fabric), oxid, iport->active_oxid_fabric_req);
return;
}
fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req);
switch (flogi_rsp->els.fl_cmd) {
case ELS_LS_ACC:
atomic64_inc(&iport->iport_stats.fabric_flogi_ls_accepts);
if (iport->fabric.timer_pending) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"iport fcid: 0x%x Canceling fabric disc timer\n",
iport->fcid);
fnic_del_fabric_timer_sync(fnic);
}
iport->fabric.timer_pending = 0;
iport->fabric.retry_counter = 0;
fcid = FNIC_STD_GET_D_ID(fchdr);
iport->fcid = ntoh24(fcid);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FLOGI response accepted", iport->fcid);
/* Learn the Service Params */
rdf_size = be16_to_cpu(FNIC_LOGI_RDF_SIZE(flogi_rsp->els));
if ((rdf_size >= FNIC_MIN_DATA_FIELD_SIZE)
&& (rdf_size < FNIC_FC_MAX_PAYLOAD_LEN))
iport->max_payload_size = min(rdf_size,
iport->max_payload_size);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"max_payload_size from fabric: %u set: %d", rdf_size,
iport->max_payload_size);
iport->r_a_tov = be32_to_cpu(FNIC_LOGI_R_A_TOV(flogi_rsp->els));
iport->e_d_tov = be32_to_cpu(FNIC_LOGI_E_D_TOV(flogi_rsp->els));
if (FNIC_LOGI_FEATURES(flogi_rsp->els) & FNIC_FC_EDTOV_NSEC)
iport->e_d_tov = iport->e_d_tov / FNIC_NSEC_TO_MSEC;
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"From fabric: R_A_TOV: %d E_D_TOV: %d",
iport->r_a_tov, iport->e_d_tov);
fc_host_fabric_name(iport->fnic->host) =
get_unaligned_be64(&FNIC_LOGI_NODE_NAME(flogi_rsp->els));
fc_host_port_id(iport->fnic->host) = iport->fcid;
fnic_fdls_learn_fcoe_macs(iport, rx_frame, fcid);
if (fnic_fdls_register_portid(iport, iport->fcid, rx_frame) != 0) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FLOGI registration failed", iport->fcid);
break;
}
memcpy(&fcmac[3], fcid, 3);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Adding vNIC device MAC addr: %02x:%02x:%02x:%02x:%02x:%02x",
fcmac[0], fcmac[1], fcmac[2], fcmac[3], fcmac[4],
fcmac[5]);
vnic_dev_add_addr(iport->fnic->vdev, fcmac);
if (fdls_get_state(fabric) == FDLS_STATE_FABRIC_FLOGI) {
fnic_fdls_start_plogi(iport);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"FLOGI response received. Starting PLOGI");
} else {
/* From FDLS_STATE_FABRIC_FLOGI state fabric can only go to
* FDLS_STATE_LINKDOWN
* state, hence we don't have to worry about undoing:
* the fnic_fdls_register_portid and vnic_dev_add_addr
*/
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"FLOGI response received in state (%d). Dropping frame",
fdls_get_state(fabric));
}
break;
case ELS_LS_RJT:
atomic64_inc(&iport->iport_stats.fabric_flogi_ls_rejects);
if (fabric->retry_counter < iport->max_flogi_retries) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"FLOGI returned ELS_LS_RJT BUSY. Retry from timer routine %p",
iport);
/* Retry Flogi again from the timer routine. */
fabric->flags |= FNIC_FDLS_RETRY_FRAME;
} else {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"FLOGI returned ELS_LS_RJT. Halting discovery %p",
iport);
if (iport->fabric.timer_pending) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"iport 0x%p Canceling fabric disc timer\n",
iport);
fnic_del_fabric_timer_sync(fnic);
}
fabric->timer_pending = 0;
fabric->retry_counter = 0;
}
break;
default:
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"FLOGI response not accepted: 0x%x",
flogi_rsp->els.fl_cmd);
atomic64_inc(&iport->iport_stats.fabric_flogi_misc_rejects);
break;
}
}
static void
fdls_process_fabric_plogi_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
{
struct fc_std_flogi *plogi_rsp = (struct fc_std_flogi *) fchdr;
struct fc_std_els_rjt_rsp *els_rjt = (struct fc_std_els_rjt_rsp *) fchdr;
struct fnic_fdls_fabric_s *fdls = &iport->fabric;
struct fnic *fnic = iport->fnic;
uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr);
if (fdls_get_state((&iport->fabric)) != FDLS_STATE_FABRIC_PLOGI) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Fabric PLOGI response received in state (%d). Dropping frame",
fdls_get_state(&iport->fabric));
return;
}
if (iport->active_oxid_fabric_req != oxid) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n",
fdls_get_state(fdls), oxid, iport->active_oxid_fabric_req);
return;
}
fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req);
switch (plogi_rsp->els.fl_cmd) {
case ELS_LS_ACC:
atomic64_inc(&iport->iport_stats.fabric_plogi_ls_accepts);
if (iport->fabric.timer_pending) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"iport fcid: 0x%x fabric PLOGI response: Accepted\n",
iport->fcid);
fnic_del_fabric_timer_sync(fnic);
}
iport->fabric.timer_pending = 0;
iport->fabric.retry_counter = 0;
fdls_set_state(&iport->fabric, FDLS_STATE_RPN_ID);
fdls_send_rpn_id(iport);
break;
case ELS_LS_RJT:
atomic64_inc(&iport->iport_stats.fabric_plogi_ls_rejects);
if (((els_rjt->rej.er_reason == ELS_RJT_BUSY)
|| (els_rjt->rej.er_reason == ELS_RJT_UNAB))
&& (iport->fabric.retry_counter < iport->max_plogi_retries)) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: Fabric PLOGI ELS_LS_RJT BUSY. Retry from timer routine",
iport->fcid);
} else {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: Fabric PLOGI ELS_LS_RJT. Halting discovery",
iport->fcid);
if (iport->fabric.timer_pending) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"iport fcid: 0x%x Canceling fabric disc timer\n",
iport->fcid);
fnic_del_fabric_timer_sync(fnic);
}
iport->fabric.timer_pending = 0;
iport->fabric.retry_counter = 0;
return;
}
break;
default:
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"PLOGI response not accepted: 0x%x",
plogi_rsp->els.fl_cmd);
atomic64_inc(&iport->iport_stats.fabric_plogi_misc_rejects);
break;
}
}
static void fdls_process_fdmi_plogi_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
{
struct fc_std_flogi *plogi_rsp = (struct fc_std_flogi *)fchdr;
struct fc_std_els_rjt_rsp *els_rjt = (struct fc_std_els_rjt_rsp *)fchdr;
struct fnic_fdls_fabric_s *fdls = &iport->fabric;
struct fnic *fnic = iport->fnic;
u64 fdmi_tov;
uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr);
if (iport->active_oxid_fdmi_plogi != oxid) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n",
fdls_get_state(fdls), oxid, iport->active_oxid_fdmi_plogi);
return;
}
iport->fabric.fdmi_pending &= ~FDLS_FDMI_PLOGI_PENDING;
fdls_free_oxid(iport, oxid, &iport->active_oxid_fdmi_plogi);
if (ntoh24(fchdr->fh_s_id) == FC_FID_MGMT_SERV) {
timer_delete_sync(&iport->fabric.fdmi_timer);
iport->fabric.fdmi_pending = 0;
switch (plogi_rsp->els.fl_cmd) {
case ELS_LS_ACC:
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"FDLS process fdmi PLOGI response status: ELS_LS_ACC\n");
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Sending fdmi registration for port 0x%x\n",
iport->fcid);
fdls_fdmi_register_hba(iport);
fdls_fdmi_register_pa(iport);
fdmi_tov = jiffies + msecs_to_jiffies(5000);
mod_timer(&iport->fabric.fdmi_timer,
round_jiffies(fdmi_tov));
break;
case ELS_LS_RJT:
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Fabric FDMI PLOGI returned ELS_LS_RJT reason: 0x%x",
els_rjt->rej.er_reason);
if (((els_rjt->rej.er_reason == ELS_RJT_BUSY)
|| (els_rjt->rej.er_reason == ELS_RJT_UNAB))
&& (iport->fabric.fdmi_retry < 7)) {
iport->fabric.fdmi_retry++;
fdls_send_fdmi_plogi(iport);
}
break;
default:
break;
}
}
}
static void fdls_process_fdmi_reg_ack(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr,
int rsp_type)
{
struct fnic *fnic = iport->fnic;
uint16_t oxid;
if (!iport->fabric.fdmi_pending) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Received FDMI ack while not waiting: 0x%x\n",
FNIC_STD_GET_OX_ID(fchdr));
return;
}
oxid = FNIC_STD_GET_OX_ID(fchdr);
if ((iport->active_oxid_fdmi_rhba != oxid) &&
(iport->active_oxid_fdmi_rpa != oxid)) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Incorrect OXID in response. oxid recvd: 0x%x, active oxids(rhba,rpa): 0x%x, 0x%x\n",
oxid, iport->active_oxid_fdmi_rhba, iport->active_oxid_fdmi_rpa);
return;
}
if (FNIC_FRAME_TYPE(oxid) == FNIC_FRAME_TYPE_FDMI_RHBA) {
iport->fabric.fdmi_pending &= ~FDLS_FDMI_REG_HBA_PENDING;
fdls_free_oxid(iport, oxid, &iport->active_oxid_fdmi_rhba);
} else {
iport->fabric.fdmi_pending &= ~FDLS_FDMI_RPA_PENDING;
fdls_free_oxid(iport, oxid, &iport->active_oxid_fdmi_rpa);
}
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"iport fcid: 0x%x: Received FDMI registration ack\n",
iport->fcid);
if (!iport->fabric.fdmi_pending) {
timer_delete_sync(&iport->fabric.fdmi_timer);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"iport fcid: 0x%x: Canceling FDMI timer\n",
iport->fcid);
}
}
static void fdls_process_fdmi_abts_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
{
uint32_t s_id;
struct fnic *fnic = iport->fnic;
uint16_t oxid;
s_id = ntoh24(FNIC_STD_GET_S_ID(fchdr));
if (!(s_id != FC_FID_MGMT_SERV)) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Received abts rsp with invalid SID: 0x%x. Dropping frame",
s_id);
return;
}
oxid = FNIC_STD_GET_OX_ID(fchdr);
switch (FNIC_FRAME_TYPE(oxid)) {
case FNIC_FRAME_TYPE_FDMI_PLOGI:
fdls_free_oxid(iport, oxid, &iport->active_oxid_fdmi_plogi);
break;
case FNIC_FRAME_TYPE_FDMI_RHBA:
fdls_free_oxid(iport, oxid, &iport->active_oxid_fdmi_rhba);
break;
case FNIC_FRAME_TYPE_FDMI_RPA:
fdls_free_oxid(iport, oxid, &iport->active_oxid_fdmi_rpa);
break;
default:
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Received abts rsp with invalid oxid: 0x%x. Dropping frame",
oxid);
break;
}
timer_delete_sync(&iport->fabric.fdmi_timer);
iport->fabric.fdmi_pending &= ~FDLS_FDMI_ABORT_PENDING;
fdls_send_fdmi_plogi(iport);
}
static void
fdls_process_fabric_abts_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
{
uint32_t s_id;
struct fc_std_abts_ba_acc *ba_acc = (struct fc_std_abts_ba_acc *)fchdr;
struct fc_std_abts_ba_rjt *ba_rjt;
uint32_t fabric_state = iport->fabric.state;
struct fnic *fnic = iport->fnic;
int frame_type;
uint16_t oxid;
s_id = ntoh24(fchdr->fh_s_id);
ba_rjt = (struct fc_std_abts_ba_rjt *) fchdr;
if (!((s_id == FC_FID_DIR_SERV) || (s_id == FC_FID_FLOGI)
|| (s_id == FC_FID_FCTRL))) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Received abts rsp with invalid SID: 0x%x. Dropping frame",
s_id);
return;
}
oxid = FNIC_STD_GET_OX_ID(fchdr);
if (iport->active_oxid_fabric_req != oxid) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Received abts rsp with invalid oxid: 0x%x. Dropping frame",
oxid);
return;
}
if (iport->fabric.timer_pending) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Canceling fabric disc timer %p\n", iport);
fnic_del_fabric_timer_sync(fnic);
}
iport->fabric.timer_pending = 0;
iport->fabric.flags &= ~FNIC_FDLS_FABRIC_ABORT_ISSUED;
if (fchdr->fh_r_ctl == FC_RCTL_BA_ACC) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Received abts rsp BA_ACC for fabric_state: %d OX_ID: 0x%x",
fabric_state, be16_to_cpu(ba_acc->acc.ba_ox_id));
} else if (fchdr->fh_r_ctl == FC_RCTL_BA_RJT) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"BA_RJT fs: %d OX_ID: 0x%x rc: 0x%x rce: 0x%x",
fabric_state, FNIC_STD_GET_OX_ID(&ba_rjt->fchdr),
ba_rjt->rjt.br_reason, ba_rjt->rjt.br_explan);
}
frame_type = FNIC_FRAME_TYPE(oxid);
fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req);
/* currently error handling/retry logic is same for ABTS BA_ACC & BA_RJT */
switch (frame_type) {
case FNIC_FRAME_TYPE_FABRIC_FLOGI:
if (iport->fabric.retry_counter < iport->max_flogi_retries)
fdls_send_fabric_flogi(iport);
else
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Exceeded max FLOGI retries");
break;
case FNIC_FRAME_TYPE_FABRIC_LOGO:
if (iport->fabric.retry_counter < FABRIC_LOGO_MAX_RETRY)
fdls_send_fabric_logo(iport);
break;
case FNIC_FRAME_TYPE_FABRIC_PLOGI:
if (iport->fabric.retry_counter < iport->max_plogi_retries)
fdls_send_fabric_plogi(iport);
else
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Exceeded max PLOGI retries");
break;
case FNIC_FRAME_TYPE_FABRIC_RPN:
if (iport->fabric.retry_counter < FDLS_RETRY_COUNT)
fdls_send_rpn_id(iport);
else
/* go back to fabric Plogi */
fnic_fdls_start_plogi(iport);
break;
case FNIC_FRAME_TYPE_FABRIC_SCR:
if (iport->fabric.retry_counter < FDLS_RETRY_COUNT)
fdls_send_scr(iport);
else {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"SCR exhausted retries. Start fabric PLOGI %p",
iport);
fnic_fdls_start_plogi(iport); /* go back to fabric Plogi */
}
break;
case FNIC_FRAME_TYPE_FABRIC_RFT:
if (iport->fabric.retry_counter < FDLS_RETRY_COUNT)
fdls_send_register_fc4_types(iport);
else {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"RFT exhausted retries. Start fabric PLOGI %p",
iport);
fnic_fdls_start_plogi(iport); /* go back to fabric Plogi */
}
break;
case FNIC_FRAME_TYPE_FABRIC_RFF:
if (iport->fabric.retry_counter < FDLS_RETRY_COUNT)
fdls_send_register_fc4_features(iport);
else {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"RFF exhausted retries. Start fabric PLOGI %p",
iport);
fnic_fdls_start_plogi(iport); /* go back to fabric Plogi */
}
break;
case FNIC_FRAME_TYPE_FABRIC_GPN_FT:
if (iport->fabric.retry_counter <= FDLS_RETRY_COUNT)
fdls_send_gpn_ft(iport, fabric_state);
else
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"GPN FT exhausted retries. Start fabric PLOGI %p",
iport);
break;
default:
/*
* We should not be here since we already validated rx oxid with
* our active_oxid_fabric_req
*/
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Invalid OXID/active oxid 0x%x\n", oxid);
WARN_ON(true);
return;
}
}
static void
fdls_process_abts_req(struct fnic_iport_s *iport, struct fc_frame_header *fchdr)
{
uint8_t *frame;
struct fc_std_abts_ba_acc *pba_acc;
uint32_t nport_id;
uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr);
struct fnic_tport_s *tport;
struct fnic *fnic = iport->fnic;
uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
sizeof(struct fc_std_abts_ba_acc);
nport_id = ntoh24(fchdr->fh_s_id);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Received abort from SID 0x%8x", nport_id);
tport = fnic_find_tport_by_fcid(iport, nport_id);
if (tport) {
if (tport->active_oxid == oxid) {
tport->flags |= FNIC_FDLS_TGT_ABORT_ISSUED;
fdls_free_oxid(iport, oxid, &tport->active_oxid);
}
}
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"0x%x: Failed to allocate frame to send response for ABTS req",
iport->fcid);
return;
}
pba_acc = (struct fc_std_abts_ba_acc *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
*pba_acc = (struct fc_std_abts_ba_acc) {
.fchdr = {.fh_r_ctl = FC_RCTL_BA_ACC,
.fh_f_ctl = {FNIC_FCP_RSP_FCTL, 0, 0}},
.acc = {.ba_low_seq_cnt = 0, .ba_high_seq_cnt = cpu_to_be16(0xFFFF)}
};
FNIC_STD_SET_S_ID(pba_acc->fchdr, fchdr->fh_d_id);
FNIC_STD_SET_D_ID(pba_acc->fchdr, fchdr->fh_s_id);
FNIC_STD_SET_OX_ID(pba_acc->fchdr, FNIC_STD_GET_OX_ID(fchdr));
FNIC_STD_SET_RX_ID(pba_acc->fchdr, FNIC_STD_GET_RX_ID(fchdr));
pba_acc->acc.ba_rx_id = cpu_to_be16(FNIC_STD_GET_RX_ID(fchdr));
pba_acc->acc.ba_ox_id = cpu_to_be16(FNIC_STD_GET_OX_ID(fchdr));
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS send BA ACC with oxid: 0x%x",
iport->fcid, oxid);
fnic_send_fcoe_frame(iport, frame, frame_size);
}
static void
fdls_process_unsupported_els_req(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
{
uint8_t *frame;
struct fc_std_els_rjt_rsp *pls_rsp;
uint16_t oxid;
uint32_t d_id = ntoh24(fchdr->fh_d_id);
struct fnic *fnic = iport->fnic;
uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
sizeof(struct fc_std_els_rjt_rsp);
if (iport->fcid != d_id) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Dropping unsupported ELS with illegal frame bits 0x%x\n",
d_id);
atomic64_inc(&iport->iport_stats.unsupported_frames_dropped);
return;
}
if ((iport->state != FNIC_IPORT_STATE_READY)
&& (iport->state != FNIC_IPORT_STATE_FABRIC_DISC)) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Dropping unsupported ELS request in iport state: %d",
iport->state);
atomic64_inc(&iport->iport_stats.unsupported_frames_dropped);
return;
}
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame to send response to unsupported ELS request");
return;
}
pls_rsp = (struct fc_std_els_rjt_rsp *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
fdls_init_els_rjt_frame(frame, iport);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: Process unsupported ELS request from SID: 0x%x",
iport->fcid, ntoh24(fchdr->fh_s_id));
/* We don't support this ELS request, send a reject */
pls_rsp->rej.er_reason = 0x0B;
pls_rsp->rej.er_explan = 0x0;
pls_rsp->rej.er_vendor = 0x0;
FNIC_STD_SET_S_ID(pls_rsp->fchdr, fchdr->fh_d_id);
FNIC_STD_SET_D_ID(pls_rsp->fchdr, fchdr->fh_s_id);
oxid = FNIC_STD_GET_OX_ID(fchdr);
FNIC_STD_SET_OX_ID(pls_rsp->fchdr, oxid);
fnic_send_fcoe_frame(iport, frame, frame_size);
}
static void
fdls_process_rls_req(struct fnic_iport_s *iport, struct fc_frame_header *fchdr)
{
uint8_t *frame;
struct fc_std_rls_acc *prls_acc_rsp;
uint16_t oxid;
struct fnic *fnic = iport->fnic;
uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
sizeof(struct fc_std_rls_acc);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Process RLS request %d", iport->fnic->fnic_num);
if ((iport->state != FNIC_IPORT_STATE_READY)
&& (iport->state != FNIC_IPORT_STATE_FABRIC_DISC)) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Received RLS req in iport state: %d. Dropping the frame.",
iport->state);
return;
}
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame to send RLS accept");
return;
}
prls_acc_rsp = (struct fc_std_rls_acc *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
FNIC_STD_SET_S_ID(prls_acc_rsp->fchdr, fchdr->fh_d_id);
FNIC_STD_SET_D_ID(prls_acc_rsp->fchdr, fchdr->fh_s_id);
oxid = FNIC_STD_GET_OX_ID(fchdr);
FNIC_STD_SET_OX_ID(prls_acc_rsp->fchdr, oxid);
FNIC_STD_SET_RX_ID(prls_acc_rsp->fchdr, FNIC_UNASSIGNED_RXID);
FNIC_STD_SET_F_CTL(prls_acc_rsp->fchdr, FNIC_ELS_REP_FCTL << 16);
FNIC_STD_SET_R_CTL(prls_acc_rsp->fchdr, FC_RCTL_ELS_REP);
FNIC_STD_SET_TYPE(prls_acc_rsp->fchdr, FC_TYPE_ELS);
prls_acc_rsp->els.rls_cmd = ELS_LS_ACC;
prls_acc_rsp->els.rls_lesb.lesb_link_fail =
cpu_to_be32(iport->fnic->link_down_cnt);
fnic_send_fcoe_frame(iport, frame, frame_size);
}
static void
fdls_process_els_req(struct fnic_iport_s *iport, struct fc_frame_header *fchdr,
uint32_t len)
{
uint8_t *frame;
struct fc_std_els_acc_rsp *pels_acc;
uint16_t oxid;
uint8_t *fc_payload;
uint8_t type;
struct fnic *fnic = iport->fnic;
uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET;
fc_payload = (uint8_t *) fchdr + sizeof(struct fc_frame_header);
type = *fc_payload;
if ((iport->state != FNIC_IPORT_STATE_READY)
&& (iport->state != FNIC_IPORT_STATE_FABRIC_DISC)) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Dropping ELS frame type: 0x%x in iport state: %d",
type, iport->state);
return;
}
switch (type) {
case ELS_ECHO:
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"sending LS_ACC for ECHO request %d\n",
iport->fnic->fnic_num);
break;
case ELS_RRQ:
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"sending LS_ACC for RRQ request %d\n",
iport->fnic->fnic_num);
break;
default:
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"sending LS_ACC for 0x%x ELS frame\n", type);
break;
}
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame to send ELS response for 0x%x",
type);
return;
}
if (type == ELS_ECHO) {
/* Brocade sends a longer payload, copy all frame back */
memcpy(frame, fchdr, len);
}
pels_acc = (struct fc_std_els_acc_rsp *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
fdls_init_els_acc_frame(frame, iport);
FNIC_STD_SET_D_ID(pels_acc->fchdr, fchdr->fh_s_id);
oxid = FNIC_STD_GET_OX_ID(fchdr);
FNIC_STD_SET_OX_ID(pels_acc->fchdr, oxid);
if (type == ELS_ECHO)
frame_size += len;
else
frame_size += sizeof(struct fc_std_els_acc_rsp);
fnic_send_fcoe_frame(iport, frame, frame_size);
}
static void
fdls_process_tgt_abts_rsp(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
{
uint32_t s_id;
struct fnic_tport_s *tport;
uint32_t tport_state;
struct fc_std_abts_ba_acc *ba_acc;
struct fc_std_abts_ba_rjt *ba_rjt;
uint16_t oxid;
struct fnic *fnic = iport->fnic;
int frame_type;
s_id = ntoh24(fchdr->fh_s_id);
ba_acc = (struct fc_std_abts_ba_acc *)fchdr;
ba_rjt = (struct fc_std_abts_ba_rjt *)fchdr;
tport = fnic_find_tport_by_fcid(iport, s_id);
if (!tport) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Received tgt abts rsp with invalid SID: 0x%x", s_id);
return;
}
if (tport->timer_pending) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"tport 0x%p Canceling fabric disc timer\n", tport);
fnic_del_tport_timer_sync(fnic, tport);
}
if (iport->state != FNIC_IPORT_STATE_READY) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Received tgt abts rsp in iport state(%d). Dropping.",
iport->state);
return;
}
tport->timer_pending = 0;
tport->flags &= ~FNIC_FDLS_TGT_ABORT_ISSUED;
tport_state = tport->state;
oxid = FNIC_STD_GET_OX_ID(fchdr);
/*This abort rsp is for ADISC */
frame_type = FNIC_FRAME_TYPE(oxid);
switch (frame_type) {
case FNIC_FRAME_TYPE_TGT_ADISC:
if (fchdr->fh_r_ctl == FC_RCTL_BA_ACC) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"OX_ID: 0x%x tgt_fcid: 0x%x rcvd tgt adisc abts resp BA_ACC",
be16_to_cpu(ba_acc->acc.ba_ox_id),
tport->fcid);
} else if (fchdr->fh_r_ctl == FC_RCTL_BA_RJT) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"ADISC BA_RJT rcvd tport_fcid: 0x%x tport_state: %d ",
tport->fcid, tport_state);
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"reason code: 0x%x reason code explanation:0x%x ",
ba_rjt->rjt.br_reason,
ba_rjt->rjt.br_explan);
}
if ((tport->retry_counter < FDLS_RETRY_COUNT)
&& (fchdr->fh_r_ctl == FC_RCTL_BA_ACC)) {
fdls_free_oxid(iport, oxid, &tport->active_oxid);
fdls_send_tgt_adisc(iport, tport);
return;
}
fdls_free_oxid(iport, oxid, &tport->active_oxid);
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"ADISC not responding. Deleting target port: 0x%x",
tport->fcid);
fdls_delete_tport(iport, tport);
/* Restart discovery of targets */
if ((iport->state == FNIC_IPORT_STATE_READY)
&& (iport->fabric.state != FDLS_STATE_SEND_GPNFT)
&& (iport->fabric.state != FDLS_STATE_RSCN_GPN_FT)) {
fdls_send_gpn_ft(iport, FDLS_STATE_SEND_GPNFT);
}
break;
case FNIC_FRAME_TYPE_TGT_PLOGI:
if (fchdr->fh_r_ctl == FC_RCTL_BA_ACC) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Received tgt PLOGI abts response BA_ACC tgt_fcid: 0x%x",
tport->fcid);
} else if (fchdr->fh_r_ctl == FC_RCTL_BA_RJT) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"PLOGI BA_RJT received for tport_fcid: 0x%x OX_ID: 0x%x",
tport->fcid, FNIC_STD_GET_OX_ID(fchdr));
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"reason code: 0x%x reason code explanation: 0x%x",
ba_rjt->rjt.br_reason,
ba_rjt->rjt.br_explan);
}
if ((tport->retry_counter < iport->max_plogi_retries)
&& (fchdr->fh_r_ctl == FC_RCTL_BA_ACC)) {
fdls_free_oxid(iport, oxid, &tport->active_oxid);
fdls_send_tgt_plogi(iport, tport);
return;
}
fdls_free_oxid(iport, oxid, &tport->active_oxid);
fdls_delete_tport(iport, tport);
/* Restart discovery of targets */
if ((iport->state == FNIC_IPORT_STATE_READY)
&& (iport->fabric.state != FDLS_STATE_SEND_GPNFT)
&& (iport->fabric.state != FDLS_STATE_RSCN_GPN_FT)) {
fdls_send_gpn_ft(iport, FDLS_STATE_SEND_GPNFT);
}
break;
case FNIC_FRAME_TYPE_TGT_PRLI:
if (fchdr->fh_r_ctl == FC_RCTL_BA_ACC) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: Received tgt PRLI abts response BA_ACC",
tport->fcid);
} else if (fchdr->fh_r_ctl == FC_RCTL_BA_RJT) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"PRLI BA_RJT received for tport_fcid: 0x%x OX_ID: 0x%x ",
tport->fcid, FNIC_STD_GET_OX_ID(fchdr));
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"reason code: 0x%x reason code explanation: 0x%x",
ba_rjt->rjt.br_reason,
ba_rjt->rjt.br_explan);
}
if ((tport->retry_counter < FDLS_RETRY_COUNT)
&& (fchdr->fh_r_ctl == FC_RCTL_BA_ACC)) {
fdls_free_oxid(iport, oxid, &tport->active_oxid);
fdls_send_tgt_prli(iport, tport);
return;
}
fdls_free_oxid(iport, oxid, &tport->active_oxid);
fdls_send_tgt_plogi(iport, tport); /* go back to plogi */
fdls_set_tport_state(tport, FDLS_TGT_STATE_PLOGI);
break;
default:
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Received ABTS response for unknown frame %p", iport);
break;
}
}
static void
fdls_process_plogi_req(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
{
uint8_t *frame;
struct fc_std_els_rjt_rsp *pplogi_rsp;
uint16_t oxid;
uint32_t d_id = ntoh24(fchdr->fh_d_id);
struct fnic *fnic = iport->fnic;
uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
sizeof(struct fc_std_els_rjt_rsp);
if (iport->fcid != d_id) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Received PLOGI with illegal frame bits. Dropping frame from 0x%x",
d_id);
return;
}
if (iport->state != FNIC_IPORT_STATE_READY) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Received PLOGI request in iport state: %d Dropping frame",
iport->state);
return;
}
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame to send response to PLOGI request");
return;
}
pplogi_rsp = (struct fc_std_els_rjt_rsp *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
fdls_init_els_rjt_frame(frame, iport);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: Process PLOGI request from SID: 0x%x",
iport->fcid, ntoh24(fchdr->fh_s_id));
/* We don't support PLOGI request, send a reject */
pplogi_rsp->rej.er_reason = 0x0B;
pplogi_rsp->rej.er_explan = 0x0;
pplogi_rsp->rej.er_vendor = 0x0;
FNIC_STD_SET_S_ID(pplogi_rsp->fchdr, fchdr->fh_d_id);
FNIC_STD_SET_D_ID(pplogi_rsp->fchdr, fchdr->fh_s_id);
oxid = FNIC_STD_GET_OX_ID(fchdr);
FNIC_STD_SET_OX_ID(pplogi_rsp->fchdr, oxid);
fnic_send_fcoe_frame(iport, frame, frame_size);
}
static void
fdls_process_logo_req(struct fnic_iport_s *iport, struct fc_frame_header *fchdr)
{
struct fc_std_logo *logo = (struct fc_std_logo *)fchdr;
uint32_t nport_id;
uint64_t nport_name;
struct fnic_tport_s *tport;
struct fnic *fnic = iport->fnic;
uint16_t oxid;
nport_id = ntoh24(logo->els.fl_n_port_id);
nport_name = be64_to_cpu(logo->els.fl_n_port_wwn);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Process LOGO request from fcid: 0x%x", nport_id);
if (iport->state != FNIC_IPORT_STATE_READY) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Dropping LOGO req from 0x%x in iport state: %d",
nport_id, iport->state);
return;
}
tport = fnic_find_tport_by_fcid(iport, nport_id);
if (!tport) {
/* We are not logged in with the nport, log and drop... */
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Received LOGO from an nport not logged in: 0x%x(0x%llx)",
nport_id, nport_name);
return;
}
if (tport->fcid != nport_id) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Received LOGO with invalid target port fcid: 0x%x(0x%llx)",
nport_id, nport_name);
return;
}
if (tport->timer_pending) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"tport fcid 0x%x: Canceling disc timer\n",
tport->fcid);
fnic_del_tport_timer_sync(fnic, tport);
tport->timer_pending = 0;
}
/* got a logo in response to adisc to a target which has logged out */
if (tport->state == FDLS_TGT_STATE_ADISC) {
tport->retry_counter = 0;
oxid = tport->active_oxid;
fdls_free_oxid(iport, oxid, &tport->active_oxid);
fdls_delete_tport(iport, tport);
fdls_send_logo_resp(iport, &logo->fchdr);
if ((iport->state == FNIC_IPORT_STATE_READY)
&& (fdls_get_state(&iport->fabric) != FDLS_STATE_SEND_GPNFT)
&& (fdls_get_state(&iport->fabric) != FDLS_STATE_RSCN_GPN_FT)) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Sending GPNFT in response to LOGO from Target:0x%x",
nport_id);
fdls_send_gpn_ft(iport, FDLS_STATE_SEND_GPNFT);
return;
}
} else {
fdls_delete_tport(iport, tport);
}
if (iport->state == FNIC_IPORT_STATE_READY) {
fdls_send_logo_resp(iport, &logo->fchdr);
if ((fdls_get_state(&iport->fabric) != FDLS_STATE_SEND_GPNFT) &&
(fdls_get_state(&iport->fabric) != FDLS_STATE_RSCN_GPN_FT)) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Sending GPNFT in response to LOGO from Target:0x%x",
nport_id);
fdls_send_gpn_ft(iport, FDLS_STATE_SEND_GPNFT);
}
}
}
static void
fdls_process_rscn(struct fnic_iport_s *iport, struct fc_frame_header *fchdr)
{
struct fc_std_rscn *rscn;
struct fc_els_rscn_page *rscn_port = NULL;
int num_ports;
struct fnic_tport_s *tport, *next;
uint32_t nport_id;
uint8_t fcid[3];
int newports = 0;
struct fnic_fdls_fabric_s *fdls = &iport->fabric;
struct fnic *fnic = iport->fnic;
int rscn_type = NOT_PC_RSCN;
uint32_t sid = ntoh24(fchdr->fh_s_id);
unsigned long reset_fnic_list_lock_flags = 0;
uint16_t rscn_payload_len;
atomic64_inc(&iport->iport_stats.num_rscns);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"FDLS process RSCN %p", iport);
if (iport->state != FNIC_IPORT_STATE_READY) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"FDLS RSCN received in state(%d). Dropping",
fdls_get_state(fdls));
return;
}
rscn = (struct fc_std_rscn *)fchdr;
rscn_payload_len = be16_to_cpu(rscn->els.rscn_plen);
/* frame validation */
if ((rscn_payload_len % 4 != 0) || (rscn_payload_len < 8)
|| (rscn_payload_len > 1024)
|| (rscn->els.rscn_page_len != 4)) {
num_ports = 0;
if ((rscn_payload_len == 0xFFFF)
&& (sid == FC_FID_FCTRL)) {
rscn_type = PC_RSCN;
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"pcrscn: PCRSCN received. sid: 0x%x payload len: 0x%x",
sid, rscn_payload_len);
} else {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"RSCN payload_len: 0x%x page_len: 0x%x",
rscn_payload_len, rscn->els.rscn_page_len);
/* if this happens then we need to send ADISC to all the tports. */
list_for_each_entry_safe(tport, next, &iport->tport_list, links) {
if (tport->state == FDLS_TGT_STATE_READY)
tport->flags |= FNIC_FDLS_TPORT_SEND_ADISC;
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"RSCN for port id: 0x%x", tport->fcid);
}
} /* end else */
} else {
num_ports = (rscn_payload_len - 4) / rscn->els.rscn_page_len;
rscn_port = (struct fc_els_rscn_page *)(rscn + 1);
}
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"RSCN received for num_ports: %d payload_len: %d page_len: %d ",
num_ports, rscn_payload_len, rscn->els.rscn_page_len);
/*
* RSCN have at least one Port_ID page , but may not have any port_id
* in it. If no port_id is specified in the Port_ID page , we send
* ADISC to all the tports
*/
while (num_ports) {
memcpy(fcid, rscn_port->rscn_fid, 3);
nport_id = ntoh24(fcid);
rscn_port++;
num_ports--;
/* if this happens then we need to send ADISC to all the tports. */
if (nport_id == 0) {
list_for_each_entry_safe(tport, next, &iport->tport_list,
links) {
if (tport->state == FDLS_TGT_STATE_READY)
tport->flags |= FNIC_FDLS_TPORT_SEND_ADISC;
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"RSCN for port id: 0x%x", tport->fcid);
}
break;
}
tport = fnic_find_tport_by_fcid(iport, nport_id);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"RSCN port id list: 0x%x", nport_id);
if (!tport) {
newports++;
continue;
}
if (tport->state == FDLS_TGT_STATE_READY)
tport->flags |= FNIC_FDLS_TPORT_SEND_ADISC;
}
if (pc_rscn_handling_feature_flag == PC_RSCN_HANDLING_FEATURE_ON &&
rscn_type == PC_RSCN && fnic->role == FNIC_ROLE_FCP_INITIATOR) {
if (fnic->pc_rscn_handling_status == PC_RSCN_HANDLING_IN_PROGRESS) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"PCRSCN handling already in progress. Skip host reset: %d",
iport->fnic->fnic_num);
return;
}
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Processing PCRSCN. Queuing fnic for host reset: %d",
iport->fnic->fnic_num);
fnic->pc_rscn_handling_status = PC_RSCN_HANDLING_IN_PROGRESS;
spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
spin_lock_irqsave(&reset_fnic_list_lock,
reset_fnic_list_lock_flags);
list_add_tail(&fnic->links, &reset_fnic_list);
spin_unlock_irqrestore(&reset_fnic_list_lock,
reset_fnic_list_lock_flags);
queue_work(reset_fnic_work_queue, &reset_fnic_work);
spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags);
} else {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"FDLS process RSCN sending GPN_FT: newports: %d", newports);
fdls_send_gpn_ft(iport, FDLS_STATE_RSCN_GPN_FT);
fdls_send_rscn_resp(iport, fchdr);
}
}
void fnic_fdls_disc_start(struct fnic_iport_s *iport)
{
struct fnic *fnic = iport->fnic;
fc_host_fabric_name(iport->fnic->host) = 0;
fc_host_post_event(iport->fnic->host, fc_get_event_number(),
FCH_EVT_LIPRESET, 0);
if (!iport->usefip) {
if (iport->flags & FNIC_FIRST_LINK_UP) {
spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
fnic_scsi_fcpio_reset(iport->fnic);
spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags);
iport->flags &= ~FNIC_FIRST_LINK_UP;
}
fnic_fdls_start_flogi(iport);
} else
fnic_fdls_start_plogi(iport);
}
static void
fdls_process_adisc_req(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
{
struct fc_std_els_adisc *padisc_acc;
struct fc_std_els_adisc *adisc_req = (struct fc_std_els_adisc *)fchdr;
uint64_t frame_wwnn;
uint64_t frame_wwpn;
uint32_t tgt_fcid;
struct fnic_tport_s *tport;
uint8_t *fcid;
uint8_t *rjt_frame;
uint8_t *acc_frame;
struct fc_std_els_rjt_rsp *prjts_rsp;
uint16_t oxid;
struct fnic *fnic = iport->fnic;
uint16_t rjt_frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
sizeof(struct fc_std_els_rjt_rsp);
uint16_t acc_frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
sizeof(struct fc_std_els_adisc);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Process ADISC request %d", iport->fnic->fnic_num);
fcid = FNIC_STD_GET_S_ID(fchdr);
tgt_fcid = ntoh24(fcid);
tport = fnic_find_tport_by_fcid(iport, tgt_fcid);
if (!tport) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"tport for fcid: 0x%x not found. Dropping ADISC req.",
tgt_fcid);
return;
}
if (iport->state != FNIC_IPORT_STATE_READY) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Dropping ADISC req from fcid: 0x%x in iport state: %d",
tgt_fcid, iport->state);
return;
}
frame_wwnn = be64_to_cpu(adisc_req->els.adisc_wwnn);
frame_wwpn = be64_to_cpu(adisc_req->els.adisc_wwpn);
if ((frame_wwnn != tport->wwnn) || (frame_wwpn != tport->wwpn)) {
/* send reject */
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"ADISC req from fcid: 0x%x mismatch wwpn: 0x%llx wwnn: 0x%llx",
tgt_fcid, frame_wwpn, frame_wwnn);
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"local tport wwpn: 0x%llx wwnn: 0x%llx. Sending RJT",
tport->wwpn, tport->wwnn);
rjt_frame = fdls_alloc_frame(iport);
if (rjt_frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate rjt_frame to send response to ADISC request");
return;
}
prjts_rsp = (struct fc_std_els_rjt_rsp *) (rjt_frame + FNIC_ETH_FCOE_HDRS_OFFSET);
fdls_init_els_rjt_frame(rjt_frame, iport);
prjts_rsp->rej.er_reason = 0x03; /* logical error */
prjts_rsp->rej.er_explan = 0x1E; /* N_port login required */
prjts_rsp->rej.er_vendor = 0x0;
FNIC_STD_SET_S_ID(prjts_rsp->fchdr, fchdr->fh_d_id);
FNIC_STD_SET_D_ID(prjts_rsp->fchdr, fchdr->fh_s_id);
oxid = FNIC_STD_GET_OX_ID(fchdr);
FNIC_STD_SET_OX_ID(prjts_rsp->fchdr, oxid);
fnic_send_fcoe_frame(iport, rjt_frame, rjt_frame_size);
return;
}
acc_frame = fdls_alloc_frame(iport);
if (acc_frame == NULL) {
FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
"Failed to allocate frame to send ADISC accept");
return;
}
padisc_acc = (struct fc_std_els_adisc *) (acc_frame + FNIC_ETH_FCOE_HDRS_OFFSET);
FNIC_STD_SET_S_ID(padisc_acc->fchdr, fchdr->fh_d_id);
FNIC_STD_SET_D_ID(padisc_acc->fchdr, fchdr->fh_s_id);
FNIC_STD_SET_F_CTL(padisc_acc->fchdr, FNIC_ELS_REP_FCTL << 16);
FNIC_STD_SET_R_CTL(padisc_acc->fchdr, FC_RCTL_ELS_REP);
FNIC_STD_SET_TYPE(padisc_acc->fchdr, FC_TYPE_ELS);
oxid = FNIC_STD_GET_OX_ID(fchdr);
FNIC_STD_SET_OX_ID(padisc_acc->fchdr, oxid);
FNIC_STD_SET_RX_ID(padisc_acc->fchdr, FNIC_UNASSIGNED_RXID);
padisc_acc->els.adisc_cmd = ELS_LS_ACC;
FNIC_STD_SET_NPORT_NAME(&padisc_acc->els.adisc_wwpn,
iport->wwpn);
FNIC_STD_SET_NODE_NAME(&padisc_acc->els.adisc_wwnn,
iport->wwnn);
memcpy(padisc_acc->els.adisc_port_id, fchdr->fh_d_id, 3);
fnic_send_fcoe_frame(iport, acc_frame, acc_frame_size);
}
/*
* Performs a validation for all FCOE frames and return the frame type
*/
int
fnic_fdls_validate_and_get_frame_type(struct fnic_iport_s *iport,
struct fc_frame_header *fchdr)
{
uint8_t type;
uint8_t *fc_payload;
uint16_t oxid;
uint32_t s_id;
uint32_t d_id;
struct fnic *fnic = iport->fnic;
struct fnic_fdls_fabric_s *fabric = &iport->fabric;
int oxid_frame_type;
oxid = FNIC_STD_GET_OX_ID(fchdr);
fc_payload = (uint8_t *) fchdr + sizeof(struct fc_frame_header);
type = *fc_payload;
s_id = ntoh24(fchdr->fh_s_id);
d_id = ntoh24(fchdr->fh_d_id);
/* some common validation */
if (fdls_get_state(fabric) > FDLS_STATE_FABRIC_FLOGI) {
if (iport->fcid != d_id || (!FNIC_FC_FRAME_CS_CTL(fchdr))) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"invalid frame received. Dropping frame");
return -1;
}
}
/* BLS ABTS response */
if ((fchdr->fh_r_ctl == FC_RCTL_BA_ACC)
|| (fchdr->fh_r_ctl == FC_RCTL_BA_RJT)) {
if (!(FNIC_FC_FRAME_TYPE_BLS(fchdr))) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Received ABTS invalid frame. Dropping frame");
return -1;
}
if (fdls_is_oxid_fabric_req(oxid)) {
if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED)) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Received unexpected ABTS RSP(oxid:0x%x) from 0x%x. Dropping frame",
oxid, s_id);
return -1;
}
return FNIC_FABRIC_BLS_ABTS_RSP;
} else if (fdls_is_oxid_fdmi_req(oxid)) {
return FNIC_FDMI_BLS_ABTS_RSP;
} else if (fdls_is_oxid_tgt_req(oxid)) {
return FNIC_TPORT_BLS_ABTS_RSP;
}
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Received ABTS rsp with unknown oxid(0x%x) from 0x%x. Dropping frame",
oxid, s_id);
return -1;
}
/* BLS ABTS Req */
if ((fchdr->fh_r_ctl == FC_RCTL_BA_ABTS)
&& (FNIC_FC_FRAME_TYPE_BLS(fchdr))) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Receiving Abort Request from s_id: 0x%x", s_id);
return FNIC_BLS_ABTS_REQ;
}
/* unsolicited requests frames */
if (FNIC_FC_FRAME_UNSOLICITED(fchdr)) {
switch (type) {
case ELS_LOGO:
if ((!FNIC_FC_FRAME_FCTL_FIRST_LAST_SEQINIT(fchdr))
|| (!FNIC_FC_FRAME_UNSOLICITED(fchdr))
|| (!FNIC_FC_FRAME_TYPE_ELS(fchdr))) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Received LOGO invalid frame. Dropping frame");
return -1;
}
return FNIC_ELS_LOGO_REQ;
case ELS_RSCN:
if ((!FNIC_FC_FRAME_FCTL_FIRST_LAST_SEQINIT(fchdr))
|| (!FNIC_FC_FRAME_TYPE_ELS(fchdr))
|| (!FNIC_FC_FRAME_UNSOLICITED(fchdr))) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Received RSCN invalid FCTL. Dropping frame");
return -1;
}
if (s_id != FC_FID_FCTRL)
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Received RSCN from target FCTL: 0x%x type: 0x%x s_id: 0x%x.",
fchdr->fh_f_ctl[0], fchdr->fh_type, s_id);
return FNIC_ELS_RSCN_REQ;
case ELS_PLOGI:
return FNIC_ELS_PLOGI_REQ;
case ELS_ECHO:
return FNIC_ELS_ECHO_REQ;
case ELS_ADISC:
return FNIC_ELS_ADISC;
case ELS_RLS:
return FNIC_ELS_RLS;
case ELS_RRQ:
return FNIC_ELS_RRQ;
default:
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Unsupported frame (type:0x%02x) from fcid: 0x%x",
type, s_id);
return FNIC_ELS_UNSUPPORTED_REQ;
}
}
/* solicited response from fabric or target */
oxid_frame_type = FNIC_FRAME_TYPE(oxid);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"oxid frame code: 0x%x, oxid: 0x%x\n", oxid_frame_type, oxid);
switch (oxid_frame_type) {
case FNIC_FRAME_TYPE_FABRIC_FLOGI:
if (type == ELS_LS_ACC) {
if ((s_id != FC_FID_FLOGI)
|| (!FNIC_FC_FRAME_TYPE_ELS(fchdr))) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Received unknown frame. Dropping frame");
return -1;
}
}
return FNIC_FABRIC_FLOGI_RSP;
case FNIC_FRAME_TYPE_FABRIC_PLOGI:
if (type == ELS_LS_ACC) {
if ((s_id != FC_FID_DIR_SERV)
|| (!FNIC_FC_FRAME_TYPE_ELS(fchdr))) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Received unknown frame. Dropping frame");
return -1;
}
}
return FNIC_FABRIC_PLOGI_RSP;
case FNIC_FRAME_TYPE_FABRIC_SCR:
if (type == ELS_LS_ACC) {
if ((s_id != FC_FID_FCTRL)
|| (!FNIC_FC_FRAME_TYPE_ELS(fchdr))) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Received unknown frame. Dropping frame");
return -1;
}
}
return FNIC_FABRIC_SCR_RSP;
case FNIC_FRAME_TYPE_FABRIC_RPN:
if ((s_id != FC_FID_DIR_SERV) || (!FNIC_FC_FRAME_TYPE_FC_GS(fchdr))) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Received unknown frame. Dropping frame");
return -1;
}
return FNIC_FABRIC_RPN_RSP;
case FNIC_FRAME_TYPE_FABRIC_RFT:
if ((s_id != FC_FID_DIR_SERV) || (!FNIC_FC_FRAME_TYPE_FC_GS(fchdr))) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Received unknown frame. Dropping frame");
return -1;
}
return FNIC_FABRIC_RFT_RSP;
case FNIC_FRAME_TYPE_FABRIC_RFF:
if ((s_id != FC_FID_DIR_SERV) || (!FNIC_FC_FRAME_TYPE_FC_GS(fchdr))) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Received unknown frame. Dropping frame");
return -1;
}
return FNIC_FABRIC_RFF_RSP;
case FNIC_FRAME_TYPE_FABRIC_GPN_FT:
if ((s_id != FC_FID_DIR_SERV) || (!FNIC_FC_FRAME_TYPE_FC_GS(fchdr))) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Received unknown frame. Dropping frame");
return -1;
}
return FNIC_FABRIC_GPN_FT_RSP;
case FNIC_FRAME_TYPE_FABRIC_LOGO:
return FNIC_FABRIC_LOGO_RSP;
case FNIC_FRAME_TYPE_FDMI_PLOGI:
return FNIC_FDMI_PLOGI_RSP;
case FNIC_FRAME_TYPE_FDMI_RHBA:
return FNIC_FDMI_REG_HBA_RSP;
case FNIC_FRAME_TYPE_FDMI_RPA:
return FNIC_FDMI_RPA_RSP;
case FNIC_FRAME_TYPE_TGT_PLOGI:
return FNIC_TPORT_PLOGI_RSP;
case FNIC_FRAME_TYPE_TGT_PRLI:
return FNIC_TPORT_PRLI_RSP;
case FNIC_FRAME_TYPE_TGT_ADISC:
return FNIC_TPORT_ADISC_RSP;
case FNIC_FRAME_TYPE_TGT_LOGO:
if (!FNIC_FC_FRAME_TYPE_ELS(fchdr)) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Dropping Unknown frame in tport solicited exchange range type: 0x%x.",
fchdr->fh_type);
return -1;
}
return FNIC_TPORT_LOGO_RSP;
default:
/* Drop the Rx frame and log/stats it */
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Solicited response: unknown OXID: 0x%x", oxid);
return -1;
}
return -1;
}
void fnic_fdls_recv_frame(struct fnic_iport_s *iport, void *rx_frame,
int len, int fchdr_offset)
{
struct fc_frame_header *fchdr;
uint32_t s_id = 0;
uint32_t d_id = 0;
struct fnic *fnic = iport->fnic;
int frame_type;
fchdr = (struct fc_frame_header *) ((uint8_t *) rx_frame + fchdr_offset);
s_id = ntoh24(fchdr->fh_s_id);
d_id = ntoh24(fchdr->fh_d_id);
fnic_debug_dump_fc_frame(fnic, fchdr, len, "Incoming");
frame_type =
fnic_fdls_validate_and_get_frame_type(iport, fchdr);
/*if we are in flogo drop everything else */
if (iport->fabric.state == FDLS_STATE_FABRIC_LOGO &&
frame_type != FNIC_FABRIC_LOGO_RSP)
return;
switch (frame_type) {
case FNIC_FABRIC_FLOGI_RSP:
fdls_process_flogi_rsp(iport, fchdr, rx_frame);
break;
case FNIC_FABRIC_PLOGI_RSP:
fdls_process_fabric_plogi_rsp(iport, fchdr);
break;
case FNIC_FDMI_PLOGI_RSP:
fdls_process_fdmi_plogi_rsp(iport, fchdr);
break;
case FNIC_FABRIC_RPN_RSP:
fdls_process_rpn_id_rsp(iport, fchdr);
break;
case FNIC_FABRIC_RFT_RSP:
fdls_process_rft_id_rsp(iport, fchdr);
break;
case FNIC_FABRIC_RFF_RSP:
fdls_process_rff_id_rsp(iport, fchdr);
break;
case FNIC_FABRIC_SCR_RSP:
fdls_process_scr_rsp(iport, fchdr);
break;
case FNIC_FABRIC_GPN_FT_RSP:
fdls_process_gpn_ft_rsp(iport, fchdr, len);
break;
case FNIC_TPORT_PLOGI_RSP:
fdls_process_tgt_plogi_rsp(iport, fchdr);
break;
case FNIC_TPORT_PRLI_RSP:
fdls_process_tgt_prli_rsp(iport, fchdr);
break;
case FNIC_TPORT_ADISC_RSP:
fdls_process_tgt_adisc_rsp(iport, fchdr);
break;
case FNIC_TPORT_BLS_ABTS_RSP:
fdls_process_tgt_abts_rsp(iport, fchdr);
break;
case FNIC_TPORT_LOGO_RSP:
/* Logo response from tgt which we have deleted */
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Logo response from tgt: 0x%x",
ntoh24(fchdr->fh_s_id));
break;
case FNIC_FABRIC_LOGO_RSP:
fdls_process_fabric_logo_rsp(iport, fchdr);
break;
case FNIC_FABRIC_BLS_ABTS_RSP:
fdls_process_fabric_abts_rsp(iport, fchdr);
break;
case FNIC_FDMI_BLS_ABTS_RSP:
fdls_process_fdmi_abts_rsp(iport, fchdr);
break;
case FNIC_BLS_ABTS_REQ:
fdls_process_abts_req(iport, fchdr);
break;
case FNIC_ELS_UNSUPPORTED_REQ:
fdls_process_unsupported_els_req(iport, fchdr);
break;
case FNIC_ELS_PLOGI_REQ:
fdls_process_plogi_req(iport, fchdr);
break;
case FNIC_ELS_RSCN_REQ:
fdls_process_rscn(iport, fchdr);
break;
case FNIC_ELS_LOGO_REQ:
fdls_process_logo_req(iport, fchdr);
break;
case FNIC_ELS_RRQ:
case FNIC_ELS_ECHO_REQ:
fdls_process_els_req(iport, fchdr, len);
break;
case FNIC_ELS_ADISC:
fdls_process_adisc_req(iport, fchdr);
break;
case FNIC_ELS_RLS:
fdls_process_rls_req(iport, fchdr);
break;
case FNIC_FDMI_REG_HBA_RSP:
case FNIC_FDMI_RPA_RSP:
fdls_process_fdmi_reg_ack(iport, fchdr, frame_type);
break;
default:
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"s_id: 0x%x d_did: 0x%x", s_id, d_id);
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"Received unknown FCoE frame of len: %d. Dropping frame", len);
break;
}
}
void fnic_fdls_disc_init(struct fnic_iport_s *iport)
{
fdls_reset_oxid_pool(iport);
fdls_set_state((&iport->fabric), FDLS_STATE_INIT);
}
void fnic_fdls_link_down(struct fnic_iport_s *iport)
{
struct fnic_tport_s *tport, *next;
struct fnic *fnic = iport->fnic;
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS processing link down", iport->fcid);
fdls_set_state((&iport->fabric), FDLS_STATE_LINKDOWN);
iport->fabric.flags = 0;
spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
fnic_scsi_fcpio_reset(iport->fnic);
spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags);
list_for_each_entry_safe(tport, next, &iport->tport_list, links) {
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"removing rport: 0x%x", tport->fcid);
fdls_delete_tport(iport, tport);
}
if ((fnic_fdmi_support == 1) && (iport->fabric.fdmi_pending > 0)) {
timer_delete_sync(&iport->fabric.fdmi_timer);
iport->fabric.fdmi_pending = 0;
}
FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
"0x%x: FDLS finish processing link down", iport->fcid);
}
|