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