From 7f64b7d91fb5f0e94729213c7add5761990ab65c Mon Sep 17 00:00:00 2001 From: Francis Pravin Date: Wed, 26 Jun 2024 12:05:39 +0530 Subject: [PATCH] nvme: choose PIF from QPIF if QPIFS supports and PIF is QTYPE As per TP4141a: "If the Qualified Protection Information Format Support(QPIFS) bit is set to 1 and the Protection Information Format(PIF) field is set to 11b (i.e., Qualified Type), then the pif is as defined in the Qualified Protection Information Format (QPIF) field." So, choose PIF from QPIF if QPIFS supports and PIF is QTYPE. Signed-off-by: Francis Pravin Reviewed-by: Steven Seungcheol Lee --- nvme.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/nvme.c b/nvme.c index bde49258..11de8361 100644 --- a/nvme.c +++ b/nvme.c @@ -6860,6 +6860,7 @@ static int write_zeroes(int argc, char **argv, struct command *cmd, struct plugi _cleanup_free_ struct nvme_id_ns *ns = NULL; _cleanup_nvme_dev_ struct nvme_dev *dev = NULL; __u8 lba_index, sts = 0, pif = 0; + __u32 elbaf = 0; __u16 control = 0; int err; @@ -6971,8 +6972,11 @@ static int write_zeroes(int argc, char **argv, struct command *cmd, struct plugi err = nvme_identify_ns_csi(dev_fd(dev), cfg.namespace_id, 0, NVME_CSI_NVM, nvm_ns); if (!err) { nvme_id_ns_flbas_to_lbaf_inuse(ns->flbas, &lba_index); - sts = nvm_ns->elbaf[lba_index] & NVME_NVM_ELBAF_STS_MASK; - pif = (nvm_ns->elbaf[lba_index] & NVME_NVM_ELBAF_PIF_MASK) >> 7; + elbaf = le32_to_cpu(nvm_ns->elbaf[lba_index]); + sts = elbaf & NVME_NVM_ELBAF_STS_MASK; + pif = (elbaf & NVME_NVM_ELBAF_PIF_MASK) >> 7; + if (pif == NVME_NVM_PIF_QTYPE && (nvm_ns->pic & 0x8)) + pif = (elbaf & NVME_NVM_ELBAF_QPIF_MASK) >> 9; } if (invalid_tags(cfg.storage_tag, cfg.ref_tag, sts, pif)) @@ -7698,7 +7702,7 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char int flags; int mode = 0644; __u16 control = 0, nblocks = 0; - __u32 dsmgmt = 0; + __u32 dsmgmt = 0, elbaf = 0; unsigned int logical_block_size = 0; unsigned long long buffer_size = 0, mbuffer_size = 0; _cleanup_huge_ struct nvme_mem_huge mh = { 0, }; @@ -7929,8 +7933,11 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char if (cfg.metadata_size) { err = nvme_identify_ns_csi(dev_fd(dev), 1, 0, NVME_CSI_NVM, nvm_ns); if (!err) { - sts = nvm_ns->elbaf[lba_index] & NVME_NVM_ELBAF_STS_MASK; - pif = (nvm_ns->elbaf[lba_index] & NVME_NVM_ELBAF_PIF_MASK) >> 7; + elbaf = le32_to_cpu(nvm_ns->elbaf[lba_index]); + sts = elbaf & NVME_NVM_ELBAF_STS_MASK; + pif = (elbaf & NVME_NVM_ELBAF_PIF_MASK) >> 7; + if (pif == NVME_NVM_PIF_QTYPE && (nvm_ns->pic & 0x8)) + pif = (elbaf & NVME_NVM_ELBAF_QPIF_MASK) >> 9; } mbuffer_size = ((unsigned long long)cfg.block_count + 1) * ms; @@ -8065,11 +8072,12 @@ static int write_cmd(int argc, char **argv, struct command *cmd, struct plugin * static int verify_cmd(int argc, char **argv, struct command *cmd, struct plugin *plugin) { - __u16 control = 0; - __u8 lba_index, sts = 0, pif = 0; _cleanup_free_ struct nvme_nvm_id_ns *nvm_ns = NULL; _cleanup_free_ struct nvme_id_ns *ns = NULL; _cleanup_nvme_dev_ struct nvme_dev *dev = NULL; + __u8 lba_index, sts = 0, pif = 0; + __u16 control = 0; + __u32 elbaf = 0; int err; const char *desc = "Verify specified logical blocks on the given device."; @@ -8163,8 +8171,11 @@ static int verify_cmd(int argc, char **argv, struct command *cmd, struct plugin NVME_CSI_NVM, nvm_ns); if (!err) { nvme_id_ns_flbas_to_lbaf_inuse(ns->flbas, &lba_index); - sts = nvm_ns->elbaf[lba_index] & NVME_NVM_ELBAF_STS_MASK; - pif = (nvm_ns->elbaf[lba_index] & NVME_NVM_ELBAF_PIF_MASK) >> 7; + elbaf = le32_to_cpu(nvm_ns->elbaf[lba_index]); + sts = elbaf & NVME_NVM_ELBAF_STS_MASK; + pif = (elbaf & NVME_NVM_ELBAF_PIF_MASK) >> 7; + if (pif == NVME_NVM_PIF_QTYPE && (nvm_ns->pic & 0x8)) + pif = (elbaf & NVME_NVM_ELBAF_QPIF_MASK) >> 9; } if (invalid_tags(cfg.storage_tag, cfg.ref_tag, sts, pif)) -- 2.50.1