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.

589 lines
13 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. portlib.h
  5. Abstract:
  6. Contains all structure and routine definitions for storage port driver
  7. library.
  8. Author:
  9. John Strange (JohnStra)
  10. Environment:
  11. Kernel mode only.
  12. Notes:
  13. Revision History:
  14. --*/
  15. #ifndef _PASSTHRU_H_
  16. #define _PASSTHRU_H_
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif // __cplusplus
  20. typedef struct _PORT_PASSTHROUGH_INFO {
  21. PDEVICE_OBJECT Pdo;
  22. PSCSI_PASS_THROUGH SrbControl;
  23. PIRP RequestIrp;
  24. PVOID Buffer;
  25. PVOID SrbBuffer;
  26. ULONG BufferOffset;
  27. ULONG Length;
  28. #if defined (_WIN64)
  29. PSCSI_PASS_THROUGH32 SrbControl32;
  30. SCSI_PASS_THROUGH SrbControl64;
  31. #endif
  32. UCHAR MajorCode;
  33. } PORT_PASSTHROUGH_INFO, *PPORT_PASSTHROUGH_INFO;
  34. typedef struct _PORT_ADAPTER_REGISTRY_VALUES {
  35. ULONG MaxLuCount;
  36. ULONG EnableDebugging;
  37. ULONG SrbFlags;
  38. PHYSICAL_ADDRESS MinimumCommonBufferBase;
  39. PHYSICAL_ADDRESS MaximumCommonBufferBase;
  40. ULONG NumberOfRequests;
  41. ULONG InquiryTimeout;
  42. ULONG ResetHoldTime;
  43. ULONG UncachedExtAlignment;
  44. BOOLEAN CreateInitiatorLU;
  45. BOOLEAN DisableTaggedQueueing;
  46. BOOLEAN DisableMultipleLu;
  47. ULONG AdapterNumber;
  48. ULONG BusNumber;
  49. PVOID Parameter;
  50. PACCESS_RANGE AccessRanges;
  51. UNICODE_STRING RegistryPath;
  52. PORT_CONFIGURATION_INFORMATION PortConfig;
  53. }PORT_ADAPTER_REGISTRY_VALUES, *PPORT_ADAPTER_REGISTRY_VALUES;
  54. //
  55. // registry parameters
  56. //
  57. #define MAXIMUM_LOGICAL_UNIT 0x00001
  58. #define INITIATOR_TARGET_ID 0x00002
  59. #define SCSI_DEBUG 0x00004
  60. #define BREAK_POINT_ON_ENTRY 0x00008
  61. #define DISABLE_SYNCHRONOUS_TRANSFERS 0x00010
  62. #define DISABLE_DISCONNECTS 0x00020
  63. #define DISABLE_TAGGED_QUEUING 0x00040
  64. #define DISABLE_MULTIPLE_REQUESTS 0x00080
  65. #define MAXIMUM_UCX_ADDRESS 0x00100
  66. #define MINIMUM_UCX_ADDRESS 0x00200
  67. #define DRIVER_PARAMETERS 0x00400
  68. #define MAXIMUM_SG_LIST 0x00800
  69. #define NUMBER_OF_REQUESTS 0x01000
  70. #define RESOURCE_LIST 0x02000
  71. #define CONFIGURATION_DATA 0x04000
  72. #define UNCACHED_EXT_ALIGNMENT 0x08000
  73. #define INQUIRY_TIMEOUT 0x10000
  74. #define RESET_HOLD_TIME 0x20000
  75. #define CREATE_INITIATOR_LU 0x40000
  76. //
  77. // Uninitialized flag value.
  78. //
  79. #define PORT_UNINITIALIZED_VALUE ((ULONG) ~0)
  80. //
  81. // Define PORT maximum configuration parameters.
  82. //
  83. #define PORT_MAXIMUM_LOGICAL_UNITS 8
  84. #define PORT_MINIMUM_PHYSICAL_BREAKS 16
  85. #define PORT_MAXIMUM_PHYSICAL_BREAKS 255
  86. #define MAX_UNCACHED_EXT_ALIGNMENT 16
  87. #define MIN_UNCACHED_EXT_ALIGNMENT 3
  88. #define MAX_TIMEOUT_VALUE 60
  89. #define MAX_RESET_HOLD_TIME 60
  90. //
  91. // Define the mimimum and maximum number of srb extensions which will be allocated.
  92. //
  93. #define MINIMUM_EXTENSIONS 16
  94. #define MAXIMUM_EXTENSIONS 255
  95. //
  96. // This routine verifies that the supplied IRP contains a valid
  97. // SCSI_PASS_THROUGH structure and returns a pointer to a SCSI_PASS_THROUGH
  98. // structure witch the caller may use. If necessary, the routine will marshal
  99. // the contents of the structure from 32-bit to 64-bit format. If the caller
  100. // makes any changes to the contents of the SCSI_PASS_THROUGH structure, it
  101. // must call PortPassThroughCleanup in case the structure needs to be marshaled
  102. // back to its original format.
  103. //
  104. NTSTATUS
  105. PortGetPassThrough(
  106. IN OUT PPORT_PASSTHROUGH_INFO PassThroughInfo,
  107. IN PIRP Irp,
  108. IN BOOLEAN Direct
  109. );
  110. //
  111. // This routine should be called after processing a passthrough request. The
  112. // routine will perform any necessary cleanup and it will ensure that any
  113. // changes made to the SCSI_PASS_THROUGH structure are marshaled back to the
  114. // original format if necessary.
  115. //
  116. VOID
  117. PortPassThroughCleanup(
  118. IN PPORT_PASSTHROUGH_INFO PassThroughInfo
  119. );
  120. //
  121. // This routine performs validation checks on the input and output buffers
  122. // supplied by the caller and performs all the required initialization
  123. // in preperation for proper handling of a SCSI passthrough request.
  124. //
  125. NTSTATUS
  126. PortPassThroughInitialize(
  127. IN OUT PPORT_PASSTHROUGH_INFO PassThroughInfo,
  128. IN PIRP Irp,
  129. IN PIO_SCSI_CAPABILITIES Capabilities,
  130. IN PDEVICE_OBJECT Pdo,
  131. IN BOOLEAN Direct
  132. );
  133. //
  134. // This routine initialize a caller-supplied SRB for dispatching.
  135. //
  136. NTSTATUS
  137. PortPassThroughInitializeSrb(
  138. IN PPORT_PASSTHROUGH_INFO PassThroughInfo,
  139. IN PSCSI_REQUEST_BLOCK Srb,
  140. IN PIRP Irp,
  141. IN ULONG SrbFlags,
  142. IN PVOID SenseBuffer
  143. );
  144. //
  145. // This routine offers a turn-key passthrough solution. The caller must
  146. // have called PortGetPassThrough to initialize a pointer to the
  147. // SCSI_PASS_THROUGH structure and obtained a pointer to the PDO to which
  148. // the passthrough request is to be dispatched. This routine does the rest.
  149. //
  150. NTSTATUS
  151. PortSendPassThrough(
  152. IN PDEVICE_OBJECT Pdo,
  153. IN PIRP Irp,
  154. IN BOOLEAN Direct,
  155. IN ULONG SrbFlags,
  156. IN PIO_SCSI_CAPABILITIES Capabilities
  157. );
  158. //
  159. // This routine will safely set the SCSI address in the SCSI_PASS_THROUGH
  160. // structure of the supplied IRP.
  161. //
  162. NTSTATUS
  163. PortSetPassThroughAddress(
  164. IN PIRP Irp,
  165. IN UCHAR PathId,
  166. IN UCHAR TargetId,
  167. IN UCHAR Lun
  168. );
  169. VOID
  170. PortPassThroughMarshalResults(
  171. IN PPORT_PASSTHROUGH_INFO PassThroughInfo,
  172. IN PSCSI_REQUEST_BLOCK Srb,
  173. IN PIRP RequestIrp,
  174. IN PIO_STATUS_BLOCK IoStatusBlock,
  175. IN BOOLEAN Direct
  176. );
  177. NTSTATUS
  178. PortGetMPIODeviceList(
  179. IN PUNICODE_STRING RegistryPath,
  180. OUT PUNICODE_STRING MPIODeviceList
  181. );
  182. BOOLEAN
  183. PortIsDeviceMPIOSupported(
  184. IN PUNICODE_STRING DeviceList,
  185. IN PUCHAR VendorId,
  186. IN PUCHAR ProductId
  187. );
  188. NTSTATUS
  189. PortGetPassThroughAddress(
  190. IN PIRP Irp,
  191. OUT PUCHAR PathId,
  192. OUT PUCHAR TargetId,
  193. OUT PUCHAR Lun
  194. );
  195. //
  196. // Bugcheck Callback support structures and routines.
  197. //
  198. typedef struct _KBUGCHECK_DATA {
  199. ULONG BugCheckCode;
  200. ULONG_PTR BugCheckParameter1;
  201. ULONG_PTR BugCheckParameter2;
  202. ULONG_PTR BugCheckParameter3;
  203. ULONG_PTR BugCheckParameter4;
  204. } KBUGCHECK_DATA, *PKBUGCHECK_DATA;
  205. typedef
  206. (*PPORT_BUGCHECK_CALLBACK_ROUTINE)(
  207. IN PKBUGCHECK_DATA BugcheckData,
  208. IN PVOID BugcheckBuffer,
  209. IN ULONG BugcheckBufferSize,
  210. IN PULONG BugcheckBufferUsed
  211. );
  212. typedef const GUID* PCGUID;
  213. //
  214. // Registry access support routines.
  215. //
  216. NTSTATUS
  217. PortRegisterBugcheckCallback(
  218. IN PCGUID BugcheckDataGuid,
  219. IN PPORT_BUGCHECK_CALLBACK_ROUTINE BugcheckRoutine
  220. );
  221. NTSTATUS
  222. PortDeregisterBugcheckCallback(
  223. IN PCGUID BugcheckDataGuid
  224. );
  225. HANDLE
  226. PortOpenDeviceKey(
  227. IN PUNICODE_STRING RegistryPath,
  228. IN ULONG DeviceNumber
  229. );
  230. VOID
  231. PortGetDriverParameters(
  232. IN PUNICODE_STRING RegistryPath,
  233. IN ULONG DeviceNumber,
  234. OUT PVOID * DriverParameters
  235. );
  236. VOID
  237. PortGetLinkTimeoutValue(
  238. IN PUNICODE_STRING RegistryPath,
  239. IN ULONG DeviceNumber,
  240. OUT PULONG LinkTimeoutValue
  241. );
  242. VOID
  243. PortGetDiskTimeoutValue(
  244. OUT PULONG DiskTimeout
  245. );
  246. VOID
  247. PortFreeDriverParameters(
  248. IN PVOID DriverParameters
  249. );
  250. VOID
  251. PortGetRegistrySettings(
  252. IN PUNICODE_STRING RegistryPath,
  253. IN ULONG DeviceNumber,
  254. IN PPORT_ADAPTER_REGISTRY_VALUES Context,
  255. IN ULONG Fields
  256. );
  257. //
  258. // This structure describes the information needed by the registry routine library
  259. // to handle the memory allocations and frees for the miniport.
  260. //
  261. typedef struct _PORT_REGISTRY_INFO {
  262. //
  263. // Size, in bytes, of the structure.
  264. //
  265. ULONG Size;
  266. //
  267. // Not used currently, but if multiple buffers are allowed, link them here.
  268. //
  269. LIST_ENTRY ListEntry;
  270. //
  271. // G.P. SpinLock
  272. //
  273. KSPIN_LOCK SpinLock;
  274. //
  275. // The miniport's registry buffer.
  276. //
  277. PUCHAR Buffer;
  278. //
  279. // The allocated length of the buffer.
  280. //
  281. ULONG AllocatedLength;
  282. //
  283. // The size currently being used.
  284. //
  285. ULONG CurrentLength;
  286. //
  287. // Used to pass around what the buffer should be for the current
  288. // operation.
  289. //
  290. ULONG LengthNeeded;
  291. //
  292. // Offset into the Buffer that should be used for the
  293. // current operation.
  294. //
  295. ULONG Offset;
  296. //
  297. // Various state bits. See below for defines.
  298. //
  299. ULONG Flags;
  300. //
  301. // Used to pass status back and forth between
  302. // the portlib calling routine and the registry
  303. // callback.
  304. //
  305. NTSTATUS InternalStatus;
  306. } PORT_REGISTRY_INFO, *PPORT_REGISTRY_INFO;
  307. NTSTATUS
  308. PortMiniportRegistryInitialize(
  309. IN OUT PPORT_REGISTRY_INFO PortContext
  310. );
  311. VOID
  312. PortMiniportRegistryDestroy(
  313. IN PPORT_REGISTRY_INFO PortContext
  314. );
  315. NTSTATUS
  316. PortAllocateRegistryBuffer(
  317. IN PPORT_REGISTRY_INFO PortContext
  318. );
  319. NTSTATUS
  320. PortFreeRegistryBuffer(
  321. IN PPORT_REGISTRY_INFO PortContext
  322. );
  323. NTSTATUS
  324. PortBuildRegKeyName(
  325. IN PUNICODE_STRING RegistryPath,
  326. IN OUT PUNICODE_STRING KeyName,
  327. IN ULONG PortNumber,
  328. IN ULONG Global
  329. );
  330. NTSTATUS
  331. PortAsciiToUnicode(
  332. IN PUCHAR AsciiString,
  333. OUT PUNICODE_STRING UnicodeString
  334. );
  335. NTSTATUS
  336. PortRegistryRead(
  337. IN PUNICODE_STRING RegistryKeyName,
  338. IN PUNICODE_STRING ValueName,
  339. IN ULONG Type,
  340. IN PPORT_REGISTRY_INFO PortContext
  341. );
  342. NTSTATUS
  343. PortRegistryWrite(
  344. IN PUNICODE_STRING RegistryKeyName,
  345. IN PUNICODE_STRING ValueName,
  346. IN ULONG Type,
  347. IN PPORT_REGISTRY_INFO PortContext
  348. );
  349. VOID
  350. PortReadRegistrySettings(
  351. IN HANDLE Key,
  352. IN PPORT_ADAPTER_REGISTRY_VALUES Context,
  353. IN ULONG Fields
  354. );
  355. NTSTATUS
  356. PortCreateKeyEx(
  357. IN HANDLE Key,
  358. IN ULONG CreateOptions,
  359. OUT PHANDLE NewKeyBuffer, OPTIONAL
  360. IN PCWSTR Format,
  361. ...
  362. );
  363. //
  364. // Additional data type for the Type parameter in PortSetValueKey.
  365. //
  366. #define PORT_REG_ANSI_STRING (0x07232002)
  367. NTSTATUS
  368. PortSetValueKey(
  369. IN HANDLE KeyHandle,
  370. IN PCWSTR ValueName,
  371. IN ULONG Type,
  372. IN PVOID Data,
  373. IN ULONG DataSize
  374. );
  375. //
  376. // SCSI DEVIC TYPE structure.
  377. //
  378. typedef struct _SCSI_DEVICE_TYPE {
  379. //
  380. // String specifying the device name, e.g., "Disk", "Sequential", etc.
  381. //
  382. PCSTR Name;
  383. //
  384. // The generic device name for this device, e.g., "GenDisk",
  385. // "GenPrinter", etc.
  386. //
  387. PCSTR GenericName;
  388. //
  389. // Name of the device as stored in the SCSI DeviceMap.
  390. //
  391. PCWSTR DeviceMap;
  392. //
  393. // Is this a storage device?
  394. //
  395. BOOLEAN IsStorage;
  396. } SCSI_DEVICE_TYPE, *PSCSI_DEVICE_TYPE;
  397. typedef const SCSI_DEVICE_TYPE* PCSCSI_DEVICE_TYPE;
  398. typedef GUID* PGUID;
  399. PCSCSI_DEVICE_TYPE
  400. PortGetDeviceType(
  401. IN ULONG DeviceType
  402. );
  403. NTSTATUS
  404. PortOpenMapKey(
  405. OUT PHANDLE DeviceMapKey
  406. );
  407. NTSTATUS
  408. PortMapBuildAdapterEntry(
  409. IN HANDLE DeviceMapKey,
  410. IN ULONG PortNumber,
  411. IN ULONG InterruptLevel,
  412. IN ULONG IoAddress,
  413. IN ULONG Dma64BitAddresses,
  414. IN PUNICODE_STRING DriverName,
  415. IN PGUID BusType, OPTIONAL
  416. OUT PHANDLE AdapterKey OPTIONAL
  417. );
  418. NTSTATUS
  419. PortMapBuildBusEntry(
  420. IN HANDLE AdapterKey,
  421. IN ULONG BusId,
  422. IN ULONG InitiatorId,
  423. OUT PHANDLE BusKeyBuffer OPTIONAL
  424. );
  425. NTSTATUS
  426. PortMapBuildTargetEntry(
  427. IN HANDLE BusKey,
  428. IN ULONG TargetId,
  429. OUT PHANDLE TargetKey OPTIONAL
  430. );
  431. NTSTATUS
  432. PortMapBuildLunEntry(
  433. IN HANDLE TargetKey,
  434. IN ULONG Lun,
  435. IN PINQUIRYDATA InquiryData,
  436. IN PANSI_STRING SerialNumber, OPTIONAL
  437. PVOID DeviceId,
  438. IN ULONG DeviceIdLength,
  439. OUT PHANDLE LunKeyBuffer OPTIONAL
  440. );
  441. NTSTATUS
  442. PortMapDeleteAdapterEntry(
  443. IN ULONG PortId
  444. );
  445. NTSTATUS
  446. PortMapDeleteLunEntry(
  447. IN ULONG PortId,
  448. IN ULONG BusId,
  449. IN ULONG TargetId,
  450. IN ULONG Lun
  451. );
  452. typedef struct _INTERNAL_WAIT_CONTEXT_BLOCK {
  453. ULONG Flags;
  454. PMDL Mdl;
  455. PMDL DmaMdl;
  456. PVOID MapRegisterBase;
  457. PVOID CurrentVa;
  458. ULONG Length;
  459. ULONG NumberOfMapRegisters;
  460. union {
  461. struct {
  462. WAIT_CONTEXT_BLOCK Wcb;
  463. PDRIVER_LIST_CONTROL DriverExecutionRoutine;
  464. PVOID DriverContext;
  465. PIRP CurrentIrp;
  466. PADAPTER_OBJECT AdapterObject;
  467. BOOLEAN WriteToDevice;
  468. };
  469. SCATTER_GATHER_LIST ScatterGather;
  470. };
  471. } INTERNAL_WAIT_CONTEXT_BLOCK, *PINTERNAL_WAIT_CONTEXT_BLOCK;
  472. #ifdef __cplusplus
  473. }
  474. #endif // __cplusplus
  475. #endif //_PASSTHRU_H_