File: hba.cpp

package info (click to toggle)
raidutils 0.0.6-23
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 10,840 kB
  • sloc: cpp: 39,794; ansic: 22,774; sh: 8,306; makefile: 19
file content (4225 lines) | stat: -rw-r--r-- 114,064 bytes parent folder | download | duplicates (5)
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
/* Copyright (c) 1996-2004, Adaptec Corporation
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice, this
 *   list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 * - Neither the name of the Adaptec Corporation nor the names of its
 *   contributors may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

//File - HBA.CPP
//***************************************************************************
//
//Description:
//
//    This file contains function definitions for the dptHBA_C class.
//
//Author:       Doug Anderson
//Date:         4/8/93
//
//Editors:
//
//Remarks:
//
//
//***************************************************************************

#include	"allfiles.hpp"	// All engine include files
#include	"i2omsg.h"
#include	"i2obscsi.h"
#include	"i2odpt.h"

#ifdef _DPT_ERGO
extern "C" {
	#ifndef _DPT_SOLARIS
		void _Cdecl sleep( unsigned __seconds );
	#endif
}
#endif
#ifdef _DPT_UNIX
#include <unistd.h>     // sleep()
#endif


#include <time.h>

//TODO: remove
#include <stdio.h>

extern "C" {
#ifdef _DPT_NETWARE

//Watcom 9.5 compiler doesn't do the right thing here and the linker can't resolve
//the symbol if it has an extern in front of it

unsigned short DPTI_BootFlags;

#else

extern unsigned short DPTI_BootFlags;

#endif
};

#if !defined _DPT_UNIX && !defined _DPT_NETWARE && !defined _DPT_DOS
extern "C" {
	DPT_RTN_T DPT_EXPORT osdSendMessage(uLONG, PI2O_MESSAGE_FRAME, PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME);
	uLONG osdTargetBusy(uLONG HbaNum, uLONG Channel, uLONG TargetId, uLONG LUN);
	DPT_RTN_T osdRescan(uLONG HbaNum, uLONG Operation);
}
#else
	DPT_RTN_T DPT_EXPORT osdSendMessage(uLONG, PI2O_MESSAGE_FRAME, PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME);
	uLONG osdTargetBusy(uLONG HbaNum, uLONG Channel, uLONG TargetId, uLONG LUN);
	DPT_RTN_T osdRescan(uLONG HbaNum, uLONG Operation);
#endif // _DPT_UNIX

//Function - dptHBA_C::passCCB() - start
//===========================================================================
//
//Description:
//
//    This function makes adjustments to the CCB and then passes
//the send CCB request up the attachment chain.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::passCCB(engCCB_C *ccb_P)
{

   DPT_RTN_T    retVal = MSG_RTN_FAILED | ERR_BLINK_LED_IO;

  // If the HBA is not in blink LED mode...
if (!isBlinkLED()) {
	// Set the nested FW drive bit
   ccb_P->setNFW();

	// If the command came from a physical device...
   if (ccb_P->isPhy() && !ccb_P->isNoEATAphys())
	// Set physical bit
	 ccb_P->setPhysical();
	// If the command came from an HBA logical device...
   else if (ccb_P->isRAIDcmd())
	// Set the firmware level bits
	 ccb_P->setFW();
   else if (ccb_P->isMgr())
	// Set the interpret bit
	 ccb_P->setInterpret();

	// Always physical origin to the next level
   ccb_P->setPhy();

	// Send the CCB to the next level in the attachment chain
   retVal = myMgr_P()->passCCB(ccb_P);
}

return (retVal);

}
//dptHBA_C::passCCB() - end


//Function - dptHBA_C::findMyPhysicals() - start
//===========================================================================
//
//Description:
//
//    This function finds all physical SCSI devices attached to this HBA.
//
//---------------------------------------------------------------------------

uSHORT  dptHBA_C::findMyPhysicals()
{

   uSHORT               retVal = 0;
   uSHORT               foundDev,skipToNextID;
   engCCB_C             *ccb_P;
   sdInquiry_S          *inq_P;
   dptDevice_C          *newDev_P;
   uCHAR                qualifier;
   uCHAR                devType;
   dptSCSIbcd_C         *bcd_P = NULL;
   dptSCSIbcd_C         *newBCD_P = NULL;
   dptDevice_C          *prevDev_P = NULL;

  // If flash command mode or blink LED mode...
if (isFlashMode() || isBlinkLED())
   return (1);

  // Get a CCB
ccb_P = getCCB();
if (ccb_P!=NULL) {
	// Indicate a successful scan
   retVal = 1;
	// For all supported SCSI channels, ids, & luns
   for (phyRange.reset();!phyRange.maxedOut();phyRange.incBottomUp()) {
	 skipToNextID = 0;
	// If a new SCSI ID...
	 if (phyRange.cur().lun==0) {
	   // If there was an object at the last SCSI ID
	 if (prevDev_P!=NULL)
		 // Enter it into the physical device list
	    enterPhy(prevDev_P);
	   // There is no bridge controller
	 bcd_P = NULL;
	   // There is no previous object at this SCSI ID
	 prevDev_P = NULL;
		}
	 foundDev = 0;
	 ccb_P->reInit();
	// Initialize the CCB for a SCSI Inquiry command
	 ccb_P->inquiry();
	// Target the CCB for the specified SCSI address
	 ccb_P->target(phyRange.cur(),this,CCB_ORIG_PHY);
	// Send the CCB to H/W
	 DPT_RTN_T rtnStatus = launchCCB(ccb_P);
	// If an I/O error occurred...
	 if (rtnStatus == (MSG_RTN_FAILED | ERR_SCSI_IO)) {
	   // If a check condition...
	 if (ccb_P->scsiStatus == 2) {
	    uCHAR *reqSense_P = NULL;
		 // If auto-request sense is active...
	    if (ccb_P->eataCP.flags & CP_REQ_SENSE)
		  reqSense_P = ccb_P->defReqSense;
	    else {
		  ccb_P->reInit();
		  ccb_P->reqSense();
		 // Target the CCB for the specified SCSI address
		  ccb_P->target(phyRange.cur(),this,CCB_ORIG_PHY);
		  if (launchCCB(ccb_P) == MSG_RTN_COMPLETED)
			reqSense_P = ccb_P->dataBuff_P;
	    }
	    if (reqSense_P != NULL) {
		 // If sense key == Not Ready
		  if (((reqSense_P[2] & 0x0f) == 0x02) && (reqSense_P[12] == 0x04)) {
		    // If format in progress or DPT format clearing phase
		  if ((reqSense_P[13] == 0x04) || (reqSense_P[13] == 0x84)) {
			foundDev = 2;
			devType = DPT_SCSI_DASD;
		  }
		  }
		 }
	 }
	   // If a selection timeout...
	 else if (ccb_P->ctlrStatus == 1)
		 // Give other tasks a chance to run
	    osdSwitchThreads();
	   //-------------------------------------------------------
	   // Note: By going to the next SCSI ID here, if a drive is
	   // formatting, no further LUNs will be searched.  This
	   // will cause the engine not to see devices attached to
	   // a bridge controller if a lower LUN is formatting.
	   //-------------------------------------------------------
	   // Go to the next SCSI ID
	 skipToNextID = 1;
	 }
	// If the Inquiry was successful...
	 else if (rtnStatus == MSG_RTN_COMPLETED) {
	   // Cast the default data buffer as SCSI Inquiry data
	 inq_P = (sdInquiry_S *) ccb_P->defData;
	   // Get the peripheral qualifier
	 qualifier = (inq_P->getPeripheral() & 0xe0) >> 5;

		// If LUN not supported... *** Always check all luns ***
	 //if (qualifier==0x3)
	 //	 skipToNextID = 1;
		// If a device is connected at this ID...
	 //else if ((qualifier==0x00) || (qualifier==0x02)) {

	 if ((qualifier==0x00) || (qualifier==0x02)) {
			// Get the peripheral device type
		 devType = (inq_P->getPeripheral() & 0x1f);
		 foundDev = 1;
#if 0
		// Most scanners (including HP) return a peripheral
		// device type of 3 (Processor) instead of scanner
		// If the unit responds to a Get Window (25h) command,
		// we will assume that it is a scanner
		// NOTE: Get Window (25h) is not mandatory for scanner
		// devices.  It is used here because the only scanner
		// specific SCSI command which are mandatory are SCAN
		// and Set Window, both of which have major side effects.
		if(devType == 3)
		{
			ccb_P->reInit();
			// A readCapacity is the same opcode as Get Window
			// Have to use this function because we don't have
			// access to the dptCDB_S from here
			ccb_P->readCapacity();
			// Data In
			ccb_P->input();
			// Set the physical bit
			ccb_P->setPhysical();

			// Target the CCB for the specified SCSI address
			ccb_P->target(phyRange.cur(),this,CCB_ORIG_PHY);
			if(launchCCB(ccb_P) == MSG_RTN_COMPLETED)
				devType = 6;
		}
#endif
		// Don't look for LUNs on scanners
		// Some (i.e. Mustek MFS-12000SP) respond to all
		// LUNs with qualifier == 0
	    if(devType == 6) skipToNextID = 1;

	    if (bcd_P == NULL) {
		 // If the device is attached to an NCR type RAID
		 // bridge controller...
		  if (isRAIDbcd())
		    // Create an NCR type RAID bridge controller
		  newBCD_P = (dptSCSIbcd_C *) newObject(DPT_RAID_BCD);
		 // If the device is at a non-zero lun
		  else if (phyRange.cur().lun!=0)
		    // Create a standard bridge controller
		  newBCD_P = (dptSCSIbcd_C *) newObject(DPT_SCSI_BCD);
	    }
	 }
	   // If LUN is supported, but no device at this ID
	 else if ((qualifier==0x01) && (bcd_P==NULL)) {
		 // If the device is attached to an NCR type RAID
		 // bridge controller...
	    if (isRAIDbcd())
		 // Create an NCR type RAID bridge controller
		  newBCD_P = (dptSCSIbcd_C *) newObject(DPT_RAID_BCD);
	    else
		 // Create a standard bridge controller
		  newBCD_P = (dptSCSIbcd_C *) newObject(DPT_SCSI_BCD);
	 }
	   // If a bridge controller has just been created...
	 if (newBCD_P!=NULL) {
	    bcd_P       = newBCD_P;
	    newBCD_P    = NULL;
		 // Indicate that this manager is real
	    bcd_P->status.flags |= FLG_STAT_REAL;
		 // Set the manager's address
	    bcd_P->addr = phyRange.cur();
		 // Add the manager to the physical device list
	    enterPhy(bcd_P);
		 // If there was a previous device at this SCSI ID...
	    if (prevDev_P!=NULL) {
		 // Add to the BCD
		  bcd_P->enterFromHBA(prevDev_P);
		  prevDev_P = NULL;
	    }
	 }
	 } // end if (rtnStatus == MSG_RTN_COMPLETED)

	// If a device was found...
	 if (foundDev) {
	   // Create a new SCSI device
	 newDev_P = (dptDevice_C *) newObject(devType);
	 if (newDev_P!=NULL) {
		 // Indicate that this is a real device
	    newDev_P->status.flags |= FLG_STAT_REAL;
		 // Set the new device's SCSI address
	    newDev_P->addr = phyRange.cur();
		 // If there is an active bridge controller...
	    if (bcd_P!=NULL)
		 // Add the new device to the BCD
		  bcd_P->enterFromHBA(newDev_P);
	    else {
		 // Set a previous object pointer so the device
		 // can be added to a bridge ctlr or when the scan
		 // moves to the next SCSI ID
		  prevDev_P = newDev_P;
	    } // end if (bcd_P==NULL)
	 } // end if (newDev_P!=NULL)
	 } // end if (foundDev)

	 if (skipToNextID)
	 phyRange.nextID();

   } // end for (phyRange)
	// If there was an object at the last SCSI ID
   if (prevDev_P!=NULL)
	// Enter it into the physical device list
	 enterPhy(prevDev_P);
	// Free the CCB
   ccb_P->clrInUse();
} // end if (ccb_P!=NULL)

return (retVal);

}
//dptHBA_C::findMyPhysicals() - end


//Function - dptHBA_C::findMyLogicals() - start
//===========================================================================
//
//Description:
//
//    This function finds all FW logical devices associated with this HBA.
//
//Return Value:
//
//   1 = OK
//   0 = Failure
//
//---------------------------------------------------------------------------

uSHORT  dptHBA_C::findMyLogicals()
{

   uSHORT       retVal = 1;

  // If flash command mode or blink LED mode...
if (isFlashMode() || isBlinkLED())
   return (retVal);

  // If the HBA supports RAID...
if (isRAIDcapable()) {
   retVal = 0;
	// Get a CCB
   engCCB_C *ccb_P = getCCB();
   if (ccb_P!=NULL) {
	 retVal = 1;
	// Initialize the CCB to do a log sense
	 ccb_P->logSense(0x36);
	// Indicate that this is a RAID command
	 ccb_P->setRAIDcmd();
	// Target the controller
	 ccb_P->target(addr,this,CCB_ORIG_LOG);
	 if (launchCCB(ccb_P)==MSG_RTN_COMPLETED) {
	   // Create logical devices for the SCSI addresses returned
	 newLP36Devices(ccb_P,this);
	 }

	// Free the CCB
	 ccb_P->clrInUse();
   } // end if (ccb_P!=NULL)
} // end if (isRAIDcapable())

  // Check for emulated drives
checkForEmul();

return (retVal);

}
//dptHBA_C::findMyLogicals() - end


//Function - dptHBA_C::isRAIDbcd() - start
//===========================================================================
//
//Description:
//
//    This routine checks to see if a device is attached to a hardware
//array.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
// 1. This function is intended for use in the findPhysObjects() function.
//
//---------------------------------------------------------------------------

uSHORT  dptHBA_C::isRAIDbcd()
{

   uSHORT               retVal = 0;
   hwaHWdata_S          *bcdData_P;

  // Get a CCB
engCCB_C *ccb_P = getCCB();
if (ccb_P!=NULL) {
  // Initialize the EATA CP.......................

	// Initialize the CCB for a SCSI Inquiry command
   ccb_P->inquiry(0xc0);
	// Target the CCB for the specified SCSI address
   ccb_P->target(phyRange.cur(),this,CCB_ORIG_PHY);
   if (launchCCB(ccb_P)==MSG_RTN_COMPLETED) {
	// Cast the return data pointer
	 bcdData_P = (hwaHWdata_S *) ccb_P->defData;
	// Check for the hardware array info signature
		if (memcmp(bcdData_P->getPageID(),"HWRE",4)==0 )
	 retVal = 1;
   }
	// Free the CCB
   ccb_P->clrInUse();
}

return (retVal);

}
//dptHBA_C::isRAIDbcd() - end


//Function - dptHBA_C::findComponent() - start
//===========================================================================
//
//Description:
//
//    This function finds a component device with the specified SCSI
//address.  The HBA field of the SCSI address is assumed to be set to
//the HBA's index #.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

dptDevice_C *   dptHBA_C::findComponent(dptAddr_S inAddr,uSHORT,uLONG inMagicNum, dptCoreList_C *)
{

   dptObject_C          *obj_P = NULL;
   dptDevice_C          *comp_P = NULL;
   dptSCSIbcd_C         *bcd_P = NULL;

  // Assume the component is attached to this HBA
inAddr.hba = getHBA();

  // If a magic # was specified...
if (inMagicNum)
	// Search for a device with a matching magic #
   obj_P = findMagicObject(phyList,inMagicNum);
else
	// Search for a device with a matching SCSI address
   obj_P = findObjectAt(phyList,inAddr);

  // If an object was found...
if (obj_P!=NULL) {
	// If a manager was found...
   if (obj_P->isManager())
	 bcd_P = (dptSCSIbcd_C *) obj_P;
	// If a device was found...
   else
	 comp_P = (dptDevice_C *) obj_P;
}

  // If no device was found...
if (comp_P==NULL) {
	// Create an absent device
   comp_P = (dptDevice_C *) newObject(DPT_SCSI_DASD);
   if (comp_P!=NULL) {
	// Set the device's SCSI address
	 comp_P->addr = inAddr;
	// Set the devices status to missing
	 comp_P->status.display = DSPLY_STAT_MISSING;
	// If the device belongs on a bridge controller &
	// no bridge exists...
	 if ((bcd_P==NULL) && (inAddr.lun!=0)) {
	   // Create a new bridge controller
	 bcd_P = (dptSCSIbcd_C *) newObject(DPT_SCSI_BCD);
	 if (bcd_P!=NULL) {
		 // Set the device's SCSI address
	    bcd_P->addr = inAddr;
		 // Set the devices status to missing
	    bcd_P->status.display = DSPLY_STAT_MISSING;
		 // Add the manager to the HBA's physical list
	    if (!enterPhy(bcd_P))
		    bcd_P = NULL;
	 }
	 } // end if (inAddr.lun!=0)
	 if (bcd_P!=NULL)
	   // Add the component to the sub-manager's logical list
	 bcd_P->enterFromHBA(comp_P);
	 else
	   // Add the component to the HBA's physical list
		// if this call fails object will be deleted.
	 if (enterPhy(comp_P))
		comp_P = NULL;
   } // end if (comp_P!=NULL)
} // end if (comp_P!=NULL)

return (comp_P);

}
//dptHBA_C::findComponent() - end


//Function - dptHBA_C::realInit() - start
//===========================================================================
//
//Description:
//
//    This function initializes a real HBA.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

void    dptHBA_C::realInit()
{

  // Get the hardware information
getHWinfo();

  // Get the info contained in NV RAM
getNVinfo();

  // Check for RAID response to RAID command
checkForRAID();

  // Get the event log control word
getEventCtl();

  // Read the drive size table
  // (If not supported pointer will remain NULL)
readDriveSizeTable();
/* DEBUG code
if (driveSizeTable_P != NULL) {
	dptBuffer_S *buff_P = dptBuffer_S::newBuffer(512);
	uLONG temp = 1;
	buff_P->insert(temp);
	temp = 3;
	buff_P->insert(temp);
	temp = 0x10000;
	buff_P->insert(temp);
	temp = 0x20000;
	buff_P->insert(temp);
	temp = 0x40000;
	buff_P->insert(temp);
	setArrayDriveSizeTable(buff_P);
	buff_P->reset();
	buff_P->clear();
	getArrayDriveSizeTable(buff_P);
	dptBuffer_S::delBuffer(buff_P);
}
*/
/* DEBUG code
// Fake a drive size table
driveSizeTable_S *ds_P = (driveSizeTable_S *) new UCHAR[8+(2*4)];
ds_P->setMaxEntries(1);
ds_P->setNumEntries(1);
ds_P->setEntry(0, 0x40000);
useDriveSizeTable(ds_P);
delete[] ((uCHAR *) ds_P);
*/

}
//dptHBA_C::realInit() - end


//Function - dptHBA_C::getHWinfo() - start
//===========================================================================
//
//Description:
//
//    This function determines what hardware the HBA has.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

void    dptHBA_C::getHWinfo()
{


DEBUG_BEGIN(5, dptHBA_C::getHWinfo());

  // Get a CCB
engCCB_C *ccb_P = getCCB();
if (ccb_P!=NULL) {
	// Initialize the CCB to do a log sense page 0x33
	// Limit data buffer to 0xff bytes
	ccb_P->logSense(0x33,0,0xff);
	// Target this HBA
	ccb_P->target(this);
	// Send the CCB to hardware
	if (launchCCB(ccb_P)==MSG_RTN_COMPLETED) {
		uSHORT tempUShort = 0;
		raidDef_S *def_P;
		// Clear all flags except those specified below
		hbaFlags2 &= FLG_HBA_SCAM | FLG_HBA_I2O;
		ccb_P->initLogSense();
		while (ccb_P->log.isValidParam()) {
			switch (ccb_P->log.code()) {

				 // Check for a RAID Key Card & Cache Module
				case 1:
					if (ccb_P->log.data_P()[0] & LGS_KEYCARD)
						modules       |= FLG_MOD_DM401X;
					if (ccb_P->log.data_P()[0] & LGS_CACHEMODULE)
						modules       |= FLG_MOD_CM401X;
					// Check for DEC storage sub-system H/W on HBA
					if (ccb_P->log.data_P()[0] & 0x20)
						hbaFlags2     |= FLG_HBA_SUBSYS_HW;
					// NV RAM is present on the HBA
					if (ccb_P->log.data_P()[0] & 0x40)
						hbaFlags2     |= FLG_HBA_NVRAM;
					// Auto-termination of narrow SCSI bus supported
					if (ccb_P->log.data_P()[0] & 0x80)
						hbaFlags2     |= FLG_HBA_AUTO_TERM;

					if (ccb_P->log.length() >= 2) {
						irqNum &= ~0xff;
						irqNum |= ccb_P->log.data_P()[1];
					}
					break;

				 // Get the firmware battery flags and memory parity error flag
				case 2:
					fwFlags = ccb_P->log.data_P()[0];
					break;

				 // Get the total controller memory
				case 4:
					totalMem = getU4(ccb_P->log.data_P(),0);
					reverseBytes(totalMem);
					break;

                // Get the total controller memory
				case 6:
					if(isI2O())
					{
						if (ccb_P->log.data_P()[1] & 0x01) {
							raidSupport &= ~FLG_RAID_0;
						}
						if (ccb_P->log.data_P()[1] & 0x02) {
							raidSupport &= ~FLG_RAID_1;
						}
						if (ccb_P->log.data_P()[1] & 0x04) {
							raidSupport &= ~FLG_RAID_5;
						}
						if (ccb_P->log.data_P()[1] & 0x08) {
							hbaFlags2 |= FLG_HBA_PREDICTIVE;
						}
					}
					break;

				 // Get the Host to HBA bus information
				case 7:
					if (ccb_P->log.data_P()[0] & 0x40)
						busType = HBA_BUS_PCI;
					switch (ccb_P->log.data_P()[0] & 0x3f) {
						case 1:       memcpy(busSpeed,"3.3",4);       break;
						case 2:       memcpy(busSpeed,"4.0",4);       break;
						case 3:       memcpy(busSpeed,"4.4",4);       break;
						case 4:       memcpy(busSpeed,"5.0",4);       break;
						case 5:       memcpy(busSpeed,"5.7",4);       break;
						case 6:       memcpy(busSpeed,"6.7",4);       break;
						case 7:       memcpy(busSpeed,"8.0",4);       break;
						case 8:       memcpy(busSpeed," 10",4);       break;
						case 0x10:    memcpy(busSpeed," 33",4);       break;
						case 0x11:    memcpy(busSpeed," 66",4);       break;
						case 0x12:    memcpy(busSpeed,"132",4);       break;
						case 0x13:    memcpy(busSpeed,"264",4);       break;
					}
					hostBusInfo = ccb_P->log.data_P()[1];
					break;

				 // Get the SCSI bus capabilities
				case 8:
					switch (ccb_P->log.data_P()[0] & 0x0f) {
						case 0:       scsiBusSpeed = 5;       break;
						case 1:       scsiBusSpeed = 10;      break;
						case 2:       scsiBusSpeed = 20;      break;
					}
					if (ccb_P->log.data_P()[0] & 0x80) {
						flags |= FLG_HBA_DIFFERENTIAL;
						chanInfo[0].flags |= FLG_CHAN_DIFFERENTIAL;
					}
					if (ccb_P->log.data_P()[0] & 0x40) {
						flags |= FLG_HBA_WIDE_16;
						chanInfo[0].flags |= FLG_CHAN_WIDE_16;
						scsiBusSpeed <<= 1;
					}
					if (ccb_P->log.data_P()[0] & 0x20) {
						flags |= FLG_HBA_EXTERNAL;
						chanInfo[0].flags |= FLG_CHAN_EXTERNAL;
						scsiBusSpeed >>= 1;
					}
					if (ccb_P->log.data_P()[0] & 0x10) {
						hbaFlags2 |= FLG_HBA_ULTRA;
						chanInfo[0].flags |= FLG_CHAN_ULTRA;
					}
					chanInfo[0].scsiBusSpeed = scsiBusSpeed;
					break;

				 // Get the attached modules
				case 9:
					if (!(ccb_P->log.data_P()[0] & 0x80))
						flags |= FLG_HBA_CHIPSET;
					modules |= ((uSHORT)ccb_P->log.data_P()[0]) << 9;
					// If a new cache module was detected
					if (modules & (FLG_MOD_CM4000 | FLG_MOD_CMI))
						// There can't be an old cache module
						modules &= ~FLG_MOD_CM401X;
					// If a new RAID module was detected
					if (modules & (FLG_MOD_DM4000 | FLG_MOD_DMI))
						// There can't be an old RAID module
						modules &= ~FLG_MOD_DM401X;
					cpuType = ccb_P->log.data_P()[1];
					cpuSpeed = ccb_P->log.data_P()[2];
					if (ccb_P->log.data_P()[3] & 0x80)
						flags |= FLG_HBA_SMARTROM;
					if (ccb_P->log.data_P()[3] & 0x40)
						status.flags |= FLG_STAT_ALARM_ON;
					if (ccb_P->log.data_P()[3] & 0x01)
						modules |= FLG_MOD_SX1;
					if (ccb_P->log.data_P()[3] & 0x02)
						modules |= FLG_MOD_SX2;
					if (ccb_P->log.data_P()[3] & 0x04)
						modules |= FLG_MOD_BBU;
					if (ccb_P->log.data_P()[3] & 0x10) {
						modules |= FLG_MOD_RC4040;
						modules &= ~(FLG_MOD_CM401X | FLG_MOD_CM4000 | FLG_MOD_DM401X | FLG_MOD_DM4000);
					}
					if (ccb_P->log.data_P()[3] & 0x20) {
						modules |= FLG_MOD_RC4041;
						modules &= ~(FLG_MOD_CM401X | FLG_MOD_CM4000 | FLG_MOD_DM401X | FLG_MOD_DM4000);
					}
					if (ccb_P->log.data_P()[3] & 0x08)
						hbaFlags2 |= FLG_HBA_SC4;
					break;

				 // Get the attached memory modules/SIMMs
				case 10:
					memBank[0] = ccb_P->log.data_P()[0];
					extMemBank[0] = ccb_P->log.data_P()[0] & 0x7f;
					if (memBank[0]!=0) {
						modules |= FLG_MOD_MEM_BANK0;
					}
					memBank[1] = ccb_P->log.data_P()[1];
					extMemBank[1] = ccb_P->log.data_P()[1] & 0x7f;
					if (memBank[1]!=0) {
						modules |= FLG_MOD_MEM_BANK1;
					}
					memBank[2] = ccb_P->log.data_P()[2];
					extMemBank[2] = ccb_P->log.data_P()[2] & 0x7f;
					if (memBank[2]!=0) {
						modules |= FLG_MOD_MEM_BANK2;
					}
					memBank[3] = ccb_P->log.data_P()[3];
					extMemBank[3] = ccb_P->log.data_P()[3] & 0x7f;
					if (memBank[3]!=0) {
						modules |= FLG_MOD_MEM_BANK3;
					}

					if (ccb_P->log.length() >= 0x0c) {
						tempUShort = getU2(ccb_P->log.data_P(), 4);
						#ifndef	_DPT_BIG_ENDIAN
							reverseBytes(tempUShort);
						#endif
						if (tempUShort) {
							modules |= FLG_MOD_MEM_BANK0;
							extMemBank[0] = tempUShort;
						}

						tempUShort = getU2(ccb_P->log.data_P(), 6);
						#ifndef	_DPT_BIG_ENDIAN
							reverseBytes(tempUShort);
						#endif
						if (tempUShort) {
							modules |= FLG_MOD_MEM_BANK1;
							extMemBank[1] = tempUShort;
						}

						tempUShort = getU2(ccb_P->log.data_P(), 8);
						#ifndef	_DPT_BIG_ENDIAN
							reverseBytes(tempUShort);
						#endif
						if (tempUShort) {
							modules |= FLG_MOD_MEM_BANK2;
							extMemBank[2] = tempUShort;
						}

						tempUShort = getU2(ccb_P->log.data_P(), 10);
						#ifndef	_DPT_BIG_ENDIAN
							reverseBytes(tempUShort);
						#endif
						if (tempUShort) {
							modules |= FLG_MOD_MEM_BANK3;
							extMemBank[3] = tempUShort;
						}
					}
					break;

				 // Get the FW type
				case 11:
					fwType = *(uSHORT *)(ccb_P->log.data_P()+2);
					reverseBytes(fwType);
					// If downloadable FW is supported...
					if (ccb_P->log.data_P()[0] & 0x0001)
						// Set the downloadable FW support flag
						flags |= FLG_HBA_DOWNLOAD_FW;
					if (ccb_P->log.data_P()[0] & 0x0002)
						// Indicate that 528 byte block size ECC is supported
						flags |= FLG_HBA_ECC_ENABLED;
					if (ccb_P->log.data_P()[0] & 0x0004)
						// Indicate that F/W supports the "Interpret Format" cmd
						hbaFlags2 |= FLG_HBA_INTERPRET_FMT;
					if (ccb_P->log.data_P()[0] & 0x0008)
						// Indicate that F/W and the board support ECC
						flags |= FLG_HBA_ECC_SUPPORTED;
					if (ccb_P->log.data_P()[0] & 0x0010)
						// Indicate that F/W based diagnostics are supported
						hbaFlags2 |= FLG_HBA_DIAGNOSTICS;
					if (ccb_P->log.data_P()[0] & 0x0080)
						// Indicate that SMART emulation is support
						hbaFlags2 |= FLG_HBA_SMART_EMULATION;
					// Indicate array expansion capability
					if (ccb_P->log.data_P()[1] & 0x01)
						hbaFlags2 |= FLG_HBA_EXPAND_ARRAY;
					// does the hba support tuneable drive spinups?
					if (ccb_P->log.data_P()[1] & 0x02)
						hbaFlags2 |= FLG_HBA_VAR_SPIN_UP;
					// Firmware supports
					//	1. The second version of log page 0x36
					//	2. The second version of the physical array page
					//	3. Fibre SCSI ID packing
					//     (using the upper 2 channel bits as extended ID bits
					//	    if 2 or fewer SCSI buses)
					if (ccb_P->log.data_P()[1] & 0x04)
						hbaFlags2 |= FLG_HBA_I2O_VER2;

					if (ccb_P->log.data_P()[1] & 0x10)
						hbaFlags2 |= FLG_HBA_NO_ALARM;

					if (ccb_P->log.data_P()[1] & 0x20) {
						raidFlags |= FLG_SEG_64;
					}

					if (ccb_P->log.data_P()[1] & 0x40) {
						raidFlags |= FLG_SEG_SUPPORTED;
					}

					// Check for temperature thresholds
					if (ccb_P->log.length() > 4)
						if (ccb_P->log.data_P()[4] && ccb_P->log.data_P()[5])
							hbaFlags2 |= FLG_HBA_TEMP_PROBE;
					break;

				 // SmartRAID signals
				case 12:
					hbaFlags2 |= (uSHORT) ccb_P->log.data_P()[0];
					// Make the invalid subsystem status flag a valid flag
					hbaFlags2 ^= FLG_HBA_SUBSYS_VALID;
					break;

				 // Per channel info (including SmartRAID signals)
				case 13:
					updateChannelInfo(&(ccb_P->log));
					break;

				case 14:
					maxArrays = (uSHORT) ccb_P->log.data_P()[0];
					def_P = getRAIDtdef(0);
					if (def_P != NULL)
						def_P->maxDrives = (uSHORT) ccb_P->log.data_P()[1];
					def_P = getRAIDtdef(3);
					if (def_P != NULL)
						def_P->maxDrives = (uSHORT) ccb_P->log.data_P()[2];
					def_P = getRAIDtdef(5);
					if (def_P != NULL) {
						def_P->maxDrives = (uSHORT) ccb_P->log.data_P()[2];
					}

					// Get the default rebuild frequency (if supported by firmware)
					if (ccb_P->log.data_P()[7] != 0) {
						rbldFrequency = ccb_P->log.data_P()[7];
					}


					maxRaidComponents = (uSHORT) ccb_P->log.data_P()[2];

					if (ccb_P->log.length() >= 0x18) {
						maxMajorStripe = getU2(ccb_P->log.data_P(), 22);
						#ifndef	_DPT_BIG_ENDIAN
							reverseBytes(maxMajorStripe);
						#endif
					}
					if (ccb_P->log.length() >= 0x1e) {
						maxRaidDiskEntries = getU2(ccb_P->log.data_P(), 24);
						maxRaidMemEntries = getU2(ccb_P->log.data_P(), 26);
						#ifndef	_DPT_BIG_ENDIAN
							reverseBytes(maxRaidDiskEntries);
							reverseBytes(maxRaidMemEntries);
						#endif
					}

					// max # arrays of a certain type
					DEBUG(5, "HBA " << PRT_ADDR << "maxArrays=" << (int)ccb_P->log.data_P()[0] << \
								 " maxRaid0=" << (int)ccb_P->log.data_P()[1] << \
								 " maxRaid5=" << (int)ccb_P->log.data_P()[2]);
					break;

				 // Background task exclusion period
				case 15:
					excludeStart = ccb_P->log.data_P()[0];
					excludeEnd = ccb_P->log.data_P()[1];

					// exclusion period stuff
					DEBUG(5, "HBA " << PRT_ADDR << "excludeStart=" << \
					 (int)excludeStart << " excludeEnd=" <<  (int)excludeEnd);

					break;

			} // end switch()
			// Get the next log parameter
			ccb_P->log.next();
		} // end while()
	} // end if (launchCCB()==MSG_RTN_COMPLETED)

	// Free the CCB
	ccb_P->clrInUse();
} // end if (ccb_P!=NULL)


}
//dptHBA_C::getHWinfo() - end


//Function - dptHBA_C::getNVinfo() - start
//===========================================================================
//Description:
//    This function reads NV information and sets HBA info accordingly.
//---------------------------------------------------------------------------

void    dptHBA_C::getNVinfo()
{

engCCB_C *ccb_P = getCCB();
if (ccb_P != NULL) {
	// Attempt to read the contents of the NV RAM
	ccb_P->modeSense(0x2e);
	ccb_P->target(this);
	if (launchCCB(ccb_P) == MSG_RTN_COMPLETED) {
		// If manual JBOD...
		if (ccb_P->modeParam_P->getData()[0x31] & 0x01) {
			hbaFlags2 |= FLG_HBA_MANUAL_JBOD_ACTIVE;
		}
		// If wolfpack cluster mode...
		if (ccb_P->modeParam_P->getData()[0x30] & 0x08) {
			hbaFlags2 |= FLG_HBA_CLUSTER_MODE;
		}
	}

	// Free the CCB
	ccb_P->clrInUse();
}

}
//dptHBA_C::getNVinfo() - end


//Function - dptHBA_C::updateChannelInfo() - start
//===========================================================================
//
//Description:
//
//    This function updates the specified SCSI channel info.
//
//---------------------------------------------------------------------------

void    dptHBA_C::updateChannelInfo(dptSCSIlog_C *log)
{  
	// Get the length of the log parameter                 
	uCHAR length = log->length();

	uCHAR *data_P = log->data_P();

	uSHORT chanIndex = (uSHORT) (*data_P & 0x7);
	if (chanIndex < MAX_NUM_CHANS) {
		if (chanIndex > phyRange.getMaxChan())
			phyRange.setMaxChan((uCHAR)chanIndex);

		// Set the channels flags
		chanInfo[chanIndex].flags = *(data_P+1);
		// If there is another byte of flags, get it
		if(length > 2)
			chanInfo[chanIndex].flags += (*(data_P+2) << 8);
		// If the channel info has SCAM info, get it
		if(length > 4)
		{
			chanInfo[chanIndex].scamIdMap = *(data_P+4) << 8;
			chanInfo[chanIndex].scamIdMap += *(data_P+5);
		}
		// Make the invalid subsystem status flag a valid flag
		chanInfo[chanIndex].flags ^= FLG_CHAN_SUBSYS_VALID;

		// If ultra 80
		if (chanInfo[chanIndex].flags & FLG_CHAN_ULTRA_80)
			// Set the bus speed
			chanInfo[chanIndex].scsiBusSpeed = 80;
		// If ultra 
		else if (chanInfo[chanIndex].flags & FLG_CHAN_ULTRA_40)
			// Set the bus speed
			chanInfo[chanIndex].scsiBusSpeed = 40;
		// If ultra 40
		else if (chanInfo[chanIndex].flags & FLG_CHAN_ULTRA)
			// Set the bus speed
			chanInfo[chanIndex].scsiBusSpeed = 20;
		else
			// Initialize the SCSI bus speed
			chanInfo[chanIndex].scsiBusSpeed = 10;


		// If 16 bit wide SCSI...
		if (chanInfo[chanIndex].flags & FLG_CHAN_WIDE_16) {
			// Double the SCSI bus speed
			chanInfo[chanIndex].scsiBusSpeed <<= 1;
			// Set the maximum SCSI ID for this channel
			phyRange.setMaxId((uCHAR)chanIndex, 15);
		}

		// If limited due to an external SCSI cable...
		if (chanInfo[chanIndex].flags & FLG_CHAN_EXTERNAL)
			// Halve the bus speed
			chanInfo[chanIndex].scsiBusSpeed >>= 1;

		if (chanInfo[chanIndex].flags & FLG_CHAN_FIBRE) {
			// Set the maximum SCSI ID for this channel
			phyRange.setMaxId((uCHAR)chanIndex, 127);
			chanInfo[chanIndex].scsiBusSpeed = 100;
		}

		if (chanIndex == 0)
			scsiBusSpeed = chanInfo[chanIndex].scsiBusSpeed;

		// get the SCSI ID of the HBA for this channel
		engCCB_C *ccb_P = getCCB();
		if(ccb_P) {
			ccb_P->target(this);
			// Get the firmware information page (vital product data page 0xc1 has the read config in it)
			ccb_P->inquiry(0xc1);
			if (launchCCB(ccb_P)==MSG_RTN_COMPLETED) {
				if (ccb_P->ok()) {
					// pull out the hba SCSI id for this channel
					eataRdConfig_S *rdCfg_P = (eataRdConfig_S *) ccb_P->defData;
					chanInfo[chanIndex].hbaID = rdCfg_P->getScsiIDs()[3-chanIndex];
				}
			}
			// Free the CCB
			ccb_P->clrInUse();
		}
	}
}
//dptHBA_C::updateChannelInfo() - end


//Function - dptHBA_C::checkForRAID() - start
//===========================================================================
//
//Description:
//
//    This function checks to see if the HBA responds to RAID commands.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

void    dptHBA_C::checkForRAID()
{

  // Clear the FW RAID support flag
flags   &= ~FLG_HBA_RAID_FW;

  // If a RAID module && a cache module or an I2O HBA...
if ((isRAIDmodule() && is512kCache()) || isI2O()) {
   engCCB_C *ccb_P = getCCB();
   if (ccb_P!=NULL) {
	if (isI2O())
		  // Set the FW RAID support flag
		flags |= FLG_HBA_RAID_FW;
	else {
		// Initialize the CCB to get the physical array page
		 ccb_P->modeSense(0x2a);
		// Target this HBA
		 ccb_P->target(this);
		// Indicate that this is a RAID command
		 ccb_P->setRAIDcmd();
		// Send the CCB to hardware
		 if (launchCCB(ccb_P)==MSG_RTN_COMPLETED) {
			   // Insure the proper mode page was returned
			 if ((ccb_P->modeParam_P->getPageCode() & 0x3f)==0x2a)
				  // Set the FW RAID support flag
				flags |= FLG_HBA_RAID_FW;
		 }
	 }

	// If firmware version 7.C1 or higher...
	if ((memcmp(descr.revision,"07C0",4) > 0) || isI2O())
		// Use the new logical array page (mode page 0x30)
		lapPage = LAP_DPT2;
	// if this is the special SNI version of FW use LAP 1
	else if (memcmp(descr.revision, "0UX2", 4) == 0)
		lapPage = LAP_DPT1;
	// its <= 7c0 use lap1
	else
		lapPage = LAP_DPT1;

	// Re-initialize the CCB
	 ccb_P->reInit();
	// Initialize the CCB to perform a SCSI inquiry
	 ccb_P->inquiry(0xc0);
	// Target this HBA
	 ccb_P->target(this);
	// Send the CCB to hardware
	 if (launchCCB(ccb_P)==MSG_RTN_COMPLETED) {
	   // If RAID-3 is not supported...
	 if (!(ccb_P->defData[12] & 0x08)) {
		 // Clear the RAID 3 support flag
	    raidSupport &= ~FLG_RAID_3;
	    if (getRAIDtdef(3)!=NULL)
		  raidDefList.del();
	 }
	 }

	// Free the CCB
	 ccb_P->clrInUse();
   }
}

}
//dptHBA_C::checkForRAID() - end


//Function - dptHBA_C::handleMessage() - start
//===========================================================================
//
//Description:
//
//    This routine handles DPT events for the dptRAIDmgr_C class.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::handleMessage(DPT_MSG_T   message,
										dptBuffer_S *fromEng_P,
										dptBuffer_S *toEng_P
									   )
{

	DPT_RTN_T    retVal = MSG_RTN_IGNORED;

	switch (message) {

		// Turns the HBA's alarm on
		case MSG_ALARM_ON:
			if (isRAIDmodule())
				retVal = sendMFC(MFC_ALARM_ON);
			break;

		// Turns the HBA's alarm off
		case MSG_ALARM_OFF:
			if (isRAIDmodule())
				retVal = sendMFC(MFC_ALARM_OFF);
			break;

		// Stops all activity on this HBA so that a physical device may
		// be changed.
		case MSG_QUIET:
			retVal = quietBus(toEng_P);
			break;

		// Resumes activity on this HBA after a quiet command has been issued
		case MSG_UNQUIET:
			retVal = sendMFC(MFC_UNQUIET);
			break;

		// Re-reads the RAID tables on the drives and configures the system
		// accordingly.
		case MSG_RELOCK_DRIVES:
			retVal = sendMFC(MFC_READ_RAID_TBL);
			break;

		// Update the HBA's status
		case MSG_UPDATE_STATUS:
			retVal = updateStatus(fromEng_P);
			break;

		// Get the HBA's time
		case MSG_GET_TIME:
			retVal = getTime(fromEng_P);
			break;

		// Set the HBA's time
		case MSG_SET_TIME:
			retVal = setTime(toEng_P);
			break;

		// Return the HBA's event log
		case MSG_LOG_READ:
			retVal = rtnEventLog(toEng_P,fromEng_P);
			break;

		// Clear the HBA event log
		case MSG_LOG_CLEAR:
			retVal = clearEventLog();
			break;

		// Set the HBA event log control word
		case MSG_LOG_SET_HBA_FILTER:
			retVal = setEventCtl(toEng_P);
			break;

		// Return global HBA read/write statistics information
		case MSG_GET_IO_STATS:
			retVal = rtnIOstats(fromEng_P,1);
			break;

		// Clear global HBA read/write statistics information
		case MSG_CLEAR_IO_STATS:
			retVal = rtnIOstats(NULL,0);
			break;

		// Return HBA specific statistics information
		case MSG_GET_HBA_STATS:
			retVal = rtnHBAstats(fromEng_P,1);
			break;

		// Clear HBA specific statistics information
		case MSG_CLEAR_HBA_STATS:
			retVal = rtnHBAstats(NULL,0);
			break;

		// Set an HBA data field to a specified value
		case MSG_SET_INFO:
			retVal = setDataField(toEng_P);
			break;

		// Return the contents of the HBA's NV RAM
		case MSG_GET_NV_INFO:
			retVal = readNV_RAM(fromEng_P);
			break;

		// Write the contents of the HBA's NV RAM
		case MSG_SET_NV_INFO:
			retVal = writeNV_RAM(toEng_P);
			break;

		// Attempts to switch from operational mode into flash mode
		case MSG_FLASH_SWITCH_INTO:
			retVal = flashSwitchInto();
			break;

		// Attempts to switch from flash mode into operational mode
		case MSG_FLASH_SWITCH_OUT_OF:
			// If a non-zero input byte was specified...
			if ((toEng_P->writeIndex) && *toEng_P->data)
				// Skip the flash checksum test
				retVal = flashSwitchOutOf(1);
			else
				// Perform the flash checksum test
				retVal = flashSwitchOutOf(0);
			break;

		// Writes to the HBA's flash memory
		case MSG_FLASH_WRITE:
			retVal = flashWrite(toEng_P);
			break;

		// Writes to the HBA's flash memory without verification
		case MSG_FLASH_WR_NO_VERIFY:
			retVal = flashWrite(toEng_P,0);
			break;

		// Causes F/W to compute flash memory checksums...
		case MSG_FLASH_WRITE_DONE:
			if ((toEng_P->writeIndex) && *toEng_P->data)
				// Skip the flash checksum test
				retVal = flashWriteDone(0);
			else
				retVal = flashWriteDone(1);
			break;

		// Reads from the HBA's flash memory
		case MSG_FLASH_READ:
			retVal = flashRead(toEng_P,fromEng_P);
			break;

		// Returns detailed status information about the HBA's flash memory
		case MSG_FLASH_STATUS:
			retVal = flashStatus(fromEng_P);
			break;

		// Sets the region offset to be flashed
		case MSG_FLASH_SET_REGION:
			retVal = flashSetRegion(toEng_P);
			break;


		// Sets the HBA's exclusion period (no diags, rebuilds, verifies)
		case MSG_DIAG_EXCLUDE:
			// If F/W diagnostics are supported
			if (isFWdiagCapable())
				retVal = setExclusion(toEng_P);
			break;

		// Return the HBA's array limits
		case MSG_RAID_GET_LIMITS:
			retVal = getArrayLimits(fromEng_P);
			break;

		//dz
		case MSG_STATS_LOG_READ:
		case MSG_STATS_LOG_CLEAR:
		case MSG_STATS_LOG_GET_STATUS:
		case MSG_STATS_LOG_SET_STATUS:
			// Send to the statistics logger
			retVal = osdLoggerCmd(message,
								  (void*)toEng_P,
								  (dptData_S*)fromEng_P,
								  (uSHORT)myConn_P()->getIOmethod(),
								  0,
								  (uLONG)getRAIDid());
			break;

		case MSG_SET_ACCESS_RIGHTS:
			retVal = SetAccessRights(fromEng_P, toEng_P);
			break;

		case MSG_GET_ACCESS_RIGHTS:
			retVal = GetAccessRights(fromEng_P);
			break;

		case MSG_GET_ENVIRON_INFO:
			retVal = GetEnvironInfo(fromEng_P);
			break;

		case MSG_SET_ENVIRON_INFO:
			retVal = SetEnvironInfo(toEng_P);
			break;

		// Get backup battery info
		case MSG_GET_BATTERY_INFO:
			retVal = getBatteryInfo(toEng_P, fromEng_P);
			break;

		// Set backup battery thresholds
		case MSG_SET_BATTERY_THRESHOLDS:
			retVal = setBatteryThresholds(toEng_P);
			break;

		// Calibrate the backup battery
		case MSG_CALIBRATE_BATTERY:
			retVal = calibrateBattery(toEng_P);
			break;

		// Perform a DMA test on the controller
		case MSG_I2O_DMA_TEST:
			retVal = i2oDiagTest(toEng_P,fromEng_P, 0x07);
			break;

		// Perform a RAM test on the controller
		case MSG_I2O_RAM_TEST:
			retVal = i2oDiagTest(toEng_P,fromEng_P, 0x06);
			break;

		// Initiate the controller's built-in-self-test
		case MSG_I2O_BIST:
			retVal = i2oDiagTest(toEng_P,fromEng_P, 0x08);
			break;

		// Initialize the device busy logic
		case MSG_CHECK_BUSY:
			retVal = initBusyLogic(fromEng_P);
			break;

		// Set the array drive size table
		case MSG_SET_ARRAY_DRIVE_SIZES:
			retVal = setArrayDriveSizeTable(toEng_P);
			break;

		// Return the array drive size table
		case MSG_GET_ARRAY_DRIVE_SIZES:
			retVal = getArrayDriveSizeTable(fromEng_P);
			break;

		// Return the array drive size table
		case MSG_I2O_RESYNC:
			retVal = resetHba(toEng_P);
			break;

		// Send an I2O pass-through message
		case MSG_I2O_SEND_MESSAGE:
			retVal = sendI2OMessage(fromEng_P, toEng_P);
			break;

		// Return detailed channel information
		case MSG_GET_CHAN_INFO:
			retVal = getChanInfo(fromEng_P);
			break;

		default:
			// Call base class event handler
			retVal = dptRAIDhba_C::handleMessage(message,fromEng_P,toEng_P);
			break;

	} // end switch

return (retVal);

}
//dptHBA_C::handleMessage() - end


//Function - dptHBA_C::getChanInfo() - start
//===========================================================================
//   This function returns detailed information about each I/O channel/
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::getChanInfo(dptBuffer_S *fromEng_P)
{

	DPT_RTN_T               retVal = MSG_RTN_FAILED | ERR_GET_CCB;

  // Get a CCB
engCCB_C *ccb_P = getCCB();
if (ccb_P!=NULL) {

	uCHAR	hbaId_A[4];
	dptChanInfo2_S	rtnInfo;

	// Read NVRAM to get the HBA ID for each channel
	ccb_P->modeSense(0x2e);
	ccb_P->target(this);
	retVal = launchCCB(ccb_P);
	if (retVal == MSG_RTN_COMPLETED) {
		hbaId_A[0] = ccb_P->modeParam_P->getData()[0x08];
		hbaId_A[1] = ccb_P->modeParam_P->getData()[0x09];
		hbaId_A[2] = ccb_P->modeParam_P->getData()[0x0a];
		hbaId_A[3] = ccb_P->modeParam_P->getData()[0x19];


		ccb_P->reInit();

		// Get log page 0x33
		ccb_P->logSense(0x33,0,0xff);
		ccb_P->target(this);
		retVal = launchCCB(ccb_P);
		if (retVal ==MSG_RTN_COMPLETED) {
			uLONG numChannels = 0;
			uLONG *numChannels_P = (uLONG *) fromEng_P->data;
			fromEng_P->insert(numChannels);

			ccb_P->initLogSense();
			while (ccb_P->log.isValidParam()) {
				if (ccb_P->log.code() == 0x0d) {
					numChannels++;
					memset(&rtnInfo, 0, sizeof(dptChanInfo2_S));
					rtnInfo.chanNum = ccb_P->log.data_P()[0];
					rtnInfo.length = sizeof(dptChanInfo2_S);
					rtnInfo.pc13Flags1 = ccb_P->log.data_P()[1];
					rtnInfo.pc13Flags2 = ccb_P->log.data_P()[2];
					rtnInfo.pc13Speed = ccb_P->log.data_P()[3];
					rtnInfo.pc13ScamIdMap1 = ccb_P->log.data_P()[4];
					rtnInfo.pc13ScamIdMap2 = ccb_P->log.data_P()[5];
					if (ccb_P->log.length() >= 8) {
						rtnInfo.pc13Flags3 = ccb_P->log.data_P()[6];
						rtnInfo.pc13Flags4 = ccb_P->log.data_P()[7];
					}
					if (rtnInfo.chanNum < 4) {
						rtnInfo.hbaId = hbaId_A[rtnInfo.chanNum];
						rtnInfo.maxXfrSpeed = chanInfo[rtnInfo.chanNum].scsiBusSpeed;
						if (rtnInfo.pc13Flags4 & FLG_CHAN2_ULTR320) {
							rtnInfo.maxXfrSpeed = 640;
						}
						else if (rtnInfo.pc13Flags4 & FLG_CHAN2_ULTR160) {
							rtnInfo.maxXfrSpeed = 320;
						}
					}

					if (!fromEng_P->insert(&rtnInfo, sizeof(dptChanInfo2_S))) {
						retVal = MSG_RTN_DATA_OVERFLOW;
					}
				}
				// Get the next log parameter
				ccb_P->log.next();
			}

			*numChannels_P = numChannels;
		}
	} // end if (launchCCB())


	// Free the CCB
   ccb_P->clrInUse();
} // end if (ccb_P!=NULL)

return(retVal);

}
//dptHBA_C::getChanInfo() - end


//Function - dptHBA_C::resetHba() - start
//===========================================================================
//Description:
//   This function attempts to reset the HBA
//---------------------------------------------------------------------------

DPT_RTN_T dptHBA_C::sendI2OMessage(dptBuffer_S *fromEng_P, dptBuffer_S *toEng_P)
{

	DPT_RTN_T	retVal = MSG_RTN_IGNORED;

	//fromEng_P->data
	//toEng_P->data

	return retVal;
}
//dptHBA_C::sendI2OMessage() - end


//Function - dptHBA_C::resetHba() - start
//===========================================================================
//Description:
//   This function attempts to reset the HBA
//---------------------------------------------------------------------------

DPT_RTN_T dptHBA_C::resetHba(dptBuffer_S *toEng_P)
{

	DPT_RTN_T	retVal = MSG_RTN_IGNORED;

	if (isI2O()) {
		uLONG	rescanFlags = 0;
		retVal = MSG_RTN_DATA_UNDERFLOW;
		if (toEng_P->extract(rescanFlags)) {
			retVal = osdRescan(getDrvrNum(), rescanFlags);
			if (retVal != MSG_RTN_IGNORED) {
				  // Get a CCB
				engCCB_C *ccb_P = getCCB();
				if (ccb_P==NULL)
					retVal = ERR_GET_CCB;
				else {

					// Get the inquiry data
					ccb_P->inquiry();
					ccb_P->target(this);
					if (launchCCB(ccb_P)==MSG_RTN_COMPLETED) {
						inquiryInit((sdInquiry_S *)ccb_P->defData);
					}
					ccb_P->clrInUse();

					// Get the H/W page etc.
					realInit();
				}
			}
		}
	}

	return (retVal);

}
//dptHBA_C::resetHba()


//Function - dptHBA_C::setArrayDriveSizeTable() - start
//===========================================================================
//Description:
//   This function sets the array drive size table.
//---------------------------------------------------------------------------

DPT_RTN_T dptHBA_C::setArrayDriveSizeTable(dptBuffer_S *toEng_P)
{


DPT_RTN_T	retVal = MSG_RTN_COMPLETED;
uLONG		saveTable = 0;
uLONG		numEntries = 0;

toEng_P->extract(saveTable);
if (!toEng_P->extract(numEntries))
	retVal = MSG_RTN_DATA_UNDERFLOW;
else if (((numEntries<<2)+8) > toEng_P->writeIndex)
	retVal = MSG_RTN_DATA_UNDERFLOW;
else if (numEntries > MAX_DRIVE_SIZE_ENTRIES)
	retVal = ERR_DRIVE_SIZE_TABLE_MAX;
else {
	if (driveSizeTable_P != NULL) {
		if (numEntries > driveSizeTable_P->getMaxEntries()) {
			retVal = ERR_DRIVE_SIZE_TABLE_MAX;
		}
	}
	if (retVal == MSG_RTN_COMPLETED) {
		driveSizeTable_S *ds_P = (driveSizeTable_S *) toEng_P->data;
		if (driveSizeTable_P != NULL) {
			ds_P->setMaxEntries(driveSizeTable_P->getMaxEntries());
		}
		else {
			ds_P->setMaxEntries(MAX_DRIVE_SIZE_ENTRIES);
		}
		useDriveSizeTable(ds_P);
		if (saveTable) {
			retVal = writeDriveSizeTable();
		}
	}
}

return (retVal);

}
//dptHBA_C::setArrayDriveSizeTable()


//Function - dptHBA_C::getArrayDriveSizeTable() - start
//===========================================================================
//Description:
//   This function returns the array drive size table.
//---------------------------------------------------------------------------

DPT_RTN_T dptHBA_C::getArrayDriveSizeTable(dptBuffer_S *fromEng_P)
{


DPT_RTN_T	retVal = MSG_RTN_COMPLETED;
uLONG		maxEntries = 0;
uLONG		numEntries = 0;

if (driveSizeTable_P == NULL) {
	fromEng_P->insert(maxEntries);
	if (!fromEng_P->insert(numEntries)) {
		retVal = MSG_RTN_DATA_OVERFLOW;
	}
}
else {
	if (!fromEng_P->insert(driveSizeTable_P, 8+(driveSizeTable_P->getNumEntries()<<2))) {
		retVal = MSG_RTN_DATA_OVERFLOW;
	}
}

return (retVal);

}
//dptHBA_C::getArrayDriveSizeTable()


//Function - dptHBA_C::initBusyLogic() - start
//===========================================================================
//Description:
//   This function initializes the device busy checking code.
//---------------------------------------------------------------------------

DPT_RTN_T dptHBA_C::initBusyLogic(dptBuffer_S *fromEng_P)
{


DPT_RTN_T retVal = MSG_RTN_IGNORED;

uLONG busyStatus = osdTargetBusy(0, 0, 0, 0);
if (busyStatus & 0x80000000) {
	retVal = ERR_BUSY_CHECK_FAILED;
}
else if (busyStatus != 2) {
	retVal =  (fromEng_P->insert(busyStatus)) ? MSG_RTN_COMPLETED : MSG_RTN_DATA_OVERFLOW;
}

return (retVal);

}
//dptHBA_C::initBusyLogic()


//Function - dptHBA_C::i2oDiagTest() - start
//===========================================================================
//Description:
//   This function starts a commanded diagnostic on an I2O controller.
//---------------------------------------------------------------------------

DPT_RTN_T dptHBA_C::i2oDiagTest(dptBuffer_S *toEng_P, dptBuffer_S *fromEng_P, uSHORT fnCode)
{


DPT_RTN_T retVal = MSG_RTN_IGNORED;

if (isI2O()) {
	uLONG rtnSize = 0;

	retVal = ERR_MEM_ALLOC;
	char *buff_P = new char[4096];
	if (buff_P) {
		retVal = MSG_RTN_IGNORED;
		// Inititialize the message and data pointers
		memset(buff_P, 0, 4096);
		PRIVATE_SCSI_SCB_EXECUTE_MESSAGE *request_P = (PRIVATE_SCSI_SCB_EXECUTE_MESSAGE *)buff_P;
		I2O_SINGLE_REPLY_MESSAGE_FRAME *reply_P = (I2O_SINGLE_REPLY_MESSAGE_FRAME *) (buff_P + 1024);
		char *data_P = buff_P + 2048;

		// Initialize the request message to issue a DPT private SCSI command
		if (fnCode == 7) {
			if (toEng_P->allocSize < 516)
				retVal = MSG_RTN_DATA_UNDERFLOW;
			else if (fromEng_P->allocSize < 536)
				retVal = MSG_RTN_DATA_OVERFLOW;
			else
				i2oInitDmaTest(buff_P, (char *)toEng_P->data+4, (char *)fromEng_P->data);
		}
		else
			i2oInitPrivateScsi(buff_P, 0x01, 2048, data_P);

		if (!fnCode) {
			request_P->CDBLength = 6;
			request_P->CDB[0] = 0x12;
			request_P->CDB[4] = 0xff;
		}
		else if (retVal == MSG_RTN_IGNORED) {
			request_P->CDBLength = 16;
			request_P->CDB[0] = 0xc2;
			request_P->CDB[2] = 0x01; // Function version
			request_P->CDB[3] = 0x01; // Function category = hardware
			setU2(request_P->CDB, 4, fnCode); // Function code
			#ifndef      _DPT_BIG_ENDIAN
				osdSwap2((uSHORT *)(request_P->CDB+4));
			#endif

			// If DMA test...
			if (fnCode == 0x07) {
				rtnSize = 0;
				uCHAR tempFlags = 0;
				uCHAR defFlags = 0;
				uCHAR defSourceByte = 0xaa;
				uCHAR defDestByte = 0x55;

				toEng_P->extract(tempFlags);
				toEng_P->extract(defFlags);
				toEng_P->extract(defSourceByte);
				toEng_P->extract(defDestByte);

				// Copy the "source data" if specified
				if (toEng_P->skip(512))
					defFlags &= ~0x01;
				// Copy the "destination data" if specified
				if (toEng_P->extract(fromEng_P->data+8, 512))
					defFlags &= ~0x02;

				// If the "source data" should be set to a specified value...
				if (defFlags & 0x01)
					memset(toEng_P->data+4, defSourceByte, 512);
				// If the "destination data" should be set to a specified value...
				if (defFlags & 0x02)
					memset(fromEng_P->data+8, defDestByte, 512);

				memset(fromEng_P->data, 0x00, 8); // Initial the CQC header to zero
				memset(fromEng_P->data+520, 0x00, 16); // Initial teh ECC data to zero

				request_P->CDB[14] = tempFlags;
			}
			// If RAM test...
			else if (fnCode == 0x06) {
				rtnSize = 16;
				uCHAR tempFlags = 0;
				if (!toEng_P->extract(tempFlags))
					retVal = MSG_RTN_DATA_UNDERFLOW;
				else 
					request_P->CDB[6] = tempFlags;
			}
			// BIST test...
			else if (fnCode == 0x08) {
				rtnSize = 4;
			}
		}

		if (retVal == MSG_RTN_IGNORED) {
			retVal = osdSendMessage(drvrRefNum, (I2O_MESSAGE_FRAME *) request_P, (I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME *) reply_P);
			if (retVal == MSG_RTN_COMPLETED) {
				if (I2O_SINGLE_REPLY_MESSAGE_FRAME_getReqStatus(reply_P) == I2O_REPLY_STATUS_SUCCESS) {
					if (fnCode == 7) {
						fromEng_P->setExtractSize(536);
					}
					else if (fnCode) {
						if (!fromEng_P->insert(data_P+8, rtnSize))
							retVal = MSG_RTN_DATA_OVERFLOW;
					}
					else if (!fromEng_P->insert(data_P, 64)) {
						retVal = MSG_RTN_DATA_OVERFLOW;
					}
				}
				else
					retVal = ERR_I2O_REPLY_FAILURE;
			}
		}

		delete[] buff_P;
	} // (buff_P != NULL)
} // end if (isI2O())

return (retVal);

}
//dptHBA_C::i2oDiagTest()


//Function - dptHBA_C::i2oInitPrivateScsi() - start
//===========================================================================
//Description:
//   This function initializes an I2O request message to send a DPT
//private SCSI pass-through command.
//---------------------------------------------------------------------------

void dptHBA_C::i2oInitPrivateScsi(char *buff_P,
								  uLONG dataDir,
								  uLONG dataSize,
								  char *data_P)
{
	PRIVATE_SCSI_SCB_EXECUTE_MESSAGE *privScsi_P = (PRIVATE_SCSI_SCB_EXECUTE_MESSAGE *) buff_P;
	I2O_PRIVATE_MESSAGE_FRAME *privI2o_P = &privScsi_P->PrivateMessageFrame;
	I2O_MESSAGE_FRAME *i2oMsg_P = &privI2o_P->StdMessageFrame;
	uCHAR versionOffset = 0x01;

	// Initialize the request message to perform a DPT private SCSI command
	I2O_MESSAGE_FRAME_setFunction(i2oMsg_P, I2O_PRIVATE_MESSAGE);
	I2O_MESSAGE_FRAME_setInitiatorAddress(i2oMsg_P, 0x01);

	PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setSCBFlags(privScsi_P, I2O_SCB_FLAG_SENSE_DATA_IN_MESSAGE | I2O_SCB_FLAG_ENABLE_DISCONNECT);

	I2O_PRIVATE_MESSAGE_FRAME_setXFunctionCode(privI2o_P, I2O_SCSI_SCB_EXEC);
	I2O_PRIVATE_MESSAGE_FRAME_setOrganizationID(privI2o_P, DPT_ORGANIZATION_ID);

	PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setInterpret(privScsi_P, 0x01);

	uLONG msgSize = sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE) - sizeof(I2O_SG_ELEMENT) - 4;
	if (dataDir) {
		msgSize += 4; // "ByteCount" field

		versionOffset |= (msgSize << 2) & 0xf0;

		I2O_SGE_SIMPLE_ELEMENT *sg_P = (I2O_SGE_SIMPLE_ELEMENT *)(buff_P + msgSize);
		I2O_FLAGS_COUNT *flagsCount_P = &sg_P->FlagsCount;
		if (dataDir == 1) { // data in
			I2O_FLAGS_COUNT_setFlags(flagsCount_P, (I2O_SGL_FLAGS_LAST_ELEMENT | I2O_SGL_FLAGS_END_OF_BUFFER | I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT));
			uSHORT scbFlags = PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_getSCBFlags(privScsi_P);
			PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setSCBFlags(privScsi_P, scbFlags | I2O_SCB_FLAG_XFER_FROM_DEVICE);
		}
		else { // data out
			I2O_FLAGS_COUNT_setFlags(flagsCount_P, (I2O_SGL_FLAGS_LAST_ELEMENT | I2O_SGL_FLAGS_END_OF_BUFFER | I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT | I2O_SGL_FLAGS_DIR));
			uSHORT scbFlags = PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_getSCBFlags(privScsi_P);
			PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setSCBFlags(privScsi_P, scbFlags | I2O_SCB_FLAG_XFER_TO_DEVICE);
		}
		I2O_FLAGS_COUNT_setCount(flagsCount_P,  dataSize);
		I2O_SGE_SIMPLE_ELEMENT_setPhysicalAddress(sg_P, (uLONG) data_P);

		PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setByteCount(privScsi_P, dataSize);
		msgSize += sizeof(I2O_SGE_SIMPLE_ELEMENT); // SG element

	}
	I2O_MESSAGE_FRAME_setMessageSize(i2oMsg_P, (uSHORT)(msgSize >> 2));

	I2O_MESSAGE_FRAME_setVersionOffset(i2oMsg_P, versionOffset);

	return;

}
//dptHBA_C::i2oInitPrivateScsi() - end


//Function - dptHBA_C::i2oInitDmaTest() - start
//===========================================================================
//Description:
//   This function initializes an I2O request message to send a DPT
//private SCSI pass-through command.
//---------------------------------------------------------------------------

void dptHBA_C::i2oInitDmaTest(char *buff_P, char *source_P, char *dest_P)
{
	PRIVATE_SCSI_SCB_EXECUTE_MESSAGE *privScsi_P = (PRIVATE_SCSI_SCB_EXECUTE_MESSAGE *) buff_P;
	I2O_PRIVATE_MESSAGE_FRAME *privI2o_P = &privScsi_P->PrivateMessageFrame;
	I2O_MESSAGE_FRAME *i2oMsg_P = &privI2o_P->StdMessageFrame;
	uCHAR versionOffset = 0x01;

	// Initialize the request message to perform a DPT private SCSI command
	I2O_MESSAGE_FRAME_setFunction(i2oMsg_P, I2O_PRIVATE_MESSAGE);
	I2O_MESSAGE_FRAME_setInitiatorAddress(i2oMsg_P, 0x01);

	PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setSCBFlags(privScsi_P, I2O_SCB_FLAG_SENSE_DATA_IN_MESSAGE | I2O_SCB_FLAG_ENABLE_DISCONNECT);

	I2O_PRIVATE_MESSAGE_FRAME_setXFunctionCode(privI2o_P, I2O_SCSI_SCB_EXEC);
	I2O_PRIVATE_MESSAGE_FRAME_setOrganizationID(privI2o_P, DPT_ORGANIZATION_ID);

	PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setInterpret(privScsi_P, 0x01);

	uLONG msgSize = sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE) - sizeof(I2O_SG_ELEMENT);

	versionOffset |= (msgSize << 2) & 0xf0;

	// Initialize the scatter/gather entry for the source buffer
	I2O_SGE_SIMPLE_ELEMENT *sg_P = (I2O_SGE_SIMPLE_ELEMENT *)(buff_P + msgSize);
	I2O_FLAGS_COUNT *flagsCount_P = &sg_P->FlagsCount;
	I2O_FLAGS_COUNT_setFlags(flagsCount_P, (I2O_SGL_FLAGS_END_OF_BUFFER | I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT | I2O_SGL_FLAGS_DIR));
	uSHORT scbFlags = PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_getSCBFlags(privScsi_P);
	PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setSCBFlags(privScsi_P, scbFlags | I2O_SCB_FLAG_XFER_TO_DEVICE);
	I2O_FLAGS_COUNT_setCount(flagsCount_P,  512);
	I2O_SGE_SIMPLE_ELEMENT_setPhysicalAddress(sg_P, (uLONG) source_P);
	msgSize += sizeof(I2O_SGE_SIMPLE_ELEMENT); // SG element

	// Initialize the scatter/gather entry for the destination buffer
	sg_P = (I2O_SGE_SIMPLE_ELEMENT *)(buff_P + msgSize);
	flagsCount_P = &sg_P->FlagsCount;
	I2O_FLAGS_COUNT_setFlags(flagsCount_P, (I2O_SGL_FLAGS_LAST_ELEMENT | I2O_SGL_FLAGS_END_OF_BUFFER | I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT));
	scbFlags = PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_getSCBFlags(privScsi_P);
	PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setSCBFlags(privScsi_P, scbFlags | I2O_SCB_FLAG_XFER_FROM_DEVICE);
	I2O_FLAGS_COUNT_setCount(flagsCount_P,  536);
	I2O_SGE_SIMPLE_ELEMENT_setPhysicalAddress(sg_P, (uLONG) dest_P);
	msgSize += sizeof(I2O_SGE_SIMPLE_ELEMENT); // SG element

	// Set the byte count to the size of the largest buffer
	PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setByteCount(privScsi_P, 536);

	I2O_MESSAGE_FRAME_setMessageSize(i2oMsg_P, (uSHORT)(msgSize >> 2));

	I2O_MESSAGE_FRAME_setVersionOffset(i2oMsg_P, versionOffset);

	return;

}
//dptHBA_C::i2oInitDmaTest() - end


//Function - dptHBA_C::getBatteryInfo() - start
//===========================================================================
//Description:
//   This function returns the backup battery information structure.
//---------------------------------------------------------------------------

DPT_RTN_T dptHBA_C::getBatteryInfo(dptBuffer_S *toEng_P, dptBuffer_S *fromEng_P)
{


DPT_RTN_T retVal = MSG_RTN_IGNORED;

if (isBatteryUnit()) {
	uCHAR	pageControl = 0;
	uCHAR	pageType = 0;
	if (toEng_P->extract(pageType)) {
		if (pageType)
			pageControl = 0x02; // Default values
	}

	  // Get a CCB
	engCCB_C *ccb_P = getCCB();
	if (ccb_P==NULL)
		retVal = ERR_GET_CCB;
	else {
		// Mode page 0x3A - battery info
		ccb_P->modeSense(0x3A, pageControl);
		// Target this HBA
		ccb_P->target(this);

		// Send the CCB to hardware
		retVal=launchCCB(ccb_P);
		
		if (retVal==MSG_RTN_COMPLETED) {

			uLONG	tempLong = 0;
			uCHAR	tempChar = 0;
			struct tm	*tm_P = NULL;	// pointer to the static structure returned by localtime()

			dptBatteryModePage_S *info_P = (dptBatteryModePage_S *) ccb_P->modeParam_P->getData();
			info_P->scsiSwap();

			tempLong = info_P->getStatus();
			fromEng_P->insert(tempLong);
			tempLong = info_P->getCurrent();
			fromEng_P->insert(tempLong);
			tempLong = info_P->getVoltage();
			fromEng_P->insert(tempLong);
			tempLong = info_P->getDesignCapacity();
			fromEng_P->insert(tempLong);
			tempLong = info_P->getFullChargeCapacity();
			fromEng_P->insert(tempLong);
			tempLong = info_P->getRemainingCapacity();
			fromEng_P->insert(tempLong);
			tempLong = info_P->getRemainingTime();
			fromEng_P->insert(tempLong);
			tempLong = info_P->getMaxRemainingTime();
			fromEng_P->insert(tempLong);
			tempLong = info_P->getTemperature();
			fromEng_P->insert(tempLong);
			tempLong = info_P->getMaintenanceCycleCount();
			fromEng_P->insert(tempLong);
			tempLong = info_P->getHwDesignVersion();
			fromEng_P->insert(tempLong);

			// Manufacture date fields
			tempLong = info_P->getManufactureDate();
			tempChar = (uCHAR) (tempLong & 0x1f);
			fromEng_P->insert(tempChar);	// Day of month
			tempChar = (uCHAR) ((tempLong >> 5) & 0xf);
			fromEng_P->insert(tempChar);	// Month
			tempChar = (uCHAR) ((tempLong >> 9) & 0x7f);
			fromEng_P->insert(tempChar);	// Year (biased by 1980)
			tempChar = info_P->getFlags();
			fromEng_P->insert(tempChar);	// reserved byte

			// Thresholds
			tempLong = info_P->getWriteThruThreshold();
			fromEng_P->insert(tempLong);
			tempLong = info_P->getPredictiveFailureThreshold();
			fromEng_P->insert(tempLong);
			tempLong = 0; // used to be "normal threshold" now it's reserved
			fromEng_P->insert(tempLong);
			tempLong = info_P->getThresholdEnable();
			fromEng_P->insert(tempLong);

			// Date of last maintenance calibration
			tempLong = info_P->getMaintenanceDate();
			if (tempLong) {
				tm_P = localtime((const time_t *)&tempLong);
				if (tm_P == NULL) {
					tempLong = 0;
					fromEng_P->insert(tempLong);
				}
				else {
					tempChar = tm_P->tm_mday;
					fromEng_P->insert(tempChar);	// Day of month
					tempChar = tm_P->tm_mon + 1;
					fromEng_P->insert(tempChar);	// Month
					tempChar = tm_P->tm_year - 80;	// Year is already biased by 1900 so we only need to take out another 80
					fromEng_P->insert(tempChar);	// Year
					tempChar = 0;
					fromEng_P->insert(tempChar);	// reserved byte
				}
			}
			else
				fromEng_P->insert(tempLong);

			// Date of last initial calibration
			tempLong = info_P->getInitialCalibrationDate();
			if (tempLong) {
				tm_P = localtime((const time_t *)&tempLong);
				if (tm_P == NULL) {
					tempLong = 0;
					fromEng_P->insert(tempLong);
				}
				else {
					tempChar = tm_P->tm_mday;
					fromEng_P->insert(tempChar);	// Day of month
					tempChar = tm_P->tm_mon + 1;
					fromEng_P->insert(tempChar);	// Month
					tempChar = tm_P->tm_year - 80;	// Year is already biased by 1900 so we only need to take out another 80
					fromEng_P->insert(tempChar);	// Year
					tempChar = 0;
					fromEng_P->insert(tempChar);	// reserved byte
				}
			}
			else
				fromEng_P->insert(tempLong);

			// ASCII fields
			info_P->getDeviceChemistry()[15] = 0; // ensure NULL terminated
			fromEng_P->insert(info_P->getDeviceChemistry(), 16);
			info_P->getManufacturerName()[15] = 0; // ensure NULL terminated
			fromEng_P->insert(info_P->getManufacturerName(), 16);
			info_P->getDeviceName()[15] = 0; // ensure NULL terminated
			if (!fromEng_P->insert(info_P->getDeviceName(), 16))
				retVal = MSG_RTN_DATA_OVERFLOW;
			else
				retVal = MSG_RTN_COMPLETED;

		} // launchCCB() - end
		// Free the CCB
		ccb_P->clrInUse();
	} // (ccb_P!=NULL)

	return retVal;

} // if (isBatteryUnit())

return (retVal);

}
//dptHBA_C::getBatteryInfo() - end


//Function - dptHBA_C::setBatteryThresholds() - start
//===========================================================================
//Description:
//   This function sets the backup battery threshold levels.
//---------------------------------------------------------------------------

DPT_RTN_T dptHBA_C::setBatteryThresholds(dptBuffer_S *toEng_P)
{


DPT_RTN_T retVal = MSG_RTN_IGNORED;

if (isBatteryUnit()) {
	  // Get a CCB
	engCCB_C *ccb_P = getCCB();
	if (ccb_P==NULL)
		retVal = ERR_GET_CCB;
	else {

		// --- Read the battery info mode page ---

		// Mode page 0x3A - battery info
		ccb_P->modeSense(0x3A);
		// Target this HBA
		ccb_P->target(this);
		// Send the CCB to hardware
		retVal = launchCCB(ccb_P);

		// Send the CCB to hardware
		if (retVal==MSG_RTN_COMPLETED) {

			uLONG	tempLong = 0;

			dptBatteryModePage_S *info_P = (dptBatteryModePage_S *) ccb_P->modeParam_P->getData();

			// --- Write the battery info mode page ---

			memset(ccb_P->eataCP.scsiCDB, 0, 12);
			ccb_P->modeSelect(0x3A, (uSHORT)(dptBatteryModePage_S::size() + 2));
			ccb_P->target(this);

			toEng_P->extract(tempLong);
			info_P->setWriteThruThreshold((uSHORT)tempLong);
			info_P->swapWriteThruThreshold();

			toEng_P->extract(tempLong);
			info_P->setPredictiveFailureThreshold((uSHORT)tempLong);
			info_P->swapPredictiveFailureThreshold();

			toEng_P->extract(tempLong); // reserved

			if (!toEng_P->extract(tempLong))
				retVal = MSG_RTN_DATA_UNDERFLOW;
			else {
				info_P->setThresholdEnable((uSHORT)tempLong);
				info_P->swapThresholdEnable();

				// Send the mode select to hardware
				retVal = launchCCB(ccb_P);
			}

		} // launchCCB() - end

		// Free the CCB
		ccb_P->clrInUse();

	} // (ccb_P!=NULL)

} // end if (ccb_P!=NULL)

return (retVal);

}
//dptHBA_C::setBatteryThresholds() - end


//Function - dptHBA_C::calibrateBattery() - start
//===========================================================================
//Description:
//   This function calibrates the backup battery.
//
// calibrationType = 0, Perform initial calibration (charge, discharge, recharge)
// calibrationType = 1, Perform maintenance calibration (discharge, charge)
//---------------------------------------------------------------------------

DPT_RTN_T dptHBA_C::calibrateBattery(dptBuffer_S *toEng_P)
{

	DPT_RTN_T retVal = MSG_RTN_IGNORED;

	if (isBatteryUnit()) {
		uCHAR	calibrationType = 0;

		// Get the calibration type (initial calibration == 0, maintenance calibration == 1)
		if (!toEng_P->extract(calibrationType))
			retVal = MSG_RTN_DATA_UNDERFLOW;
		else
			retVal = sendMFC(MFC_CALIBRATE_BATTERY, calibrationType);
	}

	return (retVal);

}
//dptHBA_C::calibrateBattery() - end


//Function - dptHBA_C::getBatteryStatus() - start
//===========================================================================
//Description:
//   This function returns the backup battery information structure.
//---------------------------------------------------------------------------

DPT_RTN_T dptHBA_C::getBatteryStatus()
{

DPT_RTN_T retVal = MSG_RTN_IGNORED;

if (isBatteryUnit()) {
	uCHAR	pageControl = 0;
	  // Get a CCB
	engCCB_C *ccb_P = getCCB();
	if (ccb_P==NULL)
		retVal = ERR_GET_CCB;
	else {
		// Mode page 0x3A - battery info
		ccb_P->modeSense(0x3A, pageControl);
		// Target this HBA
		ccb_P->target(this);

		// Send the CCB to hardware
		retVal=launchCCB(ccb_P);
		
		if (retVal==MSG_RTN_COMPLETED) {
			dptBatteryModePage_S *info_P = (dptBatteryModePage_S *) ccb_P->modeParam_P->getData();
			info_P->scsiSwap();

			// Update the battery status and flags
			batteryStatus = info_P->getStatus();
			batteryFlags = info_P->getFlags();

		} // launchCCB() - end

		// Free the CCB
		ccb_P->clrInUse();
	} // (ccb_P!=NULL)

	return retVal;

} // end if (isBatteryUnit)

return (retVal);

}
//dptHBA_C::getBatteryInfo() - end


//Function - dptHBA_C::getArrayLimits() - start
//===========================================================================
//
//Description:
//   This function returns the firmware array limit information
//for this HBA.
//
//---------------------------------------------------------------------------

DPT_RTN_T dptHBA_C::getArrayLimits(dptBuffer_S *fromEng_P)
{

DPT_RTN_T retVal = ERR_GET_CCB;

  // Get a CCB
engCCB_C *ccb_P = getCCB();
if (ccb_P!=NULL) {
   retVal = MSG_RTN_IGNORED;
	// Initialize the CCB to do a log sense page 0x33
	// Limit data buffer to 0xff bytes
   ccb_P->logSense(0x33,0,0xff);
	// Target this HBA
   ccb_P->target(this);
	// Send the CCB to hardware
   if (launchCCB(ccb_P)==MSG_RTN_COMPLETED) {
	// Initialize the log page
	 ccb_P->initLogSense();
	// Find the array limits parameter
	 if (ccb_P->log.find(0x0e)) {
	 if (ccb_P->log.length() >= dptArrayLimits_S::size()) {
		 // Return success
	    retVal = MSG_RTN_COMPLETED;
	    dptArrayLimits_S *limits_P = (dptArrayLimits_S *) ccb_P->log.data_P();
	    limits_P->scsiSwap();
	    if (!fromEng_P->insert(limits_P,dptArrayLimits_S::size()))
		  retVal = MSG_RTN_DATA_OVERFLOW;
	 }
	 else
	    retVal = MSG_RTN_IGNORED;
	 }
   } // end if (launchCCB()==MSG_RTN_COMPLETED)

	// Free the CCB
   ccb_P->clrInUse();
} // end if (ccb_P!=NULL)

return (retVal);

}
//dptHBA_C::getArrayLimits() - end


//Function - dptHBA_C::setExclusion() - start
//===========================================================================
//
//Description:
//
//   This function sets the HBA's background task exclusion period.
//
//---------------------------------------------------------------------------

DPT_RTN_T dptHBA_C::setExclusion(dptBuffer_S *toEng_P)
{

DPT_RTN_T retVal = MSG_RTN_DATA_UNDERFLOW;
uCHAR          startTime,endTime;

toEng_P->extract(startTime);
if (toEng_P->extract(endTime)) {
	// The time cannot be larger than 23 since it is a 24 hour count (0-23)
   if ((startTime >= 24) || (endTime >= 24) || (startTime > endTime))
	 retVal = MSG_RTN_FAILED | ERR_EXCLUSION_TIME;
   else {
	 retVal = sendMFC(MFC_DIAG_EXCLUSION,startTime,endTime);
	 if (retVal == MSG_RTN_COMPLETED) {
	   // Update the HBA's background task exclusion period
	 excludeStart = startTime;
	 excludeEnd = endTime;
	 }
   }
}

return (retVal);

}
//dptHBA_C::setExclusion() - end


//Function - dptHBA_C::readDriveSizeTable() - start
//===========================================================================
//Description:
//    This function reads the drive size table from the controller.
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::readDriveSizeTable()
{

   DPT_RTN_T    retVal = MSG_RTN_FAILED | ERR_GET_CCB;

engCCB_C *ccb_P = getCCB();
if (ccb_P!=NULL) {
	// Read the controller's drive size table
	ccb_P->readDriveSizeTable();
	// Target this HBA
	ccb_P->target(this);
	// Send the CCB to hardware
	retVal = launchCCB(ccb_P);
	if (retVal == MSG_RTN_COMPLETED) {
		driveSizeTable_S *ds_P = (driveSizeTable_S *) ccb_P->dataBuff_P;
		ds_P->swapFromBigEndian();
		useDriveSizeTable(ds_P);
	}

	// Free the CCB
	ccb_P->clrInUse();
}

return (retVal);

}
//dptHBA_C::readDriveSizeTable() - end


//Function - dptHBA_C::writeDriveSizeTable() - start
//===========================================================================
//Description:
//    This function writes the current drive size table to the controller.
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::writeDriveSizeTable()
{

   DPT_RTN_T    retVal = MSG_RTN_FAILED | ERR_NO_DRIVE_SIZE_TABLE;

if (driveSizeTable_P != NULL) {
	retVal = MSG_RTN_FAILED | ERR_GET_CCB;
	engCCB_C *ccb_P = getCCB();
	if (ccb_P!=NULL) {
		uLONG tableSize = 8+(driveSizeTable_P->getNumEntries()<<2);
		// Get the drive size table
		ccb_P->writeDriveSizeTable(tableSize);
		// Target this HBA
		ccb_P->target(this);
		// Copy the current drive size table to the output buffer
		memcpy(ccb_P->dataBuff_P, driveSizeTable_P, tableSize);
		driveSizeTable_S *ds_P = (driveSizeTable_S *) ccb_P->dataBuff_P;
		ds_P->swapToBigEndian();

		// Send the CCB to hardware
		retVal = launchCCB(ccb_P);

		// Free the CCB
		ccb_P->clrInUse();
	}
}

return (retVal);

}
//dptHBA_C::writeDriveSizeTable() - end


//Function - dptHBA_C::useDriveSizeTable() - start
//===========================================================================
//Description:
//    This function sets the current drive size table from the specified
//structure.
//---------------------------------------------------------------------------

void	dptHBA_C::useDriveSizeTable(driveSizeTable_S *ds_P)
{

	DPT_RTN_T    retVal = MSG_RTN_FAILED | ERR_GET_CCB;

	// If a table has not been allocated...
	if (driveSizeTable_P == NULL)
		driveSizeTable_P = (driveSizeTable_S *) new uCHAR[8+(MAX_DRIVE_SIZE_ENTRIES<<2)];

	// Limit the maximum number of entries to the engine's limit
	if (ds_P->getMaxEntries() > MAX_DRIVE_SIZE_ENTRIES)
		ds_P->setMaxEntries(MAX_DRIVE_SIZE_ENTRIES);
	// Limit the current number of entries to the table's limit
	if (ds_P->getNumEntries() > ds_P->getMaxEntries())
		ds_P->setNumEntries(ds_P->getMaxEntries());

	if (driveSizeTable_P) {
		// Clear the entire buffer
		memset(driveSizeTable_P, 0, 8+(MAX_DRIVE_SIZE_ENTRIES<<2));
		// Copy the valid data
		memcpy(driveSizeTable_P, ds_P, 8+(ds_P->getNumEntries()<<2));
	}


}
//dptHBA_C::useDriveSizeTable() - end


//Function - dptHBA_C::sendMFC() - start
//===========================================================================
//
//Description:
//
//    This function sends a RAID multi-function command to this HBA.
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::sendMFC(uCHAR inCmd,uCHAR inModifier,uCHAR inParam)
{

   DPT_RTN_T    retVal = MSG_RTN_FAILED | ERR_GET_CCB;

engCCB_C *ccb_P = getCCB();
if (ccb_P!=NULL) {
	// Initialize the CCB for a DPT multi-function command
   ccb_P->mfCmd(inCmd,inModifier,inParam);
	// Target this HBA
   ccb_P->target(this);
	// Send the CCB to hardware
   retVal = launchCCB(ccb_P);

	// Free the CCB
   ccb_P->clrInUse();
}

return (retVal);

}
//dptHBA_C::sendMFC() - end


//Function - dptHBA_C::sendExtMFC() - start
//===========================================================================
//
//Description:
//
//    This function sends an extended multi-function command to this HBA.
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::sendExtMFC(uCHAR inCmd,uCHAR inModifier,
					uLONG     inParam1,
					uSHORT    inParam2,
					uCHAR     inParam3
				    )
{

   DPT_RTN_T    retVal = MSG_RTN_FAILED | ERR_GET_CCB;

engCCB_C *ccb_P = getCCB();
if (ccb_P!=NULL) {
	// Initialize the CCB for an extended DPT multi-function command
   ccb_P->extMfCmd(inCmd,inModifier,inParam1,inParam2,inParam3);
	// Target this HBA
   ccb_P->target(this);
	// Send the CCB to hardware
   retVal = launchCCB(ccb_P);

	// Free the CCB
   ccb_P->clrInUse();
}

return (retVal);

}
//dptHBA_C::sendExtMFC() - end


//Function - dptHBA_C::updateStatus() - start
//===========================================================================
//
//Description:
//
//    This function updates this HBA's status.
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::updateStatus(dptBuffer_S *fromEng_P)
{

   DPT_RTN_T    retVal = MSG_RTN_IGNORED;
   uSHORT       LEDpattern;

if (isReal()) {
   retVal = MSG_RTN_COMPLETED;
	// If the controller is in a blink LED condition...
   if (osdCheckBLED(getDrvrNum(),&LEDpattern)) {
	 if ((LEDpattern == 0x69) || (LEDpattern == 0x6a)) {
	     // If not previously in flash mode...
	     if (status.main != SMAIN_FLASH_MODE)
	        status.sub = SSUB_FLASH_INIT;
	     status.main = SMAIN_FLASH_MODE;
	     status.display = DSPLY_STAT_WARNING;
	 }
	 else {
	     status.main = SMAIN_BLINK_LED;
	     status.sub = (uCHAR) LEDpattern;
	     status.display = DSPLY_STAT_FAILED;
	 }
   }
   else {
	 retVal = MSG_RTN_FAILED | ERR_GET_CCB;
	 status.main = 0;
	 status.sub = 0;
	 status.display = DSPLY_STAT_OPTIMAL;
	// Get a CCB
	 engCCB_C *ccb_P = getCCB();
	 if (ccb_P!=NULL) {
	   // Initialize the CCB to do a log sense page 0x33
	   // Limit data buffer to 0xff bytes
	 ccb_P->logSense(0x33,0,0xff);
	   // Target this HBA
	 ccb_P->target(this);
	   // Send the CCB to hardware
	 if ((retVal = launchCCB(ccb_P))==MSG_RTN_COMPLETED) {
	    ccb_P->initLogSense();
		 // Find parameter #2
	    if (ccb_P->log.find(0x02)!=NULL) {
			fwFlags = ccb_P->log.data_P()[0];
		}
		 // Find parameter #9
	    if (ccb_P->log.findNext(0x09)!=NULL) {
		 // Determine if the alarm is on or off
		  if (ccb_P->log.data_P()[3] & 0x40)
		    // Indicate that the alarm is on
		  status.flags |= FLG_STAT_ALARM_ON;
		  else
		    // Indicate that the alarm is off
		  status.flags &= ~FLG_STAT_ALARM_ON;
	    }
	    if (ccb_P->log.findNext(0x0c)!=NULL) {
		  hbaFlags2 &= 0xffffff00;
		  hbaFlags2 |= ((uSHORT) ccb_P->log.data_P()[0]) & 0xff;
		 // Make the invalid subsystem status flag a valid flag
		  hbaFlags2 ^= FLG_HBA_SUBSYS_VALID;
	    }
	    uSHORT notCrazy = 10;  // for safety
		 // Update all channel info
	    while ((ccb_P->log.findNext(0x0d)!=NULL) && notCrazy--)
		  updateChannelInfo(&(ccb_P->log));
	    
	    if(hbaFlags2 & FLG_HBA_TEMP_PROBE)
			ccb_P->log.reset();
		 if (ccb_P->log.findNext(0x10)!=NULL) {
			currVoltage = *(uSHORT *)(ccb_P->log.data_P());
			currTemperature = *(uSHORT *)(ccb_P->log.data_P()+2);
			osdSwap2(&currVoltage);
			osdSwap2(&currTemperature);
		 }
	 } // end if (launchCCB())

	   // Free the CCB
	 ccb_P->clrInUse();
	 } // end if (ccb_!=NULL)
   } // end if (!blink LED)

   // Update the battery status
   getBatteryStatus();

	// If returning the status...
   if (fromEng_P != NULL) {
	// If not another type of error...
	 if (!fromEng_P->insert(&status,sizeof(dptStatus_S))) {
	 if (retVal == MSG_RTN_COMPLETED)
	    retVal = MSG_RTN_DATA_OVERFLOW;
	 }
   }
} // end if (isReal())

return (retVal);

}
//dptHBA_C::updateStatus() - end


//Function - dptHBA_C::getTime() - start
//===========================================================================
//
//Description:
//
//    This function reads the time from the HBA.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::getTime(dptBuffer_S *fromEng_P)
{

	DPT_RTN_T               retVal = MSG_RTN_FAILED | ERR_GET_CCB;

  // Get a CCB
engCCB_C *ccb_P = getCCB();
if (ccb_P!=NULL) {
	  // Initialize the CDB to perform a mode sense
	ccb_P->modeSense(0x2f);
	  // Target this HBA
	ccb_P->target(this);
	  // Send the CCB to hardware
	if ((retVal = launchCCB(ccb_P))==MSG_RTN_COMPLETED) {
		uLONG inTime = getU4(ccb_P->modeParam_P->getData(),2);
		reverseBytes(inTime);
		retVal = MSG_RTN_DATA_OVERFLOW;
	 if (fromEng_P->insert(inTime))
	 retVal = MSG_RTN_COMPLETED;
   } // end if (launchCCB())

	// Free the CCB
   ccb_P->clrInUse();
} // end if (ccb_P!=NULL)

return(retVal);

}
//dptHBA_C::getTime() - end


//Function - dptHBA_C::setTime() - start
//===========================================================================
//
//Description:
//
//    This function sets the HBA time.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::setTime(dptBuffer_S *toEng_P)
{

	DPT_RTN_T               retVal = MSG_RTN_DATA_UNDERFLOW;
	uLONG           hbaTime;

  // Get the new time value
if (toEng_P->extract(hbaTime)) {
	retVal = MSG_RTN_FAILED | ERR_GET_CCB;
	  // Get a CCB
	engCCB_C *ccb_P = getCCB();
	if (ccb_P!=NULL) {
	// Zero the data buffer
		ccb_P->clrData();
	// Initialize the CCB to do a mode select page 0x2f
		ccb_P->modeSelect6(0x2f,0x06+2);
	// Target this HBA
		ccb_P->target(this);
	// Set the time
		uLONG *time_P = (uLONG *) (ccb_P->modeParam_P->getData()+2);
		setU4(time_P,0,hbaTime);
		reverseBytes(*time_P);
	// Send the CCB to hardware
		retVal = launchCCB(ccb_P);

	// Free the CCB
		ccb_P->clrInUse();
	} // end if (ccb_P!=NULL)
}

return(retVal);

}
//dptHBA_C::setTime() - end


//Function - dptHBA_C::checkForEmul() - start
//===========================================================================
//
//Description:
//
//    This function checks for emulated drives associated with this HBA.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

void    dptHBA_C::checkForEmul()
{

   uSHORT       done = 0;

dptDevice_C *dev_P = (dptDevice_C *) logList.reset();
while ((dev_P!=NULL) && !done) {
   done = dev_P->checkForEmulation();
   dev_P = (dptDevice_C *) logList.next();
}

}
//dptHBA_C::checkForEmul() - end


//Function - dptHBA_C::getEventCtl() - start
//===========================================================================
//
//Description:
//
//    This function gets the DPT HBA event log control word.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

void    dptHBA_C::getEventCtl()
{

engCCB_C *ccb_P = getCCB();
if (ccb_P!=NULL) {
	  // Initialize the CCB to get the HBA event log control word
	ccb_P->modeSense(0x22,0,0,0x60);
	  // Target this HBA
	ccb_P->target(this);
	if (launchCCB(ccb_P)==MSG_RTN_COMPLETED) {
	// Get the event log control word
		eventLogCtl = getU4(ccb_P->modeParam_P->getData(),0);
	 reverseBytes(eventLogCtl);
   }

	// Free the CCB
   ccb_P->clrInUse();
}

}
//dptHBA_C::getEventCtl() - end


//Function - dptHBA_C::setEventCtl() - start
//===========================================================================
//
//Description:
//
//    This function sets the DPT HBA event log control word.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::setEventCtl(dptBuffer_S *toEng_P)
{

   DPT_RTN_T            retVal = MSG_RTN_DATA_UNDERFLOW;
	uLONG           newEventCtl;
   uCHAR                saveToNV;

  // Get the new event control word
if (toEng_P->extract(newEventCtl)) {
   retVal = MSG_RTN_FAILED | ERR_GET_CCB;
	// Get the save to non-volatile status
   if (!toEng_P->extract(saveToNV))
	 saveToNV = 1;
	// Get a CCB
   engCCB_C *ccb_P = getCCB();
   if (ccb_P!=NULL) {
	// Initialize the CCB to get the HBA event log control word
	 ccb_P->modeSelect(0x22,0x04+2,saveToNV & 0x7f);
	// Target this HBA
	 ccb_P->target(this);
	// Set the event log control word
	 reverseBytes(newEventCtl);
	 setU4(ccb_P->modeParam_P->getData(),0,newEventCtl);
	// Send the mode select to hardware
	 retVal = launchCCB(ccb_P);
	 if (retVal == MSG_RTN_COMPLETED)
		eventLogCtl = newEventCtl;

	// Free the CCB
	 ccb_P->clrInUse();
   }
}

return (retVal);

}
//dptHBA_C::setEventCtl() - end


//Function - dptHBA_C::rtnEventLog() - start
//===========================================================================
//
//Description:
//
//    This function returns the event log for this HBA (non-destructively).
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::rtnEventLog(dptBuffer_S *toEng_P,
					 dptBuffer_S *fromEng_P
					)
{

   DPT_RTN_T            retVal = MSG_RTN_IGNORED;
   uLONG                offset = 0;

if (is512kCache() || isI2O()) {
   if (!toEng_P->extract(offset))
	 offset = 0;

	// Get the event log data - Do not clear the event log
   retVal = doLogSense(fromEng_P,0x34,1,offset,1);

   if (retVal==MSG_RTN_COMPLETED) {
	 dptHBAlog_C               hbaLog;
	// Initialize the HBA log sense data (reverse byte ordering)
	 hbaLog.initSense(fromEng_P->data,1);
   }
}

return (retVal);

}
//dptHBA_C::rtnEventLog() - end


//Function - dptHBA_C::clearEventLog() - start
//===========================================================================
//
//Description:
//
//    This function clears the HBA event log.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::clearEventLog()
{

   DPT_RTN_T    retVal = MSG_RTN_FAILED | ERR_GET_CCB;

engCCB_C *ccb_P = getCCB();
if (ccb_P!=NULL) {
	// Target this HBA
   ccb_P->target(this);
	// Indicate that this is an event logger command
   ccb_P->setLoggerCmd(0);
	// Initialize the CCB to perform a SCSI log sense
   ccb_P->logSense(0x34,0,0xff);
	// Send the CCB to hardware
   retVal = launchCCB(ccb_P);

	// Free the CCB
   ccb_P->clrInUse();
}

return (retVal);

}
//dptHBA_C::clearEventLog() - end


//Function - dptHBA_C::rtnHBAstats() - start
//===========================================================================
//
//Description:
//
//    Return this HBA's global statistics information.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::rtnHBAstats(dptBuffer_S *fromEng_P,
					 uCHAR savePage
					)
{

   DPT_RTN_T    retVal = MSG_RTN_FAILED | ERR_GET_CCB;

engCCB_C *ccb_P = getCCB();
if (ccb_P!=NULL) {
	// Initialize the CCB to get the global statistics page
   ccb_P->logSense(0x30,savePage);
	// Target this HBA
   ccb_P->target(this);
	// Send the CCB to hardware
   if ((retVal = launchCCB(ccb_P))==MSG_RTN_COMPLETED) {
	 if (savePage) {
	 retVal = MSG_RTN_DATA_OVERFLOW;
	 dptHBAstatLog_C        hbaStat;
	   // Initialize the log page data (reverse bytes)
	 hbaStat.initSense(ccb_P->defData,1);
	   // Copy the statistics data to the output buffer
	 if (fromEng_P->insert(hbaStat.data_P(),sizeof(hbaStats_S)))
	    retVal = MSG_RTN_COMPLETED;
	 }
   }
	// Free the CCB
   ccb_P->clrInUse();
}

return (retVal);

}
//dptHBA_C::rtnHBAstats() - end


//Function - dptHBA_C::rtnIOstats() - start
//===========================================================================
//
//Description:
//
//    Return this HBA's global read/write statistics information.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::rtnIOstats(dptBuffer_S *fromEng_P,
					uCHAR savePage
				    )
{

   DPT_RTN_T    retVal = MSG_RTN_DATA_OVERFLOW;

  // If clear stats data...
if (!savePage)
	// Clear the statistics buffer
   retVal = addRWstats(NULL,savePage);
else if (fromEng_P->allocSize>=sizeof(devStats_S)) {
	// Initialize the return statistics to zero
   memset(fromEng_P->data,0,sizeof(devStats_S));
	// Get this device's statistics
   retVal = addRWstats((uLONG *)fromEng_P->data,savePage);
	// Set the buffer's write indexes
   fromEng_P->writeIndex = sizeof(devStats_S);
}

return (retVal);

}
//dptHBA_C::rtnIOstats() - end


//Function - dptHBA_C::delEmulation() - start
//===========================================================================
//
//Description:
//
//    This function deletes all emulated drives associated with this
//HBA.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::delEmulation()
{

   DPT_RTN_T            retVal = MSG_RTN_FAILED | ERR_GET_CCB;
   dptEmulation_S       *emul_P;
   uSHORT               bitTest;
   uSHORT               emulStatus;
   dptAddr_S            devAddr;
   uSHORT               i;
   uCHAR                emulAddrs[8];

engCCB_C *ccb_P = getCCB();
if (ccb_P!=NULL) {
	// Target this HBA
   ccb_P->target(this);
	// Get the emulated drive mode page
   ccb_P->modeSense(0x3d,0,0,0x60);
   if ((retVal=launchCCB(ccb_P))==MSG_RTN_COMPLETED) {
	// Cast the return data as mode
	 emul_P = (dptEmulation_S *) ccb_P->modeParam_P->getData();
	// Save the status byte
	 emulStatus = emul_P->getStatus();
	// If there are any emulated drives...
	 if (emul_P->getStatus() & 0x0f) {
	   // Save the emulated drive SCSI addresses
	 memcpy(emulAddrs,emul_P->getChanID0_P(),8);
	   // Zero the output data buffer
	 ccb_P->clrData();
	 for (bitTest=1,i=0;bitTest<=0x08;bitTest<<=1,i+=2) {
	    if (emulStatus & bitTest) {
		 // Re-initialize the CCB
		  ccb_P->reInit();
		 // Perform an emulated drive page select
		  ccb_P->modeSelect(0x3d,0x10);
		 // Set the emulated drive's SCSI address
		  devAddr.chan     = emulAddrs[i] >> 5;
		  devAddr.id       = emulAddrs[i] & 0x1f;
		  devAddr.lun      = emulAddrs[i+1];
		 // Target the emulated drive address
		  ccb_P->target(devAddr,this,CCB_ORIG_MGR);
		  emul_P->setStatus((uCHAR) bitTest);
		 // Send the CCB to the HBA
		  launchCCB(ccb_P);
	    }
	 }
	 }
   }
	// Free the CCB
   ccb_P->clrInUse();
}

return (retVal);

}
//dptHBA_C::delEmulation() - end


//Function - dptHBA_C::flashWriteInit() - start
//===========================================================================
//
//Description:
//
//    This function performs the required initialization to prepare
//the HBA's flash memory to be programmed.
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::flashWriteInit(engCCB_C *ccb_P)
{

DPT_RTN_T retVal = MSG_RTN_FAILED | ERR_FLASH_SWITCH_MODES;

	updateStatus();
	if (!isFlashMode())
		switchToFlashMode(ccb_P);
	// If in flash mode...
        if (isI2O()) {
		// kmc 10/02/1998 - Initializing to zero here.
		// When using the setregion methods, we have to reset this to 0,
		// or else we get the wrong offsets when sending them down with the
		// flashcmd in ::flashWrite(...)
		flashWriteCnt = 0;
                retVal = MSG_RTN_COMPLETED;
	} else if (isFlashMode()) {
		// Erase the flash
		ccb_P->reInit();
		ccb_P->target(this);

		time_t pre, post;
		time(&pre);
		ccb_P->flashCmd(FLASH_CMD_ERASE);
		if ((retVal = launchCCB(ccb_P)) == MSG_RTN_COMPLETED) {

			flashStablize();

			time(&post);

			dptBuffer_S *inBuffer_P = dptBuffer_S::newBuffer(1024);
			dptBuffer_S *outBuffer_P = dptBuffer_S::newBuffer(1024);

			if (inBuffer_P && outBuffer_P && ((post-pre) > 1)) {
				inBuffer_P->reset();

				retVal += flashStatus(inBuffer_P);
				dptFlashStatus_S *status_P = (dptFlashStatus_S *) &inBuffer_P->data[8];

				uLONG numFlashBytes = status_P->getBurnSize();
				uLONG curRead = 0;

				while(curRead < numFlashBytes) {

					outBuffer_P->reset();
					outBuffer_P->insert(curRead);
					outBuffer_P->insert((uLONG) 512);
					inBuffer_P->reset();

					retVal += flashRead(outBuffer_P,inBuffer_P);

					for(int x = 0; x < 512; x++) {
						if (inBuffer_P->data[x] != 0xff)
							retVal++;
					}
					curRead += 512;
				}

				dptBuffer_S::delBuffer(inBuffer_P);
				dptBuffer_S::delBuffer(outBuffer_P);
			}

		}


		if (retVal)
			retVal = MSG_RTN_FAILED | ERR_FLASH_ERASE;
		else {
			status.sub = SSUB_FLASH_WRITE;
			flashWriteCnt = 0;
			retVal = MSG_RTN_COMPLETED;
		}

	} else
		retVal = MSG_RTN_FAILED | ERR_FLASH_ERASE;

	return (retVal);

}
//dptHBA_C::flashWriteInit() - end


//Function - dptHBA_C::flashWrite() - start
//===========================================================================
//
//Description:
//
//    This function writes the specified data to the next unwritten
//location in the flash memory.
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::flashWrite(dptBuffer_S *toEng_P,uINT verify)
{


DEBUG_BEGIN(1, dptHBA_C::flashWrite());

DPT_RTN_T retVal = MSG_RTN_FAILED | ERR_GET_CCB;

engCCB_C *ccb_P = getCCB();
if (ccb_P!=NULL) {

	// If we're not in flash write mode...
	if (isFlashMode() != SSUB_FLASH_WRITE) {
	// Try to get into flash write mode
	 if ((retVal = flashWriteInit(ccb_P)) != MSG_RTN_COMPLETED)
	 return (retVal);
	// Indicate that we are prepared to write to the flash
	 status.sub = SSUB_FLASH_WRITE;
	}

	retVal = MSG_RTN_DATA_UNDERFLOW;
	if (toEng_P->writeIndex & 0x1ff)
	 retVal = MSG_RTN_FAILED | ERR_FLASH_WRITE_512;
	else {
	 uLONG bytesWritten = 0;
	 while (toEng_P->extract(ccb_P->defData,512)) {
	 ccb_P->reInit();
	 ccb_P->target(this);
	 ccb_P->flashCmd(FLASH_CMD_WRITE,flashWriteCnt + flashRegionOffset);
	 retVal = launchCCB(ccb_P);
	 if (verify && (retVal == MSG_RTN_COMPLETED)) {

		 flashStablize();
		 retVal = MSG_RTN_FAILED | ERR_FLASH_ENG_VERIFY;
		 ccb_P->reInit();
		 ccb_P->target(this);
		 ccb_P->flashCmd(FLASH_CMD_READ,flashWriteCnt + flashRegionOffset);
		 if (launchCCB(ccb_P) == MSG_RTN_COMPLETED) {
		  if (memcmp(toEng_P->data+bytesWritten,ccb_P->defData,512) == 0)
		  retVal = MSG_RTN_COMPLETED;
		 }
	 }
	 flashStablize();
		// If a failure has occurred...
	 if (retVal != MSG_RTN_COMPLETED) {
		 status.sub = SSUB_FLASH_INIT;

	    DEBUG(1, PRT_ADDR << "FLASH FAILURE - retVal=0x" << hex << retVal);

		 break;
	 }
	 bytesWritten += 512;
	 flashWriteCnt += 512;

	 DEBUG(1, PRT_ADDR << PRT_STAT << (int)flashWriteCnt << "Byte written");

	 }
	}

	// Free the CCB
	ccb_P->clrInUse();
}

return (retVal);

}
//dptHBA_C::flashWrite() - end


//Function - dptHBA_C::flashWriteDone() - start
//===========================================================================
//
//Description:
//
//    This function closes out the flash programming process.  This
//function causes the F/W flash code to compute and write the
//flash checksums.
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::flashWriteDone(uCHAR sendToHW)
{

// if SM has requested that we reset our pointers and not write
// the checksum in the FW
if (!isI2O() && !sendToHW) {
	status.sub = SSUB_FLASH_INIT;
	return(MSG_RTN_COMPLETED);
}


DPT_RTN_T retVal = MSG_RTN_FAILED | ERR_GET_CCB;

engCCB_C *ccb_P = getCCB();
if (ccb_P!=NULL) {
	// If in flash write mode...
   // if (isFlashMode() == SSUB_FLASH_WRITE) {
	// Always take out of flash write mode
	 status.sub = SSUB_FLASH_INIT;
	// Send the write done command to firmware
	 ccb_P->target(this);
	 ccb_P->flashCmd(FLASH_CMD_WRITE_DONE);
	 retVal = launchCCB(ccb_P);
	 flashStablize();
//   }
//   else
//      retVal = MSG_RTN_FAILED | ERR_FLASH_INIT_REQ;

	// Free the CCB
	ccb_P->clrInUse();
}

return (retVal);

}
//dptHBA_C::flashWriteDone() - end


//Function - dptHBA_C::flashRead() - start
//===========================================================================
//
//Description:
//
//    This function reads from the HBA's flash memory.  Reading of
//the flash does not require that the HBA be in flash mode.
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::flashRead(dptBuffer_S *toEng_P,dptBuffer_S *fromEng_P)
{

DPT_RTN_T retVal = MSG_RTN_FAILED | ERR_GET_CCB;

engCCB_C *ccb_P = getCCB();
if (ccb_P!=NULL) {
	uLONG flashAddr;
	uLONG bytesRequested;
	retVal = MSG_RTN_DATA_UNDERFLOW;
	toEng_P->extract(flashAddr);
	if (toEng_P->extract(bytesRequested)) {
	 uLONG bytesToRead;
	 while (bytesRequested) {
	 bytesToRead = (bytesRequested > 512) ? 512 : bytesRequested;
	 ccb_P->target(this);
	 ccb_P->flashCmd(FLASH_CMD_READ,flashAddr + flashRegionOffset,bytesToRead);
	 retVal = launchCCB(ccb_P);
	 if (retVal == MSG_RTN_COMPLETED) {
		 if (!fromEng_P->insert(ccb_P->defData,bytesToRead))
		  retVal = MSG_RTN_DATA_OVERFLOW;
	 }
	 flashStablize();

	 if (retVal != MSG_RTN_COMPLETED)
		 break;
	 flashAddr += bytesToRead;
	 bytesRequested -= bytesToRead;
	 }
	}
	// Free the CCB
	ccb_P->clrInUse();
}

return (retVal);

}
//dptHBA_C::flashRead() - end


//Function - dptHBA_C::flashStatus() - start
//===========================================================================
//
//Description:
//
//    This function inquires the status of the HBA's flash memory.
//This status command does not require that the HBA be in flash
//mode.
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::flashStatus(dptBuffer_S *fromEng_P)
{

DPT_RTN_T retVal = MSG_RTN_FAILED | ERR_GET_CCB;

engCCB_C *ccb_P = getCCB();
if (ccb_P!=NULL) {
	retVal = MSG_RTN_DATA_OVERFLOW;
	uLONG fwStatus = 0;
	fromEng_P->insert(flashWriteCnt + flashRegionOffset);
	ccb_P->target(this);
	ccb_P->flashCmd(FLASH_CMD_STATUS);
	if (launchCCB(ccb_P) == MSG_RTN_COMPLETED) {
	 fwStatus = 1;
	 fromEng_P->insert(fwStatus);
	 dptFlashStatus_S *fstat_P = (dptFlashStatus_S *) ccb_P->defData;
	 fstat_P->scsiSwap();
	 if (fromEng_P->insert(ccb_P->defData,dptFlashStatus_S::size()))
	 retVal = MSG_RTN_COMPLETED;
	}
	else if (fromEng_P->insert(fwStatus))
	 retVal = MSG_RTN_COMPLETED;

	 flashStablize();

	// Free the CCB
	ccb_P->clrInUse();
}

return (retVal);

}
//dptHBA_C::flashStatus() - end


//Function - dptHBA_C::flashSwitchInto() - start
//===========================================================================
//
//Description:
//
//    This function attempts to switch the HBA into flash mode from
//operational mode.
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::flashSwitchInto()
{

DPT_RTN_T retVal = MSG_RTN_IGNORED;

updateStatus();
  // If in operational mode...
if (!isFlashMode()) {
	retVal = ERR_GET_CCB;
	engCCB_C *ccb_P = getCCB();
	if (ccb_P != NULL) {
	// Attempt to switch to flash mode
		switchToFlashMode(ccb_P);
	// If in flash mode...
	 retVal = (isFlashMode()) ? MSG_RTN_COMPLETED : ERR_FLASH_SWITCH_MODES;

	// Free the CCB
	 ccb_P->clrInUse();
	}
}

return (retVal);

}
//dptHBA_C::flashSwitchInto() - end


//Function - dptHBA_C::flashSwitchOutOf() - start
//===========================================================================
//
//Description:
//
//    This function attempt to switch the firmware into operational
//mode from flash mode.  This function causes the firmware to perform
//a "cold" reboot.
//    if (method == 0)
//       a "normal" switch to operational mode is attempted
//    else
//       a no-checksum switch is attempted for the purposes of
//       verifying the functionality newly burned firmware
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::flashSwitchOutOf(uINT skipChecksumTst)
{

DPT_RTN_T retVal = MSG_RTN_IGNORED;

  // Determine how to switch out of flash mode
uCHAR action = (skipChecksumTst) ? FLASH_CMD_TST_RESTART : FLASH_CMD_RESTART;


DEBUG_BEGIN(1, dptHBA_C::flashSwitchOutOf());
updateStatus();
DEBUG(1, PRT_DADDR(this) << PRT_STAT);


  // If in flash mode...
if (isFlashMode()) {
	retVal = ERR_GET_CCB;
	  // Attempt to switch to operational mode
	engCCB_C *ccb_P = getCCB();
	if (ccb_P!=NULL) {
		ccb_P->target(this);
		ccb_P->flashCmd(action);
		retVal = launchCCB(ccb_P);

		// if we are testing the new flash code, give the F/W a few seconds to do thier
		// thing before we start "attacking" them
		if (action == FLASH_CMD_TST_RESTART)
#if defined (_DPT_MSDOS) || defined (_DPT_UNIX)
			sleep(5);
#elif defined (_DPT_WINNT)
			Sleep(5000);
#elif defined (_DPT_OS2)
			DosSleep(5000);
#endif
		if (retVal == MSG_RTN_COMPLETED)
			status.main = status.sub = 0;

	// Free the CCB
		ccb_P->clrInUse();
	}
}

return (retVal);

}
//dptHBA_C::flashSwitchOutOf() - end


//Function - dptHBA_C::switchToFlashMode() - start
//===========================================================================
//
//Description:
//
//    This function tries to switch the firmware into flash mode.
//In order to switch into flash mode all F/W level diagnostics and
//all RAID builds, rebuilds, and verifies must be stopped, and all
//dirty cache must be flushed.  This command will fail if F/W cannot
//switch for any of the reasons mentioned above.
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::switchToFlashMode(engCCB_C *ccb_P)
{


DEBUG_BEGIN(1, dptHBA_C::switchToFlashMode());


  // Try to switch into flash mode
ccb_P->reInit();
ccb_P->target(this);
ccb_P->flashCmd(FLASH_CMD_FLASH_MODE);
DPT_RTN_T retVal = launchCCB(ccb_P);
if (retVal == MSG_RTN_COMPLETED) {

// sleep for 2 seconds to make sure the FW has dones thier init'ing.
#if defined(_DPT_MSDOS) || defined (_DPT_UNIX)
			sleep(2);
#elif defined (_DPT_WINNT)
			Sleep(2000);
#elif defined (_DPT_OS2)
			DosSleep(2000);
#endif
	for (uINT i=0;i<50;i++) {
		updateStatus();
		if (isFlashMode()) {

#if defined(_DPT_MSDOS) || defined (_DPT_UNIX)
			sleep(1);
#elif defined (_DPT_WINNT)
			Sleep(1000);
#elif defined (_DPT_OS2)
			DosSleep(1000);
#endif

			ccb_P->reInit();
			ccb_P->target(this);
			ccb_P->inquiry();
			launchCCB(ccb_P);

			sdInquiry_S *inq_P = (sdInquiry_S *) ccb_P->defData;

		} break;
	}
}

DEBUG(1, PRT_DADDR(this) << "flash in retVal=" << hex << retVal <<  \
         PRT_STAT);


return (retVal);

}
//dptHBA_C::switchToFlashMode() - end


//Function - dptHBA_C::flashSetRegion() - start
//===========================================================================
//
//Description:
//
//    This function 
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::flashSetRegion(dptBuffer_S *toEng_P)
{

	DPT_RTN_T retVal = MSG_RTN_COMPLETED;
	uLONG	RegionType = 0;
	uLONG	BootFlags = 0;
	uLONG	ActualSize = 0;
	uINT	topAligned = 0;

	if (!isI2O()) {
		retVal = MSG_RTN_FAILED;
	}
	else {
		toEng_P->extract(RegionType);
		toEng_P->extract(BootFlags);
		toEng_P->extract(ActualSize);
           
		uLONG flashSize = FLASH_REGION_NVRAM_OFFSET + 0x4000L;
		uLONG biosOffset = FLASH_REGION_BIOS_OFFSET;
		uLONG utilOffset = FLASH_REGION_UTILITY_OFFSET;

		// Determine if top or bottom aligned
		if (BootFlags & FW_LOAD_TOP) {
			topAligned = 1;
		}

		engCCB_C *ccb_P = getCCB();
		if (ccb_P!=NULL) {
			DPTI_BootFlags = (uSHORT)BootFlags;
			// Get the flash status to help determine region sizes
			ccb_P->target(this);
			ccb_P->flashCmd(FLASH_CMD_STATUS);
			if (launchCCB(ccb_P) == MSG_RTN_COMPLETED) {
				dptFlashStatus_S *fstat_P = (dptFlashStatus_S *) ccb_P->defData;
				fstat_P->scsiSwap();
				flashSize = fstat_P->getFlashSize();
				biosOffset = fstat_P->getBurnSize();
			}

			// Read the first 512 bytes of the BIOS region to determine the utility region offset
			utilOffset = biosOffset + 0x8000L; // default = BIOS offset + 32k
			ccb_P->reInit();
			ccb_P->target(this);
			ccb_P->flashCmd(FLASH_CMD_READ, biosOffset, 512);
			if (launchCCB(ccb_P) == MSG_RTN_COMPLETED) {
				if ((ccb_P->defData[0] == 0x55) && (ccb_P->defData[1] == 0xaa)) {
					utilOffset = ccb_P->defData[2];
					utilOffset <<= 9;
					utilOffset += biosOffset;
				}
			}

			ccb_P->clrInUse();
		}

		switch(RegionType) {
			case FLASH_REGION_FIRMWARE:
				flashRegionOffset = FLASH_REGION_FIRMWARE_OFFSET;     
				if (topAligned && (biosOffset > ActualSize)) {
					flashRegionOffset = biosOffset - ActualSize; // burnSize - ActualSize
				}
				break;
			case FLASH_REGION_BIOS:
				flashRegionOffset = biosOffset;
				break;
			case FLASH_REGION_UTILITY:
				flashRegionOffset = utilOffset;
				break;
			case FLASH_REGION_NVRAM:
				flashRegionOffset = flashSize - 0x4000L; // flash size - 16k
				break;
			case FLASH_REGION_SERIAL_NUM:
				flashRegionOffset = flashSize - 0x2000L; // flash size - 8k
				break;
			default :
				retVal = MSG_RTN_FAILED;
				break;
		}
	}

return (retVal);

}
//dptHBA_C::flashSetRegion() - end

//Function - dptHBA_C::flashStablize()  - start
//===========================================================================
//
//Description: the board is in flash mode, wait until we see the
//                       bled code before going on
//
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------
void dptHBA_C::flashStablize()
{
	uSHORT LEDpattern = 0;

	if (!isI2O() && status.main == SMAIN_FLASH_MODE) {
		while((LEDpattern & 0x00ff) != 0x69)
			osdCheckBLED(getDrvrNum(),&LEDpattern);
	}
}
// - end

//Function - dptHBA_C::setDataField() - start
//===========================================================================
//
//Description:
//
//    This function sets the specified data field to the specified
//value.
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::setDataField(dptBuffer_S *toEng_P)
{

   DPT_RTN_T            retVal = MSG_RTN_DATA_UNDERFLOW;
   uSHORT               dataField,tempShort;

  // If a data field was specified...
if (toEng_P->extract(dataField)) {
   switch (dataField) {
	 case DF_RBLD_POLL_FREQ:
	 if (toEng_P->extract(tempShort)) {
	    rbldPollFreq = tempShort;
	    retVal = updateLAPparams();
	 }
	 break;
	 case DF_RBLD_BOOT_CHECK:
	 if (toEng_P->extract(tempShort)) {
	    if (tempShort)
		  raidFlags |= FLG_RBLD_BOOT_CHECK;
	    else
		  raidFlags &= ~FLG_RBLD_BOOT_CHECK;
	    retVal = updateLAPparams();
	 }
	 break;
	 case DF_SPIN_DOWN_DELAY:
	 if (toEng_P->extract(tempShort)) {
	    spinDownDelay = tempShort;
	    retVal = updateLAPparams();
	 }
	 break;
	 default:
	 toEng_P->replay();
	 retVal = dptRAIDhba_C::setDataField(toEng_P);
	 break;
   } // end switch (dataField)
} //

return (retVal);

}
//dptHBA_C::setDataField() - end


//Function - dptHBA_C::readNV_RAM() - start
//===========================================================================
//
//Description:
//
//      This function attempts to read the contents of the HBA's
//non-volatile memory.
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::readNV_RAM(dptBuffer_S *fromEng_P)
{

DPT_RTN_T       retVal = MSG_RTN_FAILED | ERR_GET_CCB;

engCCB_C *ccb_P = getCCB();
if (ccb_P != NULL) {
	// Attempt to read the contents of the NV RAM
   ccb_P->modeSense(0x2e);
   ccb_P->target(this);
   if ((retVal = launchCCB(ccb_P)) == MSG_RTN_COMPLETED) {
	 if (fromEng_P->insert(ccb_P->modeParam_P->getData(),128))
	 retVal = MSG_RTN_COMPLETED;
	 else
	 retVal = MSG_RTN_DATA_OVERFLOW;
   }

	// Free the CCB
   ccb_P->clrInUse();
}

return (retVal);

}
//dptHBA_C::readNV_RAM() - end


//Function - dptHBA_C::writeNV_RAM() - start
//===========================================================================
//
//Description:
//
//      This function attempts to write the contents of the HBA's
//non-volatile memory.
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::writeNV_RAM(dptBuffer_S *toEng_P)
{

DPT_RTN_T       retVal = MSG_RTN_FAILED | ERR_GET_CCB;

engCCB_C *ccb_P = getCCB();
if (ccb_P != NULL) {
   ccb_P->clrData();
   ccb_P->modeSelect(0x2e,128+2);
   ccb_P->target(this);
   retVal = MSG_RTN_DATA_UNDERFLOW;
	// Insert the data to be written to the NV RAM
   if (toEng_P->extract(ccb_P->modeParam_P->getData(),128)) {
	// Compute the checksum
	 char checksum = 0;
	 char *byte_P = (char *) ccb_P->modeParam_P->getData();
	 for (uSHORT i=0;i<127;i++)
	 checksum += *byte_P++;
	 checksum = -checksum;
	 ccb_P->modeParam_P->getData()[127] = checksum;
	 retVal = launchCCB(ccb_P);
   }
	// Free the CCB
   ccb_P->clrInUse();
}

return (retVal);

}
//dptHBA_C::writeNV_RAM() - end


//Function - dptHBA_C::quietBus() - start
//===========================================================================
//
//Description:
//
//      This function quiets the SCSI bus and optionally blinks the
//LED of this device.
//
//---------------------------------------------------------------------------

DPT_RTN_T       dptHBA_C::quietBus(dptBuffer_S *toEng_P)
{

   uSHORT       blinkMode = 1;
   uCHAR        modifier = 0x80;

if (!toEng_P->extract(blinkMode))
   blinkMode = 0;

if (blinkMode)
   modifier = 0xa0;

return (sendMFC(MFC_QUIET,modifier));

}
//dptHBA_C::quietBus() - end


//Function - dptHBA_C::updateLAPparams() - start
//===========================================================================
//
//Description:
//
//    This function overrides the dptManager_C::updateLAPparams()
//function and updates the background priority via the extended
//multifunction command if the dptManager_C found no RAID devices
//to which to send the logical array page.
//
//---------------------------------------------------------------------------

DPT_RTN_T dptHBA_C::updateLAPparams()
{

  // Attempt to update all logical array page data
DPT_RTN_T retVal = dptManager_C::updateLAPparams();

  // If the logical array page was not issued to at least 1 device
if (retVal == (MSG_RTN_FAILED | ERR_NO_RAID_DEVICES))
	// Try to set the background priority via the multi-function cmd
   retVal = sendExtMFC(0x0b,0,0L,rbldAmount,(uCHAR)rbldFrequency);

return (retVal);

}
//dptHBA_C::updateLAPparams() - end


//Function - dptHBA_C::setPhyMagicNums() - start
//===========================================================================
//
//Description:
//
//    This function attempts to set the RAID magic number of all
//unarrayed physical DASD devices.
//---------------------------------------------------------------------------
void dptHBA_C::setPhyMagicNums()
{

dptDevice_C *dev_P = (dptDevice_C *) logList.reset();
while (dev_P) {
	// If an unarrayed physical DASD device with no magic number...
   if ((dev_P->getLevel()==2) && (dev_P->getObjType()==DPT_SCSI_DASD) &&
	  !dev_P->isComponent() && !dev_P->isRemovable() &&
	  !dev_P->getMagicNum()) {

	// Attempt to set the physical device's magic number
	 dev_P->setPhyMagicNum();
   }

   dev_P = (dptDevice_C *) logList.next();

}

}
//dptHBA_C::setPhyMagicNums() - end


//Function - dptHBA_C::GetAccessRights - start
//===========================================================================
//
//Description:
//
//    This function attempts to get the HBA's access rights
//
//---------------------------------------------------------------------------
DPT_RTN_T dptHBA_C::GetAccessRights(dptBuffer_S *fromEng_P)
{
	DPT_RTN_T rtnVal = ERR_GET_CCB;

	engCCB_C *ccb_P = getCCB();
	if (ccb_P) {	

		// target the me
		ccb_P->target(this);

		// get the hba's portion of the rights
		ccb_P->modeSense(0x2d);

		// send it
		if ((rtnVal = launchCCB(ccb_P)) == MSG_RTN_COMPLETED) {

			dptMultiInitPage_S page;

			// copy the hba's poritons of the access rights
			memcpy(&page, ccb_P->modeParam_P->getData(), page.size());
			page.scsiSwap();
			fromEng_P->insert(&page, page.size());

			// loop thru all the attached devices, we can look at the physical list
			// because the GetAccessRights function will get the RAID parent if any
			dptDevice_C *dev_P = (dptDevice_C *) phyList.reset();

			while(dev_P) {
				rtnVal = dev_P->GetAccessRights(fromEng_P);
				dev_P = (dptDevice_C *) phyList.next();
			}
		}
	}
	return rtnVal;
}

//Function - dptHBA_C::setPhyMagicNums() - start
//===========================================================================
//
//Description:
//
//    This function attempts to set the RAID magic number of all
//unarrayed physical DASD devices.
//---------------------------------------------------------------------------
DPT_RTN_T dptHBA_C::SetAccessRights(dptBuffer_S *fromEng_P, dptBuffer_S *toEng_P)
{
	DPT_RTN_T rtnVal = MSG_RTN_DATA_UNDERFLOW;
	uCHAR acquire = 0;

	dptMultiInitPage_S page;

	// makw sure we get the data we need
	if (toEng_P->extract(&page, page.size())) {
		if (toEng_P->writeIndex - toEng_P->readIndex >= dptMultiInitList_S::size() + 1) {
			toEng_P->extract(acquire);
			rtnVal = MSG_RTN_COMPLETED;
		}
	}

	engCCB_C *ccb_P = getCCB();
	if (ccb_P) {	

		// target the me
		ccb_P->target(this);

		// get the hba's portion of the rights
		ccb_P->modeSelect(0x2d, (uSHORT)(2+dptMultiInitPage_S::size()), (acquire >> 1) | 0x80);

		// scsi swap
		page.scsiSwap();

		// copy the data
		memcpy(ccb_P->modeParam_P->getData(), &page, page.size());

		// send it
		if ((rtnVal = launchCCB(ccb_P)) == MSG_RTN_COMPLETED) {

			// go thru the physical list setting the rights there, the arrays will 
			// automatically be set as well
			dptDevice_C *dev_P = (dptDevice_C *) phyList.reset();

			while(dev_P) {
				toEng_P->replay();
				toEng_P->skip(page.size());
				DPT_RTN_T devRtn = dev_P->SetAccessRights(fromEng_P, toEng_P);

				// a device returned an error, palce its tag in
				if (devRtn) {
					fromEng_P->insert(dev_P->tag());
					rtnVal = devRtn;
				}

				dev_P = (dptDevice_C *) phyList.next();
			}
		}
	} else
		rtnVal = ERR_GET_CCB;

	return rtnVal;
}

DPT_RTN_T dptHBA_C::GetEnvironInfo(dptBuffer_S *fromEng_P)
{
	DPT_RTN_T rtnVal = MSG_RTN_FAILED;
	dptHBAenviron_S info;
	info.clear();

	//TODO:  make something in the logger that make the following events "special" in that
	// it keeps track of the count and last triggered
	// 0x4014
	// 0x4015
	// 0x4017
	// 0x4018
	// for now, set it to 0xffffffff

	info.setHighTempCount(0xffffffff);
	info.setHighTempLast(0xffffffff);
	info.setVeryHighTempCount(0xffffffff);
	info.setVeryHighTempLast(0xffffffff);
	info.setLowVoltCount(0xffffffff);
	info.setLowVoltLast(0xffffffff);
	info.setHightVoltCount(0xffffffff);
	info.setHightVoltLast(0xffffffff);

	// this updates the temp and volt
	updateStatus(fromEng_P);
	fromEng_P->reset();

	if(currVoltage != 0xffff) 
		info.setCurVolt(currVoltage);
	else 
		info.setCurVolt(0xffffffff);
		
	if(currTemperature != 0xffff) 	
		info.setCurTemp(currTemperature);
	else
		info.setCurTemp(0xffffffff);

	// get the temp thresholds	
	readNV_RAM(fromEng_P);
	dptNVRAM_S *nv_P = (dptNVRAM_S *) &fromEng_P->data;	

	if (nv_P->getHighTemp())
		info.setHighTempThresh((uLONG) nv_P->getHighTemp());
	else
		info.setHighTempThresh((uLONG) 46);
		
	if (nv_P->getVeryHighTemp())
		info.setVeryHighTempThresh((uLONG) nv_P->getVeryHighTemp());
	else
		info.setVeryHighTempThresh((uLONG) 60);

	fromEng_P->reset();

	// give them the buffer
	if (fromEng_P->insert(&info, info.size()))
		rtnVal = MSG_RTN_COMPLETED;


	return rtnVal;
}

DPT_RTN_T dptHBA_C::SetEnvironInfo(dptBuffer_S *toEng_P)
{
	DPT_RTN_T rtnVal = MSG_RTN_FAILED;

	dptHBAenviron_S info;
	info.clear();
	
	if (toEng_P->extract(&info, info.size())) {

		readNV_RAM(toEng_P);
		dptNVRAM_S *nv_P = (dptNVRAM_S *) &toEng_P->data;		
		nv_P->setHighTemp((uCHAR)info.getHighTempThresh());
		nv_P->setVeryHighTemp((uCHAR)info.getHighTempThresh());
		rtnVal = writeNV_RAM(toEng_P);
	}

	return rtnVal;
}