i2c: octeon/thunderx: Fix DMA mask + improvements
Subsystems (3)
v2 cover i2c: octeon/thunderx: Fix DMA mask + improvements
Hi Robert, Andi,
This patchset adds a fix to the ThunderX driver where the DMA mask was not set, sometimes preventing MSI-X from being initialized properly.
The v2 brings an extra patch that fixes an infinite loop in the clock divisor calculation.
The other two patches improve error handling on the bus, and the latency in HS mode.
Cheers,
-Paul
Changelog:
v2:
- [1/4]: New patch
- Every other patch untouched.
Tanmay Jagdale (4):
i2c: octeon: Fix infinite loop in clock divisor calculation
i2c: octeon: Add error state recovery
i2c: thunderx: Set DMA mask
i2c: thunderx: Use polling with delay in HS mode
drivers/i2c/busses/i2c-octeon-core.c | 35 ++++++++++++++---------- drivers/i2c/busses/i2c-thunderx-pcidrv.c | 4 +++ 2 files changed, 24 insertions(+), 15 deletions(-)
Signature · 1 line
2.47.3
PATCH v2 1/4 i2c: octeon: Fix infinite loop in clock divisor calculation
From: Tanmay Jagdale <[email protected]>
When mdiv_min is unsigned, the signed mdiv_idx variable is cast to unsigned as well in the inner loop condition comparison, leading to an infinite loop.
---
v2: New patch
--- drivers/i2c/busses/i2c-octeon-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-octeon-core.c +2 -2
@@ -823,14 +823,14 @@ int octeon_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)/* calculate and set clock divisors */ void octeon_i2c_set_clock (struct octeon_i2c *i2c) { -int tclk, thp_base, inc, thp_idx, mdiv_idx, ndiv_idx, foscl, diff; +int tclk, thp_base, inc, thp_idx, mdiv_idx, mdiv_min, ndiv_idx, foscl, diff;bool is_plat_otx2;/* * Find divisors to produce target frequency, start with large delta * to cover wider range of divisors, note thp = TCLK half period and * ds is OSCL output frequency divisor. */ -unsigned int thp, mdiv_min, mdiv =2 , ndiv =0 , ds =10 ; +unsigned int thp, mdiv =2 , ndiv =0 , ds =10 ;unsigned int delta_hz =INITIAL_DELTA_HZ ; is_plat_otx2 =octeon_i2c_is_otx2 (to_pci_dev (i2c->dev));
Signature · 1 line
2.47.3
Re: [PATCH v2 1/4] i2c: octeon: Fix infinite loop in clock divisor calculation
Hi Robert, Andi,
Le vendredi 13 novembre 2026 à 14:41 +0100, Paul Cercueil a écrit :
Quoted 7 lines
From: Tanmay Jagdale <[email protected]>
When
mdiv_minis unsigned, the signedmdiv_idxvariable is cast to unsigned as well in the inner loop condition comparison, leading to an infinite loop.Fixes 03240f826b02 ("i2c: thunderx: Support for High speed mode")
I get only one complaint from Sashiko on this patchset, which is that the Fixes:
tag should actually point to 114c69f4be3f ("i2c: thunderx: Clock divisor logic changes").
Do you want a v3 with that addressed?
Cheers,
-Paul
Quoted 36 lines
Signed-off-by Tanmay Jagdale <[email protected]>Co-developed-by Paul Cercueil <[email protected]>Signed-off-by Paul Cercueil <[email protected]>---
v2: New patch
---
drivers/i2c/busses/i2c-octeon-core.c | 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)drivers/i2c/busses/i2c- renamed from drivers/i2c/busses/i2c-octeon-core.c +0
-0
octeon-core.c
index93a49e4637ec..85e18ca2410e100644drivers/i2c/busses/i2c-octeon-core.c +2
-2@@ -823,14 +823,14 @@ int octeon_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) /* calculate and set clock divisors */ void octeon_i2c_set_clock(struct octeon_i2c *i2c) { - int tclk, thp_base, inc, thp_idx, mdiv_idx, ndiv_idx, foscl, diff; + int tclk, thp_base, inc, thp_idx, mdiv_idx, mdiv_min, ndiv_idx, foscl, diff; bool is_plat_otx2; /** Find divisors to produce target frequency, start with large delta * to cover wider range of divisors, note thp = TCLK half period and * ds is OSCL output frequency divisor. */ -unsigned int thp, mdiv_min, mdiv =2 , ndiv =0 , ds =10 ; +unsigned int thp, mdiv =2 , ndiv =0 , ds =10 ; unsigned int delta_hz = INITIAL_DELTA_HZ;
is_plat_otx2= octeon_i2c_is_otx2(to_pci_dev(i2c->dev));
PATCH v2 2/4 i2c: octeon: Add error state recovery
In reply to Paul CercueilFrom: Tanmay Jagdale <[email protected]>
Whenever a Bus Error state occurs, trigger a software recovery to attempt to return to a working state.
---
v2: No change
--- drivers/i2c/busses/i2c-octeon-core.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-)
drivers/i2c/busses/i2c-octeon-core.c +14 -13
@@ -205,6 +205,17 @@ static int octeon_i2c_hlc_wait(struct octeon_i2c *i2c)return 0 ; } +static int octeon_i2c_recovery (struct octeon_i2c *i2c) +{ +int ret; + + ret =i2c_recover_bus (&i2c->adap); +if (ret) +/* recover failed, try hardware re-init */ + ret =octeon_i2c_init_lowlevel (i2c); +return ret; +} +static int octeon_i2c_check_status (struct octeon_i2c *i2c,int final_read) {u8 stat;
@@ -265,8 +276,9 @@ static int octeon_i2c_check_status(struct octeon_i2c *i2c, int final_read)return -EOPNOTSUPP ;case STAT_TXDATA_NAK : -case STAT_BUS_ERROR :return -EIO ; +case STAT_BUS_ERROR : +return octeon_i2c_recovery (i2c) ? -EIO : -EAGAIN ;case STAT_TXADDR_NAK :case STAT_RXADDR_NAK :case STAT_AD2W_NAK :
@@ -277,24 +289,13 @@ static int octeon_i2c_check_status(struct octeon_i2c *i2c, int final_read)/* Set BUS_MON_RST to reset bus monitor */ mode |=BUS_MON_RST_MASK ;octeon_i2c_writeq_flush (mode, i2c->twsi_base +OCTEON_REG_MODE (i2c)); -return -EIO ; +return octeon_i2c_recovery (i2c) ? -EIO : -EAGAIN ;default :dev_err (i2c->dev,"unhandled state: %d\n" , stat);return -EIO ; } } -static int octeon_i2c_recovery (struct octeon_i2c *i2c) -{ -int ret; - - ret =i2c_recover_bus (&i2c->adap); -if (ret) -/* recover failed, try hardware re-init */ - ret =octeon_i2c_init_lowlevel (i2c); -return ret; -} -/** * octeon_i2c_start - send START to the bus * @i2c: The struct octeon_i2c
Signature · 1 line
2.47.3
PATCH v2 3/4 i2c: thunderx: Set DMA mask
In reply to Paul CercueilFrom: Tanmay Jagdale <[email protected]>
Without it, MSI-X initialization can fail.
---
v2: No change
--- drivers/i2c/busses/i2c-thunderx-pcidrv.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/i2c/busses/i2c-thunderx-pcidrv.c +4 -0
@@ -198,6 +198,10 @@ static int thunder_i2c_probe_pci(struct pci_dev *pdev, i2c->hlc_int_enable = thunder_i2c_hlc_int_enable; i2c->hlc_int_disable = thunder_i2c_hlc_int_disable; + ret =dma_set_mask_and_coherent (dev,DMA_BIT_MASK (48 )); +if (ret <0 ) + goto error; + ret =pci_alloc_irq_vectors (pdev,1 ,1 ,PCI_IRQ_MSIX );if (ret <0 ) goto error;
Signature · 1 line
2.47.3
PATCH v2 4/4 i2c: thunderx: Use polling with delay in HS mode
In reply to Paul CercueilFrom: Tanmay Jagdale <[email protected]>
High I2C transaction latencies exceeding 1 second were intermittently observed while operating in HS mode. These delays caused DTLS handshakes between the main processor and firmware processors to time out, resulting in increased startup time.
Replace the existing wait mechanism with delayed polling in HS mode to improve transfer responsiveness and avoid prolonged latency spikes.
---
v2: No change
--- drivers/i2c/busses/i2c-octeon-core.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/i2c/busses/i2c-octeon-core.c +4 -0
@@ -15,6 +15,7 @@#include <linux/delay.h> #include <linux/i2c.h> #include <linux/interrupt.h> +#include <linux/iopoll.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/pci.h>
@@ -65,6 +66,9 @@ static int octeon_i2c_wait(struct octeon_i2c *i2c)return octeon_i2c_test_iflg (i2c) ?0 : -ETIMEDOUT ; } +if (!IS_LS_FREQ (i2c->twsi_freq)) + return poll_timeout_us_atomic(, octeon_i2c_test_iflg(i2c), 1, 1000, false); + i2c->int_enable (i2c); time_left =wait_event_timeout (i2c->queue,octeon_i2c_test_iflg (i2c), i2c->adap.timeout);
Signature · 1 line
2.47.3