|
|
1.1 root 1: /*++
2:
3: Coyright (c) 1991 Microsoft Corporation
4:
5: Module Name:
6:
7: srb.h
8:
9: Abstract:
10:
11: This file defines the interface between SCSI mini-port drivers and the
12: SCSI port driver. It is also used by SCSI class drivers to talk to the
13: SCSI port driver.
14:
15: Author:
16:
17: Mike Glass
18:
19: Notes:
20:
21: Revision History:
22:
23: --*/
24: #ifndef _NTSRB_
25: #define _NTSRB_
26:
27: #if DBG
28: #define DebugPrint(x) ScsiDebugPrint x
29: #else
30: #define DebugPrint(x)
31: #endif
32:
33: typedef PHYSICAL_ADDRESS SCSI_PHYSICAL_ADDRESS, *PSCSI_PHYSICAL_ADDRESS;
34:
35: typedef struct _ACCESS_RANGE {
36: SCSI_PHYSICAL_ADDRESS RangeStart;
37: ULONG RangeLength;
38: BOOLEAN RangeInMemory;
39: }ACCESS_RANGE, *PACCESS_RANGE;
40:
41: //
42: // Configuration information structure. Contains the information necessary
43: // to initialize the adapter.
44: //
45:
46: typedef struct _PORT_CONFIGURATION_INFORMATION {
47:
48: //
49: // Length of port configuation information strucuture.
50: //
51:
52: ULONG Length;
53:
54: //
55: // IO bus number (0 for machines that have only 1 IO bus
56: //
57:
58: ULONG SystemIoBusNumber;
59:
60: //
61: // EISA, MCA or ISA
62: //
63:
64: INTERFACE_TYPE AdapterInterfaceType;
65:
66: //
67: // Interrupt request level for device
68: //
69:
70: ULONG BusInterruptLevel;
71:
72: //
73: // Bus interrupt vector used with hardware buses which use as vector as
74: // well as level, such as internal buses.
75: //
76:
77: ULONG BusInterruptVector;
78:
79: //
80: // Interrupt mode (level-sensitive or edge-triggered)
81: //
82:
83: KINTERRUPT_MODE InterruptMode;
84:
85: //
86: // Maximum number of bytes that can be transferred in a single SRB
87: //
88:
89: ULONG MaximumTransferLength;
90:
91: //
92: // Number of contiguous blocks of physical memory
93: //
94:
95: ULONG NumberOfPhysicalBreaks;
96:
97: //
98: // DMA channel for devices using system DMA
99: //
100:
101: ULONG DmaChannel;
102: ULONG DmaPort;
103: DMA_WIDTH DmaWidth;
104: DMA_SPEED DmaSpeed;
105:
106: //
107: // Alignment masked required by the adapter for data transfers.
108: //
109:
110: ULONG AlignmentMask;
111:
112: //
113: // Number of access range elements which have been allocated.
114: //
115:
116: ULONG NumberOfAccessRanges;
117:
118: //
119: // Pointer to array of access range elements.
120: //
121:
122: ACCESS_RANGE (*AccessRanges)[];
123:
124: //
125: // Reserved field.
126: //
127:
128: PVOID Reserved;
129:
130: //
131: // Number of SCSI buses attached to the adapter.
132: //
133:
134: UCHAR NumberOfBuses;
135:
136: //
137: // SCSI bus ID for adapter
138: //
139:
140: CCHAR InitiatorBusId[8];
141:
142: //
143: // Indicates that the adapter does scatter/gather
144: //
145:
146: BOOLEAN ScatterGather;
147:
148: //
149: // Indicates that the adapter is a bus master
150: //
151:
152: BOOLEAN Master;
153:
154: //
155: // Host caches data or state.
156: //
157:
158: BOOLEAN CachesData;
159:
160: //
161: // Host adapter scans down for bios devices.
162: //
163:
164: BOOLEAN AdapterScansDown;
165:
166: //
167: // Primary at disk address (0x1F0) claimed.
168: //
169:
170: BOOLEAN AtdiskPrimaryClaimed;
171:
172: //
173: // Secondary at disk address (0x170) claimed.
174: //
175:
176: BOOLEAN AtdiskSecondaryClaimed;
177:
178: //
179: // The master uses 32-bit DMA addresses.
180: //
181:
182: BOOLEAN Dma32BitAddresses;
183:
184: //
185: // Use Demand Mode DMA rather than Single Request.
186: //
187:
188: BOOLEAN DemandMode;
189:
190: //
191: // Data buffers must be mapped into virtual address space.
192: //
193:
194: BOOLEAN MapBuffers;
195:
196: //
197: // The driver will need to tranlate virtual to physical addresses.
198: //
199:
200: BOOLEAN NeedPhysicalAddresses;
201:
202: //
203: // Supports tagged queuing
204: //
205:
206: BOOLEAN TaggedQueuing;
207:
208: //
209: // Supports auto request sense.
210: //
211:
212: BOOLEAN AutoRequestSense;
213:
214: //
215: // Supports multiple requests per logical unit.
216: //
217:
218: BOOLEAN MultipleRequestPerLu;
219:
220: //
221: // Support receive event function.
222: //
223:
224: BOOLEAN ReceiveEvent;
225:
226: //
227: // Indicates the real-mode driver has initialized the card.
228: //
229:
230: BOOLEAN RealModeInitialized;
231:
232: } PORT_CONFIGURATION_INFORMATION, *PPORT_CONFIGURATION_INFORMATION;
233:
234: //
235: // Uninitialized flag value.
236: //
237:
238: #define SP_UNINITIALIZED_VALUE ((ULONG) ~0)
239: #define SP_UNTAGGED ((UCHAR) ~0)
240:
241: //
242: // Set asynchronous events.
243: //
244:
245: #define SRBEV_BUS_RESET 0x0001
246: #define SRBEV_SCSI_ASYNC_NOTIFICATION 0x0002
247:
248: //
249: // SCSI I/O Request Block
250: //
251:
252: typedef struct _SCSI_REQUEST_BLOCK {
253: USHORT Length; // offset 0
254: UCHAR Function; // offset 2
255: UCHAR SrbStatus; // offset 3
256: UCHAR ScsiStatus; // offset 4
257: UCHAR PathId; // offset 5
258: UCHAR TargetId; // offset 6
259: UCHAR Lun; // offset 7
260: UCHAR QueueTag; // offset 8
261: UCHAR QueueAction; // offset 9
262: UCHAR CdbLength; // offset 10
263: UCHAR SenseInfoBufferLength; // offset 11
264: ULONG SrbFlags; // offset 12
265: ULONG DataTransferLength; // offset 16
266: ULONG TimeOutValue; // offset 20
267: PVOID DataBuffer; // offset 24
268: PVOID SenseInfoBuffer; // offset 28
269: struct _SCSI_REQUEST_BLOCK *NextSrb; // offset 32
270: PVOID OriginalRequest; // offset 36
271: PVOID SrbExtension; // offset 40
272: ULONG QueueSortKey; // offset 44
273: UCHAR Cdb[16]; // offset 48
274: } SCSI_REQUEST_BLOCK, *PSCSI_REQUEST_BLOCK;
275:
276: #define SCSI_REQUEST_BLOCK_SIZE sizeof(SCSI_REQUEST_BLOCK)
277:
278: //
279: // SRB Functions
280: //
281:
282: #define SRB_FUNCTION_EXECUTE_SCSI 0x00
283: #define SRB_FUNCTION_CLAIM_DEVICE 0x01
284: #define SRB_FUNCTION_IO_CONTROL 0x02
285: #define SRB_FUNCTION_RECEIVE_EVENT 0x03
286: #define SRB_FUNCTION_RELEASE_QUEUE 0x04
287: #define SRB_FUNCTION_ATTACH_DEVICE 0x05
288: #define SRB_FUNCTION_RELEASE_DEVICE 0x06
289: #define SRB_FUNCTION_SHUTDOWN 0x07
290: #define SRB_FUNCTION_FLUSH 0x08
291: #define SRB_FUNCTION_ABORT_COMMAND 0x10
292: #define SRB_FUNCTION_RELEASE_RECOVERY 0x11
293: #define SRB_FUNCTION_RESET_BUS 0x12
294: #define SRB_FUNCTION_RESET_DEVICE 0x13
295: #define SRB_FUNCTION_TERMINATE_IO 0x14
296: #define SRB_FUNCTION_FLUSH_QUEUE 0x15
297:
298: //
299: // SRB Status
300: //
301:
302: #define SRB_STATUS_PENDING 0x00
303: #define SRB_STATUS_SUCCESS 0x01
304: #define SRB_STATUS_ABORTED 0x02
305: #define SRB_STATUS_ABORT_FAILED 0x03
306: #define SRB_STATUS_ERROR 0x04
307: #define SRB_STATUS_BUSY 0x05
308: #define SRB_STATUS_INVALID_REQUEST 0x06
309: #define SRB_STATUS_INVALID_PATH_ID 0x07
310: #define SRB_STATUS_NO_DEVICE 0x08
311: #define SRB_STATUS_TIMEOUT 0x09
312: #define SRB_STATUS_SELECTION_TIMEOUT 0x0A
313: #define SRB_STATUS_COMMAND_TIMEOUT 0x0B
314: #define SRB_STATUS_MESSAGE_REJECTED 0x0D
315: #define SRB_STATUS_BUS_RESET 0x0E
316: #define SRB_STATUS_PARITY_ERROR 0x0F
317: #define SRB_STATUS_REQUEST_SENSE_FAILED 0x10
318: #define SRB_STATUS_NO_HBA 0x11
319: #define SRB_STATUS_DATA_OVERRUN 0x12
320: #define SRB_STATUS_UNEXPECTED_BUS_FREE 0x13
321: #define SRB_STATUS_PHASE_SEQUENCE_FAILURE 0x14
322: #define SRB_STATUS_BAD_SRB_BLOCK_LENGTH 0x15
323: #define SRB_STATUS_REQUEST_FLUSHED 0x16
324: #define SRB_STATUS_INVALID_LUN 0x20
325: #define SRB_STATUS_INVALID_TARGET_ID 0x21
326: #define SRB_STATUS_BAD_FUNCTION 0x22
327: #define SRB_STATUS_ERROR_RECOVERY 0x23
328:
329: //
330: // SRB Status Masks
331: //
332:
333: #define SRB_STATUS_QUEUE_FROZEN 0x40
334: #define SRB_STATUS_AUTOSENSE_VALID 0x80
335:
336: #define SRB_STATUS(Status) (Status & ~(SRB_STATUS_AUTOSENSE_VALID | SRB_STATUS_QUEUE_FROZEN))
337:
338: //
339: // SRB Flag Bits
340: //
341:
342: #define SRB_FLAGS_QUEUE_ACTION_ENABLE 0x00000002
343: #define SRB_FLAGS_DISABLE_DISCONNECT 0x00000004
344: #define SRB_FLAGS_DISABLE_SYNCH_TRANSFER 0x00000008
345: #define SRB_FLAGS_BYPASS_FROZEN_QUEUE 0x00000010
346: #define SRB_FLAGS_DISABLE_AUTOSENSE 0x00000020
347: #define SRB_FLAGS_DATA_IN 0x00000040
348: #define SRB_FLAGS_DATA_OUT 0x00000080
349: #define SRB_FLAGS_NO_DATA_TRANSFER 0x00000000
350: #define SRB_FLAGS_UNSPECIFIED_DIRECTION (SRB_FLAGS_DATA_IN | SRB_FLAGS_DATA_OUT)
351: #define SRB_FLAGS_NO_QUEUE_FREEZE 0x00000100
352: #define SRB_FLAGS_ADAPTER_CACHE_ENABLE 0x00000200
353: #define SRB_FLAGS_IS_ACTIVE 0x00010000
354: #define SRB_FLAGS_ALLOCATED_FROM_ZONE 0x00020000
355:
356: //
357: // Queue Action
358: //
359:
360: #define SRB_SIMPLE_TAG_REQUEST 0x20
361: #define SRB_HEAD_OF_QUEUE_TAG_REQUEST 0x21
362: #define SRB_ORDERED_QUEUE_TAG_REQUEST 0x22
363:
364: //
365: // SCSI Adapter Dependent Routines
366: //
367:
368: typedef
369: BOOLEAN
370: (*PHW_INITIALIZE) (
371: IN PVOID DeviceExtension
372: );
373:
374: typedef
375: BOOLEAN
376: (*PHW_STARTIO) (
377: IN PVOID DeviceExtension,
378: IN PSCSI_REQUEST_BLOCK Srb
379: );
380:
381: typedef
382: BOOLEAN
383: (*PHW_INTERRUPT) (
384: IN PVOID DeviceExtension
385: );
386:
387: typedef
388: VOID
389: (*PHW_TIMER) (
390: IN PVOID DeviceExtension
391: );
392:
393: typedef
394: VOID
395: (*PHW_DMA_STARTED) (
396: IN PVOID DeviceExtension
397: );
398:
399: typedef
400: ULONG
401: (*PHW_FIND_ADAPTER) (
402: IN PVOID DeviceExtension,
403: IN PVOID HwContext,
404: IN PVOID BusInformation,
405: IN PCHAR ArgumentString,
406: IN OUT PPORT_CONFIGURATION_INFORMATION ConfigInfo,
407: OUT PBOOLEAN Again
408: );
409:
410: typedef
411: BOOLEAN
412: (*PHW_RESET_BUS) (
413: IN PVOID DeviceExtension,
414: IN ULONG PathId
415: );
416:
417: typedef
418: BOOLEAN
419: (*PHW_ADAPTER_STATE) (
420: IN PVOID DeviceExtension,
421: IN PVOID Context,
422: IN BOOLEAN SaveState
423: );
424:
425: //
426: // Port driver error codes
427: //
428:
429: #define SP_BUS_PARITY_ERROR 0x0001
430: #define SP_UNEXPECTED_DISCONNECT 0x0002
431: #define SP_INVALID_RESELECTION 0x0003
432: #define SP_BUS_TIME_OUT 0x0004
433: #define SP_PROTOCOL_ERROR 0x0005
434: #define SP_INTERNAL_ADAPTER_ERROR 0x0006
435: #define SP_REQUEST_TIMEOUT 0x0007
436: #define SP_IRQ_NOT_RESPONDING 0x0008
437: #define SP_BAD_FW_WARNING 0x0009
438: #define SP_BAD_FW_ERROR 0x000a
439:
440: //
441: // Return values for SCSI_HW_FIND_ADAPTER.
442: //
443:
444: #define SP_RETURN_NOT_FOUND 0
445: #define SP_RETURN_FOUND 1
446: #define SP_RETURN_ERROR 2
447: #define SP_RETURN_BAD_CONFIG 3
448:
449: //
450: // Notification Event Types
451: //
452:
453: typedef enum _SCSI_NOTIFICATION_TYPE {
454: RequestComplete,
455: NextRequest,
456: NextLuRequest,
457: ResetDetected,
458: CallDisableInterrupts,
459: CallEnableInterrupts,
460: RequestTimerCall
461: } SCSI_NOTIFICATION_TYPE, *PSCSI_NOTIFICATION_TYPE;
462:
463: //
464: // Structure passed between miniport initialization
465: // and SCSI port initialization
466: //
467:
468: typedef struct _HW_INITIALIZATION_DATA {
469:
470: ULONG HwInitializationDataSize;
471:
472: INTERFACE_TYPE AdapterInterfaceType;
473:
474: PHW_INITIALIZE HwInitialize;
475:
476: PHW_STARTIO HwStartIo;
477:
478: PHW_INTERRUPT HwInterrupt;
479:
480: PHW_FIND_ADAPTER HwFindAdapter;
481:
482: PHW_RESET_BUS HwResetBus;
483:
484: PHW_DMA_STARTED HwDmaStarted;
485:
486: PHW_ADAPTER_STATE HwAdapterState;
487:
488: ULONG DeviceExtensionSize;
489:
490: ULONG SpecificLuExtensionSize;
491:
492: ULONG SrbExtensionSize;
493:
494: ULONG NumberOfAccessRanges;
495:
496: PVOID Reserved;
497:
498: //
499: // Data buffers must be mapped into virtual address space.
500: //
501:
502: BOOLEAN MapBuffers;
503:
504: //
505: // The driver will need to tranlate virtual to physical addresses.
506: //
507:
508: BOOLEAN NeedPhysicalAddresses;
509:
510: //
511: // Supports tagged queuing
512: //
513:
514: BOOLEAN TaggedQueuing;
515:
516: //
517: // Supports auto request sense.
518: //
519:
520: BOOLEAN AutoRequestSense;
521:
522: //
523: // Supports multiple requests per logical unit.
524: //
525:
526: BOOLEAN MultipleRequestPerLu;
527:
528: //
529: // Support receive event function.
530: //
531:
532: BOOLEAN ReceiveEvent;
533:
534: } HW_INITIALIZATION_DATA, *PHW_INITIALIZATION_DATA;
535:
536: //
537: // Port driver routines called by miniport driver
538: //
539:
540: ULONG
541: ScsiPortInitialize(
542: IN PVOID Argument1,
543: IN PVOID Argument2,
544: IN struct _HW_INITIALIZATION_DATA *HwInitializationData,
545: IN PVOID HwContext
546: );
547:
548: VOID
549: ScsiPortFreeDeviceBase(
550: IN PVOID HwDeviceExtension,
551: IN PVOID MappedAddress
552: );
553:
554: ULONG
555: ScsiPortGetBusData(
556: IN PVOID DeviceExtension,
557: IN ULONG BusDataType,
558: IN ULONG SystemIoBusNumber,
559: IN ULONG SlotNumber,
560: IN PVOID Buffer,
561: IN ULONG Length
562: );
563:
564: PVOID
565: ScsiPortGetDeviceBase(
566: IN PVOID HwDeviceExtension,
567: IN INTERFACE_TYPE BusType,
568: IN ULONG SystemIoBusNumber,
569: IN SCSI_PHYSICAL_ADDRESS IoAddress,
570: IN ULONG NumberOfBytes,
571: IN BOOLEAN InIoSpace
572: );
573:
574: PVOID
575: ScsiPortGetLogicalUnit(
576: IN PVOID HwDeviceExtension,
577: IN UCHAR PathId,
578: IN UCHAR TargetId,
579: IN UCHAR Lun
580: );
581:
582: PSCSI_REQUEST_BLOCK
583: ScsiPortGetSrb(
584: IN PVOID DeviceExtension,
585: IN UCHAR PathId,
586: IN UCHAR TargetId,
587: IN UCHAR Lun,
588: IN LONG QueueTag
589: );
590:
591: SCSI_PHYSICAL_ADDRESS
592: ScsiPortGetPhysicalAddress(
593: IN PVOID HwDeviceExtension,
594: IN PSCSI_REQUEST_BLOCK Srb,
595: IN PVOID VirtualAddress,
596: OUT ULONG *Length
597: );
598:
599: PVOID
600: ScsiPortGetVirtualAddress(
601: IN PVOID HwDeviceExtension,
602: IN SCSI_PHYSICAL_ADDRESS PhysicalAddress
603: );
604:
605: PVOID
606: ScsiPortGetUncachedExtension(
607: IN PVOID HwDeviceExtension,
608: IN PPORT_CONFIGURATION_INFORMATION ConfigInfo,
609: IN ULONG NumberOfBytes
610: );
611:
612: VOID
613: ScsiPortFlushDma(
614: IN PVOID DeviceExtension
615: );
616:
617: VOID
618: ScsiPortIoMapTransfer(
619: IN PVOID HwDeviceExtension,
620: IN PSCSI_REQUEST_BLOCK Srb,
621: IN PVOID LogicalAddress,
622: IN ULONG Length
623: );
624:
625: VOID
626: ScsiPortNotification(
627: IN SCSI_NOTIFICATION_TYPE NotificationType,
628: IN PVOID HwDeviceExtension,
629: ...
630: );
631:
632: VOID
633: ScsiPortLogError(
634: IN PVOID HwDeviceExtension,
635: IN PSCSI_REQUEST_BLOCK Srb OPTIONAL,
636: IN UCHAR PathId,
637: IN UCHAR TargetId,
638: IN UCHAR Lun,
639: IN ULONG ErrorCode,
640: IN ULONG UniqueId
641: );
642:
643: VOID
644: ScsiPortCompleteRequest(
645: IN PVOID HwDeviceExtension,
646: IN UCHAR PathId,
647: IN UCHAR TargetId,
648: IN UCHAR Lun,
649: IN UCHAR SrbStatus
650: );
651:
652: VOID
653: ScsiPortMoveMemory(
654: IN PVOID WriteBuffer,
655: IN PVOID ReadBuffer,
656: IN ULONG Length
657: );
658:
659: UCHAR
660: ScsiPortReadPortUchar(
661: IN PUCHAR Port
662: );
663:
664: USHORT
665: ScsiPortReadPortUshort(
666: IN PUSHORT Port
667: );
668:
669: ULONG
670: ScsiPortReadPortUlong(
671: IN PULONG Port
672: );
673:
674: VOID
675: ScsiPortReadPortBufferUchar(
676: IN PUCHAR Port,
677: IN PUCHAR Buffer,
678: IN ULONG Count
679: );
680:
681: VOID
682: ScsiPortReadPortBufferUshort(
683: IN PUSHORT Port,
684: IN PUSHORT Buffer,
685: IN ULONG Count
686: );
687:
688: VOID
689: ScsiPortReadPortBufferUlong(
690: IN PULONG Port,
691: IN PULONG Buffer,
692: IN ULONG Count
693: );
694:
695: UCHAR
696: ScsiPortReadRegisterUchar(
697: IN PUCHAR Register
698: );
699:
700: USHORT
701: ScsiPortReadRegisterUshort(
702: IN PUSHORT Register
703: );
704:
705: ULONG
706: ScsiPortReadRegisterUlong(
707: IN PULONG Register
708: );
709:
710: VOID
711: ScsiPortReadRegisterBufferUchar(
712: IN PUCHAR Register,
713: IN PUCHAR Buffer,
714: IN ULONG Count
715: );
716:
717: VOID
718: ScsiPortReadRegisterBufferUshort(
719: IN PUSHORT Register,
720: IN PUSHORT Buffer,
721: IN ULONG Count
722: );
723:
724: VOID
725: ScsiPortStallExecution(
726: IN ULONG Delay
727: );
728:
729: VOID
730: ScsiPortWritePortUchar(
731: IN PUCHAR Port,
732: IN UCHAR Value
733: );
734:
735: VOID
736: ScsiPortWritePortUshort(
737: IN PUSHORT Port,
738: IN USHORT Value
739: );
740:
741: VOID
742: ScsiPortWritePortUlong(
743: IN PULONG Port,
744: IN ULONG Value
745: );
746:
747: VOID
748: ScsiPortWritePortBufferUchar(
749: IN PUCHAR Port,
750: IN PUCHAR Buffer,
751: IN ULONG Count
752: );
753:
754: VOID
755: ScsiPortWritePortBufferUshort(
756: IN PUSHORT Port,
757: IN PUSHORT Buffer,
758: IN ULONG Count
759: );
760:
761: VOID
762: ScsiPortWritePortBufferUlong(
763: IN PULONG Port,
764: IN PULONG Buffer,
765: IN ULONG Count
766: );
767:
768: VOID
769: ScsiPortWriteRegisterUchar(
770: IN PUCHAR Register,
771: IN UCHAR Value
772: );
773:
774: VOID
775: ScsiPortWriteRegisterUshort(
776: IN PUSHORT Register,
777: IN USHORT Value
778: );
779:
780: VOID
781: ScsiPortWriteRegisterUlong(
782: IN PULONG Register,
783: IN ULONG Value
784: );
785:
786: VOID
787: ScsiPortWriteRegisterBufferUchar(
788: IN PUCHAR Register,
789: IN PUCHAR Buffer,
790: IN ULONG Count
791: );
792:
793: VOID
794: ScsiPortWriteRegisterBufferUshort(
795: IN PUSHORT Register,
796: IN PUSHORT Buffer,
797: IN ULONG Count
798: );
799:
800: SCSI_PHYSICAL_ADDRESS
801: ScsiPortConvertUlongToPhysicalAddress(
802: ULONG UlongAddress
803: );
804:
805: ULONG
806: ScsiPortConvertPhysicalAddressToUlong(
807: SCSI_PHYSICAL_ADDRESS Address
808: );
809:
810: #define ScsiPortConvertPhysicalAddressToUlong(Address) ((Address).LowPart)
811:
812: #ifdef DBG
813:
814: VOID
815: ScsiDebugPrint(
816: ULONG DebugPrintLevel,
817: PCCHAR DebugMessage,
818: ...
819: );
820:
821: #else
822:
823: #define ScsiDebugPrint
824:
825: #endif // DBG
826:
827: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.