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_log(lvl, dev, f, ...) \
26 vlib_log(lvl, af_xdp_main.log_class, "%v: " f, (dev)->name, ##__VA_ARGS__)
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") \
37 #define _(a, b, c) AF_XDP_DEVICE_F_##b = (1 << a),
38 foreach_af_xdp_device_flags
42 #define af_xdp_device_error(dev, fmt, ...) \
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_); \
52 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
54 /* fields below are accessed in data-plane (hot) */
56 struct xsk_ring_cons rx;
57 struct xsk_ring_prod fq;
60 /* fields below are accessed in control-plane only (cold) */
67 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
69 /* fields below are accessed in data-plane (hot) */
72 struct xsk_ring_prod tx;
73 struct xsk_ring_cons cq;
79 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
81 /* fields below are accessed in data-plane (hot) */
85 vlib_buffer_t *buffer_template;
86 u32 per_interface_next_index;
90 u8 pool; /* buffer pool index */
93 /* fields below are accessed in control-plane only (cold) */
100 struct xsk_umem **umem;
101 struct xsk_socket **xsk;
103 struct bpf_object *bpf_obj;
104 unsigned linux_ifindex;
112 af_xdp_device_t *devices;
113 vlib_log_class_t log_class;
117 extern af_xdp_main_t af_xdp_main;
121 AF_XDP_MODE_AUTO = 0,
122 AF_XDP_MODE_COPY = 1,
123 AF_XDP_MODE_ZERO_COPY = 2,
140 } af_xdp_create_if_args_t;
142 void af_xdp_create_if (vlib_main_t * vm, af_xdp_create_if_args_t * args);
143 void af_xdp_delete_if (vlib_main_t * vm, af_xdp_device_t * ad);
145 extern vlib_node_registration_t af_xdp_input_node;
146 extern vnet_device_class_t af_xdp_device_class;
149 format_function_t format_af_xdp_device;
150 format_function_t format_af_xdp_device_name;
151 format_function_t format_af_xdp_input_trace;
154 unformat_function_t unformat_af_xdp_create_if_args;
160 } af_xdp_input_trace_t;
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")
169 #define _(f,s) AF_XDP_TX_ERROR_##f,
170 foreach_af_xdp_tx_func_error
173 } af_xdp_tx_func_error_t;
175 #endif /* _AF_XDP_H_ */
178 * fd.io coding-style-patch-verification: ON
181 * eval: (c-set-style "gnu")