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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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 *------------------------------------------------------------------
19 #include <sys/ioctl.h>
22 #include <vlib/vlib.h>
23 #include <vlib/unix/unix.h>
24 #include <vlib/pci/pci.h>
25 #include <vnet/ethernet/ethernet.h>
27 #include <vmxnet3/vmxnet3.h>
30 vmxnet3_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
31 vlib_cli_command_t * cmd)
33 unformat_input_t _line_input, *line_input = &_line_input;
34 vmxnet3_create_if_args_t args;
37 /* Get a line of input. */
38 if (!unformat_user (input, unformat_line_input, line_input))
41 clib_memset (&args, 0, sizeof (args));
42 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
44 if (unformat (line_input, "%U", unformat_vlib_pci_addr, &args.addr))
46 else if (unformat (line_input, "gso"))
48 else if (unformat (line_input, "elog"))
50 else if (unformat (line_input, "bind"))
52 else if (unformat (line_input, "rx-queue-size %u", &size))
54 else if (unformat (line_input, "tx-queue-size %u", &size))
56 else if (unformat (line_input, "num-tx-queues %u", &size))
58 else if (unformat (line_input, "num-rx-queues %u", &size))
61 return clib_error_return (0, "unknown input `%U'",
62 format_unformat_error, input);
64 unformat_free (line_input);
67 vmxnet3_create_if (vm, &args);
73 VLIB_CLI_COMMAND (vmxnet3_create_command, static) = {
74 .path = "create interface vmxnet3",
75 .short_help = "create interface vmxnet3 <pci-address>"
76 " [rx-queue-size <size>] [tx-queue-size <size>]"
77 " [num-tx-queues <number>] [num-rx-queues <number>] [bind]"
79 .function = vmxnet3_create_command_fn,
84 vmxnet3_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
85 vlib_cli_command_t * cmd)
87 unformat_input_t _line_input, *line_input = &_line_input;
89 vnet_hw_interface_t *hw;
90 vmxnet3_main_t *vmxm = &vmxnet3_main;
92 vnet_main_t *vnm = vnet_get_main ();
94 /* Get a line of input. */
95 if (!unformat_user (input, unformat_line_input, line_input))
98 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
100 if (unformat (line_input, "sw_if_index %d", &sw_if_index))
102 else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
106 return clib_error_return (0, "unknown input `%U'",
107 format_unformat_error, input);
109 unformat_free (line_input);
111 if (sw_if_index == ~0)
112 return clib_error_return (0,
113 "please specify interface name or sw_if_index");
115 hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
116 if (hw == NULL || vmxnet3_device_class.index != hw->dev_class_index)
117 return clib_error_return (0, "not a vmxnet3 interface");
119 vd = pool_elt_at_index (vmxm->devices, hw->dev_instance);
121 vmxnet3_delete_if (vm, vd);
127 VLIB_CLI_COMMAND (vmxnet3_delete_command, static) = {
128 .path = "delete interface vmxnet3",
129 .short_help = "delete interface vmxnet3 "
130 "{<interface> | sw_if_index <sw_idx>}",
131 .function = vmxnet3_delete_command_fn,
135 static clib_error_t *
136 vmxnet3_test_command_fn (vlib_main_t * vm, unformat_input_t * input,
137 vlib_cli_command_t * cmd)
139 unformat_input_t _line_input, *line_input = &_line_input;
140 u32 sw_if_index = ~0;
141 vnet_hw_interface_t *hw;
142 vmxnet3_main_t *vmxm = &vmxnet3_main;
143 vmxnet3_device_t *vd;
144 vnet_main_t *vnm = vnet_get_main ();
145 int enable_elog = 0, disable_elog = 0;
147 /* Get a line of input. */
148 if (!unformat_user (input, unformat_line_input, line_input))
151 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
153 if (unformat (line_input, "sw_if_index %d", &sw_if_index))
155 else if (unformat (line_input, "elog-on"))
157 else if (unformat (line_input, "elog-off"))
159 else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
163 return clib_error_return (0, "unknown input `%U'",
164 format_unformat_error, input);
166 unformat_free (line_input);
168 if (sw_if_index == ~0)
169 return clib_error_return (0,
170 "please specify interface name or sw_if_index");
172 hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
173 if (hw == NULL || vmxnet3_device_class.index != hw->dev_class_index)
174 return clib_error_return (0, "not a vmxnet3 interface");
176 vd = pool_elt_at_index (vmxm->devices, hw->dev_instance);
179 vd->flags |= VMXNET3_DEVICE_F_ELOG;
182 vd->flags &= ~VMXNET3_DEVICE_F_ELOG;
188 VLIB_CLI_COMMAND (vmxnet3_test_command, static) = {
189 .path = "test vmxnet3",
190 .short_help = "test vmxnet3 <interface> | sw_if_index <sw_idx> [irq] "
191 "[elog-on] [elog-off]",
192 .function = vmxnet3_test_command_fn,
197 show_vmxnet3 (vlib_main_t * vm, u32 * hw_if_indices, u8 show_descr,
198 u8 show_one_table, u32 which, u8 show_one_slot, u32 slot)
201 vmxnet3_device_t *vd;
202 vnet_main_t *vnm = &vnet_main;
203 vmxnet3_main_t *vmxm = &vmxnet3_main;
204 vnet_hw_interface_t *hi;
206 vmxnet3_rx_desc *rxd;
207 vmxnet3_rx_comp *rx_comp;
209 vmxnet3_tx_desc *txd;
210 vmxnet3_tx_comp *tx_comp;
216 for (i = 0; i < vec_len (hw_if_indices); i++)
218 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
219 vd = vec_elt_at_index (vmxm->devices, hi->dev_instance);
220 vlib_cli_output (vm, "Interface: %U (ifindex %d)",
221 format_vnet_hw_if_index_name, vnm, hw_if_indices[i],
223 vlib_cli_output (vm, " Version: %u", vd->version);
224 vlib_cli_output (vm, " GSO enable: %u", vd->gso_enable);
225 vlib_cli_output (vm, " PCI Address: %U", format_vlib_pci_addr,
227 vlib_cli_output (vm, " Mac Address: %U", format_ethernet_address,
229 vlib_cli_output (vm, " hw if index: %u", vd->hw_if_index);
230 vlib_cli_output (vm, " Device instance: %u", vd->dev_instance);
231 vlib_cli_output (vm, " Number of interrupts: %u", vd->num_intrs);
233 vec_foreach_index (qid, vd->rxqs)
235 rxq = vec_elt_at_index (vd->rxqs, qid);
238 vlib_cli_output (vm, " Queue %u (RX)", qid);
239 vlib_cli_output (vm, " RX completion next index %u",
240 rxq->rx_comp_ring.next);
241 vlib_cli_output (vm, " RX completion generation flag 0x%x",
242 rxq->rx_comp_ring.gen);
244 /* RX descriptors tables */
245 for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
247 vmxnet3_rx_ring *ring = &rxq->rx_ring[rid];
250 " ring %u size %u fill %u "
251 "consume %u produce %u", rid,
252 rxq->size, ring->fill, ring->consume,
256 vlib_cli_output (vm, "RX descriptors table");
257 vlib_cli_output (vm, " %5s %18s %10s",
258 "slot", "address", "flags");
259 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
261 rxd = &rxq->rx_desc[rid][desc_idx];
262 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x",
263 desc_idx, rxd->address, rxd->flags);
266 else if (show_one_table)
268 if (((which == VMXNET3_SHOW_RX_DESC0) && (rid == 0)) ||
269 ((which == VMXNET3_SHOW_RX_DESC1) && (rid == 1)))
271 vlib_cli_output (vm, "RX descriptors table");
272 vlib_cli_output (vm, " %5s %18s %10s",
273 "slot", "address", "flags");
276 rxd = &rxq->rx_desc[rid][slot];
277 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x",
278 slot, rxd->address, rxd->flags);
281 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
283 rxd = &rxq->rx_desc[rid][desc_idx];
284 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x",
285 desc_idx, rxd->address,
292 /* RX completion table */
295 vlib_cli_output (vm, "RX completion descriptors table");
296 vlib_cli_output (vm, " %5s %10s %10s %10s %10s",
297 "slot", "index", "rss", "len", "flags");
298 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
300 rx_comp = &rxq->rx_comp[desc_idx];
301 vlib_cli_output (vm, " %5u 0x%08x %10u %10u 0x%08x",
302 desc_idx, rx_comp->index, rx_comp->rss,
303 rx_comp->len, rx_comp->flags);
306 else if (show_one_table)
308 if (which == VMXNET3_SHOW_RX_COMP)
310 vlib_cli_output (vm, "RX completion descriptors table");
311 vlib_cli_output (vm, " %5s %10s %10s %10s %10s",
312 "slot", "index", "rss", "len", "flags");
315 rx_comp = &rxq->rx_comp[slot];
316 vlib_cli_output (vm, " %5u 0x%08x %10u %10u 0x%08x",
317 slot, rx_comp->index, rx_comp->rss,
318 rx_comp->len, rx_comp->flags);
321 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
323 rx_comp = &rxq->rx_comp[desc_idx];
325 " %5u 0x%08x %10u %10u 0x%08x",
326 desc_idx, rx_comp->index, rx_comp->rss,
327 rx_comp->len, rx_comp->flags);
333 vec_foreach_index (qid, vd->txqs)
335 txq = vec_elt_at_index (vd->txqs, qid);
336 vlib_cli_output (vm, " Queue %u (TX)", qid);
337 vlib_cli_output (vm, " TX completion next index %u",
338 txq->tx_comp_ring.next);
339 vlib_cli_output (vm, " TX completion generation flag 0x%x",
340 txq->tx_comp_ring.gen);
341 vlib_cli_output (vm, " size %u consume %u produce %u",
342 txq->size, txq->tx_ring.consume,
343 txq->tx_ring.produce);
346 vlib_cli_output (vm, "TX descriptors table");
347 vlib_cli_output (vm, " %5s %18s %10s %10s",
348 "slot", "address", "flags0", "flags1");
349 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
351 txd = &txq->tx_desc[desc_idx];
352 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x 0x%08x",
353 desc_idx, txd->address, txd->flags[0],
357 vlib_cli_output (vm, "TX completion descriptors table");
358 vlib_cli_output (vm, " %5s %10s %10s",
359 "slot", "index", "flags");
360 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
362 tx_comp = &txq->tx_comp[desc_idx];
363 vlib_cli_output (vm, " %5u 0x%08x 0x%08x",
364 desc_idx, tx_comp->index, tx_comp->flags);
367 else if (show_one_table)
369 if (which == VMXNET3_SHOW_TX_DESC)
371 vlib_cli_output (vm, "TX descriptors table");
372 vlib_cli_output (vm, " %5s %18s %10s %10s",
373 "slot", "address", "flags0", "flags1");
376 txd = &txq->tx_desc[slot];
377 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x 0x%08x",
378 slot, txd->address, txd->flags[0],
382 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
384 txd = &txq->tx_desc[desc_idx];
385 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x 0x%08x",
386 desc_idx, txd->address, txd->flags[0],
390 else if (which == VMXNET3_SHOW_TX_COMP)
392 vlib_cli_output (vm, "TX completion descriptors table");
393 vlib_cli_output (vm, " %5s %10s %10s",
394 "slot", "index", "flags");
397 tx_comp = &txq->tx_comp[slot];
398 vlib_cli_output (vm, " %5u 0x%08x 0x%08x",
399 slot, tx_comp->index, tx_comp->flags);
402 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
404 tx_comp = &txq->tx_comp[desc_idx];
405 vlib_cli_output (vm, " %5u 0x%08x 0x%08x",
406 desc_idx, tx_comp->index,
415 static clib_error_t *
416 show_vmxnet3_fn (vlib_main_t * vm, unformat_input_t * input,
417 vlib_cli_command_t * cmd)
419 vmxnet3_main_t *vmxm = &vmxnet3_main;
420 vnet_main_t *vnm = &vnet_main;
421 vmxnet3_device_t *vd;
422 clib_error_t *error = 0;
423 u32 hw_if_index, *hw_if_indices = 0;
424 vnet_hw_interface_t *hi = 0;
425 u8 show_descr = 0, show_one_table = 0, show_one_slot = 0;
426 u32 which = ~0, slot;
428 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
431 (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
433 hi = vnet_get_hw_interface (vnm, hw_if_index);
434 if (vmxnet3_device_class.index != hi->dev_class_index)
436 error = clib_error_return (0, "unknown input `%U'",
437 format_unformat_error, input);
440 vec_add1 (hw_if_indices, hw_if_index);
442 else if (unformat (input, "desc"))
446 vmxnet3_device_t *vd =
447 vec_elt_at_index (vmxm->devices, hi->dev_instance);
449 if (unformat (input, "rx-comp"))
452 which = VMXNET3_SHOW_RX_COMP;
453 if (unformat (input, "%u", &slot))
455 vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, 0);
457 if (slot >= rxq->size)
459 error = clib_error_return (0,
460 "slot size must be < rx queue "
461 "size %u", rxq->size);
467 else if (unformat (input, "rx-desc-0"))
470 which = VMXNET3_SHOW_RX_DESC0;
471 if (unformat (input, "%u", &slot))
473 vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, 0);
475 if (slot >= rxq->size)
477 error = clib_error_return (0,
478 "slot size must be < rx queue "
479 "size %u", rxq->size);
485 else if (unformat (input, "rx-desc-1"))
488 which = VMXNET3_SHOW_RX_DESC1;
489 if (unformat (input, "%u", &slot))
491 vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, 0);
493 if (slot >= rxq->size)
495 error = clib_error_return (0,
496 "slot size must be < rx queue "
497 "size %u", rxq->size);
503 else if (unformat (input, "tx-comp"))
506 which = VMXNET3_SHOW_TX_COMP;
507 if (unformat (input, "%u", &slot))
509 vmxnet3_txq_t *txq = vec_elt_at_index (vd->txqs, 0);
511 if (slot >= txq->size)
513 error = clib_error_return (0,
514 "slot size must be < tx queue "
515 "size %u", txq->size);
521 else if (unformat (input, "tx-desc"))
524 which = VMXNET3_SHOW_TX_DESC;
525 if (unformat (input, "%u", &slot))
527 vmxnet3_txq_t *txq = vec_elt_at_index (vd->txqs, 0);
529 if (slot >= txq->size)
531 error = clib_error_return (0,
532 "slot size must be < tx queue "
533 "size %u", txq->size);
541 error = clib_error_return (0, "unknown input `%U'",
542 format_unformat_error, input);
548 error = clib_error_return (0, "unknown input `%U'",
549 format_unformat_error, input);
554 if (vec_len (hw_if_indices) == 0)
556 pool_foreach (vd, vmxm->devices,
557 vec_add1 (hw_if_indices, vd->hw_if_index);
561 show_vmxnet3 (vm, hw_if_indices, show_descr, show_one_table, which,
562 show_one_slot, slot);
565 vec_free (hw_if_indices);
570 VLIB_CLI_COMMAND (show_vmxnet3_command, static) = {
571 .path = "show vmxnet3",
572 .short_help = "show vmxnet3 [[<interface>] ([desc] | ([rx-comp] | "
573 "[rx-desc-0] | [rx-desc-1] | [tx-comp] | [tx-desc]) [<slot>])]",
574 .function = show_vmxnet3_fn,
579 vmxnet3_cli_init (vlib_main_t * vm)
581 vmxnet3_main_t *vmxm = &vmxnet3_main;
583 /* initialize binary API */
584 vmxnet3_plugin_api_hookup (vm);
586 vmxm->log_default = vlib_log_register_class ("vmxnet3", 0);
590 VLIB_INIT_FUNCTION (vmxnet3_cli_init);
593 * fd.io coding-style-patch-verification: ON
596 * eval: (c-set-style "gnu")