2013-06-04 17:17:10 +02:00
|
|
|
#ifndef HW_NVME_H
|
|
|
|
#define HW_NVME_H
|
2020-06-09 21:03:15 +02:00
|
|
|
|
2018-01-16 07:08:59 +01:00
|
|
|
#include "block/nvme.h"
|
2013-06-04 17:17:10 +02:00
|
|
|
|
2020-06-09 21:03:15 +02:00
|
|
|
typedef struct NvmeParams {
|
|
|
|
char *serial;
|
2020-06-09 21:03:19 +02:00
|
|
|
uint32_t num_queues; /* deprecated since 5.1 */
|
|
|
|
uint32_t max_ioqpairs;
|
2020-06-09 21:03:32 +02:00
|
|
|
uint16_t msix_qsize;
|
2020-06-09 21:03:15 +02:00
|
|
|
uint32_t cmb_size_mb;
|
|
|
|
} NvmeParams;
|
|
|
|
|
2013-06-04 17:17:10 +02:00
|
|
|
typedef struct NvmeAsyncEvent {
|
|
|
|
QSIMPLEQ_ENTRY(NvmeAsyncEvent) entry;
|
|
|
|
NvmeAerResult result;
|
|
|
|
} NvmeAsyncEvent;
|
|
|
|
|
|
|
|
typedef struct NvmeRequest {
|
|
|
|
struct NvmeSQueue *sq;
|
2014-10-07 13:59:14 +02:00
|
|
|
BlockAIOCB *aiocb;
|
2013-06-04 17:17:10 +02:00
|
|
|
uint16_t status;
|
2015-06-11 12:01:38 +02:00
|
|
|
bool has_sg;
|
2013-06-04 17:17:10 +02:00
|
|
|
NvmeCqe cqe;
|
|
|
|
BlockAcctCookie acct;
|
|
|
|
QEMUSGList qsg;
|
2017-06-13 12:08:35 +02:00
|
|
|
QEMUIOVector iov;
|
2013-06-04 17:17:10 +02:00
|
|
|
QTAILQ_ENTRY(NvmeRequest)entry;
|
|
|
|
} NvmeRequest;
|
|
|
|
|
|
|
|
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 11:58:10 +01:00
|
|
|
QTAILQ_HEAD(, NvmeRequest) req_list;
|
|
|
|
QTAILQ_HEAD(, NvmeRequest) out_req_list;
|
2013-06-04 17:17:10 +02: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 11:58:10 +01:00
|
|
|
QTAILQ_HEAD(, NvmeSQueue) sq_list;
|
|
|
|
QTAILQ_HEAD(, NvmeRequest) req_list;
|
2013-06-04 17:17:10 +02:00
|
|
|
} NvmeCQueue;
|
|
|
|
|
|
|
|
typedef struct NvmeNamespace {
|
|
|
|
NvmeIdNs id_ns;
|
|
|
|
} NvmeNamespace;
|
|
|
|
|
2020-06-09 21:03:24 +02: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;
|
|
|
|
}
|
|
|
|
|
2013-06-04 17:17:10 +02:00
|
|
|
#define TYPE_NVME "nvme"
|
|
|
|
#define NVME(obj) \
|
|
|
|
OBJECT_CHECK(NvmeCtrl, (obj), TYPE_NVME)
|
|
|
|
|
|
|
|
typedef struct NvmeCtrl {
|
|
|
|
PCIDevice parent_obj;
|
|
|
|
MemoryRegion iomem;
|
2017-05-16 21:10:59 +02:00
|
|
|
MemoryRegion ctrl_mem;
|
2013-06-04 17:17:10 +02:00
|
|
|
NvmeBar bar;
|
|
|
|
BlockConf conf;
|
2020-06-09 21:03:15 +02:00
|
|
|
NvmeParams params;
|
2013-06-04 17:17:10 +02:00
|
|
|
|
2014-11-27 04:39:21 +01:00
|
|
|
uint32_t page_size;
|
2013-06-04 17:17:10 +02: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;
|
2017-05-16 21:10:59 +02:00
|
|
|
uint8_t *cmbuf;
|
2020-06-09 21:03:18 +02:00
|
|
|
uint32_t irq_status;
|
2019-05-20 19:40:30 +02:00
|
|
|
uint64_t host_timestamp; /* Timestamp sent by the host */
|
|
|
|
uint64_t timestamp_set_qemu_clock_ms; /* QEMU clock time */
|
2013-06-04 17:17:10 +02:00
|
|
|
|
2020-03-30 18:46:56 +02:00
|
|
|
HostMemoryBackend *pmrdev;
|
|
|
|
|
2013-06-04 17:17:10 +02:00
|
|
|
NvmeNamespace *namespaces;
|
|
|
|
NvmeSQueue **sq;
|
|
|
|
NvmeCQueue **cq;
|
|
|
|
NvmeSQueue admin_sq;
|
|
|
|
NvmeCQueue admin_cq;
|
|
|
|
NvmeIdCtrl id_ctrl;
|
|
|
|
} NvmeCtrl;
|
|
|
|
|
2020-06-09 21:03:24 +02: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 17:17:10 +02:00
|
|
|
#endif /* HW_NVME_H */
|