2 Header file for NVMe function definitions
4 Copyright (c) 2016, 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
;
87 BOOLEAN PollCancellation
;
88 UINT16 NvmeInitWaitTime
;
102 // Pointers to 4kB aligned submission & completion queues.
104 NVME_SQ
*SqBuffer
[NVME_MAX_IO_QUEUES
];
105 NVME_CQ
*CqBuffer
[NVME_MAX_IO_QUEUES
];
106 UINT16 Cid
[NVME_MAX_IO_QUEUES
];
109 // Submission and completion queue indices.
111 NVME_SQTDBL SqTdbl
[NVME_MAX_IO_QUEUES
];
112 NVME_CQHDBL CqHdbl
[NVME_MAX_IO_QUEUES
];
113 UINT8 Pt
[NVME_MAX_IO_QUEUES
];
115 UINTN SqeCount
[NVME_MAX_IO_QUEUES
];
118 // Nvme controller capabilities
123 // pointer to identify controller Data
125 NVME_ADMIN_CONTROLLER_DATA
*ControllerData
;
126 NVME_ADMIN_NAMESPACE_DATA
*NamespaceData
;
132 Transfer MMIO Data to memory.
134 @param[in,out] MemBuffer - Destination: Memory address
135 @param[in] MmioAddr - Source: MMIO address
136 @param[in] Size - Size for read
138 @retval EFI_SUCCESS - MMIO read sucessfully
142 IN OUT VOID
*MemBuffer
,
148 Transfer memory Data to MMIO.
150 @param[in,out] MmioAddr - Destination: MMIO address
151 @param[in] MemBuffer - Source: Memory address
152 @param[in] Size - Size for write
154 @retval EFI_SUCCESS - MMIO write sucessfully
158 IN OUT UINTN MmioAddr
,
164 Transfer memory data to MMIO.
166 @param[in,out] MmioAddr - Destination: MMIO address
167 @param[in] MemBuffer - Source: Memory address
168 @param[in] Size - Size for write
170 @retval EFI_SUCCESS - MMIO write sucessfully
174 IN OUT UINTN MmioAddr
,
180 Transfer MMIO data to memory.
182 @param[in,out] MemBuffer - Destination: Memory address
183 @param[in] MmioAddr - Source: MMIO address
184 @param[in] Size - Size for read
186 @retval EFI_SUCCESS - MMIO read sucessfully
190 IN OUT VOID
*MemBuffer
,
196 Allocate transfer-related Data struct which is used at Nvme.
198 @param[in] ImageHandle Image handle for this driver image
199 @param[in] Nvme The pointer to the NVME_CONTEXT Data structure.
201 @retval EFI_OUT_OF_RESOURCE The allocation is failure.
202 @retval EFI_SUCCESS Successful to allocate memory.
207 NvmeAllocateResource (
208 IN EFI_HANDLE ImageHandle
,
209 IN NVME_CONTEXT
*Nvme
213 Free allocated transfer-related Data struct which is used at NVMe.
215 @param[in] Nvme The pointer to the NVME_CONTEXT Data structure.
221 IN NVME_CONTEXT
*Nvme
225 Sends an NVM Express Command Packet to an NVM Express controller or namespace. This function supports
226 both blocking I/O and nonblocking I/O. The blocking I/O functionality is required, and the nonblocking
227 I/O functionality is optional.
229 @param[in] Nvme - The pointer to the NVME_CONTEXT Data structure.
230 @param[in] NamespaceId - Is a 32 bit Namespace ID to which the Express HCI command packet will be sent.
231 A Value of 0 denotes the NVM Express controller, a Value of all 0FFh in the namespace
232 ID specifies that the command packet should be sent to all valid namespaces.
233 @param[in] NamespaceUuid - Is a 64 bit Namespace UUID to which the Express HCI command packet will be sent.
234 A Value of 0 denotes the NVM Express controller, a Value of all 0FFh in the namespace
235 UUID specifies that the command packet should be sent to all valid namespaces.
236 @param[in,out] Packet - A pointer to the NVM Express HCI Command Packet to send to the NVMe namespace specified
239 @retval EFI_SUCCESS - The NVM Express Command Packet was sent by the host. TransferLength bytes were transferred
240 to, or from DataBuffer.
241 @retval EFI_NOT_READY - The NVM Express Command Packet could not be sent because the controller is not ready. The caller
242 may retry again later.
243 @retval EFI_DEVICE_ERROR - A device error occurred while attempting to send the NVM Express Command Packet.
244 @retval EFI_INVALID_PARAMETER - Namespace, or the contents of NVM_EXPRESS_PASS_THRU_COMMAND_PACKET are invalid. The NVM
245 Express Command Packet was not sent, so no additional status information is available.
246 @retval EFI_UNSUPPORTED - The command described by the NVM Express Command Packet is not supported by the host adapter.
247 The NVM Express Command Packet was not sent, so no additional status information is available.
248 @retval EFI_TIMEOUT - A timeout occurred while waiting for the NVM Express Command Packet to execute.
253 IN NVME_CONTEXT
*Nvme
,
254 IN UINT32 NamespaceId
,
255 IN UINT64 NamespaceUuid
,
256 IN OUT NVM_EXPRESS_PASS_THRU_COMMAND_PACKET
*Packet
260 Waits until all NVME commands completed.
262 @param[in] Nvme - The pointer to the NVME_CONTEXT Data structure.
263 @param[in] Qid - Queue index
265 @retval EFI_SUCCESS - All NVME commands have completed
266 @retval EFI_TIMEOUT - Timeout occured
267 @retval EFI_NOT_READY - Not all NVME commands have completed
268 @retval others - Error occurred on device side.
271 NvmeWaitAllComplete (
272 IN NVME_CONTEXT
*Nvme
,
277 Initialize the Nvm Express controller.
279 @param[in] Nvme - The pointer to the NVME_CONTEXT Data structure.
281 @retval EFI_SUCCESS - The NVM Express Controller is initialized successfully.
282 @retval Others - A device error occurred while initializing the controller.
287 IN NVME_CONTEXT
*Nvme
291 Un-initialize the Nvm Express controller.
293 @param[in] Nvme - The pointer to the NVME_CONTEXT Data structure.
295 @retval EFI_SUCCESS - The NVM Express Controller is un-initialized successfully.
296 @retval Others - A device error occurred while un-initializing the controller.
301 IN NVME_CONTEXT
*Nvme
305 Check whether there are available command slots.
307 @param[in] Nvme - The pointer to the NVME_CONTEXT Data structure.
308 @param[in] Qid - Queue index
310 @retval EFI_SUCCESS - Available command slot is found
311 @retval EFI_NOT_READY - No available command slot is found
312 @retval EFI_DEVICE_ERROR - Error occurred on device side.
317 IN NVME_CONTEXT
*Nvme
,
322 Check whether all command slots are clean.
324 @param[in] Nvme - The pointer to the NVME_CONTEXT Data structure.
325 @param[in] Qid - Queue index
327 @retval EFI_SUCCESS - All command slots are clean
328 @retval EFI_NOT_READY - Not all command slots are clean
329 @retval EFI_DEVICE_ERROR - Error occurred on device side.
333 NvmeIsAllCmdSlotClean (
334 IN NVME_CONTEXT
*Nvme
,
339 Read sector Data from the NVMe device.
341 @param[in] Nvme - The pointer to the NVME_CONTEXT Data structure.
342 @param[in,out] Buffer - The Buffer used to store the Data read from the device.
343 @param[in] Lba - The start block number.
344 @param[in] Blocks - Total block number to be read.
346 @retval EFI_SUCCESS - Datum are read from the device.
347 @retval Others - Fail to read all the datum.
352 IN NVME_CONTEXT
*Nvme
,
353 IN OUT UINT64 Buffer
,
359 Write sector Data to the NVMe device.
361 @param[in] Nvme - The pointer to the NVME_CONTEXT Data structure.
362 @param[in] Buffer - The Buffer to be written into the device.
363 @param[in] Lba - The start block number.
364 @param[in] Blocks - Total block number to be written.
366 @retval EFI_SUCCESS - Datum are written into the Buffer.
367 @retval Others - Fail to write all the datum.
372 IN NVME_CONTEXT
*Nvme
,
379 Flushes all modified Data to the device.
381 @param[in] Nvme - The pointer to the NVME_CONTEXT Data structure.
383 @retval EFI_SUCCESS - Datum are written into the Buffer.
384 @retval Others - Fail to write all the datum.
389 IN NVME_CONTEXT
*Nvme
393 Read some blocks from the device.
395 @param[in] Nvme - The pointer to the NVME_CONTEXT Data structure.
396 @param[out] Buffer - The Buffer used to store the Data read from the device.
397 @param[in] Lba - The start block number.
398 @param[in] Blocks - Total block number to be read.
400 @retval EFI_SUCCESS - Datum are read from the device.
401 @retval Others - Fail to read all the datum.
406 IN NVME_CONTEXT
*Nvme
,
413 Write some blocks to the device.
415 @param[in] Nvme - The pointer to the NVME_CONTEXT Data structure.
416 @param[in] Buffer - The Buffer to be written into the device.
417 @param[in] Lba - The start block number.
418 @param[in] Blocks - Total block number to be written.
420 @retval EFI_SUCCESS - Datum are written into the Buffer.
421 @retval Others - Fail to write all the datum.
426 IN NVME_CONTEXT
*Nvme
,
433 Security send and receive commands.
435 @param[in] Nvme - The pointer to the NVME_CONTEXT Data structure.
436 @param[in] SendCommand - The flag to indicate the command type, TRUE for Send command and FALSE for receive command
437 @param[in] SecurityProtocol - Security Protocol
438 @param[in] SpSpecific - Security Protocol Specific
439 @param[in] TransferLength - Transfer Length of Buffer (in bytes) - always a multiple of 512
440 @param[in,out] TransferBuffer - Address of Data to transfer
442 @return EFI_SUCCESS - Successfully create io submission queue.
443 @return others - Fail to send/receive commands.
447 NvmeSecuritySendReceive (
448 IN NVME_CONTEXT
*Nvme
,
449 IN BOOLEAN SendCommand
,
450 IN UINT8 SecurityProtocol
,
451 IN UINT16 SpSpecific
,
452 IN UINTN TransferLength
,
453 IN OUT VOID
*TransferBuffer