FD.io VPP  v20.09-64-g4f7b92f0a
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_NUM_RX_QUEUES_ALL ((u16)-1)
26 
27 #define af_xdp_log(lvl, dev, f, ...) \
28  vlib_log(lvl, af_xdp_main.log_class, "%v: " f, (dev)->name, ##__VA_ARGS__)
29 
30 #define foreach_af_xdp_device_flags \
31  _(0, INITIALIZED, "initialized") \
32  _(1, ERROR, "error") \
33  _(2, ADMIN_UP, "admin-up") \
34  _(4, LINK_UP, "link-up") \
35  _(8, ZEROCOPY, "zero-copy") \
36 
37 enum
38 {
39 #define _(a, b, c) AF_XDP_DEVICE_F_##b = (1 << a),
41 #undef _
42 };
43 
44 #define af_xdp_device_error(dev, fmt, ...) \
45  if (!(dev)->error) \
46  { \
47  clib_error_t *err_ = clib_error_return_unix (0, fmt, ## __VA_ARGS__); \
48  if (!clib_atomic_bool_cmp_and_swap (&(dev)->error, 0, err_)) \
49  clib_error_free(err_); \
50  }
51 
52 typedef struct
53 {
54  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
55 
56  /* fields below are accessed in data-plane (hot) */
57 
58  struct xsk_ring_cons rx;
59  struct xsk_ring_prod fq;
60  int xsk_fd;
61 
62  /* fields below are accessed in control-plane only (cold) */
63 
65 } af_xdp_rxq_t;
66 
67 typedef struct
68 {
69  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
70 
71  /* fields below are accessed in data-plane (hot) */
72 
74  struct xsk_ring_prod tx;
75  struct xsk_ring_cons cq;
76  int xsk_fd;
77 } af_xdp_txq_t;
78 
79 typedef struct
80 {
81  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
82 
83  /* fields below are accessed in data-plane (hot) */
84 
92  u8 pool; /* buffer pool index */
94 
95  /* fields below are accessed in control-plane only (cold) */
96 
97  char *name;
98  char *linux_ifname;
100  u8 hwaddr[6];
101 
102  struct xsk_umem **umem;
103  struct xsk_socket **xsk;
104 
105  struct bpf_object *bpf_obj;
106  unsigned linux_ifindex;
107 
108  /* error */
111 
112 typedef struct
113 {
117 } af_xdp_main_t;
118 
120 
121 typedef enum
122 {
126 } af_xdp_mode_t;
127 
128 typedef struct
129 {
131  char *name;
132  char *prog;
137 
138  /* return */
139  int rv;
143 
146 
149 
150 /* format.c */
154 
155 /* unformat.c */
157 
158 typedef struct
159 {
163 
164 #define foreach_af_xdp_tx_func_error \
165 _(NO_FREE_SLOTS, "no free tx slots") \
166 _(SENDTO_REQUIRED, "sendto required") \
167 _(SENDTO_FAILURES, "sendto failures")
168 
169 typedef enum
170 {
171 #define _(f,s) AF_XDP_TX_ERROR_##f,
173 #undef _
176 
177 #endif /* _AF_XDP_H_ */
178 
179 /*
180  * fd.io coding-style-patch-verification: ON
181  *
182  * Local Variables:
183  * eval: (c-set-style "gnu")
184  * End:
185  */
u16 msg_id_base
Definition: af_xdp.h:116
#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:88
format_function_t format_af_xdp_device_name
Definition: af_xdp.h:152
clib_error_t * error
Definition: af_xdp.h:109
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:89
struct _vnet_device_class vnet_device_class_t
unsigned char u8
Definition: types.h:56
af_xdp_device_t * devices
Definition: af_xdp.h:114
af_xdp_rxq_t * rxqs
Definition: af_xdp.h:85
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
struct xsk_umem ** umem
Definition: af_xdp.h:102
vlib_log_class_t log_class
Definition: af_xdp.h:115
struct xsk_socket ** xsk
Definition: af_xdp.h:103
vlib_buffer_t * buffer_template
Definition: af_xdp.h:87
u32 vlib_log_class_t
Definition: vlib.h:51
af_xdp_main_t af_xdp_main
Definition: device.c:30
uword file_index
Definition: af_xdp.h:64
unsigned int u32
Definition: types.h:88
char * name
Definition: af_xdp.h:97
unsigned linux_ifindex
Definition: af_xdp.h:106
format_function_t format_af_xdp_input_trace
Definition: af_xdp.h:153
af_xdp_mode_t
Definition: af_xdp.h:121
int xsk_fd
Definition: af_xdp.h:60
unsigned short u16
Definition: types.h:57
af_xdp_tx_func_error_t
Definition: af_xdp.h:169
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:30
u32 dev_instance
Definition: af_xdp.h:99
void af_xdp_create_if(vlib_main_t *vm, af_xdp_create_if_args_t *args)
Definition: device.c:305
char * linux_ifname
Definition: af_xdp.h:98
unformat_function_t unformat_af_xdp_create_if_args
Definition: af_xdp.h:156
format_function_t format_af_xdp_device
Definition: af_xdp.h:151
clib_spinlock_t lock
Definition: af_xdp.h:73
u32 hw_if_index
Definition: af_xdp.h:90
int xsk_fd
Definition: af_xdp.h:76
struct _vlib_node_registration vlib_node_registration_t
#define foreach_af_xdp_tx_func_error
Definition: af_xdp.h:164
VLIB buffer representation.
Definition: buffer.h:102
clib_error_t * error
Definition: af_xdp.h:141
u64 uword
Definition: types.h:112
u32 sw_if_index
Definition: af_xdp.h:89
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:86
af_xdp_mode_t mode
Definition: af_xdp.h:133
struct bpf_object * bpf_obj
Definition: af_xdp.h:105