Re: [PATCH v2 22/27] nvdimm/ocxl: Implement the heartbeat command
From: Jonathan Cameron
Date: Mon Feb 03 2020 - 10:11:56 EST
On Tue, 3 Dec 2019 14:46:50 +1100
Alastair D'Silva <alastair@xxxxxxxxxxx> wrote:
> From: Alastair D'Silva <alastair@xxxxxxxxxxx>
>
> The heartbeat admin command is a simple admin command that exercises
> the communication mechanisms within the controller.
>
> This patch issues a heartbeat command to the card during init to ensure
> we can communicate with the card's crontroller.
controller
>
> Signed-off-by: Alastair D'Silva <alastair@xxxxxxxxxxx>
> ---
> drivers/nvdimm/ocxl/scm.c | 43 +++++++++++++++++++++++++++++++++++++++
> 1 file changed, 43 insertions(+)
>
> diff --git a/drivers/nvdimm/ocxl/scm.c b/drivers/nvdimm/ocxl/scm.c
> index 8a30c887b5ed..e8b34262f397 100644
> --- a/drivers/nvdimm/ocxl/scm.c
> +++ b/drivers/nvdimm/ocxl/scm.c
> @@ -353,6 +353,44 @@ static bool scm_is_usable(const struct scm_data *scm_data)
> return true;
> }
>
> +/**
> + * scm_heartbeat() - Issue a heartbeat command to the controller
> + * @scm_data: a pointer to the SCM device data
> + * Return: 0 if the controller responded correctly, negative on error
> + */
> +static int scm_heartbeat(struct scm_data *scm_data)
> +{
> + int rc;
> +
> + mutex_lock(&scm_data->admin_command.lock);
> +
> + rc = scm_admin_command_request(scm_data, ADMIN_COMMAND_HEARTBEAT);
> + if (rc)
> + goto out;
> +
> + rc = scm_admin_command_execute(scm_data);
> + if (rc)
> + goto out;
> +
> + rc = scm_admin_command_complete_timeout(scm_data, ADMIN_COMMAND_HEARTBEAT);
> + if (rc < 0) {
> + dev_err(&scm_data->dev, "Heartbeat timeout\n");
> + goto out;
> + }
> +
> + rc = scm_admin_response(scm_data);
> + if (rc < 0)
> + goto out;
> + if (rc != STATUS_SUCCESS)
> + scm_warn_status(scm_data, "Unexpected status from heartbeat", rc);
> +
> + rc = scm_admin_response_handled(scm_data);
> +
> +out:
> + mutex_unlock(&scm_data->admin_command.lock);
> + return rc;
> +}
> +
> /**
> * allocate_scm_minor() - Allocate a minor number to use for an SCM device
> * @scm_data: The SCM device to associate the minor with
> @@ -1508,6 +1546,11 @@ static int scm_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
> goto err;
> }
>
> + if (scm_heartbeat(scm_data)) {
> + dev_err(&pdev->dev, "SCM Heartbeat failed\n");
> + goto err;
> + }
> +
> elapsed = 0;
> timeout = scm_data->readiness_timeout + scm_data->memory_available_timeout;
> while (!scm_is_usable(scm_data)) {