All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jean Delvare <jdelvare@suse.de>
To: Terry Bowman <terry.bowman@amd.com>
Cc: <linux@roeck-us.net>, <linux-watchdog@vger.kernel.org>,
	<linux-i2c@vger.kernel.org>, <wsa@kernel.org>,
	<andy.shevchenko@gmail.com>, <rafael.j.wysocki@intel.com>,
	<linux-kernel@vger.kernel.org>, <wim@linux-watchdog.org>,
	<rrichter@amd.com>, <thomas.lendacky@amd.com>,
	<sudheesh.mavila@amd.com>, <Nehal-bakulchandra.Shah@amd.com>,
	<Basavaraj.Natikar@amd.com>, <Shyam-sundar.S-k@amd.com>,
	<Mario.Limonciello@amd.com>
Subject: Re: [PATCH v4 5/9] i2c: piix4: Move SMBus port selection into function
Date: Tue, 8 Feb 2022 16:29:44 +0100	[thread overview]
Message-ID: <20220208162944.3207577c@endymion.delvare> (raw)
In-Reply-To: <20220130184130.176646-6-terry.bowman@amd.com>

On Sun, 30 Jan 2022 12:41:26 -0600, Terry Bowman wrote:
> Move port selection code into a separate function. Refactor is in
> preparation for following MMIO changes.
> 
> Signed-off-by: Terry Bowman <terry.bowman@amd.com>
> ---
>  drivers/i2c/busses/i2c-piix4.c | 26 ++++++++++++++++----------
>  1 file changed, 16 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
> index eab06e9e5fdf..32a30af5778a 100644
> --- a/drivers/i2c/busses/i2c-piix4.c
> +++ b/drivers/i2c/busses/i2c-piix4.c
> @@ -699,6 +699,19 @@ static void piix4_imc_wakeup(void)
>  	release_region(KERNCZ_IMC_IDX, 2);
>  }
>  
> +static int piix4_sb800_port_sel(u8 port)
> +{
> +	u8 smba_en_lo, val;
> +
> +	outb_p(piix4_port_sel_sb800, SB800_PIIX4_SMB_IDX);
> +	smba_en_lo = inb_p(SB800_PIIX4_SMB_IDX + 1);
> +
> +	val = (smba_en_lo & ~piix4_port_mask_sb800) | port;
> +	if (smba_en_lo != val)
> +		outb_p(val, SB800_PIIX4_SMB_IDX + 1);
> +
> +	return (smba_en_lo & piix4_port_mask_sb800);
> +}
>  /*
>   * Handles access to multiple SMBus ports on the SB800.
>   * The port is selected by bits 2:1 of the smb_en register (0x2c).
> @@ -715,8 +728,7 @@ static s32 piix4_access_sb800(struct i2c_adapter *adap, u16 addr,
>  	unsigned short piix4_smba = adapdata->smba;
>  	int retries = MAX_TIMEOUT;
>  	int smbslvcnt;
> -	u8 smba_en_lo;
> -	u8 port;
> +	u8 prev_port;
>  	int retval;
>  
>  	retval = piix4_sb800_region_request(&adap->dev);
> @@ -776,18 +788,12 @@ static s32 piix4_access_sb800(struct i2c_adapter *adap, u16 addr,
>  		}
>  	}
>  
> -	outb_p(piix4_port_sel_sb800, SB800_PIIX4_SMB_IDX);
> -	smba_en_lo = inb_p(SB800_PIIX4_SMB_IDX + 1);
> -
> -	port = adapdata->port;
> -	if ((smba_en_lo & piix4_port_mask_sb800) != port)
> -		outb_p((smba_en_lo & ~piix4_port_mask_sb800) | port,
> -		       SB800_PIIX4_SMB_IDX + 1);
> +	prev_port = piix4_sb800_port_sel(adapdata->port);
>  
>  	retval = piix4_access(adap, addr, flags, read_write,
>  			      command, size, data);
>  
> -	outb_p(smba_en_lo, SB800_PIIX4_SMB_IDX + 1);
> +	piix4_sb800_port_sel(prev_port);
>  
>  	/* Release the semaphore */
>  	outb_p(smbslvcnt | 0x20, SMBSLVCNT);

Hmm, this gets pretty inefficient. You set SB800_PIIX4_SMB_IDX to
piix4_port_sel_sb800 twice and compare the new port with the previous
port twice, even though the result will inevitably be the same. The
original code would just unconditionally restore the original port
value, which was also not always needed, but was cheaper in the end.

I can't really think of a better way though, so, so be it :-(

I wonder why we insist on restoring the port though. When you read
multiple values from the same bus (and I2C device drivers do that a
lot, obviously) you end up switching ports a lot for no good reason. I
looked at the git history and it has been that way since support for
the multiplexed buses was added back in 2015. There's a mutex
protecting that section of code anyway, so I don't think restoring the
port buys us anything we did not already have. The only benefit I can
see is to leave the port setting in its original state on suspend and
shutdown (and we know by experience that it can be important to the
BIOS) but then we should just do it in the suspend and remove
functions, instead of after every transfer.

-- 
Jean Delvare
SUSE L3 Support

  reply	other threads:[~2022-02-08 15:29 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-30 18:41 [PATCH v4 0/9] i2c: piix4: Replace cd6h/cd7h port I/O accesses with MMIO accesses Terry Bowman
2022-01-30 18:41 ` [PATCH v4 1/9] kernel/resource: Introduce request_mem_region_muxed() Terry Bowman
2022-01-30 18:41 ` [PATCH v4 2/9] i2c: piix4: Replace hardcoded memory map size with a #define Terry Bowman
2022-01-30 18:41 ` [PATCH v4 3/9] i2c: piix4: Move port I/O region request/release code into functions Terry Bowman
2022-02-08 14:45   ` Jean Delvare
2022-02-08 15:15     ` Terry Bowman
2022-01-30 18:41 ` [PATCH v4 4/9] i2c: piix4: Move SMBus controller base address detect into function Terry Bowman
2022-02-08 15:09   ` Jean Delvare
2022-01-30 18:41 ` [PATCH v4 5/9] i2c: piix4: Move SMBus port selection " Terry Bowman
2022-02-08 15:29   ` Jean Delvare [this message]
2022-01-30 18:41 ` [PATCH v4 6/9] i2c: piix4: Add EFCH MMIO support to region request and release Terry Bowman
2022-02-08 15:49   ` Jean Delvare
2022-01-30 18:41 ` [PATCH v4 7/9] i2c: piix4: Add EFCH MMIO support to SMBus base address detect Terry Bowman
2022-01-30 18:41 ` [PATCH v4 8/9] i2c: piix4: Add EFCH MMIO support for SMBus port select Terry Bowman
2022-02-08 16:19   ` Jean Delvare
2022-01-30 18:41 ` [PATCH v4 9/9] i2c: piix4: Enable EFCH MMIO for Family 17h+ Terry Bowman
2022-02-08 16:33   ` Jean Delvare
2022-02-08 20:10     ` Andy Shevchenko
2022-02-08 21:00       ` Terry Bowman
2022-01-31 11:01 ` [PATCH v4 0/9] i2c: piix4: Replace cd6h/cd7h port I/O accesses with MMIO accesses Andy Shevchenko
2022-02-01 15:21   ` Terry Bowman
2022-02-07 12:08 ` Wolfram Sang
2022-02-08 17:11 ` Jean Delvare
2022-02-08 19:36   ` Terry Bowman
2022-02-08 21:46     ` Jean Delvare
2022-02-08 23:03       ` Terry Bowman
2022-02-09  7:04         ` Jean Delvare

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=20220208162944.3207577c@endymion.delvare \
    --to=jdelvare@suse.de \
    --cc=Basavaraj.Natikar@amd.com \
    --cc=Mario.Limonciello@amd.com \
    --cc=Nehal-bakulchandra.Shah@amd.com \
    --cc=Shyam-sundar.S-k@amd.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rrichter@amd.com \
    --cc=sudheesh.mavila@amd.com \
    --cc=terry.bowman@amd.com \
    --cc=thomas.lendacky@amd.com \
    --cc=wim@linux-watchdog.org \
    --cc=wsa@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.