misc: remove GNU Indent directives
[vpp.git] / src / plugins / avf / cli.c
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 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   clib_memset (&args, 0, sizeof (avf_create_if_args_t));
37
38   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
39     {
40       if (unformat (input, "%U", unformat_vlib_pci_addr, &args.addr))
41         ;
42       else if (unformat (input, "elog"))
43         args.enable_elog = 1;
44       else if (unformat (input, "rx-queue-size %u", &tmp))
45         args.rxq_size = tmp;
46       else if (unformat (input, "tx-queue-size %u", &tmp))
47         args.txq_size = tmp;
48       else if (unformat (input, "num-rx-queues %u", &tmp))
49         args.rxq_num = tmp;
50       else if (unformat (input, "num-tx-queues %u", &tmp))
51         args.txq_num = tmp;
52       else if (unformat (input, "name %s", &args.name))
53         ;
54       else
55         return clib_error_return (0, "unknown input `%U'",
56                                   format_unformat_error, input);
57     }
58
59   avf_create_if (vm, &args);
60
61   vec_free (args.name);
62
63   return args.error;
64 }
65
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,
72 };
73
74 static clib_error_t *
75 avf_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
76                        vlib_cli_command_t * cmd)
77 {
78   u32 sw_if_index = ~0;
79   vnet_hw_interface_t *hw;
80   vnet_main_t *vnm = vnet_get_main ();
81
82   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
83     {
84       if (unformat (input, "sw_if_index %d", &sw_if_index))
85         ;
86       else if (unformat (input, "%U", unformat_vnet_sw_interface, vnm,
87                          &sw_if_index))
88         ;
89       else
90         return clib_error_return (0, "unknown input `%U'",
91                                   format_unformat_error, input);
92     }
93
94   if (sw_if_index == ~0)
95     return clib_error_return (0,
96                               "please specify interface name or sw_if_index");
97
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");
101
102   vlib_process_signal_event (vm, avf_process_node.index,
103                              AVF_PROCESS_EVENT_DELETE_IF, hw->dev_instance);
104
105   return 0;
106 }
107
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,
113   .is_mp_safe = 1,
114 };
115
116 static clib_error_t *
117 avf_test_command_fn (vlib_main_t * vm, unformat_input_t * input,
118                      vlib_cli_command_t * cmd)
119 {
120   u32 sw_if_index = ~0;
121   vnet_hw_interface_t *hw;
122   avf_device_t *ad;
123   vnet_main_t *vnm = vnet_get_main ();
124   int test_irq = 0, enable_elog = 0, disable_elog = 0;
125
126   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
127     {
128       if (unformat (input, "sw_if_index %d", &sw_if_index))
129         ;
130       else if (unformat (input, "irq"))
131         test_irq = 1;
132       else if (unformat (input, "elog-on"))
133         enable_elog = 1;
134       else if (unformat (input, "elog-off"))
135         disable_elog = 1;
136       else if (unformat (input, "%U", unformat_vnet_sw_interface, vnm,
137                          &sw_if_index))
138         ;
139       else
140         return clib_error_return (0, "unknown input `%U'",
141                                   format_unformat_error, input);
142     }
143
144   if (sw_if_index == ~0)
145     return clib_error_return (0,
146                               "please specify interface name or sw_if_index");
147
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");
151
152   ad = avf_get_device (hw->dev_instance);
153
154   if (enable_elog)
155     ad->flags |= AVF_DEVICE_F_ELOG;
156
157   if (disable_elog)
158     ad->flags &= ~AVF_DEVICE_F_ELOG;
159
160   if (test_irq)
161     avf_reg_write (ad, AVFINT_DYN_CTL0, (1 << 0) | (3 << 3) | (1 << 2));
162
163   return 0;
164 }
165
166 VLIB_CLI_COMMAND (avf_test_command, static) = {
167   .path = "test avf",
168   .short_help = "test avf [<interface> | sw_if_index <sw_idx>] [irq] "
169     "[elog-on] [elog-off]",
170   .function = avf_test_command_fn,
171 };
172
173 clib_error_t *
174 avf_cli_init (vlib_main_t * vm)
175 {
176   return 0;
177 }
178
179 VLIB_INIT_FUNCTION (avf_cli_init);
180
181 /*
182  * fd.io coding-style-patch-verification: ON
183  *
184  * Local Variables:
185  * eval: (c-set-style "gnu")
186  * End:
187  */