linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] PCI: mvebu: Add support for error interrupt
@ 2022-08-17 23:00 Pali Rohár
  2022-08-17 23:00 ` [PATCH 1/4] dt-bindings: PCI: mvebu: Update information about " Pali Rohár
                   ` (4 more replies)
  0 siblings, 5 replies; 16+ messages in thread
From: Pali Rohár @ 2022-08-17 23:00 UTC (permalink / raw)
  To: Lorenzo Pieralisi, Krzysztof Wilczyński, Bjorn Helgaas,
	Rob Herring, Andrew Lunn, Sebastian Hesselbarth, Gregory Clement,
	Thomas Petazzoni
  Cc: linux-pci, devicetree, linux-kernel, linux-arm-kernel

PCI mvebu error interrupt source is triggered for non-INTx event.
So e.g. when AER or PME event occurs.

This patch series adds support for reporting AER and PME interrupts on
Marvell PCIe Root Ports which allows use to kernel AER and PME drivers.

Without this change kernel AER and PME drivers do not work at all.

DT bindings for this support is currently provided only for Kirkwood and
Dove platforms as other new mvebu SoCs requires extension to armada IRQ
driver, which is currently disallowed.

Without new DTS files, pci-mvebu.c driver acts as before this change,
there is no AER and PME kernel support.

I have tested this change on Armada 385 board (with additional changes
to A385 DTS files and IRQ driver, not included there) and AER interrupt
is delivered to kernel AER driver correctly.

Pali Rohár (4):
  dt-bindings: PCI: mvebu: Update information about error interrupt
  PCI: mvebu: Implement support for interrupts on emulated bridge
  ARM: dts: kirkwood: Add definitions for PCIe error interrupts
  ARM: dts: dove: Add definitions for PCIe error interrupts

 .../devicetree/bindings/pci/mvebu-pci.txt     |   1 +
 arch/arm/boot/dts/dove.dtsi                   |   8 +-
 arch/arm/boot/dts/kirkwood-6192.dtsi          |   4 +-
 arch/arm/boot/dts/kirkwood-6281.dtsi          |   4 +-
 arch/arm/boot/dts/kirkwood-6282.dtsi          |   8 +-
 arch/arm/boot/dts/kirkwood-98dx4122.dtsi      |   4 +-
 drivers/pci/controller/pci-mvebu.c            | 256 ++++++++++++++++--
 7 files changed, 252 insertions(+), 33 deletions(-)

-- 
2.20.1


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

* [PATCH 1/4] dt-bindings: PCI: mvebu: Update information about error interrupt
  2022-08-17 23:00 [PATCH 0/4] PCI: mvebu: Add support for error interrupt Pali Rohár
@ 2022-08-17 23:00 ` Pali Rohár
  2022-08-18 16:32   ` Rob Herring
  2022-08-18 19:34   ` Andrew Lunn
  2022-08-17 23:00 ` [PATCH 2/4] PCI: mvebu: Implement support for interrupts on emulated bridge Pali Rohár
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 16+ messages in thread
From: Pali Rohár @ 2022-08-17 23:00 UTC (permalink / raw)
  To: Lorenzo Pieralisi, Krzysztof Wilczyński, Bjorn Helgaas,
	Rob Herring, Andrew Lunn, Sebastian Hesselbarth, Gregory Clement,
	Thomas Petazzoni
  Cc: linux-pci, devicetree, linux-kernel, linux-arm-kernel

mvebu error interrupt is triggered by any non-intx event, which is mainly
some pcie error.

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 Documentation/devicetree/bindings/pci/mvebu-pci.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/pci/mvebu-pci.txt b/Documentation/devicetree/bindings/pci/mvebu-pci.txt
index 6d022a9d36ee..8f0bca42113f 100644
--- a/Documentation/devicetree/bindings/pci/mvebu-pci.txt
+++ b/Documentation/devicetree/bindings/pci/mvebu-pci.txt
@@ -83,6 +83,7 @@ and the following optional properties:
   specified will default to 100ms, as required by the PCIe specification.
 - interrupt-names: list of interrupt names, supported are:
    - "intx" - interrupt line triggered by one of the legacy interrupt
+   - "error" - interrupt line triggered by any other event (non-intx)
 - interrupts or interrupts-extended: List of the interrupt sources which
   corresponding to the "interrupt-names". If non-empty then also additional
   'interrupt-controller' subnode must be defined.
-- 
2.20.1


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

* [PATCH 2/4] PCI: mvebu: Implement support for interrupts on emulated bridge
  2022-08-17 23:00 [PATCH 0/4] PCI: mvebu: Add support for error interrupt Pali Rohár
  2022-08-17 23:00 ` [PATCH 1/4] dt-bindings: PCI: mvebu: Update information about " Pali Rohár
@ 2022-08-17 23:00 ` Pali Rohár
  2022-08-18 19:51   ` Andrew Lunn
  2022-08-30 12:36   ` Pali Rohár
  2022-08-17 23:00 ` [PATCH 3/4] ARM: dts: kirkwood: Add definitions for PCIe error interrupts Pali Rohár
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 16+ messages in thread
From: Pali Rohár @ 2022-08-17 23:00 UTC (permalink / raw)
  To: Lorenzo Pieralisi, Krzysztof Wilczyński, Bjorn Helgaas,
	Rob Herring, Andrew Lunn, Sebastian Hesselbarth, Gregory Clement,
	Thomas Petazzoni
  Cc: linux-pci, devicetree, linux-kernel, linux-arm-kernel

This adds support for PME and ERR interrupts reported by emulated bridge
(for PME and AER kernel drivers) via new Root Port irq chip as these
interrupts from PCIe Root Ports are handled by mvebu hardware completely
separately from INTx and MSI interrupts send by real PCIe devices.

With this change, kernel PME and AER drivers start working as they can
acquire required interrupt lines (provided by mvebu rp virtual irq chip).

Note that for this support, device tree files has to be properly adjusted
to provide "interrupts" or "interrupts-extended" property with error
interrupt source and "interrupt-names" property with "error" string.

If device tree files do not provide these properties then driver would work
as before and would not provide interrupts on emulated bridge, like before.

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 drivers/pci/controller/pci-mvebu.c | 256 ++++++++++++++++++++++++++---
 1 file changed, 237 insertions(+), 19 deletions(-)

diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c
index 54ce5d43b695..e69bdaa8de43 100644
--- a/drivers/pci/controller/pci-mvebu.c
+++ b/drivers/pci/controller/pci-mvebu.c
@@ -56,8 +56,16 @@
 #define PCIE_CONF_DATA_OFF	0x18fc
 #define PCIE_INT_CAUSE_OFF	0x1900
 #define PCIE_INT_UNMASK_OFF	0x1910
+#define  PCIE_INT_DET_COR		BIT(8)
+#define  PCIE_INT_DET_NONFATAL		BIT(9)
+#define  PCIE_INT_DET_FATAL		BIT(10)
+#define  PCIE_INT_ERR_FATAL		BIT(16)
+#define  PCIE_INT_ERR_NONFATAL		BIT(17)
+#define  PCIE_INT_ERR_COR		BIT(18)
 #define  PCIE_INT_INTX(i)		BIT(24+i)
 #define  PCIE_INT_PM_PME		BIT(28)
+#define  PCIE_INT_DET_MASK		(PCIE_INT_DET_COR | PCIE_INT_DET_NONFATAL | PCIE_INT_DET_FATAL)
+#define  PCIE_INT_ERR_MASK		(PCIE_INT_ERR_FATAL | PCIE_INT_ERR_NONFATAL | PCIE_INT_ERR_COR)
 #define  PCIE_INT_ALL_MASK		GENMASK(31, 0)
 #define PCIE_CTRL_OFF		0x1a00
 #define  PCIE_CTRL_X1_MODE		0x0001
@@ -120,9 +128,12 @@ struct mvebu_pcie_port {
 	struct resource regs;
 	u8 slot_power_limit_value;
 	u8 slot_power_limit_scale;
+	struct irq_domain *rp_irq_domain;
 	struct irq_domain *intx_irq_domain;
 	raw_spinlock_t irq_lock;
+	int error_irq;
 	int intx_irq;
+	bool pme_pending;
 };
 
 static inline void mvebu_writel(struct mvebu_pcie_port *port, u32 val, u32 reg)
@@ -321,9 +332,19 @@ static void mvebu_pcie_setup_hw(struct mvebu_pcie_port *port)
 	/* Clear all interrupt causes. */
 	mvebu_writel(port, ~PCIE_INT_ALL_MASK, PCIE_INT_CAUSE_OFF);
 
-	/* Check if "intx" interrupt was specified in DT. */
-	if (port->intx_irq > 0)
-		return;
+	/*
+	 * Unmask all error interrupts which are internally generated.
+	 * They cannot be disabled by SERR# Enable bit in PCI Command register,
+	 * see Figure 6-3: Pseudo Logic Diagram for Error Message Controls in
+	 * PCIe base specification.
+	 * Internally generated mvebu interrupts are reported via mvebu summary
+	 * interrupt which requires "error" interrupt to be specified in DT.
+	 */
+	if (port->error_irq > 0) {
+		unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
+		unmask |= PCIE_INT_DET_MASK;
+		mvebu_writel(port, unmask, PCIE_INT_UNMASK_OFF);
+	}
 
 	/*
 	 * Fallback code when "intx" interrupt was not specified in DT:
@@ -335,10 +356,12 @@ static void mvebu_pcie_setup_hw(struct mvebu_pcie_port *port)
 	 * performance penalty as every PCIe interrupt handler needs to be
 	 * called when some interrupt is triggered.
 	 */
-	unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
-	unmask |= PCIE_INT_INTX(0) | PCIE_INT_INTX(1) |
-		  PCIE_INT_INTX(2) | PCIE_INT_INTX(3);
-	mvebu_writel(port, unmask, PCIE_INT_UNMASK_OFF);
+	if (port->intx_irq <= 0) {
+		unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
+		unmask |= PCIE_INT_INTX(0) | PCIE_INT_INTX(1) |
+			  PCIE_INT_INTX(2) | PCIE_INT_INTX(3);
+		mvebu_writel(port, unmask, PCIE_INT_UNMASK_OFF);
+	}
 }
 
 static struct mvebu_pcie_port *mvebu_pcie_find_port(struct mvebu_pcie *pcie,
@@ -603,11 +626,16 @@ mvebu_pci_bridge_emul_base_conf_read(struct pci_bridge_emul *bridge,
 	case PCI_INTERRUPT_LINE: {
 		/*
 		 * From the whole 32bit register we support reading from HW only
-		 * one bit: PCI_BRIDGE_CTL_BUS_RESET.
+		 * two bits: PCI_BRIDGE_CTL_BUS_RESET and PCI_BRIDGE_CTL_SERR.
 		 * Other bits are retrieved only from emulated config buffer.
 		 */
 		__le32 *cfgspace = (__le32 *)&bridge->conf;
 		u32 val = le32_to_cpu(cfgspace[PCI_INTERRUPT_LINE / 4]);
+		if ((mvebu_readl(port, PCIE_INT_UNMASK_OFF) &
+		      PCIE_INT_ERR_MASK) == PCIE_INT_ERR_MASK)
+			val |= PCI_BRIDGE_CTL_SERR << 16;
+		else
+			val &= ~(PCI_BRIDGE_CTL_SERR << 16);
 		if (mvebu_readl(port, PCIE_CTRL_OFF) & PCIE_CTRL_MASTER_HOT_RESET)
 			val |= PCI_BRIDGE_CTL_BUS_RESET << 16;
 		else
@@ -675,6 +703,11 @@ mvebu_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge,
 		break;
 	}
 
+	case PCI_EXP_RTCTL:
+		*value = (mvebu_readl(port, PCIE_INT_UNMASK_OFF) &
+			  PCIE_INT_PM_PME) ? PCI_EXP_RTCTL_PMEIE : 0;
+		break;
+
 	case PCI_EXP_RTSTA:
 		*value = mvebu_readl(port, PCIE_RC_RTSTA);
 		break;
@@ -780,6 +813,14 @@ mvebu_pci_bridge_emul_base_conf_write(struct pci_bridge_emul *bridge,
 		break;
 
 	case PCI_INTERRUPT_LINE:
+		if ((mask & (PCI_BRIDGE_CTL_SERR << 16)) && port->error_irq > 0) {
+			u32 unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
+			if (new & (PCI_BRIDGE_CTL_SERR << 16))
+				unmask |= PCIE_INT_ERR_MASK;
+			else
+				unmask &= ~PCIE_INT_ERR_MASK;
+			mvebu_writel(port, unmask, PCIE_INT_UNMASK_OFF);
+		}
 		if (mask & (PCI_BRIDGE_CTL_BUS_RESET << 16)) {
 			u32 ctrl = mvebu_readl(port, PCIE_CTRL_OFF);
 			if (new & (PCI_BRIDGE_CTL_BUS_RESET << 16))
@@ -838,10 +879,25 @@ mvebu_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge,
 		 * PME Status bit in Root Status Register (PCIE_RC_RTSTA)
 		 * is read-only and can be cleared only by writing 0b to the
 		 * Interrupt Cause RW0C register (PCIE_INT_CAUSE_OFF). So
-		 * clear PME via Interrupt Cause.
+		 * clear PME via Interrupt Cause and also set port->pme_pending
+		 * variable to false value to start processing PME interrupts
+		 * in interrupt handler again.
 		 */
-		if (new & PCI_EXP_RTSTA_PME)
+		if (new & PCI_EXP_RTSTA_PME) {
 			mvebu_writel(port, ~PCIE_INT_PM_PME, PCIE_INT_CAUSE_OFF);
+			port->pme_pending = false;
+		}
+		break;
+
+	case PCI_EXP_RTCTL:
+		if ((mask & PCI_EXP_RTCTL_PMEIE) && port->error_irq > 0) {
+			u32 unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
+			if (new & PCI_EXP_RTCTL_PMEIE)
+				unmask |= PCIE_INT_PM_PME;
+			else
+				unmask &= ~PCIE_INT_PM_PME;
+			mvebu_writel(port, unmask, PCIE_INT_UNMASK_OFF);
+		}
 		break;
 
 	case PCI_EXP_DEVCTL2:
@@ -924,6 +980,14 @@ static int mvebu_pci_bridge_emul_init(struct mvebu_pcie_port *port)
 		bridge_flags |= PCI_BRIDGE_EMUL_NO_IO_FORWARD;
 	}
 
+	/*
+	 * Interrupts on emulated bridge are supported only when "error"
+	 * interrupt was specified in DT. Without it emulated bridge cannot
+	 * emulate interrupts.
+	 */
+	if (port->error_irq > 0)
+		bridge->conf.intpin = PCI_INTERRUPT_INTA;
+
 	/*
 	 * Older mvebu hardware provides PCIe Capability structure only in
 	 * version 1. New hardware provides it in version 2.
@@ -1072,6 +1136,26 @@ static const struct irq_domain_ops mvebu_pcie_intx_irq_domain_ops = {
 	.xlate = irq_domain_xlate_onecell,
 };
 
+static struct irq_chip rp_irq_chip = {
+	.name = "mvebu-rp",
+};
+
+static int mvebu_pcie_rp_irq_map(struct irq_domain *h,
+				   unsigned int virq, irq_hw_number_t hwirq)
+{
+	struct mvebu_pcie_port *port = h->host_data;
+
+	irq_set_chip_and_handler(virq, &rp_irq_chip, handle_simple_irq);
+	irq_set_chip_data(virq, port);
+
+	return 0;
+}
+
+static const struct irq_domain_ops mvebu_pcie_rp_irq_domain_ops = {
+	.map = mvebu_pcie_rp_irq_map,
+	.xlate = irq_domain_xlate_onecell,
+};
+
 static int mvebu_pcie_init_irq_domain(struct mvebu_pcie_port *port)
 {
 	struct device *dev = &port->pcie->pdev->dev;
@@ -1094,10 +1178,72 @@ static int mvebu_pcie_init_irq_domain(struct mvebu_pcie_port *port)
 		return -ENOMEM;
 	}
 
+	/*
+	 * When "error" interrupt was not specified in DT then there is no
+	 * support for interrupts on emulated root bridge. So skip following
+	 * initialization.
+	 */
+	if (port->error_irq <= 0)
+		return 0;
+
+	port->rp_irq_domain = irq_domain_add_linear(NULL, 1,
+						      &mvebu_pcie_rp_irq_domain_ops,
+						      port);
+	if (!port->rp_irq_domain) {
+		irq_domain_remove(port->intx_irq_domain);
+		dev_err(dev, "Failed to add Root Port IRQ domain for %s\n", port->name);
+		return -ENOMEM;
+	}
+
 	return 0;
 }
 
-static irqreturn_t mvebu_pcie_irq_handler(int irq, void *arg)
+static irqreturn_t mvebu_pcie_error_irq_handler(int irq, void *arg)
+{
+	struct mvebu_pcie_port *port = arg;
+	struct device *dev = &port->pcie->pdev->dev;
+	u32 cause, unmask, status;
+
+	cause = mvebu_readl(port, PCIE_INT_CAUSE_OFF);
+	unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
+	status = cause & unmask;
+
+	/* "error" interrupt handler does not process INTX interrupts */
+	status &= ~(PCIE_INT_INTX(0) | PCIE_INT_INTX(1) |
+		    PCIE_INT_INTX(2) | PCIE_INT_INTX(3));
+
+	/* Process PME interrupt */
+	if ((status & PCIE_INT_PM_PME) && !port->pme_pending) {
+		/*
+		 * Do not clear PME interrupt bit in Cause Register as it
+		 * invalidates also content of Root Status Register. Instead
+		 * set port->pme_pending variable to true to indicate that
+		 * next time PME interrupt should be ignored until variable
+		 * is back to the false value.
+		 */
+		port->pme_pending = true;
+		if (generic_handle_domain_irq(port->rp_irq_domain, 0) == -EINVAL)
+			dev_err_ratelimited(dev, "unhandled PME IRQ\n");
+	}
+
+	/* Process ERR interrupt */
+	if (status & PCIE_INT_ERR_MASK) {
+		mvebu_writel(port, ~PCIE_INT_ERR_MASK, PCIE_INT_CAUSE_OFF);
+		if (generic_handle_domain_irq(port->rp_irq_domain, 0) == -EINVAL)
+			dev_err_ratelimited(dev, "unhandled ERR IRQ\n");
+	}
+
+	/* Process local ERR interrupt */
+	if (status & PCIE_INT_DET_MASK) {
+		mvebu_writel(port, ~PCIE_INT_DET_MASK, PCIE_INT_CAUSE_OFF);
+		if (generic_handle_domain_irq(port->rp_irq_domain, 0) == -EINVAL)
+			dev_err_ratelimited(dev, "unhandled ERR IRQ\n");
+	}
+
+	return status ? IRQ_HANDLED : IRQ_NONE;
+}
+
+static irqreturn_t mvebu_pcie_intx_irq_handler(int irq, void *arg)
 {
 	struct mvebu_pcie_port *port = arg;
 	struct device *dev = &port->pcie->pdev->dev;
@@ -1108,6 +1254,10 @@ static irqreturn_t mvebu_pcie_irq_handler(int irq, void *arg)
 	unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
 	status = cause & unmask;
 
+	/* "intx" interrupt handler process only INTX interrupts */
+	status &= PCIE_INT_INTX(0) | PCIE_INT_INTX(1) |
+		  PCIE_INT_INTX(2) | PCIE_INT_INTX(3);
+
 	/* Process legacy INTx interrupts */
 	for (i = 0; i < PCI_NUM_INTX; i++) {
 		if (!(status & PCIE_INT_INTX(i)))
@@ -1122,9 +1272,29 @@ static irqreturn_t mvebu_pcie_irq_handler(int irq, void *arg)
 
 static int mvebu_pcie_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
 {
-	/* Interrupt support on mvebu emulated bridges is not implemented yet */
-	if (dev->bus->number == 0)
-		return 0; /* Proper return code 0 == NO_IRQ */
+	struct mvebu_pcie_port *port;
+	struct mvebu_pcie *pcie;
+
+	if (dev->bus->number == 0) {
+		/*
+		 * Each emulated root bridge for every mvebu port has its own
+		 * Root Port irq chip and irq domain. Argument pin is the INTx
+		 * pin (1=INTA, 2=INTB, 3=INTC, 4=INTD) and hwirq for function
+		 * irq_create_mapping() is indexed from zero.
+		 */
+		pcie = dev->bus->sysdata;
+		port = mvebu_pcie_find_port(pcie, dev->bus, PCI_DEVFN(slot, 0));
+		if (!port)
+			return 0; /* Proper return code 0 == NO_IRQ */
+		/*
+		 * port->rp_irq_domain is available only when "error" interrupt
+		 * was specified in DT. When is not available then interrupts
+		 * for emulated root bridge are not provided.
+		 */
+		if (port->error_irq <= 0)
+			return 0; /* Proper return code 0 == NO_IRQ */
+		return irq_create_mapping(port->rp_irq_domain, pin - 1);
+	}
 
 	return of_irq_parse_and_map_pci(dev, slot, pin);
 }
@@ -1333,6 +1503,21 @@ static int mvebu_pcie_parse_port(struct mvebu_pcie *pcie,
 			 port->name, child);
 	}
 
+	/*
+	 * Old DT bindings do not contain "error" interrupt
+	 * so do not fail probing driver when interrupt does not exist.
+	 */
+	port->error_irq = of_irq_get_byname(child, "error");
+	if (port->error_irq == -EPROBE_DEFER) {
+		ret = port->error_irq;
+		goto err;
+	}
+	if (port->error_irq <= 0) {
+		dev_warn(dev, "%s: interrupts on Root Port are unsupported, "
+			      "%pOF does not contain error interrupt\n",
+			 port->name, child);
+	}
+
 	reset_gpio = of_get_named_gpio_flags(child, "reset-gpios", 0, &flags);
 	if (reset_gpio == -EPROBE_DEFER) {
 		ret = reset_gpio;
@@ -1538,7 +1723,6 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
 
 	for (i = 0; i < pcie->nports; i++) {
 		struct mvebu_pcie_port *port = &pcie->ports[i];
-		int irq = port->intx_irq;
 
 		child = port->dn;
 		if (!child)
@@ -1566,7 +1750,7 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
 			continue;
 		}
 
-		if (irq > 0) {
+		if (port->error_irq > 0 || port->intx_irq > 0) {
 			ret = mvebu_pcie_init_irq_domain(port);
 			if (ret) {
 				dev_err(dev, "%s: cannot init irq domain\n",
@@ -1577,14 +1761,42 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
 				mvebu_pcie_powerdown(port);
 				continue;
 			}
+		}
+
+		if (port->error_irq > 0) {
+			ret = devm_request_irq(dev, port->error_irq,
+					       mvebu_pcie_error_irq_handler,
+					       IRQF_SHARED | IRQF_NO_THREAD,
+					       port->name, port);
+			if (ret) {
+				dev_err(dev, "%s: cannot register error interrupt handler: %d\n",
+					port->name, ret);
+				if (port->intx_irq_domain)
+					irq_domain_remove(port->intx_irq_domain);
+				if (port->rp_irq_domain)
+					irq_domain_remove(port->rp_irq_domain);
+				pci_bridge_emul_cleanup(&port->bridge);
+				devm_iounmap(dev, port->base);
+				port->base = NULL;
+				mvebu_pcie_powerdown(port);
+				continue;
+			}
+		}
 
-			ret = devm_request_irq(dev, irq, mvebu_pcie_irq_handler,
+		if (port->intx_irq > 0) {
+			ret = devm_request_irq(dev, port->intx_irq,
+					       mvebu_pcie_intx_irq_handler,
 					       IRQF_SHARED | IRQF_NO_THREAD,
 					       port->name, port);
 			if (ret) {
-				dev_err(dev, "%s: cannot register interrupt handler: %d\n",
+				dev_err(dev, "%s: cannot register intx interrupt handler: %d\n",
 					port->name, ret);
-				irq_domain_remove(port->intx_irq_domain);
+				if (port->error_irq > 0)
+					devm_free_irq(dev, port->error_irq, port);
+				if (port->intx_irq_domain)
+					irq_domain_remove(port->intx_irq_domain);
+				if (port->rp_irq_domain)
+					irq_domain_remove(port->rp_irq_domain);
 				pci_bridge_emul_cleanup(&port->bridge);
 				devm_iounmap(dev, port->base);
 				port->base = NULL;
@@ -1722,6 +1934,12 @@ static int mvebu_pcie_remove(struct platform_device *pdev)
 			}
 			irq_domain_remove(port->intx_irq_domain);
 		}
+		if (port->rp_irq_domain) {
+			int virq = irq_find_mapping(port->rp_irq_domain, 0);
+			if (virq > 0)
+				irq_dispose_mapping(virq);
+			irq_domain_remove(port->rp_irq_domain);
+		}
 
 		/* Free config space for emulated root bridge. */
 		pci_bridge_emul_cleanup(&port->bridge);
-- 
2.20.1


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

* [PATCH 3/4] ARM: dts: kirkwood: Add definitions for PCIe error interrupts
  2022-08-17 23:00 [PATCH 0/4] PCI: mvebu: Add support for error interrupt Pali Rohár
  2022-08-17 23:00 ` [PATCH 1/4] dt-bindings: PCI: mvebu: Update information about " Pali Rohár
  2022-08-17 23:00 ` [PATCH 2/4] PCI: mvebu: Implement support for interrupts on emulated bridge Pali Rohár
@ 2022-08-17 23:00 ` Pali Rohár
  2022-08-18 19:51   ` Andrew Lunn
  2022-08-17 23:00 ` [PATCH 4/4] ARM: dts: dove: " Pali Rohár
  2022-09-02 14:54 ` [PATCH 0/4] PCI: mvebu: Add support for error interrupt Gregory CLEMENT
  4 siblings, 1 reply; 16+ messages in thread
From: Pali Rohár @ 2022-08-17 23:00 UTC (permalink / raw)
  To: Lorenzo Pieralisi, Krzysztof Wilczyński, Bjorn Helgaas,
	Rob Herring, Andrew Lunn, Sebastian Hesselbarth, Gregory Clement,
	Thomas Petazzoni
  Cc: linux-pci, devicetree, linux-kernel, linux-arm-kernel

First PCIe controller on Kirkwood SoC reports error interrupt via IRQ 44
and second PCIe controller via IRQ 45.

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 arch/arm/boot/dts/kirkwood-6192.dtsi     | 4 ++--
 arch/arm/boot/dts/kirkwood-6281.dtsi     | 4 ++--
 arch/arm/boot/dts/kirkwood-6282.dtsi     | 8 ++++----
 arch/arm/boot/dts/kirkwood-98dx4122.dtsi | 4 ++--
 4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/arch/arm/boot/dts/kirkwood-6192.dtsi b/arch/arm/boot/dts/kirkwood-6192.dtsi
index 07f4f7f98c0c..705c0d7effed 100644
--- a/arch/arm/boot/dts/kirkwood-6192.dtsi
+++ b/arch/arm/boot/dts/kirkwood-6192.dtsi
@@ -26,8 +26,8 @@
 				ranges = <0x82000000 0 0 0x82000000 0x1 0 1 0
 					  0x81000000 0 0 0x81000000 0x1 0 1 0>;
 				bus-range = <0x00 0xff>;
-				interrupt-names = "intx";
-				interrupts = <9>;
+				interrupt-names = "intx", "error";
+				interrupts = <9>, <44>;
 				interrupt-map-mask = <0 0 0 7>;
 				interrupt-map = <0 0 0 1 &pcie_intc 0>,
 						<0 0 0 2 &pcie_intc 1>,
diff --git a/arch/arm/boot/dts/kirkwood-6281.dtsi b/arch/arm/boot/dts/kirkwood-6281.dtsi
index d08a9a5ecc26..8e311165fd13 100644
--- a/arch/arm/boot/dts/kirkwood-6281.dtsi
+++ b/arch/arm/boot/dts/kirkwood-6281.dtsi
@@ -26,8 +26,8 @@
 				ranges = <0x82000000 0 0 0x82000000 0x1 0 1 0
 					  0x81000000 0 0 0x81000000 0x1 0 1 0>;
 				bus-range = <0x00 0xff>;
-				interrupt-names = "intx";
-				interrupts = <9>;
+				interrupt-names = "intx", "error";
+				interrupts = <9>, <44>;
 				interrupt-map-mask = <0 0 0 7>;
 				interrupt-map = <0 0 0 1 &pcie_intc 0>,
 						<0 0 0 2 &pcie_intc 1>,
diff --git a/arch/arm/boot/dts/kirkwood-6282.dtsi b/arch/arm/boot/dts/kirkwood-6282.dtsi
index 2eea5b304f47..e33723160ce7 100644
--- a/arch/arm/boot/dts/kirkwood-6282.dtsi
+++ b/arch/arm/boot/dts/kirkwood-6282.dtsi
@@ -30,8 +30,8 @@
 				ranges = <0x82000000 0 0 0x82000000 0x1 0 1 0
 					  0x81000000 0 0 0x81000000 0x1 0 1 0>;
 				bus-range = <0x00 0xff>;
-				interrupt-names = "intx";
-				interrupts = <9>;
+				interrupt-names = "intx", "error";
+				interrupts = <9>, <44>;
 				interrupt-map-mask = <0 0 0 7>;
 				interrupt-map = <0 0 0 1 &pcie0_intc 0>,
 						<0 0 0 2 &pcie0_intc 1>,
@@ -58,8 +58,8 @@
 				ranges = <0x82000000 0 0 0x82000000 0x2 0 1 0
 					  0x81000000 0 0 0x81000000 0x2 0 1 0>;
 				bus-range = <0x00 0xff>;
-				interrupt-names = "intx";
-				interrupts = <10>;
+				interrupt-names = "intx", "error";
+				interrupts = <10>, <45>;
 				interrupt-map-mask = <0 0 0 7>;
 				interrupt-map = <0 0 0 1 &pcie1_intc 0>,
 						<0 0 0 2 &pcie1_intc 1>,
diff --git a/arch/arm/boot/dts/kirkwood-98dx4122.dtsi b/arch/arm/boot/dts/kirkwood-98dx4122.dtsi
index 070bc13242b8..c3469a2fc58a 100644
--- a/arch/arm/boot/dts/kirkwood-98dx4122.dtsi
+++ b/arch/arm/boot/dts/kirkwood-98dx4122.dtsi
@@ -26,8 +26,8 @@
 				ranges = <0x82000000 0 0 0x82000000 0x1 0 1 0
 					  0x81000000 0 0 0x81000000 0x1 0 1 0>;
 				bus-range = <0x00 0xff>;
-				interrupt-names = "intx";
-				interrupts = <9>;
+				interrupt-names = "intx", "error";
+				interrupts = <9>, <44>;
 				interrupt-map-mask = <0 0 0 7>;
 				interrupt-map = <0 0 0 1 &pcie_intc 0>,
 						<0 0 0 2 &pcie_intc 1>,
-- 
2.20.1


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

* [PATCH 4/4] ARM: dts: dove: Add definitions for PCIe error interrupts
  2022-08-17 23:00 [PATCH 0/4] PCI: mvebu: Add support for error interrupt Pali Rohár
                   ` (2 preceding siblings ...)
  2022-08-17 23:00 ` [PATCH 3/4] ARM: dts: kirkwood: Add definitions for PCIe error interrupts Pali Rohár
@ 2022-08-17 23:00 ` Pali Rohár
  2022-08-18 19:52   ` Andrew Lunn
  2022-09-02 14:54 ` [PATCH 0/4] PCI: mvebu: Add support for error interrupt Gregory CLEMENT
  4 siblings, 1 reply; 16+ messages in thread
From: Pali Rohár @ 2022-08-17 23:00 UTC (permalink / raw)
  To: Lorenzo Pieralisi, Krzysztof Wilczyński, Bjorn Helgaas,
	Rob Herring, Andrew Lunn, Sebastian Hesselbarth, Gregory Clement,
	Thomas Petazzoni
  Cc: linux-pci, devicetree, linux-kernel, linux-arm-kernel

First PCIe controller on Dove SoC reports error interrupt via IRQ 15
and second PCIe controller via IRQ 17.

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 arch/arm/boot/dts/dove.dtsi | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/boot/dts/dove.dtsi b/arch/arm/boot/dts/dove.dtsi
index 70d45d2b1258..9aee3cfd3e98 100644
--- a/arch/arm/boot/dts/dove.dtsi
+++ b/arch/arm/boot/dts/dove.dtsi
@@ -122,8 +122,8 @@
 				bus-range = <0x00 0xff>;
 
 				#interrupt-cells = <1>;
-				interrupt-names = "intx";
-				interrupts = <16>;
+				interrupt-names = "intx", "error";
+				interrupts = <16>, <15>;
 				interrupt-map-mask = <0 0 0 7>;
 				interrupt-map = <0 0 0 1 &pcie0_intc 0>,
 						<0 0 0 2 &pcie0_intc 1>,
@@ -151,8 +151,8 @@
 				bus-range = <0x00 0xff>;
 
 				#interrupt-cells = <1>;
-				interrupt-names = "intx";
-				interrupts = <18>;
+				interrupt-names = "intx", "error";
+				interrupts = <18>, <17>;
 				interrupt-map-mask = <0 0 0 7>;
 				interrupt-map = <0 0 0 1 &pcie1_intc 0>,
 						<0 0 0 2 &pcie1_intc 1>,
-- 
2.20.1


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

* Re: [PATCH 1/4] dt-bindings: PCI: mvebu: Update information about error interrupt
  2022-08-17 23:00 ` [PATCH 1/4] dt-bindings: PCI: mvebu: Update information about " Pali Rohár
@ 2022-08-18 16:32   ` Rob Herring
  2022-08-18 19:34   ` Andrew Lunn
  1 sibling, 0 replies; 16+ messages in thread
From: Rob Herring @ 2022-08-18 16:32 UTC (permalink / raw)
  To: Pali Rohár
  Cc: Lorenzo Pieralisi, Krzysztof Wilczyński, Bjorn Helgaas,
	Andrew Lunn, Sebastian Hesselbarth, Gregory Clement,
	Thomas Petazzoni, linux-pci, devicetree, linux-kernel,
	linux-arm-kernel

On Thu, Aug 18, 2022 at 01:00:33AM +0200, Pali Rohár wrote:
> mvebu error interrupt is triggered by any non-intx event, which is mainly
> some pcie error.
> 
> Signed-off-by: Pali Rohár <pali@kernel.org>
> ---
>  Documentation/devicetree/bindings/pci/mvebu-pci.txt | 1 +
>  1 file changed, 1 insertion(+)

Acked-by: Rob Herring <robh@kernel.org>

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

* Re: [PATCH 1/4] dt-bindings: PCI: mvebu: Update information about error interrupt
  2022-08-17 23:00 ` [PATCH 1/4] dt-bindings: PCI: mvebu: Update information about " Pali Rohár
  2022-08-18 16:32   ` Rob Herring
@ 2022-08-18 19:34   ` Andrew Lunn
  1 sibling, 0 replies; 16+ messages in thread
From: Andrew Lunn @ 2022-08-18 19:34 UTC (permalink / raw)
  To: Pali Rohár
  Cc: Lorenzo Pieralisi, Krzysztof Wilczyński, Bjorn Helgaas,
	Rob Herring, Sebastian Hesselbarth, Gregory Clement,
	Thomas Petazzoni, linux-pci, devicetree, linux-kernel,
	linux-arm-kernel

On Thu, Aug 18, 2022 at 01:00:33AM +0200, Pali Rohár wrote:
> mvebu error interrupt is triggered by any non-intx event, which is mainly
> some pcie error.
> 
> Signed-off-by: Pali Rohár <pali@kernel.org>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

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

* Re: [PATCH 2/4] PCI: mvebu: Implement support for interrupts on emulated bridge
  2022-08-17 23:00 ` [PATCH 2/4] PCI: mvebu: Implement support for interrupts on emulated bridge Pali Rohár
@ 2022-08-18 19:51   ` Andrew Lunn
  2022-08-18 20:07     ` Pali Rohár
  2022-08-30 12:36   ` Pali Rohár
  1 sibling, 1 reply; 16+ messages in thread
From: Andrew Lunn @ 2022-08-18 19:51 UTC (permalink / raw)
  To: Pali Rohár
  Cc: Lorenzo Pieralisi, Krzysztof Wilczyński, Bjorn Helgaas,
	Rob Herring, Sebastian Hesselbarth, Gregory Clement,
	Thomas Petazzoni, linux-pci, devicetree, linux-kernel,
	linux-arm-kernel

> -static irqreturn_t mvebu_pcie_irq_handler(int irq, void *arg)
> +static irqreturn_t mvebu_pcie_error_irq_handler(int irq, void *arg)
> +{
> +	struct mvebu_pcie_port *port = arg;
> +	struct device *dev = &port->pcie->pdev->dev;
> +	u32 cause, unmask, status;
> +
> +	cause = mvebu_readl(port, PCIE_INT_CAUSE_OFF);
> +	unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
> +	status = cause & unmask;
> +
> +	/* "error" interrupt handler does not process INTX interrupts */
> +	status &= ~(PCIE_INT_INTX(0) | PCIE_INT_INTX(1) |
> +		    PCIE_INT_INTX(2) | PCIE_INT_INTX(3));

Just for my understanding...

There are two interrupts, but the status information what those
interrupts actually mean are all packed into one register? I assume
reading the clause register does not clear set bits? Otherwise there
would be a race condition. Are these actually level interrupts, and in
order to clear them you need to poke some other register?

> +	/*
> +	 * Old DT bindings do not contain "error" interrupt
> +	 * so do not fail probing driver when interrupt does not exist.
> +	 */
> +	port->error_irq = of_irq_get_byname(child, "error");
> +	if (port->error_irq == -EPROBE_DEFER) {
> +		ret = port->error_irq;
> +		goto err;
> +	}
> +	if (port->error_irq <= 0) {
> +		dev_warn(dev, "%s: interrupts on Root Port are unsupported, "

Maybe that should be "Error interrupts on Root..." ?

      Andrew

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

* Re: [PATCH 3/4] ARM: dts: kirkwood: Add definitions for PCIe error interrupts
  2022-08-17 23:00 ` [PATCH 3/4] ARM: dts: kirkwood: Add definitions for PCIe error interrupts Pali Rohár
@ 2022-08-18 19:51   ` Andrew Lunn
  0 siblings, 0 replies; 16+ messages in thread
From: Andrew Lunn @ 2022-08-18 19:51 UTC (permalink / raw)
  To: Pali Rohár
  Cc: Lorenzo Pieralisi, Krzysztof Wilczyński, Bjorn Helgaas,
	Rob Herring, Sebastian Hesselbarth, Gregory Clement,
	Thomas Petazzoni, linux-pci, devicetree, linux-kernel,
	linux-arm-kernel

On Thu, Aug 18, 2022 at 01:00:35AM +0200, Pali Rohár wrote:
> First PCIe controller on Kirkwood SoC reports error interrupt via IRQ 44
> and second PCIe controller via IRQ 45.
> 
> Signed-off-by: Pali Rohár <pali@kernel.org>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

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

* Re: [PATCH 4/4] ARM: dts: dove: Add definitions for PCIe error interrupts
  2022-08-17 23:00 ` [PATCH 4/4] ARM: dts: dove: " Pali Rohár
@ 2022-08-18 19:52   ` Andrew Lunn
  0 siblings, 0 replies; 16+ messages in thread
From: Andrew Lunn @ 2022-08-18 19:52 UTC (permalink / raw)
  To: Pali Rohár
  Cc: Lorenzo Pieralisi, Krzysztof Wilczyński, Bjorn Helgaas,
	Rob Herring, Sebastian Hesselbarth, Gregory Clement,
	Thomas Petazzoni, linux-pci, devicetree, linux-kernel,
	linux-arm-kernel

On Thu, Aug 18, 2022 at 01:00:36AM +0200, Pali Rohár wrote:
> First PCIe controller on Dove SoC reports error interrupt via IRQ 15
> and second PCIe controller via IRQ 17.
> 
> Signed-off-by: Pali Rohár <pali@kernel.org>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

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

* Re: [PATCH 2/4] PCI: mvebu: Implement support for interrupts on emulated bridge
  2022-08-18 19:51   ` Andrew Lunn
@ 2022-08-18 20:07     ` Pali Rohár
  2022-08-18 20:27       ` Andrew Lunn
  0 siblings, 1 reply; 16+ messages in thread
From: Pali Rohár @ 2022-08-18 20:07 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Lorenzo Pieralisi, Krzysztof Wilczyński, Bjorn Helgaas,
	Rob Herring, Sebastian Hesselbarth, Gregory Clement,
	Thomas Petazzoni, linux-pci, devicetree, linux-kernel,
	linux-arm-kernel

On Thursday 18 August 2022 21:51:21 Andrew Lunn wrote:
> > -static irqreturn_t mvebu_pcie_irq_handler(int irq, void *arg)
> > +static irqreturn_t mvebu_pcie_error_irq_handler(int irq, void *arg)
> > +{
> > +	struct mvebu_pcie_port *port = arg;
> > +	struct device *dev = &port->pcie->pdev->dev;
> > +	u32 cause, unmask, status;
> > +
> > +	cause = mvebu_readl(port, PCIE_INT_CAUSE_OFF);
> > +	unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
> > +	status = cause & unmask;
> > +
> > +	/* "error" interrupt handler does not process INTX interrupts */
> > +	status &= ~(PCIE_INT_INTX(0) | PCIE_INT_INTX(1) |
> > +		    PCIE_INT_INTX(2) | PCIE_INT_INTX(3));
> 
> Just for my understanding...
> 
> There are two interrupts

yes

> but the status information what those
> interrupts actually mean are all packed into one register?

yes

for masking individual interrupt events there is just one shared
register for both "intx" and "error" interrupt source.

and also there is also just one shared "cause" register which says which
individual interrupt events happened.

> I assume reading the clause register does not clear set bits?

yes, reading does not clear any interrupt event.

> Otherwise there
> would be a race condition.

> Are these actually level interrupts

yes

> and in order to clear them you need to poke some other register?

to clear individual interrupt event you have to write corresponding 1b
bit into that cause register.

so if interrupts events BIT(24), BIT(16) and BIT(17) happened and
BIT(24), BIT(25), BIT(26), BIT(27) and BIT(16) are unmasked then CPU
receives two interrupts (one for intx:24-27 and one for err:16). kernel
will call interrupt handlers for both intx and err (possible also in
parallel if it unmasked on different CPUs) and each handler just clears
events which process. So writing BIT(16) into cause register clears only
event 16 and all other (24-27, 17) are still active. And level interrupt
(the correct one intx or err) is then triggered again.

> > +	/*
> > +	 * Old DT bindings do not contain "error" interrupt
> > +	 * so do not fail probing driver when interrupt does not exist.
> > +	 */
> > +	port->error_irq = of_irq_get_byname(child, "error");
> > +	if (port->error_irq == -EPROBE_DEFER) {
> > +		ret = port->error_irq;
> > +		goto err;
> > +	}
> > +	if (port->error_irq <= 0) {
> > +		dev_warn(dev, "%s: interrupts on Root Port are unsupported, "
> 
> Maybe that should be "Error interrupts on Root..." ?
> 
>       Andrew

From PCIe Root Port point of view, it can be _any_ interrupt which can
PCIe Root Port (as PCI device) reports (it does not have to be PCIe AER
- error). Without this support PCIe Root Port cannot trigger or generate
any interrupt. Note that from PCIe point of view, this Marvell Root Port
never generates INTx interrupt. INTx interrupts are generated only by
endpoint devices. Marvell Root Port reports all events via those
_custom_ Marvell interrupts triggered by "error" source. So "error" here
means "Marvell error", not "PCIe error" (e.g. PCIe AER). For example
also PME events are reported via this "error" source. And PME is not
error.

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

* Re: [PATCH 2/4] PCI: mvebu: Implement support for interrupts on emulated bridge
  2022-08-18 20:07     ` Pali Rohár
@ 2022-08-18 20:27       ` Andrew Lunn
  0 siblings, 0 replies; 16+ messages in thread
From: Andrew Lunn @ 2022-08-18 20:27 UTC (permalink / raw)
  To: Pali Rohár
  Cc: Lorenzo Pieralisi, Krzysztof Wilczyński, Bjorn Helgaas,
	Rob Herring, Sebastian Hesselbarth, Gregory Clement,
	Thomas Petazzoni, linux-pci, devicetree, linux-kernel,
	linux-arm-kernel

On Thu, Aug 18, 2022 at 10:07:37PM +0200, Pali Rohár wrote:
> On Thursday 18 August 2022 21:51:21 Andrew Lunn wrote:
> > > -static irqreturn_t mvebu_pcie_irq_handler(int irq, void *arg)
> > > +static irqreturn_t mvebu_pcie_error_irq_handler(int irq, void *arg)
> > > +{
> > > +	struct mvebu_pcie_port *port = arg;
> > > +	struct device *dev = &port->pcie->pdev->dev;
> > > +	u32 cause, unmask, status;
> > > +
> > > +	cause = mvebu_readl(port, PCIE_INT_CAUSE_OFF);
> > > +	unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
> > > +	status = cause & unmask;
> > > +
> > > +	/* "error" interrupt handler does not process INTX interrupts */
> > > +	status &= ~(PCIE_INT_INTX(0) | PCIE_INT_INTX(1) |
> > > +		    PCIE_INT_INTX(2) | PCIE_INT_INTX(3));
> > 
> > Just for my understanding...
> > 
> > There are two interrupts
> 
> yes
> 
> > but the status information what those
> > interrupts actually mean are all packed into one register?
> 
> yes
> 
> for masking individual interrupt events there is just one shared
> register for both "intx" and "error" interrupt source.
> 
> and also there is also just one shared "cause" register which says which
> individual interrupt events happened.
> 
> > I assume reading the clause register does not clear set bits?
> 
> yes, reading does not clear any interrupt event.
> 
> > Otherwise there
> > would be a race condition.
> 
> > Are these actually level interrupts
> 
> yes
> 
> > and in order to clear them you need to poke some other register?
> 
> to clear individual interrupt event you have to write corresponding 1b
> bit into that cause register.
> 
> so if interrupts events BIT(24), BIT(16) and BIT(17) happened and
> BIT(24), BIT(25), BIT(26), BIT(27) and BIT(16) are unmasked then CPU
> receives two interrupts (one for intx:24-27 and one for err:16). kernel
> will call interrupt handlers for both intx and err (possible also in
> parallel if it unmasked on different CPUs) and each handler just clears
> events which process. So writing BIT(16) into cause register clears only
> event 16 and all other (24-27, 17) are still active. And level interrupt
> (the correct one intx or err) is then triggered again.

Thanks for the explanation.

I don't know enough about PCI to be able to give a meaningful
Reviewed-by, so i will leave that to the PCI maintainer. But the DT
bits look good to me.

     Andrew

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

* Re: [PATCH 2/4] PCI: mvebu: Implement support for interrupts on emulated bridge
  2022-08-17 23:00 ` [PATCH 2/4] PCI: mvebu: Implement support for interrupts on emulated bridge Pali Rohár
  2022-08-18 19:51   ` Andrew Lunn
@ 2022-08-30 12:36   ` Pali Rohár
  2022-09-29 14:05     ` Pali Rohár
  1 sibling, 1 reply; 16+ messages in thread
From: Pali Rohár @ 2022-08-30 12:36 UTC (permalink / raw)
  To: Lorenzo Pieralisi, Krzysztof Wilczyński, Bjorn Helgaas,
	Rob Herring, Andrew Lunn, Sebastian Hesselbarth, Gregory Clement,
	Thomas Petazzoni
  Cc: linux-pci, devicetree, linux-kernel, linux-arm-kernel

On Thursday 18 August 2022 01:00:34 Pali Rohár wrote:
> This adds support for PME and ERR interrupts reported by emulated bridge
> (for PME and AER kernel drivers) via new Root Port irq chip as these
> interrupts from PCIe Root Ports are handled by mvebu hardware completely
> separately from INTx and MSI interrupts send by real PCIe devices.
> 
> With this change, kernel PME and AER drivers start working as they can
> acquire required interrupt lines (provided by mvebu rp virtual irq chip).
> 
> Note that for this support, device tree files has to be properly adjusted
> to provide "interrupts" or "interrupts-extended" property with error
> interrupt source and "interrupt-names" property with "error" string.
> 
> If device tree files do not provide these properties then driver would work
> as before and would not provide interrupts on emulated bridge, like before.
> 
> Signed-off-by: Pali Rohár <pali@kernel.org>
> ---

Just to note that because these error interrupts are shared on some
mvebu platforms, this patch depends on another patch which convert
driver to devm_request_irq() and which I sent more months before:
https://lore.kernel.org/linux-pci/20220524122817.7199-1-pali@kernel.org/

>  drivers/pci/controller/pci-mvebu.c | 256 ++++++++++++++++++++++++++---
>  1 file changed, 237 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c
> index 54ce5d43b695..e69bdaa8de43 100644
> --- a/drivers/pci/controller/pci-mvebu.c
> +++ b/drivers/pci/controller/pci-mvebu.c
> @@ -56,8 +56,16 @@
>  #define PCIE_CONF_DATA_OFF	0x18fc
>  #define PCIE_INT_CAUSE_OFF	0x1900
>  #define PCIE_INT_UNMASK_OFF	0x1910
> +#define  PCIE_INT_DET_COR		BIT(8)
> +#define  PCIE_INT_DET_NONFATAL		BIT(9)
> +#define  PCIE_INT_DET_FATAL		BIT(10)
> +#define  PCIE_INT_ERR_FATAL		BIT(16)
> +#define  PCIE_INT_ERR_NONFATAL		BIT(17)
> +#define  PCIE_INT_ERR_COR		BIT(18)
>  #define  PCIE_INT_INTX(i)		BIT(24+i)
>  #define  PCIE_INT_PM_PME		BIT(28)
> +#define  PCIE_INT_DET_MASK		(PCIE_INT_DET_COR | PCIE_INT_DET_NONFATAL | PCIE_INT_DET_FATAL)
> +#define  PCIE_INT_ERR_MASK		(PCIE_INT_ERR_FATAL | PCIE_INT_ERR_NONFATAL | PCIE_INT_ERR_COR)
>  #define  PCIE_INT_ALL_MASK		GENMASK(31, 0)
>  #define PCIE_CTRL_OFF		0x1a00
>  #define  PCIE_CTRL_X1_MODE		0x0001
> @@ -120,9 +128,12 @@ struct mvebu_pcie_port {
>  	struct resource regs;
>  	u8 slot_power_limit_value;
>  	u8 slot_power_limit_scale;
> +	struct irq_domain *rp_irq_domain;
>  	struct irq_domain *intx_irq_domain;
>  	raw_spinlock_t irq_lock;
> +	int error_irq;
>  	int intx_irq;
> +	bool pme_pending;
>  };
>  
>  static inline void mvebu_writel(struct mvebu_pcie_port *port, u32 val, u32 reg)
> @@ -321,9 +332,19 @@ static void mvebu_pcie_setup_hw(struct mvebu_pcie_port *port)
>  	/* Clear all interrupt causes. */
>  	mvebu_writel(port, ~PCIE_INT_ALL_MASK, PCIE_INT_CAUSE_OFF);
>  
> -	/* Check if "intx" interrupt was specified in DT. */
> -	if (port->intx_irq > 0)
> -		return;
> +	/*
> +	 * Unmask all error interrupts which are internally generated.
> +	 * They cannot be disabled by SERR# Enable bit in PCI Command register,
> +	 * see Figure 6-3: Pseudo Logic Diagram for Error Message Controls in
> +	 * PCIe base specification.
> +	 * Internally generated mvebu interrupts are reported via mvebu summary
> +	 * interrupt which requires "error" interrupt to be specified in DT.
> +	 */
> +	if (port->error_irq > 0) {
> +		unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
> +		unmask |= PCIE_INT_DET_MASK;
> +		mvebu_writel(port, unmask, PCIE_INT_UNMASK_OFF);
> +	}
>  
>  	/*
>  	 * Fallback code when "intx" interrupt was not specified in DT:
> @@ -335,10 +356,12 @@ static void mvebu_pcie_setup_hw(struct mvebu_pcie_port *port)
>  	 * performance penalty as every PCIe interrupt handler needs to be
>  	 * called when some interrupt is triggered.
>  	 */
> -	unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
> -	unmask |= PCIE_INT_INTX(0) | PCIE_INT_INTX(1) |
> -		  PCIE_INT_INTX(2) | PCIE_INT_INTX(3);
> -	mvebu_writel(port, unmask, PCIE_INT_UNMASK_OFF);
> +	if (port->intx_irq <= 0) {
> +		unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
> +		unmask |= PCIE_INT_INTX(0) | PCIE_INT_INTX(1) |
> +			  PCIE_INT_INTX(2) | PCIE_INT_INTX(3);
> +		mvebu_writel(port, unmask, PCIE_INT_UNMASK_OFF);
> +	}
>  }
>  
>  static struct mvebu_pcie_port *mvebu_pcie_find_port(struct mvebu_pcie *pcie,
> @@ -603,11 +626,16 @@ mvebu_pci_bridge_emul_base_conf_read(struct pci_bridge_emul *bridge,
>  	case PCI_INTERRUPT_LINE: {
>  		/*
>  		 * From the whole 32bit register we support reading from HW only
> -		 * one bit: PCI_BRIDGE_CTL_BUS_RESET.
> +		 * two bits: PCI_BRIDGE_CTL_BUS_RESET and PCI_BRIDGE_CTL_SERR.
>  		 * Other bits are retrieved only from emulated config buffer.
>  		 */
>  		__le32 *cfgspace = (__le32 *)&bridge->conf;
>  		u32 val = le32_to_cpu(cfgspace[PCI_INTERRUPT_LINE / 4]);
> +		if ((mvebu_readl(port, PCIE_INT_UNMASK_OFF) &
> +		      PCIE_INT_ERR_MASK) == PCIE_INT_ERR_MASK)
> +			val |= PCI_BRIDGE_CTL_SERR << 16;
> +		else
> +			val &= ~(PCI_BRIDGE_CTL_SERR << 16);
>  		if (mvebu_readl(port, PCIE_CTRL_OFF) & PCIE_CTRL_MASTER_HOT_RESET)
>  			val |= PCI_BRIDGE_CTL_BUS_RESET << 16;
>  		else
> @@ -675,6 +703,11 @@ mvebu_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge,
>  		break;
>  	}
>  
> +	case PCI_EXP_RTCTL:
> +		*value = (mvebu_readl(port, PCIE_INT_UNMASK_OFF) &
> +			  PCIE_INT_PM_PME) ? PCI_EXP_RTCTL_PMEIE : 0;
> +		break;
> +
>  	case PCI_EXP_RTSTA:
>  		*value = mvebu_readl(port, PCIE_RC_RTSTA);
>  		break;
> @@ -780,6 +813,14 @@ mvebu_pci_bridge_emul_base_conf_write(struct pci_bridge_emul *bridge,
>  		break;
>  
>  	case PCI_INTERRUPT_LINE:
> +		if ((mask & (PCI_BRIDGE_CTL_SERR << 16)) && port->error_irq > 0) {
> +			u32 unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
> +			if (new & (PCI_BRIDGE_CTL_SERR << 16))
> +				unmask |= PCIE_INT_ERR_MASK;
> +			else
> +				unmask &= ~PCIE_INT_ERR_MASK;
> +			mvebu_writel(port, unmask, PCIE_INT_UNMASK_OFF);
> +		}
>  		if (mask & (PCI_BRIDGE_CTL_BUS_RESET << 16)) {
>  			u32 ctrl = mvebu_readl(port, PCIE_CTRL_OFF);
>  			if (new & (PCI_BRIDGE_CTL_BUS_RESET << 16))
> @@ -838,10 +879,25 @@ mvebu_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge,
>  		 * PME Status bit in Root Status Register (PCIE_RC_RTSTA)
>  		 * is read-only and can be cleared only by writing 0b to the
>  		 * Interrupt Cause RW0C register (PCIE_INT_CAUSE_OFF). So
> -		 * clear PME via Interrupt Cause.
> +		 * clear PME via Interrupt Cause and also set port->pme_pending
> +		 * variable to false value to start processing PME interrupts
> +		 * in interrupt handler again.
>  		 */
> -		if (new & PCI_EXP_RTSTA_PME)
> +		if (new & PCI_EXP_RTSTA_PME) {
>  			mvebu_writel(port, ~PCIE_INT_PM_PME, PCIE_INT_CAUSE_OFF);
> +			port->pme_pending = false;
> +		}
> +		break;
> +
> +	case PCI_EXP_RTCTL:
> +		if ((mask & PCI_EXP_RTCTL_PMEIE) && port->error_irq > 0) {
> +			u32 unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
> +			if (new & PCI_EXP_RTCTL_PMEIE)
> +				unmask |= PCIE_INT_PM_PME;
> +			else
> +				unmask &= ~PCIE_INT_PM_PME;
> +			mvebu_writel(port, unmask, PCIE_INT_UNMASK_OFF);
> +		}
>  		break;
>  
>  	case PCI_EXP_DEVCTL2:
> @@ -924,6 +980,14 @@ static int mvebu_pci_bridge_emul_init(struct mvebu_pcie_port *port)
>  		bridge_flags |= PCI_BRIDGE_EMUL_NO_IO_FORWARD;
>  	}
>  
> +	/*
> +	 * Interrupts on emulated bridge are supported only when "error"
> +	 * interrupt was specified in DT. Without it emulated bridge cannot
> +	 * emulate interrupts.
> +	 */
> +	if (port->error_irq > 0)
> +		bridge->conf.intpin = PCI_INTERRUPT_INTA;
> +
>  	/*
>  	 * Older mvebu hardware provides PCIe Capability structure only in
>  	 * version 1. New hardware provides it in version 2.
> @@ -1072,6 +1136,26 @@ static const struct irq_domain_ops mvebu_pcie_intx_irq_domain_ops = {
>  	.xlate = irq_domain_xlate_onecell,
>  };
>  
> +static struct irq_chip rp_irq_chip = {
> +	.name = "mvebu-rp",
> +};
> +
> +static int mvebu_pcie_rp_irq_map(struct irq_domain *h,
> +				   unsigned int virq, irq_hw_number_t hwirq)
> +{
> +	struct mvebu_pcie_port *port = h->host_data;
> +
> +	irq_set_chip_and_handler(virq, &rp_irq_chip, handle_simple_irq);
> +	irq_set_chip_data(virq, port);
> +
> +	return 0;
> +}
> +
> +static const struct irq_domain_ops mvebu_pcie_rp_irq_domain_ops = {
> +	.map = mvebu_pcie_rp_irq_map,
> +	.xlate = irq_domain_xlate_onecell,
> +};
> +
>  static int mvebu_pcie_init_irq_domain(struct mvebu_pcie_port *port)
>  {
>  	struct device *dev = &port->pcie->pdev->dev;
> @@ -1094,10 +1178,72 @@ static int mvebu_pcie_init_irq_domain(struct mvebu_pcie_port *port)
>  		return -ENOMEM;
>  	}
>  
> +	/*
> +	 * When "error" interrupt was not specified in DT then there is no
> +	 * support for interrupts on emulated root bridge. So skip following
> +	 * initialization.
> +	 */
> +	if (port->error_irq <= 0)
> +		return 0;
> +
> +	port->rp_irq_domain = irq_domain_add_linear(NULL, 1,
> +						      &mvebu_pcie_rp_irq_domain_ops,
> +						      port);
> +	if (!port->rp_irq_domain) {
> +		irq_domain_remove(port->intx_irq_domain);
> +		dev_err(dev, "Failed to add Root Port IRQ domain for %s\n", port->name);
> +		return -ENOMEM;
> +	}
> +
>  	return 0;
>  }
>  
> -static irqreturn_t mvebu_pcie_irq_handler(int irq, void *arg)
> +static irqreturn_t mvebu_pcie_error_irq_handler(int irq, void *arg)
> +{
> +	struct mvebu_pcie_port *port = arg;
> +	struct device *dev = &port->pcie->pdev->dev;
> +	u32 cause, unmask, status;
> +
> +	cause = mvebu_readl(port, PCIE_INT_CAUSE_OFF);
> +	unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
> +	status = cause & unmask;
> +
> +	/* "error" interrupt handler does not process INTX interrupts */
> +	status &= ~(PCIE_INT_INTX(0) | PCIE_INT_INTX(1) |
> +		    PCIE_INT_INTX(2) | PCIE_INT_INTX(3));
> +
> +	/* Process PME interrupt */
> +	if ((status & PCIE_INT_PM_PME) && !port->pme_pending) {
> +		/*
> +		 * Do not clear PME interrupt bit in Cause Register as it
> +		 * invalidates also content of Root Status Register. Instead
> +		 * set port->pme_pending variable to true to indicate that
> +		 * next time PME interrupt should be ignored until variable
> +		 * is back to the false value.
> +		 */
> +		port->pme_pending = true;
> +		if (generic_handle_domain_irq(port->rp_irq_domain, 0) == -EINVAL)
> +			dev_err_ratelimited(dev, "unhandled PME IRQ\n");
> +	}
> +
> +	/* Process ERR interrupt */
> +	if (status & PCIE_INT_ERR_MASK) {
> +		mvebu_writel(port, ~PCIE_INT_ERR_MASK, PCIE_INT_CAUSE_OFF);
> +		if (generic_handle_domain_irq(port->rp_irq_domain, 0) == -EINVAL)
> +			dev_err_ratelimited(dev, "unhandled ERR IRQ\n");
> +	}
> +
> +	/* Process local ERR interrupt */
> +	if (status & PCIE_INT_DET_MASK) {
> +		mvebu_writel(port, ~PCIE_INT_DET_MASK, PCIE_INT_CAUSE_OFF);
> +		if (generic_handle_domain_irq(port->rp_irq_domain, 0) == -EINVAL)
> +			dev_err_ratelimited(dev, "unhandled ERR IRQ\n");
> +	}
> +
> +	return status ? IRQ_HANDLED : IRQ_NONE;
> +}
> +
> +static irqreturn_t mvebu_pcie_intx_irq_handler(int irq, void *arg)
>  {
>  	struct mvebu_pcie_port *port = arg;
>  	struct device *dev = &port->pcie->pdev->dev;
> @@ -1108,6 +1254,10 @@ static irqreturn_t mvebu_pcie_irq_handler(int irq, void *arg)
>  	unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
>  	status = cause & unmask;
>  
> +	/* "intx" interrupt handler process only INTX interrupts */
> +	status &= PCIE_INT_INTX(0) | PCIE_INT_INTX(1) |
> +		  PCIE_INT_INTX(2) | PCIE_INT_INTX(3);
> +
>  	/* Process legacy INTx interrupts */
>  	for (i = 0; i < PCI_NUM_INTX; i++) {
>  		if (!(status & PCIE_INT_INTX(i)))
> @@ -1122,9 +1272,29 @@ static irqreturn_t mvebu_pcie_irq_handler(int irq, void *arg)
>  
>  static int mvebu_pcie_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
>  {
> -	/* Interrupt support on mvebu emulated bridges is not implemented yet */
> -	if (dev->bus->number == 0)
> -		return 0; /* Proper return code 0 == NO_IRQ */
> +	struct mvebu_pcie_port *port;
> +	struct mvebu_pcie *pcie;
> +
> +	if (dev->bus->number == 0) {
> +		/*
> +		 * Each emulated root bridge for every mvebu port has its own
> +		 * Root Port irq chip and irq domain. Argument pin is the INTx
> +		 * pin (1=INTA, 2=INTB, 3=INTC, 4=INTD) and hwirq for function
> +		 * irq_create_mapping() is indexed from zero.
> +		 */
> +		pcie = dev->bus->sysdata;
> +		port = mvebu_pcie_find_port(pcie, dev->bus, PCI_DEVFN(slot, 0));
> +		if (!port)
> +			return 0; /* Proper return code 0 == NO_IRQ */
> +		/*
> +		 * port->rp_irq_domain is available only when "error" interrupt
> +		 * was specified in DT. When is not available then interrupts
> +		 * for emulated root bridge are not provided.
> +		 */
> +		if (port->error_irq <= 0)
> +			return 0; /* Proper return code 0 == NO_IRQ */
> +		return irq_create_mapping(port->rp_irq_domain, pin - 1);
> +	}
>  
>  	return of_irq_parse_and_map_pci(dev, slot, pin);
>  }
> @@ -1333,6 +1503,21 @@ static int mvebu_pcie_parse_port(struct mvebu_pcie *pcie,
>  			 port->name, child);
>  	}
>  
> +	/*
> +	 * Old DT bindings do not contain "error" interrupt
> +	 * so do not fail probing driver when interrupt does not exist.
> +	 */
> +	port->error_irq = of_irq_get_byname(child, "error");
> +	if (port->error_irq == -EPROBE_DEFER) {
> +		ret = port->error_irq;
> +		goto err;
> +	}
> +	if (port->error_irq <= 0) {
> +		dev_warn(dev, "%s: interrupts on Root Port are unsupported, "
> +			      "%pOF does not contain error interrupt\n",
> +			 port->name, child);
> +	}
> +
>  	reset_gpio = of_get_named_gpio_flags(child, "reset-gpios", 0, &flags);
>  	if (reset_gpio == -EPROBE_DEFER) {
>  		ret = reset_gpio;
> @@ -1538,7 +1723,6 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
>  
>  	for (i = 0; i < pcie->nports; i++) {
>  		struct mvebu_pcie_port *port = &pcie->ports[i];
> -		int irq = port->intx_irq;
>  
>  		child = port->dn;
>  		if (!child)
> @@ -1566,7 +1750,7 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
>  			continue;
>  		}
>  
> -		if (irq > 0) {
> +		if (port->error_irq > 0 || port->intx_irq > 0) {
>  			ret = mvebu_pcie_init_irq_domain(port);
>  			if (ret) {
>  				dev_err(dev, "%s: cannot init irq domain\n",
> @@ -1577,14 +1761,42 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
>  				mvebu_pcie_powerdown(port);
>  				continue;
>  			}
> +		}
> +
> +		if (port->error_irq > 0) {
> +			ret = devm_request_irq(dev, port->error_irq,
> +					       mvebu_pcie_error_irq_handler,
> +					       IRQF_SHARED | IRQF_NO_THREAD,
> +					       port->name, port);
> +			if (ret) {
> +				dev_err(dev, "%s: cannot register error interrupt handler: %d\n",
> +					port->name, ret);
> +				if (port->intx_irq_domain)
> +					irq_domain_remove(port->intx_irq_domain);
> +				if (port->rp_irq_domain)
> +					irq_domain_remove(port->rp_irq_domain);
> +				pci_bridge_emul_cleanup(&port->bridge);
> +				devm_iounmap(dev, port->base);
> +				port->base = NULL;
> +				mvebu_pcie_powerdown(port);
> +				continue;
> +			}
> +		}
>  
> -			ret = devm_request_irq(dev, irq, mvebu_pcie_irq_handler,
> +		if (port->intx_irq > 0) {
> +			ret = devm_request_irq(dev, port->intx_irq,
> +					       mvebu_pcie_intx_irq_handler,
>  					       IRQF_SHARED | IRQF_NO_THREAD,
>  					       port->name, port);
>  			if (ret) {
> -				dev_err(dev, "%s: cannot register interrupt handler: %d\n",
> +				dev_err(dev, "%s: cannot register intx interrupt handler: %d\n",
>  					port->name, ret);
> -				irq_domain_remove(port->intx_irq_domain);
> +				if (port->error_irq > 0)
> +					devm_free_irq(dev, port->error_irq, port);
> +				if (port->intx_irq_domain)
> +					irq_domain_remove(port->intx_irq_domain);
> +				if (port->rp_irq_domain)
> +					irq_domain_remove(port->rp_irq_domain);
>  				pci_bridge_emul_cleanup(&port->bridge);
>  				devm_iounmap(dev, port->base);
>  				port->base = NULL;
> @@ -1722,6 +1934,12 @@ static int mvebu_pcie_remove(struct platform_device *pdev)
>  			}
>  			irq_domain_remove(port->intx_irq_domain);
>  		}
> +		if (port->rp_irq_domain) {
> +			int virq = irq_find_mapping(port->rp_irq_domain, 0);
> +			if (virq > 0)
> +				irq_dispose_mapping(virq);
> +			irq_domain_remove(port->rp_irq_domain);
> +		}
>  
>  		/* Free config space for emulated root bridge. */
>  		pci_bridge_emul_cleanup(&port->bridge);
> -- 
> 2.20.1
> 

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

* Re: [PATCH 0/4] PCI: mvebu: Add support for error interrupt
  2022-08-17 23:00 [PATCH 0/4] PCI: mvebu: Add support for error interrupt Pali Rohár
                   ` (3 preceding siblings ...)
  2022-08-17 23:00 ` [PATCH 4/4] ARM: dts: dove: " Pali Rohár
@ 2022-09-02 14:54 ` Gregory CLEMENT
  4 siblings, 0 replies; 16+ messages in thread
From: Gregory CLEMENT @ 2022-09-02 14:54 UTC (permalink / raw)
  To: Pali Rohár, Lorenzo Pieralisi, Krzysztof Wilczyński,
	Bjorn Helgaas, Rob Herring, Andrew Lunn, Sebastian Hesselbarth,
	Thomas Petazzoni
  Cc: linux-pci, devicetree, linux-kernel, linux-arm-kernel

Pali Rohár <pali@kernel.org> writes:

> PCI mvebu error interrupt source is triggered for non-INTx event.
> So e.g. when AER or PME event occurs.
>
> This patch series adds support for reporting AER and PME interrupts on
> Marvell PCIe Root Ports which allows use to kernel AER and PME drivers.
>
> Without this change kernel AER and PME drivers do not work at all.
>
> DT bindings for this support is currently provided only for Kirkwood and
> Dove platforms as other new mvebu SoCs requires extension to armada IRQ
> driver, which is currently disallowed.
>
> Without new DTS files, pci-mvebu.c driver acts as before this change,
> there is no AER and PME kernel support.
>
> I have tested this change on Armada 385 board (with additional changes
> to A385 DTS files and IRQ driver, not included there) and AER interrupt
> is delivered to kernel AER driver correctly.
>
> Pali Rohár (4):
>   dt-bindings: PCI: mvebu: Update information about error interrupt
>   PCI: mvebu: Implement support for interrupts on emulated bridge


>   ARM: dts: kirkwood: Add definitions for PCIe error interrupts
>   ARM: dts: dove: Add definitions for PCIe error interrupts

Applied both dts patches on mvebu/dt

Thanks,

Gregory


>
>  .../devicetree/bindings/pci/mvebu-pci.txt     |   1 +
>  arch/arm/boot/dts/dove.dtsi                   |   8 +-
>  arch/arm/boot/dts/kirkwood-6192.dtsi          |   4 +-
>  arch/arm/boot/dts/kirkwood-6281.dtsi          |   4 +-
>  arch/arm/boot/dts/kirkwood-6282.dtsi          |   8 +-
>  arch/arm/boot/dts/kirkwood-98dx4122.dtsi      |   4 +-
>  drivers/pci/controller/pci-mvebu.c            | 256 ++++++++++++++++--
>  7 files changed, 252 insertions(+), 33 deletions(-)
>
> -- 
> 2.20.1
>

-- 
Gregory Clement, Bootlin
Embedded Linux and Kernel engineering
http://bootlin.com

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

* Re: [PATCH 2/4] PCI: mvebu: Implement support for interrupts on emulated bridge
  2022-08-30 12:36   ` Pali Rohár
@ 2022-09-29 14:05     ` Pali Rohár
  2022-09-30  7:39       ` Lorenzo Pieralisi
  0 siblings, 1 reply; 16+ messages in thread
From: Pali Rohár @ 2022-09-29 14:05 UTC (permalink / raw)
  To: Lorenzo Pieralisi, Krzysztof Wilczyński, Bjorn Helgaas,
	Rob Herring, Andrew Lunn, Sebastian Hesselbarth, Gregory Clement,
	Thomas Petazzoni, kabel
  Cc: linux-pci, devicetree, linux-kernel, linux-arm-kernel

Hello!

Gentle reminder for this patch. It is waiting there for more than month
and other patches from this patch series were already reviewed and merged.
Could you please look at it?

As stated in commit message this patch adds support for PCIe AER to
pci-mvebu.c and as we know AER required for debugging any PCIe endpoint
issues.

On Tuesday 30 August 2022 14:36:39 Pali Rohár wrote:
> On Thursday 18 August 2022 01:00:34 Pali Rohár wrote:
> > This adds support for PME and ERR interrupts reported by emulated bridge
> > (for PME and AER kernel drivers) via new Root Port irq chip as these
> > interrupts from PCIe Root Ports are handled by mvebu hardware completely
> > separately from INTx and MSI interrupts send by real PCIe devices.
> > 
> > With this change, kernel PME and AER drivers start working as they can
> > acquire required interrupt lines (provided by mvebu rp virtual irq chip).
> > 
> > Note that for this support, device tree files has to be properly adjusted
> > to provide "interrupts" or "interrupts-extended" property with error
> > interrupt source and "interrupt-names" property with "error" string.
> > 
> > If device tree files do not provide these properties then driver would work
> > as before and would not provide interrupts on emulated bridge, like before.
> > 
> > Signed-off-by: Pali Rohár <pali@kernel.org>
> > ---
> 
> Just to note that because these error interrupts are shared on some
> mvebu platforms, this patch depends on another patch which convert
> driver to devm_request_irq() and which I sent more months before:
> https://lore.kernel.org/linux-pci/20220524122817.7199-1-pali@kernel.org/
> 
> >  drivers/pci/controller/pci-mvebu.c | 256 ++++++++++++++++++++++++++---
> >  1 file changed, 237 insertions(+), 19 deletions(-)
> > 
> > diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c
> > index 54ce5d43b695..e69bdaa8de43 100644
> > --- a/drivers/pci/controller/pci-mvebu.c
> > +++ b/drivers/pci/controller/pci-mvebu.c
> > @@ -56,8 +56,16 @@
> >  #define PCIE_CONF_DATA_OFF	0x18fc
> >  #define PCIE_INT_CAUSE_OFF	0x1900
> >  #define PCIE_INT_UNMASK_OFF	0x1910
> > +#define  PCIE_INT_DET_COR		BIT(8)
> > +#define  PCIE_INT_DET_NONFATAL		BIT(9)
> > +#define  PCIE_INT_DET_FATAL		BIT(10)
> > +#define  PCIE_INT_ERR_FATAL		BIT(16)
> > +#define  PCIE_INT_ERR_NONFATAL		BIT(17)
> > +#define  PCIE_INT_ERR_COR		BIT(18)
> >  #define  PCIE_INT_INTX(i)		BIT(24+i)
> >  #define  PCIE_INT_PM_PME		BIT(28)
> > +#define  PCIE_INT_DET_MASK		(PCIE_INT_DET_COR | PCIE_INT_DET_NONFATAL | PCIE_INT_DET_FATAL)
> > +#define  PCIE_INT_ERR_MASK		(PCIE_INT_ERR_FATAL | PCIE_INT_ERR_NONFATAL | PCIE_INT_ERR_COR)
> >  #define  PCIE_INT_ALL_MASK		GENMASK(31, 0)
> >  #define PCIE_CTRL_OFF		0x1a00
> >  #define  PCIE_CTRL_X1_MODE		0x0001
> > @@ -120,9 +128,12 @@ struct mvebu_pcie_port {
> >  	struct resource regs;
> >  	u8 slot_power_limit_value;
> >  	u8 slot_power_limit_scale;
> > +	struct irq_domain *rp_irq_domain;
> >  	struct irq_domain *intx_irq_domain;
> >  	raw_spinlock_t irq_lock;
> > +	int error_irq;
> >  	int intx_irq;
> > +	bool pme_pending;
> >  };
> >  
> >  static inline void mvebu_writel(struct mvebu_pcie_port *port, u32 val, u32 reg)
> > @@ -321,9 +332,19 @@ static void mvebu_pcie_setup_hw(struct mvebu_pcie_port *port)
> >  	/* Clear all interrupt causes. */
> >  	mvebu_writel(port, ~PCIE_INT_ALL_MASK, PCIE_INT_CAUSE_OFF);
> >  
> > -	/* Check if "intx" interrupt was specified in DT. */
> > -	if (port->intx_irq > 0)
> > -		return;
> > +	/*
> > +	 * Unmask all error interrupts which are internally generated.
> > +	 * They cannot be disabled by SERR# Enable bit in PCI Command register,
> > +	 * see Figure 6-3: Pseudo Logic Diagram for Error Message Controls in
> > +	 * PCIe base specification.
> > +	 * Internally generated mvebu interrupts are reported via mvebu summary
> > +	 * interrupt which requires "error" interrupt to be specified in DT.
> > +	 */
> > +	if (port->error_irq > 0) {
> > +		unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
> > +		unmask |= PCIE_INT_DET_MASK;
> > +		mvebu_writel(port, unmask, PCIE_INT_UNMASK_OFF);
> > +	}
> >  
> >  	/*
> >  	 * Fallback code when "intx" interrupt was not specified in DT:
> > @@ -335,10 +356,12 @@ static void mvebu_pcie_setup_hw(struct mvebu_pcie_port *port)
> >  	 * performance penalty as every PCIe interrupt handler needs to be
> >  	 * called when some interrupt is triggered.
> >  	 */
> > -	unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
> > -	unmask |= PCIE_INT_INTX(0) | PCIE_INT_INTX(1) |
> > -		  PCIE_INT_INTX(2) | PCIE_INT_INTX(3);
> > -	mvebu_writel(port, unmask, PCIE_INT_UNMASK_OFF);
> > +	if (port->intx_irq <= 0) {
> > +		unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
> > +		unmask |= PCIE_INT_INTX(0) | PCIE_INT_INTX(1) |
> > +			  PCIE_INT_INTX(2) | PCIE_INT_INTX(3);
> > +		mvebu_writel(port, unmask, PCIE_INT_UNMASK_OFF);
> > +	}
> >  }
> >  
> >  static struct mvebu_pcie_port *mvebu_pcie_find_port(struct mvebu_pcie *pcie,
> > @@ -603,11 +626,16 @@ mvebu_pci_bridge_emul_base_conf_read(struct pci_bridge_emul *bridge,
> >  	case PCI_INTERRUPT_LINE: {
> >  		/*
> >  		 * From the whole 32bit register we support reading from HW only
> > -		 * one bit: PCI_BRIDGE_CTL_BUS_RESET.
> > +		 * two bits: PCI_BRIDGE_CTL_BUS_RESET and PCI_BRIDGE_CTL_SERR.
> >  		 * Other bits are retrieved only from emulated config buffer.
> >  		 */
> >  		__le32 *cfgspace = (__le32 *)&bridge->conf;
> >  		u32 val = le32_to_cpu(cfgspace[PCI_INTERRUPT_LINE / 4]);
> > +		if ((mvebu_readl(port, PCIE_INT_UNMASK_OFF) &
> > +		      PCIE_INT_ERR_MASK) == PCIE_INT_ERR_MASK)
> > +			val |= PCI_BRIDGE_CTL_SERR << 16;
> > +		else
> > +			val &= ~(PCI_BRIDGE_CTL_SERR << 16);
> >  		if (mvebu_readl(port, PCIE_CTRL_OFF) & PCIE_CTRL_MASTER_HOT_RESET)
> >  			val |= PCI_BRIDGE_CTL_BUS_RESET << 16;
> >  		else
> > @@ -675,6 +703,11 @@ mvebu_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge,
> >  		break;
> >  	}
> >  
> > +	case PCI_EXP_RTCTL:
> > +		*value = (mvebu_readl(port, PCIE_INT_UNMASK_OFF) &
> > +			  PCIE_INT_PM_PME) ? PCI_EXP_RTCTL_PMEIE : 0;
> > +		break;
> > +
> >  	case PCI_EXP_RTSTA:
> >  		*value = mvebu_readl(port, PCIE_RC_RTSTA);
> >  		break;
> > @@ -780,6 +813,14 @@ mvebu_pci_bridge_emul_base_conf_write(struct pci_bridge_emul *bridge,
> >  		break;
> >  
> >  	case PCI_INTERRUPT_LINE:
> > +		if ((mask & (PCI_BRIDGE_CTL_SERR << 16)) && port->error_irq > 0) {
> > +			u32 unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
> > +			if (new & (PCI_BRIDGE_CTL_SERR << 16))
> > +				unmask |= PCIE_INT_ERR_MASK;
> > +			else
> > +				unmask &= ~PCIE_INT_ERR_MASK;
> > +			mvebu_writel(port, unmask, PCIE_INT_UNMASK_OFF);
> > +		}
> >  		if (mask & (PCI_BRIDGE_CTL_BUS_RESET << 16)) {
> >  			u32 ctrl = mvebu_readl(port, PCIE_CTRL_OFF);
> >  			if (new & (PCI_BRIDGE_CTL_BUS_RESET << 16))
> > @@ -838,10 +879,25 @@ mvebu_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge,
> >  		 * PME Status bit in Root Status Register (PCIE_RC_RTSTA)
> >  		 * is read-only and can be cleared only by writing 0b to the
> >  		 * Interrupt Cause RW0C register (PCIE_INT_CAUSE_OFF). So
> > -		 * clear PME via Interrupt Cause.
> > +		 * clear PME via Interrupt Cause and also set port->pme_pending
> > +		 * variable to false value to start processing PME interrupts
> > +		 * in interrupt handler again.
> >  		 */
> > -		if (new & PCI_EXP_RTSTA_PME)
> > +		if (new & PCI_EXP_RTSTA_PME) {
> >  			mvebu_writel(port, ~PCIE_INT_PM_PME, PCIE_INT_CAUSE_OFF);
> > +			port->pme_pending = false;
> > +		}
> > +		break;
> > +
> > +	case PCI_EXP_RTCTL:
> > +		if ((mask & PCI_EXP_RTCTL_PMEIE) && port->error_irq > 0) {
> > +			u32 unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
> > +			if (new & PCI_EXP_RTCTL_PMEIE)
> > +				unmask |= PCIE_INT_PM_PME;
> > +			else
> > +				unmask &= ~PCIE_INT_PM_PME;
> > +			mvebu_writel(port, unmask, PCIE_INT_UNMASK_OFF);
> > +		}
> >  		break;
> >  
> >  	case PCI_EXP_DEVCTL2:
> > @@ -924,6 +980,14 @@ static int mvebu_pci_bridge_emul_init(struct mvebu_pcie_port *port)
> >  		bridge_flags |= PCI_BRIDGE_EMUL_NO_IO_FORWARD;
> >  	}
> >  
> > +	/*
> > +	 * Interrupts on emulated bridge are supported only when "error"
> > +	 * interrupt was specified in DT. Without it emulated bridge cannot
> > +	 * emulate interrupts.
> > +	 */
> > +	if (port->error_irq > 0)
> > +		bridge->conf.intpin = PCI_INTERRUPT_INTA;
> > +
> >  	/*
> >  	 * Older mvebu hardware provides PCIe Capability structure only in
> >  	 * version 1. New hardware provides it in version 2.
> > @@ -1072,6 +1136,26 @@ static const struct irq_domain_ops mvebu_pcie_intx_irq_domain_ops = {
> >  	.xlate = irq_domain_xlate_onecell,
> >  };
> >  
> > +static struct irq_chip rp_irq_chip = {
> > +	.name = "mvebu-rp",
> > +};
> > +
> > +static int mvebu_pcie_rp_irq_map(struct irq_domain *h,
> > +				   unsigned int virq, irq_hw_number_t hwirq)
> > +{
> > +	struct mvebu_pcie_port *port = h->host_data;
> > +
> > +	irq_set_chip_and_handler(virq, &rp_irq_chip, handle_simple_irq);
> > +	irq_set_chip_data(virq, port);
> > +
> > +	return 0;
> > +}
> > +
> > +static const struct irq_domain_ops mvebu_pcie_rp_irq_domain_ops = {
> > +	.map = mvebu_pcie_rp_irq_map,
> > +	.xlate = irq_domain_xlate_onecell,
> > +};
> > +
> >  static int mvebu_pcie_init_irq_domain(struct mvebu_pcie_port *port)
> >  {
> >  	struct device *dev = &port->pcie->pdev->dev;
> > @@ -1094,10 +1178,72 @@ static int mvebu_pcie_init_irq_domain(struct mvebu_pcie_port *port)
> >  		return -ENOMEM;
> >  	}
> >  
> > +	/*
> > +	 * When "error" interrupt was not specified in DT then there is no
> > +	 * support for interrupts on emulated root bridge. So skip following
> > +	 * initialization.
> > +	 */
> > +	if (port->error_irq <= 0)
> > +		return 0;
> > +
> > +	port->rp_irq_domain = irq_domain_add_linear(NULL, 1,
> > +						      &mvebu_pcie_rp_irq_domain_ops,
> > +						      port);
> > +	if (!port->rp_irq_domain) {
> > +		irq_domain_remove(port->intx_irq_domain);
> > +		dev_err(dev, "Failed to add Root Port IRQ domain for %s\n", port->name);
> > +		return -ENOMEM;
> > +	}
> > +
> >  	return 0;
> >  }
> >  
> > -static irqreturn_t mvebu_pcie_irq_handler(int irq, void *arg)
> > +static irqreturn_t mvebu_pcie_error_irq_handler(int irq, void *arg)
> > +{
> > +	struct mvebu_pcie_port *port = arg;
> > +	struct device *dev = &port->pcie->pdev->dev;
> > +	u32 cause, unmask, status;
> > +
> > +	cause = mvebu_readl(port, PCIE_INT_CAUSE_OFF);
> > +	unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
> > +	status = cause & unmask;
> > +
> > +	/* "error" interrupt handler does not process INTX interrupts */
> > +	status &= ~(PCIE_INT_INTX(0) | PCIE_INT_INTX(1) |
> > +		    PCIE_INT_INTX(2) | PCIE_INT_INTX(3));
> > +
> > +	/* Process PME interrupt */
> > +	if ((status & PCIE_INT_PM_PME) && !port->pme_pending) {
> > +		/*
> > +		 * Do not clear PME interrupt bit in Cause Register as it
> > +		 * invalidates also content of Root Status Register. Instead
> > +		 * set port->pme_pending variable to true to indicate that
> > +		 * next time PME interrupt should be ignored until variable
> > +		 * is back to the false value.
> > +		 */
> > +		port->pme_pending = true;
> > +		if (generic_handle_domain_irq(port->rp_irq_domain, 0) == -EINVAL)
> > +			dev_err_ratelimited(dev, "unhandled PME IRQ\n");
> > +	}
> > +
> > +	/* Process ERR interrupt */
> > +	if (status & PCIE_INT_ERR_MASK) {
> > +		mvebu_writel(port, ~PCIE_INT_ERR_MASK, PCIE_INT_CAUSE_OFF);
> > +		if (generic_handle_domain_irq(port->rp_irq_domain, 0) == -EINVAL)
> > +			dev_err_ratelimited(dev, "unhandled ERR IRQ\n");
> > +	}
> > +
> > +	/* Process local ERR interrupt */
> > +	if (status & PCIE_INT_DET_MASK) {
> > +		mvebu_writel(port, ~PCIE_INT_DET_MASK, PCIE_INT_CAUSE_OFF);
> > +		if (generic_handle_domain_irq(port->rp_irq_domain, 0) == -EINVAL)
> > +			dev_err_ratelimited(dev, "unhandled ERR IRQ\n");
> > +	}
> > +
> > +	return status ? IRQ_HANDLED : IRQ_NONE;
> > +}
> > +
> > +static irqreturn_t mvebu_pcie_intx_irq_handler(int irq, void *arg)
> >  {
> >  	struct mvebu_pcie_port *port = arg;
> >  	struct device *dev = &port->pcie->pdev->dev;
> > @@ -1108,6 +1254,10 @@ static irqreturn_t mvebu_pcie_irq_handler(int irq, void *arg)
> >  	unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
> >  	status = cause & unmask;
> >  
> > +	/* "intx" interrupt handler process only INTX interrupts */
> > +	status &= PCIE_INT_INTX(0) | PCIE_INT_INTX(1) |
> > +		  PCIE_INT_INTX(2) | PCIE_INT_INTX(3);
> > +
> >  	/* Process legacy INTx interrupts */
> >  	for (i = 0; i < PCI_NUM_INTX; i++) {
> >  		if (!(status & PCIE_INT_INTX(i)))
> > @@ -1122,9 +1272,29 @@ static irqreturn_t mvebu_pcie_irq_handler(int irq, void *arg)
> >  
> >  static int mvebu_pcie_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
> >  {
> > -	/* Interrupt support on mvebu emulated bridges is not implemented yet */
> > -	if (dev->bus->number == 0)
> > -		return 0; /* Proper return code 0 == NO_IRQ */
> > +	struct mvebu_pcie_port *port;
> > +	struct mvebu_pcie *pcie;
> > +
> > +	if (dev->bus->number == 0) {
> > +		/*
> > +		 * Each emulated root bridge for every mvebu port has its own
> > +		 * Root Port irq chip and irq domain. Argument pin is the INTx
> > +		 * pin (1=INTA, 2=INTB, 3=INTC, 4=INTD) and hwirq for function
> > +		 * irq_create_mapping() is indexed from zero.
> > +		 */
> > +		pcie = dev->bus->sysdata;
> > +		port = mvebu_pcie_find_port(pcie, dev->bus, PCI_DEVFN(slot, 0));
> > +		if (!port)
> > +			return 0; /* Proper return code 0 == NO_IRQ */
> > +		/*
> > +		 * port->rp_irq_domain is available only when "error" interrupt
> > +		 * was specified in DT. When is not available then interrupts
> > +		 * for emulated root bridge are not provided.
> > +		 */
> > +		if (port->error_irq <= 0)
> > +			return 0; /* Proper return code 0 == NO_IRQ */
> > +		return irq_create_mapping(port->rp_irq_domain, pin - 1);
> > +	}
> >  
> >  	return of_irq_parse_and_map_pci(dev, slot, pin);
> >  }
> > @@ -1333,6 +1503,21 @@ static int mvebu_pcie_parse_port(struct mvebu_pcie *pcie,
> >  			 port->name, child);
> >  	}
> >  
> > +	/*
> > +	 * Old DT bindings do not contain "error" interrupt
> > +	 * so do not fail probing driver when interrupt does not exist.
> > +	 */
> > +	port->error_irq = of_irq_get_byname(child, "error");
> > +	if (port->error_irq == -EPROBE_DEFER) {
> > +		ret = port->error_irq;
> > +		goto err;
> > +	}
> > +	if (port->error_irq <= 0) {
> > +		dev_warn(dev, "%s: interrupts on Root Port are unsupported, "
> > +			      "%pOF does not contain error interrupt\n",
> > +			 port->name, child);
> > +	}
> > +
> >  	reset_gpio = of_get_named_gpio_flags(child, "reset-gpios", 0, &flags);
> >  	if (reset_gpio == -EPROBE_DEFER) {
> >  		ret = reset_gpio;
> > @@ -1538,7 +1723,6 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
> >  
> >  	for (i = 0; i < pcie->nports; i++) {
> >  		struct mvebu_pcie_port *port = &pcie->ports[i];
> > -		int irq = port->intx_irq;
> >  
> >  		child = port->dn;
> >  		if (!child)
> > @@ -1566,7 +1750,7 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
> >  			continue;
> >  		}
> >  
> > -		if (irq > 0) {
> > +		if (port->error_irq > 0 || port->intx_irq > 0) {
> >  			ret = mvebu_pcie_init_irq_domain(port);
> >  			if (ret) {
> >  				dev_err(dev, "%s: cannot init irq domain\n",
> > @@ -1577,14 +1761,42 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
> >  				mvebu_pcie_powerdown(port);
> >  				continue;
> >  			}
> > +		}
> > +
> > +		if (port->error_irq > 0) {
> > +			ret = devm_request_irq(dev, port->error_irq,
> > +					       mvebu_pcie_error_irq_handler,
> > +					       IRQF_SHARED | IRQF_NO_THREAD,
> > +					       port->name, port);
> > +			if (ret) {
> > +				dev_err(dev, "%s: cannot register error interrupt handler: %d\n",
> > +					port->name, ret);
> > +				if (port->intx_irq_domain)
> > +					irq_domain_remove(port->intx_irq_domain);
> > +				if (port->rp_irq_domain)
> > +					irq_domain_remove(port->rp_irq_domain);
> > +				pci_bridge_emul_cleanup(&port->bridge);
> > +				devm_iounmap(dev, port->base);
> > +				port->base = NULL;
> > +				mvebu_pcie_powerdown(port);
> > +				continue;
> > +			}
> > +		}
> >  
> > -			ret = devm_request_irq(dev, irq, mvebu_pcie_irq_handler,
> > +		if (port->intx_irq > 0) {
> > +			ret = devm_request_irq(dev, port->intx_irq,
> > +					       mvebu_pcie_intx_irq_handler,
> >  					       IRQF_SHARED | IRQF_NO_THREAD,
> >  					       port->name, port);
> >  			if (ret) {
> > -				dev_err(dev, "%s: cannot register interrupt handler: %d\n",
> > +				dev_err(dev, "%s: cannot register intx interrupt handler: %d\n",
> >  					port->name, ret);
> > -				irq_domain_remove(port->intx_irq_domain);
> > +				if (port->error_irq > 0)
> > +					devm_free_irq(dev, port->error_irq, port);
> > +				if (port->intx_irq_domain)
> > +					irq_domain_remove(port->intx_irq_domain);
> > +				if (port->rp_irq_domain)
> > +					irq_domain_remove(port->rp_irq_domain);
> >  				pci_bridge_emul_cleanup(&port->bridge);
> >  				devm_iounmap(dev, port->base);
> >  				port->base = NULL;
> > @@ -1722,6 +1934,12 @@ static int mvebu_pcie_remove(struct platform_device *pdev)
> >  			}
> >  			irq_domain_remove(port->intx_irq_domain);
> >  		}
> > +		if (port->rp_irq_domain) {
> > +			int virq = irq_find_mapping(port->rp_irq_domain, 0);
> > +			if (virq > 0)
> > +				irq_dispose_mapping(virq);
> > +			irq_domain_remove(port->rp_irq_domain);
> > +		}
> >  
> >  		/* Free config space for emulated root bridge. */
> >  		pci_bridge_emul_cleanup(&port->bridge);
> > -- 
> > 2.20.1
> > 

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

* Re: [PATCH 2/4] PCI: mvebu: Implement support for interrupts on emulated bridge
  2022-09-29 14:05     ` Pali Rohár
@ 2022-09-30  7:39       ` Lorenzo Pieralisi
  0 siblings, 0 replies; 16+ messages in thread
From: Lorenzo Pieralisi @ 2022-09-30  7:39 UTC (permalink / raw)
  To: Pali Rohár
  Cc: Lorenzo Pieralisi, Krzysztof Wilczyński, Bjorn Helgaas,
	Rob Herring, Andrew Lunn, Sebastian Hesselbarth, Gregory Clement,
	Thomas Petazzoni, kabel, linux-pci, devicetree, linux-kernel,
	linux-arm-kernel

On Thu, Sep 29, 2022 at 04:05:10PM +0200, Pali Rohár wrote:
> Hello!
> 
> Gentle reminder for this patch. It is waiting there for more than month
> and other patches from this patch series were already reviewed and merged.
> Could you please look at it?
> 
> As stated in commit message this patch adds support for PCIe AER to
> pci-mvebu.c and as we know AER required for debugging any PCIe endpoint
> issues.

I thought this patch has a dependency on other patches that I can't
merge and therefore I postponed reviewing it:

https://lore.kernel.org/linux-pci/20220830123639.4zpvvvlrsaqs2rls@pali/

> On Tuesday 30 August 2022 14:36:39 Pali Rohár wrote:
> > On Thursday 18 August 2022 01:00:34 Pali Rohár wrote:
> > > This adds support for PME and ERR interrupts reported by emulated bridge
> > > (for PME and AER kernel drivers) via new Root Port irq chip as these
> > > interrupts from PCIe Root Ports are handled by mvebu hardware completely
> > > separately from INTx and MSI interrupts send by real PCIe devices.
> > > 
> > > With this change, kernel PME and AER drivers start working as they can
> > > acquire required interrupt lines (provided by mvebu rp virtual irq chip).
> > > 
> > > Note that for this support, device tree files has to be properly adjusted
> > > to provide "interrupts" or "interrupts-extended" property with error
> > > interrupt source and "interrupt-names" property with "error" string.
> > > 
> > > If device tree files do not provide these properties then driver would work
> > > as before and would not provide interrupts on emulated bridge, like before.
> > > 
> > > Signed-off-by: Pali Rohár <pali@kernel.org>
> > > ---
> > 
> > Just to note that because these error interrupts are shared on some
> > mvebu platforms, this patch depends on another patch which convert
> > driver to devm_request_irq() and which I sent more months before:
> > https://lore.kernel.org/linux-pci/20220524122817.7199-1-pali@kernel.org/
> > 
> > >  drivers/pci/controller/pci-mvebu.c | 256 ++++++++++++++++++++++++++---
> > >  1 file changed, 237 insertions(+), 19 deletions(-)
> > > 
> > > diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c
> > > index 54ce5d43b695..e69bdaa8de43 100644
> > > --- a/drivers/pci/controller/pci-mvebu.c
> > > +++ b/drivers/pci/controller/pci-mvebu.c
> > > @@ -56,8 +56,16 @@
> > >  #define PCIE_CONF_DATA_OFF	0x18fc
> > >  #define PCIE_INT_CAUSE_OFF	0x1900
> > >  #define PCIE_INT_UNMASK_OFF	0x1910
> > > +#define  PCIE_INT_DET_COR		BIT(8)
> > > +#define  PCIE_INT_DET_NONFATAL		BIT(9)
> > > +#define  PCIE_INT_DET_FATAL		BIT(10)
> > > +#define  PCIE_INT_ERR_FATAL		BIT(16)
> > > +#define  PCIE_INT_ERR_NONFATAL		BIT(17)
> > > +#define  PCIE_INT_ERR_COR		BIT(18)
> > >  #define  PCIE_INT_INTX(i)		BIT(24+i)
> > >  #define  PCIE_INT_PM_PME		BIT(28)
> > > +#define  PCIE_INT_DET_MASK		(PCIE_INT_DET_COR | PCIE_INT_DET_NONFATAL | PCIE_INT_DET_FATAL)
> > > +#define  PCIE_INT_ERR_MASK		(PCIE_INT_ERR_FATAL | PCIE_INT_ERR_NONFATAL | PCIE_INT_ERR_COR)
> > >  #define  PCIE_INT_ALL_MASK		GENMASK(31, 0)
> > >  #define PCIE_CTRL_OFF		0x1a00
> > >  #define  PCIE_CTRL_X1_MODE		0x0001
> > > @@ -120,9 +128,12 @@ struct mvebu_pcie_port {
> > >  	struct resource regs;
> > >  	u8 slot_power_limit_value;
> > >  	u8 slot_power_limit_scale;
> > > +	struct irq_domain *rp_irq_domain;
> > >  	struct irq_domain *intx_irq_domain;
> > >  	raw_spinlock_t irq_lock;
> > > +	int error_irq;
> > >  	int intx_irq;
> > > +	bool pme_pending;
> > >  };
> > >  
> > >  static inline void mvebu_writel(struct mvebu_pcie_port *port, u32 val, u32 reg)
> > > @@ -321,9 +332,19 @@ static void mvebu_pcie_setup_hw(struct mvebu_pcie_port *port)
> > >  	/* Clear all interrupt causes. */
> > >  	mvebu_writel(port, ~PCIE_INT_ALL_MASK, PCIE_INT_CAUSE_OFF);
> > >  
> > > -	/* Check if "intx" interrupt was specified in DT. */
> > > -	if (port->intx_irq > 0)
> > > -		return;
> > > +	/*
> > > +	 * Unmask all error interrupts which are internally generated.
> > > +	 * They cannot be disabled by SERR# Enable bit in PCI Command register,
> > > +	 * see Figure 6-3: Pseudo Logic Diagram for Error Message Controls in
> > > +	 * PCIe base specification.
> > > +	 * Internally generated mvebu interrupts are reported via mvebu summary
> > > +	 * interrupt which requires "error" interrupt to be specified in DT.
> > > +	 */
> > > +	if (port->error_irq > 0) {
> > > +		unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
> > > +		unmask |= PCIE_INT_DET_MASK;
> > > +		mvebu_writel(port, unmask, PCIE_INT_UNMASK_OFF);
> > > +	}
> > >  
> > >  	/*
> > >  	 * Fallback code when "intx" interrupt was not specified in DT:
> > > @@ -335,10 +356,12 @@ static void mvebu_pcie_setup_hw(struct mvebu_pcie_port *port)
> > >  	 * performance penalty as every PCIe interrupt handler needs to be
> > >  	 * called when some interrupt is triggered.
> > >  	 */
> > > -	unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
> > > -	unmask |= PCIE_INT_INTX(0) | PCIE_INT_INTX(1) |
> > > -		  PCIE_INT_INTX(2) | PCIE_INT_INTX(3);
> > > -	mvebu_writel(port, unmask, PCIE_INT_UNMASK_OFF);
> > > +	if (port->intx_irq <= 0) {
> > > +		unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
> > > +		unmask |= PCIE_INT_INTX(0) | PCIE_INT_INTX(1) |
> > > +			  PCIE_INT_INTX(2) | PCIE_INT_INTX(3);
> > > +		mvebu_writel(port, unmask, PCIE_INT_UNMASK_OFF);
> > > +	}
> > >  }
> > >  
> > >  static struct mvebu_pcie_port *mvebu_pcie_find_port(struct mvebu_pcie *pcie,
> > > @@ -603,11 +626,16 @@ mvebu_pci_bridge_emul_base_conf_read(struct pci_bridge_emul *bridge,
> > >  	case PCI_INTERRUPT_LINE: {
> > >  		/*
> > >  		 * From the whole 32bit register we support reading from HW only
> > > -		 * one bit: PCI_BRIDGE_CTL_BUS_RESET.
> > > +		 * two bits: PCI_BRIDGE_CTL_BUS_RESET and PCI_BRIDGE_CTL_SERR.
> > >  		 * Other bits are retrieved only from emulated config buffer.
> > >  		 */
> > >  		__le32 *cfgspace = (__le32 *)&bridge->conf;
> > >  		u32 val = le32_to_cpu(cfgspace[PCI_INTERRUPT_LINE / 4]);
> > > +		if ((mvebu_readl(port, PCIE_INT_UNMASK_OFF) &
> > > +		      PCIE_INT_ERR_MASK) == PCIE_INT_ERR_MASK)
> > > +			val |= PCI_BRIDGE_CTL_SERR << 16;
> > > +		else
> > > +			val &= ~(PCI_BRIDGE_CTL_SERR << 16);
> > >  		if (mvebu_readl(port, PCIE_CTRL_OFF) & PCIE_CTRL_MASTER_HOT_RESET)
> > >  			val |= PCI_BRIDGE_CTL_BUS_RESET << 16;
> > >  		else
> > > @@ -675,6 +703,11 @@ mvebu_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge,
> > >  		break;
> > >  	}
> > >  
> > > +	case PCI_EXP_RTCTL:
> > > +		*value = (mvebu_readl(port, PCIE_INT_UNMASK_OFF) &
> > > +			  PCIE_INT_PM_PME) ? PCI_EXP_RTCTL_PMEIE : 0;
> > > +		break;
> > > +
> > >  	case PCI_EXP_RTSTA:
> > >  		*value = mvebu_readl(port, PCIE_RC_RTSTA);
> > >  		break;
> > > @@ -780,6 +813,14 @@ mvebu_pci_bridge_emul_base_conf_write(struct pci_bridge_emul *bridge,
> > >  		break;
> > >  
> > >  	case PCI_INTERRUPT_LINE:
> > > +		if ((mask & (PCI_BRIDGE_CTL_SERR << 16)) && port->error_irq > 0) {
> > > +			u32 unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
> > > +			if (new & (PCI_BRIDGE_CTL_SERR << 16))
> > > +				unmask |= PCIE_INT_ERR_MASK;
> > > +			else
> > > +				unmask &= ~PCIE_INT_ERR_MASK;
> > > +			mvebu_writel(port, unmask, PCIE_INT_UNMASK_OFF);
> > > +		}
> > >  		if (mask & (PCI_BRIDGE_CTL_BUS_RESET << 16)) {
> > >  			u32 ctrl = mvebu_readl(port, PCIE_CTRL_OFF);
> > >  			if (new & (PCI_BRIDGE_CTL_BUS_RESET << 16))
> > > @@ -838,10 +879,25 @@ mvebu_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge,
> > >  		 * PME Status bit in Root Status Register (PCIE_RC_RTSTA)
> > >  		 * is read-only and can be cleared only by writing 0b to the
> > >  		 * Interrupt Cause RW0C register (PCIE_INT_CAUSE_OFF). So
> > > -		 * clear PME via Interrupt Cause.
> > > +		 * clear PME via Interrupt Cause and also set port->pme_pending
> > > +		 * variable to false value to start processing PME interrupts
> > > +		 * in interrupt handler again.
> > >  		 */
> > > -		if (new & PCI_EXP_RTSTA_PME)
> > > +		if (new & PCI_EXP_RTSTA_PME) {
> > >  			mvebu_writel(port, ~PCIE_INT_PM_PME, PCIE_INT_CAUSE_OFF);
> > > +			port->pme_pending = false;
> > > +		}
> > > +		break;
> > > +
> > > +	case PCI_EXP_RTCTL:
> > > +		if ((mask & PCI_EXP_RTCTL_PMEIE) && port->error_irq > 0) {
> > > +			u32 unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
> > > +			if (new & PCI_EXP_RTCTL_PMEIE)
> > > +				unmask |= PCIE_INT_PM_PME;
> > > +			else
> > > +				unmask &= ~PCIE_INT_PM_PME;
> > > +			mvebu_writel(port, unmask, PCIE_INT_UNMASK_OFF);
> > > +		}
> > >  		break;
> > >  
> > >  	case PCI_EXP_DEVCTL2:
> > > @@ -924,6 +980,14 @@ static int mvebu_pci_bridge_emul_init(struct mvebu_pcie_port *port)
> > >  		bridge_flags |= PCI_BRIDGE_EMUL_NO_IO_FORWARD;
> > >  	}
> > >  
> > > +	/*
> > > +	 * Interrupts on emulated bridge are supported only when "error"
> > > +	 * interrupt was specified in DT. Without it emulated bridge cannot
> > > +	 * emulate interrupts.
> > > +	 */
> > > +	if (port->error_irq > 0)
> > > +		bridge->conf.intpin = PCI_INTERRUPT_INTA;
> > > +
> > >  	/*
> > >  	 * Older mvebu hardware provides PCIe Capability structure only in
> > >  	 * version 1. New hardware provides it in version 2.
> > > @@ -1072,6 +1136,26 @@ static const struct irq_domain_ops mvebu_pcie_intx_irq_domain_ops = {
> > >  	.xlate = irq_domain_xlate_onecell,
> > >  };
> > >  
> > > +static struct irq_chip rp_irq_chip = {
> > > +	.name = "mvebu-rp",
> > > +};
> > > +
> > > +static int mvebu_pcie_rp_irq_map(struct irq_domain *h,
> > > +				   unsigned int virq, irq_hw_number_t hwirq)
> > > +{
> > > +	struct mvebu_pcie_port *port = h->host_data;
> > > +
> > > +	irq_set_chip_and_handler(virq, &rp_irq_chip, handle_simple_irq);
> > > +	irq_set_chip_data(virq, port);
> > > +
> > > +	return 0;
> > > +}
> > > +
> > > +static const struct irq_domain_ops mvebu_pcie_rp_irq_domain_ops = {
> > > +	.map = mvebu_pcie_rp_irq_map,
> > > +	.xlate = irq_domain_xlate_onecell,
> > > +};
> > > +
> > >  static int mvebu_pcie_init_irq_domain(struct mvebu_pcie_port *port)
> > >  {
> > >  	struct device *dev = &port->pcie->pdev->dev;
> > > @@ -1094,10 +1178,72 @@ static int mvebu_pcie_init_irq_domain(struct mvebu_pcie_port *port)
> > >  		return -ENOMEM;
> > >  	}
> > >  
> > > +	/*
> > > +	 * When "error" interrupt was not specified in DT then there is no
> > > +	 * support for interrupts on emulated root bridge. So skip following
> > > +	 * initialization.
> > > +	 */
> > > +	if (port->error_irq <= 0)
> > > +		return 0;
> > > +
> > > +	port->rp_irq_domain = irq_domain_add_linear(NULL, 1,
> > > +						      &mvebu_pcie_rp_irq_domain_ops,
> > > +						      port);
> > > +	if (!port->rp_irq_domain) {
> > > +		irq_domain_remove(port->intx_irq_domain);
> > > +		dev_err(dev, "Failed to add Root Port IRQ domain for %s\n", port->name);
> > > +		return -ENOMEM;
> > > +	}
> > > +
> > >  	return 0;
> > >  }
> > >  
> > > -static irqreturn_t mvebu_pcie_irq_handler(int irq, void *arg)
> > > +static irqreturn_t mvebu_pcie_error_irq_handler(int irq, void *arg)
> > > +{
> > > +	struct mvebu_pcie_port *port = arg;
> > > +	struct device *dev = &port->pcie->pdev->dev;
> > > +	u32 cause, unmask, status;
> > > +
> > > +	cause = mvebu_readl(port, PCIE_INT_CAUSE_OFF);
> > > +	unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
> > > +	status = cause & unmask;
> > > +
> > > +	/* "error" interrupt handler does not process INTX interrupts */
> > > +	status &= ~(PCIE_INT_INTX(0) | PCIE_INT_INTX(1) |
> > > +		    PCIE_INT_INTX(2) | PCIE_INT_INTX(3));
> > > +
> > > +	/* Process PME interrupt */
> > > +	if ((status & PCIE_INT_PM_PME) && !port->pme_pending) {
> > > +		/*
> > > +		 * Do not clear PME interrupt bit in Cause Register as it
> > > +		 * invalidates also content of Root Status Register. Instead
> > > +		 * set port->pme_pending variable to true to indicate that
> > > +		 * next time PME interrupt should be ignored until variable
> > > +		 * is back to the false value.
> > > +		 */
> > > +		port->pme_pending = true;
> > > +		if (generic_handle_domain_irq(port->rp_irq_domain, 0) == -EINVAL)
> > > +			dev_err_ratelimited(dev, "unhandled PME IRQ\n");
> > > +	}
> > > +
> > > +	/* Process ERR interrupt */
> > > +	if (status & PCIE_INT_ERR_MASK) {
> > > +		mvebu_writel(port, ~PCIE_INT_ERR_MASK, PCIE_INT_CAUSE_OFF);
> > > +		if (generic_handle_domain_irq(port->rp_irq_domain, 0) == -EINVAL)
> > > +			dev_err_ratelimited(dev, "unhandled ERR IRQ\n");
> > > +	}
> > > +
> > > +	/* Process local ERR interrupt */
> > > +	if (status & PCIE_INT_DET_MASK) {
> > > +		mvebu_writel(port, ~PCIE_INT_DET_MASK, PCIE_INT_CAUSE_OFF);
> > > +		if (generic_handle_domain_irq(port->rp_irq_domain, 0) == -EINVAL)
> > > +			dev_err_ratelimited(dev, "unhandled ERR IRQ\n");
> > > +	}
> > > +
> > > +	return status ? IRQ_HANDLED : IRQ_NONE;
> > > +}
> > > +
> > > +static irqreturn_t mvebu_pcie_intx_irq_handler(int irq, void *arg)
> > >  {
> > >  	struct mvebu_pcie_port *port = arg;
> > >  	struct device *dev = &port->pcie->pdev->dev;
> > > @@ -1108,6 +1254,10 @@ static irqreturn_t mvebu_pcie_irq_handler(int irq, void *arg)
> > >  	unmask = mvebu_readl(port, PCIE_INT_UNMASK_OFF);
> > >  	status = cause & unmask;
> > >  
> > > +	/* "intx" interrupt handler process only INTX interrupts */
> > > +	status &= PCIE_INT_INTX(0) | PCIE_INT_INTX(1) |
> > > +		  PCIE_INT_INTX(2) | PCIE_INT_INTX(3);
> > > +
> > >  	/* Process legacy INTx interrupts */
> > >  	for (i = 0; i < PCI_NUM_INTX; i++) {
> > >  		if (!(status & PCIE_INT_INTX(i)))
> > > @@ -1122,9 +1272,29 @@ static irqreturn_t mvebu_pcie_irq_handler(int irq, void *arg)
> > >  
> > >  static int mvebu_pcie_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
> > >  {
> > > -	/* Interrupt support on mvebu emulated bridges is not implemented yet */
> > > -	if (dev->bus->number == 0)
> > > -		return 0; /* Proper return code 0 == NO_IRQ */
> > > +	struct mvebu_pcie_port *port;
> > > +	struct mvebu_pcie *pcie;
> > > +
> > > +	if (dev->bus->number == 0) {
> > > +		/*
> > > +		 * Each emulated root bridge for every mvebu port has its own
> > > +		 * Root Port irq chip and irq domain. Argument pin is the INTx
> > > +		 * pin (1=INTA, 2=INTB, 3=INTC, 4=INTD) and hwirq for function
> > > +		 * irq_create_mapping() is indexed from zero.
> > > +		 */
> > > +		pcie = dev->bus->sysdata;
> > > +		port = mvebu_pcie_find_port(pcie, dev->bus, PCI_DEVFN(slot, 0));
> > > +		if (!port)
> > > +			return 0; /* Proper return code 0 == NO_IRQ */
> > > +		/*
> > > +		 * port->rp_irq_domain is available only when "error" interrupt
> > > +		 * was specified in DT. When is not available then interrupts
> > > +		 * for emulated root bridge are not provided.
> > > +		 */
> > > +		if (port->error_irq <= 0)
> > > +			return 0; /* Proper return code 0 == NO_IRQ */
> > > +		return irq_create_mapping(port->rp_irq_domain, pin - 1);
> > > +	}
> > >  
> > >  	return of_irq_parse_and_map_pci(dev, slot, pin);
> > >  }
> > > @@ -1333,6 +1503,21 @@ static int mvebu_pcie_parse_port(struct mvebu_pcie *pcie,
> > >  			 port->name, child);
> > >  	}
> > >  
> > > +	/*
> > > +	 * Old DT bindings do not contain "error" interrupt
> > > +	 * so do not fail probing driver when interrupt does not exist.
> > > +	 */
> > > +	port->error_irq = of_irq_get_byname(child, "error");
> > > +	if (port->error_irq == -EPROBE_DEFER) {
> > > +		ret = port->error_irq;
> > > +		goto err;
> > > +	}
> > > +	if (port->error_irq <= 0) {
> > > +		dev_warn(dev, "%s: interrupts on Root Port are unsupported, "
> > > +			      "%pOF does not contain error interrupt\n",
> > > +			 port->name, child);
> > > +	}
> > > +
> > >  	reset_gpio = of_get_named_gpio_flags(child, "reset-gpios", 0, &flags);
> > >  	if (reset_gpio == -EPROBE_DEFER) {
> > >  		ret = reset_gpio;
> > > @@ -1538,7 +1723,6 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
> > >  
> > >  	for (i = 0; i < pcie->nports; i++) {
> > >  		struct mvebu_pcie_port *port = &pcie->ports[i];
> > > -		int irq = port->intx_irq;
> > >  
> > >  		child = port->dn;
> > >  		if (!child)
> > > @@ -1566,7 +1750,7 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
> > >  			continue;
> > >  		}
> > >  
> > > -		if (irq > 0) {
> > > +		if (port->error_irq > 0 || port->intx_irq > 0) {
> > >  			ret = mvebu_pcie_init_irq_domain(port);
> > >  			if (ret) {
> > >  				dev_err(dev, "%s: cannot init irq domain\n",
> > > @@ -1577,14 +1761,42 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
> > >  				mvebu_pcie_powerdown(port);
> > >  				continue;
> > >  			}
> > > +		}
> > > +
> > > +		if (port->error_irq > 0) {
> > > +			ret = devm_request_irq(dev, port->error_irq,
> > > +					       mvebu_pcie_error_irq_handler,
> > > +					       IRQF_SHARED | IRQF_NO_THREAD,
> > > +					       port->name, port);
> > > +			if (ret) {
> > > +				dev_err(dev, "%s: cannot register error interrupt handler: %d\n",
> > > +					port->name, ret);
> > > +				if (port->intx_irq_domain)
> > > +					irq_domain_remove(port->intx_irq_domain);
> > > +				if (port->rp_irq_domain)
> > > +					irq_domain_remove(port->rp_irq_domain);
> > > +				pci_bridge_emul_cleanup(&port->bridge);
> > > +				devm_iounmap(dev, port->base);
> > > +				port->base = NULL;
> > > +				mvebu_pcie_powerdown(port);
> > > +				continue;
> > > +			}
> > > +		}
> > >  
> > > -			ret = devm_request_irq(dev, irq, mvebu_pcie_irq_handler,
> > > +		if (port->intx_irq > 0) {
> > > +			ret = devm_request_irq(dev, port->intx_irq,
> > > +					       mvebu_pcie_intx_irq_handler,
> > >  					       IRQF_SHARED | IRQF_NO_THREAD,
> > >  					       port->name, port);
> > >  			if (ret) {
> > > -				dev_err(dev, "%s: cannot register interrupt handler: %d\n",
> > > +				dev_err(dev, "%s: cannot register intx interrupt handler: %d\n",
> > >  					port->name, ret);
> > > -				irq_domain_remove(port->intx_irq_domain);
> > > +				if (port->error_irq > 0)
> > > +					devm_free_irq(dev, port->error_irq, port);
> > > +				if (port->intx_irq_domain)
> > > +					irq_domain_remove(port->intx_irq_domain);
> > > +				if (port->rp_irq_domain)
> > > +					irq_domain_remove(port->rp_irq_domain);
> > >  				pci_bridge_emul_cleanup(&port->bridge);
> > >  				devm_iounmap(dev, port->base);
> > >  				port->base = NULL;
> > > @@ -1722,6 +1934,12 @@ static int mvebu_pcie_remove(struct platform_device *pdev)
> > >  			}
> > >  			irq_domain_remove(port->intx_irq_domain);
> > >  		}
> > > +		if (port->rp_irq_domain) {
> > > +			int virq = irq_find_mapping(port->rp_irq_domain, 0);
> > > +			if (virq > 0)
> > > +				irq_dispose_mapping(virq);
> > > +			irq_domain_remove(port->rp_irq_domain);
> > > +		}
> > >  
> > >  		/* Free config space for emulated root bridge. */
> > >  		pci_bridge_emul_cleanup(&port->bridge);
> > > -- 
> > > 2.20.1
> > > 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2022-09-30  7:40 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-17 23:00 [PATCH 0/4] PCI: mvebu: Add support for error interrupt Pali Rohár
2022-08-17 23:00 ` [PATCH 1/4] dt-bindings: PCI: mvebu: Update information about " Pali Rohár
2022-08-18 16:32   ` Rob Herring
2022-08-18 19:34   ` Andrew Lunn
2022-08-17 23:00 ` [PATCH 2/4] PCI: mvebu: Implement support for interrupts on emulated bridge Pali Rohár
2022-08-18 19:51   ` Andrew Lunn
2022-08-18 20:07     ` Pali Rohár
2022-08-18 20:27       ` Andrew Lunn
2022-08-30 12:36   ` Pali Rohár
2022-09-29 14:05     ` Pali Rohár
2022-09-30  7:39       ` Lorenzo Pieralisi
2022-08-17 23:00 ` [PATCH 3/4] ARM: dts: kirkwood: Add definitions for PCIe error interrupts Pali Rohár
2022-08-18 19:51   ` Andrew Lunn
2022-08-17 23:00 ` [PATCH 4/4] ARM: dts: dove: " Pali Rohár
2022-08-18 19:52   ` Andrew Lunn
2022-09-02 14:54 ` [PATCH 0/4] PCI: mvebu: Add support for error interrupt Gregory CLEMENT

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).