]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
ioctl: add CDW2 and CDW3 support for Write Zeroes and Verify Command
authorGollu Appalanaidu <anaidu.gollu@samsung.com>
Wed, 3 Nov 2021 13:13:46 +0000 (14:13 +0100)
committerDaniel Wagner <dwagner@suse.de>
Tue, 16 Nov 2021 15:29:00 +0000 (16:29 +0100)
Added support for the Variable Sized Expected Logical Block Storage Tag(ELBST)
and Expected Logical Block Reference Tag (ELBRT), CDW2 and CDW3 (00:47) bits
for NVM commands Write Zeroes and Verify commands.

Signed-off-by: Gollu Appalanaidu <anaidu.gollu@samsung.com>
[dwagner: ported from nvme-cli-monolithic]
Signed-off-by: Daniel Wagner <dwagner@suse.de>
src/nvme/ioctl.c
src/nvme/ioctl.h
src/nvme/tree.c

index 1cd8d22a5de7fa520d82133d569900a51625a0c6..5b0705cfa49278d2afc4d1426cb427d38e836ed3 100644 (file)
@@ -1666,8 +1666,11 @@ int nvme_flush(int fd, __u32 nsid)
 
 static int nvme_io(int fd, __u8 opcode, __u32 nsid, __u64 slba, __u16 nlb,
        __u16 control, __u32 flags, __u32 reftag, __u16 apptag, __u16 appmask,
-       __u32 data_len, void *data, __u32 metadata_len, void *metadata)
+       __u64 storage_tag, __u32 data_len, void *data, __u32 metadata_len,
+       void *metadata)
 {
+       __u32 cdw2  = storage_tag & 0xffffffff;
+       __u32 cdw3  = (storage_tag >> 32) & 0xffff;
        __u32 cdw10 = slba & 0xffffffff;
        __u32 cdw11 = slba >> 32;
        __u32 cdw12 = nlb | (control << 16);
@@ -1678,6 +1681,8 @@ static int nvme_io(int fd, __u8 opcode, __u32 nsid, __u64 slba, __u16 nlb,
        struct nvme_passthru_cmd cmd = {
                .opcode         = opcode,
                .nsid           = nsid,
+               .cdw2           = cdw2,
+               .cdw3           = cdw3,
                .cdw10          = cdw10,
                .cdw11          = cdw11,
                .cdw12          = cdw12,
@@ -1698,7 +1703,7 @@ int nvme_read(int fd, __u32 nsid, __u64 slba, __u16 nlb, __u16 control,
              __u32 data_len, void *data, __u32 metadata_len, void *metadata)
 {
        return nvme_io(fd, nvme_cmd_read, nsid, slba, nlb, control, dsm,
-                      reftag, apptag, appmask, data_len, data, metadata_len,
+                      reftag, apptag, appmask, 0, data_len, data, metadata_len,
                       metadata);
 }
 
@@ -1710,7 +1715,7 @@ int nvme_write(int fd, __u32 nsid, __u64 slba, __u16 nlb, __u16 control,
        __u32 flags = dsm | dspec << 16;
 
        return nvme_io(fd, nvme_cmd_write, nsid, slba, nlb, control, flags,
-                      reftag, apptag, appmask, data_len, data, metadata_len,
+                      reftag, apptag, appmask, 0, data_len, data, metadata_len,
                       metadata);
 }
 
@@ -1719,28 +1724,29 @@ int nvme_compare(int fd, __u32 nsid, __u64 slba, __u16 nlb, __u16 control,
                 void *data, __u32 metadata_len, void *metadata)
 {
        return nvme_io(fd, nvme_cmd_compare, nsid, slba, nlb, control, 0,
-                      reftag, apptag, appmask, data_len, data, metadata_len,
+                      reftag, apptag, appmask, 0, data_len, data, metadata_len,
                       metadata);
 }
 
 int nvme_write_zeros(int fd, __u32 nsid, __u64 slba, __u16 nlb, __u16 control,
-                    __u32 reftag, __u16 apptag, __u16 appmask)
+                    __u32 reftag, __u16 apptag, __u16 appmask,
+                    __u64 storage_tag)
 {
        return nvme_io(fd, nvme_cmd_write_zeroes, nsid, slba, nlb, control, 0,
-                      reftag, apptag, appmask, 0, NULL, 0, NULL);
+                      reftag, apptag, appmask, storage_tag, 0, NULL, 0, NULL);
 }
 
 int nvme_verify(int fd, __u32 nsid, __u64 slba, __u16 nlb, __u16 control,
-               __u32 reftag, __u16 apptag, __u16 appmask)
+               __u32 reftag, __u16 apptag, __u16 appmask, __u64 storage_tag)
 {
        return nvme_io(fd, nvme_cmd_verify, nsid, slba, nlb, control, 0,
-                      reftag, apptag, appmask, 0, NULL, 0, NULL);
+                      reftag, apptag, appmask, 0, 0, NULL, 0, NULL);
 }
 
 int nvme_write_uncorrectable(int fd, __u32 nsid, __u64 slba, __u16 nlb)
 {
        return nvme_io(fd, nvme_cmd_write_uncor, nsid, slba, nlb, 0, 0, 0, 0,
-                      0, 0, NULL, 0, NULL);
+                      0, 0, 0, NULL, 0, NULL);
 }
 
 int nvme_dsm(int fd, __u32 nsid, __u32 attrs, __u16 nr_ranges,
index faeae5d8b595fdbed87078d297cda1b257c088f4..f4737212566403757ad3cc1726b2ac63d81338ab 100644 (file)
@@ -2338,6 +2338,9 @@ int nvme_compare(int fd, __u32 nsid, __u64 slba, __u16 nlb, __u16 control,
  * @appmask:   This field specifies the Application Tag expected value. Used
  *             only if the namespace is formatted to use end-to-end protection
  *             information.
+ * @storage_tag: This filed specifies Variable Sized Expected Logical Block
+ *             Storage Tag (ELBST) and Expected Logical Block Reference
+ *             Tag (ELBRT)
  *
  * The Write Zeroes command sets a range of logical blocks to zero.  After
  * successful completion of this command, the value returned by subsequent
@@ -2348,7 +2351,8 @@ int nvme_compare(int fd, __u32 nsid, __u64 slba, __u16 nlb, __u16 control,
  * &enum nvme_status_field) or -1 with errno set otherwise.
  */
 int nvme_write_zeros(int fd, __u32 nsid, __u64 slba, __u16 nlb, __u16 control,
-                    __u32 reftag, __u16 apptag, __u16 appmask);
+                    __u32 reftag, __u16 apptag, __u16 appmask,
+                    __u64 storage_tag);
 
 /**
  * nvme_write_uncorrectable() - Submit an nvme write uncorrectable command
@@ -2383,6 +2387,9 @@ int nvme_write_uncorrectable(int fd, __u32 nsid, __u64 slba, __u16 nlb);
  * @appmask:   This field specifies the Application Tag expected value. Used
  *             only if the namespace is formatted to use end-to-end protection
  *             information.
+ * @storage_tag: This filed specifies Variable Sized Expected Logical Block
+ *             Storage Tag (ELBST) and Expected Logical Block Reference
+ *             Tag (ELBRT)
  *
  * The Verify command verifies integrity of stored information by reading data
  * and metadata, if applicable, for the LBAs indicated without transferring any
@@ -2392,7 +2399,7 @@ int nvme_write_uncorrectable(int fd, __u32 nsid, __u64 slba, __u16 nlb);
  * &enum nvme_status_field) or -1 with errno set otherwise.
  */
 int nvme_verify(int fd, __u32 nsid, __u64 slba, __u16 nlb, __u16 control,
-               __u32 reftag, __u16 apptag, __u16 appmask);
+               __u32 reftag, __u16 apptag, __u16 appmask, __u64 storage_tag);
 
 /**
  * nvme_dsm() - Send an nvme data set management command
index 2950ddf51b050bbb69cf4a99cbc4e62af7dc0bb4..8613f23589ad3bec309cc3bba4109d9c8e3791e8 100644 (file)
@@ -1418,7 +1418,7 @@ int nvme_ns_verify(nvme_ns_t n, off_t offset, size_t count)
                return -1;
 
        return nvme_verify(nvme_ns_get_fd(n), nvme_ns_get_nsid(n), slba, nlb,
-                          0, 0, 0, 0);
+                          0, 0, 0, 0, 0);
 }
 
 int nvme_ns_write_uncorrectable(nvme_ns_t n, off_t offset, size_t count)
@@ -1442,7 +1442,7 @@ int nvme_ns_write_zeros(nvme_ns_t n, off_t offset, size_t count)
                return -1;
 
        return nvme_write_zeros(nvme_ns_get_fd(n), nvme_ns_get_nsid(n), slba,
-                               nlb, 0, 0, 0, 0);
+                               nlb, 0, 0, 0, 0, 0);
 }
 
 int nvme_ns_write(nvme_ns_t n, void *buf, off_t offset, size_t count)