1 From 2e88d4ff03013937028f5397268b21e10cf68713 Mon Sep 17 00:00:00 2001
2 From: Lorenzo Bianconi <lorenzo@kernel.org>
3 Date: Fri, 21 Jan 2022 11:09:45 +0100
4 Subject: [PATCH] xdp: introduce flags field in xdp_buff/xdp_frame
6 Introduce flags field in xdp_frame and xdp_buffer data structures
7 to define additional buffer features. At the moment the only
8 supported buffer feature is frags bit (XDP_FLAGS_HAS_FRAGS).
9 frags bit is used to specify if this is a linear buffer
10 (XDP_FLAGS_HAS_FRAGS not set) or a frags frame (XDP_FLAGS_HAS_FRAGS
11 set). In the latter case the driver is expected to initialize the
12 skb_shared_info structure at the end of the first buffer to link together
13 subsequent buffers belonging to the same frame.
15 Acked-by: Toke Hoiland-Jorgensen <toke@redhat.com>
16 Acked-by: John Fastabend <john.fastabend@gmail.com>
17 Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>
18 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
19 Link: https://lore.kernel.org/r/e389f14f3a162c0a5bc6a2e1aa8dd01a90be117d.1642758637.git.lorenzo@kernel.org
20 Signed-off-by: Alexei Starovoitov <ast@kernel.org>
22 include/net/xdp.h | 29 +++++++++++++++++++++++++++++
23 1 file changed, 29 insertions(+)
25 diff --git a/include/net/xdp.h b/include/net/xdp.h
26 index 8f0812e4996d..485e9495a690 100644
27 --- a/include/net/xdp.h
28 +++ b/include/net/xdp.h
29 @@ -66,6 +66,10 @@ struct xdp_txq_info {
30 struct net_device *dev;
33 +enum xdp_buff_flags {
34 + XDP_FLAGS_HAS_FRAGS = BIT(0), /* non-linear xdp buff */
40 @@ -74,13 +78,30 @@ struct xdp_buff {
41 struct xdp_rxq_info *rxq;
42 struct xdp_txq_info *txq;
43 u32 frame_sz; /* frame size to deduce data_hard_end/reserved tailroom*/
44 + u32 flags; /* supported values defined in xdp_buff_flags */
47 +static __always_inline bool xdp_buff_has_frags(struct xdp_buff *xdp)
49 + return !!(xdp->flags & XDP_FLAGS_HAS_FRAGS);
52 +static __always_inline void xdp_buff_set_frags_flag(struct xdp_buff *xdp)
54 + xdp->flags |= XDP_FLAGS_HAS_FRAGS;
57 +static __always_inline void xdp_buff_clear_frags_flag(struct xdp_buff *xdp)
59 + xdp->flags &= ~XDP_FLAGS_HAS_FRAGS;
62 static __always_inline void
63 xdp_init_buff(struct xdp_buff *xdp, u32 frame_sz, struct xdp_rxq_info *rxq)
65 xdp->frame_sz = frame_sz;
70 static __always_inline void
71 @@ -122,8 +143,14 @@ struct xdp_frame {
73 struct xdp_mem_info mem;
74 struct net_device *dev_rx; /* used by cpumap */
75 + u32 flags; /* supported values defined in xdp_buff_flags */
78 +static __always_inline bool xdp_frame_has_frags(struct xdp_frame *frame)
80 + return !!(frame->flags & XDP_FLAGS_HAS_FRAGS);
83 #define XDP_BULK_QUEUE_SIZE 16
84 struct xdp_frame_bulk {
86 @@ -180,6 +207,7 @@ void xdp_convert_frame_to_buff(struct xd
87 xdp->data_end = frame->data + frame->len;
88 xdp->data_meta = frame->data - frame->metasize;
89 xdp->frame_sz = frame->frame_sz;
90 + xdp->flags = frame->flags;
94 @@ -206,6 +234,7 @@ int xdp_update_frame_from_buff(struct xd
95 xdp_frame->headroom = headroom - sizeof(*xdp_frame);
96 xdp_frame->metasize = metasize;
97 xdp_frame->frame_sz = xdp->frame_sz;
98 + xdp_frame->flags = xdp->flags;