mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tom Lendacky <thomas.lendacky@amd.com>
To: "Mario Limonciello" <mario.limonciello@amd.com>,
	"Jan Dąbroś" <jsd@semihalf.com>,
	"Grzegorz Bernacki" <gjb@semihalf.com>,
	Rijo-john.Thomas@amd.com, herbert@gondor.apana.org.au,
	"John Allen" <john.allen@amd.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 7/9] crypto: ccp: Add support for ringing a platform doorbell
Date: Thu, 2 Mar 2023 15:51:46 -0600	[thread overview]
Message-ID: <b52c68e6-2501-67c8-1fbd-60a35537c1f2@amd.com> (raw)
In-Reply-To: <20230302194235.1724-8-mario.limonciello@amd.com>

On 3/2/23 13:42, Mario Limonciello wrote:
> Some platforms support using a doorbell to communicate. Export
> this feature for other drivers to utilize as well.
> 
> Link: https://lore.kernel.org/linux-i2c/20220916131854.687371-3-jsd@semihalf.com/
> Suggested-by: Jan Dabros <jsd@semihalf.com>
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> ---
> v1->v2:
>   * New patch
> ---
>   drivers/crypto/ccp/platform-access.c | 47 ++++++++++++++++++++++++++++
>   drivers/crypto/ccp/sp-dev.h          |  1 +
>   include/linux/psp-platform-access.h  | 15 +++++++++
>   include/linux/psp.h                  |  3 ++
>   4 files changed, 66 insertions(+)
> 
> diff --git a/drivers/crypto/ccp/platform-access.c b/drivers/crypto/ccp/platform-access.c
> index af3a1e97abfe..0763389a2814 100644
> --- a/drivers/crypto/ccp/platform-access.c
> +++ b/drivers/crypto/ccp/platform-access.c
> @@ -135,6 +135,53 @@ 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(enum psp_platform_access_msg msg)
> +{
> +	struct psp_device *psp = psp_get_master_device();
> +	struct psp_platform_access_device *pa_dev;
> +	u32 __iomem *drbl;
> +	u32 drbl_reg;

Lets spell out doorbell for these two variable names.

> +	int ret;
> +
> +	if (!psp || !psp->platform_access_data)
> +		return -ENODEV;
> +
> +	pa_dev = psp->platform_access_data;
> +	drbl = psp->io_regs + pa_dev->vdata->doorbell_reg;
> +
> +	if (!drbl)
> +		return -ENODEV;

This will be non-zero because psp->io_regs will always be non-zero. Maybe 
you meant to check the actual pa_dev->vdata->doorbell_reg value?

I think you should squash this and patch #9 together so that patch #8 just 
works right away.

> +
> +	mutex_lock(&pa_dev->mutex);

Does the doorbell register operate independently from the other registers 
(C2PMSG_28 - C2PMSG_30)? If it does, you could probably just introduce a 
doorbell mutex.

> +
> +	if (check_recovery(drbl)) {
> +		dev_dbg(psp->dev, "in recovery\n");

Maybe a bit more info as to what is "in recovery" (that goes for patch #4, 
too) or just prefix it with "doorbell" (and "platform" in #4) since you 
now have duplicated messages.

> +		ret = -EBUSY;
> +		goto unlock;
> +	}
> +
> +	if (wait_cmd(drbl)) {
> +		dev_dbg(psp->dev, "not done processing command\n");

Ditto.

Thanks,
Tom

> +		ret = -EBUSY;
> +		goto unlock;
> +	}
> +
> +	drbl_reg = FIELD_PREP(PSP_DRBL_MSG, msg) | PSP_DRBL_RING;
> +	iowrite32(drbl_reg, drbl);
> +
> +	if (wait_cmd(drbl)) {
> +		ret = -ETIMEDOUT;
> +		goto unlock;
> +	}
> +
> +	ret = 0;
> +unlock:
> +	mutex_unlock(&pa_dev->mutex);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(psp_ring_platform_doorbell);
> +
>   void platform_access_dev_destroy(struct psp_device *psp)
>   {
>   	struct psp_platform_access_device *pa_dev = psp->platform_access_data;
> diff --git a/drivers/crypto/ccp/sp-dev.h b/drivers/crypto/ccp/sp-dev.h
> index 5ec6c219a731..87c0b9350bc2 100644
> --- a/drivers/crypto/ccp/sp-dev.h
> +++ b/drivers/crypto/ccp/sp-dev.h
> @@ -54,6 +54,7 @@ struct tee_vdata {
>   };
>   
>   struct platform_access_vdata {
> +	const unsigned int doorbell_reg;
>   	const unsigned int cmdresp_reg;
>   	const unsigned int cmdbuff_addr_lo_reg;
>   	const unsigned int cmdbuff_addr_hi_reg;
> diff --git a/include/linux/psp-platform-access.h b/include/linux/psp-platform-access.h
> index f5a03cd11f10..1e1d0e077cec 100644
> --- a/include/linux/psp-platform-access.h
> +++ b/include/linux/psp-platform-access.h
> @@ -35,6 +35,21 @@ struct psp_request {
>    */
>   int psp_send_platform_access_msg(enum psp_platform_access_msg, struct psp_request *req);
>   
> +/**
> + * psp_ring_platform_doorbell() - Ring platform doorbell
> + *
> + * This function is intended to be used by drivers outside of ccp to ring the
> + * platform doorbell with a message.
> + *
> + * Returns:
> + *  0:           success
> + *  -%EBUSY:     mailbox in recovery or in use
> + *  -%ENODEV:    driver not bound with PSP device
> + *  -%ETIMEDOUT: request timed out
> + *  -%EIO:       unknown error (see kernel log)
> + */
> +int psp_ring_platform_doorbell(enum psp_platform_access_msg);
> +
>   /**
>    * psp_check_platform_access_status() - Checks whether platform features is ready
>    *
> diff --git a/include/linux/psp.h b/include/linux/psp.h
> index d3424790a70e..92e60aeef21e 100644
> --- a/include/linux/psp.h
> +++ b/include/linux/psp.h
> @@ -23,4 +23,7 @@
>   #define PSP_CMDRESP_RECOVERY	BIT(30)
>   #define PSP_CMDRESP_RESP	BIT(31)
>   
> +#define PSP_DRBL_MSG		PSP_CMDRESP_CMD
> +#define PSP_DRBL_RING		BIT(0)
> +
>   #endif /* __PSP_H */

  reply	other threads:[~2023-03-02 21:56 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-02 19:42 [PATCH v2 0/9] Export platform features from ccp driver Mario Limonciello
2023-03-02 19:42 ` [PATCH v2 1/9] crypto: ccp: Drop TEE support for IRQ handler Mario Limonciello
2023-03-03 10:31   ` Rijo Thomas
2023-03-02 19:42 ` [PATCH v2 2/9] crypto: ccp: Add a header for multiple drivers to use `__psp_pa` Mario Limonciello
2023-03-02 19:42 ` [PATCH v2 3/9] crypto: ccp: Move some PSP mailbox bit definitions into common header Mario Limonciello
2023-03-03 10:36   ` Rijo Thomas
2023-03-02 19:42 ` [PATCH v2 4/9] crypto: ccp: Add support for an interface for platform features Mario Limonciello
2023-03-02 19:42 ` [PATCH v2 5/9] crypto: ccp: Enable platform access interface on client PSP parts Mario Limonciello
2023-03-02 19:42 ` [PATCH v2 6/9] i2c: designware: Use PCI PSP driver for communication Mario Limonciello
2023-03-02 19:42 ` [PATCH v2 7/9] crypto: ccp: Add support for ringing a platform doorbell Mario Limonciello
2023-03-02 21:51   ` Tom Lendacky [this message]
2023-03-02 21:55     ` Limonciello, Mario
2023-03-02 19:42 ` [PATCH v2 8/9] i2c: designware: Add doorbell support for Skyrim Mario Limonciello
2023-03-03 12:00   ` Grzegorz Bernacki
2023-03-03 15:00     ` Limonciello, Mario
2023-03-06 11:37       ` Andy Shevchenko
2023-03-02 19:42 ` [PATCH v2 9/9] crypto: ccp: Add doorbell register offset Mario Limonciello
2023-03-03 11:57   ` Grzegorz Bernacki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b52c68e6-2501-67c8-1fbd-60a35537c1f2@amd.com \
    --to=thomas.lendacky@amd.com \
    --cc=Rijo-john.Thomas@amd.com \
    --cc=davem@davemloft.net \
    --cc=gjb@semihalf.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=john.allen@amd.com \
    --cc=jsd@semihalf.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®