FD.io VPP  v18.10-34-gcce845e
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  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
56  return clib_error_return (0, "unknown input `%U'",
57  format_unformat_error, input);
58  }
59  unformat_free (line_input);
60 
61  avf_create_if (vm, &args);
62 
63  return args.error;
64 }
65 
66 /* *INDENT-OFF* */
67 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 *
78  vlib_cli_command_t * cmd)
79 {
80  unformat_input_t _line_input, *line_input = &_line_input;
81  u32 sw_if_index = ~0;
83  avf_main_t *am = &avf_main;
84  avf_device_t *ad;
85  vnet_main_t *vnm = vnet_get_main ();
86 
87  /* Get a line of input. */
88  if (!unformat_user (input, unformat_line_input, line_input))
89  return 0;
90 
91  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
92  {
93  if (unformat (line_input, "sw_if_index %d", &sw_if_index))
94  ;
95  else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
96  vnm, &sw_if_index))
97  ;
98  else
99  return clib_error_return (0, "unknown input `%U'",
100  format_unformat_error, input);
101  }
102  unformat_free (line_input);
103 
104  if (sw_if_index == ~0)
105  return clib_error_return (0,
106  "please specify interface name or sw_if_index");
107 
108  hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
109  if (hw == NULL || avf_device_class.index != hw->dev_class_index)
110  return clib_error_return (0, "not an AVF interface");
111 
112  ad = pool_elt_at_index (am->devices, hw->dev_instance);
113 
114  avf_delete_if (vm, ad);
115 
116  return 0;
117 }
118 
119 /* *INDENT-OFF* */
120 VLIB_CLI_COMMAND (avf_delete_command, static) = {
121  .path = "delete interface avf",
122  .short_help = "delete interface avf "
123  "{<interface> | sw_if_index <sw_idx>}",
124  .function = avf_delete_command_fn,
125 };
126 /* *INDENT-ON* */
127 
128 static clib_error_t *
130  vlib_cli_command_t * cmd)
131 {
132  unformat_input_t _line_input, *line_input = &_line_input;
133  u32 sw_if_index = ~0;
135  avf_main_t *am = &avf_main;
136  avf_device_t *ad;
137  vnet_main_t *vnm = vnet_get_main ();
138  int test_irq = 0, enable_elog = 0, disable_elog = 0;
139 
140  /* Get a line of input. */
141  if (!unformat_user (input, unformat_line_input, line_input))
142  return 0;
143 
144  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
145  {
146  if (unformat (line_input, "sw_if_index %d", &sw_if_index))
147  ;
148  else if (unformat (line_input, "irq"))
149  test_irq = 1;
150  else if (unformat (line_input, "elog-on"))
151  enable_elog = 1;
152  else if (unformat (line_input, "elog-off"))
153  disable_elog = 1;
154  else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
155  vnm, &sw_if_index))
156  ;
157  else
158  return clib_error_return (0, "unknown input `%U'",
159  format_unformat_error, input);
160  }
161  unformat_free (line_input);
162 
163  if (sw_if_index == ~0)
164  return clib_error_return (0,
165  "please specify interface name or sw_if_index");
166 
167  hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
168  if (hw == NULL || avf_device_class.index != hw->dev_class_index)
169  return clib_error_return (0, "not a AVF interface");
170 
171  ad = pool_elt_at_index (am->devices, hw->dev_instance);
172 
173  if (enable_elog)
174  ad->flags |= AVF_DEVICE_F_ELOG;
175 
176  if (disable_elog)
177  ad->flags &= ~AVF_DEVICE_F_ELOG;
178 
179  if (test_irq)
180  avf_reg_write (ad, AVFINT_DYN_CTL0, (1 << 0) | (3 << 3) | (1 << 2));
181 
182  return 0;
183 }
184 
185 /* *INDENT-OFF* */
186 VLIB_CLI_COMMAND (avf_test_command, static) = {
187  .path = "test avf",
188  .short_help = "test avf [<interface> | sw_if_index <sw_idx>] [irq] "
189  "[elog-on] [elog-off]",
190  .function = avf_test_command_fn,
191 };
192 /* *INDENT-ON* */
193 
194 clib_error_t *
196 {
197  return 0;
198 }
199 
201 
202 /*
203  * fd.io coding-style-patch-verification: ON
204  *
205  * Local Variables:
206  * eval: (c-set-style "gnu")
207  * End:
208  */
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
static clib_error_t * avf_test_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:129
#define NULL
Definition: clib.h:57
vlib_pci_addr_t addr
Definition: avf.h:204
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:983
unformat_function_t unformat_vnet_sw_interface
unformat_function_t unformat_vlib_pci_addr
Definition: pci.h:287
avf_device_t * devices
Definition: avf.h:189
vnet_device_class_t avf_device_class
memset(h->entries, 0, sizeof(h->entries[0])*entries)
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
u32 sw_if_index
Definition: vxlan_gbp.api:39
#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:77
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:1174
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:464
struct _unformat_input_t unformat_input_t
clib_error_t * avf_cli_init(vlib_main_t *vm)
Definition: cli.c:195
#define UNFORMAT_END_OF_INPUT
Definition: format.h:144
vlib_main_t * vm
Definition: buffer.c:294
#define AVFINT_DYN_CTL0
Definition: virtchnl.h:28
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:155
u32 flags
Definition: avf.h:106
static void avf_reg_write(avf_device_t *ad, u32 addr, u32 val)
Definition: avf.h:267
avf_main_t avf_main
Definition: device.c:36
void avf_delete_if(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:1119
static void unformat_free(unformat_input_t *i)
Definition: format.h:162
clib_error_t * error
Definition: avf.h:212
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:972
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:170