FD.io VPP  v21.06-3-gbb25fbf28
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 <vlib/vlib.h>
18 #include <vlib/unix/unix.h>
19 #include <vlib/pci/pci.h>
20 #include <vnet/ethernet/ethernet.h>
21 #include <vnet/ip/ip4_packet.h>
22 #include <vnet/ip/ip6_packet.h>
25 
26 static clib_error_t *
28  vlib_cli_command_t * cmd)
29 {
30  unformat_input_t _line_input, *line_input = &_line_input;
32  u64 feature_mask = (u64) ~ (0ULL);
33  u32 buffering_size = 0;
34 
35  /* Get a line of input. */
36  if (!unformat_user (input, unformat_line_input, line_input))
37  return 0;
38 
39  memset (&args, 0, sizeof (args));
40  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
41  {
42  if (unformat (line_input, "%U", unformat_vlib_pci_addr, &args.addr))
43  ;
44  else if (unformat (line_input, "feature-mask 0x%llx", &feature_mask))
45  args.features = feature_mask;
46  else if (unformat (line_input, "gso-enabled"))
47  args.gso_enabled = 1;
48  else if (unformat (line_input, "csum-enabled"))
49  args.checksum_offload_enabled = 1;
50  else if (unformat (line_input, "buffering"))
51  {
52  args.virtio_flags |= VIRTIO_FLAG_BUFFERING;
53  if (unformat (line_input, "size %u", &buffering_size))
54  args.buffering_size = buffering_size;
55  }
56  else if (unformat (line_input, "packed"))
57  args.virtio_flags |= VIRTIO_FLAG_PACKED;
58  else
59  return clib_error_return (0, "unknown input `%U'",
60  format_unformat_error, input);
61  }
62  unformat_free (line_input);
63 
64  virtio_pci_create_if (vm, &args);
65 
66  return args.error;
67 }
68 
69 /* *INDENT-OFF* */
71  .path = "create interface virtio",
72  .short_help = "create interface virtio <pci-address> "
73  "[feature-mask <hex-mask>] [gso-enabled] [csum-enabled] "
74  "[buffering [size <buffering-szie>]] [packed]",
75  .function = virtio_pci_create_command_fn,
76 };
77 /* *INDENT-ON* */
78 
79 static clib_error_t *
81  vlib_cli_command_t * cmd)
82 {
83  unformat_input_t _line_input, *line_input = &_line_input;
84  u32 sw_if_index = ~0;
86  virtio_main_t *vim = &virtio_main;
87  virtio_if_t *vif;
88  vnet_main_t *vnm = vnet_get_main ();
89 
90  /* Get a line of input. */
91  if (!unformat_user (input, unformat_line_input, line_input))
92  return 0;
93 
94  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
95  {
96  if (unformat (line_input, "sw_if_index %d", &sw_if_index))
97  ;
98  else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
99  vnm, &sw_if_index))
100  ;
101  else
102  return clib_error_return (0, "unknown input `%U'",
103  format_unformat_error, input);
104  }
105  unformat_free (line_input);
106 
107  if (sw_if_index == ~0)
108  return clib_error_return (0,
109  "please specify interface name or sw_if_index");
110 
112  if (hw == NULL || virtio_device_class.index != hw->dev_class_index)
113  return clib_error_return (0, "not a virtio interface");
114 
115  vif = pool_elt_at_index (vim->interfaces, hw->dev_instance);
116 
117  if (virtio_pci_delete_if (vm, vif) < 0)
118  return clib_error_return (0, "not a virtio pci interface");
119 
120  return 0;
121 }
122 
123 /* *INDENT-OFF* */
125  .path = "delete interface virtio",
126  .short_help = "delete interface virtio "
127  "{<interface> | sw_if_index <sw_idx>}",
128  .function = virtio_pci_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  virtio_main_t *vim = &virtio_main;
140  virtio_if_t *vif;
141  vnet_main_t *vnm = vnet_get_main ();
142  int gso_enabled = 0, checksum_offload_enabled = 0;
143  int offloads_disabled = 0;
144 
145  /* Get a line of input. */
146  if (!unformat_user (input, unformat_line_input, line_input))
147  return 0;
148 
149  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
150  {
151  if (unformat (line_input, "sw_if_index %d", &sw_if_index))
152  ;
153  else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
154  vnm, &sw_if_index))
155  ;
156  else if (unformat (line_input, "gso-enabled"))
157  gso_enabled = 1;
158  else if (unformat (line_input, "csum-offload-enabled"))
159  checksum_offload_enabled = 1;
160  else if (unformat (line_input, "offloads-disabled"))
161  offloads_disabled = 1;
162  else
163  return clib_error_return (0, "unknown input `%U'",
164  format_unformat_error, input);
165  }
166  unformat_free (line_input);
167 
168  if (sw_if_index == ~0)
169  return clib_error_return (0,
170  "please specify interface name or sw_if_index");
171 
173  if (hw == NULL || virtio_device_class.index != hw->dev_class_index)
174  return clib_error_return (0, "not a virtio interface");
175 
176  vif = pool_elt_at_index (vim->interfaces, hw->dev_instance);
177 
179  (vm, vif, gso_enabled, checksum_offload_enabled, offloads_disabled) < 0)
180  return clib_error_return (0, "not able to enable/disable offloads");
181 
182  return 0;
183 }
184 
185 /* *INDENT-OFF* */
187  .path = "set virtio pci",
188  .short_help = "set virtio pci {<interface> | sw_if_index <sw_idx>}"
189  " [gso-enabled | csum-offload-enabled | offloads-disabled]",
190  .function = virtio_pci_enable_command_fn,
191 };
192 /* *INDENT-ON* */
193 
194 static clib_error_t *
196  vlib_cli_command_t * cmd)
197 {
198  virtio_main_t *vim = &virtio_main;
199  vnet_main_t *vnm = &vnet_main;
200  virtio_if_t *vif;
201  clib_error_t *error = 0;
202  u32 hw_if_index, *hw_if_indices = 0;
204  u8 show_descr = 0, show_device_config = 0;
205 
207  {
208  if (unformat
209  (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
210  {
211  hi = vnet_get_hw_interface (vnm, hw_if_index);
212  if (virtio_device_class.index != hi->dev_class_index)
213  {
214  error = clib_error_return (0, "unknown input `%U'",
215  format_unformat_error, input);
216  goto done;
217  }
218  vec_add1 (hw_if_indices, hw_if_index);
219  }
220  else if (unformat (input, "descriptors") || unformat (input, "desc"))
221  show_descr = 1;
222  else if (unformat (input, "debug-device"))
223  show_device_config = 1;
224  else
225  {
226  error = clib_error_return (0, "unknown input `%U'",
227  format_unformat_error, input);
228  goto done;
229  }
230  }
231 
232  if (vec_len (hw_if_indices) == 0)
233  {
234  pool_foreach (vif, vim->interfaces)
235  vec_add1 (hw_if_indices, vif->hw_if_index);
236  }
237  else if (show_device_config)
238  {
239  vif = pool_elt_at_index (vim->interfaces, hi->dev_instance);
240  if (vif->type == VIRTIO_IF_TYPE_PCI)
241  vif->virtio_pci_func->device_debug_config_space (vm, vif);
242  }
243 
244  virtio_show (vm, hw_if_indices, show_descr, VIRTIO_IF_TYPE_PCI);
245 
246 done:
247  vec_free (hw_if_indices);
248  return error;
249 }
250 
251 /* *INDENT-OFF* */
253  .path = "show virtio pci",
254  .short_help = "show virtio pci [<interface>] [descriptors | desc] [debug-device]",
255  .function = show_virtio_pci_fn,
256 };
257 /* *INDENT-ON* */
258 
259 clib_error_t *
261 {
262  return 0;
263 }
264 
266 
267 /*
268  * fd.io coding-style-patch-verification: ON
269  *
270  * Local Variables:
271  * eval: (c-set-style "gnu")
272  * End:
273  */
vlib.h
virtio_device_class
vnet_device_class_t virtio_device_class
pci.h
virtio_pci_create_if
void virtio_pci_create_if(vlib_main_t *vm, virtio_pci_create_if_args_t *args)
Definition: pci.c:1348
unformat_user
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
virtio_pci_delete_command_fn
static clib_error_t * virtio_pci_delete_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:80
virtio.h
unformat_line_input
unformat_function_t unformat_line_input
Definition: format.h:275
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:553
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
virtio_pci_create_if_args_t::gso_enabled
u8 gso_enabled
Definition: pci.h:239
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
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
virtio_pci_enable_command_fn
static clib_error_t * virtio_pci_enable_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:133
hi
vl_api_ip4_address_t hi
Definition: arp.api:37
unformat_input_t
struct _unformat_input_t unformat_input_t
vnet_hw_interface_t::dev_instance
u32 dev_instance
Definition: interface.h:660
virtio_if_t::virtio_pci_func
const virtio_pci_func_t * virtio_pci_func
Definition: virtio.h:210
ethernet.h
error
Definition: cJSON.c:88
virtio_pci_create_if_args_t::features
u64 features
Definition: pci.h:238
ip6_packet.h
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
virtio_main
virtio_main_t virtio_main
Definition: virtio.c:37
pool_foreach
#define pool_foreach(VAR, POOL)
Iterate through pool.
Definition: pool.h:534
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
unformat_free
static void unformat_free(unformat_input_t *i)
Definition: format.h:155
virtio_pci_delete_if
int virtio_pci_delete_if(vlib_main_t *vm, virtio_if_t *vif)
Definition: pci.c:1548
vec_add1
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:606
vnet_get_hw_interface
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
Definition: interface_funcs.h:44
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
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
virtio_pci_delete_command
static vlib_cli_command_t virtio_pci_delete_command
(constructor) VLIB_CLI_COMMAND (virtio_pci_delete_command)
Definition: cli.c:124
virtio_pci_enable_command
static vlib_cli_command_t virtio_pci_enable_command
(constructor) VLIB_CLI_COMMAND (virtio_pci_enable_command)
Definition: cli.c:186
vnet_hw_interface_t::dev_class_index
u32 dev_class_index
Definition: interface.h:659
virtio_pci_create_if_args_t::addr
u32 addr
Definition: pci.h:232
virtio_pci_create_if_args_t::virtio_flags
u32 virtio_flags
Definition: pci.h:242
virtio_pci_create_if_args_t::checksum_offload_enabled
u8 checksum_offload_enabled
Definition: pci.h:240
virtio_pci_create_if_args_t::error
clib_error_t * error
Definition: pci.h:243
virtio_if_t::hw_if_index
u32 hw_if_index
Definition: virtio.h:152
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
virtio_pci_create_command_fn
static clib_error_t * virtio_pci_create_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:27
unformat_vnet_hw_interface
unformat_function_t unformat_vnet_hw_interface
Definition: interface_funcs.h:460
show_virtio_pci_command
static vlib_cli_command_t show_virtio_pci_command
(constructor) VLIB_CLI_COMMAND (show_virtio_pci_command)
Definition: cli.c:252
virtio_pci_create_command
static vlib_cli_command_t virtio_pci_create_command
(constructor) VLIB_CLI_COMMAND (virtio_pci_create_command)
Definition: cli.c:70
ip4_packet.h
virtio_main_t
Definition: virtio.h:214
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
show_virtio_pci_fn
static clib_error_t * show_virtio_pci_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:195
u64
unsigned long u64
Definition: types.h:89
unformat_vnet_sw_interface
unformat_function_t unformat_vnet_sw_interface
Definition: interface_funcs.h:459
virtio_show
void virtio_show(vlib_main_t *vm, u32 *hw_if_indices, u8 show_descr, u32 type)
Definition: virtio.c:298
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
pci.h
virtio_if_t::type
virtio_if_type_t type
Definition: virtio.h:150
virtio_if_t
Definition: virtio.h:128
virtio_main_t::interfaces
virtio_if_t * interfaces
Definition: virtio.h:220
virtio_pci_create_if_args_t
Definition: pci.h:230
vnet_main
vnet_main_t vnet_main
Definition: misc.c:43
vlib_main_t
Definition: main.h:102
u8
unsigned char u8
Definition: types.h:56
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
virtio_pci_enable_disable_offloads
int virtio_pci_enable_disable_offloads(vlib_main_t *vm, virtio_if_t *vif, int gso_enabled, int checksum_offload_enabled, int offloads_disabled)
Definition: pci.c:1630
virtio_pci_cli_init
clib_error_t * virtio_pci_cli_init(vlib_main_t *vm)
Definition: cli.c:260
virtio_pci_create_if_args_t::buffering_size
u32 buffering_size
Definition: pci.h:241
vlib_cli_command_t
Definition: cli.h:92
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137