FD.io VPP  v20.09-rc2-28-g3c5414029
Vector Packet Processing
af_xdp.h
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2018 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17 
18 #ifndef _AF_XDP_H_
19 #define _AF_XDP_H_
20 
21 #include <vlib/log.h>
22 #include <vnet/interface.h>
23 #include <bpf/xsk.h>
24 
25 #define af_xdp_log(lvl, dev, f, ...) \
26  vlib_log(lvl, af_xdp_main.log_class, "%v: " f, (dev)->name, ##__VA_ARGS__)
27 
28 #define foreach_af_xdp_device_flags \
29  _(0, INITIALIZED, "initialized") \
30  _(1, ERROR, "error") \
31  _(2, ADMIN_UP, "admin-up") \
32  _(4, LINK_UP, "link-up") \
33  _(8, ZEROCOPY, "zero-copy") \
34 
35 enum
36 {
37 #define _(a, b, c) AF_XDP_DEVICE_F_##b = (1 << a),
39 #undef _
40 };
41 
42 #define af_xdp_device_error(dev, fmt, ...) \
43  if (!(dev)->error) \
44  { \
45  clib_error_t *err_ = clib_error_return_unix (0, fmt, ## __VA_ARGS__); \
46  if (!clib_atomic_bool_cmp_and_swap (&(dev)->error, 0, err_)) \
47  clib_error_free(err_); \
48  }
49 
50 typedef struct
51 {
52  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
53 
54  /* fields below are accessed in data-plane (hot) */
55 
56  struct xsk_ring_cons rx;
57  struct xsk_ring_prod fq;
58  int xsk_fd;
59 
60  /* fields below are accessed in control-plane only (cold) */
61 
63 } af_xdp_rxq_t;
64 
65 typedef struct
66 {
67  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
68 
69  /* fields below are accessed in data-plane (hot) */
70 
72  struct xsk_ring_prod tx;
73  struct xsk_ring_cons cq;
74  int xsk_fd;
75 } af_xdp_txq_t;
76 
77 typedef struct
78 {
79  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
80 
81  /* fields below are accessed in data-plane (hot) */
82 
90  u8 pool; /* buffer pool index */
92 
93  /* fields below are accessed in control-plane only (cold) */
94 
95  char *name;
96  char *linux_ifname;
98  u8 hwaddr[6];
99 
100  struct xsk_umem **umem;
101  struct xsk_socket **xsk;
102 
103  struct bpf_object *bpf_obj;
104  unsigned linux_ifindex;
105 
106  /* error */
109 
110 typedef struct
111 {
115 } af_xdp_main_t;
116 
118 
119 typedef enum
120 {
124 } af_xdp_mode_t;
125 
126 typedef struct
127 {
129  char *name;
130  char *prog;
135 
136  /* return */
137  int rv;
141 
144 
147 
148 /* format.c */
152 
153 /* unformat.c */
155 
156 typedef struct
157 {
161 
162 #define foreach_af_xdp_tx_func_error \
163 _(NO_FREE_SLOTS, "no free tx slots") \
164 _(SENDTO_REQUIRED, "sendto required") \
165 _(SENDTO_FAILURES, "sendto failures")
166 
167 typedef enum
168 {
169 #define _(f,s) AF_XDP_TX_ERROR_##f,
171 #undef _
174 
175 #endif /* _AF_XDP_H_ */
176 
177 /*
178  * fd.io coding-style-patch-verification: ON
179  *
180  * Local Variables:
181  * eval: (c-set-style "gnu")
182  * End:
183  */
u16 msg_id_base
Definition: af_xdp.h:114
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
vnet_device_class_t af_xdp_device_class
u32 per_interface_next_index
Definition: af_xdp.h:86
format_function_t format_af_xdp_device_name
Definition: af_xdp.h:150
clib_error_t * error
Definition: af_xdp.h:107
vlib_main_t * vm
Definition: in2out_ed.c:1582
void af_xdp_delete_if(vlib_main_t *vm, af_xdp_device_t *ad)
Definition: device.c:88
struct _vnet_device_class vnet_device_class_t
unsigned char u8
Definition: types.h:56
af_xdp_device_t * devices
Definition: af_xdp.h:112
af_xdp_rxq_t * rxqs
Definition: af_xdp.h:83
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
struct xsk_umem ** umem
Definition: af_xdp.h:100
vlib_log_class_t log_class
Definition: af_xdp.h:113
struct xsk_socket ** xsk
Definition: af_xdp.h:101
vlib_buffer_t * buffer_template
Definition: af_xdp.h:85
u32 vlib_log_class_t
Definition: vlib.h:51
af_xdp_main_t af_xdp_main
Definition: device.c:29
uword file_index
Definition: af_xdp.h:62
unsigned int u32
Definition: types.h:88
char * name
Definition: af_xdp.h:95
unsigned linux_ifindex
Definition: af_xdp.h:104
format_function_t format_af_xdp_input_trace
Definition: af_xdp.h:151
af_xdp_mode_t
Definition: af_xdp.h:119
int xsk_fd
Definition: af_xdp.h:58
unsigned short u16
Definition: types.h:57
af_xdp_tx_func_error_t
Definition: af_xdp.h:167
uword() unformat_function_t(unformat_input_t *input, va_list *args)
Definition: format.h:233
#define foreach_af_xdp_device_flags
Definition: af_xdp.h:28
u32 dev_instance
Definition: af_xdp.h:97
void af_xdp_create_if(vlib_main_t *vm, af_xdp_create_if_args_t *args)
Definition: device.c:294
char * linux_ifname
Definition: af_xdp.h:96
unformat_function_t unformat_af_xdp_create_if_args
Definition: af_xdp.h:154
format_function_t format_af_xdp_device
Definition: af_xdp.h:149
clib_spinlock_t lock
Definition: af_xdp.h:71
u32 hw_if_index
Definition: af_xdp.h:88
int xsk_fd
Definition: af_xdp.h:74
struct _vlib_node_registration vlib_node_registration_t
#define foreach_af_xdp_tx_func_error
Definition: af_xdp.h:162
VLIB buffer representation.
Definition: buffer.h:102
clib_error_t * error
Definition: af_xdp.h:139
u64 uword
Definition: types.h:112
u32 sw_if_index
Definition: af_xdp.h:87
vlib_node_registration_t af_xdp_input_node
(constructor) VLIB_REGISTER_NODE (af_xdp_input_node)
Definition: input.c:349
af_xdp_txq_t * txqs
Definition: af_xdp.h:84
af_xdp_mode_t mode
Definition: af_xdp.h:131
struct bpf_object * bpf_obj
Definition: af_xdp.h:103