From nobody Mon Feb 9 17:37:50 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1600981823; cv=none; d=zohomail.com; s=zohoarc; b=n1gC1zA9/1FchaPh8brU0GYPvGf4pzlV6cyBckQVwpGKFg/I6/BW9ARchiQqWgp9YRFAUqfZtsZN1pmsTXTiIDo2Q4nFN8Oh84nE0C8bU9kqd4aqX9fhelHraP7yIQTWlm1Q8OH8lNmz6ayJD2VWTiUp2pr6MoSepU6BG93sYQg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600981823; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iHh5SVDa7WZAZiIwnoJA5VT73xcAn9ABMOivHzmv5kI=; b=RnpukZF0mMTaUVlTvgHPA/Rtl110wsyzIX2JoTvfFvkbT6Jip7NsZPMwfdj/+atUo1po45JTL4oMZIEqfzO1iknq0OqUSExPFjzEkUIHi0TYVU4rC2ybn+8aYcutZVk7DRm2ytCGZz4lOr9do1J6eMkh1NsY3O9QP8x+IT90fgo= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600981823736560.4687741365638; Thu, 24 Sep 2020 14:10:23 -0700 (PDT) Received: from localhost ([::1]:49086 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLYVS-0002UL-7n for importer@patchew.org; Thu, 24 Sep 2020 17:10:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38618) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLY7Y-0004ZC-SS; Thu, 24 Sep 2020 16:45:41 -0400 Received: from new2-smtp.messagingengine.com ([66.111.4.224]:43295) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLY7T-0007nP-6b; Thu, 24 Sep 2020 16:45:40 -0400 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailnew.nyi.internal (Postfix) with ESMTP id 56D7E580509; Thu, 24 Sep 2020 16:45:33 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Thu, 24 Sep 2020 16:45:33 -0400 Received: from apples.local (80-167-98-190-cable.dk.customer.tdc.net [80.167.98.190]) by mail.messagingengine.com (Postfix) with ESMTPA id 4709D3064686; Thu, 24 Sep 2020 16:45:31 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irrelevant.dk; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=iHh5SVDa7WZAZ iIwnoJA5VT73xcAn9ABMOivHzmv5kI=; b=Q3zTLCUcu109+KkBGezVZvmh7I++L XA+KF2WiEFCHttgugLeU9MeGCxFEAD2PaC+cspU2YiBci+BELee8O/a7rBeX7/7P FFVI98pVEzlkm3hZXjQHmVcbHqMxbpXxqJm8t0VgdyZvZB2ARfwh9je5ZpM4s7Cl St9FGl0MNDvlFgtG7WjYlc5r5k0UNOvjkEvEm7xw6LKXUnTq6V7S0F6GvIoZjdM0 b01Ovdc1bDZ6mqnxQgEkkiMg+lYbFEk+z7GNcReeutsAbK+80j+31n0WRHMmhtsn rF62E6yvCFGex0eYGCsj4jDIUndlHsa7npSUfxUKJBOAL1bcIeXoqUhvw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=iHh5SVDa7WZAZiIwnoJA5VT73xcAn9ABMOivHzmv5kI=; b=jbfIktMg vgKLO7b/Zcw1uGwhgC1tdVJnQ7g6XHSQNPvJ9JyKurQOXMLW0MHWPF3kl7Mbay5P jXw6FCJmRKtXGFY+wFL7LegPI6AF05gAldImg4K7zIffETx+zCWaPpP0gy85u4f6 /0sqw8QyudQ4Kkw1VQ06kBCZfvz2GxgrDEYx88l8iTI5FZ0nt58DFf69erpwAx0e 3kS/QVUPEtvKG051pOIANBqY4Jg98uKimDJAgWvAE7ff9wqATGh7BPhj1XF9uupQ cxDpgbWHVUodUW6lMm3eeEdp3zA42q3ylcdUDO+ZMhbj4wHo1U7cNfxWQVZ/LWJX sJPxQ3raBFsX2A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudekgdduheduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefmlhgruhhs ucflvghnshgvnhcuoehithhssehirhhrvghlvghvrghnthdrughkqeenucggtffrrghtth gvrhhnpeeuleetgeeiuefhgfekfefgveejiefgteekiedtgfdtieefhfdthfefueffvefg keenucfkphepkedtrdduieejrdelkedrudeltdenucevlhhushhtvghrufhiiigvpeegne curfgrrhgrmhepmhgrihhlfhhrohhmpehithhssehirhhrvghlvghvrghnthdrughk X-ME-Proxy: From: Klaus Jensen To: qemu-devel@nongnu.org Subject: [PATCH 10/16] hw/block/nvme: add the zone management receive command Date: Thu, 24 Sep 2020 22:45:10 +0200 Message-Id: <20200924204516.1881843-11-its@irrelevant.dk> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200924204516.1881843-1-its@irrelevant.dk> References: <20200924204516.1881843-1-its@irrelevant.dk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=66.111.4.224; envelope-from=its@irrelevant.dk; helo=new2-smtp.messagingengine.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/24 14:55:29 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, Klaus Jensen , Max Reitz , Keith Busch , Klaus Jensen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Klaus Jensen Add the Zone Management Receive command. Signed-off-by: Klaus Jensen --- hw/block/nvme-ns.h | 8 +++ hw/block/nvme.h | 1 + include/block/nvme.h | 46 ++++++++++++++ hw/block/nvme-ns.c | 35 ++++++++++- hw/block/nvme.c | 135 ++++++++++++++++++++++++++++++++++++++++++ hw/block/trace-events | 1 + 6 files changed, 223 insertions(+), 3 deletions(-) diff --git a/hw/block/nvme-ns.h b/hw/block/nvme-ns.h index c15bfcfc5a08..5a695334a052 100644 --- a/hw/block/nvme-ns.h +++ b/hw/block/nvme-ns.h @@ -27,11 +27,13 @@ typedef struct NvmeNamespaceParams { struct { uint64_t zcap; uint64_t zsze; + uint8_t zdes; } zns; } NvmeNamespaceParams; =20 typedef struct NvmeZone { NvmeZoneDescriptor *zd; + uint8_t *zde; =20 uint64_t wp_staging; } NvmeZone; @@ -68,6 +70,7 @@ typedef struct NvmeNamespace { =20 NvmeZone *zones; NvmeZoneDescriptor *zd; + uint8_t *zde; } zns; } NvmeNamespace; =20 @@ -160,6 +163,11 @@ static inline void nvme_zs_set(NvmeZone *zone, NvmeZon= eState zs) zone->zd->zs =3D zs << 4; } =20 +static inline size_t nvme_ns_zdes_bytes(NvmeNamespace *ns) +{ + return ns->params.zns.zdes << 6; +} + static inline bool nvme_ns_zone_wp_valid(NvmeZone *zone) { switch (nvme_zs(zone)) { diff --git a/hw/block/nvme.h b/hw/block/nvme.h index f66ed9ab7eff..523eef0bcad8 100644 --- a/hw/block/nvme.h +++ b/hw/block/nvme.h @@ -71,6 +71,7 @@ static inline const char *nvme_io_opc_str(uint8_t opc) case NVME_CMD_WRITE: return "NVME_NVM_CMD_WRITE"; case NVME_CMD_READ: return "NVME_NVM_CMD_READ"; case NVME_CMD_WRITE_ZEROES: return "NVME_NVM_CMD_WRITE_ZEROES"; + case NVME_CMD_ZONE_MGMT_RECV: return "NVME_ZONED_CMD_ZONE_MGMT_RECV"; default: return "NVME_NVM_CMD_UNKNOWN"; } } diff --git a/include/block/nvme.h b/include/block/nvme.h index 2e523c9d97b4..9bacf48ee9e9 100644 --- a/include/block/nvme.h +++ b/include/block/nvme.h @@ -481,6 +481,7 @@ enum NvmeIoCommands { NVME_CMD_COMPARE =3D 0x05, NVME_CMD_WRITE_ZEROES =3D 0x08, NVME_CMD_DSM =3D 0x09, + NVME_CMD_ZONE_MGMT_RECV =3D 0x7a, }; =20 typedef struct QEMU_PACKED NvmeDeleteQ { @@ -593,6 +594,44 @@ enum { NVME_RW_PRINFO_PRCHK_REF =3D 1 << 10, }; =20 +typedef struct QEMU_PACKED NvmeZoneManagementRecvCmd { + uint8_t opcode; + uint8_t flags; + uint16_t cid; + uint32_t nsid; + uint8_t rsvd8[16]; + NvmeCmdDptr dptr; + uint64_t slba; + uint32_t numdw; + uint8_t zra; + uint8_t zrasp; + uint8_t zrasf; + uint8_t rsvd55[9]; +} NvmeZoneManagementRecvCmd; + +typedef enum NvmeZoneManagementRecvAction { + NVME_CMD_ZONE_MGMT_RECV_REPORT_ZONES =3D 0x0, + NVME_CMD_ZONE_MGMT_RECV_EXTENDED_REPORT_ZONES =3D 0x1, +} NvmeZoneManagementRecvAction; + +typedef enum NvmeZoneManagementRecvActionSpecificField { + NVME_CMD_ZONE_MGMT_RECV_LIST_ALL =3D 0x0, + NVME_CMD_ZONE_MGMT_RECV_LIST_ZSE =3D 0x1, + NVME_CMD_ZONE_MGMT_RECV_LIST_ZSIO =3D 0x2, + NVME_CMD_ZONE_MGMT_RECV_LIST_ZSEO =3D 0x3, + NVME_CMD_ZONE_MGMT_RECV_LIST_ZSC =3D 0x4, + NVME_CMD_ZONE_MGMT_RECV_LIST_ZSF =3D 0x5, + NVME_CMD_ZONE_MGMT_RECV_LIST_ZSRO =3D 0x6, + NVME_CMD_ZONE_MGMT_RECV_LIST_ZSO =3D 0x7, +} NvmeZoneManagementRecvActionSpecificField; + +#define NVME_CMD_ZONE_MGMT_RECEIVE_PARTIAL 0x1 + +typedef struct QEMU_PACKED NvmeZoneReportHeader { + uint64_t num_zones; + uint8_t rsvd[56]; +} NvmeZoneReportHeader; + typedef struct QEMU_PACKED NvmeDsmCmd { uint8_t opcode; uint8_t flags; @@ -812,6 +851,12 @@ typedef struct QEMU_PACKED NvmeZoneDescriptor { uint8_t rsvd32[32]; } NvmeZoneDescriptor; =20 +#define NVME_ZA_ZDEV (1 << 7) + +#define NVME_ZA_SET(za, attrs) ((za) |=3D (attrs)) +#define NVME_ZA_CLEAR(za, attrs) ((za) &=3D ~(attrs)) +#define NVME_ZA_CLEAR_ALL(za) ((za) =3D 0x0) + enum NvmeSmartWarn { NVME_SMART_SPARE =3D 1 << 0, NVME_SMART_TEMPERATURE =3D 1 << 1, @@ -1162,6 +1207,7 @@ static inline void _nvme_check_size(void) QEMU_BUILD_BUG_ON(sizeof(NvmeIdentify) !=3D 64); QEMU_BUILD_BUG_ON(sizeof(NvmeRwCmd) !=3D 64); QEMU_BUILD_BUG_ON(sizeof(NvmeDsmCmd) !=3D 64); + QEMU_BUILD_BUG_ON(sizeof(NvmeZoneManagementRecvCmd) !=3D 64); QEMU_BUILD_BUG_ON(sizeof(NvmeRangeType) !=3D 64); QEMU_BUILD_BUG_ON(sizeof(NvmeErrorLog) !=3D 64); QEMU_BUILD_BUG_ON(sizeof(NvmeFwSlotInfoLog) !=3D 512); diff --git a/hw/block/nvme-ns.c b/hw/block/nvme-ns.c index 872c46f2f2f0..0fb196c7103e 100644 --- a/hw/block/nvme-ns.c +++ b/hw/block/nvme-ns.c @@ -85,6 +85,9 @@ static void nvme_ns_zns_init_zones(NvmeNamespace *ns) zslba =3D i * zsze; zone =3D nvme_ns_get_zone(ns, zslba); zone->zd =3D &ns->zns.zd[i]; + if (ns->params.zns.zdes) { + zone->zde =3D &ns->zns.zde[i]; + } =20 zd =3D zone->zd; =20 @@ -104,11 +107,15 @@ static void nvme_ns_init_zoned(NvmeNamespace *ns) for (int i =3D 0; i <=3D id_ns->nlbaf; i++) { id_ns_zns->lbafe[i].zsze =3D ns->params.zns.zsze ? ns->params.zns.zsze : cpu_to_le64(pow2ceil(ns->params.zns.zcap= )); + id_ns_zns->lbafe[i].zdes =3D ns->params.zns.zdes; } =20 ns->zns.num_zones =3D nvme_ns_nlbas(ns) / nvme_ns_zsze(ns); ns->zns.zones =3D g_malloc0_n(ns->zns.num_zones, sizeof(NvmeZone)); ns->zns.zd =3D g_malloc0_n(ns->zns.num_zones, sizeof(NvmeZoneDescripto= r)); + if (ns->params.zns.zdes) { + ns->zns.zde =3D g_malloc0_n(ns->zns.num_zones, nvme_ns_zdes_bytes(= ns)); + } =20 id_ns->ncap =3D ns->zns.num_zones * ns->params.zns.zcap; =20 @@ -148,7 +155,7 @@ static int nvme_ns_setup_blk_pstate(NvmeNamespace *ns, = Error **errp) BlockBackend *blk =3D ns->pstate.blk; uint64_t perm, shared_perm; ssize_t len; - size_t util_len, zd_len, pstate_len; + size_t util_len, zd_len, zde_len, pstate_len; int ret; =20 perm =3D BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE; @@ -162,7 +169,9 @@ static int nvme_ns_setup_blk_pstate(NvmeNamespace *ns, = Error **errp) util_len =3D DIV_ROUND_UP(nvme_ns_nlbas(ns), 8); zd_len =3D nvme_ns_zoned(ns) ? ns->zns.num_zones * sizeof(NvmeZoneDescriptor) : 0; - pstate_len =3D ROUND_UP(util_len + zd_len, BDRV_SECTOR_SIZE); + zde_len =3D nvme_ns_zoned(ns) ? + ns->zns.num_zones * nvme_ns_zdes_bytes(ns) : 0; + pstate_len =3D ROUND_UP(util_len + zd_len + zde_len, BDRV_SECTOR_SIZE); =20 len =3D blk_getlength(blk); if (len < 0) { @@ -213,9 +222,19 @@ static int nvme_ns_setup_blk_pstate(NvmeNamespace *ns,= Error **errp) return ret; } =20 + if (zde_len) { + ret =3D blk_pread(blk, util_len + zd_len, ns->zns.zde, + zde_len); + if (ret < 0) { + error_setg_errno(errp, -ret, "could not read pstate"); + return ret; + } + } + for (int i =3D 0; i < ns->zns.num_zones; i++) { NvmeZone *zone =3D &ns->zns.zones[i]; zone->zd =3D &ns->zns.zd[i]; + zone->zde =3D &ns->zns.zde[i]; =20 zone->wp_staging =3D nvme_wp(zone); =20 @@ -227,7 +246,8 @@ static int nvme_ns_setup_blk_pstate(NvmeNamespace *ns, = Error **errp) continue; =20 case NVME_ZS_ZSC: - if (nvme_wp(zone) =3D=3D nvme_zslba(zone)) { + if (nvme_wp(zone) =3D=3D nvme_zslba(zone) && + !(zone->zd->za & NVME_ZA_ZDEV)) { nvme_zs_set(zone, NVME_ZS_ZSE); } =20 @@ -248,6 +268,14 @@ static int nvme_ns_setup_blk_pstate(NvmeNamespace *ns,= Error **errp) error_setg_errno(errp, -ret, "could not write pstate"); return ret; } + + if (zde_len) { + ret =3D blk_pwrite(blk, util_len + zd_len, ns->zns.zde, zde_le= n, 0); + if (ret < 0) { + error_setg_errno(errp, -ret, "could not write pstate"); + return ret; + } + } } =20 return 0; @@ -389,6 +417,7 @@ static Property nvme_ns_props[] =3D { DEFINE_PROP_UINT8("iocs", NvmeNamespace, params.iocs, NVME_IOCS_NVM), DEFINE_PROP_UINT64("zns.zcap", NvmeNamespace, params.zns.zcap, 0), DEFINE_PROP_UINT64("zns.zsze", NvmeNamespace, params.zns.zsze, 0), + DEFINE_PROP_UINT8("zns.zdes", NvmeNamespace, params.zns.zdes, 0), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/hw/block/nvme.c b/hw/block/nvme.c index b0179291b966..43ae89a0a6cb 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -163,6 +163,7 @@ static const NvmeEffectsLog nvme_effects[NVME_IOCS_MAX]= =3D { =20 .iocs =3D { NVME_EFFECTS_NVM_INITIALIZER, + [NVME_CMD_ZONE_MGMT_RECV] =3D NVME_EFFECTS_CSUPP, }, }, }; @@ -1201,6 +1202,9 @@ static void nvme_rw_cb(void *opaque, int ret) NVME_ZS_ZSRO : NVME_ZS_ZSO; =20 nvme_zs_set(zone, zs); + if (zs =3D=3D NVME_ZS_ZSO) { + NVME_ZA_CLEAR_ALL(zone->zd->za); + } =20 if (nvme_zns_commit_zone(ns, zone) < 0) { req->status =3D NVME_INTERNAL_DEV_ERROR; @@ -1269,6 +1273,135 @@ static uint16_t nvme_do_aio(BlockBackend *blk, int6= 4_t offset, size_t len, return NVME_NO_COMPLETE; } =20 +static uint16_t nvme_zone_mgmt_recv(NvmeCtrl *n, NvmeRequest *req) +{ + NvmeZoneManagementRecvCmd *recv; + NvmeZoneManagementRecvAction zra; + NvmeZoneManagementRecvActionSpecificField zrasp; + NvmeNamespace *ns =3D req->ns; + NvmeZone *zone; + + uint8_t *buf, *bufp, zs_list; + uint64_t slba; + int num_zones =3D 0, zidx =3D 0, zidx_begin; + uint16_t zes, status; + size_t len; + + recv =3D (NvmeZoneManagementRecvCmd *) &req->cmd; + + zra =3D recv->zra; + zrasp =3D recv->zrasp; + slba =3D le64_to_cpu(recv->slba); + len =3D (le32_to_cpu(recv->numdw) + 1) << 2; + + if (!nvme_ns_zoned(ns)) { + return NVME_INVALID_OPCODE | NVME_DNR; + } + + trace_pci_nvme_zone_mgmt_recv(nvme_cid(req), nvme_nsid(ns), slba, len, + zra, zrasp, recv->zrasf); + + if (!len) { + return NVME_SUCCESS; + } + + switch (zrasp) { + case NVME_CMD_ZONE_MGMT_RECV_LIST_ALL: + zs_list =3D 0; + break; + + case NVME_CMD_ZONE_MGMT_RECV_LIST_ZSE: + zs_list =3D NVME_ZS_ZSE; + break; + + case NVME_CMD_ZONE_MGMT_RECV_LIST_ZSIO: + zs_list =3D NVME_ZS_ZSIO; + break; + + case NVME_CMD_ZONE_MGMT_RECV_LIST_ZSEO: + zs_list =3D NVME_ZS_ZSEO; + break; + + case NVME_CMD_ZONE_MGMT_RECV_LIST_ZSC: + zs_list =3D NVME_ZS_ZSC; + break; + + case NVME_CMD_ZONE_MGMT_RECV_LIST_ZSF: + zs_list =3D NVME_ZS_ZSF; + break; + + case NVME_CMD_ZONE_MGMT_RECV_LIST_ZSRO: + zs_list =3D NVME_ZS_ZSRO; + break; + + case NVME_CMD_ZONE_MGMT_RECV_LIST_ZSO: + zs_list =3D NVME_ZS_ZSO; + break; + default: + return NVME_INVALID_FIELD | NVME_DNR; + } + + status =3D nvme_check_mdts(n, len); + if (status) { + return status; + } + + if (!nvme_ns_get_zone(ns, slba)) { + trace_pci_nvme_err_invalid_zone(nvme_cid(req), slba); + return NVME_INVALID_FIELD | NVME_DNR; + } + + zidx_begin =3D zidx =3D nvme_ns_zone_idx(ns, slba); + zes =3D sizeof(NvmeZoneDescriptor); + if (zra =3D=3D NVME_CMD_ZONE_MGMT_RECV_EXTENDED_REPORT_ZONES) { + zes +=3D nvme_ns_zdes_bytes(ns); + } + + buf =3D bufp =3D g_malloc0(len); + bufp +=3D sizeof(NvmeZoneReportHeader); + + while ((bufp + zes) - buf <=3D len && zidx < ns->zns.num_zones) { + zone =3D &ns->zns.zones[zidx++]; + + if (zs_list && zs_list !=3D nvme_zs(zone)) { + continue; + } + + num_zones++; + + memcpy(bufp, zone->zd, sizeof(NvmeZoneDescriptor)); + + if (zra =3D=3D NVME_CMD_ZONE_MGMT_RECV_EXTENDED_REPORT_ZONES) { + memcpy(bufp + sizeof(NvmeZoneDescriptor), zone->zde, + nvme_ns_zdes_bytes(ns)); + } + + bufp +=3D zes; + } + + if (!(recv->zrasf & NVME_CMD_ZONE_MGMT_RECEIVE_PARTIAL)) { + if (!zs_list) { + num_zones =3D ns->zns.num_zones - zidx_begin; + } else { + num_zones =3D 0; + for (int i =3D zidx_begin; i < ns->zns.num_zones; i++) { + zone =3D &ns->zns.zones[i]; + + if (zs_list =3D=3D nvme_zs(zone)) { + num_zones++; + } + } + } + } + + stq_le_p(buf, (uint64_t)num_zones); + + status =3D nvme_dma(n, buf, len, DMA_DIRECTION_FROM_DEVICE, req); + g_free(buf); + + return status; +} + static uint16_t nvme_flush(NvmeCtrl *n, NvmeRequest *req) { NvmeNamespace *ns =3D req->ns; @@ -1408,6 +1541,8 @@ static uint16_t nvme_io_cmd(NvmeCtrl *n, NvmeRequest = *req) case NVME_CMD_WRITE: case NVME_CMD_READ: return nvme_rwz(n, req); + case NVME_CMD_ZONE_MGMT_RECV: + return nvme_zone_mgmt_recv(n, req); default: trace_pci_nvme_err_invalid_opc(req->cmd.opcode); return NVME_INVALID_OPCODE | NVME_DNR; diff --git a/hw/block/trace-events b/hw/block/trace-events index d46a7a4942bb..a2671dadb1e8 100644 --- a/hw/block/trace-events +++ b/hw/block/trace-events @@ -42,6 +42,7 @@ pci_nvme_io_cmd(uint16_t cid, uint32_t nsid, uint16_t sqi= d, uint8_t opcode, cons pci_nvme_admin_cmd(uint16_t cid, uint16_t sqid, uint8_t opcode, const char= *opname) "cid %"PRIu16" sqid %"PRIu16" opc 0x%"PRIx8" opname '%s'" pci_nvme_rwz(uint16_t cid, const char *verb, uint32_t nsid, uint32_t nlb, = uint64_t len, uint64_t lba) "cid %"PRIu16" opname '%s' nsid %"PRIu32" nlb %= "PRIu32" len %"PRIu64" lba 0x%"PRIx64"" pci_nvme_rw_cb(uint16_t cid, const char *blkname) "cid %"PRIu16" blk '%s'" +pci_nvme_zone_mgmt_recv(uint16_t cid, uint32_t nsid, uint64_t slba, uint64= _t len, uint8_t zra, uint8_t zrasp, uint8_t zrasf) "cid %"PRIu16" nsid %"PR= Iu32" slba 0x%"PRIx64" len %"PRIu64" zra 0x%"PRIx8" zrasp 0x%"PRIx8" zrasf = 0x%"PRIx8"" pci_nvme_allocate(uint32_t ns, uint64_t slba, uint32_t nlb) "nsid %"PRIu32= " slba 0x%"PRIx64" nlb %"PRIu32"" pci_nvme_do_aio(uint16_t cid, uint8_t opc, const char *opname, const char = *blkname, int64_t offset, size_t len) "cid %"PRIu16" opc 0x%"PRIx8" opname = '%s' blk '%s' offset %"PRId64" len %zu" pci_nvme_create_sq(uint64_t addr, uint16_t sqid, uint16_t cqid, uint16_t q= size, uint16_t qflags) "create submission queue, addr=3D0x%"PRIx64", sqid= =3D%"PRIu16", cqid=3D%"PRIu16", qsize=3D%"PRIu16", qflags=3D%"PRIu16"" --=20 2.28.0