280 ULONG waitCount = 20000;
308 "IssueIdentify: Checking for IDE. Status (%x)\n",
331 if (signatureLow == 0x14 && signatureHigh == 0xEB) {
341 "IssueIdentify: Resetting controller.\n"));
373 if (signatureLow == 0x14 && signatureHigh == 0xEB) {
382 statusByte &= ~IDE_STATUS_INDEX;
398 "IssueIdentify: Checking for ATAPI. Status (%x)\n",
410 for (
j = 0;
j < 2;
j++) {
424 for (
i = 0;
i < 4;
i++) {
444 if (signatureLow == 0x14 && signatureHigh == 0xEB) {
465 if (signatureLow == 0x14 && signatureHigh == 0xEB) {
478 if (
i == 4 &&
j == 0) {
485 "IssueIdentify: DRQ never asserted (%x). Error reg (%x)\n",
494 "IssueIdentify: Status after soft reset (%x)\n",
514 "IssueIdentify: Status before read words %x\n",
542 DebugPrint((2,
"IssueIdentify: Marking drive %d as removable. SFE = %d\n",
573 "IssueIdentify: Device interrupts on assertion of DRQ.\n"));
578 "IssueIdentify: Device does not interrupt on assertion of DRQ.\n"));
591 "IssueIdentify: Device is a tape drive.\n"));
596 "IssueIdentify: Device is not a tape drive.\n"));
606 for (
i = 0;
i < 0x10000;
i++) {
626 "IssueIdentify: Status after read words (%x)\n",
669 "SetDriveParameters: Number of heads %x\n",
673 "SetDriveParameters: Sectors per track %x\n",
697 for (
i=0;
i<30 * 1000;
i++) {
706 "SetDriveParameters: Error bit set. Status %x, error %x\n",
722 if (
i == 30 * 1000) {
764 DebugPrint((2,
"AtapiResetController: Reset IDE\n"));
814 for (
j = 0;
j < numberChannels;
j++) {
823 for (
i = 0;
i < 2;
i++) {
843 "AtapiResetController: Status before Atapi reset (%x).\n",
850 if (statusByte == 0x0) {
859 "AtapiResetController: Status after soft reset %x\n",
884 "AtapiResetController: SetDriveParameters failed\n"));
942 "MapError: Error register is %x\n",
947 switch (errorByte >> 4) {
951 "ATAPI: No sense information\n"));
959 "ATAPI: Recovered error\n"));
967 "ATAPI: Device not ready\n"));
975 "ATAPI: Media error\n"));
983 "ATAPI: Hardware error\n"));
991 "ATAPI: Illegal request\n"));
999 "ATAPI: Unit attention\n"));
1007 "ATAPI: Data protect\n"));
1015 "ATAPI: Blank check\n"));
1022 "Atapi: Command Aborted\n"));
1030 "ATAPI: Invalid sense information\n"));
1048 "IDE: Media change\n"));
1054 "IDE: Command abort\n"));
1063 senseBuffer->
Valid = 1;
1077 "IDE: End of media\n"));
1087 "IDE: Illegal length\n"));
1093 "IDE: Bad block\n"));
1101 senseBuffer->
Valid = 1;
1113 "IDE: Id not found\n"));
1122 senseBuffer->
Valid = 1;
1136 "IDE: Media change\n"));
1145 senseBuffer->
Valid = 1;
1157 "IDE: Data error\n"));
1174 senseBuffer->
Valid = 1;
1189 "MapError: Disabling 32-bit PIO and Multi-sector IOs\n"));
1206 for (
i = 0;
i < 4;
i++) {
1217 (
UCHAR)(((
i & 0x1) << 4) | 0xA0));
1253 "AtapiHwInitialize: Error setting multiple mode. Status %x, error byte %x\n",
1305 UCHAR statusByte, errorByte;
1308 for (
i = 0;
i < 4;
i++) {
1331 (
UCHAR)(((
i & 0x1) << 4) | 0xA0));
1367 "AtapiHwInitialize: Error setting multiple mode. Status %x, error byte %x\n",
1378 "AtapiHwInitialize: Using Multiblock on Device %d. Blocks / int - %d\n",
1392 for (
j = 0;
j < 13;
j += 2) {
1408 if (vendorId[12] ==
'C') {
1457 }
while (waitCount--);
1476 if (MechanismStatus) {
1519 skipSetParameters =
FALSE;
1520 ULONG waitCount = 10000;
1538 for (deviceNumber = 0; deviceNumber < 2; deviceNumber++) {
1545 (
UCHAR)((deviceNumber << 4) | 0xA0));
1552 if (statusByte == 0xFF) {
1562 if (signatureLow == 0x14 && signatureHigh == 0xEB) {
1588 "FindDevices: Device %x is ATAPI\n",
1594 deviceResponded =
TRUE;
1609 "FindDevices: Device %x not responding\n",
1635 "FindDevices: Device %x is IDE\n",
1641 deviceResponded =
TRUE;
1664 if (signatureLow == 0x14 && signatureHigh == 0xEB) {
1671 for (
i = 0;
i < 2;
i++) {
1688 "FindDevices: Found nasty Compaq ESDI!\n"));
1706 "FindDevices: Found nasty Compaq ESDI!\n"));
1725 "FindDevices: Found nasty UltraStor ESDI!\n"));
1735 skipSetParameters =
TRUE;
1739 if (!skipSetParameters) {
1748 (
UCHAR)((
i << 4) | 0xA0));
1759 "FindDevices: Resetting controller before SetDriveParameters.\n"));
1765 (
UCHAR)((
i << 4) | 0xA0));
1781 "FindDevices: Status before SetDriveParameters: (%x) (%x)\n",
1792 "AtapHwInitialize: Set drive parameters for device %d failed\n",
1818 deviceResponded =
TRUE;
1838 if (!deviceResponded) {
1845 return deviceResponded;
1880 ULONG stringLength = 0;
1881 ULONG keyWordLength = 0;
1897 if (*cptr >=
'A' && *cptr <=
'Z') {
1898 *cptr = *cptr + (
'a' -
'A');
1911 if (*cptr >=
'A' && *cptr <=
'Z') {
1912 *cptr = *cptr + (
'a' -
'A');
1918 if (keyWordLength > stringLength) {
1939 while (*cptr ==
' ' || *cptr ==
'\t') {
1943 if (*cptr ==
'\0') {
1953 while (*cptr++ == *kptr++) {
1955 if (*(cptr - 1) ==
'\0') {
1965 if (*(kptr - 1) ==
'\0') {
1972 while (*cptr ==
' ' || *cptr ==
'\t') {
1987 if (*cptr++ ==
';') {
1988 goto ContinueSearch;
2004 while ((*cptr ==
' ') || (*cptr ==
'\t')) {
2008 if (*cptr ==
'\0') {
2024 goto ContinueSearch;
2028 if ((*cptr ==
'0') && (*(cptr + 1) ==
'x')) {
2037 if (*(cptr +
index) ==
' ' ||
2038 *(cptr +
index) ==
'\t' ||
2039 *(cptr +
index) ==
';') {
2043 if ((*(cptr +
index) >=
'0') && (*(cptr +
index) <=
'9')) {
2046 if ((*(cptr +
index) >=
'a') && (*(cptr +
index) <=
'f')) {
2065 if (*(cptr +
index) ==
' ' ||
2066 *(cptr +
index) ==
'\t' ||
2067 *(cptr +
index) ==
';') {
2071 if ((*(cptr +
index) >=
'0') && (*(cptr +
index) <=
'9')) {
2091 if (*cptr++ ==
';') {
2092 goto ContinueSearch;
2155 CONST ULONG AdapterAddresses[5] = {0x1F0, 0x170, 0x1e8, 0x168, 0};
2162 CONST ULONG InterruptLevels[5] = {14, 15, 11, 10, 0};
2164 if (!deviceExtension) {
2173 if (ArgumentString) {
2201 ConfigInfo->AdapterInterfaceType,
2202 ConfigInfo->SystemIoBusNumber,
2203 (*ConfigInfo->AccessRanges)[0].RangeStart,
2204 (*ConfigInfo->AccessRanges)[0].RangeLength,
2205 (
BOOLEAN) !((*ConfigInfo->AccessRanges)[0].RangeInMemory));
2217 while (AdapterAddresses[*adapterCount] != 0) {
2221 for (
i = 0;
i < 4;
i++) {
2241 if (preConfig ==
FALSE) {
2245 ConfigInfo->AdapterInterfaceType,
2246 ConfigInfo->SystemIoBusNumber,
2252 ConfigInfo->AdapterInterfaceType,
2253 ConfigInfo->SystemIoBusNumber,
2295 "AtapiFindController: Identifier read back from Master (%x)\n",
2313 "AtapiFindController: First access to status %x\n",
2318 goto retryIdentifier;
2337 "AtapiFindController: Identifier read back from Slave (%x)\n",
2361 if (preConfig ==
FALSE) {
2371 (*ConfigInfo->AccessRanges)[0].RangeStart =
2375 (*ConfigInfo->AccessRanges)[0].RangeLength = 8;
2376 (*ConfigInfo->AccessRanges)[0].RangeInMemory =
FALSE;
2383 ConfigInfo->BusInterruptLevel =
irq;
2385 ConfigInfo->BusInterruptLevel = InterruptLevels[*adapterCount - 1];
2388 if (ConfigInfo->AdapterInterfaceType ==
MicroChannel) {
2391 ConfigInfo->InterruptMode =
Latched;
2401 ConfigInfo->AdapterInterfaceType,
2402 ConfigInfo->SystemIoBusNumber,
2408 ConfigInfo->AdapterInterfaceType,
2409 ConfigInfo->SystemIoBusNumber,
2419 ConfigInfo->NumberOfBuses = 1;
2420 ConfigInfo->MaximumNumberOfTargets = 2;
2426 ConfigInfo->MaximumTransferLength = 0x10000;
2429 "AtapiFindController: Found IDE at %x\n",
2438 if (preConfig ==
FALSE) {
2441 if (*adapterCount - 1 < 2) {
2448 if (ArgumentString) {
2452 "AtapiFindController: Crash dump\n"));
2457 "AtapiFindController: Atapi Only\n"));
2464 "AtapiFindController: Atapi Only\n"));
2480 slotData.
u.
bits.DeviceNumber = 0;
2481 slotData.
u.
bits.FunctionNumber = 0;
2532 ConfigInfo->AtdiskSecondaryClaimed =
TRUE;
2536 ConfigInfo->AtdiskPrimaryClaimed =
TRUE;
2543 if (*adapterCount == 1) {
2544 ConfigInfo->AtdiskPrimaryClaimed =
TRUE;
2546 }
else if (*adapterCount == 2) {
2547 ConfigInfo->AtdiskSecondaryClaimed =
TRUE;
2563 *(adapterCount) = 0;
2603 ULONG functionNumber;
2606 UCHAR vendorString[5];
2607 UCHAR deviceString[5];
2623 slotData.
u.
bits.DeviceNumber = slotNumber;
2629 for (functionNumber= *FunctionNumber;
2633 slotData.
u.
bits.FunctionNumber = functionNumber;
2664 vendorStrPtr = vendorString;
2665 deviceStrPtr = deviceString;
2670 "FindBrokenController: Bus %x Slot %x Function %x Vendor %s Product %s\n",
2695 *FunctionNumber = functionNumber;
2701 *FunctionNumber = 0;
2749 deviceFound =
FALSE;
2755 UCHAR vendorString[5];
2756 UCHAR deviceString[5];
2767 CONST ULONG AdapterAddresses[3] = {0x1F0, 0x170, 0};
2769 if (!deviceExtension) {
2776 slotData.
u.
bits.DeviceNumber = ConfigInfo->SlotNumber;
2778 for (funcNumber= 0; funcNumber < 8; funcNumber++) {
2780 slotData.
u.
bits.FunctionNumber = funcNumber;
2784 ConfigInfo->SystemIoBusNumber,
2788 if (busDataRead !=
sizeof (pciData)) {
2799 vendorStrPtr = vendorString;
2800 deviceStrPtr = deviceString;
2817 if (pciData.ProgIf & ((1 << 2) | (1 << 0))) {
2827 if (*Again !=
FALSE) {
2829 for (channel = 0; channel < 2; channel++) {
2831 IoBasePort1 = (*ConfigInfo->AccessRanges)[channel * 2 + 0].RangeStart;
2832 IoBasePort2 = (*ConfigInfo->AccessRanges)[channel * 2 + 1].RangeStart;
2840 ConfigInfo->AdapterInterfaceType,
2841 ConfigInfo->SystemIoBusNumber,
2873 "AtapiFindPciController: Identifier read back from Master (%x)\n",
2892 "AtapiFindPciController: Identifier read back from Slave (%x)\n",
2910 goto setStatusAndExit;
2929 ConfigInfo->AdapterInterfaceType,
2930 ConfigInfo->SystemIoBusNumber,
2943 ConfigInfo->NumberOfBuses = 1;
2950 ConfigInfo->MaximumNumberOfTargets = 4;
2956 ConfigInfo->MaximumTransferLength = 0x10000;
2959 "AtapiFindPciController: Found native mode IDE at %x\n",
2988 ConfigInfo->AtdiskPrimaryClaimed =
TRUE;
2992 ConfigInfo->AtdiskSecondaryClaimed =
TRUE;
3049 static ULONG functionNumber,
3056 controllerFound =
FALSE,
3057 deviceFound =
FALSE;
3065 CONST ULONG AdapterAddresses[5] = {0x1F0, 0x170, 0x1e8, 0x168, 0};
3072 CONST ULONG InterruptLevels[5] = {14, 15, 11, 10, 0};
3074 if (!deviceExtension) {
3119 ConfigInfo->SystemIoBusNumber,
3124 controllerFound =
TRUE;
3127 "Found broken PCI IDE controller: VendorId %s, DeviceId %s\n",
3131 if (AdapterAddresses[*adapterCount] != 0) {
3133 for (
j = 0;
j < 2;
j++) {
3140 ConfigInfo->AdapterInterfaceType,
3141 ConfigInfo->SystemIoBusNumber,
3179 "AtapiFindPciController: Identifier read back from Master (%x)\n",
3198 "AtapiFindPciController: Identifier read back from Slave (%x)\n",
3216 goto setStatusAndExit;
3224 if (controllerFound) {
3236 (*ConfigInfo->AccessRanges)[channel].RangeStart =
3239 (*ConfigInfo->AccessRanges)[channel].RangeLength = 8;
3240 (*ConfigInfo->AccessRanges)[channel].RangeInMemory =
FALSE;
3247 ConfigInfo->BusInterruptLevel = InterruptLevels[*adapterCount - 1];
3248 ConfigInfo->InterruptMode =
Latched;
3250 ConfigInfo->BusInterruptLevel2 = InterruptLevels[*adapterCount - 1];
3251 ConfigInfo->InterruptMode2 =
Latched;
3259 ConfigInfo->AdapterInterfaceType,
3260 ConfigInfo->SystemIoBusNumber,
3273 ConfigInfo->NumberOfBuses = 1;
3280 ConfigInfo->MaximumNumberOfTargets = 4;
3286 ConfigInfo->MaximumTransferLength = 0x10000;
3289 "AtapiFindPciController: Found broken IDE at %x\n",
3317 if (*adapterCount == 1) {
3318 ConfigInfo->AtdiskPrimaryClaimed =
TRUE;
3321 }
else if (*adapterCount == 2) {
3322 ConfigInfo->AtdiskSecondaryClaimed =
TRUE;
3339 if (controllerFound && deviceFound) {
3362 IN char *DataBuffer,
3366 ULONG bytesAdjust = 0;
3405 return bytesAdjust >> 1;
3429 "AtapiCallBack: Invalid CDB marked as RDP - %x\n",
3435 if (deviceExtension->
RDP) {
3464 "AtapiCallBack: Requesting another timer for Op %x\n",
3477 "AtapiCallBack: Calling ISR directly due to BUSY\n"));
3509 ULONG wordCount = 0, wordsThisInterrupt = 256;
3512 UCHAR statusByte,interruptReason;
3520 "AtapiInterrupt: CurrentSrb is NULL\n"));
3555 "AtapiInterrupt: Unexpected interrupt.\n"));
3566 "AtapiInterrupt: Entered with status (%x)\n",
3579 "AtapiInterrupt: Hit BUSY while polling during crashdump.\n"));
3588 for (
i = 0;
i < 10;
i++) {
3600 "AtapiInterrupt: BUSY on entry. Status %x, Base IO %x\n",
3638 wordsThisInterrupt = 256;
3651 interruptReason = 0x2;
3654 interruptReason = 0x0;
3676 for (
k = 0;
k < 5000;
k++) {
3692 "AtapiInterrupt: Resetting due to DRQ not up. Status %x, Base IO %x\n",
3710 interruptReason = 0x3;
3722 "AtapiInterrupt: Writing Atapi packet.\n"));
3734 }
else if (interruptReason == 0x0 && (statusByte &
IDE_STATUS_DRQ)) {
3758 if (wordCount != deviceExtension->
WordsLeft) {
3760 "AtapiInterrupt: %d words requested; %d words xferred\n",
3769 if (wordCount > deviceExtension->
WordsLeft) {
3779 if (deviceExtension->
WordsLeft < wordsThisInterrupt) {
3793 wordCount = wordsThisInterrupt;
3804 "AtapiInterrupt: Write interrupt\n"));
3808 if (atapiDev || !deviceExtension->
DWordIO) {
3824 "AtapiInterrupt: Int reason %x, but srb is for a write %x.\n",
3842 deviceExtension->
WordsLeft -= wordCount;
3846 }
else if (interruptReason == 0x2 && (statusByte &
IDE_STATUS_DRQ)) {
3867 if (wordCount != deviceExtension->
WordsLeft) {
3869 "AtapiInterrupt: %d words requested; %d words xferred\n",
3878 if (wordCount > deviceExtension->
WordsLeft) {
3888 if (deviceExtension->
WordsLeft < wordsThisInterrupt) {
3902 wordCount = wordsThisInterrupt;
3913 "AtapiInterrupt: Read interrupt\n"));
3917 if (atapiDev || !deviceExtension->
DWordIO) {
3932 "AtapiInterrupt: Int reason %x, but srb is for a read %x.\n",
3963 deviceExtension->
WordsLeft -= wordCount;
3979 if ((srb->
Cdb[0] == 0x25) &&
3983 if (deviceExtension->
DataBuffer[0] == 0x00) {
4016 }
else if (interruptReason == 0x3 && !(statusByte &
IDE_STATUS_DRQ)) {
4143 for (
i = 0;
i < 30;
i++) {
4158 "AtapiInterrupt: Resetting due to BSY still up - %x. Base Io %x\n",
4171 for (
i = 0;
i < 500;
i++) {
4187 "AtapiInterrupt: Resetting due to DRQ still up - %x\n",
4243 if (!(deviceExtension->
RDP)) {
4295 "AtapiInterrupt: No SRB!\n"));
4302 if (!(deviceExtension->
RDP)) {
4330 "AtapiInterrupt: Unexpected interrupt. InterruptReason %x. Status %x.\n",
4373 UCHAR statusByte,targetId;
4401 "IdeSendSmartCommand: Returning BUSY status\n"));
4410 ((
PUCHAR)cmdOutParameters)[
i] = 0;
4451 "IdeSendSmartCommand: Returning BUSY status\n"));
4460 ((
PUCHAR)cmdOutParameters)[
i] = 0;
4527 UCHAR statusByte,statusByte2;
4528 UCHAR cylinderHigh,cylinderLow,drvSelect,sectorNumber;
4541 "IdeReadWrite: Returning BUSY status\n"));
4569 startingSector = ((
PCDB)
Srb->
Cdb)->CDB10.LogicalBlockByte3 |
4570 ((
PCDB)
Srb->
Cdb)->CDB10.LogicalBlockByte2 << 8 |
4571 ((
PCDB)
Srb->
Cdb)->CDB10.LogicalBlockByte1 << 16 |
4572 ((
PCDB)
Srb->
Cdb)->CDB10.LogicalBlockByte0 << 24;
4575 "IdeReadWrite: Starting sector is %x, Number of bytes %x\n",
4611 "IdeReadWrite: Cylinder %x Head %x Sector %x\n",
4649 if (deviceExtension->
WordsLeft < wordCount) {
4676 "IdeReadWrite 2: Returning BUSY status %x\n",
4681 for (
i = 0;
i < 1000;
i++) {
4693 "IdeReadWrite: DRQ never asserted (%x) original status (%x)\n",
4726 deviceExtension->
WordsLeft -= wordCount;
4769 ULONG startingSector;
4783 "IdeVerify: Total sectors %x\n",
4790 startingSector = ((
PCDB)
Srb->
Cdb)->CDB10.LogicalBlockByte3 |
4791 ((
PCDB)
Srb->
Cdb)->CDB10.LogicalBlockByte2 << 8 |
4792 ((
PCDB)
Srb->
Cdb)->CDB10.LogicalBlockByte1 << 16 |
4793 ((
PCDB)
Srb->
Cdb)->CDB10.LogicalBlockByte0 << 24;
4796 "IdeVerify: Starting sector %x. Number of blocks %x\n",
4805 "IdeVerify: Ending sector %x\n",
4815 "IdeVerify: Truncating request to %x blocks\n",
4816 sectors - startingSector - 1));
4852 (
UCHAR)((startingSector %
4860 (
UCHAR)(startingSector /
4869 (
UCHAR)((startingSector /
4878 (
UCHAR)(((startingSector /
4884 "IdeVerify: Cylinder %x Head %x Sector %x\n",
4965 modeSelect10->
PFBit = 1;
5008 UCHAR statusByte,byteCountLow,byteCountHigh;
5049 "AtapiSendCommand: Command %x to TargetId %d lun %d\n",
5068 }
else if (
Srb->
Lun > 0) {
5090 "AtapiSendCommand: Entered with status %x\n",
5095 "AtapiSendCommand: Device busy (%x)\n",
5105 "AtapiSendCommand: Error on entry: (%x)\n",
5124 DebugPrint((2,
"AtapiSendCommand: DSC not set. %x\n",statusByte));
5133 "AtapiSendCommand: %x mapped as DSC restrictive\n",
5144 "AtapiSendCommand: Entered with status (%x). Attempting to recover.\n",
5152 for (
i = 0;
i < 0x10000;
i++) {
5169 "AtapiSendCommand: DRQ still asserted.Status (%x)\n",
5175 "AtapiSendCommand: Issued soft reset to Atapi device. \n"));
5255 byteCountLow = byteCountHigh = 0xFF;
5276 "AtapiSendCommand: Wait for int. to send packet. Status (%x)\n",
5302 "AtapiSendCommand: DRQ never asserted (%x)\n",
5364 UCHAR statusByte,errorByte;
5370 "IdeSendCommand: Command %x to device %d\n",
5425 for (
i = 0;
i < 8;
i += 2) {
5432 for (
i = 0;
i < 12;
i += 2) {
5443 for (
i = 0;
i < 4;
i++) {
5452 for (
i = 0;
i < 4;
i += 2) {