Line data Source code
1 : /*
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:
7 : *
8 : * http://www.apache.org/licenses/LICENSE-2.0
9 : *
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 : *------------------------------------------------------------------
16 : */
17 : #include <stdint.h>
18 : #include <net/if.h>
19 : #include <sys/ioctl.h>
20 : #include <inttypes.h>
21 :
22 : #include <vlib/vlib.h>
23 : #include <vlib/unix/unix.h>
24 : #include <vlib/pci/pci.h>
25 : #include <vnet/ethernet/ethernet.h>
26 :
27 : #include <avf/avf.h>
28 :
29 : static clib_error_t *
30 0 : avf_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
31 : vlib_cli_command_t * cmd)
32 : {
33 : avf_create_if_args_t args;
34 : u32 tmp;
35 :
36 0 : clib_memset (&args, 0, sizeof (avf_create_if_args_t));
37 :
38 0 : while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
39 : {
40 0 : if (unformat (input, "%U", unformat_vlib_pci_addr, &args.addr))
41 : ;
42 0 : else if (unformat (input, "elog"))
43 0 : args.enable_elog = 1;
44 0 : else if (unformat (input, "rx-queue-size %u", &tmp))
45 0 : args.rxq_size = tmp;
46 0 : else if (unformat (input, "tx-queue-size %u", &tmp))
47 0 : args.txq_size = tmp;
48 0 : else if (unformat (input, "num-rx-queues %u", &tmp))
49 0 : args.rxq_num = tmp;
50 0 : else if (unformat (input, "num-tx-queues %u", &tmp))
51 0 : args.txq_num = tmp;
52 0 : else if (unformat (input, "name %s", &args.name))
53 : ;
54 : else
55 0 : return clib_error_return (0, "unknown input `%U'",
56 : format_unformat_error, input);
57 : }
58 :
59 0 : avf_create_if (vm, &args);
60 :
61 0 : vec_free (args.name);
62 :
63 0 : return args.error;
64 : }
65 :
66 : /* *INDENT-OFF* */
67 256087 : 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,
73 : };
74 : /* *INDENT-ON* */
75 :
76 : static clib_error_t *
77 0 : avf_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
78 : vlib_cli_command_t * cmd)
79 : {
80 0 : u32 sw_if_index = ~0;
81 : vnet_hw_interface_t *hw;
82 0 : vnet_main_t *vnm = vnet_get_main ();
83 :
84 0 : while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
85 : {
86 0 : if (unformat (input, "sw_if_index %d", &sw_if_index))
87 : ;
88 0 : else if (unformat (input, "%U", unformat_vnet_sw_interface, vnm,
89 : &sw_if_index))
90 : ;
91 : else
92 0 : return clib_error_return (0, "unknown input `%U'",
93 : format_unformat_error, input);
94 : }
95 :
96 0 : if (sw_if_index == ~0)
97 0 : return clib_error_return (0,
98 : "please specify interface name or sw_if_index");
99 :
100 0 : hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
101 0 : if (hw == NULL || avf_device_class.index != hw->dev_class_index)
102 0 : return clib_error_return (0, "not an AVF interface");
103 :
104 0 : vlib_process_signal_event (vm, avf_process_node.index,
105 0 : AVF_PROCESS_EVENT_DELETE_IF, hw->dev_instance);
106 :
107 0 : return 0;
108 : }
109 :
110 : /* *INDENT-OFF* */
111 256087 : 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,
116 : .is_mp_safe = 1,
117 : };
118 : /* *INDENT-ON* */
119 :
120 : static clib_error_t *
121 0 : avf_test_command_fn (vlib_main_t * vm, unformat_input_t * input,
122 : vlib_cli_command_t * cmd)
123 : {
124 0 : u32 sw_if_index = ~0;
125 : vnet_hw_interface_t *hw;
126 : avf_device_t *ad;
127 0 : vnet_main_t *vnm = vnet_get_main ();
128 0 : int test_irq = 0, enable_elog = 0, disable_elog = 0;
129 :
130 0 : while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
131 : {
132 0 : if (unformat (input, "sw_if_index %d", &sw_if_index))
133 : ;
134 0 : else if (unformat (input, "irq"))
135 0 : test_irq = 1;
136 0 : else if (unformat (input, "elog-on"))
137 0 : enable_elog = 1;
138 0 : else if (unformat (input, "elog-off"))
139 0 : disable_elog = 1;
140 0 : else if (unformat (input, "%U", unformat_vnet_sw_interface, vnm,
141 : &sw_if_index))
142 : ;
143 : else
144 0 : return clib_error_return (0, "unknown input `%U'",
145 : format_unformat_error, input);
146 : }
147 :
148 0 : if (sw_if_index == ~0)
149 0 : return clib_error_return (0,
150 : "please specify interface name or sw_if_index");
151 :
152 0 : hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
153 0 : if (hw == NULL || avf_device_class.index != hw->dev_class_index)
154 0 : return clib_error_return (0, "not a AVF interface");
155 :
156 0 : ad = avf_get_device (hw->dev_instance);
157 :
158 0 : if (enable_elog)
159 0 : ad->flags |= AVF_DEVICE_F_ELOG;
160 :
161 0 : if (disable_elog)
162 0 : ad->flags &= ~AVF_DEVICE_F_ELOG;
163 :
164 0 : if (test_irq)
165 0 : avf_reg_write (ad, AVFINT_DYN_CTL0, (1 << 0) | (3 << 3) | (1 << 2));
166 :
167 0 : return 0;
168 : }
169 :
170 : /* *INDENT-OFF* */
171 256087 : VLIB_CLI_COMMAND (avf_test_command, static) = {
172 : .path = "test avf",
173 : .short_help = "test avf [<interface> | sw_if_index <sw_idx>] [irq] "
174 : "[elog-on] [elog-off]",
175 : .function = avf_test_command_fn,
176 : };
177 : /* *INDENT-ON* */
178 :
179 : clib_error_t *
180 559 : avf_cli_init (vlib_main_t * vm)
181 : {
182 559 : return 0;
183 : }
184 :
185 1119 : VLIB_INIT_FUNCTION (avf_cli_init);
186 :
187 : /*
188 : * fd.io coding-style-patch-verification: ON
189 : *
190 : * Local Variables:
191 : * eval: (c-set-style "gnu")
192 : * End:
193 : */
|