On Mon, Sep 28, 2020 at 11:35:23AM +0900, Dmitry Fomichev wrote: > The emulation code has been changed to advertise NVM Command Set when > "zoned" device property is not set (default) and Zoned Namespace > Command Set otherwise. > > Handlers for three new NVMe commands introduced in Zoned Namespace > Command Set specification are added, namely for Zone Management > Receive, Zone Management Send and Zone Append. > > Device initialization code has been extended to create a proper > configuration for zoned operation using device properties. > > Read/Write command handler is modified to only allow writes at the > write pointer if the namespace is zoned. For Zone Append command, > writes implicitly happen at the write pointer and the starting write > pointer value is returned as the result of the command. Write Zeroes > handler is modified to add zoned checks that are identical to those > done as a part of Write flow. > > The code to support for Zone Descriptor Extensions is not included in > this commit and ZDES 0 is always reported. A later commit in this > series will add ZDE support. > > This commit doesn't yet include checks for active and open zone > limits. It is assumed that there are no limits on either active or > open zones. > > Signed-off-by: Niklas Cassel <niklas.cas...@wdc.com> > Signed-off-by: Hans Holmberg <hans.holmb...@wdc.com> > Signed-off-by: Ajay Joshi <ajay.jo...@wdc.com> > Signed-off-by: Chaitanya Kulkarni <chaitanya.kulka...@wdc.com> > Signed-off-by: Matias Bjorling <matias.bjorl...@wdc.com> > Signed-off-by: Aravind Ramesh <aravind.ram...@wdc.com> > Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawas...@wdc.com> > Signed-off-by: Adam Manzanares <adam.manzana...@wdc.com> > Signed-off-by: Dmitry Fomichev <dmitry.fomic...@wdc.com> > --- > block/nvme.c | 2 +- > hw/block/nvme-ns.c | 185 ++++++++- > hw/block/nvme-ns.h | 6 +- > hw/block/nvme.c | 872 +++++++++++++++++++++++++++++++++++++++++-- > include/block/nvme.h | 6 +- > 5 files changed, 1033 insertions(+), 38 deletions(-) > > diff --git a/block/nvme.c b/block/nvme.c > index 05485fdd11..7a513c9a17 100644 > --- a/block/nvme.c > +++ b/block/nvme.c
(snip) > @@ -1326,11 +2060,20 @@ static uint16_t nvme_cmd_effects(NvmeCtrl *n, > uint32_t buf_len, > acs[NVME_ADM_CMD_GET_LOG_PAGE] = NVME_CMD_EFFECTS_CSUPP; > acs[NVME_ADM_CMD_ASYNC_EV_REQ] = NVME_CMD_EFFECTS_CSUPP; > > - iocs[NVME_CMD_FLUSH] = NVME_CMD_EFFECTS_CSUPP | NVME_CMD_EFFECTS_LBCC; > - iocs[NVME_CMD_WRITE_ZEROES] = NVME_CMD_EFFECTS_CSUPP | > - NVME_CMD_EFFECTS_LBCC; > - iocs[NVME_CMD_WRITE] = NVME_CMD_EFFECTS_CSUPP | NVME_CMD_EFFECTS_LBCC; > - iocs[NVME_CMD_READ] = NVME_CMD_EFFECTS_CSUPP; > + if (NVME_CC_CSS(n->bar.cc) != CSS_ADMIN_ONLY) { > + iocs[NVME_CMD_FLUSH] = NVME_CMD_EFFECTS_CSUPP | > NVME_CMD_EFFECTS_LBCC; > + iocs[NVME_CMD_WRITE_ZEROES] = NVME_CMD_EFFECTS_CSUPP | > + NVME_CMD_EFFECTS_LBCC; > + iocs[NVME_CMD_WRITE] = NVME_CMD_EFFECTS_CSUPP | > NVME_CMD_EFFECTS_LBCC; > + iocs[NVME_CMD_READ] = NVME_CMD_EFFECTS_CSUPP; > + } > + > + if (csi == NVME_CSI_ZONED && NVME_CC_CSS(n->bar.cc) == CSS_CSI) { Actually, intead of naming the helper function, ctrl_has_zns_namespaces(), a better name might be ctrl_has_zns_support() Since this is what is used to set the bit in nvme_identify_cmd_set(), Then, I think that this should be: if (ctrl_has_zns_support() && csi == NVME_CSI_ZONED && NVME_CC_CSS(n->bar.cc) == CSS_CSI) { > + iocs[NVME_CMD_ZONE_APPEND] = NVME_CMD_EFFECTS_CSUPP | > + NVME_CMD_EFFECTS_LBCC; > + iocs[NVME_CMD_ZONE_MGMT_SEND] = NVME_CMD_EFFECTS_CSUPP; > + iocs[NVME_CMD_ZONE_MGMT_RECV] = NVME_CMD_EFFECTS_CSUPP; > + } > > trans_len = MIN(sizeof(cmd_eff_log) - off, buf_len); >