1 ////////////////////////////////////////////////////////////////////
2 // Copyright (C) Alexander Telyatnikov, Ivan Keliukh, Yegor Anchishkin, SKIF Software, 1999-2013. Kiev, Ukraine
3 // All rights reserved
4 // This file was released under the GPLv2 on June 2015.
5 ////////////////////////////////////////////////////////////////////
6 /*
7 
8 Module Name:
9 
10     scsi_port.h
11 
12 Abstract:
13 
14     This is the include file that defines all constants and types for
15     accessing the SCSI port adapters.
16 
17 Environment:
18 
19     kernel mode only
20  */
21 
22 #ifndef __SCSI_PORT_H__
23 #define __SCSI_PORT_H__
24 
25 #include "srb.h"
26 
27 #ifdef SCSIPORT_API
28 #undef SCSIPORT_API
29 #endif
30 
31 // Device Name - this string is the name of the device.  It is the name
32 // that should be passed to NtOpenFile when accessing the device.
33 //
34 // Note:  For devices that support multiple units, it should be suffixed
35 //        with the Ascii representation of the unit number.
36 
37 #define IOCTL_SCSI_BASE                 FILE_DEVICE_CONTROLLER
38 
39 #define DD_SCSI_DEVICE_NAME "\\Device\\ScsiPort"
40 
41 
42 // NtDeviceIoControlFile IoControlCode values for this device.
43 //
44 // Warning:  Remember that the low two bits of the code specify how the
45 //           buffers are passed to the driver!
46 
47 #define IOCTL_SCSI_PASS_THROUGH         CTL_CODE(IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
48 #define IOCTL_SCSI_MINIPORT             CTL_CODE(IOCTL_SCSI_BASE, 0x0402, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
49 #define IOCTL_SCSI_GET_INQUIRY_DATA     CTL_CODE(IOCTL_SCSI_BASE, 0x0403, METHOD_BUFFERED, FILE_ANY_ACCESS)
50 #define IOCTL_SCSI_GET_CAPABILITIES     CTL_CODE(IOCTL_SCSI_BASE, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS)
51 #define IOCTL_SCSI_PASS_THROUGH_DIRECT  CTL_CODE(IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
52 #define IOCTL_SCSI_GET_ADDRESS          CTL_CODE(IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS)
53 #define IOCTL_SCSI_RESCAN_BUS           CTL_CODE(IOCTL_SCSI_BASE, 0x0407, METHOD_BUFFERED, FILE_ANY_ACCESS)
54 #define IOCTL_SCSI_GET_DUMP_POINTERS    CTL_CODE(IOCTL_SCSI_BASE, 0x0408, METHOD_BUFFERED, FILE_ANY_ACCESS)
55 
56 // Define the SCSI pass through structure.
57 
58 typedef struct _SCSI_PASS_THROUGH {
59     USHORT Length;
60     UCHAR ScsiStatus;
61     UCHAR PathId;
62     UCHAR TargetId;
63     UCHAR Lun;
64     UCHAR CdbLength;
65     UCHAR SenseInfoLength;
66     UCHAR DataIn;
67     ULONG DataTransferLength;
68     ULONG TimeOutValue;
69     ULONG DataBufferOffset;
70     ULONG SenseInfoOffset;
71     UCHAR Cdb[16];
72 }SCSI_PASS_THROUGH, *PSCSI_PASS_THROUGH;
73 
74 // Define the SCSI pass through direct structure.
75 
76 typedef struct _SCSI_PASS_THROUGH_DIRECT {
77     USHORT Length;
78     UCHAR ScsiStatus;
79     UCHAR PathId;
80     UCHAR TargetId;
81     UCHAR Lun;
82     UCHAR CdbLength;
83     UCHAR SenseInfoLength;
84     UCHAR DataIn;
85     ULONG DataTransferLength;
86     ULONG TimeOutValue;
87     PVOID DataBuffer;
88     ULONG SenseInfoOffset;
89     UCHAR Cdb[16];
90 }SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
91 
92 // Define SCSI information.
93 // Used with the IOCTL_SCSI_GET_INQUIRY_DATA IOCTL.
94 
95 typedef struct _SCSI_BUS_DATA {
96     UCHAR NumberOfLogicalUnits;
97     UCHAR InitiatorBusId;
98     ULONG InquiryDataOffset;
99 }SCSI_BUS_DATA, *PSCSI_BUS_DATA;
100 
101 // Define SCSI adapter bus information structure..
102 // Used with the IOCTL_SCSI_GET_INQUIRY_DATA IOCTL.
103 
104 typedef struct _SCSI_ADAPTER_BUS_INFO {
105     UCHAR NumberOfBuses;
106     SCSI_BUS_DATA BusData[1];
107 } SCSI_ADAPTER_BUS_INFO, *PSCSI_ADAPTER_BUS_INFO;
108 
109 // Define SCSI adapter bus information.
110 // Used with the IOCTL_SCSI_GET_INQUIRY_DATA IOCTL.
111 
112 typedef struct _SCSI_INQUIRY_DATA {
113     UCHAR PathId;
114     UCHAR TargetId;
115     UCHAR Lun;
116     BOOLEAN DeviceClaimed;
117     ULONG InquiryDataLength;
118     ULONG NextInquiryDataOffset;
119     UCHAR InquiryData[1];
120 }SCSI_INQUIRY_DATA, *PSCSI_INQUIRY_DATA;
121 
122 // Define header for I/O control SRB.
123 
124 typedef struct _SRB_IO_CONTROL {
125         ULONG HeaderLength;
126         UCHAR Signature[8];
127         ULONG Timeout;
128         ULONG ControlCode;
129         ULONG ReturnCode;
130         ULONG Length;
131 } SRB_IO_CONTROL, *PSRB_IO_CONTROL;
132 
133 // SCSI port driver capabilities structure.
134 
135 typedef struct _IO_SCSI_CAPABILITIES {
136     ULONG Length;    // Length of this structure
137     ULONG MaximumTransferLength;    // Maximum transfer size in single SRB (obsolete)
138     ULONG MaximumPhysicalPages;    // Maximum number of physical pages per data buffer
139     ULONG SupportedAsynchronousEvents;    // Async calls from port to class
140     ULONG AlignmentMask;    // Alignment mask for data transfers.
141     BOOLEAN TaggedQueuing;    // Supports tagged queuing
142     BOOLEAN AdapterScansDown;    // Host adapter scans down for bios devices.
143     BOOLEAN AdapterUsesPio;    // The host adapter uses programmed I/O.
144 } IO_SCSI_CAPABILITIES, *PIO_SCSI_CAPABILITIES;
145 
146 typedef struct _SCSI_ADDRESS {
147     ULONG Length;
148     UCHAR PortNumber;
149     UCHAR PathId;
150     UCHAR TargetId;
151     UCHAR Lun;
152 }SCSI_ADDRESS, *PSCSI_ADDRESS;
153 
154 // Define structure for returning crash dump pointers.
155 
156 struct _ADAPTER_OBJECT;
157 
158 typedef struct _DUMP_POINTERS {
159     struct _ADAPTER_OBJECT *AdapterObject;
160     PVOID MappedRegisterBase;
161     PVOID PortConfiguration;
162     PVOID CommonBufferVa;
163     LARGE_INTEGER CommonBufferPa;
164     ULONG CommonBufferSize;
165 } DUMP_POINTERS, *PDUMP_POINTERS;
166 
167 
168 
169 // Define values for pass-through DataIn field.
170 
171 #define SCSI_IOCTL_DATA_OUT          0
172 #define SCSI_IOCTL_DATA_IN           1
173 #define SCSI_IOCTL_DATA_UNSPECIFIED  2
174 
175 #define CLASS_SPECIAL_CAUSE_NOT_REPORTABLE_HACK     0x00000020
176 
177 #define SCSIPORT_API
178 
179 #ifndef USER_MODE
180 extern NTSTATUS ScsiClassGetInquiryData(IN PDEVICE_OBJECT PortDeviceObject,
181                                         IN PSCSI_ADAPTER_BUS_INFO *ConfigInfo);
182 extern NTSTATUS ScsiClassReadDeviceInquiryData(IN PDEVICE_OBJECT DeviceObject,
183                                                IN BOOLEAN DirectAccess);
184 extern NTSTATUS ScsiClassReadDriveCapacity(IN PDEVICE_OBJECT DeviceObject);
185 
186 #ifndef CDRW_W32
187 
188 // Class dll routines called by class drivers
189 
190 extern NTSTATUS ScsiClassGetCapabilities(IN PDEVICE_OBJECT PortDeviceObject,
191                                          OUT PIO_SCSI_CAPABILITIES *PortCapabilities);
192 extern NTSTATUS ScsiClassGetAddress(IN PDEVICE_OBJECT ClassDeviceObject,
193                                     OUT PSCSI_ADDRESS Address);
194 extern VOID     ScsiClassReleaseQueue(IN PDEVICE_OBJECT DeviceObject);
195 extern NTSTATUS ScsiClassRemoveDevice(IN PDEVICE_OBJECT PortDeviceObject, IN UCHAR PathId,
196                                       IN UCHAR TargetId, IN UCHAR Lun);
197 extern NTSTATUS ScsiClassClaimDevice(IN PDEVICE_OBJECT PortDeviceObject,
198                                      IN PSCSI_INQUIRY_DATA LunInfo, IN BOOLEAN Release,
199                                      OUT PDEVICE_OBJECT *NewPortDeviceObject OPTIONAL);
200 extern NTSTATUS ScsiClassInternalIoControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
201 extern NTSTATUS ScsiClassIoCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp,
202                                       IN PVOID Context);
203 extern NTSTATUS ScsiClassSendSrbSynchronous(IN PDEVICE_OBJECT TargetDeviceObject,
204                                             IN PSCSI_REQUEST_BLOCK _srb,
205                                             IN PKEVENT event);
206 
207 #endif //CDRW_W32
208 
209 extern VOID     ScsiClassInitSrbBusAddr(PSCSI_REQUEST_BLOCK Srb,
210                                         PVOID DeviceExtension);
211 
212 extern NTSTATUS
213 DbgWaitForSingleObject_(
214     IN PVOID Object,
215     IN PLARGE_INTEGER Timeout OPTIONAL
216     );
217 #endif //USER_MODE
218 
219 #endif //__SCSI_PORT_H__
220