diff mbox series

[PATCHv4,3/8] asm-generic: introduce be48 unaligned accessors

Message ID 20220303201312.3255347-4-kbusch@kernel.org (mailing list archive)
State New, archived
Headers show
Series 64-bit data integrity field support | expand

Commit Message

Keith Busch March 3, 2022, 8:13 p.m. UTC
The NVMe protocol extended the data integrity fields with unaligned
48-bit reference tags. Provide some helper accessors in
preparation for these.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
---
 include/asm-generic/unaligned.h | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

Comments

Bart Van Assche March 3, 2022, 8:47 p.m. UTC | #1
On 3/3/22 12:13, Keith Busch wrote:
> The NVMe protocol extended the data integrity fields with unaligned
> 48-bit reference tags. Provide some helper accessors in
> preparation for these.

Reviewed-by: Bart Van Assche <bvanassche@acm.org>
David Laight March 4, 2022, 1:31 a.m. UTC | #2
From: Keith Busch
> Sent: 03 March 2022 20:13
> 
> The NVMe protocol extended the data integrity fields with unaligned
> 48-bit reference tags.

If they are reference tags, are they only interpreted by the
sending system?
In which case they don't need to be big-endian since the
actual value doesn't really matter.

> Provide some helper accessors in preparation for these.
> 
...
> diff --git a/include/asm-generic/unaligned.h b/include/asm-generic/unaligned.h
> index 1c4242416c9f..8fc637379899 100644
> --- a/include/asm-generic/unaligned.h
> +++ b/include/asm-generic/unaligned.h
> @@ -126,4 +126,30 @@ static inline void put_unaligned_le24(const u32 val, void *p)
>  	__put_unaligned_le24(val, p);
>  }
> 
> +static inline void __put_unaligned_be48(const u64 val, __u8 *p)
> +{
> +	*p++ = val >> 40;
> +	*p++ = val >> 32;
> +	*p++ = val >> 24;
> +	*p++ = val >> 16;
> +	*p++ = val >> 8;
> +	*p++ = val;
> +}

Although that matches __put_unaligned_be24() I think I'd use
array indexing not pointer increments.
The compiler will probably generate the same code anyway.

However it is probably better to do:
	put_unaligned_be16(val >> 32, p);
	put_unaligned_be32(val, p + 2);
so you get 2 memory accesses on x86 (etc) instead of 6.

Similarly for __get_unaligned_be48() where it is likely
so make a bigger difference.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Martin K. Petersen March 4, 2022, 2:40 a.m. UTC | #3
David,

> If they are reference tags, are they only interpreted by the sending
> system?  In which case they don't need to be big-endian since the
> actual value doesn't really matter.

The tags are validated by the storage device.
Keith Busch March 4, 2022, 2:56 a.m. UTC | #4
On Fri, Mar 04, 2022 at 01:31:26AM +0000, David Laight wrote:
> From: Keith Busch
> > Sent: 03 March 2022 20:13
> > 
> > The NVMe protocol extended the data integrity fields with unaligned
> > 48-bit reference tags.
> 
> If they are reference tags, are they only interpreted by the
> sending system?

No, this field participates in end-to-end data protection formats, so is
verified on both sides.
diff mbox series

Patch

diff --git a/include/asm-generic/unaligned.h b/include/asm-generic/unaligned.h
index 1c4242416c9f..8fc637379899 100644
--- a/include/asm-generic/unaligned.h
+++ b/include/asm-generic/unaligned.h
@@ -126,4 +126,30 @@  static inline void put_unaligned_le24(const u32 val, void *p)
 	__put_unaligned_le24(val, p);
 }
 
+static inline void __put_unaligned_be48(const u64 val, __u8 *p)
+{
+	*p++ = val >> 40;
+	*p++ = val >> 32;
+	*p++ = val >> 24;
+	*p++ = val >> 16;
+	*p++ = val >> 8;
+	*p++ = val;
+}
+
+static inline void put_unaligned_be48(const u64 val, void *p)
+{
+	__put_unaligned_be48(val, p);
+}
+
+static inline u64 __get_unaligned_be48(const u8 *p)
+{
+	return (u64)p[0] << 40 | (u64)p[1] << 32 | p[2] << 24 |
+		p[3] << 16 | p[4] << 8 | p[5];
+}
+
+static inline u64 get_unaligned_be48(const void *p)
+{
+	return __get_unaligned_be48(p);
+}
+
 #endif /* __ASM_GENERIC_UNALIGNED_H */