All of lore.kernel.org
 help / color / mirror / Atom feed
From: Quan Nguyen <quan@os.amperecomputing.com>
To: Mark Brown <broonie@kernel.org>
Cc: Joel Stanley <joel@jms.id.au>, Andrew Jeffery <andrew@aj.id.au>,
	Jean Delvare <jdelvare@suse.com>,
	Guenter Roeck <linux@roeck-us.net>,
	Rob Herring <robh+dt@kernel.org>,
	Lee Jones <lee.jones@linaro.org>,
	Jonathan Corbet <corbet@lwn.net>,
	linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-aspeed@lists.ozlabs.org, openbmc@lists.ozlabs.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	Derek Kiernan <derek.kiernan@xilinx.com>,
	Dragan Cvetic <dragan.cvetic@xilinx.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Gustavo Pimentel <Gustavo.Pimentel@synopsys.com>,
	Open Source Submission <patches@amperecomputing.com>,
	Phong Vo <phong@os.amperecomputing.com>,
	"Thang Q . Nguyen" <thang@os.amperecomputing.com>
Subject: Re: [PATCH v6 6/9] misc: smpro-errmon: Add Ampere's SMpro error monitor driver
Date: Mon, 7 Mar 2022 15:30:42 +0700	[thread overview]
Message-ID: <e6644ea3-71b2-d045-be74-77792baf6dc2@os.amperecomputing.com> (raw)
In-Reply-To: <YcXLGYWx4gYq/Y+J@sirena.org.uk>

On 24/12/2021 20:28, Mark Brown wrote:
> On Fri, Dec 24, 2021 at 11:13:49AM +0700, Quan Nguyen wrote:
> 
>> +static int read_i2c_block_data(struct i2c_client *client, u16 address, u16 length, u8 *data)
>> +{
>> +	unsigned char outbuf[MAX_READ_BLOCK_LENGTH];
>> +	unsigned char inbuf[2];
>> +	struct i2c_msg msgs[2];
>> +	ssize_t ret;
>> +
>> +	inbuf[0] = (address & 0xff);
>> +	inbuf[1] = length;
>> +
>> +	msgs[0].addr = client->addr;
>> +	msgs[0].flags = client->flags & I2C_M_TEN;
>> +	msgs[0].len = 2;
>> +	msgs[0].buf = inbuf;
>> +
>> +	msgs[1].addr = client->addr;
>> +	msgs[1].flags = (client->flags  & I2C_M_TEN) | I2C_M_RD;
>> +	msgs[1].len = length;
>> +	msgs[1].buf = outbuf;
>> +
>> +	ret = i2c_transfer(client->adapter, msgs, NUM_I2C_MESSAGES);
>> +	if (ret < 0)
> 
> regmap already supports bulk data access so it's not clear why we
> would open code this.  Given that this is a single I2C transfer
> it's also unclear why we'd need to export the regmap lock - a
> single I2C transfer is atomic at the bus level so the regmap lock
> isn't providing any additional concurrency protection.

Thanks a lot for the review, Mark.
Even though the single i2c transfer is atomic at the bus level, but my 
concerns is that the transfer may be interlaced with some other 
transaction from the regmap which was guarded by regmap's lock. And so 
making these accesses atomic in regmap level should be done as well. 
That is why I need the regmap's lock export for user driver.

But your comment made re-think about the code, and I think we can handle 
multiple types of transfer by using remap_bus->read/write(). The 
read_i2c_block_data() is now replaced by regmap_noinc_read() and hence, 
remove the use of regmap's lock. These changes will be included in my 
next version.

Thanks,
- Quan

WARNING: multiple messages have this Message-ID (diff)
From: Quan Nguyen <quan@os.amperecomputing.com>
To: Mark Brown <broonie@kernel.org>
Cc: linux-aspeed@lists.ozlabs.org, linux-doc@vger.kernel.org,
	Dragan Cvetic <dragan.cvetic@xilinx.com>,
	Phong Vo <phong@os.amperecomputing.com>,
	Lee Jones <lee.jones@linaro.org>,
	Jonathan Corbet <corbet@lwn.net>,
	openbmc@lists.ozlabs.org,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	Joel Stanley <joel@jms.id.au>,
	Derek Kiernan <derek.kiernan@xilinx.com>,
	Guenter Roeck <linux@roeck-us.net>,
	devicetree@vger.kernel.org, Jean Delvare <jdelvare@suse.com>,
	Arnd Bergmann <arnd@arndb.de>,
	"Thang Q . Nguyen" <thang@os.amperecomputing.com>,
	Rob Herring <robh+dt@kernel.org>,
	Open Source Submission <patches@amperecomputing.com>,
	linux-hwmon@vger.kernel.org, Andrew Jeffery <andrew@aj.id.au>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org,
	Gustavo Pimentel <Gustavo.Pimentel@synopsys.com>
Subject: Re: [PATCH v6 6/9] misc: smpro-errmon: Add Ampere's SMpro error monitor driver
Date: Mon, 7 Mar 2022 15:30:42 +0700	[thread overview]
Message-ID: <e6644ea3-71b2-d045-be74-77792baf6dc2@os.amperecomputing.com> (raw)
In-Reply-To: <YcXLGYWx4gYq/Y+J@sirena.org.uk>

On 24/12/2021 20:28, Mark Brown wrote:
> On Fri, Dec 24, 2021 at 11:13:49AM +0700, Quan Nguyen wrote:
> 
>> +static int read_i2c_block_data(struct i2c_client *client, u16 address, u16 length, u8 *data)
>> +{
>> +	unsigned char outbuf[MAX_READ_BLOCK_LENGTH];
>> +	unsigned char inbuf[2];
>> +	struct i2c_msg msgs[2];
>> +	ssize_t ret;
>> +
>> +	inbuf[0] = (address & 0xff);
>> +	inbuf[1] = length;
>> +
>> +	msgs[0].addr = client->addr;
>> +	msgs[0].flags = client->flags & I2C_M_TEN;
>> +	msgs[0].len = 2;
>> +	msgs[0].buf = inbuf;
>> +
>> +	msgs[1].addr = client->addr;
>> +	msgs[1].flags = (client->flags  & I2C_M_TEN) | I2C_M_RD;
>> +	msgs[1].len = length;
>> +	msgs[1].buf = outbuf;
>> +
>> +	ret = i2c_transfer(client->adapter, msgs, NUM_I2C_MESSAGES);
>> +	if (ret < 0)
> 
> regmap already supports bulk data access so it's not clear why we
> would open code this.  Given that this is a single I2C transfer
> it's also unclear why we'd need to export the regmap lock - a
> single I2C transfer is atomic at the bus level so the regmap lock
> isn't providing any additional concurrency protection.

Thanks a lot for the review, Mark.
Even though the single i2c transfer is atomic at the bus level, but my 
concerns is that the transfer may be interlaced with some other 
transaction from the regmap which was guarded by regmap's lock. And so 
making these accesses atomic in regmap level should be done as well. 
That is why I need the regmap's lock export for user driver.

But your comment made re-think about the code, and I think we can handle 
multiple types of transfer by using remap_bus->read/write(). The 
read_i2c_block_data() is now replaced by regmap_noinc_read() and hence, 
remove the use of regmap's lock. These changes will be included in my 
next version.

Thanks,
- Quan

  reply	other threads:[~2022-03-07  8:31 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-24  4:13 [PATCH v6 0/9] Add Ampere's Altra SMPro MFD and its child drivers Quan Nguyen
2021-12-24  4:13 ` Quan Nguyen
2021-12-24  4:13 ` [PATCH v6 1/9] dt-bindings: mfd: Add bindings for Ampere Altra SMPro MFD driver Quan Nguyen
2021-12-24  4:13   ` Quan Nguyen
2021-12-24  4:13 ` [PATCH v6 2/9] mfd: smpro-mfd: Adds Ampere's Altra SMpro " Quan Nguyen
2021-12-24  4:13   ` Quan Nguyen
2022-02-08  9:12   ` Lee Jones
2022-02-08  9:12     ` Lee Jones
2022-03-07  8:31   ` Quan Nguyen
2022-03-07  8:31     ` Quan Nguyen
2021-12-24  4:13 ` [PATCH v6 3/9] hwmon: smpro: Add Ampere's Altra smpro-hwmon driver Quan Nguyen
2021-12-24  4:13   ` Quan Nguyen
2021-12-24  4:13 ` [PATCH v6 4/9] docs: hwmon: (smpro-hwmon) Add documentation Quan Nguyen
2021-12-24  4:13   ` Quan Nguyen
2021-12-24  4:13 ` [PATCH v6 5/9] regmap: Introduces regmap lock helpers Quan Nguyen
2021-12-24  4:13   ` Quan Nguyen
2021-12-24 13:19   ` Mark Brown
2021-12-24 13:19     ` Mark Brown
2022-03-07  8:31     ` Quan Nguyen
2022-03-07  8:31       ` Quan Nguyen
2021-12-24  4:13 ` [PATCH v6 6/9] misc: smpro-errmon: Add Ampere's SMpro error monitor driver Quan Nguyen
2021-12-24  4:13   ` Quan Nguyen
2021-12-24  8:32   ` Greg Kroah-Hartman
2021-12-24  8:32     ` Greg Kroah-Hartman
2022-03-07  8:32     ` Quan Nguyen
2022-03-07  8:32       ` Quan Nguyen
2021-12-24 13:28   ` Mark Brown
2021-12-24 13:28     ` Mark Brown
2022-03-07  8:30     ` Quan Nguyen [this message]
2022-03-07  8:30       ` Quan Nguyen
2021-12-28  6:31   ` kernel test robot
2021-12-29 10:16   ` Lee Jones
2021-12-29 10:16     ` Lee Jones
2022-03-07  8:31   ` Quan Nguyen
2022-03-07  8:31     ` Quan Nguyen
2021-12-24  4:13 ` [PATCH v6 7/9] docs: misc-devices: (smpro-errmon) Add documentation Quan Nguyen
2021-12-24  4:13   ` Quan Nguyen
2021-12-24  4:13 ` [PATCH v6 8/9] misc: smpro-misc: Add Ampere's Altra SMpro misc driver Quan Nguyen
2021-12-24  4:13   ` Quan Nguyen
2021-12-29 10:18   ` Lee Jones
2021-12-29 10:18     ` Lee Jones
2022-03-07  8:32   ` Quan Nguyen
2022-03-07  8:32     ` Quan Nguyen
2022-03-07 13:16     ` Arnd Bergmann
2022-03-07 13:16       ` Arnd Bergmann
2021-12-24  4:13 ` [PATCH v6 9/9] docs: misc-devices: (smpro-misc) Add documentation Quan Nguyen
2021-12-24  4:13   ` Quan Nguyen

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=e6644ea3-71b2-d045-be74-77792baf6dc2@os.amperecomputing.com \
    --to=quan@os.amperecomputing.com \
    --cc=Gustavo.Pimentel@synopsys.com \
    --cc=andrew@aj.id.au \
    --cc=arnd@arndb.de \
    --cc=broonie@kernel.org \
    --cc=corbet@lwn.net \
    --cc=derek.kiernan@xilinx.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dragan.cvetic@xilinx.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jdelvare@suse.com \
    --cc=joel@jms.id.au \
    --cc=lee.jones@linaro.org \
    --cc=linux-aspeed@lists.ozlabs.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=openbmc@lists.ozlabs.org \
    --cc=patches@amperecomputing.com \
    --cc=phong@os.amperecomputing.com \
    --cc=rafael@kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=thang@os.amperecomputing.com \
    /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.