From nobody Tue Nov 26 06:34:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1710184470; cv=none; d=zohomail.com; s=zohoarc; b=l2jOHN6do3uyWMyg2u3VHYC4uO4ISWPna3QBxmHEiigJkXMilSIR1gG4Oi7rg3k22DM0AdszPgOkcHNfwvBG3vbcBqcaDzYb/r15e80l2Y1oKBzqDSDIResdshD7kDS9cx+4XC4Plul4fFbetwxESSnlhv3B6A7t7SnPGyQODDg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710184470; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=36zri1GcmnYjWuiUbS/DYfGvFGJWspbBOoOk5UfdR7E=; b=hCH/o5YpSGxCVZa18GnBw/wMIVyNf8oKN928m1zlPycJfloN1hZA8u7eo4GtVCuwUGy5/5/n3DUi5vOVFkLqLnnPh+RIkXUAbpr0QuNkbBc2LsdCym2IpGBWN3z3C4aJHrCpZPP6Axm/lDPVFFe4q8XMXF+kxV4R5UmDQihidcc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1710184470006581.9203445454467; Mon, 11 Mar 2024 12:14:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rjl3z-00021u-81; Mon, 11 Mar 2024 15:11:55 -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 1rjl3x-00020y-Gn; Mon, 11 Mar 2024 15:11:53 -0400 Received: from wfout6-smtp.messagingengine.com ([64.147.123.149]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rjl3o-0000FZ-SN; Mon, 11 Mar 2024 15:11:53 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.west.internal (Postfix) with ESMTP id C1BE21C000C1; Mon, 11 Mar 2024 15:11:39 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 11 Mar 2024 15:11:40 -0400 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 11 Mar 2024 15:11:34 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irrelevant.dk; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1710184299; x= 1710270699; bh=36zri1GcmnYjWuiUbS/DYfGvFGJWspbBOoOk5UfdR7E=; b=s e842zXAkQwXLEME93dnaXMiaK8uWYAtr0NlTc8HsN4mASkE7ASqnZrX0pDHWsZKt h+f1pQMBPuVKV7szLczdFvj/6cqey9U2grRfq+JlraxyYmmAwTvgVbCEjAoRYIzA LDQUyNQhTLYhwta9vQTIpR4ffQS4FQCKOvaN3RslMvPvWNy68TUfDIGwGZE7dgLZ Gr81exfaObAIqqW9NCcY2ncM9w1N1W00XVGVACPC/82dHt6uU5ma8q7xUQCQqoPC HgOSdZPfeDf8thJU5Ickd2C8Edf5UNbkb7B6tnOHQTuY5w4H8gmx3muYYmDpcyd8 42q+tU1RA2GtIjLkYWsNw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1710184299; x= 1710270699; bh=36zri1GcmnYjWuiUbS/DYfGvFGJWspbBOoOk5UfdR7E=; b=A bNfGGPEMdkWje1tib+Ms5vi4XCejX2Ghv1rqLjB4P2GHSv0PMWLMFepHevf2dS8E E6NNGoqlLEjzdc9Oh3RXM/Kul7G6PtIk2t3E5KyLFC7ULqqsAMdW3eYhV+oZje+b hEPtuiktgDjMmp1ldzOc2om/29fwEgz5RanznZjOOwO27EtHcPYR4yt+KQNQS5Fv b+739RbXcXJ9hrw9pUDuhULd1aAqXAqGnrxa0P52uR+cQzh6DcKp/o1c7KT6P7BO CVcelaD+mP8ptFR2QTNnzaRRmaqGDKuWmy4yTZ86OEMAOt2rU+7W2O3xcjSIxCfC vhkwjtk+QZHWp5wmowBow== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrjedugdduvddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepmfhlrghu shculfgvnhhsvghnuceoihhtshesihhrrhgvlhgvvhgrnhhtrdgukheqnecuggftrfgrth htvghrnhepjefgieelgfeiveehkeeuveehheekfeevgeeigfehfefgjeejhefffeegudej udegnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepih htshesihhrrhgvlhgvvhgrnhhtrdgukh X-ME-Proxy: Feedback-ID: idc91472f:Fastmail From: Klaus Jensen To: Peter Maydell , qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-block@nongnu.org, Klaus Jensen , Jesper Devantier , Yanan Wang , Marcel Apfelbaum , Eduardo Habkost , Keith Busch , Klaus Jensen , qemu-stable@nongnu.org Subject: [PULL 5/6] hw/nvme: generalize the mbar size helper Date: Mon, 11 Mar 2024 20:11:11 +0100 Message-ID: <20240311191105.35224-13-its@irrelevant.dk> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240311191105.35224-8-its@irrelevant.dk> References: <20240311191105.35224-8-its@irrelevant.dk> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3040; i=k.jensen@samsung.com; h=from:subject; bh=Iu1VY7eu1syRxpCgT+eHNq1QL+mThEly36cgVUNqMKI=; b=owJ4nAFtAZL+kA0DAAoBTeGvMW1PDekByyZiAGXvV0qSCft48nMy3ACHXN/+RxYPNlwhF548q DRQl9v8WhXVoYkBMwQAAQoAHRYhBFIoM6p14tzmokdmwE3hrzFtTw3pBQJl71dKAAoJEE3hrzFt Tw3pbuoH/3Eydkwv8kCZaQ2el3T6HPvbGawBnQr+DpIMA94jzhd8bN/pBdUExLm1mhjVIOVvuGi GyUbDvjv32cmGgSef/UD5tGXs8fK3LH86/gOZwWItVz6R3ocDeX89t3IKePxApi1LFKx1t5vgln vl1lGWH6xOCiiLQwzsnNbUChix8xfPXG+DFtcEEDaKYou5KoxdvuXGqqiMrWPRR8UOBH5D3cxHJ aGOCg2ff/d6K9C7n4/lrLMMQChO36UTHqelp44SJkz1APUCeJRwjXzrHTYjqWRG7ZMZcm8Nirv8 Z47njuy87YQjchm0eq0tw0N8ZveJt3okDHa2J2fW6FWB9V0bGgu0iKfW X-Developer-Key: i=k.jensen@samsung.com; a=openpgp; fpr=DDCA4D9C9EF931CC3468427263D56FC5E55DA838 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=64.147.123.149; envelope-from=its@irrelevant.dk; helo=wfout6-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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @irrelevant.dk) X-ZM-MESSAGEID: 1710184470711100001 Content-Type: text/plain; charset="utf-8" From: Klaus Jensen Generalize the mbar size helper such that it can handle cases where the MSI-X table and PBA are expected to be in an exclusive bar. Cc: qemu-stable@nongnu.org Reviewed-by: Jesper Wendel Devantier Signed-off-by: Klaus Jensen --- hw/nvme/ctrl.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 6c5a2b875da8..5ee8deda22a4 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -8015,13 +8015,18 @@ static void nvme_init_pmr(NvmeCtrl *n, PCIDevice *p= ci_dev) memory_region_set_enabled(&n->pmr.dev->mr, false); } =20 -static uint64_t nvme_bar_size(unsigned total_queues, unsigned total_irqs, - unsigned *msix_table_offset, - unsigned *msix_pba_offset) +static uint64_t nvme_mbar_size(unsigned total_queues, unsigned total_irqs, + unsigned *msix_table_offset, + unsigned *msix_pba_offset) { - uint64_t bar_size, msix_table_size, msix_pba_size; + uint64_t bar_size, msix_table_size; =20 bar_size =3D sizeof(NvmeBar) + 2 * total_queues * NVME_DB_SIZE; + + if (total_irqs =3D=3D 0) { + goto out; + } + bar_size =3D QEMU_ALIGN_UP(bar_size, 4 * KiB); =20 if (msix_table_offset) { @@ -8036,11 +8041,10 @@ static uint64_t nvme_bar_size(unsigned total_queues= , unsigned total_irqs, *msix_pba_offset =3D bar_size; } =20 - msix_pba_size =3D QEMU_ALIGN_UP(total_irqs, 64) / 8; - bar_size +=3D msix_pba_size; + bar_size +=3D QEMU_ALIGN_UP(total_irqs, 64) / 8; =20 - bar_size =3D pow2ceil(bar_size); - return bar_size; +out: + return pow2ceil(bar_size); } =20 static void nvme_init_sriov(NvmeCtrl *n, PCIDevice *pci_dev, uint16_t offs= et) @@ -8048,7 +8052,7 @@ static void nvme_init_sriov(NvmeCtrl *n, PCIDevice *p= ci_dev, uint16_t offset) uint16_t vf_dev_id =3D n->params.use_intel_id ? PCI_DEVICE_ID_INTEL_NVME : PCI_DEVICE_ID_REDHAT_N= VME; NvmePriCtrlCap *cap =3D &n->pri_ctrl_cap; - uint64_t bar_size =3D nvme_bar_size(le16_to_cpu(cap->vqfrsm), + uint64_t bar_size =3D nvme_mbar_size(le16_to_cpu(cap->vqfrsm), le16_to_cpu(cap->vifrsm), NULL, NULL); =20 @@ -8110,8 +8114,8 @@ static bool nvme_init_pci(NvmeCtrl *n, PCIDevice *pci= _dev, Error **errp) } =20 /* add one to max_ioqpairs to account for the admin queue pair */ - bar_size =3D nvme_bar_size(n->params.max_ioqpairs + 1, n->params.msix_= qsize, - &msix_table_offset, &msix_pba_offset); + bar_size =3D nvme_mbar_size(n->params.max_ioqpairs + 1, n->params.msix= _qsize, + &msix_table_offset, &msix_pba_offset); =20 memory_region_init(&n->bar0, OBJECT(n), "nvme-bar0", bar_size); memory_region_init_io(&n->iomem, OBJECT(n), &nvme_mmio_ops, n, "nvme", --=20 2.44.0