From nobody Sun Sep 20 14:32:35 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1780585728; cv=none; d=zohomail.com; s=zohoarc; b=mbLOrKJTlCCZ3XQM5u4JxrgKfUMH6HXlIDsPaszsk8/DNTF4X7mxT+Kf18myb+7s9QDjbsRAEzdLq0AUN1KdQx/mm27vguQSzOrYKyMXfV6sPSJU6BQS5KinttY7+Wn97YioMwUB8nMDmlRq8z5bJGN+doHN2mPJLTygPIzxivY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780585728; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=DQ5QlRlqJf2BWfjEpgZtMhqYoBzzggdHeyuHigzWBDQ=; b=AwmI90LKtIBYGt/SVP2NhNjdXV6PIhdjjxmSNjaHdYnBuLskPvpcWncbuw4/n1M+J2CaZIo70YF0Pii6guJW9hfy8b9OE5gwdei80X+Y+CnCTpTfRB0LBgz5SN3iNpU7Lyo5r2j6JOhRJTGiuvyUB5QQftPJroMb7Ua2VHZKdME= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1780585728174289.18676606621807; Thu, 4 Jun 2026 08:08:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1328041.1592742 (Exim 4.92) (envelope-from ) id 1wV9gD-00061X-U3; Thu, 04 Jun 2026 15:08:21 +0000 Received: by outflank-mailman (output) from mailman id 1328041.1592742; Thu, 04 Jun 2026 15:08:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wV9gD-0005zn-7U; Thu, 04 Jun 2026 15:08:21 +0000 Received: by outflank-mailman (input) for mailman id 1328041; Thu, 04 Jun 2026 15:02:13 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wV9aH-0004B2-32 for xen-devel@lists.xenproject.org; Thu, 04 Jun 2026 15:02:13 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wV9aG-00ALgh-Fd for xen-devel@lists.xenproject.org; Thu, 04 Jun 2026 17:02:12 +0200 Received: from [10.42.69.7] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a21936d-bab6-0a2a0a5309dd-0a2a45078eda-38 for ; Thu, 04 Jun 2026 17:02:12 +0200 Received: from [209.85.214.172] (helo=mail-pl1-f172.google.com) by tlsNG-ef75cf.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a219373-229c-0a2a45070019-d155d6acb425-3 for ; Thu, 04 Jun 2026 17:02:12 +0200 Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2c0c1e0b0faso6078675ad.0 for ; Thu, 04 Jun 2026 08:02:11 -0700 (PDT) Received: from localhost ([2a03:2880:7ff:1::]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c16609df79sm62219485ad.42.2026.06.04.08.02.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2026 08:02:08 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780585330; x=1781190130; darn=lists.xenproject.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=DQ5QlRlqJf2BWfjEpgZtMhqYoBzzggdHeyuHigzWBDQ=; b=IOcZNkdmJQuDr7JHH+JExjDNRdKXBZJ6jbrpGw6VSMmEYZ95rilPkA7twiDZBzhxW+ Xbom02EC93Xf2KvYEGvMUnzHzqKZ/LY43Ea9RhNfVAZAon2U0Iz51kp6Mx4UamRNi94Y 7c37Fdxtwb4bVPo3NrNRiaDfnc062M1DPeOk2V6yInMIEKaSUePGKiNYinFRljjsqrtf xyPurDnKkZX8be1piPqCOFg+TCqc+fiJfuj5gU0RGrnivuX7xgHvJRzL8AzwzVNNliqn 9dXOSBNllP856xNPmc9TNN85E86sLHXmUdti2RUx+DgHEO52PXPqNwwK0VsFR1bzCOgM TnVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780585330; x=1781190130; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=DQ5QlRlqJf2BWfjEpgZtMhqYoBzzggdHeyuHigzWBDQ=; b=rvWqdHz6AM8hLj+zo/L0mM65sLKbaRX8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a17:903:1b07:b0:2c0:eee2:fc45 with SMTP id d9443c01a7336-2c163a28b9fmr86640905ad.4.1780585329440; Thu, 04 Jun 2026 08:02:09 -0700 (PDT) From: Dimitri Daskalakis To: Bjorn Helgaas Cc: linux-pci@vger.kernel.org, Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Mahesh J Salgaonkar , Oliver O'Halloran , Niklas Schnelle , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Alex Williamson , Jason Gunthorpe , Kevin Tian , Ankit Agrawal , Leon Romanovsky , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Keith Busch , Alexander Duyck , Jakub Kicinski , Dimitri Daskalakis , linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org Subject: [RFC 09/12] PCI: Add helper to compute VF Routing ID to pci.h Date: Thu, 4 Jun 2026 08:01:50 -0700 Message-ID: <20260604150153.3619662-10-dimitri.daskalakis1@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260604150153.3619662-1-dimitri.daskalakis1@gmail.com> References: <20260604150153.3619662-1-dimitri.daskalakis1@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-ef75cf/1780585332-08F66C48-6AC9C3F4/0/0 X-purgate-type: clean X-purgate-size: 2035 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1780585730156158500 Content-Type: text/plain; charset="utf-8" From: Dimitri Daskalakis The VF RID computation is identical for SR-IOV and SIOV. Add a common helper so we can share the logic across both. No functional changes. Assisted-by: Claude:claude-opus-4.7 Signed-off-by: Dimitri Daskalakis --- drivers/pci/iov.c | 8 ++++---- drivers/pci/pci.h | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 4aed4f6a42c3..5d65413ce98d 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -25,16 +25,16 @@ int pci_iov_virtfn_bus(struct pci_dev *dev, int vf_id) { if (!pci_is_sriov_physfn(dev)) return -EINVAL; - return dev->bus->number + ((dev->devfn + dev->sriov->offset + - dev->sriov->stride * vf_id) >> 8); + return pci_virtfn_routing_id(dev, dev->sriov->offset, + dev->sriov->stride, vf_id) >> 8; } =20 int pci_iov_virtfn_devfn(struct pci_dev *dev, int vf_id) { if (!pci_is_sriov_physfn(dev)) return -EINVAL; - return (dev->devfn + dev->sriov->offset + - dev->sriov->stride * vf_id) & 0xff; + return pci_virtfn_routing_id(dev, dev->sriov->offset, + dev->sriov->stride, vf_id) & 0xff; } EXPORT_SYMBOL_GPL(pci_iov_virtfn_devfn); =20 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 73b913bcb87a..45411960fd2e 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -1017,6 +1017,18 @@ static inline int pci_resource_num_to_vf_bar(int res= no) } #endif /* CONFIG_PCI_IOV */ =20 +#if defined(CONFIG_PCI_IOV) || defined(CONFIG_PCI_SIOV) +/* + * Compute the Routing ID (bus/devfn) for a VF or SDI under @pf, given the + * capability's offset and stride. + */ +static inline u16 pci_virtfn_routing_id(struct pci_dev *pf, u16 offset, + u16 stride, int id) +{ + return (pf->bus->number << 8) + pf->devfn + offset + stride * id; +} +#endif + #ifdef CONFIG_PCIE_TPH void pci_restore_tph_state(struct pci_dev *dev); void pci_save_tph_state(struct pci_dev *dev); --=20 2.52.0