Source code of Windows XP (NT5)
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.

424 lines
7.7 KiB

  1. #ifndef _HP_DSM_H_
  2. #define _HP_DSM_H_
  3. #include <ntddscsi.h>
  4. #include <scsi.h>
  5. #include "dsm.h"
  6. //
  7. // Set an arbitrary limit of 4 paths.
  8. //
  9. #define MAX_PATHS 4
  10. //
  11. // Device State defines.
  12. //
  13. #define DEV_ACTIVE 0x00000001
  14. #define DEV_PASSIVE 0x00000002
  15. #define DEV_FAILED 0x00000003
  16. //
  17. // Multi-path Group State
  18. //
  19. //
  20. // Fail-Over Group State
  21. //
  22. #define FG_NORMAL 0x00000001
  23. #define FG_PENDING 0x00000002
  24. #define FG_FAILBACK 0x00000003
  25. #define FG_FAILED 0x00000004
  26. //
  27. // Load-Balance Types
  28. //
  29. #define LB_ACTIVE_PASSIVE 0x01
  30. #define LB_STATIC 0x02
  31. #define LB_MIN_QUEUE 0x03
  32. #define LB_ROUNDROBIN 0x04
  33. //
  34. // Internal structures.
  35. //
  36. //
  37. // Statistics structure. Used by the device
  38. // and path routines.
  39. //
  40. typedef struct _DSM_STATS {
  41. ULONG NumberReads;
  42. LARGE_INTEGER BytesRead;
  43. ULONG NumberWrites;
  44. LARGE_INTEGER BytesWritten;
  45. } DSM_STATS, *PDSM_STATS;
  46. //
  47. // Dsm Context is the global driver
  48. // context that gets pushed to each of
  49. // the dsm entry points.
  50. //
  51. typedef struct _DSM_CONTEXT {
  52. KSPIN_LOCK SpinLock;
  53. ULONG NumberDevices;
  54. ULONG NumberGroups;
  55. ULONG NumberFOGroups;
  56. LIST_ENTRY DeviceList;
  57. LIST_ENTRY GroupList;
  58. LIST_ENTRY FailGroupList;
  59. PVOID MPIOContext;
  60. NPAGED_LOOKASIDE_LIST ContextList;
  61. } DSM_CONTEXT, *PDSM_CONTEXT;
  62. typedef struct _GROUP_ENTRY;
  63. typedef struct _FAILOVER_GROUP;
  64. //
  65. // Information about each device that's
  66. // supported.
  67. //
  68. typedef struct _DEVICE_INFO {
  69. LIST_ENTRY ListEntry;
  70. PVOID DsmContext;
  71. PDEVICE_OBJECT PortPdo;
  72. PDEVICE_OBJECT TargetObject;
  73. struct _GROUP_ENTRY *Group;
  74. struct _FAILOVER_GROUP *FailGroup;
  75. ULONG State;
  76. ULONG Controller;
  77. BOOLEAN NeedsVerification;
  78. UCHAR Reserved[3];
  79. LONG Requests;
  80. DSM_STATS Stats;
  81. UCHAR SerialNumber[20];
  82. STORAGE_DEVICE_DESCRIPTOR Descriptor;
  83. } DEVICE_INFO, *PDEVICE_INFO;
  84. //
  85. // Information about multi-path groups:
  86. // The same device found via multiple paths.
  87. //
  88. typedef struct _GROUP_ENTRY {
  89. LIST_ENTRY ListEntry;
  90. ULONG GroupNumber;
  91. BOOLEAN LoadBalanceInit;
  92. UCHAR LoadBalanceType;
  93. UCHAR Reserved[2];
  94. ULONG NumberDevices;
  95. PDEVICE_INFO DeviceList[MAX_PATHS];
  96. } GROUP_ENTRY, *PGROUP_ENTRY;
  97. //
  98. // The collection of devices on one path.
  99. // These fail-over as a unit.
  100. //
  101. typedef struct _FAILOVER_GROUP {
  102. LIST_ENTRY ListEntry;
  103. PVOID PathId;
  104. ULONG State;
  105. ULONG Count;
  106. //
  107. // BUGBUG: Revisit using an array
  108. //
  109. PDEVICE_INFO DeviceList[32];
  110. } FAILOVER_GROUP, *PFAILOVER_GROUP;
  111. //
  112. // Completion context structure.
  113. //
  114. typedef struct _COMPLETION_CONTEXT {
  115. LARGE_INTEGER TickCount;
  116. PDEVICE_INFO DeviceInfo;
  117. PDSM_CONTEXT DsmContext;
  118. } COMPLETION_CONTEXT, *PCOMPLETION_CONTEXT;
  119. //
  120. // Direct-Commands
  121. //
  122. #pragma pack(1)
  123. typedef struct _HP_ENQUIRY {
  124. UCHAR NumberSysDrives;
  125. UCHAR SDFlags;
  126. UCHAR EventChangeCounter;
  127. UCHAR Reserved;
  128. UCHAR DriveSizes[32];
  129. UCHAR ROMProgCount[2];
  130. UCHAR StatusFlag;
  131. UCHAR FreeStateChangeCount;
  132. UCHAR FwMinorRev;
  133. UCHAR FwMajorRev;
  134. UCHAR Fill[56];
  135. } HP_ENQUIRY, *PHP_ENQUIRY;
  136. typedef struct _HP_DAC_STATUS {
  137. UCHAR Format;
  138. UCHAR LUN;
  139. UCHAR SysDrive;
  140. UCHAR InformationLength;
  141. UCHAR MasterSlaveState[4];
  142. UCHAR MSAdditionalInfo[4];
  143. UCHAR PartnerStatus[4];
  144. UCHAR DACInfo[4];
  145. } HP_DAC_STATUS, *PHP_DAC_STATUS;
  146. #pragma pack()
  147. #define DCMD_ENQUIRY 0x05
  148. #define DCMD_GET_DAC_STATUS 0x55
  149. NTSTATUS
  150. HPSendDirectCommand(
  151. IN PDEVICE_OBJECT DeviceObject,
  152. IN PUCHAR Buffer,
  153. IN ULONG BufferSize,
  154. IN UCHAR Opcode
  155. );
  156. NTSTATUS
  157. HPSendScsiCommand(
  158. IN PDEVICE_OBJECT DeviceObject,
  159. IN PUCHAR Buffer,
  160. IN ULONG BufferSize,
  161. IN ULONG CdbLength,
  162. IN PCDB Cdb,
  163. IN BOOLEAN DataIn
  164. );
  165. //
  166. // Export functions.
  167. //
  168. NTSTATUS
  169. HPInquire (
  170. IN PVOID DsmContext,
  171. IN PDEVICE_OBJECT TargetDevice,
  172. IN PDEVICE_OBJECT PortObject,
  173. IN PSTORAGE_DEVICE_DESCRIPTOR Descriptor,
  174. IN PSTORAGE_DEVICE_ID_DESCRIPTOR DeviceIdList,
  175. OUT PVOID *DsmIdentifier
  176. );
  177. BOOLEAN
  178. HPCompareDevices(
  179. IN PVOID DsmContext,
  180. IN PVOID DsmId1,
  181. IN PVOID DsmId2
  182. );
  183. NTSTATUS
  184. HPSetDeviceInfo(
  185. IN PVOID DsmContext,
  186. IN PDEVICE_OBJECT TargetObject,
  187. IN PVOID DsmId,
  188. IN OUT PVOID *PathId
  189. );
  190. NTSTATUS
  191. HPGetControllerInfo(
  192. IN PVOID DsmContext,
  193. IN PVOID DsmId,
  194. IN ULONG Flags,
  195. IN OUT PCONTROLLER_INFO *ControllerInfo
  196. );
  197. BOOLEAN
  198. HPIsPathActive(
  199. IN PVOID DsmContext,
  200. IN PVOID PathId
  201. );
  202. NTSTATUS
  203. HPPathVerify(
  204. IN PVOID DsmContext,
  205. IN PVOID DsmId,
  206. IN PVOID PathId
  207. );
  208. NTSTATUS
  209. HPInvalidatePath(
  210. IN PVOID DsmContext,
  211. IN ULONG ErrorMask,
  212. IN PVOID PathId,
  213. IN OUT PVOID *NewPathId
  214. );
  215. NTSTATUS
  216. HPRemoveDevice(
  217. IN PVOID DsmContext,
  218. IN PVOID DsmId,
  219. IN PVOID PathId
  220. );
  221. NTSTATUS
  222. HPRemovePath(
  223. IN PDSM_CONTEXT DsmContext,
  224. IN PVOID PathId
  225. );
  226. NTSTATUS
  227. HPBringPathOnLine(
  228. IN PVOID DsmContext,
  229. IN PVOID PathId,
  230. OUT PULONG DSMError
  231. );
  232. PVOID
  233. HPLBGetPath(
  234. IN PVOID DsmContext,
  235. IN PSCSI_REQUEST_BLOCK Srb,
  236. IN PDSM_IDS DsmList,
  237. IN PVOID CurrentPath,
  238. OUT NTSTATUS *Status
  239. );
  240. ULONG
  241. HPCategorizeRequest(
  242. IN PVOID DsmContext,
  243. IN PDSM_IDS DsmIds,
  244. IN PIRP Irp,
  245. IN PSCSI_REQUEST_BLOCK Srb,
  246. IN PVOID CurrentPath,
  247. OUT PVOID *PathId,
  248. OUT NTSTATUS *Status
  249. );
  250. NTSTATUS
  251. HPBroadcastRequest(
  252. IN PVOID DsmContext,
  253. IN PDSM_IDS DsmIds,
  254. IN PIRP Irp,
  255. IN PSCSI_REQUEST_BLOCK Srb,
  256. IN PKEVENT Event
  257. );
  258. NTSTATUS
  259. HPSrbDeviceControl(
  260. IN PVOID DsmContext,
  261. IN PDSM_IDS DsmIds,
  262. IN PIRP Irp,
  263. IN PSCSI_REQUEST_BLOCK Srb,
  264. IN PKEVENT Event
  265. );
  266. VOID
  267. HPSetCompletion(
  268. IN PVOID DsmContext,
  269. IN PVOID DsmId,
  270. IN PIRP Irp,
  271. IN PSCSI_REQUEST_BLOCK Srb,
  272. IN OUT PDSM_COMPLETION_INFO DsmCompletion
  273. );
  274. ULONG
  275. HPInterpretError(
  276. IN PVOID DsmContext,
  277. IN PVOID DsmId,
  278. IN PSCSI_REQUEST_BLOCK Srb,
  279. IN OUT NTSTATUS *Status,
  280. OUT PBOOLEAN Retry
  281. );
  282. NTSTATUS
  283. HPUnload(
  284. IN PVOID DsmContext
  285. );
  286. //
  287. // Various utility functions.
  288. //
  289. PGROUP_ENTRY
  290. FindDevice(
  291. IN PDSM_CONTEXT DsmContext,
  292. IN PDEVICE_INFO DeviceInfo
  293. );
  294. PGROUP_ENTRY
  295. BuildGroupEntry (
  296. IN PDSM_CONTEXT DsmContext,
  297. IN PDEVICE_INFO deviceInfo
  298. );
  299. NTSTATUS
  300. AddGroupEntry(
  301. IN PDSM_CONTEXT DsmContext,
  302. IN PGROUP_ENTRY Group
  303. );
  304. NTSTATUS
  305. AddDeviceEntry(
  306. IN PDSM_CONTEXT DsmContext,
  307. IN PGROUP_ENTRY Group,
  308. IN PDEVICE_INFO DeviceInfo,
  309. IN ULONG DeviceState
  310. );
  311. VOID
  312. RemoveDeviceEntry(
  313. IN PDSM_CONTEXT DsmContext,
  314. IN PGROUP_ENTRY Group,
  315. IN PDEVICE_INFO DeviceInfo
  316. );
  317. PFAILOVER_GROUP
  318. FindFOGroup(
  319. IN PDSM_CONTEXT DsmContext,
  320. IN PVOID PathId
  321. );
  322. PFAILOVER_GROUP
  323. BuildFOGroup(
  324. IN PDSM_CONTEXT DsmContext,
  325. IN PDEVICE_INFO DeviceInfo,
  326. IN PVOID PathId
  327. );
  328. NTSTATUS
  329. UpdateFOGroup(
  330. IN PDSM_CONTEXT DsmContext,
  331. IN PFAILOVER_GROUP FailGroup,
  332. IN PDEVICE_INFO DeviceInfo
  333. );
  334. VOID
  335. RemoveDeviceFailGroup(
  336. IN PDSM_CONTEXT DsmContext,
  337. IN PFAILOVER_GROUP FailGroup,
  338. IN PDEVICE_INFO DeviceInfo
  339. );
  340. PFAILOVER_GROUP
  341. SetNewPath(
  342. IN PDSM_CONTEXT DsmContext,
  343. IN PGROUP_ENTRY Group,
  344. IN PDEVICE_INFO FailingDevice,
  345. IN PFAILOVER_GROUP SelectedPath
  346. );
  347. VOID
  348. LBInit(
  349. IN PDSM_CONTEXT DsmContext,
  350. IN PGROUP_ENTRY Group
  351. );
  352. VOID
  353. HPConvertHexToAscii(
  354. IN PUCHAR HexString,
  355. IN OUT PUCHAR AsciiString,
  356. IN ULONG Count
  357. );
  358. #define DEBUG_BUFFER_LENGTH 255
  359. UCHAR DebugBuffer[DEBUG_BUFFER_LENGTH + 1];
  360. ULONG HPDSMDebug = 1;
  361. VOID
  362. DsmDebugPrint(
  363. ULONG DebugPrintLevel,
  364. PCCHAR DebugMessage,
  365. ...
  366. );
  367. #ifdef DebugPrint
  368. #undef DebugPrint
  369. #define DebugPrint(x) DsmDebugPrint x
  370. #endif
  371. #endif // _HP_DSM_H