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);
66 VLIB_CLI_COMMAND (avf_create_command, static) = {
67 .path = "create interface avf",
68 .short_help = "create interface avf <pci-address> "
69 "[rx-queue-size <size>] [tx-queue-size <size>] "
70 "[num-rx-queues <size>]",
71 .function = avf_create_command_fn,
75 avf_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
76 vlib_cli_command_t * cmd)
79 vnet_hw_interface_t *hw;
80 vnet_main_t *vnm = vnet_get_main ();
82 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
84 if (unformat (input, "sw_if_index %d", &sw_if_index))
86 else if (unformat (input, "%U", unformat_vnet_sw_interface, vnm,
90 return clib_error_return (0, "unknown input `%U'",
91 format_unformat_error, input);
94 if (sw_if_index == ~0)
95 return clib_error_return (0,
96 "please specify interface name or sw_if_index");
98 hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
99 if (hw == NULL || avf_device_class.index != hw->dev_class_index)
100 return clib_error_return (0, "not an AVF interface");
102 vlib_process_signal_event (vm, avf_process_node.index,
103 AVF_PROCESS_EVENT_DELETE_IF, hw->dev_instance);
108 VLIB_CLI_COMMAND (avf_delete_command, static) = {
109 .path = "delete interface avf",
110 .short_help = "delete interface avf "
111 "{<interface> | sw_if_index <sw_idx>}",
112 .function = avf_delete_command_fn,
116 static clib_error_t *
117 avf_test_command_fn (vlib_main_t * vm, unformat_input_t * input,
118 vlib_cli_command_t * cmd)
120 u32 sw_if_index = ~0;
121 vnet_hw_interface_t *hw;
123 vnet_main_t *vnm = vnet_get_main ();
124 int test_irq = 0, enable_elog = 0, disable_elog = 0;
126 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
128 if (unformat (input, "sw_if_index %d", &sw_if_index))
130 else if (unformat (input, "irq"))
132 else if (unformat (input, "elog-on"))
134 else if (unformat (input, "elog-off"))
136 else if (unformat (input, "%U", unformat_vnet_sw_interface, vnm,
140 return clib_error_return (0, "unknown input `%U'",
141 format_unformat_error, input);
144 if (sw_if_index == ~0)
145 return clib_error_return (0,
146 "please specify interface name or sw_if_index");
148 hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
149 if (hw == NULL || avf_device_class.index != hw->dev_class_index)
150 return clib_error_return (0, "not a AVF interface");
152 ad = avf_get_device (hw->dev_instance);
155 ad->flags |= AVF_DEVICE_F_ELOG;
158 ad->flags &= ~AVF_DEVICE_F_ELOG;
161 avf_reg_write (ad, AVFINT_DYN_CTL0, (1 << 0) | (3 << 3) | (1 << 2));
166 VLIB_CLI_COMMAND (avf_test_command, static) = {
168 .short_help = "test avf [<interface> | sw_if_index <sw_idx>] [irq] "
169 "[elog-on] [elog-off]",
170 .function = avf_test_command_fn,
174 avf_cli_init (vlib_main_t * vm)
179 VLIB_INIT_FUNCTION (avf_cli_init);
182 * fd.io coding-style-patch-verification: ON
185 * eval: (c-set-style "gnu")