1 /** @file 2 This protocol provides services that allow NVM Express commands to be sent to an 3 NVM Express controller or to a specific namespace in a NVM Express controller. 4 This protocol interface is optimized for storage. 5 6 Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.<BR> 7 This program and the accompanying materials 8 are licensed and made available under the terms and conditions of the BSD License 9 which accompanies this distribution. The full text of the license may be found at 10 http://opensource.org/licenses/bsd-license.php. 11 12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 14 15 **/ 16 17 #ifndef _UEFI_NVM_EXPRESS_PASS_THRU_H_ 18 #define _UEFI_NVM_EXPRESS_PASS_THRU_H_ 19 20 #define EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL_GUID \ 21 { \ 22 0x52c78312, 0x8edc, 0x4233, { 0x98, 0xf2, 0x1a, 0x1a, 0xa5, 0xe3, 0x88, 0xa5 } \ 23 } 24 25 typedef struct _EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL; 26 27 typedef struct { 28 UINT32 Attributes; 29 UINT32 IoAlign; 30 UINT32 NvmeVersion; 31 } EFI_NVM_EXPRESS_PASS_THRU_MODE; 32 33 // 34 // If this bit is set, then the EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL interface is 35 // for directly addressable namespaces. 36 // 37 #define EFI_NVM_EXPRESS_PASS_THRU_ATTRIBUTES_PHYSICAL 0x0001 38 // 39 // If this bit is set, then the EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL interface is 40 // for a single volume logical namespace comprised of multiple namespaces. 41 // 42 #define EFI_NVM_EXPRESS_PASS_THRU_ATTRIBUTES_LOGICAL 0x0002 43 // 44 // If this bit is set, then the EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL interface 45 // supports non-blocking I/O. 46 // 47 #define EFI_NVM_EXPRESS_PASS_THRU_ATTRIBUTES_NONBLOCKIO 0x0004 48 // 49 // If this bit is set, then the EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL interface 50 // supports NVM command set. 51 // 52 #define EFI_NVM_EXPRESS_PASS_THRU_ATTRIBUTES_CMD_SET_NVM 0x0008 53 54 // 55 // FusedOperation 56 // 57 #define NORMAL_CMD 0x00 58 #define FUSED_FIRST_CMD 0x01 59 #define FUSED_SECOND_CMD 0x02 60 61 typedef struct { 62 UINT32 Opcode:8; 63 UINT32 FusedOperation:2; 64 UINT32 Reserved:22; 65 } NVME_CDW0; 66 67 // 68 // Flags 69 // 70 #define CDW2_VALID 0x01 71 #define CDW3_VALID 0x02 72 #define CDW10_VALID 0x04 73 #define CDW11_VALID 0x08 74 #define CDW12_VALID 0x10 75 #define CDW13_VALID 0x20 76 #define CDW14_VALID 0x40 77 #define CDW15_VALID 0x80 78 79 // 80 // Queue Type 81 // 82 #define NVME_ADMIN_QUEUE 0x00 83 #define NVME_IO_QUEUE 0x01 84 85 typedef struct { 86 NVME_CDW0 Cdw0; 87 UINT8 Flags; 88 UINT32 Nsid; 89 UINT32 Cdw2; 90 UINT32 Cdw3; 91 UINT32 Cdw10; 92 UINT32 Cdw11; 93 UINT32 Cdw12; 94 UINT32 Cdw13; 95 UINT32 Cdw14; 96 UINT32 Cdw15; 97 } EFI_NVM_EXPRESS_COMMAND; 98 99 typedef struct { 100 UINT32 DW0; 101 UINT32 DW1; 102 UINT32 DW2; 103 UINT32 DW3; 104 } EFI_NVM_EXPRESS_COMPLETION; 105 106 typedef struct { 107 UINT64 CommandTimeout; 108 VOID *TransferBuffer; 109 UINT32 TransferLength; 110 VOID *MetadataBuffer; 111 UINT32 MetadataLength; 112 UINT8 QueueType; 113 EFI_NVM_EXPRESS_COMMAND *NvmeCmd; 114 EFI_NVM_EXPRESS_COMPLETION *NvmeCompletion; 115 } EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET; 116 117 // 118 // Protocol funtion prototypes 119 // 120 /** 121 Sends an NVM Express Command Packet to an NVM Express controller or namespace. This function supports 122 both blocking I/O and non-blocking I/O. The blocking I/O functionality is required, and the non-blocking 123 I/O functionality is optional. 124 125 126 @param[in] This A pointer to the EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL instance. 127 @param[in] NamespaceId A 32 bit namespace ID as defined in the NVMe specification to which the NVM Express Command 128 Packet will be sent. A value of 0 denotes the NVM Express controller, a value of all 0xFF's 129 (all bytes are 0xFF) in the namespace ID specifies that the command packet should be sent to 130 all valid namespaces. 131 @param[in,out] Packet A pointer to the NVM Express Command Packet. 132 @param[in] Event If non-blocking I/O is not supported then Event is ignored, and blocking I/O is performed. 133 If Event is NULL, then blocking I/O is performed. If Event is not NULL and non-blocking I/O 134 is supported, then non-blocking I/O is performed, and Event will be signaled when the NVM 135 Express Command Packet completes. 136 137 @retval EFI_SUCCESS The NVM Express Command Packet was sent by the host. TransferLength bytes were transferred 138 to, or from DataBuffer. 139 @retval EFI_BAD_BUFFER_SIZE The NVM Express Command Packet was not executed. The number of bytes that could be transferred 140 is returned in TransferLength. 141 @retval EFI_NOT_READY The NVM Express Command Packet could not be sent because the controller is not ready. The caller 142 may retry again later. 143 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the NVM Express Command Packet. 144 @retval EFI_INVALID_PARAMETER NamespaceId or the contents of EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET are invalid. The NVM 145 Express Command Packet was not sent, so no additional status information is available. 146 @retval EFI_UNSUPPORTED The command described by the NVM Express Command Packet is not supported by the NVM Express 147 controller. The NVM Express Command Packet was not sent so no additional status information 148 is available. 149 @retval EFI_TIMEOUT A timeout occurred while waiting for the NVM Express Command Packet to execute. 150 151 **/ 152 typedef 153 EFI_STATUS 154 (EFIAPI *EFI_NVM_EXPRESS_PASS_THRU_PASSTHRU)( 155 IN EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *This, 156 IN UINT32 NamespaceId, 157 IN OUT EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET *Packet, 158 IN EFI_EVENT Event OPTIONAL 159 ); 160 161 /** 162 Used to retrieve the next namespace ID for this NVM Express controller. 163 164 The EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL.GetNextNamespace() function retrieves the next valid 165 namespace ID on this NVM Express controller. 166 167 If on input the value pointed to by NamespaceId is 0xFFFFFFFF, then the first valid namespace 168 ID defined on the NVM Express controller is returned in the location pointed to by NamespaceId 169 and a status of EFI_SUCCESS is returned. 170 171 If on input the value pointed to by NamespaceId is an invalid namespace ID other than 0xFFFFFFFF, 172 then EFI_INVALID_PARAMETER is returned. 173 174 If on input the value pointed to by NamespaceId is a valid namespace ID, then the next valid 175 namespace ID on the NVM Express controller is returned in the location pointed to by NamespaceId, 176 and EFI_SUCCESS is returned. 177 178 If the value pointed to by NamespaceId is the namespace ID of the last namespace on the NVM 179 Express controller, then EFI_NOT_FOUND is returned. 180 181 @param[in] This A pointer to the EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL instance. 182 @param[in,out] NamespaceId On input, a pointer to a legal NamespaceId for an NVM Express 183 namespace present on the NVM Express controller. On output, a 184 pointer to the next NamespaceId of an NVM Express namespace on 185 an NVM Express controller. An input value of 0xFFFFFFFF retrieves 186 the first NamespaceId for an NVM Express namespace present on an 187 NVM Express controller. 188 189 @retval EFI_SUCCESS The Namespace ID of the next Namespace was returned. 190 @retval EFI_NOT_FOUND There are no more namespaces defined on this controller. 191 @retval EFI_INVALID_PARAMETER NamespaceId is an invalid value other than 0xFFFFFFFF. 192 193 **/ 194 typedef 195 EFI_STATUS 196 (EFIAPI *EFI_NVM_EXPRESS_PASS_THRU_GET_NEXT_NAMESPACE)( 197 IN EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *This, 198 IN OUT UINT32 *NamespaceId 199 ); 200 201 /** 202 Used to allocate and build a device path node for an NVM Express namespace on an NVM Express controller. 203 204 The EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL.BuildDevicePath() function allocates and builds a single device 205 path node for the NVM Express namespace specified by NamespaceId. 206 207 If the NamespaceId is not valid, then EFI_NOT_FOUND is returned. 208 209 If DevicePath is NULL, then EFI_INVALID_PARAMETER is returned. 210 211 If there are not enough resources to allocate the device path node, then EFI_OUT_OF_RESOURCES is returned. 212 213 Otherwise, DevicePath is allocated with the boot service AllocatePool(), the contents of DevicePath are 214 initialized to describe the NVM Express namespace specified by NamespaceId, and EFI_SUCCESS is returned. 215 216 @param[in] This A pointer to the EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL instance. 217 @param[in] NamespaceId The NVM Express namespace ID for which a device path node is to be 218 allocated and built. Caller must set the NamespaceId to zero if the 219 device path node will contain a valid UUID. 220 @param[in,out] DevicePath A pointer to a single device path node that describes the NVM Express 221 namespace specified by NamespaceId. This function is responsible for 222 allocating the buffer DevicePath with the boot service AllocatePool(). 223 It is the caller's responsibility to free DevicePath when the caller 224 is finished with DevicePath. 225 @retval EFI_SUCCESS The device path node that describes the NVM Express namespace specified 226 by NamespaceId was allocated and returned in DevicePath. 227 @retval EFI_NOT_FOUND The NamespaceId is not valid. 228 @retval EFI_INVALID_PARAMETER DevicePath is NULL. 229 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate the DevicePath node. 230 231 **/ 232 typedef 233 EFI_STATUS 234 (EFIAPI *EFI_NVM_EXPRESS_PASS_THRU_BUILD_DEVICE_PATH)( 235 IN EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *This, 236 IN UINT32 NamespaceId, 237 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath 238 ); 239 240 /** 241 Used to translate a device path node to a namespace ID. 242 243 The EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL.GetNamespace() function determines the namespace ID associated with the 244 namespace described by DevicePath. 245 246 If DevicePath is a device path node type that the NVM Express Pass Thru driver supports, then the NVM Express 247 Pass Thru driver will attempt to translate the contents DevicePath into a namespace ID. 248 249 If this translation is successful, then that namespace ID is returned in NamespaceId, and EFI_SUCCESS is returned 250 251 @param[in] This A pointer to the EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL instance. 252 @param[in] DevicePath A pointer to the device path node that describes an NVM Express namespace on 253 the NVM Express controller. 254 @param[out] NamespaceId The NVM Express namespace ID contained in the device path node. 255 256 @retval EFI_SUCCESS DevicePath was successfully translated to NamespaceId. 257 @retval EFI_INVALID_PARAMETER If DevicePath or NamespaceId are NULL, then EFI_INVALID_PARAMETER is returned. 258 @retval EFI_UNSUPPORTED If DevicePath is not a device path node type that the NVM Express Pass Thru driver 259 supports, then EFI_UNSUPPORTED is returned. 260 @retval EFI_NOT_FOUND If DevicePath is a device path node type that the NVM Express Pass Thru driver 261 supports, but there is not a valid translation from DevicePath to a namespace ID, 262 then EFI_NOT_FOUND is returned. 263 **/ 264 typedef 265 EFI_STATUS 266 (EFIAPI *EFI_NVM_EXPRESS_PASS_THRU_GET_NAMESPACE)( 267 IN EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *This, 268 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, 269 OUT UINT32 *NamespaceId 270 ); 271 272 // 273 // Protocol Interface Structure 274 // 275 struct _EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL { 276 EFI_NVM_EXPRESS_PASS_THRU_MODE *Mode; 277 EFI_NVM_EXPRESS_PASS_THRU_PASSTHRU PassThru; 278 EFI_NVM_EXPRESS_PASS_THRU_GET_NEXT_NAMESPACE GetNextNamespace; 279 EFI_NVM_EXPRESS_PASS_THRU_BUILD_DEVICE_PATH BuildDevicePath; 280 EFI_NVM_EXPRESS_PASS_THRU_GET_NAMESPACE GetNamespace; 281 }; 282 283 extern EFI_GUID gEfiNvmExpressPassThruProtocolGuid; 284 285 #endif 286 287