From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by mail.toke.dk (Postfix) with ESMTPS id 8CBAC982F73 for ; Tue, 28 Jun 2022 21:50:07 +0200 (CEST) Authentication-Results: mail.toke.dk; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=JsnEwwQ1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656445807; x=1687981807; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=t8ZlSI0m7zNuVag8i0YVuPoeiLfNpeZeGU0sNzKVBRo=; b=JsnEwwQ1FBJgbqNG04U1io02EbH6a6wbnPUztssAtwSC/zOC3pHI1cnX oesx5nPLLvNIiH8TkqQ+xlD86uh57z1VEHPtNjHnQgipJyZQq372MoV4V 0Nml3tDQaFtM03c63F5xPvFexaYVkv8uj6mYR/FcK9/7lnxKm6tDuEX9P 2qacoMCFeeqna7DvKQZn4yKOsrElrr81m+/wwsRhM4MzhR5nP6vrYko9A 3cbatxD+e/JgWKdDUq4pqitPGOxOvezLLhVV/EHuA78OpT5JxlPGFZvWF 4/D7aF217ymXBqfCtP/hF7yMF5am7efdSdBoZjC5uQRLXAg1ulSPf0uxQ w==; X-IronPort-AV: E=McAfee;i="6400,9594,10392"; a="343523408" X-IronPort-AV: E=Sophos;i="5.92,229,1650956400"; d="scan'208";a="343523408" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2022 12:50:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,229,1650956400"; d="scan'208";a="732883570" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by fmsmga001.fm.intel.com with ESMTP; 28 Jun 2022 12:50:01 -0700 Received: from newjersey.igk.intel.com (newjersey.igk.intel.com [10.102.20.203]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id 25SJmr9n022013; Tue, 28 Jun 2022 20:49:59 +0100 From: Alexander Lobakin To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Date: Tue, 28 Jun 2022 21:48:09 +0200 Message-Id: <20220628194812.1453059-50-alexandr.lobakin@intel.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220628194812.1453059-1-alexandr.lobakin@intel.com> References: <20220628194812.1453059-1-alexandr.lobakin@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: EO7V3MW3GLQEMH2UCWZAIAIWCGNRB4ZJ X-Message-ID-Hash: EO7V3MW3GLQEMH2UCWZAIAIWCGNRB4ZJ X-MailFrom: alexandr.lobakin@intel.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Alexander Lobakin , Larysa Zaremba , Michal Swiatkowski , Jesper Dangaard Brouer , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , Toke Hoiland-Jorgensen , Lorenzo Bianconi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jesse Brandeburg , John Fastabend , Yajun Deng , Willem de Bruijn , bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, xdp-hints@xdp-project.net X-Mailman-Version: 3.3.5 Precedence: list Subject: [xdp-hints] [PATCH RFC bpf-next 49/52] libbpf: add LE <--> CPU conversion helpers List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Larysa Zaremba 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 Signed-off-by: Alexander Lobakin --- tools/lib/bpf/bpf_endian.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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__ */ -- 2.36.1