2 Header file for NVMe function definitions
4 Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #ifndef __OPAL_PASSWORD_NVME_MODE_H__
16 #define __OPAL_PASSWORD_NVME_MODE_H__
19 #include "OpalNvmeReg.h"
21 #define NVME_MAX_SECTORS 0x10000
25 #define NVME_ADMIN_QUEUE 0x00
26 #define NVME_IO_QUEUE 0x01
31 #define NORMAL_CMD 0x00
32 #define FUSED_FIRST_CMD 0x01
33 #define FUSED_SECOND_CMD 0x02
40 #define CDW10_VALID 0x01
41 #define CDW11_VALID 0x02
42 #define CDW12_VALID 0x04
43 #define CDW13_VALID 0x08
44 #define CDW14_VALID 0x10
45 #define CDW15_VALID 0x20
53 } NVM_EXPRESS_COMMAND
;
60 } NVM_EXPRESS_RESPONSE
;
63 UINT64 CommandTimeout
;
64 UINT64 TransferBuffer
;
65 UINT32 TransferLength
;
66 UINT64 MetadataBuffer
;
67 UINT32 MetadataLength
;
69 NVM_EXPRESS_COMMAND
*NvmeCmd
;
70 NVM_EXPRESS_RESPONSE
*NvmeResponse
;
71 } NVM_EXPRESS_PASS_THRU_COMMAND_PACKET
;
88 BOOLEAN PollCancellation
;
89 UINT16 NvmeInitWaitTime
;
103 // Pointers to 4kB aligned submission & completion queues.
105 NVME_SQ
*SqBuffer
[NVME_MAX_IO_QUEUES
];
106 NVME_CQ
*CqBuffer
[NVME_MAX_IO_QUEUES
];
107 UINT16 Cid
[NVME_MAX_IO_QUEUES
];
110 // Submission and completion queue indices.
112 NVME_SQTDBL SqTdbl
[NVME_MAX_IO_QUEUES
];
113 NVME_CQHDBL CqHdbl
[NVME_MAX_IO_QUEUES
];
114 UINT8 Pt
[NVME_MAX_IO_QUEUES
];
116 UINTN SqeCount
[NVME_MAX_IO_QUEUES
];
119 // Nvme controller capabilities
124 // pointer to identify controller Data
126 NVME_ADMIN_CONTROLLER_DATA
*ControllerData
;
127 NVME_ADMIN_NAMESPACE_DATA
*NamespaceData
;
133 Transfer MMIO Data to memory.
135 @param[in,out] MemBuffer - Destination: Memory address
136 @param[in] MmioAddr - Source: MMIO address
137 @param[in] Size - Size for read
139 @retval EFI_SUCCESS - MMIO read sucessfully
143 IN OUT VOID
*MemBuffer
,
149 Transfer memory Data to MMIO.
151 @param[in,out] MmioAddr - Destination: MMIO address
152 @param[in] MemBuffer - Source: Memory address
153 @param[in] Size - Size for write
155 @retval EFI_SUCCESS - MMIO write sucessfully
159 IN OUT UINTN MmioAddr
,
165 Transfer memory data to MMIO.
167 @param[in,out] MmioAddr - Destination: MMIO address
168 @param[in] MemBuffer - Source: Memory address
169 @param[in] Size - Size for write
171 @retval EFI_SUCCESS - MMIO write sucessfully
175 IN OUT UINTN MmioAddr
,
181 Transfer MMIO data to memory.
183 @param[in,out] MemBuffer - Destination: Memory address
184 @param[in] MmioAddr - Source: MMIO address
185 @param[in] Size - Size for read
187 @retval EFI_SUCCESS - MMIO read sucessfully
191 IN OUT VOID
*MemBuffer
,
197 Allocate transfer-related Data struct which is used at Nvme.
199 @param[in, out] Nvme The pointer to the NVME_CONTEXT Data structure.
201 @retval EFI_OUT_OF_RESOURCE No enough resource.
202 @retval EFI_SUCCESS Successful to allocate resource.
207 NvmeAllocateResource (
208 IN OUT NVME_CONTEXT
*Nvme
212 Free allocated transfer-related Data struct which is used at NVMe.
214 @param[in, out] Nvme The pointer to the NVME_CONTEXT Data structure.
220 IN OUT NVME_CONTEXT
*Nvme
224 Sends an NVM Express Command Packet to an NVM Express controller or namespace. This function supports
225 both blocking I/O and nonblocking I/O. The blocking I/O functionality is required, and the nonblocking
226 I/O functionality is optional.
228 @param[in] Nvme - The pointer to the NVME_CONTEXT Data structure.
229 @param[in] NamespaceId - Is a 32 bit Namespace ID to which the Express HCI command packet will be sent.
230 A Value of 0 denotes the NVM Express controller, a Value of all 0FFh in the namespace
231 ID specifies that the command packet should be sent to all valid namespaces.
232 @param[in] NamespaceUuid - Is a 64 bit Namespace UUID to which the Express HCI command packet will be sent.
233 A Value of 0 denotes the NVM Express controller, a Value of all 0FFh in the namespace
234 UUID specifies that the command packet should be sent to all valid namespaces.
235 @param[in,out] Packet - A pointer to the NVM Express HCI Command Packet to send to the NVMe namespace specified
238 @retval EFI_SUCCESS - The NVM Express Command Packet was sent by the host. TransferLength bytes were transferred
239 to, or from DataBuffer.
240 @retval EFI_NOT_READY - The NVM Express Command Packet could not be sent because the controller is not ready. The caller
241 may retry again later.
242 @retval EFI_DEVICE_ERROR - A device error occurred while attempting to send the NVM Express Command Packet.
243 @retval EFI_INVALID_PARAMETER - Namespace, or the contents of NVM_EXPRESS_PASS_THRU_COMMAND_PACKET are invalid. The NVM
244 Express Command Packet was not sent, so no additional status information is available.
245 @retval EFI_UNSUPPORTED - The command described by the NVM Express Command Packet is not supported by the host adapter.
246 The NVM Express Command Packet was not sent, so no additional status information is available.
247 @retval EFI_TIMEOUT - A timeout occurred while waiting for the NVM Express Command Packet to execute.
252 IN NVME_CONTEXT
*Nvme
,
253 IN UINT32 NamespaceId
,
254 IN UINT64 NamespaceUuid
,
255 IN OUT NVM_EXPRESS_PASS_THRU_COMMAND_PACKET
*Packet
259 Waits until all NVME commands completed.
261 @param[in] Nvme - The pointer to the NVME_CONTEXT Data structure.
262 @param[in] Qid - Queue index
264 @retval EFI_SUCCESS - All NVME commands have completed
265 @retval EFI_TIMEOUT - Timeout occured
266 @retval EFI_NOT_READY - Not all NVME commands have completed
267 @retval others - Error occurred on device side.
270 NvmeWaitAllComplete (
271 IN NVME_CONTEXT
*Nvme
,
276 Initialize the Nvm Express controller.
278 @param[in] Nvme - The pointer to the NVME_CONTEXT Data structure.
280 @retval EFI_SUCCESS - The NVM Express Controller is initialized successfully.
281 @retval Others - A device error occurred while initializing the controller.
286 IN NVME_CONTEXT
*Nvme
290 Un-initialize the Nvm Express controller.
292 @param[in] Nvme - The pointer to the NVME_CONTEXT Data structure.
294 @retval EFI_SUCCESS - The NVM Express Controller is un-initialized successfully.
295 @retval Others - A device error occurred while un-initializing the controller.
300 IN NVME_CONTEXT
*Nvme
304 Check whether there are available command slots.
306 @param[in] Nvme - The pointer to the NVME_CONTEXT Data structure.
307 @param[in] Qid - Queue index
309 @retval EFI_SUCCESS - Available command slot is found
310 @retval EFI_NOT_READY - No available command slot is found
311 @retval EFI_DEVICE_ERROR - Error occurred on device side.
316 IN NVME_CONTEXT
*Nvme
,
321 Check whether all command slots are clean.
323 @param[in] Nvme - The pointer to the NVME_CONTEXT Data structure.
324 @param[in] Qid - Queue index
326 @retval EFI_SUCCESS - All command slots are clean
327 @retval EFI_NOT_READY - Not all command slots are clean
328 @retval EFI_DEVICE_ERROR - Error occurred on device side.
332 NvmeIsAllCmdSlotClean (
333 IN NVME_CONTEXT
*Nvme
,
338 Read sector Data from the NVMe device.
340 @param[in] Nvme - The pointer to the NVME_CONTEXT Data structure.
341 @param[in,out] Buffer - The Buffer used to store the Data read from the device.
342 @param[in] Lba - The start block number.
343 @param[in] Blocks - Total block number to be read.
345 @retval EFI_SUCCESS - Datum are read from the device.
346 @retval Others - Fail to read all the datum.
351 IN NVME_CONTEXT
*Nvme
,
352 IN OUT UINT64 Buffer
,
358 Write sector Data to the NVMe device.
360 @param[in] Nvme - The pointer to the NVME_CONTEXT Data structure.
361 @param[in] Buffer - The Buffer to be written into the device.
362 @param[in] Lba - The start block number.
363 @param[in] Blocks - Total block number to be written.
365 @retval EFI_SUCCESS - Datum are written into the Buffer.
366 @retval Others - Fail to write all the datum.
371 IN NVME_CONTEXT
*Nvme
,
378 Flushes all modified Data to the device.
380 @param[in] Nvme - The pointer to the NVME_CONTEXT Data structure.
382 @retval EFI_SUCCESS - Datum are written into the Buffer.
383 @retval Others - Fail to write all the datum.
388 IN NVME_CONTEXT
*Nvme
392 Read some blocks from the device.
394 @param[in] Nvme - The pointer to the NVME_CONTEXT Data structure.
395 @param[out] Buffer - The Buffer used to store the Data read from the device.
396 @param[in] Lba - The start block number.
397 @param[in] Blocks - Total block number to be read.
399 @retval EFI_SUCCESS - Datum are read from the device.
400 @retval Others - Fail to read all the datum.
405 IN NVME_CONTEXT
*Nvme
,
412 Write some blocks to the device.
414 @param[in] Nvme - The pointer to the NVME_CONTEXT Data structure.
415 @param[in] Buffer - The Buffer to be written into the device.
416 @param[in] Lba - The start block number.
417 @param[in] Blocks - Total block number to be written.
419 @retval EFI_SUCCESS - Datum are written into the Buffer.
420 @retval Others - Fail to write all the datum.
425 IN NVME_CONTEXT
*Nvme
,
432 Security send and receive commands.
434 @param[in] Nvme - The pointer to the NVME_CONTEXT Data structure.
435 @param[in] SendCommand - The flag to indicate the command type, TRUE for Send command and FALSE for receive command
436 @param[in] SecurityProtocol - Security Protocol
437 @param[in] SpSpecific - Security Protocol Specific
438 @param[in] TransferLength - Transfer Length of Buffer (in bytes) - always a multiple of 512
439 @param[in,out] TransferBuffer - Address of Data to transfer
441 @return EFI_SUCCESS - Successfully create io submission queue.
442 @return others - Fail to send/receive commands.
446 NvmeSecuritySendReceive (
447 IN NVME_CONTEXT
*Nvme
,
448 IN BOOLEAN SendCommand
,
449 IN UINT8 SecurityProtocol
,
450 IN UINT16 SpSpecific
,
451 IN UINTN TransferLength
,
452 IN OUT VOID
*TransferBuffer