FD.io VPP  v21.10.1-2-g0a485f517
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  _ (3, LINK_UP, "link-up") \
35  _ (4, ZEROCOPY, "zero-copy") \
36  _ (5, SYSCALL_LOCK, "syscall-lock")
37 
38 enum
39 {
40 #define _(a, b, c) AF_XDP_DEVICE_F_##b = (1 << a),
42 #undef _
43 };
44 
45 #define af_xdp_device_error(dev, fmt, ...) \
46  if (!(dev)->error) \
47  { \
48  clib_error_t *err_ = clib_error_return_unix (0, fmt, ## __VA_ARGS__); \
49  if (!clib_atomic_bool_cmp_and_swap (&(dev)->error, 0, err_)) \
50  clib_error_free(err_); \
51  }
52 
53 typedef enum
54 {
58 } __clib_packed af_xdp_rxq_mode_t;
59 
60 typedef struct
61 {
62  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
63 
64  /* fields below are accessed in data-plane (hot) */
65 
67  struct xsk_ring_cons rx;
68  struct xsk_ring_prod fq;
69  int xsk_fd;
70 
71  /* fields below are accessed in control-plane only (cold) */
72 
75  af_xdp_rxq_mode_t mode;
76 } af_xdp_rxq_t;
77 
78 typedef struct
79 {
80  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
81 
82  /* fields below are accessed in data-plane (hot) */
83 
86  struct xsk_ring_prod tx;
87  struct xsk_ring_cons cq;
88  int xsk_fd;
89 } af_xdp_txq_t;
90 
91 typedef struct
92 {
93  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
94 
95  /* fields below are accessed in data-plane (hot) */
96 
104  u8 pool; /* buffer pool index */
106 
107  /* fields below are accessed in control-plane only (cold) */
108 
109  char *name;
112  u8 hwaddr[6];
113 
115 
116  struct xsk_umem **umem;
117  struct xsk_socket **xsk;
118 
119  struct bpf_object *bpf_obj;
120  unsigned linux_ifindex;
121 
122  /* error */
125 
126 typedef struct
127 {
131 } af_xdp_main_t;
132 
134 
135 typedef enum
136 {
140 } af_xdp_mode_t;
141 
142 typedef enum
143 {
146 
147 typedef struct
148 {
150  char *name;
151  char *prog;
157 
158  /* return */
159  int rv;
163 
166 
168 
171 
172 /* format.c */
176 
177 /* unformat.c */
179 
180 typedef struct
181 {
185 
186 #define foreach_af_xdp_tx_func_error \
187  _ (NO_FREE_SLOTS, "no free tx slots") \
188  _ (SYSCALL_REQUIRED, "syscall required") \
189  _ (SYSCALL_FAILURES, "syscall failures")
190 
191 typedef enum
192 {
193 #define _(f,s) AF_XDP_TX_ERROR_##f,
195 #undef _
198 
199 #endif /* _AF_XDP_H_ */
200 
201 /*
202  * fd.io coding-style-patch-verification: ON
203  *
204  * Local Variables:
205  * eval: (c-set-style "gnu")
206  * End:
207  */
af_xdp_create_if_args_t::flags
af_xdp_create_flag_t flags
Definition: af_xdp.h:153
af_xdp_device_t::xsk
struct xsk_socket ** xsk
Definition: af_xdp.h:117
vnet_device_class_t
struct _vnet_device_class vnet_device_class_t
af_xdp_create_if_args_t::prog
char * prog
Definition: af_xdp.h:151
af_xdp_main_t
Definition: af_xdp.h:126
af_xdp_create_if_args_t::mode
af_xdp_mode_t mode
Definition: af_xdp.h:152
AF_XDP_TX_N_ERROR
@ AF_XDP_TX_N_ERROR
Definition: af_xdp.h:196
af_xdp_device_t::rxqs
af_xdp_rxq_t * rxqs
Definition: af_xdp.h:97
CLIB_CACHE_LINE_ALIGN_MARK
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
af_xdp_device_t::umem
struct xsk_umem ** umem
Definition: af_xdp.h:116
vlib_log_class_t
u32 vlib_log_class_t
Definition: vlib.h:52
af_xdp_create_flag_t
af_xdp_create_flag_t
Definition: af_xdp.h:142
af_xdp_input_trace_t
Definition: af_xdp.h:180
af_xdp_device_t::pool
u8 pool
Definition: af_xdp.h:104
af_xdp_create_if_args_t::rxq_size
u32 rxq_size
Definition: af_xdp.h:154
AF_XDP_MODE_AUTO
@ AF_XDP_MODE_AUTO
Definition: af_xdp.h:137
format_af_xdp_device_name
format_function_t format_af_xdp_device_name
Definition: af_xdp.h:174
af_xdp_rxq_t::xsk_fd
int xsk_fd
Definition: af_xdp.h:69
af_xdp_main_t::devices
af_xdp_device_t * devices
Definition: af_xdp.h:128
u16
unsigned short u16
Definition: types.h:57
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
af_xdp_device_class
vnet_device_class_t af_xdp_device_class
af_xdp_rxq_t::mode
af_xdp_rxq_mode_t mode
Definition: af_xdp.h:75
format_af_xdp_input_trace
format_function_t format_af_xdp_input_trace
Definition: af_xdp.h:175
af_xdp_mode_t
af_xdp_mode_t
Definition: af_xdp.h:135
af_xdp_delete_if
void af_xdp_delete_if(vlib_main_t *vm, af_xdp_device_t *ad)
Definition: device.c:93
af_xdp_txq_t::syscall_lock
clib_spinlock_t syscall_lock
Definition: af_xdp.h:85
AF_XDP_RXQ_MODE_UNKNOWN
@ AF_XDP_RXQ_MODE_UNKNOWN
Definition: af_xdp.h:55
af_xdp_device_t::txqs
af_xdp_txq_t * txqs
Definition: af_xdp.h:98
af_xdp_tx_func_error_t
af_xdp_tx_func_error_t
Definition: af_xdp.h:191
af_xdp_device_t::buffer_template
vlib_buffer_t * buffer_template
Definition: af_xdp.h:99
af_xdp_main_t::log_class
vlib_log_class_t log_class
Definition: af_xdp.h:129
af_xdp_input_trace_t::hw_if_index
u32 hw_if_index
Definition: af_xdp.h:183
af_xdp_main
af_xdp_main_t af_xdp_main
Definition: device.c:34
AF_XDP_MODE_COPY
@ AF_XDP_MODE_COPY
Definition: af_xdp.h:138
af_xdp_txq_t::xsk_fd
int xsk_fd
Definition: af_xdp.h:88
af_xdp_rxq_t::syscall_lock
clib_spinlock_t syscall_lock
Definition: af_xdp.h:66
af_xdp_create_if_args_t::linux_ifname
char * linux_ifname
Definition: af_xdp.h:149
log.h
clib_spinlock_s
Definition: lock.h:51
uword
u64 uword
Definition: types.h:112
af_xdp_device_t
Definition: af_xdp.h:91
interface.h
af_xdp_device_t::bpf_obj
struct bpf_object * bpf_obj
Definition: af_xdp.h:119
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
af_xdp_create_if_args_t::rxq_num
u32 rxq_num
Definition: af_xdp.h:156
af_xdp_create_if_args_t::name
char * name
Definition: af_xdp.h:150
af_xdp_device_t::flags
u32 flags
Definition: af_xdp.h:103
unformat_af_xdp_create_if_args
unformat_function_t unformat_af_xdp_create_if_args
Definition: af_xdp.h:178
af_xdp_create_if_args_t::rv
int rv
Definition: af_xdp.h:159
af_xdp_create_if_args_t::txq_size
u32 txq_size
Definition: af_xdp.h:155
af_xdp_rxq_t::file_index
uword file_index
Definition: af_xdp.h:73
AF_XDP_RXQ_MODE_INTERRUPT
@ AF_XDP_RXQ_MODE_INTERRUPT
Definition: af_xdp.h:57
format_function_t
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
af_xdp_create_if_args_t::error
clib_error_t * error
Definition: af_xdp.h:161
af_xdp_device_t::linux_ifname
char * linux_ifname
Definition: af_xdp.h:110
af_xdp_device_input_refill
void af_xdp_device_input_refill(af_xdp_device_t *ad)
Definition: input.c:347
af_xdp_create_if
void af_xdp_create_if(vlib_main_t *vm, af_xdp_create_if_args_t *args)
Definition: device.c:386
af_xdp_create_if_args_t
Definition: af_xdp.h:147
u32
unsigned int u32
Definition: types.h:88
foreach_af_xdp_device_flags
#define foreach_af_xdp_device_flags
Definition: af_xdp.h:30
af_xdp_device_t::hw_if_index
u32 hw_if_index
Definition: af_xdp.h:102
format_af_xdp_device
format_function_t format_af_xdp_device
Definition: af_xdp.h:173
AF_XDP_MODE_ZERO_COPY
@ AF_XDP_MODE_ZERO_COPY
Definition: af_xdp.h:139
unformat_function_t
uword() unformat_function_t(unformat_input_t *input, va_list *args)
Definition: format.h:225
af_xdp_rxq_t::queue_index
u32 queue_index
Definition: af_xdp.h:74
vlib_main_t
Definition: main.h:102
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
af_xdp_device_t::txq_num
u8 txq_num
Definition: af_xdp.h:105
af_xdp_rxq_t
Definition: af_xdp.h:60
af_xdp_input_node
vlib_node_registration_t af_xdp_input_node
(constructor) VLIB_REGISTER_NODE (af_xdp_input_node)
Definition: input.c:357
af_xdp_device_t::sw_if_index
u32 sw_if_index
Definition: af_xdp.h:101
af_xdp_main_t::msg_id_base
u16 msg_id_base
Definition: af_xdp.h:130
af_xdp_device_t::rxq_num
u8 rxq_num
Definition: af_xdp.h:114
af_xdp_device_t::per_interface_next_index
u32 per_interface_next_index
Definition: af_xdp.h:100
af_xdp_input_trace_t::next_index
u32 next_index
Definition: af_xdp.h:182
af_xdp_txq_t
Definition: af_xdp.h:78
foreach_af_xdp_tx_func_error
#define foreach_af_xdp_tx_func_error
Definition: af_xdp.h:186
AF_XDP_RXQ_MODE_POLLING
@ AF_XDP_RXQ_MODE_POLLING
Definition: af_xdp.h:56
AF_XDP_CREATE_FLAGS_NO_SYSCALL_LOCK
@ AF_XDP_CREATE_FLAGS_NO_SYSCALL_LOCK
Definition: af_xdp.h:144
af_xdp_create_if_args_t::sw_if_index
u32 sw_if_index
Definition: af_xdp.h:160
af_xdp_device_t::dev_instance
u32 dev_instance
Definition: af_xdp.h:111
af_xdp_txq_t::lock
clib_spinlock_t lock
Definition: af_xdp.h:84
af_xdp_device_t::name
char * name
Definition: af_xdp.h:109
af_xdp_device_t::linux_ifindex
unsigned linux_ifindex
Definition: af_xdp.h:120
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
af_xdp_device_t::error
clib_error_t * error
Definition: af_xdp.h:123