Skip to contentSkip to conversation

PCI: xilinx-nwl: Avoid crashing if configuring when the link is down

PATCH Applied Sean Anderson 3 participants 3 messages Jan 6 – Jan 12

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

PATCH 1/1 PCI: xilinx-nwl: Avoid crashing if configuring when the link is down

The ECAM will return a slave error if we access non-root devices while the link is down. Add a check for this like Linux does so we don't crash.

Fixes 2f5ad77cfea ("PCI: zynqmp: Add ZynqMP NWL PCIe root port driver")

---

 drivers/pci/pcie-xilinx-nwl.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
drivers/pci/pcie-xilinx-nwl.c +10 -7
index e03ab3be912..ab597c83e47 100644
@@ -135,6 +135,13 @@ struct nwl_pcie {
 	u32 ecam_value;
 };
 
+static bool nwl_pcie_link_up(struct nwl_pcie *pcie)
+{
+	if (readl(pcie->pcireg_base + PS_LINKUP_OFFSET) & PCIE_PHY_LINKUP_BIT)
+		return true;
+	return false;
+}
+
 static int nwl_pcie_config_address(const struct udevice *bus,
 				   pci_dev_t bdf, uint offset,
 				   void **paddress)
@@ -142,6 +149,9 @@ static int nwl_pcie_config_address(const struct udevice *bus,
 	struct nwl_pcie *pcie = dev_get_priv(bus);
 	void *addr;
 
+	if (PCI_BUS(bdf) != dev_seq(bus) && !nwl_pcie_link_up(pcie))
+		return -EIO;
+
 	addr = pcie->ecam_base;
 	addr += PCIE_ECAM_OFFSET(PCI_BUS(bdf) - dev_seq(bus),
 				 PCI_DEV(bdf), PCI_FUNC(bdf), offset);
@@ -181,13 +191,6 @@ static inline void nwl_bridge_writel(struct nwl_pcie *pcie, u32 val, u32 off)
 	writel(val, pcie->breg_base + off);
 }
 
-static bool nwl_pcie_link_up(struct nwl_pcie *pcie)
-{
-	if (readl(pcie->pcireg_base + PS_LINKUP_OFFSET) & PCIE_PHY_LINKUP_BIT)
-		return true;
-	return false;
-}
-
 static bool nwl_phy_link_up(struct nwl_pcie *pcie)
 {
 	if (readl(pcie->pcireg_base + PS_LINKUP_OFFSET) & PHY_RDY_LINKUP_BIT)
Signature · 4 lines
2.35.1.1320.gc452695387.dirty

base-commit: beab3fe49e1e9209dd32fe2791e7ac706038460f
branch: pcie_nwl_ecam
Reviewed-by on v1 1/1
#1 lore raw

Hi Sean,

Quoted 6 lines · Sean Anderson

The ECAM will return a slave error if we access non-root devices while the link is down. Add a check for this like Linux does so we don't crash.

Fixes 2f5ad77cfea ("PCI: zynqmp: Add ZynqMP NWL PCIe root port driver")

Thanks,
Stefan

Quoted 47 lines

---

  drivers/pci/pcie-xilinx-nwl.c | 17 ++++++++++-------
  1 file changed, 10 insertions(+), 7 deletions(-)
drivers/pci/pcie-xilinx-nwl.c +10 -7
index e03ab3be912..ab597c83e47 100644
@@ -135,6 +135,13 @@ struct nwl_pcie {
  	u32 ecam_value;
  };
 
+static bool nwl_pcie_link_up(struct nwl_pcie *pcie)
+{
+	if (readl(pcie->pcireg_base + PS_LINKUP_OFFSET) & PCIE_PHY_LINKUP_BIT)
+		return true;
+	return false;
+}
+
  static int nwl_pcie_config_address(const struct udevice *bus,
  				   pci_dev_t bdf, uint offset,
  				   void **paddress)
@@ -142,6 +149,9 @@ static int nwl_pcie_config_address(const struct udevice *bus,
  	struct nwl_pcie *pcie = dev_get_priv(bus);
  	void *addr;
 
+	if (PCI_BUS(bdf) != dev_seq(bus) && !nwl_pcie_link_up(pcie))
+		return -EIO;
+
  	addr = pcie->ecam_base;
  	addr += PCIE_ECAM_OFFSET(PCI_BUS(bdf) - dev_seq(bus),
  				 PCI_DEV(bdf), PCI_FUNC(bdf), offset);
@@ -181,13 +191,6 @@ static inline void nwl_bridge_writel(struct nwl_pcie *pcie, u32 val, u32 off)
  	writel(val, pcie->breg_base + off);
  }
 
-static bool nwl_pcie_link_up(struct nwl_pcie *pcie)
-{
-	if (readl(pcie->pcireg_base + PS_LINKUP_OFFSET) & PCIE_PHY_LINKUP_BIT)
-		return true;
-	return false;
-}
-
  static bool nwl_phy_link_up(struct nwl_pcie *pcie)
  {
  	if (readl(pcie->pcireg_base + PS_LINKUP_OFFSET) & PHY_RDY_LINKUP_BIT)
maintainer Applied
#2 lore raw
In reply to Sean Anderson
Quoted 43 lines · Sean Anderson

The ECAM will return a slave error if we access non-root devices while the link is down. Add a check for this like Linux does so we don't crash.

Fixes 2f5ad77cfea ("PCI: zynqmp: Add ZynqMP NWL PCIe root port driver")

---

  drivers/pci/pcie-xilinx-nwl.c | 17 ++++++++++-------
  1 file changed, 10 insertions(+), 7 deletions(-)
drivers/pci/pcie-xilinx-nwl.c +10 -0
index e03ab3be912..ab597c83e47 100644
@@ -135,6 +135,13 @@ struct nwl_pcie {
  	u32 ecam_value;
  };
 
+static bool nwl_pcie_link_up(struct nwl_pcie *pcie)
+{
+	if (readl(pcie->pcireg_base + PS_LINKUP_OFFSET) & PCIE_PHY_LINKUP_BIT)
+		return true;
+	return false;
+}
+
  static int nwl_pcie_config_address(const struct udevice *bus,
  				   pci_dev_t bdf, uint offset,
  				   void **paddress)
@@ -142,6 +149,9 @@ static int nwl_pcie_config_address(const struct udevice *bus,
  	struct nwl_pcie *pcie = dev_get_priv(bus);
  	void *addr;
 
+	if (PCI_BUS(bdf) != dev_seq(bus) && !nwl_pcie_link_up(pcie))
+		return -EIO;
+
  	addr = pcie->ecam_base;
  	addr += PCIE_ECAM_OFFSET(PCI_BUS(bdf) - dev_seq(bus),
  				 PCI_DEV(bdf), PCI_FUNC(bdf), offset);
@@ -181,13 +191,6 @@ static inline void nwl_bridge_writel(struct nwl_pcie *pcie, u32 val, u32 off)
  	writel(val, pcie->breg_base + off);
  }
 

drivers/pci/pcie-xilinx-nwl.c static inline void nwl_bridge_writel(struct nwl_pcie *pcie, u32 val, u32 off) · line 196

Quoted 10 lines
drivers/pci/pcie-xilinx-nwl.c +0 -7
-static bool nwl_pcie_link_up(struct nwl_pcie *pcie)
-{
-	if (readl(pcie->pcireg_base + PS_LINKUP_OFFSET) & PCIE_PHY_LINKUP_BIT)
-		return true;
-	return false;
-}
-
  static bool nwl_phy_link_up(struct nwl_pcie *pcie)
  {
  	if (readl(pcie->pcireg_base + PS_LINKUP_OFFSET) & PHY_RDY_LINKUP_BIT)

Applied.
M