Advertisement
MagicAndre1981

new firmware/power API for storage devices

Apr 3rd, 2015
2,628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define IOCTL_STORAGE_SET_TEMPERATURE_THRESHOLD     CTL_CODE(IOCTL_STORAGE_BASE, 0x0480, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  2.  
  3. #define IOCTL_STORAGE_PROTOCOL_COMMAND              CTL_CODE(IOCTL_STORAGE_BASE, 0x04F0, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  4.  
  5.  
  6. //
  7. // IOCTLs for firmware upgrade on storage devices
  8. //
  9.  
  10. #define IOCTL_STORAGE_FIRMWARE_GET_INFO         CTL_CODE(IOCTL_STORAGE_BASE, 0x0700, METHOD_BUFFERED, FILE_ANY_ACCESS)
  11. #define IOCTL_STORAGE_FIRMWARE_DOWNLOAD         CTL_CODE(IOCTL_STORAGE_BASE, 0x0701, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  12. #define IOCTL_STORAGE_FIRMWARE_ACTIVATE         CTL_CODE(IOCTL_STORAGE_BASE, 0x0702, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  13.  
  14.  
  15. //
  16. // IOCTL to specify a power cap for a storage device.
  17. //
  18. #define IOCTL_STORAGE_DEVICE_POWER_CAP CTL_CODE(IOCTL_STORAGE_BASE, 0x0725, METHOD_BUFFERED, FILE_ANY_ACCESS)
  19.  
  20. //
  21. // Output buffer for StorageDeviceFaultDomainProperty & PropertyStandardQuery
  22. //
  23.  
  24. typedef _Struct_size_bytes_(Size) struct _STORAGE_DEVICE_FAULT_DOMAIN_DESCRIPTOR {
  25.  
  26.     //
  27.     // Size of this structure serves
  28.     // as the version
  29.     //
  30.  
  31.     ULONG Version;
  32.  
  33.     //
  34.     // Size of  this structure  plus
  35.     // all the variable sized fields
  36.     //
  37.  
  38.     ULONG Size;
  39.  
  40.     //
  41.     // Number of fault domains
  42.     //
  43.  
  44.     ULONG NumberOfFaultDomains;
  45.  
  46.     //
  47.     // Fault domain ids
  48.     //
  49.  
  50.     _Field_size_(NumberOfFaultDomains) GUID FaultDomainIds[ANYSIZE_ARRAY];
  51.  
  52. } STORAGE_DEVICE_FAULT_DOMAIN_DESCRIPTOR, *PSTORAGE_DEVICE_FAULT_DOMAIN_DESCRIPTOR;
  53.  
  54. //
  55. // Parameters for StorageAdapterProtocolSpecificProperty (or StorageDeviceProtocolSpecificProperty) & PropertyStandardQuery
  56. //
  57.  
  58. //
  59. // Define the different storage command protocols that used between software and hardware.
  60. // e.g. command protocol software uses to communicate with hardware.
  61. // Protocol types below 128 (0x80) are reserved for Microsoft use.
  62. //
  63. typedef enum _STORAGE_PROTOCOL_TYPE {
  64.     ProtocolTypeUnknown = 0x00,
  65.     ProtocolTypeScsi,
  66.     ProtocolTypeAta,
  67.     ProtocolTypeNvme,
  68.     ProtocolTypeSd,
  69.     ProtocolTypeProprietary = 0x7E,
  70.     ProtocolTypeMaxReserved = 0x7F
  71. } STORAGE_PROTOCOL_TYPE, *PSTORAGE_PROTOCOL_TYPE;
  72.  
  73.  
  74. typedef enum _STORAGE_PROTOCOL_NVME_DATA_TYPE {
  75.     NVMeDataTypeUnknown = 0,
  76.     NVMeDataTypeIdentify,       // Retrieved by command - IDENTIFY CONTROLLER or IDENTIFY NAMESPACE
  77.     NVMeDataTypeLogPage,        // Retrieved by command - GET LOG PAGE
  78.     NVMeDataTypeFeature,        // Retrieved by command - GET FEATURES
  79. } STORAGE_PROTOCOL_NVME_DATA_TYPE, *PSTORAGE_PROTOCOL_NVME_DATA_TYPE;
  80.  
  81. typedef enum _STORAGE_PROTOCOL_ATA_DATA_TYPE {
  82.     AtaDataTypeUnknown = 0,
  83.     AtaDataTypeIdentify,        // Retrieved by command - IDENTIFY DEVICE
  84.     AtaDataTypeLogPage,         // Retrieved by command - READ LOG EXT
  85. } STORAGE_PROTOCOL_ATA_DATA_TYPE, *PSTORAGE_PROTOCOL_ATA_DATA_TYPE;
  86.  
  87. //
  88. // Protocol Data should follow this data structure in the same buffer.
  89. // The offset of Protocol Data from the beginning of this data structure
  90. // is reported in data field - "ProtocolDataOffset".
  91. //
  92. typedef struct _STORAGE_PROTOCOL_SPECIFIC_DATA {
  93.  
  94.     STORAGE_PROTOCOL_TYPE ProtocolType;
  95.     ULONG   DataType;                   // The value will be protocol specific, as defined in STORAGE_PROTOCOL_NVME_DATA_TYPE or STORAGE_PROTOCOL_ATA_DATA_TYPE.
  96.  
  97.     ULONG   ProtocolDataRequestValue;
  98.     ULONG   ProtocolDataRequestSubValue;
  99.  
  100.     ULONG   ProtocolDataOffset;         // The offset of data buffer is from beginning of this data structure.
  101.     ULONG   ProtocolDataLength;
  102.  
  103.     ULONG   FixedProtocolReturnData;    // This is returned data, especially from NVMe feature data that doesn't need separate device data transfer.
  104.     ULONG   Reserved[3];
  105.  
  106. } STORAGE_PROTOCOL_SPECIFIC_DATA, *PSTORAGE_PROTOCOL_SPECIFIC_DATA;
  107.  
  108. //
  109. // Input parameters for StorageAdapterProtocolSpecificProperty (or StorageDeviceProtocolSpecificProperty) & PropertyStandardQuery
  110. // will be data structure STORAGE_PROPERTY_QUERY, where the data field "AdditionalParameters" is a buffer
  111. // in format of STORAGE_PROTOCOL_SPECIFIC_DATA.
  112. //
  113.  
  114. //
  115. // Out parameters for StorageAdapterProtocolSpecificProperty (or StorageDeviceProtocolSpecificProperty) & PropertyStandardQuery
  116. //
  117. typedef struct _STORAGE_PROTOCOL_DATA_DESCRIPTOR {
  118.  
  119.     ULONG   Version;
  120.     ULONG   Size;
  121.  
  122.     STORAGE_PROTOCOL_SPECIFIC_DATA ProtocolSpecificData;
  123.  
  124. } STORAGE_PROTOCOL_DATA_DESCRIPTOR, *PSTORAGE_PROTOCOL_DATA_DESCRIPTOR;
  125.  
  126. //
  127. // Parameters for StorageAdapterTemperatureProperty (or StorageDeviceTemperatureProperty) & PropertyStandardQuery
  128. //
  129.  
  130.  
  131. //
  132. // Input parameters for StorageAdapterTemperatureProperty (or StorageDeviceTemperatureProperty) & PropertyStandardQuery
  133. // uses data structure STORAGE_PROPERTY_QUERY.
  134. //
  135.  
  136. //
  137. // Out parameters for StorageAdapterTemperatureProperty (or StorageDeviceTemperatureProperty) & PropertyStandardQuery
  138. // For temperature/threshold data fields, the smallest value of SHORT type - 0x8000 indicates the value is not reported.
  139. //
  140. #define STORAGE_TEMPERATURE_VALUE_NOT_REPORTED           0x8000
  141.  
  142. typedef struct _STORAGE_TEMPERATURE_INFO {
  143.  
  144.     USHORT  Index;                      // Starts from 0. Index 0 may indicate a composite value.
  145.     SHORT   Temperature;                // Signed value; in Celsius.
  146.     SHORT   OverThreshold;              // Signed value; in Celsius.
  147.     SHORT   UnderThreshold;             // Signed value; in Celsius.
  148.  
  149.     BOOLEAN OverThresholdChangable;     // Can the threshold value being changed by using IOCTL_STORAGE_SET_TEMPERATURE_THRESHOLD.
  150.     BOOLEAN UnderThresholdChangable;    // Can the threshold value being changed by using IOCTL_STORAGE_SET_TEMPERATURE_THRESHOLD.
  151.     BOOLEAN EventGenerated;             // Indicates that notification will be generated when temperature cross threshold.
  152.     UCHAR   Reserved0;
  153.     ULONG   Reserved1;
  154.  
  155. } STORAGE_TEMPERATURE_INFO, *PSTORAGE_TEMPERATURE_INFO;
  156.  
  157. typedef struct _STORAGE_TEMPERATURE_DATA_DESCRIPTOR {
  158.  
  159.     ULONG   Version;
  160.     ULONG   Size;
  161.  
  162.     //
  163.     // Indicates the maximum temperature in degrees Celsius that may prevent continued normal operation,
  164.     // possibility of data loss, automatic device shutdown, extreme performance throttling, or permanent damage.
  165.     //
  166.     SHORT   CriticalTemperature;    // Signed value; in Celsius.
  167.  
  168.     //
  169.     // Indicates the maximum temperature in degrees Celsius at which the device is capable of
  170.     // operating continuously without degrading operation or reliability.
  171.     //
  172.     SHORT   WarningTemperature;     // Signed value; in Celsius.
  173.  
  174.     USHORT  InfoCount;              // Some devices may report more than one temperature information as there can be multiple sensors implemented.
  175.  
  176.     UCHAR   Reserved0[2];
  177.  
  178.     ULONG   Reserved1[2];
  179.  
  180.     STORAGE_TEMPERATURE_INFO TemperatureInfo[ANYSIZE_ARRAY];
  181.  
  182. } STORAGE_TEMPERATURE_DATA_DESCRIPTOR, *PSTORAGE_TEMPERATURE_DATA_DESCRIPTOR;
  183.  
  184.  
  185. //
  186. // Input parameters for IOCTL_STORAGE_SET_TEMPERATURE_THRESHOLD
  187. //
  188.  
  189. //
  190. // Indicate the target of the request other than the device handle/object itself.
  191. // This is used in "Flags" field of data structures.
  192. //
  193. #define STORAGE_TEMPERATURE_THRESHOLD_FLAG_ADAPTER_REQUEST       0x0001
  194.  
  195. typedef struct _STORAGE_TEMPERATURE_THRESHOLD {
  196.  
  197.     ULONG   Version;
  198.     ULONG   Size;
  199.  
  200.     USHORT  Flags;
  201.     USHORT  Index;
  202.  
  203.     SHORT   Threshold;          // Signed value; in Celsius.
  204.     BOOLEAN OverThreshold;      // If TRUE, set the OverThreshold value; Otherwise, set the UnderThreshold value.
  205.     UCHAR   Reserved;
  206.  
  207. } STORAGE_TEMPERATURE_THRESHOLD, *PSTORAGE_TEMPERATURE_THRESHOLD;
  208.  
  209. //
  210. // Parameters for StorageAdapterPhysicalTopologyProperty (or StorageDevicePhysicalTopologyProperty) & PropertyStandardQuery
  211. //
  212.  
  213.  
  214. //
  215. // Input parameters for StorageAdapterPhysicalTopologyProperty (or StorageDevicePhysicalTopologyProperty) & PropertyStandardQuery
  216. // uses data structure STORAGE_PROPERTY_QUERY.
  217. //
  218.  
  219. //
  220. // Out parameters for StorageAdapterPhysicalTopologyProperty (or StorageDevicePhysicalTopologyProperty) & PropertyStandardQuery
  221. // uses data structure STORAGE_PHYSICAL_TOPOLOGY_DESCRIPTOR
  222. //
  223.  
  224. //
  225. // Multiple roles are allowed for a single device.
  226. //
  227. #define STORAGE_COMPONENT_ROLE_CACHE        0x00000001
  228. #define STORAGE_COMPONENT_ROLE_TIERING      0x00000002
  229. #define STORAGE_COMPONENT_ROLE_DATA         0x00000004
  230.  
  231.  
  232. typedef enum _STORAGE_DEVICE_FORM_FACTOR {
  233.     FormFactorUnknown = 0,
  234.  
  235.     FormFactor3_5,          // 3.5 inch nominal form factor
  236.     FormFactor2_5,          // 2.5 inch nominal form factor
  237.     FormFactor1_8,          // 1.8 inch nominal form factor
  238.     FormFactor1_8Less,      // Less than 1.8 inch nominal form factor
  239.  
  240.     FormFactorEmbedded,     // Embedded on board.
  241.     FormFactorMemoryCard,   // Memory card such as SD, CF.
  242.     FormFactormSata,        // mSATA
  243.     FormFactorM_2,          // M.2
  244.     FormFactorPCIeBoard,    // PCIe card plug into slot.
  245.     FormFactorDimm,         // DIMM Slot
  246.  
  247. } STORAGE_DEVICE_FORM_FACTOR, *PSTORAGE_DEVICE_FORM_FACTOR;
  248.  
  249.  
  250. typedef enum _STORAGE_COMPONENT_HEALTH_STATUS {
  251.     HealthStatusUnknown = 0,
  252.     HealthStatusNormal,
  253.     HealthStatusThrottled,
  254.     HealthStatusWarning,
  255.     HealthStatusDisabled,
  256.     HealthStatusFailed,
  257. } STORAGE_COMPONENT_HEALTH_STATUS, *PSTORAGE_COMPONENT_HEALTH_STATUS;
  258.  
  259. #pragma warning(push)
  260. #pragma warning(disable:4201) // nameless struct/unions
  261.  
  262. typedef union _STORAGE_SPEC_VERSION {
  263.  
  264.     struct {
  265.         union {
  266.             struct {
  267.                 UCHAR   SubMinor;
  268.                 UCHAR   Minor;
  269.             } DUMMYSTRUCTNAME;
  270.  
  271.             USHORT  AsUshort;
  272.  
  273.         } MinorVersion;
  274.  
  275.         USHORT  MajorVersion;
  276.     } DUMMYSTRUCTNAME;
  277.  
  278.     ULONG   AsUlong;
  279.  
  280. } STORAGE_SPEC_VERSION, *PSTORAGE_SPEC_VERSION;
  281.  
  282. #pragma warning(pop)
  283.  
  284.  
  285. typedef struct _STORAGE_PHYSICAL_DEVICE_DATA {
  286.  
  287.     ULONG       DeviceId;
  288.     ULONG       Role;                                   // Value(s) of bitmask from STORAGE_COMPONENT_ROLE_xxx
  289.  
  290.     STORAGE_COMPONENT_HEALTH_STATUS HealthStatus;
  291.     STORAGE_PROTOCOL_TYPE           CommandProtocol;
  292.     STORAGE_SPEC_VERSION            SpecVersion;        // Supported storage spec version. For example: SBC 3, SATA 3.2, NVMe 1.2
  293.     STORAGE_DEVICE_FORM_FACTOR      FormFactor;
  294.  
  295.     UCHAR       Vendor[8];
  296.     UCHAR       Model[40];
  297.     UCHAR       FirmwareRevision[16];
  298.  
  299.     ULONGLONG   Capacity;                               // in unit of Kilo-Bytes (1024 bytes).
  300.  
  301.     UCHAR       PhysicalLocation[32];                   // Reserved for future.
  302.  
  303.     ULONG       Reserved[2];
  304.  
  305. } STORAGE_PHYSICAL_DEVICE_DATA, *PSTORAGE_PHYSICAL_DEVICE_DATA;
  306.  
  307.  
  308. typedef struct _STORAGE_PHYSICAL_ADAPTER_DATA {
  309.  
  310.     ULONG       AdapterId;
  311.     STORAGE_COMPONENT_HEALTH_STATUS HealthStatus;
  312.     STORAGE_PROTOCOL_TYPE           CommandProtocol;
  313.     STORAGE_SPEC_VERSION            SpecVersion;        // Supported storage spec version. For example: AHCI 1.3.1
  314.  
  315.     UCHAR       Vendor[8];
  316.     UCHAR       Model[40];
  317.     UCHAR       FirmwareRevision[16];
  318.  
  319.     UCHAR       PhysicalLocation[32];   // Reserve for future.
  320.  
  321.     BOOLEAN     ExpanderConnected;
  322.     UCHAR       Reserved0[3];
  323.     ULONG       Reserved1[3];
  324.  
  325. } STORAGE_PHYSICAL_ADAPTER_DATA, *PSTORAGE_PHYSICAL_ADAPTER_DATA;
  326.  
  327.  
  328. typedef struct _STORAGE_PHYSICAL_NODE_DATA {
  329.  
  330.     ULONG       NodeId;
  331.  
  332.     ULONG       AdapterCount;           // 0 or 1
  333.     ULONG       AdapterDataLength;
  334.     ULONG       AdapterDataOffset;      // Offset from beginning of this data structure. The buffer contains an array of STORAGE_PHYSICAL_ADAPTER_DATA.
  335.  
  336.     ULONG       DeviceCount;            // >= 1
  337.     ULONG       DeviceDataLength;
  338.     ULONG       DeviceDataOffset;       // Offset from beginning of this data structure. The buffer contains an array of STORAGE_PHYSICAL_DEVICE_DATA.
  339.  
  340.     ULONG       Reserved[3];
  341.  
  342. } STORAGE_PHYSICAL_NODE_DATA, *PSTORAGE_PHYSICAL_NODE_DATA;
  343.  
  344.  
  345. typedef struct _STORAGE_PHYSICAL_TOPOLOGY_DESCRIPTOR {
  346.  
  347.     ULONG       Version;            // sizeof(STORAGE_PHYSICAL_TOPOLOGY_DESCRIPTOR)
  348.     ULONG       Size;               // Total size of the data. Should be >= sizeof(STORAGE_PHYSICAL_TOPOLOGY_DESCRIPTOR)
  349.  
  350.     ULONG       NodeCount;
  351.     ULONG       Reserved;
  352.  
  353.     STORAGE_PHYSICAL_NODE_DATA Node[ANYSIZE_ARRAY];
  354.  
  355. } STORAGE_PHYSICAL_TOPOLOGY_DESCRIPTOR, *PSTORAGE_PHYSICAL_TOPOLOGY_DESCRIPTOR;
  356.  
  357.  
  358. //
  359. // Output buffer for StorageDeviceIoCapabilityProperty & PropertyStandardQuery
  360. //
  361.  
  362. typedef _Struct_size_bytes_(Size) struct _STORAGE_DEVICE_IO_CAPABILITY_DESCRIPTOR {
  363.  
  364.     //
  365.     // Size of this structure serves
  366.     // as the version
  367.     //
  368.  
  369.     ULONG Version;
  370.  
  371.     //
  372.     // Size of this structure
  373.     //
  374.  
  375.     ULONG Size;
  376.  
  377.     //
  378.     // LUN max outstanding IO count
  379.     //
  380.  
  381.     ULONG LunMaxIoCount;
  382.  
  383.     //
  384.     // Adapter max outstanding IO count
  385.     //
  386.  
  387.     ULONG AdapterMaxIoCount;
  388.  
  389. } STORAGE_DEVICE_IO_CAPABILITY_DESCRIPTOR, *PSTORAGE_DEVICE_IO_CAPABILITY_DESCRIPTOR;
  390.  
  391.  
  392. //
  393. // IOCTL_STORAGE_DEVICE_POWER_CAP
  394. //
  395. // This IOCTL specifies a maximum *operational* power consumption level for a
  396. // storage device.
  397. // The storage stack will do its best to transition the device to a power state
  398. // that will not exceed the given maximum.  However, this depends on what the
  399. // device supports.  The actual maximum may be less than or greater than the
  400. // desired maximum.
  401. //
  402. // Input buffer:
  403. //  A STORAGE_DEVICE_POWER_CAP structure.
  404. //  * The Units field specifies the units of the MaxPower field.  It can be
  405. //    either a percentage (0-100%) or an absolute value in milliwatts.
  406. //  * The MaxPower field is used to set the desired maximum power consumption
  407. //    value for the storage device.
  408. //
  409. // Output buffer:
  410. //  On success, the output buffer will contain a STORAGE_DEVICE_POWER_CAP
  411. //  structure.
  412. //  * The Units field will continue to specify the units of the MaxPower field
  413. //    and will match the value from the input buffer.
  414. //  * The MaxPower field will contain the value of the actual maximum
  415. //    power consumption level of the device.  This may be equal to, less than,
  416. //    or greater than the desired cap, depending on what the device supports.
  417. //
  418. typedef enum _STORAGE_DEVICE_POWER_CAP_UNITS {
  419.     StorageDevicePowerCapUnitsPercent,
  420.     StorageDevicePowerCapUnitsMilliwatts
  421. } STORAGE_DEVICE_POWER_CAP_UNITS, *PSTORAGE_DEVICE_POWER_CAP_UNITS;
  422.  
  423. typedef struct _STORAGE_DEVICE_POWER_CAP {
  424.     ULONG Version;
  425.     ULONG Size;
  426.     STORAGE_DEVICE_POWER_CAP_UNITS Units;
  427.     ULONGLONG MaxPower;
  428. } STORAGE_DEVICE_POWER_CAP, *PSTORAGE_DEVICE_POWER_CAP;
  429.  
  430. #define STORAGE_DEVICE_POWER_CAP_VERSION_V1 1
  431.  
  432.  
  433. //
  434. // Parameter and data structure for firmware upgrade IOCTLs
  435. // IOCTL_STORAGE_FIRMWARE_GET_INFO, IOCTL_STORAGE_FIRMWARE_DOWNLOAD, IOCTL_STORAGE_FIRMWARE_ACTIVATE
  436. //
  437.  
  438. //
  439. // Indicate the target of the request other than the device handle/object itself.
  440. // This is used in "Flags" field of data structures for firmware upgrade request.
  441. //
  442. #define STORAGE_HW_FIRMWARE_REQUEST_FLAG_CONTROLLER                     0x00000001
  443.  
  444. //
  445. // Indicate that the existing firmware in slot should be activated.
  446. // Only valid for IOCTL_STORAGE_FIRMWARE_ACTIVATE.
  447. //
  448. #define STORAGE_HW_FIRMWARE_REQUEST_FLAG_SWITCH_TO_EXISTING_FIRMWARE    0x80000000
  449.  
  450. //
  451. // Input parameter for IOCTL_STORAGE_FIRMWARE_GET_INFO
  452. //
  453. typedef struct _STORAGE_HW_FIRMWARE_INFO_QUERY {
  454.     ULONG   Version;            // sizeof(STORAGE_FIRMWARE_INFO_QUERY)
  455.     ULONG   Size;               // Whole size of the buffer (in case this data structure being extended to be variable length)
  456.     ULONG   Flags;
  457.     ULONG   Reserved;
  458. } STORAGE_HW_FIRMWARE_INFO_QUERY, *PSTORAGE_HW_FIRMWARE_INFO_QUERY;
  459.  
  460. //
  461. // Output parameter for IOCTL_STORAGE_FIRMWARE_GET_INFO
  462. // The total size of returned data is for Firmware Info is:
  463. //   sizeof(STORAGE_HW_FIRMWARE_INFO) + sizeof(STORAGE_HW_FIRMWARE_SLOT_INFO) * (SlotCount - 1).
  464. // If the buffer is not big enough, callee should set the required length in "Size" field of STORAGE_HW_FIRMWARE_INFO,
  465. //
  466.  
  467. //
  468. // Following value maybe used in "PendingActiveSlot" field indicating there is no firmware pending to activate.
  469. //
  470. #define STORAGE_HW_FIRMWARE_INVALID_SLOT              0xFF
  471.  
  472. #pragma warning(push)
  473. #pragma warning(disable:4214) // bit fields other than int
  474.  
  475. #define STORAGE_HW_FIRMWARE_REVISION_LENGTH             16
  476.  
  477. typedef struct _STORAGE_HW_FIRMWARE_SLOT_INFO {
  478.  
  479.     ULONG   Version;            // sizeof(STORAGE_HW_FIRMWARE_SLOT_INFO)
  480.     ULONG   Size;               // size the data contained in STORAGE_HW_FIRMWARE_SLOT_INFO.
  481.  
  482.     UCHAR   SlotNumber;
  483.     UCHAR   ReadOnly : 1;
  484.     UCHAR   Reserved0 : 7;
  485.     UCHAR   Reserved1[6];
  486.  
  487.     UCHAR   Revision[STORAGE_HW_FIRMWARE_REVISION_LENGTH];
  488.  
  489. } STORAGE_HW_FIRMWARE_SLOT_INFO, *PSTORAGE_HW_FIRMWARE_SLOT_INFO;
  490.  
  491. typedef struct _STORAGE_HW_FIRMWARE_INFO {
  492.  
  493.     ULONG   Version;            // sizeof(STORAGE_HW_FIRMWARE_INFO)
  494.     ULONG   Size;               // size of the whole buffer including slot[]
  495.  
  496.     UCHAR   SupportUpgrade : 1;
  497.     UCHAR   Reserved0 : 7;
  498.     UCHAR   SlotCount;
  499.     UCHAR   ActiveSlot;
  500.     UCHAR   PendingActivateSlot;
  501.     BOOLEAN FirmwareShared;     // The firmware applies to both device and adapter. For example: PCIe SSD.
  502.     UCHAR   Reserved[3];
  503.  
  504.     ULONG   ImagePayloadAlignment;  // Number of bytes. Max: PAGE_SIZE. The transfer size should be multiple of this unit size. Some protocol requires at least sector size. 0 means the value is not valid.
  505.     ULONG   ImagePayloadMaxSize;    // for a single command.
  506.  
  507.     STORAGE_HW_FIRMWARE_SLOT_INFO Slot[ANYSIZE_ARRAY];
  508.  
  509. } STORAGE_HW_FIRMWARE_INFO, *PSTORAGE_HW_FIRMWARE_INFO;
  510. #pragma warning(pop)
  511.  
  512.  
  513. //
  514. // Input parameter for IOCTL_STORAGE_FIRMWARE_DOWNLOAD
  515. //
  516. #pragma warning(push)
  517. #pragma warning(disable:4200)
  518.  
  519. typedef struct _STORAGE_HW_FIRMWARE_DOWNLOAD {
  520.  
  521.     ULONG       Version;            // sizeof(STORAGE_FIRMWARE_DOWNLOAD)
  522.     ULONG       Size;               // size of the whole buffer include "ImageBuffer"
  523.  
  524.     ULONG       Flags;
  525.     UCHAR       Slot;               // Slot number that firmware image will be downloaded into.
  526.     UCHAR       Reserved[3];
  527.  
  528.     ULONGLONG   Offset;             // Image file offset, should be aligned to "ImagePayloadAlignment" value from STORAGE_FIRMWARE_INFO.
  529.     ULONGLONG   BufferSize;         // should be multiple of "ImagePayloadAlignment" value from STORAGE_FIRMWARE_INFO.
  530.  
  531.     UCHAR       ImageBuffer[ANYSIZE_ARRAY];     // firmware image file.
  532.  
  533. } STORAGE_HW_FIRMWARE_DOWNLOAD, *PSTORAGE_HW_FIRMWARE_DOWNLOAD;
  534.  
  535. #pragma warning(pop)
  536.  
  537. //
  538. // Input parameter for IOCTL_STORAGE_FIRMWARE_ACTIVATE
  539. //
  540. typedef struct _STORAGE_HW_FIRMWARE_ACTIVATE {
  541.  
  542.     ULONG   Version;
  543.     ULONG   Size;
  544.  
  545.     ULONG   Flags;
  546.     UCHAR   Slot;                   // Slot with firmware image to be activated.
  547.     UCHAR   Reserved0[3];
  548.  
  549. } STORAGE_HW_FIRMWARE_ACTIVATE, *PSTORAGE_HW_FIRMWARE_ACTIVATE;
  550.  
  551. //
  552. // Parameter for IOCTL_STORAGE_PROTOCOL_COMMAND
  553. // Buffer layout: <STORAGE_PROTOCOL_COMMAND> <Command> [Error Info Buffer] [Data-to-Device Buffer] [Data-from-Device Buffer]
  554. //
  555. #define STORAGE_PROTOCOL_STRUCTURE_VERSION              0x1
  556.  
  557. typedef struct _STORAGE_PROTOCOL_COMMAND {
  558.  
  559.     ULONG   Version;                        // STORAGE_PROTOCOL_STRUCTURE_VERSION
  560.     ULONG   Length;                         // sizeof(STORAGE_PROTOCOL_COMMAND)
  561.  
  562.     STORAGE_PROTOCOL_TYPE  ProtocolType;
  563.     ULONG   Flags;                          // Flags for the request
  564.  
  565.     ULONG   ReturnStatus;                   // return value
  566.     ULONG   ErrorCode;                      // return value, optional
  567.  
  568.     ULONG   CommandLength;                  // non-zero value should be set by caller
  569.     ULONG   ErrorInfoLength;                // optional, can be zero
  570.     ULONG   DataToDeviceTransferLength;     // optional, can be zero. Used by WRITE type of request.
  571.     ULONG   DataFromDeviceTransferLength;   // optional, can be zero. Used by READ type of request.
  572.  
  573.     ULONG   TimeOutValue;                   // in unit of seconds
  574.  
  575.     ULONG   ErrorInfoOffset;                // offsets need to be pointer aligned
  576.     ULONG   DataToDeviceBufferOffset;       // offsets need to be pointer aligned
  577.     ULONG   DataFromDeviceBufferOffset;     // offsets need to be pointer aligned
  578.  
  579.     ULONG   CommandSpecific;                // optional information passed along with Command.
  580.     ULONG   Reserved0;
  581.  
  582.     ULONG   FixedProtocolReturnData;        // return data, optional. Some protocol, such as NVMe, may return a small amount data (DWORD0 from completion queue entry) without the need of separate device data transfer.
  583.     ULONG   Reserved1[3];
  584.  
  585.     _Field_size_bytes_full_(CommandLength) UCHAR Command[ANYSIZE_ARRAY];
  586.  
  587. } STORAGE_PROTOCOL_COMMAND, *PSTORAGE_PROTOCOL_COMMAND;
  588.  
  589. //
  590. // Bit-mask values for STORAGE_PROTOCOL_COMMAND - "Flags" field.
  591. //
  592. #define STORAGE_PROTOCOL_COMMAND_FLAG_ADAPTER_REQUEST    0x80000000     // Flag indicates the request targeting to adapter instead of device.
  593.  
  594. //
  595. // Status values for STORAGE_PROTOCOL_COMMAND - "ReturnStatus" field.
  596. //
  597. #define STORAGE_PROTOCOL_STATUS_PENDING                 0x0
  598. #define STORAGE_PROTOCOL_STATUS_SUCCESS                 0x1
  599. #define STORAGE_PROTOCOL_STATUS_ERROR                   0x2
  600. #define STORAGE_PROTOCOL_STATUS_INVALID_REQUEST         0x3
  601. #define STORAGE_PROTOCOL_STATUS_NO_DEVICE               0x4
  602. #define STORAGE_PROTOCOL_STATUS_BUSY                    0x5
  603. #define STORAGE_PROTOCOL_STATUS_DATA_OVERRUN            0x6
  604. #define STORAGE_PROTOCOL_STATUS_INSUFFICIENT_RESOURCES  0x7
  605.  
  606. #define STORAGE_PROTOCOL_STATUS_NOT_SUPPORTED           0xFF
  607.  
  608. //
  609. // Command Length for Storage Protocols.
  610. //
  611. #define STORAGE_PROTOCOL_COMMAND_LENGTH_NVME            0x40            // NVMe commands are always 64 bytes.
  612.  
  613. //
  614. // Command Specific Information for Storage Protocols - "CommandSpecific" field.
  615. //
  616. #define STORAGE_PROTOCOL_SPECIFIC_NVME_ADMIN_COMMAND    0x01
  617. #define STORAGE_PROTOCOL_SPECIFIC_NVME_NVM_COMMAND      0x02
  618.  
  619. //
  620. // Additional notes when STORAGE_PROTOCOL_TYPE is ProtocolTypeNvme:
  621. //  1.  When flag STORAGE_PROTOCOL_COMMAND_FLAG_ADAPTER_REQUEST is set, or the request is sent through adapter, namespace Id from "Command" field is used;
  622. //      otherwise, the underneath driver should determine namespace Id from the device that receives the command.
  623. //  2.  When a command fails, the "ErrorCode" field contains value from NVMe Completion Queue Entry - DW3 - Status Field.
  624. //  3.  "CommandLength" field must have value of 64. e.g. STORAGE_PROTOCOL_COMMAND_LENGTH_NVME.
  625. //  4.  "CommandSpecific" field must have value of either STORAGE_PROTOCOL_SPECIFIC_NVME_ADMIN_COMMAND, or STORAGE_PROTOCOL_SPECIFIC_NVME_NVM_COMMAND.
  626. //  5.  When a command succeeds, field "FixedProtocolReturnData" may contain value from NVMe Completion Queue Entry - DW0.
  627. //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement