public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
To: David Brownell <david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
Cc: i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
Subject: Re: [patch 2.6.25-git] i2c_adapters:  return -Errno not -1
Date: Sun, 18 May 2008 09:06:04 +0200	[thread overview]
Message-ID: <20080518090604.711a18cd@hyperion.delvare> (raw)
In-Reply-To: <200805171754.15976.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>

Hi David,

On Sat, 17 May 2008 17:54:15 -0700, David Brownell wrote:
> On Thursday 15 May 2008, Jean Delvare wrote:
> > Hi David,
> > On Mon, 12 May 2008 09:43:04 -0700, David Brownell wrote:
> > > @@ -164,13 +168,17 @@ static int ali1563_block_start(struct i2
> > >  
> > >  	if (timeout && !(data & HST_STS_BAD))
> > >  		return 0;
> > > +
> > > +	if (timeout == 0 && !(data & HST_STS_DONE))
> > > +		status = -ETIMEDOUT;
> > 
> > That's pretty strange to check for both timeout == 0 and !(data &
> > HST_STS_DONE), given that the former implies the latter if I read the
> > code correctly. The same strangeness is present in the code below, if
> > we print "Timeout" then we will also print "Transaction Never Finished".
> 
> Without chip docs, and knowing that it overloads lots of fault
> cases into not enough bits, I wouldn't rely on such conclusions.
> Instead, I just tried to make sure the ETIMEDOUT means exactly
> what is promised in the faultcode writeup.

This doesn't have anything to do with the hardware. The poll loop is:

	timeout = ALI1563_MAX_TIMEOUT;
	do
		msleep(1);
	while (!((data = inb_p(SMB_HST_STS)) & HST_STS_DONE) && --timeout);

Regardless of what the hardware does, it is simply impossible to have
timeout == 0 if you don't have !(data & HST_STS_DONE), because you
wouldn't decrease timeout if (data & HST_STS_DONE). This, testing for
just timeout == 0 after this loop is equivalent to testing for timeout
== 0 && !(data & HST_STS_DONE). As a matter of fact, the driver only
tests for timeout == 0 in ali1563_transaction() (although it doesn't
return -ETIMEDOUT there, we probably should fix that.)

> > >  		data & HST_STS_FAIL ? "Transaction Failed " : "",
> > >  		data & HST_STS_BUSERR ? "No response or Bus Collision " : "",
> > >  		data & HST_STS_DEVERR ? "Device Error " : "",
> > >  		!(data & HST_STS_DONE) ? "Transaction Never Finished " : "");
> > > -	return -1;
> > > +	return status;
> > >  }
> > 
> > I thought we had agreed that we would return -ENXIO for HST_STS_DEVERR,
> > as we already do in ali1563_transaction()?
> 
> I thought we'd agreed to not play guessing games about the behavior
> of chips we don't have docs for ... ;)

The problem is that in ali1563_transaction() we map (data &
HST_STS_DEVERR) to -ENXIO, so not doing the same in
ali1563_block_start() is somewhat inconsistent.

> Appended is a small fixup patch addressing the issues above ...
> 
> - Dave
> 
> 
> --- g26.orig/drivers/i2c/busses/i2c-ali1563.c	2008-05-17 17:53:24.000000000 -0700
> +++ g26/drivers/i2c/busses/i2c-ali1563.c	2008-05-17 17:48:01.000000000 -0700
> @@ -105,14 +105,6 @@ static int ali1563_transaction(struct i2
>  		data = inb_p(SMB_HST_STS);
>   	}
>  
> -	/* device error - no response, ignore the autodetection case */
> -	if (data & HST_STS_DEVERR) {
> -		if (size != HST_CNTL2_QUICK)
> -			dev_err(&a->dev, "Device error!\n");
> -		else
> -			return -ENXIO;
> -	}
> -
>  	/* bus collision */
>  	if (data & HST_STS_BUSERR) {
>  		dev_err(&a->dev, "Bus collision!\n");
> @@ -125,6 +117,13 @@ static int ali1563_transaction(struct i2
>  		outb_p(0x0,SMB_HST_CNTL2);
>  	}
>  
> +	/* device error - no response, ignore the autodetection case */
> +	if (data & HST_STS_DEVERR) {
> +		if (size != HST_CNTL2_QUICK)
> +			dev_err(&a->dev, "Device error!\n");
> +		return -ENXIO;
> +	}
> +
>  	return -EIO;
>  }
>  
> @@ -173,7 +172,7 @@ static int ali1563_block_start(struct i2
>  		status = -ETIMEDOUT;
>  
>  	dev_err(&a->dev, "SMBus Error: %s%s%s%s%s\n",
> -		timeout ? "Timeout " : "",
> +		timeout ? "" : "Timeout ",
>  		data & HST_STS_FAIL ? "Transaction Failed " : "",
>  		data & HST_STS_BUSERR ? "No response or Bus Collision " : "",
>  		data & HST_STS_DEVERR ? "Device Error " : "",
> --- g26.orig/drivers/i2c/busses/i2c-viapro.c	2008-05-17 17:53:24.000000000 -0700
> +++ g26/drivers/i2c/busses/i2c-viapro.c	2008-05-17 17:45:52.000000000 -0700
> @@ -184,15 +184,14 @@ static int vt596_transaction(u8 size)
>  
>  	if (temp & 0x04) {
>  		int read = inb_p(SMBHSTADD) & 0x01;
> -		result = -EIO;
> +
>  		/* The quick and receive byte commands are used to probe
>  		   for chips, so errors are expected, and we don't want
>  		   to frighten the user. */
>  		if (!((size == VT596_QUICK && !read) ||
>  		      (size == VT596_BYTE && read)))
>  			dev_err(&vt596_adapter.dev, "Transaction error!\n");
> -		else
> -			result = -ENXIO;
> +		result = -ENXIO;
>  	}
>  
>  	/* Resetting status register */

OK, I've merged that. I'll add a couple minor fixes as discussed above,
and then your patch is ready for linux-next. Thanks!

-- 
Jean Delvare

_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c

      parent reply	other threads:[~2008-05-18  7:06 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-02  3:46 [patch 2.6.25-git] i2c_adapters: return -Errno not -1 David Brownell
     [not found] ` <200805012046.07885.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-05-10 18:18   ` Jean Delvare
     [not found]     ` <20080510201825.489198d2-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-05-11  7:32       ` David Brownell
2008-05-12 16:48       ` David Brownell
     [not found]         ` <200805120948.23842.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-05-14 12:17           ` Jean Delvare
     [not found]             ` <20080514141738.327be680-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-05-14 14:48               ` David Brownell
2008-05-14 14:50               ` David Brownell
     [not found]                 ` <200805140750.49365.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-05-15 18:33                   ` Jean Delvare
2008-05-10 20:55   ` Jean Delvare
     [not found]     ` <20080510225548.36297637-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-05-11  8:17       ` David Brownell
     [not found]         ` <200805110117.23023.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-05-11 10:26           ` Jean Delvare
     [not found]             ` <20080511122647.1e04c9c0-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-05-11 16:23               ` David Brownell
     [not found]                 ` <200805110923.44693.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-05-12 14:05                   ` Jean Delvare
     [not found]                     ` <20080512160537.13e7739a-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-05-12 16:44                       ` David Brownell
2008-05-11 17:13       ` David Brownell
     [not found]         ` <200805111013.25440.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-05-12 13:05           ` Jean Delvare
     [not found]             ` <20080512150512.1837e3e7-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-05-12 16:25               ` David Brownell
     [not found]                 ` <200805120925.33533.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-05-12 16:54                   ` Jean Delvare
     [not found]                     ` <20080512185439.1a9cf3c1-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-05-12 17:08                       ` David Brownell
2008-05-11 17:16       ` David Brownell
2008-05-12 16:43       ` David Brownell
     [not found]         ` <200805120943.04899.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-05-15 17:16           ` Jean Delvare
     [not found]             ` <20080515191631.7791346c-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-05-18  0:54               ` David Brownell
     [not found]                 ` <200805171754.15976.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-05-18  7:06                   ` Jean Delvare [this message]

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=20080518090604.711a18cd@hyperion.delvare \
    --to=khali-puyad+kwke1g9huczpvpmw@public.gmane.org \
    --cc=david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org \
    --cc=i2c-GZX6beZjE8VD60Wz+7aTrA@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