Skip to content

Commit 70121f7

Browse files
Jan GlauberWolfram Sang
Jan Glauber
authored and
Wolfram Sang
committed
i2c: octeon: thunderx: Limit register access retries
Do not infinitely retry register readq and writeq operations in order to not lock up the CPU in case the TWSI gets stuck. Return -ETIMEDOUT in case of a failed data read. For all other cases just return so subsequent operations will fail. Signed-off-by: Jan Glauber <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent fcbd4bd commit 70121f7

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

drivers/i2c/busses/i2c-octeon-core.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,9 @@ static int octeon_i2c_read(struct octeon_i2c *i2c, int target,
381381
if (result)
382382
return result;
383383

384-
data[i] = octeon_i2c_data_read(i2c);
384+
data[i] = octeon_i2c_data_read(i2c, &result);
385+
if (result)
386+
return result;
385387
if (recv_len && i == 0) {
386388
if (data[i] > I2C_SMBUS_BLOCK_MAX + 1)
387389
return -EPROTO;

drivers/i2c/busses/i2c-octeon-core.h

+16-11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <linux/i2c.h>
66
#include <linux/i2c-smbus.h>
77
#include <linux/io.h>
8+
#include <linux/iopoll.h>
89
#include <linux/kernel.h>
910
#include <linux/pci.h>
1011

@@ -144,9 +145,9 @@ static inline void octeon_i2c_reg_write(struct octeon_i2c *i2c, u64 eop_reg, u8
144145
u64 tmp;
145146

146147
__raw_writeq(SW_TWSI_V | eop_reg | data, i2c->twsi_base + SW_TWSI(i2c));
147-
do {
148-
tmp = __raw_readq(i2c->twsi_base + SW_TWSI(i2c));
149-
} while ((tmp & SW_TWSI_V) != 0);
148+
149+
readq_poll_timeout(i2c->twsi_base + SW_TWSI(i2c), tmp, tmp & SW_TWSI_V,
150+
I2C_OCTEON_EVENT_WAIT, i2c->adap.timeout);
150151
}
151152

152153
#define octeon_i2c_ctl_write(i2c, val) \
@@ -163,24 +164,28 @@ static inline void octeon_i2c_reg_write(struct octeon_i2c *i2c, u64 eop_reg, u8
163164
*
164165
* The I2C core registers are accessed indirectly via the SW_TWSI CSR.
165166
*/
166-
static inline u8 octeon_i2c_reg_read(struct octeon_i2c *i2c, u64 eop_reg)
167+
static inline int octeon_i2c_reg_read(struct octeon_i2c *i2c, u64 eop_reg,
168+
int *error)
167169
{
168170
u64 tmp;
171+
int ret;
169172

170173
__raw_writeq(SW_TWSI_V | eop_reg | SW_TWSI_R, i2c->twsi_base + SW_TWSI(i2c));
171-
do {
172-
tmp = __raw_readq(i2c->twsi_base + SW_TWSI(i2c));
173-
} while ((tmp & SW_TWSI_V) != 0);
174174

175+
ret = readq_poll_timeout(i2c->twsi_base + SW_TWSI(i2c), tmp,
176+
tmp & SW_TWSI_V, I2C_OCTEON_EVENT_WAIT,
177+
i2c->adap.timeout);
178+
if (error)
179+
*error = ret;
175180
return tmp & 0xFF;
176181
}
177182

178183
#define octeon_i2c_ctl_read(i2c) \
179-
octeon_i2c_reg_read(i2c, SW_TWSI_EOP_TWSI_CTL)
180-
#define octeon_i2c_data_read(i2c) \
181-
octeon_i2c_reg_read(i2c, SW_TWSI_EOP_TWSI_DATA)
184+
octeon_i2c_reg_read(i2c, SW_TWSI_EOP_TWSI_CTL, NULL)
185+
#define octeon_i2c_data_read(i2c, error) \
186+
octeon_i2c_reg_read(i2c, SW_TWSI_EOP_TWSI_DATA, error)
182187
#define octeon_i2c_stat_read(i2c) \
183-
octeon_i2c_reg_read(i2c, SW_TWSI_EOP_TWSI_STAT)
188+
octeon_i2c_reg_read(i2c, SW_TWSI_EOP_TWSI_STAT, NULL)
184189

185190
/**
186191
* octeon_i2c_read_int - read the TWSI_INT register

0 commit comments

Comments
 (0)