Skip to content

Commit 415fb38

Browse files
francispravin5keithbusch
authored andcommitted
nvme-core: 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 <francis.p@samsung.com> Reviewed-by: Sagi Grimberg <sagi@grimberg.me> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Keith Busch <kbusch@kernel.org>
1 parent 92fc2c4 commit 415fb38

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

drivers/nvme/host/core.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1875,12 +1875,18 @@ static void nvme_configure_pi_elbas(struct nvme_ns_head *head,
18751875
struct nvme_id_ns *id, struct nvme_id_ns_nvm *nvm)
18761876
{
18771877
u32 elbaf = le32_to_cpu(nvm->elbaf[nvme_lbaf_index(id->flbas)]);
1878+
u8 guard_type;
18781879

18791880
/* no support for storage tag formats right now */
18801881
if (nvme_elbaf_sts(elbaf))
18811882
return;
18821883

1883-
head->guard_type = nvme_elbaf_guard_type(elbaf);
1884+
guard_type = nvme_elbaf_guard_type(elbaf);
1885+
if ((nvm->pic & NVME_ID_NS_NVM_QPIFS) &&
1886+
guard_type == NVME_NVM_NS_QTYPE_GUARD)
1887+
guard_type = nvme_elbaf_qualified_guard_type(elbaf);
1888+
1889+
head->guard_type = guard_type;
18841890
switch (head->guard_type) {
18851891
case NVME_NVM_NS_64B_GUARD:
18861892
head->pi_size = sizeof(struct crc64_pi_tuple);

include/linux/nvme.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,9 @@ enum {
483483
NVME_ID_NS_NVM_STS_MASK = 0x7f,
484484
NVME_ID_NS_NVM_GUARD_SHIFT = 7,
485485
NVME_ID_NS_NVM_GUARD_MASK = 0x3,
486+
NVME_ID_NS_NVM_QPIF_SHIFT = 9,
487+
NVME_ID_NS_NVM_QPIF_MASK = 0xf,
488+
NVME_ID_NS_NVM_QPIFS = 1 << 3,
486489
};
487490

488491
static inline __u8 nvme_elbaf_sts(__u32 elbaf)
@@ -495,6 +498,11 @@ static inline __u8 nvme_elbaf_guard_type(__u32 elbaf)
495498
return (elbaf >> NVME_ID_NS_NVM_GUARD_SHIFT) & NVME_ID_NS_NVM_GUARD_MASK;
496499
}
497500

501+
static inline __u8 nvme_elbaf_qualified_guard_type(__u32 elbaf)
502+
{
503+
return (elbaf >> NVME_ID_NS_NVM_QPIF_SHIFT) & NVME_ID_NS_NVM_QPIF_MASK;
504+
}
505+
498506
struct nvme_id_ctrl_nvm {
499507
__u8 vsl;
500508
__u8 wzsl;
@@ -574,6 +582,7 @@ enum {
574582
NVME_NVM_NS_16B_GUARD = 0,
575583
NVME_NVM_NS_32B_GUARD = 1,
576584
NVME_NVM_NS_64B_GUARD = 2,
585+
NVME_NVM_NS_QTYPE_GUARD = 3,
577586
};
578587

579588
static inline __u8 nvme_lbaf_index(__u8 flbas)

0 commit comments

Comments
 (0)