TianoCore EDK2 master
Loading...
Searching...
No Matches
NvmExpress.h
Go to the documentation of this file.
1
12#ifndef _EFI_NVM_EXPRESS_H_
13#define _EFI_NVM_EXPRESS_H_
14
15#include <Uefi.h>
16
19
24#include <Protocol/DevicePath.h>
25#include <Protocol/PciIo.h>
27#include <Protocol/BlockIo.h>
28#include <Protocol/BlockIo2.h>
29#include <Protocol/DiskInfo.h>
34
35#include <Library/BaseLib.h>
37#include <Library/DebugLib.h>
38#include <Library/PrintLib.h>
39#include <Library/UefiLib.h>
45
46#include <Guid/NVMeEventGroup.h>
47
50
51#include "NvmExpressBlockIo.h"
52#include "NvmExpressDiskInfo.h"
53#include "NvmExpressHci.h"
55
56extern EFI_DRIVER_BINDING_PROTOCOL gNvmExpressDriverBinding;
57extern EFI_COMPONENT_NAME_PROTOCOL gNvmExpressComponentName;
58extern EFI_COMPONENT_NAME2_PROTOCOL gNvmExpressComponentName2;
59extern EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL gNvmExpressDriverSupportedEfiVersion;
60
61#define PCI_CLASS_MASS_STORAGE_NVM 0x08 // mass storage sub-class non-volatile memory.
62#define PCI_IF_NVMHCI 0x02 // mass storage programming interface NVMHCI.
63
64#define NVME_ASQ_SIZE 1 // Number of admin submission queue entries, which is 0-based
65#define NVME_ACQ_SIZE 1 // Number of admin completion queue entries, which is 0-based
66
67#define NVME_CSQ_SIZE 1 // Number of I/O submission queue entries, which is 0-based
68#define NVME_CCQ_SIZE 1 // Number of I/O completion queue entries, which is 0-based
69
70//
71// Number of asynchronous I/O submission queue entries, which is 0-based.
72// The asynchronous I/O submission queue size is 4kB in total.
73//
74#define NVME_ASYNC_CSQ_SIZE 63
75//
76// Number of asynchronous I/O completion queue entries, which is 0-based.
77// The asynchronous I/O completion queue size is 4kB in total.
78//
79#define NVME_ASYNC_CCQ_SIZE 255
80
81#define NVME_MAX_QUEUES 3 // Number of queues supported by the driver
82
83//
84// FormatNVM Admin Command LBA Format (LBAF) Mask
85//
86#define NVME_LBA_FORMATNVM_LBAF_MASK 0xF
87
88//
89// NVMe Completion Queue Entry Bits, Fields, Masks
90//
91#define NVME_CQE_STATUS_FIELD_MASK 0xFFFF0000
92#define NVME_CQE_STATUS_FIELD_OFFSET 16
93#define NVME_CQE_STATUS_FIELD_SCT_MASK 0x0E00
94#define NVME_CQE_STATUS_FIELD_SCT_OFFSET 0x9
95#define NVME_CQE_STATUS_FIELD_SC_MASK 0x1FE
96#define NVME_CQE_STATUS_FIELD_SC_OFFSET 0x01
97#define NVME_CQE_SCT_GENERIC_CMD_STATUS 0x0
98#define NVME_CQE_SCT_CMD_SPECIFIC_STATUS 0x1
99#define NVME_CQE_SCT_MEDIA_DATA_INTEGRITY_ERRORS_STATUS 0x2
100#define NVME_CQE_SCT_PATH_RELATED_STATUS 0x3
101#define NVME_CQE_SC_SUCCESSFUL_COMPLETION 0x00
102#define NVME_CQE_SC_INVALID_CMD_OPCODE 0x01
103#define NVME_CQE_SC_INVALID_FIELD_IN_CMD 0x02
104
105#define NVME_ALL_NAMESPACES 0xFFFFFFFF
106
107#define NVME_CONTROLLER_ID 0
108
109//
110// Time out value for Nvme transaction execution
111//
112#define NVME_GENERIC_TIMEOUT EFI_TIMER_PERIOD_SECONDS (5)
113
114//
115// Nvme async transfer timer interval, set by experience.
116//
117#define NVME_HC_ASYNC_TIMER EFI_TIMER_PERIOD_MILLISECONDS (1)
118
119//
120// Unique signature for private data structure.
121//
122#define NVME_CONTROLLER_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('N','V','M','E')
123
124//
125// Nvme private data structure.
126//
128 UINT32 Signature;
129
130 EFI_HANDLE ControllerHandle;
131 EFI_HANDLE ImageHandle;
132 EFI_HANDLE DriverBindingHandle;
133
134 EFI_PCI_IO_PROTOCOL *PciIo;
135 UINT64 PciAttributes;
136
137 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
138
141
142 //
143 // pointer to identify controller data
144 //
145 NVME_ADMIN_CONTROLLER_DATA *ControllerData;
146
147 //
148 // 6 x 4kB aligned buffers will be carved out of this buffer.
149 // 1st 4kB boundary is the start of the admin submission queue.
150 // 2nd 4kB boundary is the start of the admin completion queue.
151 // 3rd 4kB boundary is the start of I/O submission queue #1.
152 // 4th 4kB boundary is the start of I/O completion queue #1.
153 // 5th 4kB boundary is the start of I/O submission queue #2.
154 // 6th 4kB boundary is the start of I/O completion queue #2.
155 //
156 UINT8 *Buffer;
157 UINT8 *BufferPciAddr;
158
159 //
160 // Pointers to 4kB aligned submission & completion queues.
161 //
162 NVME_SQ *SqBuffer[NVME_MAX_QUEUES];
163 NVME_CQ *CqBuffer[NVME_MAX_QUEUES];
164 NVME_SQ *SqBufferPciAddr[NVME_MAX_QUEUES];
165 NVME_CQ *CqBufferPciAddr[NVME_MAX_QUEUES];
166
167 //
168 // Submission and completion queue indices.
169 //
170 NVME_SQTDBL SqTdbl[NVME_MAX_QUEUES];
171 NVME_CQHDBL CqHdbl[NVME_MAX_QUEUES];
172 UINT16 AsyncSqHead;
173
174 //
175 // Flag to indicate internal IO queue creation.
176 //
177 BOOLEAN CreateIoQueue;
178
179 UINT8 Pt[NVME_MAX_QUEUES];
180 UINT16 Cid[NVME_MAX_QUEUES];
181
182 //
183 // Nvme controller capabilities
184 //
185 NVME_CAP Cap;
186
187 VOID *Mapping;
188
189 //
190 // For Non-blocking operations.
191 //
192 EFI_EVENT TimerEvent;
193 LIST_ENTRY AsyncPassThruQueue;
194 LIST_ENTRY UnsubmittedSubtasks;
195};
196
197#define NVME_CONTROLLER_PRIVATE_DATA_FROM_PASS_THRU(a) \
198 CR (a, \
199 NVME_CONTROLLER_PRIVATE_DATA, \
200 Passthru, \
201 NVME_CONTROLLER_PRIVATE_DATA_SIGNATURE \
202 )
203
204//
205// Unique signature for private data structure.
206//
207#define NVME_DEVICE_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('X','S','S','D')
208
209//
210// Nvme device private data structure
211//
213 UINT32 Signature;
214
215 EFI_HANDLE DeviceHandle;
216 EFI_HANDLE ControllerHandle;
217 EFI_HANDLE DriverBindingHandle;
218
219 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
220
221 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
222
223 UINT32 NamespaceId;
224 UINT64 NamespaceUuid;
225
226 EFI_BLOCK_IO_MEDIA Media;
227 EFI_BLOCK_IO_PROTOCOL BlockIo;
228 EFI_BLOCK_IO2_PROTOCOL BlockIo2;
229 EFI_DISK_INFO_PROTOCOL DiskInfo;
231
232 MEDIA_SANITIZE_PROTOCOL MediaSanitize;
233
234 LIST_ENTRY AsyncQueue;
235
236 EFI_LBA NumBlocks;
237
238 CHAR16 ModelName[80];
239 NVME_ADMIN_NAMESPACE_DATA NamespaceData;
240
242};
243
244//
245// Statments to retrieve the private data from produced protocols.
246//
247#define NVME_DEVICE_PRIVATE_DATA_FROM_BLOCK_IO(a) \
248 CR (a, \
249 NVME_DEVICE_PRIVATE_DATA, \
250 BlockIo, \
251 NVME_DEVICE_PRIVATE_DATA_SIGNATURE \
252 )
253
254#define NVME_DEVICE_PRIVATE_DATA_FROM_BLOCK_IO2(a) \
255 CR (a, \
256 NVME_DEVICE_PRIVATE_DATA, \
257 BlockIo2, \
258 NVME_DEVICE_PRIVATE_DATA_SIGNATURE \
259 )
260
261#define NVME_DEVICE_PRIVATE_DATA_FROM_DISK_INFO(a) \
262 CR (a, \
263 NVME_DEVICE_PRIVATE_DATA, \
264 DiskInfo, \
265 NVME_DEVICE_PRIVATE_DATA_SIGNATURE \
266 )
267
268#define NVME_DEVICE_PRIVATE_DATA_FROM_STORAGE_SECURITY(a) \
269 CR (a, \
270 NVME_DEVICE_PRIVATE_DATA, \
271 StorageSecurity, \
272 NVME_DEVICE_PRIVATE_DATA_SIGNATURE \
273 )
274
275#define NVME_DEVICE_PRIVATE_DATA_FROM_MEDIA_SANITIZE(a) \
276 CR (a, \
277 NVME_DEVICE_PRIVATE_DATA, \
278 MediaSanitize, \
279 NVME_DEVICE_PRIVATE_DATA_SIGNATURE \
280 )
281
282//
283// Nvme block I/O 2 request.
284//
285#define NVME_BLKIO2_REQUEST_SIGNATURE SIGNATURE_32 ('N', 'B', '2', 'R')
286
287typedef struct {
288 UINT32 Signature;
289 LIST_ENTRY Link;
290
291 EFI_BLOCK_IO2_TOKEN *Token;
292 UINTN UnsubmittedSubtaskNum;
293 BOOLEAN LastSubtaskSubmitted;
294 //
295 // The queue for Nvme read/write sub-tasks of a BlockIo2 request.
296 //
297 LIST_ENTRY SubtasksQueue;
299
300#define NVME_BLKIO2_REQUEST_FROM_LINK(a) \
301 CR (a, NVME_BLKIO2_REQUEST, Link, NVME_BLKIO2_REQUEST_SIGNATURE)
302
303#define NVME_BLKIO2_SUBTASK_SIGNATURE SIGNATURE_32 ('N', 'B', '2', 'S')
304
305typedef struct {
306 UINT32 Signature;
307 LIST_ENTRY Link;
308
309 BOOLEAN IsLast;
310 UINT32 NamespaceId;
311 EFI_EVENT Event;
313 //
314 // The BlockIo2 request this subtask belongs to
315 //
316 NVME_BLKIO2_REQUEST *BlockIo2Request;
318
319#define NVME_BLKIO2_SUBTASK_FROM_LINK(a) \
320 CR (a, NVME_BLKIO2_SUBTASK, Link, NVME_BLKIO2_SUBTASK_SIGNATURE)
321
322//
323// Nvme asynchronous passthru request.
324//
325#define NVME_PASS_THRU_ASYNC_REQ_SIG SIGNATURE_32 ('N', 'P', 'A', 'R')
326
327typedef struct {
328 UINT32 Signature;
329 LIST_ENTRY Link;
330
332 UINT16 CommandId;
333 VOID *MapPrpList;
334 UINTN PrpListNo;
335 VOID *PrpListHost;
336 VOID *MapData;
337 VOID *MapMeta;
338 EFI_EVENT CallerEvent;
340
341#define NVME_PASS_THRU_ASYNC_REQ_FROM_THIS(a) \
342 CR (a, \
343 NVME_PASS_THRU_ASYNC_REQ, \
344 Link, \
345 NVME_PASS_THRU_ASYNC_REQ_SIG \
346 )
347
388EFIAPI
391 IN CHAR8 *Language,
392 OUT CHAR16 **DriverName
393 );
394
464EFIAPI
467 IN EFI_HANDLE ControllerHandle,
468 IN EFI_HANDLE ChildHandle OPTIONAL,
469 IN CHAR8 *Language,
470 OUT CHAR16 **ControllerName
471 );
472
516EFIAPI
519 IN EFI_HANDLE Controller,
520 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
521 );
522
559EFIAPI
562 IN EFI_HANDLE Controller,
563 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
564 );
565
593EFIAPI
596 IN EFI_HANDLE Controller,
597 IN UINTN NumberOfChildren,
598 IN EFI_HANDLE *ChildHandleBuffer
599 );
600
632EFIAPI
635 IN UINT32 NamespaceId,
637 IN EFI_EVENT Event OPTIONAL
638 );
639
674EFIAPI
677 IN OUT UINT32 *NamespaceId
678 );
679
705EFIAPI
708 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
709 OUT UINT32 *NamespaceId
710 );
711
744EFIAPI
747 IN UINT32 NamespaceId,
748 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
749 );
750
757VOID
759 IN NVME_CQ *Cq
760 );
761
767VOID
769 VOID
770 );
771
777VOID
779 VOID
780 );
781
782#endif
UINT64 UINTN
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
EFI_STATUS EFIAPI NvmExpressComponentNameGetControllerName(IN EFI_COMPONENT_NAME_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ChildHandle OPTIONAL, IN CHAR8 *Language, OUT CHAR16 **ControllerName)
EFI_STATUS EFIAPI NvmExpressPassThru(IN EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *This, IN UINT32 NamespaceId, IN OUT EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET *Packet, IN EFI_EVENT Event OPTIONAL)
EFI_STATUS EFIAPI NvmExpressDriverBindingStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
Definition: NvmExpress.c:946
EFI_STATUS EFIAPI NvmExpressGetNamespace(IN EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *This, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, OUT UINT32 *NamespaceId)
EFI_STATUS EFIAPI NvmExpressBuildDevicePath(IN EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *This, IN UINT32 NamespaceId, IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath)
VOID NvmeRegisterShutdownNotification(VOID)
EFI_STATUS EFIAPI NvmExpressComponentNameGetDriverName(IN EFI_COMPONENT_NAME_PROTOCOL *This, IN CHAR8 *Language, OUT CHAR16 **DriverName)
Definition: ComponentName.c:81
EFI_STATUS EFIAPI NvmExpressDriverBindingSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
Definition: NvmExpress.c:792
VOID NvmeDumpStatus(IN NVME_CQ *Cq)
EFI_STATUS EFIAPI NvmExpressDriverBindingStop(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer)
Definition: NvmExpress.c:1236
EFI_STATUS EFIAPI NvmExpressGetNextNamespace(IN EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *This, IN OUT UINT32 *NamespaceId)
VOID NvmeUnregisterShutdownNotification(VOID)
UINT64 EFI_LBA
Definition: UefiBaseType.h:45
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
Definition: Nvme.h:55
Definition: Nvme.h:901
Definition: Nvme.h:865