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