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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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 *------------------------------------------------------------------
22 #include <vnet/interface.h>
25 #define AF_XDP_NUM_RX_QUEUES_ALL ((u16)-1)
27 #define af_xdp_log(lvl, dev, f, ...) \
28 vlib_log(lvl, af_xdp_main.log_class, "%v: " f, (dev)->name, ##__VA_ARGS__)
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")
40 #define _(a, b, c) AF_XDP_DEVICE_F_##b = (1 << a),
41 foreach_af_xdp_device_flags
45 #define af_xdp_device_error(dev, fmt, ...) \
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_); \
55 AF_XDP_RXQ_MODE_UNKNOWN,
56 AF_XDP_RXQ_MODE_POLLING,
57 AF_XDP_RXQ_MODE_INTERRUPT,
58 } __clib_packed af_xdp_rxq_mode_t;
62 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
64 /* fields below are accessed in data-plane (hot) */
66 clib_spinlock_t syscall_lock;
67 struct xsk_ring_cons rx;
68 struct xsk_ring_prod fq;
71 /* fields below are accessed in control-plane only (cold) */
75 af_xdp_rxq_mode_t mode;
80 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
82 /* fields below are accessed in data-plane (hot) */
85 clib_spinlock_t syscall_lock;
86 struct xsk_ring_prod tx;
87 struct xsk_ring_cons cq;
90 /* fields below are accessed in control-plane only (cold) */
97 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
99 /* fields below are accessed in data-plane (hot) */
103 vlib_buffer_t *buffer_template;
104 u32 per_interface_next_index;
108 u8 pool; /* buffer pool index */
111 /* fields below are accessed in control-plane only (cold) */
122 struct xsk_umem **umem;
123 struct xsk_socket **xsk;
125 struct bpf_object *bpf_obj;
126 unsigned linux_ifindex;
134 af_xdp_device_t *devices;
135 vlib_log_class_t log_class;
139 extern af_xdp_main_t af_xdp_main;
143 AF_XDP_MODE_AUTO = 0,
144 AF_XDP_MODE_COPY = 1,
145 AF_XDP_MODE_ZERO_COPY = 2,
150 AF_XDP_CREATE_FLAGS_NO_SYSCALL_LOCK = 1,
151 } af_xdp_create_flag_t;
160 af_xdp_create_flag_t flags;
169 } af_xdp_create_if_args_t;
171 void af_xdp_create_if (vlib_main_t * vm, af_xdp_create_if_args_t * args);
172 void af_xdp_delete_if (vlib_main_t * vm, af_xdp_device_t * ad);
174 void af_xdp_device_input_refill (af_xdp_device_t *ad);
176 extern vlib_node_registration_t af_xdp_input_node;
177 extern vnet_device_class_t af_xdp_device_class;
180 format_function_t format_af_xdp_device;
181 format_function_t format_af_xdp_device_name;
182 format_function_t format_af_xdp_input_trace;
185 unformat_function_t unformat_af_xdp_create_if_args;
191 } af_xdp_input_trace_t;
193 #define foreach_af_xdp_tx_func_error \
194 _ (NO_FREE_SLOTS, "no free tx slots") \
195 _ (SYSCALL_REQUIRED, "syscall required") \
196 _ (SYSCALL_FAILURES, "syscall failures")
200 #define _(f,s) AF_XDP_TX_ERROR_##f,
201 foreach_af_xdp_tx_func_error
204 } af_xdp_tx_func_error_t;
206 #endif /* _AF_XDP_H_ */
209 * fd.io coding-style-patch-verification: ON
212 * eval: (c-set-style "gnu")