public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PCI/ATS:  Allow to enable ATS on VFs even if it is not enabled on PF
@ 2023-02-08 18:43 Ganapatrao Kulkarni
  2023-02-12 18:14 ` Leon Romanovsky
  0 siblings, 1 reply; 12+ messages in thread
From: Ganapatrao Kulkarni @ 2023-02-08 18:43 UTC (permalink / raw)
  To: linux-kernel, linux-pci, bhelgaas
  Cc: jean-philippe, darren, scott, gankulkarni

As per PCIe specification(section 10.5), If a VF implements an
ATS capability, its associated PF must implement an ATS capability.
The ATS Capabilities in VFs and their associated PFs are permitted to
be enabled independently.
Also, it states that the Smallest Translation Unit (STU) for VFs must be
hardwired to Zero and the associated PF's value applies to VFs STU.

The current code allows to enable ATS on VFs only if it is already
enabled on associated PF, which is not necessary as per the specification.

It is only required to have valid STU programmed on PF to enable
ATS on VFs. Adding code to write the first VFs STU to a PF's STU
when PFs ATS is not enabled.

Signed-off-by: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>
---
 drivers/pci/ats.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c
index f9cc2e10b676..a97ec67201d1 100644
--- a/drivers/pci/ats.c
+++ b/drivers/pci/ats.c
@@ -67,13 +67,20 @@ int pci_enable_ats(struct pci_dev *dev, int ps)
 	if (ps < PCI_ATS_MIN_STU)
 		return -EINVAL;
 
-	/*
-	 * Note that enabling ATS on a VF fails unless it's already enabled
-	 * with the same STU on the PF.
-	 */
 	ctrl = PCI_ATS_CTRL_ENABLE;
 	if (dev->is_virtfn) {
 		pdev = pci_physfn(dev);
+
+		if (!pdev->ats_enabled &&
+				(pdev->ats_stu < PCI_ATS_MIN_STU)) {
+			u16 ctrl2;
+
+			/* Associated PF's STU value applies to VFs. */
+			pdev->ats_stu = ps;
+			ctrl2 = PCI_ATS_CTRL_STU(pdev->ats_stu - PCI_ATS_MIN_STU);
+			pci_write_config_word(pdev, pdev->ats_cap + PCI_ATS_CTRL, ctrl2);
+		}
+
 		if (pdev->ats_stu != ps)
 			return -EINVAL;
 	} else {
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-02-23 15:45 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-08 18:43 [PATCH] PCI/ATS: Allow to enable ATS on VFs even if it is not enabled on PF Ganapatrao Kulkarni
2023-02-12 18:14 ` Leon Romanovsky
2023-02-15 20:57   ` Bjorn Helgaas
2023-02-16  7:26     ` Leon Romanovsky
2023-02-16  7:46       ` Leon Romanovsky
2023-02-16 10:47         ` Jean-Philippe Brucker
2023-02-16 10:23     ` Joerg Roedel
2023-02-16 11:12     ` Jean-Philippe Brucker
2023-02-16 11:36       ` Ganapatrao Kulkarni
2023-02-21  9:13         ` Ganapatrao Kulkarni
2023-02-21 15:46       ` Bjorn Helgaas
2023-02-23 15:45         ` Jean-Philippe Brucker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox