]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
Integration fixes
authorKeith Busch <kbusch@kernel.org>
Sat, 15 Feb 2020 18:25:47 +0000 (10:25 -0800)
committerKeith Busch <kbusch@kernel.org>
Sat, 15 Feb 2020 18:25:47 +0000 (10:25 -0800)
Fix up inconsistencies and missing features discovered while integrating
with nvme-cli.

Signed-off-by: Keith Busch <kbusch@kernel.org>
src/nvme/ioctl.c
src/nvme/ioctl.h
src/nvme/types.h
src/nvme/util.c

index 3b9f035d778dc3619b80906ba4a097ed113b5f92..28aee2d3cf8369d29f4a2175db6e787bdbe4f1b1 100644 (file)
@@ -904,7 +904,7 @@ int nvme_set_features_resv_mask(int fd, __u32 mask, bool save, __u32 *result)
 
 int nvme_set_features_resv_persist(int fd, bool ptpl, bool save, __u32 *result)
 {
-       return __nvme_set_features(fd, NVME_FEAT_RESV_PERSIST, !!ptpl, save,
+       return __nvme_set_features(fd, NVME_FEAT_FID_RESV_PERSIST, !!ptpl, save,
                                   result);
 }
 
@@ -1122,7 +1122,7 @@ int nvme_get_features_resv_mask(int fd, enum nvme_get_features_sel sel,
 int nvme_get_features_resv_persist(int fd, enum nvme_get_features_sel sel,
                                   __u32 *result)
 {
-       return __nvme_get_features(fd, NVME_FEAT_RESV_PERSIST, sel, result);
+       return __nvme_get_features(fd, NVME_FEAT_FID_RESV_PERSIST, sel, result);
 }
 
 int nvme_get_features_write_protect(int fd, __u32 nsid,
index c96c24d85d478880857ab29ca1c2d122dcfc4450..fe4d664a65a00370142d56e0c02a7a8d1d531797 100644 (file)
@@ -20,6 +20,9 @@
 #ifndef _UAPI_LINUX_NVME_IOCTL_H
 #define _UAPI_LINUX_NVME_IOCTL_H
 
+#ifndef _LINUX_NVME_IOCTL_H
+#define _LINUX_NVME_IOCTL_H
+
 /**
  * struct nvme_passthru_cmd -
  * @opcode:    Operation code, see &enum nvme_io_opcodes and &enum nvme_admin_opcodes
@@ -117,6 +120,8 @@ struct nvme_passthru_cmd64 {
 
 #endif /* _UAPI_LINUX_NVME_IOCTL_H */
 
+#endif /* _LINUX_NVME_IOCTL_H */
+
 /**
  * nvme_submit_admin_passthru64() - Submit a 64-bit nvme passthrough admin
  *                                 command
@@ -526,7 +531,7 @@ enum nvme_cmd_get_log_lid {
  * @NVME_FEAT_FID_SW_PROGRESS:
  * @NVME_FEAT_FID_HOST_ID:
  * @NVME_FEAT_FID_RESV_MASK:
- * @NVME_FEAT_RESV_PERSIST:
+ * @NVME_FEAT_FID_RESV_PERSIST:
  * @NVME_FEAT_FID_WRITE_PROTECT:
  */
 enum nvme_features_id {
@@ -557,7 +562,7 @@ enum nvme_features_id {
        NVME_FEAT_FID_SW_PROGRESS                               = 0x80,
        NVME_FEAT_FID_HOST_ID                                   = 0x81,
        NVME_FEAT_FID_RESV_MASK                                 = 0x82,
-       NVME_FEAT_RESV_PERSIST                                  = 0x83,
+       NVME_FEAT_FID_RESV_PERSIST                              = 0x83,
        NVME_FEAT_FID_WRITE_PROTECT                             = 0x84,
 };
 
@@ -2409,7 +2414,7 @@ int nvme_set_property(int fd, int offset, __u64 value);
 int nvme_get_property(int fd, int offset, __u64 *value);
 
 /**
- * nvme_sanitize() - Start a sanitize operation
+ * nvme_sanitize_nvme() - Start a sanitize operation
  * @fd:                File descriptor of nvme device
  * @sanact:    Sanitize action, see &enum nvme_sanitize_sanact
  * @ause:      Set to allow unrestriced sanitize exit
index 02b3a6dc5e3298212851e619f823142e16830f33..88ccb9c98a3c4c0a85ac8d61c6b2774a540a066a 100644 (file)
@@ -131,12 +131,14 @@ enum nvme_constants {
        NVME_NQN_LENGTH                 = 256,
        NVMF_TRADDR_SIZE                = 256,
        NVMF_TSAS_SIZE                  = 256,
+       NVME_NIDT_EUI64_LEN             = 8,
+       NVME_NIDT_NGUID_LEN             = 16,
 };
 
 /**
- * enum nvme_registers - The nvme controller registers for all transports. This
- *                      is the layout of BAR0/1 for PCIe, and properties for
- *                      fabrics.
+ * enum nvme_register_offsets - The nvme controller registers for all transports. This
+ *                             is the layout of BAR0/1 for PCIe, and
+ *                             properties for fabrics.
  * @NVME_REG_CAP:      Controller Capabilities
  * @NVME_REG_VS:       Version
  * @NVME_REG_INTMS:    Interrupt Mask Set
@@ -162,7 +164,7 @@ enum nvme_constants {
  * @NVME_REG_PMRMSC:   Persistent Memory Region Controller Memory Space Control
  * @NVME_REG_DBS:      SQ 0 Tail Doorbell
  */
-enum nvme_registers {
+enum nvme_register_offsets {
        NVME_REG_CAP    = 0x0000,
        NVME_REG_VS     = 0x0008,
        NVME_REG_INTMS  = 0x000c,
@@ -1852,24 +1854,16 @@ enum {
        NVME_SMART_EGCW_RO              = 1 << 3,
 };
 
-/**
- * struct nvme_frs -
- * @frs:
- */
-struct nvme_frs {
-       char frs[8];
-};
-
 /**
  * struct nvme_firmware_slot -
  * @afi:
  * @frs:
  */
 struct nvme_firmware_slot {
-       __u8            afi;
-       __u8            resv[7];
-       struct nvme_frs frs[7];
-       __u8            resv2[448];
+       __u8    afi;
+       __u8    resv[7];
+       char    frs[7][8];
+       __u8    resv2[448];
 };
 
 /**
@@ -1941,6 +1935,7 @@ struct nvme_st_result {
  * @NVME_ST_RESULT_ABORTED_UNKNOWN:
  * @NVME_ST_RESULT_ABORTED_SANITIZE:
  * @NVME_ST_RESULT_NOT_USED:
+ * @NVME_ST_RESULT_NOT_MASK:
  */
 enum {
        NVME_ST_RESULT_NO_ERR           = 0x0,
@@ -1954,20 +1949,22 @@ enum {
        NVME_ST_RESULT_ABORTED_UNKNOWN  = 0x8,
        NVME_ST_RESULT_ABORTED_SANITIZE = 0x9,
        NVME_ST_RESULT_NOT_USED         = 0xf,
+       NVME_ST_RESULT_NOT_MASK         = 0xf,
 };
 
 /**
  * enum -
- * @NVME_ST_OPERATION_NONE:
- * @NVME_ST_OPERATION_SHORT:
- * @NVME_ST_OPERATION_EXTENDED:
- * @NVME_ST_OPERATION_VS:
+ * @NVME_ST_CODE_NONE:
+ * @NVME_ST_CODE_SHORT:
+ * @NVME_ST_CODE_EXTENDED:
+ * @NVME_ST_CODE_VS:
  */
 enum {
-       NVME_ST_OPERATION_NONE          = 0x0,
-       NVME_ST_OPERATION_SHORT         = 0x1,
-       NVME_ST_OPERATION_EXTENDED      = 0x2,
-       NVME_ST_OPERATION_VS            = 0xe,
+       NVME_ST_CODE_SHIFT              = 4,
+       NVME_ST_CODE_RESRVED            = 0x0,
+       NVME_ST_CODE_SHORT              = 0x1,
+       NVME_ST_CODE_EXTENDED           = 0x2,
+       NVME_ST_CODE_VS                 = 0xe,
 };
 
 /**
@@ -2165,14 +2162,14 @@ struct nvme_ana_group_desc {
 };
 
 /**
- * enum -
+ * enum nvme_ana_state -
  * @NVME_ANA_STATE_OPTIMIZED:
  * @NVME_ANA_STATE_NONOPTIMIZED:
  * @NVME_ANA_STATE_INACCESSIBLE:
  * @NVME_ANA_STATE_PERSISTENT_LOSS:
  * @NVME_ANA_STATE_CHANGE:
  */
-enum {
+enum nvme_ana_state {
        NVME_ANA_STATE_OPTIMIZED        = 0x1,
        NVME_ANA_STATE_NONOPTIMIZED     = 0x2,
        NVME_ANA_STATE_INACCESSIBLE     = 0x3,
@@ -2347,19 +2344,24 @@ struct nvme_sanitize_log_page {
 };
 
 /**
- * enum -
- * @NVME_SANITIZE_SSTAT_NEVER_SANITIZED:
- * @NVME_SANITIZE_SSTAT_COMPLETE_SUCCESS:
- * @NVME_SANITIZE_SSTAT_IN_PROGESS:
- * @NVME_SANITIZE_SSTAT_COMPLETED_FAILED:
- * @NVME_SANITIZE_SSTAT_ND_COMPLETE_SUCCESS:
+ * enum nvme_sanitize_sstat -
+ * @NVME_SANITIZE_SSTAT_STATUS_MASK:
+ * @NVME_SANITIZE_SSTAT_STATUS_NEVER_SANITIZED:
+ * @NVME_SANITIZE_SSTAT_STATUS_COMPLETE_SUCCESS:
+ * @NVME_SANITIZE_SSTAT_STATUS_IN_PROGESS:
+ * @NVME_SANITIZE_SSTAT_STATUS_COMPLETED_FAILED:
+ * @NVME_SANITIZE_SSTAT_STATUS_ND_COMPLETE_SUCCESS:
  */
-enum {
-       NVME_SANITIZE_SSTAT_NEVER_SANITIZED     = 0,
-       NVME_SANITIZE_SSTAT_COMPLETE_SUCCESS    = 1,
-       NVME_SANITIZE_SSTAT_IN_PROGESS          = 2,
-       NVME_SANITIZE_SSTAT_COMPLETED_FAILED    = 3,
-       NVME_SANITIZE_SSTAT_ND_COMPLETE_SUCCESS = 4,
+enum nvme_sanitize_sstat {
+       NVME_SANITIZE_SSTAT_STATUS_MASK                 = 0x7,
+       NVME_SANITIZE_SSTAT_STATUS_NEVER_SANITIZED      = 0,
+       NVME_SANITIZE_SSTAT_STATUS_COMPLETE_SUCCESS     = 1,
+       NVME_SANITIZE_SSTAT_STATUS_IN_PROGESS           = 2,
+       NVME_SANITIZE_SSTAT_STATUS_COMPLETED_FAILED     = 3,
+       NVME_SANITIZE_SSTAT_STATUS_ND_COMPLETE_SUCCESS  = 4,
+       NVME_SANITIZE_SSTAT_COMPLETED_PASSES_MASK       = 0xf8,
+       NVME_SANITIZE_SSTAT_COMPLETED_PASSES_SHIFT      = 3,
+       NVME_SANITIZE_SSTAT_GLOBAL_DATA_ERASED          = 1 << 8,
 };
 
 /**
@@ -3343,8 +3345,8 @@ struct nvme_mi_vpd_hdr {
 };
 
 /**
- * enum nvme_status_code - Defines all parts of the nvme status field: status
- *                        code, status code type, and additional flags.
+ * enum nvme_status_field - Defines all parts of the nvme status field: status
+ *                         code, status code type, and additional flags.
  * @NVME_SCT_MASK:                   Mask to get the value of the Status Code Type
  * @NVME_SCT_GENERIC:                Generic errors applicable to multiple opcodes
  * @NVME_SCT_CMD_SPECIFIC:           Errors associated to a specific opcode
@@ -3355,13 +3357,16 @@ struct nvme_mi_vpd_hdr {
  * @NVME_SC_SUCCESS:                 Successful Completion: The command
  *                                   completed without error.
  * @NVME_SC_INVALID_OPCODE:          Invalid Command Opcode: A reserved coded
- *                                   value or an unsupported value in the command opcode field.
+ *                                   value or an unsupported value in the
+ *                                   command opcode field.
  * @NVME_SC_INVALID_FIELD:           Invalid Field in Command: A reserved
- *                                   coded value or an unsupported value in a defined field.
+ *                                   coded value or an unsupported value in a
+ *                                   defined field.
  * @NVME_SC_CMDID_CONFLICT:          Command ID Conflict: The command
  *                                   identifier is already in use.
  * @NVME_SC_DATA_XFER_ERROR:         Data Transfer Error: Transferring the
- *                                   data or metadata associated with a command experienced an error.
+ *                                   data or metadata associated with a
+ *                                   command experienced an error.
  * @NVME_SC_POWER_LOSS:                      Commands Aborted due to Power Loss
  *                                   Notification: Indicates that the command
  *                                   was aborted due to a power loss
@@ -3387,11 +3392,14 @@ struct nvme_mi_vpd_hdr {
  *                                   containing a fused command that is the
  *                                   other command.
  * @NVME_SC_INVALID_NS:                      Invalid Namespace or Format: The
- *                                   namespace or the format of that namespace is invalid.
+ *                                   namespace or the format of that namespace
+ *                                   is invalid.
  * @NVME_SC_CMD_SEQ_ERROR:           Command Sequence Error: The command was
- *                                   aborted due to a protocol violation in a multi-command sequence.
+ *                                   aborted due to a protocol violation in a
+ *                                   multi-command sequence.
  * @NVME_SC_SGL_INVALID_LAST:        Invalid SGL Segment Descriptor: The
- *                                   command includes an invalid SGL Last Segment or SGL Segment descriptor.
+ *                                   command includes an invalid SGL Last
+ *                                   Segment or SGL Segment descriptor.
  * @NVME_SC_SGL_INVALID_COUNT:       Invalid Number of SGL Descriptors: There
  *                                   is an SGL Last Segment descriptor or an
  *                                   SGL Segment descriptor in a location
@@ -3415,7 +3423,8 @@ struct nvme_mi_vpd_hdr {
  *                                   Support field of the Identify Controller
  *                                   data structure.
  * @NVME_SC_SGL_INVALID_TYPE:        SGL Descriptor Type Invalid: The type of
- *                                   an SGL Descriptor is a type that is not supported by the controller.
+ *                                   an SGL Descriptor is a type that is not
+ *                                   supported by the controller.
  * @NVME_SC_CMB_INVALID_USE:         Invalid Use of Controller Memory Buffer:
  *                                   The attempted use of the Controller
  *                                   Memory Buffer is not supported by the
@@ -3443,9 +3452,11 @@ struct nvme_mi_vpd_hdr {
  * @NVME_SC_KAT_INVALID:             Keep Alive Timeout Invalid: The Keep
  *                                   Alive Timeout value specified is invalid.
  * @NVME_SC_CMD_ABORTED_PREMEPT:      Command Aborted due to Preempt and Abort:
- *                                   The command was aborted due to a Reservation Acquire command.
+ *                                   The command was aborted due to a
+ *                                   Reservation Acquire command.
  * @NVME_SC_SANITIZE_FAILED:         Sanitize Failed: The most recent sanitize
- *                                   operation failed and no recovery action has been successfully completed.
+ *                                   operation failed and no recovery action
+ *                                   has been successfully completed.
  * @NVME_SC_SANITIZE_IN_PROGRESS:     Sanitize In Progress: The requested
  *                                   function (e.g., command) is prohibited
  *                                   while a sanitize operation is in
@@ -3698,6 +3709,7 @@ enum nvme_status_field {
         * Status Code Type indicators
         */
        NVME_SCT_MASK                   = 0x700,
+       NVME_SCT_SHIFT                  = 0x700,
        NVME_SCT_GENERIC                = 0x000,
        NVME_SCT_CMD_SPECIFIC           = 0x100,
        NVME_SCT_MEDIA                  = 0x200,
index 86a2ad0ef1ea4b27cdcc9e0cf80f86afc6c29891..8461e6a3ae530d55529034468b9b200705ec2b74 100644 (file)
@@ -461,7 +461,7 @@ int nvme_get_feature_length(int fid, __u32 cdw11, __u32 *len)
        case NVME_FEAT_FID_ENDURANCE_EVT_CFG:
        case NVME_FEAT_FID_SW_PROGRESS:
        case NVME_FEAT_FID_RESV_MASK:
-       case NVME_FEAT_RESV_PERSIST:
+       case NVME_FEAT_FID_RESV_PERSIST:
        case NVME_FEAT_FID_WRITE_PROTECT:
                *len = 0;
                break;