FD.io VPP  v21.01.1
Vector Packet Processing
cli.c
Go to the documentation of this file.
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 *
31  vlib_cli_command_t * cmd)
32 {
33  unformat_input_t _line_input, *line_input = &_line_input;
35  u32 tmp;
36 
37  clib_memset (&args, 0, sizeof (avf_create_if_args_t));
38 
39  /* Get a line of input. */
40  if (!unformat_user (input, unformat_line_input, line_input))
41  return 0;
42 
43  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
44  {
45  if (unformat (line_input, "%U", unformat_vlib_pci_addr, &args.addr))
46  ;
47  else if (unformat (line_input, "elog"))
48  args.enable_elog = 1;
49  else if (unformat (line_input, "rx-queue-size %u", &tmp))
50  args.rxq_size = tmp;
51  else if (unformat (line_input, "tx-queue-size %u", &tmp))
52  args.txq_size = tmp;
53  else if (unformat (line_input, "num-rx-queues %u", &tmp))
54  args.rxq_num = tmp;
55  else if (unformat (line_input, "name %s", &args.name))
56  ;
57  else
58  return clib_error_return (0, "unknown input `%U'",
59  format_unformat_error, input);
60  }
61  unformat_free (line_input);
62 
63  avf_create_if (vm, &args);
64 
65  vec_free (args.name);
66 
67  return args.error;
68 }
69 
70 /* *INDENT-OFF* */
71 VLIB_CLI_COMMAND (avf_create_command, static) = {
72  .path = "create interface avf",
73  .short_help = "create interface avf <pci-address> "
74  "[rx-queue-size <size>] [tx-queue-size <size>] "
75  "[num-rx-queues <size>]",
76  .function = avf_create_command_fn,
77 };
78 /* *INDENT-ON* */
79 
80 static clib_error_t *
82  vlib_cli_command_t * cmd)
83 {
84  unformat_input_t _line_input, *line_input = &_line_input;
85  u32 sw_if_index = ~0;
87  vnet_main_t *vnm = vnet_get_main ();
88 
89  /* Get a line of input. */
90  if (!unformat_user (input, unformat_line_input, line_input))
91  return 0;
92 
93  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
94  {
95  if (unformat (line_input, "sw_if_index %d", &sw_if_index))
96  ;
97  else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
98  vnm, &sw_if_index))
99  ;
100  else
101  return clib_error_return (0, "unknown input `%U'",
102  format_unformat_error, input);
103  }
104  unformat_free (line_input);
105 
106  if (sw_if_index == ~0)
107  return clib_error_return (0,
108  "please specify interface name or sw_if_index");
109 
110  hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
111  if (hw == NULL || avf_device_class.index != hw->dev_class_index)
112  return clib_error_return (0, "not an AVF interface");
113 
116 
117  return 0;
118 }
119 
120 /* *INDENT-OFF* */
121 VLIB_CLI_COMMAND (avf_delete_command, static) = {
122  .path = "delete interface avf",
123  .short_help = "delete interface avf "
124  "{<interface> | sw_if_index <sw_idx>}",
125  .function = avf_delete_command_fn,
126  .is_mp_safe = 1,
127 };
128 /* *INDENT-ON* */
129 
130 static clib_error_t *
132  vlib_cli_command_t * cmd)
133 {
134  unformat_input_t _line_input, *line_input = &_line_input;
135  u32 sw_if_index = ~0;
137  avf_device_t *ad;
138  vnet_main_t *vnm = vnet_get_main ();
139  int test_irq = 0, enable_elog = 0, disable_elog = 0;
140 
141  /* Get a line of input. */
142  if (!unformat_user (input, unformat_line_input, line_input))
143  return 0;
144 
145  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
146  {
147  if (unformat (line_input, "sw_if_index %d", &sw_if_index))
148  ;
149  else if (unformat (line_input, "irq"))
150  test_irq = 1;
151  else if (unformat (line_input, "elog-on"))
152  enable_elog = 1;
153  else if (unformat (line_input, "elog-off"))
154  disable_elog = 1;
155  else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
156  vnm, &sw_if_index))
157  ;
158  else
159  return clib_error_return (0, "unknown input `%U'",
160  format_unformat_error, input);
161  }
162  unformat_free (line_input);
163 
164  if (sw_if_index == ~0)
165  return clib_error_return (0,
166  "please specify interface name or sw_if_index");
167 
168  hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
169  if (hw == NULL || avf_device_class.index != hw->dev_class_index)
170  return clib_error_return (0, "not a AVF interface");
171 
172  ad = avf_get_device (hw->dev_instance);
173 
174  if (enable_elog)
175  ad->flags |= AVF_DEVICE_F_ELOG;
176 
177  if (disable_elog)
178  ad->flags &= ~AVF_DEVICE_F_ELOG;
179 
180  if (test_irq)
181  avf_reg_write (ad, AVFINT_DYN_CTL0, (1 << 0) | (3 << 3) | (1 << 2));
182 
183  return 0;
184 }
185 
186 /* *INDENT-OFF* */
187 VLIB_CLI_COMMAND (avf_test_command, static) = {
188  .path = "test avf",
189  .short_help = "test avf [<interface> | sw_if_index <sw_idx>] [irq] "
190  "[elog-on] [elog-off]",
191  .function = avf_test_command_fn,
192 };
193 /* *INDENT-ON* */
194 
195 clib_error_t *
197 {
198  return 0;
199 }
200 
202 
203 /*
204  * fd.io coding-style-patch-verification: ON
205  *
206  * Local Variables:
207  * eval: (c-set-style "gnu")
208  * End:
209  */
clib_error_t * avf_cli_init(vlib_main_t *vm)
Definition: cli.c:196
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_pci_addr_t addr
Definition: avf.h:287
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
vlib_main_t * vm
Definition: in2out_ed.c:1580
unformat_function_t unformat_vnet_sw_interface
vnet_device_class_t avf_device_class
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
#define clib_error_return(e, args...)
Definition: error.h:99
static clib_error_t * avf_test_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:131
unsigned int u32
Definition: types.h:88
unformat_function_t unformat_line_input
Definition: format.h:282
void avf_create_if(vlib_main_t *vm, avf_create_if_args_t *args)
Definition: device.c:1508
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:1015
struct _unformat_input_t unformat_input_t
unformat_function_t unformat_vlib_pci_addr
Definition: pci.h:325
vlib_node_registration_t avf_process_node
(constructor) VLIB_REGISTER_NODE (avf_process_node)
Definition: device.c:1326
#define UNFORMAT_END_OF_INPUT
Definition: format.h:144
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:380
static vnet_hw_interface_t * vnet_get_sup_hw_interface_api_visible_or_null(vnet_main_t *vnm, u32 sw_if_index)
static_always_inline avf_device_t * avf_get_device(u32 dev_instance)
Definition: avf.h:311
#define AVFINT_DYN_CTL0
Definition: virtchnl.h:38
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:158
u32 flags
Definition: avf.h:186
static void avf_reg_write(avf_device_t *ad, u32 addr, u32 val)
Definition: avf.h:357
static clib_error_t * avf_delete_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:81
static void unformat_free(unformat_input_t *i)
Definition: format.h:162
clib_error_t * error
Definition: avf.h:296
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
static clib_error_t * avf_create_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:30
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:170