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;
36 memset (&args, 0, sizeof (avf_create_if_args_t));
38 /* Get a line of input. */
39 if (!unformat_user (input, unformat_line_input, line_input))
42 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
44 if (unformat (line_input, "%U", unformat_vlib_pci_addr, &args.addr))
46 else if (unformat (line_input, "elog"))
49 return clib_error_return (0, "unknown input `%U'",
50 format_unformat_error, input);
52 unformat_free (line_input);
55 avf_create_if (vm, &args);
61 VLIB_CLI_COMMAND (avf_create_command, static) = {
62 .path = "create interface avf",
63 .short_help = "create interface avf <pci-address>",
64 .function = avf_create_command_fn,
69 avf_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
70 vlib_cli_command_t * cmd)
72 unformat_input_t _line_input, *line_input = &_line_input;
74 vnet_hw_interface_t *hw;
75 avf_main_t *am = &avf_main;
77 vnet_main_t *vnm = vnet_get_main ();
79 /* Get a line of input. */
80 if (!unformat_user (input, unformat_line_input, line_input))
83 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
85 if (unformat (line_input, "sw_if_index %d", &sw_if_index))
87 else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
91 return clib_error_return (0, "unknown input `%U'",
92 format_unformat_error, input);
94 unformat_free (line_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 (vnm, sw_if_index);
101 if (hw == NULL || avf_device_class.index != hw->dev_class_index)
102 return clib_error_return (0, "not a AVF interface");
104 ad = pool_elt_at_index (am->devices, hw->dev_instance);
106 avf_delete_if (vm, ad);
112 VLIB_CLI_COMMAND (avf_delete_command, static) = {
113 .path = "delete interface avf",
114 .short_help = "delete interface avf "
115 "{<interface> | sw_if_index <sw_idx>}",
116 .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 unformat_input_t _line_input, *line_input = &_line_input;
125 u32 sw_if_index = ~0;
126 vnet_hw_interface_t *hw;
127 avf_main_t *am = &avf_main;
129 vnet_main_t *vnm = vnet_get_main ();
130 int test_irq = 0, enable_elog = 0, disable_elog = 0;
132 /* Get a line of input. */
133 if (!unformat_user (input, unformat_line_input, line_input))
136 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
138 if (unformat (line_input, "sw_if_index %d", &sw_if_index))
140 else if (unformat (line_input, "irq"))
142 else if (unformat (line_input, "elog-on"))
144 else if (unformat (line_input, "elog-off"))
146 else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
150 return clib_error_return (0, "unknown input `%U'",
151 format_unformat_error, input);
153 unformat_free (line_input);
155 if (sw_if_index == ~0)
156 return clib_error_return (0,
157 "please specify interface name or sw_if_index");
159 hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
160 if (hw == NULL || avf_device_class.index != hw->dev_class_index)
161 return clib_error_return (0, "not a AVF interface");
163 ad = pool_elt_at_index (am->devices, hw->dev_instance);
166 ad->flags |= AVF_DEVICE_F_ELOG;
169 ad->flags &= ~AVF_DEVICE_F_ELOG;
172 avf_reg_write (ad, AVFINT_DYN_CTL0, (1 << 0) | (3 << 3) | (1 << 2));
178 VLIB_CLI_COMMAND (avf_test_command, static) = {
180 .short_help = "test avf [<interface> | sw_if_index <sw_idx>] [irq] "
181 "[elog-on] [elog-off]",
182 .function = avf_test_command_fn,
187 avf_cli_init (vlib_main_t * vm)
192 VLIB_INIT_FUNCTION (avf_cli_init);
195 * fd.io coding-style-patch-verification: ON
198 * eval: (c-set-style "gnu")