Skip to contentSkip to conversation

Improvement and fix for HiSilicon I2C driver

PATCH Applied Yicong Yang 2 participants 5 messages Mar 13, 2023 – Mar 16, 2023

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

cover Improvement and fix for HiSilicon I2C driver

From: Yicong Yang <[email protected]>

This patchset includes 2 patches for 1) Improve the interrupt handling to avoid redundant interrupts and 2) fix the issue that on error case the completion is not handled and corrupt the next transfer.

Yicong Yang (2):
i2c: hisi: Avoid redundant interrupts
i2c: hisi: Only use the completion interrupt to finish the transfer

 drivers/i2c/busses/i2c-hisi.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
Signature · 1 line
2.24.0
#1 lore raw

PATCH 1/2 i2c: hisi: Avoid redundant interrupts

From: Yicong Yang <[email protected]>

After issuing all the messages we can disable the TX_EMPTY interrupts to avoid handling redundant interrupts. For doing a sinlge bus detection (i2cdetect -y -r 0) we can reduce ~97% interrupts (before ~12000 after ~400).

---
 drivers/i2c/busses/i2c-hisi.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/i2c/busses/i2c-hisi.c +7 -0
index 8c6c7075c765..1b7609a34f4a 100644
@@ -316,6 +316,13 @@ static void hisi_i2c_xfer_msg(struct hisi_i2c_controller *ctlr)
 		    max_write == 0)
 			break;
 	}
+
+	/*
+	 * Disable the TX_EMPTY interrupt after finishing all the messages to
+	 * avoid overwhelming the CPU.
+	 */
+	if (ctlr->msg_tx_idx == ctlr->msg_num)
+		hisi_i2c_disable_int(ctlr, HISI_I2C_INT_TX_EMPTY);
 }
 
 static irqreturn_t hisi_i2c_irq(int irq, void *context)
Signature · 1 line
2.24.0
Applied
#2 lore raw

Re: [PATCH 1/2] i2c: hisi: Avoid redundant interrupts

Quoted 10 lines · Yicong Yang

From: Yicong Yang <[email protected]>

After issuing all the messages we can disable the TX_EMPTY interrupts to avoid handling redundant interrupts. For doing a sinlge bus detection (i2cdetect -y -r 0) we can reduce ~97% interrupts (before ~12000 after ~400).

Applied to for-current, thanks!

#3 lore raw

PATCH 2/2 i2c: hisi: Only use the completion interrupt to finish the transfer

In reply to Yicong Yang

From: Yicong Yang <[email protected]>

The controller will always generate a completion interrupt when the transfer is finished normally or not. Currently we use either error or completion interrupt to finish, this may result the completion interrupt unhandled and corrupt the next transfer, especially at low speed mode. Since on error case, the error interrupt will come first then is the completion interrupt. So only use the completion interrupt to finish the whole transfer process.

Fixes d62fbdb99a85 ("i2c: add support for HiSilicon I2C controller")
---
 drivers/i2c/busses/i2c-hisi.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-hisi.c +5 -1
index 1b7609a34f4a..e067671b3ce2 100644
@@ -348,7 +348,11 @@ static irqreturn_t hisi_i2c_irq(int irq, void *context)
 		hisi_i2c_read_rx_fifo(ctlr);
 
 out:
-	if (int_stat & HISI_I2C_INT_TRANS_CPLT || ctlr->xfer_err) {
+	/*
+	 * Only use TRANS_CPLT to indicate the completion. On error cases we'll
+	 * get two interrupts, INT_ERR first then TRANS_CPLT.
+	 */
+	if (int_stat & HISI_I2C_INT_TRANS_CPLT) {
 		hisi_i2c_disable_int(ctlr, HISI_I2C_INT_ALL);
 		hisi_i2c_clear_int(ctlr, HISI_I2C_INT_ALL);
 		complete(ctlr->completion);
Signature · 1 line
2.24.0
Applied
#4 lore raw

Re: [PATCH 2/2] i2c: hisi: Only use the completion interrupt to finish the transfer

Quoted 10 lines · Yicong Yang

From: Yicong Yang <[email protected]>

The controller will always generate a completion interrupt when the transfer is finished normally or not. Currently we use either error or completion interrupt to finish, this may result the completion interrupt unhandled and corrupt the next transfer, especially at low speed mode. Since on error case, the error interrupt will come first then is the completion interrupt. So only use the completion interrupt to finish the whole transfer process.

Quoted 4 lines
Fixes d62fbdb99a85 ("i2c: add support for HiSilicon I2C controller")

Applied to for-current, thanks!