All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] i2c: octeon: thunderx: Recovery fixes and improvements
@ 2016-09-23  9:40 Jan Glauber
  2016-09-23  9:40 ` [PATCH v2 1/2] i2c: octeon: thunderx: Check bus state before starting a transaction Jan Glauber
  2016-09-23  9:40 ` [PATCH v2 2/2] i2c: octeon: thunderx: Limit register access retries Jan Glauber
  0 siblings, 2 replies; 7+ messages in thread
From: Jan Glauber @ 2016-09-23  9:40 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-kernel, linux-i2c, Dmitry Bazhenov, Jan Glauber

Hi Wolfram,

here are the remaining two patches with iopoll.h usage and a timed wait
before entering the recovery on a failed bus check.

thanks,
Jan

---------------------

Jan Glauber (2):
  i2c: octeon: thunderx: Check bus state before starting a transaction
  i2c: octeon: thunderx: Limit register access retries

 drivers/i2c/busses/i2c-octeon-core.c | 33 ++++++++++++++++++++++++++++++++-
 drivers/i2c/busses/i2c-octeon-core.h | 27 ++++++++++++++++-----------
 2 files changed, 48 insertions(+), 12 deletions(-)

-- 
1.9.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/2] i2c: octeon: thunderx: Check bus state before starting a transaction
  2016-09-23  9:40 [PATCH v2 0/2] i2c: octeon: thunderx: Recovery fixes and improvements Jan Glauber
@ 2016-09-23  9:40 ` Jan Glauber
  2016-09-24  9:24   ` Wolfram Sang
  2016-09-23  9:40 ` [PATCH v2 2/2] i2c: octeon: thunderx: Limit register access retries Jan Glauber
  1 sibling, 1 reply; 7+ messages in thread
From: Jan Glauber @ 2016-09-23  9:40 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-kernel, linux-i2c, Dmitry Bazhenov, Jan Glauber

Add an additional status check before starting a transaction. If the
check fails wait for some time to tolerate multi-master mode. After the
timeout expires trigger the recovery.

Signed-off-by: Jan Glauber <jglauber@cavium.com>
---
 drivers/i2c/busses/i2c-octeon-core.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/drivers/i2c/busses/i2c-octeon-core.c b/drivers/i2c/busses/i2c-octeon-core.c
index 5e63b17..f526511 100644
--- a/drivers/i2c/busses/i2c-octeon-core.c
+++ b/drivers/i2c/busses/i2c-octeon-core.c
@@ -630,6 +630,31 @@ static int octeon_i2c_hlc_comp_write(struct octeon_i2c *i2c, struct i2c_msg *msg
 	return ret;
 }
 
+static int octeon_i2c_check_bus(struct octeon_i2c *i2c)
+{
+	u64 end = get_jiffies_64() + i2c->adap.timeout;
+	int stat, lines;
+
+	while (time_before64(get_jiffies_64(), end)) {
+		stat = octeon_i2c_stat_read(i2c);
+
+		/* get I2C line state */
+		lines = octeon_i2c_read_int(i2c) & (TWSI_INT_SCL | TWSI_INT_SDA);
+
+		if (stat == STAT_IDLE && lines == (TWSI_INT_SCL | TWSI_INT_SDA))
+			return 0;
+
+		if (stat == STAT_LOST_ARB_38 || stat == STAT_LOST_ARB_68 ||
+		    stat == STAT_LOST_ARB_78 || stat == STAT_LOST_ARB_B0)
+			break;
+
+		usleep_range(I2C_OCTEON_EVENT_WAIT / 2, I2C_OCTEON_EVENT_WAIT);
+	}
+
+	/* bus check failed, try to recover */
+	return octeon_i2c_recovery(i2c);
+}
+
 /**
  * octeon_i2c_xfer - The driver's master_xfer function
  * @adap: Pointer to the i2c_adapter structure
@@ -643,6 +668,10 @@ int octeon_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 	struct octeon_i2c *i2c = i2c_get_adapdata(adap);
 	int i, ret = 0;
 
+	ret = octeon_i2c_check_bus(i2c);
+	if (ret)
+		goto out;
+
 	if (num == 1) {
 		if (msgs[0].len > 0 && msgs[0].len <= 8) {
 			if (msgs[0].flags & I2C_M_RD)
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/2] i2c: octeon: thunderx: Limit register access retries
  2016-09-23  9:40 [PATCH v2 0/2] i2c: octeon: thunderx: Recovery fixes and improvements Jan Glauber
  2016-09-23  9:40 ` [PATCH v2 1/2] i2c: octeon: thunderx: Check bus state before starting a transaction Jan Glauber
@ 2016-09-23  9:40 ` Jan Glauber
  2016-09-24  9:24   ` Wolfram Sang
  1 sibling, 1 reply; 7+ messages in thread
From: Jan Glauber @ 2016-09-23  9:40 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-kernel, linux-i2c, Dmitry Bazhenov, Jan Glauber

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
and trigger the recovery.

Signed-off-by: Jan Glauber <jglauber@cavium.com>
---
 drivers/i2c/busses/i2c-octeon-core.c |  4 +++-
 drivers/i2c/busses/i2c-octeon-core.h | 27 ++++++++++++++++-----------
 2 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/drivers/i2c/busses/i2c-octeon-core.c b/drivers/i2c/busses/i2c-octeon-core.c
index f526511..1dfc4b8 100644
--- a/drivers/i2c/busses/i2c-octeon-core.c
+++ b/drivers/i2c/busses/i2c-octeon-core.c
@@ -381,7 +381,9 @@ static int octeon_i2c_read(struct octeon_i2c *i2c, int target,
 		if (result)
 			return result;
 
-		data[i] = octeon_i2c_data_read(i2c);
+		data[i] = octeon_i2c_data_read(i2c, &result);
+		if (result)
+			return result;
 		if (recv_len && i == 0) {
 			if (data[i] > I2C_SMBUS_BLOCK_MAX + 1)
 				return -EPROTO;
diff --git a/drivers/i2c/busses/i2c-octeon-core.h b/drivers/i2c/busses/i2c-octeon-core.h
index 87151ea..1db7c83 100644
--- a/drivers/i2c/busses/i2c-octeon-core.h
+++ b/drivers/i2c/busses/i2c-octeon-core.h
@@ -5,6 +5,7 @@
 #include <linux/i2c.h>
 #include <linux/i2c-smbus.h>
 #include <linux/io.h>
+#include <linux/iopoll.h>
 #include <linux/kernel.h>
 #include <linux/pci.h>
 
@@ -144,9 +145,9 @@ static inline void octeon_i2c_reg_write(struct octeon_i2c *i2c, u64 eop_reg, u8
 	u64 tmp;
 
 	__raw_writeq(SW_TWSI_V | eop_reg | data, i2c->twsi_base + SW_TWSI(i2c));
-	do {
-		tmp = __raw_readq(i2c->twsi_base + SW_TWSI(i2c));
-	} while ((tmp & SW_TWSI_V) != 0);
+
+	readq_poll_timeout(i2c->twsi_base + SW_TWSI(i2c), tmp, tmp & SW_TWSI_V,
+			   I2C_OCTEON_EVENT_WAIT, i2c->adap.timeout);
 }
 
 #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
  *
  * The I2C core registers are accessed indirectly via the SW_TWSI CSR.
  */
-static inline u8 octeon_i2c_reg_read(struct octeon_i2c *i2c, u64 eop_reg)
+static inline int octeon_i2c_reg_read(struct octeon_i2c *i2c, u64 eop_reg,
+				      int *error)
 {
 	u64 tmp;
+	int ret;
 
 	__raw_writeq(SW_TWSI_V | eop_reg | SW_TWSI_R, i2c->twsi_base + SW_TWSI(i2c));
-	do {
-		tmp = __raw_readq(i2c->twsi_base + SW_TWSI(i2c));
-	} while ((tmp & SW_TWSI_V) != 0);
 
+	ret = readq_poll_timeout(i2c->twsi_base + SW_TWSI(i2c), tmp,
+				 tmp & SW_TWSI_V, I2C_OCTEON_EVENT_WAIT,
+				 i2c->adap.timeout);
+	if (error)
+		*error = ret;
 	return tmp & 0xFF;
 }
 
 #define octeon_i2c_ctl_read(i2c)					\
-	octeon_i2c_reg_read(i2c, SW_TWSI_EOP_TWSI_CTL)
-#define octeon_i2c_data_read(i2c)					\
-	octeon_i2c_reg_read(i2c, SW_TWSI_EOP_TWSI_DATA)
+	octeon_i2c_reg_read(i2c, SW_TWSI_EOP_TWSI_CTL, NULL)
+#define octeon_i2c_data_read(i2c, error)				\
+	octeon_i2c_reg_read(i2c, SW_TWSI_EOP_TWSI_DATA, error)
 #define octeon_i2c_stat_read(i2c)					\
-	octeon_i2c_reg_read(i2c, SW_TWSI_EOP_TWSI_STAT)
+	octeon_i2c_reg_read(i2c, SW_TWSI_EOP_TWSI_STAT, NULL)
 
 /**
  * octeon_i2c_read_int - read the TWSI_INT register
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] i2c: octeon: thunderx: Check bus state before starting a transaction
  2016-09-23  9:40 ` [PATCH v2 1/2] i2c: octeon: thunderx: Check bus state before starting a transaction Jan Glauber
@ 2016-09-24  9:24   ` Wolfram Sang
  2016-09-26  5:58       ` Jan Glauber
  0 siblings, 1 reply; 7+ messages in thread
From: Wolfram Sang @ 2016-09-24  9:24 UTC (permalink / raw)
  To: Jan Glauber; +Cc: linux-kernel, linux-i2c, Dmitry Bazhenov

[-- Attachment #1: Type: text/plain, Size: 370 bytes --]

On Fri, Sep 23, 2016 at 11:40:38AM +0200, Jan Glauber wrote:
> Add an additional status check before starting a transaction. If the
> check fails wait for some time to tolerate multi-master mode. After the
> timeout expires trigger the recovery.
> 
> Signed-off-by: Jan Glauber <jglauber@cavium.com>

Need to think more about it, needs to wait for next cycle.


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] i2c: octeon: thunderx: Limit register access retries
  2016-09-23  9:40 ` [PATCH v2 2/2] i2c: octeon: thunderx: Limit register access retries Jan Glauber
@ 2016-09-24  9:24   ` Wolfram Sang
  0 siblings, 0 replies; 7+ messages in thread
From: Wolfram Sang @ 2016-09-24  9:24 UTC (permalink / raw)
  To: Jan Glauber; +Cc: linux-kernel, linux-i2c, Dmitry Bazhenov

[-- Attachment #1: Type: text/plain, Size: 533 bytes --]

On Fri, Sep 23, 2016 at 11:40:39AM +0200, Jan Glauber wrote:
> 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
> and trigger the recovery.
> 
> Signed-off-by: Jan Glauber <jglauber@cavium.com>

Deleted the last 4 words from commit message (previous recovery patch
needs more discussion) and applied to for-next, thanks!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] i2c: octeon: thunderx: Check bus state before starting a transaction
  2016-09-24  9:24   ` Wolfram Sang
@ 2016-09-26  5:58       ` Jan Glauber
  0 siblings, 0 replies; 7+ messages in thread
From: Jan Glauber @ 2016-09-26  5:58 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-kernel, linux-i2c, Dmitry Bazhenov

On Sat, Sep 24, 2016 at 11:24:19AM +0200, Wolfram Sang wrote:
> On Fri, Sep 23, 2016 at 11:40:38AM +0200, Jan Glauber wrote:
> > Add an additional status check before starting a transaction. If the
> > check fails wait for some time to tolerate multi-master mode. After the
> > timeout expires trigger the recovery.
> > 
> > Signed-off-by: Jan Glauber <jglauber@cavium.com>
> 
> Need to think more about it, needs to wait for next cycle.
> 

OK, please share your thoughts when you get to it.

--Jan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] i2c: octeon: thunderx: Check bus state before starting a transaction
@ 2016-09-26  5:58       ` Jan Glauber
  0 siblings, 0 replies; 7+ messages in thread
From: Jan Glauber @ 2016-09-26  5:58 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-kernel, linux-i2c, Dmitry Bazhenov

On Sat, Sep 24, 2016 at 11:24:19AM +0200, Wolfram Sang wrote:
> On Fri, Sep 23, 2016 at 11:40:38AM +0200, Jan Glauber wrote:
> > Add an additional status check before starting a transaction. If the
> > check fails wait for some time to tolerate multi-master mode. After the
> > timeout expires trigger the recovery.
> > 
> > Signed-off-by: Jan Glauber <jglauber@cavium.com>
> 
> Need to think more about it, needs to wait for next cycle.
> 

OK, please share your thoughts when you get to it.

--Jan

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-09-26  5:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-23  9:40 [PATCH v2 0/2] i2c: octeon: thunderx: Recovery fixes and improvements Jan Glauber
2016-09-23  9:40 ` [PATCH v2 1/2] i2c: octeon: thunderx: Check bus state before starting a transaction Jan Glauber
2016-09-24  9:24   ` Wolfram Sang
2016-09-26  5:58     ` Jan Glauber
2016-09-26  5:58       ` Jan Glauber
2016-09-23  9:40 ` [PATCH v2 2/2] i2c: octeon: thunderx: Limit register access retries Jan Glauber
2016-09-24  9:24   ` Wolfram Sang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.