047e48d4acf37b4d90796b3ba4263f9f008a9103
[reactos.git] / drivers / storage / class / include / class2.h
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: services/storage/include/class2.h
5 * PURPOSE: SCSI class driver definitions
6 * PROGRAMMER: Eric Kohl
7 */
8
9 #pragma once
10
11 #include <ntddscsi.h>
12 #include <srb.h>
13
14 #define MAXIMUM_RETRIES 15
15 #define RETRY_WAIT 2000000 /* 200 ms in units of 100 ns */
16
17 //
18 // Indicates that the device has write caching enabled.
19 //
20
21 #define DEV_WRITE_CACHE 0x00000001
22
23
24 //
25 // Build SCSI 1 or SCSI 2 CDBs
26 //
27
28 #define DEV_USE_SCSI1 0x00000002
29
30 //
31 // Indicates whether is is safe to send StartUnit commands
32 // to this device. It will only be off for some removeable devices.
33 //
34
35 #define DEV_SAFE_START_UNIT 0x00000004
36
37 //
38 // Indicates whether it is unsafe to send SCSIOP_MECHANISM_STATUS commands to
39 // this device. Some devices don't like these 12 byte commands
40 //
41
42 #define DEV_NO_12BYTE_CDB 0x00000008
43
44
45 struct _CLASS_INIT_DATA;
46
47 typedef VOID
48 (NTAPI *PCLASS_ERROR)(IN PDEVICE_OBJECT DeviceObject,
49 IN PSCSI_REQUEST_BLOCK Srb,
50 IN OUT NTSTATUS *Status,
51 IN OUT BOOLEAN *Retry);
52
53 typedef BOOLEAN
54 (NTAPI *PCLASS_DEVICE_CALLBACK)(IN PINQUIRYDATA);
55
56 typedef NTSTATUS
57 (NTAPI *PCLASS_READ_WRITE)(IN PDEVICE_OBJECT DeviceObject,
58 IN PIRP Irp);
59
60 typedef BOOLEAN
61 (NTAPI *PCLASS_FIND_DEVICES)(IN PDRIVER_OBJECT DriverObject,
62 IN PUNICODE_STRING RegistryPath,
63 IN struct _CLASS_INIT_DATA *InitializationData,
64 IN PDEVICE_OBJECT PortDeviceObject,
65 IN ULONG PortNumber);
66
67 typedef NTSTATUS
68 (NTAPI *PCLASS_DEVICE_CONTROL)(IN PDEVICE_OBJECT DeviceObject,
69 IN PIRP Irp);
70
71 typedef NTSTATUS
72 (NTAPI *PCLASS_SHUTDOWN_FLUSH)(IN PDEVICE_OBJECT DeviceObject,
73 IN PIRP Irp);
74
75 typedef NTSTATUS
76 (NTAPI *PCLASS_CREATE_CLOSE)(IN PDEVICE_OBJECT DeviceObject,
77 IN PIRP Irp);
78
79
80 typedef struct _CLASS_INIT_DATA
81 {
82 ULONG InitializationDataSize;
83 ULONG DeviceExtensionSize;
84 DEVICE_TYPE DeviceType;
85 ULONG DeviceCharacteristics;
86 PCLASS_ERROR ClassError;
87 PCLASS_READ_WRITE ClassReadWriteVerification;
88 PCLASS_DEVICE_CALLBACK ClassFindDeviceCallBack;
89 PCLASS_FIND_DEVICES ClassFindDevices;
90 PCLASS_DEVICE_CONTROL ClassDeviceControl;
91 PCLASS_SHUTDOWN_FLUSH ClassShutdownFlush;
92 PCLASS_CREATE_CLOSE ClassCreateClose;
93 PDRIVER_STARTIO ClassStartIo;
94 } CLASS_INIT_DATA, *PCLASS_INIT_DATA;
95
96
97 typedef struct _DEVICE_EXTENSION
98 {
99 PDEVICE_OBJECT DeviceObject;
100 PDEVICE_OBJECT PortDeviceObject;
101 LARGE_INTEGER PartitionLength;
102 LARGE_INTEGER StartingOffset;
103 ULONG DMByteSkew;
104 ULONG DMSkew;
105 BOOLEAN DMActive;
106 PCLASS_ERROR ClassError;
107 PCLASS_READ_WRITE ClassReadWriteVerification;
108 PCLASS_FIND_DEVICES ClassFindDevices;
109 PCLASS_DEVICE_CONTROL ClassDeviceControl;
110 PCLASS_SHUTDOWN_FLUSH ClassShutdownFlush;
111 PCLASS_CREATE_CLOSE ClassCreateClose;
112 PDRIVER_STARTIO ClassStartIo;
113 PIO_SCSI_CAPABILITIES PortCapabilities;
114 PDISK_GEOMETRY_EX DiskGeometry;
115 PDEVICE_OBJECT PhysicalDevice;
116 PSENSE_DATA SenseData;
117 ULONG TimeOutValue;
118 ULONG DeviceNumber;
119 ULONG SrbFlags;
120 ULONG ErrorCount;
121 KSPIN_LOCK SplitRequestSpinLock;
122 NPAGED_LOOKASIDE_LIST SrbLookasideListHead;
123 LONG LockCount;
124 UCHAR PortNumber;
125 UCHAR PathId;
126 UCHAR TargetId;
127 UCHAR Lun;
128 UCHAR SectorShift;
129 UCHAR ReservedByte;
130 USHORT DeviceFlags;
131 PKEVENT MediaChangeEvent;
132 HANDLE MediaChangeEventHandle;
133 BOOLEAN MediaChangeNoMedia;
134 ULONG MediaChangeCount;
135 } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
136
137
138 typedef struct _COMPLETION_CONTEXT
139 {
140 PDEVICE_OBJECT DeviceObject;
141 SCSI_REQUEST_BLOCK Srb;
142 } COMPLETION_CONTEXT, *PCOMPLETION_CONTEXT;
143
144
145 /* FUNCTIONS ****************************************************************/
146
147 IO_COMPLETION_ROUTINE ScsiClassAsynchronousCompletion;
148 NTSTATUS NTAPI
149 ScsiClassAsynchronousCompletion(IN PDEVICE_OBJECT DeviceObject,
150 IN PIRP Irp,
151 IN PVOID Context);
152
153 VOID NTAPI
154 ScsiClassBuildRequest(IN PDEVICE_OBJECT DeviceObject,
155 IN PIRP Irp);
156
157 NTSTATUS NTAPI
158 ScsiClassClaimDevice(IN PDEVICE_OBJECT PortDeviceObject,
159 IN PSCSI_INQUIRY_DATA LunInfo,
160 IN BOOLEAN Release,
161 OUT PDEVICE_OBJECT *NewPortDeviceObject OPTIONAL);
162
163 NTSTATUS NTAPI
164 ScsiClassCreateDeviceObject(IN PDRIVER_OBJECT DriverObject,
165 IN PCCHAR ObjectNameBuffer,
166 IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL,
167 IN OUT PDEVICE_OBJECT *DeviceObject,
168 IN PCLASS_INIT_DATA InitializationData);
169
170 NTSTATUS NTAPI
171 ScsiClassDeviceControl(IN PDEVICE_OBJECT DeviceObject,
172 IN PIRP Irp);
173
174 PVOID NTAPI
175 ScsiClassFindModePage(IN PCHAR ModeSenseBuffer,
176 IN ULONG Length,
177 IN UCHAR PageMode,
178 IN BOOLEAN Use6Byte);
179
180 ULONG NTAPI
181 ScsiClassFindUnclaimedDevices(IN PCLASS_INIT_DATA InitializationData,
182 OUT PSCSI_ADAPTER_BUS_INFO AdapterInformation);
183
184 NTSTATUS NTAPI
185 ScsiClassGetCapabilities(IN PDEVICE_OBJECT PortDeviceObject,
186 OUT PIO_SCSI_CAPABILITIES *PortCapabilities);
187
188 NTSTATUS NTAPI
189 ScsiClassGetInquiryData(IN PDEVICE_OBJECT PortDeviceObject,
190 OUT PSCSI_ADAPTER_BUS_INFO *ConfigInfo);
191
192 ULONG NTAPI
193 ScsiClassInitialize(IN PVOID Argument1,
194 IN PVOID Argument2,
195 IN PCLASS_INIT_DATA InitializationData);
196
197 VOID NTAPI
198 ScsiClassInitializeSrbLookasideList(IN PDEVICE_EXTENSION DeviceExtension,
199 IN ULONG NumberElements);
200
201 NTSTATUS NTAPI
202 ScsiClassInternalIoControl(IN PDEVICE_OBJECT DeviceObject,
203 IN PIRP Irp);
204
205 BOOLEAN NTAPI
206 ScsiClassInterpretSenseInfo(IN PDEVICE_OBJECT DeviceObject,
207 IN PSCSI_REQUEST_BLOCK Srb,
208 IN UCHAR MajorFunctionCode,
209 IN ULONG IoDeviceCode,
210 IN ULONG RetryCount,
211 OUT NTSTATUS *Status);
212
213 NTSTATUS NTAPI
214 ScsiClassIoComplete(IN PDEVICE_OBJECT DeviceObject,
215 IN PIRP Irp,
216 IN PVOID Context);
217
218 NTSTATUS NTAPI
219 ScsiClassIoCompleteAssociated(IN PDEVICE_OBJECT DeviceObject,
220 IN PIRP Irp,
221 IN PVOID Context);
222
223 ULONG NTAPI
224 ScsiClassModeSense(IN PDEVICE_OBJECT DeviceObject,
225 IN PCHAR ModeSenseBuffer,
226 IN ULONG Length,
227 IN UCHAR PageMode);
228
229 ULONG NTAPI
230 ScsiClassQueryTimeOutRegistryValue(IN PUNICODE_STRING RegistryPath);
231
232 NTSTATUS NTAPI
233 ScsiClassReadDriveCapacity(IN PDEVICE_OBJECT DeviceObject);
234
235 VOID NTAPI
236 ScsiClassReleaseQueue(IN PDEVICE_OBJECT DeviceObject);
237
238 NTSTATUS NTAPI
239 ScsiClassSendSrbAsynchronous(PDEVICE_OBJECT DeviceObject,
240 PSCSI_REQUEST_BLOCK Srb,
241 PIRP Irp,
242 PVOID BufferAddress,
243 ULONG BufferLength,
244 BOOLEAN WriteToDevice);
245
246 NTSTATUS NTAPI
247 ScsiClassSendSrbSynchronous(PDEVICE_OBJECT DeviceObject,
248 PSCSI_REQUEST_BLOCK Srb,
249 PVOID BufferAddress,
250 ULONG BufferLength,
251 BOOLEAN WriteToDevice);
252
253 VOID NTAPI
254 ScsiClassSplitRequest(IN PDEVICE_OBJECT DeviceObject,
255 IN PIRP Irp,
256 IN ULONG MaximumBytes);
257
258 NTSTATUS
259 NTAPI
260 ScsiClassCheckVerifyComplete(
261 IN PDEVICE_OBJECT DeviceObject,
262 IN PIRP Irp,
263 IN PVOID Context
264 );
265
266 /* EOF */