Skip to contentSkip to conversation

Use CCP driver to handle PSP I2C arbitration

PATCH In review Mario Limonciello 3 participants 6 messages Apr 14, 2023 – Apr 20, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v9 cover Use CCP driver to handle PSP I2C arbitration

The CCP driver now has symbols that can be used by i2c-designware-amdpsp to handle the communication regarding i2c arbitration with the PSP for both Cezanne and Mendocino based designs.

Utilize those symbols.

v8->v9:
* Drop v8 patches 1-4 as they're merged now
* Pick up tags for v8 patches 5-6
* Repost to linux-crypto as this needs to merge through crypto tree.

Mario Limonciello (2):
i2c: designware: Use PCI PSP driver for communication
i2c: designware: Add doorbell support for Mendocino

 drivers/i2c/busses/Kconfig                  |   5 +-
 drivers/i2c/busses/i2c-designware-amdpsp.c  | 197 +++++---------------
 drivers/i2c/busses/i2c-designware-core.h    |   1 -
 drivers/i2c/busses/i2c-designware-platdrv.c |   1 -
 include/linux/psp-platform-access.h         |   1 +
 5 files changed, 53 insertions(+), 152 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v9 1/2 i2c: designware: Use PCI PSP driver for communication

Currently the PSP semaphore communication base address is discovered by using an MSR that is not architecturally guaranteed for future platforms. Also the mailbox that is utilized for communication with the PSP may have other consumers in the kernel, so it's better to make all communication go through a single driver.

---
v8->v9
* Add tag
v7->v8:
* Drop hunk changing error message
* Stop using imply. As shown by failed configs for kernel robot we need stronger dependencies. Model them off of I2C_DESIGNWARE_BAYTRAIL which has a similar relationship

---
 drivers/i2c/busses/Kconfig                  |   4 +-
 drivers/i2c/busses/i2c-designware-amdpsp.c  | 175 +++-----------------
 drivers/i2c/busses/i2c-designware-core.h    |   1 -
 drivers/i2c/busses/i2c-designware-platdrv.c |   1 -
 include/linux/psp-platform-access.h         |   1 +
 5 files changed, 29 insertions(+), 153 deletions(-)
drivers/i2c/busses/Kconfig +3 -1
index 25eb4e8fd22f..89f8b75043d0 100644
@@ -566,9 +566,11 @@ config I2C_DESIGNWARE_PLATFORM
 
 config I2C_DESIGNWARE_AMDPSP
 	bool "AMD PSP I2C semaphore support"
-	depends on X86_MSR
 	depends on ACPI
+	depends on CRYPTO_DEV_SP_PSP
 	depends on I2C_DESIGNWARE_PLATFORM
+	depends on (I2C_DESIGNWARE_PLATFORM=y && CRYPTO_DEV_CCP_DD=y) || \
+		   (I2C_DESIGNWARE_PLATFORM=m && CRYPTO_DEV_CCP_DD)
 	help
 	  This driver enables managed host access to the selected I2C bus shared
 	  between AMD CPU and AMD PSP.
drivers/i2c/busses/i2c-designware-amdpsp.c +25 -150

239 lines not on this page · raw message

drivers/i2c/busses/i2c-designware-core.h +0 -1
index 050d8c63ad3c..c5d87aae39c6 100644
@@ -383,7 +383,6 @@ int i2c_dw_baytrail_probe_lock_support(struct dw_i2c_dev *dev);
 
 #if IS_ENABLED(CONFIG_I2C_DESIGNWARE_AMDPSP)
 int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev);
-void i2c_dw_amdpsp_remove_lock_support(struct dw_i2c_dev *dev);
 #endif
 
 int i2c_dw_validate_speed(struct dw_i2c_dev *dev);
drivers/i2c/busses/i2c-designware-platdrv.c +0 -1
index 74182db03a88..89ad88c54754 100644
@@ -214,7 +214,6 @@ static const struct i2c_dw_semaphore_callbacks i2c_dw_semaphore_cb_table[] = {
 #ifdef CONFIG_I2C_DESIGNWARE_AMDPSP
 	{
 		.probe = i2c_dw_amdpsp_probe_lock_support,
-		.remove = i2c_dw_amdpsp_remove_lock_support,
 	},
 #endif
 	{}
include/linux/psp-platform-access.h +1 -0
index 1b661341d8f3..75da8f5f7ad8 100644
@@ -7,6 +7,7 @@
 
 enum psp_platform_access_msg {
 	PSP_CMD_NONE = 0x0,
+	PSP_I2C_REQ_BUS_CMD = 0x64,
 };
 
 struct psp_req_buffer_hdr {
Signature · 1 line
2.34.1
#2 lore raw

PATCH v9 2/2 i2c: designware: Add doorbell support for Mendocino

In reply to Mario Limonciello

Mendocino and later platform don't use the platform feature mailbox for communication for I2C arbitration, they rely upon ringing a doorbell.

Detect the platform by the device ID of the root port and choose the appropriate method.

---
v8->v9:
* Add tag

 drivers/i2c/busses/Kconfig                 |  1 +
 drivers/i2c/busses/i2c-designware-amdpsp.c | 26 +++++++++++++++++++++-
 2 files changed, 26 insertions(+), 1 deletion(-)
drivers/i2c/busses/Kconfig +1 -0
index 89f8b75043d0..4b4323bbf268 100644
@@ -568,6 +568,7 @@ config I2C_DESIGNWARE_AMDPSP
 	bool "AMD PSP I2C semaphore support"
 	depends on ACPI
 	depends on CRYPTO_DEV_SP_PSP
+	depends on PCI
 	depends on I2C_DESIGNWARE_PLATFORM
 	depends on (I2C_DESIGNWARE_PLATFORM=y && CRYPTO_DEV_CCP_DD=y) || \
 		   (I2C_DESIGNWARE_PLATFORM=m && CRYPTO_DEV_CCP_DD)
drivers/i2c/busses/i2c-designware-amdpsp.c +25 -1
index 12870dc44bdb..63454b06e5da 100644
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 
 #include <linux/i2c.h>
+#include <linux/pci.h>
 #include <linux/psp-platform-access.h>
 #include <linux/psp.h>
 #include <linux/workqueue.h>
@@ -32,6 +33,8 @@ static u32 psp_i2c_access_count;
 static bool psp_i2c_mbox_fail;
 static struct device *psp_i2c_dev;
 
+static int (*_psp_send_i2c_req)(struct psp_i2c_req *req);
+
 /* Helper to verify status returned by PSP */
 static int check_i2c_req_sts(struct psp_i2c_req *req)
 {
@@ -72,6 +75,17 @@ static int psp_send_i2c_req_cezanne(struct psp_i2c_req *req)
 	return ret;
 }
 
+static int psp_send_i2c_req_doorbell(struct psp_i2c_req *req)
+{
+	int ret;
+
+	ret = psp_ring_platform_doorbell(req->type, &req->hdr.status);
+	if (ret == -EIO)
+		return check_i2c_req_sts(req);
+
+	return ret;
+}
+
 static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type)
 {
 	struct psp_i2c_req *req;
@@ -87,7 +101,7 @@ static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type)
 	req->type = i2c_req_type;
 
 	start = jiffies;
-	ret = read_poll_timeout(psp_send_i2c_req_cezanne, status,
+	ret = read_poll_timeout(_psp_send_i2c_req, status,
 				(status != -EBUSY),
 				PSP_I2C_REQ_RETRY_DELAY_US,
 				PSP_I2C_REQ_RETRY_CNT * PSP_I2C_REQ_RETRY_DELAY_US,
@@ -262,6 +276,8 @@ static const struct i2c_lock_operations i2c_dw_psp_lock_ops = {
 
 int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev)
 {
+	struct pci_dev *rdev;
+
 	if (!IS_REACHABLE(CONFIG_CRYPTO_DEV_CCP_DD))
 		return -ENODEV;
 
@@ -275,6 +291,14 @@ int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev)
 	if (psp_i2c_dev)
 		return -EEXIST;
 
+	/* Cezanne uses platform mailbox, Mendocino and later use doorbell */
+	rdev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0, 0));
+	if (rdev->device == 0x1630)
+		_psp_send_i2c_req = psp_send_i2c_req_cezanne;
+	else
+		_psp_send_i2c_req = psp_send_i2c_req_doorbell;
+	pci_dev_put(rdev);
+
 	if (psp_check_platform_access_status())
 		return -EPROBE_DEFER;
 
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH v9 2/2] i2c: designware: Add doorbell support for Mendocino

kernel test robot noticed the following build errors:

Hi Mario,

kernel test robot noticed the following build errors:

[auto build test ERROR on next-20230413]
[cannot apply to wsa/i2c/for-next linus/master v6.3-rc6 v6.3-rc5 v6.3-rc4 v6.3-rc6] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Mario-Limonciello/i2c-designware-Use-PCI-PSP-driver-for-communication/20230414-224238
patch link:    https://lore.kernel.org/r/20230414144008.836-3-mario.limonciello%40amd.com
patch subject: [PATCH v9 2/2] i2c: designware: Add doorbell support for Mendocino
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20230415/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/a8ae7845f0c3fcb46f4c37508838fed08dae7eec
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Mario-Limonciello/i2c-designware-Use-PCI-PSP-driver-for-communication/20230414-224238
        git checkout a8ae7845f0c3fcb46f4c37508838fed08dae7eec
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=x86_64 olddefconfig
        make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/i2c/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/i2c/busses/i2c-designware-amdpsp.c: In function 'psp_send_i2c_req_doorbell':

>> drivers/i2c/busses/i2c-designware-amdpsp.c:82:15: error: too many arguments to function 'psp_ring_platform_doorbell'
      82 |         ret = psp_ring_platform_doorbell(req->type, &req->hdr.status);
         |               ^~~~~~~~~~~~~~~~~~~~~~~~~~
   In file included from drivers/i2c/busses/i2c-designware-amdpsp.c:5:
   include/linux/psp-platform-access.h:51:5: note: declared here
      51 | int psp_ring_platform_doorbell(int msg);
         |     ^~~~~~~~~~~~~~~~~~~~~~~~~~

vim +/psp_ring_platform_doorbell +82 drivers/i2c/busses/i2c-designware-amdpsp.c

    77	
    78	static int psp_send_i2c_req_doorbell(struct psp_i2c_req *req)
    79	{
    80		int ret;
    81	
  > 82		ret = psp_ring_platform_doorbell(req->type, &req->hdr.status);
    83		if (ret == -EIO)
    84			return check_i2c_req_sts(req);
    85	
    86		return ret;
    87	}
    88	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
#4 lore raw

RE: [PATCH v9 2/2] i2c: designware: Add doorbell support for Mendocino

[Public]

Quoted 83 lines

-----Original Message-----
From: kernel test robot <[email protected]>
Sent: Friday, April 14, 2023 11:50
To: Limonciello, Mario <[email protected]>; Herbert Xu <[email protected]>; Jarkko Nikula <[email protected]>; Andy Shevchenko <[email protected]>; Mika Westerberg <[email protected]>; Jan Dabros <[email protected]>
Cc: [email protected]; [email protected]; Limonciello, Mario <[email protected]>; Mark Hasemeyer <[email protected]>; Wolfram Sang <wsa-dev@sang- engineering.com>; [email protected]; [email protected]
Subject: Re: [PATCH v9 2/2] i2c: designware: Add doorbell support for Mendocino

Hi Mario,

kernel test robot noticed the following build errors:

[auto build test ERROR on next-20230413]
[cannot apply to wsa/i2c/for-next linus/master v6.3-rc6 v6.3-rc5 v6.3-rc4 v6.3-rc6]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Mario-Limonciello/i2c-
designware-Use-PCI-PSP-driver-for-communication/20230414-224238
patch link: https://lore.kernel.org/r/20230414144008.836-3-
mario.limonciello%40amd.com
patch subject: [PATCH v9 2/2] i2c: designware: Add doorbell support for Mendocino
config: x86_64-allyesconfig (https://download.01.org/0day-
ci/archive/20230415/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):

        # https://github.com/intel-lab-

lkp/linux/commit/a8ae7845f0c3fcb46f4c37508838fed08dae7eec
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Mario-Limonciello/i2c-designware-Use-
PCI-PSP-driver-for-communication/20230414-224238

        git checkout a8ae7845f0c3fcb46f4c37508838fed08dae7eec
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=x86_64 olddefconfig
        make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/i2c/

If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/202304150012.IieZ4vzl-
[email protected]/

All errors (new ones prefixed by >>):

drivers/i2c/busses/i2c-designware-amdpsp.c: In function
'psp_send_i2c_req_doorbell':

Quoted 1 line
Quoted 1 line

drivers/i2c/busses/i2c-designware-amdpsp.c:82:15: error: too many

arguments to function 'psp_ring_platform_doorbell'

      82 |         ret = psp_ring_platform_doorbell(req->type, &req->hdr.status);
         |               ^~~~~~~~~~~~~~~~~~~~~~~~~~
   In file included from drivers/i2c/busses/i2c-designware-amdpsp.c:5:
   include/linux/psp-platform-access.h:51:5: note: declared here
      51 | int psp_ring_platform_doorbell(int msg);
         |     ^~~~~~~~~~~~~~~~~~~~~~~~~~

vim +/psp_ring_platform_doorbell +82 drivers/i2c/busses/i2c-designware- amdpsp.c

    77
    78	static int psp_send_i2c_req_doorbell(struct psp_i2c_req *req)
    79	{
    80		int ret;
    81
Quoted 2 lines

82 ret = psp_ring_platform_doorbell(req->type, &req-
hdr.status);

    83		if (ret == -EIO)
    84			return check_i2c_req_sts(req);
    85
    86		return ret;
    87	}
    88
Quoted 3 lines

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests

FYI - this failure is because it was tested across wrong tree. I didn't use a base commit so it guessed.

Thanks,

maintainer
#5 lore raw
In reply to Mario Limonciello
Quoted 15 lines · Mario Limonciello

The CCP driver now has symbols that can be used by i2c-designware-amdpsp to handle the communication regarding i2c arbitration with the PSP for both Cezanne and Mendocino based designs.

Utilize those symbols.

v8->v9:
* Drop v8 patches 1-4 as they're merged now
* Pick up tags for v8 patches 5-6
* Repost to linux-crypto as this needs to merge through crypto tree.

Mario Limonciello (2):
i2c: designware: Use PCI PSP driver for communication
i2c: designware: Add doorbell support for Mendocino

Quoted 9 lines
 drivers/i2c/busses/Kconfig                  |   5 +-
 drivers/i2c/busses/i2c-designware-amdpsp.c  | 197 +++++---------------
 drivers/i2c/busses/i2c-designware-core.h    |   1 -
 drivers/i2c/busses/i2c-designware-platdrv.c |   1 -
 include/linux/psp-platform-access.h         |   1 +
 5 files changed, 53 insertions(+), 152 deletions(-)
Signature · 1 line
2.34.1

All applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt