linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: "Jan Dąbroś" <jsd@semihalf.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-i2c <linux-i2c@vger.kernel.org>,
	Jarkko Nikula <jarkko.nikula@linux.intel.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	Wolfram Sang <wsa@kernel.org>,
	Raul E Rangel <rrangel@chromium.org>,
	Marcin Wojtas <mw@semihalf.com>,
	Grzegorz Jaszczyk <jaz@semihalf.com>,
	upstream@semihalf.com, mario.limonciello@amd.com
Subject: Re: [PATCH 2/2] i2c: designware: Add AMD PSP I2C bus support
Date: Mon, 24 Jan 2022 15:27:45 +0100	[thread overview]
Message-ID: <ca28b3eb-c06d-f8e3-c930-95da631e9a93@redhat.com> (raw)
In-Reply-To: <CAOtMz3Om=R-mFbi-PRkB4zwO_j1Dc4QRH-Z0HDCk_XwWif7Pog@mail.gmail.com>

Hi,

On 1/24/22 13:35, Jan Dąbroś wrote:
> pt., 21 sty 2022 o 11:32 Hans de Goede <hdegoede@redhat.com> napisał(a):
>>
>> Hi Jan,
>>
>> On 1/21/22 10:59, Jan Dąbroś wrote:

<snip>

>>>> Also I don't think you are allowed to use the bus_locking code
>>>> like this. The i2c bus-locking code is intended to deal with
>>>> busses which have muxes in them, where the mux must be set
>>>> to the right branch of the bus to reach the client and then
>>>> not be changed during the transfer to that client.
>>>>
>>>> So i2c-client drivers are never supposed to directly call
>>>> the bus-locking functions.
>>>
>>> I think you are not correct here. There are examples of i2c-clients
>>> which are using i2c bus_locking for the purpose of locking adapter for
>>> the bunch of i2c transactions.
>>>
>>> As an example let's take drivers/char/tpm/tpm_tis_i2c_cr50.c. It
>>> operates in write-wait-read model and there is i2c_lock_bus() call
>>> used to ensure that bus won't be released -
>>> https://github.com/torvalds/linux/blob/master/drivers/char/tpm/tpm_tis_i2c_cr50.c#L202.
>>>
>>> Similar model is followed in drivers/char/tpm/tpm_i2c_infineon.c and
>>> couple of other i2c-client drivers.
>>
>> Ah I see, interesting (live and learn).
>>
>> But this is then combined with using the special __i2c_transfer()
>> function for the actual i2c reads/writes, since using the regular
>> i2c_transfer() function after already taking the lock would deadlock.
> 
> Correct. In other words, if i2c-client wants to block the bus/adapter
> for more than one transaction it must use some special methods. This
> isn't changed with my patchset. If one is using "normal"
> i2c_transfer(), we should be on the safe side, nothing will change
> from the i2c-client point of view. The same if one is using
> __i2c_transfer().
> 
>>
>> There is a similar unlocked raw __i2c_smbus_xfer(), but as the
>> comment in include/linux/i2c.h above the locked i2c_smbus_xfer() says:
>>
>> /* This is the very generalized SMBus access routine. You probably do not
>>    want to use this, though; one of the functions below may be much easier,
>>    and probably just as fast.
>>    Note that we use i2c_adapter here, because you do not need a specific
>>    smbus adapter to call this function. */
>> s32 i2c_smbus_xfer(...);
>>
>> So in this case a driver cannot use the usual
>> i2c_smbus_read_byte/word/byte_data/word_data() helpers and
>> the same for writes. Also using an i2c_regmap (which is used
>> in a ton of places like PMIC drivers) will not work this way.
> 
> Right, however this behavior is not altered by my patch. I just wanted
> to ensure that drivers which are already using i2c bus_locking will
> still work as expected.

Ah I see, I thought that maybe you wanted to add extra i2c bus-locking
calls to some drivers which don't have them yet to ensure that the
AMD PSP semaphore would be hold over multiple transfers in
drivers which don't do this yet.

>> So yes you can use i2c_bus_lock() for this; but only if all the
>> drivers where you want to do that limit themselves to
>> __i2c_transfer() and __i2c_smbus_xfer() calls and/or are
>> rewritten to only use those.
> 
> My goal is to not modify current behavior, that is - we don't need to
> modify clients' drivers and extra quirks applied by amdpsp semaphore
> will be "transparent" for them. IOW, switch from generic
> i2c-designware to i2c-designware-amdpsp should be invisible from the
> i2c bus perspective for i2c-clients.

Ok, I believe everything is fine as is then. My worries where about
extending the i2c bus-locking to more drivers, but if there are no
plans for that then everything is good.

Regards,

Hans


  reply	other threads:[~2022-01-24 14:27 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-20  0:16 [PATCH 0/2] i2c-designware: Add support for AMD PSP semaphore Jan Dabros
2022-01-20  0:16 ` [PATCH 1/2] i2c: designware: Add missing locks Jan Dabros
2022-01-20 11:25   ` Hans de Goede
2022-01-24 10:33     ` Jan Dąbroś
2022-01-28 14:48   ` [PATCH v2 0/2] i2c-designware: Add support for AMD PSP semaphore Jan Dabros
2022-01-28 14:48     ` [PATCH v2 1/2] i2c: designware: Add missing locks Jan Dabros
2022-01-28 14:48     ` [PATCH v2 2/2] i2c: designware: Add AMD PSP I2C bus support Jan Dabros
2022-01-28 14:59       ` Jan Dąbroś
2022-01-28 15:49         ` Andy Shevchenko
2022-01-31 12:10           ` Jan Dąbroś
     [not found]           ` <CAOtMz3Oryr7mmRKf+secix_6=ZD_Lq+pMUoP=5T6AS6BPoqyQw@mail.gmail.com>
2022-01-31 13:31             ` Andy Shevchenko
2022-02-02 14:42               ` Jan Dąbroś
2022-01-28 14:58     ` [PATCH v2 0/2] i2c-designware: Add support for AMD PSP semaphore Jan Dąbroś
2022-02-02 14:43   ` [PATCH v3 " Jan Dabros
2022-02-02 14:43     ` [PATCH v3 2/2] i2c: designware: Add AMD PSP I2C bus support Jan Dabros
2022-02-02 16:13       ` Andy Shevchenko
2022-02-07  8:27         ` Jan Dąbroś
2022-02-07 11:41           ` Andy Shevchenko
2022-02-08 14:15             ` Jan Dąbroś
2022-02-07 14:25         ` Wolfram Sang
2022-02-08 14:13           ` Jan Dąbroś
2022-02-02 22:49       ` Limonciello, Mario
2022-02-03 10:41         ` Andy Shevchenko
2022-02-03 11:52           ` Jan Dąbroś
2022-01-20  0:16 ` [PATCH " Jan Dabros
2022-01-20 11:44   ` kernel test robot
2022-01-20 11:51   ` Hans de Goede
2022-01-21  9:59     ` Jan Dąbroś
2022-01-21 10:32       ` Hans de Goede
2022-01-21 17:38         ` Limonciello, Mario
2022-01-21 19:18           ` Tom Lendacky
2022-01-24 13:42             ` Jan Dąbroś
2022-01-26 19:36               ` Limonciello, Mario
2022-01-28 14:47                 ` Jan Dąbroś
2022-01-24 12:35         ` Jan Dąbroś
2022-01-24 14:27           ` Hans de Goede [this message]
2022-01-20 14:20   ` Andy Shevchenko
2022-01-21 10:20     ` Jan Dąbroś
2022-01-21 17:51       ` Andy Shevchenko
2022-01-28 14:46         ` Jan Dąbroś
2022-01-20 15:33   ` kernel test robot
2022-01-20 17:09     ` Andy Shevchenko
2022-01-28 14:39       ` Jan Dąbroś
2022-01-20 11:15 ` [PATCH 0/2] i2c-designware: Add support for AMD PSP semaphore Hans de Goede
2022-01-20 12:29   ` Jan Dąbroś
2022-01-20 15:57     ` Hans de Goede
2022-01-21 10:27       ` Jan Dąbroś

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=ca28b3eb-c06d-f8e3-c930-95da631e9a93@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=jarkko.nikula@linux.intel.com \
    --cc=jaz@semihalf.com \
    --cc=jsd@semihalf.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=mika.westerberg@linux.intel.com \
    --cc=mw@semihalf.com \
    --cc=rrangel@chromium.org \
    --cc=upstream@semihalf.com \
    --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 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).