diff mbox

i2c: designware: retry transfer on transient failure

Message ID a34c8973420a179cb195ddcfbb29ef1728f32ba3.1450889004.git.baruch@tkos.co.il
State Accepted
Headers show

Commit Message

Baruch Siach Dec. 23, 2015, 4:43 p.m. UTC
Set the i2c_adapter retries field to a sensible value. This allows the i2c core
to retry master_xfer() when it returns -EAGAIN. Currently the i2c-designware
driver returns -EAGAIN only on Tx arbitration failure (DW_IC_TX_ARB_LOST).

Reported-by: Rolland Chau <zourongrong@gmail.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---
 drivers/i2c/busses/i2c-designware-core.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Andy Shevchenko Dec. 23, 2015, 4:51 p.m. UTC | #1
On Wed, 2015-12-23 at 18:43 +0200, Baruch Siach wrote:
> Set the i2c_adapter retries field to a sensible value. This allows
> the i2c core
> to retry master_xfer() when it returns -EAGAIN. Currently the i2c-
> designware
> driver returns -EAGAIN only on Tx arbitration failure
> (DW_IC_TX_ARB_LOST).

While this patch looks okay I have another proposal.
Let me time I'm going to mock up the idea.

> 
> Reported-by: Rolland Chau <zourongrong@gmail.com>
> Signed-off-by: Baruch Siach <baruch@tkos.co.il>
> ---
>  drivers/i2c/busses/i2c-designware-core.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/i2c/busses/i2c-designware-core.c
> b/drivers/i2c/busses/i2c-designware-core.c
> index de7fbbb374cd..f7b34b360dc9 100644
> --- a/drivers/i2c/busses/i2c-designware-core.c
> +++ b/drivers/i2c/busses/i2c-designware-core.c
> @@ -860,6 +860,7 @@ int i2c_dw_probe(struct dw_i2c_dev *dev)
>  
>  	snprintf(adap->name, sizeof(adap->name),
>  		 "Synopsys DesignWare I2C adapter");
> +	adap->retries = 3;
>  	adap->algo = &i2c_dw_algo;
>  	adap->dev.parent = dev->dev;
>  	i2c_set_adapdata(adap, dev);
Andy Shevchenko Dec. 28, 2015, 4:34 p.m. UTC | #2
On Wed, 2015-12-23 at 18:43 +0200, Baruch Siach wrote:
> Set the i2c_adapter retries field to a sensible value. This allows
> the i2c core
> to retry master_xfer() when it returns -EAGAIN. Currently the i2c-
> designware
> driver returns -EAGAIN only on Tx arbitration failure
> (DW_IC_TX_ARB_LOST).

Wolfram, regarding to this patch I have the following idea (I would
like to discuss a road map before step in implementing that).

First of all I would like to refactor the existing API,
i.e. i2c_parse_fw_timings(). So, do exactly two things:
a) embed struct i2c_timings into struct i2c_adapter;
b) change prototype to be i2c_parse_fw_timings(struct i2c_adapter
*adapter, bool use_defaults).

After that, introduce a new property 'linux,i2c-retry-count' to be used
as retries field in struct i2c_adapter.

Then introduce where we do similar stuff

void i2c_parse_linux_retries(struct i2c_adapter *adapter, bool
use_defaults)
{
  struct device *dev = adapter->dev.parent;
  int ret;

  ret = device_property_read_u{8,16,32?}(dev, "linux,i2c-retry-count",
&adapter->retries);
  if (ret && use_defaults)
    adapter->retries = 3;
}

And replace adapter.retries = 3 in the drivers by
i2c_parse_linux_retries(&adapter, true);

So, what do you think?

> 
> Reported-by: Rolland Chau <zourongrong@gmail.com>
> Signed-off-by: Baruch Siach <baruch@tkos.co.il>
> ---
>  drivers/i2c/busses/i2c-designware-core.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/i2c/busses/i2c-designware-core.c
> b/drivers/i2c/busses/i2c-designware-core.c
> index de7fbbb374cd..f7b34b360dc9 100644
> --- a/drivers/i2c/busses/i2c-designware-core.c
> +++ b/drivers/i2c/busses/i2c-designware-core.c
> @@ -860,6 +860,7 @@ int i2c_dw_probe(struct dw_i2c_dev *dev)
>  
>  	snprintf(adap->name, sizeof(adap->name),
>  		 "Synopsys DesignWare I2C adapter");
> +	adap->retries = 3;
>  	adap->algo = &i2c_dw_algo;
>  	adap->dev.parent = dev->dev;
>  	i2c_set_adapdata(adap, dev);
Wolfram Sang Jan. 4, 2016, 7:49 p.m. UTC | #3
> After that, introduce a new property 'linux,i2c-retry-count' to be used
> as retries field in struct i2c_adapter.

Hmm, to be honest, I always have difficulties with this "retries"
parameter; to me "try x milliseconds" makes more sense than "try 5
times". It is there for ages, so we have to stick with it, but frankly,
I wouldn't like to expose it too much :)

I'm okay with the original patch putting some "sane" initial value. It
can be modified at runtime via a i2c-dev ioctl if needed.
Andy Shevchenko Jan. 5, 2016, 12:22 p.m. UTC | #4
On Mon, 2016-01-04 at 20:49 +0100, Wolfram Sang wrote:
> > After that, introduce a new property 'linux,i2c-retry-count' to be
> > used
> > as retries field in struct i2c_adapter.
> 
> Hmm, to be honest, I always have difficulties with this "retries"
> parameter; to me "try x milliseconds" makes more sense than "try 5
> times". It is there for ages, so we have to stick with it, but
> frankly,
> I wouldn't like to expose it too much :)

Point taken.

> I'm okay with the original patch putting some "sane" initial value.
> It
> can be modified at runtime via a i2c-dev ioctl if needed.

Ah, good. So, I'm fine with it if no one has strong argument.
Baruch Siach Jan. 6, 2016, 4:40 a.m. UTC | #5
Hi Andy,

On Tue, Jan 05, 2016 at 02:22:28PM +0200, Andy Shevchenko wrote:
> On Mon, 2016-01-04 at 20:49 +0100, Wolfram Sang wrote:
> > I'm okay with the original patch putting some "sane" initial value.
> > It can be modified at runtime via a i2c-dev ioctl if needed.
> 
> Ah, good. So, I'm fine with it if no one has strong argument.

So can you give your ack to the original patch then?

Thanks,
baruch
Andy Shevchenko Jan. 7, 2016, 12:32 p.m. UTC | #6
On Wed, 2016-01-06 at 06:40 +0200, Baruch Siach wrote:
> Hi Andy,
> 
> On Tue, Jan 05, 2016 at 02:22:28PM +0200, Andy Shevchenko wrote:
> > On Mon, 2016-01-04 at 20:49 +0100, Wolfram Sang wrote:
> > > I'm okay with the original patch putting some "sane" initial
> > > value.
> > > It can be modified at runtime via a i2c-dev ioctl if needed.
> > 
> > Ah, good. So, I'm fine with it if no one has strong argument.
> 
> So can you give your ack to the original patch then?

Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Wolfram Sang Jan. 10, 2016, 8:25 a.m. UTC | #7
On Wed, Dec 23, 2015 at 06:43:24PM +0200, Baruch Siach wrote:
> Set the i2c_adapter retries field to a sensible value. This allows the i2c core
> to retry master_xfer() when it returns -EAGAIN. Currently the i2c-designware
> driver returns -EAGAIN only on Tx arbitration failure (DW_IC_TX_ARB_LOST).
> 
> Reported-by: Rolland Chau <zourongrong@gmail.com>
> Signed-off-by: Baruch Siach <baruch@tkos.co.il>

Applied to for-next, thanks!
diff mbox

Patch

diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c
index de7fbbb374cd..f7b34b360dc9 100644
--- a/drivers/i2c/busses/i2c-designware-core.c
+++ b/drivers/i2c/busses/i2c-designware-core.c
@@ -860,6 +860,7 @@  int i2c_dw_probe(struct dw_i2c_dev *dev)
 
 	snprintf(adap->name, sizeof(adap->name),
 		 "Synopsys DesignWare I2C adapter");
+	adap->retries = 3;
 	adap->algo = &i2c_dw_algo;
 	adap->dev.parent = dev->dev;
 	i2c_set_adapdata(adap, dev);