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, "rx-queue-size %u", &args.rxq_size))
49 else if (unformat (line_input, "tx-queue-size %u", &args.txq_size))
51 else if (unformat (line_input, "num-tx-queues %u", &args.txq_num))
54 return clib_error_return (0, "unknown input `%U'",
55 format_unformat_error, input);
57 unformat_free (line_input);
60 vmxnet3_create_if (vm, &args);
66 VLIB_CLI_COMMAND (vmxnet3_create_command, static) = {
67 .path = "create interface vmxnet3",
68 .short_help = "create interface vmxnet3 <pci-address>"
69 "[rx-queue-size <size>] [tx-queue-size <size>]"
70 "[num-tx-queues <number>]",
71 .function = vmxnet3_create_command_fn,
76 vmxnet3_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
77 vlib_cli_command_t * cmd)
79 unformat_input_t _line_input, *line_input = &_line_input;
81 vnet_hw_interface_t *hw;
82 vmxnet3_main_t *vmxm = &vmxnet3_main;
84 vnet_main_t *vnm = vnet_get_main ();
86 /* Get a line of input. */
87 if (!unformat_user (input, unformat_line_input, line_input))
90 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
92 if (unformat (line_input, "sw_if_index %d", &sw_if_index))
94 else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
98 return clib_error_return (0, "unknown input `%U'",
99 format_unformat_error, input);
101 unformat_free (line_input);
103 if (sw_if_index == ~0)
104 return clib_error_return (0,
105 "please specify interface name or sw_if_index");
107 hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
108 if (hw == NULL || vmxnet3_device_class.index != hw->dev_class_index)
109 return clib_error_return (0, "not a vmxnet3 interface");
111 vd = pool_elt_at_index (vmxm->devices, hw->dev_instance);
113 vmxnet3_delete_if (vm, vd);
119 VLIB_CLI_COMMAND (vmxnet3_delete_command, static) = {
120 .path = "delete interface vmxnet3",
121 .short_help = "delete interface vmxnet3 "
122 "{<interface> | sw_if_index <sw_idx>}",
123 .function = vmxnet3_delete_command_fn,
127 static clib_error_t *
128 vmxnet3_test_command_fn (vlib_main_t * vm, unformat_input_t * input,
129 vlib_cli_command_t * cmd)
131 unformat_input_t _line_input, *line_input = &_line_input;
132 u32 sw_if_index = ~0;
133 vnet_hw_interface_t *hw;
134 vmxnet3_main_t *vmxm = &vmxnet3_main;
135 vmxnet3_device_t *vd;
136 vnet_main_t *vnm = vnet_get_main ();
137 int enable_elog = 0, disable_elog = 0;
139 /* Get a line of input. */
140 if (!unformat_user (input, unformat_line_input, line_input))
143 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
145 if (unformat (line_input, "sw_if_index %d", &sw_if_index))
147 else if (unformat (line_input, "elog-on"))
149 else if (unformat (line_input, "elog-off"))
151 else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
155 return clib_error_return (0, "unknown input `%U'",
156 format_unformat_error, input);
158 unformat_free (line_input);
160 if (sw_if_index == ~0)
161 return clib_error_return (0,
162 "please specify interface name or sw_if_index");
164 hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
165 if (hw == NULL || vmxnet3_device_class.index != hw->dev_class_index)
166 return clib_error_return (0, "not a vmxnet3 interface");
168 vd = pool_elt_at_index (vmxm->devices, hw->dev_instance);
171 vd->flags |= VMXNET3_DEVICE_F_ELOG;
174 vd->flags &= ~VMXNET3_DEVICE_F_ELOG;
180 VLIB_CLI_COMMAND (vmxnet3_test_command, static) = {
181 .path = "test vmxnet3",
182 .short_help = "test vmxnet3 <interface> | sw_if_index <sw_idx> [irq] "
183 "[elog-on] [elog-off]",
184 .function = vmxnet3_test_command_fn,
189 show_vmxnet3 (vlib_main_t * vm, u32 * hw_if_indices, u8 show_descr,
190 u8 show_one_table, u32 which, u8 show_one_slot, u32 slot)
193 vmxnet3_device_t *vd;
194 vnet_main_t *vnm = &vnet_main;
195 vmxnet3_main_t *vmxm = &vmxnet3_main;
196 vnet_hw_interface_t *hi;
198 vmxnet3_rx_desc *rxd;
199 vmxnet3_rx_comp *rx_comp;
201 vmxnet3_tx_desc *txd;
202 vmxnet3_tx_comp *tx_comp;
208 vlib_cli_output (vm, "LRO/TSO configured: %u", vmxm->lro_configured);
209 for (i = 0; i < vec_len (hw_if_indices); i++)
211 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
212 vd = vec_elt_at_index (vmxm->devices, hi->dev_instance);
213 vlib_cli_output (vm, "Interface: %U (ifindex %d)",
214 format_vnet_hw_if_index_name, vnm, hw_if_indices[i],
216 vlib_cli_output (vm, " Version: %u", vd->version);
217 vlib_cli_output (vm, " LRO/TSO enable: %u", vd->lro_enable);
218 vlib_cli_output (vm, " PCI Address: %U", format_vlib_pci_addr,
220 vlib_cli_output (vm, " Mac Address: %U", format_ethernet_address,
222 vlib_cli_output (vm, " hw if index: %u", vd->hw_if_index);
223 vlib_cli_output (vm, " Device instance: %u", vd->dev_instance);
224 vlib_cli_output (vm, " Number of interrupts: %u", vd->num_intrs);
226 vec_foreach_index (qid, vd->rxqs)
228 rxq = vec_elt_at_index (vd->rxqs, qid);
231 vlib_cli_output (vm, " Queue %u (RX)", qid);
232 vlib_cli_output (vm, " RX completion next index %u",
233 rxq->rx_comp_ring.next);
234 vlib_cli_output (vm, " RX completion generation flag 0x%x",
235 rxq->rx_comp_ring.gen);
237 /* RX descriptors tables */
238 for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
240 vmxnet3_rx_ring *ring = &rxq->rx_ring[rid];
243 " ring %u size %u fill %u "
244 "consume %u produce %u", rid,
245 rxq->size, ring->fill, ring->consume,
249 vlib_cli_output (vm, "RX descriptors table");
250 vlib_cli_output (vm, " %5s %18s %10s",
251 "slot", "address", "flags");
252 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
254 rxd = &rxq->rx_desc[rid][desc_idx];
255 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x",
256 desc_idx, rxd->address, rxd->flags);
259 else if (show_one_table)
261 if (((which == VMXNET3_SHOW_RX_DESC0) && (rid == 0)) ||
262 ((which == VMXNET3_SHOW_RX_DESC1) && (rid == 1)))
264 vlib_cli_output (vm, "RX descriptors table");
265 vlib_cli_output (vm, " %5s %18s %10s",
266 "slot", "address", "flags");
269 rxd = &rxq->rx_desc[rid][slot];
270 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x",
271 slot, rxd->address, rxd->flags);
274 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
276 rxd = &rxq->rx_desc[rid][desc_idx];
277 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x",
278 desc_idx, rxd->address,
285 /* RX completion table */
288 vlib_cli_output (vm, "RX completion descriptors table");
289 vlib_cli_output (vm, " %5s %10s %10s %10s %10s",
290 "slot", "index", "rss", "len", "flags");
291 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
293 rx_comp = &rxq->rx_comp[desc_idx];
294 vlib_cli_output (vm, " %5u 0x%08x %10u %10u 0x%08x",
295 desc_idx, rx_comp->index, rx_comp->rss,
296 rx_comp->len, rx_comp->flags);
299 else if (show_one_table)
301 if (which == VMXNET3_SHOW_RX_COMP)
303 vlib_cli_output (vm, "RX completion descriptors table");
304 vlib_cli_output (vm, " %5s %10s %10s %10s %10s",
305 "slot", "index", "rss", "len", "flags");
308 rx_comp = &rxq->rx_comp[slot];
309 vlib_cli_output (vm, " %5u 0x%08x %10u %10u 0x%08x",
310 slot, rx_comp->index, rx_comp->rss,
311 rx_comp->len, rx_comp->flags);
314 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
316 rx_comp = &rxq->rx_comp[desc_idx];
318 " %5u 0x%08x %10u %10u 0x%08x",
319 desc_idx, rx_comp->index, rx_comp->rss,
320 rx_comp->len, rx_comp->flags);
326 vec_foreach_index (qid, vd->txqs)
328 txq = vec_elt_at_index (vd->txqs, qid);
329 vlib_cli_output (vm, " Queue %u (TX)", qid);
330 vlib_cli_output (vm, " TX completion next index %u",
331 txq->tx_comp_ring.next);
332 vlib_cli_output (vm, " TX completion generation flag 0x%x",
333 txq->tx_comp_ring.gen);
334 vlib_cli_output (vm, " size %u consume %u produce %u",
335 txq->size, txq->tx_ring.consume,
336 txq->tx_ring.produce);
339 vlib_cli_output (vm, "TX descriptors table");
340 vlib_cli_output (vm, " %5s %18s %10s %10s",
341 "slot", "address", "flags0", "flags1");
342 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
344 txd = &txq->tx_desc[desc_idx];
345 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x 0x%08x",
346 desc_idx, txd->address, txd->flags[0],
350 vlib_cli_output (vm, "TX completion descriptors table");
351 vlib_cli_output (vm, " %5s %10s %10s",
352 "slot", "index", "flags");
353 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
355 tx_comp = &txq->tx_comp[desc_idx];
356 vlib_cli_output (vm, " %5u 0x%08x 0x%08x",
357 desc_idx, tx_comp->index, tx_comp->flags);
360 else if (show_one_table)
362 if (which == VMXNET3_SHOW_TX_DESC)
364 vlib_cli_output (vm, "TX descriptors table");
365 vlib_cli_output (vm, " %5s %18s %10s %10s",
366 "slot", "address", "flags0", "flags1");
369 txd = &txq->tx_desc[slot];
370 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x 0x%08x",
371 slot, txd->address, txd->flags[0],
375 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
377 txd = &txq->tx_desc[desc_idx];
378 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x 0x%08x",
379 desc_idx, txd->address, txd->flags[0],
383 else if (which == VMXNET3_SHOW_TX_COMP)
385 vlib_cli_output (vm, "TX completion descriptors table");
386 vlib_cli_output (vm, " %5s %10s %10s",
387 "slot", "index", "flags");
390 tx_comp = &txq->tx_comp[slot];
391 vlib_cli_output (vm, " %5u 0x%08x 0x%08x",
392 slot, tx_comp->index, tx_comp->flags);
395 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
397 tx_comp = &txq->tx_comp[desc_idx];
398 vlib_cli_output (vm, " %5u 0x%08x 0x%08x",
399 desc_idx, tx_comp->index,
408 static clib_error_t *
409 show_vmxnet3_fn (vlib_main_t * vm, unformat_input_t * input,
410 vlib_cli_command_t * cmd)
412 vmxnet3_main_t *vmxm = &vmxnet3_main;
413 vnet_main_t *vnm = &vnet_main;
414 vmxnet3_device_t *vd;
415 clib_error_t *error = 0;
416 u32 hw_if_index, *hw_if_indices = 0;
417 vnet_hw_interface_t *hi = 0;
418 u8 show_descr = 0, show_one_table = 0, show_one_slot = 0;
419 u32 which = ~0, slot;
421 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
424 (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
426 hi = vnet_get_hw_interface (vnm, hw_if_index);
427 if (vmxnet3_device_class.index != hi->dev_class_index)
429 error = clib_error_return (0, "unknown input `%U'",
430 format_unformat_error, input);
433 vec_add1 (hw_if_indices, hw_if_index);
435 else if (unformat (input, "desc"))
439 vmxnet3_device_t *vd =
440 vec_elt_at_index (vmxm->devices, hi->dev_instance);
442 if (unformat (input, "rx-comp"))
445 which = VMXNET3_SHOW_RX_COMP;
446 if (unformat (input, "%u", &slot))
448 vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, 0);
450 if (slot >= rxq->size)
452 error = clib_error_return (0,
453 "slot size must be < rx queue "
454 "size %u", rxq->size);
460 else if (unformat (input, "rx-desc-0"))
463 which = VMXNET3_SHOW_RX_DESC0;
464 if (unformat (input, "%u", &slot))
466 vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, 0);
468 if (slot >= rxq->size)
470 error = clib_error_return (0,
471 "slot size must be < rx queue "
472 "size %u", rxq->size);
478 else if (unformat (input, "rx-desc-1"))
481 which = VMXNET3_SHOW_RX_DESC1;
482 if (unformat (input, "%u", &slot))
484 vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, 0);
486 if (slot >= rxq->size)
488 error = clib_error_return (0,
489 "slot size must be < rx queue "
490 "size %u", rxq->size);
496 else if (unformat (input, "tx-comp"))
499 which = VMXNET3_SHOW_TX_COMP;
500 if (unformat (input, "%u", &slot))
502 vmxnet3_txq_t *txq = vec_elt_at_index (vd->txqs, 0);
504 if (slot >= txq->size)
506 error = clib_error_return (0,
507 "slot size must be < tx queue "
508 "size %u", txq->size);
514 else if (unformat (input, "tx-desc"))
517 which = VMXNET3_SHOW_TX_DESC;
518 if (unformat (input, "%u", &slot))
520 vmxnet3_txq_t *txq = vec_elt_at_index (vd->txqs, 0);
522 if (slot >= txq->size)
524 error = clib_error_return (0,
525 "slot size must be < tx queue "
526 "size %u", txq->size);
534 error = clib_error_return (0, "unknown input `%U'",
535 format_unformat_error, input);
541 error = clib_error_return (0, "unknown input `%U'",
542 format_unformat_error, input);
547 if (vec_len (hw_if_indices) == 0)
549 pool_foreach (vd, vmxm->devices,
550 vec_add1 (hw_if_indices, vd->hw_if_index);
554 show_vmxnet3 (vm, hw_if_indices, show_descr, show_one_table, which,
555 show_one_slot, slot);
558 vec_free (hw_if_indices);
563 VLIB_CLI_COMMAND (show_vmxnet3_command, static) = {
564 .path = "show vmxnet3",
565 .short_help = "show vmxnet3 [[<interface>] ([desc] | ([rx-comp] | "
566 "[rx-desc-0] | [rx-desc-1] | [tx-comp] | [tx-desc]) [<slot>])]",
567 .function = show_vmxnet3_fn,
572 vmxnet3_cli_init (vlib_main_t * vm)
574 vmxnet3_main_t *vmxm = &vmxnet3_main;
576 /* initialize binary API */
577 vmxnet3_plugin_api_hookup (vm);
579 vmxm->log_default = vlib_log_register_class ("vmxnet3", 0);
583 VLIB_INIT_FUNCTION (vmxnet3_cli_init);
585 static clib_error_t *
586 vmxnet3_config (vlib_main_t * vm, unformat_input_t * input)
588 vmxnet3_main_t *vmxm = &vmxnet3_main;
590 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
592 if (unformat (input, "lro"))
593 vmxm->lro_configured = 1;
595 return clib_error_return (0, "unknown input `%U'",
596 format_unformat_error, input);
602 /* vmxnet3 { ... } configuration. */
603 VLIB_CONFIG_FUNCTION (vmxnet3_config, "vmxnet3");
606 * fd.io coding-style-patch-verification: ON
609 * eval: (c-set-style "gnu")