nvme: refactoring and cleanups
PATCH 1/16 nvme: fix pci doorbell size calculation
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
The size of the BAR is 0x1000 (main registers) + 8 bytes for each queue. Currently, the size of the BAR is calculated like so:
n->reg_size = pow2ceil(0x1004 + 2 * (n->params.num_queues + 1) * 4);
Since the 'num_queues' parameter already accounts for the admin queue, this should in any case not need to be incremented by one. Also, the size should be initialized to (0x1000).
n->reg_size = pow2ceil(0x1000 + 2 * n->params.num_queues * 4);
This, with the default value of num_queues (64), we will set aside room for 1 admin queue and 63 I/O queues (4 bytes per doorbell, 2 doorbells per queue).
--- hw/block/nvme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/block/nvme.c +1 -1
@@ -1345,7 +1345,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)pcie_endpoint_cap_init (pci_dev,0x80 ); n->num_namespaces =1 ; - n->reg_size =pow2ceil (0x1004 +2 * (n->num_queues +1 ) *4 ); + n->reg_size =pow2ceil (0x1000 +2 * n->num_queues *4 ); n->ns_size = bs_size / (uint64_t )n->num_namespaces; n->namespaces =g_new0 (NvmeNamespace, n->num_namespaces);
Signature · 1 line
2.26.0
PATCH 5/16 nvme: use constants in identify
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
--- hw/block/nvme.c | 8 ++++---- include/block/nvme.h | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-)
hw/block/nvme.c +4 -4
@@ -679,7 +679,7 @@ static uint16_t nvme_identify_ns(NvmeCtrl *n, NvmeIdentify *c)static uint16_t nvme_identify_nslist (NvmeCtrl *n,NvmeIdentify *c) { -static const int data_len =4 * KiB; +static const int data_len =NVME_IDENTIFY_DATA_SIZE ;uint32_t min_nsid =le32_to_cpu (c->nsid);uint64_t prp1 =le64_to_cpu (c->prp1);uint64_t prp2 =le64_to_cpu (c->prp2);
@@ -709,11 +709,11 @@ static uint16_t nvme_identify(NvmeCtrl *n, NvmeCmd *cmd)NvmeIdentify *c = (NvmeIdentify *)cmd;switch (le32_to_cpu (c->cns)) { -case 0x00 : +case NVME_ID_CNS_NS :return nvme_identify_ns (n, c); -case 0x01 : +case NVME_ID_CNS_CTRL :return nvme_identify_ctrl (n, c); -case 0x02 : +case NVME_ID_CNS_NS_ACTIVE_LIST :return nvme_identify_nslist (n, c);default :trace_nvme_dev_err_invalid_identify_cns (le32_to_cpu (c->cns));
include/block/nvme.h +8 -0
@@ -533,6 +533,14 @@ typedef struct NvmePSD {uint8_t resv[16 ]; } NvmePSD; +#define NVME_IDENTIFY_DATA_SIZE 4096 + +enum { +NVME_ID_CNS_NS =0x0 , +NVME_ID_CNS_CTRL =0x1 , +NVME_ID_CNS_NS_ACTIVE_LIST =0x2 , +}; + typedef struct NvmeIdCtrl { uint16_t vid; uint16_t ssvid;
Signature · 1 line
2.26.0
PATCH 3/16 nvme: remove superfluous breaks
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
These break statements was left over when commit 3036a626e9ef ("nvme:
add Get/Set Feature Timestamp support") was merged.
--- hw/block/nvme.c | 4 ---- 1 file changed, 4 deletions(-)
hw/block/nvme.c +0 -4
@@ -788,7 +788,6 @@ static uint16_t nvme_get_feature(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)break ;case NVME_TIMESTAMP :return nvme_get_feature_timestamp (n, cmd); -break ;default :trace_nvme_dev_err_invalid_getfeat (dw10);return NVME_INVALID_FIELD |NVME_DNR ;
@@ -832,11 +831,8 @@ static uint16_t nvme_set_feature(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req) req->cqe.result =cpu_to_le32 ((n->num_queues -2 ) | ((n->num_queues -2 ) <<16 ));break ; -case NVME_TIMESTAMP :return nvme_set_feature_timestamp (n, cmd); -break ; -default :trace_nvme_dev_err_invalid_setfeat (dw10);return NVME_INVALID_FIELD |NVME_DNR ;
Signature · 1 line
2.26.0
PATCH 7/16 nvme: add max_ioqpairs device parameter
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
The num_queues device paramater has a slightly confusing meaning because it accounts for the admin queue pair which is not really optional. Secondly, it is really a maximum value of queues allowed.
Add a new max_ioqpairs parameter that only accounts for I/O queue pairs, but keep num_queues for compatibility.
--- hw/block/nvme.c | 46 ++++++++++++++++++++++++++++------------------ hw/block/nvme.h | 4 +++- 2 files changed, 31 insertions(+), 19 deletions(-)
hw/block/nvme.c +28 -18
@@ -19,7 +19,7 @@* -drive file=<file>,if=none,id=<drive_id> * -device nvme,drive=<drive_id>,serial=<serial>,id=<id[optional]>, \ * cmb_size_mb=<cmb_size_mb[optional]>, \ -* num_queues=<N[optional]> +* max_ioqpairs=<N[optional]> * * Note cmb_size_mb denotes size of CMB in MB. CMB is assumed to be at * offset 0 in BAR2 and supports only WDS, RDS and SQS for now.
@@ -27,6 +27,7 @@#include "qemu/osdep.h" #include "qemu/units.h" +#include "qemu/error-report.h" #include "hw/block/block.h" #include "hw/pci/msix.h" #include "hw/pci/pci.h"
@@ -72,12 +73,12 @@ static void nvme_addr_read(NvmeCtrl *n, hwaddr addr, void *buf, int size)static int nvme_check_sqid (NvmeCtrl *n,uint16_t sqid) { -return sqid < n->params.num_queues && n->sq[sqid] !=NULL ?0 :-1 ; +return sqid < n->params.max_ioqpairs +1 && n->sq[sqid] !=NULL ?0 :-1 ; }static int nvme_check_cqid (NvmeCtrl *n,uint16_t cqid) { -return cqid < n->params.num_queues && n->cq[cqid] !=NULL ?0 :-1 ; +return cqid < n->params.max_ioqpairs +1 && n->cq[cqid] !=NULL ?0 :-1 ; }static void nvme_inc_cq_tail (NvmeCQueue *cq)
@@ -639,7 +640,7 @@ static uint16_t nvme_create_cq(NvmeCtrl *n, NvmeCmd *cmd)trace_nvme_dev_err_invalid_create_cq_addr (prp1);return NVME_INVALID_FIELD |NVME_DNR ; } -if (unlikely (vector > n->params.num_queues)) { +if (unlikely (vector > n->params.max_ioqpairs +1 )) {trace_nvme_dev_err_invalid_create_cq_vector (vector);return NVME_INVALID_IRQ_VECTOR |NVME_DNR ; }
@@ -791,8 +792,8 @@ static uint16_t nvme_get_feature(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)trace_nvme_dev_getfeat_vwcache (result ?"enabled" :"disabled" );break ;case NVME_NUMBER_OF_QUEUES : - result =cpu_to_le32 ((n->params.num_queues -2 ) | - ((n->params.num_queues -2 ) <<16 )); + result =cpu_to_le32 ((n->params.max_ioqpairs -1 ) | + ((n->params.max_ioqpairs -1 ) <<16 ));trace_nvme_dev_getfeat_numq (result);break ;case NVME_TIMESTAMP :
@@ -836,10 +837,10 @@ static uint16_t nvme_set_feature(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)case NVME_NUMBER_OF_QUEUES :trace_nvme_dev_setfeat_numq ((dw11 &0xFFFF ) +1 , ((dw11 >>16 ) &0xFFFF ) +1 , - n->params.num_queues -1 , - n->params.num_queues -1 ); - req->cqe.result =cpu_to_le32 ((n->params.num_queues -2 ) | - ((n->params.num_queues -2 ) <<16 )); + n->params.max_ioqpairs, + n->params.max_ioqpairs); + req->cqe.result =cpu_to_le32 ((n->params.max_ioqpairs -1 ) | + ((n->params.max_ioqpairs -1 ) <<16 ));break ;case NVME_TIMESTAMP :return nvme_set_feature_timestamp (n, cmd);
@@ -910,12 +911,12 @@ static void nvme_clear_ctrl(NvmeCtrl *n)blk_drain (n->conf.blk); -for (i =0 ; i < n->params.num_queues; i++) { +for (i =0 ; i < n->params.max_ioqpairs +1 ; i++) {if (n->sq[i] !=NULL ) {nvme_free_sq (n->sq[i], n); } } -for (i =0 ; i < n->params.num_queues; i++) { +for (i =0 ; i < n->params.max_ioqpairs +1 ; i++) {if (n->cq[i] !=NULL ) {nvme_free_cq (n->cq[i], n); }
@@ -1316,8 +1317,17 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)int64_t bs_size;uint8_t *pci_conf; -if (!n->params.num_queues) { -error_setg (errp,"num_queues can't be zero" ); +if (n->params.num_queues) { +warn_report ("num_queues is deprecated; please use max_ioqpairs " +"instead" ); + + n->params.max_ioqpairs = n->params.num_queues -1 ; + } + +if (n->params.max_ioqpairs <1 || + n->params.max_ioqpairs >PCI_MSIX_FLAGS_QSIZE ) { +error_setg (errp,"max_ioqpairs must be between 1 and %d" , +PCI_MSIX_FLAGS_QSIZE );return ; }
@@ -1349,19 +1359,19 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)pcie_endpoint_cap_init (pci_dev,0x80 ); n->num_namespaces =1 ; - n->reg_size =pow2ceil (0x1000 +2 * n->params.num_queues *4 ); + n->reg_size =pow2ceil (0x1008 +2 * (n->params.max_ioqpairs) *4 ); n->ns_size = bs_size / (uint64_t )n->num_namespaces; n->namespaces =g_new0 (NvmeNamespace, n->num_namespaces); - n->sq = g_new0(NvmeSQueue *, n->params.num_queues); - n->cq = g_new0(NvmeCQueue *, n->params.num_queues); + n->sq = g_new0(NvmeSQueue *, n->params.max_ioqpairs + 1); + n->cq = g_new0(NvmeCQueue *, n->params.max_ioqpairs + 1);memory_region_init_io (&n->iomem,OBJECT (n), &nvme_mmio_ops, n,"nvme" , n->reg_size);pci_register_bar (pci_dev,0 ,PCI_BASE_ADDRESS_SPACE_MEMORY |PCI_BASE_ADDRESS_MEM_TYPE_64 , &n->iomem); -msix_init_exclusive_bar (pci_dev, n->params.num_queues,4 ,NULL ); +msix_init_exclusive_bar (pci_dev, n->params.max_ioqpairs +1 ,4 ,NULL ); id->vid =cpu_to_le16 (pci_get_word (pci_conf +PCI_VENDOR_ID )); id->ssvid =cpu_to_le16 (pci_get_word (pci_conf +PCI_SUBSYSTEM_VENDOR_ID ));
hw/block/nvme.h +3 -1
@@ -6,11 +6,13 @@#define DEFINE_NVME_PROPERTIES (_state, _props) \ DEFINE_PROP_STRING("serial", _state, _props.serial), \ DEFINE_PROP_UINT32("cmb_size_mb", _state, _props.cmb_size_mb, 0), \ - DEFINE_PROP_UINT32("num_queues", _state, _props.num_queues, 64) + DEFINE_PROP_UINT32("num_queues", _state, _props.num_queues, 0), \ + DEFINE_PROP_UINT32("max_ioqpairs", _state, _props.max_ioqpairs, 64)typedef struct NvmeParams {char *serial;uint32_t num_queues; +uint32_t max_ioqpairs;uint32_t cmb_size_mb; }NvmeParams ;
Signature · 1 line
2.26.0
cover nvme: refactoring and cleanups
From: Klaus Jensen <[email protected]>
Philippe suggested that I split up this already way too huge series (more than 50 patches now), so here goes.
The first patch in this series fixes a small bug in the pci doorbell size calculation. Please consider cherry-picking this.
The rest are refactorings. The "nvme: add max_ioqpairs device parameter" introduces the 'max_ioqpairs' device parameter, the meaning of which should be more intuitive than the existing 'num_queues' parameter.
Klaus Jensen (16):
nvme: fix pci doorbell size calculation
nvme: rename trace events to nvme_dev
nvme: remove superfluous breaks
nvme: move device parameters to separate struct
nvme: use constants in identify
nvme: refactor nvme_addr_read
nvme: add max_ioqpairs device parameter
nvme: remove redundant cmbloc/cmbsz members
nvme: factor out property/constraint checks
nvme: factor out device state setup
nvme: factor out block backend setup
nvme: add namespace helpers
nvme: factor out namespace setup
nvme: factor out pci setup
nvme: factor out cmb setup
nvme: factor out controller identify setup
hw/block/nvme.c | 436 ++++++++++++++++++++++++------------------ hw/block/nvme.h | 36 +++- hw/block/trace-events | 172 ++++++++--------- include/block/nvme.h | 8 + 4 files changed, 373 insertions(+), 279 deletions(-)
Signature · 1 line
2.26.0
PATCH 9/16 nvme: factor out property/constraint checks
From: Klaus Jensen <[email protected]>
--- hw/block/nvme.c | 52 ++++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 20 deletions(-)
hw/block/nvme.c +32 -20
@@ -1308,6 +1308,37 @@ static const MemoryRegionOps nvme_cmb_ops = { }, }; +static int nvme_check_constraints (NvmeCtrl *n,Error **errp) +{ +NvmeParams *params = &n->params; + +if (params->num_queues) { +warn_report ("num_queues is deprecated; please use max_ioqpairs " +"instead" ); + + params->max_ioqpairs = params->num_queues -1 ; + } + +if (params->max_ioqpairs <1 || + params->max_ioqpairs >PCI_MSIX_FLAGS_QSIZE ) { +error_setg (errp,"max_ioqpairs must be between 1 and %d" , +PCI_MSIX_FLAGS_QSIZE ); +return -1 ; + } + +if (!n->conf.blk) { +error_setg (errp,"drive property not set" ); +return -1 ; + } + +if (!params->serial) { +error_setg (errp,"serial property not set" ); +return -1 ; + } + +return 0 ; +} +static void nvme_realize (PCIDevice *pci_dev,Error **errp) {NvmeCtrl *n =NVME (pci_dev);
@@ -1317,22 +1348,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)int64_t bs_size;uint8_t *pci_conf; -if (n->params.num_queues) { -warn_report ("num_queues is deprecated; please use max_ioqpairs " -"instead" ); - - n->params.max_ioqpairs = n->params.num_queues -1 ; - } - -if (n->params.max_ioqpairs <1 || - n->params.max_ioqpairs >PCI_MSIX_FLAGS_QSIZE ) { -error_setg (errp,"max_ioqpairs must be between 1 and %d" , -PCI_MSIX_FLAGS_QSIZE ); -return ; - } - -if (!n->conf.blk) { -error_setg (errp,"drive property not set" ); +if (nvme_check_constraints (n, errp)) {return ; }
@@ -1342,10 +1358,6 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)return ; } -if (!n->params.serial) { -error_setg (errp,"serial property not set" ); -return ; - }blkconf_blocksizes (&n->conf);if (!blkconf_apply_backend_options (&n->conf,blk_is_read_only (n->conf.blk), false, errp)) {
Signature · 1 line
2.26.0
PATCH 16/16 nvme: factor out controller identify setup
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
--- hw/block/nvme.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-)
hw/block/nvme.c +24 -18
@@ -1428,27 +1428,11 @@ static void nvme_init_pci(NvmeCtrl *n, PCIDevice *pci_dev) } } -static void nvme_realize (PCIDevice *pci_dev,Error **errp) +static void nvme_init_ctrl (NvmeCtrl *n,PCIDevice *pci_dev) { -NvmeCtrl *n =NVME (pci_dev);NvmeIdCtrl *id = &n->id_ctrl; +uint8_t *pci_conf = pci_dev->config; -int i; -uint8_t *pci_conf; - -if (nvme_check_constraints (n, errp)) { -return ; - } - -nvme_init_state (n); - -if (nvme_init_blk (n, errp)) { -return ; - } - -nvme_init_pci (n, pci_dev); - - pci_conf = pci_dev->config; id->vid =cpu_to_le16 (pci_get_word (pci_conf +PCI_VENDOR_ID )); id->ssvid =cpu_to_le16 (pci_get_word (pci_conf +PCI_SUBSYSTEM_VENDOR_ID ));strpadcpy ((char *)id->mn,sizeof (id->mn),"QEMU NVMe Ctrl" ,' ' );
@@ -1482,6 +1466,28 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp) n->bar.vs =0x00010200 ; n->bar.intmc = n->bar.intms =0 ; + +} + +static void nvme_realize (PCIDevice *pci_dev,Error **errp) +{ +NvmeCtrl *n =NVME (pci_dev); + +int i; + +if (nvme_check_constraints (n, errp)) { +return ; + } + +nvme_init_state (n); + +if (nvme_init_blk (n, errp)) { +return ; + } + +nvme_init_pci (n, pci_dev); +nvme_init_ctrl (n, pci_dev); +for (i =0 ; i < n->num_namespaces; i++) {if (nvme_init_namespace (n, &n->namespaces[i], errp)) {return ;
Signature · 1 line
2.26.0
PATCH 4/16 nvme: move device parameters to separate struct
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
Move device configuration parameters to separate struct to make it explicit what is configurable and what is set internally.
--- hw/block/nvme.c | 44 ++++++++++++++++++++++---------------------- hw/block/nvme.h | 16 +++++++++++++--- 2 files changed, 35 insertions(+), 25 deletions(-)
hw/block/nvme.c +22 -22
@@ -64,12 +64,12 @@ static void nvme_addr_read(NvmeCtrl *n, hwaddr addr, void *buf, int size)static int nvme_check_sqid (NvmeCtrl *n,uint16_t sqid) { -return sqid < n->num_queues && n->sq[sqid] !=NULL ?0 :-1 ; +return sqid < n->params.num_queues && n->sq[sqid] !=NULL ?0 :-1 ; }static int nvme_check_cqid (NvmeCtrl *n,uint16_t cqid) { -return cqid < n->num_queues && n->cq[cqid] !=NULL ?0 :-1 ; +return cqid < n->params.num_queues && n->cq[cqid] !=NULL ?0 :-1 ; }static void nvme_inc_cq_tail (NvmeCQueue *cq)
@@ -631,7 +631,7 @@ static uint16_t nvme_create_cq(NvmeCtrl *n, NvmeCmd *cmd)trace_nvme_dev_err_invalid_create_cq_addr (prp1);return NVME_INVALID_FIELD |NVME_DNR ; } -if (unlikely (vector > n->num_queues)) { +if (unlikely (vector > n->params.num_queues)) {trace_nvme_dev_err_invalid_create_cq_vector (vector);return NVME_INVALID_IRQ_VECTOR |NVME_DNR ; }
@@ -783,7 +783,8 @@ static uint16_t nvme_get_feature(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)trace_nvme_dev_getfeat_vwcache (result ?"enabled" :"disabled" );break ;case NVME_NUMBER_OF_QUEUES : - result =cpu_to_le32 ((n->num_queues -2 ) | ((n->num_queues -2 ) <<16 )); + result =cpu_to_le32 ((n->params.num_queues -2 ) | + ((n->params.num_queues -2 ) <<16 ));trace_nvme_dev_getfeat_numq (result);break ;case NVME_TIMESTAMP :
@@ -827,9 +828,10 @@ static uint16_t nvme_set_feature(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)case NVME_NUMBER_OF_QUEUES :trace_nvme_dev_setfeat_numq ((dw11 &0xFFFF ) +1 , ((dw11 >>16 ) &0xFFFF ) +1 , - n->num_queues -1 , n->num_queues -1 ); - req->cqe.result = -cpu_to_le32 ((n->num_queues -2 ) | ((n->num_queues -2 ) <<16 )); + n->params.num_queues -1 , + n->params.num_queues -1 ); + req->cqe.result =cpu_to_le32 ((n->params.num_queues -2 ) | + ((n->params.num_queues -2 ) <<16 ));break ;case NVME_TIMESTAMP :return nvme_set_feature_timestamp (n, cmd);
@@ -900,12 +902,12 @@ static void nvme_clear_ctrl(NvmeCtrl *n)blk_drain (n->conf.blk); -for (i =0 ; i < n->num_queues; i++) { +for (i =0 ; i < n->params.num_queues; i++) {if (n->sq[i] !=NULL ) {nvme_free_sq (n->sq[i], n); } } -for (i =0 ; i < n->num_queues; i++) { +for (i =0 ; i < n->params.num_queues; i++) {if (n->cq[i] !=NULL ) {nvme_free_cq (n->cq[i], n); }
@@ -1306,7 +1308,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)int64_t bs_size;uint8_t *pci_conf; -if (!n->num_queues) { +if (!n->params.num_queues) {error_setg (errp,"num_queues can't be zero" );return ; }
@@ -1322,7 +1324,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)return ; } -if (!n->serial) { +if (!n->params.serial) {error_setg (errp,"serial property not set" );return ; }
@@ -1339,25 +1341,25 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)pcie_endpoint_cap_init (pci_dev,0x80 ); n->num_namespaces =1 ; - n->reg_size =pow2ceil (0x1000 +2 * n->num_queues *4 ); + n->reg_size =pow2ceil (0x1000 +2 * n->params.num_queues *4 ); n->ns_size = bs_size / (uint64_t )n->num_namespaces; n->namespaces =g_new0 (NvmeNamespace, n->num_namespaces); - n->sq = g_new0(NvmeSQueue *, n->num_queues); - n->cq = g_new0(NvmeCQueue *, n->num_queues); + n->sq = g_new0(NvmeSQueue *, n->params.num_queues); + n->cq = g_new0(NvmeCQueue *, n->params.num_queues);memory_region_init_io (&n->iomem,OBJECT (n), &nvme_mmio_ops, n,"nvme" , n->reg_size);pci_register_bar (pci_dev,0 ,PCI_BASE_ADDRESS_SPACE_MEMORY |PCI_BASE_ADDRESS_MEM_TYPE_64 , &n->iomem); -msix_init_exclusive_bar (pci_dev, n->num_queues,4 ,NULL ); +msix_init_exclusive_bar (pci_dev, n->params.num_queues,4 ,NULL ); id->vid =cpu_to_le16 (pci_get_word (pci_conf +PCI_VENDOR_ID )); id->ssvid =cpu_to_le16 (pci_get_word (pci_conf +PCI_SUBSYSTEM_VENDOR_ID ));strpadcpy ((char *)id->mn,sizeof (id->mn),"QEMU NVMe Ctrl" ,' ' );strpadcpy ((char *)id->fr,sizeof (id->fr),"1.0" ,' ' ); -strpadcpy ((char *)id->sn,sizeof (id->sn), n->serial,' ' ); +strpadcpy ((char *)id->sn,sizeof (id->sn), n->params.serial,' ' ); id->rab =6 ; id->ieee[0 ] =0x00 ; id->ieee[1 ] =0x02 ;
@@ -1386,7 +1388,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp) n->bar.vs =0x00010200 ; n->bar.intmc = n->bar.intms =0 ; -if (n->cmb_size_mb) { +if (n->params.cmb_size_mb) {NVME_CMBLOC_SET_BIR (n->bar.cmbloc,2 );NVME_CMBLOC_SET_OFST (n->bar.cmbloc,0 );
@@ -1397,7 +1399,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)NVME_CMBSZ_SET_RDS (n->bar.cmbsz,1 );NVME_CMBSZ_SET_WDS (n->bar.cmbsz,1 );NVME_CMBSZ_SET_SZU (n->bar.cmbsz,2 );/* MBs */ -NVME_CMBSZ_SET_SZ (n->bar.cmbsz, n->cmb_size_mb); +NVME_CMBSZ_SET_SZ (n->bar.cmbsz, n->params.cmb_size_mb); n->cmbloc = n->bar.cmbloc; n->cmbsz = n->bar.cmbsz;
@@ -1436,7 +1438,7 @@ static void nvme_exit(PCIDevice *pci_dev)g_free (n->cq);g_free (n->sq); -if (n->cmb_size_mb) { +if (n->params.cmb_size_mb) {g_free (n->cmbuf); }msix_uninit_exclusive_bar (pci_dev);
@@ -1444,9 +1446,7 @@ static void nvme_exit(PCIDevice *pci_dev)static Property nvme_props[] = {DEFINE_BLOCK_PROPERTIES (NvmeCtrl, conf), -DEFINE_PROP_STRING ("serial" , NvmeCtrl, serial), -DEFINE_PROP_UINT32 ("cmb_size_mb" , NvmeCtrl, cmb_size_mb,0 ), -DEFINE_PROP_UINT32 ("num_queues" , NvmeCtrl, num_queues,64 ), +DEFINE_NVME_PROPERTIES (NvmeCtrl, params),DEFINE_PROP_END_OF_LIST (), };
hw/block/nvme.h +13 -3
@@ -1,7 +1,19 @@ #ifndef HW_NVME_H #define HW_NVME_H + #include "block/nvme.h" +#define DEFINE_NVME_PROPERTIES(_state, _props) \ + DEFINE_PROP_STRING("serial", _state, _props.serial), \ + DEFINE_PROP_UINT32("cmb_size_mb", _state, _props.cmb_size_mb, 0), \ + DEFINE_PROP_UINT32("num_queues", _state, _props.num_queues, 64) + +typedef struct NvmeParams { + char *serial; + uint32_t num_queues; + uint32_t cmb_size_mb; +} NvmeParams; + typedef struct NvmeAsyncEvent { QSIMPLEQ_ENTRY(NvmeAsyncEvent) entry; NvmeAerResult result;
@@ -63,6 +75,7 @@ typedef struct NvmeCtrl {MemoryRegion ctrl_mem;NvmeBar bar;BlockConf conf; +NvmeParams params;uint32_t page_size;uint16_t page_bits;
@@ -71,10 +84,8 @@ typedef struct NvmeCtrl {uint16_t sqe_size;uint32_t reg_size;uint32_t num_namespaces; -uint32_t num_queues;uint32_t max_q_ents;uint64_t ns_size; -uint32_t cmb_size_mb;uint32_t cmbsz;uint32_t cmbloc;uint8_t *cmbuf;
@@ -82,7 +93,6 @@ typedef struct NvmeCtrl {uint64_t host_timestamp;/* Timestamp sent by the host */ uint64_t timestamp_set_qemu_clock_ms;/* QEMU clock time */ -char *serial;NvmeNamespace *namespaces;NvmeSQueue **sq;NvmeCQueue **cq;
Signature · 1 line
2.26.0
PATCH 6/16 nvme: refactor nvme_addr_read
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
Pull the controller memory buffer check to its own function. The check will be used on its own in later patches.
--- hw/block/nvme.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
hw/block/nvme.c +12 -4
@@ -52,14 +52,22 @@static void nvme_process_sq (void *opaque); +static bool nvme_addr_is_cmb (NvmeCtrl *n,hwaddr addr) +{ +hwaddr low = n->ctrl_mem.addr; +hwaddr hi = n->ctrl_mem.addr +int128_get64 (n->ctrl_mem.size); + +return addr >= low && addr < hi; +} +static void nvme_addr_read (NvmeCtrl *n,hwaddr addr,void *buf,int size) { -if (n->cmbsz && addr >= n->ctrl_mem.addr && - addr < (n->ctrl_mem.addr +int128_get64 (n->ctrl_mem.size))) { +if (n->cmbsz &&nvme_addr_is_cmb (n, addr)) {memcpy (buf, (void *)&n->cmbuf[addr - n->ctrl_mem.addr], size); - }else { -pci_dma_read (&n->parent_obj, addr, buf, size); +return ; } + +pci_dma_read (&n->parent_obj, addr, buf, size); }static int nvme_check_sqid (NvmeCtrl *n,uint16_t sqid)
Signature · 1 line
2.26.0
PATCH 2/16 nvme: rename trace events to nvme_dev
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
Change the prefix of all nvme device related trace events to 'nvme_dev' to not clash with trace events from the nvme block driver.
--- hw/block/nvme.c | 190 +++++++++++++++++++++--------------------- hw/block/trace-events | 172 +++++++++++++++++++------------------- 2 files changed, 180 insertions(+), 182 deletions(-)
hw/block/nvme.c +94 -96
@@ -112,16 +112,16 @@ static void nvme_irq_assert(NvmeCtrl *n, NvmeCQueue *cq) {if (cq->irq_enabled) {if (msix_enabled (&(n->parent_obj))) { -trace_nvme_irq_msix (cq->vector); +trace_nvme_dev_irq_msix (cq->vector);msix_notify (&(n->parent_obj), cq->vector); }else { -trace_nvme_irq_pin (); +trace_nvme_dev_irq_pin ();assert (cq->cqid <64 ); n->irq_status |=1 << cq->cqid;nvme_irq_check (n); } }else { -trace_nvme_irq_masked (); +trace_nvme_dev_irq_masked (); } }
@@ -146,7 +146,7 @@ static uint16_t nvme_map_prp(QEMUSGList *qsg, QEMUIOVector *iov, uint64_t prp1,int num_prps = (len >> n->page_bits) +1 ;if (unlikely (!prp1)) { -trace_nvme_err_invalid_prp (); +trace_nvme_dev_err_invalid_prp ();return NVME_INVALID_FIELD |NVME_DNR ; }else if (n->cmbsz && prp1 >= n->ctrl_mem.addr && prp1 < n->ctrl_mem.addr +int128_get64 (n->ctrl_mem.size)) {
@@ -160,7 +160,7 @@ static uint16_t nvme_map_prp(QEMUSGList *qsg, QEMUIOVector *iov, uint64_t prp1, len -= trans_len;if (len) {if (unlikely (!prp2)) { -trace_nvme_err_invalid_prp2_missing (); +trace_nvme_dev_err_invalid_prp2_missing (); goto unmap; }if (len > n->page_size) {
@@ -176,7 +176,7 @@ static uint16_t nvme_map_prp(QEMUSGList *qsg, QEMUIOVector *iov, uint64_t prp1,if (i == n->max_prp_ents -1 && len > n->page_size) {if (unlikely (!prp_ent || prp_ent & (n->page_size -1 ))) { -trace_nvme_err_invalid_prplist_ent (prp_ent); +trace_nvme_dev_err_invalid_prplist_ent (prp_ent); goto unmap; }
@@ -189,7 +189,7 @@ static uint16_t nvme_map_prp(QEMUSGList *qsg, QEMUIOVector *iov, uint64_t prp1, }if (unlikely (!prp_ent || prp_ent & (n->page_size -1 ))) { -trace_nvme_err_invalid_prplist_ent (prp_ent); +trace_nvme_dev_err_invalid_prplist_ent (prp_ent); goto unmap; }
@@ -204,7 +204,7 @@ static uint16_t nvme_map_prp(QEMUSGList *qsg, QEMUIOVector *iov, uint64_t prp1, } }else {if (unlikely (prp2 & (n->page_size -1 ))) { -trace_nvme_err_invalid_prp2_align (prp2); +trace_nvme_dev_err_invalid_prp2_align (prp2); goto unmap; }if (qsg->nsg) {
@@ -252,20 +252,20 @@ static uint16_t nvme_dma_read_prp(NvmeCtrl *n, uint8_t *ptr, uint32_t len,QEMUIOVector iov;uint16_t status =NVME_SUCCESS ; -trace_nvme_dma_read (prp1, prp2); +trace_nvme_dev_dma_read (prp1, prp2);if (nvme_map_prp (&qsg, &iov, prp1, prp2, len, n)) {return NVME_INVALID_FIELD |NVME_DNR ; }if (qsg.nsg >0 ) {if (unlikely (dma_buf_read (ptr, len, &qsg))) { -trace_nvme_err_invalid_dma (); +trace_nvme_dev_err_invalid_dma (); status =NVME_INVALID_FIELD |NVME_DNR ; }qemu_sglist_destroy (&qsg); }else {if (unlikely (qemu_iovec_from_buf (&iov,0 , ptr, len) != len)) { -trace_nvme_err_invalid_dma (); +trace_nvme_dev_err_invalid_dma (); status =NVME_INVALID_FIELD |NVME_DNR ; }qemu_iovec_destroy (&iov);
@@ -354,7 +354,7 @@ static uint16_t nvme_write_zeros(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd,uint32_t count = nlb << data_shift;if (unlikely (slba + nlb > ns->id_ns.nsze)) { -trace_nvme_err_invalid_lba_range (slba, nlb, ns->id_ns.nsze); +trace_nvme_dev_err_invalid_lba_range (slba, nlb, ns->id_ns.nsze);return NVME_LBA_RANGE |NVME_DNR ; }
@@ -382,11 +382,11 @@ static uint16_t nvme_rw(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd,int is_write = rw->opcode ==NVME_CMD_WRITE ?1 :0 ;enum BlockAcctType acct = is_write ?BLOCK_ACCT_WRITE :BLOCK_ACCT_READ ; -trace_nvme_rw (is_write ?"write" :"read" , nlb, data_size, slba); +trace_nvme_dev_rw (is_write ?"write" :"read" , nlb, data_size, slba);if (unlikely ((slba + nlb) > ns->id_ns.nsze)) {block_acct_invalid (blk_get_stats (n->conf.blk), acct); -trace_nvme_err_invalid_lba_range (slba, nlb, ns->id_ns.nsze); +trace_nvme_dev_err_invalid_lba_range (slba, nlb, ns->id_ns.nsze);return NVME_LBA_RANGE |NVME_DNR ; }
@@ -421,7 +421,7 @@ static uint16_t nvme_io_cmd(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)uint32_t nsid =le32_to_cpu (cmd->nsid);if (unlikely (nsid ==0 || nsid > n->num_namespaces)) { -trace_nvme_err_invalid_ns (nsid, n->num_namespaces); +trace_nvme_dev_err_invalid_ns (nsid, n->num_namespaces);return NVME_INVALID_NSID |NVME_DNR ; }
@@ -435,7 +435,7 @@ static uint16_t nvme_io_cmd(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)case NVME_CMD_READ :return nvme_rw (n, ns, cmd, req);default : -trace_nvme_err_invalid_opc (cmd->opcode); +trace_nvme_dev_err_invalid_opc (cmd->opcode);return NVME_INVALID_OPCODE |NVME_DNR ; } }
@@ -460,11 +460,11 @@ static uint16_t nvme_del_sq(NvmeCtrl *n, NvmeCmd *cmd)uint16_t qid =le16_to_cpu (c->qid);if (unlikely (!qid ||nvme_check_sqid (n, qid))) { -trace_nvme_err_invalid_del_sq (qid); +trace_nvme_dev_err_invalid_del_sq (qid);return NVME_INVALID_QID |NVME_DNR ; } -trace_nvme_del_sq (qid); +trace_nvme_dev_del_sq (qid); sq = n->sq[qid];while (!QTAILQ_EMPTY (&sq->out_req_list)) {
@@ -528,26 +528,26 @@ static uint16_t nvme_create_sq(NvmeCtrl *n, NvmeCmd *cmd)uint16_t qflags =le16_to_cpu (c->sq_flags);uint64_t prp1 =le64_to_cpu (c->prp1); -trace_nvme_create_sq (prp1, sqid, cqid, qsize, qflags); +trace_nvme_dev_create_sq (prp1, sqid, cqid, qsize, qflags);if (unlikely (!cqid ||nvme_check_cqid (n, cqid))) { -trace_nvme_err_invalid_create_sq_cqid (cqid); +trace_nvme_dev_err_invalid_create_sq_cqid (cqid);return NVME_INVALID_CQID |NVME_DNR ; }if (unlikely (!sqid || !nvme_check_sqid (n, sqid))) { -trace_nvme_err_invalid_create_sq_sqid (sqid); +trace_nvme_dev_err_invalid_create_sq_sqid (sqid);return NVME_INVALID_QID |NVME_DNR ; }if (unlikely (!qsize || qsize >NVME_CAP_MQES (n->bar.cap))) { -trace_nvme_err_invalid_create_sq_size (qsize); +trace_nvme_dev_err_invalid_create_sq_size (qsize);return NVME_MAX_QSIZE_EXCEEDED |NVME_DNR ; }if (unlikely (!prp1 || prp1 & (n->page_size -1 ))) { -trace_nvme_err_invalid_create_sq_addr (prp1); +trace_nvme_dev_err_invalid_create_sq_addr (prp1);return NVME_INVALID_FIELD |NVME_DNR ; }if (unlikely (!(NVME_SQ_FLAGS_PC (qflags)))) { -trace_nvme_err_invalid_create_sq_qflags (NVME_SQ_FLAGS_PC (qflags)); +trace_nvme_dev_err_invalid_create_sq_qflags (NVME_SQ_FLAGS_PC (qflags));return NVME_INVALID_FIELD |NVME_DNR ; } sq =g_malloc0 (sizeof (*sq));
@@ -573,17 +573,17 @@ static uint16_t nvme_del_cq(NvmeCtrl *n, NvmeCmd *cmd)uint16_t qid =le16_to_cpu (c->qid);if (unlikely (!qid ||nvme_check_cqid (n, qid))) { -trace_nvme_err_invalid_del_cq_cqid (qid); +trace_nvme_dev_err_invalid_del_cq_cqid (qid);return NVME_INVALID_CQID |NVME_DNR ; } cq = n->cq[qid];if (unlikely (!QTAILQ_EMPTY (&cq->sq_list))) { -trace_nvme_err_invalid_del_cq_notempty (qid); +trace_nvme_dev_err_invalid_del_cq_notempty (qid);return NVME_INVALID_QUEUE_DEL ; }nvme_irq_deassert (n, cq); -trace_nvme_del_cq (qid); +trace_nvme_dev_del_cq (qid);nvme_free_cq (cq, n);return NVME_SUCCESS ; }
@@ -616,27 +616,27 @@ static uint16_t nvme_create_cq(NvmeCtrl *n, NvmeCmd *cmd)uint16_t qflags =le16_to_cpu (c->cq_flags);uint64_t prp1 =le64_to_cpu (c->prp1); -trace_nvme_create_cq (prp1, cqid, vector, qsize, qflags, -NVME_CQ_FLAGS_IEN (qflags) !=0 ); +trace_nvme_dev_create_cq (prp1, cqid, vector, qsize, qflags, +NVME_CQ_FLAGS_IEN (qflags) !=0 );if (unlikely (!cqid || !nvme_check_cqid (n, cqid))) { -trace_nvme_err_invalid_create_cq_cqid (cqid); +trace_nvme_dev_err_invalid_create_cq_cqid (cqid);return NVME_INVALID_CQID |NVME_DNR ; }if (unlikely (!qsize || qsize >NVME_CAP_MQES (n->bar.cap))) { -trace_nvme_err_invalid_create_cq_size (qsize); +trace_nvme_dev_err_invalid_create_cq_size (qsize);return NVME_MAX_QSIZE_EXCEEDED |NVME_DNR ; }if (unlikely (!prp1)) { -trace_nvme_err_invalid_create_cq_addr (prp1); +trace_nvme_dev_err_invalid_create_cq_addr (prp1);return NVME_INVALID_FIELD |NVME_DNR ; }if (unlikely (vector > n->num_queues)) { -trace_nvme_err_invalid_create_cq_vector (vector); +trace_nvme_dev_err_invalid_create_cq_vector (vector);return NVME_INVALID_IRQ_VECTOR |NVME_DNR ; }if (unlikely (!(NVME_CQ_FLAGS_PC (qflags)))) { -trace_nvme_err_invalid_create_cq_qflags (NVME_CQ_FLAGS_PC (qflags)); +trace_nvme_dev_err_invalid_create_cq_qflags (NVME_CQ_FLAGS_PC (qflags));return NVME_INVALID_FIELD |NVME_DNR ; }
@@ -651,7 +651,7 @@ static uint16_t nvme_identify_ctrl(NvmeCtrl *n, NvmeIdentify *c)uint64_t prp1 =le64_to_cpu (c->prp1);uint64_t prp2 =le64_to_cpu (c->prp2); -trace_nvme_identify_ctrl (); +trace_nvme_dev_identify_ctrl ();return nvme_dma_read_prp (n, (uint8_t *)&n->id_ctrl,sizeof (n->id_ctrl), prp1, prp2);
@@ -664,10 +664,10 @@ static uint16_t nvme_identify_ns(NvmeCtrl *n, NvmeIdentify *c)uint64_t prp1 =le64_to_cpu (c->prp1);uint64_t prp2 =le64_to_cpu (c->prp2); -trace_nvme_identify_ns (nsid); +trace_nvme_dev_identify_ns (nsid);if (unlikely (nsid ==0 || nsid > n->num_namespaces)) { -trace_nvme_err_invalid_ns (nsid, n->num_namespaces); +trace_nvme_dev_err_invalid_ns (nsid, n->num_namespaces);return NVME_INVALID_NSID |NVME_DNR ; }
@@ -687,7 +687,7 @@ static uint16_t nvme_identify_nslist(NvmeCtrl *n, NvmeIdentify *c)uint16_t ret;int i, j =0 ; -trace_nvme_identify_nslist (min_nsid); +trace_nvme_dev_identify_nslist (min_nsid); list =g_malloc0 (data_len);for (i =0 ; i < n->num_namespaces; i++) {
@@ -716,14 +716,14 @@ static uint16_t nvme_identify(NvmeCtrl *n, NvmeCmd *cmd)case 0x02 :return nvme_identify_nslist (n, c);default : -trace_nvme_err_invalid_identify_cns (le32_to_cpu (c->cns)); +trace_nvme_dev_err_invalid_identify_cns (le32_to_cpu (c->cns));return NVME_INVALID_FIELD |NVME_DNR ; } }static inline void nvme_set_timestamp (NvmeCtrl *n,uint64_t ts) { -trace_nvme_setfeat_timestamp (ts); +trace_nvme_dev_setfeat_timestamp (ts); n->host_timestamp =le64_to_cpu (ts); n->timestamp_set_qemu_clock_ms =qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL );
@@ -756,7 +756,7 @@ static inline uint64_t nvme_get_timestamp(const NvmeCtrl *n)/* If the host timestamp is non-zero, set the timestamp origin */ ts.origin = n->host_timestamp ?0x01 :0x00 ; -trace_nvme_getfeat_timestamp (ts.all); +trace_nvme_dev_getfeat_timestamp (ts.all);return cpu_to_le64 (ts.all); }
@@ -780,17 +780,17 @@ static uint16_t nvme_get_feature(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)switch (dw10) {case NVME_VOLATILE_WRITE_CACHE : result =blk_enable_write_cache (n->conf.blk); -trace_nvme_getfeat_vwcache (result ?"enabled" :"disabled" ); +trace_nvme_dev_getfeat_vwcache (result ?"enabled" :"disabled" );break ;case NVME_NUMBER_OF_QUEUES : result =cpu_to_le32 ((n->num_queues -2 ) | ((n->num_queues -2 ) <<16 )); -trace_nvme_getfeat_numq (result); +trace_nvme_dev_getfeat_numq (result);break ;case NVME_TIMESTAMP :return nvme_get_feature_timestamp (n, cmd);break ;default : -trace_nvme_err_invalid_getfeat (dw10); +trace_nvme_dev_err_invalid_getfeat (dw10);return NVME_INVALID_FIELD |NVME_DNR ; }
@@ -826,9 +826,9 @@ static uint16_t nvme_set_feature(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)blk_set_enable_write_cache (n->conf.blk, dw11 &1 );break ;case NVME_NUMBER_OF_QUEUES : -trace_nvme_setfeat_numq ((dw11 &0xFFFF ) +1 , - ((dw11 >>16 ) &0xFFFF ) +1 , - n->num_queues -1 , n->num_queues -1 ); +trace_nvme_dev_setfeat_numq ((dw11 &0xFFFF ) +1 , + ((dw11 >>16 ) &0xFFFF ) +1 , + n->num_queues -1 , n->num_queues -1 ); req->cqe.result =cpu_to_le32 ((n->num_queues -2 ) | ((n->num_queues -2 ) <<16 ));break ;
@@ -838,7 +838,7 @@ static uint16_t nvme_set_feature(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)break ;default : -trace_nvme_err_invalid_setfeat (dw10); +trace_nvme_dev_err_invalid_setfeat (dw10);return NVME_INVALID_FIELD |NVME_DNR ; }return NVME_SUCCESS ;
@@ -862,7 +862,7 @@ static uint16_t nvme_admin_cmd(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)case NVME_ADM_CMD_GET_FEATURES :return nvme_get_feature (n, cmd, req);default : -trace_nvme_err_invalid_admin_opc (cmd->opcode); +trace_nvme_dev_err_invalid_admin_opc (cmd->opcode);return NVME_INVALID_OPCODE |NVME_DNR ; } }
@@ -925,77 +925,77 @@ static int nvme_start_ctrl(NvmeCtrl *n)uint32_t page_size =1 << page_bits;if (unlikely (n->cq[0 ])) { -trace_nvme_err_startfail_cq (); +trace_nvme_dev_err_startfail_cq ();return -1 ; }if (unlikely (n->sq[0 ])) { -trace_nvme_err_startfail_sq (); +trace_nvme_dev_err_startfail_sq ();return -1 ; }if (unlikely (!n->bar.asq)) { -trace_nvme_err_startfail_nbarasq (); +trace_nvme_dev_err_startfail_nbarasq ();return -1 ; }if (unlikely (!n->bar.acq)) { -trace_nvme_err_startfail_nbaracq (); +trace_nvme_dev_err_startfail_nbaracq ();return -1 ; }if (unlikely (n->bar.asq & (page_size -1 ))) { -trace_nvme_err_startfail_asq_misaligned (n->bar.asq); +trace_nvme_dev_err_startfail_asq_misaligned (n->bar.asq);return -1 ; }if (unlikely (n->bar.acq & (page_size -1 ))) { -trace_nvme_err_startfail_acq_misaligned (n->bar.acq); +trace_nvme_dev_err_startfail_acq_misaligned (n->bar.acq);return -1 ; }if (unlikely (NVME_CC_MPS (n->bar.cc) <NVME_CAP_MPSMIN (n->bar.cap))) { -trace_nvme_err_startfail_page_too_small ( +trace_nvme_dev_err_startfail_page_too_small (NVME_CC_MPS (n->bar.cc),NVME_CAP_MPSMIN (n->bar.cap));return -1 ; }if (unlikely (NVME_CC_MPS (n->bar.cc) >NVME_CAP_MPSMAX (n->bar.cap))) { -trace_nvme_err_startfail_page_too_large ( +trace_nvme_dev_err_startfail_page_too_large (NVME_CC_MPS (n->bar.cc),NVME_CAP_MPSMAX (n->bar.cap));return -1 ; }if (unlikely (NVME_CC_IOCQES (n->bar.cc) <NVME_CTRL_CQES_MIN (n->id_ctrl.cqes))) { -trace_nvme_err_startfail_cqent_too_small ( +trace_nvme_dev_err_startfail_cqent_too_small (NVME_CC_IOCQES (n->bar.cc),NVME_CTRL_CQES_MIN (n->bar.cap));return -1 ; }if (unlikely (NVME_CC_IOCQES (n->bar.cc) >NVME_CTRL_CQES_MAX (n->id_ctrl.cqes))) { -trace_nvme_err_startfail_cqent_too_large ( +trace_nvme_dev_err_startfail_cqent_too_large (NVME_CC_IOCQES (n->bar.cc),NVME_CTRL_CQES_MAX (n->bar.cap));return -1 ; }if (unlikely (NVME_CC_IOSQES (n->bar.cc) <NVME_CTRL_SQES_MIN (n->id_ctrl.sqes))) { -trace_nvme_err_startfail_sqent_too_small ( +trace_nvme_dev_err_startfail_sqent_too_small (NVME_CC_IOSQES (n->bar.cc),NVME_CTRL_SQES_MIN (n->bar.cap));return -1 ; }if (unlikely (NVME_CC_IOSQES (n->bar.cc) >NVME_CTRL_SQES_MAX (n->id_ctrl.sqes))) { -trace_nvme_err_startfail_sqent_too_large ( +trace_nvme_dev_err_startfail_sqent_too_large (NVME_CC_IOSQES (n->bar.cc),NVME_CTRL_SQES_MAX (n->bar.cap));return -1 ; }if (unlikely (!NVME_AQA_ASQS (n->bar.aqa))) { -trace_nvme_err_startfail_asqent_sz_zero (); +trace_nvme_dev_err_startfail_asqent_sz_zero ();return -1 ; }if (unlikely (!NVME_AQA_ACQS (n->bar.aqa))) { -trace_nvme_err_startfail_acqent_sz_zero (); +trace_nvme_dev_err_startfail_acqent_sz_zero ();return -1 ; }
@@ -1018,14 +1018,14 @@ static void nvme_write_bar(NvmeCtrl *n, hwaddr offset, uint64_t data, unsigned size) {if (unlikely (offset & (sizeof (uint32_t ) -1 ))) { -NVME_GUEST_ERR (nvme_ub_mmiowr_misaligned32, +NVME_GUEST_ERR (nvme_dev_ub_mmiowr_misaligned32,"MMIO write not 32-bit aligned," " offset=0x%" PRIx64"" , offset);/* should be ignored, fall through for now */ }if (unlikely (size <sizeof (uint32_t ))) { -NVME_GUEST_ERR (nvme_ub_mmiowr_toosmall, +NVME_GUEST_ERR (nvme_dev_ub_mmiowr_toosmall,"MMIO write smaller than 32-bits," " offset=0x%" PRIx64", size=%u" , offset, size);
@@ -1035,32 +1035,30 @@ static void nvme_write_bar(NvmeCtrl *n, hwaddr offset, uint64_t data,switch (offset) {case 0xc :/* INTMS */ if (unlikely (msix_enabled (&(n->parent_obj)))) { -NVME_GUEST_ERR (nvme_ub_mmiowr_intmask_with_msix, +NVME_GUEST_ERR (nvme_dev_ub_mmiowr_intmask_with_msix,"undefined access to interrupt mask set" " when MSI-X is enabled" );/* should be ignored, fall through for now */ } n->bar.intms |= data &0xffffffff ; n->bar.intmc = n->bar.intms; -trace_nvme_mmio_intm_set (data &0xffffffff , - n->bar.intmc); +trace_nvme_dev_mmio_intm_set (data &0xffffffff , n->bar.intmc);nvme_irq_check (n);break ;case 0x10 :/* INTMC */ if (unlikely (msix_enabled (&(n->parent_obj)))) { -NVME_GUEST_ERR (nvme_ub_mmiowr_intmask_with_msix, +NVME_GUEST_ERR (nvme_dev_ub_mmiowr_intmask_with_msix,"undefined access to interrupt mask clr" " when MSI-X is enabled" );/* should be ignored, fall through for now */ } n->bar.intms &= ~(data &0xffffffff ); n->bar.intmc = n->bar.intms; -trace_nvme_mmio_intm_clr (data &0xffffffff , - n->bar.intmc); +trace_nvme_dev_mmio_intm_clr (data &0xffffffff , n->bar.intmc);nvme_irq_check (n);break ;case 0x14 :/* CC */ -trace_nvme_mmio_cfg (data &0xffffffff ); +trace_nvme_dev_mmio_cfg (data &0xffffffff );/* Windows first sends data, then sends enable bit */ if (!NVME_CC_EN (data) && !NVME_CC_EN (n->bar.cc) && !NVME_CC_SHN (data) && !NVME_CC_SHN (n->bar.cc))
@@ -1071,42 +1069,42 @@ static void nvme_write_bar(NvmeCtrl *n, hwaddr offset, uint64_t data,if (NVME_CC_EN (data) && !NVME_CC_EN (n->bar.cc)) { n->bar.cc = data;if (unlikely (nvme_start_ctrl (n))) { -trace_nvme_err_startfail (); +trace_nvme_dev_err_startfail (); n->bar.csts =NVME_CSTS_FAILED ; }else { -trace_nvme_mmio_start_success (); +trace_nvme_dev_mmio_start_success (); n->bar.csts =NVME_CSTS_READY ; } }else if (!NVME_CC_EN (data) &&NVME_CC_EN (n->bar.cc)) { -trace_nvme_mmio_stopped (); +trace_nvme_dev_mmio_stopped ();nvme_clear_ctrl (n); n->bar.csts &= ~NVME_CSTS_READY ; }if (NVME_CC_SHN (data) && !(NVME_CC_SHN (n->bar.cc))) { -trace_nvme_mmio_shutdown_set (); +trace_nvme_dev_mmio_shutdown_set ();nvme_clear_ctrl (n); n->bar.cc = data; n->bar.csts |=NVME_CSTS_SHST_COMPLETE ; }else if (!NVME_CC_SHN (data) &&NVME_CC_SHN (n->bar.cc)) { -trace_nvme_mmio_shutdown_cleared (); +trace_nvme_dev_mmio_shutdown_cleared (); n->bar.csts &= ~NVME_CSTS_SHST_COMPLETE ; n->bar.cc = data; }break ;case 0x1C :/* CSTS */ if (data & (1 <<4 )) { -NVME_GUEST_ERR (nvme_ub_mmiowr_ssreset_w1c_unsupported, +NVME_GUEST_ERR (nvme_dev_ub_mmiowr_ssreset_w1c_unsupported,"attempted to W1C CSTS.NSSRO" " but CAP.NSSRS is zero (not supported)" ); }else if (data !=0 ) { -NVME_GUEST_ERR (nvme_ub_mmiowr_ro_csts, +NVME_GUEST_ERR (nvme_dev_ub_mmiowr_ro_csts,"attempted to set a read only bit" " of controller status" ); }break ;case 0x20 :/* NSSR */ if (data ==0x4E564D65 ) { -trace_nvme_ub_mmiowr_ssreset_unsupported (); +trace_nvme_dev_ub_mmiowr_ssreset_unsupported (); }else {/* The spec says that writes of other values have no effect */ return ;
@@ -1114,35 +1112,35 @@ static void nvme_write_bar(NvmeCtrl *n, hwaddr offset, uint64_t data,break ;case 0x24 :/* AQA */ n->bar.aqa = data &0xffffffff ; -trace_nvme_mmio_aqattr (data &0xffffffff ); +trace_nvme_dev_mmio_aqattr (data &0xffffffff );break ;case 0x28 :/* ASQ */ n->bar.asq = data; -trace_nvme_mmio_asqaddr (data); +trace_nvme_dev_mmio_asqaddr (data);break ;case 0x2c :/* ASQ hi */ n->bar.asq |= data <<32 ; -trace_nvme_mmio_asqaddr_hi (data, n->bar.asq); +trace_nvme_dev_mmio_asqaddr_hi (data, n->bar.asq);break ;case 0x30 :/* ACQ */ -trace_nvme_mmio_acqaddr (data); +trace_nvme_dev_mmio_acqaddr (data); n->bar.acq = data;break ;case 0x34 :/* ACQ hi */ n->bar.acq |= data <<32 ; -trace_nvme_mmio_acqaddr_hi (data, n->bar.acq); +trace_nvme_dev_mmio_acqaddr_hi (data, n->bar.acq);break ;case 0x38 :/* CMBLOC */ -NVME_GUEST_ERR (nvme_ub_mmiowr_cmbloc_reserved, +NVME_GUEST_ERR (nvme_dev_ub_mmiowr_cmbloc_reserved,"invalid write to reserved CMBLOC" " when CMBSZ is zero, ignored" );return ;case 0x3C :/* CMBSZ */ -NVME_GUEST_ERR (nvme_ub_mmiowr_cmbsz_readonly, +NVME_GUEST_ERR (nvme_dev_ub_mmiowr_cmbsz_readonly,"invalid write to read only CMBSZ, ignored" );return ;default : -NVME_GUEST_ERR (nvme_ub_mmiowr_invalid, +NVME_GUEST_ERR (nvme_dev_ub_mmiowr_invalid,"invalid MMIO write," " offset=0x%" PRIx64", data=%" PRIx64"" , offset, data);
@@ -1157,12 +1155,12 @@ static uint64_t nvme_mmio_read(void *opaque, hwaddr addr, unsigned size)uint64_t val =0 ;if (unlikely (addr & (sizeof (uint32_t ) -1 ))) { -NVME_GUEST_ERR (nvme_ub_mmiord_misaligned32, +NVME_GUEST_ERR (nvme_dev_ub_mmiord_misaligned32,"MMIO read not 32-bit aligned," " offset=0x%" PRIx64"" , addr);/* should RAZ, fall through for now */ }else if (unlikely (size <sizeof (uint32_t ))) { -NVME_GUEST_ERR (nvme_ub_mmiord_toosmall, +NVME_GUEST_ERR (nvme_dev_ub_mmiord_toosmall,"MMIO read smaller than 32-bits," " offset=0x%" PRIx64"" , addr);/* should RAZ, fall through for now */
@@ -1171,7 +1169,7 @@ static uint64_t nvme_mmio_read(void *opaque, hwaddr addr, unsigned size)if (addr <sizeof (n->bar)) {memcpy (&val, ptr + addr, size); }else { -NVME_GUEST_ERR (nvme_ub_mmiord_invalid_ofs, +NVME_GUEST_ERR (nvme_dev_ub_mmiord_invalid_ofs,"MMIO read beyond last register," " offset=0x%" PRIx64", returning 0" , addr); }
@@ -1184,7 +1182,7 @@ static void nvme_process_db(NvmeCtrl *n, hwaddr addr, int val)uint32_t qid;if (unlikely (addr & ((1 <<2 ) -1 ))) { -NVME_GUEST_ERR (nvme_ub_db_wr_misaligned, +NVME_GUEST_ERR (nvme_dev_ub_db_wr_misaligned,"doorbell write not 32-bit aligned," " offset=0x%" PRIx64", ignoring" , addr);return ;
@@ -1199,7 +1197,7 @@ static void nvme_process_db(NvmeCtrl *n, hwaddr addr, int val) qid = (addr - (0x1000 + (1 <<2 ))) >>3 ;if (unlikely (nvme_check_cqid (n, qid))) { -NVME_GUEST_ERR (nvme_ub_db_wr_invalid_cq, +NVME_GUEST_ERR (nvme_dev_ub_db_wr_invalid_cq,"completion queue doorbell write" " for nonexistent queue," " sqid=%" PRIu32", ignoring" , qid);
@@ -1208,7 +1206,7 @@ static void nvme_process_db(NvmeCtrl *n, hwaddr addr, int val) cq = n->cq[qid];if (unlikely (new_head >= cq->size)) { - NVME_GUEST_ERR(nvme_ub_db_wr_invalid_cqhead, + NVME_GUEST_ERR(nvme_dev_ub_db_wr_invalid_cqhead, "completion queue doorbell write value" " beyond queue size, sqid=%"PRIu32"," " new_head=%"PRIu16", ignoring",
@@ -1237,7 +1235,7 @@ static void nvme_process_db(NvmeCtrl *n, hwaddr addr, int val) qid = (addr -0x1000 ) >>3 ;if (unlikely (nvme_check_sqid (n, qid))) { -NVME_GUEST_ERR (nvme_ub_db_wr_invalid_sq, +NVME_GUEST_ERR (nvme_dev_ub_db_wr_invalid_sq,"submission queue doorbell write" " for nonexistent queue," " sqid=%" PRIu32", ignoring" , qid);
@@ -1246,7 +1244,7 @@ static void nvme_process_db(NvmeCtrl *n, hwaddr addr, int val) sq = n->sq[qid];if (unlikely (new_tail >= sq->size)) { - NVME_GUEST_ERR(nvme_ub_db_wr_invalid_sqtail, + NVME_GUEST_ERR(nvme_dev_ub_db_wr_invalid_sqtail, "submission queue doorbell write value" " beyond queue size, sqid=%"PRIu32"," " new_tail=%"PRIu16", ignoring",
hw/block/trace-events +86 -86
182 lines not on this page · raw message
Signature · 1 line
2.26.0
PATCH 10/16 nvme: factor out device state setup
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
--- hw/block/nvme.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
hw/block/nvme.c +11 -6
@@ -1339,6 +1339,15 @@ static int nvme_check_constraints(NvmeCtrl *n, Error **errp)return 0 ; } +static void nvme_init_state (NvmeCtrl *n) +{ + n->num_namespaces =1 ; + n->reg_size =pow2ceil (0x1008 +2 * (n->params.max_ioqpairs) *4 ); + n->namespaces =g_new0 (NvmeNamespace, n->num_namespaces); + n->sq = g_new0(NvmeSQueue *, n->params.max_ioqpairs + 1); + n->cq = g_new0(NvmeCQueue *, n->params.max_ioqpairs + 1); +} +static void nvme_realize (PCIDevice *pci_dev,Error **errp) {NvmeCtrl *n =NVME (pci_dev);
@@ -1352,6 +1361,8 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)return ; } +nvme_init_state (n); + bs_size =blk_getlength (n->conf.blk);if (bs_size <0 ) {error_setg (errp,"could not get backing file size" );
@@ -1370,14 +1381,8 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)pci_config_set_class (pci_dev->config,PCI_CLASS_STORAGE_EXPRESS );pcie_endpoint_cap_init (pci_dev,0x80 ); - n->num_namespaces =1 ; - n->reg_size =pow2ceil (0x1008 +2 * (n->params.max_ioqpairs) *4 ); n->ns_size = bs_size / (uint64_t )n->num_namespaces; - n->namespaces =g_new0 (NvmeNamespace, n->num_namespaces); - n->sq = g_new0(NvmeSQueue *, n->params.max_ioqpairs + 1); - n->cq = g_new0(NvmeCQueue *, n->params.max_ioqpairs + 1); -memory_region_init_io (&n->iomem,OBJECT (n), &nvme_mmio_ops, n,"nvme" , n->reg_size); pci_register_bar(pci_dev, 0,
Signature · 1 line
2.26.0
PATCH 11/16 nvme: factor out block backend setup
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
--- hw/block/nvme.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
hw/block/nvme.c +12 -3
@@ -1348,6 +1348,17 @@ static void nvme_init_state(NvmeCtrl *n) n->cq = g_new0(NvmeCQueue *, n->params.max_ioqpairs + 1); } +static int nvme_init_blk (NvmeCtrl *n,Error **errp) +{ +blkconf_blocksizes (&n->conf); +if (!blkconf_apply_backend_options (&n->conf,blk_is_read_only (n->conf.blk), + false, errp)) { +return -1 ; + } + +return 0 ; +} +static void nvme_realize (PCIDevice *pci_dev,Error **errp) {NvmeCtrl *n =NVME (pci_dev);
@@ -1369,9 +1380,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)return ; } -blkconf_blocksizes (&n->conf); -if (!blkconf_apply_backend_options (&n->conf,blk_is_read_only (n->conf.blk), - false, errp)) { +if (nvme_init_blk (n, errp)) {return ; }
Signature · 1 line
2.26.0
PATCH 8/16 nvme: remove redundant cmbloc/cmbsz members
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
--- hw/block/nvme.c | 7 ++----- hw/block/nvme.h | 2 -- 2 files changed, 2 insertions(+), 7 deletions(-)
hw/block/nvme.c +2 -5
@@ -63,7 +63,7 @@ static bool nvme_addr_is_cmb(NvmeCtrl *n, hwaddr addr)static void nvme_addr_read (NvmeCtrl *n,hwaddr addr,void *buf,int size) { -if (n->cmbsz &&nvme_addr_is_cmb (n, addr)) { +if (n->bar.cmbsz &&nvme_addr_is_cmb (n, addr)) {memcpy (buf, (void *)&n->cmbuf[addr - n->ctrl_mem.addr], size);return ; }
@@ -157,7 +157,7 @@ static uint16_t nvme_map_prp(QEMUSGList *qsg, QEMUIOVector *iov, uint64_t prp1,if (unlikely (!prp1)) {trace_nvme_dev_err_invalid_prp ();return NVME_INVALID_FIELD |NVME_DNR ; - }else if (n->cmbsz && prp1 >= n->ctrl_mem.addr && + }else if (n->bar.cmbsz && prp1 >= n->ctrl_mem.addr && prp1 < n->ctrl_mem.addr +int128_get64 (n->ctrl_mem.size)) { qsg->nsg =0 ;qemu_iovec_init (iov, num_prps);
@@ -1419,9 +1419,6 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)NVME_CMBSZ_SET_SZU (n->bar.cmbsz,2 );/* MBs */ NVME_CMBSZ_SET_SZ (n->bar.cmbsz, n->params.cmb_size_mb); - n->cmbloc = n->bar.cmbloc; - n->cmbsz = n->bar.cmbsz; - n->cmbuf =g_malloc0 (NVME_CMBSZ_GETSIZE (n->bar.cmbsz));memory_region_init_io (&n->ctrl_mem,OBJECT (n), &nvme_cmb_ops, n,"nvme-cmb" ,NVME_CMBSZ_GETSIZE (n->bar.cmbsz));
hw/block/nvme.h +0 -2
@@ -88,8 +88,6 @@ typedef struct NvmeCtrl {uint32_t num_namespaces;uint32_t max_q_ents;uint64_t ns_size; -uint32_t cmbsz; -uint32_t cmbloc;uint8_t *cmbuf;uint64_t irq_status;uint64_t host_timestamp;/* Timestamp sent by the host */
Signature · 1 line
2.26.0
PATCH 12/16 nvme: add namespace helpers
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
Introduce some small helpers to make the next patches easier on the eye.
--- hw/block/nvme.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
hw/block/nvme.h +16 -0
@@ -67,6 +67,17 @@ typedef struct NvmeNamespace {NvmeIdNs id_ns; } NvmeNamespace; +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; +} +#define TYPE_NVME "nvme"#define NVME (obj) \ OBJECT_CHECK(NvmeCtrl, (obj), TYPE_NVME)
@@ -101,4 +112,9 @@ typedef struct NvmeCtrl { NvmeIdCtrl id_ctrl; } NvmeCtrl; +static inline uint64_t nvme_ns_nlbas (NvmeCtrl *n,NvmeNamespace *ns) +{ +return n->ns_size >>nvme_ns_lbads (ns); +} +#endif /* HW_NVME_H */
Signature · 1 line
2.26.0
PATCH 14/16 nvme: factor out pci setup
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
--- hw/block/nvme.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-)
hw/block/nvme.c +20 -12
@@ -1382,6 +1382,24 @@ static int nvme_init_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp)return 0 ; } +static void nvme_init_pci (NvmeCtrl *n,PCIDevice *pci_dev) +{ +uint8_t *pci_conf = pci_dev->config; + + pci_conf[PCI_INTERRUPT_PIN ] =1 ; +pci_config_set_prog_interface (pci_conf,0x2 ); +pci_config_set_vendor_id (pci_conf,PCI_VENDOR_ID_INTEL ); +pci_config_set_device_id (pci_conf,0x5845 ); +pci_config_set_class (pci_conf,PCI_CLASS_STORAGE_EXPRESS ); +pcie_endpoint_cap_init (pci_dev,0x80 ); + +memory_region_init_io (&n->iomem,OBJECT (n), &nvme_mmio_ops, n,"nvme" , + n->reg_size); +pci_register_bar (pci_dev,0 ,PCI_BASE_ADDRESS_SPACE_MEMORY | +PCI_BASE_ADDRESS_MEM_TYPE_64 , &n->iomem); +msix_init_exclusive_bar (pci_dev, n->params.max_ioqpairs +1 ,4 ,NULL ); +} +static void nvme_realize (PCIDevice *pci_dev,Error **errp) {NvmeCtrl *n =NVME (pci_dev);
@@ -1400,19 +1418,9 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)return ; } +nvme_init_pci (n, pci_dev); + pci_conf = pci_dev->config; - pci_conf[PCI_INTERRUPT_PIN ] =1 ; -pci_config_set_prog_interface (pci_dev->config,0x2 ); -pci_config_set_class (pci_dev->config,PCI_CLASS_STORAGE_EXPRESS ); -pcie_endpoint_cap_init (pci_dev,0x80 ); - -memory_region_init_io (&n->iomem,OBJECT (n), &nvme_mmio_ops, n, -"nvme" , n->reg_size); -pci_register_bar (pci_dev,0 , -PCI_BASE_ADDRESS_SPACE_MEMORY |PCI_BASE_ADDRESS_MEM_TYPE_64 , - &n->iomem); -msix_init_exclusive_bar (pci_dev, n->params.max_ioqpairs +1 ,4 ,NULL ); - id->vid =cpu_to_le16 (pci_get_word (pci_conf +PCI_VENDOR_ID )); id->ssvid =cpu_to_le16 (pci_get_word (pci_conf +PCI_SUBSYSTEM_VENDOR_ID ));strpadcpy ((char *)id->mn,sizeof (id->mn),"QEMU NVMe Ctrl" ,' ' );
Signature · 1 line
2.26.0
Re: [PATCH 13/16] nvme: factor out namespace setup
In reply to Klaus JensenQuoted 62 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-)hw/block/nvme.c +23
-7@@ -1359,13 +1359,35 @@ static int nvme_init_blk(NvmeCtrl *n, Error **errp)return 0 ; } +static int nvme_init_namespace (NvmeCtrl *n,NvmeNamespace *ns,Error **errp) +{ +int64_t bs_size; +NvmeIdNs *id_ns = &ns->id_ns; + + bs_size =blk_getlength (n->conf.blk); +if (bs_size <0 ) { +error_setg_errno (errp, -bs_size,"could not get backing file size" ); +return -1 ; + } + + n->ns_size = bs_size; + + id_ns->lbaf[0 ].ds =BDRV_SECTOR_BITS ; + id_ns->nsze =cpu_to_le64 (nvme_ns_nlbas (n, ns)); + +/* no thin provisioning */ + id_ns->ncap = id_ns->nsze; + id_ns->nuse = id_ns->ncap; + +return 0 ; +} +static void nvme_realize (PCIDevice *pci_dev,Error **errp) {NvmeCtrl *n =NVME (pci_dev);NvmeIdCtrl *id = &n->id_ctrl;int i; -int64_t bs_size;uint8_t *pci_conf;if (nvme_check_constraints (n, errp)) {@@ -1374,12 +1396,6 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)nvme_init_state (n); - bs_size =blk_getlength (n->conf.blk); -if (bs_size <0 ) { -error_setg (errp,"could not get backing file size" ); -return ; - } -if (nvme_init_blk (n, errp)) {return ; }
hw/block/nvme.c static void nvme_realize(PCIDevice *pci_dev, Error **errp) · line 1393
Quoted 4 lines
hw/block/nvme.c +0
-1@@ -1390,8 +1406,6 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)pci_config_set_class (pci_dev->config,PCI_CLASS_STORAGE_EXPRESS );pcie_endpoint_cap_init (pci_dev,0x80 ); - n->ns_size = bs_size / (uint64_t )n->num_namespaces;
I'm not sure this line belong to this patch.
Quoted 27 lines
hw/block/nvme.c +3
-13-memory_region_init_io (&n->iomem,OBJECT (n), &nvme_mmio_ops, n,"nvme" , n->reg_size); pci_register_bar(pci_dev, 0,@@ -1455,18 +1469,9 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp) }for (i =0 ; i < n->num_namespaces; i++) { -NvmeNamespace *ns = &n->namespaces[i]; -NvmeIdNs *id_ns = &ns->id_ns; - id_ns->nsfeat =0 ; - id_ns->nlbaf =0 ; - id_ns->flbas =0 ; - id_ns->mc =0 ; - id_ns->dpc =0 ; - id_ns->dps =0 ; - id_ns->lbaf[0 ].ds =BDRV_SECTOR_BITS ; - id_ns->ncap = id_ns->nuse = id_ns->nsze = -cpu_to_le64 (n->ns_size >> - id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX (ns->id_ns.flbas)].ds); +if (nvme_init_namespace (n, &n->namespaces[i], errp)) { +return ; + } } }
PATCH 15/16 nvme: factor out cmb setup
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
--- hw/block/nvme.c | 50 +++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 22 deletions(-)
hw/block/nvme.c +28 -22
@@ -44,6 +44,8 @@#include "trace.h" #include "nvme.h" +#define NVME_CMB_BIR 2 +#define NVME_GUEST_ERR (trace, fmt, ...) \ do { \ (trace_##trace)(__VA_ARGS__); \
@@ -1382,6 +1384,28 @@ static int nvme_init_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp)return 0 ; } +static void nvme_init_cmb (NvmeCtrl *n,PCIDevice *pci_dev) +{ +NVME_CMBLOC_SET_BIR (n->bar.cmbloc,NVME_CMB_BIR ); +NVME_CMBLOC_SET_OFST (n->bar.cmbloc,0 ); + +NVME_CMBSZ_SET_SQS (n->bar.cmbsz,1 ); +NVME_CMBSZ_SET_CQS (n->bar.cmbsz,0 ); +NVME_CMBSZ_SET_LISTS (n->bar.cmbsz,0 ); +NVME_CMBSZ_SET_RDS (n->bar.cmbsz,1 ); +NVME_CMBSZ_SET_WDS (n->bar.cmbsz,1 ); +NVME_CMBSZ_SET_SZU (n->bar.cmbsz,2 ); +NVME_CMBSZ_SET_SZ (n->bar.cmbsz, n->params.cmb_size_mb); + + n->cmbuf =g_malloc0 (NVME_CMBSZ_GETSIZE (n->bar.cmbsz)); +memory_region_init_io (&n->ctrl_mem,OBJECT (n), &nvme_cmb_ops, n, +"nvme-cmb" ,NVME_CMBSZ_GETSIZE (n->bar.cmbsz)); +pci_register_bar (pci_dev,NVME_CMBLOC_BIR (n->bar.cmbloc), +PCI_BASE_ADDRESS_SPACE_MEMORY | +PCI_BASE_ADDRESS_MEM_TYPE_64 | +PCI_BASE_ADDRESS_MEM_PREFETCH , &n->ctrl_mem); +} +static void nvme_init_pci (NvmeCtrl *n,PCIDevice *pci_dev) {uint8_t *pci_conf = pci_dev->config;
@@ -1398,6 +1422,10 @@ static void nvme_init_pci(NvmeCtrl *n, PCIDevice *pci_dev)pci_register_bar (pci_dev,0 ,PCI_BASE_ADDRESS_SPACE_MEMORY |PCI_BASE_ADDRESS_MEM_TYPE_64 , &n->iomem);msix_init_exclusive_bar (pci_dev, n->params.max_ioqpairs +1 ,4 ,NULL ); + +if (n->params.cmb_size_mb) { +nvme_init_cmb (n, pci_dev); + } }static void nvme_realize (PCIDevice *pci_dev,Error **errp)
@@ -1454,28 +1482,6 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp) n->bar.vs =0x00010200 ; n->bar.intmc = n->bar.intms =0 ; -if (n->params.cmb_size_mb) { - -NVME_CMBLOC_SET_BIR (n->bar.cmbloc,2 ); -NVME_CMBLOC_SET_OFST (n->bar.cmbloc,0 ); - -NVME_CMBSZ_SET_SQS (n->bar.cmbsz,1 ); -NVME_CMBSZ_SET_CQS (n->bar.cmbsz,0 ); -NVME_CMBSZ_SET_LISTS (n->bar.cmbsz,0 ); -NVME_CMBSZ_SET_RDS (n->bar.cmbsz,1 ); -NVME_CMBSZ_SET_WDS (n->bar.cmbsz,1 ); -NVME_CMBSZ_SET_SZU (n->bar.cmbsz,2 );/* MBs */ -NVME_CMBSZ_SET_SZ (n->bar.cmbsz, n->params.cmb_size_mb); - - n->cmbuf =g_malloc0 (NVME_CMBSZ_GETSIZE (n->bar.cmbsz)); -memory_region_init_io (&n->ctrl_mem,OBJECT (n), &nvme_cmb_ops, n, -"nvme-cmb" ,NVME_CMBSZ_GETSIZE (n->bar.cmbsz)); -pci_register_bar (pci_dev,NVME_CMBLOC_BIR (n->bar.cmbloc), -PCI_BASE_ADDRESS_SPACE_MEMORY |PCI_BASE_ADDRESS_MEM_TYPE_64 | -PCI_BASE_ADDRESS_MEM_PREFETCH , &n->ctrl_mem); - - } -for (i =0 ; i < n->num_namespaces; i++) {if (nvme_init_namespace (n, &n->namespaces[i], errp)) {return ;
Signature · 1 line
2.26.0
PATCH 13/16 nvme: factor out namespace setup
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
--- hw/block/nvme.c | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-)
hw/block/nvme.c +26 -21
@@ -1359,13 +1359,35 @@ static int nvme_init_blk(NvmeCtrl *n, Error **errp)return 0 ; } +static int nvme_init_namespace (NvmeCtrl *n,NvmeNamespace *ns,Error **errp) +{ +int64_t bs_size; +NvmeIdNs *id_ns = &ns->id_ns; + + bs_size =blk_getlength (n->conf.blk); +if (bs_size <0 ) { +error_setg_errno (errp, -bs_size,"could not get backing file size" ); +return -1 ; + } + + n->ns_size = bs_size; + + id_ns->lbaf[0 ].ds =BDRV_SECTOR_BITS ; + id_ns->nsze =cpu_to_le64 (nvme_ns_nlbas (n, ns)); + +/* no thin provisioning */ + id_ns->ncap = id_ns->nsze; + id_ns->nuse = id_ns->ncap; + +return 0 ; +} +static void nvme_realize (PCIDevice *pci_dev,Error **errp) {NvmeCtrl *n =NVME (pci_dev);NvmeIdCtrl *id = &n->id_ctrl;int i; -int64_t bs_size;uint8_t *pci_conf;if (nvme_check_constraints (n, errp)) {
@@ -1374,12 +1396,6 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)nvme_init_state (n); - bs_size =blk_getlength (n->conf.blk); -if (bs_size <0 ) { -error_setg (errp,"could not get backing file size" ); -return ; - } -if (nvme_init_blk (n, errp)) {return ; }
@@ -1390,8 +1406,6 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)pci_config_set_class (pci_dev->config,PCI_CLASS_STORAGE_EXPRESS );pcie_endpoint_cap_init (pci_dev,0x80 ); - n->ns_size = bs_size / (uint64_t )n->num_namespaces; -memory_region_init_io (&n->iomem,OBJECT (n), &nvme_mmio_ops, n,"nvme" , n->reg_size); pci_register_bar(pci_dev, 0,
@@ -1455,18 +1469,9 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp) }for (i =0 ; i < n->num_namespaces; i++) { -NvmeNamespace *ns = &n->namespaces[i]; -NvmeIdNs *id_ns = &ns->id_ns; - id_ns->nsfeat =0 ; - id_ns->nlbaf =0 ; - id_ns->flbas =0 ; - id_ns->mc =0 ; - id_ns->dpc =0 ; - id_ns->dps =0 ; - id_ns->lbaf[0 ].ds =BDRV_SECTOR_BITS ; - id_ns->ncap = id_ns->nuse = id_ns->nsze = -cpu_to_le64 (n->ns_size >> - id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX (ns->id_ns.flbas)].ds); +if (nvme_init_namespace (n, &n->namespaces[i], errp)) { +return ; + } } }
Signature · 1 line
2.26.0
Re: [PATCH 12/16] nvme: add namespace helpers
In reply to Klaus JensenQuoted 33 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Introduce some small helpers to make the next patches easier on the eye.
Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)hw/block/nvme.h +11
-0@@ -67,6 +67,17 @@ typedef struct NvmeNamespace {NvmeIdNs id_ns; } NvmeNamespace; +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; +} +#define TYPE_NVME "nvme"#define NVME (obj) \ OBJECT_CHECK(NvmeCtrl, (obj), TYPE_NVME)
hw/block/nvme.h typedef struct NvmeCtrl { · line 120
Quoted 9 lines
hw/block/nvme.h +5
-0@@ -101,4 +112,9 @@ typedef struct NvmeCtrl { NvmeIdCtrl id_ctrl; } NvmeCtrl; +static inline uint64_t nvme_ns_nlbas (NvmeCtrl *n,NvmeNamespace *ns) +{ +return n->ns_size >>nvme_ns_lbads (ns); +} +#endif /* HW_NVME_H */
Personally I'd use it directly in the same patch, this is one more hunk:
@@ -1455,18 +1469,9 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp) [...]
- id_ns->ncap = id_ns->nuse = id_ns->nsze =
- cpu_to_le64(n->ns_size >>
- id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas)].ds);
+ cpu_to_le64(nvme_ns_nlbas(n, ns));
Re: [PATCH 15/16] nvme: factor out cmb setup
In reply to Klaus JensenQuoted 25 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 50 +++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 22 deletions(-)hw/block/nvme.c +3
-0@@ -44,6 +44,8 @@#include "trace.h" #include "nvme.h" +#define NVME_CMB_BIR 2 +#define NVME_GUEST_ERR (trace, fmt, ...) \ do { \ (trace_##trace)(__VA_ARGS__); \@@ -1382,6 +1384,28 @@ static int nvme_init_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp)return 0 ; } +static void nvme_init_cmb (NvmeCtrl *n,PCIDevice *pci_dev)
hw/block/nvme.c static int nvme_init_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp) · line 1397
Quoted 10 lines
hw/block/nvme.c +10
-0+{ +NVME_CMBLOC_SET_BIR (n->bar.cmbloc,NVME_CMB_BIR ); +NVME_CMBLOC_SET_OFST (n->bar.cmbloc,0 ); + +NVME_CMBSZ_SET_SQS (n->bar.cmbsz,1 ); +NVME_CMBSZ_SET_CQS (n->bar.cmbsz,0 ); +NVME_CMBSZ_SET_LISTS (n->bar.cmbsz,0 ); +NVME_CMBSZ_SET_RDS (n->bar.cmbsz,1 ); +NVME_CMBSZ_SET_WDS (n->bar.cmbsz,1 ); +NVME_CMBSZ_SET_SZU (n->bar.cmbsz,2 );
We lost the /* MBs */ comment, otherwise:
Quoted 55 lines
hw/block/nvme.c +15
-22+NVME_CMBSZ_SET_SZ (n->bar.cmbsz, n->params.cmb_size_mb); + + n->cmbuf =g_malloc0 (NVME_CMBSZ_GETSIZE (n->bar.cmbsz)); +memory_region_init_io (&n->ctrl_mem,OBJECT (n), &nvme_cmb_ops, n, +"nvme-cmb" ,NVME_CMBSZ_GETSIZE (n->bar.cmbsz)); +pci_register_bar (pci_dev,NVME_CMBLOC_BIR (n->bar.cmbloc), +PCI_BASE_ADDRESS_SPACE_MEMORY | +PCI_BASE_ADDRESS_MEM_TYPE_64 | +PCI_BASE_ADDRESS_MEM_PREFETCH , &n->ctrl_mem); +} +static void nvme_init_pci (NvmeCtrl *n,PCIDevice *pci_dev) {uint8_t *pci_conf = pci_dev->config;@@ -1398,6 +1422,10 @@ static void nvme_init_pci(NvmeCtrl *n, PCIDevice *pci_dev)pci_register_bar (pci_dev,0 ,PCI_BASE_ADDRESS_SPACE_MEMORY |PCI_BASE_ADDRESS_MEM_TYPE_64 , &n->iomem);msix_init_exclusive_bar (pci_dev, n->params.max_ioqpairs +1 ,4 ,NULL ); + +if (n->params.cmb_size_mb) { +nvme_init_cmb (n, pci_dev); + } }static void nvme_realize (PCIDevice *pci_dev,Error **errp)@@ -1454,28 +1482,6 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp) n->bar.vs =0x00010200 ; n->bar.intmc = n->bar.intms =0 ; -if (n->params.cmb_size_mb) { - -NVME_CMBLOC_SET_BIR (n->bar.cmbloc,2 ); -NVME_CMBLOC_SET_OFST (n->bar.cmbloc,0 ); - -NVME_CMBSZ_SET_SQS (n->bar.cmbsz,1 ); -NVME_CMBSZ_SET_CQS (n->bar.cmbsz,0 ); -NVME_CMBSZ_SET_LISTS (n->bar.cmbsz,0 ); -NVME_CMBSZ_SET_RDS (n->bar.cmbsz,1 ); -NVME_CMBSZ_SET_WDS (n->bar.cmbsz,1 ); -NVME_CMBSZ_SET_SZU (n->bar.cmbsz,2 );/* MBs */ -NVME_CMBSZ_SET_SZ (n->bar.cmbsz, n->params.cmb_size_mb); - - n->cmbuf =g_malloc0 (NVME_CMBSZ_GETSIZE (n->bar.cmbsz)); -memory_region_init_io (&n->ctrl_mem,OBJECT (n), &nvme_cmb_ops, n, -"nvme-cmb" ,NVME_CMBSZ_GETSIZE (n->bar.cmbsz)); -pci_register_bar (pci_dev,NVME_CMBLOC_BIR (n->bar.cmbloc), -PCI_BASE_ADDRESS_SPACE_MEMORY |PCI_BASE_ADDRESS_MEM_TYPE_64 | -PCI_BASE_ADDRESS_MEM_PREFETCH , &n->ctrl_mem); - - } -for (i =0 ; i < n->num_namespaces; i++) {if (nvme_init_namespace (n, &n->namespaces[i], errp)) {return ;
Re: [PATCH 14/16] nvme: factor out pci setup
In reply to Klaus JensenQuoted 12 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-)hw/block/nvme.c +0
-0
hw/block/nvme.c static int nvme_init_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp) · line 1390
Quoted 9 lines
hw/block/nvme.c +6
-0@@ -1382,6 +1382,24 @@ static int nvme_init_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp)return 0 ; } +static void nvme_init_pci (NvmeCtrl *n,PCIDevice *pci_dev) +{ +uint8_t *pci_conf = pci_dev->config; + + pci_conf[PCI_INTERRUPT_PIN ] =1 ; +pci_config_set_prog_interface (pci_conf,0x2 );
<--
hw/block/nvme.c static int nvme_init_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp) · line 1392
Quoted 2 lines
hw/block/nvme.c +2
-0+pci_config_set_vendor_id (pci_conf,PCI_VENDOR_ID_INTEL ); +pci_config_set_device_id (pci_conf,0x5845 );
-->
This is new. Already inherited by nvme_class_init().
Quoted 36 lines
hw/block/nvme.c +12
-12+pci_config_set_class (pci_conf,PCI_CLASS_STORAGE_EXPRESS ); +pcie_endpoint_cap_init (pci_dev,0x80 ); + +memory_region_init_io (&n->iomem,OBJECT (n), &nvme_mmio_ops, n,"nvme" , + n->reg_size); +pci_register_bar (pci_dev,0 ,PCI_BASE_ADDRESS_SPACE_MEMORY | +PCI_BASE_ADDRESS_MEM_TYPE_64 , &n->iomem); +msix_init_exclusive_bar (pci_dev, n->params.max_ioqpairs +1 ,4 ,NULL ); +} +static void nvme_realize (PCIDevice *pci_dev,Error **errp) {NvmeCtrl *n =NVME (pci_dev);@@ -1400,19 +1418,9 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)return ; } +nvme_init_pci (n, pci_dev); + pci_conf = pci_dev->config; - pci_conf[PCI_INTERRUPT_PIN ] =1 ; -pci_config_set_prog_interface (pci_dev->config,0x2 ); -pci_config_set_class (pci_dev->config,PCI_CLASS_STORAGE_EXPRESS ); -pcie_endpoint_cap_init (pci_dev,0x80 ); - -memory_region_init_io (&n->iomem,OBJECT (n), &nvme_mmio_ops, n, -"nvme" , n->reg_size); -pci_register_bar (pci_dev,0 , -PCI_BASE_ADDRESS_SPACE_MEMORY |PCI_BASE_ADDRESS_MEM_TYPE_64 , - &n->iomem); -msix_init_exclusive_bar (pci_dev, n->params.max_ioqpairs +1 ,4 ,NULL ); - id->vid =cpu_to_le16 (pci_get_word (pci_conf +PCI_VENDOR_ID )); id->ssvid =cpu_to_le16 (pci_get_word (pci_conf +PCI_SUBSYSTEM_VENDOR_ID ));strpadcpy ((char *)id->mn,sizeof (id->mn),"QEMU NVMe Ctrl" ,' ' );
Re: [PATCH 11/16] nvme: factor out block backend setup
In reply to Klaus JensenQuoted 14 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)hw/block/nvme.c +0
-0@@ -1348,6 +1348,17 @@ static void nvme_init_state(NvmeCtrl *n) n->cq = g_new0(NvmeCQueue *, n->params.max_ioqpairs + 1); }
hw/block/nvme.c static void nvme_init_state(NvmeCtrl *n) · line 1359
Quoted 10 lines
hw/block/nvme.c +9
-0+static int nvme_init_blk (NvmeCtrl *n,Error **errp) +{ +blkconf_blocksizes (&n->conf); +if (!blkconf_apply_backend_options (&n->conf,blk_is_read_only (n->conf.blk), + false, errp)) { +return -1 ; + } + +return 0 ;
I'm not sure this is a correct usage of the 'propagating errors' API (see CODING_STYLE.rst and include/qapi/error.h), I'd expect this function to return void, and use a local_error & error_propagate() in nvme_realize().
However this works, so:
Quoted 17 lines
hw/block/nvme.c +3
-3+} +static void nvme_realize (PCIDevice *pci_dev,Error **errp) {NvmeCtrl *n =NVME (pci_dev);@@ -1369,9 +1380,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)return ; } -blkconf_blocksizes (&n->conf); -if (!blkconf_apply_backend_options (&n->conf,blk_is_read_only (n->conf.blk), - false, errp)) { +if (nvme_init_blk (n, errp)) {return ; }
Re: [PATCH 13/16] nvme: factor out namespace setup
In reply to Philippe Mathieu-DaudéQuoted 55 lines · Philippe Mathieu-Daudé
Quoted 54 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-)hw/block/nvme.c +23
-7@@ -1359,13 +1359,35 @@ static int nvme_init_blk(NvmeCtrl *n, Error **errp)return 0 ; } +static int nvme_init_namespace (NvmeCtrl *n,NvmeNamespace *ns,Error **errp) +{ +int64_t bs_size; +NvmeIdNs *id_ns = &ns->id_ns; + + bs_size =blk_getlength (n->conf.blk); +if (bs_size <0 ) { +error_setg_errno (errp, -bs_size,"could not get backing file size" ); +return -1 ; + } + + n->ns_size = bs_size; + + id_ns->lbaf[0 ].ds =BDRV_SECTOR_BITS ; + id_ns->nsze =cpu_to_le64 (nvme_ns_nlbas (n, ns)); + +/* no thin provisioning */ + id_ns->ncap = id_ns->nsze; + id_ns->nuse = id_ns->ncap; + +return 0 ; +} +static void nvme_realize (PCIDevice *pci_dev,Error **errp) {NvmeCtrl *n =NVME (pci_dev);NvmeIdCtrl *id = &n->id_ctrl;int i; -int64_t bs_size;uint8_t *pci_conf;if (nvme_check_constraints (n, errp)) {@@ -1374,12 +1396,6 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)nvme_init_state (n); - bs_size =blk_getlength (n->conf.blk); -if (bs_size <0 ) { -error_setg (errp,"could not get backing file size" ); -return ; - } -if (nvme_init_blk (n, errp)) {
Quoted 9 lines
hw/block/nvme.c static void nvme_realize(PCIDevice *pci_dev, Error **errp) · line 1392
Quoted 6 lines
hw/block/nvme.c +0
-1return ; }@@ -1390,8 +1406,6 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)pci_config_set_class (pci_dev->config,PCI_CLASS_STORAGE_EXPRESS );pcie_endpoint_cap_init (pci_dev,0x80 ); - n->ns_size = bs_size / (uint64_t )n->num_namespaces;I'm not sure this line belong to this patch.
It does. It is already there in the middle of the realize function. It is moved to nvme_init_namespace as
n->ns_size = bs_size;
since only a single namespace can be configured anyway. I will remove the for-loop that initializes multiple namespaces as well.
Re: [PATCH 10/16] nvme: factor out device state setup
In reply to Klaus JensenQuoted 42 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)hw/block/nvme.c +11
-1@@ -1339,6 +1339,15 @@ static int nvme_check_constraints(NvmeCtrl *n, Error **errp)return 0 ; } +static void nvme_init_state (NvmeCtrl *n) +{ + n->num_namespaces =1 ; + n->reg_size =pow2ceil (0x1008 +2 * (n->params.max_ioqpairs) *4 ); + n->namespaces =g_new0 (NvmeNamespace, n->num_namespaces); + n->sq = g_new0(NvmeSQueue *, n->params.max_ioqpairs + 1); + n->cq = g_new0(NvmeCQueue *, n->params.max_ioqpairs + 1); +} +static void nvme_realize (PCIDevice *pci_dev,Error **errp) {NvmeCtrl *n =NVME (pci_dev);@@ -1352,6 +1361,8 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)return ; } +nvme_init_state (n); + bs_size =blk_getlength (n->conf.blk);if (bs_size <0 ) {error_setg (errp,"could not get backing file size" );@@ -1370,14 +1381,8 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)pci_config_set_class (pci_dev->config,PCI_CLASS_STORAGE_EXPRESS );pcie_endpoint_cap_init (pci_dev,0x80 ); - n->num_namespaces =1 ;
hw/block/nvme.c static void nvme_realize(PCIDevice *pci_dev, Error **errp) · line 1388
Quoted 10 lines
hw/block/nvme.c +0
-5- n->reg_size =pow2ceil (0x1008 +2 * (n->params.max_ioqpairs) *4 ); n->ns_size = bs_size / (uint64_t )n->num_namespaces; - n->namespaces =g_new0 (NvmeNamespace, n->num_namespaces); - n->sq = g_new0(NvmeSQueue *, n->params.max_ioqpairs + 1); - n->cq = g_new0(NvmeCQueue *, n->params.max_ioqpairs + 1); -memory_region_init_io (&n->iomem,OBJECT (n), &nvme_mmio_ops, n,"nvme" , n->reg_size); pci_register_bar(pci_dev, 0,
Re: [PATCH 09/16] nvme: factor out property/constraint checks
In reply to Klaus JensenQuoted 34 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 52 ++++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 20 deletions(-)hw/block/nvme.c +19
-0@@ -1308,6 +1308,37 @@ static const MemoryRegionOps nvme_cmb_ops = { }, }; +static int nvme_check_constraints (NvmeCtrl *n,Error **errp) +{ +NvmeParams *params = &n->params; + +if (params->num_queues) { +warn_report ("num_queues is deprecated; please use max_ioqpairs " +"instead" ); + + params->max_ioqpairs = params->num_queues -1 ; + } + +if (params->max_ioqpairs <1 || + params->max_ioqpairs >PCI_MSIX_FLAGS_QSIZE ) { +error_setg (errp,"max_ioqpairs must be between 1 and %d" , +PCI_MSIX_FLAGS_QSIZE ); +return -1 ; + } + +if (!n->conf.blk) {
hw/block/nvme.c static const MemoryRegionOps nvme_cmb_ops = { · line 1339
Quoted 10 lines
hw/block/nvme.c +10
-0+error_setg (errp,"drive property not set" ); +return -1 ; + } + +if (!params->serial) { +error_setg (errp,"serial property not set" ); +return -1 ; + } + +return 0 ;
Similar comment than nvme_init_blk(), I'd expect this function to return void, and use a local_error & error_propagate() in nvme_realize().
Quoted 41 lines
hw/block/nvme.c +3
-20+} +static void nvme_realize (PCIDevice *pci_dev,Error **errp) {NvmeCtrl *n =NVME (pci_dev);@@ -1317,22 +1348,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)int64_t bs_size;uint8_t *pci_conf; -if (n->params.num_queues) { -warn_report ("num_queues is deprecated; please use max_ioqpairs " -"instead" ); - - n->params.max_ioqpairs = n->params.num_queues -1 ; - } - -if (n->params.max_ioqpairs <1 || - n->params.max_ioqpairs >PCI_MSIX_FLAGS_QSIZE ) { -error_setg (errp,"max_ioqpairs must be between 1 and %d" , -PCI_MSIX_FLAGS_QSIZE ); -return ; - } - -if (!n->conf.blk) { -error_setg (errp,"drive property not set" ); +if (nvme_check_constraints (n, errp)) {return ; }@@ -1342,10 +1358,6 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)return ; } -if (!n->params.serial) { -error_setg (errp,"serial property not set" ); -return ; - }blkconf_blocksizes (&n->conf);if (!blkconf_apply_backend_options (&n->conf,blk_is_read_only (n->conf.blk), false, errp)) {
Re: [PATCH 13/16] nvme: factor out namespace setup
In reply to Klaus Birkelund JensenQuoted 5 lines · Klaus Birkelund Jensen
Quoted 3 lines · Philippe Mathieu-Daudé
I'm not sure this line belong to this patch.
Quoted 7 lines
It does. It is already there in the middle of the realize function. It is moved to
nvme_init_namespaceasn->ns_size = bs_size;since only a single namespace can be configured anyway. I will remove the for-loop that initializes multiple namespaces as well.
I'm gonna backtrack on that. Removing that for loop is just noise I think.
Re: [PATCH 07/16] nvme: add max_ioqpairs device parameter
In reply to Klaus JensenQuoted 151 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
The
num_queuesdevice paramater has a slightly confusing meaning because it accounts for the admin queue pair which is not really optional. Secondly, it is really a maximum value of queues allowed.Add a new
max_ioqpairsparameter that only accounts for I/O queue pairs, but keepnum_queuesfor compatibility.Signed-off-by Klaus Jensen <[email protected]>Reviewed-by Maxim Levitsky <[email protected]>--- hw/block/nvme.c | 46 ++++++++++++++++++++++++++++------------------ hw/block/nvme.h | 4 +++- 2 files changed, 31 insertions(+), 19 deletions(-)hw/block/nvme.c +28
-18@@ -19,7 +19,7 @@* -drive file=<file>,if=none,id=<drive_id> * -device nvme,drive=<drive_id>,serial=<serial>,id=<id[optional]>, \ * cmb_size_mb=<cmb_size_mb[optional]>, \ -* num_queues=<N[optional]> +* max_ioqpairs=<N[optional]> * * Note cmb_size_mb denotes size of CMB in MB. CMB is assumed to be at * offset 0 in BAR2 and supports only WDS, RDS and SQS for now. @@ -27,6 +27,7 @@#include "qemu/osdep.h" #include "qemu/units.h" +#include "qemu/error-report.h" #include "hw/block/block.h" #include "hw/pci/msix.h" #include "hw/pci/pci.h" @@ -72,12 +73,12 @@ static void nvme_addr_read(NvmeCtrl *n, hwaddr addr, void *buf, int size)static int nvme_check_sqid (NvmeCtrl *n,uint16_t sqid) { -return sqid < n->params.num_queues && n->sq[sqid] !=NULL ?0 :-1 ; +return sqid < n->params.max_ioqpairs +1 && n->sq[sqid] !=NULL ?0 :-1 ; }static int nvme_check_cqid (NvmeCtrl *n,uint16_t cqid) { -return cqid < n->params.num_queues && n->cq[cqid] !=NULL ?0 :-1 ; +return cqid < n->params.max_ioqpairs +1 && n->cq[cqid] !=NULL ?0 :-1 ; }static void nvme_inc_cq_tail (NvmeCQueue *cq)@@ -639,7 +640,7 @@ static uint16_t nvme_create_cq(NvmeCtrl *n, NvmeCmd *cmd)trace_nvme_dev_err_invalid_create_cq_addr (prp1);return NVME_INVALID_FIELD |NVME_DNR ; } -if (unlikely (vector > n->params.num_queues)) { +if (unlikely (vector > n->params.max_ioqpairs +1 )) {trace_nvme_dev_err_invalid_create_cq_vector (vector);return NVME_INVALID_IRQ_VECTOR |NVME_DNR ; }@@ -791,8 +792,8 @@ static uint16_t nvme_get_feature(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)trace_nvme_dev_getfeat_vwcache (result ?"enabled" :"disabled" );break ;case NVME_NUMBER_OF_QUEUES : - result =cpu_to_le32 ((n->params.num_queues -2 ) | - ((n->params.num_queues -2 ) <<16 )); + result =cpu_to_le32 ((n->params.max_ioqpairs -1 ) | + ((n->params.max_ioqpairs -1 ) <<16 ));trace_nvme_dev_getfeat_numq (result);break ;case NVME_TIMESTAMP :@@ -836,10 +837,10 @@ static uint16_t nvme_set_feature(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)case NVME_NUMBER_OF_QUEUES :trace_nvme_dev_setfeat_numq ((dw11 &0xFFFF ) +1 , ((dw11 >>16 ) &0xFFFF ) +1 , - n->params.num_queues -1 , - n->params.num_queues -1 ); - req->cqe.result =cpu_to_le32 ((n->params.num_queues -2 ) | - ((n->params.num_queues -2 ) <<16 )); + n->params.max_ioqpairs, + n->params.max_ioqpairs); + req->cqe.result =cpu_to_le32 ((n->params.max_ioqpairs -1 ) | + ((n->params.max_ioqpairs -1 ) <<16 ));break ;case NVME_TIMESTAMP :return nvme_set_feature_timestamp (n, cmd);@@ -910,12 +911,12 @@ static void nvme_clear_ctrl(NvmeCtrl *n)blk_drain (n->conf.blk); -for (i =0 ; i < n->params.num_queues; i++) { +for (i =0 ; i < n->params.max_ioqpairs +1 ; i++) {if (n->sq[i] !=NULL ) {nvme_free_sq (n->sq[i], n); } } -for (i =0 ; i < n->params.num_queues; i++) { +for (i =0 ; i < n->params.max_ioqpairs +1 ; i++) {if (n->cq[i] !=NULL ) {nvme_free_cq (n->cq[i], n); }@@ -1316,8 +1317,17 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)int64_t bs_size;uint8_t *pci_conf; -if (!n->params.num_queues) { -error_setg (errp,"num_queues can't be zero" ); +if (n->params.num_queues) { +warn_report ("num_queues is deprecated; please use max_ioqpairs " +"instead" ); + + n->params.max_ioqpairs = n->params.num_queues -1 ; + } + +if (n->params.max_ioqpairs <1 || + n->params.max_ioqpairs >PCI_MSIX_FLAGS_QSIZE ) { +error_setg (errp,"max_ioqpairs must be between 1 and %d" , +PCI_MSIX_FLAGS_QSIZE );return ; }@@ -1349,19 +1359,19 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)pcie_endpoint_cap_init (pci_dev,0x80 ); n->num_namespaces =1 ; - n->reg_size =pow2ceil (0x1000 +2 * n->params.num_queues *4 ); + n->reg_size =pow2ceil (0x1008 +2 * (n->params.max_ioqpairs) *4 ); n->ns_size = bs_size / (uint64_t )n->num_namespaces; n->namespaces =g_new0 (NvmeNamespace, n->num_namespaces); - n->sq = g_new0(NvmeSQueue *, n->params.num_queues); - n->cq = g_new0(NvmeCQueue *, n->params.num_queues); + n->sq = g_new0(NvmeSQueue *, n->params.max_ioqpairs + 1); + n->cq = g_new0(NvmeCQueue *, n->params.max_ioqpairs + 1);memory_region_init_io (&n->iomem,OBJECT (n), &nvme_mmio_ops, n,"nvme" , n->reg_size);pci_register_bar (pci_dev,0 ,PCI_BASE_ADDRESS_SPACE_MEMORY |PCI_BASE_ADDRESS_MEM_TYPE_64 , &n->iomem); -msix_init_exclusive_bar (pci_dev, n->params.num_queues,4 ,NULL ); +msix_init_exclusive_bar (pci_dev, n->params.max_ioqpairs +1 ,4 ,NULL ); id->vid =cpu_to_le16 (pci_get_word (pci_conf +PCI_VENDOR_ID )); id->ssvid =cpu_to_le16 (pci_get_word (pci_conf +PCI_SUBSYSTEM_VENDOR_ID ));hw/block/nvme.h +0
-0
hw/block/nvme.h line 14
Quoted 10 lines
hw/block/nvme.h +2
-1@@ -6,11 +6,13 @@#define DEFINE_NVME_PROPERTIES (_state, _props) \ DEFINE_PROP_STRING("serial", _state, _props.serial), \ DEFINE_PROP_UINT32("cmb_size_mb", _state, _props.cmb_size_mb, 0), \ - DEFINE_PROP_UINT32("num_queues", _state, _props.num_queues, 64) + DEFINE_PROP_UINT32("num_queues", _state, _props.num_queues, 0), \ + DEFINE_PROP_UINT32("max_ioqpairs", _state, _props.max_ioqpairs, 64) typedef struct NvmeParams { char *serial; uint32_t num_queues;
I'm tempted to rename it 'deprecated_num_queues' ... Can you add a comment such /* deprecated since 5.0 */?
Quoted 5 lines
hw/block/nvme.h +1
-0+uint32_t max_ioqpairs;uint32_t cmb_size_mb; } NvmeParams;
Re: [PATCH 11/16] nvme: factor out block backend setup
In reply to Philippe Mathieu-DaudéQuoted 29 lines · Philippe Mathieu-Daudé
Quoted 13 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)hw/block/nvme.c +0
-0@@ -1348,6 +1348,17 @@ static void nvme_init_state(NvmeCtrl *n) n->cq = g_new0(NvmeCQueue *, n->params.max_ioqpairs + 1);hw/block/nvme.c static void nvme_init_state(NvmeCtrl *n) · line 1358
Quoted 10 lines
hw/block/nvme.c +9
-0} +static int nvme_init_blk (NvmeCtrl *n,Error **errp) +{ +blkconf_blocksizes (&n->conf); +if (!blkconf_apply_backend_options (&n->conf,blk_is_read_only (n->conf.blk), + false, errp)) { +return -1 ; + } + +return 0 ;I'm not sure this is a correct usage of the 'propagating errors' API (see
CODING_STYLE.rstandinclude/qapi/error.h), I'd expect this function to return void, and use alocal_error&error_propagate()innvme_realize().
Quoted 3 lines
However this works, so:
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
So, I get that and did use the propagate functionality earlier. But I still used the int return. I'm not sure about the style if returning void - should I check if errp is now non-NULL? Point is that I need to return early since the later calls could fail if previous calls did not complete successfully.
Re: [PATCH 16/16] nvme: factor out controller identify setup
In reply to Klaus JensenQuoted 6 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-)
The review is trivial using 'git-diff -W'.
Quoted 65 lines
hw/block/nvme.c +24
-18@@ -1428,27 +1428,11 @@ static void nvme_init_pci(NvmeCtrl *n, PCIDevice *pci_dev) } } -static void nvme_realize (PCIDevice *pci_dev,Error **errp) +static void nvme_init_ctrl (NvmeCtrl *n,PCIDevice *pci_dev) { -NvmeCtrl *n =NVME (pci_dev);NvmeIdCtrl *id = &n->id_ctrl; +uint8_t *pci_conf = pci_dev->config; -int i; -uint8_t *pci_conf; - -if (nvme_check_constraints (n, errp)) { -return ; - } - -nvme_init_state (n); - -if (nvme_init_blk (n, errp)) { -return ; - } - -nvme_init_pci (n, pci_dev); - - pci_conf = pci_dev->config; id->vid =cpu_to_le16 (pci_get_word (pci_conf +PCI_VENDOR_ID )); id->ssvid =cpu_to_le16 (pci_get_word (pci_conf +PCI_SUBSYSTEM_VENDOR_ID ));strpadcpy ((char *)id->mn,sizeof (id->mn),"QEMU NVMe Ctrl" ,' ' );@@ -1482,6 +1466,28 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp) n->bar.vs =0x00010200 ; n->bar.intmc = n->bar.intms =0 ; + +} + +static void nvme_realize (PCIDevice *pci_dev,Error **errp) +{ +NvmeCtrl *n =NVME (pci_dev); + +int i; + +if (nvme_check_constraints (n, errp)) { +return ; + } + +nvme_init_state (n); + +if (nvme_init_blk (n, errp)) { +return ; + } + +nvme_init_pci (n, pci_dev); +nvme_init_ctrl (n, pci_dev); +for (i =0 ; i < n->num_namespaces; i++) {if (nvme_init_namespace (n, &n->namespaces[i], errp)) {return ;
Re: [PATCH 11/16] nvme: factor out block backend setup
In reply to Klaus Birkelund JensenQuoted 34 lines · Klaus Birkelund Jensen
Quoted 29 lines · Philippe Mathieu-Daudé
Quoted 13 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)hw/block/nvme.c +0
-0@@ -1348,6 +1348,17 @@ static void nvme_init_state(NvmeCtrl *n) n->cq = g_new0(NvmeCQueue *, n->params.max_ioqpairs + 1);hw/block/nvme.c static void nvme_init_state(NvmeCtrl *n) · line 1358
Quoted 10 lines
hw/block/nvme.c +9
-0} +static int nvme_init_blk (NvmeCtrl *n,Error **errp) +{ +blkconf_blocksizes (&n->conf); +if (!blkconf_apply_backend_options (&n->conf,blk_is_read_only (n->conf.blk), + false, errp)) { +return -1 ; + } + +return 0 ;I'm not sure this is a correct usage of the 'propagating errors' API (see
CODING_STYLE.rstandinclude/qapi/error.h), I'd expect this function to return void, and use alocal_error&error_propagate()innvme_realize().Quoted 3 lines
However this works, so:
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Quoted 5 lines
So, I get that and did use the propagate functionality earlier. But I still used the int return. I'm not sure about the style if returning void - should I check if errp is now non-NULL? Point is that I need to return early since the later calls could fail if previous calls did not complete successfully.
Nevermind, I got it. I've changed it to propagate it correctly.
Re: [PATCH 01/16] nvme: fix pci doorbell size calculation
In reply to Klaus JensenQuoted 11 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
The size of the BAR is
0x1000(main registers) + 8 bytes for each queue. Currently, the size of the BAR is calculated like so:n->reg_size = pow2ceil(0x1004 + 2 * (n->params.num_queues + 1) * 4);Since the '
num_queues' parameter already accounts for the admin queue, this should in any case not need to be incremented by one. Also, the size should be initialized to (0x1000).
Quoted 5 lines
n->reg_size = pow2ceil(0x1000 + 2 * n->params.num_queues * 4);This, with the default value of
num_queues(64), we will set aside room for 1 admin queue and 63 I/O queues (4 bytes per doorbell, 2 doorbells per queue).
It seems you are right, but I'd feel safer with a Ack-by from Keith.
Do you mind adding definitions such:
#define NVME_IO_SIZE (4 * KiB)
#define DOORBELL_SIZE 4
#define DOORBELL_COUNT 2
Looking at nvme_set_feature() I see better why you introduce max_ioqpairs in patch #7:
case NVME_NUMBER_OF_QUEUES:
trace_nvme_setfeat_numq((dw11 & 0xFFFF) + 1,
((dw11 >> 16) & 0xFFFF) + 1,
n->num_queues - 1, n->num_queues - 1);
req->cqe.result =
cpu_to_le32((n->num_queues - 2) | ((n->num_queues - 2) << 16));
break;Quoted 20 lines
Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/block/nvme.c +1
-1@@ -1345,7 +1345,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)pcie_endpoint_cap_init (pci_dev,0x80 ); n->num_namespaces =1 ; - n->reg_size =pow2ceil (0x1004 +2 * (n->num_queues +1 ) *4 ); + n->reg_size =pow2ceil (0x1000 +2 * n->num_queues *4 ); n->ns_size = bs_size / (uint64_t )n->num_namespaces; n->namespaces =g_new0 (NvmeNamespace, n->num_namespaces);
Re: [PATCH 02/16] nvme: rename trace events to nvme_dev
In reply to Klaus JensenQuoted 3 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Change the prefix of all nvme device related trace events to '
nvme_dev'
Another option is 'pci_nvme'. None of them make me happy but I can't find a better name.
Quoted 33 lines
to not clash with trace events from the nvme block driver.
Signed-off-by Klaus Jensen <[email protected]>Acked-by Keith Busch <[email protected]>Reviewed-by Maxim Levitsky <[email protected]>--- hw/block/nvme.c | 190 +++++++++++++++++++++--------------------- hw/block/trace-events | 172 +++++++++++++++++++------------------- 2 files changed, 180 insertions(+), 182 deletions(-)hw/block/nvme.c +3
-3@@ -112,16 +112,16 @@ static void nvme_irq_assert(NvmeCtrl *n, NvmeCQueue *cq) {if (cq->irq_enabled) {if (msix_enabled (&(n->parent_obj))) { -trace_nvme_irq_msix (cq->vector); +trace_nvme_dev_irq_msix (cq->vector);msix_notify (&(n->parent_obj), cq->vector); }else { -trace_nvme_irq_pin (); +trace_nvme_dev_irq_pin ();assert (cq->cqid <64 ); n->irq_status |=1 << cq->cqid;nvme_irq_check (n); } }else { -trace_nvme_irq_masked (); +trace_nvme_dev_irq_masked (); } }
[...]
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series seems to have some coding style problems. See output below for more information:
Subject: [PATCH 00/16] nvme: refactoring and cleanups
Message-id: [email protected]
Type: series
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
2f7cc1f..73995d1 master -> master - [tag update] patchew/[email protected] -> patchew/[email protected] - [tag update] patchew/[email protected] -> patchew/[email protected] - [tag update] patchew/[email protected] -> patchew/[email protected] * [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
36a0670 nvme: factor out controller identify setup 0eba9ad nvme: factor out cmb setup
5b5feee nvme: factor out pci setup
577bb77 nvme: factor out namespace setup 9ac7fae nvme: add namespace helpers
ab9bbca nvme: factor out block backend setup ba90026 nvme: factor out device state setup b14d6d1 nvme: factor out property/constraint checks 35fc2dc nvme: remove redundant cmbloc/cmbsz members 802a9ab nvme: add max_ioqpairs device parameter acf5b71 nvme: refactor nvme_addr_read
945aa26 nvme: use constants in identify 06aee41 nvme: move device parameters to separate struct d1f279f nvme: remove superfluous breaks e659f34 nvme: rename trace events to nvme_dev f6d960a nvme: fix pci doorbell size calculation
=== OUTPUT BEGIN ===
1/16 Checking commit f6d960adefde (nvme: fix pci doorbell size calculation) 2/16 Checking commit e659f3474c29 (nvme: rename trace events to nvme_dev) 3/16 Checking commit d1f279f37080 (nvme: remove superfluous breaks) 4/16 Checking commit 06aee411cb67 (nvme: move device parameters to separate struct)
ERROR: Macros with complex values should be enclosed in parenthesis #181: FILE: hw/block/nvme.h:6:
+#define DEFINE_NVME_PROPERTIES(_state, _props) \
+ DEFINE_PROP_STRING("serial", _state, _props.serial), \
+ DEFINE_PROP_UINT32("cmb_size_mb", _state, _props.cmb_size_mb, 0), \
+ DEFINE_PROP_UINT32("num_queues", _state, _props.num_queues, 64)total: 1 errors, 0 warnings, 181 lines checked
Patch 4/16 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
5/16 Checking commit 945aa26e4b39 (nvme: use constants in identify) 6/16 Checking commit acf5b7156c93 (nvme: refactor nvme_addr_read) 7/16 Checking commit 802a9ab0f8c1 (nvme: add max_ioqpairs device parameter) 8/16 Checking commit 35fc2dcb7465 (nvme: remove redundant cmbloc/cmbsz members) 9/16 Checking commit b14d6d1afb3e (nvme: factor out property/constraint checks) 10/16 Checking commit ba9002645e0c (nvme: factor out device state setup) 11/16 Checking commit ab9bbcaa7af5 (nvme: factor out block backend setup) 12/16 Checking commit 9ac7faec3567 (nvme: add namespace helpers) 13/16 Checking commit 577bb7783e47 (nvme: factor out namespace setup) 14/16 Checking commit 5b5feee08d6d (nvme: factor out pci setup) 15/16 Checking commit 0eba9ade7b81 (nvme: factor out cmb setup) 16/16 Checking commit 36a0670099c1 (nvme: factor out controller identify setup) === OUTPUT END ===
Test command exited with code: 1
The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]