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, "elog"))
48 else if (unformat (line_input, "bind"))
50 else if (unformat (line_input, "rx-queue-size %u", &size))
52 else if (unformat (line_input, "tx-queue-size %u", &size))
54 else if (unformat (line_input, "num-tx-queues %u", &size))
56 else if (unformat (line_input, "num-rx-queues %u", &size))
59 return clib_error_return (0, "unknown input `%U'",
60 format_unformat_error, input);
62 unformat_free (line_input);
65 vmxnet3_create_if (vm, &args);
71 VLIB_CLI_COMMAND (vmxnet3_create_command, static) = {
72 .path = "create interface vmxnet3",
73 .short_help = "create interface vmxnet3 <pci-address>"
74 "[rx-queue-size <size>] [tx-queue-size <size>]"
75 "[num-tx-queues <number>] [num-rx-queues <number>] [bind]",
76 .function = vmxnet3_create_command_fn,
81 vmxnet3_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
82 vlib_cli_command_t * cmd)
84 unformat_input_t _line_input, *line_input = &_line_input;
86 vnet_hw_interface_t *hw;
87 vmxnet3_main_t *vmxm = &vmxnet3_main;
89 vnet_main_t *vnm = vnet_get_main ();
91 /* Get a line of input. */
92 if (!unformat_user (input, unformat_line_input, line_input))
95 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
97 if (unformat (line_input, "sw_if_index %d", &sw_if_index))
99 else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
103 return clib_error_return (0, "unknown input `%U'",
104 format_unformat_error, input);
106 unformat_free (line_input);
108 if (sw_if_index == ~0)
109 return clib_error_return (0,
110 "please specify interface name or sw_if_index");
112 hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
113 if (hw == NULL || vmxnet3_device_class.index != hw->dev_class_index)
114 return clib_error_return (0, "not a vmxnet3 interface");
116 vd = pool_elt_at_index (vmxm->devices, hw->dev_instance);
118 vmxnet3_delete_if (vm, vd);
124 VLIB_CLI_COMMAND (vmxnet3_delete_command, static) = {
125 .path = "delete interface vmxnet3",
126 .short_help = "delete interface vmxnet3 "
127 "{<interface> | sw_if_index <sw_idx>}",
128 .function = vmxnet3_delete_command_fn,
132 static clib_error_t *
133 vmxnet3_test_command_fn (vlib_main_t * vm, unformat_input_t * input,
134 vlib_cli_command_t * cmd)
136 unformat_input_t _line_input, *line_input = &_line_input;
137 u32 sw_if_index = ~0;
138 vnet_hw_interface_t *hw;
139 vmxnet3_main_t *vmxm = &vmxnet3_main;
140 vmxnet3_device_t *vd;
141 vnet_main_t *vnm = vnet_get_main ();
142 int enable_elog = 0, disable_elog = 0;
144 /* Get a line of input. */
145 if (!unformat_user (input, unformat_line_input, line_input))
148 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
150 if (unformat (line_input, "sw_if_index %d", &sw_if_index))
152 else if (unformat (line_input, "elog-on"))
154 else if (unformat (line_input, "elog-off"))
156 else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
160 return clib_error_return (0, "unknown input `%U'",
161 format_unformat_error, input);
163 unformat_free (line_input);
165 if (sw_if_index == ~0)
166 return clib_error_return (0,
167 "please specify interface name or sw_if_index");
169 hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
170 if (hw == NULL || vmxnet3_device_class.index != hw->dev_class_index)
171 return clib_error_return (0, "not a vmxnet3 interface");
173 vd = pool_elt_at_index (vmxm->devices, hw->dev_instance);
176 vd->flags |= VMXNET3_DEVICE_F_ELOG;
179 vd->flags &= ~VMXNET3_DEVICE_F_ELOG;
185 VLIB_CLI_COMMAND (vmxnet3_test_command, static) = {
186 .path = "test vmxnet3",
187 .short_help = "test vmxnet3 <interface> | sw_if_index <sw_idx> [irq] "
188 "[elog-on] [elog-off]",
189 .function = vmxnet3_test_command_fn,
194 show_vmxnet3 (vlib_main_t * vm, u32 * hw_if_indices, u8 show_descr,
195 u8 show_one_table, u32 which, u8 show_one_slot, u32 slot)
198 vmxnet3_device_t *vd;
199 vnet_main_t *vnm = &vnet_main;
200 vmxnet3_main_t *vmxm = &vmxnet3_main;
201 vnet_hw_interface_t *hi;
203 vmxnet3_rx_desc *rxd;
204 vmxnet3_rx_comp *rx_comp;
206 vmxnet3_tx_desc *txd;
207 vmxnet3_tx_comp *tx_comp;
213 vlib_cli_output (vm, "LRO/TSO configured: %u", vmxm->lro_configured);
214 for (i = 0; i < vec_len (hw_if_indices); i++)
216 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
217 vd = vec_elt_at_index (vmxm->devices, hi->dev_instance);
218 vlib_cli_output (vm, "Interface: %U (ifindex %d)",
219 format_vnet_hw_if_index_name, vnm, hw_if_indices[i],
221 vlib_cli_output (vm, " Version: %u", vd->version);
222 vlib_cli_output (vm, " LRO/TSO enable: %u", vd->lro_enable);
223 vlib_cli_output (vm, " PCI Address: %U", format_vlib_pci_addr,
225 vlib_cli_output (vm, " Mac Address: %U", format_ethernet_address,
227 vlib_cli_output (vm, " hw if index: %u", vd->hw_if_index);
228 vlib_cli_output (vm, " Device instance: %u", vd->dev_instance);
229 vlib_cli_output (vm, " Number of interrupts: %u", vd->num_intrs);
231 vec_foreach_index (qid, vd->rxqs)
233 rxq = vec_elt_at_index (vd->rxqs, qid);
236 vlib_cli_output (vm, " Queue %u (RX)", qid);
237 vlib_cli_output (vm, " RX completion next index %u",
238 rxq->rx_comp_ring.next);
239 vlib_cli_output (vm, " RX completion generation flag 0x%x",
240 rxq->rx_comp_ring.gen);
242 /* RX descriptors tables */
243 for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
245 vmxnet3_rx_ring *ring = &rxq->rx_ring[rid];
248 " ring %u size %u fill %u "
249 "consume %u produce %u", rid,
250 rxq->size, ring->fill, ring->consume,
254 vlib_cli_output (vm, "RX descriptors table");
255 vlib_cli_output (vm, " %5s %18s %10s",
256 "slot", "address", "flags");
257 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
259 rxd = &rxq->rx_desc[rid][desc_idx];
260 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x",
261 desc_idx, rxd->address, rxd->flags);
264 else if (show_one_table)
266 if (((which == VMXNET3_SHOW_RX_DESC0) && (rid == 0)) ||
267 ((which == VMXNET3_SHOW_RX_DESC1) && (rid == 1)))
269 vlib_cli_output (vm, "RX descriptors table");
270 vlib_cli_output (vm, " %5s %18s %10s",
271 "slot", "address", "flags");
274 rxd = &rxq->rx_desc[rid][slot];
275 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x",
276 slot, rxd->address, rxd->flags);
279 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
281 rxd = &rxq->rx_desc[rid][desc_idx];
282 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x",
283 desc_idx, rxd->address,
290 /* RX completion table */
293 vlib_cli_output (vm, "RX completion descriptors table");
294 vlib_cli_output (vm, " %5s %10s %10s %10s %10s",
295 "slot", "index", "rss", "len", "flags");
296 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
298 rx_comp = &rxq->rx_comp[desc_idx];
299 vlib_cli_output (vm, " %5u 0x%08x %10u %10u 0x%08x",
300 desc_idx, rx_comp->index, rx_comp->rss,
301 rx_comp->len, rx_comp->flags);
304 else if (show_one_table)
306 if (which == VMXNET3_SHOW_RX_COMP)
308 vlib_cli_output (vm, "RX completion descriptors table");
309 vlib_cli_output (vm, " %5s %10s %10s %10s %10s",
310 "slot", "index", "rss", "len", "flags");
313 rx_comp = &rxq->rx_comp[slot];
314 vlib_cli_output (vm, " %5u 0x%08x %10u %10u 0x%08x",
315 slot, rx_comp->index, rx_comp->rss,
316 rx_comp->len, rx_comp->flags);
319 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
321 rx_comp = &rxq->rx_comp[desc_idx];
323 " %5u 0x%08x %10u %10u 0x%08x",
324 desc_idx, rx_comp->index, rx_comp->rss,
325 rx_comp->len, rx_comp->flags);
331 vec_foreach_index (qid, vd->txqs)
333 txq = vec_elt_at_index (vd->txqs, qid);
334 vlib_cli_output (vm, " Queue %u (TX)", qid);
335 vlib_cli_output (vm, " TX completion next index %u",
336 txq->tx_comp_ring.next);
337 vlib_cli_output (vm, " TX completion generation flag 0x%x",
338 txq->tx_comp_ring.gen);
339 vlib_cli_output (vm, " size %u consume %u produce %u",
340 txq->size, txq->tx_ring.consume,
341 txq->tx_ring.produce);
344 vlib_cli_output (vm, "TX descriptors table");
345 vlib_cli_output (vm, " %5s %18s %10s %10s",
346 "slot", "address", "flags0", "flags1");
347 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
349 txd = &txq->tx_desc[desc_idx];
350 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x 0x%08x",
351 desc_idx, txd->address, txd->flags[0],
355 vlib_cli_output (vm, "TX completion descriptors table");
356 vlib_cli_output (vm, " %5s %10s %10s",
357 "slot", "index", "flags");
358 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
360 tx_comp = &txq->tx_comp[desc_idx];
361 vlib_cli_output (vm, " %5u 0x%08x 0x%08x",
362 desc_idx, tx_comp->index, tx_comp->flags);
365 else if (show_one_table)
367 if (which == VMXNET3_SHOW_TX_DESC)
369 vlib_cli_output (vm, "TX descriptors table");
370 vlib_cli_output (vm, " %5s %18s %10s %10s",
371 "slot", "address", "flags0", "flags1");
374 txd = &txq->tx_desc[slot];
375 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x 0x%08x",
376 slot, txd->address, txd->flags[0],
380 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
382 txd = &txq->tx_desc[desc_idx];
383 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x 0x%08x",
384 desc_idx, txd->address, txd->flags[0],
388 else if (which == VMXNET3_SHOW_TX_COMP)
390 vlib_cli_output (vm, "TX completion descriptors table");
391 vlib_cli_output (vm, " %5s %10s %10s",
392 "slot", "index", "flags");
395 tx_comp = &txq->tx_comp[slot];
396 vlib_cli_output (vm, " %5u 0x%08x 0x%08x",
397 slot, tx_comp->index, tx_comp->flags);
400 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
402 tx_comp = &txq->tx_comp[desc_idx];
403 vlib_cli_output (vm, " %5u 0x%08x 0x%08x",
404 desc_idx, tx_comp->index,
413 static clib_error_t *
414 show_vmxnet3_fn (vlib_main_t * vm, unformat_input_t * input,
415 vlib_cli_command_t * cmd)
417 vmxnet3_main_t *vmxm = &vmxnet3_main;
418 vnet_main_t *vnm = &vnet_main;
419 vmxnet3_device_t *vd;
420 clib_error_t *error = 0;
421 u32 hw_if_index, *hw_if_indices = 0;
422 vnet_hw_interface_t *hi = 0;
423 u8 show_descr = 0, show_one_table = 0, show_one_slot = 0;
424 u32 which = ~0, slot;
426 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
429 (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
431 hi = vnet_get_hw_interface (vnm, hw_if_index);
432 if (vmxnet3_device_class.index != hi->dev_class_index)
434 error = clib_error_return (0, "unknown input `%U'",
435 format_unformat_error, input);
438 vec_add1 (hw_if_indices, hw_if_index);
440 else if (unformat (input, "desc"))
444 vmxnet3_device_t *vd =
445 vec_elt_at_index (vmxm->devices, hi->dev_instance);
447 if (unformat (input, "rx-comp"))
450 which = VMXNET3_SHOW_RX_COMP;
451 if (unformat (input, "%u", &slot))
453 vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, 0);
455 if (slot >= rxq->size)
457 error = clib_error_return (0,
458 "slot size must be < rx queue "
459 "size %u", rxq->size);
465 else if (unformat (input, "rx-desc-0"))
468 which = VMXNET3_SHOW_RX_DESC0;
469 if (unformat (input, "%u", &slot))
471 vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, 0);
473 if (slot >= rxq->size)
475 error = clib_error_return (0,
476 "slot size must be < rx queue "
477 "size %u", rxq->size);
483 else if (unformat (input, "rx-desc-1"))
486 which = VMXNET3_SHOW_RX_DESC1;
487 if (unformat (input, "%u", &slot))
489 vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, 0);
491 if (slot >= rxq->size)
493 error = clib_error_return (0,
494 "slot size must be < rx queue "
495 "size %u", rxq->size);
501 else if (unformat (input, "tx-comp"))
504 which = VMXNET3_SHOW_TX_COMP;
505 if (unformat (input, "%u", &slot))
507 vmxnet3_txq_t *txq = vec_elt_at_index (vd->txqs, 0);
509 if (slot >= txq->size)
511 error = clib_error_return (0,
512 "slot size must be < tx queue "
513 "size %u", txq->size);
519 else if (unformat (input, "tx-desc"))
522 which = VMXNET3_SHOW_TX_DESC;
523 if (unformat (input, "%u", &slot))
525 vmxnet3_txq_t *txq = vec_elt_at_index (vd->txqs, 0);
527 if (slot >= txq->size)
529 error = clib_error_return (0,
530 "slot size must be < tx queue "
531 "size %u", txq->size);
539 error = clib_error_return (0, "unknown input `%U'",
540 format_unformat_error, input);
546 error = clib_error_return (0, "unknown input `%U'",
547 format_unformat_error, input);
552 if (vec_len (hw_if_indices) == 0)
554 pool_foreach (vd, vmxm->devices,
555 vec_add1 (hw_if_indices, vd->hw_if_index);
559 show_vmxnet3 (vm, hw_if_indices, show_descr, show_one_table, which,
560 show_one_slot, slot);
563 vec_free (hw_if_indices);
568 VLIB_CLI_COMMAND (show_vmxnet3_command, static) = {
569 .path = "show vmxnet3",
570 .short_help = "show vmxnet3 [[<interface>] ([desc] | ([rx-comp] | "
571 "[rx-desc-0] | [rx-desc-1] | [tx-comp] | [tx-desc]) [<slot>])]",
572 .function = show_vmxnet3_fn,
577 vmxnet3_cli_init (vlib_main_t * vm)
579 vmxnet3_main_t *vmxm = &vmxnet3_main;
581 /* initialize binary API */
582 vmxnet3_plugin_api_hookup (vm);
584 vmxm->log_default = vlib_log_register_class ("vmxnet3", 0);
588 VLIB_INIT_FUNCTION (vmxnet3_cli_init);
590 static clib_error_t *
591 vmxnet3_config (vlib_main_t * vm, unformat_input_t * input)
593 vmxnet3_main_t *vmxm = &vmxnet3_main;
595 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
597 if (unformat (input, "lro"))
598 vmxm->lro_configured = 1;
600 return clib_error_return (0, "unknown input `%U'",
601 format_unformat_error, input);
607 /* vmxnet3 { ... } configuration. */
608 VLIB_CONFIG_FUNCTION (vmxnet3_config, "vmxnet3");
611 * fd.io coding-style-patch-verification: ON
614 * eval: (c-set-style "gnu")