Skip to contentSkip to conversation

Use CCP driver to handle PSP I2C arbitration

PATCH Superseded Mario Limonciello 4 participants 14 messages Mar 22, 2023 – Mar 27, 2023

Subsystems (6)

v6 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Mario Limonciello

author maintainer
#0 lore raw

v6 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.

Mario Limonciello (4):
crypto: ccp: Bump up doorbell debug messages to error
crypto: ccp: Return doorbell status code as an argument
i2c: designware: Use PCI PSP driver for communication
i2c: designware: Add doorbell support for Mendocino

 drivers/crypto/ccp/platform-access.c        |  10 +-
 drivers/i2c/busses/Kconfig                  |   3 +-
 drivers/i2c/busses/i2c-designware-amdpsp.c  | 196 +++++---------------
 drivers/i2c/busses/i2c-designware-core.h    |   1 -
 drivers/i2c/busses/i2c-designware-platdrv.c |   1 -
 include/linux/psp-platform-access.h         |   5 +-
 6 files changed, 58 insertions(+), 158 deletions(-)

base-commit: e6af5c0c4d32a27e04a56f29aad587e03ff427f1

Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH v6 1/4 crypto: ccp: Bump up doorbell debug messages to error

This is helpful not just for debugging problems, but also for investigating captured logs later on.

---
 drivers/crypto/ccp/platform-access.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/crypto/ccp/platform-access.c +3 -3
index b51fb1196932..3e97ce60270d 100644
@@ -157,19 +157,19 @@ int psp_ring_platform_doorbell(int msg)
 	mutex_lock(&pa_dev->doorbell_mutex);
 
 	if (check_doorbell(button)) {
-		dev_dbg(psp->dev, "doorbell is not ready\n");
+		dev_err(psp->dev, "doorbell is not ready\n");
 		ret = -EBUSY;
 		goto unlock;
 	}
 
 	if (check_recovery(cmd)) {
-		dev_dbg(psp->dev, "doorbell command in recovery\n");
+		dev_err(psp->dev, "doorbell command in recovery\n");
 		ret = -EBUSY;
 		goto unlock;
 	}
 
 	if (wait_cmd(cmd)) {
-		dev_dbg(psp->dev, "doorbell command not done processing\n");
+		dev_err(psp->dev, "doorbell command not done processing\n");
 		ret = -EBUSY;
 		goto unlock;
 	}
Signature · 1 line
2.34.1
author maintainer
#2 lore raw

PATCH v6 2/4 crypto: ccp: Return doorbell status code as an argument

In reply to Mario Limonciello

If the doorbell failed to ring we return -EIO, but the caller can't determine why it failed. Pass the reason for the failure in an argument for caller to investigate.

---
v5->v6:
* New patch

---
 drivers/crypto/ccp/platform-access.c | 4 +++-
 include/linux/psp-platform-access.h  | 4 ++--
 2 files changed, 5 insertions(+), 3 deletions(-)
drivers/crypto/ccp/platform-access.c +3 -1
index 3e97ce60270d..9f3d469bbe76 100644
@@ -140,7 +140,7 @@ int psp_send_platform_access_msg(enum psp_platform_access_msg msg,
 }
 EXPORT_SYMBOL_GPL(psp_send_platform_access_msg);
 
-int psp_ring_platform_doorbell(int msg)
+int psp_ring_platform_doorbell(int msg, u32 *result)
 {
 	struct psp_device *psp = psp_get_master_device();
 	struct psp_platform_access_device *pa_dev;
@@ -184,6 +184,8 @@ int psp_ring_platform_doorbell(int msg)
 
 	val = FIELD_GET(PSP_CMDRESP_STS, ioread32(cmd));
 	if (val) {
+		if (result)
+			*result = val;
 		ret = -EIO;
 		goto unlock;
 	}
include/linux/psp-platform-access.h +2 -2
index 89df4549fada..1b661341d8f3 100644
@@ -45,9 +45,9 @@ int psp_send_platform_access_msg(enum psp_platform_access_msg, struct psp_reques
  *  -%EBUSY:     mailbox in recovery or in use
  *  -%ENODEV:    driver not bound with PSP device
  *  -%ETIMEDOUT: request timed out
- *  -%EIO:       unknown error (see kernel log)
+ *  -%EIO:       error will be stored in result argument
  */
-int psp_ring_platform_doorbell(int msg);
+int psp_ring_platform_doorbell(int msg, u32 *result);
 
 /**
  * psp_check_platform_access_status() - Checks whether platform features is ready
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH v6 2/4] crypto: ccp: Return doorbell status code as an argument

Quoted 6 lines
drivers/crypto/ccp/platform-access.c +1 -1
-int psp_ring_platform_doorbell(int msg)
+int psp_ring_platform_doorbell(int msg, u32 *result)
 {
        struct psp_device *psp = psp_get_master_device();
        struct psp_platform_access_device *pa_dev;

drivers/crypto/ccp/platform-access.c int psp_ring_platform_doorbell(int msg) · line 191

Quoted 8 lines
drivers/crypto/ccp/platform-access.c +2 -0
@@ -184,6 +184,8 @@ int psp_ring_platform_doorbell(int msg)
 
        val = FIELD_GET(PSP_CMDRESP_STS, ioread32(cmd));
        if (val) {
+               if (result)
+                       *result = val;
                ret = -EIO;
                goto unlock;
        }

The bitfields in the new mailbox architecture have changed, as it is now a dedicated mailbox for I2C arbitration. The 8 lsbs are used for command and response status, and bit 31 is the ready bit. Accounting for these changes, I was able to get the TPM contention test to pass locally. I also removed calls to "check_doorbell" and "check_recovery" as those steps weren't described in the design doc.

author maintainer
#4 lore raw

PATCH v6 3/4 i2c: designware: Use PCI PSP driver for communication

In reply to Mario Limonciello

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.

---
v5->v6:
* Drop now unnecessary asm/msr.h header
* Fix IS_REACHABLE
* Drop tags
* Fix status code handling for Cezanne
v4->v5:
* Pick up tags
v3->v4:
* Pick up tags
v1->v2:
* Fix Kconfig to use imply
* Use IS_REACHABLE

---
 drivers/i2c/busses/Kconfig                  |   2 +-
 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, 27 insertions(+), 153 deletions(-)
drivers/i2c/busses/Kconfig +1 -1
index 25eb4e8fd22f..d53bf716f97d 100644
@@ -566,9 +566,9 @@ config I2C_DESIGNWARE_PLATFORM
 
 config I2C_DESIGNWARE_AMDPSP
 	bool "AMD PSP I2C semaphore support"
-	depends on X86_MSR
 	depends on ACPI
 	depends on I2C_DESIGNWARE_PLATFORM
+	imply CRYPTO_DEV_SP_PSP
 	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
reviewer Reviewed-by on v6 3/4
#5 lore raw

Re: [PATCH v6 3/4] i2c: designware: Use PCI PSP driver for communication

Quoted 5 lines · Mario Limonciello

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.

Fine by me,

Quoted 326 lines

---
v5->v6:
* Drop now unnecessary asm/msr.h header
* Fix IS_REACHABLE
* Drop tags
* Fix status code handling for Cezanne
v4->v5:
* Pick up tags
v3->v4:
* Pick up tags
v1->v2:
* Fix Kconfig to use imply
* Use IS_REACHABLE

---
 drivers/i2c/busses/Kconfig                  |   2 +-
 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, 27 insertions(+), 153 deletions(-)
drivers/i2c/busses/Kconfig +1 -1
index 25eb4e8fd22f..d53bf716f97d 100644
@@ -566,9 +566,9 @@ config I2C_DESIGNWARE_PLATFORM
 
 config I2C_DESIGNWARE_AMDPSP
 	bool "AMD PSP I2C semaphore support"
-	depends on X86_MSR
 	depends on ACPI
 	depends on I2C_DESIGNWARE_PLATFORM
+	imply CRYPTO_DEV_SP_PSP
 	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
index 652e6b64bd5f..12870dc44bdb 100644
@@ -1,35 +1,20 @@
 // SPDX-License-Identifier: GPL-2.0
 
-#include <linux/bitfield.h>
-#include <linux/bits.h>
 #include <linux/i2c.h>
-#include <linux/io-64-nonatomic-lo-hi.h>
+#include <linux/psp-platform-access.h>
 #include <linux/psp.h>
-#include <linux/types.h>
 #include <linux/workqueue.h>
 
-#include <asm/msr.h>
-
 #include "i2c-designware-core.h"
 
-#define MSR_AMD_PSP_ADDR	0xc00110a2
-#define PSP_MBOX_OFFSET		0x10570
-#define PSP_CMD_TIMEOUT_US	(500 * USEC_PER_MSEC)
-
 #define PSP_I2C_RESERVATION_TIME_MS 100
 
-#define PSP_I2C_REQ_BUS_CMD		0x64
 #define PSP_I2C_REQ_RETRY_CNT		400
 #define PSP_I2C_REQ_RETRY_DELAY_US	(25 * USEC_PER_MSEC)
 #define PSP_I2C_REQ_STS_OK		0x0
 #define PSP_I2C_REQ_STS_BUS_BUSY	0x1
 #define PSP_I2C_REQ_STS_INV_PARAM	0x3
 
-struct psp_req_buffer_hdr {
-	u32 total_size;
-	u32 status;
-};
-
 enum psp_i2c_req_type {
 	PSP_I2C_REQ_ACQUIRE,
 	PSP_I2C_REQ_RELEASE,
@@ -41,119 +26,12 @@ struct psp_i2c_req {
 	enum psp_i2c_req_type type;
 };
 
-struct psp_mbox {
-	u32 cmd_fields;
-	u64 i2c_req_addr;
-} __packed;
-
 static DEFINE_MUTEX(psp_i2c_access_mutex);
 static unsigned long psp_i2c_sem_acquired;
-static void __iomem *mbox_iomem;
 static u32 psp_i2c_access_count;
 static bool psp_i2c_mbox_fail;
 static struct device *psp_i2c_dev;
 
-/*
- * Implementation of PSP-x86 i2c-arbitration mailbox introduced for AMD Cezanne
- * family of SoCs.
- */
-
-static int psp_get_mbox_addr(unsigned long *mbox_addr)
-{
-	unsigned long long psp_mmio;
-
-	if (rdmsrl_safe(MSR_AMD_PSP_ADDR, &psp_mmio))
-		return -EIO;
-
-	*mbox_addr = (unsigned long)(psp_mmio + PSP_MBOX_OFFSET);
-
-	return 0;
-}
-
-static int psp_mbox_probe(void)
-{
-	unsigned long mbox_addr;
-	int ret;
-
-	ret = psp_get_mbox_addr(&mbox_addr);
-	if (ret)
-		return ret;
-
-	mbox_iomem = ioremap(mbox_addr, sizeof(struct psp_mbox));
-	if (!mbox_iomem)
-		return -ENOMEM;
-
-	return 0;
-}
-
-/* Recovery field should be equal 0 to start sending commands */
-static int psp_check_mbox_recovery(struct psp_mbox __iomem *mbox)
-{
-	u32 tmp;
-
-	tmp = readl(&mbox->cmd_fields);
-
-	return FIELD_GET(PSP_CMDRESP_RECOVERY, tmp);
-}
-
-static int psp_wait_cmd(struct psp_mbox __iomem *mbox)
-{
-	u32 tmp, expected;
-
-	/* Expect mbox_cmd to be cleared and the response bit to be set by PSP */
-	expected = FIELD_PREP(PSP_CMDRESP_RESP, 1);
-
-	/*
-	 * Check for readiness of PSP mailbox in a tight loop in order to
-	 * process further as soon as command was consumed.
-	 */
-	return readl_poll_timeout(&mbox->cmd_fields, tmp, (tmp == expected),
-				  0, PSP_CMD_TIMEOUT_US);
-}
-
-/* Status equal to 0 means that PSP succeed processing command */
-static u32 psp_check_mbox_sts(struct psp_mbox __iomem *mbox)
-{
-	u32 cmd_reg;
-
-	cmd_reg = readl(&mbox->cmd_fields);
-
-	return FIELD_GET(PSP_CMDRESP_STS, cmd_reg);
-}
-
-static int psp_send_cmd(struct psp_i2c_req *req)
-{
-	struct psp_mbox __iomem *mbox = mbox_iomem;
-	phys_addr_t req_addr;
-	u32 cmd_reg;
-
-	if (psp_check_mbox_recovery(mbox))
-		return -EIO;
-
-	if (psp_wait_cmd(mbox))
-		return -EBUSY;
-
-	/*
-	 * Fill mailbox with address of command-response buffer, which will be
-	 * used for sending i2c requests as well as reading status returned by
-	 * PSP. Use physical address of buffer, since PSP will map this region.
-	 */
-	req_addr = __psp_pa((void *)req);
-	writeq(req_addr, &mbox->i2c_req_addr);
-
-	/* Write command register to trigger processing */
-	cmd_reg = FIELD_PREP(PSP_CMDRESP_CMD, PSP_I2C_REQ_BUS_CMD);
-	writel(cmd_reg, &mbox->cmd_fields);
-
-	if (psp_wait_cmd(mbox))
-		return -ETIMEDOUT;
-
-	if (psp_check_mbox_sts(mbox))
-		return -EIO;
-
-	return 0;
-}
-
 /* Helper to verify status returned by PSP */
 static int check_i2c_req_sts(struct psp_i2c_req *req)
 {
@@ -173,22 +51,25 @@ static int check_i2c_req_sts(struct psp_i2c_req *req)
 	}
 }
 
-static int psp_send_check_i2c_req(struct psp_i2c_req *req)
+/*
+ * Errors in x86-PSP i2c-arbitration protocol may occur at two levels:
+ * 1. mailbox communication - PSP is not operational or some IO errors with
+ *    basic communication had happened.
+ * 2. i2c-requests - PSP refuses to grant i2c arbitration to x86 for too long.
+ *
+ * In order to distinguish between these in error handling code all mailbox
+ * communication errors on the first level (from CCP symbols) will be passed
+ * up and if -EIO is returned the second level will be checked.
+ */
+static int psp_send_i2c_req_cezanne(struct psp_i2c_req *req)
 {
-	/*
-	 * Errors in x86-PSP i2c-arbitration protocol may occur at two levels:
-	 * 1. mailbox communication - PSP is not operational or some IO errors
-	 * with basic communication had happened;
-	 * 2. i2c-requests - PSP refuses to grant i2c arbitration to x86 for too
-	 * long.
-	 * In order to distinguish between these two in error handling code, all
-	 * errors on the first level (returned by psp_send_cmd) are shadowed by
-	 * -EIO.
-	 */
-	if (psp_send_cmd(req))
-		return -EIO;
+	int ret;
 
-	return check_i2c_req_sts(req);
+	ret = psp_send_platform_access_msg(PSP_I2C_REQ_BUS_CMD, (struct psp_request *)req);
+	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)
@@ -202,11 +83,11 @@ static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type)
 	if (!req)
 		return -ENOMEM;
 
-	req->hdr.total_size = sizeof(*req);
+	req->hdr.payload_size = sizeof(*req);
 	req->type = i2c_req_type;
 
 	start = jiffies;
-	ret = read_poll_timeout(psp_send_check_i2c_req, status,
+	ret = read_poll_timeout(psp_send_i2c_req_cezanne, status,
 				(status != -EBUSY),
 				PSP_I2C_REQ_RETRY_DELAY_US,
 				PSP_I2C_REQ_RETRY_CNT * PSP_I2C_REQ_RETRY_DELAY_US,
@@ -381,7 +262,8 @@ static const struct i2c_lock_operations i2c_dw_psp_lock_ops = {
 
 int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev)
 {
-	int ret;
+	if (!IS_REACHABLE(CONFIG_CRYPTO_DEV_CCP_DD))
+		return -ENODEV;
 
 	if (!dev)
 		return -ENODEV;
@@ -393,11 +275,10 @@ int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev)
 	if (psp_i2c_dev)
 		return -EEXIST;
 
-	psp_i2c_dev = dev->dev;
+	if (psp_check_platform_access_status())
+		return -EPROBE_DEFER;
 
-	ret = psp_mbox_probe();
-	if (ret)
-		return ret;
+	psp_i2c_dev = dev->dev;
 
 	dev_info(psp_i2c_dev, "I2C bus managed by AMD PSP\n");
 
@@ -411,9 +292,3 @@ int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev)
 
 	return 0;
 }
-
-/* Unmap area used as a mailbox with PSP */
-void i2c_dw_amdpsp_remove_lock_support(struct dw_i2c_dev *dev)
-{
-	iounmap(mbox_iomem);
-}
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
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw

Re: [PATCH v6 3/4] i2c: designware: Use PCI PSP driver for communication

In reply to Mario Limonciello
Thank you for the patch! Yet something to improve:

Hi Mario,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on e6af5c0c4d32a27e04a56f29aad587e03ff427f1]

url:    https://github.com/intel-lab-lkp/linux/commits/Mario-Limonciello/crypto-ccp-Bump-up-doorbell-debug-messages-to-error/20230323-050710
base:   e6af5c0c4d32a27e04a56f29aad587e03ff427f1
patch link:    https://lore.kernel.org/r/20230322210227.464-4-mario.limonciello%40amd.com
patch subject: [PATCH v6 3/4] i2c: designware: Use PCI PSP driver for communication
config: arm64-allyesconfig (https://download.01.org/0day-ci/archive/20230324/[email protected]/config)
compiler: aarch64-linux-gcc (GCC) 12.1.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/addff0f32acff3a5278cbbf6fffc9054ecb03e2f
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Mario-Limonciello/crypto-ccp-Bump-up-doorbell-debug-messages-to-error/20230323-050710 git checkout addff0f32acff3a5278cbbf6fffc9054ecb03e2f
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arm64 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash

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 >>):

>> aarch64-linux-ld: Unexpected GOT/PLT entries detected!
>> aarch64-linux-ld: Unexpected run-time procedure linkages detected!

aarch64-linux-ld: drivers/i2c/busses/i2c-designware-amdpsp.o: in function `psp_send_i2c_req':
i2c-designware-amdpsp.c:(.text+0xe0): undefined reference to `psp_send_platform_access_msg'
aarch64-linux-ld: i2c-designware-amdpsp.c:(.text+0x16c): undefined reference to `psp_send_platform_access_msg'
aarch64-linux-ld: drivers/i2c/busses/i2c-designware-amdpsp.o: in function `i2c_dw_amdpsp_probe_lock_support':
i2c-designware-amdpsp.c:(.text+0xad4): undefined reference to `psp_check_platform_access_status'

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
#7 lore raw

Re: [PATCH v6 3/4] i2c: designware: Use PCI PSP driver for communication

In reply to Mario Limonciello
Thank you for the patch! Yet something to improve:

Hi Mario,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on e6af5c0c4d32a27e04a56f29aad587e03ff427f1]

url:    https://github.com/intel-lab-lkp/linux/commits/Mario-Limonciello/crypto-ccp-Bump-up-doorbell-debug-messages-to-error/20230323-050710
base:   e6af5c0c4d32a27e04a56f29aad587e03ff427f1
patch link:    https://lore.kernel.org/r/20230322210227.464-4-mario.limonciello%40amd.com
patch subject: [PATCH v6 3/4] i2c: designware: Use PCI PSP driver for communication
config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20230324/[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/addff0f32acff3a5278cbbf6fffc9054ecb03e2f
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Mario-Limonciello/crypto-ccp-Bump-up-doorbell-debug-messages-to-error/20230323-050710 git checkout addff0f32acff3a5278cbbf6fffc9054ecb03e2f
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=i386 olddefconfig
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash

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 >>):

ld: drivers/i2c/busses/i2c-designware-amdpsp.o: in function `psp_send_i2c_req':

>> i2c-designware-amdpsp.c:(.text+0x77): undefined reference to `psp_send_platform_access_msg'
   ld: i2c-designware-amdpsp.c:(.text+0xbb): undefined reference to `psp_send_platform_access_msg'
   ld: drivers/i2c/busses/i2c-designware-amdpsp.o: in function `i2c_dw_amdpsp_probe_lock_support':
>> i2c-designware-amdpsp.c:(.text+0x400): undefined reference to `psp_check_platform_access_status'
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
author maintainer
#8 lore raw

PATCH v6 4/4 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.

---
v5->v6:
* Handle Mendocino busy code like Cezanne
v4->v5:
* Poll for busy
* Rename to mendocino
* Add explicit dependency on PCI
v3->v4:
* Adjust to use PCI device ID and function pointers instead
v2->v3:
* Use CPU ID rather than ACPI ID, this will be pushed to a later patch
v1->v2:
* New patch

---
 drivers/i2c/busses/Kconfig                 |  1 +
 drivers/i2c/busses/i2c-designware-amdpsp.c | 25 +++++++++++++++++++++-
 2 files changed, 25 insertions(+), 1 deletion(-)
drivers/i2c/busses/Kconfig +1 -0
index d53bf716f97d..2aba5ffa8b03 100644
@@ -568,6 +568,7 @@ config I2C_DESIGNWARE_AMDPSP
 	bool "AMD PSP I2C semaphore support"
 	depends on ACPI
 	depends on I2C_DESIGNWARE_PLATFORM
+	depends on PCI
 	imply CRYPTO_DEV_SP_PSP
 	help
 	  This driver enables managed host access to the selected I2C bus shared
drivers/i2c/busses/i2c-designware-amdpsp.c +24 -1
index 12870dc44bdb..f5c754919fbd 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_mendocino(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,13 @@ 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_mendocino;
+
 	if (psp_check_platform_access_status())
 		return -EPROBE_DEFER;
 
Signature · 1 line
2.34.1
#9 lore raw

Re: [PATCH v6 4/4] i2c: designware: Add doorbell support for Mendocino

Quoted 5 lines · 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.

...

drivers/i2c/busses/i2c-designware-amdpsp.c static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type) · line 105

Quoted 3 lines
drivers/i2c/busses/i2c-designware-amdpsp.c +1 -1
-	ret = read_poll_timeout(psp_send_i2c_req_cezanne, status,
+	ret = read_poll_timeout(_psp_send_i2c_req, status,
 				(status != -EBUSY),

You can place it now in the above line, but up to you.

Quoted 2 lines
drivers/i2c/busses/i2c-designware-amdpsp.c +0 -0
 				PSP_I2C_REQ_RETRY_DELAY_US,
 				PSP_I2C_REQ_RETRY_CNT * PSP_I2C_REQ_RETRY_DELAY_US,

...

drivers/i2c/busses/i2c-designware-amdpsp.c int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev) · line 299

Quoted 6 lines
drivers/i2c/busses/i2c-designware-amdpsp.c +6 -0
+	/* 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_mendocino;

Where is pci_dev_put()?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#10 lore raw

RE: [PATCH v6 4/4] i2c: designware: Add doorbell support for Mendocino

[Public]

Quoted 35 lines

-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Thursday, March 23, 2023 08:06
To: Limonciello, Mario <[email protected]>
Cc: Jan Dąbroś <[email protected]>; Grzegorz Bernacki <[email protected]>; Mark Hasemeyer <[email protected]>; Jarkko Nikula <[email protected]>; Mika Westerberg <[email protected]>; [email protected]; linux- [email protected]
Subject: Re: [PATCH v6 4/4] i2c: designware: Add doorbell support for Mendocino

Quoted 5 lines · 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.

...

drivers/i2c/busses/i2c-designware-amdpsp.c static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type) · line 105

Quoted 3 lines
drivers/i2c/busses/i2c-designware-amdpsp.c +1 -1
-	ret = read_poll_timeout(psp_send_i2c_req_cezanne, status,
+	ret = read_poll_timeout(_psp_send_i2c_req, status,
 				(status != -EBUSY),

You can place it now in the above line, but up to you.

Review

Quoted 2 lines
(quoted diff) +0 -0
 				PSP_I2C_REQ_RETRY_DELAY_US,
 				PSP_I2C_REQ_RETRY_CNT *

PSP_I2C_REQ_RETRY_DELAY_US,

...

Review

Quoted 1 line
(quoted diff) +1 -0
+	/* Cezanne uses platform mailbox, Mendocino and later use doorbell

*/

Quoted 7 lines

drivers/i2c/busses/i2c-designware-amdpsp.c int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev) · line 299

Quoted 5 lines
drivers/i2c/busses/i2c-designware-amdpsp.c +5 -0
+	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_mendocino;

Where is pci_dev_put()?

Missing, thanks for catching it!

#11 lore raw

Re: [PATCH v6 4/4] i2c: designware: Add doorbell support for Mendocino

In reply to Mario Limonciello
Thank you for the patch! Yet something to improve:

Hi Mario,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on e6af5c0c4d32a27e04a56f29aad587e03ff427f1]

url:    https://github.com/intel-lab-lkp/linux/commits/Mario-Limonciello/crypto-ccp-Bump-up-doorbell-debug-messages-to-error/20230323-050710
base:   e6af5c0c4d32a27e04a56f29aad587e03ff427f1
patch link:    https://lore.kernel.org/r/20230322210227.464-5-mario.limonciello%40amd.com
patch subject: [PATCH v6 4/4] i2c: designware: Add doorbell support for Mendocino
config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20230325/[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/9056f37ee3c0bd46052df6b3fb08c0ad951752a4
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Mario-Limonciello/crypto-ccp-Bump-up-doorbell-debug-messages-to-error/20230323-050710 git checkout 9056f37ee3c0bd46052df6b3fb08c0ad951752a4
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=i386 olddefconfig
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash

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 >>):

ld: drivers/i2c/busses/i2c-designware-amdpsp.o: in function `psp_send_i2c_req_mendocino':

>> i2c-designware-amdpsp.c:(.text+0x12): undefined reference to `psp_ring_platform_doorbell'

ld: drivers/i2c/busses/i2c-designware-amdpsp.o: in function `psp_send_i2c_req_cezanne':
i2c-designware-amdpsp.c:(.text+0x67): undefined reference to `psp_send_platform_access_msg'
ld: drivers/i2c/busses/i2c-designware-amdpsp.o: in function `i2c_dw_amdpsp_probe_lock_support':
i2c-designware-amdpsp.c:(.text+0x497): undefined reference to `psp_check_platform_access_status'

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
#12 lore raw

Re: [PATCH v6 4/4] i2c: designware: Add doorbell support for Mendocino

In reply to Mario Limonciello

drivers/i2c/busses/i2c-designware-amdpsp.c static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type) · line 107

Quoted 12 lines

static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type)

 {
        struct psp_i2c_req *req;
drivers/i2c/busses/i2c-designware-amdpsp.c +1 -1
@@ -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,

The timeout error handling message after this has "acquire" and "release" flopped.

drivers/i2c/busses/i2c-designware-amdpsp.c int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev) · line 299

Quoted 10 lines
drivers/i2c/busses/i2c-designware-amdpsp.c +6 -0
@@ -275,6 +291,13 @@ 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_mendocino;

Thinking about naming again, perhaps "mendocino" should be dropped from the function name as the logic applies to all platforms except cezanne.

author maintainer
#13 lore raw

RE: [PATCH v6 4/4] i2c: designware: Add doorbell support for Mendocino

[Public]

Quoted 13 lines

Review static int psp_send_i2c_req(enum psp_i2c_req_type

Quoted 4 lines

static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type)

 {
        struct psp_i2c_req *req;
(quoted diff) +0 -0
@@ -87,7 +101,7 @@ static int psp_send_i2c_req(enum psp_i2c_req_type

i2c_req_type)

drivers/i2c/busses/i2c-designware-amdpsp.c static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type)

Quoted 8 lines
drivers/i2c/busses/i2c-designware-amdpsp.c +1 -1
        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 *
Quoted 4 lines

PSP_I2C_REQ_RETRY_DELAY_US,
The timeout error handling message after this has "acquire" and "release" flopped.

Thx, will fix.

Quoted 7 lines

Review int i2c_dw_amdpsp_probe_lock_support(struct

Quoted 1 line
(quoted diff) +0 -0
@@ -275,6 +291,13 @@ int i2c_dw_amdpsp_probe_lock_support(struct

dw_i2c_dev *dev)

drivers/i2c/busses/i2c-designware-amdpsp.c int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev)

Quoted 4 lines
drivers/i2c/busses/i2c-designware-amdpsp.c +1 -0
        if (psp_i2c_dev)
                return -EEXIST;
 
+       /* Cezanne uses platform mailbox, Mendocino and later use doorbell

*/

Quoted 8 lines

drivers/i2c/busses/i2c-designware-amdpsp.c int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev) · line 299

Quoted 5 lines
drivers/i2c/busses/i2c-designware-amdpsp.c +5 -0
+       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_mendocino;

Thinking about naming again, perhaps "mendocino" should be dropped from the function name as the logic applies to all platforms except cezanne.

OK.