Skip to contentSkip to conversation

Update pcie-tegra194 driver

PATCH Applied Om Prakash Singh 2 participants 9 messages Jun 23, 2021 – Aug 4, 2021

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

v3 cover Update pcie-tegra194 driver

Update pcie-tegra194 driver with bug fixing and cleanup

Changes from V2->V3
Updated subject line from "PCI: tegra:" to "PCI: tegra194:"

Changes from V1->V2
PCI: tegra: Fix handling BME_CHGED event
- Update variable naming
PCI: tegra: Fix MSI-X programming
- No change
PCI: tegra: Disable interrupts before entering L2
- Rephrase the commit message
PCI: tegra: Don't allow suspend when Tegra PCIe is in EP mode
- Update return value to -ENOTSUPP.
PCI: tegra: Cleanup unused code
- No Change

V1:
http://patchwork.ozlabs.org/project/linux-pci/cover/[email protected]/
V2:
http://patchwork.ozlabs.org/project/linux-pci/cover/[email protected]/

Om Prakash Singh (5):
PCI: tegra: Fix handling BME_CHGED event
PCI: tegra: Fix MSI-X programming
PCI: tegra: Disable interrupts before entering L2
PCI: tegra: Don't allow suspend when Tegra PCIe is in EP mode
PCI: tegra: Cleanup unused code

 drivers/pci/controller/dwc/pcie-tegra194.c | 36 +++++++++++++---------
 1 file changed, 22 insertions(+), 14 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v3 1/5 PCI: tegra194: Fix handling BME_CHGED event

In tegra_pcie_ep_hard_irq(), APPL_INTR_STATUS_L0 is stored in val and again APPL_INTR_STATUS_L1_0_0 is also stored in val. So when execution reaches "if (val & APPL_INTR_STATUS_L0_PCI_CMD_EN_INT)", val is not correct.

---
 drivers/pci/controller/dwc/pcie-tegra194.c | 30 +++++++++++-----------
 1 file changed, 15 insertions(+), 15 deletions(-)
drivers/pci/controller/dwc/pcie-tegra194.c +15 -15
index bafd2c6ab3c2..6f388523bffe 100644
@@ -615,19 +615,19 @@ static irqreturn_t tegra_pcie_ep_hard_irq(int irq, void *arg)
 	struct tegra_pcie_dw *pcie = arg;
 	struct dw_pcie_ep *ep = &pcie->pci.ep;
 	int spurious = 1;
-	u32 val, tmp;
+	u32 status_l0, status_l1, link_status;
 
-	val = appl_readl(pcie, APPL_INTR_STATUS_L0);
-	if (val & APPL_INTR_STATUS_L0_LINK_STATE_INT) {
-		val = appl_readl(pcie, APPL_INTR_STATUS_L1_0_0);
-		appl_writel(pcie, val, APPL_INTR_STATUS_L1_0_0);
+	status_l0 = appl_readl(pcie, APPL_INTR_STATUS_L0);
+	if (status_l0 & APPL_INTR_STATUS_L0_LINK_STATE_INT) {
+		status_l1 = appl_readl(pcie, APPL_INTR_STATUS_L1_0_0);
+		appl_writel(pcie, status_l1, APPL_INTR_STATUS_L1_0_0);
 
-		if (val & APPL_INTR_STATUS_L1_0_0_HOT_RESET_DONE)
+		if (status_l1 & APPL_INTR_STATUS_L1_0_0_HOT_RESET_DONE)
 			pex_ep_event_hot_rst_done(pcie);
 
-		if (val & APPL_INTR_STATUS_L1_0_0_RDLH_LINK_UP_CHGED) {
-			tmp = appl_readl(pcie, APPL_LINK_STATUS);
-			if (tmp & APPL_LINK_STATUS_RDLH_LINK_UP) {
+		if (status_l1 & APPL_INTR_STATUS_L1_0_0_RDLH_LINK_UP_CHGED) {
+			link_status = appl_readl(pcie, APPL_LINK_STATUS);
+			if (link_status & APPL_LINK_STATUS_RDLH_LINK_UP) {
 				dev_dbg(pcie->dev, "Link is up with Host\n");
 				dw_pcie_ep_linkup(ep);
 			}
@@ -636,11 +636,11 @@ static irqreturn_t tegra_pcie_ep_hard_irq(int irq, void *arg)
 		spurious = 0;
 	}
 
-	if (val & APPL_INTR_STATUS_L0_PCI_CMD_EN_INT) {
-		val = appl_readl(pcie, APPL_INTR_STATUS_L1_15);
-		appl_writel(pcie, val, APPL_INTR_STATUS_L1_15);
+	if (status_l0 & APPL_INTR_STATUS_L0_PCI_CMD_EN_INT) {
+		status_l1 = appl_readl(pcie, APPL_INTR_STATUS_L1_15);
+		appl_writel(pcie, status_l1, APPL_INTR_STATUS_L1_15);
 
-		if (val & APPL_INTR_STATUS_L1_15_CFG_BME_CHGED)
+		if (status_l1 & APPL_INTR_STATUS_L1_15_CFG_BME_CHGED)
 			return IRQ_WAKE_THREAD;
 
 		spurious = 0;
@@ -648,8 +648,8 @@ static irqreturn_t tegra_pcie_ep_hard_irq(int irq, void *arg)
 
 	if (spurious) {
 		dev_warn(pcie->dev, "Random interrupt (STATUS = 0x%08X)\n",
-			 val);
-		appl_writel(pcie, val, APPL_INTR_STATUS_L0);
+			 status_l0);
+		appl_writel(pcie, status_l0, APPL_INTR_STATUS_L0);
 	}
 
 	return IRQ_HANDLED;
Signature · 1 line
2.17.1
#2 lore raw

PATCH v3 2/5 PCI: tegra194: Fix MSI-X programming

In reply to Om Prakash Singh

Lower order MSI-X address is programmed in MSIX_ADDR_MATCH_HIGH_OFF DBI register instead of higher order address. This patch fixes this programming mistake.

---
 drivers/pci/controller/dwc/pcie-tegra194.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-tegra194.c +1 -1
index 6f388523bffe..66e00b276cd3 100644
@@ -1863,7 +1863,7 @@ static void pex_ep_event_pex_rst_deassert(struct tegra_pcie_dw *pcie)
 	val = (ep->msi_mem_phys & MSIX_ADDR_MATCH_LOW_OFF_MASK);
 	val |= MSIX_ADDR_MATCH_LOW_OFF_EN;
 	dw_pcie_writel_dbi(pci, MSIX_ADDR_MATCH_LOW_OFF, val);
-	val = (lower_32_bits(ep->msi_mem_phys) & MSIX_ADDR_MATCH_HIGH_OFF_MASK);
+	val = (upper_32_bits(ep->msi_mem_phys) & MSIX_ADDR_MATCH_HIGH_OFF_MASK);
 	dw_pcie_writel_dbi(pci, MSIX_ADDR_MATCH_HIGH_OFF, val);
 
 	ret = dw_pcie_ep_init_complete(ep);
Signature · 1 line
2.17.1
#3 lore raw

PATCH v3 3/5 PCI: tegra194: Disable interrupts before entering L2

In reply to Om Prakash Singh

In suspend_noirq() call if link doesn't goto L2, PERST# is asserted to bring link to detect state. However, this is causing surprise link down AER error. Since Kernel is executing noirq suspend calls, AER interrupt is not processed. PME and AER are shared interrupts and PCIe subsystem driver enables wake capability of PME irq during suspend. So this AER will cause suspend failure due to pending AER interrupt.

After PCIe link is in L2, interrupts are not expected since PCIe controller will be in reset state. Disable PCIe interrupts before going to L2 state to avoid pending AER interrupt.

---
 drivers/pci/controller/dwc/pcie-tegra194.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/pci/controller/dwc/pcie-tegra194.c +10 -0
index 66e00b276cd3..64ec0da31b5b 100644
@@ -1593,6 +1593,16 @@ static void tegra_pcie_dw_pme_turnoff(struct tegra_pcie_dw *pcie)
 		return;
 	}
 
+	/*
+	 * PCIe controller exits from L2 only if reset is applied, so
+	 * controller doesn't handle interrupts. But in cases where
+	 * L2 entry fails, PERST# is asserted which can trigger surprise
+	 * link down AER. However this function call happens in
+	 * suspend_noirq(), so AER interrupt will not be processed.
+	 * Disable all interrupts to avoid such a scenario.
+	 */
+	appl_writel(pcie, 0x0, APPL_INTR_EN_L0_0);
+
 	if (tegra_pcie_try_link_l2(pcie)) {
 		dev_info(pcie->dev, "Link didn't transition to L2 state\n");
 		/*
Signature · 1 line
2.17.1
#4 lore raw

PATCH v3 4/5 PCI: tegra194: Don't allow suspend when Tegra PCIe is in EP mode

In reply to Om Prakash Singh

When Tegra PCIe is in endpoint mode it should be available for root port. PCIe link up by root port fails if it is in suspend state. So, don't allow Tegra to suspend when endpoint mode is enabled.

---
 drivers/pci/controller/dwc/pcie-tegra194.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/pci/controller/dwc/pcie-tegra194.c +5 -0
index 64ec0da31b5b..ae4c0a29818d 100644
@@ -2276,6 +2276,11 @@ static int tegra_pcie_dw_suspend_late(struct device *dev)
 	struct tegra_pcie_dw *pcie = dev_get_drvdata(dev);
 	u32 val;
 
+	if (pcie->mode == DW_PCIE_EP_TYPE) {
+		dev_err(dev, "Suspend is not supported in EP mode");
+		return -ENOTSUPP;
+	}
+
 	if (!pcie->link_state)
 		return 0;
 
Signature · 1 line
2.17.1
#5 lore raw

PATCH v3 5/5 PCI: tegra194: Cleanup unused code

In reply to Om Prakash Singh

Remove unused code from function tegra_pcie_config_ep.

---
 drivers/pci/controller/dwc/pcie-tegra194.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/pci/controller/dwc/pcie-tegra194.c +0 -7
index ae4c0a29818d..e9d573c850dd 100644
@@ -2045,13 +2045,6 @@ static int tegra_pcie_config_ep(struct tegra_pcie_dw *pcie,
 		return ret;
 	}
 
-	name = devm_kasprintf(dev, GFP_KERNEL, "tegra_pcie_%u_ep_work",
-			      pcie->cid);
-	if (!name) {
-		dev_err(dev, "Failed to create PCIe EP work thread string\n");
-		return -ENOMEM;
-	}
-
 	pm_runtime_enable(dev);
 
 	ret = dw_pcie_ep_init(ep);
Signature · 1 line
2.17.1
#6 lore raw
In reply to Om Prakash Singh

Hi Lorenzo,
Can you help review these patches.

Thanks,
Om

Quoted 38 lines · Om Prakash Singh

External email: Use caution opening links or attachments

Update pcie-tegra194 driver with bug fixing and cleanup

Changes from V2->V3
Updated subject line from "PCI: tegra:" to "PCI: tegra194:"

Changes from V1->V2
PCI: tegra: Fix handling BME_CHGED event
- Update variable naming
PCI: tegra: Fix MSI-X programming
- No change
PCI: tegra: Disable interrupts before entering L2
- Rephrase the commit message
PCI: tegra: Don't allow suspend when Tegra PCIe is in EP mode
- Update return value to -ENOTSUPP.
PCI: tegra: Cleanup unused code
- No Change

V1:
http://patchwork.ozlabs.org/project/linux-pci/cover/[email protected]/
V2:
http://patchwork.ozlabs.org/project/linux-pci/cover/[email protected]/

Om Prakash Singh (5):
PCI: tegra: Fix handling BME_CHGED event
PCI: tegra: Fix MSI-X programming
PCI: tegra: Disable interrupts before entering L2
PCI: tegra: Don't allow suspend when Tegra PCIe is in EP mode
PCI: tegra: Cleanup unused code

  drivers/pci/controller/dwc/pcie-tegra194.c | 36 +++++++++++++---------
  1 file changed, 22 insertions(+), 14 deletions(-)

--
2.17.1

#7 lore raw
In reply to Om Prakash Singh

Hi Lorenzo,
Please consider these patches to review.

Thanks,
Om

Quoted 38 lines · Om Prakash Singh

External email: Use caution opening links or attachments

Update pcie-tegra194 driver with bug fixing and cleanup

Changes from V2->V3
Updated subject line from "PCI: tegra:" to "PCI: tegra194:"

Changes from V1->V2
PCI: tegra: Fix handling BME_CHGED event
- Update variable naming
PCI: tegra: Fix MSI-X programming
- No change
PCI: tegra: Disable interrupts before entering L2
- Rephrase the commit message
PCI: tegra: Don't allow suspend when Tegra PCIe is in EP mode
- Update return value to -ENOTSUPP.
PCI: tegra: Cleanup unused code
- No Change

V1:
http://patchwork.ozlabs.org/project/linux-pci/cover/[email protected]/
V2:
http://patchwork.ozlabs.org/project/linux-pci/cover/[email protected]/

Om Prakash Singh (5):
PCI: tegra: Fix handling BME_CHGED event
PCI: tegra: Fix MSI-X programming
PCI: tegra: Disable interrupts before entering L2
PCI: tegra: Don't allow suspend when Tegra PCIe is in EP mode
PCI: tegra: Cleanup unused code

  drivers/pci/controller/dwc/pcie-tegra194.c | 36 +++++++++++++---------
  1 file changed, 22 insertions(+), 14 deletions(-)

--
2.17.1

#8 lore raw
In reply to Om Prakash Singh
Quoted 17 lines · Om Prakash Singh

Update pcie-tegra194 driver with bug fixing and cleanup

Changes from V2->V3
Updated subject line from "PCI: tegra:" to "PCI: tegra194:"

Changes from V1->V2
PCI: tegra: Fix handling BME_CHGED event
- Update variable naming
PCI: tegra: Fix MSI-X programming
- No change
PCI: tegra: Disable interrupts before entering L2
- Rephrase the commit message
PCI: tegra: Don't allow suspend when Tegra PCIe is in EP mode
- Update return value to -ENOTSUPP.
PCI: tegra: Cleanup unused code
- No Change

Quoted 1 line

[...]

Applied to pci/tegra194, thanks!

[1/5] PCI: tegra194: Fix handling BME_CHGED event

      https://git.kernel.org/lpieralisi/pci/c/ceb1412c1c
[2/5] PCI: tegra194: Fix MSI-X programming
      https://git.kernel.org/lpieralisi/pci/c/43537cf7e3
[3/5] PCI: tegra194: Disable interrupts before entering L2
      https://git.kernel.org/lpieralisi/pci/c/834c5cf2b5
[4/5] PCI: tegra194: Don't allow suspend when Tegra PCIe is in EP mode
      https://git.kernel.org/lpieralisi/pci/c/de2bbf2b71
[5/5] PCI: tegra194: Cleanup unused code
      https://git.kernel.org/lpieralisi/pci/c/f62750e691

Thanks,
Lorenzo