]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.h
MdeModulePkg: Apply uncrustify changes
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / NvmExpressDxe / NvmExpress.h
1 /** @file
2 NvmExpressDxe driver is used to manage non-volatile memory subsystem which follows
3 NVM Express specification.
4
5 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
6 Copyright (c) 2013 - 2019, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9 **/
10
11 #ifndef _EFI_NVM_EXPRESS_H_
12 #define _EFI_NVM_EXPRESS_H_
13
14 #include <Uefi.h>
15
16 #include <IndustryStandard/Pci.h>
17 #include <IndustryStandard/Nvme.h>
18
19 #include <Protocol/ComponentName.h>
20 #include <Protocol/ComponentName2.h>
21 #include <Protocol/DriverBinding.h>
22 #include <Protocol/LoadedImage.h>
23 #include <Protocol/DevicePath.h>
24 #include <Protocol/PciIo.h>
25 #include <Protocol/NvmExpressPassthru.h>
26 #include <Protocol/BlockIo.h>
27 #include <Protocol/BlockIo2.h>
28 #include <Protocol/DiskInfo.h>
29 #include <Protocol/DriverSupportedEfiVersion.h>
30 #include <Protocol/StorageSecurityCommand.h>
31 #include <Protocol/ResetNotification.h>
32
33 #include <Library/BaseLib.h>
34 #include <Library/BaseMemoryLib.h>
35 #include <Library/DebugLib.h>
36 #include <Library/PrintLib.h>
37 #include <Library/UefiLib.h>
38 #include <Library/DevicePathLib.h>
39 #include <Library/MemoryAllocationLib.h>
40 #include <Library/UefiBootServicesTableLib.h>
41 #include <Library/UefiDriverEntryPoint.h>
42 #include <Library/ReportStatusCodeLib.h>
43
44 typedef struct _NVME_CONTROLLER_PRIVATE_DATA NVME_CONTROLLER_PRIVATE_DATA;
45 typedef struct _NVME_DEVICE_PRIVATE_DATA NVME_DEVICE_PRIVATE_DATA;
46
47 #include "NvmExpressBlockIo.h"
48 #include "NvmExpressDiskInfo.h"
49 #include "NvmExpressHci.h"
50
51 extern EFI_DRIVER_BINDING_PROTOCOL gNvmExpressDriverBinding;
52 extern EFI_COMPONENT_NAME_PROTOCOL gNvmExpressComponentName;
53 extern EFI_COMPONENT_NAME2_PROTOCOL gNvmExpressComponentName2;
54 extern EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL gNvmExpressDriverSupportedEfiVersion;
55
56 #define PCI_CLASS_MASS_STORAGE_NVM 0x08 // mass storage sub-class non-volatile memory.
57 #define PCI_IF_NVMHCI 0x02 // mass storage programming interface NVMHCI.
58
59 #define NVME_ASQ_SIZE 1 // Number of admin submission queue entries, which is 0-based
60 #define NVME_ACQ_SIZE 1 // Number of admin completion queue entries, which is 0-based
61
62 #define NVME_CSQ_SIZE 1 // Number of I/O submission queue entries, which is 0-based
63 #define NVME_CCQ_SIZE 1 // Number of I/O completion queue entries, which is 0-based
64
65 //
66 // Number of asynchronous I/O submission queue entries, which is 0-based.
67 // The asynchronous I/O submission queue size is 4kB in total.
68 //
69 #define NVME_ASYNC_CSQ_SIZE 63
70 //
71 // Number of asynchronous I/O completion queue entries, which is 0-based.
72 // The asynchronous I/O completion queue size is 4kB in total.
73 //
74 #define NVME_ASYNC_CCQ_SIZE 255
75
76 #define NVME_MAX_QUEUES 3 // Number of queues supported by the driver
77
78 #define NVME_CONTROLLER_ID 0
79
80 //
81 // Time out value for Nvme transaction execution
82 //
83 #define NVME_GENERIC_TIMEOUT EFI_TIMER_PERIOD_SECONDS (5)
84
85 //
86 // Nvme async transfer timer interval, set by experience.
87 //
88 #define NVME_HC_ASYNC_TIMER EFI_TIMER_PERIOD_MILLISECONDS (1)
89
90 //
91 // Unique signature for private data structure.
92 //
93 #define NVME_CONTROLLER_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('N','V','M','E')
94
95 //
96 // Nvme private data structure.
97 //
98 struct _NVME_CONTROLLER_PRIVATE_DATA {
99 UINT32 Signature;
100
101 EFI_HANDLE ControllerHandle;
102 EFI_HANDLE ImageHandle;
103 EFI_HANDLE DriverBindingHandle;
104
105 EFI_PCI_IO_PROTOCOL *PciIo;
106 UINT64 PciAttributes;
107
108 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
109
110 EFI_NVM_EXPRESS_PASS_THRU_MODE PassThruMode;
111 EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL Passthru;
112
113 //
114 // pointer to identify controller data
115 //
116 NVME_ADMIN_CONTROLLER_DATA *ControllerData;
117
118 //
119 // 6 x 4kB aligned buffers will be carved out of this buffer.
120 // 1st 4kB boundary is the start of the admin submission queue.
121 // 2nd 4kB boundary is the start of the admin completion queue.
122 // 3rd 4kB boundary is the start of I/O submission queue #1.
123 // 4th 4kB boundary is the start of I/O completion queue #1.
124 // 5th 4kB boundary is the start of I/O submission queue #2.
125 // 6th 4kB boundary is the start of I/O completion queue #2.
126 //
127 UINT8 *Buffer;
128 UINT8 *BufferPciAddr;
129
130 //
131 // Pointers to 4kB aligned submission & completion queues.
132 //
133 NVME_SQ *SqBuffer[NVME_MAX_QUEUES];
134 NVME_CQ *CqBuffer[NVME_MAX_QUEUES];
135 NVME_SQ *SqBufferPciAddr[NVME_MAX_QUEUES];
136 NVME_CQ *CqBufferPciAddr[NVME_MAX_QUEUES];
137
138 //
139 // Submission and completion queue indices.
140 //
141 NVME_SQTDBL SqTdbl[NVME_MAX_QUEUES];
142 NVME_CQHDBL CqHdbl[NVME_MAX_QUEUES];
143 UINT16 AsyncSqHead;
144
145 //
146 // Flag to indicate internal IO queue creation.
147 //
148 BOOLEAN CreateIoQueue;
149
150 UINT8 Pt[NVME_MAX_QUEUES];
151 UINT16 Cid[NVME_MAX_QUEUES];
152
153 //
154 // Nvme controller capabilities
155 //
156 NVME_CAP Cap;
157
158 VOID *Mapping;
159
160 //
161 // For Non-blocking operations.
162 //
163 EFI_EVENT TimerEvent;
164 LIST_ENTRY AsyncPassThruQueue;
165 LIST_ENTRY UnsubmittedSubtasks;
166 };
167
168 #define NVME_CONTROLLER_PRIVATE_DATA_FROM_PASS_THRU(a) \
169 CR (a, \
170 NVME_CONTROLLER_PRIVATE_DATA, \
171 Passthru, \
172 NVME_CONTROLLER_PRIVATE_DATA_SIGNATURE \
173 )
174
175 //
176 // Unique signature for private data structure.
177 //
178 #define NVME_DEVICE_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('X','S','S','D')
179
180 //
181 // Nvme device private data structure
182 //
183 struct _NVME_DEVICE_PRIVATE_DATA {
184 UINT32 Signature;
185
186 EFI_HANDLE DeviceHandle;
187 EFI_HANDLE ControllerHandle;
188 EFI_HANDLE DriverBindingHandle;
189
190 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
191
192 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
193
194 UINT32 NamespaceId;
195 UINT64 NamespaceUuid;
196
197 EFI_BLOCK_IO_MEDIA Media;
198 EFI_BLOCK_IO_PROTOCOL BlockIo;
199 EFI_BLOCK_IO2_PROTOCOL BlockIo2;
200 EFI_DISK_INFO_PROTOCOL DiskInfo;
201 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL StorageSecurity;
202
203 LIST_ENTRY AsyncQueue;
204
205 EFI_LBA NumBlocks;
206
207 CHAR16 ModelName[80];
208 NVME_ADMIN_NAMESPACE_DATA NamespaceData;
209
210 NVME_CONTROLLER_PRIVATE_DATA *Controller;
211 };
212
213 //
214 // Statments to retrieve the private data from produced protocols.
215 //
216 #define NVME_DEVICE_PRIVATE_DATA_FROM_BLOCK_IO(a) \
217 CR (a, \
218 NVME_DEVICE_PRIVATE_DATA, \
219 BlockIo, \
220 NVME_DEVICE_PRIVATE_DATA_SIGNATURE \
221 )
222
223 #define NVME_DEVICE_PRIVATE_DATA_FROM_BLOCK_IO2(a) \
224 CR (a, \
225 NVME_DEVICE_PRIVATE_DATA, \
226 BlockIo2, \
227 NVME_DEVICE_PRIVATE_DATA_SIGNATURE \
228 )
229
230 #define NVME_DEVICE_PRIVATE_DATA_FROM_DISK_INFO(a) \
231 CR (a, \
232 NVME_DEVICE_PRIVATE_DATA, \
233 DiskInfo, \
234 NVME_DEVICE_PRIVATE_DATA_SIGNATURE \
235 )
236
237 #define NVME_DEVICE_PRIVATE_DATA_FROM_STORAGE_SECURITY(a) \
238 CR (a, \
239 NVME_DEVICE_PRIVATE_DATA, \
240 StorageSecurity, \
241 NVME_DEVICE_PRIVATE_DATA_SIGNATURE \
242 )
243
244 //
245 // Nvme block I/O 2 request.
246 //
247 #define NVME_BLKIO2_REQUEST_SIGNATURE SIGNATURE_32 ('N', 'B', '2', 'R')
248
249 typedef struct {
250 UINT32 Signature;
251 LIST_ENTRY Link;
252
253 EFI_BLOCK_IO2_TOKEN *Token;
254 UINTN UnsubmittedSubtaskNum;
255 BOOLEAN LastSubtaskSubmitted;
256 //
257 // The queue for Nvme read/write sub-tasks of a BlockIo2 request.
258 //
259 LIST_ENTRY SubtasksQueue;
260 } NVME_BLKIO2_REQUEST;
261
262 #define NVME_BLKIO2_REQUEST_FROM_LINK(a) \
263 CR (a, NVME_BLKIO2_REQUEST, Link, NVME_BLKIO2_REQUEST_SIGNATURE)
264
265 #define NVME_BLKIO2_SUBTASK_SIGNATURE SIGNATURE_32 ('N', 'B', '2', 'S')
266
267 typedef struct {
268 UINT32 Signature;
269 LIST_ENTRY Link;
270
271 BOOLEAN IsLast;
272 UINT32 NamespaceId;
273 EFI_EVENT Event;
274 EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET *CommandPacket;
275 //
276 // The BlockIo2 request this subtask belongs to
277 //
278 NVME_BLKIO2_REQUEST *BlockIo2Request;
279 } NVME_BLKIO2_SUBTASK;
280
281 #define NVME_BLKIO2_SUBTASK_FROM_LINK(a) \
282 CR (a, NVME_BLKIO2_SUBTASK, Link, NVME_BLKIO2_SUBTASK_SIGNATURE)
283
284 //
285 // Nvme asynchronous passthru request.
286 //
287 #define NVME_PASS_THRU_ASYNC_REQ_SIG SIGNATURE_32 ('N', 'P', 'A', 'R')
288
289 typedef struct {
290 UINT32 Signature;
291 LIST_ENTRY Link;
292
293 EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET *Packet;
294 UINT16 CommandId;
295 VOID *MapPrpList;
296 UINTN PrpListNo;
297 VOID *PrpListHost;
298 VOID *MapData;
299 VOID *MapMeta;
300 EFI_EVENT CallerEvent;
301 } NVME_PASS_THRU_ASYNC_REQ;
302
303 #define NVME_PASS_THRU_ASYNC_REQ_FROM_THIS(a) \
304 CR (a, \
305 NVME_PASS_THRU_ASYNC_REQ, \
306 Link, \
307 NVME_PASS_THRU_ASYNC_REQ_SIG \
308 )
309
310 /**
311 Retrieves a Unicode string that is the user readable name of the driver.
312
313 This function retrieves the user readable name of a driver in the form of a
314 Unicode string. If the driver specified by This has a user readable name in
315 the language specified by Language, then a pointer to the driver name is
316 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
317 by This does not support the language specified by Language,
318 then EFI_UNSUPPORTED is returned.
319
320 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
321 EFI_COMPONENT_NAME_PROTOCOL instance.
322
323 @param Language[in] A pointer to a Null-terminated ASCII string
324 array indicating the language. This is the
325 language of the driver name that the caller is
326 requesting, and it must match one of the
327 languages specified in SupportedLanguages. The
328 number of languages supported by a driver is up
329 to the driver writer. Language is specified
330 in RFC 4646 or ISO 639-2 language code format.
331
332 @param DriverName[out] A pointer to the Unicode string to return.
333 This Unicode string is the name of the
334 driver specified by This in the language
335 specified by Language.
336
337 @retval EFI_SUCCESS The Unicode string for the Driver specified by
338 This and the language specified by Language was
339 returned in DriverName.
340
341 @retval EFI_INVALID_PARAMETER Language is NULL.
342
343 @retval EFI_INVALID_PARAMETER DriverName is NULL.
344
345 @retval EFI_UNSUPPORTED The driver specified by This does not support
346 the language specified by Language.
347
348 **/
349 EFI_STATUS
350 EFIAPI
351 NvmExpressComponentNameGetDriverName (
352 IN EFI_COMPONENT_NAME_PROTOCOL *This,
353 IN CHAR8 *Language,
354 OUT CHAR16 **DriverName
355 );
356
357 /**
358 Retrieves a Unicode string that is the user readable name of the controller
359 that is being managed by a driver.
360
361 This function retrieves the user readable name of the controller specified by
362 ControllerHandle and ChildHandle in the form of a Unicode string. If the
363 driver specified by This has a user readable name in the language specified by
364 Language, then a pointer to the controller name is returned in ControllerName,
365 and EFI_SUCCESS is returned. If the driver specified by This is not currently
366 managing the controller specified by ControllerHandle and ChildHandle,
367 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
368 support the language specified by Language, then EFI_UNSUPPORTED is returned.
369
370 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
371 EFI_COMPONENT_NAME_PROTOCOL instance.
372
373 @param ControllerHandle[in] The handle of a controller that the driver
374 specified by This is managing. This handle
375 specifies the controller whose name is to be
376 returned.
377
378 @param ChildHandle[in] The handle of the child controller to retrieve
379 the name of. This is an optional parameter that
380 may be NULL. It will be NULL for device
381 drivers. It will also be NULL for a bus drivers
382 that wish to retrieve the name of the bus
383 controller. It will not be NULL for a bus
384 driver that wishes to retrieve the name of a
385 child controller.
386
387 @param Language[in] A pointer to a Null-terminated ASCII string
388 array indicating the language. This is the
389 language of the driver name that the caller is
390 requesting, and it must match one of the
391 languages specified in SupportedLanguages. The
392 number of languages supported by a driver is up
393 to the driver writer. Language is specified in
394 RFC 4646 or ISO 639-2 language code format.
395
396 @param ControllerName[out] A pointer to the Unicode string to return.
397 This Unicode string is the name of the
398 controller specified by ControllerHandle and
399 ChildHandle in the language specified by
400 Language from the point of view of the driver
401 specified by This.
402
403 @retval EFI_SUCCESS The Unicode string for the user readable name in
404 the language specified by Language for the
405 driver specified by This was returned in
406 DriverName.
407
408 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
409
410 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
411 EFI_HANDLE.
412
413 @retval EFI_INVALID_PARAMETER Language is NULL.
414
415 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
416
417 @retval EFI_UNSUPPORTED The driver specified by This is not currently
418 managing the controller specified by
419 ControllerHandle and ChildHandle.
420
421 @retval EFI_UNSUPPORTED The driver specified by This does not support
422 the language specified by Language.
423
424 **/
425 EFI_STATUS
426 EFIAPI
427 NvmExpressComponentNameGetControllerName (
428 IN EFI_COMPONENT_NAME_PROTOCOL *This,
429 IN EFI_HANDLE ControllerHandle,
430 IN EFI_HANDLE ChildHandle OPTIONAL,
431 IN CHAR8 *Language,
432 OUT CHAR16 **ControllerName
433 );
434
435 /**
436 Tests to see if this driver supports a given controller. If a child device is provided,
437 it further tests to see if this driver supports creating a handle for the specified child device.
438
439 This function checks to see if the driver specified by This supports the device specified by
440 ControllerHandle. Drivers will typically use the device path attached to
441 ControllerHandle and/or the services from the bus I/O abstraction attached to
442 ControllerHandle to determine if the driver supports ControllerHandle. This function
443 may be called many times during platform initialization. In order to reduce boot times, the tests
444 performed by this function must be very small, and take as little time as possible to execute. This
445 function must not change the state of any hardware devices, and this function must be aware that the
446 device specified by ControllerHandle may already be managed by the same driver or a
447 different driver. This function must match its calls to AllocatePages() with FreePages(),
448 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
449 Since ControllerHandle may have been previously started by the same driver, if a protocol is
450 already in the opened state, then it must not be closed with CloseProtocol(). This is required
451 to guarantee the state of ControllerHandle is not modified by this function.
452
453 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
454 @param[in] ControllerHandle The handle of the controller to test. This handle
455 must support a protocol interface that supplies
456 an I/O abstraction to the driver.
457 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
458 parameter is ignored by device drivers, and is optional for bus
459 drivers. For bus drivers, if this parameter is not NULL, then
460 the bus driver must determine if the bus controller specified
461 by ControllerHandle and the child controller specified
462 by RemainingDevicePath are both supported by this
463 bus driver.
464
465 @retval EFI_SUCCESS The device specified by ControllerHandle and
466 RemainingDevicePath is supported by the driver specified by This.
467 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
468 RemainingDevicePath is already being managed by the driver
469 specified by This.
470 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
471 RemainingDevicePath is already being managed by a different
472 driver or an application that requires exclusive access.
473 Currently not implemented.
474 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
475 RemainingDevicePath is not supported by the driver specified by This.
476 **/
477 EFI_STATUS
478 EFIAPI
479 NvmExpressDriverBindingSupported (
480 IN EFI_DRIVER_BINDING_PROTOCOL *This,
481 IN EFI_HANDLE Controller,
482 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
483 );
484
485 /**
486 Starts a device controller or a bus controller.
487
488 The Start() function is designed to be invoked from the EFI boot service ConnectController().
489 As a result, much of the error checking on the parameters to Start() has been moved into this
490 common boot service. It is legal to call Start() from other locations,
491 but the following calling restrictions must be followed or the system behavior will not be deterministic.
492 1. ControllerHandle must be a valid EFI_HANDLE.
493 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
494 EFI_DEVICE_PATH_PROTOCOL.
495 3. Prior to calling Start(), the Supported() function for the driver specified by This must
496 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
497
498 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
499 @param[in] ControllerHandle The handle of the controller to start. This handle
500 must support a protocol interface that supplies
501 an I/O abstraction to the driver.
502 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
503 parameter is ignored by device drivers, and is optional for bus
504 drivers. For a bus driver, if this parameter is NULL, then handles
505 for all the children of Controller are created by this driver.
506 If this parameter is not NULL and the first Device Path Node is
507 not the End of Device Path Node, then only the handle for the
508 child device specified by the first Device Path Node of
509 RemainingDevicePath is created by this driver.
510 If the first Device Path Node of RemainingDevicePath is
511 the End of Device Path Node, no child handle is created by this
512 driver.
513
514 @retval EFI_SUCCESS The device was started.
515 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
516 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
517 @retval Others The driver failded to start the device.
518
519 **/
520 EFI_STATUS
521 EFIAPI
522 NvmExpressDriverBindingStart (
523 IN EFI_DRIVER_BINDING_PROTOCOL *This,
524 IN EFI_HANDLE Controller,
525 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
526 );
527
528 /**
529 Stops a device controller or a bus controller.
530
531 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
532 As a result, much of the error checking on the parameters to Stop() has been moved
533 into this common boot service. It is legal to call Stop() from other locations,
534 but the following calling restrictions must be followed or the system behavior will not be deterministic.
535 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
536 same driver's Start() function.
537 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
538 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
539 Start() function, and the Start() function must have called OpenProtocol() on
540 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
541
542 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
543 @param[in] ControllerHandle A handle to the device being stopped. The handle must
544 support a bus specific I/O protocol for the driver
545 to use to stop the device.
546 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
547 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
548 if NumberOfChildren is 0.
549
550 @retval EFI_SUCCESS The device was stopped.
551 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
552
553 **/
554 EFI_STATUS
555 EFIAPI
556 NvmExpressDriverBindingStop (
557 IN EFI_DRIVER_BINDING_PROTOCOL *This,
558 IN EFI_HANDLE Controller,
559 IN UINTN NumberOfChildren,
560 IN EFI_HANDLE *ChildHandleBuffer
561 );
562
563 /**
564 Sends an NVM Express Command Packet to an NVM Express controller or namespace. This function supports
565 both blocking I/O and nonblocking I/O. The blocking I/O functionality is required, and the nonblocking
566 I/O functionality is optional.
567
568 @param[in] This A pointer to the EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL instance.
569 @param[in] NamespaceId Is a 32 bit Namespace ID to which the Express HCI command packet will be sent.
570 A value of 0 denotes the NVM Express controller, a value of all 0FFh in the namespace
571 ID specifies that the command packet should be sent to all valid namespaces.
572 @param[in,out] Packet A pointer to the NVM Express HCI Command Packet to send to the NVMe namespace specified
573 by NamespaceId.
574 @param[in] Event If nonblocking I/O is not supported then Event is ignored, and blocking I/O is performed.
575 If Event is NULL, then blocking I/O is performed. If Event is not NULL and non blocking I/O
576 is supported, then nonblocking I/O is performed, and Event will be signaled when the NVM
577 Express Command Packet completes.
578
579 @retval EFI_SUCCESS The NVM Express Command Packet was sent by the host. TransferLength bytes were transferred
580 to, or from DataBuffer.
581 @retval EFI_BAD_BUFFER_SIZE The NVM Express Command Packet was not executed. The number of bytes that could be transferred
582 is returned in TransferLength.
583 @retval EFI_NOT_READY The NVM Express Command Packet could not be sent because the controller is not ready. The caller
584 may retry again later.
585 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the NVM Express Command Packet.
586 @retval EFI_INVALID_PARAMETER Namespace, or the contents of EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET are invalid. The NVM
587 Express Command Packet was not sent, so no additional status information is available.
588 @retval EFI_UNSUPPORTED The command described by the NVM Express Command Packet is not supported by the host adapter.
589 The NVM Express Command Packet was not sent, so no additional status information is available.
590 @retval EFI_TIMEOUT A timeout occurred while waiting for the NVM Express Command Packet to execute.
591
592 **/
593 EFI_STATUS
594 EFIAPI
595 NvmExpressPassThru (
596 IN EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *This,
597 IN UINT32 NamespaceId,
598 IN OUT EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET *Packet,
599 IN EFI_EVENT Event OPTIONAL
600 );
601
602 /**
603 Used to retrieve the next namespace ID for this NVM Express controller.
604
605 The EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL.GetNextNamespace() function retrieves the next valid
606 namespace ID on this NVM Express controller.
607
608 If on input the value pointed to by NamespaceId is 0xFFFFFFFF, then the first valid namespace
609 ID defined on the NVM Express controller is returned in the location pointed to by NamespaceId
610 and a status of EFI_SUCCESS is returned.
611
612 If on input the value pointed to by NamespaceId is an invalid namespace ID other than 0xFFFFFFFF,
613 then EFI_INVALID_PARAMETER is returned.
614
615 If on input the value pointed to by NamespaceId is a valid namespace ID, then the next valid
616 namespace ID on the NVM Express controller is returned in the location pointed to by NamespaceId,
617 and EFI_SUCCESS is returned.
618
619 If the value pointed to by NamespaceId is the namespace ID of the last namespace on the NVM
620 Express controller, then EFI_NOT_FOUND is returned.
621
622 @param[in] This A pointer to the EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL instance.
623 @param[in,out] NamespaceId On input, a pointer to a legal NamespaceId for an NVM Express
624 namespace present on the NVM Express controller. On output, a
625 pointer to the next NamespaceId of an NVM Express namespace on
626 an NVM Express controller. An input value of 0xFFFFFFFF retrieves
627 the first NamespaceId for an NVM Express namespace present on an
628 NVM Express controller.
629
630 @retval EFI_SUCCESS The Namespace ID of the next Namespace was returned.
631 @retval EFI_NOT_FOUND There are no more namespaces defined on this controller.
632 @retval EFI_INVALID_PARAMETER NamespaceId is an invalid value other than 0xFFFFFFFF.
633
634 **/
635 EFI_STATUS
636 EFIAPI
637 NvmExpressGetNextNamespace (
638 IN EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *This,
639 IN OUT UINT32 *NamespaceId
640 );
641
642 /**
643 Used to translate a device path node to a namespace ID.
644
645 The EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL.GetNamespace() function determines the namespace ID associated with the
646 namespace described by DevicePath.
647
648 If DevicePath is a device path node type that the NVM Express Pass Thru driver supports, then the NVM Express
649 Pass Thru driver will attempt to translate the contents DevicePath into a namespace ID.
650
651 If this translation is successful, then that namespace ID is returned in NamespaceId, and EFI_SUCCESS is returned
652
653 @param[in] This A pointer to the EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL instance.
654 @param[in] DevicePath A pointer to the device path node that describes an NVM Express namespace on
655 the NVM Express controller.
656 @param[out] NamespaceId The NVM Express namespace ID contained in the device path node.
657
658 @retval EFI_SUCCESS DevicePath was successfully translated to NamespaceId.
659 @retval EFI_INVALID_PARAMETER If DevicePath or NamespaceId are NULL, then EFI_INVALID_PARAMETER is returned.
660 @retval EFI_UNSUPPORTED If DevicePath is not a device path node type that the NVM Express Pass Thru driver
661 supports, then EFI_UNSUPPORTED is returned.
662 @retval EFI_NOT_FOUND If DevicePath is a device path node type that the NVM Express Pass Thru driver
663 supports, but there is not a valid translation from DevicePath to a namespace ID,
664 then EFI_NOT_FOUND is returned.
665 **/
666 EFI_STATUS
667 EFIAPI
668 NvmExpressGetNamespace (
669 IN EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *This,
670 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
671 OUT UINT32 *NamespaceId
672 );
673
674 /**
675 Used to allocate and build a device path node for an NVM Express namespace on an NVM Express controller.
676
677 The EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL.BuildDevicePath() function allocates and builds a single device
678 path node for the NVM Express namespace specified by NamespaceId.
679
680 If the NamespaceId is not valid, then EFI_NOT_FOUND is returned.
681
682 If DevicePath is NULL, then EFI_INVALID_PARAMETER is returned.
683
684 If there are not enough resources to allocate the device path node, then EFI_OUT_OF_RESOURCES is returned.
685
686 Otherwise, DevicePath is allocated with the boot service AllocatePool(), the contents of DevicePath are
687 initialized to describe the NVM Express namespace specified by NamespaceId, and EFI_SUCCESS is returned.
688
689 @param[in] This A pointer to the EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL instance.
690 @param[in] NamespaceId The NVM Express namespace ID for which a device path node is to be
691 allocated and built. Caller must set the NamespaceId to zero if the
692 device path node will contain a valid UUID.
693 @param[in,out] DevicePath A pointer to a single device path node that describes the NVM Express
694 namespace specified by NamespaceId. This function is responsible for
695 allocating the buffer DevicePath with the boot service AllocatePool().
696 It is the caller's responsibility to free DevicePath when the caller
697 is finished with DevicePath.
698 @retval EFI_SUCCESS The device path node that describes the NVM Express namespace specified
699 by NamespaceId was allocated and returned in DevicePath.
700 @retval EFI_NOT_FOUND The NamespaceId is not valid.
701 @retval EFI_INVALID_PARAMETER DevicePath is NULL.
702 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate the DevicePath node.
703
704 **/
705 EFI_STATUS
706 EFIAPI
707 NvmExpressBuildDevicePath (
708 IN EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *This,
709 IN UINT32 NamespaceId,
710 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
711 );
712
713 /**
714 Dump the execution status from a given completion queue entry.
715
716 @param[in] Cq A pointer to the NVME_CQ item.
717
718 **/
719 VOID
720 NvmeDumpStatus (
721 IN NVME_CQ *Cq
722 );
723
724 /**
725 Register the shutdown notification through the ResetNotification protocol.
726
727 Register the shutdown notification when mNvmeControllerNumber increased from 0 to 1.
728 **/
729 VOID
730 NvmeRegisterShutdownNotification (
731 VOID
732 );
733
734 /**
735 Unregister the shutdown notification through the ResetNotification protocol.
736
737 Unregister the shutdown notification when mNvmeControllerNumber decreased from 1 to 0.
738 **/
739 VOID
740 NvmeUnregisterShutdownNotification (
741 VOID
742 );
743
744 #endif