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.

393 lines
7.2 KiB

  1. #ifndef _GEN_DSM_H_
  2. #define _GEN_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. #define DEV_PENDING_REMOVE 0x00000004
  17. #define DEV_REMOVED 0x00000005
  18. //
  19. // Multi-path Group State
  20. //
  21. //
  22. // Fail-Over Group State
  23. //
  24. #define FG_NORMAL 0x00000001
  25. #define FG_PENDING 0x00000002
  26. #define FG_FAILBACK 0x00000003
  27. #define FG_FAILED 0x00000004
  28. //
  29. // Load-Balance Types
  30. //
  31. #define LB_ACTIVE_PASSIVE 0x01
  32. #define LB_STATIC 0x02
  33. #define LB_MIN_QUEUE 0x03
  34. #define LB_ROUNDROBIN 0x04
  35. #define DSM_DEVICE_SIG 0xAAAAAAAA
  36. #define DSM_GROUP_SIG 0x55555555
  37. #define DSM_FOG_SIG 0x88888888
  38. //
  39. // Internal structures.
  40. //
  41. //
  42. // Statistics structure. Used by the device
  43. // and path routines.
  44. //
  45. typedef struct _DSM_STATS {
  46. ULONG NumberReads;
  47. LARGE_INTEGER BytesRead;
  48. ULONG NumberWrites;
  49. LARGE_INTEGER BytesWritten;
  50. } DSM_STATS, *PDSM_STATS;
  51. //
  52. // Dsm Context is the global driver
  53. // context that gets pushed to each of
  54. // the dsm entry points.
  55. //
  56. typedef struct _DSM_CONTEXT {
  57. UNICODE_STRING SupportedDevices;
  58. KSPIN_LOCK SpinLock;
  59. ULONG NumberDevices;
  60. ULONG NumberGroups;
  61. ULONG NumberFOGroups;
  62. LIST_ENTRY DeviceList;
  63. LIST_ENTRY GroupList;
  64. LIST_ENTRY FailGroupList;
  65. PVOID MPIOContext;
  66. ULONG ControllerId;
  67. NPAGED_LOOKASIDE_LIST ContextList;
  68. } DSM_CONTEXT, *PDSM_CONTEXT;
  69. typedef struct _GROUP_ENTRY;
  70. typedef struct _FAILOVER_GROUP;
  71. //
  72. // Information about each device that's
  73. // supported.
  74. //
  75. typedef struct _DEVICE_INFO {
  76. LIST_ENTRY ListEntry;
  77. ULONG DeviceSig;
  78. PVOID DsmContext;
  79. PDEVICE_OBJECT PortPdo;
  80. PDEVICE_OBJECT TargetObject;
  81. struct _GROUP_ENTRY *Group;
  82. struct _FAILOVER_GROUP *FailGroup;
  83. ULONG State;
  84. BOOLEAN NeedsVerification;
  85. UCHAR Reserved[3];
  86. LONG Requests;
  87. DSM_STATS Stats;
  88. PUCHAR SerialNumber;
  89. STORAGE_DEVICE_DESCRIPTOR Descriptor;
  90. } DEVICE_INFO, *PDEVICE_INFO;
  91. //
  92. // Information about multi-path groups:
  93. // The same device found via multiple paths.
  94. //
  95. typedef struct _GROUP_ENTRY {
  96. LIST_ENTRY ListEntry;
  97. ULONG GroupSig;
  98. ULONG GroupNumber;
  99. BOOLEAN LoadBalanceInit;
  100. UCHAR LoadBalanceType;
  101. UCHAR Reserved[2];
  102. ULONG NumberDevices;
  103. PDEVICE_INFO DeviceList[MAX_PATHS];
  104. } GROUP_ENTRY, *PGROUP_ENTRY;
  105. //
  106. // The collection of devices on one path.
  107. // These fail-over as a unit.
  108. //
  109. typedef struct _FAILOVER_GROUP {
  110. LIST_ENTRY ListEntry;
  111. ULONG FailOverSig;
  112. PVOID PathId;
  113. PDEVICE_OBJECT MPIOPath;
  114. PVOID AlternatePath;
  115. ULONG State;
  116. ULONG Count;
  117. //
  118. // BUGBUG: Revisit using an array
  119. //
  120. PDEVICE_INFO DeviceList[32];
  121. } FAILOVER_GROUP, *PFAILOVER_GROUP;
  122. //
  123. // Completion context structure.
  124. //
  125. typedef struct _COMPLETION_CONTEXT {
  126. LARGE_INTEGER TickCount;
  127. PDEVICE_INFO DeviceInfo;
  128. PDSM_CONTEXT DsmContext;
  129. } COMPLETION_CONTEXT, *PCOMPLETION_CONTEXT;
  130. NTSTATUS
  131. DsmInquire (
  132. IN PVOID DsmContext,
  133. IN PDEVICE_OBJECT TargetDevice,
  134. IN PDEVICE_OBJECT PortObject,
  135. IN PSTORAGE_DEVICE_DESCRIPTOR Descriptor,
  136. IN PSTORAGE_DEVICE_ID_DESCRIPTOR DeviceIdList,
  137. OUT PVOID *DsmIdentifier
  138. );
  139. BOOLEAN
  140. DsmCompareDevices(
  141. IN PVOID DsmContext,
  142. IN PVOID DsmId1,
  143. IN PVOID DsmId2
  144. );
  145. NTSTATUS
  146. DsmSetDeviceInfo(
  147. IN PVOID DsmContext,
  148. IN PDEVICE_OBJECT TargetObject,
  149. IN PVOID DsmId,
  150. IN OUT PVOID *PathId
  151. );
  152. NTSTATUS
  153. DsmGetControllerInfo(
  154. IN PVOID DsmContext,
  155. IN PVOID DsmId,
  156. IN ULONG Flags,
  157. IN OUT PCONTROLLER_INFO *ControllerInfo
  158. );
  159. BOOLEAN
  160. DsmIsPathActive(
  161. IN PVOID DsmContext,
  162. IN PVOID PathId
  163. );
  164. NTSTATUS
  165. DsmPathVerify(
  166. IN PVOID DsmContext,
  167. IN PVOID DsmId,
  168. IN PVOID PathId
  169. );
  170. NTSTATUS
  171. DsmInvalidatePath(
  172. IN PVOID DsmContext,
  173. IN ULONG ErrorMask,
  174. IN PVOID PathId,
  175. IN OUT PVOID *NewPathId
  176. );
  177. NTSTATUS
  178. DsmMoveDevice(
  179. IN PVOID DsmContext,
  180. IN PDSM_IDS DsmIds,
  181. IN PVOID MPIOPath,
  182. IN PVOID SuggestedPath,
  183. IN ULONG Flags
  184. );
  185. NTSTATUS
  186. DsmRemovePending(
  187. IN PVOID DsmContext,
  188. IN PVOID DsmId
  189. );
  190. NTSTATUS
  191. DsmRemoveDevice(
  192. IN PVOID DsmContext,
  193. IN PVOID DsmId,
  194. IN PVOID PathId
  195. );
  196. NTSTATUS
  197. DsmRemovePath(
  198. IN PDSM_CONTEXT DsmContext,
  199. IN PVOID PathId
  200. );
  201. NTSTATUS
  202. DsmBringPathOnLine(
  203. IN PVOID DsmContext,
  204. IN PVOID PathId,
  205. OUT PULONG DSMError
  206. );
  207. PVOID
  208. DsmLBGetPath(
  209. IN PVOID DsmContext,
  210. IN PSCSI_REQUEST_BLOCK Srb,
  211. IN PDSM_IDS DsmList,
  212. IN PVOID CurrentPath,
  213. OUT NTSTATUS *Status
  214. );
  215. ULONG
  216. DsmCategorizeRequest(
  217. IN PVOID DsmContext,
  218. IN PDSM_IDS DsmIds,
  219. IN PIRP Irp,
  220. IN PSCSI_REQUEST_BLOCK Srb,
  221. IN PVOID CurrentPath,
  222. OUT PVOID *PathId,
  223. OUT NTSTATUS *Status
  224. );
  225. NTSTATUS
  226. DsmBroadcastRequest(
  227. IN PVOID DsmContext,
  228. IN PDSM_IDS DsmIds,
  229. IN PIRP Irp,
  230. IN PSCSI_REQUEST_BLOCK Srb,
  231. IN PKEVENT Event
  232. );
  233. NTSTATUS
  234. DsmSrbDeviceControl(
  235. IN PVOID DsmContext,
  236. IN PDSM_IDS DsmIds,
  237. IN PIRP Irp,
  238. IN PSCSI_REQUEST_BLOCK Srb,
  239. IN PKEVENT Event
  240. );
  241. VOID
  242. DsmSetCompletion(
  243. IN PVOID DsmContext,
  244. IN PVOID DsmId,
  245. IN PIRP Irp,
  246. IN PSCSI_REQUEST_BLOCK Srb,
  247. IN OUT PDSM_COMPLETION_INFO DsmCompletion
  248. );
  249. ULONG
  250. DsmInterpretError(
  251. IN PVOID DsmContext,
  252. IN PVOID DsmId,
  253. IN PSCSI_REQUEST_BLOCK Srb,
  254. IN OUT NTSTATUS *Status,
  255. OUT PBOOLEAN Retry
  256. );
  257. NTSTATUS
  258. DsmUnload(
  259. IN PVOID DsmContext
  260. );
  261. //
  262. // Various utility functions.
  263. //
  264. VOID
  265. DsmWmiInitialize(
  266. IN PDSM_WMILIB_CONTEXT WmiInfo
  267. );
  268. PGROUP_ENTRY
  269. DsmFindDevice(
  270. IN PDSM_CONTEXT DsmContext,
  271. IN PDEVICE_INFO DeviceInfo
  272. );
  273. PGROUP_ENTRY
  274. DsmBuildGroupEntry (
  275. IN PDSM_CONTEXT DsmContext,
  276. IN PDEVICE_INFO deviceInfo
  277. );
  278. NTSTATUS
  279. DsmAddGroupEntry(
  280. IN PDSM_CONTEXT DsmContext,
  281. IN PGROUP_ENTRY Group
  282. );
  283. NTSTATUS
  284. DsmAddDeviceEntry(
  285. IN PDSM_CONTEXT DsmContext,
  286. IN PGROUP_ENTRY Group,
  287. IN PDEVICE_INFO DeviceInfo,
  288. IN ULONG DeviceState
  289. );
  290. VOID
  291. DsmRemoveDeviceEntry(
  292. IN PDSM_CONTEXT DsmContext,
  293. IN PGROUP_ENTRY Group,
  294. IN PDEVICE_INFO DeviceInfo
  295. );
  296. PFAILOVER_GROUP
  297. DsmFindFOGroup(
  298. IN PDSM_CONTEXT DsmContext,
  299. IN PVOID PathId
  300. );
  301. PFAILOVER_GROUP
  302. DsmBuildFOGroup(
  303. IN PDSM_CONTEXT DsmContext,
  304. IN PDEVICE_INFO DeviceInfo,
  305. IN PVOID PathId
  306. );
  307. NTSTATUS
  308. DsmUpdateFOGroup(
  309. IN PDSM_CONTEXT DsmContext,
  310. IN PFAILOVER_GROUP FailGroup,
  311. IN PDEVICE_INFO DeviceInfo
  312. );
  313. VOID
  314. DsmRemoveDeviceFailGroup(
  315. IN PDSM_CONTEXT DsmContext,
  316. IN PFAILOVER_GROUP FailGroup,
  317. IN PDEVICE_INFO DeviceInfo
  318. );
  319. PFAILOVER_GROUP
  320. DsmSetNewPath(
  321. IN PDSM_CONTEXT DsmContext,
  322. IN PGROUP_ENTRY Group,
  323. IN PDEVICE_INFO FailingDevice,
  324. IN PFAILOVER_GROUP SelectedPath
  325. );
  326. VOID
  327. DsmLBInit(
  328. IN PDSM_CONTEXT DsmContext,
  329. IN PGROUP_ENTRY Group
  330. );
  331. #define DEBUG_BUFFER_LENGTH 255
  332. UCHAR DebugBuffer[DEBUG_BUFFER_LENGTH + 1];
  333. ULONG GenDSMDebug = 1;
  334. VOID
  335. DsmDebugPrint(
  336. ULONG DebugPrintLevel,
  337. PCCHAR DebugMessage,
  338. ...
  339. );
  340. #ifdef DebugPrint
  341. #undef DebugPrint
  342. #define DebugPrint(x) DsmDebugPrint x
  343. #endif
  344. #endif // _GEN_DSM_H