summaryrefslogblamecommitdiffstats
path: root/private/ntos/miniport/oliscsi/oliesc1.c
blob: a3ae32d8fb2ec6fc0c4806d4ce66f5775968932d (plain) (tree)
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



























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                                                                   
/*++

Copyright (c) 1991  Microsoft Corporation

Module Name:

    oliesc1.c

Abstract:

    This is the port driver for the Olivetti ESC-1 SCSI adapters.

Authors:

    Bruno Sartirana (o-obruno) 13-Dec-1991

Environment:

    kernel mode only

Notes:

Revision History:

    12-Feb-1992:    (o-obruno) Replaced calls to HAL and MM with calls to
                    ScsiPortGetDeviceBase and ScsiPortFreeDeviceBase.

     8-Nov-1992:    (o-obruno) 
                        - Added error logging
                        - Removed adapter reset at initialization time
                          (it saves 2-3 secs.)
                        - Removed list of present peripherals
                        - Enhanced interrupt status check for better handling
			  of the ESC-2 interrupt status codes.

     9-Apr-1993:    (v-egidis)
			- Removed the search for ESC-2 cards.
			- Added call to ESC-2/EFP-2 driver init routine.
			- Added code to claim the primary AT disk ctrl
			  if the AT mode is enabled.
			- Now all the routine names start with the "OliEsc1".
			- Removed all the "static" directives, this will
			  be very useful during the debugging sessions.
			- Now if there is an error during the execution of
			  OliEsc1Configuration routine the SP_RETURN_ERROR
			  error code is returned instead of
			  SP_RETURN_NOT_FOUND.
			- Now all the physical slots 1-15 are checked,
			  before only slots 1-7 were checked.

     7-Jul-1993:     (v-egidis)
			- The reset has been changed to use the scsiport's
			  timer.  This modification fixes the following
			  problem: the reset is taking too much DPC time.


--*/

#include "miniport.h"
#include "oliesc1.h"		// includes scsi.h


//
// Function declarations
//
// Functions that start with 'OliEsc1' are entry points
// for the OS port driver.
//

VOID
OliEsc1BuildCcb(
    IN PHW_DEVICE_EXTENSION DeviceExtension,
    IN PSCSI_REQUEST_BLOCK Srb
    );

VOID
OliEsc1BuildSgl(
    IN PHW_DEVICE_EXTENSION DeviceExtension,
    IN PSCSI_REQUEST_BLOCK Srb
    );

ULONG
DriverEntry (
    IN PVOID DriverObject,
    IN PVOID Argument2
    );

BOOLEAN
OliEsc1GetIrql(
    IN PEISA_CONTROLLER eisaController,
    PUCHAR Irql
    );

BOOLEAN
OliEsc1CheckAtMode(
    IN PEISA_CONTROLLER eisaController,
    PBOOLEAN AtModeEnabled
    );

ULONG
OliEsc1DriverEntry(
    IN PVOID DriverObject,
    IN PVOID Argument2
    );

ULONG
OliEsc1Configuration(
    IN PVOID HwDeviceExtension,
    IN PVOID Context,
    IN PVOID BusInformation,
    IN PCHAR ArgumentString,
    IN OUT PPORT_CONFIGURATION_INFORMATION ConfigInfo,
    OUT PBOOLEAN Again
    );

BOOLEAN
OliEsc1Initialize(
    IN PVOID HwDeviceExtension
    );

BOOLEAN
OliEsc1Interrupt(
    IN PVOID HwDeviceExtension
    );

BOOLEAN
OliEsc1ResetBus(
    IN PVOID HwDeviceExtension,
    IN ULONG PathId
    );

BOOLEAN
OliEsc1StartIo(
    IN PVOID HwDeviceExtension,
    IN PSCSI_REQUEST_BLOCK Srb
    );

BOOLEAN
OliEsc1SendCommand(
    IN PHW_DEVICE_EXTENSION DeviceExtension,
    IN UCHAR OperationCode,
    IN PCCB ccb
    );

BOOLEAN
OliEsc1SendCommandQuick(
    IN PEISA_CONTROLLER EisaController,
    IN UCHAR TaskId,
    IN UCHAR OperationCode,
    IN USHORT CommandLength,
    IN ULONG Address
    );

VOID
OliEsc1ResetAdapter(
    IN PVOID Context
    );


//
// External entry points
//

ULONG
OliEsc2DriverEntry(
    IN PVOID DriverObject,
    IN PVOID Argument2
    );


VOID
OliEsc1BuildCcb(
    IN PHW_DEVICE_EXTENSION DeviceExtension,
    IN PSCSI_REQUEST_BLOCK Srb
    )

/*++

Routine Description:

    Build a Command Control Block for the ESC-1.

Arguments:

    DeviceExtension     Pointer to the device extension for this driver.
    Srb                 Pointer to the Scsi Request Block to service

Return Value:

    Nothing.

--*/

{
    PCCB ccb;                           // Virtual address of the CCB
    ULONG physicalAddress;              // Physical address of the CCB
    ULONG length;                       // Length of contiguous memory in the
                                        // data buffer, starting at the
                                        // beginning of the buffer

    DebugPrint((3,"OliEsc1BuildCcb: Enter routine\n"));

    //
    // Get the CCB address
    //

    ccb = Srb->SrbExtension;

    //
    // Set LUN and Target ID
    //

    ccb->TaskId = Srb->Lun | (UCHAR) (Srb->TargetId << CCB_TARGET_ID_SHIFT);

    //
    // We distinguish between the Abort command and all the others, because
    // we translate the Abort into a Target Reset, which does not require
    // a CCB. Since a Terget Reset doesn't imply any data transfer, we skip
    // some proceessing here below, but we use a CCB anyway, so as to allow
    // the interrupt service routine to complete the Target Reset request
    // like any others, without special case handling.
    //

    if (Srb->Function != SRB_FUNCTION_ABORT_COMMAND) {

        //
        // Set transfer direction bit.
        //

        if (Srb->SrbFlags & SRB_FLAGS_DATA_OUT) {

           //
           // Adapter to system transfer
           //

           ccb->TaskId |= CCB_DATA_XFER_OUT;

        } else if (Srb->SrbFlags & SRB_FLAGS_DATA_IN) {

           //
           // System to adapter transfer
           //

           ccb->TaskId |= CCB_DATA_XFER_IN;

        } else ccb->TaskId |= CCB_DATA_XFER_NONE;

        //
        // Set the LinkedCommandAddress to NULL. It is not used by the ESC-1,
        // but, for safety, it's better to set it.
        //

        ccb->LinkedCommandAddress = (ULONG) NULL;

        //
        // Copy the Command Descriptor Block (CDB) into the CCB.
        //

        ScsiPortMoveMemory(ccb->Cdb, Srb->Cdb, Srb->CdbLength);

	DebugPrint((3,"OliEsc1BuildCcb: CDB at %lx, length=%x\n",
			 ccb->Cdb, Srb->CdbLength));

        //
        // Set the CDB length and the data transfer length in the CCB
        //

        ccb->CdbLength = (UCHAR) Srb->CdbLength;
        ccb->DataLength = Srb->DataTransferLength;

        //
        // Build a actter/gather list in the CCB if necessary
        //

        if (Srb->DataTransferLength > 0) {

            physicalAddress = ScsiPortConvertPhysicalAddressToUlong(
                ScsiPortGetPhysicalAddress(DeviceExtension,
                                                         Srb,
                                                         Srb->DataBuffer,
                                                         &length));

            //
            // length contains the length of contiguous memory starting
            // at Srb->DataBuffer
            //

            if (length >= Srb->DataTransferLength) {

                //
                // The Srb->DataBuffer is contiguous: no need of
                // scatter/gather descriptors
                //

                ccb->DataAddress = physicalAddress;
                ccb->AdditionalRequestBlockLength = 0;

            } else {

                //
                // The Srb->DataBuffer is not contiguous: we need
                // scatter/gather descriptors
                //

		OliEsc1BuildSgl(DeviceExtension, Srb);

            }

        } else {

            //
            // No data transfer is requested
            //

            ccb->AdditionalRequestBlockLength = 0;
        }
    }

    return;

} // end OliEsc1BuildCcb()


VOID
OliEsc1BuildSgl(
    IN PHW_DEVICE_EXTENSION DeviceExtension,
    IN PSCSI_REQUEST_BLOCK Srb
    )

/*++

Routine Description:

    This routine builds a scatter/gather descriptor list for the Command
    Control Block.

Arguments:

    DeviceExtension     Pointer to the device extension for this driver.
    Srb                 Pointer to the Scsi Request Block to service

Return Value:

    None

--*/

{
    ULONG bytesLeft;                    // # of bytes left to be described
                                        // in an SGL
    PCCB ccb;                           // CCB address
    PVOID dataPointer;                  // Pointer to the data buffer to send
    ULONG descriptorCount;              // # of scatter/gather descriptors
                                        // built
    ULONG length;                       // Length of contiguous memory in the
                                        // data buffer, starting at a given
                                        // offset
    ULONG physicalAddress;   // Physical address of the data buffer
    ULONG physicalSgl;                  // Physical SGL address
    PSGL sgl;                           // Virtual SGL address


    DebugPrint((3,"OliEsc1BuildSgl: Enter routine\n"));

    //
    // Initialize some variables
    //

    dataPointer = Srb->DataBuffer;
    bytesLeft = Srb->DataTransferLength;
    ccb = Srb->SrbExtension;
    sgl = &ccb->Sgl;
    descriptorCount = 0;

    //
    // Get physical SGL address.
    //

    physicalSgl = ScsiPortConvertPhysicalAddressToUlong(
        ScsiPortGetPhysicalAddress(DeviceExtension, NULL,
                                             sgl, &length));

    //
    // Assume physical memory contiguous for sizeof(SGL) bytes.
    //

    ASSERT(length >= sizeof(SGL));

    //
    // Create SGL segment descriptors.
    //

    do {

	DebugPrint((3,
	    "OliEsc1BuildSgl: Data buffer %lx\n", dataPointer));

        //
        // Get physical address and length of contiguous
        // physical buffer.
        //

        physicalAddress = ScsiPortConvertPhysicalAddressToUlong(
            ScsiPortGetPhysicalAddress(DeviceExtension,
                                                     Srb,
                                                     dataPointer,
                                                     &length));

	DebugPrint((3, "OliEsc1BuildSgl: Physical address %lx\n",
		       physicalAddress));
	DebugPrint((3, "OliEsc1BuildSgl: Data length %lx\n", length));
	DebugPrint((3, "OliEsc1BuildSgl: Bytes left %lx\n", bytesLeft));

        //
        // If length of physical memory is more
        // than bytes left in transfer, use bytes
        // left as final length.
        //

        if  (length > bytesLeft) {
            length = bytesLeft;
        }

        sgl->Descriptor[descriptorCount].Address = physicalAddress;
        sgl->Descriptor[descriptorCount].Length = length;

        //
        // Adjust counts.
        //

        dataPointer = (PUCHAR)dataPointer + length;
        bytesLeft -= length;
        descriptorCount++;

    } while (bytesLeft);

    //
    // Write SGL length to CCB.
    //

    ccb->AdditionalRequestBlockLength = descriptorCount * sizeof(SG_DESCRIPTOR);

    DebugPrint((3,"OliEsc1BuildSgl: SGL length is %d\n", descriptorCount));

    //
    // Write SGL address to CCB.
    //

    ccb->DataAddress = physicalSgl;

    DebugPrint((3,"OliEsc1BuildSgl: SGL address is %lx\n", sgl));

    DebugPrint((3,"OliEsc1BuildSgl: CCB address is %lx\n", ccb));

    return;

} // end OliEsc1BuildSgl()


ULONG
DriverEntry (
    IN PVOID DriverObject,
    IN PVOID Argument2
    )

/*++

Routine Description:

    Installable driver initialization entry point for the OS.

Arguments:

    Driver Object       Pointer to the driver object for this driver

Return Value:

    Status from OliEsc1DriverEntry()

--*/

{
    ULONG   Esc1Status, Esc2Status;

    //
    // Search for any ESC-1
    //

    Esc1Status = OliEsc1DriverEntry(DriverObject, Argument2);

    //
    // Search for any ESC-2 and EFP-2
    //

    Esc2Status = OliEsc2DriverEntry(DriverObject, Argument2);

    //
    // The driver should return the lowest status
    //

    return MIN( Esc1Status, Esc2Status );

} // end DriverEntry()


BOOLEAN
OliEsc1GetIrql(
    IN PEISA_CONTROLLER eisaController,
    PUCHAR Irql
    )

/*++

Routine Description:

    It reads the ESC-1's IRQL. It is assumed to be called at system
    initialization time only, since it uses polling.

Arguments:


Return Value:

    TRUE    Success
    FALSE   Failure

--*/

{

    BOOLEAN Success;    // Return value
    UCHAR IntMask;      // Current System Doorbell interrupt mask value
    ULONG i;            // Auxiliary variable



    //
    // Get the current System Doorbell Interrupt Mask
    //

    IntMask = ScsiPortReadPortUchar(&eisaController->SystemDoorBellMask);

    //
    // Disable ESC-1 interrupts
    //

    ScsiPortWritePortUchar(&eisaController->SystemDoorBellMask,
                           INTERRUPTS_DISABLE);


    //
    // Get the ESC-1 Irql
    //

    Success = OliEsc1SendCommandQuick(eisaController,
                               CCB_DATA_XFER_NONE,
                               GET_CONFIGURATION,
                               IRQL_REGISTER,
                               (ULONG) NULL);

    if (Success) {

        i = 0;

        //
        // Poll interrupt pending bit
        //

        while (!(ScsiPortReadPortUchar(&eisaController->SystemDoorBell) &
                 INTERRUPT_PENDING) && i < INTERRUPT_POLLING_TIME) {

            ScsiPortStallExecution(1);
            i++;

        }

	DebugPrint((4, "OliEsc1GetIrql: got INT after %ld us\n", i));

        if (i < INTERRUPT_POLLING_TIME) {

            //
            // Sensed the INTERRUPT_PENDING bit. Reset the interrupt pending.
            //

            ScsiPortWritePortUchar(&eisaController->SystemDoorBell,
                                   INTERRUPT_PENDING);

            //
            // Check to see whether the command completed correctly
            //

            if ((UCHAR)
                ((ScsiPortReadPortUshort(&eisaController->Status) >> 8)) ==
                NO_ERROR) {

                Success = TRUE;

                //
                // The IRQL value is available in the OutAddress mailbox
                // register, in the low byte
                //

                switch((UCHAR) ScsiPortReadPortUlong(
                                                &eisaController->OutAddress)) {

                    case 0: *Irql = (KIRQL) 11;
                            break;
                    case 1: *Irql = (KIRQL) 10;
                            break;
                    case 2: *Irql = (KIRQL) 5;
                            break;
		    case 3: *Irql = (KIRQL) 15;
                            break;
                    default: Success = FALSE;
                }

                //
                // Unlock the Result Semaphore, so that the ESC-1 can load
                // new values in the output mailboxes.
                //

                ScsiPortWritePortUchar(&eisaController->ResultSemaphore,
                                       SEM_UNLOCK);

            } else Success = FALSE;

        } else Success = FALSE;
    }

    //
    // Restore the original interrupt mask
    //

    ScsiPortWritePortUchar(&eisaController->SystemDoorBellMask, IntMask);

    return Success;

} // end OliEsc1GetIrql


BOOLEAN
OliEsc1CheckAtMode(
    IN PEISA_CONTROLLER eisaController,
    PBOOLEAN AtModeEnabled
    )

/*++

Routine Description:

    This routine checks if this board has the AT compatible mode enabled.

Arguments:

    eisaController	    I/O address of ESC-1 controller.
    AtModeEnabled	    pointer to a variable.  This variable is
			    set to FALSE if the AT mode is not enable,
			    and to TRUE otherwise.

Return Value:

    TRUE    Success
    FALSE   Failure

--*/

{

    BOOLEAN Success;    // Return value
    UCHAR IntMask;      // Current System Doorbell interrupt mask value
    ULONG i;            // Auxiliary variable

    //
    // Get the current System Doorbell Interrupt Mask
    //

    IntMask = ScsiPortReadPortUchar(&eisaController->SystemDoorBellMask);

    //
    // Disable ESC-1 interrupts
    //

    ScsiPortWritePortUchar(&eisaController->SystemDoorBellMask,
                           INTERRUPTS_DISABLE);


    //
    // Get the ESC-1 Hard Disk Configuration value
    //

    Success = OliEsc1SendCommandQuick(eisaController,
                               CCB_DATA_XFER_NONE,
                               GET_CONFIGURATION,
			       ATCFG_REGISTER,
                               (ULONG) NULL);

    if (Success) {

        i = 0;

        //
        // Poll interrupt pending bit
        //

        while (!(ScsiPortReadPortUchar(&eisaController->SystemDoorBell) &
                 INTERRUPT_PENDING) && i < INTERRUPT_POLLING_TIME) {

            ScsiPortStallExecution(1);
            i++;

        }

	DebugPrint((4, "OliEsc1CheckAtMode: got INT after %ld us\n", i));

        if (i < INTERRUPT_POLLING_TIME) {

            //
            // Sensed the INTERRUPT_PENDING bit. Reset the interrupt pending.
            //

            ScsiPortWritePortUchar(&eisaController->SystemDoorBell,
                                   INTERRUPT_PENDING);

            //
            // Check to see whether the command completed correctly
            //

            if ((UCHAR)
                ((ScsiPortReadPortUshort(&eisaController->Status) >> 8)) ==
                NO_ERROR) {

                Success = TRUE;

                //
		// The AT info is available in the OutAddress mailbox
                // register, in the low byte
                //

		if (ScsiPortReadPortUlong(&eisaController->OutAddress)& 0x01) {

		    *AtModeEnabled = TRUE;
		}
		else {

		    *AtModeEnabled = FALSE;
		}

                //
                // Unlock the Result Semaphore, so that the ESC-1 can load
                // new values in the output mailboxes.
                //

                ScsiPortWritePortUchar(&eisaController->ResultSemaphore,
                                       SEM_UNLOCK);

            } else Success = FALSE;

        } else Success = FALSE;
    }

    //
    // Restore the original interrupt mask
    //

    ScsiPortWritePortUchar(&eisaController->SystemDoorBellMask, IntMask);

    return Success;

} // end OliEsc1CheckAtMode



ULONG
OliEsc1DriverEntry(
    IN PVOID DriverObject,
    IN PVOID Argument2
    )

/*++

Routine Description:

    This routine is called from DriverEntry(). It initializes some fields
    in a data structure of type HW_INITIALIZATION_DATA for use by the port
    driver.

Arguments:

    DriverObject     Address of the context to pass to ScsiPortInitialize

Return Value:

    Status from ScsiPortInitialize()

--*/

{

    HW_INITIALIZATION_DATA hwInitializationData;
                                        // Structure used to tell the upper
                                        // layer the entry points of this
                                        // driver
    ULONG i;                            // Auxiliary variable
    ULONG adapterCount = 0;             // Indicates the slot which have been
                                        // check for adapters.

    DebugPrint((1,"\n\nSCSI ESC-1 MiniPort Driver\n"));

    //
    // Zero out structure.
    //

    for (i = 0; i < sizeof(HW_INITIALIZATION_DATA); i++) {
        ((PUCHAR)&hwInitializationData)[i] = 0;
    }

    //
    // Set size of hwInitializationData.
    //

    hwInitializationData.HwInitializationDataSize = sizeof(HW_INITIALIZATION_DATA);

    //
    // Set entry points.
    //

    hwInitializationData.HwInitialize = OliEsc1Initialize;
    hwInitializationData.HwFindAdapter = OliEsc1Configuration;
    hwInitializationData.HwStartIo = OliEsc1StartIo;
    hwInitializationData.HwInterrupt = OliEsc1Interrupt;
    hwInitializationData.HwResetBus = OliEsc1ResetBus;

    //
    // Set number of access ranges and the bus type.
    //

    hwInitializationData.NumberOfAccessRanges = 1;
    hwInitializationData.AdapterInterfaceType = Eisa;

    //
    // The ESC-1 supports tagged queuing
    //

    hwInitializationData.TaggedQueuing = TRUE;

    //
    // Indicate no buffer mapping but will need physical
    // addresses.
    //

    hwInitializationData.NeedPhysicalAddresses = TRUE;

    //
    // Specify size of extensions.
    //

    hwInitializationData.DeviceExtensionSize = sizeof(HW_DEVICE_EXTENSION);
    hwInitializationData.SpecificLuExtensionSize = sizeof(LU_EXTENSION);

    //
    // Ask for SRB extensions for CCBs.
    //

    hwInitializationData.SrbExtensionSize = sizeof(CCB);

    DebugPrint((1,
	"OliEsc1DriverEntry: hwInitializationData address %lx\n",
	&hwInitializationData));

    return(ScsiPortInitialize(DriverObject, Argument2, &hwInitializationData, &adapterCount));

} // end OliEsc1DriverEntry()


ULONG
OliEsc1Configuration(
    IN PVOID HwDeviceExtension,
    IN PVOID Context,
    IN PVOID BusInformation,
    IN PCHAR ArgumentString,
    IN OUT PPORT_CONFIGURATION_INFORMATION ConfigInfo,
    OUT PBOOLEAN Again
    )

/*++

Routine Description:

    This function is called by the OS-specific port driver after
    the necessary storage has been allocated, to gather information
    about the adapter's configuration.
    The EISA bus is scanned in search for an ESC-1 or an ESC-2 board.
    ES: The search for an ESC-2 has been removed.

Arguments:

    HwDeviceExtension       Device extension for this driver
    Context                 ESC-1 registers' address space
    ConfigInfo              Configuration information structure describing
                            the board configuration

Return Value:

    TRUE if adapter present in system

--*/

{
    PHW_DEVICE_EXTENSION deviceExtension;   // Pointer to the device extension
                                            // for this driver
    PEISA_CONTROLLER eisaController;        // Base address of the ESC-1
                                            // registers' address space
    ULONG eisaSlotNumber;                   // Auxiliary variable
                                            // in case of initialization failure
    BOOLEAN Success = FALSE;                // Indicates an adapter was found.
    PULONG adapterCount = Context;          // Indicates which slots have been
                                            // checked.

    deviceExtension = HwDeviceExtension;

    //
    // Check to see if an adapter is present in the system
    //

    for (eisaSlotNumber = *adapterCount + 1;
	 eisaSlotNumber < MAX_EISA_SLOTS_STD; eisaSlotNumber++) {

        //
        // Update the adpater count to indicate this slot has been checked.
        //

        (*adapterCount)++;

        //
        // Get the system physical address for this card.
        // The card uses I/O space.
        //

        eisaController = ScsiPortGetDeviceBase(
                deviceExtension,
                ConfigInfo->AdapterInterfaceType,
                ConfigInfo->SystemIoBusNumber,
                ScsiPortConvertUlongToPhysicalAddress(0x1000 * eisaSlotNumber),
                0x1000,
                (BOOLEAN) TRUE);

        eisaController =
            (PEISA_CONTROLLER)((PUCHAR)eisaController + EISA_ADDRESS_BASE);

        //
        // Read the EISA board ID and check to see whether it identifies
        // an ESC-1
        //

        if ((ScsiPortReadPortUchar(&eisaController->BoardId[0]) == 0x3D) &&
            (ScsiPortReadPortUchar(&eisaController->BoardId[1]) == 0x89) &&
            (ScsiPortReadPortUchar(&eisaController->BoardId[2]) == 0x10) &&
	    (ScsiPortReadPortUchar(&eisaController->BoardId[3]) == 0x21)) {

	    DebugPrint((1,"ESC-1 Adapter found at EISA slot %d\n",
			   eisaSlotNumber));

	    //
            // Immediately disable system interrupts (bellinte).
            // They will remain disabled (polling mode only) during
            // the EFP initialization sequence.
	    //

            ScsiPortWritePortUchar(&eisaController->SystemIntEnable,
                                   INTERRUPTS_DISABLE);

            //
            // The adpater is not reset and assumed to be functioning.
            // Resetting the adapter is particularly time consuming (2 secs.
            // for the ESC-1, 3.1 secs. for the ESC-2). The BIOS on x86
            // computers or the EISA Support F/W on the M700 computers have
            // already reset the adapter and checked its status.
	    //

	    //
	    // Reset System Doorbell interrupts
	    //

	    ScsiPortWritePortUchar(&eisaController->SystemDoorBell, 0x0FF);

	    //
	    // Enable the ESC-1 High Performance interrupt.
	    //

	    ScsiPortWritePortUchar(&eisaController->SystemDoorBellMask,
				    INTERRUPTS_ENABLE);

            Success = TRUE;
            break;
        }

        //
	// In the current slot there isn't an ESC-1/ESC-2 card. Try next
        // slot.
        //

        ScsiPortFreeDeviceBase(deviceExtension,
                           (PUCHAR)eisaController - EISA_ADDRESS_BASE);

    } // end for (eisaSlotNumber ...

    if (!Success) {

        //
        // No adapter was found.  Clear the call again flag, reset the adapter
        // count for the next bus and return.
        //

        *Again = FALSE;
        *adapterCount = 0;
        return(SP_RETURN_NOT_FOUND);
    }

    //
    // There are more slots to search so call again.
    //

    *Again = TRUE;

    //
    // Store base address of EISA registers in device extension.
    //

    deviceExtension->EisaController = eisaController;

    //
    // Reset the "ResetInProgress" variable.
    //

    deviceExtension->ResetInProgress = 0;

    //
    // Indicate the SCSI ID of the ESC-x, that's always 7
    //

    ConfigInfo->InitiatorBusId[0] = ADAPTER_ID;

    //
    // Indicate the maximum transfer length in bytes.
    //

    ConfigInfo->MaximumTransferLength = MAXIMUM_TRANSFER_SIZE;

    //
    // Indicate the maximum number of physical segments
    //

    ConfigInfo->NumberOfPhysicalBreaks = MAXIMUM_SGL_DESCRIPTORS;

    ConfigInfo->ScatterGather = TRUE;
    ConfigInfo->Master = TRUE;
    ConfigInfo->NumberOfBuses = 1;

    //
    // Get the "AtdiskPrimaryClaimed" info
    //

    if (!OliEsc1CheckAtMode(deviceExtension->EisaController,
	     &ConfigInfo->AtdiskPrimaryClaimed)) {

	DebugPrint((1,
	    "OliEsc1Configuration: Adapter initialization error.\n"));

        ScsiPortLogError(
	    deviceExtension,
            NULL,
            0,
            0,
            0,
            SP_INTERNAL_ADAPTER_ERROR,
	    ESCX_INIT_FAILED
            );

	return SP_RETURN_ERROR;
    }

    //
    // Indicate which interrupt mode the adapter uses
    //

    if (ScsiPortReadPortUchar(&eisaController->GlobalConfiguration) &
        EDGE_SENSITIVE) {

        ConfigInfo->InterruptMode = Latched;

    } else {

        ConfigInfo->InterruptMode = LevelSensitive;
    }

    //
    // Fill in the access array information.
    //

    (*ConfigInfo->AccessRanges)[0].RangeStart = ScsiPortConvertUlongToPhysicalAddress(0x1000 * eisaSlotNumber + EISA_ADDRESS_BASE);
    (*ConfigInfo->AccessRanges)[0].RangeLength = sizeof(EISA_CONTROLLER);
    (*ConfigInfo->AccessRanges)[0].RangeInMemory = FALSE;

    //
    // Get the ESC-x IRQL.
    //

    if (OliEsc1GetIrql(deviceExtension->EisaController,
                (UCHAR *) &ConfigInfo->BusInterruptLevel)) {

	return SP_RETURN_FOUND;

    } else {

	DebugPrint((1,
	    "OliEsc1Configuration: Adapter initialization error.\n"));

        ScsiPortLogError(
	    deviceExtension,
            NULL,
            0,
            0,
            0,
            SP_INTERNAL_ADAPTER_ERROR,
	    ESCX_INIT_FAILED
            );

	return SP_RETURN_ERROR;
    }

} // end OliEsc1Configuration()


BOOLEAN
OliEsc1Initialize(
    IN PVOID HwDeviceExtension
    )

/*++

Routine Description:

    It does nothing (for now).

Arguments:

    HwDeviceExtension       Device extension for this driver

Return Value:

    Always TRUE.

--*/

{
    PHW_DEVICE_EXTENSION deviceExtension;   // Pointer to the device extension
                                            // for this driver
    PEISA_CONTROLLER eisaController;	    // Base address of the ESC-1

    deviceExtension = HwDeviceExtension;
    eisaController = deviceExtension->EisaController;

    //
    // Make sure that the ESC-1 High Performance interrupt is enabled.
    //

    ScsiPortWritePortUchar(&eisaController->SystemDoorBellMask,
			    INTERRUPTS_ENABLE);

    //
    // Enable system interrupts (bellinte).
    //

    ScsiPortWritePortUchar(&eisaController->SystemIntEnable,
			    SYSTEM_INTS_ENABLE);

    return TRUE;

} // end OliEsc1Initialize()


BOOLEAN
OliEsc1Interrupt(
    IN PVOID HwDeviceExtension
    )

/*++

Routine Description:

    This is the interrupt service routine for the ESC-1 SCSI adapter.
    It reads the interrupt register to determine if the adapter is indeed
    the source of the interrupt and clears the interrupt at the device.
    If the adapter is interrupting because an outuput mailbox is full,
    the CCB is retrieved to complete the request.

    NOTE: if the semaphore 1 is used, it must be released after resetting
	  the associated interrupt !


Arguments:

    HwDeviceExtension       Device extention for this driver

Return Value:

    TRUE if the interrupt was expected

--*/

{
    PCCB ccb;
    PHW_DEVICE_EXTENSION deviceExtension;
    PEISA_CONTROLLER eisaController;
    USHORT interruptStatus;
    ULONG physicalCcb;
    PLU_EXTENSION LuExtension;
    UCHAR Lun;
    PSCSI_REQUEST_BLOCK srb;

    deviceExtension = HwDeviceExtension;
    eisaController = deviceExtension->EisaController;

    //
    // Disable interrupts to diminish the chance for other CPUs to "spin-lock"
    // for the same interrupt vector (multi-processor environment with dynamic
    // interrupt dispatching).
    //

    ScsiPortWritePortUchar(&eisaController->SystemDoorBellMask,
                           INTERRUPTS_DISABLE);

    //
    // Check interrupt pending.
    //

    if (!(ScsiPortReadPortUchar(&eisaController->SystemDoorBell) &
          INTERRUPT_PENDING)) {

        //
        // No interrupt is pending.
        // Enable interrupts.
        //

        ScsiPortWritePortUchar(&eisaController->SystemDoorBellMask,
			       INTERRUPTS_ENABLE);

	DebugPrint((2, "OliEsc1Interrupt: Unrecognized interrupt\n"));
        return FALSE;
    }

    //
    // Read interrupt status. The high byte is the adapter status, whereas
    // the low byte is the device status. If the device status is not zero,
    // an error will be returned, regardless of the adapter status.
    //

    interruptStatus = ScsiPortReadPortUshort(&eisaController->Status);

    //
    // Get physical address of CCB.
    //

    physicalCcb = ScsiPortReadPortUlong(&eisaController->OutAddress);

    //
    // Acknowledge interrupt.
    //

    ScsiPortWritePortUchar(&eisaController->SystemDoorBell, INTERRUPT_RESET);

    //
    // Unlock the Result Semaphore, so that the ESC-1 can load
    // new values in the output mailboxes.
    //

    ScsiPortWritePortUchar(&eisaController->ResultSemaphore, SEM_UNLOCK);

    //
    // Enable interrupts
    //

    ScsiPortWritePortUchar(&eisaController->SystemDoorBellMask,
                           INTERRUPTS_ENABLE);


    //
    // Get virtual CCB address.
    //

    ccb = ScsiPortGetVirtualAddress(deviceExtension, ScsiPortConvertUlongToPhysicalAddress(physicalCcb));

    //
    // Make sure the virtual address was found.
    //

    if (ccb == NULL) {

        //
        // A bad physcial address was return by the adapter.
        // Log it as an error.
        //

        ScsiPortLogError(
            deviceExtension,
            NULL,
            0,
            ADAPTER_ID,
            0,
            SP_INTERNAL_ADAPTER_ERROR,
            ESC1_BAD_PHYSICAL_ADDRESS | (ULONG) interruptStatus
            );

        return TRUE;
    }

    //
    // Get SRB from CCB.
    //

    srb = ccb->SrbAddress;

    DebugPrint((5,
	"OliEsc1Interrupt: ccb = %lx,  srb = %lx, Int Status = %x\n",
	 ccb, srb, interruptStatus));

    //
    // Check the adapter status.
    //

    switch (interruptStatus >> 8) {

    case NO_ERROR:

        //
        // Check the device status.
        //

        if ((interruptStatus & 0xff) != NO_ERROR) {

            //
            // The device status is not ok: return an error. This allows
            // the class driver to detect a media change on a removable disk
            // unit.
            //

	    DebugPrint((1, "OliEsc1Interrupt: Status = %x\n",
			   interruptStatus));
            srb->SrbStatus = SRB_STATUS_ERROR;
            srb->ScsiStatus = (UCHAR) (interruptStatus & 0xff);
        } else {
	    srb->SrbStatus = SRB_STATUS_SUCCESS;
	    srb->ScsiStatus = SCSISTAT_GOOD;
        }
        break;


    case SELECTION_TIMEOUT_EXPIRED:

        srb->SrbStatus = SRB_STATUS_SELECTION_TIMEOUT;
        break;

    case DATA_OVERRUN_UNDERRUN:

        srb->SrbStatus = SRB_STATUS_DATA_OVERRUN;

	//
	// On the ESC-1 it is not possible to distinguish the overrun error
	// from the underrun error.
	// We don't log the error because the underrun error can be very
	// common on some devices (example: scanner).
	//
	// ScsiPortLogError(
	//		 deviceExtension,
	//		 NULL,
	//		 0,
	//		 ADAPTER_ID,
	//		 0,
	//		 SP_INTERNAL_ADAPTER_ERROR,
	//		 DATA_OVERRUN_UNDERRUN
	//		 );
	//

        break;

    case UNEXPECTED_BUS_FREE:

        srb->SrbStatus = SRB_STATUS_UNEXPECTED_BUS_FREE;
        break;

    case SCSI_PHASE_SEQUENCE_FAILURE:

        srb->SrbStatus = SRB_STATUS_PHASE_SEQUENCE_FAILURE;
        break;

    case QUEUE_FULL:

        srb->SrbStatus = SRB_STATUS_BUSY;
        break;

    case PARITY_ERROR:

        //
        // This is a severe error. The controller is now shut down.
        //

        srb->SrbStatus = SRB_STATUS_PARITY_ERROR;

        ScsiPortLogError(
                        deviceExtension,
                        NULL,
                        0,
                        ADAPTER_ID,
                        0,
                        SP_BUS_PARITY_ERROR,
                        0
                        );
        break;
         
    case PROTOCOL_ERROR:

        //
        // Return bus reset error, because the bus has been reset.
        //

        srb->SrbStatus = SRB_STATUS_BUS_RESET;

        ScsiPortLogError(
                        deviceExtension,
                        NULL,
                        0,
                        ADAPTER_ID,
                        0,
                        SP_PROTOCOL_ERROR,
                        0
                        );
        break;
         
    case BUS_RESET_BY_TARGET:

        //
        // No error logging.
        //
        // Return bus reset error, because the bus has been reset.
        //

        srb->SrbStatus = SRB_STATUS_BUS_RESET;
        break;

    case UNEXPECTED_PHASE_CHANGE:

        //
        // This is a severe error. The controller is now shut down.
        //

    case PARITY_ERROR_DURING_DATA_PHASE:
    case AUTO_REQUEST_SENSE_FAILURE:
    case NO_REQUEST_SENSE_ISSUED:
    case INVALID_CONFIGURATION_COMMAND:
    case INVALID_CONFIGURATION_REGISTER:
    case INVALID_COMMAND:

        srb->SrbStatus = SRB_STATUS_ERROR;
	srb->ScsiStatus = SCSISTAT_GOOD;

        ScsiPortLogError(
                        deviceExtension,
                        NULL,
                        0,
                        ADAPTER_ID,
                        0,
                        SP_INTERNAL_ADAPTER_ERROR,
                        interruptStatus
                        );
        break;
         
    default:

	DebugPrint((1,
	    "OliEsc1Interrupt: Unrecognized interrupt status %x\n",
	     interruptStatus));

        srb->SrbStatus = SRB_STATUS_ERROR;
	srb->ScsiStatus = SCSISTAT_GOOD;

        ScsiPortLogError(
                        deviceExtension,
                        NULL,
                        0,
                        ADAPTER_ID,
                        0,
                        SP_INTERNAL_ADAPTER_ERROR,
                        interruptStatus
                        );

    } // end switch


    if (srb->Function == SRB_FUNCTION_ABORT_COMMAND ||
        srb->Function == SRB_FUNCTION_RESET_DEVICE) {

        if (srb->Function == SRB_FUNCTION_RESET_DEVICE) {

            //
            // Call notification routine for the SRB.
            //

            ScsiPortNotification(RequestComplete, (PVOID)deviceExtension, srb);

        }

        //
        // The interrupt refers to a Target Reset command issued
        // instead of the unsupported Abort command or to a real one.
        // All the pending requests for the target have to be completed
        // with status SRB_STATUS_BUS_RESET (any better idea?).
        //

        ScsiPortCompleteRequest(deviceExtension,
                                (UCHAR) 0,
                                srb->TargetId,
                                (UCHAR) ALL_LUNS,
                                (UCHAR) SRB_STATUS_BUS_RESET);

        //
        // Reset all the pending request counters for the target
        //

        for (Lun = 0; Lun < 8; Lun++) {
            LuExtension = ScsiPortGetLogicalUnit(deviceExtension,
                                                 0,
                                                 srb->TargetId,
                                                 Lun);

            if (LuExtension != NULL) {
                LuExtension->NumberOfPendingRequests = 0;
            }
        }
    } else {

        //
        // Decrement the pending requests counter for this (targetId, LUN)
        // pair
        //

        LuExtension = ScsiPortGetLogicalUnit(deviceExtension,
                                             0,
                                             srb->TargetId,
                                             srb->Lun);
        ASSERT(LuExtension);
        LuExtension->NumberOfPendingRequests--;
        ASSERT (LuExtension->NumberOfPendingRequests >= 0);

        //
        // Call notification routine for the SRB.
        //

        ScsiPortNotification(RequestComplete, (PVOID)deviceExtension, srb);
    }

    return TRUE;

} // end OliEsc1Interrupt()


BOOLEAN
OliEsc1ResetBus(
    IN PVOID HwDeviceExtension,
    IN ULONG PathId
)

/*++

Routine Description:

    Reset ESC-1 SCSI adapter and SCSI bus.

Arguments:

    HwDeviceExtension       Device extension for this driver
    PathId                  SCSI Bus path ID (always 0 for the ESC-1)

Return Value:

    Nothing.

--*/

{
    PHW_DEVICE_EXTENSION deviceExtension;
    PEISA_CONTROLLER eisaController;
    PLU_EXTENSION LuExtension;
    UCHAR Lun;
    UCHAR TargetId;

    UNREFERENCED_PARAMETER(PathId);

    DebugPrint((2,"OliEsc1ResetBus: Reset ESC-1 and SCSI bus\n"));

    //
    // Get the ESC-1 registers' base address
    //

    deviceExtension = HwDeviceExtension;
    eisaController = deviceExtension->EisaController;

    //
    // If the reset is already in progress, return TRUE.
    // This should never happen!
    //

    if (deviceExtension->ResetInProgress) {

	DebugPrint((2,"OliEsc1ResetBus: The reset is already in progess.\n"));
	return TRUE;
    }

    //
    // Issue a board reset
    //

    OliEsc1ResetAdapter(deviceExtension);

    //
    // Complete all outstanding requests with SRB_STATUS_BUS_RESET
    //

    ScsiPortCompleteRequest(deviceExtension,
                            (UCHAR) 0,
                            (UCHAR) ALL_TARGET_IDS,
                            (UCHAR) ALL_LUNS,
                            (UCHAR) SRB_STATUS_BUS_RESET);

    //
    // Reset to zero all the pending request counters
    //

    for (TargetId = 0; TargetId < 8; TargetId++) {
        for (Lun = 0; Lun < 8; Lun++) {
            LuExtension = ScsiPortGetLogicalUnit(deviceExtension,
                                                 0,
                                                 TargetId,
                                                 Lun);

            if (LuExtension != NULL) {
                LuExtension->NumberOfPendingRequests = 0;
            }
        }
    }

    //
    // Send a "reset detected" notification.
    //

    ScsiPortNotification(ResetDetected, deviceExtension, 0);

    return TRUE;

} // end Oliesc1ResetBus

BOOLEAN
OliEsc1StartIo(
    IN PVOID HwDeviceExtension,
    IN PSCSI_REQUEST_BLOCK Srb
    )

/*++

Routine Description:

    This routine is called from the SCSI port driver synchronized
    with the kernel to send a CCB or issue an immediate command.

Arguments:

    HwDeviceExtension       Device extension for this driver
    Srb                     Pointer to the Scsi Request Block to service

Return Value:

    Nothing

--*/

{
    PHW_DEVICE_EXTENSION deviceExtension;
    PEISA_CONTROLLER eisaController;
    PLU_EXTENSION luExtension;
    PCCB ccb;
    UCHAR opCode;
    BOOLEAN Send;

    DebugPrint((3,"OliEsc1StartIo: Enter routine\n"));

    //
    // Get the base address of the ESC-1 registers' address space
    //

    deviceExtension = HwDeviceExtension;
    eisaController = deviceExtension->EisaController;

    //
    // If the "ResetInProgress" flag is TRUE, no SRBs are allowed to go
    // through because the SCSI controller needs more time to complete its
    // initialization.
    //

    if (deviceExtension->ResetInProgress) {

	DebugPrint((2,"OliEsc1StartIo: The reset is not completed yet.\n"));

	//
	// Complete the current request.
	//

	Srb->SrbStatus = SRB_STATUS_BUS_RESET;
	ScsiPortNotification(RequestComplete, deviceExtension, Srb);

	//
	// Notify that a reset was detected on the SCSI bus.
	//

	ScsiPortNotification(ResetDetected, deviceExtension, 0);

	//
	// The controller is now ready for the next request.
	//

	ScsiPortNotification(NextRequest, deviceExtension, NULL);

	return(TRUE);
    }

    //
    // Assume we are going to send a command to the ESC-1
    //

    Send = TRUE;

    //
    // Get CCB from SRB
    //

    ccb = Srb->SrbExtension;

    //
    // Save SRB back pointer in CCB
    //

    ccb->SrbAddress = Srb;

    //
    // Get the pointer to the extension data area associated with the
    // pair (Srb->TargetId, Srb->Lun)
    //

    luExtension = ScsiPortGetLogicalUnit(deviceExtension,
                                         0,
                                         Srb->TargetId,
                                         Srb->Lun);
    ASSERT(luExtension);

    switch (Srb->Function) {

    case SRB_FUNCTION_EXECUTE_SCSI:

        if (Srb->TargetId == ADAPTER_ID) {

            //
            // No SCSI massages directed to the adatpter are let
            // go through, because the adapter doesn't support any
            //

	    DebugPrint((1,
		"OliEsc1StartIo: SCSI command to adapter rejected\n"));
            Srb->SrbStatus = SRB_STATUS_NO_DEVICE;
            ScsiPortNotification(RequestComplete, deviceExtension, Srb);
            Send = FALSE;

        } else {

            //
            // Increment the number of pending requests for this (targetId,
            // LUN), so that we can process an abort request in case this
            // command gets timed out
            //

            luExtension->NumberOfPendingRequests++;

            //
            // Build CCB.
            //

	    OliEsc1BuildCcb(deviceExtension, Srb);

            opCode = START_CCB;
        }

        break;

    case SRB_FUNCTION_ABORT_COMMAND:

	DebugPrint((1,
	    "OliEsc1StartIo: Abort Cmd Target ID %d\n", Srb->TargetId));
        //
        // The Abort command is not supported by the ESC-x. Here we do what
        // we can.
        //

        if (luExtension->NumberOfPendingRequests) {

            //
            // A command sent to a device has to be aborted.
            // All we can do is to reset the target.
            //

	    OliEsc1BuildCcb(deviceExtension, Srb);
            opCode = RESET_TARGET;

        } else {

            //
            // The request to abort has already completed.
            //

	    Srb->SrbStatus = SRB_STATUS_ABORT_FAILED;
            ScsiPortNotification(RequestComplete, deviceExtension, Srb);
            Send = FALSE;
        }

        break;

    case SRB_FUNCTION_RESET_BUS:

        //
        // Reset ESC-1 and SCSI bus.
        //

	DebugPrint((1, "OliEsc1StartIo: Reset bus request received\n"));

	//
	// The following routine will ...
	//
	//  a) reset the bus.
	//  b) complete all the active requests (including this one).
	//  c) notify that a reset was detected on the SCSI bus.
	//

	OliEsc1ResetBus(deviceExtension, (ULONG) NULL);

        Send = FALSE;
        break;

    case SRB_FUNCTION_RESET_DEVICE:

        if (Srb->TargetId == ADAPTER_ID) {

            //
            // No SCSI massages directed to the adatpter are let
            // go through, because the adapter doesn't support any
            //

	    DebugPrint((1,
		"OliEsc1StartIo: Reset Device sent to the adapter rjected\n"));
            Srb->SrbStatus = SRB_STATUS_NO_DEVICE;
            ScsiPortNotification(RequestComplete, deviceExtension, Srb);
            Send = FALSE;

        } else {

            //
            // Increment the number of pending requests for this (targetId,
            // LUN), so that we can process an abort request in case this
            // command gets timed out
            //

	    DebugPrint((4,"OliEsc1StartIo: Reset device ID %d\n",
			   Srb->TargetId));
	    OliEsc1BuildCcb(deviceExtension, Srb);
            opCode = RESET_TARGET;
        }
        break;

    default:

        //
        // Set error and complete request
        //

	DebugPrint((1,"OliEsc1StartIo: Invalid Request\n"));

        Srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;

        ScsiPortNotification(RequestComplete, deviceExtension, Srb);

        Send = FALSE;

    } // end switch

    if (Send) {
	if (!OliEsc1SendCommand(deviceExtension, opCode, ccb)) {

	    DebugPrint((1,"OliEsc1StartIo: Send command timed out\n"));

            //
            // Let operating system time out SRB.
            //
        }
    }

    //
    // Adapter ready for next request.
    //

    ScsiPortNotification(NextRequest, deviceExtension, NULL);

    return TRUE;

} // end OliEsc1StartIo()



VOID
OliEsc1ResetAdapter(
    IN PVOID Context
    )

/*++

Routine Description:

    The routine resets the SCSI controller.

Arguments:

    Context	    Device adapter context pointer.

Return Value:

    None.

--*/

{
    PHW_DEVICE_EXTENSION deviceExtension;
    PEISA_CONTROLLER eisaController;
    ULONG Delay;
    BOOLEAN Error = FALSE;

    deviceExtension = Context;
    eisaController = deviceExtension->EisaController;

    //
    // The routine releases the control of the CPU while waiting for some
    // status/interrupt, this is required  because the reset/re-initialization
    // of the controller can take several seconds.
    //
    // Reset Controller:
    //
    // Phase 0: Reset the controller.
    // Phase 1: Waiting for the controller to complete its initialization.
    // Phase 2: Small delay.
    //

    switch(deviceExtension->ResetInProgress) {

    //
    // Phase 0: Reset the controller.
    //

    case 0:

	//////////////////////////////////////////////////////////////////////
	//
	// Disable interrupts.
	//

	ScsiPortWritePortUchar(&eisaController->SystemDoorBellMask,
			       INTERRUPTS_DISABLE);

	//////////////////////////////////////////////////////////////////////
	//
	// Reset controller.
	//

	DebugPrint((3,
	   "OliEsc1ResetAdapter: Phase 1 (reset adapter) max time = %ld us.\n",
	    ESC_RESET_DELAY + ESC_RESET_INTERVAL * ESC_RESET_LOOPS
	    ));

	//
	// Initialize the output location to a known value.
	//

	ScsiPortWritePortUchar( (PUCHAR)&eisaController->Status,
				(UCHAR)(~DIAGNOSTICS_OK_NO_CONFIG_RECEIVED));

	//
	// Reset ESC-1 and SCSI bus. Wait to allow the
	// board diagnostics to complete
	//

	ScsiPortWritePortUchar(&eisaController->LocalDoorBell, ADAPTER_RESET);

	//
	// Request a timer call to complete the reset.
	//

	deviceExtension->ResetTimerCalls = ESC_RESET_LOOPS + 1;
	Delay = ESC_RESET_DELAY;

	//
	// The "ResetNotification" variable is used to keep track of the
	// time during the reset.  If the reset is not completed before
	// the next ESC1_RESET_NOTIFICATION usec. unit, we call the
	// "ScsiPortNotification(ResetDetected...)" routine.
	// After the call the ScsiPort stops the delivery of SRBs for a
	// little bit (~4 sec.).
	//

	deviceExtension->ResetNotification = 0;
	deviceExtension->ResetInProgress++;
	break;

    //
    // Phase 1: Waiting for the controller to complete its initialization.
    //

    case 1:

	//
	// Note that after a reset the LOW byte of the Status register is
	// loaded with the diagnostics result code. This should be the
	// only case, since usually the high byte reports the adapter status.
	//

	if ( (UCHAR)ScsiPortReadPortUshort(&eisaController->Status) !=
		 DIAGNOSTICS_OK_NO_CONFIG_RECEIVED ) {

	    Delay = ESC_RESET_INTERVAL;
	    break;
	}

	//
	// Reset completed!
	//

	DebugPrint((1,
	   "OliEsc1ResetAdapter: Reset bus succeeded after %ld us\n",
	    ESC_RESET_DELAY + ESC_RESET_INTERVAL *
	    (ESC_RESET_LOOPS - deviceExtension->ResetTimerCalls)
	    ));

        //
        // The following delay is necessary because the adapter, immediately
        // after a reset, is insensitive to interrupts through the Local
        // Doorbell Register for almost 50ms. This shouldn't be and needs
        // to be investigated further. After the adapter has accepted the very
	// first command (see OliEsc1GetIrql()), it take 500ms to return the answer to
        // the CPU (i.e., to generate an interrupt). The very first command sent
        // to the adapter is a "Get Configuration" to read the IRQL register
        // at system boot time
        //

	deviceExtension->ResetTimerCalls = 1;
	Delay = POST_RESET_DELAY;
	deviceExtension->ResetInProgress++;
	break;

    //
    // Phase 2: Small delay.
    //

    case 2:

	//////////////////////////////////////////////////////////////////////
	//
	// Remove any interrupt that was pending before issuing the reset.
	// The controller doesn't reset these interrupts.
        //

        if (ScsiPortReadPortUchar(&eisaController->SystemDoorBell) &
	    INTERRUPT_PENDING) {

	    DebugPrint((3,
		"OliEsc1ResetAdapter: The HP interrupt was pending.\n"));

            //
            // Reset the interrupt
            //

            ScsiPortWritePortUchar(&eisaController->SystemDoorBell,
                                   INTERRUPT_PENDING);
        }

	//////////////////////////////////////////////////////////////////////
	//
	// Enable interrupts.
        //

        ScsiPortWritePortUchar(&eisaController->SystemDoorBellMask,
			       INTERRUPTS_ENABLE);

	//////////////////////////////////////////////////////////////////////
	//
	// All done !
	//

	deviceExtension->ResetInProgress = 0;
	return;

    default:

	//
	// Invalid reset phase number.	This should never happen!
	//

	DebugPrint((1,
	    "OliEsc1ResetAdapter: Invalid reset phase number: %x hex.\n",
	     deviceExtension->ResetInProgress ));

	ASSERT(0);

	Error = TRUE;
	break;
    }

    //
    // If no error, request a timer call.
    //

    if (!Error) {

	//
	// Check if time-out.
	//

	if (deviceExtension->ResetTimerCalls--) {

	    //
	    // Request a timer call.
	    //

	    ScsiPortNotification(RequestTimerCall,
				 deviceExtension,
				 OliEsc1ResetAdapter,
				 Delay);

	    //
	    // The "ResetNotification" variable is used to keep track of the
	    // time during the reset.  If the reset is not completed before
	    // the next ESC1_RESET_NOTIFICATION usec. unit, we call the
	    // "ScsiPortNotification(ResetDetected...)" routine.
	    // After the call the ScsiPort stops the delivery of SRBs for a
	    // little bit (~4 sec.).
	    //

	    if (deviceExtension->ResetNotification >= ESC1_RESET_NOTIFICATION) {

		//
		// Notify that a reset was detected on the SCSI bus.
		//

		ScsiPortNotification(ResetDetected, deviceExtension, 0);

		//
		// Reset the "reset notification timer".
		//

		deviceExtension->ResetNotification = 0;
	    }

	    //
	    // Update the "reset notification timer".
	    //

	    deviceExtension->ResetNotification += Delay;
	}
	else {

	    //
	    // Time-out !
	    //

	    DebugPrint((1,
		"OliEsc1ResetAdapter: Time-out! Reset phase number: %x hex.\n",
		 deviceExtension->ResetInProgress ));

	    Error = TRUE;
	}
    }

    //
    // If error, log it.
    //

    if (Error) {

	//
	// Log an error.
	//

	ScsiPortLogError(
		deviceExtension,
		NULL,
		0,
		ADAPTER_ID,
		0,
		SP_INTERNAL_ADAPTER_ERROR,
		ESCX_RESET_FAILED
		);

	//
	// We clear the "ResetInProgress" variable to force another SCSI
	// bus reset when the driver receives the first SRB request.
	// Note that the interrupts are left disabled at the controller level.
	//

	deviceExtension->ResetInProgress = 0;
    }

    //
    // Done for now.
    //

    return;

} // end OliEsc1ResetAdapter



BOOLEAN
OliEsc1SendCommand(
    IN PHW_DEVICE_EXTENSION DeviceExtension,
    IN UCHAR OperationCode,
    IN PCCB ccb
    )

/*++

Routine Description:

    Send a Command Control Block to ESC-1.

Arguments:

    DeviceExtension     Device extension for this driver
    OperationCode       Command for the ESC-1
    ccb                 Pointer to the CCB

Return Value:

    True if command was sent.
    False if the Command Semaphore was busy.

--*/

{

    PEISA_CONTROLLER EisaController;
    ULONG physicalCcb;
    ULONG length;

    //
    // Get the base address of the ESC-1 registers' address space
    //

    EisaController = DeviceExtension->EisaController;

    length = 0;

    //
    // Get the CCB physical address
    //

    physicalCcb =
        ScsiPortConvertPhysicalAddressToUlong(
            ScsiPortGetPhysicalAddress(DeviceExtension, NULL, ccb, &length));

    ASSERT (length >= sizeof(CCB));

    return(OliEsc1SendCommandQuick(EisaController, ccb->TaskId, OperationCode,
                            (USHORT) (CCB_FIXED_LENGTH + ccb->CdbLength),
                            physicalCcb));

}

BOOLEAN
OliEsc1SendCommandQuick(
    IN PEISA_CONTROLLER EisaController,
    IN UCHAR TaskId,
    IN UCHAR OperationCode,
    IN USHORT CommandLength,
    IN ULONG Address
    )

/*++

Routine Description:

    Send CCB or immediate command to ESC-1.

Arguments:

    EisaController      Base address of the ESC-1 registers' address space
    TaskId              Task ID for the ESC-1
    OperationCode       Command code for the ESC-1
    CommandLength       Total CCB length
    Address             Physical address of the CCB

Return Value:

    True if the command was sent.
    False if the Command Semaphore was busy.

--*/

{
    ULONG i;
    BOOLEAN ReturnCode = FALSE;

    //
    // Try to send the command for up to 100 microsends
    //

    for (i = 0; i < 100; i++) {


        ScsiPortWritePortUchar(&EisaController->CommandSemaphore, SEM_LOCK);

        if ((ScsiPortReadPortUchar(&EisaController->CommandSemaphore) &
            SEM_TAKEN_MASK) == SEM_TAKEN) {

            //
            // We can send a command to the ESC-1.
            //

            ScsiPortWritePortUchar(&EisaController->InTaskId, TaskId);
            ScsiPortWritePortUchar(&EisaController->Command, OperationCode);
            ScsiPortWritePortUshort(&EisaController->CommandLength,
                                    CommandLength);
            ScsiPortWritePortUlong(&EisaController->InAddress, Address);

            //
            // Send an attention interrupt to the adapter.
            //

            ScsiPortWritePortUchar(&EisaController->LocalDoorBell,
                                    INTERRUPT_PENDING);

            ReturnCode = TRUE;
            break;
        }

        //
        // Stall execution for 1 microsecond.
        //

        ScsiPortStallExecution(1);
    }

    return ReturnCode;

} // end OliEsc1SendCommand()