From nobody Mon Feb 9 15:45:29 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=1615931622; cv=none; d=zohomail.com; s=zohoarc; b=R37uQExrl5FFzTzJMJiBjhQraqAudAjsdQBJDWrTgVzB4wuk/Sxz+GE5toXttmj0L8urdGjthpCOD7nyM4HuWTkGUFAyBKCG+gIX8hvMGDE75HCfhVA0nzInnuKE+43YjZg5+swJRjV2LXz93gBZB7KN6ZHZVo92f5XH5K3BAAU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615931622; 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=8F3ZKsYMEXHk+5AdV0um3WvGB+j6ek/Kt6khc+0in98=; b=VeV3CxzBoVqBajjaewUAvHBLq9epvx3/q2lSi/Jj4XV0F1Gq6nSdB8S8ACMCKjwy72kRqsTQI175L0ON4pOONGqF4r08RueUyaFYjpSZOOB4afWeh3GpvWJtdnZZ1Ea6vkAp+Y9cuYDjdSmjCTJ3F0N+ulqtn6Zooulx9D9cN04= 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 1615931622715258.486715563035; Tue, 16 Mar 2021 14:53:42 -0700 (PDT) Received: from localhost ([::1]:45548 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMHdF-0003L0-Gs for importer@patchew.org; Tue, 16 Mar 2021 17:53:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60536) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMHXy-00075L-M2; Tue, 16 Mar 2021 17:48:14 -0400 Received: from new1-smtp.messagingengine.com ([66.111.4.221]:45103) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMHXw-0000z5-SQ; Tue, 16 Mar 2021 17:48:14 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.nyi.internal (Postfix) with ESMTP id E4C64580A7B; Tue, 16 Mar 2021 17:48:09 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 16 Mar 2021 17:48:09 -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 6954B108005C; Tue, 16 Mar 2021 17:48:08 -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=fm2; bh=8F3ZKsYMEXHk+ 5AdV0um3WvGB+j6ek/Kt6khc+0in98=; b=qMvTCH4vL1oVOtuRtwolzhZm+vfD+ oJh1kZqKVTJwmrhBuehxu+4xwbRu6RKPuyH+RQgNIOLOYhSy9n5b4WtWnrUTph0/ hPgIWpt8ciqzpV37PWAnQJxmnAdgCn4cGpRjsVa97lD3k0FTJsP5vhpBBZpTaE/d VGAe/YcRc4nUwRDaMcSBfQ9ZzZOFittVEAhnsee0bgUrB4LCLKcQSFgu4wb3hJPA 8PXM7fCIGMaVGr/wvUqLSaNT3Fo8OvNOda8Si151La/JgOGeNkNPFgKZl51YMx35 9qND+bwyHqvdPVIiFG899+ZVgPsUeo/xERStwx3WD/aYrm0y/mzmijNow== 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= fm2; bh=8F3ZKsYMEXHk+5AdV0um3WvGB+j6ek/Kt6khc+0in98=; b=KYnEbb4L OuPi9fxrVYZEdKqqcu0RtENL6vQhKWeQ17hKYnbgPsuasrz9QsCAZJKXAtQojBkR 18OjVijL4tmJv8UaY4lAavc8oPnNDxUJ0K0ixORYGRAKH9ewzUgBy8fcdboBYkKE gi6FsF0YITgBrCJ2vrp0mBlUtDsQEsO+rwQS/T2EnmAOWB5VZ9cJAXA29yxcYjHi cveZLlJGIHl5e4lfPkDBbyYTrFktvl+ZUT4EUkmLFO+Lwt+ybuK71sJZ0lBnbC2B fXqKi7W1CBB+OWZRKbuVavqX8+CUkw1+hhIQkP3hrEMvRS4uJU0zoIoDmK7KJgNC qm6soF6g5cV7/w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudefvddgudehhecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepmfhlrghu shculfgvnhhsvghnuceoihhtshesihhrrhgvlhgvvhgrnhhtrdgukheqnecuggftrfgrth htvghrnhepueelteegieeuhffgkeefgfevjeeigfetkeeitdfgtdeifefhtdfhfeeuffev gfeknecukfhppeektddrudeijedrleekrdduledtnecuvehluhhsthgvrhfuihiivgepud enucfrrghrrghmpehmrghilhhfrhhomhepihhtshesihhrrhgvlhgvvhgrnhhtrdgukh X-ME-Proxy: From: Klaus Jensen To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 08/11] hw/block/nvme: support multiple lba formats Date: Tue, 16 Mar 2021 22:47:50 +0100 Message-Id: <20210316214753.399389-9-its@irrelevant.dk> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210316214753.399389-1-its@irrelevant.dk> References: <20210316214753.399389-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.221; envelope-from=its@irrelevant.dk; helo=new1-smtp.messagingengine.com 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, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Klaus Jensen , Max Reitz , Keith Busch , Stefan Hajnoczi , Klaus Jensen , Minwoo Im Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Minwoo Im This patch introduces multiple LBA formats supported with the typical logical block sizes of 512 bytes and 4096 bytes as well as metadata sizes of 0, 8, 16 and 64 bytes. The format will be chosed based on the lbads and ms parameters of the nvme-ns device. Signed-off-by: Minwoo Im [k.jensen: resurrected and rebased] Signed-off-by: Klaus Jensen Reviewed-by: Keith Busch --- hw/block/nvme-ns.c | 60 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 8 deletions(-) diff --git a/hw/block/nvme-ns.c b/hw/block/nvme-ns.c index a082a7004d8e..00e8f6af2162 100644 --- a/hw/block/nvme-ns.c +++ b/hw/block/nvme-ns.c @@ -36,13 +36,15 @@ static int nvme_ns_init(NvmeNamespace *ns, Error **errp) { BlockDriverInfo bdi; NvmeIdNs *id_ns =3D &ns->id_ns; - int lba_index =3D NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas); int npdg, nlbas; + uint8_t ds; + uint16_t ms; + int i; =20 ns->id_ns.dlfeat =3D 0x1; =20 - id_ns->lbaf[lba_index].ds =3D 31 - clz32(ns->blkconf.logical_block_siz= e); - id_ns->lbaf[lba_index].ms =3D ns->params.ms; + ds =3D 31 - clz32(ns->blkconf.logical_block_size); + ms =3D ns->params.ms; =20 if (ns->params.ms) { id_ns->mc =3D 0x3; @@ -53,8 +55,47 @@ static int nvme_ns_init(NvmeNamespace *ns, Error **errp) =20 id_ns->dpc =3D 0x1f; id_ns->dps =3D ((ns->params.pil & 0x1) << 3) | ns->params.pi; + + NvmeLBAF lbaf[16] =3D { + [0] =3D { .ds =3D 9 }, + [1] =3D { .ds =3D 9, .ms =3D 8 }, + [2] =3D { .ds =3D 9, .ms =3D 16 }, + [3] =3D { .ds =3D 9, .ms =3D 64 }, + [4] =3D { .ds =3D 12 }, + [5] =3D { .ds =3D 12, .ms =3D 8 }, + [6] =3D { .ds =3D 12, .ms =3D 16 }, + [7] =3D { .ds =3D 12, .ms =3D 64 }, + }; + + memcpy(&id_ns->lbaf, &lbaf, sizeof(lbaf)); + id_ns->nlbaf =3D 7; + } else { + NvmeLBAF lbaf[16] =3D { + [0] =3D { .ds =3D 9 }, + [1] =3D { .ds =3D 12 }, + }; + + memcpy(&id_ns->lbaf, &lbaf, sizeof(lbaf)); + id_ns->nlbaf =3D 1; } =20 + for (i =3D 0; i <=3D id_ns->nlbaf; i++) { + NvmeLBAF *lbaf =3D &id_ns->lbaf[i]; + if (lbaf->ds =3D=3D ds) { + if (lbaf->ms =3D=3D ms) { + id_ns->flbas |=3D i; + goto lbaf_found; + } + } + } + + /* add non-standard lba format */ + id_ns->nlbaf++; + id_ns->lbaf[id_ns->nlbaf].ds =3D ds; + id_ns->lbaf[id_ns->nlbaf].ms =3D ms; + id_ns->flbas |=3D id_ns->nlbaf; + +lbaf_found: nlbas =3D nvme_ns_nlbas(ns); =20 id_ns->nsze =3D cpu_to_le64(nlbas); @@ -244,9 +285,10 @@ static void nvme_ns_zoned_init_state(NvmeNamespace *ns) } } =20 -static void nvme_ns_init_zoned(NvmeNamespace *ns, int lba_index) +static void nvme_ns_init_zoned(NvmeNamespace *ns) { NvmeIdNsZoned *id_ns_z; + int i; =20 nvme_ns_zoned_init_state(ns); =20 @@ -258,9 +300,11 @@ static void nvme_ns_init_zoned(NvmeNamespace *ns, int = lba_index) id_ns_z->zoc =3D 0; id_ns_z->ozcs =3D ns->params.cross_zone_read ? 0x01 : 0x00; =20 - id_ns_z->lbafe[lba_index].zsze =3D cpu_to_le64(ns->zone_size); - id_ns_z->lbafe[lba_index].zdes =3D - ns->params.zd_extension_size >> 6; /* Units of 64B */ + for (i =3D 0; i <=3D ns->id_ns.nlbaf; i++) { + id_ns_z->lbafe[i].zsze =3D cpu_to_le64(ns->zone_size); + id_ns_z->lbafe[i].zdes =3D + ns->params.zd_extension_size >> 6; /* Units of 64B */ + } =20 ns->csi =3D NVME_CSI_ZONED; ns->id_ns.nsze =3D cpu_to_le64(ns->num_zones * ns->zone_size); @@ -367,7 +411,7 @@ int nvme_ns_setup(NvmeNamespace *ns, Error **errp) if (nvme_ns_zoned_check_calc_geometry(ns, errp) !=3D 0) { return -1; } - nvme_ns_init_zoned(ns, 0); + nvme_ns_init_zoned(ns); } =20 return 0; --=20 2.30.1