4 #include "block/nvme.h"
7 #define NVME_MAX_NAMESPACES 256
9 #define NVME_DEFAULT_ZONE_SIZE (128 * MiB)
10 #define NVME_DEFAULT_MAX_ZA_SIZE (128 * KiB)
12 typedef struct NvmeParams
{
14 uint32_t num_queues
; /* deprecated since 5.1 */
15 uint32_t max_ioqpairs
;
19 uint32_t aer_max_queued
;
26 typedef struct NvmeAsyncEvent
{
27 QTAILQ_ENTRY(NvmeAsyncEvent
) entry
;
31 typedef struct NvmeRequest
{
32 struct NvmeSQueue
*sq
;
33 struct NvmeNamespace
*ns
;
42 QTAILQ_ENTRY(NvmeRequest
)entry
;
45 static inline const char *nvme_adm_opc_str(uint8_t opc
)
48 case NVME_ADM_CMD_DELETE_SQ
: return "NVME_ADM_CMD_DELETE_SQ";
49 case NVME_ADM_CMD_CREATE_SQ
: return "NVME_ADM_CMD_CREATE_SQ";
50 case NVME_ADM_CMD_GET_LOG_PAGE
: return "NVME_ADM_CMD_GET_LOG_PAGE";
51 case NVME_ADM_CMD_DELETE_CQ
: return "NVME_ADM_CMD_DELETE_CQ";
52 case NVME_ADM_CMD_CREATE_CQ
: return "NVME_ADM_CMD_CREATE_CQ";
53 case NVME_ADM_CMD_IDENTIFY
: return "NVME_ADM_CMD_IDENTIFY";
54 case NVME_ADM_CMD_ABORT
: return "NVME_ADM_CMD_ABORT";
55 case NVME_ADM_CMD_SET_FEATURES
: return "NVME_ADM_CMD_SET_FEATURES";
56 case NVME_ADM_CMD_GET_FEATURES
: return "NVME_ADM_CMD_GET_FEATURES";
57 case NVME_ADM_CMD_ASYNC_EV_REQ
: return "NVME_ADM_CMD_ASYNC_EV_REQ";
58 default: return "NVME_ADM_CMD_UNKNOWN";
62 static inline const char *nvme_io_opc_str(uint8_t opc
)
65 case NVME_CMD_FLUSH
: return "NVME_NVM_CMD_FLUSH";
66 case NVME_CMD_WRITE
: return "NVME_NVM_CMD_WRITE";
67 case NVME_CMD_READ
: return "NVME_NVM_CMD_READ";
68 case NVME_CMD_COMPARE
: return "NVME_NVM_CMD_COMPARE";
69 case NVME_CMD_WRITE_ZEROES
: return "NVME_NVM_CMD_WRITE_ZEROES";
70 case NVME_CMD_DSM
: return "NVME_NVM_CMD_DSM";
71 case NVME_CMD_ZONE_MGMT_SEND
: return "NVME_ZONED_CMD_MGMT_SEND";
72 case NVME_CMD_ZONE_MGMT_RECV
: return "NVME_ZONED_CMD_MGMT_RECV";
73 case NVME_CMD_ZONE_APPEND
: return "NVME_ZONED_CMD_ZONE_APPEND";
74 default: return "NVME_NVM_CMD_UNKNOWN";
78 typedef struct NvmeSQueue
{
79 struct NvmeCtrl
*ctrl
;
88 QTAILQ_HEAD(, NvmeRequest
) req_list
;
89 QTAILQ_HEAD(, NvmeRequest
) out_req_list
;
90 QTAILQ_ENTRY(NvmeSQueue
) entry
;
93 typedef struct NvmeCQueue
{
94 struct NvmeCtrl
*ctrl
;
104 QTAILQ_HEAD(, NvmeSQueue
) sq_list
;
105 QTAILQ_HEAD(, NvmeRequest
) req_list
;
108 #define TYPE_NVME_BUS "nvme-bus"
109 #define NVME_BUS(obj) OBJECT_CHECK(NvmeBus, (obj), TYPE_NVME_BUS)
111 typedef struct NvmeBus
{
115 #define TYPE_NVME "nvme"
117 OBJECT_CHECK(NvmeCtrl, (obj), TYPE_NVME)
119 typedef struct NvmeFeatureVal
{
121 uint16_t temp_thresh_hi
;
122 uint16_t temp_thresh_low
;
124 uint32_t async_config
;
127 typedef struct NvmeCtrl
{
128 PCIDevice parent_obj
;
139 uint16_t max_prp_ents
;
143 uint32_t num_namespaces
;
145 uint8_t outstanding_aers
;
147 uint64_t host_timestamp
; /* Timestamp sent by the host */
148 uint64_t timestamp_set_qemu_clock_ms
; /* QEMU clock time */
149 uint64_t starttime_ms
;
150 uint16_t temperature
;
151 uint8_t smart_critical_warning
;
161 HostMemoryBackend
*dev
;
167 NvmeRequest
**aer_reqs
;
168 QTAILQ_HEAD(, NvmeAsyncEvent
) aer_queue
;
173 NvmeNamespace
namespace;
174 NvmeNamespace
*namespaces
[NVME_MAX_NAMESPACES
];
180 NvmeFeatureVal features
;
183 static inline NvmeNamespace
*nvme_ns(NvmeCtrl
*n
, uint32_t nsid
)
185 if (!nsid
|| nsid
> n
->num_namespaces
) {
189 return n
->namespaces
[nsid
- 1];
192 static inline NvmeCQueue
*nvme_cq(NvmeRequest
*req
)
194 NvmeSQueue
*sq
= req
->sq
;
195 NvmeCtrl
*n
= sq
->ctrl
;
197 return n
->cq
[sq
->cqid
];
200 static inline NvmeCtrl
*nvme_ctrl(NvmeRequest
*req
)
202 NvmeSQueue
*sq
= req
->sq
;
206 int nvme_register_namespace(NvmeCtrl
*n
, NvmeNamespace
*ns
, Error
**errp
);
208 #endif /* HW_NVME_H */