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>
30 avf_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
31 vlib_cli_command_t * cmd)
33 avf_create_if_args_t args;
36 clib_memset (&args, 0, sizeof (avf_create_if_args_t));
38 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
40 if (unformat (input, "%U", unformat_vlib_pci_addr, &args.addr))
42 else if (unformat (input, "elog"))
44 else if (unformat (input, "rx-queue-size %u", &tmp))
46 else if (unformat (input, "tx-queue-size %u", &tmp))
48 else if (unformat (input, "num-rx-queues %u", &tmp))
50 else if (unformat (input, "num-tx-queues %u", &tmp))
52 else if (unformat (input, "name %s", &args.name))
55 return clib_error_return (0, "unknown input `%U'",
56 format_unformat_error, input);
59 avf_create_if (vm, &args);
67 VLIB_CLI_COMMAND (avf_create_command, static) = {
68 .path = "create interface avf",
69 .short_help = "create interface avf <pci-address> "
70 "[rx-queue-size <size>] [tx-queue-size <size>] "
71 "[num-rx-queues <size>]",
72 .function = avf_create_command_fn,
77 avf_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
78 vlib_cli_command_t * cmd)
81 vnet_hw_interface_t *hw;
82 vnet_main_t *vnm = vnet_get_main ();
84 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
86 if (unformat (input, "sw_if_index %d", &sw_if_index))
88 else if (unformat (input, "%U", unformat_vnet_sw_interface, vnm,
92 return clib_error_return (0, "unknown input `%U'",
93 format_unformat_error, input);
96 if (sw_if_index == ~0)
97 return clib_error_return (0,
98 "please specify interface name or sw_if_index");
100 hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
101 if (hw == NULL || avf_device_class.index != hw->dev_class_index)
102 return clib_error_return (0, "not an AVF interface");
104 vlib_process_signal_event (vm, avf_process_node.index,
105 AVF_PROCESS_EVENT_DELETE_IF, hw->dev_instance);
111 VLIB_CLI_COMMAND (avf_delete_command, static) = {
112 .path = "delete interface avf",
113 .short_help = "delete interface avf "
114 "{<interface> | sw_if_index <sw_idx>}",
115 .function = avf_delete_command_fn,
120 static clib_error_t *
121 avf_test_command_fn (vlib_main_t * vm, unformat_input_t * input,
122 vlib_cli_command_t * cmd)
124 u32 sw_if_index = ~0;
125 vnet_hw_interface_t *hw;
127 vnet_main_t *vnm = vnet_get_main ();
128 int test_irq = 0, enable_elog = 0, disable_elog = 0;
130 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
132 if (unformat (input, "sw_if_index %d", &sw_if_index))
134 else if (unformat (input, "irq"))
136 else if (unformat (input, "elog-on"))
138 else if (unformat (input, "elog-off"))
140 else if (unformat (input, "%U", unformat_vnet_sw_interface, vnm,
144 return clib_error_return (0, "unknown input `%U'",
145 format_unformat_error, input);
148 if (sw_if_index == ~0)
149 return clib_error_return (0,
150 "please specify interface name or sw_if_index");
152 hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
153 if (hw == NULL || avf_device_class.index != hw->dev_class_index)
154 return clib_error_return (0, "not a AVF interface");
156 ad = avf_get_device (hw->dev_instance);
159 ad->flags |= AVF_DEVICE_F_ELOG;
162 ad->flags &= ~AVF_DEVICE_F_ELOG;
165 avf_reg_write (ad, AVFINT_DYN_CTL0, (1 << 0) | (3 << 3) | (1 << 2));
171 VLIB_CLI_COMMAND (avf_test_command, static) = {
173 .short_help = "test avf [<interface> | sw_if_index <sw_idx>] [irq] "
174 "[elog-on] [elog-off]",
175 .function = avf_test_command_fn,
180 avf_cli_init (vlib_main_t * vm)
185 VLIB_INIT_FUNCTION (avf_cli_init);
188 * fd.io coding-style-patch-verification: ON
191 * eval: (c-set-style "gnu")