FD.io VPP  v19.08-27-gf4dcae4
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  avf_main_t *am = &avf_main;
88  avf_device_t *ad;
89  vnet_main_t *vnm = vnet_get_main ();
90 
91  /* Get a line of input. */
92  if (!unformat_user (input, unformat_line_input, line_input))
93  return 0;
94 
95  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
96  {
97  if (unformat (line_input, "sw_if_index %d", &sw_if_index))
98  ;
99  else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
100  vnm, &sw_if_index))
101  ;
102  else
103  return clib_error_return (0, "unknown input `%U'",
104  format_unformat_error, input);
105  }
106  unformat_free (line_input);
107 
108  if (sw_if_index == ~0)
109  return clib_error_return (0,
110  "please specify interface name or sw_if_index");
111 
112  hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
113  if (hw == NULL || avf_device_class.index != hw->dev_class_index)
114  return clib_error_return (0, "not an AVF interface");
115 
116  ad = pool_elt_at_index (am->devices, hw->dev_instance);
117 
118  avf_delete_if (vm, ad);
119 
120  return 0;
121 }
122 
123 /* *INDENT-OFF* */
124 VLIB_CLI_COMMAND (avf_delete_command, static) = {
125  .path = "delete interface avf",
126  .short_help = "delete interface avf "
127  "{<interface> | sw_if_index <sw_idx>}",
128  .function = avf_delete_command_fn,
129 };
130 /* *INDENT-ON* */
131 
132 static clib_error_t *
134  vlib_cli_command_t * cmd)
135 {
136  unformat_input_t _line_input, *line_input = &_line_input;
137  u32 sw_if_index = ~0;
139  avf_main_t *am = &avf_main;
140  avf_device_t *ad;
141  vnet_main_t *vnm = vnet_get_main ();
142  int test_irq = 0, enable_elog = 0, disable_elog = 0;
143 
144  /* Get a line of input. */
145  if (!unformat_user (input, unformat_line_input, line_input))
146  return 0;
147 
148  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
149  {
150  if (unformat (line_input, "sw_if_index %d", &sw_if_index))
151  ;
152  else if (unformat (line_input, "irq"))
153  test_irq = 1;
154  else if (unformat (line_input, "elog-on"))
155  enable_elog = 1;
156  else if (unformat (line_input, "elog-off"))
157  disable_elog = 1;
158  else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
159  vnm, &sw_if_index))
160  ;
161  else
162  return clib_error_return (0, "unknown input `%U'",
163  format_unformat_error, input);
164  }
165  unformat_free (line_input);
166 
167  if (sw_if_index == ~0)
168  return clib_error_return (0,
169  "please specify interface name or sw_if_index");
170 
171  hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
172  if (hw == NULL || avf_device_class.index != hw->dev_class_index)
173  return clib_error_return (0, "not a AVF interface");
174 
175  ad = pool_elt_at_index (am->devices, hw->dev_instance);
176 
177  if (enable_elog)
178  ad->flags |= AVF_DEVICE_F_ELOG;
179 
180  if (disable_elog)
181  ad->flags &= ~AVF_DEVICE_F_ELOG;
182 
183  if (test_irq)
184  avf_reg_write (ad, AVFINT_DYN_CTL0, (1 << 0) | (3 << 3) | (1 << 2));
185 
186  return 0;
187 }
188 
189 /* *INDENT-OFF* */
190 VLIB_CLI_COMMAND (avf_test_command, static) = {
191  .path = "test avf",
192  .short_help = "test avf [<interface> | sw_if_index <sw_idx>] [irq] "
193  "[elog-on] [elog-off]",
194  .function = avf_test_command_fn,
195 };
196 /* *INDENT-ON* */
197 
198 clib_error_t *
200 {
201  return 0;
202 }
203 
205 
206 /*
207  * fd.io coding-style-patch-verification: ON
208  *
209  * Local Variables:
210  * eval: (c-set-style "gnu")
211  * End:
212  */
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
static clib_error_t * avf_test_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:133
#define NULL
Definition: clib.h:58
vlib_pci_addr_t addr
Definition: avf.h:227
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
unformat_function_t unformat_vnet_sw_interface
avf_device_t * devices
Definition: avf.h:217
vnet_device_class_t avf_device_class
vl_api_interface_index_t sw_if_index
Definition: gre.api:50
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
#define clib_error_return(e, args...)
Definition: error.h:99
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
unsigned int u32
Definition: types.h:88
unformat_function_t unformat_line_input
Definition: format.h:283
void avf_create_if(vlib_main_t *vm, avf_create_if_args_t *args)
Definition: device.c:1300
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
struct _unformat_input_t unformat_input_t
unformat_function_t unformat_vlib_pci_addr
Definition: pci.h:323
clib_error_t * avf_cli_init(vlib_main_t *vm)
Definition: cli.c:199
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
vlib_main_t * vm
Definition: buffer.c:312
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
static vnet_hw_interface_t * vnet_get_sup_hw_interface_api_visible_or_null(vnet_main_t *vnm, u32 sw_if_index)
#define AVFINT_DYN_CTL0
Definition: virtchnl.h:38
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:155
u32 flags
Definition: avf.h:142
static void avf_reg_write(avf_device_t *ad, u32 addr, u32 val)
Definition: avf.h:291
avf_main_t avf_main
Definition: device.c:37
void avf_delete_if(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:1243
static void unformat_free(unformat_input_t *i)
Definition: format.h:163
clib_error_t * error
Definition: avf.h:236
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
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:171