Skip to content

Commit a2cd280

Browse files
francispravin5igaw
authored andcommitted
nvme-print-stdout: Add helper function to print PIF in string form
Use PIF enum and add a helper function to print the Protection Information Format(PIF) in string form. Signed-off-by: Francis Pravin <francis.p@samsung.com>
1 parent edeb9d7 commit a2cd280

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

nvme-print-stdout.c

+15-4
Original file line numberDiff line numberDiff line change
@@ -3056,6 +3056,20 @@ static void stdout_nvm_id_ns_pic(__u8 pic)
30563056
printf("\n");
30573057
}
30583058

3059+
static char *pif_to_string(__u8 pif)
3060+
{
3061+
switch (pif) {
3062+
case NVME_NVM_PIF_16B_GUARD:
3063+
return "16b Guard";
3064+
case NVME_NVM_PIF_32B_GUARD:
3065+
return "32b Guard";
3066+
case NVME_NVM_PIF_64B_GUARD:
3067+
return "64b Guard";
3068+
default:
3069+
return "Reserved";
3070+
}
3071+
}
3072+
30593073
static void stdout_nvm_id_ns(struct nvme_nvm_id_ns *nvm_ns, unsigned int nsid,
30603074
struct nvme_id_ns *ns, unsigned int lba_index,
30613075
bool cap_only)
@@ -3086,10 +3100,7 @@ static void stdout_nvm_id_ns(struct nvme_nvm_id_ns *nvm_ns, unsigned int nsid,
30863100
if (verbose)
30873101
printf("Extended LBA Format %2d : Protection Information Format: "
30883102
"%s(%d) - Storage Tag Size (MSB): %-2d %s\n",
3089-
i, pif == 3 ? "Reserved" :
3090-
pif == 2 ? "64b Guard" :
3091-
pif == 1 ? "32b Guard" : "16b Guard",
3092-
pif, sts, i == lbaf ? in_use : "");
3103+
i, pif_to_string(pif), pif, sts, i == lbaf ? in_use : "");
30933104
else
30943105
printf("elbaf %2d : pif:%d sts:%-2d %s\n", i,
30953106
pif, sts, i == lbaf ? in_use : "");

nvme.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -6830,15 +6830,15 @@ static int invalid_tags(__u64 storage_tag, __u64 ref_tag, __u8 sts, __u8 pif)
68306830
}
68316831

68326832
switch (pif) {
6833-
case 0:
6833+
case NVME_NVM_PIF_16B_GUARD:
68346834
if (ref_tag >= (1LL << (32 - sts)))
68356835
result = 1;
68366836
break;
6837-
case 1:
6837+
case NVME_NVM_PIF_32B_GUARD:
68386838
if (sts > 16 && ref_tag >= (1LL << (80 - sts)))
68396839
result = 1;
68406840
break;
6841-
case 2:
6841+
case NVME_NVM_PIF_64B_GUARD:
68426842
if (sts > 0 && ref_tag >= (1LL << (48 - sts)))
68436843
result = 1;
68446844
break;

0 commit comments

Comments
 (0)