Skip to contentSkip to conversation

i2c: aspeed: Acknowledge most interrupts early in interrupt handler

PATCH Applied Guenter Roeck 5 participants 8 messages Sep 14, 2018 – Sep 24, 2018

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

PATCH 1/1 i2c: aspeed: Acknowledge most interrupts early in interrupt handler

Commit 3e9efc3299dd ("i2c: aspeed: Handle master/slave combined irq events properly") moved interrupt acknowledgment to the end of the interrupt handler. In part this was done because the AST2500 datasheet says:

I2CD10 Interrupt Status Register
bit 2 Receive Done Interrupt status
S/W needs to clear this status bit to allow next data receiving.

Acknowledging Receive Done before receive data was handled resulted in receive errors on high speed I2C busses.

However, interrupt acknowledgment was not only moved to the end of the interrupt handler for Receive Done Interrupt status, but for all interrupt status bits. This could result in race conditions if a second interrupt was received during interrupt handling and not handled but still acknowledged at the end of the interrupt handler.

Acknowledge only "Receive Done Interrupt status" late in the interrupt handler to solve the problem.

Fixes 3e9efc3299dd ("i2c: aspeed: Handle master/slave combined irq events properly")
Cc Jae Hyun Yoo <[email protected]>
Cc Joel Stanley <[email protected]>
---
 drivers/i2c/busses/i2c-aspeed.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-aspeed.c +7 -2
index c258c4d9a4c0..3d518e09369f 100644
@@ -552,6 +552,9 @@ static irqreturn_t aspeed_i2c_bus_irq(int irq, void *dev_id)
 
 	spin_lock(&bus->lock);
 	irq_received = readl(bus->base + ASPEED_I2C_INTR_STS_REG);
+	/* Ack all interrupts except for Rx done */
+	writel(irq_received & ~ASPEED_I2CD_INTR_RX_DONE,
+	       bus->base + ASPEED_I2C_INTR_STS_REG);
 	irq_remaining = irq_received;
 
 #if IS_ENABLED(CONFIG_I2C_SLAVE)
@@ -584,8 +587,10 @@ static irqreturn_t aspeed_i2c_bus_irq(int irq, void *dev_id)
 			"irq handled != irq. expected 0x%08x, but was 0x%08x\n",
 			irq_received, irq_handled);
 
-	/* Ack all interrupt bits. */
-	writel(irq_received, bus->base + ASPEED_I2C_INTR_STS_REG);
+	/* Ack Rx done */
+	if (irq_received & ASPEED_I2CD_INTR_RX_DONE)
+		writel(ASPEED_I2CD_INTR_RX_DONE,
+		       bus->base + ASPEED_I2C_INTR_STS_REG);
 	spin_unlock(&bus->lock);
 	return irq_remaining ? IRQ_NONE : IRQ_HANDLED;
 }
Signature · 1 line
2.7.4
Acked-by on v1 1/1
#1 lore raw
Quoted 46 lines · Guenter Roeck

Commit 3e9efc3299dd ("i2c: aspeed: Handle master/slave combined irq events properly") moved interrupt acknowledgment to the end of the interrupt handler. In part this was done because the AST2500 datasheet says:

I2CD10 Interrupt Status Register
bit 2 Receive Done Interrupt status
S/W needs to clear this status bit to allow next data receiving.

Acknowledging Receive Done before receive data was handled resulted in receive errors on high speed I2C busses.

However, interrupt acknowledgment was not only moved to the end of the interrupt handler for Receive Done Interrupt status, but for all interrupt status bits. This could result in race conditions if a second interrupt was received during interrupt handling and not handled but still acknowledged at the end of the interrupt handler.

Acknowledge only "Receive Done Interrupt status" late in the interrupt handler to solve the problem.

Fixes 3e9efc3299dd ("i2c: aspeed: Handle master/slave combined irq events properly")
Cc Jae Hyun Yoo <[email protected]>
Cc Joel Stanley <[email protected]>
---
  drivers/i2c/busses/i2c-aspeed.c | 9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-aspeed.c +3 -0
index c258c4d9a4c0..3d518e09369f 100644
@@ -552,6 +552,9 @@ static irqreturn_t aspeed_i2c_bus_irq(int irq, void *dev_id)
 
  	spin_lock(&bus->lock);
  	irq_received = readl(bus->base + ASPEED_I2C_INTR_STS_REG);
+	/* Ack all interrupts except for Rx done */
+	writel(irq_received & ~ASPEED_I2CD_INTR_RX_DONE,
+	       bus->base + ASPEED_I2C_INTR_STS_REG);
  	irq_remaining = irq_received;
 
  #if IS_ENABLED(CONFIG_I2C_SLAVE)
@@ -584,8 +587,10 @@ static irqreturn_t aspeed_i2c_bus_irq(int irq, void *dev_id)
  			"irq handled != irq. expected 0x%08x, but was 0x%08x\n",
  			irq_received, irq_handled);

drivers/i2c/busses/i2c-aspeed.c static irqreturn_t aspeed_i2c_bus_irq(int irq, void *dev_id) · line 596

Quoted 10 lines
drivers/i2c/busses/i2c-aspeed.c +4 -2
 
-	/* Ack all interrupt bits. */
-	writel(irq_received, bus->base + ASPEED_I2C_INTR_STS_REG);
+	/* Ack Rx done */
+	if (irq_received & ASPEED_I2CD_INTR_RX_DONE)
+		writel(ASPEED_I2CD_INTR_RX_DONE,
+		       bus->base + ASPEED_I2C_INTR_STS_REG);
  	spin_unlock(&bus->lock);
  	return irq_remaining ? IRQ_NONE : IRQ_HANDLED;
  }

Looks good to me. Thanks! :)

#2 lore raw
Quoted 4 lines

Looks good to me. Thanks! :)

Does that mean I need to revert "[PATCH i2c-next v6] i2c: aspeed: Handle master/slave combined irq events properly" in i2c/for-next? And apply this to i2c/for-current?

(and please quote only relevat parts of a message when replying)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/linux-aspeed/attachments/20180917/7cb37b53/attachment.sig>

#3 lore raw
Quoted 11 lines · Wolfram Sang
Quoted 4 lines

Looks good to me. Thanks! :)

Does that mean I need to revert "[PATCH i2c-next v6] i2c: aspeed: Handle master/slave combined irq events properly" in i2c/for-next? And apply this to i2c/for-current?

(and please quote only relevat parts of a message when replying)

No need to revert "[PATCH i2c-next v6] i2c: aspeed: Handle master/slave combined irq events properly". This patch should be applied on top of the patch.

(Will reduce message size when replying. Thanks!)

Jae

#4 lore raw
Quoted 6 lines · Jae Hyun Yoo
Quoted 5 lines · Wolfram Sang
Quoted 4 lines

Looks good to me. Thanks! :)

Quoted 9 lines
Quoted 4 lines

Does that mean I need to revert "[PATCH i2c-next v6] i2c: aspeed: Handle master/slave combined irq events properly" in i2c/for-next? And apply this to i2c/for-current?

No need to revert "[PATCH i2c-next v6] i2c: aspeed: Handle master/slave combined irq events properly". This patch should be applied on top of the patch.

Yes, sorry, I should have tagged the patch as for-next.

Guenter

maintainer Tested-by on v1 1/1
#5 lore raw
In reply to Guenter Roeck
Quoted 18 lines · Guenter Roeck

Commit 3e9efc3299dd ("i2c: aspeed: Handle master/slave combined irq events properly") moved interrupt acknowledgment to the end of the interrupt handler. In part this was done because the AST2500 datasheet says:

I2CD10 Interrupt Status Register
bit 2 Receive Done Interrupt status
S/W needs to clear this status bit to allow next data receiving.

Acknowledging Receive Done before receive data was handled resulted in receive errors on high speed I2C busses.

However, interrupt acknowledgment was not only moved to the end of the interrupt handler for Receive Done Interrupt status, but for all interrupt status bits. This could result in race conditions if a second interrupt was received during interrupt handling and not handled but still acknowledged at the end of the interrupt handler.

Quoted 7 lines

Acknowledge only "Receive Done Interrupt status" late in the interrupt handler to solve the problem.

Fixes 3e9efc3299dd ("i2c: aspeed: Handle master/slave combined irq events properly")
Cc Jae Hyun Yoo <[email protected]>
Cc Joel Stanley <[email protected]>

Thanks for getting to the bottom of this Guenter. I gave it a spin on Romulus (ast2500) and Palmetto (ast2400) without issue.

Cheers,

Joel

#6 lore raw
Quoted 28 lines · Joel Stanley
Quoted 18 lines · Guenter Roeck

Commit 3e9efc3299dd ("i2c: aspeed: Handle master/slave combined irq events properly") moved interrupt acknowledgment to the end of the interrupt handler. In part this was done because the AST2500 datasheet says:

I2CD10 Interrupt Status Register
bit 2 Receive Done Interrupt status
S/W needs to clear this status bit to allow next data receiving.

Acknowledging Receive Done before receive data was handled resulted in receive errors on high speed I2C busses.

However, interrupt acknowledgment was not only moved to the end of the interrupt handler for Receive Done Interrupt status, but for all interrupt status bits. This could result in race conditions if a second interrupt was received during interrupt handling and not handled but still acknowledged at the end of the interrupt handler.

Quoted 7 lines

Acknowledge only "Receive Done Interrupt status" late in the interrupt handler to solve the problem.

Fixes 3e9efc3299dd ("i2c: aspeed: Handle master/slave combined irq events properly")
Cc Jae Hyun Yoo <[email protected]>
Cc Joel Stanley <[email protected]>
Quoted 5 lines

Thanks for getting to the bottom of this Guenter. I gave it a spin on Romulus (ast2500) and Palmetto (ast2400) without issue.

Nice work! Thanks!

Applied
#7 lore raw
In reply to Guenter Roeck
Quoted 17 lines · Guenter Roeck

Commit 3e9efc3299dd ("i2c: aspeed: Handle master/slave combined irq events properly") moved interrupt acknowledgment to the end of the interrupt handler. In part this was done because the AST2500 datasheet says:

I2CD10 Interrupt Status Register
bit 2 Receive Done Interrupt status
S/W needs to clear this status bit to allow next data receiving.

Acknowledging Receive Done before receive data was handled resulted in receive errors on high speed I2C busses.

However, interrupt acknowledgment was not only moved to the end of the interrupt handler for Receive Done Interrupt status, but for all interrupt status bits. This could result in race conditions if a second interrupt was received during interrupt handling and not handled but still acknowledged at the end of the interrupt handler.

Quoted 7 lines

Acknowledge only "Receive Done Interrupt status" late in the interrupt handler to solve the problem.

Fixes 3e9efc3299dd ("i2c: aspeed: Handle master/slave combined irq events properly")
Cc Jae Hyun Yoo <[email protected]>
Cc Joel Stanley <[email protected]>

Applied to for-next, thanks!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/linux-aspeed/attachments/20180924/6e8c62c7/attachment.sig>