Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

524 lines
10 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. scsiboot.h
  5. Abstract:
  6. This file defines the necessary structures, defines, and functions for
  7. the common SCSI boot port driver.
  8. Author:
  9. Jeff Havens (jhavens) 28-Feb-1991
  10. Mike Glass
  11. Revision History:
  12. --*/
  13. #include "ntddscsi.h"
  14. //
  15. // SCSI Get Configuration Information
  16. //
  17. // LUN Information
  18. //
  19. typedef struct _LUNINFO {
  20. UCHAR PathId;
  21. UCHAR TargetId;
  22. UCHAR Lun;
  23. BOOLEAN DeviceClaimed;
  24. PVOID DeviceObject;
  25. struct _LUNINFO *NextLunInfo;
  26. UCHAR InquiryData[INQUIRYDATABUFFERSIZE];
  27. } LUNINFO, *PLUNINFO;
  28. typedef struct _SCSI_BUS_SCAN_DATA {
  29. USHORT Length;
  30. UCHAR InitiatorBusId;
  31. UCHAR NumberOfLogicalUnits;
  32. PLUNINFO LunInfoList;
  33. } SCSI_BUS_SCAN_DATA, *PSCSI_BUS_SCAN_DATA;
  34. typedef struct _SCSI_CONFIGURATION_INFO {
  35. UCHAR NumberOfBuses;
  36. PSCSI_BUS_SCAN_DATA BusScanData[1];
  37. } SCSI_CONFIGURATION_INFO, *PSCSI_CONFIGURATION_INFO;
  38. #define MAXIMUM_RETRIES 4
  39. //
  40. // SCSI device timeout values in seconds
  41. //
  42. #define SCSI_DISK_TIMEOUT 10
  43. #define SCSI_CDROM_TIMEOUT 10
  44. #define SCSI_TAPE_TIMEOUT 120
  45. //
  46. // Adapter object transfer information.
  47. //
  48. typedef struct _ADAPTER_TRANSFER {
  49. PSCSI_REQUEST_BLOCK Srb;
  50. PVOID LogicalAddress;
  51. ULONG Length;
  52. }ADAPTER_TRANSFER, *PADAPTER_TRANSFER;
  53. typedef struct _SRB_SCATTER_GATHER {
  54. ULONG PhysicalAddress;
  55. ULONG Length;
  56. }SRB_SCATTER_GATHER, *PSRB_SCATTER_GATHER;
  57. //
  58. // Srb Structure plus extra storage for the port driver.
  59. //
  60. #define IRP_STACK_SIZE 2
  61. typedef struct _FULL_SCSI_REQUEST_BLOCK {
  62. SCSI_REQUEST_BLOCK Srb;
  63. PVOID PreviousIrp;
  64. IRP Irp;
  65. IO_STACK_LOCATION IrpStack[IRP_STACK_SIZE];
  66. ULONG SrbExtensionSize;
  67. MDL Mdl;
  68. ULONG PageFrame[20];
  69. }FULL_SCSI_REQUEST_BLOCK, *PFULL_SCSI_REQUEST_BLOCK;
  70. //
  71. // Logical unit extension
  72. //
  73. typedef struct _LOGICAL_UNIT_EXTENSION {
  74. UCHAR PathId;
  75. UCHAR TargetId;
  76. UCHAR Lun;
  77. ULONG Flags;
  78. PIRP CurrentRequest;
  79. KSPIN_LOCK CurrentRequestSpinLock;
  80. PVOID SpecificLuExtension;
  81. struct _LOGICAL_UNIT_EXTENSION *NextLogicalUnit;
  82. KDEVICE_QUEUE RequestQueue;
  83. KSPIN_LOCK RequestQueueSpinLock;
  84. LONG RequestTimeoutCounter;
  85. ULONG RetryCount;
  86. UCHAR NumberOfLogicalUnits;
  87. PVOID MapRegisterBase;
  88. ULONG NumberOfMapRegisters;
  89. SRB_SCATTER_GATHER ScatterGather[17];
  90. } LOGICAL_UNIT_EXTENSION, *PLOGICAL_UNIT_EXTENSION;
  91. //
  92. // Device extension
  93. //
  94. typedef struct _DEVICE_EXTENSION {
  95. PDEVICE_OBJECT DeviceObject;
  96. //
  97. // Dma Adapter information.
  98. //
  99. PVOID MapRegisterBase;
  100. PADAPTER_OBJECT DmaAdapterObject;
  101. ADAPTER_TRANSFER FlushAdapterParameters;
  102. //
  103. // Number of SCSI buses
  104. //
  105. UCHAR NumberOfBuses;
  106. //
  107. // Maximum targets per bus
  108. //
  109. UCHAR MaximumTargetIds;
  110. //
  111. // SCSI Capabilities structure
  112. //
  113. IO_SCSI_CAPABILITIES Capabilities;
  114. //
  115. // SCSI port driver flags
  116. //
  117. ULONG Flags;
  118. //
  119. // SCSI port interrupt flags
  120. //
  121. ULONG InterruptFlags;
  122. //
  123. // List head for singlely linked list of complete IRPs.
  124. //
  125. PIRP CompletedRequests;
  126. //
  127. // Adapter object transfer parameters.
  128. //
  129. ADAPTER_TRANSFER MapTransferParameters;
  130. KSPIN_LOCK SpinLock;
  131. //
  132. // Miniport Initialization Routine
  133. //
  134. PHW_INITIALIZE HwInitialize;
  135. //
  136. // Miniport Start IO Routine
  137. //
  138. PHW_STARTIO HwStartIo;
  139. //
  140. // Miniport Interrupt Service Routine
  141. //
  142. PHW_INTERRUPT HwInterrupt;
  143. //
  144. // Miniport Reset Routine
  145. //
  146. PHW_RESET_BUS HwReset;
  147. //
  148. // Miniport DMA started Routine
  149. //
  150. PHW_DMA_STARTED HwDmaStarted;
  151. //
  152. // Buffers must be mapped into system space.
  153. //
  154. BOOLEAN MapBuffers;
  155. //
  156. // Is this device a bus master and does it require map registers.
  157. //
  158. BOOLEAN MasterWithAdapter;
  159. //
  160. // Device extension for miniport routines.
  161. //
  162. PVOID HwDeviceExtension;
  163. //
  164. // Miniport request interrupt enabled/disable routine.
  165. //
  166. PHW_INTERRUPT HwRequestInterrupt;
  167. //
  168. // Miniport timer request routine.
  169. //
  170. PHW_INTERRUPT HwTimerRequest;
  171. //
  172. // Adapter control routine.
  173. //
  174. PHW_ADAPTER_CONTROL HwAdapterControl;
  175. //
  176. // SCSI configuration information from inquiries.
  177. //
  178. PSCSI_CONFIGURATION_INFO ScsiInfo;
  179. //
  180. // Miniport noncached device extension
  181. //
  182. PVOID NonCachedExtension;
  183. //
  184. // The length of the non-cached extension
  185. //
  186. ULONG NonCachedExtensionSize;
  187. //
  188. // SrbExtension Zone Pool
  189. //
  190. PVOID SrbExtensionZonePool;
  191. PCHAR SrbExtensionPointer;
  192. //
  193. // Physical address of zone pool
  194. //
  195. ULONG PhysicalZoneBase;
  196. //
  197. // Size of Srb extension.
  198. //
  199. ULONG SrbExtensionSize;
  200. //
  201. // Spinlock for zoned hash table entries
  202. //
  203. KSPIN_LOCK ZoneSpinLock;
  204. //
  205. // Logical Unit Extension
  206. //
  207. ULONG HwLogicalUnitExtensionSize;
  208. PLOGICAL_UNIT_EXTENSION LogicalUnitList;
  209. ULONG TimerValue;
  210. //
  211. // Port timing count.
  212. //
  213. LONG PortTimeoutCounter;
  214. //
  215. // Shutdown Information.
  216. //
  217. BOOLEAN HasShutdown;
  218. BOOLEAN HasSetBoot;
  219. } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
  220. #define DEVICE_EXTENSION_SIZE sizeof(DEVICE_EXTENSION)
  221. //
  222. // Port driver extension flags.
  223. //
  224. #define PD_CURRENT_IRP_VALID 0X0001
  225. #define PD_RESET_DETECTED 0X0002
  226. #define PD_NOTIFICATION_IN_PROGRESS 0X0004
  227. #define PD_READY_FOR_NEXT_REQUEST 0X0008
  228. #define PD_FLUSH_ADAPTER_BUFFERS 0X0010
  229. #define PD_MAP_TRANSFER 0X0020
  230. #define PD_CALL_DMA_STARTED 0X01000
  231. #define PD_DISABLE_CALL_REQUEST 0X02000
  232. #define PD_DISABLE_INTERRUPTS 0X04000
  233. #define PD_ENABLE_CALL_REQUEST 0X08000
  234. #define PD_TIMER_CALL_REQUEST 0X10000
  235. //
  236. // Logical unit extension flags.
  237. //
  238. #define PD_QUEUE_FROZEN 0X0001
  239. #define PD_LOGICAL_UNIT_IS_ACTIVE 0X0002
  240. #define PD_CURRENT_REQUEST_COMPLETE 0X0004
  241. #define PD_LOGICAL_UNIT_IS_BUSY 0X0008
  242. //
  243. // The timer interval for the miniport timer routine specified in
  244. // units of 100 nanoseconds.
  245. //
  246. #define PD_TIMER_INTERVAL (250 * 1000 * 10) // 250 ms
  247. #define PD_TIMER_RESET_HOLD_TIME 4
  248. //
  249. // The define the interloop stall.
  250. //
  251. #define PD_INTERLOOP_STALL 5
  252. #define MINIMUM_SRB_EXTENSIONS 8
  253. #define COMPLETION_DELAY 10
  254. //
  255. // Port driver error logging
  256. //
  257. #define ERROR_LOG_ENTRY_LENGTH 8
  258. typedef struct _ERROR_LOG_ENTRY {
  259. UCHAR PathId;
  260. UCHAR TargetId;
  261. UCHAR Lun;
  262. ULONG ErrorCode;
  263. ULONG UniqueId;
  264. } ERROR_LOG_ENTRY, *PERROR_LOG_ENTRY;
  265. //
  266. // Define global data structures
  267. //
  268. extern ULONG ScsiPortCount;
  269. extern FULL_SCSI_REQUEST_BLOCK PrimarySrb;
  270. extern FULL_SCSI_REQUEST_BLOCK AbortSrb;
  271. #define MAXIMUM_NUMBER_OF_SCSIPORT_OBJECTS 16
  272. extern PDEVICE_OBJECT ScsiPortDeviceObject[MAXIMUM_NUMBER_OF_SCSIPORT_OBJECTS];
  273. extern PREAD_CAPACITY_DATA ReadCapacityBuffer;
  274. extern PUCHAR SenseInfoBuffer;
  275. //
  276. // Support routine.
  277. //
  278. PIRP
  279. InitializeIrp(
  280. PFULL_SCSI_REQUEST_BLOCK FullSrb,
  281. CCHAR MajorFunction,
  282. PVOID DeviceObject,
  283. PVOID BufferPointer,
  284. ULONG BufferSize
  285. );
  286. ARC_STATUS
  287. GetAdapterCapabilities(
  288. IN PDEVICE_OBJECT PortDeviceObject,
  289. OUT PIO_SCSI_CAPABILITIES *PortCapabilities
  290. );
  291. ARC_STATUS
  292. GetInquiryData(
  293. IN PDEVICE_OBJECT PortDeviceObject,
  294. IN PSCSI_CONFIGURATION_INFO *ConfigInfo
  295. );
  296. ARC_STATUS
  297. ReadDriveCapacity(
  298. IN PPARTITION_CONTEXT PartitionContext
  299. );
  300. ARC_STATUS
  301. ScsiClassIoComplete(
  302. IN PPARTITION_CONTEXT PartitionContext,
  303. IN PIRP Irp,
  304. IN PVOID Context
  305. );
  306. ARC_STATUS
  307. SendSrbSynchronous(
  308. PPARTITION_CONTEXT PartitionContext,
  309. PSCSI_REQUEST_BLOCK Srb,
  310. PVOID BufferAddress,
  311. ULONG BufferLength,
  312. BOOLEAN WriteToDevice
  313. );
  314. BOOLEAN
  315. InterpretSenseInfo(
  316. IN PSCSI_REQUEST_BLOCK Srb,
  317. OUT ARC_STATUS *Status,
  318. PPARTITION_CONTEXT PartitionContext
  319. );
  320. VOID
  321. RetryRequest(
  322. PPARTITION_CONTEXT PartitionContext,
  323. PIRP Irp
  324. );
  325. PIRP
  326. BuildRequest(
  327. IN PPARTITION_CONTEXT PartitionContext,
  328. IN PMDL Mdl,
  329. IN ULONG LogicalBlockAddress,
  330. IN BOOLEAN Operation
  331. );
  332. //
  333. // Define the necessary functions to simulate the I/O environment.
  334. //
  335. #define ExAllocatePool(Type, Size) FwAllocatePool(Size)
  336. #if !defined(_MIPS_) && !defined(_ALPHA_) && !defined(_PPC_)
  337. #define PAUSE while (!GET_KEY());
  338. typedef struct _DRIVER_LOOKUP_ENTRY {
  339. PCHAR DevicePath;
  340. PBL_DEVICE_ENTRY_TABLE DispatchTable;
  341. } DRIVER_LOOKUP_ENTRY, *PDRIVER_LOOKUP_ENTRY;
  342. #undef ASSERT
  343. #define ASSERT( exp ) { \
  344. if (!(#exp)) { \
  345. BlPrint("ASSERT File: %s line: %lx\n", __FILE__, __LINE__); \
  346. PAUSE; \
  347. } \
  348. }
  349. VOID
  350. ScsiPortExecute(
  351. IN PDEVICE_OBJECT DeviceObject,
  352. IN PIRP Irp
  353. );
  354. #endif
  355. #if defined ExFreePool
  356. #undef ExFreePool
  357. #endif
  358. #define ExFreePool(Size)
  359. #ifdef IoCallDriver
  360. #undef IoCallDriver
  361. #endif
  362. #define IoCallDriver(DeviceObject, Irp) ( \
  363. DeviceObject->CurrentIrp = Irp, \
  364. Irp->Tail.Overlay.CurrentStackLocation--, \
  365. ScsiPortExecute(DeviceObject, Irp), \
  366. Irp->Tail.Overlay.CurrentStackLocation++ )
  367. #ifdef IoCompleteRequest
  368. #undef IoCompleteRequest
  369. #endif
  370. #define IoCompleteRequest(Irp, Boost) Irp->PendingReturned = FALSE
  371. #define IoAllocateErrorLogEntry(DeviceObject, Length) NULL
  372. #define IoWriteErrorLogEntry(Entry)
  373. #ifdef KeAcquireSpinLock
  374. #undef KeAcquireSpinLock
  375. #endif
  376. #define KeAcquireSpinLock(Lock, Irql)
  377. #ifdef KeReleaseSpinLock
  378. #undef KeReleaseSpinLock
  379. #endif
  380. #define KeReleaseSpinLock(Lock, Irql)
  381. #define KiAcquireSpinLock(Lock)
  382. #ifdef KiReleaseSpinLock
  383. #undef KiReleaseSpinLock
  384. #endif
  385. #define KiReleaseSpinLock(Lock)
  386. #define KeSynchronizeExecution(InterruptObject, ExecutionRoutine, Context) \
  387. (ExecutionRoutine)(Context)
  388. #ifdef KeRaiseIrql
  389. #undef KeRaiseIrql
  390. #endif
  391. #define KeRaiseIrql(NewLevel, OldLevel)
  392. #ifdef KeLowerIrql
  393. #undef KeLowerIrql
  394. #endif
  395. #define KeLowerIrql(Level)