Message ID | 1394449954-10797-1-git-send-email-mike.looijmans@topic.nl |
---|---|
State | Superseded |
Headers | show |
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 -- To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
SGkgTWlrZS9Tb3JlbiwNCg0KPiAtLS0tLU9yaWdpbmFsIE1lc3NhZ2UtLS0tLQ0KPiBGcm9tOiBT w7ZyZW4gQnJpbmttYW5uIFttYWlsdG86c29yZW4uYnJpbmttYW5uQHhpbGlueC5jb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tub3duIHN0YXRlXQ0KDQpJIHNl ZSBkYS12aW5jaSBkcml2ZXIgaGFuZGxpbmcgaW4gYSBzaW1pbGFyIHdheS4NCg0KUmVnYXJkcywN ClN1bmVlbA0KDQo+DQo+DQo+IEFja2VkLWJ5OiBTb3JlbiBCcmlua21hbm4gPHNvcmVuLmJyaW5r bWFubkB4aWxpbnguY29tPg0KPg0KPiAgICAgICBUaGFua3MsDQo+ICAgICAgIFPDtnJlbg0KDQoN Cg0KVGhpcyBlbWFpbCBhbmQgYW55IGF0dGFjaG1lbnRzIGFyZSBpbnRlbmRlZCBmb3IgdGhlIHNv bGUgdXNlIG9mIHRoZSBuYW1lZCByZWNpcGllbnQocykgYW5kIGNvbnRhaW4ocykgY29uZmlkZW50 aWFsIGluZm9ybWF0aW9uIHRoYXQgbWF5IGJlIHByb3ByaWV0YXJ5LCBwcml2aWxlZ2VkIG9yIGNv cHlyaWdodGVkIHVuZGVyIGFwcGxpY2FibGUgbGF3LiBJZiB5b3UgYXJlIG5vdCB0aGUgaW50ZW5k ZWQgcmVjaXBpZW50LCBkbyBub3QgcmVhZCwgY29weSwgb3IgZm9yd2FyZCB0aGlzIGVtYWlsIG1l c3NhZ2Ugb3IgYW55IGF0dGFjaG1lbnRzLiBEZWxldGUgdGhpcyBlbWFpbCBtZXNzYWdlIGFuZCBh bnkgYXR0YWNobWVudHMgaW1tZWRpYXRlbHkuDQoNCgoK -- To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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@topic.nl Website: www.topic.nl Please consider the environment before printing this e-mail -----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? 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. -- To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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);