FD.io VPP  v21.10.1-2-g0a485f517
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, "num-tx-queues %u", &tmp))
56  args.txq_num = tmp;
57  else if (unformat (line_input, "name %s", &args.name))
58  ;
59  else
60  return clib_error_return (0, "unknown input `%U'",
61  format_unformat_error, input);
62  }
63  unformat_free (line_input);
64 
65  avf_create_if (vm, &args);
66 
67  vec_free (args.name);
68 
69  return args.error;
70 }
71 
72 /* *INDENT-OFF* */
74  .path = "create interface avf",
75  .short_help = "create interface avf <pci-address> "
76  "[rx-queue-size <size>] [tx-queue-size <size>] "
77  "[num-rx-queues <size>]",
78  .function = avf_create_command_fn,
79 };
80 /* *INDENT-ON* */
81 
82 static clib_error_t *
84  vlib_cli_command_t * cmd)
85 {
86  unformat_input_t _line_input, *line_input = &_line_input;
87  u32 sw_if_index = ~0;
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 
113  if (hw == NULL || avf_device_class.index != hw->dev_class_index)
114  return clib_error_return (0, "not an AVF interface");
115 
118 
119  return 0;
120 }
121 
122 /* *INDENT-OFF* */
124  .path = "delete interface avf",
125  .short_help = "delete interface avf "
126  "{<interface> | sw_if_index <sw_idx>}",
127  .function = avf_delete_command_fn,
128  .is_mp_safe = 1,
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_device_t *ad;
140  vnet_main_t *vnm = vnet_get_main ();
141  int test_irq = 0, enable_elog = 0, disable_elog = 0;
142 
143  /* Get a line of input. */
144  if (!unformat_user (input, unformat_line_input, line_input))
145  return 0;
146 
147  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
148  {
149  if (unformat (line_input, "sw_if_index %d", &sw_if_index))
150  ;
151  else if (unformat (line_input, "irq"))
152  test_irq = 1;
153  else if (unformat (line_input, "elog-on"))
154  enable_elog = 1;
155  else if (unformat (line_input, "elog-off"))
156  disable_elog = 1;
157  else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
158  vnm, &sw_if_index))
159  ;
160  else
161  return clib_error_return (0, "unknown input `%U'",
162  format_unformat_error, input);
163  }
164  unformat_free (line_input);
165 
166  if (sw_if_index == ~0)
167  return clib_error_return (0,
168  "please specify interface name or sw_if_index");
169 
171  if (hw == NULL || avf_device_class.index != hw->dev_class_index)
172  return clib_error_return (0, "not a AVF interface");
173 
174  ad = avf_get_device (hw->dev_instance);
175 
176  if (enable_elog)
177  ad->flags |= AVF_DEVICE_F_ELOG;
178 
179  if (disable_elog)
180  ad->flags &= ~AVF_DEVICE_F_ELOG;
181 
182  if (test_irq)
183  avf_reg_write (ad, AVFINT_DYN_CTL0, (1 << 0) | (3 << 3) | (1 << 2));
184 
185  return 0;
186 }
187 
188 /* *INDENT-OFF* */
190  .path = "test avf",
191  .short_help = "test avf [<interface> | sw_if_index <sw_idx>] [irq] "
192  "[elog-on] [elog-off]",
193  .function = avf_test_command_fn,
194 };
195 /* *INDENT-ON* */
196 
197 clib_error_t *
199 {
200  return 0;
201 }
202 
204 
205 /*
206  * fd.io coding-style-patch-verification: ON
207  *
208  * Local Variables:
209  * eval: (c-set-style "gnu")
210  * End:
211  */
vlib.h
avf_create_if_args_t::error
clib_error_t * error
Definition: avf.h:343
tmp
u32 * tmp
Definition: interface_output.c:1096
unformat_user
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
avf_create_command
static vlib_cli_command_t avf_create_command
(constructor) VLIB_CLI_COMMAND (avf_create_command)
Definition: cli.c:73
unformat_line_input
unformat_function_t unformat_line_input
Definition: format.h:275
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
vlib_cli_command_t::path
char * path
Definition: cli.h:96
unformat_vlib_pci_addr
unformat_function_t unformat_vlib_pci_addr
Definition: pci.h:325
avf_create_if_args_t::rxq_size
u16 rxq_size
Definition: avf.h:338
avf_cli_init
clib_error_t * avf_cli_init(vlib_main_t *vm)
Definition: cli.c:198
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
avf_create_if_args_t::enable_elog
int enable_elog
Definition: avf.h:335
unformat_input_t
struct _unformat_input_t unformat_input_t
vnet_hw_interface_t::dev_instance
u32 dev_instance
Definition: interface.h:660
vlib_process_signal_event
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:1019
avf_create_if_args_t
Definition: avf.h:331
avf_device_t
Definition: avf.h:215
avf_device_class
vnet_device_class_t avf_device_class
ethernet.h
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
unformat_free
static void unformat_free(unformat_input_t *i)
Definition: format.h:155
avf_create_if_args_t::addr
vlib_pci_addr_t addr
Definition: avf.h:333
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
avf_delete_command
static vlib_cli_command_t avf_delete_command
(constructor) VLIB_CLI_COMMAND (avf_delete_command)
Definition: cli.c:123
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
vnet_get_sup_hw_interface_api_visible_or_null
static vnet_hw_interface_t * vnet_get_sup_hw_interface_api_visible_or_null(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:101
avf_create_if_args_t::txq_num
u16 txq_num
Definition: avf.h:337
vnet_hw_interface_t::dev_class_index
u32 dev_class_index
Definition: interface.h:659
avf_test_command
static vlib_cli_command_t avf_test_command
(constructor) VLIB_CLI_COMMAND (avf_test_command)
Definition: cli.c:189
avf_create_if_args_t::rxq_num
u16 rxq_num
Definition: avf.h:336
format_unformat_error
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
avf_create_if
void avf_create_if(vlib_main_t *vm, avf_create_if_args_t *args)
Definition: device.c:1589
avf.h
vnet_hw_interface_t
Definition: interface.h:638
vnet_main_t
Definition: vnet.h:76
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
avf_reg_write
static void avf_reg_write(avf_device_t *ad, u32 addr, u32 val)
Definition: avf.h:421
unformat_vnet_sw_interface
unformat_function_t unformat_vnet_sw_interface
Definition: interface_funcs.h:462
avf_process_node
vlib_node_registration_t avf_process_node
(constructor) VLIB_REGISTER_NODE (avf_process_node)
Definition: device.c:1401
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
pci.h
AVFINT_DYN_CTL0
#define AVFINT_DYN_CTL0
Definition: virtchnl.h:38
avf_create_command_fn
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
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
avf_device_t::flags
u32 flags
Definition: avf.h:218
clib_error_t
Definition: clib_error.h:21
unix.h
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
avf_delete_command_fn
static clib_error_t * avf_delete_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:83
AVF_PROCESS_EVENT_DELETE_IF
@ AVF_PROCESS_EVENT_DELETE_IF
Definition: avf.h:275
vlib_cli_command_t
Definition: cli.h:92
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
avf_create_if_args_t::name
u8 * name
Definition: avf.h:334
avf_test_command_fn
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
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137
avf_create_if_args_t::txq_size
u16 txq_size
Definition: avf.h:339
avf_get_device
static_always_inline avf_device_t * avf_get_device(u32 dev_instance)
Definition: avf.h:368