openbmc.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] i2c: npcm7xx: bug fix timeout (usec instead of msec)
@ 2020-08-30 12:20 Tali Perry
  2020-08-30 12:47 ` Avi Fishman
  2020-08-30 18:01 ` Andy Shevchenko
  0 siblings, 2 replies; 5+ messages in thread
From: Tali Perry @ 2020-08-30 12:20 UTC (permalink / raw)
  To: kunyi, xqiu, benjaminfair, avifishman70, joel, tmaimon77, wsa
  Cc: linux-i2c, openbmc, linux-kernel, Tali Perry

i2c: npcm7xx: bug fix timeout (usec instead of msec)

Signed-off-by: Tali Perry <tali.perry1@gmail.com>
---
 drivers/i2c/busses/i2c-npcm7xx.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c
index 75f07138a6fa..abb334492a3d 100644
--- a/drivers/i2c/busses/i2c-npcm7xx.c
+++ b/drivers/i2c/busses/i2c-npcm7xx.c
@@ -2093,8 +2093,13 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
 		}
 	}
 
-	/* Adaptive TimeOut: astimated time in usec + 100% margin */
-	timeout_usec = (2 * 10000 / bus->bus_freq) * (2 + nread + nwrite);
+	/*
+	 * Adaptive TimeOut: estimated time in usec + 100% margin:
+	 * 2: double the timeout for clock stretching case
+	 * 9: bits per transaction (including the ack/nack)
+	 * 1000000: micro second in a second
+	 */
+	timeout_usec = (2 * 9 * 1000000 / bus->bus_freq) * (2 + nread + nwrite);
 	timeout = max(msecs_to_jiffies(35), usecs_to_jiffies(timeout_usec));
 	if (nwrite >= 32 * 1024 || nread >= 32 * 1024) {
 		dev_err(bus->dev, "i2c%d buffer too big\n", bus->num);

base-commit: d012a7190fc1fd72ed48911e77ca97ba4521bccd
-- 
2.22.0

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

* Re: [PATCH v2] i2c: npcm7xx: bug fix timeout (usec instead of msec)
  2020-08-30 12:20 [PATCH v2] i2c: npcm7xx: bug fix timeout (usec instead of msec) Tali Perry
@ 2020-08-30 12:47 ` Avi Fishman
  2020-08-30 18:01 ` Andy Shevchenko
  1 sibling, 0 replies; 5+ messages in thread
From: Avi Fishman @ 2020-08-30 12:47 UTC (permalink / raw)
  To: Tali Perry
  Cc: kunyi, xqiu, Benjamin Fair, Joel Stanley, Tomer Maimon, wsa,
	linux-i2c, OpenBMC Maillist, Linux Kernel Mailing List

On Sun, Aug 30, 2020 at 3:21 PM Tali Perry <tali.perry1@gmail.com> wrote:
>
> i2c: npcm7xx: bug fix timeout (usec instead of msec)
>
> Signed-off-by: Tali Perry <tali.perry1@gmail.com>
Reviewed-by: Avi Fishman <avifishman70@gmail.com>

> ---
>  drivers/i2c/busses/i2c-npcm7xx.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c
> index 75f07138a6fa..abb334492a3d 100644
> --- a/drivers/i2c/busses/i2c-npcm7xx.c
> +++ b/drivers/i2c/busses/i2c-npcm7xx.c
> @@ -2093,8 +2093,13 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
>                 }
>         }
>
> -       /* Adaptive TimeOut: astimated time in usec + 100% margin */
> -       timeout_usec = (2 * 10000 / bus->bus_freq) * (2 + nread + nwrite);
> +       /*
> +        * Adaptive TimeOut: estimated time in usec + 100% margin:
> +        * 2: double the timeout for clock stretching case
> +        * 9: bits per transaction (including the ack/nack)
> +        * 1000000: micro second in a second
> +        */
> +       timeout_usec = (2 * 9 * 1000000 / bus->bus_freq) * (2 + nread + nwrite);
>         timeout = max(msecs_to_jiffies(35), usecs_to_jiffies(timeout_usec));
>         if (nwrite >= 32 * 1024 || nread >= 32 * 1024) {
>                 dev_err(bus->dev, "i2c%d buffer too big\n", bus->num);
>
> base-commit: d012a7190fc1fd72ed48911e77ca97ba4521bccd
> --
> 2.22.0
>


--
Regards,
Avi

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

* Re: [PATCH v2] i2c: npcm7xx: bug fix timeout (usec instead of msec)
  2020-08-30 12:20 [PATCH v2] i2c: npcm7xx: bug fix timeout (usec instead of msec) Tali Perry
  2020-08-30 12:47 ` Avi Fishman
@ 2020-08-30 18:01 ` Andy Shevchenko
  2020-08-31  7:57   ` Avi Fishman
  1 sibling, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2020-08-30 18:01 UTC (permalink / raw)
  To: Tali Perry
  Cc: kunyi, xqiu, benjaminfair, Avi Fishman, Joel Stanley,
	Tomer Maimon, Wolfram Sang, linux-i2c, OpenBMC Maillist,
	Linux Kernel Mailing List

On Sun, Aug 30, 2020 at 3:23 PM Tali Perry <tali.perry1@gmail.com> wrote:

>
> i2c: npcm7xx: bug fix timeout (usec instead of msec)

This commit message is awful. Please read [1] as a tutorial how to
write a commit messages.

[1]: https://chris.beams.io/posts/git-commit/

...

> -       /* Adaptive TimeOut: astimated time in usec + 100% margin */
> -       timeout_usec = (2 * 10000 / bus->bus_freq) * (2 + nread + nwrite);
> +       /*
> +        * Adaptive TimeOut: estimated time in usec + 100% margin:
> +        * 2: double the timeout for clock stretching case
> +        * 9: bits per transaction (including the ack/nack)

> +        * 1000000: micro second in a second

No need. See below.

> +        */

> +       timeout_usec = (2 * 9 * 1000000 / bus->bus_freq) * (2 + nread + nwrite);

USEC_PER_SEC

>         timeout = max(msecs_to_jiffies(35), usecs_to_jiffies(timeout_usec));
>         if (nwrite >= 32 * 1024 || nread >= 32 * 1024) {
>                 dev_err(bus->dev, "i2c%d buffer too big\n", bus->num);

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH v2] i2c: npcm7xx: bug fix timeout (usec instead of msec)
  2020-08-30 18:01 ` Andy Shevchenko
@ 2020-08-31  7:57   ` Avi Fishman
  2020-08-31 12:03     ` Avi Fishman
  0 siblings, 1 reply; 5+ messages in thread
From: Avi Fishman @ 2020-08-31  7:57 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Tali Perry, kunyi, xqiu, Benjamin Fair, Joel Stanley,
	Tomer Maimon, Wolfram Sang, linux-i2c, OpenBMC Maillist,
	Linux Kernel Mailing List

On Sun, Aug 30, 2020 at 9:01 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Sun, Aug 30, 2020 at 3:23 PM Tali Perry <tali.perry1@gmail.com> wrote:
>
> >
> > i2c: npcm7xx: bug fix timeout (usec instead of msec)
>
> This commit message is awful. Please read [1] as a tutorial how to
> write a commit messages.
>

Would this be better:
i2c: npcm7xx: Fix microsecond timeout calculation

Inside npcm_i2c_master_xfer() we calculate a timeout for the entire
transaction in microseconds, the calculation was wrong so big i2c
massages would timeout before they ended.
This commit fix that.

> [1]: https://chris.beams.io/posts/git-commit/
>
> ...
>
> > -       /* Adaptive TimeOut: astimated time in usec + 100% margin */
> > -       timeout_usec = (2 * 10000 / bus->bus_freq) * (2 + nread + nwrite);
> > +       /*
> > +        * Adaptive TimeOut: estimated time in usec + 100% margin:
> > +        * 2: double the timeout for clock stretching case
> > +        * 9: bits per transaction (including the ack/nack)
>
> > +        * 1000000: micro second in a second
>
> No need. See below.
>
> > +        */
>
> > +       timeout_usec = (2 * 9 * 1000000 / bus->bus_freq) * (2 + nread + nwrite);
>
> USEC_PER_SEC

OK

>
> >         timeout = max(msecs_to_jiffies(35), usecs_to_jiffies(timeout_usec));
> >         if (nwrite >= 32 * 1024 || nread >= 32 * 1024) {
> >                 dev_err(bus->dev, "i2c%d buffer too big\n", bus->num);
>
> --
> With Best Regards,
> Andy Shevchenko



-- 
Regards,
Avi

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

* Re: [PATCH v2] i2c: npcm7xx: bug fix timeout (usec instead of msec)
  2020-08-31  7:57   ` Avi Fishman
@ 2020-08-31 12:03     ` Avi Fishman
  0 siblings, 0 replies; 5+ messages in thread
From: Avi Fishman @ 2020-08-31 12:03 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Tali Perry, kunyi, xqiu, Benjamin Fair, Joel Stanley,
	Tomer Maimon, Wolfram Sang, linux-i2c, OpenBMC Maillist,
	Linux Kernel Mailing List

Please ignore my last mail, Tali already sent v3.

On Mon, Aug 31, 2020 at 10:57 AM Avi Fishman <avifishman70@gmail.com> wrote:
>
> On Sun, Aug 30, 2020 at 9:01 PM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> >
> > On Sun, Aug 30, 2020 at 3:23 PM Tali Perry <tali.perry1@gmail.com> wrote:
> >
> > >
> > > i2c: npcm7xx: bug fix timeout (usec instead of msec)
> >
> > This commit message is awful. Please read [1] as a tutorial how to
> > write a commit messages.
> >
>
> Would this be better:
> i2c: npcm7xx: Fix microsecond timeout calculation
>
> Inside npcm_i2c_master_xfer() we calculate a timeout for the entire
> transaction in microseconds, the calculation was wrong so big i2c
> massages would timeout before they ended.
> This commit fix that.
>
> > [1]: https://chris.beams.io/posts/git-commit/
> >
> > ...
> >
> > > -       /* Adaptive TimeOut: astimated time in usec + 100% margin */
> > > -       timeout_usec = (2 * 10000 / bus->bus_freq) * (2 + nread + nwrite);
> > > +       /*
> > > +        * Adaptive TimeOut: estimated time in usec + 100% margin:
> > > +        * 2: double the timeout for clock stretching case
> > > +        * 9: bits per transaction (including the ack/nack)
> >
> > > +        * 1000000: micro second in a second
> >
> > No need. See below.
> >
> > > +        */
> >
> > > +       timeout_usec = (2 * 9 * 1000000 / bus->bus_freq) * (2 + nread + nwrite);
> >
> > USEC_PER_SEC
>
> OK
>
> >
> > >         timeout = max(msecs_to_jiffies(35), usecs_to_jiffies(timeout_usec));
> > >         if (nwrite >= 32 * 1024 || nread >= 32 * 1024) {
> > >                 dev_err(bus->dev, "i2c%d buffer too big\n", bus->num);
> >
> > --
> > With Best Regards,
> > Andy Shevchenko
>
>
>
> --
> Regards,
> Avi



-- 
Regards,
Avi

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

end of thread, other threads:[~2020-08-31 12:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-30 12:20 [PATCH v2] i2c: npcm7xx: bug fix timeout (usec instead of msec) Tali Perry
2020-08-30 12:47 ` Avi Fishman
2020-08-30 18:01 ` Andy Shevchenko
2020-08-31  7:57   ` Avi Fishman
2020-08-31 12:03     ` Avi Fishman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).