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   Sends an NVM Express Command Packet to an NVM Express controller or namespace. This function supports
119   both blocking I/O and non-blocking I/O. The blocking I/O functionality is required, and the non-blocking
120   I/O functionality is optional.
121 
122 
123   @param[in]     This                A pointer to the EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL instance.
124   @param[in]     NamespaceId         A 32 bit namespace ID as defined in the NVMe specification to which the NVM Express Command
125                                      Packet will be sent.  A value of 0 denotes the NVM Express controller, a value of all 0xFF's
126                                      (all bytes are 0xFF) in the namespace ID specifies that the command packet should be sent to
127                                      all valid namespaces.
128   @param[in,out] Packet              A pointer to the NVM Express Command Packet.
129   @param[in]     Event               If non-blocking I/O is not supported then Event is ignored, and blocking I/O is performed.
130                                      If Event is NULL, then blocking I/O is performed. If Event is not NULL and non-blocking I/O
131                                      is supported, then non-blocking I/O is performed, and Event will be signaled when the NVM
132                                      Express Command Packet completes.
133 
134   @retval EFI_SUCCESS                The NVM Express Command Packet was sent by the host. TransferLength bytes were transferred
135                                      to, or from DataBuffer.
136   @retval EFI_BAD_BUFFER_SIZE        The NVM Express Command Packet was not executed. The number of bytes that could be transferred
137                                      is returned in TransferLength.
138   @retval EFI_NOT_READY              The NVM Express Command Packet could not be sent because the controller is not ready. The caller
139                                      may retry again later.
140   @retval EFI_DEVICE_ERROR           A device error occurred while attempting to send the NVM Express Command Packet.
141   @retval EFI_INVALID_PARAMETER      NamespaceId or the contents of EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET are invalid. The NVM
142                                      Express Command Packet was not sent, so no additional status information is available.
143   @retval EFI_UNSUPPORTED            The command described by the NVM Express Command Packet is not supported by the NVM Express
144                                      controller. The NVM Express Command Packet was not sent so no additional status information
145                                      is available.
146   @retval EFI_TIMEOUT                A timeout occurred while waiting for the NVM Express Command Packet to execute.
147 
148 **/
149 typedef
150 EFI_STATUS
151 (EFIAPI *EFI_NVM_EXPRESS_PASS_THRU_PASSTHRU)(
152   IN     EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL          *This,
153   IN     UINT32                                      NamespaceId,
154   IN OUT EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET    *Packet,
155   IN     EFI_EVENT                                   Event OPTIONAL
156   );
157 
158 /**
159   Used to retrieve the next namespace ID for this NVM Express controller.
160 
161   The EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL.GetNextNamespace() function retrieves the next valid
162   namespace ID on this NVM Express controller.
163 
164   If on input the value pointed to by NamespaceId is 0xFFFFFFFF, then the first valid namespace
165   ID defined on the NVM Express controller is returned in the location pointed to by NamespaceId
166   and a status of EFI_SUCCESS is returned.
167 
168   If on input the value pointed to by NamespaceId is an invalid namespace ID other than 0xFFFFFFFF,
169   then EFI_INVALID_PARAMETER is returned.
170 
171   If on input the value pointed to by NamespaceId is a valid namespace ID, then the next valid
172   namespace ID on the NVM Express controller is returned in the location pointed to by NamespaceId,
173   and EFI_SUCCESS is returned.
174 
175   If the value pointed to by NamespaceId is the namespace ID of the last namespace on the NVM
176   Express controller, then EFI_NOT_FOUND is returned.
177 
178   @param[in]     This           A pointer to the EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL instance.
179   @param[in,out] NamespaceId    On input, a pointer to a legal NamespaceId for an NVM Express
180                                 namespace present on the NVM Express controller. On output, a
181                                 pointer to the next NamespaceId of an NVM Express namespace on
182                                 an NVM Express controller. An input value of 0xFFFFFFFF retrieves
183                                 the first NamespaceId for an NVM Express namespace present on an
184                                 NVM Express controller.
185 
186   @retval EFI_SUCCESS           The Namespace ID of the next Namespace was returned.
187   @retval EFI_NOT_FOUND         There are no more namespaces defined on this controller.
188   @retval EFI_INVALID_PARAMETER NamespaceId is an invalid value other than 0xFFFFFFFF.
189 
190 **/
191 typedef
192 EFI_STATUS
193 (EFIAPI *EFI_NVM_EXPRESS_PASS_THRU_GET_NEXT_NAMESPACE)(
194   IN     EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL          *This,
195   IN OUT UINT32                                      *NamespaceId
196   );
197 
198 /**
199   Used to allocate and build a device path node for an NVM Express namespace on an NVM Express controller.
200 
201   The EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL.BuildDevicePath() function allocates and builds a single device
202   path node for the NVM Express namespace specified by NamespaceId.
203 
204   If the NamespaceId is not valid, then EFI_NOT_FOUND is returned.
205 
206   If DevicePath is NULL, then EFI_INVALID_PARAMETER is returned.
207 
208   If there are not enough resources to allocate the device path node, then EFI_OUT_OF_RESOURCES is returned.
209 
210   Otherwise, DevicePath is allocated with the boot service AllocatePool(), the contents of DevicePath are
211   initialized to describe the NVM Express namespace specified by NamespaceId, and EFI_SUCCESS is returned.
212 
213   @param[in]     This                A pointer to the EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL instance.
214   @param[in]     NamespaceId         The NVM Express namespace ID  for which a device path node is to be
215                                      allocated and built. Caller must set the NamespaceId to zero if the
216                                      device path node will contain a valid UUID.
217   @param[out]    DevicePath          A pointer to a single device path node that describes the NVM Express
218                                      namespace specified by NamespaceId. This function is responsible for
219                                      allocating the buffer DevicePath with the boot service AllocatePool().
220                                      It is the caller's responsibility to free DevicePath when the caller
221                                      is finished with DevicePath.
222   @retval EFI_SUCCESS                The device path node that describes the NVM Express namespace specified
223                                      by NamespaceId was allocated and returned in DevicePath.
224   @retval EFI_NOT_FOUND              The NamespaceId is not valid.
225   @retval EFI_INVALID_PARAMETER      DevicePath is NULL.
226   @retval EFI_OUT_OF_RESOURCES       There are not enough resources to allocate the DevicePath node.
227 
228 **/
229 typedef
230 EFI_STATUS
231 (EFIAPI *EFI_NVM_EXPRESS_PASS_THRU_BUILD_DEVICE_PATH)(
232   IN     EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL          *This,
233   IN     UINT32                                      NamespaceId,
234   OUT    EFI_DEVICE_PATH_PROTOCOL                    **DevicePath
235   );
236 
237 /**
238   Used to translate a device path node to a namespace ID.
239 
240   The EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL.GetNamespace() function determines the namespace ID associated with the
241   namespace described by DevicePath.
242 
243   If DevicePath is a device path node type that the NVM Express Pass Thru driver supports, then the NVM Express
244   Pass Thru driver will attempt to translate the contents DevicePath into a namespace ID.
245 
246   If this translation is successful, then that namespace ID is returned in NamespaceId, and EFI_SUCCESS is returned
247 
248   @param[in]  This                A pointer to the EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL instance.
249   @param[in]  DevicePath          A pointer to the device path node that describes an NVM Express namespace on
250                                   the NVM Express controller.
251   @param[out] NamespaceId         The NVM Express namespace ID contained in the device path node.
252 
253   @retval EFI_SUCCESS             DevicePath was successfully translated to NamespaceId.
254   @retval EFI_INVALID_PARAMETER   If DevicePath or NamespaceId are NULL, then EFI_INVALID_PARAMETER is returned.
255   @retval EFI_UNSUPPORTED         If DevicePath is not a device path node type that the NVM Express Pass Thru driver
256                                   supports, then EFI_UNSUPPORTED is returned.
257   @retval EFI_NOT_FOUND           If DevicePath is a device path node type that the NVM Express Pass Thru driver
258                                   supports, but there is not a valid translation from DevicePath to a namespace ID,
259                                   then EFI_NOT_FOUND is returned.
260 **/
261 typedef
262 EFI_STATUS
263 (EFIAPI *EFI_NVM_EXPRESS_PASS_THRU_GET_NAMESPACE)(
264   IN     EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL          *This,
265   IN     EFI_DEVICE_PATH_PROTOCOL                    *DevicePath,
266      OUT UINT32                                      *NamespaceId
267   );
268 
269 //
270 // Protocol Interface Structure
271 //
272 struct _EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL {
273   EFI_NVM_EXPRESS_PASS_THRU_MODE                     *Mode;
274   EFI_NVM_EXPRESS_PASS_THRU_PASSTHRU                 PassThru;
275   EFI_NVM_EXPRESS_PASS_THRU_GET_NEXT_NAMESPACE       GetNextNamespace;
276   EFI_NVM_EXPRESS_PASS_THRU_BUILD_DEVICE_PATH        BuildDevicePath;
277   EFI_NVM_EXPRESS_PASS_THRU_GET_NAMESPACE            GetNamespace;
278 };
279 
280 extern EFI_GUID gEfiNvmExpressPassThruProtocolGuid;
281 
282 #endif
283 
284