]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
ioctl: MSB variable-size storage/reference tags
authorBrandon Paupore <brandon.paupore@wdc.com>
Mon, 9 Oct 2023 21:19:17 +0000 (16:19 -0500)
committerDaniel Wagner <wagi@monom.org>
Thu, 12 Oct 2023 08:15:54 +0000 (10:15 +0200)
The spec defines these values on a bitwise basis within the shared
80-bit region, stored from MSB to LSB for each tag. Mechanically this
can be achieved by setting the values as big-endian using the same logic
currently in place.

Reviewed-by: Jeffrey Lien <jeff.lien@wdc.com>
Signed-off-by: Brandon Paupore <brandon.paupore@wdc.com>
src/nvme/ioctl.c

index 14d186a7012c13526ce44d256b4ea7e9ee9e4d94..b5c27e32fb27a08a6faea204ea90e6ef3705f3a4 100644 (file)
@@ -1836,33 +1836,35 @@ static int nvme_set_var_size_tags(__u32 *cmd_dw2, __u32 *cmd_dw3, __u32 *cmd_dw1
                __u8 pif, __u8 sts, __u64 reftag, __u64 storage_tag)
 {
        __u32 cdw2 = 0, cdw3 = 0, cdw14;
+       beint64_t be_reftag = cpu_to_be64(reftag);
+       beint64_t be_storage_tag = cpu_to_be64(storage_tag);
 
        switch (pif) {
        /* 16b Protection Information */
        case 0:
-               cdw14 = reftag & 0xffffffff;
-               cdw14 |= ((storage_tag << (32 - sts)) & 0xffffffff);
+               cdw14 = be_reftag & 0xffffffff;
+               cdw14 |= ((be_storage_tag << (32 - sts)) & 0xffffffff);
                break;
        /* 32b Protection Information */
        case 1:
-               cdw14 = reftag & 0xffffffff;
-               cdw3 = reftag >> 32;
-               cdw14 |= ((storage_tag << (80 - sts)) & 0xffff0000);
+               cdw14 = be_reftag & 0xffffffff;
+               cdw3 = be_reftag >> 32;
+               cdw14 |= ((be_storage_tag << (80 - sts)) & 0xffff0000);
                if (sts >= 48)
-                       cdw3 |= ((storage_tag >> (sts - 48)) & 0xffffffff);
+                       cdw3 |= ((be_storage_tag >> (sts - 48)) & 0xffffffff);
                else
-                       cdw3 |= ((storage_tag << (48 - sts)) & 0xffffffff);
-               cdw2 = (storage_tag >> (sts - 16)) & 0xffff;
+                       cdw3 |= ((be_storage_tag << (48 - sts)) & 0xffffffff);
+               cdw2 = (be_storage_tag >> (sts - 16)) & 0xffff;
                break;
        /* 64b Protection Information */
        case 2:
-               cdw14 = reftag & 0xffffffff;
-               cdw3 = (reftag >> 32) & 0xffff;
-               cdw14 |= ((storage_tag << (48 - sts)) & 0xffffffff);
+               cdw14 = be_reftag & 0xffffffff;
+               cdw3 = (be_reftag >> 32) & 0xffff;
+               cdw14 |= ((be_storage_tag << (48 - sts)) & 0xffffffff);
                if (sts >= 16)
-                       cdw3 |= ((storage_tag >> (sts - 16)) & 0xffff);
+                       cdw3 |= ((be_storage_tag >> (sts - 16)) & 0xffff);
                else
-                       cdw3 |= ((storage_tag << (16 - sts)) & 0xffff);
+                       cdw3 |= ((be_storage_tag << (16 - sts)) & 0xffff);
                break;
        default:
                perror("Unsupported Protection Information Format");