Skip to contentSkip to conversation

NTB: Fix access to link status and control register

PATCH New Sanjay R Mehta 1 participant 1 message Nov 26, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NTB: Fix access to link status and control register

From: Sanjay R Mehta <[email protected]>

The design of AMD NTB implementation is such that the NTB secondary endpoint is behind a combination of Upstream Switch (SWUS) and a Downstream Switch (SWDS). The link training happens on the SWUS and not on the secondary endpoint. So to correctly return the link status on the NTB secondary, we need to read the link status of the SWUS.

---
 drivers/ntb/hw/amd/ntb_hw_amd.c | 45 +++++++++++++++++++++++++++++++++++++----
 1 file changed, 41 insertions(+), 4 deletions(-)
drivers/ntb/hw/amd/ntb_hw_amd.c +41 -4
index ae91105..758f748 100644
@@ -842,6 +842,9 @@ static inline void ndev_init_struct(struct amd_ntb_dev *ndev,
 static int amd_poll_link(struct amd_ntb_dev *ndev)
 {
 	void __iomem *mmio = ndev->peer_mmio;
+	struct pci_dev *pdev = NULL;
+	struct pci_dev *pci_swds = NULL;
+	struct pci_dev *pci_swus = NULL;
 	u32 reg, stat;
 	int rc;
 
@@ -855,10 +858,44 @@ static int amd_poll_link(struct amd_ntb_dev *ndev)
 
 	ndev->cntl_sta = reg;
 
-	rc = pcie_capability_read_dword(ndev->ntb.pdev,
-				   PCI_EXP_LNKCTL, &stat);
-	if (rc)
-		return 0;
+	if (ndev->ntb.topo == NTB_TOPO_SEC) {
+		/*
+		 * Locate the pointer to Downstream Switch for
+		 * this device
+		 */
+		pci_swds = pci_upstream_bridge(ndev->ntb.pdev);
+		if (pci_swds) {
+			/*
+			 * Locate the pointer to Upstream Switch for
+			 * this device
+			 */
+			pci_swus = pci_upstream_bridge(pci_swds);
+			if (pci_swus) {
+				/*
+				 * Read the PCIe Link Control and
+				 * Status register
+				 */
+				rc = pcie_capability_read_dword(pci_swus,
+						PCI_EXP_LNKCTL, &stat);
+				if (rc)
+					return 0;
+			} else {
+				return 0;
+			}
+		} else {
+			return 0;
+		}
+	} else if (ndev->ntb.topo == NTB_TOPO_PRI) {
+		/*
+		 * For NTB primary, we simply read the Link Status and control
+		 * register of the NTB device itself.
+		 */
+		pdev = ndev->ntb.pdev;
+		rc = pcie_capability_read_dword(pdev, PCI_EXP_LNKCTL, &stat);
+		if (rc)
+			return 0;
+	}
+
 	ndev->lnk_sta = stat;
 
 	return 1;
Signature · 1 line
2.7.4