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 *------------------------------------------------------------------
19 #include <sys/ioctl.h>
22 #include <vlib/vlib.h>
23 #include <vlib/unix/unix.h>
24 #include <vlib/pci/pci.h>
25 #include <vnet/ethernet/ethernet.h>
27 #include <af_xdp/af_xdp.h>
30 af_xdp_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
31 vlib_cli_command_t * cmd)
33 af_xdp_create_if_args_t args;
35 if (!unformat_user (input, unformat_af_xdp_create_if_args, &args))
36 return clib_error_return (0, "unknown input `%U'",
37 format_unformat_error, input);
39 af_xdp_create_if (vm, &args);
41 vec_free (args.linux_ifname);
44 vec_free (args.netns);
49 VLIB_CLI_COMMAND (af_xdp_create_command, static) = {
50 .path = "create interface af_xdp",
52 "create interface af_xdp <host-if linux-ifname> [name ifname] "
53 "[rx-queue-size size] [tx-queue-size size] [num-rx-queues <num|all>] "
54 "[prog pathname] [netns ns] [zero-copy|no-zero-copy] [no-syscall-lock]",
55 .function = af_xdp_create_command_fn,
59 af_xdp_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
60 vlib_cli_command_t * cmd)
62 unformat_input_t _line_input, *line_input = &_line_input;
64 vnet_hw_interface_t *hw;
65 af_xdp_main_t *am = &af_xdp_main;
67 vnet_main_t *vnm = vnet_get_main ();
69 /* Get a line of input. */
70 if (!unformat_user (input, unformat_line_input, line_input))
73 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
75 if (unformat (line_input, "sw_if_index %d", &sw_if_index))
77 else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
81 return clib_error_return (0, "unknown input `%U'",
82 format_unformat_error, input);
84 unformat_free (line_input);
86 if (sw_if_index == ~0)
87 return clib_error_return (0,
88 "please specify interface name or sw_if_index");
90 hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
91 if (hw == NULL || af_xdp_device_class.index != hw->dev_class_index)
92 return clib_error_return (0, "not an AVF interface");
94 ad = pool_elt_at_index (am->devices, hw->dev_instance);
96 af_xdp_delete_if (vm, ad);
101 VLIB_CLI_COMMAND (af_xdp_delete_command, static) = {
102 .path = "delete interface af_xdp",
103 .short_help = "delete interface af_xdp "
104 "{<interface> | sw_if_index <sw_idx>}",
105 .function = af_xdp_delete_command_fn,
109 af_xdp_cli_init (vlib_main_t * vm)
114 VLIB_INIT_FUNCTION (af_xdp_cli_init);
117 * fd.io coding-style-patch-verification: ON
120 * eval: (c-set-style "gnu")