diff mbox series

[RFC,bpf-next,49/52] libbpf: add LE <--> CPU conversion helpers

Message ID 20220628194812.1453059-50-alexandr.lobakin@intel.com (mailing list archive)
State RFC
Delegated to: BPF
Headers show
Series bpf, xdp: introduce and use Generic Hints/metadata | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-1 fail Logs for Kernel LATEST on ubuntu-latest with gcc
bpf/vmtest-bpf-next-VM_Test-2 fail Logs for Kernel LATEST on ubuntu-latest with llvm-15
bpf/vmtest-bpf-next-VM_Test-3 fail Logs for Kernel LATEST on z15 with gcc
netdev/tree_selection success Clearly marked for bpf-next, async
netdev/apply fail Patch does not apply to bpf-next

Commit Message

Alexander Lobakin June 28, 2022, 7:48 p.m. UTC
From: Larysa Zaremba <larysa.zaremba@intel.com>

XDP Generic metadata structure has fields of the explicit
Endianness, all 16, 32 and 64-bit wide.
To make it easier to access them, define __le{16,32,64} <--> cpu
helpers the same way it's done for the BEs.

Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com>
Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>
---
 tools/lib/bpf/bpf_endian.h | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
diff mbox series

Patch

diff --git a/tools/lib/bpf/bpf_endian.h b/tools/lib/bpf/bpf_endian.h
index b03db6aa3f14..35941e6f1d99 100644
--- a/tools/lib/bpf/bpf_endian.h
+++ b/tools/lib/bpf/bpf_endian.h
@@ -60,6 +60,18 @@ 
 # define __bpf_cpu_to_be64(x)		__builtin_bswap64(x)
 # define __bpf_constant_be64_to_cpu(x)	___bpf_swab64(x)
 # define __bpf_constant_cpu_to_be64(x)	___bpf_swab64(x)
+# define __bpf_le16_to_cpu(x)		(x)
+# define __bpf_cpu_to_le16(x)		(x)
+# define __bpf_constant_le16_to_cpu(x)	(x)
+# define __bpf_constant_cpu_to_le16(x)	(x)
+# define __bpf_le32_to_cpu(x)		(x)
+# define __bpf_cpu_to_le32(x)		(x)
+# define __bpf_constant_le32_to_cpu(x)	(x)
+# define __bpf_constant_cpu_to_le32(x)	(x)
+# define __bpf_le64_to_cpu(x)		(x)
+# define __bpf_cpu_to_le64(x)		(x)
+# define __bpf_constant_le64_to_cpu(x)	(x)
+# define __bpf_constant_cpu_to_le64(x)	(x)
 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
 # define __bpf_ntohs(x)			(x)
 # define __bpf_htons(x)			(x)
@@ -73,6 +85,18 @@ 
 # define __bpf_cpu_to_be64(x)		(x)
 # define __bpf_constant_be64_to_cpu(x)  (x)
 # define __bpf_constant_cpu_to_be64(x)  (x)
+# define __bpf_le16_to_cpu(x)		__builtin_bswap16(x)
+# define __bpf_cpu_to_le16(x)		__builtin_bswap16(x)
+# define __bpf_constant_le16_to_cpu(x)	___bpf_swab16(x)
+# define __bpf_constant_cpu_to_le16(x)	___bpf_swab16(x)
+# define __bpf_le32_to_cpu(x)		__builtin_bswap32(x)
+# define __bpf_cpu_to_le32(x)		__builtin_bswap32(x)
+# define __bpf_constant_le32_to_cpu(x)	___bpf_swab32(x)
+# define __bpf_constant_cpu_to_le32(x)	___bpf_swab32(x)
+# define __bpf_le64_to_cpu(x)		__builtin_bswap64(x)
+# define __bpf_cpu_to_le64(x)		__builtin_bswap64(x)
+# define __bpf_constant_le64_to_cpu(x)	___bpf_swab64(x)
+# define __bpf_constant_cpu_to_le64(x)	___bpf_swab64(x)
 #else
 # error "Fix your compiler's __BYTE_ORDER__?!"
 #endif
@@ -87,5 +111,11 @@ 
 #define bpf_ntohl(x)			__bpf_endop(ntohl, x)
 #define bpf_cpu_to_be64(x)		__bpf_endop(cpu_to_be64, x)
 #define bpf_be64_to_cpu(x)		__bpf_endop(be64_to_cpu, x)
+#define bpf_cpu_to_le16(x)		__bpf_endop(cpu_to_le16, x)
+#define bpf_le16_to_cpu(x)		__bpf_endop(le16_to_cpu, x)
+#define bpf_cpu_to_le32(x)		__bpf_endop(cpu_to_le32, x)
+#define bpf_le32_to_cpu(x)		__bpf_endop(le32_to_cpu, x)
+#define bpf_cpu_to_le64(x)		__bpf_endop(cpu_to_le64, x)
+#define bpf_le64_to_cpu(x)		__bpf_endop(le64_to_cpu, x)
 
 #endif /* __BPF_ENDIAN__ */