Skip to contentSkip to conversation

irqchip: add EyeQ5 PCIe MSI controller

PATCH Superseded Gregory CLEMENT 2 participants 7 messages Nov 25 – Dec 1

Subsystems (4)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Gregory CLEMENT

author maintainer
#0 lore raw

v5 cover irqchip: add EyeQ5 PCIe MSI controller

Hello,

This series adds support for the MSI controller present in the Mobileye EyeQ5 PCIe ports.

Although the driver uses the standard MSI library, the EyeQ5 hardware has several specific features. First, each PCIe port has its own MSI controller, which snoops the MSI write TLPs that the port receives. A port supports a maximum of 4 MSI vectors, and the memory-region property gives the base address of the doorbell window. In addition, the GCSR mode selects the role: in root complex mode the driver registers a PCI MSI parent, while in endpoint mode it registers a platform MSI parent. The last specific point is that the driver uses the snooper domain as a chained controller on one GIC interrupt.

The series adds the binding document, the irqchip driver, the EyeQ5 DTS changes, and the MAINTAINERS entry. In particular, the DTS changes add the two MSI controllers to the EyeQ5 SoC.

I tested the series on two EyeQ5 SoCs that have a PCIe link. One SoC acted as the host and the other SoC acted as the endpoint. The pci_endpoint_test kselftest passed the MSI-X and DOORBELL_TEST cases. The MSI test uses one vector because the controller does not support standard Multi-MSI. An additional test made sure that each MSI-X vector uses its target CPU (using affinity).

This fifth series fixes the issues pointed out by Sashiko. I also ran a Sashiko-like tool, which pointed out three more potential issues that I fixed too. I hope that with this extra step, there are no more corner cases to fix.

As a side note, I am still a little annoyed by having to add an empty function as an irq_ack callback. I saw that a few other drivers do the same. Could we do better?
First, I was thinking of adding a flag so that in handle_edge_irq() we would not try to use the callback if the flag is set. The drawback is adding an extra test; I do not know if it is really sensible here. At least we could provide this empty function in kernel/irq/chip.c, so each driver could use it instead of declaring its own empty function. These are just suggestions and they do not affect the current series.

Grégory

---
Changes in v5:
- irqchip: fix the MSI loss. Mask the vector on disable_irq() with IRQ_DISABLE_UNLAZY so the MSI stays pending in GCSR_IRQSTATUS until enable_irq(). (sashiko)
- irqchip: filter GCSR_IRQSTATUS with GCSR_IRQMASK in eyeq_msi_isr()
so a masked vector is not dispatched when a sibling fires. (sashiko)
- irqchip: clear GCSR_IRQSTATUS on vector alloc and free, so a reused vector does not deliver a stale MSI to its new owner.
- irqchip: program the hardware before creating the IRQ domain, so no vector can be allocated before the hardware is ready.
- irqchip: bound the ISR loop, so a device that keeps setting a vector cannot hang a CPU.
- Link to v4: https://patch.msgid.link/[email protected]

Changes in v4:
- irqchip: use a plain raw_spinlock() in the mask/unmask callbacks, which run with interrupts disabled.
- irqchip: use guard_chained_irq() to balance the chained handler on every return path.
- irqchip: simplify the domain alloc/free callbacks now that nr_irqs is always 1.
- irqchip: reformat the MSI flag macros and use a distinct "EYEQ-P-" prefix for the platform MSI parent.
- MIPS: move the EYEQ5_MSI selection into a separate MIPS patch, out of the irqchip driver patch.
- Link to v3: https://patch.msgid.link/[email protected]

Changes in v3:
- Address review comments from sashiko.
- dt-bindings: drop the interrupt-controller, #interrupt-cells and label properties.
- irqchip: use handle_edge_irq() with an ack callback instead of handle_simple_irq(), so a vector is masked while disabled and a second MSI is not lost while the first is in progress. For this one, I ran some tests to confirm that the issue was real (it was) and that the fix resolves it.
- irqchip: convert to a platform driver because the node is no longer an interrupt controller and is no longer probed by of_irq_init().
- irqchip: stop parsing the label property and use the node full name in the boot message.
- MIPS: dts: update the MSI nodes according to the binding changes.
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Address review comments from Krzysztof Kozlowski, Thomas Gleixner and sashiko.
- dt-bindings: drop the num-vectors property (all ports have four vectors) and simplify the example.
- irqchip: use the fixed four-vector count, add lockdep assertions, and dispatch through generic_handle_demux_domain_irq() with a redirect-based irq_set_affinity() callback.
- irqchip: drop MSI_FLAG_MULTI_PCI_MSI (standard Multi-MSI cannot work with the address-based vector decoding) and MSI_FLAG_NO_AFFINITY; add MSI_FLAG_PCI_MSI_MASK_PARENT.
- irqchip: keep vectors masked during allocation, mask all vectors and clear pending status before installing the chained handler, and reject of_irq_get() returning 0.
- MIPS: dts: drop the num-vectors property from both MSI nodes.
- Reformat the driver for the 100-column limit.
- Link to v1: https://patch.msgid.link/[email protected]

To: Vladimir Kondratiev <[email protected]>
To: Benoît Monin <[email protected]>
To: Gregory CLEMENT <[email protected]>
To: Théo Lebrun <[email protected]>
To: Thomas Gleixner <[email protected]>
To: Radu Rendec <[email protected]>
To: Rob Herring <[email protected]>
To: Krzysztof Kozlowski <[email protected]>
To: Conor Dooley <[email protected]>
To: Thomas Bogendoerfer <[email protected]>
Cc: Thomas Petazzoni <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
Gregory CLEMENT (5):
dt-bindings: interrupt-controller: add Mobileye EyeQ5 PCIe MSI controller
irqchip: irq-eyeq5-msi: add EyeQ5 PCIe MSI controller driver
MIPS: eyeq: select the EyeQ5 MSI controller
MIPS: dts: eyeq5: add MSI controllers
MAINTAINERS: add EyeQ5 MSI controller entry

 .../interrupt-controller/mobileye,eyeq5-msi.yaml   |  76 ++++
 MAINTAINERS                                        |   2 +
 arch/mips/Kconfig                                  |   1 +
 arch/mips/boot/dts/mobileye/eyeq5.dtsi             |  22 +
 drivers/irqchip/Kconfig                            |   5 +
 drivers/irqchip/Makefile                           |   1 +
 drivers/irqchip/irq-eyeq5-msi.c                    | 475 +++++++++++++++++++++
 7 files changed, 582 insertions(+)

---
base-commit: 08b814ca0a6945b8effc1a0d64999d562f24c923
change-id: 20261028-eyeq5_msi-86aa1d590684

Best regards,

Signature · 3 lines
Grégory CLEMENT, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
author maintainer
#1 lore raw

PATCH v5 1/5 dt-bindings: interrupt-controller: add Mobileye EyeQ5 PCIe MSI controller

Add binding for the Mobileye EyeQ5 PCIe MSI controller.

---
 .../interrupt-controller/mobileye,eyeq5-msi.yaml   | 76 ++++++++++++++++++++++
 1 file changed, 76 insertions(+)
Documentation/devicetree/bindings/interrupt-controller/mobileye,eyeq5-msi.yaml new file +76 -0
new file mode 100644
index 0000000000000..e41a92aec3b8e
@@ -0,0 +1,76 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/interrupt-controller/mobileye,eyeq5-msi.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Mobileye EyeQ5 PCIe MSI controller
+
+maintainers:
+  - Gregory CLEMENT <[email protected]>
+
+description: |
+  The Mobileye EyeQ5 PCIe MSI controller snoops the MSI write TLPs of a
+  PCIe port. The controller signals the parent interrupt controller when a
+  vector is pending. The memory-region property gives the base address of
+  the doorbell window. A port supports a maximum of 4 MSI vectors.
+
+  This node is an MSI parent for the PCIe port. The driver chains the
+  controller interrupt to the parent interrupt controller.
+
+allOf:
+  - $ref: /schemas/interrupt-controller/msi-controller.yaml#
+
+properties:
+  compatible:
+    const: mobileye,eyeq5-msi
+
+  reg:
+    items:
+      - description: GCSR block of the PCIe port
+      - description: MSI vector control block
+
+  interrupts:
+    maxItems: 1
+
+  msi-controller: true
+
+  '#msi-cells':
+    const: 0
+
+  memory-region:
+    maxItems: 1
+    description:
+      Reserved-memory region. The hardware uses its base address as the MSI
+      doorbell window.
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - msi-controller
+  - '#msi-cells'
+  - memory-region
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/mips-gic.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    soc {
+        #address-cells = <2>;
+        #size-cells = <2>;
+
+        msi-controller@5840000 {
+            compatible = "mobileye,eyeq5-msi";
+            reg = <0x0 0x05840000 0x0 0x10>,
+                  <0x0 0x05840040 0x0 0x20>;
+            interrupt-parent = <&gic>;
+            interrupts = <GIC_SHARED 7 IRQ_TYPE_LEVEL_HIGH>;
+            msi-controller;
+            #msi-cells = <0>;
+            memory-region = <&pci0_msi_reserved>;
+        };
+    };
Signature · 1 line
2.53.0
author maintainer
#2 lore raw

PATCH v5 2/5 irqchip: irq-eyeq5-msi: add EyeQ5 PCIe MSI controller driver

In reply to Gregory CLEMENT

Each EyeQ5 PCIe port has its own MSI controller. The controller snoops the MSI write TLPs that the port receives. It raises an interrupt when a write targets the doorbell window. A port supports a maximum of 4 MSI vectors.

The driver supports two roles, selected by the GCSR mode. In root complex mode, it registers a PCI MSI parent. In endpoint mode, it registers a platform MSI parent. The driver chains the snooper domain to one GIC interrupt.

---
 drivers/irqchip/Kconfig         |   5 +
 drivers/irqchip/Makefile        |   1 +
 drivers/irqchip/irq-eyeq5-msi.c | 475 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 481 insertions(+)
drivers/irqchip/Kconfig +5 -0
index 90daedb7554ae..5d5a2e31d5eab 100644
@@ -827,6 +827,11 @@ config APPLE_AIC
 	  Support for the Apple Interrupt Controller found on Apple Silicon SoCs,
 	  such as the M1.
 
+config EYEQ5_MSI
+	bool
+	select IRQ_DOMAIN
+	select IRQ_MSI_LIB
+
 config MCHP_EIC
 	bool "Microchip External Interrupt Controller"
 	depends on ARCH_AT91 || COMPILE_TEST
drivers/irqchip/Makefile +1 -0
index eb539d41251e2..4b96194e70b72 100644
@@ -132,6 +132,7 @@ obj-$(CONFIG_MACH_REALTEK_RTL)		+= irq-realtek-rtl.o
 obj-$(CONFIG_WPCM450_AIC)		+= irq-wpcm450-aic.o
 obj-$(CONFIG_IRQ_IDT3243X)		+= irq-idt3243x.o
 obj-$(CONFIG_APPLE_AIC)			+= irq-apple-aic.o
+obj-$(CONFIG_EYEQ5_MSI)			+= irq-eyeq5-msi.o
 obj-$(CONFIG_MCHP_EIC)			+= irq-mchp-eic.o
 obj-$(CONFIG_SOPHGO_SG2042_MSI)		+= irq-sg2042-msi.o
 obj-$(CONFIG_SUNPLUS_SP7021_INTC)	+= irq-sp7021-intc.o
drivers/irqchip/irq-eyeq5-msi.c new file +475 -0

475 lines not on this page · raw message

Signature · 1 line
2.53.0
maintainer
#3 lore raw

Re: [PATCH v5 2/5] irqchip: irq-eyeq5-msi: add EyeQ5 PCIe MSI controller driver

Quoted 17 lines · Gregory CLEMENT
drivers/irqchip/irq-eyeq5-msi.c new file +17 -0
+/*
+ * The pending bit is write-one-to-cleared in eyeq_msi_isr() before the
+ * vector is dispatched, so there is nothing left to acknowledge here.
+ * handle_edge_irq() nevertheless requires an ack callback.
+ */
+static void eyeq_msi_ack_irq(struct irq_data *data) { }
+
+static struct irq_chip eyeq_msi_irq_chip = {
+	.name			= "EyeQ5-MSI",
+	.irq_mask		= eyeq_msi_mask_irq,
+	.irq_unmask		= eyeq_msi_unmask_irq,
+	.irq_ack		= eyeq_msi_ack_irq,
+	.irq_compose_msi_msg	= eyeq_msi_compose_msg,
+#ifdef CONFIG_SMP
+	.irq_set_affinity	= irq_chip_redirect_set_affinity,
+#endif
+};

drivers/irqchip/irq-eyeq5-msi.c line 163

Quoted 10 lines
drivers/irqchip/irq-eyeq5-msi.c new file +10 -0
+
+static void eyeq_msi_isr(struct irq_desc *desc)
+{
+	struct irq_chip *parent_chip = irq_desc_get_chip(desc);
+	struct eyeq_msi *msi = irq_desc_get_handler_data(desc);
+	void __iomem *status_reg;
+	unsigned long pending;
+	unsigned long mask;
+	unsigned int bit;
+	unsigned int i;

Please put same types into one line and bring the variable declarations into the scope in which they are used.

+

drivers/irqchip/irq-eyeq5-msi.c line 169

Quoted 5 lines
drivers/irqchip/irq-eyeq5-msi.c new file +5 -0
+	guard_chained_irq(parent_chip, desc);
+
+	status_reg = msi->gcsr_base + GCSR_IRQSTATUS;
+
+	for (i = 0; i < EYEQ_MSI_MAX_DRAIN; i++) {
        for (int i ...) {

drivers/irqchip/irq-eyeq5-msi.c line 170

Quoted 1 line
drivers/irqchip/irq-eyeq5-msi.c new file +1 -0
+		pending = FIELD_GET(GCSR_IRQSTATUS_MASK, readw(status_reg));

unsigned long mask, pending = ....

drivers/irqchip/irq-eyeq5-msi.c line 181

Quoted 11 lines
drivers/irqchip/irq-eyeq5-msi.c new file +11 -0
+		if (!pending)
+			break;
+
+		/*
+		 * Masked vectors must stay pending in GCSR_IRQSTATUS: unmasking
+		 * them must re-assert the top-level IRQ. Only dispatch and ack
+		 * the bits that are currently unmasked.
+		 */
+		mask = FIELD_GET(GCSR_IRQMASK_MASK,
+				 readw(msi->gcsr_base + GCSR_IRQMASK));
+		pending &= mask;

That's wishful thinking....

drivers/irqchip/irq-eyeq5-msi.c line 193

Quoted 12 lines
drivers/irqchip/irq-eyeq5-msi.c new file +12 -0
+		if (!pending)
+			break;
+
+		/*
+		 * Write-one-to-clear status register.
+		 */
+		writew(FIELD_PREP(GCSR_IRQSTATUS_MASK, pending), status_reg);
+
+		for_each_set_bit(bit, &pending, EYEQ_MSI_MAX_VECTORS) {
+			if (!generic_handle_demux_domain_irq(msi->msi_domain, bit))
+				pr_err_ratelimited("unmapped MSI interrupt %u\n", bit);
+		}

... because:

disable_irq()
__disable_irq_nosync()

        guard(irqdesc)
        irq_disable(desc, @mask = irq_settings_disable_unlazy(desc))
	   if (irqd_irq_disabled(irqd)) {
                // Not taken
                ...
                return;
           }
A:         irq_state_set_disabled();
           if (chip->irq_disable)

B: chip->irq_disable();
if (mask)
C: mask();

   synchronize_irq();

So with DISABLE_UNLAZY not set and no irq_disable() callback in the chip disable_irq() will only set the state to disabled.

So if the demultiplex interrupt is raised after #A and handled (same or other CPU) then the readout of the mask register will have the interrupt unmasked, so it's acknowledged and the handler invoked.

The handler observes disabled state, masks the interrupt, marks it PENDING and returns w/o invoking the device interrupt handler. Interrupt is lost. This is guaranteed to happen and if so it will be really hard to diagnose.

Even if you set DISABLE_UNLAZY or add an irq_disable() callback this won't work because the demultiplex interrupt on a different CPU will still be able to observe the unmasked state in the mask register between #A and #B/ #C. The edge handler will behave exactly the same way as described above and the interrupt is lost. Just the race window becomes smaller and therefore even harder to debug.

The problem is that the demultiplex handler and the device interrupt management are not synchronized in any way and you can't do anything about that.

So either you enable software resend or you do the following:

1) Implement the irq_pre_redirect() callback in the chip

   if (!irqd_irq_disabled(irqd) || irqd_irq_masked(irqd))
   	return;

   guard(raw_spinlock)(&msi->lock);
   // Mask in hardware
   mask(THIS_BIT);
   // Ensure the state is correct otherwise irq_enable() -> unmask()
   // will not work...
   irqd_set_masked(irqd);

This ensures that on redirect to a different CPU the interrupt is masked and does not resurface in the demultiplexer. It will still be handled, but the edge handler will leave when it still observes disabled state.

2) Implement a proper ACK callback in the eyeq_msi_irq_chip which takes the state into account:

if (irqd_irq_disabled(irqd))
return;

   guard(raw_spinlock)(&msi->lock);
   ack(THIS_BIT);

This prevents the ACK to be issued when the interrupt is disabled.

#1 and #2 are properly serialized with the interrupt descriptor lock against a concurrent irq_disable().

3) Remove the bulk acknowledge from the chained handler and do

	if (!generic_handle_demux_domain_irq(...)) {
		guard(raw_spinlock)(&msi->lock);
		__eyeq_msi_mask_irq(msi, bit);
                __eyeq_msi_ack_irq(msi, bit);
        }

to silence spurious unmapped interrupts.

That still leaves you with the MASK register readout racing against a concurrent write, but that's not an issue because that just results in one pointless edge handler invocation.

You also can spare the hardware read and cache the mask register content in struct eyeq_msi in mask() and unmask(). You don't have to take msi->lock in the demux handler because that'd be just a cosmetic exercise w/o any actual serialization value. So you can do the writes in mask/unmask() under the lock with WRITE_ONCE() and use READ_ONCE() in the demux handler. I would do that anyway because that avoids the read in mask/unmask() too.

Thanks,

tglx

author maintainer
#4 lore raw

PATCH v5 3/5 MIPS: eyeq: select the EyeQ5 MSI controller

In reply to Gregory CLEMENT

The MSI controller is part of the EyeQ SoC. This change selects it by default.

---
 arch/mips/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/mips/Kconfig +1 -0
index ed17c9b1624ca..19dbf24684b23 100644
@@ -632,6 +632,7 @@ config EYEQ
 	select CPU_MIPSR2_IRQ_VI
 	select CSRC_R4K
 	select DMA_NONCOHERENT
+	select EYEQ5_MSI
 	select HAVE_PCI
 	select IRQ_MIPS_CPU
 	select MIPS_AUTO_PFN_OFFSET
Signature · 1 line
2.53.0
author maintainer
#5 lore raw

PATCH v5 4/5 MIPS: dts: eyeq5: add MSI controllers

In reply to Gregory CLEMENT

Add the two EyeQ5 MSI controllers. They use reserved-memory regions as their doorbell windows.

---
 arch/mips/boot/dts/mobileye/eyeq5.dtsi | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
arch/mips/boot/dts/mobileye/eyeq5.dtsi +22 -0
index cec5ad8752285..ab63a90ed3e92 100644
@@ -309,6 +309,28 @@ gpio1: gpio@1500000 {
 			resets = <&olb 0 26>;
 		};
 
+		msi0: msi-controller@5840000 {
+			compatible = "mobileye,eyeq5-msi";
+			reg = <0x0 0x05840000 0x0 0x10>,
+			      <0x0 0x05840040 0x0 0x20>;
+			interrupt-parent = <&gic>;
+			msi-controller;
+			#msi-cells = <0>;
+			interrupts = <GIC_SHARED 7 IRQ_TYPE_LEVEL_HIGH>;
+			memory-region = <&pci0_msi_reserved>;
+		};
+
+		msi1: msi-controller@5840010 {
+			compatible = "mobileye,eyeq5-msi";
+			reg = <0x0 0x05840010 0x0 0x10>,
+			      <0x0 0x05840060 0x0 0x20>;
+			interrupt-parent = <&gic>;
+			msi-controller;
+			#msi-cells = <0>;
+			interrupts = <GIC_SHARED 48 IRQ_TYPE_LEVEL_HIGH>;
+			memory-region = <&pci1_msi_reserved>;
+		};
+
 		iocu-bus {
 			compatible = "simple-bus";
 			#address-cells = <2>;
Signature · 1 line
2.53.0
author maintainer
#6 lore raw

PATCH v5 5/5 MAINTAINERS: add EyeQ5 MSI controller entry

In reply to Gregory CLEMENT

Add the EyeQ5 MSI controller binding document and driver.

---
 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)
MAINTAINERS +2 -0
index 93abbb315065d..ca3a32790261d 100644
@@ -18769,12 +18769,14 @@ M:	Gregory CLEMENT <[email protected]>
 M:	Théo Lebrun <[email protected]>
 L:	[email protected]
 S:	Maintained
+F:	Documentation/devicetree/bindings/interrupt-controller/mobileye,eyeq5-msi.yaml
 F:	Documentation/devicetree/bindings/mips/mobileye.yaml
 F:	Documentation/devicetree/bindings/soc/mobileye/
 F:	arch/mips/boot/dts/mobileye/
 F:	arch/mips/configs/eyeq*_defconfig
 F:	arch/mips/mobileye/board-epm5.its.S
 F:	drivers/clk/clk-eyeq.c
+F:	drivers/irqchip/irq-eyeq5-msi.c
 F:	drivers/phy/phy-eyeq5-eth.c
 F:	drivers/pinctrl/pinctrl-eyeq5.c
 F:	drivers/reset/reset-eyeq.c
Signature · 1 line
2.53.0