2013-06-04 19:17:10 +04:00
|
|
|
#ifndef HW_NVME_H
|
|
|
|
#define HW_NVME_H
|
2020-06-09 22:03:15 +03:00
|
|
|
|
2018-01-16 09:08:59 +03:00
|
|
|
#include "block/nvme.h"
|
2013-06-04 19:17:10 +04:00
|
|
|
|
2020-06-09 22:03:15 +03:00
|
|
|
typedef struct NvmeParams {
|
|
|
|
char *serial;
|
2020-06-09 22:03:19 +03:00
|
|
|
uint32_t num_queues; /* deprecated since 5.1 */
|
|
|
|
uint32_t max_ioqpairs;
|
2020-06-09 22:03:32 +03:00
|
|
|
uint16_t msix_qsize;
|
2020-06-09 22:03:15 +03:00
|
|
|
uint32_t cmb_size_mb;
|
2020-07-06 09:12:53 +03:00
|
|
|
uint8_t aerl;
|
|
|
|
uint32_t aer_max_queued;
|
2020-02-23 19:38:22 +03:00
|
|
|
uint8_t mdts;
|
2020-06-09 22:03:15 +03:00
|
|
|
} NvmeParams;
|
|
|
|
|
2013-06-04 19:17:10 +04:00
|
|
|
typedef struct NvmeAsyncEvent {
|
2020-07-06 09:12:53 +03:00
|
|
|
QTAILQ_ENTRY(NvmeAsyncEvent) entry;
|
2013-06-04 19:17:10 +04:00
|
|
|
NvmeAerResult result;
|
|
|
|
} NvmeAsyncEvent;
|
|
|
|
|
|
|
|
typedef struct NvmeRequest {
|
|
|
|
struct NvmeSQueue *sq;
|
2020-07-20 13:44:01 +03:00
|
|
|
struct NvmeNamespace *ns;
|
2014-10-07 15:59:14 +04:00
|
|
|
BlockAIOCB *aiocb;
|
2013-06-04 19:17:10 +04:00
|
|
|
uint16_t status;
|
|
|
|
NvmeCqe cqe;
|
2020-07-20 13:44:01 +03:00
|
|
|
NvmeCmd cmd;
|
2013-06-04 19:17:10 +04:00
|
|
|
BlockAcctCookie acct;
|
|
|
|
QEMUSGList qsg;
|
2017-06-13 13:08:35 +03:00
|
|
|
QEMUIOVector iov;
|
2013-06-04 19:17:10 +04:00
|
|
|
QTAILQ_ENTRY(NvmeRequest)entry;
|
|
|
|
} NvmeRequest;
|
|
|
|
|
2020-08-24 23:11:33 +03:00
|
|
|
static inline const char *nvme_adm_opc_str(uint8_t opc)
|
|
|
|
{
|
|
|
|
switch (opc) {
|
|
|
|
case NVME_ADM_CMD_DELETE_SQ: return "NVME_ADM_CMD_DELETE_SQ";
|
|
|
|
case NVME_ADM_CMD_CREATE_SQ: return "NVME_ADM_CMD_CREATE_SQ";
|
|
|
|
case NVME_ADM_CMD_GET_LOG_PAGE: return "NVME_ADM_CMD_GET_LOG_PAGE";
|
|
|
|
case NVME_ADM_CMD_DELETE_CQ: return "NVME_ADM_CMD_DELETE_CQ";
|
|
|
|
case NVME_ADM_CMD_CREATE_CQ: return "NVME_ADM_CMD_CREATE_CQ";
|
|
|
|
case NVME_ADM_CMD_IDENTIFY: return "NVME_ADM_CMD_IDENTIFY";
|
|
|
|
case NVME_ADM_CMD_ABORT: return "NVME_ADM_CMD_ABORT";
|
|
|
|
case NVME_ADM_CMD_SET_FEATURES: return "NVME_ADM_CMD_SET_FEATURES";
|
|
|
|
case NVME_ADM_CMD_GET_FEATURES: return "NVME_ADM_CMD_GET_FEATURES";
|
|
|
|
case NVME_ADM_CMD_ASYNC_EV_REQ: return "NVME_ADM_CMD_ASYNC_EV_REQ";
|
|
|
|
default: return "NVME_ADM_CMD_UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline const char *nvme_io_opc_str(uint8_t opc)
|
|
|
|
{
|
|
|
|
switch (opc) {
|
|
|
|
case NVME_CMD_FLUSH: return "NVME_NVM_CMD_FLUSH";
|
|
|
|
case NVME_CMD_WRITE: return "NVME_NVM_CMD_WRITE";
|
|
|
|
case NVME_CMD_READ: return "NVME_NVM_CMD_READ";
|
|
|
|
case NVME_CMD_WRITE_ZEROES: return "NVME_NVM_CMD_WRITE_ZEROES";
|
|
|
|
default: return "NVME_NVM_CMD_UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-04 19:17:10 +04:00
|
|
|
typedef struct NvmeSQueue {
|
|
|
|
struct NvmeCtrl *ctrl;
|
|
|
|
uint16_t sqid;
|
|
|
|
uint16_t cqid;
|
|
|
|
uint32_t head;
|
|
|
|
uint32_t tail;
|
|
|
|
uint32_t size;
|
|
|
|
uint64_t dma_addr;
|
|
|
|
QEMUTimer *timer;
|
|
|
|
NvmeRequest *io_req;
|
2018-12-06 13:58:10 +03:00
|
|
|
QTAILQ_HEAD(, NvmeRequest) req_list;
|
|
|
|
QTAILQ_HEAD(, NvmeRequest) out_req_list;
|
2013-06-04 19:17:10 +04:00
|
|
|
QTAILQ_ENTRY(NvmeSQueue) entry;
|
|
|
|
} NvmeSQueue;
|
|
|
|
|
|
|
|
typedef struct NvmeCQueue {
|
|
|
|
struct NvmeCtrl *ctrl;
|
|
|
|
uint8_t phase;
|
|
|
|
uint16_t cqid;
|
|
|
|
uint16_t irq_enabled;
|
|
|
|
uint32_t head;
|
|
|
|
uint32_t tail;
|
|
|
|
uint32_t vector;
|
|
|
|
uint32_t size;
|
|
|
|
uint64_t dma_addr;
|
|
|
|
QEMUTimer *timer;
|
2018-12-06 13:58:10 +03:00
|
|
|
QTAILQ_HEAD(, NvmeSQueue) sq_list;
|
|
|
|
QTAILQ_HEAD(, NvmeRequest) req_list;
|
2013-06-04 19:17:10 +04:00
|
|
|
} NvmeCQueue;
|
|
|
|
|
|
|
|
typedef struct NvmeNamespace {
|
|
|
|
NvmeIdNs id_ns;
|
|
|
|
} NvmeNamespace;
|
|
|
|
|
2020-06-09 22:03:24 +03:00
|
|
|
static inline NvmeLBAF *nvme_ns_lbaf(NvmeNamespace *ns)
|
|
|
|
{
|
|
|
|
NvmeIdNs *id_ns = &ns->id_ns;
|
|
|
|
return &id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(id_ns->flbas)];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint8_t nvme_ns_lbads(NvmeNamespace *ns)
|
|
|
|
{
|
|
|
|
return nvme_ns_lbaf(ns)->ds;
|
|
|
|
}
|
|
|
|
|
2020-08-24 09:59:41 +03:00
|
|
|
/* convert an LBA to the equivalent in bytes */
|
|
|
|
static inline size_t nvme_l2b(NvmeNamespace *ns, uint64_t lba)
|
|
|
|
{
|
|
|
|
return lba << nvme_ns_lbads(ns);
|
|
|
|
}
|
|
|
|
|
2013-06-04 19:17:10 +04:00
|
|
|
#define TYPE_NVME "nvme"
|
|
|
|
#define NVME(obj) \
|
|
|
|
OBJECT_CHECK(NvmeCtrl, (obj), TYPE_NVME)
|
|
|
|
|
2020-07-06 09:12:54 +03:00
|
|
|
typedef struct NvmeFeatureVal {
|
|
|
|
struct {
|
|
|
|
uint16_t temp_thresh_hi;
|
|
|
|
uint16_t temp_thresh_low;
|
|
|
|
};
|
|
|
|
uint32_t async_config;
|
|
|
|
} NvmeFeatureVal;
|
|
|
|
|
2013-06-04 19:17:10 +04:00
|
|
|
typedef struct NvmeCtrl {
|
|
|
|
PCIDevice parent_obj;
|
|
|
|
MemoryRegion iomem;
|
2017-05-16 22:10:59 +03:00
|
|
|
MemoryRegion ctrl_mem;
|
2013-06-04 19:17:10 +04:00
|
|
|
NvmeBar bar;
|
|
|
|
BlockConf conf;
|
2020-06-09 22:03:15 +03:00
|
|
|
NvmeParams params;
|
2013-06-04 19:17:10 +04:00
|
|
|
|
2020-07-06 09:13:01 +03:00
|
|
|
bool qs_created;
|
2014-11-27 06:39:21 +03:00
|
|
|
uint32_t page_size;
|
2013-06-04 19:17:10 +04:00
|
|
|
uint16_t page_bits;
|
|
|
|
uint16_t max_prp_ents;
|
|
|
|
uint16_t cqe_size;
|
|
|
|
uint16_t sqe_size;
|
|
|
|
uint32_t reg_size;
|
|
|
|
uint32_t num_namespaces;
|
|
|
|
uint32_t max_q_ents;
|
|
|
|
uint64_t ns_size;
|
2020-07-06 09:12:53 +03:00
|
|
|
uint8_t outstanding_aers;
|
2017-05-16 22:10:59 +03:00
|
|
|
uint8_t *cmbuf;
|
2020-06-09 22:03:18 +03:00
|
|
|
uint32_t irq_status;
|
2019-05-20 20:40:30 +03:00
|
|
|
uint64_t host_timestamp; /* Timestamp sent by the host */
|
|
|
|
uint64_t timestamp_set_qemu_clock_ms; /* QEMU clock time */
|
2020-07-06 09:12:52 +03:00
|
|
|
uint64_t starttime_ms;
|
|
|
|
uint16_t temperature;
|
2013-06-04 19:17:10 +04:00
|
|
|
|
2020-03-30 19:46:56 +03:00
|
|
|
HostMemoryBackend *pmrdev;
|
|
|
|
|
2020-07-06 09:12:53 +03:00
|
|
|
uint8_t aer_mask;
|
|
|
|
NvmeRequest **aer_reqs;
|
|
|
|
QTAILQ_HEAD(, NvmeAsyncEvent) aer_queue;
|
|
|
|
int aer_queued;
|
|
|
|
|
2013-06-04 19:17:10 +04:00
|
|
|
NvmeNamespace *namespaces;
|
|
|
|
NvmeSQueue **sq;
|
|
|
|
NvmeCQueue **cq;
|
|
|
|
NvmeSQueue admin_sq;
|
|
|
|
NvmeCQueue admin_cq;
|
|
|
|
NvmeIdCtrl id_ctrl;
|
2020-07-06 09:12:50 +03:00
|
|
|
NvmeFeatureVal features;
|
2013-06-04 19:17:10 +04:00
|
|
|
} NvmeCtrl;
|
|
|
|
|
2020-06-09 22:03:24 +03:00
|
|
|
/* calculate the number of LBAs that the namespace can accomodate */
|
|
|
|
static inline uint64_t nvme_ns_nlbas(NvmeCtrl *n, NvmeNamespace *ns)
|
|
|
|
{
|
|
|
|
return n->ns_size >> nvme_ns_lbads(ns);
|
|
|
|
}
|
|
|
|
|
2013-06-04 19:17:10 +04:00
|
|
|
#endif /* HW_NVME_H */
|