From: Grant Likely <grant.likely@secretlab.ca>
To: Esben Haabendal <eha@doredevelopment.dk>
Cc: linuxppc-dev@ozlabs.org, linux-i2c@vger.kernel.org,
Ben Dooks <ben-linux@fluff.org>
Subject: Re: [PATCH v2] i2c-mpc: generate START condition after STOP caused by read i2c_msg
Date: Wed, 3 Jun 2009 00:01:20 -0600 [thread overview]
Message-ID: <fa686aa40906022301t19fa98fckeb9894e480fa6f1e@mail.gmail.com> (raw)
In-Reply-To: <fa686aa40906021612q3f40a0docffa9766b53cd90b@mail.gmail.com>
On Tue, Jun 2, 2009 at 5:12 PM, Grant Likely <grant.likely@secretlab.ca> wr=
ote:
> Hi Esben and Ben,
>
> Sorry for the lateness in reviewing this. =A0FWIW, here are my comments.
>
> g.
>
> On Mon, May 18, 2009 at 11:22 PM, Esben Haabendal
> <eha@doredevelopment.dk> wrote:
>> This fixes MAL (arbitration lost) bug caused by illegal use of
>> RSTA (repeated START) after STOP condition generated after last byte
>> of reads. With this patch, it is possible to do an i2c_transfer() with
>> additional i2c_msg's following the I2C_M_RD messages.
>>
>> It still needs to be resolved if it is possible to fix this issue
>> by removing the STOP condition after reads in a robust way.
>>
>> Signed-off-by: Esben Haabendal <eha@doredevelopment.dk>
>> ---
>> =A0drivers/i2c/busses/i2c-mpc.c | =A0 =A09 +++++++--
>> =A01 files changed, 7 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
>> index 4af5c09..0199f9a 100644
>> --- a/drivers/i2c/busses/i2c-mpc.c
>> +++ b/drivers/i2c/busses/i2c-mpc.c
>> @@ -456,17 +456,22 @@ static int mpc_xfer(struct i2c_adapter *adap, stru=
ct
>> i2c_msg *msgs, int num)
>> =A0 =A0 =A0 =A0}
>>
>> =A0 =A0 =A0 =A0for (i =3D 0; ret >=3D 0 && i < num; i++) {
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 int restart =3D i;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pmsg =3D &msgs[i];
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dev_dbg(i2c->dev,
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"Doing %s %d bytes to 0x%=
02x - %d of %d messages\n",
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pmsg->flags & I2C_M_RD ? =
"read" : "write",
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pmsg->len, pmsg->addr, i =
+ 1, num);
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (i > 0 && ((pmsg - 1)->flags & I2C_M_RD=
))
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 restart =3D 0;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (pmsg->flags & I2C_M_RD)
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ret =3D
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mpc_read(i2c, pmsg=
->addr, pmsg->buf, pmsg->len,
>> i);
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mpc_read(i2c, pmsg=
->addr, pmsg->buf, pmsg->len,
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0restart);
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0else
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ret =3D
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mpc_write(i2c, pms=
g->addr, pmsg->buf, pmsg->len,
>> i);
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mpc_write(i2c, pms=
g->addr, pmsg->buf, pmsg->len,
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 restart);
>> =A0 =A0 =A0 =A0}
>
> Hmmm, seems to be a rather convoluted code path. =A0Surely this could be
> handled in a clearer way. =A0The whole (pmsg - 1) bit raises my eyebrows
> (I'd rather see msgs[i-1]). =A0At the very least this deserves an
> comment describing what it is doing. =A0The following might be better
> for the next person who has to read this code:
>
> + =A0 =A0 =A0int restart =3D 0;
> =A0 =A0 =A0 for (i =3D 0; ret >=3D 0 && i < num; i++) {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 pmsg =3D &msgs[i];
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(i2c->dev,
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "Doing %s %d bytes to 0x%02x =
- %d of %d messages\n",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pmsg->flags & I2C_M_RD ? "rea=
d" : "write",
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pmsg->len, pmsg->addr, i + 1,=
num);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (pmsg->flags & I2C_M_RD)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mpc_read(i2c, pmsg-=
>addr, pmsg->buf, pmsg->len,
> i);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mpc_read(i2c, pmsg-=
>addr, pmsg->buf, pmsg->len,
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
restart);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mpc_write(i2c, pmsg=
->addr, pmsg->buf, pmsg->len,
> i);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mpc_write(i2c, pmsg=
->addr, pmsg->buf, pmsg->len,
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
restart);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Only set the restart flag if this was no=
t an
> I2C_M_RD transaction
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* because it causes an illegal use of
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* RSTA (repeated START) after STOP condi=
tion
> generated after last byte
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* of reads =A0*/
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 restart =3D (pmsg->flags & I2C_M_RD =3D=3D =
0);
> =A0 =A0 =A0 }
BTW, since you're touching these lines anyway, please clean up the
whitespace usage. Since you have to break the line anyway, it no
longer makes sense for the "ret =3D " to be on a separate line anymore.
g.
--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
next prev parent reply other threads:[~2009-06-03 6:01 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-19 5:22 [PATCH v2] i2c-mpc: generate START condition after STOP caused by read i2c_msg Esben Haabendal
2009-05-26 11:30 ` Esben Haabendal
2009-05-26 21:33 ` Ben Dooks
2009-05-28 17:17 ` Wolfram Sang
2009-05-28 18:43 ` Joakim Tjernlund
2009-05-28 20:10 ` Esben Haabendal
2009-05-28 20:34 ` Peter Korsgaard
2009-05-28 20:41 ` Esben Haabendal
2009-05-28 21:08 ` Peter Korsgaard
2009-05-28 21:22 ` Esben Haabendal
2009-12-03 15:09 ` Michael Lawnick
2009-12-03 15:29 ` Ben Dooks
2009-12-03 15:49 ` Joakim Tjernlund
2009-12-04 6:58 ` Michael Lawnick
2009-12-03 15:42 ` Joakim Tjernlund
2009-05-28 19:31 ` Grant Likely
2009-05-28 20:15 ` Esben Haabendal
2009-06-02 22:25 ` Ben Dooks
2009-06-02 23:12 ` Grant Likely
2009-06-03 6:01 ` Grant Likely [this message]
2009-06-14 13:16 ` Ben Dooks
2009-06-14 14:04 ` Esben Haabendal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fa686aa40906022301t19fa98fckeb9894e480fa6f1e@mail.gmail.com \
--to=grant.likely@secretlab.ca \
--cc=ben-linux@fluff.org \
--cc=eha@doredevelopment.dk \
--cc=linux-i2c@vger.kernel.org \
--cc=linuxppc-dev@ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).