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 force"))
51 args.bind = VMXNET3_BIND_FORCE;
52 else if (unformat (line_input, "bind"))
53 args.bind = VMXNET3_BIND_DEFAULT;
54 else if (unformat (line_input, "rx-queue-size %u", &size))
56 else if (unformat (line_input, "tx-queue-size %u", &size))
58 else if (unformat (line_input, "num-tx-queues %u", &size))
60 else if (unformat (line_input, "num-rx-queues %u", &size))
64 unformat_free (line_input);
65 return clib_error_return (0, "unknown input `%U'",
66 format_unformat_error, input);
69 unformat_free (line_input);
71 vmxnet3_create_if (vm, &args);
73 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
74 vnet_get_main (), args.sw_if_index);
80 VLIB_CLI_COMMAND (vmxnet3_create_command, static) = {
81 .path = "create interface vmxnet3",
83 "create interface vmxnet3 <pci-address>"
84 " [rx-queue-size <size>] [tx-queue-size <size>]"
85 " [num-tx-queues <number>] [num-rx-queues <number>] [bind [force]]"
87 .function = vmxnet3_create_command_fn,
92 vmxnet3_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
93 vlib_cli_command_t * cmd)
95 unformat_input_t _line_input, *line_input = &_line_input;
97 vnet_hw_interface_t *hw;
98 vmxnet3_main_t *vmxm = &vmxnet3_main;
100 vnet_main_t *vnm = vnet_get_main ();
102 /* Get a line of input. */
103 if (!unformat_user (input, unformat_line_input, line_input))
106 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
108 if (unformat (line_input, "sw_if_index %d", &sw_if_index))
110 else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
114 return clib_error_return (0, "unknown input `%U'",
115 format_unformat_error, input);
117 unformat_free (line_input);
119 if (sw_if_index == ~0)
120 return clib_error_return (0,
121 "please specify interface name or sw_if_index");
123 hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
124 if (hw == NULL || vmxnet3_device_class.index != hw->dev_class_index)
125 return clib_error_return (0, "not a vmxnet3 interface");
127 vd = pool_elt_at_index (vmxm->devices, hw->dev_instance);
129 vmxnet3_delete_if (vm, vd);
135 VLIB_CLI_COMMAND (vmxnet3_delete_command, static) = {
136 .path = "delete interface vmxnet3",
137 .short_help = "delete interface vmxnet3 "
138 "{<interface> | sw_if_index <sw_idx>}",
139 .function = vmxnet3_delete_command_fn,
143 static clib_error_t *
144 vmxnet3_test_command_fn (vlib_main_t * vm, unformat_input_t * input,
145 vlib_cli_command_t * cmd)
147 unformat_input_t _line_input, *line_input = &_line_input;
148 u32 sw_if_index = ~0;
149 vnet_hw_interface_t *hw;
150 vmxnet3_main_t *vmxm = &vmxnet3_main;
151 vmxnet3_device_t *vd;
152 vnet_main_t *vnm = vnet_get_main ();
153 int enable_elog = 0, disable_elog = 0;
155 /* Get a line of input. */
156 if (!unformat_user (input, unformat_line_input, line_input))
159 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
161 if (unformat (line_input, "sw_if_index %d", &sw_if_index))
163 else if (unformat (line_input, "elog-on"))
165 else if (unformat (line_input, "elog-off"))
167 else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
171 return clib_error_return (0, "unknown input `%U'",
172 format_unformat_error, input);
174 unformat_free (line_input);
176 if (sw_if_index == ~0)
177 return clib_error_return (0,
178 "please specify interface name or sw_if_index");
180 hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
181 if (hw == NULL || vmxnet3_device_class.index != hw->dev_class_index)
182 return clib_error_return (0, "not a vmxnet3 interface");
184 vd = pool_elt_at_index (vmxm->devices, hw->dev_instance);
187 vd->flags |= VMXNET3_DEVICE_F_ELOG;
190 vd->flags &= ~VMXNET3_DEVICE_F_ELOG;
196 VLIB_CLI_COMMAND (vmxnet3_test_command, static) = {
197 .path = "test vmxnet3",
198 .short_help = "test vmxnet3 <interface> | sw_if_index <sw_idx> [irq] "
199 "[elog-on] [elog-off]",
200 .function = vmxnet3_test_command_fn,
205 show_vmxnet3 (vlib_main_t * vm, u32 * hw_if_indices, u8 show_descr,
206 u8 show_one_table, u32 which, u8 show_one_slot, u32 slot)
209 vmxnet3_device_t *vd;
210 vnet_main_t *vnm = &vnet_main;
211 vmxnet3_main_t *vmxm = &vmxnet3_main;
212 vnet_hw_interface_t *hi;
214 vmxnet3_rx_desc *rxd;
215 vmxnet3_rx_comp *rx_comp;
217 vmxnet3_tx_desc *txd;
218 vmxnet3_tx_comp *tx_comp;
221 vlib_cli_output (vm, "Global:");
222 for (u32 tid = 0; tid <= vlib_num_workers (); tid++)
224 vmxnet3_per_thread_data_t *ptd =
225 vec_elt_at_index (vmxm->per_thread_data, tid);
226 vlib_cli_output (vm, " Thread %u: polling queue count %u", tid,
227 ptd->polling_q_count);
233 for (i = 0; i < vec_len (hw_if_indices); i++)
235 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
236 vd = vec_elt_at_index (vmxm->devices, hi->dev_instance);
237 vlib_cli_output (vm, "Interface: %U (ifindex %d)",
238 format_vnet_hw_if_index_name, vnm, hw_if_indices[i],
240 vlib_cli_output (vm, " Version: %u", vd->version);
241 vlib_cli_output (vm, " GSO enable: %u", vd->gso_enable);
242 vlib_cli_output (vm, " PCI Address: %U", format_vlib_pci_addr,
244 vlib_cli_output (vm, " Mac Address: %U", format_ethernet_address,
246 vlib_cli_output (vm, " hw if index: %u", vd->hw_if_index);
247 vlib_cli_output (vm, " Device instance: %u", vd->dev_instance);
248 vlib_cli_output (vm, " Number of interrupts: %u", vd->num_intrs);
250 vec_foreach_index (qid, vd->rxqs)
252 rxq = vec_elt_at_index (vd->rxqs, qid);
255 vlib_cli_output (vm, " Queue %u (RX)", qid);
256 vlib_cli_output (vm, " RX completion next index %u",
257 rxq->rx_comp_ring.next);
258 vlib_cli_output (vm, " RX completion generation flag 0x%x",
259 rxq->rx_comp_ring.gen);
261 /* RX descriptors tables */
262 for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
264 vmxnet3_rx_ring *ring = &rxq->rx_ring[rid];
267 " ring %u size %u fill %u "
268 "consume %u produce %u", rid,
269 rxq->size, ring->fill, ring->consume,
273 vlib_cli_output (vm, "RX descriptors table");
274 vlib_cli_output (vm, " %5s %18s %10s",
275 "slot", "address", "flags");
276 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
278 rxd = &rxq->rx_desc[rid][desc_idx];
279 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x",
280 desc_idx, rxd->address, rxd->flags);
283 else if (show_one_table)
285 if (((which == VMXNET3_SHOW_RX_DESC0) && (rid == 0)) ||
286 ((which == VMXNET3_SHOW_RX_DESC1) && (rid == 1)))
288 vlib_cli_output (vm, "RX descriptors table");
289 vlib_cli_output (vm, " %5s %18s %10s",
290 "slot", "address", "flags");
293 rxd = &rxq->rx_desc[rid][slot];
294 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x",
295 slot, rxd->address, rxd->flags);
298 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
300 rxd = &rxq->rx_desc[rid][desc_idx];
301 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x",
302 desc_idx, rxd->address,
309 /* RX completion table */
312 vlib_cli_output (vm, "RX completion descriptors table");
313 vlib_cli_output (vm, " %5s %10s %10s %10s %10s",
314 "slot", "index", "rss", "len", "flags");
315 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
317 rx_comp = &rxq->rx_comp[desc_idx];
318 vlib_cli_output (vm, " %5u 0x%08x %10u %10u 0x%08x",
319 desc_idx, rx_comp->index, rx_comp->rss,
320 rx_comp->len, rx_comp->flags);
323 else if (show_one_table)
325 if (which == VMXNET3_SHOW_RX_COMP)
327 vlib_cli_output (vm, "RX completion descriptors table");
328 vlib_cli_output (vm, " %5s %10s %10s %10s %10s",
329 "slot", "index", "rss", "len", "flags");
332 rx_comp = &rxq->rx_comp[slot];
333 vlib_cli_output (vm, " %5u 0x%08x %10u %10u 0x%08x",
334 slot, rx_comp->index, rx_comp->rss,
335 rx_comp->len, rx_comp->flags);
338 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
340 rx_comp = &rxq->rx_comp[desc_idx];
342 " %5u 0x%08x %10u %10u 0x%08x",
343 desc_idx, rx_comp->index, rx_comp->rss,
344 rx_comp->len, rx_comp->flags);
350 vec_foreach_index (qid, vd->txqs)
352 txq = vec_elt_at_index (vd->txqs, qid);
353 vlib_cli_output (vm, " Queue %u (TX)", qid);
354 vlib_cli_output (vm, " TX completion next index %u",
355 txq->tx_comp_ring.next);
356 vlib_cli_output (vm, " TX completion generation flag 0x%x",
357 txq->tx_comp_ring.gen);
358 vlib_cli_output (vm, " size %u consume %u produce %u",
359 txq->size, txq->tx_ring.consume,
360 txq->tx_ring.produce);
363 vlib_cli_output (vm, "TX descriptors table");
364 vlib_cli_output (vm, " %5s %18s %10s %10s",
365 "slot", "address", "flags0", "flags1");
366 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
368 txd = &txq->tx_desc[desc_idx];
369 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x 0x%08x",
370 desc_idx, txd->address, txd->flags[0],
374 vlib_cli_output (vm, "TX completion descriptors table");
375 vlib_cli_output (vm, " %5s %10s %10s",
376 "slot", "index", "flags");
377 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
379 tx_comp = &txq->tx_comp[desc_idx];
380 vlib_cli_output (vm, " %5u 0x%08x 0x%08x",
381 desc_idx, tx_comp->index, tx_comp->flags);
384 else if (show_one_table)
386 if (which == VMXNET3_SHOW_TX_DESC)
388 vlib_cli_output (vm, "TX descriptors table");
389 vlib_cli_output (vm, " %5s %18s %10s %10s",
390 "slot", "address", "flags0", "flags1");
393 txd = &txq->tx_desc[slot];
394 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x 0x%08x",
395 slot, txd->address, txd->flags[0],
399 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
401 txd = &txq->tx_desc[desc_idx];
402 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x 0x%08x",
403 desc_idx, txd->address, txd->flags[0],
407 else if (which == VMXNET3_SHOW_TX_COMP)
409 vlib_cli_output (vm, "TX completion descriptors table");
410 vlib_cli_output (vm, " %5s %10s %10s",
411 "slot", "index", "flags");
414 tx_comp = &txq->tx_comp[slot];
415 vlib_cli_output (vm, " %5u 0x%08x 0x%08x",
416 slot, tx_comp->index, tx_comp->flags);
419 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
421 tx_comp = &txq->tx_comp[desc_idx];
422 vlib_cli_output (vm, " %5u 0x%08x 0x%08x",
423 desc_idx, tx_comp->index,
432 static clib_error_t *
433 show_vmxnet3_fn (vlib_main_t * vm, unformat_input_t * input,
434 vlib_cli_command_t * cmd)
436 vmxnet3_main_t *vmxm = &vmxnet3_main;
437 vnet_main_t *vnm = &vnet_main;
438 vmxnet3_device_t *vd;
439 clib_error_t *error = 0;
440 u32 hw_if_index, *hw_if_indices = 0;
441 vnet_hw_interface_t *hi = 0;
442 u8 show_descr = 0, show_one_table = 0, show_one_slot = 0;
443 u32 which = ~0, slot;
445 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
448 (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
450 hi = vnet_get_hw_interface (vnm, hw_if_index);
451 if (vmxnet3_device_class.index != hi->dev_class_index)
453 error = clib_error_return (0, "unknown input `%U'",
454 format_unformat_error, input);
457 vec_add1 (hw_if_indices, hw_if_index);
459 else if (unformat (input, "desc"))
463 vmxnet3_device_t *vd =
464 vec_elt_at_index (vmxm->devices, hi->dev_instance);
466 if (unformat (input, "rx-comp"))
469 which = VMXNET3_SHOW_RX_COMP;
470 if (unformat (input, "%u", &slot))
472 vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, 0);
474 if (slot >= rxq->size)
476 error = clib_error_return (0,
477 "slot size must be < rx queue "
478 "size %u", rxq->size);
484 else if (unformat (input, "rx-desc-0"))
487 which = VMXNET3_SHOW_RX_DESC0;
488 if (unformat (input, "%u", &slot))
490 vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, 0);
492 if (slot >= rxq->size)
494 error = clib_error_return (0,
495 "slot size must be < rx queue "
496 "size %u", rxq->size);
502 else if (unformat (input, "rx-desc-1"))
505 which = VMXNET3_SHOW_RX_DESC1;
506 if (unformat (input, "%u", &slot))
508 vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, 0);
510 if (slot >= rxq->size)
512 error = clib_error_return (0,
513 "slot size must be < rx queue "
514 "size %u", rxq->size);
520 else if (unformat (input, "tx-comp"))
523 which = VMXNET3_SHOW_TX_COMP;
524 if (unformat (input, "%u", &slot))
526 vmxnet3_txq_t *txq = vec_elt_at_index (vd->txqs, 0);
528 if (slot >= txq->size)
530 error = clib_error_return (0,
531 "slot size must be < tx queue "
532 "size %u", txq->size);
538 else if (unformat (input, "tx-desc"))
541 which = VMXNET3_SHOW_TX_DESC;
542 if (unformat (input, "%u", &slot))
544 vmxnet3_txq_t *txq = vec_elt_at_index (vd->txqs, 0);
546 if (slot >= txq->size)
548 error = clib_error_return (0,
549 "slot size must be < tx queue "
550 "size %u", txq->size);
558 error = clib_error_return (0, "unknown input `%U'",
559 format_unformat_error, input);
565 error = clib_error_return (0, "unknown input `%U'",
566 format_unformat_error, input);
571 if (vec_len (hw_if_indices) == 0)
573 pool_foreach (vd, vmxm->devices)
574 vec_add1 (hw_if_indices, vd->hw_if_index);
577 show_vmxnet3 (vm, hw_if_indices, show_descr, show_one_table, which,
578 show_one_slot, slot);
581 vec_free (hw_if_indices);
586 VLIB_CLI_COMMAND (show_vmxnet3_command, static) = {
587 .path = "show vmxnet3",
588 .short_help = "show vmxnet3 [[<interface>] ([desc] | ([rx-comp] | "
589 "[rx-desc-0] | [rx-desc-1] | [tx-comp] | [tx-desc]) [<slot>])]",
590 .function = show_vmxnet3_fn,
595 vmxnet3_cli_init (vlib_main_t * vm)
597 vmxnet3_main_t *vmxm = &vmxnet3_main;
598 vlib_thread_main_t *tm = vlib_get_thread_main ();
600 /* initialize binary API */
601 vmxnet3_plugin_api_hookup (vm);
603 vmxm->log_default = vlib_log_register_class ("vmxnet3", 0);
605 vec_validate (vmxm->per_thread_data, tm->n_vlib_mains - 1);
609 VLIB_INIT_FUNCTION (vmxnet3_cli_init);
612 * fd.io coding-style-patch-verification: ON
615 * eval: (c-set-style "gnu")