From: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
To: Troy Kisky
<troy.kisky-Q5RJGjKts06CY9SHAMCTRUEOCMrvLtNR@public.gmane.org>
Cc: i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org,
Kevin Hilman <khilman-Igf4POYTYCDQT0dZR+AlfA@public.gmane.org>
Subject: Re: [PATCH 4/5] I2C: DaVinci: fix signal handling bug
Date: Mon, 28 Apr 2008 19:13:32 +0200 [thread overview]
Message-ID: <20080428191332.371e35e3@hyperion.delvare> (raw)
In-Reply-To: <1209142694-30046-4-git-send-email-troy.kisky-Q5RJGjKts06CY9SHAMCTRUEOCMrvLtNR@public.gmane.org>
Hi Troy,
On Fri, 25 Apr 2008 09:58:13 -0700, Troy Kisky wrote:
> If wait_for_completion_interruptible_timeout exits due
> to a signal, the i2c bus was locking up.
What kind of signal (coming from where) are you talking about?
If you don't want to be interrupted, why don't you simply use
wait_for_completion_timeout() instead of
wait_for_completion_interruptible_timeout()?
>
> Signed-off-by: Troy Kisky <troy.kisky-Q5RJGjKts06CY9SHAMCTRUEOCMrvLtNR@public.gmane.org>
> Signed-off-by: Kevin Hilman <khilman-Igf4POYTYCDQT0dZR+AlfA@public.gmane.org>
> ---
> drivers/i2c/busses/i2c-davinci.c | 66 +++++++++++++++++++++++++++++++-------
> 1 files changed, 54 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
> index d9752ae..6719cdb 100644
> --- a/drivers/i2c/busses/i2c-davinci.c
> +++ b/drivers/i2c/busses/i2c-davinci.c
> @@ -85,6 +85,7 @@
> #define DAVINCI_I2C_MDR_MST (1 << 10)
> #define DAVINCI_I2C_MDR_TRX (1 << 9)
> #define DAVINCI_I2C_MDR_XA (1 << 8)
> +#define DAVINCI_I2C_MDR_RM (1 << 7)
> #define DAVINCI_I2C_MDR_IRS (1 << 5)
>
> #define DAVINCI_I2C_IMR_AAS (1 << 6)
> @@ -112,6 +113,7 @@ struct davinci_i2c_dev {
> u8 *buf;
> size_t buf_len;
> int irq;
> + u8 terminate;
> struct i2c_adapter adapter;
> };
>
> @@ -283,20 +285,31 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
> MOD_REG_BIT(w, DAVINCI_I2C_IMR_XRDY, 1);
> davinci_i2c_write_reg(dev, DAVINCI_I2C_IMR_REG, w);
>
> + dev->terminate = 0;
> /* write the data into mode register */
> davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);
>
> r = wait_for_completion_interruptible_timeout(&dev->cmd_complete,
> DAVINCI_I2C_TIMEOUT);
> - dev->buf_len = 0;
> - if (r < 0)
> - return r;
> -
> if (r == 0) {
> dev_err(dev->dev, "controller timed out\n");
> i2c_davinci_init(dev);
> + dev->buf = NULL;
> return -ETIMEDOUT;
> }
> + if (dev->buf_len) {
> + /* signal may have aborted the transfer */
> + if (r >= 0) {
> + dev_err(dev->dev, "abnormal termination buf_len=%i\n",
> + dev->buf_len);
> + r = -EREMOTEIO;
> + }
> + dev->terminate = 1;
> + wmb();
> + dev->buf = NULL;
> + }
> + if (r < 0)
> + return r;
>
> /* no error */
> if (likely(!dev->cmd_err))
> @@ -353,6 +366,30 @@ static u32 i2c_davinci_func(struct i2c_adapter *adap)
> return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK);
> }
>
> +static inline void terminate_read(struct davinci_i2c_dev *dev)
> +{
> + if (dev->buf_len)
> + dev->buf_len--;
> + if (dev->buf_len) {
Please explain (in a comment) what you are doing here. Can't you just
test for (dev->buf_len > 1)?
> + u16 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG);
> + w |= DAVINCI_I2C_MDR_NACK;
> + davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w);
> + }
> + /* Throw away data */
> + davinci_i2c_read_reg(dev, DAVINCI_I2C_DRR_REG);
> + if (!dev->terminate)
> + dev_err(dev->dev, "RDR IRQ while no data requested\n");
> +}
> +static inline void terminate_write(struct davinci_i2c_dev *dev)
> +{
> + u16 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG);
> + w |= DAVINCI_I2C_MDR_RM|DAVINCI_I2C_MDR_STP;
Coding-style: spaces around |.
> + davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w);
> +
> + if (!dev->terminate)
> + dev_err(dev->dev, "TDR IRQ while no data to send\n");
> +}
I don't see the point of inlining these functions explicitly... They
are only called in an unlikely event so this is certainly not
performance-critical.
> +
> /*
> * Interrupt service routine. This gets called whenever an I2C interrupt
> * occurs.
> @@ -373,12 +410,15 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id)
>
> switch (stat) {
> case DAVINCI_I2C_IVR_AL:
> + /* Arbitration lost, must retry */
> dev->cmd_err |= DAVINCI_I2C_STR_AL;
> + dev->buf_len = 0;
> complete(&dev->cmd_complete);
> break;
>
> case DAVINCI_I2C_IVR_NACK:
> dev->cmd_err |= DAVINCI_I2C_STR_NACK;
> + dev->buf_len = 0;
> complete(&dev->cmd_complete);
> break;
>
> @@ -389,7 +429,7 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id)
> break;
>
> case DAVINCI_I2C_IVR_RDR:
> - if (dev->buf_len) {
> + if (dev->buf && dev->buf_len) {
> *dev->buf++ =
> davinci_i2c_read_reg(dev,
> DAVINCI_I2C_DRR_REG);
> @@ -400,13 +440,14 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id)
> davinci_i2c_write_reg(dev,
> DAVINCI_I2C_STR_REG,
> DAVINCI_I2C_IMR_RRDY);
> - } else
> - dev_err(dev->dev, "RDR IRQ while no "
> - "data requested\n");
> + } else {
> + /* signal can terminate transfer */
> + terminate_read(dev);
> + }
> break;
>
> case DAVINCI_I2C_IVR_XRDY:
> - if (dev->buf_len) {
> + if (dev->buf && dev->buf_len) {
> davinci_i2c_write_reg(dev, DAVINCI_I2C_DXR_REG,
> *dev->buf++);
> dev->buf_len--;
> @@ -419,9 +460,10 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id)
> davinci_i2c_write_reg(dev,
> DAVINCI_I2C_IMR_REG,
> w);
> - } else
> - dev_err(dev->dev, "TDR IRQ while no data to "
> - "send\n");
> + } else {
> + /* signal can terminate transfer */
> + terminate_write(dev);
> + }
> break;
>
> case DAVINCI_I2C_IVR_SCD:
Apparently you are using dev->buf_len = 0 and dev->buf = NULL to notify
particular conditions accross the driver? This should be clearly
documented, otherwise other developers are likely to break the driver
while working on it.
--
Jean Delvare
_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c
next prev parent reply other threads:[~2008-04-28 17:13 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-25 16:58 [PATCH 1/5] I2C: DaVinci: clock between 7-12 MHz Troy Kisky
[not found] ` <1209142694-30046-1-git-send-email-troy.kisky-Q5RJGjKts06CY9SHAMCTRUEOCMrvLtNR@public.gmane.org>
2008-04-25 16:58 ` [PATCH 2/5] I2C: DaVinci: move dev_debug line for more output Troy Kisky
[not found] ` <1209142694-30046-2-git-send-email-troy.kisky-Q5RJGjKts06CY9SHAMCTRUEOCMrvLtNR@public.gmane.org>
2008-04-25 16:58 ` [PATCH 3/5] I2C: DaVinci: remove useless IVR read Troy Kisky
[not found] ` <1209142694-30046-3-git-send-email-troy.kisky-Q5RJGjKts06CY9SHAMCTRUEOCMrvLtNR@public.gmane.org>
2008-04-25 16:58 ` [PATCH 4/5] I2C: DaVinci: fix signal handling bug Troy Kisky
[not found] ` <1209142694-30046-4-git-send-email-troy.kisky-Q5RJGjKts06CY9SHAMCTRUEOCMrvLtNR@public.gmane.org>
2008-04-25 16:58 ` [PATCH 5/5] I2C: DaVinci: initialize cmd_complete sooner Troy Kisky
[not found] ` <1209142694-30046-5-git-send-email-troy.kisky-Q5RJGjKts06CY9SHAMCTRUEOCMrvLtNR@public.gmane.org>
2008-04-28 20:35 ` Jean Delvare
2008-04-28 17:13 ` Jean Delvare [this message]
[not found] ` <20080428191332.371e35e3-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-04-28 18:20 ` [PATCH 4/5] I2C: DaVinci: fix signal handling bug Troy Kisky
[not found] ` <48161578.3080000-Q5RJGjKts06CY9SHAMCTRUEOCMrvLtNR@public.gmane.org>
2008-04-28 20:50 ` Jean Delvare
[not found] ` <20080428225011.4d97736c-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-04-28 23:40 ` Troy Kisky
[not found] ` <4816608B.2000001-Q5RJGjKts06CY9SHAMCTRUEOCMrvLtNR@public.gmane.org>
2008-04-29 8:08 ` Jean Delvare
2008-04-28 16:08 ` [PATCH 3/5] I2C: DaVinci: remove useless IVR read Jean Delvare
2008-04-28 16:04 ` [PATCH 2/5] I2C: DaVinci: move dev_debug line for more output Jean Delvare
[not found] ` <20080428180437.272109dc-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-04-28 16:20 ` Troy Kisky
[not found] ` <4815F951.5030700-Q5RJGjKts06CY9SHAMCTRUEOCMrvLtNR@public.gmane.org>
2008-04-28 16:37 ` Jean Delvare
2008-04-28 14:32 ` [PATCH 1/5] I2C: DaVinci: clock between 7-12 MHz Jean Delvare
-- strict thread matches above, loose matches on Subject: below --
2008-03-21 3:06 [PATCH 0/5]I2C: Davinci host controller changes Troy Kisky
2008-03-21 3:06 ` [PATCH 1/5] I2C: DaVinci: fix lost interrupt Troy Kisky
2008-03-21 3:06 ` [PATCH 2/5] I2C: DaVinci: clock between 7-12 Mhz Troy Kisky
2008-03-21 3:06 ` [PATCH 3/5] I2C: DaVinci: remove useless IVR read Troy Kisky
[not found] ` <1206068770-15458-4-git-send-email-troy.kisky-Q5RJGjKts06CY9SHAMCTRUEOCMrvLtNR@public.gmane.org>
2008-03-21 3:06 ` [PATCH 4/5] I2C: DaVinci: fix signal handling bug Troy Kisky
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=20080428191332.371e35e3@hyperion.delvare \
--to=khali-puyad+kwke1g9huczpvpmw@public.gmane.org \
--cc=i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org \
--cc=khilman-Igf4POYTYCDQT0dZR+AlfA@public.gmane.org \
--cc=troy.kisky-Q5RJGjKts06CY9SHAMCTRUEOCMrvLtNR@public.gmane.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