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 for (i = 0; i < vec_len (hw_if_indices); i++)
210 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
211 vd = vec_elt_at_index (vmxm->devices, hi->dev_instance);
212 vlib_cli_output (vm, "Interface: %U (ifindex %d)",
213 format_vnet_hw_if_index_name, vnm, hw_if_indices[i],
215 vlib_cli_output (vm, " Version: %u", vd->version);
216 vlib_cli_output (vm, " PCI Address: %U", format_vlib_pci_addr,
218 vlib_cli_output (vm, " Mac Address: %U", format_ethernet_address,
220 vlib_cli_output (vm, " hw if index: %u", vd->hw_if_index);
221 vlib_cli_output (vm, " Device instance: %u", vd->dev_instance);
222 vlib_cli_output (vm, " Number of interrupts: %u", vd->num_intrs);
224 vec_foreach_index (qid, vd->rxqs)
226 rxq = vec_elt_at_index (vd->rxqs, qid);
229 vlib_cli_output (vm, " Queue %u (RX)", qid);
230 vlib_cli_output (vm, " RX completion next index %u",
231 rxq->rx_comp_ring.next);
232 vlib_cli_output (vm, " RX completion generation flag 0x%x",
233 rxq->rx_comp_ring.gen);
235 /* RX descriptors tables */
236 for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
238 vmxnet3_rx_ring *ring = &rxq->rx_ring[rid];
241 " ring %u size %u fill %u "
242 "consume %u produce %u", rid,
243 rxq->size, ring->fill, ring->consume,
247 vlib_cli_output (vm, "RX descriptors table");
248 vlib_cli_output (vm, " %5s %18s %10s",
249 "slot", "address", "flags");
250 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
252 rxd = &rxq->rx_desc[rid][desc_idx];
253 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x",
254 desc_idx, rxd->address, rxd->flags);
257 else if (show_one_table)
259 if (((which == VMXNET3_SHOW_RX_DESC0) && (rid == 0)) ||
260 ((which == VMXNET3_SHOW_RX_DESC1) && (rid == 1)))
262 vlib_cli_output (vm, "RX descriptors table");
263 vlib_cli_output (vm, " %5s %18s %10s",
264 "slot", "address", "flags");
267 rxd = &rxq->rx_desc[rid][slot];
268 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x",
269 slot, rxd->address, rxd->flags);
272 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
274 rxd = &rxq->rx_desc[rid][desc_idx];
275 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x",
276 desc_idx, rxd->address,
283 /* RX completion table */
286 vlib_cli_output (vm, "RX completion descriptors table");
287 vlib_cli_output (vm, " %5s %10s %10s %10s %10s",
288 "slot", "index", "rss", "len", "flags");
289 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
291 rx_comp = &rxq->rx_comp[desc_idx];
292 vlib_cli_output (vm, " %5u 0x%08x %10u %10u 0x%08x",
293 desc_idx, rx_comp->index, rx_comp->rss,
294 rx_comp->len, rx_comp->flags);
297 else if (show_one_table)
299 if (which == VMXNET3_SHOW_RX_COMP)
301 vlib_cli_output (vm, "RX completion descriptors table");
302 vlib_cli_output (vm, " %5s %10s %10s %10s %10s",
303 "slot", "index", "rss", "len", "flags");
306 rx_comp = &rxq->rx_comp[slot];
307 vlib_cli_output (vm, " %5u 0x%08x %10u %10u 0x%08x",
308 slot, rx_comp->index, rx_comp->rss,
309 rx_comp->len, rx_comp->flags);
312 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
314 rx_comp = &rxq->rx_comp[desc_idx];
316 " %5u 0x%08x %10u %10u 0x%08x",
317 desc_idx, rx_comp->index, rx_comp->rss,
318 rx_comp->len, rx_comp->flags);
324 vec_foreach_index (qid, vd->txqs)
326 txq = vec_elt_at_index (vd->txqs, qid);
327 vlib_cli_output (vm, " Queue %u (TX)", qid);
328 vlib_cli_output (vm, " TX completion next index %u",
329 txq->tx_comp_ring.next);
330 vlib_cli_output (vm, " TX completion generation flag 0x%x",
331 txq->tx_comp_ring.gen);
332 vlib_cli_output (vm, " size %u consume %u produce %u",
333 txq->size, txq->tx_ring.consume,
334 txq->tx_ring.produce);
337 vlib_cli_output (vm, "TX descriptors table");
338 vlib_cli_output (vm, " %5s %18s %10s %10s",
339 "slot", "address", "flags0", "flags1");
340 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
342 txd = &txq->tx_desc[desc_idx];
343 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x 0x%08x",
344 desc_idx, txd->address, txd->flags[0],
348 vlib_cli_output (vm, "TX completion descriptors table");
349 vlib_cli_output (vm, " %5s %10s %10s",
350 "slot", "index", "flags");
351 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
353 tx_comp = &txq->tx_comp[desc_idx];
354 vlib_cli_output (vm, " %5u 0x%08x 0x%08x",
355 desc_idx, tx_comp->index, tx_comp->flags);
358 else if (show_one_table)
360 if (which == VMXNET3_SHOW_TX_DESC)
362 vlib_cli_output (vm, "TX descriptors table");
363 vlib_cli_output (vm, " %5s %18s %10s %10s",
364 "slot", "address", "flags0", "flags1");
367 txd = &txq->tx_desc[slot];
368 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x 0x%08x",
369 slot, txd->address, txd->flags[0],
373 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
375 txd = &txq->tx_desc[desc_idx];
376 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x 0x%08x",
377 desc_idx, txd->address, txd->flags[0],
381 else if (which == VMXNET3_SHOW_TX_COMP)
383 vlib_cli_output (vm, "TX completion descriptors table");
384 vlib_cli_output (vm, " %5s %10s %10s",
385 "slot", "index", "flags");
388 tx_comp = &txq->tx_comp[slot];
389 vlib_cli_output (vm, " %5u 0x%08x 0x%08x",
390 slot, tx_comp->index, tx_comp->flags);
393 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
395 tx_comp = &txq->tx_comp[desc_idx];
396 vlib_cli_output (vm, " %5u 0x%08x 0x%08x",
397 desc_idx, tx_comp->index,
406 static clib_error_t *
407 show_vmxnet3_fn (vlib_main_t * vm, unformat_input_t * input,
408 vlib_cli_command_t * cmd)
410 vmxnet3_main_t *vmxm = &vmxnet3_main;
411 vnet_main_t *vnm = &vnet_main;
412 vmxnet3_device_t *vd;
413 clib_error_t *error = 0;
414 u32 hw_if_index, *hw_if_indices = 0;
415 vnet_hw_interface_t *hi = 0;
416 u8 show_descr = 0, show_one_table = 0, show_one_slot = 0;
417 u32 which = ~0, slot;
419 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
422 (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
424 hi = vnet_get_hw_interface (vnm, hw_if_index);
425 if (vmxnet3_device_class.index != hi->dev_class_index)
427 error = clib_error_return (0, "unknown input `%U'",
428 format_unformat_error, input);
431 vec_add1 (hw_if_indices, hw_if_index);
433 else if (unformat (input, "desc"))
437 vmxnet3_device_t *vd =
438 vec_elt_at_index (vmxm->devices, hi->dev_instance);
440 if (unformat (input, "rx-comp"))
443 which = VMXNET3_SHOW_RX_COMP;
444 if (unformat (input, "%u", &slot))
446 vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, 0);
448 if (slot >= rxq->size)
450 error = clib_error_return (0,
451 "slot size must be < rx queue "
452 "size %u", rxq->size);
458 else if (unformat (input, "rx-desc-0"))
461 which = VMXNET3_SHOW_RX_DESC0;
462 if (unformat (input, "%u", &slot))
464 vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, 0);
466 if (slot >= rxq->size)
468 error = clib_error_return (0,
469 "slot size must be < rx queue "
470 "size %u", rxq->size);
476 else if (unformat (input, "rx-desc-1"))
479 which = VMXNET3_SHOW_RX_DESC1;
480 if (unformat (input, "%u", &slot))
482 vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, 0);
484 if (slot >= rxq->size)
486 error = clib_error_return (0,
487 "slot size must be < rx queue "
488 "size %u", rxq->size);
494 else if (unformat (input, "tx-comp"))
497 which = VMXNET3_SHOW_TX_COMP;
498 if (unformat (input, "%u", &slot))
500 vmxnet3_txq_t *txq = vec_elt_at_index (vd->txqs, 0);
502 if (slot >= txq->size)
504 error = clib_error_return (0,
505 "slot size must be < tx queue "
506 "size %u", txq->size);
512 else if (unformat (input, "tx-desc"))
515 which = VMXNET3_SHOW_TX_DESC;
516 if (unformat (input, "%u", &slot))
518 vmxnet3_txq_t *txq = vec_elt_at_index (vd->txqs, 0);
520 if (slot >= txq->size)
522 error = clib_error_return (0,
523 "slot size must be < tx queue "
524 "size %u", txq->size);
532 error = clib_error_return (0, "unknown input `%U'",
533 format_unformat_error, input);
539 error = clib_error_return (0, "unknown input `%U'",
540 format_unformat_error, input);
545 if (vec_len (hw_if_indices) == 0)
547 pool_foreach (vd, vmxm->devices,
548 vec_add1 (hw_if_indices, vd->hw_if_index);
552 show_vmxnet3 (vm, hw_if_indices, show_descr, show_one_table, which,
553 show_one_slot, slot);
556 vec_free (hw_if_indices);
561 VLIB_CLI_COMMAND (show_vmxnet3_command, static) = {
562 .path = "show vmxnet3",
563 .short_help = "show vmxnet3 [[<interface>] ([desc] | ([rx-comp] | "
564 "[rx-desc-0] | [rx-desc-1] | [tx-comp] | [tx-desc]) [<slot>])]",
565 .function = show_vmxnet3_fn,
570 vmxnet3_cli_init (vlib_main_t * vm)
572 vmxnet3_main_t *vmxm = &vmxnet3_main;
574 /* initialize binary API */
575 vmxnet3_plugin_api_hookup (vm);
577 vmxm->log_default = vlib_log_register_class ("vmxnet3", 0);
581 VLIB_INIT_FUNCTION (vmxnet3_cli_init);
584 * fd.io coding-style-patch-verification: ON
587 * eval: (c-set-style "gnu")