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;
36 /* Get a line of input. */
37 if (!unformat_user (input, unformat_line_input, line_input))
40 clib_memset (&args, 0, sizeof (args));
41 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
43 if (unformat (line_input, "%U", unformat_vlib_pci_addr, &args.addr))
45 else if (unformat (line_input, "elog"))
47 else if (unformat (line_input, "bind"))
49 else if (unformat (line_input, "rx-queue-size %u", &args.rxq_size))
51 else if (unformat (line_input, "tx-queue-size %u", &args.txq_size))
53 else if (unformat (line_input, "num-tx-queues %u", &args.txq_num))
55 else if (unformat (line_input, "num-rx-queues %u", &args.rxq_num))
58 return clib_error_return (0, "unknown input `%U'",
59 format_unformat_error, input);
61 unformat_free (line_input);
64 vmxnet3_create_if (vm, &args);
70 VLIB_CLI_COMMAND (vmxnet3_create_command, static) = {
71 .path = "create interface vmxnet3",
72 .short_help = "create interface vmxnet3 <pci-address>"
73 "[rx-queue-size <size>] [tx-queue-size <size>]"
74 "[num-tx-queues <number>] [num-rx-queues <number>] [bind]",
75 .function = vmxnet3_create_command_fn,
80 vmxnet3_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
81 vlib_cli_command_t * cmd)
83 unformat_input_t _line_input, *line_input = &_line_input;
85 vnet_hw_interface_t *hw;
86 vmxnet3_main_t *vmxm = &vmxnet3_main;
88 vnet_main_t *vnm = vnet_get_main ();
90 /* Get a line of input. */
91 if (!unformat_user (input, unformat_line_input, line_input))
94 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
96 if (unformat (line_input, "sw_if_index %d", &sw_if_index))
98 else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
102 return clib_error_return (0, "unknown input `%U'",
103 format_unformat_error, input);
105 unformat_free (line_input);
107 if (sw_if_index == ~0)
108 return clib_error_return (0,
109 "please specify interface name or sw_if_index");
111 hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
112 if (hw == NULL || vmxnet3_device_class.index != hw->dev_class_index)
113 return clib_error_return (0, "not a vmxnet3 interface");
115 vd = pool_elt_at_index (vmxm->devices, hw->dev_instance);
117 vmxnet3_delete_if (vm, vd);
123 VLIB_CLI_COMMAND (vmxnet3_delete_command, static) = {
124 .path = "delete interface vmxnet3",
125 .short_help = "delete interface vmxnet3 "
126 "{<interface> | sw_if_index <sw_idx>}",
127 .function = vmxnet3_delete_command_fn,
131 static clib_error_t *
132 vmxnet3_test_command_fn (vlib_main_t * vm, unformat_input_t * input,
133 vlib_cli_command_t * cmd)
135 unformat_input_t _line_input, *line_input = &_line_input;
136 u32 sw_if_index = ~0;
137 vnet_hw_interface_t *hw;
138 vmxnet3_main_t *vmxm = &vmxnet3_main;
139 vmxnet3_device_t *vd;
140 vnet_main_t *vnm = vnet_get_main ();
141 int enable_elog = 0, disable_elog = 0;
143 /* Get a line of input. */
144 if (!unformat_user (input, unformat_line_input, line_input))
147 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
149 if (unformat (line_input, "sw_if_index %d", &sw_if_index))
151 else if (unformat (line_input, "elog-on"))
153 else if (unformat (line_input, "elog-off"))
155 else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
159 return clib_error_return (0, "unknown input `%U'",
160 format_unformat_error, input);
162 unformat_free (line_input);
164 if (sw_if_index == ~0)
165 return clib_error_return (0,
166 "please specify interface name or sw_if_index");
168 hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
169 if (hw == NULL || vmxnet3_device_class.index != hw->dev_class_index)
170 return clib_error_return (0, "not a vmxnet3 interface");
172 vd = pool_elt_at_index (vmxm->devices, hw->dev_instance);
175 vd->flags |= VMXNET3_DEVICE_F_ELOG;
178 vd->flags &= ~VMXNET3_DEVICE_F_ELOG;
184 VLIB_CLI_COMMAND (vmxnet3_test_command, static) = {
185 .path = "test vmxnet3",
186 .short_help = "test vmxnet3 <interface> | sw_if_index <sw_idx> [irq] "
187 "[elog-on] [elog-off]",
188 .function = vmxnet3_test_command_fn,
193 show_vmxnet3 (vlib_main_t * vm, u32 * hw_if_indices, u8 show_descr,
194 u8 show_one_table, u32 which, u8 show_one_slot, u32 slot)
197 vmxnet3_device_t *vd;
198 vnet_main_t *vnm = &vnet_main;
199 vmxnet3_main_t *vmxm = &vmxnet3_main;
200 vnet_hw_interface_t *hi;
202 vmxnet3_rx_desc *rxd;
203 vmxnet3_rx_comp *rx_comp;
205 vmxnet3_tx_desc *txd;
206 vmxnet3_tx_comp *tx_comp;
212 vlib_cli_output (vm, "LRO/TSO configured: %u", vmxm->lro_configured);
213 for (i = 0; i < vec_len (hw_if_indices); i++)
215 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
216 vd = vec_elt_at_index (vmxm->devices, hi->dev_instance);
217 vlib_cli_output (vm, "Interface: %U (ifindex %d)",
218 format_vnet_hw_if_index_name, vnm, hw_if_indices[i],
220 vlib_cli_output (vm, " Version: %u", vd->version);
221 vlib_cli_output (vm, " LRO/TSO enable: %u", vd->lro_enable);
222 vlib_cli_output (vm, " PCI Address: %U", format_vlib_pci_addr,
224 vlib_cli_output (vm, " Mac Address: %U", format_ethernet_address,
226 vlib_cli_output (vm, " hw if index: %u", vd->hw_if_index);
227 vlib_cli_output (vm, " Device instance: %u", vd->dev_instance);
228 vlib_cli_output (vm, " Number of interrupts: %u", vd->num_intrs);
230 vec_foreach_index (qid, vd->rxqs)
232 rxq = vec_elt_at_index (vd->rxqs, qid);
235 vlib_cli_output (vm, " Queue %u (RX)", qid);
236 vlib_cli_output (vm, " RX completion next index %u",
237 rxq->rx_comp_ring.next);
238 vlib_cli_output (vm, " RX completion generation flag 0x%x",
239 rxq->rx_comp_ring.gen);
241 /* RX descriptors tables */
242 for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
244 vmxnet3_rx_ring *ring = &rxq->rx_ring[rid];
247 " ring %u size %u fill %u "
248 "consume %u produce %u", rid,
249 rxq->size, ring->fill, ring->consume,
253 vlib_cli_output (vm, "RX descriptors table");
254 vlib_cli_output (vm, " %5s %18s %10s",
255 "slot", "address", "flags");
256 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
258 rxd = &rxq->rx_desc[rid][desc_idx];
259 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x",
260 desc_idx, rxd->address, rxd->flags);
263 else if (show_one_table)
265 if (((which == VMXNET3_SHOW_RX_DESC0) && (rid == 0)) ||
266 ((which == VMXNET3_SHOW_RX_DESC1) && (rid == 1)))
268 vlib_cli_output (vm, "RX descriptors table");
269 vlib_cli_output (vm, " %5s %18s %10s",
270 "slot", "address", "flags");
273 rxd = &rxq->rx_desc[rid][slot];
274 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x",
275 slot, rxd->address, rxd->flags);
278 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
280 rxd = &rxq->rx_desc[rid][desc_idx];
281 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x",
282 desc_idx, rxd->address,
289 /* RX completion table */
292 vlib_cli_output (vm, "RX completion descriptors table");
293 vlib_cli_output (vm, " %5s %10s %10s %10s %10s",
294 "slot", "index", "rss", "len", "flags");
295 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
297 rx_comp = &rxq->rx_comp[desc_idx];
298 vlib_cli_output (vm, " %5u 0x%08x %10u %10u 0x%08x",
299 desc_idx, rx_comp->index, rx_comp->rss,
300 rx_comp->len, rx_comp->flags);
303 else if (show_one_table)
305 if (which == VMXNET3_SHOW_RX_COMP)
307 vlib_cli_output (vm, "RX completion descriptors table");
308 vlib_cli_output (vm, " %5s %10s %10s %10s %10s",
309 "slot", "index", "rss", "len", "flags");
312 rx_comp = &rxq->rx_comp[slot];
313 vlib_cli_output (vm, " %5u 0x%08x %10u %10u 0x%08x",
314 slot, rx_comp->index, rx_comp->rss,
315 rx_comp->len, rx_comp->flags);
318 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
320 rx_comp = &rxq->rx_comp[desc_idx];
322 " %5u 0x%08x %10u %10u 0x%08x",
323 desc_idx, rx_comp->index, rx_comp->rss,
324 rx_comp->len, rx_comp->flags);
330 vec_foreach_index (qid, vd->txqs)
332 txq = vec_elt_at_index (vd->txqs, qid);
333 vlib_cli_output (vm, " Queue %u (TX)", qid);
334 vlib_cli_output (vm, " TX completion next index %u",
335 txq->tx_comp_ring.next);
336 vlib_cli_output (vm, " TX completion generation flag 0x%x",
337 txq->tx_comp_ring.gen);
338 vlib_cli_output (vm, " size %u consume %u produce %u",
339 txq->size, txq->tx_ring.consume,
340 txq->tx_ring.produce);
343 vlib_cli_output (vm, "TX descriptors table");
344 vlib_cli_output (vm, " %5s %18s %10s %10s",
345 "slot", "address", "flags0", "flags1");
346 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
348 txd = &txq->tx_desc[desc_idx];
349 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x 0x%08x",
350 desc_idx, txd->address, txd->flags[0],
354 vlib_cli_output (vm, "TX completion descriptors table");
355 vlib_cli_output (vm, " %5s %10s %10s",
356 "slot", "index", "flags");
357 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
359 tx_comp = &txq->tx_comp[desc_idx];
360 vlib_cli_output (vm, " %5u 0x%08x 0x%08x",
361 desc_idx, tx_comp->index, tx_comp->flags);
364 else if (show_one_table)
366 if (which == VMXNET3_SHOW_TX_DESC)
368 vlib_cli_output (vm, "TX descriptors table");
369 vlib_cli_output (vm, " %5s %18s %10s %10s",
370 "slot", "address", "flags0", "flags1");
373 txd = &txq->tx_desc[slot];
374 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x 0x%08x",
375 slot, txd->address, txd->flags[0],
379 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
381 txd = &txq->tx_desc[desc_idx];
382 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x 0x%08x",
383 desc_idx, txd->address, txd->flags[0],
387 else if (which == VMXNET3_SHOW_TX_COMP)
389 vlib_cli_output (vm, "TX completion descriptors table");
390 vlib_cli_output (vm, " %5s %10s %10s",
391 "slot", "index", "flags");
394 tx_comp = &txq->tx_comp[slot];
395 vlib_cli_output (vm, " %5u 0x%08x 0x%08x",
396 slot, tx_comp->index, tx_comp->flags);
399 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
401 tx_comp = &txq->tx_comp[desc_idx];
402 vlib_cli_output (vm, " %5u 0x%08x 0x%08x",
403 desc_idx, tx_comp->index,
412 static clib_error_t *
413 show_vmxnet3_fn (vlib_main_t * vm, unformat_input_t * input,
414 vlib_cli_command_t * cmd)
416 vmxnet3_main_t *vmxm = &vmxnet3_main;
417 vnet_main_t *vnm = &vnet_main;
418 vmxnet3_device_t *vd;
419 clib_error_t *error = 0;
420 u32 hw_if_index, *hw_if_indices = 0;
421 vnet_hw_interface_t *hi = 0;
422 u8 show_descr = 0, show_one_table = 0, show_one_slot = 0;
423 u32 which = ~0, slot;
425 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
428 (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
430 hi = vnet_get_hw_interface (vnm, hw_if_index);
431 if (vmxnet3_device_class.index != hi->dev_class_index)
433 error = clib_error_return (0, "unknown input `%U'",
434 format_unformat_error, input);
437 vec_add1 (hw_if_indices, hw_if_index);
439 else if (unformat (input, "desc"))
443 vmxnet3_device_t *vd =
444 vec_elt_at_index (vmxm->devices, hi->dev_instance);
446 if (unformat (input, "rx-comp"))
449 which = VMXNET3_SHOW_RX_COMP;
450 if (unformat (input, "%u", &slot))
452 vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, 0);
454 if (slot >= rxq->size)
456 error = clib_error_return (0,
457 "slot size must be < rx queue "
458 "size %u", rxq->size);
464 else if (unformat (input, "rx-desc-0"))
467 which = VMXNET3_SHOW_RX_DESC0;
468 if (unformat (input, "%u", &slot))
470 vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, 0);
472 if (slot >= rxq->size)
474 error = clib_error_return (0,
475 "slot size must be < rx queue "
476 "size %u", rxq->size);
482 else if (unformat (input, "rx-desc-1"))
485 which = VMXNET3_SHOW_RX_DESC1;
486 if (unformat (input, "%u", &slot))
488 vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, 0);
490 if (slot >= rxq->size)
492 error = clib_error_return (0,
493 "slot size must be < rx queue "
494 "size %u", rxq->size);
500 else if (unformat (input, "tx-comp"))
503 which = VMXNET3_SHOW_TX_COMP;
504 if (unformat (input, "%u", &slot))
506 vmxnet3_txq_t *txq = vec_elt_at_index (vd->txqs, 0);
508 if (slot >= txq->size)
510 error = clib_error_return (0,
511 "slot size must be < tx queue "
512 "size %u", txq->size);
518 else if (unformat (input, "tx-desc"))
521 which = VMXNET3_SHOW_TX_DESC;
522 if (unformat (input, "%u", &slot))
524 vmxnet3_txq_t *txq = vec_elt_at_index (vd->txqs, 0);
526 if (slot >= txq->size)
528 error = clib_error_return (0,
529 "slot size must be < tx queue "
530 "size %u", txq->size);
538 error = clib_error_return (0, "unknown input `%U'",
539 format_unformat_error, input);
545 error = clib_error_return (0, "unknown input `%U'",
546 format_unformat_error, input);
551 if (vec_len (hw_if_indices) == 0)
553 pool_foreach (vd, vmxm->devices,
554 vec_add1 (hw_if_indices, vd->hw_if_index);
558 show_vmxnet3 (vm, hw_if_indices, show_descr, show_one_table, which,
559 show_one_slot, slot);
562 vec_free (hw_if_indices);
567 VLIB_CLI_COMMAND (show_vmxnet3_command, static) = {
568 .path = "show vmxnet3",
569 .short_help = "show vmxnet3 [[<interface>] ([desc] | ([rx-comp] | "
570 "[rx-desc-0] | [rx-desc-1] | [tx-comp] | [tx-desc]) [<slot>])]",
571 .function = show_vmxnet3_fn,
576 vmxnet3_cli_init (vlib_main_t * vm)
578 vmxnet3_main_t *vmxm = &vmxnet3_main;
580 /* initialize binary API */
581 vmxnet3_plugin_api_hookup (vm);
583 vmxm->log_default = vlib_log_register_class ("vmxnet3", 0);
587 VLIB_INIT_FUNCTION (vmxnet3_cli_init);
589 static clib_error_t *
590 vmxnet3_config (vlib_main_t * vm, unformat_input_t * input)
592 vmxnet3_main_t *vmxm = &vmxnet3_main;
594 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
596 if (unformat (input, "lro"))
597 vmxm->lro_configured = 1;
599 return clib_error_return (0, "unknown input `%U'",
600 format_unformat_error, input);
606 /* vmxnet3 { ... } configuration. */
607 VLIB_CONFIG_FUNCTION (vmxnet3_config, "vmxnet3");
610 * fd.io coding-style-patch-verification: ON
613 * eval: (c-set-style "gnu")