[PATCH RFCv2 bpf-next 14/18] i40e: Add xdp_hints_union

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The union named "xdp_hints_union" must contain all the xdp_hints_*
struct's available in this driver. This is used when decoding the
modules BTF to identify the available XDP-hints struct's. As metadata
grows backwards padding are needed for proper alignment. This alignment
is verified by compile time checks via BUILD_BUG_ON().

Signed-off-by: Jesper Dangaard Brouer <brouer@xxxxxxxxxx>
---
 drivers/net/ethernet/intel/i40e/i40e_txrx.c |   31 +++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/drivers/net/ethernet/intel/i40e/i40e_txrx.c b/drivers/net/ethernet/intel/i40e/i40e_txrx.c
index d945ac122d4c..e21f3ff4c811 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_txrx.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_txrx.c
@@ -1953,6 +1953,36 @@ struct xdp_hints_i40e_timestamp {
 	struct xdp_hints_i40e base;
 };
 
+/* xdp_hints_union defines xdp_hints_* structs available in this driver.
+ * As metadata grows backwards structure are padded to align.
+ */
+union xdp_hints_union {
+	struct xdp_hints_i40e_timestamp i40e_ts;
+	struct {
+		u64 pad1_ts;
+		struct xdp_hints_i40e i40e;
+	};
+	struct {
+		u64 pad2_ts;
+		u32 pad3_i40e;
+		struct xdp_hints_common common;
+	};
+}; // __aligned(4) __attribute__((packed));
+
+union xdp_hints_union define_union;
+
+#define OFFSET1 offsetof(union xdp_hints_union, common)
+#define OFFSET2 offsetof(union xdp_hints_union, i40e.common)
+#define OFFSET3 offsetof(union xdp_hints_union, i40e_ts.base.common)
+
+static void xdp_hints_compile_check(void)
+{
+	union xdp_hints_union my_union = {};
+
+	BUILD_BUG_ON(OFFSET1 != OFFSET2);
+	BUILD_BUG_ON(OFFSET1 != OFFSET3);
+}
+
 /* Extending xdp_hints_flags */
 enum xdp_hints_flags_driver {
 	HINT_FLAG_RX_TIMESTAMP = BIT(16),
@@ -1968,6 +1998,7 @@ static inline u32 i40e_rx_checksum_xdp(struct i40e_vsi *vsi, u64 qword1,
 {
 	struct i40e_rx_checksum_ret ret;
 
+	xdp_hints_compile_check();
 	ret = _i40e_rx_checksum(vsi, qword1, ptype);
 	return xdp_hints_set_rx_csum(&xdp_hints->common, ret.ip_summed, ret.csum_level);
 }





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux