Skip to contentSkip to conversation

PCI: pcie-xilinx-dma-pl: Fix off-by-one INTx IRQ handling

PATCH Superseded Stefan Roese 2 participants 6 messages Oct 21, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: pcie-xilinx-dma-pl: Fix off-by-one INTx IRQ handling

While testing with NVMe drives connected to the Versal QDMA PL PCIe RP on our platform I noticed that with MSI disabled (e.g. via pci=nomsi) the NVMe interrupts are not delivered to the host CPU resulting in timeouts while probing.

Debugging has shown, that the hwirq numbers passed to this device driver (1...4, 1=INTA etc) need to get adjusted to match the numbers in the controller registers bits (0...3). This patch now correctly matches the hwirq number to the PCIe controller register bits.

Cc Sean Anderson <[email protected]>
Cc Manivannan Sadhasivam <[email protected]>
Cc Ravi Kumar Bandi <[email protected]>
Cc Thippeswamy Havalige <[email protected]>
Cc Michal Simek <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 drivers/pci/controller/pcie-xilinx-dma-pl.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/pci/controller/pcie-xilinx-dma-pl.c +18 -3
index 84888eda990b2..5cca9d018bc89 100644
@@ -331,7 +331,12 @@ static void xilinx_mask_intx_irq(struct irq_data *data)
 	unsigned long flags;
 	u32 mask, val;
 
-	mask = BIT(data->hwirq + XILINX_PCIE_DMA_IDRN_SHIFT);
+	/*
+	 * INTx hwirq: 1=INTA, 2=INTB, 3=INTC, 4=INTD
+	 * In the controller regs this is represented in bits 0...3, so we need
+	 * to subtract 1 here
+	 */
+	mask = BIT(data->hwirq + XILINX_PCIE_DMA_IDRN_SHIFT - 1);
 	raw_spin_lock_irqsave(&port->lock, flags);
 	val = pcie_read(port, XILINX_PCIE_DMA_REG_IDRN_MASK);
 	pcie_write(port, (val & (~mask)), XILINX_PCIE_DMA_REG_IDRN_MASK);
@@ -344,7 +349,12 @@ static void xilinx_unmask_intx_irq(struct irq_data *data)
 	unsigned long flags;
 	u32 mask, val;
 
-	mask = BIT(data->hwirq + XILINX_PCIE_DMA_IDRN_SHIFT);
+	/*
+	 * INTx hwirq: 1=INTA, 2=INTB, 3=INTC, 4=INTD
+	 * In the controller regs this is represented in bits 0...3, so we need
+	 * to subtract 1 here
+	 */
+	mask = BIT(data->hwirq + XILINX_PCIE_DMA_IDRN_SHIFT - 1);
 	raw_spin_lock_irqsave(&port->lock, flags);
 	val = pcie_read(port, XILINX_PCIE_DMA_REG_IDRN_MASK);
 	pcie_write(port, (val | mask), XILINX_PCIE_DMA_REG_IDRN_MASK);
@@ -620,8 +630,13 @@ static irqreturn_t xilinx_pl_dma_pcie_intx_flow(int irq, void *args)
 	val = FIELD_GET(XILINX_PCIE_DMA_IDRN_MASK,
 			pcie_read(port, XILINX_PCIE_DMA_REG_IDRN));
 
+	/*
+	 * INTx hwirq: 1=INTA, 2=INTB, 3=INTC, 4=INTD
+	 * In the controller regs this is represented in bits 0...3, so we need
+	 * to add 1 here again for the registered handler
+	 */
 	for_each_set_bit(i, &val, PCI_NUM_INTX)
-		generic_handle_domain_irq(port->intx_domain, i);
+		generic_handle_domain_irq(port->intx_domain, i + 1);
 	return IRQ_HANDLED;
 }
 
Signature · 1 line
2.51.1
#1 lore raw
Quoted 5 lines · Stefan Roese

While testing with NVMe drives connected to the Versal QDMA PL PCIe RP on our platform I noticed that with MSI disabled (e.g. via pci=nomsi) the NVMe interrupts are not delivered to the host CPU resulting in timeouts while probing.

Quoted 7 lines

Debugging has shown, that the hwirq numbers passed to this device driver (1...4, 1=INTA etc) need to get adjusted to match the numbers in the controller registers bits (0...3). This patch now correctly matches the hwirq number to the PCIe controller register bits.

I assume I'm CC'd because of commit 02a370c4fc0f ("PCI: xilinx-nwl: Fix off-by-one in INTx IRQ handler"), which does the exact opposite of this patch.

And I'm rather confused as to how you determined that hwirq is one-based, since it seems to come directly from

	for_each_set_bit(i, &val, PCI_NUM_INTX)
		generic_handle_domain_irq(port->intx_domain, i);

which is zero-based.

--Sean

Quoted 56 lines
Cc Manivannan Sadhasivam <[email protected]>
Cc Ravi Kumar Bandi <[email protected]>
Cc Thippeswamy Havalige <[email protected]>
Cc Michal Simek <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 drivers/pci/controller/pcie-xilinx-dma-pl.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/pci/controller/pcie-xilinx-dma-pl.c +18 -3
index 84888eda990b2..5cca9d018bc89 100644
@@ -331,7 +331,12 @@ static void xilinx_mask_intx_irq(struct irq_data *data)
 	unsigned long flags;
 	u32 mask, val;
 
-	mask = BIT(data->hwirq + XILINX_PCIE_DMA_IDRN_SHIFT);
+	/*
+	 * INTx hwirq: 1=INTA, 2=INTB, 3=INTC, 4=INTD
+	 * In the controller regs this is represented in bits 0...3, so we need
+	 * to subtract 1 here
+	 */
+	mask = BIT(data->hwirq + XILINX_PCIE_DMA_IDRN_SHIFT - 1);
 	raw_spin_lock_irqsave(&port->lock, flags);
 	val = pcie_read(port, XILINX_PCIE_DMA_REG_IDRN_MASK);
 	pcie_write(port, (val & (~mask)), XILINX_PCIE_DMA_REG_IDRN_MASK);
@@ -344,7 +349,12 @@ static void xilinx_unmask_intx_irq(struct irq_data *data)
 	unsigned long flags;
 	u32 mask, val;
 
-	mask = BIT(data->hwirq + XILINX_PCIE_DMA_IDRN_SHIFT);
+	/*
+	 * INTx hwirq: 1=INTA, 2=INTB, 3=INTC, 4=INTD
+	 * In the controller regs this is represented in bits 0...3, so we need
+	 * to subtract 1 here
+	 */
+	mask = BIT(data->hwirq + XILINX_PCIE_DMA_IDRN_SHIFT - 1);
 	raw_spin_lock_irqsave(&port->lock, flags);
 	val = pcie_read(port, XILINX_PCIE_DMA_REG_IDRN_MASK);
 	pcie_write(port, (val | mask), XILINX_PCIE_DMA_REG_IDRN_MASK);
@@ -620,8 +630,13 @@ static irqreturn_t xilinx_pl_dma_pcie_intx_flow(int irq, void *args)
 	val = FIELD_GET(XILINX_PCIE_DMA_IDRN_MASK,
 			pcie_read(port, XILINX_PCIE_DMA_REG_IDRN));
 
+	/*
+	 * INTx hwirq: 1=INTA, 2=INTB, 3=INTC, 4=INTD
+	 * In the controller regs this is represented in bits 0...3, so we need
+	 * to add 1 here again for the registered handler
+	 */
 	for_each_set_bit(i, &val, PCI_NUM_INTX)
-		generic_handle_domain_irq(port->intx_domain, i);
+		generic_handle_domain_irq(port->intx_domain, i + 1);
 	return IRQ_HANDLED;
 }
 
#2 lore raw
Quoted 18 lines · Sean Anderson
Quoted 5 lines · Stefan Roese

While testing with NVMe drives connected to the Versal QDMA PL PCIe RP on our platform I noticed that with MSI disabled (e.g. via pci=nomsi) the NVMe interrupts are not delivered to the host CPU resulting in timeouts while probing.

Quoted 7 lines

Debugging has shown, that the hwirq numbers passed to this device driver (1...4, 1=INTA etc) need to get adjusted to match the numbers in the controller registers bits (0...3). This patch now correctly matches the hwirq number to the PCIe controller register bits.

I assume I'm CC'd because of commit 02a370c4fc0f ("PCI: xilinx-nwl: Fix off-by-one in INTx IRQ handler"), which does the exact opposite of this patch.

Quoted 7 lines

And I'm rather confused as to how you determined that hwirq is one-based, since it seems to come directly from

	for_each_set_bit(i, &val, PCI_NUM_INTX)
		generic_handle_domain_irq(port->intx_domain, i);

which is zero-based.

OK, upon re-reading the patch it looks like you also adjusted the above hunk to be one-based. After this patch the drivers adds one just to subtract it off again.

So why do the interrupts need to be one-based and not zero-based?

--Sean

Quoted 57 lines
Quoted 57 lines
Cc Manivannan Sadhasivam <[email protected]>
Cc Ravi Kumar Bandi <[email protected]>
Cc Thippeswamy Havalige <[email protected]>
Cc Michal Simek <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 drivers/pci/controller/pcie-xilinx-dma-pl.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/pci/controller/pcie-xilinx-dma-pl.c +18 -3
index 84888eda990b2..5cca9d018bc89 100644
@@ -331,7 +331,12 @@ static void xilinx_mask_intx_irq(struct irq_data *data)
 	unsigned long flags;
 	u32 mask, val;
 
-	mask = BIT(data->hwirq + XILINX_PCIE_DMA_IDRN_SHIFT);
+	/*
+	 * INTx hwirq: 1=INTA, 2=INTB, 3=INTC, 4=INTD
+	 * In the controller regs this is represented in bits 0...3, so we need
+	 * to subtract 1 here
+	 */
+	mask = BIT(data->hwirq + XILINX_PCIE_DMA_IDRN_SHIFT - 1);
 	raw_spin_lock_irqsave(&port->lock, flags);
 	val = pcie_read(port, XILINX_PCIE_DMA_REG_IDRN_MASK);
 	pcie_write(port, (val & (~mask)), XILINX_PCIE_DMA_REG_IDRN_MASK);
@@ -344,7 +349,12 @@ static void xilinx_unmask_intx_irq(struct irq_data *data)
 	unsigned long flags;
 	u32 mask, val;
 
-	mask = BIT(data->hwirq + XILINX_PCIE_DMA_IDRN_SHIFT);
+	/*
+	 * INTx hwirq: 1=INTA, 2=INTB, 3=INTC, 4=INTD
+	 * In the controller regs this is represented in bits 0...3, so we need
+	 * to subtract 1 here
+	 */
+	mask = BIT(data->hwirq + XILINX_PCIE_DMA_IDRN_SHIFT - 1);
 	raw_spin_lock_irqsave(&port->lock, flags);
 	val = pcie_read(port, XILINX_PCIE_DMA_REG_IDRN_MASK);
 	pcie_write(port, (val | mask), XILINX_PCIE_DMA_REG_IDRN_MASK);
@@ -620,8 +630,13 @@ static irqreturn_t xilinx_pl_dma_pcie_intx_flow(int irq, void *args)
 	val = FIELD_GET(XILINX_PCIE_DMA_IDRN_MASK,
 			pcie_read(port, XILINX_PCIE_DMA_REG_IDRN));
 
+	/*
+	 * INTx hwirq: 1=INTA, 2=INTB, 3=INTC, 4=INTD
+	 * In the controller regs this is represented in bits 0...3, so we need
+	 * to add 1 here again for the registered handler
+	 */
 	for_each_set_bit(i, &val, PCI_NUM_INTX)
-		generic_handle_domain_irq(port->intx_domain, i);
+		generic_handle_domain_irq(port->intx_domain, i + 1);
 	return IRQ_HANDLED;
 }
 
#3 lore raw

Hi Sean,

Quoted 12 lines · Sean Anderson
Quoted 11 lines · Sean Anderson
Quoted 10 lines · Stefan Roese

While testing with NVMe drives connected to the Versal QDMA PL PCIe RP on our platform I noticed that with MSI disabled (e.g. via pci=nomsi) the NVMe interrupts are not delivered to the host CPU resulting in timeouts while probing.

Debugging has shown, that the hwirq numbers passed to this device driver (1...4, 1=INTA etc) need to get adjusted to match the numbers in the controller registers bits (0...3). This patch now correctly matches the hwirq number to the PCIe controller register bits.

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

I assume I'm CC'd because of commit 02a370c4fc0f ("PCI: xilinx-nwl: Fix off-by-one in INTx IRQ handler"), which does the exact opposite of this patch.

Correct. PCI legacy interrupts are rarely used as it seems lately.

Quoted 6 lines
Quoted 6 lines

And I'm rather confused as to how you determined that hwirq is one-based, since it seems to come directly from

	for_each_set_bit(i, &val, PCI_NUM_INTX)
		generic_handle_domain_irq(port->intx_domain, i);
Quoted 7 lines
Quoted 1 line

which is zero-based.

OK, upon re-reading the patch it looks like you also adjusted the above hunk to be one-based. After this patch the drivers adds one just to subtract it off again.

So why do the interrupts need to be one-based and not zero-based?

My testing / debugging showed, that hwirq as an input to these functions is always 1 in my case. My assumption was, that this is because of these defines in include/linux/pci.h:

/**
* enum pci_interrupt_pin - PCI INTx interrupt values
* @PCI_INTERRUPT_UNKNOWN: Unknown or unassigned interrupt
* @PCI_INTERRUPT_INTA: PCI INTA pin
* @PCI_INTERRUPT_INTB: PCI INTB pin
* @PCI_INTERRUPT_INTC: PCI INTC pin
* @PCI_INTERRUPT_INTD: PCI INTD pin
*
* Corresponds to values for legacy PCI INTx interrupts, as can be
found in the
* PCI_INTERRUPT_PIN register.
*/
enum pci_interrupt_pin {
PCI_INTERRUPT_UNKNOWN,
PCI_INTERRUPT_INTA,
PCI_INTERRUPT_INTB,
PCI_INTERRUPT_INTC,
PCI_INTERRUPT_INTD,
};

So 0 is unknown and 1 is INTA.

I might have gotten something totally wrong this patch with these changes enables PCIe INTx generation on my Versal platform.

Thanks,
Stefan

Quoted 59 lines

--Sean

Quoted 57 lines
Quoted 57 lines
Cc Manivannan Sadhasivam <[email protected]>
Cc Ravi Kumar Bandi <[email protected]>
Cc Thippeswamy Havalige <[email protected]>
Cc Michal Simek <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
  drivers/pci/controller/pcie-xilinx-dma-pl.c | 21 ++++++++++++++++++---
  1 file changed, 18 insertions(+), 3 deletions(-)
drivers/pci/controller/pcie-xilinx-dma-pl.c +18 -3
index 84888eda990b2..5cca9d018bc89 100644
@@ -331,7 +331,12 @@ static void xilinx_mask_intx_irq(struct irq_data *data)
  	unsigned long flags;
  	u32 mask, val;
 
-	mask = BIT(data->hwirq + XILINX_PCIE_DMA_IDRN_SHIFT);
+	/*
+	 * INTx hwirq: 1=INTA, 2=INTB, 3=INTC, 4=INTD
+	 * In the controller regs this is represented in bits 0...3, so we need
+	 * to subtract 1 here
+	 */
+	mask = BIT(data->hwirq + XILINX_PCIE_DMA_IDRN_SHIFT - 1);
  	raw_spin_lock_irqsave(&port->lock, flags);
  	val = pcie_read(port, XILINX_PCIE_DMA_REG_IDRN_MASK);
  	pcie_write(port, (val & (~mask)), XILINX_PCIE_DMA_REG_IDRN_MASK);
@@ -344,7 +349,12 @@ static void xilinx_unmask_intx_irq(struct irq_data *data)
  	unsigned long flags;
  	u32 mask, val;
 
-	mask = BIT(data->hwirq + XILINX_PCIE_DMA_IDRN_SHIFT);
+	/*
+	 * INTx hwirq: 1=INTA, 2=INTB, 3=INTC, 4=INTD
+	 * In the controller regs this is represented in bits 0...3, so we need
+	 * to subtract 1 here
+	 */
+	mask = BIT(data->hwirq + XILINX_PCIE_DMA_IDRN_SHIFT - 1);
  	raw_spin_lock_irqsave(&port->lock, flags);
  	val = pcie_read(port, XILINX_PCIE_DMA_REG_IDRN_MASK);
  	pcie_write(port, (val | mask), XILINX_PCIE_DMA_REG_IDRN_MASK);
@@ -620,8 +630,13 @@ static irqreturn_t xilinx_pl_dma_pcie_intx_flow(int irq, void *args)
  	val = FIELD_GET(XILINX_PCIE_DMA_IDRN_MASK,
  			pcie_read(port, XILINX_PCIE_DMA_REG_IDRN));
 
+	/*
+	 * INTx hwirq: 1=INTA, 2=INTB, 3=INTC, 4=INTD
+	 * In the controller regs this is represented in bits 0...3, so we need
+	 * to add 1 here again for the registered handler
+	 */
  	for_each_set_bit(i, &val, PCI_NUM_INTX)
-		generic_handle_domain_irq(port->intx_domain, i);
+		generic_handle_domain_irq(port->intx_domain, i + 1);
  	return IRQ_HANDLED;
  }
 
#4 lore raw
Quoted 61 lines · Stefan Roese

Hi Sean,

Quoted 12 lines · Sean Anderson
Quoted 11 lines · Sean Anderson
Quoted 10 lines · Stefan Roese

While testing with NVMe drives connected to the Versal QDMA PL PCIe RP on our platform I noticed that with MSI disabled (e.g. via pci=nomsi) the NVMe interrupts are not delivered to the host CPU resulting in timeouts while probing.

Debugging has shown, that the hwirq numbers passed to this device driver (1...4, 1=INTA etc) need to get adjusted to match the numbers in the controller registers bits (0...3). This patch now correctly matches the hwirq number to the PCIe controller register bits.

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

I assume I'm CC'd because of commit 02a370c4fc0f ("PCI: xilinx-nwl: Fix off-by-one in INTx IRQ handler"), which does the exact opposite of this patch.

Correct. PCI legacy interrupts are rarely used as it seems lately.

Quoted 6 lines
Quoted 6 lines

And I'm rather confused as to how you determined that hwirq is one-based, since it seems to come directly from

    for_each_set_bit(i, &val, PCI_NUM_INTX) generic_handle_domain_irq(port->intx_domain, i);

Quoted 7 lines
Quoted 1 line

which is zero-based.

OK, upon re-reading the patch it looks like you also adjusted the above hunk to be one-based. After this patch the drivers adds one just to subtract it off again.

So why do the interrupts need to be one-based and not zero-based?

My testing / debugging showed, that hwirq as an input to these functions is always 1 in my case. My assumption was, that this is because of these defines in include/linux/pci.h:

/**
 * enum pci_interrupt_pin - PCI INTx interrupt values
 * @PCI_INTERRUPT_UNKNOWN: Unknown or unassigned interrupt
 * @PCI_INTERRUPT_INTA: PCI INTA pin
 * @PCI_INTERRUPT_INTB: PCI INTB pin
 * @PCI_INTERRUPT_INTC: PCI INTC pin
 * @PCI_INTERRUPT_INTD: PCI INTD pin
 *
 * Corresponds to values for legacy PCI INTx interrupts, as can be found in the
 * PCI_INTERRUPT_PIN register.
 */
enum pci_interrupt_pin {
    PCI_INTERRUPT_UNKNOWN,
    PCI_INTERRUPT_INTA,
    PCI_INTERRUPT_INTB,
    PCI_INTERRUPT_INTC,
    PCI_INTERRUPT_INTD,
};

Quoted 5 lines

So 0 is unknown and 1 is INTA.

I might have gotten something totally wrong this patch with these changes enables PCIe INTx generation on my Versal platform.

Maybe you need to set intx_domain_ops.xlate to pci_irqd_intx_xlate?

--Sean

Quoted 56 lines
Quoted 55 lines
Quoted 55 lines
Quoted 55 lines
Cc Manivannan Sadhasivam <[email protected]>
Cc Ravi Kumar Bandi <[email protected]>
Cc Thippeswamy Havalige <[email protected]>
Cc Michal Simek <[email protected]>
Cc Bjorn Helgaas <[email protected]>

---
  drivers/pci/controller/pcie-xilinx-dma-pl.c | 21 ++++++++++++++++++---

  1 file changed, 18 insertions(+), 3 deletions(-)
drivers/pci/controller/pcie-xilinx-dma-pl.c +12 -0
index 84888eda990b2..5cca9d018bc89 100644
@@ -331,7 +331,12 @@ static void xilinx_mask_intx_irq(struct irq_data *data)
       unsigned long flags;
       u32 mask, val;
   -    mask = BIT(data->hwirq + XILINX_PCIE_DMA_IDRN_SHIFT);
+    /*
+     * INTx hwirq: 1=INTA, 2=INTB, 3=INTC, 4=INTD
+     * In the controller regs this is represented in bits 0...3, so we need
+     * to subtract 1 here
+     */
+    mask = BIT(data->hwirq + XILINX_PCIE_DMA_IDRN_SHIFT - 1);
       raw_spin_lock_irqsave(&port->lock, flags);
       val = pcie_read(port, XILINX_PCIE_DMA_REG_IDRN_MASK);
       pcie_write(port, (val & (~mask)), XILINX_PCIE_DMA_REG_IDRN_MASK);
@@ -344,7 +349,12 @@ static void xilinx_unmask_intx_irq(struct irq_data *data)
       unsigned long flags;
       u32 mask, val;
   -    mask = BIT(data->hwirq + XILINX_PCIE_DMA_IDRN_SHIFT);
+    /*
+     * INTx hwirq: 1=INTA, 2=INTB, 3=INTC, 4=INTD
+     * In the controller regs this is represented in bits 0...3, so we need
+     * to subtract 1 here
+     */
+    mask = BIT(data->hwirq + XILINX_PCIE_DMA_IDRN_SHIFT - 1);
       raw_spin_lock_irqsave(&port->lock, flags);
       val = pcie_read(port, XILINX_PCIE_DMA_REG_IDRN_MASK);
       pcie_write(port, (val | mask), XILINX_PCIE_DMA_REG_IDRN_MASK);
@@ -620,8 +630,13 @@ static irqreturn_t xilinx_pl_dma_pcie_intx_flow(int irq, void *args)
       val = FIELD_GET(XILINX_PCIE_DMA_IDRN_MASK,
               pcie_read(port, XILINX_PCIE_DMA_REG_IDRN));

  +    /*
+     * INTx hwirq: 1=INTA, 2=INTB, 3=INTC, 4=INTD
+     * In the controller regs this is represented in bits 0...3, so we need +     * to add 1 here again for the registered handler
+     */
      for_each_set_bit(i, &val, PCI_NUM_INTX)
-        generic_handle_domain_irq(port->intx_domain, i);
+        generic_handle_domain_irq(port->intx_domain, i + 1); return IRQ_HANDLED;
  }

#5 lore raw

Hi Sean,

Quoted 62 lines · Sean Anderson
Quoted 61 lines · Stefan Roese

Hi Sean,

Quoted 12 lines · Sean Anderson
Quoted 11 lines · Sean Anderson
Quoted 10 lines · Stefan Roese

While testing with NVMe drives connected to the Versal QDMA PL PCIe RP on our platform I noticed that with MSI disabled (e.g. via pci=nomsi) the NVMe interrupts are not delivered to the host CPU resulting in timeouts while probing.

Debugging has shown, that the hwirq numbers passed to this device driver (1...4, 1=INTA etc) need to get adjusted to match the numbers in the controller registers bits (0...3). This patch now correctly matches the hwirq number to the PCIe controller register bits.

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

I assume I'm CC'd because of commit 02a370c4fc0f ("PCI: xilinx-nwl: Fix off-by-one in INTx IRQ handler"), which does the exact opposite of this patch.

Correct. PCI legacy interrupts are rarely used as it seems lately.

Quoted 6 lines
Quoted 6 lines

And I'm rather confused as to how you determined that hwirq is one-based, since it seems to come directly from

    for_each_set_bit(i, &val, PCI_NUM_INTX) generic_handle_domain_irq(port->intx_domain, i);

Quoted 7 lines
Quoted 1 line

which is zero-based.

OK, upon re-reading the patch it looks like you also adjusted the above hunk to be one-based. After this patch the drivers adds one just to subtract it off again.

So why do the interrupts need to be one-based and not zero-based?

My testing / debugging showed, that hwirq as an input to these functions is always 1 in my case. My assumption was, that this is because of these defines in include/linux/pci.h:

/**
 * enum pci_interrupt_pin - PCI INTx interrupt values
 * @PCI_INTERRUPT_UNKNOWN: Unknown or unassigned interrupt
 * @PCI_INTERRUPT_INTA: PCI INTA pin
 * @PCI_INTERRUPT_INTB: PCI INTB pin
 * @PCI_INTERRUPT_INTC: PCI INTC pin
 * @PCI_INTERRUPT_INTD: PCI INTD pin
 *
 * Corresponds to values for legacy PCI INTx interrupts, as can be found in the
 * PCI_INTERRUPT_PIN register.
 */
enum pci_interrupt_pin {
    PCI_INTERRUPT_UNKNOWN,
    PCI_INTERRUPT_INTA,
    PCI_INTERRUPT_INTB,
    PCI_INTERRUPT_INTC,
    PCI_INTERRUPT_INTD,
};

Quoted 7 lines
Quoted 5 lines

So 0 is unknown and 1 is INTA.

I might have gotten something totally wrong this patch with these changes enables PCIe INTx generation on my Versal platform.

Maybe you need to set intx_domain_ops.xlate to pci_irqd_intx_xlate?

Ah, much better. I was not aware of this. Will send v2 using this xlate function instead.

Thanks a lot,
Stefan

Quoted 59 lines

--Sean

Quoted 56 lines
Quoted 55 lines
Quoted 55 lines
Quoted 55 lines
Cc Manivannan Sadhasivam <[email protected]>
Cc Ravi Kumar Bandi <[email protected]>
Cc Thippeswamy Havalige <[email protected]>
Cc Michal Simek <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
   drivers/pci/controller/pcie-xilinx-dma-pl.c | 21 ++++++++++++++++++---
   1 file changed, 18 insertions(+), 3 deletions(-)
drivers/pci/controller/pcie-xilinx-dma-pl.c +17 -1
index 84888eda990b2..5cca9d018bc89 100644
@@ -331,7 +331,12 @@ static void xilinx_mask_intx_irq(struct irq_data *data)
       unsigned long flags;
       u32 mask, val;
   -    mask = BIT(data->hwirq + XILINX_PCIE_DMA_IDRN_SHIFT);
+    /*
+     * INTx hwirq: 1=INTA, 2=INTB, 3=INTC, 4=INTD
+     * In the controller regs this is represented in bits 0...3, so we need
+     * to subtract 1 here
+     */
+    mask = BIT(data->hwirq + XILINX_PCIE_DMA_IDRN_SHIFT - 1);
       raw_spin_lock_irqsave(&port->lock, flags);
       val = pcie_read(port, XILINX_PCIE_DMA_REG_IDRN_MASK);
       pcie_write(port, (val & (~mask)), XILINX_PCIE_DMA_REG_IDRN_MASK);
@@ -344,7 +349,12 @@ static void xilinx_unmask_intx_irq(struct irq_data *data)
       unsigned long flags;
       u32 mask, val;
   -    mask = BIT(data->hwirq + XILINX_PCIE_DMA_IDRN_SHIFT);
+    /*
+     * INTx hwirq: 1=INTA, 2=INTB, 3=INTC, 4=INTD
+     * In the controller regs this is represented in bits 0...3, so we need
+     * to subtract 1 here
+     */
+    mask = BIT(data->hwirq + XILINX_PCIE_DMA_IDRN_SHIFT - 1);
       raw_spin_lock_irqsave(&port->lock, flags);
       val = pcie_read(port, XILINX_PCIE_DMA_REG_IDRN_MASK);
       pcie_write(port, (val | mask), XILINX_PCIE_DMA_REG_IDRN_MASK);
@@ -620,8 +630,13 @@ static irqreturn_t xilinx_pl_dma_pcie_intx_flow(int irq, void *args)
       val = FIELD_GET(XILINX_PCIE_DMA_IDRN_MASK,
               pcie_read(port, XILINX_PCIE_DMA_REG_IDRN));
   +    /*
+     * INTx hwirq: 1=INTA, 2=INTB, 3=INTC, 4=INTD
+     * In the controller regs this is represented in bits 0...3, so we need
+     * to add 1 here again for the registered handler
+     */
       for_each_set_bit(i, &val, PCI_NUM_INTX)
-        generic_handle_domain_irq(port->intx_domain, i);
+        generic_handle_domain_irq(port->intx_domain, i + 1);
       return IRQ_HANDLED;
   }
 

Thanks a