Skip to contentSkip to conversation

Add missing firmware_status checks

PATCH Superseded Vishal Verma 2 participants 9 messages Jan 11, 2019 – Jan 12, 2019 libnvdimm: non-volatile memory device

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Vishal Verma

author maintainer
#0 lore raw

cover Add missing firmware_status checks

There were several places in ndctl where we neglected to check the firmware_status from a command submission.

Add an ndctl_dimm_op target to perform error translation for a DSM family, and provide a new helper -ndctl_cmd_submit_xlat - that will submit the command and call an error translation routing if one has been registered.

Finally, switch the call sites in ndctl/inject-smart.c and ndctl/monitor.c over to the new command submission helper.

Vishal Verma (3):
libndctl, intel: Add infrastructure for firmware_status translation ndctl, inject-smart: switch to ndctl_cmd_submit_xlat ndctl, monitor: switch to ndctl_cmd_submit_xlat

 ndctl/inject-smart.c   |  8 +++----
 ndctl/lib/intel.c      | 49 ++++++++++++++++++++++++++++++++++++++++++
 ndctl/lib/intel.h      |  1 +
 ndctl/lib/libndctl.c   | 26 ++++++++++++++++++++++
 ndctl/lib/libndctl.sym |  6 ++++++
 ndctl/lib/private.h    |  1 +
 ndctl/libndctl.h       |  3 +++
 ndctl/monitor.c        |  4 ++--
 8 files changed, 92 insertions(+), 6 deletions(-)
Signature · 6 lines
2.17.2

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
author maintainer
#1 lore raw

PATCH 1/3 libndctl, intel: Add infrastructure for firmware_status translation

Add a new routine to ndctl_dimm_ops that allows a DSM family to provide a translation routine that will translate the status codes of the result of a DSM to generic errno style error codes. To use this routine effectively, add a new wrapper around ndctl_cmd_submit (called ndctl_cmd_submit_xlat) that submits the command, and also runs it through the above translator dimm_op (if one is is defined).

---
 ndctl/lib/intel.c      | 49 ++++++++++++++++++++++++++++++++++++++++++
 ndctl/lib/intel.h      |  1 +
 ndctl/lib/libndctl.c   | 26 ++++++++++++++++++++++
 ndctl/lib/libndctl.sym |  6 ++++++
 ndctl/lib/private.h    |  1 +
 ndctl/libndctl.h       |  3 +++
 6 files changed, 86 insertions(+)
ndctl/lib/intel.c +49 -0
index 744386f..d684bac 100644
@@ -16,6 +16,54 @@
 #include <ndctl/libndctl.h>
 #include "private.h"
 
+static int intel_cmd_xlat_firmware_status(struct ndctl_cmd *cmd)
+{
+	struct nd_pkg_intel *pkg = cmd->intel;
+	unsigned int status, ext_status;
+
+	status = (*cmd->firmware_status) & ND_INTEL_STATUS_MASK;
+	ext_status = (*cmd->firmware_status) & ND_INTEL_STATUS_EXTEND_MASK;
+
+	/* Common statuses */
+	switch (status) {
+	case ND_INTEL_STATUS_SUCCESS:
+		return 0;
+	case ND_INTEL_STATUS_NOTSUPP:
+		return -EOPNOTSUPP;
+	case ND_INTEL_STATUS_NOTEXIST:
+		return -ENXIO;
+	case ND_INTEL_STATUS_INVALPARM:
+		return -EINVAL;
+	case ND_INTEL_STATUS_HWERR:
+		return -EIO;
+	case ND_INTEL_STATUS_RETRY:
+		return -EAGAIN;
+	case ND_INTEL_STATUS_EXTEND:
+		/* refer to extended status, break out of this */
+		break;
+	case ND_INTEL_STATUS_NORES:
+		return -EAGAIN;
+	case ND_INTEL_STATUS_NOTREADY:
+		return -EBUSY;
+	}
+
+	/* Extended status is command specific */
+	switch (pkg->gen.nd_command) {
+	case ND_INTEL_SMART:
+	case ND_INTEL_SMART_THRESHOLD:
+	case ND_INTEL_SMART_SET_THRESHOLD:
+		/* ext status not specified */
+		break;
+	case ND_INTEL_SMART_INJECT:
+		/* smart injection not enabled */
+		if (ext_status == ND_INTEL_STATUS_INJ_DISABLED)
+			return -ENXIO;
+		break;
+	}
+
+	return -ENOMSG;
+}
+
 static struct ndctl_cmd *alloc_intel_cmd(struct ndctl_dimm *dimm,
 		unsigned func, size_t in_size, size_t out_size)
 {
@@ -780,4 +828,5 @@ struct ndctl_dimm_ops * const intel_dimm_ops = &(struct ndctl_dimm_ops) {
 	.fw_xlat_firmware_status = intel_cmd_fw_xlat_firmware_status,
 	.new_ack_shutdown_count = intel_dimm_cmd_new_lss,
 	.fw_update_supported = intel_dimm_fw_update_supported,
+	.xlat_firmware_status = intel_cmd_xlat_firmware_status,
 };
ndctl/lib/intel.h +1 -0
index 3b01bba..530c996 100644
@@ -179,5 +179,6 @@ struct nd_pkg_intel {
 #define ND_INTEL_STATUS_FQ_BUSY		0x20000
 #define ND_INTEL_STATUS_FQ_BAD		0x30000
 #define ND_INTEL_STATUS_FQ_ORDER	0x40000
+#define ND_INTEL_STATUS_INJ_DISABLED	0x10000
 
 #endif /* __INTEL_H__ */
ndctl/lib/libndctl.c +26 -0
index e82a08d..5f1fd84 100644
@@ -2704,6 +2704,16 @@ static const char *ndctl_dimm_get_cmd_subname(struct ndctl_cmd *cmd)
 	return ops->cmd_desc(cmd->pkg->nd_command);
 }
 
+NDCTL_EXPORT int ndctl_cmd_xlat_firmware_status(struct ndctl_cmd *cmd)
+{
+	struct ndctl_dimm *dimm = cmd->dimm;
+	struct ndctl_dimm_ops *ops = dimm ? dimm->ops : NULL;
+
+	if (!dimm || !ops || !ops->xlat_firmware_status)
+		return -ENOMSG;
+	return ops->xlat_firmware_status(cmd);
+}
+
 static int do_cmd(int fd, int ioctl_cmd, struct ndctl_cmd *cmd)
 {
 	int rc;
@@ -2819,6 +2829,22 @@ NDCTL_EXPORT int ndctl_cmd_submit(struct ndctl_cmd *cmd)
 	return rc;
 }
 
+NDCTL_EXPORT int ndctl_cmd_submit_xlat(struct ndctl_cmd *cmd)
+{
+	int rc;
+
+	rc = ndctl_cmd_submit(cmd);
+	if (rc < 0)
+		return rc;
+
+	/*
+	 * NOTE: This loses a positive rc which happens in the case of a
+	 * buffer underrun. If the caller cares about that (usually not very
+	 * useful), then the xlat function is available separately as well.
+	 */
+	return ndctl_cmd_xlat_firmware_status(cmd);
+}
+
 NDCTL_EXPORT int ndctl_cmd_get_status(struct ndctl_cmd *cmd)
 {
 	return cmd->status;
ndctl/lib/libndctl.sym +6 -0
index 6c4c8b4..275db92 100644
@@ -385,3 +385,9 @@ global:
 	ndctl_namespace_get_next_badblock;
 	ndctl_dimm_get_dirty_shutdown;
 } LIBNDCTL_17;
+
+LIBNDCTL_19 {
+global:
+	ndctl_cmd_xlat_firmware_status;
+	ndctl_cmd_submit_xlat;
+} LIBNDCTL_18;
ndctl/lib/private.h +1 -0
index 4fbea56..a387b0b 100644
@@ -338,6 +338,7 @@ struct ndctl_dimm_ops {
 	enum ND_FW_STATUS (*fw_xlat_firmware_status)(struct ndctl_cmd *);
 	struct ndctl_cmd *(*new_ack_shutdown_count)(struct ndctl_dimm *);
 	int (*fw_update_supported)(struct ndctl_dimm *);
+	int (*xlat_firmware_status)(struct ndctl_cmd *);
 };
 
 struct ndctl_dimm_ops * const intel_dimm_ops;
ndctl/libndctl.h +3 -0
index c81cc03..e55a593 100644
@@ -681,6 +681,9 @@ enum ND_FW_STATUS ndctl_cmd_fw_xlat_firmware_status(struct ndctl_cmd *cmd);
 struct ndctl_cmd *ndctl_dimm_cmd_new_ack_shutdown_count(struct ndctl_dimm *dimm);
 int ndctl_dimm_fw_update_supported(struct ndctl_dimm *dimm);
 
+int ndctl_cmd_xlat_firmware_status(struct ndctl_cmd *cmd);
+int ndctl_cmd_submit_xlat(struct ndctl_cmd *cmd);
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
Signature · 6 lines
2.17.2

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
#2 lore raw

Re: [ndctl PATCH 1/3] libndctl, intel: Add infrastructure for firmware_status translation

Quoted 10 lines · Vishal Verma

Add a new routine to ndctl_dimm_ops that allows a DSM family to provide a translation routine that will translate the status codes of the result of a DSM to generic errno style error codes. To use this routine effectively, add a new wrapper around ndctl_cmd_submit (called ndctl_cmd_submit_xlat) that submits the command, and also runs it through the above translator dimm_op (if one is is defined).

[..]

ndctl/lib/libndctl.c NDCTL_EXPORT int ndctl_cmd_submit(struct ndctl_cmd *cmd) · line 2844

Quoted 13 lines
ndctl/lib/libndctl.c +13 -0
+NDCTL_EXPORT int ndctl_cmd_submit_xlat(struct ndctl_cmd *cmd)
+{
+       int rc;
+
+       rc = ndctl_cmd_submit(cmd);
+       if (rc < 0)
+               return rc;
+
+       /*
+        * NOTE: This loses a positive rc which happens in the case of a
+        * buffer underrun. If the caller cares about that (usually not very
+        * useful), then the xlat function is available separately as well.
+        */

Hmm, yes not very useful in general but if ndctl_cmd_xlat_firmware_status() returns 0, why not preserve the positive value if available? Just to keep the 2 interfaces more closely aligned.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

author maintainer
#3 lore raw

Re: [ndctl PATCH 1/3] libndctl, intel: Add infrastructure for firmware_status translation

Quoted 23 lines · Dan Williams
Quoted 10 lines · Vishal Verma

Add a new routine to ndctl_dimm_ops that allows a DSM family to provide a translation routine that will translate the status codes of the result of a DSM to generic errno style error codes. To use this routine effectively, add a new wrapper around ndctl_cmd_submit (called ndctl_cmd_submit_xlat) that submits the command, and also runs it through the above translator dimm_op (if one is is defined).

[..]

Quoted 10 lines
ndctl/lib/libndctl.c +10 -0
+NDCTL_EXPORT int ndctl_cmd_submit_xlat(struct ndctl_cmd *cmd)
+{
+       int rc;
+
+       rc = ndctl_cmd_submit(cmd);
+       if (rc < 0)
+               return rc;
+
+       /*
+        * NOTE: This loses a positive rc which happens in the case of a
Quoted 8 lines

ndctl/lib/libndctl.c NDCTL_EXPORT int ndctl_cmd_submit(struct ndctl_cmd *cmd) · line 2844

Quoted 3 lines
ndctl/lib/libndctl.c +3 -0
+        * buffer underrun. If the caller cares about that (usually not very
+        * useful), then the xlat function is available separately as well.
+        */

Hmm, yes not very useful in general but if ndctl_cmd_xlat_firmware_status() returns 0, why not preserve the positive value if available? Just to keep the 2 interfaces more closely aligned.

Good idea. We'd still lose the positive rc if there was an underrun && firmware_status was non-zero, but that is fine (I'll still keep this note for that case).

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

author maintainer
#4 lore raw

PATCH 2/3 ndctl, inject-smart: switch to ndctl_cmd_submit_xlat

In reply to Vishal Verma

The ndctl inject-smart command was neglecting to check the 'firmware_status' field that is set by the platform firmware to indicate failure. Use the new ndctl_cmd_submit_xlat facility to include the firmware_status check as part of the command submission.

---
 ndctl/inject-smart.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
ndctl/inject-smart.c +4 -4
index eaa137a..12f3474 100644
@@ -280,7 +280,7 @@ static int smart_set_thresh(struct ndctl_dimm *dimm)
 		goto out;
 	}
 
-	rc = ndctl_cmd_submit(st_cmd);
+	rc = ndctl_cmd_submit_xlat(st_cmd);
 	if (rc) {
 		error("%s: smart threshold command failed: %s (%d)\n",
 			name, strerror(abs(rc)), rc);
@@ -320,7 +320,7 @@ static int smart_set_thresh(struct ndctl_dimm *dimm)
 		ndctl_cmd_smart_threshold_set_alarm_control(sst_cmd, alarm);
 	}
 
-	rc = ndctl_cmd_submit(sst_cmd);
+	rc = ndctl_cmd_submit_xlat(sst_cmd);
 	if (rc)
 		error("%s: smart set threshold command failed: %s (%d)\n",
 			name, strerror(abs(rc)), rc);
@@ -351,7 +351,7 @@ out:
 			if (sctx.err_continue == false) \
 				goto out; \
 		} \
-		rc = ndctl_cmd_submit(si_cmd); \
+		rc = ndctl_cmd_submit_xlat(si_cmd); \
 		if (rc) { \
 			error("%s: smart inject %s command failed: %s (%d)\n", \
 				name, #arg, strerror(abs(rc)), rc); \
@@ -382,7 +382,7 @@ out:
 			if (sctx.err_continue == false) \
 				goto out; \
 		} \
-		rc = ndctl_cmd_submit(si_cmd); \
+		rc = ndctl_cmd_submit_xlat(si_cmd); \
 		if (rc) { \
 			error("%s: smart inject %s command failed: %s (%d)\n", \
 				name, #arg, strerror(abs(rc)), rc); \
Signature · 6 lines
2.17.2

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
#5 lore raw

Re: [ndctl PATCH 2/3] ndctl, inject-smart: switch to ndctl_cmd_submit_xlat

Quoted 45 lines · Vishal Verma

The ndctl inject-smart command was neglecting to check the 'firmware_status' field that is set by the platform firmware to indicate failure. Use the new ndctl_cmd_submit_xlat facility to include the firmware_status check as part of the command submission.

---
 ndctl/inject-smart.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
ndctl/inject-smart.c +3 -3
index eaa137a..12f3474 100644
@@ -280,7 +280,7 @@ static int smart_set_thresh(struct ndctl_dimm *dimm)
                goto out;
        }
 
-       rc = ndctl_cmd_submit(st_cmd);
+       rc = ndctl_cmd_submit_xlat(st_cmd);
        if (rc) {
                error("%s: smart threshold command failed: %s (%d)\n",
                        name, strerror(abs(rc)), rc);
@@ -320,7 +320,7 @@ static int smart_set_thresh(struct ndctl_dimm *dimm)
                ndctl_cmd_smart_threshold_set_alarm_control(sst_cmd, alarm);
        }
 
-       rc = ndctl_cmd_submit(sst_cmd);
+       rc = ndctl_cmd_submit_xlat(sst_cmd);
        if (rc)
                error("%s: smart set threshold command failed: %s (%d)\n",
                        name, strerror(abs(rc)), rc);
@@ -351,7 +351,7 @@ out:
                        if (sctx.err_continue == false) \
                                goto out; \
                } \
-               rc = ndctl_cmd_submit(si_cmd); \
+               rc = ndctl_cmd_submit_xlat(si_cmd); \
                if (rc) { \
                        error("%s: smart inject %s command failed: %s (%d)\n", \
                                name, #arg, strerror(abs(rc)), rc); \

ndctl/inject-smart.c out: · line 388

Quoted 8 lines
ndctl/inject-smart.c +1 -1
@@ -382,7 +382,7 @@ out:
                        if (sctx.err_continue == false) \
                                goto out; \
                } \
-               rc = ndctl_cmd_submit(si_cmd); \
+               rc = ndctl_cmd_submit_xlat(si_cmd); \
                if (rc) { \
                        error("%s: smart inject %s command failed: %s (%d)\n", \
                                name, #arg, strerror(abs(rc)), rc); \

These need to become if (rc < 0) just to be compatible with the calling convention. Maybe that's a lead in cleanup patch.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

author maintainer
#6 lore raw

Re: [ndctl PATCH 2/3] ndctl, inject-smart: switch to ndctl_cmd_submit_xlat

Quoted 49 lines · Dan Williams
Quoted 48 lines · Vishal Verma

The ndctl inject-smart command was neglecting to check the 'firmware_status' field that is set by the platform firmware to indicate failure. Use the new ndctl_cmd_submit_xlat facility to include the firmware_status check as part of the command submission.

---
 ndctl/inject-smart.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
ndctl/inject-smart.c +3 -3
index eaa137a..12f3474 100644
@@ -280,7 +280,7 @@ static int smart_set_thresh(struct ndctl_dimm *dimm)
                goto out;
        }
 
-       rc = ndctl_cmd_submit(st_cmd);
+       rc = ndctl_cmd_submit_xlat(st_cmd);
        if (rc) {
                error("%s: smart threshold command failed: %s (%d)\n",
                        name, strerror(abs(rc)), rc);
@@ -320,7 +320,7 @@ static int smart_set_thresh(struct ndctl_dimm *dimm)
                ndctl_cmd_smart_threshold_set_alarm_control(sst_cmd, alarm);
        }
 
-       rc = ndctl_cmd_submit(sst_cmd);
+       rc = ndctl_cmd_submit_xlat(sst_cmd);
        if (rc)
                error("%s: smart set threshold command failed: %s (%d)\n",
                        name, strerror(abs(rc)), rc);
@@ -351,7 +351,7 @@ out:
                        if (sctx.err_continue == false) \
                                goto out; \
                } \
-               rc = ndctl_cmd_submit(si_cmd); \
+               rc = ndctl_cmd_submit_xlat(si_cmd); \
                if (rc) { \
                        error("%s: smart inject %s command failed: %s (%d)\n", \
                                name, #arg, strerror(abs(rc)), rc); \
@@ -382,7 +382,7 @@ out:
                        if (sctx.err_continue == false) \
                                goto out; \
                } \
Quoted 8 lines

ndctl/inject-smart.c out: · line 357

Quoted 5 lines
ndctl/inject-smart.c +1 -1
-               rc = ndctl_cmd_submit(si_cmd); \
+               rc = ndctl_cmd_submit_xlat(si_cmd); \
                if (rc) { \
                        error("%s: smart inject %s command failed: %s (%d)\n", \
                                name, #arg, strerror(abs(rc)), rc); \

These need to become if (rc < 0) just to be compatible with the calling convention. Maybe that's a lead in cleanup patch.

Hm, I think there may be several other lurkers that fail on positive. I'll fix these two patches up and add a follow on patch for any others in v2.

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

author maintainer
#7 lore raw

PATCH 3/3 ndctl, monitor: switch to ndctl_cmd_submit_xlat

In reply to Vishal Verma

The ndctl monitor command was neglecting to check the 'firmware_status' field that is set by the platform firmware to indicate failure. Use the new ndctl_cmd_submit_xlat facility to include the firmware_status check as part of the command submission.

---
 ndctl/monitor.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
ndctl/monitor.c +2 -2
index 233f2bb..01af338 100644
@@ -226,7 +226,7 @@ static int enable_dimm_supported_threshold_alarms(struct ndctl_dimm *dimm)
 		err(&monitor, "%s: no smart threshold command support\n", name);
 		goto out;
 	}
-	if (ndctl_cmd_submit(st_cmd)) {
+	if (ndctl_cmd_submit_xlat(st_cmd)) {
 		err(&monitor, "%s: smart threshold command failed\n", name);
 		goto out;
 	}
@@ -246,7 +246,7 @@ static int enable_dimm_supported_threshold_alarms(struct ndctl_dimm *dimm)
 		alarm |= ND_SMART_CTEMP_TRIP;
 	ndctl_cmd_smart_threshold_set_alarm_control(sst_cmd, alarm);
 
-	rc = ndctl_cmd_submit(sst_cmd);
+	rc = ndctl_cmd_submit_xlat(sst_cmd);
 	if (rc) {
 		err(&monitor, "%s: smart set threshold command failed\n", name);
 		goto out;
Signature · 6 lines
2.17.2

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
#8 lore raw

Re: [ndctl PATCH 3/3] ndctl, monitor: switch to ndctl_cmd_submit_xlat

Quoted 18 lines · Vishal Verma

The ndctl monitor command was neglecting to check the 'firmware_status' field that is set by the platform firmware to indicate failure. Use the new ndctl_cmd_submit_xlat facility to include the firmware_status check as part of the command submission.

---
 ndctl/monitor.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
ndctl/monitor.c +0 -0
index 233f2bb..01af338 100644

ndctl/monitor.c static int enable_dimm_supported_threshold_alarms(struct ndctl_dimm *dimm) · line 229

Quoted 5 lines
ndctl/monitor.c +1 -1
@@ -226,7 +226,7 @@ static int enable_dimm_supported_threshold_alarms(struct ndctl_dimm *dimm)
                err(&monitor, "%s: no smart threshold command support\n", name);
                goto out;
        }
-       if (ndctl_cmd_submit(st_cmd)) {
+       if (ndctl_cmd_submit_xlat(st_cmd)) {

Same comment about fixing this up to explicitly check for '< 0'.

ndctl/monitor.c static int enable_dimm_supported_threshold_alarms(struct ndctl_dimm *dimm) · line 250

Quoted 10 lines
ndctl/monitor.c +1 -1
                err(&monitor, "%s: smart threshold command failed\n", name);
                goto out;
        }
@@ -246,7 +246,7 @@ static int enable_dimm_supported_threshold_alarms(struct ndctl_dimm *dimm)
                alarm |= ND_SMART_CTEMP_TRIP;
        ndctl_cmd_smart_threshold_set_alarm_control(sst_cmd, alarm);
 
-       rc = ndctl_cmd_submit(sst_cmd);
+       rc = ndctl_cmd_submit_xlat(sst_cmd);
        if (rc) {

Ditto.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm