linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v5 0/3] Use CCP driver to handle PSP I2C arbitration
@ 2023-03-21 21:28 Mario Limonciello
  2023-03-21 21:28 ` [PATCH v5 1/3] crypto: ccp: Bump up doorbell debug messages to error Mario Limonciello
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Mario Limonciello @ 2023-03-21 21:28 UTC (permalink / raw)
  To: Mark Hasemeyer, Grzegorz Bernacki, Andy Shevchenko,
	Mika Westerberg, Jan Dabros, linux-crypto, linux-i2c
  Cc: Held Felix, Mario Limonciello, linux-kernel

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.

v4->v5:
 * Rebase on crypodev-2.6 with merged patches 1-5 & 7
 * Pick up tags
 * PCI dependency
 * Poll for busy
 * Make errors visible rather than debugging only.

Mario Limonciello (3):
  crypto: ccp: Bump up doorbell debug messages to error
  i2c: designware: Use PCI PSP driver for communication
  i2c: designware: Add doorbell support for Skyrim

 drivers/crypto/ccp/platform-access.c        |   7 +-
 drivers/i2c/busses/Kconfig                  |   3 +-
 drivers/i2c/busses/i2c-designware-amdpsp.c  | 192 +++++---------------
 drivers/i2c/busses/i2c-designware-core.h    |   1 -
 drivers/i2c/busses/i2c-designware-platdrv.c |   1 -
 include/linux/psp-platform-access.h         |   1 +
 6 files changed, 57 insertions(+), 148 deletions(-)


base-commit: e6af5c0c4d32a27e04a56f29aad587e03ff427f1
-- 
2.34.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v5 1/3] crypto: ccp: Bump up doorbell debug messages to error
  2023-03-21 21:28 [PATCH v5 0/3] Use CCP driver to handle PSP I2C arbitration Mario Limonciello
@ 2023-03-21 21:28 ` Mario Limonciello
  2023-03-21 21:28 ` [PATCH v5 2/3] i2c: designware: Use PCI PSP driver for communication Mario Limonciello
  2023-03-21 21:28 ` [PATCH v5 3/3] i2c: designware: Add doorbell support for Mendocino Mario Limonciello
  2 siblings, 0 replies; 10+ messages in thread
From: Mario Limonciello @ 2023-03-21 21:28 UTC (permalink / raw)
  To: Mark Hasemeyer, Grzegorz Bernacki, Mario Limonciello,
	Tom Lendacky, John Allen
  Cc: jsd, Held Felix, Herbert Xu, David S. Miller, linux-crypto, linux-kernel

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

Suggested-by: Grzegorz Bernacki <gjb@semihalf.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
 drivers/crypto/ccp/platform-access.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/ccp/platform-access.c b/drivers/crypto/ccp/platform-access.c
index b51fb1196932..b9f94e1aeb78 100644
--- a/drivers/crypto/ccp/platform-access.c
+++ b/drivers/crypto/ccp/platform-access.c
@@ -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;
 	}
@@ -184,6 +184,7 @@ int psp_ring_platform_doorbell(int msg)
 
 	val = FIELD_GET(PSP_CMDRESP_STS, ioread32(cmd));
 	if (val) {
+		dev_err(psp->dev, "doorbell response invalid: 0x%x\n", val);
 		ret = -EIO;
 		goto unlock;
 	}
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v5 2/3] i2c: designware: Use PCI PSP driver for communication
  2023-03-21 21:28 [PATCH v5 0/3] Use CCP driver to handle PSP I2C arbitration Mario Limonciello
  2023-03-21 21:28 ` [PATCH v5 1/3] crypto: ccp: Bump up doorbell debug messages to error Mario Limonciello
@ 2023-03-21 21:28 ` Mario Limonciello
  2023-03-22  3:26   ` kernel test robot
  2023-03-21 21:28 ` [PATCH v5 3/3] i2c: designware: Add doorbell support for Mendocino Mario Limonciello
  2 siblings, 1 reply; 10+ messages in thread
From: Mario Limonciello @ 2023-03-21 21:28 UTC (permalink / raw)
  To: Mark Hasemeyer, Grzegorz Bernacki, Jarkko Nikula,
	Andy Shevchenko, Mika Westerberg, Jan Dabros
  Cc: Held Felix, Mario Limonciello, Tom Lendacky, linux-i2c, linux-kernel

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.

Acked-by: Tom Lendacky <thomas.lendacky@amd.com>
Acked-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
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  | 142 ++------------------
 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, 11 insertions(+), 136 deletions(-)

diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 25eb4e8fd22f..d53bf716f97d 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -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.
diff --git a/drivers/i2c/busses/i2c-designware-amdpsp.c b/drivers/i2c/busses/i2c-designware-amdpsp.c
index 652e6b64bd5f..105584abcf8f 100644
--- a/drivers/i2c/busses/i2c-designware-amdpsp.c
+++ b/drivers/i2c/busses/i2c-designware-amdpsp.c
@@ -1,11 +1,8 @@
 // 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>
@@ -13,23 +10,15 @@
 #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 +30,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)
 {
@@ -182,10 +64,10 @@ static int psp_send_check_i2c_req(struct psp_i2c_req *req)
 	 * 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
+	 * errors on the first level (returned by psp_send_platform_access_msg) are shadowed by
 	 * -EIO.
 	 */
-	if (psp_send_cmd(req))
+	if (psp_send_platform_access_msg(PSP_I2C_REQ_BUS_CMD, (struct psp_request *)req))
 		return -EIO;
 
 	return check_i2c_req_sts(req);
@@ -202,7 +84,7 @@ 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;
@@ -381,7 +263,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(CRYPTO_DEV_CCP_DD))
+		return -ENODEV;
 
 	if (!dev)
 		return -ENODEV;
@@ -393,11 +276,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 +293,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);
-}
diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
index 050d8c63ad3c..c5d87aae39c6 100644
--- a/drivers/i2c/busses/i2c-designware-core.h
+++ b/drivers/i2c/busses/i2c-designware-core.h
@@ -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);
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index 74182db03a88..89ad88c54754 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -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
 	{}
diff --git a/include/linux/psp-platform-access.h b/include/linux/psp-platform-access.h
index 89df4549fada..aca3b148af93 100644
--- a/include/linux/psp-platform-access.h
+++ b/include/linux/psp-platform-access.h
@@ -7,6 +7,7 @@
 
 enum psp_platform_access_msg {
 	PSP_CMD_NONE = 0x0,
+	PSP_I2C_REQ_BUS_CMD = 0x64,
 };
 
 struct psp_req_buffer_hdr {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v5 3/3] i2c: designware: Add doorbell support for Mendocino
  2023-03-21 21:28 [PATCH v5 0/3] Use CCP driver to handle PSP I2C arbitration Mario Limonciello
  2023-03-21 21:28 ` [PATCH v5 1/3] crypto: ccp: Bump up doorbell debug messages to error Mario Limonciello
  2023-03-21 21:28 ` [PATCH v5 2/3] i2c: designware: Use PCI PSP driver for communication Mario Limonciello
@ 2023-03-21 21:28 ` Mario Limonciello
  2023-03-22 17:01   ` Mark Hasemeyer
  2 siblings, 1 reply; 10+ messages in thread
From: Mario Limonciello @ 2023-03-21 21:28 UTC (permalink / raw)
  To: Mark Hasemeyer, Grzegorz Bernacki, Jarkko Nikula,
	Andy Shevchenko, Mika Westerberg, Jan Dabros
  Cc: Held Felix, Mario Limonciello, linux-i2c, linux-kernel

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.

Link: https://lore.kernel.org/linux-i2c/20220916131854.687371-3-jsd@semihalf.com/
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
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 | 52 +++++++++++++++++-----
 2 files changed, 43 insertions(+), 10 deletions(-)

diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index d53bf716f97d..2aba5ffa8b03 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -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
diff --git a/drivers/i2c/busses/i2c-designware-amdpsp.c b/drivers/i2c/busses/i2c-designware-amdpsp.c
index 105584abcf8f..87b6cc345d1d 100644
--- a/drivers/i2c/busses/i2c-designware-amdpsp.c
+++ b/drivers/i2c/busses/i2c-designware-amdpsp.c
@@ -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>
@@ -36,6 +37,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)(enum psp_i2c_req_type);
+
 /* Helper to verify status returned by PSP */
 static int check_i2c_req_sts(struct psp_i2c_req *req)
 {
@@ -73,34 +76,55 @@ static int psp_send_check_i2c_req(struct psp_i2c_req *req)
 	return check_i2c_req_sts(req);
 }
 
-static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type)
+static int psp_send_i2c_req_cezanne(enum psp_i2c_req_type i2c_req_type)
 {
 	struct psp_i2c_req *req;
-	unsigned long start;
 	int status, ret;
 
 	/* Allocate command-response buffer */
 	req = kzalloc(sizeof(*req), GFP_KERNEL);
 	if (!req)
 		return -ENOMEM;
-
 	req->hdr.payload_size = sizeof(*req);
 	req->type = i2c_req_type;
-
-	start = jiffies;
 	ret = read_poll_timeout(psp_send_check_i2c_req, status,
 				(status != -EBUSY),
 				PSP_I2C_REQ_RETRY_DELAY_US,
 				PSP_I2C_REQ_RETRY_CNT * PSP_I2C_REQ_RETRY_DELAY_US,
 				0, req);
-	if (ret) {
+	kfree(req);
+
+	if (ret)
 		dev_err(psp_i2c_dev, "Timed out waiting for PSP to %s I2C bus\n",
 			(i2c_req_type == PSP_I2C_REQ_ACQUIRE) ?
 			"release" : "acquire");
-		goto cleanup;
-	}
 
-	ret = status;
+	return ret ? ret : status;
+}
+
+static int psp_send_i2c_req_mendocino(enum psp_i2c_req_type i2c_req_type)
+{
+	int status, ret;
+
+	ret = read_poll_timeout(psp_ring_platform_doorbell, status,
+				(status != -EBUSY),
+				PSP_I2C_REQ_RETRY_DELAY_US,
+				PSP_I2C_REQ_RETRY_CNT * PSP_I2C_REQ_RETRY_DELAY_US,
+				0, i2c_req_type);
+	if (ret)
+		dev_err(psp_i2c_dev, "Timed out waiting for PSP to %s I2C bus\n",
+			(i2c_req_type == PSP_I2C_REQ_ACQUIRE) ?
+			"release" : "acquire");
+
+	return ret ? ret : status;
+}
+
+static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type)
+{
+	unsigned long start = jiffies;
+	int ret;
+
+	ret = _psp_send_i2c_req(i2c_req_type);
 	if (ret) {
 		dev_err(psp_i2c_dev, "PSP communication error\n");
 		goto cleanup;
@@ -115,7 +139,6 @@ static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type)
 		psp_i2c_mbox_fail = true;
 	}
 
-	kfree(req);
 	return ret;
 }
 
@@ -263,6 +286,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(CRYPTO_DEV_CCP_DD))
 		return -ENODEV;
 
@@ -276,6 +301,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;
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v5 2/3] i2c: designware: Use PCI PSP driver for communication
  2023-03-21 21:28 ` [PATCH v5 2/3] i2c: designware: Use PCI PSP driver for communication Mario Limonciello
@ 2023-03-22  3:26   ` kernel test robot
  2023-03-22  9:45     ` Andy Shevchenko
  0 siblings, 1 reply; 10+ messages in thread
From: kernel test robot @ 2023-03-22  3:26 UTC (permalink / raw)
  To: Mario Limonciello, Mark Hasemeyer, Grzegorz Bernacki,
	Jarkko Nikula, Andy Shevchenko, Mika Westerberg, Jan Dabros
  Cc: oe-kbuild-all, Held Felix, Mario Limonciello, Tom Lendacky,
	linux-i2c, linux-kernel

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/20230322-053048
base:   e6af5c0c4d32a27e04a56f29aad587e03ff427f1
patch link:    https://lore.kernel.org/r/20230321212822.5714-3-mario.limonciello%40amd.com
patch subject: [PATCH v5 2/3] i2c: designware: Use PCI PSP driver for communication
config: loongarch-allmodconfig (https://download.01.org/0day-ci/archive/20230322/202303221157.58L3rUhr-lkp@intel.com/config)
compiler: loongarch64-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/0ddf14b7f34bfe410e49c800d855f4e0c59d6bef
        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/20230322-053048
        git checkout 0ddf14b7f34bfe410e49c800d855f4e0c59d6bef
        # 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=loongarch olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=loongarch SHELL=/bin/bash drivers/i2c/busses/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202303221157.58L3rUhr-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/i2c/busses/i2c-designware-amdpsp.c:8:10: fatal error: asm/msr.h: No such file or directory
       8 | #include <asm/msr.h>
         |          ^~~~~~~~~~~
   compilation terminated.


vim +8 drivers/i2c/busses/i2c-designware-amdpsp.c

78d5e9e299e31b Jan Dabros 2022-02-08  7  
78d5e9e299e31b Jan Dabros 2022-02-08 @8  #include <asm/msr.h>
78d5e9e299e31b Jan Dabros 2022-02-08  9  

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v5 2/3] i2c: designware: Use PCI PSP driver for communication
  2023-03-22  3:26   ` kernel test robot
@ 2023-03-22  9:45     ` Andy Shevchenko
  2023-03-22 15:56       ` Mario Limonciello
  0 siblings, 1 reply; 10+ messages in thread
From: Andy Shevchenko @ 2023-03-22  9:45 UTC (permalink / raw)
  To: kernel test robot
  Cc: Mario Limonciello, Mark Hasemeyer, Grzegorz Bernacki,
	Jarkko Nikula, Mika Westerberg, Jan Dabros, oe-kbuild-all,
	Held Felix, Tom Lendacky, linux-i2c, linux-kernel

On Wed, Mar 22, 2023 at 11:26:01AM +0800, kernel test robot wrote:

...

> All errors (new ones prefixed by >>):
> 
> >> drivers/i2c/busses/i2c-designware-amdpsp.c:8:10: fatal error: asm/msr.h: No such file or directory
>        8 | #include <asm/msr.h>
>          |          ^~~~~~~~~~~
>    compilation terminated.

Should be under "#ifdef CONFIG_X86" (IIRC).

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v5 2/3] i2c: designware: Use PCI PSP driver for communication
  2023-03-22  9:45     ` Andy Shevchenko
@ 2023-03-22 15:56       ` Mario Limonciello
  0 siblings, 0 replies; 10+ messages in thread
From: Mario Limonciello @ 2023-03-22 15:56 UTC (permalink / raw)
  To: Andy Shevchenko, kernel test robot
  Cc: Mark Hasemeyer, Grzegorz Bernacki, Jarkko Nikula,
	Mika Westerberg, Jan Dabros, oe-kbuild-all, Held Felix,
	Tom Lendacky, linux-i2c, linux-kernel


On 3/22/23 04:45, Andy Shevchenko wrote:
> On Wed, Mar 22, 2023 at 11:26:01AM +0800, kernel test robot wrote:
>
> ...
>
>> All errors (new ones prefixed by >>):
>>
>>>> drivers/i2c/busses/i2c-designware-amdpsp.c:8:10: fatal error: asm/msr.h: No such file or directory
>>         8 | #include <asm/msr.h>
>>           |          ^~~~~~~~~~~
>>     compilation terminated.
> Should be under "#ifdef CONFIG_X86" (IIRC).
>
Actually the header isn't needed anymore with these changes.

I'll drop it in the next version of the series once I have some updated 
results from Grzegorz and Jan.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v5 3/3] i2c: designware: Add doorbell support for Mendocino
  2023-03-21 21:28 ` [PATCH v5 3/3] i2c: designware: Add doorbell support for Mendocino Mario Limonciello
@ 2023-03-22 17:01   ` Mark Hasemeyer
  2023-03-22 17:12     ` Mario Limonciello
  0 siblings, 1 reply; 10+ messages in thread
From: Mark Hasemeyer @ 2023-03-22 17:01 UTC (permalink / raw)
  To: Mario Limonciello
  Cc: Grzegorz Bernacki, Jarkko Nikula, Andy Shevchenko,
	Mika Westerberg, Jan Dabros, Held Felix, linux-i2c, linux-kernel

> +static int psp_send_i2c_req_mendocino(enum psp_i2c_req_type i2c_req_type)
> +{
> +       int status, ret;
> +
> +       ret = read_poll_timeout(psp_ring_platform_doorbell, status,
> +                               (status != -EBUSY),
> +                               PSP_I2C_REQ_RETRY_DELAY_US,
> +                               PSP_I2C_REQ_RETRY_CNT * PSP_I2C_REQ_RETRY_DELAY_US,
> +                               0, i2c_req_type);
> +       if (ret)
> +               dev_err(psp_i2c_dev, "Timed out waiting for PSP to %s I2C bus\n",
> +                       (i2c_req_type == PSP_I2C_REQ_ACQUIRE) ?
> +                       "release" : "acquire");
> +
> +       return ret ? ret : status;
> +}

I think we need the value of the PSP_CMDRESP_STS field returned to the caller
and its status checked like in psp_send_i2c_req_cezanne. Otherwise the function
won't continue to poll when the PSP_I2C_REQ_STS_BUS_BUSY bit is set.

FYI - there's a test on ChromeOS to stress test I2C bus arbitration:
https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/tast-tests/src/chromiumos/tast/local/bundles/cros/hwsec/tpm_contest.go
I can try to run it assuming the ToT kernel runs on skyrim.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v5 3/3] i2c: designware: Add doorbell support for Mendocino
  2023-03-22 17:01   ` Mark Hasemeyer
@ 2023-03-22 17:12     ` Mario Limonciello
  2023-03-22 17:32       ` Mark Hasemeyer
  0 siblings, 1 reply; 10+ messages in thread
From: Mario Limonciello @ 2023-03-22 17:12 UTC (permalink / raw)
  To: Mark Hasemeyer
  Cc: Grzegorz Bernacki, Jarkko Nikula, Andy Shevchenko,
	Mika Westerberg, Jan Dabros, Held Felix, linux-i2c, linux-kernel


On 3/22/23 12:01, Mark Hasemeyer wrote:
>> +static int psp_send_i2c_req_mendocino(enum psp_i2c_req_type i2c_req_type)
>> +{
>> +       int status, ret;
>> +
>> +       ret = read_poll_timeout(psp_ring_platform_doorbell, status,
>> +                               (status != -EBUSY),
>> +                               PSP_I2C_REQ_RETRY_DELAY_US,
>> +                               PSP_I2C_REQ_RETRY_CNT * PSP_I2C_REQ_RETRY_DELAY_US,
>> +                               0, i2c_req_type);
>> +       if (ret)
>> +               dev_err(psp_i2c_dev, "Timed out waiting for PSP to %s I2C bus\n",
>> +                       (i2c_req_type == PSP_I2C_REQ_ACQUIRE) ?
>> +                       "release" : "acquire");
>> +
>> +       return ret ? ret : status;
>> +}
> I think we need the value of the PSP_CMDRESP_STS field returned to the caller
> and its status checked like in psp_send_i2c_req_cezanne. Otherwise the function
> won't continue to poll when the PSP_I2C_REQ_STS_BUS_BUSY bit is set.

In that case it looks like psp_send_check_i2c_req isn't handling this 
properly
for Cezanne either in this series.  I think psp_send_platform_access_msg
returning -EIO is going to mean that check_i2c_req_sts never gets run.

So either psp_send_platform_access_msg should return 0 for that case
(expecting caller to investigate more closely) or psp_send_check_i2c_req
needs to special case -EIO for more investigation.

I lean upon the latter unless you have a strong opinion.

>
> FYI - there's a test on ChromeOS to stress test I2C bus arbitration:
> https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/tast-tests/src/chromiumos/tast/local/bundles/cros/hwsec/tpm_contest.go
> I can try to run it assuming the ToT kernel runs on skyrim.

I would expect ToT should run fine on Skyrim.  I'll adjust as you suggested
if you can please test it.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v5 3/3] i2c: designware: Add doorbell support for Mendocino
  2023-03-22 17:12     ` Mario Limonciello
@ 2023-03-22 17:32       ` Mark Hasemeyer
  0 siblings, 0 replies; 10+ messages in thread
From: Mark Hasemeyer @ 2023-03-22 17:32 UTC (permalink / raw)
  To: Mario Limonciello
  Cc: Grzegorz Bernacki, Jarkko Nikula, Andy Shevchenko,
	Mika Westerberg, Jan Dabros, Held Felix, linux-i2c, linux-kernel

> So either psp_send_platform_access_msg should return 0 for that case
> (expecting caller to investigate more closely) or psp_send_check_i2c_req
> needs to special case -EIO for more investigation.
>
> I lean upon the latter unless you have a strong opinion.

I'm ok with either, but if you go with the latter, the documentation
will need to be updated in psp_send_check_i2c_req as it states that
-EIO is used for basic mailbox comm errors.

> I would expect ToT should run fine on Skyrim.  I'll adjust as you suggested
> if you can please test it.

Sure! I can test the next version you send out.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-03-22 17:32 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-21 21:28 [PATCH v5 0/3] Use CCP driver to handle PSP I2C arbitration Mario Limonciello
2023-03-21 21:28 ` [PATCH v5 1/3] crypto: ccp: Bump up doorbell debug messages to error Mario Limonciello
2023-03-21 21:28 ` [PATCH v5 2/3] i2c: designware: Use PCI PSP driver for communication Mario Limonciello
2023-03-22  3:26   ` kernel test robot
2023-03-22  9:45     ` Andy Shevchenko
2023-03-22 15:56       ` Mario Limonciello
2023-03-21 21:28 ` [PATCH v5 3/3] i2c: designware: Add doorbell support for Mendocino Mario Limonciello
2023-03-22 17:01   ` Mark Hasemeyer
2023-03-22 17:12     ` Mario Limonciello
2023-03-22 17:32       ` Mark Hasemeyer

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