[PATCH v2 14/27] nvdimm/ocxl: Add support for near storage commands

Alastair D'Silva
2019-12-03T03:50:12Z

From: Alastair D'Silva <alastair@d-silva.org>

Similar to the previous patch, this adds support for near storage commands.

Signed-off-by: Alastair D'Silva <alastair@d-silva.org>
---
drivers/nvdimm/ocxl/scm.c | 6 +++++
drivers/nvdimm/ocxl/scm_internal.c | 41 ++++++++++++++++++++++++++++++
drivers/nvdimm/ocxl/scm_internal.h | 38 +++++++++++++++++++++++++++
3 files changed, 85 insertions(+)

diff --git a/drivers/nvdimm/ocxl/scm.c b/drivers/nvdimm/ocxl/scm.c
index 1e175f3c3cf2..6c16ca7fabfa 100644
--- a/drivers/nvdimm/ocxl/scm.c
+++ b/drivers/nvdimm/ocxl/scm.c
@@ -310,12 +310,18 @@ static int scm_setup_command_metadata(struct scm_data *scm_data)
int rc;

mutex_init(&scm_data->admin_command.lock);
+ mutex_init(&scm_data->ns_command.lock);

rc = scm_extract_command_metadata(scm_data, GLOBAL_MMIO_ACMA_CREQO,
&scm_data->admin_command);
if (rc)
return rc;

+ rc = scm_extract_command_metadata(scm_data, GLOBAL_MMIO_NSCMA_CREQO,
+ &scm_data->ns_command);
+ if (rc)
+ return rc;
+
return 0;
}

diff --git a/drivers/nvdimm/ocxl/scm_internal.c b/drivers/nvdimm/ocxl/scm_internal.c
index 7b11b56863fb..c405f1d8afb8 100644
--- a/drivers/nvdimm/ocxl/scm_internal.c
+++ b/drivers/nvdimm/ocxl/scm_internal.c
@@ -132,6 +132,47 @@ int scm_admin_response_handled(const struct scm_data *scm_data)
OCXL_LITTLE_ENDIAN, GLOBAL_MMIO_CHI_ACRA);
}

+int scm_ns_command_request(struct scm_data *scm_data, u8 op_code)
+{
+ u64 val;
+ int rc = ocxl_global_mmio_read64(scm_data->ocxl_afu, GLOBAL_MMIO_CHI,
+ OCXL_LITTLE_ENDIAN, &val);
+ if (rc)
+ return rc;
+
+ if (!(val & GLOBAL_MMIO_CHI_NSCRA))
+ return -EBUSY;
+
+ return scm_command_request(scm_data, &scm_data->ns_command, op_code);
+}
+
+int scm_ns_response(const struct scm_data *scm_data)
+{
+ return scm_command_response(scm_data, &scm_data->ns_command);
+}
+
+int scm_ns_command_execute(const struct scm_data *scm_data)
+{
+ return ocxl_global_mmio_set64(scm_data->ocxl_afu, GLOBAL_MMIO_HCI,
+ OCXL_LITTLE_ENDIAN, GLOBAL_MMIO_HCI_NSCRW);
+}
+
+bool scm_ns_command_complete(const struct scm_data *scm_data)
+{
+ u64 val = 0;
+ int rc = scm_chi(scm_data, &val);
+
+ WARN_ON(rc);
+
+ return (val & GLOBAL_MMIO_CHI_NSCRA) != 0;
+}
+
+int scm_ns_response_handled(const struct scm_data *scm_data)
+{
+ return ocxl_global_mmio_set64(scm_data->ocxl_afu, GLOBAL_MMIO_CHIC,
+ OCXL_LITTLE_ENDIAN, GLOBAL_MMIO_CHI_NSCRA);
+}
+
void scm_warn_status(const struct scm_data *scm_data, const char *message,
u8 status)
{
diff --git a/drivers/nvdimm/ocxl/scm_internal.h b/drivers/nvdimm/ocxl/scm_internal.h
index 9bff684cd069..9575996a89e7 100644
--- a/drivers/nvdimm/ocxl/scm_internal.h
+++ b/drivers/nvdimm/ocxl/scm_internal.h
@@ -108,6 +108,7 @@ struct scm_data {
struct ocxl_context *ocxl_context;
void *metadata_addr;
struct command_metadata admin_command;
+ struct command_metadata ns_command;
struct resource scm_res;
struct nd_region *nd_region;
char fw_version[8+1];
@@ -176,6 +177,42 @@ int scm_admin_command_complete_timeout(const struct scm_data *scm_data,
*/
int scm_admin_response_handled(const struct scm_data *scm_data);

+/**
+ * scm_ns_command_request() - Issue a near storage command request
+ * @scm_data: a pointer to the SCM device data
+ * @op_code: The op-code for the command
+ * Returns an identifier for the command, or negative on error
+ */
+int scm_ns_command_request(struct scm_data *scm_data, u8 op_code);
+
+/**
+ * scm_ns_response() - Validate a near storage response
+ * @scm_data: a pointer to the SCM device data
+ * Returns the status code of the command, or negative on error
+ */
+int scm_ns_response(const struct scm_data *scm_data);
+
+/**
+ * scm_ns_command_execute() - Notify the controller to start processing a pending near storage command
+ * @scm_data: a pointer to the SCM device data
+ * Returns 0 on success, negative on error
+ */
+int scm_ns_command_execute(const struct scm_data *scm_data);
+
+/**
+ * scm_ns_command_complete() - Is a near storage command executing
+ * scm_data: a pointer to the SCM device data
+ * Returns true if the previous admin command has completed
+ */
+bool scm_ns_command_complete(const struct scm_data *scm_data);
+
+/**
+ * scm_ns_response_handled() - Notify the controller that the near storage response has been handled
+ * scm_data: a pointer to the SCM device data
+ * Returns 0 on success, negative on failure
+ */
+int scm_ns_response_handled(const struct scm_data *scm_data);
+
/**
* scm_warn_status() - Emit a kernel warning showing a command status.
* @scm_data: a pointer to the SCM device data
@@ -184,3 +221,4 @@ int scm_admin_response_handled(const struct scm_data *scm_data);
*/
void scm_warn_status(const struct scm_data *scm_data, const char *message,
u8 status);
+
--
2.23.0