* [PATCH] i2c-cadence: Do not let signals interrupt I2C transfers
@ 2014-03-10 11:12 Mike Looijmans
2014-03-10 21:59 ` Sören Brinkmann
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Mike Looijmans @ 2014-03-10 11:12 UTC (permalink / raw)
To: git-gjFFaj9aHVfQT0dZR+AlfA, wsa-z923LK4zBo2bacvFa/9K2g,
linux-i2c-u79uwXL29TY76Z2rM5mHXA
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA, Mike Looijmans
Pressing CTRL-C while communicating with an I2C device leads to erratic
behaviour. The cause is that the controller will interrupt the I2C transfer
in progress, and leave the client device in an undefined state. Many
drivers do not handle error return codes on I2C transfers. The calling driver
has no way of telling how much of the transfer has actually completed, so
it cannot reliably determine the device's state.
The best solution here is to not handle signals in the I2C bus driver at all,
but always complete a transaction before returning control.
See for a related patch and discussion on this topic:
http://lkml.org/lkml/2014/1/9/246
---
drivers/i2c/busses/i2c-cadence.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index 86713d6..32ce2ee 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -452,16 +452,12 @@ static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg,
cdns_i2c_msend(id);
/* Wait for the signal of completion */
- ret = wait_for_completion_interruptible_timeout(
- &id->xfer_done, HZ);
- if (ret < 1) {
+ ret = wait_for_completion_timeout(&id->xfer_done, HZ);
+ if (ret == 0) {
cdns_i2c_master_reset(adap);
- if (!ret) {
- dev_err(id->adap.dev.parent,
+ dev_err(id->adap.dev.parent,
"timeout waiting on completion\n");
- return -ETIMEDOUT;
- }
- return ret;
+ return -ETIMEDOUT;
}
cdns_i2c_writereg(CDNS_I2C_IXR_ALL_INTR_MASK,
CDNS_I2C_IDR_OFFSET);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] i2c-cadence: Do not let signals interrupt I2C transfers
2014-03-10 11:12 [PATCH] i2c-cadence: Do not let signals interrupt I2C transfers Mike Looijmans
@ 2014-03-10 21:59 ` Sören Brinkmann
[not found] ` <20140310215952.GF13293@xsjandreislx>
[not found] ` <1394449954-10797-1-git-send-email-mike.looijmans-Oq418RWZeHk@public.gmane.org>
2 siblings, 0 replies; 6+ messages in thread
From: Sören Brinkmann @ 2014-03-10 21:59 UTC (permalink / raw)
To: Mike Looijmans, Michal Simek; +Cc: git, wsa, linux-i2c, linux-kernel
Hi Mike,
The cadence driver is not in mainline yet. I think for our vendor tree
we can pretty much take it this way.
Regarding getting this into mainline, I'll send another iteration of the
change set and include these changes.
On Mon, 2014-03-10 at 12:12PM +0100, Mike Looijmans wrote:
> Pressing CTRL-C while communicating with an I2C device leads to erratic
> behaviour. The cause is that the controller will interrupt the I2C transfer
> in progress, and leave the client device in an undefined state. Many
> drivers do not handle error return codes on I2C transfers. The calling driver
> has no way of telling how much of the transfer has actually completed, so
> it cannot reliably determine the device's state.
>
> The best solution here is to not handle signals in the I2C bus driver at all,
> but always complete a transaction before returning control.
>
> See for a related patch and discussion on this topic:
> http://lkml.org/lkml/2014/1/9/246
Can we get your Signed-off-by, please?
> ---
> drivers/i2c/busses/i2c-cadence.c | 12 ++++--------
> 1 file changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
> index 86713d6..32ce2ee 100644
> --- a/drivers/i2c/busses/i2c-cadence.c
> +++ b/drivers/i2c/busses/i2c-cadence.c
> @@ -452,16 +452,12 @@ static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg,
> cdns_i2c_msend(id);
>
> /* Wait for the signal of completion */
> - ret = wait_for_completion_interruptible_timeout(
> - &id->xfer_done, HZ);
> - if (ret < 1) {
> + ret = wait_for_completion_timeout(&id->xfer_done, HZ);
> + if (ret == 0) {
To match the style used throughout the file this should just be
if (!ret) {
Acked-by: Soren Brinkmann <soren.brinkmann@xilinx.com>
Thanks,
Sören
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH] i2c-cadence: Do not let signals interrupt I2C transfers
[not found] ` <20140310215952.GF13293@xsjandreislx>
@ 2014-03-11 4:49 ` Suneel Garapati
[not found] ` <b6f0755f-cfc9-4962-851f-5eeac767e93e-dAX9Bq04yCSsiP+nND6G/7jjLBE8jN/0@public.gmane.org>
0 siblings, 1 reply; 6+ messages in thread
From: Suneel Garapati @ 2014-03-11 4:49 UTC (permalink / raw)
To: Soren Brinkmann, Mike Looijmans, Michal Simek
Cc: git, wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org,
linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Hi Mike/Soren,
> -----Original Message-----
> From: Sören Brinkmann [mailto:soren.brinkmann@xilinx.com]
> Sent: Tuesday, March 11, 2014 03:30
> To: Mike Looijmans; Michal Simek
> Cc: git; wsa@the-dreams.de; linux-i2c@vger.kernel.org; linux-
> kernel@vger.kernel.org
> Subject: Re: [PATCH] i2c-cadence: Do not let signals interrupt I2C transfers
>
> Hi Mike,
>
> The cadence driver is not in mainline yet. I think for our vendor tree we can
> pretty much take it this way.
> Regarding getting this into mainline, I'll send another iteration of the change
> set and include these changes.
>
> On Mon, 2014-03-10 at 12:12PM +0100, Mike Looijmans wrote:
> > Pressing CTRL-C while communicating with an I2C device leads to
> > erratic behaviour. The cause is that the controller will interrupt the
> > I2C transfer in progress, and leave the client device in an undefined
> > state. Many drivers do not handle error return codes on I2C transfers.
> > The calling driver has no way of telling how much of the transfer has
> > actually completed, so it cannot reliably determine the device's state.
> >
> > The best solution here is to not handle signals in the I2C bus driver
> > at all, but always complete a transaction before returning control.
> >
> > See for a related patch and discussion on this topic:
> > http://lkml.org/lkml/2014/1/9/246
>
> Can we get your Signed-off-by, please?
>
> > ---
> > drivers/i2c/busses/i2c-cadence.c | 12 ++++--------
> > 1 file changed, 4 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/i2c/busses/i2c-cadence.c
> > b/drivers/i2c/busses/i2c-cadence.c
> > index 86713d6..32ce2ee 100644
> > --- a/drivers/i2c/busses/i2c-cadence.c
> > +++ b/drivers/i2c/busses/i2c-cadence.c
> > @@ -452,16 +452,12 @@ static int cdns_i2c_process_msg(struct cdns_i2c
> *id, struct i2c_msg *msg,
> > cdns_i2c_msend(id);
> >
> > /* Wait for the signal of completion */
> > - ret = wait_for_completion_interruptible_timeout(
> > - &id->xfer_done, HZ);
> > - if (ret < 1) {
> > + ret = wait_for_completion_timeout(&id->xfer_done, HZ);
> > + if (ret == 0) {
>
> To match the style used throughout the file this should just be
> if (!ret) {
Instead of discarding Ctrl+C, Can we wait until the current msg transfer completes
[to avoid client undefined state or re-init the host to a known state]
I see da-vinci driver handling in a similar way.
Regards,
Suneel
>
>
> Acked-by: Soren Brinkmann <soren.brinkmann@xilinx.com>
>
> Thanks,
> Sören
This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] i2c-cadence: Do not let signals interrupt I2C transfers
[not found] ` <b6f0755f-cfc9-4962-851f-5eeac767e93e-dAX9Bq04yCSsiP+nND6G/7jjLBE8jN/0@public.gmane.org>
@ 2014-03-11 6:59 ` Mike Looijmans
0 siblings, 0 replies; 6+ messages in thread
From: Mike Looijmans @ 2014-03-11 6:59 UTC (permalink / raw)
To: Suneel Garapati, Soren Brinkmann, Michal Simek
Cc: git, wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org,
linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
On 03/11/2014 05:49 AM, Suneel Garapati wrote:
> Hi Mike/Soren,
>
>>
Met vriendelijke groet / kind regards,
Mike Looijmans
TOPIC Embedded Systems
Eindhovenseweg 32-C, NL-5683 KH Best
Postbus 440, NL-5680 AK Best
Telefoon: (+31) (0) 499 33 69 79
Telefax: (+31) (0) 499 33 69 70
E-mail: mike.looijmans-Oq418RWZeHk@public.gmane.org
Website: www.topic.nl
Please consider the environment before printing this e-mail
-----Original Message-----
>> From: Sören Brinkmann [mailto:soren.brinkmann-gjFFaj9aHVfQT0dZR+AlfA@public.gmane.org]
>> Sent: Tuesday, March 11, 2014 03:30
>> To: Mike Looijmans; Michal Simek
>> Cc: git; wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org; linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; linux-
>> kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
>> Subject: Re: [PATCH] i2c-cadence: Do not let signals interrupt I2C transfers
>>
>> Hi Mike,
>>
>> The cadence driver is not in mainline yet. I think for our vendor tree we can
>> pretty much take it this way.
>> Regarding getting this into mainline, I'll send another iteration of the change
>> set and include these changes.
>>
>> On Mon, 2014-03-10 at 12:12PM +0100, Mike Looijmans wrote:
>>> Pressing CTRL-C while communicating with an I2C device leads to
>>> erratic behaviour. The cause is that the controller will interrupt the
>>> I2C transfer in progress, and leave the client device in an undefined
>>> state. Many drivers do not handle error return codes on I2C transfers.
>>> The calling driver has no way of telling how much of the transfer has
>>> actually completed, so it cannot reliably determine the device's state.
>>>
>>> The best solution here is to not handle signals in the I2C bus driver
>>> at all, but always complete a transaction before returning control.
>>>
>>> See for a related patch and discussion on this topic:
>>> http://lkml.org/lkml/2014/1/9/246
>>
>> Can we get your Signed-off-by, please?
Sure, I forgot the -s, will add it in the next version.
>>
>>> ---
>>> drivers/i2c/busses/i2c-cadence.c | 12 ++++--------
>>> 1 file changed, 4 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/drivers/i2c/busses/i2c-cadence.c
>>> b/drivers/i2c/busses/i2c-cadence.c
>>> index 86713d6..32ce2ee 100644
>>> --- a/drivers/i2c/busses/i2c-cadence.c
>>> +++ b/drivers/i2c/busses/i2c-cadence.c
>>> @@ -452,16 +452,12 @@ static int cdns_i2c_process_msg(struct cdns_i2c
>> *id, struct i2c_msg *msg,
>>> cdns_i2c_msend(id);
>>>
>>> /* Wait for the signal of completion */
>>> - ret = wait_for_completion_interruptible_timeout(
>>> - &id->xfer_done, HZ);
>>> - if (ret < 1) {
>>> + ret = wait_for_completion_timeout(&id->xfer_done, HZ);
>>> + if (ret == 0) {
>>
>> To match the style used throughout the file this should just be
>> if (!ret) {
Will do.
> Instead of discarding Ctrl+C, Can we wait until the current msg transfer completes
> [to avoid client undefined state or re-init the host to a known state]
>
> I see da-vinci driver handling in a similar way.
My patch for the davinci should have completely ignored the signals too. I
haven't come across a driver that actually calls the xfer function with more
than one item anyway. If drivers check the result of the xfer at all, they
usually don't have a clue how to handle partial transfers. Many drivers just
ignore the return code completely and don't even report failure.
The gain is a stable I2C system. The loss here is something like <1ms more
latency to interrupt a process in the case it was just transferring I2C data.
From experience I can tell that the gain far outweighs that loss.
Mike.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] i2c-cadence: Do not let signals interrupt I2C transfers
[not found] ` <1394449954-10797-1-git-send-email-mike.looijmans-Oq418RWZeHk@public.gmane.org>
@ 2014-03-11 7:07 ` Mike Looijmans
[not found] ` <1394521655-3444-1-git-send-email-mike.looijmans-Oq418RWZeHk@public.gmane.org>
0 siblings, 1 reply; 6+ messages in thread
From: Mike Looijmans @ 2014-03-11 7:07 UTC (permalink / raw)
To: git-gjFFaj9aHVfQT0dZR+AlfA, wsa-z923LK4zBo2bacvFa/9K2g,
linux-i2c-u79uwXL29TY76Z2rM5mHXA
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA, Mike Looijmans
Pressing CTRL-C while communicating with an I2C device leads to erratic
behaviour. The cause is that the controller will interrupt the I2C transfer
in progress, and leave the client device in an undefined state. Many
drivers do not handle error return codes on I2C transfers. The calling driver
has no way of telling how much of the transfer has actually completed, so
it cannot reliably determine the device's state.
The best solution here is to not handle signals in the I2C bus driver at all,
but always complete a transaction before returning control.
See for a related patch and discussion on this topic:
http://lkml.org/lkml/2014/1/9/246
Signed-off-by: Mike Looijmans <mike.looijmans-Oq418RWZeHk@public.gmane.org>
---
drivers/i2c/busses/i2c-cadence.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index 86713d6..c61c3c9 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -452,16 +452,12 @@ static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg,
cdns_i2c_msend(id);
/* Wait for the signal of completion */
- ret = wait_for_completion_interruptible_timeout(
- &id->xfer_done, HZ);
- if (ret < 1) {
+ ret = wait_for_completion_timeout(&id->xfer_done, HZ);
+ if (!ret) {
cdns_i2c_master_reset(adap);
- if (!ret) {
- dev_err(id->adap.dev.parent,
+ dev_err(id->adap.dev.parent,
"timeout waiting on completion\n");
- return -ETIMEDOUT;
- }
- return ret;
+ return -ETIMEDOUT;
}
cdns_i2c_writereg(CDNS_I2C_IXR_ALL_INTR_MASK,
CDNS_I2C_IDR_OFFSET);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] i2c-cadence: Do not let signals interrupt I2C transfers
[not found] ` <1394521655-3444-1-git-send-email-mike.looijmans-Oq418RWZeHk@public.gmane.org>
@ 2014-03-11 16:00 ` Sören Brinkmann
0 siblings, 0 replies; 6+ messages in thread
From: Sören Brinkmann @ 2014-03-11 16:00 UTC (permalink / raw)
To: Mike Looijmans
Cc: git-gjFFaj9aHVfQT0dZR+AlfA, wsa-z923LK4zBo2bacvFa/9K2g,
linux-i2c-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
Hi Mike,
On Tue, 2014-03-11 at 08:07AM +0100, Mike Looijmans wrote:
> Pressing CTRL-C while communicating with an I2C device leads to erratic
> behaviour. The cause is that the controller will interrupt the I2C transfer
> in progress, and leave the client device in an undefined state. Many
> drivers do not handle error return codes on I2C transfers. The calling driver
> has no way of telling how much of the transfer has actually completed, so
> it cannot reliably determine the device's state.
>
> The best solution here is to not handle signals in the I2C bus driver at all,
> but always complete a transaction before returning control.
>
> See for a related patch and discussion on this topic:
> http://lkml.org/lkml/2014/1/9/246
>
> Signed-off-by: Mike Looijmans <mike.looijmans-Oq418RWZeHk@public.gmane.org>
Acked-by: Soren Brinkmann <soren.brinkmann-gjFFaj9aHVfQT0dZR+AlfA@public.gmane.org>
Thanks for the update. I'll take these changes and resubmit the driver
to LKML as well.
Sören
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-03-11 16:00 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-10 11:12 [PATCH] i2c-cadence: Do not let signals interrupt I2C transfers Mike Looijmans
2014-03-10 21:59 ` Sören Brinkmann
[not found] ` <20140310215952.GF13293@xsjandreislx>
2014-03-11 4:49 ` Suneel Garapati
[not found] ` <b6f0755f-cfc9-4962-851f-5eeac767e93e-dAX9Bq04yCSsiP+nND6G/7jjLBE8jN/0@public.gmane.org>
2014-03-11 6:59 ` Mike Looijmans
[not found] ` <1394449954-10797-1-git-send-email-mike.looijmans-Oq418RWZeHk@public.gmane.org>
2014-03-11 7:07 ` Mike Looijmans
[not found] ` <1394521655-3444-1-git-send-email-mike.looijmans-Oq418RWZeHk@public.gmane.org>
2014-03-11 16:00 ` Sören Brinkmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox