Skip to contentSkip to conversation

spi: pca2xx: Prepare for and enable MSI support

PATCH Superseded Jan Kiszka 5 participants 30 messages Jan 16, 2017 – Jan 24, 2017

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

v2 cover spi: pca2xx: Prepare for and enable MSI support

This enhances the pca2xx driver's interrupt handler with support for edge-triggered interrupts and makes use of that for PCI-hosted variants, like the Intel Quark SoC.

Changes in v2:
- factored out handle_bad_msg (Andy)
- reordered code in patch 3, avoiding unneeded pci_free_irq_vectors (Andy)

Jan

Jan Kiszka (3):
spi: pxa2xx: Factor out handle_bad_msg
spi: pxa2xx: Prepare for edge-triggered interrupts
spi: pca2xx-pci: Allow MSI

 drivers/spi/spi-pxa2xx-pci.c |  8 ++++++-
 drivers/spi/spi-pxa2xx.c     | 51 +++++++++++++++++++++++++-------------------
 2 files changed, 36 insertions(+), 23 deletions(-)
Signature · 1 line
2.1.4
author
#1 lore raw

PATCH v2 1/3 spi: pxa2xx: Factor out handle_bad_msg

As suggested by Andy Shevchenko: Decouple this corner cause from the general handling logic in ssp_int.

---
 drivers/spi/spi-pxa2xx.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
drivers/spi/spi-pxa2xx.c +15 -14
index dd7b5b4..0d10090 100644
@@ -732,6 +732,20 @@ static irqreturn_t interrupt_transfer(struct driver_data *drv_data)
 	return IRQ_HANDLED;
 }
 
+static void handle_bad_msg(struct driver_data *drv_data)
+{
+	pxa2xx_spi_write(drv_data, SSCR0,
+			 pxa2xx_spi_read(drv_data, SSCR0) & ~SSCR0_SSE);
+	pxa2xx_spi_write(drv_data, SSCR1,
+			 pxa2xx_spi_read(drv_data, SSCR1) & ~drv_data->int_cr1);
+	if (!pxa25x_ssp_comp(drv_data))
+		pxa2xx_spi_write(drv_data, SSTO, 0);
+	write_SSSR_CS(drv_data, drv_data->clear_sr);
+
+	dev_err(&drv_data->pdev->dev,
+		"bad message state in interrupt handler\n");
+}
+
 static irqreturn_t ssp_int(int irq, void *dev_id)
 {
 	struct driver_data *drv_data = dev_id;
@@ -772,20 +786,7 @@ static irqreturn_t ssp_int(int irq, void *dev_id)
 		return IRQ_NONE;
 
 	if (!drv_data->master->cur_msg) {
-
-		pxa2xx_spi_write(drv_data, SSCR0,
-				 pxa2xx_spi_read(drv_data, SSCR0)
-				 & ~SSCR0_SSE);
-		pxa2xx_spi_write(drv_data, SSCR1,
-				 pxa2xx_spi_read(drv_data, SSCR1)
-				 & ~drv_data->int_cr1);
-		if (!pxa25x_ssp_comp(drv_data))
-			pxa2xx_spi_write(drv_data, SSTO, 0);
-		write_SSSR_CS(drv_data, drv_data->clear_sr);
-
-		dev_err(&drv_data->pdev->dev,
-			"bad message state in interrupt handler\n");
-
+		handle_bad_msg(drv_data);
 		/* Never fail */
 		return IRQ_HANDLED;
 	}
Signature · 1 line
2.1.4
author
#4 lore raw

PATCH v2 2/3 spi: pxa2xx: Prepare for edge-triggered interrupts

In reply to Jan Kiszka

When using the a device with edge-triggered interrupts, such as MSIs, the interrupt handler has to ensure that there is a point in time during its execution where all interrupts sources are silent so that a new event can trigger a new interrupt again.

This is achieved here by looping over SSSR evaluation. We need to take into account that SSCR1 may be changed by the transfer handler, thus we need to redo the mask calculation, at least regarding the volatile interrupt enable bit (TIE).

---
 drivers/spi/spi-pxa2xx.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)
drivers/spi/spi-pxa2xx.c +18 -12
index 0d10090..ac49b80 100644
@@ -751,6 +751,7 @@ static irqreturn_t ssp_int(int irq, void *dev_id)
 	struct driver_data *drv_data = dev_id;
 	u32 sccr1_reg;
 	u32 mask = drv_data->mask_sr;
+	irqreturn_t ret = IRQ_NONE;
 	u32 status;
 
 	/*
@@ -774,24 +775,29 @@ static irqreturn_t ssp_int(int irq, void *dev_id)
 
 	sccr1_reg = pxa2xx_spi_read(drv_data, SSCR1);
 
-	/* Ignore possible writes if we don't need to write */
-	if (!(sccr1_reg & SSCR1_TIE))
-		mask &= ~SSSR_TFS;
-
 	/* Ignore RX timeout interrupt if it is disabled */
 	if (!(sccr1_reg & SSCR1_TINTE))
 		mask &= ~SSSR_TINT;
 
-	if (!(status & mask))
-		return IRQ_NONE;
+	while (1) {
+		/* Ignore possible writes if we don't need to write */
+		if (!(sccr1_reg & SSCR1_TIE))
+			mask &= ~SSSR_TFS;
 
-	if (!drv_data->master->cur_msg) {
-		handle_bad_msg(drv_data);
-		/* Never fail */
-		return IRQ_HANDLED;
-	}
+		if (!(status & mask))
+			return ret;
+
+		if (!drv_data->master->cur_msg) {
+			handle_bad_msg(drv_data);
+			/* Never fail */
+			return IRQ_HANDLED;
+		}
+
+		ret |= drv_data->transfer_handler(drv_data);
 
-	return drv_data->transfer_handler(drv_data);
+		status = pxa2xx_spi_read(drv_data, SSSR);
+		sccr1_reg = pxa2xx_spi_read(drv_data, SSCR1);
+	}
 }
 
 /*
Signature · 1 line
2.1.4
author
#26 lore raw

PATCH v2 3/3 spi: pca2xx-pci: Allow MSI

In reply to Jan Kiszka

Now that the core is ready for edge-triggered interrupts, we can safely allow the PCI versions that provide this to enable the feature and, thus, have less shared interrupts.

---
 drivers/spi/spi-pxa2xx-pci.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/spi/spi-pxa2xx-pci.c +7 -1
index 58d2d48..58dcadb 100644
@@ -203,10 +203,16 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev,
 	ssp = &spi_pdata.ssp;
 	ssp->phys_base = pci_resource_start(dev, 0);
 	ssp->mmio_base = pcim_iomap_table(dev)[0];
-	ssp->irq = dev->irq;
 	ssp->port_id = (c->port_id >= 0) ? c->port_id : dev->devfn;
 	ssp->type = c->type;
 
+	pci_set_master(dev);
+
+	ret = pci_alloc_irq_vectors(dev, 1, 1, PCI_IRQ_ALL_TYPES);
+	if (ret < 0)
+		return ret;
+	ssp->irq = pci_irq_vector(dev, 0);
+
 	snprintf(buf, sizeof(buf), "pxa2xx-spi.%d", ssp->port_id);
 	ssp->clk = clk_register_fixed_rate(&dev->dev, buf , NULL, 0,
 					   c->max_clk_rate);
Signature · 1 line
2.1.4
#5 lore raw

Re: [PATCH v2 2/3] spi: pxa2xx: Prepare for edge-triggered interrupts

In reply to Jan Kiszka
Quoted 6 lines · Jan Kiszka

When using the a device with edge-triggered interrupts, such as MSIs, the interrupt handler has to ensure that there is a point in time during
its execution where all interrupts sources are silent so that a new event can trigger a new interrupt again.

Quoted 6 lines

This is achieved here by looping over SSSR evaluation. We need to take into account that SSCR1 may be changed by the transfer handler, thus we
need to redo the mask calculation, at least regarding the volatile interrupt enable bit (TIE).

So, more comments/questions below.

Quoted 11 lines

?
? sccr1_reg = pxa2xx_spi_read(drv_data, SSCR1);
?

drivers/spi/spi-pxa2xx.c +0 -4
-	/* Ignore possible writes if we don't need to write */
-	if (!(sccr1_reg & SSCR1_TIE))
-		mask &= ~SSSR_TFS;
-

? /* Ignore RX timeout interrupt if it is disabled */
? if (!(sccr1_reg & SSCR1_TINTE))
? mask &= ~SSSR_TINT;
?

drivers/spi/spi-pxa2xx.c static irqreturn_t ssp_int(int irq, void *dev_id) · line 782

Quoted 3 lines
drivers/spi/spi-pxa2xx.c +1 -2
-	if (!(status & mask))
-		return IRQ_NONE;
+	while (1) {

Can we switch to do-while and move previous block here? Btw, can TINTE bit be set again during a loop?

Quoted 11 lines
(quoted diff) +1 -0
+		/* Ignore possible writes if we don't need to write

*/

drivers/spi/spi-pxa2xx.c +2 -0
+		if (!(sccr1_reg & SSCR1_TIE))
+			mask &= ~SSSR_TFS;

?

drivers/spi/spi-pxa2xx.c +1 -5
-	if (!drv_data->master->cur_msg) {
-		handle_bad_msg(drv_data);
-		/* Never fail */
-		return IRQ_HANDLED;
-	}
+		if (!(status & mask))

drivers/spi/spi-pxa2xx.c static irqreturn_t ssp_int(int irq, void *dev_id)

Quoted 10 lines
drivers/spi/spi-pxa2xx.c +9 -0
+			return ret;
+
+		if (!drv_data->master->cur_msg) {
+			handle_bad_msg(drv_data);
+			/* Never fail */
+			return IRQ_HANDLED;
+		}
+
 
+		ret |= drv_data->transfer_handler(drv_data);

So, we might call handler several times. This needs to be commented in the code why you do so.

drivers/spi/spi-pxa2xx.c static irqreturn_t ssp_int(int irq, void *dev_id) · line 798

Quoted 3 lines

?

drivers/spi/spi-pxa2xx.c +1 -1
-	return drv_data->transfer_handler(drv_data);
+		status = pxa2xx_spi_read(drv_data, SSSR);

Would it be possible to get all 1:s from the register (something/autosuspend just powered off it by timeout?) ?

Quoted 5 lines
drivers/spi/spi-pxa2xx.c +2 -0
+		sccr1_reg = pxa2xx_spi_read(drv_data, SSCR1);
+	}

?}
?
?/*

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
reviewer Reviewed-by on v2 3/3
#27 lore raw

Re: [PATCH v2 3/3] spi: pca2xx-pci: Allow MSI

In reply to Jan Kiszka
Quoted 5 lines · Jan Kiszka

Now that the core is ready for edge-triggered interrupts, we can safely
allow the PCI versions that provide this to enable the feature and, thus, have less shared interrupts.

Quoted 17 lines

?drivers/spi/spi-pxa2xx-pci.c | 8 +++++++-
?1 file changed, 7 insertions(+), 1 deletion(-)

drivers/spi/spi-pxa2xx- renamed from drivers/spi/spi-pxa2xx-pci.c +0 -0

pci.c
index 58d2d48..58dcadb 100644

drivers/spi/spi-pxa2xx-pci.c +0 -1
@@ -203,10 +203,16 @@ static int pxa2xx_spi_pci_probe(struct pci_dev
 *dev,
 ?	ssp = &spi_pdata.ssp;
 ?	ssp->phys_base = pci_resource_start(dev, 0);
 ?	ssp->mmio_base = pcim_iomap_table(dev)[0];
-	ssp->irq = dev->irq;
 ?	ssp->port_id = (c->port_id >= 0) ? c->port_id : dev->devfn;
 ?	ssp->type = c->type;

?

drivers/spi/spi-pxa2xx-pci.c static int pxa2xx_spi_pci_probe(struct pci_dev *dev, · line 213

Quoted 5 lines
drivers/spi/spi-pxa2xx-pci.c +5 -0
+	pci_set_master(dev);
+
+	ret = pci_alloc_irq_vectors(dev, 1, 1, PCI_IRQ_ALL_TYPES);
+	if (ret < 0)
+		return ret;

+ perhaps an empty line?

Quoted 4 lines
drivers/spi/spi-pxa2xx-pci.c +2 -0
+	ssp->irq = pci_irq_vector(dev, 0);
+

? snprintf(buf, sizeof(buf), "pxa2xx-spi.%d", ssp->port_id);
? ssp->clk = clk_register_fixed_rate(&dev->dev, buf , NULL, 0,

? ???c->max_clk_rate);

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
author
#6 lore raw

Re: [PATCH v2 2/3] spi: pxa2xx: Prepare for edge-triggered interrupts

In reply to Andy Shevchenko
Quoted 27 lines · Andy Shevchenko
Quoted 6 lines · Jan Kiszka

When using the a device with edge-triggered interrupts, such as MSIs, the interrupt handler has to ensure that there is a point in time during
its execution where all interrupts sources are silent so that a new event can trigger a new interrupt again.

Quoted 6 lines

This is achieved here by looping over SSSR evaluation. We need to take into account that SSCR1 may be changed by the transfer handler, thus we
need to redo the mask calculation, at least regarding the volatile interrupt enable bit (TIE).

So, more comments/questions below.

Quoted 11 lines
drivers/spi/spi-pxa2xx.c +0 -4
 	sccr1_reg = pxa2xx_spi_read(drv_data, SSCR1);
 
-	/* Ignore possible writes if we don't need to write */
-	if (!(sccr1_reg & SSCR1_TIE))
-		mask &= ~SSSR_TFS;
-
 	/* Ignore RX timeout interrupt if it is disabled */
 	if (!(sccr1_reg & SSCR1_TINTE))
 		mask &= ~SSSR_TINT;
Quoted 5 lines

drivers/spi/spi-pxa2xx.c static irqreturn_t ssp_int(int irq, void *dev_id) · line 782

Quoted 3 lines
drivers/spi/spi-pxa2xx.c +1 -2
-	if (!(status & mask))
-		return IRQ_NONE;
+	while (1) {

Can we switch to do-while and move previous block here?

Don't see how this would help (without duplicating more code).

Quoted 2 lines

Btw, can TINTE
bit be set again during a loop?

Nope, it's statically set, at least so far.

What we could do is simply restarting ssp_int

Quoted 21 lines
Quoted 20 lines
(quoted diff) +1 -0
+		/* Ignore possible writes if we don't need to write

*/

drivers/spi/spi-pxa2xx.c +11 -5
+		if (!(sccr1_reg & SSCR1_TIE))
+			mask &= ~SSSR_TFS;
 
-	if (!drv_data->master->cur_msg) {
-		handle_bad_msg(drv_data);
-		/* Never fail */
-		return IRQ_HANDLED;
-	}
+		if (!(status & mask))
+			return ret;
+
+		if (!drv_data->master->cur_msg) {
+			handle_bad_msg(drv_data);
+			/* Never fail */
+			return IRQ_HANDLED;
+		}
+
Quoted 4 lines

drivers/spi/spi-pxa2xx.c static irqreturn_t ssp_int(int irq, void *dev_id) · line 796

Quoted 1 line
drivers/spi/spi-pxa2xx.c +1 -0
+		ret |= drv_data->transfer_handler(drv_data);

So, we might call handler several times. This needs to be commented in the code why you do so.

I can move the commit log into the code.

Quoted 8 lines

drivers/spi/spi-pxa2xx.c static irqreturn_t ssp_int(int irq, void *dev_id) · line 798

Quoted 4 lines
drivers/spi/spi-pxa2xx.c +1 -1
-	return drv_data->transfer_handler(drv_data);
+		status = pxa2xx_spi_read(drv_data, SSSR);

Would it be possible to get all 1:s from the register (something/autosuspend just powered off it by timeout?) ?

Not sure if that can happen, but I guess it would be simpler and more readable to simply do this instead:

	while (1) {
		/*
		 * If the device is not yet in RPM suspended state and we get an
		 * interrupt that is meant for another device, check if status
		 * bits are all set to one. That means that the device is
		 * already powered off.
		 */
		status = pxa2xx_spi_read(drv_data, SSSR);
		if (status == ~0)
			return ret;

		sccr1_reg = pxa2xx_spi_read(drv_data, SSCR1);

		/* Ignore RX timeout interrupt if it is disabled */
		if (!(sccr1_reg & SSCR1_TINTE))
			mask &= ~SSSR_TINT;

		/* Ignore possible writes if we don't need to write */
		if (!(sccr1_reg & SSCR1_TIE))
			mask &= ~SSSR_TFS;

		if (!(status & mask))
			return ret;

		if (!drv_data->master->cur_msg) {
			handle_bad_msg(drv_data);
			/* Never fail */
			return IRQ_HANDLED;
		}

		ret |= drv_data->transfer_handler(drv_data);
	}

i.e. preserve the current structure, just add the loop.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA ITP SES-DE
Corporate Competence Center Embedded Linux
maintainer
#8 lore raw

Re: [PATCH v2 2/3] spi: pxa2xx: Prepare for edge-triggered interrupts

In reply to Jan Kiszka
Quoted 11 lines · Jan Kiszka

When using the a device with edge-triggered interrupts, such as MSIs, the interrupt handler has to ensure that there is a point in time during its execution where all interrupts sources are silent so that a new event can trigger a new interrupt again.

This is achieved here by looping over SSSR evaluation. We need to take into account that SSCR1 may be changed by the transfer handler, thus we need to redo the mask calculation, at least regarding the volatile interrupt enable bit (TIE).

Hi Jan,

drivers/spi/spi-pxa2xx.c static irqreturn_t ssp_int(int irq, void *dev_id) · line 782

Quoted 1 line
drivers/spi/spi-pxa2xx.c +1 -0
+	while (1) {

This bit worries me a bit, as this can be either :
- hogging the SoC's CPU, endlessly running
- or even worse, blocking the CPU for ever

The question behind is, should this be done in a top-half, or moved to a irq thread ?

Quoted 9 lines
drivers/spi/spi-pxa2xx.c +3 -5
+		/* Ignore possible writes if we don't need to write */
+		if (!(sccr1_reg & SSCR1_TIE))
+			mask &= ~SSSR_TFS;
 
-	if (!drv_data->master->cur_msg) {
-		handle_bad_msg(drv_data);
-		/* Never fail */
-		return IRQ_HANDLED;
-	}

drivers/spi/spi-pxa2xx.c static irqreturn_t ssp_int(int irq, void *dev_id) · line 796

Quoted 10 lines
drivers/spi/spi-pxa2xx.c +10 -0
+		if (!(status & mask))
+			return ret;
+
+		if (!drv_data->master->cur_msg) {
+			handle_bad_msg(drv_data);
+			/* Never fail */
+			return IRQ_HANDLED;
+		}
+
+		ret |= drv_data->transfer_handler(drv_data);

Mmm that looks weird to me, oring a irqreturn.

Imagine that on first iteration the handler returns IRQ_NONE, and on second IRQ_HANDLED. This makes ret IRQ_HANDLED. Yet after the first iteration the handler should have exited, especially if the interrupt is shared with another driver.

Another thing which is along what Andy already said : it would be better practice to have this loop in the form :
do {
...
} while (exit_condition_not_met);

Just for maintainability, it's better, and it concentrates the test on the "exit_condition_not_met" in one place, which will enable us to review better the algorithm.

Cheers.

Signature · 1 line
Robert
maintainer
#22 lore raw

Re: [PATCH v2 2/3] spi: pxa2xx: Prepare for edge-triggered interrupts

In reply to Jan Kiszka
Quoted 9 lines · Jan Kiszka

When using the a device with edge-triggered interrupts, such as MSIs, the interrupt handler has to ensure that there is a point in time during its execution where all interrupts sources are silent so that a new event can trigger a new interrupt again.

This is achieved here by looping over SSSR evaluation. We need to take into account that SSCR1 may be changed by the transfer handler, thus we need to redo the mask calculation, at least regarding the volatile interrupt enable bit (TIE).

I'd like moreover to add a question here.

In pxa architecture, SPI interrupts are already edge-triggered, and it's working well. The interrupt source disabling is not disabled, but the interrupt controller doesn't trigger an interrupt anymore (as it is masked), yet it marks it as pending if an interrupt arrives while the interrupt handler is running.

All of this is handled by the interrupt core. My question is why for Intel MSI's is it necessary to make a change in the driver instead or relying on the interrupt core as for the pxa ?

Cheers.

--
Robert

author
#9 lore raw

Re: [PATCH v2 2/3] spi: pxa2xx: Prepare for edge-triggered interrupts

In reply to Robert Jarzmik
Quoted 15 lines · Robert Jarzmik
Quoted 11 lines · Jan Kiszka

When using the a device with edge-triggered interrupts, such as MSIs, the interrupt handler has to ensure that there is a point in time during its execution where all interrupts sources are silent so that a new event can trigger a new interrupt again.

This is achieved here by looping over SSSR evaluation. We need to take into account that SSCR1 may be changed by the transfer handler, thus we need to redo the mask calculation, at least regarding the volatile interrupt enable bit (TIE).

Hi Jan,

Quoted 7 lines

drivers/spi/spi-pxa2xx.c static irqreturn_t ssp_int(int irq, void *dev_id) · line 782

Quoted 1 line
drivers/spi/spi-pxa2xx.c +1 -0
+	while (1) {

This bit worries me a bit, as this can be either :
- hogging the SoC's CPU, endlessly running
- or even worse, blocking the CPU for ever

The question behind is, should this be done in a top-half, or moved to a irq thread ?

Every device with a broken interrupt source can hog CPUs, nothing special with this one. If you don't close the loop in the handler itself, you close it over the hardware retriggering the interrupt over and over again.

So, I don't see a point in offloading to a thread. The normal case is some TX done (FIFO available) event followed by an RX event, then the transfer is complete, isn't it?

Quoted 5 lines
Quoted 5 lines
drivers/spi/spi-pxa2xx.c +3 -0
+		/* Ignore possible writes if we don't need to write */
+		if (!(sccr1_reg & SSCR1_TIE))
+			mask &= ~SSSR_TFS;
Quoted 16 lines
Quoted 5 lines
drivers/spi/spi-pxa2xx.c +0 -5
-	if (!drv_data->master->cur_msg) {
-		handle_bad_msg(drv_data);
-		/* Never fail */
-		return IRQ_HANDLED;
-	}

drivers/spi/spi-pxa2xx.c static irqreturn_t ssp_int(int irq, void *dev_id) · line 796

Quoted 10 lines
drivers/spi/spi-pxa2xx.c +10 -0
+		if (!(status & mask))
+			return ret;
+
+		if (!drv_data->master->cur_msg) {
+			handle_bad_msg(drv_data);
+			/* Never fail */
+			return IRQ_HANDLED;
+		}
+
+		ret |= drv_data->transfer_handler(drv_data);

Mmm that looks weird to me, oring a irqreturn.

Not really an uncommon pattern, though.

Quoted 5 lines

Imagine that on first iteration the handler returns IRQ_NONE, and on second IRQ_HANDLED. This makes ret IRQ_HANDLED. Yet after the first iteration the handler should have exited, especially if the interrupt is shared with another driver.

That would be a bug in transfer_handler, because we don't enter it without a reason (status != 0).

Quoted 6 lines

Another thing which is along what Andy already said : it would be better practice to have this loop in the form :
do {
...
} while (exit_condition_not_met);

This implies code duplication in order to calculate the condition (mask...). I can do this if desired, I wouldn't do this to my own code, though.

Jan

Quoted 7 lines

Just for maintainability, it's better, and it concentrates the test on the "exit_condition_not_met" in one place, which will enable us to review better the algorithm.

Cheers.

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA ITP SES-DE
Corporate Competence Center Embedded Linux
author
#23 lore raw

Re: [PATCH v2 2/3] spi: pxa2xx: Prepare for edge-triggered interrupts

In reply to Robert Jarzmik
Quoted 14 lines · Robert Jarzmik
Quoted 9 lines · Jan Kiszka

When using the a device with edge-triggered interrupts, such as MSIs, the interrupt handler has to ensure that there is a point in time during its execution where all interrupts sources are silent so that a new event can trigger a new interrupt again.

This is achieved here by looping over SSSR evaluation. We need to take into account that SSCR1 may be changed by the transfer handler, thus we need to redo the mask calculation, at least regarding the volatile interrupt enable bit (TIE).

I'd like moreover to add a question here.

Quoted 8 lines

In pxa architecture, SPI interrupts are already edge-triggered, and it's working well. The interrupt source disabling is not disabled, but the interrupt controller doesn't trigger an interrupt anymore (as it is masked), yet it marks it as pending if an interrupt arrives while the interrupt handler is running.

All of this is handled by the interrupt core. My question is why for Intel MSI's is it necessary to make a change in the driver instead or relying on the interrupt core as for the pxa ?

If someone was using this driver with edge-triggered interrupt sources so far, it was probably slower hardware and some luck (I've seen this when driving fast-clocked devices vs. slower ones - only the latter exposed the bug). Or that hardware did some temporary masking at interrupt controller level while the handler was running. But that is also not by design. It's the driver's task to ensure that all interrupt sources are addressed once when returning from an edge-triggered handler, and that is missing in this one.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA ITP SES-DE
Corporate Competence Center Embedded Linux
Reviewed-by
#28 lore raw

Re: [PATCH v2 3/3] spi: pca2xx-pci: Allow MSI

In reply to Andy Shevchenko
Quoted 9 lines · Andy Shevchenko
Quoted 5 lines · Jan Kiszka

Now that the core is ready for edge-triggered interrupts, we can safely
allow the PCI versions that provide this to enable the feature and, thus, have less shared interrupts.

I was looking at is there need to call pci_free_irq_vectors() but pcim_release() takes care of that since this driver uses pcim_enable_device().

#24 lore raw

Re: [PATCH v2 2/3] spi: pxa2xx: Prepare for edge-triggered interrupts

In reply to Jan Kiszka
Quoted 24 lines · Jan Kiszka
Quoted 14 lines · Robert Jarzmik
Quoted 9 lines · Jan Kiszka

When using the a device with edge-triggered interrupts, such as MSIs, the interrupt handler has to ensure that there is a point in time during its execution where all interrupts sources are silent so that a new event can trigger a new interrupt again.

This is achieved here by looping over SSSR evaluation. We need to take into account that SSCR1 may be changed by the transfer handler, thus we need to redo the mask calculation, at least regarding the volatile interrupt enable bit (TIE).

I'd like moreover to add a question here.

Quoted 8 lines

In pxa architecture, SPI interrupts are already edge-triggered, and it's working well. The interrupt source disabling is not disabled, but the interrupt controller doesn't trigger an interrupt anymore (as it is masked), yet it marks it as pending if an interrupt arrives while the interrupt handler is running.

All of this is handled by the interrupt core. My question is why for Intel MSI's is it necessary to make a change in the driver instead or relying on the interrupt core as for the pxa ?

Quoted 9 lines

If someone was using this driver with edge-triggered interrupt sources so far, it was probably slower hardware and some luck (I've seen this when driving fast-clocked devices vs. slower ones - only the latter exposed the bug). Or that hardware did some temporary masking at interrupt controller level while the handler was running. But that is also not by design. It's the driver's task to ensure that all interrupt sources are addressed once when returning from an edge-triggered handler, and that is missing in this one.

Are you seeing actual problem here or adding loop just in case? Is it really so that PCI bridge doesn't generate another MSI interrupt if SPI controller has interrupt pending when handler returns? I don't know but I would expect irq line between SPI controller and PCI bridge is still level sensitive even PCI bridge issues MSIs to the CPU.

Signature · 1 line
Jarkko
author
#25 lore raw

Re: [PATCH v2 2/3] spi: pxa2xx: Prepare for edge-triggered interrupts

Quoted 39 lines · Jarkko Nikula
Quoted 29 lines · Jan Kiszka
Quoted 23 lines · Robert Jarzmik
Quoted 10 lines · Jan Kiszka

When using the a device with edge-triggered interrupts, such as MSIs, the interrupt handler has to ensure that there is a point in time during
its execution where all interrupts sources are silent so that a new event can trigger a new interrupt again.

This is achieved here by looping over SSSR evaluation. We need to take into account that SSCR1 may be changed by the transfer handler, thus we need to redo the mask calculation, at least regarding the volatile interrupt enable bit (TIE).

I'd like moreover to add a question here.

In pxa architecture, SPI interrupts are already edge-triggered, and it's working
well. The interrupt source disabling is not disabled, but the interrupt controller doesn't trigger an interrupt anymore (as it is masked), yet it marks
it as pending if an interrupt arrives while the interrupt handler is running.

Quoted 4 lines

All of this is handled by the interrupt core. My question is why for Intel MSI's
is it necessary to make a change in the driver instead or relying on the interrupt core as for the pxa ?

Quoted 9 lines

If someone was using this driver with edge-triggered interrupt sources so far, it was probably slower hardware and some luck (I've seen this when driving fast-clocked devices vs. slower ones - only the latter exposed the bug). Or that hardware did some temporary masking at interrupt controller level while the handler was running. But that is also not by design. It's the driver's task to ensure that all interrupt sources are addressed once when returning from an edge-triggered handler, and that is missing in this one.

Quoted 6 lines

Are you seeing actual problem here or adding loop just in case? Is it really so that PCI bridge doesn't generate another MSI interrupt if SPI controller has interrupt pending when handler returns? I don't know but I would expect irq line between SPI controller and PCI bridge is still level sensitive even PCI bridge issues MSIs to the CPU.

Yes, I'm seeing real problems, e.g. on the Galileo board when running against a slower SPI device and using MSI: An interrupt is raised because the TX queue was flushed towards the device (threshold underrun). While handling that interrupt, the device starts to respond and an RX event occurs as well. This raises the related interrupt reason before the TX source was satisfied. Therefore, the interrupt output of the SPI master will never go down, and there will be no additional edge generated. Using level-interrupts, this is no problem, but with edge-triggered we get stuck.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA ITP SES-DE
Corporate Competence Center Embedded Linux
maintainer
#3 lore raw

Applied "spi: pxa2xx: Factor out handle_bad_msg" to the spi tree

In reply to Jan Kiszka

The patch

spi: pxa2xx: Factor out handle_bad_msg

has been applied to the spi tree at

git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

Quoted 1 line

From b03124825b8612bf371e5b4ccc2cd812ed3c2dbb Mon Sep 17 00:00:00 2001

From: Jan Kiszka <[email protected]>
Date: Mon, 16 Jan 2017 19:44:54 +0100
Subject: [PATCH] spi: pxa2xx: Factor out handle_bad_msg

As suggested by Andy Shevchenko: Decouple this corner cause from the general handling logic in ssp_int.

---
 drivers/spi/spi-pxa2xx.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
drivers/spi/spi-pxa2xx.c +15 -14
index d6239fa718be..8c65bc1823f3 100644
@@ -732,6 +732,20 @@ static irqreturn_t interrupt_transfer(struct driver_data *drv_data)
 	return IRQ_HANDLED;
 }
 
+static void handle_bad_msg(struct driver_data *drv_data)
+{
+	pxa2xx_spi_write(drv_data, SSCR0,
+			 pxa2xx_spi_read(drv_data, SSCR0) & ~SSCR0_SSE);
+	pxa2xx_spi_write(drv_data, SSCR1,
+			 pxa2xx_spi_read(drv_data, SSCR1) & ~drv_data->int_cr1);
+	if (!pxa25x_ssp_comp(drv_data))
+		pxa2xx_spi_write(drv_data, SSTO, 0);
+	write_SSSR_CS(drv_data, drv_data->clear_sr);
+
+	dev_err(&drv_data->pdev->dev,
+		"bad message state in interrupt handler\n");
+}
+
 static irqreturn_t ssp_int(int irq, void *dev_id)
 {
 	struct driver_data *drv_data = dev_id;
@@ -772,20 +786,7 @@ static irqreturn_t ssp_int(int irq, void *dev_id)
 		return IRQ_NONE;
 
 	if (!drv_data->master->cur_msg) {
-
-		pxa2xx_spi_write(drv_data, SSCR0,
-				 pxa2xx_spi_read(drv_data, SSCR0)
-				 & ~SSCR0_SSE);
-		pxa2xx_spi_write(drv_data, SSCR1,
-				 pxa2xx_spi_read(drv_data, SSCR1)
-				 & ~drv_data->int_cr1);
-		if (!pxa25x_ssp_comp(drv_data))
-			pxa2xx_spi_write(drv_data, SSTO, 0);
-		write_SSSR_CS(drv_data, drv_data->clear_sr);
-
-		dev_err(&drv_data->pdev->dev,
-			"bad message state in interrupt handler\n");
-
+		handle_bad_msg(drv_data);
 		/* Never fail */
 		return IRQ_HANDLED;
 	}
Signature · 1 line
2.11.0
author
#7 lore raw

Re: [PATCH v2 2/3] spi: pxa2xx: Prepare for edge-triggered interrupts

In reply to Jan Kiszka
Quoted 117 lines · Jan Kiszka
Quoted 27 lines · Andy Shevchenko
Quoted 6 lines · Jan Kiszka

When using the a device with edge-triggered interrupts, such as MSIs, the interrupt handler has to ensure that there is a point in time during
its execution where all interrupts sources are silent so that a new event can trigger a new interrupt again.

Quoted 6 lines

This is achieved here by looping over SSSR evaluation. We need to take into account that SSCR1 may be changed by the transfer handler, thus we
need to redo the mask calculation, at least regarding the volatile interrupt enable bit (TIE).

So, more comments/questions below.

Quoted 11 lines
drivers/spi/spi-pxa2xx.c +0 -4
 	sccr1_reg = pxa2xx_spi_read(drv_data, SSCR1);
 
-	/* Ignore possible writes if we don't need to write */
-	if (!(sccr1_reg & SSCR1_TIE))
-		mask &= ~SSSR_TFS;
-
 	/* Ignore RX timeout interrupt if it is disabled */
 	if (!(sccr1_reg & SSCR1_TINTE))
 		mask &= ~SSSR_TINT;
Quoted 5 lines

drivers/spi/spi-pxa2xx.c static irqreturn_t ssp_int(int irq, void *dev_id) · line 782

Quoted 3 lines
drivers/spi/spi-pxa2xx.c +1 -2
-	if (!(status & mask))
-		return IRQ_NONE;
+	while (1) {

Can we switch to do-while and move previous block here?

Don't see how this would help (without duplicating more code).

Quoted 2 lines

Btw, can TINTE
bit be set again during a loop?

Nope, it's statically set, at least so far.

What we could do is simply restarting ssp_int

Quoted 21 lines
Quoted 20 lines
(quoted diff) +1 -0
+		/* Ignore possible writes if we don't need to write

*/

drivers/spi/spi-pxa2xx.c +11 -5
+		if (!(sccr1_reg & SSCR1_TIE))
+			mask &= ~SSSR_TFS;
 
-	if (!drv_data->master->cur_msg) {
-		handle_bad_msg(drv_data);
-		/* Never fail */
-		return IRQ_HANDLED;
-	}
+		if (!(status & mask))
+			return ret;
+
+		if (!drv_data->master->cur_msg) {
+			handle_bad_msg(drv_data);
+			/* Never fail */
+			return IRQ_HANDLED;
+		}
+
Quoted 4 lines

drivers/spi/spi-pxa2xx.c static irqreturn_t ssp_int(int irq, void *dev_id) · line 796

Quoted 1 line
drivers/spi/spi-pxa2xx.c +1 -0
+		ret |= drv_data->transfer_handler(drv_data);

So, we might call handler several times. This needs to be commented in the code why you do so.

I can move the commit log into the code.

Quoted 8 lines

drivers/spi/spi-pxa2xx.c static irqreturn_t ssp_int(int irq, void *dev_id) · line 798

Quoted 4 lines
drivers/spi/spi-pxa2xx.c +1 -1
-	return drv_data->transfer_handler(drv_data);
+		status = pxa2xx_spi_read(drv_data, SSSR);

Would it be possible to get all 1:s from the register (something/autosuspend just powered off it by timeout?) ?

Not sure if that can happen, but I guess it would be simpler and more readable to simply do this instead:

	while (1) {
		/*
		 * If the device is not yet in RPM suspended state and we get an
		 * interrupt that is meant for another device, check if status
		 * bits are all set to one. That means that the device is
		 * already powered off.
		 */
		status = pxa2xx_spi_read(drv_data, SSSR);
		if (status == ~0)
			return ret;

		sccr1_reg = pxa2xx_spi_read(drv_data, SSCR1);

		/* Ignore RX timeout interrupt if it is disabled */
		if (!(sccr1_reg & SSCR1_TINTE))
			mask &= ~SSSR_TINT;

		/* Ignore possible writes if we don't need to write */
		if (!(sccr1_reg & SSCR1_TIE))
			mask &= ~SSSR_TFS;

		if (!(status & mask))
			return ret;

		if (!drv_data->master->cur_msg) {
			handle_bad_msg(drv_data);
			/* Never fail */
			return IRQ_HANDLED;
		}

		ret |= drv_data->transfer_handler(drv_data);
	}
Quoted 2 lines

i.e. preserve the current structure, just add the loop.

OK, please let me know if you want a v3 of this patch with the structure above. If there are further concerns/questions, just let me know as well, but I'd like to close this topic if possible.

Thanks,
Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA ITP SES-DE
Corporate Competence Center Embedded Linux
maintainer
#10 lore raw

Re: [PATCH v2 2/3] spi: pxa2xx: Prepare for edge-triggered interrupts

In reply to Jan Kiszka
Quoted 21 lines · Jan Kiszka
Quoted 20 lines · Robert Jarzmik
Quoted 11 lines · Jan Kiszka

When using the a device with edge-triggered interrupts, such as MSIs, the interrupt handler has to ensure that there is a point in time during its execution where all interrupts sources are silent so that a new event can trigger a new interrupt again.

This is achieved here by looping over SSSR evaluation. We need to take into account that SSCR1 may be changed by the transfer handler, thus we need to redo the mask calculation, at least regarding the volatile interrupt enable bit (TIE).

Hi Jan,

drivers/spi/spi-pxa2xx.c static irqreturn_t ssp_int(int irq, void *dev_id) · line 782

Quoted 1 line
drivers/spi/spi-pxa2xx.c +1 -0
+	while (1) {

This bit worries me a bit, as this can be either :
- hogging the SoC's CPU, endlessly running
- or even worse, blocking the CPU for ever

Quoted 7 lines
Quoted 2 lines

The question behind is, should this be done in a top-half, or moved to a irq thread ?

Every device with a broken interrupt source can hog CPUs, nothing special with this one. If you don't close the loop in the handler itself, you close it over the hardware retriggering the interrupt over and over again.

I'm not speaking of a broken interrupt source, I'm speaking of a broken code, such as in the handler, or broken status readback, or lack of understanding on the status register which may imply the while(1) to loop forever.

Quoted 3 lines

So, I don't see a point in offloading to a thread. The normal case is some TX done (FIFO available) event followed by an RX event, then the transfer is complete, isn't it?

The point is if you stay forever in the while(1) loop, you can at least have a print a backtrace (LOCKUP_DETECTOR).

Quoted 7 lines
Quoted 4 lines

Imagine that on first iteration the handler returns IRQ_NONE, and on second IRQ_HANDLED. This makes ret IRQ_HANDLED. Yet after the first iteration the handler should have exited, especially if the interrupt is shared with another driver.

That would be a bug in transfer_handler, because we don't enter it without a reason (status != 0).

Sure, but can you be sure that all the people modifying the code after you will see that also ? The other way will _force_ them to see it.

Quoted 9 lines
Quoted 5 lines

Another thing which is along what Andy already said : it would be better practice to have this loop in the form :
do {
...
} while (exit_condition_not_met);

This implies code duplication in order to calculate the condition (mask...). I can do this if desired, I wouldn't do this to my own code, though.

Okay, that's acceptable.
Why not have something like this :

sccr1_reg = pxa2xx_spi_read(drv_data, SSCR1);
if (!(sccr1_reg & SSCR1_TIE))

	mask &= ~SSSR_TFS;

/* Ignore RX timeout interrupt if it is disabled */ if (!(sccr1_reg & SSCR1_TINTE))

	mask &= ~SSSR_TINT;

status = pxa2xx_spi_read(drv_data, SSR);
while (status & mask) {
... handlers etc ...
status = pxa2xx_spi_read(drv_data, SSR);
};

There is a duplication of the status read, but that looks acceptable, and the mask calculation is moved out of the loop (this should be checked more thoroughly as it looked to me only probe() would change these values, yet I might be wrong).

Cheers.

Signature · 1 line
Robert
author
#11 lore raw

Re: [PATCH v2 2/3] spi: pxa2xx: Prepare for edge-triggered interrupts

Quoted 34 lines · Robert Jarzmik
Quoted 21 lines · Jan Kiszka
Quoted 20 lines · Robert Jarzmik
Quoted 11 lines · Jan Kiszka

When using the a device with edge-triggered interrupts, such as MSIs, the interrupt handler has to ensure that there is a point in time during its execution where all interrupts sources are silent so that a new event can trigger a new interrupt again.

This is achieved here by looping over SSSR evaluation. We need to take into account that SSCR1 may be changed by the transfer handler, thus we need to redo the mask calculation, at least regarding the volatile interrupt enable bit (TIE).

Hi Jan,

drivers/spi/spi-pxa2xx.c static irqreturn_t ssp_int(int irq, void *dev_id) · line 782

Quoted 1 line
drivers/spi/spi-pxa2xx.c +1 -0
+	while (1) {

This bit worries me a bit, as this can be either :
- hogging the SoC's CPU, endlessly running
- or even worse, blocking the CPU for ever

Quoted 7 lines
Quoted 2 lines

The question behind is, should this be done in a top-half, or moved to a irq thread ?

Every device with a broken interrupt source can hog CPUs, nothing special with this one. If you don't close the loop in the handler itself, you close it over the hardware retriggering the interrupt over and over again.

I'm not speaking of a broken interrupt source, I'm speaking of a broken code, such as in the handler, or broken status readback, or lack of understanding on the status register which may imply the while(1) to loop forever.

Quoted 5 lines
Quoted 3 lines

So, I don't see a point in offloading to a thread. The normal case is some TX done (FIFO available) event followed by an RX event, then the transfer is complete, isn't it?

The point is if you stay forever in the while(1) loop, you can at least have a print a backtrace (LOCKUP_DETECTOR).

I won't consider "debugability" as a good reason to move interrupt handlers into threads. There should be real workload that requires offloading or specific prioritization.

Quoted 37 lines
Quoted 8 lines
Quoted 5 lines

Imagine that on first iteration the handler returns IRQ_NONE, and on second IRQ_HANDLED. This makes ret IRQ_HANDLED. Yet after the first iteration the handler should have exited, especially if the interrupt is shared with another driver.

That would be a bug in transfer_handler, because we don't enter it without a reason (status != 0).

Sure, but can you be sure that all the people modifying the code after you will see that also ? The other way will _force_ them to see it.

Quoted 9 lines
Quoted 5 lines

Another thing which is along what Andy already said : it would be better practice to have this loop in the form :
do {
...
} while (exit_condition_not_met);

This implies code duplication in order to calculate the condition (mask...). I can do this if desired, I wouldn't do this to my own code, though.

Okay, that's acceptable.
Why not have something like this :

sccr1_reg = pxa2xx_spi_read(drv_data, SSCR1);
if (!(sccr1_reg & SSCR1_TIE))

	mask &= ~SSSR_TFS;

/* Ignore RX timeout interrupt if it is disabled */ if (!(sccr1_reg & SSCR1_TINTE))

	mask &= ~SSSR_TINT;

status = pxa2xx_spi_read(drv_data, SSR);

while (status & mask) {
   ... handlers etc ...
   status = pxa2xx_spi_read(drv_data, SSR);
};
Quoted 4 lines

There is a duplication of the status read, but that looks acceptable, and the mask calculation is moved out of the loop (this should be checked more thoroughly as it looked to me only probe() would change these values, yet I might be wrong).

Unfortunately, mask can change if SSCR1_TIE is cleared. So this is not correct.

What would be an alternative to looping is masking (would be required for threaded irq anyway - but then we won't need to loop in the first place): disable all irq sources, check the status bits once, re-enable according to a potentially updated set, leave the handler and let the hardware call us again.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA ITP SES-DE
Corporate Competence Center Embedded Linux
maintainer
#12 lore raw

Re: [PATCH v2 2/3] spi: pxa2xx: Prepare for edge-triggered interrupts

Quoted 24 lines · Jan Kiszka
Quoted 21 lines · Robert Jarzmik
Quoted 6 lines
Quoted 5 lines

drivers/spi/spi-pxa2xx.c static irqreturn_t ssp_int(int irq, void *dev_id) · line 782

Quoted 1 line
drivers/spi/spi-pxa2xx.c +1 -0
+	while (1) {

This bit worries me a bit, as this can be either :
- hogging the SoC's CPU, endlessly running
- or even worse, blocking the CPU for ever

Quoted 7 lines
Quoted 2 lines

The question behind is, should this be done in a top-half, or moved to a irq thread ?

Every device with a broken interrupt source can hog CPUs, nothing special with this one. If you don't close the loop in the handler itself, you close it over the hardware retriggering the interrupt over and over again.

I'm not speaking of a broken interrupt source, I'm speaking of a broken code, such as in the handler, or broken status readback, or lack of understanding on the status register which may imply the while(1) to loop forever.

Quoted 3 lines

So, I don't see a point in offloading to a thread. The normal case is some TX done (FIFO available) event followed by an RX event, then the transfer is complete, isn't it?

Quoted 6 lines
Quoted 2 lines

The point is if you stay forever in the while(1) loop, you can at least have a print a backtrace (LOCKUP_DETECTOR).

I won't consider "debugability" as a good reason to move interrupt handlers into threads. There should be real workload that requires offloading or specific prioritization.

It's failure mitigation - you're translating a hard lockup into
something that will potentially allow the system to soldier on which is
likely to be less severe for the user as well as making things easier to
figure out. If we're doing something like this I'd at least have a
limit on how long we allow the interrupt to scream.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170118/2d8e46dd/attachment-0001.sig>

author
#13 lore raw

Re: [PATCH v2 2/3] spi: pxa2xx: Prepare for edge-triggered interrupts

Quoted 32 lines · Mark Brown
Quoted 24 lines · Jan Kiszka
Quoted 21 lines · Robert Jarzmik
Quoted 6 lines
Quoted 5 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	while (1) {

This bit worries me a bit, as this can be either :
- hogging the SoC's CPU, endlessly running
- or even worse, blocking the CPU for ever

Quoted 7 lines
Quoted 2 lines

The question behind is, should this be done in a top-half, or moved to a irq thread ?

Every device with a broken interrupt source can hog CPUs, nothing special with this one. If you don't close the loop in the handler itself, you close it over the hardware retriggering the interrupt over and over again.

I'm not speaking of a broken interrupt source, I'm speaking of a broken code, such as in the handler, or broken status readback, or lack of understanding on the status register which may imply the while(1) to loop forever.

Quoted 3 lines

So, I don't see a point in offloading to a thread. The normal case is some TX done (FIFO available) event followed by an RX event, then the transfer is complete, isn't it?

Quoted 6 lines
Quoted 2 lines

The point is if you stay forever in the while(1) loop, you can at least have a print a backtrace (LOCKUP_DETECTOR).

I won't consider "debugability" as a good reason to move interrupt handlers into threads. There should be real workload that requires offloading or specific prioritization.

Quoted 6 lines

It's failure mitigation - you're translating a hard lockup into something that will potentially allow the system to soldier on which is likely to be less severe for the user as well as making things easier to figure out. If we're doing something like this I'd at least have a limit on how long we allow the interrupt to scream.

OK, OK, if that is the biggest worry, I can change the pattern from loop-based to SCCR1-based, i.e. mask all interrupt sources once per interrupt so that we enforce a falling edge. Fine.

But now I'm looking at the driver, wondering who all is fiddling under which conditions with SCCR1. There are a lot of RMW patterns, but I do not see the locking pattern behind that. Are all RMW accesses run only in the interrupt handler context? Unlikely, at least with the dmaengine in the loop.

Closing my eyes regarding this potential issue for now, the patch could become as simple as

drivers/spi/spi-pxa2xx.c +3 -0
index 0d10090..f9c2329 100644
@@ -785,6 +785,9 @@ static irqreturn_t ssp_int(int irq, void *dev_id)
 	if (!(status & mask))
 		return IRQ_NONE;
 
+	pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg & ~drv_data->int_cr1);
+	pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg);
+
 	if (!drv_data->master->cur_msg) {
 		handle_bad_msg(drv_data);
 		/* Never fail */

Not efficient /wrt register accesses, but that's apparently not yet a design goal anyway (I stumbled over the SSCR1 locking while considering to introduce a cache for that reg).

Jan

Signature · 10 lines
Siemens AG, Corporate Technology, CT RDA ITP SES-DE
Corporate Competence Center Embedded Linux

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170119/85442b92/attachment.sig>
author
#14 lore raw

PATCH v3 2/3 spi: pxa2xx: Prepare for edge-triggered interrupts

When using the a device with edge-triggered interrupts, such as MSIs, the interrupt handler has to ensure that there is a point in time during its execution where all interrupts sources are silent so that a new event can trigger a new interrupt again.

This is achieved here by disabling all interrupt sources for a moment before processing them according to the status register. If a new interrupt should have arrived after we read the status, it will now re-trigger the interrupt, even in edge mode.

---

Successfully tested by now.

Changes to v2:
- avoid inner looping by making the hardware retrigger on "forgotten" IRQ sources

 drivers/spi/spi-pxa2xx.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/spi/spi-pxa2xx.c +3 -0
index 0d10090..f9c2329 100644
@@ -785,6 +785,9 @@ static irqreturn_t ssp_int(int irq, void *dev_id)
 	if (!(status & mask))
 		return IRQ_NONE;
 
+	pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg & ~drv_data->int_cr1);
+	pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg);
+
 	if (!drv_data->master->cur_msg) {
 		handle_bad_msg(drv_data);
 		/* Never fail */
Signature · 9 lines
2.1.4

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170119/035bfd45/attachment.sig>
maintainer
#15 lore raw

Re: [PATCH v3 2/3] spi: pxa2xx: Prepare for edge-triggered interrupts

Quoted 2 lines · Jan Kiszka

When using the a device with edge-triggered interrupts, such as MSIs, the interrupt handler has to ensure that there is a point in time during

I'm missing patches 1 and 3, what's going on here?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170119/a869a866/attachment.sig>

#16 lore raw

Re: [PATCH v3 2/3] spi: pxa2xx: Prepare for edge-triggered interrupts

Quoted 7 lines · Mark Brown
Quoted 4 lines · Jan Kiszka

When using the a device with edge-triggered interrupts, such as MSIs,
the interrupt handler has to ensure that there is a point in time during

I'm missing patches 1 and 3, what's going on here?

Patch 1 had been applied by you. I think Jan just needs to resend with proper version and set of patches.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
maintainer Acked-by on v3 2/3
#20 lore raw

Re: [PATCH v3 2/3] spi: pxa2xx: Prepare for edge-triggered interrupts

In reply to Jan Kiszka
Quoted 11 lines · Jan Kiszka

When using the a device with edge-triggered interrupts, such as MSIs, the interrupt handler has to ensure that there is a point in time during its execution where all interrupts sources are silent so that a new event can trigger a new interrupt again.

This is achieved here by disabling all interrupt sources for a moment before processing them according to the status register. If a new interrupt should have arrived after we read the status, it will now re-trigger the interrupt, even in edge mode.

Cheers.

--
Robert

maintainer
#17 lore raw

Re: [PATCH v3 2/3] spi: pxa2xx: Prepare for edge-triggered interrupts

In reply to Andy Shevchenko
Quoted 6 lines · Andy Shevchenko
Quoted 1 line · Mark Brown

I'm missing patches 1 and 3, what's going on here?

Patch 1 had been applied by you. I think Jan just needs to resend with proper version and set of patches.

OK - Jan, the purpose of numbering patches in a series is so we can tell
what order they come in. That's it. If the set of patches gets changed
due to things being added or removed the numbers will be different but
that's totally OK as their only relevance is in ordering things within a
given posting.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170120/f665f095/attachment.sig>

author
#18 lore raw

Re: [PATCH v3 2/3] spi: pxa2xx: Prepare for edge-triggered interrupts

Quoted 5 lines · Mark Brown
Quoted 3 lines · Andy Shevchenko
Quoted 1 line · Mark Brown

I'm missing patches 1 and 3, what's going on here?

Quoted 8 lines
Quoted 2 lines

Patch 1 had been applied by you. I think Jan just needs to resend with proper version and set of patches.

OK - Jan, the purpose of numbering patches in a series is so we can tell what order they come in. That's it. If the set of patches gets changed due to things being added or removed the numbers will be different but that's totally OK as their only relevance is in ordering things within a given posting.

Sorry if the numbering was confusing for you, it was, of course, a selective update. Just tell me, if you need a new round with of patches 2 and 3 (as 1 and 2).

Jan

Signature · 10 lines
Siemens AG, Corporate Technology, CT RDA ITP SES-DE
Corporate Competence Center Embedded Linux

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170120/df5a6ba9/attachment-0001.sig>
maintainer
#19 lore raw

Re: [PATCH v3 2/3] spi: pxa2xx: Prepare for edge-triggered interrupts

Quoted 3 lines · Jan Kiszka

Sorry if the numbering was confusing for you, it was, of course, a selective update. Just tell me, if you need a new round with of patches 2 and 3 (as 1 and 2).

Please resend.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170120/735ab402/attachment.sig>

maintainer
#29 lore raw

Applied "spi: pca2xx-pci: Allow MSI" to the spi tree

In reply to Jan Kiszka

The patch

spi: pca2xx-pci: Allow MSI

has been applied to the spi tree at

git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

Quoted 1 line

From 64e02cb0bdfc7cef0a01e2ad4d567fdc0a74450e Mon Sep 17 00:00:00 2001

From: Jan Kiszka <[email protected]>
Date: Sat, 21 Jan 2017 10:06:39 +0100
Subject: [PATCH] spi: pca2xx-pci: Allow MSI

Now that the core is ready for edge-triggered interrupts, we can safely allow the PCI versions that provide this to enable the feature and, thus, have less shared interrupts.

---
 drivers/spi/spi-pxa2xx-pci.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/spi/spi-pxa2xx-pci.c +7 -1
index 868452d8e3e1..869f188b02eb 100644
@@ -227,10 +227,16 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev,
 	ssp = &spi_pdata.ssp;
 	ssp->phys_base = pci_resource_start(dev, 0);
 	ssp->mmio_base = pcim_iomap_table(dev)[0];
-	ssp->irq = dev->irq;
 	ssp->port_id = (c->port_id >= 0) ? c->port_id : dev->devfn;
 	ssp->type = c->type;
 
+	pci_set_master(dev);
+
+	ret = pci_alloc_irq_vectors(dev, 1, 1, PCI_IRQ_ALL_TYPES);
+	if (ret < 0)
+		return ret;
+	ssp->irq = pci_irq_vector(dev, 0);
+
 	snprintf(buf, sizeof(buf), "pxa2xx-spi.%d", ssp->port_id);
 	ssp->clk = clk_register_fixed_rate(&dev->dev, buf , NULL, 0,
 					   c->max_clk_rate);
Signature · 1 line
2.11.0
maintainer
#21 lore raw

Applied "spi: pxa2xx: Prepare for edge-triggered interrupts" to the spi tree

In reply to Jan Kiszka

The patch

spi: pxa2xx: Prepare for edge-triggered interrupts

has been applied to the spi tree at

git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

Quoted 1 line

From e51e9b93049f624c179bab2c651995bca22b5bb7 Mon Sep 17 00:00:00 2001

From: Jan Kiszka <[email protected]>
Date: Sat, 21 Jan 2017 10:06:38 +0100
Subject: [PATCH] spi: pxa2xx: Prepare for edge-triggered interrupts

When using the a device with edge-triggered interrupts, such as MSIs, the interrupt handler has to ensure that there is a point in time during its execution where all interrupts sources are silent so that a new event can trigger a new interrupt again.

This is achieved here by disabling all interrupt sources for a moment before processing them according to the status register. If a new interrupt should have arrived after we read the status, it will now re-trigger the interrupt, even in edge mode.

---
 drivers/spi/spi-pxa2xx.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/spi/spi-pxa2xx.c +3 -0
index 8c65bc1823f3..06ade434c083 100644
@@ -785,6 +785,9 @@ static irqreturn_t ssp_int(int irq, void *dev_id)
 	if (!(status & mask))
 		return IRQ_NONE;
 
+	pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg & ~drv_data->int_cr1);
+	pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg);
+
 	if (!drv_data->master->cur_msg) {
 		handle_bad_msg(drv_data);
 		/* Never fail */
Signature · 1 line
2.11.0