From patchwork Thu Sep 12 11:19:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changqi Lu X-Patchwork-Id: 13801968 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 22D2CEEB591 for ; Thu, 12 Sep 2024 11:20:49 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sohsC-00083k-UV; Thu, 12 Sep 2024 07:20:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sohry-0007OV-V4 for qemu-devel@nongnu.org; Thu, 12 Sep 2024 07:20:14 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sohrv-0008H7-Kh for qemu-devel@nongnu.org; Thu, 12 Sep 2024 07:20:13 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-7178df70f28so600147b3a.2 for ; Thu, 12 Sep 2024 04:20:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1726140010; x=1726744810; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FpXCvHD2Qslc03OqNFilh7DiBfbBLmsoxBWva+ViCzE=; b=a4nw9B7iBs5/KgephC3zgmP/1x9q0dPkjBy3tLdaxgrFcU3sDuBDRTg3S6Y1z4/ZnP ga/solthTpJxP7xs1nt6DXDBmqgznrkB1RaEhmMV0Xt9Zq+dOSP2Gl3gyMepbJ4PhELh nioMYIPJ/pE2FV3hns2bjCYDhfi3dmpCPjarLvN726d85ybZGPqpeDtE75kwllW0Amn9 yViVxa+LlERIroGeYxl1Zo2SCOqSK/Jk75DL6YiQHMxnENtJ/MpRutoCveQtpuFkvU7U wviod9U4upk0w2ZzzHOsF5heY6k/43dFkMVyd/MPMEny+VyobBmJx8rPrzcyV8x3NvmC MDqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726140010; x=1726744810; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FpXCvHD2Qslc03OqNFilh7DiBfbBLmsoxBWva+ViCzE=; b=QlU+Y4gmDu6ly4H/E/TgCPkbbOWkwnX22zwtWZRPnmJFYAa2jp1knLXWWq+MkUAcL7 A7v3N2Z0NXq6duM5a1K2S07cf94647VDcN3gEsHSelFwGhi3363QtmaOkdxTg5qc5u/9 g7iUNgXGQH8z9GeQy+hLgBsprhsWVC5IPi1lVvcYiKdkGnODwpff7+Wz0wft+XFJwZlL QjggmdMQP3E3jlr3NyIRHueFUqtunF1chMmmsShew5RDg3hNZEP++MLbKtBkigXE388X 1MFJ77VbWUfTJc84cKJAV3p2ECYG1DARDk2soG1pE4HNRIauoIXCwPAiY8dM+LwBIVt+ LCYA== X-Forwarded-Encrypted: i=1; AJvYcCVXBcDSQrEeI2TahAirnuKdxY8ZhXOsOTtVYDg1B1YnujHKRMxy5+qZC06kMPGmKS9FylSbWCx0oPfn@nongnu.org X-Gm-Message-State: AOJu0YwdSFGZcfGkSRbwbQFiGXWxmDOxlStYJGhDTOHkcFWGsLdWbJ5X 32RlZCCt2dgMBHAftd+e/8taeAWUmt/k9MnlIqjGzXrlcxS8QNeN6sRv+Jqx08Q= X-Google-Smtp-Source: AGHT+IGJ4b5KNEemP6KG+oquFYD6UAbs7kOi4xU1Bz3aLpOb2C+G0vb+ps1lDYYMN0biL8h5knUQbQ== X-Received: by 2002:a05:6a00:3e18:b0:70d:2725:ebe4 with SMTP id d2e1a72fcca58-71926087d24mr3575818b3a.13.1726140009654; Thu, 12 Sep 2024 04:20:09 -0700 (PDT) Received: from TF4D9JK212.bytedance.net ([61.213.176.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-719090afadasm4552072b3a.177.2024.09.12.04.20.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 12 Sep 2024 04:20:08 -0700 (PDT) From: Changqi Lu To: qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, fam@euphon.net, ronniesahlberg@gmail.com, pbonzini@redhat.com, pl@dlhnet.de, kbusch@kernel.org, its@irrelevant.dk, foss@defmacro.it, philmd@linaro.org, pizhenwei@bytedance.com, k.jensen@samsung.com, Changqi Lu Subject: [PATCH v12 08/10] hw/nvme: enable ONCS and rescap function Date: Thu, 12 Sep 2024 19:19:15 +0800 Message-Id: <20240912111917.81477-9-luchangqi.123@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20240912111917.81477-1-luchangqi.123@bytedance.com> References: <20240912111917.81477-1-luchangqi.123@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=luchangqi.123@bytedance.com; helo=mail-pf1-x42d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, SPF_HELO_NONE=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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This commit enables ONCS to support the reservation function at the controller level. Also enables rescap function in the namespace by detecting the supported reservation function in the backend driver. Reviewed-by: Klaus Jensen Signed-off-by: Changqi Lu Signed-off-by: zhenwei pi Reviewed-by: Stefan Hajnoczi --- hw/nvme/ctrl.c | 3 ++- hw/nvme/ns.c | 5 +++++ include/block/nvme.h | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 127c3d2383..ad212de723 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -8248,7 +8248,8 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev) 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); + NVME_ONCS_COMPARE | NVME_ONCS_COPY | + NVME_ONCS_RESERVATIONS); /* * NOTE: If this device ever supports a command set that does NOT use 0x0 diff --git a/hw/nvme/ns.c b/hw/nvme/ns.c index ea8db175db..a5c903d727 100644 --- a/hw/nvme/ns.c +++ b/hw/nvme/ns.c @@ -20,6 +20,7 @@ #include "qemu/bitops.h" #include "sysemu/sysemu.h" #include "sysemu/block-backend.h" +#include "block/block_int.h" #include "nvme.h" #include "trace.h" @@ -33,6 +34,7 @@ void nvme_ns_init_format(NvmeNamespace *ns) BlockDriverInfo bdi; int npdg, ret; int64_t nlbas; + uint8_t blk_pr_cap; ns->lbaf = id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(id_ns->flbas)]; ns->lbasz = 1 << ns->lbaf.ds; @@ -55,6 +57,9 @@ void nvme_ns_init_format(NvmeNamespace *ns) } id_ns->npda = id_ns->npdg = npdg - 1; + + blk_pr_cap = blk_bs(ns->blkconf.blk)->bl.pr_cap; + id_ns->rescap = block_pr_cap_to_nvme(blk_pr_cap); } static int nvme_ns_init(NvmeNamespace *ns, Error **errp) diff --git a/include/block/nvme.h b/include/block/nvme.h index 8b125f7769..9b9eaeb3a7 100644 --- a/include/block/nvme.h +++ b/include/block/nvme.h @@ -1251,7 +1251,7 @@ enum NvmeIdCtrlOncs { NVME_ONCS_DSM = 1 << 2, NVME_ONCS_WRITE_ZEROES = 1 << 3, NVME_ONCS_FEATURES = 1 << 4, - NVME_ONCS_RESRVATIONS = 1 << 5, + NVME_ONCS_RESERVATIONS = 1 << 5, NVME_ONCS_TIMESTAMP = 1 << 6, NVME_ONCS_VERIFY = 1 << 7, NVME_ONCS_COPY = 1 << 8,