]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.h
MdeModulePkg/NvmExpressDxe: fix build error
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / NvmExpressDxe / NvmExpressPassthru.h
1 /** @file
2 NvmExpressDxe driver is used to manage non-volatile memory subsystem which follows
3 NVM Express specification.
4
5 Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #ifndef _NVM_EXPRESS_PASS_THRU_H_
17 #define _NVM_EXPRESS_PASS_THRU_H_
18
19 #define NVM_EXPRESS_PASS_THRU_PROTOCOL_GUID \
20 { \
21 0xec51ef5c, 0x2cf3, 0x4a55, {0xbf, 0x85, 0xb6, 0x3c, 0xa3, 0xb1, 0x3f, 0x44 } \
22 }
23
24 typedef struct _NVM_EXPRESS_PASS_THRU_PROTOCOL NVM_EXPRESS_PASS_THRU_PROTOCOL;
25
26 typedef struct {
27 UINT32 AdapterId;
28 UINT32 Attributes;
29 UINT32 IoAlign;
30 UINT32 HciVersion;
31 UINT64 Timeout;
32 UINT32 MaxNamespace;
33 } NVM_EXPRESS_PASS_THRU_MODE;
34
35 //
36 // If this bit is set, then the NVM_EXPRESS_PASS_THRU_PROTOCOL interface is for directly addressable namespaces.
37 //
38 #define NVM_EXPRESS_PASS_THRU_ATTRIBUTES_PHYSICAL 0x0001
39 //
40 // If this bit is set, then the NVM_EXPRESS_PASS_THRU_PROTOCOL interface is for a single volume logical namespace
41 // comprised of multiple namespaces.
42 //
43 #define NVM_EXPRESS_PASS_THRU_ATTRIBUTES_LOGICAL 0x0002
44 //
45 // If this bit is set, then the NVM_EXPRESS_PASS_THRU_PROTOCOL interface supports non blocking I/O.
46 //
47 #define NVM_EXPRESS_PASS_THRU_ATTRIBUTES_NONBLOCKIO 0x0004
48 //
49 // If this bit is set, then the NVM_EXPRESS_PASS_THRU_PROTOCOL interface supports NVM command set commands.
50 //
51 #define NVM_EXPRESS_PASS_THRU_ATTRIBUTES_CMD_SET_NVME 0x0008
52
53 //
54 // QueueId
55 //
56 #define NVME_ADMIN_QUEUE 0x00
57 #define NVME_IO_QUEUE 0x01
58
59 //
60 // ControllerStatus
61 //
62 #define NVM_EXPRESS_STATUS_CONTROLLER_READY 0x00
63 #define NVM_EXPRESS_STATUS_CONTROLLER_CMD_ERROR 0x01
64 #define NVM_EXPRESS_STATUS_CONTROLLER_FATAL 0x02
65 #define NVM_EXPRESS_STATUS_CONTROLLER_CMD_DATA_ERROR 0x04
66 #define NVM_EXPRESS_STATUS_CONTROLLER_CMD_ABORT 0x05
67 #define NVM_EXPRESS_STATUS_CONTROLLER_DEVICE_ERROR 0x06
68 #define NVM_EXPRESS_STATUS_CONTROLLER_TIMEOUT_COMMAND 0x09
69 #define NVM_EXPRESS_STATUS_CONTROLLER_INVALID_NAMESPACE 0x0B
70 #define NVM_EXPRESS_STATUS_CONTROLLER_NOT_READY 0x0C
71 #define NVM_EXPRESS_STATUS_CONTROLLER_OTHER 0x7F
72
73 typedef struct {
74 UINT8 Opcode;
75 UINT8 FusedOperation;
76 #define NORMAL_CMD 0x00
77 #define FUSED_FIRST_CMD 0x01
78 #define FUSED_SECOND_CMD 0x02
79 UINT16 Cid;
80 } NVME_CDW0;
81
82 typedef struct {
83 NVME_CDW0 Cdw0;
84 UINT8 Flags;
85 #define CDW10_VALID 0x01
86 #define CDW11_VALID 0x02
87 #define CDW12_VALID 0x04
88 #define CDW13_VALID 0x08
89 #define CDW14_VALID 0x10
90 #define CDW15_VALID 0x20
91 UINT32 Nsid;
92 UINT32 Cdw10;
93 UINT32 Cdw11;
94 UINT32 Cdw12;
95 UINT32 Cdw13;
96 UINT32 Cdw14;
97 UINT32 Cdw15;
98 } NVM_EXPRESS_COMMAND;
99
100 typedef struct {
101 UINT32 Cdw0;
102 UINT32 Cdw1;
103 UINT32 Cdw2;
104 UINT32 Cdw3;
105 } NVM_EXPRESS_RESPONSE;
106
107 typedef struct {
108 UINT64 CommandTimeout;
109 VOID *TransferBuffer;
110 UINT32 TransferLength;
111 VOID *MetadataBuffer;
112 UINT32 MetadataLength;
113 UINT8 QueueId;
114 NVM_EXPRESS_COMMAND *NvmeCmd;
115 NVM_EXPRESS_RESPONSE *NvmeResponse;
116 UINT8 ControllerStatus;
117 } NVM_EXPRESS_PASS_THRU_COMMAND_PACKET;
118
119 //
120 // Protocol funtion prototypes
121 //
122 /**
123 Sends an NVM Express Command Packet to an NVM Express controller or namespace. This function supports
124 both blocking I/O and nonblocking I/O. The blocking I/O functionality is required, and the nonblocking
125 I/O functionality is optional.
126
127 @param[in] This A pointer to the NVM_EXPRESS_PASS_THRU_PROTOCOL instance.
128 @param[in] NamespaceId Is a 32 bit Namespace ID to which the Express HCI command packet will be sent.
129 A value of 0 denotes the NVM Express controller, a value of all 0FFh in the namespace
130 ID specifies that the command packet should be sent to all valid namespaces.
131 @param[in] NamespaceUuid Is a 64 bit Namespace UUID to which the Express HCI command packet will be sent.
132 A value of 0 denotes the NVM Express controller, a value of all 0FFh in the namespace
133 UUID specifies that the command packet should be sent to all valid namespaces.
134 @param[in,out] Packet A pointer to the NVM Express HCI Command Packet to send to the NVMe namespace specified
135 by NamespaceId.
136 @param[in] Event If nonblocking I/O is not supported then Event is ignored, and blocking I/O is performed.
137 If Event is NULL, then blocking I/O is performed. If Event is not NULL and non blocking I/O
138 is supported, then nonblocking I/O is performed, and Event will be signaled when the NVM
139 Express Command Packet completes.
140
141 @retval EFI_SUCCESS The NVM Express Command Packet was sent by the host. TransferLength bytes were transferred
142 to, or from DataBuffer.
143 @retval EFI_BAD_BUFFER_SIZE The NVM Express Command Packet was not executed. The number of bytes that could be transferred
144 is returned in TransferLength.
145 @retval EFI_NOT_READY The NVM Express Command Packet could not be sent because the controller is not ready. The caller
146 may retry again later.
147 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the NVM Express Command Packet.
148 @retval EFI_INVALID_PARAMETER Namespace, or the contents of NVM_EXPRESS_PASS_THRU_COMMAND_PACKET are invalid. The NVM
149 Express Command Packet was not sent, so no additional status information is available.
150 @retval EFI_UNSUPPORTED The command described by the NVM Express Command Packet is not supported by the host adapter.
151 The NVM Express Command Packet was not sent, so no additional status information is available.
152 @retval EFI_TIMEOUT A timeout occurred while waiting for the NVM Express Command Packet to execute.
153
154 **/
155 typedef
156 EFI_STATUS
157 (EFIAPI *NVM_EXPRESS_PASS_THRU_PASSTHRU)(
158 IN NVM_EXPRESS_PASS_THRU_PROTOCOL *This,
159 IN UINT32 NamespaceId,
160 IN UINT64 NamespaceUuid,
161 IN OUT NVM_EXPRESS_PASS_THRU_COMMAND_PACKET *Packet,
162 IN EFI_EVENT Event OPTIONAL
163 );
164
165 /**
166 Used to retrieve the list of namespaces defined on an NVM Express controller.
167
168 The NVM_EXPRESS_PASS_THRU_PROTOCOL.GetNextNamespace() function retrieves a list of namespaces
169 defined on an NVM Express controller. If on input a NamespaceID is specified by all 0xFF in the
170 namespace buffer, then the first namespace defined on the NVM Express controller is returned in
171 NamespaceID, and a status of EFI_SUCCESS is returned.
172
173 If NamespaceId is a Namespace value that was returned on a previous call to GetNextNamespace(),
174 then the next valid NamespaceId for an NVM Express SSD namespace on the NVM Express controller
175 is returned in NamespaceId, and EFI_SUCCESS is returned.
176
177 If Namespace array is not a 0xFFFFFFFF and NamespaceId was not returned on a previous call to
178 GetNextNamespace(), then EFI_INVALID_PARAMETER is returned.
179
180 If NamespaceId is the NamespaceId of the last SSD namespace on the NVM Express controller, then
181 EFI_NOT_FOUND is returned
182
183 @param[in] This A pointer to the NVM_EXPRESS_PASS_THRU_PROTOCOL instance.
184 @param[in,out] NamespaceId On input, a pointer to a legal NamespaceId for an NVM Express
185 namespace present on the NVM Express controller. On output, a
186 pointer to the next NamespaceId of an NVM Express namespace on
187 an NVM Express controller. An input value of 0xFFFFFFFF retrieves
188 the first NamespaceId for an NVM Express namespace present on an
189 NVM Express controller.
190 @param[out] NamespaceUuid On output, the UUID associated with the next namespace, if a UUID
191 is defined for that NamespaceId, otherwise, zero is returned in
192 this parameter. If the caller does not require a UUID, then a NULL
193 pointer may be passed.
194
195 @retval EFI_SUCCESS The NamespaceId of the next Namespace was returned.
196 @retval EFI_NOT_FOUND There are no more namespaces defined on this controller.
197 @retval EFI_INVALID_PARAMETER Namespace array is not a 0xFFFFFFFF and NamespaceId was not returned
198 on a previous call to GetNextNamespace().
199
200 **/
201 typedef
202 EFI_STATUS
203 (EFIAPI *NVM_EXPRESS_PASS_THRU_GET_NEXT_NAMESPACE)(
204 IN NVM_EXPRESS_PASS_THRU_PROTOCOL *This,
205 IN OUT UINT32 *NamespaceId,
206 OUT UINT64 *NamespaceUuid OPTIONAL
207 );
208
209 /**
210 Used to allocate and build a device path node for an NVM Express namespace on an NVM Express controller.
211
212 The NVM_EXPRESS_PASS_THRU_PROTOCOL.BuildDevicePath() function allocates and builds a single device
213 path node for the NVM Express namespace specified by NamespaceId.
214
215 If the namespace device specified by NamespaceId is not valid , then EFI_NOT_FOUND is returned.
216
217 If DevicePath is NULL, then EFI_INVALID_PARAMETER is returned.
218
219 If there are not enough resources to allocate the device path node, then EFI_OUT_OF_RESOURCES is returned.
220
221 Otherwise, DevicePath is allocated with the boot service AllocatePool(), the contents of DevicePath are
222 initialized to describe the NVM Express namespace specified by NamespaceId, and EFI_SUCCESS is returned.
223
224 @param[in] This A pointer to the NVM_EXPRESS_PASS_THRU_PROTOCOL instance.
225 @param[in] NamespaceId The NVM Express namespace ID for which a device path node is to be
226 allocated and built. Caller must set the NamespaceId to zero if the
227 device path node will contain a valid UUID.
228 @param[in] NamespaceUuid The NVM Express namespace UUID for which a device path node is to be
229 allocated and built. UUID will only be valid of the Namespace ID is zero.
230 @param[in,out] DevicePath A pointer to a single device path node that describes the NVM Express
231 namespace specified by NamespaceId. This function is responsible for
232 allocating the buffer DevicePath with the boot service AllocatePool().
233 It is the caller's responsibility to free DevicePath when the caller
234 is finished with DevicePath.
235 @retval EFI_SUCCESS The device path node that describes the NVM Express namespace specified
236 by NamespaceId was allocated and returned in DevicePath.
237 @retval EFI_NOT_FOUND The NVM Express namespace specified by NamespaceId does not exist on the
238 NVM Express controller.
239 @retval EFI_INVALID_PARAMETER DevicePath is NULL.
240 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate the DevicePath node.
241
242 **/
243 typedef
244 EFI_STATUS
245 (EFIAPI *NVM_EXPRESS_PASS_THRU_BUILD_DEVICE_PATH)(
246 IN NVM_EXPRESS_PASS_THRU_PROTOCOL *This,
247 IN UINT32 NamespaceId,
248 IN UINT64 NamespaceUuid,
249 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
250 );
251
252 /**
253 Used to translate a device path node to a Namespace ID and Namespace UUID.
254
255 The NVM_EXPRESS_PASS_THRU_PROTOCOL.GetNamwspace() function determines the Namespace ID and Namespace UUID
256 associated with the NVM Express SSD namespace described by DevicePath. If DevicePath is a device path node type
257 that the NVM Express Pass Thru driver supports, then the NVM Express Pass Thru driver will attempt to translate
258 the contents DevicePath into a Namespace ID and UUID. If this translation is successful, then that Namespace ID
259 and UUID are returned in NamespaceID and NamespaceUUID, and EFI_SUCCESS is returned.
260
261 @param[in] This A pointer to the NVM_EXPRESS_PASS_THRU_PROTOCOL instance.
262 @param[in] DevicePath A pointer to the device path node that describes an NVM Express namespace on
263 the NVM Express controller.
264 @param[out] NamespaceId The NVM Express namespace ID contained in the device path node.
265 @param[out] NamespaceUuid The NVM Express namespace contained in the device path node.
266
267 @retval EFI_SUCCESS DevicePath was successfully translated to NamespaceId and NamespaceUuid.
268 @retval EFI_INVALID_PARAMETER If DevicePath, NamespaceId, or NamespaceUuid are NULL, then EFI_INVALID_PARAMETER
269 is returned.
270 @retval EFI_UNSUPPORTED If DevicePath is not a device path node type that the NVM Express Pass Thru driver
271 supports, then EFI_UNSUPPORTED is returned.
272 @retval EFI_NOT_FOUND If DevicePath is a device path node type that the Nvm Express Pass Thru driver
273 supports, but there is not a valid translation from DevicePath to a NamespaceID
274 and NamespaceUuid, then EFI_NOT_FOUND is returned.
275 **/
276 typedef
277 EFI_STATUS
278 (EFIAPI *NVM_EXPRESS_PASS_THRU_GET_NAMESPACE)(
279 IN NVM_EXPRESS_PASS_THRU_PROTOCOL *This,
280 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
281 OUT UINT32 *NamespaceId,
282 OUT UINT64 *NamespaceUuid
283 );
284
285 //
286 // Protocol Interface Structure
287 //
288 struct _NVM_EXPRESS_PASS_THRU_PROTOCOL {
289 NVM_EXPRESS_PASS_THRU_MODE *Mode;
290 NVM_EXPRESS_PASS_THRU_PASSTHRU PassThru;
291 NVM_EXPRESS_PASS_THRU_GET_NEXT_NAMESPACE GetNextNamespace;
292 NVM_EXPRESS_PASS_THRU_BUILD_DEVICE_PATH BuildDevicePath;
293 NVM_EXPRESS_PASS_THRU_GET_NAMESPACE GetNamespace;
294 };
295
296 //extern EFI_GUID gNvmExpressPassThruProtocolGuid;
297
298 #endif
299