Skip to content

Commit

Permalink
ioctl: MSB variable-size storage/reference tags
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Brandon Paupore <[email protected]>
  • Loading branch information
bpaupore-wdc authored and igaw committed Oct 12, 2023
1 parent 0d3b74f commit b121a6f
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/nvme/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit b121a6f

Please sign in to comment.