hw(/block/)nvme: spring cleaning
cover hw(/block/)nvme: spring cleaning
From: Klaus Jensen <[email protected]>
This series consists of various clean up patches.
The final patch moves nvme emulation from hw/block to hw/nvme.
Klaus Jensen (14):
hw/block/nvme: rename __nvme_zrm_open hw/block/nvme: rename __nvme_advance_zone_wp hw/block/nvme: rename __nvme_select_ns_iocs hw/block/nvme: consolidate header files hw/block/nvme: cleanup includes
hw/block/nvme: remove non-shared defines from header file hw/block/nvme: replace nvme_ns_status hw/block/nvme: cache lba and ms sizes hw/block/nvme: add metadata offset helper hw/block/nvme: streamline namespace array indexing hw/block/nvme: remove num_namespaces member hw/block/nvme: remove irrelevant zone resource checks hw/block/nvme: move zoned constraints checks hw/nvme: move nvme emulation out of hw/block
meson.build | 1 +
hw/block/nvme-dif.h | 63 ---
hw/block/nvme-ns.h | 229 ---------
hw/block/nvme-subsys.h | 59 ---
hw/block/nvme.h | 266 -----------
hw/nvme/nvme.h | 547 ++++++++++++++++++++++
hw/nvme/trace.h | 1 +
hw/{block/nvme.c => nvme/ctrl.c} | 204 ++++----
hw/{block/nvme-dif.c => nvme/dif.c} | 57 +--
hw/{block/nvme-ns.c => nvme/ns.c} | 104 ++--
hw/{block/nvme-subsys.c => nvme/subsys.c} | 13 +-
MAINTAINERS | 2 +-
hw/Kconfig | 1 +
hw/block/Kconfig | 5 -
hw/block/meson.build | 1 -
hw/block/trace-events | 206 --------
hw/meson.build | 1 +
hw/nvme/Kconfig | 4 +
hw/nvme/meson.build | 1 +
hw/nvme/trace-events | 204 ++++++++
20 files changed, 928 insertions(+), 1041 deletions(-)
delete mode 100644 hw/block/nvme-dif.h
delete mode 100644 hw/block/nvme-ns.h
delete mode 100644 hw/block/nvme-subsys.h
delete mode 100644 hw/block/nvme.h
create mode 100644 hw/nvme/nvme.h
create mode 100644 hw/nvme/trace.h
rename hw/{block/nvme.c => nvme/ctrl.c} (98%)
rename hw/{block/nvme-dif.c => nvme/dif.c} (90%)
rename hw/{block/nvme-ns.c => nvme/ns.c} (87%)
rename hw/{block/nvme-subsys.c => nvme/subsys.c} (85%)
create mode 100644 hw/nvme/Kconfig
create mode 100644 hw/nvme/meson.build
create mode 100644 hw/nvme/trace-eventsSignature · 1 line
2.31.1
PATCH 10/14 hw/block/nvme: streamline namespace array indexing
From: Klaus Jensen <[email protected]>
Streamline namespace array indexing such that both the subsystem and controller namespaces arrays are 1-indexed.
--- hw/block/nvme.h | 4 ++-- hw/block/nvme.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
hw/block/nvme.h +2 -2
@@ -438,7 +438,7 @@ typedef struct NvmeCtrl {NvmeSubsystem *subsys;NvmeNamespace namespace; -NvmeNamespace *namespaces[NVME_MAX_NAMESPACES ]; +NvmeNamespace *namespaces[NVME_MAX_NAMESPACES +1 ];NvmeSQueue **sq;NvmeCQueue **cq;NvmeSQueue admin_sq;
@@ -460,7 +460,7 @@ static inline NvmeNamespace *nvme_ns(NvmeCtrl *n, uint32_t nsid)return NULL ; } -return n->namespaces[nsid -1 ]; +return n->namespaces[nsid]; }static inline NvmeCQueue *nvme_cq (NvmeRequest *req)
hw/block/nvme.c +2 -2
@@ -4978,7 +4978,7 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)return NVME_NS_NOT_ATTACHED |NVME_DNR ; } - ctrl->namespaces[nsid -1 ] =NULL ; + ctrl->namespaces[nsid] =NULL ; ns->attached--;nvme_update_dmrsl (ctrl);
@@ -6151,7 +6151,7 @@ void nvme_attach_ns(NvmeCtrl *n, NvmeNamespace *ns)uint32_t nsid = ns->params.nsid;assert (nsid && nsid <=NVME_MAX_NAMESPACES ); - n->namespaces[nsid -1 ] = ns; + n->namespaces[nsid] = ns; ns->attached++; n->dmrsl = MIN_NON_ZERO(n->dmrsl,
Signature · 1 line
2.31.1
PATCH 1/14 hw/block/nvme: rename __nvme_zrm_open
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
Get rid of the (reserved) double underscore use.
--- hw/block/nvme.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
hw/block/nvme.c +10 -6
@@ -1682,8 +1682,12 @@ static void nvme_zrm_auto_transition_zone(NvmeNamespace *ns) } } -static uint16_t __nvme_zrm_open (NvmeNamespace *ns,NvmeZone *zone, -bool implicit) +enum { +NVME_ZRM_AUTO =1 <<0 , +}; + +static uint16_t nvme_zrm_open_flags (NvmeNamespace *ns,NvmeZone *zone, +int flags) {int act =0 ;uint16_t status;
@@ -1707,7 +1711,7 @@ static uint16_t __nvme_zrm_open(NvmeNamespace *ns, NvmeZone *zone,nvme_aor_inc_open (ns); -if (implicit) { +if (flags &NVME_ZRM_AUTO ) {nvme_assign_zone_state (ns, zone,NVME_ZONE_STATE_IMPLICITLY_OPEN );return NVME_SUCCESS ; }
@@ -1715,7 +1719,7 @@ static uint16_t __nvme_zrm_open(NvmeNamespace *ns, NvmeZone *zone,/* fallthrough */ case NVME_ZONE_STATE_IMPLICITLY_OPEN : -if (implicit) { +if (flags &NVME_ZRM_AUTO ) {return NVME_SUCCESS ; }
@@ -1733,12 +1737,12 @@ static uint16_t __nvme_zrm_open(NvmeNamespace *ns, NvmeZone *zone,static inline uint16_t nvme_zrm_auto (NvmeNamespace *ns,NvmeZone *zone) { -return __nvme_zrm_open (ns, zone, true); +return nvme_zrm_open_flags (ns, zone,NVME_ZRM_AUTO ); }static inline uint16_t nvme_zrm_open (NvmeNamespace *ns,NvmeZone *zone) { -return __nvme_zrm_open (ns, zone, false); +return nvme_zrm_open_flags (ns, zone,0 ); } static void __nvme_advance_zone_wp(NvmeNamespace *ns, NvmeZone *zone,
Signature · 1 line
2.31.1
PATCH 5/14 hw/block/nvme: cleanup includes
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
Clean up includes.
--- hw/block/nvme-dif.c | 7 +++---- hw/block/nvme-ns.c | 11 ++--------- hw/block/nvme-subsys.c | 12 +----------- hw/block/nvme.c | 22 +++++++++------------- 4 files changed, 15 insertions(+), 37 deletions(-)
hw/block/nvme-dif.c +3 -4
@@ -9,12 +9,11 @@*/ #include "qemu/osdep.h" -#include "hw/block/block.h" -#include "sysemu/dma.h" -#include "sysemu/block-backend.h" #include "qapi/error.h" -#include "trace.h" +#include "sysemu/block-backend.h" +#include "nvme.h" +#include "trace.h" uint16_t nvme_check_prinfo (NvmeNamespace *ns,uint16_t ctrl,uint64_t slba,uint32_t reftag)
hw/block/nvme-ns.c +2 -9
@@ -14,20 +14,13 @@#include "qemu/osdep.h" #include "qemu/units.h" -#include "qemu/cutils.h" -#include "qemu/log.h" #include "qemu/error-report.h" -#include "hw/block/block.h" -#include "hw/pci/pci.h" +#include "qapi/error.h" #include "sysemu/sysemu.h" #include "sysemu/block-backend.h" -#include "qapi/error.h" -#include "hw/qdev-properties.h" -#include "hw/qdev-core.h" - -#include "trace.h" #include "nvme.h" +#include "trace.h" #define MIN_DISCARD_GRANULARITY (4 * KiB)
hw/block/nvme-subsys.c +1 -11
@@ -6,19 +6,9 @@* This code is licensed under the GNU GPL v2. Refer COPYING. */ -#include "qemu/units.h" #include "qemu/osdep.h" -#include "qemu/uuid.h" -#include "qemu/iov.h" -#include "qemu/cutils.h" #include "qapi/error.h" -#include "hw/qdev-properties.h" -#include "hw/qdev-core.h" -#include "hw/block/block.h" -#include "block/aio.h" -#include "block/accounting.h" -#include "sysemu/sysemu.h" -#include "hw/pci/pci.h" +#include "nvme.h" int nvme_subsys_register_ctrl (NvmeCtrl *n,Error **errp)
hw/block/nvme.c +9 -13
@@ -135,24 +135,20 @@*/ #include "qemu/osdep.h" -#include "qemu/units.h" +#include "qemu/cutils.h" #include "qemu/error-report.h" -#include "hw/block/block.h" -#include "hw/pci/msix.h" -#include "hw/pci/pci.h" -#include "hw/qdev-properties.h" -#include "migration/vmstate.h" -#include "sysemu/sysemu.h" +#include "qemu/log.h" +#include "qemu/units.h" #include "qapi/error.h" #include "qapi/visitor.h" -#include "sysemu/hostmem.h" +#include "sysemu/sysemu.h" #include "sysemu/block-backend.h" -#include "exec/memory.h" -#include "qemu/log.h" -#include "qemu/module.h" -#include "qemu/cutils.h" -#include "trace.h" +#include "sysemu/hostmem.h" +#include "hw/pci/msix.h" +#include "migration/vmstate.h" +#include "nvme.h" +#include "trace.h" #define NVME_MAX_IOQPAIRS 0xffff#define NVME_DB_SIZE 4
Signature · 1 line
2.31.1
PATCH 2/14 hw/block/nvme: rename __nvme_advance_zone_wp
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
Get rid of the (reserved) double underscore use.
--- hw/block/nvme.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
hw/block/nvme.c +4 -4
@@ -1745,8 +1745,8 @@ static inline uint16_t nvme_zrm_open(NvmeNamespace *ns, NvmeZone *zone)return nvme_zrm_open_flags (ns, zone,0 ); } -static void __nvme_advance_zone_wp (NvmeNamespace *ns,NvmeZone *zone, -uint32_t nlb) +static void nvme_advance_zone_wp (NvmeNamespace *ns,NvmeZone *zone, +uint32_t nlb) { zone->d.wp += nlb;
@@ -1766,7 +1766,7 @@ static void nvme_finalize_zoned_write(NvmeNamespace *ns, NvmeRequest *req) nlb =le16_to_cpu (rw->nlb) +1 ; zone =nvme_get_zone_by_slba (ns, slba); -__nvme_advance_zone_wp (ns, zone, nlb); +nvme_advance_zone_wp (ns, zone, nlb); }static inline bool nvme_is_write (NvmeRequest *req)
@@ -2155,7 +2155,7 @@ out:uint64_t sdlba =le64_to_cpu (copy->sdlba);NvmeZone *zone =nvme_get_zone_by_slba (ns, sdlba); -__nvme_advance_zone_wp (ns, zone, ctx->nlb); +nvme_advance_zone_wp (ns, zone, ctx->nlb); }g_free (ctx->bounce);
Signature · 1 line
2.31.1
PATCH 7/14 hw/block/nvme: replace nvme_ns_status
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
The inline nvme_ns_status() helper only has a single call site. Remove it from the header file and inline it for real.
--- hw/block/nvme.h | 5 ----- hw/block/nvme.c | 15 ++++++++------- 2 files changed, 8 insertions(+), 12 deletions(-)
hw/block/nvme.h +0 -5
@@ -137,11 +137,6 @@ typedef struct NvmeNamespace { } features; } NvmeNamespace; -static inline uint16_t nvme_ns_status (NvmeNamespace *ns) -{ -return ns->status; -} -static inline uint32_t nvme_nsid (NvmeNamespace *ns) {if (ns) {
hw/block/nvme.c +8 -7
@@ -3594,8 +3594,8 @@ static uint16_t nvme_zone_mgmt_recv(NvmeCtrl *n, NvmeRequest *req)static uint16_t nvme_io_cmd (NvmeCtrl *n,NvmeRequest *req) { +NvmeNamespace *ns;uint32_t nsid =le32_to_cpu (req->cmd.nsid); -uint16_t status;trace_pci_nvme_io_cmd (nvme_cid (req), nsid,nvme_sqid (req), req->cmd.opcode,nvme_io_opc_str (req->cmd.opcode));
@@ -3627,21 +3627,22 @@ static uint16_t nvme_io_cmd(NvmeCtrl *n, NvmeRequest *req)return nvme_flush (n, req); } - req->ns =nvme_ns (n, nsid); -if (unlikely (!req->ns)) { + ns =nvme_ns (n, nsid); +if (unlikely (!ns)) {return NVME_INVALID_FIELD |NVME_DNR ; } -if (!(req->ns->iocs[req->cmd.opcode] &NVME_CMD_EFF_CSUPP )) { +if (!(ns->iocs[req->cmd.opcode] &NVME_CMD_EFF_CSUPP )) {trace_pci_nvme_err_invalid_opc (req->cmd.opcode);return NVME_INVALID_OPCODE |NVME_DNR ; } - status =nvme_ns_status (req->ns); -if (unlikely (status)) { -return status; +if (ns->status) { +return ns->status; } + req->ns = ns; +switch (req->cmd.opcode) {case NVME_CMD_WRITE_ZEROES :return nvme_write_zeroes (n, req);
Signature · 1 line
2.31.1
PATCH 8/14 hw/block/nvme: cache lba and ms sizes
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
There is no need to look up the lba size and metadata size in the LBA Format structure everytime we want to use it. And we use it a lot.
Cache the values in the NvmeNamespace and update them if the namespace is formatted.
--- hw/block/nvme.h | 37 ++++------------------------------- hw/block/nvme-dif.c | 45 ++++++++++++++++++------------------------- hw/block/nvme-ns.c | 26 +++++++++++++------------ hw/block/nvme.c | 47 ++++++++++++++++++--------------------------- 4 files changed, 56 insertions(+), 99 deletions(-)
hw/block/nvme.h +4 -33
@@ -109,6 +109,8 @@ typedef struct NvmeNamespace {int64_t size;int64_t mdata_offset;NvmeIdNs id_ns; +NvmeLBAF lbaf; +size_t lbasz;const uint32_t *iocs;uint8_t csi;uint16_t status;
@@ -146,36 +148,14 @@ static inline uint32_t nvme_nsid(NvmeNamespace *ns)return 0 ; } -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; -} - -/* convert an LBA to the equivalent in bytes */ static inline size_t nvme_l2b (NvmeNamespace *ns,uint64_t lba) { -return lba <<nvme_ns_lbads (ns); -} - -static inline size_t nvme_lsize (NvmeNamespace *ns) -{ -return 1 <<nvme_ns_lbads (ns); -} - -static inline uint16_t nvme_msize (NvmeNamespace *ns) -{ -return nvme_ns_lbaf (ns)->ms; +return lba << ns->lbaf.ds; }static inline size_t nvme_m2b (NvmeNamespace *ns,uint64_t lba) { -return nvme_msize (ns) * lba; +return ns->lbaf.ms * lba; }static inline bool nvme_ns_ext (NvmeNamespace *ns)
@@ -183,15 +163,6 @@ static inline bool nvme_ns_ext(NvmeNamespace *ns)return !!NVME_ID_NS_FLBAS_EXTENDED (ns->id_ns.flbas); } -/* calculate the number of LBAs that the namespace can accomodate */ -static inline uint64_t nvme_ns_nlbas (NvmeNamespace *ns) -{ -if (nvme_msize (ns)) { -return ns->size / (nvme_lsize (ns) +nvme_msize (ns)); - } -return ns->size >>nvme_ns_lbads (ns); -} -static inline NvmeZoneState nvme_get_zone_state (NvmeZone *zone) {return zone->d.zs >>4 ;
hw/block/nvme-dif.c +19 -26
137 lines not on this page · raw message
hw/block/nvme-ns.c +14 -12
@@ -31,7 +31,10 @@ void nvme_ns_init_format(NvmeNamespace *ns)BlockDriverInfo bdi;int npdg, nlbas, ret; - nlbas =nvme_ns_nlbas (ns); + ns->lbaf = id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX (id_ns->flbas)]; + ns->lbasz =1 << ns->lbaf.ds; + + nlbas = ns->size / (ns->lbasz + ns->lbaf.ms); id_ns->nsze =cpu_to_le64 (nlbas);
@@ -39,13 +42,13 @@ void nvme_ns_init_format(NvmeNamespace *ns) id_ns->ncap = id_ns->nsze; id_ns->nuse = id_ns->ncap; - ns->mdata_offset =nvme_l2b (ns, nlbas); + ns->mdata_offset = (int64_t )nlbas << ns->lbaf.ds; - npdg = ns->blkconf.discard_granularity /nvme_lsize (ns); + npdg = ns->blkconf.discard_granularity / ns->lbasz; ret =bdrv_get_info (blk_bs (ns->blkconf.blk), &bdi);if (ret >=0 && bdi.cluster_size > ns->blkconf.discard_granularity) { - npdg = bdi.cluster_size /nvme_lsize (ns); + npdg = bdi.cluster_size / ns->lbasz; } id_ns->npda = id_ns->npdg = npdg -1 ;
@@ -163,7 +166,6 @@ static int nvme_ns_init_blk(NvmeNamespace *ns, Error **errp)static int nvme_ns_zoned_check_calc_geometry (NvmeNamespace *ns,Error **errp) {uint64_t zone_size, zone_cap; -uint32_t lbasz =nvme_lsize (ns);/* Make sure that the values of ZNS properties are sane */ if (ns->params.zone_size_bs) {
@@ -181,14 +183,14 @@ static int nvme_ns_zoned_check_calc_geometry(NvmeNamespace *ns, Error **errp) "zone size %"PRIu64"B", zone_cap, zone_size);return -1 ; } -if (zone_size < lbasz) { +if (zone_size < ns->lbasz) {error_setg (errp,"zone size %" PRIu64"B too small, " -"must be at least %" PRIu32"B" , zone_size, lbasz); +"must be at least %zuB" , zone_size, ns->lbasz);return -1 ; } -if (zone_cap < lbasz) { +if (zone_cap < ns->lbasz) {error_setg (errp,"zone capacity %" PRIu64"B too small, " -"must be at least %" PRIu32"B" , zone_cap, lbasz); +"must be at least %zuB" , zone_cap, ns->lbasz);return -1 ; }
@@ -196,9 +198,9 @@ static int nvme_ns_zoned_check_calc_geometry(NvmeNamespace *ns, Error **errp)* Save the main zone geometry values to avoid * calculating them later again. */ - ns->zone_size = zone_size / lbasz; - ns->zone_capacity = zone_cap / lbasz; - ns->num_zones =nvme_ns_nlbas (ns) / ns->zone_size; + ns->zone_size = zone_size / ns->lbasz; + ns->zone_capacity = zone_cap / ns->lbasz; + ns->num_zones =le64_to_cpu (ns->id_ns.nsze) / ns->zone_size;/* Do a few more sanity checks of ZNS properties */ if (!ns->num_zones) {
hw/block/nvme.c +19 -28
139 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH 3/14 hw/block/nvme: rename __nvme_select_ns_iocs
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
Get rid of the (reserved) double underscore use.
--- hw/block/nvme.c | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-)
hw/block/nvme.c +23 -24
@@ -4916,7 +4916,25 @@ static void nvme_update_dmrsl(NvmeCtrl *n) } } -static void __nvme_select_ns_iocs (NvmeCtrl *n,NvmeNamespace *ns); +static void nvme_select_iocs_ns (NvmeCtrl *n,NvmeNamespace *ns) +{ + ns->iocs = nvme_cse_iocs_none; +switch (ns->csi) { +case NVME_CSI_NVM : +if (NVME_CC_CSS (n->bar.cc) !=NVME_CC_CSS_ADMIN_ONLY ) { + ns->iocs = nvme_cse_iocs_nvm; + } +break ; +case NVME_CSI_ZONED : +if (NVME_CC_CSS (n->bar.cc) ==NVME_CC_CSS_CSI ) { + ns->iocs = nvme_cse_iocs_zoned; + }else if (NVME_CC_CSS (n->bar.cc) ==NVME_CC_CSS_NVM ) { + ns->iocs = nvme_cse_iocs_nvm; + } +break ; + } +} +static uint16_t nvme_ns_attachment (NvmeCtrl *n,NvmeRequest *req) {NvmeNamespace *ns;
@@ -4967,7 +4985,7 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req) }nvme_attach_ns (ctrl, ns); -__nvme_select_ns_iocs (ctrl, ns); +nvme_select_iocs_ns (ctrl, ns); }else {if (!nvme_ns (ctrl, nsid)) {return NVME_NS_NOT_ATTACHED |NVME_DNR ;
@@ -5268,26 +5286,7 @@ static void nvme_ctrl_shutdown(NvmeCtrl *n) } } -static void __nvme_select_ns_iocs (NvmeCtrl *n,NvmeNamespace *ns) -{ - ns->iocs = nvme_cse_iocs_none; -switch (ns->csi) { -case NVME_CSI_NVM : -if (NVME_CC_CSS (n->bar.cc) !=NVME_CC_CSS_ADMIN_ONLY ) { - ns->iocs = nvme_cse_iocs_nvm; - } -break ; -case NVME_CSI_ZONED : -if (NVME_CC_CSS (n->bar.cc) ==NVME_CC_CSS_CSI ) { - ns->iocs = nvme_cse_iocs_zoned; - }else if (NVME_CC_CSS (n->bar.cc) ==NVME_CC_CSS_NVM ) { - ns->iocs = nvme_cse_iocs_nvm; - } -break ; - } -} - -static void nvme_select_ns_iocs (NvmeCtrl *n) +static void nvme_select_iocs (NvmeCtrl *n) {NvmeNamespace *ns;int i;
@@ -5298,7 +5297,7 @@ static void nvme_select_ns_iocs(NvmeCtrl *n)continue ; } -__nvme_select_ns_iocs (n, ns); +nvme_select_iocs_ns (n, ns); } }
@@ -5400,7 +5399,7 @@ static int nvme_start_ctrl(NvmeCtrl *n)QTAILQ_INIT (&n->aer_queue); -nvme_select_ns_iocs (n); +nvme_select_iocs (n);return 0 ; }
Signature · 1 line
2.31.1
PATCH 12/14 hw/block/nvme: remove irrelevant zone resource checks
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
It is not an error to report more active/open zones supported than the number of zones in the namespace.
--- hw/block/nvme-ns.c | 13 ------------- 1 file changed, 13 deletions(-)
hw/block/nvme-ns.c +0 -13
@@ -210,19 +210,6 @@ static int nvme_ns_zoned_check_calc_geometry(NvmeNamespace *ns, Error **errp)return -1 ; } -if (ns->params.max_open_zones > ns->num_zones) { -error_setg (errp, -"max_open_zones value %u exceeds the number of zones %u" , - ns->params.max_open_zones, ns->num_zones); -return -1 ; - } -if (ns->params.max_active_zones > ns->num_zones) { -error_setg (errp, -"max_active_zones value %u exceeds the number of zones %u" , - ns->params.max_active_zones, ns->num_zones); -return -1 ; - } -if (ns->params.max_active_zones) {if (ns->params.max_open_zones > ns->params.max_active_zones) { error_setg(errp, "max_open_zones (%u) exceeds max_active_zones (%u)",
Signature · 1 line
2.31.1
PATCH 4/14 hw/block/nvme: consolidate header files
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
In preparation for moving the nvme device into its own subtree, merge the header files into one.
Also add missing copyright notice and add list of authors with substantial contributions.
--- hw/block/nvme-dif.h | 63 ------- hw/block/nvme-ns.h | 229 ------------------------ hw/block/nvme-subsys.h | 59 ------- hw/block/nvme.h | 383 +++++++++++++++++++++++++++++++++++++---- hw/block/nvme-dif.c | 1 - hw/block/nvme-ns.c | 1 - hw/block/nvme-subsys.c | 1 - hw/block/nvme.c | 2 - 8 files changed, 348 insertions(+), 391 deletions(-) delete mode 100644 hw/block/nvme-dif.h delete mode 100644 hw/block/nvme-ns.h delete mode 100644 hw/block/nvme-subsys.h
hw/block/nvme-dif.h deleted +0 -63
@@ -1,63 +0,0 @@ -/* -* QEMU NVM Express End-to-End Data Protection support -* -* Copyright (c) 2021 Samsung Electronics Co., Ltd. -* -* Authors: -* Klaus Jensen <[email protected]> -* Gollu Appalanaidu <[email protected]> -*/ - -#ifndef HW_NVME_DIF_H -#define HW_NVME_DIF_H - -/* from Linux kernel (crypto/crct10dif_common.c) */ -static const uint16_t t10_dif_crc_table[256 ] = { -0x0000 ,0x8BB7 ,0x9CD9 ,0x176E ,0xB205 ,0x39B2 ,0x2EDC ,0xA56B , -0xEFBD ,0x640A ,0x7364 ,0xF8D3 ,0x5DB8 ,0xD60F ,0xC161 ,0x4AD6 , -0x54CD ,0xDF7A ,0xC814 ,0x43A3 ,0xE6C8 ,0x6D7F ,0x7A11 ,0xF1A6 , -0xBB70 ,0x30C7 ,0x27A9 ,0xAC1E ,0x0975 ,0x82C2 ,0x95AC ,0x1E1B , -0xA99A ,0x222D ,0x3543 ,0xBEF4 ,0x1B9F ,0x9028 ,0x8746 ,0x0CF1 , -0x4627 ,0xCD90 ,0xDAFE ,0x5149 ,0xF422 ,0x7F95 ,0x68FB ,0xE34C , -0xFD57 ,0x76E0 ,0x618E ,0xEA39 ,0x4F52 ,0xC4E5 ,0xD38B ,0x583C , -0x12EA ,0x995D ,0x8E33 ,0x0584 ,0xA0EF ,0x2B58 ,0x3C36 ,0xB781 , -0xD883 ,0x5334 ,0x445A ,0xCFED ,0x6A86 ,0xE131 ,0xF65F ,0x7DE8 , -0x373E ,0xBC89 ,0xABE7 ,0x2050 ,0x853B ,0x0E8C ,0x19E2 ,0x9255 , -0x8C4E ,0x07F9 ,0x1097 ,0x9B20 ,0x3E4B ,0xB5FC ,0xA292 ,0x2925 , -0x63F3 ,0xE844 ,0xFF2A ,0x749D ,0xD1F6 ,0x5A41 ,0x4D2F ,0xC698 , -0x7119 ,0xFAAE ,0xEDC0 ,0x6677 ,0xC31C ,0x48AB ,0x5FC5 ,0xD472 , -0x9EA4 ,0x1513 ,0x027D ,0x89CA ,0x2CA1 ,0xA716 ,0xB078 ,0x3BCF , -0x25D4 ,0xAE63 ,0xB90D ,0x32BA ,0x97D1 ,0x1C66 ,0x0B08 ,0x80BF , -0xCA69 ,0x41DE ,0x56B0 ,0xDD07 ,0x786C ,0xF3DB ,0xE4B5 ,0x6F02 , -0x3AB1 ,0xB106 ,0xA668 ,0x2DDF ,0x88B4 ,0x0303 ,0x146D ,0x9FDA , -0xD50C ,0x5EBB ,0x49D5 ,0xC262 ,0x6709 ,0xECBE ,0xFBD0 ,0x7067 , -0x6E7C ,0xE5CB ,0xF2A5 ,0x7912 ,0xDC79 ,0x57CE ,0x40A0 ,0xCB17 , -0x81C1 ,0x0A76 ,0x1D18 ,0x96AF ,0x33C4 ,0xB873 ,0xAF1D ,0x24AA , -0x932B ,0x189C ,0x0FF2 ,0x8445 ,0x212E ,0xAA99 ,0xBDF7 ,0x3640 , -0x7C96 ,0xF721 ,0xE04F ,0x6BF8 ,0xCE93 ,0x4524 ,0x524A ,0xD9FD , -0xC7E6 ,0x4C51 ,0x5B3F ,0xD088 ,0x75E3 ,0xFE54 ,0xE93A ,0x628D , -0x285B ,0xA3EC ,0xB482 ,0x3F35 ,0x9A5E ,0x11E9 ,0x0687 ,0x8D30 , -0xE232 ,0x6985 ,0x7EEB ,0xF55C ,0x5037 ,0xDB80 ,0xCCEE ,0x4759 , -0x0D8F ,0x8638 ,0x9156 ,0x1AE1 ,0xBF8A ,0x343D ,0x2353 ,0xA8E4 , -0xB6FF ,0x3D48 ,0x2A26 ,0xA191 ,0x04FA ,0x8F4D ,0x9823 ,0x1394 , -0x5942 ,0xD2F5 ,0xC59B ,0x4E2C ,0xEB47 ,0x60F0 ,0x779E ,0xFC29 , -0x4BA8 ,0xC01F ,0xD771 ,0x5CC6 ,0xF9AD ,0x721A ,0x6574 ,0xEEC3 , -0xA415 ,0x2FA2 ,0x38CC ,0xB37B ,0x1610 ,0x9DA7 ,0x8AC9 ,0x017E , -0x1F65 ,0x94D2 ,0x83BC ,0x080B ,0xAD60 ,0x26D7 ,0x31B9 ,0xBA0E , -0xF0D8 ,0x7B6F ,0x6C01 ,0xE7B6 ,0x42DD ,0xC96A ,0xDE04 ,0x55B3 -}; - -uint16_t nvme_check_prinfo (NvmeNamespace *ns,uint16_t ctrl,uint64_t slba, -uint32_t reftag); -uint16_t nvme_dif_mangle_mdata (NvmeNamespace *ns,uint8_t *mbuf,size_t mlen, -uint64_t slba); -void nvme_dif_pract_generate_dif (NvmeNamespace *ns,uint8_t *buf,size_t len, -uint8_t *mbuf,size_t mlen,uint16_t apptag, -uint32_t reftag); -uint16_t nvme_dif_check (NvmeNamespace *ns,uint8_t *buf,size_t len, -uint8_t *mbuf,size_t mlen,uint16_t ctrl, -uint64_t slba,uint16_t apptag, -uint16_t appmask,uint32_t reftag); -uint16_t nvme_dif_rw (NvmeCtrl *n,NvmeRequest *req); - -#endif /* HW_NVME_DIF_H */
hw/block/nvme-ns.h deleted +0 -229
229 lines not on this page · raw message
hw/block/nvme-subsys.h deleted +0 -59
59 lines not on this page · raw message
hw/block/nvme.h +348 -35
432 lines not on this page · raw message
hw/block/nvme-dif.c +0 -1
@@ -15,7 +15,6 @@#include "qapi/error.h" #include "trace.h" #include "nvme.h" -#include "nvme-dif.h" uint16_t nvme_check_prinfo (NvmeNamespace *ns,uint16_t ctrl,uint64_t slba,uint32_t reftag)
hw/block/nvme-ns.c +0 -1
@@ -28,7 +28,6 @@#include "trace.h" #include "nvme.h" -#include "nvme-ns.h" #define MIN_DISCARD_GRANULARITY (4 * KiB)
hw/block/nvme-subsys.c +0 -1
@@ -20,7 +20,6 @@#include "sysemu/sysemu.h" #include "hw/pci/pci.h" #include "nvme.h" -#include "nvme-subsys.h" int nvme_subsys_register_ctrl (NvmeCtrl *n,Error **errp) {
hw/block/nvme.c +0 -2
@@ -153,8 +153,6 @@#include "qemu/cutils.h" #include "trace.h" #include "nvme.h" -#include "nvme-ns.h" -#include "nvme-dif.h" #define NVME_MAX_IOQPAIRS 0xffff#define NVME_DB_SIZE 4
Signature · 1 line
2.31.1
PATCH 9/14 hw/block/nvme: add metadata offset helper
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
Add an nvme_moff() helper.
--- hw/block/nvme.h | 7 ++++++- hw/block/nvme-dif.c | 4 ++-- hw/block/nvme-ns.c | 2 +- hw/block/nvme.c | 12 ++++++------ 4 files changed, 15 insertions(+), 10 deletions(-)
hw/block/nvme.h +6 -1
@@ -107,7 +107,7 @@ typedef struct NvmeNamespace {BlockConf blkconf;int32_t bootindex;int64_t size; -int64_t mdata_offset; +int64_t moff;NvmeIdNs id_ns;NvmeLBAF lbaf;size_t lbasz;
@@ -158,6 +158,11 @@ static inline size_t nvme_m2b(NvmeNamespace *ns, uint64_t lba)return ns->lbaf.ms * lba; } +static inline int64_t nvme_moff (NvmeNamespace *ns,uint64_t lba) +{ +return ns->moff +nvme_m2b (ns, lba); +} +static inline bool nvme_ns_ext (NvmeNamespace *ns) {return !!NVME_ID_NS_FLBAS_EXTENDED (ns->id_ns.flbas);
hw/block/nvme-dif.c +2 -2
@@ -306,7 +306,7 @@ static void nvme_dif_rw_mdata_in_cb(void *opaque, int ret)uint64_t slba =le64_to_cpu (rw->slba);uint32_t nlb =le16_to_cpu (rw->nlb) +1 ;size_t mlen =nvme_m2b (ns, nlb); -uint64_t offset = ns->mdata_offset +nvme_m2b (ns, slba); +uint64_t offset =nvme_moff (ns, slba);BlockBackend *blk = ns->blkconf.blk;trace_pci_nvme_dif_rw_mdata_in_cb (nvme_cid (req),blk_name (blk));
@@ -335,7 +335,7 @@ static void nvme_dif_rw_mdata_out_cb(void *opaque, int ret)NvmeNamespace *ns = req->ns;NvmeRwCmd *rw = (NvmeRwCmd *)&req->cmd;uint64_t slba =le64_to_cpu (rw->slba); -uint64_t offset = ns->mdata_offset +nvme_m2b (ns, slba); +uint64_t offset =nvme_moff (ns, slba);BlockBackend *blk = ns->blkconf.blk;trace_pci_nvme_dif_rw_mdata_out_cb (nvme_cid (req),blk_name (blk));
hw/block/nvme-ns.c +1 -1
@@ -42,7 +42,7 @@ void nvme_ns_init_format(NvmeNamespace *ns) id_ns->ncap = id_ns->nsze; id_ns->nuse = id_ns->ncap; - ns->mdata_offset = (int64_t )nlbas << ns->lbaf.ds; + ns->moff = (int64_t )nlbas << ns->lbaf.ds; npdg = ns->blkconf.discard_granularity / ns->lbasz;
hw/block/nvme.c +6 -6
@@ -1827,7 +1827,7 @@ static void nvme_rw_cb(void *opaque, int ret)NvmeRwCmd *rw = (NvmeRwCmd *)&req->cmd;uint64_t slba =le64_to_cpu (rw->slba);uint32_t nlb = (uint32_t )le16_to_cpu (rw->nlb) +1 ; -uint64_t offset = ns->mdata_offset +nvme_m2b (ns, slba); +uint64_t offset =nvme_moff (ns, slba);if (req->cmd.opcode ==NVME_CMD_WRITE_ZEROES ) {size_t mlen =nvme_m2b (ns, nlb);
@@ -1993,7 +1993,7 @@ static void nvme_verify_mdata_in_cb(void *opaque, int ret)uint64_t slba =le64_to_cpu (rw->slba);uint32_t nlb =le16_to_cpu (rw->nlb) +1 ;size_t mlen =nvme_m2b (ns, nlb); -uint64_t offset = ns->mdata_offset +nvme_m2b (ns, slba); +uint64_t offset =nvme_moff (ns, slba);BlockBackend *blk = ns->blkconf.blk;trace_pci_nvme_verify_mdata_in_cb (nvme_cid (req),blk_name (blk));
@@ -2096,7 +2096,7 @@ static void nvme_aio_zone_reset_cb(void *opaque, int ret) }if (ns->lbaf.ms) { -int64_t offset = ns->mdata_offset +nvme_m2b (ns, zone->d.zslba); +int64_t offset =nvme_moff (ns, zone->d.zslba); blk_aio_pwrite_zeroes(ns->blkconf.blk, offset, nvme_m2b(ns, ns->zone_size), BDRV_REQ_MAY_UNMAP,
@@ -2167,7 +2167,7 @@ static void nvme_copy_cb(void *opaque, int ret)if (ns->lbaf.ms) {NvmeCopyCmd *copy = (NvmeCopyCmd *)&req->cmd;uint64_t sdlba =le64_to_cpu (copy->sdlba); -int64_t offset = ns->mdata_offset +nvme_m2b (ns, sdlba); +int64_t offset =nvme_moff (ns, sdlba);qemu_iovec_reset (&req->sg.iov);qemu_iovec_add (&req->sg.iov, ctx->mbounce,nvme_m2b (ns, ctx->nlb));
@@ -2463,7 +2463,7 @@ static void nvme_compare_data_cb(void *opaque, int ret)uint64_t slba =le64_to_cpu (rw->slba);uint32_t nlb =le16_to_cpu (rw->nlb) +1 ;size_t mlen =nvme_m2b (ns, nlb); -uint64_t offset = ns->mdata_offset +nvme_m2b (ns, slba); +uint64_t offset =nvme_moff (ns, slba); ctx->mdata.bounce =g_malloc (mlen);
@@ -2744,7 +2744,7 @@ static uint16_t nvme_copy(NvmeCtrl *n, NvmeRequest *req)if (ns->lbaf.ms) { len =nvme_m2b (ns, nlb); - offset = ns->mdata_offset +nvme_m2b (ns, slba); + offset =nvme_moff (ns, slba); in_ctx = g_new(struct nvme_copy_in_ctx, 1); in_ctx->req = req;
Signature · 1 line
2.31.1
PATCH 6/14 hw/block/nvme: remove non-shared defines from header file
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
Remove non-shared defines from the shared header.
--- hw/block/nvme.h | 2 -- hw/block/nvme-ns.c | 1 + hw/block/nvme.c | 1 + 3 files changed, 2 insertions(+), 2 deletions(-)
hw/block/nvme.h +0 -2
@@ -24,8 +24,6 @@#include "block/nvme.h" -#define NVME_DEFAULT_ZONE_SIZE (128 * MiB) -#define NVME_DEFAULT_MAX_ZA_SIZE (128 * KiB)#define NVME_MAX_CONTROLLERS 32#define NVME_MAX_NAMESPACES 256
hw/block/nvme-ns.c +1 -0
@@ -23,6 +23,7 @@#include "trace.h" #define MIN_DISCARD_GRANULARITY (4 * KiB) +#define NVME_DEFAULT_ZONE_SIZE (128 * MiB)void nvme_ns_init_format (NvmeNamespace *ns) {
hw/block/nvme.c +1 -0
@@ -159,6 +159,7 @@#define NVME_TEMPERATURE_WARNING 0x157#define NVME_TEMPERATURE_CRITICAL 0x175#define NVME_NUM_FW_SLOTS 1 +#define NVME_DEFAULT_MAX_ZA_SIZE (128 * KiB)#define NVME_GUEST_ERR (trace, fmt, ...) \ do { \
Signature · 1 line
2.31.1
PATCH 13/14 hw/block/nvme: move zoned constraints checks
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
Validation of the max_active and max_open zoned parameters are independent of any other state, so move them to the early nvme_ns_check_constraints parameter checks.
--- hw/block/nvme-ns.c | 52 +++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 24 deletions(-)
hw/block/nvme-ns.c +28 -24
@@ -210,30 +210,6 @@ static int nvme_ns_zoned_check_calc_geometry(NvmeNamespace *ns, Error **errp)return -1 ; } -if (ns->params.max_active_zones) { -if (ns->params.max_open_zones > ns->params.max_active_zones) { -error_setg (errp,"max_open_zones (%u) exceeds max_active_zones (%u)" , - ns->params.max_open_zones, ns->params.max_active_zones); -return -1 ; - } - -if (!ns->params.max_open_zones) { - ns->params.max_open_zones = ns->params.max_active_zones; - } - } - -if (ns->params.zd_extension_size) { -if (ns->params.zd_extension_size &0x3f ) { -error_setg (errp, -"zone descriptor extension size must be a multiple of 64B" ); -return -1 ; - } -if ((ns->params.zd_extension_size >>6 ) >0xff ) { -error_setg (errp,"zone descriptor extension size is too large" ); -return -1 ; - } - } -return 0 ; }
@@ -403,6 +379,34 @@ static int nvme_ns_check_constraints(NvmeCtrl *n, NvmeNamespace *ns, } } +if (ns->params.zoned) { +if (ns->params.max_active_zones) { +if (ns->params.max_open_zones > ns->params.max_active_zones) { +error_setg (errp,"max_open_zones (%u) exceeds " +"max_active_zones (%u)" , ns->params.max_open_zones, + ns->params.max_active_zones); +return -1 ; + } + +if (!ns->params.max_open_zones) { + ns->params.max_open_zones = ns->params.max_active_zones; + } + } + +if (ns->params.zd_extension_size) { +if (ns->params.zd_extension_size &0x3f ) { +error_setg (errp,"zone descriptor extension size must be a " +"multiple of 64B" ); +return -1 ; + } +if ((ns->params.zd_extension_size >>6 ) >0xff ) { +error_setg (errp, +"zone descriptor extension size is too large" ); +return -1 ; + } + } + } +return 0 ; }
Signature · 1 line
2.31.1
PATCH 11/14 hw/block/nvme: remove num_namespaces member
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
The NvmeCtrl num_namespaces member is just an indirection for the NVME_MAX_NAMESPACES constant.
Remove the indirection.
--- hw/block/nvme.h | 1 - hw/block/nvme.c | 30 +++++++++++++++--------------- 2 files changed, 15 insertions(+), 16 deletions(-)
hw/block/nvme.h +0 -1
@@ -401,7 +401,6 @@ typedef struct NvmeCtrl {uint16_t cqe_size;uint16_t sqe_size;uint32_t reg_size; -uint32_t num_namespaces;uint32_t max_q_ents;uint8_t outstanding_aers;uint32_t irq_status;
hw/block/nvme.c +15 -15
@@ -382,7 +382,8 @@ static int nvme_addr_write(NvmeCtrl *n, hwaddr addr, void *buf, int size)static bool nvme_nsid_valid (NvmeCtrl *n,uint32_t nsid) { -return nsid && (nsid ==NVME_NSID_BROADCAST || nsid <= n->num_namespaces); +return nsid && + (nsid ==NVME_NSID_BROADCAST || nsid <=NVME_MAX_NAMESPACES ); }static int nvme_check_sqid (NvmeCtrl *n,uint16_t sqid)
@@ -2865,7 +2866,7 @@ static uint16_t nvme_flush(NvmeCtrl *n, NvmeRequest *req)/* 1-initialize; see comment in nvme_dsm */ *num_flushes =1 ; -for (int i =1 ; i <= n->num_namespaces; i++) { +for (int i =1 ; i <=NVME_MAX_NAMESPACES ; i++) { ns =nvme_ns (n, i);if (!ns) {continue ;
@@ -3835,7 +3836,7 @@ static uint16_t nvme_smart_info(NvmeCtrl *n, uint8_t rae, uint32_t buf_len, }else {int i; -for (i =1 ; i <= n->num_namespaces; i++) { +for (i =1 ; i <=NVME_MAX_NAMESPACES ; i++) { ns =nvme_ns (n, i);if (!ns) {continue ;
@@ -4332,7 +4333,7 @@ static uint16_t nvme_identify_nslist(NvmeCtrl *n, NvmeRequest *req,return NVME_INVALID_NSID |NVME_DNR ; } -for (i =1 ; i <= n->num_namespaces; i++) { +for (i =1 ; i <=NVME_MAX_NAMESPACES ; i++) { ns =nvme_ns (n, i);if (!ns) {if (!active) {
@@ -4380,7 +4381,7 @@ static uint16_t nvme_identify_nslist_csi(NvmeCtrl *n, NvmeRequest *req,return NVME_INVALID_FIELD |NVME_DNR ; } -for (i =1 ; i <= n->num_namespaces; i++) { +for (i =1 ; i <=NVME_MAX_NAMESPACES ; i++) { ns =nvme_ns (n, i);if (!ns) {if (!active) {
@@ -4646,7 +4647,7 @@ static uint16_t nvme_get_feature(NvmeCtrl *n, NvmeRequest *req) goto out;case NVME_VOLATILE_WRITE_CACHE : result =0 ; -for (i =1 ; i <= n->num_namespaces; i++) { +for (i =1 ; i <=NVME_MAX_NAMESPACES ; i++) { ns =nvme_ns (n, i);if (!ns) {continue ;
@@ -4796,7 +4797,7 @@ static uint16_t nvme_set_feature(NvmeCtrl *n, NvmeRequest *req)break ;case NVME_ERROR_RECOVERY :if (nsid ==NVME_NSID_BROADCAST ) { -for (i =1 ; i <= n->num_namespaces; i++) { +for (i =1 ; i <=NVME_MAX_NAMESPACES ; i++) { ns =nvme_ns (n, i);if (!ns) {
@@ -4817,7 +4818,7 @@ static uint16_t nvme_set_feature(NvmeCtrl *n, NvmeRequest *req) }break ;case NVME_VOLATILE_WRITE_CACHE : -for (i =1 ; i <= n->num_namespaces; i++) { +for (i =1 ; i <=NVME_MAX_NAMESPACES ; i++) { ns =nvme_ns (n, i);if (!ns) {continue ;
@@ -5110,7 +5111,7 @@ static uint16_t nvme_format(NvmeCtrl *n, NvmeRequest *req) req->status = status; } }else { -for (i =1 ; i <= n->num_namespaces; i++) { +for (i =1 ; i <=NVME_MAX_NAMESPACES ; i++) { ns =nvme_ns (n, i);if (!ns) {continue ;
@@ -5221,7 +5222,7 @@ static void nvme_ctrl_reset(NvmeCtrl *n)NvmeNamespace *ns;int i; -for (i =1 ; i <= n->num_namespaces; i++) { +for (i =1 ; i <=NVME_MAX_NAMESPACES ; i++) { ns =nvme_ns (n, i);if (!ns) {continue ;
@@ -5263,7 +5264,7 @@ static void nvme_ctrl_shutdown(NvmeCtrl *n)memory_region_msync (&n->pmr.dev->mr,0 , n->pmr.dev->size); } -for (i =1 ; i <= n->num_namespaces; i++) { +for (i =1 ; i <=NVME_MAX_NAMESPACES ; i++) { ns =nvme_ns (n, i);if (!ns) {continue ;
@@ -5278,7 +5279,7 @@ static void nvme_select_iocs(NvmeCtrl *n)NvmeNamespace *ns;int i; -for (i =1 ; i <= n->num_namespaces; i++) { +for (i =1 ; i <=NVME_MAX_NAMESPACES ; i++) { ns =nvme_ns (n, i);if (!ns) {continue ;
@@ -5905,7 +5906,6 @@ static void nvme_check_constraints(NvmeCtrl *n, Error **errp)static void nvme_init_state (NvmeCtrl *n) { - n->num_namespaces =NVME_MAX_NAMESPACES ;/* add one to max_ioqpairs to account for the admin queue pair */ n->reg_size =pow2ceil (sizeof (NvmeBar) +2 * (n->params.max_ioqpairs +1 ) *NVME_DB_SIZE );
@@ -6086,7 +6086,7 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev) id->sqes = (0x6 <<4 ) |0x6 ; id->cqes = (0x4 <<4 ) |0x4 ; - id->nn =cpu_to_le32 (n->num_namespaces); + id->nn =cpu_to_le32 (NVME_MAX_NAMESPACES ); id->oncs =cpu_to_le16 (NVME_ONCS_WRITE_ZEROES |NVME_ONCS_TIMESTAMP |NVME_ONCS_FEATURES |NVME_ONCS_DSM |NVME_ONCS_COMPARE |NVME_ONCS_COPY );
@@ -6205,7 +6205,7 @@ static void nvme_exit(PCIDevice *pci_dev)nvme_ctrl_reset (n); -for (i =1 ; i <= n->num_namespaces; i++) { +for (i =1 ; i <=NVME_MAX_NAMESPACES ; i++) { ns =nvme_ns (n, i);if (!ns) {continue ;
Signature · 1 line
2.31.1
PATCH 14/14 hw/nvme: move nvme emulation out of hw/block
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
With the introduction of the nvme-subsystem device we are really cluttering up the hw/block directory.
As suggested by Philippe previously, move the nvme emulation to hw/nvme.
---
meson.build | 1 +
hw/{block => nvme}/nvme.h | 6 +-
hw/nvme/trace.h | 1 +
hw/{block/nvme.c => nvme/ctrl.c} | 0
hw/{block/nvme-dif.c => nvme/dif.c} | 0
hw/{block/nvme-ns.c => nvme/ns.c} | 0
hw/{block/nvme-subsys.c => nvme/subsys.c} | 0
MAINTAINERS | 2 +-
hw/Kconfig | 1 +
hw/block/Kconfig | 5 -
hw/block/meson.build | 1 -
hw/block/trace-events | 206 ----------------------
hw/meson.build | 1 +
hw/nvme/Kconfig | 4 +
hw/nvme/meson.build | 1 +
hw/nvme/trace-events | 204 +++++++++++++++++++++
16 files changed, 217 insertions(+), 216 deletions(-)
rename hw/{block => nvme}/nvme.h (99%)
create mode 100644 hw/nvme/trace.h
rename hw/{block/nvme.c => nvme/ctrl.c} (100%)
rename hw/{block/nvme-dif.c => nvme/dif.c} (100%)
rename hw/{block/nvme-ns.c => nvme/ns.c} (100%)
rename hw/{block/nvme-subsys.c => nvme/subsys.c} (100%)
create mode 100644 hw/nvme/Kconfig
create mode 100644 hw/nvme/meson.build
create mode 100644 hw/nvme/trace-eventsmeson.build +1 -0
@@ -1811,6 +1811,7 @@ if have_system 'hw/misc/macio', 'hw/net', 'hw/net/can', + 'hw/nvme', 'hw/nvram', 'hw/pci', 'hw/pci-host',
hw/nvme/nvme.h renamed from hw/block/nvme.h +3 -3
@@ -15,8 +15,8 @@* This code is licensed under the GNU GPL v2 or later. */ -#ifndef HW_NVME_H -#define HW_NVME_H +#ifndef HW_NVME_INTERNAL_H +#define HW_NVME_INTERNAL_H #include "qemu/uuid.h" #include "hw/pci/pci.h"
@@ -544,4 +544,4 @@ uint16_t nvme_dif_check(NvmeNamespace *ns, uint8_t *buf, size_t len,uint16_t nvme_dif_rw (NvmeCtrl *n,NvmeRequest *req); -#endif /* HW_NVME_H */ +#endif /* HW_NVME_INTERNAL_H */
hw/nvme/trace.h new file +1 -0
@@ -0,0 +1 @@ +#include "trace/trace-hw_nvme.h"
hw/nvme/ctrl.c renamed from hw/block/nvme.c +0 -0
hw/nvme/dif.c renamed from hw/block/nvme-dif.c +0 -0
hw/nvme/ns.c renamed from hw/block/nvme-ns.c +0 -0
hw/nvme/subsys.c renamed from hw/block/nvme-subsys.c +0 -0
MAINTAINERS +1 -1
@@ -1972,7 +1972,7 @@ M: Keith Busch <[email protected]> M: Klaus Jensen <[email protected]> L: [email protected] S: Supported -F: hw/block/nvme* +F: hw/nvme/* F: include/block/nvme.h F: tests/qtest/nvme-test.c F: docs/system/nvme.rst
hw/Kconfig +1 -0
@@ -21,6 +21,7 @@ source mem/Kconfig source misc/Kconfig source net/Kconfig source nubus/Kconfig +source nvme/Kconfig source nvram/Kconfig source pci-bridge/Kconfig source pci-host/Kconfig
hw/block/Kconfig +0 -5
@@ -25,11 +25,6 @@ config ONENAND config TC58128 bool -config NVME_PCI - bool - default y if PCI_DEVICES - depends on PCI - config VIRTIO_BLK bool default y
hw/block/meson.build +0 -1
@@ -13,7 +13,6 @@ softmmu_ss.add(when: 'CONFIG_SSI_M25P80', if_true: files('m25p80.c')) softmmu_ss.add(when: 'CONFIG_SWIM', if_true: files('swim.c')) softmmu_ss.add(when: 'CONFIG_XEN', if_true: files('xen-block.c')) softmmu_ss.add(when: 'CONFIG_TC58128', if_true: files('tc58128.c')) -softmmu_ss.add(when: 'CONFIG_NVME_PCI', if_true: files('nvme.c', 'nvme-ns.c', 'nvme-subsys.c', 'nvme-dif.c')) specific_ss.add(when: 'CONFIG_VIRTIO_BLK', if_true: files('virtio-blk.c')) specific_ss.add(when: 'CONFIG_VHOST_USER_BLK', if_true: files('vhost-user-blk.c'))
hw/block/trace-events +0 -206
212 lines not on this page · raw message
hw/meson.build +1 -0
@@ -21,6 +21,7 @@ subdir('mem') subdir('misc') subdir('net') subdir('nubus') +subdir('nvme') subdir('nvram') subdir('pci') subdir('pci-bridge')
hw/nvme/Kconfig new file +4 -0
@@ -0,0 +1,4 @@ +config NVME_PCI + bool + default y if PCI_DEVICES + depends on PCI
hw/nvme/meson.build new file +1 -0
@@ -0,0 +1 @@ +softmmu_ss.add(when: 'CONFIG_NVME_PCI', if_true: files('ctrl.c', 'dif.c', 'ns.c', 'subsys.c'))
hw/nvme/trace-events new file +204 -0
204 lines not on this page · raw message
Signature · 1 line
2.31.1
Re: [PATCH 01/14] hw/block/nvme: rename __nvme_zrm_open
In reply to Klaus JensenQuoted 10 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Get rid of the (reserved) double underscore use.
Cc Philippe Mathieu-Daudé <[email protected]>Cc Thomas Huth <[email protected]>Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
I think it would be good to mention the change with NVME_ZRM_AUTO in the patch description, too.
Apart from that:
Re: [PATCH 02/14] hw/block/nvme: rename __nvme_advance_zone_wp
In reply to Klaus JensenQuoted 37 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Get rid of the (reserved) double underscore use.
Cc Philippe Mathieu-Daudé <[email protected]>Cc Thomas Huth <[email protected]>Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)hw/block/nvme.c +3
-3@@ -1745,8 +1745,8 @@ static inline uint16_t nvme_zrm_open(NvmeNamespace *ns, NvmeZone *zone)return nvme_zrm_open_flags (ns, zone,0 ); } -static void __nvme_advance_zone_wp (NvmeNamespace *ns,NvmeZone *zone, -uint32_t nlb) +static void nvme_advance_zone_wp (NvmeNamespace *ns,NvmeZone *zone, +uint32_t nlb) { zone->d.wp += nlb;@@ -1766,7 +1766,7 @@ static void nvme_finalize_zoned_write(NvmeNamespace *ns, NvmeRequest *req) nlb =le16_to_cpu (rw->nlb) +1 ; zone =nvme_get_zone_by_slba (ns, slba); -__nvme_advance_zone_wp (ns, zone, nlb); +nvme_advance_zone_wp (ns, zone, nlb); }static inline bool nvme_is_write (NvmeRequest *req)
hw/block/nvme.c out: · line 2161
Quoted 8 lines
hw/block/nvme.c +1
-1@@ -2155,7 +2155,7 @@ out:uint64_t sdlba =le64_to_cpu (copy->sdlba);NvmeZone *zone =nvme_get_zone_by_slba (ns, sdlba); -__nvme_advance_zone_wp (ns, zone, ctx->nlb); +nvme_advance_zone_wp (ns, zone, ctx->nlb); }g_free (ctx->bounce);
Re: [PATCH 03/14] hw/block/nvme: rename __nvme_select_ns_iocs
In reply to Klaus JensenQuoted 10 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Get rid of the (reserved) double underscore use.
Cc Philippe Mathieu-Daudé <[email protected]>Cc Thomas Huth <[email protected]>Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-)
Re: [PATCH 01/14] hw/block/nvme: rename __nvme_zrm_open
In reply to Thomas HuthQuoted 12 lines · Thomas Huth
Quoted 10 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Get rid of the (reserved) double underscore use.
Cc Philippe Mathieu-Daudé <[email protected]>Cc Thomas Huth <[email protected]>Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
Quoted 5 lines
I think it would be good to mention the change with
NVME_ZRM_AUTOin the patch description, too.Apart from that:
Reviewed-by Thomas Huth <[email protected]>
Makes sense, thanks!
Quoted 5 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
This series consists of various clean up patches.
The final patch moves nvme emulation from hw/block to hw/nvme.
Series looks good to me.
Re: [PATCH 14/14] hw/nvme: move nvme emulation out of hw/block
In reply to Klaus JensenQuoted 8 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
With the introduction of the nvme-subsystem device we are really cluttering up the hw/block directory.
As suggested by Philippe previously, move the nvme emulation to hw/nvme.
Suggested-by Philippe Mathieu-Daudé <[email protected]>
Hi Philippe,
You originally suggested this. Do you know if an Ack is required from anyone "up in the food chain" before being PR'ed to Peter?
Cheers,
Klaus
Klaus Jensen
AppliedQuoted 43 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
This series consists of various clean up patches.
The final patch moves nvme emulation from hw/block to hw/nvme.
Klaus Jensen (14):
hw/block/nvme: rename__nvme_zrm_openhw/block/nvme: rename__nvme_advance_zone_wphw/block/nvme: rename__nvme_select_ns_iocshw/block/nvme: consolidate header files hw/block/nvme: cleanup includes
hw/block/nvme: remove non-shared defines from header file hw/block/nvme: replacenvme_ns_statushw/block/nvme: cache lba and ms sizes hw/block/nvme: add metadata offset helper hw/block/nvme: streamline namespace array indexing hw/block/nvme: removenum_namespacesmember hw/block/nvme: remove irrelevant zone resource checks hw/block/nvme: move zoned constraints checks hw/nvme: move nvme emulation out of hw/blockmeson.build | 1 + hw/block/nvme-dif.h | 63 --- hw/block/nvme-ns.h | 229 --------- hw/block/nvme-subsys.h | 59 --- hw/block/nvme.h | 266 ----------- hw/nvme/nvme.h | 547 ++++++++++++++++++++++ hw/nvme/trace.h | 1 + hw/{block/nvme.c => nvme/ctrl.c} | 204 ++++---- hw/{block/nvme-dif.c => nvme/dif.c} | 57 +-- hw/{block/nvme-ns.c => nvme/ns.c} | 104 ++-- hw/{block/nvme-subsys.c => nvme/subsys.c} | 13 +- MAINTAINERS | 2 +- hw/Kconfig | 1 + hw/block/Kconfig | 5 - hw/block/meson.build | 1 - hw/block/trace-events | 206 -------- hw/meson.build | 1 + hw/nvme/Kconfig | 4 + hw/nvme/meson.build | 1 + hw/nvme/trace-events | 204 ++++++++ 20 files changed, 928 insertions(+), 1041 deletions(-)
Quoted 18 lines
delete mode 100644
hw/block/nvme-dif.h
delete mode 100644hw/block/nvme-ns.h
delete mode 100644hw/block/nvme-subsys.hdelete mode 100644hw/block/nvme.h
create mode 100644hw/nvme/nvme.h
create mode 100644hw/nvme/trace.h
renamehw/{block/nvme.c=>nvme/ctrl.c} (98%) renamehw/{block/nvme-dif.c=>nvme/dif.c} (90%) renamehw/{block/nvme-ns.c=>nvme/ns.c} (87%) renamehw/{block/nvme-subsys.c=>nvme/subsys.c} (85%) create mode 100644 hw/nvme/Kconfig
create mode 100644 hw/nvme/meson.build
create mode 100644 hw/nvme/trace-eventsSignature · 1 line
2.31.1
Applied to nvme-next.