Skip to content

Commit b465046

Browse files
calebsanderkeithbusch
authored andcommitted
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 <[email protected]> Signed-off-by: Caleb Sander Mateos <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent 823340b commit b465046

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

drivers/nvme/host/nvme.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,12 @@ static inline u32 nvme_bytes_to_numd(size_t len)
762762
return (len >> 2) - 1;
763763
}
764764

765+
/* Decode a 2-byte "0's based"/"0-based" field */
766+
static inline u32 from0based(__le16 value)
767+
{
768+
return (u32)le16_to_cpu(value) + 1;
769+
}
770+
765771
static inline bool nvme_is_ana_error(u16 status)
766772
{
767773
switch (status & NVME_SCT_SC_MASK) {

0 commit comments

Comments
 (0)