linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Cc: Jean Delvare <jdelvare@suse.com>,
	Wolfram Sang <wsa@the-dreams.de>,
	linux-i2c@vger.kernel.org,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] i2c: piix4: Avoid race conditions with IMC
Date: Wed, 11 Jan 2017 18:39:43 +0200	[thread overview]
Message-ID: <CAHp75VeV2TfgfaYni7oS4ax4H87euJa9ReWX+vYjZ4b5nYRsMg@mail.gmail.com> (raw)
In-Reply-To: <20170111091144.6881-1-ricardo.ribalda@gmail.com>

On Wed, Jan 11, 2017 at 11:11 AM, Ricardo Ribalda Delgado
<ricardo.ribalda@gmail.com> wrote:
> On AMD's SB800 and upwards, the SMBus is shared with the Integrated
> Micro Controller (IMC).
>
> The platform provides a hardware semaphore to avoid race conditions
> among them. (Check page 288 of the SB800-Series Southbridges Register
> Reference Guide http://support.amd.com/TechDocs/45482.pdf)
>
> Without this patch, many access to the SMBus end with an invalid
> transaction or even with the bus stalled.
>

After addressing below comment
FWIW: Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>:

> Credit-to: Alexandre Desnoyers <alex@qtec.com>

It would be nice to put in plain test what you tell in the discussion
here instead of non-standard (see submitting-patches.rst) tag.

> Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
> ---
>
> v2: Suggestions by Andy Shevchenko <andy.shevchenko@gmail.com>:
>  -Rename timeout to retries
>  -Use do {} while(--retries) pattern
>  -Group new variables
>
>
>  drivers/i2c/busses/i2c-piix4.c | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
>
> diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
> index f0563f7ce01b..81d06be0a72d 100644
> --- a/drivers/i2c/busses/i2c-piix4.c
> +++ b/drivers/i2c/busses/i2c-piix4.c
> @@ -585,10 +585,29 @@ static s32 piix4_access_sb800(struct i2c_adapter *adap, u16 addr,
>                  u8 command, int size, union i2c_smbus_data *data)
>  {
>         struct i2c_piix4_adapdata *adapdata = i2c_get_adapdata(adap);
> +       unsigned short piix4_smba = adapdata->smba;
> +       int retries = MAX_TIMEOUT;
> +       int smbslvcnt;
>         u8 smba_en_lo;
>         u8 port;
>         int retval;
>
> +       /* Request the SMBUS semaphore, avoid conflicts with the IMC */
> +       smbslvcnt  = inb_p(SMBSLVCNT);
> +       do {
> +               outb_p(smbslvcnt | 0x10, SMBSLVCNT);
> +
> +               /* Check the semaphore status */
> +               smbslvcnt  = inb_p(SMBSLVCNT);
> +               if (smbslvcnt & 0x10)
> +                       break;
> +
> +               usleep_range(1000, 2000);
> +       } while (--retries);
> +       /* SMBus is still owned by the IMC, we give up */
> +       if (!retries)
> +               return -EBUSY;
> +
>         mutex_lock(&piix4_mutex_sb800);
>
>         outb_p(piix4_port_sel_sb800, SB800_PIIX4_SMB_IDX);
> @@ -606,6 +625,9 @@ static s32 piix4_access_sb800(struct i2c_adapter *adap, u16 addr,
>
>         mutex_unlock(&piix4_mutex_sb800);
>
> +       /* Release the semaphore */
> +       outb_p(smbslvcnt | 0x20, SMBSLVCNT);
> +
>         return retval;
>  }
>
> --
> 2.11.0
>



-- 
With Best Regards,
Andy Shevchenko

  reply	other threads:[~2017-01-11 16:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-11  9:11 [PATCH v2] i2c: piix4: Avoid race conditions with IMC Ricardo Ribalda Delgado
2017-01-11 16:39 ` Andy Shevchenko [this message]
2017-01-12 19:29   ` Wolfram Sang
2017-01-12 19:36     ` Andy Shevchenko
2017-01-12 19:54       ` Wolfram Sang
2017-01-12 20:02         ` Ricardo Ribalda Delgado
2017-01-12 20:27           ` Wolfram Sang
2017-01-12 20:42           ` Andy Shevchenko

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=CAHp75VeV2TfgfaYni7oS4ax4H87euJa9ReWX+vYjZ4b5nYRsMg@mail.gmail.com \
    --to=andy.shevchenko@gmail.com \
    --cc=jdelvare@suse.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ricardo.ribalda@gmail.com \
    --cc=wsa@the-dreams.de \
    /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).