summaryrefslogtreecommitdiff
blob: c639a935c68f7e46eb7eaf350748ed4f1a09d4f3 (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
--- linux-2.6.8.1-t043-libata-update/drivers/scsi/aacraid/aachba.c	2005-09-26 13:33:12.000000000 +0400
+++ aacraid-drv/drivers/scsi/aacraid/aachba.c	2005-04-27 15:51:56.000000000 +0400
@@ -32,16 +32,47 @@
 #include <linux/slab.h>
 #include <linux/completion.h>
 #include <linux/blkdev.h>
+#include <linux/version.h> /* For the following test */
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
+#include <linux/dma-mapping.h>
+#endif
 #include <asm/semaphore.h>
 #include <asm/uaccess.h>
 
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+#include <linux/module.h>
+#define MAJOR_NR SCSI_DISK0_MAJOR	/* For DEVICE_NR() */
+#include <linux/blk.h>	/* for DEVICE_NR & io_request_lock definition */
+#include "scsi.h"
+#include "hosts.h"
+#include "sd.h"
+#else
+#include <linux/moduleparam.h>
 #include <scsi/scsi.h>
 #include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_device.h>
 #include <scsi/scsi_host.h>
+#include <scsi/scsi_eh.h>
+#include <scsi/scsi_tcq.h>
+#endif
 
 #include "aacraid.h"
 
+/**
+ * 	locking primitives
+ *
+ */
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+#define aac_spin_lock_irqsave(host_lock, cpu_flags)		spin_lock_irqsave(host_lock, cpu_flags)
+#define aac_spin_lock_irq(host_lock)				spin_lock_irq(host_lock)
+#define aac_spin_unlock_irqrestore(host_lock, cpu_flags)	spin_unlock_irqrestore(host_lock, cpu_flags)
+#define aac_spin_unlock_irq(host_lock)				spin_unlock_irq(host_lock)
+#else
+#define aac_spin_lock_irqsave(host_lock, cpu_flags)		spin_lock_irqsave(&io_request_lock, cpu_flags)
+#define aac_spin_lock_irq(host_lock)				spin_lock_irq(&io_request_lock)
+#define aac_spin_unlock_irqrestore(host_lock, cpu_flags)	spin_unlock_irqrestore(&io_request_lock, cpu_flags)
+#define aac_spin_unlock_irq(host_lock)				spin_unlock_irq(&io_request_lock)
+#endif
 /* values for inqd_pdt: Peripheral device type in plain English */
 #define	INQD_PDT_DA	0x00	/* Direct-access (DISK) device */
 #define	INQD_PDT_PROC	0x03	/* Processor device */
@@ -53,10 +84,6 @@
 #define	INQD_PDT_DMASK	0x1F	/* Peripheral Device Type Mask */
 #define	INQD_PDT_QMASK	0xE0	/* Peripheral Device Qualifer Mask */
 
-#define MAX_FIB_DATA (sizeof(struct hw_fib) - sizeof(FIB_HEADER))
-
-#define MAX_DRIVER_SG_SEGMENT_COUNT 17
-
 /*
  *	Sense codes
  */
@@ -114,6 +141,19 @@
 #define BYTE2(x) (unsigned char)((x) >> 16)
 #define BYTE3(x) (unsigned char)((x) >> 24)
 
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+/* compatibility */
+#ifndef SAM_STAT_CHECK_CONDITION
+# define SAM_STAT_CHECK_CONDITION	(CHECK_CONDITION << 1)
+#endif
+#ifndef SAM_STAT_GOOD
+# define SAM_STAT_GOOD			(GOOD << 1)
+#endif
+#ifndef SAM_STAT_TASK_SET_FULL
+# define SAM_STAT_TASK_SET_FULL		(QUEUE_FULL << 1)
+#endif
+
+#endif
 /*------------------------------------------------------------------------------
  *              S T R U C T S / T Y P E D E F S
  *----------------------------------------------------------------------------*/
@@ -131,54 +171,217 @@ struct inquiry_data {
 	u8 inqd_prl[4];	/* Product Revision Level */
 };
 
-struct sense_data {
-	u8 error_code;		/* 70h (current errors), 71h(deferred errors) */
-	u8 valid:1;		/* A valid bit of one indicates that the information  */
-				/* field contains valid information as defined in the
-				 * SCSI-2 Standard.
-				 */
-	u8 segment_number;	/* Only used for COPY, COMPARE, or COPY AND VERIFY Commands */
-	u8 sense_key:4;		/* Sense Key */
-	u8 reserved:1;
-	u8 ILI:1;		/* Incorrect Length Indicator */
-	u8 EOM:1;		/* End Of Medium - reserved for random access devices */
-	u8 filemark:1;		/* Filemark - reserved for random access devices */
-
-	u8 information[4];	/* for direct-access devices, contains the unsigned 
-				 * logical block address or residue associated with 
-				 * the sense key 
-				 */
-	u8 add_sense_len;	/* number of additional sense bytes to follow this field */
-	u8 cmnd_info[4];	/* not used */
-	u8 ASC;			/* Additional Sense Code */
-	u8 ASCQ;		/* Additional Sense Code Qualifier */
-	u8 FRUC;		/* Field Replaceable Unit Code - not used */
-	u8 bit_ptr:3;		/* indicates which byte of the CDB or parameter data
-				 * was in error
-				 */
-	u8 BPV:1;		/* bit pointer valid (BPV): 1- indicates that 
-				 * the bit_ptr field has valid value
-				 */
-	u8 reserved2:2;
-	u8 CD:1;		/* command data bit: 1- illegal parameter in CDB.
-				 * 0- illegal parameter in data.
-				 */
-	u8 SKSV:1;
-	u8 field_ptr[2];	/* byte of the CDB or parameter data in error */
-};
-
 /*
  *              M O D U L E   G L O B A L S
  */
  
-static struct sense_data sense_data[MAXIMUM_NUM_CONTAINERS];
 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* sgmap);
 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg);
+static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg);
 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
 #ifdef AAC_DETAILED_STATUS_INFO
 static char *aac_get_status_string(u32 status);
 #endif
 
+/*
+ *	Non dasd selection is handled entirely in aachba now
+ */	
+ 
+static int nondasd = -1;
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+module_param(nondasd, int, S_IRUGO|S_IWUSR);
+#else
+MODULE_PARM(nondasd, "i");
+#endif
+MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices. 0=off, 1=on");
+
+static int dacmode = -1;
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+module_param(dacmode, int, S_IRUGO|S_IWUSR);
+#else
+MODULE_PARM(dacmode, "i");
+#endif
+MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC. 0=off, 1=on");
+
+#if (defined(__arm__) || defined(CONFIG_EXTERNAL))
+static int commit = 1;
+#else
+static int commit = -1;
+#endif
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+module_param(commit, int, S_IRUGO|S_IWUSR);
+#else
+MODULE_PARM(commit, "i");
+#endif
+MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the adapter for foreign arrays.\nThis is typically needed in systems that do not have a BIOS. 0=off, 1=on");
+
+#if (defined(__arm__) || defined(CONFIG_EXTERNAL) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) || defined(__VMKERNEL_MODULE__))
+static int coalescethreshold = 0;
+#else
+static int coalescethreshold = 16; /* 8KB coalesce knee */
+#endif
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+module_param(coalescethreshold, int, S_IRUGO|S_IWUSR);
+#else
+MODULE_PARM(coalescethreshold, "i");
+#endif
+MODULE_PARM_DESC(coalescethreshold, "Control the maximum block size of sequential requests that are fed back to the\nscsi_merge layer for coalescing. 0=off, 16 block (8KB) default.");
+
+int numacb = -1;
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+module_param(numacb, int, S_IRUGO|S_IWUSR);
+#else
+MODULE_PARM(numacb, "i");
+#endif
+MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control blocks (FIB) allocated. Valid\nvalues are 512 and down. Default is to use suggestion from Firmware.");
+
+int acbsize = -1;
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+module_param(acbsize, int, S_IRUGO|S_IWUSR);
+#else
+MODULE_PARM(acbsize, "i");
+#endif
+MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB) size. Valid values are 512,\n2048, 4096 and 8192. Default is to use suggestion from Firmware.");
+#if (defined(AAC_EXTENDED_TIMEOUT))
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+int extendedtimeout = -1;
+module_param(extendedtimeout, int, S_IRUGO|S_IWUSR);
+#else
+static int extendedtimeout = -1;
+MODULE_PARM(extendedtimeout, "i");
+#endif
+MODULE_PARM_DESC(extendedtimeout, "Request a specific timeout to override I/O requests issed to the adapter.");
+#endif
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+static char aacraid[256];
+module_param_string(aacraid, aacraid, sizeof(aacraid), 0);
+#else
+static char * aacraid = NULL;
+MODULE_PARM(aacraid, "s");
+#endif
+MODULE_PARM_DESC(aacraid, "set the various published parameters of the aacraid driver with a syntax of aacraid=parm:value[,parm:value]...");
+
+static int aacraid_setup(char *str)
+{
+	int i;
+	char *key;
+	char *value;
+	struct {
+		char * option_name;
+		int * option_flag;
+		int option_value;
+	} options[] = {
+		{ "nondasd", &nondasd, 1 },
+		{ "dacmode", &dacmode, 1 },
+		{ "commit", &commit, 1 },
+		{ "coalescethreshold", &coalescethreshold, 16 },
+		{ "acbsize", &acbsize, 8192 },
+#if (defined(AAC_EXTENDED_TIMEOUT))
+		{ "extendedtimeout", &extendedtimeout, AAC_EXTENDED_TIMEOUT },
+#endif
+	};
+
+#if 0
+printk (KERN_INFO "aacraid_setup(\"%s\")\n", (str) ? str : "<null>");
+#endif
+	if (str) while ((key = strsep(&str, ",."))) {
+		if (!*key)
+			continue;
+		value = strchr(key, ':');
+		if (value)
+			*value++ = '\0';
+		for (i = 0; i < (sizeof (options) / sizeof (options[0])); i++) {
+			if (strnicmp (key, options[i].option_name,
+			     strlen(options[i].option_name)) == 0) {
+				*options[i].option_flag
+				  = (value)
+				    ? simple_strtoul(value, NULL, 0)
+				    : options[i].option_value;
+				break;
+			}
+		}
+	}
+
+	return (1);
+}
+
+__setup("aacraid=", aacraid_setup);
+
+/**
+ *	aac_get_config_status	-	check the adapter configuration
+ *	@common: adapter to query
+ *
+ *	Query config status, and commit the configuration if needed.
+ */
+int aac_get_config_status(struct aac_dev *dev)
+{
+	int status = 0;
+	struct fib * fibptr;
+
+	if (!(fibptr = fib_alloc(dev)))
+		return -ENOMEM;
+
+	fib_init(fibptr);
+	{
+		struct aac_get_config_status *dinfo;
+		dinfo = (struct aac_get_config_status *) fib_data(fibptr);
+
+		dinfo->command = cpu_to_le32(VM_ContainerConfig);
+		dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
+		dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
+	}
+
+	status = fib_send(ContainerCommand,
+			    fibptr,
+			    sizeof (struct aac_get_config_status),
+			    FsaNormal,
+			    1, 1,
+			    NULL, NULL);
+	if (status < 0 ) {
+		printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
+	} else {
+		struct aac_get_config_status_resp *reply
+		  = (struct aac_get_config_status_resp *) fib_data(fibptr);
+		dprintk((KERN_WARNING
+		  "aac_get_config_status: response=%d status=%d action=%d\n",
+		  le32_to_cpu(reply->response),
+		  le32_to_cpu(reply->status),
+		  le32_to_cpu(reply->data.action)));
+		if ((le32_to_cpu(reply->response) != ST_OK) ||
+		     (le32_to_cpu(reply->status) != CT_OK) ||
+		     (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
+			printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
+			status = -EINVAL;
+		}
+	}
+	fib_complete(fibptr);
+	/* Send a CT_COMMIT_CONFIG to enable discovery of devices */
+	if (status >= 0) {
+		if (commit == 1) {
+			struct aac_commit_config * dinfo;
+			fib_init(fibptr);
+			dinfo = (struct aac_commit_config *) fib_data(fibptr);
+	
+			dinfo->command = cpu_to_le32(VM_ContainerConfig);
+			dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
+	
+			status = fib_send(ContainerCommand,
+				    fibptr,
+				    sizeof (struct aac_commit_config),
+				    FsaNormal,
+				    1, 1,
+				    NULL, NULL);
+			fib_complete(fibptr);
+		} else if (commit == 0) {
+			printk(KERN_WARNING
+			  "aac_get_config_status: Foreign device configurations are being ignored\n");
+		}
+	}
+	fib_free(fibptr);
+	return status;
+}
+
 /**
  *	aac_get_containers	-	list containers
  *	@common: adapter to probe
@@ -187,21 +390,60 @@ static char *aac_get_status_string(u32 s
  */
 int aac_get_containers(struct aac_dev *dev)
 {
-	struct fsa_scsi_hba *fsa_dev_ptr;
+	struct fsa_dev_info *fsa_dev_ptr;
 	u32 index; 
 	int status = 0;
-	struct aac_query_mount *dinfo;
-	struct aac_mount *dresp;
 	struct fib * fibptr;
 	unsigned instance;
 
-	fsa_dev_ptr = &(dev->fsa_dev);
 	instance = dev->scsi_host_ptr->unique_id;
 
 	if (!(fibptr = fib_alloc(dev)))
 		return -ENOMEM;
 
-	for (index = 0; index < MAXIMUM_NUM_CONTAINERS; index++) {
+	{
+		struct aac_get_container_count *dinfo;
+		struct aac_get_container_count_resp *dresp;
+		int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
+
+		fib_init(fibptr);
+		dinfo = (struct aac_get_container_count *) fib_data(fibptr);
+	
+		dinfo->command = cpu_to_le32(VM_ContainerConfig);
+		dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
+	
+		status = fib_send(ContainerCommand,
+			    fibptr,
+			    sizeof (struct aac_get_container_count),
+			    FsaNormal,
+			    1, 1,
+			    NULL, NULL);
+		if (status >= 0) {
+			dresp = (struct aac_get_container_count_resp *) fib_data(fibptr);
+			maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
+			fib_complete(fibptr);
+		}
+
+		if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
+			maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
+		fsa_dev_ptr = (struct fsa_dev_info *) kmalloc(
+		  sizeof(*fsa_dev_ptr) * maximum_num_containers, GFP_KERNEL);
+		if (!fsa_dev_ptr) {
+			fib_free(fibptr);
+			return -ENOMEM;
+		}
+		memset(fsa_dev_ptr, 0, sizeof(*fsa_dev_ptr) * maximum_num_containers);
+
+		dev->fsa_dev = fsa_dev_ptr;
+		dev->maximum_num_containers = maximum_num_containers;
+	}
+
+	for (index = 0; index < dev->maximum_num_containers; index++) {
+		struct aac_query_mount *dinfo;
+		struct aac_mount *dresp;
+
+		fsa_dev_ptr[index].devname[0] = '\0';
+
 		fib_init(fibptr);
 		dinfo = (struct aac_query_mount *) fib_data(fibptr);
 
@@ -221,14 +463,69 @@ int aac_get_containers(struct aac_dev *d
 		}
 		dresp = (struct aac_mount *)fib_data(fibptr);
 
+#if (defined(AAC_DEBUG_INSTRUMENT_2TB))
+		printk(KERN_INFO "dresp->mnt[0].vol=%d "
+		  "dresp->mnt[0].capacity=%u"
+		  "={%02x %02x %02x %02x}\n",
+		  le32_to_cpu(dresp->mnt[0].vol),
+		  le32_to_cpu(dresp->mnt[0].capacity),
+		  ((u8 *)&dresp->mnt[0].capacity)[0],
+		  ((u8 *)&dresp->mnt[0].capacity)[1],
+		  ((u8 *)&dresp->mnt[0].capacity)[2],
+		  ((u8 *)&dresp->mnt[0].capacity)[3]);
+#endif
+		if ((le32_to_cpu(dresp->status) == ST_OK) &&
+		    (le32_to_cpu(dresp->mnt[0].vol) == CT_NONE)) {
+			dinfo->command = cpu_to_le32(VM_NameServe64);
+			dinfo->count = cpu_to_le32(index);
+			dinfo->type = cpu_to_le32(FT_FILESYS);
+
+			if (fib_send(ContainerCommand,
+				    fibptr,
+				    sizeof(struct aac_query_mount),
+				    FsaNormal,
+				    1, 1,
+				    NULL, NULL) < 0)
+				continue;
+#if (defined(AAC_DEBUG_INSTRUMENT_2TB))
+			printk(KERN_INFO "dresp->mnt[0].capacity64=%llu"
+			  "={%02x %02x %02x %02x %02x %02x %02x %02x}\n",
+			  ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
+			    (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32),
+			  ((u8 *)&dresp->mnt[0].capacity)[0],
+			  ((u8 *)&dresp->mnt[0].capacity)[1],
+			  ((u8 *)&dresp->mnt[0].capacity)[2],
+			  ((u8 *)&dresp->mnt[0].capacity)[3],
+			  ((u8 *)&dresp->mnt[0].capacityhigh)[0],
+			  ((u8 *)&dresp->mnt[0].capacityhigh)[1],
+			  ((u8 *)&dresp->mnt[0].capacityhigh)[2],
+			  ((u8 *)&dresp->mnt[0].capacityhigh)[3]);
+#endif
+		} else
+			dresp->mnt[0].capacityhigh = 0;
+
+		dprintk ((KERN_DEBUG
+		  "VM_NameServe cid=%d status=%d vol=%d state=%d cap=%llu\n",
+		  (int)index, (int)le32_to_cpu(dresp->status),
+		  (int)le32_to_cpu(dresp->mnt[0].vol),
+		  (int)le32_to_cpu(dresp->mnt[0].state),
+		  ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
+		    (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32)));
 		if ((le32_to_cpu(dresp->status) == ST_OK) &&
 		    (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
 		    (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
-			fsa_dev_ptr->valid[index] = 1;
-			fsa_dev_ptr->type[index] = le32_to_cpu(dresp->mnt[0].vol);
-			fsa_dev_ptr->size[index] = le32_to_cpu(dresp->mnt[0].capacity);
+			fsa_dev_ptr[index].valid = 1;
+			fsa_dev_ptr[index].type = le32_to_cpu(dresp->mnt[0].vol);
+			fsa_dev_ptr[index].size
+			  = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
+			    (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
 			if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY)
-				    fsa_dev_ptr->ro[index] = 1;
+				    fsa_dev_ptr[index].ro = 1;
+#if (defined(AAC_DEBUG_INSTRUMENT_2TB))
+			printk(KERN_INFO "Valid type=%u size=%llu ro=%d\n",
+			  fsa_dev_ptr[index].type, fsa_dev_ptr[index].size,
+			  fsa_dev_ptr[index].ro);
+#endif
 		}
 		fib_complete(fibptr);
 		/*
@@ -242,25 +539,190 @@ int aac_get_containers(struct aac_dev *d
 	return status;
 }
 
+static void aac_io_done(struct scsi_cmnd * scsicmd)
+{
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)) /* suppress unused variable warning */
+	unsigned long cpu_flags;
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)) /* suppress unused variable warning */
+	struct Scsi_Host *host = scsicmd->device->host;
+#endif
+#endif
+
+	if (scsicmd->scsi_done == (void (*)(struct scsi_cmnd*))NULL) {
+		printk(KERN_WARNING "aac_io_done: scsi_done NULL\n");
+		return;
+	}
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
+	aac_spin_lock_irqsave(host->host_lock, cpu_flags);
+#endif
+	scsicmd->scsi_done(scsicmd);
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
+	aac_spin_unlock_irqrestore(host->host_lock, cpu_flags);
+#endif
+#if (defined(AAC_DEBUG_INSTRUMENT_TIMING))
+	{
+		u64 lba;
+		u32 count = 0;
+		struct timeval now;
+		do_gettimeofday(&now);
+		if ((scsicmd->cmnd[0] == WRITE_6)	/* 6 byte command */
+		 || (scsicmd->cmnd[0] == READ_6)) {
+			lba = ((scsicmd->cmnd[1] & 0x1F) << 16)
+			    | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
+			count = scsicmd->cmnd[4];
+			if (count == 0)
+				count = 256;
+#if (defined(WRITE_16))
+		} else if ((scsicmd->cmnd[0] == WRITE_16) /* 16 byte command */
+		 || (scsicmd->cmnd[0] == READ_16)) {
+			lba = ((u64)scsicmd->cmnd[2] << 56)
+			    | ((u64)scsicmd->cmnd[3] << 48)
+			    | ((u64)scsicmd->cmnd[4] << 40)
+			    | ((u64)scsicmd->cmnd[9] << 32)
+			    | ((u64)scsicmd->cmnd[6] << 24)
+			    | (scsicmd->cmnd[7] << 16)
+			    | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
+			count = (scsicmd->cmnd[10] << 24)
+			      | (scsicmd->cmnd[11] << 16)
+			      | (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
+#endif
+		} else if ((scsicmd->cmnd[0] == WRITE_12) /* 12 byte command */
+		 || (scsicmd->cmnd[0] == READ_12)) {
+			lba = ((u64)scsicmd->cmnd[2] << 24)
+			    | (scsicmd->cmnd[3] << 16)
+			    | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
+			count = (scsicmd->cmnd[6] << 24)
+			      | (scsicmd->cmnd[7] << 16)
+			      | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
+		} else if ((scsicmd->cmnd[0] == WRITE_10) /* 10 byte command */
+		 || (scsicmd->cmnd[0] == READ_10)) {
+			lba = ((u64)scsicmd->cmnd[2] << 24)
+			    | (scsicmd->cmnd[3] << 16)
+			    | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
+			count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
+		} else
+			lba = (u64)(long)scsicmd;
+		printk(((count)
+		  ? KERN_DEBUG "%lu.%06lu d%lu %llu[%u]\n"
+		  : KERN_DEBUG "%lu.%06lu d%lu 0x%llx\n"),
+		  now.tv_sec % 100, now.tv_usec,
+		  ((struct aac_dev *)scsicmd->device->host->hostdata)->queues->queue[AdapNormCmdQueue].numpending,
+		  lba, count);
+	}
+#endif
+}
+#if (defined(AAC_DEBUG_INSTRUMENT_TIMING))
+
+static inline void __aac_io_done(struct scsi_cmnd * scsicmd)
+{
+	struct timeval now;
+	scsicmd->scsi_done(scsicmd);
+	do_gettimeofday(&now);
+	printk(KERN_DEBUG "%lu.%06lu d%lu %p\n",
+	  now.tv_sec % 100, now.tv_usec,
+	  ((struct aac_dev *)scsicmd->device->host->hostdata)->queues->queue[AdapNormCmdQueue].numpending,
+	  scsicmd);
+}
+#endif
+
+static void get_container_name_callback(void *context, struct fib * fibptr)
+{
+	struct aac_get_name_resp * get_name_reply;
+	struct scsi_cmnd * scsicmd;
+
+	scsicmd = (struct scsi_cmnd *) context;
+
+	dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
+	if (fibptr == NULL)
+		BUG();
+
+	get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
+	/* Failure is irrelevant, using default value instead */
+	if ((le32_to_cpu(get_name_reply->status) == CT_OK)
+	 && (get_name_reply->data[0] != '\0')) {
+		int    count;
+		char * dp;
+		char * sp = get_name_reply->data;
+		sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
+		while (*sp == ' ')
+			++sp;
+		count = sizeof(((struct inquiry_data *)NULL)->inqd_pid);
+		dp = ((struct inquiry_data *)scsicmd->request_buffer)->inqd_pid;
+		if (*sp) do {
+			*dp++ = (*sp) ? *sp++ : ' ';
+		} while (--count > 0);
+	}
+	scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
+
+	fib_complete(fibptr);
+	fib_free(fibptr);
+	aac_io_done(scsicmd);
+}
+
+/**
+ *	aac_get_container_name	-	get container name, none blocking.
+ */
+static int aac_get_container_name(struct scsi_cmnd * scsicmd, int cid)
+{
+	int status;
+	struct aac_get_name *dinfo;
+	struct fib * cmd_fibcontext;
+	struct aac_dev * dev;
+
+	dev = (struct aac_dev *)scsicmd->device->host->hostdata;
+
+	if (!(cmd_fibcontext = fib_alloc(dev)))
+		return -ENOMEM;
+
+	fib_init(cmd_fibcontext);
+	dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
+
+	dinfo->command = cpu_to_le32(VM_ContainerConfig);
+	dinfo->type = cpu_to_le32(CT_READ_NAME);
+	dinfo->cid = cpu_to_le32(cid);
+	dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
+
+	status = fib_send(ContainerCommand, 
+		  cmd_fibcontext, 
+		  sizeof (struct aac_get_name),
+		  FsaNormal, 
+		  0, 1, 
+		  (fib_callback) get_container_name_callback, 
+		  (void *) scsicmd);
+	
+	/*
+	 *	Check that the command queued to the controller
+	 */
+	if (status == -EINPROGRESS) 
+		return 0;
+		
+	printk(KERN_WARNING "aac_get_container_name: fib_send failed with status: %d.\n", status);
+	scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
+	aac_io_done(scsicmd);
+	fib_complete(cmd_fibcontext);
+	fib_free(cmd_fibcontext);
+	return 0;
+}
+
 /**
  *	probe_container		-	query a logical volume
  *	@dev: device to query
  *	@cid: container identifier
  *
  *	Queries the controller about the given volume. The volume information
- *	is updated in the struct fsa_scsi_hba structure rather than returned.
+ *	is updated in the struct fsa_dev_info structure rather than returned.
  */
  
-static int probe_container(struct aac_dev *dev, int cid)
+int probe_container(struct aac_dev *dev, int cid)
 {
-	struct fsa_scsi_hba *fsa_dev_ptr;
+	struct fsa_dev_info *fsa_dev_ptr;
 	int status;
 	struct aac_query_mount *dinfo;
 	struct aac_mount *dresp;
 	struct fib * fibptr;
 	unsigned instance;
 
-	fsa_dev_ptr = &(dev->fsa_dev);
+	fsa_dev_ptr = dev->fsa_dev;
 	instance = dev->scsi_host_ptr->unique_id;
 
 	if (!(fibptr = fib_alloc(dev)))
@@ -281,20 +743,38 @@ static int probe_container(struct aac_de
 			    1, 1,
 			    NULL, NULL);
 	if (status < 0) {
-		printk(KERN_WARNING "aacraid: probe_containers query failed.\n");
+		printk(KERN_WARNING "aacraid: probe_container query failed.\n");
 		goto error;
 	}
 
 	dresp = (struct aac_mount *) fib_data(fibptr);
 
 	if ((le32_to_cpu(dresp->status) == ST_OK) &&
+	    (le32_to_cpu(dresp->mnt[0].vol) == CT_NONE)) {
+		dinfo->command = cpu_to_le32(VM_NameServe64);
+		dinfo->count = cpu_to_le32(cid);
+		dinfo->type = cpu_to_le32(FT_FILESYS);
+
+		if (fib_send(ContainerCommand,
+			    fibptr,
+			    sizeof(struct aac_query_mount),
+			    FsaNormal,
+			    1, 1,
+			    NULL, NULL) < 0)
+			goto error;
+	} else
+		dresp->mnt[0].capacityhigh = 0;
+
+	if ((le32_to_cpu(dresp->status) == ST_OK) &&
 	    (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
 	    (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
-		fsa_dev_ptr->valid[cid] = 1;
-		fsa_dev_ptr->type[cid] = le32_to_cpu(dresp->mnt[0].vol);
-		fsa_dev_ptr->size[cid] = le32_to_cpu(dresp->mnt[0].capacity);
+		fsa_dev_ptr[cid].valid = 1;
+		fsa_dev_ptr[cid].type = le32_to_cpu(dresp->mnt[0].vol);
+		fsa_dev_ptr[cid].size
+		  = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
+		    (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
 		if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY)
-			fsa_dev_ptr->ro[cid] = 1;
+			fsa_dev_ptr[cid].ro = 1;
 	}
 
 error:
@@ -343,6 +823,11 @@ static char *container_types[] = {
         "V-MIRRORS",          
         "PSEUDO R4",          
 	"RAID50",
+	"RAID5D",
+	"RAID5D0",
+	"RAID1E",
+	"RAID6",
+	"RAID60",
         "Unknown"
 };
 
@@ -353,35 +838,63 @@ static char *container_types[] = {
  * Arguments: [1] pointer to void [1] int
  *
  * Purpose: Sets SCSI inquiry data strings for vendor, product
- * and revision level. Allows strings to be set in platform dependent
- * files instead of in OS dependent driver source.
+ * and revision level. Allows strings to be set in platform dependant
+ * files instead of in OS dependant driver source.
  */
 
-static void setinqstr(int devtype, void *data, int tindex)
+static void setinqstr(struct aac_dev *dev, void *data, int tindex)
 {
 	struct scsi_inq *str;
-	char *findit;
-	struct aac_driver_ident *mp;
 
-	mp = aac_get_driver_ident(devtype);
-   
 	str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
+	memset(str, ' ', sizeof(*str));
 
-	inqstrcpy (mp->vname, str->vid); 
-	inqstrcpy (mp->model, str->pid); /* last six chars reserved for vol type */
-
-	findit = str->pid;
+	if (dev->supplement_adapter_info.AdapterTypeText[0]) {
+		char * cp = dev->supplement_adapter_info.AdapterTypeText;
+		int c = sizeof(str->vid);
+		while (*cp && *cp != ' ' && --c)
+			++cp;
+		c = *cp;
+		*cp = '\0';
+		inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
+		  str->vid); 
+		*cp = c;
+		while (*cp && *cp != ' ')
+			++cp;
+		while (*cp == ' ')
+			++cp;
+		/* last six chars reserved for vol type */
+		c = 0;
+		if (strlen(cp) > sizeof(str->pid)) {
+			c = cp[sizeof(str->pid)];
+			cp[sizeof(str->pid)] = '\0';
+		}
+		inqstrcpy (cp, str->pid);
+		if (c)
+			cp[sizeof(str->pid)] = c;
+	} else {
+		struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
+   
+		inqstrcpy (mp->vname, str->vid); 
+		/* last six chars reserved for vol type */
+		inqstrcpy (mp->model, str->pid);
+	}
 
-	for ( ; *findit != ' '; findit++); /* walk till we find a space then incr by 1 */
-		findit++;
-	
 	if (tindex < (sizeof(container_types)/sizeof(char *))){
-		inqstrcpy (container_types[tindex], findit);
+		char *findit = str->pid;
+
+		for ( ; *findit != ' '; findit++); /* walk till we find a space */
+		/* RAID is superfluous in the context of a RAID device */
+		if (memcmp(findit-4, "RAID", 4) == 0)
+			*(findit -= 4) = ' ';
+		if (((findit - str->pid) + strlen(container_types[tindex]))
+		 < (sizeof(str->pid) + sizeof(str->prl)))
+			inqstrcpy (container_types[tindex], findit + 1);
 	}
 	inqstrcpy ("V1.0", str->prl);
 }
 
-void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code,
+static void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code,
 		    u8 a_sense_code, u8 incorrect_length,
 		    u8 bit_pointer, u16 field_pointer,
 		    u32 residue)
@@ -421,69 +934,213 @@ void set_sense(u8 *sense_buf, u8 sense_k
 	}
 }
 
-static void aac_io_done(struct scsi_cmnd * scsicmd)
-{
-	unsigned long cpu_flags;
-	struct Scsi_Host *host = scsicmd->device->host;
-	spin_lock_irqsave(host->host_lock, cpu_flags);
-	scsicmd->scsi_done(scsicmd);
-	spin_unlock_irqrestore(host->host_lock, cpu_flags);
-}
-
-static void __aac_io_done(struct scsi_cmnd * scsicmd)
-{
-	scsicmd->scsi_done(scsicmd);
-}
-
 int aac_get_adapter_info(struct aac_dev* dev)
 {
 	struct fib* fibptr;
-	struct aac_adapter_info* info;
 	int rcode;
 	u32 tmp;
+
 	if (!(fibptr = fib_alloc(dev)))
 		return -ENOMEM;
 
-	fib_init(fibptr);
-	info = (struct aac_adapter_info*) fib_data(fibptr);
+	{
+		struct aac_adapter_info * info;
 
-	memset(info,0,sizeof(struct aac_adapter_info));
+		fib_init(fibptr);
+
+		info = (struct aac_adapter_info *) fib_data(fibptr);
+
+		memset(info,0,sizeof(*info));
 
-	rcode = fib_send(RequestAdapterInfo,
+		rcode = fib_send(RequestAdapterInfo,
 			fibptr, 
-			sizeof(struct aac_adapter_info),
+			sizeof(*info),
 			FsaNormal, 
-			1, 1, 
+			-1, 1, /* First `interrupt' command uses special wait */
 			NULL, 
 			NULL);
 
-	memcpy(&dev->adapter_info, info, sizeof(struct aac_adapter_info));
+		if (rcode < 0) {
+			fib_complete(fibptr);
+			fib_free(fibptr);
+			return rcode;
+		}
+		memcpy(&dev->adapter_info, info, sizeof(*info));
+	}
 
-	tmp = dev->adapter_info.kernelrev;
-	printk(KERN_INFO"%s%d: kernel %d.%d.%d build %d\n", 
-			dev->name, dev->id,
-			tmp>>24,(tmp>>16)&0xff,(tmp>>8)&0xff,
-			dev->adapter_info.kernelbuild);
-	tmp = dev->adapter_info.monitorrev;
-	printk(KERN_INFO"%s%d: monitor %d.%d.%d build %d\n", 
+	if (dev->adapter_info.options & le32_to_cpu(AAC_OPT_SUPPLEMENT_ADAPTER_INFO)) {
+		struct aac_supplement_adapter_info * info;
+
+		fib_init(fibptr);
+
+		info = (struct aac_supplement_adapter_info *) fib_data(fibptr);
+
+		memset(info,0,sizeof(*info));
+
+		rcode = fib_send(RequestSupplementAdapterInfo,
+			fibptr,
+			sizeof(*info),
+			FsaNormal,
+			1, 1,
+			NULL,
+			NULL);
+
+		if (rcode >= 0)
+			memcpy(&dev->supplement_adapter_info, info, sizeof(*info));
+	}
+
+#if (defined(CODE_STREAM_IDENTIFIER))
+	if (dev->supplement_adapter_info.FeatureBits & le32_to_cpu(AAC_FEATURE_FALCON)) {
+		char * info;
+
+		fib_init(fibptr);
+
+		info = (char *) fib_data(fibptr);
+
+		memset(info,0,MAX_CODE_STREAM_IDENTIFIER_LENGTH);
+
+		rcode = fib_send(RequestCompatibilityId,
+			fibptr,
+			MAX_CODE_STREAM_IDENTIFIER_LENGTH,
+			FsaNormal,
+			1, 1,
+			NULL,
+			NULL);
+
+		if (rcode >= 0)
+			memcpy(dev->code_stream_identifier, info,
+			  MAX_CODE_STREAM_IDENTIFIER_LENGTH);
+
+		if (dev->code_stream_identifier[0]
+		 && strncmp(CODE_STREAM_IDENTIFIER,
+		  dev->code_stream_identifier,
+		  MAX_CODE_STREAM_IDENTIFIER_LENGTH)) {
+			extern unsigned long aac_driver_version;
+			printk(KERN_INFO
+			  "%s%d: Warning ! ! ! Compatibility Mismatch\n",
+			  dev->name, dev->id);
+			tmp = le32_to_cpu(dev->adapter_info.kernelrev);
+			printk(KERN_INFO
+			  "%s%d: Firmware=%d.%d-%d[%d],"
+			  " Device Driver=%d.%d-%d"
+#if (defined(AAC_DRIVER_BUILD))
+			  "[%d]"
+#else
+			  " " __DATE__ " " __TIME__
+#endif
+			  "\n",
+			  dev->name, dev->id,
+			  tmp>>24,(tmp>>16)&0xff,tmp&0xff,
+			  le32_to_cpu(dev->adapter_info.kernelbuild),
+			  (int)aac_driver_version >> 24,
+			  (int)(aac_driver_version >> 16) & 0xFF,
+			  (int)aac_driver_version & 0xFF
+#if (defined(AAC_DRIVER_BUILD))
+			  , AAC_DRIVER_BUILD
+#endif
+			);
+			printk(KERN_INFO
+			  "%s%d: These should be a tested set to avoid possible compatibility problems.\n",
+			  dev->name, dev->id);
+		}
+	}
+#endif
+
+	/* GetBusInfo */
+	{
+		struct aac_bus_info * command;
+		struct aac_bus_info_response * info;
+
+		fib_init(fibptr);
+
+		info = (struct aac_bus_info_response *) fib_data(fibptr);
+
+		memset(info,0,sizeof(*info));
+
+		command = (struct aac_bus_info *) info;
+
+		command->Command = cpu_to_le32(VM_Ioctl);
+		command->ObjType = cpu_to_le32(FT_DRIVE);
+		command->MethodId = cpu_to_le32(1);
+		command->CtlCmd = cpu_to_le32(GetBusInfo);
+
+		rcode = fib_send(ContainerCommand,
+				    fibptr,
+				    sizeof (*info),
+				    FsaNormal,
+				    1, 1,
+				    NULL, NULL);
+
+		if ((rcode >= 0 ) && (le32_to_cpu(info->Status) == ST_OK)) {
+			dev->maximum_num_physicals = le32_to_cpu(info->TargetsPerBus);
+			dev->maximum_num_channels = le32_to_cpu(info->BusCount);
+		}
+	}
+
+	tmp = le32_to_cpu(dev->adapter_info.kernelrev);
+	printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n", 
+			dev->name, 
+			dev->id,
+			tmp>>24,
+			(tmp>>16)&0xff,
+			tmp&0xff,
+			le32_to_cpu(dev->adapter_info.kernelbuild),
+			(int)sizeof(dev->supplement_adapter_info.BuildDate),
+			dev->supplement_adapter_info.BuildDate);
+	tmp = le32_to_cpu(dev->adapter_info.monitorrev);
+	printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n", 
 			dev->name, dev->id,
-			tmp>>24,(tmp>>16)&0xff,(tmp>>8)&0xff,
-			dev->adapter_info.monitorbuild);
-	tmp = dev->adapter_info.biosrev;
-	printk(KERN_INFO"%s%d: bios %d.%d.%d build %d\n", 
+			tmp>>24,(tmp>>16)&0xff,tmp&0xff,
+			le32_to_cpu(dev->adapter_info.monitorbuild));
+	tmp = le32_to_cpu(dev->adapter_info.biosrev);
+	printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n", 
 			dev->name, dev->id,
-			tmp>>24,(tmp>>16)&0xff,(tmp>>8)&0xff,
-			dev->adapter_info.biosbuild);
-	printk(KERN_INFO"%s%d: serial %x%x\n",
+			tmp>>24,(tmp>>16)&0xff,tmp&0xff,
+			le32_to_cpu(dev->adapter_info.biosbuild));
+	if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0)
+		printk(KERN_INFO "%s%d: serial %x\n",
 			dev->name, dev->id,
-			dev->adapter_info.serial[0],
-			dev->adapter_info.serial[1]);
+			le32_to_cpu(dev->adapter_info.serial[0]));
+	aacraid_setup(aacraid);
+#if 0
+#if (defined(AAC_EXTENDED_TIMEOUT))
+	printk(KERN_INFO "nondasd=%d dacmode=%d commit=%d "
+	  "coalescethreshold=%d acbsize=%d extendedtimeout=%d\n",
+	  nondasd, dacmode, commit, coalescethreshold, acbsize,
+	  extendedtimeout);
+#else
+	printk(KERN_INFO "nondasd=%d dacmode=%d commit=%d "
+	  "coalescethreshold=%d acbsize=%d\n",
+	  nondasd, dacmode, commit, coalescethreshold, acbsize);
+#endif
+#endif
 
 	dev->nondasd_support = 0;
+	dev->raid_scsi_mode = 0;
 	if(dev->adapter_info.options & AAC_OPT_NONDASD){
-//		dev->nondasd_support = 1;
-// dmb - temporarily disable nondasd
+		dev->nondasd_support = 1;
 	}
+
+	/*
+	 * If the firmware supports ROMB RAID/SCSI mode and we are currently
+	 * in RAID/SCSI mode, set the flag. For now if in this mode we will
+	 * force nondasd support on. If we decide to allow the non-dasd flag
+	 * additional changes changes will have to be made to support
+	 * RAID/SCSI.  the function aac_scsi_cmd in this module will have to be
+	 * changed to support the new dev->raid_scsi_mode flag instead of
+	 * leaching off of the dev->nondasd_support flag. Also in linit.c the
+	 * function aac_detect will have to be modified where it sets up the
+	 * max number of channels based on the aac->nondasd_support flag only.
+	 */
+	if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
+	    (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
+		dev->nondasd_support = 1;
+		dev->raid_scsi_mode = 1;
+	}
+	if (dev->raid_scsi_mode != 0)
+		printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
+				dev->name, dev->id);
+		
 	if(nondasd != -1) {  
 		dev->nondasd_support = (nondasd!=0);
 	}
@@ -491,18 +1148,72 @@ int aac_get_adapter_info(struct aac_dev*
 		printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
 	}
 
-	dev->pae_support = 0;
-	if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
-		printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id);
-		dev->pae_support = 1;
+	dev->dac_support = 0;
+	/*
+	 *	Only enable DAC mode if the dma_addr_t is larger than 32
+	 * bit addressing, and we have more than 32 bit addressing worth of
+	 * memory and if the controller supports 64 bit scatter gather elements.
+	 */
+	if( (sizeof(dma_addr_t) > 4) && (num_physpages > (0xFFFFFFFFULL >> PAGE_SHIFT)) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
+		dev->dac_support = 1;
 	}
 
-	if(paemode != -1){
-		dev->pae_support = (paemode!=0);
-	}
-	if(dev->pae_support != 0) {
-		printk(KERN_INFO"%s%d: 64 Bit PAE enabled\n", dev->name, dev->id);
-		pci_set_dma_mask(dev->pdev, (dma_addr_t)0xFFFFFFFFFFFFFFFFULL);
+	if(dacmode != -1) {
+		dev->dac_support = (dacmode!=0);
+	}
+	if(dev->dac_support != 0) {
+		if (!pci_set_dma_mask(dev->pdev, DMA_64BIT_MASK) &&
+			!pci_set_consistent_dma_mask(dev->pdev, DMA_64BIT_MASK)) {
+			printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
+				dev->name, dev->id);
+		} else if (!pci_set_dma_mask(dev->pdev, DMA_32BIT_MASK) &&
+			!pci_set_consistent_dma_mask(dev->pdev, DMA_32BIT_MASK)) {
+			printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
+				dev->name, dev->id);
+			dev->dac_support = 0;
+		} else {
+			printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
+				dev->name, dev->id);
+			rcode = -ENOMEM;
+		}
+	}
+	/* 57 scatter gather elements */
+	if (!(dev->raw_io_interface)) {
+		dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size
+			- sizeof(struct aac_fibhdr)
+			- sizeof(struct aac_write) + sizeof(struct sgmap))
+				/ sizeof(struct sgmap);
+		if( (sizeof(dma_addr_t) > 4) && (num_physpages >= (0xFFFFFFFFULL >> PAGE_SHIFT)) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64) && (dev->dac_support) ){
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,18)) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)) && (!defined(__arm__)) && defined(CONFIG_HIGHMEM) && ((LINUX_VERSION_CODE != KERNEL_VERSION(2,4,19)) || defined(CONFIG_HIGHIO))
+			dev->scsi_host_ptr->highmem_io = 1;
+#endif
+			/* 38 scatter gather elements */
+			dev->scsi_host_ptr->sg_tablesize
+				= (dev->max_fib_size
+				- sizeof(struct aac_fibhdr)
+				- sizeof(struct aac_write64)
+				+ sizeof(struct sgmap64))
+					/ sizeof(struct sgmap64);
+		}
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,18)) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)) && (!defined(__arm__)) && defined(CONFIG_HIGHMEM) && ((LINUX_VERSION_CODE != KERNEL_VERSION(2,4,19)) || defined(CONFIG_HIGHIO))
+		else {
+			dev->scsi_host_ptr->highmem_io = 0;
+		}
+#endif
+		dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
+		if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
+			/*
+			 * Worst case size that could cause sg overflow when
+			 * we break up SG elements that are larger than 64KB.
+			 * Would be nice if we could tell the SCSI layer what
+			 * the maximum SG element size can be. Worst case is
+			 * (sg_tablesize-1) 4KB elements with one 64KB
+			 * element.
+			 *	32bit -> 468 or 238KB	64bit -> 424 or 212KB
+			 */
+			dev->scsi_host_ptr->max_sectors
+			  = (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
+		}
 	}
 
 	fib_complete(fibptr);
@@ -512,12 +1223,11 @@ int aac_get_adapter_info(struct aac_dev*
 }
 
 
-static void read_callback(void *context, struct fib * fibptr)
+static void io_callback(void *context, struct fib * fibptr)
 {
 	struct aac_dev *dev;
 	struct aac_read_reply *readreply;
 	struct scsi_cmnd *scsicmd;
-	u32 lba;
 	u32 cid;
 
 	scsicmd = (struct scsi_cmnd *) context;
@@ -525,8 +1235,36 @@ static void read_callback(void *context,
 	dev = (struct aac_dev *)scsicmd->device->host->hostdata;
 	cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
 
-	lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
-	dprintk((KERN_DEBUG "read_callback[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), lba, jiffies));
+	if (nblank(dprintk(x))) {
+		u64 lba;
+		if ((scsicmd->cmnd[0] == WRITE_6)	/* 6 byte command */
+		 || (scsicmd->cmnd[0] == READ_6))
+			lba = ((scsicmd->cmnd[1] & 0x1F) << 16)
+			    | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
+#if (defined(WRITE_16))
+		else if ((scsicmd->cmnd[0] == WRITE_16)	/* 16 byte command */
+		 || (scsicmd->cmnd[0] == READ_16))
+			lba = ((u64)scsicmd->cmnd[2] << 56)
+			    | ((u64)scsicmd->cmnd[3] << 48)
+			    | ((u64)scsicmd->cmnd[4] << 40)
+			    | ((u64)scsicmd->cmnd[9] << 32)
+			    | ((u64)scsicmd->cmnd[6] << 24)
+			    | (scsicmd->cmnd[7] << 16)
+			    | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
+#endif
+		else if ((scsicmd->cmnd[0] == WRITE_12)	/* 12 byte command */
+		 || (scsicmd->cmnd[0] == READ_12))
+			lba = ((u64)scsicmd->cmnd[2] << 24)
+			    | (scsicmd->cmnd[3] << 16)
+			    | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
+		else
+			lba = ((u64)scsicmd->cmnd[2] << 24)
+			    | (scsicmd->cmnd[3] << 16)
+			    | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
+		printk(KERN_DEBUG
+		  "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
+		  smp_processor_id(), (unsigned long long)lba, jiffies);
+	}
 
 	if (fibptr == NULL)
 		BUG();
@@ -537,77 +1275,106 @@ static void read_callback(void *context,
 			scsicmd->use_sg,
 			scsicmd->sc_data_direction);
 	else if(scsicmd->request_bufflen)
-		pci_unmap_single(dev->pdev, (dma_addr_t)(ulong)scsicmd->SCp.ptr,
+		pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle,
 				 scsicmd->request_bufflen,
 				 scsicmd->sc_data_direction);
 	readreply = (struct aac_read_reply *)fib_data(fibptr);
 	if (le32_to_cpu(readreply->status) == ST_OK)
 		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
 	else {
-		printk(KERN_WARNING "read_callback: read failed, status = %d\n", readreply->status);
+#ifdef AAC_DETAILED_STATUS_INFO
+		printk(KERN_WARNING "io_callback: io failed, status = %d\n",
+		  le32_to_cpu(readreply->status));
+#endif
 		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
-		set_sense((u8 *) &sense_data[cid],
+		set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
 				    HARDWARE_ERROR,
 				    SENCODE_INTERNAL_TARGET_FAILURE,
 				    ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
 				    0, 0);
-		memcpy(scsicmd->sense_buffer, &sense_data[cid], sizeof(struct sense_data));
+		memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
+		  (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
+		    ? sizeof(scsicmd->sense_buffer)
+		    : sizeof(dev->fsa_dev[cid].sense_data));
 	}
 	fib_complete(fibptr);
 	fib_free(fibptr);
 
 	aac_io_done(scsicmd);
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+	if (scsicmd->device->device_blocked) {
+		struct scsi_cmnd * cmd;
+		cid = 0;
+
+		for (cmd = scsicmd->device->device_queue; cmd; cmd = cmd->next)
+			if (cmd->serial_number)
+				++cid;
+		if (cid < scsicmd->device->queue_depth)
+			scsicmd->device->device_blocked = 0;
+	}
+#endif
 }
 
-static void write_callback(void *context, struct fib * fibptr)
+static inline void aac_select_queue_depth(
+	struct scsi_cmnd * scsicmd,
+	int cid,
+	u64 lba,
+	u32 count)
 {
+	struct scsi_device *device = scsicmd->device;
 	struct aac_dev *dev;
-	struct aac_write_reply *writereply;
-	struct scsi_cmnd *scsicmd;
-	u32 lba;
-	u32 cid;
-
-	scsicmd = (struct scsi_cmnd *) context;
-	dev = (struct aac_dev *)scsicmd->device->host->hostdata;
-	cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
-
-	lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
-	dprintk((KERN_DEBUG "write_callback[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), lba, jiffies));
-	if (fibptr == NULL)
-		BUG();
+	unsigned depth;
 
-	if(scsicmd->use_sg)
-		pci_unmap_sg(dev->pdev, 
-			(struct scatterlist *)scsicmd->buffer,
-			scsicmd->use_sg,
-			scsicmd->sc_data_direction);
-	else if(scsicmd->request_bufflen)
-		pci_unmap_single(dev->pdev, (dma_addr_t)(ulong)scsicmd->SCp.ptr,
-				 scsicmd->request_bufflen,
-				 scsicmd->sc_data_direction);
-
-	writereply = (struct aac_write_reply *) fib_data(fibptr);
-	if (le32_to_cpu(writereply->status) == ST_OK)
-		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
-	else {
-		printk(KERN_WARNING "write_callback: write failed, status = %d\n", writereply->status);
-		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
-		set_sense((u8 *) &sense_data[cid],
-				    HARDWARE_ERROR,
-				    SENCODE_INTERNAL_TARGET_FAILURE,
-				    ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
-				    0, 0);
-		memcpy(scsicmd->sense_buffer, &sense_data[cid], sizeof(struct sense_data));
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+	if (!device->tagged_supported)
+		return;
+#endif
+	dev = (struct aac_dev *)device->host->hostdata;
+	if (dev->fsa_dev[cid].queue_depth <= 2)
+		dev->fsa_dev[cid].queue_depth = device->queue_depth;
+	if (lba == dev->fsa_dev[cid].last) {
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+		struct scsi_cmnd * cmd;
+#endif
+		/*
+		 * If larger than coalescethreshold in size, coalescing has
+		 * less effect on overall performance.  Also, if we are
+		 * coalescing right now, leave it alone if above the threshold.
+		 */
+		if (count > coalescethreshold)
+			return;
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+		depth = 0;
+
+		for (cmd = device->device_queue; cmd; cmd = cmd->next)
+			if ((cmd->serial_number)
+			 && (cmd != scsicmd)
+			 && (++depth > 1)) {
+				device->device_blocked = 1;
+				break;
+			}
+#endif
+		depth = 2;
+	} else {
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+		device->device_blocked = 0;
+#endif
+		depth = dev->fsa_dev[cid].queue_depth;
 	}
-
-	fib_complete(fibptr);
-	fib_free(fibptr);
-	aac_io_done(scsicmd);
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+	scsi_adjust_queue_depth(device, MSG_ORDERED_TAG, depth);
+#else
+	device->queue_depth = depth;
+#endif
+	dprintk((KERN_DEBUG "l=%llu %llu[%u] q=%u %lu\n",
+	  dev->fsa_dev[cid].last, lba, count, device->queue_depth,
+	  dev->queues->queue[AdapNormCmdQueue].numpending));
+	dev->fsa_dev[cid].last = lba + count;
 }
 
-int aac_read(struct scsi_cmnd * scsicmd, int cid)
+static int aac_read(struct scsi_cmnd * scsicmd, int cid)
 {
-	u32 lba;
+	u64 lba;
 	u32 count;
 	int status;
 
@@ -619,6 +1386,15 @@ int aac_read(struct scsi_cmnd * scsicmd,
 	/*
 	 *	Get block address and transfer length
 	 */
+#if (defined(AAC_DEBUG_INSTRUMENT_IO))
+	printk(KERN_DEBUG "aac_read: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
+	  scsicmd->cmnd[0],  scsicmd->cmnd[1],  scsicmd->cmnd[2],
+	  scsicmd->cmnd[3],  scsicmd->cmnd[4],  scsicmd->cmnd[5],
+	  scsicmd->cmnd[6],  scsicmd->cmnd[7],  scsicmd->cmnd[8],
+	  scsicmd->cmnd[9],  scsicmd->cmnd[10], scsicmd->cmnd[11],
+	  scsicmd->cmnd[12], scsicmd->cmnd[13], scsicmd->cmnd[14],
+	  scsicmd->cmnd[15]);
+#endif
 	if (scsicmd->cmnd[0] == READ_6)	/* 6 byte command */
 	{
 		dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", cid));
@@ -628,36 +1404,110 @@ int aac_read(struct scsi_cmnd * scsicmd,
 
 		if (count == 0)
 			count = 256;
+#if (defined(READ_16))
+	} else if (scsicmd->cmnd[0] == READ_16) { /* 16 byte command */
+		dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", cid));
+
+		lba = ((u64)scsicmd->cmnd[2] << 56)
+		    | ((u64)scsicmd->cmnd[3] << 48)
+		    | ((u64)scsicmd->cmnd[4] << 40)
+		    | ((u64)scsicmd->cmnd[9] << 32)
+		    | ((u64)scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
+		    | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
+		count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16)
+		      | (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
+#endif
+	} else if (scsicmd->cmnd[0] == READ_12) { /* 12 byte command */
+		dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", cid));
+
+		lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
+		    | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
+		count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
+		      | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
 	} else {
 		dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", cid));
 
-		lba = (scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
+		lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
 		count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
 	}
-	dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), lba, jiffies));
+	dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
+	  smp_processor_id(), (unsigned long long)lba, jiffies));
+	if ((!(dev->raw_io_interface) || !(dev->raw_io_64))
+	 && (lba & 0xffffffff00000000LL)) {
+		dprintk((KERN_DEBUG "aac_read: Illegal lba\n"));
+		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
+		set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
+			    HARDWARE_ERROR,
+			    SENCODE_INTERNAL_TARGET_FAILURE,
+			    ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
+			    0, 0);
+		memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
+		  (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
+		    ? sizeof(scsicmd->sense_buffer)
+		    : sizeof(dev->fsa_dev[cid].sense_data));
+#if (defined(AAC_DEBUG_INSTRUMENT_TIMING))
+		__aac_io_done(scsicmd);
+#else
+		scsicmd->scsi_done(scsicmd);
+#endif
+		return 0;
+	}
+	/*
+	 *	Are we in a sequential mode?
+	 */
+	aac_select_queue_depth(scsicmd, cid, lba, count);
 	/*
 	 *	Alocate and initialize a Fib
 	 */
 	if (!(cmd_fibcontext = fib_alloc(dev))) {
-		return -1;
+		scsicmd->result = DID_ERROR << 16;
+		aac_io_done(scsicmd);
+		return 0;
 	}
 
 	fib_init(cmd_fibcontext);
 
-	if(dev->pae_support == 1){
+	if (dev->raw_io_interface) {
+		struct aac_raw_io *readcmd;
+		readcmd = (struct aac_raw_io *) fib_data(cmd_fibcontext);
+		readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
+		readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
+		readcmd->count = cpu_to_le32(count<<9);
+		readcmd->cid = cpu_to_le16(cid);
+		readcmd->flags = cpu_to_le16(1);
+		readcmd->bpTotal = 0;
+		readcmd->bpComplete = 0;
+		
+		aac_build_sgraw(scsicmd, &readcmd->sg);
+		fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
+		if (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)))
+			BUG();
+		/*
+		 *	Now send the Fib to the adapter
+		 */
+		status = fib_send(ContainerRawIo,
+			  cmd_fibcontext, 
+			  fibsize, 
+			  FsaNormal, 
+			  0, 1, 
+			  (fib_callback) io_callback, 
+			  (void *) scsicmd);
+	} else if (dev->dac_support == 1) {
 		struct aac_read64 *readcmd;
 		readcmd = (struct aac_read64 *) fib_data(cmd_fibcontext);
 		readcmd->command = cpu_to_le32(VM_CtHostRead64);
 		readcmd->cid = cpu_to_le16(cid);
 		readcmd->sector_count = cpu_to_le16(count);
-		readcmd->block = cpu_to_le32(lba);
-		readcmd->pad   = cpu_to_le16(0);
-		readcmd->flags = cpu_to_le16(0); 
+		readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
+		readcmd->pad   = 0;
+		readcmd->flags = 0; 
 
 		aac_build_sg64(scsicmd, &readcmd->sg);
-		if(readcmd->sg.count > MAX_DRIVER_SG_SEGMENT_COUNT)
-			BUG();
-		fibsize = sizeof(struct aac_read64) + ((readcmd->sg.count - 1) * sizeof (struct sgentry64));
+		fibsize = sizeof(struct aac_read64) + 
+			((le32_to_cpu(readcmd->sg.count) - 1) * 
+			 sizeof (struct sgentry64));
+		BUG_ON (fibsize > (sizeof(struct hw_fib) - 
+					sizeof(struct aac_fibhdr)));
 		/*
 		 *	Now send the Fib to the adapter
 		 */
@@ -666,23 +1516,22 @@ int aac_read(struct scsi_cmnd * scsicmd,
 			  fibsize, 
 			  FsaNormal, 
 			  0, 1, 
-			  (fib_callback) read_callback, 
+			  (fib_callback) io_callback, 
 			  (void *) scsicmd);
 	} else {
 		struct aac_read *readcmd;
 		readcmd = (struct aac_read *) fib_data(cmd_fibcontext);
 		readcmd->command = cpu_to_le32(VM_CtBlockRead);
 		readcmd->cid = cpu_to_le32(cid);
-		readcmd->block = cpu_to_le32(lba);
+		readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
 		readcmd->count = cpu_to_le32(count * 512);
 
-		if (count * 512 > (64 * 1024))
-			BUG();
-
 		aac_build_sg(scsicmd, &readcmd->sg);
-		if(readcmd->sg.count > MAX_DRIVER_SG_SEGMENT_COUNT)
-			BUG();
-		fibsize = sizeof(struct aac_read) + ((readcmd->sg.count - 1) * sizeof (struct sgentry));
+		fibsize = sizeof(struct aac_read) + 
+			((le32_to_cpu(readcmd->sg.count) - 1) * 
+			 sizeof (struct sgentry));
+		BUG_ON (fibsize > (dev->max_fib_size -
+					sizeof(struct aac_fibhdr)));
 		/*
 		 *	Now send the Fib to the adapter
 		 */
@@ -691,7 +1540,7 @@ int aac_read(struct scsi_cmnd * scsicmd,
 			  fibsize, 
 			  FsaNormal, 
 			  0, 1, 
-			  (fib_callback) read_callback, 
+			  (fib_callback) io_callback, 
 			  (void *) scsicmd);
 	}
 
@@ -701,10 +1550,7 @@ int aac_read(struct scsi_cmnd * scsicmd,
 	 *	Check that the command queued to the controller
 	 */
 	if (status == -EINPROGRESS) 
-	{
-		dprintk("read queued.\n");
 		return 0;
-	}
 		
 	printk(KERN_WARNING "aac_read: fib_send failed with status: %d.\n", status);
 	/*
@@ -714,12 +1560,12 @@ int aac_read(struct scsi_cmnd * scsicmd,
 	aac_io_done(scsicmd);
 	fib_complete(cmd_fibcontext);
 	fib_free(cmd_fibcontext);
-	return -1;
+	return 0;
 }
 
 static int aac_write(struct scsi_cmnd * scsicmd, int cid)
 {
-	u32 lba;
+	u64 lba;
 	u32 count;
 	int status;
 	u16 fibsize;
@@ -730,42 +1576,123 @@ static int aac_write(struct scsi_cmnd * 
 	/*
 	 *	Get block address and transfer length
 	 */
+#if (defined(AAC_DEBUG_INSTRUMENT_IO))
+	printk(KERN_DEBUG "aac_write: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
+	  scsicmd->cmnd[0],  scsicmd->cmnd[1],  scsicmd->cmnd[2],
+	  scsicmd->cmnd[3],  scsicmd->cmnd[4],  scsicmd->cmnd[5],
+	  scsicmd->cmnd[6],  scsicmd->cmnd[7],  scsicmd->cmnd[8],
+	  scsicmd->cmnd[9],  scsicmd->cmnd[10], scsicmd->cmnd[11],
+	  scsicmd->cmnd[12], scsicmd->cmnd[13], scsicmd->cmnd[14],
+	  scsicmd->cmnd[15]);
+#endif
 	if (scsicmd->cmnd[0] == WRITE_6)	/* 6 byte command */
 	{
 		lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
 		count = scsicmd->cmnd[4];
 		if (count == 0)
 			count = 256;
+#if (defined(WRITE_16))
+	} else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
+		dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", cid));
+
+		lba = ((u64)scsicmd->cmnd[2] << 56)
+		    | ((u64)scsicmd->cmnd[3] << 48)
+		    | ((u64)scsicmd->cmnd[4] << 40)
+		    | ((u64)scsicmd->cmnd[9] << 32)
+		    | ((u64)scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
+		    | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
+		count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16)
+		      | (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
+#endif
+	} else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
+		dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", cid));
+
+		lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
+		    | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
+		count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
+		      | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
 	} else {
 		dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", cid));
-		lba = (scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
+		lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
 		count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
 	}
-	dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), lba, jiffies));
+	dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
+	  smp_processor_id(), (unsigned long long)lba, jiffies));
+	if ((!(dev->raw_io_interface) || !(dev->raw_io_64))
+	 && (lba & 0xffffffff00000000LL)) {
+		dprintk((KERN_DEBUG "aac_write: Illegal lba\n"));
+		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
+		set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
+			    HARDWARE_ERROR,
+			    SENCODE_INTERNAL_TARGET_FAILURE,
+			    ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
+			    0, 0);
+		memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
+		  (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
+		    ? sizeof(scsicmd->sense_buffer)
+		    : sizeof(dev->fsa_dev[cid].sense_data));
+#if (defined(AAC_DEBUG_INSTRUMENT_TIMING))
+		__aac_io_done(scsicmd);
+#else
+		scsicmd->scsi_done(scsicmd);
+#endif
+		return 0;
+	}
+	/*
+	 *	Are we in a sequential mode?
+	 */
+	aac_select_queue_depth(scsicmd, cid, lba, count);
 	/*
 	 *	Allocate and initialize a Fib then setup a BlockWrite command
 	 */
 	if (!(cmd_fibcontext = fib_alloc(dev))) {
 		scsicmd->result = DID_ERROR << 16;
 		aac_io_done(scsicmd);
-		return -1;
+		return 0;
 	}
 	fib_init(cmd_fibcontext);
 
-	if(dev->pae_support == 1){
+	if (dev->raw_io_interface) {
+		struct aac_raw_io *writecmd;
+		writecmd = (struct aac_raw_io *) fib_data(cmd_fibcontext);
+		writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
+		writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
+		writecmd->count = cpu_to_le32(count<<9);
+		writecmd->cid = cpu_to_le16(cid);
+		writecmd->flags = 0; 
+		writecmd->bpTotal = 0;
+		writecmd->bpComplete = 0;
+		
+		aac_build_sgraw(scsicmd, &writecmd->sg);
+		fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
+		if (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)))
+			BUG();
+		/*
+		 *	Now send the Fib to the adapter
+		 */
+		status = fib_send(ContainerRawIo,
+			  cmd_fibcontext, 
+			  fibsize, 
+			  FsaNormal, 
+			  0, 1, 
+			  (fib_callback) io_callback, 
+			  (void *) scsicmd);
+	} else if (dev->dac_support == 1) {
 		struct aac_write64 *writecmd;
 		writecmd = (struct aac_write64 *) fib_data(cmd_fibcontext);
 		writecmd->command = cpu_to_le32(VM_CtHostWrite64);
 		writecmd->cid = cpu_to_le16(cid);
 		writecmd->sector_count = cpu_to_le16(count); 
-		writecmd->block = cpu_to_le32(lba);
-		writecmd->pad	= cpu_to_le16(0);
-		writecmd->flags	= cpu_to_le16(0);
+		writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
+		writecmd->pad	= 0;
+		writecmd->flags	= 0;
 
 		aac_build_sg64(scsicmd, &writecmd->sg);
-		if(writecmd->sg.count > MAX_DRIVER_SG_SEGMENT_COUNT)
-			BUG();
-		fibsize = sizeof(struct aac_write64) + ((writecmd->sg.count - 1) * sizeof (struct sgentry64));
+		fibsize = sizeof(struct aac_write64) + 
+			((le32_to_cpu(writecmd->sg.count) - 1) * 
+			 sizeof (struct sgentry64));
+		BUG_ON (fibsize > (dev->max_fib_size -
+					sizeof(struct aac_fibhdr)));
 		/*
 		 *	Now send the Fib to the adapter
 		 */
@@ -774,26 +1701,24 @@ static int aac_write(struct scsi_cmnd * 
 			  fibsize, 
 			  FsaNormal, 
 			  0, 1, 
-			  (fib_callback) write_callback, 
+			  (fib_callback) io_callback, 
 			  (void *) scsicmd);
 	} else {
 		struct aac_write *writecmd;
 		writecmd = (struct aac_write *) fib_data(cmd_fibcontext);
 		writecmd->command = cpu_to_le32(VM_CtBlockWrite);
 		writecmd->cid = cpu_to_le32(cid);
-		writecmd->block = cpu_to_le32(lba);
+		writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
 		writecmd->count = cpu_to_le32(count * 512);
 		writecmd->sg.count = cpu_to_le32(1);
 		/* ->stable is not used - it did mean which type of write */
 
-		if (count * 512 > (64 * 1024)) {
-			BUG();
-		}
-
 		aac_build_sg(scsicmd, &writecmd->sg);
-		if(writecmd->sg.count > MAX_DRIVER_SG_SEGMENT_COUNT)
-			BUG();
-		fibsize = sizeof(struct aac_write) + ((writecmd->sg.count - 1) * sizeof (struct sgentry));
+		fibsize = sizeof(struct aac_write) + 
+			((le32_to_cpu(writecmd->sg.count) - 1) * 
+			 sizeof (struct sgentry));
+		BUG_ON (fibsize > (dev->max_fib_size -
+					sizeof(struct aac_fibhdr)));
 		/*
 		 *	Now send the Fib to the adapter
 		 */
@@ -802,7 +1727,7 @@ static int aac_write(struct scsi_cmnd * 
 			  fibsize, 
 			  FsaNormal, 
 			  0, 1, 
-			  (fib_callback) write_callback, 
+			  (fib_callback) io_callback, 
 			  (void *) scsicmd);
 	}
 
@@ -811,7 +1736,6 @@ static int aac_write(struct scsi_cmnd * 
 	 */
 	if (status == -EINPROGRESS)
 	{
-		dprintk("write queued.\n");
 		return 0;
 	}
 
@@ -824,9 +1748,164 @@ static int aac_write(struct scsi_cmnd * 
 
 	fib_complete(cmd_fibcontext);
 	fib_free(cmd_fibcontext);
-	return -1;
+	return 0;
+}
+
+static void synchronize_callback(void *context, struct fib *fibptr)
+{
+	struct aac_synchronize_reply *synchronizereply;
+	struct scsi_cmnd *cmd;
+
+	cmd = context;
+
+	dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n", 
+				smp_processor_id(), jiffies));
+	BUG_ON(fibptr == NULL);
+
+
+	synchronizereply = fib_data(fibptr);
+	if (le32_to_cpu(synchronizereply->status) == CT_OK)
+		cmd->result = DID_OK << 16 | 
+			COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
+	else {
+		struct scsi_device *sdev = cmd->device;
+		struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
+		u32 cid = ID_LUN_TO_CONTAINER(sdev->id, sdev->lun);
+		printk(KERN_WARNING 
+		     "synchronize_callback: synchronize failed, status = %d\n",
+		     le32_to_cpu(synchronizereply->status));
+		cmd->result = DID_OK << 16 | 
+			COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
+		set_sense((u8 *)&dev->fsa_dev[cid].sense_data,
+				    HARDWARE_ERROR,
+				    SENCODE_INTERNAL_TARGET_FAILURE,
+				    ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
+				    0, 0);
+		memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
+		  min(sizeof(dev->fsa_dev[cid].sense_data), 
+			  sizeof(cmd->sense_buffer)));
+	}
+
+	fib_complete(fibptr);
+	fib_free(fibptr);
+	aac_io_done(cmd);
+}
+
+static int aac_synchronize(struct scsi_cmnd *scsicmd, int cid)
+{
+	int status;
+	struct fib *cmd_fibcontext;
+	struct aac_synchronize *synchronizecmd;
+	struct scsi_cmnd *cmd;
+	struct scsi_device *sdev = scsicmd->device;
+	int active = 0;
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+	unsigned long flags;
+
+	/*
+	 * Wait for all commands to complete to this specific
+	 * target (block).
+	 */
+	spin_lock_irqsave(&sdev->list_lock, flags);
+	list_for_each_entry(cmd, &sdev->cmd_list, list)
+		if (cmd != scsicmd && cmd->serial_number != 0) {
+			++active;
+			break;
+		}
+
+	spin_unlock_irqrestore(&sdev->list_lock, flags);
+#else
+
+	/*
+	 * Wait for all commands to complete to this specific
+	 * target (block).
+	 */
+	for(cmd = sdev->device_queue; cmd; cmd = cmd->next)
+		if ((cmd != scsicmd) && (cmd->serial_number != 0)) {
+			++active;
+			break;
+		}
+#endif
+
+	/*
+	 *	Yield the processor (requeue for later)
+	 */
+	if (active)
+		return SCSI_MLQUEUE_DEVICE_BUSY;
+
+#if (defined(AAC_DEBUG_INSTRUMENT_IO))
+	printk(KERN_DEBUG "aac_synchronize[cpu %d]: t = %ld.\n",
+	  smp_processor_id(), jiffies);
+#endif
+	/*
+	 *	Allocate and initialize a Fib
+	 */
+	if (!(cmd_fibcontext = 
+	    fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) 
+		return SCSI_MLQUEUE_HOST_BUSY;
+
+	fib_init(cmd_fibcontext);
+
+	synchronizecmd = fib_data(cmd_fibcontext);
+	synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
+	synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
+	synchronizecmd->cid = cpu_to_le32(cid);
+	synchronizecmd->count = 
+	     cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
+
+	/*
+	 *	Now send the Fib to the adapter
+	 */
+	status = fib_send(ContainerCommand,
+		  cmd_fibcontext,
+		  sizeof(struct aac_synchronize),
+		  FsaNormal,
+		  0, 1,
+		  (fib_callback)synchronize_callback,
+		  (void *)scsicmd);
+
+	/*
+	 *	Check that the command queued to the controller
+	 */
+	if (status == -EINPROGRESS)
+		return 0;
+
+	printk(KERN_WARNING 
+		"aac_synchronize: fib_send failed with status: %d.\n", status);
+	fib_complete(cmd_fibcontext);
+	fib_free(cmd_fibcontext);
+	return SCSI_MLQUEUE_HOST_BUSY;
+}
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+
+static inline void get_sd_devname(int disknum, char *buffer)
+{
+	if (disknum < 0) {
+		buffer[0] = '\0';
+		return;
+	}
+
+	buffer[0] = 's';
+	buffer[1] = 'd';
+	if (disknum < 26) {
+		buffer[2] = 'a' + disknum;
+		buffer[3] = '\0';
+	} else {
+		/*
+		 * For larger numbers of disks, we need to go to a new
+		 * naming scheme.
+		 */
+		buffer[2] = 'a' - 1 + (disknum / 26);
+		buffer[3] = 'a' + (disknum % 26);
+		buffer[4] = '\0';
+	}
 }
 
+# define strlcpy(s1,s2,n) strncpy(s1,s2,n);s1[n-1]='\0'
+# ifndef min
+#  define min(a,b) (((a)<(b))?(a):(b))
+# endif
+#endif
 
 /**
  *	aac_scsi_cmd()		-	Process SCSI command
@@ -839,12 +1918,20 @@ static int aac_write(struct scsi_cmnd * 
 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
 {
 	u32 cid = 0;
-	int ret;
 	struct Scsi_Host *host = scsicmd->device->host;
 	struct aac_dev *dev = (struct aac_dev *)host->hostdata;
-	struct fsa_scsi_hba *fsa_dev_ptr = &dev->fsa_dev;
-	int cardtype = dev->cardtype;
+	struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
 	
+#	if (defined(AAC_DEBUG_INSTRUMENT_2TB))
+		printk(KERN_NOTICE "scsicmd->cmnd={%02x %02x %02x %02x %02x "
+		  "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x}\n",
+		  scsicmd->cmnd[0], scsicmd->cmnd[1], scsicmd->cmnd[2],
+		  scsicmd->cmnd[3], scsicmd->cmnd[4], scsicmd->cmnd[5],
+		  scsicmd->cmnd[6], scsicmd->cmnd[7], scsicmd->cmnd[8],
+		  scsicmd->cmnd[9], scsicmd->cmnd[10], scsicmd->cmnd[11],
+		  scsicmd->cmnd[12], scsicmd->cmnd[13], scsicmd->cmnd[14],
+		  scsicmd->cmnd[15]);
+#	endif
 	/*
 	 *	If the bus, id or lun is out of range, return fail
 	 *	Test does not apply to ID 16, the pseudo id for the controller
@@ -852,9 +1939,19 @@ int aac_scsi_cmd(struct scsi_cmnd * scsi
 	 */
 	if (scsicmd->device->id != host->this_id) {
 		if ((scsicmd->device->channel == 0) ){
-			if( (scsicmd->device->id >= MAXIMUM_NUM_CONTAINERS) || (scsicmd->device->lun != 0)){ 
+			if( (scsicmd->device->id >= dev->maximum_num_containers) || (scsicmd->device->lun != 0)){ 
+#				if (defined(AAC_DEBUG_INSTRUMENT_2TB))
+					printk(KERN_INFO
+					  "scsicmd(0:%d:%d:0) No Connect\n",
+					  scsicmd->device->channel,
+					  scsicmd->device->id);
+#				endif
 				scsicmd->result = DID_NO_CONNECT << 16;
+#if (defined(AAC_DEBUG_INSTRUMENT_TIMING))
 				__aac_io_done(scsicmd);
+#else
+				scsicmd->scsi_done(scsicmd);
+#endif
 				return 0;
 			}
 			cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
@@ -863,38 +1960,127 @@ int aac_scsi_cmd(struct scsi_cmnd * scsi
 			 *	If the target container doesn't exist, it may have
 			 *	been newly created
 			 */
-			if (fsa_dev_ptr->valid[cid] == 0) {
+#if (!defined(__arm__) && !defined(CONFIG_EXTERNAL))
+			if ((fsa_dev_ptr[cid].valid & 1) == 0) {
+#endif
 				switch (scsicmd->cmnd[0]) {
+#if (defined(SERVICE_ACTION_IN))
+				case SERVICE_ACTION_IN:
+					if (!(dev->raw_io_interface)
+					 || !(dev->raw_io_64)
+					 || ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
+						break;
+#endif
 				case INQUIRY:
 				case READ_CAPACITY:
 				case TEST_UNIT_READY:
-					spin_unlock_irq(host->host_lock);
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,19))
+# if (MAX_NESTED == 1)
+					if (fsa_dev_ptr[cid].nested)
+						return -1;
+					fsa_dev_ptr[cid].nested = 1;
+# else
+					if (fsa_dev_ptr[cid].nested >= MAX_NESTED)
+						return -1;
+					++(fsa_dev_ptr[cid].nested);
+# endif
+#endif
+					aac_spin_unlock_irq(host->host_lock);
 					probe_container(dev, cid);
-					spin_lock_irq(host->host_lock);
-					if (fsa_dev_ptr->valid[cid] == 0) {
+					if ((fsa_dev_ptr[cid].valid & 1) == 0)
+						fsa_dev_ptr[cid].valid = 0;
+					aac_spin_lock_irq(host->host_lock);
+					if (fsa_dev_ptr[cid].valid == 0) {
+#						if (defined(AAC_DEBUG_INSTRUMENT_2TB))
+							printk(KERN_INFO
+							  "scsicmd(0:%d:%d:0) "
+							  "Invalid\n",
+							  scsicmd->device->channel,
+							  scsicmd->device->id);
+#						endif
 						scsicmd->result = DID_NO_CONNECT << 16;
+#if (defined(AAC_DEBUG_INSTRUMENT_TIMING))
 						__aac_io_done(scsicmd);
+#else
+						scsicmd->scsi_done(scsicmd);
+#endif
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,19))
+# if (MAX_NESTED == 1)
+						fsa_dev_ptr[cid].nested = 0;
+# else
+						if (fsa_dev_ptr[cid].nested != 0)
+							--(fsa_dev_ptr[cid].nested);
+# endif
+#endif
 						return 0;
 					}
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,19))
+# if (MAX_NESTED == 1)
+					fsa_dev_ptr[cid].nested = 0;
+# else
+					if (fsa_dev_ptr[cid].nested != 0)
+						--(fsa_dev_ptr[cid].nested);
+# endif
+#endif
 				default:
 					break;
 				}
+#if (!defined(__arm__) && !defined(CONFIG_EXTERNAL))
 			}
+#endif
 			/*
 			 *	If the target container still doesn't exist, 
 			 *	return failure
 			 */
-			if (fsa_dev_ptr->valid[cid] == 0) {
+			if (fsa_dev_ptr[cid].valid == 0) {
+#				if (defined(AAC_DEBUG_INSTRUMENT_2TB))
+					printk(KERN_INFO
+					  "scsicmd(0:%d:%d:0) Does not exist\n",
+					  scsicmd->device->channel,
+					  scsicmd->device->id);
+#				endif
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,19))
+# if (MAX_NESTED == 1)
+				if (fsa_dev_ptr[cid].nested)
+					return -1;
+				fsa_dev_ptr[cid].nested = 1;
+# else
+				if (fsa_dev_ptr[cid].nested >= MAX_NESTED)
+					return -1;
+				++(fsa_dev_ptr[cid].nested);
+# endif
+#endif
 				scsicmd->result = DID_BAD_TARGET << 16;
+#if (defined(AAC_DEBUG_INSTRUMENT_TIMING))
 				__aac_io_done(scsicmd);
+#else
+				scsicmd->scsi_done(scsicmd);
+#endif
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,19))
+# if (MAX_NESTED == 1)
+				fsa_dev_ptr[cid].nested = 0;
+# else
+				if (fsa_dev_ptr[cid].nested != 0)
+					--(fsa_dev_ptr[cid].nested);
+# endif
+#endif
 				return 0;
 			}
 		} else {  /* check for physical non-dasd devices */
+#			if (defined(AAC_DEBUG_INSTRUMENT_2TB))
+				printk(KERN_INFO "scsicmd(0:%d:%d:0) Phys\n",
+				  scsicmd->device->channel,
+				  scsicmd->device->id);
+#			endif
 			if(dev->nondasd_support == 1){
 				return aac_send_srb_fib(scsicmd);
 			} else {
 				scsicmd->result = DID_NO_CONNECT << 16;
+#if (defined(AAC_DEBUG_INSTRUMENT_TIMING))
 				__aac_io_done(scsicmd);
+#else
+				scsicmd->scsi_done(scsicmd);
+#endif
 				return 0;
 			}
 		}
@@ -907,17 +2093,27 @@ int aac_scsi_cmd(struct scsi_cmnd * scsi
 	{
 		dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
 		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
-		set_sense((u8 *) &sense_data[cid],
+		set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
 			    ILLEGAL_REQUEST,
 			    SENCODE_INVALID_COMMAND,
 			    ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
+		memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
+		  (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
+		    ? sizeof(scsicmd->sense_buffer)
+		    : sizeof(dev->fsa_dev[cid].sense_data));
+#if (defined(AAC_DEBUG_INSTRUMENT_TIMING))
 		__aac_io_done(scsicmd);
-		memcpy(scsicmd->sense_buffer, &sense_data[cid], sizeof(struct sense_data));
+#else
+		scsicmd->scsi_done(scsicmd);
+#endif
 		return 0;
 	}
 
 
 	/* Handle commands here that don't really require going out to the adapter */
+#	if (defined(AAC_DEBUG_INSTRUMENT_2TB))
+		printk(KERN_NOTICE "cmnd[0]=%02x\n", scsicmd->cmnd[0]);
+#	endif
 	switch (scsicmd->cmnd[0]) {
 	case INQUIRY:
 	{
@@ -928,7 +2124,6 @@ int aac_scsi_cmd(struct scsi_cmnd * scsi
 		memset(inq_data_ptr, 0, sizeof (struct inquiry_data));
 
 		inq_data_ptr->inqd_ver = 2;	/* claim compliance to SCSI-2 */
-		inq_data_ptr->inqd_dtq = 0x80;	/* set RMB bit to one indicating that the medium is removable */
 		inq_data_ptr->inqd_rdf = 2;	/* A response data format value of two indicates that the data shall be in the format specified in SCSI-2 */
 		inq_data_ptr->inqd_len = 31;
 		/*Format for "pad2" is  RelAdr | WBus32 | WBus16 |  Sync  | Linked |Reserved| CmdQue | SftRe */
@@ -937,22 +2132,88 @@ int aac_scsi_cmd(struct scsi_cmnd * scsi
 		 *	Set the Vendor, Product, and Revision Level
 		 *	see: <vendor>.c i.e. aac.c
 		 */
-		setinqstr(cardtype, (void *) (inq_data_ptr->inqd_vid), fsa_dev_ptr->type[cid]);
-		if (scsicmd->device->id == host->this_id)
+		if (scsicmd->device->id == host->this_id) {
+			setinqstr(dev, (void *) (inq_data_ptr->inqd_vid), (sizeof(container_types)/sizeof(char *)));
 			inq_data_ptr->inqd_pdt = INQD_PDT_PROC;	/* Processor device */
-		else
-			inq_data_ptr->inqd_pdt = INQD_PDT_DA;	/* Direct/random access device */
+			scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
+#if (defined(AAC_DEBUG_INSTRUMENT_TIMING))
+			__aac_io_done(scsicmd);
+#else
+			scsicmd->scsi_done(scsicmd);
+#endif
+			return 0;
+		}
+		setinqstr(dev, (void *) (inq_data_ptr->inqd_vid), fsa_dev_ptr[cid].type);
+		inq_data_ptr->inqd_pdt = INQD_PDT_DA;	/* Direct/random access device */
+		return aac_get_container_name(scsicmd, cid);
+	}
+#if (defined(SERVICE_ACTION_IN))
+	case SERVICE_ACTION_IN:
+#if (defined(AAC_DEBUG_INSTRUMENT_2TB))
+		printk(KERN_NOTICE
+		  "SERVICE_ACTION_IN, raw_io_interface=%d raw_io_64=%d\n",
+		  dev->raw_io_interface, dev->raw_io_64);
+#endif
+		if (!(dev->raw_io_interface)
+		 || !(dev->raw_io_64)
+		 || ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
+			break;
+	{
+		u64 capacity;
+		char *cp;
+
+		dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
+		capacity = fsa_dev_ptr[cid].size - 1;
+		cp = scsicmd->request_buffer;
+		if (scsicmd->cmnd[13] > 12) {
+			memset(cp, 0, scsicmd->cmnd[13] - 12);
+			cp += scsicmd->cmnd[13] - 12;
+		}
+		cp[0] = (capacity >> 56) & 0xff;
+		cp[1] = (capacity >> 48) & 0xff;
+		cp[2] = (capacity >> 40) & 0xff;
+		cp[3] = (capacity >> 32) & 0xff;
+		cp[4] = (capacity >> 24) & 0xff;
+		cp[5] = (capacity >> 16) & 0xff;
+		cp[6] = (capacity >> 8) & 0xff;
+		cp[7] = (capacity >> 0) & 0xff;
+		cp[8] = 0;
+		cp[9] = 0;
+		cp[10] = 2;
+		cp[11] = 0;
+#if (defined(AAC_DEBUG_INSTRUMENT_2TB))
+		printk(KERN_INFO "SAI_READ_CAPACITY_16(%d): "
+		  "%02x %02x %02x %02x %02x %02x %02x %02x "
+		  "%02x %02x %02x %02x\n",
+		  scsicmd->cmnd[13],
+		  cp[0] & 0xff, cp[1] & 0xff, cp[2] & 0xff, cp[3] & 0xff,
+		  cp[4] & 0xff, cp[5] & 0xff, cp[6] & 0xff, cp[7] & 0xff,
+		  cp[8] & 0xff, cp[9] & 0xff, cp[10] & 0xff, cp[11] & 0xff);
+#endif
+
+		/* Do not cache partition table for arrays */
+		scsicmd->device->removable = 1;
+
 		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
+#if (defined(AAC_DEBUG_INSTRUMENT_TIMING))
 		__aac_io_done(scsicmd);
+#else
+		scsicmd->scsi_done(scsicmd);
+#endif
+
 		return 0;
 	}
+#endif
 	case READ_CAPACITY:
 	{
-		int capacity;
+		u32 capacity;
 		char *cp;
 
 		dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
-		capacity = fsa_dev_ptr->size[cid] - 1;
+		if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
+			capacity = fsa_dev_ptr[cid].size - 1;
+		else
+			capacity = (u32)-1;
 		cp = scsicmd->request_buffer;
 		cp[0] = (capacity >> 24) & 0xff;
 		cp[1] = (capacity >> 16) & 0xff;
@@ -962,9 +2223,22 @@ int aac_scsi_cmd(struct scsi_cmnd * scsi
 		cp[5] = 0;
 		cp[6] = 2;
 		cp[7] = 0;
+#if (defined(AAC_DEBUG_INSTRUMENT_2TB))
+		printk(KERN_INFO "READ_CAPACITY: "
+		  "%02x %02x %02x %02x %02x %02x %02x %02x\n",
+		  cp[0] & 0xff, cp[1] & 0xff, cp[2] & 0xff, cp[3] & 0xff,
+		  cp[4] & 0xff, cp[5] & 0xff, cp[6] & 0xff, cp[7] & 0xff);
+#endif
+
+		/* Do not cache partition table for arrays */
+		scsicmd->device->removable = 1;
 
 		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
+#if (defined(AAC_DEBUG_INSTRUMENT_TIMING))
 		__aac_io_done(scsicmd);
+#else
+		scsicmd->scsi_done(scsicmd);
+#endif
 
 		return 0;
 	}
@@ -981,7 +2255,11 @@ int aac_scsi_cmd(struct scsi_cmnd * scsi
 		mode_buf[3] = 0;	/* Block descriptor length */
 
 		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
+#if (defined(AAC_DEBUG_INSTRUMENT_TIMING))
 		__aac_io_done(scsicmd);
+#else
+		scsicmd->scsi_done(scsicmd);
+#endif
 
 		return 0;
 	}
@@ -1001,27 +2279,39 @@ int aac_scsi_cmd(struct scsi_cmnd * scsi
 		mode_buf[7] = 0;	/* Block descriptor length (LSB) */
 
 		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
+#if (defined(AAC_DEBUG_INSTRUMENT_TIMING))
 		__aac_io_done(scsicmd);
+#else
+		scsicmd->scsi_done(scsicmd);
+#endif
 
 		return 0;
 	}
 	case REQUEST_SENSE:
 		dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
-		memcpy(scsicmd->sense_buffer, &sense_data[cid], sizeof (struct sense_data));
-		memset(&sense_data[cid], 0, sizeof (struct sense_data));
+		memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
+		memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
 		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
+#if (defined(AAC_DEBUG_INSTRUMENT_TIMING))
 		__aac_io_done(scsicmd);
+#else
+		scsicmd->scsi_done(scsicmd);
+#endif
 		return 0;
 
 	case ALLOW_MEDIUM_REMOVAL:
 		dprintk((KERN_DEBUG "LOCK command.\n"));
 		if (scsicmd->cmnd[4])
-			fsa_dev_ptr->locked[cid] = 1;
+			fsa_dev_ptr[cid].locked = 1;
 		else
-			fsa_dev_ptr->locked[cid] = 0;
+			fsa_dev_ptr[cid].locked = 0;
 
 		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
+#if (defined(AAC_DEBUG_INSTRUMENT_TIMING))
 		__aac_io_done(scsicmd);
+#else
+		scsicmd->scsi_done(scsicmd);
+#endif
 		return 0;
 	/*
 	 *	These commands are all No-Ops
@@ -1034,7 +2324,11 @@ int aac_scsi_cmd(struct scsi_cmnd * scsi
 	case SEEK_10:
 	case START_STOP:
 		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
+#if (defined(AAC_DEBUG_INSTRUMENT_TIMING))
 		__aac_io_done(scsicmd);
+#else
+		scsicmd->scsi_done(scsicmd);
+#endif
 		return 0;
 	}
 
@@ -1042,57 +2336,136 @@ int aac_scsi_cmd(struct scsi_cmnd * scsi
 	{
 		case READ_6:
 		case READ_10:
+		case READ_12:
+#if (defined(READ_16))
+		case READ_16:
+#endif
 			/*
 			 *	Hack to keep track of ordinal number of the device that
 			 *	corresponds to a container. Needed to convert
 			 *	containers to /dev/sd device names
 			 */
+#if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) && defined(AAC_EXTENDED_TIMEOUT))
+			if ((scsicmd->eh_state != SCSI_STATE_QUEUED)
+			 && (extendedtimeout > 0)) {
+				mod_timer(&scsicmd->eh_timeout, jiffies + (extendedtimeout * HZ));
+			}
+#endif
 			 
-			spin_unlock_irq(host->host_lock);
-			if  (scsicmd->request->rq_disk)
-				memcpy(fsa_dev_ptr->devname[cid],
-					scsicmd->request->rq_disk->disk_name,
-					8);
-
-			ret = aac_read(scsicmd, cid);
-			spin_lock_irq(host->host_lock);
-			return ret;
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+#if (defined(AAC_DEBUG_INSTRUMENT_IOCTL))
+			if(fsa_dev_ptr[cid].devname[0]=='\0') {
+				printk(KERN_INFO
+				  "rq_disk=%p disk_name=\"%s\"\n",
+				  scsicmd->request->rq_disk,
+				  scsicmd->request->rq_disk
+				    ? scsicmd->request->rq_disk->disk_name
+				    : "Aiiiii");
+			}
+#endif
+			if (scsicmd->request->rq_disk)
+				strlcpy(fsa_dev_ptr[cid].devname,
+				  scsicmd->request->rq_disk->disk_name,
+				  min(
+				    sizeof(fsa_dev_ptr[cid].devname),
+				    sizeof(scsicmd->request->rq_disk->disk_name) + 1));
+#else
+			get_sd_devname(DEVICE_NR(scsicmd->request.rq_dev), fsa_dev_ptr[cid].devname);
+#endif
+
+			return aac_read(scsicmd, cid);
 
 		case WRITE_6:
 		case WRITE_10:
-			spin_unlock_irq(host->host_lock);
-			ret = aac_write(scsicmd, cid);
-			spin_lock_irq(host->host_lock);
-			return ret;
+		case WRITE_12:
+#if (defined(WRITE_16))
+		case WRITE_16:
+#endif
+#if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) && defined(AAC_EXTENDED_TIMEOUT))
+			if ((scsicmd->eh_state != SCSI_STATE_QUEUED)
+			 && (extendedtimeout > 0)) {
+				mod_timer(&scsicmd->eh_timeout, jiffies + (extendedtimeout * HZ));
+			}
+#endif
+			return aac_write(scsicmd, cid);
+
+		case SYNCHRONIZE_CACHE:
+			/* Issue FIB to tell Firmware to flush it's cache */
+			return aac_synchronize(scsicmd, cid);
+			
 		default:
 			/*
 			 *	Unhandled commands
 			 */
-			printk(KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]);
+			dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
 			scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
-			set_sense((u8 *) &sense_data[cid],
+			set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
 				ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
-			ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
-			memcpy(scsicmd->sense_buffer, &sense_data[cid],
-				sizeof(struct sense_data));
+				ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
+			memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
+			  (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
+			    ? sizeof(scsicmd->sense_buffer)
+			    : sizeof(dev->fsa_dev[cid].sense_data));
+#if (defined(AAC_DEBUG_INSTRUMENT_TIMING))
 			__aac_io_done(scsicmd);
+#else
+			scsicmd->scsi_done(scsicmd);
+#endif
 			return 0;
 	}
 }
 
+static int busy_disk(struct aac_dev * dev, int cid)
+{
+	if ((dev != (struct aac_dev *)NULL)
+	 && (dev->scsi_host_ptr != (struct Scsi_Host *)NULL)) {
+		struct scsi_device *device;
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
+		shost_for_each_device(device, dev->scsi_host_ptr)
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+		list_for_each_entry(device, &dev->scsi_host_ptr->my_devices, siblings)
+#else
+		for (device = dev->scsi_host_ptr->host_queue;
+		  device != (struct scsi_device *)NULL;
+		  device = device->next)
+#endif
+		{
+			if ((device->channel == CONTAINER_TO_CHANNEL(cid))
+			 && (device->id == CONTAINER_TO_ID(cid))
+			 && (device->lun == CONTAINER_TO_LUN(cid))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
+			 && (atomic_read(&device->access_count)
+			  || test_bit(SHOST_RECOVERY, &dev->scsi_host_ptr->shost_state))) {
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
+			&& (device->device_busy
+			  || test_bit(SHOST_RECOVERY, &dev->scsi_host_ptr->shost_state))) {
+#else
+			&& (device->access_count
+			  || dev->scsi_host_ptr->in_recovery)) {
+#endif
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
+				scsi_device_put(device);
+#endif
+				return 1;
+			}
+		}
+	}
+	return 0;
+}
+
 static int query_disk(struct aac_dev *dev, void __user *arg)
 {
 	struct aac_query_disk qd;
-	struct fsa_scsi_hba *fsa_dev_ptr;
+	struct fsa_dev_info *fsa_dev_ptr;
 
-	fsa_dev_ptr = &(dev->fsa_dev);
+	fsa_dev_ptr = dev->fsa_dev;
 	if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
 		return -EFAULT;
 	if (qd.cnum == -1)
 		qd.cnum = ID_LUN_TO_CONTAINER(qd.id, qd.lun);
 	else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1)) 
 	{
-		if (qd.cnum < 0 || qd.cnum >= MAXIMUM_NUM_CONTAINERS)
+		if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
 			return -EINVAL;
 		qd.instance = dev->scsi_host_ptr->host_no;
 		qd.bus = 0;
@@ -1101,16 +2474,17 @@ static int query_disk(struct aac_dev *de
 	}
 	else return -EINVAL;
 
-	qd.valid = fsa_dev_ptr->valid[qd.cnum];
-	qd.locked = fsa_dev_ptr->locked[qd.cnum];
-	qd.deleted = fsa_dev_ptr->deleted[qd.cnum];
+	qd.valid = fsa_dev_ptr[qd.cnum].valid != 0;
+	qd.locked = fsa_dev_ptr[qd.cnum].locked || busy_disk(dev, qd.cnum);
+	qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
 
-	if (fsa_dev_ptr->devname[qd.cnum][0] == '\0')
+	if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
 		qd.unmapped = 1;
 	else
 		qd.unmapped = 0;
 
-	strlcpy(qd.name, fsa_dev_ptr->devname[qd.cnum], sizeof(qd.name));
+	strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
+	  min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
 
 	if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
 		return -EFAULT;
@@ -1120,65 +2494,125 @@ static int query_disk(struct aac_dev *de
 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
 {
 	struct aac_delete_disk dd;
-	struct fsa_scsi_hba *fsa_dev_ptr;
+	struct fsa_dev_info *fsa_dev_ptr;
 
-	fsa_dev_ptr = &(dev->fsa_dev);
+	fsa_dev_ptr = dev->fsa_dev;
 
 	if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
 		return -EFAULT;
 
-	if (dd.cnum >= MAXIMUM_NUM_CONTAINERS)
+	if (dd.cnum >= dev->maximum_num_containers)
 		return -EINVAL;
 	/*
 	 *	Mark this container as being deleted.
 	 */
-	fsa_dev_ptr->deleted[dd.cnum] = 1;
+	fsa_dev_ptr[dd.cnum].deleted = 1;
 	/*
 	 *	Mark the container as no longer valid
 	 */
-	fsa_dev_ptr->valid[dd.cnum] = 0;
+	fsa_dev_ptr[dd.cnum].valid = 0;
 	return 0;
 }
 
 static int delete_disk(struct aac_dev *dev, void __user *arg)
 {
 	struct aac_delete_disk dd;
-	struct fsa_scsi_hba *fsa_dev_ptr;
+	struct fsa_dev_info *fsa_dev_ptr;
 
-	fsa_dev_ptr = &(dev->fsa_dev);
+	fsa_dev_ptr = dev->fsa_dev;
 
 	if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
 		return -EFAULT;
 
-	if (dd.cnum >= MAXIMUM_NUM_CONTAINERS)
+	if (dd.cnum >= dev->maximum_num_containers)
 		return -EINVAL;
 	/*
 	 *	If the container is locked, it can not be deleted by the API.
 	 */
-	if (fsa_dev_ptr->locked[dd.cnum])
+	if (fsa_dev_ptr[dd.cnum].locked || busy_disk(dev, dd.cnum))
 		return -EBUSY;
 	else {
 		/*
 		 *	Mark the container as no longer being valid.
 		 */
-		fsa_dev_ptr->valid[dd.cnum] = 0;
-		fsa_dev_ptr->devname[dd.cnum][0] = '\0';
+		fsa_dev_ptr[dd.cnum].valid = 0;
+		fsa_dev_ptr[dd.cnum].devname[0] = '\0';
+		return 0;
+	}
+}
+
+#if (defined(FSACTL_REGISTER_FIB_SEND))
+static int aac_register_fib_send(struct aac_dev *dev, void *arg)
+{
+	fib_send_t callback;
+
+	if (arg == NULL) {
+		return -EINVAL;
+	}
+	callback = *((fib_send_t *)arg);
+	*((fib_send_t *)arg) = aac_fib_send;
+	if (callback == (fib_send_t)NULL) {
+		fib_send = aac_fib_send;
 		return 0;
 	}
+	if (fib_send != aac_fib_send) {
+		return -EBUSY;
+	}
+	fib_send = callback;
+	return 0;
 }
 
+#endif
 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
 {
+#if (defined(AAC_DEBUG_INSTRUMENT_IOCTL))
+	int retval;
+	if (cmd != FSACTL_GET_NEXT_ADAPTER_FIB)
+		printk("aac_dev_ioctl(%p,%x,%p)\n", dev, cmd, arg);
+#endif
 	switch (cmd) {
 	case FSACTL_QUERY_DISK:
+#if (defined(AAC_DEBUG_INSTRUMENT_IOCTL))
+		retval = query_disk(dev, arg);
+		printk("aac_dev_ioctl returns %d\n", retval);
+		return retval;
+#endif
 		return query_disk(dev, arg);
 	case FSACTL_DELETE_DISK:
+#if (defined(AAC_DEBUG_INSTRUMENT_IOCTL))
+		retval = delete_disk(dev, arg);
+		printk("aac_dev_ioctl returns %d\n", retval);
+		return retval;
+#endif
 		return delete_disk(dev, arg);
 	case FSACTL_FORCE_DELETE_DISK:
+#if (defined(AAC_DEBUG_INSTRUMENT_IOCTL))
+		retval = force_delete_disk(dev, arg);
+		printk("aac_dev_ioctl returns %d\n", retval);
+		return retval;
+#endif
 		return force_delete_disk(dev, arg);
 	case FSACTL_GET_CONTAINERS:
+#if (defined(AAC_DEBUG_INSTRUMENT_IOCTL))
+		retval = aac_get_containers(dev);
+		printk("aac_dev_ioctl returns %d\n", retval);
+		return retval;
+#endif
 		return aac_get_containers(dev);
+#if (defined(FSACTL_REGISTER_FIB_SEND))
+	case FSACTL_REGISTER_FIB_SEND:
+#if (defined(AAC_DEBUG_INSTRUMENT_IOCTL))
+		retval = aac_register_fib_send(dev, arg);
+		printk("aac_dev_ioctl returns %d\n", retval);
+		return retval;
+#endif
+		return aac_register_fib_send(dev, arg);
+#endif
 	default:
+#if (defined(AAC_DEBUG_INSTRUMENT_IOCTL))
+		printk("aac_dev_ioctl returns -ENOTTY\n");
+	case FSACTL_GET_NEXT_ADAPTER_FIB:
+#endif
 		return -ENOTTY;
 	}
 }
@@ -1212,7 +2646,8 @@ static void aac_srb_callback(void *conte
 	 *	Calculate resid for sg 
 	 */
 	 
-	scsicmd->resid = scsicmd->request_bufflen - srbreply->data_xfer_length;
+	scsicmd->resid = scsicmd->request_bufflen - 
+		le32_to_cpu(srbreply->data_xfer_length);
 
 	if(scsicmd->use_sg)
 		pci_unmap_sg(dev->pdev, 
@@ -1220,7 +2655,7 @@ static void aac_srb_callback(void *conte
 			scsicmd->use_sg,
 			scsicmd->sc_data_direction);
 	else if(scsicmd->request_bufflen)
-		pci_unmap_single(dev->pdev, (ulong)scsicmd->SCp.ptr, scsicmd->request_bufflen,
+		pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle, scsicmd->request_bufflen,
 			scsicmd->sc_data_direction);
 
 	/*
@@ -1230,8 +2665,10 @@ static void aac_srb_callback(void *conte
 	if (le32_to_cpu(srbreply->status) != ST_OK){
 		int len;
 		printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
-		len = (srbreply->sense_data_size > sizeof(scsicmd->sense_buffer))?
-				sizeof(scsicmd->sense_buffer):srbreply->sense_data_size;
+		len = (le32_to_cpu(srbreply->sense_data_size) > 
+				sizeof(scsicmd->sense_buffer)) ?
+				sizeof(scsicmd->sense_buffer) : 
+				le32_to_cpu(srbreply->sense_data_size);
 		scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
 		memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
 	}
@@ -1255,8 +2692,17 @@ static void aac_srb_callback(void *conte
 			if( b==TYPE_TAPE || b==TYPE_WORM || b==TYPE_ROM || b==TYPE_MOD|| b==TYPE_MEDIUM_CHANGER 
 					|| (b==TYPE_DISK && (b1&0x80)) ){
 				scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
+			/*
+			 * We will allow disk devices if in RAID/SCSI mode and
+			 * the channel is 2
+			 */
+			} else if ((dev->raid_scsi_mode) &&
+					(scsicmd->device->channel == 2)) {
+				scsicmd->result = DID_OK << 16 | 
+						COMMAND_COMPLETE << 8;
 			} else {
-				scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
+				scsicmd->result = DID_NO_CONNECT << 16 | 
+						COMMAND_COMPLETE << 8;
 			}
 		} else {
 			scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
@@ -1270,6 +2716,12 @@ static void aac_srb_callback(void *conte
 		case  WRITE_10:
 		case  READ_12:
 		case  WRITE_12:
+#if (defined(READ_16))
+		case  READ_16:
+#endif
+#if (defined(WRITE_16))
+		case  WRITE_16:
+#endif
 			if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) {
 				printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
 			} else {
@@ -1288,8 +2740,17 @@ static void aac_srb_callback(void *conte
 			if( b==TYPE_TAPE || b==TYPE_WORM || b==TYPE_ROM || b==TYPE_MOD|| b==TYPE_MEDIUM_CHANGER
 					|| (b==TYPE_DISK && (b1&0x80)) ){
 				scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
+			/*
+			 * We will allow disk devices if in RAID/SCSI mode and
+			 * the channel is 2
+			 */
+			} else if ((dev->raid_scsi_mode) &&
+					(scsicmd->device->channel == 2)) {
+				scsicmd->result = DID_OK << 16 | 
+						COMMAND_COMPLETE << 8;
 			} else {
-				scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
+				scsicmd->result = DID_NO_CONNECT << 16 | 
+						COMMAND_COMPLETE << 8;
 			}
 			break;
 		}
@@ -1348,7 +2809,12 @@ static void aac_srb_callback(void *conte
 	case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
 	default:
 #ifdef AAC_DETAILED_STATUS_INFO
-		printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",le32_to_cpu(srbreply->srb_status&0x3f),aac_get_status_string(le32_to_cpu(srbreply->srb_status)), scsicmd->cmnd[0], le32_to_cpu(srbreply->scsi_status) );
+		printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
+			le32_to_cpu(srbreply->srb_status) & 0x3F,
+			aac_get_status_string(
+				le32_to_cpu(srbreply->srb_status) & 0x3F), 
+			scsicmd->cmnd[0], 
+			le32_to_cpu(srbreply->scsi_status));
 #endif
 		scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
 		break;
@@ -1356,9 +2822,14 @@ static void aac_srb_callback(void *conte
 	if (le32_to_cpu(srbreply->scsi_status) == 0x02 ){  // Check Condition
 		int len;
 		scsicmd->result |= SAM_STAT_CHECK_CONDITION;
-		len = (srbreply->sense_data_size > sizeof(scsicmd->sense_buffer))?
-				sizeof(scsicmd->sense_buffer):srbreply->sense_data_size;
-		dprintk((KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n", le32_to_cpu(srbreply->status), len));
+		len = (le32_to_cpu(srbreply->sense_data_size) > 
+				sizeof(scsicmd->sense_buffer)) ?
+				sizeof(scsicmd->sense_buffer) :
+				le32_to_cpu(srbreply->sense_data_size);
+#ifdef AAC_DETAILED_STATUS_INFO
+		printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
+					le32_to_cpu(srbreply->status), len);
+#endif
 		memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
 		
 	}
@@ -1391,13 +2862,18 @@ static int aac_send_srb_fib(struct scsi_
 	u32 flag;
 	u32 timeout;
 
-	if( scsicmd->device->id > 15 || scsicmd->device->lun > 7) {
+	dev = (struct aac_dev *)scsicmd->device->host->hostdata;
+	if ((scsicmd->device->id >= dev->maximum_num_physicals)
+	 || (scsicmd->device->lun > 7)) {
 		scsicmd->result = DID_NO_CONNECT << 16;
+#if (defined(AAC_DEBUG_INSTRUMENT_TIMING))
 		__aac_io_done(scsicmd);
+#else
+		scsicmd->scsi_done(scsicmd);
+#endif
 		return 0;
 	}
 
-	dev = (struct aac_dev *)scsicmd->device->host->hostdata;
 	switch(scsicmd->sc_data_direction){
 	case DMA_TO_DEVICE:
 		flag = SRB_DataOut;
@@ -1434,10 +2910,10 @@ static int aac_send_srb_fib(struct scsi_
 		timeout = 1;
 	}
 	srbcmd->timeout  = cpu_to_le32(timeout);  // timeout in seconds
-	srbcmd->retry_limit =cpu_to_le32(0); // Obsolete parameter
+	srbcmd->retry_limit = 0; /* Obsolete parameter */
 	srbcmd->cdb_size = cpu_to_le32(scsicmd->cmd_len);
 	
-	if( dev->pae_support ==1 ) {
+	if( dev->dac_support == 1 ) {
 		aac_build_sg64(scsicmd, (struct sgmap64*) &srbcmd->sg);
 		srbcmd->count = cpu_to_le32(scsicmd->request_bufflen);
 
@@ -1446,13 +2922,19 @@ static int aac_send_srb_fib(struct scsi_
 		/*
 		 *	Build Scatter/Gather list
 		 */
-		fibsize = sizeof (struct aac_srb) + (((srbcmd->sg.count & 0xff) - 1) * sizeof (struct sgentry64));
+		fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
+			((le32_to_cpu(srbcmd->sg.count) & 0xff) * 
+			 sizeof (struct sgentry64));
+		BUG_ON (fibsize > (dev->max_fib_size -
+					sizeof(struct aac_fibhdr)));
 
 		/*
 		 *	Now send the Fib to the adapter
 		 */
-		status = fib_send(ScsiPortCommand64, cmd_fibcontext, fibsize, FsaNormal, 0, 1,
-				  (fib_callback) aac_srb_callback, (void *) scsicmd);
+		status = fib_send(ScsiPortCommand64, cmd_fibcontext, 
+				fibsize, FsaNormal, 0, 1,
+				  (fib_callback) aac_srb_callback, 
+				  (void *) scsicmd);
 	} else {
 		aac_build_sg(scsicmd, (struct sgmap*)&srbcmd->sg);
 		srbcmd->count = cpu_to_le32(scsicmd->request_bufflen);
@@ -1462,7 +2944,11 @@ static int aac_send_srb_fib(struct scsi_
 		/*
 		 *	Build Scatter/Gather list
 		 */
-		fibsize = sizeof (struct aac_srb) + (((srbcmd->sg.count & 0xff) - 1) * sizeof (struct sgentry));
+		fibsize = sizeof (struct aac_srb) + 
+			(((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) * 
+			 sizeof (struct sgentry));
+		BUG_ON (fibsize > (dev->max_fib_size -
+					sizeof(struct aac_fibhdr)));
 
 		/*
 		 *	Now send the Fib to the adapter
@@ -1478,43 +2964,198 @@ static int aac_send_srb_fib(struct scsi_
 	}
 
 	printk(KERN_WARNING "aac_srb: fib_send failed with status: %d\n", status);
+	scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
+	aac_io_done(scsicmd);
 	fib_complete(cmd_fibcontext);
 	fib_free(cmd_fibcontext);
 
-	return -1;
+	return 0;
 }
 
 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
 {
-	struct aac_dev *dev;
+	struct Scsi_Host *host = scsicmd->device->host;
+	struct aac_dev *dev = (struct aac_dev *)host->hostdata;
 	unsigned long byte_count = 0;
 
-	dev = (struct aac_dev *)scsicmd->device->host->hostdata;
 	// Get rid of old data
-	psg->count = cpu_to_le32(0);
-	psg->sg[0].addr = cpu_to_le32(0);
-	psg->sg[0].count = cpu_to_le32(0);  
+	psg->count = 0;
+	psg->sg[0].addr = 0;
+	psg->sg[0].count = 0;  
 	if (scsicmd->use_sg) {
 		struct scatterlist *sg;
 		int i;
-		int sg_count;
+		int sg_count, sg_count_hold;
 		sg = (struct scatterlist *) scsicmd->request_buffer;
 
-		sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
-			scsicmd->sc_data_direction);
+		sg_count_hold = sg_count = pci_map_sg(dev->pdev, sg,
+			scsicmd->use_sg, scsicmd->sc_data_direction);
+
+		for (i = 0; i < sg_count; i++) {
+			int count = sg_dma_len(sg);
+			u32 addr = sg_dma_address(sg);
+			if (host->max_sectors < AAC_MAX_32BIT_SGBCOUNT)
+			while (count > 65536) {
+				psg->sg[i].addr = cpu_to_le32(addr);
+				psg->sg[i].count = cpu_to_le32(65536);
+				++i;
+				if (++sg_count > host->sg_tablesize) {
+#if (defined(AAC_DEBUG_INSTRUMENT_SG))
+					printk(KERN_INFO
+					  "SG List[%d] too large based on original[%d]:\n",
+					  sg_count, sg_count_hold);
+					sg = (struct scatterlist *) scsicmd->request_buffer;
+					for (i = 0; i < sg_count_hold; i++) {
+						printk(KERN_INFO "0x%llx[%d] ",
+						  (u64)(sg_dma_address(sg)),
+						  (int)(sg_dma_len(sg)));
+						++sg;
+					}
+					printk(KERN_INFO "...\n");
+#endif
+					BUG();
+				}
+				byte_count += 65536;
+				addr += 65536;
+				count -= 65536;
+			}
+
+			psg->sg[i].addr = cpu_to_le32(addr);
+			psg->sg[i].count = cpu_to_le32(count);
+			byte_count += count;
+			sg++;
+		}
 		psg->count = cpu_to_le32(sg_count);
+		/* hba wants the size to be exact */
+		if(byte_count > scsicmd->request_bufflen){
+			u32 temp = le32_to_cpu(psg->sg[i-1].count) -
+				(byte_count - scsicmd->request_bufflen);
+			psg->sg[i-1].count = cpu_to_le32(temp);
+			byte_count = scsicmd->request_bufflen;
+		}
+		/* Check for command underflow */
+		if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
+			printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
+					byte_count, scsicmd->underflow);
+		}
+	}
+	else if(scsicmd->request_bufflen) {
+		int i, count;
+		u32 addr;
+		scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
+				scsicmd->request_buffer,
+				scsicmd->request_bufflen,
+				scsicmd->sc_data_direction);
+		addr = scsicmd->SCp.dma_handle;
+		count = scsicmd->request_bufflen;  
+		i = 0;
+		if (host->max_sectors < AAC_MAX_32BIT_SGBCOUNT)
+		while (count > 65536) {
+			psg->sg[i].addr = cpu_to_le32(addr);
+			psg->sg[i].count = cpu_to_le32(65536);
+			if (++i >= host->sg_tablesize) {
+#if (defined(AAC_DEBUG_INSTRUMENT_SG))
+				printk(KERN_INFO
+				  "SG List[%d] too large based on original single element %d in size\n",
+				  i, scsicmd->request_bufflen);
+#endif
+				BUG();
+			}
+			addr += 65536;
+			count -= 65536;
+		}
+		psg->count = cpu_to_le32(1+i);
+		psg->sg[i].addr = cpu_to_le32(addr);
+		psg->sg[i].count = cpu_to_le32(count);
+		byte_count = scsicmd->request_bufflen;
+	}
+#if (defined(AAC_DEBUG_INSTRUMENT_SG))
+{
+	int i, sg_count = le32_to_cpu(psg->count);
+	printk("aac_build_sg:");
+	for (i = 0; i < sg_count; i++) {
+		int count = le32_to_cpu(psg->sg[i].count);
+		u32 addr = le32_to_cpu(psg->sg[i].addr);
+		printk(" %x[%d]", addr, count);
+	}
+	printk ("\n");
+}
+#endif
+#if (defined(AAC_DEBUG_INSTRUMENT_AAC_CONFIG))
+	if (le32_to_cpu(psg->count) > aac_config.peak_sg) {
+		aac_config.peak_sg = le32_to_cpu(psg->count);
+		printk ("peak_sg=%u\n", aac_config.peak_sg);
+	}
+	if (byte_count > aac_config.peak_size) {
+		aac_config.peak_size = byte_count;
+		printk ("peak_size=%u\n", aac_config.peak_size);
+	}
+#endif
+	return byte_count;
+}
+
+
+static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
+{
+	struct Scsi_Host *host = scsicmd->device->host;
+	struct aac_dev *dev = (struct aac_dev *)host->hostdata;
+	unsigned long byte_count = 0;
+
+	// Get rid of old data
+	psg->count = 0;
+	psg->sg[0].addr[0] = 0;
+	psg->sg[0].addr[1] = 0;
+	psg->sg[0].count = 0;
+	if (scsicmd->use_sg) {
+		struct scatterlist *sg;
+		int i;
+		int sg_count, sg_count_hold;
+		sg = (struct scatterlist *) scsicmd->request_buffer;
 
-		byte_count = 0;
+		sg_count_hold = sg_count = pci_map_sg(dev->pdev, sg,
+			scsicmd->use_sg, scsicmd->sc_data_direction);
 
 		for (i = 0; i < sg_count; i++) {
-			psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
-			psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
-			byte_count += sg_dma_len(sg);
+			int count = sg_dma_len(sg);
+			u64 addr = sg_dma_address(sg);
+			if (host->max_sectors < AAC_MAX_32BIT_SGBCOUNT)
+			while (count > 65536) {
+				psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
+				psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
+				psg->sg[i].count = cpu_to_le32(65536);
+				++i;
+				if (++sg_count > host->sg_tablesize) {
+#if (defined(AAC_DEBUG_INSTRUMENT_SG))
+					printk(KERN_INFO
+					  "SG List[%d] too large based on original[%d]:\n",
+					  sg_count, sg_count_hold);
+					sg = (struct scatterlist *) scsicmd->request_buffer;
+					for (i = 0; i < sg_count_hold; i++) {
+						printk(KERN_INFO "0x%llx[%d] ",
+						  (u64)sg_dma_address(sg),
+						  (int)sg_dma_len(sg));
+						++sg;
+					}
+					printk(KERN_INFO "...\n");
+#endif
+					BUG();
+				}
+				byte_count += 65536;
+				addr += 65536;
+				count -= 65536;
+			}
+			psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
+			psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
+			psg->sg[i].count = cpu_to_le32(count);
+			byte_count += count;
 			sg++;
 		}
+		psg->count = cpu_to_le32(sg_count);
 		/* hba wants the size to be exact */
 		if(byte_count > scsicmd->request_bufflen){
-			psg->sg[i-1].count -= (byte_count - scsicmd->request_bufflen);
+			u32 temp = le32_to_cpu(psg->sg[i-1].count) -
+				 (byte_count - scsicmd->request_bufflen);
+			psg->sg[i-1].count = cpu_to_le32(temp);
 			byte_count = scsicmd->request_bufflen;
 		}
 		/* Check for command underflow */
@@ -1524,33 +3165,81 @@ static unsigned long aac_build_sg(struct
 		}
 	}
 	else if(scsicmd->request_bufflen) {
-		dma_addr_t addr; 
-		addr = pci_map_single(dev->pdev,
+		int i, count;
+		u64 addr;
+		scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
 				scsicmd->request_buffer,
 				scsicmd->request_bufflen,
 				scsicmd->sc_data_direction);
-		psg->count = cpu_to_le32(1);
-		psg->sg[0].addr = cpu_to_le32(addr);
-		psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);  
-		scsicmd->SCp.ptr = (char *)(ulong)addr;
+		addr = scsicmd->SCp.dma_handle;
+		count = scsicmd->request_bufflen;  
+		i = 0;
+		if (host->max_sectors < AAC_MAX_32BIT_SGBCOUNT)
+		while (count > 65536) {
+			psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
+			psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
+			psg->sg[i].count = cpu_to_le32(65536);
+			if (++i >= host->sg_tablesize) {
+#if (defined(AAC_DEBUG_INSTRUMENT_SG))
+				printk(KERN_INFO
+				  "SG List[%d] too large based on original single element %d in size\n",
+				  i, scsicmd->request_bufflen);
+#endif
+				BUG();
+			}
+			addr += 65536;
+			count -= 65536;
+		}
+		psg->count = cpu_to_le32(1+i);
+		psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
+		psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
+		psg->sg[i].count = cpu_to_le32(count);
 		byte_count = scsicmd->request_bufflen;
 	}
+#if (defined(AAC_DEBUG_INSTRUMENT_SG))
+{
+	int i, sg_count = le32_to_cpu(psg->count);
+	printk("aac_build_sg64:");
+	for (i = 0; i < sg_count; i++) {
+		int count = le32_to_cpu(psg->sg[i].count);
+		u32 addr0 = le32_to_cpu(psg->sg[i].addr[0]);
+		u32 addr1 = le32_to_cpu(psg->sg[i].addr[1]);
+		if (addr1 == 0)
+			printk(" %x[%d]", addr0, count);
+		else
+			printk(" %x%08x[%d]", addr1, addr0, count);
+	}
+	printk ("\n");
+}
+#endif
+#if (defined(AAC_DEBUG_INSTRUMENT_AAC_CONFIG))
+	if (le32_to_cpu(psg->count) > aac_config.peak_sg) {
+		aac_config.peak_sg = le32_to_cpu(psg->count);
+		printk ("peak_sg=%u\n", aac_config.peak_sg);
+	}
+	if (byte_count > aac_config.peak_size) {
+		aac_config.peak_size = byte_count;
+		printk ("peak_size=%u\n", aac_config.peak_size);
+	}
+#endif
 	return byte_count;
 }
 
 
-static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
+static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
 {
-	struct aac_dev *dev;
+	struct Scsi_Host *host = scsicmd->device->host;
+	struct aac_dev *dev = (struct aac_dev *)host->hostdata;
 	unsigned long byte_count = 0;
-	u64 le_addr;
 
-	dev = (struct aac_dev *)scsicmd->device->host->hostdata;
 	// Get rid of old data
-	psg->count = cpu_to_le32(0);
-	psg->sg[0].addr[0] = cpu_to_le32(0);
-	psg->sg[0].addr[1] = cpu_to_le32(0);
-	psg->sg[0].count = cpu_to_le32(0);  
+	psg->count = 0;
+	psg->sg[0].next = 0;
+	psg->sg[0].prev = 0;
+	psg->sg[0].addr[0] = 0;
+	psg->sg[0].addr[1] = 0;
+	psg->sg[0].count = 0;
+	psg->sg[0].flags = 0;
 	if (scsicmd->use_sg) {
 		struct scatterlist *sg;
 		int i;
@@ -1559,18 +3248,20 @@ static unsigned long aac_build_sg64(stru
 
 		sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
 			scsicmd->sc_data_direction);
-		psg->count = cpu_to_le32(sg_count);
-
-		byte_count = 0;
 
 		for (i = 0; i < sg_count; i++) {
-			le_addr = cpu_to_le64(sg_dma_address(sg));
-			psg->sg[i].addr[1] = (u32)(le_addr>>32);
-			psg->sg[i].addr[0] = (u32)(le_addr & 0xffffffff);
-			psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
-			byte_count += sg_dma_len(sg);
+			int count = sg_dma_len(sg);
+			u64 addr = sg_dma_address(sg);
+			psg->sg[i].next = 0;
+			psg->sg[i].prev = 0;
+			psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
+			psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
+			psg->sg[i].count = cpu_to_le32(count);
+			psg->sg[i].flags = 0;
+			byte_count += count;
 			sg++;
 		}
+		psg->count = cpu_to_le32(sg_count);
 		/* hba wants the size to be exact */
 		if(byte_count > scsicmd->request_bufflen){
 			psg->sg[i-1].count -= (byte_count - scsicmd->request_bufflen);
@@ -1583,19 +3274,33 @@ static unsigned long aac_build_sg64(stru
 		}
 	}
 	else if(scsicmd->request_bufflen) {
-		dma_addr_t addr; 
-		addr = pci_map_single(dev->pdev,
+		int count;
+		u64 addr;
+		scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
 				scsicmd->request_buffer,
 				scsicmd->request_bufflen,
 				scsicmd->sc_data_direction);
+		addr = scsicmd->SCp.dma_handle;
+		count = scsicmd->request_bufflen;
 		psg->count = cpu_to_le32(1);
-		le_addr = cpu_to_le64(addr);
-		psg->sg[0].addr[1] = (u32)(le_addr>>32);
-		psg->sg[0].addr[0] = (u32)(le_addr & 0xffffffff);
-		psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);  
-		scsicmd->SCp.ptr = (char *)(ulong)addr;
+		psg->sg[0].next = 0;
+		psg->sg[0].prev = 0;
+		psg->sg[0].addr[1] = cpu_to_le32((u32)(addr>>32));
+		psg->sg[0].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
+		psg->sg[0].count = cpu_to_le32(count);
+		psg->sg[0].flags = 0;
 		byte_count = scsicmd->request_bufflen;
 	}
+#if (defined(AAC_DEBUG_INSTRUMENT_AAC_CONFIG))
+	if (le32_to_cpu(psg->count) > aac_config.peak_sg) {
+		aac_config.peak_sg = le32_to_cpu(psg->count);
+		printk ("peak_sg=%u\n", aac_config.peak_sg);
+	}
+	if (byte_count > aac_config.peak_size) {
+		aac_config.peak_size = byte_count;
+		printk ("peak_size=%u\n", aac_config.peak_size);
+	}
+#endif
 	return byte_count;
 }
 
--- linux-2.6.8.1-t043-libata-update/drivers/scsi/aacraid/sa.c	2005-09-26 13:33:12.000000000 +0400
+++ aacraid-drv/drivers/scsi/aacraid/sa.c	2005-04-27 16:49:12.000000000 +0400
@@ -40,9 +40,22 @@
 #include <linux/completion.h>
 #include <linux/time.h>
 #include <linux/interrupt.h>
+#include <linux/version.h>	/* Needed for the following */
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,23))
+#if (!defined(IRQ_NONE))
+  typedef void irqreturn_t;
+# define IRQ_HANDLED
+# define IRQ_NONE
+#endif
+#endif
 #include <asm/semaphore.h>
 
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
+#include "scsi.h"
+#include "hosts.h"
+#else
 #include <scsi/scsi_host.h>
+#endif
 
 #include "aacraid.h"
 
@@ -62,15 +75,15 @@ static irqreturn_t aac_sa_intr(int irq, 
 
 	if (intstat & mask) {
 		if (intstat & PrintfReady) {
-			aac_printf(dev, le32_to_cpu(sa_readl(dev, Mailbox5)));
+			aac_printf(dev, sa_readl(dev, Mailbox5));
 			sa_writew(dev, DoorbellClrReg_p, PrintfReady); /* clear PrintfReady */
 			sa_writew(dev, DoorbellReg_s, PrintfDone);
 		} else if (intstat & DOORBELL_1) {	// dev -> Host Normal Command Ready
-			aac_command_normal(&dev->queues->queue[HostNormCmdQueue]);
 			sa_writew(dev, DoorbellClrReg_p, DOORBELL_1);
+			aac_command_normal(&dev->queues->queue[HostNormCmdQueue]);
 		} else if (intstat & DOORBELL_2) {	// dev -> Host Normal Response Ready
-			aac_response_normal(&dev->queues->queue[HostNormRespQueue]);
 			sa_writew(dev, DoorbellClrReg_p, DOORBELL_2);
+			aac_response_normal(&dev->queues->queue[HostNormRespQueue]);
 		} else if (intstat & DOORBELL_3) {	// dev -> Host Normal Command Not Full
 			sa_writew(dev, DoorbellClrReg_p, DOORBELL_3);
 		} else if (intstat & DOORBELL_4) {	// dev -> Host Normal Response Not Full
@@ -82,65 +95,13 @@ static irqreturn_t aac_sa_intr(int irq, 
 }
 
 /**
- *	aac_sa_enable_interrupt	-	enable an interrupt event
- *	@dev: Which adapter to enable.
- *	@event: Which adapter event.
- *
- *	This routine will enable the corresponding adapter event to cause an interrupt on 
- * 	the host.
- */
- 
-void aac_sa_enable_interrupt(struct aac_dev *dev, u32 event)
-{
-	switch (event) {
-
-	case HostNormCmdQue:
-		sa_writew(dev, SaDbCSR.PRICLEARIRQMASK, DOORBELL_1);
-		break;
-
-	case HostNormRespQue:
-		sa_writew(dev, SaDbCSR.PRICLEARIRQMASK, DOORBELL_2);
-		break;
-
-	case AdapNormCmdNotFull:
-		sa_writew(dev, SaDbCSR.PRICLEARIRQMASK, DOORBELL_3);
-		break;
-
-	case AdapNormRespNotFull:
-		sa_writew(dev, SaDbCSR.PRICLEARIRQMASK, DOORBELL_4);
-		break;
-	}
-}
-
-/**
- *	aac_sa_disable_interrupt	-	disable an interrupt event
+ *	aac_sa_disable_interrupt	-	disable interrupt
  *	@dev: Which adapter to enable.
- *	@event: Which adapter event.
- *
- *	This routine will enable the corresponding adapter event to cause an interrupt on 
- * 	the host.
  */
 
-void aac_sa_disable_interrupt (struct aac_dev *dev, u32 event)
+void aac_sa_disable_interrupt (struct aac_dev *dev)
 {
-	switch (event) {
-
-	case HostNormCmdQue:
-		sa_writew(dev, SaDbCSR.PRISETIRQMASK, DOORBELL_1);
-		break;
-
-	case HostNormRespQue:
-		sa_writew(dev, SaDbCSR.PRISETIRQMASK, DOORBELL_2);
-		break;
-
-	case AdapNormCmdNotFull:
-		sa_writew(dev, SaDbCSR.PRISETIRQMASK, DOORBELL_3);
-		break;
-
-	case AdapNormRespNotFull:
-		sa_writew(dev, SaDbCSR.PRISETIRQMASK, DOORBELL_4);
-		break;
-	}
+	sa_writew(dev, SaDbCSR.PRISETIRQMASK, cpu_to_le16(0xffff));
 }
 
 /**
@@ -151,7 +112,7 @@ void aac_sa_disable_interrupt (struct aa
  *	Notify the adapter of an event
  */
  
-void aac_sa_notify_adapter(struct aac_dev *dev, u32 event)
+static void aac_sa_notify_adapter(struct aac_dev *dev, u32 event)
 {
 	switch (event) {
 
@@ -168,7 +129,8 @@ void aac_sa_notify_adapter(struct aac_de
 		sa_writew(dev, DoorbellReg_s,DOORBELL_3);
 		break;
 	case HostShutdown:
-		//sa_sync_cmd(dev, HOST_CRASHING, 0, &ret);
+		//sa_sync_cmd(dev, HOST_CRASHING, 0, 0, 0, 0, 0, 0,
+		//  NULL, NULL, NULL, NULL, NULL);
 		break;
 	case FastIo:
 		sa_writew(dev, DoorbellReg_s,DOORBELL_6);
@@ -190,25 +152,31 @@ void aac_sa_notify_adapter(struct aac_de
  *	@p1: first parameter
  *	@ret: adapter status
  *
- *	This routine will send a synchronous comamnd to the adapter and wait 
+ *	This routine will send a synchronous command to the adapter and wait 
  *	for its	completion.
  */
 
-static int sa_sync_cmd(struct aac_dev *dev, u32 command, u32 p1, u32 *ret)
+static int sa_sync_cmd(struct aac_dev *dev, u32 command,
+	u32 p1, u32 p2, u32 p3, u32 p4, u32 p5, u32 p6,
+	u32 *ret, u32 * r1, u32 * r2, u32 * r3, u32 * r4)
 {
 	unsigned long start;
  	int ok;
 	/*
 	 *	Write the Command into Mailbox 0
 	 */
-	sa_writel(dev, Mailbox0, cpu_to_le32(command));
+	sa_writel(dev, Mailbox0, command);
 	/*
 	 *	Write the parameters into Mailboxes 1 - 4
 	 */
-	sa_writel(dev, Mailbox1, cpu_to_le32(p1));
-	sa_writel(dev, Mailbox2, 0);
-	sa_writel(dev, Mailbox3, 0);
-	sa_writel(dev, Mailbox4, 0);
+	sa_writel(dev, Mailbox1, p1);
+	sa_writel(dev, Mailbox2, p2);
+	sa_writel(dev, Mailbox3, p3);
+	sa_writel(dev, Mailbox4, p4);
+#if (defined(AAC_LM_SENSOR))
+	sa_writel(dev, Mailbox5, p5);
+	sa_writel(dev, Mailbox6, p6);
+#endif
 	/*
 	 *	Clear the synch command doorbell to start on a clean slate.
 	 */
@@ -248,7 +216,16 @@ static int sa_sync_cmd(struct aac_dev *d
 	/*
 	 *	Pull the synch status from Mailbox 0.
 	 */
-	*ret = le32_to_cpu(sa_readl(dev, Mailbox0));
+	if (ret)
+		*ret = sa_readl(dev, Mailbox0);
+	if (r1)
+		*r1 = sa_readl(dev, Mailbox1);
+	if (r2)
+		*r2 = sa_readl(dev, Mailbox2);
+	if (r3)
+		*r3 = sa_readl(dev, Mailbox3);
+	if (r4)
+		*r4 = sa_readl(dev, Mailbox4);
 	return 0;
 }
 
@@ -261,8 +238,8 @@ static int sa_sync_cmd(struct aac_dev *d
  
 static void aac_sa_interrupt_adapter (struct aac_dev *dev)
 {
-	u32 ret;
-	sa_sync_cmd(dev, BREAKPOINT_REQUEST, 0, &ret);
+	sa_sync_cmd(dev, BREAKPOINT_REQUEST, 0, 0, 0, 0, 0, 0,
+	  NULL, NULL, NULL, NULL, NULL);
 }
 
 /**
@@ -274,30 +251,15 @@ static void aac_sa_interrupt_adapter (st
 
 static void aac_sa_start_adapter(struct aac_dev *dev)
 {
-	u32 ret;
 	struct aac_init *init;
 	/*
 	 * Fill in the remaining pieces of the init.
 	 */
 	init = dev->init;
-	init->HostElapsedSeconds = cpu_to_le32(jiffies/HZ);
-
-	dprintk(("INIT\n"));
-	/*
-	 * Tell the adapter we are back and up and running so it will scan its command
-	 * queues and enable our interrupts
-	 */
-	dev->irq_mask =	(PrintfReady | DOORBELL_1 | DOORBELL_2 | DOORBELL_3 | DOORBELL_4);
-	/*
-	 *	First clear out all interrupts.  Then enable the one's that 
-	 *	we can handle.
-	 */
-	dprintk(("MASK\n"));
-	sa_writew(dev, SaDbCSR.PRISETIRQMASK, cpu_to_le16(0xffff));
-	sa_writew(dev, SaDbCSR.PRICLEARIRQMASK, (PrintfReady | DOORBELL_1 | DOORBELL_2 | DOORBELL_3 | DOORBELL_4));
-	dprintk(("SYNCCMD\n"));
+	init->HostElapsedSeconds = cpu_to_le32(get_seconds());
 	/* We can only use a 32 bit address here */
-	sa_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS, (u32)(ulong)dev->init_pa, &ret);
+	sa_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS, (u32)(ulong)dev->init_pa,
+	  0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL);
 }
 
 /**
@@ -348,21 +310,10 @@ int aac_sa_init(struct aac_dev *dev)
 	int instance;
 	const char *name;
 
-	dprintk(("PREINST\n"));
 	instance = dev->id;
 	name     = dev->name;
 
 	/*
-	 *	Map in the registers from the adapter.
-	 */
-	dprintk(("PREMAP\n"));
-
-	if((dev->regs.sa = (struct sa_registers *)ioremap((unsigned long)dev->scsi_host_ptr->base, 8192))==NULL)
-	{	
-		printk(KERN_WARNING "aacraid: unable to map ARM.\n" );
-		goto error_iounmap;
-	}
-	/*
 	 *	Check to see if the board failed any self tests.
 	 */
 	if (sa_readl(dev, Mailbox7) & SELF_TEST_FAILED) {
@@ -382,15 +333,15 @@ int aac_sa_init(struct aac_dev *dev)
 	 */
 	while (!(sa_readl(dev, Mailbox7) & KERNEL_UP_AND_RUNNING)) {
 		if (time_after(jiffies, start+180*HZ)) {
-			status = sa_readl(dev, Mailbox7) >> 16;
-			printk(KERN_WARNING "%s%d: adapter kernel failed to start, init status = %d.\n", name, instance, le32_to_cpu(status));
+			status = sa_readl(dev, Mailbox7);
+			printk(KERN_WARNING "%s%d: adapter kernel failed to start, init status = %lx.\n", 
+					name, instance, status);
 			goto error_iounmap;
 		}
 		set_current_state(TASK_UNINTERRUPTIBLE);
 		schedule_timeout(1);
 	}
 
-	dprintk(("ATIRQ\n"));
 	if (request_irq(dev->scsi_host_ptr->irq, aac_sa_intr, SA_SHIRQ|SA_INTERRUPT, "aacraid", (void *)dev ) < 0) {
 		printk(KERN_WARNING "%s%d: Interrupt unavailable.\n", name, instance);
 		goto error_iounmap;
@@ -401,18 +352,24 @@ int aac_sa_init(struct aac_dev *dev)
 	 */
 
 	dev->a_ops.adapter_interrupt = aac_sa_interrupt_adapter;
-	dev->a_ops.adapter_enable_int = aac_sa_enable_interrupt;
 	dev->a_ops.adapter_disable_int = aac_sa_disable_interrupt;
 	dev->a_ops.adapter_notify = aac_sa_notify_adapter;
 	dev->a_ops.adapter_sync_cmd = sa_sync_cmd;
 	dev->a_ops.adapter_check_health = aac_sa_check_health;
+#if (defined(SCSI_HAS_DUMP))
+	dev->a_ops.adapter_intr = aac_sa_intr;
+#endif
 
-	dprintk(("FUNCDONE\n"));
+	/*
+	 *	First clear out all interrupts.  Then enable the one's that 
+	 *	we can handle.
+	 */
+	sa_writew(dev, SaDbCSR.PRISETIRQMASK, cpu_to_le16(0xffff));
+	sa_writew(dev, SaDbCSR.PRICLEARIRQMASK, (PrintfReady | DOORBELL_1 | DOORBELL_2 | DOORBELL_3 | DOORBELL_4));
 
 	if(aac_init_adapter(dev) == NULL)
 		goto error_irq;
 
-	dprintk(("NEWADAPTDONE\n"));
 	/*
 	 *	Start any kernel threads needed
 	 */
@@ -426,9 +383,7 @@ int aac_sa_init(struct aac_dev *dev)
 	 *	Tell the adapter that all is configure, and it can start 
 	 *	accepting requests
 	 */
-	dprintk(("STARTING\n"));
 	aac_sa_start_adapter(dev);
-	dprintk(("STARTED\n"));
 	return 0;
 
 
@@ -436,10 +391,10 @@ error_kfree:
 	kfree(dev->queues);
 
 error_irq:
+	sa_writew(dev, SaDbCSR.PRISETIRQMASK, cpu_to_le16(0xffff));
 	free_irq(dev->scsi_host_ptr->irq, (void *)dev);
 
 error_iounmap:
-	iounmap(dev->regs.sa);
 
 	return -1;
 }
--- linux-2.6.8.1-t043-libata-update/drivers/scsi/aacraid/fwdebug.h	1970-01-01 03:00:00.000000000 +0300
+++ aacraid-drv/drivers/scsi/aacraid/fwdebug.h	2004-09-30 21:31:02.000000000 +0400
@@ -0,0 +1,51 @@
+/*
+ *	Adaptec AAC series RAID controller driver
+ *
+ * Copyright (c) 2004 Adaptec, Inc. (aacraid@adaptec.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#ifndef PRINT_BUFFER_SIZE
+
+#define PRINT_BUFFER_SIZE     512       /* Debugging print buffer size */
+
+#define HBA_FLAGS_DBG_FLAGS_MASK         0x0000ffff  /* Mask for debug flags */
+#define HBA_FLAGS_DBG_KERNEL_PRINT_B     0x00000001  /* Kernel Debugger Print */
+#define HBA_FLAGS_DBG_FW_PRINT_B         0x00000002  /* Firmware Debugger Print */
+#define HBA_FLAGS_DBG_FUNCTION_ENTRY_B   0x00000004  /* Function Entry Point */
+#define HBA_FLAGS_DBG_FUNCTION_EXIT_B    0x00000008  /* Function Exit */
+#define HBA_FLAGS_DBG_ERROR_B            0x00000010  /* Error Conditions */
+#define HBA_FLAGS_DBG_INIT_B             0x00000020  /* Init Prints */
+#define HBA_FLAGS_DBG_OS_COMMANDS_B      0x00000040  /* OS Command Info */
+#define HBA_FLAGS_DBG_SCAN_B             0x00000080  /* Device Scan */
+#define HBA_FLAGS_DBG_COALESCE_B         0x00000100  /* Coalescing Queueing flags */
+#define HBA_FLAGS_DBG_IOCTL_COMMANDS_B   0x00000200  /* IOCTL Command Info */
+#define HBA_FLAGS_DBG_SYNC_COMMANDS_B    0x00000400  /* SYNC Command Info */
+#define HBA_FLAGS_DBG_COMM_B             0x00000800  /* Comm Info */
+#define HBA_FLAGS_DBG_CSMI_COMMANDS_B    0x00001000  /* CSMI Command Info */
+#define HBA_FLAGS_DBG_AIF_B              0x00001000  /* Aif Info */
+
+#define FW_DEBUG_STR_LENGTH_OFFSET       0x00
+#define FW_DEBUG_FLAGS_OFFSET            0x04
+#define FW_DEBUG_BLED_OFFSET             0x08
+#define FW_DEBUG_FLAGS_NO_HEADERS_B      0x01 
+
+int aac_get_fw_debug_buffer(struct aac_dev *);
+void aac_fw_printf(struct aac_dev *, unsigned long, const char *, ...);
+void aac_fw_print_mem(struct aac_dev *, unsigned long, u8 *, int);
+
+#endif
--- linux-2.6.8.1-t043-libata-update/drivers/scsi/aacraid/comminit.c	2005-09-26 13:33:12.000000000 +0400
+++ aacraid-drv/drivers/scsi/aacraid/comminit.c	2005-04-27 16:42:06.000000000 +0400
@@ -41,22 +41,43 @@
 #include <linux/mm.h>
 #include <asm/semaphore.h>
 
+#include <linux/version.h>	/* Needed for the following */
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+#include <scsi/scsi.h>
+#include <scsi/scsi_host.h>
+#else
+#include "scsi.h"
+#include "hosts.h"
+#endif
+
 #include "aacraid.h"
 
-struct aac_common aac_config;
+struct aac_common aac_config = {
+	.irq_mod = 1
+};
 
 static int aac_alloc_comm(struct aac_dev *dev, void **commaddr, unsigned long commsize, unsigned long commalign)
 {
 	unsigned char *base;
 	unsigned long size, align;
-	unsigned long fibsize = 4096;
-	unsigned long printfbufsiz = 256;
+	const unsigned long fibsize = 4096;
+	const unsigned long printfbufsiz = 256;
 	struct aac_init *init;
 	dma_addr_t phys;
 
 	size = fibsize + sizeof(struct aac_init) + commsize + commalign + printfbufsiz;
 
- 
+#if 0 && (defined(CONFIG_X86) || defined(CONFIG_X86_64))
+	base = kmalloc(size, GFP_ATOMIC|GFP_KERNEL);
+	if (base) {
+		phys = pci_map_single(dev->pdev, base, size, DMA_BIDIRECTIONAL);
+		if (phys > (0x80000000UL - size)) {
+			kfree(base);
+			base = NULL;
+		}
+	}
+	if (base == NULL)
+#endif
 	base = pci_alloc_consistent(dev->pdev, size, &phys);
 
 	if(base == NULL)
@@ -74,6 +95,8 @@ static int aac_alloc_comm(struct aac_dev
 	init = dev->init;
 
 	init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION);
+	if (dev->max_fib_size != sizeof(struct hw_fib))
+		init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_4);
 	init->MiniPortRevision = cpu_to_le32(Sa_MINIPORT_REVISION);
 	init->fsrev = cpu_to_le32(dev->fsrev);
 
@@ -83,7 +106,7 @@ static int aac_alloc_comm(struct aac_dev
 	 */
 	dev->aif_base_va = (struct hw_fib *)base;
 	
-	init->AdapterFibsVirtualAddress = cpu_to_le32(0);
+	init->AdapterFibsVirtualAddress = 0;
 	init->AdapterFibsPhysicalAddress = cpu_to_le32((u32)phys);
 	init->AdapterFibsSize = cpu_to_le32(fibsize);
 	init->AdapterFibAlign = cpu_to_le32(sizeof(struct hw_fib));
@@ -110,6 +133,14 @@ static int aac_alloc_comm(struct aac_dev
 		init->HostPhysMemPages = cpu_to_le32(AAC_MAX_HOSTPHYSMEMPAGES);
 	}
 
+	init->InitFlags = 0;
+	if (dev->new_comm_interface) {
+		init->InitFlags = cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED);
+		dprintk((KERN_WARNING"aacraid: New Comm Interface enabled\n"));
+	}
+	init->MaxIoCommands = cpu_to_le32(dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB);
+	init->MaxIoSize = cpu_to_le32(dev->scsi_host_ptr->max_sectors << 9);
+	init->MaxFibSize = cpu_to_le32(dev->max_fib_size);
 
 	/*
 	 * Increment the base address by the amount already used
@@ -152,8 +183,8 @@ static void aac_queue_init(struct aac_de
 	init_waitqueue_head(&q->qfull);
 	spin_lock_init(&q->lockdata);
 	q->lock = &q->lockdata;
-	q->headers.producer = mem;
-	q->headers.consumer = mem+1;
+	q->headers.producer = (__le32 *)mem;
+	q->headers.consumer = (__le32 *)(mem+1);
 	*(q->headers.producer) = cpu_to_le32(qsize);
 	*(q->headers.consumer) = cpu_to_le32(qsize);
 	q->entries = qsize;
@@ -173,6 +204,8 @@ int aac_send_shutdown(struct aac_dev * d
 	int status;
 
 	fibctx = fib_alloc(dev);
+	if (!fibctx)
+		return -ENOMEM;
 	fib_init(fibctx);
 
 	cmd = (struct aac_close *) fib_data(fibctx);
@@ -184,7 +217,7 @@ int aac_send_shutdown(struct aac_dev * d
 			  fibctx,
 			  sizeof(struct aac_close),
 			  FsaNormal,
-			  1, 1,
+			  -2 /* Timeout silently */, 1,
 			  NULL, NULL);
 
 	if (status == 0)
@@ -204,7 +237,7 @@ int aac_send_shutdown(struct aac_dev * d
  *		0 - If there were errors initing. This is a fatal error.
  */
  
-int aac_comm_init(struct aac_dev * dev)
+static int aac_comm_init(struct aac_dev * dev)
 {
 	unsigned long hdrsize = (sizeof(u32) * NUMBER_OF_COMM_QUEUES) * 2;
 	unsigned long queuesize = sizeof(struct aac_entry) * TOTAL_QUEUE_ENTRIES;
@@ -293,6 +326,113 @@ int aac_comm_init(struct aac_dev * dev)
 
 struct aac_dev *aac_init_adapter(struct aac_dev *dev)
 {
+	u32 status[5];
+	struct Scsi_Host * host = dev->scsi_host_ptr;
+
+	/*
+	 *	Check the preferred comm settings, defaults from template.
+	 */
+	dev->max_fib_size = sizeof(struct hw_fib);
+	dev->sg_tablesize = host->sg_tablesize = (dev->max_fib_size
+		- sizeof(struct aac_fibhdr)
+		- sizeof(struct aac_write) + sizeof(struct sgmap))
+			/ sizeof(struct sgmap);
+	dev->new_comm_interface = 0;
+	dev->raw_io_64 = 0;
+	if ((!aac_adapter_sync_cmd(dev, GET_ADAPTER_PROPERTIES,
+	  0, 0, 0, 0, 0, 0,
+	  status+0, status+1, status+2, NULL, NULL))
+	 && (status[0] == 0x00000001)) {
+		if (status[1] & AAC_OPT_NEW_COMM_64)
+			dev->raw_io_64 = 1;
+		if (status[1] & AAC_OPT_NEW_COMM)
+			dev->new_comm_interface = dev->a_ops.adapter_send != 0;
+		if (dev->new_comm_interface
+		 && (status[2] > AAC_MIN_FOOTPRINT_SIZE)) {
+			iounmap((void * )dev->regs.sa);
+			dev->base_size = status[2];
+			dprintk((KERN_DEBUG "ioremap(%lx,%d)\n",
+			  dev->scsi_host_ptr->base, status[2]));
+			if ((dev->regs.sa = (struct sa_registers *)ioremap(
+			  (unsigned long)dev->scsi_host_ptr->base, status[2]))
+			  == NULL) {
+				/* remap failed, go back ... */
+				dev->new_comm_interface = 0;
+				if ((dev->regs.sa
+				  = (struct sa_registers *)ioremap(
+				    (unsigned long)dev->scsi_host_ptr->base,
+				    AAC_MIN_FOOTPRINT_SIZE)) == NULL) {	
+					printk(KERN_WARNING
+					  "aacraid: unable to map adapter.\n");
+					return NULL;
+				}
+			}
+		}
+	}
+	if ((!aac_adapter_sync_cmd(dev, GET_COMM_PREFERRED_SETTINGS,
+	  0, 0, 0, 0, 0, 0,
+	  status+0, status+1, status+2, status+3, status+4))
+	 && (status[0] == 0x00000001)) {
+		extern int acbsize;
+		/*
+		 *	status[1] >> 16		maximum command size in KB
+		 *	status[1] & 0xFFFF	maximum FIB size
+		 *	status[2] >> 16		maximum SG elements to driver
+		 *	status[2] & 0xFFFF	maximum SG elements from driver
+		 *	status[3] & 0xFFFF	maximum number FIBs outstanding
+		 */
+		host->max_sectors = (status[1] >> 16) << 1;
+		dev->max_fib_size = status[1] & 0xFFFF;
+		host->sg_tablesize = status[2] >> 16;
+		dev->sg_tablesize = status[2] & 0xFFFF;
+		host->can_queue = (status[3] & 0xFFFF) - AAC_NUM_MGT_FIB;
+		/*
+		 *	NOTE:
+		 *	All these overrides are based on a fixed internal
+		 *	knowledge and understanding of existing adapters,
+		 *	acbsize should be set with caution.
+		 */
+		if (acbsize == 512) {
+			host->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
+			dev->max_fib_size = 512;
+			dev->sg_tablesize = host->sg_tablesize
+			  = (512 - sizeof(struct aac_fibhdr)
+			    - sizeof(struct aac_write) + sizeof(struct sgmap))
+			     / sizeof(struct sgmap);
+			host->can_queue = AAC_NUM_IO_FIB;
+		} else if (acbsize == 2048) {
+			host->max_sectors = 512;
+			dev->max_fib_size = 2048;
+			host->sg_tablesize = 65;
+			dev->sg_tablesize = 81;
+			host->can_queue = 512 - AAC_NUM_MGT_FIB;
+		} else if (acbsize == 4096) {
+			host->max_sectors = 1024;
+			dev->max_fib_size = 4096;
+			host->sg_tablesize = 129;
+			dev->sg_tablesize = 166;
+			host->can_queue = 256 - AAC_NUM_MGT_FIB;
+		} else if (acbsize == 8192) {
+			host->max_sectors = 2048;
+			dev->max_fib_size = 8192;
+			host->sg_tablesize = 257;
+			dev->sg_tablesize = 337;
+			host->can_queue = 128 - AAC_NUM_MGT_FIB;
+		} else if (acbsize > 0) {
+			printk("Illegal acbsize=%d ignored\n", acbsize);
+		}
+	}
+	{
+		extern int numacb;
+
+		if (numacb > 0) {
+			if (numacb < host->can_queue)
+				host->can_queue = numacb;
+			else
+				printk("numacb=%d ignored\n", numacb);
+		}
+	}
+
 	/*
 	 *	Ok now init the communication subsystem
 	 */
--- linux-2.6.8.1-t043-libata-update/drivers/scsi/aacraid/aacraid.h	2005-09-26 13:33:12.000000000 +0400
+++ aacraid-drv/drivers/scsi/aacraid/aacraid.h	2005-05-13 19:59:51.000000000 +0400
@@ -1,20 +1,66 @@
+#define CODE_STREAM_IDENTIFIER "This is the code stream identifier"
+#define AAC_DRIVER_BRANCH "dkms"
+//#define dprintk(x) printk x
 #if (!defined(dprintk))
 # define dprintk(x)
 #endif
+//#define fwprintf(x) aac_fw_printf x
+#if (!defined(fwprintf))
+# define fwprintf(x)
+#endif
+//#define AAC_DETAILED_STATUS_INFO
+//#define AAC_DEBUG_INSTRUMENT_TIMING
+//#define AAC_DEBUG_INSTRUMENT_AIF
+//#define AAC_DEBUG_INSTRUMENT_IOCTL
+//#define AAC_DEBUG_INSTRUMENT_AAC_CONFIG
+//#define AAC_DEBUG_INSTRUMENT_RESET
+//#define AAC_DEBUG_INSTRUMENT_FIB
+//#define AAC_DEBUG_INSTRUMENT_2TB
+//#define AAC_DEBUG_INSTRUMENT_SENDFIB
+//#define AAC_DEBUG_INSTRUMENT_IO
+
+/* eg: if (nblank(dprintk(x))) */
+#define _nblank(x) #x
+#define nblank(x) _nblank(x)[0]
+
+#include "compat.h"
+#if (defined(SCSI_HAS_DUMP))
+#include <linux/interrupt.h>
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,23))
+#if (!defined(IRQ_NONE))
+  typedef void irqreturn_t;
+# define IRQ_HANDLED
+# define IRQ_NONE
+#endif
+#endif
+#endif
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,9))
+#define AAC_CSMI
+#endif
 
 /*------------------------------------------------------------------------------
  *              D E F I N E S
  *----------------------------------------------------------------------------*/
 
+//#define AAC_EXTENDED_TIMEOUT	120
+
+#ifndef AAC_DRIVER_BUILD
+# define AAC_DRIVER_BUILD 2400
+#endif
 #define MAXIMUM_NUM_CONTAINERS	32
-#define MAXIMUM_NUM_ADAPTERS	8
 
-#define AAC_NUM_FIB		(256 + 64)
-#define AAC_NUM_IO_FIB		100
+#define AAC_NUM_MGT_FIB		8
+#define AAC_NUM_IO_FIB		(512-AAC_NUM_MGT_FIB)
+#define AAC_NUM_FIB		(AAC_NUM_IO_FIB+AAC_NUM_MGT_FIB)
 
 #define AAC_MAX_LUN		(8)
 
 #define AAC_MAX_HOSTPHYSMEMPAGES (0xfffff)
+/*
+ *  max_sectors is an unsigned short, otherwise limit is 0x100000000 / 512
+ * Linux has starvation problems if we permit larger than 4MB I/O ...
+ */
+#define AAC_MAX_32BIT_SGBCOUNT	((unsigned short)8192)
 
 /*
  * These macros convert from physical channels to virtual channels
@@ -28,10 +74,10 @@
 #define aac_phys_to_logical(x)  (x+1)
 #define aac_logical_to_phys(x)  (x?x-1:0)
 
-#define AAC_DETAILED_STATUS_INFO
-
-extern int nondasd;
-extern int paemode;
+/* #define AAC_DETAILED_STATUS_INFO */
+#if (defined(__arm__))
+#define AAC_LM_SENSOR
+#endif
 
 struct diskparm
 {
@@ -60,6 +106,7 @@ struct diskparm
 #define		CT_VOLUME_OF_MIRRORS	12	/* volume of mirror */
 #define		CT_PSEUDO_RAID		13	/* really raid4 */
 #define		CT_LAST_VOLUME_TYPE	14
+#define 	CT_OK        		218
 
 /*
  *	Types of objects addressable in some fashion by the client.
@@ -92,15 +139,41 @@ struct diskparm
  *	on 64 bit systems not all cards support the 64 bit version
  */
 struct sgentry {
+	__le32	addr;	/* 32-bit address. */
+	__le32	count;	/* Length. */
+};
+
+struct user_sgentry {
 	u32	addr;	/* 32-bit address. */
 	u32	count;	/* Length. */
 };
 
 struct sgentry64 {
+	__le32	addr[2];	/* 64-bit addr. 2 pieces for data alignment */
+	__le32	count;	/* Length. */
+};
+
+struct user_sgentry64 {
 	u32	addr[2];	/* 64-bit addr. 2 pieces for data alignment */
 	u32	count;	/* Length. */
 };
 
+struct sgentryraw {
+	__le32		next;	/* reserved for F/W use */
+	__le32		prev;	/* reserved for F/W use */
+	__le32		addr[2];
+	__le32		count;
+	__le32		flags;	/* reserved for F/W use */
+};
+
+struct user_sgentryraw {
+	u32		next;	/* reserved for F/W use */
+	u32		prev;	/* reserved for F/W use */
+	u32		addr[2];
+	u32		count;
+	u32		flags;	/* reserved for F/W use */
+};
+
 /*
  *	SGMAP
  *
@@ -109,15 +182,35 @@ struct sgentry64 {
  */
 
 struct sgmap {
-	u32		count;
+	__le32		count;
 	struct sgentry	sg[1]; 
 };
 
-struct sgmap64 {
+struct user_sgmap {
 	u32		count;
+	struct user_sgentry	sg[1]; 
+};
+
+struct sgmap64 {
+	__le32		count;
 	struct sgentry64 sg[1];
 };
 
+struct user_sgmap64 {
+	u32		count;
+	struct user_sgentry64 sg[1];
+};
+
+struct sgmapraw {
+	__le32		  count;
+	struct sgentryraw sg[1];
+};
+
+struct user_sgmapraw {
+	u32		  count;
+	struct user_sgentryraw sg[1];
+};
+
 struct creation_info
 {
 	u8 		buildnum;		/* e.g., 588 */
@@ -126,14 +219,14 @@ struct creation_info
 						 * 	 2 = API
 						 */
 	u8	 	year;		 	/* e.g., 1997 = 97 */
-	u32		date;			/*
+	__le32		date;			/*
 						 * unsigned 	Month		:4;	// 1 - 12
 						 * unsigned 	Day		:6;	// 1 - 32
 						 * unsigned 	Hour		:6;	// 0 - 23
 						 * unsigned 	Minute		:6;	// 0 - 60
 						 * unsigned 	Second		:6;	// 0 - 60
 						 */
-	u32		serial[2];			/* e.g., 0x1DEADB0BFAFAF001 */
+	__le32		serial[2];			/* e.g., 0x1DEADB0BFAFAF001 */
 };
 
 
@@ -178,8 +271,8 @@ struct creation_info
  */
 
 struct aac_entry {
-	u32 size;          /* Size in bytes of Fib which this QE points to */
-	u32 addr; /* Receiver address of the FIB */
+	__le32 size;          /* Size in bytes of Fib which this QE points to */
+	__le32 addr; /* Receiver address of the FIB */
 };
 
 /*
@@ -188,9 +281,10 @@ struct aac_entry {
  */
  
 struct aac_qhdr {
-	u64 header_addr;		/* Address to hand the adapter to access to this queue head */
-	u32 *producer;			/* The producer index for this queue (host address) */
-	u32 *consumer;			/* The consumer index for this queue (host address) */
+	__le64 header_addr;/* Address to hand the adapter to access
+			to this queue head */
+	__le32 *producer; /* The producer index for this queue (host address) */
+	__le32 *consumer; /* The consumer index for this queue (host address) */
 };
 
 /*
@@ -264,29 +358,30 @@ enum aac_queue_types {
  */
 
 struct aac_fibhdr {
-	u32 XferState;			// Current transfer state for this CCB
-	u16 Command;			// Routing information for the destination
-	u8 StructType;			// Type FIB
-	u8 Flags;			// Flags for FIB
-	u16 Size;			// Size of this FIB in bytes
-	u16 SenderSize;			// Size of the FIB in the sender (for response sizing)
-	u32 SenderFibAddress;		// Host defined data in the FIB
-	u32 ReceiverFibAddress;		// Logical address of this FIB for the adapter
-	u32 SenderData;			// Place holder for the sender to store data
+	__le32 XferState;	  /* Current transfer state for this CCB */
+	__le16 Command;		  /* Routing information for the destination */
+	u8 StructType;		  /* Type FIB */
+	u8 Flags;		  /* Flags for FIB */
+	__le16 Size;		  /* Size of this FIB in bytes */
+	__le16 SenderSize;	  /* Size of the FIB in the sender
+				  (for response sizing) */
+	__le32 SenderFibAddress;  /* Host defined data in the FIB */
+	__le32 ReceiverFibAddress;/* Logical address of this FIB for
+				the adapter */
+	__le32 SenderData;	  /* Place holder for the sender to store data */
 	union {
 		struct {
-		    u32 _ReceiverTimeStart; 	// Timestamp for receipt of fib
-		    u32 _ReceiverTimeDone;	// Timestamp for completion of fib
+		    __le32 _ReceiverTimeStart; 	/* Timestamp for
+					receipt of fib */
+		    __le32 _ReceiverTimeDone;	/* Timestamp for
+					completion of fib */
 		} _s;
 	} _u;
 };
 
-#define FIB_DATA_SIZE_IN_BYTES (512 - sizeof(struct aac_fibhdr))
-
-
 struct hw_fib {
 	struct aac_fibhdr header;
-	u8 data[FIB_DATA_SIZE_IN_BYTES];		// Command specific data
+	u8 data[512-sizeof(struct aac_fibhdr)];	// Command specific data
 };
 
 /*
@@ -330,6 +425,7 @@ struct hw_fib {
  */
 #define		ContainerCommand		500
 #define		ContainerCommand64		501
+#define		ContainerRawIo			502
 /*
  *	Cluster Commands
  */
@@ -348,11 +444,14 @@ struct hw_fib {
 #define		RequestAdapterInfo		703
 #define		IsAdapterPaused			704
 #define		SendHostTime			705
-#define		LastMiscCommand			706
+#define		RequestSupplementAdapterInfo	706
+#define		LastMiscCommand			707
+
+#define		RequestCompatibilityId		802
 
-//
-// Commands that will target the failover level on the FSA adapter
-//
+/*
+ * Commands that will target the failover level on the FSA adapter
+ */
 
 enum fib_xfer_state {
 	HostOwned 			= (1<<0),
@@ -385,49 +484,61 @@ enum fib_xfer_state {
  */
 
 #define ADAPTER_INIT_STRUCT_REVISION		3
+#define ADAPTER_INIT_STRUCT_REVISION_4		4 // rocket science
 
 struct aac_init
 {
-	u32	InitStructRevision;
-	u32	MiniPortRevision;
-	u32	fsrev;
-	u32	CommHeaderAddress;
-	u32	FastIoCommAreaAddress;
-	u32	AdapterFibsPhysicalAddress;
-	u32	AdapterFibsVirtualAddress;
-	u32	AdapterFibsSize;
-	u32	AdapterFibAlign;
-	u32	printfbuf;
-	u32	printfbufsiz;
-	u32	HostPhysMemPages;		// number of 4k pages of host physical memory
-	u32	HostElapsedSeconds;		// number of seconds since 1970.
+	__le32	InitStructRevision;
+	__le32	MiniPortRevision;
+	__le32	fsrev;
+	__le32	CommHeaderAddress;
+	__le32	FastIoCommAreaAddress;
+	__le32	AdapterFibsPhysicalAddress;
+	__le32	AdapterFibsVirtualAddress;
+	__le32	AdapterFibsSize;
+	__le32	AdapterFibAlign;
+	__le32	printfbuf;
+	__le32	printfbufsiz;
+	__le32	HostPhysMemPages;	/* number of 4k pages of host
+				physical memory */
+	__le32	HostElapsedSeconds;	/* number of seconds since 1970. */
+	/* ADAPTER_INIT_STRUCT_REVISION_4 begins here */
+	__le32	InitFlags;		/* flags for supported features */
+#	define INITFLAGS_NEW_COMM_SUPPORTED	0x00000001
+	__le32	MaxIoCommands;		/* max outstanding commands */
+	__le32	MaxIoSize;		/* largest I/O command */
+	__le32	MaxFibSize;		/* largest FIB to adapter */
 };
 
 enum aac_log_level {
-	LOG_INIT			= 10,
-	LOG_INFORMATIONAL		= 20,
-	LOG_WARNING			= 30,
-	LOG_LOW_ERROR			= 40,
-	LOG_MEDIUM_ERROR		= 50,
-	LOG_HIGH_ERROR			= 60,
-	LOG_PANIC			= 70,
-	LOG_DEBUG			= 80,
-	LOG_WINDBG_PRINT		= 90
+	LOG_AAC_INIT			= 10,
+	LOG_AAC_INFORMATIONAL		= 20,
+	LOG_AAC_WARNING			= 30,
+	LOG_AAC_LOW_ERROR		= 40,
+	LOG_AAC_MEDIUM_ERROR		= 50,
+	LOG_AAC_HIGH_ERROR		= 60,
+	LOG_AAC_PANIC			= 70,
+	LOG_AAC_DEBUG			= 80,
+	LOG_AAC_WINDBG_PRINT		= 90
 };
 
 #define FSAFS_NTC_GET_ADAPTER_FIB_CONTEXT	0x030b
 #define FSAFS_NTC_FIB_CONTEXT			0x030c
 
 struct aac_dev;
+struct fib;
 
 struct adapter_ops
 {
 	void (*adapter_interrupt)(struct aac_dev *dev);
 	void (*adapter_notify)(struct aac_dev *dev, u32 event);
-	void (*adapter_enable_int)(struct aac_dev *dev, u32 event);
-	void (*adapter_disable_int)(struct aac_dev *dev, u32 event);
-	int  (*adapter_sync_cmd)(struct aac_dev *dev, u32 command, u32 p1, u32 *status);
+	void (*adapter_disable_int)(struct aac_dev *dev);
+	int  (*adapter_sync_cmd)(struct aac_dev *dev, u32 command, u32 p1, u32 p2, u32 p3, u32 p4, u32 p5, u32 p6, u32 *status, u32 *r1, u32 *r2, u32 *r3, u32 *r4);
 	int  (*adapter_check_health)(struct aac_dev *dev);
+	int  (*adapter_send)(struct fib * fib);
+#if (defined(SCSI_HAS_DUMP))
+	irqreturn_t (*adapter_intr)(int irq, void *dev_id, struct pt_regs *regs);
+#endif
 };
 
 /*
@@ -449,7 +560,24 @@ struct aac_driver_ident
  * dma mask such that fib memory will be allocated where the
  * adapter firmware can get to it.
  */
-#define AAC_QUIRK_31BIT	1
+#define AAC_QUIRK_31BIT	0x0001
+
+/*
+ * Some adapter firmware, when the raid card's cache is turned off, can not
+ * split up scatter gathers in order to deal with the limits of the
+ * underlying CHIM. This limit is 34 scatter gather elements.
+ */
+#define AAC_QUIRK_34SG	0x0002
+
+/*
+ * This adapter is a slave (no Firmware)
+ */
+#define AAC_QUIRK_SLAVE 0x0004
+
+/*
+ * This adapter is a master.
+ */
+#define AAC_QUIRK_MASTER 0x0008
 
 /*
  *	The adapter interface specs all queues to be located in the same
@@ -471,8 +599,6 @@ struct aac_queue {
                   /* This is only valid for adapter to host command queues. */ 
 	spinlock_t	 	*lock;		/* Spinlock for this queue must take this lock before accessing the lock */
 	spinlock_t		lockdata;	/* Actual lock (used only on one side of the lock) */
-	unsigned long		SavedIrql;     	/* Previous IRQL when the spin lock is taken */
-	u32			padding;	/* Padding - FIXME - can remove I believe */
 	struct list_head 	cmdq;	   	/* A queue of FIBs which need to be prcessed by the FS thread. This is */
                                 		/* only valid for command queues which receive entries from the adapter. */
 	struct list_head	pendingq;	/* A queue of outstanding fib's to the adapter. */
@@ -495,40 +621,32 @@ struct aac_queue_block
  */
  
 struct sa_drawbridge_CSR {
-						//	 Offset |	Name
-	u32	reserved[10];			//	00h-27h |   Reserved
-	u8	LUT_Offset;			//	28h	|	Looup Table Offset
-	u8	reserved1[3];			// 	29h-2bh	|	Reserved
-	u32	LUT_Data;			//	2ch	|	Looup Table Data	
-	u32	reserved2[26];			//	30h-97h	|	Reserved
-	u16	PRICLEARIRQ;			//	98h	|	Primary Clear Irq
-	u16	SECCLEARIRQ;			//	9ah	|	Secondary Clear Irq
-	u16	PRISETIRQ;			//	9ch	|	Primary Set Irq
-	u16	SECSETIRQ;			//	9eh	|	Secondary Set Irq
-	u16	PRICLEARIRQMASK;		//	a0h	|	Primary Clear Irq Mask
-	u16	SECCLEARIRQMASK;		//	a2h	|	Secondary Clear Irq Mask
-	u16	PRISETIRQMASK;			//	a4h	|	Primary Set Irq Mask
-	u16	SECSETIRQMASK;			//	a6h	|	Secondary Set Irq Mask
-	u32	MAILBOX0;			//	a8h	|	Scratchpad 0
-	u32	MAILBOX1;			//	ach	|	Scratchpad 1
-	u32	MAILBOX2;			//	b0h	|	Scratchpad 2
-	u32	MAILBOX3;			//	b4h	|	Scratchpad 3
-	u32	MAILBOX4;			//	b8h	|	Scratchpad 4
-	u32	MAILBOX5;			//	bch	|	Scratchpad 5
-	u32	MAILBOX6;			//	c0h	|	Scratchpad 6
-	u32	MAILBOX7;			//	c4h	|	Scratchpad 7
-
-	u32	ROM_Setup_Data;			//	c8h | 	Rom Setup and Data
-	u32	ROM_Control_Addr;		//	cch | 	Rom Control and Address
-
-	u32	reserved3[12];			//	d0h-ffh	| 	reserved
-	u32	LUT[64];			// 100h-1ffh|	Lookup Table Entries
-
-	//
-	//  TO DO
-	//	need to add DMA, I2O, UART, etc registers form 80h to 364h
-	//
-
+				/*	Offset 	|  Name */
+	__le32	reserved[10];	/*	00h-27h |  Reserved */
+	u8	LUT_Offset;	/*	28h	|  Lookup Table Offset */
+	u8	reserved1[3];	/* 	29h-2bh	|  Reserved */
+	__le32	LUT_Data;	/*	2ch	|  Looup Table Data */
+	__le32	reserved2[26];	/*	30h-97h	|  Reserved */
+	__le16	PRICLEARIRQ;	/*	98h	|  Primary Clear Irq */
+	__le16	SECCLEARIRQ;	/*	9ah	|  Secondary Clear Irq */
+	__le16	PRISETIRQ;	/*	9ch	|  Primary Set Irq */
+	__le16	SECSETIRQ;	/*	9eh	|  Secondary Set Irq */
+	__le16	PRICLEARIRQMASK;/*	a0h	|  Primary Clear Irq Mask */
+	__le16	SECCLEARIRQMASK;/*	a2h	|  Secondary Clear Irq Mask */
+	__le16	PRISETIRQMASK;	/*	a4h	|  Primary Set Irq Mask */
+	__le16	SECSETIRQMASK;	/*	a6h	|  Secondary Set Irq Mask */
+	__le32	MAILBOX0;	/*	a8h	|  Scratchpad 0 */
+	__le32	MAILBOX1;	/*	ach	|  Scratchpad 1 */
+	__le32	MAILBOX2;	/*	b0h	|  Scratchpad 2 */
+	__le32	MAILBOX3;	/*	b4h	|  Scratchpad 3 */
+	__le32	MAILBOX4;	/*	b8h	|  Scratchpad 4 */
+	__le32	MAILBOX5;	/*	bch	|  Scratchpad 5 */
+	__le32	MAILBOX6;	/*	c0h	|  Scratchpad 6 */
+	__le32	MAILBOX7;	/*	c4h	|  Scratchpad 7 */
+	__le32	ROM_Setup_Data;	/*	c8h 	|  Rom Setup and Data */
+	__le32	ROM_Control_Addr;/*	cch 	|  Rom Control and Address */
+	__le32	reserved3[12];	/*	d0h-ffh	|  reserved */
+	__le32	LUT[64];	/*    100h-1ffh	|  Lookup Table Entries */
 };
 
 #define Mailbox0	SaDbCSR.MAILBOX0
@@ -537,6 +655,9 @@ struct sa_drawbridge_CSR {
 #define Mailbox3	SaDbCSR.MAILBOX3
 #define Mailbox4	SaDbCSR.MAILBOX4
 #define Mailbox5	SaDbCSR.MAILBOX5
+#if (defined(AAC_LM_SENSOR))
+#define Mailbox6	SaDbCSR.MAILBOX6
+#endif
 #define Mailbox7	SaDbCSR.MAILBOX7
 	
 #define DoorbellReg_p SaDbCSR.PRISETIRQ
@@ -544,13 +665,13 @@ struct sa_drawbridge_CSR {
 #define DoorbellClrReg_p SaDbCSR.PRICLEARIRQ
 
 
-#define	DOORBELL_0	cpu_to_le16(0x0001)
-#define DOORBELL_1	cpu_to_le16(0x0002)
-#define DOORBELL_2	cpu_to_le16(0x0004)
-#define DOORBELL_3	cpu_to_le16(0x0008)
-#define DOORBELL_4	cpu_to_le16(0x0010)
-#define DOORBELL_5	cpu_to_le16(0x0020)
-#define DOORBELL_6	cpu_to_le16(0x0040)
+#define	DOORBELL_0	0x0001
+#define DOORBELL_1	0x0002
+#define DOORBELL_2	0x0004
+#define DOORBELL_3	0x0008
+#define DOORBELL_4	0x0010
+#define DOORBELL_5	0x0020
+#define DOORBELL_6	0x0040
 
 	
 #define PrintfReady	DOORBELL_5
@@ -573,25 +694,33 @@ struct sa_registers {
  */
 
 struct rx_mu_registers {
-						//	 Local	|   PCI*	|	Name
-						//			|		|
-	u32	ARSR;				//	1300h	|	00h	|	APIC Register Select Register
-	u32	reserved0;			//	1304h	|	04h	|	Reserved
-	u32	AWR;				//	1308h	|	08h	|	APIC Window Register
-	u32	reserved1;			//	130Ch	|	0Ch	|	Reserved
-	u32	IMRx[2];			//	1310h	|	10h	|	Inbound Message Registers
-	u32	OMRx[2];			//	1318h	|	18h	|	Outbound Message Registers
-	u32	IDR;				//	1320h	|	20h	|	Inbound Doorbell Register
-	u32	IISR;				//	1324h	|	24h	|	Inbound Interrupt Status Register
-	u32	IIMR;				//	1328h	|	28h	|	Inbound Interrupt Mask Register
-	u32	ODR;				//	132Ch	|	2Ch	|	Outbound Doorbell Register
-	u32	OISR;				//	1330h	|	30h	|	Outbound Interrupt Status Register
-	u32	OIMR;				//	1334h	|	34h	|	Outbound Interrupt Mask Register
-						// * Must access through ATU Inbound Translation Window
+			    /*	Local  | PCI*| Name */
+	__le32	ARSR;	    /*	1300h  | 00h | APIC Register Select Register */
+	__le32	reserved0;  /*	1304h  | 04h | Reserved */
+	__le32	AWR;	    /*	1308h  | 08h | APIC Window Register */
+	__le32	reserved1;  /*	130Ch  | 0Ch | Reserved */
+	__le32	IMRx[2];    /*	1310h  | 10h | Inbound Message Registers */
+	__le32	OMRx[2];    /*	1318h  | 18h | Outbound Message Registers */
+	__le32	IDR;	    /*	1320h  | 20h | Inbound Doorbell Register */
+	__le32	IISR;	    /*	1324h  | 24h | Inbound Interrupt 
+						Status Register */
+	__le32	IIMR;	    /*	1328h  | 28h | Inbound Interrupt 
+					 	Mask Register */
+	__le32	ODR;	    /*	132Ch  | 2Ch | Outbound Doorbell Register */
+	__le32	OISR;	    /*	1330h  | 30h | Outbound Interrupt 
+						Status Register */
+	__le32	OIMR;	    /*	1334h  | 34h | Outbound Interrupt 
+						Mask Register */
+	__le32	reserved2;  /*	1338h  | 38h | Reserved */
+	__le32	reserved3;  /*	133Ch  | 3Ch | Reserved */
+	__le32	InboundQueue;/*	1340h  | 40h | Inbound Queue Port relative to firmware */
+	__le32	OutboundQueue;/*1344h  | 44h | Outbound Queue Port relative to firmware */
+			    /* * Must access through ATU Inbound 
+			     	 Translation Window */
 };
 
 struct rx_inbound {
-	u32	Mailbox[8];
+	__le32	Mailbox[8];
 };
 
 #define	InboundMailbox0		IndexRegs.Mailbox[0]
@@ -599,30 +728,31 @@ struct rx_inbound {
 #define	InboundMailbox2		IndexRegs.Mailbox[2]
 #define	InboundMailbox3		IndexRegs.Mailbox[3]
 #define	InboundMailbox4		IndexRegs.Mailbox[4]
+#if (defined(AAC_LM_SENSOR))
 #define	InboundMailbox5		IndexRegs.Mailbox[5]
 #define	InboundMailbox6		IndexRegs.Mailbox[6]
-#define	InboundMailbox7		IndexRegs.Mailbox[7]
+#endif
 
-#define	INBOUNDDOORBELL_0	cpu_to_le32(0x00000001)
-#define INBOUNDDOORBELL_1	cpu_to_le32(0x00000002)
-#define INBOUNDDOORBELL_2	cpu_to_le32(0x00000004)
-#define INBOUNDDOORBELL_3	cpu_to_le32(0x00000008)
-#define INBOUNDDOORBELL_4	cpu_to_le32(0x00000010)
-#define INBOUNDDOORBELL_5	cpu_to_le32(0x00000020)
-#define INBOUNDDOORBELL_6	cpu_to_le32(0x00000040)
-
-#define	OUTBOUNDDOORBELL_0	cpu_to_le32(0x00000001)
-#define OUTBOUNDDOORBELL_1	cpu_to_le32(0x00000002)
-#define OUTBOUNDDOORBELL_2	cpu_to_le32(0x00000004)
-#define OUTBOUNDDOORBELL_3	cpu_to_le32(0x00000008)
-#define OUTBOUNDDOORBELL_4	cpu_to_le32(0x00000010)
+#define	INBOUNDDOORBELL_0	0x00000001
+#define INBOUNDDOORBELL_1	0x00000002
+#define INBOUNDDOORBELL_2	0x00000004
+#define INBOUNDDOORBELL_3	0x00000008
+#define INBOUNDDOORBELL_4	0x00000010
+#define INBOUNDDOORBELL_5	0x00000020
+#define INBOUNDDOORBELL_6	0x00000040
+
+#define	OUTBOUNDDOORBELL_0	0x00000001
+#define OUTBOUNDDOORBELL_1	0x00000002
+#define OUTBOUNDDOORBELL_2	0x00000004
+#define OUTBOUNDDOORBELL_3	0x00000008
+#define OUTBOUNDDOORBELL_4	0x00000010
 
 #define InboundDoorbellReg	MUnit.IDR
 #define OutboundDoorbellReg	MUnit.ODR
 
 struct rx_registers {
-	struct rx_mu_registers		MUnit;		// 1300h - 1334h
-	u32				reserved1[6];	// 1338h - 134ch
+	struct rx_mu_registers		MUnit;		/* 1300h - 1344h */
+	__le32				reserved1[2];	/* 1348h - 134ch */
 	struct rx_inbound		IndexRegs;
 };
 
@@ -639,8 +769,8 @@ struct rx_registers {
 #define rkt_inbound rx_inbound
 
 struct rkt_registers {
-	struct rkt_mu_registers		MUnit;		 /* 1300h - 1334h */
-	u32				reserved1[1010]; /* 1338h - 22fch */
+	struct rkt_mu_registers		MUnit;		 /* 1300h - 1344h */
+	__le32				reserved1[1006]; /* 1348h - 22fch */
 	struct rkt_inbound		IndexRegs;	 /* 2300h - */
 };
 
@@ -649,8 +779,6 @@ struct rkt_registers {
 #define rkt_writeb(AEP, CSR, value)	writeb(value, &((AEP)->regs.rkt->CSR))
 #define rkt_writel(AEP, CSR, value)	writel(value, &((AEP)->regs.rkt->CSR))
 
-struct fib;
-
 typedef void (*fib_callback)(void *ctxt, struct fib *fibctx);
 
 struct aac_fib_context {
@@ -665,14 +793,65 @@ struct aac_fib_context {
 	struct list_head	fib_list;	// this holds fibs and their attachd hw_fibs
 };
 
-struct fsa_scsi_hba {
-	u32		size[MAXIMUM_NUM_CONTAINERS];
-	u32		type[MAXIMUM_NUM_CONTAINERS];
-	u8		valid[MAXIMUM_NUM_CONTAINERS];
-	u8		ro[MAXIMUM_NUM_CONTAINERS];
-	u8		locked[MAXIMUM_NUM_CONTAINERS];
-	u8		deleted[MAXIMUM_NUM_CONTAINERS];
-	char		devname[MAXIMUM_NUM_CONTAINERS][8];
+struct sense_data {
+	u8 error_code;		/* 70h (current errors), 71h(deferred errors) */
+	u8 valid:1;		/* A valid bit of one indicates that the information  */
+				/* field contains valid information as defined in the
+				 * SCSI-2 Standard.
+				 */
+	u8 segment_number;	/* Only used for COPY, COMPARE, or COPY AND VERIFY Commands */
+	u8 sense_key:4;		/* Sense Key */
+	u8 reserved:1;
+	u8 ILI:1;		/* Incorrect Length Indicator */
+	u8 EOM:1;		/* End Of Medium - reserved for random access devices */
+	u8 filemark:1;		/* Filemark - reserved for random access devices */
+
+	u8 information[4];	/* for direct-access devices, contains the unsigned 
+				 * logical block address or residue associated with 
+				 * the sense key 
+				 */
+	u8 add_sense_len;	/* number of additional sense bytes to follow this field */
+	u8 cmnd_info[4];	/* not used */
+	u8 ASC;			/* Additional Sense Code */
+	u8 ASCQ;		/* Additional Sense Code Qualifier */
+	u8 FRUC;		/* Field Replaceable Unit Code - not used */
+	u8 bit_ptr:3;		/* indicates which byte of the CDB or parameter data
+				 * was in error
+				 */
+	u8 BPV:1;		/* bit pointer valid (BPV): 1- indicates that 
+				 * the bit_ptr field has valid value
+				 */
+	u8 reserved2:2;
+	u8 CD:1;		/* command data bit: 1- illegal parameter in CDB.
+				 * 0- illegal parameter in data.
+				 */
+	u8 SKSV:1;
+	u8 field_ptr[2];	/* byte of the CDB or parameter data in error */
+};
+
+struct fsa_dev_info {
+	u64		last;
+	u64		size;
+	u32		type;
+	u32		ConfigWaitingOn;
+	u16		queue_depth;
+	u8		ConfigNeeded;
+	u8		valid;
+	u8		ro;
+	u8		locked;
+	u8		deleted;
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,19))
+#	define MAX_NESTED AAC_NUM_MGT_FIB
+//#	undef MAX_NESTED
+//#	define MAX_NESTED 1
+#	if (MAX_NESTED >= 256)
+		u16	nested;
+#	else
+		u8	nested;
+#	endif
+#endif
+	char		devname[8];
+	struct sense_data sense_data;
 };
 
 struct fib {
@@ -707,6 +886,12 @@ struct fib {
 	void 			*data;
 	struct hw_fib		*hw_fib;		/* Actual shared object */
 	dma_addr_t		hw_fib_pa;		/* physical address of hw_fib*/
+#if (defined(AAC_DEBUG_INSTRUMENT_TIMING))
+	unsigned long		DriverTimeStartS;
+	unsigned long		DriverTimeStartuS;
+	unsigned long		DriverTimeDoneS;
+	unsigned long		DriverTimeDoneuS;
+#endif
 };
 
 /*
@@ -717,27 +902,68 @@ struct fib {
  
 struct aac_adapter_info
 {
-	u32	platform;
-	u32	cpu;
-	u32	subcpu;
-	u32	clock;
-	u32	execmem;
-	u32	buffermem;
-	u32	totalmem;
-	u32	kernelrev;
-	u32	kernelbuild;
-	u32	monitorrev;
-	u32	monitorbuild;
-	u32	hwrev;
-	u32	hwbuild;
-	u32	biosrev;
-	u32	biosbuild;
-	u32	cluster;
-	u32	clusterchannelmask; 
-	u32	serial[2];
-	u32	battery;
-	u32	options;
-	u32	OEM;
+	__le32	platform;
+	__le32	cpu;
+	__le32	subcpu;
+	__le32	clock;
+	__le32	execmem;
+	__le32	buffermem;
+	__le32	totalmem;
+	__le32	kernelrev;
+	__le32	kernelbuild;
+	__le32	monitorrev;
+	__le32	monitorbuild;
+	__le32	hwrev;
+	__le32	hwbuild;
+	__le32	biosrev;
+	__le32	biosbuild;
+	__le32	cluster;
+	__le32	clusterchannelmask; 
+	__le32	serial[2];
+	__le32	battery;
+	__le32	options;
+	__le32	OEM;
+};
+
+struct aac_supplement_adapter_info
+{
+	u8	AdapterTypeText[17+1];
+	u8	Pad[2];
+	u32	FlashMemoryByteSize;
+	u32	FlashImageId;
+	u32	MaxNumberPorts;
+	u32	Version;
+	u32	FeatureBits;
+	u8	SlotNumber;
+	u8	ReservedPad0[0];
+	u8	BuildDate[12];
+	u32	CurrentNumberPorts;
+	u32	ReservedGrowth[24];
+};
+#define AAC_FEATURE_FALCON	0x00000010
+#define AAC_SIS_VERSION_V3	3
+#define AAC_SIS_SLOT_UNKNOWN	0xFF
+
+#define GetBusInfo 0x00000009
+struct aac_bus_info {
+	u32	Command;	/* VM_Ioctl */
+	u32	ObjType;	/* FT_DRIVE */
+	u32	MethodId;	/* 1 = SCSI Layer */
+	u32	ObjectId;	/* Handle */
+	u32	CtlCmd;		/* GetBusInfo */
+};
+
+struct aac_bus_info_response {
+	u32	Status;		/* ST_OK */
+	u32	ObjType;
+	u32	MethodId;	/* unused */
+	u32	ObjectId;	/* unused */
+	u32	CtlCmd;		/* unused */
+	u32	ProbeComplete;
+	u32	BusCount;
+	u32	TargetsPerBus;
+	u8	InitiatorBusId[10];
+	u8	BusValid[10];
 };
 
 /*
@@ -771,14 +997,24 @@ struct aac_adapter_info
 #define AAC_OPT_SGMAP_HOST64		cpu_to_le32(1<<10)
 #define AAC_OPT_ALARM			cpu_to_le32(1<<11)
 #define AAC_OPT_NONDASD			cpu_to_le32(1<<12)
+#define AAC_OPT_SCSI_MANAGED    	cpu_to_le32(1<<13)
+#define AAC_OPT_RAID_SCSI_MODE		cpu_to_le32(1<<14)
+#define AAC_OPT_SUPPLEMENT_ADAPTER_INFO	cpu_to_le32(1<<16)
+#define AAC_OPT_NEW_COMM		cpu_to_le32(1<<17)
+#define AAC_OPT_NEW_COMM_64		cpu_to_le32(1<<18)
 
 struct aac_dev
 {
-	struct aac_dev		*next;
+	struct list_head	entry;
 	const char		*name;
 	int			id;
 
-	u16			irq_mask;
+	/*
+	 *	negotiated FIB settings
+	 */
+	unsigned		max_fib_size;
+	unsigned		sg_tablesize;
+
 	/*
 	 *	Map for 128 fib objects (64k)
 	 */	
@@ -807,28 +1043,43 @@ struct aac_dev
 	struct adapter_ops	a_ops;
 	unsigned long		fsrev;		/* Main driver's revision number */
 	
+	unsigned		base_size;	/* Size of mapped in region */
 	struct aac_init		*init;		/* Holds initialization info to communicate with adapter */
 	dma_addr_t		init_pa; 	/* Holds physical address of the init struct */
 	
 	struct pci_dev		*pdev;		/* Our PCI interface */
 	void *			printfbuf;	/* pointer to buffer used for printf's from the adapter */
+	u32			DebugFlags;	/* Debug print flags bitmap */
+	u8 *			FwDebugBuffer_P;/* Addr FW Debug Buffer */
+	u32 *			FwDebugFlags_P;	/* Addr FW Debug Flags */
+	u32			FwDebugFlags;	/* FW Debug Flags */
+	u32 *			FwDebugStrLength_P;/* Addr FW Debug String Length */
+	u8 *			FwDebugBLEDflag_P;/* Addr FW Debug BLED */
+	u8 *			FwDebugBLEDvalue_P;/* Addr FW Debug BLED */
+	u32			FwDebugBufferSize;/* FW Debug Buffer Size in Bytes */
 	void *			comm_addr;	/* Base address of Comm area */
 	dma_addr_t		comm_phys;	/* Physical Address of Comm area */
 	size_t			comm_size;
 
 	struct Scsi_Host	*scsi_host_ptr;
-	struct fsa_scsi_hba	fsa_dev;
+	int			maximum_num_containers;
+	int			maximum_num_physicals;
+	int			maximum_num_channels;
+	struct fsa_dev_info	*fsa_dev;
 	pid_t			thread_pid;
 	int			cardtype;
 	
 	/*
 	 *	The following is the device specific extension.
 	 */
+#if (!defined(AAC_MIN_FOOTPRINT_SIZE))
+#	define AAC_MIN_FOOTPRINT_SIZE 8192
+#endif
 	union
 	{
-		struct sa_registers *sa;
-		struct rx_registers *rx;
-		struct rkt_registers *rkt;
+		struct sa_registers __iomem *sa;
+		struct rx_registers __iomem *rx;
+		struct rkt_registers __iomem *rkt;
 	} regs;
 	u32			OIMR; /* Mask Register Cache */
 	/*
@@ -837,34 +1088,50 @@ struct aac_dev
 	u32			aif_thread;
 	struct completion	aif_completion;
 	struct aac_adapter_info adapter_info;
+	struct aac_supplement_adapter_info supplement_adapter_info;
+#if (defined(CODE_STREAM_IDENTIFIER))
+# if (!defined(MAX_CODE_STREAM_IDENTIFIER_LENGTH))
+#  define MAX_CODE_STREAM_IDENTIFIER_LENGTH 64
+# endif
+	char			code_stream_identifier[MAX_CODE_STREAM_IDENTIFIER_LENGTH];
+#endif
 	/* These are in adapter info but they are in the io flow so
 	 * lets break them out so we don't have to do an AND to check them
 	 */
 	u8			nondasd_support; 
-	u8			pae_support;
+	u8			dac_support;
+	u8			raid_scsi_mode;
+	u8			new_comm_interface;
+	/* macro side-effects BEWARE */
+#	define			raw_io_interface \
+	  init->InitStructRevision==cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_4)
+#	define			printf_enabled \
+	  scsi_host_ptr->sg_tablesize<=34
+	u8			raw_io_64;
 };
 
-#define AllocateAndMapFibSpace(dev, MapFibContext) \
-	(dev)->a_ops.AllocateAndMapFibSpace(dev, MapFibContext)
-
-#define UnmapAndFreeFibSpace(dev, MapFibContext) \
-	(dev)->a_ops.UnmapAndFreeFibSpace(dev, MapFibContext)
-
 #define aac_adapter_interrupt(dev) \
 	(dev)->a_ops.adapter_interrupt(dev)
 
 #define aac_adapter_notify(dev, event) \
 	(dev)->a_ops.adapter_notify(dev, event)
 
-#define aac_adapter_enable_int(dev, event) \
-	(dev)->a_ops.adapter_enable_int(dev, event)
+#define aac_adapter_disable_int(dev) \
+	(dev)->a_ops.adapter_disable_int(dev)
 
-#define aac_adapter_disable_int(dev, event) \
-	dev->a_ops.adapter_disable_int(dev, event)
+#define aac_adapter_sync_cmd(dev, command, p1, p2, p3, p4, p5, p6, status, r1, r2, r3, r4) \
+	(dev)->a_ops.adapter_sync_cmd(dev, command, p1, p2, p3, p4, p5, p6, status, r1, r2, r3, r4)
 
 #define aac_adapter_check_health(dev) \
 	(dev)->a_ops.adapter_check_health(dev)
 
+#define aac_adapter_send(fib) \
+	((fib)->dev)->a_ops.adapter_send(fib)
+#if (defined(SCSI_HAS_DUMP))
+
+#define aac_adapter_intr(dev) \
+	(dev)->a_ops.adapter_intr(dev->scsi_host_ptr->irq, (void *)dev, (struct pt_regs *)NULL)
+#endif
 
 #define FIB_CONTEXT_FLAG_TIMED_OUT		(0x00000001)
 
@@ -974,59 +1241,113 @@ struct aac_dev
 
 struct aac_read
 {
-	u32	 	command;
-	u32 		cid;
-	u32 		block;
-	u32 		count;
+	__le32	 	command;
+	__le32 		cid;
+	__le32 		block;
+	__le32 		count;
 	struct sgmap	sg;	// Must be last in struct because it is variable
 };
 
 struct aac_read64
 {
-	u32	 	command;
-	u16 		cid;
-	u16 		sector_count;
-	u32 		block;
-	u16		pad;
-	u16		flags;
+	__le32	 	command;
+	__le16 		cid;
+	__le16 		sector_count;
+	__le32 		block;
+	__le16		pad;
+	__le16		flags;
 	struct sgmap64	sg;	// Must be last in struct because it is variable
 };
 
 struct aac_read_reply
 {
-	u32	 	status;
-	u32 		count;
+	__le32	 	status;
+	__le32 		count;
 };
 
 struct aac_write
 {
-	u32		command;
-	u32 		cid;
-	u32 		block;
-	u32 		count;
-	u32	 	stable;	// Not used
+	__le32		command;
+	__le32 		cid;
+	__le32 		block;
+	__le32 		count;
+	__le32	 	stable;	// Not used
 	struct sgmap	sg;	// Must be last in struct because it is variable
 };
 
 struct aac_write64
 {
-	u32	 	command;
-	u16 		cid;
-	u16 		sector_count;
-	u32 		block;
-	u16		pad;
-	u16		flags;
+	__le32	 	command;
+	__le16 		cid;
+	__le16 		sector_count;
+	__le32 		block;
+	__le16		pad;
+	__le16		flags;
 	struct sgmap64	sg;	// Must be last in struct because it is variable
 };
 struct aac_write_reply
 {
-	u32		status;
-	u32 		count;
-	u32		committed;
+	__le32		status;
+	__le32 		count;
+	__le32		committed;
+};
+
+struct aac_raw_io
+{
+	__le32		block[2];
+	__le32		count;
+	__le16		cid;
+	__le16		flags;		/* 00 W, 01 R */
+	__le16		bpTotal;	/* reserved for F/W use */
+	__le16		bpComplete;	/* reserved for F/W use */
+	struct sgmapraw	sg;
+};
+
+#define CT_FLUSH_CACHE 129
+struct aac_synchronize {
+	__le32		command;	/* VM_ContainerConfig */
+	__le32		type;		/* CT_FLUSH_CACHE */
+	__le32		cid;
+	__le32		parm1;
+	__le32		parm2;
+	__le32		parm3;
+	__le32		parm4;
+	__le32		count;	/* sizeof(((struct aac_synchronize_reply *)NULL)->data) */
+};
+
+struct aac_synchronize_reply {
+	__le32		dummy0;
+	__le32		dummy1;
+	__le32		status;	/* CT_OK */
+	__le32		parm1;
+	__le32		parm2;
+	__le32		parm3;
+	__le32		parm4;
+	__le32		parm5;
+	u8		data[16];
 };
 
 struct aac_srb
 {
+	__le32		function;
+	__le32		channel;
+	__le32		id;
+	__le32		lun;
+	__le32		timeout;
+	__le32		flags;
+	__le32		count;		// Data xfer size
+	__le32		retry_limit;
+	__le32		cdb_size;
+	u8		cdb[16];
+	struct	sgmap	sg;
+};
+
+/*
+ * This and associated data structs are used by the
+ * ioctl caller and are in cpu order.
+ */
+struct user_aac_srb
+{
 	u32		function;
 	u32		channel;
 	u32		id;
@@ -1037,20 +1358,18 @@ struct aac_srb
 	u32		retry_limit;
 	u32		cdb_size;
 	u8		cdb[16];
-	struct	sgmap	sg;
+	struct	user_sgmap	sg;
 };
 
-
-
 #define		AAC_SENSE_BUFFERSIZE	 30
 
 struct aac_srb_reply
 {
-	u32		status;
-	u32		srb_status;
-	u32		scsi_status;
-	u32		data_xfer_length;
-	u32		sense_data_size;
+	__le32		status;
+	__le32		srb_status;
+	__le32		scsi_status;
+	__le32		data_xfer_length;
+	__le32		sense_data_size;
 	u8		sense_data[AAC_SENSE_BUFFERSIZE]; // Can this be SCSI_SENSE_BUFFERSIZE
 };
 /*
@@ -1145,8 +1464,10 @@ struct aac_srb_reply
 #define		VM_CtBlockVerify64	18
 #define		VM_CtHostRead64		19
 #define		VM_CtHostWrite64	20
+#define		VM_DrvErrTblLog		21
+#define		VM_NameServe64		22
 
-#define		MAX_VMCOMMAND_NUM	21	/* used for sizing stats array - leave last */
+#define		MAX_VMCOMMAND_NUM	23	/* used for sizing stats array - leave last */
 
 /*
  *	Descriptive information (eg, vital stats)
@@ -1157,14 +1478,14 @@ struct aac_srb_reply
  */
 
 struct aac_fsinfo {
-	u32  fsTotalSize;	/* Consumed by fs, incl. metadata */
-	u32  fsBlockSize;
-	u32  fsFragSize;
-	u32  fsMaxExtendSize;
-	u32  fsSpaceUnits;
-	u32  fsMaxNumFiles;
-	u32  fsNumFreeFiles;
-	u32  fsInodeDensity;
+	__le32  fsTotalSize;	/* Consumed by fs, incl. metadata */
+	__le32  fsBlockSize;
+	__le32  fsFragSize;
+	__le32  fsMaxExtendSize;
+	__le32  fsSpaceUnits;
+	__le32  fsMaxNumFiles;
+	__le32  fsNumFreeFiles;
+	__le32  fsInodeDensity;
 };	/* valid iff ObjType == FT_FILESYS && !(ContentState & FSCS_NOTCLEAN) */
 
 union aac_contentinfo {
@@ -1172,20 +1493,90 @@ union aac_contentinfo {
 };
 
 /*
+ *	Query for Container Configuration Status
+ */
+
+#define CT_GET_CONFIG_STATUS 147
+struct aac_get_config_status {
+	__le32		command;	/* VM_ContainerConfig */
+	__le32		type;		/* CT_GET_CONFIG_STATUS */
+	__le32		parm1;
+	__le32		parm2;
+	__le32		parm3;
+	__le32		parm4;
+	__le32		parm5;
+	__le32		count;	/* sizeof(((struct aac_get_config_status_resp *)NULL)->data) */
+};
+
+#define CFACT_CONTINUE 0
+#define CFACT_PAUSE    1
+#define CFACT_ABORT    2
+struct aac_get_config_status_resp {
+	__le32		response; /* ST_OK */
+	__le32		dummy0;
+	__le32		status;	/* CT_OK */
+	__le32		parm1;
+	__le32		parm2;
+	__le32		parm3;
+	__le32		parm4;
+	__le32		parm5;
+	struct {
+		__le32	action; /* CFACT_CONTINUE, CFACT_PAUSE or CFACT_ABORT */
+		__le16	flags;
+		__le16	count;
+	}		data;
+};
+
+/*
+ *	Accept the configuration as-is
+ */
+
+#define CT_COMMIT_CONFIG 152
+
+struct aac_commit_config {
+	__le32		command;	/* VM_ContainerConfig */
+	__le32		type;		/* CT_COMMIT_CONFIG */
+};
+
+/*
+ *	Query for Container Configuration Status
+ */
+
+#define CT_GET_CONTAINER_COUNT 4
+struct aac_get_container_count {
+	__le32		command;	/* VM_ContainerConfig */
+	__le32		type;		/* CT_GET_CONTAINER_COUNT */
+};
+
+struct aac_get_container_count_resp {
+	__le32		response; /* ST_OK */
+	__le32		dummy0;
+	__le32		MaxContainers;
+	__le32		ContainerSwitchEntries;
+	__le32		MaxPartitions;
+};
+
+
+/*
  *	Query for "mountable" objects, ie, objects that are typically
  *	associated with a drive letter on the client (host) side.
  */
 
 struct aac_mntent {
-	u32    			oid;
-	u8			name[16];	// if applicable
-	struct creation_info	create_info;	// if applicable
-	u32			capacity;
-	u32			vol;    	// substrate structure
-	u32			obj;	        // FT_FILESYS, FT_DATABASE, etc.
-	u32			state;		// unready for mounting, readonly, etc.
-	union aac_contentinfo	fileinfo;	// Info specific to content manager (eg, filesystem)
-	u32			altoid;		// != oid <==> snapshot or broken mirror exists
+	__le32    		oid;
+	u8			name[16];	/* if applicable */
+	struct creation_info	create_info;	/* if applicable */
+	__le32			capacity;
+	__le32			vol;    	/* substrate structure */
+	__le32			obj;	        /* FT_FILESYS,
+					FT_DATABASE, etc. */
+	__le32			state;		/* unready for mounting,
+					readonly, etc. */
+	union aac_contentinfo	fileinfo;	/* Info specific to content
+					manager (eg, filesystem) */
+	__le32			altoid;		/* != oid <==> snapshot or
+					broken mirror exists */
+	__le32			capacityhigh;
 };
 
 #define FSCS_NOTCLEAN	0x0001  /* fsck is neccessary before mounting */
@@ -1193,25 +1584,49 @@ struct aac_mntent {
 #define FSCS_HIDDEN	0x0004	/* should be ignored - set during a clear */
 
 struct aac_query_mount {
-	u32		command;
-	u32		type;
-	u32		count;
+	__le32		command;
+	__le32		type;
+	__le32		count;
 };
 
 struct aac_mount {
-	u32		status;
-	u32	   	type;           /* should be same as that requested */
-	u32		count;
+	__le32		status;
+	__le32	   	type;           /* should be same as that requested */
+	__le32		count;
 	struct aac_mntent mnt[1];
 };
 
+#define CT_READ_NAME 130
+struct aac_get_name {
+	__le32		command;	/* VM_ContainerConfig */
+	__le32		type;		/* CT_READ_NAME */
+	__le32		cid;
+	__le32		parm1;
+	__le32		parm2;
+	__le32		parm3;
+	__le32		parm4;
+	__le32		count;	/* sizeof(((struct aac_get_name_resp *)NULL)->data) */
+};
+
+struct aac_get_name_resp {
+	__le32		dummy0;
+	__le32		dummy1;
+	__le32		status;	/* CT_OK */
+	__le32		parm1;
+	__le32		parm2;
+	__le32		parm3;
+	__le32		parm4;
+	__le32		parm5;
+	u8		data[16];
+};
+
 /*
  * The following command is sent to shut down each container.
  */
 
 struct aac_close {
-	u32	command;
-	u32	cid;
+	__le32	command;
+	__le32	cid;
 };
 
 struct aac_query_disk
@@ -1246,6 +1661,17 @@ struct revision
 	u32 version;
 	u32 build;
 };
+
+#if (defined(CODE_STREAM_IDENTIFIER))
+#define VERSION_MATCH_SUCCESS		1
+#define VERSION_MATCH_FAILED		2
+#define VERSION_MATCH_UNSUPPORTED	3
+struct VersionMatch {
+	u32 status;
+	char driver[MAX_CODE_STREAM_IDENTIFIER_LENGTH];
+	char firmware[MAX_CODE_STREAM_IDENTIFIER_LENGTH];
+};
+#endif
 	
 /*
  * 	Ugly - non Linux like ioctl coding for back compat.
@@ -1277,7 +1703,10 @@ struct revision
 #define FSACTL_MINIPORT_REV_CHECK               CTL_CODE(2107, METHOD_BUFFERED)
 #define FSACTL_GET_PCI_INFO               	CTL_CODE(2119, METHOD_BUFFERED)
 #define FSACTL_FORCE_DELETE_DISK		CTL_CODE(2120, METHOD_NEITHER)
+#define FSACTL_REGISTER_FIB_SEND		CTL_CODE(2136, METHOD_BUFFERED)
 #define FSACTL_GET_CONTAINERS			2131
+#define FSACTL_GET_VERSION_MATCHING		CTL_CODE(2137, METHOD_BUFFERED)
+#define FSACTL_SEND_LARGE_FIB			CTL_CODE(2138, METHOD_BUFFERED)
 
 
 struct aac_common
@@ -1290,6 +1719,13 @@ struct aac_common
 	u32 peak_fibs;
 	u32 zero_fibs;
 	u32 fib_timeouts;
+#if (defined(AAC_DEBUG_INSTRUMENT_AAC_CONFIG))
+	u32 peak_size;
+	u32 peak_sg;
+#endif
+#if (defined(AAC_DEBUG_INSTRUMENT_TIMING))
+	u32 peak_duration;
+#endif
 	/*
 	 *	Statistical counters in debug mode
 	 */
@@ -1324,15 +1760,19 @@ extern struct aac_common aac_config;
  *	Monitor/Kernel API
  */
 
-#define	BREAKPOINT_REQUEST		cpu_to_le32(0x00000004)
-#define	INIT_STRUCT_BASE_ADDRESS	cpu_to_le32(0x00000005)
-#define READ_PERMANENT_PARAMETERS	cpu_to_le32(0x0000000a)
-#define WRITE_PERMANENT_PARAMETERS	cpu_to_le32(0x0000000b)
-#define HOST_CRASHING			cpu_to_le32(0x0000000d)
-#define	SEND_SYNCHRONOUS_FIB		cpu_to_le32(0x0000000c)
-#define	COMMAND_POST_RESULTS		cpu_to_le32(0x00000014)
-#define GET_ADAPTER_PROPERTIES		cpu_to_le32(0x00000019)
-#define RE_INIT_ADAPTER			cpu_to_le32(0x000000ee)
+#define	BREAKPOINT_REQUEST		0x00000004
+#define	INIT_STRUCT_BASE_ADDRESS	0x00000005
+#define READ_PERMANENT_PARAMETERS	0x0000000a
+#define WRITE_PERMANENT_PARAMETERS	0x0000000b
+#define HOST_CRASHING			0x0000000d
+#define	SEND_SYNCHRONOUS_FIB		0x0000000c
+#define COMMAND_POST_RESULTS		0x00000014
+#define GET_ADAPTER_PROPERTIES		0x00000019
+#define GET_DRIVER_BUFFER_PROPERTIES	0x00000023
+#define RCV_TEMP_READINGS		0x00000025
+#define GET_COMM_PREFERRED_SETTINGS	0x00000026
+#define IOP_RESET			0x00001000
+#define RE_INIT_ADAPTER			0x000000ee
 
 /*
  *	Adapter Status Register
@@ -1355,22 +1795,22 @@ extern struct aac_common aac_config;
  *	Phases are bit oriented.  It is NOT valid  to have multiple bits set						
  */					
 
-#define	SELF_TEST_FAILED		(cpu_to_le32(0x00000004))
-#define MONITOR_PANIC			(cpu_to_le32(0x00000020))
-#define	KERNEL_UP_AND_RUNNING		(cpu_to_le32(0x00000080))
-#define	KERNEL_PANIC			(cpu_to_le32(0x00000100))
+#define	SELF_TEST_FAILED		0x00000004
+#define	MONITOR_PANIC			0x00000020
+#define	KERNEL_UP_AND_RUNNING		0x00000080
+#define	KERNEL_PANIC			0x00000100
 
 /*
  *	Doorbell bit defines
  */
 
-#define DoorBellSyncCmdAvailable	cpu_to_le32(1<<0)	// Host -> Adapter
-#define DoorBellPrintfDone		cpu_to_le32(1<<5)	// Host -> Adapter
-#define DoorBellAdapterNormCmdReady	cpu_to_le32(1<<1)	// Adapter -> Host
-#define DoorBellAdapterNormRespReady	cpu_to_le32(1<<2)	// Adapter -> Host
-#define DoorBellAdapterNormCmdNotFull	cpu_to_le32(1<<3)	// Adapter -> Host
-#define DoorBellAdapterNormRespNotFull	cpu_to_le32(1<<4)	// Adapter -> Host
-#define DoorBellPrintfReady		cpu_to_le32(1<<5)	// Adapter -> Host
+#define DoorBellSyncCmdAvailable	(1<<0)	/* Host -> Adapter */
+#define DoorBellPrintfDone		(1<<5)	/* Host -> Adapter */
+#define DoorBellAdapterNormCmdReady	(1<<1)	/* Adapter -> Host */
+#define DoorBellAdapterNormRespReady	(1<<2)	/* Adapter -> Host */
+#define DoorBellAdapterNormCmdNotFull	(1<<3)	/* Adapter -> Host */
+#define DoorBellAdapterNormRespNotFull	(1<<4)	/* Adapter -> Host */
+#define DoorBellPrintfReady		(1<<5)	/* Adapter -> Host */
 
 /*
  *	For FIB communication, we need all of the following things
@@ -1413,8 +1853,8 @@ extern struct aac_common aac_config;
  */
 
 struct aac_aifcmd {
-	u32 command;		/* Tell host what type of notify this is */
-	u32 seqnum;		/* To allow ordering of reports (if necessary) */
+	__le32 command;		/* Tell host what type of notify this is */
+	__le32 seqnum;		/* To allow ordering of reports (if necessary) */
 	u8 data[1];		/* Undefined length (from kernel viewpoint) */
 };
 
@@ -1423,9 +1863,17 @@ struct aac_aifcmd {
  *  	accounting for the fact capacity could be a 64 bit value
  *
  */
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+typedef unsigned long sector_t;
+
+#endif
 static inline u32 cap_to_cyls(sector_t capacity, u32 divisor)
 {
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
 	sector_div(capacity, divisor);
+#else
+	capacity /= divisor;
+#endif
 	return (u32)capacity;
 }
 
@@ -1437,27 +1885,44 @@ int fib_setup(struct aac_dev *dev);
 void fib_map_free(struct aac_dev *dev);
 void fib_free(struct fib * context);
 void fib_init(struct fib * context);
-void fib_dealloc(struct fib * context);
 void aac_printf(struct aac_dev *dev, u32 val);
-int fib_send(u16 command, struct fib * context, unsigned long size, int priority, int wait, int reply, fib_callback callback, void *ctxt);
+#if (defined(FSACTL_REGISTER_FIB_SEND))
+typedef int (*fib_send_t)(u16 command, struct fib * context, unsigned long size, int priority, int wait, int reply, fib_callback callback, void *ctxt);
+extern fib_send_t fib_send;
+#else
+#define aac_fib_send fib_send
+#endif
+int aac_fib_send(u16 command, struct fib * context, unsigned long size, int priority, int wait, int reply, fib_callback callback, void *ctxt);
 int aac_consumer_get(struct aac_dev * dev, struct aac_queue * q, struct aac_entry **entry);
-int aac_consumer_avail(struct aac_dev * dev, struct aac_queue * q);
 void aac_consumer_free(struct aac_dev * dev, struct aac_queue * q, u32 qnum);
 int fib_complete(struct fib * context);
 #define fib_data(fibctx) ((void *)(fibctx)->hw_fib->data)
 struct aac_dev *aac_init_adapter(struct aac_dev *dev);
+int aac_get_config_status(struct aac_dev *dev);
 int aac_get_containers(struct aac_dev *dev);
 int aac_scsi_cmd(struct scsi_cmnd *cmd);
 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg);
+#if (defined(AAC_CSMI))
+int aac_csmi_ioctl(struct aac_dev *dev, int cmd, void __user *arg);
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11))
+#if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) ? defined(__x86_64__) : defined(CONFIG_COMPAT))
+void aac_csmi_register_ioctl32_conversion(void);
+void aac_csmi_unregister_ioctl32_conversion(void);
+#endif
+#endif
+#endif
 int aac_do_ioctl(struct aac_dev * dev, int cmd, void __user *arg);
 int aac_rx_init(struct aac_dev *dev);
 int aac_rkt_init(struct aac_dev *dev);
 int aac_sa_init(struct aac_dev *dev);
 unsigned int aac_response_normal(struct aac_queue * q);
 unsigned int aac_command_normal(struct aac_queue * q);
+unsigned int aac_intr_normal(struct aac_dev * dev, u32 Index);
 int aac_command_thread(struct aac_dev * dev);
 int aac_close_fib_context(struct aac_dev * dev, struct aac_fib_context *fibctx);
+int aac_atoi(char ** str);
 int fib_adapter_complete(struct fib * fibptr, unsigned short size);
 struct aac_driver_ident* aac_get_driver_ident(int devtype);
+int probe_container(struct aac_dev *dev, int cid);
 int aac_get_adapter_info(struct aac_dev* dev);
 int aac_send_shutdown(struct aac_dev *dev);
--- linux-2.6.8.1-t043-libata-update/drivers/scsi/aacraid/fwdebug.c	1970-01-01 03:00:00.000000000 +0300
+++ aacraid-drv/drivers/scsi/aacraid/fwdebug.c	2005-01-13 17:19:21.000000000 +0300
@@ -0,0 +1,343 @@
+/*
+ *	Adaptec AAC series RAID controller driver
+ *
+ * Copyright (c) 2004 Adaptec, Inc. (aacraid@adaptec.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <stdarg.h>
+#include <linux/types.h>
+#include <linux/wait.h>
+#include <linux/spinlock.h>
+#include <asm/semaphore.h>
+#include <linux/kernel.h>
+#include <linux/blkdev.h>
+#include <linux/completion.h>
+#include <linux/string.h>
+#include <linux/sched.h>
+#include <linux/version.h>
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+#include <scsi/scsi.h>
+#include <scsi/scsi_cmnd.h>
+#include <scsi/scsi_host.h>
+#else
+#include "scsi.h"
+#include "hosts.h"
+#endif
+#include "aacraid.h"
+#include "fwdebug.h"
+
+/*
+ * Debug flags to be put into the HBA flags field when initialized
+ */
+const unsigned long aac_debug_flags = /* Variable to setup with above flags. */
+/*			HBA_FLAGS_DBG_KERNEL_PRINT_B |		*/
+			HBA_FLAGS_DBG_FW_PRINT_B |
+			HBA_FLAGS_DBG_FUNCTION_ENTRY_B |
+			HBA_FLAGS_DBG_FUNCTION_EXIT_B |
+			HBA_FLAGS_DBG_ERROR_B |
+/*			HBA_FLAGS_DBG_INIT_B |			*/
+/*			HBA_FLAGS_DBG_OS_COMMANDS_B |		*/
+/*			HBA_FLAGS_DBG_SCAN_B |			*/
+/*			HBA_FLAGS_DBG_COALESCE_B |		*/
+/*			HBA_FLAGS_DBG_IOCTL_COMMANDS_B |	*/
+/*			HBA_FLAGS_DBG_SYNC_COMMANDS_B |		*/
+/*			HBA_FLAGS_DBG_COMM_B |			*/
+/*			HBA_FLAGS_DBG_AIF_B |			*/
+/*			HBA_FLAGS_DBG_CSMI_COMMANDS_B | 	*/
+/*			HBA_FLAGS_DBG_FLAGS_MASK | 		*/
+0;
+
+int aac_get_fw_debug_buffer(struct aac_dev * dev)
+{
+if (nblank(fwprintf(x))) {
+	u32 MonDriverBufferPhysAddrLow = 0;
+	u32 MonDriverBufferPhysAddrHigh = 0;
+	u32 MonDriverBufferSize = 0;
+	u32 MonDriverHeaderSize = 0;
+	u32 ReturnStatus = 0;
+
+	/*
+	 * Initialize the firmware print buffer fields
+	 */
+	dev->FwDebugBuffer_P = NULL;
+	dev->FwDebugFlags_P = NULL;
+	dev->FwDebugStrLength_P = NULL;
+	dev->FwDebugBLEDvalue_P = NULL;
+	dev->FwDebugBLEDflag_P = NULL;
+	dev->FwDebugBufferSize = 0;
+	dev->FwDebugFlags = 0;
+	dev->DebugFlags = 0;
+
+	/*
+	 * Get the firmware print buffer parameters from the firmware
+	 * If the command was successful map in the address.
+	 */
+	if (!aac_adapter_sync_cmd(dev, GET_DRIVER_BUFFER_PROPERTIES,
+	  0, 0, 0, 0, 0, 0,
+	  &ReturnStatus,
+	  &MonDriverBufferPhysAddrLow,
+	  &MonDriverBufferPhysAddrHigh,
+	  &MonDriverBufferSize,
+	  &MonDriverHeaderSize) && MonDriverBufferSize) {
+		unsigned long Offset = MonDriverBufferPhysAddrLow
+		                     - (dev->scsi_host_ptr->base & 0xffffffff);
+
+		/*
+		 * See if the address is already mapped in and if so set it up
+		 * from the base address
+		 */
+		if (((u32)(((u64)dev->scsi_host_ptr->base) >> 32)
+		  == MonDriverBufferPhysAddrHigh)
+		 && ((Offset + MonDriverBufferSize) < dev->base_size))
+			dev->FwDebugBuffer_P
+			  = ((unsigned char *)dev->regs.sa + Offset);
+
+		/*
+		 * If mapping went well, Set up the debug buffer fields in the
+		 * HBA structure from the data returned
+		 */
+		if (dev->FwDebugBuffer_P != NULL) {
+			dev->FwDebugFlags_P
+			  = (u32 *)(dev->FwDebugBuffer_P
+			  + FW_DEBUG_FLAGS_OFFSET);
+			dev->FwDebugStrLength_P
+			  = (u32 *)(dev->FwDebugBuffer_P
+			  + FW_DEBUG_STR_LENGTH_OFFSET);
+			dev->FwDebugBLEDvalue_P
+			  = dev->FwDebugBuffer_P
+			  + FW_DEBUG_BLED_OFFSET;
+			dev->FwDebugBLEDflag_P
+			  = dev->FwDebugBLEDvalue_P + 1;
+			dev->FwDebugBufferSize = MonDriverBufferSize;
+			dev->FwDebugBuffer_P += MonDriverHeaderSize;
+			dev->FwDebugFlags = 0;
+			dev->DebugFlags = aac_debug_flags;
+			return 1;
+		}
+	}
+
+	/*
+	 * The GET_DRIVER_BUFFER_PROPERTIES command failed
+	 */
+}
+	return 0;
+}
+
+#define PRINT_TIMEOUT (HZ/4) /* 1/4 second */
+
+void aac_fw_printf(struct aac_dev * dev, unsigned long PrintFlags, const char * fmt, ...)
+{
+if (nblank(fwprintf(x))) {
+	va_list args;
+	u32 Count;
+	unsigned long next_jiffies;
+	char PrintBuffer_P[PRINT_BUFFER_SIZE];
+
+	if ((((PrintFlags
+	  & ~(HBA_FLAGS_DBG_KERNEL_PRINT_B|HBA_FLAGS_DBG_FW_PRINT_B)) != 0)
+	  && (dev != NULL)
+	  && ((dev->DebugFlags & PrintFlags) == 0))
+	 || ((dev != NULL) && (dev->DebugFlags
+	   & (HBA_FLAGS_DBG_KERNEL_PRINT_B|HBA_FLAGS_DBG_FW_PRINT_B)) == 0))
+		return;
+	/*
+	 * Set up parameters and call sprintf function to format the data
+	 */
+	va_start(args, fmt);
+	vsprintf(PrintBuffer_P, fmt, args);
+	va_end(args);
+
+	/*
+	 * Make sure the HBA structure has been passed in for this section
+	 */
+	if ((dev != NULL) && (dev->FwDebugBufferSize)) {
+		/*
+		 * If we are set up for a Firmware print
+		 */
+		if ((dev->DebugFlags & HBA_FLAGS_DBG_FW_PRINT_B)
+		 && ((PrintFlags
+		  & (HBA_FLAGS_DBG_KERNEL_PRINT_B|HBA_FLAGS_DBG_FW_PRINT_B))
+		  != HBA_FLAGS_DBG_KERNEL_PRINT_B)) {
+			/*
+			 * Make sure the string size is within boundaries
+			 */
+			Count = strlen(PrintBuffer_P);
+			if (Count > dev->FwDebugBufferSize)
+				Count = (u16)dev->FwDebugBufferSize;
+
+			/*
+			 * Wait for no more than PRINT_TIMEOUT for the previous
+			 * message length to clear (the handshake).
+			 */
+			next_jiffies = jiffies + PRINT_TIMEOUT;
+			while ((next_jiffies - jiffies) >= 0) {
+				if (!(*dev->FwDebugStrLength_P))
+					break;
+				schedule();
+			}
+
+			/*
+			 * If the Length is clear, copy over the message, the
+			 * flags, and the length. Make sure the length is the
+			 * last because that is the signal for the Firmware to
+			 * pick it up.
+			 */
+			if (!(*dev->FwDebugStrLength_P)) {
+				memcpy(dev->FwDebugBuffer_P,
+				  PrintBuffer_P, Count);
+				*dev->FwDebugFlags_P = cpu_to_le32(dev->FwDebugFlags);
+				*dev->FwDebugStrLength_P = cpu_to_le32(Count);
+			} else
+				dev->DebugFlags &= ~HBA_FLAGS_DBG_FW_PRINT_B;
+		}
+
+		/*
+		 * If the Kernel Debug Print flag is set, send it off to the
+		 * Kernel debugger
+		 */
+		if ((dev->DebugFlags & HBA_FLAGS_DBG_KERNEL_PRINT_B)
+		 && ((PrintFlags
+		  & (HBA_FLAGS_DBG_KERNEL_PRINT_B|HBA_FLAGS_DBG_FW_PRINT_B))
+		  != HBA_FLAGS_DBG_FW_PRINT_B)) {
+			if (dev->FwDebugFlags & FW_DEBUG_FLAGS_NO_HEADERS_B)
+				printk ("%s", PrintBuffer_P);
+			else
+				printk (KERN_INFO "%s: %s\n",
+				  dev->scsi_host_ptr->hostt->proc_name,
+				  PrintBuffer_P);
+		}
+	}
+
+	/*
+	 * No HBA structure passed in so it has to be for the Kernel Debugger
+	 */
+	else if ((PrintFlags
+	  & (HBA_FLAGS_DBG_KERNEL_PRINT_B|HBA_FLAGS_DBG_FW_PRINT_B))
+	  != HBA_FLAGS_DBG_FW_PRINT_B) {
+		if ((dev != NULL)
+		 && (dev->FwDebugFlags & FW_DEBUG_FLAGS_NO_HEADERS_B))
+			printk ("%s", PrintBuffer_P);
+		else if (dev != NULL)
+			printk (KERN_INFO "%s: %s\n",
+			  dev->scsi_host_ptr->hostt->proc_name,
+			  PrintBuffer_P);
+		else
+			printk(KERN_INFO "%s\n", PrintBuffer_P);
+	}
+}
+}
+
+void aac_fw_print_mem(struct aac_dev * dev, unsigned long PrintFlags, u8 * Addr, int Count)
+{
+if (nblank(fwprintf(x))) {
+	int Offset, i;
+	u32 DebugFlags = 0;
+	char Buffer[100];
+	char * LineBuffer_P;
+
+	/*
+	 * If we have an HBA structure, save off the flags and set the no
+	 * headers flag so we don't have garbage between our lines of data
+	 */
+	if (dev != NULL) {
+		DebugFlags = dev->FwDebugFlags;
+		dev->FwDebugFlags |= FW_DEBUG_FLAGS_NO_HEADERS_B;
+	}
+
+	Offset = 0;
+
+	/*
+	 * Loop through all the data
+	 */
+	while (Offset < Count) {
+		/*
+		 * We will format each line into a buffer and then print out
+		 * the entire line so set the pointer to the beginning of the
+		 * buffer
+		 */
+		LineBuffer_P = Buffer;
+
+		/*
+		 * Set up the address in HEX
+		 */
+		sprintf(LineBuffer_P, "\n%04x  ", Offset);
+		LineBuffer_P += 6;
+
+		/*
+		 * Set up 16 bytes in HEX format
+		 */
+		for (i = 0; i < 16; ++i) {
+			/*
+			 * If we are past the count of data bytes to output,
+			 * pad with blanks
+			 */
+			sprintf (LineBuffer_P,
+			  (((Offset + i) >= Count) ? "   " : "%02x "),
+			  Addr[Offset + i]);
+			LineBuffer_P += 3;
+
+			/*
+			 * At the mid point we will put in a divider
+			 */
+			if (i == 7) {
+				sprintf (LineBuffer_P, "- ");
+				LineBuffer_P += 2;
+			}
+		}
+		/*
+		 * Now do the same 16 bytes at the end of the line in ASCII
+		 * format
+		 */
+		sprintf (LineBuffer_P, "  ");
+		LineBuffer_P += 2;
+		for (i = 0; i < 16; ++i) {
+			/*
+			 * If all data processed, OUT-O-HERE
+			 */
+			if ((Offset + i) >= Count)
+				break;
+
+			/*
+			 * If this is a printable ASCII character, convert it
+			 */
+			sprintf (LineBuffer_P,
+			  (((Addr[Offset + i] > 0x1F)
+			   && (Addr[Offset + i] < 0x7F))
+				? "%c"
+				: "."), Addr[Offset + i]);
+
+			++LineBuffer_P;
+		}
+		/*
+		 * The line is now formatted, so print it out
+		 */
+		aac_fw_printf(dev, PrintFlags, "%s", Buffer);
+
+		/*
+		 * Bump the offset by 16 for the next line
+		 */
+		Offset += 16;
+
+	}
+
+	/*
+	 * Restore the saved off flags
+	 */
+	if (dev != NULL)
+		dev->FwDebugFlags = DebugFlags;
+}
+}
--- linux-2.6.8.1-t043-libata-update/drivers/scsi/aacraid/csmi.h	1970-01-01 03:00:00.000000000 +0300
+++ aacraid-drv/drivers/scsi/aacraid/csmi.h	2004-12-17 15:54:52.000000000 +0300
@@ -0,0 +1,402 @@
+/*
+ *	Adaptec AAC series RAID controller driver
+ *	(c) Copyright 2004 Adaptec, Inc
+ *
+ * Copyright (c) 2004 Adaptec, Inc. (aacraid@adaptec.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Module Name:
+ *   csmi.h
+ *
+ * Abstract: All CSMI IOCTL definitions are here
+ */
+
+/*
+ *	This file is based on the following CSMI revision
+ */
+#define	CSMI_MAJOR_REVISION	0
+#define	CSMI_MINOR_REVISION	82
+
+/*
+ *	IoctlHeader.ReturnCode
+ */
+#define	CSMI_SAS_STATUS_SUCCESS			0
+#define	CSMI_SAS_STATUS_FAILED			1
+#define	CSMI_SAS_STATUS_BAD_CNTL_CODE		2
+#define	CSMI_SAS_STATUS_INVALID_PARAMETER	3
+#define CSMI_SAS_PHY_INFO_NOT_CHANGEABLE	2000
+#define CSMI_SAS_NO_SATA_DEVICE			2009
+
+/*
+ *	Status.uStatus
+ */
+#define	CSMI_SAS_CNTLR_STATUS_GOOD	1
+#define	CSMI_SAS_CNTLR_STATUS_FAILED	2
+#define CSMI_SAS_CNTLR_STATUS_OFFLINE	3
+
+/*
+ *	Status.uOfflineReason
+ */
+#define CSMI_SAS_OFFLINE_REASON_NO_REASON	0
+
+/*
+ *	IoctlHeader.ControlCode
+ */
+#define CSMI_SAS_RAID_SET_OUT_OF_RANGE	1000
+
+/*
+ *	Parameters.uFlags
+ */
+#define	CSMI_SAS_STP_READ		0x00000001
+#define	CSMI_SAS_STP_DMA		0x00000020
+#define	CSMI_SAS_STP_DMA_QUEUED		0x00000080
+#define	CSMI_SAS_STP_RESET_DEVICE	0x00000200	
+
+/*
+ *	Status.bConnectionStatus
+ */
+#define	CSMI_SAS_OPEN_ACCEPT		0
+
+/*
+ *	Configuration.bIoBusType
+ */
+#define	CSMI_SAS_BUS_TYPE_PCI		3
+
+/*
+ *	Configuration.bControllerClass
+ */
+#define	CSMI_SAS_CNTLR_CLASS_HBA	5
+
+/*
+ *	Configuration.uControllerFlags
+ */
+#define	CSMI_SAS_CNTLR_SAS_HBA		0x00000001
+#define	CSMI_SAS_CNTLR_SAS_RAID		0x00000002
+#define	CSMI_SAS_CNTLR_SATA_HBA		0x00000004
+#define	CSMI_SAS_CNTLR_SATA_RAID	0x00000008
+
+/*
+ *	Configuration.usSlotNumber
+ */
+#define SLOT_NUMBER_UNKNOWN		0xFFFF
+
+/*
+ *	CSMI ioctl commands
+ */
+/* #define CSMI_ALL_SIGNATURE		"CSMIALL" */
+#define	CC_CSMI_SAS_GET_DRIVER_INFO	0xCC770001
+#define	CC_CSMI_SAS_GET_CNTLR_CONFIG	0xCC770002
+#define	CC_CSMI_SAS_GET_CNTLR_STATUS	0xCC770003
+#define	CC_CSMI_SAS_FIRMWARE_DOWNLOAD	0xCC770004
+
+/* #define CSMI_RAID_SIGNATURE		"CSMIARY" */
+#define	CC_CSMI_SAS_GET_RAID_INFO	0xCC77000A
+#define	CC_CSMI_SAS_GET_RAID_CONFIG	0xCC77000B
+
+/* #define CSMI_SAS_SIGNATURE		"CSMISAS" */
+#define	CC_CSMI_SAS_GET_PHY_INFO	0xCC770014
+#define	CC_CSMI_SAS_SET_PHY_INFO	0xCC770015
+#define	CC_CSMI_SAS_GET_LINK_ERRORS	0xCC770016
+#define	CC_CSMI_SAS_SSP_PASSTHRU	0xCC770017
+#define	CC_CSMI_SAS_SMP_PASSTHRU	0xCC770018
+#define	CC_CSMI_SAS_STP_PASSTHRU	0xCC770019
+#define CC_CSMI_SAS_GET_SATA_SIGNATURE	0xCC770020
+#define	CC_CSMI_SAS_GET_SCSI_ADDRESS	0xCC770021
+#define	CC_CSMI_SAS_GET_DEVICE_ADDRESS	0xCC770022
+#define	CC_CSMI_SAS_TASK_MANAGEMENT	0xCC770023
+#define	CC_CSMI_SAS_GET_CONNECTOR_INFO	0xCC770024
+
+/* #define CSMI_PHY_SIGNATURE		"CSMIPHY" */
+#define CC_CSMI_SAS_PHY_CONTROL		0xCC77003C
+
+typedef struct {
+	u32	IOControllerNumber;
+	u32	Length;
+	u32	ReturnCode;
+	u32	Timeout;
+	u16	Direction;
+#if (defined(CSMI_8_BYTE_ALIGNED))
+	u16	Reserved[3];
+#endif
+} IOCTL_HEADER;
+typedef IOCTL_HEADER *PIOCTL_HEADER;
+
+/* CC_CSMI_SAS_GET_DRIVER_INFO */
+
+typedef struct {
+	u8	szName[81];
+	u8	szDescription[81];
+	u16	usMajorRevision;
+	u16	usMinorRevision;
+	u16	usBuildRevision;
+	u16	usReleaseRevision;
+	u16	usCSMIMajorRevision;
+	u16	usCSMIMinorRevision;
+#if (defined(CSMI_8_BYTE_ALIGNED))
+	u16	usReserved;
+#endif
+} CSMI_SAS_DRIVER_INFO;
+
+typedef struct {
+	IOCTL_HEADER	IoctlHeader;
+	CSMI_SAS_DRIVER_INFO	Information;
+} CSMI_SAS_DRIVER_INFO_BUFFER;
+typedef CSMI_SAS_DRIVER_INFO_BUFFER * PCSMI_SAS_DRIVER_INFO_BUFFER;
+
+/* CC_CSMI_SAS_GET_CNTLR_CONFIG */
+
+typedef struct {
+	u8	bBusNumber;
+	u8	bDeviceNumber;
+	u8	bFunctionNumber;
+	u8	bReserved;
+} CSMI_SAS_PCI_BUS_ADDRESS;
+
+typedef union {
+	CSMI_SAS_PCI_BUS_ADDRESS	PciAddress;
+	u8	bReserved[32];
+} CSMI_SAS_IO_BUS_ADDRESS;
+
+typedef struct {
+	u32	uBaseIoAddress;
+#if (defined(CSMI_8_BYTE_ALIGNED))
+	u32	uReserved;
+#endif
+	struct {
+		u32	uLowPart;
+		u32	uHighPart;
+	} BaseMemoryAddress;
+	u32	uBoardID;
+	u16	usSlotNumber;
+	u8	bControllerClass;
+	u8	bIoBusType;
+	CSMI_SAS_IO_BUS_ADDRESS	BusAddress;
+	u8	szSerialNumber[81];
+#if (defined(CSMI_8_BYTE_ALIGNED))
+	u8	bReserve;
+#endif
+	u16	usMajorRevision;
+	u16	usMinorRevision;
+	u16	usBuildRevision;
+	u16	usReleaseRevision;
+	u16	usBIOSMajorRevision;
+	u16	usBIOSMinorRevision;
+	u16	usBIOSBuildRevision;
+	u16	usBIOSReleaseRevision;
+#if (defined(CSMI_8_BYTE_ALIGNED))
+	u16	usReserved;
+#endif
+	u32	uControllerFlags;
+	u16	usRromMajorRevision;
+	u16	usRromMinorRevision;
+	u16	usRromBuildRevision;
+	u16	usRromReleaseRevision;
+	u16	usRromBIOSMajorRevision;
+	u16	usRromBIOSMinorRevision;
+	u16	usRromBIOSBuildRevision;
+	u16	usRromBIOSReleaseRevision;
+	u8	bReserved[7];
+#if (defined(CSMI_8_BYTE_ALIGNED))
+	u8	bReserved1;
+#endif
+} CSMI_SAS_CNTLR_CONFIG;
+
+typedef struct {
+	IOCTL_HEADER	IoctlHeader;
+	CSMI_SAS_CNTLR_CONFIG	Configuration;
+} CSMI_SAS_CNTLR_CONFIG_BUFFER;
+typedef CSMI_SAS_CNTLR_CONFIG_BUFFER * PCSMI_SAS_CNTLR_CONFIG_BUFFER;
+
+/* CC_CSMI_SAS_GET_CNTLR_STATUS */
+
+typedef struct {
+	u32	uStatus;
+	u32	uOfflineReason;
+	u8	bReserved[28];
+#if (defined(CSMI_8_BYTE_ALIGNED))
+	u8	bReserved[4];
+#endif
+} CSMI_SAS_CNTLR_STATUS;
+
+typedef struct {
+	IOCTL_HEADER	IoctlHeader;
+	CSMI_SAS_CNTLR_STATUS	Status;
+} CSMI_SAS_CNTLR_STATUS_BUFFER;
+typedef CSMI_SAS_CNTLR_STATUS_BUFFER * PCSMI_SAS_CNTLR_STATUS_BUFFER;
+
+/* CC_CSMI_SAS_GET_SATA_SIGNATURE */
+
+typedef struct {
+	u8	pPhyIdentifier;
+	u8	bReserved[3];
+	u8	bSignatureFIS[20];
+} CSMI_SAS_SATA_SIGNATURE;
+
+typedef struct {
+	IOCTL_HEADER IoctlHeader;
+	CSMI_SAS_SATA_SIGNATURE Signature;
+} CSMI_SAS_SATA_SIGNATURE_BUFFER;
+typedef CSMI_SAS_SATA_SIGNATURE_BUFFER * PCSMI_SAS_SATA_SIGNATURE_BUFFER;
+
+/* CC_CSMI_SAS_GET_RAID_INFO */
+
+typedef struct {
+	u32	uNumRaidSets;
+	u32	uMaxDrivesPerSet;
+	u8	bReserved[92];
+#if (defined(CSMI_8_BYTE_ALIGNED))
+	u8	bReserved1[4];
+#endif
+} CSMI_SAS_RAID_INFO;
+
+typedef struct {
+	IOCTL_HEADER	IoctlHeader;
+	CSMI_SAS_RAID_INFO	Information;
+} CSMI_SAS_RAID_INFO_BUFFER;
+typedef CSMI_SAS_RAID_INFO_BUFFER * PCSMI_SAS_RAID_INFO_BUFFER;
+
+/* CC_CSMI_SAS_GET_RAID_CONFIG */
+
+typedef struct {
+	u8	bModel[40];
+	u8	bFirmware[8];
+	u8	bSerialNumber[40];
+	u8	bSASAddress[8];
+	u8	bSASLun[8];
+	u8	bDriveStatus;
+	u8	bDriveUsage;
+	u8	bReserved[30];
+} CSMI_SAS_RAID_DRIVES;
+
+typedef struct {
+	u32	uRaidSetIndex;
+	u32	uCapacity;
+	u32	uStripeSize;
+	u8	bRaidType;
+	u8	bStatus;
+	u8	bInformation;
+	u8	bDriveCount;
+	u8	bReserved[20];
+#if (defined(CSMI_8_BYTE_ALIGNED))
+	u8	bReserved1[4];
+#endif
+	CSMI_SAS_RAID_DRIVES	Drives[1];
+} CSMI_SAS_RAID_CONFIG;
+
+typedef struct {
+	IOCTL_HEADER IoctlHeader;
+	CSMI_SAS_RAID_CONFIG Configuration;
+} CSMI_SAS_RAID_CONFIG_BUFFER;
+typedef CSMI_SAS_RAID_CONFIG_BUFFER * PCSMI_SAS_RAID_CONFIG_BUFFER;
+
+/* CC_CSMI_SAS_GET_PHY_INFO */
+
+typedef struct {
+	u8	bDeviceType;
+	u8	bRestricted;
+	u8	bInitiatorPortProtocol;
+	u8	bTargetPortProtocol;
+	u8	bRestricted2[8];
+	u8	bSASAddress[8];
+	u8	bPhyIdentifier;
+	u8	bSignalClass;
+	u8	bReserved[6];
+#if (defined(CSMI_8_BYTE_ALIGNED))
+	u8	bReserved1[4];
+#endif
+} CSMI_SAS_IDENTIFY;
+
+typedef struct {
+	CSMI_SAS_IDENTIFY	Identify;
+	u8	bPortIdentifier;
+	u8	bNegotiatedLinkRate;
+	u8	bMinimumLinkRate;
+	u8	bMaximumLinkRate;
+	u8	bPhyChangeCount;
+	u8	bAutoDiscover;
+	u8	bReserved[2];
+	CSMI_SAS_IDENTIFY	Attached;
+} CSMI_SAS_PHY_ENTITY;
+
+typedef struct {
+	u8	bNumberofPhys;
+	u8	bReserved[3];
+#if (defined(CSMI_8_BYTE_ALIGNED))
+	u8	bReserved1[4];
+#endif
+	CSMI_SAS_PHY_ENTITY Phy[32];
+} CSMI_SAS_PHY_INFO;
+
+typedef struct {
+	IOCTL_HEADER IoctlHeader;
+	CSMI_SAS_PHY_INFO Information;
+} CSMI_SAS_PHY_INFO_BUFFER;
+typedef CSMI_SAS_PHY_INFO_BUFFER * PCSMI_SAS_PHY_INFO_BUFFER;
+
+/* CC_CSMI_SAS_SET_PHY_INFO */
+
+typedef struct {
+	u8	bPhyIdentifier;
+	u8	bNegotiatedLinkRate;
+	u8	bProgrammedMinimumLinkRate;
+	u8	bProgrammedMaximumLinkRate;
+	u8	bSignalClass;
+	u8	bReserved[3];
+} CSMI_SAS_SET_PHY_INFO;
+
+typedef struct {
+	IOCTL_HEADER IoctlHeader;
+	CSMI_SAS_SET_PHY_INFO Information;
+} CSMI_SAS_SET_PHY_INFO_BUFFER;
+typedef CSMI_SAS_SET_PHY_INFO_BUFFER * PCSMI_SAS_SET_PHY_INFO_BUFFER;
+
+/* CC_CSMI_SAS_STP_PASSTHRU */
+
+typedef struct {
+	u8	bPhyIdentifier;
+	u8	bPortIdentifier;
+	u8	bConnectionRate;
+	u8	bReserved;
+	u8	bDestinationSASAddress[8];
+	u8	bReserved2[4];
+	u8	bCommandFIS[20];
+	u32	uFlags;
+	u32	uDataLength;
+#if (defined(CSMI_8_BYTE_ALIGNED))
+	u32	uReserved;
+#endif
+} CSMI_SAS_STP_PASSTHRU;
+
+typedef struct {
+	u8	bConnectionStatus;
+	u8	bReserved[3];
+	u8	bStatusFIS[20];
+	u32	uSCR[16];
+	u32	uDataBytes;
+#if (defined(CSMI_8_BYTE_ALIGNED))
+	u32	uReserved;
+#endif
+} CSMI_SAS_STP_PASSTHRU_STATUS;
+
+typedef struct {
+	IOCTL_HEADER	IoctlHeader;
+	CSMI_SAS_STP_PASSTHRU	Parameters;
+	CSMI_SAS_STP_PASSTHRU_STATUS	Status;
+	u8	bDataBuffer[1];
+} CSMI_SAS_STP_PASSTHRU_BUFFER;
+typedef CSMI_SAS_STP_PASSTHRU_BUFFER * PCSMI_SAS_STP_PASSTHRU_BUFFER;
+
+int aac_csmi_ioctl(struct aac_dev *, int, void __user *);
--- linux-2.6.8.1-t043-libata-update/drivers/scsi/aacraid/dpcsup.c	2005-09-26 13:33:12.000000000 +0400
+++ aacraid-drv/drivers/scsi/aacraid/dpcsup.c	2005-04-27 16:46:03.000000000 +0400
@@ -39,6 +39,7 @@
 #include <linux/completion.h>
 #include <linux/blkdev.h>
 #include <asm/semaphore.h>
+#include <linux/version.h>
 
 #include "aacraid.h"
 
@@ -73,7 +74,7 @@ unsigned int aac_response_normal(struct 
 		int fast;
 		u32 index = le32_to_cpu(entry->addr);
 		fast = index & 0x01;
-		fib = &dev->fibs[index >> 1];
+		fib = &dev->fibs[index >> 2];
 		hwfib = fib->hw_fib;
 		
 		aac_consumer_free(dev, q, HostNormRespQueue);
@@ -99,7 +100,7 @@ unsigned int aac_response_normal(struct 
 			/*
 			 *	Doctor the fib
 			 */
-			*(u32 *)hwfib->data = cpu_to_le32(ST_OK);
+			*(__le32 *)hwfib->data = cpu_to_le32(ST_OK);
 			hwfib->header.XferState |= cpu_to_le32(AdapterProcessed);
 		}
 
@@ -134,8 +135,12 @@ unsigned int aac_response_normal(struct 
 		spin_lock_irqsave(q->lock, flags);
 	}
 
-	if (consumed > aac_config.peak_fibs)
+	if (consumed > aac_config.peak_fibs) {
 		aac_config.peak_fibs = consumed;
+#if (defined(AAC_DEBUG_INSTRUMENT_AAC_CONFIG))
+		printk("peak_fibs=%d\n", aac_config.peak_fibs);
+#endif
+	}
 	if (consumed == 0) 
 		aac_config.zero_fibs++;
 
@@ -174,17 +179,27 @@ unsigned int aac_command_normal(struct a
 		u32 index;
 		struct fib *fib = &fibctx;
 		
-		index = le32_to_cpu(entry->addr) / sizeof(struct hw_fib);
-		hw_fib = &dev->aif_base_va[index];
-		
 		/*
-		 *	Allocate a FIB at all costs. For non queued stuff
+		 *	Allocate a FIB. For non queued stuff
 		 *	we can just use the stack so we are happy. We need
 		 *	a fib object in order to manage the linked lists
 		 */
-		if (dev->aif_thread)
-			if((fib = kmalloc(sizeof(struct fib), GFP_ATOMIC)) == NULL)
+		if (dev->aif_thread) {
+			/* Limit the number we retreive from fib pool */
+			struct list_head * each;
+			int i = (le32_to_cpu(dev->init->AdapterFibsSize) / sizeof(struct hw_fib)) - 1;
+			list_for_each(each, &(q->cmdq))
+				if (--i <= 0)
+					break;
+			if ((i <= 0) || (!(fib = kmalloc(sizeof(struct fib),GFP_ATOMIC))))
 				fib = &fibctx;
+		}
+		index = le32_to_cpu(entry->addr) / sizeof(struct hw_fib);
+#if 0
+		printk(KERN_INFO "index=%d or %d\n", index,
+		  le32_to_cpu(entry->addr / sizeof(struct hw_fib)));
+#endif
+		hw_fib = &dev->aif_base_va[index];
 		
 		memset(fib, 0, sizeof(struct fib));
 		INIT_LIST_HEAD(&fib->fiblink);
@@ -205,7 +220,7 @@ unsigned int aac_command_normal(struct a
 			/*
 			 *	Set the status of this FIB
 			 */
-			*(u32 *)hw_fib->data = cpu_to_le32(ST_OK);
+			*(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
 			fib_adapter_complete(fib, sizeof(u32));
 			spin_lock_irqsave(q->lock, flags);
 		}		
@@ -213,3 +228,139 @@ unsigned int aac_command_normal(struct a
 	spin_unlock_irqrestore(q->lock, flags);
 	return 0;
 }
+
+
+/**
+ *	aac_intr_normal	-	Handle command replies
+ *	@dev: Device
+ *	@index: completion reference
+ *
+ *	This DPC routine will be run when the adapter interrupts us to let us
+ *	know there is a response on our normal priority queue. We will pull off
+ *	all QE there are and wake up all the waiters before exiting.
+ */
+
+unsigned int aac_intr_normal(struct aac_dev * dev, u32 Index)
+{
+	u32 index = le32_to_cpu(Index);
+
+	dprintk((KERN_INFO "aac_intr_normal(%p,%x)\n", dev, Index));
+	if ((index & 0x00000002L)) {
+		struct hw_fib * hw_fib;
+		struct fib * fib;
+		struct aac_queue *q = &dev->queues->queue[HostNormCmdQueue];
+		unsigned long flags;
+
+		if (index == 0xFFFFFFFEL) /* Special Case */
+			return 0;	  /* Do nothing */
+		/*
+		 *	Allocate a FIB. For non queued stuff we can just use
+		 * the stack so we are happy. We need a fib object in order to
+		 * manage the linked lists.
+		 */
+		if ((!dev->aif_thread)
+		 || (!(fib = kmalloc(sizeof(struct fib),GFP_ATOMIC))))
+			return 1;
+		if (!(hw_fib = kmalloc(sizeof(struct hw_fib),GFP_ATOMIC))) {
+			kfree (fib);
+			return 1;
+		}
+		memset(hw_fib, 0, sizeof(struct hw_fib));
+		memcpy(hw_fib, (struct hw_fib *)(((char *)(dev->regs.sa)) + (index & ~0x00000002L)), sizeof(struct hw_fib));
+		memset(fib, 0, sizeof(struct fib));
+		INIT_LIST_HEAD(&fib->fiblink);
+		fib->type = FSAFS_NTC_FIB_CONTEXT;
+		fib->size = sizeof(struct fib);
+		fib->hw_fib = hw_fib;
+		fib->data = hw_fib->data;
+		fib->dev = dev;
+	
+		spin_lock_irqsave(q->lock, flags);
+		list_add_tail(&fib->fiblink, &q->cmdq);
+	        wake_up_interruptible(&q->cmdready);
+		spin_unlock_irqrestore(q->lock, flags);
+		return 1;
+	} else {
+		int fast = index & 0x01;
+		struct fib * fib = &dev->fibs[index >> 2];
+		struct hw_fib * hwfib = fib->hw_fib;
+
+		/*
+		 *	Remove this fib from the Outstanding I/O queue.
+		 *	But only if it has not already been timed out.
+		 *
+		 *	If the fib has been timed out already, then just 
+		 *	continue. The caller has already been notified that
+		 *	the fib timed out.
+		 */
+		if ((fib->flags & FIB_CONTEXT_FLAG_TIMED_OUT)) {
+			printk(KERN_WARNING "aacraid: FIB timeout (%x).\n", fib->flags);
+			printk(KERN_DEBUG"aacraid: hwfib=%p index=%i fib=%p\n",hwfib, hwfib->header.SenderData,fib);
+			return 0;
+		}
+
+#if 0
+		if (fib->queue.prev == NULL)
+			printk(KERN_WARNING
+			  "aacraid: empty fib %d list prev\n", index >> 1);
+#if (defined(LIST_POISON2))
+		else if (fib->queue.prev == LIST_POISON2)
+			printk(KERN_WARNING
+			  "aacraid: poison fib %d list prev\n", index >> 1);
+#endif
+		if (fib->queue.next == NULL)
+			printk(KERN_WARNING
+			  "aacraid: empty fib %d list next\n", index >> 1);
+#if (defined(LIST_POISON1))
+		else if (fib->queue.next == LIST_POISON1)
+			printk(KERN_WARNING
+			  "aacraid: poison fib %d list next\n", index >> 1);
+#endif
+		else if ((fib->queue.prev != NULL)
+#if (defined(LIST_POISON2))
+		 && (fib->queue.prev != LIST_POISON2)
+#endif
+		)
+#endif
+		list_del(&fib->queue);
+		dev->queues->queue[AdapNormCmdQueue].numpending--;
+
+		if (fast) {
+			/*
+			 *	Doctor the fib
+			 */
+			*(__le32 *)hwfib->data = cpu_to_le32(ST_OK);
+			hwfib->header.XferState |= cpu_to_le32(AdapterProcessed);
+		}
+
+		FIB_COUNTER_INCREMENT(aac_config.FibRecved);
+
+		if (hwfib->header.Command == cpu_to_le16(NuFileSystem))
+		{
+			u32 *pstatus = (u32 *)hwfib->data;
+			if (*pstatus & cpu_to_le32(0xffff0000))
+				*pstatus = cpu_to_le32(ST_OK);
+		}
+		if (hwfib->header.XferState & cpu_to_le32(NoResponseExpected | Async)) 
+		{
+	        	if (hwfib->header.XferState & cpu_to_le32(NoResponseExpected))
+				FIB_COUNTER_INCREMENT(aac_config.NoResponseRecved);
+			else 
+				FIB_COUNTER_INCREMENT(aac_config.AsyncRecved);
+			/*
+			 *	NOTE:  we cannot touch the fib after this
+			 *	    call, because it may have been deallocated.
+			 */
+			fib->callback(fib->callback_data, fib);
+		} else {
+			unsigned long flagv;
+	  		dprintk((KERN_INFO "event_wait up\n"));
+			spin_lock_irqsave(&fib->event_lock, flagv);
+			fib->done = 1;
+			up(&fib->event_wait);
+			spin_unlock_irqrestore(&fib->event_lock, flagv);
+			FIB_COUNTER_INCREMENT(aac_config.NormalRecved);
+		}
+		return 0;
+	}
+}
--- linux-2.6.8.1-t043-libata-update/drivers/scsi/aacraid/Makefile	2005-09-26 13:33:12.000000000 +0400
+++ aacraid-drv/drivers/scsi/aacraid/Makefile	2005-04-21 15:27:23.000000000 +0400
@@ -1,8 +1,114 @@
 # Adaptec aacraid
 
+AAC_FLAGS := $(shell if [ ! -d ${TOPDIR}/drivers/scsi/aacraid ] ; then \
+	echo --error_Please_build_this_driver_in_the_Linux_Kernel_tree ; \
+fi)
+AAC_FLAGS += $(shell if [ -s ${TOPDIR}/drivers/scsi/hosts.h ] ; then \
+	if grep vary_io ${TOPDIR}/drivers/scsi/hosts.h >/dev/null 2>/dev/null ; then \
+		echo -DSCSI_HAS_VARY_IO ; \
+	fi ; \
+fi)
+AAC_FLAGS += $(shell if [ -s ${TOPDIR}/include/linux/delay.h ] ; then \
+	if grep ssleep ${TOPDIR}/include/linux/delay.h >/dev/null 2>/dev/null ; then \
+		echo -DSCSI_HAS_SSLEEP ; \
+	fi ; \
+fi)
+AAC_FLAGS += $(shell if [ -s ${TOPDIR}/include/scsi/scsi_device.h ] ; then \
+	if grep scsi_device_online ${TOPDIR}/include/scsi/scsi_device.h >/dev/null 2>/dev/null ; then \
+		echo -DSCSI_HAS_SCSI_DEVICE_ONLINE ; \
+	fi ; \
+fi)
+AAC_FLAGS += $(shell if [ -s ${TOPDIR}/include/scsi/scsi_host.h ] ; then \
+	if grep dump_poll ${TOPDIR}/include/scsi/scsi_host.h >/dev/null 2>/dev/null ; then \
+		echo -DSCSI_HAS_DUMP ; \
+	fi ; \
+fi)
+AAC_FLAGS += $(shell if [ -s ${TOPDIR}/include/scsi/scsi_host.h ] ; then \
+	if grep dump_sanity_check ${TOPDIR}/include/scsi/scsi_host.h >/dev/null 2>/dev/null ; then \
+		echo -DSCSI_HAS_DUMP_SANITY_CHECK ; \
+	fi ; \
+fi)
+AAC_FLAGS += $(shell if [ -s ${TOPDIR}/include/linux/types.h ] ; then \
+	if grep __bitwise ${TOPDIR}/include/linux/types.h >/dev/null 2>/dev/null ; then \
+		echo -DHAS_BITWISE_TYPE ; \
+	fi ; \
+fi)
+
+ifeq (${VERSION},2) # 2.x.x
+
+ifeq (${PATCHLEVEL},2) # 2.2.x
+
+CFILES_DRIVER=linit.c aachba.c commctrl.c comminit.c commsup.c \
+	dpcsup.c rx.c sa.c rkt.c fwdebug.c csmi.c
+
+IFILES_DRIVER=aacraid.h compat.h
+
+ALL_SOURCE=${CFILES_DRIVER} ${IFILES_DRIVER} 
+
+TARGET_OFILES=${CFILES_DRIVER:.c=.o}
+
+ifndef GCCVERSION
+GCCVERSION=2.96
+endif
+
+GCCMACHINE:=$(shell ls -d /usr/lib/gcc-lib/*/${GCCVERSION} | sed -n 1s@/${GCCVERSION}@@p)
+
+INCS=-I. -I.. -I../../../include -I/usr/src/linux/include -I/usr/src/linux/drivers/scsi 
+INCS=-nostdinc -I${GCCMACHINE}/${GCCVERSION}/include -I. -I..
+
+WARNINGS= -w -Wall -Wno-unused -Wno-switch -Wno-missing-prototypes -Wno-implicit
+
+COMMON_FLAGS=\
+	-D__KERNEL__=1 -DUNIX -DCVLOCK_USE_SPINLOCK -DLINUX \
+	-Wall -Wstrict-prototypes \
+	${INCS} \
+	${WARNINGS} \
+	-O2 -fomit-frame-pointer
+
+AACFLAGS=${COMMON_FLAGS} ${CFLAGS} ${EXTRA_FLAGS} ${AAC_FLAGS}
+COMPILE.c=${CC} ${AACFLAGS} ${TARGET_ARCH} -c
+
+.SUFFIXES:
+.SUFFIXES: .c .o .h .a
+
+all: source ${TARGET_OFILES} aacraid.o
+
+modules: all
+
+source: ${ALL_SOURCE}
+
+clean:
+	rm *.o
+
+aacraid.o: source ${TARGET_OFILES}
+	ld -r -o $@ $(TARGET_OFILES)
+	cp -r aacraid.o ../
+
+endif # 2.2.x
+
+ifeq (${PATCHLEVEL},4) # 2.4.x
+
+EXTRA_CFLAGS	+= -I$(TOPDIR)/drivers/scsi ${EXTRA_FLAGS} ${AAC_FLAGS}
+
+O_TARGET	:= aacraid.o
+obj-m		:= $(O_TARGET)
+
+obj-y		:= linit.o aachba.o commctrl.o comminit.o commsup.o \
+		   dpcsup.o rx.o sa.o rkt.o fwdebug.o csmi.o
+
+include $(TOPDIR)/Rules.make
+
+endif # 2.4.x
+
+ifeq (${PATCHLEVEL},6) # 2.6.x
+
 obj-$(CONFIG_SCSI_AACRAID) := aacraid.o
 
 aacraid-objs	:= linit.o aachba.o commctrl.o comminit.o commsup.o \
-		   dpcsup.o rx.o sa.o rkt.o
+		   dpcsup.o rx.o sa.o rkt.o fwdebug.o csmi.o
+
+EXTRA_CFLAGS	:= -Idrivers/scsi ${EXTRA_FLAGS} ${AAC_FLAGS}
+
+endif # 2.6.x
 
-EXTRA_CFLAGS	:= -Idrivers/scsi
+endif # 2.x.x
--- linux-2.6.8.1-t043-libata-update/drivers/scsi/aacraid/rkt.c	2005-09-26 13:33:12.000000000 +0400
+++ aacraid-drv/drivers/scsi/aacraid/rkt.c	2005-04-27 16:47:24.000000000 +0400
@@ -40,111 +40,91 @@
 #include <linux/completion.h>
 #include <linux/time.h>
 #include <linux/interrupt.h>
+#include <linux/version.h>	/* Needed for the following */
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,23))
+#if (!defined(IRQ_NONE))
+  typedef void irqreturn_t;
+# define IRQ_HANDLED
+# define IRQ_NONE
+#endif
+#endif
 #include <asm/semaphore.h>
 
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
+#include "scsi.h"
+#include "hosts.h"
+#else
 #include <scsi/scsi_host.h>
+#endif
 
 #include "aacraid.h"
 
 static irqreturn_t aac_rkt_intr(int irq, void *dev_id, struct pt_regs *regs)
 {
 	struct aac_dev *dev = dev_id;
-	unsigned long bellbits;
-	u8 intstat, mask;
-	intstat = rkt_readb(dev, MUnit.OISR);
-	/*
-	 *	Read mask and invert because drawbridge is reversed.
-	 *	This allows us to only service interrupts that have 
-	 *	been enabled.
-	 */
-	mask = ~(dev->OIMR);
-	/* Check to see if this is our interrupt.  If it isn't just return */
-	if (intstat & mask) 
-	{
-		bellbits = rkt_readl(dev, OutboundDoorbellReg);
-		if (bellbits & DoorBellPrintfReady) {
-			aac_printf(dev, le32_to_cpu(rkt_readl (dev, IndexRegs.Mailbox[5])));
-			rkt_writel(dev, MUnit.ODR,DoorBellPrintfReady);
-			rkt_writel(dev, InboundDoorbellReg,DoorBellPrintfDone);
-		}
-		else if (bellbits & DoorBellAdapterNormCmdReady) {
-			rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdReady);
-			aac_command_normal(&dev->queues->queue[HostNormCmdQueue]);
-		}
-		else if (bellbits & DoorBellAdapterNormRespReady) {
-			aac_response_normal(&dev->queues->queue[HostNormRespQueue]);
-			rkt_writel(dev, MUnit.ODR,DoorBellAdapterNormRespReady);
-		}
-		else if (bellbits & DoorBellAdapterNormCmdNotFull) {
-			rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull);
+
+	if (dev->new_comm_interface) {
+		u32 Index = rkt_readl(dev, MUnit.OutboundQueue);
+		if (Index == 0xFFFFFFFFL)
+			Index = rkt_readl(dev, MUnit.OutboundQueue);
+		if (Index != 0xFFFFFFFFL) {
+			do {
+				if (aac_intr_normal(dev, Index)) {
+					rkt_writel(dev, MUnit.OutboundQueue, Index);
+					rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormRespReady);
+				}
+				Index = rkt_readl(dev, MUnit.OutboundQueue);
+			} while (Index != 0xFFFFFFFFL);
+			return IRQ_HANDLED;
 		}
-		else if (bellbits & DoorBellAdapterNormRespNotFull) {
-			rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull);
-			rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormRespNotFull);
+	} else {
+		unsigned long bellbits;
+		u8 intstat;
+		intstat = rkt_readb(dev, MUnit.OISR);
+		/*
+		 *	Read mask and invert because drawbridge is reversed.
+		 *	This allows us to only service interrupts that have 
+		 *	been enabled.
+		 *	Check to see if this is our interrupt.  If it isn't just return
+		 */
+		if (intstat & ~(dev->OIMR))
+		{
+			bellbits = rkt_readl(dev, OutboundDoorbellReg);
+			if (bellbits & DoorBellPrintfReady) {
+				aac_printf(dev, rkt_readl (dev, IndexRegs.Mailbox[5]));
+				rkt_writel(dev, MUnit.ODR,DoorBellPrintfReady);
+				rkt_writel(dev, InboundDoorbellReg,DoorBellPrintfDone);
+			}
+			else if (bellbits & DoorBellAdapterNormCmdReady) {
+				rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdReady);
+				aac_command_normal(&dev->queues->queue[HostNormCmdQueue]);
+//				rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdReady);
+			}
+			else if (bellbits & DoorBellAdapterNormRespReady) {
+				rkt_writel(dev, MUnit.ODR,DoorBellAdapterNormRespReady);
+				aac_response_normal(&dev->queues->queue[HostNormRespQueue]);
+			}
+			else if (bellbits & DoorBellAdapterNormCmdNotFull) {
+				rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull);
+			}
+			else if (bellbits & DoorBellAdapterNormRespNotFull) {
+				rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull);
+				rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormRespNotFull);
+			}
+			return IRQ_HANDLED;
 		}
-		return IRQ_HANDLED;
 	}
 	return IRQ_NONE;
 }
 
 /**
- *	aac_rkt_enable_interrupt	-	Enable event reporting
+ *	aac_rkt_disable_interrupt	-	Disable interrupts
  *	@dev: Adapter
- *	@event: Event to enable
- *
- *	Enable event reporting from the i960 for a given event.
  */
- 
-static void aac_rkt_enable_interrupt(struct aac_dev * dev, u32 event)
-{
-	switch (event) {
-
-	case HostNormCmdQue:
-		dev->irq_mask &= ~(OUTBOUNDDOORBELL_1);
-		break;
-
-	case HostNormRespQue:
-		dev->irq_mask &= ~(OUTBOUNDDOORBELL_2);
-		break;
 
-	case AdapNormCmdNotFull:
-		dev->irq_mask &= ~(OUTBOUNDDOORBELL_3);
-		break;
-
-	case AdapNormRespNotFull:
-		dev->irq_mask &= ~(OUTBOUNDDOORBELL_4);
-		break;
-	}
-}
-
-/**
- *	aac_rkt_disable_interrupt	-	Disable event reporting
- *	@dev: Adapter
- *	@event: Event to enable
- *
- *	Disable event reporting from the i960 for a given event.
- */
-
-static void aac_rkt_disable_interrupt(struct aac_dev *dev, u32 event)
+static void aac_rkt_disable_interrupt(struct aac_dev *dev)
 {
-	switch (event) {
-
-	case HostNormCmdQue:
-		dev->irq_mask |= (OUTBOUNDDOORBELL_1);
-		break;
-
-	case HostNormRespQue:
-		dev->irq_mask |= (OUTBOUNDDOORBELL_2);
-		break;
-
-	case AdapNormCmdNotFull:
-		dev->irq_mask |= (OUTBOUNDDOORBELL_3);
-		break;
-
-	case AdapNormRespNotFull:
-		dev->irq_mask |= (OUTBOUNDDOORBELL_4);
-		break;
-	}
+	rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
 }
 
 /**
@@ -154,25 +134,31 @@ static void aac_rkt_disable_interrupt(st
  *	@p1: first parameter
  *	@ret: adapter status
  *
- *	This routine will send a synchronous comamnd to the adapter and wait 
+ *	This routine will send a synchronous command to the adapter and wait 
  *	for its	completion.
  */
 
-static int rkt_sync_cmd(struct aac_dev *dev, u32 command, u32 p1, u32 *status)
+static int rkt_sync_cmd(struct aac_dev *dev, u32 command,
+	u32 p1, u32 p2, u32 p3, u32 p4, u32 p5, u32 p6,
+	u32 *status, u32 *r1, u32 *r2, u32 *r3, u32 *r4)
 {
 	unsigned long start;
 	int ok;
 	/*
 	 *	Write the command into Mailbox 0
 	 */
-	rkt_writel(dev, InboundMailbox0, cpu_to_le32(command));
+	rkt_writel(dev, InboundMailbox0, command);
 	/*
-	 *	Write the parameters into Mailboxes 1 - 4
+	 *	Write the parameters into Mailboxes 1 - 6
 	 */
-	rkt_writel(dev, InboundMailbox1, cpu_to_le32(p1));
-	rkt_writel(dev, InboundMailbox2, 0);
-	rkt_writel(dev, InboundMailbox3, 0);
-	rkt_writel(dev, InboundMailbox4, 0);
+	rkt_writel(dev, InboundMailbox1, p1);
+	rkt_writel(dev, InboundMailbox2, p2);
+	rkt_writel(dev, InboundMailbox3, p3);
+	rkt_writel(dev, InboundMailbox4, p4);
+#if (defined(AAC_LM_SENSOR))
+	rkt_writel(dev, InboundMailbox5, p5);
+	rkt_writel(dev, InboundMailbox6, p6);
+#endif
 	/*
 	 *	Clear the synch command doorbell to start on a clean slate.
 	 */
@@ -180,7 +166,7 @@ static int rkt_sync_cmd(struct aac_dev *
 	/*
 	 *	Disable doorbell interrupts
 	 */
-	rkt_writeb(dev, MUnit.OIMR, dev->OIMR |= 0x04);
+	rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
 	/*
 	 *	Force the completion of the mask register write before issuing
 	 *	the interrupt.
@@ -221,13 +207,25 @@ static int rkt_sync_cmd(struct aac_dev *
 		/*
 		 *	Restore interrupt mask even though we timed out
 		 */
-		rkt_writeb(dev, MUnit.OIMR, dev->OIMR &= 0xfb);
+		if (dev->new_comm_interface)
+			rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xf7);
+		else
+			rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
 		return -ETIMEDOUT;
 	}
 	/*
 	 *	Pull the synch status from Mailbox 0.
 	 */
-	*status = le32_to_cpu(rkt_readl(dev, IndexRegs.Mailbox[0]));
+	if (status)
+		*status = rkt_readl(dev, IndexRegs.Mailbox[0]);
+	if (r1)
+		*r1 = rkt_readl(dev, IndexRegs.Mailbox[1]);
+	if (r2)
+		*r2 = rkt_readl(dev, IndexRegs.Mailbox[2]);
+	if (r3)
+		*r3 = rkt_readl(dev, IndexRegs.Mailbox[3]);
+	if (r4)
+		*r4 = rkt_readl(dev, IndexRegs.Mailbox[4]);
 	/*
 	 *	Clear the synch command doorbell.
 	 */
@@ -235,7 +233,10 @@ static int rkt_sync_cmd(struct aac_dev *
 	/*
 	 *	Restore interrupt mask
 	 */
-	rkt_writeb(dev, MUnit.OIMR, dev->OIMR &= 0xfb);
+	if (dev->new_comm_interface)
+		rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xf7);
+	else
+		rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
 	return 0;
 
 }
@@ -249,8 +250,8 @@ static int rkt_sync_cmd(struct aac_dev *
 
 static void aac_rkt_interrupt_adapter(struct aac_dev *dev)
 {
-	u32 ret;
-	rkt_sync_cmd(dev, BREAKPOINT_REQUEST, 0, &ret);
+	rkt_sync_cmd(dev, BREAKPOINT_REQUEST, 0, 0, 0, 0, 0, 0,
+	  NULL, NULL, NULL, NULL, NULL);
 }
 
 /**
@@ -279,7 +280,8 @@ static void aac_rkt_notify_adapter(struc
 		rkt_writel(dev, MUnit.IDR,INBOUNDDOORBELL_3);
 		break;
 	case HostShutdown:
-//		rkt_sync_cmd(dev, HOST_CRASHING, 0, 0, 0, 0, &ret);
+//		rkt_sync_cmd(dev, HOST_CRASHING, 0, 0, 0, 0, 0, 0,
+//		  NULL, NULL, NULL, NULL, NULL);
 		break;
 	case FastIo:
 		rkt_writel(dev, MUnit.IDR,INBOUNDDOORBELL_6);
@@ -302,27 +304,13 @@ static void aac_rkt_notify_adapter(struc
 
 static void aac_rkt_start_adapter(struct aac_dev *dev)
 {
-	u32 status;
 	struct aac_init *init;
 
 	init = dev->init;
 	init->HostElapsedSeconds = cpu_to_le32(get_seconds());
-	/*
-	 *	Tell the adapter we are back and up and running so it will scan
-	 *	its command queues and enable our interrupts
-	 */
-	dev->irq_mask = (DoorBellPrintfReady | OUTBOUNDDOORBELL_1 | OUTBOUNDDOORBELL_2 | OUTBOUNDDOORBELL_3 | OUTBOUNDDOORBELL_4);
-	/*
-	 *	First clear out all interrupts.  Then enable the one's that we
-	 *	can handle.
-	 */
-	rkt_writeb(dev, MUnit.OIMR, 0xff);
-	rkt_writel(dev, MUnit.ODR, 0xffffffff);
-//	rkt_writeb(dev, MUnit.OIMR, ~(u8)OUTBOUND_DOORBELL_INTERRUPT_MASK);
-	rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
-
 	// We can only use a 32 bit address here
-	rkt_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS, (u32)(ulong)dev->init_pa, &status);
+	rkt_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS, (u32)(ulong)dev->init_pa,
+	  0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL);
 }
 
 /**
@@ -334,7 +322,7 @@ static void aac_rkt_start_adapter(struct
  */
 static int aac_rkt_check_health(struct aac_dev *dev)
 {
-	long status = rkt_readl(dev, IndexRegs.Mailbox[7]);
+	u32 status = rkt_readl(dev, MUnit.OMRx[0]);
 
 	/*
 	 *	Check to see if the board failed any self tests.
@@ -344,34 +332,43 @@ static int aac_rkt_check_health(struct a
 	/*
 	 *	Check to see if the board panic'd.
 	 */
-	if (status & KERNEL_PANIC)
-	{
-		char * buffer = kmalloc(512, GFP_KERNEL|__GFP_DMA);
+	if (status & KERNEL_PANIC) {
+		char * buffer;
 		struct POSTSTATUS {
-			u32 Post_Command;
-			u32 Post_Address;
-		} * post = kmalloc(sizeof(struct POSTSTATUS), GFP_KERNEL);
-		dma_addr_t paddr = pci_map_single(dev->pdev, post, sizeof(struct POSTSTATUS), 2);
-		dma_addr_t baddr = pci_map_single(dev->pdev, buffer, 512, 1);
-		u32 status = -1;
-		int ret = -2;
-		
-		memset(buffer, 0, 512);
-		post->Post_Command = cpu_to_le32(COMMAND_POST_RESULTS);
-		post->Post_Address = cpu_to_le32(baddr);
-		rkt_writel(dev, MUnit.IMRx[0], cpu_to_le32(paddr));
-		rkt_sync_cmd(dev, COMMAND_POST_RESULTS, baddr, &status);
-		pci_unmap_single(dev->pdev, paddr, sizeof(struct POSTSTATUS),2);
-		kfree(post);
-		if ((buffer[0] == '0') && (buffer[1] == 'x')) {
-			ret = (buffer[2] <= '9') ? (buffer[2] - '0') : (buffer[2] - 'A' + 10);
-			ret <<= 4;
-			ret += (buffer[3] <= '9') ? (buffer[3] - '0') : (buffer[3] - 'A' + 10);
+			__le32 Post_Command;
+			__le32 Post_Address;
+		} * post;
+		dma_addr_t paddr, baddr;
+		int ret;
+
+		if ((status & 0xFF000000L) == 0xBC000000L)
+			return (status >> 16) & 0xFF;
+		buffer = pci_alloc_consistent(dev->pdev, 512, &baddr);
+		ret = -2;
+		if (buffer == NULL)
+			return ret;
+		post = pci_alloc_consistent(dev->pdev,
+		  sizeof(struct POSTSTATUS), &paddr);
+		if (post == NULL) {
+			pci_free_consistent(dev->pdev, 512, buffer, baddr);
+			return ret;
 		}
-		pci_unmap_single(dev->pdev, baddr, 512, 1);
-		kfree(buffer);
-		return ret;
-	}
+                memset(buffer, 0, 512);
+		post->Post_Command = cpu_to_le32(COMMAND_POST_RESULTS);
+                post->Post_Address = cpu_to_le32(baddr);
+                rkt_writel(dev, MUnit.IMRx[0], paddr);
+                rkt_sync_cmd(dev, COMMAND_POST_RESULTS, baddr, 0, 0, 0, 0, 0,
+		  NULL, NULL, NULL, NULL, NULL);
+		pci_free_consistent(dev->pdev, sizeof(struct POSTSTATUS),
+		  post, paddr);
+                if ((buffer[0] == '0') && (buffer[1] == 'x')) {
+                        ret = (buffer[2] <= '9') ? (buffer[2] - '0') : (buffer[2] - 'A' + 10);
+                        ret <<= 4;
+                        ret += (buffer[3] <= '9') ? (buffer[3] - '0') : (buffer[3] - 'A' + 10);
+                }
+		pci_free_consistent(dev->pdev, 512, buffer, baddr);
+                return ret;
+        }
 	/*
 	 *	Wait for the adapter to be up and running.
 	 */
@@ -384,6 +381,39 @@ static int aac_rkt_check_health(struct a
 }
 
 /**
+ *	aac_rkt_send
+ *	@fib: fib to issue
+ *
+ *	Will send a fib, returning 0 if successful.
+ */
+static int aac_rkt_send(struct fib * fib)
+{
+	u64 addr = fib->hw_fib_pa;
+	struct aac_dev *dev = fib->dev;
+	u32 * device = (u32 *)(dev->regs.rkt);
+	u32 Index;
+
+	dprintk((KERN_DEBUG "%p->aac_rkt_send(%p->%llx)\n", dev, fib, addr));
+	Index = rkt_readl(dev, MUnit.InboundQueue);
+	if (Index == 0xFFFFFFFFL)
+		Index = rkt_readl(dev, MUnit.InboundQueue);
+	dprintk((KERN_DEBUG "Index = 0x%x\n", Index));
+	if (Index == 0xFFFFFFFFL)
+		return Index;
+	device += Index / sizeof(u32);
+	dprintk((KERN_DEBUG "entry = %x %x %u\n", (u32)(addr & 0xffffffff),
+	  (u32)(addr >> 32), (u32)le16_to_cpu(fib->hw_fib->header.Size)));
+	writel((u32)(addr & 0xffffffff), device);
+	++device;
+	writel((u32)(addr >> 32), device);
+	++device;
+	writel(le16_to_cpu(fib->hw_fib->header.Size), device);
+	rkt_writel(dev, MUnit.InboundQueue, Index);
+	dprintk((KERN_DEBUG "aac_rkt_send - return 0\n"));
+	return 0;
+}
+
+/**
  *	aac_rkt_init	-	initialize an i960 based AAC card
  *	@dev: device to configure
  *
@@ -403,14 +433,6 @@ int aac_rkt_init(struct aac_dev *dev)
 	name     = dev->name;
 
 	/*
-	 *	Map in the registers from the adapter.
-	 */
-	if((dev->regs.rkt = (struct rkt_registers *)ioremap((unsigned long)dev->scsi_host_ptr->base, 8192))==NULL)
-	{	
-		printk(KERN_WARNING "aacraid: unable to map i960.\n" );
-		goto error_iounmap;
-	}
-	/*
 	 *	Check to see if the board failed any self tests.
 	 */
 	if (rkt_readl(dev, MUnit.OMRx[0]) & SELF_TEST_FAILED) {
@@ -435,12 +457,13 @@ int aac_rkt_init(struct aac_dev *dev)
 	/*
 	 *	Wait for the adapter to be up and running. Wait up to 3 minutes
 	 */
-	while (!(rkt_readl(dev, MUnit.OMRx[0]) & KERNEL_UP_AND_RUNNING))
+	while (!(rkt_readl(dev, MUnit.OMRx[0]) & KERNEL_UP_AND_RUNNING)) 
 	{
 		if(time_after(jiffies, start+180*HZ))
 		{
-			status = rkt_readl(dev, IndexRegs.Mailbox[7]) >> 16;
-			printk(KERN_ERR "%s%d: adapter kernel failed to start, init status = %ld.\n", dev->name, instance, status);
+			status = rkt_readl(dev, MUnit.OMRx[0]);
+			printk(KERN_ERR "%s%d: adapter kernel failed to start, init status = %lx.\n", 
+					dev->name, instance, status);
 			goto error_iounmap;
 		}
 		set_current_state(TASK_UNINTERRUPTIBLE);
@@ -455,14 +478,43 @@ int aac_rkt_init(struct aac_dev *dev)
 	 *	Fill in the function dispatch table.
 	 */
 	dev->a_ops.adapter_interrupt = aac_rkt_interrupt_adapter;
-	dev->a_ops.adapter_enable_int = aac_rkt_enable_interrupt;
 	dev->a_ops.adapter_disable_int = aac_rkt_disable_interrupt;
 	dev->a_ops.adapter_notify = aac_rkt_notify_adapter;
 	dev->a_ops.adapter_sync_cmd = rkt_sync_cmd;
 	dev->a_ops.adapter_check_health = aac_rkt_check_health;
+	dev->a_ops.adapter_send = aac_rkt_send;
+#if (defined(SCSI_HAS_DUMP))
+	dev->a_ops.adapter_intr = aac_rkt_intr;
+#endif
+
+	/*
+	 *	First clear out all interrupts.  Then enable the one's that we
+	 *	can handle.
+	 */
+	rkt_writeb(dev, MUnit.OIMR, 0xff);
+	rkt_writel(dev, MUnit.ODR, 0xffffffff);
+	rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
 
 	if (aac_init_adapter(dev) == NULL)
 		goto error_irq;
+	if (dev->new_comm_interface) {
+		/*
+		 * FIB Setup has already been done, but we can minimize the
+		 * damage by at least ensuring the OS never issues more
+		 * commands than we can handle. The Rocket adapters currently
+		 * can only handle 246 commands and 8 AIFs at the same time,
+		 * and in fact do notify us accordingly if we negotiate the
+		 * FIB size. The problem that causes us to add this check is
+		 * to ensure that we do not overdo it with the adapter when a
+		 * hard coded FIB override is being utilized. This special
+		 * case warrants this half baked, but convenient, check here.
+		 */
+		if (dev->scsi_host_ptr->can_queue > (246 - AAC_NUM_MGT_FIB)) {
+			dev->init->MaxIoCommands = cpu_to_le32(246);
+			dev->scsi_host_ptr->can_queue = 246 - AAC_NUM_MGT_FIB;
+		}
+		rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xf7);
+	}
 	/*
 	 *	Start any kernel threads needed
 	 */
@@ -483,10 +535,10 @@ error_kfree:
 	kfree(dev->queues);
 
 error_irq:
+	rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
 	free_irq(dev->scsi_host_ptr->irq, (void *)dev);
 
 error_iounmap:
-	iounmap(dev->regs.rkt);
 
 	return -1;
 }
--- linux-2.6.8.1-t043-libata-update/drivers/scsi/aacraid/dkms.conf	1970-01-01 03:00:00.000000000 +0300
+++ aacraid-drv/drivers/scsi/aacraid/dkms.conf	2005-05-13 19:59:51.000000000 +0400
@@ -0,0 +1,11 @@
+PACKAGE_VERSION="1.1.5.2400"
+
+# Items below here should not have to change with each driver version
+PACKAGE_NAME="aacraid"
+MAKE[0]="make -C ${kernel_source_dir} SUBDIRS=${dkms_tree}/${PACKAGE_NAME}/${PACKAGE_VERSION}/build modules"
+CLEAN="make -C ${kernel_source_dir} SUBDIRS=${dkms_tree}/${PACKAGE_NAME}/${PACKAGE_VERSION}/build clean"
+BUILT_MODULE_NAME[0]="aacraid"
+DEST_MODULE_LOCATION[0]="/kernel/drivers/scsi/aacraid/"
+REMAKE_INITRD="yes"
+MODULES_CONF_ALIAS_TYPE="scsi_hostadapter"
+MODULES_CONF_OBSOLETES_ONLY[0]="aacraid"
--- linux-2.6.8.1-t043-libata-update/drivers/scsi/aacraid/README	2005-09-26 13:33:12.000000000 +0400
+++ aacraid-drv/drivers/scsi/aacraid/README	2005-04-21 00:11:43.000000000 +0400
@@ -10,14 +10,24 @@ the original).
 
 Supported Cards/Chipsets
 -------------------------
-	AAR-2410SA SATA
+	Adaptec 2020S
+	Adaptec 2025S
 	Adaptec 2120S
+	Adaptec 2130S
 	Adaptec 2200S
 	Adaptec 2230S
+	Adaptec 2240S
+	Adaptec 2410SA
+	Adaptec 2610SA
+	Adaptec 2810SA
+	Adaptec 21610SA
 	Adaptec 3230S
 	Adaptec 3240S
+	Adaptec 4000SAS
+	Adaptec 4005SAS
+	Adaptec 4800SAS
+	Adaptec 4805SAS
 	Adaptec 5400S
-	ASR-2020S PCI-X
 	Dell PERC 2 Quad Channel
 	Dell PERC 2/Si
 	Dell PERC 3/Si
@@ -26,6 +36,13 @@ Supported Cards/Chipsets
 	HP NetRAID-4M
 	Legend S220
 	Legend S230
+	IBM ServeRAID 8i
+	ICP 9014R0
+	ICP 9024R0
+	ICP 9047MA
+	ICP 9087MA
+	ICP 9085LI
+	ICP 5085AU
 
 People
 -------------------------
@@ -33,7 +50,7 @@ Alan Cox <alan@redhat.com>
 Christoph Hellwig <hch@infradead.org>	(updates for new-style PCI probing and SCSI host registration,
 					 small cleanups/fixes)
 Matt Domsch <matt_domsch@dell.com>	(revision ioctl, adapter messages)
-Deanna Bonds <deanna_bonds@adaptec.com> (non-DASD support, PAE fibs and 64 bit, added new adaptec controllers
+Deanna Bonds                            (non-DASD support, PAE fibs and 64 bit, added new adaptec controllers
 					 added new ioctls, changed scsi interface to use new error handler,
 					 increased the number of fibs and outstanding commands to a container)
 
@@ -49,7 +66,6 @@ Adaptec Unix OEM Product Group
 Mailing List
 -------------------------
 linux-scsi@vger.kernel.org (Interested parties troll here)
-http://mbserver.adaptec.com/ (Currently more Community Support than Devel Support)
 Also note this is very different to Brian's original driver
 so don't expect him to support it.
 Adaptec does support this driver.  Contact either tech support or Mark Salyzyn.
--- linux-2.6.8.1-t043-libata-update/drivers/scsi/aacraid/linit.c	2005-09-26 13:33:12.000000000 +0400
+++ aacraid-drv/drivers/scsi/aacraid/linit.c	2005-05-04 21:02:24.000000000 +0400
@@ -27,25 +27,59 @@
  * Abstract: Linux Driver entry module for Adaptec RAID Array Controller
  */
 
-#define AAC_DRIVER_VERSION		"1.1.2-lk2"
-#define AAC_DRIVER_BUILD_DATE		__DATE__
+#define AAC_DRIVER_VERSION		"1.1-5"
+#define AAC_DRIVER_BUILD_DATE		__DATE__ " " __TIME__
 #define AAC_DRIVERNAME			"aacraid"
 
+#if (defined(AAC_DRIVER_BUILD))
+#define _str(x) #x
+#define str(x) _str(x)
+#if (defined(AAC_DRIVER_BRANCH))
+#define AAC_DRIVER_FULL_VERSION	AAC_DRIVER_VERSION "[" str(AAC_DRIVER_BUILD) "]" AAC_DRIVER_BRANCH
+#else
+#define AAC_DRIVER_FULL_VERSION	AAC_DRIVER_VERSION "[" str(AAC_DRIVER_BUILD) "]"
+#endif
+#else
+#if (defined(AAC_DRIVER_BRANCH))
+#define AAC_DRIVER_FULL_VERSION	AAC_DRIVER_VERSION AAC_DRIVER_BRANCH " " AAC_DRIVER_BUILD_DATE
+#else
+#define AAC_DRIVER_FULL_VERSION	AAC_DRIVER_VERSION " " AAC_DRIVER_BUILD_DATE
+#endif
+#endif
+
+#include <linux/version.h> /* for the following test */
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,3))
 #include <linux/compat.h>
+#endif
 #include <linux/blkdev.h>
 #include <linux/completion.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,3))
 #include <linux/moduleparam.h>
+#else
+#include <linux/config.h>
+#include <linux/types.h>
+#include <linux/sched.h>
+#endif
 #include <linux/pci.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,3))
 #include <linux/syscalls.h>
 #include <linux/ioctl32.h>
+#endif
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,9)) || defined(SCSI_HAS_SSLEEP)
+#include <linux/delay.h>
+#endif
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+#include <linux/dma-mapping.h>
+#endif
 #include <asm/semaphore.h>
 
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
 #include <scsi/scsi.h>
 #include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_device.h>
@@ -53,28 +87,49 @@
 #include <scsi/scsi_tcq.h>
 #include <scsi/scsicam.h>
 #include <scsi/scsi_eh.h>
+#else
+#include "scsi.h"
+#include "hosts.h"
+#include "sd.h"
+#include <linux/blk.h>	/* for io_request_lock definition */
+#endif
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11))
+#if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) ? defined(__x86_64__) : defined(CONFIG_COMPAT))
+#if ((KERNEL_VERSION(2,4,19) <= LINUX_VERSION_CODE) && (LINUX_VERSION_CODE <= KERNEL_VERSION(2,4,21)))
+# include <asm-x86_64/ioctl32.h>
+#elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+# include <asm/ioctl32.h>
+#elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,3))
+# include <linux/ioctl32.h>
+#endif
+  /* Cast the function, since sys_ioctl does not match */
+# define aac_ioctl32(x,y) register_ioctl32_conversion((x), \
+    (int(*)(unsigned int,unsigned int,unsigned long,struct file*))(y))
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+# include <asm/uaccess.h>
+#endif
+#endif
+#endif
+#include <linux/reboot.h>
 
 #include "aacraid.h"
+#include "fwdebug.h"
 
 
 MODULE_AUTHOR("Red Hat Inc and Adaptec");
 MODULE_DESCRIPTION("Dell PERC2, 2/Si, 3/Si, 3/Di, "
 		   "Adaptec Advanced Raid Products, "
 		   "and HP NetRAID-4M SCSI driver");
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,4,7))
 MODULE_LICENSE("GPL");
+#endif
+#if ((LINUX_VERSION_CODE > KERNEL_VERSION(2,6,3)) || defined(MODULE_VERSION))
+MODULE_VERSION(AAC_DRIVER_FULL_VERSION);
+#endif
 
-
-int nondasd = -1;
-module_param(nondasd, int, S_IRUGO|S_IWUSR);
-MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices. 0=off, 1=on");
-
-int paemode = -1;
-module_param(paemode, int, S_IRUGO|S_IWUSR);
-MODULE_PARM_DESC(paemode, "Control whether dma addressing is using PAE. 0=off, 1=on");
-
-struct aac_dev *aac_devices[MAXIMUM_NUM_ADAPTERS];
-static unsigned aac_count;
+LIST_HEAD(aac_devices);
 static int aac_cfg_major = -1;
+char aac_driver_version[] = AAC_DRIVER_FULL_VERSION;
 
 /*
  * Because of the way Linux names scsi devices, the order in this table has
@@ -83,44 +138,69 @@ static int aac_cfg_major = -1;
  * Note: The last field is used to index into aac_drivers below.
  */
 static struct pci_device_id aac_pci_tbl[] = {
-	{ 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si */
-	{ 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di */
-	{ 0x1028, 0x0003, 0x1028, 0x0003, 0, 0, 2 }, /* PERC 3/Si */
-	{ 0x1028, 0x0004, 0x1028, 0x00d0, 0, 0, 3 }, /* PERC 3/Si */
-	{ 0x1028, 0x0002, 0x1028, 0x00d1, 0, 0, 4 }, /* PERC 3/Di */
-	{ 0x1028, 0x0002, 0x1028, 0x00d9, 0, 0, 5 }, /* PERC 3/Di */
-	{ 0x1028, 0x000a, 0x1028, 0x0106, 0, 0, 6 }, /* PERC 3/Di */
-	{ 0x1028, 0x000a, 0x1028, 0x011b, 0, 0, 7 }, /* PERC 3/Di */
-	{ 0x1028, 0x000a, 0x1028, 0x0121, 0, 0, 8 }, /* PERC 3/Di */
-	{ 0x9005, 0x0283, 0x9005, 0x0283, 0, 0, 9 }, /* catapult*/
-	{ 0x9005, 0x0284, 0x9005, 0x0284, 0, 0, 10 }, /* tomcat*/
-	{ 0x9005, 0x0285, 0x9005, 0x0286, 0, 0, 11 }, /* Adaptec 2120S (Crusader)*/
-	{ 0x9005, 0x0285, 0x9005, 0x0285, 0, 0, 12 }, /* Adaptec 2200S (Vulcan)*/
-	{ 0x9005, 0x0285, 0x9005, 0x0287, 0, 0, 13 }, /* Adaptec 2200S (Vulcan-2m)*/
-	{ 0x9005, 0x0285, 0x17aa, 0x0286, 0, 0, 14 }, /* Legend S220*/
-	{ 0x9005, 0x0285, 0x17aa, 0x0287, 0, 0, 15 }, /* Legend S230*/
-
-	{ 0x9005, 0x0285, 0x9005, 0x0288, 0, 0, 16 }, /* Adaptec 3230S (Harrier)*/
-	{ 0x9005, 0x0285, 0x9005, 0x0289, 0, 0, 17 }, /* Adaptec 3240S (Tornado)*/
-	{ 0x9005, 0x0285, 0x9005, 0x028a, 0, 0, 18 }, /* ASR-2020 ZCR PCI-X U320 */
-	{ 0x9005, 0x0285, 0x9005, 0x028b, 0, 0, 19 }, /* ASR-2025 ZCR DIMM U320 */
-	{ 0x9005, 0x0285, 0x9005, 0x0290, 0, 0, 20 }, /* AAR-2410SA PCI SATA 4ch (Jaguar II)*/
-
-	{ 0x9005, 0x0285, 0x1028, 0x0287, 0, 0, 21 }, /* Perc 320/DC*/
-	{ 0x1011, 0x0046, 0x9005, 0x0365, 0, 0, 22 }, /* Adaptec 5400S (Mustang)*/
-	{ 0x1011, 0x0046, 0x9005, 0x0364, 0, 0, 23 }, /* Adaptec 5400S (Mustang)*/
-	{ 0x1011, 0x0046, 0x9005, 0x1364, 0, 0, 24 }, /* Dell PERC2 "Quad Channel" */
-	{ 0x1011, 0x0046, 0x103c, 0x10c2, 0, 0, 25 }, /* HP NetRAID-4M */
-
-	{ 0x9005, 0x0285, 0x1028, 0x0291, 0, 0, 26 }, /* CERC SATA RAID 2 PCI SATA 6ch (DellCorsair) */
-	{ 0x9005, 0x0285, 0x9005, 0x0292, 0, 0, 27 }, /* AAR-2810SA PCI SATA 8ch (Corsair-8) */
-	{ 0x9005, 0x0285, 0x9005, 0x0293, 0, 0, 28 }, /* AAR-21610SA PCI SATA 16ch (Corsair-16) */
-	{ 0x9005, 0x0285, 0x9005, 0x0294, 0, 0, 29 }, /* ESD SO-DIMM PCI-X SATA ZCR (Prowler) */
-	{ 0x9005, 0x0285, 0x0E11, 0x0295, 0, 0, 30 }, /* SATA 6Ch (Bearcat) */
-
-	{ 0x9005, 0x0286, 0x9005, 0x028c, 0, 0, 31 }, /* ASR-2230S + ASR-2230SLP PCI-X (Lancer) */
-	{ 0x9005, 0x0285, 0x9005, 0x028e, 0, 0, 32 }, /* ASR-2020SA      (ZCR PCI-X SATA) */
-	{ 0x9005, 0x0285, 0x9005, 0x028f, 0, 0, 33 }, /* ASR-2025SA      (ZCR DIMM SATA) */
+	{ 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
+	{ 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
+	{ 0x1028, 0x0003, 0x1028, 0x0003, 0, 0, 2 }, /* PERC 3/Si (SlimFast/PERC3Si */
+	{ 0x1028, 0x0004, 0x1028, 0x00d0, 0, 0, 3 }, /* PERC 3/Di (Iguana FlipChip/PERC3DiF */
+	{ 0x1028, 0x0002, 0x1028, 0x00d1, 0, 0, 4 }, /* PERC 3/Di (Viper/PERC3DiV) */
+	{ 0x1028, 0x0002, 0x1028, 0x00d9, 0, 0, 5 }, /* PERC 3/Di (Lexus/PERC3DiL) */
+	{ 0x1028, 0x000a, 0x1028, 0x0106, 0, 0, 6 }, /* PERC 3/Di (Jaguar/PERC3DiJ) */
+	{ 0x1028, 0x000a, 0x1028, 0x011b, 0, 0, 7 }, /* PERC 3/Di (Dagger/PERC3DiD) */
+	{ 0x1028, 0x000a, 0x1028, 0x0121, 0, 0, 8 }, /* PERC 3/Di (Boxster/PERC3DiB) */
+	{ 0x9005, 0x0283, 0x9005, 0x0283, 0, 0, 9 }, /* catapult */
+	{ 0x9005, 0x0284, 0x9005, 0x0284, 0, 0, 10 }, /* tomcat */
+	{ 0x9005, 0x0285, 0x9005, 0x0286, 0, 0, 11 }, /* Adaptec 2120S (Crusader) */
+	{ 0x9005, 0x0285, 0x9005, 0x0285, 0, 0, 12 }, /* Adaptec 2200S (Vulcan) */
+	{ 0x9005, 0x0285, 0x9005, 0x0287, 0, 0, 13 }, /* Adaptec 2200S (Vulcan-2m) */
+	{ 0x9005, 0x0285, 0x17aa, 0x0286, 0, 0, 14 }, /* Legend S220 (Legend Crusader) */
+	{ 0x9005, 0x0285, 0x17aa, 0x0287, 0, 0, 15 }, /* Legend S230 (Legend Vulcan) */
+
+	{ 0x9005, 0x0285, 0x9005, 0x0288, 0, 0, 16 }, /* Adaptec 3230S (Harrier) */
+	{ 0x9005, 0x0285, 0x9005, 0x0289, 0, 0, 17 }, /* Adaptec 3240S (Tornado) */
+	{ 0x9005, 0x0285, 0x9005, 0x028a, 0, 0, 18 }, /* ASR-2020ZCR SCSI PCI-X ZCR (Skyhawk) */
+	{ 0x9005, 0x0285, 0x9005, 0x028b, 0, 0, 19 }, /* ASR-2025ZCR SCSI SO-DIMM PCI-X ZCR (Terminator) */
+	{ 0x9005, 0x0286, 0x9005, 0x028c, 0, 0, 20 }, /* ASR-2230S + ASR-2230SLP PCI-X (Lancer) */
+	{ 0x9005, 0x0286, 0x9005, 0x028d, 0, 0, 21 }, /* ASR-2130S (Lancer) */
+	{ 0x9005, 0x0286, 0x9005, 0x029b, 0, 0, 22 }, /* AAR-2820SA (Intruder) */
+	{ 0x9005, 0x0286, 0x9005, 0x029c, 0, 0, 23 }, /* AAR-2620SA (Intruder) */
+	{ 0x9005, 0x0286, 0x9005, 0x029d, 0, 0, 24 }, /* AAR-2420SA (Intruder) */
+	{ 0x9005, 0x0286, 0x9005, 0x029e, 0, 0, 25 }, /* ICP9024R0 (Lancer) */
+	{ 0x9005, 0x0286, 0x9005, 0x029f, 0, 0, 26 }, /* ICP9014R0 (Lancer) */
+	{ 0x9005, 0x0286, 0x9005, 0x02a0, 0, 0, 27 }, /* ICP9047MA (Lancer) */
+	{ 0x9005, 0x0286, 0x9005, 0x02a1, 0, 0, 28 }, /* ICP9087MA (Lancer) */
+	{ 0x9005, 0x0286, 0x9005, 0x02a3, 0, 0, 29 }, /* ICP5085AU (Hurricane) */
+	{ 0x9005, 0x0285, 0x9005, 0x02a4, 0, 0, 30 }, /* ICP9085LI (Marauder-X) */
+	{ 0x9005, 0x0285, 0x9005, 0x02a5, 0, 0, 31 }, /* ICP5085BR (Marauder-E) */
+	{ 0x9005, 0x0287, 0x9005, 0x0800, 0, 0, 32 }, /* Themisto Jupiter Platform */
+	{ 0x9005, 0x0200, 0x9005, 0x0200, 0, 0, 32 }, /* Themisto Jupiter Platform */
+	{ 0x9005, 0x0286, 0x9005, 0x0800, 0, 0, 33 }, /* Callisto Jupiter Platform */
+	{ 0x9005, 0x0285, 0x9005, 0x028e, 0, 0, 34 }, /* ASR-2020SA SATA PCI-X ZCR (Skyhawk) */
+	{ 0x9005, 0x0285, 0x9005, 0x028f, 0, 0, 35 }, /* ASR-2025SA SATA SO-DIMM PCI-X ZCR (Terminator) */
+	{ 0x9005, 0x0285, 0x9005, 0x0290, 0, 0, 36 }, /* AAR-2410SA PCI SATA 4ch (Jaguar II) */
+	{ 0x9005, 0x0285, 0x1028, 0x0291, 0, 0, 37 }, /* CERC SATA RAID 2 PCI SATA 6ch (DellCorsair) */
+	{ 0x9005, 0x0285, 0x9005, 0x0292, 0, 0, 38 }, /* AAR-2810SA PCI SATA 8ch (Corsair-8) */
+	{ 0x9005, 0x0285, 0x9005, 0x0293, 0, 0, 39 }, /* AAR-21610SA PCI SATA 16ch (Corsair-16) */
+	{ 0x9005, 0x0285, 0x9005, 0x0294, 0, 0, 40 }, /* ESD SO-DIMM PCI-X SATA ZCR (Prowler) */
+	{ 0x9005, 0x0285, 0x103C, 0x3227, 0, 0, 41 }, /* AAR-2610SA PCI SATA 6ch */
+	{ 0x9005, 0x0285, 0x9005, 0x0296, 0, 0, 42 }, /* ASR-2240S (SabreExpress) */
+	{ 0x9005, 0x0285, 0x9005, 0x0297, 0, 0, 43 }, /* ASR-4005SAS */
+	{ 0x9005, 0x0285, 0x1014, 0x02F2, 0, 0, 44 }, /* IBM 8i (AvonPark) */
+	{ 0x9005, 0x0285, 0x1014, 0x0312, 0, 0, 44 }, /* IBM 8i (AvonPark Lite) */
+	{ 0x9005, 0x0285, 0x9005, 0x0298, 0, 0, 45 }, /* ASR-4000SAS (BlackBird) */
+	{ 0x9005, 0x0285, 0x9005, 0x0299, 0, 0, 46 }, /* ASR-4800SAS (Marauder-X) */
+	{ 0x9005, 0x0285, 0x9005, 0x029a, 0, 0, 47 }, /* ASR-4805SAS (Marauder-E) */
+	{ 0x9005, 0x0286, 0x9005, 0x02a2, 0, 0, 48 }, /* ASR-4810SAS (Hurricane */
+
+	{ 0x9005, 0x0285, 0x1028, 0x0287, 0, 0, 49 }, /* Perc 320/DC*/
+	{ 0x1011, 0x0046, 0x9005, 0x0365, 0, 0, 50 }, /* Adaptec 5400S (Mustang)*/
+	{ 0x1011, 0x0046, 0x9005, 0x0364, 0, 0, 51 }, /* Adaptec 5400S (Mustang)*/
+	{ 0x1011, 0x0046, 0x9005, 0x1364, 0, 0, 52 }, /* Dell PERC2/QC */
+	{ 0x1011, 0x0046, 0x103c, 0x10c2, 0, 0, 53 }, /* HP NetRAID-4M */
+
+	{ 0x9005, 0x0285, 0x1028, PCI_ANY_ID, 0, 0, 54 }, /* Dell Catchall */
+	{ 0x9005, 0x0285, 0x17aa, PCI_ANY_ID, 0, 0, 55 }, /* Legend Catchall */
+	{ 0x9005, 0x0285, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 56 }, /* Adaptec Catch All */
+	{ 0x9005, 0x0286, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 57 }, /* Adaptec Rocket Catch All */
 	{ 0,}
 };
 MODULE_DEVICE_TABLE(pci, aac_pci_tbl);
@@ -131,53 +211,91 @@ MODULE_DEVICE_TABLE(pci, aac_pci_tbl);
  * for the card.  At that time we can remove the channels from here
  */
 static struct aac_driver_ident aac_drivers[] = {
-	{ aac_rx_init, "percraid", "DELL    ", "PERCRAID        ", 2, AAC_QUIRK_31BIT }, /* PERC 2/Si */
-	{ aac_rx_init, "percraid", "DELL    ", "PERCRAID        ", 2, AAC_QUIRK_31BIT }, /* PERC 3/Di */
-	{ aac_rx_init, "percraid", "DELL    ", "PERCRAID        ", 2, AAC_QUIRK_31BIT }, /* PERC 3/Si */
-	{ aac_rx_init, "percraid", "DELL    ", "PERCRAID        ", 2, AAC_QUIRK_31BIT }, /* PERC 3/Si */
-	{ aac_rx_init, "percraid", "DELL    ", "PERCRAID        ", 2, AAC_QUIRK_31BIT }, /* PERC 3/Di */
-	{ aac_rx_init, "percraid", "DELL    ", "PERCRAID        ", 2, AAC_QUIRK_31BIT }, /* PERC 3/Di */
-	{ aac_rx_init, "percraid", "DELL    ", "PERCRAID        ", 2, AAC_QUIRK_31BIT }, /* PERC 3/Di */
-	{ aac_rx_init, "percraid", "DELL    ", "PERCRAID        ", 2, AAC_QUIRK_31BIT }, /* PERC 3/Di */
-	{ aac_rx_init, "percraid", "DELL    ", "PERCRAID        ", 2, AAC_QUIRK_31BIT }, /* PERC 3/Di */
-	{ aac_rx_init, "aacraid",  "ADAPTEC ", "catapult        ", 2, AAC_QUIRK_31BIT }, /* catapult*/
-	{ aac_rx_init, "aacraid",  "ADAPTEC ", "tomcat          ", 2, AAC_QUIRK_31BIT }, /* tomcat*/
-	{ aac_rx_init, "aacraid",  "ADAPTEC ", "Adaptec 2120S   ", 1, AAC_QUIRK_31BIT }, /* Adaptec 2120S (Crusader)*/
-	{ aac_rx_init, "aacraid",  "ADAPTEC ", "Adaptec 2200S   ", 2, AAC_QUIRK_31BIT }, /* Adaptec 2200S (Vulcan)*/
-	{ aac_rx_init, "aacraid",  "ADAPTEC ", "Adaptec 2200S   ", 2, AAC_QUIRK_31BIT }, /* Adaptec 2200S (Vulcan-2m)*/
-	{ aac_rx_init, "aacraid",  "Legend  ", "Legend S220     ", 1, AAC_QUIRK_31BIT }, /* Legend S220*/
-	{ aac_rx_init, "aacraid",  "Legend  ", "Legend S230     ", 2, AAC_QUIRK_31BIT }, /* Legend S230*/
-
-	{ aac_rx_init, "aacraid",  "ADAPTEC ", "Adaptec 3230S   ", 2 }, /* Adaptec 3230S (Harrier)*/
-	{ aac_rx_init, "aacraid",  "ADAPTEC ", "Adaptec 3240S   ", 2 }, /* Adaptec 3240S (Tornado)*/
-	{ aac_rx_init, "aacraid",  "ADAPTEC ", "ASR-2020ZCR     ", 2 }, /* ASR-2020 ZCR PCI-X U320 */
-	{ aac_rx_init, "aacraid",  "ADAPTEC ", "ASR-2025ZCR     ", 2 }, /* ASR-2025 ZCR DIMM U320 */
-	{ aac_rx_init, "aacraid",  "ADAPTEC ", "AAR-2410SA SATA ", 2 }, /* AAR-2410SA PCI SATA 4ch (Jaguar II)*/
-
-	{ aac_rx_init, "percraid", "DELL    ", "PERC 320/DC     ", 2, AAC_QUIRK_31BIT }, /* Perc 320/DC*/
-	{ aac_sa_init, "aacraid",  "ADAPTEC ", "Adaptec 5400S   ", 4 }, /* Adaptec 5400S (Mustang)*/
-	{ aac_sa_init, "aacraid",  "ADAPTEC ", "AAC-364         ", 4 }, /* Adaptec 5400S (Mustang)*/
-	{ aac_sa_init, "percraid", "DELL    ", "PERCRAID        ", 4, AAC_QUIRK_31BIT }, /* Dell PERC2 "Quad Channel" */
-	{ aac_sa_init, "hpnraid",  "HP      ", "NetRAID         ", 4 },  /* HP NetRAID-4M */
-
+	{ aac_rx_init, "percraid", "DELL    ", "PERCRAID        ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* PERC 2/Si (Iguana/PERC2Si) */
+	{ aac_rx_init, "percraid", "DELL    ", "PERCRAID        ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* PERC 3/Di (Opal/PERC3Di) */
+	{ aac_rx_init, "percraid", "DELL    ", "PERCRAID        ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* PERC 3/Si (SlimFast/PERC3Si */
+	{ aac_rx_init, "percraid", "DELL    ", "PERCRAID        ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* PERC 3/Di (Iguana FlipChip/PERC3DiF */
+	{ aac_rx_init, "percraid", "DELL    ", "PERCRAID        ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* PERC 3/Di (Viper/PERC3DiV) */
+	{ aac_rx_init, "percraid", "DELL    ", "PERCRAID        ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* PERC 3/Di (Lexus/PERC3DiL) */
+	{ aac_rx_init, "percraid", "DELL    ", "PERCRAID        ", 1, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* PERC 3/Di (Jaguar/PERC3DiJ) */
+	{ aac_rx_init, "percraid", "DELL    ", "PERCRAID        ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* PERC 3/Di (Dagger/PERC3DiD) */
+	{ aac_rx_init, "percraid", "DELL    ", "PERCRAID        ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* PERC 3/Di (Boxster/PERC3DiB) */
+	{ aac_rx_init, "aacraid",  "ADAPTEC ", "catapult        ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* catapult */
+	{ aac_rx_init, "aacraid",  "ADAPTEC ", "tomcat          ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* tomcat */
+	{ aac_rx_init, "aacraid",  "ADAPTEC ", "Adaptec 2120S   ", 1, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Adaptec 2120S (Crusader) */
+	{ aac_rx_init, "aacraid",  "ADAPTEC ", "Adaptec 2200S   ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Adaptec 2200S (Vulcan) */
+	{ aac_rx_init, "aacraid",  "ADAPTEC ", "Adaptec 2200S   ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Adaptec 2200S (Vulcan-2m) */
+	{ aac_rx_init, "aacraid",  "Legend  ", "Legend S220     ", 1, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Legend S220 (Legend Crusader) */
+	{ aac_rx_init, "aacraid",  "Legend  ", "Legend S230     ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Legend S230 (Legend Vulcan) */
+
+	{ aac_rx_init, "aacraid",  "ADAPTEC ", "Adaptec 3230S   ", 2 }, /* Adaptec 3230S (Harrier) */
+	{ aac_rx_init, "aacraid",  "ADAPTEC ", "Adaptec 3240S   ", 2 }, /* Adaptec 3240S (Tornado) */
+	{ aac_rx_init, "aacraid",  "ADAPTEC ", "ASR-2020ZCR     ", 2 }, /* ASR-2020ZCR SCSI PCI-X ZCR (Skyhawk) */
+	{ aac_rx_init, "aacraid",  "ADAPTEC ", "ASR-2025ZCR     ", 2 }, /* ASR-2025ZCR SCSI SO-DIMM PCI-X ZCR (Terminator) */
+	{ aac_rkt_init, "aacraid",  "ADAPTEC ", "ASR-2230S PCI-X ", 2 }, /* ASR-2230S + ASR-2230SLP PCI-X (Lancer) */
+	{ aac_rkt_init, "aacraid",  "ADAPTEC ", "ASR-2130S PCI-X ", 1 }, /* ASR-2130S (Lancer) */
+	{ aac_rkt_init, "aacraid",  "ADAPTEC ", "AAR-2820SA      ", 1 }, /* AAR-2820SA (Intruder) */
+	{ aac_rkt_init, "aacraid",  "ADAPTEC ", "AAR-2620SA      ", 1 }, /* AAR-2620SA (Intruder) */
+	{ aac_rkt_init, "aacraid",  "ADAPTEC ", "AAR-2420SA      ", 1 }, /* AAR-2420SA (Intruder) */
+	{ aac_rkt_init, "aacraid",  "ICP     ", "ICP9024R0       ", 2 }, /* ICP9024R0 (Lancer) */
+	{ aac_rkt_init, "aacraid",  "ICP     ", "ICP9014R0       ", 1 }, /* ICP9014R0 (Lancer) */
+	{ aac_rkt_init, "aacraid",  "ICP     ", "ICP9047MA       ", 1 }, /* ICP9047MA (Lancer) */
+	{ aac_rkt_init, "aacraid",  "ICP     ", "ICP9087MA       ", 1 }, /* ICP9087MA (Lancer) */
+	{ aac_rkt_init, "aacraid",  "ICP     ", "ICP5085AU       ", 1 }, /* ICP5085AU (Hurricane) */
+	{ aac_rkt_init, "aacraid",  "ICP     ", "ICP9085LI       ", 1 }, /* ICP9085LI (Marauder-X) */
+	{ aac_rkt_init, "aacraid",  "ICP     ", "ICP5085BR       ", 1 }, /* ICP5085BR (Marauder-E) */
+	{ NULL        , "aacraid",  "ADAPTEC ", "Themisto        ", 0, AAC_QUIRK_SLAVE }, /* Jupiter Platform */
+	{ aac_rkt_init, "aacraid",  "ADAPTEC ", "Callisto        ", 2, AAC_QUIRK_MASTER }, /* Jupiter Platform */
+	{ aac_rx_init, "aacraid",  "ADAPTEC ", "ASR-2020SA       ", 1 }, /* ASR-2020SA SATA PCI-X ZCR (Skyhawk) */
+	{ aac_rx_init, "aacraid",  "ADAPTEC ", "ASR-2025SA       ", 1 }, /* ASR-2025SA SATA SO-DIMM PCI-X ZCR (Terminator) */
+	{ aac_rx_init, "aacraid",  "ADAPTEC ", "AAR-2410SA SATA ", 1 }, /* AAR-2410SA PCI SATA 4ch (Jaguar II) */
 	{ aac_rx_init, "aacraid",  "DELL    ", "CERC SR2        ", 1 }, /* CERC SATA RAID 2 PCI SATA 6ch (DellCorsair) */
 	{ aac_rx_init, "aacraid",  "ADAPTEC ", "AAR-2810SA SATA ", 1 }, /* AAR-2810SA PCI SATA 8ch (Corsair-8) */
 	{ aac_rx_init, "aacraid",  "ADAPTEC ", "AAR-21610SA SATA", 1 }, /* AAR-21610SA PCI SATA 16ch (Corsair-16) */
-	{ aac_rx_init, "aacraid",  "ADAPTEC ", "SO-DIMM SATA ZCR", 1 }, /* ESD SO-DIMM PCI-X SATA ZCR (Prowler) */
-	{ aac_rx_init, "aacraid",  "ADAPTEC ", "SATA 6Channel   ", 1 }, /* SATA 6Ch (Bearcat) */
-
-	{ aac_rkt_init,"aacraid",  "ADAPTEC ", "ASR-2230S PCI-X ", 2 }, /* ASR-2230S + ASR-2230SLP PCI-X (Lancer) */
-	{ aac_rx_init, "aacraid",  "ADAPTEC ", "ASR-2020SA      ", 1 }, /* ASR-2020SA      (ZCR PCI-X SATA) */
-	{ aac_rx_init, "aacraid",  "ADAPTEC ", "ASR-2025SA      ", 1 }, /* ASR-2025SA      (ZCR DIMM SATA) */
+	{ aac_rx_init, "aacraid",  "ADAPTEC ", "ASR-2026ZCR     ", 1 }, /* ESD SO-DIMM PCI-X SATA ZCR (Prowler) */
+	{ aac_rx_init, "aacraid",  "ADAPTEC ", "AAR-2610SA      ", 1 }, /* SATA 6Ch (Bearcat) */
+	{ aac_rx_init, "aacraid",  "ADAPTEC ", "ASR-2240S       ", 1 }, /* ASR-2240S (SabreExpress) */
+	{ aac_rx_init, "aacraid",  "ADAPTEC ", "ASR-4005SAS     ", 1 }, /* ASR-4005SAS */
+	{ aac_rx_init, "ServeRAID","IBM     ", "ServeRAID 8i    ", 1 }, /* IBM 8i (AvonPark) */
+	{ aac_rx_init, "aacraid",  "ADAPTEC ", "ASR-4000SAS     ", 1 }, /* ASR-4000SAS (BlackBird & AvonPark) */
+	{ aac_rx_init, "aacraid",  "ADAPTEC ", "ASR-4800SAS     ", 1 }, /* ASR-4800SAS (Marauder-X) */
+	{ aac_rx_init, "aacraid",  "ADAPTEC ", "ASR-4805SAS     ", 1 }, /* ASR-4805SAS (Marauder-E) */
+	{ aac_rx_init, "aacraid",  "ADAPTEC ", "ASR-4810SAS     ", 1 }, /* ASR-4810SAS (Hurricane) */
+
+	{ aac_rx_init, "percraid", "DELL    ", "PERC 320/DC     ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Perc 320/DC*/
+	{ aac_sa_init, "aacraid",  "ADAPTEC ", "Adaptec 5400S   ", 4, AAC_QUIRK_34SG }, /* Adaptec 5400S (Mustang)*/
+	{ aac_sa_init, "aacraid",  "ADAPTEC ", "AAC-364         ", 4, AAC_QUIRK_34SG }, /* Adaptec 5400S (Mustang)*/
+	{ aac_sa_init, "percraid", "DELL    ", "PERCRAID        ", 4, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Dell PERC2/QC */
+	{ aac_sa_init, "hpnraid",  "HP      ", "NetRAID         ", 4, AAC_QUIRK_34SG }, /* HP NetRAID-4M */
+
+	{ aac_rx_init, "aacraid",  "DELL    ", "RAID            ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Dell Catchall */
+	{ aac_rx_init, "aacraid",  "Legend  ", "RAID            ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Legend Catchall */
+	{ aac_rx_init, "aacraid",  "ADAPTEC ", "RAID            ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Adaptec Catch All */
+	{ aac_rkt_init, "aacraid", "ADAPTEC ", "RAID            ", 2 } /* Adaptec Rocket Catch All */
 };
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11))
 
-#ifdef CONFIG_COMPAT
+#if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) ? defined(__x86_64__) : defined(CONFIG_COMPAT))
 /* 
  * Promote 32 bit apps that call get_next_adapter_fib_ioctl to 64 bit version 
  */
 static int aac_get_next_adapter_fib_ioctl(unsigned int fd, unsigned int cmd, 
 		unsigned long arg, struct file *file)
 {
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+	struct fib_ioctl f;
+	mm_segment_t fs;
+	int retval;
+
+	memset (&f, 0, sizeof(f));
+	if (copy_from_user(&f, (void __user *)arg, sizeof(f) - sizeof(u32)))
+		return -EFAULT;
+	fs = get_fs();
+	set_fs(get_ds());
+	retval = sys_ioctl(fd, cmd, (unsigned long)&f);
+	set_fs(fs);
+	return retval;
+#else
 	struct fib_ioctl __user *f;
 
 	f = compat_alloc_user_space(sizeof(*f));
@@ -185,13 +303,48 @@ static int aac_get_next_adapter_fib_ioct
 		return -EFAULT;
 
 	clear_user(f, sizeof(*f));
-	if (copy_in_user(f, (void __user *)arg, sizeof(struct fib_ioctl) - sizeof(u32)))
+	if (copy_in_user(f, (void __user *)arg, sizeof(*f) - sizeof(u32)))
 		return -EFAULT;
 
 	return sys_ioctl(fd, cmd, (unsigned long)f);
+#endif
 }
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
+#define sys_ioctl NULL	/* register_ioctl32_conversion defaults to this when NULL passed in as a handler */
+#endif
+#endif
+
+#endif
+#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,0))
+static struct Scsi_Host * aac_dummy;
+
+/**
+ *	aac_detect	-	Probe for aacraid cards
+ *	@template: SCSI driver template
+ *
+ *	This is but a stub to convince the 2.4 scsi layer to scan targets,
+ *	the pci scan has already picked up the adapters.
+ */
+static int aac_detect(Scsi_Host_Template *template)
+{
+#if 0
+printk(KERN_INFO "aac_detect(%p)\n", template);
 #endif
+	/* By changing the host list we trick a scan */
+	if (aac_dummy) {
+#if 0
+printk(KERN_INFO "scsi_host_put(%p)\n", aac_dummy);
+#endif
+		scsi_host_put(aac_dummy);
+		aac_dummy = NULL;
+	}
+#if 0
+printk(KERN_INFO "aac_detect()=%d\n", !list_empty(&aac_devices));
+#endif
+	return !list_empty(&aac_devices);
+}
 
+#endif
 
 /**
  *	aac_queuecommand	-	queue a SCSI command
@@ -205,6 +358,55 @@ static int aac_get_next_adapter_fib_ioct
 
 static int aac_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
 {
+#if (defined(AAC_DEBUG_INSTRUMENT_TIMING))
+	u64 lba;
+	u32 count = 0;
+	struct timeval now;
+	do_gettimeofday(&now);
+	if ((cmd->cmnd[0] == WRITE_6)	/* 6 byte command */
+	 || (cmd->cmnd[0] == READ_6)) {
+		lba = ((cmd->cmnd[1] & 0x1F) << 16)
+		    | (cmd->cmnd[2] << 8) | cmd->cmnd[3];
+		count = cmd->cmnd[4];
+		if (count == 0)
+			count = 256;
+#if (defined(WRITE_16))
+	} else if ((cmd->cmnd[0] == WRITE_16) /* 16 byte command */
+	 || (cmd->cmnd[0] == READ_16)) {
+		lba = ((u64)cmd->cmnd[2] << 56)
+		    | ((u64)cmd->cmnd[3] << 48)
+		    | ((u64)cmd->cmnd[4] << 40)
+		    | ((u64)cmd->cmnd[9] << 32)
+		    | (cmd->cmnd[6] << 24)
+		    | (cmd->cmnd[7] << 16)
+		    | (cmd->cmnd[8] << 8) | cmd->cmnd[9];
+		count = (cmd->cmnd[10] << 24)
+		      | (cmd->cmnd[11] << 16)
+		      | (cmd->cmnd[12] << 8) | cmd->cmnd[13];
+#endif
+	} else if ((cmd->cmnd[0] == WRITE_12) /* 12 byte command */
+	 || (cmd->cmnd[0] == READ_12)) {
+		lba = (cmd->cmnd[2] << 24)
+		    | (cmd->cmnd[3] << 16)
+		    | (cmd->cmnd[4] << 8) | cmd->cmnd[5];
+		count = (cmd->cmnd[6] << 24)
+		      | (cmd->cmnd[7] << 16)
+		      | (cmd->cmnd[8] << 8) | cmd->cmnd[9];
+	} else if ((cmd->cmnd[0] == WRITE_10) /* 10 byte command */
+	 || (cmd->cmnd[0] == READ_10)) {
+		lba = (cmd->cmnd[2] << 24)
+		    | (cmd->cmnd[3] << 16)
+		    | (cmd->cmnd[4] << 8) | cmd->cmnd[5];
+		count = (cmd->cmnd[7] << 8) | cmd->cmnd[8];
+	} else
+		lba = (u64)(long)cmd;
+	printk(((count)
+	  ? KERN_DEBUG "%lu.%06lu q%lu %llu[%u]\n"
+	  : KERN_DEBUG "%lu.%06lu q%lu 0x%llx\n"),
+ 	  now.tv_sec % 100, now.tv_usec,
+	  ((struct aac_dev *)cmd->device->host->hostdata)->queues->queue[AdapNormCmdQueue].numpending,
+	  lba, count);
+#endif
 	cmd->scsi_done = done;
 	return (aac_scsi_cmd(cmd) ? FAILED : 0);
 } 
@@ -216,9 +418,21 @@ static int aac_queuecommand(struct scsi_
  *	Returns a static string describing the device in question
  */
 
-const char *aac_info(struct Scsi_Host *shost)
+static const char *aac_info(struct Scsi_Host *shost)
 {
+#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,0))
+	struct aac_dev *dev;
+	if (shost == aac_dummy)
+		return shost->hostt->name;
+	dev = (struct aac_dev *)shost->hostdata;
+	if (!dev
+	 || (dev->cardtype >= (sizeof(aac_drivers)/sizeof(aac_drivers[0]))))
+		return shost->hostt->name;
+	if (dev->scsi_host_ptr != shost)
+		return shost->hostt->name;
+#else
 	struct aac_dev *dev = (struct aac_dev *)shost->hostdata;
+#endif
 	return aac_drivers[dev->cardtype].name;
 }
 
@@ -236,6 +450,10 @@ struct aac_driver_ident* aac_get_driver_
 
 /**
  *	aac_biosparm	-	return BIOS parameters for disk
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+ *	@disk: SCSI disk object to process
+ *	@device: kdev_t of the disk in question
+#endif
  *	@sdev: The scsi device corresponding to the disk
  *	@bdev: the block device corresponding to the disk
  *	@capacity: the sector capacity of the disk
@@ -256,11 +474,21 @@ struct aac_driver_ident* aac_get_driver_
  *	be displayed.
  */
  
-static int aac_biosparm(struct scsi_device *sdev, struct block_device *bdev,
-			sector_t capacity, int *geom)
+static int aac_biosparm(
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+	struct scsi_device *sdev, struct block_device *bdev, sector_t capacity,
+#else
+	Scsi_Disk *disk, kdev_t dev,
+#endif
+	int *geom)
 {
 	struct diskparm *param = (struct diskparm *)geom;
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
 	unsigned char *buf;
+#else
+	struct buffer_head * buf;
+	sector_t capacity = disk->capacity;
+#endif
 
 	dprintk((KERN_DEBUG "aac_biosparm.\n"));
 
@@ -288,9 +516,20 @@ static int aac_biosparm(struct scsi_devi
 	 *	entry whose end_head matches one of the standard geometry 
 	 *	translations ( 64/32, 128/32, 255/63 ).
 	 */
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
 	buf = scsi_bios_ptable(bdev);
-	if(*(unsigned short *)(buf + 0x40) == cpu_to_le16(0xaa55)) {
+#else
+	buf = bread(MKDEV(MAJOR(dev), MINOR(dev)&~0xf), 0, block_size(dev));
+	if(buf == NULL)
+		return 0;
+#endif
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+	if(*(__le16 *)(buf + 0x40) == cpu_to_le16(0xaa55)) {
 		struct partition *first = (struct partition * )buf;
+#else
+	if(*(unsigned short *)(buf->b_data + 0x1fe) == cpu_to_le16(0xaa55)) {
+		struct partition *first = (struct partition * )(buf->b_data + 0x1be);
+#endif
 		struct partition *entry = first;
 		int saved_cylinders = param->cylinders;
 		int num;
@@ -333,12 +572,17 @@ static int aac_biosparm(struct scsi_devi
 					param->heads, param->sectors));
 		}
 	}
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
 	kfree(buf);
+#else
+	brelse(buf);
+#endif
 	return 0;
 }
 
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
 /**
- *	aac_queuedepth		-	compute queue depths
+ *	aac_slave_configure		-	compute queue depths
  *	@sdev:	SCSI device we are considering
  *
  *	Selects queue depths for each target device based on the host adapter's
@@ -348,16 +592,107 @@ static int aac_biosparm(struct scsi_devi
 
 static int aac_slave_configure(struct scsi_device *sdev)
 {
-	if (sdev->tagged_supported)
-		scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, 128);
-	else
+	if (sdev->tagged_supported) {
+		struct scsi_device * dev;
+		struct Scsi_Host * host = sdev->host;
+		unsigned num_lsu = 0;
+		unsigned num_one = 0;
+		unsigned depth;
+
+		__shost_for_each_device(dev, host) {
+			if (dev->tagged_supported && (dev->type == 0))
+				++num_lsu;
+			else
+				++num_one;
+		}
+		if (num_lsu == 0)
+			++num_lsu;
+		depth = (host->can_queue - num_one) / num_lsu;
+		if (depth > 256)
+			depth = 256;
+		else if (depth < 2)
+			depth = 2;
+		scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, depth);
+	} else
 		scsi_adjust_queue_depth(sdev, 0, 1);
+#if ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)) && defined(AAC_EXTENDED_TIMEOUT))
+	{
+		extern int extendedtimeout;
+
+		if (extendedtimeout != -1)
+			sdev->timeout = extendedtimeout * HZ;
+	}
+#endif
 	return 0;
 }
+#else
+/**
+ *	aac_queuedepth		-	compute queue depths
+ *	@host:	SCSI host in question
+ *	@dev:	SCSI device we are considering
+ *
+ *	Selects queue depths for each target device based on the host adapter's
+ *	total capacity and the queue depth supported by the target device.
+ *	A queue depth of one automatically disables tagged queueing.
+ */
+
+static void aac_queuedepth(struct Scsi_Host * host, struct scsi_device * dev )
+{
+	struct scsi_device * dptr;
+	unsigned num = 0;
+	unsigned depth;
+
+#if 0
+printk(KERN_INFO "aac_queuedepth(%p,%p)\n", host, dev);
+#endif
+	for(dptr = dev; dptr != NULL; dptr = dptr->next)
+		if((dptr->host == host) && (dptr->type == 0))
+			++num;
+
+	dprintk((KERN_DEBUG "can_queue=%d num=%d\n", host->can_queue, num));
+#if 0
+printk(KERN_INFO "can_queue=%d num=%d\n", host->can_queue, num);
+#endif
+	if (num == 0)
+		++num;
+	depth = host->can_queue / num;
+	if (depth > 255)
+		depth = 255;
+	else if (depth < 2)
+		depth = 2;
+	dprintk((KERN_DEBUG "aac_queuedepth.\n"));
+	dprintk((KERN_DEBUG "Device #   Q Depth   Online\n"));
+	dprintk((KERN_DEBUG "---------------------------\n"));
+#if 0
+printk(KERN_INFO "aac_queuedepth.\n");
+printk(KERN_INFO "Device #   Q Depth   Online\n");
+printk(KERN_INFO "---------------------------\n");
+#endif
+	for(dptr = dev; dptr != NULL; dptr = dptr->next)
+	{
+		if(dptr->host == host)
+		{
+			dptr->queue_depth = depth;
+			dprintk((KERN_DEBUG "  %2d         %d        %d\n", 
+				dptr->id, dptr->queue_depth, scsi_device_online(dptr)));
+#if 0
+printk(KERN_INFO "  %2d         %d        %d\n", dptr->id, dptr->queue_depth, scsi_device_online(dptr));
+#endif
+		}
+	}
+}
+#endif
 
 static int aac_ioctl(struct scsi_device *sdev, int cmd, void __user * arg)
 {
 	struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
+#if (defined(AAC_DEBUG_INSTRUMENT_IOCTL))
+	int retval;
+	printk("aac_ioctl(%p, %x, %p)\n", sdev, cmd, arg);
+	retval = aac_do_ioctl(dev, cmd, arg);
+	printk("aac_ioctl returns %d\n", retval);
+	return retval;
+#endif
 	return aac_do_ioctl(dev, cmd, arg);
 }
 
@@ -369,28 +704,255 @@ static int aac_eh_abort(struct scsi_cmnd
 	return FAILED;
 }
 
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+/**
+ *	aac_eh_device_reset	-	Reset command handling
+ *	@cmd:	SCSI command block causing the reset
+ *
+ *	Issue a reset of a SCSI device. We are ourselves not truely a SCSI
+ *	controller and our firmware will do the work for us anyway. Thus this
+ *	is a no-op. We just return FAILED.
+ */
+
+static int aac_eh_device_reset(struct scsi_cmnd *cmd)
+{
+	return FAILED;
+}
+
+/**
+ *	aac_eh_bus_reset	-	Reset command handling
+ *	@scsi_cmd:	SCSI command block causing the reset
+ *
+ *	Issue a reset of a SCSI bus. We are ourselves not truely a SCSI
+ *	controller and our firmware will do the work for us anyway. Thus this
+ *	is a no-op. We just return FAILED.
+ */
+
+static int aac_eh_bus_reset(struct scsi_cmnd* cmd)
+{
+	return FAILED;
+}
+
+#endif
 /*
  *	aac_eh_reset	- Reset command handling
  *	@scsi_cmd:	SCSI command block causing the reset
  *
  */
+#if (defined(__arm__))
+//DEBUG
+#define AAC_DEBUG_INSTRUMENT_RESET
+#endif
+#if (defined(AAC_DEBUG_INSTRUMENT_RESET))
+# undef dprintk
+# define dprintk(x)	printk x
+#endif
 static int aac_eh_reset(struct scsi_cmnd* cmd)
 {
+#if (!defined(AAC_DEBUG_INSTRUMENT_RESET) && defined(__arm__))
+//	return FAILED;
+	return SUCCESS; /* Cause an immediate retry of the command with a ten second delay after successful tur */
+#else
 	struct scsi_device * dev = cmd->device;
 	struct Scsi_Host * host = dev->host;
 	struct scsi_cmnd * command;
 	int count;
 	struct aac_dev * aac;
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
 	unsigned long flags;
+#endif
 
 	printk(KERN_ERR "%s: Host adapter reset request. SCSI hang ?\n", 
 					AAC_DRIVERNAME);
+	aac = (struct aac_dev *)host->hostdata;
+	fwprintf((aac, HBA_FLAGS_DBG_FW_PRINT_B, "SCSI hang ?"));
+	if (nblank(dprintk(x))) {
+		int active = 0;
+		unsigned long DebugFlags = aac->FwDebugFlags;
 
+		active = active;
+		dprintk((KERN_ERR
+		  "%s: Outstanding commands on (%d,%d,%d,%d):\n",
+		  AAC_DRIVERNAME,
+		  host->host_no, dev->channel, dev->id, dev->lun));
+		aac->FwDebugFlags |= FW_DEBUG_FLAGS_NO_HEADERS_B;
+		fwprintf((aac, HBA_FLAGS_DBG_FW_PRINT_B,
+		  "%s: Outstanding commands on (%d,%d,%d,%d):\n",
+		  AAC_DRIVERNAME,
+		  host->host_no, dev->channel, dev->id, dev->lun));
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+		spin_lock_irqsave(&dev->list_lock, flags);
+		list_for_each_entry(command, &dev->cmd_list, list)
+#else
+		for(command = dev->device_queue; command; command = command->next)
+#endif
+		{
+			if ((command->state != SCSI_STATE_FINISHED)
+			 && (command->state != 0))
+			dprintk((KERN_ERR
+			  "%4d %c%c %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
+			  active++,
+			  (command->serial_number) ? 'A' : 'C',
+			  (cmd == command) ? '*' : ' ',
+			  command->cmnd[0], command->cmnd[1], command->cmnd[2],
+			  command->cmnd[3], command->cmnd[4], command->cmnd[5],
+			  command->cmnd[6], command->cmnd[7], command->cmnd[8],
+			  command->cmnd[9]));
+			fwprintf((aac, HBA_FLAGS_DBG_FW_PRINT_B,
+			  "%4d %c%c %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
+			  active++,
+			  (command->serial_number) ? 'A' : 'C',
+			  (cmd == command) ? '*' : ' ',
+			  command->cmnd[0], command->cmnd[1], command->cmnd[2],
+			  command->cmnd[3], command->cmnd[4], command->cmnd[5],
+			  command->cmnd[6], command->cmnd[7], command->cmnd[8],
+			  command->cmnd[9]));
+		}
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+		spin_unlock_irqrestore(&dev->list_lock, flags);
+#endif
+		aac->FwDebugFlags = DebugFlags;
+	}
 
-	aac = (struct aac_dev *)host->hostdata;
-	if (aac_adapter_check_health(aac)) {
-		printk(KERN_ERR "%s: Host adapter appears dead\n", 
-				AAC_DRIVERNAME);
+	if ((count = aac_adapter_check_health(aac))) {
+		/* Fake up an AIF:
+		 *	aac_aifcmd.command = AifCmdEventNotify = 1
+		 *	aac_aifcmd.seqnum = 0xFFFFFFFF
+		 *	aac_aifcmd.data[0] = AifEnExpEvent = 23
+		 *	aac_aifcmd.data[1] = AifExeFirmwarePanic = 3
+		 *	aac.aifcmd.data[2] = AifHighPriority = 3
+		 *	aac.aifcmd.data[3] = count
+		 */
+		struct list_head *entry;
+		u32 time_now = jiffies/HZ;
+		unsigned long flagv;
+			
+		spin_lock_irqsave(&aac->fib_lock, flagv);
+		entry = aac->fib_list.next;
+
+		/*
+		 * For each Context that is on the 
+		 * fibctxList, make a copy of the
+		 * fib, and then set the event to wake up the
+		 * thread that is waiting for it.
+		 */
+		while (entry != &aac->fib_list) {
+			/*
+			 * Extract the fibctx
+			 */
+			struct aac_fib_context *fibctx = list_entry(entry, struct aac_fib_context, next);
+			struct hw_fib * hw_fib;
+			struct fib * fib;
+			/*
+			 * Check if the queue is getting
+			 * backlogged
+			 */
+			if (fibctx->count > 20) {
+				/*
+				 * It's *not* jiffies folks,
+				 * but jiffies / HZ, so do not
+				 * panic ...
+				 */
+				u32 time_last = fibctx->jiffies;
+				/*
+				 * Has it been > 2 minutes 
+				 * since the last read off
+				 * the queue?
+				 */
+				if ((time_now - time_last) > 120) {
+					entry = entry->next;
+					aac_close_fib_context(aac, fibctx);
+					continue;
+				}
+			}
+			/*
+			 * Warning: no sleep allowed while
+			 * holding spinlock
+			 */
+			hw_fib = kmalloc(sizeof(struct hw_fib), GFP_ATOMIC);
+			fib = kmalloc(sizeof(struct fib), GFP_ATOMIC);
+			if (fib && hw_fib) {
+				struct aac_aifcmd * aif;
+				memset(hw_fib, 0, sizeof(struct hw_fib));
+				memset(fib, 0, sizeof(struct fib));
+				fib->hw_fib = hw_fib;
+				fib->dev = aac;
+				fib_init(fib);
+				fib->type = FSAFS_NTC_FIB_CONTEXT;
+				fib->size = sizeof (struct fib);
+				fib->data = hw_fib->data;
+				aif = (struct aac_aifcmd *)hw_fib->data;
+				aif->command = AifCmdEventNotify;
+			 	aif->seqnum = 0xFFFFFFFF;
+			 	aif->data[0] = AifEnExpEvent;
+				aif->data[1] = AifExeFirmwarePanic;
+			 	aif->data[2] = AifHighPriority;
+				aif->data[3] = count;
+
+				/*
+				 * Put the FIB onto the
+				 * fibctx's fibs
+				 */
+				list_add_tail(&fib->fiblink, &fibctx->fib_list);
+				fibctx->count++;
+				/* 
+				 * Set the event to wake up the
+				 * thread that will waiting.
+				 */
+				up(&fibctx->wait_sem);
+			} else {
+				printk(KERN_WARNING "aifd: didn't allocate NewFib.\n");
+				if(fib)
+					kfree(fib);
+				if(hw_fib)
+					kfree(hw_fib);
+			}
+			entry = entry->next;
+		}
+		spin_unlock_irqrestore(&aac->fib_lock, flagv);
+
+		printk(((count < 0)
+		    ? KERN_ERR "%s: Host adapter appears dead %d\n"
+		    : KERN_ERR "%s: Host adapter BLINK LED 0x%x\n"),
+		  AAC_DRIVERNAME, count);
+
+		/*
+		 *	If a positive health, means in a known DEAD PANIC
+		 * state and the adapter could be reset to `try again'.
+		 */
+#if 0
+		if ((count > 0)
+		 && (!aac_adapter_sync_cmd(dev, IOP_RESET, 0, 0, 0, 0, 0, 0,
+		  &time_now, NULL, NULL, NULL, NULL))
+		 && (time_now == 0x00000001)) {
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+			__shost_for_each_device(dev, host) {
+				spin_lock_irqsave(&dev->list_lock, flags);
+				list_for_each_entry(command, &dev->cmd_list, list) {
+					if (command->serial_number) {
+						command->result
+						  = DID_RESET << 16
+						  | COMMAND_COMPLETE << 8;
+						command->scsi_done(command);
+					}
+				}
+				spin_unlock_irqrestore(&dev->list_lock, flags);
+			}
+#else
+			for (dev = host->host_queue; dev != (struct scsi_device *)NULL; dev = dev->next) {
+				for(command = dev->device_queue; command; command = command->next) {
+					if (command->serial_number) {
+						command->result
+						  = DID_RESET << 16
+						  | COMMAND_COMPLETE << 8;
+						command->scsi_done(command);
+					}
+				}
+			}
+#endif
+			return SUCCESS;
+		}
+#endif
 		return -ENODEV;
 	}
 	/*
@@ -399,6 +961,7 @@ static int aac_eh_reset(struct scsi_cmnd
 	 */
 	for (count = 60; count; --count) {
 		int active = 0;
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
 		__shost_for_each_device(dev, host) {
 			spin_lock_irqsave(&dev->list_lock, flags);
 			list_for_each_entry(command, &dev->cmd_list, list) {
@@ -408,20 +971,510 @@ static int aac_eh_reset(struct scsi_cmnd
 				}
 			}
 			spin_unlock_irqrestore(&dev->list_lock, flags);
+			if (active)
+				break;
 
-			/*
-			 * We can exit If all the commands are complete
-			 */
-			if (active == 0)
-				return SUCCESS;
 		}
+#else
+		for (dev = host->host_queue; dev != (struct scsi_device *)NULL; dev = dev->next) {
+			for(command = dev->device_queue; command; command = command->next) {
+				if (command->serial_number) {
+					++active;
+					break;
+				}
+			}
+		}
+#endif
+		/*
+		 * We can exit If all the commands are complete
+		 */
+		if (active == 0)
+			return SUCCESS;
+#if (defined(SCSI_HAS_HOST_LOCK) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,21)) && ((LINUX_VERSION_CODE > KERNEL_VERSION(2,4,21)) || !defined(CONFIG_CFGNAME))
 		spin_unlock_irq(host->host_lock);
-		scsi_sleep(HZ);
+#else
+		spin_unlock_irq(host->lock);
+#endif
+#else
+		spin_unlock_irq(&io_request_lock);
+#endif
+		ssleep(1);
+#if (defined(SCSI_HAS_HOST_LOCK) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,21)) && ((LINUX_VERSION_CODE > KERNEL_VERSION(2,4,21)) || !defined(CONFIG_CFGNAME))
 		spin_lock_irq(host->host_lock);
+#else
+		spin_lock_irq(host->lock);
+#endif
+#else
+		spin_lock_irq(&io_request_lock);
+#endif
 	}
 	printk(KERN_ERR "%s: SCSI bus appears hung\n", AAC_DRIVERNAME);
-	return -ETIMEDOUT;
+	fwprintf((aac, HBA_FLAGS_DBG_FW_PRINT_B, "SCSI bus appears hung"));
+//	return -ETIMEDOUT;
+	return SUCCESS; /* Cause an immediate retry of the command with a ten second delay after successful tur */
+#endif
+}
+#if (defined(AAC_DEBUG_INSTRUMENT_RESET))
+/* We are making an assumption that dprintk was turned off */
+# undef dprintk
+# define dprintk(x)
+#endif
+#if (defined(SCSI_HAS_DUMP))
+#if (defined(SCSI_HAS_DUMP_SANITY_CHECK))
+static int aac_sanity_check(struct scsi_device * sdev)
+{
+	return 0;
+}
+
+#endif
+static void aac_poll(struct scsi_device * sdev)
+{
+	struct Scsi_Host * shost = sdev->host;
+	struct aac_dev *dev = (struct aac_dev *)shost->hostdata;
+	unsigned long flags;
+
+#if (defined(SCSI_HAS_HOST_LOCK) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,21)) && ((LINUX_VERSION_CODE > KERNEL_VERSION(2,4,21)) || !defined(CONFIG_CFGNAME))
+	spin_lock_irqsave(shost->host_lock, flags);
+#else
+	spin_lock_irqsave(shost->lock, flags);
+#endif
+#else
+	spin_lock_irqsave(&io_request_lock, flags);
+#endif
+	aac_adapter_intr(dev);
+#if (defined(SCSI_HAS_HOST_LOCK) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,21)) && ((LINUX_VERSION_CODE > KERNEL_VERSION(2,4,21)) || !defined(CONFIG_CFGNAME))
+	spin_unlock_irqrestore(shost->host_lock, flags);
+#else
+	spin_unlock_irqrestore(shost->lock, flags);
+#endif
+#else
+	spin_unlock_irqrestore(&io_request_lock, flags);
+#endif
+}
+#endif
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+#define shost_to_class(shost) &shost->shost_classdev
+#else
+#define class_device Scsi_Host
+#define shost_to_class(shost) shost
+#define class_to_shost(class_dev) class_dev
+#endif
+
+static ssize_t aac_show_host_version(struct class_device *class_dev, char *buf)
+{
+	int len;
+
+	len = snprintf(buf, PAGE_SIZE, "Adaptec Raid Controller %s\n",
+	  aac_driver_version);
+	return len;
+}
+
+static ssize_t aac_show_model(struct class_device *class_dev, char *buf)
+{
+	struct aac_dev *dev = (struct aac_dev*)class_to_shost(class_dev)->hostdata;
+	int len;
+
+	if (dev->supplement_adapter_info.AdapterTypeText[0]) {
+		char * cp = dev->supplement_adapter_info.AdapterTypeText;
+		char * endp;
+		while (*cp && *cp != ' ')
+			++cp;
+		endp = cp;
+		while (*cp == ' ')
+			++cp;
+		len = snprintf(buf, PAGE_SIZE, "Vendor: %.*s Model: %s\n",
+		  (int)(endp - (char *)dev->supplement_adapter_info.AdapterTypeText),
+		  dev->supplement_adapter_info.AdapterTypeText, cp);
+	} else
+		len = snprintf(buf, PAGE_SIZE, "Vendor: %s Model: %s\n",
+		  aac_drivers[dev->cardtype].vname,
+		  aac_drivers[dev->cardtype].model);
+	return len;
+}
+
+static ssize_t aac_show_flags(struct class_device *class_dev, char *buf)
+{
+	int len = 0;
+
+	if (nblank(dprintk(x)))
+		len = snprintf(buf, PAGE_SIZE, "dprintk\n");
+#	if (defined(AAC_DETAILED_STATUS_INFO))
+		len += snprintf(buf + len, PAGE_SIZE - len,
+		  "AAC_DETAILED_STATUS_INFO\n");
+#	endif
+#	if (defined(AAC_DEBUG_INSTRUMENT_AAC_CONFIG))
+		len += snprintf(buf + len, PAGE_SIZE- len,
+		  "AAC_DEBUG_INSTRUMENT_AAC_CONFIG\n");
+#	endif
+#	if (defined(AAC_DEBUG_INSTRUMENT_AIF))
+		len += snprintf(buf + len, PAGE_SIZE - len,
+		  "AAC_DEBUG_INSTRUMENT_AIF\n");
+#	endif
+#	if (defined(AAC_DEBUG_INSTRUMENT_IOCTL))
+		len += snprintf(buf + len, PAGE_SIZE - len,
+		  "AAC_DEBUG_INSTRUMENT_IOCTL\n");
+#	endif
+#	if (defined(AAC_DEBUG_INSTRUMENT_TIMING))
+		len += snprintf(buf + len, PAGE_SIZE - len,
+		  "AAC_DEBUG_INSTRUMENT_TIMING\n");
+#	endif
+#	if (defined(AAC_DEBUG_INSTRUMENT_RESET))
+		len += snprintf(buf + len, PAGE_SIZE - len,
+		  "AAC_DEBUG_INSTRUMENT_RESET\n");
+#	endif
+#	if (defined(AAC_DEBUG_INSTRUMENT_FIB))
+		len += snprintf(buf + len, PAGE_SIZE - len,
+		  "AAC_DEBUG_INSTRUMENT_FIB\n");
+#	endif
+#	if (defined(AAC_DEBUG_INSTRUMENT_2TB))
+		len += snprintf(buf + len, PAGE_SIZE - len,
+		  "AAC_DEBUG_INSTRUMENT_2TB\n");
+#	endif
+#	if (defined(AAC_DEBUG_INSTRUMENT_IOCTL_SENDFIB))
+		len += snprintf(buf + len, PAGE_SIZE - len,
+		  "AAC_DEBUG_INSTRUMENT_IOCTL_SENDFIB\n");
+#	endif
+#	if (defined(AAC_DEBUG_INSTRUMENT_IO))
+		len += snprintf(buf + len, PAGE_SIZE - len,
+		  "AAC_DEBUG_INSTRUMENT_IO\n");
+#	endif
+#if (defined(SERVICE_ACTION_IN) && defined(SAI_READ_CAPACITY_16))
+	{
+		struct aac_dev *dev = (struct aac_dev*)class_to_shost(class_dev)->hostdata;
+		if (dev->raw_io_interface && dev->raw_io_64)
+			len += snprintf(buf + len, PAGE_SIZE - len,
+			  "SAI_READ_CAPACITY_16\n");
+	}
+#endif
+	return len;
+}
+
+static ssize_t aac_show_kernel_version(struct class_device *class_dev, char *buf)
+{
+	struct aac_dev *dev = (struct aac_dev*)class_to_shost(class_dev)->hostdata;
+	int len, tmp;
+
+	tmp = le32_to_cpu(dev->adapter_info.kernelrev);
+	len = snprintf(buf, PAGE_SIZE, "kernel: %d.%d-%d[%d]\n", 
+	  tmp >> 24, (tmp >> 16) & 0xff, tmp & 0xff,
+	  le32_to_cpu(dev->adapter_info.kernelbuild));
+	return len;
+}
+
+static ssize_t aac_show_monitor_version(struct class_device *class_dev, char *buf)
+{
+	struct aac_dev *dev = (struct aac_dev*)class_to_shost(class_dev)->hostdata;
+	int len, tmp;
+
+	tmp = le32_to_cpu(dev->adapter_info.monitorrev);
+	len = snprintf(buf, PAGE_SIZE, "monitor: %d.%d-%d[%d]\n", 
+	  tmp >> 24, (tmp >> 16) & 0xff, tmp & 0xff,
+	  le32_to_cpu(dev->adapter_info.monitorbuild));
+	return len;
+}
+
+static ssize_t aac_show_bios_version(struct class_device *class_dev, char *buf)
+{
+	struct aac_dev *dev = (struct aac_dev*)class_to_shost(class_dev)->hostdata;
+	int len, tmp;
+
+	tmp = le32_to_cpu(dev->adapter_info.biosrev);
+	len = snprintf(buf, PAGE_SIZE, "bios: %d.%d-%d[%d]\n", 
+	  tmp >> 24, (tmp >> 16) & 0xff, tmp & 0xff,
+	  le32_to_cpu(dev->adapter_info.biosbuild));
+	return len;
+}
+
+static ssize_t aac_show_serial_number(struct class_device *class_dev, char *buf)
+{
+	struct aac_dev *dev = (struct aac_dev*)class_to_shost(class_dev)->hostdata;
+	int len = 0;
+
+	if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0)
+		len = snprintf(buf, PAGE_SIZE, "serial: %x\n",
+		  le32_to_cpu(dev->adapter_info.serial[0]));
+	return len;
+}
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+
+static struct class_device_attribute aac_host_version = {
+	.attr = {
+		.name = "aac_version",
+		.mode = S_IRUGO,
+	},
+	.show = aac_show_host_version,
+};
+static struct class_device_attribute aac_model = {
+	.attr = {
+		.name = "aac_model",
+		.mode = S_IRUGO,
+	},
+	.show = aac_show_model,
+};
+static struct class_device_attribute aac_flags = {
+	.attr = {
+		.name = "aac_flags",
+		.mode = S_IRUGO,
+	},
+	.show = aac_show_flags,
+};
+static struct class_device_attribute aac_kernel_version = {
+	.attr = {
+		.name = "aac_kernel_version",
+		.mode = S_IRUGO,
+	},
+	.show = aac_show_kernel_version,
+};
+static struct class_device_attribute aac_monitor_version = {
+	.attr = {
+		.name = "aac_monitor_version",
+		.mode = S_IRUGO,
+	},
+	.show = aac_show_monitor_version,
+};
+static struct class_device_attribute aac_bios_version = {
+	.attr = {
+		.name = "aac_bios_version",
+		.mode = S_IRUGO,
+	},
+	.show = aac_show_bios_version,
+};
+static struct class_device_attribute aac_serial_number = {
+	.attr = {
+		.name = "aac_serial_number",
+		.mode = S_IRUGO,
+	},
+	.show = aac_show_serial_number,
+};
+
+static struct class_device_attribute *aac_attrs[] = {
+	&aac_host_version,
+	&aac_model,
+	&aac_flags,
+	&aac_kernel_version,
+	&aac_monitor_version,
+	&aac_bios_version,
+	&aac_serial_number,
+	NULL
+};
+#endif
+#if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) || defined(CONFIG_SCSI_PROC_FS))
+
+/**
+ *	aac_procinfo	-	Implement /proc/scsi/<drivername>/<n>
+ *	@proc_buffer: memory buffer for I/O
+ *	@start_ptr: pointer to first valid data
+ *	@offset: offset into file
+ *	@bytes_available: space left
+ *	@host_no: scsi host ident
+ *	@write: direction of I/O
+ *
+ *	Used to export driver statistics and other infos to the world outside 
+ *	the kernel using the proc file system. Also provides an interface to
+ *	feed the driver with information.
+ *
+ *		For reads
+ *			- if offset > 0 return 0
+ *			- if offset == 0 write data to proc_buffer and set the start_ptr to
+ *			beginning of proc_buffer, return the number of characters written.
+ *		For writes
+ *			- writes currently not supported, return 0
+ *
+ *	Bugs:	Only offset zero is handled
+ */
+
+static int aac_procinfo(
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+	struct Scsi_Host * shost,
+#endif
+	char *proc_buffer, char **start_ptr,off_t offset,
+	int bytes_available,
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+	int host_no,
+#endif
+	int write)
+{
+	struct aac_dev * dev = (struct aac_dev *)NULL;
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+	struct Scsi_Host * shost = (struct Scsi_Host *)NULL;
+#endif
+	char *buf;
+	int len;
+	int total_len = 0;
+
+#if (defined(AAC_LM_SENSOR))
+	if(offset > 0)
+#else
+	if(write || offset > 0)
+#endif
+		return 0;
+	*start_ptr = proc_buffer;
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+	dev = (struct aac_dev *)shost->hostdata;
+#else
+	list_for_each_entry(dev, &aac_devices, entry) {
+		shost = dev->scsi_host_ptr;
+		if (shost->host_no == host_no)
+			break;
+	}
+#endif
+	if (dev == (struct aac_dev *)NULL)
+		return 0;
+	if (!write) {
+		buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
+		if (!buf)
+			return 0;
+		len = aac_show_host_version(shost_to_class(shost), buf);
+		total_len += len;
+		memcpy(proc_buffer, buf, len);
+		proc_buffer += len;
+		len = aac_show_model(shost_to_class(shost), buf);
+		total_len += len;
+		if (total_len > bytes_available) {
+			kfree(buf);
+			return 0;
+		}
+		memcpy(proc_buffer, buf, len);
+		proc_buffer += len;
+		len = aac_show_flags(shost_to_class(shost), buf);
+		if (len) {
+			static char flags_equal[] = "flags=";
+			char *cp;
+			total_len += len + sizeof(flags_equal) - 1;
+			if (total_len > bytes_available) {
+				kfree(buf);
+				return 0;
+			}
+			memcpy(proc_buffer, flags_equal, sizeof(flags_equal) - 1);
+			cp = proc_buffer + (sizeof(flags_equal) - 1);
+			memcpy(cp, buf, len);
+			proc_buffer += len + sizeof(flags_equal) - 1;
+			while (--len > 0) {
+				if (*cp == '\n')
+					*cp = '+';
+				++cp;
+			}
+		}
+		len = aac_show_kernel_version(shost_to_class(shost), buf);
+		total_len += len;
+		if (total_len > bytes_available) {
+			kfree(buf);
+			return 0;
+		}
+		memcpy(proc_buffer, buf, len);
+		proc_buffer += len;
+		len = aac_show_monitor_version(shost_to_class(shost), buf);
+		total_len += len;
+		if (total_len > bytes_available) {
+			kfree(buf);
+			return 0;
+		}
+		memcpy(proc_buffer, buf, len);
+		proc_buffer += len;
+		len = aac_show_bios_version(shost_to_class(shost), buf);
+		total_len += len;
+		if (total_len > bytes_available) {
+			kfree(buf);
+			return 0;
+		}
+		memcpy(proc_buffer, buf, len);
+		proc_buffer += len;
+		len = aac_show_serial_number(shost_to_class(shost), buf);
+		total_len += len;
+		if (total_len > bytes_available) {
+			kfree(buf);
+			return 0;
+		}
+		memcpy(proc_buffer, buf, len);
+		kfree(buf);
+		return total_len;
+	}
+#if (defined(AAC_LM_SENSOR))
+	{
+		int ret, tmp, index;
+		s32 temp[5];
+		static char temperature[] = "temperature=";
+		if (strnicmp (proc_buffer, temperature, sizeof(temperature) - 1))
+			return bytes_available;
+		for (index = 0;
+		  index < (sizeof(temp)/sizeof(temp[0]));
+		  ++index)
+			temp[index] = 0x80000000;
+		ret = sizeof(temperature) - 1;
+		for (index = 0;
+		  index < (sizeof(temp)/sizeof(temp[0]));
+		  ++index) {
+			int sign, mult, c;
+			if (ret >= bytes_available)
+				break;
+			c = proc_buffer[ret];
+			if (c == '\n') {
+				++ret;
+				break;
+			}
+			if (c == ',') {
+				++ret;
+				continue;
+			}
+			sign = 1;
+			mult = 0;
+			tmp = 0;
+			if (c == '-') {
+				sign = -1;
+				++ret;
+			}
+			for (;
+			  (ret < bytes_available) && ((c = proc_buffer[ret]));
+			  ++ret) {
+				if (('0' <= c) && (c <= '9')) {
+					tmp *= 10;
+					tmp += c - '0';
+					mult *= 10;
+				} else if ((c == '.') && (mult == 0))
+					mult = 1;
+				else
+					break;
+			}
+			if ((ret < bytes_available)
+			 && ((c == ',') || (c == '\n')))
+				++ret;
+			if (!mult)
+				mult = 1;
+			if (sign < 0)
+				tmp = -tmp;
+			temp[index] = ((tmp << 8) + (mult >> 1)) / mult;
+			if (c == '\n')
+				break;
+		}
+		ret = index;
+		if (nblank(dprintk(x))) {
+			for (index = 0; index < ret; ++index) {
+				int sign;
+				tmp = temp[index];
+				sign = tmp < 0;
+				if (sign)
+					tmp = -tmp;
+				dprintk((KERN_DEBUG "%s%s%d.%08doC",
+				  (index ? "," : ""),
+				  (sign ? "-" : ""),
+				  tmp >> 8, (tmp % 256) * 390625));
+			}
+		}
+		/* Send temperature message to Firmware */
+		(void)aac_adapter_sync_cmd(dev, RCV_TEMP_READINGS,
+		  ret, temp[0], temp[1], temp[2], temp[3], temp[4],
+		  NULL, NULL, NULL, NULL, NULL);
+		return bytes_available;
+	}
+#endif
+	return 0;
 }
+#endif
 
 /**
  *	aac_cfg_open		-	open a configuration file
@@ -437,14 +1490,37 @@ static int aac_eh_reset(struct scsi_cmnd
 
 static int aac_cfg_open(struct inode *inode, struct file *file)
 {
-	unsigned minor = iminor(inode);
+	struct aac_dev *aac;
+	unsigned minor_number = iminor(inode);
+	int err = -ENODEV;
 
-	if (minor >= aac_count)
-		return -ENODEV;
-	file->private_data = aac_devices[minor];
+	list_for_each_entry(aac, &aac_devices, entry) {
+		if (aac->id == minor_number) {
+			file->private_data = aac;
+			err = 0;
+			break;
+		}
+	}
+
+	return err;
+}
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+/**
+ *	aac_cfg_release		-	close down an AAC config device
+ *	@inode: inode of configuration file
+ *	@file: file handle of configuration file
+ *	
+ *	Called when the last close of the configuration file handle
+ *	is performed.
+ */
+ 
+static int aac_cfg_release(struct inode * inode, struct file * file )
+{
 	return 0;
 }
 
+#endif
 /**
  *	aac_cfg_ioctl		-	AAC configuration request
  *	@inode: inode of device
@@ -462,28 +1538,138 @@ static int aac_cfg_open(struct inode *in
 static int aac_cfg_ioctl(struct inode *inode,  struct file *file,
 		unsigned int cmd, unsigned long arg)
 {
+#if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,4,4)) && defined(__VMKERNEL_MODULE__))
+	list_for_each_entry(aac, &aac_devices, entry) {
+		if (aac->id == iminor(inode);
+			file->private_data = aac;
+			break;
+		}
+	}
+	if (file->private_data == NULL)
+		return -ENODEV;
+#endif
+#if (defined(AAC_DEBUG_INSTRUMENT_IOCTL))
+	int retval;
+	if (cmd != FSACTL_GET_NEXT_ADAPTER_FIB)
+		printk("aac_cfg_ioctl(%p,%p,%x,%lx)\n", inode, file, cmd, arg);
+	retval = aac_do_ioctl(file->private_data, cmd, (void __user *)arg);
+	if (cmd != FSACTL_GET_NEXT_ADAPTER_FIB)
+		printk("aac_cfg_ioctl returns %d\n", retval);
+	return retval;
+#else
 	return aac_do_ioctl(file->private_data, cmd, (void __user *)arg);
+#endif
+}
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11))
+#ifdef CONFIG_COMPAT
+static long aac_compat_do_ioctl(struct aac_dev *dev, unsigned cmd, unsigned long arg)
+{
+	long ret;
+	lock_kernel();
+	switch (cmd) { 
+	case FSACTL_MINIPORT_REV_CHECK:
+	case FSACTL_SENDFIB:
+	case FSACTL_OPEN_GET_ADAPTER_FIB:
+	case FSACTL_CLOSE_GET_ADAPTER_FIB:
+	case FSACTL_SEND_RAW_SRB:
+	case FSACTL_GET_PCI_INFO:
+	case FSACTL_QUERY_DISK:
+	case FSACTL_DELETE_DISK:
+	case FSACTL_FORCE_DELETE_DISK:
+	case FSACTL_GET_CONTAINERS: 
+	case FSACTL_GET_VERSION_MATCHING:
+	case FSACTL_SEND_LARGE_FIB:
+#if (defined(FSACTL_REGISTER_FIB_SEND))
+	case FSACTL_REGISTER_FIB_SEND:
+#endif
+		ret = aac_do_ioctl(dev, cmd, (void __user *)arg);
+		break;
+
+	case FSACTL_GET_NEXT_ADAPTER_FIB: {
+		struct fib_ioctl __user *f;
+		
+		f = compat_alloc_user_space(sizeof(*f));
+		ret = 0;
+		if (clear_user(f, sizeof(*f) != sizeof(*f)))
+			ret = -EFAULT;
+		if (copy_in_user(f, (void __user *)arg, sizeof(struct fib_ioctl) - sizeof(u32)))
+			ret = -EFAULT;
+		if (!ret)
+			ret = aac_do_ioctl(dev, cmd, (void __user *)arg);
+		break;
+	}
+
+	default:
+#if (defined(AAC_CSMI))
+		ret = aac_csmi_ioctl(dev, cmd, (void __user *)arg);
+		if (ret == -ENOTTY)
+#endif
+		ret = -ENOIOCTLCMD; 
+		break;
+	} 
+	unlock_kernel();
+	return ret;
+}
+
+static int aac_compat_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
+{
+	struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
+	return aac_compat_do_ioctl(dev, cmd, (unsigned long)arg);
+}
+
+static long aac_compat_cfg_ioctl(struct file *file, unsigned cmd, unsigned long arg)
+{
+	return aac_compat_do_ioctl((struct aac_dev *)file->private_data, cmd, arg);
 }
+#endif
+#endif
 
 static struct file_operations aac_cfg_fops = {
 	.owner		= THIS_MODULE,
 	.ioctl		= aac_cfg_ioctl,
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11))
+#ifdef CONFIG_COMPAT
+	.compat_ioctl   = aac_compat_cfg_ioctl,
+#endif
+#endif
 	.open		= aac_cfg_open,
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+	.release	= aac_cfg_release
+#endif
 };
 
 static struct scsi_host_template aac_driver_template = {
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+	.detect				= aac_detect,
+#endif
 	.module				= THIS_MODULE,
 	.name           		= "AAC",
-	.proc_name			= "aacraid",
+	.proc_name			= AAC_DRIVERNAME,
 	.info           		= aac_info,
 	.ioctl          		= aac_ioctl,
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11))
+#ifdef CONFIG_COMPAT
+	.compat_ioctl			= aac_compat_ioctl,
+#endif
+#endif
 	.queuecommand   		= aac_queuecommand,
 	.bios_param     		= aac_biosparm,	
+#if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) || defined(CONFIG_SCSI_PROC_FS))
+	.proc_info      		= aac_procinfo,
+#endif
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+	.shost_attrs			= aac_attrs,
 	.slave_configure		= aac_slave_configure,
+#endif
 	.eh_abort_handler		= aac_eh_abort,
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+	.eh_device_reset_handler	= aac_eh_device_reset,
+	.eh_bus_reset_handler		= aac_eh_bus_reset,
+#endif
 	.eh_host_reset_handler		= aac_eh_reset,
 	.can_queue      		= AAC_NUM_IO_FIB,	
-	.this_id        		= 16,
+	.this_id        		= MAXIMUM_NUM_CONTAINERS,
 	.sg_tablesize   		= 16,
 	.max_sectors    		= 128,
 #if (AAC_NUM_IO_FIB > 256)
@@ -491,7 +1677,19 @@ static struct scsi_host_template aac_dri
 #else		
 	.cmd_per_lun    		= AAC_NUM_IO_FIB, 
 #endif	
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+	.use_new_eh_code		= 1, 
+#endif
 	.use_clustering			= ENABLE_CLUSTERING,
+#if (defined(SCSI_HAS_VARY_IO))
+	.vary_io			= 1,
+#endif
+#if (defined(SCSI_HAS_DUMP))
+#if (defined(SCSI_HAS_DUMP_SANITY_CHECK))
+	.dump_sanity_check		= aac_sanity_check,
+#endif
+	.dump_poll			= aac_poll,
+#endif
 };
 
 
@@ -500,16 +1698,88 @@ static int __devinit aac_probe_one(struc
 {
 	unsigned index = id->driver_data;
 	struct Scsi_Host *shost;
-	struct fsa_scsi_hba *fsa_dev_ptr;
 	struct aac_dev *aac;
-	int container;
+	struct list_head *insert = &aac_devices;
 	int error = -ENODEV;
+	int unique_id = 0;
+	static struct pci_dev * slave = NULL;
+	static int nslave = 0;
+
+	if (aac_drivers[index].quirks & AAC_QUIRK_SLAVE) {
+		/* detect adjoining slaves */
+		if (slave) {
+			if ((pci_resource_start(pdev, 0)
+			  + pci_resource_len(pdev, 0))
+			  == pci_resource_start(slave, 0))
+				slave = pdev;
+			else if ((pci_resource_start(slave, 0)
+			  + (pci_resource_len(slave, 0) * nslave))
+			  != pci_resource_start(pdev, 0)) {
+				printk(KERN_WARNING
+				  "%s: multiple sets of slave controllers discovered\n",
+				  AAC_DRIVERNAME);
+				nslave = 0;
+				slave = pdev;
+			}
+		} else
+			slave = pdev;
+		if (pci_resource_start(slave,0)) {
+			error = pci_enable_device(pdev);
+			if (error) {
+				printk(KERN_WARNING
+				  "%s: failed to enable slave\n",
+				  AAC_DRIVERNAME);
+				nslave = 0;
+				slave = NULL;
+				return error;
+			}
+			++nslave;
+			pci_set_master(pdev);
+		} else {
+			printk(KERN_WARNING
+			  "%s: slave BAR0 is not set\n", AAC_DRIVERNAME);
+			nslave = 0;
+			slave = NULL;
+			return error;
+		}
+		return 1;
+	}
+	list_for_each_entry(aac, &aac_devices, entry) {
+		if (aac->id > unique_id)
+			break;
+		insert = &aac->entry;
+		unique_id++;
+	}
 
-	if (pci_enable_device(pdev))
+	error = pci_enable_device(pdev);
+	if (error)
 		goto out;
 
-	if (pci_set_dma_mask(pdev, 0xFFFFFFFFULL) || 
-			pci_set_consistent_dma_mask(pdev, 0xFFFFFFFFULL))
+	if ((aac_drivers[index].quirks & AAC_QUIRK_MASTER) && (slave)) {
+		unsigned long base = pci_resource_start(pdev, 0);
+		struct master_registers {
+			u32 x[51];
+			u32	E_CONFIG1;
+			u32 y[3];
+			u32	E_CONFIG2;
+		} __iomem * map = ioremap(base, AAC_MIN_FOOTPRINT_SIZE);
+		if (!map) {
+			printk(KERN_WARNING
+			  "%s: unable to map master adapter to configure slaves.\n",
+			  AAC_DRIVERNAME);
+		} else {
+			((struct master_registers *)map)->E_CONFIG2
+			  = cpu_to_le32(pci_resource_start(slave, 0));
+			((struct master_registers *)map)->E_CONFIG1
+			  = cpu_to_le32(0x5A000000 + nslave);
+			iounmap(map);
+		}
+		nslave = 0;
+		slave = NULL;
+	}
+
+	if (pci_set_dma_mask(pdev, DMA_32BIT_MASK) || 
+			pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))
 		goto out;
 	/*
 	 * If the quirk31 bit is set, the adapter needs adapter
@@ -522,16 +1792,32 @@ static int __devinit aac_probe_one(struc
 	
 	pci_set_master(pdev);
 
-	/* Increment the host adapter count */
-	aac_count++;
-
 	shost = scsi_host_alloc(&aac_driver_template, sizeof(struct aac_dev));
+#if 0
+printk(KERN_INFO "scsi_host_alloc(%p,%d)=%p\n", &aac_driver_template, sizeof(struct aac_dev), shost);
+#endif
 	if (!shost)
 		goto out_disable_pdev;
 
 	shost->irq = pdev->irq;
 	shost->base = pci_resource_start(pdev, 0);
-	shost->unique_id = aac_count - 1;
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+	scsi_set_pci_device(shost, pdev);
+#elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9))
+	scsi_set_device(shost, &pdev->dev);
+#endif
+	shost->unique_id = unique_id;
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+	/*
+	 *	This function is called after the device list
+	 *	has been built to find the tagged queueing
+	 *	depth supported for each device.
+	 */
+	shost->select_queue_depths = aac_queuedepth;
+#endif
+#if (defined(SERVICE_ACTION_IN))
+	shost->max_cmd_len = 16;
+#endif
 
 	aac = (struct aac_dev *)shost->hostdata;
 	aac->scsi_host_ptr = shost;	
@@ -539,19 +1825,28 @@ static int __devinit aac_probe_one(struc
 	aac->name = aac_driver_template.name;
 	aac->id = shost->unique_id;
 	aac->cardtype =  index;
+	INIT_LIST_HEAD(&aac->entry);
 
-	aac->fibs = kmalloc(sizeof(struct fib) * AAC_NUM_FIB, GFP_KERNEL);
+	aac->fibs = kmalloc(sizeof(struct fib) * (shost->can_queue + AAC_NUM_MGT_FIB), GFP_KERNEL);
 	if (!aac->fibs)
 		goto out_free_host;
 	spin_lock_init(&aac->fib_lock);
 
-	/* Initialize the ordinal number of the device to -1 */
-	fsa_dev_ptr = &aac->fsa_dev;
-	for (container = 0; container < MAXIMUM_NUM_CONTAINERS; container++)
-		fsa_dev_ptr->devname[container][0] = '\0';
-
-	if ((*aac_drivers[index].init)(aac))
+	/*
+	 *	Map in the registers from the adapter.
+	 */
+	aac->base_size = AAC_MIN_FOOTPRINT_SIZE;
+	if ((aac->regs.sa = ioremap(
+	  (unsigned long)aac->scsi_host_ptr->base, AAC_MIN_FOOTPRINT_SIZE))
+	  == NULL) {	
+		printk(KERN_WARNING "%s: unable to map adapter.\n",
+		  AAC_DRIVERNAME);
 		goto out_free_fibs;
+	}
+	if ((*aac_drivers[index].init)(aac))
+		goto out_unmap;
+
+	aac_get_fw_debug_buffer(aac);
 
 	/*
 	 * If we had set a smaller DMA mask earlier, set it to 4gig
@@ -559,10 +1854,23 @@ static int __devinit aac_probe_one(struc
 	 * address space.
 	 */
 	if (aac_drivers[index].quirks & AAC_QUIRK_31BIT)
-		if (pci_set_dma_mask(pdev, 0xFFFFFFFFULL))
-			goto out_free_fibs;
+		if (pci_set_dma_mask(pdev, DMA_32BIT_MASK))
+			goto out_deinit;
+
+	aac->maximum_num_channels = aac_drivers[index].channels;
+	error = aac_get_adapter_info(aac);
+	if (error < 0)
+		goto out_deinit;
 
-	aac_get_adapter_info(aac);
+	/*
+	 * Lets override negotiations and drop the maximum SG limit to 34
+	 */
+	if ((aac_drivers[index].quirks & AAC_QUIRK_34SG)
+	 && (aac->scsi_host_ptr->sg_tablesize > 34)) {
+		aac->scsi_host_ptr->sg_tablesize = 34;
+		aac->scsi_host_ptr->max_sectors
+		  = (aac->scsi_host_ptr->sg_tablesize * 8) + 112;
+	}
 
 	/*
 	 * max channel will be the physical channels plus 1 virtual channel
@@ -570,25 +1878,36 @@ static int __devinit aac_probe_one(struc
 	 * physical channels are address by their actual physical number+1
 	 */
 	if (aac->nondasd_support == 1)
-		shost->max_channel = aac_drivers[index].channels+1;
+		shost->max_channel = aac->maximum_num_channels+1;
 	else
 		shost->max_channel = 1;
 
+	aac_get_config_status(aac);
 	aac_get_containers(aac);
-	aac_devices[aac_count-1] = aac;
+	list_add(&aac->entry, insert);
+
+	shost->max_id = aac->maximum_num_containers;
+	if (shost->max_id < aac->maximum_num_physicals)
+		shost->max_id = aac->maximum_num_physicals;
+	if (shost->max_id < MAXIMUM_NUM_CONTAINERS)
+		shost->max_id = MAXIMUM_NUM_CONTAINERS;
+	else
+		shost->this_id = shost->max_id;
 
 	/*
 	 * dmb - we may need to move the setting of these parms somewhere else once
 	 * we get a fib that can report the actual numbers
 	 */
-	shost->max_id = MAXIMUM_NUM_CONTAINERS;
 	shost->max_lun = AAC_MAX_LUN;
 
+	pci_set_drvdata(pdev, shost);
+
 	error = scsi_add_host(shost, &pdev->dev);
 	if (error)
 		goto out_deinit;
-
-	pci_set_drvdata(pdev, shost);
+	fwprintf((aac, HBA_FLAGS_DBG_FW_PRINT_B,
+	  "Linux %s driver (%s)",
+	  AAC_DRIVERNAME, aac_driver_version));
 	scsi_scan_host(shost);
 
 	return 0;
@@ -598,18 +1917,20 @@ static int __devinit aac_probe_one(struc
 	wait_for_completion(&aac->aif_completion);
 
 	aac_send_shutdown(aac);
+	aac_adapter_disable_int(aac);
 	fib_map_free(aac);
 	pci_free_consistent(aac->pdev, aac->comm_size, aac->comm_addr, aac->comm_phys);
 	kfree(aac->queues);
 	free_irq(pdev->irq, aac);
-	iounmap((void * )aac->regs.sa);
+ out_unmap:
+	iounmap(aac->regs.sa);
  out_free_fibs:
 	kfree(aac->fibs);
+	kfree(aac->fsa_dev);
  out_free_host:
 	scsi_host_put(shost);
  out_disable_pdev:
 	pci_disable_device(pdev);
-	aac_count--;
  out:
 	return error;
 }
@@ -625,28 +1946,21 @@ static void __devexit aac_remove_one(str
 	wait_for_completion(&aac->aif_completion);
 
 	aac_send_shutdown(aac);
+	aac_adapter_disable_int(aac);
 	fib_map_free(aac);
 	pci_free_consistent(aac->pdev, aac->comm_size, aac->comm_addr,
 			aac->comm_phys);
 	kfree(aac->queues);
 
 	free_irq(pdev->irq, aac);
-	iounmap((void * )aac->regs.sa);
+	iounmap(aac->regs.sa);
 	
 	kfree(aac->fibs);
+	kfree(aac->fsa_dev);
 	
+	list_del(&aac->entry);
 	scsi_host_put(shost);
 	pci_disable_device(pdev);
-
-	/*
-	 * We don't decrement aac_count here because adapters can be unplugged
-	 * in a different order than they were detected.  If we're ever going
-	 * to overflow MAXIMUM_NUM_ADAPTERS we'll have to consider using a
-	 * bintmap of free aac_devices slots.
-	 */
-#if 0
-	aac_count--;
-#endif
 }
 
 static struct pci_driver aac_pci_driver = {
@@ -656,15 +1970,35 @@ static struct pci_driver aac_pci_driver 
 	.remove		= __devexit_p(aac_remove_one),
 };
 
+static int aac_reboot_event(struct notifier_block * n, ulong code, void *p)
+{
+	if ((code == SYS_RESTART)
+	 || (code == SYS_HALT)
+	 || (code == SYS_POWER_OFF)) {
+		struct aac_dev *aac;
+
+		list_for_each_entry(aac, &aac_devices, entry)
+			aac_send_shutdown(aac);
+	}
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block aac_reboot_notifier =
+{
+	aac_reboot_event,
+	NULL,
+	0
+};
+
 static int __init aac_init(void)
 {
 	int error;
 	
-	printk(KERN_INFO "Red Hat/Adaptec aacraid driver (%s %s)\n",
-			AAC_DRIVER_VERSION, AAC_DRIVER_BUILD_DATE);
+	printk(KERN_INFO "Adaptec %s driver (%s)\n",
+	  AAC_DRIVERNAME, aac_driver_version);
 
-	error = pci_module_init(&aac_pci_driver);
-	if (error)
+	error = pci_register_driver(&aac_pci_driver);
+	if (error < 0)
 		return error;
 
 	aac_cfg_major = register_chrdev( 0, "aac", &aac_cfg_fops);
@@ -672,27 +2006,57 @@ static int __init aac_init(void)
 		printk(KERN_WARNING
 		       "aacraid: unable to register \"aac\" device.\n");
 	}
-#ifdef CONFIG_COMPAT
-	register_ioctl32_conversion(FSACTL_MINIPORT_REV_CHECK, NULL);
-	register_ioctl32_conversion(FSACTL_SENDFIB, NULL);
-	register_ioctl32_conversion(FSACTL_OPEN_GET_ADAPTER_FIB, NULL);
-	register_ioctl32_conversion(FSACTL_GET_NEXT_ADAPTER_FIB, 
-		aac_get_next_adapter_fib_ioctl);
-	register_ioctl32_conversion(FSACTL_CLOSE_GET_ADAPTER_FIB, NULL);
-	register_ioctl32_conversion(FSACTL_SEND_RAW_SRB, NULL);
-	register_ioctl32_conversion(FSACTL_GET_PCI_INFO, NULL);
-	register_ioctl32_conversion(FSACTL_QUERY_DISK, NULL);
-	register_ioctl32_conversion(FSACTL_DELETE_DISK, NULL);
-	register_ioctl32_conversion(FSACTL_FORCE_DELETE_DISK, NULL);
-	register_ioctl32_conversion(FSACTL_GET_CONTAINERS, NULL);
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11))
+#if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) ? defined(__x86_64__) : defined(CONFIG_COMPAT))
+	aac_ioctl32(FSACTL_MINIPORT_REV_CHECK, sys_ioctl);
+	aac_ioctl32(FSACTL_SENDFIB, sys_ioctl);
+	aac_ioctl32(FSACTL_OPEN_GET_ADAPTER_FIB, sys_ioctl);
+	aac_ioctl32(FSACTL_GET_NEXT_ADAPTER_FIB,
+	  aac_get_next_adapter_fib_ioctl);
+	aac_ioctl32(FSACTL_CLOSE_GET_ADAPTER_FIB, sys_ioctl);
+	aac_ioctl32(FSACTL_SEND_RAW_SRB, sys_ioctl);
+	aac_ioctl32(FSACTL_GET_PCI_INFO, sys_ioctl);
+	aac_ioctl32(FSACTL_QUERY_DISK, sys_ioctl);
+	aac_ioctl32(FSACTL_DELETE_DISK, sys_ioctl);
+	aac_ioctl32(FSACTL_FORCE_DELETE_DISK, sys_ioctl);
+	aac_ioctl32(FSACTL_GET_CONTAINERS, sys_ioctl);
+#if (defined(FSACTL_REGISTER_FIB_SEND))
+	aac_ioctl32(FSACTL_REGISTER_FIB_SEND, sys_ioctl);
+#endif
+	aac_ioctl32(FSACTL_GET_VERSION_MATCHING, sys_ioctl);
+	aac_ioctl32(FSACTL_SEND_LARGE_FIB, sys_ioctl);
+#if (defined(AAC_CSMI))
+	aac_csmi_register_ioctl32_conversion();
+#endif
+#endif
+#endif
+#if 0
+printk(KERN_INFO "list_empty(&aac_devices)=%d\n", list_empty(&aac_devices));
+#endif
+	if (!list_empty(&aac_devices)) {
+		register_reboot_notifier(&aac_reboot_notifier);
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+		/* Trigger a target scan in the 2.4 tree */
+		if (!aac_dummy) {
+			aac_dummy = scsi_host_alloc(&aac_driver_template,0);
+#if 0
+printk(KERN_INFO "scsi_host_alloc(%p,0)=%p\n", &aac_driver_template, aac_dummy);
+#endif
+		}
+#if 0
+printk(KERN_INFO "scsi_register_module(MODULE_SCSI_HA,%p)\n", &aac_driver_template);
+#endif
+		scsi_register_module(MODULE_SCSI_HA,&aac_driver_template);
 #endif
+	}
 
 	return 0;
 }
 
 static void __exit aac_exit(void)
 {
-#ifdef CONFIG_COMPAT
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11))
+#if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) ? defined(__x86_64__) : defined(CONFIG_COMPAT))
 	unregister_ioctl32_conversion(FSACTL_MINIPORT_REV_CHECK);
 	unregister_ioctl32_conversion(FSACTL_SENDFIB);
 	unregister_ioctl32_conversion(FSACTL_OPEN_GET_ADAPTER_FIB);
@@ -704,10 +2068,23 @@ static void __exit aac_exit(void)
 	unregister_ioctl32_conversion(FSACTL_DELETE_DISK);
 	unregister_ioctl32_conversion(FSACTL_FORCE_DELETE_DISK);
 	unregister_ioctl32_conversion(FSACTL_GET_CONTAINERS);
+#if (defined(FSACTL_REGISTER_FIB_SEND))
+	unregister_ioctl32_conversion(FSACTL_REGISTER_FIB_SEND);
+#endif
+	unregister_ioctl32_conversion(FSACTL_GET_VERSION_MATCHING);
+	unregister_ioctl32_conversion(FSACTL_SEND_LARGE_FIB);
+#if (defined(AAC_CSMI))
+	aac_csmi_unregister_ioctl32_conversion();
+#endif
+#endif
 #endif
 	unregister_chrdev(aac_cfg_major, "aac");
+	unregister_reboot_notifier(&aac_reboot_notifier);
 	pci_unregister_driver(&aac_pci_driver);
 }
 
 module_init(aac_init);
 module_exit(aac_exit);
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+EXPORT_NO_SYMBOLS;
+#endif
--- linux-2.6.8.1-t043-libata-update/drivers/scsi/aacraid/TODO	2005-09-26 13:33:12.000000000 +0400
+++ aacraid-drv/drivers/scsi/aacraid/TODO	2005-03-03 19:08:40.000000000 +0300
@@ -1,6 +1,3 @@
 o	Testing
 o	More testing
-o	Feature request: display the firmware/bios/etc revisions in the
-	/proc info
-o	Drop irq_mask, basically unused
 o	I/O size increase
--- linux-2.6.8.1-t043-libata-update/drivers/scsi/aacraid/commctrl.c	2005-09-26 13:33:12.000000000 +0400
+++ aacraid-drv/drivers/scsi/aacraid/commctrl.c	2005-05-02 22:56:44.000000000 +0400
@@ -36,12 +36,23 @@
 #include <linux/spinlock.h>
 #include <linux/slab.h>
 #include <linux/completion.h>
+#include <linux/version.h> /* for the following test */
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
 #include <linux/dma-mapping.h>
+#endif
 #include <linux/blkdev.h>
 #include <asm/semaphore.h>
 #include <asm/uaccess.h>
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0))
+#include <scsi/scsi.h>
+#else
+#include "scsi.h"
+#endif
 
 #include "aacraid.h"
+#if (defined(AAC_CSMI))
+# include "csmi.h"
+#endif
 
 /**
  *	ioctl_send_fib	-	send a FIB from userspace
@@ -51,15 +62,45 @@
  *	This routine sends a fib to the adapter on behalf of a user level
  *	program.
  */
+#if (defined(AAC_DEBUG_INSTRUMENT_IOCTL_SENDFIB))
+static char * aac_debug_timestamp(void)
+{
+	unsigned long seconds = get_seconds();
+	static char buffer[80];
+	sprintf(buffer, "%02u:%02u:%02u: ",
+	  (int)((seconds / 3600) % 24),
+	  (int)((seconds / 60) % 60),
+	  (int)(seconds % 60));
+	return buffer;
+}
+# define AAC_DEBUG_PREAMBLE	"%s"
+# define AAC_DEBUG_POSTAMBLE	,aac_debug_timestamp()
+#else
+# define AAC_DEBUG_PREAMBLE	KERN_INFO
+# define AAC_DEBUG_POSTAMBLE
+#endif
  
 static int ioctl_send_fib(struct aac_dev * dev, void __user *arg)
 {
 	struct hw_fib * kfib;
 	struct fib *fibptr;
-
+	struct hw_fib * hw_fib = (struct hw_fib *)0;
+	dma_addr_t hw_fib_pa = (dma_addr_t)0LL;
+	unsigned size;
+	int retval;
+
+#if (defined(AAC_DEBUG_INSTRUMENT_IOCTL) || defined(AAC_DEBUG_INSTRUMENT_IOCTL_SENDFIB))
+	printk(AAC_DEBUG_PREAMBLE "ioctl_send_fib(%p,%p)\n" AAC_DEBUG_POSTAMBLE,
+	  dev, arg);
+#endif
 	fibptr = fib_alloc(dev);
-	if(fibptr == NULL)
+	if(fibptr == NULL) {
+#if (defined(AAC_DEBUG_INSTRUMENT_IOCTL) || defined(AAC_DEBUG_INSTRUMENT_IOCTL_SENDFIB))
+		printk(AAC_DEBUG_PREAMBLE "ioctl_send_fib returns -ENOMEM\n"
+		  AAC_DEBUG_POSTAMBLE);
+#endif
 		return -ENOMEM;
+	}
 		
 	kfib = fibptr->hw_fib;
 	/*
@@ -67,6 +108,10 @@ static int ioctl_send_fib(struct aac_dev
 	 */
 	if (copy_from_user((void *)kfib, arg, sizeof(struct aac_fibhdr))) {
 		fib_free(fibptr);
+#if (defined(AAC_DEBUG_INSTRUMENT_IOCTL) || defined(AAC_DEBUG_INSTRUMENT_IOCTL_SENDFIB))
+		printk(AAC_DEBUG_PREAMBLE "ioctl_send_fib returns -EFAULT\n"
+		  AAC_DEBUG_POSTAMBLE);
+#endif
 		return -EFAULT;
 	}
 	/*
@@ -74,17 +119,24 @@ static int ioctl_send_fib(struct aac_dev
 	 *	will not overrun the buffer when we copy the memory. Return
 	 *	an error if we would.
 	 */
-	if(le32_to_cpu(kfib->header.Size) > sizeof(struct hw_fib) - sizeof(struct aac_fibhdr)) {
-		fib_free(fibptr);
-		return -EINVAL;
+	size = le16_to_cpu(kfib->header.Size) + sizeof(struct aac_fibhdr);
+	if (size < le16_to_cpu(kfib->header.SenderSize))
+		size = le16_to_cpu(kfib->header.SenderSize);
+	if (size > dev->max_fib_size) {
+		/* Highjack the hw_fib */
+		hw_fib = fibptr->hw_fib;
+		hw_fib_pa = fibptr->hw_fib_pa;
+		fibptr->hw_fib = kfib = pci_alloc_consistent(dev->pdev, size, &fibptr->hw_fib_pa);
+		memset(((char *)kfib) + dev->max_fib_size, 0, size - dev->max_fib_size);
+		memcpy(kfib, hw_fib, dev->max_fib_size);
 	}
 
-	if (copy_from_user((void *) kfib, arg, le32_to_cpu(kfib->header.Size) + sizeof(struct aac_fibhdr))) {
-		fib_free(fibptr);
-		return -EFAULT;
+	if (copy_from_user(kfib, arg, size)) {
+		retval = -EFAULT;
+		goto cleanup;
 	}
 
-	if (kfib->header.Command == cpu_to_le32(TakeABreakPt)) {
+	if (kfib->header.Command == cpu_to_le16(TakeABreakPt)) {
 		aac_adapter_interrupt(dev);
 		/*
 		 * Since we didn't really send a fib, zero out the state to allow 
@@ -92,16 +144,43 @@ static int ioctl_send_fib(struct aac_dev
 		 */
 		kfib->header.XferState = 0;
 	} else {
-		int retval = fib_send(kfib->header.Command, fibptr,
-				le32_to_cpu(kfib->header.Size) , FsaNormal,
+#		if (defined(AAC_DEBUG_INSTRUMENT_IOCTL) || defined(AAC_DEBUG_INSTRUMENT_IOCTL_SENDFIB))
+			{
+				u8 * fib = (u8 *)kfib;
+				unsigned len = le16_to_cpu(kfib->header.Size);
+				char buffer[80];
+				char * cp = buffer;
+
+				strcpy(cp, "FIB=");
+				cp += 4;
+				while (len > 0) {
+					if (cp >= &buffer[sizeof(buffer)-4]) {
+						printk (AAC_DEBUG_PREAMBLE
+						  "%s\n" AAC_DEBUG_POSTAMBLE,
+						  buffer);
+						strcpy(cp = buffer, "    ");
+						cp += 4;
+					}
+					sprintf (cp, "%02x ", *(fib++));
+					cp += strlen(cp);
+					--len;
+				}
+				if (cp > &buffer[4])
+					printk (AAC_DEBUG_PREAMBLE "%s\n"
+					  AAC_DEBUG_POSTAMBLE, buffer);
+			}
+			printk(AAC_DEBUG_PREAMBLE "fib_send(%x,,%d,...)\n"
+			  AAC_DEBUG_POSTAMBLE, kfib->header.Command,
+			  le16_to_cpu(kfib->header.Size));
+#		endif
+		retval = fib_send(le16_to_cpu(kfib->header.Command), fibptr,
+				le16_to_cpu(kfib->header.Size) , FsaNormal,
 				1, 1, NULL, NULL);
-		if (retval) {
-			fib_free(fibptr);
-			return retval;
-		}
+		if (retval)
+			goto cleanup;
 		if (fib_complete(fibptr) != 0) {
-			fib_free(fibptr);
-			return -EINVAL;
+			retval = -EINVAL;
+			goto cleanup;
 		}
 	}
 	/*
@@ -112,12 +191,21 @@ static int ioctl_send_fib(struct aac_dev
 	 *	was already included by the adapter.)
 	 */
 
-	if (copy_to_user(arg, (void *)kfib, kfib->header.Size)) {
-		fib_free(fibptr);
-		return -EFAULT;
+	retval = 0;
+	if (copy_to_user(arg, (void *)kfib, size))
+		retval = -EFAULT;
+cleanup:
+	if (hw_fib) {
+		pci_free_consistent(dev->pdev, size, kfib, fibptr->hw_fib_pa);
+		fibptr->hw_fib_pa = hw_fib_pa;
+		fibptr->hw_fib = hw_fib;
 	}
 	fib_free(fibptr);
-	return 0;
+#if (defined(AAC_DEBUG_INSTRUMENT_IOCTL) || defined(AAC_DEBUG_INSTRUMENT_IOCTL_SENDFIB))
+	printk(AAC_DEBUG_PREAMBLE "ioctl_send_fib returns %d\n"
+	  AAC_DEBUG_POSTAMBLE, retval);
+#endif
+	return retval;
 }
 
 /**
@@ -269,7 +357,6 @@ return_fib:
 		kfree(fib->hw_fib);
 		kfree(fib);
 		status = 0;
-		fibctx->jiffies = jiffies/HZ;
 	} else {
 		spin_unlock_irqrestore(&dev->fib_lock, flags);
 		if (f.wait) {
@@ -284,6 +371,7 @@ return_fib:
 			status = -EAGAIN;
 		}	
 	}
+	fibctx->jiffies = jiffies/HZ;
 	return status;
 }
 
@@ -306,8 +394,10 @@ int aac_close_fib_context(struct aac_dev
 		/*
 		 *	Free the space occupied by this copy of the fib.
 		 */
+		spin_unlock_irq(&dev->fib_lock);
 		kfree(fib->hw_fib);
 		kfree(fib);
+		spin_lock_irq(&dev->fib_lock);
 	}
 	/*
 	 *	Remove the Context from the AdapterFibContext List
@@ -320,7 +410,9 @@ int aac_close_fib_context(struct aac_dev
 	/*
 	 *	Free the space occupied by the Context
 	 */
+	spin_unlock_irq(&dev->fib_lock);
 	kfree(fibctx);
+	spin_lock_irq(&dev->fib_lock);
 	return 0;
 }
 
@@ -374,6 +466,15 @@ static int close_getadapter_fib(struct a
 	return status;
 }
 
+int aac_atoi(char ** str)
+{
+	int c, result = 0;
+
+	while (('0' <= (c = *((*str)++))) && (c <= '9'))
+		result = (result * 10) + (c - '0');
+	return result;
+}
+
 /**
  *	check_revision	-	close down user fib context
  *	@dev: adapter
@@ -387,28 +488,71 @@ static int close_getadapter_fib(struct a
 static int check_revision(struct aac_dev *dev, void __user *arg)
 {
 	struct revision response;
+	extern char aac_driver_version[];
+	char * driver_version = aac_driver_version;
+	u32 version;
 
 	response.compat = 1;
-	response.version = dev->adapter_info.kernelrev;
-	response.build = dev->adapter_info.kernelbuild;
+	version = (aac_atoi(&driver_version) << 24) | 0x00000400;
+	version += aac_atoi(&driver_version) << 16;
+	version += aac_atoi(&driver_version);
+	response.version = cpu_to_le32(version);
+#	if (defined(AAC_DRIVER_BUILD))
+		response.build = cpu_to_le32(AAC_DRIVER_BUILD);
+#	else
+		response.build = cpu_to_le32(9999);
+#	endif
 
 	if (copy_to_user(arg, &response, sizeof(response)))
 		return -EFAULT;
 	return 0;
 }
 
+#if (defined(CODE_STREAM_IDENTIFIER))
+/**
+ *	check_code_stream	-	close down user fib context
+ *	@dev: adapter
+ *	@arg: ioctl arguments
+ *
+ *	This routine returns the driver code stream identifier
+ */
+
+static int check_code_stream_identifier(struct aac_dev *dev, void __user *arg)
+{
+	struct VersionMatch response;
+
+	memset (&response, 0, sizeof(response));
+	strncpy (response.driver, CODE_STREAM_IDENTIFIER,
+	  MAX_CODE_STREAM_IDENTIFIER_LENGTH);
+	strncpy (response.firmware, dev->code_stream_identifier,
+	  MAX_CODE_STREAM_IDENTIFIER_LENGTH);
+	if (response.firmware[0] == '\0')
+		response.status = VERSION_MATCH_UNSUPPORTED;
+	else if (strncmp(response.driver, response.firmware,
+	  MAX_CODE_STREAM_IDENTIFIER_LENGTH))
+		response.status = VERSION_MATCH_FAILED;
+	else
+		response.status = VERSION_MATCH_SUCCESS;
+
+	if (copy_to_user(arg, &response, sizeof(response)))
+		return -EFAULT;
+	return 0;
+}
+#endif
+
 /**
  *
  * aac_send_raw_scb
  *
  */
 
-int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
+static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 {
 	struct fib* srbfib;
 	int status;
-	struct aac_srb *srbcmd;
-	struct aac_srb __user *user_srb = arg;
+	struct aac_srb *srbcmd = NULL;
+	struct user_aac_srb *user_srbcmd = NULL;
+	struct user_aac_srb __user *user_srb = arg;
 	struct aac_srb_reply __user *user_reply;
 	struct aac_srb_reply* reply;
 	u32 fibsize = 0;
@@ -424,7 +568,7 @@ int aac_send_raw_srb(struct aac_dev* dev
 
 
 	if (!capable(CAP_SYS_ADMIN)){
-		printk(KERN_DEBUG"aacraid: No permission to send raw srb\n"); 
+		dprintk((KERN_DEBUG"aacraid: No permission to send raw srb\n")); 
 		return -EPERM;
 	}
 	/*
@@ -437,37 +581,68 @@ int aac_send_raw_srb(struct aac_dev* dev
 
 	srbcmd = (struct aac_srb*) fib_data(srbfib);
 
+	memset(sg_list, 0, sizeof(sg_list)); /* cleanup may take issue */
 	if(copy_from_user(&fibsize, &user_srb->count,sizeof(u32))){
-		printk(KERN_DEBUG"aacraid: Could not copy data size from user\n"); 
+		dprintk((KERN_DEBUG"aacraid: Could not copy data size from user\n")); 
 		rcode = -EFAULT;
 		goto cleanup;
 	}
 
-	if (fibsize > FIB_DATA_SIZE_IN_BYTES) {
+	if (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr))) {
 		rcode = -EINVAL;
 		goto cleanup;
 	}
 
-	if(copy_from_user(srbcmd, user_srb,fibsize)){
-		printk(KERN_DEBUG"aacraid: Could not copy srb from user\n"); 
+	user_srbcmd = kmalloc(GFP_KERNEL, fibsize);
+	if (!user_srbcmd) {
+		dprintk((KERN_DEBUG"aacraid: Could not make a copy of the srb\n"));
+		rcode = -ENOMEM;
+		goto cleanup;
+	}
+	if(copy_from_user(user_srbcmd, user_srb,fibsize)){
+		dprintk((KERN_DEBUG"aacraid: Could not copy srb from user\n")); 
 		rcode = -EFAULT;
 		goto cleanup;
 	}
+#	if (defined(AAC_DEBUG_INSTRUMENT_IOCTL))
+		{
+			u8 * srb = (u8 *)srbcmd;
+			unsigned len = fibsize;
+			char buffer[80];
+			char * cp = buffer;
+
+			strcpy(cp, "SRB=");
+			cp += 4;
+			while (len > 0) {
+				if (cp >= &buffer[sizeof(buffer)-4]) {
+					printk (KERN_INFO "%s\n", buffer);
+					strcpy(cp = buffer, "    ");
+					cp += 4;
+				}
+				sprintf (cp, "%02x ", *(srb++));
+				cp += strlen(cp);
+				--len;
+			}
+			if (cp > &buffer[4])
+				printk (KERN_INFO "%s\n", buffer);
+		}
+#	endif
 
 	user_reply = arg+fibsize;
 
-	flags = srbcmd->flags;
+	flags = user_srbcmd->flags; /* from user in cpu order */
 	// Fix up srb for endian and force some values
+
 	srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);	// Force this
-	srbcmd->channel  = cpu_to_le32(srbcmd->channel);
-	srbcmd->id	 = cpu_to_le32(srbcmd->id);
-	srbcmd->lun      = cpu_to_le32(srbcmd->lun);
-	srbcmd->flags    = cpu_to_le32(srbcmd->flags);
-	srbcmd->timeout  = cpu_to_le32(srbcmd->timeout);
+	srbcmd->channel  = cpu_to_le32(user_srbcmd->channel);
+	srbcmd->id	 = cpu_to_le32(user_srbcmd->id);
+	srbcmd->lun      = cpu_to_le32(user_srbcmd->lun);
+	srbcmd->flags    = cpu_to_le32(flags);
+	srbcmd->timeout  = cpu_to_le32(user_srbcmd->timeout);
 	srbcmd->retry_limit =cpu_to_le32(0); // Obsolete parameter
-	srbcmd->cdb_size = cpu_to_le32(srbcmd->cdb_size);
+	srbcmd->cdb_size = cpu_to_le32(user_srbcmd->cdb_size);
 	
-	switch (srbcmd->flags & (SRB_DataIn | SRB_DataOut)) {
+	switch (flags & (SRB_DataIn | SRB_DataOut)) {
 	case SRB_DataOut:
 		data_dir = DMA_TO_DEVICE;
 		break;
@@ -480,116 +655,200 @@ int aac_send_raw_srb(struct aac_dev* dev
 	default:
 		data_dir = DMA_NONE;
 	}
-	if (dev->pae_support == 1) {
-		struct sgmap64* psg = (struct sgmap64*)&srbcmd->sg;
+	if (le32_to_cpu(srbcmd->sg.count) > (sizeof(sg_list)/sizeof(sg_list[0]))) {
+		dprintk((KERN_DEBUG"aacraid: too many sg entries %d\n",
+		  le32_to_cpu(srbcmd->sg.count)));
+		rcode = -EINVAL;
+		goto cleanup;
+	}
+	if (dev->dac_support == 1) {
+		struct user_sgmap64* upsg = (struct user_sgmap64*)&user_srbcmd->sg;
+		struct sgmap64* psg = (struct sgmap64*)&user_srbcmd->sg;
+		struct user_sgmap* usg;
 		byte_count = 0;
 
 		/*
 		 * This should also catch if user used the 32 bit sgmap
 		 */
 		actual_fibsize = sizeof(struct aac_srb) - 
-			sizeof(struct sgentry) + ((srbcmd->sg.count & 0xff) * 
-			 	sizeof(struct sgentry64));
+			sizeof(struct sgentry) +
+			((upsg->count & 0xff) * 
+		 	sizeof(struct sgentry));
 		if(actual_fibsize != fibsize){ // User made a mistake - should not continue
-			printk(KERN_DEBUG"aacraid: Bad Size specified in Raw SRB command\n");
+			dprintk((KERN_DEBUG"aacraid: Bad Size specified in Raw SRB command\n"));
 			rcode = -EINVAL;
 			goto cleanup;
 		}
-		if ((data_dir == DMA_NONE) && psg->count) { 
-			printk(KERN_DEBUG"aacraid: SG with no direction specified in Raw SRB command\n");
+		usg = kmalloc(actual_fibsize - sizeof(struct aac_srb)
+		  + sizeof(struct sgmap), GFP_KERNEL);
+		if (!usg) {
+			dprintk((KERN_DEBUG"aacraid: Allocation error in Raw SRB command\n"));
+			rcode = -ENOMEM;
+			goto cleanup;
+		}
+		memcpy (usg, upsg, actual_fibsize - sizeof(struct aac_srb)
+		  + sizeof(struct sgmap));
+		actual_fibsize = sizeof(struct aac_srb) - 
+			sizeof(struct sgentry) + ((usg->count & 0xff) * 
+			 	sizeof(struct sgentry64));
+		if ((data_dir == DMA_NONE) && upsg->count) {
+			kfree (usg);
+			dprintk((KERN_DEBUG"aacraid: SG with no direction specified in Raw SRB command\n"));
 			rcode = -EINVAL;
 			goto cleanup;
 		}
 
-		for (i = 0; i < psg->count; i++) {
-			dma_addr_t addr; 
-			u64 le_addr;
+		for (i = 0; i < usg->count; i++) {
+			u64 addr;
 			void* p;
-			p = kmalloc(psg->sg[i].count,GFP_KERNEL|__GFP_DMA);
+			/* Does this really need to be GFP_DMA? */
+			p = kmalloc(usg->sg[i].count,GFP_KERNEL|__GFP_DMA);
 			if(p == 0) {
-				printk(KERN_DEBUG"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
-				psg->sg[i].count,i,psg->count);
+				kfree (usg);
+				dprintk((KERN_DEBUG"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
+				  usg->sg[i].count,i,usg->count));
 				rcode = -ENOMEM;
 				goto cleanup;
 			}
-			sg_user[i] = (void __user *)psg->sg[i].addr;
+			sg_user[i] = (void __user *)usg->sg[i].addr;
 			sg_list[i] = p; // save so we can clean up later
 			sg_indx = i;
 
 			if( flags & SRB_DataOut ){
-				if(copy_from_user(p,sg_user[i],psg->sg[i].count)){
-					printk(KERN_DEBUG"aacraid: Could not copy sg data from user\n"); 
+				if(copy_from_user(p,sg_user[i],upsg->sg[i].count)){
+					kfree (usg);
+					dprintk((KERN_DEBUG"aacraid: Could not copy sg data from user\n")); 
 					rcode = -EFAULT;
 					goto cleanup;
 				}
 			}
-			addr = pci_map_single(dev->pdev, p, psg->sg[i].count, data_dir);
+			addr = pci_map_single(dev->pdev, p, usg->sg[i].count, data_dir);
 
-			le_addr = cpu_to_le64(addr);
-			psg->sg[i].addr[1] = (u32)(le_addr>>32);
-			psg->sg[i].addr[0] = (u32)(le_addr & 0xffffffff);
-			psg->sg[i].count = cpu_to_le32(psg->sg[i].count);  
-			byte_count += psg->sg[i].count;
+			psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
+			psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
+			psg->sg[i].count = cpu_to_le32(usg->sg[i].count);  
+			byte_count += usg->sg[i].count;
 		}
+		kfree (usg);
 
 		srbcmd->count = cpu_to_le32(byte_count);
+		psg->count = cpu_to_le32(sg_indx+1);
+#		if (defined(AAC_DEBUG_INSTRUMENT_IOCTL))
+			{
+				u8 * srb = (u8 *)srbfib->hw_fib;
+				unsigned len = actual_fibsize;
+				char buffer[80];
+				char * cp = buffer;
+
+				strcpy(cp, "FIB=");
+				cp += 4;
+				while (len > 0) {
+					if (cp >= &buffer[sizeof(buffer)-4]) {
+						printk (KERN_INFO "%s\n", buffer);
+						strcpy(cp = buffer, "    ");
+						cp += 4;
+					}
+					sprintf (cp, "%02x ", *(srb++));
+					cp += strlen(cp);
+					--len;
+				}
+				if (cp > &buffer[4])
+					printk (KERN_INFO "%s\n", buffer);
+			}
+			printk(KERN_INFO
+			  "fib_send(ScsiPortCommand64,,%d,...)\n",
+			  actual_fibsize);
+#		endif
 		status = fib_send(ScsiPortCommand64, srbfib, actual_fibsize, FsaNormal, 1, 1,NULL,NULL);
 	} else {
+		struct user_sgmap* upsg = &user_srbcmd->sg;
 		struct sgmap* psg = &srbcmd->sg;
 		byte_count = 0;
 
-		actual_fibsize = sizeof (struct aac_srb) + (((srbcmd->sg.count & 0xff) - 1) * sizeof (struct sgentry));
+		actual_fibsize = sizeof (struct aac_srb) + (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) * sizeof (struct sgentry));
 		if(actual_fibsize != fibsize){ // User made a mistake - should not continue
-			printk(KERN_DEBUG"aacraid: Bad Size specified in Raw SRB command\n");
+			dprintk((KERN_DEBUG"aacraid: Bad Size specified in Raw SRB command\n"));
 			rcode = -EINVAL;
 			goto cleanup;
 		}
-		if ((data_dir == DMA_NONE) && psg->count) {
-			printk(KERN_DEBUG"aacraid: SG with no direction specified in Raw SRB command\n");
+		if ((data_dir == DMA_NONE) && upsg->count) {
+			dprintk((KERN_DEBUG"aacraid: SG with no direction specified in Raw SRB command\n"));
 			rcode = -EINVAL;
 			goto cleanup;
 		}
-		for (i = 0; i < psg->count; i++) {
+		for (i = 0; i < upsg->count; i++) {
 			dma_addr_t addr; 
 			void* p;
-			p = kmalloc(psg->sg[i].count,GFP_KERNEL);
+			p = kmalloc(upsg->sg[i].count,GFP_KERNEL);
 			if(p == 0) {
-				printk(KERN_DEBUG"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
-				psg->sg[i].count,i,psg->count);
+				dprintk((KERN_DEBUG"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
+				  upsg->sg[i].count,i,upsg->count));
 				rcode = -ENOMEM;
 				goto cleanup;
 			}
-			sg_user[i] = (void __user *)(psg->sg[i].addr);
+			sg_user[i] = (void __user *)upsg->sg[i].addr;
 			sg_list[i] = p; // save so we can clean up later
 			sg_indx = i;
 
 			if( flags & SRB_DataOut ){
-				if(copy_from_user(p,sg_user[i],psg->sg[i].count)){
-					printk(KERN_DEBUG"aacraid: Could not copy sg data from user\n"); 
+				if(copy_from_user(p, sg_user[i],
+						upsg->sg[i].count)) {
+					dprintk((KERN_DEBUG"aacraid: Could not copy sg data from user\n")); 
 					rcode = -EFAULT;
 					goto cleanup;
 				}
 			}
-			addr = pci_map_single(dev->pdev, p, psg->sg[i].count, data_dir);
+			addr = pci_map_single(dev->pdev, p,
+				upsg->sg[i].count, data_dir);
 
 			psg->sg[i].addr = cpu_to_le32(addr);
-			psg->sg[i].count = cpu_to_le32(psg->sg[i].count);  
-			byte_count += psg->sg[i].count;
+			psg->sg[i].count = cpu_to_le32(upsg->sg[i].count);  
+			byte_count += upsg->sg[i].count;
 		}
 		srbcmd->count = cpu_to_le32(byte_count);
+		psg->count = cpu_to_le32(sg_indx+1);
+#		if (defined(AAC_DEBUG_INSTRUMENT_IOCTL))
+			{
+				u8 * srb = (u8 *)srbfib->hw_fib;
+				unsigned len = actual_fibsize;
+				char buffer[80];
+				char * cp = buffer;
+
+				strcpy(cp, "FIB=");
+				cp += 4;
+				while (len > 0) {
+					if (cp >= &buffer[sizeof(buffer)-4]) {
+						printk (KERN_INFO "%s\n", buffer);
+						strcpy(cp = buffer, "    ");
+						cp += 4;
+					}
+					sprintf (cp, "%02x ", *(srb++));
+					cp += strlen(cp);
+					--len;
+				}
+				if (cp > &buffer[4])
+					printk (KERN_INFO "%s\n", buffer);
+			}
+			printk(KERN_INFO
+			  "fib_send(ScsiPortCommand,,%d,...)\n",
+			  actual_fibsize);
+#		endif
 		status = fib_send(ScsiPortCommand, srbfib, actual_fibsize, FsaNormal, 1, 1, NULL, NULL);
 	}
 
 	if (status != 0){
-		printk(KERN_DEBUG"aacraid: Could not send raw srb fib to hba\n"); 
+		dprintk((KERN_DEBUG"aacraid: Could not send raw srb fib to hba\n")); 
 		rcode = -1;
 		goto cleanup;
 	}
 
 	if( flags & SRB_DataIn ) {
 		for(i = 0 ; i <= sg_indx; i++){
-			if(copy_to_user(sg_user[i],sg_list[i],le32_to_cpu(srbcmd->sg.sg[i].count))){
-				printk(KERN_DEBUG"aacraid: Could not copy sg data to user\n"); 
+			byte_count = le32_to_cpu((dev->dac_support == 1)
+			      ? ((struct sgmap64*)&srbcmd->sg)->sg[i].count
+			      : srbcmd->sg.sg[i].count);
+			if(copy_to_user(sg_user[i],sg_list[i],byte_count)){
+				dprintk((KERN_DEBUG"aacraid: Could not copy sg data to user\n")); 
 				rcode = -EFAULT;
 				goto cleanup;
 
@@ -599,12 +858,13 @@ int aac_send_raw_srb(struct aac_dev* dev
 
 	reply = (struct aac_srb_reply *) fib_data(srbfib);
 	if(copy_to_user(user_reply,reply,sizeof(struct aac_srb_reply))){
-		printk(KERN_DEBUG"aacraid: Could not copy reply to user\n"); 
+		dprintk((KERN_DEBUG"aacraid: Could not copy reply to user\n")); 
 		rcode = -EFAULT;
 		goto cleanup;
 	}
 
 cleanup:
+	kfree(user_srbcmd);
 	for(i=0; i <= sg_indx; i++){
 		kfree(sg_list[i]);
 	}
@@ -621,7 +881,7 @@ struct aac_pci_info {
 };
 
 
-int aac_get_pci_info(struct aac_dev* dev, void __user *arg)
+static int aac_get_pci_info(struct aac_dev* dev, void __user *arg)
 {
         struct aac_pci_info pci_info;
 
@@ -629,29 +889,52 @@ int aac_get_pci_info(struct aac_dev* dev
 	pci_info.slot = PCI_SLOT(dev->pdev->devfn);
 
        if (copy_to_user(arg, &pci_info, sizeof(struct aac_pci_info))) {
-		printk(KERN_DEBUG "aacraid: Could not copy pci info\n");
+               dprintk((KERN_DEBUG "aacraid: Could not copy pci info\n"));
                return -EFAULT;
 	}
         return 0;
- }
+}
  
 
 int aac_do_ioctl(struct aac_dev * dev, int cmd, void __user *arg)
 {
 	int status;
 	
+#if (defined(AAC_DEBUG_INSTRUMENT_IOCTL))
+	if (cmd != FSACTL_GET_NEXT_ADAPTER_FIB)
+		printk("aac_do_ioctl(%p,%x,%p)\n", dev, cmd, arg);
+#endif
 	/*
 	 *	HBA gets first crack
 	 */
 	 
 	status = aac_dev_ioctl(dev, cmd, arg);
-	if(status != -ENOTTY)
+	if(status != -ENOTTY) {
+#if (defined(AAC_DEBUG_INSTRUMENT_IOCTL))
+		printk("aac_do_ioctl returns %d\n", status);
+#endif
 		return status;
+	}
+
+#if (defined(AAC_CSMI))
+	/*
+	 *	HP gets second crack
+	 */
+	 
+	status = aac_csmi_ioctl(dev, cmd, arg);
+	if (status != -ENOTTY) {
+#if (defined(AAC_DEBUG_INSTRUMENT_IOCTL))
+		printk("aac_do_ioctl returns %d\n", status);
+#endif
+		return status;
+	}
 
+#endif
 	switch (cmd) {
 	case FSACTL_MINIPORT_REV_CHECK:
 		status = check_revision(dev, arg);
 		break;
+	case FSACTL_SEND_LARGE_FIB:
 	case FSACTL_SENDFIB:
 		status = ioctl_send_fib(dev, arg);
 		break;
@@ -670,10 +953,19 @@ int aac_do_ioctl(struct aac_dev * dev, i
 	case FSACTL_GET_PCI_INFO:
 		status = aac_get_pci_info(dev,arg);
 		break;
+#if (defined(CODE_STREAM_IDENTIFIER))
+	case FSACTL_GET_VERSION_MATCHING:
+		status = check_code_stream_identifier(dev,arg);
+		break;
+#endif
 	default:
 		status = -ENOTTY;
 	  	break;	
 	}
+#if (defined(AAC_DEBUG_INSTRUMENT_IOCTL))
+	if (cmd != FSACTL_GET_NEXT_ADAPTER_FIB)
+		printk("aac_do_ioctl returns %d\n", status);
+#endif
 	return status;
 }
 
--- linux-2.6.8.1-t043-libata-update/drivers/scsi/aacraid/compat.h	1970-01-01 03:00:00.000000000 +0300
+++ aacraid-drv/drivers/scsi/aacraid/compat.h	2005-05-12 18:45:40.000000000 +0400
@@ -0,0 +1,223 @@
+/*
+ *	Adaptec AAC series RAID controller driver
+ *	(c) Copyright 2001 Red Hat Inc.	<alan@redhat.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+/*
+ * This file is for backwards compatibility with older kernel versions
+ */
+#include <linux/version.h>
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9)) && (!defined(SCSI_HAS_SSLEEP))
+#define ssleep(x) scsi_sleep((x)*HZ)
+#endif
+#ifndef BUG_ON
+#ifndef unlikely
+#ifndef __builtin_expect
+#define __builtin_expect(x, expected_value) (x)
+#endif
+#define unlikely(x) __builtin_expect((x),0)
+#endif
+#define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while (0)
+#endif
+#ifndef min
+#define min(a,b) (((a)<(b))?(a):(b))
+#endif
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
+ typedef unsigned long dma_addr_t;
+#include <linux/kcomp.h>
+#define PCI_ANY_ID (~0)
+#define SCSI_DATA_UNKNOWN	0
+#define SCSI_DATA_WRITE		1
+#define SCSI_DATA_READ		2
+#define SCSI_DATA_NONE		3
+ /* Sigh ... a *lot* more needs to be done for this Grandpa */
+#endif
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+#include <linux/time.h>
+static inline unsigned long get_seconds(void)
+{
+	struct timeval now;
+	do_gettimeofday(&now);
+	return now.tv_sec;
+}
+#define scsi_host_template SHT
+#define DMA_BIDIRECTIONAL	SCSI_DATA_UNKNOWN
+#define DMA_TO_DEVICE		SCSI_DATA_WRITE
+#define DMA_FROM_DEVICE		SCSI_DATA_READ
+#define DMA_NONE		SCSI_DATA_NONE
+#define iminor(x) MINOR(x->i_rdev)
+#define scsi_host_alloc(t,s) scsi_register(t,s)
+#define scsi_host_put(s) scsi_unregister(s)
+#ifndef pci_set_consistent_dma_mask
+#define pci_set_consistent_dma_mask(d,m) 0
+#endif
+#ifndef scsi_scan_host
+#define scsi_scan_host(s)
+#endif
+#define scsi_add_host(s,d) 0
+#if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,4,20)) && !defined(list_for_each_entry))
+#if (!defined(_LINUX_PREFETCH_H))
+static inline void prefetch(const void *x) {;}
+#endif
+#define list_for_each_entry(pos, head, member)                          \
+        for (pos = list_entry((head)->next, typeof(*pos), member),      \
+                     prefetch(pos->member.next);                        \
+             &pos->member != (head);                                    \
+             pos = list_entry(pos->member.next, typeof(*pos), member),  \
+                     prefetch(pos->member.next))
+#endif
+#if (defined(MODULE))
+# define scsi_remove_host(s) \
+	list_for_each_entry(aac, &aac_devices, entry) { \
+		if (aac != (struct aac_dev *)s->hostdata) \
+			break; \
+	} \
+	if (list_empty(&aac_devices) \
+	 || (aac == (struct aac_dev *)s->hostdata)) scsi_unregister_module(MODULE_SCSI_HA,s->hostt)
+#else
+# define scsi_remove_host(s)
+#endif
+#if (!defined(__devexit_p))
+# if (defined(MODULE))
+#  define __devexit_p(x) x
+# else
+#  define __devexit_p(x) NULL
+# endif
+#endif
+#define __user
+#endif
+#if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,6,6)) && (!defined(SCSI_HAS_SCSI_DEVICE_ONLINE)))
+#define scsi_device_online(d) ((d)->online)
+#endif
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9))
+#define __iomem
+#endif
+#if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9)) && !defined(HAS_BITWISE_TYPE))
+typedef u64 __le64;
+typedef u32 __le32;
+typedef u16 __le16;
+#endif
+
+#ifndef DMA_64BIT_MASK
+#define DMA_64BIT_MASK ((dma_addr_t)0xffffffffffffffffULL)
+#endif
+#ifndef DMA_32BIT_MASK
+#define DMA_32BIT_MASK ((dma_addr_t)0xffffffffULL)
+#endif
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)) && (LINUX_VERSION_CODE != KERNEL_VERSION(2,4,9)) && (LINUX_VERSION_CODE != KERNEL_VERSION(2,4,13))
+# define dma_handle ptr
+#endif
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,11))
+#include <linux/blk.h>
+
+static inline unsigned int block_size(kdev_t dev)
+{
+	int retval = BLOCK_SIZE;
+	int major = MAJOR(dev);
+
+	if (blksize_size[major]) {
+		int minor = MINOR(dev);
+		if (blksize_size[major][minor])
+			retval = blksize_size[major][minor];
+	}
+	return retval;
+}
+#endif
+
+#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,4,7))
+
+#ifndef COMPLETION_INITIALIZER
+
+#include <linux/wait.h>
+
+struct completion {
+	unsigned int done;
+	wait_queue_head_t wait;
+};
+#define COMPLETION_INITIALIZER(work) \
+	{ 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
+
+#define DECLARE_COMPLETION(work) \
+	struct completion work = COMPLETION_INITIALIZER(work)
+#define INIT_COMPLETION(x)	((x).done = 0)
+
+static inline void init_completion(struct completion *x)
+{
+	x->done = 0;
+	init_waitqueue_head(&x->wait);
+}
+#endif
+
+#ifndef complete_and_exit
+static inline void complete_and_exit(struct completion *comp, long code)
+{
+	/*
+	if (comp)
+		complete(comp);
+
+	do_exit(code);
+	*/
+}
+#endif
+
+#endif
+
+#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,4,2))
+
+static inline void scsi_set_pci_device(struct Scsi_Host *SHpnt,
+                                       struct pci_dev *pdev)
+{
+//	SHpnt->pci_dev = pdev;
+}
+
+static inline void wait_for_completion(struct completion *x)
+{
+	spin_lock_irq(&x->wait.lock);
+	if (!x->done) {
+		DECLARE_WAITQUEUE(wait, current);
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0))
+		wait.flags |= WQ_FLAG_EXCLUSIVE;
+#endif
+		__add_wait_queue_tail(&x->wait, &wait);
+		do {
+			__set_current_state(TASK_UNINTERRUPTIBLE);
+			spin_unlock_irq(&x->wait.lock);
+			schedule();
+			spin_lock_irq(&x->wait.lock);
+		} while (!x->done);
+		__remove_wait_queue(&x->wait, &wait);
+	}
+	x->done--;
+	spin_unlock_irq(&x->wait.lock);
+}
+
+static inline int pci_set_dma_mask(struct pci_dev *dev, dma_addr_t mask)
+{
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0))
+    dev->dma_mask = mask;
+#endif
+
+    return 0;
+}
+
+#endif
+    
--- linux-2.6.8.1-t043-libata-update/drivers/scsi/aacraid/commsup.c	2005-09-26 13:33:12.000000000 +0400
+++ aacraid-drv/drivers/scsi/aacraid/commsup.c	2005-04-27 16:44:54.000000000 +0400
@@ -25,7 +25,7 @@
  *  commsup.c
  *
  * Abstract: Contain all routines that are required for FSA host/adapter
- *    commuication.
+ *    communication.
  *
  */
 
@@ -36,8 +36,20 @@
 #include <linux/pci.h>
 #include <linux/spinlock.h>
 #include <linux/slab.h>
+#include <linux/delay.h>
 #include <linux/completion.h>
 #include <linux/blkdev.h>
+#include <linux/version.h>	/* Needed for the following */
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+#include <asm/uaccess.h>
+#include "scsi.h"
+#include "hosts.h"
+#else
+#include <scsi/scsi.h>
+#include <scsi/scsi_host.h>
+#include <scsi/scsi_device.h>
+#include <scsi/scsi_driver.h>
+#endif
 #include <asm/semaphore.h>
 
 #include "aacraid.h"
@@ -52,7 +64,31 @@
  
 static int fib_map_alloc(struct aac_dev *dev)
 {
-	if((dev->hw_fib_va = pci_alloc_consistent(dev->pdev, sizeof(struct hw_fib) * AAC_NUM_FIB, &dev->hw_fib_pa))==NULL)
+	dprintk((KERN_INFO
+	  "allocate hardware fibs pci_alloc_consistent(%p, %d * (%d + %d), %p)\n",
+	  dev->pdev, dev->max_fib_size, dev->scsi_host_ptr->can_queue,
+	  AAC_NUM_MGT_FIB, &dev->hw_fib_pa));
+#if 0 && (defined(CONFIG_X86) || defined(CONFIG_X86_64))
+	/* Bug in pci_alloc_consistent dealing with respecting dma map */
+	dev->hw_fib_va = kmalloc(
+	  dev->max_fib_size * (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB),
+	  GFP_ATOMIC|GFP_KERNEL);
+	if (dev->hw_fib_va) {
+		dev->hw_fib_pa = pci_map_single(dev->pdev, dev->hw_fib_va,
+		  dev->max_fib_size * (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB),
+		  DMA_BIDIRECTIONAL);
+		if (dev->hw_fib_pa > (0x80000000UL
+		  - (dev->max_fib_size
+		   * (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB)))) {
+			kfree(dev->hw_fib_va);
+			dev->hw_fib_va = NULL;
+		}
+	}
+	if (dev->hw_fib_va == NULL)
+#endif
+	if((dev->hw_fib_va = pci_alloc_consistent(dev->pdev, dev->max_fib_size
+	  * (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB),
+	  &dev->hw_fib_pa))==NULL)
 		return -ENOMEM;
 	return 0;
 }
@@ -67,7 +103,7 @@ static int fib_map_alloc(struct aac_dev 
 
 void fib_map_free(struct aac_dev *dev)
 {
-	pci_free_consistent(dev->pdev, sizeof(struct hw_fib) * AAC_NUM_FIB, dev->hw_fib_va, dev->hw_fib_pa);
+	pci_free_consistent(dev->pdev, dev->max_fib_size * (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB), dev->hw_fib_va, dev->hw_fib_pa);
 }
 
 /**
@@ -84,17 +120,22 @@ int fib_setup(struct aac_dev * dev)
 	struct hw_fib *hw_fib_va;
 	dma_addr_t hw_fib_pa;
 	int i;
-	
-	if(fib_map_alloc(dev)<0)
+
+	while (((i = fib_map_alloc(dev)) == -ENOMEM)
+	 && (dev->scsi_host_ptr->can_queue > (64 - AAC_NUM_MGT_FIB))) {
+		dev->init->MaxIoCommands = cpu_to_le32((dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB) >> 1);
+		dev->scsi_host_ptr->can_queue = le32_to_cpu(dev->init->MaxIoCommands) - AAC_NUM_MGT_FIB;
+	}
+	if (i<0)
 		return -ENOMEM;
 		
 	hw_fib_va = dev->hw_fib_va;
 	hw_fib_pa = dev->hw_fib_pa;
-	memset(hw_fib_va, 0, sizeof(struct hw_fib) * AAC_NUM_FIB);
+	memset(hw_fib_va, 0, dev->max_fib_size * (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB));
 	/*
 	 *	Initialise the fibs
 	 */
-	for (i = 0, fibptr = &dev->fibs[i]; i < AAC_NUM_FIB; i++, fibptr++) 
+	for (i = 0, fibptr = &dev->fibs[i]; i < (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB); i++, fibptr++) 
 	{
 		fibptr->dev = dev;
 		fibptr->hw_fib = hw_fib_va;
@@ -103,15 +144,15 @@ int fib_setup(struct aac_dev * dev)
 		init_MUTEX_LOCKED(&fibptr->event_wait);
 		spin_lock_init(&fibptr->event_lock);
 		hw_fib_va->header.XferState = cpu_to_le32(0xffffffff);
-		hw_fib_va->header.SenderSize = cpu_to_le16(sizeof(struct hw_fib));
+		hw_fib_va->header.SenderSize = cpu_to_le16(dev->max_fib_size);
 		fibptr->hw_fib_pa = hw_fib_pa;
-		hw_fib_va = (struct hw_fib *)((unsigned char *)hw_fib_va + sizeof(struct hw_fib));
-		hw_fib_pa = hw_fib_pa + sizeof(struct hw_fib); 
+		hw_fib_va = (struct hw_fib *)((unsigned char *)hw_fib_va + dev->max_fib_size);
+		hw_fib_pa = hw_fib_pa + dev->max_fib_size;
 	}
 	/*
 	 *	Add the fib chain to the free list
 	 */
-	dev->fibs[AAC_NUM_FIB-1].next = NULL;
+	dev->fibs[dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB - 1].next = NULL;
 	/*
 	 *	Enable this to debug out of queue space
 	 */
@@ -124,7 +165,7 @@ int fib_setup(struct aac_dev * dev)
  *	@dev: Adapter to allocate the fib for
  *
  *	Allocate a fib from the adapter fib pool. If the pool is empty we
- *	wait for fibs to become free.
+ *	return NULL.
  */
  
 struct fib * fib_alloc(struct aac_dev *dev)
@@ -133,10 +174,10 @@ struct fib * fib_alloc(struct aac_dev *d
 	unsigned long flags;
 	spin_lock_irqsave(&dev->fib_lock, flags);
 	fibptr = dev->free_fib;	
-	/* Cannot sleep here or you get hangs. Instead we did the
-	   maths at compile time. */
-	if(!fibptr)
-		BUG();
+	if(!fibptr){
+		spin_unlock_irqrestore(&dev->fib_lock, flags);
+		return fibptr;
+	}
 	dev->free_fib = fibptr->next;
 	spin_unlock_irqrestore(&dev->fib_lock, flags);
 	/*
@@ -148,9 +189,19 @@ struct fib * fib_alloc(struct aac_dev *d
 	 *	Null out fields that depend on being zero at the start of
 	 *	each I/O
 	 */
-	fibptr->hw_fib->header.XferState = cpu_to_le32(0);
+	fibptr->hw_fib->header.XferState = 0;
 	fibptr->callback = NULL;
 	fibptr->callback_data = NULL;
+#if (defined(AAC_DEBUG_INSTRUMENT_TIMING))
+	{
+		struct timeval now;
+		do_gettimeofday(&now);
+		fibptr->DriverTimeStartS = now.tv_sec;
+		fibptr->DriverTimeStartuS = now.tv_usec;
+	}
+	fibptr->DriverTimeDoneS = 0;
+	fibptr->DriverTimeDoneuS = 0;
+#endif
 
 	return fibptr;
 }
@@ -167,6 +218,18 @@ void fib_free(struct fib * fibptr)
 {
 	unsigned long flags;
 
+#if (defined(AAC_DEBUG_INSTRUMENT_TIMING))
+	struct timeval now;
+	do_gettimeofday(&now);
+	fibptr->DriverTimeDoneS = now.tv_sec;
+	fibptr->DriverTimeDoneuS = now.tv_usec;
+	flags = (fibptr->DriverTimeDoneS - fibptr->DriverTimeStartS) * 1000000L
+	      + fibptr->DriverTimeDoneuS - fibptr->DriverTimeStartuS;
+	if (flags > aac_config.peak_duration) {
+		aac_config.peak_duration = flags;
+		printk(KERN_INFO "peak_duration %lduseconds\n", flags);
+	}
+#endif
 	spin_lock_irqsave(&fibptr->dev->fib_lock, flags);
 	if (fibptr->flags & FIB_CONTEXT_FLAG_TIMED_OUT) {
 		aac_config.fib_timeouts++;
@@ -175,7 +238,8 @@ void fib_free(struct fib * fibptr)
 	} else {
 		if (fibptr->hw_fib->header.XferState != 0) {
 			printk(KERN_WARNING "fib_free, XferState != 0, fibptr = 0x%p, XferState = 0x%x\n", 
-				 (void*)fibptr, fibptr->hw_fib->header.XferState);
+				 (void*)fibptr, 
+				 le32_to_cpu(fibptr->hw_fib->header.XferState));
 		}
 		fibptr->next = fibptr->dev->free_fib;
 		fibptr->dev->free_fib = fibptr;
@@ -195,11 +259,11 @@ void fib_init(struct fib *fibptr)
 	struct hw_fib *hw_fib = fibptr->hw_fib;
 
 	hw_fib->header.StructType = FIB_MAGIC;
-	hw_fib->header.Size = cpu_to_le16(sizeof(struct hw_fib));
-        hw_fib->header.XferState = cpu_to_le32(HostOwned | FibInitialized | FibEmpty | FastResponseCapable);
-	hw_fib->header.SenderFibAddress = cpu_to_le32(fibptr->hw_fib_pa);
+	hw_fib->header.Size = cpu_to_le16(fibptr->dev->max_fib_size);
+	hw_fib->header.XferState = cpu_to_le32(HostOwned | FibInitialized | FibEmpty | FastResponseCapable);
+	hw_fib->header.SenderFibAddress = 0; /* Filled in later if needed */
 	hw_fib->header.ReceiverFibAddress = cpu_to_le32(fibptr->hw_fib_pa);
-	hw_fib->header.SenderSize = cpu_to_le16(sizeof(struct hw_fib));
+	hw_fib->header.SenderSize = cpu_to_le16(fibptr->dev->max_fib_size);
 }
 
 /**
@@ -210,12 +274,12 @@ void fib_init(struct fib *fibptr)
  *	caller.
  */
  
-void fib_dealloc(struct fib * fibptr)
+static void fib_dealloc(struct fib * fibptr)
 {
 	struct hw_fib *hw_fib = fibptr->hw_fib;
 	if(hw_fib->header.StructType != FIB_MAGIC) 
 		BUG();
-	hw_fib->header.XferState = cpu_to_le32(0);        
+	hw_fib->header.XferState = 0;        
 }
 
 /*
@@ -241,6 +305,7 @@ void fib_dealloc(struct fib * fibptr)
 static int aac_get_entry (struct aac_dev * dev, u32 qid, struct aac_entry **entry, u32 * index, unsigned long *nonotify)
 {
 	struct aac_queue * q;
+	unsigned long idx;
 
 	/*
 	 *	All of the queues wrap when they reach the end, so we check
@@ -250,10 +315,23 @@ static int aac_get_entry (struct aac_dev
 	 */
 
 	q = &dev->queues->queue[qid];
-	
-	*index = le32_to_cpu(*(q->headers.producer));
-	if ((*index - 2) == le32_to_cpu(*(q->headers.consumer)))
+
+	idx = *index = le32_to_cpu(*(q->headers.producer));
+	/* Interrupt Moderation, only interrupt for first two entries */
+	if (idx != le32_to_cpu(*(q->headers.consumer))) {
+		if (--idx == 0) {
+			if (qid == AdapHighCmdQueue)
+				idx = ADAP_HIGH_CMD_ENTRIES;
+			else if (qid == AdapNormCmdQueue)
+				idx = ADAP_NORM_CMD_ENTRIES;
+			else if (qid == AdapHighRespQueue) 
+	        		idx = ADAP_HIGH_RESP_ENTRIES;
+			else if (qid == AdapNormRespQueue) 
+				idx = ADAP_NORM_RESP_ENTRIES;
+		}
+		if (idx != le32_to_cpu(*(q->headers.consumer)))
 			*nonotify = 1; 
+	}
 
 	if (qid == AdapHighCmdQueue) {
 	        if (*index >= ADAP_HIGH_CMD_ENTRIES)
@@ -278,7 +356,7 @@ static int aac_get_entry (struct aac_dev
 	}
 
         if ((*index + 1) == le32_to_cpu(*(q->headers.consumer))) { /* Queue is full */
-		printk(KERN_WARNING "Queue %d full, %d outstanding.\n",
+		printk(KERN_WARNING "Queue %d full, %u outstanding.\n",
 				qid, q->numpending);
 		return 0;
 	} else {
@@ -307,10 +385,7 @@ static int aac_queue_get(struct aac_dev 
 {
 	struct aac_entry * entry = NULL;
 	int map = 0;
-	struct aac_queue * q = &dev->queues->queue[qid];
 		
-	spin_lock_irqsave(q->lock, q->SavedIrql);
-	    
 	if (qid == AdapHighCmdQueue || qid == AdapNormCmdQueue) 
 	{
 		/*  if no entries wait for some if caller wants to */
@@ -344,43 +419,7 @@ static int aac_queue_get(struct aac_dev 
 	 *	in the queue entry.
 	 */
 	if (map)
-		entry->addr = fibptr->hw_fib_pa;
-	return 0;
-}
-
-
-/**
- *	aac_insert_entry	-	insert a queue entry
- *	@dev: Adapter
- *	@index: Index of entry to insert
- *	@qid: Queue number
- *	@nonotify: Suppress adapter notification
- *
- *	Gets the next free QE off the requested priorty adapter command
- *	queue and associates the Fib with the QE. The QE represented by
- *	index is ready to insert on the queue when this routine returns
- *	success.
- */
- 
-static int aac_insert_entry(struct aac_dev * dev, u32 index, u32 qid, unsigned long nonotify) 
-{
-	struct aac_queue * q = &dev->queues->queue[qid];
-
-	if(q == NULL)
-		BUG();
-	*(q->headers.producer) = cpu_to_le32(index + 1);
-	spin_unlock_irqrestore(q->lock, q->SavedIrql);
-
-	if (qid == AdapHighCmdQueue ||
-	    qid == AdapNormCmdQueue ||
-	    qid == AdapHighRespQueue ||
-	    qid == AdapNormRespQueue)
-	{
-		if (!nonotify)
-			aac_adapter_notify(dev, qid);
-	}
-	else
-		printk("Suprise insert!\n");
+		entry->addr = cpu_to_le32(fibptr->hw_fib_pa);
 	return 0;
 }
 
@@ -408,23 +447,28 @@ static int aac_insert_entry(struct aac_d
  *	an event to wait on must be supplied. This event will be set when a
  *	response FIB is received from the adapter.
  */
- 
-int fib_send(u16 command, struct fib * fibptr, unsigned long size,  int priority, int wait, int reply, fib_callback callback, void * callback_data)
+#if (defined(FSACTL_REGISTER_FIB_SEND))
+fib_send_t fib_send = aac_fib_send;
+#endif
+
+int aac_fib_send(u16 command, struct fib * fibptr, unsigned long size,
+		int priority, int wait, int reply, fib_callback callback,
+		void * callback_data)
 {
-	u32 index;
 	u32 qid;
 	struct aac_dev * dev = fibptr->dev;
-	unsigned long nointr = 0;
 	struct hw_fib * hw_fib = fibptr->hw_fib;
 	struct aac_queue * q;
 	unsigned long flags = 0;
-	if (!(le32_to_cpu(hw_fib->header.XferState) & HostOwned))
+	unsigned long qflags;
+
+	if (!(hw_fib->header.XferState & cpu_to_le32(HostOwned)))
 		return -EBUSY;
 	/*
 	 *	There are 5 cases with the wait and reponse requested flags. 
 	 *	The only invalid cases are if the caller requests to wait and
 	 *	does not request a response and if the caller does not want a
-	 *	response and the Fibis not allocated from pool. If a response
+	 *	response and the Fib is not allocated from pool. If a response
 	 *	is not requesed the Fib will just be deallocaed by the DPC
 	 *	routine when the response comes back from the adapter. No
 	 *	further processing will be done besides deleting the Fib. We 
@@ -447,7 +491,7 @@ int fib_send(u16 command, struct fib * f
 	 *	Map the fib into 32bits by using the fib number
 	 */
 
-	hw_fib->header.SenderFibAddress = cpu_to_le32(((u32)(fibptr-dev->fibs)) << 1);
+	hw_fib->header.SenderFibAddress = cpu_to_le32(((u32)(fibptr - dev->fibs)) << 2);
 	hw_fib->header.SenderData = (u32)(fibptr - dev->fibs);
 	/*
 	 *	Set FIB state to indicate where it came from and if we want a
@@ -477,19 +521,7 @@ int fib_send(u16 command, struct fib * f
 		hw_fib->header.XferState |= cpu_to_le32(NormalPriority);
 		qid = AdapNormCmdQueue;
 	}
-	q = &dev->queues->queue[qid];
 
-	if(wait)
-		spin_lock_irqsave(&fibptr->event_lock, flags);
-	if(aac_queue_get( dev, &index, qid, hw_fib, 1, fibptr, &nointr)<0)
-		return -EWOULDBLOCK;
-	dprintk((KERN_DEBUG "fib_send: inserting a queue entry at index %d.\n",index));
-	dprintk((KERN_DEBUG "Fib contents:.\n"));
-	dprintk((KERN_DEBUG "  Command =               %d.\n", hw_fib->header.Command));
-	dprintk((KERN_DEBUG "  XferState  =            %x.\n", hw_fib->header.XferState));
-	dprintk((KERN_DEBUG "  hw_fib va being sent=%p\n",fibptr->hw_fib));
-	dprintk((KERN_DEBUG "  hw_fib pa being sent=%lx\n",(ulong)fibptr->hw_fib_pa));
-	dprintk((KERN_DEBUG "  fib being sent=%p\n",fibptr));
 	/*
 	 *	Fill in the Callback and CallbackContext if we are not
 	 *	going to wait.
@@ -498,22 +530,114 @@ int fib_send(u16 command, struct fib * f
 		fibptr->callback = callback;
 		fibptr->callback_data = callback_data;
 	}
-	FIB_COUNTER_INCREMENT(aac_config.FibsSent);
-	list_add_tail(&fibptr->queue, &q->pendingq);
-	q->numpending++;
 
 	fibptr->done = 0;
 	fibptr->flags = 0;
 
-	if(aac_insert_entry(dev, index, qid, (nointr & aac_config.irq_mod)) < 0)
-		return -EWOULDBLOCK;
+#	if (defined(AAC_DEBUG_INSTRUMENT_FIB))
+		printk(KERN_INFO "Fib content %p[%d] P=%llx:\n",
+		  hw_fib, le16_to_cpu(hw_fib->header.Size), fibptr->hw_fib_pa);
+		{
+			int size = le16_to_cpu(hw_fib->header.Size)
+					/ sizeof(u32);
+			char buffer[80];
+			u32 * up = (u32 *)hw_fib;
+
+			while (size > 0) {
+				sprintf (buffer,
+				  "  %08x %08x %08x %08x %08x %08x %08x %08x\n",
+				  up[0], up[1], up[2], up[3], up[4], up[5],
+				  up[6], up[7]);
+				up += 8;
+				size -= 8;
+				if (size < 0) {
+					buffer[73+(size*9)] = '\n';
+					buffer[74+(size*9)] = '\0';
+				}
+				printk(KERN_INFO "%s", buffer);
+			}
+		}
+#	endif
+
+	FIB_COUNTER_INCREMENT(aac_config.FibsSent);
+
+	dprintk((KERN_DEBUG "Fib contents:.\n"));
+	dprintk((KERN_DEBUG "  Command =               %d.\n", le32_to_cpu(hw_fib->header.Command)));
+	dprintk((KERN_DEBUG "  SubCommand =            %d.\n", le32_to_cpu(((struct aac_query_mount *)fib_data(fibptr))->command)));
+	dprintk((KERN_DEBUG "  XferState  =            %x.\n", le32_to_cpu(hw_fib->header.XferState)));
+	dprintk((KERN_DEBUG "  hw_fib va being sent=%p\n",fibptr->hw_fib));
+	dprintk((KERN_DEBUG "  hw_fib pa being sent=%lx\n",(ulong)fibptr->hw_fib_pa));
+	dprintk((KERN_DEBUG "  fib being sent=%p\n",fibptr));
+
+	q = &dev->queues->queue[qid];
+
+	if(wait)
+		spin_lock_irqsave(&fibptr->event_lock, flags);
+	spin_lock_irqsave(q->lock, qflags);
+	if (dev->new_comm_interface) {
+		unsigned long count = 10000000L; /* 50 seconds */
+		list_add_tail(&fibptr->queue, &q->pendingq);
+		q->numpending++;
+		spin_unlock_irqrestore(q->lock, qflags);
+		while (aac_adapter_send(fibptr) != 0) {
+			if (--count == 0) {
+				if (wait)
+					spin_unlock_irqrestore(&fibptr->event_lock, flags);
+				spin_lock_irqsave(q->lock, qflags);
+				q->numpending--;
+				list_del(&fibptr->queue);
+				spin_unlock_irqrestore(q->lock, qflags);
+				return -ETIMEDOUT;
+			}
+			udelay(5);
+		}
+	} else {
+		u32 index;
+		unsigned long nointr = 0;
+		aac_queue_get( dev, &index, qid, hw_fib, 1, fibptr, &nointr);
+
+		list_add_tail(&fibptr->queue, &q->pendingq);
+		q->numpending++;
+		*(q->headers.producer) = cpu_to_le32(index + 1);
+		spin_unlock_irqrestore(q->lock, qflags);
+		dprintk((KERN_DEBUG "fib_send: inserting a queue entry at index %d.\n",index));
+		if (!(nointr & aac_config.irq_mod))
+			aac_adapter_notify(dev, qid);
+	}
+
 	/*
 	 *	If the caller wanted us to wait for response wait now. 
 	 */
     
 	if (wait) {
 		spin_unlock_irqrestore(&fibptr->event_lock, flags);
-		down(&fibptr->event_wait);
+		/* Only set for first known interruptable command */
+		if (wait < 0) {
+			/*
+			 * *VERY* Dangerous to time out a command, the
+			 * assumption is made that we have no hope of
+			 * functioning because an interrupt routing or other
+			 * hardware failure has occurred.
+			 */
+			unsigned long count = 36000000L; /* 3 minutes */
+			while (down_trylock(&fibptr->event_wait)) {
+				if (--count == 0) {
+					spin_lock_irqsave(q->lock, qflags);
+					q->numpending--;
+					list_del(&fibptr->queue);
+					spin_unlock_irqrestore(q->lock, qflags);
+					if (wait == -1) {
+	        				printk(KERN_ERR "aacraid: fib_send: first asynchronous command timed out.\n"
+						  "Usually a result of a PCI interrupt routing problem;\n"
+						  "update mother board BIOS or consider utilizing one of\n"
+						  "the SAFE mode kernel options (acpi, apic etc)\n");
+					}
+					return -ETIMEDOUT;
+				}
+				udelay(5);
+			}
+		} else
+			down(&fibptr->event_wait);
 		if(fibptr->done == 0)
 			BUG();
 			
@@ -566,12 +690,6 @@ int aac_consumer_get(struct aac_dev * de
 	return(status);
 }
 
-int aac_consumer_avail(struct aac_dev *dev, struct aac_queue * q)
-{
-	return (le32_to_cpu(*q->headers.producer) != le32_to_cpu(*q->headers.consumer));
-}
-
-
 /**
  *	aac_consumer_free	-	free consumer entry
  *	@dev: Adapter
@@ -631,13 +749,22 @@ int fib_adapter_complete(struct fib * fi
 {
 	struct hw_fib * hw_fib = fibptr->hw_fib;
 	struct aac_dev * dev = fibptr->dev;
+	struct aac_queue * q;
 	unsigned long nointr = 0;
-	if (le32_to_cpu(hw_fib->header.XferState) == 0)
+	unsigned long qflags;
+	u32 qid;
+
+	if (hw_fib->header.XferState == 0) {
+		if (dev->new_comm_interface)
+			kfree (hw_fib);
         	return 0;
+	}
 	/*
 	 *	If we plan to do anything check the structure type first.
 	 */ 
 	if ( hw_fib->header.StructType != FIB_MAGIC ) {
+		if (dev->new_comm_interface)
+			kfree (hw_fib);
         	return -EINVAL;
 	}
 	/*
@@ -648,37 +775,31 @@ int fib_adapter_complete(struct fib * fi
 	 *	send the completed cdb to the adapter.
 	 */
 	if (hw_fib->header.XferState & cpu_to_le32(SentFromAdapter)) {
-	        hw_fib->header.XferState |= cpu_to_le32(HostProcessed);
-	        if (hw_fib->header.XferState & cpu_to_le32(HighPriority)) {
-        		u32 index;
-       			if (size) 
-			{
-				size += sizeof(struct aac_fibhdr);
-				if (size > le16_to_cpu(hw_fib->header.SenderSize))
-					return -EMSGSIZE;
-				hw_fib->header.Size = cpu_to_le16(size);
-			}
-			if(aac_queue_get(dev, &index, AdapHighRespQueue, hw_fib, 1, NULL, &nointr) < 0) {
-				return -EWOULDBLOCK;
-			}
-			if (aac_insert_entry(dev, index, AdapHighRespQueue,  (nointr & (int)aac_config.irq_mod)) != 0) {
-			}
-		}
-		else if (hw_fib->header.XferState & NormalPriority) 
-		{
-			u32 index;
-
+		if (dev->new_comm_interface) {
+			kfree (hw_fib);
+		} else {
+	       		u32 index;
+		        hw_fib->header.XferState |= cpu_to_le32(HostProcessed);
+		        if (hw_fib->header.XferState & cpu_to_le32(HighPriority))
+				qid = AdapHighRespQueue;
+			else if (hw_fib->header.XferState &
+					cpu_to_le32(NormalPriority))
+				qid = AdapNormRespQueue;
+			else
+				return 0;
 			if (size) {
 				size += sizeof(struct aac_fibhdr);
 				if (size > le16_to_cpu(hw_fib->header.SenderSize)) 
 					return -EMSGSIZE;
 				hw_fib->header.Size = cpu_to_le16(size);
 			}
-			if (aac_queue_get(dev, &index, AdapNormRespQueue, hw_fib, 1, NULL, &nointr) < 0) 
-				return -EWOULDBLOCK;
-			if (aac_insert_entry(dev, index, AdapNormRespQueue, (nointr & (int)aac_config.irq_mod)) != 0) 
-			{
-			}
+			q = &dev->queues->queue[qid];
+			spin_lock_irqsave(q->lock, qflags);
+			aac_queue_get(dev, &index, qid, hw_fib, 1, NULL, &nointr);
+			*(q->headers.producer) = cpu_to_le32(index + 1);
+			spin_unlock_irqrestore(q->lock, qflags);
+			if (!(nointr & (int)aac_config.irq_mod))
+				aac_adapter_notify(dev, qid);
 		}
 	}
 	else 
@@ -704,7 +825,7 @@ int fib_complete(struct fib * fibptr)
 	 *	Check for a fib which has already been completed
 	 */
 
-	if (hw_fib->header.XferState == cpu_to_le32(0))
+	if (hw_fib->header.XferState == 0)
         	return 0;
 	/*
 	 *	If we plan to do anything check the structure type first.
@@ -749,22 +870,27 @@ int fib_complete(struct fib * fibptr)
 
 void aac_printf(struct aac_dev *dev, u32 val)
 {
-	int length = val & 0xffff;
-	int level = (val >> 16) & 0xffff;
 	char *cp = dev->printfbuf;
-	
-	/*
-	 *	The size of the printfbuf is set in port.c
-	 *	There is no variable or define for it
-	 */
-	if (length > 255)
-		length = 255;
-	if (cp[length] != 0)
-		cp[length] = 0;
-	if (level == LOG_HIGH_ERROR)
-		printk(KERN_WARNING "aacraid:%s", cp);
-	else
-		printk(KERN_INFO "aacraid:%s", cp);
+#if (!defined(AAC_PRINTF_ENABLED))
+	if (dev->printf_enabled)
+#endif
+	{
+		int length = val & 0xffff;
+		int level = (val >> 16) & 0xffff;
+		
+		/*
+		 *	The size of the printfbuf is set in port.c
+		 *	There is no variable or define for it
+		 */
+		if (length > 255)
+			length = 255;
+		if (cp[length] != 0)
+			cp[length] = 0;
+		if (level == LOG_AAC_HIGH_ERROR)
+			printk(KERN_WARNING "aacraid:%s", cp);
+		else
+			printk(KERN_INFO "aacraid:%s", cp);
+	}
 	memset(cp, 0,  256);
 }
 
@@ -781,13 +907,395 @@ void aac_printf(struct aac_dev *dev, u32
 static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr)
 {
 	struct hw_fib * hw_fib = fibptr->hw_fib;
+	struct aac_aifcmd * aifcmd = (struct aac_aifcmd *)hw_fib->data;
+	int busy;
+	u32 container;
+	struct scsi_device *device;
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+	struct scsi_driver * drv;
+#endif
+	enum {
+		NOTHING,
+		DELETE,
+		ADD,
+		CHANGE
+	} DeviceConfigNeeded;
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+	extern struct proc_dir_entry * proc_scsi;
+#endif
+
+	/* Sniff for container changes */
+	dprintk ((KERN_INFO "aac_handle_aif: Aif command=%x type=%x\n",
+	  le32_to_cpu(aifcmd->command), le32_to_cpu(*(u32 *)aifcmd->data)));
+#if (defined(AAC_DEBUG_INSTRUMENT_AIF))
+	printk ("aac_handle_aif: Aif command=%x type=%x\n",
+	  le32_to_cpu(aifcmd->command), le32_to_cpu(*(u32 *)aifcmd->data));
+#endif
+
+	if (!dev)
+		return;
+	container = (u32)-1;
+
+	/*
+	 *	We have set this up to try and minimize the number of
+	 * re-configures that take place. As a result of this when
+	 * certain AIF's come in we will set a flag waiting for another
+	 * type of AIF before setting the re-config flag.
+	 */
+	switch (le32_to_cpu(aifcmd->command)) {
+	case AifCmdDriverNotify:
+		switch (le32_to_cpu(((u32 *)aifcmd->data)[0])) {
+		/*
+		 *	Morph or Expand complete
+		 */
+		case AifDenMorphComplete:
+		case AifDenVolumeExtendComplete:
+			container = le32_to_cpu(((u32 *)aifcmd->data)[1]);
+			if (container >= dev->maximum_num_containers)
+				break;
+			dprintk ((KERN_INFO "container=%d(%d,%d,%d,%d)\n",
+			  container,
+			  (dev && dev->scsi_host_ptr)
+			    ? dev->scsi_host_ptr->host_no
+			    : -1,
+			  CONTAINER_TO_CHANNEL(container),
+			  CONTAINER_TO_ID(container),
+			  CONTAINER_TO_LUN(container)));
+
+			/*
+			 *	Find the Scsi_Device associated with the SCSI
+			 * address. Make sure we have the right array, and if
+			 * so set the flag to initiate a new re-config once we
+			 * see an AifEnConfigChange AIF come through.
+			 */
+
+			if ((dev != (struct aac_dev *)NULL)
+			 && (dev->scsi_host_ptr != (struct Scsi_Host *)NULL)) {
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
+				shost_for_each_device(device, dev->scsi_host_ptr)
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+				list_for_each_entry(device,
+					&dev->scsi_host_ptr->my_devices, siblings)
+#else
+				for (device = dev->scsi_host_ptr->host_queue;
+				  device != (struct scsi_device *)NULL;
+				  device = device->next)
+#endif
+				{
+					if ((device->channel == CONTAINER_TO_CHANNEL(container))
+					 && (device->id == CONTAINER_TO_ID(container))
+					 && (device->lun == CONTAINER_TO_LUN(container))) {
+
+						dev->fsa_dev[container].ConfigNeeded = CHANGE;
+						dev->fsa_dev[container].ConfigWaitingOn = AifEnConfigChange;
+						break;
+					}
+				}
+			}
+		}
+
+		/*
+		 *	If we are waiting on something and this happens to be
+		 * that thing then set the re-configure flag.
+		 */
+		if (container != (u32)-1) {
+			if (container >= dev->maximum_num_containers)
+				break;
+			if (dev->fsa_dev[container].ConfigWaitingOn == le32_to_cpu(*(u32 *)aifcmd->data))
+				dev->fsa_dev[container].ConfigWaitingOn = 0;
+		} else for (container = 0; container < dev->maximum_num_containers; ++container) {
+			if (dev->fsa_dev[container].ConfigWaitingOn == le32_to_cpu(*(u32 *)aifcmd->data))
+				dev->fsa_dev[container].ConfigWaitingOn = 0;
+		}
+		break;
+
+	case AifCmdEventNotify:
+		switch (le32_to_cpu(((u32 *)aifcmd->data)[0])) {
+		/*
+		 *	Add an Array.
+		 */
+		case AifEnAddContainer:
+			container = le32_to_cpu(((u32 *)aifcmd->data)[1]);
+			if (container >= dev->maximum_num_containers)
+				break;
+			dev->fsa_dev[container].ConfigNeeded = ADD;
+			dev->fsa_dev[container].ConfigWaitingOn = AifEnConfigChange;
+			break;
+
+		/*
+		 *	Delete an Array.
+		 */
+		case AifEnDeleteContainer:
+			container = le32_to_cpu(((u32 *)aifcmd->data)[1]);
+			if (container >= dev->maximum_num_containers)
+				break;
+			dev->fsa_dev[container].ConfigNeeded = DELETE;
+			dev->fsa_dev[container].ConfigWaitingOn = AifEnConfigChange;
+			break;
+
+		/*
+		 *	Container change detected. If we currently are not
+		 * waiting on something else, setup to wait on a Config Change.
+		 */
+		case AifEnContainerChange:
+			container = le32_to_cpu(((u32 *)aifcmd->data)[1]);
+			if (container >= dev->maximum_num_containers)
+				break;
+			if (dev->fsa_dev[container].ConfigWaitingOn) {
+				break;
+			}
+			dev->fsa_dev[container].ConfigNeeded = CHANGE;
+			dev->fsa_dev[container].ConfigWaitingOn = AifEnConfigChange;
+			break;
+
+		case AifEnConfigChange:
+			break;
+
+		}
+
+		/*
+		 *	If we are waiting on something and this happens to be
+		 * that thing then set the re-configure flag.
+		 */
+		if (container != (u32)-1) {
+			if (container >= dev->maximum_num_containers)
+				break;
+			if (dev->fsa_dev[container].ConfigWaitingOn == le32_to_cpu(*(u32 *)aifcmd->data))
+				dev->fsa_dev[container].ConfigWaitingOn = 0;
+		} else for (container = 0; container < dev->maximum_num_containers; ++container) {
+			if (dev->fsa_dev[container].ConfigWaitingOn == le32_to_cpu(*(u32 *)aifcmd->data))
+				dev->fsa_dev[container].ConfigWaitingOn = 0;
+		}
+		break;
+
+	case AifCmdJobProgress:
+		/*
+		 *	These are job progress AIF's. When a Clear is being
+		 * done on a container it is initially created then hidden from
+		 * the OS. When the clear completes we don't get a config
+		 * change so we monitor the job status complete on a clear then
+		 * wait for a container change.
+		 */
+
+		if ((((u32 *)aifcmd->data)[1] == cpu_to_le32(AifJobCtrZero))
+		 && ((((u32 *)aifcmd->data)[6] == ((u32 *)aifcmd->data)[5])
+		  || (((u32 *)aifcmd->data)[4] == cpu_to_le32(AifJobStsSuccess)))) {
+			for (container = 0; container < dev->maximum_num_containers; ++container) {
+				/* Stomp on all config sequencing for all containers? */
+				dev->fsa_dev[container].ConfigWaitingOn = AifEnContainerChange;
+				dev->fsa_dev[container].ConfigNeeded = ADD;
+			}
+		}
+		break;
+	}
+
+	DeviceConfigNeeded = NOTHING;
+	for (container = 0; container < dev->maximum_num_containers; ++container) {
+		if ((dev->fsa_dev[container].ConfigWaitingOn == 0)
+		 && (dev->fsa_dev[container].ConfigNeeded != NOTHING)) {
+			DeviceConfigNeeded = dev->fsa_dev[container].ConfigNeeded;
+			dev->fsa_dev[container].ConfigNeeded = NOTHING;
+			break;
+		}
+	}
+	if (DeviceConfigNeeded == NOTHING)
+		return;
+
 	/*
-	 * Set the status of this FIB to be Invalid parameter.
-	 *
-	 *	*(u32 *)fib->data = ST_INVAL;
+	 *	If we decided that a re-configuration needs to be done,
+	 * schedule it here on the way out the door, please close the door
+	 * behind you.
 	 */
-	*(u32 *)hw_fib->data = cpu_to_le32(ST_OK);
-	fib_adapter_complete(fibptr, sizeof(u32));
+
+	busy = 0;
+
+	dprintk ((KERN_INFO "container=%d(%d,%d,%d,%d)\n",
+	  container,
+	  (dev && dev->scsi_host_ptr)
+	    ? dev->scsi_host_ptr->host_no
+	    : -1,
+	  CONTAINER_TO_CHANNEL(container),
+	  CONTAINER_TO_ID(container),
+	  CONTAINER_TO_LUN(container)));
+
+	/*
+	 *	Find the Scsi_Device associated with the SCSI address,
+	 * and mark it as changed, invalidating the cache. This deals
+	 * with changes to existing device IDs.
+	 */
+
+	if (!dev || !dev->scsi_host_ptr) {
+		return;
+	}
+	/*
+	 * force reload of disk info via probe_container
+	 */
+	if ((DeviceConfigNeeded == CHANGE)
+	 && (dev->fsa_dev[container].valid == 1))
+		dev->fsa_dev[container].valid = 2;
+	if ((DeviceConfigNeeded == CHANGE)
+	 || (DeviceConfigNeeded == ADD))
+		probe_container(dev, container);
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
+	shost_for_each_device(device, dev->scsi_host_ptr)
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+	list_for_each_entry(device, &dev->scsi_host_ptr->my_devices, siblings)
+#else
+	for (device = dev->scsi_host_ptr->host_queue;
+	  device != (struct scsi_device *)NULL;
+	  device = device->next)
+#endif
+	{
+		dprintk((KERN_INFO "aifd: device (%d,%d,%d,%d)?\n",
+		  dev->scsi_host_ptr->host_no,
+		  device->channel,
+		  device->id,
+		  device->lun));
+		if ((device->channel == CONTAINER_TO_CHANNEL(container))
+		 && (device->id == CONTAINER_TO_ID(container))
+		 && (device->lun == CONTAINER_TO_LUN(container))) {
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
+			busy |= atomic_read(&device->access_count) || test_bit(SHOST_RECOVERY, &dev->scsi_host_ptr->shost_state);
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
+			busy |= device->device_busy || test_bit(SHOST_RECOVERY, &dev->scsi_host_ptr->shost_state);
+#else
+			busy |= device->access_count || dev->scsi_host_ptr->in_recovery;
+#endif
+			dprintk((KERN_INFO " %s %s\n",
+			  ((busy) ? "BUSY" : "AVAILABLE"),
+			  (DeviceConfigNeeded == NOTHING)
+			   ? "NOTHING"
+			   : (DeviceConfigNeeded == DELETE)
+			     ? "DELETE"
+			     : (DeviceConfigNeeded == ADD)
+			       ? "ADD"
+			       : (DeviceConfigNeeded == CHANGE)
+			         ? "CHANGE"
+				 : "UNKNOWN"));
+			if (busy == 0) {
+				device->removable = 1;
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+				switch (DeviceConfigNeeded) {
+				case ADD:
+					/* No need to call scsi_scan_single_target */
+					DeviceConfigNeeded = CHANGE;
+#if ((LINUX_VERSION_CODE > KERNEL_VERSION(2,6,3)) || !defined(MODULE))
+					scsi_add_device(dev->scsi_host_ptr,
+					  device->channel, device->id, device->lun);
+					break;
+#endif
+				case DELETE:
+#if ((LINUX_VERSION_CODE > KERNEL_VERSION(2,6,3)) || !defined(MODULE))
+					scsi_remove_device(device);
+					break;
+#endif
+				case CHANGE:
+#if ((LINUX_VERSION_CODE > KERNEL_VERSION(2,6,10)) || !defined(MODULE))
+					scsi_rescan_device(&device->sdev_gendev);
+#else
+					/* scsi_rescan_device code fragment */
+					if (!device->sdev_gendev.driver)
+						break;
+					drv = to_scsi_driver(
+						device->sdev_gendev.driver);
+					if (!try_module_get(drv->owner))
+						break;
+					if(drv->rescan)
+						drv->rescan(&device->sdev_gendev);
+					module_put(drv->owner);
+#endif
+
+				default:
+					break;
+				}
+#endif
+			}
+		}
+	}
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0))
+	if (DeviceConfigNeeded == ADD) {
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,10))
+		scsi_scan_single_target(dev->scsi_host_ptr,
+		  CONTAINER_TO_CHANNEL(container),
+		  CONTAINER_TO_ID(container));
+#elif (!defined(MODULE))
+		scsi_scan_host_selected(dev->scsi_host_ptr,
+		  CONTAINER_TO_CHANNEL(container),
+		  CONTAINER_TO_ID(container),
+		  CONTAINER_TO_LUN(container), 0);
+#endif
+	}
+#endif
+	dprintk (("busy=%d\n", busy));
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+	/*
+	 * if (busy == 0) {
+	 *	scan_scsis(dev->scsi_host_ptr, 1,
+	 *	  CONTAINER_TO_CHANNEL(container),
+	 *	  CONTAINER_TO_ID(container),
+	 *	  CONTAINER_TO_LUN(container));
+	 * }
+	 * is not exported as accessible, so we need to go around it
+	 * another way. So, we look for the "proc/scsi/scsi" entry in
+	 * the proc filesystem (using proc_scsi as a shortcut) and send
+	 * it a message. This deals with new devices that have
+	 * appeared. If the device has gone offline, scan_scsis will
+	 * also discover this, but we do not want the device to
+	 * go away. We need to check the access_count for the
+	 * device since we are not wanting the devices to go away.
+	 */
+	if (busy) {
+		dev->fsa_dev[container].ConfigWaitingOn = 0;
+		dev->fsa_dev[container].ConfigNeeded = DeviceConfigNeeded;
+		return;
+	}
+	if (proc_scsi != (struct proc_dir_entry *)NULL) {
+		struct proc_dir_entry * entry;
+
+		dprintk((KERN_INFO "proc_scsi=%p ", proc_scsi));
+		for (entry = proc_scsi->subdir;
+		  entry != (struct proc_dir_entry *)NULL;
+		  entry = entry->next) {
+			dprintk(("\"%.*s\"[%d]=%x ", entry->namelen,
+			  entry->name, entry->namelen, entry->low_ino));
+			if ((entry->low_ino != 0)
+			 && (entry->namelen == 4)
+			 && (memcmp ("scsi", entry->name, 4) == 0)) {
+				dprintk(("%p->write_proc=%p ", entry, entry->write_proc));
+				if (entry->write_proc != (int (*)(struct file *, const char *, unsigned long, void *))NULL) {
+					char buffer[80];
+					int length;
+					mm_segment_t fs;
+
+					sprintf (buffer,
+					  "scsi %s-single-device %d %d %d %d\n",
+					  ((DeviceConfigNeeded == DELETE)
+					   ? "remove"
+					   : "add"),
+					  dev->scsi_host_ptr->host_no,
+					  CONTAINER_TO_CHANNEL(container),
+					  CONTAINER_TO_ID(container),
+					  CONTAINER_TO_LUN(container));
+					length = strlen (buffer);
+					dprintk((KERN_INFO
+					  "echo %.*s > /proc/scsi/scsi\n",
+					  length-1,
+					  buffer));
+//printk("echo %.*s > /proc/scsi/scsi\n", length-1, buffer);
+					fs = get_fs();
+					set_fs(get_ds());
+					length = entry->write_proc(
+					  NULL, buffer, length, NULL);
+					set_fs(fs);
+					dprintk((KERN_INFO
+					  "returns %d\n", length));
+				}
+				break;
+			}
+		}
+	}
+#endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) */
 }
 
 /**
@@ -804,10 +1312,12 @@ int aac_command_thread(struct aac_dev * 
 {
 	struct hw_fib *hw_fib, *hw_newfib;
 	struct fib *fib, *newfib;
-	struct aac_queue_block *queues = dev->queues;
+	struct aac_queue *q = &dev->queues->queue[HostNormCmdQueue];
 	struct aac_fib_context *fibctx;
 	unsigned long flags;
 	DECLARE_WAITQUEUE(wait, current);
+	unsigned long next_jiffies = jiffies + HZ;
+	long difference;
 
 	/*
 	 *	We can only have one thread per adapter for AIF's.
@@ -818,27 +1328,33 @@ int aac_command_thread(struct aac_dev * 
 	 *	Set up the name that will appear in 'ps'
 	 *	stored in  task_struct.comm[16].
 	 */
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
 	daemonize("aacraid");
 	allow_signal(SIGKILL);
+#else
+	sprintf(current->comm, "aacraid");
+	daemonize();
+#endif
 	/*
 	 *	Let the DPC know it has a place to send the AIF's to.
 	 */
 	dev->aif_thread = 1;
-	add_wait_queue(&queues->queue[HostNormCmdQueue].cmdready, &wait);
+	add_wait_queue(&q->cmdready, &wait);
 	set_current_state(TASK_INTERRUPTIBLE);
+	dprintk ((KERN_INFO "aac_command_thread start\n"));
 	while(1) 
 	{
-		spin_lock_irqsave(queues->queue[HostNormCmdQueue].lock, flags);
-		while(!list_empty(&(queues->queue[HostNormCmdQueue].cmdq))) {
+		spin_lock_irqsave(q->lock, flags);
+		while(!list_empty(&(q->cmdq))) {
 			struct list_head *entry;
 			struct aac_aifcmd * aifcmd;
 
 			set_current_state(TASK_RUNNING);
-		
-			entry = queues->queue[HostNormCmdQueue].cmdq.next;
+	
+			entry = q->cmdq.next;
 			list_del(entry);
-			
-			spin_unlock_irqrestore(queues->queue[HostNormCmdQueue].lock, flags);
+		
+			spin_unlock_irqrestore(q->lock, flags);
 			fib = list_entry(entry, struct fib, fiblink);
 			/*
 			 *	We will process the FIB here or pass it to a 
@@ -860,7 +1376,7 @@ int aac_command_thread(struct aac_dev * 
 			if (aifcmd->command == cpu_to_le32(AifCmdDriverNotify)) {
 				/* Handle Driver Notify Events */
 				aac_handle_aif(dev, fib);
-				*(u32 *)hw_fib->data = cpu_to_le32(ST_OK);
+				*(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
 				fib_adapter_complete(fib, sizeof(u32));
 			} else {
 				struct list_head *entry;
@@ -869,13 +1385,60 @@ int aac_command_thread(struct aac_dev * 
 				   
 				u32 time_now, time_last;
 				unsigned long flagv;
-				
+				unsigned num;
+				struct hw_fib ** hw_fib_pool, ** hw_fib_p;
+				struct fib ** fib_pool, ** fib_p;
+			
 				/* Sniff events */
-				if (aifcmd->command == cpu_to_le32(AifCmdEventNotify))
+				if ((aifcmd->command == cpu_to_le32(AifCmdEventNotify))
+				 || (aifcmd->command == cpu_to_le32(AifCmdJobProgress))) {
 					aac_handle_aif(dev, fib);
+				}
 				
 				time_now = jiffies/HZ;
 
+				/*
+				 * Warning: no sleep allowed while
+				 * holding spinlock. We take the estimate
+				 * and pre-allocate a set of fibs outside the
+				 * lock.
+				 */
+				num = le32_to_cpu(dev->init->AdapterFibsSize)
+				    / sizeof(struct hw_fib); /* some extra */
+				spin_lock_irqsave(&dev->fib_lock, flagv);
+				entry = dev->fib_list.next;
+				while (entry != &dev->fib_list) {
+					entry = entry->next;
+					++num;
+				}
+				spin_unlock_irqrestore(&dev->fib_lock, flagv);
+				hw_fib_pool = NULL;
+				fib_pool = NULL;
+				if (num
+				 && ((hw_fib_pool = kmalloc(sizeof(struct hw_fib *) * num, GFP_ATOMIC|GFP_KERNEL)))
+				 && ((fib_pool = kmalloc(sizeof(struct fib *) * num, GFP_ATOMIC|GFP_KERNEL)))) {
+					hw_fib_p = hw_fib_pool;
+					fib_p = fib_pool;
+					while (hw_fib_p < &hw_fib_pool[num]) {
+						if (!(*(hw_fib_p++) = kmalloc(sizeof(struct hw_fib), GFP_ATOMIC|GFP_KERNEL))) {
+							--hw_fib_p;
+							break;
+						}
+						if (!(*(fib_p++) = kmalloc(sizeof(struct fib), GFP_ATOMIC|GFP_KERNEL))) { 
+							kfree(*(--hw_fib_p));
+							break;
+						}
+					}
+					if ((num = hw_fib_p - hw_fib_pool) == 0) {
+						kfree(fib_pool);
+						fib_pool = NULL;
+						kfree(hw_fib_pool);
+						hw_fib_pool = NULL;
+					}
+				} else if (hw_fib_pool) {
+					kfree(hw_fib_pool);
+					hw_fib_pool = NULL;
+				}
 				spin_lock_irqsave(&dev->fib_lock, flagv);
 				entry = dev->fib_list.next;
 				/*
@@ -884,6 +1447,8 @@ int aac_command_thread(struct aac_dev * 
 				 * fib, and then set the event to wake up the
 				 * thread that is waiting for it.
 				 */
+				hw_fib_p = hw_fib_pool;
+				fib_p = fib_pool;
 				while (entry != &dev->fib_list) {
 					/*
 					 * Extract the fibctx
@@ -916,9 +1481,11 @@ int aac_command_thread(struct aac_dev * 
 					 * Warning: no sleep allowed while
 					 * holding spinlock
 					 */
-					hw_newfib = kmalloc(sizeof(struct hw_fib), GFP_ATOMIC);
-					newfib = kmalloc(sizeof(struct fib), GFP_ATOMIC);
-					if (newfib && hw_newfib) {
+					if (hw_fib_p < &hw_fib_pool[num]) {
+						hw_newfib = *hw_fib_p;
+						*(hw_fib_p++) = NULL;
+						newfib = *fib_p;
+						*(fib_p++) = NULL;
 						/*
 						 * Make the copy of the FIB
 						 */
@@ -933,39 +1500,91 @@ int aac_command_thread(struct aac_dev * 
 						fibctx->count++;
 						/* 
 						 * Set the event to wake up the
-						 * thread that will waiting.
+						 * thread that is waiting.
 						 */
 						up(&fibctx->wait_sem);
 					} else {
 						printk(KERN_WARNING "aifd: didn't allocate NewFib.\n");
-						if(newfib)
-							kfree(newfib);
-						if(hw_newfib)
-							kfree(hw_newfib);
 					}
 					entry = entry->next;
 				}
 				/*
 				 *	Set the status of this FIB
 				 */
-				*(u32 *)hw_fib->data = cpu_to_le32(ST_OK);
+				*(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
 				fib_adapter_complete(fib, sizeof(u32));
 				spin_unlock_irqrestore(&dev->fib_lock, flagv);
+				/* Free up the remaining resources */
+				hw_fib_p = hw_fib_pool;
+				fib_p = fib_pool;
+				while (hw_fib_p < &hw_fib_pool[num]) {
+					if (*hw_fib_p)
+						kfree(*hw_fib_p);
+					if (*fib_p)
+						kfree(*fib_p);
+					++fib_p;
+					++hw_fib_p;
+				}
+				if (hw_fib_pool)
+					kfree(hw_fib_pool);
+				if (fib_pool)
+					kfree(fib_pool);
 			}
-			spin_lock_irqsave(queues->queue[HostNormCmdQueue].lock, flags);
 			kfree(fib);
+			spin_lock_irqsave(q->lock, flags);
 		}
 		/*
 		 *	There are no more AIF's
 		 */
-		spin_unlock_irqrestore(queues->queue[HostNormCmdQueue].lock, flags);
-		schedule();
+		spin_unlock_irqrestore(q->lock, flags);
+
+		difference = next_jiffies - jiffies;
+		if (difference <= 0) {
+			struct timeval now;
+
+			do_gettimeofday(&now);
+
+			/* Synchronize our watches */
+			if (((1000000 - (1000000 / HZ)) > now.tv_usec)
+			 && (now.tv_usec > (1000000 / HZ)))
+				difference = (((1000000 - now.tv_usec) * HZ)
+				  + 500000) / 1000000;
+			else {
+				struct fib *fibptr;
+
+				if ((fibptr = fib_alloc(dev))) {
+					u32 * info;
+
+					fib_init(fibptr);
+
+					info = (u32 *) fib_data(fibptr);
+					if (now.tv_usec > 500000)
+						++now.tv_sec;
+
+					*info = cpu_to_le32(now.tv_sec);
+
+					(void)fib_send(SendHostTime,
+						fibptr,
+						sizeof(*info),
+						FsaNormal,
+						1, 1,
+						NULL,
+						NULL);
+					fib_complete(fibptr);
+					fib_free(fibptr);
+				}
+				difference = 30 * 60 * HZ;
+			}
+			next_jiffies = jiffies + difference;
+		}
+		schedule_timeout(difference);
 
 		if(signal_pending(current))
 			break;
 		set_current_state(TASK_INTERRUPTIBLE);
 	}
-	remove_wait_queue(&queues->queue[HostNormCmdQueue].cmdready, &wait);
+	remove_wait_queue(&q->cmdready, &wait);
 	dev->aif_thread = 0;
 	complete_and_exit(&dev->aif_completion, 0);
+	return 0;
 }
--- linux-2.6.8.1-t043-libata-update/drivers/scsi/aacraid/CHANGELOG	1970-01-01 03:00:00.000000000 +0300
+++ aacraid-drv/drivers/scsi/aacraid/CHANGELOG	2005-05-12 22:42:21.000000000 +0400
@@ -0,0 +1,2019 @@
+Version: 0.9.10
+
+Version: 1.1.2
+
+2003-05-15	Mark_Salyzyn@adaptec.com
+
+Differences between 2.4.21-rc2-ac2 kernel and our 1.1.2 versioned driver,
+changes as performed by Deanna Bonds, Bob Pasteur and Mark Salyzyn.
+
+aachba.c:
+	- If the state of a logical unit is hidden, then do not report. This
+	  state is typically entered when a device is being cleared.
+	- Added support for the Tallahassee project, where one channel is
+	  dedicated to SCSI, and the other channel is dedicated to RAID.
+	- Resolved some issues surrounding PAE support and IA64.
+	- If the driver is a not a boot disk driver, then set the Removable
+	  bit on the inquiry strings returned by the logical units to ensure
+	  that any changes in the arrays will be acquired when the device is
+	  re-attached.
+	- mask the SRB status with 0x3F to deal with misbehaving devices.
+	- Do not report DISKs to inquiry requests on the SCSI bus except if
+	  the channel is designated as a SCSI only bus.
+	- Propagate check conditions to the SCSI command result.
+	- Add support for programmable timeouts to propagate down toe the
+	  requests.
+	- If we have pae mode enabled, right after we get the adapter
+	  information and determine the pae mode capability, we enable the
+	  system to issue 64 bit requests.
+aacraid.h:
+	- Had to drop from 512 commands to 100 commands because some versions
+	  of the firmware would starve commands causing a timeout reaction
+	  which lead to lost commands.
+	- Added a global control variable for nondasd and paemode support.
+	- Dealt with some 64 bit / 32 bit issues in list_head structures and
+	  helper Macros, replacing them with our own more sensitive variants.
+	- Differentiated virtual and physical references to the shared fib
+	  allocations.
+	- information structure not synchronized to firmware, needed to add
+	  a clusterchannelmask.
+	- Added definitions in support of the new configuration information
+	  page bits in support of Tallahassee.
+	- Changed to an allocated fib pool, rather than an array in the hba
+	  structure as this affected the SCSI memory pool.
+	- Added some AIF definitions to permit us to sniff for container
+	  changes to permit a rescan to pick up new information or targets.
+commctrl.c:
+	- The fib reference was changed to a physical and a virtual address,
+	  absorb the name changes.
+	- The list_head structure handlers have been replaced with our own,
+	  absorb the name changes.
+	- The fib address reported in an AIF is a physical (32 bit) reference,
+	  and not a virtual (possibly 64 bit) reference.
+	- added the ioctl handling for sending a raw srb (FSACTL_SEND_RAW_SRB).
+comminit.c:
+	- Deal with IA64 issues.
+	- Change to using the physical address (32 bit) for the AIF references.
+	- The list_head structure handlers have been replaced with our own,
+	  absorb the name changes.
+	- Observed a memory leak, free up the queue resources should we fail
+	  to initialize the adapter.
+commsup.c:
+	- The fib reference was changed to a physical and a virtual address,
+	  absorb the name changes.
+	- Instead of panicking the kernel when a fib allocation was available,
+	  sleep until it is available.
+	- Submitted fib pointers are physical (32 bit) rather than virtual
+	  (possibly 64 bit) values.
+	- producer and consumer indexes should be converted over to local
+	  cpu endian before comparison.
+	- aac_handle_aif now sniffs AIF events and takes plug and play action
+	  for container changes.
+	- The aif thread is set up to be a kernel thread, and not a user
+	  thread. This permits us the ability to make plug and play calls
+	  without prejudice.
+	- Added instrumentation to the aif thread to confirm the plug and
+	  play activity and as an aid to several other debug sessions.
+	- Do not age an aif context based on the last received aif, but rather
+	  the last poll.
+dpcsup.c:
+	- The fib reference was changed to a physical and a virtual address,
+	  absorb the name changes.
+	- Submitted fib pointers are physical (32 bit) rather than virtual
+	  (possibly 64 bit) values.
+linit.c:
+	- Added paemode control.
+	- Added various upcoming board products, and documented better the
+	  existing board product ids. This includes SATA RAID products.
+	- needed to take the io_request_lock during portions of initialization.
+	- allocate the fib resource separately, rather than part of adapter
+	  structure to aid in the precious SCSI resources.
+	- cleanup of none dasd support options.
+	- Added more details about the build date of the driver to the proc
+	  information.
+	- dropped a change that permitted 64 bit DMA resources to be generated
+	  instead of through a 32 bit bounce buffer. (it was moved to aachba.c
+	  where it can be turned on after we determine the adapter's
+	  capabilities).
+	- max_id, max_lun and max_channel parameters are set after the
+	  adapter information has been picked up (the number of channels is
+	  based on the product id table now).
+sa.c:
+	- Context of timeout handling was incorrect, only noticed in IA64
+	  bit machines (due to lack of BIOS initialization).
+
+Differences that need further investigation and could be viewed as regressions
+and added after submission:
+
+rx.c:
+	- Dropped detection of failure to generate kernel command thread.
+sa.c:
+	- Dropped detection of failure to generate kernel command thread.
+
+Version: 1.1.3
+
+2003-07-01	Mark_Salyzyn@adaptec.com
+
+aachba.c:
+	- Added aac_get_container_name to permit override of array inquiry
+	  string with the set name.
+
+2003-07-08	Mark_Salyzyn@adaptec.com
+
+aachba.c:
+	- Return 0 (success) for unsupported commands, the check condition
+	  should perform the necessary action of error handling.
+
+2003-07-10	Mark_Salyzyn@adaptec.com
+
+aachba.c:
+	- The pass-through SCSI SCB command in PAE mode was getting the fib
+	  size count wrong, by using the 32 bit command, then doing an (n-1)
+	  times the size of the 64 bit scatter gather. Resolution was to
+	  subtract the 32 bit scatter gather, then do an n times the 64 scatter
+	  gather size.
+	- Only go into PAE mode if more than 4MB of memory in the system.
+
+2003-07-10	Mark_Salyzyn@adaptec.com
+
+linit.c:
+	- Added `Family' product codes and reordered the product discovery code
+	  to produce devices in PCI order rather than in product order.
+	  Dell, Legend and Adaptec Families were produced with the assumption
+	  of 2 available busses.
+
+2003-07-24	Mark_Salyzyn@adaptec.com
+
+linit.c:
+	- Added Bearcat (6 ch SATA) and a commented entry for Lancer where
+	  future workarounds may be necessary due to hardware constraints.
+	- Set highmem_io (for kernels of 2.4.18 and above).
+
+aachba.c:
+	- Set highmem_io (for kernels of 2.4.18 and above; and when the
+	  adapter is guaranteed to handle the possible address ranges it
+	  will be provided).
+
+Version: 1.1.4:
+
+2003-07-28	Mark_Salyzyn@adaptec.com
+
+aacraid.h+common/include/fsaioctl.h+aachba.c
+	- Added the FSACTL_REGISTER_FIB_SEND function to the ioctl. This ioctl
+	  is *not* a user accessible ioctl, meant only for driver use to permit
+	  stacking a filter driver just ahead of the hardware layer. The call
+	  to register is:
+
+		typedef void (*fib_callback)(void *ctxt, struct fib *fibctx);
+		typedef struct {
+			int (*fib_send)(u16 command,
+					struct fib * context,
+					unsigned long fib_size,
+					int priority,
+					int wait,
+					int reply
+					fib_callback callback,
+					void * ctxt);
+		} fib_send_t;
+		. . .
+		fib_send_t original;
+		int dummy_fib_send (u16 command,
+				    struct fib * context,
+				    unsigned long fib_size,
+				    int priority,
+				    int wait,
+				    int reply
+				    fib_callback callback,
+				    void * ctxt)
+		{
+			return (*original->fib_send)(command, context, fib_size, priority, wait, reply, callback, ctxt);
+		}
+		. . .
+		Scsi_Host_Template * host;
+		Scsi_Device * adapter;
+		original->fib_send = dummy_fib_send;
+		host->ioctl(adapter, FSACTL_REGISTER_FIB_SEND, &original);
+
+	  Return value from the ioctl include ENOTTY (not supported), EINVAL
+	  (invalid argument pointer) and EBUSY (another function already
+	  registered) and the original fib_send function is returned in the
+	  ioctl argument structure. A NULL value for the fib_send member of the
+	  structure deregisters the filter driver. The fib_callback function is
+	  issued at interrupt priority and should follow all the constraints of
+	  interrupt operation. It is the responsibility of the registered
+	  fib_send function to ensure that the original fib_callback function
+	  is called with the ctxt value when completing the command (this
+	  subtlety is lost in the above dummy function).
+
+2003-07-28	Mark_Salyzyn@adaptec.com
+
+linit.c:
+	- Added Kernel, Firmware and BIOS revision and build number to proc
+	  information.
+	- Added board serial number to proc information.
+
+aachba.c:
+	- Do not set removable bit in the inquiry command, the aif delivery
+	  of array status change will handle the reasons for the removable
+	  bit (capacity change and differences in the partition table). Some
+	  customers take issue with the fact our arrays appear as removable.
+
+commctrl.c:
+	- Reported driver version and build number instead of Firmware version
+	  and build number for the Miniport Version Check ioctl. ADPmp57715
+
+2003-08-06	Mark_Salyzyn@adaptec.com and a cast of thousands
+
+all files:
+	- Added appropriate ifdefs, or merged in additions, in support of the
+	  2.6.0-test2 kernels as follows:
+
+Makefile:
+	- Added ifdefs for 2.4 and 2.6 kernels so we can use a common Makefile
+	  for both kernel build environments.
+
+aachba.c:
+	- use linux/blkdev.h in 2.5+ kernels.
+	- define aac_spin_* macros to differentiate between lock requirements
+	  in 2.5+ and 2.4 kernels.
+	- Use the SCSI layers definitions of the SCSI commands, rather than
+	  our own internal SS_* manifests.
+	- Define SCSICMD_TO_* macros to acquire the SCSI target host, channel,
+	  id and lun.
+	- Use the 2.6 SAM_* status codes for return, the 2.4 system will
+	  redefine the SAM_* codes to 2.4 variants.
+	- Change to devname instead of devno when referencing devices to
+	  simplify conversions.
+	- MAXIMUM_NUM_CONTAINERS references were +/- 1 in comparisons, made
+	  this value a `number' rather than a mix of `number' and `limit'.
+	- Resolved `Cast of pointer from integer of different size' by
+	  (void *)(ulong)dma_addr_t.
+	- Change to `id' rather than `target' to match SCSI subsystem
+	  references name for consistency.
+
+aacraid.h:
+	- MAXIMUM_NUM_CONTAINERS references were +/- 1 in comparisons, made
+	  this value a `number' rather than a mix of `number' and `limit'.
+	- Removed AAC_MAX_TARGET, as it is no longer used.
+	- Added CONTAINER_TO_* macros to simplify references.
+	- Change to `id' rather than `target' to match SCSI subsystem
+	  references name for consistency.
+	- Change to devname instead of devno when referencing devices.
+	- Use cap_to_cyls inline to handle 64 bit calculation correctly.
+
+commctrl.c:
+	- use linux/blkdev.h in 2.5+ kernels.
+	- Change to `id' rather than `target' to match SCSI subsystem
+	  references name for consistency.
+
+comminit.c:
+	- use linux/blkdev.h in 2.5+ kernels.
+
+commsup.c:
+	- use linux/blkdev.h in 2.5+ kernels.
+	- Moved CONTAINER_TO_* macros to aacraid.h to simplify references.
+	- Device Discovery loops are different for 2.4 and 2.5+ kernels,
+	  use list_for_each_entry siblings instead of host_queue loop.
+	- daemonize adds the process name as a parameter, and requires
+	  SIGKILL to be enabled to permit kernel shutdown in 2.5+ kernels.
+
+dpcsup.c:
+	- use linux/blkdev.h in 2.5+ kernels.
+
+linit.c:
+	- use linux/blkdev.h in 2.5+ kernels.
+	- added aacids to provide a table hint for installers.
+	- changed over to utilize ANSI structure initialization.
+	- aac_biosparm and aac_procinfo change parameters in 2.5+ kernels.
+	- aac_slave_configure replaces aac_queuedepth in 2.5+ kernels.
+	- detect no longer needs to unlock io_request_lock to do it's duty
+	  in 2.5+ kernels.
+	- use SCSI_set_device in 2.5+ kernels rather than scsi_set_pci_device.
+	- Change to devname instead of devno when referencing devices to
+	  simplify conversions.
+	- Use MAXIMUM_NUM_CONTAINERS rather than AAC_MAX_TARGET
+	- Use cap_to_cyls inline to handle 64 bit calculation correctly in
+	  aac_biosparm.
+	- Use minor in 2.5+ kernels instead of MINOR macro.
+
+rx.c:
+	- use linux/blkdev.h in 2.5+ kernels.
+	- interrupts now return irqreturn_t.
+
+sa.c:
+	- use linux/blkdev.h in 2.5+ kernels.
+	- interrupts now return irqreturn_t.
+
+2003-08-15	Mark_Salyzyn@adaptec.com
+
+install.sh:
+	- increased range of kernel version reports in the magic file to 30.
+
+2003-08-19	Mark_Salyzyn@adaptec.com & ijohns@elipsan.com
+
+aachba.c:
+	- status_byte in the result is shifted down by one.
+	- set_sense spoof was not immediately followed by a copy of the check
+	  condition results into the SCSI command.
+
+2003-08-20	Mark_Salyzyn@adaptec.com, Scott_Long@adaptec.com & Alan Cox
+
+commctrl.c:
+	- The raw SCSI SCB ioctl command in PAE mode was getting the fib
+	  size count wrong, by using the 32 bit command, then doing an (n-1)
+	  times the size of the 64 bit scatter gather. Resolution was to
+	  subtract the 32 bit scatter gather, then do an n times the 64 scatter
+	  gather size.
+
+aacraid.h:
+	- Added definition of CT_FLUSH_CACHE command and structures.
+	- Added AAC_QUIRK_31BIT for ROMB based adapters.
+
+linit.c:
+	- Added AAC_QUIRK_31BIT for ROMB based adapters.
+	- Check return from scsi_register.
+
+aachba.c:
+	- Added support for issuing CT_FLUSH_CACHE command when the SCSI
+	  SYNCHRONIZE command is issued to a container.
+	- Restored mask after adding AAC_QUIRK_31BIT for ROMB based adapters.
+
+2003-08-21	Mark_Salyzyn@adaptec.com
+
+aachba.c:
+	- Changed aac_get_container_name to be a none-blocking function,
+	  completing the incoming scsicmd with the adapter response.
+
+2003-08-26	Mark_Salyzyn@adaptec.com
+
+commsup.c + aacraid.h:
+	- Altered handling of AIF messages from Firmware to differentiate
+	  events in a finer grained manner.
+
+2003-08-29	Mark_Salyzyn@adaptec.com
+
+aachba.c + aacraid.h
+	- Driver too noisy, undefined AAC_DETAILD_STATUS_INFO and incorporated
+	  check condition report into the AAC_DETAILED_STATUS_INFO ifdef.
+
+2003-09-03	Mark_Salyzyn@adaptec.com
+
+aachba.c:
+	- Check if the device is in use and report that as a locked device
+	  to both the FSACTL_QUERY_DISK and FSACTL_DELETE_ARRAY ioctls.
+	- unlock/lock around probe_container as this is a blocking function.
+	  This change addresses a deadlock issue that surfaced in SMP only
+	  environments.
+
+Version: 1.1.4-2172
+
+2003-09-04	Mark_Salyzyn@adaptec.com
+
+commsup.c:
+	- References to the Status Job update structure were at incorrect
+	  offsets causing incorrect operation during an Array Clear with
+	  regards to plug and play actions.
+
+Version: 1.1.4-2177
+
+2003-09-05	Mark_Salyzyn@adaptec.com
+
+aachba.c:
+	- Cleanup request from the SCSI list maintainers.
+	- Dropped use of SCSICMD_TO_CHANNEL & friends since
+	  scsicmd->device->channel is available in all versions of the
+	  operating system.
+	- Removed deprecated code and/or comments related to deprecation.
+	- include <linux/blkdev.h> works in all versions of the operating
+	  system.
+
+2003-09-09	Mark_Salyzyn@adaptec.com
+
+aacraid.h:
+	- NUM_FIBs should be 64 larger (AIFS) larger than the NUM_IO_FIBS.
+
+commsup.c:
+	- efficiency improved if we hold on to the aac_queue variable, aims
+	  towards better code compliance and consistency.
+
+2003-09-15	Mark_Salyzyn@adaptec.com
+
+rkt.c:
+	- Copy if rx.c with rx = rkt
+
+aacraid.h:
+	- Added definition for rkt interface structures, copy of rx, but a
+	  larger reserved region.
+
+linit.c:
+	- Added product code for ROC (Lancer/Rocket) U320 two channel, use rkt
+	  interface.
+
+2003-09-16	Mark_Salyzyn@adaptec.com
+
+linit.c:
+	- Show Adapter vendor and model in proc information.
+
+Version: 1.1.4-2185
+
+2003-09-16	Mark_Salyzyn@adaptec.com
+
+aacraid.h:
+	- Added definition of nblank() to assist us in determining if
+	  dprintk(x) is defined as a blank definition to enable us to ifdef
+	  debug code that ends up calling only dprintk functions.
+
+commsup.c:
+	- Ignore events that refer to containers > MAXIMUM_NUM_CONTAINERS
+	- include <linux/blkdev.h> works in all versions of the operating
+	  system.
+
+linit.c:
+	- print more details about outstanding commands when a SCSI hang
+	  occurs (first use of nblank() macro just defined in aacraid.h)
+
+2003-09-19	Mark_Salyzyn@adaptec.com & Mark Haverkamp <markh@osdi.org>
+
+commsup.c & aachba.c:
+	- valid flag has added support for a value of 2, which means target
+	  is still valid, but needs a probe_container.
+
+commsup.c:
+	- fib_alloc should not go to sleep, but return NULL if there are no
+	  available entries in the pool.
+
+dpcsup.c:
+	- print a message if the fib kmalloc fails when forwarding AIFs
+
+comminit.c:
+	- check fib_alloc return, and report -ENOMEM should the pool be
+	  empty.
+
+aachba.c:
+	- Check value of scsicmd->scsi_done in aac_io_done as we can get
+	  errant firmware which returns commands twice (no released firmware
+	  does this, this is a driver hardening issue only).
+	- When a fib_alloc fails, return -1 to SCSI layer. Formerly, we would
+	  send the command with DID_ERROR.
+
+Version: 1.1.4-2192
+
+2003-09-25	Mark_Salyzyn@adaptec.com
+
+linit.c:
+	- Moved debug variables into block to reduce impact on none-debug
+	  environments.
+
+dpcsup.c + commsup.c:
+	- Use the fib pool instead of a kmalloc to allocate a fib for the
+	  processing of an AIF.
+
+install.sh:
+	- Install driver into any forgotten /lib/modules directories.
+
+2003-09-26	Mark_Salyzyn@adaptec.com
+
+commctrl.c + aacraid.h:
+	- AMD-64 and IA-64 management applications will fail, need to change
+	  fibctx to a 32 bit unique value.
+
+Version: 1.1.4-2194
+
+2003-09-29	Mark_Salyzyn@adaptec.com & Mark Haverkamp <markh@osdi.org>
+
+aachba.c:
+	- use linux/blkdev.h for all variants on Linux.
+	- hold on to the host pointer in aac_io_done, because it's reference
+	  in the device and scsicmd can go away after scsi_done is called.
+	- check return value of pci_set_dma_mask.
+
+commctrl.c:
+	- use linux/blkdev.h for all variants on Linux.
+
+comminit.c:
+	- use linux/blkdev.h for all variants on Linux.
+
+commsup.c:
+	- use linux/blkdev.h for all variants on Linux.
+	- drop linux/smp_lock.h include as it was added in a debug test from
+	  some time ago.
+	- Added current 2.6 kernel support routines for rescanning.
+
+dpcsup.c:
+	- use linux/blkdev.h for all variants on Linux.
+
+linit.c:
+	- use linux/blkdev.h for all variants on Linux.
+	- check return value of pci_set_dma_mask.
+	- template->present is no longer relevant in 2.6 based kernels.
+
+rx.c:
+	- use linux/blkdev.h for all variants on Linux.
+
+sa.c:
+	- use linux/blkdev.h for all variants on Linux.
+
+rkt.c:
+	- use linux/blkdev.h for all variants on Linux.
+
+2003-10-01	Mark_Salyzyn@adaptec.com
+
+commsup.c:
+	- needed a fib_dealloc call ahead of the fib_free call added when
+	  we moved over to the fib pool to handle the AIFs.
+
+dpcsup.c:
+	- need to use the `local' fibctx so that the AIF command can be
+	  acknowledged.
+
+commctrl.c:
+	- return error status from the send_fib function in ioctl_send_fib.
+
+2003-10-07	Mark_Salyzyn@adaptec.com
+
+aachba.c + linit.c:
+	- serial number contains the cookie (fafa0001) that is at index 1
+	  of the serial number element. Only show the serial number which
+	  is at index 0.
+
+linit.c:
+	- Added registration to receive 32 bit ioctls.
+
+commsup.c + dpcsup.c + aacraid.h:
+	- Dropped code to acquire AIF's from the general FIB pool, it was a
+	  fool's errand. However, we kept the code that limits the AIF's
+	  received and allocated to the AdapterFibsSize / sizeof(hw_fib).
+	  The `last' AIF hw_fib is used to quickly acknowledge the entries,
+	  and drop the results on the floor.
+
+rx.c + rkt.c:
+	- Cache the OIMR data in dev->OIMR, it looks remarkably like irq_mask,
+	  which is really unused, but we can clean that up later.
+
+2003-10-08	Matthew Wilcox <willy@debian.org>
+
+aachba.c:
+	- Use SCp.dma_handle instead of SCp.ptr for holding on to the physical
+	  address of the allocated pci_map_single as part of the request.
+
+compat.h:
+	- define dma_handle to be ptr (in support of SCp.dma_handle change
+	  above) for kernels that do not define this member.
+
+2003-10-08	Christoph Hellwig <hch@infradead.org>
+
+aachba.c:
+	- drop use of scsi_to_pci_dma_dir() as it is a pass-through in all
+	  versions of the kernel.
+
+2003-10-09	Mark_Salyzyn@adaptec.com
+
+linit.c:
+	- When an Adapter Reset is requested, wait up to 60 seconds for all
+	  outstanding commands to complete and report SUCCESS.
+
+Version: 1.1.4-2221
+
+2003-10-09	Mark_Salyzyn@adaptec.com
+
+linit.c:
+	- Waited for *all* commands to complete for *all* devices on the
+	  controller when an Adapter Reset is requested.
+
+Version: 1.1.4-2222
+
+2003-10-10	Mark_Salyzyn@adaptec.com
+
+aacraid.h + rx.c + rkt.c + sa.c + linit.c:
+	- Added a aac_adapter_check_health, make sure the adapter is healthy
+	  when performing and Adapter Reset request, report error codes.
+
+aachba.c:
+	- revert to use of scsi_to_pci_dma_dir() as it is not a pass-through in
+	  all versions of the kernel.
+
+linit.c:
+	- SCSI_HAS_HOST_LOCK means that we should be working with releasing
+	  host->lock or host->host_lock instead of io_request_lock surrounding
+	  scsi_sleep.
+
+aacraid.h:
+	- Added definition for AAC_MAX_HOSTPHYSMEMPAGES
+
+comminit.c:
+	- Utilized AAC_MAX_HOSTPHYSMEMPAGES to limit the number of open DMA
+	  4096 byte PAGES of memory requested by the operating system.
+
+2003-10-16	Mark_Salyzyn@adaptec.com
+
+install.sh:
+	- Added support for x86_64 installs
+
+aachba.c:
+	- used SENSE KEYS from scsi.h rather than our own definitions.
+
+2003-10-20	Xose Vazquez Perez <xose@wanadoo.es>
+
+linit.c:
+	- Added pci_ids for 0x10110046/0x90050365
+
+Version: 1.1.4-2265
+
+2003-10-23	Mark_Salyzyn@adaptec.com
+
+linit.c:
+	- no need to set template->present as this is done by the SCSI layer.
+
+2003-10-24	Mark_Salyzyn@adaptec.com
+
+install.sh
+	- Added support for SuSE kernel determination for finer selection
+	  of modules
+	- If the kernel is compiled for athlon, use that instead of
+	  /proc/cpuinfo
+	- if /proc/cpuinfo is not present, don't show any errors during
+	  install
+
+2003-10-28	Mark_Salyzyn@adaptec.com
+
+install.sh
+	- The entire class of SuSE OS releases (sles7, sles8, suse7, suse8,
+	  suse8.1, suse8.2, ul1, ul1-sp2a) place the driver module results into
+	  /lib/modules/[kernel]/kernel/drivers/scsi/aacraid/aacraid.o. The
+	  package places updates in ...//scsi/aacraid.o (note, one directory
+	  up). The module selected for use in the mkinitrd is fed via a `find'
+	  command which reports files in raw directory order which in the
+	  reiser file system would be in the .../scsi directory, but for EXT2
+	  since the file was added later, would prefer the previously placed
+	  product in ../scsi/aacraid/aacraid.o. The fix is to have the driver
+	  disk post-install remove the older .../scsi/aacraid directory.
+
+2003-10-30	Mark_Salyzyn@adaptec.com
+
+install.sh
+	- For the installations to `extra' /lib/modules directories beyond
+	  the boot set, take the processor clue from the postscript (-athlon,
+	  -x86_64 or -ia64) rather than from /proc/cpuinfo.
+
+Version: 1.1.4-2282
+Version: 1.1.4-2292 (Debug)
+
+2003-10-31	Mark_Salyzyn@adaptec.com
+
+aacraid.h + aachba.c:
+	- Added a nested count to the fsa_scsi_dev structure since some kernels
+	  before 2.4.19 have troubles overflowing their stack when a device
+	  goes offline. The issue is that the SCSI done call nests into sending
+	  another queued command, which in turn spoofs a response back
+	  indicating failure which in turn calls SCSI done. We limit the
+	  nesting to 64 commands before we respond with a busy instead.
+
+Version: 1.1.4-2296 (Debug)
+
+linit.c & .version:
+	- Versioning is defined by the structure:
+	    struct {
+		unsigned char dash; // Dash version number
+		unsigned char type; // Type, 1=Devo, 2=Alpha, 3=Beta, 4=Release
+		unsigned char minor;// Minor version minor
+		unsigned char major;// Major version number
+	    }
+	  Adjusted version data to match this definition for generation and
+	  support.
+
+Version: 1.1.4-2299
+Version: 1.1.4-2301
+Version: 1.1.4-2302
+Version: 1.1.4-2303
+
+linit.c & aacraid.h:
+	- Allow 64 bit apps to call GET_NEXT_ADAPTER_FIB ioctl directly,
+	  promoting 32 bit apps when they call.
+
+aachba.c & aacraid.h:
+	- Set MAX_NESTED to 1, and improve code to reflect this simplicity.
+
+install.sh:
+	- Handle name change of products from *-athlon-athlon to *-athlon.
+	- Warn the user if the initrd shrinks too much
+
+Version: 1.1.4-2308
+
+install.sh:
+	- Add support for identifying 2.4.19-340 kernels.
+
+2003-12-12	Mark Haverkamp <markh@osdl.org>
+
+linit.c:
+	- updated aac_eh_reset to use __shost_for_each_device now that the
+	  device element is now private and we're supposed to use the helper
+	  function for access.
+
+Version: 1.1.4-2309
+Version: 1.1.4-2310 (debug)
+
+2003-12-18	Mark Salyzyn <Mark_Salyzyn@adaptec.com>
+
+linit.c:
+	- suppress unused variable warning in debug code.
+	- cast sys_ioctl when registering as it does not match prototype
+	  argument for ioctl32 registration.
+
+Version: 1.1.4-2311
+
+2003-12-22	Mark Haverkamp <markh@osdl.org>
+
+aachba.c:
+	- change from pae to dac as this is the more public understanding of
+	  the 64 bit support concepts.
+aacraid.h:
+	- Remove padding and SavedIrql
+commsup.c + aachba.c:
+	- use atomic_read when accessing access_count member of device
+	  structure.
+linit.c & aacraid.h
+	- iminor takes the inode, not the inode->i_rdev member.
+
+Version: 1.1.4-2313
+
+aachba.c + commsup.c:
+	- use device_busy, shost_status, in_recovery instead of just
+	  access_count. Adjust for each OS release variant.
+
+Version: 1.1.4-2314
+
+2003-12-22: Ken Beaty <ken@nova.org>
+
+aachba.c + commsup.c:
+	- Adjusted ifdefs for kernel version to make more sense.
+
+2004-01-24: Mark Salyzyn <Mark_Salyzyn@adaptec.com>
+
+install.sh:
+	- Altered script to discover prebuilt binaries from the classic
+	  Adaptec rpm package, the Red Hat install disk format, or the
+	  SuSE install disk format.
+
+2004-02-09: Christoph Hellwig <hch@lst.de>
+
+aachba.c:
+	- Remove fsa_dev structure since fsa_dev is always available.
+
+Version: 1.1.4-2324
+
+2004-02-10: Submit to scsi list for inclusion
+
+2004-02-17: Herve MORILLON <hmorillon@doremilabs.fr> + Mark_Salyzyn@adaptec.com
+
+rx.c + rkt.c:
+	- hit doorbell before processing host_command_normal
+
+aachba.c:
+	- Permit requests larger than 64KB
+
+aacraid.h:
+	- Permit 512 outstanding requests
+
+Version: 1.1.5-2326
+
+linit.c + build:
+	- Added support for vary_io, unfortunately the build system also needed
+	  to be adjusted to generate the SCSI_HAS_VARY_IO if the member is
+	  seen in the drivers/scsi/hosts.h file.
+
+build + install.sh:
+	- Added support for 2.4.19-189, 2.4.19-191 and 2.4.19-201 SuSE Kernels
+
+Version: 1.1.5-2327
+
+rkt.c + rx.c:
+	- Added support to issue the Temperature sync command. Since the
+	  cost of the sync command should not increase, the decision was
+	  made to support a `varargs' approach to dealing with the additional
+	  temperature elements *only* for this command.
+
+linit.c:
+	- Added a proc write that accepts the string "Temperature=[0-9.],..."
+	  to send the off-board temperature value to the Firmware so that it
+	  may be integrated into the Enclosure Data.
+	- Added SkyHawk SATA cards to device list. 2020S changes now to 
+	  2020ZCR, and we add 2020SA.
+
+aachba.c:
+	- PERCRAID RAID-5 is superfluous, changed to to PERC RAID-5.
+
+Version: 1.1.5-2328
+
+linit.c + aacraid.h:
+	- Migrate towards using CONFIG_COMPAT instead of __x86_64__
+
+rx.c + rkt.c:
+	- Added support to pick up an Adapter Blink code. ADPmp64499.
+
+linit.c:
+	- Report the Adapter Blink code to the console log. ADPmp64499.
+
+build:
+	- Correctly built the x86_64 SLES8 and ul1 driver disk. Side effects
+	  discovered also fix problems with ia32 SLES8 install. ADPmp64499.
+
+Version: 1.1.5-2329
+
+linit.c + aacraid.h:
+	- Report an AifExeFirmwarePanic AIF message to applications when the
+	  adapter is in a blinkled state.
+
+aachba.c + commsup.c: Brad House <brad@mainstreetsoftworks.com>
+	- use shost_for_each_device instead of list_for_each_entry.
+
+linit.c + aachba.c:
+	- xscale (arm) systems can not have highmem_io set as virtual/phys
+	  handling does not recognize the page/offset addressing.
+
+rkt.c + rx.c:
+	- The Mailbox[7] in none BBS systems is not active until shortly
+	  before the Firmware kernel is booted. The Outbound Message register
+	  is always active and contains the same bringup conditions. We must
+	  look at the OMR during the *_init wait.
+
+Version: 1.1.5-2330
+
+rkt.c + rx.c + sa.c:
+	- Set the time by using get_seconds (epoch January 1 1970) instead
+	  of jiffies/HZ (epoch machine startup). get_seconds is provided
+	  for kernels < 2.6.
+
+Version: 1.1.5-2331
+
+rkt.c:
+	- Mailbox[7] becomes momentarily inaccessible right after PATUWAIT
+	  on the Callisto, lets loop on OMR only. Do not know if this
+	  problem exists on other systems.
+
+Version: 1.1.5-2332
+
+aachba.c + linit.c:
+	- Issue CT_COMMIT_CONFIG before issuign the VM_NameServe. This is
+	  for systems that do not have a BIOS to perform this step.
+
+Version: 1.1.5-2333
+
+aacraid.h:
+	- SAS requires the ability to handle as many as 32 Adapters in a
+	  system, increased the manifest that limits the number of Adapters.
+	- Testing has shown that allowing 33MB I/O can starve a machine, so
+	  we are limiting the maximum I/O size to 4MB (to match other drivers
+	  that permit large I/O).
+
+linit.c:
+	- Make sure that the driver does not register more than
+	  AAC_MAXIMUM_ADAPTERS instances.
+	- Set the queue depth to each device as divided up from AAC_MAX_IO_FIB
+
+commctrl.c: Chris Wright <chrisw@osdl.org>
+	- aac_send_raw_srb added check for bounding of fibsize value.
+
+all: Mark Haverkamp <markh@osdl.org> & Mark Salyzyn <Mark_Salyzyn@adaptec.com>
+	- merge 2.6 driver changes into tree to synchronize.
+
+Version: 1.1.5-2334
+
+aacraid.h+linit.c+commctrl.c+comminit.c:
+	- Added sg_tablesize and max_fib_size to adapter structure and
+	  negotiate these plus Scsi_Host sg_tablesize, can_queue and
+	  max_sectors based on the adapter capabilities.
+
+aachba.c:
+	- Added aac_raw_io command
+	- Recognize that read_callback is identical to write_callback, which
+	  is in turn identical to raw_io's need for a callback. Renamed to
+	  one callback function io_callback.
+
+rx.c+rkt.c+sa.c:
+	- Moved initialization around to permit New Command Interface probes
+	- dropped irq_mask and associated functions.
+	- moved acknowledgement of F/W commands *before* processing so that
+	  we get re-interrupted if a new command is added to the produced
+	  index while we are processing.
+
+linit.c+aachba.c:
+	- Do not print `bad0' for the serial number
+
+linit.c:
+	- this_id = 32, because it gets in the way of Container 16 being
+	  processed.
+
+aachba.c:
+	- scsi_add_timer call issued just before completion routine called
+	  since error recovery handler is there *just* to detect card
+	  failure and not to affect command processing.
+
+build:
+	- Added 2.4.19.SuSE-343 kernel in support of ul1-sles8-ia32 install,
+	  which adds yet another installation floppy to the list.
+
+Version: 1.1.5-2335
+
+linit.c+all:
+	- Revert temporarily to 1.1.4-2177, Changed ASR-2020S to ASR-2020ZCR,
+	  and ASR-2020S Terminator to ASR-2025ZCR.
+
+Version: 1.1.4-2336
+
+linit.c+all:
+	- Revert temporarily to 1.1.4-2322, Changed ASR-2020S to ASR-2020ZCR,
+	  and ASR-2020S Terminator to ASR-2025ZCR.
+
+Version: 1.1.4-2337
+
+all:
+	- Revert back to 1.1.5 code base.
+
+commsup.c:
+	- Fix Irq Moderation code. A Misnomer, since this is really a PCI
+	  utilization moderation, interrupts are not recurring on F/W.
+
+comminit.c:
+	- Turn on Irq Moderation feature (Tentatively 30% reduction in Host
+	  CPU utilization)
+
+Version: 1.1.5-2337
+
+aacraid.h+commsup.c+dpcsup.c+comminit.c+rx.c:
+	- Added support for the new comm interface.
+
+linit.c:
+	- Added debug information to proc output
+
+Version: 1.1.5-2338
+
+commsup.c: Mark Haverkamp <markh@osdl.org>
+	- Added scsi/scsi_device.h, scsi/scsi_driver.h to include file set
+	- set removable to a value of 1, not to TRUE.
+
+aachba.c: Mark_Salyzyn@adaptec.com
+	- Switch to using max_fib_size rather than FIB_DATA_SIZE_IN_BYTES,
+	  this permits SAS management applications to send ioctl FIBs larger
+	  than 512 bytes in size to adapters that accept larger FIBs.
+	- Added support for SAI_READ_CAPACITY_16, READ_12, WRITE_12, READ_16
+	  and WRITE_16 commands.
+	- Played `tricks' with device_blocked and queue_depth fields in the
+	  scsi_device structure to meter the outstanding commands down when
+	  large sequential activity is detected.
+
+aacraid.h: Mark_Salyzyn@adaptec.com
+	- Remove unused definition of FIB_DATA_SIZE_IN_BYTES.
+
+linit.c:
+	- Setting the maximum number of I/O requests/device to a maximum of
+	  256 would act in the SCSI layer as only allocating to permit 1 I/O
+	  for each device.
+
+Version: 1.1.5-2339
+
+build: Mark_Salyzyn@adaptec.com
+	- Added support for 2.6.4-52 SuSE 9.1 Pro install
+	- Added support for multiple architectures for 2.4.21-15.EL RHEL3 QU2
+	  install.
+
+aacraid.h+aachba.c+linit.c: Mark Haverkamp <markh@osdl.org>
+	- Define 2131 as FSACTL_GET_CONTAINERS
+
+commctrl.c: Adam Manthei <amanthei@redhat.com>, Mark_Salyzyn@adaptec.com
+	- change all printk() to dprintk(()) as this is a user initiated
+	  call for aac_send_rw_srb & aac_get_pci_info.
+
+rx.c+rkt.c: Adam Manthei <amanthei@redhat.com>, Mark_Salyzyn@adaptec.com
+	- use pci_alloc_consistent/pci_free_consistent instead of an
+	  unchecked combination of kmalloc(,_GFP_DMA)/pci_map_single/
+	  pci_unmap_single/kfree.
+
+Version: 1.1.5-2340
+
+linit.c+commctrl.c: Mark Haverkamp <markh@osdl.org>
+	- adjust to reflect linux-scsi submission results
+
+aachba.c: Mark_Salyzyn@adaptec.com
+	- remove print for unhandled commands into a debug print. The
+	  unhandled commands are reported to the caller as unhandled, let
+	  the caller deal with this.
+
+rx.c+rkt.c+sa.c: maximilian attems <janitor@sternwelten.at>
+	- upon failure of the init routine, make sure that the registered
+	  interupt handler is deregistered.
+
+commsup.c:
+	- fib_adapter_complete is supposed to free the hw_fib and that is it,
+	  it tried to talk to hardware and caused a lockup.
+
+Version: 1.1.5-2341
+
+build:
+	- use aacraid.ko for 2.6 releases
+
+Version: 1.1.5-2342
+
+aachba.c: Mark_Salyzyn@adaptec.com
+	- added support for a module parameter 'commit=1' to enable COMMIT
+	  CONFIG to be issued to the adapter.
+	- added support for a module parameter 'coalescethreshold=16' which
+	  sets the maximum block size to consider for pushing back to the
+	  scsi_merge layer.
+	- added support for a module parameter 'acbsize=8192' which sets the
+	  suggested fib size to override the suggestion from Firmare.
+	- dropped call to scsi_add_timer, as it causes a panic. It was placed
+	  in the source to resolve a command completion race condition.
+
+Version: 1.1.5-2343
+
+install.sh: Mark_Salyzyn@adaptec.com
+	- globbing issue caused more whiny complaints about a missing
+	  installation into the initrd.
+	- fixed some issued surrounding using the script for SuSE module
+	  update.
+
+linit.c: Mark_Salyzyn@adaptec.com
+	- if the driver does not discover any targets, report failure.
+	- drop kernel_version hack to support build
+
+build: Mark_Salyzyn@adaptec.com
+	- Use vermagic instead of kernel_version to pick up matching kernel.
+	- when innoculating 2.6 tree builds, one needs a *full* compile in
+	  order to generate the struct_module member.
+	- use module.ko for 2.6 kernels.
+
+Version: 1.1.5-2344
+
+build: Mark_Salyzyn@adaptec.com
+	- floppy linux/suse/${ARCH}-${VERS}/modules/${PRODUCT}.o needs to be
+	  a ${PRODUCT}.ko in the 2.6 based installations.
+	- Placed module in both scsi and scsi/${PRODUCT} directories as it
+	  appears that the post-install is not functioning properly.
+
+aachba.c: Mark_Salyzyn@adaptec.com
+	- Checked if the lba exceeds 32 bit block address for systems that
+	  can not support it. raw_io_64 enables 64 bit block addresses.
+	- Redid math for u64 >> 32 as it appears the xscale 64 bit library
+	  is flawed.
+
+Version: 1.1.5-2345
+
+aachba.c: Mark_Salyzyn@adaptec.com
+	- Overrides to force 8KB fibs needs to be reverted to defaults.
+
+Version: 1.1.5-2346
+
+build: Mark_Salyzyn@adaptec.com
+	- Added 2.4.21-15.0.2.EL kernel
+	- Added 2.6.5-7.97 kernel to the build
+
+rx.c+rkt.c: Mark_Salyzyn@adaptec.com
+	- Mailbox7 continues to be a consternation regarding reliable
+	  adapter recovery scenarios; switched to using OMRx[0].
+
+Version: 1.1.5-2347
+
+aachba.c: Mark_Salyzyn@adaptec.com
+	- (u64)=((u8)<<24) does not give expected results, sign extension
+	  occurs. Replace with (u64)=((u64)(u8)<<24)
+
+Version: 1.1.5-2348
+
+install.sh: Mark_Salyzyn@adaptec.com
+	- initrd is blocked from incorporating our product if there is
+	  something in /lib/modules/${OS}-${CONFIG}/update/${PRODUCT}.o,
+	  so remove the file.
+
+Version: 1.1.5-2349
+
+aachba.c+aacraid.h:
+	- define commit_config FIB command
+	- define get_container_count FIB command.
+
+aachba.c+aacraid.h+commsup.c+linit.c
+	- fsa_dev becomes a dynamic structure to accommodate a variable
+	  maximum_num_containers.
+
+build:
+	- Added 2.4.21-231 kernel to build system.
+
+linit.c:
+	- Turned on debug printing of scsi timeouts for xscale only.
+
+Version: 1.1.5-2350
+
+rkt.c:
+	- Limit can_queue to 246 for rocket
+
+build:
+	- Added 2.4.19-306 kernel to build system.
+
+aachba.c:
+	- Removed an innocuous (obnoxious?) DEBUG printk
+
+2004-07-15: Mark Salyzyn <Mark_Salyzyn@adaptec.com>
+
+Version: 1.1.5-2351
+
+build:
+	- Added 2.4.9-31 to the build system
+
+modules.conf:
+	- Added 2.4.9-e.41, 2.4.9-e.43, 2.4.21-17.EL & 2.4.21-15.0.3.EL kernels
+
+build:
+	- Dropped 2.4.21-231 from build
+
+2004-07-16: Mark Salyzyn <Mark_Salyzyn@adaptec.com>
+
+Version: 1.1.5-2352
+
+build:
+	- Added 2.6.3-7mdk to the build system
+
+2004-07-20: Mark Salyzyn <Mark_Salyzyn@adaptec.com>
+
+Version: 1.1.5-2353 (7t Build w/o SLES9, SuSE9.1 & SuSE9 errata 231)
+Version: 1.1.5-2354 (7t Build w/o SLES9 & SuSE9 errata 231)
+Version: 1.1.5-2355 (BigQual refresh)
+
+install.sh:
+	- If missing, add a reference to the module to the kernel's module.dep
+	  file (affects drivers that are *not* shipped with the OS; HostRAID
+	  and some dpt_i2o)
+
+aachba.c:
+	- for __arm__ build, the default FIB size is selected by F/W and not
+	  overridden to 8192 bytes.
+
+Version: 1.1.5-2356 (Jupiter)
+
+aacraid.h+comminit.c+rkt.c+commsup.c+linit.c: Ken Sandars <Ken_Sandars@adaptec.com> + Mark Salyzyn
+	- Added AAC_NUM_MGT_FIB, and ensured can_queue represents the
+	  maximum number of io commands allowed and not be confused as the
+	  maximum number of FIB commands permitted into the Adapter. Thus
+	  host->can_queue is the maximum number of I/O commands, AAC_NUM_MGT_FIB
+	  is the maximum number of ioctl commands (set to 8 rather than legacy
+	  of 64) and init->MaxIoCommands sent back to the adapter is the total
+	  number of FIBs.
+
+Version: 1.1.5-2357 (Jupiter+BigQual)
+
+commctrl.c: Mark Salyzyn
+	- Added support for issuing FIBs that are larger than the negotiated
+	  size for the management interface.
+
+linit.c: Mark Salyzyn
+	- Added ASR-2240S, ASR-4005SAS, ASR-4000SAS, ASR-4800SAS, ASR-4805SAS
+	  and AAR-2610SA to the product list.
+
+install.sh: Mark Salyzyn
+	- Fixed problems with using the RH & SuSE modules disk as an update
+	  media, most of which was the selection of the extraction name from
+	  the modules.cgz file or acquiring the appropriate update.tar.gz file.
+
+build: Mark Salyzyn
+	- set 700 for update.sh in the modules disks to recognize at least
+	  that the RH modules disk works as an update media.
+
+aachba.c: Mark Salyzyn
+	- Dropped to 8K for the coalesce threshold for xscale builds.
+
+Version: 1.1.5-2358 (BigQual+7t)
+
+aachba.c+commctrl.c+aacraid.h+comminit.c+commsup.c+dpcsup.c+linit.c:
+	- Merged 2.6.8-rc2-bk9 differences into the driver (COSMETIC)
+
+compat.h
+	- Added definition for __user for kernels less than 2.5 (COSMETIC)
+
+linit.c:
+	- The aac_get_next_adapter_fib_ioctl for 64 bit implementations under
+	  2.6 maladdressed the transfer.
+
+Version: 1.1.5-2359 (BigQual+SPOCK+7t)
+
+commctrl.c:
+	- Added support for CODE_STREAM_IDENTIFIER, accessed via a new
+	  ioctl FSACTL_GET_VERSION_MATCHING
+	- Added support for FSACTL_SEND_LARGE_FIB
+
+aacraid.h:
+	- Added definition for struct VersionMatch
+	- Added definition for FSACTL_GET_VERSION_MATCHING
+	- Added definition for FSACTL_SEND_LARGE_FIB
+
+install.sh:
+	- if the modules.dep file does not exist, then ensure no complaints
+	  are made about mv not being able to access the file.
+	- If an entry is missing in modules.dep, construct it correctly.
+
+aachba.c:
+	- Remove any leading spaces from the Container Name. Ensure that
+	  if there is no container name remaining, to leave the existing
+	  one alone.
+
+build:
+	- Added support for 2.4.18-e.43
+	- Added support for 2.4.18-e.47
+	- Added support for 2.4.9-e.48
+	- Added support for 2.4.9-e.49 (RHAS 2.1 QU5)
+	- Added support for 2.4.21-15.0.4.EL
+
+rx.c+rkt.c:
+	- When responding to AIFs, use DoorBellAdapterNormRespReady instead of
+	  DoorBellAdapterNormCmdReady. The code appeared to work without
+	  undue side effects because Firmware would clear off the queues
+	  when new AIFs are delivered.
+
+commsup.c:
+	- If busy, defer scan action to next AIF. Half hearted attempt to
+	  improve the reliability of this unsupported feature.
+
+aacraid.h+linit.c+comminit.c+rx.c+rkt.c+sa.c:
+	- Remove references to Mailbox7 accesses for synchronous commands.
+
+aacraid.h+aachba.c:
+	- Turned on support for Compatibility ID testing. Only enabled if
+	  the build environment defines CODE_STREAM_IDENTIFIER.
+	- Fortify the adapter information to include supplemental information
+	  as well as the GetBusInfo in support of SAS programatic limits.
+
+linit.c+aachba.c:
+	- Use the newly acquired supplement information vendor and product
+	  fields to override the cardtype selection.
+
+Version: 1.1.5-2360
+Version: 1.1.5-2361 (Branch off 1.1.5-2340 in RHEL3 QU3 with aac_info fix in 1.1.5-2364)
+
+linit.c:
+	- register a reboot notifier to flush adapter
+	- faked AIF needs to call fib_init() later (ADPmp70525)
+
+commctrl.c:
+	- Since kfree has the possibility of switching in some esoteric
+	  variants of the kernel, and since the BKL is held during ioctl
+	  calls, we are unlocking the fib lock around these system calls.
+
+Version: 1.1.5-2362
+
+build:
+	- Added support for 2.4.21-17.EL (RHEL3 QU3 beta)
+	- Added support for 2.4.21-20.EL (RHEL3 QU3)
+	- Added support for 2.6.7-1.451.2.3 (RHEL4 alpha 4)
+
+linit.c:
+	- ASR4000 series entries were flawed in the indexes. Added an
+	  additional 8i entry.
+
+Version: 1.1.5-2363
+
+linit.c:
+	- aac_info is flawed and causes periodic panics in certain systems.
+
+build:
+	- Allow the build system to operate as background build
+	- em64t/ia32e binaries did not show in the rpm
+
+Version: 1.1.5-2364 [BigQual, Pratt, Jupiter Dual & 7t]
+
+linit.c:
+	- AAR-2610SA has had a subproduct change from 0x103C/0x0295 to
+	  0x103C/0x3227.
+	- Some adapters have internal limits of 34 SG elements as a result
+	  of a bug of not splitting requests up when cache is disabled when
+	  sending them to the CHIM. Created a quirk for the adapters that
+	  have this limit.
+
+Version: 1.1.5-2365
+
+aachba.c:
+	- Neglected to add maximum_num_physical check to the srb handler.
+	- leading space on inquiry code was flawed as a result of a typographic
+	  error (replace ! with *)
+
+linit.c:
+	- ASR-4005SAS for IBM is designated as an 8i (ADPmp71521)
+	- Added check for late completion of command during timeout
+	- called aac_get_fw_debug_buffer() after init
+
+fwdebug.c+fwdebug.h
+	- Added firmware debug print handlers
+
+build:
+	- RH floppy disk was limited to 864KB, let it open up to 1.4MB. The
+	  risk is that 864KB was about all the ramdisk could handle when
+	  extracting, so we will no longer get a report of disk overrun as
+	  a warning to existing OS releases. We do not know what will overload
+	  the ramdisk during install. (ADPmp72476)
+	- Product ID list for aacraid is broken in the build due to changes
+	  resulting from incorporating the 2.6 tree.
+	- em32t binaries did not show in the rpm fix broke SuSE releases that
+	  utilize the 2.4.19 kernel (ADPmp73104)
+
+commsup.c:
+	- Added support for sending the time every 30 minutes.
+
+Version: 1.1.5-2366
+
+commctrl.c:
+	- Fixed 64 bit version of the SCB ioctl call as it was not translating
+	  the 32 bit scatter-gather correctly for scatter gather elements
+	  beyond the first one. Do not believe this issue presented a problem
+	  for any Adaptec management products due to their needs as they
+	  limited their SG to only one entry.
+
+build:
+	- Added 2.4.19-238
+	- Added 2.4.19-241
+	- Added 2.4.19-248
+	- Added 2.4.19-251
+
+Version: 1.1.5-2367
+
+linit.c:
+	- Added Themisto discovery to driver
+	- Added AAC_QUIRK_MASTER and AAC_QUIRK_SLAVE to deal with controller
+	  pairs.
+	- Changed Prowler "ESD SO-DIMM PCI-X SATA ZCR" to "ASR-2026ZCR".
+	- Return FAILED when hba_reset completed, the ten second bus settling
+	  delay is counter productive.
+
+aacraid.h+linit.c: Christoph Hellwig <hch@lst.de>
+	- drop casting surrounding iomap and ioremap and use the __iomem
+	  type enhancement.
+
+csmi.c+csmi.h:
+	- Added CSMI ioctl support.
+
+install.sh:
+	- log both successful and failed installations and limit complaints
+	  about installation to a minimum by not repeating similar failure
+	  messages.
+
+aachba.c:
+	- vtune reports that 2% of the time dealing with read calls was
+	  devoted to get_sd_devname(). Optimized codepath.
+
+Version: 1.1.5-2368
+
+build:
+	- Added 2.4.27 debian smp kernel to build
+	- Added 2.6.7-1.451.2.3 RHEL4 alpha 4 to the build
+	- Added 2.6.8-1.602 RHEL4 beta 1 to the build
+	- Added 2.6.5-7.109.5 SuSE 9.1 errata to the build
+
+csmi.h:
+	- Changed from CSMI_8_BYTE_ALLIGNED to CSMI_8_BYTE_ALIGNED
+
+csmi.c:
+	- failure on return from copy_to_user is ignored, but (void) is
+	  not the way to ignore it based on compiler warnings.
+	- scb size is set to 16 always.
+	- scb flags is set to 0 always.
+
+linit.c+compat.h:
+	- scsi_sleep() renamed to ssleep() in 2.6.9 kernel
+
+commctrl.c:
+	- 32 bit application issuing a raw srb in a 64 bit address space
+	  is not handled correctly for the fibsize calculation.
+	- Limit the number of scatter gather entries to 32, and zero
+	  out the references to those sg entries.
+
+Version: 1.1.5-2369
+
+compat.h:
+	- 2.6.8-1.602 RHEL4 beta 1 kernel looks more like 2.6.9, so needed to
+	  define scsi_sleep for kernels 2.6.8 and up rather than 2.6.9 and up.
+
+linit.c: Chris Trown <ctrown@uoregon.edu>
+	- Added an include for linux/delay.h to pick up the definition of
+	  ssleep().
+	- Added `other' Themisto ID to list.
+
+csmi.h:
+	- bumped to 0.83 version
+
+csmi.c:
+	- Acquired slot number from Supplementary Adapter Info SlotNumber
+	  field
+	- Added support to determine the actual bus type (SAS, SATA, Other).
+
+build:
+	- Added support for 2.4.21-22.EL (RHEL3 errata)
+	- Added support for 2.6.5-7.111 (SLES9 NLD)
+	- Added support for 2.4.21-243 (SuSE 9.x errata)
+
+aachba.c:
+	- valid must clear if VM_Nameserve fails on scan
+	- setinqstr has the possibility of overflowing the inquiry structure,
+	  the results are a damaged stack.
+
+commsup.c:
+	- do a probe_container before issuing scan as the adapter can take
+	  some time to write DDF data (not SCSI).
+
+aacraid.h:
+	- added definition of probe_container.
+
+Version: 1.1.5-2370
+
+aacraid.h+commsup.c+aachba.c+commctrl.c+comminit.c+linit.c+sa.c: Adrian Bunk <bunk@stusta.de>
+	- Make some needlessly global code static
+
+linit.c:
+	- Added Intruder (AAR-2420SA, AAR-2620SA & AAR-2820SA)
+
+aachba.c+commsup.c:
+	- Enable a 50 second timeout on the first asynchronous command to
+	  permit the driver to error out and report the hardware failure.
+
+linit.c:
+	- Fixed a comment completion problem for Intruder additions.
+
+build:
+	- Added support for 2.6.8-24 (SuSE 9.2)
+
+Version: 1.1.5-2371
+
+aachba.c: Jens Axboe
+	- Use a busy status return with scsi_done rather than -1 to
+	  signal OS to try again later for aac_read and aac_write to
+	  meet with acceptable coding standards.
+
+aachba.c+linit.c: Mark Salyzyn & Christoph Hellwig <hch@infradead.org>
+	- Moved AAC_EXTENDED_TIMEOUT to set sdev->timeout instead of
+	  inline for every command in the 2.6 variant.
+
+linit.c:
+	- There is a subsystem device id clash between SATAHAWK and INTRUDER
+	  and is giving the BIOS group some grief. Therefore the subsystem
+	  device ID for intruder is changed to 029B, 029C and 029D for 8, 6,
+	  and 4 port versions respectively.
+	- Added FSACTL_GET_VERSION_MATCHING and FSACTL_SEND_LARGE_FIB ioctls to
+	  list of supported 32 bit ioctl calls.
+
+build:
+	- enhanced README.txt to also provide a brief description of the
+	  binary file.
+	- Added support for a RHEL3 i686 ISO image as well.
+	- Added support for 2.6.5-7.109.12 (SLES9/SuSE9.1 SP1 B2 i386)
+	- Added support for 2.6.5-7.109.13 (SLES9/SuSE9.1 SP1 B2 x86_64)
+	- Added support for 2.6.5-7.115 (SLES9/SuSE9.1 SP1 B3)
+	- Added support for 2.6.5-1.358 (RH FC2)
+	- Added support for 2.6.9-1.667 (RH FC3)
+	- Added support for 2.4.21-260 (SuSE 9 errata)
+	- Added support for 2.4.21-261 (SuSE 8 errata)
+
+csmi.c:
+	- return code for CSMIGetSATASignature is under the control of the
+	  firmware and should not be blindly set to SUCCESS if the command
+	  succeeded.
+
+
+Version: 1.1.5-2372
+
+build:
+	- Added support for 2.6.9-1.648_EL (RHEL4 beta 2)
+
+linit.c:
+	- trim space from Model
+
+install.sh:
+	- Add /etc/modprobe.conf as another modules configuration file.
+	- If the module in the initrd does not match, but has the same
+	  `size' values, then report a `possibly stripped' warning message.
+
+Version: 1.1.5-2373
+
+build:
+	- Use "Avon Park SIT" for this build for the version identifier
+
+commsup.c:
+	- enable scsi-scan-single (ADPmp75534 & ADPmp69336)
+
+Version: 1.1.5-2374
+
+build:
+	- Added support for 2.6.5-7.111.5 (SLES9 NLD errata)
+	- Added support for 2.6.5-7.128 (SLES9 SP1 B4)
+	- Added support for 2.6.5-7.134 (SLES9 SP1 RC)
+	- Added support for 2.6.9-1.906_EL (RHEL4 RC)
+
+commsup.c:
+	- disable scsi-scan-single for 2.6 kernels, proc_scsi no longer
+	  exported
+
+install.sh
+	- Missed a double quote in the scripting to reduce size sensitivity.
+
+Version: 1.1.5-2375 (Avon Park SIT)
+
+csmi.c:
+	- Paramters.uFlags is a bit field, not a state.
+	- cdbLength needs to be hard coded to 14 from 16 (beware, 2TB warning).
+	- Set the srbFlags based on data direction or if there is any data to
+	  send at all (HOST_FLAGS_DATA_IN/DATA_OUT/NO_DATA_TRANSFER).
+
+csmi.h:
+	- Added definition for HOST_FLAGS_DATA_IN/DATA_OUT/NO_DATA_TRANSFER.
+
+Version: 1.1.5-2376 (This is a code stream identifier)
+
+linit.c:
+	- Added ICP Lancer products ICP9024R0 and ICP9014R0.
+	- Added include of asm/ioctl32.h
+	- Report ServeRAID for driver name if IBM 8i.
+
+aacraid.h
+	- Added definition for IOP_RESET synchronous command
+
+rkt.c+rx.c+linit.c+aacraid.h+commsup.c+aachba.c+csmi.c+comminit.c+commctrl.c+compat.h
+	- Merged code and style changes in 2.6.10-rc3-bk14 into codebase.
+
+aachba.c:
+	- set the scsi device as removeable during the Read Capacity call.
+	  (ADPmp76369)
+
+pci.ids:
+	- Submitted patch to pci-ids@ucw.cz to update the vital product list
+	  to match the products in the linit.c file (ADPmp77082)
+
+build:
+	- Added support for 2.4.21-20.0.1.EL (RHEL3 errata)
+	- Added support for 2.4.21-27.EL (RHEL3 QU4)
+	- Added support for 2.4.21-27.0.1.EL (RHEL3 errata)
+
+Version: 1.1.5-2377 (Avon Park SIT)
+
+linit.c:
+	- Dropped the maximum number of commands down to 16 per target if on
+	  an x86_64 machine with more than 4GB of memory when built in the
+	  2.4.* environment.
+
+Version: 1.1.5-2378 (CERC Test)
+
+linit.c:
+	- Dropped the maximum number of commands down to 10 per target for
+	  this test.
+
+Version: 1.1.5-2379 (CERC Test)
+
+build:
+	- Added support for 2.6.9-5.EL (RHEL4 RC)
+	- Added support for 2.6.5-7.139 (SLES9 SP1)
+	- Added support for 2.4.9-e.57 (RHAS QU6)
+	- Added support for 2.4.9-e.59 (RHAS QU6 errata 59)
+
+commsup.c:
+	- Added kernel ifdef's to handle scsi_add_target and
+	  scsi_remove_target calls.
+
+aachba.c+aacraid.h:
+	- Added AAC_DEBUG_INSTRUMENT_DAC_CERC to disable 64 bit scatter gather
+	  for only the CERC SR2 product.
+
+Version: 1.1.5-2380 (This is a code stream identifier)
+
+aachba.c+comminit.c:
+	- Added numacb insmod parameter.
+
+aachba.c+aacraid.h
+	- Remove AAC_DEBUG_INSTRUMENT_DAC_CERC code.
+
+build:
+	- Error in incorporating the RHAS2.1 QU6 kernel (2.4.9-e.57) on to the
+	  driver disk (ADPmp78010)
+	- Same problem with RHEL4 RC (2.6.9-5.EL) (ADPmp69861)
+
+Version: 1.1.5-2381 (This is a code stream identifier)
+
+build:
+	- Added support for 2.4.21-273 (SLES 8 errata 273)
+	- Added support for 2.6.5-7.111.30 (SLES 9 errata 30)
+	- Added support for 2.6.8-24.11 (SuSE 9.2 errata 11)
+	- Added support for 2.4.19.SuSE-256 (SLES8 x86_64 errata 256)
+	- Added support for 2.4.21-9.EL (RHEL3 QU1)
+	- Added support for 2.6.8.1-12mdk (Mandrake 10.1)
+	- Added support for 2.6.9-1.11_FC2 (FC2)
+	- Added support for 2.6.10-1.9_FC2 (FC2)
+	- Updated dkms to v2.0.5
+
+commsup.c+aacraid.h
+	- Changed Plug-n-Play state machine to be per-array rather than
+	  per-adapter (ADPmp77096)
+
+Version: 1.1.5-2382 (This is a code stream identifier)
+
+build:
+	- Added support for 2.4.21-276 (SLES8/UL1 SP4 B2)
+	- Added support for 2.6.10-1.8_FC2 (FC2)
+	- Added support for 2.6.10-1.12_FC2 (FC2)
+	- Added support for 2.6.9-1.681_FC3-2.6 (FC3)
+	- Added support for 2.6.9-1.724_FC3-2.6 (FC3)
+	- Added support for 2.6.10-1.737_FC3-2.6 (FC3)
+	- Added support for 2.6.10-1.741_FC3-2.6 (FC3)
+	- Added support for 2.6.10-1.760_FC3-2.6 (FC3)
+
+linit.c:
+	- vmware specifically utilizes the file->private_data. They will be
+	  correcting the problem in future releases thus the fix will work
+	  in both environments being obnoxious^H^H^H^H^H^H^H^H^Hinnocuous in
+	  the later releases.
+
+aachba.c:
+	- vmware has problems with the coalescing code.
+
+commctrl.c:
+	- used sizeof(struct sgmap *) instead of sizeof(struct sgmap) and
+	  misrepresented the size of the srb command truncating the scatter
+	  gather size from the incoming data in 64 bit architectures with
+	  more than 4G of memory populated in the system. (ADPmp78515,
+	  ADPmp78128, ADPmp76236 & ADPmp78228)
+
+Version: 1.1.5-2383 (Avon Park SIT)
+
+Makefile:
+	- Self detect the various SCSI_HAS_* flags rather than depending on
+	  the build system to generate them.
+
+aacraid.h+aachba.c
+	- Added VM_NameServe64
+	- Added capacity64 field to end of the mnt information.
+	- Do not respond to SERVICE_ACTION_IN when card not capable of 64 bit
+	  lba.
+
+commctrl.c:
+	- The srbcmd in 64 bit environments with more than 4GB of memory
+	  are utilizing the sgentry64 elements for the scatter gather, thus
+	  the counts were not parsed correctly when copying the data back
+	  to the user. (ADPmp78846)
+
+build:
+	- Removed support for linux-2.4.21-1.1931.2.349.2.2.ent.RH
+	- Removed support for linux-2.4.21-1.1931.2.393.ent.RH
+	- Removed support for linux-2.4.21-1.1931.2.399.ent.RH
+	- Removed support for debug configurations
+	- Split AS2.1 summit/enterprise from up/smp
+	- pcitable for aacraid driver disk is missing " after the ICP cards
+
+Version: 1.1.5-2384 (Avon Park SIT)
+
+aacraid.h+rkt.c+rx.c+sa.c:
+	- use aac_io_cpu_to_le* and aac_io_le*_to_cpu to deal with perceived
+	  discrepancies in write* and read* io handlers.
+
+commsup.c+commctrl.c:
+	- header.Size and header.SenderSize is a 16 bit field, erroneously
+	  handled by 32 bit swap handlers.
+
+commsup.c+comminit.c+commctrl.c+aachba.c+dpcsup.c:
+	- missing swap handlers for various packets.
+
+aachba.c:
+	- When 'first' command times out, return error immediately, do not
+	  fall through.
+
+csmi.c+aachba.c+linit.c:
+	- monitor/kernel/build information from adapter needs to be swapped
+	  in BE architectures.
+
+aachba.c:
+	- Revert 64 bit LBA code
+
+Version: 1.1.5-2385 (Avon Park SIT)
+Version: 1.1.5-2386 (Avon Park SIT, revert to 1.1.5-2383, plus one managment change)
+
+aachba.c+linit.c+compat.h: Tobias Klauser <tklauser@nuerscht.ch>
+	- Use the DMA_{64,32}BIT_MASK constants
+
+linit.c:
+	- scsi_host_alloc calls scsi_register which prints a report in some
+	  versions of the 2.4 kernel. The aac_info function is not ready to
+	  be called at that time as the hostdata has not been set up, so we
+	  report a 'default' name of "AAC" (ADPmp78060).
+
+aacraid.h+aachba.c:
+	- Adding any u64 to a structure will cause, in some cases of the
+	  compiler, 8 byte alignment constraints which can reshape the
+	  structure at each element even before the u64 definition. Changed to
+	  using a pair of u32's for capacity64 element in the mount structure.
+	  (ADPmp79142)
+
+Version: 1.1.5-2387 (This is a code stream identifier)
+
+build:
+	- Added support for 2.4.21-277 (SLES8/UL1 SP4 RC1)
+
+aacraid.h+rx.c+rkt.c+sa.c+linit.c+Makefile:
+	- Added support for dump_poll. Currently RHEL4 and RHFC support this
+	  new interface. (ADPmp79442)
+
+Version: 1.1.5-2388 (This is a code stream identifier)
+
+compat.h+aachba.c+aacraid.h+commctrl.c+comminit.c+commsup.c+dpcsup.c+linit.c:
+	- Merged code and style changes in 2.6.11-rc5-bk3 into codebase.
+
+linit.c:
+	- Added support for shost_attrs & sysfs.
+
+linit.c+csmi.c:
+	- Dropped reference to Red Hat in printouts (ADPmp79559 & ADPmp79382)
+
+build:
+	- Strip kernel environment check for sourceball that is part of the
+	  DKMS packaging, broke DKMS build environment (ADPmp79708)
+
+Version: 1.1.5-2389 (This is a code stream identifier)
+
+build:
+	- Switch from 3.3 compiler to 3.4 for RHEL4 ia64 and FC3 all archs
+	  & all errata.
+	- Added support for 2.4.18-19.7.x (RH7.3 errata 19)
+
+linit.c: Domen Puncer <domen@coderock.org>
+	- Change from pci_module_init to pci_register_driver.
+
+linit.c:
+	- Loop for determining unique_id failed and generates a pattern of
+	  0, 1, 0, 0, ... (ADPmp79694)
+	- Added ICP9047MA and ICP9087MA to product probe. Added AvonPark Lite.
+
+linit.c+aachba.c:
+	- An SG list of 1K,4K,...,4K,64K+4K-1K got produced, the math for the
+	  maximum I/O should be (sg_tablesize * 8) + 112 instead.
+
+rkt.c+rx.c:
+	- Adapter Panic handler has AAC_IO_USES_CPU_ORDER misspelled.
+
+commsup.c:
+	- time stamp is an u32, not an unsigned long.
+
+csmi.c:
+	- Send LoopCount rather than bufferOffset to param[4] of GetRAIDConfig
+	  command. (ADPmp77631, ADPmp79282)
+
+Version: 1.1.5-2390 (This is a code stream identifier)
+
+build:
+	- Added support for 2.4.21-278 (SLES8/UL1 SP4 RC3)
+	- Removed support for 2.4.21-276
+	- Removed support for 2.4.21-277
+	- Removed support for 2.4.18-24.7.x (RH7.3 errata 24)
+	- Removed support for 2.4.18-26.7.x (RH7.3 errata 26)
+	- Removed support for 2.6.10-1.741_FC3-2.6 (FC3 errata 741)
+	- Dropped all the sles9-sp1 betas from the packaging.
+	- strip date stamps, then join.file the patches before commiting them
+	  to the archive.
+
+modules.equiv
+	- Declared 2.4.21-277 to be identical to 2.4.21-278
+	- Declared 2.4.18-24.7 to be identical to 2.4.18-19.7
+	- Declared 2.4.18-26.7 to be identical to 2.4.18-19.7
+	- Declared 2.6.10-1.737_FC3-2.6 to be identical to 2.6.10-1.741_FC3-2.6
+
+linit.c:
+	- return code from pci_register_driver() is not of the same form
+	  as pci_module_init. Only negative return values should be reported
+	  as an error.
+
+install.sh:
+	- Added /etc/grub.conf to list of grub files
+	- redirect error on boot configuration file awk script for cases when
+	  boot configuration file is not found.
+
+Version: 1.1.5-2391 (This is a code stream identifier)
+Version: 1.1.5-2392 (Branch off 1.1.5-2372 with pci_unregister_driver if aac_count drops to zero).
+
+build:
+	- Added support for 2.6.10-1.14_FC2-2.6 (RH FC2 Errata 14)
+	- Added support for 2.6.10-1.770_FC2 (RH FC2 Errata 770)
+	- Added support for 2.6.10-1.766_FC3-2.6 (RH FC3 Errata 766)
+	- Added support for 2.6.10-1.770_FC3-2.6 (RH FC3 Errata 770)
+	- Removed support for 2.6.10-1.9_FC2 (FC2) and placed in
+	  module.equiv
+	- Removed support for 2.4.18-e.47 (RHAS 2.1 IA64) and placed in
+	  module.equiv
+	- Added support for 2.4.18-e.52 (RHAS 2.1 IA64) in module.equiv
+	- Added support for 2.4.18-e.54 (RHAS 2.1 IA64) in module.equiv
+	- Generate dkms package with build number, but add a Branch Type
+	  of "dkms" into the version information reported by the driver.
+	- Generate source package with a Branch Type of "custom" into the
+	  version information reported by the driver.
+	- build rpm packages as 'noarch' and not as default of the build
+	  system 'i386'.
+
+csmi.c:
+	- uMaxDrivesPerSet needs to be acquired from the Firmware,
+	  rather than using the driver physical limits (ADPmp80188)
+
+aachba.c:
+	- Added some new container types (RAID5D, RAID5D0, RAID1E, RAID6
+	  and RAID60) to default array naming list.
+	- Changed over to new format of VM_NameServe64 (changed before
+	  customer release of Firmware that utilized interim format).
+
+linit.c:
+	- Added Hurricane ASR-4810SAS
+	- Added sensitivity to AAC_DRIVER_BRANCH in order to propogate
+	  driver source with keys as to their history.
+
+linit.c: (Mark Haverkamp <markh@osdl.org>
+	- Restructured sys handler to match standards expectations.
+	  ADPmp80589
+
+install.sh:
+	- Do not compare result in initrd to any backup orig drivers
+	  that may have been left in the /lib/modules tree.
+	- Added support for elilo.efi
+
+commsup.c+comminit.c:
+	- pci_alloc_consistent acquired GFP_DMA arena pool. This has
+	  been shown as a problem on 2.4 based kernels on em64t machines
+	  with > 4GB of memory which typically exhaust the DMA pool. So,
+	  prior to making the call, we will acquire GFP_ATOMIC
+	  memory first and check if it is 31BIT limited, and instead use
+	  that memory rather than resorting to the precious DMA pool. The
+	  other workarounds are to limit the memory to 4GB, set the
+	  memsize to 4GB, or to tell the SW IOMMU to reduce it's memory
+	  requirements (swiotlb=12288).
+
+Version: 1.1.5-2393 (This is a code stream identifier)
+
+linit.c+commctrl.c:
+	- Added AAC_DEBUG_INSTRUMENT_IOCTL_SENDFIB
+
+linit.c: Ming Zhang <mingz@ele.uri.edu> & Mark Salyzyn
+	- Set max_cmd_len to 16 to permit SAI_READ_CAPACITY_16 call to
+	  get through the scsi layer to the driver.
+
+linit.c:
+	- Added calls to csmi_register_ioctl32_conversion() and
+	  csmi_unregister_ioctl32_conversion()
+
+csmi.c:
+	- Added csmi_register_ioctl32_conversion(void) and
+	  csmi_unregister_ioctl32_conversion(void)
+
+install.sh:
+	- notice that we are doing an ELILO configuration on ia64
+
+aachba.c:
+	- Removed sundry debugging prints
+
+build:
+	- Added MODULES_CONF_OBSOLETES_ONLY[0]="${PRODUCT}" to dkms.conf
+	- Added support for 2.6.5-7.147 (SLES9 SP1 errata 147) to
+	  modules.equiv
+	- Added support for 2.6.5-7.151 (SUSE9.1 SP1 errata 151) to
+	  module.equiv
+	- Added support for 2.4.21-278-x86_64 (SLES8 SP4 64 bit)
+
+Makefile:
+	- Use TOPDIR instead of AAC_ROOT
+
+Version: 1.1.5-2394 (This is a code stream identifier)
+
+build:
+	- Added support for 2.4.20-133 (SuSE 8.2 errata 133)
+	- Added support for 2.4.21-286 (SuSE 9.0 errata 286) to modules.conf
+	- Added support for 2.6.8-24.14 (SuSE 9.2 errata 14)
+	- Added support for 2.6.9-5.0.3.EL (RHEL4 errata 3)
+	- Added support for 2.6.9-6.37.EL-2.6 (RHEL4 U1 beta)
+	- Added support for 2.6.10-1.771_FC2 (FC2 errata 771)
+	- Added support for 2.6.11-1.14_FC3 (FC3 errata 773)
+	- Added support for 2.4.21-31.EL (RHEL3 QU5 beta)
+
+aachba.c+linit.c: Tobias Klauser <tklauser@nuerscht.ch> & Domen Puncer <domen@coderock.org>
+	- added include for linux/dma-mapping.h
+
+linit.c: Konstantin Khorenko <khorenko@sw.ru>
+	- aac_info and aac_detect need to be active on in-kernel
+	  versions of the driver.
+
+linit.c:
+	- aac_show_flags is a newline separated list
+	- Added SAI_READ_CAPACITY_16 to list of possible flags in
+	  aac_show_flags
+	- aac_get_adapter_info status needs to be placed in the 'error'
+	  variable to unload correctly and deinit rather than unmap
+	  (ADPmp83209).
+
+commsup.c:
+	- allocate 8 more NewFibs than noticed to deal with high AIF
+	  traffic.
+	- Added support for wait=-2 to do a 'silent' timeout of a
+	  command.
+	- Increased the timeout for wait<0 to 3 minutes from 50 seconds
+	  due to paranoia (ADPmp83209)
+
+comminit.c:
+	- issue the adapter shutdown with a wait=-2 value (ADPmp78635)
+
+aacraid.h+rx.c+rkt.c+sa.c+linit.c:
+	- Added a disable_interrupt method to prevent future adapter
+	  interrupts when shut down. Call this method before free_irq(),
+	  preferably before dealocating structures. (ADPmp83209)
+
+commsup.c+comminit.c:
+	- revert out the GFP_KERNEL kmalloc call to see if it reports an
+	  address <2GB instead of using pci_alloc_consistent. Fix this
+	  another day. (ADPmp83209)
+
+Version: 1.1.5-2395 (This is a code stream identifier)
+
+build:
+	- Added support for 2.6.5-7.162 (SLES9 sp2 beta1)
+
+aachba.c+linit.c+aacraid.h+commsup.c+comminit.c+dpcsup.c:
+	- Merge differences in the 2.6.12-rc2 kernel.org branch of the
+	  driver.
+
+linit.c:
+	- Added ICP9085LI & ICP5085AU
+	- Modified support for ASR4810SAS
+
+aacraid.h+commsup.c:
+	- If ROMB heritage adapter, enable printf
+
+Version: 1.1.5-2396 (Avon Park SIT)
+
+build:
+	- Added support for 2.6.11.4-20a (SUSE 9.3)
+	- Added support for 2.6.9-5.0.3.EL-2.6 (CentOS4) to driver disks
+	- Added support for 2.6.9-5.0.5.EL (RHEL4 Errata 5) to
+	  modules.equiv
+	- Added support for 2.4.21-27.0.2.EL-2.4 (CentOS3) to driver
+	  disks
+
+linit.c+aacraid.h:
+	- Merge differences in the 2.6.12-rc2 kernel.org branch of the
+	  driver.
+
+linit.c:
+	- str() did not do the right thing, needed to nest macros.
+
+aachba.c+aacraid.h+commctrl.c+comminit.c+commsup.c+dpcsup.c+linit.c: Mark Haverkamp <markh@osdl.org>
+	- Remove sparce warnings
+
+readme.txt(dkms):
+	- Added strings for 'ips' driver
+	- Added documentation on how to make a 'suse' driver disk
+
+Version: 1.1.5-2397 (This is a code stream identifier)
+
+build:
+	- sort distributions when code has to cut the products into
+	  pieces.
+
+commctrl.c:
+	- byte_count is converted from le32 to cpu, then again when used
+	  in the following line. Dropped the second le32_to_cpu call. No
+	  side effects in an LE machine.
+
+linit.c:
+	- MODULE_VERSION limited to 2.6.4 and higher
+
+Version: 1.1.5-2398 (Avon Park SIT)
+Version: 1.1.5-2399 (This is a code stream identifier)
+
+build:
+	- Added linked equivalent entries for multi-OS driver disk
+	  images in driverdisks tarball
+	- dkms package versioning is ${VERSION}.${REVISION}.${BUILD} as
+	  required by DKMS and changed the tarball package name to
+	  ${VERSION}.${REVISION}-${BUILD} to match the other build
+	  product names. Adjusted dkms documentation to match.
+	- Added support for 2.4.21-27.0.4.EL-2.4 (RHEL3 QU4 Errata 4) to
+	  modules.equiv
+
+install.sh
+	- RHEL3, RHEL4, FC2 and FC3 all can add a -2.4 or -2.6 into the
+	  kernel name that does not match the /lib/modules/kernel names.
+
+Version: 1.1.2-2400 - 1.1.2-lk2 + LARGE_FIB patch
+Version: 1.1.5-2400 (Enzo)
+
+build:
+	- Added support for 2.6.5-7.104 (SLES9 errata) to module.equiv
+	- Added support for 2.6.5-7.108 (SLES9 errata)
+	- Added support for 2.4.21-169 (SLES8 errata)
+	- Added support for 2.4.21-190 (SLES8 errata) to module.equiv
+	- Added support for 2.4.21-192 (SuSE 9 errata) to module.equiv
+	- Added support for 2.4.21-196 (SLES8 errata) to module.equiv
+	- Added support for 2.4.21-198 (SLES8 errata) to module.equiv
+	- Added support for 2.4.21-199 (SuSE 9 errata)
+	- Added support for 2.4.21-202 (SuSE 9 errata) to module.equiv
+	- Added support for 2.4.21-207 (SLES8 errata) to module.equiv
+	- Added support for 2.4.21-215 (SLES8 errata) to module.equiv
+	- Added support for 2.4.21-226 (SuSE 9 errata) to module.equiv
+	- Added support for 2.4.21-238 (SuSE 9 errata) to module.equiv
+	- Added support for 2.4.21-280 (SLES8 errata) to module.equiv
+	- Added support for 2.6.8-24.3 (SuSE 9.2 errata 3)
+	- Added support for 2.4.9-e.62 (RHAS2.1 QU7)
+	- Switched support for 2.4.19-340 to module.equiv
+	- 2.6.5-7.162 had the wrong .config entries, CONFIG_RELEASE="0"
+	  instead of "7.162"
+
+Version: 1.1.5-2400 (This is a code stream identifier)
--- linux-2.6.8.1-t043-libata-update/drivers/scsi/aacraid/csmi.c	1970-01-01 03:00:00.000000000 +0300
+++ aacraid-drv/drivers/scsi/aacraid/csmi.c	2005-04-20 23:18:38.000000000 +0400
@@ -0,0 +1,1679 @@
+/*
+ *	Adaptec AAC series RAID controller driver
+ *	(c) Copyright 2004 Adaptec, Inc
+ *
+ * Copyright (c) 2004 Adaptec, Inc. (aacraid@adaptec.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Module Name:
+ *   csmi.c
+ *
+ * Abstract: All CSMI IOCTL processing is handled here.
+ */
+
+/*
+ * Include Files
+ */
+
+#include <linux/types.h>
+#include <linux/wait.h>
+#include <linux/spinlock.h>
+#include <asm/semaphore.h>
+#include <linux/kernel.h>
+#include <linux/blkdev.h>
+#include <linux/completion.h>
+#include <linux/string.h>
+#include <linux/sched.h>
+#include <linux/pci.h>
+#include <asm/uaccess.h> /* For copy_from_user()/copy_to_user() definitions */
+#include <linux/slab.h> /* For kmalloc()/kfree() definitions */
+#include "aacraid.h"
+#include "fwdebug.h"
+#include <linux/version.h> /* For the following test */
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+# include "scsi.h"
+# include "hosts.h"
+#else
+# include <scsi/scsi.h>
+# include <scsi/scsi_host.h>
+# include <linux/pci.h>
+# include <linux/dma-mapping.h>
+#endif
+#if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) ? defined(__x86_64__) : defined(CONFIG_COMPAT))
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,3))
+#include <linux/syscalls.h>
+#include <linux/ioctl32.h>
+#endif
+#if ((KERNEL_VERSION(2,4,19) <= LINUX_VERSION_CODE) && (LINUX_VERSION_CODE <= KERNEL_VERSION(2,4,21)))
+# include <asm-x86_64/ioctl32.h>
+#elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+# include <asm/ioctl32.h>
+#elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,3))
+# include <linux/ioctl32.h>
+#endif
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+# include <asm/uaccess.h>
+#endif
+#endif
+
+#if (defined(AAC_CSMI))
+
+#include "csmi.h"
+
+
+/*
+ * Routine Description:
+ *	This routine will verify that the *ppHeader is big enough
+ *	for the expected CSMI IOCTL buffer.
+ * Return Value:
+ *	ppHeader
+ *	0 - Success ppHeader set up with successful completion code
+ *	!0 - CSMI_SAS_STATUS_INVALID_PARAMETER as the ReturnCode.
+ */
+static int
+aac_VerifyCSMIBuffer(
+	struct aac_dev ** pDev,
+	void __user * arg,
+	unsigned long csmiBufferSizeToVerify,
+	PIOCTL_HEADER * ppHeader)
+{
+	u32 Length;
+	int Rtnval;
+	struct aac_dev * dev = *pDev;
+	extern struct list_head aac_devices; /* in linit.c */
+
+	fwprintf((dev, HBA_FLAGS_DBG_FUNCTION_ENTRY_B,
+	  "aac_VerifyCSMIBuffer: Enter"));
+
+	*ppHeader = (PIOCTL_HEADER)NULL;
+
+	if (copy_from_user((void *)&Length,
+	  (void __user *)&((PIOCTL_HEADER)arg)->Length, sizeof(u32))) {
+		fwprintf((dev, HBA_FLAGS_DBG_ERROR_B,
+		  "aac_VerifyCSMIBuffer: Acquire Length Failure"));
+		Length = CSMI_SAS_STATUS_INVALID_PARAMETER;
+		/* Will msot probably fail */
+		Rtnval = copy_to_user(
+		  (void __user *)&((PIOCTL_HEADER)arg)->ReturnCode,
+		  (void *)&Length, sizeof(u32));
+		Rtnval = -EFAULT;
+	} else if ((Length < sizeof(IOCTL_HEADER))
+	 || (Length < csmiBufferSizeToVerify)
+	 || (csmiBufferSizeToVerify < sizeof(IOCTL_HEADER))) {
+		fwprintf((dev, HBA_FLAGS_DBG_ERROR_B,
+		  "aac_VerifyCSMIBuffer:"
+		  " sizeof(IOCTL_HEADER)=%u, Length=%u, MinPacketLength=%u",
+		  sizeof(IOCTL_HEADER), Length, csmiBufferSizeToVerify));
+		Length = CSMI_SAS_STATUS_INVALID_PARAMETER;
+		if (copy_to_user(
+		  (void __user *)&((PIOCTL_HEADER)arg)->ReturnCode,
+		  (void *)&Length, sizeof(u32)))
+			Rtnval = -EFAULT;
+		else
+			Rtnval = -EINVAL;
+	} else if (!(*ppHeader = kmalloc(Length, GFP_KERNEL))) {
+		fwprintf((dev, HBA_FLAGS_DBG_ERROR_B,
+		  "aac_VerifyCSMIBuffer: Acquire Memory %u Failure",
+		  Length));
+		Length = CSMI_SAS_STATUS_INVALID_PARAMETER;
+		if (copy_to_user(
+		  (void __user *)&((PIOCTL_HEADER)arg)->ReturnCode,
+		  (void *)&Length, sizeof(u32)))
+			Rtnval = -EFAULT;
+		else
+			Rtnval = -ENOMEM;
+	} else if (copy_from_user((void *)*ppHeader, arg, Length)) {
+		fwprintf((dev, HBA_FLAGS_DBG_ERROR_B,
+		  "aac_VerifyCSMIBuffer: Acquire Content Failure"));
+		kfree(*ppHeader);
+		*ppHeader = NULL;
+		Length = CSMI_SAS_STATUS_INVALID_PARAMETER;
+		/* Will most probably fail */
+		Rtnval = copy_to_user(
+		  (void __user *)&((PIOCTL_HEADER)arg)->ReturnCode,
+		  (void *)&Length, sizeof(u32));
+		Rtnval = -EFAULT;
+	} else {
+		list_for_each_entry(dev, &aac_devices, entry)
+			if (dev->id == (*ppHeader)->IOControllerNumber)
+				break;
+		if (dev == (struct aac_dev *)NULL) {
+			dev = *pDev; /* Return to original host */
+			fwprintf((dev, HBA_FLAGS_DBG_ERROR_B,
+			  "aac_VerifyCSMIBuffer: Acquire %d Indexed Controller Failure",
+			  (*ppHeader)->IOControllerNumber));
+			kfree(*ppHeader);
+			*ppHeader = NULL;
+			Length = CSMI_SAS_STATUS_INVALID_PARAMETER;
+			if (copy_to_user(
+			  (void __user *)&((PIOCTL_HEADER)arg)->ReturnCode,
+			  (void *)&Length, sizeof(u32)))
+				Rtnval = -EFAULT;
+			else
+				Rtnval = -EINVAL;
+		} else {
+			(*ppHeader)->ReturnCode = CSMI_SAS_STATUS_SUCCESS;
+			*pDev = dev;
+			Rtnval = 0;
+		}
+	}
+
+	fwprintf((dev, HBA_FLAGS_DBG_FUNCTION_EXIT_B,
+	  "aac_VerifyCSMIBuffer: Exit, ReturnValue=%d",Rtnval));
+
+	return Rtnval;
+
+}
+
+
+/*
+ * Routine Description:
+ *	This routine will close the *ppHeader.
+ * Return Value:
+ *	0 - Success
+ *	!0 - Failure
+ */
+static inline int
+aac_CloseCSMIBuffer(
+	struct aac_dev * dev,
+	void __user * arg,
+	PIOCTL_HEADER pHeader)
+{
+	int Rtnval = 0;
+
+	fwprintf((dev, HBA_FLAGS_DBG_FUNCTION_ENTRY_B,
+	  "aac_CloseCSMIBuffer: Enter"));
+
+	if (pHeader) {
+		if (copy_to_user(arg, (void *)pHeader, pHeader->Length))
+			Rtnval = -EFAULT;
+		kfree (pHeader);
+	}
+
+	fwprintf((dev, HBA_FLAGS_DBG_FUNCTION_EXIT_B,
+	  "aac_CloseCSMIBuffer: Exit, ReturnValue=%d",Rtnval));
+
+	return Rtnval;
+
+}
+
+typedef struct aac_bus_info DIOCTL;
+typedef DIOCTL * PDIOCTL;
+/* IOCTL Functions */
+#define CsmiGetPhyInfo		0x0070
+#define CsmiSataSignature	0x0071
+
+typedef struct {
+	u32	Status;		/* ST_OK */
+	u32	ObjType;	
+	u32	MethodId;	/* unused */
+	u32	ObjectId;	/* unused */
+	u32	CtlCmd;		/* unused */
+} DIOCTLRESPONSE;
+typedef DIOCTLRESPONSE * PDIOCTLRESPONSE;
+
+#define EnhancedGetBusInfo	0x0000000C
+#define SCSI_MAX_PORTS	10
+#define CSS_BUS_TYPE_SATA 11
+#define CSS_BUS_TYPE_SAS	12
+typedef struct aac_enhanced_bus_info_response {
+	struct aac_bus_info_response BusInfo;
+	/* Enhancements */
+	u32	Version;
+	u32	BusType[SCSI_MAX_PORTS];
+	u8	NumPortsMapped[SCSI_MAX_PORTS];
+	u8	ReservedPad0[2];
+	u32	Reserved[17];
+} ENHANCED_GBI_CSS;
+
+/*
+ * Routine Description:
+ *	This routine is called to request the version information for the
+ *	hardware, firmware, and boot BIOS associated with a storage controller.
+ *
+ * Return Value:
+ *	Status value, to be returned by aac_HandleCSMI, and returned to
+ *	--> Must set CSMI status value in pHeader->ReturnCode.
+ */
+int
+aac_CSMIGetControllerConfig(
+	struct aac_dev * dev,
+	void __user * arg)
+{
+	int Rtnval;
+	PCSMI_SAS_CNTLR_CONFIG_BUFFER pControllerConfigBuffer;
+	PDIOCTL pIoctlInfo;
+	ENHANCED_GBI_CSS * EnhancedBusInfo;
+	struct fib * fibptr;
+	int status;
+
+	fwprintf((dev,
+	  HBA_FLAGS_DBG_FUNCTION_ENTRY_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+	  "aac_CSMIGetControllerConfig: Enter"));
+
+	/*
+	 * Verify buffer size. If buffer is too small, the error status will
+	 * be set for pHeader->ReturnCode in aac_VerifyCSMIBuffer.
+	 */
+	if ((Rtnval = aac_VerifyCSMIBuffer(&dev, arg,
+	  sizeof(CSMI_SAS_CNTLR_CONFIG_BUFFER),
+	  (PIOCTL_HEADER *)&pControllerConfigBuffer))) {
+		fwprintf((dev,
+		  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+		  "aac_CSMISTPPassThru: Exit, ReturnValue = %d",
+		  Rtnval));
+		return Rtnval;
+	}
+
+	pControllerConfigBuffer->Configuration.uBaseIoAddress = 0;
+	pControllerConfigBuffer->Configuration.BaseMemoryAddress.uHighPart
+	  = ((u64)dev->scsi_host_ptr->base) >> 32;
+	pControllerConfigBuffer->Configuration.BaseMemoryAddress.uLowPart
+	  = dev->scsi_host_ptr->base & 0xffffffff;
+	pControllerConfigBuffer->Configuration.uBoardID
+	  = (dev->pdev->subsystem_device << 16)
+	  + dev->pdev->subsystem_vendor;
+	/*
+	 * Slot number can be pulled from
+	 * dev->supplement_adapter_info->SlotNumber in later versions of
+	 * the firmware else we could choose to take Linux PCI device slot
+	 * number PCI_SLOT(dev->pdev->devfn) instead?
+	 */
+	if ((dev->supplement_adapter_info.Version < AAC_SIS_VERSION_V3)
+	 || (dev->supplement_adapter_info.SlotNumber == AAC_SIS_SLOT_UNKNOWN)) {
+		pControllerConfigBuffer->Configuration.usSlotNumber
+		  = SLOT_NUMBER_UNKNOWN;
+	} else {
+		pControllerConfigBuffer->Configuration.usSlotNumber
+		 = dev->supplement_adapter_info.SlotNumber;
+	}
+	pControllerConfigBuffer->Configuration.bControllerClass
+	  = CSMI_SAS_CNTLR_CLASS_HBA;
+	pControllerConfigBuffer->Configuration.bIoBusType
+	  = CSMI_SAS_BUS_TYPE_PCI;
+	pControllerConfigBuffer->Configuration.BusAddress.PciAddress.bBusNumber
+	  = dev->pdev->bus->number;
+	pControllerConfigBuffer->Configuration.BusAddress.PciAddress.bDeviceNumber
+	  = PCI_SLOT(dev->pdev->devfn);
+	pControllerConfigBuffer->Configuration.BusAddress.PciAddress.bFunctionNumber
+	  = PCI_FUNC(dev->pdev->devfn);
+	pControllerConfigBuffer->Configuration.szSerialNumber[0] = '\0';
+	if (dev->adapter_info.serial[0] != 0xBAD0)
+		sprintf(pControllerConfigBuffer->Configuration.szSerialNumber,
+		  "%x", dev->adapter_info.serial[0]);
+	/* Get Bus Type */
+	fibptr = fib_alloc(dev);
+	if (fibptr == NULL) {
+		pControllerConfigBuffer->Configuration.uControllerFlags
+		  = CSMI_SAS_CNTLR_SATA_RAID;
+	} else {
+		fib_init(fibptr);
+
+		pIoctlInfo = (PDIOCTL) fib_data(fibptr);
+		pIoctlInfo->Command = cpu_to_le32(VM_Ioctl);
+		pIoctlInfo->ObjType = cpu_to_le32(FT_DRIVE);
+		pIoctlInfo->MethodId = cpu_to_le32(1);
+		pIoctlInfo->ObjectId = 0;
+		pIoctlInfo->CtlCmd = cpu_to_le32(EnhancedGetBusInfo);
+
+		status = fib_send(ContainerCommand, fibptr,
+		  sizeof(*EnhancedBusInfo),
+		  FsaNormal, 1, 1, NULL, NULL);
+	
+		fib_complete(fibptr);
+	
+		EnhancedBusInfo = (struct aac_enhanced_bus_info_response *) pIoctlInfo;
+	
+		if (status < 0) {
+			pControllerConfigBuffer->Configuration.uControllerFlags
+			  = CSMI_SAS_CNTLR_SATA_RAID;
+		} else switch (EnhancedBusInfo->BusType[0]) {
+		case CSS_BUS_TYPE_SATA:
+			pControllerConfigBuffer->Configuration.uControllerFlags
+			  = CSMI_SAS_CNTLR_SATA_RAID;
+			break;
+		case CSS_BUS_TYPE_SAS:
+			pControllerConfigBuffer->Configuration.uControllerFlags
+			  = CSMI_SAS_CNTLR_SAS_RAID;
+			break;
+		default:
+			pControllerConfigBuffer->Configuration.uControllerFlags
+			  = 0;
+			break;
+		}
+		fib_free(fibptr);
+	}
+
+	pControllerConfigBuffer->Configuration.usBIOSBuildRevision
+	  = cpu_to_le16(le32_to_cpu(dev->adapter_info.biosbuild));
+	pControllerConfigBuffer->Configuration.usBIOSMajorRevision
+	  = cpu_to_le16(le32_to_cpu(dev->adapter_info.biosrev) >> 24);
+	pControllerConfigBuffer->Configuration.usBIOSMinorRevision
+	  = cpu_to_le16((le32_to_cpu(dev->adapter_info.biosrev) >> 16) & 0xff);
+	pControllerConfigBuffer->Configuration.usBIOSReleaseRevision
+	  = cpu_to_le16(le32_to_cpu(dev->adapter_info.biosrev) & 0xff);
+	pControllerConfigBuffer->Configuration.usBuildRevision
+	  = cpu_to_le16(le32_to_cpu(dev->adapter_info.kernelbuild));
+	pControllerConfigBuffer->Configuration.usMajorRevision
+	  = cpu_to_le16(le32_to_cpu(dev->adapter_info.kernelrev) >> 24);
+	pControllerConfigBuffer->Configuration.usMinorRevision
+	  = cpu_to_le16((le32_to_cpu(dev->adapter_info.kernelrev) >> 16) & 0xff);
+	pControllerConfigBuffer->Configuration.usReleaseRevision
+	  = cpu_to_le16(le32_to_cpu(dev->adapter_info.kernelrev) & 0xff);
+	pControllerConfigBuffer->Configuration.usRromBIOSBuildRevision = 0;
+	pControllerConfigBuffer->Configuration.usRromBIOSMajorRevision = 0;
+	pControllerConfigBuffer->Configuration.usRromBIOSMinorRevision = 0;
+	pControllerConfigBuffer->Configuration.usRromBIOSReleaseRevision = 0;
+	pControllerConfigBuffer->Configuration.usRromBuildRevision = 0;
+	pControllerConfigBuffer->Configuration.usRromMajorRevision = 0;
+	pControllerConfigBuffer->Configuration.usRromMinorRevision = 0;
+	pControllerConfigBuffer->Configuration.usRromReleaseRevision = 0;
+
+	Rtnval = aac_CloseCSMIBuffer(dev, arg,
+	  (PIOCTL_HEADER)pControllerConfigBuffer);
+
+	fwprintf((dev,
+	  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+	  "aac_CSMIGetControllerConfig: Exit, ReturnValue=%d, ReturnCode=%x",
+	  Rtnval, pControllerConfigBuffer->IoctlHeader.ReturnCode));
+
+	return Rtnval;
+
+}
+
+
+/*
+ * Routine Description:
+ *	This routine is called to request the current status of the controller.
+ *
+ * Return Value:
+ *	Status value, to be returned by aac_HandleCSMI, and returned to the OS.
+ *	--> Must set CSMI status value in pHeader->ReturnCode.
+ */
+int
+aac_CSMIGetControllerStatus(
+	struct aac_dev * dev,
+	void __user * arg)
+{
+	int Rtnval;
+	PCSMI_SAS_CNTLR_STATUS_BUFFER pStatusBuffer;
+
+	fwprintf((dev,
+	  HBA_FLAGS_DBG_FUNCTION_ENTRY_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+	  "aac_CSMIGetControllerStatus: Enter"));
+
+	/*
+	 * Verify buffer size. If buffer is too small, the error status will
+	 * be set for pHeader->ReturnCode in aac_VerifyCSMIBuffer.
+	 */
+	if ((Rtnval = aac_VerifyCSMIBuffer(&dev, arg,
+	  sizeof(CSMI_SAS_CNTLR_STATUS_BUFFER),
+	  (PIOCTL_HEADER *)&pStatusBuffer))) {
+		fwprintf((dev,
+		  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+		  "aac_CSMIGetControllerStatus: Exit, ReturnValue=%d",
+		  Rtnval));
+		return Rtnval;
+	}
+
+	/*
+	 * Determine and set adapter state
+	 */
+	switch (aac_adapter_check_health(dev)) {
+	case 0:
+		pStatusBuffer->Status.uStatus = CSMI_SAS_CNTLR_STATUS_GOOD;
+		break;
+	case -1:
+	case -2:
+	case -3:
+		pStatusBuffer->Status.uStatus = CSMI_SAS_CNTLR_STATUS_FAILED;
+		break;
+	default:
+		pStatusBuffer->Status.uStatus = CSMI_SAS_CNTLR_STATUS_OFFLINE;
+		pStatusBuffer->Status.uOfflineReason
+		  = CSMI_SAS_OFFLINE_REASON_NO_REASON;
+	}
+
+	Rtnval = aac_CloseCSMIBuffer(dev, arg, (PIOCTL_HEADER)pStatusBuffer);
+
+	fwprintf((dev,
+	  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+	  "aac_CSMIGetControllerStatus: Exit, ReturnValue=%d, ReturnCode=%x",
+	  Rtnval, pStatusBuffer->IoctlHeader.ReturnCode));
+
+	return Rtnval;
+
+}
+
+
+/*
+ * Routine Description:
+ *	This routine is called to request information for a specified RAID set
+ *	on a controller that supports RAID.
+ * Return Value:
+ *	Status value, to be returned by aac_HandleCSMI, and returned to the OS
+ *	--> Must set CSMI status value in pHeader->ReturnCode.
+ */
+int
+aac_CSMIGetRAIDConfig(
+	struct aac_dev * dev,
+	void __user * arg)
+{
+	int Rtnval;
+	PCSMI_SAS_RAID_CONFIG_BUFFER pRaidConfigBuffer;
+	typedef struct {
+		u32	command;
+		u32	type;
+		u32	cid;
+		u32	parm1;
+		u32	parm2;
+		u32	uid;
+		u32	offset;
+		u32	parm5;
+	} CONTAINER;
+	CONTAINER * ct;
+#	define CT_PACKET_SIZE (sizeof(((struct hw_fib *)NULL)->data)-(sizeof(u32)*12))
+#	define CT_CONTINUE_DATA		83
+#	define CT_STOP_DATA		84
+#	define CT_GET_RAID_CONFIG	215
+	typedef struct {
+		u32	response;
+		u32	type;
+		u32	status;
+		u32	count;
+		u32	parm2;
+		u32	uid;
+		u32	parm4;
+		u32	parm5;
+		u32	data[1];
+	} CONTAINERRESPONSE;
+	CONTAINERRESPONSE * ctr;
+#	define CT_CONTINUATION_ERROR 199
+	u16 bufferOffset = 0;
+	u16 LoopCount = 0;
+	unsigned long uniqueID = 0, sizeLeft = 0;
+	unsigned char *DestinationBuffer;
+	struct fib * fibptr;
+	int status;
+
+	fwprintf((dev,
+	  HBA_FLAGS_DBG_FUNCTION_ENTRY_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+	  "aac_CSMIGetRAIDConfig: Enter"));
+
+	/*
+	 * Verify buffer size. If buffer is too small, the error status will
+	 * be set for pHeader->ReturnCode in aac_VerifyCSMIBuffer.
+	 */
+	if ((Rtnval = aac_VerifyCSMIBuffer(&dev, arg,
+	  sizeof(CSMI_SAS_RAID_CONFIG_BUFFER),
+	  (PIOCTL_HEADER *)&pRaidConfigBuffer))) {
+		fwprintf((dev,
+		  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+		  "aac_CSMIGetRAIDConfig: Exit, ReturnValue = %d",
+		  Rtnval));
+		return Rtnval;
+	}
+
+	/*
+	 * Make sure the requested container number exists
+	 */
+	if ((pRaidConfigBuffer->Configuration.uRaidSetIndex == 0)
+	 || (pRaidConfigBuffer->Configuration.uRaidSetIndex
+	  > dev->maximum_num_containers)
+	 || (!dev->
+	  fsa_dev[pRaidConfigBuffer->Configuration.uRaidSetIndex-1].valid)) {
+		fwprintf((dev, HBA_FLAGS_DBG_ERROR_B,
+		  ((pRaidConfigBuffer->Configuration.uRaidSetIndex
+		    >= dev->maximum_num_containers)
+		      ? "aac_CSMIGetRAIDConfig: RaidIndex=%d > Maximum=%d"
+		      : "aac_CSMIGetRAIDConfig: RaidIndex=%d invalid"),
+		  pRaidConfigBuffer->Configuration.uRaidSetIndex,
+		  dev->maximum_num_containers));
+
+		/*
+		 * Indicate the RaidSetIndex is invalid
+		 */
+		pRaidConfigBuffer->IoctlHeader.ReturnCode
+		  = CSMI_SAS_RAID_SET_OUT_OF_RANGE;
+		Rtnval = aac_CloseCSMIBuffer(dev, arg,
+		  (PIOCTL_HEADER)pRaidConfigBuffer);
+
+		fwprintf((dev,
+		  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+		  "aac_CSMIGetRAIDConfig: Exit, ReturnValue=%d,"
+		  " ReturnCode=CSMI_SAS_RAID_SET_OUT_OF_RANGE",
+		  Rtnval));
+		return Rtnval;
+	}
+
+	fibptr = fib_alloc(dev);
+	if (fibptr == NULL) {
+		pRaidConfigBuffer->IoctlHeader.ReturnCode
+		  = CSMI_SAS_STATUS_FAILED;
+		Rtnval = aac_CloseCSMIBuffer(dev, arg,
+		  (PIOCTL_HEADER)pRaidConfigBuffer);
+		fwprintf((dev,
+		  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+		  "aac_CSMIGetRAIDConfig: Exit, ReturnValue=%d,"
+		  " ReturnCode=CSMI_SAS_STATUS_FAILED",
+		  Rtnval));
+		return Rtnval;
+	}
+	fib_init (fibptr);
+	fibptr->hw_fib->header.SenderSize = cpu_to_le16(sizeof(struct hw_fib));
+
+	/*
+	 * Setup and send CT_GET_RAID_CONFIG command to FW to
+	 * fill in IOCTL buffer
+	 */
+	ct = (CONTAINER *) fib_data(fibptr);
+	ct->command = cpu_to_le32(VM_ContainerConfig);
+	ct->type = cpu_to_le32(CT_GET_RAID_CONFIG);
+ 	/* Container number */
+	ct->cid = cpu_to_le32(pRaidConfigBuffer->Configuration.uRaidSetIndex-1);
+
+	status = fib_send(ContainerCommand, fibptr, sizeof(CONTAINER),
+	  FsaNormal, 1, 1, NULL, NULL);
+	fib_complete(fibptr);
+
+	if (status < 0) {
+		fib_free(fibptr);
+		pRaidConfigBuffer->IoctlHeader.ReturnCode
+		  = CSMI_SAS_STATUS_FAILED;
+		Rtnval = aac_CloseCSMIBuffer(dev, arg,
+		  (PIOCTL_HEADER)pRaidConfigBuffer);
+		fwprintf((dev,
+		  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+		  "aac_CSMIGetRAIDConfig: Exit, ReturnValue=%d,"
+		  " ReturnCode=CSMI_SAS_STATUS_FAILED",
+		  Rtnval));
+		return Rtnval;
+	}
+
+	ctr = (CONTAINERRESPONSE *) ct;
+	/*
+	 * Check for error conditions
+	 */
+	if (ctr->status == cpu_to_le32(CT_CONTINUATION_ERROR)) {
+		fib_free(fibptr);
+		/*
+		 * Indicate failure for this IOCTL
+		 */
+		pRaidConfigBuffer->IoctlHeader.ReturnCode
+		  = CSMI_SAS_STATUS_FAILED;
+		Rtnval = aac_CloseCSMIBuffer(dev, arg,
+		  (PIOCTL_HEADER)pRaidConfigBuffer);
+		fwprintf((dev,
+		  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+		  "aac_CSMIGetRAIDConfig: Exit, ReturnValue=%d,"
+		  " ReturnCode=CSMI_SAS_STATUS_FAILED",
+		  Rtnval));
+		return Rtnval;
+	}
+
+	/*
+	 * Grab the total size of data to be returned so we can loop through
+	 * and get it all
+	 */
+	sizeLeft = le32_to_cpu(ctr->count);
+
+	/*
+	 * Get Unique ID for this continuation session
+	 */
+	uniqueID = ctr->uid;
+
+	/*
+	 * If there is more data, continue looping until we're done
+	 */
+	DestinationBuffer = (unsigned char *)(&pRaidConfigBuffer->Configuration);
+
+	while (sizeLeft) {
+		fib_init (fibptr);
+		fibptr->hw_fib->header.SenderSize
+		  = cpu_to_le16(sizeof(struct hw_fib));
+
+		ct->command = cpu_to_le32(VM_ContainerConfig);
+		ct->type = cpu_to_le32(CT_CONTINUE_DATA);
+		ct->uid = uniqueID;
+		ct->offset = cpu_to_le32(LoopCount);
+
+		status = fib_send(ContainerCommand, fibptr, sizeof(CONTAINER),
+		  FsaNormal, 1, 1, NULL, NULL);
+		fib_complete(fibptr);
+
+		if (status < 0) {
+			/*
+			 * Indicate failure for this IOCTL
+			 */
+			pRaidConfigBuffer->IoctlHeader.ReturnCode
+			  = CSMI_SAS_STATUS_FAILED;
+			break;
+		}
+
+		/*
+		 * Check for error conditions
+		 */
+		if (ctr->status == cpu_to_le32(CT_CONTINUATION_ERROR)) {
+			/*
+			 * Indicate failure for this IOCTL
+			 */
+			pRaidConfigBuffer->IoctlHeader.ReturnCode
+			  = CSMI_SAS_STATUS_FAILED;
+			break;
+		}
+
+		/*
+		 * No error so copy the remaining data
+		 */
+		/*
+		 * Move the full packet size and update for the next loop
+		 */
+		if (sizeLeft >= CT_PACKET_SIZE) {
+			memcpy(DestinationBuffer, ctr->data, CT_PACKET_SIZE);
+
+			/*
+			 * Set current offset in buffer, so we can continue
+			 * copying data.
+			 */
+			bufferOffset += CT_PACKET_SIZE;
+			DestinationBuffer += CT_PACKET_SIZE;
+			sizeLeft -= CT_PACKET_SIZE;
+			++LoopCount;
+		}
+
+		/*
+		 * last transfer; is less than CT_PACKET_SIZE, so just use
+		 * sizeLeft
+		 */
+		else {
+			memcpy(DestinationBuffer, ctr->data, sizeLeft);
+			sizeLeft = 0;
+		}
+	}
+
+	/*
+	 * At this point, we have copied back
+	 * all of the data. Send a STOP command
+	 * to finish things off.
+	 */
+	fib_init (fibptr);
+
+	ct->command = cpu_to_le32(VM_ContainerConfig);
+	ct->type = cpu_to_le32(CT_STOP_DATA);
+	ct->uid = uniqueID;
+
+	fib_send(ContainerCommand, fibptr, sizeof(CONTAINER),
+	  FsaNormal, 1, 1, NULL, NULL);
+	fib_complete(fibptr);
+	fib_free(fibptr);
+
+	Rtnval = aac_CloseCSMIBuffer(dev, arg, (PIOCTL_HEADER)pRaidConfigBuffer);
+	fwprintf((dev,
+	  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+	  "aac_CSMIGetRAIDConfig: Exit, ReturnValue=%d, ReturnCode=%x",
+	  Rtnval, pRaidConfigBuffer->IoctlHeader.ReturnCode));
+
+	return Rtnval;
+
+}
+
+
+/*
+ * Routine Description:
+ *	This routine is called to request information on the number of RAID
+ *	volumes and number of physical drives on a controller.
+ * Return Value:
+ *	Status value, to be returned by aac_HandleCSMI, and returned to the OS.
+ *	--> Must set CSMI status value in pHeader->ReturnCode.
+ */
+int
+aac_CSMIGetRAIDInfo(
+	struct aac_dev * dev,
+	void __user * arg)
+{
+	int Rtnval;
+	PCSMI_SAS_RAID_INFO_BUFFER pRaidInfoBuffer;
+	u16 NumRaidSets = 0;
+	int lcv;
+	PDIOCTL pIoctlInfo;
+	ENHANCED_GBI_CSS * EnhancedBusInfo;
+	struct fib * fibptr;
+	int status;
+
+	fwprintf((dev,
+	  HBA_FLAGS_DBG_FUNCTION_ENTRY_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+	  "aac_CSMIGetRAIDInfo: Enter"));
+
+	/*
+	 * Verify buffer size. If buffer is too small, the error status will
+	 * be set for pHeader->ReturnCode in aac_VerifyCSMIBuffer.
+	 */
+	if ((Rtnval = aac_VerifyCSMIBuffer(&dev, arg,
+	  sizeof(CSMI_SAS_RAID_INFO_BUFFER),
+	  (PIOCTL_HEADER *)&pRaidInfoBuffer))) {
+		fwprintf((dev,
+		  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+		  "aac_CSMIGetRAIDInfo: Exit, ReturnValue=%d",
+		  Rtnval));
+		return Rtnval;
+	}
+
+	/*
+	 * Traverse the container list and count all containers
+	 */
+	for (lcv = 0; lcv < dev->maximum_num_containers; lcv++)
+		if (dev->fsa_dev[lcv].valid)
+			NumRaidSets++;
+	pRaidInfoBuffer->Information.uNumRaidSets = NumRaidSets;
+
+	/*
+	 * Find the absolute maximum number of physical drives that can make
+	 * up a container. It's pretty ambiquous so we'll default it to the
+	 * Falcon maximum number of drives supported and then try to figure
+	 * out from firmware the max number of drives we can attach to this
+	 * controller.
+	 */
+	pRaidInfoBuffer->Information.uMaxDrivesPerSet = 128;
+	fibptr = fib_alloc(dev);
+	if (fibptr) {
+		fib_init(fibptr);
+
+		pIoctlInfo = (PDIOCTL) fib_data(fibptr);
+		pIoctlInfo->Command = cpu_to_le32(VM_Ioctl);
+		pIoctlInfo->ObjType = cpu_to_le32(FT_DRIVE);
+		pIoctlInfo->MethodId = cpu_to_le32(1);
+		pIoctlInfo->ObjectId = 0;
+		pIoctlInfo->CtlCmd = cpu_to_le32(EnhancedGetBusInfo);
+
+		status = fib_send(ContainerCommand, fibptr,
+		  sizeof(*EnhancedBusInfo),
+		  FsaNormal, 1, 1, NULL, NULL);
+	
+		fib_complete(fibptr);
+	
+		EnhancedBusInfo = (struct aac_enhanced_bus_info_response *) pIoctlInfo;
+	
+		if (status >= 0) switch (EnhancedBusInfo->BusType[0]) {
+		case CSS_BUS_TYPE_SATA:
+			pRaidInfoBuffer->Information.uMaxDrivesPerSet
+			  = dev->supplement_adapter_info.MaxNumberPorts;
+			break;
+		case CSS_BUS_TYPE_SAS:
+			pRaidInfoBuffer->Information.uMaxDrivesPerSet = 128;
+			break;
+		default:
+			pRaidInfoBuffer->Information.uMaxDrivesPerSet
+			  = dev->maximum_num_physicals
+			  * dev->maximum_num_channels;
+			break;
+		}
+		fib_free(fibptr);
+	}
+
+	Rtnval = aac_CloseCSMIBuffer(dev, arg, (PIOCTL_HEADER)pRaidInfoBuffer);
+
+	fwprintf((dev,
+	  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+	  "aac_CSMIGetRAIDInfo: Exit, ReturnValue=%d, ReturnCode=%x",
+	  Rtnval, pRaidInfoBuffer->IoctlHeader.ReturnCode));
+
+	return Rtnval;
+}
+
+
+/*
+ * Routine Description:
+ *	This routine is called to request information about physical
+ *	characteristics and interconnect to the SATA or SAS domain.
+ * Return Value:
+ *	Status value, to be returned by aac_HandleCSMI, and returned to the OS.
+ *	--> Must set CSMI status value in pHeader->ReturnCode.
+ */
+int
+aac_CSMIGetPhyInfo(
+	struct aac_dev * dev,
+	void __user * arg)
+{
+	int Rtnval;
+	PCSMI_SAS_PHY_INFO_BUFFER pPhyInfoBuffer;
+	PDIOCTL pIoctlInfo;
+	PDIOCTLRESPONSE pIoctlResp;
+	struct fib * fibptr;
+	int status;
+	u32 Length;
+
+	fwprintf((dev,
+	  HBA_FLAGS_DBG_FUNCTION_ENTRY_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+	  "aac_CSMIGetPhyInfo: Enter scsi%d",
+	  dev->scsi_host_ptr->host_no));
+
+#if 0
+	/* Command can not be issued to the adapter */
+	if (!(dev->supplement_adapter_info.FeatureBits
+	 & le32_to_cpu(AAC_FEATURE_FALCON))) {
+		Rtnval = -ENOENT;
+		fwprintf((dev,
+		  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+		  "aac_CSMIGetPhyInfo: Exit, ReturnValue=-ENOENT",
+		  Rtnval));
+		return Rtnval;
+	}
+#endif
+	/*
+	 * Verify buffer size. If buffer is too small, the error status will
+	 * be set for pHeader->ReturnCode in aac_VerifyCSMIBuffer.
+	 */
+	if ((Rtnval = aac_VerifyCSMIBuffer(&dev, arg,
+	  sizeof(CSMI_SAS_PHY_INFO_BUFFER),
+	  (PIOCTL_HEADER *)&pPhyInfoBuffer))) {
+		fwprintf((dev,
+		  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+		  "aac_CSMIGetPhyInfo: Exit, ReturnValue=%d",
+		  Rtnval));
+		return Rtnval;
+	}
+
+	/* TODO : Figure out the correct size to send or do a continue fib */
+
+	fibptr = fib_alloc(dev);
+	if (fibptr == NULL) {
+		pPhyInfoBuffer->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+		Rtnval = aac_CloseCSMIBuffer(dev, arg,
+		  (PIOCTL_HEADER)pPhyInfoBuffer);
+		fwprintf((dev,
+		  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+		  "aac_CSMIGetPhyInfo: Exit, ReturnValue=%d,"
+		  " ReturnCode=CSMI_SAS_STATUS_FAILED",
+		  Rtnval));
+		return Rtnval;
+	}
+	fib_init(fibptr);
+	fibptr->hw_fib->header.SenderSize = cpu_to_le16(sizeof(struct hw_fib));
+
+	pIoctlInfo = (PDIOCTL) fib_data(fibptr);
+	pIoctlInfo->Command = cpu_to_le32(VM_Ioctl);
+	pIoctlInfo->ObjType = cpu_to_le32(FT_DRIVE);
+	pIoctlInfo->MethodId = cpu_to_le32(1);
+	pIoctlInfo->ObjectId = 0;
+	pIoctlInfo->CtlCmd = cpu_to_le32(CsmiGetPhyInfo);
+	Length = pPhyInfoBuffer->IoctlHeader.Length;
+	/* Issue a Larger FIB? */
+	if (Length > (sizeof(struct hw_fib) - sizeof(struct aac_fibhdr)
+					- sizeof(*pIoctlInfo))) {
+		Length = sizeof(struct hw_fib) - sizeof(struct aac_fibhdr)
+		       - sizeof(*pIoctlInfo);
+		pPhyInfoBuffer->IoctlHeader.Length = Length;
+	}
+	memcpy(((char *)pIoctlInfo) + sizeof(*pIoctlInfo),
+	  pPhyInfoBuffer, Length);
+
+	status = fib_send(ContainerCommand, fibptr,
+	  Length + sizeof(*pIoctlInfo),
+	  FsaNormal, 1, 1, NULL, NULL);
+
+	fib_complete(fibptr);
+
+	if (status < 0) {
+		fib_free(fibptr);
+		pPhyInfoBuffer->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_FAILED;
+		Rtnval = aac_CloseCSMIBuffer(dev, arg,
+		  (PIOCTL_HEADER)pPhyInfoBuffer);
+		fwprintf((dev,
+		  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+		  "aac_CSMIGetPhyInfo: Exit, ReturnValue=%d,"
+		  " ReturnCode=CSMI_SAS_STATUS_FAILED",
+		  Rtnval));
+		return Rtnval;
+	}
+
+	pIoctlResp = (PDIOCTLRESPONSE) pIoctlInfo;
+
+	/*
+	 * Copy back the filled out buffer to complete the
+	 * request
+	 */
+	memcpy(pPhyInfoBuffer, ((char *)pIoctlResp) + sizeof(*pIoctlResp),
+	  Length);
+
+	fib_free(fibptr);
+
+	Rtnval = aac_CloseCSMIBuffer(dev, arg, (PIOCTL_HEADER)pPhyInfoBuffer);
+
+	fwprintf((dev,
+	  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+	  "aac_CSMIGetPhyInfo: Exit, Rtnval, ReturnCode=%x",
+	  Rtnval, pPhyInfoBuffer->IoctlHeader.ReturnCode));
+
+	return Rtnval;
+
+}
+
+
+/*
+ * Routine Description:
+ *	This routine is called to obtain the initial SATA signature (the
+ *	initial Register Device to the Host FIS) from a directly attached SATA
+ *	device.
+ * Return Value:
+ *	Status value, to be returned by aac_HandleCSMI, and returned to the OS.
+ *	--> Must set CSMI status value in pHeader->ReturnCode.
+ */
+int
+aac_CSMIGetSATASignature(
+	struct aac_dev * dev,
+	void __user * arg)
+{
+	int Rtnval;
+	PCSMI_SAS_SATA_SIGNATURE_BUFFER pSataSignatureBuffer;
+	PDIOCTL pIoctlInfo;
+	PDIOCTLRESPONSE pIoctlResp;
+	struct fib * fibptr;
+	int status;
+
+	fwprintf((dev,
+	  HBA_FLAGS_DBG_FUNCTION_ENTRY_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+	  "aac_CSMIGetSATASignature: Enter scsi%d",
+	  dev->scsi_host_ptr->host_no));
+
+	/*
+	 * Verify buffer size. If buffer is too small, the error status will
+	 * be set for pHeader->ReturnCode in aac_VerifyCSMIBuffer.
+	 */
+	if ((Rtnval = aac_VerifyCSMIBuffer(&dev, arg,
+	  sizeof(CSMI_SAS_SATA_SIGNATURE_BUFFER),
+	  (PIOCTL_HEADER *)&pSataSignatureBuffer))) {
+		fwprintf((dev,
+		  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+		  "aac_CSMIGetSATASignature: Exit, ReturnValue=%d",
+		  Rtnval));
+		return Rtnval;
+	}
+
+	pSataSignatureBuffer->IoctlHeader.ReturnCode = CSMI_SAS_NO_SATA_DEVICE;
+
+	fibptr = fib_alloc(dev);
+	if (fibptr == NULL) {
+		pSataSignatureBuffer->IoctlHeader.ReturnCode
+		  = CSMI_SAS_STATUS_FAILED;
+		Rtnval = aac_CloseCSMIBuffer(dev, arg,
+		  (PIOCTL_HEADER)pSataSignatureBuffer);
+		fwprintf((dev,
+		  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+		  "aac_CSMIGetSATASignature: Exit, ReturnValue=%d,"
+		  " ReturnCode=CSMI_SAS_STATUS_FAILED",
+		  Rtnval));
+		return Rtnval;
+	}
+	fib_init(fibptr);
+
+	pIoctlInfo = (PDIOCTL) fib_data(fibptr);
+	pIoctlInfo->Command = cpu_to_le32(VM_Ioctl);
+	pIoctlInfo->ObjType = cpu_to_le32(FT_DRIVE);
+	pIoctlInfo->MethodId = cpu_to_le32(1);
+	pIoctlInfo->ObjectId = 0;
+	pIoctlInfo->CtlCmd = cpu_to_le32(CsmiSataSignature);
+	memcpy(((char *)pIoctlInfo) + sizeof(*pIoctlInfo),
+	  pSataSignatureBuffer,sizeof(CSMI_SAS_SATA_SIGNATURE_BUFFER));
+
+	status = fib_send(ContainerCommand, fibptr, sizeof(*pIoctlInfo)
+	  - sizeof(u32) + sizeof(CSMI_SAS_SATA_SIGNATURE_BUFFER), FsaNormal,
+	  1, 1, NULL, NULL);
+
+	fib_complete(fibptr);
+
+	if (status < 0) {
+		fib_free(fibptr);
+		pSataSignatureBuffer->IoctlHeader.ReturnCode
+		  = CSMI_SAS_STATUS_FAILED;
+		Rtnval = aac_CloseCSMIBuffer(dev, arg,
+		  (PIOCTL_HEADER)pSataSignatureBuffer);
+		fwprintf((dev,
+		  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+		  "aac_CSMIGetSATASignature: Exit, ReturnValue=%d,"
+		  " ReturnCode=CSMI_SAS_STATUS_FAILED",
+		  Rtnval));
+		return Rtnval;
+	}
+
+	pIoctlResp = (PDIOCTLRESPONSE) pIoctlInfo;
+
+	/*
+	 * Copy back the filled out buffer to complete the
+	 * request
+	 */
+	memcpy(pSataSignatureBuffer,
+	  ((char *)pIoctlResp) + sizeof(*pIoctlResp),
+	  sizeof(CSMI_SAS_SATA_SIGNATURE_BUFFER));
+
+	fib_free(fibptr);
+
+	/*
+	 * Indicate success for this IOCTL
+	 *	pSataSignatureBuffer->IoctlHeader.ReturnCode
+	 *		= CSMI_SAS_STATUS_SUCCESS;
+	 * is set by the Firmware Response.
+	 */
+	Rtnval = aac_CloseCSMIBuffer(dev, arg,
+	  (PIOCTL_HEADER)pSataSignatureBuffer);
+
+	fwprintf((dev,
+	  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+	  "aac_CSMIGetSATASignature: Exit, ReturnValue=%d,"
+	  " ReturnCode=CSMI_SAS_STATUS_SUCCESS",
+	  Rtnval));
+
+	return Rtnval;
+
+}
+
+
+/*
+ * Routine Description:
+ *	This routine is called to return the driver information.
+ * Return Value:
+ *	Status value, to be returned by aac_HandleCSMI, and returned to the OS.
+ *	--> Must set CSMI status value in pHeader->ReturnCode.
+ */
+int
+aac_CSMIGetDriverInfo(
+	struct aac_dev * dev,
+	void __user * arg)
+{
+	int Rtnval;
+	PCSMI_SAS_DRIVER_INFO_BUFFER pDriverInfoBuffer;
+	extern char aac_driver_version[];
+	char * driver_version = aac_driver_version;
+
+	fwprintf((dev,
+	  HBA_FLAGS_DBG_FUNCTION_ENTRY_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+	  "aac_CSMIGetDriverInfo: Enter"));
+
+	/*
+	 * Verify buffer size. If buffer is too small, the error status will
+	 * be set for pHeader->ReturnCode in aac_VerifyCSMIBuffer.
+	 */
+	if ((Rtnval = aac_VerifyCSMIBuffer(&dev, arg,
+	  sizeof(CSMI_SAS_DRIVER_INFO_BUFFER),
+	  (PIOCTL_HEADER *)&pDriverInfoBuffer))) {
+		fwprintf((dev,
+		  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+		  "aac_CSMIGetDriverInfo: Exit, ReturnValue=%d",
+		  Rtnval));
+		return Rtnval;
+	}
+
+	/*
+	 * Fill in the information member of the pDriverInfoBuffer
+	 * structure.
+	 */
+
+	/*
+	 * Driver name
+	 */
+	strncpy(pDriverInfoBuffer->Information.szName,
+	  (dev->scsi_host_ptr->hostt->info
+	    ? dev->scsi_host_ptr->hostt->info(dev->scsi_host_ptr)
+	    : dev->scsi_host_ptr->hostt->name),
+	  sizeof(pDriverInfoBuffer->Information.szName));
+
+	/*
+	 * Driver Description
+	 */
+	sprintf(pDriverInfoBuffer->Information.szDescription,
+	  "Adaptec %s driver",
+	  dev->scsi_host_ptr->hostt->name);
+
+	/*
+	 * Set version number information
+	 */
+	pDriverInfoBuffer->Information.usMajorRevision
+	  = cpu_to_le16(aac_atoi(&driver_version));
+	pDriverInfoBuffer->Information.usMinorRevision
+	  = cpu_to_le16(aac_atoi(&driver_version));
+#if (defined(AAC_DRIVER_BUILD))
+	pDriverInfoBuffer->Information.usBuildRevision = cpu_to_le16(AAC_DRIVER_BUILD);
+#else
+	pDriverInfoBuffer->Information.usBuildRevision = cpu_to_le16(9999);
+#endif
+	pDriverInfoBuffer->Information.usReleaseRevision
+	  = cpu_to_le16(aac_atoi(&driver_version));
+	pDriverInfoBuffer->Information.usCSMIMajorRevision
+	  = cpu_to_le16(CSMI_MAJOR_REVISION);
+	pDriverInfoBuffer->Information.usCSMIMinorRevision
+	  = cpu_to_le16(CSMI_MINOR_REVISION);
+
+	Rtnval = aac_CloseCSMIBuffer(dev, arg, (PIOCTL_HEADER)pDriverInfoBuffer);
+	fwprintf((dev,
+	  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+	  "aac_CSMIGetDriverInfo: Exit, ReturnValue=%d, ReturnCode=%x",
+	  Rtnval, pDriverInfoBuffer->IoctlHeader.ReturnCode));
+
+	return Rtnval;
+
+}
+
+
+
+/*
+ * Routine Description:
+ *	This routine is called to change the physical characteristics of a phy.
+ *	We currently do not support this functionality, and are not required to
+ *	in order to support CSMI.
+ * Return Value:
+ *	Status value, to be returned by aac_HandleCSMI, and returned to the OS.
+ *	--> Must set CSMI status value in pHeader->ReturnCode.
+ */
+int
+aac_CSMISetPhyInfo(
+	struct aac_dev * dev,
+	void __user * arg)
+{
+	int Rtnval;
+	u32 ReturnCode;
+
+	fwprintf((dev,
+	  HBA_FLAGS_DBG_FUNCTION_ENTRY_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+	  "aac_CSMISetPhyInfo: Enter scsi%d",
+	  dev->scsi_host_ptr->host_no));
+
+	ReturnCode = CSMI_SAS_PHY_INFO_NOT_CHANGEABLE;
+	Rtnval = 0;
+	if (copy_to_user((void __user *)&((PIOCTL_HEADER)arg)->ReturnCode,
+	  (void *)&ReturnCode, sizeof(u32)))
+		Rtnval = -EFAULT;
+
+	fwprintf((dev,
+	  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+	  "aac_CSMISetPhyInfo: Exit, ReturnValue=%d,"
+	  " ReturnCode=CSMI_SAS_PHY_INFO_NOT_CHANGEABLE",
+	  Rtnval));
+
+	return Rtnval;
+
+}
+
+
+/*
+ * Routine Description:
+ *	This routine is called to send generic STP or SATA commands to a
+ *	specific SAS address.
+ * Return Value:
+ *	Status value, to be returned by aac_HandleCSMI, and returned to the OS.
+ *	--> Must set CSMI status value in pHeader->ReturnCode.
+ */
+int
+aac_CSMISTPPassThru(
+	struct aac_dev * dev,
+	void __user * arg)
+{
+	int Rtnval;
+	PCSMI_SAS_STP_PASSTHRU_BUFFER pPassThruBuffer;
+	unsigned bytesLeft = 0;
+	u8 * pDataPointer = NULL;
+	/* function */
+#	define SATAPASSTHROUGH_REGISTER		0x00000000
+#	define SATAPASSTHROUGH_SOFTRESET	0x00000001
+	typedef struct {
+		u32	function;
+		u32	bus;
+		u32	targetId;
+		u32	lun;
+		u32	timeOutValue;
+		u32	srbFlags;
+#			define	HOSTSRB_FLAGS_NO_DATA_TRANSFER	0x00000000
+#			define	HOSTSRB_FLAGS_DATA_IN		0x00000040
+#			define	HOSTSRB_FLAGS_DATA_OUT		0x00000080
+		u32	dataTransferLength;
+		u32	retryLimit;
+		u32	cdbLength;
+		u8	command;
+		u8	features;
+		u8	sectorNumber;
+		u8	cylinderLow;
+		u8	cylinderHigh;
+		u8	deviceHead;
+		u8	sectorNumber_Exp;
+		u8	cylinderLow_Exp;
+		u8	cylinderHigh_Exp;
+		u8	features_Exp;
+		u8	sectorCount;
+		u8	sectorCount_Exp;
+		u8	reserved;
+		u8	control;
+		u8	reserved1[2];
+		u32	reserved2[4];
+		struct sgmap64	sgMap;
+	} HOST_SATA_REQUEST_BLOCK;
+	typedef HOST_SATA_REQUEST_BLOCK * PHOST_SATA_REQUEST_BLOCK;
+	PHOST_SATA_REQUEST_BLOCK pSataRequest;
+	typedef struct {
+		u32	status;
+		u32	srbStatus;
+		u32	scsiStatus;
+		u32	dataTransferLength;
+		u32	senseInfoBufferLength;
+		u8	statusReg;
+		u8	error;
+		u8	sectorNumber;
+		u8	cylinderLow;
+		u8	cylinderHigh;
+		u8	deviceHead;
+		u8	sectorNumber_Exp;
+		u8	cylinderLow_Exp;
+		u8	cylinderHigh_Exp;
+		u8	deviceRegister_Exp;
+		u8	features;
+		u8	featuers_Exp;
+		u8	reserved1[4];
+	} HOST_SATA_REQUEST_BLOCK_RESULT;
+	typedef HOST_SATA_REQUEST_BLOCK_RESULT * PHOST_SATA_REQUEST_BLOCK_RESULT;
+	PHOST_SATA_REQUEST_BLOCK_RESULT pSataResponse;
+	struct sgmap64 * pSgMap;
+	struct fib * fibptr;
+	int status;
+	dma_addr_t addr;
+	void * p = NULL;
+#	define SataPortCommandU64	602
+
+	fwprintf((dev,
+	  HBA_FLAGS_DBG_FUNCTION_ENTRY_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+	  "aac_CSMISTPPassThru: Enter scsi%d",
+	  dev->scsi_host_ptr->host_no));
+
+	/*
+	 * Verify buffer size. If buffer is too small, the error status will
+	 * be set for pHeader->ReturnCode in aac_VerifyCSMIBuffer.
+	 */
+	if ((Rtnval = aac_VerifyCSMIBuffer(&dev, arg,
+	  sizeof(CSMI_SAS_STP_PASSTHRU_BUFFER),
+	  (PIOCTL_HEADER *)&pPassThruBuffer))) {
+		fwprintf((dev,
+		  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+		  "aac_CSMISTPPassThru: Exit, ReturnValue=%d",
+		  Rtnval));
+		return Rtnval;
+	}
+	/*
+	 * Weed out the flags we don't support
+	 */
+	if ((pPassThruBuffer->Parameters.uFlags & CSMI_SAS_STP_DMA)
+	 || (pPassThruBuffer->Parameters.uFlags & CSMI_SAS_STP_DMA_QUEUED)) {
+		/*
+		 * Indicate failure for this IOCTL
+		 */
+		pPassThruBuffer->IoctlHeader.ReturnCode
+		  = CSMI_SAS_STATUS_FAILED;
+		Rtnval = aac_CloseCSMIBuffer(dev, arg,
+		  (PIOCTL_HEADER)pPassThruBuffer);
+		fwprintf((dev,
+		  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+		  "aac_CSMISTPPassThru: Exit, ReturnValue=%d,"
+		  " ReturnCode=CSMI_SAS_STATUS_FAILED",
+		  Rtnval));
+		return Rtnval;
+	}
+
+	fibptr = fib_alloc(dev);
+	if (fibptr == NULL) {
+		pPassThruBuffer->IoctlHeader.ReturnCode
+		  = CSMI_SAS_STATUS_FAILED;
+		Rtnval = aac_CloseCSMIBuffer(dev, arg,
+		  (PIOCTL_HEADER)pPassThruBuffer);
+		fwprintf((dev,
+		  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+		  "aac_CSMISTPPassThru: Exit, ReturnValue=%d,"
+		  " ReturnCode=CSMI_SAS_STATUS_FAILED",
+		  Rtnval));
+		return Rtnval;
+	}
+	fib_init(fibptr);
+
+	pSataRequest = (PHOST_SATA_REQUEST_BLOCK) fib_data(fibptr);
+	pSgMap = &pSataRequest->sgMap;
+	pSataResponse = (PHOST_SATA_REQUEST_BLOCK_RESULT) pSataRequest;
+
+	/*
+	 * Setup HOST_SATA_REQUEST_BLOCK structure
+	 */
+	memset(pSataRequest,0,sizeof(*pSataRequest));
+	memset(pSataResponse,0,sizeof(HOST_SATA_REQUEST_BLOCK_RESULT));
+	if (pPassThruBuffer->Parameters.uFlags & CSMI_SAS_STP_RESET_DEVICE)
+		pSataRequest->function = SATAPASSTHROUGH_SOFTRESET;
+	else
+		pSataRequest->function = SATAPASSTHROUGH_REGISTER;
+
+	/*
+	 * Pull relevant data from header.
+	 */
+	if (pPassThruBuffer->Parameters.uFlags & CSMI_SAS_STP_READ)
+		pSataRequest->srbFlags = HOSTSRB_FLAGS_DATA_IN;
+	else
+		pSataRequest->srbFlags = HOSTSRB_FLAGS_DATA_OUT;
+	pSataRequest->timeOutValue = pPassThruBuffer->IoctlHeader.Timeout;
+
+	/*
+	 * Obsolete parameter - adapter firmware ignores this
+	 */
+	pSataRequest->retryLimit = 0;
+	pSataRequest->cdbLength = 14;
+
+	/*
+	 * Fill in remaining data from IOCTL Parameters
+	 */
+	/* Someday will be: SAS_ADDR_TO_BUS((*((u64*)pPassThruBuffer->Parameters.bDestinationSASAddress))); */
+	pSataRequest->bus = 0;
+	/* Someday will be: SAS_ADDR_TO_TARGET((*((u64*)pPassThruBuffer->Parameters.bDestinationSASAddress))); */
+	pSataRequest->targetId = pPassThruBuffer->Parameters.bPhyIdentifier;
+	/* Someday will be: SAS_ADDR_TO_LUN((*((u64*)pPassThruBuffer->Parameters.bDestinationSASAddress))); */
+	pSataRequest->lun = 0;
+	pSataRequest->dataTransferLength
+	  = pPassThruBuffer->Parameters.uDataLength;
+
+	/*
+	 * SATA Task Set Register Listing
+	 */
+	pSataRequest->command = pPassThruBuffer->Parameters.bCommandFIS[2];
+	pSataRequest->features = pPassThruBuffer->Parameters.bCommandFIS[3];
+	pSataRequest->sectorNumber = pPassThruBuffer->Parameters.bCommandFIS[4];
+	pSataRequest->cylinderLow = pPassThruBuffer->Parameters.bCommandFIS[5];
+	pSataRequest->cylinderHigh = pPassThruBuffer->Parameters.bCommandFIS[6];
+	pSataRequest->deviceHead = pPassThruBuffer->Parameters.bCommandFIS[7];
+	pSataRequest->sectorNumber_Exp
+	  = pPassThruBuffer->Parameters.bCommandFIS[8];
+	pSataRequest->cylinderLow_Exp
+	  = pPassThruBuffer->Parameters.bCommandFIS[9];
+	pSataRequest->cylinderHigh_Exp
+	  = pPassThruBuffer->Parameters.bCommandFIS[10];
+	pSataRequest->features_Exp
+	  = pPassThruBuffer->Parameters.bCommandFIS[11];
+	pSataRequest->sectorCount
+	  = pPassThruBuffer->Parameters.bCommandFIS[12];
+	pSataRequest->sectorCount_Exp
+	  = pPassThruBuffer->Parameters.bCommandFIS[13];
+	pSataRequest->control = pPassThruBuffer->Parameters.bCommandFIS[15];
+
+	/*
+	 * Build SGMAP
+	 */
+	if (pPassThruBuffer->Parameters.uDataLength) {
+
+		pDataPointer = &pPassThruBuffer->bDataBuffer[0];
+		bytesLeft = pPassThruBuffer->Parameters.uDataLength;
+
+		/*
+		 * Get physical address and length of
+		 * contiguous physical buffer
+		 */
+		p = pci_alloc_consistent(dev->pdev, bytesLeft, &addr);
+		if(p == 0) {
+			fib_free(fibptr);
+			pPassThruBuffer->IoctlHeader.ReturnCode
+			  = CSMI_SAS_STATUS_FAILED;
+			Rtnval = aac_CloseCSMIBuffer(dev, arg,
+			  (PIOCTL_HEADER)pPassThruBuffer);
+			fwprintf((dev, HBA_FLAGS_DBG_FUNCTION_EXIT_B
+			   | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+			  "aac_CSMISTPPassThru: Exit, ReturnValue=%d,"
+			  " ReturnCode=CSMI_SAS_STATUS_FAILED",
+			  Rtnval));
+			return Rtnval;
+		}
+		memcpy(p, pDataPointer, bytesLeft);
+
+		pSgMap->sg[0].addr[1] = cpu_to_le32((u32)((u64)addr>>32));
+		pSgMap->sg[0].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
+
+		/*
+		 * Store the length for this entry
+		 */
+		pSgMap->sg[0].count = bytesLeft;
+
+		/*
+		 * Store final count of entries
+		 */
+		pSgMap->count = 1;
+
+	} else
+		pSataRequest->srbFlags = HOSTSRB_FLAGS_NO_DATA_TRANSFER;
+
+	/*
+	 * Send FIB
+	 */
+	status = fib_send(SataPortCommandU64, fibptr, sizeof(*pSataRequest),
+	  FsaNormal, 1, 1, NULL, NULL);
+
+	fib_complete(fibptr);
+
+	if (status < 0) {
+		if (pPassThruBuffer->Parameters.uDataLength)
+			pci_free_consistent(dev->pdev, bytesLeft,p, addr);
+		fib_free(fibptr);
+		pPassThruBuffer->IoctlHeader.ReturnCode
+		  = CSMI_SAS_STATUS_FAILED;
+		Rtnval = aac_CloseCSMIBuffer(dev, arg,
+		  (PIOCTL_HEADER)pPassThruBuffer);
+		fwprintf((dev,
+		  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+		  "aac_CSMIGetSATASignature: Exit, ReturnValue=%d,"
+		  " ReturnCode=CSMI_SAS_STATUS_FAILED",
+		  Rtnval));
+		return Rtnval;
+	}
+
+	if (pPassThruBuffer->Parameters.uDataLength) {
+		memcpy(pDataPointer, p, bytesLeft);
+		pci_free_consistent(dev->pdev, bytesLeft,p, addr);
+	}
+
+	/*
+	 * pull response data and respond to IOCTL
+	 */
+
+	/*
+	 * Return relevant data
+	 */
+	pPassThruBuffer->Status.bConnectionStatus = CSMI_SAS_OPEN_ACCEPT;
+	pPassThruBuffer->Status.bStatusFIS[2] = pSataResponse->statusReg;
+
+	/*
+	 * pPassThruBuffer->Status.uSCR = ??;
+	 */
+	pPassThruBuffer->Status.uDataBytes = pSataResponse->dataTransferLength;
+
+	fib_free(fibptr);
+
+	/*
+	 * Indicate success for this IOCTL
+	 */
+	pPassThruBuffer->IoctlHeader.ReturnCode = CSMI_SAS_STATUS_SUCCESS;
+	Rtnval = aac_CloseCSMIBuffer(dev, arg, (PIOCTL_HEADER)pPassThruBuffer);
+
+	fwprintf((dev,
+	  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+	  "aac_CSMISTPPassThru: Exit, ReturnValue=%d,"
+	  " ReturnCode=CSMI_SAS_STATUS_SUCCESS",
+	  Rtnval));
+
+	return Rtnval;
+
+}
+
+
+/*
+ *
+ * Routine Description:
+ *
+ *   This routine is the main entry point for all CSMI function calls.
+ *
+ */
+int aac_csmi_ioctl(
+	struct aac_dev * dev,
+	int cmd,
+	void __user * arg)
+{
+	int returnStatus = -ENOTTY;
+
+	fwprintf((dev,
+	  HBA_FLAGS_DBG_FUNCTION_ENTRY_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+	  "aac_HandleCSMI: Enter, (scsi%d) ControlCode = %x",
+	  dev->scsi_host_ptr->host_no, cmd));
+
+	/*
+	 * Handle the supported CSMI commands
+	 */
+	switch (cmd) {
+	case CC_CSMI_SAS_GET_DRIVER_INFO:
+		returnStatus = aac_CSMIGetDriverInfo(dev, arg);
+		break;
+
+	case CC_CSMI_SAS_GET_CNTLR_CONFIG:
+		returnStatus = aac_CSMIGetControllerConfig(dev, arg);
+		break;
+
+	case CC_CSMI_SAS_GET_CNTLR_STATUS:
+		returnStatus = aac_CSMIGetControllerStatus(dev, arg);
+		break;
+
+	case CC_CSMI_SAS_GET_RAID_INFO:
+		returnStatus = aac_CSMIGetRAIDInfo(dev, arg);
+		break;
+
+	case CC_CSMI_SAS_GET_PHY_INFO:
+		returnStatus = aac_CSMIGetPhyInfo(dev, arg);
+		break;
+
+	case CC_CSMI_SAS_SET_PHY_INFO:
+		returnStatus = aac_CSMISetPhyInfo(dev, arg);
+		break;
+
+	case CC_CSMI_SAS_GET_SATA_SIGNATURE:
+		returnStatus = aac_CSMIGetSATASignature(dev, arg);
+		break;
+
+	case CC_CSMI_SAS_GET_RAID_CONFIG:
+		returnStatus = aac_CSMIGetRAIDConfig(dev, arg);
+		break;
+
+	case CC_CSMI_SAS_STP_PASSTHRU:
+		returnStatus = aac_CSMISTPPassThru(dev, arg);
+		break;
+
+	/*
+	 * Unsupported CSMI control code
+	 */
+	case CC_CSMI_SAS_FIRMWARE_DOWNLOAD:
+	case CC_CSMI_SAS_GET_SCSI_ADDRESS:
+	case CC_CSMI_SAS_GET_DEVICE_ADDRESS:
+	case CC_CSMI_SAS_SMP_PASSTHRU:
+	case CC_CSMI_SAS_SSP_PASSTHRU:
+	case CC_CSMI_SAS_GET_LINK_ERRORS:
+	case CC_CSMI_SAS_TASK_MANAGEMENT:
+	case CC_CSMI_SAS_GET_CONNECTOR_INFO:
+	case CC_CSMI_SAS_PHY_CONTROL:
+	{
+		PIOCTL_HEADER pHeader;
+
+		/*
+		 * Verify buffer size. If buffer is too small, the error
+		 * status will be set for pHeader->ReturnCode in
+		 * aac_VerifyCSMIBuffer.
+		 */
+		if (!(returnStatus = aac_VerifyCSMIBuffer(&dev, arg,
+		  sizeof(PIOCTL_HEADER), &pHeader))) {
+			pHeader->ReturnCode = CSMI_SAS_STATUS_BAD_CNTL_CODE;
+			if (!(returnStatus = aac_CloseCSMIBuffer(dev, arg,
+			  pHeader)))
+				returnStatus = -EINVAL;
+		}
+		fwprintf((dev, HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+		  "aac_HandleCSMI: Unsupported ControlCode=%x",
+		  cmd));
+		break;
+	}
+	}
+
+	fwprintf((dev,
+	  HBA_FLAGS_DBG_FUNCTION_EXIT_B | HBA_FLAGS_DBG_CSMI_COMMANDS_B,
+	  "aac_HandleCSMI: Exit, ReturnCode=%d", returnStatus));
+
+	return(returnStatus);
+}
+
+#if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) ? defined(__x86_64__) : defined(CONFIG_COMPAT))
+void aac_csmi_register_ioctl32_conversion(void)
+{
+	register_ioctl32_conversion(CC_CSMI_SAS_GET_DRIVER_INFO,
+	  (int(*)(unsigned int,unsigned int,unsigned long,struct file*))sys_ioctl);
+	register_ioctl32_conversion(CC_CSMI_SAS_GET_CNTLR_CONFIG,
+	  (int(*)(unsigned int,unsigned int,unsigned long,struct file*))sys_ioctl);
+	register_ioctl32_conversion(CC_CSMI_SAS_GET_CNTLR_STATUS,
+	  (int(*)(unsigned int,unsigned int,unsigned long,struct file*))sys_ioctl);
+	register_ioctl32_conversion(CC_CSMI_SAS_GET_RAID_INFO,
+	  (int(*)(unsigned int,unsigned int,unsigned long,struct file*))sys_ioctl);
+	register_ioctl32_conversion(CC_CSMI_SAS_GET_PHY_INFO,
+	  (int(*)(unsigned int,unsigned int,unsigned long,struct file*))sys_ioctl);
+	register_ioctl32_conversion(CC_CSMI_SAS_SET_PHY_INFO,
+	  (int(*)(unsigned int,unsigned int,unsigned long,struct file*))sys_ioctl);
+	register_ioctl32_conversion(CC_CSMI_SAS_GET_SATA_SIGNATURE,
+	  (int(*)(unsigned int,unsigned int,unsigned long,struct file*))sys_ioctl);
+	register_ioctl32_conversion(CC_CSMI_SAS_GET_RAID_CONFIG,
+	  (int(*)(unsigned int,unsigned int,unsigned long,struct file*))sys_ioctl);
+	register_ioctl32_conversion(CC_CSMI_SAS_STP_PASSTHRU,
+	  (int(*)(unsigned int,unsigned int,unsigned long,struct file*))sys_ioctl);
+	register_ioctl32_conversion(CC_CSMI_SAS_FIRMWARE_DOWNLOAD,
+	  (int(*)(unsigned int,unsigned int,unsigned long,struct file*))sys_ioctl);
+	register_ioctl32_conversion(CC_CSMI_SAS_GET_SCSI_ADDRESS,
+	  (int(*)(unsigned int,unsigned int,unsigned long,struct file*))sys_ioctl);
+	register_ioctl32_conversion(CC_CSMI_SAS_GET_DEVICE_ADDRESS,
+	  (int(*)(unsigned int,unsigned int,unsigned long,struct file*))sys_ioctl);
+	register_ioctl32_conversion(CC_CSMI_SAS_SMP_PASSTHRU,
+	  (int(*)(unsigned int,unsigned int,unsigned long,struct file*))sys_ioctl);
+	register_ioctl32_conversion(CC_CSMI_SAS_SSP_PASSTHRU,
+	  (int(*)(unsigned int,unsigned int,unsigned long,struct file*))sys_ioctl);
+	register_ioctl32_conversion(CC_CSMI_SAS_GET_LINK_ERRORS,
+	  (int(*)(unsigned int,unsigned int,unsigned long,struct file*))sys_ioctl);
+	register_ioctl32_conversion(CC_CSMI_SAS_TASK_MANAGEMENT,
+	  (int(*)(unsigned int,unsigned int,unsigned long,struct file*))sys_ioctl);
+	register_ioctl32_conversion(CC_CSMI_SAS_GET_CONNECTOR_INFO,
+	  (int(*)(unsigned int,unsigned int,unsigned long,struct file*))sys_ioctl);
+	register_ioctl32_conversion(CC_CSMI_SAS_PHY_CONTROL,
+	  (int(*)(unsigned int,unsigned int,unsigned long,struct file*))sys_ioctl);
+}
+
+void aac_csmi_unregister_ioctl32_conversion(void)
+{
+	unregister_ioctl32_conversion(CC_CSMI_SAS_GET_DRIVER_INFO);
+	unregister_ioctl32_conversion(CC_CSMI_SAS_GET_CNTLR_CONFIG);
+	unregister_ioctl32_conversion(CC_CSMI_SAS_GET_CNTLR_STATUS);
+	unregister_ioctl32_conversion(CC_CSMI_SAS_GET_RAID_INFO);
+	unregister_ioctl32_conversion(CC_CSMI_SAS_GET_PHY_INFO);
+	unregister_ioctl32_conversion(CC_CSMI_SAS_SET_PHY_INFO);
+	unregister_ioctl32_conversion(CC_CSMI_SAS_GET_SATA_SIGNATURE);
+	unregister_ioctl32_conversion(CC_CSMI_SAS_GET_RAID_CONFIG);
+	unregister_ioctl32_conversion(CC_CSMI_SAS_STP_PASSTHRU);
+	unregister_ioctl32_conversion(CC_CSMI_SAS_FIRMWARE_DOWNLOAD);
+	unregister_ioctl32_conversion(CC_CSMI_SAS_GET_SCSI_ADDRESS);
+	unregister_ioctl32_conversion(CC_CSMI_SAS_GET_DEVICE_ADDRESS);
+	unregister_ioctl32_conversion(CC_CSMI_SAS_SMP_PASSTHRU);
+	unregister_ioctl32_conversion(CC_CSMI_SAS_SSP_PASSTHRU);
+	unregister_ioctl32_conversion(CC_CSMI_SAS_GET_LINK_ERRORS);
+	unregister_ioctl32_conversion(CC_CSMI_SAS_TASK_MANAGEMENT);
+	unregister_ioctl32_conversion(CC_CSMI_SAS_GET_CONNECTOR_INFO);
+	unregister_ioctl32_conversion(CC_CSMI_SAS_PHY_CONTROL);
+}
+#endif
+
+#endif
--- linux-2.6.8.1-t043-libata-update/drivers/scsi/aacraid/rx.c	2005-09-26 13:33:12.000000000 +0400
+++ aacraid-drv/drivers/scsi/aacraid/rx.c	2005-04-27 16:47:35.000000000 +0400
@@ -40,111 +40,91 @@
 #include <linux/completion.h>
 #include <linux/time.h>
 #include <linux/interrupt.h>
+#include <linux/version.h>	/* Needed for the following */
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,23))
+#if (!defined(IRQ_NONE))
+  typedef void irqreturn_t;
+# define IRQ_HANDLED
+# define IRQ_NONE
+#endif
+#endif
 #include <asm/semaphore.h>
 
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
+#include "scsi.h"
+#include "hosts.h"
+#else
 #include <scsi/scsi_host.h>
+#endif
 
 #include "aacraid.h"
 
 static irqreturn_t aac_rx_intr(int irq, void *dev_id, struct pt_regs *regs)
 {
 	struct aac_dev *dev = dev_id;
-	unsigned long bellbits;
-	u8 intstat, mask;
-	intstat = rx_readb(dev, MUnit.OISR);
-	/*
-	 *	Read mask and invert because drawbridge is reversed.
-	 *	This allows us to only service interrupts that have 
-	 *	been enabled.
-	 */
-	mask = ~(dev->OIMR);
-	/* Check to see if this is our interrupt.  If it isn't just return */
-	if (intstat & mask) 
-	{
-		bellbits = rx_readl(dev, OutboundDoorbellReg);
-		if (bellbits & DoorBellPrintfReady) {
-			aac_printf(dev, le32_to_cpu(rx_readl (dev, IndexRegs.Mailbox[5])));
-			rx_writel(dev, MUnit.ODR,DoorBellPrintfReady);
-			rx_writel(dev, InboundDoorbellReg,DoorBellPrintfDone);
-		}
-		else if (bellbits & DoorBellAdapterNormCmdReady) {
-			rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdReady);
-			aac_command_normal(&dev->queues->queue[HostNormCmdQueue]);
-		}
-		else if (bellbits & DoorBellAdapterNormRespReady) {
-			aac_response_normal(&dev->queues->queue[HostNormRespQueue]);
-			rx_writel(dev, MUnit.ODR,DoorBellAdapterNormRespReady);
-		}
-		else if (bellbits & DoorBellAdapterNormCmdNotFull) {
-			rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull);
+
+	dprintk((KERN_DEBUG "aac_rx_intr(%d,%p,%p)\n", irq, dev_id, regs));
+	if (dev->new_comm_interface) {
+		u32 Index = rx_readl(dev, MUnit.OutboundQueue);
+		if (Index == 0xFFFFFFFFL)
+			Index = rx_readl(dev, MUnit.OutboundQueue);
+		if (Index != 0xFFFFFFFFL) {
+			do {
+				if (aac_intr_normal(dev, Index)) {
+					rx_writel(dev, MUnit.OutboundQueue, Index);
+					rx_writel(dev, MUnit.ODR, DoorBellAdapterNormRespReady);
+				}
+				Index = rx_readl(dev, MUnit.OutboundQueue);
+			} while (Index != 0xFFFFFFFFL);
+			return IRQ_HANDLED;
 		}
-		else if (bellbits & DoorBellAdapterNormRespNotFull) {
-			rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull);
-			rx_writel(dev, MUnit.ODR, DoorBellAdapterNormRespNotFull);
+	} else {
+		unsigned long bellbits;
+		u8 intstat;
+		intstat = rx_readb(dev, MUnit.OISR);
+		/*
+		 *	Read mask and invert because drawbridge is reversed.
+		 *	This allows us to only service interrupts that have 
+		 *	been enabled.
+		 *	Check to see if this is our interrupt.  If it isn't just return
+		 */
+		if (intstat & ~(dev->OIMR)) 
+		{
+			bellbits = rx_readl(dev, OutboundDoorbellReg);
+			if (bellbits & DoorBellPrintfReady) {
+				aac_printf(dev, rx_readl (dev, IndexRegs.Mailbox[5]));
+				rx_writel(dev, MUnit.ODR,DoorBellPrintfReady);
+				rx_writel(dev, InboundDoorbellReg,DoorBellPrintfDone);
+			}
+			else if (bellbits & DoorBellAdapterNormCmdReady) {
+				rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdReady);
+				aac_command_normal(&dev->queues->queue[HostNormCmdQueue]);
+			}
+			else if (bellbits & DoorBellAdapterNormRespReady) {
+				rx_writel(dev, MUnit.ODR,DoorBellAdapterNormRespReady);
+				aac_response_normal(&dev->queues->queue[HostNormRespQueue]);
+			}
+			else if (bellbits & DoorBellAdapterNormCmdNotFull) {
+				rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull);
+			}
+			else if (bellbits & DoorBellAdapterNormRespNotFull) {
+				rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull);
+				rx_writel(dev, MUnit.ODR, DoorBellAdapterNormRespNotFull);
+			}
+			return IRQ_HANDLED;
 		}
-		return IRQ_HANDLED;
 	}
 	return IRQ_NONE;
 }
 
 /**
- *	aac_rx_enable_interrupt	-	Enable event reporting
- *	@dev: Adapter
- *	@event: Event to enable
- *
- *	Enable event reporting from the i960 for a given event.
- */
- 
-static void aac_rx_enable_interrupt(struct aac_dev * dev, u32 event)
-{
-	switch (event) {
-
-	case HostNormCmdQue:
-		dev->irq_mask &= ~(OUTBOUNDDOORBELL_1);
-		break;
-
-	case HostNormRespQue:
-		dev->irq_mask &= ~(OUTBOUNDDOORBELL_2);
-		break;
-
-	case AdapNormCmdNotFull:
-		dev->irq_mask &= ~(OUTBOUNDDOORBELL_3);
-		break;
-
-	case AdapNormRespNotFull:
-		dev->irq_mask &= ~(OUTBOUNDDOORBELL_4);
-		break;
-	}
-}
-
-/**
- *	aac_rx_disable_interrupt	-	Disable event reporting
+ *	aac_rx_disable_interrupt	-	Disable interrupts
  *	@dev: Adapter
- *	@event: Event to enable
- *
- *	Disable event reporting from the i960 for a given event.
  */
 
-static void aac_rx_disable_interrupt(struct aac_dev *dev, u32 event)
+static void aac_rx_disable_interrupt(struct aac_dev *dev)
 {
-	switch (event) {
-
-	case HostNormCmdQue:
-		dev->irq_mask |= (OUTBOUNDDOORBELL_1);
-		break;
-
-	case HostNormRespQue:
-		dev->irq_mask |= (OUTBOUNDDOORBELL_2);
-		break;
-
-	case AdapNormCmdNotFull:
-		dev->irq_mask |= (OUTBOUNDDOORBELL_3);
-		break;
-
-	case AdapNormRespNotFull:
-		dev->irq_mask |= (OUTBOUNDDOORBELL_4);
-		break;
-	}
+	rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
 }
 
 /**
@@ -154,25 +134,31 @@ static void aac_rx_disable_interrupt(str
  *	@p1: first parameter
  *	@ret: adapter status
  *
- *	This routine will send a synchronous comamnd to the adapter and wait 
+ *	This routine will send a synchronous command to the adapter and wait 
  *	for its	completion.
  */
 
-static int rx_sync_cmd(struct aac_dev *dev, u32 command, u32 p1, u32 *status)
+static int rx_sync_cmd(struct aac_dev *dev, u32 command,
+	u32 p1, u32 p2, u32 p3, u32 p4, u32 p5, u32 p6,
+	u32 *status, u32 * r1, u32 * r2, u32 * r3, u32 * r4)
 {
 	unsigned long start;
 	int ok;
 	/*
 	 *	Write the command into Mailbox 0
 	 */
-	rx_writel(dev, InboundMailbox0, cpu_to_le32(command));
+	rx_writel(dev, InboundMailbox0, command);
 	/*
-	 *	Write the parameters into Mailboxes 1 - 4
+	 *	Write the parameters into Mailboxes 1 - 6
 	 */
-	rx_writel(dev, InboundMailbox1, cpu_to_le32(p1));
-	rx_writel(dev, InboundMailbox2, 0);
-	rx_writel(dev, InboundMailbox3, 0);
-	rx_writel(dev, InboundMailbox4, 0);
+	rx_writel(dev, InboundMailbox1, p1);
+	rx_writel(dev, InboundMailbox2, p2);
+	rx_writel(dev, InboundMailbox3, p3);
+	rx_writel(dev, InboundMailbox4, p4);
+#if (defined(AAC_LM_SENSOR))
+	rx_writel(dev, InboundMailbox5, p5);
+	rx_writel(dev, InboundMailbox6, p6);
+#endif
 	/*
 	 *	Clear the synch command doorbell to start on a clean slate.
 	 */
@@ -180,7 +166,7 @@ static int rx_sync_cmd(struct aac_dev *d
 	/*
 	 *	Disable doorbell interrupts
 	 */
-	rx_writeb(dev, MUnit.OIMR, dev->OIMR |= 0x04);
+	rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
 	/*
 	 *	Force the completion of the mask register write before issuing
 	 *	the interrupt.
@@ -221,13 +207,25 @@ static int rx_sync_cmd(struct aac_dev *d
 		/*
 		 *	Restore interrupt mask even though we timed out
 		 */
-		rx_writeb(dev, MUnit.OIMR, dev->OIMR &= 0xfb);
+		if (dev->new_comm_interface)
+			rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xf7);
+		else
+			rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
 		return -ETIMEDOUT;
 	}
 	/*
 	 *	Pull the synch status from Mailbox 0.
 	 */
-	*status = le32_to_cpu(rx_readl(dev, IndexRegs.Mailbox[0]));
+	if (status)
+		*status = rx_readl(dev, IndexRegs.Mailbox[0]);
+	if (r1)
+		*r1 = rx_readl(dev, IndexRegs.Mailbox[1]);
+	if (r2)
+		*r2 = rx_readl(dev, IndexRegs.Mailbox[2]);
+	if (r3)
+		*r3 = rx_readl(dev, IndexRegs.Mailbox[3]);
+	if (r4)
+		*r4 = rx_readl(dev, IndexRegs.Mailbox[4]);
 	/*
 	 *	Clear the synch command doorbell.
 	 */
@@ -235,7 +233,10 @@ static int rx_sync_cmd(struct aac_dev *d
 	/*
 	 *	Restore interrupt mask
 	 */
-	rx_writeb(dev, MUnit.OIMR, dev->OIMR &= 0xfb);
+	if (dev->new_comm_interface)
+		rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xf7);
+	else
+		rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
 	return 0;
 
 }
@@ -249,8 +250,7 @@ static int rx_sync_cmd(struct aac_dev *d
 
 static void aac_rx_interrupt_adapter(struct aac_dev *dev)
 {
-	u32 ret;
-	rx_sync_cmd(dev, BREAKPOINT_REQUEST, 0, &ret);
+	rx_sync_cmd(dev, BREAKPOINT_REQUEST, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL);
 }
 
 /**
@@ -279,7 +279,8 @@ static void aac_rx_notify_adapter(struct
 		rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_3);
 		break;
 	case HostShutdown:
-//		rx_sync_cmd(dev, HOST_CRASHING, 0, 0, 0, 0, &ret);
+//		rx_sync_cmd(dev, HOST_CRASHING, 0, 0, 0, 0, 0, 0,
+//		  NULL, NULL, NULL, NULL, NULL);
 		break;
 	case FastIo:
 		rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_6);
@@ -302,27 +303,13 @@ static void aac_rx_notify_adapter(struct
 
 static void aac_rx_start_adapter(struct aac_dev *dev)
 {
-	u32 status;
 	struct aac_init *init;
 
 	init = dev->init;
 	init->HostElapsedSeconds = cpu_to_le32(get_seconds());
-	/*
-	 *	Tell the adapter we are back and up and running so it will scan
-	 *	its command queues and enable our interrupts
-	 */
-	dev->irq_mask = (DoorBellPrintfReady | OUTBOUNDDOORBELL_1 | OUTBOUNDDOORBELL_2 | OUTBOUNDDOORBELL_3 | OUTBOUNDDOORBELL_4);
-	/*
-	 *	First clear out all interrupts.  Then enable the one's that we
-	 *	can handle.
-	 */
-	rx_writeb(dev, MUnit.OIMR, 0xff);
-	rx_writel(dev, MUnit.ODR, 0xffffffff);
-//	rx_writeb(dev, MUnit.OIMR, ~(u8)OUTBOUND_DOORBELL_INTERRUPT_MASK);
-	rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
-
 	// We can only use a 32 bit address here
-	rx_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS, (u32)(ulong)dev->init_pa, &status);
+	rx_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS, (u32)(ulong)dev->init_pa,
+	  0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL);
 }
 
 /**
@@ -334,7 +321,7 @@ static void aac_rx_start_adapter(struct 
  */
 static int aac_rx_check_health(struct aac_dev *dev)
 {
-	long status = rx_readl(dev, IndexRegs.Mailbox[7]);
+	u32 status = rx_readl(dev, MUnit.OMRx[0]);
 
 	/*
 	 *	Check to see if the board failed any self tests.
@@ -345,29 +332,40 @@ static int aac_rx_check_health(struct aa
 	 *	Check to see if the board panic'd.
 	 */
 	if (status & KERNEL_PANIC) {
-		char * buffer = kmalloc(512, GFP_KERNEL);
+		char * buffer;
 		struct POSTSTATUS {
-			u32 Post_Command;
-			u32 Post_Address;
-		} * post = kmalloc(sizeof(struct POSTSTATUS), GFP_KERNEL);
-		dma_addr_t paddr = pci_map_single(dev->pdev, post, sizeof(struct POSTSTATUS), 2);
-		dma_addr_t baddr = pci_map_single(dev->pdev, buffer, 512, 1);
-		u32 status = -1;
-		int ret = -2;
+			__le32 Post_Command;
+			__le32 Post_Address;
+		} * post;
+		dma_addr_t paddr, baddr;
+		int ret;
+
+		if ((status & 0xFF000000L) == 0xBC000000L)
+			return (status >> 16) & 0xFF;
+		buffer = pci_alloc_consistent(dev->pdev, 512, &baddr);
+		ret = -2;
+		if (buffer == NULL)
+			return ret;
+		post = pci_alloc_consistent(dev->pdev,
+		  sizeof(struct POSTSTATUS), &paddr);
+		if (post == NULL) {
+			pci_free_consistent(dev->pdev, 512, buffer, baddr);
+			return ret;
+		}
 		memset(buffer, 0, 512);
 		post->Post_Command = cpu_to_le32(COMMAND_POST_RESULTS);
 		post->Post_Address = cpu_to_le32(baddr);
-		rx_writel(dev, MUnit.IMRx[0], cpu_to_le32(paddr));
-		rx_sync_cmd(dev, COMMAND_POST_RESULTS, baddr, &status);
-		pci_unmap_single(dev->pdev, paddr, sizeof(struct POSTSTATUS), 2);
-		kfree(post);
+		rx_writel(dev, MUnit.IMRx[0], paddr);
+		rx_sync_cmd(dev, COMMAND_POST_RESULTS, baddr, 0, 0, 0, 0, 0,
+		  NULL, NULL, NULL, NULL, NULL);
+		pci_free_consistent(dev->pdev, sizeof(struct POSTSTATUS),
+		  post, paddr);
 		if ((buffer[0] == '0') && (buffer[1] == 'x')) {
 			ret = (buffer[2] <= '9') ? (buffer[2] - '0') : (buffer[2] - 'A' + 10);
 			ret <<= 4;
 			ret += (buffer[3] <= '9') ? (buffer[3] - '0') : (buffer[3] - 'A' + 10);
 		}
-		pci_unmap_single(dev->pdev, baddr, 512, 1);
-		kfree(buffer);
+		pci_free_consistent(dev->pdev, 512, buffer, baddr);
 		return ret;
 	}
 	/*
@@ -379,7 +377,40 @@ static int aac_rx_check_health(struct aa
 	 *	Everything is OK
 	 */
 	return 0;
-} /* aac_rx_check_health */
+}
+
+/**
+ *	aac_rx_send
+ *	@fib: fib to issue
+ *
+ *	Will send a fib, returning 0 if successful.
+ */
+static int aac_rx_send(struct fib * fib)
+{
+	u64 addr = fib->hw_fib_pa;
+	struct aac_dev *dev = fib->dev;
+	u32 * device = (u32 *)(dev->regs.rx);
+	u32 Index;
+
+	dprintk((KERN_DEBUG "%p->aac_rx_send(%p->%llx)\n", dev, fib, addr));
+	Index = rx_readl(dev, MUnit.InboundQueue);
+	if (Index == 0xFFFFFFFFL)
+		Index = rx_readl(dev, MUnit.InboundQueue);
+	dprintk((KERN_DEBUG "Index = 0x%x\n", Index));
+	if (Index == 0xFFFFFFFFL)
+		return Index;
+	device += Index / sizeof(u32);
+	dprintk((KERN_DEBUG "entry = %x %x %u\n", (u32)(addr & 0xffffffff),
+	  (u32)(addr >> 32), (u32)le16_to_cpu(fib->hw_fib->header.Size)));
+	writel((u32)(addr & 0xffffffff), device);
+	++device;
+	writel((u32)(addr >> 32), device);
+	++device;
+	writel(le16_to_cpu(fib->hw_fib->header.Size), device);
+	rx_writel(dev, MUnit.InboundQueue, Index);
+	dprintk((KERN_DEBUG "aac_rx_send - return 0\n"));
+	return 0;
+}
 
 /**
  *	aac_rx_init	-	initialize an i960 based AAC card
@@ -401,14 +432,6 @@ int aac_rx_init(struct aac_dev *dev)
 	name     = dev->name;
 
 	/*
-	 *	Map in the registers from the adapter.
-	 */
-	if((dev->regs.rx = (struct rx_registers *)ioremap((unsigned long)dev->scsi_host_ptr->base, 8192))==NULL)
-	{	
-		printk(KERN_WARNING "aacraid: unable to map i960.\n" );
-		return -1;
-	}
-	/*
 	 *	Check to see if the board failed any self tests.
 	 */
 	if (rx_readl(dev, MUnit.OMRx[0]) & SELF_TEST_FAILED) {
@@ -438,8 +461,9 @@ int aac_rx_init(struct aac_dev *dev)
 	{
 		if(time_after(jiffies, start+180*HZ))
 		{
-			status = rx_readl(dev, IndexRegs.Mailbox[7]) >> 16;
-			printk(KERN_ERR "%s%d: adapter kernel failed to start, init status = %ld.\n", dev->name, instance, status);
+			status = rx_readl(dev, IndexRegs.Mailbox[7]);
+			printk(KERN_ERR "%s%d: adapter kernel failed to start, init status = %lx.\n", 
+					dev->name, instance, status);
 			goto error_iounmap;
 		}
 		set_current_state(TASK_UNINTERRUPTIBLE);
@@ -454,14 +478,28 @@ int aac_rx_init(struct aac_dev *dev)
 	 *	Fill in the function dispatch table.
 	 */
 	dev->a_ops.adapter_interrupt = aac_rx_interrupt_adapter;
-	dev->a_ops.adapter_enable_int = aac_rx_enable_interrupt;
 	dev->a_ops.adapter_disable_int = aac_rx_disable_interrupt;
 	dev->a_ops.adapter_notify = aac_rx_notify_adapter;
 	dev->a_ops.adapter_sync_cmd = rx_sync_cmd;
 	dev->a_ops.adapter_check_health = aac_rx_check_health;
+	dev->a_ops.adapter_send = aac_rx_send;
+#if (defined(SCSI_HAS_DUMP))
+	dev->a_ops.adapter_intr = aac_rx_intr;
+#endif
+
+	/*
+	 *	First clear out all interrupts.  Then enable the one's that we
+	 *	can handle.
+	 */
+	rx_writeb(dev, MUnit.OIMR, 0xff);
+	rx_writel(dev, MUnit.ODR, 0xffffffff);
+	rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
 
 	if (aac_init_adapter(dev) == NULL)
 		goto error_irq;
+	if (dev->new_comm_interface)
+		rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xf7);
+
 	/*
 	 *	Start any kernel threads needed
 	 */
@@ -482,10 +520,10 @@ error_kfree:
 	kfree(dev->queues);
 
 error_irq:
+	rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
 	free_irq(dev->scsi_host_ptr->irq, (void *)dev);
 
 error_iounmap:
-	iounmap(dev->regs.rx);
 
 	return -1;
 }