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