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 unformat_input_t _line_input, *line_input = &_line_input;
34 avf_create_if_args_t args;
37 clib_memset (&args, 0, sizeof (avf_create_if_args_t));
39 /* Get a line of input. */
40 if (!unformat_user (input, unformat_line_input, line_input))
43 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
45 if (unformat (line_input, "%U", unformat_vlib_pci_addr, &args.addr))
47 else if (unformat (line_input, "elog"))
49 else if (unformat (line_input, "rx-queue-size %u", &tmp))
51 else if (unformat (line_input, "tx-queue-size %u", &tmp))
53 else if (unformat (line_input, "num-rx-queues %u", &tmp))
55 else if (unformat (line_input, "num-tx-queues %u", &tmp))
57 else if (unformat (line_input, "name %s", &args.name))
60 return clib_error_return (0, "unknown input `%U'",
61 format_unformat_error, input);
63 unformat_free (line_input);
65 avf_create_if (vm, &args);
73 VLIB_CLI_COMMAND (avf_create_command, static) = {
74 .path = "create interface avf",
75 .short_help = "create interface avf <pci-address> "
76 "[rx-queue-size <size>] [tx-queue-size <size>] "
77 "[num-rx-queues <size>]",
78 .function = avf_create_command_fn,
83 avf_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
84 vlib_cli_command_t * cmd)
86 unformat_input_t _line_input, *line_input = &_line_input;
88 vnet_hw_interface_t *hw;
89 vnet_main_t *vnm = vnet_get_main ();
91 /* Get a line of input. */
92 if (!unformat_user (input, unformat_line_input, line_input))
95 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
97 if (unformat (line_input, "sw_if_index %d", &sw_if_index))
99 else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
103 return clib_error_return (0, "unknown input `%U'",
104 format_unformat_error, input);
106 unformat_free (line_input);
108 if (sw_if_index == ~0)
109 return clib_error_return (0,
110 "please specify interface name or sw_if_index");
112 hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
113 if (hw == NULL || avf_device_class.index != hw->dev_class_index)
114 return clib_error_return (0, "not an AVF interface");
116 vlib_process_signal_event (vm, avf_process_node.index,
117 AVF_PROCESS_EVENT_DELETE_IF, hw->dev_instance);
123 VLIB_CLI_COMMAND (avf_delete_command, static) = {
124 .path = "delete interface avf",
125 .short_help = "delete interface avf "
126 "{<interface> | sw_if_index <sw_idx>}",
127 .function = avf_delete_command_fn,
132 static clib_error_t *
133 avf_test_command_fn (vlib_main_t * vm, unformat_input_t * input,
134 vlib_cli_command_t * cmd)
136 unformat_input_t _line_input, *line_input = &_line_input;
137 u32 sw_if_index = ~0;
138 vnet_hw_interface_t *hw;
140 vnet_main_t *vnm = vnet_get_main ();
141 int test_irq = 0, enable_elog = 0, disable_elog = 0;
143 /* Get a line of input. */
144 if (!unformat_user (input, unformat_line_input, line_input))
147 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
149 if (unformat (line_input, "sw_if_index %d", &sw_if_index))
151 else if (unformat (line_input, "irq"))
153 else if (unformat (line_input, "elog-on"))
155 else if (unformat (line_input, "elog-off"))
157 else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
161 return clib_error_return (0, "unknown input `%U'",
162 format_unformat_error, input);
164 unformat_free (line_input);
166 if (sw_if_index == ~0)
167 return clib_error_return (0,
168 "please specify interface name or sw_if_index");
170 hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
171 if (hw == NULL || avf_device_class.index != hw->dev_class_index)
172 return clib_error_return (0, "not a AVF interface");
174 ad = avf_get_device (hw->dev_instance);
177 ad->flags |= AVF_DEVICE_F_ELOG;
180 ad->flags &= ~AVF_DEVICE_F_ELOG;
183 avf_reg_write (ad, AVFINT_DYN_CTL0, (1 << 0) | (3 << 3) | (1 << 2));
189 VLIB_CLI_COMMAND (avf_test_command, static) = {
191 .short_help = "test avf [<interface> | sw_if_index <sw_idx>] [irq] "
192 "[elog-on] [elog-off]",
193 .function = avf_test_command_fn,
198 avf_cli_init (vlib_main_t * vm)
203 VLIB_INIT_FUNCTION (avf_cli_init);
206 * fd.io coding-style-patch-verification: ON
209 * eval: (c-set-style "gnu")