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.

587 lines
17 KiB

  1. /*++ BUILD Version: 0000 // Increment this if a change has global effects
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. scsiwmi.h
  5. Abstract:
  6. This module contains the internal structure definitions and APIs used by
  7. the SCSI WMILIB helper functions
  8. Author:
  9. AlanWar
  10. Revision History:
  11. --*/
  12. #ifndef _SCSIWMI_
  13. #define _SCSIWMI_
  14. #if defined (_MSC_VER) && (_MSC_VER >= 1020)
  15. #pragma once
  16. #endif
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. //
  21. // This is a per-request context buffer that is needed for every wmi srb.
  22. // The request context must remain valid throughout the entire processing
  23. // of the srb, at least until ScsiPortWmiPostProcess returns with the
  24. // final srb return status and buffer size. If the srb can
  25. // pend then memory for this buffer should be allocated from the SRB
  26. // extension. If not then the memory can be allocated from a stack frame that
  27. // does not go out of scope.
  28. //
  29. typedef struct
  30. {
  31. PVOID UserContext; // Available for miniport use
  32. ULONG BufferSize; // Reserved for SCSIWMI use
  33. PUCHAR Buffer; // Reserved for SCSIWMI use
  34. UCHAR MinorFunction;// Reserved for SCSIWMI use
  35. UCHAR ReturnStatus; // Available to miniport after ScsiPortWmiPostProcess
  36. ULONG ReturnSize; // Available to miniport after ScsiPortWmiPostProcess
  37. } SCSIWMI_REQUEST_CONTEXT, *PSCSIWMI_REQUEST_CONTEXT;
  38. #define ScsiPortWmiGetReturnStatus(RequestContext) ((RequestContext)->ReturnStatus)
  39. #define ScsiPortWmiGetReturnSize(RequestContext) ((RequestContext)->ReturnSize)
  40. //
  41. // This defines a guid to be registered with WMI.
  42. //
  43. typedef struct
  44. {
  45. LPCGUID Guid; // Guid representing data block
  46. ULONG InstanceCount; // Count of Instances of Datablock
  47. ULONG Flags; // Additional flags (see WMIREGINFO in wmistr.h)
  48. } SCSIWMIGUIDREGINFO, *PSCSIWMIGUIDREGINFO;
  49. typedef
  50. UCHAR
  51. (*PSCSIWMI_QUERY_REGINFO) (
  52. IN PVOID DeviceContext,
  53. IN PSCSIWMI_REQUEST_CONTEXT RequestContext,
  54. OUT PWCHAR *MofResourceName
  55. );
  56. /*++
  57. Routine Description:
  58. This routine is a callback into the miniport to retrieve information about
  59. the guids being registered.
  60. This callback is synchronous and may not be pended. Also
  61. ScsiPortWmiPostProcess should not be called from within this callback.
  62. Arguments:
  63. DeviceContext is a caller specified context value originally passed to
  64. ScsiPortWmiDispatchFunction.
  65. RequestContext is a context associated with the srb being processed.
  66. MofResourceName returns with a pointer to a WCHAR string with name of
  67. the MOF resource attached to the miniport binary image file. If
  68. the driver does not have a mof resource attached then this can
  69. be returned as NULL.
  70. Return Value:
  71. TRUE if request is pending else FALSE
  72. --*/
  73. typedef
  74. BOOLEAN
  75. (*PSCSIWMI_QUERY_DATABLOCK) (
  76. IN PVOID Context,
  77. IN PSCSIWMI_REQUEST_CONTEXT DispatchContext,
  78. IN ULONG GuidIndex,
  79. IN ULONG InstanceIndex,
  80. IN ULONG InstanceCount,
  81. IN OUT PULONG InstanceLengthArray,
  82. IN ULONG BufferAvail,
  83. OUT PUCHAR Buffer
  84. );
  85. /*++
  86. Routine Description:
  87. This routine is a callback into the miniport to query for the contents of
  88. one or more instances of a data block. This callback may be called with
  89. an output buffer that is too small to return all of the data queried.
  90. In this case the callback is responsible to report the correct output
  91. buffer size needed.
  92. If the request can be completed immediately without pending,
  93. ScsiPortWmiPostProcess should be called from within this callback and
  94. FALSE returned.
  95. If the request cannot be completed within this callback then TRUE should
  96. be returned. Once the pending operations are finished the miniport should
  97. call ScsiPortWmiPostProcess and then complete the srb.
  98. Arguments:
  99. DeviceContext is a caller specified context value originally passed to
  100. ScsiPortWmiDispatchFunction.
  101. RequestContext is a context associated with the srb being processed.
  102. GuidIndex is the index into the list of guids provided when the
  103. miniport registered
  104. InstanceIndex is the index that denotes first instance of the data block
  105. is being queried.
  106. InstanceCount is the number of instances expected to be returned for
  107. the data block.
  108. InstanceLengthArray is a pointer to an array of ULONG that returns the
  109. lengths of each instance of the data block. This may be NULL when
  110. there is not enough space in the output buffer to fufill the request.
  111. In this case the miniport should call ScsiPortWmiPostProcess with
  112. a status of SRB_STATUS_DATA_OVERRUN and the size of the output buffer
  113. needed to fufill the request.
  114. BufferAvail on entry has the maximum size available to write the data
  115. blocks in the output buffer. If the output buffer is not large enough
  116. to return all of the data blocks then the miniport should call
  117. ScsiPortWmiPostProcess with a status of SRB_STATUS_DATA_OVERRUN
  118. and the size of the output buffer needed to fufill the request.
  119. Buffer on return is filled with the returned data blocks. Note that each
  120. instance of the data block must be aligned on a 8 byte boundry. This
  121. may be NULL when there is not enough space in the output buffer to
  122. fufill the request. In this case the miniport should call
  123. ScsiPortWmiPostProcess with a status of SRB_STATUS_DATA_OVERRUN and
  124. the size of the output buffer needed to fufill the request.
  125. Return Value:
  126. TRUE if request is pending else FALSE
  127. --*/
  128. typedef
  129. BOOLEAN
  130. (*PSCSIWMI_SET_DATABLOCK) (
  131. IN PVOID DeviceContext,
  132. IN PSCSIWMI_REQUEST_CONTEXT RequestContext,
  133. IN ULONG GuidIndex,
  134. IN ULONG InstanceIndex,
  135. IN ULONG BufferSize,
  136. IN PUCHAR Buffer
  137. );
  138. /*++
  139. Routine Description:
  140. This routine is a callback into the miniport to set the contents of an
  141. entire instance of a data block.
  142. If the request can be completed immediately without pending,
  143. ScsiPortWmiPostProcess should be called from within this callback and
  144. FALSE returned.
  145. If the request cannot be completed within this callback then TRUE should
  146. be returned. Once the pending operations are finished the miniport should
  147. call ScsiPortWmiPostProcess and then complete the srb.
  148. Arguments:
  149. DeviceContext is a caller specified context value originally passed to
  150. ScsiPortWmiDispatchFunction.
  151. RequestContext is a context associated with the srb being processed.
  152. GuidIndex is the index into the list of guids provided when the
  153. miniport registered
  154. InstanceIndex is the index that denotes which instance of the data block
  155. is being set.
  156. BufferSize has the size of the data block passed
  157. Buffer has the new values for the data block
  158. Return Value:
  159. TRUE if request is pending else FALSE
  160. --*/
  161. typedef
  162. BOOLEAN
  163. (*PSCSIWMI_SET_DATAITEM) (
  164. IN PVOID DeviceContext,
  165. IN PSCSIWMI_REQUEST_CONTEXT RequestContext,
  166. IN ULONG GuidIndex,
  167. IN ULONG InstanceIndex,
  168. IN ULONG DataItemId,
  169. IN ULONG BufferSize,
  170. IN PUCHAR Buffer
  171. );
  172. /*++
  173. Routine Description:
  174. This routine is a callback into the miniport to set a single data item
  175. in a single instance of a data block.
  176. If the request can be completed immediately without pending,
  177. ScsiPortWmiPostProcess should be called from within this callback and
  178. FALSE returned.
  179. If the request cannot be completed within this callback then TRUE should
  180. be returned. Once the pending operations are finished the miniport should
  181. call ScsiPortWmiPostProcess and then complete the srb.
  182. Arguments:
  183. DeviceContext is a caller specified context value originally passed to
  184. ScsiPortWmiDispatchFunction.
  185. RequestContext is a context associated with the srb being processed.
  186. GuidIndex is the index into the list of guids provided when the
  187. miniport registered
  188. InstanceIndex is the index that denotes which instance of the data block
  189. is being set.
  190. DataItemId has the id of the data item being set
  191. BufferSize has the size of the data item passed
  192. Buffer has the new values for the data item
  193. Return Value:
  194. TRUE if request is pending else FALSE
  195. --*/
  196. typedef
  197. BOOLEAN
  198. (*PSCSIWMI_EXECUTE_METHOD) (
  199. IN PVOID DeviceContext,
  200. IN PSCSIWMI_REQUEST_CONTEXT RequestContext,
  201. IN ULONG GuidIndex,
  202. IN ULONG InstanceIndex,
  203. IN ULONG MethodId,
  204. IN ULONG InBufferSize,
  205. IN ULONG OutBufferSize,
  206. IN OUT PUCHAR Buffer
  207. );
  208. /*++
  209. Routine Description:
  210. This routine is a callback into the miniport to execute a method.
  211. If the request can be completed immediately without pending,
  212. ScsiPortWmiPostProcess should be called from within this callback and
  213. FALSE returned.
  214. If the request cannot be completed within this callback then TRUE should
  215. be returned. Once the pending operations are finished the miniport should
  216. call ScsiPortWmiPostProcess and then complete the srb.
  217. Arguments:
  218. Context is a caller specified context value originally passed to
  219. ScsiPortWmiDispatchFunction.
  220. RequestContext is a context associated with the srb being processed.
  221. GuidIndex is the index into the list of guids provided when the
  222. miniport registered
  223. InstanceIndex is the index that denotes which instance of the data block
  224. is being called.
  225. MethodId has the id of the method being called
  226. InBufferSize has the size of the data block passed in as the input to
  227. the method.
  228. OutBufferSize on entry has the maximum size available to write the
  229. returned data block. If the output buffer is not large enough
  230. to return all of the data blocks then the miniport should call
  231. ScsiPortWmiPostProcess with a status of SRB_STATUS_DATA_OVERRUN
  232. and the size of the output buffer needed to fufill the request.
  233. It is important to check that there is sufficient room in the
  234. output buffer before performing any operations that may have
  235. side effects.
  236. Buffer on entry has the input data block and on return has the output
  237. output data block.
  238. Return Value:
  239. TRUE if request is pending else FALSE
  240. --*/
  241. typedef enum
  242. {
  243. ScsiWmiEventControl, // Enable or disable an event
  244. ScsiWmiDataBlockControl // Enable or disable data block collection
  245. } SCSIWMI_ENABLE_DISABLE_CONTROL;
  246. typedef
  247. BOOLEAN
  248. (*PSCSIWMI_FUNCTION_CONTROL) (
  249. IN PVOID DeviceContext,
  250. IN PSCSIWMI_REQUEST_CONTEXT RequestContext,
  251. IN ULONG GuidIndex,
  252. IN SCSIWMI_ENABLE_DISABLE_CONTROL Function,
  253. IN BOOLEAN Enable
  254. );
  255. /*++
  256. Routine Description:
  257. This routine is a callback into the miniport to enabled or disable event
  258. generation or data block collection. Since WMI manages reference counting
  259. for each of the data blocks or events, a miniport should only expect a
  260. single enable followed by a single disable. Data blocks will only
  261. receive collection enable/disable if they were registered as requiring
  262. it, that is include the WMIREG_FLAG_EXPENSIVE flag.
  263. If the request can be completed immediately without pending,
  264. ScsiPortWmiPostProcess should be called from within this callback and
  265. FALSE returned.
  266. If the request cannot be completed within this callback then TRUE should
  267. be returned. Once the pending operations are finished the miniport should
  268. call ScsiPortWmiPostProcess and then complete the srb.
  269. Arguments:
  270. DeviceContext is a caller specified context value originally passed to
  271. ScsiPortWmiDispatchFunction.
  272. RequestContext is a context associated with the srb being processed.
  273. Function specifies which functionality is being enabled or disabled
  274. Enable is TRUE then the function is being enabled else disabled
  275. Return Value:
  276. TRUE if request is pending else FALSE
  277. --*/
  278. //
  279. // This structure supplies context information for SCSIWMILIB to process the
  280. // WMI srbs.
  281. //
  282. typedef struct _SCSIWMILIB_CONTEXT
  283. {
  284. //
  285. // WMI data block guid registration info
  286. ULONG GuidCount;
  287. PSCSIWMIGUIDREGINFO GuidList;
  288. //
  289. // WMI functionality callbacks
  290. PSCSIWMI_QUERY_REGINFO QueryWmiRegInfo;
  291. PSCSIWMI_QUERY_DATABLOCK QueryWmiDataBlock;
  292. PSCSIWMI_SET_DATABLOCK SetWmiDataBlock;
  293. PSCSIWMI_SET_DATAITEM SetWmiDataItem;
  294. PSCSIWMI_EXECUTE_METHOD ExecuteWmiMethod;
  295. PSCSIWMI_FUNCTION_CONTROL WmiFunctionControl;
  296. } SCSI_WMILIB_CONTEXT, *PSCSI_WMILIB_CONTEXT;
  297. VOID
  298. ScsiPortWmiPostProcess(
  299. IN PSCSIWMI_REQUEST_CONTEXT RequestContext,
  300. IN UCHAR SrbStatus,
  301. IN ULONG BufferUsed
  302. );
  303. /*++
  304. Routine Description:
  305. This routine will do the work of post-processing a WMI srb.
  306. Arguments:
  307. RequestContext is a context associated with the srb being processed. After
  308. this api returns the ReturnStatus and ReturnSize fields are updated.
  309. SrbStatus has the return status code for the srb. If a query or method
  310. callback was passed an output buffer that was not large enough
  311. then SrbStatus should be SRB_STATUS_DATA_OVERRUN and BufferUsed
  312. should be the number of bytes needed in the output buffer.
  313. BufferUsed has the number of bytes required by the miniport to return the
  314. data requested in the WMI srb. If SRB_STATUS_DATA_OVERRUN was passed
  315. in SrbStatus then BufferUsed has the number of needed in the output
  316. buffer. If SRB_STATUS_SUCCESS is passed in SrbStatus then BufferUsed
  317. has the actual number of bytes used in the output buffer.
  318. Return Value:
  319. --*/
  320. BOOLEAN
  321. ScsiPortWmiDispatchFunction(
  322. IN PSCSI_WMILIB_CONTEXT WmiLibInfo,
  323. IN UCHAR MinorFunction,
  324. IN PVOID DeviceContext,
  325. IN PSCSIWMI_REQUEST_CONTEXT RequestContext,
  326. IN PVOID DataPath,
  327. IN ULONG BufferSize,
  328. IN PVOID Buffer
  329. );
  330. /*++
  331. Routine Description:
  332. Dispatch helper routine for WMI srb requests. Based on the Minor
  333. function passed the WMI request is processed and this routine
  334. invokes the appropriate callback in the WMILIB structure.
  335. Arguments:
  336. WmiLibInfo has the SCSI WMILIB information control block associated
  337. with the adapter or logical unit
  338. DeviceContext is miniport defined context value passed on to the callbacks
  339. invoked by this api.
  340. RequestContext is a pointer to a context structure that maintains
  341. information about this WMI srb. This request context must remain
  342. valid throughout the entire processing of the srb, at least until
  343. ScsiPortWmiPostProcess returns with the final srb return status and
  344. buffer size. If the srb can pend then memory for this buffer should
  345. be allocated from the SRB extension. If not then the memory can be
  346. allocated from a stack frame that does not go out of scope, perhaps
  347. that of the caller to this api.
  348. DataPath is value passed in wmi request
  349. BufferSize is value passed in wmi request
  350. Buffer is value passed in wmi request
  351. Return Value:
  352. TRUE if request is pending else FALSE
  353. --*/
  354. #define ScsiPortWmiFireAdapterEvent( \
  355. HwDeviceExtension, \
  356. Guid, \
  357. InstanceIndex, \
  358. EventDataSize, \
  359. EventData \
  360. ) \
  361. ScsiPortWmiFireLogicalUnitEvent(\
  362. HwDeviceExtension, \
  363. 0xff, \
  364. 0, \
  365. 0, \
  366. Guid, \
  367. InstanceIndex, \
  368. EventDataSize, \
  369. EventData)
  370. /*++
  371. Routine Description:
  372. This routine will fire a WMI event associated with an adapter using
  373. the data buffer passed. This routine may be called at or below DPC level.
  374. Arguments:
  375. HwDeviceExtension is the adapter device extension
  376. Guid is pointer to the GUID that represents the event
  377. InstanceIndex is the index of the instance of the event
  378. EventDataSize is the number of bytes of data that is being fired with
  379. with the event. This size specifies the size of the event data only
  380. and does NOT include the 0x40 bytes of preceeding padding.
  381. EventData is the data that is fired with the events. There must be exactly
  382. 0x40 bytes of padding preceeding the event data.
  383. Return Value:
  384. --*/
  385. VOID
  386. ScsiPortWmiFireLogicalUnitEvent(
  387. IN PVOID HwDeviceExtension,
  388. IN UCHAR PathId,
  389. IN UCHAR TargetId,
  390. IN UCHAR Lun,
  391. IN LPGUID Guid,
  392. IN ULONG InstanceIndex,
  393. IN ULONG EventDataSize,
  394. IN PVOID EventData
  395. );
  396. /*++
  397. Routine Description:
  398. This routine will fire a WMI event using the data buffer passed. This
  399. routine may be called at or below DPC level
  400. Arguments:
  401. HwDeviceExtension is the adapter device extension
  402. PathId identifies the SCSI bus if a logical unit is firing the event
  403. or is 0xff if the adapter is firing the event.
  404. TargetId identifies the target controller or device on the bus
  405. Lun identifies the logical unit number of the target device
  406. Guid is pointer to the GUID that represents the event
  407. InstanceIndex is the index of the instance of the event
  408. EventDataSize is the number of bytes of data that is being fired with
  409. with the event. This size specifies the size of the event data only
  410. and does NOT include the 0x40 bytes of preceeding padding.
  411. EventData is the data that is fired with the events. There must be exactly
  412. 0x40 bytes of padding preceeding the event data.
  413. Return Value:
  414. --*/
  415. #ifdef __cplusplus
  416. }
  417. #endif
  418. #endif