Annotation of ntddk/src/scsi/qic117/drv1nt.c, revision 1.1.1.1

1.1       root        1: /*++
                      2: 
                      3: Copyright (c) 1993 - Colorado Memory Systems, Inc.
                      4: All Rights Reserved
                      5: 
                      6: Module Name:
                      7: 
                      8:     drv1nt.c
                      9: 
                     10: Abstract:
                     11: 
                     12:     Error translation,  and NT interface routines for needed driver functions.
                     13: 
                     14: Revision History:
                     15: 
                     16: 
                     17: 
                     18: 
                     19: --*/
                     20: 
                     21: //
                     22: // include files
                     23: //
                     24: 
                     25: #include <ntddk.h>                        // various NT definitions
                     26: #include <ntdddisk.h>                    // disk device driver I/O control codes
                     27: #include <ntiologc.h>
                     28: #include "common.h"
                     29: #include "drvtask.h"                     // this driver's data declarations
                     30: #include "mt1defs.h"                     // this driver's data declarations
                     31: #include "mt1strc.h"                     // this driver's data declarations
                     32: #include "q117data.h"                    // this driver's data declarations
                     33: #include "q117log.h"
                     34: 
                     35: 
                     36: NTSTATUS
                     37: Q117iTranslateError(
                     38:    IN PDEVICE_OBJECT DeviceObject,
                     39:    IN STATUS ReturnValue
                     40:    )
                     41: /*++
                     42: 
                     43: 
                     44: Routine Description:
                     45: 
                     46: 
                     47: 
                     48: Arguments:
                     49: 
                     50:    ReturnValue -
                     51: 
                     52: Return Value:
                     53: 
                     54: 
                     55: 
                     56: --*/
                     57: 
                     58: {
                     59:     NTSTATUS ntStatus;
                     60:     PTAPE_EXTENSION tapeExtension;
                     61: 
                     62:     tapeExtension = DeviceObject->DeviceExtension;
                     63: 
                     64:     if (tapeExtension->PersistentNewCart &&
                     65:         (ReturnValue == NoErr)) {
                     66: 
                     67:         ReturnValue = NewCart;
                     68: 
                     69:     }
                     70: 
                     71:     if (ReturnValue) {
                     72: 
                     73:         ntStatus = (NTSTATUS)(STATUS_SEVERITY_WARNING << 30);
                     74:         ntStatus |= (FILE_DEVICE_TAPE << 16) & 0x3fff0000;
                     75:         ntStatus |= ReturnValue & 0x0000ffff;
                     76: 
                     77:         if (!tapeExtension->Found) {
                     78:             NTSTATUS logStatus = q117MapStatus(ReturnValue);
                     79:     
                     80:             if (logStatus != QIC117_NOTAPE) {
                     81:                 q117LogError(
                     82:                     DeviceObject,
                     83:                     tapeExtension->ErrorSequence++,
                     84:                     0,
                     85:                     0,
                     86:                     ReturnValue,
                     87:                     ntStatus,
                     88:                     logStatus
                     89:                     );
                     90:             }
                     91:         }
                     92: 
                     93:     } else {
                     94: 
                     95:         ntStatus = STATUS_SUCCESS;
                     96: 
                     97:     }
                     98: 
                     99:     return(ntStatus);
                    100: }
                    101: 
                    102: 
                    103: STATUS
                    104: Q117iSleep(
                    105:    IN PTAPE_EXTENSION TapeExtension,
                    106:    IN QIC_TIME WaitTime,
                    107:    IN BOOLEAN InterruptSleep
                    108:    )
                    109: 
                    110: /*++
                    111: 
                    112: Routine Description:
                    113: 
                    114: 
                    115: 
                    116: Arguments:
                    117: 
                    118:    TapeExtension -
                    119: 
                    120:    WaitTime -
                    121: 
                    122:    InterruptSleep -
                    123: 
                    124: Return Value:
                    125: 
                    126: 
                    127: 
                    128: --*/
                    129: 
                    130: {
                    131:    NTSTATUS ntStatus;
                    132:    LARGE_INTEGER timeout;
                    133: 
                    134:    timeout = RtlLargeIntegerNegate(
                    135:                 RtlEnlargedIntegerMultiply (
                    136:                     (LONG)(10 * 1000),
                    137:                     (LONG)WaitTime)
                    138:                );
                    139: 
                    140:    if (InterruptSleep) {
                    141: 
                    142:       ntStatus = KeWaitForSingleObject(
                    143:             &TapeExtension->QControllerData->InterruptEvent,
                    144:             Executive,
                    145:             KernelMode,
                    146:             FALSE,
                    147:             &timeout );
                    148: 
                    149:       if (ntStatus == STATUS_TIMEOUT) {
                    150: 
                    151:             return TimeOut;
                    152: 
                    153:       } else {
                    154: 
                    155:             return NoErr;
                    156: 
                    157:       }
                    158: 
                    159:    } else {
                    160: 
                    161:       (VOID) KeDelayExecutionThread(
                    162:             KernelMode,
                    163:             FALSE,
                    164:             &timeout );
                    165: 
                    166:       return TimeOut;
                    167: 
                    168:    }
                    169: 
                    170:    return NoErr;
                    171: }
                    172: 
                    173: 
                    174: VOID
                    175: Q117iShortTimer(
                    176:    IN QIC_TIME StallTime
                    177:    )
                    178: 
                    179: /*++
                    180: 
                    181: Routine Description:
                    182: 
                    183: 
                    184: 
                    185: Arguments:
                    186: 
                    187:    StallTime -
                    188: 
                    189: Return Value:
                    190: 
                    191:    None
                    192: 
                    193: --*/
                    194: 
                    195: {
                    196:    KeStallExecutionProcessor( StallTime );
                    197: 
                    198:    return;
                    199: }
                    200: 
                    201: 
                    202: VOID
                    203: Q117iResetInterruptEvent(
                    204:    IN PTAPE_EXTENSION TapeExtension
                    205:    )
                    206: 
                    207: /*++
                    208: 
                    209: Routine Description:
                    210: 
                    211: 
                    212: 
                    213: Arguments:
                    214: 
                    215:    TapeExtension -
                    216: 
                    217: Return Value:
                    218: 
                    219:    None
                    220: 
                    221: --*/
                    222: 
                    223: {
                    224:    TapeExtension->QControllerData->CurrentDeviceObject =
                    225:       TapeExtension->QDeviceObject;
                    226:    (VOID) KeResetEvent( &TapeExtension->QControllerData->InterruptEvent );
                    227: 
                    228: return;
                    229: }
                    230: 
                    231: 
                    232: VOID
                    233: Q117iDLockUnlockDMA(
                    234:    IN PTAPE_EXTENSION TapeExtension,
                    235:    IN BOOLEAN Lock
                    236:    )
                    237: 
                    238: /*++
                    239: 
                    240: Routine Description:
                    241: 
                    242: 
                    243: 
                    244: Arguments:
                    245: 
                    246:    TapeExtension -
                    247: 
                    248:    AdapterInfo -
                    249: 
                    250:    Lock -
                    251: 
                    252: Return Value:
                    253: 
                    254:    None
                    255: 
                    256: --*/
                    257: 
                    258: {
                    259:    KIRQL oldIrql;
                    260: 
                    261:    if (TapeExtension->QControllerData->AdapterObject) {
                    262: 
                    263:       if (Lock) {
                    264: 
                    265:             if (!TapeExtension->QControllerData->AdapterLocked) {
                    266: 
                    267:                //
                    268:                // Allocate an adapter channel for the I/O.
                    269:                //
                    270: 
                    271:                (VOID) KeResetEvent(
                    272:                   &TapeExtension->QControllerData->AllocateAdapterChannelEvent );
                    273: 
                    274:                KeRaiseIrql( DISPATCH_LEVEL, &oldIrql );
                    275: 
                    276: 
                    277:                IoAllocateAdapterChannel(
                    278:                   TapeExtension->QControllerData->AdapterObject,
                    279:                   TapeExtension->QDeviceObject,
                    280:                   TapeExtension->QControllerData->NumberOfMapRegisters,
                    281:                   Q117iTapeAllocateAdapterChannel,
                    282:                   TapeExtension->QControllerData );
                    283: 
                    284:                KeLowerIrql( oldIrql );
                    285: 
                    286:                //
                    287:                // Wait for the adapter to be allocated.  No
                    288:                // timeout; we trust the system to do it
                    289:                // properly - so KeWaitForSingleObject can't
                    290:                // return an error.
                    291:                //
                    292: 
                    293:                (VOID) KeWaitForSingleObject(
                    294:                   &TapeExtension->QControllerData->AllocateAdapterChannelEvent,
                    295:                   Executive,
                    296:                   KernelMode,
                    297:                   FALSE,
                    298:                   (PLARGE_INTEGER) NULL );
                    299: 
                    300:                TapeExtension->QControllerData->AdapterLocked = TRUE;
                    301:             }
                    302: 
                    303:       } else {
                    304: 
                    305:             if (TapeExtension->QControllerData->AdapterLocked) {
                    306: 
                    307:                //
                    308:                // Free the adapter channel that we just used.
                    309:                //
                    310: 
                    311:                KeRaiseIrql( DISPATCH_LEVEL, &oldIrql );
                    312: 
                    313:                IoFreeAdapterChannel( TapeExtension->QControllerData->AdapterObject );
                    314: 
                    315:                KeLowerIrql( oldIrql );
                    316: 
                    317:                TapeExtension->QControllerData->AdapterLocked = FALSE;
                    318: #if DBG
                    319:                if (QIC117DebugLevel & QIC117SHOWQD) {
                    320:                   while (TapeExtension->DbgHead != TapeExtension->DbgTail) {
                    321: 
                    322:                      switch(TapeExtension->DbgCommand[TapeExtension->DbgHead]) {
                    323:                            case 0x12345678:
                    324:                               DbgPrint("\nPgmFdc: ");
                    325:                               break;
                    326:                            case 0x12345679:
                    327:                               DbgPrint("\nReadFdc: ");
                    328:                               break;
                    329:                            case 0x1234567a:
                    330:                               DbgPrint("\nPgmDMA: ");
                    331:                               break;
                    332:                            case 0x1234567b:
                    333:                               DbgPrint("\nSendByte: ");
                    334:                               break;
                    335:                            case 0x1234567c:
                    336:                               DbgPrint("   ReceiveByte: ");
                    337:                               break;
                    338:                            case 0x1234567d:
                    339:                               DbgPrint("\nI/O Status: ");
                    340:                               break;
                    341:                            default:
                    342:                               // Dump command history
                    343:                               DbgPrint("%02x ", TapeExtension->DbgCommand[TapeExtension->DbgHead]);
                    344: 
                    345:                      }
                    346: 
                    347:                      TapeExtension->DbgHead++;
                    348:                      if (TapeExtension->DbgHead >= DBG_SIZE) {
                    349:                            TapeExtension->DbgHead = 0;
                    350:                      }
                    351: 
                    352: 
                    353:                   }
                    354:                   DbgPrint("\n");
                    355:                }
                    356: 
                    357: #endif
                    358: 
                    359: 
                    360:             }
                    361:       }
                    362:    }
                    363: 
                    364: 
                    365:    return;
                    366: }
                    367: 
                    368: 
                    369: VOID
                    370: hio_ProgramDMA(
                    371:    IN PTAPE_EXTENSION TapeExtension,
                    372:    IN PIRP Irp,
                    373:    IN BOOLEAN WriteOperation
                    374:    )
                    375: 
                    376: /*++
                    377: 
                    378: Routine Description:
                    379: 
                    380: 
                    381: Arguments:
                    382: 
                    383:    TapeExtension -
                    384: 
                    385:    Irp -
                    386: 
                    387:    WriteOperation -
                    388: 
                    389: Return Value:
                    390: 
                    391:    None
                    392: 
                    393: --*/
                    394: 
                    395: {
                    396: 
                    397:    PHYSICAL_ADDRESS val;
                    398: 
                    399:    Q117iDLockUnlockDMA(TapeExtension, TRUE);
                    400: 
                    401:    //
                    402:    // Map the transfer through the DMA hardware.
                    403:    //
                    404: 
                    405:    KeFlushIoBuffers( Irp->MdlAddress, !WriteOperation, TRUE );
                    406: 
                    407:    DbgAddEntry(0x1234567a);
                    408:    DbgAddEntry((ULONG)TapeExtension->QControllerData->AdapterObject);
                    409:    DbgAddEntry((ULONG)Irp->MdlAddress);
                    410:    DbgAddEntry((ULONG)TapeExtension->QControllerData->MapRegisterBase);
                    411:    DbgAddEntry((ULONG) MmGetMdlVirtualAddress(Irp->MdlAddress)
                    412:             + TapeExtension->RdWrOp.BytesTransferredSoFar );
                    413:    DbgAddEntry(TapeExtension->RdWrOp.TotalBytesOfTransfer);
                    414:    DbgAddEntry(WriteOperation);
                    415: 
                    416:    val = IoMapTransfer(
                    417:       TapeExtension->QControllerData->AdapterObject,
                    418:       Irp->MdlAddress,
                    419:       TapeExtension->QControllerData->MapRegisterBase,
                    420:       (PVOID)( (ULONG) MmGetMdlVirtualAddress(Irp->MdlAddress)
                    421:             + TapeExtension->RdWrOp.BytesTransferredSoFar ),
                    422:       &TapeExtension->RdWrOp.TotalBytesOfTransfer,
                    423:       WriteOperation );
                    424: 
                    425:    DbgAddEntry(val.HighPart);
                    426:    DbgAddEntry(val.LowPart);
                    427:    DbgAddEntry(TapeExtension->RdWrOp.TotalBytesOfTransfer);
                    428: }
                    429: 
                    430: 
                    431: VOID
                    432: hio_FlushDMA(
                    433:    IN PTAPE_EXTENSION TapeExtension,
                    434:    IN PIRP Irp,
                    435:    IN BOOLEAN WriteOperation
                    436:    )
                    437: 
                    438: /*++
                    439: 
                    440: Routine Description:
                    441: 
                    442: 
                    443: 
                    444: Arguments:
                    445: 
                    446:    TapeExtension -
                    447: 
                    448:    Irp -
                    449: 
                    450:    WriteOperation -
                    451: 
                    452: Return Value:
                    453: 
                    454:    None
                    455: 
                    456: --*/
                    457: 
                    458: {
                    459:    IoFlushAdapterBuffers(
                    460:       TapeExtension->QControllerData->AdapterObject,
                    461:       Irp->MdlAddress,
                    462:       TapeExtension->QControllerData->MapRegisterBase,
                    463:       (PVOID)( (ULONG) MmGetMdlVirtualAddress( Irp->MdlAddress )
                    464:             + TapeExtension->RdWrOp.BytesTransferredSoFar ),
                    465:       TapeExtension->RdWrOp.TotalBytesOfTransfer,
                    466:       WriteOperation );
                    467: }
                    468: 
                    469: 
                    470: STATUS
                    471: Q117iDDeselect(
                    472:    IN PTAPE_EXTENSION TapeExtension
                    473:    )
                    474: 
                    475: /*++
                    476: 
                    477: Routine Description:
                    478: 
                    479: 
                    480: 
                    481: Arguments:
                    482: 
                    483:    TapeExtension -
                    484: 
                    485: Return Value:
                    486: 
                    487: 
                    488: 
                    489: --*/
                    490: 
                    491: {
                    492:     STATUS retval = NoErr;                 // return value
                    493: 
                    494:     if (TapeExtension->QControllerData->AdapterLocked) {
                    495: 
                    496:         Q117iDLockUnlockDMA(TapeExtension, FALSE);
                    497: 
                    498:     }
                    499: 
                    500:     (VOID) Q117iResetFDC(TapeExtension);
                    501:     (VOID) Q117iSelectDrive(TapeExtension);
                    502:     (VOID) Q117iStopTape(TapeExtension);
                    503:     (VOID) Q117iDeselectDrive(TapeExtension);
                    504: 
                    505:     TapeExtension->NoPause = TRUE;
                    506:     TapeExtension->NewCart = FALSE;
                    507:     TapeExtension->QControllerData->CurrentInterrupt = FALSE;
                    508: 
                    509:     CheckedDump(QIC117INFO,( "Q117iDDeselect: Setting Controller Event\n"));
                    510: 
                    511:     (VOID) KeSetEvent(
                    512:        TapeExtension->QControllerData->ControllerEvent,
                    513:        (KPRIORITY) 0,
                    514:        FALSE );
                    515: 
                    516:     return retval;
                    517: }
                    518: 
                    519: 
                    520: NTSTATUS
                    521: Q117iClearIO(
                    522:    IN OUT PIRP Irp
                    523:    )
                    524: 
                    525: /*++
                    526: 
                    527: Routine Description:
                    528: 
                    529: 
                    530: 
                    531: Arguments:
                    532: 
                    533:    Irp -
                    534: 
                    535: Return Value:
                    536: 
                    537: 
                    538: 
                    539: --*/
                    540: 
                    541: {
                    542:    PTAPE_EXTENSION tapeExtension;
                    543:    PIO_STACK_LOCATION  irpStack = IoGetCurrentIrpStackLocation(Irp);
                    544: 
                    545: 
                    546:    tapeExtension = irpStack->DeviceObject->DeviceExtension;
                    547:    tapeExtension->QDeviceObject = irpStack->DeviceObject;
                    548: 
                    549:    tapeExtension->QControllerData->AbortRequested = FALSE;
                    550: 
                    551:    if (Q117iGetDriveError(tapeExtension) == NotRdy) {
                    552: 
                    553:       Q117iPauseTape(tapeExtension);
                    554: 
                    555:    }
                    556: 
                    557:    if (tapeExtension->NewCart) {
                    558: 
                    559:       Q117iNewTape(tapeExtension);
                    560: 
                    561:    }
                    562: 
                    563:    return STATUS_SUCCESS;
                    564: }
                    565: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.