]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - include/linux/skb_array.h
2 * Definitions for the 'struct skb_array' datastructure.
5 * Michael S. Tsirkin <mst@redhat.com>
7 * Copyright (C) 2016 Red Hat, Inc.
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
14 * Limited-size FIFO of skbs. Can be used more or less whenever
15 * sk_buff_head can be used, except you need to know the queue size in
17 * Implemented as a type-safe wrapper around ptr_ring.
20 #ifndef _LINUX_SKB_ARRAY_H
21 #define _LINUX_SKB_ARRAY_H 1
24 #include <linux/ptr_ring.h>
25 #include <linux/skbuff.h>
26 #include <linux/if_vlan.h>
33 /* Might be slightly faster than skb_array_full below, but callers invoking
34 * this in a loop must use a compiler barrier, for example cpu_relax().
36 static inline bool __skb_array_full(struct skb_array
*a
)
38 return __ptr_ring_full(&a
->ring
);
41 static inline bool skb_array_full(struct skb_array
*a
)
43 return ptr_ring_full(&a
->ring
);
46 static inline int skb_array_produce(struct skb_array
*a
, struct sk_buff
*skb
)
48 return ptr_ring_produce(&a
->ring
, skb
);
51 static inline int skb_array_produce_irq(struct skb_array
*a
, struct sk_buff
*skb
)
53 return ptr_ring_produce_irq(&a
->ring
, skb
);
56 static inline int skb_array_produce_bh(struct skb_array
*a
, struct sk_buff
*skb
)
58 return ptr_ring_produce_bh(&a
->ring
, skb
);
61 static inline int skb_array_produce_any(struct skb_array
*a
, struct sk_buff
*skb
)
63 return ptr_ring_produce_any(&a
->ring
, skb
);
66 /* Might be slightly faster than skb_array_empty below, but only safe if the
67 * array is never resized. Also, callers invoking this in a loop must take care
68 * to use a compiler barrier, for example cpu_relax().
70 static inline bool __skb_array_empty(struct skb_array
*a
)
72 return !__ptr_ring_peek(&a
->ring
);
75 static inline bool skb_array_empty(struct skb_array
*a
)
77 return ptr_ring_empty(&a
->ring
);
80 static inline bool skb_array_empty_bh(struct skb_array
*a
)
82 return ptr_ring_empty_bh(&a
->ring
);
85 static inline bool skb_array_empty_irq(struct skb_array
*a
)
87 return ptr_ring_empty_irq(&a
->ring
);
90 static inline bool skb_array_empty_any(struct skb_array
*a
)
92 return ptr_ring_empty_any(&a
->ring
);
95 static inline struct sk_buff
*skb_array_consume(struct skb_array
*a
)
97 return ptr_ring_consume(&a
->ring
);
100 static inline int skb_array_consume_batched(struct skb_array
*a
,
101 struct sk_buff
**array
, int n
)
103 return ptr_ring_consume_batched(&a
->ring
, (void **)array
, n
);
106 static inline struct sk_buff
*skb_array_consume_irq(struct skb_array
*a
)
108 return ptr_ring_consume_irq(&a
->ring
);
111 static inline int skb_array_consume_batched_irq(struct skb_array
*a
,
112 struct sk_buff
**array
, int n
)
114 return ptr_ring_consume_batched_irq(&a
->ring
, (void **)array
, n
);
117 static inline struct sk_buff
*skb_array_consume_any(struct skb_array
*a
)
119 return ptr_ring_consume_any(&a
->ring
);
122 static inline int skb_array_consume_batched_any(struct skb_array
*a
,
123 struct sk_buff
**array
, int n
)
125 return ptr_ring_consume_batched_any(&a
->ring
, (void **)array
, n
);
129 static inline struct sk_buff
*skb_array_consume_bh(struct skb_array
*a
)
131 return ptr_ring_consume_bh(&a
->ring
);
134 static inline int skb_array_consume_batched_bh(struct skb_array
*a
,
135 struct sk_buff
**array
, int n
)
137 return ptr_ring_consume_batched_bh(&a
->ring
, (void **)array
, n
);
140 static inline int __skb_array_len_with_tag(struct sk_buff
*skb
)
145 if (skb_vlan_tag_present(skb
))
154 static inline int skb_array_peek_len(struct skb_array
*a
)
156 return PTR_RING_PEEK_CALL(&a
->ring
, __skb_array_len_with_tag
);
159 static inline int skb_array_peek_len_irq(struct skb_array
*a
)
161 return PTR_RING_PEEK_CALL_IRQ(&a
->ring
, __skb_array_len_with_tag
);
164 static inline int skb_array_peek_len_bh(struct skb_array
*a
)
166 return PTR_RING_PEEK_CALL_BH(&a
->ring
, __skb_array_len_with_tag
);
169 static inline int skb_array_peek_len_any(struct skb_array
*a
)
171 return PTR_RING_PEEK_CALL_ANY(&a
->ring
, __skb_array_len_with_tag
);
174 static inline int skb_array_init(struct skb_array
*a
, int size
, gfp_t gfp
)
176 return ptr_ring_init(&a
->ring
, size
, gfp
);
179 static void __skb_array_destroy_skb(void *ptr
)
184 static inline void skb_array_unconsume(struct skb_array
*a
,
185 struct sk_buff
**skbs
, int n
)
187 ptr_ring_unconsume(&a
->ring
, (void **)skbs
, n
, __skb_array_destroy_skb
);
190 static inline int skb_array_resize(struct skb_array
*a
, int size
, gfp_t gfp
)
192 return ptr_ring_resize(&a
->ring
, size
, gfp
, __skb_array_destroy_skb
);
195 static inline int skb_array_resize_multiple(struct skb_array
**rings
,
196 int nrings
, unsigned int size
,
199 BUILD_BUG_ON(offsetof(struct skb_array
, ring
));
200 return ptr_ring_resize_multiple((struct ptr_ring
**)rings
,
202 __skb_array_destroy_skb
);
205 static inline void skb_array_cleanup(struct skb_array
*a
)
207 ptr_ring_cleanup(&a
->ring
, __skb_array_destroy_skb
);
210 #endif /* _LINUX_SKB_ARRAY_H */