nvme: add from0based() helper

The NVMe specifications are big fans of "0's based"/"0-based" fields for
encoding values that must be positive. The encoded value is 1 less than
the value it represents. nvmet already provides a helper to0based() for
encoding 0's based values, so add a corresponding helper to decode these
fields on the host side.

Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
Signed-off-by: Keith Busch <kbusch@kernel.org>
This commit is contained in:
Caleb Sander Mateos
2026-02-27 13:23:50 -07:00
committed by Keith Busch
parent 823340b7e8
commit b465046c8c

View File

@@ -762,6 +762,12 @@ static inline u32 nvme_bytes_to_numd(size_t len)
return (len >> 2) - 1;
}
/* Decode a 2-byte "0's based"/"0-based" field */
static inline u32 from0based(__le16 value)
{
return (u32)le16_to_cpu(value) + 1;
}
static inline bool nvme_is_ana_error(u16 status)
{
switch (status & NVME_SCT_SC_MASK) {