Skip to contentSkip to conversation

Use CCP driver to handle PSP I2C arbitration

PATCH Superseded Mario Limonciello 3 participants 15 messages Apr 3, 2023 – Apr 14, 2023

Subsystems (6)

v8 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Mario Limonciello

author maintainer
#0 lore raw

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

v7->v8:
* Pick up tags
* Drop hunk for error message change
* Fix kernel robot build failures

Mario Limonciello (6):
crypto: ccp: Drop extra doorbell checks
crypto: ccp: Bump up doorbell debug message to error
crypto: ccp: Return doorbell status code as an argument
crypto: ccp: Use lower 8 bytes to communicate with doorbell command
register
i2c: designware: Use PCI PSP driver for communication
i2c: designware: Add doorbell support for Mendocino

 drivers/crypto/ccp/platform-access.c        |  31 +--
 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         |   5 +-
 6 files changed, 62 insertions(+), 178 deletions(-)

base-commit: d6cb9ab4bfeaaa69147948e42d7cff080db82d07

Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH v8 1/6 crypto: ccp: Drop extra doorbell checks

The doorbell register set used for I2C arbitration is dedicated for this purpose and there is no need to utilize other safety checks the platform access register set uses.

---
 drivers/crypto/ccp/platform-access.c | 20 --------------------
 1 file changed, 20 deletions(-)
drivers/crypto/ccp/platform-access.c +0 -20
index b51fb1196932..1ad3a0a512b1 100644
@@ -20,14 +20,6 @@
 
 #define PSP_CMD_TIMEOUT_US	(500 * USEC_PER_MSEC)
 
-/* Doorbell shouldn't be ringing */
-static int check_doorbell(u32 __iomem *doorbell)
-{
-	u32 tmp;
-
-	return readl_poll_timeout(doorbell, tmp, tmp != 0, 0, PSP_CMD_TIMEOUT_US);
-}
-
 /* Recovery field should be equal 0 to start sending commands */
 static int check_recovery(u32 __iomem *cmd)
 {
@@ -156,18 +148,6 @@ 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");
-		ret = -EBUSY;
-		goto unlock;
-	}
-
-	if (check_recovery(cmd)) {
-		dev_dbg(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");
 		ret = -EBUSY;
Signature · 1 line
2.34.1
author maintainer
#2 lore raw

PATCH v8 2/6 crypto: ccp: Bump up doorbell debug message to error

In reply to Mario Limonciello

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

---
 drivers/crypto/ccp/platform-access.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/ccp/platform-access.c +1 -1
index 1ad3a0a512b1..1cc154a1c6ab 100644
@@ -149,7 +149,7 @@ int psp_ring_platform_doorbell(int msg)
 	mutex_lock(&pa_dev->doorbell_mutex);
 
 	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
#3 lore raw

PATCH v8 3/6 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.

---
 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 1cc154a1c6ab..48f59ae91692 100644
@@ -132,7 +132,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;
@@ -164,6 +164,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
author maintainer
#4 lore raw

PATCH v8 4/6 crypto: ccp: Use lower 8 bytes to communicate with doorbell command register

In reply to Mario Limonciello

Unlike other command registers used by the PSP, only the lower 8 bytes are used for communication for both command and status of the command.

---
 drivers/crypto/ccp/platform-access.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/crypto/ccp/platform-access.c +3 -2
index 48f59ae91692..939c924fc383 100644
@@ -19,6 +19,7 @@
 #include "platform-access.h"
 
 #define PSP_CMD_TIMEOUT_US	(500 * USEC_PER_MSEC)
+#define DOORBELL_CMDRESP_STS	GENMASK(7, 0)
 
 /* Recovery field should be equal 0 to start sending commands */
 static int check_recovery(u32 __iomem *cmd)
@@ -154,7 +155,7 @@ int psp_ring_platform_doorbell(int msg, u32 *result)
 		goto unlock;
 	}
 
-	iowrite32(FIELD_PREP(PSP_DRBL_MSG, msg), cmd);
+	iowrite32(FIELD_PREP(DOORBELL_CMDRESP_STS, msg), cmd);
 	iowrite32(PSP_DRBL_RING, button);
 
 	if (wait_cmd(cmd)) {
@@ -162,7 +163,7 @@ int psp_ring_platform_doorbell(int msg, u32 *result)
 		goto unlock;
 	}
 
-	val = FIELD_GET(PSP_CMDRESP_STS, ioread32(cmd));
+	val = FIELD_GET(DOORBELL_CMDRESP_STS, ioread32(cmd));
 	if (val) {
 		if (result)
 			*result = val;
Signature · 1 line
2.34.1
author maintainer
#5 lore raw

PATCH v8 5/6 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.

---
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
Acked-by on v8 5/6
#6 lore raw

Re: [PATCH v8 5/6] i2c: designware: Use PCI PSP driver for communication

Quoted 10 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.

maintainer
#7 lore raw

Re: [PATCH v8 5/6] i2c: designware: Use PCI PSP driver for communication

Quoted 7 lines · Wolfram Sang
Quoted 6 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.

Quoted 6 lines
Quoted 4 lines

Thanks, but as the original patch wasn't posted to linux-crypto so I can't pick this up.

Mario, could you repost just these two patches with the Acks added?

Cheers,

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
author maintainer
#8 lore raw

PATCH v8 6/6 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.

---
 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
Acked-by on v8 6/6
#9 lore raw

Re: [PATCH v8 6/6] i2c: designware: Add doorbell support for Mendocino

Quoted 11 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.

#10 lore raw
In reply to Mario Limonciello
Quoted 3 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.

How should this go upstream, i.e. are there dependencies? Shall I pick the I2C patches or is it better if all goes via the crypto tree?

author maintainer
#11 lore raw
Quoted 7 lines · Wolfram Sang
Quoted 3 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.

How should this go upstream, i.e. are there dependencies? Shall I pick the I2C patches or is it better if all goes via the crypto tree?

IMO it's better to go through the crypto tree.  There are dependencies in the crypto part from the earlier series that was merged.

#12 lore raw
Quoted 6 lines
Quoted 4 lines

How should this go upstream, i.e. are there dependencies? Shall I pick the I2C patches or is it better if all goes via the crypto tree?

IMO it's better to go through the crypto tree.  There are dependencies in the crypto part from the earlier series that was merged.

Ok, fine with me. I acked the I2C patches. Thanks for the heads up.

author maintainer
#13 lore raw
Quoted 9 lines · Wolfram Sang
Quoted 6 lines
Quoted 4 lines

How should this go upstream, i.e. are there dependencies? Shall I pick the I2C patches or is it better if all goes via the crypto tree?

IMO it's better to go through the crypto tree.  There are dependencies in the crypto part from the earlier series that was merged.

Ok, fine with me. I acked the I2C patches. Thanks for the heads up.

Herbert,

Would you mind to queue these up for -next? I do have some other separate work I will be submitting that is going to layer on top of them, so I'd like to base it off your branch with these landed.

maintainer
#14 lore raw
In reply to Mario Limonciello
Quoted 29 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.

v7->v8:
* Pick up tags
* Drop hunk for error message change
* Fix kernel robot build failures

Mario Limonciello (6):
crypto: ccp: Drop extra doorbell checks
crypto: ccp: Bump up doorbell debug message to error
crypto: ccp: Return doorbell status code as an argument
crypto: ccp: Use lower 8 bytes to communicate with doorbell command
register
i2c: designware: Use PCI PSP driver for communication
i2c: designware: Add doorbell support for Mendocino

 drivers/crypto/ccp/platform-access.c        |  31 +--
 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         |   5 +-
 6 files changed, 62 insertions(+), 178 deletions(-)
Quoted 3 lines

base-commit: d6cb9ab4bfeaaa69147948e42d7cff080db82d07

Signature · 1 line
2.34.1

Patches 1-4 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