From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 4EBFAC64ED6 for ; Tue, 28 Feb 2023 16:33:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YYiKdyh+E2aTCn/ICbrhfzg2OXUhdBxJpDUMC9tIa1E=; b=ar1MAYZ2EjF2Un b3rPvfnbBLity0oD3AC0qvhn3lh/lRC0OSd66+MdL9aL5PYDs1EwCJnGGeEtMxT5QwRotEvkIu43N xMlfox5jaicgLofVMdvsIi4yZcPcTPvIS3Olg6Wlf+FLCllAncSKfeeSSCMBsmkayKLDtsE6Nh7FF xzjUZIjneav5rckdQD8Q4Uf6kw5SWA00o8UwIvKBd5fmKb6qIakbVUhSNzF/NVJYvDOPR/PzFE8sR 7LyDwdtHu74kM8JeO/PBjYLMqw1fQptKOnrRs/EeU2wnNe/RcOoFBn+w4XN7hMXgpA3wypu9EW522 ixMgnqe8YFMMvxq1kQ/A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pX2s7-00DlVq-4W; Tue, 28 Feb 2023 16:30:35 +0000 Received: from mga06b.intel.com ([134.134.136.31] helo=mga06.intel.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pX2s0-00DlV8-76 for linux-arm-kernel@lists.infradead.org; Tue, 28 Feb 2023 16:30:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1677601827; x=1709137827; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=dyojsfFIUKPS3PvJ1BbTCwtCmtNpDYEHb7YR/J13vUk=; b=mE99jv56T5AHm5o/ko7MYIMVmtU4liLAPI29YThxpPpYY2yXcbZp7Ee0 tmNRpbrhCxNd5++CXgajY5IObuPk00ARzZjfb/k5x0EO9euL1pqUu87YX MUNG9yD77AZE+pZlv2oGU+B4GpTNrECr7JayjLyfbWHSfCIKrBiu/ThWg /I18QBh63wgRMzJuf8LrjRXBN8DkPsLLhUdYEInGhsgjf+oKOwLiRstwx MkoRGz5Luwa5roB3od+Wkkh+YPUZ8wuVR1t66F+Z2zlJhruX6iwe4Yv0N ITk0AX51TMDoln5gwCvpmcC9HTECGZfsUSYSb3td83JMrQ8AsS4vIFKlG g==; X-IronPort-AV: E=McAfee;i="6500,9779,10635"; a="396751349" X-IronPort-AV: E=Sophos;i="5.98,222,1673942400"; d="scan'208";a="396751349" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2023 08:30:25 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10635"; a="798107637" X-IronPort-AV: E=Sophos;i="5.98,222,1673942400"; d="scan'208";a="798107637" Received: from ticela-az-102.amr.corp.intel.com (HELO [10.209.55.154]) ([10.209.55.154]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2023 08:30:24 -0800 Message-ID: Date: Tue, 28 Feb 2023 08:30:24 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0 Thunderbird/102.4.2 Subject: Re: [PATCH v2 1/2] PCI/ATS: Add a helper function to configure ATS STU of a PF Content-Language: en-US To: Ganapatrao Kulkarni , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, joro@8bytes.org, bhelgaas@google.com, robin.murphy@arm.com, will@kernel.org Cc: jean-philippe@linaro.org, darren@os.amperecomputing.com, scott@os.amperecomputing.com References: <20230228042137.1941024-1-gankulkarni@os.amperecomputing.com> <20230228042137.1941024-2-gankulkarni@os.amperecomputing.com> From: Sathyanarayanan Kuppuswamy In-Reply-To: <20230228042137.1941024-2-gankulkarni@os.amperecomputing.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230228_083028_331088_5C3DB35D X-CRM114-Status: GOOD ( 25.48 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2/27/23 8:21 PM, Ganapatrao Kulkarni wrote: > As per PCI specification (PCI Express Base Specification Revision > 6.0, Section 10.5) both PF and VFs of a PCI EP are permitted to be enabled > independently for ATS capability, however the STU(Smallest Translation > Unit) is shared between PF and VFs. For VFs, it is hardwired to Zero and > the associated PF's value applies to VFs. > > In the current code, the STU is being configured while enabling the PF ATS. > Hence, it is not able to enable ATS for VFs, if it is not enabled on the > associated PF already. > > Adding a function pci_ats_stu_configure(), which can be called to > configure the STU during PF enumeration. > Latter enumerations of VFs can successfully enable ATS independently. > > Signed-off-by: Ganapatrao Kulkarni > --- > drivers/pci/ats.c | 33 +++++++++++++++++++++++++++++++-- > include/linux/pci-ats.h | 3 +++ > 2 files changed, 34 insertions(+), 2 deletions(-) > > diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c > index f9cc2e10b676..1611bfa1d5da 100644 > --- a/drivers/pci/ats.c > +++ b/drivers/pci/ats.c > @@ -46,6 +46,35 @@ bool pci_ats_supported(struct pci_dev *dev) > } > EXPORT_SYMBOL_GPL(pci_ats_supported); > > +/** > + * pci_ats_stu_configure - Configure STU of a PF. > + * @dev: the PCI device > + * @ps: the IOMMU page shift > + * > + * Returns 0 on success, or negative on failure. > + */ > +int pci_ats_stu_configure(struct pci_dev *dev, int ps) > +{ > + u16 ctrl; > + > + if (dev->ats_enabled || dev->is_virtfn) > + return 0; Is PF allowed to re-configure STU if there are other active VF's which uses it? > + > + if (!pci_ats_supported(dev)) > + return -EINVAL; > + > + if (ps < PCI_ATS_MIN_STU) > + return -EINVAL; > + > + dev->ats_stu = ps; > + pci_read_config_word(dev, dev->ats_cap + PCI_ATS_CTRL, &ctrl); > + ctrl |= PCI_ATS_CTRL_STU(dev->ats_stu - PCI_ATS_MIN_STU); > + pci_write_config_word(dev, dev->ats_cap + PCI_ATS_CTRL, ctrl); > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(pci_ats_stu_configure); > + > /** > * pci_enable_ats - enable the ATS capability > * @dev: the PCI device > @@ -68,8 +97,8 @@ int pci_enable_ats(struct pci_dev *dev, int ps) > return -EINVAL; > > /* > - * Note that enabling ATS on a VF fails unless it's already enabled > - * with the same STU on the PF. > + * Note that enabling ATS on a VF fails unless it's already > + * configured with the same STU on the PF. > */ > ctrl = PCI_ATS_CTRL_ENABLE; > if (dev->is_virtfn) { > diff --git a/include/linux/pci-ats.h b/include/linux/pci-ats.h > index df54cd5b15db..7d62a92aaf23 100644 > --- a/include/linux/pci-ats.h > +++ b/include/linux/pci-ats.h > @@ -8,6 +8,7 @@ > /* Address Translation Service */ > bool pci_ats_supported(struct pci_dev *dev); > int pci_enable_ats(struct pci_dev *dev, int ps); > +int pci_ats_stu_configure(struct pci_dev *dev, int ps); > void pci_disable_ats(struct pci_dev *dev); > int pci_ats_queue_depth(struct pci_dev *dev); > int pci_ats_page_aligned(struct pci_dev *dev); > @@ -16,6 +17,8 @@ static inline bool pci_ats_supported(struct pci_dev *d) > { return false; } > static inline int pci_enable_ats(struct pci_dev *d, int ps) > { return -ENODEV; } > +static inline int pci_ats_stu_configure(struct pci_dev *d, int ps) > +{ return -ENODEV; } > static inline void pci_disable_ats(struct pci_dev *d) { } > static inline int pci_ats_queue_depth(struct pci_dev *d) > { return -ENODEV; } -- Sathyanarayanan Kuppuswamy Linux Kernel Developer _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel