summaryrefslogtreecommitdiff
blob: 24f2705df3f089ad54b0755c0f0e922cf71c45aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994
13995
13996
13997
13998
13999
14000
14001
14002
14003
14004
14005
14006
14007
14008
14009
14010
14011
14012
14013
14014
14015
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14050
14051
14052
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093
14094
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113
14114
14115
14116
14117
14118
14119
14120
14121
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14208
14209
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248
14249
14250
14251
14252
14253
14254
14255
14256
14257
14258
14259
14260
14261
14262
14263
14264
14265
14266
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
14336
14337
14338
14339
14340
14341
14342
14343
14344
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354
14355
14356
14357
14358
14359
14360
14361
14362
14363
14364
14365
14366
14367
14368
14369
14370
14371
14372
14373
14374
14375
14376
14377
14378
14379
14380
14381
14382
14383
14384
14385
14386
14387
14388
14389
14390
14391
14392
14393
14394
14395
14396
14397
14398
14399
14400
14401
14402
14403
14404
14405
14406
14407
14408
14409
14410
14411
14412
14413
14414
14415
14416
14417
14418
14419
14420
14421
14422
14423
14424
14425
14426
14427
14428
14429
14430
14431
14432
14433
14434
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
14448
14449
14450
14451
14452
14453
14454
14455
14456
14457
14458
14459
14460
14461
14462
14463
14464
14465
14466
14467
14468
14469
14470
14471
14472
14473
14474
14475
14476
14477
14478
14479
14480
14481
14482
14483
14484
14485
14486
14487
14488
14489
14490
14491
14492
14493
14494
14495
14496
14497
14498
14499
14500
14501
14502
14503
14504
14505
14506
14507
14508
14509
14510
14511
14512
14513
14514
14515
14516
14517
14518
14519
14520
14521
14522
14523
14524
14525
14526
14527
14528
14529
14530
14531
14532
14533
14534
14535
14536
14537
14538
14539
14540
14541
14542
14543
14544
14545
14546
14547
14548
14549
14550
14551
14552
14553
14554
14555
14556
14557
14558
14559
14560
14561
14562
14563
14564
14565
14566
14567
14568
14569
14570
14571
14572
14573
14574
14575
14576
14577
14578
14579
14580
14581
14582
14583
14584
14585
14586
14587
14588
14589
14590
14591
14592
14593
14594
14595
14596
14597
14598
14599
14600
14601
14602
14603
14604
14605
14606
14607
14608
14609
14610
14611
14612
14613
14614
14615
14616
14617
14618
14619
14620
14621
14622
14623
14624
14625
14626
14627
14628
14629
14630
14631
14632
14633
14634
14635
14636
14637
14638
14639
14640
14641
14642
14643
14644
14645
14646
14647
14648
14649
14650
14651
14652
14653
14654
14655
14656
14657
14658
14659
14660
14661
14662
14663
14664
14665
14666
14667
14668
14669
14670
14671
14672
14673
14674
14675
14676
14677
14678
14679
14680
14681
14682
14683
14684
14685
14686
14687
14688
14689
14690
14691
14692
14693
14694
14695
14696
14697
14698
14699
14700
14701
14702
14703
14704
14705
14706
14707
14708
14709
14710
14711
14712
14713
14714
14715
14716
14717
14718
14719
14720
14721
14722
14723
14724
14725
14726
14727
14728
14729
14730
14731
14732
14733
14734
14735
14736
14737
14738
14739
14740
14741
14742
14743
14744
14745
14746
14747
14748
14749
14750
14751
14752
14753
14754
14755
14756
14757
14758
14759
14760
14761
14762
14763
14764
14765
14766
14767
14768
14769
14770
14771
14772
14773
14774
14775
14776
14777
14778
14779
14780
14781
14782
14783
14784
14785
14786
14787
14788
14789
14790
14791
14792
14793
14794
14795
14796
14797
14798
14799
14800
14801
14802
14803
14804
14805
14806
14807
14808
14809
14810
14811
14812
14813
14814
14815
14816
14817
14818
14819
14820
14821
14822
14823
14824
14825
14826
14827
14828
14829
14830
14831
14832
14833
14834
14835
14836
14837
14838
14839
14840
14841
14842
14843
14844
14845
14846
14847
14848
14849
14850
14851
14852
14853
14854
14855
14856
14857
14858
14859
14860
14861
14862
14863
14864
14865
14866
14867
14868
14869
14870
14871
14872
14873
14874
14875
14876
14877
14878
14879
14880
14881
14882
14883
14884
14885
14886
14887
14888
14889
14890
14891
14892
14893
14894
14895
14896
14897
14898
14899
14900
14901
14902
14903
14904
14905
14906
14907
14908
14909
14910
14911
14912
14913
14914
14915
14916
14917
14918
14919
14920
14921
14922
14923
14924
14925
14926
14927
14928
14929
14930
14931
14932
14933
14934
14935
14936
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14956
14957
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977
14978
14979
14980
14981
14982
14983
14984
14985
14986
14987
14988
14989
14990
14991
14992
14993
14994
14995
14996
14997
14998
14999
15000
15001
15002
15003
15004
15005
15006
15007
15008
15009
15010
15011
15012
15013
15014
15015
15016
15017
15018
15019
15020
15021
15022
15023
15024
15025
15026
15027
15028
15029
15030
15031
15032
15033
15034
15035
15036
15037
15038
15039
15040
15041
15042
15043
15044
15045
15046
15047
15048
15049
15050
15051
15052
15053
15054
15055
15056
15057
15058
15059
15060
15061
15062
15063
15064
15065
15066
15067
15068
15069
15070
15071
15072
15073
15074
15075
15076
15077
15078
15079
15080
15081
15082
15083
15084
15085
15086
15087
15088
15089
15090
15091
15092
15093
15094
15095
15096
15097
15098
15099
15100
15101
15102
15103
15104
15105
15106
15107
15108
15109
15110
15111
15112
15113
15114
15115
15116
15117
15118
15119
15120
15121
15122
15123
15124
15125
15126
15127
15128
15129
15130
15131
15132
15133
15134
15135
15136
15137
15138
15139
15140
15141
15142
15143
15144
15145
15146
15147
15148
15149
15150
15151
15152
15153
15154
15155
15156
15157
15158
15159
15160
15161
15162
15163
15164
15165
15166
15167
15168
15169
15170
15171
15172
15173
15174
15175
15176
15177
15178
15179
15180
15181
15182
15183
15184
15185
15186
15187
15188
15189
15190
15191
15192
15193
15194
15195
15196
15197
15198
15199
15200
15201
15202
15203
15204
15205
15206
15207
15208
15209
15210
15211
15212
15213
15214
15215
15216
15217
15218
15219
15220
15221
15222
15223
15224
15225
15226
15227
15228
15229
15230
15231
15232
15233
15234
15235
15236
15237
15238
15239
15240
15241
15242
15243
15244
15245
15246
15247
15248
15249
15250
15251
15252
15253
15254
15255
15256
15257
15258
15259
15260
15261
15262
15263
15264
15265
15266
15267
15268
15269
15270
15271
15272
15273
15274
15275
15276
15277
15278
15279
15280
15281
15282
15283
15284
15285
15286
15287
15288
15289
15290
15291
15292
15293
15294
15295
15296
15297
15298
15299
15300
15301
15302
15303
15304
15305
15306
15307
15308
15309
15310
15311
15312
15313
15314
15315
15316
15317
15318
15319
15320
15321
15322
15323
15324
15325
15326
15327
15328
15329
15330
15331
15332
15333
15334
15335
15336
15337
15338
15339
15340
15341
15342
15343
15344
15345
15346
15347
15348
15349
15350
15351
15352
15353
15354
15355
15356
15357
15358
15359
15360
15361
15362
15363
15364
15365
15366
15367
15368
15369
15370
15371
15372
15373
15374
15375
15376
15377
15378
15379
15380
15381
15382
15383
15384
15385
15386
15387
15388
15389
15390
15391
15392
15393
15394
15395
15396
15397
15398
15399
15400
15401
15402
15403
15404
15405
15406
15407
15408
15409
15410
15411
15412
15413
15414
15415
15416
15417
15418
15419
15420
15421
15422
15423
15424
15425
15426
15427
15428
15429
15430
15431
15432
15433
15434
15435
15436
15437
15438
15439
15440
15441
15442
15443
15444
15445
15446
15447
15448
15449
15450
15451
15452
15453
15454
15455
15456
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
15467
15468
15469
15470
15471
15472
15473
15474
15475
15476
15477
15478
15479
15480
15481
15482
15483
15484
15485
15486
15487
15488
15489
15490
15491
15492
15493
15494
15495
15496
15497
15498
15499
15500
15501
15502
15503
15504
15505
15506
15507
15508
15509
15510
15511
15512
15513
15514
15515
15516
15517
15518
15519
15520
15521
15522
15523
15524
15525
15526
15527
15528
15529
15530
15531
15532
15533
15534
15535
15536
15537
15538
15539
15540
15541
15542
15543
15544
15545
15546
15547
15548
15549
15550
15551
15552
15553
15554
15555
15556
15557
15558
15559
15560
15561
15562
15563
15564
15565
15566
15567
15568
15569
15570
15571
15572
15573
15574
15575
15576
15577
15578
15579
15580
15581
15582
15583
15584
15585
15586
15587
15588
15589
15590
15591
15592
15593
15594
15595
15596
15597
15598
15599
15600
15601
15602
15603
15604
15605
15606
15607
15608
15609
15610
15611
15612
15613
15614
15615
15616
15617
15618
15619
15620
15621
15622
15623
15624
15625
15626
15627
15628
15629
15630
15631
15632
15633
15634
15635
15636
15637
15638
15639
15640
15641
15642
15643
15644
15645
15646
15647
15648
15649
15650
15651
15652
15653
15654
15655
15656
15657
15658
15659
15660
15661
15662
15663
15664
15665
15666
15667
15668
15669
15670
15671
15672
15673
15674
15675
15676
15677
15678
15679
15680
15681
15682
15683
15684
15685
15686
15687
15688
15689
15690
15691
15692
15693
15694
15695
15696
15697
15698
15699
15700
15701
15702
15703
15704
15705
15706
15707
15708
15709
15710
15711
15712
15713
15714
15715
15716
15717
15718
15719
15720
15721
15722
15723
15724
15725
15726
15727
15728
15729
15730
15731
15732
15733
15734
15735
15736
15737
15738
15739
15740
15741
15742
15743
15744
15745
15746
15747
15748
15749
15750
15751
15752
15753
15754
15755
15756
15757
15758
15759
15760
15761
15762
15763
15764
15765
15766
15767
15768
15769
15770
15771
15772
15773
15774
15775
15776
15777
15778
15779
15780
15781
15782
15783
15784
15785
15786
15787
15788
15789
15790
15791
15792
15793
15794
15795
15796
15797
15798
15799
15800
15801
15802
15803
15804
15805
15806
15807
15808
15809
15810
15811
15812
15813
15814
15815
15816
15817
15818
15819
15820
15821
15822
15823
15824
15825
15826
15827
15828
15829
15830
15831
15832
15833
15834
15835
15836
15837
15838
15839
15840
15841
15842
15843
15844
15845
15846
15847
15848
15849
15850
15851
15852
15853
15854
15855
15856
15857
15858
15859
15860
15861
15862
15863
15864
15865
15866
15867
15868
15869
15870
15871
15872
15873
15874
15875
15876
15877
15878
15879
15880
15881
15882
15883
15884
15885
15886
15887
15888
15889
15890
15891
15892
15893
15894
15895
15896
15897
15898
15899
15900
15901
15902
15903
15904
15905
15906
15907
15908
15909
15910
15911
15912
15913
15914
15915
15916
15917
15918
15919
15920
15921
15922
15923
15924
15925
15926
15927
15928
15929
15930
15931
15932
15933
15934
15935
15936
15937
15938
15939
15940
15941
15942
15943
15944
15945
15946
15947
15948
15949
15950
15951
15952
15953
15954
15955
15956
15957
15958
15959
15960
15961
15962
15963
15964
15965
15966
15967
15968
15969
15970
15971
15972
15973
15974
15975
15976
15977
15978
15979
15980
15981
15982
15983
15984
15985
15986
15987
15988
15989
15990
15991
15992
15993
15994
15995
15996
15997
15998
15999
16000
16001
16002
16003
16004
16005
16006
16007
16008
16009
16010
16011
16012
16013
16014
16015
16016
16017
16018
16019
16020
16021
16022
16023
16024
16025
16026
16027
16028
16029
16030
16031
16032
16033
16034
16035
16036
16037
16038
16039
16040
16041
16042
16043
16044
16045
16046
16047
16048
16049
16050
16051
16052
16053
16054
16055
16056
16057
16058
16059
16060
16061
16062
16063
16064
16065
16066
16067
16068
16069
16070
16071
16072
16073
16074
16075
16076
16077
16078
16079
16080
16081
16082
16083
16084
16085
16086
16087
16088
16089
16090
16091
16092
16093
16094
16095
16096
16097
16098
16099
16100
16101
16102
16103
16104
16105
16106
16107
16108
16109
16110
16111
16112
16113
16114
16115
16116
16117
16118
16119
16120
16121
16122
16123
16124
16125
16126
16127
16128
16129
16130
16131
16132
16133
16134
16135
16136
16137
16138
16139
16140
16141
16142
16143
16144
16145
16146
16147
16148
16149
16150
16151
16152
16153
16154
16155
16156
16157
16158
16159
16160
16161
16162
16163
16164
16165
16166
16167
16168
16169
16170
16171
16172
16173
16174
16175
16176
16177
16178
16179
16180
16181
16182
16183
16184
16185
16186
16187
16188
16189
16190
16191
16192
16193
16194
16195
16196
16197
16198
16199
16200
16201
16202
16203
16204
16205
16206
16207
16208
16209
16210
16211
16212
16213
16214
16215
16216
16217
16218
16219
16220
16221
16222
16223
16224
16225
16226
16227
16228
16229
16230
16231
16232
16233
16234
16235
16236
16237
16238
16239
16240
16241
16242
16243
16244
16245
16246
16247
16248
16249
16250
16251
16252
16253
16254
16255
16256
16257
16258
16259
16260
16261
16262
16263
16264
16265
16266
16267
16268
16269
16270
16271
16272
16273
16274
16275
16276
16277
16278
16279
16280
16281
16282
16283
16284
16285
16286
16287
16288
16289
16290
16291
16292
16293
16294
16295
16296
16297
16298
16299
16300
16301
16302
16303
16304
16305
16306
16307
16308
16309
16310
16311
16312
16313
16314
16315
16316
16317
16318
16319
16320
16321
16322
16323
16324
16325
16326
16327
16328
16329
16330
16331
16332
16333
16334
16335
16336
16337
16338
16339
16340
16341
16342
16343
16344
16345
16346
16347
16348
16349
16350
16351
16352
16353
16354
16355
16356
16357
16358
16359
16360
16361
16362
16363
16364
16365
16366
16367
16368
16369
16370
16371
16372
16373
16374
16375
16376
16377
16378
16379
16380
16381
16382
16383
16384
16385
16386
16387
16388
16389
16390
16391
16392
16393
16394
16395
16396
16397
16398
16399
16400
16401
16402
16403
16404
16405
16406
16407
16408
16409
16410
16411
16412
16413
16414
16415
16416
16417
16418
16419
16420
16421
16422
16423
16424
16425
16426
16427
16428
16429
16430
16431
16432
16433
16434
16435
16436
16437
16438
16439
16440
16441
16442
16443
16444
16445
16446
16447
16448
16449
16450
16451
16452
16453
16454
16455
16456
16457
16458
16459
16460
16461
16462
16463
16464
16465
16466
16467
16468
16469
16470
16471
16472
16473
16474
16475
16476
16477
16478
16479
16480
16481
16482
16483
16484
16485
16486
16487
16488
16489
16490
16491
16492
16493
16494
16495
16496
16497
16498
16499
16500
16501
16502
16503
16504
16505
16506
16507
16508
16509
16510
16511
16512
16513
16514
16515
16516
16517
16518
16519
16520
16521
16522
16523
16524
16525
16526
16527
16528
16529
16530
16531
16532
16533
16534
16535
16536
16537
16538
16539
16540
16541
16542
16543
16544
16545
16546
16547
16548
16549
16550
16551
16552
16553
16554
16555
16556
16557
16558
16559
16560
16561
16562
16563
16564
16565
16566
16567
16568
16569
16570
16571
16572
16573
16574
16575
16576
16577
16578
16579
16580
16581
16582
16583
16584
16585
16586
16587
16588
16589
16590
16591
16592
16593
16594
16595
16596
16597
16598
16599
16600
16601
16602
16603
16604
16605
16606
16607
16608
16609
16610
16611
16612
16613
16614
16615
16616
16617
16618
16619
16620
16621
16622
16623
16624
16625
16626
16627
16628
16629
16630
16631
16632
16633
16634
16635
16636
16637
16638
16639
16640
16641
16642
16643
16644
16645
16646
16647
16648
16649
16650
16651
16652
16653
16654
16655
16656
16657
16658
16659
16660
16661
16662
16663
16664
16665
16666
16667
16668
16669
16670
16671
16672
16673
16674
16675
16676
16677
16678
16679
16680
16681
16682
16683
16684
16685
16686
16687
16688
16689
16690
16691
16692
16693
16694
16695
16696
16697
16698
16699
16700
16701
16702
16703
16704
16705
16706
16707
16708
16709
16710
16711
16712
16713
16714
16715
16716
16717
16718
16719
16720
16721
16722
16723
16724
16725
16726
16727
16728
16729
16730
16731
16732
16733
16734
16735
16736
16737
16738
16739
16740
16741
16742
16743
16744
16745
16746
16747
16748
16749
16750
16751
16752
16753
16754
16755
16756
16757
16758
16759
16760
16761
16762
16763
16764
16765
16766
16767
16768
16769
16770
16771
16772
16773
16774
16775
16776
16777
16778
16779
16780
16781
16782
16783
16784
16785
16786
16787
16788
16789
16790
16791
16792
16793
16794
16795
16796
16797
16798
16799
16800
16801
16802
16803
16804
16805
16806
16807
16808
16809
16810
16811
16812
16813
16814
16815
16816
16817
16818
16819
16820
16821
16822
16823
16824
16825
16826
16827
16828
16829
16830
16831
16832
16833
16834
16835
16836
16837
16838
16839
16840
16841
16842
16843
16844
16845
16846
16847
16848
16849
16850
16851
16852
16853
16854
16855
16856
16857
16858
16859
16860
16861
16862
16863
16864
16865
16866
16867
16868
16869
16870
16871
16872
16873
16874
16875
16876
16877
16878
16879
16880
16881
16882
16883
16884
16885
16886
16887
16888
16889
16890
16891
16892
16893
16894
16895
16896
16897
16898
16899
16900
16901
16902
16903
16904
16905
16906
16907
16908
16909
16910
16911
16912
16913
16914
16915
16916
16917
16918
16919
16920
16921
16922
16923
16924
16925
16926
16927
16928
16929
16930
16931
16932
16933
16934
16935
16936
16937
16938
16939
16940
16941
16942
16943
16944
16945
16946
16947
16948
16949
16950
16951
16952
16953
16954
16955
16956
16957
16958
16959
16960
16961
16962
16963
16964
16965
16966
16967
16968
16969
16970
16971
16972
16973
16974
16975
16976
16977
16978
16979
16980
16981
16982
16983
16984
16985
16986
16987
16988
16989
16990
16991
16992
16993
16994
16995
16996
16997
16998
16999
17000
17001
17002
17003
17004
17005
17006
17007
17008
17009
17010
17011
17012
17013
17014
17015
17016
17017
17018
17019
17020
17021
17022
17023
17024
17025
17026
17027
17028
17029
17030
17031
17032
17033
17034
17035
17036
17037
17038
17039
17040
17041
17042
17043
17044
17045
17046
17047
17048
17049
17050
17051
17052
17053
17054
17055
17056
17057
17058
17059
17060
17061
17062
17063
17064
17065
17066
17067
17068
17069
17070
17071
17072
17073
17074
17075
17076
17077
17078
17079
17080
17081
17082
17083
17084
17085
17086
17087
17088
17089
17090
17091
17092
17093
17094
17095
17096
17097
17098
17099
17100
17101
17102
17103
17104
17105
17106
17107
17108
17109
17110
17111
17112
17113
17114
17115
17116
17117
17118
17119
17120
17121
17122
17123
17124
17125
17126
17127
17128
17129
17130
17131
17132
17133
17134
17135
17136
17137
17138
17139
17140
17141
17142
17143
17144
17145
17146
17147
17148
17149
17150
17151
17152
17153
17154
17155
17156
17157
17158
17159
17160
17161
17162
17163
17164
17165
17166
17167
17168
17169
17170
17171
17172
17173
17174
17175
17176
17177
17178
17179
17180
17181
17182
17183
17184
17185
17186
17187
17188
17189
17190
17191
17192
17193
17194
17195
17196
17197
17198
17199
17200
17201
17202
17203
17204
17205
17206
17207
17208
17209
17210
17211
17212
17213
17214
17215
17216
17217
17218
17219
17220
17221
17222
17223
17224
17225
17226
17227
17228
17229
17230
17231
17232
17233
17234
17235
17236
17237
17238
17239
17240
17241
17242
17243
17244
17245
17246
17247
17248
17249
17250
17251
17252
17253
17254
17255
17256
17257
17258
17259
17260
17261
17262
17263
17264
17265
17266
17267
17268
17269
17270
17271
17272
17273
17274
17275
17276
17277
17278
17279
17280
17281
17282
17283
17284
17285
17286
17287
17288
17289
17290
17291
17292
17293
17294
17295
17296
17297
17298
17299
17300
17301
17302
17303
17304
17305
17306
17307
17308
17309
17310
17311
17312
17313
17314
17315
17316
17317
17318
17319
17320
17321
17322
17323
17324
17325
17326
17327
17328
17329
17330
17331
17332
17333
17334
17335
17336
17337
17338
17339
17340
17341
17342
17343
17344
17345
17346
17347
17348
17349
17350
17351
17352
17353
17354
17355
17356
17357
17358
17359
17360
17361
17362
17363
17364
17365
17366
17367
17368
17369
17370
17371
17372
17373
17374
17375
17376
17377
17378
17379
17380
17381
17382
17383
17384
17385
17386
17387
17388
17389
17390
17391
17392
17393
17394
17395
17396
17397
17398
17399
17400
17401
17402
17403
17404
17405
17406
17407
17408
17409
17410
17411
17412
17413
17414
17415
17416
17417
17418
17419
17420
17421
17422
17423
17424
17425
17426
17427
17428
17429
17430
17431
17432
17433
17434
17435
17436
17437
17438
17439
17440
17441
17442
17443
17444
17445
17446
17447
17448
17449
17450
17451
17452
17453
17454
17455
17456
17457
17458
17459
17460
17461
17462
17463
17464
17465
17466
17467
17468
17469
17470
17471
17472
17473
17474
17475
17476
17477
17478
17479
17480
17481
17482
17483
17484
17485
17486
17487
17488
17489
17490
17491
17492
17493
17494
17495
17496
17497
17498
17499
17500
17501
17502
17503
17504
17505
17506
17507
17508
17509
17510
17511
17512
17513
17514
17515
17516
17517
17518
17519
17520
17521
17522
17523
17524
17525
17526
17527
17528
17529
17530
17531
17532
17533
17534
17535
17536
17537
17538
17539
17540
17541
17542
17543
17544
17545
17546
17547
17548
17549
17550
17551
17552
17553
17554
17555
17556
17557
17558
17559
17560
17561
17562
17563
17564
17565
17566
17567
17568
17569
17570
17571
17572
17573
17574
17575
17576
17577
17578
17579
17580
17581
17582
17583
17584
17585
17586
17587
17588
17589
17590
17591
17592
17593
17594
17595
17596
17597
17598
17599
17600
17601
17602
17603
17604
17605
17606
17607
17608
17609
17610
17611
17612
17613
17614
17615
17616
17617
17618
17619
17620
17621
17622
17623
17624
17625
17626
17627
17628
17629
17630
17631
17632
17633
17634
17635
17636
17637
17638
17639
17640
17641
17642
17643
17644
17645
17646
17647
17648
17649
17650
17651
17652
17653
17654
17655
17656
17657
17658
17659
17660
17661
17662
17663
17664
17665
17666
17667
17668
17669
17670
17671
17672
17673
17674
17675
17676
17677
17678
17679
17680
17681
17682
17683
17684
17685
17686
17687
17688
17689
17690
17691
17692
17693
17694
17695
17696
17697
17698
17699
17700
17701
17702
17703
17704
17705
17706
17707
17708
17709
17710
17711
17712
17713
17714
17715
17716
17717
17718
17719
17720
17721
17722
17723
17724
17725
17726
17727
17728
17729
17730
17731
17732
17733
17734
17735
17736
17737
17738
17739
17740
17741
17742
17743
17744
17745
17746
17747
17748
17749
17750
17751
17752
17753
17754
17755
17756
17757
17758
17759
17760
17761
17762
17763
17764
17765
17766
17767
17768
17769
17770
17771
17772
17773
17774
17775
17776
17777
17778
17779
17780
17781
17782
17783
17784
17785
17786
17787
17788
17789
17790
17791
17792
17793
17794
17795
17796
17797
17798
17799
17800
17801
17802
17803
17804
17805
17806
17807
17808
17809
17810
17811
17812
17813
17814
17815
17816
17817
17818
17819
17820
17821
17822
17823
17824
17825
17826
17827
17828
17829
17830
17831
17832
17833
17834
17835
17836
17837
17838
17839
17840
17841
17842
17843
17844
17845
17846
17847
17848
17849
17850
17851
17852
17853
17854
17855
17856
17857
17858
17859
17860
17861
17862
17863
17864
17865
17866
17867
17868
17869
17870
17871
17872
17873
17874
17875
17876
17877
17878
17879
17880
17881
17882
17883
17884
17885
17886
17887
17888
17889
17890
17891
17892
17893
17894
17895
17896
17897
17898
17899
17900
17901
17902
17903
17904
17905
17906
17907
17908
17909
17910
17911
17912
17913
17914
17915
17916
17917
17918
17919
17920
17921
17922
17923
17924
17925
17926
17927
17928
17929
17930
17931
17932
17933
17934
17935
17936
17937
17938
17939
17940
17941
17942
17943
17944
17945
17946
17947
17948
17949
17950
17951
17952
17953
17954
17955
17956
17957
17958
17959
17960
17961
17962
17963
17964
17965
17966
17967
17968
17969
17970
17971
17972
17973
17974
17975
17976
17977
17978
17979
17980
17981
17982
17983
17984
17985
17986
17987
17988
17989
17990
17991
17992
17993
17994
17995
17996
17997
17998
17999
18000
18001
18002
18003
18004
18005
18006
18007
18008
18009
18010
18011
18012
18013
18014
18015
18016
18017
18018
18019
18020
18021
18022
18023
18024
18025
18026
18027
18028
18029
18030
18031
18032
18033
18034
18035
18036
18037
18038
18039
18040
18041
18042
18043
18044
18045
18046
18047
18048
18049
18050
18051
18052
18053
18054
18055
18056
18057
18058
18059
18060
18061
18062
18063
18064
18065
18066
18067
18068
18069
18070
18071
18072
18073
18074
18075
18076
18077
18078
18079
18080
18081
18082
18083
18084
18085
18086
18087
18088
18089
18090
18091
18092
18093
18094
18095
18096
18097
18098
18099
18100
18101
18102
18103
18104
18105
18106
18107
18108
18109
18110
18111
18112
18113
18114
18115
18116
18117
18118
18119
18120
18121
18122
18123
18124
18125
18126
18127
18128
18129
18130
18131
18132
18133
18134
18135
18136
18137
18138
18139
18140
18141
18142
18143
18144
18145
18146
18147
18148
18149
18150
18151
18152
18153
18154
18155
18156
18157
18158
18159
18160
18161
18162
18163
18164
18165
18166
18167
18168
18169
18170
18171
18172
18173
18174
18175
18176
18177
18178
18179
18180
18181
18182
18183
18184
18185
18186
18187
18188
18189
18190
18191
18192
18193
18194
18195
18196
18197
18198
18199
18200
18201
18202
18203
18204
18205
18206
18207
18208
18209
18210
18211
18212
18213
18214
18215
18216
18217
18218
18219
18220
18221
18222
18223
18224
18225
18226
18227
18228
18229
18230
18231
18232
18233
18234
18235
18236
18237
18238
18239
18240
18241
18242
18243
18244
18245
18246
18247
18248
18249
18250
18251
18252
18253
18254
18255
18256
18257
18258
18259
18260
18261
18262
18263
18264
18265
18266
18267
18268
18269
18270
18271
18272
18273
18274
18275
18276
18277
18278
18279
18280
18281
18282
18283
18284
18285
18286
18287
18288
18289
18290
18291
18292
18293
18294
18295
18296
18297
18298
18299
18300
18301
18302
18303
18304
18305
18306
18307
18308
18309
18310
18311
18312
18313
18314
18315
18316
18317
18318
18319
18320
18321
18322
18323
18324
18325
18326
18327
18328
18329
18330
18331
18332
18333
18334
18335
18336
18337
18338
18339
18340
18341
18342
18343
18344
18345
18346
18347
18348
18349
18350
18351
18352
18353
18354
18355
18356
18357
18358
18359
18360
18361
18362
18363
18364
18365
18366
18367
18368
18369
18370
18371
18372
18373
18374
18375
18376
18377
18378
18379
18380
18381
18382
18383
18384
18385
18386
18387
18388
18389
18390
18391
18392
18393
18394
18395
18396
18397
18398
18399
18400
18401
18402
18403
18404
18405
18406
18407
18408
18409
18410
18411
18412
18413
18414
18415
18416
18417
18418
18419
18420
18421
18422
18423
18424
18425
18426
18427
18428
18429
18430
18431
18432
18433
18434
18435
18436
18437
18438
18439
18440
18441
18442
18443
18444
18445
18446
18447
18448
18449
18450
18451
18452
18453
18454
18455
18456
18457
18458
18459
18460
18461
18462
18463
18464
18465
18466
18467
18468
18469
18470
18471
18472
18473
18474
18475
18476
18477
18478
18479
18480
18481
18482
18483
18484
18485
18486
18487
18488
18489
18490
18491
18492
18493
18494
18495
18496
18497
18498
18499
18500
18501
18502
18503
18504
18505
18506
18507
18508
18509
18510
18511
18512
18513
18514
18515
18516
18517
18518
18519
18520
18521
18522
18523
18524
18525
18526
18527
18528
18529
18530
18531
18532
18533
18534
18535
18536
18537
18538
18539
18540
18541
18542
18543
18544
18545
18546
18547
18548
18549
18550
18551
18552
18553
18554
18555
18556
18557
18558
18559
18560
18561
18562
18563
18564
18565
18566
18567
18568
18569
18570
18571
18572
18573
18574
18575
18576
18577
18578
18579
18580
18581
18582
18583
18584
18585
18586
18587
18588
18589
18590
18591
18592
18593
18594
18595
18596
18597
18598
18599
18600
18601
18602
18603
18604
18605
18606
18607
18608
18609
18610
18611
18612
18613
18614
18615
18616
18617
18618
18619
18620
18621
18622
18623
18624
18625
18626
18627
18628
18629
18630
18631
18632
18633
18634
18635
18636
18637
18638
18639
18640
18641
18642
18643
18644
18645
18646
18647
18648
18649
18650
18651
18652
18653
18654
18655
18656
18657
18658
18659
18660
18661
18662
18663
18664
18665
18666
18667
18668
18669
18670
18671
18672
18673
18674
18675
18676
18677
18678
18679
18680
18681
18682
18683
18684
18685
18686
18687
18688
18689
18690
18691
18692
18693
18694
18695
18696
18697
18698
18699
18700
18701
18702
18703
18704
18705
18706
18707
18708
18709
18710
18711
18712
18713
18714
18715
18716
18717
18718
18719
18720
18721
18722
18723
18724
18725
18726
18727
18728
18729
18730
18731
18732
18733
18734
18735
18736
18737
18738
18739
18740
18741
18742
18743
18744
18745
18746
18747
18748
18749
18750
18751
18752
18753
18754
18755
18756
18757
18758
18759
18760
18761
18762
18763
18764
18765
18766
18767
18768
18769
18770
18771
18772
18773
18774
18775
18776
18777
18778
18779
18780
18781
18782
18783
18784
18785
18786
18787
18788
18789
18790
18791
18792
18793
18794
18795
18796
18797
18798
18799
18800
18801
18802
18803
18804
18805
18806
18807
18808
18809
18810
18811
18812
18813
18814
18815
18816
18817
18818
18819
18820
18821
18822
18823
18824
18825
18826
18827
18828
18829
18830
18831
18832
18833
18834
18835
18836
18837
18838
18839
18840
18841
18842
18843
18844
18845
18846
18847
18848
18849
18850
18851
18852
18853
18854
18855
18856
18857
18858
18859
18860
18861
18862
18863
18864
18865
18866
18867
18868
18869
18870
18871
18872
18873
18874
18875
18876
18877
18878
18879
18880
18881
18882
18883
18884
18885
18886
18887
18888
18889
18890
18891
18892
18893
18894
18895
18896
18897
18898
18899
18900
18901
18902
18903
18904
18905
18906
18907
18908
18909
18910
18911
18912
18913
18914
18915
18916
18917
18918
18919
18920
18921
18922
18923
18924
18925
18926
18927
18928
18929
18930
18931
18932
18933
18934
18935
18936
18937
18938
18939
18940
18941
18942
18943
18944
18945
18946
18947
18948
18949
18950
18951
18952
18953
18954
18955
18956
18957
18958
18959
18960
18961
18962
18963
18964
18965
18966
18967
18968
18969
18970
18971
18972
18973
18974
18975
18976
18977
18978
18979
18980
18981
18982
18983
18984
18985
18986
18987
18988
18989
18990
18991
18992
18993
18994
18995
18996
18997
18998
18999
19000
19001
19002
19003
19004
19005
19006
19007
19008
19009
19010
19011
19012
19013
19014
19015
19016
19017
19018
19019
19020
19021
19022
19023
19024
19025
19026
19027
19028
19029
19030
19031
19032
19033
19034
19035
19036
19037
19038
19039
19040
19041
19042
19043
19044
19045
19046
19047
19048
19049
19050
19051
19052
19053
19054
19055
19056
19057
19058
19059
19060
19061
19062
19063
19064
19065
19066
19067
19068
19069
19070
19071
19072
19073
19074
19075
19076
19077
19078
19079
19080
19081
19082
19083
19084
19085
19086
19087
19088
19089
19090
19091
19092
19093
19094
19095
19096
19097
19098
19099
19100
19101
19102
19103
19104
19105
19106
19107
19108
19109
19110
19111
19112
19113
19114
19115
19116
19117
19118
19119
19120
19121
19122
19123
19124
19125
19126
19127
19128
19129
19130
19131
19132
19133
19134
19135
19136
19137
19138
19139
19140
19141
19142
19143
19144
19145
19146
19147
19148
19149
19150
19151
19152
19153
19154
19155
19156
19157
19158
19159
19160
19161
19162
19163
19164
19165
19166
19167
19168
19169
19170
19171
19172
19173
19174
19175
19176
19177
19178
19179
19180
19181
19182
19183
19184
19185
19186
19187
19188
19189
19190
19191
19192
19193
19194
19195
19196
19197
19198
19199
19200
19201
19202
19203
19204
19205
19206
19207
19208
19209
19210
19211
19212
19213
19214
19215
19216
19217
19218
19219
19220
19221
19222
19223
19224
19225
19226
19227
19228
19229
19230
19231
19232
19233
19234
19235
19236
19237
19238
19239
19240
19241
19242
19243
19244
19245
19246
19247
19248
19249
19250
19251
19252
19253
19254
19255
19256
19257
19258
19259
19260
19261
19262
19263
19264
19265
19266
19267
19268
19269
19270
19271
19272
19273
19274
19275
19276
19277
19278
19279
19280
19281
19282
19283
19284
19285
19286
19287
19288
19289
19290
19291
19292
19293
19294
19295
19296
19297
19298
19299
19300
19301
19302
19303
19304
19305
19306
19307
19308
19309
19310
19311
19312
19313
19314
19315
19316
19317
19318
19319
19320
19321
19322
19323
19324
19325
19326
19327
19328
19329
19330
19331
19332
19333
19334
19335
19336
19337
19338
19339
19340
19341
19342
19343
19344
19345
19346
19347
19348
19349
19350
19351
19352
19353
19354
19355
19356
19357
19358
19359
19360
19361
19362
19363
19364
19365
19366
19367
19368
19369
19370
19371
19372
19373
19374
19375
19376
19377
19378
19379
19380
19381
19382
19383
19384
19385
19386
19387
19388
19389
19390
19391
19392
19393
19394
19395
19396
19397
19398
19399
19400
19401
19402
19403
19404
19405
19406
19407
19408
19409
19410
19411
19412
19413
19414
19415
19416
19417
19418
19419
19420
19421
19422
19423
19424
19425
19426
19427
19428
19429
19430
19431
19432
19433
19434
19435
19436
19437
19438
19439
19440
19441
19442
19443
19444
19445
19446
19447
19448
19449
19450
19451
19452
19453
19454
19455
19456
19457
19458
19459
19460
19461
19462
19463
19464
19465
19466
19467
19468
19469
19470
19471
19472
19473
19474
19475
19476
19477
19478
19479
19480
19481
19482
19483
19484
19485
19486
19487
19488
19489
19490
19491
19492
19493
19494
19495
19496
19497
19498
19499
19500
19501
19502
19503
19504
19505
19506
19507
19508
19509
19510
19511
19512
19513
19514
19515
19516
19517
19518
19519
19520
19521
19522
19523
19524
19525
19526
19527
19528
19529
19530
19531
19532
19533
19534
19535
19536
19537
19538
19539
19540
19541
19542
19543
19544
19545
19546
19547
19548
19549
19550
19551
19552
19553
19554
19555
19556
19557
19558
19559
19560
19561
19562
19563
19564
19565
19566
19567
19568
19569
19570
19571
19572
19573
19574
19575
19576
19577
19578
19579
19580
19581
19582
19583
19584
19585
19586
19587
19588
19589
19590
19591
19592
19593
19594
19595
19596
19597
19598
19599
19600
19601
19602
19603
19604
19605
19606
19607
19608
19609
19610
19611
19612
19613
19614
19615
19616
19617
19618
19619
19620
19621
19622
19623
19624
19625
19626
19627
19628
19629
19630
19631
19632
19633
19634
19635
19636
19637
19638
19639
19640
19641
19642
19643
19644
19645
19646
19647
19648
19649
19650
19651
19652
19653
19654
19655
19656
19657
19658
19659
19660
19661
19662
19663
19664
19665
19666
19667
19668
19669
19670
19671
19672
19673
19674
19675
19676
19677
19678
19679
19680
19681
19682
19683
19684
19685
19686
19687
19688
19689
19690
19691
19692
19693
19694
19695
19696
19697
19698
19699
19700
19701
19702
19703
19704
19705
19706
19707
19708
19709
19710
19711
19712
19713
19714
19715
19716
19717
19718
19719
19720
19721
19722
19723
19724
19725
19726
19727
19728
19729
19730
19731
19732
19733
19734
19735
19736
19737
19738
19739
19740
19741
19742
19743
19744
19745
19746
19747
19748
19749
19750
19751
19752
19753
19754
19755
19756
19757
19758
19759
19760
19761
19762
19763
19764
19765
19766
19767
19768
19769
19770
19771
19772
19773
19774
19775
19776
19777
19778
19779
19780
19781
19782
19783
19784
19785
19786
19787
19788
19789
19790
19791
19792
19793
19794
19795
19796
19797
19798
19799
19800
19801
19802
19803
19804
19805
19806
19807
19808
19809
19810
19811
19812
19813
19814
19815
19816
19817
19818
19819
19820
19821
19822
19823
19824
19825
19826
19827
19828
19829
19830
19831
19832
19833
19834
19835
19836
19837
19838
19839
19840
19841
19842
19843
19844
19845
19846
19847
19848
19849
19850
19851
19852
19853
19854
19855
19856
19857
19858
19859
19860
19861
19862
19863
19864
19865
19866
19867
19868
19869
19870
19871
19872
19873
19874
19875
19876
19877
19878
19879
19880
19881
19882
19883
19884
19885
19886
19887
19888
19889
19890
19891
19892
19893
19894
19895
19896
19897
19898
19899
19900
19901
19902
19903
19904
19905
19906
19907
19908
19909
19910
19911
19912
19913
19914
19915
19916
19917
19918
19919
19920
19921
19922
19923
19924
19925
19926
19927
19928
19929
19930
19931
19932
19933
19934
19935
19936
19937
19938
19939
19940
19941
19942
19943
19944
19945
19946
19947
19948
19949
19950
19951
19952
19953
19954
19955
19956
19957
19958
19959
19960
19961
19962
19963
19964
19965
19966
19967
19968
19969
19970
19971
19972
19973
19974
19975
19976
19977
19978
19979
19980
19981
19982
19983
19984
19985
19986
19987
19988
19989
19990
19991
19992
19993
19994
19995
19996
19997
19998
19999
20000
20001
20002
20003
20004
20005
20006
20007
20008
20009
20010
20011
20012
20013
20014
20015
20016
20017
20018
20019
20020
20021
20022
20023
20024
20025
20026
20027
20028
20029
20030
20031
20032
20033
20034
20035
20036
20037
20038
20039
20040
20041
20042
20043
20044
20045
20046
20047
20048
20049
20050
20051
20052
20053
20054
20055
20056
20057
20058
20059
20060
20061
20062
20063
20064
20065
20066
20067
20068
20069
20070
20071
20072
20073
20074
20075
20076
20077
20078
20079
20080
20081
20082
20083
20084
20085
20086
20087
20088
20089
20090
20091
20092
20093
20094
20095
20096
20097
20098
20099
20100
20101
20102
20103
20104
20105
20106
20107
20108
20109
20110
20111
20112
20113
20114
20115
20116
20117
20118
20119
20120
20121
20122
20123
20124
20125
20126
20127
20128
20129
20130
20131
20132
20133
20134
20135
20136
20137
20138
20139
20140
20141
20142
20143
20144
20145
20146
20147
20148
20149
20150
20151
20152
20153
20154
20155
20156
20157
20158
20159
20160
20161
20162
20163
20164
20165
20166
20167
20168
20169
20170
20171
20172
20173
20174
20175
20176
20177
20178
20179
20180
20181
20182
20183
20184
20185
20186
20187
20188
20189
20190
20191
20192
20193
20194
20195
20196
20197
20198
20199
20200
20201
20202
20203
20204
20205
20206
20207
20208
20209
20210
20211
20212
20213
20214
20215
20216
20217
20218
20219
20220
20221
20222
20223
20224
20225
20226
20227
20228
20229
20230
20231
20232
20233
20234
20235
20236
20237
20238
20239
20240
20241
20242
20243
20244
20245
20246
20247
20248
20249
20250
20251
20252
20253
20254
20255
20256
20257
20258
20259
20260
20261
20262
20263
20264
20265
20266
20267
20268
20269
20270
20271
20272
20273
20274
20275
20276
20277
20278
20279
20280
20281
20282
20283
20284
20285
20286
20287
20288
20289
20290
20291
20292
20293
20294
20295
20296
20297
20298
20299
20300
20301
20302
20303
20304
20305
20306
20307
20308
20309
20310
20311
20312
20313
20314
20315
20316
20317
20318
20319
20320
20321
20322
20323
20324
20325
20326
20327
20328
20329
20330
20331
20332
20333
20334
20335
20336
20337
20338
20339
20340
20341
20342
20343
20344
20345
20346
20347
20348
20349
20350
20351
20352
20353
20354
20355
20356
20357
20358
20359
20360
20361
20362
20363
20364
20365
20366
20367
20368
20369
20370
20371
20372
20373
20374
20375
20376
20377
20378
20379
20380
20381
20382
20383
20384
20385
20386
20387
20388
20389
20390
20391
20392
20393
20394
20395
20396
20397
20398
20399
20400
20401
20402
20403
20404
20405
20406
20407
20408
20409
20410
20411
20412
20413
20414
20415
20416
20417
20418
20419
20420
20421
20422
20423
20424
20425
20426
20427
20428
20429
20430
20431
20432
20433
20434
20435
20436
20437
20438
20439
20440
20441
20442
20443
20444
20445
20446
20447
20448
20449
20450
20451
20452
20453
20454
20455
20456
20457
20458
20459
20460
20461
20462
20463
20464
20465
20466
20467
20468
20469
20470
20471
20472
20473
20474
20475
20476
20477
20478
20479
20480
20481
20482
20483
20484
20485
20486
20487
20488
20489
20490
20491
20492
20493
20494
20495
20496
20497
20498
20499
20500
20501
20502
20503
20504
20505
20506
20507
20508
20509
20510
20511
20512
20513
20514
20515
20516
20517
20518
20519
20520
20521
20522
20523
20524
20525
20526
20527
20528
20529
20530
20531
20532
20533
20534
20535
20536
20537
20538
20539
20540
20541
20542
20543
20544
20545
20546
20547
20548
20549
20550
20551
20552
20553
20554
20555
20556
20557
20558
20559
20560
20561
20562
20563
20564
20565
20566
20567
20568
20569
20570
20571
20572
20573
20574
20575
20576
20577
20578
20579
20580
20581
20582
20583
20584
20585
20586
20587
20588
20589
20590
20591
20592
20593
20594
20595
20596
20597
20598
20599
20600
20601
20602
20603
20604
20605
20606
20607
20608
20609
20610
20611
20612
20613
20614
20615
20616
20617
20618
20619
20620
20621
20622
20623
20624
20625
20626
20627
20628
20629
20630
20631
20632
20633
20634
20635
20636
20637
20638
20639
20640
20641
20642
20643
20644
20645
20646
20647
20648
20649
20650
20651
20652
20653
20654
20655
20656
20657
20658
20659
20660
20661
20662
20663
20664
20665
20666
20667
20668
20669
20670
20671
20672
20673
20674
20675
20676
20677
20678
20679
20680
20681
20682
20683
20684
20685
20686
20687
20688
20689
20690
20691
20692
20693
20694
20695
20696
20697
20698
20699
20700
20701
20702
20703
20704
20705
20706
20707
20708
20709
20710
20711
20712
20713
20714
20715
20716
20717
20718
20719
20720
20721
20722
20723
20724
20725
20726
20727
20728
20729
20730
20731
20732
20733
20734
20735
20736
20737
20738
20739
20740
20741
20742
20743
20744
20745
20746
20747
20748
20749
20750
20751
20752
20753
20754
20755
20756
20757
20758
20759
20760
20761
20762
20763
20764
20765
20766
20767
20768
20769
20770
20771
20772
20773
20774
20775
20776
20777
20778
20779
20780
20781
20782
20783
20784
20785
20786
20787
20788
20789
20790
20791
20792
20793
20794
20795
20796
20797
20798
20799
20800
20801
20802
20803
20804
20805
20806
20807
20808
20809
20810
20811
20812
20813
20814
20815
20816
20817
20818
20819
20820
20821
20822
20823
20824
20825
20826
20827
20828
20829
20830
20831
20832
20833
20834
20835
20836
20837
20838
20839
20840
20841
20842
20843
20844
20845
20846
20847
20848
20849
20850
20851
20852
20853
20854
20855
20856
20857
20858
20859
20860
20861
20862
20863
20864
20865
20866
20867
20868
20869
20870
20871
20872
20873
20874
20875
20876
20877
20878
20879
20880
20881
20882
20883
20884
20885
20886
20887
20888
20889
20890
20891
20892
20893
20894
20895
20896
20897
20898
20899
20900
20901
20902
20903
20904
20905
20906
20907
20908
20909
20910
20911
20912
20913
20914
20915
20916
20917
20918
20919
20920
20921
20922
20923
20924
20925
20926
20927
20928
20929
20930
20931
20932
20933
20934
20935
20936
20937
20938
20939
20940
20941
20942
20943
20944
20945
20946
20947
20948
20949
20950
20951
20952
20953
20954
20955
20956
20957
20958
20959
20960
20961
20962
20963
20964
20965
20966
20967
20968
20969
20970
20971
20972
20973
20974
20975
20976
20977
20978
20979
20980
20981
20982
20983
20984
20985
20986
20987
20988
20989
20990
20991
20992
20993
20994
20995
20996
20997
20998
20999
21000
21001
21002
21003
21004
21005
21006
21007
21008
21009
21010
21011
21012
21013
21014
21015
21016
21017
21018
21019
21020
21021
21022
21023
21024
21025
21026
21027
21028
21029
21030
21031
21032
21033
21034
21035
21036
21037
21038
21039
21040
21041
21042
21043
21044
21045
21046
21047
21048
21049
21050
21051
21052
21053
21054
21055
21056
21057
21058
21059
21060
21061
21062
21063
21064
21065
21066
21067
21068
21069
21070
21071
21072
21073
21074
21075
21076
21077
21078
21079
21080
21081
21082
21083
21084
21085
21086
21087
21088
21089
21090
21091
21092
21093
21094
21095
21096
21097
21098
21099
21100
21101
21102
21103
21104
21105
21106
21107
21108
21109
21110
21111
21112
21113
21114
21115
21116
21117
21118
21119
21120
21121
21122
21123
21124
21125
21126
21127
21128
21129
21130
21131
21132
21133
21134
21135
21136
21137
21138
21139
21140
21141
21142
21143
21144
21145
21146
21147
21148
21149
21150
21151
21152
21153
21154
21155
21156
21157
21158
21159
21160
21161
21162
21163
21164
21165
21166
21167
21168
21169
21170
21171
21172
21173
21174
21175
21176
21177
21178
21179
21180
21181
21182
21183
21184
21185
21186
21187
21188
21189
21190
21191
21192
21193
21194
21195
21196
21197
21198
21199
21200
21201
21202
21203
21204
21205
21206
21207
21208
21209
21210
21211
21212
21213
21214
21215
21216
21217
21218
21219
21220
21221
21222
21223
21224
21225
21226
21227
21228
21229
21230
21231
21232
21233
21234
21235
21236
21237
21238
21239
21240
21241
21242
21243
21244
21245
21246
21247
21248
21249
21250
21251
21252
21253
21254
21255
21256
21257
21258
21259
21260
21261
21262
21263
21264
21265
21266
21267
21268
21269
21270
21271
21272
21273
21274
21275
21276
21277
21278
21279
21280
21281
21282
21283
21284
21285
21286
21287
21288
21289
21290
21291
21292
21293
21294
21295
21296
21297
21298
21299
21300
21301
21302
21303
21304
21305
21306
21307
21308
21309
21310
21311
21312
21313
21314
21315
21316
21317
21318
21319
21320
21321
21322
21323
21324
21325
21326
21327
21328
21329
21330
21331
21332
21333
21334
21335
21336
21337
21338
21339
21340
21341
21342
21343
21344
21345
21346
21347
21348
21349
21350
21351
21352
21353
21354
21355
21356
21357
21358
21359
21360
21361
21362
21363
21364
21365
21366
21367
21368
21369
21370
21371
21372
21373
21374
21375
21376
21377
21378
21379
21380
21381
21382
21383
21384
21385
21386
21387
21388
21389
21390
21391
21392
21393
21394
21395
21396
21397
21398
21399
21400
21401
21402
21403
21404
21405
21406
21407
21408
21409
21410
21411
21412
21413
21414
21415
21416
21417
21418
21419
21420
21421
21422
21423
21424
21425
21426
21427
21428
21429
21430
21431
21432
21433
21434
21435
21436
21437
21438
21439
21440
21441
21442
21443
21444
21445
21446
21447
21448
21449
21450
21451
21452
21453
21454
21455
21456
21457
21458
21459
21460
21461
21462
21463
21464
21465
21466
21467
21468
21469
21470
21471
21472
21473
21474
21475
21476
21477
21478
21479
21480
21481
21482
21483
21484
21485
21486
21487
21488
21489
21490
21491
21492
21493
21494
21495
21496
21497
21498
21499
21500
21501
21502
21503
21504
21505
21506
21507
21508
21509
21510
21511
21512
21513
21514
21515
21516
21517
21518
21519
21520
21521
21522
21523
21524
21525
21526
21527
21528
21529
21530
21531
21532
21533
21534
21535
21536
21537
21538
21539
21540
21541
21542
21543
21544
21545
21546
21547
21548
21549
21550
21551
21552
21553
21554
21555
21556
21557
21558
21559
21560
21561
21562
21563
21564
21565
21566
21567
21568
21569
21570
21571
21572
21573
21574
21575
21576
21577
21578
21579
21580
21581
21582
21583
21584
21585
21586
21587
21588
21589
21590
21591
21592
21593
21594
21595
21596
21597
21598
21599
21600
21601
21602
21603
21604
21605
21606
21607
21608
21609
21610
21611
21612
21613
21614
21615
21616
21617
21618
21619
21620
21621
21622
21623
21624
21625
21626
21627
21628
21629
21630
21631
21632
21633
21634
21635
21636
21637
21638
21639
21640
21641
21642
21643
21644
21645
21646
21647
21648
21649
21650
21651
21652
21653
21654
21655
21656
21657
21658
21659
21660
21661
21662
21663
21664
21665
21666
21667
21668
21669
21670
21671
21672
21673
21674
21675
21676
21677
21678
21679
21680
21681
21682
21683
21684
21685
21686
21687
21688
21689
21690
21691
21692
21693
21694
21695
21696
21697
21698
21699
21700
21701
21702
21703
21704
21705
21706
21707
21708
21709
21710
21711
21712
21713
21714
21715
21716
21717
21718
21719
21720
21721
21722
21723
21724
21725
21726
21727
21728
21729
21730
21731
21732
21733
21734
21735
21736
21737
21738
21739
21740
21741
21742
21743
21744
21745
21746
21747
21748
21749
21750
21751
21752
21753
21754
21755
21756
21757
21758
21759
21760
21761
21762
21763
21764
21765
21766
21767
21768
21769
21770
21771
21772
21773
21774
21775
21776
21777
21778
21779
21780
21781
21782
21783
21784
21785
21786
21787
21788
21789
21790
21791
21792
21793
21794
21795
21796
21797
21798
21799
21800
21801
21802
21803
21804
21805
21806
21807
21808
21809
21810
21811
21812
21813
21814
21815
21816
21817
21818
21819
21820
21821
21822
21823
21824
21825
21826
21827
21828
21829
21830
21831
21832
21833
21834
21835
21836
21837
21838
21839
21840
21841
21842
21843
21844
21845
21846
21847
21848
21849
21850
21851
21852
21853
21854
21855
21856
21857
21858
21859
21860
21861
21862
21863
21864
21865
21866
21867
21868
21869
21870
21871
21872
21873
21874
21875
21876
21877
21878
21879
21880
21881
21882
21883
21884
21885
21886
21887
21888
21889
21890
21891
21892
21893
21894
21895
21896
21897
21898
21899
21900
21901
21902
21903
21904
21905
21906
21907
21908
21909
21910
21911
21912
21913
21914
21915
21916
21917
21918
21919
21920
21921
21922
21923
21924
21925
21926
21927
21928
21929
21930
21931
21932
21933
21934
21935
21936
21937
21938
21939
21940
21941
21942
21943
21944
21945
21946
21947
21948
21949
21950
21951
21952
21953
21954
21955
21956
21957
21958
21959
21960
21961
21962
21963
21964
21965
21966
21967
21968
21969
21970
21971
21972
21973
21974
21975
21976
21977
21978
21979
21980
21981
21982
21983
21984
21985
21986
21987
21988
21989
21990
21991
21992
21993
21994
21995
21996
21997
21998
21999
22000
22001
22002
22003
22004
22005
22006
22007
22008
22009
22010
22011
22012
22013
22014
22015
22016
22017
22018
22019
22020
22021
22022
22023
22024
22025
22026
22027
22028
22029
22030
22031
22032
22033
22034
22035
22036
22037
22038
22039
22040
22041
22042
22043
22044
22045
22046
22047
22048
22049
22050
22051
22052
22053
22054
22055
22056
22057
22058
22059
22060
22061
22062
22063
22064
22065
22066
22067
22068
22069
22070
22071
22072
22073
22074
22075
22076
22077
22078
22079
22080
22081
22082
22083
22084
22085
22086
22087
22088
22089
22090
22091
22092
22093
22094
22095
22096
22097
22098
22099
22100
22101
22102
22103
22104
22105
22106
22107
22108
22109
22110
22111
22112
22113
22114
22115
22116
22117
22118
22119
22120
22121
22122
22123
22124
22125
22126
22127
22128
22129
22130
22131
22132
22133
22134
22135
22136
22137
22138
22139
22140
22141
22142
22143
22144
22145
22146
22147
22148
22149
22150
22151
22152
22153
22154
22155
22156
22157
22158
22159
22160
22161
22162
22163
22164
22165
22166
22167
22168
22169
22170
22171
22172
22173
22174
22175
22176
22177
22178
22179
22180
22181
22182
22183
22184
22185
22186
22187
22188
22189
22190
22191
22192
22193
22194
22195
22196
22197
22198
22199
22200
22201
22202
22203
22204
22205
22206
22207
22208
22209
22210
22211
22212
22213
22214
22215
22216
22217
22218
22219
22220
22221
22222
22223
22224
22225
22226
22227
22228
22229
22230
22231
22232
22233
22234
22235
22236
22237
22238
22239
22240
22241
22242
22243
22244
22245
22246
22247
22248
22249
22250
22251
22252
22253
22254
22255
22256
22257
22258
22259
22260
22261
22262
22263
22264
22265
22266
22267
22268
22269
22270
22271
22272
22273
22274
22275
22276
22277
22278
22279
22280
22281
22282
22283
22284
22285
22286
22287
22288
22289
22290
22291
22292
22293
22294
22295
22296
22297
22298
22299
22300
22301
22302
22303
22304
22305
22306
22307
22308
22309
22310
22311
22312
22313
22314
22315
22316
22317
22318
22319
22320
22321
22322
22323
22324
22325
22326
22327
22328
22329
22330
22331
22332
22333
22334
22335
22336
22337
22338
22339
22340
22341
22342
22343
22344
22345
22346
22347
22348
22349
22350
22351
22352
22353
22354
22355
22356
22357
22358
22359
22360
22361
22362
22363
22364
22365
22366
22367
22368
22369
22370
22371
22372
22373
22374
22375
22376
22377
22378
22379
22380
22381
22382
22383
22384
22385
22386
22387
22388
22389
22390
22391
22392
22393
22394
22395
22396
22397
22398
22399
22400
22401
22402
22403
22404
22405
22406
22407
22408
22409
22410
22411
22412
22413
22414
22415
22416
22417
22418
22419
22420
22421
22422
22423
22424
22425
22426
22427
22428
22429
22430
22431
22432
22433
22434
22435
22436
22437
22438
22439
22440
22441
22442
22443
22444
22445
22446
22447
22448
22449
22450
22451
22452
22453
22454
22455
22456
22457
22458
22459
22460
22461
22462
22463
22464
22465
22466
22467
22468
22469
22470
22471
22472
22473
22474
22475
22476
22477
22478
22479
22480
22481
22482
22483
22484
22485
22486
22487
22488
22489
22490
22491
22492
22493
22494
22495
22496
22497
22498
22499
22500
22501
22502
22503
22504
22505
22506
22507
22508
22509
22510
22511
22512
22513
22514
22515
22516
22517
22518
22519
22520
22521
22522
22523
22524
22525
22526
22527
22528
22529
22530
22531
22532
22533
22534
22535
22536
22537
22538
22539
22540
22541
22542
22543
22544
22545
22546
22547
22548
22549
22550
22551
22552
22553
22554
22555
22556
22557
22558
22559
22560
22561
22562
22563
22564
22565
22566
22567
22568
22569
22570
22571
22572
22573
22574
22575
22576
22577
22578
22579
22580
22581
22582
22583
22584
22585
22586
22587
22588
22589
22590
22591
22592
22593
22594
22595
22596
22597
22598
22599
22600
22601
22602
22603
22604
22605
22606
22607
22608
22609
22610
22611
22612
22613
22614
22615
22616
22617
22618
22619
22620
22621
22622
22623
22624
22625
22626
22627
22628
22629
22630
22631
22632
22633
22634
22635
22636
22637
22638
22639
22640
22641
22642
22643
22644
22645
22646
22647
22648
22649
22650
22651
22652
22653
22654
22655
22656
22657
22658
22659
22660
22661
22662
22663
22664
22665
22666
22667
22668
22669
22670
22671
22672
22673
22674
22675
22676
22677
22678
22679
22680
22681
22682
22683
22684
22685
22686
22687
22688
22689
22690
22691
22692
22693
22694
22695
22696
22697
22698
22699
22700
22701
22702
22703
22704
22705
22706
22707
22708
22709
22710
22711
22712
22713
22714
22715
22716
22717
22718
22719
22720
22721
22722
22723
22724
22725
22726
22727
22728
22729
22730
22731
22732
22733
22734
22735
22736
22737
22738
22739
22740
22741
22742
22743
22744
22745
22746
22747
22748
22749
22750
22751
22752
22753
22754
22755
22756
22757
22758
22759
22760
22761
22762
22763
22764
22765
22766
22767
22768
22769
22770
22771
22772
22773
22774
22775
22776
22777
22778
22779
22780
22781
22782
22783
22784
22785
22786
22787
22788
22789
22790
22791
22792
22793
22794
22795
22796
22797
22798
22799
22800
22801
22802
22803
22804
22805
22806
22807
22808
22809
22810
22811
22812
22813
22814
22815
22816
22817
22818
22819
22820
22821
22822
22823
22824
22825
22826
22827
22828
22829
22830
22831
22832
22833
22834
22835
22836
22837
22838
22839
22840
22841
22842
22843
22844
22845
22846
22847
22848
22849
22850
22851
22852
22853
22854
22855
22856
22857
22858
22859
22860
22861
22862
22863
22864
22865
22866
22867
22868
22869
22870
22871
22872
22873
22874
22875
22876
22877
22878
22879
22880
22881
22882
22883
22884
22885
22886
22887
22888
22889
22890
22891
22892
22893
22894
22895
22896
22897
22898
22899
22900
22901
22902
22903
22904
22905
22906
22907
22908
22909
22910
22911
22912
22913
22914
22915
22916
22917
22918
22919
22920
22921
22922
22923
22924
22925
22926
22927
22928
22929
22930
22931
22932
22933
22934
22935
22936
22937
22938
22939
22940
22941
22942
22943
22944
22945
22946
22947
22948
22949
22950
22951
22952
22953
22954
22955
22956
22957
22958
22959
22960
22961
22962
22963
22964
22965
22966
22967
22968
22969
22970
22971
22972
22973
22974
22975
22976
22977
22978
22979
22980
22981
22982
22983
22984
22985
22986
22987
22988
22989
22990
22991
22992
22993
22994
22995
22996
22997
22998
22999
23000
23001
23002
23003
23004
23005
23006
23007
23008
23009
23010
23011
23012
23013
23014
23015
23016
23017
23018
23019
23020
23021
23022
23023
23024
23025
23026
23027
23028
23029
23030
23031
23032
23033
23034
23035
23036
23037
23038
23039
23040
23041
23042
23043
23044
23045
23046
23047
23048
23049
23050
23051
23052
23053
23054
23055
23056
23057
23058
23059
23060
23061
23062
23063
23064
23065
23066
23067
23068
23069
23070
23071
23072
23073
23074
23075
23076
23077
23078
23079
23080
23081
23082
23083
23084
23085
23086
23087
23088
23089
23090
23091
23092
23093
23094
23095
23096
23097
23098
23099
23100
23101
23102
23103
23104
23105
23106
23107
23108
23109
23110
23111
23112
23113
23114
23115
23116
23117
23118
23119
23120
23121
23122
23123
23124
23125
23126
23127
23128
23129
23130
23131
23132
23133
23134
23135
23136
23137
23138
23139
23140
23141
23142
23143
23144
23145
23146
23147
23148
23149
23150
23151
23152
23153
23154
23155
23156
23157
23158
23159
23160
23161
23162
23163
23164
23165
23166
23167
23168
23169
23170
23171
23172
23173
23174
23175
23176
23177
23178
23179
23180
23181
23182
23183
23184
23185
23186
23187
23188
23189
23190
23191
23192
23193
23194
23195
23196
23197
23198
23199
23200
23201
23202
23203
23204
23205
23206
23207
23208
23209
23210
23211
23212
23213
23214
23215
23216
23217
23218
23219
23220
23221
23222
23223
23224
23225
23226
23227
23228
23229
23230
23231
23232
23233
23234
23235
23236
23237
23238
23239
23240
23241
23242
23243
23244
23245
23246
23247
23248
23249
23250
23251
23252
23253
23254
23255
23256
23257
23258
23259
23260
23261
23262
23263
23264
23265
23266
23267
23268
23269
23270
23271
23272
23273
23274
23275
23276
23277
23278
23279
23280
23281
23282
23283
23284
23285
23286
23287
23288
23289
23290
23291
23292
23293
23294
23295
23296
23297
23298
23299
23300
23301
23302
23303
23304
23305
23306
23307
23308
23309
23310
23311
23312
23313
23314
23315
23316
23317
23318
23319
23320
23321
23322
23323
23324
23325
23326
23327
23328
23329
23330
23331
23332
23333
23334
23335
23336
23337
23338
23339
23340
23341
23342
23343
23344
23345
23346
23347
23348
23349
23350
23351
23352
23353
23354
23355
23356
23357
23358
23359
23360
23361
23362
23363
23364
23365
23366
23367
23368
23369
23370
23371
23372
23373
23374
23375
23376
23377
23378
23379
23380
23381
23382
23383
23384
23385
23386
23387
23388
23389
23390
23391
23392
23393
23394
23395
23396
23397
23398
23399
23400
23401
23402
23403
23404
23405
23406
23407
23408
23409
23410
23411
23412
23413
23414
23415
23416
23417
23418
23419
23420
23421
23422
23423
23424
23425
23426
23427
23428
23429
23430
23431
23432
23433
23434
23435
23436
23437
23438
23439
23440
23441
23442
23443
23444
23445
23446
23447
23448
23449
23450
23451
23452
23453
23454
23455
23456
23457
23458
23459
23460
23461
23462
23463
23464
23465
23466
23467
23468
23469
23470
23471
23472
23473
23474
23475
23476
23477
23478
23479
23480
23481
23482
23483
23484
23485
23486
23487
23488
23489
23490
23491
23492
23493
23494
23495
23496
23497
23498
23499
23500
--- linux-2.6.8.1-t044-driver-update//drivers/scsi/lpfc/lpfc_fcp.c	1970-01-01 03:00:00.000000000 +0300
+++ rhel4u2//drivers/scsi/lpfc/lpfc_fcp.c	2005-10-19 11:47:17.000000000 +0400
@@ -0,0 +1,2470 @@
+/*******************************************************************
+ * This file is part of the Emulex Linux Device Driver for         *
+ * Fibre Channel Host Bus Adapters.                                *
+ * Copyright (C) 2003-2005 Emulex.  All rights reserved.           *
+ * EMULEX and SLI are trademarks of Emulex.                        *
+ * www.emulex.com                                                  *
+ *                                                                 *
+ * This program is free software; you can redistribute it and/or   *
+ * modify it under the terms of version 2 of the GNU General       *
+ * Public License as published by the Free Software Foundation.    *
+ * This program is distributed in the hope that it will be useful. *
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
+ * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
+ * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
+ * more details, a copy of which can be found in the file COPYING  *
+ * included with this package.                                     *
+ *******************************************************************/
+
+/*
+ * $Id: lpfc_fcp.c 1.466.1.3 2005/06/21 15:48:55EDT sf_support Exp  $
+ */
+
+#include <linux/version.h>
+#include <linux/config.h>
+#include <linux/init.h>
+#include <linux/blkdev.h>
+#include <linux/ctype.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/pci.h>
+#include <linux/smp_lock.h>
+#include <linux/spinlock.h>
+#include <linux/timer.h>
+#include <linux/utsname.h>
+
+#include <asm/byteorder.h>
+
+#include <scsi/scsi_device.h>
+#include <scsi/scsi_host.h>
+#include <scsi/scsi_cmnd.h>
+#include <scsi/scsi_tcq.h>
+#include <scsi/scsi_transport_fc.h>
+
+#include "lpfc_sli.h"
+#include "lpfc_disc.h"
+#include "lpfc_scsi.h"
+#include "lpfc.h"
+#include "lpfc_fcp.h"
+#include "lpfc_hw.h"
+#include "lpfc_logmsg.h"
+#include "lpfc_mem.h"
+#include "lpfc_version.h"
+#include "lpfc_crtn.h"
+#include "lpfc_compat.h"
+
+static char *lpfc_drvr_name = LPFC_DRIVER_NAME;
+
+static struct scsi_transport_template *lpfc_transport_template = NULL;
+
+struct list_head lpfc_hba_list = LIST_HEAD_INIT(lpfc_hba_list);
+EXPORT_SYMBOL(lpfc_hba_list);
+
+static const char *
+lpfc_info(struct Scsi_Host *host)
+{
+	struct lpfc_hba    *phba = (struct lpfc_hba *) host->hostdata[0];
+	int len;
+	static char  lpfcinfobuf[384];
+
+	memset(lpfcinfobuf,0,384);
+	if (phba && phba->pcidev){
+		strncpy(lpfcinfobuf, phba->ModelDesc, 256);
+		len = strlen(lpfcinfobuf);
+		snprintf(lpfcinfobuf + len,
+			384-len,
+	       		" on PCI bus %02x device %02x irq %d",
+			phba->pcidev->bus->number,
+		 	phba->pcidev->devfn,
+			phba->pcidev->irq);
+		len = strlen(lpfcinfobuf);
+		if (phba->Port[0]) {
+			snprintf(lpfcinfobuf + len,
+				 384-len,
+				 " port %s",
+				 phba->Port);
+		}
+	}
+	return lpfcinfobuf;
+}
+
+static void
+lpfc_jedec_to_ascii(int incr, char hdw[])
+{
+	int i, j;
+	for (i = 0; i < 8; i++) {
+		j = (incr & 0xf);
+		if (j <= 9)
+			hdw[7 - i] = 0x30 +  j;
+		 else
+			hdw[7 - i] = 0x61 + j - 10;
+		incr = (incr >> 4);
+	}
+	hdw[8] = 0;
+	return;
+}
+
+static ssize_t
+lpfc_drvr_version_show(struct class_device *cdev, char *buf)
+{
+	return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
+}
+
+static ssize_t
+management_version_show(struct class_device *cdev, char *buf)
+{
+	return snprintf(buf, PAGE_SIZE, DFC_API_VERSION "\n");
+}
+
+static ssize_t
+lpfc_info_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
+}
+
+static ssize_t
+lpfc_serialnum_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
+}
+
+static ssize_t
+lpfc_modeldesc_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
+}
+
+static ssize_t
+lpfc_modelname_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
+}
+
+static ssize_t
+lpfc_programtype_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
+}
+
+static ssize_t
+lpfc_portnum_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
+}
+
+static ssize_t
+lpfc_fwrev_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	char fwrev[32];
+	lpfc_decode_firmware_rev(phba, fwrev, 1);
+	return snprintf(buf, PAGE_SIZE, "%s\n",fwrev);
+}
+
+static ssize_t
+lpfc_hdw_show(struct class_device *cdev, char *buf)
+{
+	char hdw[9];
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	lpfc_vpd_t *vp = &phba->vpd;
+	lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
+	return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
+}
+static ssize_t
+lpfc_option_rom_version_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
+}
+static ssize_t
+lpfc_state_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	int len = 0;
+	switch (phba->hba_state) {
+	case LPFC_INIT_START:
+	case LPFC_INIT_MBX_CMDS:
+	case LPFC_LINK_DOWN:
+		len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
+		break;
+	case LPFC_LINK_UP:
+	case LPFC_LOCAL_CFG_LINK:
+		len += snprintf(buf + len, PAGE_SIZE-len, "Link Up\n");
+		break;
+	case LPFC_FLOGI:
+	case LPFC_FABRIC_CFG_LINK:
+	case LPFC_NS_REG:
+	case LPFC_NS_QRY:
+	case LPFC_BUILD_DISC_LIST:
+	case LPFC_DISC_AUTH:
+	case LPFC_CLEAR_LA:
+		len += snprintf(buf + len, PAGE_SIZE-len,
+				"Link Up - Discovery\n");
+		break;
+	case LPFC_HBA_READY:
+		len += snprintf(buf + len, PAGE_SIZE-len,
+				"Link Up - Ready:\n");
+		if (phba->fc_topology == TOPOLOGY_LOOP) {
+			if (phba->fc_flag & FC_PUBLIC_LOOP)
+				len += snprintf(buf + len, PAGE_SIZE-len,
+						"   Public Loop\n");
+			else
+				len += snprintf(buf + len, PAGE_SIZE-len,
+						"   Private Loop\n");
+		} else {
+			if (phba->fc_flag & FC_FABRIC)
+				len += snprintf(buf + len, PAGE_SIZE-len,
+						"   Fabric\n");
+			else
+				len += snprintf(buf + len, PAGE_SIZE-len,
+						"   Point-2-Point\n");
+		}
+	}
+	return len;
+}
+
+static ssize_t
+lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	return snprintf(buf, PAGE_SIZE, "%d\n", phba->fc_map_cnt +
+							phba->fc_unmap_cnt);
+}
+
+/*
+ * These are replaced by Generic FC transport attributes
+ */
+static ssize_t
+lpfc_speed_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	int len = 0;
+	if (phba->fc_linkspeed == LA_4GHZ_LINK)
+		len += snprintf(buf + len, PAGE_SIZE-len, "4 Gigabit\n");
+	else
+	if (phba->fc_linkspeed == LA_2GHZ_LINK)
+		len += snprintf(buf + len, PAGE_SIZE-len, "2 Gigabit\n");
+	else
+		len += snprintf(buf + len, PAGE_SIZE-len, "1 Gigabit\n");
+	return len;
+}
+
+static ssize_t
+lpfc_node_name_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	uint64_t node_name = 0;
+	memcpy (&node_name, &phba->fc_nodename, sizeof (struct lpfc_name));
+	return snprintf(buf, PAGE_SIZE, "0x%llx\n",
+				(unsigned long long) be64_to_cpu(node_name));
+}
+static ssize_t
+lpfc_port_name_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	uint64_t port_name = 0;
+	memcpy (&port_name, &phba->fc_portname, sizeof (struct lpfc_name));
+	return snprintf(buf, PAGE_SIZE, "0x%llx\n",
+				(unsigned long long) be64_to_cpu(port_name));
+}
+static ssize_t
+lpfc_did_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	return snprintf(buf, PAGE_SIZE, "0x%x\n", phba->fc_myDID);
+}
+
+static ssize_t
+lpfc_port_type_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+
+	size_t retval = -EPERM;
+
+	if (phba->fc_topology == TOPOLOGY_LOOP) {
+		if (phba->fc_flag & FC_PUBLIC_LOOP)
+			retval = snprintf(buf, PAGE_SIZE, "NL_Port\n");
+		else
+		        retval = snprintf(buf, PAGE_SIZE, "L_Port\n");
+	} else {
+		if (phba->fc_flag & FC_FABRIC)
+			retval = snprintf(buf, PAGE_SIZE, "N_Port\n");
+		else
+			retval = snprintf(buf, PAGE_SIZE,
+					  "Point-to-Point N_Port\n");
+	}
+
+	return retval;
+}
+
+static ssize_t
+lpfc_fabric_name_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	uint64_t node_name = 0;
+	memcpy (&node_name, &phba->fc_nodename, sizeof (struct lpfc_name));
+
+	if ((phba->fc_flag & FC_FABRIC) ||
+	    ((phba->fc_topology == TOPOLOGY_LOOP) &&
+	     (phba->fc_flag & FC_PUBLIC_LOOP))) {
+			memcpy(&node_name,
+			       & phba->fc_fabparam.nodeName,
+			       sizeof (struct lpfc_name));
+	}
+
+	return snprintf(buf, PAGE_SIZE, "0x%08llx\n",
+				(unsigned long long) be64_to_cpu(node_name));
+}
+
+static ssize_t
+lpfc_events_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	int i = 0, len = 0, get = phba->hba_event_put;
+	struct lpfc_hba_event *rec;
+
+	if (get == phba->hba_event_get)
+		 return snprintf(buf, PAGE_SIZE, "None\n");
+
+	for (i = 0; i < MAX_HBAEVT; i++) {
+		if (get == 0)
+			get = MAX_HBAEVT;
+		get--;
+		rec = &phba->hbaevt[get];
+		switch (rec->fc_eventcode) {
+			case 0:
+				len += snprintf(buf+len, PAGE_SIZE-len,
+						"---------");
+				break;
+			case HBA_EVENT_RSCN:
+				len += snprintf(buf+len, PAGE_SIZE-len,
+						"RSCN     ");
+				break;
+			case HBA_EVENT_LINK_UP:
+				len += snprintf(buf+len, PAGE_SIZE-len,
+						 "LINK UP  ");
+				break;
+			case HBA_EVENT_LINK_DOWN:
+				len += snprintf(buf+len, PAGE_SIZE-len,
+							"LINK DOWN");
+				break;
+			default:
+				len += snprintf(buf+len, PAGE_SIZE-len,
+						"?????????");
+				break;
+
+		}
+		len += snprintf(buf+len, PAGE_SIZE-len, " %d,%d,%d,%d\n",
+				 rec->fc_evdata1, rec->fc_evdata2,
+				 rec->fc_evdata3, rec->fc_evdata4);
+	}
+	return len;
+}
+
+static ssize_t
+lpfc_issue_lip (struct class_device *cdev, const char *buf, size_t count)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba *) host->hostdata[0];
+ 	int val = 0;
+	LPFC_MBOXQ_t *pmboxq;
+	int mbxstatus = MBXERR_ERROR;
+
+ 	if ((sscanf(buf, "%d", &val) != 1) ||
+	    (val != 1))
+		return -EINVAL;
+
+	if ((phba->fc_flag & FC_OFFLINE_MODE) ||
+	    (phba->hba_state != LPFC_HBA_READY))
+		return -EPERM;
+
+	pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
+
+	if (!pmboxq)
+		return -ENOMEM;
+
+	memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
+	lpfc_init_link(phba, pmboxq, phba->cfg_topology, phba->cfg_link_speed);
+	mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
+
+	if (mbxstatus == MBX_TIMEOUT)
+		pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
+	else
+		mempool_free( pmboxq, phba->mbox_mem_pool);
+
+	if (mbxstatus == MBXERR_ERROR)
+		return -EIO;
+
+	return strlen(buf);
+}
+
+static ssize_t
+lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
+}
+
+static ssize_t
+lpfc_board_online_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+
+	if (!phba) return -EPERM;
+
+	if (phba->fc_flag & FC_OFFLINE_MODE)
+		return snprintf(buf, PAGE_SIZE, "0\n");
+	else
+		return snprintf(buf, PAGE_SIZE, "1\n");
+}
+
+static ssize_t
+lpfc_board_online_store(struct class_device *cdev, const char *buf,
+								size_t count)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+ 	int val=0;
+
+	if (!phba) return -EPERM;
+
+ 	if (sscanf(buf, "%d", &val) != 1)
+		return -EINVAL;
+
+	if (val && (phba->fc_flag & FC_OFFLINE_MODE)) {
+		lpfc_online(phba);
+	}
+	else if (!val && !(phba->fc_flag & FC_OFFLINE_MODE)) {
+		lpfc_offline(phba);
+	}
+
+	return strlen(buf);
+}
+
+static int
+lpfc_disc_ndlp_show(struct lpfc_hba * phba, struct lpfc_nodelist *ndlp,
+			char *buf, int offset)
+{
+	int len = 0, pgsz = PAGE_SIZE;
+	uint8_t name[sizeof (struct lpfc_name)];
+
+	buf += offset;
+	pgsz -= offset;
+	len += snprintf(buf + len, pgsz -len,
+			"DID %06x WWPN ", ndlp->nlp_DID);
+
+	/* A Fibre Channel node or port name is 8 octets
+	 * long and delimited by colons.
+	 */
+	memcpy (&name[0], &ndlp->nlp_portname,
+		sizeof (struct lpfc_name));
+	len += snprintf(buf + len, pgsz-len,
+			"%02x:%02x:%02x:%02x:%02x:%02x:"
+			"%02x:%02x",
+			name[0], name[1], name[2],
+			name[3], name[4], name[5],
+			name[6], name[7]);
+
+	len += snprintf(buf + len, pgsz-len,
+			" WWNN ");
+	memcpy (&name[0], &ndlp->nlp_nodename,
+		sizeof (struct lpfc_name));
+	len += snprintf(buf + len, pgsz-len,
+			"%02x:%02x:%02x:%02x:%02x:%02x:"
+			"%02x:%02x\n",
+			name[0], name[1], name[2],
+			name[3], name[4], name[5],
+			name[6], name[7]);
+	len += snprintf(buf + len, pgsz-len,
+			"    INFO %02x:%08x:%02x:%02x:%02x:%02x:"
+			"%02x:%02x:%02x\n",
+			ndlp->nlp_state, ndlp->nlp_flag, ndlp->nlp_type,
+			ndlp->nlp_rpi, ndlp->nlp_sid, ndlp->nlp_failMask,
+			ndlp->nlp_retry, ndlp->nlp_disc_refcnt,
+			ndlp->nlp_fcp_info);
+	return len;
+}
+
+#define LPFC_MAX_SYS_DISC_ENTRIES 35
+
+static ssize_t
+lpfc_disc_npr_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	struct lpfc_nodelist  *ndlp, *next_ndlp;
+	struct list_head *listp;
+	unsigned long iflag;
+	int i = 0, len = 0;
+
+	if (!phba) return -EPERM;
+
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+	listp = &phba->fc_npr_list;
+	if (list_empty(listp)) {
+		spin_unlock_irqrestore(phba->host->host_lock, iflag);
+		return snprintf(buf, PAGE_SIZE, "NPR    list: Empty\n");
+	}
+
+	len += snprintf(buf+len, PAGE_SIZE-len, "NPR    list: %d Entries\n",
+		phba->fc_npr_cnt);
+	list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
+		i++;
+		if(i > LPFC_MAX_SYS_DISC_ENTRIES) {
+			len += snprintf(buf+len, PAGE_SIZE-len,
+			"Missed %d entries - sysfs %ld limit exceeded\n",
+			(phba->fc_npr_cnt - i + 1), PAGE_SIZE);
+			break;
+		}
+		if(len > (PAGE_SIZE-1))  /* double check */
+			break;
+		len += lpfc_disc_ndlp_show(phba, ndlp, buf, len);
+	}
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+	return len;
+}
+
+static ssize_t
+lpfc_disc_map_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	struct lpfc_nodelist  *ndlp, *next_ndlp;
+	struct list_head *listp;
+	unsigned long iflag;
+	int i = 0, len = 0;
+
+	if (!phba) return -EPERM;
+
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+	listp = &phba->fc_nlpmap_list;
+	if (list_empty(listp)) {
+		spin_unlock_irqrestore(phba->host->host_lock, iflag);
+		return snprintf(buf, PAGE_SIZE, "Map    list: Empty\n");
+	}
+
+	len += snprintf(buf+len, PAGE_SIZE-len, "Map    list: %d Entries\n",
+		phba->fc_map_cnt);
+	list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
+		i++;
+		if(i > LPFC_MAX_SYS_DISC_ENTRIES) {
+			len += snprintf(buf+len, PAGE_SIZE-len,
+			"Missed %d entries - sysfs %ld limit exceeded\n",
+			(phba->fc_map_cnt - i + 1), PAGE_SIZE);
+			break;
+		}
+		if(len > (PAGE_SIZE-1))  /* double check */
+			break;
+		len += lpfc_disc_ndlp_show(phba, ndlp, buf, len);
+	}
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+	return len;
+}
+
+static ssize_t
+lpfc_disc_unmap_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	struct lpfc_nodelist  *ndlp, *next_ndlp;
+	struct list_head *listp;
+	unsigned long iflag;
+	int i = 0, len = 0;
+
+	if (!phba) return -EPERM;
+
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+	listp = &phba->fc_nlpunmap_list;
+	if (list_empty(listp)) {
+		spin_unlock_irqrestore(phba->host->host_lock, iflag);
+		return snprintf(buf, PAGE_SIZE, "Unmap  list: Empty\n");
+	}
+
+	len += snprintf(buf+len, PAGE_SIZE-len, "Unmap  list: %d Entries\n",
+		phba->fc_unmap_cnt);
+	list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
+		i++;
+		if(i > LPFC_MAX_SYS_DISC_ENTRIES) {
+			len += snprintf(buf+len, PAGE_SIZE-len,
+			"Missed %d entries - sysfs %ld limit exceeded\n",
+			(phba->fc_unmap_cnt - i + 1), PAGE_SIZE);
+			break;
+		}
+		if(len > (PAGE_SIZE-1))  /* double check */
+			break;
+		len += lpfc_disc_ndlp_show(phba, ndlp, buf, len);
+	}
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+	return len;
+}
+
+static ssize_t
+lpfc_disc_prli_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	struct lpfc_nodelist  *ndlp, *next_ndlp;
+	struct list_head *listp;
+	unsigned long iflag;
+	int i = 0, len = 0;
+
+	if (!phba) return -EPERM;
+
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+	listp = &phba->fc_prli_list;
+	if (list_empty(listp)) {
+		spin_unlock_irqrestore(phba->host->host_lock, iflag);
+		return snprintf(buf, PAGE_SIZE, "PRLI   list: Empty\n");
+	}
+
+	len += snprintf(buf+len, PAGE_SIZE-len, "PRLI   list: %d Entries\n",
+		phba->fc_prli_cnt);
+	list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
+		i++;
+		if(i > LPFC_MAX_SYS_DISC_ENTRIES) {
+			len += snprintf(buf+len, PAGE_SIZE-len,
+			"Missed %d entries - sysfs %ld limit exceeded\n",
+			(phba->fc_prli_cnt - i + 1), PAGE_SIZE);
+			break;
+		}
+		if(len > (PAGE_SIZE-1))  /* double check */
+			break;
+		len += lpfc_disc_ndlp_show(phba, ndlp, buf, len);
+	}
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+	return len;
+}
+
+static ssize_t
+lpfc_disc_reglgn_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	struct lpfc_nodelist  *ndlp, *next_ndlp;
+	struct list_head *listp;
+	unsigned long iflag;
+	int i = 0, len = 0;
+
+	if (!phba) return -EPERM;
+
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+	listp = &phba->fc_reglogin_list;
+	if (list_empty(listp)) {
+		spin_unlock_irqrestore(phba->host->host_lock, iflag);
+		return snprintf(buf, PAGE_SIZE, "RegLgn list: Empty\n");
+	}
+
+	len += snprintf(buf+len, PAGE_SIZE-len, "RegLgn list: %d Entries\n",
+		phba->fc_reglogin_cnt);
+	list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
+		i++;
+		if(i > LPFC_MAX_SYS_DISC_ENTRIES) {
+			len += snprintf(buf+len, PAGE_SIZE-len,
+			"Missed %d entries - sysfs %ld limit exceeded\n",
+			(phba->fc_reglogin_cnt - i + 1), PAGE_SIZE);
+			break;
+		}
+		if(len > (PAGE_SIZE-1))  /* double check */
+			break;
+		len += lpfc_disc_ndlp_show(phba, ndlp, buf, len);
+	}
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+	return len;
+}
+
+static ssize_t
+lpfc_disc_adisc_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	struct lpfc_nodelist  *ndlp, *next_ndlp;
+	struct list_head *listp;
+	unsigned long iflag;
+	int i = 0, len = 0;
+
+	if (!phba) return -EPERM;
+
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+	listp = &phba->fc_adisc_list;
+	if (list_empty(listp)) {
+		spin_unlock_irqrestore(phba->host->host_lock, iflag);
+		return snprintf(buf, PAGE_SIZE, "ADISC  list: Empty\n");
+	}
+
+	len += snprintf(buf+len, PAGE_SIZE-len, "ADISC  list: %d Entries\n",
+		phba->fc_adisc_cnt);
+	list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
+		i++;
+		if(i > LPFC_MAX_SYS_DISC_ENTRIES) {
+			len += snprintf(buf+len, PAGE_SIZE-len,
+			"Missed %d entries - sysfs %ld limit exceeded\n",
+			(phba->fc_adisc_cnt - i + 1), PAGE_SIZE);
+			break;
+		}
+		if(len > (PAGE_SIZE-1))  /* double check */
+			break;
+		len += lpfc_disc_ndlp_show(phba, ndlp, buf, len);
+	}
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+	return len;
+}
+
+static ssize_t
+lpfc_disc_plogi_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	struct lpfc_nodelist  *ndlp, *next_ndlp;
+	struct list_head *listp;
+	unsigned long iflag;
+	int i = 0, len = 0;
+
+	if (!phba) return -EPERM;
+
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+	listp = &phba->fc_plogi_list;
+	if (list_empty(listp)) {
+		spin_unlock_irqrestore(phba->host->host_lock, iflag);
+		return snprintf(buf, PAGE_SIZE, "PLOGI  list: Empty\n");
+	}
+
+	len += snprintf(buf+len, PAGE_SIZE-len, "PLOGI  list: %d Entries\n",
+		phba->fc_plogi_cnt);
+	list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
+		i++;
+		if(i > LPFC_MAX_SYS_DISC_ENTRIES) {
+			len += snprintf(buf+len, PAGE_SIZE-len,
+			"Missed %d entries - sysfs %ld limit exceeded\n",
+			(phba->fc_plogi_cnt - i + 1), PAGE_SIZE);
+			break;
+		}
+		if(len > (PAGE_SIZE-1))  /* double check */
+			break;
+		len += lpfc_disc_ndlp_show(phba, ndlp, buf, len);
+	}
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+	return len;
+}
+
+static ssize_t
+lpfc_disc_unused_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	struct lpfc_nodelist  *ndlp, *next_ndlp;
+	struct list_head *listp;
+	unsigned long iflag;
+	int i = 0, len = 0;
+
+	if (!phba) return -EPERM;
+
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+	listp = &phba->fc_unused_list;
+	if (list_empty(listp)) {
+		spin_unlock_irqrestore(phba->host->host_lock, iflag);
+		return snprintf(buf, PAGE_SIZE, "Unused list: Empty\n");
+	}
+
+	len += snprintf(buf+len, PAGE_SIZE-len, "Unused list: %d Entries\n",
+		phba->fc_unused_cnt);
+	list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
+		i++;
+		if(i > LPFC_MAX_SYS_DISC_ENTRIES) {
+			len += snprintf(buf+len, PAGE_SIZE-len,
+			"Missed %d entries - sysfs %ld limit exceeded\n",
+			(phba->fc_unused_cnt - i + 1), PAGE_SIZE);
+			break;
+		}
+		if(len > (PAGE_SIZE-1))  /* double check */
+			break;
+		len += lpfc_disc_ndlp_show(phba, ndlp, buf, len);
+	}
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+	return len;
+}
+
+#define LPFC_MAX_SYS_OUTFCPIO_ENTRIES 50
+
+static ssize_t
+lpfc_outfcpio_show(struct class_device *cdev, char *buf)
+{
+	struct Scsi_Host *host = class_to_shost(cdev);
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	struct lpfc_sli      *psli;
+	struct lpfc_sli_ring *pring;
+	struct lpfc_target   *targetp;
+	struct lpfc_nodelist *ndlp;
+	struct lpfc_scsi_buf *lpfc_cmd;
+	struct list_head *curr, *next;
+	struct lpfc_iocbq *iocb;
+	struct lpfc_iocbq *next_iocb;
+	IOCB_t *cmd;
+	unsigned long iflag;
+	int i = 0, len = 0;
+	int cnt = 0, unused = 0, total = 0;
+	int tx_count, txcmpl_count;
+
+	if (!phba) return -EPERM;
+	psli = &phba->sli;
+	pring = &psli->ring[psli->fcp_ring];
+
+
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+
+	for(i=0;i<LPFC_MAX_TARGET;i++) {
+		targetp = phba->device_queue_hash[i];
+		if(targetp) {
+			if(cnt >= LPFC_MAX_SYS_OUTFCPIO_ENTRIES) {
+				unused++;
+				continue;
+			}
+			cnt++;
+			len += snprintf(buf+len, PAGE_SIZE-len,
+				"ID %03d:qcmd %08x done %08x err %08x "
+				"slv %03x ", targetp->scsi_id, targetp->qcmdcnt,
+				targetp->iodonecnt, targetp->errorcnt,
+				targetp->slavecnt);
+			total += (targetp->qcmdcnt - targetp->iodonecnt);
+
+			tx_count = 0;
+			txcmpl_count = 0;
+
+			/* Count I/Os on txq and txcmplq. */
+			list_for_each_safe(curr, next, &pring->txq) {
+				next_iocb = list_entry(curr, struct lpfc_iocbq,
+					list);
+				iocb = next_iocb;
+				cmd = &iocb->iocb;
+
+				/* Must be a FCP command */
+				if ((cmd->ulpCommand != CMD_FCP_ICMND64_CR) &&
+				    (cmd->ulpCommand != CMD_FCP_IWRITE64_CR) &&
+				    (cmd->ulpCommand != CMD_FCP_IREAD64_CR)) {
+					continue;
+				}
+
+				/* context1 MUST be a struct lpfc_scsi_buf */
+				lpfc_cmd =
+				    (struct lpfc_scsi_buf *) (iocb->context1);
+				if ((lpfc_cmd == 0)
+				    || (lpfc_cmd->target->scsi_id !=
+					targetp->scsi_id)) {
+					continue;
+				}
+				tx_count++;
+			}
+
+			/* Next check the txcmplq */
+			list_for_each_safe(curr, next, &pring->txcmplq) {
+				next_iocb = list_entry(curr, struct lpfc_iocbq,
+					list);
+				iocb = next_iocb;
+				cmd = &iocb->iocb;
+
+				/* Must be a FCP command */
+				if ((cmd->ulpCommand != CMD_FCP_ICMND64_CR) &&
+				    (cmd->ulpCommand != CMD_FCP_IWRITE64_CR) &&
+				    (cmd->ulpCommand != CMD_FCP_IREAD64_CR)) {
+					continue;
+				}
+
+				/* context1 MUST be a struct lpfc_scsi_buf */
+				lpfc_cmd =
+				    (struct lpfc_scsi_buf *) (iocb->context1);
+				if ((lpfc_cmd == 0)
+				    || (lpfc_cmd->target->scsi_id !=
+					targetp->scsi_id)) {
+					continue;
+				}
+
+				txcmpl_count++;
+			}
+			len += snprintf(buf+len, PAGE_SIZE-len,
+				"tx %04x txc %04x ",
+				tx_count, txcmpl_count);
+
+			ndlp = targetp->pnode;
+			if(ndlp == NULL) {
+				len += snprintf(buf+len, PAGE_SIZE-len,
+					"DISAPPERED\n");
+			}
+			else {
+				if(ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
+					len += snprintf(buf+len, PAGE_SIZE-len,
+						"MAPPED\n");
+				}
+				else {
+					len += snprintf(buf+len, PAGE_SIZE-len,
+						"RECOVERY (%d)\n",
+						ndlp->nlp_state);
+				}
+			}
+		}
+		if(len > (PAGE_SIZE-1))  /* double check */
+			break;
+	}
+	if(unused) {
+		len += snprintf(buf+len, PAGE_SIZE-len,
+		"Missed x%x entries - sysfs %ld limit exceeded\n",
+		unused, PAGE_SIZE);
+	}
+	len += snprintf(buf+len, PAGE_SIZE-len,
+		"x%x total I/Os outstanding\n", total);
+
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+	return len;
+}
+
+#define lpfc_param_show(attr)	\
+static ssize_t \
+lpfc_##attr##_show(struct class_device *cdev, char *buf) \
+{ \
+ 	struct Scsi_Host *host = class_to_shost(cdev);\
+ 	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];\
+ 	int val = 0;\
+ 	if (phba){\
+ 		val = phba->cfg_##attr;\
+ 		return snprintf(buf, PAGE_SIZE, "%d\n",\
+ 				phba->cfg_##attr);\
+ 	}\
+ 	return -EPERM;\
+}
+
+#define lpfc_param_set(attr, default, minval, maxval)	\
+static int \
+lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
+{ \
+ 	if (val >= minval && val <= maxval) {\
+ 		phba->cfg_##attr = val;\
+ 		return 0;\
+ 	}\
+ 	phba->cfg_##attr = default;\
+ 	return -EINVAL;\
+}
+
+#define lpfc_param_store(attr)	\
+static ssize_t \
+lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
+{ \
+ 	struct Scsi_Host *host = class_to_shost(cdev);\
+ 	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];\
+ 	int val=0;\
+ 	if (sscanf(buf, "%d", &val) != 1)\
+ 		return -EPERM;\
+ 	if (phba){\
+ 		if (lpfc_##attr##_set(phba, val) == 0) \
+ 			return strlen(buf);\
+ 	}\
+ 	return -EINVAL;\
+}
+
+#define LPFC_ATTR(name, defval, minval, maxval, desc) \
+static int lpfc_##name = defval;\
+module_param(lpfc_##name, int, 0);\
+MODULE_PARM_DESC(lpfc_##name, desc);\
+lpfc_param_set(name, defval, minval, maxval)\
+
+
+#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
+static int lpfc_##name = defval;\
+module_param(lpfc_##name, int, 0);\
+MODULE_PARM_DESC(lpfc_##name, desc);\
+lpfc_param_show(name)\
+lpfc_param_set(name, defval, minval, maxval)\
+static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
+
+#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
+static int lpfc_##name = defval;\
+module_param(lpfc_##name, int, 0);\
+MODULE_PARM_DESC(lpfc_##name, desc);\
+lpfc_param_show(name)\
+lpfc_param_set(name, defval, minval, maxval)\
+lpfc_param_store(name)\
+static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
+			 lpfc_##name##_show, lpfc_##name##_store)
+
+static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
+static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
+static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
+static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
+static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
+static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_portnum_show, NULL);
+static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
+static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
+static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
+static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO,
+					lpfc_option_rom_version_show, NULL);
+static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO,
+					lpfc_num_discovered_ports_show, NULL);
+static CLASS_DEVICE_ATTR(speed, S_IRUGO, lpfc_speed_show, NULL);
+static CLASS_DEVICE_ATTR(node_name, S_IRUGO, lpfc_node_name_show, NULL);
+static CLASS_DEVICE_ATTR(port_name, S_IRUGO, lpfc_port_name_show, NULL);
+static CLASS_DEVICE_ATTR(portfcid, S_IRUGO, lpfc_did_show, NULL);
+static CLASS_DEVICE_ATTR(port_type, S_IRUGO, lpfc_port_type_show, NULL);
+static CLASS_DEVICE_ATTR(fabric_name, S_IRUGO, lpfc_fabric_name_show, NULL);
+static CLASS_DEVICE_ATTR(events, S_IRUGO, lpfc_events_show, NULL);
+static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
+static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show,
+			 NULL);
+static CLASS_DEVICE_ATTR(management_version, S_IRUGO, management_version_show,
+			 NULL);
+static CLASS_DEVICE_ATTR(issue_lip, S_IWUSR, NULL, lpfc_issue_lip);
+static CLASS_DEVICE_ATTR(board_online, S_IRUGO | S_IWUSR,
+			 lpfc_board_online_show, lpfc_board_online_store);
+
+static CLASS_DEVICE_ATTR(disc_npr, S_IRUGO, lpfc_disc_npr_show, NULL);
+static CLASS_DEVICE_ATTR(disc_map, S_IRUGO, lpfc_disc_map_show, NULL);
+static CLASS_DEVICE_ATTR(disc_unmap, S_IRUGO, lpfc_disc_unmap_show, NULL);
+static CLASS_DEVICE_ATTR(disc_prli, S_IRUGO, lpfc_disc_prli_show, NULL);
+static CLASS_DEVICE_ATTR(disc_reglgn, S_IRUGO, lpfc_disc_reglgn_show, NULL);
+static CLASS_DEVICE_ATTR(disc_adisc, S_IRUGO, lpfc_disc_adisc_show, NULL);
+static CLASS_DEVICE_ATTR(disc_plogi, S_IRUGO, lpfc_disc_plogi_show, NULL);
+static CLASS_DEVICE_ATTR(disc_unused, S_IRUGO, lpfc_disc_unused_show, NULL);
+static CLASS_DEVICE_ATTR(outfcpio, S_IRUGO, lpfc_outfcpio_show, NULL);
+
+/*
+# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
+# deluged with LOTS of information.
+# You can set a bit mask to record specific types of verbose messages:
+#
+# LOG_ELS                       0x1        ELS events
+# LOG_DISCOVERY                 0x2        Link discovery events
+# LOG_MBOX                      0x4        Mailbox events
+# LOG_INIT                      0x8        Initialization events
+# LOG_LINK_EVENT                0x10       Link events
+# LOG_IP                        0x20       IP traffic history
+# LOG_FCP                       0x40       FCP traffic history
+# LOG_NODE                      0x80       Node table events
+# LOG_MISC                      0x400      Miscellaneous events
+# LOG_SLI                       0x800      SLI events
+# LOG_CHK_COND                  0x1000     FCP Check condition flag
+# LOG_LIBDFC                    0x2000     LIBDFC events
+# LOG_ALL_MSG                   0xffff     LOG all messages
+*/
+LPFC_ATTR_RW(log_verbose, 0x0, 0x0, 0xffff, "Verbose logging bit-mask");
+
+/*
+# lun_queue_depth:  This parameter is used to limit the number of outstanding
+# commands per FCP LUN. Value range is [1,128]. Default value is 30.
+*/
+LPFC_ATTR_R(lun_queue_depth, 30, 1, 128,
+	    "Max number of FCP commands we can queue to a specific LUN");
+
+/*
+# Some disk devices have a "select ID" or "select Target" capability.
+# From a protocol standpoint "select ID" usually means select the
+# Fibre channel "ALPA".  In the FC-AL Profile there is an "informative
+# annex" which contains a table that maps a "select ID" (a number
+# between 0 and 7F) to an ALPA.  By default, for compatibility with
+# older drivers, the lpfc driver scans this table from low ALPA to high
+# ALPA.
+#
+# Turning on the scan-down variable (on  = 1, off = 0) will
+# cause the lpfc driver to use an inverted table, effectively
+# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
+#
+# (Note: This "select ID" functionality is a LOOP ONLY characteristic
+# and will not work across a fabric. Also this parameter will take
+# effect only in the case when ALPA map is not available.)
+*/
+LPFC_ATTR_R(scan_down, 1, 0, 1,
+	     "Start scanning for devices from highest ALPA to lowest");
+
+/*
+# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
+# until the timer expires. Value range is [0,255]. Default value is 20.
+# NOTE: this MUST be less then the SCSI Layer command timeout - 1.
+*/
+LPFC_ATTR_RW(nodev_tmo, 30, 0, 255,
+	     "Seconds driver will hold I/O waiting for a device to come back");
+
+/*
+# lpfc_topology:  link topology for init link
+#            0x0  = attempt loop mode then point-to-point
+#            0x02 = attempt point-to-point mode only
+#            0x04 = attempt loop mode only
+#            0x06 = attempt point-to-point mode then loop
+# Set point-to-point mode if you want to run as an N_Port.
+# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
+# Default value is 0.
+*/
+LPFC_ATTR_R(topology, 0, 0, 6, "Select Fibre Channel topology");
+
+/*
+# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
+# connection.
+#       0  = auto select (default)
+#       1  = 1 Gigabaud
+#       2  = 2 Gigabaud
+#       4  = 4 Gigabaud
+# Value range is [0,4]. Default value is 0.
+*/
+LPFC_ATTR_R(link_speed, 0, 0, 4, "Select link speed");
+
+/*
+# lpfc_fcp_class:  Determines FC class to use for the FCP protocol.
+# Value range is [2,3]. Default value is 3.
+*/
+LPFC_ATTR_R(fcp_class, 3, 2, 3,
+	     "Select Fibre Channel class of service for FCP sequences");
+
+/*
+# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
+# is [0,1]. Default value is 0.
+*/
+LPFC_ATTR_RW(use_adisc, 0, 0, 1,
+	     "Use ADISC on rediscovery to authenticate FCP devices");
+
+/*
+# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
+# range is [0,1]. Default value is 0.
+*/
+LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
+
+/*
+# lpfc_fcp_bind_method: It specifies the method of binding to be used for each
+# port. This  binding method is used for consistent binding and mapped
+# binding. A value of 1 will force WWNN binding, value of 2 will force WWPN
+# binding, value of 3 will force DID binding and value of 4 will force the
+# driver to derive binding from ALPA. Any consistent binding whose type does
+# not match with the bind method of the port will be ignored. Value range
+# is [1,4]. Default value is 2.
+*/
+LPFC_ATTR_R(fcp_bind_method, 2, 0, 4,
+	    "Select the bind method to be used");
+
+/*
+# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
+# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
+# value [0,63]. cr_count can take value [0,255]. Default value of cr_delay
+# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
+# cr_delay is set to 0.
+*/
+LPFC_ATTR(cr_delay, 0, 0, 63, "A count of milliseconds after which an"
+		"interrupt response is generated");
+
+LPFC_ATTR(cr_count, 1, 1, 255, "A count of I/O completions after which an"
+		"interrupt response is generated");
+
+/*
+# lpfc_fdmi_on: controls FDMI support.
+#       0 = no FDMI support
+#       1 = support FDMI without attribute of hostname
+#       2 = support FDMI with attribute of hostname
+# Value range [0,2]. Default value is 0.
+*/
+LPFC_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
+
+/*
+# Specifies the maximum number of ELS cmds we can have outstanding (for
+# discovery). Value range is [1,64]. Default value = 32.
+*/
+LPFC_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands"
+		 "during discovery");
+
+/*
+# lpfc_max_luns: maximum number of LUNs per target driver will support
+# Value range is [1,32768]. Default value is 256.
+# NOTE: The SCSI layer will scan each target for this many luns
+*/
+LPFC_ATTR_R(max_luns, 256, 1, 32768,
+	     "Maximum number of LUNs per target driver will support");
+
+
+static ssize_t
+sysfs_ctlreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
+{
+	unsigned long iflag;
+	size_t buf_off;
+	struct Scsi_Host *host = class_to_shost(container_of(kobj,
+					     struct class_device, kobj));
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+
+	if ((off + count) > FF_REG_AREA_SIZE)
+		return -ERANGE;
+
+	if (count == 0) return 0;
+
+	if (off % 4 || count % 4 || (unsigned long)buf % 4)
+		return -EINVAL;
+
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+
+	if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
+		spin_unlock_irqrestore(phba->host->host_lock, iflag);
+		return -EPERM;
+	}
+
+	for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
+		writel(*((uint32_t *)(buf + buf_off)),
+		       (uint8_t *)phba->ctrl_regs_memmap_p + off + buf_off);
+
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+
+	return count;
+}
+
+static ssize_t
+sysfs_ctlreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
+{
+	unsigned long iflag;
+	size_t buf_off;
+	uint32_t * tmp_ptr;
+	struct Scsi_Host *host = class_to_shost(container_of(kobj,
+					     struct class_device, kobj));
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+
+	if (off > FF_REG_AREA_SIZE)
+		return -ERANGE;
+
+	if ((off + count) > FF_REG_AREA_SIZE)
+		count = FF_REG_AREA_SIZE - off;
+
+	if (count == 0) return 0;
+
+	if (off % 4 || count % 4 || (unsigned long)buf % 4)
+		return -EINVAL;
+
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+
+	for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
+		tmp_ptr = (uint32_t *)(buf + buf_off);
+		*tmp_ptr = readl((uint8_t *)(phba->ctrl_regs_memmap_p
+					     + off + buf_off));
+	}
+
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+
+	return count;
+}
+
+static struct bin_attribute sysfs_ctlreg_attr = {
+	.attr = {
+		.name = "ctlreg",
+		.mode = S_IRUSR | S_IWUSR,
+		.owner = THIS_MODULE,
+	},
+	.size = 256,
+	.read = sysfs_ctlreg_read,
+	.write = sysfs_ctlreg_write,
+};
+
+
+#define MBOX_BUFF_SIZE (MAILBOX_CMD_WSIZE*sizeof(uint32_t))
+
+static void
+sysfs_mbox_idle (struct lpfc_hba * phba)
+{
+	phba->sysfs_mbox.state = SMBOX_IDLE;
+	phba->sysfs_mbox.offset = 0;
+
+	if (phba->sysfs_mbox.mbox) {
+		mempool_free(phba->sysfs_mbox.mbox,
+			     phba->mbox_mem_pool);
+		phba->sysfs_mbox.mbox = NULL;
+	}
+}
+
+static ssize_t
+sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
+{
+	unsigned long iflag;
+	struct Scsi_Host * host =
+		class_to_shost(container_of(kobj, struct class_device, kobj));
+	struct lpfc_hba * phba = (struct lpfc_hba*)host->hostdata[0];
+	struct lpfcMboxq * mbox = NULL;
+
+	if ((count + off) > MBOX_BUFF_SIZE)
+		return -ERANGE;
+
+	if (off % 4 ||  count % 4 || (unsigned long)buf % 4)
+		return -EINVAL;
+
+	if (count == 0)
+		return 0;
+
+	if (off == 0) {
+		mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
+		if (!mbox)
+			return -ENOMEM;
+
+	}
+
+	spin_lock_irqsave(host->host_lock, iflag);
+
+	if (off == 0) {
+		if (phba->sysfs_mbox.mbox)
+			mempool_free(mbox, phba->mbox_mem_pool);
+		else
+			phba->sysfs_mbox.mbox = mbox;
+		phba->sysfs_mbox.state = SMBOX_WRITING;
+	}
+	else {
+		if (phba->sysfs_mbox.state  != SMBOX_WRITING ||
+		    phba->sysfs_mbox.offset != off           ||
+		    phba->sysfs_mbox.mbox   == NULL ) {
+			sysfs_mbox_idle(phba);
+			spin_unlock_irqrestore(host->host_lock, iflag);
+			return -EINVAL;
+		}
+	}
+
+	memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
+	       buf, count);
+
+	phba->sysfs_mbox.offset = off + count;
+
+	spin_unlock_irqrestore(host->host_lock, iflag);
+
+	return count;
+}
+
+static ssize_t
+sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
+{
+	unsigned long iflag;
+	struct Scsi_Host *host =
+		class_to_shost(container_of(kobj, struct class_device,
+					    kobj));
+	struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
+	int rc;
+
+	if (off > sizeof(MAILBOX_t))
+		return -ERANGE;
+
+	if ((count + off) > sizeof(MAILBOX_t))
+		count = sizeof(MAILBOX_t) - off;
+
+	if (off % 4 ||  count % 4 || (unsigned long)buf % 4)
+		return -EINVAL;
+
+	if (off && count == 0)
+		return 0;
+
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+
+	if (off == 0 &&
+	    phba->sysfs_mbox.state  == SMBOX_WRITING &&
+	    phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
+
+		switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
+			/* Offline only */
+		case MBX_WRITE_NV:
+		case MBX_INIT_LINK:
+		case MBX_DOWN_LINK:
+		case MBX_CONFIG_LINK:
+		case MBX_CONFIG_RING:
+		case MBX_RESET_RING:
+		case MBX_UNREG_LOGIN:
+		case MBX_CLEAR_LA:
+		case MBX_DUMP_CONTEXT:
+		case MBX_RUN_DIAGS:
+		case MBX_RESTART:
+		case MBX_FLASH_WR_ULA:
+		case MBX_SET_MASK:
+		case MBX_SET_SLIM:
+		case MBX_SET_DEBUG:
+			if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
+				printk(KERN_WARNING "mbox_read:Command 0x%x "
+				       "is illegal in on-line state\n",
+				       phba->sysfs_mbox.mbox->mb.mbxCommand);
+				sysfs_mbox_idle(phba);
+				spin_unlock_irqrestore(phba->host->host_lock,
+						       iflag);
+				return -EPERM;
+			}
+		case MBX_LOAD_SM:
+		case MBX_READ_NV:
+		case MBX_READ_CONFIG:
+		case MBX_READ_RCONFIG:
+		case MBX_READ_STATUS:
+		case MBX_READ_XRI:
+		case MBX_READ_REV:
+		case MBX_READ_LNK_STAT:
+		case MBX_DUMP_MEMORY:
+		case MBX_DOWN_LOAD:
+		case MBX_UPDATE_CFG:
+		case MBX_LOAD_AREA:
+		case MBX_LOAD_EXP_ROM:
+			break;
+		case MBX_READ_SPARM64:
+		case MBX_READ_LA:
+		case MBX_READ_LA64:
+		case MBX_REG_LOGIN:
+		case MBX_REG_LOGIN64:
+		case MBX_CONFIG_PORT:
+		case MBX_RUN_BIU_DIAG:
+			printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
+			       phba->sysfs_mbox.mbox->mb.mbxCommand);
+			sysfs_mbox_idle(phba);
+			spin_unlock_irqrestore(phba->host->host_lock,
+					       iflag);
+			return -EPERM;
+		default:
+			printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
+			       phba->sysfs_mbox.mbox->mb.mbxCommand);
+			sysfs_mbox_idle(phba);
+			spin_unlock_irqrestore(phba->host->host_lock,
+					       iflag);
+			return -EPERM;
+		}
+
+		if ((phba->fc_flag & FC_OFFLINE_MODE) ||
+		    (!(phba->sli.sliinit.sli_flag & LPFC_SLI2_ACTIVE))){
+			spin_unlock_irqrestore(phba->host->host_lock, iflag);
+			rc = lpfc_sli_issue_mbox (phba,
+						  phba->sysfs_mbox.mbox,
+						  MBX_POLL);
+			spin_lock_irqsave(phba->host->host_lock, iflag);
+		} else {
+			spin_unlock_irqrestore(phba->host->host_lock, iflag);
+			rc = lpfc_sli_issue_mbox_wait (phba,
+						       phba->sysfs_mbox.mbox,
+						       phba->fc_ratov * 2);
+			spin_lock_irqsave(phba->host->host_lock, iflag);
+		}
+
+		if (rc != MBX_SUCCESS) {
+			sysfs_mbox_idle(phba);
+			spin_unlock_irqrestore(host->host_lock, iflag);
+			return -ENODEV;
+		}
+		phba->sysfs_mbox.state = SMBOX_READING;
+	}
+	else if (phba->sysfs_mbox.offset != off ||
+		 phba->sysfs_mbox.state  != SMBOX_READING) {
+		printk(KERN_WARNING  "mbox_read: Bad State\n");
+		sysfs_mbox_idle(phba);
+		spin_unlock_irqrestore(host->host_lock, iflag);
+		return -EINVAL;
+	}
+
+	memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
+
+	phba->sysfs_mbox.offset = off + count;
+
+	if (phba->sysfs_mbox.offset == sizeof(MAILBOX_t))
+		sysfs_mbox_idle(phba);
+
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+
+	return count;
+}
+
+static struct bin_attribute sysfs_mbox_attr = {
+	.attr = {
+		.name = "mbox",
+		.mode = S_IRUSR | S_IWUSR,
+		.owner = THIS_MODULE,
+	},
+	.size = sizeof(MAILBOX_t),
+	.read = sysfs_mbox_read,
+	.write = sysfs_mbox_write,
+};
+
+
+#ifdef  RHEL_FC
+/*
+ * The LPFC driver treats linkdown handling as target loss events so there
+ * are no sysfs handlers for link_down_tmo.
+ */
+static void
+lpfc_get_starget_port_id(struct scsi_target *starget)
+{
+	struct lpfc_nodelist *ndlp = NULL;
+	struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
+	struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata[0];
+	uint16_t did = 0;
+
+	spin_lock_irq(shost->host_lock);
+	/* Search the mapped list for this target ID */
+	list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
+		if (starget->id == ndlp->nlp_sid) {
+			did = ndlp->nlp_DID;
+			break;
+		}
+	}
+	spin_unlock_irq(shost->host_lock);
+
+	fc_starget_port_id(starget) = did;
+}
+
+static void
+lpfc_get_starget_node_name(struct scsi_target *starget)
+{
+	struct lpfc_nodelist *ndlp = NULL;
+	struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
+	struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata[0];
+	uint64_t node_name = 0;
+
+	spin_lock_irq(shost->host_lock);
+	/* Search the mapped list for this target ID */
+	list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
+		if (starget->id == ndlp->nlp_sid) {
+			memcpy(&node_name, &ndlp->nlp_nodename,
+						sizeof(struct lpfc_name));
+			break;
+		}
+	}
+	spin_unlock_irq(shost->host_lock);
+
+	fc_starget_node_name(starget) = be64_to_cpu(node_name);
+}
+
+static void
+lpfc_get_starget_port_name(struct scsi_target *starget)
+{
+	struct lpfc_nodelist *ndlp = NULL;
+	struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
+	struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata[0];
+	uint64_t port_name = 0;
+
+	spin_lock_irq(shost->host_lock);
+	/* Search the mapped list for this target ID */
+	list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
+		if (starget->id == ndlp->nlp_sid) {
+			memcpy(&port_name, &ndlp->nlp_portname,
+						sizeof(struct lpfc_name));
+			break;
+		}
+	}
+	spin_unlock_irq(shost->host_lock);
+
+	fc_starget_port_name(starget) = be64_to_cpu(port_name);
+}
+
+static void
+lpfc_get_starget_loss_tmo(struct scsi_target *starget)
+{
+	/*
+	 * Return the driver's global value for device loss timeout plus
+	 * five seconds to allow the driver's nodev timer to run.
+	 */
+	fc_starget_dev_loss_tmo(starget) = lpfc_nodev_tmo + 5;
+}
+
+static void
+lpfc_set_starget_loss_tmo(struct scsi_target *starget, uint32_t timeout)
+{
+	/*
+	 * The driver doesn't have a per-target timeout setting.  Set
+	 * this value globally. Keep lpfc_nodev_tmo >= 1.
+	 */
+	if (timeout)
+		lpfc_nodev_tmo = timeout;
+	else
+		lpfc_nodev_tmo = 1;
+}
+
+#else /* not RHEL_FC */
+
+static void
+lpfc_get_port_id(struct scsi_device *sdev)
+{
+	struct lpfc_target *target = sdev->hostdata;
+	if (sdev->host->transportt && target->pnode)
+		fc_port_id(sdev) = target->pnode->nlp_DID;
+}
+
+static void
+lpfc_get_node_name(struct scsi_device *sdev)
+{
+	struct lpfc_target *target = sdev->hostdata;
+	uint64_t node_name = 0;
+	if (sdev->host->transportt && target->pnode)
+		memcpy(&node_name, &target->pnode->nlp_nodename,
+						sizeof(struct lpfc_name));
+	fc_node_name(sdev) = be64_to_cpu(node_name);
+}
+
+static void
+lpfc_get_port_name(struct scsi_device *sdev)
+{
+	struct lpfc_target *target = sdev->hostdata;
+	uint64_t port_name = 0;
+	if (sdev->host->transportt && target->pnode)
+		memcpy(&port_name, &target->pnode->nlp_portname,
+						sizeof(struct lpfc_name));
+	fc_port_name(sdev) = be64_to_cpu(port_name);
+}
+#endif /* not RHEL_FC */
+
+static struct fc_function_template lpfc_transport_functions = {
+#ifdef RHEL_FC
+	.get_starget_port_id  = lpfc_get_starget_port_id,
+	.show_starget_port_id = 1,
+
+	.get_starget_node_name = lpfc_get_starget_node_name,
+	.show_starget_node_name = 1,
+
+	.get_starget_port_name = lpfc_get_starget_port_name,
+	.show_starget_port_name = 1,
+
+	.get_starget_dev_loss_tmo = lpfc_get_starget_loss_tmo,
+	.set_starget_dev_loss_tmo = lpfc_set_starget_loss_tmo,
+	.show_starget_dev_loss_tmo = 1,
+
+#else /* not RHEL_FC */
+	.get_port_id  = lpfc_get_port_id,
+	.show_port_id = 1,
+
+	.get_node_name = lpfc_get_node_name,
+	.show_node_name = 1,
+
+	.get_port_name = lpfc_get_port_name,
+	.show_port_name = 1,
+#endif /* not RHEL_FC */
+};
+
+static int
+lpfc_proc_info(struct Scsi_Host *host,
+	       char *buf, char **start, off_t offset, int count, int rw)
+{
+	struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata[0];
+	struct lpfc_nodelist *ndlp;
+	int len = 0;
+
+	/* Sufficient bytes to hold a port or node name. */
+	uint8_t name[sizeof (struct lpfc_name)];
+
+	/* If rw = 0, then read info
+	 * If rw = 1, then write info (NYI)
+	 */
+	if (rw)
+		return -EINVAL;
+
+	list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
+		if (ndlp->nlp_state == NLP_STE_MAPPED_NODE){
+			len += snprintf(buf + len, PAGE_SIZE -len,
+					"lpfc%dt%02x DID %06x WWPN ",
+					phba->brd_no,
+					ndlp->nlp_sid, ndlp->nlp_DID);
+
+			memcpy (&name[0], &ndlp->nlp_portname,
+				sizeof (struct lpfc_name));
+			len += snprintf(buf + len, PAGE_SIZE-len,
+					"%02x:%02x:%02x:%02x:%02x:%02x:"
+					"%02x:%02x",
+					name[0], name[1], name[2],
+					name[3], name[4], name[5],
+					name[6], name[7]);
+			len += snprintf(buf + len, PAGE_SIZE-len, " WWNN ");
+			memcpy (&name[0], &ndlp->nlp_nodename,
+				sizeof (struct lpfc_name));
+			len += snprintf(buf + len, PAGE_SIZE-len,
+					"%02x:%02x:%02x:%02x:%02x:%02x:"
+					"%02x:%02x\n",
+					name[0], name[1], name[2],
+					name[3], name[4], name[5],
+					name[6], name[7]);
+			}
+		if (PAGE_SIZE - len < 90)
+			break;
+	}
+	if (&ndlp->nlp_listp != &phba->fc_nlpmap_list)
+		len += snprintf(buf+len, PAGE_SIZE-len, "...\n");
+
+	return (len);
+}
+
+static int
+lpfc_slave_alloc(struct scsi_device *scsi_devs)
+{
+	struct lpfc_hba *phba;
+	struct lpfc_target *target;
+
+	/*
+	 * Store the lun pointer in the scsi_device hostdata pointer provided
+	 * the driver has already discovered the target id.
+	 */
+	phba = (struct lpfc_hba *) scsi_devs->host->hostdata[0];
+	target = lpfc_find_target(phba, scsi_devs->id, NULL);
+	if (target) {
+		scsi_devs->hostdata = target;
+		target->slavecnt++;
+		return 0;
+	}
+
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9)
+	return -ENXIO;
+#else
+
+	/*
+	 * The driver does not have a target id matching that in the scsi
+	 * device.  Allocate a dummy target initialized to zero so that
+	 * the driver's queuecommand entry correctly fails the call
+	 * forcing the midlayer to call lpfc_slave_destroy.  This code
+	 * will be removed in a subsequent kernel patch.
+	 */
+
+	target = kmalloc(sizeof (struct lpfc_target), GFP_KERNEL);
+	if (!target)
+		return 1;
+
+	memset(target, 0, sizeof (struct lpfc_target));
+#ifdef SLES_FC
+	init_timer(&target->dev_loss_timer);
+#endif
+	scsi_devs->hostdata = target;
+	target->slavecnt++;
+	return 0;
+#endif
+}
+
+static int
+lpfc_slave_configure(struct scsi_device *sdev)
+{
+	struct lpfc_hba *phba = (struct lpfc_hba *) sdev->host->hostdata[0];
+
+#if defined(RHEL_FC)
+	struct lpfc_target *target = (struct lpfc_target *) sdev->hostdata;
+#endif
+
+	if (sdev->tagged_supported)
+		scsi_activate_tcq(sdev, phba->cfg_lun_queue_depth);
+	else
+		scsi_deactivate_tcq(sdev, phba->cfg_lun_queue_depth);
+
+#ifdef RHEL_FC
+	if ((target) && (sdev->sdev_target)) {
+		/*
+		 * Initialize the fc transport attributes for the target
+		 * containing this scsi device.  Also note that the driver's
+		 * target pointer is stored in the starget_data for the
+		 * driver's sysfs entry point functions.
+		 */
+		target->starget = sdev->sdev_target;
+		fc_starget_dev_loss_tmo(target->starget) = lpfc_nodev_tmo + 5;
+	}
+#endif /* RHEL_FC */
+
+	return 0;
+}
+
+static void
+lpfc_slave_destroy(struct scsi_device *sdev)
+{
+	struct lpfc_hba *phba;
+	struct lpfc_target *target;
+	int i;
+
+	phba = (struct lpfc_hba *) sdev->host->hostdata[0];
+	target = sdev->hostdata;
+	if (target) {
+		target->slavecnt--;
+
+		/* Double check for valid lpfc_target */
+		for (i = 0; i < MAX_FCP_TARGET; i++) {
+			if(target == phba->device_queue_hash[i]) {
+				if ((!target->slavecnt) && !(target->pnode)) {
+					kfree(target);
+					phba->device_queue_hash[i] = NULL;
+				}
+				sdev->hostdata = NULL;
+				return;
+			}
+		}
+		/* If we get here, this was a dummy lpfc_target allocated
+		 * in lpfc_slave_alloc.
+		 */
+		if (!target->slavecnt)
+			kfree(target);
+	}
+
+	/*
+	 * Set this scsi device's hostdata to NULL since it is going
+	 * away.  Also, (future) don't set the starget_dev_loss_tmo
+	 * this value is global to all targets managed by this
+	 * host.
+	 */
+	sdev->hostdata = NULL;
+	return;
+}
+
+static struct class_device_attribute *lpfc_host_attrs[] = {
+	&class_device_attr_info,
+	&class_device_attr_serialnum,
+	&class_device_attr_modeldesc,
+	&class_device_attr_modelname,
+	&class_device_attr_programtype,
+	&class_device_attr_portnum,
+	&class_device_attr_fwrev,
+	&class_device_attr_hdw,
+	&class_device_attr_option_rom_version,
+	&class_device_attr_state,
+	&class_device_attr_num_discovered_ports,
+	&class_device_attr_speed,
+	&class_device_attr_node_name,
+	&class_device_attr_port_name,
+	&class_device_attr_portfcid,
+	&class_device_attr_port_type,
+	&class_device_attr_fabric_name,
+	&class_device_attr_events,
+	&class_device_attr_lpfc_drvr_version,
+	&class_device_attr_lpfc_log_verbose,
+	&class_device_attr_lpfc_lun_queue_depth,
+	&class_device_attr_lpfc_nodev_tmo,
+	&class_device_attr_lpfc_fcp_class,
+	&class_device_attr_lpfc_use_adisc,
+	&class_device_attr_lpfc_ack0,
+	&class_device_attr_lpfc_topology,
+	&class_device_attr_lpfc_scan_down,
+	&class_device_attr_lpfc_link_speed,
+	&class_device_attr_lpfc_fdmi_on,
+	&class_device_attr_lpfc_fcp_bind_method,
+	&class_device_attr_lpfc_max_luns,
+	&class_device_attr_nport_evt_cnt,
+	&class_device_attr_management_version,
+	&class_device_attr_issue_lip,
+	&class_device_attr_board_online,
+	&class_device_attr_disc_npr,
+	&class_device_attr_disc_map,
+	&class_device_attr_disc_unmap,
+	&class_device_attr_disc_prli,
+	&class_device_attr_disc_reglgn,
+	&class_device_attr_disc_adisc,
+	&class_device_attr_disc_plogi,
+	&class_device_attr_disc_unused,
+	&class_device_attr_outfcpio,
+	NULL,
+};
+
+static struct scsi_host_template driver_template = {
+	.module			= THIS_MODULE,
+	.name			= LPFC_DRIVER_NAME,
+	.info			= lpfc_info,
+	.queuecommand		= lpfc_queuecommand,
+	.eh_abort_handler	= lpfc_abort_handler,
+	.eh_device_reset_handler= lpfc_reset_lun_handler,
+	.eh_bus_reset_handler	= lpfc_reset_bus_handler,
+	.slave_alloc		= lpfc_slave_alloc,
+	.slave_configure	= lpfc_slave_configure,
+	.slave_destroy		= lpfc_slave_destroy,
+	.proc_info		= lpfc_proc_info,
+	.proc_name		= LPFC_DRIVER_NAME,
+	.this_id		= -1,
+	.sg_tablesize		= SG_ALL,
+	.cmd_per_lun		= 30,
+	.max_sectors		= 0xFFFF,
+	.shost_attrs		= lpfc_host_attrs,
+	.use_clustering		= ENABLE_CLUSTERING,
+};
+
+static int
+lpfc_sli_setup(struct lpfc_hba * phba)
+{
+	int i, totiocb = 0;
+	struct lpfc_sli *psli = &phba->sli;
+	LPFC_RING_INIT_t *pring;
+
+	psli->sliinit.num_rings = MAX_CONFIGURED_RINGS;
+	psli->fcp_ring = LPFC_FCP_RING;
+	psli->next_ring = LPFC_FCP_NEXT_RING;
+	psli->ip_ring = LPFC_IP_RING;
+
+	for (i = 0; i < psli->sliinit.num_rings; i++) {
+		pring = &psli->sliinit.ringinit[i];
+		switch (i) {
+		case LPFC_FCP_RING:	/* ring 0 - FCP */
+			/* numCiocb and numRiocb are used in config_port */
+			pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
+			pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
+			pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
+			pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
+			pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
+			pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
+			pring->iotag_ctr = 0;
+			pring->iotag_max =
+			    (phba->cfg_hba_queue_depth * 2);
+			pring->fast_iotag = pring->iotag_max;
+			pring->num_mask = 0;
+			break;
+		case LPFC_IP_RING:	/* ring 1 - IP */
+			/* numCiocb and numRiocb are used in config_port */
+			pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
+			pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
+			pring->num_mask = 0;
+			break;
+		case LPFC_ELS_RING:	/* ring 2 - ELS / CT */
+			/* numCiocb and numRiocb are used in config_port */
+			pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
+			pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
+			pring->fast_iotag = 0;
+			pring->iotag_ctr = 0;
+			pring->iotag_max = 4096;
+			pring->num_mask = 4;
+			pring->prt[0].profile = 0;	/* Mask 0 */
+			pring->prt[0].rctl = FC_ELS_REQ;
+			pring->prt[0].type = FC_ELS_DATA;
+			pring->prt[0].lpfc_sli_rcv_unsol_event =
+			    lpfc_els_unsol_event;
+			pring->prt[1].profile = 0;	/* Mask 1 */
+			pring->prt[1].rctl = FC_ELS_RSP;
+			pring->prt[1].type = FC_ELS_DATA;
+			pring->prt[1].lpfc_sli_rcv_unsol_event =
+			    lpfc_els_unsol_event;
+			pring->prt[2].profile = 0;	/* Mask 2 */
+			/* NameServer Inquiry */
+			pring->prt[2].rctl = FC_UNSOL_CTL;
+			/* NameServer */
+			pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
+			pring->prt[2].lpfc_sli_rcv_unsol_event =
+			    lpfc_ct_unsol_event;
+			pring->prt[3].profile = 0;	/* Mask 3 */
+			/* NameServer response */
+			pring->prt[3].rctl = FC_SOL_CTL;
+			/* NameServer */
+			pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
+			pring->prt[3].lpfc_sli_rcv_unsol_event =
+			    lpfc_ct_unsol_event;
+			break;
+		}
+		totiocb += (pring->numCiocb + pring->numRiocb);
+	}
+	if (totiocb > MAX_SLI2_IOCB) {
+		/* Too many cmd / rsp ring entries in SLI2 SLIM */
+		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
+				"%d:0462 Too many cmd / rsp ring entries in "
+				"SLI2 SLIM Data: x%x x%x\n",
+				phba->brd_no, totiocb, MAX_SLI2_IOCB);
+	}
+
+#ifdef USE_HGP_HOST_SLIM
+	psli->sliinit.sli_flag = LPFC_HGP_HOSTSLIM;
+#else
+	psli->sliinit.sli_flag = 0;
+#endif
+
+	return (0);
+}
+
+static int
+lpfc_set_bind_type(struct lpfc_hba * phba)
+{
+	int bind_type = phba->cfg_fcp_bind_method;
+	int ret = LPFC_BIND_WW_NN_PN;
+
+	switch (bind_type) {
+	case 1:
+		phba->fcp_mapping = FCP_SEED_WWNN;
+		break;
+
+	case 2:
+		phba->fcp_mapping = FCP_SEED_WWPN;
+		break;
+
+	case 3:
+		phba->fcp_mapping = FCP_SEED_DID;
+		ret = LPFC_BIND_DID;
+		break;
+
+	case 4:
+		phba->fcp_mapping = FCP_SEED_DID;
+		ret = LPFC_BIND_DID;
+		break;
+	}
+
+	return (ret);
+}
+
+static void
+lpfc_get_cfgparam(struct lpfc_hba *phba)
+{
+	lpfc_log_verbose_set(phba, lpfc_log_verbose);
+	lpfc_fcp_bind_method_set(phba, lpfc_fcp_bind_method);
+	lpfc_cr_delay_set(phba, lpfc_cr_delay);
+	lpfc_cr_count_set(phba, lpfc_cr_count);
+	lpfc_lun_queue_depth_set(phba, lpfc_lun_queue_depth);
+	lpfc_fcp_class_set(phba, lpfc_fcp_class);
+	lpfc_use_adisc_set(phba, lpfc_use_adisc);
+	lpfc_ack0_set(phba, lpfc_ack0);
+	lpfc_topology_set(phba, lpfc_topology);
+	lpfc_scan_down_set(phba, lpfc_scan_down);
+	lpfc_nodev_tmo_set(phba, lpfc_nodev_tmo);
+	lpfc_link_speed_set(phba, lpfc_link_speed);
+	lpfc_fdmi_on_set(phba, lpfc_fdmi_on);
+	lpfc_discovery_threads_set(phba, lpfc_discovery_threads);
+	lpfc_max_luns_set(phba, lpfc_max_luns);
+	phba->cfg_scsi_hotplug = 0;
+
+	switch (phba->pcidev->device) {
+	case PCI_DEVICE_ID_LP101:
+	case PCI_DEVICE_ID_BSMB:
+	case PCI_DEVICE_ID_ZSMB:
+		phba->cfg_hba_queue_depth = LPFC_LP101_HBA_Q_DEPTH;
+		break;
+	case PCI_DEVICE_ID_RFLY:
+	case PCI_DEVICE_ID_PFLY:
+	case PCI_DEVICE_ID_BMID:
+	case PCI_DEVICE_ID_ZMID:
+	case PCI_DEVICE_ID_TFLY:
+		phba->cfg_hba_queue_depth = LPFC_LC_HBA_Q_DEPTH;
+		break;
+	default:
+		phba->cfg_hba_queue_depth = LPFC_DFT_HBA_Q_DEPTH;
+	}
+	return;
+}
+
+static void
+lpfc_consistent_bind_setup(struct lpfc_hba * phba)
+{
+	INIT_LIST_HEAD(&phba->fc_nlpbind_list);
+	phba->fc_bind_cnt = 0;
+}
+
+static uint8_t
+lpfc_get_brd_no(struct lpfc_hba * phba)
+{
+	uint8_t    brd, found = 1;
+
+ 	brd = 0;
+	while(found) {
+		phba = NULL;
+		found = 0;
+		list_for_each_entry(phba, &lpfc_hba_list, hba_list) {
+			if (phba->brd_no == brd) {
+				found = 1;
+				brd++;
+				break;
+			}
+		}
+	}
+	return (brd);
+}
+
+
+static int __devinit
+lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
+{
+	struct Scsi_Host *host;
+	struct lpfc_hba  *phba;
+	struct lpfc_sli  *psli;
+	unsigned long iflag;
+	unsigned long bar0map_len, bar2map_len;
+	int error = -ENODEV, retval;
+
+	if (pci_enable_device(pdev))
+		goto out;
+	if (pci_request_regions(pdev, LPFC_DRIVER_NAME))
+		goto out_disable_device;
+
+	/*
+	 * Allocate space for adapter info structure
+	 */
+	phba = kmalloc(sizeof(*phba), GFP_KERNEL);
+	if (!phba)
+		goto out_release_regions;
+	memset(phba, 0, sizeof (struct lpfc_hba));
+
+	host = scsi_host_alloc(&driver_template, sizeof (unsigned long));
+	if (!host) {
+		printk (KERN_WARNING "%s: scsi_host_alloc failed.\n",
+							 lpfc_drvr_name);
+		error = -ENOMEM;
+		goto out_kfree_phba;
+	}
+
+	phba->fc_flag |= FC_LOADING;
+	phba->pcidev = pdev;
+	phba->host = host;
+
+	INIT_LIST_HEAD(&phba->ctrspbuflist);
+	INIT_LIST_HEAD(&phba->rnidrspbuflist);
+	INIT_LIST_HEAD(&phba->freebufList);
+
+	/* Initialize timers used by driver */
+	init_timer(&phba->fc_estabtmo);
+	phba->fc_estabtmo.function = lpfc_establish_link_tmo;
+	phba->fc_estabtmo.data = (unsigned long)phba;
+	init_timer(&phba->fc_disctmo);
+	phba->fc_disctmo.function = lpfc_disc_timeout;
+	phba->fc_disctmo.data = (unsigned long)phba;
+	init_timer(&phba->fc_scantmo);
+	phba->fc_scantmo.function = lpfc_scan_timeout;
+	phba->fc_scantmo.data = (unsigned long)phba;
+
+	init_timer(&phba->fc_fdmitmo);
+	phba->fc_fdmitmo.function = lpfc_fdmi_tmo;
+	phba->fc_fdmitmo.data = (unsigned long)phba;
+	init_timer(&phba->els_tmofunc);
+	phba->els_tmofunc.function = lpfc_els_timeout;
+	phba->els_tmofunc.data = (unsigned long)phba;
+	psli = &phba->sli;
+	init_timer(&psli->mbox_tmo);
+	psli->mbox_tmo.function = lpfc_mbox_timeout;
+	psli->mbox_tmo.data = (unsigned long)phba;
+
+	/* Assign an unused board number */
+ 	phba->brd_no = lpfc_get_brd_no(phba);
+	host->unique_id = phba->brd_no;
+
+	/*
+	 * Get all the module params for configuring this host and then
+	 * establish the host parameters.
+	 */
+	lpfc_get_cfgparam(phba);
+
+	host->max_id = LPFC_MAX_TARGET;
+	host->max_lun = phba->cfg_max_luns;
+	host->this_id = -1;
+
+	if(phba->cfg_scsi_hotplug) {
+		lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
+			"%d:0264 HotPlug Support Enabled\n",
+			phba->brd_no);
+	}
+
+	/* Add adapter structure to list */
+	list_add_tail(&phba->hba_list, &lpfc_hba_list);
+
+	/* Initialize all internally managed lists. */
+	INIT_LIST_HEAD(&phba->fc_nlpmap_list);
+	INIT_LIST_HEAD(&phba->fc_nlpunmap_list);
+	INIT_LIST_HEAD(&phba->fc_unused_list);
+	INIT_LIST_HEAD(&phba->fc_plogi_list);
+	INIT_LIST_HEAD(&phba->fc_adisc_list);
+	INIT_LIST_HEAD(&phba->fc_reglogin_list);
+	INIT_LIST_HEAD(&phba->fc_prli_list);
+	INIT_LIST_HEAD(&phba->fc_npr_list);
+	lpfc_consistent_bind_setup(phba);
+
+	init_waitqueue_head(&phba->linkevtwq);
+	init_waitqueue_head(&phba->rscnevtwq);
+	init_waitqueue_head(&phba->ctevtwq);
+
+	pci_set_master(pdev);
+	retval = pci_set_mwi(pdev);
+	if (retval)
+		dev_printk(KERN_WARNING, &pdev->dev,
+			   "Warning: pci_set_mwi returned %d\n", retval);
+
+	/* Configure DMA attributes. */
+	if (dma_set_mask(&phba->pcidev->dev, 0xffffffffffffffffULL) &&
+	    dma_set_mask(&phba->pcidev->dev, 0xffffffffULL))
+		goto out_list_del;
+
+	/*
+	 * Get the physical address of Bar0 and Bar2 and the number of bytes
+	 * required by each mapping.
+	 */
+	phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
+	bar0map_len        = pci_resource_len(phba->pcidev, 0);
+
+	phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
+	bar2map_len        = pci_resource_len(phba->pcidev, 2);
+
+	/* Map HBA SLIM and Control Registers to a kernel virtual address. */
+	phba->slim_memmap_p      = ioremap(phba->pci_bar0_map, bar0map_len);
+	phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
+
+	/*
+	 * Allocate memory for SLI-2 structures
+	 */
+	phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE,
+					  &phba->slim2p_mapping, GFP_KERNEL);
+	if (!phba->slim2p)
+		goto out_iounmap;
+
+
+	lpfc_sli_setup(phba);	/* Setup SLI Layer to run over lpfc HBAs */
+	lpfc_sli_queue_setup(phba);	/* Initialize the SLI Layer */
+
+	error = lpfc_mem_alloc(phba);
+	if (error)
+		goto out_dec_nhbas;
+
+	lpfc_set_bind_type(phba);
+
+	/* Initialize HBA structure */
+	phba->fc_edtov = FF_DEF_EDTOV;
+	phba->fc_ratov = FF_DEF_RATOV;
+	phba->fc_altov = FF_DEF_ALTOV;
+	phba->fc_arbtov = FF_DEF_ARBTOV;
+
+	INIT_LIST_HEAD(&phba->dpc_disc);
+	init_completion(&phba->dpc_startup);
+	init_completion(&phba->dpc_exiting);
+
+	/*
+	* Startup the kernel thread for this host adapter
+	*/
+	phba->dpc_kill = 0;
+	phba->dpc_pid = kernel_thread(lpfc_do_dpc, phba, 0);
+	if (phba->dpc_pid < 0) {
+		error = phba->dpc_pid;
+		goto out_free_mem;
+	}
+	wait_for_completion(&phba->dpc_startup);
+
+	/* Call SLI to initialize the HBA. */
+	error = lpfc_sli_hba_setup(phba);
+	if (error)
+		goto out_hba_down;
+
+	/* We can rely on a queue depth attribute only after SLI HBA setup */
+	host->can_queue = phba->cfg_hba_queue_depth - 10;
+
+	/*
+	 * Starting with 2.4.0 kernel, Linux can support commands longer
+	 * than 12 bytes. However, scsi_register() always sets it to 12.
+	 * For it to be useful to the midlayer, we have to set it here.
+	 */
+	host->max_cmd_len = 16;
+
+	/*
+	 * Queue depths per lun
+	 */
+	host->transportt = lpfc_transport_template;
+	host->hostdata[0] = (unsigned long)phba;
+	pci_set_drvdata(pdev, host);
+	error = scsi_add_host(host, &pdev->dev);
+	if (error)
+		goto out_hba_down;
+
+	sysfs_create_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
+	sysfs_create_bin_file(&host->shost_classdev.kobj, &sysfs_mbox_attr);
+	scsi_scan_host(host);
+	phba->fc_flag &= ~FC_LOADING;
+	return 0;
+
+out_hba_down:
+	/* Stop any timers that were started during this attach. */
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+	lpfc_sli_hba_down(phba);
+	lpfc_stop_timer(phba);
+	phba->work_hba_events = 0;
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+
+	/* Kill the kernel thread for this host */
+	if (phba->dpc_pid >= 0) {
+		phba->dpc_kill = 1;
+		wmb();
+		kill_proc(phba->dpc_pid, SIGHUP, 1);
+		wait_for_completion(&phba->dpc_exiting);
+	}
+
+out_free_mem:
+	lpfc_mem_free(phba);
+out_dec_nhbas:
+	dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
+			  phba->slim2p, phba->slim2p_mapping);
+out_iounmap:
+	iounmap(phba->ctrl_regs_memmap_p);
+	iounmap(phba->slim_memmap_p);
+out_list_del:
+	list_del_init(&phba->hba_list);
+	scsi_host_put(host);
+out_kfree_phba:
+	kfree(phba);
+out_release_regions:
+	pci_release_regions(pdev);
+out_disable_device:
+	pci_disable_device(pdev);
+out:
+	return error;
+}
+
+static void __devexit
+lpfc_pci_remove_one(struct pci_dev *pdev)
+{
+	struct Scsi_Host   *host = pci_get_drvdata(pdev);
+	struct lpfc_hba    *phba = (struct lpfc_hba *)host->hostdata[0];
+	struct lpfc_target *targetp;
+	int i;
+	unsigned long iflag;
+
+	sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_mbox_attr);
+	sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
+
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+
+	/* Since we are going to scsi_remove_host(), disassociate scsi_dev
+	 * from lpfc_target, and make sure its unblocked.
+	 */
+	for (i = 0; i < MAX_FCP_TARGET; i++) {
+		targetp = phba->device_queue_hash[i];
+		if (!targetp)
+			continue;
+#if defined(RHEL_FC) || defined(SLES_FC)
+		if(targetp->pnode) {
+			if(targetp->blocked) {
+				/* If we are blocked, force a nodev_tmo */
+				del_timer_sync(&targetp->pnode->nlp_tmofunc);
+				if (!list_empty(&targetp->pnode->
+						nodev_timeout_evt.evt_listp))
+					list_del_init(&targetp->pnode->
+						      nodev_timeout_evt.
+						      evt_listp);
+				lpfc_process_nodev_timeout(phba,
+					targetp->pnode);
+			}
+			else {
+				/* If we are unblocked, just remove
+				 * the scsi device.
+				 */
+				lpfc_target_remove(phba, targetp);
+			}
+		}
+#endif /* RHEL_FC or SLES_FC */
+#if defined(RHEL_FC)
+		targetp->starget = NULL;
+#endif /* RHEL_FC */
+	}
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+
+	list_del(&phba->hba_list);
+	scsi_remove_host(phba->host);
+
+	/* detach the board */
+
+	/* Kill the kernel thread for this host */
+	if (phba->dpc_pid >= 0) {
+		phba->dpc_kill = 1;
+		wmb();
+		kill_proc(phba->dpc_pid, SIGHUP, 1);
+		wait_for_completion(&phba->dpc_exiting);
+	}
+
+	/*
+	 * Bring down the SLI Layer. This step disable all interrupts,
+	 * clears the rings, discards all mailbox commands, and resets
+	 * the HBA.
+	 */
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+	lpfc_sli_hba_down(phba);
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+
+	/* Release the irq reservation */
+	free_irq(phba->pcidev->irq, phba);
+
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+	lpfc_cleanup(phba, 0);
+	lpfc_stop_timer(phba);
+	phba->work_hba_events = 0;
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+	lpfc_scsi_free(phba);
+
+	lpfc_mem_free(phba);
+
+	/* Free resources associated with SLI2 interface */
+	dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
+			  phba->slim2p, phba->slim2p_mapping);
+
+	/* unmap adapter SLIM and Control Registers */
+	iounmap(phba->ctrl_regs_memmap_p);
+	iounmap(phba->slim_memmap_p);
+
+	pci_release_regions(phba->pcidev);
+	pci_disable_device(phba->pcidev);
+
+	scsi_host_put(phba->host);
+	kfree(phba);
+
+	pci_set_drvdata(pdev, NULL);
+}
+
+static struct pci_device_id lpfc_id_table[] = {
+	{PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
+		PCI_ANY_ID, PCI_ANY_ID, },
+	{PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
+		PCI_ANY_ID, PCI_ANY_ID, },
+	{PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
+		PCI_ANY_ID, PCI_ANY_ID, },
+	{PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
+		PCI_ANY_ID, PCI_ANY_ID, },
+	{PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
+		PCI_ANY_ID, PCI_ANY_ID, },
+	{PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
+		PCI_ANY_ID, PCI_ANY_ID, },
+	{PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
+		PCI_ANY_ID, PCI_ANY_ID, },
+	{PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
+		PCI_ANY_ID, PCI_ANY_ID, },
+	{PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
+		PCI_ANY_ID, PCI_ANY_ID, },
+	{PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
+		PCI_ANY_ID, PCI_ANY_ID, },
+	{PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
+		PCI_ANY_ID, PCI_ANY_ID, },
+	{PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
+		PCI_ANY_ID, PCI_ANY_ID, },
+	{PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
+		PCI_ANY_ID, PCI_ANY_ID, },
+	{PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
+		PCI_ANY_ID, PCI_ANY_ID, },
+	{PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
+		PCI_ANY_ID, PCI_ANY_ID, },
+	{PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
+		PCI_ANY_ID, PCI_ANY_ID, },
+	{PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
+		PCI_ANY_ID, PCI_ANY_ID, },
+	{ 0 }
+};
+MODULE_DEVICE_TABLE(pci, lpfc_id_table);
+
+
+static struct pci_driver lpfc_driver = {
+	.name		= LPFC_DRIVER_NAME,
+	.id_table	= lpfc_id_table,
+	.probe		= lpfc_pci_probe_one,
+	.remove		= __devexit_p(lpfc_pci_remove_one),
+};
+
+static int __init
+lpfc_init(void)
+{
+	int rc;
+
+	printk(LPFC_MODULE_DESC "\n");
+	printk(LPFC_COPYRIGHT "\n");
+
+	lpfc_transport_template =
+		fc_attach_transport(&lpfc_transport_functions);
+	if (!lpfc_transport_template)
+		return -ENODEV;
+	rc = pci_module_init(&lpfc_driver);
+	return rc;
+
+}
+
+static void __exit
+lpfc_exit(void)
+{
+	pci_unregister_driver(&lpfc_driver);
+	fc_release_transport(lpfc_transport_template);
+}
+module_init(lpfc_init);
+module_exit(lpfc_exit);
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION(LPFC_MODULE_DESC);
+MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
+MODULE_VERSION("0:" LPFC_DRIVER_VERSION);
--- linux-2.6.8.1-t044-driver-update//drivers/scsi/lpfc/lpfc_version.h	1970-01-01 03:00:00.000000000 +0300
+++ rhel4u2//drivers/scsi/lpfc/lpfc_version.h	2005-10-19 11:47:17.000000000 +0400
@@ -0,0 +1,38 @@
+/*******************************************************************
+ * This file is part of the Emulex Linux Device Driver for         *
+ * Fibre Channel Host Bus Adapters.                                *
+ * Copyright (C) 2003-2005 Emulex.  All rights reserved.           *
+ * EMULEX and SLI are trademarks of Emulex.                        *
+ * www.emulex.com                                                  *
+ *                                                                 *
+ * This program is free software; you can redistribute it and/or   *
+ * modify it under the terms of version 2 of the GNU General       *
+ * Public License as published by the Free Software Foundation.    *
+ * This program is distributed in the hope that it will be useful. *
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
+ * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
+ * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
+ * more details, a copy of which can be found in the file COPYING  *
+ * included with this package.                                     *
+ *******************************************************************/
+
+/*
+ * $Id: lpfc_version.h 1.58.1.8 2005/07/27 18:29:31EDT sf_support Exp  $
+ */
+
+#ifndef _H_LPFC_VERSION
+#define _H_LPFC_VERSION
+
+#define LPFC_DRIVER_VERSION "8.0.16.17"
+
+#define LPFC_DRIVER_NAME "lpfc"
+
+#define LPFC_MODULE_DESC "Emulex LightPulse Fibre Channel SCSI driver " \
+		LPFC_DRIVER_VERSION
+#define LPFC_COPYRIGHT "Copyright(c) 2003-2005 Emulex.  All rights reserved."
+
+#define DFC_API_VERSION "0.0.0"
+
+#endif
--- linux-2.6.8.1-t044-driver-update//drivers/scsi/lpfc/lpfc_mem.h	1970-01-01 03:00:00.000000000 +0300
+++ rhel4u2//drivers/scsi/lpfc/lpfc_mem.h	2005-10-19 11:47:17.000000000 +0400
@@ -0,0 +1,56 @@
+/*******************************************************************
+ * This file is part of the Emulex Linux Device Driver for         *
+ * Fibre Channel Host Bus Adapters.                                *
+ * Copyright (C) 2003-2005 Emulex.  All rights reserved.           *
+ * EMULEX and SLI are trademarks of Emulex.                        *
+ * www.emulex.com                                                  *
+ *                                                                 *
+ * This program is free software; you can redistribute it and/or   *
+ * modify it under the terms of version 2 of the GNU General       *
+ * Public License as published by the Free Software Foundation.    *
+ * This program is distributed in the hope that it will be useful. *
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
+ * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
+ * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
+ * more details, a copy of which can be found in the file COPYING  *
+ * included with this package.                                     *
+ *******************************************************************/
+
+/*
+ * $Id: lpfc_mem.h 1.23.1.2 2005/06/13 17:16:36EDT sf_support Exp  $
+ */
+
+#ifndef _H_LPFC_MEM
+#define _H_LPFC_MEM
+
+
+struct lpfc_dmabuf {
+	struct list_head list;
+	void *virt;		/* virtual address ptr */
+	dma_addr_t phys;	/* mapped address */
+};
+struct lpfc_dmabufext {
+	struct lpfc_dmabuf dma;
+	uint32_t size;
+	uint32_t flag;
+	struct list_head list;
+	uint32_t uniqueid;
+	uint32_t data;
+};
+typedef struct lpfc_dmabufext DMABUFEXT_t;
+
+struct lpfc_dma_pool {
+	struct lpfc_dmabuf   *elements;
+	uint32_t    max_count;
+	uint32_t    current_count;
+};
+
+
+#define MEM_PRI             0x100	/* Priority bit: set to exceed low
+					   water */
+#define LPFC_MBUF_POOL_SIZE     64      /* max elements in MBUF safety pool */
+#define LPFC_MEM_POOL_SIZE      64      /* max elements in non DMA safety
+					   pool */
+#endif				/* _H_LPFC_MEM */
--- linux-2.6.8.1-t044-driver-update//drivers/scsi/lpfc/lpfc_init.c	1970-01-01 03:00:00.000000000 +0300
+++ rhel4u2//drivers/scsi/lpfc/lpfc_init.c	2005-10-19 11:47:17.000000000 +0400
@@ -0,0 +1,1536 @@
+/*******************************************************************
+ * This file is part of the Emulex Linux Device Driver for         *
+ * Fibre Channel Host Bus Adapters.                                *
+ * Copyright (C) 2003-2005 Emulex.  All rights reserved.           *
+ * EMULEX and SLI are trademarks of Emulex.                        *
+ * www.emulex.com                                                  *
+ *                                                                 *
+ * This program is free software; you can redistribute it and/or   *
+ * modify it under the terms of version 2 of the GNU General       *
+ * Public License as published by the Free Software Foundation.    *
+ * This program is distributed in the hope that it will be useful. *
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
+ * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
+ * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
+ * more details, a copy of which can be found in the file COPYING  *
+ * included with this package.                                     *
+ *******************************************************************/
+
+/*
+ * $Id: lpfc_init.c 1.183.1.2 2005/06/13 17:16:27EDT sf_support Exp  $
+ */
+
+#include <linux/version.h>
+#include <linux/blkdev.h>
+#include <linux/ctype.h>
+#include <linux/dma-mapping.h>
+#include <linux/pci.h>
+#include <linux/spinlock.h>
+
+#include <scsi/scsi_device.h>
+#include <scsi/scsi_host.h>
+
+#include "lpfc_sli.h"
+#include "lpfc_disc.h"
+#include "lpfc_scsi.h"
+#include "lpfc.h"
+#include "lpfc_crtn.h"
+#include "lpfc_hw.h"
+#include "lpfc_logmsg.h"
+#include "lpfc_mem.h"
+#include "lpfc_version.h"
+#include "lpfc_compat.h"
+
+static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *);
+static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
+static int lpfc_post_rcv_buf(struct lpfc_hba *);
+static int lpfc_rdrev_wd30 = 0;
+
+/************************************************************************/
+/*                                                                      */
+/*    lpfc_config_port_prep                                             */
+/*    This routine will do LPFC initialization prior to the             */
+/*    CONFIG_PORT mailbox command. This will be initialized             */
+/*    as a SLI layer callback routine.                                  */
+/*    This routine returns 0 on success or -ERESTART if it wants        */
+/*    the SLI layer to reset the HBA and try again. Any                 */
+/*    other return value indicates an error.                            */
+/*                                                                      */
+/************************************************************************/
+int
+lpfc_config_port_prep(struct lpfc_hba * phba)
+{
+	lpfc_vpd_t *vp = &phba->vpd;
+	int i = 0;
+	LPFC_MBOXQ_t *pmb;
+	MAILBOX_t *mb;
+	uint32_t *lpfc_vpd_data = 0;
+	uint16_t offset = 0;
+
+	/* Get a Mailbox buffer to setup mailbox commands for HBA
+	   initialization */
+	pmb = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
+	if (!pmb) {
+		phba->hba_state = LPFC_HBA_ERROR;
+		return -ENOMEM;
+	}
+
+	mb = &pmb->mb;
+	phba->hba_state = LPFC_INIT_MBX_CMDS;
+
+	/* special handling for LC HBAs */
+	if (lpfc_is_LC_HBA(phba->pcidev->device)) {
+		char licensed[56] =
+		    "key unlock for use with gnu public licensed code only\0";
+		uint32_t *ptext = (uint32_t *) licensed;
+
+		for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
+			*ptext = cpu_to_be32(*ptext);
+
+		/* Setup and issue mailbox READ NVPARAMS command */
+		lpfc_read_nv(phba, pmb);
+		memset((char*)mb->un.varRDnvp.rsvd3, 0,
+			sizeof (mb->un.varRDnvp.rsvd3));
+		memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
+			 sizeof (licensed));
+
+		if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
+			/* Adapter initialization error, mbxCmd <cmd>
+			   READ_NVPARM, mbxStatus <status> */
+			lpfc_printf_log(phba,
+					KERN_ERR,
+					LOG_MBOX,
+					"%d:0324 Config Port initialization "
+					"error, mbxCmd x%x READ_NVPARM, "
+					"mbxStatus x%x\n",
+					phba->brd_no,
+					mb->mbxCommand, mb->mbxStatus);
+			mempool_free( pmb, phba->mbox_mem_pool);
+			return -ERESTART;
+		}
+		memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
+		       sizeof (mb->un.varRDnvp.nodename));
+	}
+
+	/* Setup and issue mailbox READ REV command */
+	lpfc_read_rev(phba, pmb);
+	if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
+		/* Adapter failed to init, mbxCmd <mbxCmd> READ_REV, mbxStatus
+		   <status> */
+		lpfc_printf_log(phba,
+				KERN_ERR,
+				LOG_INIT,
+				"%d:0439 Adapter failed to init, mbxCmd x%x "
+				"READ_REV, mbxStatus x%x\n",
+				phba->brd_no,
+				mb->mbxCommand, mb->mbxStatus);
+		mempool_free( pmb, phba->mbox_mem_pool);
+		return -ERESTART;
+	}
+
+	/* The HBA's current state is provided by the ProgType and rr fields.
+	 * Read and check the value of these fields before continuing to config
+	 * this port.
+	 */
+	if (mb->un.varRdRev.rr == 0 || mb->un.varRdRev.un.b.ProgType != 2) {
+		/* Old firmware */
+		vp->rev.rBit = 0;
+		/* Adapter failed to init, mbxCmd <cmd> READ_REV detected
+		   outdated firmware */
+		lpfc_printf_log(phba,
+				KERN_ERR,
+				LOG_INIT,
+				"%d:0440 Adapter failed to init, mbxCmd x%x "
+				"READ_REV detected outdated firmware"
+				"Data: x%x\n",
+				phba->brd_no,
+				mb->mbxCommand, 0);
+		mempool_free(pmb, phba->mbox_mem_pool);
+		return -ERESTART;
+	} else {
+		vp->rev.rBit = 1;
+		vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
+		memcpy(vp->rev.sli1FwName,
+			(char*)mb->un.varRdRev.sli1FwName, 16);
+		vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
+		memcpy(vp->rev.sli2FwName,
+			(char *)mb->un.varRdRev.sli2FwName, 16);
+	}
+
+	/* Save information as VPD data */
+	vp->rev.biuRev = mb->un.varRdRev.biuRev;
+	vp->rev.smRev = mb->un.varRdRev.smRev;
+	vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
+	vp->rev.endecRev = mb->un.varRdRev.endecRev;
+	vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
+	vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
+	vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
+	vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
+	vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
+	vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
+	lpfc_rdrev_wd30 = mb->un.varWords[30];
+
+	if (lpfc_is_LC_HBA(phba->pcidev->device))
+		memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
+			sizeof (phba->RandomData));
+
+	/* Get the default values for Model Name and Description */
+	lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
+
+	/* Get adapter VPD information */
+	pmb->context2 = kmalloc(DMP_RSP_SIZE, GFP_ATOMIC);
+	lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_ATOMIC);
+
+	do {
+		lpfc_dump_mem(phba, pmb, offset);
+		if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
+			/* Let it go through even if failed. */
+			/* Adapter failed to init, mbxCmd <cmd> DUMP VPD,
+			   mbxStatus <status> */
+			lpfc_printf_log(phba,
+					KERN_INFO,
+					LOG_INIT,
+					"%d:0441 VPD not present on adapter, mbxCmd "
+					"x%x DUMP VPD, mbxStatus x%x\n",
+					phba->brd_no,
+					mb->mbxCommand, mb->mbxStatus);
+			kfree(lpfc_vpd_data);
+			lpfc_vpd_data = 0;
+			break;
+		}
+
+		lpfc_sli_pcimem_bcopy((uint32_t *)pmb->context2,
+                                      (uint32_t*)((uint8_t*)lpfc_vpd_data + offset),
+                                      mb->un.varDmp.word_cnt);
+
+		offset += mb->un.varDmp.word_cnt;
+	} while (mb->un.varDmp.word_cnt);
+
+	lpfc_parse_vpd(phba, (uint8_t *)lpfc_vpd_data);
+
+	if(pmb->context2)
+		kfree(pmb->context2);
+	if (lpfc_vpd_data)
+		kfree(lpfc_vpd_data);
+
+	pmb->context2 = 0;
+	mempool_free(pmb, phba->mbox_mem_pool);
+	return 0;
+}
+
+/************************************************************************/
+/*                                                                      */
+/*    lpfc_config_port_post                                             */
+/*    This routine will do LPFC initialization after the                */
+/*    CONFIG_PORT mailbox command. This will be initialized             */
+/*    as a SLI layer callback routine.                                  */
+/*    This routine returns 0 on success. Any other return value         */
+/*    indicates an error.                                               */
+/*                                                                      */
+/************************************************************************/
+int
+lpfc_config_port_post(struct lpfc_hba * phba)
+{
+	LPFC_MBOXQ_t *pmb;
+	MAILBOX_t *mb;
+	struct lpfc_dmabuf *mp;
+	struct lpfc_sli *psli = &phba->sli;
+	uint32_t status, timeout;
+	int i, j, flogi_sent;
+	unsigned long isr_cnt, clk_cnt;
+
+
+	/* Get a Mailbox buffer to setup mailbox commands for HBA
+	   initialization */
+	pmb = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
+	if (!pmb) {
+		phba->hba_state = LPFC_HBA_ERROR;
+		return -ENOMEM;
+	}
+	mb = &pmb->mb;
+
+	/* Setup link timers */
+	lpfc_config_link(phba, pmb);
+	if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
+		lpfc_printf_log(phba,
+				KERN_ERR,
+				LOG_INIT,
+				"%d:0447 Adapter failed init, mbxCmd x%x "
+				"CONFIG_LINK mbxStatus x%x\n",
+				phba->brd_no,
+				mb->mbxCommand, mb->mbxStatus);
+		phba->hba_state = LPFC_HBA_ERROR;
+		mempool_free( pmb, phba->mbox_mem_pool);
+		return -EIO;
+	}
+
+	/* Get login parameters for NID.  */
+	lpfc_read_sparam(phba, pmb);
+	if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
+		lpfc_printf_log(phba,
+				KERN_ERR,
+				LOG_INIT,
+				"%d:0448 Adapter failed init, mbxCmd x%x "
+				"READ_SPARM mbxStatus x%x\n",
+				phba->brd_no,
+				mb->mbxCommand, mb->mbxStatus);
+		phba->hba_state = LPFC_HBA_ERROR;
+		mp = (struct lpfc_dmabuf *) pmb->context1;
+		lpfc_mbuf_free(phba, mp->virt, mp->phys);
+		kfree(mp);
+		mempool_free( pmb, phba->mbox_mem_pool);
+		return -EIO;
+	}
+
+	mp = (struct lpfc_dmabuf *) pmb->context1;
+
+	memcpy(&phba->fc_sparam, mp->virt, sizeof (struct serv_parm));
+	lpfc_mbuf_free(phba, mp->virt, mp->phys);
+	kfree(mp);
+	pmb->context1 = NULL;
+
+	memcpy(&phba->fc_nodename, &phba->fc_sparam.nodeName,
+	       sizeof (struct lpfc_name));
+	memcpy(&phba->fc_portname, &phba->fc_sparam.portName,
+	       sizeof (struct lpfc_name));
+	/* If no serial number in VPD data, use low 6 bytes of WWNN */
+	/* This should be consolidated into parse_vpd ? - mr */
+	if (phba->SerialNumber[0] == 0) {
+		uint8_t *outptr;
+
+		outptr = (uint8_t *) & phba->fc_nodename.IEEE[0];
+		for (i = 0; i < 12; i++) {
+			status = *outptr++;
+			j = ((status & 0xf0) >> 4);
+			if (j <= 9)
+				phba->SerialNumber[i] =
+				    (char)((uint8_t) 0x30 + (uint8_t) j);
+			else
+				phba->SerialNumber[i] =
+				    (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
+			i++;
+			j = (status & 0xf);
+			if (j <= 9)
+				phba->SerialNumber[i] =
+				    (char)((uint8_t) 0x30 + (uint8_t) j);
+			else
+				phba->SerialNumber[i] =
+				    (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
+		}
+	}
+
+	/* This should turn on DELAYED ABTS for ELS timeouts */
+	lpfc_set_slim(phba, pmb, 0x052198, 0x1);
+	if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
+		phba->hba_state = LPFC_HBA_ERROR;
+		mempool_free( pmb, phba->mbox_mem_pool);
+		return -EIO;
+	}
+
+
+	lpfc_read_config(phba, pmb);
+	if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
+		lpfc_printf_log(phba,
+				KERN_ERR,
+				LOG_INIT,
+				"%d:0453 Adapter failed to init, mbxCmd x%x "
+				"READ_CONFIG, mbxStatus x%x\n",
+				phba->brd_no,
+				mb->mbxCommand, mb->mbxStatus);
+		phba->hba_state = LPFC_HBA_ERROR;
+		mempool_free( pmb, phba->mbox_mem_pool);
+		return -EIO;
+	}
+
+	/* Reset the DFT_HBA_Q_DEPTH to the max xri  */
+	if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
+		phba->cfg_hba_queue_depth =
+			mb->un.varRdConfig.max_xri + 1;
+
+	phba->lmt = mb->un.varRdConfig.lmt;
+	/* HBA is not 4GB capable, or HBA is not 2GB capable,
+	don't let link speed ask for it */
+	if ((((phba->lmt & LMT_4250_10bit) != LMT_4250_10bit) &&
+		(phba->cfg_link_speed > LINK_SPEED_2G)) ||
+		(((phba->lmt & LMT_2125_10bit) != LMT_2125_10bit) &&
+		(phba->cfg_link_speed > LINK_SPEED_1G))) {
+		/* Reset link speed to auto. 1G/2GB HBA cfg'd for 4G */
+		lpfc_printf_log(phba,
+			KERN_WARNING,
+			LOG_LINK_EVENT,
+			"%d:1302 Invalid speed for this board: "
+			"Reset link speed to auto: x%x\n",
+			phba->brd_no,
+			phba->cfg_link_speed);
+			phba->cfg_link_speed = LINK_SPEED_AUTO;
+	}
+
+	if (!phba->intr_inited) {
+		/* Add our interrupt routine to kernel's interrupt chain &
+		   enable it */
+
+		if (request_irq(phba->pcidev->irq,
+				lpfc_intr_handler,
+				SA_SHIRQ,
+				LPFC_DRIVER_NAME,
+				phba) != 0) {
+			/* Enable interrupt handler failed */
+			lpfc_printf_log(phba,
+					KERN_ERR,
+					LOG_INIT,
+					"%d:0451 Enable interrupt handler "
+					"failed\n",
+					phba->brd_no);
+			phba->hba_state = LPFC_HBA_ERROR;
+			mempool_free(pmb, phba->mbox_mem_pool);
+			return -EIO;
+		}
+		phba->intr_inited =
+			(HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA);
+	}
+
+	phba->hba_state = LPFC_LINK_DOWN;
+
+	/* Only process IOCBs on ring 0 till hba_state is READY */
+	if (psli->ring[psli->ip_ring].cmdringaddr)
+		psli->ring[psli->ip_ring].flag |= LPFC_STOP_IOCB_EVENT;
+	if (psli->ring[psli->fcp_ring].cmdringaddr)
+		psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
+	if (psli->ring[psli->next_ring].cmdringaddr)
+		psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
+
+	/* Post receive buffers for desired rings */
+	lpfc_post_rcv_buf(phba);
+
+	/* Enable appropriate host interrupts */
+	status = readl(phba->HCregaddr);
+	status |= phba->intr_inited;
+	if (psli->sliinit.num_rings > 0)
+		status |= HC_R0INT_ENA;
+	if (psli->sliinit.num_rings > 1)
+		status |= HC_R1INT_ENA;
+	if (psli->sliinit.num_rings > 2)
+		status |= HC_R2INT_ENA;
+	if (psli->sliinit.num_rings > 3)
+		status |= HC_R3INT_ENA;
+
+	writel(status, phba->HCregaddr);
+	readl(phba->HCregaddr); /* flush */
+
+	/* Setup and issue mailbox INITIALIZE LINK command */
+	lpfc_init_link(phba, pmb, phba->cfg_topology,
+		       phba->cfg_link_speed);
+
+	isr_cnt = psli->slistat.sliIntr;
+	clk_cnt = jiffies;
+
+	pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
+	if (lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT) != MBX_SUCCESS) {
+		lpfc_printf_log(phba,
+				KERN_ERR,
+				LOG_INIT,
+				"%d:0454 Adapter failed to init, mbxCmd x%x "
+				"INIT_LINK, mbxStatus x%x\n",
+				phba->brd_no,
+				mb->mbxCommand, mb->mbxStatus);
+
+		/* Clear all interrupt enable conditions */
+		writel(0, phba->HCregaddr);
+		readl(phba->HCregaddr); /* flush */
+		/* Clear all pending interrupts */
+		writel(0xffffffff, phba->HAregaddr);
+		readl(phba->HAregaddr); /* flush */
+
+		free_irq(phba->pcidev->irq, phba);
+		phba->hba_state = LPFC_HBA_ERROR;
+		mempool_free(pmb, phba->mbox_mem_pool);
+		return -EIO;
+	}
+	/* MBOX buffer will be freed in mbox compl */
+
+	/*
+	 * Setup the ring 0 (els)  timeout handler
+	 */
+	timeout = phba->fc_ratov << 1;
+
+	phba->els_tmofunc.expires = jiffies + HZ * timeout;
+	add_timer(&phba->els_tmofunc);
+
+	phba->fc_prevDID = Mask_DID;
+	flogi_sent = 0;
+	i = 0;
+	while ((phba->hba_state != LPFC_HBA_READY) ||
+	       (phba->num_disc_nodes) || (phba->fc_prli_sent) ||
+	       ((phba->fc_map_cnt == 0) && (i<2)) ||
+	       (psli->sliinit.sli_flag & LPFC_SLI_MBOX_ACTIVE)) {
+		/* Check every second for 30 retries. */
+		i++;
+		if (i > 30) {
+			break;
+		}
+		if ((i >= 15) && (phba->hba_state <= LPFC_LINK_DOWN)) {
+			/* The link is down.  Set linkdown timeout */
+			break;
+		}
+
+		/* Delay for 1 second to give discovery time to complete. */
+		for (j = 0; j < 20; j++) {
+			/* On some systems, the driver's attach/detect routines
+			 * are uninterruptible.  Since the driver cannot predict
+			 * when this is true, just manually call the ISR every
+			 * 50 ms to service any interrupts.
+			 */
+			msleep(50);
+			if (isr_cnt == psli->slistat.sliIntr) {
+				lpfc_sli_intr(phba);
+				isr_cnt = psli->slistat.sliIntr;
+			}
+		}
+		isr_cnt = psli->slistat.sliIntr;
+
+		if (clk_cnt == jiffies) {
+			/* REMOVE: IF THIS HAPPENS, SYSTEM CLOCK IS NOT RUNNING.
+			 * WE HAVE TO MANUALLY CALL OUR TIMEOUT ROUTINES.
+			 */
+			clk_cnt = jiffies;
+		}
+	}
+
+	/* Since num_disc_nodes keys off of PLOGI, delay a bit to let
+	 * any potential PRLIs to flush thru the SLI sub-system.
+	 */
+	msleep(50);
+	if (isr_cnt == psli->slistat.sliIntr) {
+		lpfc_sli_intr(phba);
+	}
+
+	return (0);
+}
+
+/************************************************************************/
+/*                                                                      */
+/*    lpfc_hba_down_prep                                                */
+/*    This routine will do LPFC uninitialization before the             */
+/*    HBA is reset when bringing down the SLI Layer. This will be       */
+/*    initialized as a SLI layer callback routine.                      */
+/*    This routine returns 0 on success. Any other return value         */
+/*    indicates an error.                                               */
+/*                                                                      */
+/************************************************************************/
+int
+lpfc_hba_down_prep(struct lpfc_hba * phba)
+{
+	/* Disable interrupts */
+	writel(0, phba->HCregaddr);
+	readl(phba->HCregaddr); /* flush */
+
+	/* Cleanup potential discovery resources */
+	lpfc_els_flush_rscn(phba);
+	lpfc_els_flush_cmd(phba);
+	lpfc_disc_flush_list(phba);
+
+	return (0);
+}
+
+/************************************************************************/
+/*                                                                      */
+/*    lpfc_handle_eratt                                                 */
+/*    This routine will handle processing a Host Attention              */
+/*    Error Status event. This will be initialized                      */
+/*    as a SLI layer callback routine.                                  */
+/*                                                                      */
+/************************************************************************/
+void
+lpfc_handle_eratt(struct lpfc_hba * phba, uint32_t status)
+{
+	struct lpfc_sli *psli;
+	struct lpfc_sli_ring  *pring;
+	struct lpfc_iocbq     *iocb, *next_iocb;
+	IOCB_t          *icmd = NULL, *cmd = NULL;
+	struct lpfc_scsi_buf  *lpfc_cmd;
+	volatile uint32_t status1, status2;
+	void *from_slim;
+	unsigned long iflag;
+
+	psli = &phba->sli;
+	from_slim = ((uint8_t *)phba->MBslimaddr + 0xa8);
+	status1 = readl( from_slim);
+	from_slim =  ((uint8_t *)phba->MBslimaddr + 0xac);
+	status2 = readl( from_slim);
+
+	if (status & HS_FFER6) {
+		/* Re-establishing Link */
+		spin_lock_irqsave(phba->host->host_lock, iflag);
+		lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
+				"%d:1301 Re-establishing Link "
+				"Data: x%x x%x x%x\n",
+				phba->brd_no, status, status1, status2);
+		phba->fc_flag |= FC_ESTABLISH_LINK;
+
+		/*
+		* Firmware stops when it triggled erratt with HS_FFER6.
+		* That could cause the I/Os dropped by the firmware.
+		* Error iocb (I/O) on txcmplq and let the SCSI layer
+		* retry it after re-establishing link.
+		*/
+		pring = &psli->ring[psli->fcp_ring];
+
+		list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
+					 list) {
+			cmd = &iocb->iocb;
+
+			/* Must be a FCP command */
+			if ((cmd->ulpCommand != CMD_FCP_ICMND64_CR) &&
+				(cmd->ulpCommand != CMD_FCP_IWRITE64_CR) &&
+				(cmd->ulpCommand != CMD_FCP_IREAD64_CR)) {
+				continue;
+				}
+
+			/* context1 MUST be a struct lpfc_scsi_buf */
+			lpfc_cmd = (struct lpfc_scsi_buf *)(iocb->context1);
+			if (lpfc_cmd == 0) {
+				continue;
+			}
+
+			/* Clear fast_lookup entry */
+			if (cmd->ulpIoTag &&
+			    (cmd->ulpIoTag <
+			     psli->sliinit.ringinit[pring->ringno].fast_iotag))
+				*(pring->fast_lookup + cmd->ulpIoTag) = NULL;
+			
+			list_del(&iocb->list);
+			pring->txcmplq_cnt--;
+
+			if (iocb->iocb_cmpl) {
+				icmd = &iocb->iocb;
+				icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
+				icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
+				(iocb->iocb_cmpl)(phba, iocb, iocb);
+			} else {
+				mempool_free( iocb, phba->iocb_mem_pool);
+			}
+		}
+
+		/*
+		 * There was a firmware error.  Take the hba offline and then
+		 * attempt to restart it.
+		 */
+		spin_unlock_irqrestore(phba->host->host_lock, iflag);
+		lpfc_offline(phba);
+		if (lpfc_online(phba) == 0) {	/* Initialize the HBA */
+			mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
+			return;
+		}
+	} else {
+		/* The if clause above forces this code path when the status
+		 * failure is a value other than FFER6.  Do not call the offline
+		 *  twice. This is the adapter hardware error path.
+		 */
+		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
+				"%d:0457 Adapter Hardware Error "
+				"Data: x%x x%x x%x\n",
+				phba->brd_no, status, status1, status2);
+
+		lpfc_offline(phba);
+
+		/*
+		 * Restart all traffic to this host.  Since the fc_transport
+		 * block functions (future) were not called in lpfc_offline,
+		 * don't call them here.
+		 */
+		scsi_unblock_requests(phba->host);
+	}
+	return;
+}
+
+/************************************************************************/
+/*                                                                      */
+/*    lpfc_handle_latt                                                  */
+/*    This routine will handle processing a Host Attention              */
+/*    Link Status event. This will be initialized                       */
+/*    as a SLI layer callback routine.                                  */
+/*                                                                      */
+/************************************************************************/
+void
+lpfc_handle_latt(struct lpfc_hba * phba)
+{
+	struct lpfc_sli *psli;
+	LPFC_MBOXQ_t *pmb;
+	volatile uint32_t control;
+	unsigned long iflag;
+
+
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+
+	/* called from host_interrupt, to process LATT */
+	psli = &phba->sli;
+	psli->slistat.linkEvent++;
+
+	/* Get a buffer which will be used for mailbox commands */
+	if ((pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
+						  GFP_ATOMIC))) {
+		if (lpfc_read_la(phba, pmb) == 0) {
+			pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
+			if (lpfc_sli_issue_mbox
+			    (phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
+			    != MBX_NOT_FINISHED) {
+				/* Turn off Link Attention interrupts until
+				   CLEAR_LA done */
+				psli->sliinit.sli_flag &= ~LPFC_PROCESS_LA;
+				control = readl(phba->HCregaddr);
+				control &= ~HC_LAINT_ENA;
+				writel(control, phba->HCregaddr);
+				readl(phba->HCregaddr); /* flush */
+
+				/* Clear Link Attention in HA REG */
+				writel(HA_LATT, phba->HAregaddr);
+				readl(phba->HAregaddr); /* flush */
+				spin_unlock_irqrestore(phba->host->host_lock,
+						       iflag);
+				return;
+			} else {
+				mempool_free(pmb, phba->mbox_mem_pool);
+			}
+		} else {
+			mempool_free(pmb, phba->mbox_mem_pool);
+		}
+	}
+
+	/* Clear Link Attention in HA REG */
+	writel(HA_LATT, phba->HAregaddr);
+	readl(phba->HAregaddr); /* flush */
+	lpfc_linkdown(phba);
+	phba->hba_state = LPFC_HBA_ERROR;
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+	return;
+}
+
+/************************************************************************/
+/*                                                                      */
+/*   lpfc_parse_vpd                                                     */
+/*   This routine will parse the VPD data                               */
+/*                                                                      */
+/************************************************************************/
+static int
+lpfc_parse_vpd(struct lpfc_hba * phba, uint8_t * vpd)
+{
+	uint8_t lenlo, lenhi;
+	uint32_t Length;
+	int i, j;
+	int finished = 0;
+	int index = 0;
+
+	if(!vpd)
+		return 0;
+
+	/* Vital Product */
+	lpfc_printf_log(phba,
+			KERN_INFO,
+			LOG_INIT,
+			"%d:0455 Vital Product Data: x%x x%x x%x x%x\n",
+			phba->brd_no,
+			(uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
+			(uint32_t) vpd[3]);
+	do {
+		switch (vpd[index]) {
+		case 0x82:
+			index += 1;
+			lenlo = vpd[index];
+			index += 1;
+			lenhi = vpd[index];
+			index += 1;
+			i = ((((unsigned short)lenhi) << 8) + lenlo);
+			index += i;
+			break;
+		case 0x90:
+			index += 1;
+			lenlo = vpd[index];
+			index += 1;
+			lenhi = vpd[index];
+			index += 1;
+			Length = ((((unsigned short)lenhi) << 8) + lenlo);
+
+			while (Length > 0) {
+			/* Look for Serial Number */
+			if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
+				index += 2;
+				i = vpd[index];
+				index += 1;
+				j = 0;
+				Length -= (3+i);
+				while(i--) {
+					phba->SerialNumber[j++] = vpd[index++];
+					if(j == 31)
+						break;
+				}
+				phba->SerialNumber[j] = 0;
+				continue;
+			}
+			else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
+				phba->vpd_flag |= VPD_MODEL_DESC;
+				index += 2;
+				i = vpd[index];
+				index += 1;
+				j = 0;
+				Length -= (3+i);
+				while(i--) {
+					phba->ModelDesc[j++] = vpd[index++];
+					if(j == 255)
+						break;
+				}
+				phba->ModelDesc[j] = 0;
+				continue;
+			}
+			else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
+				phba->vpd_flag |= VPD_MODEL_NAME;
+				index += 2;
+				i = vpd[index];
+				index += 1;
+				j = 0;
+				Length -= (3+i);
+				while(i--) {
+					phba->ModelName[j++] = vpd[index++];
+					if(j == 79)
+						break;
+				}
+				phba->ModelName[j] = 0;
+				continue;
+			}
+			else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
+				phba->vpd_flag |= VPD_PROGRAM_TYPE;
+				index += 2;
+				i = vpd[index];
+				index += 1;
+				j = 0;
+				Length -= (3+i);
+				while(i--) {
+					phba->ProgramType[j++] = vpd[index++];
+					if(j == 255)
+						break;
+				}
+				phba->ProgramType[j] = 0;
+				continue;
+			}
+			else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
+				phba->vpd_flag |= VPD_PORT;
+				index += 2;
+				i = vpd[index];
+				index += 1;
+				j = 0;
+				Length -= (3+i);
+				while(i--) {
+				phba->Port[j++] = vpd[index++];
+				if(j == 19)
+					break;
+				}
+				phba->Port[j] = 0;
+				continue;
+			}
+			else {
+				index += 2;
+				i = vpd[index];
+				index += 1;
+				index += i;
+				Length -= (3 + i);
+			}
+		}
+		finished = 0;
+		break;
+		case 0x78:
+			finished = 1;
+			break;
+		default:
+			index ++;
+			break;
+		}
+	} while (!finished && (index < 108));
+
+	return(1);
+}
+
+static void
+lpfc_get_hba_model_desc(struct lpfc_hba * phba, uint8_t * mdp, uint8_t * descp)
+{
+	lpfc_vpd_t *vp;
+	uint32_t id;
+	uint8_t hdrtype;
+	char str[16];
+
+	vp = &phba->vpd;
+	pci_read_config_dword(phba->pcidev, PCI_VENDOR_ID, &id);
+	pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
+
+	switch ((id >> 16) & 0xffff) {
+	case PCI_DEVICE_ID_SUPERFLY:
+		if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
+			strcpy(str, "LP7000 1");
+		else
+			strcpy(str, "LP7000E 1");
+		break;
+	case PCI_DEVICE_ID_DRAGONFLY:
+		strcpy(str, "LP8000 1");
+		break;
+	case PCI_DEVICE_ID_CENTAUR:
+		if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
+			strcpy(str, "LP9002 2");
+		else
+			strcpy(str, "LP9000 1");
+		break;
+	case PCI_DEVICE_ID_RFLY:
+		strcpy(str, "LP952 2");
+		break;
+	case PCI_DEVICE_ID_PEGASUS:
+		strcpy(str, "LP9802 2");
+		break;
+	case PCI_DEVICE_ID_THOR:
+		if (hdrtype == 0x80)
+			strcpy(str, "LP10000DC 2");
+		else
+			strcpy(str, "LP10000 2");
+		break;
+	case PCI_DEVICE_ID_VIPER:
+		strcpy(str, "LPX1000 10");
+		break;
+	case PCI_DEVICE_ID_PFLY:
+		strcpy(str, "LP982 2");
+		break;
+	case PCI_DEVICE_ID_TFLY:
+		if (hdrtype == 0x80)
+			strcpy(str, "LP1050DC 2");
+		else
+			strcpy(str, "LP1050 2");
+		break;
+	case PCI_DEVICE_ID_HELIOS:
+		if (hdrtype == 0x80)
+			strcpy(str, "LP11002 4");
+		else
+			strcpy(str, "LP11000 4");
+		break;
+	case PCI_DEVICE_ID_BMID:
+		strcpy(str, "LP1150 4");
+		break;
+	case PCI_DEVICE_ID_BSMB:
+		strcpy(str, "LP111 4");
+		break;
+	case PCI_DEVICE_ID_ZEPHYR:
+		if (hdrtype == 0x80)
+			strcpy(str, "LPe11002 4");
+		else
+			strcpy(str, "LPe11000 4");
+		break;
+	case PCI_DEVICE_ID_ZMID:
+		strcpy(str, "LPe1150 4");
+		break;
+	case PCI_DEVICE_ID_ZSMB:
+		strcpy(str, "LPe111 4");
+		break;
+	case PCI_DEVICE_ID_LP101:
+		strcpy(str, "LP101 2");
+		break;
+	case PCI_DEVICE_ID_LP10000S:
+		strcpy(str, "LP10000-S 2");
+		break;
+	}
+	if (mdp)
+		sscanf(str, "%s", mdp);
+	if (descp)
+		sprintf(descp, "Emulex LightPulse %s Gigabit PCI Fibre "
+			"Channel Adapter", str);
+}
+
+/**************************************************/
+/*   lpfc_post_buffer                             */
+/*                                                */
+/*   This routine will post count buffers to the  */
+/*   ring with the QUE_RING_BUF_CN command. This  */
+/*   allows 3 buffers / command to be posted.     */
+/*   Returns the number of buffers NOT posted.    */
+/**************************************************/
+int
+lpfc_post_buffer(struct lpfc_hba * phba, struct lpfc_sli_ring * pring, int cnt,
+		 int type)
+{
+	IOCB_t *icmd;
+	struct lpfc_iocbq *iocb;
+	struct lpfc_dmabuf *mp1, *mp2;
+
+	cnt += pring->missbufcnt;
+
+	/* While there are buffers to post */
+	while (cnt > 0) {
+		/* Allocate buffer for  command iocb */
+		if ((iocb = mempool_alloc(phba->iocb_mem_pool, GFP_ATOMIC))
+		    == 0) {
+			pring->missbufcnt = cnt;
+			return (cnt);
+		}
+		memset(iocb, 0, sizeof (struct lpfc_iocbq));
+		icmd = &iocb->iocb;
+
+		/* 2 buffers can be posted per command */
+		/* Allocate buffer to post */
+		mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_ATOMIC);
+		if (mp1)
+		    mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
+						&mp1->phys);
+		if (mp1 == 0 || mp1->virt == 0) {
+			if (mp1)
+				kfree(mp1);
+
+			mempool_free( iocb, phba->iocb_mem_pool);
+			pring->missbufcnt = cnt;
+			return (cnt);
+		}
+
+		INIT_LIST_HEAD(&mp1->list);
+		/* Allocate buffer to post */
+		if (cnt > 1) {
+			mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_ATOMIC);
+			if (mp2)
+				mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
+							    &mp2->phys);
+			if (mp2 == 0 || mp2->virt == 0) {
+				if (mp2)
+					kfree(mp2);
+				lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
+				kfree(mp1);
+				mempool_free( iocb, phba->iocb_mem_pool);
+				pring->missbufcnt = cnt;
+				return (cnt);
+			}
+
+			INIT_LIST_HEAD(&mp2->list);
+		} else {
+			mp2 = NULL;
+		}
+
+		icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
+		icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
+		icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
+		icmd->ulpBdeCount = 1;
+		cnt--;
+		if (mp2) {
+			icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
+			icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
+			icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
+			cnt--;
+			icmd->ulpBdeCount = 2;
+		}
+
+		icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
+		icmd->ulpIoTag = lpfc_sli_next_iotag(phba, pring);
+		icmd->ulpLe = 1;
+
+		if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
+			lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
+			kfree(mp1);
+			cnt++;
+			if (mp2) {
+				lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
+				kfree(mp2);
+				cnt++;
+			}
+			mempool_free( iocb, phba->iocb_mem_pool);
+			pring->missbufcnt = cnt;
+			return (cnt);
+		}
+		lpfc_sli_ringpostbuf_put(phba, pring, mp1);
+		if (mp2) {
+			lpfc_sli_ringpostbuf_put(phba, pring, mp2);
+		}
+	}
+	pring->missbufcnt = 0;
+	return (0);
+}
+
+/************************************************************************/
+/*                                                                      */
+/*   lpfc_post_rcv_buf                                                  */
+/*   This routine post initial rcv buffers to the configured rings      */
+/*                                                                      */
+/************************************************************************/
+static int
+lpfc_post_rcv_buf(struct lpfc_hba * phba)
+{
+	struct lpfc_sli *psli = &phba->sli;
+
+	/* Ring 0, ELS / CT buffers */
+	lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0, 1);
+	/* Ring 2 - FCP no buffers needed */
+
+	return 0;
+}
+
+#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
+
+/************************************************************************/
+/*                                                                      */
+/*   lpfc_sha_init                                                      */
+/*                                                                      */
+/************************************************************************/
+static void
+lpfc_sha_init(uint32_t * HashResultPointer)
+{
+	HashResultPointer[0] = 0x67452301;
+	HashResultPointer[1] = 0xEFCDAB89;
+	HashResultPointer[2] = 0x98BADCFE;
+	HashResultPointer[3] = 0x10325476;
+	HashResultPointer[4] = 0xC3D2E1F0;
+}
+
+/************************************************************************/
+/*                                                                      */
+/*   lpfc_sha_iterate                                                   */
+/*                                                                      */
+/************************************************************************/
+static void
+lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
+{
+	int t;
+	uint32_t TEMP;
+	uint32_t A, B, C, D, E;
+	t = 16;
+	do {
+		HashWorkingPointer[t] =
+		    S(1,
+		      HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
+								     8] ^
+		      HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
+	} while (++t <= 79);
+	t = 0;
+	A = HashResultPointer[0];
+	B = HashResultPointer[1];
+	C = HashResultPointer[2];
+	D = HashResultPointer[3];
+	E = HashResultPointer[4];
+
+	do {
+		if (t < 20) {
+			TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
+		} else if (t < 40) {
+			TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
+		} else if (t < 60) {
+			TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
+		} else {
+			TEMP = (B ^ C ^ D) + 0xCA62C1D6;
+		}
+		TEMP += S(5, A) + E + HashWorkingPointer[t];
+		E = D;
+		D = C;
+		C = S(30, B);
+		B = A;
+		A = TEMP;
+	} while (++t <= 79);
+
+	HashResultPointer[0] += A;
+	HashResultPointer[1] += B;
+	HashResultPointer[2] += C;
+	HashResultPointer[3] += D;
+	HashResultPointer[4] += E;
+
+}
+
+/************************************************************************/
+/*                                                                      */
+/*   lpfc_challenge_key                                                 */
+/*                                                                      */
+/************************************************************************/
+static void
+lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
+{
+	*HashWorking = (*RandomChallenge ^ *HashWorking);
+}
+
+/************************************************************************/
+/*                                                                      */
+/*   lpfc_hba_init                                                      */
+/*                                                                      */
+/************************************************************************/
+void
+lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
+{
+	int t;
+	uint32_t *HashWorking;
+	uint32_t *pwwnn = phba->wwnn;
+
+	HashWorking = kmalloc(80 * sizeof(uint32_t), GFP_ATOMIC);
+	if (!HashWorking)
+		return;
+
+	memset(HashWorking, 0, (80 * sizeof(uint32_t)));
+	HashWorking[0] = HashWorking[78] = *pwwnn++;
+	HashWorking[1] = HashWorking[79] = *pwwnn;
+
+	for (t = 0; t < 7; t++)
+		lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
+
+	lpfc_sha_init(hbainit);
+	lpfc_sha_iterate(hbainit, HashWorking);
+	kfree(HashWorking);
+}
+
+static void
+lpfc_consistent_bind_cleanup(struct lpfc_hba * phba)
+{
+	struct lpfc_bindlist *bdlp, *next_bdlp;
+
+	list_for_each_entry_safe(bdlp, next_bdlp,
+				 &phba->fc_nlpbind_list, nlp_listp) {
+		list_del(&bdlp->nlp_listp);
+		mempool_free( bdlp, phba->bind_mem_pool);
+	}
+	phba->fc_bind_cnt = 0;
+}
+
+void
+lpfc_cleanup(struct lpfc_hba * phba, uint32_t save_bind)
+{
+	struct lpfc_nodelist *ndlp, *next_ndlp;
+
+	/* clean up phba - lpfc specific */
+	lpfc_can_disctmo(phba);
+	list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpunmap_list,
+				nlp_listp) {
+		lpfc_nlp_remove(phba, ndlp);
+	}
+
+	list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpmap_list,
+				 nlp_listp) {
+		lpfc_nlp_remove(phba, ndlp);
+	}
+
+	list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
+				nlp_listp) {
+		lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
+	}
+
+	list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
+				nlp_listp) {
+		lpfc_nlp_remove(phba, ndlp);
+	}
+
+	list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
+				nlp_listp) {
+		lpfc_nlp_remove(phba, ndlp);
+	}
+
+	list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_reglogin_list,
+				nlp_listp) {
+		lpfc_nlp_remove(phba, ndlp);
+	}
+
+	list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_prli_list,
+				nlp_listp) {
+		lpfc_nlp_remove(phba, ndlp);
+	}
+
+	list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
+				nlp_listp) {
+		lpfc_nlp_remove(phba, ndlp);
+	}
+
+	if (save_bind == 0) {
+		lpfc_consistent_bind_cleanup(phba);
+	}
+
+	INIT_LIST_HEAD(&phba->fc_nlpmap_list);
+	INIT_LIST_HEAD(&phba->fc_nlpunmap_list);
+	INIT_LIST_HEAD(&phba->fc_unused_list);
+	INIT_LIST_HEAD(&phba->fc_plogi_list);
+	INIT_LIST_HEAD(&phba->fc_adisc_list);
+	INIT_LIST_HEAD(&phba->fc_reglogin_list);
+	INIT_LIST_HEAD(&phba->fc_prli_list);
+	INIT_LIST_HEAD(&phba->fc_npr_list);
+
+	phba->fc_map_cnt   = 0;
+	phba->fc_unmap_cnt = 0;
+	phba->fc_plogi_cnt = 0;
+	phba->fc_adisc_cnt = 0;
+	phba->fc_reglogin_cnt = 0;
+	phba->fc_prli_cnt  = 0;
+	phba->fc_npr_cnt   = 0;
+	phba->fc_unused_cnt= 0;
+	return;
+}
+
+void
+lpfc_establish_link_tmo(unsigned long ptr)
+{
+	struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
+	unsigned long iflag;
+
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+
+	/* Re-establishing Link, timer expired */
+	lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
+			"%d:1300 Re-establishing Link, timer expired "
+			"Data: x%x x%x\n",
+			phba->brd_no, phba->fc_flag, phba->hba_state);
+	phba->fc_flag &= ~FC_ESTABLISH_LINK;
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+}
+
+int
+lpfc_online(struct lpfc_hba * phba)
+{
+	if (!phba)
+		return 0;
+
+	if (!(phba->fc_flag & FC_OFFLINE_MODE))
+		return 0;
+
+	lpfc_printf_log(phba,
+		       KERN_WARNING,
+		       LOG_INIT,
+		       "%d:0458 Bring Adapter online\n",
+		       phba->brd_no);
+
+	if (!lpfc_sli_queue_setup(phba))
+		return 1;
+
+	if (lpfc_sli_hba_setup(phba))	/* Initialize the HBA */
+		return 1;
+
+	phba->fc_flag &= ~FC_OFFLINE_MODE;
+
+	/*
+	 * Restart all traffic to this host.  Since the fc_transport block
+	 * functions (future) were not called in lpfc_offline, don't call them
+	 * here.
+	 */
+	scsi_unblock_requests(phba->host);
+	return 0;
+}
+
+int
+lpfc_offline(struct lpfc_hba * phba)
+{
+	struct lpfc_sli_ring *pring;
+	struct lpfc_sli *psli;
+	unsigned long iflag;
+	int i = 0;
+
+	if (!phba)
+		return 0;
+
+	if (phba->fc_flag & FC_OFFLINE_MODE)
+		return 0;
+
+	/*
+	 * Don't call the fc_transport block api (future).  The device is
+	 * going offline and causing a timer to fire in the midlayer is
+	 * unproductive.  Just block all new requests until the driver
+	 * comes back online.
+	 */
+	scsi_block_requests(phba->host);
+	psli = &phba->sli;
+	pring = &psli->ring[psli->fcp_ring];
+
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+	lpfc_linkdown(phba);
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+
+	/* The linkdown event takes 30 seconds to timeout. */
+	while (pring->txcmplq_cnt) {
+		mdelay(10);
+		if (i++ > 3000)
+			break;
+	}
+
+	/* stop all timers associated with this hba */
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+	lpfc_stop_timer(phba);
+	phba->work_hba_events = 0;
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+
+	lpfc_printf_log(phba,
+		       KERN_WARNING,
+		       LOG_INIT,
+		       "%d:0460 Bring Adapter offline\n",
+		       phba->brd_no);
+
+	/* Bring down the SLI Layer and cleanup.  The HBA is offline
+	   now.  */
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+	lpfc_sli_hba_down(phba);
+	lpfc_cleanup(phba, 1);
+	phba->fc_flag |= FC_OFFLINE_MODE;
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+	return 0;
+}
+
+/******************************************************************************
+* Function name : lpfc_scsi_free
+*
+* Description   : Called from fc_detach to free scsi tgt / lun resources
+*
+******************************************************************************/
+int
+lpfc_scsi_free(struct lpfc_hba * phba)
+{
+	struct lpfc_target *targetp;
+	int i;
+
+	for (i = 0; i < MAX_FCP_TARGET; i++) {
+		targetp = phba->device_queue_hash[i];
+		if (targetp) {
+			kfree(targetp);
+			phba->device_queue_hash[i] = NULL;
+		}
+	}
+	return 0;
+}
+
+static void
+lpfc_wakeup_event(struct lpfc_hba * phba, fcEVTHDR_t * ep)
+{
+	ep->e_mode &= ~E_SLEEPING_MODE;
+	switch (ep->e_mask) {
+	case FC_REG_LINK_EVENT:
+		wake_up_interruptible(&phba->linkevtwq);
+		break;
+	case FC_REG_RSCN_EVENT:
+		wake_up_interruptible(&phba->rscnevtwq);
+		break;
+	case FC_REG_CT_EVENT:
+		wake_up_interruptible(&phba->ctevtwq);
+		break;
+	}
+	return;
+}
+
+int
+lpfc_put_event(struct lpfc_hba * phba, uint32_t evcode, uint32_t evdata0,
+	       void * evdata1, uint32_t evdata2, uint32_t evdata3)
+{
+	fcEVT_t *ep;
+	fcEVTHDR_t *ehp = phba->fc_evt_head;
+	int found = 0;
+	void *fstype = NULL;
+	struct lpfc_dmabuf *mp;
+	struct lpfc_sli_ct_request *ctp;
+	struct lpfc_hba_event *rec;
+	uint32_t evtype;
+
+	switch (evcode) {
+		case HBA_EVENT_RSCN:
+			evtype = FC_REG_RSCN_EVENT;
+			break;
+		case HBA_EVENT_LINK_DOWN:
+		case HBA_EVENT_LINK_UP:
+			evtype = FC_REG_LINK_EVENT;
+			break;
+		default:
+			evtype = FC_REG_CT_EVENT;
+	}
+
+	if (evtype == FC_REG_RSCN_EVENT || evtype == FC_REG_LINK_EVENT) {
+		rec = &phba->hbaevt[phba->hba_event_put];
+		rec->fc_eventcode = evcode;
+		rec->fc_evdata1 = evdata0;
+		rec->fc_evdata2 = (uint32_t)(unsigned long)evdata1;
+		rec->fc_evdata3 = evdata2;
+		rec->fc_evdata4 = evdata3;
+
+		phba->hba_event_put++;
+		if (phba->hba_event_put >= MAX_HBAEVT)
+			phba->hba_event_put = 0;
+
+		if (phba->hba_event_put == phba->hba_event_get) {
+			phba->hba_event_missed++;
+			phba->hba_event_get++;
+			if (phba->hba_event_get >= MAX_HBAEVT)
+				phba->hba_event_get = 0;
+		}
+	}
+
+	if (evtype == FC_REG_CT_EVENT) {
+		mp = (struct lpfc_dmabuf *) evdata1;
+		ctp = (struct lpfc_sli_ct_request *) mp->virt;
+		fstype = (void *)(ulong) (ctp->FsType);
+	}
+
+	while (ehp && ((ehp->e_mask != evtype) || (ehp->e_type != fstype)))
+		ehp = (fcEVTHDR_t *) ehp->e_next_header;
+
+	if (!ehp)
+		return (0);
+
+	ep = ehp->e_head;
+
+	while (ep && !(found)) {
+		if (ep->evt_sleep) {
+			switch (evtype) {
+			case FC_REG_CT_EVENT:
+				if ((ep->evt_type ==
+				     (void *)(ulong) FC_FSTYPE_ALL)
+				    || (ep->evt_type == fstype)) {
+					found++;
+					ep->evt_data0 = evdata0; /* tag */
+					ep->evt_data1 = evdata1; /* buffer
+								    ptr */
+					ep->evt_data2 = evdata2; /* count */
+					ep->evt_sleep = 0;
+					if (ehp->e_mode & E_SLEEPING_MODE) {
+						ehp->e_flag |=
+						    E_GET_EVENT_ACTIVE;
+						lpfc_wakeup_event(phba, ehp);
+					}
+					/* For FC_REG_CT_EVENT just give it to
+					   first one found */
+				}
+				break;
+			default:
+				found++;
+				ep->evt_data0 = evdata0;
+				ep->evt_data1 = evdata1;
+				ep->evt_data2 = evdata2;
+				ep->evt_sleep = 0;
+				if ((ehp->e_mode & E_SLEEPING_MODE)
+				    && !(ehp->e_flag & E_GET_EVENT_ACTIVE)) {
+					ehp->e_flag |= E_GET_EVENT_ACTIVE;
+					lpfc_wakeup_event(phba, ehp);
+				}
+				/* For all other events, give it to every one
+				   waiting */
+				break;
+			}
+		}
+		ep = ep->evt_next;
+	}
+	if (evtype == FC_REG_LINK_EVENT)
+		phba->nport_event_cnt++;
+
+	return (found);
+}
+
+int
+lpfc_stop_timer(struct lpfc_hba * phba)
+{
+	struct lpfc_sli *psli = &phba->sli;
+
+	/* Instead of a timer, this has been converted to a
+	 * deferred procedding list.
+	 */
+	while (!list_empty(&phba->freebufList)) {
+		struct lpfc_dmabuf *mp;
+
+		mp = (struct lpfc_dmabuf *)(phba->freebufList.next);
+		if (mp) {
+			lpfc_mbuf_free(phba, mp->virt, mp->phys);
+			list_del(&mp->list);
+			kfree(mp);
+		}
+	}
+
+	del_timer_sync(&phba->fc_estabtmo);
+	del_timer_sync(&phba->fc_disctmo);
+	del_timer_sync(&phba->fc_scantmo);
+	del_timer_sync(&phba->fc_fdmitmo);
+	del_timer_sync(&phba->els_tmofunc);
+	psli = &phba->sli;
+	del_timer_sync(&psli->mbox_tmo);
+	return(1);
+}
--- linux-2.6.8.1-t044-driver-update//drivers/scsi/lpfc/lpfc_scsiport.c	1970-01-01 03:00:00.000000000 +0300
+++ rhel4u2//drivers/scsi/lpfc/lpfc_scsiport.c	2005-10-19 11:47:17.000000000 +0400
@@ -0,0 +1,1374 @@
+/*******************************************************************
+ * This file is part of the Emulex Linux Device Driver for         *
+ * Fibre Channel Host Bus Adapters.                                *
+ * Copyright (C) 2003-2005 Emulex.  All rights reserved.           *
+ * EMULEX and SLI are trademarks of Emulex.                        *
+ * www.emulex.com                                                  *
+ *                                                                 *
+ * This program is free software; you can redistribute it and/or   *
+ * modify it under the terms of version 2 of the GNU General       *
+ * Public License as published by the Free Software Foundation.    *
+ * This program is distributed in the hope that it will be useful. *
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
+ * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
+ * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
+ * more details, a copy of which can be found in the file COPYING  *
+ * included with this package.                                     *
+ *******************************************************************/
+
+/*
+ * $Id: lpfc_scsiport.c 1.231.2.8 2005/07/25 12:56:08EDT sf_support Exp  $
+ */
+#include <linux/version.h>
+#include <linux/spinlock.h>
+#include <linux/pci.h>
+#include <linux/blkdev.h>
+#include <scsi/scsi.h>
+#include <scsi/scsi_device.h>
+#include <scsi/scsi_host.h>
+#include <scsi/scsi_cmnd.h>
+#include <scsi/scsi_transport_fc.h>
+
+#include "lpfc_hw.h"
+#include "lpfc_sli.h"
+#include "lpfc_mem.h"
+#include "lpfc_disc.h"
+#include "lpfc_scsi.h"
+#include "lpfc.h"
+#include "lpfc_logmsg.h"
+#include "lpfc_fcp.h"
+#include "lpfc_crtn.h"
+
+/* This routine allocates a scsi buffer, which contains all the necessary
+ * information needed to initiate a SCSI I/O. The non-DMAable region of
+ * the buffer contains the area to build the IOCB. The DMAable region contains
+ * the memory for the FCP CMND, FCP RSP, and the inital BPL.
+ * In addition to allocating memeory, the FCP CMND and FCP RSP BDEs are setup
+ * in the BPL and the BPL BDE is setup in the IOCB.
+ */
+struct lpfc_scsi_buf *
+lpfc_get_scsi_buf(struct lpfc_hba * phba, int gfp_flags)
+{
+	struct lpfc_scsi_buf *psb;
+	struct ulp_bde64 *bpl;
+	IOCB_t *cmd;
+	uint8_t *ptr;
+	dma_addr_t pdma_phys;
+
+	psb = mempool_alloc(phba->scsibuf_mem_pool, gfp_flags);
+	if (!psb)
+		return NULL;
+
+	memset(psb, 0, sizeof (struct lpfc_scsi_buf));
+
+	/* Get a SCSI DMA extention for an I/O */
+	/*
+	 * The DMA buffer for struct fcp_cmnd, struct fcp_rsp and BPL use
+	 * lpfc_scsi_dma_ext_pool with size LPFC_SCSI_DMA_EXT_SIZE
+	 *
+	 *
+	 *    The size of struct fcp_cmnd  = 32 bytes.
+	 *    The size of struct fcp_rsp   = 160 bytes.
+	 *    The size of struct ulp_bde64 = 12 bytes and driver can only
+	 *    support LPFC_SCSI_INITIAL_BPL_SIZE (3) S/G segments for scsi data.
+	 *    One struct ulp_bde64 is used for each of the struct fcp_cmnd and
+	 *    struct fcp_rsp
+	 *
+	 *    Total usage for each I/O use 32 + 160 + (2 * 12) +
+	 *    (4 * 12) = 264 bytes.
+	 */
+
+	INIT_LIST_HEAD(&psb->dma_ext.list);
+
+	psb->dma_ext.virt = pci_pool_alloc(phba->lpfc_scsi_dma_ext_pool,
+					   GFP_ATOMIC, &psb->dma_ext.phys);
+	if (!psb->dma_ext.virt) {
+		mempool_free(psb, phba->scsibuf_mem_pool);
+		return NULL;
+	}
+
+	/* Save virtual ptrs to FCP Command, Response, and BPL */
+	ptr = (uint8_t *) psb->dma_ext.virt;
+
+	memset(ptr, 0, LPFC_SCSI_DMA_EXT_SIZE);
+	psb->fcp_cmnd = (struct fcp_cmnd *) ptr;
+	ptr += sizeof (struct fcp_cmnd);
+	psb->fcp_rsp = (struct fcp_rsp *) ptr;
+	ptr += (sizeof (struct fcp_rsp));
+	psb->fcp_bpl = (struct ulp_bde64 *) ptr;
+	psb->scsi_hba = phba;
+
+	/* Since this is for a FCP cmd, the first 2 BDEs in the BPL are always
+	 * the FCP CMND and FCP RSP, so lets just set it up right here.
+	 */
+	bpl = psb->fcp_bpl;
+	/* ptr points to physical address of FCP CMD */
+	pdma_phys = psb->dma_ext.phys;
+	bpl->addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys));
+	bpl->addrLow = le32_to_cpu(putPaddrLow(pdma_phys));
+	bpl->tus.f.bdeSize = sizeof (struct fcp_cmnd);
+	bpl->tus.f.bdeFlags = BUFF_USE_CMND;
+	bpl->tus.w = le32_to_cpu(bpl->tus.w);
+	bpl++;
+
+	/* Setup FCP RSP */
+	pdma_phys += sizeof (struct fcp_cmnd);
+	bpl->addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys));
+	bpl->addrLow = le32_to_cpu(putPaddrLow(pdma_phys));
+	bpl->tus.f.bdeSize = sizeof (struct fcp_rsp);
+	bpl->tus.f.bdeFlags = (BUFF_USE_CMND | BUFF_USE_RCV);
+	bpl->tus.w = le32_to_cpu(bpl->tus.w);
+	bpl++;
+
+	/* Since the IOCB for the FCP I/O is built into the struct
+	 * lpfc_scsi_buf, lets setup what we can right here.
+	 */
+	pdma_phys += (sizeof (struct fcp_rsp));
+	cmd = &psb->cur_iocbq.iocb;
+	cmd->un.fcpi64.bdl.ulpIoTag32 = 0;
+	cmd->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys);
+	cmd->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys);
+	cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof (struct ulp_bde64));
+	cmd->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDL;
+	cmd->ulpBdeCount = 1;
+	cmd->ulpClass = CLASS3;
+
+	return (psb);
+}
+
+void
+lpfc_free_scsi_buf(struct lpfc_scsi_buf * psb)
+{
+	struct lpfc_hba *phba = psb->scsi_hba;
+	struct lpfc_dmabuf *pbpl, *next_bpl;
+
+	/*
+	 * There are only two special cases to consider.  (1) the scsi command
+	 * requested scatter-gather usage or (2) the scsi command allocated
+	 * a request buffer, but did not request use_sg.  There is a third
+	 * case, but it does not require resource deallocation.
+	 */
+
+	if ((psb->seg_cnt > 0) && (psb->pCmd->use_sg)) {
+		/*
+		 * Since the segment count is nonzero, the scsi command
+		 * requested scatter-gather usage and the driver allocated
+		 * addition memory buffers to chain BPLs.  Traverse this list
+		 * and release those resource before freeing the parent
+		 * structure.
+		 */
+		dma_unmap_sg(&phba->pcidev->dev, psb->pCmd->request_buffer,
+				psb->seg_cnt, psb->pCmd->sc_data_direction);
+
+		list_for_each_entry_safe(pbpl, next_bpl,
+						&psb->dma_ext.list, list) {
+			lpfc_mbuf_free(phba, pbpl->virt, pbpl->phys);
+			list_del(&pbpl->list);
+			kfree(pbpl);
+		}
+	} else {
+		 if ((psb->nonsg_phys) && (psb->pCmd->request_bufflen)) {
+			/*
+			 * Since either the segment count or the use_sg
+			 * value is zero, the scsi command did not request
+			 * scatter-gather usage and no additional buffers were
+			 * required.  Just unmap the dma single resource.
+			 */
+			dma_unmap_single(&phba->pcidev->dev, psb->nonsg_phys,
+						psb->pCmd->request_bufflen,
+						psb->pCmd->sc_data_direction);
+		 }
+	}
+
+	/*
+	 * Release the pci pool resource and clean up the scsi buffer.  Neither
+	 * are required now that the IO has completed.
+	 */
+	pci_pool_free(phba->lpfc_scsi_dma_ext_pool, psb->dma_ext.virt,
+							 psb->dma_ext.phys);
+	mempool_free(psb, phba->scsibuf_mem_pool);
+}
+
+static int
+lpfc_os_prep_io(struct lpfc_hba * phba, struct lpfc_scsi_buf * lpfc_cmd)
+{
+	struct fcp_cmnd *fcp_cmnd;
+	struct ulp_bde64 *topbpl = NULL;
+	struct ulp_bde64 *bpl;
+	struct lpfc_dmabuf *bmp;
+	struct lpfc_dmabuf *head_bmp;
+	IOCB_t *cmd;
+	struct scsi_cmnd *cmnd;
+	struct scatterlist *sgel = NULL;
+	struct scatterlist *sgel_begin = NULL;
+	dma_addr_t physaddr;
+	uint32_t i;
+	uint32_t num_bmps = 1, num_bde = 0, max_bde;
+	uint16_t use_sg;
+	int datadir;
+	int dma_error;
+
+	bpl = lpfc_cmd->fcp_bpl;
+	fcp_cmnd = lpfc_cmd->fcp_cmnd;
+
+	bpl += 2;		/* Bump past FCP CMND and FCP RSP */
+	max_bde = LPFC_SCSI_INITIAL_BPL_SIZE - 1;
+
+	cmnd = lpfc_cmd->pCmd;
+	cmd = &lpfc_cmd->cur_iocbq.iocb;
+
+	/* These are needed if we chain BPLs */
+	head_bmp = &(lpfc_cmd->dma_ext);
+	use_sg = cmnd->use_sg;
+
+	/*
+	 * Fill in the FCP CMND
+	 */
+	memcpy(&fcp_cmnd->fcpCdb[0], cmnd->cmnd, 16);
+
+	if (cmnd->device->tagged_supported) {
+		switch (cmnd->tag) {
+		case HEAD_OF_QUEUE_TAG:
+			fcp_cmnd->fcpCntl1 = HEAD_OF_Q;
+			break;
+		case ORDERED_QUEUE_TAG:
+			fcp_cmnd->fcpCntl1 = ORDERED_Q;
+			break;
+		default:
+			fcp_cmnd->fcpCntl1 = SIMPLE_Q;
+			break;
+		}
+	} else {
+		fcp_cmnd->fcpCntl1 = 0;
+	}
+
+	datadir = cmnd->sc_data_direction;
+
+	if (use_sg) {
+		/*
+		 * Get a local pointer to the scatter-gather list.  The
+		 * scatter-gather list head must be preserved since
+		 * sgel is incremented in the loop.  The driver must store
+		 * the segment count returned from pci_map_sg for calls to
+		 * pci_unmap_sg later on because the use_sg field in the
+		 * scsi_cmd is a count of physical memory pages, whereas the
+		 * seg_cnt is a count of dma-mappings used by the MMIO to
+		 * map the use_sg pages.  They are not the same in most
+		 * cases for those architectures that implement an MMIO.
+		 */
+		sgel = (struct scatterlist *)cmnd->request_buffer;
+		sgel_begin = sgel;
+		lpfc_cmd->seg_cnt = dma_map_sg(&phba->pcidev->dev, sgel,
+						use_sg, datadir);
+
+		/* return error if we cannot map sg list */
+		if (lpfc_cmd->seg_cnt == 0)
+			return 1;
+
+		/* scatter-gather list case */
+		for (i = 0; i < lpfc_cmd->seg_cnt; i++) {
+			/* Check to see if current BPL is full of BDEs */
+			/* If this is last BDE and there is one left in */
+			/* current BPL, use it.                         */
+			if (num_bde == max_bde) {
+				bmp = kmalloc(sizeof (struct lpfc_dmabuf),
+					      GFP_ATOMIC);
+				if (bmp == 0) {
+					goto error_out;
+				}
+				memset(bmp, 0, sizeof (struct lpfc_dmabuf));
+				bmp->virt =
+				    lpfc_mbuf_alloc(phba, 0, &bmp->phys);
+				if (!bmp->virt) {
+					kfree(bmp);
+					goto error_out;
+				}
+				max_bde = ((1024 / sizeof(struct ulp_bde64))-3);
+				/* Fill in continuation entry to next bpl */
+				bpl->addrHigh =
+				    le32_to_cpu(putPaddrHigh(bmp->phys));
+				bpl->addrLow =
+				    le32_to_cpu(putPaddrLow(bmp->phys));
+				bpl->tus.f.bdeFlags = BPL64_SIZE_WORD;
+				num_bde++;
+				if (num_bmps == 1) {
+					cmd->un.fcpi64.bdl.bdeSize += (num_bde *
+						sizeof (struct ulp_bde64));
+				} else {
+					topbpl->tus.f.bdeSize = (num_bde *
+						sizeof (struct ulp_bde64));
+					topbpl->tus.w =
+					    le32_to_cpu(topbpl->tus.w);
+				}
+				topbpl = bpl;
+				bpl = (struct ulp_bde64 *) bmp->virt;
+				list_add(&bmp->list, &head_bmp->list);
+				num_bde = 0;
+				num_bmps++;
+			}
+
+			physaddr = sg_dma_address(sgel);
+
+			bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr));
+			bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
+			bpl->tus.f.bdeSize = sg_dma_len(sgel);
+			if (datadir == DMA_TO_DEVICE)
+				bpl->tus.f.bdeFlags = 0;
+			else
+				bpl->tus.f.bdeFlags = BUFF_USE_RCV;
+			bpl->tus.w = le32_to_cpu(bpl->tus.w);
+			bpl++;
+			sgel++;
+			num_bde++;
+		}		/* end for loop */
+
+		if (datadir == DMA_TO_DEVICE) {
+			cmd->ulpCommand = CMD_FCP_IWRITE64_CR;
+			fcp_cmnd->fcpCntl3 = WRITE_DATA;
+
+			phba->fc4OutputRequests++;
+		} else {
+			cmd->ulpCommand = CMD_FCP_IREAD64_CR;
+			cmd->ulpPU = PARM_READ_CHECK;
+			cmd->un.fcpi.fcpi_parm = cmnd->request_bufflen;
+			fcp_cmnd->fcpCntl3 = READ_DATA;
+
+			phba->fc4InputRequests++;
+		}
+	} else if (cmnd->request_buffer && cmnd->request_bufflen) {
+		physaddr = dma_map_single(&phba->pcidev->dev,
+					  cmnd->request_buffer,
+					  cmnd->request_bufflen,
+					  datadir);
+			dma_error = dma_mapping_error(physaddr);
+			if (dma_error){
+				lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
+					"%d:0718 Unable to dma_map_single "
+					"request_buffer: x%x\n",
+					phba->brd_no, dma_error);
+				return 1;
+			}
+
+		/* no scatter-gather list case */
+		lpfc_cmd->nonsg_phys = physaddr;
+		bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr));
+		bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
+		bpl->tus.f.bdeSize = cmnd->request_bufflen;
+		if (datadir == DMA_TO_DEVICE) {
+			cmd->ulpCommand = CMD_FCP_IWRITE64_CR;
+			fcp_cmnd->fcpCntl3 = WRITE_DATA;
+			bpl->tus.f.bdeFlags = 0;
+
+			phba->fc4OutputRequests++;
+		} else {
+			cmd->ulpCommand = CMD_FCP_IREAD64_CR;
+			cmd->ulpPU = PARM_READ_CHECK;
+			cmd->un.fcpi.fcpi_parm = cmnd->request_bufflen;
+			fcp_cmnd->fcpCntl3 = READ_DATA;
+			bpl->tus.f.bdeFlags = BUFF_USE_RCV;
+
+			phba->fc4InputRequests++;
+		}
+		bpl->tus.w = le32_to_cpu(bpl->tus.w);
+		num_bde = 1;
+		bpl++;
+	} else {
+		cmd->ulpCommand = CMD_FCP_ICMND64_CR;
+		cmd->un.fcpi.fcpi_parm = 0;
+		fcp_cmnd->fcpCntl3 = 0;
+
+		phba->fc4ControlRequests++;
+	}
+
+	bpl->addrHigh = 0;
+	bpl->addrLow = 0;
+	bpl->tus.w = 0;
+	if (num_bmps == 1) {
+		cmd->un.fcpi64.bdl.bdeSize +=
+			(num_bde * sizeof (struct ulp_bde64));
+	} else {
+		topbpl->tus.f.bdeSize = (num_bde * sizeof (struct ulp_bde64));
+		topbpl->tus.w = le32_to_cpu(topbpl->tus.w);
+	}
+	cmd->ulpBdeCount = 1;
+	cmd->ulpLe = 1;		/* Set the LE bit in the iocb */
+
+	/* set the Data Length field in the FCP CMND accordingly */
+	fcp_cmnd->fcpDl = be32_to_cpu(cmnd->request_bufflen);
+
+	return 0;
+
+error_out:
+	/*
+	 * Allocation of a chained BPL failed, unmap the sg list and return
+	 * error.  This will ultimately cause lpfc_free_scsi_buf to be called
+	 * which will handle the rest of the cleanup.  Set seg_cnt back to zero
+	 * to avoid double unmaps of the sg resources.
+	 */
+	dma_unmap_sg(&phba->pcidev->dev, sgel_begin, lpfc_cmd->seg_cnt,
+			datadir);
+	lpfc_cmd->seg_cnt = 0;
+	return 1;
+}
+
+static void
+lpfc_handle_fcp_err(struct lpfc_scsi_buf *lpfc_cmd)
+{
+	struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
+	struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd;
+	struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
+	struct lpfc_hba *phba = lpfc_cmd->scsi_hba;
+	uint32_t fcpi_parm = lpfc_cmd->cur_iocbq.iocb.un.fcpi.fcpi_parm;
+	uint32_t resp_info = fcprsp->rspStatus2;
+	uint32_t scsi_status = fcprsp->rspStatus3;
+	uint32_t host_status = DID_OK;
+	uint32_t rsplen = 0;
+
+	/*
+	 *  If this is a task management command, there is no
+	 *  scsi packet associated with this lpfc_cmd.  The driver
+	 *  consumes it.
+	 */
+	if (fcpcmd->fcpCntl2) {
+		scsi_status = 0;
+		goto out;
+	}
+
+	lpfc_printf_log(phba, KERN_WARNING, LOG_FCP,
+			"%d:0730 FCP command failed: RSP "
+			"Data: x%x x%x x%x x%x x%x x%x\n",
+			phba->brd_no, resp_info, scsi_status,
+			be32_to_cpu(fcprsp->rspResId),
+			be32_to_cpu(fcprsp->rspSnsLen),
+			be32_to_cpu(fcprsp->rspRspLen),
+			fcprsp->rspInfo3);
+
+	if (resp_info & RSP_LEN_VALID) {
+		rsplen = be32_to_cpu(fcprsp->rspRspLen);
+		if ((rsplen != 0 && rsplen != 4 && rsplen != 8) ||
+		    (fcprsp->rspInfo3 != RSP_NO_FAILURE)) {
+			host_status = DID_ERROR;
+			goto out;
+		}
+	}
+
+	if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) {
+		uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen);
+		if (snslen > SCSI_SENSE_BUFFERSIZE)
+			snslen = SCSI_SENSE_BUFFERSIZE;
+
+		memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen);
+	}
+
+	cmnd->resid = 0;
+	if (resp_info & RESID_UNDER) {
+		cmnd->resid = be32_to_cpu(fcprsp->rspResId);
+
+		lpfc_printf_log(phba, KERN_INFO, LOG_FCP,
+				"%d:0716 FCP Read Underrun, expected %d, "
+				"residual %d Data: x%x x%x x%x\n", phba->brd_no,
+				be32_to_cpu(fcpcmd->fcpDl), cmnd->resid,
+				fcpi_parm, cmnd->cmnd[0], cmnd->underflow);
+
+		/*
+		 * The cmnd->underflow is the minimum number of bytes that must
+		 * be transfered for this command.  Provided a sense condition is
+		 * not present, make sure the actual amount transferred is at
+		 * least the underflow value or fail.
+		 */
+		if (!(resp_info & SNS_LEN_VALID) &&
+		    (scsi_status == SAM_STAT_GOOD) &&
+		    (cmnd->request_bufflen - cmnd->resid) < cmnd->underflow) {
+			lpfc_printf_log(phba, KERN_INFO, LOG_FCP,
+					"%d:0717 FCP command x%x residual "
+					"underrun converted to error "
+					"Data: x%x x%x x%x\n", phba->brd_no,
+					cmnd->cmnd[0], cmnd->request_bufflen,
+					cmnd->resid, cmnd->underflow);
+
+			host_status = DID_ERROR;
+		}
+	} else if (resp_info & RESID_OVER) {
+		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP,
+				"%d:0720 FCP command x%x residual "
+				"overrun error. Data: x%x x%x \n",
+				phba->brd_no, cmnd->cmnd[0],
+				cmnd->request_bufflen, cmnd->resid);
+		host_status = DID_ERROR;
+
+	/*
+	 * Check SLI validation that all the transfer was actually done
+	 * (fcpi_parm should be zero). Apply check only to reads.
+	 */
+	} else if ((scsi_status == SAM_STAT_GOOD) && fcpi_parm &&
+			(cmnd->sc_data_direction == DMA_FROM_DEVICE)) {
+		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP,
+			"%d:0734 FCP Read Check Error Data: "
+			"x%x x%x x%x x%x\n", phba->brd_no,
+			be32_to_cpu(fcpcmd->fcpDl),
+			be32_to_cpu(fcprsp->rspResId),
+			fcpi_parm, cmnd->cmnd[0]);
+		host_status = DID_ERROR;
+		cmnd->resid = cmnd->request_bufflen;
+	}
+
+ out:
+	cmnd->result = ScsiResult(host_status, scsi_status);
+}
+
+void
+lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
+			struct lpfc_iocbq *pIocbOut)
+{
+	int depth, pend_cnt;
+	struct lpfc_scsi_buf *lpfc_cmd =
+		(struct lpfc_scsi_buf *) pIocbIn->context1;
+	struct lpfc_target *target = lpfc_cmd->target;
+	struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
+	struct scsi_device *sdev;
+	int result;
+
+	lpfc_cmd->result = pIocbOut->iocb.un.ulpWord[4];
+	lpfc_cmd->status = pIocbOut->iocb.ulpStatus;
+
+	target->iodonecnt++;
+
+	if (lpfc_cmd->status) {
+		target->errorcnt++;
+
+		if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
+		    (lpfc_cmd->result & IOERR_DRVR_MASK))
+			lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
+		else if (lpfc_cmd->status >= IOSTAT_CNT)
+			lpfc_cmd->status = IOSTAT_DEFAULT;
+
+		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP,
+				"%d:0729 FCP cmd x%x failed <%d/%d> status: "
+				"x%x result: x%x Data: x%x x%x\n",
+				phba->brd_no, cmd->cmnd[0], cmd->device->id,
+				cmd->device->lun, lpfc_cmd->status,
+				lpfc_cmd->result, pIocbOut->iocb.ulpContext,
+				lpfc_cmd->cur_iocbq.iocb.ulpIoTag);
+
+		switch (lpfc_cmd->status) {
+		case IOSTAT_FCP_RSP_ERROR:
+			/* Call FCP RSP handler to determine result */
+			lpfc_handle_fcp_err(lpfc_cmd);
+			break;
+		case IOSTAT_NPORT_BSY:
+		case IOSTAT_FABRIC_BSY:
+			cmd->result = ScsiResult(DID_BUS_BUSY, 0);
+			break;
+		case IOSTAT_LOCAL_REJECT:
+			if (lpfc_cmd->result == IOERR_LOOP_OPEN_FAILURE)
+				lpfc_discq_post_event(phba, target->pnode,
+						      NULL,
+						      LPFC_EVT_OPEN_LOOP);
+			cmd->result = ScsiResult(DID_ERROR, 0);
+			break;
+		default:
+			cmd->result = ScsiResult(DID_ERROR, 0);
+			break;
+		}
+
+		if (target->pnode) {
+			if(target->pnode->nlp_state != NLP_STE_MAPPED_NODE)
+				cmd->result = ScsiResult(DID_BUS_BUSY,
+					SAM_STAT_BUSY);
+		}
+		else {
+			cmd->result = ScsiResult(DID_NO_CONNECT, 0);
+		}
+	} else {
+		cmd->result = ScsiResult(DID_OK, 0);
+	}
+
+	if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) {
+		uint32_t *lp = (uint32_t *)cmd->sense_buffer;
+
+		lpfc_printf_log(phba, KERN_INFO, LOG_FCP,
+				"%d:0710 Iodone <%d/%d> cmd %p, error x%x "
+				"SNS x%x x%x Data: x%x x%x\n",
+				phba->brd_no, cmd->device->id,
+				cmd->device->lun, cmd, cmd->result,
+				*lp, *(lp + 3), cmd->retries, cmd->resid);
+	}
+
+	result = cmd->result;
+	sdev = cmd->device;
+
+	lpfc_free_scsi_buf(lpfc_cmd);
+	cmd->host_scribble = NULL;
+	cmd->scsi_done(cmd);
+
+	/*
+	 * Check for queue full.  If the lun is reporting queue full, then
+	 * back off the lun queue depth to prevent target overloads.
+	 */
+	if (result == SAM_STAT_TASK_SET_FULL) {
+		pend_cnt = lpfc_sli_sum_iocb_lun(phba,
+				&phba->sli.ring[phba->sli.fcp_ring],
+				sdev->id, sdev->lun);
+
+		spin_unlock_irq(phba->host->host_lock);
+		depth = scsi_track_queue_full(sdev, pend_cnt);
+		spin_lock_irq(phba->host->host_lock);
+	
+		if (depth) {
+			lpfc_printf_log(phba, KERN_WARNING, LOG_FCP,
+				"%d:0711 detected queue full - lun queue depth "
+				" adjusted to %d.\n", phba->brd_no, depth);
+		}			
+	}
+}
+
+static int
+lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_hba *phba,
+			     struct lpfc_scsi_buf *lpfc_cmd,
+			     uint8_t task_mgmt_cmd)
+{
+
+	struct lpfc_sli *psli;
+	struct lpfc_iocbq *piocbq;
+	IOCB_t *piocb;
+	struct fcp_cmnd *fcp_cmnd;
+	struct lpfc_nodelist *ndlp = lpfc_cmd->target->pnode;
+
+	if ((ndlp == 0) || (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
+		return 0;
+	}
+
+	/* allocate an iocb command */
+	psli = &phba->sli;
+	piocbq = &(lpfc_cmd->cur_iocbq);
+	piocb = &piocbq->iocb;
+
+
+	fcp_cmnd = lpfc_cmd->fcp_cmnd;
+	putLunHigh(fcp_cmnd->fcpLunMsl, lpfc_cmd->lun);
+	putLunLow(fcp_cmnd->fcpLunLsl, lpfc_cmd->lun)
+	fcp_cmnd->fcpCntl2 = task_mgmt_cmd;
+	fcp_cmnd->fcpCntl3 = 0;
+
+	piocb->ulpCommand = CMD_FCP_ICMND64_CR;
+
+	piocb->ulpContext = ndlp->nlp_rpi;
+	if (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
+		piocb->ulpFCP2Rcvy = 1;
+	}
+	piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f);
+
+	/* ulpTimeout is only one byte */
+	if (lpfc_cmd->timeout > 0xff) {
+		/*
+		 * Do not timeout the command at the firmware level.
+		 * The driver will provide the timeout mechanism.
+		 */
+		piocb->ulpTimeout = 0;
+	} else {
+		piocb->ulpTimeout = lpfc_cmd->timeout;
+	}
+
+	switch (task_mgmt_cmd) {
+	case FCP_LUN_RESET:
+		/* Issue LUN Reset to TGT <num> LUN <num> */
+		lpfc_printf_log(phba,
+				KERN_INFO,
+				LOG_FCP,
+				"%d:0703 Issue LUN Reset to TGT %d LUN %d "
+				"Data: x%x x%x\n",
+				phba->brd_no,
+				lpfc_cmd->target->scsi_id, lpfc_cmd->lun,
+				ndlp->nlp_rpi, ndlp->nlp_flag);
+
+		break;
+	case FCP_ABORT_TASK_SET:
+		/* Issue Abort Task Set to TGT <num> LUN <num> */
+		lpfc_printf_log(phba,
+				KERN_INFO,
+				LOG_FCP,
+				"%d:0701 Issue Abort Task Set to TGT %d LUN %d "
+				"Data: x%x x%x\n",
+				phba->brd_no,
+				lpfc_cmd->target->scsi_id, lpfc_cmd->lun,
+				ndlp->nlp_rpi, ndlp->nlp_flag);
+
+		break;
+	case FCP_TARGET_RESET:
+		/* Issue Target Reset to TGT <num> */
+		lpfc_printf_log(phba,
+				KERN_INFO,
+				LOG_FCP,
+				"%d:0702 Issue Target Reset to TGT %d "
+				"Data: x%x x%x\n",
+				phba->brd_no,
+				lpfc_cmd->target->scsi_id, ndlp->nlp_rpi,
+				ndlp->nlp_flag);
+		break;
+	}
+
+	return (1);
+}
+
+static int
+lpfc_scsi_tgt_reset(struct lpfc_target * target, int id, struct lpfc_hba * phba)
+{
+	struct lpfc_iocbq *piocbq, *piocbqrsp;
+	struct lpfc_scsi_buf * lpfc_cmd;
+	struct lpfc_sli *psli = &phba->sli;
+	int ret, retval = FAILED;
+
+	lpfc_cmd = lpfc_get_scsi_buf(phba, GFP_ATOMIC);
+	if (!lpfc_cmd)
+		goto out;
+
+	/*
+	 * The driver cannot count on any meaningful timeout value in the scsi
+	 * command.  The timeout is chosen to be twice the ratov plus a window.
+	 */
+	lpfc_cmd->timeout  = (2 * phba->fc_ratov) + 3;
+	lpfc_cmd->target = target;
+	lpfc_cmd->lun = 0;
+
+	ret = lpfc_scsi_prep_task_mgmt_cmd(phba, lpfc_cmd, FCP_TARGET_RESET);
+	if (!ret)
+		goto out_free_scsi_buf;
+
+	piocbq = &lpfc_cmd->cur_iocbq;
+	piocbq->context1 = lpfc_cmd;
+
+	piocbqrsp = mempool_alloc(phba->iocb_mem_pool, GFP_ATOMIC);
+	if (!piocbqrsp)
+		goto out_free_scsi_buf;
+
+	/* First flush all outstanding commands on the txq for the target */
+	lpfc_sli_abort_iocb_tgt(phba, &phba->sli.ring[phba->sli.fcp_ring],
+				lpfc_cmd->target->scsi_id, LPFC_ABORT_TXQ);
+
+	memset(piocbqrsp, 0, sizeof (struct lpfc_iocbq));
+
+	piocbq->iocb_flag |= LPFC_IO_POLL;
+
+	ret = lpfc_sli_issue_iocb_wait_high_priority(phba,
+		     &phba->sli.ring[psli->fcp_ring],
+		     piocbq, SLI_IOCB_HIGH_PRIORITY,
+		     piocbqrsp);
+	if (ret != IOCB_SUCCESS) {
+		lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
+		retval = FAILED;
+	} else {
+		lpfc_cmd->result = piocbqrsp->iocb.un.ulpWord[4];
+		lpfc_cmd->status = piocbqrsp->iocb.ulpStatus;
+		if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
+			(lpfc_cmd->result & IOERR_DRVR_MASK))
+				lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
+		retval = SUCCESS;
+	}
+
+	/* At this point in time, target reset completion, all outstanding
+	 * txcmplq I/Os should have been aborted by the target.
+	 * Unfortunately, all targets do not abide by this so we need
+	 * to help it out a bit.
+	 */
+	lpfc_sli_abort_iocb_tgt(phba, &phba->sli.ring[phba->sli.fcp_ring],
+				lpfc_cmd->target->scsi_id, LPFC_ABORT_ALLQ);
+
+	/*
+	 * If the IOCB failed then free the memory resources.  Otherwise,
+	 * the resources will be freed up by the completion handler.
+	 */
+	if (ret == IOCB_TIMEDOUT)
+		goto out;
+
+	mempool_free(piocbqrsp, phba->iocb_mem_pool);
+
+out_free_scsi_buf:
+	lpfc_free_scsi_buf(lpfc_cmd);
+out:
+	return retval;
+}
+
+
+#define LPFC_RESET_WAIT  2
+int
+lpfc_reset_bus_handler(struct scsi_cmnd *cmnd)
+{
+	struct Scsi_Host *shost = cmnd->device->host;
+	struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata[0];
+	int ret = FAILED, i, err_count = 0;
+	struct lpfc_target *target;
+	int cnt, loopcnt;
+
+	/*
+	 * Since the driver manages a single bus device, reset all
+	 * targets known to the driver.  Should any target reset
+	 * fail, this routine returns failure to the midlayer.
+	 */
+	for (i = 0; i < MAX_FCP_TARGET; i++) {
+		target = phba->device_queue_hash[i];
+		if (!target)
+			continue;
+
+		ret = lpfc_scsi_tgt_reset(target, i, phba);
+		if (ret != SUCCESS) {
+			lpfc_printf_log(phba, KERN_INFO, LOG_FCP,
+				"%d:0712 Bus Reset on target %d failed\n",
+				phba->brd_no, i);
+			err_count++;
+		}
+	}
+
+	loopcnt = 0;
+	while((cnt = lpfc_sli_sum_iocb_host(phba,
+				&phba->sli.ring[phba->sli.fcp_ring]))) {
+		spin_unlock_irq(phba->host->host_lock);
+		set_current_state(TASK_UNINTERRUPTIBLE);
+		schedule_timeout(LPFC_RESET_WAIT*HZ);
+		spin_lock_irq(phba->host->host_lock);
+
+		if (++loopcnt
+		    > (2 * phba->cfg_nodev_tmo)/LPFC_RESET_WAIT)
+			break;
+	}
+
+	if (cnt) {
+		/* flush all outstanding commands on the host */
+		i = lpfc_sli_abort_iocb_host(phba,
+				&phba->sli.ring[phba->sli.fcp_ring],
+				LPFC_ABORT_ALLQ);
+
+		lpfc_printf_log(phba, KERN_INFO, LOG_FCP,
+		   "%d:0715 Bus Reset I/O flush failure: cnt x%x left x%x\n",
+		   phba->brd_no, cnt, i);
+	}
+
+	if (!err_count)
+		ret = SUCCESS;
+	else
+		ret = FAILED;
+
+	lpfc_printf_log(phba,
+			KERN_ERR,
+			LOG_FCP,
+			"%d:0714 SCSI layer issued Bus Reset Data: x%x\n",
+			phba->brd_no, ret);
+
+	return ret;
+}
+
+
+int
+lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
+{
+	struct lpfc_hba *phba =
+		(struct lpfc_hba *) cmnd->device->host->hostdata[0];
+	struct lpfc_sli *psli = &phba->sli;
+	struct lpfc_target *targetp = cmnd->device->hostdata;
+	struct lpfc_nodelist *ndlp;
+	struct lpfc_iocbq *piocbq;
+	struct lpfc_scsi_buf *lpfc_cmd;
+	IOCB_t *piocb;
+	int err = 0;
+	uint16_t nlp_state;
+
+	targetp->qcmdcnt++;
+
+	/*
+	 * The target pointer is guaranteed not to be NULL because the driver
+	 * only clears the device->hostdata field in lpfc_slave_destroy.  This
+	 * approach guarantees no further IO calls on this target.
+	 */
+	ndlp =  targetp->pnode;
+	if (!ndlp) {
+		cmnd->result = ScsiResult(DID_NO_CONNECT, 0);
+		goto out_fail_command;
+	}
+
+	nlp_state = ndlp->nlp_state;
+
+	/*
+	 * A Fibre Channel is present and functioning only when the node state
+	 * is MAPPED.  Any other state is a failure.
+	 */
+	if (nlp_state != NLP_STE_MAPPED_NODE) {
+		if ((nlp_state == NLP_STE_UNMAPPED_NODE) ||
+		    (nlp_state == NLP_STE_UNUSED_NODE)) {
+			cmnd->result = ScsiResult(DID_NO_CONNECT, 0);
+			goto out_fail_command;
+		}
+		/*
+		 * The device is most likely recovered and the driver
+		 * needs a bit more time to finish.  Ask the midlayer
+		 * to retry.
+		 */
+		goto out_host_busy;
+	}
+
+	lpfc_cmd = lpfc_get_scsi_buf(phba, GFP_ATOMIC);
+	if (!lpfc_cmd)
+		goto out_host_busy;
+
+	/*
+	 * Store the midlayer's command structure for the completion phase
+	 * and complete the command initialization.
+	 */
+	cmnd->scsi_done = done;
+	cmnd->host_scribble = (unsigned char *)lpfc_cmd;
+
+	lpfc_cmd->target = targetp;
+	lpfc_cmd->lun = cmnd->device->lun;
+	lpfc_cmd->timeout = 0;
+	lpfc_cmd->pCmd = cmnd;
+	putLunHigh(lpfc_cmd->fcp_cmnd->fcpLunMsl, lpfc_cmd->lun);
+	putLunLow(lpfc_cmd->fcp_cmnd->fcpLunLsl, lpfc_cmd->lun);
+
+	err = lpfc_os_prep_io(phba, lpfc_cmd);
+	if (err)
+		goto out_host_busy_free_buf;
+
+	piocbq = &(lpfc_cmd->cur_iocbq);
+	piocb = &piocbq->iocb;
+	piocb->ulpTimeout = lpfc_cmd->timeout;
+	piocbq->context1 = lpfc_cmd;
+	piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
+
+	piocbq->iocb.ulpContext = ndlp->nlp_rpi;
+	if (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
+		piocbq->iocb.ulpFCP2Rcvy = 1;
+	}
+
+	piocbq->iocb.ulpClass = (ndlp->nlp_fcp_info & 0x0f);
+
+	err = lpfc_sli_issue_iocb(phba, &phba->sli.ring[psli->fcp_ring], piocbq,
+				 SLI_IOCB_RET_IOCB);
+	if (err)
+		goto out_host_busy_free_buf;
+	return 0;
+
+ out_host_busy_free_buf:
+	lpfc_free_scsi_buf(lpfc_cmd);
+	cmnd->host_scribble = NULL;
+ out_host_busy:
+	targetp->iodonecnt++;
+	targetp->errorcnt++;
+	return SCSI_MLQUEUE_HOST_BUSY;
+
+ out_fail_command:
+	targetp->iodonecnt++;
+	targetp->errorcnt++;
+	done(cmnd);
+	return 0;
+}
+
+int
+lpfc_reset_lun_handler(struct scsi_cmnd *cmnd)
+{
+	struct Scsi_Host *shost = cmnd->device->host;
+	struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata[0];
+	struct lpfc_sli *psli = &phba->sli;
+	struct lpfc_scsi_buf *lpfc_cmd;
+	struct lpfc_iocbq *piocbq, *piocbqrsp = NULL;
+	struct lpfc_target *target = cmnd->device->hostdata;
+	int ret, retval = FAILED;
+	int cnt, loopcnt;
+
+	/*
+	 * If target is not in a MAPPED state, delay the reset till
+	 * target is rediscovered or nodev timeout is fired.
+	 */
+	while ( 1 ) {
+		if (!target->pnode)
+			break;
+
+		if (target->pnode->nlp_state != NLP_STE_MAPPED_NODE) {
+			spin_unlock_irq(phba->host->host_lock);
+			set_current_state(TASK_UNINTERRUPTIBLE);
+			schedule_timeout( HZ/2);
+			spin_lock_irq(phba->host->host_lock);
+		}
+		if ((target->pnode) &&
+		    (target->pnode->nlp_state == NLP_STE_MAPPED_NODE))
+			break;
+	}
+
+	lpfc_cmd = lpfc_get_scsi_buf(phba, GFP_ATOMIC);
+	if (!lpfc_cmd)
+		goto out;
+
+	lpfc_cmd->timeout = 60; /* set command timeout to 60 seconds */
+	lpfc_cmd->scsi_hba = phba;
+	lpfc_cmd->target = target;
+	lpfc_cmd->lun = cmnd->device->lun;
+
+	ret = lpfc_scsi_prep_task_mgmt_cmd(phba, lpfc_cmd, FCP_LUN_RESET);
+	if (!ret)
+		goto out_free_scsi_buf;
+
+	piocbq = &lpfc_cmd->cur_iocbq;
+	piocbq->context1 = lpfc_cmd;
+
+	/* get a buffer for this IOCB command response */
+	piocbqrsp = mempool_alloc(phba->iocb_mem_pool, GFP_ATOMIC);
+	if(!piocbqrsp)
+		goto out_free_scsi_buf;
+
+	/* First flush all outstanding commands on the txq for the lun */
+	lpfc_sli_abort_iocb_lun(phba,
+				&phba->sli.ring[phba->sli.fcp_ring],
+				cmnd->device->id,
+				cmnd->device->lun, LPFC_ABORT_TXQ);
+
+	memset(piocbqrsp, 0, sizeof (struct lpfc_iocbq));
+
+	piocbq->iocb_flag |= LPFC_IO_POLL;
+
+	ret = lpfc_sli_issue_iocb_wait_high_priority(phba,
+		     &phba->sli.ring[psli->fcp_ring],
+		     piocbq, 0,
+		     piocbqrsp);
+	if (ret == IOCB_SUCCESS)
+		retval = SUCCESS;
+
+	lpfc_cmd->result = piocbqrsp->iocb.un.ulpWord[4];
+	lpfc_cmd->status = piocbqrsp->iocb.ulpStatus;
+	if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT)
+		if (lpfc_cmd->result & IOERR_DRVR_MASK)
+			lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
+
+	/* At this point in time, lun reset completion, all outstanding
+	 * txcmplq I/Os should have been aborted by the target.
+	 * Unfortunately, all targets do not abide by this so we need
+	 * to help it out a bit.
+	 */
+	lpfc_sli_abort_iocb_lun(phba,
+				&phba->sli.ring[phba->sli.fcp_ring],
+				cmnd->device->id,
+				cmnd->device->lun, LPFC_ABORT_ALLQ);
+
+	loopcnt = 0;
+	while((cnt = lpfc_sli_sum_iocb_lun(phba,
+				&phba->sli.ring[phba->sli.fcp_ring],
+				cmnd->device->id,
+				cmnd->device->lun))) {
+		spin_unlock_irq(phba->host->host_lock);
+		set_current_state(TASK_UNINTERRUPTIBLE);
+		schedule_timeout(LPFC_RESET_WAIT*HZ);
+		spin_lock_irq(phba->host->host_lock);
+
+		if (++loopcnt
+		    > (2 * phba->cfg_nodev_tmo)/LPFC_RESET_WAIT)
+			break;
+	}
+
+	if(cnt) {
+		lpfc_printf_log(phba, KERN_INFO, LOG_FCP,
+			"%d:0719 LUN Reset I/O flush failure: cnt x%x\n",
+			phba->brd_no, cnt);
+	}
+
+	lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
+			"%d:0713 SCSI layer issued LUN reset (%d, %d) "
+			"Data: x%x x%x x%x\n",
+			phba->brd_no, lpfc_cmd->target->scsi_id,
+			lpfc_cmd->lun, ret, lpfc_cmd->status,
+			lpfc_cmd->result);
+
+	if (ret == IOCB_TIMEDOUT)
+		goto out;
+
+	mempool_free(piocbqrsp, phba->iocb_mem_pool);
+
+out_free_scsi_buf:
+	lpfc_free_scsi_buf(lpfc_cmd);
+out:
+	return retval;
+}
+
+static void
+lpfc_scsi_cmd_iocb_cleanup (struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
+                            struct lpfc_iocbq *pIocbOut)
+{
+        struct lpfc_scsi_buf *lpfc_cmd =
+                (struct lpfc_scsi_buf *) pIocbIn->context1;
+	struct scsi_cmnd *ml_cmd =
+		((struct lpfc_scsi_buf *) pIocbIn->context1)->pCmd;
+	struct lpfc_target *targetp = ml_cmd->device->hostdata;
+
+	if (targetp) {
+		targetp->iodonecnt++;
+		targetp->errorcnt++;
+	}
+        lpfc_free_scsi_buf(lpfc_cmd);
+}
+
+static void
+lpfc_scsi_cmd_iocb_cmpl_aborted (struct lpfc_hba *phba, 
+				 struct lpfc_iocbq *pIocbIn,
+				 struct lpfc_iocbq *pIocbOut)
+{
+	struct scsi_cmnd *ml_cmd =
+		((struct lpfc_scsi_buf *) pIocbIn->context1)->pCmd;
+
+	lpfc_scsi_cmd_iocb_cleanup (phba, pIocbIn, pIocbOut);
+	ml_cmd->host_scribble = NULL;
+}
+
+#define LPFC_ABORT_WAIT  2
+int
+lpfc_abort_handler(struct scsi_cmnd *cmnd)
+{
+	struct lpfc_hba *phba =
+			(struct lpfc_hba *)cmnd->device->host->hostdata[0];
+	struct lpfc_sli_ring *pring = &phba->sli.ring[phba->sli.fcp_ring];
+	struct lpfc_iocbq *iocb, *next_iocb, *abtsiocbp;
+	struct lpfc_scsi_buf *lpfc_cmd;
+	IOCB_t *cmd, *icmd;
+	unsigned long snum;
+	unsigned int id, lun;
+	unsigned int loop_count = 0;
+	int ret = IOCB_SUCCESS;
+
+	/*
+	 * If the host_scribble data area is NULL, then the driver has already
+	 * completed this command, but the midlayer did not see the completion
+	 * before the eh fired.  Just return SUCCESS.
+	 */	
+	lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble;
+	if (!lpfc_cmd)
+       		return SUCCESS;
+
+	/* save these now since lpfc_cmd can be freed */
+	id   = lpfc_cmd->target->scsi_id;
+	lun  = lpfc_cmd->lun;
+	snum = cmnd->serial_number;
+
+	/* Search the txq first. */
+	list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
+		cmd = &iocb->iocb;
+		if (iocb->context1 != lpfc_cmd)
+			continue;
+
+		list_del_init(&iocb->list);
+		pring->txq_cnt--;
+		if (!iocb->iocb_cmpl) {
+			mempool_free(iocb, phba->iocb_mem_pool);
+		}
+		else {
+			cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
+			cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
+			lpfc_scsi_cmd_iocb_cmpl_aborted(phba, iocb, iocb);
+		}
+       		goto out;
+	}
+
+	abtsiocbp = mempool_alloc(phba->iocb_mem_pool, GFP_ATOMIC);
+	if (!abtsiocbp)
+		goto out;
+	memset(abtsiocbp, 0, sizeof (struct lpfc_iocbq));
+
+	/*
+	 * The scsi command was not in the txq.  Check the txcmplq and if it is
+	 * found, send an abort to the FW.
+	 */
+	list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
+		if (iocb->context1 != lpfc_cmd)
+			continue;
+
+		iocb->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl_aborted;
+		cmd = &iocb->iocb;
+		icmd = &abtsiocbp->iocb;
+		icmd->un.acxri.abortType = ABORT_TYPE_ABTS;
+		icmd->un.acxri.abortContextTag = cmd->ulpContext;
+		icmd->un.acxri.abortIoTag = cmd->ulpIoTag;
+
+		icmd->ulpLe = 1;
+		icmd->ulpClass = cmd->ulpClass;
+		abtsiocbp->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
+		if (phba->hba_state >= LPFC_LINK_UP)
+			icmd->ulpCommand = CMD_ABORT_XRI_CN;
+		else
+			icmd->ulpCommand = CMD_CLOSE_XRI_CN;
+
+		if (lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0) ==
+								IOCB_ERROR) {
+			mempool_free(abtsiocbp, phba->iocb_mem_pool);
+			ret = IOCB_ERROR;
+			break;
+		}
+
+		/* Wait for abort to complete */
+		while (cmnd->host_scribble)
+		{
+			spin_unlock_irq(phba->host->host_lock);
+			set_current_state(TASK_UNINTERRUPTIBLE);
+			schedule_timeout(LPFC_ABORT_WAIT*HZ);
+			spin_lock_irq(phba->host->host_lock);
+			if (++loop_count
+			    > (2 * phba->cfg_nodev_tmo)/LPFC_ABORT_WAIT)
+				break;
+		}
+
+		if (cmnd->host_scribble) {
+			lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
+					"%d:0748 abort handler timed "
+					"out waiting for abort to "
+					"complete. Data: "
+					"x%x x%x x%x x%lx\n",
+					phba->brd_no, ret, id, lun, snum);
+			cmnd->host_scribble = NULL;
+			iocb->iocb_cmpl = lpfc_scsi_cmd_iocb_cleanup;
+			ret = IOCB_ERROR;
+		}
+
+		break;
+	}
+
+ out:
+	lpfc_printf_log(phba, KERN_WARNING, LOG_FCP,
+			"%d:0749 SCSI layer issued abort device "
+			"Data: x%x x%x x%x x%lx\n",
+			phba->brd_no, ret, id, lun, snum);
+
+	return (ret == IOCB_SUCCESS ? SUCCESS : FAILED);
+}
+
+#if defined(RHEL_FC) || defined(SLES_FC)
+void
+lpfc_target_unblock(struct lpfc_hba *phba, struct lpfc_target *targetp)
+{
+#if defined(RHEL_FC)
+	/*
+	 * This code to be removed once block/unblock and the new
+	 * dicovery state machine are fully debugged.
+	 */
+	if (!targetp || !targetp->starget) {
+#else /* not RHEL_FC -> is SLES_FC */
+	if (!targetp) {
+#endif
+		lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY | LOG_FCP,
+			"%d:0262 Cannot unblock scsi target\n", phba->brd_no);
+
+		return;
+	}
+
+	/* Unblock IO to target scsi id <sid> to NPort <nlp_DID> */
+	lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY | LOG_FCP,
+			"%d:0258 Unblocking IO to Target scsi id x%x  "
+			"NPort pointer x%p\n",
+			phba->brd_no, targetp->scsi_id, targetp->pnode);
+
+	spin_unlock_irq(phba->host->host_lock);
+
+#if defined(RHEL_FC)
+	fc_target_unblock(targetp->starget);
+#else /* not RHEL_FC -> is SLES_FC */
+	fc_target_unblock(phba->host, targetp->scsi_id,
+			  &targetp->dev_loss_timer);
+#endif
+	spin_lock_irq(phba->host->host_lock);
+	targetp->blocked--;
+}
+
+void
+lpfc_target_block(struct lpfc_hba *phba, struct lpfc_target *targetp)
+{
+#if defined(RHEL_FC)
+	/*
+	 * This code to be removed once block/unblock and the new
+	 * dicovery state machine are fully debugged.
+	 */
+	if (!targetp || !targetp->starget) {
+#else /* not RHEL_FC -> is SLES_FC */
+	if (!targetp) {
+#endif
+		lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY | LOG_FCP,
+				"%d:0263 Cannot block scsi target."
+				" target ptr x%p\n",
+				phba->brd_no, targetp);
+		return;
+	}
+
+	/* Block all IO to target scsi id <sid> to NPort <nlp_DID> */
+	lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY | LOG_FCP,
+			"%d:0259 Blocking IO to Target scsi id x%x"
+			" NPort pointer x%p\n",
+			phba->brd_no, targetp->scsi_id, targetp->pnode);
+
+	spin_unlock_irq(phba->host->host_lock);
+#if defined(RHEL_FC)
+	fc_target_block(targetp->starget);
+#else /* not RHEL_FC -> is SLES_FC */
+	fc_target_block(phba->host, targetp->scsi_id, &targetp->dev_loss_timer,
+			phba->cfg_nodev_tmo);
+
+	/*
+	 * Kill the midlayer unblock timer, but leave the target blocked.
+	 * The driver will unblock with the nodev_tmo callback function.
+	 */
+	del_timer_sync(&targetp->dev_loss_timer);
+#endif
+	spin_lock_irq(phba->host->host_lock);
+	targetp->blocked++;
+}
+
+int
+lpfc_target_remove(struct lpfc_hba *phba, struct lpfc_target *targetp)
+{
+	struct scsi_device *sdev;
+	struct Scsi_Host   *shost = phba->host;
+
+	/* This is only called if scsi target (targetp->starget) is valid */
+	lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY | LOG_FCP,
+			"%d:0260 Remove Target scsi id x%x\n",
+			phba->brd_no, targetp->scsi_id);
+
+	/* If this target is blocked, we must unblock it first */
+	if (targetp->blocked)
+		lpfc_target_unblock(phba, targetp);
+
+	/* Remove all associated devices for this target */
+	if (phba->cfg_scsi_hotplug) {
+top:
+		list_for_each_entry(sdev, &shost->__devices, siblings) {
+			if (sdev->channel == 0
+			    && sdev->id == targetp->scsi_id) {
+				spin_unlock_irq(shost->host_lock);
+				scsi_device_get(sdev);
+				scsi_remove_device(sdev);
+				scsi_device_put(sdev);
+				spin_lock_irq(shost->host_lock);
+				goto top;
+			}
+		}
+	}
+
+	return 0;
+}
+
+int
+lpfc_target_add(struct lpfc_hba *phba, struct lpfc_target *targetp)
+{
+	/* If the driver is not supporting scsi hotplug, just exit. */
+	if(!phba->cfg_scsi_hotplug)
+		return 1;
+
+	/* This is only called if scsi target (targetp->starget) is valid */
+
+	lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY | LOG_FCP,
+			"%d:0261 Adding Target scsi id x%x\n",
+			phba->brd_no, targetp->scsi_id);
+
+	/*
+	 * The driver discovered a new target.  Call the midlayer and get this
+	 * target's luns added into the device list.
+	 * Since we are going to scan the entire host, kick off a timer to
+	 * do this so we can possibly consolidate multiple target scans into
+	 * one scsi host scan.
+	 */
+	mod_timer(&phba->fc_scantmo, jiffies + HZ);
+	phba->fc_flag |= FC_SCSI_SCAN_TMO;
+	return 0;
+}
+#endif  /* RHEL_FC or SLES_FC */
--- linux-2.6.8.1-t044-driver-update//drivers/scsi/lpfc/lpfc_compat.h	1970-01-01 03:00:00.000000000 +0300
+++ rhel4u2//drivers/scsi/lpfc/lpfc_compat.h	2005-10-19 11:47:17.000000000 +0400
@@ -0,0 +1,109 @@
+/*******************************************************************
+ * This file is part of the Emulex Linux Device Driver for         *
+ * Fibre Channel Host Bus Adapters.                                *
+ * Copyright (C) 2003-2005 Emulex.  All rights reserved.           *
+ * EMULEX and SLI are trademarks of Emulex.                        *
+ * www.emulex.com                                                  *
+ *                                                                 *
+ * This program is free software; you can redistribute it and/or   *
+ * modify it under the terms of version 2 of the GNU General       *
+ * Public License as published by the Free Software Foundation.    *
+ * This program is distributed in the hope that it will be useful. *
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
+ * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
+ * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
+ * more details, a copy of which can be found in the file COPYING  *
+ * included with this package.                                     *
+ *******************************************************************/
+
+/*
+ * $Id: lpfc_compat.h 1.31.1.2 2005/06/13 17:16:04EDT sf_support Exp  $
+ *
+ * This file provides macros to aid compilation in the Linux 2.4 kernel
+ * over various platform architectures.
+ */
+
+#ifndef _H_LPFC_COMPAT
+#define  _H_LPFC_COMPAT
+
+
+/*******************************************************************
+Note: HBA's SLI memory contains little-endian LW.
+Thus to access it from a little-endian host,
+memcpy_toio() and memcpy_fromio() can be used.
+However on a big-endian host, copy 4 bytes at a time,
+using writel() and readl().
+ *******************************************************************/
+
+#if __BIG_ENDIAN
+
+static inline void
+lpfc_memcpy_to_slim( void *dest, void *src, unsigned int bytes)
+{
+	uint32_t *dest32;
+	uint32_t *src32;
+	unsigned int four_bytes;
+
+
+	dest32  = (uint32_t *) dest;
+	src32  = (uint32_t *) src;
+
+	/* write input bytes, 4 bytes at a time */
+	for (four_bytes = bytes /4; four_bytes > 0; four_bytes--) {
+		writel( *src32, dest32);
+		readl(dest32); /* flush */
+		dest32++;
+		src32++;
+	}
+
+	return;
+}
+
+static inline void
+lpfc_memcpy_from_slim( void *dest, void *src, unsigned int bytes)
+{
+	uint32_t *dest32;
+	uint32_t *src32;
+	unsigned int four_bytes;
+
+
+	dest32  = (uint32_t *) dest;
+	src32  = (uint32_t *) src;
+
+	/* read input bytes, 4 bytes at a time */
+	for (four_bytes = bytes /4; four_bytes > 0; four_bytes--) {
+		*dest32 = readl( src32);
+		dest32++;
+		src32++;
+	}
+
+	return;
+}
+
+#else
+
+static inline void
+lpfc_memcpy_to_slim( void *dest, void *src, unsigned int bytes)
+{
+	/* actually returns 1 byte past dest */
+	memcpy_toio( dest, src, bytes);
+}
+
+static inline void
+lpfc_memcpy_from_slim( void *dest, void *src, unsigned int bytes)
+{
+	/* actually returns 1 byte past dest */
+	memcpy_fromio( dest, src, bytes);
+}
+
+#endif /* __BIG_ENDIAN */
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,6)
+#define msleep(x) do { \
+			set_current_state(TASK_UNINTERRUPTIBLE); \
+			schedule_timeout((x)); \
+		} while (0);
+#endif
+#endif				/*  _H_LPFC_COMPAT */
--- linux-2.6.8.1-t044-driver-update//drivers/scsi/lpfc/lpfc_hbadisc.c	1970-01-01 03:00:00.000000000 +0300
+++ rhel4u2//drivers/scsi/lpfc/lpfc_hbadisc.c	2005-10-19 11:47:17.000000000 +0400
@@ -0,0 +1,2906 @@
+/*******************************************************************
+ * This file is part of the Emulex Linux Device Driver for         *
+ * Fibre Channel Host Bus Adapters.                                *
+ * Copyright (C) 2003-2005 Emulex.  All rights reserved.           *
+ * EMULEX and SLI are trademarks of Emulex.                        *
+ * www.emulex.com                                                  *
+ *                                                                 *
+ * This program is free software; you can redistribute it and/or   *
+ * modify it under the terms of version 2 of the GNU General       *
+ * Public License as published by the Free Software Foundation.    *
+ * This program is distributed in the hope that it will be useful. *
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
+ * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
+ * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
+ * more details, a copy of which can be found in the file COPYING  *
+ * included with this package.                                     *
+ *******************************************************************/
+
+/*
+ * $Id: lpfc_hbadisc.c 1.225.1.3 2005/07/08 19:33:24EDT sf_support Exp  $
+ */
+
+#include <linux/version.h>
+#include <linux/blkdev.h>
+#include <linux/dma-mapping.h>
+#include <linux/pci.h>
+#include <linux/spinlock.h>
+#include <linux/kernel.h>
+#include <linux/smp_lock.h>
+
+#include <scsi/scsi_cmnd.h>
+#include <scsi/scsi_device.h>
+#include <scsi/scsi_host.h>
+
+#include <scsi/scsi_transport_fc.h>
+
+#include "lpfc_sli.h"
+#include "lpfc_disc.h"
+#include "lpfc_scsi.h"
+#include "lpfc.h"
+#include "lpfc_crtn.h"
+#include "lpfc_fcp.h"
+#include "lpfc_hw.h"
+#include "lpfc_logmsg.h"
+#include "lpfc_mem.h"
+
+/* AlpaArray for assignment of scsid for scan-down and bind_method */
+uint8_t lpfcAlpaArray[] = {
+	0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
+	0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
+	0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
+	0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
+	0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
+	0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
+	0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
+	0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
+	0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
+	0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
+	0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
+	0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
+	0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
+};
+
+static void lpfc_disc_timeout_handler(struct lpfc_hba *);
+
+void
+lpfc_evt_iocb_free(struct lpfc_hba * phba, struct lpfc_iocbq * saveq)
+{
+	struct lpfc_iocbq  *rspiocbp, *tmpiocbp;
+
+	/* Free up iocb buffer chain for cmd just processed */
+	list_for_each_entry_safe(rspiocbp, tmpiocbp,
+		&saveq->list, list) {
+		list_del(&rspiocbp->list);
+		mempool_free( rspiocbp, phba->iocb_mem_pool);
+	}
+	mempool_free( saveq, phba->iocb_mem_pool);
+}
+
+void
+lpfc_process_nodev_timeout(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
+{
+	struct lpfc_target *targetp;
+	int scsid, warn_user = 0;
+
+	/* If the nodev_timeout is cancelled do nothing */
+	if (!(ndlp->nlp_flag & NLP_NODEV_TMO))
+		return;
+
+	ndlp->nlp_flag &= ~NLP_NODEV_TMO;
+
+	for(scsid=0;scsid<MAX_FCP_TARGET;scsid++) {
+		targetp = phba->device_queue_hash[scsid];
+		/* First see if the SCSI ID has an allocated struct
+		   lpfc_target */
+		if (targetp) {
+			if (targetp->pnode == ndlp) {
+				/* flush the target */
+				lpfc_sli_abort_iocb_tgt(phba,
+					&phba->sli.ring[phba->sli.fcp_ring],
+					scsid, LPFC_ABORT_ALLQ);
+				warn_user = 1;
+				break;
+			}
+		}
+	}
+
+	if (warn_user) {
+		lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
+				"%d:0203 Nodev timeout on NPort x%x "
+				"Data: x%x x%x x%x\n",
+				phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
+				ndlp->nlp_state, ndlp->nlp_rpi);
+	} else {
+		lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
+				"%d:0206 Nodev timeout on NPort x%x "
+				"Data: x%x x%x x%x\n",
+				phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
+				ndlp->nlp_state, ndlp->nlp_rpi);
+	}
+
+	lpfc_disc_state_machine(phba, ndlp, NULL, NLP_EVT_DEVICE_RM);
+	return;
+}
+
+static void
+lpfc_disc_done(struct lpfc_hba * phba)
+{
+	struct lpfc_sli *psli = &phba->sli;
+	LPFC_DISC_EVT_t  *evtp;
+	LPFC_MBOXQ_t *pmb;
+	struct lpfc_iocbq  *cmdiocbp, *saveq;
+	struct lpfc_nodelist  *ndlp;
+	LPFC_RING_MASK_t *func;
+	struct Scsi_Host *shost;
+	struct lpfc_dmabuf *mp;
+	uint32_t work_hba_events;
+	int free_evt;
+
+	work_hba_events=phba->work_hba_events;
+	spin_unlock_irq(phba->host->host_lock);
+
+	if (work_hba_events & WORKER_DISC_TMO)
+		lpfc_disc_timeout_handler(phba);
+	
+	if (work_hba_events & WORKER_ELS_TMO)
+		lpfc_els_timeout_handler(phba);
+	
+	if (work_hba_events & WORKER_MBOX_TMO)
+		lpfc_mbox_timeout_handler(phba);
+
+	if (work_hba_events & WORKER_FDMI_TMO)
+		lpfc_fdmi_tmo_handler(phba);
+
+	spin_lock_irq(phba->host->host_lock);
+	phba->work_hba_events &= ~work_hba_events;
+
+	/* check discovery event list */
+	while(!list_empty(&phba->dpc_disc)) {
+		evtp = list_entry(phba->dpc_disc.next,
+				  typeof(*evtp), evt_listp);
+		list_del_init(&evtp->evt_listp);
+		free_evt =1;
+		switch(evtp->evt) {
+		case LPFC_EVT_MBOX:
+			pmb = (LPFC_MBOXQ_t *)(evtp->evt_arg1);
+			if ( pmb->mbox_cmpl )
+				(pmb->mbox_cmpl) (phba, pmb);
+			else {
+				mp = (struct lpfc_dmabuf *) (pmb->context1);
+				if (mp) {
+					lpfc_mbuf_free(phba, mp->virt, mp->phys);
+					kfree(mp);
+				}
+				mempool_free( pmb, phba->mbox_mem_pool);
+			}
+			break;
+		case LPFC_EVT_SOL_IOCB:
+			cmdiocbp = (struct lpfc_iocbq *)(evtp->evt_arg1);
+			saveq = (struct lpfc_iocbq *)(evtp->evt_arg2);
+			(cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
+			lpfc_evt_iocb_free(phba, saveq);
+			break;
+		case LPFC_EVT_UNSOL_IOCB:
+			func = (LPFC_RING_MASK_t *)(evtp->evt_arg1);
+			saveq = (struct lpfc_iocbq *)(evtp->evt_arg2);
+			(func->lpfc_sli_rcv_unsol_event) (phba,
+	 		&psli->ring[LPFC_ELS_RING], saveq);
+			lpfc_evt_iocb_free(phba, saveq);
+			break;
+		case LPFC_EVT_NODEV_TMO:
+			free_evt = 0;
+			ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
+			lpfc_process_nodev_timeout(phba, ndlp);
+			break;
+		case LPFC_EVT_ELS_RETRY:
+			ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
+			spin_unlock_irq(phba->host->host_lock);
+			lpfc_els_retry_delay_handler(ndlp);
+			spin_lock_irq(phba->host->host_lock);
+			free_evt = 0;
+			break;
+		case LPFC_EVT_SCAN:
+			shost = phba->host;
+			lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY | LOG_FCP,
+				"%d:0252 Rescanning scsi host\n", phba->brd_no);
+			spin_unlock_irq(shost->host_lock);
+			scsi_scan_host(shost);
+			spin_lock_irq(shost->host_lock);
+			break;
+		case LPFC_EVT_ERR_ATTN:
+			spin_unlock_irq(phba->host->host_lock);
+			lpfc_handle_eratt(phba, (unsigned long) evtp->evt_arg1);
+			spin_lock_irq(phba->host->host_lock);
+			break;
+		case LPFC_EVT_OPEN_LOOP:
+			ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
+			lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
+			ndlp->nlp_flag &= ~NLP_NPR_ADISC;
+			break;
+		}
+		if (free_evt)
+			kfree(evtp);
+	}
+}
+
+int
+lpfc_do_dpc(void *p)
+{
+	unsigned long flags;
+	DECLARE_MUTEX_LOCKED(sem);
+	struct lpfc_hba *phba = (struct lpfc_hba *)p;
+
+	lock_kernel();
+
+	daemonize("lpfc_dpc_%d", phba->brd_no);
+	allow_signal(SIGHUP);
+
+	phba->dpc_wait = &sem;
+	set_user_nice(current, -20);
+
+	unlock_kernel();
+
+	complete(&phba->dpc_startup);
+
+	while (1) {
+		if (down_interruptible(&sem))
+			break;
+
+		if (signal_pending(current))
+			break;
+
+		if (phba->dpc_kill)
+			break;
+
+		spin_lock_irqsave(phba->host->host_lock, flags);
+		lpfc_disc_done(phba);
+		spin_unlock_irqrestore(phba->host->host_lock, flags);
+	}
+
+	/* Zero out semaphore we were waiting on. */
+	phba->dpc_wait = NULL;
+	complete_and_exit(&phba->dpc_exiting, 0);
+	return(0);
+}
+
+/*
+ * This is only called to handle FC discovery events. Since this a rare
+ * occurance, we allocate an LPFC_DISC_EVT_t structure here instead of
+ * embedding it in the IOCB.
+ */
+int
+lpfc_discq_post_event(struct lpfc_hba * phba, void *arg1, void *arg2,
+		      uint32_t evt)
+{
+	LPFC_DISC_EVT_t  *evtp;
+
+	/* All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events
+	 * will be queued to DPC for processing
+	 */
+	evtp = (LPFC_DISC_EVT_t *) kmalloc(sizeof(LPFC_DISC_EVT_t), GFP_ATOMIC);
+	if (!evtp)
+		return 0;
+
+	evtp->evt_arg1  = arg1;
+	evtp->evt_arg2  = arg2;
+	evtp->evt       = evt;
+	evtp->evt_listp.next = NULL;
+	evtp->evt_listp.prev = NULL;
+
+	/* Queue the event to the DPC to be processed later */
+	list_add_tail(&evtp->evt_listp, &phba->dpc_disc);
+	if (phba->dpc_wait)
+		up(phba->dpc_wait);
+
+	return 1;
+}
+
+int
+lpfc_linkdown(struct lpfc_hba * phba)
+{
+	struct lpfc_sli       *psli;
+	struct lpfc_nodelist  *ndlp, *next_ndlp;
+	struct list_head *listp;
+	struct list_head *node_list[7];
+	LPFC_MBOXQ_t     *mb;
+	int               rc, i;
+
+	psli = &phba->sli;
+	phba->hba_state = LPFC_LINK_DOWN;
+
+#if !defined(RHEL_FC) && !defined(SLES_FC)
+	/* Stop all requests to the driver from the midlayer. */
+	scsi_block_requests(phba->host);
+#endif
+
+	lpfc_put_event(phba, HBA_EVENT_LINK_DOWN, phba->fc_myDID, NULL, 0, 0);
+
+	/* Clean up any firmware default rpi's */
+	if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC))) {
+		lpfc_unreg_did(phba, 0xffffffff, mb);
+		mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
+		if (lpfc_sli_issue_mbox(phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
+		    == MBX_NOT_FINISHED) {
+			mempool_free( mb, phba->mbox_mem_pool);
+		}
+	}
+
+	/* Cleanup any outstanding RSCN activity */
+	lpfc_els_flush_rscn(phba);
+
+	/* Cleanup any outstanding ELS commands */
+	lpfc_els_flush_cmd(phba);
+
+	/*
+	 * If this function was called by the lpfc_do_dpc, don't recurse into
+	 * the routine again.  If not, just process any outstanding
+	 * discovery events.
+	 */
+	if ((!list_empty(&phba->dpc_disc)) ||
+	    (phba->work_hba_events)){
+		lpfc_disc_done(phba);
+	}
+
+	/* Issue a LINK DOWN event to all nodes */
+	node_list[0] = &phba->fc_npr_list;  /* MUST do this list first */
+	node_list[1] = &phba->fc_nlpmap_list;
+	node_list[2] = &phba->fc_nlpunmap_list;
+	node_list[3] = &phba->fc_prli_list;
+	node_list[4] = &phba->fc_reglogin_list;
+	node_list[5] = &phba->fc_adisc_list;
+	node_list[6] = &phba->fc_plogi_list;
+	for (i = 0; i < 7; i++) {
+		listp = node_list[i];
+		if (list_empty(listp))
+			continue;
+
+		list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
+			/* Fabric nodes are not handled thru state machine for
+			   link down */
+			if (ndlp->nlp_type & NLP_FABRIC) {
+				/* Remove ALL Fabric nodes except Fabric_DID */
+				if (ndlp->nlp_DID != Fabric_DID) {
+					/* Take it off current list and free */
+					lpfc_nlp_list(phba, ndlp,
+						NLP_NO_LIST);
+				}
+			}
+			else {
+				lpfc_set_failmask(phba, ndlp,
+						  LPFC_DEV_LINK_DOWN,
+						  LPFC_SET_BITMASK);
+
+				rc = lpfc_disc_state_machine(phba, ndlp, NULL,
+						     NLP_EVT_DEVICE_RECOVERY);
+
+				/* Check config parameter use-adisc or FCP-2 */
+				if ((rc != NLP_STE_FREED_NODE) &&
+					(phba->cfg_use_adisc == 0) &&
+					!(ndlp->nlp_fcp_info &
+						NLP_FCP_2_DEVICE)) {
+					/* We know we will have to relogin, so
+					 * unreglogin the rpi right now to fail
+					 * any outstanding I/Os quickly.
+					 */
+					lpfc_unreg_rpi(phba, ndlp);
+				}
+			}
+		}
+	}
+
+	/* free any ndlp's on unused list */
+	list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
+				nlp_listp) {
+		lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
+	}
+
+	/* Setup myDID for link up if we are in pt2pt mode */
+	if (phba->fc_flag & FC_PT2PT) {
+		phba->fc_myDID = 0;
+		if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC))) {
+			lpfc_config_link(phba, mb);
+			mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
+			if (lpfc_sli_issue_mbox
+			    (phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
+			    == MBX_NOT_FINISHED) {
+				mempool_free( mb, phba->mbox_mem_pool);
+			}
+		}
+		phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
+	}
+	phba->fc_flag &= ~FC_LBIT;
+
+	/* Turn off discovery timer if its running */
+	lpfc_can_disctmo(phba);
+
+	/* Must process IOCBs on all rings to handle ABORTed I/Os */
+	return (0);
+}
+
+static int
+lpfc_linkup(struct lpfc_hba * phba)
+{
+	struct lpfc_nodelist *ndlp, *next_ndlp;
+	struct list_head *listp;
+	struct list_head *node_list[7];
+	int i;
+
+	phba->hba_state = LPFC_LINK_UP;
+	phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
+			   FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
+	phba->fc_flag |= FC_NDISC_ACTIVE;
+	phba->fc_ns_retry = 0;
+
+
+	lpfc_put_event(phba, HBA_EVENT_LINK_UP, phba->fc_myDID,
+			(void *)(unsigned long)(phba->fc_topology),
+			0, phba->fc_linkspeed);
+
+	/*
+	 * Clean up old Fabric NLP_FABRIC logins.
+	 */
+	list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpunmap_list,
+				nlp_listp) {
+		if (ndlp->nlp_DID == Fabric_DID) {
+			/* Take it off current list and free */
+			lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
+		}
+	}
+
+	/* free any ndlp's on unused list */
+	list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
+				nlp_listp) {
+		lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
+	}
+
+	/* Mark all nodes for LINK UP */
+	node_list[0] = &phba->fc_plogi_list;
+	node_list[1] = &phba->fc_adisc_list;
+	node_list[2] = &phba->fc_reglogin_list;
+	node_list[3] = &phba->fc_prli_list;
+	node_list[4] = &phba->fc_nlpunmap_list;
+	node_list[5] = &phba->fc_nlpmap_list;
+	node_list[6] = &phba->fc_npr_list;
+	for (i = 0; i < 7; i++) {
+		listp = node_list[i];
+		if (list_empty(listp))
+			continue;
+
+		list_for_each_entry(ndlp, listp, nlp_listp) {
+			lpfc_set_failmask(phba, ndlp, LPFC_DEV_DISCOVERY_INP,
+					  LPFC_SET_BITMASK);
+			lpfc_set_failmask(phba, ndlp, LPFC_DEV_LINK_DOWN,
+					  LPFC_CLR_BITMASK);
+		}
+	}
+
+#if !defined(RHEL_FC) && !defined(SLES_FC)
+	spin_unlock_irq(phba->host->host_lock);
+	scsi_unblock_requests(phba->host);
+	spin_lock_irq(phba->host->host_lock);
+#endif
+	return 0;
+}
+
+/*
+ * This routine handles processing a CLEAR_LA mailbox
+ * command upon completion. It is setup in the LPFC_MBOXQ
+ * as the completion routine when the command is
+ * handed off to the SLI layer.
+ */
+void
+lpfc_mbx_cmpl_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
+{
+	struct lpfc_sli *psli;
+	MAILBOX_t *mb;
+	uint32_t control;
+
+	psli = &phba->sli;
+	mb = &pmb->mb;
+	/* Since we don't do discovery right now, turn these off here */
+	psli->ring[psli->ip_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
+	psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
+	psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
+	/* Check for error */
+	if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
+		/* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
+		lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
+				"%d:0320 CLEAR_LA mbxStatus error x%x hba "
+				"state x%x\n",
+				phba->brd_no, mb->mbxStatus, phba->hba_state);
+
+		phba->hba_state = LPFC_HBA_ERROR;
+		goto out;
+	}
+
+	if(phba->fc_flag & FC_ABORT_DISCOVERY)
+		goto out;
+
+	phba->num_disc_nodes = 0;
+	/* go thru NPR list and issue ELS PLOGIs */
+	if (phba->fc_npr_cnt) {
+		lpfc_els_disc_plogi(phba);
+	}
+
+	if(!phba->num_disc_nodes) {
+		phba->fc_flag &= ~FC_NDISC_ACTIVE;
+	}
+
+	phba->hba_state = LPFC_HBA_READY;
+
+out:
+	phba->fc_flag &= ~FC_ABORT_DISCOVERY;
+	/* Device Discovery completes */
+	lpfc_printf_log(phba,
+			 KERN_INFO,
+			 LOG_DISCOVERY,
+			 "%d:0225 Device Discovery completes\n",
+			 phba->brd_no);
+
+	mempool_free( pmb, phba->mbox_mem_pool);
+	if (phba->fc_flag & FC_ESTABLISH_LINK) {
+		phba->fc_flag &= ~FC_ESTABLISH_LINK;
+	}
+	spin_unlock_irq(phba->host->host_lock);
+	del_timer_sync(&phba->fc_estabtmo);
+	spin_lock_irq(phba->host->host_lock);
+	lpfc_can_disctmo(phba);
+
+	/* turn on Link Attention interrupts */
+	psli->sliinit.sli_flag |= LPFC_PROCESS_LA;
+	control = readl(phba->HCregaddr);
+	control |= HC_LAINT_ENA;
+	writel(control, phba->HCregaddr);
+	readl(phba->HCregaddr); /* flush */
+
+	return;
+}
+
+static void
+lpfc_mbx_cmpl_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
+{
+	struct lpfc_sli *psli;
+	MAILBOX_t *mb;
+
+	psli = &phba->sli;
+	mb = &pmb->mb;
+	/* Check for error */
+	if (mb->mbxStatus) {
+		/* CONFIG_LINK mbox error <mbxStatus> state <hba_state> */
+		lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
+				"%d:0306 CONFIG_LINK mbxStatus error x%x "
+				"HBA state x%x\n",
+				phba->brd_no, mb->mbxStatus, phba->hba_state);
+
+		lpfc_linkdown(phba);
+		phba->hba_state = LPFC_HBA_ERROR;
+		goto out;
+	}
+
+	if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
+		/* Start discovery by sending a FLOGI hba_state is identically
+		 * LPFC_FLOGI while waiting for FLOGI cmpl (same on FAN)
+		 */
+		phba->hba_state = LPFC_FLOGI;
+		lpfc_set_disctmo(phba);
+		lpfc_initial_flogi(phba);
+		mempool_free( pmb, phba->mbox_mem_pool);
+		return;
+	}
+	if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
+		mempool_free( pmb, phba->mbox_mem_pool);
+		return;
+	}
+
+out:
+	/* CONFIG_LINK bad hba state <hba_state> */
+	lpfc_printf_log(phba,
+			KERN_ERR,
+			LOG_DISCOVERY,
+			"%d:0200 CONFIG_LINK bad hba state x%x\n",
+			phba->brd_no, phba->hba_state);
+
+	if (phba->hba_state != LPFC_CLEAR_LA) {
+		lpfc_clear_la(phba, pmb);
+		pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
+		if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
+		    == MBX_NOT_FINISHED) {
+			mempool_free( pmb, phba->mbox_mem_pool);
+			lpfc_disc_flush_list(phba);
+			psli->ring[(psli->ip_ring)].flag &=
+				~LPFC_STOP_IOCB_EVENT;
+			psli->ring[(psli->fcp_ring)].flag &=
+				~LPFC_STOP_IOCB_EVENT;
+			psli->ring[(psli->next_ring)].flag &=
+				~LPFC_STOP_IOCB_EVENT;
+			phba->hba_state = LPFC_HBA_READY;
+		}
+	} else {
+		mempool_free( pmb, phba->mbox_mem_pool);
+	}
+	return;
+}
+
+static void
+lpfc_mbx_cmpl_read_sparam(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
+{
+	struct lpfc_sli *psli = &phba->sli;
+	MAILBOX_t *mb = &pmb->mb;
+	struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
+
+
+	/* Check for error */
+	if (mb->mbxStatus) {
+		/* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
+		lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
+				"%d:0319 READ_SPARAM mbxStatus error x%x "
+				"hba state x%x>\n",
+				phba->brd_no, mb->mbxStatus, phba->hba_state);
+
+		lpfc_linkdown(phba);
+		phba->hba_state = LPFC_HBA_ERROR;
+		goto out;
+	}
+
+	memcpy((uint8_t *) & phba->fc_sparam, (uint8_t *) mp->virt,
+	       sizeof (struct serv_parm));
+	memcpy((uint8_t *) & phba->fc_nodename,
+	       (uint8_t *) & phba->fc_sparam.nodeName,
+	       sizeof (struct lpfc_name));
+	memcpy((uint8_t *) & phba->fc_portname,
+	       (uint8_t *) & phba->fc_sparam.portName,
+	       sizeof (struct lpfc_name));
+	lpfc_mbuf_free(phba, mp->virt, mp->phys);
+	kfree(mp);
+	mempool_free( pmb, phba->mbox_mem_pool);
+	return;
+
+out:
+	pmb->context1 = NULL;
+	lpfc_mbuf_free(phba, mp->virt, mp->phys);
+	kfree(mp);
+	if (phba->hba_state != LPFC_CLEAR_LA) {
+		lpfc_clear_la(phba, pmb);
+		pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
+		if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
+		    == MBX_NOT_FINISHED) {
+			mempool_free( pmb, phba->mbox_mem_pool);
+			lpfc_disc_flush_list(phba);
+			psli->ring[(psli->ip_ring)].flag &=
+			    ~LPFC_STOP_IOCB_EVENT;
+			psli->ring[(psli->fcp_ring)].flag &=
+			    ~LPFC_STOP_IOCB_EVENT;
+			psli->ring[(psli->next_ring)].flag &=
+			    ~LPFC_STOP_IOCB_EVENT;
+			phba->hba_state = LPFC_HBA_READY;
+		}
+	} else {
+		mempool_free( pmb, phba->mbox_mem_pool);
+	}
+	return;
+}
+
+/*
+ * This routine handles processing a READ_LA mailbox
+ * command upon completion. It is setup in the LPFC_MBOXQ
+ * as the completion routine when the command is
+ * handed off to the SLI layer.
+ */
+void
+lpfc_mbx_cmpl_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
+{
+	struct lpfc_sli *psli = &phba->sli;
+	READ_LA_VAR *la;
+	LPFC_MBOXQ_t *mbox;
+	MAILBOX_t *mb = &pmb->mb;
+	struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
+	uint32_t control;
+	int i;
+
+	/* Check for error */
+	if (mb->mbxStatus) {
+		/* READ_LA mbox error <mbxStatus> state <hba_state> */
+		lpfc_printf_log(phba,
+				KERN_INFO,
+				LOG_LINK_EVENT,
+				"%d:1307 READ_LA mbox error x%x state x%x\n",
+				phba->brd_no,
+				mb->mbxStatus, phba->hba_state);
+		pmb->context1 = NULL;
+		lpfc_mbuf_free(phba, mp->virt, mp->phys);
+		kfree(mp);
+		mempool_free( pmb, phba->mbox_mem_pool);
+
+		lpfc_linkdown(phba);
+		phba->hba_state = LPFC_HBA_ERROR;
+
+		/* turn on Link Attention interrupts */
+		psli->sliinit.sli_flag |= LPFC_PROCESS_LA;
+		control = readl(phba->HCregaddr);
+		control |= HC_LAINT_ENA;
+		writel(control, phba->HCregaddr);
+		readl(phba->HCregaddr); /* flush */
+		return;
+	}
+	la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
+
+	/* Get Loop Map information */
+	if (mp) {
+		memcpy(&phba->alpa_map[0], mp->virt, 128);
+	} else {
+		memset(&phba->alpa_map[0], 0, 128);
+	}
+
+	if (((phba->fc_eventTag + 1) < la->eventTag) ||
+	    (phba->fc_eventTag == la->eventTag)) {
+		phba->fc_stat.LinkMultiEvent++;
+		if (la->attType == AT_LINK_UP) {
+			if (phba->fc_eventTag != 0) {
+
+				lpfc_linkdown(phba);
+			}
+		}
+	}
+
+	phba->fc_eventTag = la->eventTag;
+
+	if (la->attType == AT_LINK_UP) {
+		phba->fc_stat.LinkUp++;
+		/* Link Up Event <eventTag> received */
+		lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
+				"%d:1303 Link Up Event x%x received "
+				"Data: x%x x%x x%x x%x\n",
+				phba->brd_no, la->eventTag, phba->fc_eventTag,
+				la->granted_AL_PA, la->UlnkSpeed,
+				phba->alpa_map[0]);
+
+		switch(la->UlnkSpeed) {
+			case LA_1GHZ_LINK:
+				phba->fc_linkspeed = LA_1GHZ_LINK;
+			break;
+			case LA_2GHZ_LINK:
+				phba->fc_linkspeed = LA_2GHZ_LINK;
+			break;
+			case LA_4GHZ_LINK:
+				phba->fc_linkspeed = LA_4GHZ_LINK;
+			break;
+			default:
+				phba->fc_linkspeed = LA_UNKNW_LINK;
+			break;
+		}
+
+		if ((phba->fc_topology = la->topology) == TOPOLOGY_LOOP) {
+
+			if (la->il) {
+				phba->fc_flag |= FC_LBIT;
+			}
+
+			phba->fc_myDID = la->granted_AL_PA;
+
+			i = la->un.lilpBde64.tus.f.bdeSize;
+			if (i == 0) {
+				phba->alpa_map[0] = 0;
+			} else {
+				if (phba->cfg_log_verbose
+				    & LOG_LINK_EVENT) {
+					int numalpa, j, k;
+					union {
+						uint8_t pamap[16];
+						struct {
+							uint32_t wd1;
+							uint32_t wd2;
+							uint32_t wd3;
+							uint32_t wd4;
+						} pa;
+					} un;
+
+					numalpa = phba->alpa_map[0];
+					j = 0;
+					while (j < numalpa) {
+						memset(un.pamap, 0, 16);
+						for (k = 1; j < numalpa; k++) {
+							un.pamap[k - 1] =
+							    phba->alpa_map[j +
+									   1];
+							j++;
+							if (k == 16)
+								break;
+						}
+						/* Link Up Event ALPA map */
+						lpfc_printf_log(phba,
+							KERN_WARNING,
+							LOG_LINK_EVENT,
+							"%d:1304 Link Up Event "
+							"ALPA map Data: x%x "
+							"x%x x%x x%x\n",
+							phba->brd_no,
+							un.pa.wd1, un.pa.wd2,
+							un.pa.wd3, un.pa.wd4);
+					}
+				}
+			}
+		} else {
+			phba->fc_myDID = phba->fc_pref_DID;
+			phba->fc_flag |= FC_LBIT;
+		}
+
+		lpfc_linkup(phba);
+		if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC))) {
+			lpfc_read_sparam(phba, mbox);
+			mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
+			lpfc_sli_issue_mbox
+			    (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
+		}
+
+		if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC))) {
+			phba->hba_state = LPFC_LOCAL_CFG_LINK;
+			lpfc_config_link(phba, mbox);
+			mbox->mbox_cmpl = lpfc_mbx_cmpl_config_link;
+			lpfc_sli_issue_mbox
+			    (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
+		}
+	} else {
+		phba->fc_stat.LinkDown++;
+		/* Link Down Event <eventTag> received */
+		lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
+				"%d:1305 Link Down Event x%x received "
+				"Data: x%x x%x x%x\n",
+				phba->brd_no, la->eventTag, phba->fc_eventTag,
+				phba->hba_state, phba->fc_flag);
+
+		lpfc_linkdown(phba);
+
+		/* turn on Link Attention interrupts - no CLEAR_LA needed */
+		psli->sliinit.sli_flag |= LPFC_PROCESS_LA;
+		control = readl(phba->HCregaddr);
+		control |= HC_LAINT_ENA;
+		writel(control, phba->HCregaddr);
+		readl(phba->HCregaddr); /* flush */
+	}
+
+	pmb->context1 = NULL;
+	lpfc_mbuf_free(phba, mp->virt, mp->phys);
+	kfree(mp);
+	mempool_free( pmb, phba->mbox_mem_pool);
+	return;
+}
+
+/*
+ * This routine handles processing a REG_LOGIN mailbox
+ * command upon completion. It is setup in the LPFC_MBOXQ
+ * as the completion routine when the command is
+ * handed off to the SLI layer.
+ */
+void
+lpfc_mbx_cmpl_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
+{
+	struct lpfc_sli *psli;
+	MAILBOX_t *mb;
+	struct lpfc_dmabuf *mp;
+	struct lpfc_nodelist *ndlp;
+
+	psli = &phba->sli;
+	mb = &pmb->mb;
+
+	ndlp = (struct lpfc_nodelist *) pmb->context2;
+	mp = (struct lpfc_dmabuf *) (pmb->context1);
+
+	pmb->context1 = NULL;
+
+	/* Good status, call state machine */
+	lpfc_disc_state_machine(phba, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
+	lpfc_mbuf_free(phba, mp->virt, mp->phys);
+	kfree(mp);
+	mempool_free( pmb, phba->mbox_mem_pool);
+
+	return;
+}
+
+/*
+ * This routine handles processing a Fabric REG_LOGIN mailbox
+ * command upon completion. It is setup in the LPFC_MBOXQ
+ * as the completion routine when the command is
+ * handed off to the SLI layer.
+ */
+void
+lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
+{
+	struct lpfc_sli *psli;
+	MAILBOX_t *mb;
+	struct lpfc_dmabuf *mp;
+	struct lpfc_nodelist *ndlp;
+	struct lpfc_nodelist *ndlp_fdmi;
+
+
+	psli = &phba->sli;
+	mb = &pmb->mb;
+
+	ndlp = (struct lpfc_nodelist *) pmb->context2;
+	mp = (struct lpfc_dmabuf *) (pmb->context1);
+
+	if (mb->mbxStatus) {
+		lpfc_mbuf_free(phba, mp->virt, mp->phys);
+		kfree(mp);
+		mempool_free( pmb, phba->mbox_mem_pool);
+		mempool_free( ndlp, phba->nlp_mem_pool);
+
+		/* FLOGI failed, so just use loop map to make discovery list */
+		lpfc_disc_list_loopmap(phba);
+
+		/* Start discovery */
+		lpfc_disc_start(phba);
+		return;
+	}
+
+	pmb->context1 = NULL;
+
+	if (ndlp->nlp_rpi != 0)
+		lpfc_findnode_remove_rpi(phba, ndlp->nlp_rpi);
+	ndlp->nlp_rpi = mb->un.varWords[0];
+	lpfc_addnode_rpi(phba, ndlp, ndlp->nlp_rpi);
+	ndlp->nlp_type |= NLP_FABRIC;
+	ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
+	lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
+
+	if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
+		/* This NPort has been assigned an NPort_ID by the fabric as a
+		 * result of the completed fabric login.  Issue a State Change
+		 * Registration (SCR) ELS request to the fabric controller
+		 * (SCR_DID) so that this NPort gets RSCN events from the
+		 * fabric.
+		 */
+		lpfc_issue_els_scr(phba, SCR_DID, 0);
+
+		/* Allocate a new node instance.  If the pool is empty, just
+		 * start the discovery process and skip the Nameserver login
+		 * process.  This is attempted again later on.  Otherwise, issue
+		 * a Port Login (PLOGI) to the NameServer
+		 */
+		if ((ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC))
+		    == 0) {
+			lpfc_disc_start(phba);
+		} else {
+			lpfc_nlp_init(phba, ndlp, NameServer_DID);
+			ndlp->nlp_type |= NLP_FABRIC;
+			ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
+			lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
+			lpfc_issue_els_plogi(phba, ndlp, 0);
+			if (phba->cfg_fdmi_on) {
+				if ((ndlp_fdmi = mempool_alloc(
+						       phba->nlp_mem_pool,
+						       GFP_ATOMIC))) {
+					lpfc_nlp_init(phba, ndlp_fdmi,
+						FDMI_DID);
+					ndlp_fdmi->nlp_type |= NLP_FABRIC;
+					ndlp_fdmi->nlp_state =
+					    NLP_STE_PLOGI_ISSUE;
+					lpfc_issue_els_plogi(phba, ndlp_fdmi,
+							     0);
+				}
+			}
+		}
+	}
+
+	lpfc_mbuf_free(phba, mp->virt, mp->phys);
+	kfree(mp);
+	mempool_free( pmb, phba->mbox_mem_pool);
+
+	return;
+}
+
+/*
+ * This routine handles processing a NameServer REG_LOGIN mailbox
+ * command upon completion. It is setup in the LPFC_MBOXQ
+ * as the completion routine when the command is
+ * handed off to the SLI layer.
+ */
+void
+lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
+{
+	struct lpfc_sli *psli;
+	MAILBOX_t *mb;
+	struct lpfc_dmabuf *mp;
+	struct lpfc_nodelist *ndlp;
+
+	psli = &phba->sli;
+	mb = &pmb->mb;
+
+	ndlp = (struct lpfc_nodelist *) pmb->context2;
+	mp = (struct lpfc_dmabuf *) (pmb->context1);
+
+	if (mb->mbxStatus) {
+		lpfc_mbuf_free(phba, mp->virt, mp->phys);
+		kfree(mp);
+		mempool_free( pmb, phba->mbox_mem_pool);
+		lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
+
+		/* RegLogin failed, so just use loop map to make discovery
+		   list */
+		lpfc_disc_list_loopmap(phba);
+
+		/* Start discovery */
+		lpfc_disc_start(phba);
+		return;
+	}
+
+	pmb->context1 = NULL;
+
+	if (ndlp->nlp_rpi != 0)
+		lpfc_findnode_remove_rpi(phba, ndlp->nlp_rpi);
+	ndlp->nlp_rpi = mb->un.varWords[0];
+	lpfc_addnode_rpi(phba, ndlp, ndlp->nlp_rpi);
+	ndlp->nlp_type |= NLP_FABRIC;
+	ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
+	lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
+
+	if (phba->hba_state < LPFC_HBA_READY) {
+		/* Link up discovery requires Fabrib registration. */
+		lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RNN_ID);
+		lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RSNN_NN);
+		lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFT_ID);
+	}
+
+	phba->fc_ns_retry = 0;
+	/* Good status, issue CT Request to NameServer */
+	if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT)) {
+		/* Cannot issue NameServer Query, so finish up discovery */
+		lpfc_disc_start(phba);
+	}
+
+	lpfc_mbuf_free(phba, mp->virt, mp->phys);
+	kfree(mp);
+	mempool_free( pmb, phba->mbox_mem_pool);
+
+	return;
+}
+
+/* Put blp on the bind list */
+int
+lpfc_consistent_bind_save(struct lpfc_hba * phba, struct lpfc_bindlist * blp)
+{
+	/* Put it at the end of the bind list */
+	list_add_tail(&blp->nlp_listp, &phba->fc_nlpbind_list);
+	phba->fc_bind_cnt++;
+
+	/* Add scsiid <sid> to BIND list */
+	lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
+			"%d:0903 Add scsiid %d to BIND list "
+			"Data: x%x x%x x%x x%p\n",
+			phba->brd_no, blp->nlp_sid, phba->fc_bind_cnt,
+			blp->nlp_DID, blp->nlp_bind_type, blp);
+
+	return (0);
+}
+
+int
+lpfc_nlp_list(struct lpfc_hba * phba, struct lpfc_nodelist * nlp, int list)
+{
+	struct lpfc_bindlist *blp;
+	struct lpfc_target   *targetp;
+	struct lpfc_sli      *psli;
+	psli = &phba->sli;
+
+	/* Sanity check to ensure we are not moving to / from the same list */
+	if((nlp->nlp_flag & NLP_LIST_MASK) == list) {
+		if(list != NLP_NO_LIST)
+			return(0);
+	}
+
+	blp = nlp->nlp_listp_bind;
+
+	switch(nlp->nlp_flag & NLP_LIST_MASK) {
+	case NLP_NO_LIST: /* Not on any list */
+		break;
+	case NLP_UNUSED_LIST:
+		phba->fc_unused_cnt--;
+		list_del(&nlp->nlp_listp);
+		nlp->nlp_flag &= ~NLP_LIST_MASK;
+		break;
+	case NLP_PLOGI_LIST:
+		phba->fc_plogi_cnt--;
+		list_del(&nlp->nlp_listp);
+		nlp->nlp_flag &= ~NLP_LIST_MASK;
+		break;
+	case NLP_ADISC_LIST:
+		phba->fc_adisc_cnt--;
+		list_del(&nlp->nlp_listp);
+		nlp->nlp_flag &= ~NLP_LIST_MASK;
+		break;
+	case NLP_REGLOGIN_LIST:
+		phba->fc_reglogin_cnt--;
+		list_del(&nlp->nlp_listp);
+		nlp->nlp_flag &= ~NLP_LIST_MASK;
+		break;
+	case NLP_PRLI_LIST:
+		phba->fc_prli_cnt--;
+		list_del(&nlp->nlp_listp);
+		nlp->nlp_flag &= ~NLP_LIST_MASK;
+		break;
+	case NLP_UNMAPPED_LIST:
+		phba->fc_unmap_cnt--;
+		list_del(&nlp->nlp_listp);
+		nlp->nlp_flag &= ~NLP_LIST_MASK;
+		nlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
+	  	nlp->nlp_type &= ~NLP_FC_NODE;
+		phba->nport_event_cnt++;
+		break;
+	case NLP_MAPPED_LIST:
+		phba->fc_map_cnt--;
+		list_del(&nlp->nlp_listp);
+		nlp->nlp_flag &= ~NLP_LIST_MASK;
+		phba->nport_event_cnt++;
+		lpfc_set_failmask(phba, nlp, LPFC_DEV_DISAPPEARED,
+			  LPFC_SET_BITMASK);
+	  	nlp->nlp_type &= ~NLP_FCP_TARGET;
+		targetp = nlp->nlp_Target;
+		if (targetp && (list != NLP_MAPPED_LIST)) {
+			nlp->nlp_Target = NULL;
+#if defined(RHEL_FC) || defined(SLES_FC)
+			/*
+			 * Do not block the target if the driver has just reset
+			 * its interface to the hardware.
+			 */
+			if (phba->hba_state != LPFC_INIT_START)
+				lpfc_target_block(phba, targetp);
+#endif
+		}
+
+		break;
+	case NLP_NPR_LIST:
+		phba->fc_npr_cnt--;
+		list_del(&nlp->nlp_listp);
+		nlp->nlp_flag &= ~NLP_LIST_MASK;
+		/* Stop delay tmo if taking node off NPR list */
+		if ((nlp->nlp_flag & NLP_DELAY_TMO) &&
+		   (list != NLP_NPR_LIST)) {
+			nlp->nlp_flag &= ~NLP_DELAY_TMO;
+			spin_unlock_irq(phba->host->host_lock);
+			del_timer_sync(&nlp->nlp_delayfunc);
+			spin_lock_irq(phba->host->host_lock);
+			if (!list_empty(&nlp->els_retry_evt.evt_listp))
+				list_del_init(&nlp->els_retry_evt.
+					      evt_listp);
+			if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
+				nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
+				if (phba->num_disc_nodes) {
+					/* Check to see if there are more
+					 * PLOGIs to be sent
+					 */
+					lpfc_more_plogi(phba);
+				}
+
+
+				if (phba->num_disc_nodes == 0) {
+					phba->fc_flag &= ~FC_NDISC_ACTIVE;
+					lpfc_can_disctmo(phba);
+
+					if (phba->fc_flag & FC_RSCN_MODE) {
+						/* Check to see if more RSCNs
+						 * came in while we were
+			 			 * processing this one.
+			 			 */
+						if((phba->fc_rscn_id_cnt==0) &&
+			    			   (!(phba->fc_flag &
+							FC_RSCN_DISCOVERY))) {
+							phba->fc_flag &=
+							   ~FC_RSCN_MODE;
+						}
+						else {
+							lpfc_els_handle_rscn(
+							   phba);
+						}
+					}
+				}
+			}
+		}
+		break;
+	}
+
+	/* Add NPort <did> to <num> list */
+	lpfc_printf_log(phba,
+			KERN_INFO,
+			LOG_NODE,
+			"%d:0904 Add NPort x%x to %d list Data: x%x x%p\n",
+			phba->brd_no,
+			nlp->nlp_DID, list, nlp->nlp_flag, blp);
+
+	nlp->nlp_listp_bind = NULL;
+
+	switch(list) {
+	case NLP_NO_LIST: /* No list, just remove it */
+#if defined(SLES_FC)
+		targetp = NULL;
+		if (((nlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) && 
+		    (nlp->nlp_sid != NLP_NO_SID)) {
+			targetp = phba->device_queue_hash[nlp->nlp_sid];
+		}
+#endif
+		lpfc_nlp_remove(phba, nlp);
+
+#if defined(SLES_FC)
+		if (targetp && targetp->blocked) {
+			lpfc_target_unblock(phba, targetp);
+		}
+#endif
+
+		break;
+	case NLP_UNUSED_LIST:
+		nlp->nlp_flag |= list;
+		/* Put it at the end of the unused list */
+		list_add_tail(&nlp->nlp_listp, &phba->fc_unused_list);
+		phba->fc_unused_cnt++;
+		break;
+	case NLP_PLOGI_LIST:
+		nlp->nlp_flag |= list;
+		/* Put it at the end of the plogi list */
+		list_add_tail(&nlp->nlp_listp, &phba->fc_plogi_list);
+		phba->fc_plogi_cnt++;
+		break;
+	case NLP_ADISC_LIST:
+		nlp->nlp_flag |= list;
+		/* Put it at the end of the adisc list */
+		list_add_tail(&nlp->nlp_listp, &phba->fc_adisc_list);
+		phba->fc_adisc_cnt++;
+		break;
+	case NLP_REGLOGIN_LIST:
+		nlp->nlp_flag |= list;
+		/* Put it at the end of the reglogin list */
+		list_add_tail(&nlp->nlp_listp, &phba->fc_reglogin_list);
+		phba->fc_reglogin_cnt++;
+		break;
+	case NLP_PRLI_LIST:
+		nlp->nlp_flag |= list;
+		/* Put it at the end of the prli list */
+		list_add_tail(&nlp->nlp_listp, &phba->fc_prli_list);
+		phba->fc_prli_cnt++;
+		break;
+	case NLP_UNMAPPED_LIST:
+		nlp->nlp_flag |= list;
+		/* Put it at the end of the unmap list */
+		list_add_tail(&nlp->nlp_listp, &phba->fc_nlpunmap_list);
+		phba->fc_unmap_cnt++;
+		phba->nport_event_cnt++;
+		/* stop nodev tmo if running */
+		if (nlp->nlp_flag & NLP_NODEV_TMO) {
+			nlp->nlp_flag &= ~NLP_NODEV_TMO;
+			spin_unlock_irq(phba->host->host_lock);
+			del_timer_sync(&nlp->nlp_tmofunc);
+			spin_lock_irq(phba->host->host_lock);
+			if (!list_empty(&nlp->nodev_timeout_evt.
+					evt_listp))
+				list_del_init(&nlp->nodev_timeout_evt.
+					      evt_listp);
+		}
+	  	nlp->nlp_type |= NLP_FC_NODE;
+		lpfc_set_failmask(phba, nlp, LPFC_DEV_DISCOVERY_INP,
+				  LPFC_CLR_BITMASK);
+		break;
+	case NLP_MAPPED_LIST:
+		nlp->nlp_flag |= list;
+		/* Put it at the end of the map list */
+		list_add_tail(&nlp->nlp_listp, &phba->fc_nlpmap_list);
+		phba->fc_map_cnt++;
+		phba->nport_event_cnt++;
+		/* stop nodev tmo if running */
+		if (nlp->nlp_flag & NLP_NODEV_TMO) {
+			nlp->nlp_flag &= ~NLP_NODEV_TMO;
+			spin_unlock_irq(phba->host->host_lock);
+			del_timer_sync(&nlp->nlp_tmofunc);
+			spin_lock_irq(phba->host->host_lock);
+			if (!list_empty(&nlp->nodev_timeout_evt.
+					evt_listp))
+				list_del_init(&nlp->nodev_timeout_evt.
+					      evt_listp);
+		}
+	  	nlp->nlp_type |= NLP_FCP_TARGET;
+		lpfc_set_failmask(phba, nlp, LPFC_DEV_DISAPPEARED,
+			  LPFC_CLR_BITMASK);
+		lpfc_set_failmask(phba, nlp, LPFC_DEV_DISCOVERY_INP,
+				  LPFC_CLR_BITMASK);
+
+		targetp = NULL;
+		if (nlp->nlp_sid != NLP_NO_SID)
+			targetp = phba->device_queue_hash[nlp->nlp_sid];
+
+		if (targetp && targetp->pnode) {
+			nlp->nlp_Target = targetp;
+#if defined(RHEL_FC) || defined(SLES_FC)
+			/* Unblock I/Os on target */
+			if(targetp->blocked)
+				lpfc_target_unblock(phba, targetp);
+#endif
+		}
+		break;
+	case NLP_NPR_LIST:
+		nlp->nlp_flag |= list;
+		/* Put it at the end of the npr list */
+		list_add_tail(&nlp->nlp_listp, &phba->fc_npr_list);
+		phba->fc_npr_cnt++;
+
+		/*
+		 * Sanity check for Fabric entity.
+		 * Set nodev_tmo for NPR state, for Fabric use 1 sec.
+		 */
+		if (nlp->nlp_type & NLP_FABRIC) {
+			mod_timer(&nlp->nlp_tmofunc, jiffies + HZ);
+		}
+		else {
+			mod_timer(&nlp->nlp_tmofunc,
+			    jiffies + HZ * phba->cfg_nodev_tmo);
+		}
+		nlp->nlp_flag |= NLP_NODEV_TMO;
+		nlp->nlp_flag &= ~NLP_RCV_PLOGI;
+		break;
+	case NLP_JUST_DQ:
+		break;
+	}
+
+	if (blp) {
+		nlp->nlp_flag &= ~NLP_SEED_MASK;
+		nlp->nlp_Target = NULL;
+		lpfc_consistent_bind_save(phba, blp);
+	}
+	return (0);
+}
+
+/*
+ * Start / ReStart rescue timer for Discovery / RSCN handling
+ */
+void
+lpfc_set_disctmo(struct lpfc_hba * phba)
+{
+	uint32_t tmo;
+
+	tmo = ((phba->fc_ratov * 2) + LPFC_DRVR_TIMEOUT + 3);
+
+	mod_timer(&phba->fc_disctmo, jiffies + HZ * tmo);
+	phba->fc_flag |= FC_DISC_TMO;
+
+	/* Start Discovery Timer state <hba_state> */
+	lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
+			"%d:0247 Start Discovery Timer state x%x "
+			"Data: x%x x%lx x%x x%x\n",
+			phba->brd_no,
+			phba->hba_state, tmo, (unsigned long)&phba->fc_disctmo,
+			phba->fc_plogi_cnt, phba->fc_adisc_cnt);
+
+	return;
+}
+
+/*
+ * Cancel rescue timer for Discovery / RSCN handling
+ */
+int
+lpfc_can_disctmo(struct lpfc_hba * phba)
+{
+	/* Turn off discovery timer if its running */
+	if(phba->fc_flag & FC_DISC_TMO) {
+		phba->fc_flag &= ~FC_DISC_TMO;
+		spin_unlock_irq(phba->host->host_lock);
+		del_timer_sync(&phba->fc_disctmo);
+		spin_lock_irq(phba->host->host_lock);
+		phba->work_hba_events &= ~WORKER_DISC_TMO;
+	}
+
+	/* Cancel Discovery Timer state <hba_state> */
+	lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
+			"%d:0248 Cancel Discovery Timer state x%x "
+			"Data: x%x x%x x%x\n",
+			phba->brd_no, phba->hba_state, phba->fc_flag,
+			phba->fc_plogi_cnt, phba->fc_adisc_cnt);
+
+	return (0);
+}
+
+/*
+ * Check specified ring for outstanding IOCB on the SLI queue
+ * Return true if iocb matches the specified nport
+ */
+int
+lpfc_check_sli_ndlp(struct lpfc_hba * phba,
+		    struct lpfc_sli_ring * pring,
+		    struct lpfc_iocbq * iocb, struct lpfc_nodelist * ndlp)
+{
+	struct lpfc_sli *psli;
+	IOCB_t *icmd;
+
+	psli = &phba->sli;
+	icmd = &iocb->iocb;
+	if (pring->ringno == LPFC_ELS_RING) {
+		switch (icmd->ulpCommand) {
+		case CMD_GEN_REQUEST64_CR:
+			if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
+				return (1);
+		case CMD_ELS_REQUEST64_CR:
+		case CMD_XMIT_ELS_RSP64_CX:
+			if (iocb->context1 == (uint8_t *) ndlp)
+				return (1);
+		}
+	} else if (pring->ringno == psli->ip_ring) {
+
+	} else if (pring->ringno == psli->fcp_ring) {
+		/* Skip match check if waiting to relogin to FCP target */
+	  	if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
+		  (ndlp->nlp_flag & NLP_DELAY_TMO)) {
+			return (0);
+		}
+		if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
+			return (1);
+		}
+	} else if (pring->ringno == psli->next_ring) {
+
+	}
+	return (0);
+}
+
+/*
+ * Free resources / clean up outstanding I/Os
+ * associated with nlp_rpi in the LPFC_NODELIST entry.
+ */
+static int
+lpfc_no_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
+{
+	struct lpfc_sli *psli;
+	struct lpfc_sli_ring *pring;
+	struct lpfc_iocbq *iocb, *next_iocb;
+	IOCB_t *icmd;
+	uint32_t rpi, i;
+
+	psli = &phba->sli;
+	rpi = ndlp->nlp_rpi;
+	if (rpi) {
+		/* Now process each ring */
+		for (i = 0; i < psli->sliinit.num_rings; i++) {
+			pring = &psli->ring[i];
+
+			list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
+						list) {
+				/*
+				 * Check to see if iocb matches the nport we are
+				 * looking for
+				 */
+				if ((lpfc_check_sli_ndlp
+				     (phba, pring, iocb, ndlp))) {
+					/* It matches, so deque and call compl
+					   with an error */
+					list_del(&iocb->list);
+					pring->txq_cnt--;
+					if (iocb->iocb_cmpl) {
+						icmd = &iocb->iocb;
+						icmd->ulpStatus =
+						    IOSTAT_LOCAL_REJECT;
+						icmd->un.ulpWord[4] =
+						    IOERR_SLI_ABORTED;
+						(iocb->iocb_cmpl) (phba,
+								   iocb, iocb);
+					} else {
+						mempool_free(iocb,
+						     phba->iocb_mem_pool);
+					}
+				}
+			}
+			/* Everything that matches on txcmplq will be returned
+			 * by firmware with a no rpi error.
+			 */
+		}
+	}
+	return (0);
+}
+
+/*
+ * Free rpi associated with LPFC_NODELIST entry.
+ * This routine is called from lpfc_freenode(), when we are removing
+ * a LPFC_NODELIST entry. It is also called if the driver initiates a
+ * LOGO that completes successfully, and we are waiting to PLOGI back
+ * to the remote NPort. In addition, it is called after we receive
+ * and unsolicated ELS cmd, send back a rsp, the rsp completes and
+ * we are waiting to PLOGI back to the remote NPort.
+ */
+int
+lpfc_unreg_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
+{
+	LPFC_MBOXQ_t *mbox;
+
+	if (ndlp->nlp_rpi) {
+		if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC))) {
+			lpfc_unreg_login(phba, ndlp->nlp_rpi, mbox);
+			mbox->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
+			if (lpfc_sli_issue_mbox
+			    (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB))
+			    == MBX_NOT_FINISHED) {
+				mempool_free( mbox, phba->mbox_mem_pool);
+			}
+		}
+		lpfc_findnode_remove_rpi(phba, ndlp->nlp_rpi);
+		lpfc_no_rpi(phba, ndlp);
+		ndlp->nlp_rpi = 0;
+		lpfc_set_failmask(phba, ndlp, LPFC_DEV_DISCONNECTED,
+				  LPFC_SET_BITMASK);
+		return 1;
+	}
+	return 0;
+}
+
+/*
+ * Free resources associated with LPFC_NODELIST entry
+ * so it can be freed.
+ */
+static int
+lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
+{
+	struct lpfc_target *targetp;
+	LPFC_MBOXQ_t       *mb, *nextmb;
+	LPFC_DISC_EVT_t    *evtp, *next_evtp;
+	struct lpfc_dmabuf *mp;
+	struct lpfc_sli    *psli;
+	int scsid;
+
+	/* The psli variable gets rid of the long pointer deference. */
+	psli = &phba->sli;
+
+	/* Cleanup node for NPort <nlp_DID> */
+	lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
+			"%d:0900 Cleanup node for NPort x%x "
+			"Data: x%x x%x x%x\n",
+			phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
+			ndlp->nlp_state, ndlp->nlp_rpi);
+
+	lpfc_nlp_list(phba, ndlp, NLP_JUST_DQ);
+
+	/* cleanup any ndlp on mbox q waiting for reglogin cmpl */
+	if ((mb = psli->mbox_active)) {
+		if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
+		   (ndlp == (struct lpfc_nodelist *) mb->context2)) {
+			mb->context2 = NULL;
+			mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
+		}
+        }
+	list_for_each_entry_safe(mb, nextmb, &psli->mboxq, list) {
+		if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
+		   (ndlp == (struct lpfc_nodelist *) mb->context2)) {
+			mp = (struct lpfc_dmabuf *) (mb->context1);
+			if (mp) {
+				lpfc_mbuf_free(phba, mp->virt, mp->phys);
+				kfree(mp);
+			}
+			list_del(&mb->list);
+			mempool_free(mb, phba->mbox_mem_pool);
+		}
+	}
+	/* cleanup any ndlp on disc event q waiting for reglogin cmpl */
+	list_for_each_entry_safe(evtp, next_evtp, &phba->dpc_disc, evt_listp) {
+		mb = (LPFC_MBOXQ_t *)(evtp->evt_arg1);
+		if ((evtp->evt == LPFC_EVT_MBOX) &&
+		    (mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
+		    (ndlp == (struct lpfc_nodelist *) mb->context2)) {
+			mp = (struct lpfc_dmabuf *) (mb->context1);
+			if (mp) {
+				lpfc_mbuf_free(phba, mp->virt, mp->phys);
+				kfree(mp);
+			}
+			mempool_free(mb, phba->mbox_mem_pool);
+			list_del_init(&evtp->evt_listp);
+			kfree(evtp);
+		}
+	}
+
+	lpfc_els_abort(phba,ndlp,0);
+	if(ndlp->nlp_flag & NLP_NODEV_TMO) {
+		ndlp->nlp_flag &= ~NLP_NODEV_TMO;
+		spin_unlock_irq(phba->host->host_lock);
+		del_timer_sync(&ndlp->nlp_tmofunc);
+		spin_lock_irq(phba->host->host_lock);
+		if (!list_empty(&ndlp->nodev_timeout_evt.
+				evt_listp))
+			list_del_init(&ndlp->nodev_timeout_evt.
+				      evt_listp);
+	}
+
+	if(ndlp->nlp_flag & NLP_DELAY_TMO) {
+		ndlp->nlp_flag &= ~NLP_DELAY_TMO;
+		spin_unlock_irq(phba->host->host_lock);
+		del_timer_sync(&ndlp->nlp_delayfunc);
+		spin_lock_irq(phba->host->host_lock);
+		if (!list_empty(&ndlp->els_retry_evt.
+				evt_listp))
+			list_del_init(&ndlp->els_retry_evt.
+				      evt_listp);
+	}
+
+	lpfc_unreg_rpi(phba, ndlp);
+
+	for(scsid=0;scsid<MAX_FCP_TARGET;scsid++) {
+		targetp = phba->device_queue_hash[scsid];
+		/* First see if the SCSI ID has an allocated struct
+		   lpfc_target */
+		if (targetp) {
+			if (targetp->pnode == ndlp) {
+				targetp->pnode = NULL;
+				ndlp->nlp_Target = NULL;
+#ifdef RHEL_FC
+				/*
+				 * This code does not apply to SLES9 since there
+				 * is no starget defined in the midlayer.
+				 * Additionally, dynamic target discovery to the
+				 * midlayer is not supported yet.
+				 */
+				if (targetp->starget) {
+					/* Remove SCSI target / SCSI Hotplug */
+					lpfc_target_remove(phba, targetp);
+				}
+#endif /* RHEL_FC */
+				break;
+			}
+		}
+	}
+	return (0);
+}
+
+/*
+ * Check to see if we can free the nlp back to the freelist.
+ * If we are in the middle of using the nlp in the discovery state
+ * machine, defer the free till we reach the end of the state machine.
+ */
+int
+lpfc_nlp_remove(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
+{
+
+	if(ndlp->nlp_flag & NLP_NODEV_TMO) {
+		ndlp->nlp_flag &= ~NLP_NODEV_TMO;
+		spin_unlock_irq(phba->host->host_lock);
+		del_timer_sync(&ndlp->nlp_tmofunc);
+		spin_lock_irq(phba->host->host_lock);
+		if (!list_empty(&ndlp->nodev_timeout_evt.
+				evt_listp))
+			list_del_init(&ndlp->nodev_timeout_evt.
+				      evt_listp);
+	}
+
+	if(ndlp->nlp_flag & NLP_DELAY_TMO) {
+		ndlp->nlp_flag &= ~NLP_DELAY_TMO;
+		spin_unlock_irq(phba->host->host_lock);
+		del_timer_sync(&ndlp->nlp_delayfunc);
+		spin_lock_irq(phba->host->host_lock);
+		if (!list_empty(&ndlp->els_retry_evt.
+				evt_listp))
+			list_del_init(&ndlp->els_retry_evt.
+				      evt_listp);
+	}
+
+	if (ndlp->nlp_disc_refcnt) {
+		ndlp->nlp_flag |= NLP_DELAY_REMOVE;
+	}
+	else {
+		lpfc_freenode(phba, ndlp);
+		mempool_free( ndlp, phba->nlp_mem_pool);
+	}
+	return(0);
+}
+
+static int
+lpfc_matchdid(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, uint32_t did)
+{
+	D_ID mydid;
+	D_ID ndlpdid;
+	D_ID matchdid;
+
+	if (did == Bcast_DID)
+		return (0);
+
+	if (ndlp->nlp_DID == 0) {
+		return (0);
+	}
+
+	/* First check for Direct match */
+	if (ndlp->nlp_DID == did)
+		return (1);
+
+	/* Next check for area/domain identically equals 0 match */
+	mydid.un.word = phba->fc_myDID;
+	if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
+		return (0);
+	}
+
+	matchdid.un.word = did;
+	ndlpdid.un.word = ndlp->nlp_DID;
+	if (matchdid.un.b.id == ndlpdid.un.b.id) {
+		if ((mydid.un.b.domain == matchdid.un.b.domain) &&
+		    (mydid.un.b.area == matchdid.un.b.area)) {
+			if ((ndlpdid.un.b.domain == 0) &&
+			    (ndlpdid.un.b.area == 0)) {
+				if (ndlpdid.un.b.id)
+					return (1);
+			}
+			return (0);
+		}
+
+		matchdid.un.word = ndlp->nlp_DID;
+		if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
+		    (mydid.un.b.area == ndlpdid.un.b.area)) {
+			if ((matchdid.un.b.domain == 0) &&
+			    (matchdid.un.b.area == 0)) {
+				if (matchdid.un.b.id)
+					return (1);
+			}
+		}
+	}
+	return (0);
+}
+
+/* Search for a nodelist entry on a specific list */
+struct lpfc_nodelist *
+lpfc_findnode_wwpn(struct lpfc_hba * phba, uint32_t order,
+		   struct lpfc_name * wwpn)
+{
+	struct lpfc_nodelist *ndlp, *next_ndlp;
+	uint32_t data1;
+
+	if (order & NLP_SEARCH_UNMAPPED) {
+		list_for_each_entry_safe(ndlp, next_ndlp,
+					 &phba->fc_nlpunmap_list, nlp_listp) {
+			if (memcmp(&ndlp->nlp_portname, wwpn,
+				   sizeof(struct lpfc_name)) == 0) {
+
+				data1 = (((uint32_t) ndlp->nlp_state << 24) |
+					 ((uint32_t) ndlp->nlp_xri << 16) |
+					 ((uint32_t) ndlp->nlp_type << 8) |
+					 ((uint32_t) ndlp->nlp_rpi & 0xff));
+				/* FIND node DID unmapped */
+				lpfc_printf_log(phba,
+						KERN_INFO,
+						LOG_NODE,
+						"%d:0911 FIND node DID unmapped"
+						" Data: x%p x%x x%x x%x\n",
+						phba->brd_no,
+						ndlp, ndlp->nlp_DID,
+						ndlp->nlp_flag, data1);
+				return (ndlp);
+			}
+		}
+	}
+
+	if (order & NLP_SEARCH_MAPPED) {
+		list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpmap_list,
+					nlp_listp) {
+			if (memcmp(&ndlp->nlp_portname, wwpn,
+				   sizeof(struct lpfc_name)) == 0) {
+
+				data1 = (((uint32_t) ndlp->nlp_state << 24) |
+					 ((uint32_t) ndlp->nlp_xri << 16) |
+					 ((uint32_t) ndlp->nlp_type << 8) |
+					 ((uint32_t) ndlp->nlp_rpi & 0xff));
+				/* FIND node DID mapped */
+				lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
+						"%d:0901 FIND node DID mapped "
+						"Data: x%p x%x x%x x%x\n",
+						phba->brd_no,
+						ndlp, ndlp->nlp_DID,
+						ndlp->nlp_flag, data1);
+				return (ndlp);
+			}
+		}
+	}
+
+	/* no match found */
+	return ((struct lpfc_nodelist *) 0);
+}
+/* Search for a nodelist entry on a specific list */
+struct lpfc_nodelist *
+lpfc_findnode_wwnn(struct lpfc_hba * phba, uint32_t order,
+		   struct lpfc_name * wwnn)
+{
+	struct lpfc_nodelist *ndlp, *next_ndlp;
+	uint32_t data1;
+
+	if (order & NLP_SEARCH_UNMAPPED) {
+		list_for_each_entry_safe(ndlp, next_ndlp,
+					 &phba->fc_nlpunmap_list, nlp_listp) {
+			if (memcmp(&ndlp->nlp_nodename, wwnn,
+				   sizeof(struct lpfc_name)) ==  0) {
+
+				data1 = (((uint32_t) ndlp->nlp_state << 24) |
+					 ((uint32_t) ndlp->nlp_xri << 16) |
+					 ((uint32_t) ndlp->nlp_type << 8) |
+					 ((uint32_t) ndlp->nlp_rpi & 0xff));
+				/* FIND node DID unmapped */
+				lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
+						"%d:0910 FIND node DID unmapped"
+						"Data: x%p x%x x%x x%x\n",
+						phba->brd_no,
+						ndlp, ndlp->nlp_DID,
+						ndlp->nlp_flag, data1);
+				return (ndlp);
+			}
+		}
+	}
+
+	if (order & NLP_SEARCH_MAPPED) {
+		list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpmap_list,
+					 nlp_listp) {
+			if (memcmp(&ndlp->nlp_nodename, wwnn,
+				   sizeof(struct lpfc_name)) == 0) {
+
+				data1 = (((uint32_t) ndlp->nlp_state << 24) |
+					 ((uint32_t) ndlp->nlp_xri << 16) |
+					 ((uint32_t) ndlp->nlp_type << 8) |
+					 ((uint32_t) ndlp->nlp_rpi & 0xff));
+				/* FIND node did mapped */
+				lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
+						"%d:0902 FIND node DID mapped "
+						"Data: x%p x%x x%x x%x\n",
+						phba->brd_no,
+						ndlp, ndlp->nlp_DID,
+						ndlp->nlp_flag, data1);
+				return (ndlp);
+			}
+		}
+	}
+
+	/* no match found */
+	return ((struct lpfc_nodelist *) 0);
+}
+/* Search for a nodelist entry on a specific list */
+struct lpfc_nodelist *
+lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order, uint32_t did)
+{
+	struct lpfc_nodelist *ndlp, *next_ndlp;
+	uint32_t data1;
+
+	if (order & NLP_SEARCH_UNMAPPED) {
+		list_for_each_entry_safe(ndlp, next_ndlp,
+					 &phba->fc_nlpunmap_list, nlp_listp) {
+			if (lpfc_matchdid(phba, ndlp, did)) {
+				data1 = (((uint32_t) ndlp->nlp_state << 24) |
+					 ((uint32_t) ndlp->nlp_xri << 16) |
+					 ((uint32_t) ndlp->nlp_type << 8) |
+					 ((uint32_t) ndlp->nlp_rpi & 0xff));
+				/* FIND node DID unmapped */
+				lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
+						"%d:0929 FIND node DID unmapped"
+						" Data: x%p x%x x%x x%x\n",
+						phba->brd_no,
+						ndlp, ndlp->nlp_DID,
+						ndlp->nlp_flag, data1);
+				return (ndlp);
+			}
+		}
+	}
+
+	if (order & NLP_SEARCH_MAPPED) {
+		list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpmap_list,
+					nlp_listp) {
+			if (lpfc_matchdid(phba, ndlp, did)) {
+
+				data1 = (((uint32_t) ndlp->nlp_state << 24) |
+					 ((uint32_t) ndlp->nlp_xri << 16) |
+					 ((uint32_t) ndlp->nlp_type << 8) |
+					 ((uint32_t) ndlp->nlp_rpi & 0xff));
+				/* FIND node DID mapped */
+				lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
+						"%d:0930 FIND node DID mapped "
+						"Data: x%p x%x x%x x%x\n",
+						phba->brd_no,
+						ndlp, ndlp->nlp_DID,
+						ndlp->nlp_flag, data1);
+				return (ndlp);
+			}
+		}
+	}
+
+	if (order & NLP_SEARCH_PLOGI) {
+		list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
+					nlp_listp) {
+			if (lpfc_matchdid(phba, ndlp, did)) {
+
+				data1 = (((uint32_t) ndlp->nlp_state << 24) |
+					 ((uint32_t) ndlp->nlp_xri << 16) |
+					 ((uint32_t) ndlp->nlp_type << 8) |
+					 ((uint32_t) ndlp->nlp_rpi & 0xff));
+				/* LOG change to PLOGI */
+				/* FIND node DID plogi */
+				lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
+						"%d:0908 FIND node DID plogi "
+						"Data: x%p x%x x%x x%x\n",
+						phba->brd_no,
+						ndlp, ndlp->nlp_DID,
+						ndlp->nlp_flag, data1);
+				return (ndlp);
+			}
+		}
+	}
+
+	if (order & NLP_SEARCH_ADISC) {
+		list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
+					nlp_listp) {
+			if (lpfc_matchdid(phba, ndlp, did)) {
+
+				data1 = (((uint32_t) ndlp->nlp_state << 24) |
+					 ((uint32_t) ndlp->nlp_xri << 16) |
+					 ((uint32_t) ndlp->nlp_type << 8) |
+					 ((uint32_t) ndlp->nlp_rpi & 0xff));
+				/* LOG change to ADISC */
+				/* FIND node DID adisc */
+				lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
+						"%d:0931 FIND node DID adisc "
+						"Data: x%p x%x x%x x%x\n",
+						phba->brd_no,
+						ndlp, ndlp->nlp_DID,
+						ndlp->nlp_flag, data1);
+				return (ndlp);
+			}
+		}
+	}
+
+	if (order & NLP_SEARCH_REGLOGIN) {
+		list_for_each_entry_safe(ndlp, next_ndlp,
+					 &phba->fc_reglogin_list, nlp_listp) {
+			if (lpfc_matchdid(phba, ndlp, did)) {
+
+				data1 = (((uint32_t) ndlp->nlp_state << 24) |
+					 ((uint32_t) ndlp->nlp_xri << 16) |
+					 ((uint32_t) ndlp->nlp_type << 8) |
+					 ((uint32_t) ndlp->nlp_rpi & 0xff));
+				/* LOG change to REGLOGIN */
+				/* FIND node DID reglogin */
+				lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
+						"%d:0933 FIND node DID reglogin"
+						" Data: x%p x%x x%x x%x\n",
+						phba->brd_no,
+						ndlp, ndlp->nlp_DID,
+						ndlp->nlp_flag, data1);
+				return (ndlp);
+			}
+		}
+	}
+
+	if (order & NLP_SEARCH_PRLI) {
+		list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_prli_list,
+					nlp_listp) {
+			if (lpfc_matchdid(phba, ndlp, did)) {
+
+				data1 = (((uint32_t) ndlp->nlp_state << 24) |
+					 ((uint32_t) ndlp->nlp_xri << 16) |
+					 ((uint32_t) ndlp->nlp_type << 8) |
+					 ((uint32_t) ndlp->nlp_rpi & 0xff));
+				/* LOG change to PRLI */
+				/* FIND node DID prli */
+				lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
+						"%d:0934 FIND node DID prli "
+						"Data: x%p x%x x%x x%x\n",
+						phba->brd_no,
+						ndlp, ndlp->nlp_DID,
+						ndlp->nlp_flag, data1);
+				return (ndlp);
+			}
+		}
+	}
+
+	if (order & NLP_SEARCH_NPR) {
+		list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
+					nlp_listp) {
+			if (lpfc_matchdid(phba, ndlp, did)) {
+
+				data1 = (((uint32_t) ndlp->nlp_state << 24) |
+					 ((uint32_t) ndlp->nlp_xri << 16) |
+					 ((uint32_t) ndlp->nlp_type << 8) |
+					 ((uint32_t) ndlp->nlp_rpi & 0xff));
+				/* LOG change to NPR */
+				/* FIND node DID npr */
+				lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
+						"%d:0935 FIND node DID npr "
+						"Data: x%p x%x x%x x%x\n",
+						phba->brd_no,
+						ndlp, ndlp->nlp_DID,
+						ndlp->nlp_flag, data1);
+				return (ndlp);
+			}
+		}
+	}
+
+	if (order & NLP_SEARCH_UNUSED) {
+		list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
+					nlp_listp) {
+			if (lpfc_matchdid(phba, ndlp, did)) {
+
+				data1 = (((uint32_t) ndlp->nlp_state << 24) |
+					 ((uint32_t) ndlp->nlp_xri << 16) |
+					 ((uint32_t) ndlp->nlp_type << 8) |
+					 ((uint32_t) ndlp->nlp_rpi & 0xff));
+				/* LOG change to UNUSED */
+				/* FIND node DID unused */
+				lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
+						"%d:0936 FIND node DID unused "
+						"Data: x%p x%x x%x x%x\n",
+						phba->brd_no,
+						ndlp, ndlp->nlp_DID,
+						ndlp->nlp_flag, data1);
+				return (ndlp);
+			}
+		}
+	}
+
+	/* FIND node did <did> NOT FOUND */
+	lpfc_printf_log(phba,
+			KERN_INFO,
+			LOG_NODE,
+			"%d:0932 FIND node did x%x NOT FOUND Data: x%x\n",
+			phba->brd_no, did, order);
+
+	/* no match found */
+	return ((struct lpfc_nodelist *) 0);
+}
+
+struct lpfc_nodelist *
+lpfc_setup_disc_node(struct lpfc_hba * phba, uint32_t did)
+{
+	struct lpfc_nodelist *ndlp;
+	uint32_t flg;
+
+	if((ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did)) == 0) {
+		if ((phba->hba_state == LPFC_HBA_READY) &&
+		   ((lpfc_rscn_payload_check(phba, did) == 0)))
+			return NULL;
+		ndlp = (struct lpfc_nodelist *)
+		     mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
+		if (!ndlp)
+			return NULL;
+		lpfc_nlp_init(phba, ndlp, did);
+		ndlp->nlp_state = NLP_STE_NPR_NODE;
+		lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
+		ndlp->nlp_flag |= NLP_NPR_2B_DISC;
+		return ndlp;
+	}
+	if ((phba->hba_state == LPFC_HBA_READY) &&
+	    (phba->fc_flag & FC_RSCN_MODE)) {
+		if(lpfc_rscn_payload_check(phba, did)) {
+			ndlp->nlp_flag |= NLP_NPR_2B_DISC;
+		}
+		else {
+			ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
+			ndlp = NULL;
+		}
+	}
+	else {
+		flg = ndlp->nlp_flag & NLP_LIST_MASK;
+		if ((flg == NLP_ADISC_LIST) ||
+	    	(flg == NLP_PLOGI_LIST)) {
+			return NULL;
+		}
+		ndlp->nlp_state = NLP_STE_NPR_NODE;
+		lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
+		ndlp->nlp_flag |= NLP_NPR_2B_DISC;
+	}
+	return ndlp;
+}
+
+/* Build a list of nodes to discover based on the loopmap */
+void
+lpfc_disc_list_loopmap(struct lpfc_hba * phba)
+{
+	int j;
+	uint32_t alpa, index;
+
+	if (phba->hba_state <= LPFC_LINK_DOWN) {
+		return;
+	}
+	if (phba->fc_topology != TOPOLOGY_LOOP) {
+		return;
+	}
+
+	/* Check for loop map present or not */
+	if (phba->alpa_map[0]) {
+		for (j = 1; j <= phba->alpa_map[0]; j++) {
+			alpa = phba->alpa_map[j];
+
+			if (((phba->fc_myDID & 0xff) == alpa) || (alpa == 0)) {
+				continue;
+			}
+			lpfc_setup_disc_node(phba, alpa);
+		}
+	} else {
+		/* No alpamap, so try all alpa's */
+		for (j = 0; j < FC_MAXLOOP; j++) {
+			/* If cfg_scan_down is set, start from highest
+			 * ALPA (0xef) to lowest (0x1).
+			 */
+			if (phba->cfg_scan_down)
+				index = j;
+			else
+				index = FC_MAXLOOP - j - 1;
+			alpa = lpfcAlpaArray[index];
+			if ((phba->fc_myDID & 0xff) == alpa) {
+				continue;
+			}
+
+			lpfc_setup_disc_node(phba, alpa);
+		}
+	}
+	return;
+}
+
+/* Start Link up / RSCN discovery on NPR list */
+void
+lpfc_disc_start(struct lpfc_hba * phba)
+{
+	struct lpfc_sli *psli;
+	LPFC_MBOXQ_t *mbox;
+	struct lpfc_nodelist *ndlp, *next_ndlp;
+	uint32_t did_changed, num_sent;
+	uint32_t clear_la_pending;
+
+	psli = &phba->sli;
+
+	if (phba->hba_state <= LPFC_LINK_DOWN) {
+		return;
+	}
+	if (phba->hba_state == LPFC_CLEAR_LA)
+		clear_la_pending = 1;
+	else
+		clear_la_pending = 0;
+
+	if (phba->hba_state < LPFC_HBA_READY) {
+		phba->hba_state = LPFC_DISC_AUTH;
+	}
+	lpfc_set_disctmo(phba);
+
+	if (phba->fc_prevDID == phba->fc_myDID) {
+		did_changed = 0;
+	} else {
+		did_changed = 1;
+	}
+	phba->fc_prevDID = phba->fc_myDID;
+	phba->num_disc_nodes = 0;
+
+	/* Start Discovery state <hba_state> */
+	lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
+			"%d:0202 Start Discovery hba state x%x "
+			"Data: x%x x%x x%x\n",
+			phba->brd_no, phba->hba_state, phba->fc_flag,
+			phba->fc_plogi_cnt, phba->fc_adisc_cnt);
+
+	/* If our did changed, we MUST do PLOGI */
+	list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
+				nlp_listp) {
+		if(ndlp->nlp_flag & NLP_NPR_2B_DISC) {
+			if(did_changed)
+				ndlp->nlp_flag &= ~NLP_NPR_ADISC;
+		}
+	}
+
+	/* First do ADISCs - if any */
+	num_sent = lpfc_els_disc_adisc(phba);
+
+	if(num_sent)
+		return;
+
+	if ((phba->hba_state < LPFC_HBA_READY) && (!clear_la_pending)) {
+		/* If we get here, there is nothing to ADISC */
+		if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC))) {
+			phba->hba_state = LPFC_CLEAR_LA;
+			lpfc_clear_la(phba, mbox);
+			mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
+			if (lpfc_sli_issue_mbox
+			    (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB))
+			    == MBX_NOT_FINISHED) {
+				mempool_free( mbox, phba->mbox_mem_pool);
+				lpfc_disc_flush_list(phba);
+				psli->ring[(psli->ip_ring)].flag &=
+				    ~LPFC_STOP_IOCB_EVENT;
+				psli->ring[(psli->fcp_ring)].flag &=
+				    ~LPFC_STOP_IOCB_EVENT;
+				psli->ring[(psli->next_ring)].flag &=
+				    ~LPFC_STOP_IOCB_EVENT;
+				phba->hba_state = LPFC_HBA_READY;
+			}
+		}
+	} else {
+		/* Next do PLOGIs - if any */
+		num_sent = lpfc_els_disc_plogi(phba);
+
+		if(num_sent)
+			return;
+
+		if (phba->fc_flag & FC_RSCN_MODE) {
+			/* Check to see if more RSCNs came in while we
+			 * were processing this one.
+			 */
+			if ((phba->fc_rscn_id_cnt == 0) &&
+			    (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
+				phba->fc_flag &= ~FC_RSCN_MODE;
+			} else {
+				lpfc_els_handle_rscn(phba);
+			}
+		}
+	}
+	return;
+}
+
+/*
+ *  Ignore completion for all IOCBs on tx and txcmpl queue for ELS
+ *  ring the match the sppecified nodelist.
+ */
+static void
+lpfc_free_tx(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
+{
+	struct lpfc_sli *psli;
+	IOCB_t     *icmd;
+	struct lpfc_iocbq    *iocb, *next_iocb;
+	struct lpfc_sli_ring *pring;
+	struct lpfc_dmabuf   *mp;
+
+	psli = &phba->sli;
+	pring = &psli->ring[LPFC_ELS_RING];
+
+	/* Error matching iocb on txq or txcmplq
+	 * First check the txq.
+	 */
+	list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
+		if (iocb->context1 != ndlp) {
+			continue;
+		}
+		icmd = &iocb->iocb;
+		if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
+		    (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
+
+			list_del(&iocb->list);
+			pring->txq_cnt--;
+			lpfc_els_free_iocb(phba, iocb);
+		}
+	}
+
+	/* Next check the txcmplq */
+	list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
+		if (iocb->context1 != ndlp) {
+			continue;
+		}
+		icmd = &iocb->iocb;
+		if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
+		    (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
+
+			iocb->iocb_cmpl = NULL;
+			/* context2 = cmd, context2->next = rsp, context3 =
+			   bpl */
+			if (iocb->context2) {
+				/* Free the response IOCB before handling the
+				   command. */
+
+				mp = (struct lpfc_dmabuf *)
+				     (((struct lpfc_dmabuf *) (iocb->context2))
+				    ->list.next);
+				if (mp) {
+					/* Delay before releasing rsp buffer to
+					 * give UNREG mbox a chance to take
+					 * effect.
+					 */
+					list_add(&mp->list,
+						&phba->freebufList);
+				}
+				lpfc_mbuf_free(phba,
+					       ((struct lpfc_dmabuf *)
+						iocb->context2)->virt,
+					       ((struct lpfc_dmabuf *)
+						iocb->context2)->phys);
+				kfree(iocb->context2);
+			}
+
+			if (iocb->context3) {
+				lpfc_mbuf_free(phba,
+					       ((struct lpfc_dmabuf *)
+						iocb->context3)->virt,
+					       ((struct lpfc_dmabuf *)
+						iocb->context3)->phys);
+				kfree(iocb->context3);
+			}
+		}
+	}
+
+	return;
+}
+
+void
+lpfc_disc_flush_list(struct lpfc_hba * phba)
+{
+	struct lpfc_nodelist *ndlp, *next_ndlp;
+
+	if (phba->fc_plogi_cnt) {
+		list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
+					nlp_listp) {
+			lpfc_set_failmask(phba, ndlp, LPFC_DEV_DISCONNECTED,
+					  LPFC_SET_BITMASK);
+			lpfc_free_tx(phba, ndlp);
+			lpfc_nlp_remove(phba, ndlp);
+		}
+	}
+	if (phba->fc_adisc_cnt) {
+		list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
+					nlp_listp) {
+			lpfc_set_failmask(phba, ndlp, LPFC_DEV_DISCONNECTED,
+					  LPFC_SET_BITMASK);
+			lpfc_free_tx(phba, ndlp);
+			lpfc_nlp_remove(phba, ndlp);
+		}
+	}
+	return;
+}
+
+/*****************************************************************************/
+/*
+ * NAME:     lpfc_disc_timeout
+ *
+ * FUNCTION: Fibre Channel driver discovery timeout routine.
+ *
+ * EXECUTION ENVIRONMENT: interrupt only
+ *
+ * CALLED FROM:
+ *      Timer function
+ *
+ * RETURNS:
+ *      none
+ */
+/*****************************************************************************/
+void
+lpfc_disc_timeout(unsigned long ptr)
+{
+	struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
+	unsigned long flags = 0;
+
+	if (unlikely(!phba))
+		return;
+
+	spin_lock_irqsave(phba->host->host_lock, flags);
+	if (!(phba->work_hba_events & WORKER_DISC_TMO)) {
+		phba->work_hba_events |= WORKER_DISC_TMO;
+		if (phba->dpc_wait)
+			up(phba->dpc_wait);
+	}
+	spin_unlock_irqrestore(phba->host->host_lock, flags);
+	return;
+}
+
+static void
+lpfc_disc_timeout_handler(struct lpfc_hba *phba)
+{
+	struct lpfc_sli *psli;
+	struct lpfc_nodelist *ndlp;
+	LPFC_MBOXQ_t *mbox;
+
+	if (!phba) {
+		return;
+	}
+	if (!(phba->fc_flag & FC_DISC_TMO))
+		return;
+
+	psli = &phba->sli;
+	spin_lock_irq(phba->host->host_lock);
+
+	phba->fc_flag &= ~FC_DISC_TMO;
+
+	/* hba_state is identically LPFC_LOCAL_CFG_LINK while waiting for FAN */
+	if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
+		/* FAN timeout */
+		lpfc_printf_log(phba,
+				 KERN_WARNING,
+				 LOG_DISCOVERY,
+				 "%d:0221 FAN timeout\n",
+				 phba->brd_no);
+
+		/* Forget about FAN, Start discovery by sending a FLOGI
+		 * hba_state is identically LPFC_FLOGI while waiting for FLOGI
+		 * cmpl
+		 */
+		phba->hba_state = LPFC_FLOGI;
+		lpfc_set_disctmo(phba);
+		lpfc_initial_flogi(phba);
+		goto out;
+	}
+
+	/* hba_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
+	if (phba->hba_state == LPFC_FLOGI) {
+		/* Initial FLOGI timeout */
+		lpfc_printf_log(phba,
+				 KERN_ERR,
+				 LOG_DISCOVERY,
+				 "%d:0222 Initial FLOGI timeout\n",
+				 phba->brd_no);
+
+		/* Assume no Fabric and go on with discovery.
+		 * Check for outstanding ELS FLOGI to abort.
+		 */
+
+		/* FLOGI failed, so just use loop map to make discovery list */
+		lpfc_disc_list_loopmap(phba);
+
+		/* Start discovery */
+		lpfc_disc_start(phba);
+		goto out;
+	}
+
+	/* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
+	   NameServer login */
+	if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
+		/* Timeout while waiting for NameServer login */
+		lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
+				"%d:0223 Timeout while waiting for NameServer "
+				"login\n", phba->brd_no);
+
+		/* Next look for NameServer ndlp */
+		if ((ndlp = lpfc_findnode_did(phba,
+				       NLP_SEARCH_ALL, NameServer_DID))) {
+			lpfc_nlp_remove(phba, ndlp);
+		}
+		/* Start discovery */
+		lpfc_disc_start(phba);
+		goto out;
+	}
+
+	/* Check for wait for NameServer Rsp timeout */
+	if (phba->hba_state == LPFC_NS_QRY) {
+		/* NameServer Query timeout */
+		lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
+				"%d:0224 NameServer Query timeout "
+				"Data: x%x x%x\n",
+				phba->brd_no,
+				phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
+
+		if ((ndlp =
+		     lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
+				       NameServer_DID))) {
+			if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
+				/* Try it one more time */
+				if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) ==
+				    0) {
+					goto out;
+				}
+			}
+			phba->fc_ns_retry = 0;
+		}
+
+		/* Nothing to authenticate, so CLEAR_LA right now */
+		if (phba->hba_state != LPFC_CLEAR_LA) {
+			if ((mbox = mempool_alloc(phba->mbox_mem_pool,
+						  GFP_ATOMIC))) {
+				phba->hba_state = LPFC_CLEAR_LA;
+				lpfc_clear_la(phba, mbox);
+				mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
+				if (lpfc_sli_issue_mbox
+				    (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB))
+				    == MBX_NOT_FINISHED) {
+					mempool_free(mbox, phba->mbox_mem_pool);
+					goto clrlaerr;
+				}
+			} else {
+				/* Device Discovery completion error */
+				lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
+						"%d:0226 Device Discovery "
+						"completion error\n",
+						phba->brd_no);
+				phba->hba_state = LPFC_HBA_ERROR;
+			}
+		}
+		if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC))) {
+			/* Setup and issue mailbox INITIALIZE LINK command */
+			lpfc_linkdown(phba);
+			lpfc_init_link(phba, mbox,
+				       phba->cfg_topology,
+				       phba->cfg_link_speed);
+			mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
+			mbox->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
+			if (lpfc_sli_issue_mbox
+			    (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB))
+			    == MBX_NOT_FINISHED) {
+				mempool_free( mbox, phba->mbox_mem_pool);
+			}
+		}
+		goto out;
+	}
+
+	if (phba->hba_state == LPFC_DISC_AUTH) {
+		/* Node Authentication timeout */
+		lpfc_printf_log(phba,
+				 KERN_ERR,
+				 LOG_DISCOVERY,
+				 "%d:0227 Node Authentication timeout\n",
+				 phba->brd_no);
+		lpfc_disc_flush_list(phba);
+		if (phba->hba_state != LPFC_CLEAR_LA) {
+			if ((mbox = mempool_alloc(phba->mbox_mem_pool,
+						  GFP_ATOMIC))) {
+				phba->hba_state = LPFC_CLEAR_LA;
+				lpfc_clear_la(phba, mbox);
+				mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
+				if (lpfc_sli_issue_mbox
+				    (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB))
+				    == MBX_NOT_FINISHED) {
+					mempool_free(mbox, phba->mbox_mem_pool);
+					goto clrlaerr;
+				}
+			}
+		}
+		goto out;
+	}
+
+	if (phba->hba_state == LPFC_CLEAR_LA) {
+		/* CLEAR LA timeout */
+		lpfc_printf_log(phba,
+				 KERN_ERR,
+				 LOG_DISCOVERY,
+				 "%d:0228 CLEAR LA timeout\n",
+				 phba->brd_no);
+clrlaerr:
+		lpfc_disc_flush_list(phba);
+		psli->ring[(psli->ip_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
+		psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
+		psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
+		phba->hba_state = LPFC_HBA_READY;
+		goto out;
+	}
+
+	if ((phba->hba_state == LPFC_HBA_READY) &&
+	    (phba->fc_flag & FC_RSCN_MODE)) {
+		/* RSCN timeout */
+		lpfc_printf_log(phba,
+				KERN_ERR,
+				LOG_DISCOVERY,
+				"%d:0231 RSCN timeout Data: x%x x%x\n",
+				phba->brd_no,
+				phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
+
+		/* Cleanup any outstanding ELS commands */
+		lpfc_els_flush_cmd(phba);
+
+		lpfc_els_flush_rscn(phba);
+		lpfc_disc_flush_list(phba);
+		goto out;
+	}
+
+out:
+	spin_unlock_irq(phba->host->host_lock);
+	return;
+}
+
+/*****************************************************************************/
+/*
+ * NAME:     lpfc_scan_timeout
+ *
+ * FUNCTION: Fibre Channel driver scsi_scan_host timeout routine.
+ *
+ * EXECUTION ENVIRONMENT: interrupt only
+ *
+ * CALLED FROM:
+ *      Timer function
+ *
+ * RETURNS:
+ *      none
+ */
+/*****************************************************************************/
+void
+lpfc_scan_timeout(unsigned long ptr)
+{
+	struct lpfc_hba *phba;
+	unsigned long iflag;
+
+	phba = (struct lpfc_hba *)ptr;
+	if (!phba) {
+		return;
+	}
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+	phba->fc_flag &= ~FC_SCSI_SCAN_TMO;
+	lpfc_discq_post_event(phba, NULL, NULL, LPFC_EVT_SCAN);
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+	return;
+}
+
+static void
+lpfc_nodev_timeout(unsigned long ptr)
+{
+	struct lpfc_hba *phba;
+	struct lpfc_nodelist *ndlp;
+	unsigned long iflag;
+	LPFC_DISC_EVT_t *evtp;
+
+	ndlp = (struct lpfc_nodelist *)ptr;
+	phba = ndlp->nlp_phba;
+	evtp = &ndlp->nodev_timeout_evt;
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+
+	if (!list_empty(&evtp->evt_listp)) {
+		spin_unlock_irqrestore(phba->host->host_lock, iflag);
+		return;
+	}
+	evtp->evt_arg1  = ndlp;
+	evtp->evt       = LPFC_EVT_NODEV_TMO;
+	list_add_tail(&evtp->evt_listp, &phba->dpc_disc);
+	if (phba->dpc_wait)
+		up(phba->dpc_wait);
+
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+	return;
+}
+
+
+/*****************************************************************************/
+/*
+ * NAME:     lpfc_find_target
+ *
+ * FUNCTION: Fibre Channel bus/target/LUN to struct lpfc_target lookup
+ *
+ * EXECUTION ENVIRONMENT:
+ *
+ * RETURNS:
+ *      ptr to desired struct lpfc_target
+ */
+/*****************************************************************************/
+struct lpfc_target *
+lpfc_find_target(struct lpfc_hba * phba, uint32_t tgt,
+	struct lpfc_nodelist *nlp)
+{
+	struct lpfc_target *targetp = NULL;
+	int found = 0, i;
+	struct list_head *listp;
+	struct list_head *node_list[6];
+
+	if (tgt == NLP_NO_SID)
+		return NULL;
+
+	if(!nlp) {
+		/* Search over all lists other than fc_nlpunmap_list */
+		node_list[0] = &phba->fc_npr_list;
+		node_list[1] = &phba->fc_nlpmap_list; /* Skip fc_nlpunmap */
+		node_list[2] = &phba->fc_prli_list;
+		node_list[3] = &phba->fc_reglogin_list;
+		node_list[4] = &phba->fc_adisc_list;
+		node_list[5] = &phba->fc_plogi_list;
+		
+		for (i=0; i < 6 && !found; i++) {
+			listp = node_list[i];
+			if (list_empty(listp))
+				continue;
+			list_for_each_entry(nlp, listp, nlp_listp) {
+				if (tgt == nlp->nlp_sid) {
+					found = 1;
+					break;
+				}
+			}
+		}
+
+		if (!found)
+			return NULL;
+	}
+
+	targetp = phba->device_queue_hash[tgt];
+
+	/* First see if the SCSI ID has an allocated struct lpfc_target */
+	if (!targetp) {
+		targetp = kmalloc(sizeof (struct lpfc_target), GFP_ATOMIC);
+		if (!targetp)
+			return NULL;
+
+		memset(targetp, 0, sizeof (struct lpfc_target));
+#ifdef SLES_FC
+		init_timer(&targetp->dev_loss_timer);
+#endif
+		phba->device_queue_hash[tgt] = targetp;
+		targetp->scsi_id = tgt;
+
+		/* Create SCSI Target <tgt> */
+		lpfc_printf_log(phba,
+				KERN_INFO,
+				LOG_DISCOVERY | LOG_FCP,
+				"%d:0204 Create SCSI Target %d\n",
+				phba->brd_no, tgt);
+	}
+
+	if (targetp->pnode == NULL) {
+		targetp->pnode = nlp;
+		nlp->nlp_Target = targetp;
+#ifdef RHEL_FC
+		/*
+		 * This code does not apply to SLES9 since there is no
+		 * starget defined in the midlayer.  Additionally,
+		 * dynamic target discovery to the midlayer is not
+		 * supported yet.
+		 */
+		if(!(phba->fc_flag & FC_LOADING)) {
+			/* Add SCSI target / SCSI Hotplug if called
+			 * after initial driver load.
+			 */
+			lpfc_target_add(phba, targetp);
+		}
+#endif /* RHEL_FC */
+	}
+	else {
+		if(targetp->pnode != nlp) {
+			/*
+			 * The scsi-id exists but the nodepointer is different.
+			 * We are reassigning the scsi-id. Attach the nodelist
+			 * pointer to the correct target. This is common
+			 * with a target side cable swap.
+			 */
+			if (targetp->pnode->nlp_Target != targetp)
+				targetp->pnode = nlp;
+		}
+	}
+	nlp->nlp_Target = targetp;
+	return (targetp);
+}
+
+/*
+ *   lpfc_set_failmask
+ *   Set, or clear, failMask bits in struct lpfc_nodelist
+ */
+void
+lpfc_set_failmask(struct lpfc_hba * phba,
+		  struct lpfc_nodelist * ndlp, uint32_t bitmask, uint32_t flag)
+{
+	uint32_t oldmask;
+	uint32_t changed;
+
+	/* Failmask change on NPort <nlp_DID> */
+	lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
+			"%d:0208 Failmask change on NPort x%x "
+			"Data: x%x x%x x%x\n",
+			phba->brd_no,
+			ndlp->nlp_DID, ndlp->nlp_failMask, bitmask, flag);
+
+	if (flag == LPFC_SET_BITMASK) {
+		oldmask = ndlp->nlp_failMask;
+		/* Set failMask event */
+		ndlp->nlp_failMask |= bitmask;
+		if (oldmask != ndlp->nlp_failMask) {
+			changed = 1;
+		} else {
+			changed = 0;
+		}
+
+	} else {
+		/* Clear failMask event */
+		ndlp->nlp_failMask &= ~bitmask;
+		changed = 1;
+	}
+	return;
+}
+
+/*
+ * This routine handles processing a NameServer REG_LOGIN mailbox
+ * command upon completion. It is setup in the LPFC_MBOXQ
+ * as the completion routine when the command is
+ * handed off to the SLI layer.
+ */
+void
+lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
+{
+	struct lpfc_sli *psli;
+	MAILBOX_t *mb;
+	struct lpfc_dmabuf *mp;
+	struct lpfc_nodelist *ndlp;
+
+	psli = &phba->sli;
+	mb = &pmb->mb;
+
+	ndlp = (struct lpfc_nodelist *) pmb->context2;
+	mp = (struct lpfc_dmabuf *) (pmb->context1);
+
+	pmb->context1 = NULL;
+
+	if (ndlp->nlp_rpi != 0)
+		lpfc_findnode_remove_rpi(phba, ndlp->nlp_rpi);
+	ndlp->nlp_rpi = mb->un.varWords[0];
+	lpfc_addnode_rpi(phba, ndlp, ndlp->nlp_rpi);
+	ndlp->nlp_type |= NLP_FABRIC;
+	ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
+	lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
+
+	/* Start issuing Fabric-Device Management Interface (FDMI)
+	 * command to 0xfffffa (FDMI well known port)
+	 */
+	if (phba->cfg_fdmi_on == 1) {
+		lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
+	} else {
+		/*
+		 * Delay issuing FDMI command if fdmi-on=2
+		 * (supporting RPA/hostnmae)
+		 */
+		mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
+	}
+
+	lpfc_mbuf_free(phba, mp->virt, mp->phys);
+	kfree(mp);
+	mempool_free( pmb, phba->mbox_mem_pool);
+
+	return;
+}
+
+/*
+ * This routine looks up the ndlp hash
+ * table for the given RPI. If rpi found
+ * it return the node list pointer
+ * else return 0.
+ */
+struct lpfc_nodelist *
+lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi)
+{
+	struct lpfc_nodelist *ret;
+
+	ret = phba->fc_nlplookup[LPFC_RPI_HASH_FUNC(rpi)];
+	while ((ret != 0) && (ret->nlp_rpi != rpi)) {
+		ret = ret->nlp_rpi_hash_next;
+	}
+	return ret;
+}
+
+/*
+ * This routine looks up the ndlp hash table for the
+ * given RPI. If rpi found it return the node list
+ * pointer else return 0 after deleting the entry
+ * from hash table.
+ */
+struct lpfc_nodelist *
+lpfc_findnode_remove_rpi(struct lpfc_hba * phba, uint16_t rpi)
+{
+	struct lpfc_nodelist *ret, *temp;;
+
+	ret = phba->fc_nlplookup[LPFC_RPI_HASH_FUNC(rpi)];
+	if (ret == 0)
+		return NULL;
+
+	if (ret->nlp_rpi == rpi) {
+		phba->fc_nlplookup[LPFC_RPI_HASH_FUNC(rpi)] =
+		    ret->nlp_rpi_hash_next;
+		ret->nlp_rpi_hash_next = NULL;
+		return ret;
+	}
+
+	while ((ret->nlp_rpi_hash_next != 0) &&
+	       (ret->nlp_rpi_hash_next->nlp_rpi != rpi)) {
+		ret = ret->nlp_rpi_hash_next;
+	}
+
+	if (ret->nlp_rpi_hash_next != 0) {
+		temp = ret->nlp_rpi_hash_next;
+		ret->nlp_rpi_hash_next = temp->nlp_rpi_hash_next;
+		temp->nlp_rpi_hash_next = NULL;
+		return temp;
+	} else {
+		return NULL;
+	}
+}
+
+/*
+ * This routine adds the node list entry to the
+ * ndlp hash table.
+ */
+void
+lpfc_addnode_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
+		 uint16_t rpi)
+{
+
+	uint32_t index;
+
+	index = LPFC_RPI_HASH_FUNC(rpi);
+	ndlp->nlp_rpi_hash_next = phba->fc_nlplookup[index];
+	phba->fc_nlplookup[index] = ndlp;
+	return;
+}
+
+void
+lpfc_nlp_init(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
+		 uint32_t did)
+{
+	memset(ndlp, 0, sizeof (struct lpfc_nodelist));
+	INIT_LIST_HEAD(&ndlp->nodev_timeout_evt.evt_listp);
+	INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
+	init_timer(&ndlp->nlp_tmofunc);
+	ndlp->nlp_tmofunc.function = lpfc_nodev_timeout;
+	ndlp->nlp_tmofunc.data = (unsigned long)ndlp;
+	init_timer(&ndlp->nlp_delayfunc);
+	ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
+	ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
+	ndlp->nlp_DID = did;
+	ndlp->nlp_phba = phba;
+	ndlp->nlp_sid = NLP_NO_SID;
+	return;
+}
+
--- linux-2.6.8.1-t044-driver-update//drivers/scsi/lpfc/lpfc_nportdisc.c	1970-01-01 03:00:00.000000000 +0300
+++ rhel4u2//drivers/scsi/lpfc/lpfc_nportdisc.c	2005-10-19 11:47:17.000000000 +0400
@@ -0,0 +1,2038 @@
+/*******************************************************************
+ * This file is part of the Emulex Linux Device Driver for         *
+ * Fibre Channel Host Bus Adapters.                                *
+ * Copyright (C) 2003-2005 Emulex.  All rights reserved.           *
+ * EMULEX and SLI are trademarks of Emulex.                        *
+ * www.emulex.com                                                  *
+ *                                                                 *
+ * This program is free software; you can redistribute it and/or   *
+ * modify it under the terms of version 2 of the GNU General       *
+ * Public License as published by the Free Software Foundation.    *
+ * This program is distributed in the hope that it will be useful. *
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
+ * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
+ * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
+ * more details, a copy of which can be found in the file COPYING  *
+ * included with this package.                                     *
+ *******************************************************************/
+
+/*
+ * $Id: lpfc_nportdisc.c 1.160.1.2 2005/06/13 17:16:39EDT sf_support Exp  $
+ */
+
+#include <linux/version.h>
+#include <linux/blkdev.h>
+#include <linux/dma-mapping.h>
+#include <linux/pci.h>
+#include <linux/spinlock.h>
+#include <scsi/scsi_device.h>
+#include <scsi/scsi_host.h>
+#include "lpfc_sli.h"
+#include "lpfc_disc.h"
+#include "lpfc_scsi.h"
+#include "lpfc.h"
+#include "lpfc_crtn.h"
+#include "lpfc_hw.h"
+#include "lpfc_logmsg.h"
+#include "lpfc_mem.h"
+
+extern uint8_t lpfcAlpaArray[];
+
+
+/* Called to verify a rcv'ed ADISC was intended for us. */
+static int
+lpfc_check_adisc(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
+		 struct lpfc_name * nn, struct lpfc_name * pn)
+{
+	/* Compare the ADISC rsp WWNN / WWPN matches our internal node
+	 * table entry for that node.
+	 */
+	if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)) != 0)
+		return (0);
+
+	if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)) != 0)
+		return (0);
+
+	/* we match, return success */
+	return (1);
+}
+
+
+int
+lpfc_check_sparm(struct lpfc_hba * phba,
+		 struct lpfc_nodelist * ndlp, struct serv_parm * sp,
+		 uint32_t class)
+{
+	volatile struct serv_parm *hsp = &phba->fc_sparam;
+	/* First check for supported version */
+
+	/* Next check for class validity */
+	if (sp->cls1.classValid) {
+
+		if (sp->cls1.rcvDataSizeMsb > hsp->cls1.rcvDataSizeMsb)
+			sp->cls1.rcvDataSizeMsb = hsp->cls1.rcvDataSizeMsb;
+		if (sp->cls1.rcvDataSizeLsb > hsp->cls1.rcvDataSizeLsb)
+			sp->cls1.rcvDataSizeLsb = hsp->cls1.rcvDataSizeLsb;
+	} else if (class == CLASS1) {
+		return (0);
+	}
+
+	if (sp->cls2.classValid) {
+
+		if (sp->cls2.rcvDataSizeMsb > hsp->cls2.rcvDataSizeMsb)
+			sp->cls2.rcvDataSizeMsb = hsp->cls2.rcvDataSizeMsb;
+		if (sp->cls2.rcvDataSizeLsb > hsp->cls2.rcvDataSizeLsb)
+			sp->cls2.rcvDataSizeLsb = hsp->cls2.rcvDataSizeLsb;
+	} else if (class == CLASS2) {
+		return (0);
+	}
+
+	if (sp->cls3.classValid) {
+
+		if (sp->cls3.rcvDataSizeMsb > hsp->cls3.rcvDataSizeMsb)
+			sp->cls3.rcvDataSizeMsb = hsp->cls3.rcvDataSizeMsb;
+		if (sp->cls3.rcvDataSizeLsb > hsp->cls3.rcvDataSizeLsb)
+			sp->cls3.rcvDataSizeLsb = hsp->cls3.rcvDataSizeLsb;
+	} else if (class == CLASS3) {
+		return (0);
+	}
+
+	if (sp->cmn.bbRcvSizeMsb > hsp->cmn.bbRcvSizeMsb)
+		sp->cmn.bbRcvSizeMsb = hsp->cmn.bbRcvSizeMsb;
+	if (sp->cmn.bbRcvSizeLsb > hsp->cmn.bbRcvSizeLsb)
+		sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
+
+	/* If check is good, copy wwpn wwnn into ndlp */
+	memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
+	memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
+	return (1);
+}
+
+static void *
+lpfc_check_elscmpl_iocb(struct lpfc_hba * phba,
+		      struct lpfc_iocbq *cmdiocb,
+		      struct lpfc_iocbq *rspiocb)
+{
+	struct lpfc_dmabuf *pcmd, *prsp;
+	uint32_t *lp;
+	void     *ptr;
+	IOCB_t   *irsp;
+
+	irsp = &rspiocb->iocb;
+	pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
+
+	/* For lpfc_els_abort, context2 could be zero'ed to delay
+	 * freeing associated memory till after ABTS completes.
+	 */
+	if (pcmd) {
+		prsp = (struct lpfc_dmabuf *) pcmd->list.next;
+		lp = (uint32_t *) prsp->virt;
+
+		ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
+	}
+	else {
+		/* Force ulpStatus error since we are returning NULL ptr */
+		if (!(irsp->ulpStatus)) {
+			irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
+			irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
+		}
+		ptr = NULL;
+	}
+	return (ptr);
+}
+
+
+/*
+ * Free resources / clean up outstanding I/Os
+ * associated with a LPFC_NODELIST entry. This
+ * routine effectively results in a "software abort".
+ */
+int
+lpfc_els_abort(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
+	int send_abts)
+{
+	struct lpfc_sli *psli;
+	struct lpfc_sli_ring *pring;
+	struct lpfc_iocbq *iocb, *next_iocb, *saveq;
+	IOCB_t *icmd;
+	int found = 0;
+	LPFC_DISC_EVT_t  *evtp, *next_evtp;
+
+	/* Abort outstanding I/O on NPort <nlp_DID> */
+	lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
+			"%d:0205 Abort outstanding I/O on NPort x%x "
+			"Data: x%x x%x x%x\n",
+			phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
+			ndlp->nlp_state, ndlp->nlp_rpi);
+
+	psli = &phba->sli;
+	pring = &psli->ring[LPFC_ELS_RING];
+
+	/* Abort all the ELS iocbs in the dpc thread. */
+	list_for_each_entry_safe(evtp, next_evtp, &phba->dpc_disc,evt_listp) {
+		if (evtp->evt != LPFC_EVT_SOL_IOCB)
+			continue;
+
+		iocb = (struct lpfc_iocbq *)(evtp->evt_arg1);
+		saveq = (struct lpfc_iocbq *)(evtp->evt_arg2);
+
+		if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp) == 0)
+			continue;
+
+		list_del_init(&evtp->evt_listp);
+		icmd = &iocb->iocb;
+		icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
+		icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
+		(iocb->iocb_cmpl) (phba, iocb, saveq);
+		lpfc_evt_iocb_free(phba, saveq);
+		kfree(evtp);
+	}
+
+	/* First check the txq */
+	do {
+		found = 0;
+		list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
+			/* Check to see if iocb matches the nport we are looking for */
+			if ((lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))) {
+				found = 1;
+				/* It matches, so deque and call compl with an error */
+				list_del(&iocb->list);
+				pring->txq_cnt--;
+				if (iocb->iocb_cmpl) {
+					icmd = &iocb->iocb;
+					icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
+					icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
+					(iocb->iocb_cmpl) (phba, iocb, iocb);
+				} else {
+					mempool_free(iocb, phba->iocb_mem_pool);
+				}
+				break;
+			}
+		}
+
+	} while (found);
+
+	/* Everything on txcmplq will be returned by firmware
+ 	* with a no rpi / linkdown / abort error.  For ring 0,
+	* ELS discovery, we want to get rid of it right here.
+ 	*/
+	/* Next check the txcmplq */
+	do {
+		found = 0;
+		list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
+			/* Check to see if iocb matches the nport we are looking for */
+			if ((lpfc_check_sli_ndlp (phba, pring, iocb, ndlp))) {
+				found = 1;
+				/* It matches, so deque and call compl with an error */
+				list_del(&iocb->list);
+				pring->txcmplq_cnt--;
+
+				icmd = &iocb->iocb;
+				/* If the driver is completing an ELS
+				 * command early, flush it out of the firmware.
+				 */
+				if (send_abts &&
+				    (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) &&
+				    (icmd->un.elsreq64.bdl.ulpIoTag32)) {
+					lpfc_sli_issue_abort_iotag32(phba, pring, iocb);
+				}
+				if (iocb->iocb_cmpl) {
+					icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
+					icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
+					(iocb->iocb_cmpl) (phba, iocb, iocb);
+				} else {
+					mempool_free(iocb, phba->iocb_mem_pool);
+				}
+				break;
+			}
+		}
+	} while (found);
+
+	
+	/* If we are delaying issuing an ELS command, cancel it */
+	if(ndlp->nlp_flag & NLP_DELAY_TMO) {
+		ndlp->nlp_flag &= ~NLP_DELAY_TMO;
+		spin_unlock_irq(phba->host->host_lock);
+		del_timer_sync(&ndlp->nlp_delayfunc);
+		spin_lock_irq(phba->host->host_lock);
+		if (!list_empty(&ndlp->els_retry_evt.
+				evt_listp))
+			list_del_init(&ndlp->els_retry_evt.
+				      evt_listp);
+	}
+	return (0);
+}
+
+static int
+lpfc_rcv_plogi(struct lpfc_hba * phba,
+		      struct lpfc_nodelist * ndlp,
+		      struct lpfc_iocbq *cmdiocb)
+{
+	struct lpfc_dmabuf *pcmd;
+	uint32_t *lp;
+	IOCB_t *icmd;
+	struct serv_parm *sp;
+	LPFC_MBOXQ_t *mbox;
+	struct ls_rjt stat;
+
+	memset(&stat, 0, sizeof (struct ls_rjt));
+	if (phba->hba_state <= LPFC_FLOGI) {
+		/* Before responding to PLOGI, check for pt2pt mode.
+		 * If we are pt2pt, with an outstanding FLOGI, abort
+		 * the FLOGI and resend it first.
+		 */
+		if (phba->fc_flag & FC_PT2PT) {
+			lpfc_els_abort_flogi(phba);
+		        if(!(phba->fc_flag & FC_PT2PT_PLOGI)) {
+				/* If the other side is supposed to initiate
+				 * the PLOGI anyway, just ACC it now and
+				 * move on with discovery.
+				 */
+				phba->fc_edtov = FF_DEF_EDTOV;
+				phba->fc_ratov = FF_DEF_RATOV;
+				/* Start discovery - this should just do
+				   CLEAR_LA */
+				lpfc_disc_start(phba);
+			}
+			else {
+				lpfc_initial_flogi(phba);
+			}
+		}
+		else {
+			stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
+			stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
+			goto out;
+		}
+	}
+	pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
+	lp = (uint32_t *) pcmd->virt;
+	sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
+	if ((lpfc_check_sparm(phba, ndlp, sp, CLASS3) == 0)) {
+		/* Reject this request because invalid parameters */
+		stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
+		stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
+		goto out;
+	}
+	icmd = &cmdiocb->iocb;
+
+	/* PLOGI chkparm OK */
+	lpfc_printf_log(phba,
+			KERN_INFO,
+			LOG_ELS,
+			"%d:0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
+			phba->brd_no,
+			ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
+			ndlp->nlp_rpi);
+
+	if ((phba->cfg_fcp_class == 2) &&
+	    (sp->cls2.classValid)) {
+		ndlp->nlp_fcp_info |= CLASS2;
+	} else {
+		ndlp->nlp_fcp_info |= CLASS3;
+	}
+
+	/* no need to reg_login if we are already in one of these states */
+	switch(ndlp->nlp_state) {
+	case  NLP_STE_NPR_NODE:
+		if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
+			break;
+	case  NLP_STE_REG_LOGIN_ISSUE:
+	case  NLP_STE_PRLI_ISSUE:
+	case  NLP_STE_UNMAPPED_NODE:
+	case  NLP_STE_MAPPED_NODE:
+		lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, 0);
+		return (1);
+	}
+
+	if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC)) == 0) {
+		stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
+		stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
+		goto out;
+	}
+
+	if ((phba->fc_flag & FC_PT2PT)
+	    && !(phba->fc_flag & FC_PT2PT_PLOGI)) {
+		/* rcv'ed PLOGI decides what our NPortId will be */
+		phba->fc_myDID = icmd->un.rcvels.parmRo;
+		lpfc_config_link(phba, mbox);
+		mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
+		if (lpfc_sli_issue_mbox
+		    (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB))
+		    == MBX_NOT_FINISHED) {
+			mempool_free( mbox, phba->mbox_mem_pool);
+			stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
+			stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
+			goto out;
+		}
+		if ((mbox = mempool_alloc(phba->mbox_mem_pool,
+			GFP_ATOMIC)) == 0) {
+			stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
+			stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
+			goto out;
+		}
+		lpfc_can_disctmo(phba);
+	}
+
+	if(lpfc_reg_login(phba, icmd->un.rcvels.remoteID,
+			   (uint8_t *) sp, mbox, 0)) {
+		mempool_free( mbox, phba->mbox_mem_pool);
+		stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
+		stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
+out:
+		lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
+		return (0);
+	}
+
+	/* ACC PLOGI rsp command needs to execute first,
+	 * queue this mbox command to be processed later.
+	 */
+	mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
+	mbox->context2  = ndlp;
+	ndlp->nlp_flag |= NLP_ACC_REGLOGIN;
+
+	/* If there is an outstanding PLOGI issued, abort it before
+	 * sending ACC rsp to PLOGI recieved.
+	 */
+	if(ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
+		/* software abort outstanding PLOGI */
+		lpfc_els_abort(phba, ndlp, 1);
+	}
+	ndlp->nlp_flag |= NLP_RCV_PLOGI;
+	lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox, 0);
+	return (1);
+}
+
+static int
+lpfc_rcv_padisc(struct lpfc_hba * phba,
+		struct lpfc_nodelist * ndlp,
+		struct lpfc_iocbq *cmdiocb)
+{
+	struct lpfc_dmabuf *pcmd;
+	struct serv_parm *sp;
+	struct lpfc_name *pnn, *ppn;
+	struct ls_rjt stat;
+	ADISC *ap;
+	IOCB_t *icmd;
+	uint32_t *lp;
+	uint32_t cmd;
+
+	pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
+	lp = (uint32_t *) pcmd->virt;
+
+	cmd = *lp++;
+	if (cmd == ELS_CMD_ADISC) {
+		ap = (ADISC *) lp;
+		pnn = (struct lpfc_name *) & ap->nodeName;
+		ppn = (struct lpfc_name *) & ap->portName;
+	} else {
+		sp = (struct serv_parm *) lp;
+		pnn = (struct lpfc_name *) & sp->nodeName;
+		ppn = (struct lpfc_name *) & sp->portName;
+	}
+
+	icmd = &cmdiocb->iocb;
+	if ((icmd->ulpStatus == 0) &&
+	    (lpfc_check_adisc(phba, ndlp, pnn, ppn))) {
+		if (cmd == ELS_CMD_ADISC) {
+			lpfc_els_rsp_adisc_acc(phba, cmdiocb, ndlp);
+		}
+		else {
+			lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp,
+				NULL, 0);
+		}
+		return (1);
+	}
+	/* Reject this request because invalid parameters */
+	stat.un.b.lsRjtRsvd0 = 0;
+	stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
+	stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
+	stat.un.b.vendorUnique = 0;
+	lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
+
+	ndlp->nlp_last_elscmd = (unsigned long)ELS_CMD_PLOGI;
+	/* 1 sec timeout */
+	mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
+
+	ndlp->nlp_flag |= NLP_DELAY_TMO;
+	ndlp->nlp_state = NLP_STE_NPR_NODE;
+	lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
+	return (0);
+}
+
+static int
+lpfc_rcv_logo(struct lpfc_hba * phba,
+		      struct lpfc_nodelist * ndlp,
+		      struct lpfc_iocbq *cmdiocb)
+{
+	/* Put ndlp on NPR list with 1 sec timeout for plogi, ACC logo */
+	/* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
+	 * PLOGIs during LOGO storms from a device.
+	 */
+	ndlp->nlp_flag |= NLP_LOGO_ACC;
+	lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
+
+	if (!(ndlp->nlp_type & NLP_FABRIC)) {
+		/* Only try to re-login if this is NOT a Fabric Node */
+		ndlp->nlp_last_elscmd = (unsigned long)ELS_CMD_PLOGI;
+		mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
+		ndlp->nlp_flag |= NLP_DELAY_TMO;
+	}
+
+	ndlp->nlp_state = NLP_STE_NPR_NODE;
+	lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
+
+	ndlp->nlp_flag &= ~NLP_NPR_ADISC;
+	/* The driver has to wait until the ACC completes before it continues
+	 * processing the LOGO.  The action will resume in
+	 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
+	 * unreg_login, the driver waits so the ACC does not get aborted.
+	 */
+	return (0);
+}
+
+static int
+lpfc_binding_found(struct lpfc_bindlist * blp, struct lpfc_nodelist * ndlp)
+{
+	uint16_t bindtype = blp->nlp_bind_type;
+
+	if ((bindtype & FCP_SEED_DID) &&
+		   (ndlp->nlp_DID == be32_to_cpu(blp->nlp_DID))) {
+		return (1);
+	} else if ((bindtype & FCP_SEED_WWPN) &&
+		   (memcmp(&ndlp->nlp_portname, &blp->nlp_portname,
+			   sizeof (struct lpfc_name)) == 0)) {
+		return (1);
+	} else if ((bindtype & FCP_SEED_WWNN) &&
+		   (memcmp(&ndlp->nlp_nodename, &blp->nlp_nodename,
+			    sizeof (struct lpfc_name)) == 0)) {
+		return (1);
+	}
+	return (0);
+}
+
+static int
+lpfc_binding_useid(struct lpfc_hba * phba, uint32_t sid)
+{
+	struct lpfc_bindlist *blp;
+
+	list_for_each_entry(blp, &phba->fc_nlpbind_list, nlp_listp) {
+		if (blp->nlp_sid == sid) {
+			return (1);
+		}
+	}
+	return (0);
+}
+
+static int
+lpfc_mapping_useid(struct lpfc_hba * phba, uint32_t sid)
+{
+	struct lpfc_nodelist *mapnode;
+	struct lpfc_bindlist *blp;
+
+	list_for_each_entry(mapnode, &phba->fc_nlpmap_list, nlp_listp) {
+		blp = mapnode->nlp_listp_bind;
+		if (blp->nlp_sid == sid) {
+			return (1);
+		}
+	}
+	return (0);
+}
+
+static struct lpfc_bindlist *
+lpfc_create_binding(struct lpfc_hba * phba,
+		    struct lpfc_nodelist * ndlp, uint16_t index,
+		    uint16_t bindtype)
+{
+	struct lpfc_bindlist *blp;
+
+	if ((blp = mempool_alloc(phba->bind_mem_pool, GFP_ATOMIC))) {
+		memset(blp, 0, sizeof (struct lpfc_bindlist));
+		switch (bindtype) {
+		case FCP_SEED_WWPN:
+			blp->nlp_bind_type = FCP_SEED_WWPN;
+			break;
+		case FCP_SEED_WWNN:
+			blp->nlp_bind_type = FCP_SEED_WWNN;
+			break;
+		case FCP_SEED_DID:
+			blp->nlp_bind_type = FCP_SEED_DID;
+			break;
+		}
+		blp->nlp_sid = index;
+		blp->nlp_DID = ndlp->nlp_DID;
+		memcpy(&blp->nlp_nodename, &ndlp->nlp_nodename,
+		       sizeof (struct lpfc_name));
+		memcpy(&blp->nlp_portname, &ndlp->nlp_portname,
+		       sizeof (struct lpfc_name));
+
+		return (blp);
+	}
+	return NULL;
+}
+
+
+static struct lpfc_bindlist *
+lpfc_consistent_bind_get(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
+{
+	struct lpfc_bindlist *blp, *next_blp;
+
+	/* check binding list */
+	list_for_each_entry_safe(blp, next_blp, &phba->fc_nlpbind_list,
+				nlp_listp) {
+		if (lpfc_binding_found(blp, ndlp)) {
+
+			/* take it off the binding list */
+			phba->fc_bind_cnt--;
+			list_del_init(&blp->nlp_listp);
+
+			/* Reassign scsi id <sid> to NPort <nlp_DID> */
+			lpfc_printf_log(phba,
+					KERN_INFO,
+					LOG_DISCOVERY | LOG_FCP,
+					"%d:0213 Reassign scsi id x%x to "
+					"NPort x%x Data: x%x x%x x%x x%x\n",
+					phba->brd_no,
+					blp->nlp_sid, ndlp->nlp_DID,
+					blp->nlp_bind_type, ndlp->nlp_flag,
+					ndlp->nlp_state, ndlp->nlp_rpi);
+
+			return (blp);
+		}
+	}
+	return NULL;
+}
+
+
+static struct lpfc_bindlist *
+lpfc_consistent_bind_create(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
+{
+
+	struct lpfc_bindlist *blp;
+	uint16_t index;
+
+
+	/* NOTE: if scan-down = 2 and we have private loop, then we use
+	 * AlpaArray to determine sid.
+	 */
+	if ((phba->cfg_fcp_bind_method == 4) &&
+	    ((phba->fc_flag & (FC_PUBLIC_LOOP | FC_FABRIC)) ||
+	     (phba->fc_topology != TOPOLOGY_LOOP))) {
+		/* Log message: ALPA based binding used on a non loop
+		   topology */
+		lpfc_printf_log(phba,
+				KERN_WARNING,
+				LOG_DISCOVERY,
+				"%d:0245 ALPA based bind method used on an HBA "
+				"which is in a nonloop topology Data: x%x\n",
+				phba->brd_no,
+				phba->fc_topology);
+	}
+
+	if ((phba->cfg_fcp_bind_method == 4) &&
+	    !(phba->fc_flag & (FC_PUBLIC_LOOP | FC_FABRIC)) &&
+	    (phba->fc_topology == TOPOLOGY_LOOP)) {
+		for (index = 0; index < FC_MAXLOOP; index++) {
+			if (ndlp->nlp_DID == (uint32_t) lpfcAlpaArray[index]) {
+				if ((blp =
+				     lpfc_create_binding(phba, ndlp, index,
+							 FCP_SEED_DID))) {
+					return (blp);
+				}
+				goto errid;
+			}
+		}
+	}
+
+	while (1) {
+		if ((lpfc_binding_useid(phba, phba->sid_cnt))
+		     || (lpfc_mapping_useid (phba, phba->sid_cnt))) {
+
+			phba->sid_cnt++;
+		} else {
+			if ((blp =
+			     lpfc_create_binding(phba, ndlp,
+						 phba->sid_cnt,
+						 phba->fcp_mapping))) {
+				blp->nlp_bind_type |= FCP_SEED_AUTO;
+
+				phba->sid_cnt++;
+				return (blp);
+			}
+			goto errid;
+		}
+	}
+errid:
+	/* Cannot assign scsi id on NPort <nlp_DID> */
+	lpfc_printf_log(phba,
+			KERN_INFO,
+			LOG_DISCOVERY | LOG_FCP,
+			"%d:0230 Cannot assign scsi ID on NPort x%x "
+			"Data: x%x x%x x%x\n",
+			phba->brd_no,
+			ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
+			ndlp->nlp_rpi);
+
+	return NULL;
+}
+
+static uint32_t
+lpfc_assign_binding(struct lpfc_hba * phba,
+		struct lpfc_nodelist * ndlp, struct lpfc_bindlist *blp)
+{
+	struct lpfc_target *targetp;
+
+	targetp = lpfc_find_target(phba, blp->nlp_sid, ndlp);
+	if(!targetp) {
+		/* Cannot assign scsi id <sid> to NPort <nlp_DID> */
+		lpfc_printf_log(phba,
+			KERN_INFO,
+			LOG_DISCOVERY | LOG_FCP,
+			"%d:0229 Cannot assign scsi id x%x to NPort x%x "
+			"Data: x%x x%x x%x\n",
+			phba->brd_no, blp->nlp_sid,
+			ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
+			ndlp->nlp_rpi);
+		return(0);
+	}
+	ndlp->nlp_sid = blp->nlp_sid;
+	ndlp->nlp_flag &= ~NLP_SEED_MASK;
+	switch ((blp->nlp_bind_type & FCP_SEED_MASK)) {
+	case FCP_SEED_WWPN:
+		ndlp->nlp_flag |= NLP_SEED_WWPN;
+		break;
+	case FCP_SEED_WWNN:
+		ndlp->nlp_flag |= NLP_SEED_WWNN;
+		break;
+	case FCP_SEED_DID:
+		ndlp->nlp_flag |= NLP_SEED_DID;
+		break;
+	}
+	if (blp->nlp_bind_type & FCP_SEED_AUTO) {
+		ndlp->nlp_flag |= NLP_AUTOMAP;
+	}
+	/* Assign scsi id <sid> to NPort <nlp_DID> */
+	lpfc_printf_log(phba,
+		KERN_INFO,
+		LOG_DISCOVERY | LOG_FCP,
+		"%d:0216 Assign scsi "
+		"id x%x to NPort x%x "
+		"Data: x%x x%x x%x x%x\n",
+		phba->brd_no,
+		ndlp->nlp_sid, ndlp->nlp_DID,
+		blp->nlp_bind_type,
+		ndlp->nlp_flag, ndlp->nlp_state,
+		ndlp->nlp_rpi);
+	return(1);
+}
+
+static uint32_t
+lpfc_disc_set_adisc(struct lpfc_hba * phba,
+		      struct lpfc_nodelist * ndlp)
+{
+	/* Check config parameter use-adisc or FCP-2 */
+	if ((phba->cfg_use_adisc == 0) &&
+		!(phba->fc_flag & FC_RSCN_MODE)) {
+		if (!(ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE))
+			return (0);
+	}
+	ndlp->nlp_flag |= NLP_NPR_ADISC;
+	return (1);
+}
+
+static uint32_t
+lpfc_disc_noop(struct lpfc_hba * phba,
+		struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	/* This routine does nothing, just return the current state */
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_disc_illegal(struct lpfc_hba * phba,
+		   struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	lpfc_printf_log(phba,
+			KERN_ERR,
+			LOG_DISCOVERY,
+			"%d:0253 Illegal State Transition: node x%x event x%x, "
+			"state x%x Data: x%x x%x\n",
+			phba->brd_no,
+			ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
+			ndlp->nlp_flag);
+	return (ndlp->nlp_state);
+}
+
+/* Start of Discovery State Machine routines */
+
+static uint32_t
+lpfc_rcv_plogi_unused_node(struct lpfc_hba * phba,
+			   struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	if(lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
+		ndlp->nlp_state = NLP_STE_UNUSED_NODE;
+		lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
+		return (ndlp->nlp_state);
+	}
+	lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
+	return (NLP_STE_FREED_NODE);
+}
+
+static uint32_t
+lpfc_rcv_els_unused_node(struct lpfc_hba * phba,
+			 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	lpfc_issue_els_logo(phba, ndlp, 0);
+	lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_logo_unused_node(struct lpfc_hba * phba,
+			  struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	struct lpfc_iocbq     *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	ndlp->nlp_flag |= NLP_LOGO_ACC;
+	lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
+	lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
+
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_cmpl_logo_unused_node(struct lpfc_hba * phba,
+			  struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
+	return (NLP_STE_FREED_NODE);
+}
+
+static uint32_t
+lpfc_device_rm_unused_node(struct lpfc_hba * phba,
+			   struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
+	return (NLP_STE_FREED_NODE);
+}
+
+static uint32_t
+lpfc_rcv_plogi_plogi_issue(struct lpfc_hba * phba,
+			   struct lpfc_nodelist * ndlp,
+			   struct lpfc_iocbq *cmdiocb, uint32_t evt)
+{
+	struct lpfc_dmabuf *pcmd;
+	struct serv_parm *sp;
+	uint32_t *lp;
+	struct ls_rjt stat;
+	int port_cmp;
+
+	pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
+	lp = (uint32_t *) pcmd->virt;
+	sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
+
+	memset(&stat, 0, sizeof (struct ls_rjt));
+
+	/* For a PLOGI, we only accept if our portname is less
+	 * than the remote portname.
+	 */
+	phba->fc_stat.elsLogiCol++;
+	port_cmp = memcmp(&phba->fc_portname, &sp->portName,
+			  sizeof (struct lpfc_name));
+
+	if (port_cmp >= 0) {
+		/* Reject this request because the remote node will accept
+		   ours */
+		stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
+		stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
+		lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
+	}
+	else {
+		lpfc_rcv_plogi(phba, ndlp, cmdiocb);
+	} /* if our portname was less */
+
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_els_plogi_issue(struct lpfc_hba * phba,
+			  struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	struct lpfc_iocbq     *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	/* software abort outstanding PLOGI */
+	lpfc_els_abort(phba, ndlp, 1);
+	mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
+	ndlp->nlp_flag |= NLP_DELAY_TMO;
+
+	if(evt == NLP_EVT_RCV_LOGO) {
+		lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
+	}
+	else {
+		lpfc_issue_els_logo(phba, ndlp, 0);
+	}
+
+	/* Put ndlp in npr list set plogi timer for 1 sec */
+	ndlp->nlp_last_elscmd = (unsigned long)ELS_CMD_PLOGI;
+	ndlp->nlp_state = NLP_STE_NPR_NODE;
+	lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
+
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_cmpl_plogi_plogi_issue(struct lpfc_hba * phba,
+			    struct lpfc_nodelist * ndlp, void *arg,
+			    uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb, *rspiocb;
+	struct lpfc_dmabuf *pcmd, *prsp;
+	uint32_t *lp;
+	IOCB_t *irsp;
+	struct serv_parm *sp;
+	LPFC_MBOXQ_t *mbox;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+	rspiocb = cmdiocb->context_un.rsp_iocb;
+
+	if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
+		return (ndlp->nlp_state);
+	}
+
+	irsp = &rspiocb->iocb;
+
+	if (irsp->ulpStatus == 0) {
+		pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
+
+		prsp = (struct lpfc_dmabuf *) pcmd->list.next;
+		lp = (uint32_t *) prsp->virt;
+
+		sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
+		if ((lpfc_check_sparm(phba, ndlp, sp, CLASS3))) {
+			/* PLOGI chkparm OK */
+			lpfc_printf_log(phba,
+					KERN_INFO,
+					LOG_ELS,
+					"%d:0121 PLOGI chkparm OK "
+					"Data: x%x x%x x%x x%x\n",
+					phba->brd_no,
+					ndlp->nlp_DID, ndlp->nlp_state,
+					ndlp->nlp_flag, ndlp->nlp_rpi);
+
+			if ((phba->cfg_fcp_class == 2) &&
+			    (sp->cls2.classValid)) {
+				ndlp->nlp_fcp_info |= CLASS2;
+			} else {
+				ndlp->nlp_fcp_info |= CLASS3;
+			}
+
+			if ((mbox = mempool_alloc(phba->mbox_mem_pool,
+						  GFP_ATOMIC))) {
+				lpfc_unreg_rpi(phba, ndlp);
+				if (lpfc_reg_login
+				    (phba, irsp->un.elsreq64.remoteID,
+				     (uint8_t *) sp, mbox, 0) == 0) {
+					/* set_slim mailbox command needs to
+					 * execute first, queue this command to
+					 * be processed later.
+					 */
+					switch(ndlp->nlp_DID) {
+					case NameServer_DID:
+						mbox->mbox_cmpl =
+						    lpfc_mbx_cmpl_ns_reg_login;
+						break;
+					case FDMI_DID:
+						mbox->mbox_cmpl =
+						    lpfc_mbx_cmpl_fdmi_reg_login;
+						break;
+					default:
+						mbox->mbox_cmpl =
+						    lpfc_mbx_cmpl_reg_login;
+					}
+					mbox->context2 = ndlp;
+					if (lpfc_sli_issue_mbox(phba, mbox,
+					     (MBX_NOWAIT | MBX_STOP_IOCB))
+					    != MBX_NOT_FINISHED) {
+						ndlp->nlp_state =
+					    	NLP_STE_REG_LOGIN_ISSUE;
+						lpfc_nlp_list(phba, ndlp,
+						      NLP_REGLOGIN_LIST);
+						return (ndlp->nlp_state);
+					}
+					mempool_free(mbox, phba->mbox_mem_pool);
+				} else {
+					mempool_free(mbox, phba->mbox_mem_pool);
+				}
+			}
+		}
+	}
+
+	/* Free this node since the driver cannot login or has the wrong
+	   sparm */
+	lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
+	return (NLP_STE_FREED_NODE);
+}
+
+static uint32_t
+lpfc_device_rm_plogi_issue(struct lpfc_hba * phba,
+			   struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	/* software abort outstanding PLOGI */
+	lpfc_els_abort(phba, ndlp, 1);
+
+	lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
+	return (NLP_STE_FREED_NODE);
+}
+
+static uint32_t
+lpfc_device_recov_plogi_issue(struct lpfc_hba * phba,
+			    struct lpfc_nodelist * ndlp, void *arg,
+			    uint32_t evt)
+{
+	/* software abort outstanding PLOGI */
+	lpfc_els_abort(phba, ndlp, 1);
+
+	ndlp->nlp_state = NLP_STE_NPR_NODE;
+	lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
+	ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
+
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_plogi_adisc_issue(struct lpfc_hba * phba,
+			    struct lpfc_nodelist * ndlp, void *arg,
+			    uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	/* software abort outstanding ADISC */
+	lpfc_els_abort(phba, ndlp, 1);
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	if(lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
+		return (ndlp->nlp_state);
+	}
+	ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
+	lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
+	lpfc_issue_els_plogi(phba, ndlp, 0);
+
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_prli_adisc_issue(struct lpfc_hba * phba,
+			    struct lpfc_nodelist * ndlp, void *arg,
+			    uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_logo_adisc_issue(struct lpfc_hba * phba,
+			    struct lpfc_nodelist * ndlp, void *arg,
+			    uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	/* software abort outstanding ADISC */
+	lpfc_els_abort(phba, ndlp, 0);
+
+	lpfc_rcv_logo(phba, ndlp, cmdiocb);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_padisc_adisc_issue(struct lpfc_hba * phba,
+			    struct lpfc_nodelist * ndlp, void *arg,
+			    uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	lpfc_rcv_padisc(phba, ndlp, cmdiocb);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_prlo_adisc_issue(struct lpfc_hba * phba,
+			    struct lpfc_nodelist * ndlp, void *arg,
+			    uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	/* Treat like rcv logo */
+	lpfc_rcv_logo(phba, ndlp, cmdiocb);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_cmpl_adisc_adisc_issue(struct lpfc_hba * phba,
+			    struct lpfc_nodelist * ndlp, void *arg,
+			    uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb, *rspiocb;
+	struct lpfc_bindlist *blp;
+	IOCB_t *irsp;
+	ADISC *ap;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+	rspiocb = cmdiocb->context_un.rsp_iocb;
+
+	ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
+	irsp = &rspiocb->iocb;
+
+	if ((irsp->ulpStatus) ||
+		(!lpfc_check_adisc(phba, ndlp, &ap->nodeName, &ap->portName))) {
+		ndlp->nlp_last_elscmd = (unsigned long)ELS_CMD_PLOGI;
+		/* 1 sec timeout */
+		mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
+		ndlp->nlp_flag |= NLP_DELAY_TMO;
+
+		memset(&ndlp->nlp_nodename, 0, sizeof (struct lpfc_name));
+		memset(&ndlp->nlp_portname, 0, sizeof (struct lpfc_name));
+
+		ndlp->nlp_state = NLP_STE_NPR_NODE;
+		lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
+		lpfc_unreg_rpi(phba, ndlp);
+		return (ndlp->nlp_state);
+	}
+   	/* move to mapped / unmapped list accordingly */
+	/* Can we assign a SCSI Id to this NPort */
+	if ((blp = lpfc_consistent_bind_get(phba, ndlp))) {
+		/* Next 4 lines MUST be in this order */
+		if(lpfc_assign_binding(phba, ndlp, blp)) {
+			ndlp->nlp_state = NLP_STE_MAPPED_NODE;
+			lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
+			ndlp->nlp_listp_bind = blp;
+
+			lpfc_set_failmask(phba, ndlp,
+				(LPFC_DEV_DISCOVERY_INP|LPFC_DEV_DISCONNECTED),
+				LPFC_CLR_BITMASK);
+
+			return (ndlp->nlp_state);
+		}
+	}
+	ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
+	ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
+	lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
+
+	lpfc_set_failmask(phba, ndlp,
+		(LPFC_DEV_DISCOVERY_INP | LPFC_DEV_DISCONNECTED),
+		LPFC_CLR_BITMASK);
+
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_device_rm_adisc_issue(struct lpfc_hba * phba,
+			    struct lpfc_nodelist * ndlp, void *arg,
+			    uint32_t evt)
+{
+	/* software abort outstanding ADISC */
+	lpfc_els_abort(phba, ndlp, 1);
+
+	lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
+	return (NLP_STE_FREED_NODE);
+}
+
+static uint32_t
+lpfc_device_recov_adisc_issue(struct lpfc_hba * phba,
+			    struct lpfc_nodelist * ndlp, void *arg,
+			    uint32_t evt)
+{
+	/* software abort outstanding ADISC */
+	lpfc_els_abort(phba, ndlp, 1);
+
+	ndlp->nlp_state = NLP_STE_NPR_NODE;
+	lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
+	ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
+
+	lpfc_disc_set_adisc(phba, ndlp);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_plogi_reglogin_issue(struct lpfc_hba * phba,
+			      struct lpfc_nodelist * ndlp, void *arg,
+			      uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	lpfc_rcv_plogi(phba, ndlp, cmdiocb);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_prli_reglogin_issue(struct lpfc_hba * phba,
+			     struct lpfc_nodelist * ndlp, void *arg,
+			     uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_logo_reglogin_issue(struct lpfc_hba * phba,
+			     struct lpfc_nodelist * ndlp, void *arg,
+			     uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	lpfc_rcv_logo(phba, ndlp, cmdiocb);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_padisc_reglogin_issue(struct lpfc_hba * phba,
+			       struct lpfc_nodelist * ndlp, void *arg,
+			       uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	lpfc_rcv_padisc(phba, ndlp, cmdiocb);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_prlo_reglogin_issue(struct lpfc_hba * phba,
+			     struct lpfc_nodelist * ndlp, void *arg,
+			     uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+	lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_hba * phba,
+				  struct lpfc_nodelist * ndlp,
+				  void *arg, uint32_t evt)
+{
+	LPFC_MBOXQ_t *pmb;
+	MAILBOX_t *mb;
+	uint32_t did;
+
+	pmb = (LPFC_MBOXQ_t *) arg;
+	mb = &pmb->mb;
+	did = mb->un.varWords[1];
+	if (mb->mbxStatus) {
+		/* RegLogin failed */
+		lpfc_printf_log(phba,
+				KERN_ERR,
+				LOG_DISCOVERY,
+				"%d:0246 RegLogin failed Data: x%x x%x x%x\n",
+				phba->brd_no,
+				did, mb->mbxStatus, phba->hba_state);
+
+		mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
+		ndlp->nlp_flag |= NLP_DELAY_TMO;
+
+		lpfc_issue_els_logo(phba, ndlp, 0);
+		/* Put ndlp in npr list set plogi timer for 1 sec */
+		ndlp->nlp_last_elscmd = (unsigned long)ELS_CMD_PLOGI;
+		ndlp->nlp_state = NLP_STE_NPR_NODE;
+		lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
+		return (ndlp->nlp_state);
+	}
+
+	if (ndlp->nlp_rpi != 0)
+		lpfc_findnode_remove_rpi(phba, ndlp->nlp_rpi);
+
+	ndlp->nlp_rpi = mb->un.varWords[0];
+	lpfc_addnode_rpi(phba, ndlp, ndlp->nlp_rpi);
+
+	/* Only if we are not a fabric nport do we issue PRLI */
+	if (!(ndlp->nlp_type & NLP_FABRIC)) {
+		ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
+		lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
+		lpfc_issue_els_prli(phba, ndlp, 0);
+	} else {
+		ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
+		lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
+	}
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_device_rm_reglogin_issue(struct lpfc_hba * phba,
+			      struct lpfc_nodelist * ndlp, void *arg,
+			      uint32_t evt)
+{
+	lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
+	return (NLP_STE_FREED_NODE);
+}
+
+static uint32_t
+lpfc_device_recov_reglogin_issue(struct lpfc_hba * phba,
+			       struct lpfc_nodelist * ndlp, void *arg,
+			       uint32_t evt)
+{
+	ndlp->nlp_state = NLP_STE_NPR_NODE;
+	lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
+	ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_plogi_prli_issue(struct lpfc_hba * phba,
+			  struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	lpfc_rcv_plogi(phba, ndlp, cmdiocb);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_prli_prli_issue(struct lpfc_hba * phba,
+			 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_logo_prli_issue(struct lpfc_hba * phba,
+			 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	/* Software abort outstanding PRLI before sending acc */
+	lpfc_els_abort(phba, ndlp, 1);
+
+	lpfc_rcv_logo(phba, ndlp, cmdiocb);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_padisc_prli_issue(struct lpfc_hba * phba,
+			   struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	lpfc_rcv_padisc(phba, ndlp, cmdiocb);
+	return (ndlp->nlp_state);
+}
+
+/* This routine is envoked when we rcv a PRLO request from a nport
+ * we are logged into.  We should send back a PRLO rsp setting the
+ * appropriate bits.
+ * NEXT STATE = PRLI_ISSUE
+ */
+static uint32_t
+lpfc_rcv_prlo_prli_issue(struct lpfc_hba * phba,
+			 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+	lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_cmpl_prli_prli_issue(struct lpfc_hba * phba,
+			  struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb, *rspiocb;
+	IOCB_t *irsp;
+	PRLI *npr;
+	struct lpfc_bindlist *blp;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+	rspiocb = cmdiocb->context_un.rsp_iocb;
+	npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
+
+	irsp = &rspiocb->iocb;
+	if (irsp->ulpStatus) {
+		ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
+		lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
+		lpfc_set_failmask(phba, ndlp, LPFC_DEV_DISCOVERY_INP,
+				  LPFC_CLR_BITMASK);
+		return (ndlp->nlp_state);
+	}
+
+	/* Check out PRLI rsp */
+	if ((npr->acceptRspCode != PRLI_REQ_EXECUTED) ||
+	    (npr->prliType != PRLI_FCP_TYPE) || (npr->targetFunc != 1)) {
+		ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
+		lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
+		lpfc_set_failmask(phba, ndlp,
+			(LPFC_DEV_DISCOVERY_INP | LPFC_DEV_DISCONNECTED),
+			LPFC_CLR_BITMASK);
+		return (ndlp->nlp_state);
+	}
+	if (npr->Retry == 1) {
+		ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
+	}
+
+	/* Can we assign a SCSI Id to this NPort */
+	blp = lpfc_consistent_bind_get(phba, ndlp);
+	if (!blp)
+		blp = lpfc_consistent_bind_create(phba, ndlp);
+	if (blp) {
+		/* Next 4 lines MUST be in this order */
+		if(lpfc_assign_binding(phba, ndlp, blp)) {
+			ndlp->nlp_state = NLP_STE_MAPPED_NODE;
+			lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
+			ndlp->nlp_listp_bind = blp;
+
+			lpfc_set_failmask(phba, ndlp,
+				(LPFC_DEV_DISCOVERY_INP|LPFC_DEV_DISCONNECTED),
+				LPFC_CLR_BITMASK);
+			return (ndlp->nlp_state);
+		}
+	}
+	ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
+	ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
+	lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
+
+	lpfc_set_failmask(phba, ndlp,
+		(LPFC_DEV_DISCOVERY_INP | LPFC_DEV_DISCONNECTED),
+		LPFC_CLR_BITMASK);
+	return (ndlp->nlp_state);
+}
+
+/*! lpfc_device_rm_prli_issue
+  *
+  * \pre
+  * \post
+  * \param   phba
+  * \param   ndlp
+  * \param   arg
+  * \param   evt
+  * \return  uint32_t
+  *
+  * \b Description:
+  *    This routine is envoked when we a request to remove a nport we are in the
+  *    process of PRLIing. We should software abort outstanding prli, unreg
+  *    login, send a logout. We will change node state to UNUSED_NODE, put it
+  *    on plogi list so it can be freed when LOGO completes.
+  *
+  */
+static uint32_t
+lpfc_device_rm_prli_issue(struct lpfc_hba * phba,
+			  struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	/* software abort outstanding PRLI */
+	lpfc_els_abort(phba, ndlp, 1);
+
+	lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
+	return (NLP_STE_FREED_NODE);
+}
+
+
+/*! lpfc_device_recov_prli_issue
+  *
+  * \pre
+  * \post
+  * \param   phba
+  * \param   ndlp
+  * \param   arg
+  * \param   evt
+  * \return  uint32_t
+  *
+  * \b Description:
+  *    The routine is envoked when the state of a device is unknown, like
+  *    during a link down. We should remove the nodelist entry from the
+  *    unmapped list, issue a UNREG_LOGIN, do a software abort of the
+  *    outstanding PRLI command, then free the node entry.
+  */
+static uint32_t
+lpfc_device_recov_prli_issue(struct lpfc_hba * phba,
+			   struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	/* software abort outstanding PRLI */
+	lpfc_els_abort(phba, ndlp, 1);
+
+	ndlp->nlp_state = NLP_STE_NPR_NODE;
+	lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
+	ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_plogi_unmap_node(struct lpfc_hba * phba,
+			  struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	lpfc_rcv_plogi(phba, ndlp, cmdiocb);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_prli_unmap_node(struct lpfc_hba * phba,
+			 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_logo_unmap_node(struct lpfc_hba * phba,
+			 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	lpfc_rcv_logo(phba, ndlp, cmdiocb);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_padisc_unmap_node(struct lpfc_hba * phba,
+			   struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	lpfc_rcv_padisc(phba, ndlp, cmdiocb);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_prlo_unmap_node(struct lpfc_hba * phba,
+			 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	/* Treat like rcv logo */
+	lpfc_rcv_logo(phba, ndlp, cmdiocb);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_device_recov_unmap_node(struct lpfc_hba * phba,
+			   struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	ndlp->nlp_state = NLP_STE_NPR_NODE;
+	lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
+	ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
+	lpfc_disc_set_adisc(phba, ndlp);
+
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_plogi_mapped_node(struct lpfc_hba * phba,
+			   struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	lpfc_rcv_plogi(phba, ndlp, cmdiocb);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_prli_mapped_node(struct lpfc_hba * phba,
+			  struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+	lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_logo_mapped_node(struct lpfc_hba * phba,
+			  struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	lpfc_rcv_logo(phba, ndlp, cmdiocb);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_padisc_mapped_node(struct lpfc_hba * phba,
+			    struct lpfc_nodelist * ndlp, void *arg,
+			    uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	lpfc_rcv_padisc(phba, ndlp, cmdiocb);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_prlo_mapped_node(struct lpfc_hba * phba,
+			  struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	/* flush the target */
+	lpfc_sli_abort_iocb_tgt(phba,
+			       &phba->sli.ring[phba->sli.fcp_ring],
+			       ndlp->nlp_sid, LPFC_ABORT_ALLQ);
+
+	/* Treat like rcv logo */
+	lpfc_rcv_logo(phba, ndlp, cmdiocb);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_device_recov_mapped_node(struct lpfc_hba * phba,
+			    struct lpfc_nodelist * ndlp, void *arg,
+			    uint32_t evt)
+{
+	ndlp->nlp_state = NLP_STE_NPR_NODE;
+	lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
+	ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
+	lpfc_disc_set_adisc(phba, ndlp);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_plogi_npr_node(struct lpfc_hba * phba,
+			    struct lpfc_nodelist * ndlp, void *arg,
+			    uint32_t evt)
+{
+	struct lpfc_iocbq *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	/* Ignore PLOGI if we have an outstanding LOGO */
+	if (ndlp->nlp_flag & NLP_LOGO_SND) {
+		return (ndlp->nlp_state);
+	}
+
+	if(lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
+		ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
+		return (ndlp->nlp_state);
+	}
+
+	/* send PLOGI immediately, move to PLOGI issue state */
+	if(!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
+			ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
+			lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
+			lpfc_issue_els_plogi(phba, ndlp, 0);
+	}
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_prli_npr_node(struct lpfc_hba * phba,
+			    struct lpfc_nodelist * ndlp, void *arg,
+			    uint32_t evt)
+{
+	struct lpfc_iocbq     *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
+
+	if(!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
+		if (ndlp->nlp_flag & NLP_NPR_ADISC) {
+			ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
+			lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
+			lpfc_issue_els_adisc(phba, ndlp, 0);
+		} else {
+			ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
+			lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
+			lpfc_issue_els_plogi(phba, ndlp, 0);
+		}
+	}
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_logo_npr_node(struct lpfc_hba * phba,
+			    struct lpfc_nodelist * ndlp, void *arg,
+			    uint32_t evt)
+{
+	struct lpfc_iocbq     *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	lpfc_rcv_logo(phba, ndlp, cmdiocb);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_padisc_npr_node(struct lpfc_hba * phba,
+			    struct lpfc_nodelist * ndlp, void *arg,
+			    uint32_t evt)
+{
+	struct lpfc_iocbq     *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	lpfc_rcv_padisc(phba, ndlp, cmdiocb);
+
+	if(!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
+		if (ndlp->nlp_flag & NLP_NPR_ADISC) {
+			ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
+			lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
+			lpfc_issue_els_adisc(phba, ndlp, 0);
+		} else {
+			ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
+			lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
+			lpfc_issue_els_plogi(phba, ndlp, 0);
+		}
+	}
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_rcv_prlo_npr_node(struct lpfc_hba * phba,
+			    struct lpfc_nodelist * ndlp, void *arg,
+			    uint32_t evt)
+{
+	struct lpfc_iocbq     *cmdiocb;
+
+	cmdiocb = (struct lpfc_iocbq *) arg;
+
+	lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
+
+	if(ndlp->nlp_flag & NLP_DELAY_TMO) {
+		if (ndlp->nlp_last_elscmd == (unsigned long)ELS_CMD_PLOGI) {
+			return (ndlp->nlp_state);
+		} else {
+			ndlp->nlp_flag &= ~NLP_DELAY_TMO;
+			spin_unlock_irq(phba->host->host_lock);
+			del_timer_sync(&ndlp->nlp_delayfunc);
+			spin_lock_irq(phba->host->host_lock);
+			if (!list_empty(&ndlp->els_retry_evt.
+					evt_listp))
+				list_del_init(&ndlp->els_retry_evt.
+					      evt_listp);
+		}
+	}
+
+	ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
+	lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
+	lpfc_issue_els_plogi(phba, ndlp, 0);
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_cmpl_logo_npr_node(struct lpfc_hba * phba,
+		struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	lpfc_unreg_rpi(phba, ndlp);
+	/* This routine does nothing, just return the current state */
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_cmpl_reglogin_npr_node(struct lpfc_hba * phba,
+			    struct lpfc_nodelist * ndlp, void *arg,
+			    uint32_t evt)
+{
+	LPFC_MBOXQ_t *pmb;
+	MAILBOX_t *mb;
+
+	pmb = (LPFC_MBOXQ_t *) arg;
+	mb = &pmb->mb;
+
+	/* save rpi */
+	if (ndlp->nlp_rpi != 0)
+		lpfc_findnode_remove_rpi(phba, ndlp->nlp_rpi);
+
+	ndlp->nlp_rpi = mb->un.varWords[0];
+	lpfc_addnode_rpi(phba, ndlp, ndlp->nlp_rpi);
+
+	return (ndlp->nlp_state);
+}
+
+static uint32_t
+lpfc_device_rm_npr_node(struct lpfc_hba * phba,
+			    struct lpfc_nodelist * ndlp, void *arg,
+			    uint32_t evt)
+{
+	lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
+	return (NLP_STE_FREED_NODE);
+}
+
+static uint32_t
+lpfc_device_recov_npr_node(struct lpfc_hba * phba,
+			    struct lpfc_nodelist * ndlp, void *arg,
+			    uint32_t evt)
+{
+	ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
+	return (ndlp->nlp_state);
+}
+
+
+/* This next section defines the NPort Discovery State Machine */
+
+/* There are 4 different double linked lists nodelist entries can reside on.
+ * The plogi list and adisc list are used when Link Up discovery or RSCN
+ * processing is needed. Each list holds the nodes that we will send PLOGI
+ * or ADISC on. These lists will keep track of what nodes will be effected
+ * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
+ * The unmapped_list will contain all nodes that we have successfully logged
+ * into at the Fibre Channel level. The mapped_list will contain all nodes
+ * that are mapped FCP targets.
+ */
+/*
+ * The bind list is a list of undiscovered (potentially non-existent) nodes
+ * that we have saved binding information on. This information is used when
+ * nodes transition from the unmapped to the mapped list.
+ */
+/* For UNUSED_NODE state, the node has just been allocated .
+ * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
+ * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
+ * and put on the unmapped list. For ADISC processing, the node is taken off
+ * the ADISC list and placed on either the mapped or unmapped list (depending
+ * on its previous state). Once on the unmapped list, a PRLI is issued and the
+ * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
+ * changed to UNMAPPED_NODE. If the completion indicates a mapped
+ * node, the node is taken off the unmapped list. The binding list is checked
+ * for a valid binding, or a binding is automatically assigned. If binding
+ * assignment is unsuccessful, the node is left on the unmapped list. If
+ * binding assignment is successful, the associated binding list entry (if
+ * any) is removed, and the node is placed on the mapped list.
+ */
+/*
+ * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
+ * lists will receive a DEVICE_RECOVERY event. If the linkdown or nodev timers
+ * expire, all effected nodes will receive a DEVICE_RM event.
+ */
+/*
+ * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
+ * to either the ADISC or PLOGI list.  After a Nameserver query or ALPA loopmap
+ * check, additional nodes may be added or removed (via DEVICE_RM) to / from
+ * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
+ * we will first process the ADISC list.  32 entries are processed initially and
+ * ADISC is initited for each one.  Completions / Events for each node are
+ * funnelled thru the state machine.  As each node finishes ADISC processing, it
+ * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
+ * waiting, and the ADISC list count is identically 0, then we are done. For
+ * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
+ * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
+ * list.  32 entries are processed initially and PLOGI is initited for each one.
+ * Completions / Events for each node are funnelled thru the state machine.  As
+ * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
+ * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
+ * indentically 0, then we are done. We have now completed discovery / RSCN
+ * handling. Upon completion, ALL nodes should be on either the mapped or
+ * unmapped lists.
+ */
+
+static void *lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT] = {
+	/* Action routine                          Event       Current State  */
+	(void *)lpfc_rcv_plogi_unused_node,	/* RCV_PLOGI   UNUSED_NODE    */
+	(void *)lpfc_rcv_els_unused_node,	/* RCV_PRLI        */
+	(void *)lpfc_rcv_logo_unused_node,	/* RCV_LOGO        */
+	(void *)lpfc_rcv_els_unused_node,	/* RCV_ADISC       */
+	(void *)lpfc_rcv_els_unused_node,	/* RCV_PDISC       */
+	(void *)lpfc_rcv_els_unused_node,	/* RCV_PRLO        */
+	(void *)lpfc_disc_illegal,		/* CMPL_PLOGI      */
+	(void *)lpfc_disc_illegal,		/* CMPL_PRLI       */
+	(void *)lpfc_cmpl_logo_unused_node,	/* CMPL_LOGO       */
+	(void *)lpfc_disc_illegal,		/* CMPL_ADISC      */
+	(void *)lpfc_disc_illegal,		/* CMPL_REG_LOGIN  */
+	(void *)lpfc_device_rm_unused_node,	/* DEVICE_RM       */
+	(void *)lpfc_disc_illegal,		/* DEVICE_RECOVERY */
+
+	(void *)lpfc_rcv_plogi_plogi_issue,	/* RCV_PLOGI   PLOGI_ISSUE    */
+	(void *)lpfc_rcv_els_plogi_issue,	/* RCV_PRLI        */
+	(void *)lpfc_rcv_els_plogi_issue,	/* RCV_LOGO        */
+	(void *)lpfc_rcv_els_plogi_issue,	/* RCV_ADISC       */
+	(void *)lpfc_rcv_els_plogi_issue,	/* RCV_PDISC       */
+	(void *)lpfc_rcv_els_plogi_issue,	/* RCV_PRLO        */
+	(void *)lpfc_cmpl_plogi_plogi_issue,	/* CMPL_PLOGI      */
+	(void *)lpfc_disc_illegal,		/* CMPL_PRLI       */
+	(void *)lpfc_disc_illegal,		/* CMPL_LOGO       */
+	(void *)lpfc_disc_illegal,		/* CMPL_ADISC      */
+	(void *)lpfc_disc_illegal,		/* CMPL_REG_LOGIN  */
+	(void *)lpfc_device_rm_plogi_issue,	/* DEVICE_RM       */
+	(void *)lpfc_device_recov_plogi_issue,	/* DEVICE_RECOVERY */
+
+	(void *)lpfc_rcv_plogi_adisc_issue,     /* RCV_PLOGI   ADISC_ISSUE    */
+	(void *)lpfc_rcv_prli_adisc_issue,      /* RCV_PRLI        */
+	(void *)lpfc_rcv_logo_adisc_issue,      /* RCV_LOGO        */
+	(void *)lpfc_rcv_padisc_adisc_issue,    /* RCV_ADISC       */
+	(void *)lpfc_rcv_padisc_adisc_issue,    /* RCV_PDISC       */
+	(void *)lpfc_rcv_prlo_adisc_issue,      /* RCV_PRLO        */
+	(void *)lpfc_disc_illegal,    		/* CMPL_PLOGI      */
+	(void *)lpfc_disc_illegal,		/* CMPL_PRLI       */
+	(void *)lpfc_disc_illegal,   		/* CMPL_LOGO       */
+	(void *)lpfc_cmpl_adisc_adisc_issue,    /* CMPL_ADISC      */
+	(void *)lpfc_disc_illegal, 		/* CMPL_REG_LOGIN  */
+	(void *)lpfc_device_rm_adisc_issue,     /* DEVICE_RM       */
+	(void *)lpfc_device_recov_adisc_issue,  /* DEVICE_RECOVERY */
+
+	(void *)lpfc_rcv_plogi_reglogin_issue,	/* RCV_PLOGI  REG_LOGIN_ISSUE */
+	(void *)lpfc_rcv_prli_reglogin_issue,	/* RCV_PLOGI       */
+	(void *)lpfc_rcv_logo_reglogin_issue,	/* RCV_LOGO        */
+	(void *)lpfc_rcv_padisc_reglogin_issue,	/* RCV_ADISC       */
+	(void *)lpfc_rcv_padisc_reglogin_issue,	/* RCV_PDISC       */
+	(void *)lpfc_rcv_prlo_reglogin_issue,	/* RCV_PRLO        */
+	(void *)lpfc_disc_illegal,		/* CMPL_PLOGI      */
+	(void *)lpfc_disc_illegal,		/* CMPL_PRLI       */
+	(void *)lpfc_disc_illegal,		/* CMPL_LOGO       */
+	(void *)lpfc_disc_illegal,		/* CMPL_ADISC      */
+	(void *)lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN  */
+	(void *)lpfc_device_rm_reglogin_issue,	/* DEVICE_RM       */
+	(void *)lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
+
+	(void *)lpfc_rcv_plogi_prli_issue,	/* RCV_PLOGI   PRLI_ISSUE     */
+	(void *)lpfc_rcv_prli_prli_issue,	/* RCV_PRLI        */
+	(void *)lpfc_rcv_logo_prli_issue,	/* RCV_LOGO        */
+	(void *)lpfc_rcv_padisc_prli_issue,	/* RCV_ADISC       */
+	(void *)lpfc_rcv_padisc_prli_issue,	/* RCV_PDISC       */
+	(void *)lpfc_rcv_prlo_prli_issue,	/* RCV_PRLO        */
+	(void *)lpfc_disc_illegal,		/* CMPL_PLOGI      */
+	(void *)lpfc_cmpl_prli_prli_issue,	/* CMPL_PRLI       */
+	(void *)lpfc_disc_illegal,		/* CMPL_LOGO       */
+	(void *)lpfc_disc_illegal,		/* CMPL_ADISC      */
+	(void *)lpfc_disc_illegal,		/* CMPL_REG_LOGIN  */
+	(void *)lpfc_device_rm_prli_issue,	/* DEVICE_RM       */
+	(void *)lpfc_device_recov_prli_issue,	/* DEVICE_RECOVERY */
+
+	(void *)lpfc_rcv_plogi_unmap_node,	/* RCV_PLOGI   UNMAPPED_NODE  */
+	(void *)lpfc_rcv_prli_unmap_node,	/* RCV_PRLI        */
+	(void *)lpfc_rcv_logo_unmap_node,	/* RCV_LOGO        */
+	(void *)lpfc_rcv_padisc_unmap_node,	/* RCV_ADISC       */
+	(void *)lpfc_rcv_padisc_unmap_node,	/* RCV_PDISC       */
+	(void *)lpfc_rcv_prlo_unmap_node,	/* RCV_PRLO        */
+	(void *)lpfc_disc_illegal,		/* CMPL_PLOGI      */
+	(void *)lpfc_disc_illegal,		/* CMPL_PRLI       */
+	(void *)lpfc_disc_illegal,		/* CMPL_LOGO       */
+	(void *)lpfc_disc_illegal,		/* CMPL_ADISC      */
+	(void *)lpfc_disc_illegal,		/* CMPL_REG_LOGIN  */
+	(void *)lpfc_disc_illegal,		/* DEVICE_RM       */
+	(void *)lpfc_device_recov_unmap_node,	/* DEVICE_RECOVERY */
+
+	(void *)lpfc_rcv_plogi_mapped_node,	/* RCV_PLOGI   MAPPED_NODE    */
+	(void *)lpfc_rcv_prli_mapped_node,	/* RCV_PRLI        */
+	(void *)lpfc_rcv_logo_mapped_node,	/* RCV_LOGO        */
+	(void *)lpfc_rcv_padisc_mapped_node,	/* RCV_ADISC       */
+	(void *)lpfc_rcv_padisc_mapped_node,	/* RCV_PDISC       */
+	(void *)lpfc_rcv_prlo_mapped_node,	/* RCV_PRLO        */
+	(void *)lpfc_disc_illegal,		/* CMPL_PLOGI      */
+	(void *)lpfc_disc_illegal,		/* CMPL_PRLI       */
+	(void *)lpfc_disc_illegal,		/* CMPL_LOGO       */
+	(void *)lpfc_disc_illegal,		/* CMPL_ADISC      */
+	(void *)lpfc_disc_illegal,		/* CMPL_REG_LOGIN  */
+	(void *)lpfc_disc_illegal,		/* DEVICE_RM       */
+	(void *)lpfc_device_recov_mapped_node,	/* DEVICE_RECOVERY */
+
+	(void *)lpfc_rcv_plogi_npr_node,        /* RCV_PLOGI   NPR_NODE    */
+	(void *)lpfc_rcv_prli_npr_node,         /* RCV_PRLI        */
+	(void *)lpfc_rcv_logo_npr_node,         /* RCV_LOGO        */
+	(void *)lpfc_rcv_padisc_npr_node,       /* RCV_ADISC       */
+	(void *)lpfc_rcv_padisc_npr_node,       /* RCV_PDISC       */
+	(void *)lpfc_rcv_prlo_npr_node,         /* RCV_PRLO        */
+	(void *)lpfc_disc_noop,			/* CMPL_PLOGI      */
+	(void *)lpfc_disc_noop,			/* CMPL_PRLI       */
+	(void *)lpfc_cmpl_logo_npr_node,        /* CMPL_LOGO       */
+	(void *)lpfc_disc_noop,			/* CMPL_ADISC      */
+	(void *)lpfc_cmpl_reglogin_npr_node,    /* CMPL_REG_LOGIN  */
+	(void *)lpfc_device_rm_npr_node,        /* DEVICE_RM       */
+	(void *)lpfc_device_recov_npr_node,     /* DEVICE_RECOVERY */
+};
+
+int
+lpfc_disc_state_machine(struct lpfc_hba * phba,
+			struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
+{
+	uint32_t cur_state, rc;
+	uint32_t(*func) (struct lpfc_hba *, struct lpfc_nodelist *, void *,
+			 uint32_t);
+
+	ndlp->nlp_disc_refcnt++;
+	cur_state = ndlp->nlp_state;
+
+	/* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
+	lpfc_printf_log(phba,
+			KERN_INFO,
+			LOG_DISCOVERY,
+			"%d:0211 DSM in event x%x on NPort x%x in state %d "
+			"Data: x%x\n",
+			phba->brd_no,
+			evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
+
+	func = (uint32_t(*)(struct lpfc_hba *, struct lpfc_nodelist *, void *,
+			    uint32_t))
+	    lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
+	rc = (func) (phba, ndlp, arg, evt);
+
+	/* DSM out state <rc> on NPort <nlp_DID> */
+	lpfc_printf_log(phba,
+		       KERN_INFO,
+		       LOG_DISCOVERY,
+		       "%d:0212 DSM out state %d on NPort x%x Data: x%x\n",
+		       phba->brd_no,
+		       rc, ndlp->nlp_DID, ndlp->nlp_flag);
+
+	ndlp->nlp_disc_refcnt--;
+
+	/* Check to see if ndlp removal is deferred */
+	if ((ndlp->nlp_disc_refcnt == 0)
+	    && (ndlp->nlp_flag & NLP_DELAY_REMOVE)) {
+
+		ndlp->nlp_flag &= ~NLP_DELAY_REMOVE;
+		lpfc_nlp_remove(phba, ndlp);
+		return (NLP_STE_FREED_NODE);
+	}
+	if (rc == NLP_STE_FREED_NODE)
+		return (NLP_STE_FREED_NODE);
+	ndlp->nlp_state = rc;
+	return (rc);
+}
--- linux-2.6.8.1-t044-driver-update//drivers/scsi/lpfc/Makefile	1970-01-01 03:00:00.000000000 +0300
+++ rhel4u2//drivers/scsi/lpfc/Makefile	2005-10-19 11:47:17.000000000 +0400
@@ -0,0 +1,7 @@
+# Driver for Emulex LightPulse fibre channel host bus adapters.
+EXTRA_CFLAGS +=  -DRHEL_FC
+obj-$(CONFIG_SCSI_LPFC) := lpfc.o
+
+lpfc-objs := lpfc_mem.o lpfc_sli.o lpfc_ct.o lpfc_els.o \
+lpfc_hbadisc.o lpfc_init.o lpfc_mbox.o lpfc_nportdisc.o lpfc_scsiport.o \
+lpfc_fcp.o
--- linux-2.6.8.1-t044-driver-update//drivers/scsi/lpfc/lpfc.h	1970-01-01 03:00:00.000000000 +0300
+++ rhel4u2//drivers/scsi/lpfc/lpfc.h	2005-10-19 11:47:17.000000000 +0400
@@ -0,0 +1,464 @@
+/*******************************************************************
+ * This file is part of the Emulex Linux Device Driver for         *
+ * Fibre Channel Host Bus Adapters.                                *
+ * Copyright (C) 2003-2005 Emulex.  All rights reserved.           *
+ * EMULEX and SLI are trademarks of Emulex.                        *
+ * www.emulex.com                                                  *
+ *                                                                 *
+ * This program is free software; you can redistribute it and/or   *
+ * modify it under the terms of version 2 of the GNU General       *
+ * Public License as published by the Free Software Foundation.    *
+ * This program is distributed in the hope that it will be useful. *
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
+ * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
+ * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
+ * more details, a copy of which can be found in the file COPYING  *
+ * included with this package.                                     *
+ *******************************************************************/
+
+/*
+ * $Id: lpfc.h 1.143.2.2 2005/06/13 17:16:00EDT sf_support Exp  $
+ */
+
+#ifndef _H_LPFC
+#define _H_LPFC
+
+struct lpfc_sli2_slim;
+
+#define LPFC_MAX_TARGET                 256	/* max nunber of targets
+						   supported */
+#define LPFC_MAX_DISC_THREADS           64	/* max outstanding discovery els
+						   requests */
+#define LPFC_MAX_NS_RETRY               3	/* Try to get to the NameServer
+						   3 times and then give up. */
+#define LPFC_DFT_HBA_Q_DEPTH            2048	/* max cmds per hba */
+#define LPFC_LC_HBA_Q_DEPTH             1024	/* max cmds per low cost hba */
+#define LPFC_LP101_HBA_Q_DEPTH          128	/* max cmds per low cost hba */
+
+/* Define the SLIM2 page size. */
+#define LPFC_SLIM2_PAGE_AREA  8192
+
+/* Define macros for 64 bit support */
+#define putPaddrLow(addr)    ((uint32_t) (0xffffffff & (u64)(addr)))
+#define putPaddrHigh(addr)   ((uint32_t) (0xffffffff & (((u64)(addr))>>32)))
+#define getPaddr(high, low)  ((dma_addr_t)( \
+			     (( (u64)(high)<<16 ) << 16)|( (u64)(low))))
+/* Provide maximum configuration definitions. */
+#define LPFC_DRVR_TIMEOUT  16		/* driver iocb timeout value in sec */
+#define MAX_FCP_TARGET     256		/* max num of FCP targets supported */
+#define FC_MAX_ADPTMSG     64
+
+#define MAX_HBAEVT 32
+
+#if __LITTLE_ENDIAN
+
+#define putLunLow(lunlow, lun)              \
+   {                                        \
+   lunlow = 0;                              \
+   }
+
+#define putLunHigh(lunhigh, lun)            \
+   {                                        \
+   lunhigh = swab16(lun);                   \
+   }
+
+#else				/* BIG_ENDIAN_HOST */
+
+#define putLunLow(lunlow, lun)              \
+   {                                        \
+   lunlow = 0;                              \
+   }
+
+#define putLunHigh(lunhigh, lun)            \
+   {                                        \
+   lunhigh = (uint32_t)(lun << 16);         \
+   }
+#endif
+
+/****************************************************************************/
+/*      Device VPD save area                                                */
+/****************************************************************************/
+typedef struct lpfc_vpd {
+	uint32_t status;	/* vpd status value */
+	uint32_t length;	/* number of bytes actually returned */
+	struct {
+		uint32_t rsvd1;	/* Revision numbers */
+		uint32_t biuRev;
+		uint32_t smRev;
+		uint32_t smFwRev;
+		uint32_t endecRev;
+		uint16_t rBit;
+		uint8_t fcphHigh;
+		uint8_t fcphLow;
+		uint8_t feaLevelHigh;
+		uint8_t feaLevelLow;
+		uint32_t postKernRev;
+		uint32_t opFwRev;
+		uint8_t opFwName[16];
+		uint32_t sli1FwRev;
+		uint8_t sli1FwName[16];
+		uint32_t sli2FwRev;
+		uint8_t sli2FwName[16];
+	} rev;
+} lpfc_vpd_t;
+
+struct lpfc_scsi_buf;
+
+struct lpfc_hba_event {
+	uint32_t fc_eventcode;
+	uint32_t fc_evdata1;
+	uint32_t fc_evdata2;
+	uint32_t fc_evdata3;
+	uint32_t fc_evdata4;
+};
+
+/*
+ * lpfc stat counters
+ */
+struct lpfc_stats {
+	/* Statistics for ELS commands */
+	uint32_t elsLogiCol;
+	uint32_t elsRetryExceeded;
+	uint32_t elsXmitRetry;
+	uint32_t elsDelayRetry;
+	uint32_t elsRcvDrop;
+	uint32_t elsRcvFrame;
+	uint32_t elsRcvRSCN;
+	uint32_t elsRcvRNID;
+	uint32_t elsRcvFARP;
+	uint32_t elsRcvFARPR;
+	uint32_t elsRcvFLOGI;
+	uint32_t elsRcvPLOGI;
+	uint32_t elsRcvADISC;
+	uint32_t elsRcvPDISC;
+	uint32_t elsRcvFAN;
+	uint32_t elsRcvLOGO;
+	uint32_t elsRcvPRLO;
+	uint32_t elsRcvPRLI;
+	uint32_t elsRcvRRQ;
+	uint32_t elsXmitFLOGI;
+	uint32_t elsXmitPLOGI;
+	uint32_t elsXmitPRLI;
+	uint32_t elsXmitADISC;
+	uint32_t elsXmitLOGO;
+	uint32_t elsXmitSCR;
+	uint32_t elsXmitRNID;
+	uint32_t elsXmitFARP;
+	uint32_t elsXmitFARPR;
+	uint32_t elsXmitACC;
+	uint32_t elsXmitLSRJT;
+
+	uint32_t frameRcvBcast;
+	uint32_t frameRcvMulti;
+	uint32_t strayXmitCmpl;
+	uint32_t frameXmitDelay;
+	uint32_t xriCmdCmpl;
+	uint32_t xriStatErr;
+	uint32_t LinkUp;
+	uint32_t LinkDown;
+	uint32_t LinkMultiEvent;
+	uint32_t NoRcvBuf;
+	uint32_t fcpCmd;
+	uint32_t fcpCmpl;
+	uint32_t fcpRspErr;
+	uint32_t fcpRemoteStop;
+	uint32_t fcpPortRjt;
+	uint32_t fcpPortBusy;
+	uint32_t fcpError;
+	uint32_t fcpLocalErr;
+};
+
+enum sysfs_mbox_state {
+	SMBOX_IDLE,
+	SMBOX_WRITING,
+	SMBOX_READING
+};
+
+struct lpfc_sysfs_mbox {
+	enum sysfs_mbox_state state;
+	size_t                offset;
+	struct lpfcMboxq *    mbox;
+};
+
+struct lpfc_hba {
+	uint32_t intr_inited;		/* flag for interrupt registration */
+	struct list_head hba_list;	/* List of hbas/ports */
+	struct lpfc_sli sli;
+	struct lpfc_sli2_slim *slim2p;
+	dma_addr_t slim2p_mapping;
+
+	uint32_t hba_state;
+
+#define LPFC_INIT_START           1	/* Initial state after board reset */
+#define LPFC_INIT_MBX_CMDS        2	/* Initialize HBA with mbox commands */
+#define LPFC_LINK_DOWN            3	/* HBA initialized, link is down */
+#define LPFC_LINK_UP              4	/* Link is up  - issue READ_LA */
+#define LPFC_LOCAL_CFG_LINK       5	/* local NPORT Id configured */
+#define LPFC_FLOGI                6	/* FLOGI sent to Fabric */
+#define LPFC_FABRIC_CFG_LINK      7	/* Fabric assigned NPORT Id
+					   configured */
+#define LPFC_NS_REG               8	/* Register with NameServer */
+#define LPFC_NS_QRY               9	/* Query NameServer for NPort ID list */
+#define LPFC_BUILD_DISC_LIST      10	/* Build ADISC and PLOGI lists for
+					 * device authentication / discovery */
+#define LPFC_DISC_AUTH            11	/* Processing ADISC list */
+#define LPFC_CLEAR_LA             12	/* authentication cmplt - issue
+					   CLEAR_LA */
+#define LPFC_HBA_READY            32
+#define LPFC_HBA_ERROR            0xff
+
+	uint8_t fc_linkspeed;	/* Link speed after last READ_LA */
+
+	uint32_t fc_eventTag;	/* event tag for link attention */
+	uint32_t fc_prli_sent;	/* cntr for outstanding PRLIs */
+
+	uint32_t num_disc_nodes;	/*in addition to hba_state */
+
+	uint8_t fcp_mapping;	/* Map FCP devices based on WWNN WWPN or DID */
+#define FCP_SEED_WWNN   0x1
+#define FCP_SEED_WWPN   0x2
+#define FCP_SEED_DID    0x4
+#define FCP_SEED_MASK   0x7
+#define FCP_SEED_AUTO   0x8	/* binding was created by auto mapping */
+
+	struct timer_list fc_estabtmo;	/* link establishment timer */
+	struct timer_list fc_disctmo;	/* Discovery rescue timer */
+	struct timer_list fc_fdmitmo;	/* fdmi timer */
+	struct timer_list fc_scantmo;	/* scsi scan host timer */
+
+
+	void *fc_evt_head;	/* waiting for event queue */
+	void *fc_evt_tail;	/* waiting for event queue */
+
+	uint16_t hba_event_put;	/* hbaevent event put word anchor */
+	uint16_t hba_event_get;	/* hbaevent event get word anchor */
+	uint32_t hba_event_missed;	/* hbaevent missed event word anchor */
+	uint32_t sid_cnt;	/* SCSI ID counter */
+
+	struct lpfc_hba_event hbaevt[MAX_HBAEVT];
+
+	/* These fields used to be binfo */
+	struct lpfc_name fc_nodename;	/* fc nodename */
+	struct lpfc_name fc_portname;	/* fc portname */
+	uint32_t fc_pref_DID;	/* preferred D_ID */
+	uint8_t fc_pref_ALPA;	/* preferred AL_PA */
+	uint32_t fc_edtov;	/* E_D_TOV timer value */
+	uint32_t fc_arbtov;	/* ARB_TOV timer value */
+	uint32_t fc_ratov;	/* R_A_TOV timer value */
+	uint32_t fc_rttov;	/* R_T_TOV timer value */
+	uint32_t fc_altov;	/* AL_TOV timer value */
+	uint32_t fc_crtov;	/* C_R_TOV timer value */
+	uint32_t fc_citov;	/* C_I_TOV timer value */
+	uint32_t fc_myDID;	/* fibre channel S_ID */
+	uint32_t fc_prevDID;	/* previous fibre channel S_ID */
+
+	struct serv_parm fc_sparam;	/* buffer for our service parameters */
+	struct serv_parm fc_fabparam;	/* fabric service parameters buffer */
+	uint8_t alpa_map[128];	/* AL_PA map from READ_LA */
+
+	uint8_t fc_ns_retry;	/* retries for fabric nameserver */
+	uint32_t fc_nlp_cnt;	/* outstanding NODELIST requests */
+	uint32_t fc_rscn_id_cnt;	/* count of RSCNs payloads in list */
+	struct lpfc_dmabuf *fc_rscn_id_list[FC_MAX_HOLD_RSCN];
+	uint32_t lmt;
+	uint32_t fc_flag;	/* FC flags */
+#define FC_PT2PT                0x1 	/* pt2pt with no fabric */
+#define FC_PT2PT_PLOGI          0x2 	/* pt2pt initiate PLOGI */
+#define FC_DISC_TMO             0x4 	/* Discovery timer running */
+#define FC_PUBLIC_LOOP          0x8	/* Public loop */
+#define FC_LBIT                 0x10 	/* LOGIN bit in loopinit set */
+#define FC_RSCN_MODE            0x20 	/* RSCN cmd rcv'ed */
+#define FC_NLP_MORE             0x40	/* More node to process in node tbl */
+#define FC_OFFLINE_MODE         0x80	/* Interface is offline for diag */
+#define FC_FABRIC               0x100	/* We are fabric attached */
+#define FC_ESTABLISH_LINK       0x200	/* Reestablish Link */
+#define FC_RSCN_DISCOVERY       0x400	/* Authenticate all devices after RSCN*/
+#define FC_LOADING		0x1000  /* HBA in process of loading drvr */
+#define FC_SCSI_SCAN_TMO        0x4000 	/* scsi scan timer running */
+#define FC_ABORT_DISCOVERY      0x8000 	/* we want to abort discovery */
+#define FC_NDISC_ACTIVE         0x10000	/* NPort discovery active */
+
+	uint32_t fc_topology;	/* link topology, from LINK INIT */
+
+	struct lpfc_stats fc_stat;
+
+	/* These are the head/tail pointers for the bind, plogi, adisc, unmap,
+	 *  and map lists.  Their counters are immediately following.
+	 */
+	struct list_head fc_nlpbind_list;
+	struct list_head fc_plogi_list;
+	struct list_head fc_adisc_list;
+	struct list_head fc_reglogin_list;
+	struct list_head fc_prli_list;
+	struct list_head fc_nlpunmap_list;
+	struct list_head fc_nlpmap_list;
+	struct list_head fc_npr_list;
+	struct list_head fc_unused_list;
+
+	/* Keep counters for the number of entries in each list. */
+	uint16_t fc_bind_cnt;
+	uint16_t fc_plogi_cnt;
+	uint16_t fc_adisc_cnt;
+	uint16_t fc_reglogin_cnt;
+	uint16_t fc_prli_cnt;
+	uint16_t fc_unmap_cnt;
+	uint16_t fc_map_cnt;
+	uint16_t fc_npr_cnt;
+	uint16_t fc_unused_cnt;
+	struct lpfc_nodelist fc_fcpnodev; /* nodelist entry for no device */
+	uint32_t nport_event_cnt;	/* timestamp for nlplist entry */
+
+	struct lpfc_target *device_queue_hash[MAX_FCP_TARGET];
+#define LPFC_RPI_HASH_SIZE     64
+#define LPFC_RPI_HASH_FUNC(x)  ((x) & (0x3f))
+	/* ptr to active D_ID / RPIs */
+	struct lpfc_nodelist *fc_nlplookup[LPFC_RPI_HASH_SIZE];
+	uint32_t wwnn[2];
+	uint32_t RandomData[7];
+
+	uint32_t cfg_log_verbose;
+	uint32_t cfg_lun_queue_depth;
+	uint32_t cfg_nodev_tmo;
+	uint32_t cfg_hba_queue_depth;
+	uint32_t cfg_fcp_class;
+	uint32_t cfg_use_adisc;
+	uint32_t cfg_ack0;
+	uint32_t cfg_topology;
+	uint32_t cfg_scan_down;
+	uint32_t cfg_link_speed;
+	uint32_t cfg_cr_delay;
+	uint32_t cfg_cr_count;
+	uint32_t cfg_fdmi_on;
+	uint32_t cfg_fcp_bind_method;
+	uint32_t cfg_discovery_threads;
+	uint32_t cfg_max_luns;
+	uint32_t cfg_scsi_hotplug;
+
+	lpfc_vpd_t vpd;		/* vital product data */
+
+#if defined(SLES_FC)
+	/*
+	 * Provide a per-HBA timer for 2.6.5 kernels patched with the
+	 * block/unblock FC transport patch.
+	 */
+	struct timer_list dev_loss_timer;
+#endif
+
+	struct Scsi_Host *host;
+	struct pci_dev *pcidev;
+	struct list_head      dpc_disc;
+
+	pid_t                 dpc_pid;
+	int                   dpc_kill;
+	struct completion     dpc_startup;
+	struct completion     dpc_exiting;
+	struct semaphore     *dpc_wait;
+	uint32_t              work_hba_events;  /* Timeout to be handled  */
+#define WORKER_DISC_TMO                0x1 	/* Discovery timeout */
+#define WORKER_ELS_TMO                 0x2 	/* ELS timeout */
+#define WORKER_MBOX_TMO                0x4 	/* MBOX timeout */
+#define WORKER_FDMI_TMO                0x8 	/* FDMI timeout */
+
+	unsigned long pci_bar0_map;     /* Physical address for PCI BAR0 */
+	unsigned long pci_bar2_map;     /* Physical address for PCI BAR2 */
+	void *slim_memmap_p;	        /* Kernel memory mapped address for PCI
+					   BAR0 */
+	void *ctrl_regs_memmap_p;	/* Kernel memory mapped address for PCI
+					   BAR2 */
+
+	void *MBslimaddr;	/* virtual address for mbox cmds */
+	void *HAregaddr;	/* virtual address for host attn reg */
+	void *CAregaddr;	/* virtual address for chip attn reg */
+	void *HSregaddr;	/* virtual address for host status reg */
+	void *HCregaddr;	/* virtual address for host ctl reg */
+	wait_queue_head_t linkevtwq;
+	wait_queue_head_t rscnevtwq;
+	wait_queue_head_t ctevtwq;
+
+	uint8_t brd_no;		/* FC board number */
+
+	char SerialNumber[32];		/* adapter Serial Number */
+	char OptionROMVersion[32];	/* adapter BIOS / Fcode version */
+	char ModelDesc[256];		/* Model Description */
+	char ModelName[80];		/* Model Name */
+	char ProgramType[256];		/* Program Type */
+	char Port[20];			/* Port No */
+	uint8_t vpd_flag;               /* VPD data flag */
+
+#define VPD_MODEL_DESC      0x1         /* valid vpd model description */
+#define VPD_MODEL_NAME      0x2         /* valid vpd model name */
+#define VPD_PROGRAM_TYPE    0x4         /* valid vpd program type */
+#define VPD_PORT            0x8         /* valid vpd port data */
+#define VPD_MASK            0xf         /* mask for any vpd data */
+
+	struct timer_list els_tmofunc;
+
+  	void *link_stats;
+
+	/*
+	 * stat  counters
+	 */
+	uint64_t fc4InputRequests;
+	uint64_t fc4OutputRequests;
+	uint64_t fc4ControlRequests;
+
+	struct lpfc_sysfs_mbox sysfs_mbox;
+;
+	/* pci_mem_pools */
+	struct pci_pool *lpfc_scsi_dma_ext_pool;
+	struct pci_pool *lpfc_mbuf_pool;
+	struct lpfc_dma_pool lpfc_mbuf_safety_pool;
+	mempool_t *scsibuf_mem_pool;
+
+	mempool_t *iocb_mem_pool;
+	mempool_t *mbox_mem_pool;
+	mempool_t *nlp_mem_pool;
+	mempool_t *bind_mem_pool;
+	struct list_head freebufList;
+	struct list_head ctrspbuflist;
+	struct list_head rnidrspbuflist;
+};
+
+/* event mask definitions */
+#define FC_REG_LINK_EVENT       0x1	/* Register for link up / down events */
+#define FC_REG_RSCN_EVENT       0x2	/* Register for RSCN events */
+#define FC_REG_CT_EVENT         0x4	/* Register for CT request events */
+
+#define FC_FSTYPE_ALL 0xffff	/* match on all fsTypes */
+
+typedef struct fcEVT {		/* Kernel level Event structure */
+	uint32_t evt_handle;
+	uint32_t evt_mask;
+	uint32_t evt_data0;
+	uint16_t evt_sleep;
+	uint16_t evt_flags;
+	void    *evt_type;
+	void    *evt_next;
+	void	*evt_data1;
+	uint32_t evt_data2;
+} fcEVT_t;
+
+typedef struct fcEVTHDR {	/* Kernel level Event Header */
+	uint32_t e_handle;
+	uint32_t e_mask;
+	uint16_t e_mode;
+#define E_SLEEPING_MODE     0x0001
+	uint16_t e_refcnt;
+	uint16_t e_flag;
+#define E_GET_EVENT_ACTIVE  0x0001
+	fcEVT_t *e_head;
+	fcEVT_t *e_tail;
+	void    *e_next_header;
+	void    *e_type;
+} fcEVTHDR_t;
+
+struct rnidrsp {
+	void *buf;
+	uint32_t uniqueid;
+	struct list_head list;
+	uint32_t data;
+};
+
+#endif				/* _H_LPFC */
--- linux-2.6.8.1-t044-driver-update//drivers/scsi/lpfc/lpfc_mbox.c	1970-01-01 03:00:00.000000000 +0300
+++ rhel4u2//drivers/scsi/lpfc/lpfc_mbox.c	2005-10-19 11:47:17.000000000 +0400
@@ -0,0 +1,665 @@
+/*******************************************************************
+ * This file is part of the Emulex Linux Device Driver for         *
+ * Fibre Channel Host Bus Adapters.                                *
+ * Copyright (C) 2003-2005 Emulex.  All rights reserved.           *
+ * EMULEX and SLI are trademarks of Emulex.                        *
+ * www.emulex.com                                                  *
+ *                                                                 *
+ * This program is free software; you can redistribute it and/or   *
+ * modify it under the terms of version 2 of the GNU General       *
+ * Public License as published by the Free Software Foundation.    *
+ * This program is distributed in the hope that it will be useful. *
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
+ * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
+ * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
+ * more details, a copy of which can be found in the file COPYING  *
+ * included with this package.                                     *
+ *******************************************************************/
+
+/*
+ * $Id: lpfc_mbox.c 1.77.2.2 2005/06/13 17:16:32EDT sf_support Exp  $
+ */
+#include <linux/version.h>
+#include <linux/blkdev.h>
+#include <linux/dma-mapping.h>
+#include <linux/pci.h>
+#include <linux/spinlock.h>
+#include <scsi/scsi_device.h>
+#include "lpfc_sli.h"
+#include "lpfc_disc.h"
+#include "lpfc_scsi.h"
+#include "lpfc.h"
+#include "lpfc_crtn.h"
+#include "lpfc_hw.h"
+#include "lpfc_logmsg.h"
+#include "lpfc_mem.h"
+#include "lpfc_compat.h"
+
+/**********************************************/
+
+/*                mailbox command             */
+/**********************************************/
+void
+lpfc_dump_mem(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, uint16_t offset)
+{
+	MAILBOX_t *mb;
+	void *ctx;
+
+	mb = &pmb->mb;
+	ctx = pmb->context2;
+
+	/* Setup to dump VPD region */
+	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
+	mb->mbxCommand = MBX_DUMP_MEMORY;
+	mb->un.varDmp.cv = 1;
+	mb->un.varDmp.type = DMP_NV_PARAMS;
+	mb->un.varDmp.entry_index = offset;
+	mb->un.varDmp.region_id = DMP_REGION_VPD;
+	mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t));
+	mb->un.varDmp.co = 0;
+	mb->un.varDmp.resp_offset = 0;
+	pmb->context2 = ctx;
+	mb->mbxOwner = OWN_HOST;
+	return;
+}
+
+/**********************************************/
+/*  lpfc_read_nv  Issue a READ NVPARAM        */
+/*                mailbox command             */
+/**********************************************/
+void
+lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
+{
+	MAILBOX_t *mb;
+
+	mb = &pmb->mb;
+	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
+	mb->mbxCommand = MBX_READ_NV;
+	mb->mbxOwner = OWN_HOST;
+	return;
+}
+
+/**********************************************/
+/*  lpfc_read_la  Issue a READ LA             */
+/*                mailbox command             */
+/**********************************************/
+int
+lpfc_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
+{
+	MAILBOX_t *mb;
+	struct lpfc_dmabuf *mp;
+	struct lpfc_sli *psli;
+
+	psli = &phba->sli;
+	mb = &pmb->mb;
+	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
+
+	/* Get a buffer to hold the loop map */
+	if (((mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_ATOMIC)) == 0) ||
+	    ((mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys))) == 0)) {
+		if (mp)
+			kfree(mp);
+		mb->mbxCommand = MBX_READ_LA64;
+		/* READ_LA: no buffers */
+		lpfc_printf_log(phba,
+			       KERN_WARNING,
+			       LOG_MBOX,
+			       "%d:0300 READ_LA: no buffers\n",
+			       phba->brd_no);
+		return (1);
+	}
+	INIT_LIST_HEAD(&mp->list);
+	mb->mbxCommand = MBX_READ_LA64;
+	mb->un.varReadLA.un.lilpBde64.tus.f.bdeSize = 128;
+	mb->un.varReadLA.un.lilpBde64.addrHigh = putPaddrHigh(mp->phys);
+	mb->un.varReadLA.un.lilpBde64.addrLow = putPaddrLow(mp->phys);
+
+	/* Save address for later completion and set the owner to host so that
+	 * the FW knows this mailbox is available for processing.
+	 */
+	pmb->context1 = (uint8_t *) mp;
+	mb->mbxOwner = OWN_HOST;
+	return (0);
+}
+
+/**********************************************/
+/*  lpfc_clear_la  Issue a CLEAR LA           */
+/*                 mailbox command            */
+/**********************************************/
+void
+lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
+{
+	MAILBOX_t *mb;
+
+	mb = &pmb->mb;
+	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
+
+	mb->un.varClearLA.eventTag = phba->fc_eventTag;
+	mb->mbxCommand = MBX_CLEAR_LA;
+	mb->mbxOwner = OWN_HOST;
+	return;
+}
+
+/**************************************************/
+/*  lpfc_config_link  Issue a CONFIG LINK         */
+/*                    mailbox command             */
+/**************************************************/
+void
+lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
+{
+	MAILBOX_t *mb = &pmb->mb;
+	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
+
+	/* NEW_FEATURE
+	 * SLI-2, Coalescing Response Feature.
+	 */
+	if (phba->cfg_cr_delay) {
+		mb->un.varCfgLnk.cr = 1;
+		mb->un.varCfgLnk.ci = 1;
+		mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay;
+		mb->un.varCfgLnk.cr_count = phba->cfg_cr_count;
+	}
+
+	mb->un.varCfgLnk.myId = phba->fc_myDID;
+	mb->un.varCfgLnk.edtov = phba->fc_edtov;
+	mb->un.varCfgLnk.arbtov = phba->fc_arbtov;
+	mb->un.varCfgLnk.ratov = phba->fc_ratov;
+	mb->un.varCfgLnk.rttov = phba->fc_rttov;
+	mb->un.varCfgLnk.altov = phba->fc_altov;
+	mb->un.varCfgLnk.crtov = phba->fc_crtov;
+	mb->un.varCfgLnk.citov = phba->fc_citov;
+
+	if (phba->cfg_ack0)
+		mb->un.varCfgLnk.ack0_enable = 1;
+
+	mb->mbxCommand = MBX_CONFIG_LINK;
+	mb->mbxOwner = OWN_HOST;
+	return;
+}
+
+/**********************************************/
+/*  lpfc_init_link  Issue an INIT LINK        */
+/*                  mailbox command           */
+/**********************************************/
+void
+lpfc_init_link(struct lpfc_hba * phba,
+	       LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed)
+{
+	lpfc_vpd_t *vpd;
+	struct lpfc_sli *psli;
+	MAILBOX_t *mb;
+
+	mb = &pmb->mb;
+	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
+
+	psli = &phba->sli;
+	switch (topology) {
+	case FLAGS_TOPOLOGY_MODE_LOOP_PT:
+		mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
+		mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
+		break;
+	case FLAGS_TOPOLOGY_MODE_PT_PT:
+		mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
+		break;
+	case FLAGS_TOPOLOGY_MODE_LOOP:
+		mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
+		break;
+	case FLAGS_TOPOLOGY_MODE_PT_LOOP:
+		mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
+		mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
+		break;
+	}
+
+	/* NEW_FEATURE
+	 * Setting up the link speed
+	 */
+	vpd = &phba->vpd;
+	if (vpd->rev.feaLevelHigh >= 0x02){
+		switch(linkspeed){
+			case LINK_SPEED_1G:
+			case LINK_SPEED_2G:
+			case LINK_SPEED_4G:
+				mb->un.varInitLnk.link_flags |=
+							FLAGS_LINK_SPEED;
+				mb->un.varInitLnk.link_speed = linkspeed;
+			break;
+			case LINK_SPEED_AUTO:
+			default:
+				mb->un.varInitLnk.link_speed =
+							LINK_SPEED_AUTO;
+			break;
+		}
+
+	}
+	else
+		mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
+
+	mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK;
+	mb->mbxOwner = OWN_HOST;
+	mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA;
+	return;
+}
+
+/**********************************************/
+/*  lpfc_read_sparam  Issue a READ SPARAM     */
+/*                    mailbox command         */
+/**********************************************/
+int
+lpfc_read_sparam(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
+{
+	struct lpfc_dmabuf *mp;
+	MAILBOX_t *mb;
+	struct lpfc_sli *psli;
+
+	psli = &phba->sli;
+	mb = &pmb->mb;
+	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
+
+	mb->mbxOwner = OWN_HOST;
+
+	/* Get a buffer to hold the HBAs Service Parameters */
+
+	if (((mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_ATOMIC)) == 0) ||
+	    ((mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys))) == 0)) {
+		if (mp)
+			kfree(mp);
+		mb->mbxCommand = MBX_READ_SPARM64;
+		/* READ_SPARAM: no buffers */
+		lpfc_printf_log(phba,
+			        KERN_WARNING,
+			        LOG_MBOX,
+			        "%d:0301 READ_SPARAM: no buffers\n",
+			        phba->brd_no);
+		return (1);
+	}
+	INIT_LIST_HEAD(&mp->list);
+	mb->mbxCommand = MBX_READ_SPARM64;
+	mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
+	mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys);
+	mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys);
+
+	/* save address for completion */
+	pmb->context1 = mp;
+
+	return (0);
+}
+
+/********************************************/
+/*  lpfc_unreg_did  Issue a UNREG_DID       */
+/*                  mailbox command         */
+/********************************************/
+void
+lpfc_unreg_did(struct lpfc_hba * phba, uint32_t did, LPFC_MBOXQ_t * pmb)
+{
+	MAILBOX_t *mb;
+
+	mb = &pmb->mb;
+	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
+
+	mb->un.varUnregDID.did = did;
+
+	mb->mbxCommand = MBX_UNREG_D_ID;
+	mb->mbxOwner = OWN_HOST;
+	return;
+}
+
+/***********************************************/
+
+/*                  command to write slim      */
+/***********************************************/
+void
+lpfc_set_slim(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, uint32_t addr,
+	      uint32_t value)
+{
+	MAILBOX_t *mb;
+
+	mb = &pmb->mb;
+	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
+
+	/* addr = 0x090597 is AUTO ABTS disable for ELS commands */
+	/* addr = 0x052198 is DELAYED ABTS enable for ELS commands */
+
+	/*
+	 * Always turn on DELAYED ABTS for ELS timeouts
+	 */
+	if ((addr == 0x052198) && (value == 0))
+		value = 1;
+
+	mb->un.varWords[0] = addr;
+	mb->un.varWords[1] = value;
+
+	mb->mbxCommand = MBX_SET_SLIM;
+	mb->mbxOwner = OWN_HOST;
+	return;
+}
+
+/**********************************************/
+/*  lpfc_read_config  Issue a READ CONFIG     */
+/*                mailbox command             */
+/**********************************************/
+void
+lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
+{
+	MAILBOX_t *mb;
+
+	mb = &pmb->mb;
+	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
+
+	mb->mbxCommand = MBX_READ_CONFIG;
+	mb->mbxOwner = OWN_HOST;
+	return;
+}
+
+/********************************************/
+/*  lpfc_reg_login  Issue a REG_LOGIN       */
+/*                  mailbox command         */
+/********************************************/
+int
+lpfc_reg_login(struct lpfc_hba * phba,
+	       uint32_t did, uint8_t * param, LPFC_MBOXQ_t * pmb, uint32_t flag)
+{
+	uint8_t *sparam;
+	struct lpfc_dmabuf *mp;
+	MAILBOX_t *mb;
+	struct lpfc_sli *psli;
+
+	psli = &phba->sli;
+	mb = &pmb->mb;
+	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
+
+	mb->un.varRegLogin.rpi = 0;
+	mb->un.varRegLogin.did = did;
+	mb->un.varWords[30] = flag;	/* Set flag to issue action on cmpl */
+
+	mb->mbxOwner = OWN_HOST;
+
+	/* Get a buffer to hold NPorts Service Parameters */
+	if (((mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_ATOMIC)) == 0) ||
+	    ((mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys))) == 0)) {
+		if (mp)
+			kfree(mp);
+
+		mb->mbxCommand = MBX_REG_LOGIN64;
+		/* REG_LOGIN: no buffers */
+		lpfc_printf_log(phba,
+			       KERN_WARNING,
+			       LOG_MBOX,
+			       "%d:0302 REG_LOGIN: no buffers Data x%x x%x\n",
+			       phba->brd_no,
+			       (uint32_t) did, (uint32_t) flag);
+		return (1);
+	}
+	INIT_LIST_HEAD(&mp->list);
+	sparam = mp->virt;
+
+	/* Copy param's into a new buffer */
+	memcpy(sparam, param, sizeof (struct serv_parm));
+
+	/* save address for completion */
+	pmb->context1 = (uint8_t *) mp;
+
+	mb->mbxCommand = MBX_REG_LOGIN64;
+	mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
+	mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys);
+	mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys);
+
+	return (0);
+}
+
+/**********************************************/
+/*  lpfc_unreg_login  Issue a UNREG_LOGIN     */
+/*                    mailbox command         */
+/**********************************************/
+void
+lpfc_unreg_login(struct lpfc_hba * phba, uint32_t rpi, LPFC_MBOXQ_t * pmb)
+{
+	MAILBOX_t *mb;
+
+	mb = &pmb->mb;
+	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
+
+	mb->un.varUnregLogin.rpi = (uint16_t) rpi;
+	mb->un.varUnregLogin.rsvd1 = 0;
+
+	mb->mbxCommand = MBX_UNREG_LOGIN;
+	mb->mbxOwner = OWN_HOST;
+	return;
+}
+
+static void
+lpfc_config_pcb_setup(struct lpfc_hba * phba)
+{
+	struct lpfc_sli *psli = &phba->sli;
+	struct lpfc_sli_ring *pring;
+	PCB_t *pcbp = &phba->slim2p->pcb;
+	LPFC_RING_INIT_t *pringinit;
+	dma_addr_t pdma_addr;
+	uint32_t offset;
+	uint32_t iocbCnt;
+	int i;
+
+	psli->MBhostaddr = (uint32_t *)&phba->slim2p->mbx;
+	pcbp->maxRing = (psli->sliinit.num_rings - 1);
+
+	iocbCnt = 0;
+	for (i = 0; i < psli->sliinit.num_rings; i++) {
+		pringinit = &psli->sliinit.ringinit[i];
+		pring = &psli->ring[i];
+		/* A ring MUST have both cmd and rsp entries defined to be
+		   valid */
+		if ((pringinit->numCiocb == 0) || (pringinit->numRiocb == 0)) {
+			pcbp->rdsc[i].cmdEntries = 0;
+			pcbp->rdsc[i].rspEntries = 0;
+			pcbp->rdsc[i].cmdAddrHigh = 0;
+			pcbp->rdsc[i].rspAddrHigh = 0;
+			pcbp->rdsc[i].cmdAddrLow = 0;
+			pcbp->rdsc[i].rspAddrLow = 0;
+			pring->cmdringaddr = NULL;
+			pring->rspringaddr = NULL;
+			continue;
+		}
+		/* Command ring setup for ring */
+		pring->cmdringaddr =
+		    (void *)&phba->slim2p->IOCBs[iocbCnt];
+		pcbp->rdsc[i].cmdEntries = pringinit->numCiocb;
+
+		offset = (uint8_t *)&phba->slim2p->IOCBs[iocbCnt] -
+			 (uint8_t *)phba->slim2p;
+		pdma_addr = phba->slim2p_mapping + offset;
+		pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr);
+		pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr);
+		iocbCnt += pringinit->numCiocb;
+
+		/* Response ring setup for ring */
+		pring->rspringaddr =
+		    (void *)&phba->slim2p->IOCBs[iocbCnt];
+
+		pcbp->rdsc[i].rspEntries = pringinit->numRiocb;
+		offset = (uint8_t *)&phba->slim2p->IOCBs[iocbCnt] -
+			 (uint8_t *)phba->slim2p;
+		pdma_addr = phba->slim2p_mapping + offset;
+		pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr);
+		pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr);
+		iocbCnt += pringinit->numRiocb;
+	}
+}
+
+void
+lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
+{
+	MAILBOX_t *mb;
+
+	mb = &pmb->mb;
+	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
+	mb->un.varRdRev.cv = 1;
+	mb->mbxCommand = MBX_READ_REV;
+	mb->mbxOwner = OWN_HOST;
+	return;
+}
+
+void
+lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
+{
+	int i;
+	MAILBOX_t *mb = &pmb->mb;
+	struct lpfc_sli *psli;
+	LPFC_RING_INIT_t *pring;
+
+	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
+
+	mb->un.varCfgRing.ring = ring;
+	mb->un.varCfgRing.maxOrigXchg = 0;
+	mb->un.varCfgRing.maxRespXchg = 0;
+	mb->un.varCfgRing.recvNotify = 1;
+
+	psli = &phba->sli;
+	pring = &psli->sliinit.ringinit[ring];
+	mb->un.varCfgRing.numMask = pring->num_mask;
+	mb->mbxCommand = MBX_CONFIG_RING;
+	mb->mbxOwner = OWN_HOST;
+
+	/* Is this ring configured for a specific profile */
+	if (pring->prt[0].profile) {
+		mb->un.varCfgRing.profile = pring->prt[0].profile;
+		return;
+	}
+
+	/* Otherwise we setup specific rctl / type masks for this ring */
+	for (i = 0; i < pring->num_mask; i++) {
+		mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl;
+		if (mb->un.varCfgRing.rrRegs[i].rval != FC_ELS_REQ)
+			mb->un.varCfgRing.rrRegs[i].rmask = 0xff;
+		else
+			mb->un.varCfgRing.rrRegs[i].rmask = 0xfe;
+		mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type;
+		mb->un.varCfgRing.rrRegs[i].tmask = 0xff;
+	}
+
+	return;
+}
+
+void
+lpfc_config_port(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
+{
+	MAILBOX_t *mb = &pmb->mb;
+	dma_addr_t pdma_addr;
+	uint32_t bar_low, bar_high;
+	size_t offset;
+	HGP hgp;
+	void *to_slim;
+
+	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
+	mb->mbxCommand = MBX_CONFIG_PORT;
+	mb->mbxOwner = OWN_HOST;
+
+	mb->un.varCfgPort.pcbLen = sizeof(PCB_t);
+	offset = (uint8_t *)&phba->slim2p->pcb - (uint8_t *)phba->slim2p;
+	pdma_addr = phba->slim2p_mapping + offset;
+	mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr);
+	mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr);
+
+	/* Now setup pcb */
+	phba->slim2p->pcb.type = TYPE_NATIVE_SLI2;
+	phba->slim2p->pcb.feature = FEATURE_INITIAL_SLI2;
+
+	/* Setup Mailbox pointers */
+	phba->slim2p->pcb.mailBoxSize = sizeof(MAILBOX_t);
+	offset = (uint8_t *)&phba->slim2p->mbx - (uint8_t *)phba->slim2p;
+	pdma_addr = phba->slim2p_mapping + offset;
+	phba->slim2p->pcb.mbAddrHigh = putPaddrHigh(pdma_addr);
+	phba->slim2p->pcb.mbAddrLow = putPaddrLow(pdma_addr);
+
+	/*
+	 * Setup Host Group ring pointer.
+	 *
+	 * For efficiency reasons, the ring get/put pointers can be
+	 * placed in adapter memory (SLIM) rather than in host memory.
+	 * This allows firmware to avoid PCI reads/writes when updating
+	 * and checking pointers.
+	 *
+	 * The firmware recognizes the use of SLIM memory by comparing
+	 * the address of the get/put pointers structure with that of
+	 * the SLIM BAR (BAR0).
+	 *
+	 * Caution: be sure to use the PCI config space value of BAR0/BAR1
+	 * (the hardware's view of the base address), not the OS's
+	 * value of pci_resource_start() as the OS value may be a cookie
+	 * for ioremap/iomap.
+	 */
+
+
+	pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low);
+	pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high);
+
+
+	/* mask off BAR0's flag bits 0 - 3 */
+	phba->slim2p->pcb.hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) +
+					(SLIMOFF*sizeof(uint32_t));
+	if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64)
+		phba->slim2p->pcb.hgpAddrHigh = bar_high;
+	else
+		phba->slim2p->pcb.hgpAddrHigh = 0;
+	/* write HGP data to SLIM at the required longword offset */
+	memset(&hgp, 0, sizeof(HGP));
+	to_slim = (uint8_t *)phba->MBslimaddr + (SLIMOFF*sizeof (uint32_t));
+	lpfc_memcpy_to_slim(to_slim, &hgp, sizeof (HGP));
+
+	/* Setup Port Group ring pointer */
+	offset = (uint8_t *)&phba->slim2p->mbx.us.s2.port -
+		 (uint8_t *)phba->slim2p;
+	pdma_addr = phba->slim2p_mapping + offset;
+	phba->slim2p->pcb.pgpAddrHigh = putPaddrHigh(pdma_addr);
+	phba->slim2p->pcb.pgpAddrLow = putPaddrLow(pdma_addr);
+
+	/* Use callback routine to setp rings in the pcb */
+	lpfc_config_pcb_setup(phba);
+
+	/* special handling for LC HBAs */
+	if (lpfc_is_LC_HBA(phba->pcidev->device)) {
+		uint32_t hbainit[5];
+
+		lpfc_hba_init(phba, hbainit);
+
+		memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20);
+	}
+
+	/* Swap PCB if needed */
+	lpfc_sli_pcimem_bcopy((uint32_t *)&phba->slim2p->pcb,
+			      (uint32_t *)&phba->slim2p->pcb,
+			      sizeof (PCB_t));
+
+	lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
+		        "%d:0405 Service Level Interface (SLI) 2 selected\n",
+		        phba->brd_no);
+}
+
+void
+lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
+{
+	struct lpfc_sli *psli;
+
+	psli = &phba->sli;
+
+	list_add_tail(&mbq->list, &psli->mboxq);
+
+	psli->mboxq_cnt++;
+
+	return;
+}
+
+LPFC_MBOXQ_t *
+lpfc_mbox_get(struct lpfc_hba * phba)
+{
+	LPFC_MBOXQ_t *mbq = NULL;
+	struct lpfc_sli *psli = &phba->sli;
+
+	if (!list_empty(&psli->mboxq)) {
+		mbq = list_entry(psli->mboxq.next, LPFC_MBOXQ_t, list);
+		list_del_init(&mbq->list);
+		psli->mboxq_cnt--;
+	}
+
+	return mbq;
+}
--- linux-2.6.8.1-t044-driver-update//drivers/scsi/lpfc/lpfc_sli.c	1970-01-01 03:00:00.000000000 +0300
+++ rhel4u2//drivers/scsi/lpfc/lpfc_sli.c	2005-10-19 11:47:17.000000000 +0400
@@ -0,0 +1,3447 @@
+/*******************************************************************
+ * This file is part of the Emulex Linux Device Driver for         *
+ * Fibre Channel Host Bus Adapters.                                *
+ * Copyright (C) 2003-2005 Emulex.  All rights reserved.           *
+ * EMULEX and SLI are trademarks of Emulex.                        *
+ * www.emulex.com                                                  *
+ *                                                                 *
+ * This program is free software; you can redistribute it and/or   *
+ * modify it under the terms of version 2 of the GNU General       *
+ * Public License as published by the Free Software Foundation.    *
+ * This program is distributed in the hope that it will be useful. *
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
+ * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
+ * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
+ * more details, a copy of which can be found in the file COPYING  *
+ * included with this package.                                     *
+ *******************************************************************/
+
+/*
+ * $Id: lpfc_sli.c 1.200.1.8 2005/07/27 17:00:59EDT sf_support Exp  $
+ */
+
+#include <linux/version.h>
+#include <linux/blkdev.h>
+#include <linux/dma-mapping.h>
+#include <linux/pci.h>
+#include <linux/spinlock.h>
+
+#include <scsi/scsi_cmnd.h>
+#include <scsi/scsi_device.h>
+#include <scsi/scsi_host.h>
+
+#include "lpfc_sli.h"
+#include "lpfc_disc.h"
+#include "lpfc_scsi.h"
+#include "lpfc.h"
+#include "lpfc_crtn.h"
+#include "lpfc_hw.h"
+#include "lpfc_logmsg.h"
+#include "lpfc_mem.h"
+#include "lpfc_compat.h"
+#include "lpfc_fcp.h"
+
+static int lpfc_sli_reset_on_init = 1;
+extern void
+lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *, struct lpfc_iocbq *, struct lpfc_iocbq *);
+/*
+ * Define macro to log: Mailbox command x%x cannot issue Data
+ * This allows multiple uses of lpfc_msgBlk0311
+ * w/o perturbing log msg utility.
+*/
+#define LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag) \
+			lpfc_printf_log(phba, \
+				KERN_INFO, \
+				LOG_MBOX | LOG_SLI, \
+				"%d:0311 Mailbox command x%x cannot issue " \
+				"Data: x%x x%x x%x\n", \
+				phba->brd_no, \
+				mb->mbxCommand,		\
+				phba->hba_state,	\
+				psli->sliinit.sli_flag,	\
+				flag);
+
+
+/* This will save a huge switch to determine if the IOCB cmd
+ * is unsolicited or solicited.
+ */
+#define LPFC_UNKNOWN_IOCB 0
+#define LPFC_UNSOL_IOCB   1
+#define LPFC_SOL_IOCB     2
+#define LPFC_ABORT_IOCB   3
+static uint8_t lpfc_sli_iocb_cmd_type[CMD_MAX_IOCB_CMD] = {
+	LPFC_UNKNOWN_IOCB,	/* 0x00 */
+	LPFC_UNSOL_IOCB,	/* CMD_RCV_SEQUENCE_CX     0x01 */
+	LPFC_SOL_IOCB,		/* CMD_XMIT_SEQUENCE_CR    0x02 */
+	LPFC_SOL_IOCB,		/* CMD_XMIT_SEQUENCE_CX    0x03 */
+	LPFC_SOL_IOCB,		/* CMD_XMIT_BCAST_CN       0x04 */
+	LPFC_SOL_IOCB,		/* CMD_XMIT_BCAST_CX       0x05 */
+	LPFC_UNKNOWN_IOCB,	/* CMD_QUE_RING_BUF_CN     0x06 */
+	LPFC_UNKNOWN_IOCB,	/* CMD_QUE_XRI_BUF_CX      0x07 */
+	LPFC_UNKNOWN_IOCB,	/* CMD_IOCB_CONTINUE_CN    0x08 */
+	LPFC_UNKNOWN_IOCB,	/* CMD_RET_XRI_BUF_CX      0x09 */
+	LPFC_SOL_IOCB,		/* CMD_ELS_REQUEST_CR      0x0A */
+	LPFC_SOL_IOCB,		/* CMD_ELS_REQUEST_CX      0x0B */
+	LPFC_UNKNOWN_IOCB,	/* 0x0C */
+	LPFC_UNSOL_IOCB,	/* CMD_RCV_ELS_REQ_CX      0x0D */
+	LPFC_ABORT_IOCB,	/* CMD_ABORT_XRI_CN        0x0E */
+	LPFC_ABORT_IOCB,	/* CMD_ABORT_XRI_CX        0x0F */
+	LPFC_ABORT_IOCB,	/* CMD_CLOSE_XRI_CR        0x10 */
+	LPFC_ABORT_IOCB,	/* CMD_CLOSE_XRI_CX        0x11 */
+	LPFC_SOL_IOCB,		/* CMD_CREATE_XRI_CR       0x12 */
+	LPFC_SOL_IOCB,		/* CMD_CREATE_XRI_CX       0x13 */
+	LPFC_SOL_IOCB,		/* CMD_GET_RPI_CN          0x14 */
+	LPFC_SOL_IOCB,		/* CMD_XMIT_ELS_RSP_CX     0x15 */
+	LPFC_SOL_IOCB,		/* CMD_GET_RPI_CR          0x16 */
+	LPFC_ABORT_IOCB,	/* CMD_XRI_ABORTED_CX      0x17 */
+	LPFC_SOL_IOCB,		/* CMD_FCP_IWRITE_CR       0x18 */
+	LPFC_SOL_IOCB,		/* CMD_FCP_IWRITE_CX       0x19 */
+	LPFC_SOL_IOCB,		/* CMD_FCP_IREAD_CR        0x1A */
+	LPFC_SOL_IOCB,		/* CMD_FCP_IREAD_CX        0x1B */
+	LPFC_SOL_IOCB,		/* CMD_FCP_ICMND_CR        0x1C */
+	LPFC_SOL_IOCB,		/* CMD_FCP_ICMND_CX        0x1D */
+	LPFC_UNKNOWN_IOCB,	/* 0x1E */
+	LPFC_SOL_IOCB,		/* CMD_FCP_TSEND_CX        0x1F */
+	LPFC_SOL_IOCB,		/* CMD_ADAPTER_MSG         0x20 */
+	LPFC_SOL_IOCB,		/* CMD_FCP_TRECEIVE_CX     0x21 */
+	LPFC_SOL_IOCB,		/* CMD_ADAPTER_DUMP        0x22 */
+	LPFC_SOL_IOCB,		/* CMD_FCP_TRSP_CX         0x23 */
+	/* 0x24 - 0x80 */
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	/* 0x30 */
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB,
+	/* 0x40 */
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB,
+	/* 0x50 */
+	LPFC_SOL_IOCB,
+	LPFC_SOL_IOCB,
+	LPFC_UNKNOWN_IOCB,
+	LPFC_SOL_IOCB,
+	LPFC_SOL_IOCB,
+	LPFC_UNSOL_IOCB,
+	LPFC_UNSOL_IOCB,
+	LPFC_SOL_IOCB,
+	LPFC_SOL_IOCB,
+
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB,
+	/* 0x60 */
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB,
+	/* 0x70 */
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB,
+	/* 0x80 */
+	LPFC_UNKNOWN_IOCB,
+	LPFC_UNSOL_IOCB,	/* CMD_RCV_SEQUENCE64_CX   0x81 */
+	LPFC_SOL_IOCB,		/* CMD_XMIT_SEQUENCE64_CR  0x82 */
+	LPFC_SOL_IOCB,		/* CMD_XMIT_SEQUENCE64_CX  0x83 */
+	LPFC_SOL_IOCB,		/* CMD_XMIT_BCAST64_CN     0x84 */
+	LPFC_SOL_IOCB,		/* CMD_XMIT_BCAST64_CX     0x85 */
+	LPFC_UNKNOWN_IOCB,	/* CMD_QUE_RING_BUF64_CN   0x86 */
+	LPFC_UNKNOWN_IOCB,	/* CMD_QUE_XRI_BUF64_CX    0x87 */
+	LPFC_UNKNOWN_IOCB,	/* CMD_IOCB_CONTINUE64_CN  0x88 */
+	LPFC_UNKNOWN_IOCB,	/* CMD_RET_XRI_BUF64_CX    0x89 */
+	LPFC_SOL_IOCB,		/* CMD_ELS_REQUEST64_CR    0x8A */
+	LPFC_SOL_IOCB,		/* CMD_ELS_REQUEST64_CX    0x8B */
+	LPFC_ABORT_IOCB,	/* CMD_ABORT_MXRI64_CN     0x8C */
+	LPFC_UNSOL_IOCB,	/* CMD_RCV_ELS_REQ64_CX    0x8D */
+	/* 0x8E - 0x94 */
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB,
+	LPFC_SOL_IOCB,		/* CMD_XMIT_ELS_RSP64_CX   0x95 */
+	LPFC_UNKNOWN_IOCB,	/* 0x96 */
+	LPFC_UNKNOWN_IOCB,	/* 0x97 */
+	LPFC_SOL_IOCB,		/* CMD_FCP_IWRITE64_CR     0x98 */
+	LPFC_SOL_IOCB,		/* CMD_FCP_IWRITE64_CX     0x99 */
+	LPFC_SOL_IOCB,		/* CMD_FCP_IREAD64_CR      0x9A */
+	LPFC_SOL_IOCB,		/* CMD_FCP_IREAD64_CX      0x9B */
+	LPFC_SOL_IOCB,		/* CMD_FCP_ICMND64_CR      0x9C */
+	LPFC_SOL_IOCB,		/* CMD_FCP_ICMND64_CX      0x9D */
+	LPFC_UNKNOWN_IOCB,	/* 0x9E */
+	LPFC_SOL_IOCB,		/* CMD_FCP_TSEND64_CX      0x9F */
+	LPFC_UNKNOWN_IOCB,	/* 0xA0 */
+	LPFC_SOL_IOCB,		/* CMD_FCP_TRECEIVE64_CX   0xA1 */
+	LPFC_UNKNOWN_IOCB,	/* 0xA2 */
+	LPFC_SOL_IOCB,		/* CMD_FCP_TRSP64_CX       0xA3 */
+	/* 0xA4 - 0xC1 */
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_SOL_IOCB,		/* CMD_GEN_REQUEST64_CR    0xC2 */
+	LPFC_SOL_IOCB,		/* CMD_GEN_REQUEST64_CX    0xC3 */
+	/* 0xC4 - 0xCF */
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+
+	LPFC_SOL_IOCB,
+	LPFC_SOL_IOCB,		/* CMD_SENDTEXT_CR              0xD1 */
+	LPFC_SOL_IOCB,		/* CMD_SENDTEXT_CX              0xD2 */
+	LPFC_SOL_IOCB,		/* CMD_RCV_LOGIN                0xD3 */
+	LPFC_SOL_IOCB,		/* CMD_ACCEPT_LOGIN             0xD4 */
+	LPFC_SOL_IOCB,		/* CMD_REJECT_LOGIN             0xD5 */
+	LPFC_UNSOL_IOCB,
+	/* 0xD7 - 0xDF */
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB, LPFC_UNKNOWN_IOCB,
+	/* 0xE0 */
+	LPFC_UNSOL_IOCB,
+	LPFC_SOL_IOCB,
+	LPFC_SOL_IOCB,
+	LPFC_SOL_IOCB,
+	LPFC_SOL_IOCB,
+	LPFC_UNSOL_IOCB
+};
+
+static void
+lpfc_sli_wake_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
+{
+	wait_queue_head_t *pdone_q;
+
+	/*
+	 * If pdone_q is empty, the driver thread gave up waiting and
+	 * continued running.
+	 */
+	pdone_q = (wait_queue_head_t *) pmboxq->context1;
+	if (pdone_q)
+		wake_up_interruptible(pdone_q);
+	return;
+}
+
+
+
+static int
+lpfc_sli_ring_map(struct lpfc_hba * phba)
+{
+	struct lpfc_sli *psli;
+	LPFC_MBOXQ_t *pmb;
+	MAILBOX_t *pmbox;
+	int i;
+
+	psli = &phba->sli;
+
+	/* Get a Mailbox buffer to setup mailbox commands for HBA
+	   initialization */
+	if ((pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
+						  GFP_ATOMIC)) == 0) {
+		phba->hba_state = LPFC_HBA_ERROR;
+		return -ENOMEM;
+	}
+	pmbox = &pmb->mb;
+
+	/* Initialize the struct lpfc_sli_ring structure for each ring */
+	for (i = 0; i < psli->sliinit.num_rings; i++) {
+		/* Issue a CONFIG_RING mailbox command for each ring */
+		phba->hba_state = LPFC_INIT_MBX_CMDS;
+		lpfc_config_ring(phba, i, pmb);
+		if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
+			/* Adapter failed to init, mbxCmd <cmd> CFG_RING,
+			   mbxStatus <status>, ring <num> */
+			lpfc_printf_log(phba,
+					KERN_ERR,
+					LOG_INIT,
+					"%d:0446 Adapter failed to init, "
+					"mbxCmd x%x CFG_RING, mbxStatus x%x, "
+					"ring %d\n",
+					phba->brd_no,
+					pmbox->mbxCommand,
+					pmbox->mbxStatus,
+					i);
+			phba->hba_state = LPFC_HBA_ERROR;
+			mempool_free( pmb, phba->mbox_mem_pool);
+			return -ENXIO;
+		}
+	}
+	mempool_free( pmb, phba->mbox_mem_pool);
+	return 0;
+}
+
+static int
+lpfc_sli_ringtxcmpl_put(struct lpfc_hba * phba,
+			struct lpfc_sli_ring * pring, struct lpfc_iocbq * piocb)
+{
+	uint16_t iotag;
+
+	list_add_tail(&piocb->list, &pring->txcmplq);
+	pring->txcmplq_cnt++;
+	if (unlikely(pring->ringno == LPFC_ELS_RING))
+		mod_timer(&phba->els_tmofunc,
+					jiffies + HZ * (phba->fc_ratov << 1));
+
+	if (pring->fast_lookup) {
+		/* Setup fast lookup based on iotag for completion */
+		iotag = piocb->iocb.ulpIoTag;
+		if (iotag && (iotag
+		      < phba->sli.sliinit.ringinit[pring->ringno].fast_iotag))
+			*(pring->fast_lookup + iotag) = piocb;
+		else {
+
+			/* Cmd ring <ringno> put: iotag <iotag> greater then
+			   configured max <fast_iotag> wd0 <icmd> */
+			lpfc_printf_log(phba,
+					KERN_ERR,
+					LOG_SLI,
+					"%d:0316 Cmd ring %d put: iotag x%x "
+					"greater then configured max x%x "
+					"wd0 x%x\n",
+					phba->brd_no,
+					pring->ringno, iotag, phba->sli.sliinit
+					.ringinit[pring->ringno].fast_iotag,
+					*(((uint32_t *)(&piocb->iocb)) + 7));
+		}
+	}
+	return (0);
+}
+
+static int
+lpfc_sli_ringtx_put(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
+		    struct lpfc_iocbq * piocb)
+{
+	/* Insert the caller's iocb in the txq tail for later processing. */
+	list_add_tail(&piocb->list, &pring->txq);
+	pring->txq_cnt++;
+	return (0);
+}
+
+static struct lpfc_iocbq *
+lpfc_sli_ringtx_get(struct lpfc_hba * phba, struct lpfc_sli_ring * pring)
+{
+	struct list_head *dlp;
+	struct lpfc_iocbq *cmd_iocb;
+	struct lpfc_iocbq *next_iocb;
+
+	dlp = &pring->txq;
+	cmd_iocb = NULL;
+	next_iocb = (struct lpfc_iocbq *) pring->txq.next;
+	if (next_iocb != (struct lpfc_iocbq *) & pring->txq) {
+		/* If the first ptr is not equal to the list header,
+		 * deque the IOCBQ_t and return it.
+		 */
+		cmd_iocb = next_iocb;
+		list_del(&cmd_iocb->list);
+		pring->txq_cnt--;
+	}
+	return (cmd_iocb);
+}
+
+static IOCB_t *
+lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
+{
+	MAILBOX_t *mbox = (MAILBOX_t *)phba->sli.MBhostaddr;
+	PGP *pgp = (PGP *)&mbox->us.s2.port[pring->ringno];
+	uint32_t  max_cmd_idx =
+		phba->sli.sliinit.ringinit[pring->ringno].numCiocb;
+	IOCB_t *iocb = NULL;
+
+	if((pring->next_cmdidx == pring->cmdidx) &&
+	   (++pring->next_cmdidx >= max_cmd_idx))
+		pring->next_cmdidx = 0;
+
+	if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
+
+		pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
+
+		if (unlikely(pring->local_getidx >= max_cmd_idx)) {
+			lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
+					"%d:0315 Ring %d issue: portCmdGet %d "
+					"is bigger then cmd ring %d\n",
+					phba->brd_no, pring->ringno,
+					pring->local_getidx, max_cmd_idx);
+
+			phba->hba_state = LPFC_HBA_ERROR;
+			/*
+			   All error attention handlers are posted to
+			   discovery tasklet
+			*/
+			lpfc_discq_post_event(phba, (void *)HS_FFER3, NULL,
+					      LPFC_EVT_ERR_ATTN);
+
+			return NULL;
+		}
+
+		if (pring->local_getidx == pring->next_cmdidx)
+			return NULL;
+	}
+
+	iocb = IOCB_ENTRY(pring->cmdringaddr, pring->cmdidx);
+
+	return iocb;
+}
+
+static int
+lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
+		IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
+{
+	struct lpfc_sli *psli = &phba->sli;
+	int ringno = pring->ringno;
+
+	/*
+	 * Alloocate and set up an iotag
+	 */
+	if ((nextiocb->iocb.ulpIoTag =
+	     lpfc_sli_next_iotag(phba, &psli->ring[psli->fcp_ring])) == 0)
+		return (1);
+
+	/*
+	 * Issue iocb command to adapter
+	 */
+	lpfc_sli_pcimem_bcopy((uint32_t *)&nextiocb->iocb,
+			      (uint32_t *)(iocb), sizeof (IOCB_t));
+	wmb();
+	psli->slistat.iocbCmd[ringno]++;
+
+	/*
+	 * If there is no completion routine to call, we can release the
+	 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
+	 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
+	 */
+	if (nextiocb->iocb_cmpl)
+		lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
+	else
+		mempool_free(nextiocb, phba->iocb_mem_pool);
+
+	/*
+	 * Let the HBA know what IOCB slot will be the next one the
+	 * driver will put a command into.
+	 */
+	pring->cmdidx = pring->next_cmdidx;
+	writeb(pring->cmdidx,
+	       (u8 *)phba->MBslimaddr + (SLIMOFF + (ringno * 2)) * 4);
+
+	return (0);
+}
+
+static void
+lpfc_sli_update_full_ring(struct lpfc_hba * phba,
+			  struct lpfc_sli_ring *pring)
+{
+	int ringno = pring->ringno;
+
+	pring->flag |= LPFC_CALL_RING_AVAILABLE;
+
+	wmb();
+
+	/*
+	 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
+	 * The HBA will tell us when an IOCB entry is available.
+	 */
+	writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
+	readl(phba->CAregaddr); /* flush */
+
+	phba->sli.slistat.iocbCmdFull[ringno]++;
+}
+
+static void
+lpfc_sli_update_ring(struct lpfc_hba * phba,
+		     struct lpfc_sli_ring *pring)
+{
+	int ringno = pring->ringno;
+
+	/*
+	 * Tell the HBA that there is work to do in this ring.
+	 */
+	wmb();
+	writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
+	readl(phba->CAregaddr); /* flush */
+}
+
+static void
+lpfc_sli_resume_iocb(struct lpfc_hba * phba, struct lpfc_sli_ring * pring)
+{
+	struct lpfc_sli *psli = &phba->sli;
+	IOCB_t *iocb;
+	struct lpfc_iocbq *nextiocb;
+
+	/*
+	 * Check to see if:
+	 *  (a) there is anything on the txq to send
+	 *  (b) link is up
+	 *  (c) link attention events can be processed (fcp ring only)
+	 *  (d) IOCB processing is not blocked by the outstanding mbox command.
+	 */
+	if (pring->txq_cnt &&
+	    (phba->hba_state > LPFC_LINK_DOWN) &&
+	    (pring->ringno != psli->fcp_ring ||
+	     psli->sliinit.sli_flag & LPFC_PROCESS_LA) &&
+	    !(pring->flag & LPFC_STOP_IOCB_MBX)) {
+
+		while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
+		       (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
+			if (lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb)) {
+				lpfc_sli_ringtx_put(phba, pring, nextiocb);
+				break;
+			}
+
+		if (iocb)
+			lpfc_sli_update_ring(phba, pring);
+		else
+			lpfc_sli_update_full_ring(phba, pring);
+	}
+
+	return;
+}
+
+/* lpfc_sli_turn_on_ring is only called by lpfc_sli_handle_mb_event below */
+static void
+lpfc_sli_turn_on_ring(struct lpfc_hba * phba, int ringno)
+{
+	struct lpfc_sli *psli;
+	struct lpfc_sli_ring *pring;
+	PGP *pgp;
+
+	psli = &phba->sli;
+	pring = &psli->ring[ringno];
+	pgp = (PGP *) & (((MAILBOX_t *)psli->MBhostaddr)->us.s2.port[ringno]);
+
+	/* If the ring is active, flag it */
+	if (psli->ring[ringno].cmdringaddr) {
+		if (psli->ring[ringno].flag & LPFC_STOP_IOCB_MBX) {
+			psli->ring[ringno].flag &= ~LPFC_STOP_IOCB_MBX;
+			/*
+			 * Force update of the local copy of cmdGetInx
+			 */
+			pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
+			lpfc_sli_resume_iocb(phba, pring);
+		}
+	}
+}
+
+static int
+lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
+{
+	uint8_t ret;
+
+	switch (mbxCommand) {
+	case MBX_LOAD_SM:
+	case MBX_READ_NV:
+	case MBX_WRITE_NV:
+	case MBX_RUN_BIU_DIAG:
+	case MBX_INIT_LINK:
+	case MBX_DOWN_LINK:
+	case MBX_CONFIG_LINK:
+	case MBX_CONFIG_RING:
+	case MBX_RESET_RING:
+	case MBX_READ_CONFIG:
+	case MBX_READ_RCONFIG:
+	case MBX_READ_SPARM:
+	case MBX_READ_STATUS:
+	case MBX_READ_RPI:
+	case MBX_READ_XRI:
+	case MBX_READ_REV:
+	case MBX_READ_LNK_STAT:
+	case MBX_REG_LOGIN:
+	case MBX_UNREG_LOGIN:
+	case MBX_READ_LA:
+	case MBX_CLEAR_LA:
+	case MBX_DUMP_MEMORY:
+	case MBX_DUMP_CONTEXT:
+	case MBX_RUN_DIAGS:
+	case MBX_RESTART:
+	case MBX_UPDATE_CFG:
+	case MBX_DOWN_LOAD:
+	case MBX_DEL_LD_ENTRY:
+	case MBX_RUN_PROGRAM:
+	case MBX_SET_MASK:
+	case MBX_SET_SLIM:
+	case MBX_UNREG_D_ID:
+	case MBX_CONFIG_FARP:
+	case MBX_LOAD_AREA:
+	case MBX_RUN_BIU_DIAG64:
+	case MBX_CONFIG_PORT:
+	case MBX_READ_SPARM64:
+	case MBX_READ_RPI64:
+	case MBX_REG_LOGIN64:
+	case MBX_READ_LA64:
+	case MBX_FLASH_WR_ULA:
+	case MBX_SET_DEBUG:
+	case MBX_LOAD_EXP_ROM:
+		ret = mbxCommand;
+		break;
+	default:
+		ret = MBX_SHUTDOWN;
+		break;
+	}
+	return (ret);
+}
+
+void
+lpfc_sli_def_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
+{
+	struct lpfc_dmabuf *mp;
+	mp = (struct lpfc_dmabuf *) (pmb->context1);
+	if (mp) {
+		lpfc_mbuf_free(phba, mp->virt, mp->phys);
+		kfree(mp);
+	}
+	mempool_free( pmb, phba->mbox_mem_pool);
+	return;
+}
+
+static int
+lpfc_sli_handle_mb_event(struct lpfc_hba * phba)
+{
+	MAILBOX_t *mbox;
+	MAILBOX_t *pmbox;
+	LPFC_MBOXQ_t *pmb;
+	struct lpfc_sli *psli;
+	int i;
+	unsigned long iflag;
+	uint32_t process_next;
+
+
+	psli = &phba->sli;
+	/* We should only get here if we are in SLI2 mode */
+	if (!(psli->sliinit.sli_flag & LPFC_SLI2_ACTIVE)) {
+		return (1);
+	}
+
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+
+	psli->slistat.mboxEvent++;
+
+	/* Get a Mailbox buffer to setup mailbox commands for callback */
+	if ((pmb = psli->mbox_active)) {
+		pmbox = &pmb->mb;
+		mbox = (MAILBOX_t *) psli->MBhostaddr;
+
+		/* First check out the status word */
+		lpfc_sli_pcimem_bcopy((uint32_t *) mbox, (uint32_t *) pmbox,
+				     sizeof (uint32_t));
+
+		/* Sanity check to ensure the host owns the mailbox */
+		if (pmbox->mbxOwner != OWN_HOST) {
+			/* Lets try for a while */
+			for (i = 0; i < 10240; i++) {
+				/* First copy command data */
+				lpfc_sli_pcimem_bcopy((uint32_t *) mbox,
+						     (uint32_t *) pmbox,
+						     sizeof (uint32_t));
+				if (pmbox->mbxOwner == OWN_HOST)
+					goto mbout;
+			}
+			/* Stray Mailbox Interrupt, mbxCommand <cmd> mbxStatus
+			   <status> */
+			lpfc_printf_log(phba,
+					KERN_ERR,
+					LOG_MBOX | LOG_SLI,
+					"%d:0304 Stray Mailbox Interrupt "
+					"mbxCommand x%x mbxStatus x%x\n",
+					phba->brd_no,
+					pmbox->mbxCommand,
+					pmbox->mbxStatus);
+
+			psli->sliinit.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
+			spin_unlock_irqrestore(phba->host->host_lock, iflag);
+			return (1);
+		}
+
+	      mbout:
+		del_timer_sync(&psli->mbox_tmo);
+		phba->work_hba_events &= ~WORKER_MBOX_TMO;
+
+		/*
+		 * It is a fatal error if unknown mbox command completion.
+		 */
+		if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
+		    MBX_SHUTDOWN) {
+
+			/* Unknow mailbox command compl */
+			lpfc_printf_log(phba,
+				KERN_ERR,
+				LOG_MBOX | LOG_SLI,
+				"%d:0323 Unknown Mailbox command %x Cmpl\n",
+				phba->brd_no,
+				pmbox->mbxCommand);
+			phba->hba_state = LPFC_HBA_ERROR;
+
+			/*
+			   All error attention handlers are posted to
+			   discovery tasklet
+			*/
+			lpfc_discq_post_event(phba, (void *)HS_FFER3, NULL,
+					      LPFC_EVT_ERR_ATTN);
+			spin_unlock_irqrestore(phba->host->host_lock, iflag);
+			return (0);
+		}
+
+		psli->mbox_active = NULL;
+		if (pmbox->mbxStatus) {
+			psli->slistat.mboxStatErr++;
+			if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
+				/* Mbox cmd cmpl error - RETRYing */
+				lpfc_printf_log(phba,
+					KERN_INFO,
+					LOG_MBOX | LOG_SLI,
+					"%d:0305 Mbox cmd cmpl error - "
+					"RETRYing Data: x%x x%x x%x x%x\n",
+					phba->brd_no,
+					pmbox->mbxCommand,
+					pmbox->mbxStatus,
+					pmbox->un.varWords[0],
+					phba->hba_state);
+				pmbox->mbxStatus = 0;
+				pmbox->mbxOwner = OWN_HOST;
+				psli->sliinit.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
+				if (lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT)
+				    == MBX_SUCCESS) {
+					spin_unlock_irqrestore(
+						       phba->host->host_lock,
+						       iflag);
+					return (0);
+				}
+			}
+		}
+
+		/* Mailbox cmd <cmd> Cmpl <cmpl> */
+		lpfc_printf_log(phba,
+				KERN_INFO,
+				LOG_MBOX | LOG_SLI,
+				"%d:0307 Mailbox cmd x%x Cmpl x%p "
+				"Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
+				phba->brd_no,
+				pmbox->mbxCommand,
+				pmb->mbox_cmpl,
+				*((uint32_t *) pmbox),
+				mbox->un.varWords[0],
+				mbox->un.varWords[1],
+				mbox->un.varWords[2],
+				mbox->un.varWords[3],
+				mbox->un.varWords[4],
+				mbox->un.varWords[5],
+				mbox->un.varWords[6],
+				mbox->un.varWords[7]);
+
+		if (pmb->mbox_cmpl) {
+			/* Copy entire mbox completion over buffer */
+			lpfc_sli_pcimem_bcopy((uint32_t *) mbox,
+						(uint32_t *) pmbox,
+						(sizeof (uint32_t) *
+						(MAILBOX_CMD_WSIZE)));
+			/* All mbox cmpls are posted to discovery tasklet */
+			lpfc_discq_post_event(phba, pmb, NULL,
+						LPFC_EVT_MBOX);
+
+		}
+	}
+
+
+	do {
+		process_next = 0;	/* by default don't loop */
+		psli->sliinit.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
+
+		/* Process next mailbox command if there is one */
+		if ((pmb = lpfc_mbox_get(phba))) {
+			if (lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT) ==
+			    MBX_NOT_FINISHED) {
+				pmb->mb.mbxStatus = MBX_NOT_FINISHED;
+				/* All mbox cmpls are posted to discovery tasklet */
+				lpfc_discq_post_event(phba, pmb, NULL,
+							LPFC_EVT_MBOX);
+				process_next = 1;
+				continue;       /* loop back */
+                        }
+		} else {
+			/* Turn on IOCB processing */
+			for (i = 0; i < psli->sliinit.num_rings; i++) {
+				lpfc_sli_turn_on_ring(phba, i);
+			}
+
+			/* Free any lpfc_dmabuf's waiting for mbox cmd cmpls */
+			while (!list_empty(&phba->freebufList)) {
+				struct lpfc_dmabuf *mp;
+
+				mp = (struct lpfc_dmabuf *)
+					(phba->freebufList.next);
+				if (mp) {
+					lpfc_mbuf_free(phba, mp->virt,
+						       mp->phys);
+					list_del(&mp->list);
+					kfree(mp);
+				}
+			}
+		}
+
+	} while (process_next);
+
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+	return (0);
+}
+static int
+lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
+			    struct lpfc_iocbq *saveq)
+{
+	struct lpfc_sli       * psli;
+	IOCB_t           * irsp;
+	LPFC_RING_INIT_t * pringinit;
+	WORD5            * w5p;
+	uint32_t           Rctl, Type;
+	uint32_t           match, ringno, i;
+	unsigned long	   iflag;
+
+	psli = &phba->sli;
+	match = 0;
+	ringno = pring->ringno;
+	irsp = &(saveq->iocb);
+	if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX)
+	    || (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX)) {
+		Rctl = FC_ELS_REQ;
+		Type = FC_ELS_DATA;
+	} else {
+		w5p =
+		    (WORD5 *) & (saveq->iocb.un.
+				 ulpWord[5]);
+		Rctl = w5p->hcsw.Rctl;
+		Type = w5p->hcsw.Type;
+
+		/* Firmware Workaround */
+		if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
+	    		(irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX)) {
+			Rctl = FC_ELS_REQ;
+			Type = FC_ELS_DATA;
+			w5p->hcsw.Rctl = Rctl;
+			w5p->hcsw.Type = Type;
+		}
+	}
+	/* unSolicited Responses */
+	pringinit = &psli->sliinit.ringinit[ringno];
+	if (pringinit->prt[0].profile) {
+		/* If this ring has a profile set, just
+		   send it to prt[0] */
+		/* All unsol iocbs for LPFC_ELS_RING
+		 * are posted to discovery tasklet.
+		 */
+		if (ringno == LPFC_ELS_RING) {
+			spin_lock_irqsave(phba->host->host_lock, iflag);
+			lpfc_discq_post_event(phba, (void *)&pringinit->prt[0],
+			(void *)saveq,  LPFC_EVT_UNSOL_IOCB);
+			spin_unlock_irqrestore(phba->host->host_lock, iflag);
+		}
+		else {
+			(pringinit->prt[0].
+		 	lpfc_sli_rcv_unsol_event) (phba, pring, saveq);
+		}
+		match = 1;
+	} else {
+		/* We must search, based on rctl / type
+		   for the right routine */
+		for (i = 0; i < pringinit->num_mask;
+		     i++) {
+			if ((pringinit->prt[i].rctl ==
+			     Rctl)
+			    && (pringinit->prt[i].
+				type == Type)) {
+				/* All unsol iocbs for LPFC_ELS_RING
+				 * are posted to discovery tasklet.
+				 */
+				if (ringno == LPFC_ELS_RING) {
+					spin_lock_irqsave(phba->host->host_lock, iflag);
+					lpfc_discq_post_event(phba,
+					(void *)&pringinit->prt[i],
+					(void *)saveq,  LPFC_EVT_UNSOL_IOCB);
+					spin_unlock_irqrestore(phba->host->host_lock, iflag);
+				}
+				else {
+					(pringinit->prt[i].
+				 	lpfc_sli_rcv_unsol_event)
+				    	(phba, pring, saveq);
+				}
+				match = 1;
+				break;
+			}
+		}
+	}
+	if (match == 0) {
+		/* Unexpected Rctl / Type received */
+		/* Ring <ringno> handler: unexpected
+		   Rctl <Rctl> Type <Type> received */
+		lpfc_printf_log(phba,
+				KERN_WARNING,
+				LOG_SLI,
+				"%d:0313 Ring %d handler: unexpected Rctl x%x "
+				"Type x%x received \n",
+				phba->brd_no,
+				ringno,
+				Rctl,
+				Type);
+	}
+	return(1);
+}
+static struct lpfc_iocbq *
+lpfc_search_txcmpl(struct lpfc_sli_ring * pring, struct lpfc_iocbq * prspiocb)
+{
+	IOCB_t *icmd = NULL;
+	IOCB_t *irsp = NULL;
+	struct lpfc_iocbq *cmd_iocb;
+	struct lpfc_iocbq *iocb, *next_iocb;
+	uint16_t iotag;
+
+	irsp = &prspiocb->iocb;
+	iotag = irsp->ulpIoTag;
+	cmd_iocb = NULL;
+
+	/* Search through txcmpl from the begining */
+	list_for_each_entry_safe(iocb, next_iocb, &(pring->txcmplq), list) {
+		icmd = &iocb->iocb;
+		if (iotag == icmd->ulpIoTag) {
+			/* Found a match.  */
+			cmd_iocb = iocb;
+			list_del(&iocb->list);
+			pring->txcmplq_cnt--;
+			break;
+		}
+	}
+
+	return (cmd_iocb);
+}
+static struct lpfc_iocbq *
+lpfc_sli_ringtxcmpl_get(struct lpfc_hba * phba,
+			struct lpfc_sli_ring * pring,
+			struct lpfc_iocbq * prspiocb, uint32_t srch)
+{
+	struct list_head *dlp;
+	IOCB_t *irsp = NULL;
+	struct lpfc_iocbq *cmd_iocb;
+	struct lpfc_sli *psli;
+	uint16_t iotag;
+
+
+	dlp = &pring->txcmplq;
+
+	if (pring->fast_lookup && (srch == 0)) {
+		/*
+		 *  Use fast lookup based on iotag for completion
+		 */
+		psli = &phba->sli;
+		irsp = &prspiocb->iocb;
+		iotag = irsp->ulpIoTag;
+		if (iotag < psli->sliinit.ringinit[pring->ringno].fast_iotag) {
+			cmd_iocb = *(pring->fast_lookup + iotag);
+			*(pring->fast_lookup + iotag) = NULL;
+			if (cmd_iocb) {
+				list_del(&cmd_iocb->list);
+				pring->txcmplq_cnt--;
+				return cmd_iocb;
+			}
+		} else {
+			/*
+			 * Rsp ring <ringno> get: iotag <iotag> greater then
+			 *  configured max <fast_iotag> wd0 <irsp>
+			 */
+			lpfc_printf_log(phba,
+					KERN_ERR,
+					LOG_SLI,
+					"%d:0317 Rsp ring %d get: iotag x%x "
+					"greater then configured max x%x "
+					"wd0 x%x\n",
+					phba->brd_no,
+					pring->ringno, iotag,
+					psli->sliinit.ringinit[pring->ringno]
+					.fast_iotag,
+					*(((uint32_t *) irsp) + 7));
+		}
+	}
+
+	cmd_iocb = lpfc_search_txcmpl(pring, prspiocb);
+
+	return cmd_iocb;
+}
+
+static int
+lpfc_sli_process_sol_iocb(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
+			  struct lpfc_iocbq *saveq)
+{
+	struct lpfc_iocbq * cmdiocbp;
+	int            ringno, rc;
+	unsigned long iflag;
+
+	rc = 1;
+	ringno = pring->ringno;
+	/* Solicited Responses */
+	/* Based on the iotag field, get the cmd IOCB
+	   from the txcmplq */
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+	if ((cmdiocbp =
+	     lpfc_sli_ringtxcmpl_get(phba, pring, saveq,
+				     0))) {
+		/* Call the specified completion
+		   routine */
+		if (cmdiocbp->iocb_cmpl) {
+			/* All iocb cmpls for LPFC_ELS_RING
+			 * are posted to discovery tasklet.
+			 */
+			if (ringno == LPFC_ELS_RING) {
+				lpfc_discq_post_event(phba, (void *)cmdiocbp,
+					(void *)saveq,  LPFC_EVT_SOL_IOCB);
+			}
+			else {
+				if (cmdiocbp->iocb_flag & LPFC_IO_POLL) {
+					rc = 0;
+				}
+
+				if (cmdiocbp->iocb_cmpl == lpfc_scsi_cmd_iocb_cmpl)
+					(cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
+				else {
+					spin_unlock_irqrestore(phba->host->host_lock,
+							       iflag);
+					(cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
+					spin_lock_irqsave(phba->host->host_lock, iflag);
+                                }
+			}
+		} else {
+			mempool_free( cmdiocbp, phba->iocb_mem_pool);
+		}
+	} else {
+		/* Could not find the initiating command
+		 * based of the response iotag.
+		 * This is expected on ELS ring because of lpfc_els_abort().
+		 */
+		if (ringno != LPFC_ELS_RING) {
+			/* Ring <ringno> handler: unexpected
+			   completion IoTag <IoTag> */
+			lpfc_printf_log(phba,
+				KERN_WARNING,
+				LOG_SLI,
+				"%d:0322 Ring %d handler: unexpected "
+				"completion IoTag x%x Data: x%x x%x x%x x%x\n",
+				phba->brd_no,
+				ringno,
+				saveq->iocb.ulpIoTag,
+				saveq->iocb.ulpStatus,
+				saveq->iocb.un.ulpWord[4],
+				saveq->iocb.ulpCommand,
+				saveq->iocb.ulpContext);
+		}
+	}
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+	return(rc);
+}
+static int
+lpfc_sli_handle_ring_event(struct lpfc_hba * phba,
+			   struct lpfc_sli_ring * pring, uint32_t mask)
+{
+	struct lpfc_sli       * psli;
+	IOCB_t           * entry;
+	IOCB_t           * irsp;
+	struct lpfc_iocbq     * rspiocbp, *next_iocb;
+	struct lpfc_iocbq     * cmdiocbp;
+	struct lpfc_iocbq     * saveq;
+	HGP              * hgp;
+	PGP              * pgp;
+	MAILBOX_t        * mbox;
+	uint32_t           status, free_saveq;
+	uint32_t           portRspPut, portRspMax;
+	int                ringno, loopcnt, rc;
+	uint8_t            type;
+	unsigned long	   iflag;
+	void *to_slim;
+
+	psli   = &phba->sli;
+	ringno = pring->ringno;
+	irsp   = NULL;
+	rc     = 1;
+
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+	psli->slistat.iocbEvent[ringno]++;
+
+	/* At this point we assume SLI-2 */
+	mbox = (MAILBOX_t *) psli->MBhostaddr;
+	pgp = (PGP *) & mbox->us.s2.port[ringno];
+	hgp = (HGP *) & mbox->us.s2.host[ringno];
+
+	/* portRspMax is the number of rsp ring entries for this specific
+	   ring. */
+	portRspMax = psli->sliinit.ringinit[ringno].numRiocb;
+
+	rspiocbp = NULL;
+	loopcnt = 0;
+
+	/* Gather iocb entries off response ring.
+	 * rspidx is the IOCB index of the next IOCB that the driver
+	 * is going to process.
+	 */
+	entry = IOCB_ENTRY(pring->rspringaddr, pring->rspidx);
+	portRspPut = le32_to_cpu(pgp->rspPutInx);
+
+	if (portRspPut >= portRspMax) {
+
+		/* Ring <ringno> handler: portRspPut <portRspPut> is bigger then
+		   rsp ring <portRspMax> */
+		lpfc_printf_log(phba,
+				KERN_ERR,
+				LOG_SLI,
+				"%d:0312 Ring %d handler: portRspPut %d "
+				"is bigger then rsp ring %d\n",
+				phba->brd_no,
+				ringno, portRspPut, portRspMax);
+		/*
+		 * Treat it as adapter hardware error.
+		 */
+		phba->hba_state = LPFC_HBA_ERROR;
+		/*
+		   All error attention handlers are posted to
+		   discovery tasklet
+		*/
+		lpfc_discq_post_event(phba, (void *)HS_FFER3, NULL,
+				      LPFC_EVT_ERR_ATTN);
+		spin_unlock_irqrestore(phba->host->host_lock, iflag);
+		return (1);
+	}
+
+	rmb();
+
+	/* Get the next available response iocb.
+	 * rspidx is the IOCB index of the next IOCB that the driver
+	 * is going to process.
+	 */
+	while (pring->rspidx != portRspPut) {
+		/* get an iocb buffer to copy entry into */
+		if ((rspiocbp = mempool_alloc(phba->iocb_mem_pool,
+					      GFP_ATOMIC)) == 0) {
+			break;
+		}
+
+		lpfc_sli_pcimem_bcopy((uint32_t *) entry,
+				      (uint32_t *) & rspiocbp->iocb,
+				      sizeof (IOCB_t));
+		irsp = &rspiocbp->iocb;
+
+		/* bump iocb available response index */
+		if (++pring->rspidx >= portRspMax) {
+			pring->rspidx = 0;
+		}
+
+		/* Let the HBA know what IOCB slot will be the next one the
+		 * driver will read a response from.
+		 */
+		to_slim = (uint8_t *) phba->MBslimaddr +
+			(SLIMOFF + (ringno * 2) + 1) * 4;
+		writeb( pring->rspidx, to_slim);
+
+		/* chain all iocb entries until LE is set */
+		if (list_empty(&(pring->iocb_continueq))) {
+			list_add(&rspiocbp->list, &(pring->iocb_continueq));
+		} else {
+			list_add_tail(&rspiocbp->list,
+				      &(pring->iocb_continueq));
+		}
+		pring->iocb_continueq_cnt++;
+
+		/*
+		 * When the ulpLe field is set, the entire Command has been
+		 * received. Start by getting a pointer to the first iocb entry
+		 * in the chain.
+		 */
+		if (irsp->ulpLe) {
+			/*
+			 * By default, the driver expects to free all resources
+			 * associated with this iocb completion.
+			 */
+			free_saveq = 1;
+			saveq = list_entry(pring->iocb_continueq.next,
+					   struct lpfc_iocbq, list);
+			irsp = &(saveq->iocb);
+			list_del_init(&pring->iocb_continueq);
+			pring->iocb_continueq_cnt = 0;
+
+			psli->slistat.iocbRsp[ringno]++;
+
+			if(irsp->ulpStatus) {
+				/* Rsp ring <ringno> error: IOCB */
+				lpfc_printf_log(phba,
+					KERN_WARNING,
+					LOG_SLI,
+					"%d:0326 Rsp Ring %d error: IOCB Data: "
+					"x%x x%x x%x x%x x%x x%x x%x x%x\n",
+					phba->brd_no,
+					ringno,
+					irsp->un.ulpWord[0],
+					irsp->un.ulpWord[1],
+					irsp->un.ulpWord[2],
+					irsp->un.ulpWord[3],
+					irsp->un.ulpWord[4],
+					irsp->un.ulpWord[5],
+					*(((uint32_t *) irsp) + 6),
+					*(((uint32_t *) irsp) + 7));
+			}
+
+			/* Determine if IOCB command is a solicited or
+			   unsolicited event */
+			type =
+			    lpfc_sli_iocb_cmd_type[(irsp->
+						    ulpCommand &
+						    CMD_IOCB_MASK)];
+			if (type == LPFC_SOL_IOCB) {
+				spin_unlock_irqrestore(phba->host->host_lock,
+						       iflag);
+				rc = lpfc_sli_process_sol_iocb(phba, pring,
+					saveq);
+				spin_lock_irqsave(phba->host->host_lock, iflag);
+				/*
+				 * If this solicted completion is an ELS
+				 * command, don't free the resources now because
+				 * the discoverytasklet does later.
+				 */
+				if (pring->ringno == LPFC_ELS_RING)
+					free_saveq = 0;
+				else
+					free_saveq = 1;
+
+			} else if (type == LPFC_UNSOL_IOCB) {
+				spin_unlock_irqrestore(phba->host->host_lock,
+						       iflag);
+				rc = lpfc_sli_process_unsol_iocb(phba, pring,
+					saveq);
+				spin_lock_irqsave(phba->host->host_lock, iflag);
+
+				/*
+				 * If this unsolicted completion is an ELS
+				 * command, don't free the resources now because
+				 * the discoverytasklet does later.
+				 */
+				if (pring->ringno == LPFC_ELS_RING)
+					free_saveq = 0;
+				else
+					free_saveq = 1;
+
+			} else if (type == LPFC_ABORT_IOCB) {
+				/* Solicited ABORT Responses */
+				/* Based on the iotag field, get the cmd IOCB
+				   from the txcmplq */
+				if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) &&
+				    ((cmdiocbp =
+				      lpfc_sli_ringtxcmpl_get(phba, pring,
+							      saveq, 0)))) {
+					/* Call the specified completion
+					   routine */
+					if (cmdiocbp->iocb_cmpl) {
+						spin_unlock_irqrestore(
+						       phba->host->host_lock,
+						       iflag);
+						(cmdiocbp->iocb_cmpl) (phba,
+							     cmdiocbp, saveq);
+						spin_lock_irqsave(
+							  phba->host->host_lock,
+							  iflag);
+					} else {
+						mempool_free(cmdiocbp,
+						     phba->iocb_mem_pool);
+					}
+				}
+			} else if (type == LPFC_UNKNOWN_IOCB) {
+				if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
+
+					char adaptermsg[LPFC_MAX_ADPTMSG];
+
+					memset(adaptermsg, 0,
+					       LPFC_MAX_ADPTMSG);
+					memcpy(&adaptermsg[0], (uint8_t *) irsp,
+					       MAX_MSG_DATA);
+					dev_warn(&((phba->pcidev)->dev),
+						 "lpfc%d: %s",
+						 phba->brd_no, adaptermsg);
+				} else {
+					/* Unknown IOCB command */
+					lpfc_printf_log(phba,
+						KERN_ERR,
+						LOG_SLI,
+						"%d:0321 Unknown IOCB command "
+						"Data: x%x x%x x%x x%x\n",
+						phba->brd_no,
+						irsp->ulpCommand,
+						irsp->ulpStatus,
+						irsp->ulpIoTag,
+						irsp->ulpContext);
+				}
+			}
+
+			if (free_saveq) {
+				/*
+				 * Free up iocb buffer chain for command just
+				 * processed
+				 */
+				if (!list_empty(&pring->iocb_continueq)) {
+					list_for_each_entry_safe(rspiocbp,
+						 next_iocb,
+						 &pring->iocb_continueq, list) {
+					list_del_init(&rspiocbp->list);
+					mempool_free(rspiocbp,
+						     phba->iocb_mem_pool);
+					}
+				}
+			mempool_free( saveq, phba->iocb_mem_pool);
+			}
+		}
+
+		/* Entire Command has been received */
+		entry = IOCB_ENTRY(pring->rspringaddr, pring->rspidx);
+
+		/* If the port response put pointer has not been updated, sync
+		 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
+		 * response put pointer.
+		 */
+		if (pring->rspidx == portRspPut) {
+			portRspPut = le32_to_cpu(pgp->rspPutInx);
+		}
+	}			/* while (pring->rspidx != portRspPut) */
+
+	if ((rspiocbp != 0) && (mask & HA_R0RE_REQ)) {
+		/* At least one response entry has been freed */
+		psli->slistat.iocbRspFull[ringno]++;
+		/* SET RxRE_RSP in Chip Att register */
+		status = ((CA_R0ATT | CA_R0RE_RSP) << (ringno * 4));
+		writel(status, phba->CAregaddr);
+		readl(phba->CAregaddr); /* flush */
+	}
+	if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
+		pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
+		psli->slistat.iocbCmdEmpty[ringno]++;
+		/*
+		 * Force update of the local copy of cmdGetInx
+		 */
+		pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
+		lpfc_sli_resume_iocb(phba, pring);
+
+		if ((psli->sliinit.ringinit[ringno].lpfc_sli_cmd_available))
+			(psli->sliinit.ringinit[ringno].
+			 lpfc_sli_cmd_available) (phba, pring);
+
+	}
+
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+	return (rc);
+}
+
+static uint32_t
+lpfc_intr_prep(struct lpfc_hba * phba)
+{
+	uint32_t ha_copy;
+
+	/* Ignore all interrupts during initialization. */
+	if (phba->hba_state < LPFC_LINK_DOWN)
+		return (0);
+
+	/* Read host attention register to determine interrupt source */
+	ha_copy = readl(phba->HAregaddr);
+
+	/* Clear Attention Sources, except ERATT (to preserve status) & LATT
+	 *    (ha_copy & ~(HA_ERATT | HA_LATT));
+	 */
+	writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
+	readl(phba->HAregaddr); /* flush */
+	return (ha_copy);
+}				/* lpfc_intr_prep */
+
+int
+lpfc_sli_intr(struct lpfc_hba * phba)
+{
+	struct lpfc_sli *psli;
+	struct lpfc_sli_ring *pring;
+	uint32_t ha_copy;
+	unsigned long status;
+	int i;
+	unsigned long iflag;
+
+	psli = &phba->sli;
+	psli->slistat.sliIntr++;
+
+	/*
+	 * Call the HBA to see if it is interrupting.  If not, don't claim
+	 * the interrupt
+	 */
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+	ha_copy = lpfc_intr_prep(phba);
+	if (!ha_copy) {
+		spin_unlock_irqrestore(phba->host->host_lock, iflag);
+		return (1);
+	}
+
+	if (ha_copy & HA_ERATT) {
+		/*
+		 * There was a link/board error.  Read the status register to
+		 * retrieve the error event and process it.
+		 */
+		psli->slistat.errAttnEvent++;
+		status = readl(phba->HSregaddr);
+		/* Clear Chip error bit */
+		writel(HA_ERATT, phba->HAregaddr);
+		readl(phba->HAregaddr); /* flush */
+	       /*
+	      	  All error attention handlers are posted to
+		  discovery tasklet
+	       */
+
+		lpfc_discq_post_event(phba, (void *)status, NULL,
+				      LPFC_EVT_ERR_ATTN);
+		spin_unlock_irqrestore(phba->host->host_lock, iflag);
+		return (0);
+	}
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+
+	if (ha_copy & HA_MBATT) {
+		/* There was a Mailbox event. */
+		lpfc_sli_handle_mb_event(phba);
+	}
+
+	if (ha_copy & HA_LATT) {
+		/*
+		 * There was a link attention event.  Provided the driver is in
+		 * a state to handle link events, handle this event.
+		 */
+		if (psli->sliinit.sli_flag & LPFC_PROCESS_LA) {
+			lpfc_handle_latt(phba);
+		}
+	}
+
+	/* Process all events on each ring */
+	for (i = 0; i < psli->sliinit.num_rings; i++) {
+		pring = &psli->ring[i];
+		if ((ha_copy & HA_RXATT)
+		    || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
+			if (pring->flag & LPFC_STOP_IOCB_MASK) {
+				pring->flag |= LPFC_DEFERRED_RING_EVENT;
+			} else {
+				lpfc_sli_handle_ring_event(phba, pring,
+							   (ha_copy &
+							    HA_RXMASK));
+				pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
+			}
+		}
+		ha_copy = (ha_copy >> 4);
+	}
+
+	return (0);
+}
+
+static int
+lpfc_sli_abort_iocb_ring(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
+			 uint32_t flag)
+{
+	struct lpfc_sli *psli;
+	struct lpfc_iocbq *iocb, *next_iocb;
+	struct lpfc_iocbq *abtsiocbp;
+	IOCB_t *icmd = NULL, *cmd = NULL;
+	int errcnt;
+	uint16_t iotag;
+
+	psli = &phba->sli;
+	errcnt = 0;
+
+	/* Error everything on txq and txcmplq
+	 * First do the txq.
+	 */
+	list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
+		list_del_init(&iocb->list);
+		if (iocb->iocb_cmpl) {
+			icmd = &iocb->iocb;
+			icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
+			icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
+			(iocb->iocb_cmpl) (phba, iocb, iocb);
+		} else {
+			mempool_free( iocb, phba->iocb_mem_pool);
+		}
+	}
+
+	pring->txq_cnt = 0;
+	INIT_LIST_HEAD(&(pring->txq));
+
+	/* Next issue ABTS for everything on the txcmplq */
+	list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
+		cmd = &iocb->iocb;
+
+		if (flag == LPFC_SLI_ABORT_IMED) {
+			/*
+			 * Imediate abort of IOCB, clear fast_lookup entry,
+			 * if any, deque and call compl
+			 */
+			iotag = cmd->ulpIoTag;
+			if (pring->fast_lookup &&
+			    iotag &&
+			    (iotag <
+			     psli->sliinit.ringinit[pring->ringno].fast_iotag))
+				*(pring->fast_lookup + iotag) = NULL;
+
+			list_del_init(&iocb->list);
+			pring->txcmplq_cnt--;
+
+			if (iocb->iocb_cmpl) {
+				cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
+				cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
+				(iocb->iocb_cmpl) (phba, iocb, iocb);
+			} else {
+				mempool_free( iocb, phba->iocb_mem_pool);
+			}
+			continue;
+		}
+
+		/* issue ABTS for this IOCB based on iotag */
+
+		if ((abtsiocbp = mempool_alloc(phba->iocb_mem_pool,
+					       GFP_ATOMIC)) == 0) {
+			errcnt++;
+			continue;
+		}
+		memset(abtsiocbp, 0, sizeof (struct lpfc_iocbq));
+		icmd = &abtsiocbp->iocb;
+
+		icmd->un.acxri.abortType = ABORT_TYPE_ABTS;
+		icmd->un.acxri.abortContextTag = cmd->ulpContext;
+		icmd->un.acxri.abortIoTag = cmd->ulpIoTag;
+
+		icmd->ulpLe = 1;
+		icmd->ulpClass = cmd->ulpClass;
+		if (phba->hba_state >= LPFC_LINK_UP) {
+			icmd->ulpCommand = CMD_ABORT_XRI_CN;
+		} else {
+			icmd->ulpCommand = CMD_CLOSE_XRI_CN;
+
+		}
+
+		if (lpfc_sli_issue_iocb
+		    (phba, pring, abtsiocbp, 0) == IOCB_ERROR) {
+			mempool_free(abtsiocbp, phba->iocb_mem_pool);
+			errcnt++;
+			continue;
+		}
+		/* The rsp ring completion will remove IOCB from txcmplq when
+		 * abort is read by HBA.
+		 */
+	}
+
+	if (flag == LPFC_SLI_ABORT_IMED) {
+		INIT_LIST_HEAD(&(pring->txcmplq));
+		pring->txcmplq_cnt = 0;
+	}
+
+	return (errcnt);
+}
+
+int
+lpfc_sli_brdreset(struct lpfc_hba * phba)
+{
+	MAILBOX_t *swpmb;
+	struct lpfc_sli *psli;
+	struct lpfc_sli_ring *pring;
+	uint16_t cfg_value, skip_post;
+	volatile uint32_t word0;
+	int i;
+	void *to_slim;
+	struct lpfc_dmabuf *mp, *next_mp;
+
+	psli = &phba->sli;
+
+	/* A board reset must use REAL SLIM. */
+	psli->sliinit.sli_flag &= ~LPFC_SLI2_ACTIVE;
+
+	word0 = 0;
+	swpmb = (MAILBOX_t *) & word0;
+	swpmb->mbxCommand = MBX_RESTART;
+	swpmb->mbxHc = 1;
+
+	to_slim = phba->MBslimaddr;
+	writel(*(uint32_t *) swpmb, to_slim);
+	readl(to_slim); /* flush */
+
+	/* Only skip post after fc_ffinit is completed */
+	if (phba->hba_state) {
+		skip_post = 1;
+		word0 = 1;	/* This is really setting up word1 */
+	} else {
+		skip_post = 0;
+		word0 = 0;	/* This is really setting up word1 */
+	}
+	to_slim = (uint8_t *) phba->MBslimaddr + sizeof (uint32_t);
+	writel(*(uint32_t *) swpmb, to_slim);
+	readl(to_slim); /* flush */
+
+	/* Reset HBA */
+	lpfc_printf_log(phba,
+		KERN_INFO,
+		LOG_SLI,
+		"%d:0325 Reset HBA Data: x%x x%x\n",
+		phba->brd_no,
+		phba->hba_state,
+		psli->sliinit.sli_flag);
+
+	/* Turn off SERR, PERR in PCI cmd register */
+	phba->hba_state = LPFC_INIT_START;
+
+	/* perform board reset */
+	phba->fc_eventTag = 0;
+	phba->fc_myDID = 0;
+	phba->fc_prevDID = 0;
+
+	/* Turn off parity checking and serr during the physical reset */
+	pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
+	pci_write_config_word(phba->pcidev, PCI_COMMAND,
+			      (cfg_value &
+			       ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
+
+	/* Now toggle INITFF bit in the Host Control Register */
+	writel(HC_INITFF, phba->HCregaddr);
+	mdelay(1);
+	readl(phba->HCregaddr); /* flush */
+	writel(0, phba->HCregaddr);
+	readl(phba->HCregaddr); /* flush */
+
+	/* Restore PCI cmd register */
+
+	pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
+	phba->hba_state = LPFC_INIT_START;
+
+	/* Initialize relevant SLI info */
+	for (i = 0; i < psli->sliinit.num_rings; i++) {
+		pring = &psli->ring[i];
+		pring->flag = 0;
+		pring->rspidx = 0;
+		pring->next_cmdidx  = 0;
+		pring->local_getidx = 0;
+		pring->cmdidx = 0;
+		pring->missbufcnt = 0;
+	}
+
+	if (skip_post) {
+		mdelay(100);
+	} else {
+		mdelay(2000);
+	}
+
+	/* Cleanup preposted buffers on the ELS ring */
+	pring = &psli->ring[LPFC_ELS_RING];
+	list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
+		list_del(&mp->list);
+		pring->postbufq_cnt--;
+		lpfc_mbuf_free(phba, mp->virt, mp->phys);
+		kfree(mp);
+	}
+
+	for (i = 0; i < psli->sliinit.num_rings; i++) {
+		pring = &psli->ring[i];
+		lpfc_sli_abort_iocb_ring(phba, pring, LPFC_SLI_ABORT_IMED);
+	}
+
+	return (0);
+}
+
+static void
+lpfc_setup_slim_access(struct lpfc_hba *phba)
+{
+	phba->MBslimaddr = phba->slim_memmap_p;
+	phba->HAregaddr = (uint32_t *) (phba->ctrl_regs_memmap_p) +
+		HA_REG_OFFSET;
+	phba->HCregaddr = (uint32_t *) (phba->ctrl_regs_memmap_p) +
+		HC_REG_OFFSET;
+	phba->CAregaddr = (uint32_t *) (phba->ctrl_regs_memmap_p) +
+		CA_REG_OFFSET;
+	phba->HSregaddr = (uint32_t *) (phba->ctrl_regs_memmap_p) +
+		HS_REG_OFFSET;
+	return;
+}
+
+int
+lpfc_sli_hba_setup(struct lpfc_hba * phba)
+{
+	struct lpfc_sli *psli;
+	LPFC_MBOXQ_t *pmb;
+	int read_rev_reset, i, rc;
+	uint32_t status;
+
+	psli = &phba->sli;
+
+	/* Setep SLI interface for HBA register and HBA SLIM access */
+	lpfc_setup_slim_access(phba);
+
+	/* Set board state to initialization started */
+	phba->hba_state = LPFC_INIT_START;
+	read_rev_reset = 0;
+
+	/* On some platforms/OS's, the driver can't rely on the state the
+	 * adapter may be in.  For this reason, the driver is allowed to reset
+	 * the HBA before initialization.
+	 */
+	if (lpfc_sli_reset_on_init) {
+		phba->hba_state = 0;	/* Don't skip post */
+		lpfc_sli_brdreset(phba);
+		phba->hba_state = LPFC_INIT_START;
+
+		/* Sleep for 2.5 sec */
+		msleep(2500);
+	}
+
+top:
+	/* Read the HBA Host Status Register */
+	status = readl(phba->HSregaddr);
+
+	/* Check status register to see what current state is */
+	i = 0;
+	while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
+
+		/* Check every 100ms for 5 retries, then every 500ms for 5, then
+		 * every 2.5 sec for 5, then reset board and every 2.5 sec for
+		 * 4.
+		 */
+		if (i++ >= 20) {
+			/* Adapter failed to init, timeout, status reg
+			   <status> */
+			lpfc_printf_log(phba,
+					KERN_ERR,
+					LOG_INIT,
+					"%d:0436 Adapter failed to init, "
+					"timeout, status reg x%x\n",
+					phba->brd_no,
+					status);
+			phba->hba_state = LPFC_HBA_ERROR;
+			return -ETIMEDOUT;
+		}
+
+		/* Check to see if any errors occurred during init */
+		if (status & HS_FFERM) {
+			/* ERROR: During chipset initialization */
+			/* Adapter failed to init, chipset, status reg
+			   <status> */
+			lpfc_printf_log(phba,
+					KERN_ERR,
+					LOG_INIT,
+					"%d:0437 Adapter failed to init, "
+					"chipset, status reg x%x\n",
+					phba->brd_no,
+					status);
+			phba->hba_state = LPFC_HBA_ERROR;
+			return -EIO;
+		}
+
+		if (i <= 5) {
+			msleep(10);
+		} else if (i <= 10) {
+			msleep(500);
+		} else {
+			msleep(2500);
+		}
+
+		if (i == 15) {
+			phba->hba_state = 0;	/* Don't skip post */
+			lpfc_sli_brdreset(phba);
+			phba->hba_state = LPFC_INIT_START;
+		}
+		/* Read the HBA Host Status Register */
+		status = readl(phba->HSregaddr);
+	}
+
+	/* Check to see if any errors occurred during init */
+	if (status & HS_FFERM) {
+		/* ERROR: During chipset initialization */
+		/* Adapter failed to init, chipset, status reg <status> */
+		lpfc_printf_log(phba,
+				KERN_ERR,
+				LOG_INIT,
+				"%d:0438 Adapter failed to init, chipset, "
+				"status reg x%x\n",
+				phba->brd_no,
+				status);
+		phba->hba_state = LPFC_HBA_ERROR;
+		return -EIO;
+	}
+
+	/* Clear all interrupt enable conditions */
+	writel(0, phba->HCregaddr);
+	readl(phba->HCregaddr); /* flush */
+
+	/* setup host attn register */
+	writel(0xffffffff, phba->HAregaddr);
+	readl(phba->HAregaddr); /* flush */
+
+	/* Get a Mailbox buffer to setup mailbox commands for HBA
+	   initialization */
+	if ((pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
+						  GFP_ATOMIC)) == 0) {
+		phba->hba_state = LPFC_HBA_ERROR;
+		return -ENOMEM;
+	}
+
+	/* Call pre CONFIG_PORT mailbox command initialization.  A value of 0
+	 * means the call was successful.  Any other nonzero value is a failure,
+	 * but if ERESTART is returned, the driver may reset the HBA and try
+	 * again.
+	 */
+	if ((rc = lpfc_config_port_prep(phba))) {
+		if ((rc == -ERESTART) && (read_rev_reset == 0)) {
+			mempool_free( pmb, phba->mbox_mem_pool);
+			phba->hba_state = 0;	/* Don't skip post */
+			lpfc_sli_brdreset(phba);
+			phba->hba_state = LPFC_INIT_START;
+			msleep(500);
+			read_rev_reset = 1;
+			goto top;
+		}
+		phba->hba_state = LPFC_HBA_ERROR;
+		mempool_free( pmb, phba->mbox_mem_pool);
+		return -ENXIO;
+	}
+
+	/* Setup and issue mailbox CONFIG_PORT command */
+	phba->hba_state = LPFC_INIT_MBX_CMDS;
+	lpfc_config_port(phba, pmb);
+	if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
+		/* Adapter failed to init, mbxCmd <cmd> CONFIG_PORT,
+		   mbxStatus <status> */
+		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
+				"%d:0442 Adapter failed to init, mbxCmd x%x "
+				"CONFIG_PORT, mbxStatus x%x Data: x%x\n",
+				phba->brd_no, pmb->mb.mbxCommand,
+				pmb->mb.mbxStatus, 0);
+
+		/* This clause gives the config_port call is given multiple
+		   chances to succeed. */
+		if (read_rev_reset == 0) {
+			mempool_free( pmb, phba->mbox_mem_pool);
+			phba->hba_state = 0;	/* Don't skip post */
+			lpfc_sli_brdreset(phba);
+			phba->hba_state = LPFC_INIT_START;
+			msleep(2500);
+			read_rev_reset = 1;
+			goto top;
+		}
+
+		psli->sliinit.sli_flag &= ~LPFC_SLI2_ACTIVE;
+		phba->hba_state = LPFC_HBA_ERROR;
+		mempool_free( pmb, phba->mbox_mem_pool);
+		return -ENXIO;
+	}
+
+	if ((rc = lpfc_sli_ring_map(phba))) {
+		phba->hba_state = LPFC_HBA_ERROR;
+		mempool_free( pmb, phba->mbox_mem_pool);
+		return -ENXIO;
+	}
+	psli->sliinit.sli_flag |= LPFC_PROCESS_LA;
+
+	/* Call post CONFIG_PORT mailbox command initialization. */
+	if ((rc = lpfc_config_port_post(phba))) {
+		phba->hba_state = LPFC_HBA_ERROR;
+		mempool_free( pmb, phba->mbox_mem_pool);
+		return -ENXIO;
+	}
+	mempool_free( pmb, phba->mbox_mem_pool);
+	return 0;
+}
+
+
+static void
+lpfc_mbox_abort(struct lpfc_hba * phba)
+{
+	struct lpfc_sli *psli;
+	LPFC_MBOXQ_t *pmbox;
+	MAILBOX_t *mb;
+
+	psli = &phba->sli;
+
+	if (psli->mbox_active) {
+		del_timer_sync(&psli->mbox_tmo);
+		phba->work_hba_events &= ~WORKER_MBOX_TMO;
+		pmbox = psli->mbox_active;
+		mb = &pmbox->mb;
+		psli->mbox_active = NULL;
+		if (pmbox->mbox_cmpl) {
+			mb->mbxStatus = MBX_NOT_FINISHED;
+			(pmbox->mbox_cmpl) (phba, pmbox);
+		}
+		psli->sliinit.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
+	}
+
+	/* Abort all the non active mailbox commands. */
+	pmbox = lpfc_mbox_get(phba);
+	while (pmbox) {
+		mb = &pmbox->mb;
+		if (pmbox->mbox_cmpl) {
+			mb->mbxStatus = MBX_NOT_FINISHED;
+			(pmbox->mbox_cmpl) (phba, pmbox);
+		}
+		pmbox = lpfc_mbox_get(phba);
+	}
+	return;
+}
+/*! lpfc_mbox_timeout
+ *
+ * \pre
+ * \post
+ * \param hba Pointer to per struct lpfc_hba structure
+ * \param l1  Pointer to the driver's mailbox queue.
+ * \return
+ *   void
+ *
+ * \b Description:
+ *
+ * This routine handles mailbox timeout events at timer interrupt context.
+ */
+void
+lpfc_mbox_timeout(unsigned long ptr)
+{
+	struct lpfc_hba *phba;
+	unsigned long iflag;
+
+	phba = (struct lpfc_hba *)ptr;
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+	if (!(phba->work_hba_events & WORKER_MBOX_TMO)) {
+		phba->work_hba_events |= WORKER_MBOX_TMO;
+		if (phba->dpc_wait)
+			up(phba->dpc_wait);
+	}
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+}
+
+void
+lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
+{
+	struct lpfc_sli *psli;
+	LPFC_MBOXQ_t *pmbox;
+	MAILBOX_t *mb;
+
+	psli = &phba->sli;
+	spin_lock_irq(phba->host->host_lock);
+	if (!(phba->work_hba_events & WORKER_MBOX_TMO)) {
+		spin_unlock_irq(phba->host->host_lock);
+		return;
+	}
+	
+	phba->work_hba_events &= ~WORKER_MBOX_TMO;
+
+	pmbox = psli->mbox_active;
+	mb = &pmbox->mb;
+
+	/* Mbox cmd <mbxCommand> timeout */
+	lpfc_printf_log(phba,
+		KERN_ERR,
+		LOG_MBOX | LOG_SLI,
+		"%d:0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
+		phba->brd_no,
+		mb->mbxCommand,
+		phba->hba_state,
+		psli->sliinit.sli_flag,
+		psli->mbox_active);
+
+	if (psli->mbox_active == pmbox) {
+		psli->mbox_active = NULL;
+		if (pmbox->mbox_cmpl) {
+			mb->mbxStatus = MBX_NOT_FINISHED;
+			(pmbox->mbox_cmpl) (phba, pmbox);
+		}
+		psli->sliinit.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
+	}
+
+	lpfc_mbox_abort(phba);
+	spin_unlock_irq(phba->host->host_lock);
+	return;
+}
+
+
+int
+lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
+{
+	MAILBOX_t *mbox;
+	MAILBOX_t *mb;
+	struct lpfc_sli *psli;
+	uint32_t status, evtctr;
+	uint32_t ha_copy;
+	int i;
+	unsigned long drvr_flag = 0;
+	volatile uint32_t word0, ldata;
+	void *to_slim;
+
+	psli = &phba->sli;
+	if (flag & MBX_POLL) {
+		spin_lock_irqsave(phba->host->host_lock, drvr_flag);
+	}
+
+	mb = &pmbox->mb;
+	status = MBX_SUCCESS;
+
+	if (psli->sliinit.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
+		/* Polling for a mbox command when another one is already active
+		 * is not allowed in SLI. Also, the driver must have established
+		 * SLI2 mode to queue and process multiple mbox commands.
+		 */
+
+		if (flag & MBX_POLL) {
+			spin_unlock_irqrestore(phba->host->host_lock,
+					       drvr_flag);
+
+			/* Mbox command <mbxCommand> cannot issue */
+			LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
+			return (MBX_NOT_FINISHED);
+		}
+
+		if (!(psli->sliinit.sli_flag & LPFC_SLI2_ACTIVE)) {
+
+			/* Mbox command <mbxCommand> cannot issue */
+			LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
+			return (MBX_NOT_FINISHED);
+		}
+
+		/* Handle STOP IOCB processing flag. This is only meaningful
+		 * if we are not polling for mbox completion.
+		 */
+		if (flag & MBX_STOP_IOCB) {
+			flag &= ~MBX_STOP_IOCB;
+			/* Now flag each ring */
+			for (i = 0; i < psli->sliinit.num_rings; i++) {
+				/* If the ring is active, flag it */
+				if (psli->ring[i].cmdringaddr) {
+					psli->ring[i].flag |=
+					    LPFC_STOP_IOCB_MBX;
+				}
+			}
+		}
+
+		/* Another mailbox command is still being processed, queue this
+		 * command to be processed later.
+		 */
+		lpfc_mbox_put(phba, pmbox);
+
+		/* Mbox cmd issue - BUSY */
+		lpfc_printf_log(phba,
+			KERN_INFO,
+			LOG_MBOX | LOG_SLI,
+			"%d:0308 Mbox cmd issue - BUSY Data: x%x x%x x%x x%x\n",
+			phba->brd_no,
+			mb->mbxCommand,
+			phba->hba_state,
+			psli->sliinit.sli_flag,
+			flag);
+
+		psli->slistat.mboxBusy++;
+		if (flag == MBX_POLL) {
+			spin_unlock_irqrestore(phba->host->host_lock,
+					       drvr_flag);
+		}
+		return (MBX_BUSY);
+	}
+
+	/* Handle STOP IOCB processing flag. This is only meaningful
+	 * if we are not polling for mbox completion.
+	 */
+	if (flag & MBX_STOP_IOCB) {
+		flag &= ~MBX_STOP_IOCB;
+		if (flag == MBX_NOWAIT) {
+			/* Now flag each ring */
+			for (i = 0; i < psli->sliinit.num_rings; i++) {
+				/* If the ring is active, flag it */
+				if (psli->ring[i].cmdringaddr) {
+					psli->ring[i].flag |=
+					    LPFC_STOP_IOCB_MBX;
+				}
+			}
+		}
+	}
+
+	psli->sliinit.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
+
+	/* If we are not polling, we MUST be in SLI2 mode */
+	if (flag != MBX_POLL) {
+		if (!(psli->sliinit.sli_flag & LPFC_SLI2_ACTIVE)) {
+			psli->sliinit.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
+
+			/* Mbox command <mbxCommand> cannot issue */
+			LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag);
+			return (MBX_NOT_FINISHED);
+		}
+		/* timeout active mbox command */
+		mod_timer(&psli->mbox_tmo, jiffies + HZ * LPFC_MBOX_TMO);
+	}
+
+	/* Mailbox cmd <cmd> issue */
+	lpfc_printf_log(phba,
+		KERN_INFO,
+		LOG_MBOX | LOG_SLI,
+		"%d:0309 Mailbox cmd x%x issue Data: x%x x%x x%x\n",
+		phba->brd_no,
+		mb->mbxCommand,
+		phba->hba_state,
+		psli->sliinit.sli_flag,
+		flag);
+
+	psli->slistat.mboxCmd++;
+	evtctr = psli->slistat.mboxEvent;
+
+	/* next set own bit for the adapter and copy over command word */
+	mb->mbxOwner = OWN_CHIP;
+
+	if (psli->sliinit.sli_flag & LPFC_SLI2_ACTIVE) {
+
+		/* First copy command data to host SLIM area */
+		mbox = (MAILBOX_t *) psli->MBhostaddr;
+		lpfc_sli_pcimem_bcopy((uint32_t *) mb, (uint32_t *) mbox,
+				      (sizeof (uint32_t) *
+				       (MAILBOX_CMD_WSIZE)));
+
+	} else {
+		if (mb->mbxCommand == MBX_CONFIG_PORT) {
+			/* copy command data into host mbox for cmpl */
+			mbox = (MAILBOX_t *) psli->MBhostaddr;
+			lpfc_sli_pcimem_bcopy((uint32_t *) mb,
+					      (uint32_t *) mbox,
+					      (sizeof (uint32_t) *
+					       (MAILBOX_CMD_WSIZE)));
+		}
+
+		/* First copy mbox command data to HBA SLIM, skip past first
+		   word */
+		to_slim = (uint8_t *) phba->MBslimaddr + sizeof (uint32_t);
+		lpfc_memcpy_to_slim(to_slim, (void *)&mb->un.varWords[0],
+			    (MAILBOX_CMD_WSIZE - 1) * sizeof (uint32_t));
+
+		/* Next copy over first word, with mbxOwner set */
+		ldata = *((volatile uint32_t *)mb);
+		to_slim = phba->MBslimaddr;
+		writel(ldata, to_slim);
+		readl(to_slim); /* flush */
+
+		if (mb->mbxCommand == MBX_CONFIG_PORT) {
+			/* switch over to host mailbox */
+			psli->sliinit.sli_flag |= LPFC_SLI2_ACTIVE;
+		}
+	}
+
+	wmb();
+	/* interrupt board to doit right away */
+	writel(CA_MBATT, phba->CAregaddr);
+	readl(phba->CAregaddr); /* flush */
+
+	switch (flag) {
+	case MBX_NOWAIT:
+		/* Don't wait for it to finish, just return */
+		psli->mbox_active = pmbox;
+		break;
+
+	case MBX_POLL:
+		i = 0;
+		psli->mbox_active = NULL;
+		if (psli->sliinit.sli_flag & LPFC_SLI2_ACTIVE) {
+			/* First read mbox status word */
+			mbox = (MAILBOX_t *) psli->MBhostaddr;
+			word0 = *((volatile uint32_t *)mbox);
+			word0 = le32_to_cpu(word0);
+		} else {
+			/* First read mbox status word */
+			word0 = readl(phba->MBslimaddr);
+		}
+
+		/* Read the HBA Host Attention Register */
+		ha_copy = readl(phba->HAregaddr);
+
+		/* Wait for command to complete */
+		while (((word0 & OWN_CHIP) == OWN_CHIP)
+		       || !(ha_copy & HA_MBATT)) {
+			if (i++ >= 5000) {
+				psli->sliinit.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
+				spin_unlock_irqrestore(phba->host->host_lock,
+						       drvr_flag);
+				return (MBX_NOT_FINISHED);
+			}
+
+			/* Check if we took a mbox interrupt while we were
+			   polling */
+			if (((word0 & OWN_CHIP) != OWN_CHIP)
+			    && (evtctr != psli->slistat.mboxEvent))
+				break;
+
+			/* Can be in interrupt context, do not sleep */
+			/* (or might be called with interrupts disabled) */
+			udelay(1000);
+
+
+			if (psli->sliinit.sli_flag & LPFC_SLI2_ACTIVE) {
+				/* First copy command data */
+				mbox = (MAILBOX_t *) psli->MBhostaddr;
+				word0 = *((volatile uint32_t *)mbox);
+				word0 = le32_to_cpu(word0);
+				if (mb->mbxCommand == MBX_CONFIG_PORT) {
+					MAILBOX_t *slimmb;
+					volatile uint32_t slimword0;
+					/* Check real SLIM for any errors */
+					slimword0 = readl(phba->MBslimaddr);
+					slimmb = (MAILBOX_t *) & slimword0;
+					if (((slimword0 & OWN_CHIP) != OWN_CHIP)
+					    && slimmb->mbxStatus) {
+						psli->sliinit.sli_flag &=
+						    ~LPFC_SLI2_ACTIVE;
+						word0 = slimword0;
+					}
+				}
+			} else {
+				/* First copy command data */
+				word0 = readl(phba->MBslimaddr);
+			}
+			/* Read the HBA Host Attention Register */
+			ha_copy = readl(phba->HAregaddr);
+		}
+
+		if (psli->sliinit.sli_flag & LPFC_SLI2_ACTIVE) {
+			/* First copy command data */
+			mbox = (MAILBOX_t *) psli->MBhostaddr;
+			/* copy results back to user */
+			lpfc_sli_pcimem_bcopy((uint32_t *) mbox,
+					      (uint32_t *) mb,
+					      (sizeof (uint32_t) *
+					       MAILBOX_CMD_WSIZE));
+		} else {
+			/* First copy command data */
+			lpfc_memcpy_from_slim((void *)mb,
+				      phba->MBslimaddr,
+				      sizeof (uint32_t) * (MAILBOX_CMD_WSIZE));
+         		if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
+				pmbox->context2) {
+				lpfc_memcpy_from_slim((void *)pmbox->context2,
+				      phba->MBslimaddr + DMP_RSP_OFFSET,
+               			      mb->un.varDmp.word_cnt);
+			}
+		}
+
+		writel(HA_MBATT, phba->HAregaddr);
+		readl(phba->HAregaddr); /* flush */
+
+		psli->sliinit.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
+		status = mb->mbxStatus;
+	}
+
+	if (flag == MBX_POLL) {
+		spin_unlock_irqrestore(phba->host->host_lock, drvr_flag);
+	}
+	return (status);
+}
+
+static struct lpfc_iocbq *
+lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
+		   struct lpfc_iocbq ** piocb)
+{
+	struct lpfc_iocbq * nextiocb;
+
+	nextiocb = lpfc_sli_ringtx_get(phba, pring);
+	if (!nextiocb) {
+		nextiocb = *piocb;
+		*piocb = NULL;
+	}
+
+	return nextiocb;
+}
+
+int
+lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
+		    struct lpfc_iocbq *piocb, uint32_t flag)
+{
+	struct lpfc_sli *psli = &phba->sli;
+	int ringno = pring->ringno;
+	struct lpfc_iocbq *nextiocb;
+	IOCB_t *iocb;
+
+	/*
+	 * We should never get an IOCB if we are in a < LINK_DOWN state
+	 */
+	if (unlikely(phba->hba_state < LPFC_LINK_DOWN))
+		return IOCB_ERROR;
+
+	/*
+	 * Check to see if we are blocking IOCB processing because of a
+	 * outstanding mbox command.
+	 */
+	if (unlikely(pring->flag & LPFC_STOP_IOCB_MBX))
+		goto iocb_busy;
+
+	if (unlikely(phba->hba_state == LPFC_LINK_DOWN)) {
+		/*
+		 * Only CREATE_XRI, CLOSE_XRI, ABORT_XRI, and QUE_RING_BUF
+		 * can be issued if the link is not up.
+		 */
+		switch (piocb->iocb.ulpCommand) {
+		case CMD_QUE_RING_BUF_CN:
+		case CMD_QUE_RING_BUF64_CN:
+			/*
+			 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
+			 * completion, iocb_cmpl MUST be 0.
+			 */
+			if (piocb->iocb_cmpl)
+				piocb->iocb_cmpl = NULL;
+			/*FALLTHROUGH*/
+		case CMD_CREATE_XRI_CR:
+			break;
+		default:
+			goto iocb_busy;
+		}
+
+	/*
+	 * For FCP commands, we must be in a state where we can process link
+	 * attention events.
+	 */
+	} else if (unlikely(pring->ringno == psli->fcp_ring &&
+		   !(psli->sliinit.sli_flag & LPFC_PROCESS_LA)))
+		goto iocb_busy;
+
+	/*
+	 * Check to see if this is a high priority command.
+	 * If so bypass tx queue processing.
+	 */
+	if (unlikely((flag & SLI_IOCB_HIGH_PRIORITY) &&
+		     (iocb = lpfc_sli_next_iocb_slot(phba, pring)))) {
+		if (lpfc_sli_submit_iocb(phba, pring, iocb, piocb))
+			goto iocb_busy;
+		piocb = NULL;
+	}
+
+	while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
+	       (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
+		if (lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb))
+			break;
+
+	if (iocb)
+		lpfc_sli_update_ring(phba, pring);
+	else
+		lpfc_sli_update_full_ring(phba, pring);
+
+	if (!piocb)
+		return IOCB_SUCCESS;
+
+	goto out_busy;
+
+ iocb_busy:
+	psli->slistat.iocbCmdDelay[ringno]++;
+
+ out_busy:
+
+	if (!(flag & SLI_IOCB_RET_IOCB)) {
+		lpfc_sli_ringtx_put(phba, pring, piocb);
+		return IOCB_SUCCESS;
+	}
+
+	return IOCB_BUSY;
+}
+
+int
+lpfc_sli_queue_setup(struct lpfc_hba * phba)
+{
+	struct lpfc_sli *psli;
+	struct lpfc_sli_ring *pring;
+	int i, cnt;
+
+	psli = &phba->sli;
+	INIT_LIST_HEAD(&psli->mboxq);
+	/* Initialize list headers for txq and txcmplq as double linked lists */
+	for (i = 0; i < psli->sliinit.num_rings; i++) {
+		pring = &psli->ring[i];
+		pring->ringno = i;
+		pring->next_cmdidx  = 0;
+		pring->local_getidx = 0;
+		pring->cmdidx = 0;
+		INIT_LIST_HEAD(&pring->txq);
+		INIT_LIST_HEAD(&pring->txcmplq);
+		INIT_LIST_HEAD(&pring->iocb_continueq);
+		INIT_LIST_HEAD(&pring->postbufq);
+		cnt = psli->sliinit.ringinit[i].fast_iotag;
+		if (cnt) {
+			pring->fast_lookup =
+				kmalloc(cnt * sizeof (struct lpfc_iocbq *),
+					GFP_KERNEL);
+			if (pring->fast_lookup == 0) {
+				return (0);
+			}
+			memset((char *)pring->fast_lookup, 0,
+			       cnt * sizeof (struct lpfc_iocbq *));
+		}
+	}
+	return (1);
+}
+
+int
+lpfc_sli_hba_down(struct lpfc_hba * phba)
+{
+	struct lpfc_sli *psli;
+	struct lpfc_sli_ring *pring;
+	LPFC_MBOXQ_t *pmb;
+	struct lpfc_iocbq *iocb, *next_iocb;
+	IOCB_t *icmd = NULL;
+	int i;
+
+	psli = &phba->sli;
+	lpfc_hba_down_prep(phba);
+
+	for (i = 0; i < psli->sliinit.num_rings; i++) {
+		pring = &psli->ring[i];
+		pring->flag |= LPFC_DEFERRED_RING_EVENT;
+
+		/*
+		 * Error everything on the txq since these iocbs have not been
+		 * given to the FW yet.
+		 */
+		pring->txq_cnt = 0;
+
+		list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
+			list_del_init(&iocb->list);
+			if (iocb->iocb_cmpl) {
+				icmd = &iocb->iocb;
+				icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
+				icmd->un.ulpWord[4] = IOERR_SLI_DOWN;
+				(iocb->iocb_cmpl) (phba, iocb, iocb);
+			} else {
+				mempool_free( iocb, phba->iocb_mem_pool);
+			}
+		}
+
+		INIT_LIST_HEAD(&(pring->txq));
+
+		if (pring->fast_lookup) {
+			kfree(pring->fast_lookup);
+			pring->fast_lookup = NULL;
+		}
+
+	}
+
+	/* Return any active mbox cmds */
+	del_timer_sync(&psli->mbox_tmo);
+	phba->work_hba_events &= ~WORKER_MBOX_TMO;
+	if ((psli->mbox_active)) {
+		pmb = psli->mbox_active;
+		pmb->mb.mbxStatus = MBX_NOT_FINISHED;
+		if (pmb->mbox_cmpl)
+			pmb->mbox_cmpl(phba,pmb);
+	}
+	psli->sliinit.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
+	psli->mbox_active = NULL;
+
+	/* Return any pending mbox cmds */
+	while ((pmb = lpfc_mbox_get(phba)) != NULL) {
+		pmb->mb.mbxStatus = MBX_NOT_FINISHED;
+		if (pmb->mbox_cmpl)
+			pmb->mbox_cmpl(phba,pmb);
+	}
+
+	INIT_LIST_HEAD(&psli->mboxq);
+
+	/*
+	 * Provided the hba is not in an error state, reset it.  It is not
+	 * capable of IO anymore.
+	 */
+	if (phba->hba_state != LPFC_HBA_ERROR) {
+		phba->hba_state = LPFC_INIT_START;
+		lpfc_sli_brdreset(phba);
+	}
+
+	return 1;
+}
+
+void
+lpfc_sli_pcimem_bcopy(uint32_t * src, uint32_t * dest, uint32_t cnt)
+{
+	uint32_t ldata;
+	int i;
+
+	for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
+		ldata = *src++;
+		ldata = le32_to_cpu(ldata);
+		*dest++ = ldata;
+	}
+}
+
+int
+lpfc_sli_ringpostbuf_put(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
+			 struct lpfc_dmabuf * mp)
+{
+	/* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
+	   later */
+	list_add_tail(&mp->list, &pring->postbufq);
+
+	pring->postbufq_cnt++;
+	return 0;
+}
+
+
+struct lpfc_dmabuf *
+lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
+			 dma_addr_t phys)
+{
+	struct lpfc_dmabuf *mp, *next_mp;
+	struct list_head *slp = &pring->postbufq;
+
+	/* Search postbufq, from the begining, looking for a match on phys */
+	list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
+		if (mp->phys == phys) {
+			list_del_init(&mp->list);
+			pring->postbufq_cnt--;
+			return mp;
+		}
+	}
+
+	lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
+			"%d:0410 Cannot find virtual addr for mapped buf on "
+			"ring %d Data x%llx x%p x%p x%x\n",
+			phba->brd_no, pring->ringno, (unsigned long long)phys,
+			slp->next, slp->prev, pring->postbufq_cnt);
+	return NULL;
+}
+
+uint32_t
+lpfc_sli_next_iotag(struct lpfc_hba * phba, struct lpfc_sli_ring * pring)
+{
+	LPFC_RING_INIT_t *pringinit;
+	struct lpfc_sli *psli;
+	uint32_t search_start;
+
+	psli = &phba->sli;
+	pringinit = &psli->sliinit.ringinit[pring->ringno];
+
+	if (pring->fast_lookup == NULL) {
+		pringinit->iotag_ctr++;
+		if (pringinit->iotag_ctr >= pringinit->iotag_max)
+			pringinit->iotag_ctr = 1;
+		return pringinit->iotag_ctr;
+	}
+
+	search_start = pringinit->iotag_ctr;
+
+	do {
+		pringinit->iotag_ctr++;
+		if (pringinit->iotag_ctr >= pringinit->fast_iotag)
+			pringinit->iotag_ctr = 1;
+
+		if(*(pring->fast_lookup + pringinit->iotag_ctr) == NULL)
+			return pringinit->iotag_ctr;
+
+	} while (pringinit->iotag_ctr != search_start);
+
+	/*
+	 * Outstanding I/O count for ring <ringno> is at max <fast_iotag>
+	 */
+	lpfc_printf_log(phba,
+		KERN_ERR,
+		LOG_SLI,
+		"%d:0318 Outstanding I/O count for ring %d is at max x%x\n",
+		phba->brd_no,
+		pring->ringno,
+		psli->sliinit.ringinit[pring->ringno].fast_iotag);
+	return (0);
+}
+
+static void
+lpfc_sli_abort_elsreq_cmpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
+			   struct lpfc_iocbq * rspiocb)
+{
+	struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
+	/* Free the resources associated with the ELS_REQUEST64 IOCB the driver
+	 * just aborted.
+	 * In this case, context2  = cmd,  context2->next = rsp, context3 = bpl
+	 */
+	if (cmdiocb->context2) {
+		buf_ptr1 = (struct lpfc_dmabuf *) cmdiocb->context2;
+
+		/* Free the response IOCB before completing the abort
+		   command.  */
+		if (!list_empty(&buf_ptr1->list)) {
+
+			buf_ptr = list_entry(buf_ptr1->list.next,
+					     struct lpfc_dmabuf, list);
+
+			list_del(&buf_ptr->list);
+			lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
+			kfree(buf_ptr);
+		}
+		lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
+		kfree(buf_ptr1);
+	}
+
+	if (cmdiocb->context3) {
+		buf_ptr = (struct lpfc_dmabuf *) cmdiocb->context3;
+		lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
+		kfree(buf_ptr);
+	}
+	mempool_free( cmdiocb, phba->iocb_mem_pool);
+	return;
+}
+
+int
+lpfc_sli_issue_abort_iotag32(struct lpfc_hba * phba,
+			     struct lpfc_sli_ring * pring,
+			     struct lpfc_iocbq * cmdiocb)
+{
+	struct lpfc_sli *psli;
+	struct lpfc_iocbq *abtsiocbp;
+	IOCB_t *icmd = NULL;
+	IOCB_t *iabt = NULL;
+	uint32_t iotag32;
+
+	psli = &phba->sli;
+
+	/* issue ABTS for this IOCB based on iotag */
+	if ((abtsiocbp = mempool_alloc(phba->iocb_mem_pool, GFP_ATOMIC)) == 0) {
+		return (0);
+	}
+	memset(abtsiocbp, 0, sizeof (struct lpfc_iocbq));
+	iabt = &abtsiocbp->iocb;
+
+	icmd = &cmdiocb->iocb;
+	switch (icmd->ulpCommand) {
+	case CMD_ELS_REQUEST64_CR:
+		iotag32 = icmd->un.elsreq64.bdl.ulpIoTag32;
+		/* Even though we abort the ELS command, the firmware may access
+		 * the BPL or other resources before it processes our
+		 * ABORT_MXRI64. Thus we must delay reusing the cmdiocb
+		 * resources till the actual abort request completes.
+		 */
+		abtsiocbp->context1 = (void *)((unsigned long)icmd->ulpCommand);
+		abtsiocbp->context2 = cmdiocb->context2;
+		abtsiocbp->context3 = cmdiocb->context3;
+		cmdiocb->context2 = NULL;
+		cmdiocb->context3 = NULL;
+		abtsiocbp->iocb_cmpl = lpfc_sli_abort_elsreq_cmpl;
+		break;
+	default:
+		mempool_free( abtsiocbp, phba->iocb_mem_pool);
+		return (0);
+	}
+
+	iabt->un.amxri.abortType = ABORT_TYPE_ABTS;
+	iabt->un.amxri.iotag32 = iotag32;
+
+	iabt->ulpLe = 1;
+	iabt->ulpClass = CLASS3;
+	iabt->ulpCommand = CMD_ABORT_MXRI64_CN;
+
+	if (lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0) == IOCB_ERROR) {
+		mempool_free( abtsiocbp, phba->iocb_mem_pool);
+		return (0);
+	}
+
+	return (1);
+}
+
+void
+lpfc_sli_abort_fcp_cmpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
+                           struct lpfc_iocbq * rspiocb)
+{
+	/*
+	 * Just free the iocbq resources back to the memory pool.  This was an
+	 * abort command and has no other outstanding resources associated with
+	 * it.
+	 */
+	mempool_free(cmdiocb, phba->iocb_mem_pool);
+}
+
+
+int
+lpfc_sli_abort_iocb_ctx(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
+			uint32_t ctx)
+{
+	struct lpfc_sli *psli;
+	struct lpfc_iocbq *iocb, *next_iocb;
+	struct lpfc_iocbq *abtsiocbp;
+	IOCB_t *icmd = NULL, *cmd = NULL;
+	int errcnt;
+
+	psli = &phba->sli;
+	errcnt = 0;
+
+	/* Error matching iocb on txq or txcmplq
+	 * First check the txq.
+	 */
+	list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
+		cmd = &iocb->iocb;
+		if (cmd->ulpContext != ctx) {
+			continue;
+		}
+
+		list_del_init(&iocb->list);
+		pring->txq_cnt--;
+		if (iocb->iocb_cmpl) {
+			icmd = &iocb->iocb;
+			icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
+			icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
+			(iocb->iocb_cmpl) (phba, iocb, iocb);
+		} else {
+			mempool_free( iocb, phba->iocb_mem_pool);
+		}
+	}
+
+	/* Next check the txcmplq */
+	list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
+		cmd = &iocb->iocb;
+		if (cmd->ulpContext != ctx) {
+			continue;
+		}
+
+		/* issue ABTS for this IOCB based on iotag */
+		if ((abtsiocbp = mempool_alloc(phba->iocb_mem_pool,
+					       GFP_ATOMIC)) == 0) {
+			errcnt++;
+			continue;
+		}
+		memset(abtsiocbp, 0, sizeof (struct lpfc_iocbq));
+		icmd = &abtsiocbp->iocb;
+
+		icmd->un.acxri.abortType = ABORT_TYPE_ABTS;
+		icmd->un.acxri.abortContextTag = cmd->ulpContext;
+		icmd->un.acxri.abortIoTag = cmd->ulpIoTag;
+
+		icmd->ulpLe = 1;
+		icmd->ulpClass = cmd->ulpClass;
+		abtsiocbp->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
+		if (phba->hba_state >= LPFC_LINK_UP) {
+			icmd->ulpCommand = CMD_ABORT_XRI_CN;
+		} else {
+			icmd->ulpCommand = CMD_CLOSE_XRI_CN;
+		}
+
+		if (lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0) ==
+								IOCB_ERROR) {
+			mempool_free( abtsiocbp, phba->iocb_mem_pool);
+			errcnt++;
+			continue;
+		}
+		/* The rsp ring completion will remove IOCB from txcmplq when
+		 * abort is read by HBA.
+		 */
+	}
+	return (errcnt);
+}
+
+int
+lpfc_sli_sum_iocb_host(struct lpfc_hba * phba,
+			struct lpfc_sli_ring * pring)
+{
+	struct lpfc_sli *psli;
+	struct lpfc_iocbq *iocb, *next_iocb;
+	IOCB_t *cmd = NULL;
+	struct lpfc_scsi_buf *lpfc_cmd;
+	int sum;
+
+	psli = &phba->sli;
+	sum = 0;
+
+	/* Error matching iocb on txq or txcmplq
+	 * First check the txq.
+	 */
+	list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
+		cmd = &iocb->iocb;
+
+		/* Must be a FCP command */
+		if ((cmd->ulpCommand != CMD_FCP_ICMND64_CR) &&
+		    (cmd->ulpCommand != CMD_FCP_IWRITE64_CR) &&
+		    (cmd->ulpCommand != CMD_FCP_IREAD64_CR)) {
+			continue;
+		}
+
+		/* context1 MUST be a struct lpfc_scsi_buf */
+		lpfc_cmd = (struct lpfc_scsi_buf *) (iocb->context1);
+		if (lpfc_cmd == 0) {
+			continue;
+		}
+		sum++;
+	}
+
+	/* Next check the txcmplq */
+	list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
+		cmd = &iocb->iocb;
+
+		/* Must be a FCP command */
+		if ((cmd->ulpCommand != CMD_FCP_ICMND64_CR) &&
+		    (cmd->ulpCommand != CMD_FCP_IWRITE64_CR) &&
+		    (cmd->ulpCommand != CMD_FCP_IREAD64_CR)) {
+			continue;
+		}
+
+		/* context1 MUST be a struct lpfc_scsi_buf */
+		lpfc_cmd = (struct lpfc_scsi_buf *) (iocb->context1);
+		if (lpfc_cmd == 0) {
+			continue;
+		}
+		sum++;
+	}
+	return (sum);
+}
+
+int
+lpfc_sli_abort_iocb_host(struct lpfc_hba * phba,
+			struct lpfc_sli_ring * pring, int flag)
+{
+	struct lpfc_sli *psli;
+	struct lpfc_iocbq *iocb, *next_iocb;
+	struct lpfc_iocbq *abtsiocbp;
+	IOCB_t *icmd = NULL, *cmd = NULL;
+	struct lpfc_scsi_buf *lpfc_cmd;
+	int errcnt;
+
+	psli = &phba->sli;
+	errcnt = 0;
+
+	/* Error matching iocb on txq or txcmplq
+	 * First check the txq.
+	 */
+	if(flag & LPFC_ABORT_TXQ) {
+		list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
+			cmd = &iocb->iocb;
+
+			/* Must be a FCP command */
+			if ((cmd->ulpCommand != CMD_FCP_ICMND64_CR) &&
+		    	(cmd->ulpCommand != CMD_FCP_IWRITE64_CR) &&
+		    	(cmd->ulpCommand != CMD_FCP_IREAD64_CR)) {
+				continue;
+			}
+
+			/* context1 MUST be a struct lpfc_scsi_buf */
+			lpfc_cmd = (struct lpfc_scsi_buf *) (iocb->context1);
+			if (lpfc_cmd == 0) {
+				continue;
+			}
+
+			list_del_init(&iocb->list);
+			pring->txq_cnt--;
+			if (iocb->iocb_cmpl) {
+				icmd = &iocb->iocb;
+				icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
+				icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
+				(iocb->iocb_cmpl) (phba, iocb, iocb);
+			} else {
+				mempool_free( iocb, phba->iocb_mem_pool);
+			}
+		}
+	}
+
+	if(flag & LPFC_ABORT_TXCMPLQ) {
+		/* Next check the txcmplq */
+		list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
+					 list) {
+			cmd = &iocb->iocb;
+
+			/* Must be a FCP command */
+			if ((cmd->ulpCommand != CMD_FCP_ICMND64_CR) &&
+			    (cmd->ulpCommand != CMD_FCP_IWRITE64_CR) &&
+			    (cmd->ulpCommand != CMD_FCP_IREAD64_CR)) {
+				continue;
+			}
+
+			/* context1 MUST be a struct lpfc_scsi_buf */
+			lpfc_cmd = (struct lpfc_scsi_buf *) (iocb->context1);
+			if (lpfc_cmd == 0) {
+				continue;
+			}
+
+			/* issue ABTS for this IOCB based on iotag */
+			if ((abtsiocbp = mempool_alloc(phba->iocb_mem_pool,
+						       GFP_ATOMIC)) == 0) {
+				errcnt++;
+				continue;
+			}
+			memset(abtsiocbp, 0, sizeof (struct lpfc_iocbq));
+			icmd = &abtsiocbp->iocb;
+
+			icmd->un.acxri.abortType = ABORT_TYPE_ABTS;
+			icmd->un.acxri.abortContextTag = cmd->ulpContext;
+			icmd->un.acxri.abortIoTag = cmd->ulpIoTag;
+
+			icmd->ulpLe = 1;
+			icmd->ulpClass = cmd->ulpClass;
+			abtsiocbp->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
+			if (phba->hba_state >= LPFC_LINK_UP) {
+				icmd->ulpCommand = CMD_ABORT_XRI_CN;
+			} else {
+				icmd->ulpCommand = CMD_CLOSE_XRI_CN;
+			}
+
+			if (lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0) ==
+								IOCB_ERROR) {
+				mempool_free( abtsiocbp, phba->iocb_mem_pool);
+				errcnt++;
+				continue;
+			}
+			/* The rsp ring completion will remove IOCB from
+			 * tacmplq when abort is read by HBA.
+			 */
+		}
+	}
+	return (errcnt);
+}
+
+int
+lpfc_sli_sum_iocb_lun(struct lpfc_hba * phba,
+			struct lpfc_sli_ring * pring,
+			uint16_t scsi_target, uint64_t scsi_lun)
+{
+	struct lpfc_sli *psli;
+	struct lpfc_iocbq *iocb, *next_iocb;
+	IOCB_t *cmd = NULL;
+	struct lpfc_scsi_buf *lpfc_cmd;
+	int sum;
+
+	psli = &phba->sli;
+	sum = 0;
+
+	/* Error matching iocb on txq or txcmplq
+	 * First check the txq.
+	 */
+	list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
+		cmd = &iocb->iocb;
+
+		/* Must be a FCP command */
+		if ((cmd->ulpCommand != CMD_FCP_ICMND64_CR) &&
+		    (cmd->ulpCommand != CMD_FCP_IWRITE64_CR) &&
+		    (cmd->ulpCommand != CMD_FCP_IREAD64_CR)) {
+			continue;
+		}
+
+		/* context1 MUST be a struct lpfc_scsi_buf */
+		lpfc_cmd = (struct lpfc_scsi_buf *) (iocb->context1);
+		if ((lpfc_cmd == 0) ||
+		    (lpfc_cmd->target == 0) ||
+		    (lpfc_cmd->target->scsi_id != scsi_target) ||
+		    (lpfc_cmd->lun != scsi_lun)) {
+			continue;
+		}
+		sum++;
+	}
+
+	/* Next check the txcmplq */
+	list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
+		cmd = &iocb->iocb;
+
+		/* Must be a FCP command */
+		if ((cmd->ulpCommand != CMD_FCP_ICMND64_CR) &&
+		    (cmd->ulpCommand != CMD_FCP_IWRITE64_CR) &&
+		    (cmd->ulpCommand != CMD_FCP_IREAD64_CR)) {
+			continue;
+		}
+
+		/* context1 MUST be a struct lpfc_scsi_buf */
+		lpfc_cmd = (struct lpfc_scsi_buf *) (iocb->context1);
+		if ((lpfc_cmd == 0) ||
+		    (lpfc_cmd->target == 0) ||
+		    (lpfc_cmd->target->scsi_id != scsi_target) ||
+		    (lpfc_cmd->lun != scsi_lun)) {
+			continue;
+		}
+
+		sum++;
+	}
+	return (sum);
+}
+
+int
+lpfc_sli_abort_iocb_lun(struct lpfc_hba * phba,
+			struct lpfc_sli_ring * pring,
+			uint16_t scsi_target, uint64_t scsi_lun, int flag)
+{
+	struct lpfc_sli *psli;
+	struct lpfc_iocbq *iocb, *next_iocb;
+	struct lpfc_iocbq *abtsiocbp;
+	IOCB_t *icmd = NULL, *cmd = NULL;
+	struct lpfc_scsi_buf *lpfc_cmd;
+	int errcnt;
+
+	psli = &phba->sli;
+	errcnt = 0;
+
+	/* Error matching iocb on txq or txcmplq
+	 * First check the txq.
+	 */
+	if(flag & LPFC_ABORT_TXQ) {
+		list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
+			cmd = &iocb->iocb;
+
+			/* Must be a FCP command */
+			if ((cmd->ulpCommand != CMD_FCP_ICMND64_CR) &&
+			    (cmd->ulpCommand != CMD_FCP_IWRITE64_CR) &&
+			    (cmd->ulpCommand != CMD_FCP_IREAD64_CR)) {
+				continue;
+			}
+
+			/* context1 MUST be a struct lpfc_scsi_buf */
+			lpfc_cmd = (struct lpfc_scsi_buf *) (iocb->context1);
+			if ((lpfc_cmd == 0) ||
+			    (lpfc_cmd->target == 0) ||
+			    (lpfc_cmd->target->scsi_id != scsi_target) ||
+			    (lpfc_cmd->lun != scsi_lun)) {
+				continue;
+			}
+
+			list_del_init(&iocb->list);
+			pring->txq_cnt--;
+			if (iocb->iocb_cmpl) {
+				icmd = &iocb->iocb;
+				icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
+				icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
+				(iocb->iocb_cmpl) (phba, iocb, iocb);
+			} else {
+				mempool_free( iocb, phba->iocb_mem_pool);
+			}
+		}
+	}
+
+	if(flag & LPFC_ABORT_TXCMPLQ) {
+		/* Next check the txcmplq */
+		list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
+					 list) {
+			cmd = &iocb->iocb;
+
+			/* Must be a FCP command */
+			if ((cmd->ulpCommand != CMD_FCP_ICMND64_CR) &&
+			    (cmd->ulpCommand != CMD_FCP_IWRITE64_CR) &&
+			    (cmd->ulpCommand != CMD_FCP_IREAD64_CR)) {
+				continue;
+			}
+
+			/* context1 MUST be a struct lpfc_scsi_buf */
+			lpfc_cmd = (struct lpfc_scsi_buf *) (iocb->context1);
+			if ((lpfc_cmd == 0) ||
+			    (lpfc_cmd->target == 0) ||
+			    (lpfc_cmd->target->scsi_id != scsi_target) ||
+			    (lpfc_cmd->lun != scsi_lun)) {
+				continue;
+			}
+
+			/* issue ABTS for this IOCB based on iotag */
+			if ((abtsiocbp = mempool_alloc(phba->iocb_mem_pool,
+						       GFP_ATOMIC)) == 0) {
+				errcnt++;
+				continue;
+			}
+			memset(abtsiocbp, 0, sizeof (struct lpfc_iocbq));
+			icmd = &abtsiocbp->iocb;
+
+			icmd->un.acxri.abortType = ABORT_TYPE_ABTS;
+			icmd->un.acxri.abortContextTag = cmd->ulpContext;
+			icmd->un.acxri.abortIoTag = cmd->ulpIoTag;
+
+			icmd->ulpLe = 1;
+			icmd->ulpClass = cmd->ulpClass;
+			abtsiocbp->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
+			if (phba->hba_state >= LPFC_LINK_UP) {
+				icmd->ulpCommand = CMD_ABORT_XRI_CN;
+			} else {
+				icmd->ulpCommand = CMD_CLOSE_XRI_CN;
+			}
+
+			if (lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0) ==
+								IOCB_ERROR) {
+				mempool_free( abtsiocbp, phba->iocb_mem_pool);
+				errcnt++;
+				continue;
+			}
+			/* The rsp ring completion will remove IOCB from
+			 * tacmplq when abort is read by HBA.
+			 */
+		}
+	}
+	return (errcnt);
+}
+
+int
+lpfc_sli_abort_iocb_tgt(struct lpfc_hba * phba,
+			struct lpfc_sli_ring * pring,
+			uint16_t scsi_target, int flag)
+{
+	struct lpfc_sli *psli;
+	struct lpfc_iocbq *iocb, *next_iocb;
+	struct lpfc_iocbq *abtsiocbp;
+	IOCB_t *icmd = NULL, *cmd = NULL;
+	struct lpfc_scsi_buf *lpfc_cmd;
+	int errcnt;
+
+	psli = &phba->sli;
+	errcnt = 0;
+
+	/* Error matching iocb on txq or txcmplq
+	 * First check the txq.
+	 */
+	if(flag & LPFC_ABORT_TXQ) {
+		list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
+			cmd = &iocb->iocb;
+
+			/* Must be a FCP command */
+			if ((cmd->ulpCommand != CMD_FCP_ICMND64_CR) &&
+			    (cmd->ulpCommand != CMD_FCP_IWRITE64_CR) &&
+			    (cmd->ulpCommand != CMD_FCP_IREAD64_CR)) {
+				continue;
+			}
+
+			/* context1 MUST be a struct lpfc_scsi_buf */
+			lpfc_cmd = (struct lpfc_scsi_buf *) (iocb->context1);
+			if ((lpfc_cmd == 0) ||
+			    (lpfc_cmd->target == 0) ||
+			    (lpfc_cmd->target->scsi_id != scsi_target)) {
+				continue;
+			}
+
+			list_del_init(&iocb->list);
+			pring->txq_cnt--;
+			if (iocb->iocb_cmpl) {
+				icmd = &iocb->iocb;
+				icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
+				icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
+				(iocb->iocb_cmpl) (phba, iocb, iocb);
+			} else {
+				mempool_free( iocb, phba->iocb_mem_pool);
+			}
+		}
+	}
+
+	if(flag & LPFC_ABORT_TXCMPLQ) {
+		/* Next check the txcmplq */
+		list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
+					 list) {
+			cmd = &iocb->iocb;
+
+			/* Must be a FCP command */
+			if ((cmd->ulpCommand != CMD_FCP_ICMND64_CR) &&
+			    (cmd->ulpCommand != CMD_FCP_IWRITE64_CR) &&
+			    (cmd->ulpCommand != CMD_FCP_IREAD64_CR)) {
+				continue;
+			}
+
+			/* context1 MUST be a struct lpfc_scsi_buf */
+			lpfc_cmd = (struct lpfc_scsi_buf *) (iocb->context1);
+			if ((lpfc_cmd == 0) ||
+			    (lpfc_cmd->target == 0) ||
+			    (lpfc_cmd->target->scsi_id != scsi_target)) {
+				continue;
+			}
+
+			/* issue ABTS for this IOCB based on iotag */
+			if ((abtsiocbp = mempool_alloc(phba->iocb_mem_pool,
+				GFP_ATOMIC)) == 0) {
+				errcnt++;
+				continue;
+			}
+			memset(abtsiocbp, 0, sizeof (struct lpfc_iocbq));
+			icmd = &abtsiocbp->iocb;
+
+			icmd->un.acxri.abortType = ABORT_TYPE_ABTS;
+			icmd->un.acxri.abortContextTag = cmd->ulpContext;
+			icmd->un.acxri.abortIoTag = cmd->ulpIoTag;
+
+			icmd->ulpLe = 1;
+			icmd->ulpClass = cmd->ulpClass;
+			abtsiocbp->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
+			if (phba->hba_state >= LPFC_LINK_UP) {
+				icmd->ulpCommand = CMD_ABORT_XRI_CN;
+			} else {
+				icmd->ulpCommand = CMD_CLOSE_XRI_CN;
+			}
+
+			if (lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0) ==
+								IOCB_ERROR) {
+				mempool_free( abtsiocbp, phba->iocb_mem_pool);
+				errcnt++;
+				continue;
+			}
+			/* The rsp ring completion will remove IOCB from
+			 * txcmplq when abort is read by HBA.
+			 */
+		}
+	}
+	return (errcnt);
+}
+
+
+
+void
+lpfc_sli_wake_iocb_high_priority(struct lpfc_hba * phba,
+				 struct lpfc_iocbq * queue1,
+				 struct lpfc_iocbq * queue2)
+{
+	if (queue1->context2 && queue2)
+		memcpy(queue1->context2, queue2, sizeof (struct lpfc_iocbq));
+
+	/* The waiter is looking for LPFC_IO_HIPRI bit to be set
+	   as a signal to wake up */
+	queue1->iocb_flag |= LPFC_IO_HIPRI;
+	return;
+}
+
+static void
+lpfc_sli_wake_iocb_high_priority_cleanup(struct lpfc_hba * phba,
+					struct lpfc_iocbq * queue1,
+					struct lpfc_iocbq * queue2)
+{
+	struct lpfc_scsi_buf *lpfc_cmd = queue1->context1;
+
+	/*
+	 * Just free the iocbq back to the mempool.  The driver
+	 * has stopped polling and this routine will execute as
+	 * a result of the subsequent abort.
+	 */
+	mempool_free(queue1->context2, phba->iocb_mem_pool);
+	lpfc_free_scsi_buf(lpfc_cmd);
+	return;
+}
+
+int
+lpfc_sli_issue_iocb_wait_high_priority(struct lpfc_hba * phba,
+				       struct lpfc_sli_ring * pring,
+				       struct lpfc_iocbq * piocb,
+				       uint32_t flag,
+				       struct lpfc_iocbq * prspiocbq)
+{
+	int wait_time = 0, retval = IOCB_ERROR;
+
+	/* The caller must left context1 empty.  */
+	if (piocb->context_un.hipri_wait_queue != 0) {
+		return IOCB_ERROR;
+	}
+
+	/*
+	 * If the caller has provided a response iocbq buffer, context2 must
+	 * be NULL or its an error.
+	 */
+	if (prspiocbq && piocb->context2) {
+		return IOCB_ERROR;
+	}
+
+	piocb->context2 = prspiocbq;
+
+	/* Setup callback routine and issue the command. */
+	piocb->iocb_cmpl = lpfc_sli_wake_iocb_high_priority;
+	retval = lpfc_sli_issue_iocb(phba, pring, piocb,
+					flag | SLI_IOCB_HIGH_PRIORITY);
+	if (retval != IOCB_SUCCESS) {
+		piocb->context2 = NULL;
+		return IOCB_ERROR;
+	}
+
+	/*
+	 * This high-priority iocb was sent out-of-band.  Poll for its
+	 * completion rather than wait for a signal.  Note that the host_lock
+	 * is held by the midlayer and must be released here to allow the
+	 * interrupt handlers to complete the IO and signal this routine via
+	 * the iocb_flag.
+	 * The driver waits a maximum of 600 seconds to give the FW ample time
+	 * to complete the target reset ABTS.  The race is not waiting long 
+	 * enough and then having the FW complete the request before the driver
+	 * can issue the second abort.  Since a solicited completion is required
+	 * by the FW, this wait period should be enough time for the FW to
+	 * complete the abts successfully or give up.
+	 */
+
+	retval = IOCB_TIMEDOUT;
+	spin_unlock_irq(phba->host->host_lock);
+	while (wait_time <= 600000) {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,6)
+		mdelay(100);
+#else
+		msleep(100);
+#endif
+		if (piocb->iocb_flag & LPFC_IO_HIPRI) {
+			piocb->iocb_flag &= ~LPFC_IO_HIPRI;
+			retval = IOCB_SUCCESS;
+			break;
+		}
+		wait_time += 100;
+	}
+
+	spin_lock_irq(phba->host->host_lock);
+
+	/*
+	 * If the polling attempt failed to get a completion from the HBA, 
+	 * then substitute the initial completion function with one that
+	 * releases the piocb back to the mempool.  Failure to do this 
+	 * results in a memory leak.  Also note the small timing race that
+	 * exists between the driver giving up and a completion coming in.
+	 */
+	if ((retval == IOCB_TIMEDOUT) && !(piocb->iocb_flag & LPFC_IO_HIPRI)) {
+		lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
+				"%d:0327 waited %d mSecs for high priority "
+				"IOCB %p - giving up\n",
+				phba->brd_no, wait_time, piocb);
+		piocb->iocb_cmpl = lpfc_sli_wake_iocb_high_priority_cleanup;
+	}
+
+	piocb->context2 = NULL;
+
+	return retval;
+}
+
+int
+lpfc_sli_issue_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq,
+			 uint32_t timeout)
+{
+	DECLARE_WAIT_QUEUE_HEAD(done_q);
+	DECLARE_WAITQUEUE(wq_entry, current);
+	uint32_t timeleft = 0;
+	int retval;
+
+	/* The caller must leave context1 empty. */
+	if (pmboxq->context1 != 0) {
+		return (MBX_NOT_FINISHED);
+	}
+
+	/* setup wake call as IOCB callback */
+	pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
+	/* setup context field to pass wait_queue pointer to wake function  */
+	pmboxq->context1 = &done_q;
+
+	/* start to sleep before we wait, to avoid races */
+	set_current_state(TASK_INTERRUPTIBLE);
+	add_wait_queue(&done_q, &wq_entry);
+
+	/* now issue the command */
+	spin_lock_irq(phba->host->host_lock);
+	retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
+	spin_unlock_irq(phba->host->host_lock);
+
+	if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
+		timeleft = schedule_timeout(timeout * HZ);
+		pmboxq->context1 = NULL;
+		/* if schedule_timeout returns 0, we timed out and were not
+		   woken up */
+		if (timeleft == 0) {
+			retval = MBX_TIMEOUT;
+		} else {
+			retval = MBX_SUCCESS;
+		}
+	}
+
+
+	set_current_state(TASK_RUNNING);
+	remove_wait_queue(&done_q, &wq_entry);
+	return retval;
+}
+
+static void
+lpfc_sli_wake_iocb_wait(struct lpfc_hba * phba,
+			struct lpfc_iocbq * queue1, struct lpfc_iocbq * queue2)
+{
+	wait_queue_head_t *pdone_q;
+
+	queue1->iocb_flag |= LPFC_IO_WAIT;
+	if (queue1->context2 && queue2)
+		memcpy(queue1->context2, queue2, sizeof (struct lpfc_iocbq));
+
+	/*
+	 * If pdone_q is empty, the waiter gave up and returned and this
+	 * call has nothing to do.
+	 */
+	pdone_q = queue1->context_un.hipri_wait_queue;
+	if (pdone_q) {
+		wake_up(pdone_q);
+	}
+
+	return;
+}
+
+int
+lpfc_sli_issue_iocb_wait(struct lpfc_hba * phba,
+			 struct lpfc_sli_ring * pring,
+			 struct lpfc_iocbq * piocb,
+			 struct lpfc_iocbq * prspiocbq, uint32_t timeout)
+{
+	DECLARE_WAIT_QUEUE_HEAD(done_q);
+	DECLARE_WAITQUEUE(wq_entry, current);
+	uint32_t timeleft = 0;
+	int retval;
+
+	/* The caller must leave context1 empty for the driver. */
+	if (piocb->context_un.hipri_wait_queue != 0)
+		return (IOCB_ERROR);
+
+	/* If the caller has provided a response iocbq buffer, then context2
+	 * is NULL or its an error.
+	 */
+	if (prspiocbq) {
+		if (piocb->context2)
+			return (IOCB_ERROR);
+		piocb->context2 = prspiocbq;
+	}
+
+	/* setup wake call as IOCB callback */
+	piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
+	/* setup context field to pass wait_queue pointer to wake function  */
+	piocb->context_un.hipri_wait_queue = &done_q;
+
+	/* start to sleep before we wait, to avoid races */
+	set_current_state(TASK_UNINTERRUPTIBLE);
+	add_wait_queue(&done_q, &wq_entry);
+
+	/* now issue the command */
+	retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0);
+	if (retval == IOCB_SUCCESS) {
+		/* Give up thread time and wait for the iocb to complete or for
+		 * the alloted time to expire.
+		 */
+		spin_unlock_irq(phba->host->host_lock);
+		timeleft = schedule_timeout(timeout * HZ);
+		spin_lock_irq(phba->host->host_lock);
+
+		piocb->context_un.hipri_wait_queue = NULL;
+		piocb->iocb_cmpl = NULL;
+		if (piocb->context2 == prspiocbq)
+			piocb->context2 = NULL;
+
+		/*
+		 * Catch the error cases.  A timeleft of zero is an error since
+		 * the iocb should have completed.  The iocb_flag not have value
+		 * LPFC_IO_WAIT is also an error since the wakeup callback sets
+		 * this flag when it runs.  Handle each.
+		 */
+		if (!(piocb->iocb_flag & LPFC_IO_WAIT)) {
+			printk(KERN_ERR "%s: Timeleft is %d, iocb_flags is 0x%x ring_no %d ulpCommand 0x%x`\n ",
+			       __FUNCTION__, timeleft, piocb->iocb_flag,
+				pring->ringno, piocb->iocb.ulpCommand);
+			retval = IOCB_TIMEDOUT;
+		}
+	}
+
+	remove_wait_queue(&done_q, &wq_entry);
+	set_current_state(TASK_RUNNING);
+	piocb->context2 = NULL;
+	return retval;
+}
+
+irqreturn_t
+lpfc_intr_handler(int irq, void *dev_id, struct pt_regs * regs)
+{
+	struct lpfc_hba *phba;
+	int intr_status;
+
+	/*
+	 * Get the driver's phba structure from the dev_id and
+	 * assume the HBA is not interrupting.
+	 */
+	phba = (struct lpfc_hba *) dev_id;
+
+	if (phba) {
+		/* Call SLI to handle the interrupt event. */
+		intr_status = lpfc_sli_intr(phba);
+		if (intr_status == 0)
+			return IRQ_HANDLED;
+	}
+
+	return IRQ_NONE;
+
+} /* lpfc_intr_handler */
--- linux-2.6.8.1-t044-driver-update//drivers/scsi/lpfc/lpfc_disc.h	1970-01-01 03:00:00.000000000 +0300
+++ rhel4u2//drivers/scsi/lpfc/lpfc_disc.h	2005-10-19 11:47:17.000000000 +0400
@@ -0,0 +1,278 @@
+/*******************************************************************
+ * This file is part of the Emulex Linux Device Driver for         *
+ * Fibre Channel Host Bus Adapters.                                *
+ * Copyright (C) 2003-2005 Emulex.  All rights reserved.           *
+ * EMULEX and SLI are trademarks of Emulex.                        *
+ * www.emulex.com                                                  *
+ *                                                                 *
+ * This program is free software; you can redistribute it and/or   *
+ * modify it under the terms of version 2 of the GNU General       *
+ * Public License as published by the Free Software Foundation.    *
+ * This program is distributed in the hope that it will be useful. *
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
+ * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
+ * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
+ * more details, a copy of which can be found in the file COPYING  *
+ * included with this package.                                     *
+ *******************************************************************/
+
+/*
+ * $Id: lpfc_disc.h 1.51.1.2 2005/06/13 17:16:12EDT sf_support Exp  $
+ */
+
+#ifndef  _H_LPFC_DISC
+#define  _H_LPFC_DISC
+
+#include "lpfc_hw.h"
+
+struct lpfc_target;
+
+#define FC_MAX_HOLD_RSCN     32	      /* max number of deferred RSCNs */
+#define FC_MAX_NS_RSP        65536    /* max size NameServer rsp */
+#define FC_MAXLOOP           126      /* max devices supported on a fc loop */
+#define LPFC_DISC_FLOGI_TMO  10	      /* Discovery FLOGI ratov */
+
+/* Defines for failMask bitmask
+ * These are reasons that the device is not currently available
+ * for I/O to be sent.
+ */
+#define LPFC_DEV_LINK_DOWN       0x1	/* Link is down */
+#define LPFC_DEV_DISAPPEARED     0x2	/* Device disappeared from mapped
+					   list */
+#define LPFC_DEV_DISCOVERY_INP   0x4	/* Device to go through discovery */
+#define LPFC_DEV_DISCONNECTED    0x8 	/* noactive connection to remote dev */
+
+/* These defines are used for set failMask routines */
+#define LPFC_SET_BITMASK		1
+#define LPFC_CLR_BITMASK		2
+
+/* Provide an enumeration for the Types of addresses a FARP can resolve. */
+typedef enum lpfc_farp_addr_type {
+	LPFC_FARP_BY_IEEE,
+	LPFC_FARP_BY_WWPN,
+	LPFC_FARP_BY_WWNN,
+} LPFC_FARP_ADDR_TYPE;
+
+/* This is the protocol dependent definition for a Node List Entry.
+ * This is used by Fibre Channel protocol to support FCP.
+ */
+
+struct lpfc_bindlist {
+	struct list_head      nlp_listp;
+	struct lpfc_target    *nlp_Target;	/* ptr to the tgt structure */
+	struct lpfc_name      nlp_portname;	/* port name */
+	struct lpfc_name      nlp_nodename;	/* node name */
+	uint16_t              nlp_bind_type;
+	uint16_t              nlp_sid;		/* scsi id */
+	uint32_t              nlp_DID;		/* FibreChannel D_ID of entry */
+};
+
+/* structure used to queue event to the discovery tasklet */
+struct lpfc_disc_evt {
+	struct list_head      evt_listp;
+	void                * evt_arg1;
+	void                * evt_arg2;
+	uint32_t              evt;
+};
+typedef struct lpfc_disc_evt LPFC_DISC_EVT_t;
+
+#define LPFC_EVT_MBOX		0x1
+#define LPFC_EVT_SOL_IOCB	0x2
+#define LPFC_EVT_UNSOL_IOCB	0x3
+#define LPFC_EVT_NODEV_TMO	0x4
+#define LPFC_EVT_SCAN		0x5
+#define LPFC_EVT_ERR_ATTN       0x6
+#define LPFC_EVT_ELS_RETRY      0x7
+#define LPFC_EVT_OPEN_LOOP      0x8
+
+struct lpfc_nodelist {
+	struct list_head nlp_listp;
+	struct lpfc_name nlp_portname;		/* port name */
+	struct lpfc_name nlp_nodename;		/* node name */
+	uint32_t         nlp_failMask;		/* failure mask for device */
+	uint32_t         nlp_flag;		/* entry  flags */
+	uint32_t         nlp_DID;		/* FC D_ID of entry */
+	uint32_t         nlp_last_elscmd;  	/* Last ELS cmd sent */
+	uint16_t         nlp_type;
+#define NLP_FC_NODE        0x1			/* entry is an FC node */
+#define NLP_FABRIC         0x4			/* entry rep a Fabric entity */
+#define NLP_FCP_TARGET     0x8			/* entry is an FCP target */
+
+	uint16_t        nlp_rpi;
+	uint16_t        nlp_state;		/* state transition indicator */
+	uint16_t        nlp_xri;		/* output exchange id for RPI */
+	uint16_t        nlp_sid;		/* scsi id */
+#define NLP_NO_SID              0xffff
+
+	uint8_t         nlp_retry;		/* used for ELS retries */
+	uint8_t         nlp_disc_refcnt;	/* used for DSM */
+	uint8_t         nlp_fcp_info;	        /* class info, bits 0-3 */
+#define NLP_FCP_2_DEVICE   0x10			/* FCP-2 device */
+
+	struct timer_list   nlp_delayfunc;	/* Used for delayed ELS cmds */
+	struct timer_list   nlp_tmofunc;	/* Used for nodev tmo */
+	struct lpfc_target *nlp_Target;		/* Pointer to the target
+						   structure */
+
+	struct lpfc_bindlist *nlp_listp_bind;	/* Linked list bounded remote
+						   ports */
+	struct lpfc_nodelist *nlp_rpi_hash_next;
+	struct lpfc_hba      *nlp_phba;
+	LPFC_DISC_EVT_t nodev_timeout_evt;
+	LPFC_DISC_EVT_t els_retry_evt;
+};
+
+/*++
+ * lpfc_node_farp_list:
+ *   This data structure defines the attributes associated with
+ *   an outstanding FARP REQ to a remote node.
+ *
+ *   listentry - head of this list of pending farp requests.
+ *   rnode_addr - The address of the remote node.  Either the IEEE, WWPN, or
+ *                WWNN.  Used in the FARP request.
+ *
+ --*/
+struct lpfc_node_farp_pend {
+	struct list_head listentry;
+	struct lpfc_name rnode_addr;
+};
+
+/* Defines for nlp_flag (uint32) */
+#define NLP_NO_LIST        0x0		/* Indicates immediately free node */
+#define NLP_UNUSED_LIST    0x1		/* Flg to indicate node will be freed */
+#define NLP_PLOGI_LIST     0x2		/* Flg to indicate sent PLOGI */
+#define NLP_ADISC_LIST     0x3		/* Flg to indicate sent ADISC */
+#define NLP_REGLOGIN_LIST  0x4		/* Flg to indicate sent REG_LOGIN */
+#define NLP_PRLI_LIST      0x5		/* Flg to indicate sent PRLI */
+#define NLP_UNMAPPED_LIST  0x6		/* Node is now unmapped */
+#define NLP_MAPPED_LIST    0x7		/* Node is now mapped */
+#define NLP_NPR_LIST       0x8		/* Node is in NPort Recovery state */
+#define NLP_JUST_DQ        0x9		/* just deque ndlp in lpfc_nlp_list */
+#define NLP_LIST_MASK      0xf		/* mask to see what list node is on */
+#define NLP_PLOGI_SND      0x20		/* sent PLOGI request for this entry */
+#define NLP_PRLI_SND       0x40		/* sent PRLI request for this entry */
+#define NLP_ADISC_SND      0x80		/* sent ADISC request for this entry */
+#define NLP_LOGO_SND       0x100	/* sent LOGO request for this entry */
+#define NLP_RNID_SND       0x400	/* sent RNID request for this entry */
+#define NLP_ELS_SND_MASK   0x7e0	/* sent ELS request for this entry */
+#define NLP_AUTOMAP        0x800	/* Entry was automap'ed */
+#define NLP_SEED_WWPN      0x1000	/* Entry scsi id is seeded for WWPN */
+#define NLP_SEED_WWNN      0x2000	/* Entry scsi id is seeded for WWNN */
+#define NLP_SEED_DID       0x4000	/* Entry scsi id is seeded for DID */
+#define NLP_SEED_MASK      0x807000	/* mask for seeded flags */
+#define NLP_NS_NODE        0x8000	/* Authenticated entry by NameServer */
+#define NLP_NODEV_TMO      0x10000	/* nodev timeout is running for node */
+#define NLP_DELAY_TMO      0x20000	/* delay timeout is running for node */
+#define NLP_NPR_2B_DISC    0x40000	/* node is included in num_disc_nodes */
+#define NLP_RCV_PLOGI      0x80000	/* Rcv'ed PLOGI from remote system */
+#define NLP_LOGO_ACC       0x100000	/* Process LOGO after ACC completes */
+#define NLP_TGT_NO_SCSIID  0x200000	/* good PRLI but no binding for scsid */
+#define NLP_SEED_ALPA      0x800000	/* SCSI id is derived from alpa array */
+#define NLP_ACC_REGLOGIN   0x1000000	/* Issue Reg Login after successful
+					   ACC */
+#define NLP_NPR_ADISC      0x2000000	/* Issue ADISC when dq'ed from
+					   NPR list */
+#define NLP_DELAY_REMOVE   0x4000000	/* Defer removal till end of DSM */
+
+/* Defines for list searchs */
+#define NLP_SEARCH_MAPPED    0x1	/* search mapped */
+#define NLP_SEARCH_UNMAPPED  0x2	/* search unmapped */
+#define NLP_SEARCH_PLOGI     0x4	/* search plogi */
+#define NLP_SEARCH_ADISC     0x8	/* search adisc */
+#define NLP_SEARCH_REGLOGIN  0x10	/* search reglogin */
+#define NLP_SEARCH_PRLI      0x20	/* search prli */
+#define NLP_SEARCH_NPR       0x40	/* search npr */
+#define NLP_SEARCH_UNUSED    0x80	/* search mapped */
+#define NLP_SEARCH_ALL       0xff	/* search all lists */
+
+/* There are 4 different double linked lists nodelist entries can reside on.
+ * The Port Login (PLOGI) list and Address Discovery (ADISC) list are used
+ * when Link Up discovery or Registered State Change Notification (RSCN)
+ * processing is needed.  Each list holds the nodes that require a PLOGI or
+ * ADISC Extended Link Service (ELS) request.  These lists keep track of the
+ * nodes affected by an RSCN, or a Link Up (Typically, all nodes are effected
+ * by Link Up) event.  The unmapped_list contains all nodes that have
+ * successfully logged into at the Fibre Channel level.  The
+ * mapped_list will contain all nodes that are mapped FCP targets.
+ *
+ * The bind list is a list of undiscovered (potentially non-existent) nodes
+ * that we have saved binding information on. This information is used when
+ * nodes transition from the unmapped to the mapped list.
+ */
+
+/* Defines for nlp_state */
+#define NLP_STE_UNUSED_NODE       0x0	/* node is just allocated */
+#define NLP_STE_PLOGI_ISSUE       0x1	/* PLOGI was sent to NL_PORT */
+#define NLP_STE_ADISC_ISSUE       0x2	/* ADISC was sent to NL_PORT */
+#define NLP_STE_REG_LOGIN_ISSUE   0x3	/* REG_LOGIN was issued for NL_PORT */
+#define NLP_STE_PRLI_ISSUE        0x4	/* PRLI was sent to NL_PORT */
+#define NLP_STE_UNMAPPED_NODE     0x5	/* PRLI completed from NL_PORT */
+#define NLP_STE_MAPPED_NODE       0x6	/* Identified as a FCP Target */
+#define NLP_STE_NPR_NODE          0x7	/* NPort disappeared */
+#define NLP_STE_MAX_STATE         0x8
+#define NLP_STE_FREED_NODE        0xff	/* node entry was freed to MEM_NLP */
+
+/* For UNUSED_NODE state, the node has just been allocated.
+ * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
+ * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
+ * and put on the unmapped list. For ADISC processing, the node is taken off
+ * the ADISC list and placed on either the mapped or unmapped list (depending
+ * on its previous state). Once on the unmapped list, a PRLI is issued and the
+ * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
+ * changed to PRLI_COMPL. If the completion indicates a mapped
+ * node, the node is taken off the unmapped list. The binding list is checked
+ * for a valid binding, or a binding is automatically assigned. If binding
+ * assignment is unsuccessful, the node is left on the unmapped list. If
+ * binding assignment is successful, the associated binding list entry (if
+ * any) is removed, and the node is placed on the mapped list.
+ */
+/*
+ * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
+ * lists will receive a DEVICE_RECOVERY event. If the linkdown or nodev timers
+ * expire, all effected nodes will receive a DEVICE_RM event.
+ */
+/*
+ * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
+ * to either the ADISC or PLOGI list.  After a Nameserver query or ALPA loopmap
+ * check, additional nodes may be added (DEVICE_ADD) or removed (DEVICE_RM) to /
+ * from the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
+ * we will first process the ADISC list.  32 entries are processed initially and
+ * ADISC is initited for each one.  Completions / Events for each node are
+ * funnelled thru the state machine.  As each node finishes ADISC processing, it
+ * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
+ * waiting, and the ADISC list count is identically 0, then we are done. For
+ * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
+ * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
+ * list.  32 entries are processed initially and PLOGI is initited for each one.
+ * Completions / Events for each node are funnelled thru the state machine.  As
+ * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
+ * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
+ * identically 0, then we are done. We have now completed discovery / RSCN
+ * handling. Upon completion, ALL nodes should be on either the mapped or
+ * unmapped lists.
+ */
+
+/* Defines for Node List Entry Events that could happen */
+#define NLP_EVT_RCV_PLOGI         0x0	/* Rcv'd an ELS PLOGI command */
+#define NLP_EVT_RCV_PRLI          0x1	/* Rcv'd an ELS PRLI  command */
+#define NLP_EVT_RCV_LOGO          0x2	/* Rcv'd an ELS LOGO  command */
+#define NLP_EVT_RCV_ADISC         0x3	/* Rcv'd an ELS ADISC command */
+#define NLP_EVT_RCV_PDISC         0x4	/* Rcv'd an ELS PDISC command */
+#define NLP_EVT_RCV_PRLO          0x5	/* Rcv'd an ELS PRLO  command */
+#define NLP_EVT_CMPL_PLOGI        0x6	/* Sent an ELS PLOGI command */
+#define NLP_EVT_CMPL_PRLI         0x7	/* Sent an ELS PRLI  command */
+#define NLP_EVT_CMPL_LOGO         0x8	/* Sent an ELS LOGO  command */
+#define NLP_EVT_CMPL_ADISC        0x9	/* Sent an ELS ADISC command */
+#define NLP_EVT_CMPL_REG_LOGIN    0xa	/* REG_LOGIN mbox cmd completed */
+#define NLP_EVT_DEVICE_RM         0xb	/* Device not found in NS / ALPAmap */
+#define NLP_EVT_DEVICE_RECOVERY   0xc	/* Device existence unknown */
+#define NLP_EVT_MAX_EVENT         0xd
+
+
+/* Definitions for Binding Entry Type for lpfc_parse_binding_entry()  */
+#define LPFC_BIND_WW_NN_PN   0
+#define LPFC_BIND_DID        1
+
+#endif				/* _H_LPFC_DISC */
--- linux-2.6.8.1-t044-driver-update//drivers/scsi/lpfc/lpfc_scsi.h	1970-01-01 03:00:00.000000000 +0300
+++ rhel4u2//drivers/scsi/lpfc/lpfc_scsi.h	2005-10-19 11:47:17.000000000 +0400
@@ -0,0 +1,93 @@
+/*******************************************************************
+ * This file is part of the Emulex Linux Device Driver for         *
+ * Fibre Channel Host Bus Adapters.                                *
+ * Copyright (C) 2003-2005 Emulex.  All rights reserved.           *
+ * EMULEX and SLI are trademarks of Emulex.                        *
+ * www.emulex.com                                                  *
+ *                                                                 *
+ * This program is free software; you can redistribute it and/or   *
+ * modify it under the terms of version 2 of the GNU General       *
+ * Public License as published by the Free Software Foundation.    *
+ * This program is distributed in the hope that it will be useful. *
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
+ * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
+ * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
+ * more details, a copy of which can be found in the file COPYING  *
+ * included with this package.                                     *
+ *******************************************************************/
+
+/*
+ * $Id: lpfc_scsi.h 1.71.1.3 2005/06/21 15:48:51EDT sf_support Exp  $
+ */
+
+#ifndef _H_LPFC_SCSI
+#define _H_LPFC_SCSI
+
+#include "lpfc_disc.h"
+#include "lpfc_mem.h"
+#include "lpfc_sli.h"
+
+struct lpfc_hba;
+
+
+struct lpfc_target {
+	struct lpfc_nodelist *pnode;	/* Pointer to the node structure. */
+	uint16_t  scsi_id;
+	uint32_t  qcmdcnt;
+	uint32_t  iodonecnt;
+	uint32_t  errorcnt;
+	uint32_t  slavecnt;
+#if defined(RHEL_FC) || defined(SLES_FC)
+	uint16_t  blocked;
+#endif
+#ifdef RHEL_FC
+	struct scsi_target *starget;		/* Pointer to midlayer target
+						   structure. */
+#endif
+#ifdef SLES_FC
+	struct timer_list dev_loss_timer;
+#endif
+};
+
+struct lpfc_scsi_buf {
+	struct scsi_cmnd *pCmd;
+	struct lpfc_hba *scsi_hba;
+	struct lpfc_target *target;
+	uint32_t lun;
+
+	uint32_t timeout;
+
+	uint16_t status;	/* From IOCB Word 7- ulpStatus */
+	uint32_t result;	/* From IOCB Word 4. */
+
+	uint32_t   seg_cnt;	/* Number of scatter-gather segments returned by
+				 * dma_map_sg.  The driver needs this for calls
+				 * to dma_unmap_sg. */
+	dma_addr_t nonsg_phys;	/* Non scatter-gather physical address. */
+
+	/* dma_ext has both virt, phys to dma-able buffer
+	 * which contains fcp_cmd, fcp_rsp and scatter gather list fro upto
+	 * 68 (LPFC_SCSI_BPL_SIZE) BDE entries,
+	 * xfer length, cdb, data direction....
+	 */
+	struct lpfc_dmabuf dma_ext;
+	struct fcp_cmnd *fcp_cmnd;
+	struct fcp_rsp *fcp_rsp;
+	struct ulp_bde64 *fcp_bpl;
+
+	/* cur_iocbq has phys of the dma-able buffer.
+	 * Iotag is in here
+	 */
+	struct lpfc_iocbq cur_iocbq;
+};
+
+#define LPFC_SCSI_INITIAL_BPL_SIZE  4	/* Number of scsi buf BDEs in fcp_bpl */
+
+#define LPFC_SCSI_DMA_EXT_SIZE 264
+#define LPFC_BPL_SIZE          1024
+
+#define MDAC_DIRECT_CMD                  0x22
+
+#endif				/* _H_LPFC_SCSI */
--- linux-2.6.8.1-t044-driver-update//drivers/scsi/lpfc/lpfc_fcp.h	1970-01-01 03:00:00.000000000 +0300
+++ rhel4u2//drivers/scsi/lpfc/lpfc_fcp.h	2005-10-19 11:47:17.000000000 +0400
@@ -0,0 +1,108 @@
+/*******************************************************************
+ * This file is part of the Emulex Linux Device Driver for         *
+ * Fibre Channel Host Bus Adapters.                                *
+ * Copyright (C) 2003-2005 Emulex.  All rights reserved.           *
+ * EMULEX and SLI are trademarks of Emulex.                        *
+ * www.emulex.com                                                  *
+ *                                                                 *
+ * This program is free software; you can redistribute it and/or   *
+ * modify it under the terms of version 2 of the GNU General       *
+ * Public License as published by the Free Software Foundation.    *
+ * This program is distributed in the hope that it will be useful. *
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
+ * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
+ * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
+ * more details, a copy of which can be found in the file COPYING  *
+ * included with this package.                                     *
+ *******************************************************************/
+
+/*
+ * $Id: lpfc_fcp.h 1.10.1.2 2005/06/13 17:16:19EDT sf_support Exp  $
+ */
+
+#ifndef H_LPFC_DFC
+#define H_LPFC_DFC
+
+#define MAX_LPFC_SNS      128
+
+struct fcp_rsp {
+	uint32_t rspRsvd1;	/* FC Word 0, byte 0:3 */
+	uint32_t rspRsvd2;	/* FC Word 1, byte 0:3 */
+
+	uint8_t rspStatus0;	/* FCP_STATUS byte 0 (reserved) */
+	uint8_t rspStatus1;	/* FCP_STATUS byte 1 (reserved) */
+	uint8_t rspStatus2;	/* FCP_STATUS byte 2 field validity */
+#define RSP_LEN_VALID  0x01	/* bit 0 */
+#define SNS_LEN_VALID  0x02	/* bit 1 */
+#define RESID_OVER     0x04	/* bit 2 */
+#define RESID_UNDER    0x08	/* bit 3 */
+	uint8_t rspStatus3;	/* FCP_STATUS byte 3 SCSI status byte */
+
+	uint32_t rspResId;	/* Residual xfer if residual count field set in
+				   fcpStatus2 */
+	/* Received in Big Endian format */
+	uint32_t rspSnsLen;	/* Length of sense data in fcpSnsInfo */
+	/* Received in Big Endian format */
+	uint32_t rspRspLen;	/* Length of FCP response data in fcpRspInfo */
+	/* Received in Big Endian format */
+
+	uint8_t rspInfo0;	/* FCP_RSP_INFO byte 0 (reserved) */
+	uint8_t rspInfo1;	/* FCP_RSP_INFO byte 1 (reserved) */
+	uint8_t rspInfo2;	/* FCP_RSP_INFO byte 2 (reserved) */
+	uint8_t rspInfo3;	/* FCP_RSP_INFO RSP_CODE byte 3 */
+
+#define RSP_NO_FAILURE       0x00
+#define RSP_DATA_BURST_ERR   0x01
+#define RSP_CMD_FIELD_ERR    0x02
+#define RSP_RO_MISMATCH_ERR  0x03
+#define RSP_TM_NOT_SUPPORTED 0x04	/* Task mgmt function not supported */
+#define RSP_TM_NOT_COMPLETED 0x05	/* Task mgmt function not performed */
+
+	uint32_t rspInfoRsvd;	/* FCP_RSP_INFO bytes 4-7 (reserved) */
+
+	uint8_t rspSnsInfo[MAX_LPFC_SNS];
+#define SNS_ILLEGAL_REQ 0x05	/* sense key is byte 3 ([2]) */
+#define SNSCOD_BADCMD 0x20	/* sense code is byte 13 ([12]) */
+};
+
+struct fcp_cmnd {
+	uint32_t fcpLunMsl;	/* most  significant lun word (32 bits) */
+	uint32_t fcpLunLsl;	/* least significant lun word (32 bits) */
+	/* # of bits to shift lun id to end up in right
+	 * payload word, little endian = 8, big = 16.
+	 */
+#if __BIG_ENDIAN
+#define FC_LUN_SHIFT         16
+#define FC_ADDR_MODE_SHIFT   24
+#else	/*  __LITTLE_ENDIAN */
+#define FC_LUN_SHIFT         8
+#define FC_ADDR_MODE_SHIFT   0
+#endif
+
+	uint8_t fcpCntl0;	/* FCP_CNTL byte 0 (reserved) */
+	uint8_t fcpCntl1;	/* FCP_CNTL byte 1 task codes */
+#define  SIMPLE_Q        0x00
+#define  HEAD_OF_Q       0x01
+#define  ORDERED_Q       0x02
+#define  ACA_Q           0x04
+#define  UNTAGGED        0x05
+	uint8_t fcpCntl2;	/* FCP_CTL byte 2 task management codes */
+#define  FCP_ABORT_TASK_SET  0x02	/* Bit 1 */
+#define  FCP_CLEAR_TASK_SET  0x04	/* bit 2 */
+#define  FCP_BUS_RESET       0x08	/* bit 3 */
+#define  FCP_LUN_RESET       0x10	/* bit 4 */
+#define  FCP_TARGET_RESET    0x20	/* bit 5 */
+#define  FCP_CLEAR_ACA       0x40	/* bit 6 */
+#define  FCP_TERMINATE_TASK  0x80	/* bit 7 */
+	uint8_t fcpCntl3;
+#define  WRITE_DATA      0x01	/* Bit 0 */
+#define  READ_DATA       0x02	/* Bit 1 */
+
+	uint8_t fcpCdb[16];	/* SRB cdb field is copied here */
+	uint32_t fcpDl;		/* Total transfer length */
+
+};
+
+#endif
--- linux-2.6.8.1-t044-driver-update//drivers/scsi/lpfc/lpfc_crtn.h	1970-01-01 03:00:00.000000000 +0300
+++ rhel4u2//drivers/scsi/lpfc/lpfc_crtn.h	2005-10-19 11:47:17.000000000 +0400
@@ -0,0 +1,273 @@
+/*******************************************************************
+ * This file is part of the Emulex Linux Device Driver for         *
+ * Fibre Channel Host Bus Adapters.                                *
+ * Copyright (C) 2003-2005 Emulex.  All rights reserved.           *
+ * EMULEX and SLI are trademarks of Emulex.                        *
+ * www.emulex.com                                                  *
+ *                                                                 *
+ * This program is free software; you can redistribute it and/or   *
+ * modify it under the terms of version 2 of the GNU General       *
+ * Public License as published by the Free Software Foundation.    *
+ * This program is distributed in the hope that it will be useful. *
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
+ * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
+ * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
+ * more details, a copy of which can be found in the file COPYING  *
+ * included with this package.                                     *
+ *******************************************************************/
+
+/*
+ * $Id: lpfc_crtn.h 1.149.1.4 2005/07/13 17:04:12EDT sf_support Exp  $
+ */
+
+#ifndef _H_LPFC_CRTN
+#define _H_LPFC_CRTN
+
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <asm/uaccess.h>
+
+#include "lpfc_disc.h"
+#include "lpfc_logmsg.h"
+#include "lpfc_scsi.h"
+#include "lpfc_sli.h"
+
+
+void lpfc_dump_mem(struct lpfc_hba *, LPFC_MBOXQ_t *, uint16_t);
+void lpfc_read_nv(struct lpfc_hba *, LPFC_MBOXQ_t *);
+int lpfc_read_la(struct lpfc_hba *, LPFC_MBOXQ_t *);
+void lpfc_clear_la(struct lpfc_hba *, LPFC_MBOXQ_t *);
+void lpfc_config_link(struct lpfc_hba *, LPFC_MBOXQ_t *);
+int lpfc_read_sparam(struct lpfc_hba *, LPFC_MBOXQ_t *);
+void lpfc_read_config(struct lpfc_hba *, LPFC_MBOXQ_t *);
+void lpfc_set_slim(struct lpfc_hba *, LPFC_MBOXQ_t *, uint32_t, uint32_t);
+int lpfc_reg_login(struct lpfc_hba *, uint32_t, uint8_t *, LPFC_MBOXQ_t *,
+		   uint32_t);
+void lpfc_unreg_login(struct lpfc_hba *, uint32_t, LPFC_MBOXQ_t *);
+void lpfc_unreg_did(struct lpfc_hba *, uint32_t, LPFC_MBOXQ_t *);
+void lpfc_init_link(struct lpfc_hba *, LPFC_MBOXQ_t *, uint32_t, uint32_t);
+
+
+int lpfc_linkdown(struct lpfc_hba *);
+void lpfc_mbx_cmpl_read_la(struct lpfc_hba *, LPFC_MBOXQ_t *);
+
+void lpfc_mbx_cmpl_clear_la(struct lpfc_hba *, LPFC_MBOXQ_t *);
+void lpfc_mbx_cmpl_reg_login(struct lpfc_hba *, LPFC_MBOXQ_t *);
+void lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *, LPFC_MBOXQ_t *);
+void lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *, LPFC_MBOXQ_t *);
+void lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *, LPFC_MBOXQ_t *);
+int lpfc_consistent_bind_save(struct lpfc_hba *, struct lpfc_bindlist *);
+int lpfc_nlp_plogi(struct lpfc_hba *, struct lpfc_nodelist *);
+int lpfc_nlp_adisc(struct lpfc_hba *, struct lpfc_nodelist *);
+int lpfc_nlp_unmapped(struct lpfc_hba *, struct lpfc_nodelist *);
+int lpfc_nlp_mapped(struct lpfc_hba *, struct lpfc_nodelist *,
+		    struct lpfc_bindlist *);
+int lpfc_nlp_list(struct lpfc_hba *, struct lpfc_nodelist *, int);
+void lpfc_set_disctmo(struct lpfc_hba *);
+int lpfc_can_disctmo(struct lpfc_hba *);
+int lpfc_unreg_rpi(struct lpfc_hba *, struct lpfc_nodelist *);
+int lpfc_check_sli_ndlp(struct lpfc_hba *, struct lpfc_sli_ring *,
+		    struct lpfc_iocbq *, struct lpfc_nodelist *);
+int lpfc_nlp_remove(struct lpfc_hba *, struct lpfc_nodelist *);
+void lpfc_nlp_init(struct lpfc_hba *, struct lpfc_nodelist *, uint32_t);
+struct lpfc_nodelist *lpfc_setup_disc_node(struct lpfc_hba *, uint32_t);
+struct lpfc_nodelist *lpfc_setup_rscn_node(struct lpfc_hba *, uint32_t);
+void lpfc_disc_list_loopmap(struct lpfc_hba *);
+void lpfc_disc_start(struct lpfc_hba *);
+void lpfc_disc_flush_list(struct lpfc_hba *);
+void lpfc_establish_link_tmo(unsigned long);
+void lpfc_disc_timeout(unsigned long);
+void lpfc_scan_timeout(unsigned long);
+struct lpfc_target *lpfc_find_target(struct lpfc_hba *, uint32_t,
+			struct lpfc_nodelist *);
+void lpfc_set_failmask(struct lpfc_hba *, struct lpfc_nodelist *, uint32_t,
+		       uint32_t);
+void lpfc_process_nodev_timeout(struct lpfc_hba *, struct lpfc_nodelist *);
+
+struct lpfc_nodelist *lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi);
+struct lpfc_nodelist *lpfc_findnode_remove_rpi(struct lpfc_hba * phba,
+					       uint16_t rpi);
+void lpfc_addnode_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
+		      uint16_t rpi);
+
+int lpfc_discq_post_event(struct lpfc_hba *, void *, void *, uint32_t);
+int lpfc_do_dpc(void *);
+void lpfc_evt_iocb_free(struct lpfc_hba *, struct lpfc_iocbq *);
+int lpfc_disc_state_machine(struct lpfc_hba *, struct lpfc_nodelist *, void *,
+			    uint32_t);
+
+uint32_t lpfc_cmpl_prli_reglogin_issue(struct lpfc_hba *,
+				       struct lpfc_nodelist *, void *,
+				       uint32_t);
+uint32_t lpfc_cmpl_plogi_prli_issue(struct lpfc_hba *, struct lpfc_nodelist *,
+				    void *, uint32_t);
+
+int lpfc_check_sparm(struct lpfc_hba *, struct lpfc_nodelist *,
+		     struct serv_parm *, uint32_t);
+int lpfc_els_abort(struct lpfc_hba *, struct lpfc_nodelist * ndlp,
+		   int);
+int lpfc_els_abort_flogi(struct lpfc_hba *);
+int lpfc_initial_flogi(struct lpfc_hba *);
+void lpfc_more_plogi(struct lpfc_hba *);
+int lpfc_issue_els_plogi(struct lpfc_hba *, struct lpfc_nodelist *, uint8_t);
+int lpfc_issue_els_prli(struct lpfc_hba *, struct lpfc_nodelist *, uint8_t);
+int lpfc_issue_els_adisc(struct lpfc_hba *, struct lpfc_nodelist *, uint8_t);
+int lpfc_issue_els_logo(struct lpfc_hba *, struct lpfc_nodelist *, uint8_t);
+int lpfc_issue_els_scr(struct lpfc_hba *, uint32_t, uint8_t);
+int lpfc_els_free_iocb(struct lpfc_hba *, struct lpfc_iocbq *);
+int lpfc_els_rsp_acc(struct lpfc_hba *, uint32_t, struct lpfc_iocbq *,
+		     struct lpfc_nodelist *, LPFC_MBOXQ_t *, uint8_t);
+int lpfc_els_rsp_reject(struct lpfc_hba *, uint32_t, struct lpfc_iocbq *,
+			struct lpfc_nodelist *);
+int lpfc_els_rsp_adisc_acc(struct lpfc_hba *, struct lpfc_iocbq *,
+			   struct lpfc_nodelist *);
+int lpfc_els_rsp_prli_acc(struct lpfc_hba *, struct lpfc_iocbq *,
+			  struct lpfc_nodelist *);
+void lpfc_els_retry_delay(unsigned long);
+void lpfc_els_retry_delay_handler(struct lpfc_nodelist *);
+void lpfc_els_unsol_event(struct lpfc_hba *, struct lpfc_sli_ring *,
+			  struct lpfc_iocbq *);
+int lpfc_els_handle_rscn(struct lpfc_hba *);
+int lpfc_els_flush_rscn(struct lpfc_hba *);
+int lpfc_rscn_payload_check(struct lpfc_hba *, uint32_t);
+void lpfc_els_flush_cmd(struct lpfc_hba *);
+int lpfc_els_disc_adisc(struct lpfc_hba *);
+int lpfc_els_disc_plogi(struct lpfc_hba *);
+void lpfc_els_timeout(unsigned long);
+void lpfc_els_timeout_handler(struct lpfc_hba *);
+
+void lpfc_ct_unsol_event(struct lpfc_hba *, struct lpfc_sli_ring *,
+			 struct lpfc_iocbq *);
+int lpfc_ns_cmd(struct lpfc_hba *, struct lpfc_nodelist *, int);
+int lpfc_fdmi_cmd(struct lpfc_hba *, struct lpfc_nodelist *, int);
+void lpfc_fdmi_tmo(unsigned long);
+void lpfc_fdmi_tmo_handler(struct lpfc_hba *);
+
+int lpfc_config_port_prep(struct lpfc_hba *);
+int lpfc_config_port_post(struct lpfc_hba *);
+int lpfc_hba_down_prep(struct lpfc_hba *);
+void lpfc_handle_eratt(struct lpfc_hba *, uint32_t);
+void lpfc_handle_latt(struct lpfc_hba *);
+void lpfc_hba_init(struct lpfc_hba *, uint32_t *);
+int lpfc_post_buffer(struct lpfc_hba *, struct lpfc_sli_ring *, int, int);
+void lpfc_cleanup(struct lpfc_hba *, uint32_t);
+int lpfc_scsi_free(struct lpfc_hba *);
+void lpfc_decode_firmware_rev(struct lpfc_hba *, char *, int);
+uint8_t *lpfc_get_lpfchba_info(struct lpfc_hba *, uint8_t *);
+int lpfc_fcp_abort(struct lpfc_hba *, int, int, int);
+int lpfc_put_event(struct lpfc_hba *, uint32_t, uint32_t, void *,
+		       uint32_t, uint32_t);
+int lpfc_online(struct lpfc_hba *);
+int lpfc_offline(struct lpfc_hba *);
+
+
+
+int lpfc_sli_queue_setup(struct lpfc_hba *);
+void lpfc_slim_access(struct lpfc_hba *);
+
+void lpfc_handle_eratt(struct lpfc_hba *, uint32_t);
+void lpfc_handle_latt(struct lpfc_hba *);
+irqreturn_t lpfc_intr_handler(int, void *, struct pt_regs *);
+
+void lpfc_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *);
+void lpfc_config_ring(struct lpfc_hba *, int, LPFC_MBOXQ_t *);
+void lpfc_config_port(struct lpfc_hba *, LPFC_MBOXQ_t *);
+void lpfc_mbox_put(struct lpfc_hba *, LPFC_MBOXQ_t *);
+LPFC_MBOXQ_t *lpfc_mbox_get(struct lpfc_hba *);
+
+int lpfc_mem_alloc(struct lpfc_hba *);
+void lpfc_mem_free(struct lpfc_hba *);
+
+struct lpfc_iocbq *
+lpfc_prep_els_iocb(struct lpfc_hba * phba,
+		   uint8_t expectRsp,
+		   uint16_t cmdSize,
+		   uint8_t retry, struct lpfc_nodelist * ndlp, uint32_t elscmd);
+
+int lpfc_sli_hba_setup(struct lpfc_hba *);
+int lpfc_sli_hba_down(struct lpfc_hba *);
+int lpfc_sli_intr(struct lpfc_hba *);
+int lpfc_sli_issue_mbox(struct lpfc_hba *, LPFC_MBOXQ_t *, uint32_t);
+void lpfc_sli_def_mbox_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
+int lpfc_sli_issue_iocb(struct lpfc_hba *, struct lpfc_sli_ring *,
+			struct lpfc_iocbq *, uint32_t);
+void lpfc_sli_pcimem_bcopy(uint32_t *, uint32_t *, uint32_t);
+int lpfc_sli_ringpostbuf_put(struct lpfc_hba *, struct lpfc_sli_ring *,
+			     struct lpfc_dmabuf *);
+struct lpfc_dmabuf *lpfc_sli_ringpostbuf_get(struct lpfc_hba *,
+					     struct lpfc_sli_ring *,
+					     dma_addr_t);
+uint32_t lpfc_sli_next_iotag(struct lpfc_hba *, struct lpfc_sli_ring *);
+int lpfc_sli_issue_abort_iotag32(struct lpfc_hba *, struct lpfc_sli_ring *,
+				 struct lpfc_iocbq *);
+int lpfc_sli_abort_iocb_ctx(struct lpfc_hba *, struct lpfc_sli_ring *,
+			    uint32_t);
+int lpfc_sli_sum_iocb_host(struct lpfc_hba *, struct lpfc_sli_ring *);
+int lpfc_sli_abort_iocb_host(struct lpfc_hba *, struct lpfc_sli_ring *, int);
+int lpfc_sli_sum_iocb_lun(struct lpfc_hba *, struct lpfc_sli_ring *, uint16_t,
+			  uint64_t);
+int lpfc_sli_abort_iocb_lun(struct lpfc_hba *, struct lpfc_sli_ring *, uint16_t,
+			    uint64_t, int);
+int lpfc_sli_abort_iocb_tgt(struct lpfc_hba *, struct lpfc_sli_ring *,
+			    uint16_t, int);
+void lpfc_mbox_timeout(unsigned long);
+void lpfc_mbox_timeout_handler(struct lpfc_hba *);
+void lpfc_map_fcp_cmnd_to_bpl(struct lpfc_hba *, struct lpfc_scsi_buf *);
+void lpfc_free_scsi_cmd(struct lpfc_scsi_buf *);
+uint32_t lpfc_os_timeout_transform(struct lpfc_hba *, uint32_t);
+
+struct lpfc_nodelist *
+lpfc_findnode_wwpn(struct lpfc_hba * phba, uint32_t order,
+		   struct lpfc_name * wwpn);
+struct lpfc_nodelist *
+lpfc_findnode_wwnn(struct lpfc_hba * phba, uint32_t order,
+		   struct lpfc_name * wwnn);
+struct lpfc_nodelist *lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order,
+					uint32_t did);
+
+int lpfc_sli_issue_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq,
+			 uint32_t timeout);
+
+int
+lpfc_sli_issue_iocb_wait(struct lpfc_hba * phba,
+			 struct lpfc_sli_ring * pring,
+			 struct lpfc_iocbq * piocb,
+			 struct lpfc_iocbq * prspiocbq, uint32_t timeout);
+int lpfc_sli_issue_iocb_wait_high_priority(struct lpfc_hba * phba,
+					   struct lpfc_sli_ring * pring,
+					   struct lpfc_iocbq * piocb,
+					   uint32_t flag,
+					   struct lpfc_iocbq * prspiocbq);
+void lpfc_sli_wake_iocb_high_priority(struct lpfc_hba * phba,
+				      struct lpfc_iocbq * queue1,
+				      struct lpfc_iocbq * queue2);
+void lpfc_sli_abort_fcp_cmpl(struct lpfc_hba * phba,
+				      struct lpfc_iocbq * cmdiocb,
+				      struct lpfc_iocbq * rspiocb);
+void *lpfc_mbuf_alloc(struct lpfc_hba *, int, dma_addr_t *);
+void lpfc_mbuf_free(struct lpfc_hba *, void *, dma_addr_t);
+
+int  lpfc_stop_timer(struct lpfc_hba *);
+
+
+/* Function prototypes. */
+int lpfc_queuecommand(struct scsi_cmnd *, void (*done) (struct scsi_cmnd *));
+int lpfc_abort_handler(struct scsi_cmnd *);
+int lpfc_reset_bus_handler(struct scsi_cmnd *);
+int lpfc_reset_lun_handler(struct scsi_cmnd *);
+void lpfc_free_scsi_buf(struct lpfc_scsi_buf *);
+
+#if defined(RHEL_FC) || defined(SLES_FC)
+void lpfc_target_unblock(struct lpfc_hba *, struct lpfc_target *);
+void lpfc_target_block(struct lpfc_hba *, struct lpfc_target *);
+int lpfc_target_remove(struct lpfc_hba *, struct lpfc_target *);
+int lpfc_target_add(struct lpfc_hba *, struct lpfc_target *);
+#endif
+
+#define ScsiResult(host_code, scsi_code) (((host_code) << 16) | scsi_code)
+#define HBA_EVENT_RSCN                   5
+#define HBA_EVENT_LINK_UP                2
+#define HBA_EVENT_LINK_DOWN              3
+#endif				/* _H_LPFC_CRTN */
--- linux-2.6.8.1-t044-driver-update//drivers/scsi/lpfc/lpfc_els.c	1970-01-01 03:00:00.000000000 +0300
+++ rhel4u2//drivers/scsi/lpfc/lpfc_els.c	2005-10-19 11:47:17.000000000 +0400
@@ -0,0 +1,3152 @@
+/*******************************************************************
+ * This file is part of the Emulex Linux Device Driver for         *
+ * Fibre Channel Host Bus Adapters.                                *
+ * Copyright (C) 2003-2005 Emulex.  All rights reserved.           *
+ * EMULEX and SLI are trademarks of Emulex.                        *
+ * www.emulex.com                                                  *
+ *                                                                 *
+ * This program is free software; you can redistribute it and/or   *
+ * modify it under the terms of version 2 of the GNU General       *
+ * Public License as published by the Free Software Foundation.    *
+ * This program is distributed in the hope that it will be useful. *
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
+ * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
+ * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
+ * more details, a copy of which can be found in the file COPYING  *
+ * included with this package.                                     *
+ *******************************************************************/
+
+/*
+ * $Id: lpfc_els.c 1.165.2.3 2005/07/08 19:33:28EDT sf_support Exp  $
+ */
+#include <linux/version.h>
+#include <linux/blkdev.h>
+#include <linux/dma-mapping.h>
+#include <linux/pci.h>
+#include <linux/spinlock.h>
+#include <scsi/scsi_device.h>
+#include <scsi/scsi_host.h>
+#include "lpfc_sli.h"
+#include "lpfc_disc.h"
+#include "lpfc_scsi.h"
+#include "lpfc.h"
+#include "lpfc_crtn.h"
+#include "lpfc_hw.h"
+#include "lpfc_logmsg.h"
+#include "lpfc_mem.h"
+
+
+static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
+			  struct lpfc_iocbq *);
+static int lpfc_max_els_tries = 3;
+
+static int
+lpfc_els_chk_latt(struct lpfc_hba * phba)
+{
+	struct lpfc_sli *psli;
+	LPFC_MBOXQ_t *mbox;
+	uint32_t ha_copy;
+
+	psli = &phba->sli;
+
+	if ((phba->hba_state < LPFC_HBA_READY) &&
+		(phba->hba_state != LPFC_LINK_DOWN)) {
+
+		/* Read the HBA Host Attention Register */
+		ha_copy = readl(phba->HAregaddr);
+
+		if (ha_copy & HA_LATT) {	/* Link Attention interrupt */
+
+			/* Pending Link Event during Discovery */
+			lpfc_printf_log(phba, KERN_WARNING, LOG_DISCOVERY,
+					"%d:0237 Pending Link Event during "
+					"Discovery: State x%x\n",
+					phba->brd_no, phba->hba_state);
+
+			/* CLEAR_LA should re-enable link attention events and
+			 * we should then imediately take a LATT event. The
+			 * LATT processing should call lpfc_linkdown() which
+			 * will cleanup any left over in-progress discovery
+			 * events.
+			 */
+			phba->fc_flag |= FC_ABORT_DISCOVERY;
+
+			if (phba->hba_state != LPFC_CLEAR_LA) {
+				if ((mbox = mempool_alloc(phba->mbox_mem_pool,
+							  GFP_ATOMIC))) {
+					phba->hba_state = LPFC_CLEAR_LA;
+					lpfc_clear_la(phba, mbox);
+					mbox->mbox_cmpl =
+					    lpfc_mbx_cmpl_clear_la;
+					if (lpfc_sli_issue_mbox
+					    (phba, mbox,
+					     (MBX_NOWAIT | MBX_STOP_IOCB))
+					    == MBX_NOT_FINISHED) {
+						mempool_free(mbox,
+						     phba->mbox_mem_pool);
+						phba->hba_state =
+						    LPFC_HBA_ERROR;
+					}
+				}
+			}
+			return (1);
+		}
+	}
+
+	return (0);
+}
+
+struct lpfc_iocbq *
+lpfc_prep_els_iocb(struct lpfc_hba * phba,
+		   uint8_t expectRsp,
+		   uint16_t cmdSize,
+		   uint8_t retry, struct lpfc_nodelist * ndlp, uint32_t elscmd)
+{
+	struct lpfc_sli *psli;
+	struct lpfc_sli_ring *pring;
+	struct lpfc_iocbq *elsiocb;
+	struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
+	struct ulp_bde64 *bpl;
+	IOCB_t *icmd;
+	uint32_t tag;
+
+	psli = &phba->sli;
+	pring = &psli->ring[LPFC_ELS_RING];	/* ELS ring */
+
+	if (phba->hba_state < LPFC_LINK_UP)
+		return  NULL;
+
+
+	/* Allocate buffer for  command iocb */
+	elsiocb = mempool_alloc(phba->iocb_mem_pool, GFP_ATOMIC);
+	if (!elsiocb)
+		return NULL;
+
+	memset(elsiocb, 0, sizeof (struct lpfc_iocbq));
+	icmd = &elsiocb->iocb;
+
+	/* fill in BDEs for command */
+	/* Allocate buffer for command payload */
+	if (((pcmd = kmalloc(sizeof (struct lpfc_dmabuf), GFP_ATOMIC)) == 0) ||
+	    ((pcmd->virt = lpfc_mbuf_alloc(phba,
+					   MEM_PRI, &(pcmd->phys))) == 0)) {
+		if (pcmd)
+			kfree(pcmd);
+		mempool_free( elsiocb, phba->iocb_mem_pool);
+		return NULL;
+	}
+
+	INIT_LIST_HEAD(&pcmd->list);
+
+	/* Allocate buffer for response payload */
+	if (expectRsp) {
+		prsp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_ATOMIC);
+		if (prsp)
+			prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
+						     &prsp->phys);
+		if (prsp == 0 || prsp->virt == 0) {
+			if (prsp)
+				kfree(prsp);
+			lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
+			kfree(pcmd);
+			mempool_free( elsiocb, phba->iocb_mem_pool);
+			return NULL;
+		}
+		INIT_LIST_HEAD(&prsp->list);
+	} else {
+		prsp = NULL;
+	}
+
+	/* Allocate buffer for Buffer ptr list */
+	pbuflist = kmalloc(sizeof (struct lpfc_dmabuf), GFP_ATOMIC);
+	if (pbuflist)
+	    pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
+					     &pbuflist->phys);
+	if (pbuflist == 0 || pbuflist->virt == 0) {
+		mempool_free( elsiocb, phba->iocb_mem_pool);
+		lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
+		lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
+		kfree(pcmd);
+		kfree(prsp);
+		if (pbuflist)
+			kfree(pbuflist);
+		return NULL;
+	}
+
+	INIT_LIST_HEAD(&pbuflist->list);
+
+	icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
+	icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
+	icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
+	if (expectRsp) {
+		icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof (struct ulp_bde64));
+		icmd->un.elsreq64.remoteID = ndlp->nlp_DID;	/* DID */
+		icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
+	} else {
+		icmd->un.elsreq64.bdl.bdeSize = sizeof (struct ulp_bde64);
+		icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
+	}
+
+	/* NOTE: we don't use ulpIoTag0 because it is a t2 structure */
+	tag = lpfc_sli_next_iotag(phba, pring);
+	icmd->ulpIoTag = (uint16_t)(tag & 0xffff);
+	icmd->un.elsreq64.bdl.ulpIoTag32 = tag;
+	icmd->ulpBdeCount = 1;
+	icmd->ulpLe = 1;
+	icmd->ulpClass = CLASS3;
+
+	bpl = (struct ulp_bde64 *) pbuflist->virt;
+	bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
+	bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
+	bpl->tus.f.bdeSize = cmdSize;
+	bpl->tus.f.bdeFlags = 0;
+	bpl->tus.w = le32_to_cpu(bpl->tus.w);
+
+	if (expectRsp) {
+		bpl++;
+		bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
+		bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
+		bpl->tus.f.bdeSize = FCELSSIZE;
+		bpl->tus.f.bdeFlags = BUFF_USE_RCV;
+		bpl->tus.w = le32_to_cpu(bpl->tus.w);
+	}
+
+	/* Save for completion so we can release these resources */
+	elsiocb->context1 = (uint8_t *) ndlp;
+	elsiocb->context2 = (uint8_t *) pcmd;
+	elsiocb->context3 = (uint8_t *) pbuflist;
+	elsiocb->retry = retry;
+	elsiocb->drvrTimeout = (phba->fc_ratov * 2) + LPFC_DRVR_TIMEOUT;
+
+	if (prsp) {
+		list_add(&prsp->list, &pcmd->list);
+	}
+
+	if (expectRsp) {
+		/* Xmit ELS command <elsCmd> to remote NPORT <did> */
+		lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
+				"%d:0116 Xmit ELS command x%x to remote "
+				"NPORT x%x Data: x%x x%x\n",
+				phba->brd_no, elscmd,
+				ndlp->nlp_DID, icmd->ulpIoTag, phba->hba_state);
+	} else {
+		/* Xmit ELS response <elsCmd> to remote NPORT <did> */
+		lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
+				"%d:0117 Xmit ELS response x%x to remote "
+				"NPORT x%x Data: x%x x%x\n",
+				phba->brd_no, elscmd,
+				ndlp->nlp_DID, icmd->ulpIoTag, cmdSize);
+	}
+
+	return (elsiocb);
+}
+
+static void
+lpfc_cmpl_els_flogi(struct lpfc_hba * phba,
+		    struct lpfc_iocbq * cmdiocb, struct lpfc_iocbq * rspiocb)
+{
+	IOCB_t *irsp;
+	struct lpfc_dmabuf *pcmd, *prsp;
+	struct serv_parm *sp;
+	uint32_t *lp;
+	LPFC_MBOXQ_t *mbox;
+	struct lpfc_sli *psli;
+	struct lpfc_nodelist *ndlp;
+	int rc;
+
+	psli = &phba->sli;
+	irsp = &(rspiocb->iocb);
+	ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
+	pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
+
+	/* Check to see if link went down during discovery */
+	if (lpfc_els_chk_latt(phba)) {
+		lpfc_nlp_remove(phba, ndlp);
+		goto out;
+	}
+
+	if (irsp->ulpStatus) {
+		/* FLOGI failure */
+		lpfc_printf_log(phba,
+				KERN_INFO,
+				LOG_ELS,
+				"%d:0100 FLOGI failure Data: x%x x%x\n",
+				phba->brd_no,
+				irsp->ulpStatus, irsp->un.ulpWord[4]);
+
+		/* Check for retry */
+		if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
+			/* ELS command is being retried */
+			goto out;
+		}
+		/* FLOGI failed, so there is no fabric */
+		phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
+
+		/* If private loop, then allow max outstandting els to be
+		 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
+		 * alpa map would take too long otherwise.
+		 */
+		if (phba->alpa_map[0] == 0) {
+			phba->cfg_discovery_threads =
+			    LPFC_MAX_DISC_THREADS;
+		}
+
+	} else {
+		/* The FLogI succeeded.  Sync the data for the CPU before
+		 * accessing it.
+		 */
+		prsp = (struct lpfc_dmabuf *) pcmd->list.next;
+		lp = (uint32_t *) prsp->virt;
+
+		sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
+
+		/* FLOGI completes successfully */
+		lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
+				"%d:0101 FLOGI completes sucessfully "
+				"Data: x%x x%x x%x x%x\n",
+				phba->brd_no,
+				irsp->un.ulpWord[4], sp->cmn.e_d_tov,
+				sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
+
+		if (phba->hba_state == LPFC_FLOGI) {
+			/* If Common Service Parameters indicate Nport
+			 * we are point to point, if Fport we are Fabric.
+			 */
+			if (sp->cmn.fPort) {
+				phba->fc_flag |= FC_FABRIC;
+				if (sp->cmn.edtovResolution) {
+					/* E_D_TOV ticks are in nanoseconds */
+					phba->fc_edtov =
+					    (be32_to_cpu(sp->cmn.e_d_tov) +
+					     999999) / 1000000;
+				} else {
+					/* E_D_TOV ticks are in milliseconds */
+					phba->fc_edtov =
+					    be32_to_cpu(sp->cmn.e_d_tov);
+				}
+				phba->fc_ratov =
+				    (be32_to_cpu(sp->cmn.w2.r_a_tov) +
+				     999) / 1000;
+
+				if (phba->fc_topology == TOPOLOGY_LOOP) {
+					phba->fc_flag |= FC_PUBLIC_LOOP;
+				} else {
+					/* If we are a N-port connected to a
+					 * Fabric, fixup sparam's so logins to
+					 * devices on remote loops work.
+					 */
+					phba->fc_sparam.cmn.altBbCredit = 1;
+				}
+
+				phba->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
+
+				memcpy(&ndlp->nlp_portname, &sp->portName,
+				       sizeof (struct lpfc_name));
+				memcpy(&ndlp->nlp_nodename, &sp->nodeName,
+				       sizeof (struct lpfc_name));
+				memcpy(&phba->fc_fabparam, sp,
+				       sizeof (struct serv_parm));
+				if ((mbox = mempool_alloc(phba->mbox_mem_pool,
+							  GFP_ATOMIC)) == 0) {
+					goto flogifail;
+				}
+				phba->hba_state = LPFC_FABRIC_CFG_LINK;
+				lpfc_config_link(phba, mbox);
+				mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
+				if (lpfc_sli_issue_mbox
+				    (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB))
+				    == MBX_NOT_FINISHED) {
+					mempool_free(mbox, phba->mbox_mem_pool);
+					goto flogifail;
+				}
+
+				if ((mbox = mempool_alloc(phba->mbox_mem_pool,
+							  GFP_ATOMIC)) == 0) {
+					goto flogifail;
+				}
+				if (lpfc_reg_login(phba, Fabric_DID,
+						   (uint8_t *) sp, mbox,
+						   0) == 0) {
+					/* set_slim mailbox command needs to
+					 * execute first, queue this command to
+					 * be processed later.
+					 */
+					mbox->mbox_cmpl =
+					    lpfc_mbx_cmpl_fabric_reg_login;
+					mbox->context2 = ndlp;
+					if (lpfc_sli_issue_mbox
+					    (phba, mbox,
+					     (MBX_NOWAIT | MBX_STOP_IOCB))
+					    == MBX_NOT_FINISHED) {
+						mempool_free(mbox,
+						     phba->mbox_mem_pool);
+						goto flogifail;
+					}
+				} else {
+					mempool_free(mbox, phba->mbox_mem_pool);
+					goto flogifail;
+				}
+			} else {
+				/* We FLOGIed into an NPort, initiate pt2pt
+				   protocol */
+				phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
+				phba->fc_edtov = FF_DEF_EDTOV;
+				phba->fc_ratov = FF_DEF_RATOV;
+				rc = memcmp(&phba->fc_portname, &sp->portName,
+					    sizeof(struct lpfc_name));
+				if (rc >= 0) {
+					/* This side will initiate the PLOGI */
+					phba->fc_flag |= FC_PT2PT_PLOGI;
+
+					/* N_Port ID cannot be 0, set our to
+					 * LocalID the other side will be
+					 * RemoteID.
+					 */
+
+					/* not equal */
+					if (rc)
+						phba->fc_myDID = PT2PT_LocalID;
+
+					if ((mbox =
+					     mempool_alloc(phba->mbox_mem_pool,
+							   GFP_ATOMIC))
+					    == 0) {
+						goto flogifail;
+					}
+					lpfc_config_link(phba, mbox);
+					mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
+					if (lpfc_sli_issue_mbox
+					    (phba, mbox,
+					     (MBX_NOWAIT | MBX_STOP_IOCB))
+					    == MBX_NOT_FINISHED) {
+						mempool_free(mbox,
+						     phba->mbox_mem_pool);
+						goto flogifail;
+					}
+					mempool_free( ndlp, phba->nlp_mem_pool);
+
+					if ((ndlp =
+					     lpfc_findnode_did(phba,
+							       NLP_SEARCH_ALL,
+							       PT2PT_RemoteID))
+					    == 0) {
+						/* Cannot find existing Fabric
+						   ndlp, so allocate a new
+						   one */
+						if ((ndlp =
+						     mempool_alloc(
+							   phba->nlp_mem_pool,
+							   GFP_ATOMIC)) == 0) {
+							goto flogifail;
+						}
+						lpfc_nlp_init(phba, ndlp,
+							PT2PT_RemoteID);
+					}
+					memcpy(&ndlp->nlp_portname,
+					       &sp->portName,
+					       sizeof (struct lpfc_name));
+					memcpy(&ndlp->nlp_nodename,
+					       &sp->nodeName,
+					       sizeof (struct lpfc_name));
+					ndlp->nlp_state = NLP_STE_NPR_NODE;
+					lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
+					ndlp->nlp_flag |= NLP_NPR_2B_DISC;
+				}
+				else {
+					/* This side will wait for the PLOGI */
+					mempool_free( ndlp, phba->nlp_mem_pool);
+				}
+
+				phba->fc_flag |= FC_PT2PT;
+
+				/* Start discovery - this should just do
+				   CLEAR_LA */
+				lpfc_disc_start(phba);
+			}
+			goto out;
+		}
+	}
+
+flogifail:
+	lpfc_nlp_remove(phba, ndlp);
+
+	if((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
+	   ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
+	   (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) {
+
+		/* FLOGI failed, so just use loop map to make discovery list */
+		lpfc_disc_list_loopmap(phba);
+
+		/* Start discovery */
+		lpfc_disc_start(phba);
+	}
+
+out:
+	lpfc_els_free_iocb(phba, cmdiocb);
+	return;
+}
+
+static int
+lpfc_issue_els_flogi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
+		     uint8_t retry)
+{
+	struct serv_parm *sp;
+	IOCB_t *icmd;
+	struct lpfc_iocbq *elsiocb;
+	struct lpfc_sli_ring *pring;
+	struct lpfc_sli *psli;
+	uint8_t *pcmd;
+	uint16_t cmdsize;
+	uint32_t tmo;
+
+	psli = &phba->sli;
+	pring = &psli->ring[LPFC_ELS_RING];	/* ELS ring */
+
+	cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm));
+	if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
+					  ndlp, ELS_CMD_FLOGI)) == 0) {
+		return (1);
+	}
+
+	icmd = &elsiocb->iocb;
+	pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
+
+	/* For FLOGI request, remainder of payload is service parameters */
+	*((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
+	pcmd += sizeof (uint32_t);
+	memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
+	sp = (struct serv_parm *) pcmd;
+
+	/* Setup CSPs accordingly for Fabric */
+	sp->cmn.e_d_tov = 0;
+	sp->cmn.w2.r_a_tov = 0;
+	sp->cls1.classValid = 0;
+	sp->cls2.seqDelivery = 1;
+	sp->cls3.seqDelivery = 1;
+	if (sp->cmn.fcphLow < FC_PH3)
+		sp->cmn.fcphLow = FC_PH3;
+	if (sp->cmn.fcphHigh < FC_PH3)
+		sp->cmn.fcphHigh = FC_PH3;
+
+	tmo = phba->fc_ratov;
+	phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
+	lpfc_set_disctmo(phba);
+	phba->fc_ratov = tmo;
+
+	phba->fc_stat.elsXmitFLOGI++;
+	elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
+	if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
+		lpfc_els_free_iocb(phba, elsiocb);
+		return (1);
+	}
+	return (0);
+}
+
+int
+lpfc_els_abort_flogi(struct lpfc_hba * phba)
+{
+	struct lpfc_sli *psli;
+	struct lpfc_sli_ring *pring;
+	struct lpfc_iocbq *iocb, *next_iocb;
+	struct lpfc_nodelist *ndlp;
+	IOCB_t *icmd;
+	struct list_head *curr, *next;
+
+	/* Abort outstanding I/O on NPort <nlp_DID> */
+	lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
+			"%d:0201 Abort outstanding I/O on NPort x%x\n",
+			phba->brd_no, Fabric_DID);
+
+	psli = &phba->sli;
+	pring = &psli->ring[LPFC_ELS_RING];
+
+	/* check the txcmplq */
+	list_for_each_safe(curr, next, &pring->txcmplq) {
+		next_iocb = list_entry(curr, struct lpfc_iocbq, list);
+		iocb = next_iocb;
+		/* Check to see if iocb matches the nport we are
+		   looking for */
+		icmd = &iocb->iocb;
+		if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
+			ndlp = (struct lpfc_nodelist *)(iocb->context1);
+			if(ndlp && (ndlp->nlp_DID == Fabric_DID)) {
+				/* It matches, so deque and call compl
+				   with an error */
+				list_del(&iocb->list);
+				pring->txcmplq_cnt--;
+
+				if ((icmd->un.elsreq64.bdl.ulpIoTag32)) {
+					lpfc_sli_issue_abort_iotag32
+					    (phba, pring, iocb);
+				}
+				if (iocb->iocb_cmpl) {
+					icmd->ulpStatus =
+					    IOSTAT_LOCAL_REJECT;
+					icmd->un.ulpWord[4] =
+					    IOERR_SLI_ABORTED;
+					(iocb->iocb_cmpl) (phba, iocb, iocb);
+				} else {
+					mempool_free(iocb, phba->iocb_mem_pool);
+				}
+			}
+		}
+	}
+	return (0);
+}
+
+int
+lpfc_initial_flogi(struct lpfc_hba * phba)
+{
+	struct lpfc_nodelist *ndlp;
+
+	/* First look for Fabric ndlp on the unmapped list */
+
+	if ((ndlp =
+	     lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
+			       Fabric_DID)) == 0) {
+		/* Cannot find existing Fabric ndlp, so allocate a new one */
+		if ((ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC))
+		    == 0) {
+			return (0);
+		}
+		lpfc_nlp_init(phba, ndlp, Fabric_DID);
+	}
+	else {
+		phba->fc_unmap_cnt--;
+		list_del(&ndlp->nlp_listp);
+		ndlp->nlp_flag &= ~NLP_LIST_MASK;
+	}
+	if (lpfc_issue_els_flogi(phba, ndlp, 0)) {
+		mempool_free( ndlp, phba->nlp_mem_pool);
+	}
+	return (1);
+}
+
+void
+lpfc_more_plogi(struct lpfc_hba * phba)
+{
+	int sentplogi;
+
+	if (phba->num_disc_nodes)
+		phba->num_disc_nodes--;
+
+	/* Continue discovery with <num_disc_nodes> PLOGIs to go */
+	lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
+			"%d:0232 Continue discovery with %d PLOGIs to go "
+			"Data: x%x x%x x%x\n",
+			phba->brd_no, phba->num_disc_nodes, phba->fc_plogi_cnt,
+			phba->fc_flag, phba->hba_state);
+
+	/* Check to see if there are more PLOGIs to be sent */
+	if (phba->fc_flag & FC_NLP_MORE) {
+		/* go thru NPR list and issue any remaining ELS PLOGIs */
+		sentplogi = lpfc_els_disc_plogi(phba);
+	}
+	return;
+}
+
+static void
+lpfc_cmpl_els_plogi(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
+		    struct lpfc_iocbq * rspiocb)
+{
+	IOCB_t *irsp;
+	struct lpfc_sli *psli;
+	struct lpfc_nodelist *ndlp;
+	int disc, rc, did, type;
+	struct lpfc_nodelist *curr_ndlp, *next_ndlp;
+	int valid_ndlp = 0;
+
+	psli = &phba->sli;
+
+	/* we pass cmdiocb to state machine which needs rspiocb as well */
+	cmdiocb->context_un.rsp_iocb = rspiocb;
+
+	irsp = &rspiocb->iocb;
+	ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
+
+	list_for_each_entry_safe(curr_ndlp, next_ndlp, &phba->fc_plogi_list,
+				 nlp_listp) {
+		if (curr_ndlp == ndlp ) {
+			valid_ndlp =1;
+			break;
+		}
+	}
+	if (!valid_ndlp)
+		goto out;
+
+	ndlp->nlp_flag &= ~NLP_PLOGI_SND;
+
+	/* Since ndlp can be freed in the disc state machine, note if this node
+	 * is being used during discovery.
+	 */
+	disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
+	rc   = 0;
+
+	/* PLOGI completes to NPort <nlp_DID> */
+	lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
+			"%d:0102 PLOGI completes to NPort x%x "
+			"Data: x%x x%x x%x x%x\n",
+			phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
+			irsp->un.ulpWord[4], disc, phba->num_disc_nodes);
+
+	/* Check to see if link went down during discovery */
+	if (lpfc_els_chk_latt(phba)) {
+		ndlp->nlp_flag |= NLP_NPR_2B_DISC;
+		goto out;
+	}
+
+	/* ndlp could be freed in DSM, save these values now */
+	type = ndlp->nlp_type;
+	did = ndlp->nlp_DID;
+
+	if (irsp->ulpStatus) {
+		/* Check for retry */
+		if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
+			/* ELS command is being retried */
+			if (disc) {
+				ndlp->nlp_flag |= NLP_NPR_2B_DISC;
+			}
+			goto out;
+		}
+
+		/* PLOGI failed */
+		/* Do not call DSM for lpfc_els_abort'ed ELS cmds */
+		if((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
+		   ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
+		   (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
+			disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
+		}
+		else {
+			rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb,
+					NLP_EVT_CMPL_PLOGI);
+		}
+	} else {
+		/* Good status, call state machine */
+		rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb,
+					NLP_EVT_CMPL_PLOGI);
+	}
+
+	if(type & NLP_FABRIC) {
+		/* If we cannot login to Nameserver, kick off discovery now */
+		if ((did == NameServer_DID) && (rc == NLP_STE_FREED_NODE)) {
+			lpfc_disc_start(phba);
+		}
+		goto out;
+	}
+
+	if (disc && phba->num_disc_nodes) {
+		/* Check to see if there are more PLOGIs to be sent */
+		lpfc_more_plogi(phba);
+	}
+
+	if (rc != NLP_STE_FREED_NODE)
+		ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
+
+	if (phba->num_disc_nodes == 0) {
+		if(disc) {
+			phba->fc_flag &= ~FC_NDISC_ACTIVE;
+		}
+		lpfc_can_disctmo(phba);
+		if (phba->fc_flag & FC_RSCN_MODE) {
+			/* Check to see if more RSCNs came in while we were
+			 * processing this one.
+			 */
+			if ((phba->fc_rscn_id_cnt == 0) &&
+			    (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
+				phba->fc_flag &= ~FC_RSCN_MODE;
+			} else {
+				lpfc_els_handle_rscn(phba);
+			}
+		}
+	}
+
+out:
+	lpfc_els_free_iocb(phba, cmdiocb);
+	return;
+}
+
+int
+lpfc_issue_els_plogi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
+		     uint8_t retry)
+{
+	struct serv_parm *sp;
+	IOCB_t *icmd;
+	struct lpfc_iocbq *elsiocb;
+	struct lpfc_sli_ring *pring;
+	struct lpfc_sli *psli;
+	uint8_t *pcmd;
+	uint16_t cmdsize;
+
+	psli = &phba->sli;
+	pring = &psli->ring[LPFC_ELS_RING];	/* ELS ring */
+
+	cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm));
+	if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
+					  ndlp, ELS_CMD_PLOGI)) == 0) {
+		return (1);
+	}
+
+	icmd = &elsiocb->iocb;
+	pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
+
+	/* For PLOGI request, remainder of payload is service parameters */
+	*((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
+	pcmd += sizeof (uint32_t);
+	memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
+	sp = (struct serv_parm *) pcmd;
+
+	if (sp->cmn.fcphLow < FC_PH_4_3)
+		sp->cmn.fcphLow = FC_PH_4_3;
+
+	if (sp->cmn.fcphHigh < FC_PH3)
+		sp->cmn.fcphHigh = FC_PH3;
+
+	phba->fc_stat.elsXmitPLOGI++;
+	elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
+	ndlp->nlp_flag |= NLP_PLOGI_SND;
+	if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
+		ndlp->nlp_flag &= ~NLP_PLOGI_SND;
+		lpfc_els_free_iocb(phba, elsiocb);
+		return (1);
+	}
+	return (0);
+}
+
+static void
+lpfc_cmpl_els_prli(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
+		   struct lpfc_iocbq * rspiocb)
+{
+	IOCB_t *irsp;
+	struct lpfc_sli *psli;
+	struct lpfc_nodelist *ndlp, *curr_ndlp, *next_ndlp;
+	int valid_ndlp = 0;
+
+	psli = &phba->sli;
+	/* we pass cmdiocb to state machine which needs rspiocb as well */
+	cmdiocb->context_un.rsp_iocb = rspiocb;
+
+	irsp = &(rspiocb->iocb);
+	ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
+	phba->fc_prli_sent--;
+	list_for_each_entry_safe(curr_ndlp, next_ndlp, &phba->fc_prli_list,
+                                 nlp_listp) {
+                if (curr_ndlp == ndlp ) {
+                        valid_ndlp =1;
+                        break;
+                }
+        }
+
+        if (!valid_ndlp)
+                goto out;
+
+	ndlp->nlp_flag &= ~NLP_PRLI_SND;
+
+	/* PRLI completes to NPort <nlp_DID> */
+	lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
+			"%d:0103 PRLI completes to NPort x%x "
+			"Data: x%x x%x x%x\n",
+			phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
+			irsp->un.ulpWord[4], phba->num_disc_nodes);
+
+	/* Check to see if link went down during discovery */
+	if (lpfc_els_chk_latt(phba))
+		goto out;
+
+	if (irsp->ulpStatus) {
+		/* Check for retry */
+		if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
+			/* ELS command is being retried */
+			goto out;
+		}
+		/* PRLI failed */
+		/* Do not call DSM for lpfc_els_abort'ed ELS cmds */
+		if((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
+		   ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
+		   (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
+			goto out;
+		}
+		else {
+			lpfc_disc_state_machine(phba, ndlp, cmdiocb,
+					NLP_EVT_CMPL_PRLI);
+		}
+	} else {
+		/* Good status, call state machine */
+		lpfc_disc_state_machine(phba, ndlp, cmdiocb, NLP_EVT_CMPL_PRLI);
+	}
+
+out:
+	lpfc_els_free_iocb(phba, cmdiocb);
+	return;
+}
+
+int
+lpfc_issue_els_prli(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
+		    uint8_t retry)
+{
+	PRLI *npr;
+	IOCB_t *icmd;
+	struct lpfc_iocbq *elsiocb;
+	struct lpfc_sli_ring *pring;
+	struct lpfc_sli *psli;
+	uint8_t *pcmd;
+	uint16_t cmdsize;
+
+	psli = &phba->sli;
+	pring = &psli->ring[LPFC_ELS_RING];	/* ELS ring */
+
+	cmdsize = (sizeof (uint32_t) + sizeof (PRLI));
+	if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
+					  ndlp, ELS_CMD_PRLI)) == 0) {
+		return (1);
+	}
+
+	icmd = &elsiocb->iocb;
+	pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
+
+	/* For PRLI request, remainder of payload is service parameters */
+	memset(pcmd, 0, (sizeof (PRLI) + sizeof (uint32_t)));
+	*((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
+	pcmd += sizeof (uint32_t);
+
+	/* For PRLI, remainder of payload is PRLI parameter page */
+	npr = (PRLI *) pcmd;
+	/*
+	 * If our firmware version is 3.20 or later,
+	 * set the following bits for FC-TAPE support.
+	 */
+	if (phba->vpd.rev.feaLevelHigh >= 0x02) {
+		npr->ConfmComplAllowed = 1;
+		npr->Retry = 1;
+		npr->TaskRetryIdReq = 1;
+	}
+	npr->estabImagePair = 1;
+	npr->readXferRdyDis = 1;
+
+	/* For FCP support */
+	npr->prliType = PRLI_FCP_TYPE;
+	npr->initiatorFunc = 1;
+
+	phba->fc_stat.elsXmitPRLI++;
+	elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
+	ndlp->nlp_flag |= NLP_PRLI_SND;
+	if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
+		ndlp->nlp_flag &= ~NLP_PRLI_SND;
+		lpfc_els_free_iocb(phba, elsiocb);
+		return (1);
+	}
+	phba->fc_prli_sent++;
+	return (0);
+}
+
+static void
+lpfc_more_adisc(struct lpfc_hba * phba)
+{
+	int sentadisc;
+
+	if (phba->num_disc_nodes)
+		phba->num_disc_nodes--;
+
+	/* Continue discovery with <num_disc_nodes> ADISCs to go */
+	lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
+			"%d:0210 Continue discovery with %d ADISCs to go "
+			"Data: x%x x%x x%x\n",
+			phba->brd_no, phba->num_disc_nodes, phba->fc_adisc_cnt,
+			phba->fc_flag, phba->hba_state);
+
+	/* Check to see if there are more ADISCs to be sent */
+	if (phba->fc_flag & FC_NLP_MORE) {
+		lpfc_set_disctmo(phba);
+
+		/* go thru NPR list and issue any remaining ELS ADISCs */
+		sentadisc = lpfc_els_disc_adisc(phba);
+	}
+	return;
+}
+
+static void
+lpfc_rscn_disc(struct lpfc_hba * phba)
+{
+	/* RSCN discovery */
+	/* go thru NPR list and issue ELS PLOGIs */
+	if (phba->fc_npr_cnt) {
+		if (lpfc_els_disc_plogi(phba))
+			return;
+	}
+	if (phba->fc_flag & FC_RSCN_MODE) {
+		/* Check to see if more RSCNs came in while we were
+		 * processing this one.
+		 */
+		if ((phba->fc_rscn_id_cnt == 0) &&
+		    (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
+			phba->fc_flag &= ~FC_RSCN_MODE;
+		} else {
+			lpfc_els_handle_rscn(phba);
+		}
+	}
+}
+
+static void
+lpfc_cmpl_els_adisc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
+		    struct lpfc_iocbq * rspiocb)
+{
+	IOCB_t *irsp;
+	struct lpfc_sli *psli;
+	struct lpfc_nodelist *ndlp;
+	LPFC_MBOXQ_t *mbox;
+	int disc;
+
+	psli = &phba->sli;
+
+	/* we pass cmdiocb to state machine which needs rspiocb as well */
+	cmdiocb->context_un.rsp_iocb = rspiocb;
+
+	irsp = &(rspiocb->iocb);
+	ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
+	ndlp->nlp_flag &= ~NLP_ADISC_SND;
+
+	/* Since ndlp can be freed in the disc state machine, note if this node
+	 * is being used during discovery.
+	 */
+	disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
+
+	/* ADISC completes to NPort <nlp_DID> */
+	lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
+			"%d:0104 ADISC completes to NPort x%x "
+			"Data: x%x x%x x%x x%x\n",
+			phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
+			irsp->un.ulpWord[4], disc, phba->num_disc_nodes);
+
+	/* Check to see if link went down during discovery */
+	if (lpfc_els_chk_latt(phba)) {
+		ndlp->nlp_flag |= NLP_NPR_2B_DISC;
+		goto out;
+	}
+
+	if (irsp->ulpStatus) {
+		/* Check for retry */
+		if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
+			/* ELS command is being retried */
+			if (disc) {
+				ndlp->nlp_flag |= NLP_NPR_2B_DISC;
+			}
+			goto out;
+		}
+		/* ADISC failed */
+		/* Do not call DSM for lpfc_els_abort'ed ELS cmds */
+		if((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
+		   ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
+		   (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
+			disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
+		}
+		else {
+			lpfc_disc_state_machine(phba, ndlp, cmdiocb,
+					NLP_EVT_CMPL_ADISC);
+		}
+	} else {
+		/* Good status, call state machine */
+		lpfc_disc_state_machine(phba, ndlp, cmdiocb,
+					NLP_EVT_CMPL_ADISC);
+	}
+
+	if (disc && phba->num_disc_nodes) {
+		/* Check to see if there are more ADISCs to be sent */
+		lpfc_more_adisc(phba);
+
+		/* Check to see if we are done with ADISC authentication */
+		if (phba->num_disc_nodes == 0) {
+			lpfc_can_disctmo(phba);
+			/* If we get here, there is nothing left to wait for */
+			if ((phba->hba_state < LPFC_HBA_READY) &&
+			    (phba->hba_state != LPFC_CLEAR_LA)) {
+				/* Link up discovery */
+				if ((mbox = mempool_alloc(phba->mbox_mem_pool,
+							  GFP_ATOMIC))) {
+					phba->hba_state = LPFC_CLEAR_LA;
+					lpfc_clear_la(phba, mbox);
+					mbox->mbox_cmpl =
+					    lpfc_mbx_cmpl_clear_la;
+					if (lpfc_sli_issue_mbox
+					    (phba, mbox,
+					     (MBX_NOWAIT | MBX_STOP_IOCB))
+					    == MBX_NOT_FINISHED) {
+						mempool_free(mbox,
+						     phba->mbox_mem_pool);
+						lpfc_disc_flush_list(phba);
+						psli->ring[(psli->ip_ring)].
+						    flag &=
+						    ~LPFC_STOP_IOCB_EVENT;
+						psli->ring[(psli->fcp_ring)].
+						    flag &=
+						    ~LPFC_STOP_IOCB_EVENT;
+						psli->ring[(psli->next_ring)].
+						    flag &=
+						    ~LPFC_STOP_IOCB_EVENT;
+						phba->hba_state =
+						    LPFC_HBA_READY;
+					}
+				}
+			} else {
+				lpfc_rscn_disc(phba);
+			}
+		}
+	}
+	ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
+out:
+	lpfc_els_free_iocb(phba, cmdiocb);
+	return;
+}
+
+int
+lpfc_issue_els_adisc(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
+		     uint8_t retry)
+{
+	ADISC *ap;
+	IOCB_t *icmd;
+	struct lpfc_iocbq *elsiocb;
+	struct lpfc_sli_ring *pring;
+	struct lpfc_sli *psli;
+	uint8_t *pcmd;
+	uint16_t cmdsize;
+
+	psli = &phba->sli;
+	pring = &psli->ring[LPFC_ELS_RING];	/* ELS ring */
+
+	cmdsize = (sizeof (uint32_t) + sizeof (ADISC));
+	if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
+					  ndlp, ELS_CMD_ADISC)) == 0) {
+		return (1);
+	}
+
+	icmd = &elsiocb->iocb;
+	pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
+
+	/* For ADISC request, remainder of payload is service parameters */
+	*((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
+	pcmd += sizeof (uint32_t);
+
+	/* Fill in ADISC payload */
+	ap = (ADISC *) pcmd;
+	ap->hardAL_PA = phba->fc_pref_ALPA;
+	memcpy(&ap->portName, &phba->fc_portname, sizeof (struct lpfc_name));
+	memcpy(&ap->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
+	ap->DID = be32_to_cpu(phba->fc_myDID);
+
+	phba->fc_stat.elsXmitADISC++;
+	elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
+	ndlp->nlp_flag |= NLP_ADISC_SND;
+	if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
+		ndlp->nlp_flag &= ~NLP_ADISC_SND;
+		lpfc_els_free_iocb(phba, elsiocb);
+		return (1);
+	}
+	return (0);
+}
+
+static void
+lpfc_cmpl_els_logo(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
+		   struct lpfc_iocbq * rspiocb)
+{
+	IOCB_t *irsp;
+	struct lpfc_sli *psli;
+	struct lpfc_nodelist *ndlp;
+
+	psli = &phba->sli;
+	/* we pass cmdiocb to state machine which needs rspiocb as well */
+	cmdiocb->context_un.rsp_iocb = rspiocb;
+
+	irsp = &(rspiocb->iocb);
+	ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
+	ndlp->nlp_flag &= ~NLP_LOGO_SND;
+
+	/* LOGO completes to NPort <nlp_DID> */
+	lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
+			"%d:0105 LOGO completes to NPort x%x "
+			"Data: x%x x%x x%x\n",
+			phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
+			irsp->un.ulpWord[4], phba->num_disc_nodes);
+
+	/* Check to see if link went down during discovery */
+	if (lpfc_els_chk_latt(phba))
+		goto out;
+
+	if (irsp->ulpStatus) {
+		/* Check for retry */
+		if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
+			/* ELS command is being retried */
+			goto out;
+		}
+		/* LOGO failed */
+		/* Do not call DSM for lpfc_els_abort'ed ELS cmds */
+		if((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
+		   ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
+		   (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
+			goto out;
+		}
+		else {
+			lpfc_disc_state_machine(phba, ndlp, cmdiocb,
+					NLP_EVT_CMPL_LOGO);
+		}
+	} else {
+		/* Good status, call state machine */
+		lpfc_disc_state_machine(phba, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
+
+		if(ndlp->nlp_flag & NLP_DELAY_TMO) {
+			lpfc_unreg_rpi(phba, ndlp);
+		}
+	}
+
+out:
+	lpfc_els_free_iocb(phba, cmdiocb);
+	return;
+}
+
+int
+lpfc_issue_els_logo(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
+		    uint8_t retry)
+{
+	IOCB_t *icmd;
+	struct lpfc_iocbq *elsiocb;
+	struct lpfc_sli_ring *pring;
+	struct lpfc_sli *psli;
+	uint8_t *pcmd;
+	uint16_t cmdsize;
+
+	psli = &phba->sli;
+	pring = &psli->ring[LPFC_ELS_RING];
+
+	cmdsize = 2 * (sizeof (uint32_t) + sizeof (struct lpfc_name));
+	if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
+					  ndlp, ELS_CMD_LOGO)) == 0) {
+		return (1);
+	}
+
+	icmd = &elsiocb->iocb;
+	pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
+	*((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
+	pcmd += sizeof (uint32_t);
+
+	/* Fill in LOGO payload */
+	*((uint32_t *) (pcmd)) = be32_to_cpu(phba->fc_myDID);
+	pcmd += sizeof (uint32_t);
+	memcpy(pcmd, &phba->fc_portname, sizeof (struct lpfc_name));
+
+	phba->fc_stat.elsXmitLOGO++;
+	elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
+	ndlp->nlp_flag |= NLP_LOGO_SND;
+	if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
+		ndlp->nlp_flag &= ~NLP_LOGO_SND;
+		lpfc_els_free_iocb(phba, elsiocb);
+		return (1);
+	}
+	return (0);
+}
+
+static void
+lpfc_cmpl_els_cmd(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
+		  struct lpfc_iocbq * rspiocb)
+{
+	IOCB_t *irsp;
+
+	irsp = &rspiocb->iocb;
+
+	/* ELS cmd tag <ulpIoTag> completes */
+	lpfc_printf_log(phba,
+			KERN_INFO,
+			LOG_ELS,
+			"%d:0106 ELS cmd tag x%x completes Data: x%x x%x\n",
+			phba->brd_no,
+			irsp->ulpIoTag, irsp->ulpStatus, irsp->un.ulpWord[4]);
+
+	/* Check to see if link went down during discovery */
+	lpfc_els_chk_latt(phba);
+	lpfc_els_free_iocb(phba, cmdiocb);
+	return;
+}
+
+int
+lpfc_issue_els_scr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
+{
+	IOCB_t *icmd;
+	struct lpfc_iocbq *elsiocb;
+	struct lpfc_sli_ring *pring;
+	struct lpfc_sli *psli;
+	uint8_t *pcmd;
+	uint16_t cmdsize;
+	struct lpfc_nodelist *ndlp;
+
+	psli = &phba->sli;
+	pring = &psli->ring[LPFC_ELS_RING];	/* ELS ring */
+	cmdsize = (sizeof (uint32_t) + sizeof (SCR));
+	if ((ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC)) == 0) {
+		return (1);
+	}
+
+	lpfc_nlp_init(phba, ndlp, nportid);
+
+	if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
+					  ndlp, ELS_CMD_SCR)) == 0) {
+		mempool_free( ndlp, phba->nlp_mem_pool);
+		return (1);
+	}
+
+	icmd = &elsiocb->iocb;
+	pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
+
+	*((uint32_t *) (pcmd)) = ELS_CMD_SCR;
+	pcmd += sizeof (uint32_t);
+
+	/* For SCR, remainder of payload is SCR parameter page */
+	memset(pcmd, 0, sizeof (SCR));
+	((SCR *) pcmd)->Function = SCR_FUNC_FULL;
+
+	phba->fc_stat.elsXmitSCR++;
+	elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
+	if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
+		mempool_free( ndlp, phba->nlp_mem_pool);
+		lpfc_els_free_iocb(phba, elsiocb);
+		return (1);
+	}
+	mempool_free( ndlp, phba->nlp_mem_pool);
+	return (0);
+}
+
+static int
+lpfc_issue_els_farpr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
+{
+	IOCB_t *icmd;
+	struct lpfc_iocbq *elsiocb;
+	struct lpfc_sli_ring *pring;
+	struct lpfc_sli *psli;
+	FARP *fp;
+	uint8_t *pcmd;
+	uint32_t *lp;
+	uint16_t cmdsize;
+	struct lpfc_nodelist *ondlp;
+	struct lpfc_nodelist *ndlp;
+
+	psli = &phba->sli;
+	pring = &psli->ring[LPFC_ELS_RING];	/* ELS ring */
+	cmdsize = (sizeof (uint32_t) + sizeof (FARP));
+	if ((ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC)) == 0) {
+		return (1);
+	}
+	lpfc_nlp_init(phba, ndlp, nportid);
+
+	if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
+					  ndlp, ELS_CMD_RNID)) == 0) {
+		mempool_free( ndlp, phba->nlp_mem_pool);
+		return (1);
+	}
+
+	icmd = &elsiocb->iocb;
+	pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
+
+	*((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
+	pcmd += sizeof (uint32_t);
+
+	/* Fill in FARPR payload */
+	fp = (FARP *) (pcmd);
+	memset(fp, 0, sizeof (FARP));
+	lp = (uint32_t *) pcmd;
+	*lp++ = be32_to_cpu(nportid);
+	*lp++ = be32_to_cpu(phba->fc_myDID);
+	fp->Rflags = 0;
+	fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
+
+	memcpy(&fp->RportName, &phba->fc_portname, sizeof (struct lpfc_name));
+	memcpy(&fp->RnodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
+	if ((ondlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, nportid))) {
+		memcpy(&fp->OportName, &ondlp->nlp_portname,
+		       sizeof (struct lpfc_name));
+		memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
+		       sizeof (struct lpfc_name));
+	}
+
+	phba->fc_stat.elsXmitFARPR++;
+	elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
+	if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
+		mempool_free( ndlp, phba->nlp_mem_pool);
+		lpfc_els_free_iocb(phba, elsiocb);
+		return (1);
+	}
+	mempool_free( ndlp, phba->nlp_mem_pool);
+	return (0);
+}
+
+void
+lpfc_els_retry_delay(unsigned long ptr)
+{
+	struct lpfc_nodelist *ndlp;
+	struct lpfc_hba *phba;
+	unsigned long iflag;
+	LPFC_DISC_EVT_t  *evtp;
+
+	ndlp = (struct lpfc_nodelist *)ptr;
+	phba = ndlp->nlp_phba;
+	evtp = &ndlp->els_retry_evt;
+
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+	if (!list_empty(&evtp->evt_listp)) {
+		spin_unlock_irqrestore(phba->host->host_lock, iflag);
+		return;
+	}
+
+	evtp->evt_arg1  = ndlp;
+	evtp->evt       = LPFC_EVT_ELS_RETRY;
+	list_add_tail(&evtp->evt_listp, &phba->dpc_disc);
+	if (phba->dpc_wait)
+		up(phba->dpc_wait);
+
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+	return;
+}
+
+void
+lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
+{
+	struct lpfc_hba *phba;
+	uint32_t cmd;
+	uint32_t did;
+	uint8_t retry;
+
+	phba = ndlp->nlp_phba;
+	spin_lock_irq(phba->host->host_lock);
+	did = (uint32_t) (ndlp->nlp_DID);
+	cmd = (uint32_t) (ndlp->nlp_last_elscmd);
+
+	if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
+		spin_unlock_irq(phba->host->host_lock);
+		return;
+	}
+
+	ndlp->nlp_flag &= ~NLP_DELAY_TMO;
+	retry = ndlp->nlp_retry;
+
+	switch (cmd) {
+	case ELS_CMD_FLOGI:
+		lpfc_issue_els_flogi(phba, ndlp, retry);
+		break;
+	case ELS_CMD_PLOGI:
+		ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
+		lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
+		lpfc_issue_els_plogi(phba, ndlp, retry);
+		break;
+	case ELS_CMD_ADISC:
+		ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
+		lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
+		lpfc_issue_els_adisc(phba, ndlp, retry);
+		break;
+	case ELS_CMD_PRLI:
+		ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
+		lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
+		lpfc_issue_els_prli(phba, ndlp, retry);
+		break;
+	case ELS_CMD_LOGO:
+		ndlp->nlp_state = NLP_STE_NPR_NODE;
+		lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
+		lpfc_issue_els_logo(phba, ndlp, retry);
+		break;
+	}
+	spin_unlock_irq(phba->host->host_lock);
+	return;
+}
+
+static int
+lpfc_els_retry(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
+	       struct lpfc_iocbq * rspiocb)
+{
+	IOCB_t *irsp;
+	struct lpfc_dmabuf *pcmd;
+	struct lpfc_nodelist *ndlp;
+	uint32_t *elscmd;
+	struct ls_rjt stat;
+	int retry, maxretry;
+	int delay;
+	uint32_t cmd;
+
+	retry = 0;
+	delay = 0;
+	maxretry = lpfc_max_els_tries;
+	irsp = &rspiocb->iocb;
+	ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
+	pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
+	cmd = 0;
+	/* Note: context2 may be 0 for internal driver abort
+	 * of delays ELS command.
+	 */
+
+	if (pcmd && pcmd->virt) {
+		elscmd = (uint32_t *) (pcmd->virt);
+		cmd = *elscmd++;
+	}
+
+	switch (irsp->ulpStatus) {
+	case IOSTAT_FCP_RSP_ERROR:
+	case IOSTAT_REMOTE_STOP:
+		break;
+
+	case IOSTAT_LOCAL_REJECT:
+		switch ((irsp->un.ulpWord[4] & 0xff)) {
+		case IOERR_LOOP_OPEN_FAILURE:
+			if (cmd == ELS_CMD_PLOGI) {
+				if (cmdiocb->retry == 0) {
+					delay = 1;
+				}
+			}
+			retry = 1;
+			break;
+
+		case IOERR_SEQUENCE_TIMEOUT:
+			retry = 1;
+			if ((cmd == ELS_CMD_FLOGI)
+			    && (phba->fc_topology != TOPOLOGY_LOOP)) {
+				maxretry = 48;
+			}
+			break;
+
+		case IOERR_NO_RESOURCES:
+			if (cmd == ELS_CMD_PLOGI) {
+				delay = 1;
+			}
+			retry = 1;
+			break;
+
+		case IOERR_INVALID_RPI:
+			retry = 1;
+			break;
+		}
+		break;
+
+	case IOSTAT_NPORT_RJT:
+	case IOSTAT_FABRIC_RJT:
+		if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
+			retry = 1;
+			break;
+		}
+		break;
+
+	case IOSTAT_NPORT_BSY:
+	case IOSTAT_FABRIC_BSY:
+		retry = 1;
+		break;
+
+	case IOSTAT_LS_RJT:
+		stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
+		/* Added for Vendor specifc support
+		 * Just keep retrying for these Rsn / Exp codes
+		 */
+		switch (stat.un.b.lsRjtRsnCode) {
+		case LSRJT_UNABLE_TPC:
+			if (stat.un.b.lsRjtRsnCodeExp ==
+			    LSEXP_CMD_IN_PROGRESS) {
+				if (cmd == ELS_CMD_PLOGI) {
+					delay = 1;
+					maxretry = 48;
+				}
+				retry = 1;
+				break;
+			}
+			if (cmd == ELS_CMD_PLOGI) {
+				delay = 1;
+				retry = 1;
+				break;
+			}
+			break;
+
+		case LSRJT_LOGICAL_BSY:
+			if (cmd == ELS_CMD_PLOGI) {
+				delay = 1;
+				maxretry = 48;
+			}
+			retry = 1;
+			break;
+		}
+		break;
+
+	case IOSTAT_INTERMED_RSP:
+	case IOSTAT_BA_RJT:
+		break;
+
+	default:
+		break;
+	}
+
+	if (ndlp->nlp_DID == FDMI_DID) {
+		retry = 1;
+	}
+
+	if ((++cmdiocb->retry) >= maxretry) {
+		phba->fc_stat.elsRetryExceeded++;
+		retry = 0;
+	}
+
+	if (retry) {
+
+		/* Retry ELS command <elsCmd> to remote NPORT <did> */
+		lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
+				"%d:0107 Retry ELS command x%x to remote "
+				"NPORT x%x Data: x%x x%x\n",
+				phba->brd_no,
+				cmd, ndlp->nlp_DID, cmdiocb->retry, delay);
+
+		if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) {
+			/* If discovery / RSCN timer is running, reset it */
+			if (timer_pending(&phba->fc_disctmo) ||
+			      (phba->fc_flag & FC_RSCN_MODE)) {
+				lpfc_set_disctmo(phba);
+			}
+		}
+
+		phba->fc_stat.elsXmitRetry++;
+		if (delay) {
+			phba->fc_stat.elsDelayRetry++;
+			ndlp->nlp_retry = cmdiocb->retry;
+
+			mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
+			ndlp->nlp_flag |= NLP_DELAY_TMO;
+
+			ndlp->nlp_state = NLP_STE_NPR_NODE;
+			lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
+			ndlp->nlp_last_elscmd = cmd;
+
+			return (1);
+		}
+		switch (cmd) {
+		case ELS_CMD_FLOGI:
+			lpfc_issue_els_flogi(phba, ndlp, cmdiocb->retry);
+			return (1);
+		case ELS_CMD_PLOGI:
+			ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
+			lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
+			lpfc_issue_els_plogi(phba, ndlp, cmdiocb->retry);
+			return (1);
+		case ELS_CMD_ADISC:
+			ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
+			lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
+			lpfc_issue_els_adisc(phba, ndlp, cmdiocb->retry);
+			return (1);
+		case ELS_CMD_PRLI:
+			ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
+			lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
+			lpfc_issue_els_prli(phba, ndlp, cmdiocb->retry);
+			return (1);
+		case ELS_CMD_LOGO:
+			ndlp->nlp_state = NLP_STE_NPR_NODE;
+			lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
+			lpfc_issue_els_logo(phba, ndlp, cmdiocb->retry);
+			return (1);
+		}
+	}
+
+	/* No retry ELS command <elsCmd> to remote NPORT <did> */
+	lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
+			"%d:0108 No retry ELS command x%x to remote NPORT x%x "
+			"Data: x%x x%x\n",
+			phba->brd_no,
+			cmd, ndlp->nlp_DID, cmdiocb->retry, ndlp->nlp_flag);
+
+	return (0);
+}
+
+int
+lpfc_els_free_iocb(struct lpfc_hba * phba, struct lpfc_iocbq * elsiocb)
+{
+	struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
+
+	/* context2  = cmd,  context2->next = rsp, context3 = bpl */
+	if (elsiocb->context2) {
+		buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
+		/* Free the response before processing the command.  */
+		if (!list_empty(&buf_ptr1->list)) {
+			buf_ptr = list_entry(buf_ptr1->list.next,
+					     struct lpfc_dmabuf, list);
+			lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
+			kfree(buf_ptr);
+		}
+		lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
+		kfree(buf_ptr1);
+	}
+
+	if (elsiocb->context3) {
+		buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
+		lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
+		kfree(buf_ptr);
+	}
+
+	mempool_free( elsiocb, phba->iocb_mem_pool);
+	return 0;
+}
+
+static void
+lpfc_cmpl_els_logo_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
+		       struct lpfc_iocbq * rspiocb)
+{
+	struct lpfc_nodelist *ndlp;
+
+	ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
+
+	/* ACC to LOGO completes to NPort <nlp_DID> */
+	lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
+			"%d:0109 ACC to LOGO completes to NPort x%x "
+			"Data: x%x x%x x%x\n",
+			phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
+			ndlp->nlp_state, ndlp->nlp_rpi);
+
+	ndlp->nlp_flag &= ~NLP_LOGO_ACC;
+
+	switch (ndlp->nlp_state) {
+	case NLP_STE_UNUSED_NODE:	/* node is just allocated */
+		lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
+		break;
+	case NLP_STE_NPR_NODE:		/* NPort Recovery mode */
+		lpfc_unreg_rpi(phba, ndlp);
+		break;
+	default:
+		break;
+	}
+	lpfc_els_free_iocb(phba, cmdiocb);
+	return;
+}
+
+static void
+lpfc_cmpl_els_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
+		  struct lpfc_iocbq * rspiocb)
+{
+	struct lpfc_nodelist *ndlp;
+	LPFC_MBOXQ_t *mbox = NULL;
+
+	ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
+	if (cmdiocb->context_un.mbox)
+		mbox = cmdiocb->context_un.mbox;
+
+
+	/* Check to see if link went down during discovery */
+	if ((lpfc_els_chk_latt(phba)) || !ndlp) {
+		if (mbox) {
+			mempool_free( mbox, phba->mbox_mem_pool);
+		}
+		goto out;
+	}
+
+	/* ELS response tag <ulpIoTag> completes */
+	lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
+			"%d:0110 ELS response tag x%x completes "
+			"Data: x%x x%x x%x x%x x%x x%x\n",
+			phba->brd_no,
+			cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
+			rspiocb->iocb.un.ulpWord[4], ndlp->nlp_DID,
+			ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
+
+	if (mbox) {
+		if ((rspiocb->iocb.ulpStatus == 0)
+		    && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
+			/* set_slim mailbox command needs to execute first,
+			 * queue this command to be processed later.
+			 */
+			lpfc_unreg_rpi(phba, ndlp);
+			mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
+			mbox->context2 = ndlp;
+			ndlp->nlp_state = NLP_STE_REG_LOGIN_ISSUE;
+			lpfc_nlp_list(phba, ndlp, NLP_REGLOGIN_LIST);
+			if (lpfc_sli_issue_mbox(phba, mbox,
+						(MBX_NOWAIT | MBX_STOP_IOCB))
+			    != MBX_NOT_FINISHED) {
+				goto out;
+			}
+			/* NOTE: we should have messages for unsuccessful
+			   reglogin */
+			mempool_free( mbox, phba->mbox_mem_pool);
+		} else {
+			mempool_free( mbox, phba->mbox_mem_pool);
+			if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
+				lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
+			}
+		}
+	}
+out:
+	if(ndlp)
+		ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
+	lpfc_els_free_iocb(phba, cmdiocb);
+	return;
+}
+
+int
+lpfc_els_rsp_acc(struct lpfc_hba * phba, uint32_t flag,
+		 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp,
+		 LPFC_MBOXQ_t * mbox, uint8_t newnode)
+{
+	IOCB_t *icmd;
+	IOCB_t *oldcmd;
+	struct lpfc_iocbq *elsiocb;
+	struct lpfc_sli_ring *pring;
+	struct lpfc_sli *psli;
+	uint8_t *pcmd;
+	uint16_t cmdsize;
+
+	psli = &phba->sli;
+	pring = &psli->ring[LPFC_ELS_RING];	/* ELS ring */
+	oldcmd = &oldiocb->iocb;
+
+	switch (flag) {
+	case ELS_CMD_ACC:
+		cmdsize = sizeof (uint32_t);
+		if ((elsiocb =
+		     lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
+					ndlp, ELS_CMD_ACC)) == 0) {
+			return (1);
+		}
+		icmd = &elsiocb->iocb;
+		icmd->ulpContext = oldcmd->ulpContext;	/* Xri */
+		pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
+		*((uint32_t *) (pcmd)) = ELS_CMD_ACC;
+		pcmd += sizeof (uint32_t);
+		break;
+	case ELS_CMD_PLOGI:
+		cmdsize = (sizeof (struct serv_parm) + sizeof (uint32_t));
+		if ((elsiocb =
+		     lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
+					ndlp, ELS_CMD_ACC)) == 0) {
+			return (1);
+		}
+		icmd = &elsiocb->iocb;
+		icmd->ulpContext = oldcmd->ulpContext;	/* Xri */
+		pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
+
+		if (mbox)
+			elsiocb->context_un.mbox = mbox;
+
+		*((uint32_t *) (pcmd)) = ELS_CMD_ACC;
+		pcmd += sizeof (uint32_t);
+		memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
+		break;
+	default:
+		return (1);
+	}
+
+	if (newnode)
+		elsiocb->context1 = NULL;
+
+	/* Xmit ELS ACC response tag <ulpIoTag> */
+	lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
+			"%d:0128 Xmit ELS ACC response tag x%x "
+			"Data: x%x x%x x%x x%x x%x\n",
+			phba->brd_no,
+			elsiocb->iocb.ulpIoTag,
+			elsiocb->iocb.ulpContext, ndlp->nlp_DID,
+			ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
+
+	if (ndlp->nlp_flag & NLP_LOGO_ACC) {
+		elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
+	} else {
+		elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
+	}
+
+	phba->fc_stat.elsXmitACC++;
+	if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
+		lpfc_els_free_iocb(phba, elsiocb);
+		return (1);
+	}
+	return (0);
+}
+
+int
+lpfc_els_rsp_reject(struct lpfc_hba * phba, uint32_t rejectError,
+		    struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
+{
+	IOCB_t *icmd;
+	IOCB_t *oldcmd;
+	struct lpfc_iocbq *elsiocb;
+	struct lpfc_sli_ring *pring;
+	struct lpfc_sli *psli;
+	uint8_t *pcmd;
+	uint16_t cmdsize;
+
+	psli = &phba->sli;
+	pring = &psli->ring[LPFC_ELS_RING];	/* ELS ring */
+
+	cmdsize = 2 * sizeof (uint32_t);
+	if ((elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
+					  ndlp, ELS_CMD_LS_RJT)) == 0) {
+		return (1);
+	}
+
+	icmd = &elsiocb->iocb;
+	oldcmd = &oldiocb->iocb;
+	icmd->ulpContext = oldcmd->ulpContext;	/* Xri */
+	pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
+
+	*((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
+	pcmd += sizeof (uint32_t);
+	*((uint32_t *) (pcmd)) = rejectError;
+
+	/* Xmit ELS RJT <err> response tag <ulpIoTag> */
+	lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
+			"%d:0129 Xmit ELS RJT x%x response tag x%x "
+			"Data: x%x x%x x%x x%x x%x\n",
+			phba->brd_no,
+			rejectError, elsiocb->iocb.ulpIoTag,
+			elsiocb->iocb.ulpContext, ndlp->nlp_DID,
+			ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
+
+	phba->fc_stat.elsXmitLSRJT++;
+	elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
+
+	if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
+		lpfc_els_free_iocb(phba, elsiocb);
+		return (1);
+	}
+	return (0);
+}
+
+int
+lpfc_els_rsp_adisc_acc(struct lpfc_hba * phba,
+		       struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
+{
+	ADISC *ap;
+	IOCB_t *icmd;
+	IOCB_t *oldcmd;
+	struct lpfc_iocbq *elsiocb;
+	struct lpfc_sli_ring *pring;
+	struct lpfc_sli *psli;
+	uint8_t *pcmd;
+	uint16_t cmdsize;
+
+	psli = &phba->sli;
+	pring = &psli->ring[LPFC_ELS_RING];	/* ELS ring */
+
+	cmdsize = sizeof (uint32_t) + sizeof (ADISC);
+	if ((elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
+					  ndlp, ELS_CMD_ACC)) == 0) {
+		return (1);
+	}
+
+	/* Xmit ADISC ACC response tag <ulpIoTag> */
+	lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
+			"%d:0130 Xmit ADISC ACC response tag x%x "
+			"Data: x%x x%x x%x x%x x%x\n",
+			phba->brd_no,
+			elsiocb->iocb.ulpIoTag,
+			elsiocb->iocb.ulpContext, ndlp->nlp_DID,
+			ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
+
+	icmd = &elsiocb->iocb;
+	oldcmd = &oldiocb->iocb;
+	icmd->ulpContext = oldcmd->ulpContext;	/* Xri */
+	pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
+
+	*((uint32_t *) (pcmd)) = ELS_CMD_ACC;
+	pcmd += sizeof (uint32_t);
+
+	ap = (ADISC *) (pcmd);
+	ap->hardAL_PA = phba->fc_pref_ALPA;
+	memcpy(&ap->portName, &phba->fc_portname, sizeof (struct lpfc_name));
+	memcpy(&ap->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
+	ap->DID = be32_to_cpu(phba->fc_myDID);
+
+	phba->fc_stat.elsXmitACC++;
+	elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
+
+	if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
+		lpfc_els_free_iocb(phba, elsiocb);
+		return (1);
+	}
+	return (0);
+}
+
+int
+lpfc_els_rsp_prli_acc(struct lpfc_hba * phba,
+		      struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
+{
+	PRLI *npr;
+	lpfc_vpd_t *vpd;
+	IOCB_t *icmd;
+	IOCB_t *oldcmd;
+	struct lpfc_iocbq *elsiocb;
+	struct lpfc_sli_ring *pring;
+	struct lpfc_sli *psli;
+	uint8_t *pcmd;
+	uint16_t cmdsize;
+
+	psli = &phba->sli;
+	pring = &psli->ring[LPFC_ELS_RING];	/* ELS ring */
+
+	cmdsize = sizeof (uint32_t) + sizeof (PRLI);
+	if ((elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
+					  ndlp,
+					  (ELS_CMD_ACC |
+					   (ELS_CMD_PRLI & ~ELS_RSP_MASK)))) ==
+	    0) {
+		return (1);
+	}
+
+	/* Xmit PRLI ACC response tag <ulpIoTag> */
+	lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
+			"%d:0131 Xmit PRLI ACC response tag x%x "
+			"Data: x%x x%x x%x x%x x%x\n",
+			phba->brd_no,
+			elsiocb->iocb.ulpIoTag,
+			elsiocb->iocb.ulpContext, ndlp->nlp_DID,
+			ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
+
+	icmd = &elsiocb->iocb;
+	oldcmd = &oldiocb->iocb;
+	icmd->ulpContext = oldcmd->ulpContext;	/* Xri */
+	pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
+
+	*((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
+	pcmd += sizeof (uint32_t);
+
+	/* For PRLI, remainder of payload is PRLI parameter page */
+	memset(pcmd, 0, sizeof (PRLI));
+
+	npr = (PRLI *) pcmd;
+	vpd = &phba->vpd;
+	/*
+	 * If our firmware version is 3.20 or later,
+	 * set the following bits for FC-TAPE support.
+	 */
+	if (vpd->rev.feaLevelHigh >= 0x02) {
+		npr->ConfmComplAllowed = 1;
+		npr->Retry = 1;
+		npr->TaskRetryIdReq = 1;
+	}
+
+	npr->acceptRspCode = PRLI_REQ_EXECUTED;
+	npr->estabImagePair = 1;
+	npr->readXferRdyDis = 1;
+	npr->ConfmComplAllowed = 1;
+
+	npr->prliType = PRLI_FCP_TYPE;
+	npr->initiatorFunc = 1;
+
+	phba->fc_stat.elsXmitACC++;
+	elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
+
+	if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
+		lpfc_els_free_iocb(phba, elsiocb);
+		return (1);
+	}
+	return (0);
+}
+
+static int
+lpfc_els_rsp_rnid_acc(struct lpfc_hba * phba,
+		      uint8_t format,
+		      struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
+{
+	RNID *rn;
+	IOCB_t *icmd;
+	IOCB_t *oldcmd;
+	struct lpfc_iocbq *elsiocb;
+	struct lpfc_sli_ring *pring;
+	struct lpfc_sli *psli;
+	uint8_t *pcmd;
+	uint16_t cmdsize;
+
+	psli = &phba->sli;
+	pring = &psli->ring[LPFC_ELS_RING];
+
+	cmdsize = sizeof (uint32_t) + sizeof (uint32_t)
+		+ (2 * sizeof (struct lpfc_name));
+	if (format)
+		cmdsize += sizeof (RNID_TOP_DISC);
+
+	if ((elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
+					  ndlp, ELS_CMD_ACC)) == 0) {
+		return (1);
+	}
+
+	/* Xmit RNID ACC response tag <ulpIoTag> */
+	lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
+			"%d:0132 Xmit RNID ACC response tag x%x "
+			"Data: x%x\n",
+			phba->brd_no,
+			elsiocb->iocb.ulpIoTag,
+			elsiocb->iocb.ulpContext);
+
+	icmd = &elsiocb->iocb;
+	oldcmd = &oldiocb->iocb;
+	icmd->ulpContext = oldcmd->ulpContext;	/* Xri */
+	pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
+
+	*((uint32_t *) (pcmd)) = ELS_CMD_ACC;
+	pcmd += sizeof (uint32_t);
+
+	memset(pcmd, 0, sizeof (RNID));
+	rn = (RNID *) (pcmd);
+	rn->Format = format;
+	rn->CommonLen = (2 * sizeof (struct lpfc_name));
+	memcpy(&rn->portName, &phba->fc_portname, sizeof (struct lpfc_name));
+	memcpy(&rn->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
+	switch (format) {
+	case 0:
+		rn->SpecificLen = 0;
+		break;
+	case RNID_TOPOLOGY_DISC:
+		rn->SpecificLen = sizeof (RNID_TOP_DISC);
+		memcpy(&rn->un.topologyDisc.portName,
+		       &phba->fc_portname, sizeof (struct lpfc_name));
+		rn->un.topologyDisc.unitType = RNID_HBA;
+		rn->un.topologyDisc.physPort = 0;
+		rn->un.topologyDisc.attachedNodes = 0;
+		break;
+	default:
+		rn->CommonLen = 0;
+		rn->SpecificLen = 0;
+		break;
+	}
+
+	phba->fc_stat.elsXmitACC++;
+	elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
+	elsiocb->context1 = NULL;  /* Don't need ndlp for cmpl,
+				    * it could be freed */
+
+	if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
+		lpfc_els_free_iocb(phba, elsiocb);
+		return (1);
+	}
+	return (0);
+}
+
+int
+lpfc_els_disc_adisc(struct lpfc_hba * phba)
+{
+	int sentadisc;
+	struct lpfc_nodelist *ndlp, *next_ndlp;
+
+	sentadisc = 0;
+	/* go thru NPR list and issue any remaining ELS ADISCs */
+	list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
+			nlp_listp) {
+		if(ndlp->nlp_flag & NLP_NPR_2B_DISC) {
+			if(ndlp->nlp_flag & NLP_NPR_ADISC) {
+				ndlp->nlp_flag &= ~NLP_NPR_ADISC;
+				ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
+				lpfc_nlp_list(phba, ndlp,
+					NLP_ADISC_LIST);
+				lpfc_issue_els_adisc(phba, ndlp, 0);
+				sentadisc++;
+				phba->num_disc_nodes++;
+				if (phba->num_disc_nodes >=
+				    phba->cfg_discovery_threads) {
+					phba->fc_flag |= FC_NLP_MORE;
+					break;
+				}
+			}
+		}
+	}
+	if (sentadisc == 0) {
+		phba->fc_flag &= ~FC_NLP_MORE;
+	}
+	return(sentadisc);
+}
+
+int
+lpfc_els_disc_plogi(struct lpfc_hba * phba)
+{
+	int sentplogi;
+	struct lpfc_nodelist *ndlp, *next_ndlp;
+
+	sentplogi = 0;
+	/* go thru NPR list and issue any remaining ELS PLOGIs */
+	list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
+				nlp_listp) {
+		if((ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
+		   (!(ndlp->nlp_flag & NLP_DELAY_TMO))) {
+			if(!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
+				ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
+				lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
+				lpfc_issue_els_plogi(phba, ndlp, 0);
+				sentplogi++;
+				phba->num_disc_nodes++;
+				if (phba->num_disc_nodes >=
+				    phba->cfg_discovery_threads) {
+					phba->fc_flag |= FC_NLP_MORE;
+					break;
+				}
+			}
+		}
+	}
+	if (sentplogi == 0) {
+		phba->fc_flag &= ~FC_NLP_MORE;
+	}
+	return(sentplogi);
+}
+
+int
+lpfc_els_flush_rscn(struct lpfc_hba * phba)
+{
+	struct lpfc_dmabuf *mp;
+	int i;
+
+	for (i = 0; i < phba->fc_rscn_id_cnt; i++) {
+		mp = phba->fc_rscn_id_list[i];
+		lpfc_mbuf_free(phba, mp->virt, mp->phys);
+		kfree(mp);
+		phba->fc_rscn_id_list[i] = NULL;
+	}
+	phba->fc_rscn_id_cnt = 0;
+	phba->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
+	lpfc_can_disctmo(phba);
+	return (0);
+}
+
+int
+lpfc_rscn_payload_check(struct lpfc_hba * phba, uint32_t did)
+{
+	D_ID ns_did;
+	D_ID rscn_did;
+	struct lpfc_dmabuf *mp;
+	uint32_t *lp;
+	uint32_t payload_len, cmd, i, match;
+
+	ns_did.un.word = did;
+	match = 0;
+
+	/* Never match fabric nodes for RSCNs */
+	if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
+		return(0);
+
+	/* If we are doing a FULL RSCN rediscovery, match everything */
+	if (phba->fc_flag & FC_RSCN_DISCOVERY) {
+		return (did);
+	}
+
+	for (i = 0; i < phba->fc_rscn_id_cnt; i++) {
+		mp = phba->fc_rscn_id_list[i];
+		lp = (uint32_t *) mp->virt;
+		cmd = *lp++;
+		payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */
+		payload_len -= sizeof (uint32_t);	/* take off word 0 */
+		while (payload_len) {
+			rscn_did.un.word = *lp++;
+			rscn_did.un.word = be32_to_cpu(rscn_did.un.word);
+			payload_len -= sizeof (uint32_t);
+			switch (rscn_did.un.b.resv) {
+			case 0:	/* Single N_Port ID effected */
+				if (ns_did.un.word == rscn_did.un.word) {
+					match = did;
+				}
+				break;
+			case 1:	/* Whole N_Port Area effected */
+				if ((ns_did.un.b.domain == rscn_did.un.b.domain)
+				    && (ns_did.un.b.area == rscn_did.un.b.area))
+					{
+						match = did;
+					}
+				break;
+			case 2:	/* Whole N_Port Domain effected */
+				if (ns_did.un.b.domain == rscn_did.un.b.domain)
+					{
+						match = did;
+					}
+				break;
+			case 3:	/* Whole Fabric effected */
+				match = did;
+				break;
+			default:
+				/* Unknown Identifier in RSCN list */
+				lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
+						"%d:0217 Unknown Identifier in "
+						"RSCN payload Data: x%x\n",
+						phba->brd_no, rscn_did.un.word);
+				break;
+			}
+			if (match) {
+				break;
+			}
+		}
+	}
+	return (match);
+}
+
+static int
+lpfc_rscn_recovery_check(struct lpfc_hba * phba)
+{
+	struct lpfc_nodelist *ndlp = NULL, *next_ndlp;
+	struct list_head *listp;
+	struct list_head *node_list[7];
+	int i;
+
+	/* Look at all nodes effected by pending RSCNs and move
+	 * them to NPR list.
+	 */
+	node_list[0] = &phba->fc_npr_list;  /* MUST do this list first */
+	node_list[1] = &phba->fc_nlpmap_list;
+	node_list[2] = &phba->fc_nlpunmap_list;
+	node_list[3] = &phba->fc_prli_list;
+	node_list[4] = &phba->fc_reglogin_list;
+	node_list[5] = &phba->fc_adisc_list;
+	node_list[6] = &phba->fc_plogi_list;
+	for (i = 0; i < 7; i++) {
+		listp = node_list[i];
+		if (list_empty(listp))
+			continue;
+
+		list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
+			if((lpfc_rscn_payload_check(phba, ndlp->nlp_DID))) {
+				/* part of RSCN, process this entry */
+				lpfc_set_failmask(phba, ndlp,
+					LPFC_DEV_DISCOVERY_INP,
+					LPFC_SET_BITMASK);
+
+				lpfc_disc_state_machine(phba, ndlp, NULL,
+						NLP_EVT_DEVICE_RECOVERY);
+				if(ndlp->nlp_flag & NLP_DELAY_TMO) {
+					ndlp->nlp_flag &= ~NLP_DELAY_TMO;
+					del_timer_sync(&ndlp->nlp_delayfunc);
+					
+					if (!list_empty(&ndlp->
+							els_retry_evt.evt_listp))
+						list_del_init(&ndlp->
+							      els_retry_evt.
+							      evt_listp);
+				}
+			}
+		}
+	}
+	return (0);
+}
+
+static int
+lpfc_els_rcv_rscn(struct lpfc_hba * phba,
+		  struct lpfc_iocbq * cmdiocb,
+		  struct lpfc_nodelist * ndlp, uint8_t newnode)
+{
+	struct lpfc_dmabuf *pcmd;
+	uint32_t *lp;
+	IOCB_t *icmd;
+	uint32_t payload_len, cmd;
+
+	icmd = &cmdiocb->iocb;
+	pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
+	lp = (uint32_t *) pcmd->virt;
+
+	cmd = *lp++;
+	payload_len = be32_to_cpu(cmd) & 0xffff;	/* payload length */
+	payload_len -= sizeof (uint32_t);	/* take off word 0 */
+	cmd &= ELS_CMD_MASK;
+
+	/* RSCN received */
+	lpfc_printf_log(phba,
+			KERN_INFO,
+			LOG_DISCOVERY,
+			"%d:0214 RSCN received Data: x%x x%x x%x x%x\n",
+			phba->brd_no,
+			phba->fc_flag, payload_len, *lp, phba->fc_rscn_id_cnt);
+
+	/* If we are about to begin discovery, just ACC the RSCN.
+	 * Discovery processing will satisfy it.
+	 */
+	if (phba->hba_state < LPFC_NS_QRY) {
+		lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
+								newnode);
+		return (0);
+	}
+
+	/* If we are already processing an RSCN, save the received
+	 * RSCN payload buffer, cmdiocb->context2 to process later.
+	 */
+	if (phba->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
+		if ((phba->fc_rscn_id_cnt < FC_MAX_HOLD_RSCN) &&
+		    !(phba->fc_flag & FC_RSCN_DISCOVERY)) {
+			phba->fc_flag |= FC_RSCN_MODE;
+			phba->fc_rscn_id_list[phba->fc_rscn_id_cnt++] = pcmd;
+
+			/* If we zero, cmdiocb->context2, the calling
+			 * routine will not try to free it.
+			 */
+			cmdiocb->context2 = NULL;
+
+			/* Deferred RSCN */
+			lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
+					"%d:0235 Deferred RSCN "
+					"Data: x%x x%x x%x\n",
+					phba->brd_no, phba->fc_rscn_id_cnt,
+					phba->fc_flag, phba->hba_state);
+		} else {
+			phba->fc_flag |= FC_RSCN_DISCOVERY;
+			/* ReDiscovery RSCN */
+			lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
+					"%d:0234 ReDiscovery RSCN "
+					"Data: x%x x%x x%x\n",
+					phba->brd_no, phba->fc_rscn_id_cnt,
+					phba->fc_flag, phba->hba_state);
+		}
+		/* Send back ACC */
+		lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
+								newnode);
+
+		/* send RECOVERY event for ALL nodes that match RSCN payload */
+		lpfc_rscn_recovery_check(phba);
+		return (0);
+	}
+
+	phba->fc_flag |= FC_RSCN_MODE;
+	phba->fc_rscn_id_list[phba->fc_rscn_id_cnt++] = pcmd;
+	/*
+	 * If we zero, cmdiocb->context2, the calling routine will
+	 * not try to free it.
+	 */
+	cmdiocb->context2 = NULL;
+
+	lpfc_set_disctmo(phba);
+
+	/* Send back ACC */
+	lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, newnode);
+
+	/* send RECOVERY event for ALL nodes that match RSCN payload */
+	lpfc_rscn_recovery_check(phba);
+
+	return (lpfc_els_handle_rscn(phba));
+}
+
+int
+lpfc_els_handle_rscn(struct lpfc_hba * phba)
+{
+	struct lpfc_nodelist *ndlp;
+
+	lpfc_put_event(phba, HBA_EVENT_RSCN, phba->fc_myDID,
+			  (void *)(unsigned long)(phba->fc_myDID), 0, 0);
+
+	/* Start timer for RSCN processing */
+	lpfc_set_disctmo(phba);
+
+	/* RSCN processed */
+	lpfc_printf_log(phba,
+			KERN_INFO,
+			LOG_DISCOVERY,
+			"%d:0215 RSCN processed Data: x%x x%x x%x x%x\n",
+			phba->brd_no,
+			phba->fc_flag, 0, phba->fc_rscn_id_cnt,
+			phba->hba_state);
+
+	/* To process RSCN, first compare RSCN data with NameServer */
+	phba->fc_ns_retry = 0;
+	if ((ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
+				      NameServer_DID))) {
+		/* Good ndlp, issue CT Request to NameServer */
+		if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) == 0) {
+			/* Wait for NameServer query cmpl before we can
+			   continue */
+			return (1);
+		}
+	} else {
+		/* If login to NameServer does not exist, issue one */
+		/* Good status, issue PLOGI to NameServer */
+		if ((ndlp =
+		     lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID))) {
+			/* Wait for NameServer login cmpl before we can
+			   continue */
+			return (1);
+		}
+		if ((ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC))
+		    == 0) {
+			lpfc_els_flush_rscn(phba);
+			return (0);
+		} else {
+			lpfc_nlp_init(phba, ndlp, NameServer_DID);
+			ndlp->nlp_type |= NLP_FABRIC;
+			ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
+			lpfc_issue_els_plogi(phba, ndlp, 0);
+			/* Wait for NameServer login cmpl before we can
+			   continue */
+			return (1);
+		}
+	}
+
+	lpfc_els_flush_rscn(phba);
+	return (0);
+}
+
+static int
+lpfc_els_rcv_flogi(struct lpfc_hba * phba,
+		   struct lpfc_iocbq * cmdiocb,
+		   struct lpfc_nodelist * ndlp, uint8_t newnode)
+{
+	struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
+	uint32_t *lp = (uint32_t *) pcmd->virt;
+	IOCB_t *icmd = &cmdiocb->iocb;
+	struct serv_parm *sp;
+	LPFC_MBOXQ_t *mbox;
+	struct ls_rjt stat;
+	uint32_t cmd, did;
+
+
+	cmd = *lp++;
+	sp = (struct serv_parm *) lp;
+
+	/* FLOGI received */
+
+	lpfc_set_disctmo(phba);
+
+	if (phba->fc_topology == TOPOLOGY_LOOP) {
+		/* We should never receive a FLOGI in loop mode, ignore it */
+		did = icmd->un.elsreq64.remoteID;
+
+		/* An FLOGI ELS command <elsCmd> was received from DID <did> in
+		   Loop Mode */
+		lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
+				"%d:0113 An FLOGI ELS command x%x was received "
+				"from DID x%x in Loop Mode\n",
+				phba->brd_no, cmd, did);
+		return (1);
+	}
+
+	did = Fabric_DID;
+
+	if ((lpfc_check_sparm(phba, ndlp, sp, CLASS3))) {
+		/* For a FLOGI we accept, then if our portname is greater
+		 * then the remote portname we initiate Nport login.
+		 */
+		int rc;
+
+		rc = memcmp(&phba->fc_portname, &sp->portName,
+			    sizeof (struct lpfc_name));
+
+		if (!rc) {
+			if ((mbox = mempool_alloc(phba->mbox_mem_pool,
+						  GFP_ATOMIC)) == 0) {
+				return (1);
+			}
+			lpfc_linkdown(phba);
+			lpfc_init_link(phba, mbox,
+				       phba->cfg_topology,
+				       phba->cfg_link_speed);
+			mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
+			mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
+			if (lpfc_sli_issue_mbox
+			    (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB))
+			    == MBX_NOT_FINISHED) {
+				mempool_free( mbox, phba->mbox_mem_pool);
+			}
+			return (1);
+		}
+
+		else if (rc > 0) {	/* greater than */
+			phba->fc_flag |= FC_PT2PT_PLOGI;
+		}
+		phba->fc_flag |= FC_PT2PT;
+		phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
+	} else {
+		/* Reject this request because invalid parameters */
+		stat.un.b.lsRjtRsvd0 = 0;
+		stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
+		stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
+		stat.un.b.vendorUnique = 0;
+		lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
+		return (1);
+	}
+
+	/* Send back ACC */
+	lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, newnode);
+
+	return (0);
+}
+
+static int
+lpfc_els_rcv_rnid(struct lpfc_hba * phba,
+		  struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
+{
+	struct lpfc_dmabuf *pcmd;
+	uint32_t *lp;
+	IOCB_t *icmd;
+	RNID *rn;
+	struct ls_rjt stat;
+	uint32_t cmd, did;
+
+	icmd = &cmdiocb->iocb;
+	did = icmd->un.elsreq64.remoteID;
+	pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
+	lp = (uint32_t *) pcmd->virt;
+
+	cmd = *lp++;
+	rn = (RNID *) lp;
+
+	/* RNID received */
+
+	switch (rn->Format) {
+	case 0:
+	case RNID_TOPOLOGY_DISC:
+		/* Send back ACC */
+		lpfc_els_rsp_rnid_acc(phba, rn->Format, cmdiocb, ndlp);
+		break;
+	default:
+		/* Reject this request because format not supported */
+		stat.un.b.lsRjtRsvd0 = 0;
+		stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
+		stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
+		stat.un.b.vendorUnique = 0;
+		lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
+	}
+	return (0);
+}
+
+static int
+lpfc_els_rcv_rrq(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
+		 struct lpfc_nodelist * ndlp)
+{
+	struct lpfc_dmabuf *pcmd;
+	uint32_t *lp;
+	IOCB_t *icmd;
+	struct lpfc_sli_ring *pring;
+	struct lpfc_sli *psli;
+	RRQ *rrq;
+	uint32_t cmd, did;
+
+	psli = &phba->sli;
+	pring = &psli->ring[LPFC_FCP_RING];
+	icmd = &cmdiocb->iocb;
+	did = icmd->un.elsreq64.remoteID;
+	pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
+	lp = (uint32_t *) pcmd->virt;
+
+	cmd = *lp++;
+	rrq = (RRQ *) lp;
+
+	/* RRQ received */
+	/* Get oxid / rxid from payload and abort it */
+	if ((rrq->SID == be32_to_cpu(phba->fc_myDID))) {
+		lpfc_sli_abort_iocb_ctx(phba, pring, rrq->Oxid);
+	} else {
+		lpfc_sli_abort_iocb_ctx(phba, pring, rrq->Rxid);
+	}
+	/* ACCEPT the rrq request */
+	lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
+
+	return 0;
+}
+
+static int
+lpfc_els_rcv_farp(struct lpfc_hba * phba,
+		  struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
+{
+	struct lpfc_dmabuf *pcmd;
+	uint32_t *lp;
+	IOCB_t *icmd;
+	FARP *fp;
+	uint32_t cmd, cnt, did;
+
+	icmd = &cmdiocb->iocb;
+	did = icmd->un.elsreq64.remoteID;
+	pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
+	lp = (uint32_t *) pcmd->virt;
+
+	cmd = *lp++;
+	fp = (FARP *) lp;
+
+	/* FARP-REQ received from DID <did> */
+	lpfc_printf_log(phba,
+			 KERN_INFO,
+			 LOG_ELS,
+			 "%d:0134 FARP-REQ received from DID x%x\n",
+			 phba->brd_no, did);
+
+	/* We will only support match on WWPN or WWNN */
+	if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
+		return (0);
+	}
+
+	cnt = 0;
+	/* If this FARP command is searching for my portname */
+	if (fp->Mflags & FARP_MATCH_PORT) {
+		if (memcmp(&fp->RportName, &phba->fc_portname,
+			   sizeof (struct lpfc_name)) == 0)
+			cnt = 1;
+	}
+
+	/* If this FARP command is searching for my nodename */
+	if (fp->Mflags & FARP_MATCH_NODE) {
+		if (memcmp(&fp->RnodeName, &phba->fc_nodename,
+			   sizeof (struct lpfc_name)) == 0)
+			cnt = 1;
+	}
+
+	if (cnt) {
+		if((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
+		   (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
+			/* Log back into the node before sending the FARP. */
+			if (fp->Rflags & FARP_REQUEST_PLOGI) {
+				ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
+				lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
+				lpfc_issue_els_plogi(phba, ndlp, 0);
+			}
+
+			/* Send a FARP response to that node */
+			if (fp->Rflags & FARP_REQUEST_FARPR) {
+				lpfc_issue_els_farpr(phba, did, 0);
+			}
+		}
+	}
+	return (0);
+}
+
+static int
+lpfc_els_rcv_farpr(struct lpfc_hba * phba,
+		   struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
+{
+	struct lpfc_dmabuf *pcmd;
+	uint32_t *lp;
+	IOCB_t *icmd;
+	uint32_t cmd, did;
+
+	icmd = &cmdiocb->iocb;
+	did = icmd->un.elsreq64.remoteID;
+	pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
+	lp = (uint32_t *) pcmd->virt;
+
+	cmd = *lp++;
+	/* FARP-RSP received from DID <did> */
+	lpfc_printf_log(phba,
+			 KERN_INFO,
+			 LOG_ELS,
+			 "%d:0133 FARP-RSP received from DID x%x\n",
+			 phba->brd_no, did);
+
+	/* ACCEPT the Farp resp request */
+	lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
+
+	return 0;
+}
+
+static int
+lpfc_els_rcv_fan(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
+		 struct lpfc_nodelist * ndlp)
+{
+	/* FAN received */
+	lpfc_printf_log(phba,
+			 KERN_INFO,
+			 LOG_ELS,
+			 "%d:265 FAN received\n",
+			 phba->brd_no);
+
+	return (0);
+}
+
+void
+lpfc_els_timeout(unsigned long ptr)
+{
+	struct lpfc_hba *phba;
+	unsigned long iflag;
+
+	phba = (struct lpfc_hba *)ptr;
+	if (phba == 0)
+		return;
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+	if (!(phba->work_hba_events & WORKER_ELS_TMO)) {
+		phba->work_hba_events |= WORKER_ELS_TMO;
+		if (phba->dpc_wait)
+			up(phba->dpc_wait);
+	}
+	spin_unlock_irqrestore(phba->host->host_lock, iflag);
+	return;
+}
+
+void
+lpfc_els_timeout_handler(struct lpfc_hba *phba)
+{
+	struct lpfc_sli *psli;
+	struct lpfc_sli_ring *pring;
+	struct lpfc_iocbq *tmp_iocb, *piocb;
+	IOCB_t *cmd = NULL;
+	struct lpfc_dmabuf *pcmd;
+	struct list_head *dlp;
+	uint32_t *elscmd;
+	uint32_t els_command;
+	uint32_t timeout;
+	uint32_t remote_ID;
+
+	if(phba == 0)
+		return;
+	spin_lock_irq(phba->host->host_lock);
+	/* If the timer is already canceled do nothing */
+	if (!(phba->work_hba_events & WORKER_ELS_TMO)) {
+		spin_unlock_irq(phba->host->host_lock);
+		return;
+	}
+
+	timeout = (uint32_t)(phba->fc_ratov << 1);
+
+	psli = &phba->sli;
+	pring = &psli->ring[LPFC_ELS_RING];
+	dlp = &pring->txcmplq;
+
+	list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
+		cmd = &piocb->iocb;
+
+		if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
+			continue;
+		}
+		pcmd = (struct lpfc_dmabuf *) piocb->context2;
+		elscmd = (uint32_t *) (pcmd->virt);
+		els_command = *elscmd;
+
+		if ((els_command == ELS_CMD_FARP)
+		    || (els_command == ELS_CMD_FARPR)) {
+			continue;
+		}
+
+		if (piocb->drvrTimeout > 0) {
+			if (piocb->drvrTimeout >= timeout) {
+				piocb->drvrTimeout -= timeout;
+			} else {
+				piocb->drvrTimeout = 0;
+			}
+			continue;
+		}
+
+		list_del(&piocb->list);
+		pring->txcmplq_cnt--;
+
+		if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR) {
+			struct lpfc_nodelist *ndlp;
+
+			ndlp = lpfc_findnode_rpi(phba, cmd->ulpContext);
+			remote_ID = ndlp->nlp_DID;
+			if (cmd->un.elsreq64.bdl.ulpIoTag32) {
+				lpfc_sli_issue_abort_iotag32(phba,
+					pring, piocb);
+			}
+		} else {
+			remote_ID = cmd->un.elsreq64.remoteID;
+		}
+
+		lpfc_printf_log(phba,
+				KERN_ERR,
+				LOG_ELS,
+				"%d:0127 ELS timeout Data: x%x x%x x%x x%x\n",
+				phba->brd_no, els_command,
+				remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
+
+		/*
+		 * The iocb has timed out; abort it.
+		 */
+		if (piocb->iocb_cmpl) {
+			cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
+			cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
+			(piocb->iocb_cmpl) (phba, piocb, piocb);
+		} else {
+			mempool_free(piocb, phba->iocb_mem_pool);
+		}
+	}
+
+	if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) {
+		phba->els_tmofunc.expires = jiffies + HZ * timeout;
+		add_timer(&phba->els_tmofunc);
+	}
+	spin_unlock_irq(phba->host->host_lock);
+}
+
+void
+lpfc_els_flush_cmd(struct lpfc_hba * phba)
+{
+	struct lpfc_sli *psli;
+	struct lpfc_sli_ring *pring;
+	struct lpfc_iocbq *tmp_iocb, *piocb;
+	IOCB_t *cmd = NULL;
+	struct lpfc_dmabuf *pcmd;
+	uint32_t *elscmd;
+	uint32_t els_command;
+	uint32_t remote_ID;
+
+	psli = &phba->sli;
+	pring = &psli->ring[LPFC_ELS_RING];
+
+	list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
+		cmd = &piocb->iocb;
+
+		if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
+			continue;
+		}
+
+		/* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
+		if ((cmd->ulpCommand == CMD_QUE_RING_BUF_CN) ||
+		    (cmd->ulpCommand == CMD_QUE_RING_BUF64_CN) ||
+		    (cmd->ulpCommand == CMD_CLOSE_XRI_CN) ||
+		    (cmd->ulpCommand == CMD_ABORT_XRI_CN)) {
+			continue;
+		}
+
+		pcmd = (struct lpfc_dmabuf *) piocb->context2;
+		elscmd = (uint32_t *) (pcmd->virt);
+		els_command = *elscmd;
+
+		if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR) {
+			struct lpfc_nodelist *ndlp;
+
+			ndlp = lpfc_findnode_rpi(phba, cmd->ulpContext);
+			remote_ID = ndlp->nlp_DID;
+			if (phba->hba_state == LPFC_HBA_READY) {
+				continue;
+			}
+		} else {
+			remote_ID = cmd->un.elsreq64.remoteID;
+		}
+
+		list_del(&piocb->list);
+		pring->txcmplq_cnt--;
+
+		cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
+		cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
+
+		if (piocb->iocb_cmpl) {
+			(piocb->iocb_cmpl) (phba, piocb, piocb);
+		} else {
+			mempool_free( piocb, phba->iocb_mem_pool);
+		}
+	}
+
+	list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
+		cmd = &piocb->iocb;
+
+		if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
+			continue;
+		}
+		pcmd = (struct lpfc_dmabuf *) piocb->context2;
+		elscmd = (uint32_t *) (pcmd->virt);
+		els_command = *elscmd;
+
+		if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR) {
+			struct lpfc_nodelist *ndlp;
+
+			ndlp = lpfc_findnode_rpi(phba, cmd->ulpContext);
+			remote_ID = ndlp->nlp_DID;
+			if (phba->hba_state == LPFC_HBA_READY) {
+				continue;
+			}
+		} else {
+			remote_ID = cmd->un.elsreq64.remoteID;
+		}
+
+		list_del(&piocb->list);
+		pring->txcmplq_cnt--;
+
+		cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
+		cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
+
+		if (piocb->iocb_cmpl) {
+			(piocb->iocb_cmpl) (phba, piocb, piocb);
+		} else {
+			mempool_free( piocb, phba->iocb_mem_pool);
+		}
+	}
+	return;
+}
+
+void
+lpfc_els_unsol_event(struct lpfc_hba * phba,
+		     struct lpfc_sli_ring * pring, struct lpfc_iocbq * elsiocb)
+{
+	struct lpfc_sli *psli;
+	struct lpfc_nodelist *ndlp;
+	struct lpfc_dmabuf *mp;
+	uint32_t *lp;
+	IOCB_t *icmd;
+	struct ls_rjt stat;
+	uint32_t cmd;
+	uint32_t did;
+	uint32_t newnode;
+	uint32_t drop_cmd = 0;	/* by default do NOT drop received cmd */
+	uint32_t rjt_err = 0;
+
+	psli = &phba->sli;
+	icmd = &elsiocb->iocb;
+
+	if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
+		((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
+		/* Not enough posted buffers; Try posting more buffers */
+		phba->fc_stat.NoRcvBuf++;
+		lpfc_post_buffer(phba, pring, 0, 1);
+		return;
+	}
+
+	/* If there are no BDEs associated with this IOCB,
+	 * there is nothing to do.
+	 */
+	if (icmd->ulpBdeCount == 0)
+		return;
+
+	/* type of ELS cmd is first 32bit word in packet */
+	mp = lpfc_sli_ringpostbuf_get(phba, pring, getPaddr(icmd->un.
+							    cont64[0].
+							    addrHigh,
+							    icmd->un.
+							    cont64[0].addrLow));
+	if (mp == 0) {
+		drop_cmd = 1;
+		goto dropit;
+	}
+
+	newnode = 0;
+	lp = (uint32_t *) mp->virt;
+	cmd = *lp++;
+	lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], 1, 1);
+
+	if (icmd->ulpStatus) {
+		lpfc_mbuf_free(phba, mp->virt, mp->phys);
+		kfree(mp);
+		drop_cmd = 1;
+		goto dropit;
+	}
+
+	/* Check to see if link went down during discovery */
+	if (lpfc_els_chk_latt(phba)) {
+		lpfc_mbuf_free(phba, mp->virt, mp->phys);
+		kfree(mp);
+		drop_cmd = 1;
+		goto dropit;
+	}
+
+	did = icmd->un.rcvels.remoteID;
+	if ((ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did)) == 0) {
+		/* Cannot find existing Fabric ndlp, so allocate a new one */
+		if ((ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC))
+		    == 0) {
+			lpfc_mbuf_free(phba, mp->virt, mp->phys);
+			kfree(mp);
+			drop_cmd = 1;
+			goto dropit;
+		}
+
+		lpfc_nlp_init(phba, ndlp, did);
+		newnode = 1;
+		if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
+			ndlp->nlp_type |= NLP_FABRIC;
+		}
+	}
+
+	phba->fc_stat.elsRcvFrame++;
+	elsiocb->context1 = ndlp;
+	elsiocb->context2 = mp;
+
+	if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
+		cmd &= ELS_CMD_MASK;
+	}
+	/* ELS command <elsCmd> received from NPORT <did> */
+	lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
+			"%d:0112 ELS command x%x received from NPORT x%x "
+			"Data: x%x\n", phba->brd_no, cmd, did, phba->hba_state);
+
+	switch (cmd) {
+	case ELS_CMD_PLOGI:
+		phba->fc_stat.elsRcvPLOGI++;
+		if(phba->hba_state < LPFC_DISC_AUTH) {
+			rjt_err = LSEXP_NOTHING_MORE;
+			break;
+		}
+		lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PLOGI);
+		break;
+	case ELS_CMD_FLOGI:
+		phba->fc_stat.elsRcvFLOGI++;
+		lpfc_els_rcv_flogi(phba, elsiocb, ndlp, newnode);
+		if (newnode) {
+			mempool_free( ndlp, phba->nlp_mem_pool);
+		}
+		break;
+	case ELS_CMD_LOGO:
+		phba->fc_stat.elsRcvLOGO++;
+		if(phba->hba_state < LPFC_DISC_AUTH) {
+			rjt_err = LSEXP_NOTHING_MORE;
+			break;
+		}
+		lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
+		break;
+	case ELS_CMD_PRLO:
+		phba->fc_stat.elsRcvPRLO++;
+		if(phba->hba_state < LPFC_DISC_AUTH) {
+			rjt_err = LSEXP_NOTHING_MORE;
+			break;
+		}
+		lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
+		break;
+	case ELS_CMD_RSCN:
+		phba->fc_stat.elsRcvRSCN++;
+		lpfc_els_rcv_rscn(phba, elsiocb, ndlp, newnode);
+		if (newnode) {
+			mempool_free( ndlp, phba->nlp_mem_pool);
+		}
+		break;
+	case ELS_CMD_ADISC:
+		phba->fc_stat.elsRcvADISC++;
+		if(phba->hba_state < LPFC_DISC_AUTH) {
+			rjt_err = LSEXP_NOTHING_MORE;
+			break;
+		}
+		lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_ADISC);
+		break;
+	case ELS_CMD_PDISC:
+		phba->fc_stat.elsRcvPDISC++;
+		if(phba->hba_state < LPFC_DISC_AUTH) {
+			rjt_err = LSEXP_NOTHING_MORE;
+			break;
+		}
+		lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PDISC);
+		break;
+	case ELS_CMD_FARPR:
+		phba->fc_stat.elsRcvFARPR++;
+		lpfc_els_rcv_farpr(phba, elsiocb, ndlp);
+		break;
+	case ELS_CMD_FARP:
+		phba->fc_stat.elsRcvFARP++;
+		lpfc_els_rcv_farp(phba, elsiocb, ndlp);
+		break;
+	case ELS_CMD_FAN:
+		phba->fc_stat.elsRcvFAN++;
+		lpfc_els_rcv_fan(phba, elsiocb, ndlp);
+		break;
+	case ELS_CMD_RRQ:
+		phba->fc_stat.elsRcvRRQ++;
+		lpfc_els_rcv_rrq(phba, elsiocb, ndlp);
+		break;
+	case ELS_CMD_PRLI:
+		phba->fc_stat.elsRcvPRLI++;
+		if(phba->hba_state < LPFC_DISC_AUTH) {
+			rjt_err = LSEXP_NOTHING_MORE;
+			break;
+		}
+		lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
+		break;
+	case ELS_CMD_RNID:
+		phba->fc_stat.elsRcvRNID++;
+		lpfc_els_rcv_rnid(phba, elsiocb, ndlp);
+		break;
+	default:
+		/* Unsupported ELS command, reject */
+		rjt_err = LSEXP_NOTHING_MORE;
+
+		/* Unknown ELS command <elsCmd> received from NPORT <did> */
+		lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
+				"%d:0115 Unknown ELS command x%x received from "
+				"NPORT x%x\n", phba->brd_no, cmd, did);
+		if (newnode) {
+			mempool_free( ndlp, phba->nlp_mem_pool);
+		}
+		break;
+	}
+
+	/* check if need to LS_RJT received ELS cmd */
+	if (rjt_err) {
+		stat.un.b.lsRjtRsvd0 = 0;
+		stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
+		stat.un.b.lsRjtRsnCodeExp = rjt_err;
+		stat.un.b.vendorUnique = 0;
+		lpfc_els_rsp_reject(phba, stat.un.lsRjtError, elsiocb, ndlp);
+	}
+
+	if (elsiocb->context2) {
+		lpfc_mbuf_free(phba, mp->virt, mp->phys);
+		kfree(mp);
+	}
+dropit:
+	/* check if need to drop received ELS cmd */
+	if (drop_cmd == 1) {
+		lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
+				"%d:0111 Dropping received ELS cmd "
+				"Data: x%x x%x\n", phba->brd_no,
+				icmd->ulpStatus, icmd->un.ulpWord[4]);
+		phba->fc_stat.elsRcvDrop++;
+	}
+	return;
+}
--- linux-2.6.8.1-t044-driver-update//drivers/scsi/lpfc/lpfc_ct.c	1970-01-01 03:00:00.000000000 +0300
+++ rhel4u2//drivers/scsi/lpfc/lpfc_ct.c	2005-10-19 11:47:17.000000000 +0400
@@ -0,0 +1,1235 @@
+/*******************************************************************
+ * This file is part of the Emulex Linux Device Driver for         *
+ * Fibre Channel Host Bus Adapters.                                *
+ * Copyright (C) 2003-2005 Emulex.  All rights reserved.           *
+ * EMULEX and SLI are trademarks of Emulex.                        *
+ * www.emulex.com                                                  *
+ *                                                                 *
+ * This program is free software; you can redistribute it and/or   *
+ * modify it under the terms of version 2 of the GNU General       *
+ * Public License as published by the Free Software Foundation.    *
+ * This program is distributed in the hope that it will be useful. *
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
+ * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
+ * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
+ * more details, a copy of which can be found in the file COPYING  *
+ * included with this package.                                     *
+ *******************************************************************/
+
+/*
+ * $Id: lpfc_ct.c 1.150.2.2 2005/06/13 17:16:09EDT sf_support Exp  $
+ *
+ * Fibre Channel SCSI LAN Device Driver CT support
+ */
+
+#include <linux/version.h>
+#include <linux/blkdev.h>
+#include <linux/dma-mapping.h>
+#include <linux/pci.h>
+#include <linux/spinlock.h>
+#include <linux/utsname.h>
+#include <scsi/scsi_device.h>
+#include <scsi/scsi_host.h>
+#include "lpfc_sli.h"
+#include "lpfc_disc.h"
+#include "lpfc_scsi.h"
+#include "lpfc.h"
+#include "lpfc_crtn.h"
+#include "lpfc_hw.h"
+#include "lpfc_logmsg.h"
+#include "lpfc_mem.h"
+#include "lpfc_version.h"
+
+
+#define HBA_PORTSPEED_UNKNOWN               0	/* Unknown - transceiver
+						 * incapable of reporting */
+#define HBA_PORTSPEED_1GBIT                 1	/* 1 GBit/sec */
+#define HBA_PORTSPEED_2GBIT                 2	/* 2 GBit/sec */
+#define HBA_PORTSPEED_4GBIT                 8   /* 4 GBit/sec */
+#define HBA_PORTSPEED_8GBIT                16   /* 8 GBit/sec */
+#define HBA_PORTSPEED_10GBIT                4	/* 10 GBit/sec */
+#define HBA_PORTSPEED_NOT_NEGOTIATED        5	/* Speed not established */
+
+#define FOURBYTES	4
+
+
+static char *lpfc_release_version = LPFC_DRIVER_VERSION;
+
+/*
+ * lpfc_ct_unsol_event
+ */
+void
+lpfc_ct_unsol_event(struct lpfc_hba * phba,
+		    struct lpfc_sli_ring * pring, struct lpfc_iocbq * piocbq)
+{
+
+	struct lpfc_iocbq *next_piocbq;
+	struct lpfc_dmabuf *pmbuf = NULL;
+	struct lpfc_dmabuf *matp, *next_matp;
+	uint32_t ctx = 0, size = 0, cnt = 0;
+	IOCB_t *icmd = &piocbq->iocb;
+	IOCB_t *save_icmd = icmd;
+	int i, status, go_exit = 0;
+	struct list_head head;
+
+	if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
+		((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
+		/* Not enough posted buffers; Try posting more buffers */
+		phba->fc_stat.NoRcvBuf++;
+		lpfc_post_buffer(phba, pring, 0, 1);
+		return;
+	}
+
+	/* If there are no BDEs associated with this IOCB,
+	 * there is nothing to do.
+	 */
+	if (icmd->ulpBdeCount == 0)
+		return;
+
+	INIT_LIST_HEAD(&head);
+	list_add_tail(&head, &piocbq->list);
+	list_for_each_entry_safe(piocbq, next_piocbq, &head, list) {
+		icmd = &piocbq->iocb;
+		if (ctx == 0)
+			ctx = (uint32_t) (icmd->ulpContext);
+		if (icmd->ulpBdeCount == 0)
+			continue;
+
+		for (i = 0; i < icmd->ulpBdeCount; i++) {
+			matp = lpfc_sli_ringpostbuf_get(phba, pring,
+							getPaddr(icmd->un.
+								 cont64[i].
+								 addrHigh,
+								 icmd->un.
+								 cont64[i].
+								 addrLow));
+			if (!matp) {
+				/* Insert lpfc log message here */
+				lpfc_post_buffer(phba, pring, cnt, 1);
+				go_exit = 1;
+				goto ct_unsol_event_exit_piocbq;
+			}
+
+			/* Typically for Unsolicited CT requests */
+			if (!pmbuf) {
+				pmbuf = matp;
+				INIT_LIST_HEAD(&pmbuf->list);
+			} else
+				list_add_tail(&matp->list, &pmbuf->list);
+
+			size += icmd->un.cont64[i].tus.f.bdeSize;
+			cnt++;
+		}
+
+		icmd->ulpBdeCount = 0;
+	}
+
+	lpfc_post_buffer(phba, pring, cnt, 1);
+	if (save_icmd->ulpStatus) {
+		go_exit = 1;
+	}
+ct_unsol_event_exit_piocbq:
+	list_del(&head);
+	/*
+	 * if not early-exiting and there is pmbuf,
+	 * then do  FC_REG_CT_EVENT for libdfc
+	 */
+	if (!go_exit  &&  pmbuf) {
+		status = lpfc_put_event(phba, FC_REG_CT_EVENT, ctx,
+				       (void *)pmbuf, size, 0);
+		if (status)
+			return;
+	}
+	if (pmbuf) {
+		list_for_each_entry_safe(matp, next_matp, &pmbuf->list, list) {
+			lpfc_mbuf_free(phba, matp->virt, matp->phys);
+			list_del(&matp->list);
+			kfree(matp);
+		}
+		lpfc_mbuf_free(phba, pmbuf->virt, pmbuf->phys);
+		kfree(pmbuf);
+	}
+	return;
+}
+
+static void
+lpfc_free_ct_rsp(struct lpfc_hba * phba, struct lpfc_dmabuf * mlist)
+{
+	struct lpfc_dmabuf *mlast, *next_mlast;
+
+	list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
+		lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
+		list_del(&mlast->list);
+		kfree(mlast);
+	}
+	lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
+	kfree(mlist);
+	return;
+}
+
+static struct lpfc_dmabuf *
+lpfc_alloc_ct_rsp(struct lpfc_hba * phba, int cmdcode, struct ulp_bde64 * bpl,
+		  uint32_t size, int *entries)
+{
+	struct lpfc_dmabuf *mlist = NULL;
+	struct lpfc_dmabuf *mp;
+	int cnt, i = 0;
+
+	/* We get chucks of FCELSSIZE */
+	cnt = size > FCELSSIZE ? FCELSSIZE: size;
+
+	while (size) {
+		/* Allocate buffer for rsp payload */
+		mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_ATOMIC);
+		if (!mp) {
+			if (mlist)
+				lpfc_free_ct_rsp(phba, mlist);
+			return NULL;
+		}
+
+		INIT_LIST_HEAD(&mp->list);
+
+		if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT))
+			mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
+		else
+			mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
+
+		if (!mp->virt) {
+			kfree(mp);
+			lpfc_free_ct_rsp(phba, mlist);
+			return NULL;
+		}
+
+		/* Queue it to a linked list */
+		if (!mlist)
+			mlist = mp;
+		else
+			list_add_tail(&mp->list, &mlist->list);
+
+		bpl->tus.f.bdeFlags = BUFF_USE_RCV;
+		/* build buffer ptr list for IOCB */
+		bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
+		bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
+		bpl->tus.f.bdeSize = (uint16_t) cnt;
+		bpl->tus.w = le32_to_cpu(bpl->tus.w);
+		bpl++;
+
+		i++;
+		size -= cnt;
+	}
+
+	*entries = i;
+	return mlist;
+}
+
+static int
+lpfc_gen_req(struct lpfc_hba *phba, struct lpfc_dmabuf *bmp,
+	     struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
+	     void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
+		     struct lpfc_iocbq *),
+	     struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
+	     uint32_t tmo)
+{
+
+	struct lpfc_sli *psli = &phba->sli;
+	struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
+	IOCB_t *icmd;
+	struct lpfc_iocbq *geniocb;
+
+	/* Allocate buffer for  command iocb */
+	geniocb = mempool_alloc(phba->iocb_mem_pool, GFP_ATOMIC);
+	if (!geniocb) {
+		return 1;
+	}
+	memset(geniocb, 0, sizeof (struct lpfc_iocbq));
+	icmd = &geniocb->iocb;
+
+	icmd->un.genreq64.bdl.ulpIoTag32 = 0;
+	icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
+	icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
+	icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
+	icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
+
+	if (usr_flg)
+		geniocb->context3 = NULL;
+	else
+		geniocb->context3 = (uint8_t *) bmp;
+
+	/* Save for completion so we can release these resources */
+	geniocb->context1 = (uint8_t *) inp;
+	geniocb->context2 = (uint8_t *) outp;
+
+	/* Fill in payload, bp points to frame payload */
+	icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
+
+	icmd->ulpIoTag = lpfc_sli_next_iotag(phba, pring);
+
+	/* Fill in rest of iocb */
+	icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
+	icmd->un.genreq64.w5.hcsw.Dfctl = 0;
+	icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
+	icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
+
+	if (!tmo)
+		tmo = (2 * phba->fc_ratov) + 1;
+	icmd->ulpTimeout = tmo;
+	icmd->ulpBdeCount = 1;
+	icmd->ulpLe = 1;
+	icmd->ulpClass = CLASS3;
+	icmd->ulpContext = ndlp->nlp_rpi;
+
+	/* Issue GEN REQ IOCB for NPORT <did> */
+	lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
+			"%d:0119 Issue GEN REQ IOCB for NPORT x%x "
+			"Data: x%x x%x\n", phba->brd_no, icmd->un.ulpWord[5],
+			icmd->ulpIoTag, phba->hba_state);
+	geniocb->iocb_cmpl = cmpl;
+	geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
+	if (lpfc_sli_issue_iocb(phba, pring, geniocb, 0) == IOCB_ERROR) {
+		mempool_free( geniocb, phba->iocb_mem_pool);
+		return 1;
+	}
+
+	return 0;
+}
+
+static int
+lpfc_ct_cmd(struct lpfc_hba *phba, struct lpfc_dmabuf *inmp,
+	    struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
+	    void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
+			  struct lpfc_iocbq *),
+	    uint32_t rsp_size)
+{
+	struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
+	struct lpfc_dmabuf *outmp;
+	int cnt = 0, status;
+	int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
+		CommandResponse.bits.CmdRsp;
+
+	bpl++;			/* Skip past ct request */
+
+	/* Put buffer(s) for ct rsp in bpl */
+	outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
+	if (!outmp)
+		return -ENOMEM;
+
+	status = lpfc_gen_req(phba, bmp, inmp, outmp, cmpl, ndlp, 0,
+			      cnt+1, 0);
+	if (status) {
+		lpfc_free_ct_rsp(phba, outmp);
+		return -ENOMEM;
+	}
+	return 0;
+}
+
+static int
+lpfc_ns_rsp(struct lpfc_hba * phba, struct lpfc_dmabuf * mp, uint32_t Size)
+{
+	struct lpfc_sli_ct_request *Response =
+		(struct lpfc_sli_ct_request *) mp->virt;
+	struct lpfc_nodelist *ndlp = NULL;
+	struct lpfc_dmabuf *mlast, *next_mp;
+	uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
+	uint32_t Did;
+	uint32_t CTentry;
+	int Cnt;
+	struct list_head head;
+
+	lpfc_set_disctmo(phba);
+
+	Cnt = Size  > FCELSSIZE ? FCELSSIZE : Size;
+
+	list_add_tail(&head, &mp->list);
+	list_for_each_entry_safe(mp, next_mp, &head, list) {
+		mlast = mp;
+		Size -= Cnt;
+
+		if (!ctptr)
+			ctptr = (uint32_t *) mlast->virt;
+		else
+			Cnt -= 16;	/* subtract length of CT header */
+
+		/* Loop through entire NameServer list of DIDs */
+		while (Cnt) {
+
+			/* Get next DID from NameServer List */
+			CTentry = *ctptr++;
+			Did = ((be32_to_cpu(CTentry)) & Mask_DID);
+
+			ndlp = NULL;
+			if (Did != phba->fc_myDID) {
+				/* Check for rscn processing or not */
+				ndlp = lpfc_setup_disc_node(phba, Did);
+			}
+			/* Mark all node table entries that are in the
+			   Nameserver */
+			if (ndlp) {
+				/* NameServer Rsp */
+				lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
+						"%d:0238 Process x%x NameServer"
+						" Rsp Data: x%x x%x x%x\n",
+						phba->brd_no,
+						Did, ndlp->nlp_flag,
+						phba->fc_flag,
+						phba->fc_rscn_id_cnt);
+			} else {
+				/* NameServer Rsp */
+				lpfc_printf_log(phba,
+						KERN_INFO,
+						LOG_DISCOVERY,
+						"%d:0239 Skip x%x NameServer "
+						"Rsp Data: x%x x%x x%x\n",
+						phba->brd_no,
+						Did, Size, phba->fc_flag,
+						phba->fc_rscn_id_cnt);
+			}
+
+			if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
+				goto nsout1;
+			Cnt -= sizeof (uint32_t);
+		}
+		ctptr = NULL;
+
+	}
+
+nsout1:
+	list_del(&head);
+
+	/* Here we are finished in the case RSCN */
+	if (phba->hba_state == LPFC_HBA_READY) {
+		lpfc_els_flush_rscn(phba);
+		phba->fc_flag |= FC_RSCN_MODE; /* we are still in RSCN mode */
+	}
+	return 0;
+}
+
+
+
+
+static void
+lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
+			struct lpfc_iocbq * rspiocb)
+{
+	IOCB_t *irsp;
+	struct lpfc_sli *psli;
+	struct lpfc_dmabuf *bmp;
+	struct lpfc_dmabuf *inp;
+	struct lpfc_dmabuf *outp;
+	struct lpfc_nodelist *ndlp;
+	struct lpfc_sli_ct_request *CTrsp;
+
+	psli = &phba->sli;
+	/* we pass cmdiocb to state machine which needs rspiocb as well */
+	cmdiocb->context_un.rsp_iocb = rspiocb;
+
+	inp = (struct lpfc_dmabuf *) cmdiocb->context1;
+	outp = (struct lpfc_dmabuf *) cmdiocb->context2;
+	bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
+
+	irsp = &rspiocb->iocb;
+	if (irsp->ulpStatus) {
+		if((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
+			((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
+			 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))) {
+			goto out;
+		}
+
+		/* Check for retry */
+		if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
+			phba->fc_ns_retry++;
+			/* CT command is being retried */
+			ndlp =
+			    lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
+					      NameServer_DID);
+			if (ndlp) {
+				if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) ==
+				    0) {
+					goto out;
+				}
+			}
+		}
+	} else {
+		/* Good status, continue checking */
+		CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
+		if (CTrsp->CommandResponse.bits.CmdRsp ==
+		    be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
+			lpfc_ns_rsp(phba, outp,
+				    (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
+		} else if (CTrsp->CommandResponse.bits.CmdRsp ==
+			   be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
+			/* NameServer Rsp Error */
+			lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
+					"%d:0240 NameServer Rsp Error "
+					"Data: x%x x%x x%x x%x\n",
+					phba->brd_no,
+					CTrsp->CommandResponse.bits.CmdRsp,
+					(uint32_t) CTrsp->ReasonCode,
+					(uint32_t) CTrsp->Explanation,
+					phba->fc_flag);
+		} else {
+			/* NameServer Rsp Error */
+			lpfc_printf_log(phba,
+					KERN_INFO,
+					LOG_DISCOVERY,
+					"%d:0241 NameServer Rsp Error "
+					"Data: x%x x%x x%x x%x\n",
+					phba->brd_no,
+					CTrsp->CommandResponse.bits.CmdRsp,
+					(uint32_t) CTrsp->ReasonCode,
+					(uint32_t) CTrsp->Explanation,
+					phba->fc_flag);
+		}
+	}
+	/* Link up / RSCN discovery */
+	lpfc_disc_start(phba);
+out:
+	lpfc_free_ct_rsp(phba, outp);
+	lpfc_mbuf_free(phba, inp->virt, inp->phys);
+	lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
+	kfree(inp);
+	kfree(bmp);
+	mempool_free( cmdiocb, phba->iocb_mem_pool);
+	return;
+}
+
+static void
+lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
+			struct lpfc_iocbq * rspiocb)
+{
+	struct lpfc_sli *psli;
+	struct lpfc_dmabuf *bmp;
+	struct lpfc_dmabuf *inp;
+	struct lpfc_dmabuf *outp;
+	IOCB_t *irsp;
+	struct lpfc_sli_ct_request *CTrsp;
+
+	psli = &phba->sli;
+	/* we pass cmdiocb to state machine which needs rspiocb as well */
+	cmdiocb->context_un.rsp_iocb = rspiocb;
+
+	inp = (struct lpfc_dmabuf *) cmdiocb->context1;
+	outp = (struct lpfc_dmabuf *) cmdiocb->context2;
+	bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
+	irsp = &rspiocb->iocb;
+
+	CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
+
+	/* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
+	lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
+			"%d:0209 RFT request completes ulpStatus x%x "
+			"CmdRsp x%x\n", phba->brd_no, irsp->ulpStatus,
+			CTrsp->CommandResponse.bits.CmdRsp);
+
+	lpfc_free_ct_rsp(phba, outp);
+	lpfc_mbuf_free(phba, inp->virt, inp->phys);
+	lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
+	kfree(inp);
+	kfree(bmp);
+	mempool_free( cmdiocb, phba->iocb_mem_pool);
+	return;
+}
+
+static void
+lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
+			struct lpfc_iocbq * rspiocb)
+{
+	lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
+	return;
+}
+
+static void
+lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
+			 struct lpfc_iocbq * rspiocb)
+{
+	lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
+	return;
+}
+
+static void
+lpfc_get_hba_sym_node_name(struct lpfc_hba * phba, uint8_t * symbp)
+{
+	char fwrev[16];
+
+	lpfc_decode_firmware_rev(phba, fwrev, 0);
+
+	if (phba->Port[0]) {
+		sprintf(symbp, "Emulex %s Port %s FV%s DV%s", phba->ModelName,
+			phba->Port, fwrev, lpfc_release_version);
+	} else {
+		sprintf(symbp, "Emulex %s FV%s DV%s", phba->ModelName,
+			fwrev, lpfc_release_version);
+	}
+}
+
+/*
+ * lpfc_ns_cmd
+ * Description:
+ *    Issue Cmd to NameServer
+ *       SLI_CTNS_GID_FT
+ *       LI_CTNS_RFT_ID
+ */
+int
+lpfc_ns_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
+{
+	struct lpfc_dmabuf *mp, *bmp;
+	struct lpfc_sli_ct_request *CtReq;
+	struct ulp_bde64 *bpl;
+	void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
+		      struct lpfc_iocbq *) = NULL;
+	uint32_t rsp_size = 1024;
+
+	/* fill in BDEs for command */
+	/* Allocate buffer for command payload */
+	mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_ATOMIC);
+	if (!mp)
+		goto ns_cmd_exit;
+
+	INIT_LIST_HEAD(&mp->list);
+	mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
+	if (!mp->virt)
+		goto ns_cmd_free_mp;
+
+	/* Allocate buffer for Buffer ptr list */
+	bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_ATOMIC);
+	if (!bmp)
+		goto ns_cmd_free_mpvirt;
+
+	INIT_LIST_HEAD(&bmp->list);
+	bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
+	if (!bmp->virt)
+		goto ns_cmd_free_bmp;
+
+	/* NameServer Req */
+	lpfc_printf_log(phba,
+			KERN_INFO,
+			LOG_DISCOVERY,
+			"%d:0236 NameServer Req Data: x%x x%x x%x\n",
+			phba->brd_no, cmdcode, phba->fc_flag,
+			phba->fc_rscn_id_cnt);
+
+	bpl = (struct ulp_bde64 *) bmp->virt;
+	memset(bpl, 0, sizeof(struct ulp_bde64));
+	bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
+	bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
+	bpl->tus.f.bdeFlags = 0;
+	if (cmdcode == SLI_CTNS_GID_FT)
+		bpl->tus.f.bdeSize = GID_REQUEST_SZ;
+	else if (cmdcode == SLI_CTNS_RFT_ID)
+		bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
+	else if (cmdcode == SLI_CTNS_RNN_ID)
+		bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
+	else if (cmdcode == SLI_CTNS_RSNN_NN)
+		bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
+	else
+		bpl->tus.f.bdeSize = 0;
+	bpl->tus.w = le32_to_cpu(bpl->tus.w);
+
+	CtReq = (struct lpfc_sli_ct_request *) mp->virt;
+	memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
+	CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
+	CtReq->RevisionId.bits.InId = 0;
+	CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
+	CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
+	CtReq->CommandResponse.bits.Size = 0;
+	switch (cmdcode) {
+	case SLI_CTNS_GID_FT:
+		CtReq->CommandResponse.bits.CmdRsp =
+		    be16_to_cpu(SLI_CTNS_GID_FT);
+		CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
+		if (phba->hba_state < LPFC_HBA_READY)
+			phba->hba_state = LPFC_NS_QRY;
+		lpfc_set_disctmo(phba);
+		cmpl = lpfc_cmpl_ct_cmd_gid_ft;
+		rsp_size = FC_MAX_NS_RSP;
+		break;
+
+	case SLI_CTNS_RFT_ID:
+		CtReq->CommandResponse.bits.CmdRsp =
+		    be16_to_cpu(SLI_CTNS_RFT_ID);
+		CtReq->un.rft.PortId = be32_to_cpu(phba->fc_myDID);
+		CtReq->un.rft.fcpReg = 1;
+		cmpl = lpfc_cmpl_ct_cmd_rft_id;
+		break;
+
+	case SLI_CTNS_RNN_ID:
+		CtReq->CommandResponse.bits.CmdRsp =
+		    be16_to_cpu(SLI_CTNS_RNN_ID);
+		CtReq->un.rnn.PortId = be32_to_cpu(phba->fc_myDID);
+		memcpy(CtReq->un.rnn.wwnn,  &phba->fc_nodename,
+		       sizeof (struct lpfc_name));
+		cmpl = lpfc_cmpl_ct_cmd_rnn_id;
+		break;
+
+	case SLI_CTNS_RSNN_NN:
+		CtReq->CommandResponse.bits.CmdRsp =
+		    be16_to_cpu(SLI_CTNS_RSNN_NN);
+		memcpy(CtReq->un.rsnn.wwnn, &phba->fc_nodename,
+		       sizeof (struct lpfc_name));
+		lpfc_get_hba_sym_node_name(phba, CtReq->un.rsnn.symbname);
+		CtReq->un.rsnn.len = strlen(CtReq->un.rsnn.symbname);
+		cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
+		break;
+	}
+
+	if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, rsp_size))
+		/* On success, The cmpl function will free the buffers */
+		return 0;
+
+	lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
+ns_cmd_free_bmp:
+	kfree(bmp);
+ns_cmd_free_mpvirt:
+	lpfc_mbuf_free(phba, mp->virt, mp->phys);
+ns_cmd_free_mp:
+	kfree(mp);
+ns_cmd_exit:
+	return 1;
+}
+
+static void
+lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba * phba,
+		      struct lpfc_iocbq * cmdiocb, struct lpfc_iocbq * rspiocb)
+{
+	struct lpfc_dmabuf *bmp = cmdiocb->context3;
+	struct lpfc_dmabuf *inp = cmdiocb->context1;
+	struct lpfc_dmabuf *outp = cmdiocb->context2;
+	struct lpfc_sli_ct_request *CTrsp = outp->virt;
+	struct lpfc_sli_ct_request *CTcmd = inp->virt;
+	struct lpfc_nodelist *ndlp;
+	uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
+	uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
+
+	ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID);
+	if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
+		/* FDMI rsp failed */
+		lpfc_printf_log(phba,
+			        KERN_INFO,
+			        LOG_DISCOVERY,
+			        "%d:0220 FDMI rsp failed Data: x%x\n",
+			        phba->brd_no,
+			       be16_to_cpu(fdmi_cmd));
+	}
+
+	switch (be16_to_cpu(fdmi_cmd)) {
+	case SLI_MGMT_RHBA:
+		lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RPA);
+		break;
+
+	case SLI_MGMT_RPA:
+		break;
+
+	case SLI_MGMT_DHBA:
+		lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DPRT);
+		break;
+
+	case SLI_MGMT_DPRT:
+		lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RHBA);
+		break;
+	}
+
+	lpfc_free_ct_rsp(phba, outp);
+	lpfc_mbuf_free(phba, inp->virt, inp->phys);
+	lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
+	kfree(inp);
+	kfree(bmp);
+	mempool_free(cmdiocb, phba->iocb_mem_pool);
+	return;
+}
+int
+lpfc_fdmi_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
+{
+	struct lpfc_dmabuf *mp, *bmp;
+	struct lpfc_sli_ct_request *CtReq;
+	struct ulp_bde64 *bpl;
+	uint32_t size;
+	REG_HBA *rh;
+	PORT_ENTRY *pe;
+	REG_PORT_ATTRIBUTE *pab;
+	ATTRIBUTE_BLOCK *ab;
+	ATTRIBUTE_ENTRY *ae;
+	void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
+		      struct lpfc_iocbq *);
+
+
+	/* fill in BDEs for command */
+	/* Allocate buffer for command payload */
+	mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_ATOMIC);
+	if (!mp)
+		goto fdmi_cmd_exit;
+
+	mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
+	if (!mp->virt)
+		goto fdmi_cmd_free_mp;
+
+	/* Allocate buffer for Buffer ptr list */
+	bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_ATOMIC);
+	if (!bmp)
+		goto fdmi_cmd_free_mpvirt;
+
+	bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
+	if (!bmp->virt)
+		goto fdmi_cmd_free_bmp;
+
+	INIT_LIST_HEAD(&mp->list);
+	INIT_LIST_HEAD(&bmp->list);
+
+	/* FDMI request */
+	lpfc_printf_log(phba,
+		        KERN_INFO,
+		        LOG_DISCOVERY,
+		        "%d:0218 FDMI Request Data: x%x x%x x%x\n",
+		        phba->brd_no,
+		       phba->fc_flag, phba->hba_state, cmdcode);
+
+	CtReq = (struct lpfc_sli_ct_request *) mp->virt;
+
+	memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
+	CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
+	CtReq->RevisionId.bits.InId = 0;
+
+	CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
+	CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
+	size = 0;
+
+	switch (cmdcode) {
+	case SLI_MGMT_RHBA:
+		{
+			lpfc_vpd_t *vp = &phba->vpd;
+			uint32_t i, j, incr;
+			int len;
+
+			CtReq->CommandResponse.bits.CmdRsp =
+			    be16_to_cpu(SLI_MGMT_RHBA);
+			CtReq->CommandResponse.bits.Size = 0;
+			rh = (REG_HBA *) & CtReq->un.PortID;
+			memcpy(&rh->hi.PortName, &phba->fc_sparam.portName,
+			       sizeof (struct lpfc_name));
+			/* One entry (port) per adapter */
+			rh->rpl.EntryCnt = be32_to_cpu(1);
+			memcpy(&rh->rpl.pe, &phba->fc_sparam.portName,
+			       sizeof (struct lpfc_name));
+
+			/* point to the HBA attribute block */
+			size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
+			ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
+			ab->EntryCnt = 0;
+
+			/* Point to the beginning of the first HBA attribute
+			   entry */
+			/* #1 HBA attribute entry */
+			size += FOURBYTES;
+			ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
+			ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
+			ae->ad.bits.AttrLen =  be16_to_cpu(FOURBYTES
+						+ sizeof (struct lpfc_name));
+			memcpy(&ae->un.NodeName, &phba->fc_sparam.nodeName,
+			       sizeof (struct lpfc_name));
+			ab->EntryCnt++;
+			size += FOURBYTES + sizeof (struct lpfc_name);
+
+			/* #2 HBA attribute entry */
+			ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
+			ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
+			strcpy(ae->un.Manufacturer, "Emulex Corporation");
+			len = strlen(ae->un.Manufacturer);
+			len += (len & 3) ? (4 - (len & 3)) : 4;
+			ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
+			ab->EntryCnt++;
+			size += FOURBYTES + len;
+
+			/* #3 HBA attribute entry */
+			ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
+			ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
+			strcpy(ae->un.SerialNumber, phba->SerialNumber);
+			len = strlen(ae->un.SerialNumber);
+			len += (len & 3) ? (4 - (len & 3)) : 4;
+			ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
+			ab->EntryCnt++;
+			size += FOURBYTES + len;
+
+			/* #4 HBA attribute entry */
+			ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
+			ae->ad.bits.AttrType = be16_to_cpu(MODEL);
+			strcpy(ae->un.Model, phba->ModelName);
+			len = strlen(ae->un.Model);
+			len += (len & 3) ? (4 - (len & 3)) : 4;
+			ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
+			ab->EntryCnt++;
+			size += FOURBYTES + len;
+
+			/* #5 HBA attribute entry */
+			ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
+			ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
+			strcpy(ae->un.ModelDescription, phba->ModelDesc);
+			len = strlen(ae->un.ModelDescription);
+			len += (len & 3) ? (4 - (len & 3)) : 4;
+			ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
+			ab->EntryCnt++;
+			size += FOURBYTES + len;
+
+			/* #6 HBA attribute entry */
+			ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
+			ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
+			ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
+			/* Convert JEDEC ID to ascii for hardware version */
+			incr = vp->rev.biuRev;
+			for (i = 0; i < 8; i++) {
+				j = (incr & 0xf);
+				if (j <= 9)
+					ae->un.HardwareVersion[7 - i] =
+					    (char)((uint8_t) 0x30 +
+						   (uint8_t) j);
+				else
+					ae->un.HardwareVersion[7 - i] =
+					    (char)((uint8_t) 0x61 +
+						   (uint8_t) (j - 10));
+				incr = (incr >> 4);
+			}
+			ab->EntryCnt++;
+			size += FOURBYTES + 8;
+
+			/* #7 HBA attribute entry */
+			ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
+			ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
+			strcpy(ae->un.DriverVersion, lpfc_release_version);
+			len = strlen(ae->un.DriverVersion);
+			len += (len & 3) ? (4 - (len & 3)) : 4;
+			ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
+			ab->EntryCnt++;
+			size += FOURBYTES + len;
+
+			/* #8 HBA attribute entry */
+			ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
+			ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
+			strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
+			len = strlen(ae->un.OptionROMVersion);
+			len += (len & 3) ? (4 - (len & 3)) : 4;
+			ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
+			ab->EntryCnt++;
+			size += FOURBYTES + len;
+
+			/* #9 HBA attribute entry */
+			ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
+			ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
+			lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
+				1);
+			len = strlen(ae->un.FirmwareVersion);
+			len += (len & 3) ? (4 - (len & 3)) : 4;
+			ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
+			ab->EntryCnt++;
+			size += FOURBYTES + len;
+
+			/* #10 HBA attribute entry */
+			ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
+			ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
+			sprintf(ae->un.OsNameVersion, "%s %s %s",
+				system_utsname.sysname, system_utsname.release,
+				system_utsname.version);
+			len = strlen(ae->un.OsNameVersion);
+			len += (len & 3) ? (4 - (len & 3)) : 4;
+			ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
+			ab->EntryCnt++;
+			size += FOURBYTES + len;
+
+			/* #11 HBA attribute entry */
+			ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
+			ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
+			ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
+			ae->un.MaxCTPayloadLen = (65 * 4096);
+			ab->EntryCnt++;
+			size += FOURBYTES + 4;
+
+			ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
+			/* Total size */
+			size = GID_REQUEST_SZ - 4 + size;
+		}
+		break;
+
+	case SLI_MGMT_RPA:
+		{
+			lpfc_vpd_t *vp;
+			struct serv_parm *hsp;
+			int len;
+
+			vp = &phba->vpd;
+
+			CtReq->CommandResponse.bits.CmdRsp =
+			    be16_to_cpu(SLI_MGMT_RPA);
+			CtReq->CommandResponse.bits.Size = 0;
+			pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
+			size = sizeof (struct lpfc_name) + FOURBYTES;
+			memcpy((uint8_t *) & pab->PortName,
+			       (uint8_t *) & phba->fc_sparam.portName,
+			       sizeof (struct lpfc_name));
+			pab->ab.EntryCnt = 0;
+
+			/* #1 Port attribute entry */
+			ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
+			ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
+			ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
+			ae->un.SupportFC4Types[2] = 1;
+			ae->un.SupportFC4Types[7] = 1;
+			pab->ab.EntryCnt++;
+			size += FOURBYTES + 32;
+
+			/* #2 Port attribute entry */
+			ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
+			ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
+			ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
+			if (FC_JEDEC_ID(vp->rev.biuRev) == VIPER_JEDEC_ID)
+				ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
+			else if (FC_JEDEC_ID(vp->rev.biuRev) == HELIOS_JEDEC_ID)
+				ae->un.SupportSpeed = HBA_PORTSPEED_4GBIT;
+			else if ((FC_JEDEC_ID(vp->rev.biuRev) ==
+				  CENTAUR_2G_JEDEC_ID)
+				 || (FC_JEDEC_ID(vp->rev.biuRev) ==
+				     PEGASUS_JEDEC_ID)
+				 || (FC_JEDEC_ID(vp->rev.biuRev) ==
+				     THOR_JEDEC_ID))
+				ae->un.SupportSpeed = HBA_PORTSPEED_2GBIT;
+			else
+				ae->un.SupportSpeed = HBA_PORTSPEED_1GBIT;
+			pab->ab.EntryCnt++;
+			size += FOURBYTES + 4;
+
+			/* #3 Port attribute entry */
+			ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
+			ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
+			ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
+			switch(phba->fc_linkspeed) {
+				case LA_1GHZ_LINK:
+					ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
+				break;
+				case LA_2GHZ_LINK:
+					ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
+				break;
+				case LA_4GHZ_LINK:
+					ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
+				break;
+				default:
+					ae->un.PortSpeed =
+						HBA_PORTSPEED_UNKNOWN;
+				break;
+			}
+			pab->ab.EntryCnt++;
+			size += FOURBYTES + 4;
+
+			/* #4 Port attribute entry */
+			ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
+			ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
+			ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
+			hsp = (struct serv_parm *) & phba->fc_sparam;
+			ae->un.MaxFrameSize =
+			    (((uint32_t) hsp->cmn.
+			      bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
+			    bbRcvSizeLsb;
+			pab->ab.EntryCnt++;
+			size += FOURBYTES + 4;
+
+			/* #5 Port attribute entry */
+			ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
+			ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
+			strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
+			len = strlen((char *)ae->un.OsDeviceName);
+			len += (len & 3) ? (4 - (len & 3)) : 4;
+			ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
+			pab->ab.EntryCnt++;
+			size += FOURBYTES + len;
+
+			if (phba->cfg_fdmi_on == 2) {
+				/* #6 Port attribute entry */
+				ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
+							  size);
+				ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
+				sprintf(ae->un.HostName, "%s",
+					system_utsname.nodename);
+				len = strlen(ae->un.HostName);
+				len += (len & 3) ? (4 - (len & 3)) : 4;
+				ae->ad.bits.AttrLen =
+				    be16_to_cpu(FOURBYTES + len);
+				pab->ab.EntryCnt++;
+				size += FOURBYTES + len;
+			}
+
+			pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
+			/* Total size */
+			size = GID_REQUEST_SZ - 4 + size;
+		}
+		break;
+
+	case SLI_MGMT_DHBA:
+		CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
+		CtReq->CommandResponse.bits.Size = 0;
+		pe = (PORT_ENTRY *) & CtReq->un.PortID;
+		memcpy((uint8_t *) & pe->PortName,
+		       (uint8_t *) & phba->fc_sparam.portName,
+		       sizeof (struct lpfc_name));
+		size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
+		break;
+
+	case SLI_MGMT_DPRT:
+		CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
+		CtReq->CommandResponse.bits.Size = 0;
+		pe = (PORT_ENTRY *) & CtReq->un.PortID;
+		memcpy((uint8_t *) & pe->PortName,
+		       (uint8_t *) & phba->fc_sparam.portName,
+		       sizeof (struct lpfc_name));
+		size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
+		break;
+	}
+
+	bpl = (struct ulp_bde64 *) bmp->virt;
+	bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
+	bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
+	bpl->tus.f.bdeFlags = 0;
+	bpl->tus.f.bdeSize = size;
+	bpl->tus.w = le32_to_cpu(bpl->tus.w);
+
+	cmpl = lpfc_cmpl_ct_cmd_fdmi;
+
+	if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP))
+		return 0;
+
+	lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
+fdmi_cmd_free_bmp:
+	kfree(bmp);
+fdmi_cmd_free_mpvirt:
+	lpfc_mbuf_free(phba, mp->virt, mp->phys);
+fdmi_cmd_free_mp:
+	kfree(mp);
+fdmi_cmd_exit:
+	/* Issue FDMI request failed */
+	lpfc_printf_log(phba,
+		        KERN_INFO,
+		        LOG_DISCOVERY,
+		        "%d:0244 Issue FDMI request failed Data: x%x\n",
+		        phba->brd_no,
+			cmdcode);
+	return 1;
+}
+
+void
+lpfc_fdmi_tmo(unsigned long ptr)
+{
+	struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
+	unsigned long iflag;
+
+	spin_lock_irqsave(phba->host->host_lock, iflag);
+	if (!(phba->work_hba_events & WORKER_FDMI_TMO)) {
+		phba->work_hba_events |= WORKER_FDMI_TMO;
+		if (phba->dpc_wait)
+			up(phba->dpc_wait);
+	}
+	spin_unlock_irqrestore(phba->host->host_lock,iflag);
+}
+
+void
+lpfc_fdmi_tmo_handler(struct lpfc_hba *phba)
+{
+	struct lpfc_nodelist *ndlp;
+
+	spin_lock_irq(phba->host->host_lock);
+	if (!(phba->work_hba_events & WORKER_FDMI_TMO)) {
+		spin_unlock_irq(phba->host->host_lock);
+		return;
+	}
+	ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID);
+	if (ndlp) {
+		if (system_utsname.nodename[0] != '\0') {
+			lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
+		} else {
+ 			mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
+		}
+	}
+	spin_unlock_irq(phba->host->host_lock);
+	return;
+}
+
+
+void
+lpfc_decode_firmware_rev(struct lpfc_hba * phba, char *fwrevision, int flag)
+{
+	struct lpfc_sli *psli = &phba->sli;
+	lpfc_vpd_t *vp = &phba->vpd;
+	uint32_t b1, b2, b3, b4, i, rev;
+	char c;
+	uint32_t *ptr, str[4];
+	uint8_t *fwname;
+
+	if (vp->rev.rBit) {
+		if (psli->sliinit.sli_flag & LPFC_SLI2_ACTIVE)
+			rev = vp->rev.sli2FwRev;
+		else
+			rev = vp->rev.sli1FwRev;
+
+		b1 = (rev & 0x0000f000) >> 12;
+		b2 = (rev & 0x00000f00) >> 8;
+		b3 = (rev & 0x000000c0) >> 6;
+		b4 = (rev & 0x00000030) >> 4;
+
+		switch (b4) {
+		case 0:
+			c = 'N';
+			break;
+		case 1:
+			c = 'A';
+			break;
+		case 2:
+			c = 'B';
+			break;
+		default:
+			c = 0;
+			break;
+		}
+		b4 = (rev & 0x0000000f);
+
+		if (psli->sliinit.sli_flag & LPFC_SLI2_ACTIVE)
+			fwname = vp->rev.sli2FwName;
+		else
+			fwname = vp->rev.sli1FwName;
+
+		for (i = 0; i < 16; i++)
+			if(fwname[i] == 0x20)
+				fwname[i] = 0;
+
+		ptr = (uint32_t*)fwname;
+
+		for (i = 0; i < 3; i++)
+			str[i] = be32_to_cpu(*ptr++);
+
+		if (c == 0) {
+			if (flag)
+				sprintf(fwrevision, "%d.%d%d (%s)",
+					b1, b2, b3, (char *)str);
+			else
+				sprintf(fwrevision, "%d.%d%d", b1,
+					b2, b3);
+		} else {
+			if (flag)
+				sprintf(fwrevision, "%d.%d%d%c%d (%s)",
+					b1, b2, b3, c,
+					b4, (char *)str);
+			else
+				sprintf(fwrevision, "%d.%d%d%c%d",
+					b1, b2, b3, c, b4);
+		}
+	} else {
+		rev = vp->rev.smFwRev;
+
+		b1 = (rev & 0xff000000) >> 24;
+		b2 = (rev & 0x00f00000) >> 20;
+		b3 = (rev & 0x000f0000) >> 16;
+		c  = (rev & 0x0000ff00) >> 8;
+		b4 = (rev & 0x000000ff);
+
+		if (flag)
+			sprintf(fwrevision, "%d.%d%d%c%d ", b1,
+				b2, b3, c, b4);
+		else
+			sprintf(fwrevision, "%d.%d%d%c%d ", b1,
+				b2, b3, c, b4);
+	}
+	return;
+}
--- linux-2.6.8.1-t044-driver-update//drivers/scsi/lpfc/lpfc_sli.h	1970-01-01 03:00:00.000000000 +0300
+++ rhel4u2//drivers/scsi/lpfc/lpfc_sli.h	2005-10-19 11:47:17.000000000 +0400
@@ -0,0 +1,218 @@
+/*******************************************************************
+ * This file is part of the Emulex Linux Device Driver for         *
+ * Fibre Channel Host Bus Adapters.                                *
+ * Copyright (C) 2003-2005 Emulex.  All rights reserved.           *
+ * EMULEX and SLI are trademarks of Emulex.                        *
+ * www.emulex.com                                                  *
+ *                                                                 *
+ * This program is free software; you can redistribute it and/or   *
+ * modify it under the terms of version 2 of the GNU General       *
+ * Public License as published by the Free Software Foundation.    *
+ * This program is distributed in the hope that it will be useful. *
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
+ * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
+ * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
+ * more details, a copy of which can be found in the file COPYING  *
+ * included with this package.                                     *
+ *******************************************************************/
+
+/*
+ * $Id: lpfc_sli.h 1.38.2.2 2005/06/13 17:16:49EDT sf_support Exp  $
+ */
+
+#ifndef _H_LPFC_SLI
+#define _H_LPFC_SLI
+
+#include "lpfc_hw.h"
+
+/* forward declaration for LPFC_IOCB_t's use */
+struct lpfc_hba;
+
+/* This structure is used to handle IOCB requests / responses */
+struct lpfc_iocbq {
+	/* lpfc_iocbqs are used in double linked lists */
+	struct list_head list;
+	IOCB_t iocb;		/* IOCB cmd */
+	uint8_t retry;		/* retry counter for IOCB cmd - if needed */
+	uint8_t iocb_flag;
+#define LPFC_IO_POLL	1	/* Polling mode iocb */
+#define LPFC_IO_LIBDFC	2	/* libdfc iocb */
+#define LPFC_IO_WAIT	4
+#define LPFC_IO_HIPRI	8	/* High Priority Queue signal flag */
+
+	uint8_t abort_count;
+	uint8_t rsvd2;
+	uint32_t drvrTimeout;	/* driver timeout in seconds */
+	void *context1;		/* caller context information */
+	void *context2;		/* caller context information */
+	void *context3;		/* caller context information */
+	union {
+		wait_queue_head_t *hipri_wait_queue; /* High Priority Queue wait
+							queue */
+		struct lpfc_iocbq  *rsp_iocb;
+		struct lpfcMboxq   *mbox;
+	} context_un;
+
+	void (*iocb_cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
+			   struct lpfc_iocbq *);
+
+};
+
+#define SLI_IOCB_RET_IOCB      1	/* Return IOCB if cmd ring full */
+#define SLI_IOCB_HIGH_PRIORITY 2	/* High priority command */
+
+#define IOCB_SUCCESS        0
+#define IOCB_BUSY           1
+#define IOCB_ERROR          2
+#define IOCB_TIMEDOUT       3
+
+typedef struct lpfcMboxq {
+	/* MBOXQs are used in single linked lists */
+	struct list_head list;	/* ptr to next mailbox command */
+	MAILBOX_t mb;		/* Mailbox cmd */
+	void *context1;		/* caller context information */
+	void *context2;		/* caller context information */
+
+	void (*mbox_cmpl) (struct lpfc_hba *, struct lpfcMboxq *);
+
+} LPFC_MBOXQ_t;
+
+#define MBX_POLL        1	/* poll mailbox till command done, then
+				   return */
+#define MBX_NOWAIT      2	/* issue command then return immediately */
+#define MBX_STOP_IOCB   4	/* Stop iocb processing till mbox cmds
+				   complete */
+
+#define LPFC_MAX_RING_MASK  4	/* max num of rctl/type masks allowed per
+				   ring */
+#define LPFC_MAX_RING       4	/* max num of SLI rings used by driver */
+
+/* Structure used to hold SLI ring information */
+struct lpfc_sli_ring {
+	uint16_t flag;		/* ring flags */
+#define LPFC_DEFERRED_RING_EVENT 0x001	/* Deferred processing a ring event */
+#define LPFC_CALL_RING_AVAILABLE 0x002	/* indicates cmd was full */
+#define LPFC_STOP_IOCB_MBX       0x010	/* Stop processing IOCB cmds mbox */
+#define LPFC_STOP_IOCB_EVENT     0x020	/* Stop processing IOCB cmds event */
+#define LPFC_STOP_IOCB_MASK      0x030	/* Stop processing IOCB cmds mask */
+	uint16_t abtsiotag;	/* tracks next iotag to use for ABTS */
+
+	uint32_t local_getidx;   /* last available cmd index (from cmdGetInx) */
+	uint32_t next_cmdidx;    /* next_cmd index */
+	uint8_t rsvd;
+	uint8_t ringno;		/* ring number */
+	uint8_t rspidx;		/* current index in response ring */
+	uint8_t cmdidx;		/* current index in command ring */
+	struct lpfc_iocbq ** fast_lookup; /* array of IOCB ptrs indexed by
+					   iotag */
+	struct list_head txq;
+	uint16_t txq_cnt;	/* current length of queue */
+	uint16_t txq_max;	/* max length */
+	struct list_head txcmplq;
+	uint16_t txcmplq_cnt;	/* current length of queue */
+	uint16_t txcmplq_max;	/* max length */
+	volatile uint32_t *cmdringaddr;	/* virtual address for cmd rings */
+	volatile uint32_t *rspringaddr;	/* virtual address for rsp rings */
+	uint32_t missbufcnt;	/* keep track of buffers to post */
+	struct list_head postbufq;
+	uint16_t postbufq_cnt;	/* current length of queue */
+	uint16_t postbufq_max;	/* max length */
+	struct list_head iocb_continueq;
+	uint16_t iocb_continueq_cnt;	/* current length of queue */
+	uint16_t iocb_continueq_max;	/* max length */
+};
+
+typedef struct {
+	uint8_t profile;	/* profile associated with ring */
+	uint8_t rctl;	/* rctl / type pair configured for ring */
+	uint8_t type;	/* rctl / type pair configured for ring */
+	uint8_t rsvd;
+	/* rcv'd unsol event */
+	void (*lpfc_sli_rcv_unsol_event) (struct lpfc_hba *,
+					 struct lpfc_sli_ring *,
+					 struct lpfc_iocbq *);
+} LPFC_RING_MASK_t;
+
+/* Structure used for configuring rings to a specific profile or rctl / type */
+typedef struct {
+	LPFC_RING_MASK_t prt[LPFC_MAX_RING_MASK];
+	uint32_t num_mask;	/* number of mask entries in prt array */
+	uint32_t iotag_ctr;	/* keeps track of the next iotag to use */
+	uint32_t iotag_max;	/* max iotag value to use               */
+	uint32_t fast_iotag;	/* max fastlookup based iotag           */
+	uint16_t numCiocb;	/* number of command iocb's per ring */
+	uint16_t numRiocb;	/* number of rsp iocb's per ring */
+	/* cmd ring available */
+	void (*lpfc_sli_cmd_available) (struct lpfc_hba *,
+					struct lpfc_sli_ring *);
+} LPFC_RING_INIT_t;
+
+typedef struct {
+	LPFC_RING_INIT_t ringinit[LPFC_MAX_RING]; /* ring initialization info */
+	uint32_t num_rings;
+	uint32_t sli_flag;
+} LPFC_SLI_INIT_t;
+
+/* Structure used to hold SLI statistical counters and info */
+typedef struct {
+	uint64_t iocbEvent[LPFC_MAX_RING];	/* IOCB event counters */
+	uint64_t iocbCmd[LPFC_MAX_RING];	/* IOCB cmd issued */
+	uint64_t iocbRsp[LPFC_MAX_RING];	/* IOCB rsp received */
+	uint64_t iocbCmdDelay[LPFC_MAX_RING];	/* IOCB cmd ring delay */
+	uint64_t iocbCmdFull[LPFC_MAX_RING];	/* IOCB cmd ring full */
+	uint64_t iocbCmdEmpty[LPFC_MAX_RING];	/* IOCB cmd ring is now empty */
+	uint64_t iocbRspFull[LPFC_MAX_RING];	/* IOCB rsp ring full */
+	uint64_t mboxStatErr;	/* Mbox cmds completed status error */
+	uint64_t mboxCmd;	/* Mailbox commands issued */
+	uint64_t sliIntr;	/* Count of Host Attention interrupts */
+	uint32_t errAttnEvent;	/* Error Attn event counters */
+	uint32_t linkEvent;	/* Link event counters */
+	uint32_t mboxEvent;	/* Mailbox event counters */
+	uint32_t mboxBusy;	/* Mailbox cmd busy */
+} LPFC_SLI_STAT_t;
+
+/* Structure used to hold SLI information */
+struct lpfc_sli {
+	LPFC_SLI_INIT_t sliinit;	/* initialization info */
+	/* Additional sli_flags */
+#define LPFC_SLI_MBOX_ACTIVE      0x100	/* HBA mailbox is currently active */
+#define LPFC_SLI2_ACTIVE          0x200	/* SLI2 overlay in firmware is active */
+#define LPFC_PROCESS_LA           0x400	/* Able to process link attention */
+
+	struct lpfc_sli_ring ring[LPFC_MAX_RING];
+	int fcp_ring;		/* ring used for FCP initiator commands */
+	int next_ring;
+
+	int ip_ring;		/* ring used for IP network drv cmds */
+
+	LPFC_SLI_STAT_t slistat;	/* SLI statistical info */
+	struct list_head mboxq;
+	uint16_t mboxq_cnt;	/* current length of queue */
+	uint16_t mboxq_max;	/* max length */
+	LPFC_MBOXQ_t *mbox_active;	/* active mboxq information */
+
+	struct timer_list mbox_tmo;	/* Hold clk to timeout active mbox
+					   cmd */
+
+	volatile uint32_t *MBhostaddr;	/* virtual address for mbox cmds */
+};
+
+/* Given a pointer to the start of the ring, and the slot number of
+ * the desired iocb entry, calc a pointer to that entry.
+ * (assume iocb entry size is 32 bytes, or 8 words)
+ */
+#define IOCB_ENTRY(ring,slot) ((IOCB_t *)(((char *)(ring)) + ((slot) * 32)))
+
+#define LPFC_SLI_ABORT_IMED	0	/* Immediate abort of IOCB, deque and
+					   call compl routine immediately. */
+#define LPFC_MBOX_TMO           30	/* Sec tmo for outstanding mbox
+					   command */
+
+/* Flags for aborting I/Os on tx and txcmpl queues */
+#define LPFC_ABORT_TXQ		1	/* Abort I/Os on txq */
+#define LPFC_ABORT_TXCMPLQ	2	/* Abort I/Os on txcmplq */
+#define LPFC_ABORT_ALLQ		3	/* Abort I/Os both txq and txcmplq */
+
+#endif				/* _H_LPFC_SLI */
--- linux-2.6.8.1-t044-driver-update//drivers/scsi/lpfc/lpfc_mem.c	1970-01-01 03:00:00.000000000 +0300
+++ rhel4u2//drivers/scsi/lpfc/lpfc_mem.c	2005-10-19 11:47:17.000000000 +0400
@@ -0,0 +1,204 @@
+/*******************************************************************
+ * This file is part of the Emulex Linux Device Driver for         *
+ * Fibre Channel Host Bus Adapters.                                *
+ * Copyright (C) 2003-2005 Emulex.  All rights reserved.           *
+ * EMULEX and SLI are trademarks of Emulex.                        *
+ * www.emulex.com                                                  *
+ *                                                                 *
+ * This program is free software; you can redistribute it and/or   *
+ * modify it under the terms of version 2 of the GNU General       *
+ * Public License as published by the Free Software Foundation.    *
+ * This program is distributed in the hope that it will be useful. *
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
+ * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
+ * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
+ * more details, a copy of which can be found in the file COPYING  *
+ * included with this package.                                     *
+ *******************************************************************/
+
+/*
+ * $Id: lpfc_mem.c 1.72.1.2 2005/06/13 17:16:34EDT sf_support Exp  $
+ */
+
+#include <linux/mempool.h>
+#include <linux/pci.h>
+#include <linux/slab.h>
+#include <scsi/scsi_device.h>
+
+#include "lpfc_sli.h"
+#include "lpfc_disc.h"
+#include "lpfc_scsi.h"
+#include "lpfc.h"
+#include "lpfc_crtn.h"
+#include "lpfc_mem.h"
+
+static void *
+lpfc_pool_kmalloc(int gfp_flags, void *data)
+{
+	return kmalloc((unsigned long)data, gfp_flags);
+}
+
+static void
+lpfc_pool_kfree(void *obj, void *data)
+{
+	kfree(obj);
+}
+
+int
+lpfc_mem_alloc(struct lpfc_hba * phba)
+{
+	struct lpfc_dma_pool *pool = &phba->lpfc_mbuf_safety_pool;
+	int i;
+
+	phba->lpfc_scsi_dma_ext_pool = pci_pool_create("lpfc_scsi_dma_ext_pool",
+				phba->pcidev, LPFC_SCSI_DMA_EXT_SIZE, 8, 0);
+	if (!phba->lpfc_scsi_dma_ext_pool)
+		goto fail;
+
+	phba->lpfc_mbuf_pool = pci_pool_create("lpfc_mbuf_pool", phba->pcidev,
+							LPFC_BPL_SIZE, 8,0);
+	if (!phba->lpfc_mbuf_pool)
+		goto fail_free_dma_ext_pool;
+
+	pool->elements = kmalloc(sizeof(struct lpfc_dmabuf) *
+					 LPFC_MBUF_POOL_SIZE, GFP_KERNEL);
+	pool->max_count = 0;
+	pool->current_count = 0;
+	for ( i = 0; i < LPFC_MBUF_POOL_SIZE; i++) {
+		pool->elements[i].virt = pci_pool_alloc(phba->lpfc_mbuf_pool,
+				       GFP_KERNEL, &pool->elements[i].phys);
+		if (!pool->elements[i].virt)
+			goto fail_free_mbuf_pool;
+		pool->max_count++;
+		pool->current_count++;
+	}
+
+	phba->iocb_mem_pool = mempool_create(LPFC_MEM_POOL_SIZE,
+			lpfc_pool_kmalloc, lpfc_pool_kfree,
+			(void *)(unsigned long)sizeof(struct lpfc_iocbq));
+	if (!phba->iocb_mem_pool)
+		goto fail_free_mbuf_pool;
+
+	phba->scsibuf_mem_pool = mempool_create(LPFC_MEM_POOL_SIZE,
+			lpfc_pool_kmalloc, lpfc_pool_kfree,
+			(void *)(unsigned long)sizeof(struct lpfc_scsi_buf));
+	if (!phba->scsibuf_mem_pool)
+		goto fail_free_iocb_pool;
+
+	phba->mbox_mem_pool = mempool_create(LPFC_MEM_POOL_SIZE,
+				lpfc_pool_kmalloc, lpfc_pool_kfree,
+				(void *)(unsigned long)sizeof(LPFC_MBOXQ_t));
+	if (!phba->mbox_mem_pool)
+		goto fail_free_scsibuf_pool;
+
+	phba->nlp_mem_pool = mempool_create(LPFC_MEM_POOL_SIZE,
+			lpfc_pool_kmalloc, lpfc_pool_kfree,
+			(void *)(unsigned long)sizeof(struct lpfc_nodelist));
+	if (!phba->nlp_mem_pool)
+		goto fail_free_mbox_pool;
+
+	phba->bind_mem_pool = mempool_create(LPFC_MEM_POOL_SIZE,
+			lpfc_pool_kmalloc, lpfc_pool_kfree,
+			(void *)(unsigned long)sizeof(struct lpfc_bindlist));
+	if (!phba->bind_mem_pool)
+		goto fail_free_nlp_pool;
+
+	return 0;
+
+ fail_free_nlp_pool:
+	mempool_destroy(phba->nlp_mem_pool);
+ fail_free_mbox_pool:
+	mempool_destroy(phba->mbox_mem_pool);
+ fail_free_scsibuf_pool:
+	mempool_destroy(phba->scsibuf_mem_pool);
+ fail_free_iocb_pool:
+	mempool_destroy(phba->iocb_mem_pool);
+ fail_free_mbuf_pool:
+	while (--i)
+		pci_pool_free(phba->lpfc_mbuf_pool, pool->elements[i].virt,
+						 pool->elements[i].phys);
+	kfree(pool->elements);
+	pci_pool_destroy(phba->lpfc_mbuf_pool);
+ fail_free_dma_ext_pool:
+	pci_pool_destroy(phba->lpfc_scsi_dma_ext_pool);
+ fail:
+	return -ENOMEM;
+}
+
+void
+lpfc_mem_free(struct lpfc_hba * phba)
+{
+	struct lpfc_sli *psli = &phba->sli;
+	struct lpfc_dma_pool *pool = &phba->lpfc_mbuf_safety_pool;
+	LPFC_MBOXQ_t *mbox, *next_mbox;
+	struct lpfc_dmabuf   *mp;
+	int i;
+
+	list_for_each_entry_safe(mbox, next_mbox, &psli->mboxq, list) {
+		mp = (struct lpfc_dmabuf *) (mbox->context1);
+		if (mp) {
+			lpfc_mbuf_free(phba, mp->virt, mp->phys);
+			kfree(mp);
+		}
+		list_del(&mbox->list);
+		mempool_free(mbox, phba->mbox_mem_pool);
+	}
+
+	psli->sliinit.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
+	if (psli->mbox_active) {
+		mbox = psli->mbox_active;
+		mp = (struct lpfc_dmabuf *) (mbox->context1);
+		if (mp) {
+			lpfc_mbuf_free(phba, mp->virt, mp->phys);
+			kfree(mp);
+		}
+		mempool_free(mbox, phba->mbox_mem_pool);
+		psli->mbox_active = NULL;
+	}
+
+	for (i = 0; i < pool->current_count; i++)
+		pci_pool_free(phba->lpfc_mbuf_pool, pool->elements[i].virt,
+						 pool->elements[i].phys);
+	kfree(pool->elements);
+	mempool_destroy(phba->bind_mem_pool);
+	mempool_destroy(phba->nlp_mem_pool);
+	mempool_destroy(phba->mbox_mem_pool);
+	mempool_destroy(phba->scsibuf_mem_pool);
+	mempool_destroy(phba->iocb_mem_pool);
+
+	pci_pool_destroy(phba->lpfc_scsi_dma_ext_pool);
+	pci_pool_destroy(phba->lpfc_mbuf_pool);
+}
+
+void *
+lpfc_mbuf_alloc(struct lpfc_hba *phba, int mem_flags, dma_addr_t *handle)
+{
+	struct lpfc_dma_pool *pool = &phba->lpfc_mbuf_safety_pool;
+	void *ret;
+
+	ret = pci_pool_alloc(phba->lpfc_mbuf_pool, GFP_ATOMIC, handle);
+
+	if (!ret && ( mem_flags & MEM_PRI) && pool->current_count) {
+		pool->current_count--;
+		ret = pool->elements[pool->current_count].virt;
+		*handle = pool->elements[pool->current_count].phys;
+	}
+	return ret;
+}
+
+void
+lpfc_mbuf_free(struct lpfc_hba * phba, void *virt, dma_addr_t dma)
+{
+	struct lpfc_dma_pool *pool = &phba->lpfc_mbuf_safety_pool;
+
+	if (pool->current_count < pool->max_count) {
+		pool->elements[pool->current_count].virt = virt;
+		pool->elements[pool->current_count].phys = dma;
+		pool->current_count++;
+	} else {
+		pci_pool_free(phba->lpfc_mbuf_pool, virt, dma);
+	}
+	return;
+}
--- linux-2.6.8.1-t044-driver-update//drivers/scsi/lpfc/lpfc_hw.h	1970-01-01 03:00:00.000000000 +0300
+++ rhel4u2//drivers/scsi/lpfc/lpfc_hw.h	2005-10-19 11:47:17.000000000 +0400
@@ -0,0 +1,2691 @@
+/*******************************************************************
+ * This file is part of the Emulex Linux Device Driver for         *
+ * Fibre Channel Host Bus Adapters.                                *
+ * Copyright (C) 2003-2005 Emulex.  All rights reserved.           *
+ * EMULEX and SLI are trademarks of Emulex.                        *
+ * www.emulex.com                                                  *
+ *                                                                 *
+ * This program is free software; you can redistribute it and/or   *
+ * modify it under the terms of version 2 of the GNU General       *
+ * Public License as published by the Free Software Foundation.    *
+ * This program is distributed in the hope that it will be useful. *
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
+ * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
+ * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
+ * more details, a copy of which can be found in the file COPYING  *
+ * included with this package.                                     *
+ *******************************************************************/
+
+/*
+ * $Id: lpfc_hw.h 1.34.2.2 2005/06/13 17:16:25EDT sf_support Exp  $
+ */
+
+#ifndef  _H_LPFC_HW
+#define _H_LPFC_HW
+
+#define FDMI_DID        ((uint32_t)0xfffffa)
+#define NameServer_DID  ((uint32_t)0xfffffc)
+#define SCR_DID         ((uint32_t)0xfffffd)
+#define Fabric_DID      ((uint32_t)0xfffffe)
+#define Bcast_DID       ((uint32_t)0xffffff)
+#define Mask_DID        ((uint32_t)0xffffff)
+#define CT_DID_MASK     ((uint32_t)0xffff00)
+#define Fabric_DID_MASK ((uint32_t)0xfff000)
+#define WELL_KNOWN_DID_MASK ((uint32_t)0xfffff0)
+
+#define PT2PT_LocalID   ((uint32_t)1)
+#define PT2PT_RemoteID  ((uint32_t)2)
+
+#define FF_DEF_EDTOV          2000	/* Default E_D_TOV (2000ms) */
+#define FF_DEF_ALTOV            15	/* Default AL_TIME (15ms) */
+#define FF_DEF_RATOV             2	/* Default RA_TOV (2s) */
+#define FF_DEF_ARBTOV         1900	/* Default ARB_TOV (1900ms) */
+
+#define LPFC_BUF_RING0        64	/* Number of buffers to post to RING
+					   0 */
+
+#define FCELSSIZE             1024	/* maximum ELS transfer size */
+
+#define LPFC_FCP_RING            0	/* ring 2 for FCP initiator commands */
+#define LPFC_IP_RING             1	/* ring 1 for IP commands */
+#define LPFC_ELS_RING            2	/* ring 0 for ELS commands */
+#define LPFC_FCP_NEXT_RING       3
+
+#define SLI2_IOCB_CMD_R0_ENTRIES    172	/* SLI-2 FCP command ring entries */
+#define SLI2_IOCB_RSP_R0_ENTRIES    134	/* SLI-2 FCP response ring entries */
+#define SLI2_IOCB_CMD_R1_ENTRIES      4	/* SLI-2 IP command ring entries */
+#define SLI2_IOCB_RSP_R1_ENTRIES      4	/* SLI-2 IP response ring entries */
+#define SLI2_IOCB_CMD_R1XTRA_ENTRIES 36	/* SLI-2 extra FCP cmd ring entries */
+#define SLI2_IOCB_RSP_R1XTRA_ENTRIES 52	/* SLI-2 extra FCP rsp ring entries */
+#define SLI2_IOCB_CMD_R2_ENTRIES     20	/* SLI-2 ELS command ring entries */
+#define SLI2_IOCB_RSP_R2_ENTRIES     20	/* SLI-2 ELS response ring entries */
+#define SLI2_IOCB_CMD_R3_ENTRIES      0
+#define SLI2_IOCB_RSP_R3_ENTRIES      0
+#define SLI2_IOCB_CMD_R3XTRA_ENTRIES 24
+#define SLI2_IOCB_RSP_R3XTRA_ENTRIES 32
+
+/* Common Transport structures and definitions */
+
+union CtRevisionId {
+	/* Structure is in Big Endian format */
+	struct {
+		uint32_t Revision:8;
+		uint32_t InId:24;
+	} bits;
+	uint32_t word;
+};
+
+union CtCommandResponse {
+	/* Structure is in Big Endian format */
+	struct {
+		uint32_t CmdRsp:16;
+		uint32_t Size:16;
+	} bits;
+	uint32_t word;
+};
+
+struct lpfc_sli_ct_request {
+	/* Structure is in Big Endian format */
+	union CtRevisionId RevisionId;
+	uint8_t FsType;
+	uint8_t FsSubType;
+	uint8_t Options;
+	uint8_t Rsrvd1;
+	union CtCommandResponse CommandResponse;
+	uint8_t Rsrvd2;
+	uint8_t ReasonCode;
+	uint8_t Explanation;
+	uint8_t VendorUnique;
+
+	union {
+		uint32_t PortID;
+		struct gid {
+			uint8_t PortType;	/* for GID_PT requests */
+			uint8_t DomainScope;
+			uint8_t AreaScope;
+			uint8_t Fc4Type;	/* for GID_FT requests */
+		} gid;
+		struct rft {
+			uint32_t PortId;	/* For RFT_ID requests */
+
+#ifdef __BIG_ENDIAN_BITFIELD
+			uint32_t rsvd0:16;
+			uint32_t rsvd1:7;
+			uint32_t fcpReg:1;	/* Type 8 */
+			uint32_t rsvd2:2;
+			uint32_t ipReg:1;	/* Type 5 */
+			uint32_t rsvd3:5;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+			uint32_t rsvd0:16;
+			uint32_t fcpReg:1;	/* Type 8 */
+			uint32_t rsvd1:7;
+			uint32_t rsvd3:5;
+			uint32_t ipReg:1;	/* Type 5 */
+			uint32_t rsvd2:2;
+#endif
+
+			uint32_t rsvd[7];
+		} rft;
+		struct rnn {
+			uint32_t PortId;	/* For RNN_ID requests */
+			uint8_t wwnn[8];
+		} rnn;
+		struct rsnn {	/* For RSNN_ID requests */
+			uint8_t wwnn[8];
+			uint8_t len;
+			uint8_t symbname[255];
+		} rsnn;
+	} un;
+};
+
+#define  SLI_CT_REVISION        1
+#define  GID_REQUEST_SZ         (sizeof(struct lpfc_sli_ct_request) - 260)
+#define  RFT_REQUEST_SZ         (sizeof(struct lpfc_sli_ct_request) - 228)
+#define  RNN_REQUEST_SZ         (sizeof(struct lpfc_sli_ct_request) - 252)
+#define  RSNN_REQUEST_SZ        (sizeof(struct lpfc_sli_ct_request))
+
+/*
+ * FsType Definitions
+ */
+
+#define  SLI_CT_MANAGEMENT_SERVICE        0xFA
+#define  SLI_CT_TIME_SERVICE              0xFB
+#define  SLI_CT_DIRECTORY_SERVICE         0xFC
+#define  SLI_CT_FABRIC_CONTROLLER_SERVICE 0xFD
+
+/*
+ * Directory Service Subtypes
+ */
+
+#define  SLI_CT_DIRECTORY_NAME_SERVER     0x02
+
+/*
+ * Response Codes
+ */
+
+#define  SLI_CT_RESPONSE_FS_RJT           0x8001
+#define  SLI_CT_RESPONSE_FS_ACC           0x8002
+
+/*
+ * Reason Codes
+ */
+
+#define  SLI_CT_NO_ADDITIONAL_EXPL	  0x0
+#define  SLI_CT_INVALID_COMMAND           0x01
+#define  SLI_CT_INVALID_VERSION           0x02
+#define  SLI_CT_LOGICAL_ERROR             0x03
+#define  SLI_CT_INVALID_IU_SIZE           0x04
+#define  SLI_CT_LOGICAL_BUSY              0x05
+#define  SLI_CT_PROTOCOL_ERROR            0x07
+#define  SLI_CT_UNABLE_TO_PERFORM_REQ     0x09
+#define  SLI_CT_REQ_NOT_SUPPORTED         0x0b
+#define  SLI_CT_HBA_INFO_NOT_REGISTERED	  0x10
+#define  SLI_CT_MULTIPLE_HBA_ATTR_OF_SAME_TYPE  0x11
+#define  SLI_CT_INVALID_HBA_ATTR_BLOCK_LEN      0x12
+#define  SLI_CT_HBA_ATTR_NOT_PRESENT	  0x13
+#define  SLI_CT_PORT_INFO_NOT_REGISTERED  0x20
+#define  SLI_CT_MULTIPLE_PORT_ATTR_OF_SAME_TYPE 0x21
+#define  SLI_CT_INVALID_PORT_ATTR_BLOCK_LEN     0x22
+#define  SLI_CT_VENDOR_UNIQUE             0xff
+
+/*
+ * Name Server SLI_CT_UNABLE_TO_PERFORM_REQ Explanations
+ */
+
+#define  SLI_CT_NO_PORT_ID                0x01
+#define  SLI_CT_NO_PORT_NAME              0x02
+#define  SLI_CT_NO_NODE_NAME              0x03
+#define  SLI_CT_NO_CLASS_OF_SERVICE       0x04
+#define  SLI_CT_NO_IP_ADDRESS             0x05
+#define  SLI_CT_NO_IPA                    0x06
+#define  SLI_CT_NO_FC4_TYPES              0x07
+#define  SLI_CT_NO_SYMBOLIC_PORT_NAME     0x08
+#define  SLI_CT_NO_SYMBOLIC_NODE_NAME     0x09
+#define  SLI_CT_NO_PORT_TYPE              0x0A
+#define  SLI_CT_ACCESS_DENIED             0x10
+#define  SLI_CT_INVALID_PORT_ID           0x11
+#define  SLI_CT_DATABASE_EMPTY            0x12
+
+/*
+ * Name Server Command Codes
+ */
+
+#define  SLI_CTNS_GA_NXT      0x0100
+#define  SLI_CTNS_GPN_ID      0x0112
+#define  SLI_CTNS_GNN_ID      0x0113
+#define  SLI_CTNS_GCS_ID      0x0114
+#define  SLI_CTNS_GFT_ID      0x0117
+#define  SLI_CTNS_GSPN_ID     0x0118
+#define  SLI_CTNS_GPT_ID      0x011A
+#define  SLI_CTNS_GID_PN      0x0121
+#define  SLI_CTNS_GID_NN      0x0131
+#define  SLI_CTNS_GIP_NN      0x0135
+#define  SLI_CTNS_GIPA_NN     0x0136
+#define  SLI_CTNS_GSNN_NN     0x0139
+#define  SLI_CTNS_GNN_IP      0x0153
+#define  SLI_CTNS_GIPA_IP     0x0156
+#define  SLI_CTNS_GID_FT      0x0171
+#define  SLI_CTNS_GID_PT      0x01A1
+#define  SLI_CTNS_RPN_ID      0x0212
+#define  SLI_CTNS_RNN_ID      0x0213
+#define  SLI_CTNS_RCS_ID      0x0214
+#define  SLI_CTNS_RFT_ID      0x0217
+#define  SLI_CTNS_RSPN_ID     0x0218
+#define  SLI_CTNS_RPT_ID      0x021A
+#define  SLI_CTNS_RIP_NN      0x0235
+#define  SLI_CTNS_RIPA_NN     0x0236
+#define  SLI_CTNS_RSNN_NN     0x0239
+#define  SLI_CTNS_DA_ID       0x0300
+
+/*
+ * Port Types
+ */
+
+#define  SLI_CTPT_N_PORT      0x01
+#define  SLI_CTPT_NL_PORT     0x02
+#define  SLI_CTPT_FNL_PORT    0x03
+#define  SLI_CTPT_IP          0x04
+#define  SLI_CTPT_FCP         0x08
+#define  SLI_CTPT_NX_PORT     0x7F
+#define  SLI_CTPT_F_PORT      0x81
+#define  SLI_CTPT_FL_PORT     0x82
+#define  SLI_CTPT_E_PORT      0x84
+
+#define SLI_CT_LAST_ENTRY     0x80000000
+
+/* Fibre Channel Service Parameter definitions */
+
+#define FC_PH_4_0   6		/* FC-PH version 4.0 */
+#define FC_PH_4_1   7		/* FC-PH version 4.1 */
+#define FC_PH_4_2   8		/* FC-PH version 4.2 */
+#define FC_PH_4_3   9		/* FC-PH version 4.3 */
+
+#define FC_PH_LOW   8		/* Lowest supported FC-PH version */
+#define FC_PH_HIGH  9		/* Highest supported FC-PH version */
+#define FC_PH3   0x20		/* FC-PH-3 version */
+
+#define FF_FRAME_SIZE     2048
+
+struct lpfc_name {
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint8_t nameType:4;	/* FC Word 0, bit 28:31 */
+	uint8_t IEEEextMsn:4;	/* FC Word 0, bit 24:27, bit 8:11 of IEEE ext */
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint8_t IEEEextMsn:4;	/* FC Word 0, bit 24:27, bit 8:11 of IEEE ext */
+	uint8_t nameType:4;	/* FC Word 0, bit 28:31 */
+#endif
+
+#define NAME_IEEE           0x1	/* IEEE name - nameType */
+#define NAME_IEEE_EXT       0x2	/* IEEE extended name */
+#define NAME_FC_TYPE        0x3	/* FC native name type */
+#define NAME_IP_TYPE        0x4	/* IP address */
+#define NAME_CCITT_TYPE     0xC
+#define NAME_CCITT_GR_TYPE  0xE
+	uint8_t IEEEextLsb;	/* FC Word 0, bit 16:23, IEEE extended Lsb */
+	uint8_t IEEE[6];	/* FC IEEE address */
+};
+
+struct csp {
+	uint8_t fcphHigh;	/* FC Word 0, byte 0 */
+	uint8_t fcphLow;
+	uint8_t bbCreditMsb;
+	uint8_t bbCreditlsb;	/* FC Word 0, byte 3 */
+
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint16_t increasingOffset:1;	/* FC Word 1, bit 31 */
+	uint16_t randomOffset:1;	/* FC Word 1, bit 30 */
+	uint16_t word1Reserved2:1;	/* FC Word 1, bit 29 */
+	uint16_t fPort:1;	/* FC Word 1, bit 28 */
+	uint16_t altBbCredit:1;	/* FC Word 1, bit 27 */
+	uint16_t edtovResolution:1;	/* FC Word 1, bit 26 */
+	uint16_t multicast:1;	/* FC Word 1, bit 25 */
+	uint16_t broadcast:1;	/* FC Word 1, bit 24 */
+
+	uint16_t huntgroup:1;	/* FC Word 1, bit 23 */
+	uint16_t simplex:1;	/* FC Word 1, bit 22 */
+	uint16_t word1Reserved1:3;	/* FC Word 1, bit 21:19 */
+	uint16_t dhd:1;		/* FC Word 1, bit 18 */
+	uint16_t contIncSeqCnt:1;	/* FC Word 1, bit 17 */
+	uint16_t payloadlength:1;	/* FC Word 1, bit 16 */
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint16_t broadcast:1;	/* FC Word 1, bit 24 */
+	uint16_t multicast:1;	/* FC Word 1, bit 25 */
+	uint16_t edtovResolution:1;	/* FC Word 1, bit 26 */
+	uint16_t altBbCredit:1;	/* FC Word 1, bit 27 */
+	uint16_t fPort:1;	/* FC Word 1, bit 28 */
+	uint16_t word1Reserved2:1;	/* FC Word 1, bit 29 */
+	uint16_t randomOffset:1;	/* FC Word 1, bit 30 */
+	uint16_t increasingOffset:1;	/* FC Word 1, bit 31 */
+
+	uint16_t payloadlength:1;	/* FC Word 1, bit 16 */
+	uint16_t contIncSeqCnt:1;	/* FC Word 1, bit 17 */
+	uint16_t dhd:1;		/* FC Word 1, bit 18 */
+	uint16_t word1Reserved1:3;	/* FC Word 1, bit 21:19 */
+	uint16_t simplex:1;	/* FC Word 1, bit 22 */
+	uint16_t huntgroup:1;	/* FC Word 1, bit 23 */
+#endif
+
+	uint8_t bbRcvSizeMsb;	/* Upper nibble is reserved */
+	uint8_t bbRcvSizeLsb;	/* FC Word 1, byte 3 */
+	union {
+		struct {
+			uint8_t word2Reserved1;	/* FC Word 2 byte 0 */
+
+			uint8_t totalConcurrSeq;	/* FC Word 2 byte 1 */
+			uint8_t roByCategoryMsb;	/* FC Word 2 byte 2 */
+
+			uint8_t roByCategoryLsb;	/* FC Word 2 byte 3 */
+		} nPort;
+		uint32_t r_a_tov;	/* R_A_TOV must be in B.E. format */
+	} w2;
+
+	uint32_t e_d_tov;	/* E_D_TOV must be in B.E. format */
+};
+
+struct class_parms {
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint8_t classValid:1;	/* FC Word 0, bit 31 */
+	uint8_t intermix:1;	/* FC Word 0, bit 30 */
+	uint8_t stackedXparent:1;	/* FC Word 0, bit 29 */
+	uint8_t stackedLockDown:1;	/* FC Word 0, bit 28 */
+	uint8_t seqDelivery:1;	/* FC Word 0, bit 27 */
+	uint8_t word0Reserved1:3;	/* FC Word 0, bit 24:26 */
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint8_t word0Reserved1:3;	/* FC Word 0, bit 24:26 */
+	uint8_t seqDelivery:1;	/* FC Word 0, bit 27 */
+	uint8_t stackedLockDown:1;	/* FC Word 0, bit 28 */
+	uint8_t stackedXparent:1;	/* FC Word 0, bit 29 */
+	uint8_t intermix:1;	/* FC Word 0, bit 30 */
+	uint8_t classValid:1;	/* FC Word 0, bit 31 */
+
+#endif
+
+	uint8_t word0Reserved2;	/* FC Word 0, bit 16:23 */
+
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint8_t iCtlXidReAssgn:2;	/* FC Word 0, Bit 14:15 */
+	uint8_t iCtlInitialPa:2;	/* FC Word 0, bit 12:13 */
+	uint8_t iCtlAck0capable:1;	/* FC Word 0, bit 11 */
+	uint8_t iCtlAckNcapable:1;	/* FC Word 0, bit 10 */
+	uint8_t word0Reserved3:2;	/* FC Word 0, bit  8: 9 */
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint8_t word0Reserved3:2;	/* FC Word 0, bit  8: 9 */
+	uint8_t iCtlAckNcapable:1;	/* FC Word 0, bit 10 */
+	uint8_t iCtlAck0capable:1;	/* FC Word 0, bit 11 */
+	uint8_t iCtlInitialPa:2;	/* FC Word 0, bit 12:13 */
+	uint8_t iCtlXidReAssgn:2;	/* FC Word 0, Bit 14:15 */
+#endif
+
+	uint8_t word0Reserved4;	/* FC Word 0, bit  0: 7 */
+
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint8_t rCtlAck0capable:1;	/* FC Word 1, bit 31 */
+	uint8_t rCtlAckNcapable:1;	/* FC Word 1, bit 30 */
+	uint8_t rCtlXidInterlck:1;	/* FC Word 1, bit 29 */
+	uint8_t rCtlErrorPolicy:2;	/* FC Word 1, bit 27:28 */
+	uint8_t word1Reserved1:1;	/* FC Word 1, bit 26 */
+	uint8_t rCtlCatPerSeq:2;	/* FC Word 1, bit 24:25 */
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint8_t rCtlCatPerSeq:2;	/* FC Word 1, bit 24:25 */
+	uint8_t word1Reserved1:1;	/* FC Word 1, bit 26 */
+	uint8_t rCtlErrorPolicy:2;	/* FC Word 1, bit 27:28 */
+	uint8_t rCtlXidInterlck:1;	/* FC Word 1, bit 29 */
+	uint8_t rCtlAckNcapable:1;	/* FC Word 1, bit 30 */
+	uint8_t rCtlAck0capable:1;	/* FC Word 1, bit 31 */
+#endif
+
+	uint8_t word1Reserved2;	/* FC Word 1, bit 16:23 */
+	uint8_t rcvDataSizeMsb;	/* FC Word 1, bit  8:15 */
+	uint8_t rcvDataSizeLsb;	/* FC Word 1, bit  0: 7 */
+
+	uint8_t concurrentSeqMsb;	/* FC Word 2, bit 24:31 */
+	uint8_t concurrentSeqLsb;	/* FC Word 2, bit 16:23 */
+	uint8_t EeCreditSeqMsb;	/* FC Word 2, bit  8:15 */
+	uint8_t EeCreditSeqLsb;	/* FC Word 2, bit  0: 7 */
+
+	uint8_t openSeqPerXchgMsb;	/* FC Word 3, bit 24:31 */
+	uint8_t openSeqPerXchgLsb;	/* FC Word 3, bit 16:23 */
+	uint8_t word3Reserved1;	/* Fc Word 3, bit  8:15 */
+	uint8_t word3Reserved2;	/* Fc Word 3, bit  0: 7 */
+};
+
+struct serv_parm {	/* Structure is in Big Endian format */
+	struct csp cmn;
+	struct lpfc_name portName;
+	struct lpfc_name nodeName;
+	struct class_parms cls1;
+	struct class_parms cls2;
+	struct class_parms cls3;
+	struct class_parms cls4;
+	uint8_t vendorVersion[16];
+};
+
+/*
+ *  Extended Link Service LS_COMMAND codes (Payload Word 0)
+ */
+#ifdef __BIG_ENDIAN_BITFIELD
+#define ELS_CMD_MASK      0xffff0000
+#define ELS_RSP_MASK      0xff000000
+#define ELS_CMD_LS_RJT    0x01000000
+#define ELS_CMD_ACC       0x02000000
+#define ELS_CMD_PLOGI     0x03000000
+#define ELS_CMD_FLOGI     0x04000000
+#define ELS_CMD_LOGO      0x05000000
+#define ELS_CMD_ABTX      0x06000000
+#define ELS_CMD_RCS       0x07000000
+#define ELS_CMD_RES       0x08000000
+#define ELS_CMD_RSS       0x09000000
+#define ELS_CMD_RSI       0x0A000000
+#define ELS_CMD_ESTS      0x0B000000
+#define ELS_CMD_ESTC      0x0C000000
+#define ELS_CMD_ADVC      0x0D000000
+#define ELS_CMD_RTV       0x0E000000
+#define ELS_CMD_RLS       0x0F000000
+#define ELS_CMD_ECHO      0x10000000
+#define ELS_CMD_TEST      0x11000000
+#define ELS_CMD_RRQ       0x12000000
+#define ELS_CMD_PRLI      0x20100014
+#define ELS_CMD_PRLO      0x21100014
+#define ELS_CMD_PDISC     0x50000000
+#define ELS_CMD_FDISC     0x51000000
+#define ELS_CMD_ADISC     0x52000000
+#define ELS_CMD_FARP      0x54000000
+#define ELS_CMD_FARPR     0x55000000
+#define ELS_CMD_FAN       0x60000000
+#define ELS_CMD_RSCN      0x61040000
+#define ELS_CMD_SCR       0x62000000
+#define ELS_CMD_RNID      0x78000000
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+#define ELS_CMD_MASK      0xffff
+#define ELS_RSP_MASK      0xff
+#define ELS_CMD_LS_RJT    0x01
+#define ELS_CMD_ACC       0x02
+#define ELS_CMD_PLOGI     0x03
+#define ELS_CMD_FLOGI     0x04
+#define ELS_CMD_LOGO      0x05
+#define ELS_CMD_ABTX      0x06
+#define ELS_CMD_RCS       0x07
+#define ELS_CMD_RES       0x08
+#define ELS_CMD_RSS       0x09
+#define ELS_CMD_RSI       0x0A
+#define ELS_CMD_ESTS      0x0B
+#define ELS_CMD_ESTC      0x0C
+#define ELS_CMD_ADVC      0x0D
+#define ELS_CMD_RTV       0x0E
+#define ELS_CMD_RLS       0x0F
+#define ELS_CMD_ECHO      0x10
+#define ELS_CMD_TEST      0x11
+#define ELS_CMD_RRQ       0x12
+#define ELS_CMD_PRLI      0x14001020
+#define ELS_CMD_PRLO      0x14001021
+#define ELS_CMD_PDISC     0x50
+#define ELS_CMD_FDISC     0x51
+#define ELS_CMD_ADISC     0x52
+#define ELS_CMD_FARP      0x54
+#define ELS_CMD_FARPR     0x55
+#define ELS_CMD_FAN       0x60
+#define ELS_CMD_RSCN      0x0461
+#define ELS_CMD_SCR       0x62
+#define ELS_CMD_RNID      0x78
+#endif
+
+/*
+ *  LS_RJT Payload Definition
+ */
+
+struct ls_rjt {	/* Structure is in Big Endian format */
+	union {
+		uint32_t lsRjtError;
+		struct {
+			uint8_t lsRjtRsvd0;	/* FC Word 0, bit 24:31 */
+
+			uint8_t lsRjtRsnCode;	/* FC Word 0, bit 16:23 */
+			/* LS_RJT reason codes */
+#define LSRJT_INVALID_CMD     0x01
+#define LSRJT_LOGICAL_ERR     0x03
+#define LSRJT_LOGICAL_BSY     0x05
+#define LSRJT_PROTOCOL_ERR    0x07
+#define LSRJT_UNABLE_TPC      0x09	/* Unable to perform command */
+#define LSRJT_CMD_UNSUPPORTED 0x0B
+#define LSRJT_VENDOR_UNIQUE   0xFF	/* See Byte 3 */
+
+			uint8_t lsRjtRsnCodeExp; /* FC Word 0, bit 8:15 */
+			/* LS_RJT reason explanation */
+#define LSEXP_NOTHING_MORE      0x00
+#define LSEXP_SPARM_OPTIONS     0x01
+#define LSEXP_SPARM_ICTL        0x03
+#define LSEXP_SPARM_RCTL        0x05
+#define LSEXP_SPARM_RCV_SIZE    0x07
+#define LSEXP_SPARM_CONCUR_SEQ  0x09
+#define LSEXP_SPARM_CREDIT      0x0B
+#define LSEXP_INVALID_PNAME     0x0D
+#define LSEXP_INVALID_NNAME     0x0E
+#define LSEXP_INVALID_CSP       0x0F
+#define LSEXP_INVALID_ASSOC_HDR 0x11
+#define LSEXP_ASSOC_HDR_REQ     0x13
+#define LSEXP_INVALID_O_SID     0x15
+#define LSEXP_INVALID_OX_RX     0x17
+#define LSEXP_CMD_IN_PROGRESS   0x19
+#define LSEXP_INVALID_NPORT_ID  0x1F
+#define LSEXP_INVALID_SEQ_ID    0x21
+#define LSEXP_INVALID_XCHG      0x23
+#define LSEXP_INACTIVE_XCHG     0x25
+#define LSEXP_RQ_REQUIRED       0x27
+#define LSEXP_OUT_OF_RESOURCE   0x29
+#define LSEXP_CANT_GIVE_DATA    0x2A
+#define LSEXP_REQ_UNSUPPORTED   0x2C
+			uint8_t vendorUnique;	/* FC Word 0, bit  0: 7 */
+		} b;
+	} un;
+};
+
+/*
+ *  N_Port Login (FLOGO/PLOGO Request) Payload Definition
+ */
+
+typedef struct _LOGO {		/* Structure is in Big Endian format */
+	union {
+		uint32_t nPortId32;	/* Access nPortId as a word */
+		struct {
+			uint8_t word1Reserved1;	/* FC Word 1, bit 31:24 */
+			uint8_t nPortIdByte0;	/* N_port  ID bit 16:23 */
+			uint8_t nPortIdByte1;	/* N_port  ID bit  8:15 */
+			uint8_t nPortIdByte2;	/* N_port  ID bit  0: 7 */
+		} b;
+	} un;
+	struct lpfc_name portName;	/* N_port name field */
+} LOGO;
+
+/*
+ *  FCP Login (PRLI Request / ACC) Payload Definition
+ */
+
+#define PRLX_PAGE_LEN   0x10
+#define TPRLO_PAGE_LEN  0x14
+
+typedef struct _PRLI {		/* Structure is in Big Endian format */
+	uint8_t prliType;	/* FC Parm Word 0, bit 24:31 */
+
+#define PRLI_FCP_TYPE 0x08
+	uint8_t word0Reserved1;	/* FC Parm Word 0, bit 16:23 */
+
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint8_t origProcAssocV:1;	/* FC Parm Word 0, bit 15 */
+	uint8_t respProcAssocV:1;	/* FC Parm Word 0, bit 14 */
+	uint8_t estabImagePair:1;	/* FC Parm Word 0, bit 13 */
+
+	/*    ACC = imagePairEstablished */
+	uint8_t word0Reserved2:1;	/* FC Parm Word 0, bit 12 */
+	uint8_t acceptRspCode:4;	/* FC Parm Word 0, bit 8:11, ACC ONLY */
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint8_t acceptRspCode:4;	/* FC Parm Word 0, bit 8:11, ACC ONLY */
+	uint8_t word0Reserved2:1;	/* FC Parm Word 0, bit 12 */
+	uint8_t estabImagePair:1;	/* FC Parm Word 0, bit 13 */
+	uint8_t respProcAssocV:1;	/* FC Parm Word 0, bit 14 */
+	uint8_t origProcAssocV:1;	/* FC Parm Word 0, bit 15 */
+	/*    ACC = imagePairEstablished */
+#endif
+
+#define PRLI_REQ_EXECUTED     0x1	/* acceptRspCode */
+#define PRLI_NO_RESOURCES     0x2
+#define PRLI_INIT_INCOMPLETE  0x3
+#define PRLI_NO_SUCH_PA       0x4
+#define PRLI_PREDEF_CONFIG    0x5
+#define PRLI_PARTIAL_SUCCESS  0x6
+#define PRLI_INVALID_PAGE_CNT 0x7
+	uint8_t word0Reserved3;	/* FC Parm Word 0, bit 0:7 */
+
+	uint32_t origProcAssoc;	/* FC Parm Word 1, bit 0:31 */
+
+	uint32_t respProcAssoc;	/* FC Parm Word 2, bit 0:31 */
+
+	uint8_t word3Reserved1;	/* FC Parm Word 3, bit 24:31 */
+	uint8_t word3Reserved2;	/* FC Parm Word 3, bit 16:23 */
+
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint16_t Word3bit15Resved:1;	/* FC Parm Word 3, bit 15 */
+	uint16_t Word3bit14Resved:1;	/* FC Parm Word 3, bit 14 */
+	uint16_t Word3bit13Resved:1;	/* FC Parm Word 3, bit 13 */
+	uint16_t Word3bit12Resved:1;	/* FC Parm Word 3, bit 12 */
+	uint16_t Word3bit11Resved:1;	/* FC Parm Word 3, bit 11 */
+	uint16_t Word3bit10Resved:1;	/* FC Parm Word 3, bit 10 */
+	uint16_t TaskRetryIdReq:1;	/* FC Parm Word 3, bit  9 */
+	uint16_t Retry:1;	/* FC Parm Word 3, bit  8 */
+	uint16_t ConfmComplAllowed:1;	/* FC Parm Word 3, bit  7 */
+	uint16_t dataOverLay:1;	/* FC Parm Word 3, bit  6 */
+	uint16_t initiatorFunc:1;	/* FC Parm Word 3, bit  5 */
+	uint16_t targetFunc:1;	/* FC Parm Word 3, bit  4 */
+	uint16_t cmdDataMixEna:1;	/* FC Parm Word 3, bit  3 */
+	uint16_t dataRspMixEna:1;	/* FC Parm Word 3, bit  2 */
+	uint16_t readXferRdyDis:1;	/* FC Parm Word 3, bit  1 */
+	uint16_t writeXferRdyDis:1;	/* FC Parm Word 3, bit  0 */
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint16_t Retry:1;	/* FC Parm Word 3, bit  8 */
+	uint16_t TaskRetryIdReq:1;	/* FC Parm Word 3, bit  9 */
+	uint16_t Word3bit10Resved:1;	/* FC Parm Word 3, bit 10 */
+	uint16_t Word3bit11Resved:1;	/* FC Parm Word 3, bit 11 */
+	uint16_t Word3bit12Resved:1;	/* FC Parm Word 3, bit 12 */
+	uint16_t Word3bit13Resved:1;	/* FC Parm Word 3, bit 13 */
+	uint16_t Word3bit14Resved:1;	/* FC Parm Word 3, bit 14 */
+	uint16_t Word3bit15Resved:1;	/* FC Parm Word 3, bit 15 */
+	uint16_t writeXferRdyDis:1;	/* FC Parm Word 3, bit  0 */
+	uint16_t readXferRdyDis:1;	/* FC Parm Word 3, bit  1 */
+	uint16_t dataRspMixEna:1;	/* FC Parm Word 3, bit  2 */
+	uint16_t cmdDataMixEna:1;	/* FC Parm Word 3, bit  3 */
+	uint16_t targetFunc:1;	/* FC Parm Word 3, bit  4 */
+	uint16_t initiatorFunc:1;	/* FC Parm Word 3, bit  5 */
+	uint16_t dataOverLay:1;	/* FC Parm Word 3, bit  6 */
+	uint16_t ConfmComplAllowed:1;	/* FC Parm Word 3, bit  7 */
+#endif
+} PRLI;
+
+/*
+ *  FCP Logout (PRLO Request / ACC) Payload Definition
+ */
+
+typedef struct _PRLO {		/* Structure is in Big Endian format */
+	uint8_t prloType;	/* FC Parm Word 0, bit 24:31 */
+
+#define PRLO_FCP_TYPE  0x08
+	uint8_t word0Reserved1;	/* FC Parm Word 0, bit 16:23 */
+
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint8_t origProcAssocV:1;	/* FC Parm Word 0, bit 15 */
+	uint8_t respProcAssocV:1;	/* FC Parm Word 0, bit 14 */
+	uint8_t word0Reserved2:2;	/* FC Parm Word 0, bit 12:13 */
+	uint8_t acceptRspCode:4;	/* FC Parm Word 0, bit 8:11, ACC ONLY */
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint8_t acceptRspCode:4;	/* FC Parm Word 0, bit 8:11, ACC ONLY */
+	uint8_t word0Reserved2:2;	/* FC Parm Word 0, bit 12:13 */
+	uint8_t respProcAssocV:1;	/* FC Parm Word 0, bit 14 */
+	uint8_t origProcAssocV:1;	/* FC Parm Word 0, bit 15 */
+#endif
+
+#define PRLO_REQ_EXECUTED     0x1	/* acceptRspCode */
+#define PRLO_NO_SUCH_IMAGE    0x4
+#define PRLO_INVALID_PAGE_CNT 0x7
+
+	uint8_t word0Reserved3;	/* FC Parm Word 0, bit 0:7 */
+
+	uint32_t origProcAssoc;	/* FC Parm Word 1, bit 0:31 */
+
+	uint32_t respProcAssoc;	/* FC Parm Word 2, bit 0:31 */
+
+	uint32_t word3Reserved1;	/* FC Parm Word 3, bit 0:31 */
+} PRLO;
+
+typedef struct _ADISC {		/* Structure is in Big Endian format */
+	uint32_t hardAL_PA;
+	struct lpfc_name portName;
+	struct lpfc_name nodeName;
+	uint32_t DID;
+} ADISC;
+
+typedef struct _FARP {		/* Structure is in Big Endian format */
+	uint32_t Mflags:8;
+	uint32_t Odid:24;
+#define FARP_NO_ACTION          0	/* FARP information enclosed, no
+					   action */
+#define FARP_MATCH_PORT         0x1	/* Match on Responder Port Name */
+#define FARP_MATCH_NODE         0x2	/* Match on Responder Node Name */
+#define FARP_MATCH_IP           0x4	/* Match on IP address, not supported */
+#define FARP_MATCH_IPV4         0x5	/* Match on IPV4 address, not
+					   supported */
+#define FARP_MATCH_IPV6         0x6	/* Match on IPV6 address, not
+					   supported */
+	uint32_t Rflags:8;
+	uint32_t Rdid:24;
+#define FARP_REQUEST_PLOGI      0x1	/* Request for PLOGI */
+#define FARP_REQUEST_FARPR      0x2	/* Request for FARP Response */
+	struct lpfc_name OportName;
+	struct lpfc_name OnodeName;
+	struct lpfc_name RportName;
+	struct lpfc_name RnodeName;
+	uint8_t Oipaddr[16];
+	uint8_t Ripaddr[16];
+} FARP;
+
+typedef struct _FAN {		/* Structure is in Big Endian format */
+	uint32_t Fdid;
+	struct lpfc_name FportName;
+	struct lpfc_name FnodeName;
+} FAN;
+
+typedef struct _SCR {		/* Structure is in Big Endian format */
+	uint8_t resvd1;
+	uint8_t resvd2;
+	uint8_t resvd3;
+	uint8_t Function;
+#define  SCR_FUNC_FABRIC     0x01
+#define  SCR_FUNC_NPORT      0x02
+#define  SCR_FUNC_FULL       0x03
+#define  SCR_CLEAR           0xff
+} SCR;
+
+typedef struct _RNID_TOP_DISC {
+	struct lpfc_name portName;
+	uint8_t resvd[8];
+	uint32_t unitType;
+#define RNID_HBA            0x7
+#define RNID_HOST           0xa
+#define RNID_DRIVER         0xd
+	uint32_t physPort;
+	uint32_t attachedNodes;
+	uint16_t ipVersion;
+#define RNID_IPV4           0x1
+#define RNID_IPV6           0x2
+	uint16_t UDPport;
+	uint8_t ipAddr[16];
+	uint16_t resvd1;
+	uint16_t flags;
+#define RNID_TD_SUPPORT     0x1
+#define RNID_LP_VALID       0x2
+} RNID_TOP_DISC;
+
+typedef struct _RNID {		/* Structure is in Big Endian format */
+	uint8_t Format;
+#define RNID_TOPOLOGY_DISC  0xdf
+	uint8_t CommonLen;
+	uint8_t resvd1;
+	uint8_t SpecificLen;
+	struct lpfc_name portName;
+	struct lpfc_name nodeName;
+	union {
+		RNID_TOP_DISC topologyDisc;	/* topology disc (0xdf) */
+	} un;
+} RNID;
+
+typedef struct _RRQ {		/* Structure is in Big Endian format */
+	uint32_t SID;
+	uint16_t Oxid;
+	uint16_t Rxid;
+	uint8_t resv[32];	/* optional association hdr */
+} RRQ;
+
+/* This is used for RSCN command */
+typedef struct _D_ID {		/* Structure is in Big Endian format */
+	union {
+		uint32_t word;
+		struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+			uint8_t resv;
+			uint8_t domain;
+			uint8_t area;
+			uint8_t id;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+			uint8_t id;
+			uint8_t area;
+			uint8_t domain;
+			uint8_t resv;
+#endif
+		} b;
+	} un;
+} D_ID;
+
+/*
+ *  Structure to define all ELS Payload types
+ */
+
+typedef struct _ELS_PKT {	/* Structure is in Big Endian format */
+	uint8_t elsCode;	/* FC Word 0, bit 24:31 */
+	uint8_t elsByte1;
+	uint8_t elsByte2;
+	uint8_t elsByte3;
+	union {
+		struct ls_rjt lsRjt;	/* Payload for LS_RJT ELS response */
+		struct serv_parm logi;	/* Payload for PLOGI/FLOGI/PDISC/ACC */
+		LOGO logo;	/* Payload for PLOGO/FLOGO/ACC */
+		PRLI prli;	/* Payload for PRLI/ACC */
+		PRLO prlo;	/* Payload for PRLO/ACC */
+		ADISC adisc;	/* Payload for ADISC/ACC */
+		FARP farp;	/* Payload for FARP/ACC */
+		FAN fan;	/* Payload for FAN */
+		SCR scr;	/* Payload for SCR/ACC */
+		RRQ rrq;	/* Payload for RRQ */
+		RNID rnid;	/* Payload for RNID */
+		uint8_t pad[128 - 4];	/* Pad out to payload of 128 bytes */
+	} un;
+} ELS_PKT;
+
+/*
+ * FDMI
+ * HBA MAnagement Operations Command Codes
+ */
+#define  SLI_MGMT_GRHL     0x100	/* Get registered HBA list */
+#define  SLI_MGMT_GHAT     0x101	/* Get HBA attributes */
+#define  SLI_MGMT_GRPL     0x102	/* Get registered Port list */
+#define  SLI_MGMT_GPAT     0x110	/* Get Port attributes */
+#define  SLI_MGMT_RHBA     0x200	/* Register HBA */
+#define  SLI_MGMT_RHAT     0x201	/* Register HBA atttributes */
+#define  SLI_MGMT_RPRT     0x210	/* Register Port */
+#define  SLI_MGMT_RPA      0x211	/* Register Port attributes */
+#define  SLI_MGMT_DHBA     0x300	/* De-register HBA */
+#define  SLI_MGMT_DPRT     0x310	/* De-register Port */
+
+/*
+ * Management Service Subtypes
+ */
+#define  SLI_CT_FDMI_Subtypes     0x10
+
+/*
+ * HBA Management Service Reject Code
+ */
+#define  REJECT_CODE             0x9	/* Unable to perform command request */
+
+/*
+ * HBA Management Service Reject Reason Code
+ * Please refer to the Reason Codes above
+ */
+
+/*
+ * HBA Attribute Types
+ */
+#define  NODE_NAME               0x1
+#define  MANUFACTURER            0x2
+#define  SERIAL_NUMBER           0x3
+#define  MODEL                   0x4
+#define  MODEL_DESCRIPTION       0x5
+#define  HARDWARE_VERSION        0x6
+#define  DRIVER_VERSION          0x7
+#define  OPTION_ROM_VERSION      0x8
+#define  FIRMWARE_VERSION        0x9
+#define  OS_NAME_VERSION	 0xa
+#define  MAX_CT_PAYLOAD_LEN	 0xb
+
+/*
+ * Port Attrubute Types
+ */
+#define  SUPPORTED_FC4_TYPES     0x1
+#define  SUPPORTED_SPEED         0x2
+#define  PORT_SPEED              0x3
+#define  MAX_FRAME_SIZE          0x4
+#define  OS_DEVICE_NAME          0x5
+#define  HOST_NAME               0x6
+
+union AttributesDef {
+	/* Structure is in Big Endian format */
+	struct {
+		uint32_t AttrType:16;
+		uint32_t AttrLen:16;
+	} bits;
+	uint32_t word;
+};
+
+
+/*
+ * HBA Attribute Entry (8 - 260 bytes)
+ */
+typedef struct {
+	union AttributesDef ad;
+	union {
+		uint32_t VendorSpecific;
+		uint8_t Manufacturer[64];
+		uint8_t SerialNumber[64];
+		uint8_t Model[256];
+		uint8_t ModelDescription[256];
+		uint8_t HardwareVersion[256];
+		uint8_t DriverVersion[256];
+		uint8_t OptionROMVersion[256];
+		uint8_t FirmwareVersion[256];
+		struct lpfc_name NodeName;
+		uint8_t SupportFC4Types[32];
+		uint32_t SupportSpeed;
+		uint32_t PortSpeed;
+		uint32_t MaxFrameSize;
+		uint8_t OsDeviceName[256];
+		uint8_t OsNameVersion[256];
+		uint32_t MaxCTPayloadLen;
+		uint8_t HostName[256];
+	} un;
+} ATTRIBUTE_ENTRY;
+
+/*
+ * HBA Attribute Block
+ */
+typedef struct {
+	uint32_t EntryCnt;	/* Number of HBA attribute entries */
+	ATTRIBUTE_ENTRY Entry;	/* Variable-length array */
+} ATTRIBUTE_BLOCK;
+
+/*
+ * Port Entry
+ */
+typedef struct {
+	struct lpfc_name PortName;
+} PORT_ENTRY;
+
+/*
+ * HBA Identifier
+ */
+typedef struct {
+	struct lpfc_name PortName;
+} HBA_IDENTIFIER;
+
+/*
+ * Registered Port List Format
+ */
+typedef struct {
+	uint32_t EntryCnt;
+	PORT_ENTRY pe;		/* Variable-length array */
+} REG_PORT_LIST;
+
+/*
+ * Register HBA(RHBA)
+ */
+typedef struct {
+	HBA_IDENTIFIER hi;
+	REG_PORT_LIST rpl;	/* variable-length array */
+/* ATTRIBUTE_BLOCK   ab; */
+} REG_HBA;
+
+/*
+ * Register HBA Attributes (RHAT)
+ */
+typedef struct {
+	struct lpfc_name HBA_PortName;
+	ATTRIBUTE_BLOCK ab;
+} REG_HBA_ATTRIBUTE;
+
+/*
+ * Register Port Attributes (RPA)
+ */
+typedef struct {
+	struct lpfc_name PortName;
+	ATTRIBUTE_BLOCK ab;
+} REG_PORT_ATTRIBUTE;
+
+/*
+ * Get Registered HBA List (GRHL) Accept Payload Format
+ */
+typedef struct {
+	uint32_t HBA__Entry_Cnt; /* Number of Registered HBA Identifiers */
+	struct lpfc_name HBA_PortName;	/* Variable-length array */
+} GRHL_ACC_PAYLOAD;
+
+/*
+ * Get Registered Port List (GRPL) Accept Payload Format
+ */
+typedef struct {
+	uint32_t RPL_Entry_Cnt;	/* Number of Registered Port Entries */
+	PORT_ENTRY Reg_Port_Entry[1];	/* Variable-length array */
+} GRPL_ACC_PAYLOAD;
+
+/*
+ * Get Port Attributes (GPAT) Accept Payload Format
+ */
+
+typedef struct {
+	ATTRIBUTE_BLOCK pab;
+} GPAT_ACC_PAYLOAD;
+
+
+/*
+ *  Begin HBA configuration parameters.
+ *  The PCI configuration register BAR assignments are:
+ *  BAR0, offset 0x10 - SLIM base memory address
+ *  BAR1, offset 0x14 - SLIM base memory high address
+ *  BAR2, offset 0x18 - REGISTER base memory address
+ *  BAR3, offset 0x1c - REGISTER base memory high address
+ *  BAR4, offset 0x20 - BIU I/O registers
+ *  BAR5, offset 0x24 - REGISTER base io high address
+ */
+
+/* Number of rings currently used and available. */
+#define MAX_CONFIGURED_RINGS     3
+#define MAX_RINGS                4
+
+/* IOCB / Mailbox is owned by FireFly */
+#define OWN_CHIP        1
+
+/* IOCB / Mailbox is owned by Host */
+#define OWN_HOST        0
+
+/* Number of 4-byte words in an IOCB. */
+#define IOCB_WORD_SZ    8
+
+/* defines for type field in fc header */
+#define FC_ELS_DATA     0x1
+#define FC_LLC_SNAP     0x5
+#define FC_FCP_DATA     0x8
+#define FC_COMMON_TRANSPORT_ULP 0x20
+
+/* defines for rctl field in fc header */
+#define FC_DEV_DATA     0x0
+#define FC_UNSOL_CTL    0x2
+#define FC_SOL_CTL      0x3
+#define FC_UNSOL_DATA   0x4
+#define FC_FCP_CMND     0x6
+#define FC_ELS_REQ      0x22
+#define FC_ELS_RSP      0x23
+
+/* network headers for Dfctl field */
+#define FC_NET_HDR      0x20
+
+/* Start FireFly Register definitions */
+#define PCI_VENDOR_ID_EMULEX        0x10df
+#define PCI_DEVICE_ID_FIREFLY 	    0x1ae5
+#define PCI_DEVICE_ID_SUPERFLY      0xf700
+#define PCI_DEVICE_ID_DRAGONFLY     0xf800
+#define PCI_DEVICE_ID_RFLY          0xf095
+#define PCI_DEVICE_ID_PFLY          0xf098
+#define PCI_DEVICE_ID_TFLY          0xf0a5
+#define PCI_DEVICE_ID_CENTAUR       0xf900
+#define PCI_DEVICE_ID_PEGASUS       0xf980
+#define PCI_DEVICE_ID_THOR          0xfa00
+#define PCI_DEVICE_ID_VIPER         0xfb00
+#define PCI_DEVICE_ID_HELIOS        0xfd00
+#define PCI_DEVICE_ID_BMID          0xf0d5
+#define PCI_DEVICE_ID_BSMB          0xf0d1
+#define PCI_DEVICE_ID_ZEPHYR        0xfe00
+#define PCI_DEVICE_ID_ZMID          0xf0e5
+#define PCI_DEVICE_ID_ZSMB          0xf0e1
+#define PCI_DEVICE_ID_LP101	    0xf0a1
+#define PCI_DEVICE_ID_LP10000S	    0xfc00
+
+#define JEDEC_ID_ADDRESS            0x0080001c
+#define FIREFLY_JEDEC_ID            0x1ACC
+#define SUPERFLY_JEDEC_ID           0x0020
+#define DRAGONFLY_JEDEC_ID          0x0021
+#define DRAGONFLY_V2_JEDEC_ID       0x0025
+#define CENTAUR_2G_JEDEC_ID         0x0026
+#define CENTAUR_1G_JEDEC_ID         0x0028
+#define PEGASUS_ORION_JEDEC_ID      0x0036
+#define PEGASUS_JEDEC_ID            0x0038
+#define THOR_JEDEC_ID               0x0012
+#define HELIOS_JEDEC_ID             0x0364
+#define ZEPHYR_JEDEC_ID             0x0577
+#define VIPER_JEDEC_ID              0x4838
+
+#define JEDEC_ID_MASK               0x0FFFF000
+#define JEDEC_ID_SHIFT              12
+#define FC_JEDEC_ID(id)             ((id & JEDEC_ID_MASK) >> JEDEC_ID_SHIFT)
+
+typedef struct {		/* FireFly BIU registers */
+	uint32_t hostAtt;	/* See definitions for Host Attention
+				   register */
+	uint32_t chipAtt;	/* See definitions for Chip Attention
+				   register */
+	uint32_t hostStatus;	/* See definitions for Host Status register */
+	uint32_t hostControl;	/* See definitions for Host Control register */
+	uint32_t buiConfig;	/* See definitions for BIU configuration
+				   register */
+} FF_REGS;
+
+/* IO Register size in bytes */
+#define FF_REG_AREA_SIZE       256
+
+/* Host Attention Register */
+
+#define HA_REG_OFFSET  0	/* Word offset from register base address */
+
+#define HA_R0RE_REQ    0x00000001	/* Bit  0 */
+#define HA_R0CE_RSP    0x00000002	/* Bit  1 */
+#define HA_R0ATT       0x00000008	/* Bit  3 */
+#define HA_R1RE_REQ    0x00000010	/* Bit  4 */
+#define HA_R1CE_RSP    0x00000020	/* Bit  5 */
+#define HA_R1ATT       0x00000080	/* Bit  7 */
+#define HA_R2RE_REQ    0x00000100	/* Bit  8 */
+#define HA_R2CE_RSP    0x00000200	/* Bit  9 */
+#define HA_R2ATT       0x00000800	/* Bit 11 */
+#define HA_R3RE_REQ    0x00001000	/* Bit 12 */
+#define HA_R3CE_RSP    0x00002000	/* Bit 13 */
+#define HA_R3ATT       0x00008000	/* Bit 15 */
+#define HA_LATT        0x20000000	/* Bit 29 */
+#define HA_MBATT       0x40000000	/* Bit 30 */
+#define HA_ERATT       0x80000000	/* Bit 31 */
+
+#define HA_RXRE_REQ    0x00000001	/* Bit  0 */
+#define HA_RXCE_RSP    0x00000002	/* Bit  1 */
+#define HA_RXATT       0x00000008	/* Bit  3 */
+#define HA_RXMASK      0x0000000f
+
+/* Chip Attention Register */
+
+#define CA_REG_OFFSET  1	/* Word offset from register base address */
+
+#define CA_R0CE_REQ    0x00000001	/* Bit  0 */
+#define CA_R0RE_RSP    0x00000002	/* Bit  1 */
+#define CA_R0ATT       0x00000008	/* Bit  3 */
+#define CA_R1CE_REQ    0x00000010	/* Bit  4 */
+#define CA_R1RE_RSP    0x00000020	/* Bit  5 */
+#define CA_R1ATT       0x00000080	/* Bit  7 */
+#define CA_R2CE_REQ    0x00000100	/* Bit  8 */
+#define CA_R2RE_RSP    0x00000200	/* Bit  9 */
+#define CA_R2ATT       0x00000800	/* Bit 11 */
+#define CA_R3CE_REQ    0x00001000	/* Bit 12 */
+#define CA_R3RE_RSP    0x00002000	/* Bit 13 */
+#define CA_R3ATT       0x00008000	/* Bit 15 */
+#define CA_MBATT       0x40000000	/* Bit 30 */
+
+/* Host Status Register */
+
+#define HS_REG_OFFSET  2	/* Word offset from register base address */
+
+#define HS_MBRDY       0x00400000	/* Bit 22 */
+#define HS_FFRDY       0x00800000	/* Bit 23 */
+#define HS_FFER8       0x01000000	/* Bit 24 */
+#define HS_FFER7       0x02000000	/* Bit 25 */
+#define HS_FFER6       0x04000000	/* Bit 26 */
+#define HS_FFER5       0x08000000	/* Bit 27 */
+#define HS_FFER4       0x10000000	/* Bit 28 */
+#define HS_FFER3       0x20000000	/* Bit 29 */
+#define HS_FFER2       0x40000000	/* Bit 30 */
+#define HS_FFER1       0x80000000	/* Bit 31 */
+#define HS_FFERM       0xFF000000	/* Mask for error bits 31:24 */
+
+/* Host Control Register */
+
+#define HC_REG_OFFSET  3	/* Word offset from register base address */
+
+#define HC_MBINT_ENA   0x00000001	/* Bit  0 */
+#define HC_R0INT_ENA   0x00000002	/* Bit  1 */
+#define HC_R1INT_ENA   0x00000004	/* Bit  2 */
+#define HC_R2INT_ENA   0x00000008	/* Bit  3 */
+#define HC_R3INT_ENA   0x00000010	/* Bit  4 */
+#define HC_INITHBI     0x02000000	/* Bit 25 */
+#define HC_INITMB      0x04000000	/* Bit 26 */
+#define HC_INITFF      0x08000000	/* Bit 27 */
+#define HC_LAINT_ENA   0x20000000	/* Bit 29 */
+#define HC_ERINT_ENA   0x80000000	/* Bit 31 */
+
+/* Mailbox Commands */
+#define MBX_SHUTDOWN        0x00	/* terminate testing */
+#define MBX_LOAD_SM         0x01
+#define MBX_READ_NV         0x02
+#define MBX_WRITE_NV        0x03
+#define MBX_RUN_BIU_DIAG    0x04
+#define MBX_INIT_LINK       0x05
+#define MBX_DOWN_LINK       0x06
+#define MBX_CONFIG_LINK     0x07
+#define MBX_CONFIG_RING     0x09
+#define MBX_RESET_RING      0x0A
+#define MBX_READ_CONFIG     0x0B
+#define MBX_READ_RCONFIG    0x0C
+#define MBX_READ_SPARM      0x0D
+#define MBX_READ_STATUS     0x0E
+#define MBX_READ_RPI        0x0F
+#define MBX_READ_XRI        0x10
+#define MBX_READ_REV        0x11
+#define MBX_READ_LNK_STAT   0x12
+#define MBX_REG_LOGIN       0x13
+#define MBX_UNREG_LOGIN     0x14
+#define MBX_READ_LA         0x15
+#define MBX_CLEAR_LA        0x16
+#define MBX_DUMP_MEMORY     0x17
+#define MBX_DUMP_CONTEXT    0x18
+#define MBX_RUN_DIAGS       0x19
+#define MBX_RESTART         0x1A
+#define MBX_UPDATE_CFG      0x1B
+#define MBX_DOWN_LOAD       0x1C
+#define MBX_DEL_LD_ENTRY    0x1D
+#define MBX_RUN_PROGRAM     0x1E
+#define MBX_SET_MASK        0x20
+#define MBX_SET_SLIM        0x21
+#define MBX_UNREG_D_ID      0x23
+#define MBX_CONFIG_FARP     0x25
+
+#define MBX_LOAD_AREA       0x81
+#define MBX_RUN_BIU_DIAG64  0x84
+#define MBX_CONFIG_PORT     0x88
+#define MBX_READ_SPARM64    0x8D
+#define MBX_READ_RPI64      0x8F
+#define MBX_REG_LOGIN64     0x93
+#define MBX_READ_LA64       0x95
+
+#define MBX_FLASH_WR_ULA    0x98
+#define MBX_SET_DEBUG       0x99
+#define MBX_LOAD_EXP_ROM    0x9C
+
+#define MBX_MAX_CMDS        0x9D
+#define MBX_SLI2_CMD_MASK   0x80
+
+/* IOCB Commands */
+
+#define CMD_RCV_SEQUENCE_CX     0x01
+#define CMD_XMIT_SEQUENCE_CR    0x02
+#define CMD_XMIT_SEQUENCE_CX    0x03
+#define CMD_XMIT_BCAST_CN       0x04
+#define CMD_XMIT_BCAST_CX       0x05
+#define CMD_QUE_RING_BUF_CN     0x06
+#define CMD_QUE_XRI_BUF_CX      0x07
+#define CMD_IOCB_CONTINUE_CN    0x08
+#define CMD_RET_XRI_BUF_CX      0x09
+#define CMD_ELS_REQUEST_CR      0x0A
+#define CMD_ELS_REQUEST_CX      0x0B
+#define CMD_RCV_ELS_REQ_CX      0x0D
+#define CMD_ABORT_XRI_CN        0x0E
+#define CMD_ABORT_XRI_CX        0x0F
+#define CMD_CLOSE_XRI_CN        0x10
+#define CMD_CLOSE_XRI_CX        0x11
+#define CMD_CREATE_XRI_CR       0x12
+#define CMD_CREATE_XRI_CX       0x13
+#define CMD_GET_RPI_CN          0x14
+#define CMD_XMIT_ELS_RSP_CX     0x15
+#define CMD_GET_RPI_CR          0x16
+#define CMD_XRI_ABORTED_CX      0x17
+#define CMD_FCP_IWRITE_CR       0x18
+#define CMD_FCP_IWRITE_CX       0x19
+#define CMD_FCP_IREAD_CR        0x1A
+#define CMD_FCP_IREAD_CX        0x1B
+#define CMD_FCP_ICMND_CR        0x1C
+#define CMD_FCP_ICMND_CX        0x1D
+
+#define CMD_ADAPTER_MSG         0x20
+#define CMD_ADAPTER_DUMP        0x22
+
+/*  SLI_2 IOCB Command Set */
+
+#define CMD_RCV_SEQUENCE64_CX   0x81
+#define CMD_XMIT_SEQUENCE64_CR  0x82
+#define CMD_XMIT_SEQUENCE64_CX  0x83
+#define CMD_XMIT_BCAST64_CN     0x84
+#define CMD_XMIT_BCAST64_CX     0x85
+#define CMD_QUE_RING_BUF64_CN   0x86
+#define CMD_QUE_XRI_BUF64_CX    0x87
+#define CMD_IOCB_CONTINUE64_CN  0x88
+#define CMD_RET_XRI_BUF64_CX    0x89
+#define CMD_ELS_REQUEST64_CR    0x8A
+#define CMD_ELS_REQUEST64_CX    0x8B
+#define CMD_ABORT_MXRI64_CN     0x8C
+#define CMD_RCV_ELS_REQ64_CX    0x8D
+#define CMD_XMIT_ELS_RSP64_CX   0x95
+#define CMD_FCP_IWRITE64_CR     0x98
+#define CMD_FCP_IWRITE64_CX     0x99
+#define CMD_FCP_IREAD64_CR      0x9A
+#define CMD_FCP_IREAD64_CX      0x9B
+#define CMD_FCP_ICMND64_CR      0x9C
+#define CMD_FCP_ICMND64_CX      0x9D
+
+#define CMD_GEN_REQUEST64_CR    0xC2
+#define CMD_GEN_REQUEST64_CX    0xC3
+
+#define CMD_MAX_IOCB_CMD        0xE6
+#define CMD_IOCB_MASK           0xff
+
+#define MAX_MSG_DATA            28	/* max msg data in CMD_ADAPTER_MSG
+					   iocb */
+#define LPFC_MAX_ADPTMSG         32	/* max msg data */
+/*
+ *  Define Status
+ */
+#define MBX_SUCCESS                 0
+#define MBXERR_NUM_RINGS            1
+#define MBXERR_NUM_IOCBS            2
+#define MBXERR_IOCBS_EXCEEDED       3
+#define MBXERR_BAD_RING_NUMBER      4
+#define MBXERR_MASK_ENTRIES_RANGE   5
+#define MBXERR_MASKS_EXCEEDED       6
+#define MBXERR_BAD_PROFILE          7
+#define MBXERR_BAD_DEF_CLASS        8
+#define MBXERR_BAD_MAX_RESPONDER    9
+#define MBXERR_BAD_MAX_ORIGINATOR   10
+#define MBXERR_RPI_REGISTERED       11
+#define MBXERR_RPI_FULL             12
+#define MBXERR_NO_RESOURCES         13
+#define MBXERR_BAD_RCV_LENGTH       14
+#define MBXERR_DMA_ERROR            15
+#define MBXERR_ERROR                16
+#define MBX_NOT_FINISHED           255
+
+#define MBX_BUSY                   0xffffff /* Attempted cmd to busy Mailbox */
+#define MBX_TIMEOUT                0xfffffe /* time-out expired waiting for */
+
+/*
+ *    Begin Structure Definitions for Mailbox Commands
+ */
+
+typedef struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint8_t tval;
+	uint8_t tmask;
+	uint8_t rval;
+	uint8_t rmask;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint8_t rmask;
+	uint8_t rval;
+	uint8_t tmask;
+	uint8_t tval;
+#endif
+} RR_REG;
+
+struct ulp_bde {
+	uint32_t bdeAddress;
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t bdeReserved:4;
+	uint32_t bdeAddrHigh:4;
+	uint32_t bdeSize:24;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t bdeSize:24;
+	uint32_t bdeAddrHigh:4;
+	uint32_t bdeReserved:4;
+#endif
+};
+
+struct ulp_bde64 {	/* SLI-2 */
+	union ULP_BDE_TUS {
+		uint32_t w;
+		struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+			uint32_t bdeFlags:8;	/* BDE Flags 0 IS A SUPPORTED
+						   VALUE !! */
+			uint32_t bdeSize:24;	/* Size of buffer (in bytes) */
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+			uint32_t bdeSize:24;	/* Size of buffer (in bytes) */
+			uint32_t bdeFlags:8;	/* BDE Flags 0 IS A SUPPORTED
+						   VALUE !! */
+#endif
+
+#define BUFF_USE_RSVD       0x01	/* bdeFlags */
+#define BUFF_USE_INTRPT     0x02	/* Not Implemented with LP6000 */
+#define BUFF_USE_CMND       0x04	/* Optional, 1=cmd/rsp 0=data buffer */
+#define BUFF_USE_RCV        0x08	/*  "" "", 1=rcv buffer, 0=xmit
+					    buffer */
+#define BUFF_TYPE_32BIT     0x10	/*  "" "", 1=32 bit addr 0=64 bit
+					    addr */
+#define BUFF_TYPE_SPECIAL   0x20	/* Not Implemented with LP6000  */
+#define BUFF_TYPE_BDL       0x40	/* Optional,  may be set in BDL */
+#define BUFF_TYPE_INVALID   0x80	/*  ""  "" */
+		} f;
+	} tus;
+	uint32_t addrLow;
+	uint32_t addrHigh;
+};
+#define BDE64_SIZE_WORD 0
+#define BPL64_SIZE_WORD 0x40
+
+typedef struct ULP_BDL {	/* SLI-2 */
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t bdeFlags:8;	/* BDL Flags */
+	uint32_t bdeSize:24;	/* Size of BDL array in host memory (bytes) */
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t bdeSize:24;	/* Size of BDL array in host memory (bytes) */
+	uint32_t bdeFlags:8;	/* BDL Flags */
+#endif
+
+	uint32_t addrLow;	/* Address 0:31 */
+	uint32_t addrHigh;	/* Address 32:63 */
+	uint32_t ulpIoTag32;	/* Can be used for 32 bit I/O Tag */
+} ULP_BDL;
+
+/* Structure for MB Command LOAD_SM and DOWN_LOAD */
+
+typedef struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t rsvd2:25;
+	uint32_t acknowledgment:1;
+	uint32_t version:1;
+	uint32_t erase_or_prog:1;
+	uint32_t update_flash:1;
+	uint32_t update_ram:1;
+	uint32_t method:1;
+	uint32_t load_cmplt:1;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t load_cmplt:1;
+	uint32_t method:1;
+	uint32_t update_ram:1;
+	uint32_t update_flash:1;
+	uint32_t erase_or_prog:1;
+	uint32_t version:1;
+	uint32_t acknowledgment:1;
+	uint32_t rsvd2:25;
+#endif
+
+	uint32_t dl_to_adr_low;
+	uint32_t dl_to_adr_high;
+	uint32_t dl_len;
+	union {
+		uint32_t dl_from_mbx_offset;
+		struct ulp_bde dl_from_bde;
+		struct ulp_bde64 dl_from_bde64;
+	} un;
+
+} LOAD_SM_VAR;
+
+/* Structure for MB Command READ_NVPARM (02) */
+
+typedef struct {
+	uint32_t rsvd1[3];	/* Read as all one's */
+	uint32_t rsvd2;		/* Read as all zero's */
+	uint32_t portname[2];	/* N_PORT name */
+	uint32_t nodename[2];	/* NODE name */
+
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t pref_DID:24;
+	uint32_t hardAL_PA:8;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t hardAL_PA:8;
+	uint32_t pref_DID:24;
+#endif
+
+	uint32_t rsvd3[21];	/* Read as all one's */
+} READ_NV_VAR;
+
+/* Structure for MB Command WRITE_NVPARMS (03) */
+
+typedef struct {
+	uint32_t rsvd1[3];	/* Must be all one's */
+	uint32_t rsvd2;		/* Must be all zero's */
+	uint32_t portname[2];	/* N_PORT name */
+	uint32_t nodename[2];	/* NODE name */
+
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t pref_DID:24;
+	uint32_t hardAL_PA:8;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t hardAL_PA:8;
+	uint32_t pref_DID:24;
+#endif
+
+	uint32_t rsvd3[21];	/* Must be all one's */
+} WRITE_NV_VAR;
+
+/* Structure for MB Command RUN_BIU_DIAG (04) */
+/* Structure for MB Command RUN_BIU_DIAG64 (0x84) */
+
+typedef struct {
+	uint32_t rsvd1;
+	union {
+		struct {
+			struct ulp_bde xmit_bde;
+			struct ulp_bde rcv_bde;
+		} s1;
+		struct {
+			struct ulp_bde64 xmit_bde64;
+			struct ulp_bde64 rcv_bde64;
+		} s2;
+	} un;
+} BIU_DIAG_VAR;
+
+/* Structure for MB Command INIT_LINK (05) */
+
+typedef struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t rsvd1:24;
+	uint32_t lipsr_AL_PA:8;	/* AL_PA to issue Lip Selective Reset to */
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t lipsr_AL_PA:8;	/* AL_PA to issue Lip Selective Reset to */
+	uint32_t rsvd1:24;
+#endif
+
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint8_t fabric_AL_PA;	/* If using a Fabric Assigned AL_PA */
+	uint8_t rsvd2;
+	uint16_t link_flags;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint16_t link_flags;
+	uint8_t rsvd2;
+	uint8_t fabric_AL_PA;	/* If using a Fabric Assigned AL_PA */
+#endif
+
+#define FLAGS_LOCAL_LB               0x01 /* link_flags (=1) ENDEC loopback */
+#define FLAGS_TOPOLOGY_MODE_LOOP_PT  0x00 /* Attempt loop then pt-pt */
+#define FLAGS_TOPOLOGY_MODE_PT_PT    0x02 /* Attempt pt-pt only */
+#define FLAGS_TOPOLOGY_MODE_LOOP     0x04 /* Attempt loop only */
+#define FLAGS_TOPOLOGY_MODE_PT_LOOP  0x06 /* Attempt pt-pt then loop */
+#define FLAGS_LIRP_LILP              0x80 /* LIRP / LILP is disabled */
+
+#define FLAGS_TOPOLOGY_FAILOVER      0x0400	/* Bit 10 */
+#define FLAGS_LINK_SPEED             0x0800	/* Bit 11 */
+
+	uint32_t link_speed;
+#define LINK_SPEED_AUTO 0       /* Auto selection */
+#define LINK_SPEED_1G   1       /* 1 Gigabaud */
+#define LINK_SPEED_2G   2       /* 2 Gigabaud */
+#define LINK_SPEED_4G   4       /* 4 Gigabaud */
+#define LINK_SPEED_8G   8       /* 4 Gigabaud */
+#define LINK_SPEED_10G   16      /* 10 Gigabaud */
+
+} INIT_LINK_VAR;
+
+/* Structure for MB Command DOWN_LINK (06) */
+
+typedef struct {
+	uint32_t rsvd1;
+} DOWN_LINK_VAR;
+
+/* Structure for MB Command CONFIG_LINK (07) */
+
+typedef struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t cr:1;
+	uint32_t ci:1;
+	uint32_t cr_delay:6;
+	uint32_t cr_count:8;
+	uint32_t rsvd1:8;
+	uint32_t MaxBBC:8;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t MaxBBC:8;
+	uint32_t rsvd1:8;
+	uint32_t cr_count:8;
+	uint32_t cr_delay:6;
+	uint32_t ci:1;
+	uint32_t cr:1;
+#endif
+
+	uint32_t myId;
+	uint32_t rsvd2;
+	uint32_t edtov;
+	uint32_t arbtov;
+	uint32_t ratov;
+	uint32_t rttov;
+	uint32_t altov;
+	uint32_t crtov;
+	uint32_t citov;
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t rrq_enable:1;
+	uint32_t rrq_immed:1;
+	uint32_t rsvd4:29;
+	uint32_t ack0_enable:1;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t ack0_enable:1;
+	uint32_t rsvd4:29;
+	uint32_t rrq_immed:1;
+	uint32_t rrq_enable:1;
+#endif
+} CONFIG_LINK;
+
+/* Structure for MB Command PART_SLIM (08)
+ * will be removed since SLI1 is no longer supported!
+ */
+typedef struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint16_t offCiocb;
+	uint16_t numCiocb;
+	uint16_t offRiocb;
+	uint16_t numRiocb;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint16_t numCiocb;
+	uint16_t offCiocb;
+	uint16_t numRiocb;
+	uint16_t offRiocb;
+#endif
+} RING_DEF;
+
+typedef struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t unused1:24;
+	uint32_t numRing:8;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t numRing:8;
+	uint32_t unused1:24;
+#endif
+
+	RING_DEF ringdef[4];
+	uint32_t hbainit;
+} PART_SLIM_VAR;
+
+/* Structure for MB Command CONFIG_RING (09) */
+
+typedef struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t unused2:6;
+	uint32_t recvSeq:1;
+	uint32_t recvNotify:1;
+	uint32_t numMask:8;
+	uint32_t profile:8;
+	uint32_t unused1:4;
+	uint32_t ring:4;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t ring:4;
+	uint32_t unused1:4;
+	uint32_t profile:8;
+	uint32_t numMask:8;
+	uint32_t recvNotify:1;
+	uint32_t recvSeq:1;
+	uint32_t unused2:6;
+#endif
+
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint16_t maxRespXchg;
+	uint16_t maxOrigXchg;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint16_t maxOrigXchg;
+	uint16_t maxRespXchg;
+#endif
+
+	RR_REG rrRegs[6];
+} CONFIG_RING_VAR;
+
+/* Structure for MB Command RESET_RING (10) */
+
+typedef struct {
+	uint32_t ring_no;
+} RESET_RING_VAR;
+
+/* Structure for MB Command READ_CONFIG (11) */
+
+typedef struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t cr:1;
+	uint32_t ci:1;
+	uint32_t cr_delay:6;
+	uint32_t cr_count:8;
+	uint32_t InitBBC:8;
+	uint32_t MaxBBC:8;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t MaxBBC:8;
+	uint32_t InitBBC:8;
+	uint32_t cr_count:8;
+	uint32_t cr_delay:6;
+	uint32_t ci:1;
+	uint32_t cr:1;
+#endif
+
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t topology:8;
+	uint32_t myDid:24;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t myDid:24;
+	uint32_t topology:8;
+#endif
+
+	/* Defines for topology (defined previously) */
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t AR:1;
+	uint32_t IR:1;
+	uint32_t rsvd1:29;
+	uint32_t ack0:1;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t ack0:1;
+	uint32_t rsvd1:29;
+	uint32_t IR:1;
+	uint32_t AR:1;
+#endif
+
+	uint32_t edtov;
+	uint32_t arbtov;
+	uint32_t ratov;
+	uint32_t rttov;
+	uint32_t altov;
+	uint32_t lmt;
+#define LMT_RESERVED    0x0    /* Not used */
+#define LMT_266_10bit   0x1    /* 265.625 Mbaud 10 bit iface  */
+#define LMT_532_10bit   0x2    /* 531.25  Mbaud 10 bit iface  */
+#define LMT_1063_20bit  0x3    /* 1062.5   Mbaud 20 bit iface */
+#define LMT_1063_10bit  0x4    /* 1062.5   Mbaud 10 bit iface */
+#define LMT_2125_10bit  0x8    /* 2125     Mbaud 10 bit iface */
+#define LMT_4250_10bit  0x40   /* 4250     Mbaud 10 bit iface */
+
+	uint32_t rsvd2;
+	uint32_t rsvd3;
+	uint32_t max_xri;
+	uint32_t max_iocb;
+	uint32_t max_rpi;
+	uint32_t avail_xri;
+	uint32_t avail_iocb;
+	uint32_t avail_rpi;
+	uint32_t default_rpi;
+} READ_CONFIG_VAR;
+
+/* Structure for MB Command READ_RCONFIG (12) */
+
+typedef struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t rsvd2:7;
+	uint32_t recvNotify:1;
+	uint32_t numMask:8;
+	uint32_t profile:8;
+	uint32_t rsvd1:4;
+	uint32_t ring:4;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t ring:4;
+	uint32_t rsvd1:4;
+	uint32_t profile:8;
+	uint32_t numMask:8;
+	uint32_t recvNotify:1;
+	uint32_t rsvd2:7;
+#endif
+
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint16_t maxResp;
+	uint16_t maxOrig;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint16_t maxOrig;
+	uint16_t maxResp;
+#endif
+
+	RR_REG rrRegs[6];
+
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint16_t cmdRingOffset;
+	uint16_t cmdEntryCnt;
+	uint16_t rspRingOffset;
+	uint16_t rspEntryCnt;
+	uint16_t nextCmdOffset;
+	uint16_t rsvd3;
+	uint16_t nextRspOffset;
+	uint16_t rsvd4;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint16_t cmdEntryCnt;
+	uint16_t cmdRingOffset;
+	uint16_t rspEntryCnt;
+	uint16_t rspRingOffset;
+	uint16_t rsvd3;
+	uint16_t nextCmdOffset;
+	uint16_t rsvd4;
+	uint16_t nextRspOffset;
+#endif
+} READ_RCONF_VAR;
+
+/* Structure for MB Command READ_SPARM (13) */
+/* Structure for MB Command READ_SPARM64 (0x8D) */
+
+typedef struct {
+	uint32_t rsvd1;
+	uint32_t rsvd2;
+	union {
+		struct ulp_bde sp; /* This BDE points to struct serv_parm
+				      structure */
+		struct ulp_bde64 sp64;
+	} un;
+} READ_SPARM_VAR;
+
+/* Structure for MB Command READ_STATUS (14) */
+
+typedef struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t rsvd1:31;
+	uint32_t clrCounters:1;
+	uint16_t activeXriCnt;
+	uint16_t activeRpiCnt;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t clrCounters:1;
+	uint32_t rsvd1:31;
+	uint16_t activeRpiCnt;
+	uint16_t activeXriCnt;
+#endif
+
+	uint32_t xmitByteCnt;
+	uint32_t rcvByteCnt;
+	uint32_t xmitFrameCnt;
+	uint32_t rcvFrameCnt;
+	uint32_t xmitSeqCnt;
+	uint32_t rcvSeqCnt;
+	uint32_t totalOrigExchanges;
+	uint32_t totalRespExchanges;
+	uint32_t rcvPbsyCnt;
+	uint32_t rcvFbsyCnt;
+} READ_STATUS_VAR;
+
+/* Structure for MB Command READ_RPI (15) */
+/* Structure for MB Command READ_RPI64 (0x8F) */
+
+typedef struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint16_t nextRpi;
+	uint16_t reqRpi;
+	uint32_t rsvd2:8;
+	uint32_t DID:24;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint16_t reqRpi;
+	uint16_t nextRpi;
+	uint32_t DID:24;
+	uint32_t rsvd2:8;
+#endif
+
+	union {
+		struct ulp_bde sp;
+		struct ulp_bde64 sp64;
+	} un;
+
+} READ_RPI_VAR;
+
+/* Structure for MB Command READ_XRI (16) */
+
+typedef struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint16_t nextXri;
+	uint16_t reqXri;
+	uint16_t rsvd1;
+	uint16_t rpi;
+	uint32_t rsvd2:8;
+	uint32_t DID:24;
+	uint32_t rsvd3:8;
+	uint32_t SID:24;
+	uint32_t rsvd4;
+	uint8_t seqId;
+	uint8_t rsvd5;
+	uint16_t seqCount;
+	uint16_t oxId;
+	uint16_t rxId;
+	uint32_t rsvd6:30;
+	uint32_t si:1;
+	uint32_t exchOrig:1;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint16_t reqXri;
+	uint16_t nextXri;
+	uint16_t rpi;
+	uint16_t rsvd1;
+	uint32_t DID:24;
+	uint32_t rsvd2:8;
+	uint32_t SID:24;
+	uint32_t rsvd3:8;
+	uint32_t rsvd4;
+	uint16_t seqCount;
+	uint8_t rsvd5;
+	uint8_t seqId;
+	uint16_t rxId;
+	uint16_t oxId;
+	uint32_t exchOrig:1;
+	uint32_t si:1;
+	uint32_t rsvd6:30;
+#endif
+} READ_XRI_VAR;
+
+/* Structure for MB Command READ_REV (17) */
+
+typedef struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t cv:1;
+	uint32_t rr:1;
+	uint32_t rsvd1:29;
+	uint32_t rv:1;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t rv:1;
+	uint32_t rsvd1:29;
+	uint32_t rr:1;
+	uint32_t cv:1;
+#endif
+
+	uint32_t biuRev;
+	uint32_t smRev;
+	union {
+		uint32_t smFwRev;
+		struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+			uint8_t ProgType;
+			uint8_t ProgId;
+			uint16_t ProgVer:4;
+			uint16_t ProgRev:4;
+			uint16_t ProgFixLvl:2;
+			uint16_t ProgDistType:2;
+			uint16_t DistCnt:4;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+			uint16_t DistCnt:4;
+			uint16_t ProgDistType:2;
+			uint16_t ProgFixLvl:2;
+			uint16_t ProgRev:4;
+			uint16_t ProgVer:4;
+			uint8_t ProgId;
+			uint8_t ProgType;
+#endif
+
+		} b;
+	} un;
+	uint32_t endecRev;
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint8_t feaLevelHigh;
+	uint8_t feaLevelLow;
+	uint8_t fcphHigh;
+	uint8_t fcphLow;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint8_t fcphLow;
+	uint8_t fcphHigh;
+	uint8_t feaLevelLow;
+	uint8_t feaLevelHigh;
+#endif
+
+	uint32_t postKernRev;
+	uint32_t opFwRev;
+	uint8_t opFwName[16];
+	uint32_t sli1FwRev;
+	uint8_t sli1FwName[16];
+	uint32_t sli2FwRev;
+	uint8_t sli2FwName[16];
+	uint32_t rsvd2;
+	uint32_t RandomData[7];
+} READ_REV_VAR;
+
+/* Structure for MB Command READ_LINK_STAT (18) */
+
+typedef struct {
+	uint32_t rsvd1;
+	uint32_t linkFailureCnt;
+	uint32_t lossSyncCnt;
+
+	uint32_t lossSignalCnt;
+	uint32_t primSeqErrCnt;
+	uint32_t invalidXmitWord;
+	uint32_t crcCnt;
+	uint32_t primSeqTimeout;
+	uint32_t elasticOverrun;
+	uint32_t arbTimeout;
+} READ_LNK_VAR;
+
+/* Structure for MB Command REG_LOGIN (19) */
+/* Structure for MB Command REG_LOGIN64 (0x93) */
+
+typedef struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint16_t rsvd1;
+	uint16_t rpi;
+	uint32_t rsvd2:8;
+	uint32_t did:24;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint16_t rpi;
+	uint16_t rsvd1;
+	uint32_t did:24;
+	uint32_t rsvd2:8;
+#endif
+
+	union {
+		struct ulp_bde sp;
+		struct ulp_bde64 sp64;
+	} un;
+
+} REG_LOGIN_VAR;
+
+/* Word 30 contents for REG_LOGIN */
+typedef union {
+	struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+		uint16_t rsvd1:12;
+		uint16_t wd30_class:4;
+		uint16_t xri;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+		uint16_t xri;
+		uint16_t wd30_class:4;
+		uint16_t rsvd1:12;
+#endif
+	} f;
+	uint32_t word;
+} REG_WD30;
+
+/* Structure for MB Command UNREG_LOGIN (20) */
+
+typedef struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint16_t rsvd1;
+	uint16_t rpi;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint16_t rpi;
+	uint16_t rsvd1;
+#endif
+} UNREG_LOGIN_VAR;
+
+/* Structure for MB Command UNREG_D_ID (0x23) */
+
+typedef struct {
+	uint32_t did;
+} UNREG_D_ID_VAR;
+
+/* Structure for MB Command READ_LA (21) */
+/* Structure for MB Command READ_LA64 (0x95) */
+
+typedef struct {
+	uint32_t eventTag;	/* Event tag */
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t rsvd1:22;
+	uint32_t pb:1;
+	uint32_t il:1;
+	uint32_t attType:8;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t attType:8;
+	uint32_t il:1;
+	uint32_t pb:1;
+	uint32_t rsvd1:22;
+#endif
+
+#define AT_RESERVED    0x00	/* Reserved - attType */
+#define AT_LINK_UP     0x01	/* Link is up */
+#define AT_LINK_DOWN   0x02	/* Link is down */
+
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint8_t granted_AL_PA;
+	uint8_t lipAlPs;
+	uint8_t lipType;
+	uint8_t topology;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint8_t topology;
+	uint8_t lipType;
+	uint8_t lipAlPs;
+	uint8_t granted_AL_PA;
+#endif
+
+#define TOPOLOGY_PT_PT 0x01	/* Topology is pt-pt / pt-fabric */
+#define TOPOLOGY_LOOP  0x02	/* Topology is FC-AL */
+
+	union {
+		struct ulp_bde lilpBde; /* This BDE points to a 128 byte buffer
+					   to */
+		/* store the LILP AL_PA position map into */
+		struct ulp_bde64 lilpBde64;
+	} un;
+
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t Dlu:1;
+	uint32_t Dtf:1;
+	uint32_t Drsvd2:14;
+	uint32_t DlnkSpeed:8;
+	uint32_t DnlPort:4;
+	uint32_t Dtx:2;
+	uint32_t Drx:2;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t Drx:2;
+	uint32_t Dtx:2;
+	uint32_t DnlPort:4;
+	uint32_t DlnkSpeed:8;
+	uint32_t Drsvd2:14;
+	uint32_t Dtf:1;
+	uint32_t Dlu:1;
+#endif
+
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t Ulu:1;
+	uint32_t Utf:1;
+	uint32_t Ursvd2:14;
+	uint32_t UlnkSpeed:8;
+	uint32_t UnlPort:4;
+	uint32_t Utx:2;
+	uint32_t Urx:2;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t Urx:2;
+	uint32_t Utx:2;
+	uint32_t UnlPort:4;
+	uint32_t UlnkSpeed:8;
+	uint32_t Ursvd2:14;
+	uint32_t Utf:1;
+	uint32_t Ulu:1;
+#endif
+
+#define LA_UNKNW_LINK  0x0    /* lnkSpeed */
+#define LA_1GHZ_LINK   0x04   /* lnkSpeed */
+#define LA_2GHZ_LINK   0x08   /* lnkSpeed */
+#define LA_4GHZ_LINK   0x10   /* lnkSpeed */
+#define LA_8GHZ_LINK   0x20   /* lnkSpeed */
+#define LA_10GHZ_LINK  0x40   /* lnkSpeed */
+
+} READ_LA_VAR;
+
+/* Structure for MB Command CLEAR_LA (22) */
+
+typedef struct {
+	uint32_t eventTag;	/* Event tag */
+	uint32_t rsvd1;
+} CLEAR_LA_VAR;
+
+/* Structure for MB Command DUMP */
+
+typedef struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t rsvd:25;
+	uint32_t ra:1;
+	uint32_t co:1;
+	uint32_t cv:1;
+	uint32_t type:4;
+	uint32_t entry_index:16;
+	uint32_t region_id:16;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t type:4;
+	uint32_t cv:1;
+	uint32_t co:1;
+	uint32_t ra:1;
+	uint32_t rsvd:25;
+	uint32_t region_id:16;
+	uint32_t entry_index:16;
+#endif
+
+	uint32_t rsvd1;
+	uint32_t word_cnt;
+	uint32_t resp_offset;
+} DUMP_VAR;
+
+#define  DMP_MEM_REG             0x1
+#define  DMP_NV_PARAMS           0x2
+
+#define  DMP_REGION_VPD          0xe
+#define  DMP_VPD_SIZE            0x400  /* maximum amount of VPD */
+#define  DMP_RSP_OFFSET          0x14   /* word 5 contains first word of rsp */
+#define  DMP_RSP_SIZE            0x6C   /* maximum of 27 words of rsp data */
+
+/* Structure for MB Command CONFIG_PORT (0x88) */
+
+typedef struct {
+	uint32_t pcbLen;
+	uint32_t pcbLow;       /* bit 31:0  of memory based port config block */
+	uint32_t pcbHigh;      /* bit 63:32 of memory based port config block */
+	uint32_t hbainit[5];
+} CONFIG_PORT_VAR;
+
+/* SLI-2 Port Control Block */
+
+/* SLIM POINTER */
+#define SLIMOFF 0x30		/* WORD */
+
+typedef struct _SLI2_RDSC {
+	uint32_t cmdEntries;
+	uint32_t cmdAddrLow;
+	uint32_t cmdAddrHigh;
+
+	uint32_t rspEntries;
+	uint32_t rspAddrLow;
+	uint32_t rspAddrHigh;
+} SLI2_RDSC;
+
+typedef struct _PCB {
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t type:8;
+#define TYPE_NATIVE_SLI2       0x01;
+	uint32_t feature:8;
+#define FEATURE_INITIAL_SLI2   0x01;
+	uint32_t rsvd:12;
+	uint32_t maxRing:4;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t maxRing:4;
+	uint32_t rsvd:12;
+	uint32_t feature:8;
+#define FEATURE_INITIAL_SLI2   0x01;
+	uint32_t type:8;
+#define TYPE_NATIVE_SLI2       0x01;
+#endif
+
+	uint32_t mailBoxSize;
+	uint32_t mbAddrLow;
+	uint32_t mbAddrHigh;
+
+	uint32_t hgpAddrLow;
+	uint32_t hgpAddrHigh;
+
+	uint32_t pgpAddrLow;
+	uint32_t pgpAddrHigh;
+	SLI2_RDSC rdsc[MAX_RINGS];
+} PCB_t;
+
+/* NEW_FEATURE */
+typedef struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t rsvd0:27;
+	uint32_t discardFarp:1;
+	uint32_t IPEnable:1;
+	uint32_t nodeName:1;
+	uint32_t portName:1;
+	uint32_t filterEnable:1;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t filterEnable:1;
+	uint32_t portName:1;
+	uint32_t nodeName:1;
+	uint32_t IPEnable:1;
+	uint32_t discardFarp:1;
+	uint32_t rsvd:27;
+#endif
+
+	uint8_t portname[8];	/* Used to be struct lpfc_name */
+	uint8_t nodename[8];
+	uint32_t rsvd1;
+	uint32_t rsvd2;
+	uint32_t rsvd3;
+	uint32_t IPAddress;
+} CONFIG_FARP_VAR;
+
+/* Union of all Mailbox Command types */
+#define MAILBOX_CMD_WSIZE 32
+
+typedef union {
+	uint32_t varWords[MAILBOX_CMD_WSIZE - 1];
+	LOAD_SM_VAR varLdSM;	/* cmd =  1 (LOAD_SM)        */
+	READ_NV_VAR varRDnvp;	/* cmd =  2 (READ_NVPARMS)   */
+	WRITE_NV_VAR varWTnvp;	/* cmd =  3 (WRITE_NVPARMS)  */
+	BIU_DIAG_VAR varBIUdiag;	/* cmd =  4 (RUN_BIU_DIAG)   */
+	INIT_LINK_VAR varInitLnk;	/* cmd =  5 (INIT_LINK)      */
+	DOWN_LINK_VAR varDwnLnk;	/* cmd =  6 (DOWN_LINK)      */
+	CONFIG_LINK varCfgLnk;	/* cmd =  7 (CONFIG_LINK)    */
+	PART_SLIM_VAR varSlim;	/* cmd =  8 (PART_SLIM)      */
+	CONFIG_RING_VAR varCfgRing;	/* cmd =  9 (CONFIG_RING)    */
+	RESET_RING_VAR varRstRing;	/* cmd = 10 (RESET_RING)     */
+	READ_CONFIG_VAR varRdConfig;	/* cmd = 11 (READ_CONFIG)    */
+	READ_RCONF_VAR varRdRConfig;	/* cmd = 12 (READ_RCONFIG)   */
+	READ_SPARM_VAR varRdSparm;	/* cmd = 13 (READ_SPARM(64)) */
+	READ_STATUS_VAR varRdStatus;	/* cmd = 14 (READ_STATUS)    */
+	READ_RPI_VAR varRdRPI;	/* cmd = 15 (READ_RPI(64))   */
+	READ_XRI_VAR varRdXRI;	/* cmd = 16 (READ_XRI)       */
+	READ_REV_VAR varRdRev;	/* cmd = 17 (READ_REV)       */
+	READ_LNK_VAR varRdLnk;	/* cmd = 18 (READ_LNK_STAT)  */
+	REG_LOGIN_VAR varRegLogin;	/* cmd = 19 (REG_LOGIN(64))  */
+	UNREG_LOGIN_VAR varUnregLogin;	/* cmd = 20 (UNREG_LOGIN)    */
+	READ_LA_VAR varReadLA;	/* cmd = 21 (READ_LA(64))    */
+	CLEAR_LA_VAR varClearLA;	/* cmd = 22 (CLEAR_LA)       */
+	DUMP_VAR varDmp;	/* Warm Start DUMP mbx cmd   */
+	UNREG_D_ID_VAR varUnregDID; /* cmd = 0x23 (UNREG_D_ID)   */
+	CONFIG_FARP_VAR varCfgFarp; /* cmd = 0x25 (CONFIG_FARP)  NEW_FEATURE */
+	CONFIG_PORT_VAR varCfgPort; /* cmd = 0x88 (CONFIG_PORT)  */
+} MAILVARIANTS;
+
+/*
+ * SLI-2 specific structures
+ */
+
+typedef struct {
+	uint32_t cmdPutInx;
+	uint32_t rspGetInx;
+} HGP;
+
+typedef struct {
+	uint32_t cmdGetInx;
+	uint32_t rspPutInx;
+} PGP;
+
+typedef struct _SLI2_DESC {
+	HGP host[MAX_RINGS];
+	uint32_t unused1[16];
+	PGP port[MAX_RINGS];
+} SLI2_DESC;
+
+typedef union {
+	SLI2_DESC s2;
+} SLI_VAR;
+
+typedef volatile struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint16_t mbxStatus;
+	uint8_t mbxCommand;
+	uint8_t mbxReserved:6;
+	uint8_t mbxHc:1;
+	uint8_t mbxOwner:1;	/* Low order bit first word */
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint8_t mbxOwner:1;	/* Low order bit first word */
+	uint8_t mbxHc:1;
+	uint8_t mbxReserved:6;
+	uint8_t mbxCommand;
+	uint16_t mbxStatus;
+#endif
+
+	MAILVARIANTS un;
+	SLI_VAR us;
+} MAILBOX_t;
+
+/*
+ *    Begin Structure Definitions for IOCB Commands
+ */
+
+typedef struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint8_t statAction;
+	uint8_t statRsn;
+	uint8_t statBaExp;
+	uint8_t statLocalError;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint8_t statLocalError;
+	uint8_t statBaExp;
+	uint8_t statRsn;
+	uint8_t statAction;
+#endif
+	/* statRsn  P/F_RJT reason codes */
+#define RJT_BAD_D_ID       0x01	/* Invalid D_ID field */
+#define RJT_BAD_S_ID       0x02	/* Invalid S_ID field */
+#define RJT_UNAVAIL_TEMP   0x03	/* N_Port unavailable temp. */
+#define RJT_UNAVAIL_PERM   0x04	/* N_Port unavailable perm. */
+#define RJT_UNSUP_CLASS    0x05	/* Class not supported */
+#define RJT_DELIM_ERR      0x06	/* Delimiter usage error */
+#define RJT_UNSUP_TYPE     0x07	/* Type not supported */
+#define RJT_BAD_CONTROL    0x08	/* Invalid link conrtol */
+#define RJT_BAD_RCTL       0x09	/* R_CTL invalid */
+#define RJT_BAD_FCTL       0x0A	/* F_CTL invalid */
+#define RJT_BAD_OXID       0x0B	/* OX_ID invalid */
+#define RJT_BAD_RXID       0x0C	/* RX_ID invalid */
+#define RJT_BAD_SEQID      0x0D	/* SEQ_ID invalid */
+#define RJT_BAD_DFCTL      0x0E	/* DF_CTL invalid */
+#define RJT_BAD_SEQCNT     0x0F	/* SEQ_CNT invalid */
+#define RJT_BAD_PARM       0x10	/* Param. field invalid */
+#define RJT_XCHG_ERR       0x11	/* Exchange error */
+#define RJT_PROT_ERR       0x12	/* Protocol error */
+#define RJT_BAD_LENGTH     0x13	/* Invalid Length */
+#define RJT_UNEXPECTED_ACK 0x14	/* Unexpected ACK */
+#define RJT_LOGIN_REQUIRED 0x16	/* Login required */
+#define RJT_TOO_MANY_SEQ   0x17	/* Excessive sequences */
+#define RJT_XCHG_NOT_STRT  0x18	/* Exchange not started */
+#define RJT_UNSUP_SEC_HDR  0x19	/* Security hdr not supported */
+#define RJT_UNAVAIL_PATH   0x1A	/* Fabric Path not available */
+#define RJT_VENDOR_UNIQUE  0xFF	/* Vendor unique error */
+
+#define IOERR_SUCCESS                 0x00	/* statLocalError */
+#define IOERR_MISSING_CONTINUE        0x01
+#define IOERR_SEQUENCE_TIMEOUT        0x02
+#define IOERR_INTERNAL_ERROR          0x03
+#define IOERR_INVALID_RPI             0x04
+#define IOERR_NO_XRI                  0x05
+#define IOERR_ILLEGAL_COMMAND         0x06
+#define IOERR_XCHG_DROPPED            0x07
+#define IOERR_ILLEGAL_FIELD           0x08
+#define IOERR_BAD_CONTINUE            0x09
+#define IOERR_TOO_MANY_BUFFERS        0x0A
+#define IOERR_RCV_BUFFER_WAITING      0x0B
+#define IOERR_NO_CONNECTION           0x0C
+#define IOERR_TX_DMA_FAILED           0x0D
+#define IOERR_RX_DMA_FAILED           0x0E
+#define IOERR_ILLEGAL_FRAME           0x0F
+#define IOERR_EXTRA_DATA              0x10
+#define IOERR_NO_RESOURCES            0x11
+#define IOERR_RESERVED                0x12
+#define IOERR_ILLEGAL_LENGTH          0x13
+#define IOERR_UNSUPPORTED_FEATURE     0x14
+#define IOERR_ABORT_IN_PROGRESS       0x15
+#define IOERR_ABORT_REQUESTED         0x16
+#define IOERR_RECEIVE_BUFFER_TIMEOUT  0x17
+#define IOERR_LOOP_OPEN_FAILURE       0x18
+#define IOERR_RING_RESET              0x19
+#define IOERR_LINK_DOWN               0x1A
+#define IOERR_CORRUPTED_DATA          0x1B
+#define IOERR_CORRUPTED_RPI           0x1C
+#define IOERR_OUT_OF_ORDER_DATA       0x1D
+#define IOERR_OUT_OF_ORDER_ACK        0x1E
+#define IOERR_DUP_FRAME               0x1F
+#define IOERR_LINK_CONTROL_FRAME      0x20	/* ACK_N received */
+#define IOERR_BAD_HOST_ADDRESS        0x21
+#define IOERR_RCV_HDRBUF_WAITING      0x22
+#define IOERR_MISSING_HDR_BUFFER      0x23
+#define IOERR_MSEQ_CHAIN_CORRUPTED    0x24
+#define IOERR_ABORTMULT_REQUESTED     0x25
+#define IOERR_BUFFER_SHORTAGE         0x28
+#define IOERR_DEFAULT                 0x29
+#define IOERR_CNT                     0x2A
+
+#define IOERR_DRVR_MASK               0x100
+#define IOERR_SLI_DOWN                0x101  /* ulpStatus  - Driver defined */
+#define IOERR_SLI_BRESET              0x102
+#define IOERR_SLI_ABORTED             0x103
+} PARM_ERR;
+
+typedef union {
+	struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+		uint8_t Rctl;	/* R_CTL field */
+		uint8_t Type;	/* TYPE field */
+		uint8_t Dfctl;	/* DF_CTL field */
+		uint8_t Fctl;	/* Bits 0-7 of IOCB word 5 */
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+		uint8_t Fctl;	/* Bits 0-7 of IOCB word 5 */
+		uint8_t Dfctl;	/* DF_CTL field */
+		uint8_t Type;	/* TYPE field */
+		uint8_t Rctl;	/* R_CTL field */
+#endif
+
+#define BC      0x02		/* Broadcast Received  - Fctl */
+#define SI      0x04		/* Sequence Initiative */
+#define LA      0x08		/* Ignore Link Attention state */
+#define LS      0x80		/* Last Sequence */
+	} hcsw;
+	uint32_t reserved;
+} WORD5;
+
+/* IOCB Command template for a generic response */
+typedef struct {
+	uint32_t reserved[4];
+	PARM_ERR perr;
+} GENERIC_RSP;
+
+/* IOCB Command template for XMIT / XMIT_BCAST / RCV_SEQUENCE / XMIT_ELS */
+typedef struct {
+	struct ulp_bde xrsqbde[2];
+	uint32_t xrsqRo;	/* Starting Relative Offset */
+	WORD5 w5;		/* Header control/status word */
+} XR_SEQ_FIELDS;
+
+/* IOCB Command template for ELS_REQUEST */
+typedef struct {
+	struct ulp_bde elsReq;
+	struct ulp_bde elsRsp;
+
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t word4Rsvd:7;
+	uint32_t fl:1;
+	uint32_t myID:24;
+	uint32_t word5Rsvd:8;
+	uint32_t remoteID:24;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t myID:24;
+	uint32_t fl:1;
+	uint32_t word4Rsvd:7;
+	uint32_t remoteID:24;
+	uint32_t word5Rsvd:8;
+#endif
+} ELS_REQUEST;
+
+/* IOCB Command template for RCV_ELS_REQ */
+typedef struct {
+	struct ulp_bde elsReq[2];
+	uint32_t parmRo;
+
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t word5Rsvd:8;
+	uint32_t remoteID:24;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t remoteID:24;
+	uint32_t word5Rsvd:8;
+#endif
+} RCV_ELS_REQ;
+
+/* IOCB Command template for ABORT / CLOSE_XRI */
+typedef struct {
+	uint32_t rsvd[3];
+	uint32_t abortType;
+#define ABORT_TYPE_ABTX  0x00000000
+#define ABORT_TYPE_ABTS  0x00000001
+	uint32_t parm;
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint16_t abortContextTag; /* ulpContext from command to abort/close */
+	uint16_t abortIoTag;	/* ulpIoTag from command to abort/close */
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint16_t abortIoTag;	/* ulpIoTag from command to abort/close */
+	uint16_t abortContextTag; /* ulpContext from command to abort/close */
+#endif
+} AC_XRI;
+
+/* IOCB Command template for ABORT_MXRI64 */
+typedef struct {
+	uint32_t rsvd[3];
+	uint32_t abortType;
+	uint32_t parm;
+	uint32_t iotag32;
+} A_MXRI64;
+
+/* IOCB Command template for GET_RPI */
+typedef struct {
+	uint32_t rsvd[4];
+	uint32_t parmRo;
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t word5Rsvd:8;
+	uint32_t remoteID:24;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t remoteID:24;
+	uint32_t word5Rsvd:8;
+#endif
+} GET_RPI;
+
+/* IOCB Command template for all FCP Initiator commands */
+typedef struct {
+	struct ulp_bde fcpi_cmnd;	/* FCP_CMND payload descriptor */
+	struct ulp_bde fcpi_rsp;	/* Rcv buffer */
+	uint32_t fcpi_parm;
+	uint32_t fcpi_XRdy;	/* transfer ready for IWRITE */
+} FCPI_FIELDS;
+
+/* IOCB Command template for all FCP Target commands */
+typedef struct {
+	struct ulp_bde fcpt_Buffer[2];	/* FCP_CMND payload descriptor */
+	uint32_t fcpt_Offset;
+	uint32_t fcpt_Length;	/* transfer ready for IWRITE */
+} FCPT_FIELDS;
+
+/* SLI-2 IOCB structure definitions */
+
+/* IOCB Command template for 64 bit XMIT / XMIT_BCAST / XMIT_ELS */
+typedef struct {
+	ULP_BDL bdl;
+	uint32_t xrsqRo;	/* Starting Relative Offset */
+	WORD5 w5;		/* Header control/status word */
+} XMT_SEQ_FIELDS64;
+
+/* IOCB Command template for 64 bit RCV_SEQUENCE64 */
+typedef struct {
+	struct ulp_bde64 rcvBde;
+	uint32_t rsvd1;
+	uint32_t xrsqRo;	/* Starting Relative Offset */
+	WORD5 w5;		/* Header control/status word */
+} RCV_SEQ_FIELDS64;
+
+/* IOCB Command template for ELS_REQUEST64 */
+typedef struct {
+	ULP_BDL bdl;
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t word4Rsvd:7;
+	uint32_t fl:1;
+	uint32_t myID:24;
+	uint32_t word5Rsvd:8;
+	uint32_t remoteID:24;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t myID:24;
+	uint32_t fl:1;
+	uint32_t word4Rsvd:7;
+	uint32_t remoteID:24;
+	uint32_t word5Rsvd:8;
+#endif
+} ELS_REQUEST64;
+
+/* IOCB Command template for GEN_REQUEST64 */
+typedef struct {
+	ULP_BDL bdl;
+	uint32_t xrsqRo;	/* Starting Relative Offset */
+	WORD5 w5;		/* Header control/status word */
+} GEN_REQUEST64;
+
+/* IOCB Command template for RCV_ELS_REQ64 */
+typedef struct {
+	struct ulp_bde64 elsReq;
+	uint32_t rcvd1;
+	uint32_t parmRo;
+
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t word5Rsvd:8;
+	uint32_t remoteID:24;
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t remoteID:24;
+	uint32_t word5Rsvd:8;
+#endif
+} RCV_ELS_REQ64;
+
+/* IOCB Command template for all 64 bit FCP Initiator commands */
+typedef struct {
+	ULP_BDL bdl;
+	uint32_t fcpi_parm;
+	uint32_t fcpi_XRdy;	/* transfer ready for IWRITE */
+} FCPI_FIELDS64;
+
+/* IOCB Command template for all 64 bit FCP Target commands */
+typedef struct {
+	ULP_BDL bdl;
+	uint32_t fcpt_Offset;
+	uint32_t fcpt_Length;	/* transfer ready for IWRITE */
+} FCPT_FIELDS64;
+
+typedef volatile struct _IOCB {	/* IOCB structure */
+	union {
+		GENERIC_RSP grsp;	/* Generic response */
+		XR_SEQ_FIELDS xrseq;	/* XMIT / BCAST / RCV_SEQUENCE cmd */
+		struct ulp_bde cont[3];	/* up to 3 continuation bdes */
+		RCV_ELS_REQ rcvels;	/* RCV_ELS_REQ template */
+		AC_XRI acxri;	/* ABORT / CLOSE_XRI template */
+		A_MXRI64 amxri;	/* abort multiple xri command overlay */
+		GET_RPI getrpi;	/* GET_RPI template */
+		FCPI_FIELDS fcpi;	/* FCP Initiator template */
+		FCPT_FIELDS fcpt;	/* FCP target template */
+
+		/* SLI-2 structures */
+
+		struct ulp_bde64 cont64[2];	/* up to 2 64 bit continuation
+					   bde_64s */
+		ELS_REQUEST64 elsreq64;	/* ELS_REQUEST template */
+		GEN_REQUEST64 genreq64;	/* GEN_REQUEST template */
+		RCV_ELS_REQ64 rcvels64;	/* RCV_ELS_REQ template */
+		XMT_SEQ_FIELDS64 xseq64;	/* XMIT / BCAST cmd */
+		FCPI_FIELDS64 fcpi64;	/* FCP 64 bit Initiator template */
+		FCPT_FIELDS64 fcpt64;	/* FCP 64 bit target template */
+
+		uint32_t ulpWord[IOCB_WORD_SZ - 2];	/* generic 6 'words' */
+	} un;
+	union {
+		struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+			uint16_t ulpContext;	/* High order bits word 6 */
+			uint16_t ulpIoTag;	/* Low  order bits word 6 */
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+			uint16_t ulpIoTag;	/* Low  order bits word 6 */
+			uint16_t ulpContext;	/* High order bits word 6 */
+#endif
+		} t1;
+		struct {
+#ifdef __BIG_ENDIAN_BITFIELD
+			uint16_t ulpContext;	/* High order bits word 6 */
+			uint16_t ulpIoTag1:2;	/* Low  order bits word 6 */
+			uint16_t ulpIoTag0:14;	/* Low  order bits word 6 */
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+			uint16_t ulpIoTag0:14;	/* Low  order bits word 6 */
+			uint16_t ulpIoTag1:2;	/* Low  order bits word 6 */
+			uint16_t ulpContext;	/* High order bits word 6 */
+#endif
+		} t2;
+	} un1;
+#define ulpContext un1.t1.ulpContext
+#define ulpIoTag   un1.t1.ulpIoTag
+#define ulpIoTag0  un1.t2.ulpIoTag0
+
+#ifdef __BIG_ENDIAN_BITFIELD
+	uint32_t ulpTimeout:8;
+	uint32_t ulpXS:1;
+	uint32_t ulpFCP2Rcvy:1;
+	uint32_t ulpPU:2;
+	uint32_t ulpIr:1;
+	uint32_t ulpClass:3;
+	uint32_t ulpCommand:8;
+	uint32_t ulpStatus:4;
+	uint32_t ulpBdeCount:2;
+	uint32_t ulpLe:1;
+	uint32_t ulpOwner:1;	/* Low order bit word 7 */
+#else	/*  __LITTLE_ENDIAN_BITFIELD */
+	uint32_t ulpOwner:1;	/* Low order bit word 7 */
+	uint32_t ulpLe:1;
+	uint32_t ulpBdeCount:2;
+	uint32_t ulpStatus:4;
+	uint32_t ulpCommand:8;
+	uint32_t ulpClass:3;
+	uint32_t ulpIr:1;
+	uint32_t ulpPU:2;
+	uint32_t ulpFCP2Rcvy:1;
+	uint32_t ulpXS:1;
+	uint32_t ulpTimeout:8;
+#endif
+
+#define PARM_UNUSED        0	/* PU field (Word 4) not used */
+#define PARM_REL_OFF       1	/* PU field (Word 4) = R. O. */
+#define PARM_READ_CHECK    2	/* PU field (Word 4) = Data Transfer Length */
+#define CLASS1             0	/* Class 1 */
+#define CLASS2             1	/* Class 2 */
+#define CLASS3             2	/* Class 3 */
+#define CLASS_FCP_INTERMIX 7	/* FCP Data->Cls 1, all else->Cls 2 */
+
+#define IOSTAT_SUCCESS         0x0	/* ulpStatus  - HBA defined */
+#define IOSTAT_FCP_RSP_ERROR   0x1
+#define IOSTAT_REMOTE_STOP     0x2
+#define IOSTAT_LOCAL_REJECT    0x3
+#define IOSTAT_NPORT_RJT       0x4
+#define IOSTAT_FABRIC_RJT      0x5
+#define IOSTAT_NPORT_BSY       0x6
+#define IOSTAT_FABRIC_BSY      0x7
+#define IOSTAT_INTERMED_RSP    0x8
+#define IOSTAT_LS_RJT          0x9
+#define IOSTAT_BA_RJT          0xA
+#define IOSTAT_RSVD1           0xB
+#define IOSTAT_RSVD2           0xC
+#define IOSTAT_RSVD3           0xD
+#define IOSTAT_RSVD4           0xE
+#define IOSTAT_RSVD5           0xF
+#define IOSTAT_DRIVER_REJECT   0x10   /* ulpStatus  - Driver defined */
+#define IOSTAT_DEFAULT         0xF    /* Same as rsvd5 for now */
+#define IOSTAT_CNT             0x11
+
+} IOCB_t;
+
+
+#define SLI1_SLIM_SIZE   (4 * 1024)
+
+/* Up to 498 IOCBs will fit into 16k
+ * 256 (MAILBOX_t) + 140 (PCB_t) + ( 32 (IOCB_t) * 498 ) = < 16384
+ */
+#define SLI2_SLIM_SIZE   (16 * 1024)
+
+/* Maximum IOCBs that will fit in SLI2 slim */
+#define MAX_SLI2_IOCB    498
+
+struct lpfc_sli2_slim {
+	MAILBOX_t mbx;
+	PCB_t pcb;
+	IOCB_t IOCBs[MAX_SLI2_IOCB];
+};
+
+/*******************************************************************
+This macro check PCI device to allow special handling for LC HBAs.
+
+Parameters:
+device : struct pci_dev 's device field
+
+return 1 => TRUE
+       0 => FALSE
+ *******************************************************************/
+static inline int
+lpfc_is_LC_HBA(unsigned short device)
+{
+	if ((device == PCI_DEVICE_ID_TFLY) ||
+	    (device == PCI_DEVICE_ID_PFLY) ||
+	    (device == PCI_DEVICE_ID_LP101) ||
+	    (device == PCI_DEVICE_ID_BMID) ||
+	    (device == PCI_DEVICE_ID_BSMB) ||
+	    (device == PCI_DEVICE_ID_ZMID) ||
+	    (device == PCI_DEVICE_ID_ZSMB) ||
+	    (device == PCI_DEVICE_ID_RFLY))
+		return 1;
+	else
+		return 0;
+}
+
+#endif				/* _H_LPFC_HW */
--- linux-2.6.8.1-t044-driver-update//drivers/scsi/lpfc/lpfc_logmsg.h	1970-01-01 03:00:00.000000000 +0300
+++ rhel4u2//drivers/scsi/lpfc/lpfc_logmsg.h	2005-10-19 11:47:17.000000000 +0400
@@ -0,0 +1,46 @@
+/*******************************************************************
+ * This file is part of the Emulex Linux Device Driver for         *
+ * Fibre Channel Host Bus Adapters.                                *
+ * Copyright (C) 2003-2005 Emulex.  All rights reserved.           *
+ * EMULEX and SLI are trademarks of Emulex.                        *
+ * www.emulex.com                                                  *
+ *                                                                 *
+ * This program is free software; you can redistribute it and/or   *
+ * modify it under the terms of version 2 of the GNU General       *
+ * Public License as published by the Free Software Foundation.    *
+ * This program is distributed in the hope that it will be useful. *
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
+ * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
+ * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
+ * more details, a copy of which can be found in the file COPYING  *
+ * included with this package.                                     *
+ *******************************************************************/
+
+/*
+ * $Id: lpfc_logmsg.h 1.33.1.2 2005/06/13 17:16:30EDT sf_support Exp  $
+ */
+
+#ifndef _H_LPFC_LOGMSG
+#define _H_LPFC_LOGMSG
+
+#define LOG_ELS                       0x1	/* ELS events */
+#define LOG_DISCOVERY                 0x2	/* Link discovery events */
+#define LOG_MBOX                      0x4	/* Mailbox events */
+#define LOG_INIT                      0x8	/* Initialization events */
+#define LOG_LINK_EVENT                0x10	/* Link events */
+#define LOG_IP                        0x20	/* IP traffic history */
+#define LOG_FCP                       0x40	/* FCP traffic history */
+#define LOG_NODE                      0x80	/* Node table events */
+#define LOG_MISC                      0x400	/* Miscellaneous events */
+#define LOG_SLI                       0x800	/* SLI events */
+#define LOG_CHK_COND                  0x1000	/* FCP Check condition flag */
+#define LOG_LIBDFC                    0x2000	/* Libdfc events */
+#define LOG_ALL_MSG                   0xffff	/* LOG all messages */
+
+#define lpfc_printf_log(phba, level, mask, fmt, arg...) \
+	{ if (((mask) &(phba)->cfg_log_verbose) || (level[1] <= '3')) \
+		dev_printk(level, &((phba)->pcidev)->dev, fmt, ##arg); }
+#endif
+
--- linux-2.6.8.1-t044-driver-update//drivers/scsi/Makefile	2005-10-25 14:49:22.457611512 +0400
+++ rhel4u2//drivers/scsi/Makefile	2005-10-19 11:47:17.000000000 +0400
@@ -129,6 +132,7 @@ obj-$(CONFIG_SCSI_SATA_VITESSE)	+= libat
 obj-$(CONFIG_SCSI_SATA_SIS)	+= libata.o sata_sis.o
 obj-$(CONFIG_SCSI_SATA_SX4)	+= libata.o sata_sx4.o
 obj-$(CONFIG_SCSI_SATA_NV)	+= libata.o sata_nv.o
+obj-$(CONFIG_SCSI_LPFC)		+= lpfc/
 
 obj-$(CONFIG_ARM)		+= arm/
 
--- linux-2.6.8.1-t044-driver-update//drivers/scsi/Kconfig	2005-10-25 13:18:59.017099792 +0400
+++ rhel4u2//drivers/scsi/Kconfig	2005-10-19 11:47:17.000000000 +0400
@@ -599,6 +621,13 @@ config SCSI_EATA_PIO
 	  To compile this driver as a module, choose M here: the
 	  module will be called eata_pio.
 
+config SCSI_LPFC
+	tristate "Emulex LightPulse Fibre Channel Support"
+	depends on PCI && SCSI
+	help
+	  This lpfc driver supports the Emulex LightPulse
+	  family of Fibre Channel PCI host adapters.
+
 config SCSI_FUTURE_DOMAIN
 	tristate "Future Domain 16xx SCSI/AHA-2920A support"
 	depends on (ISA || PCI) && SCSI