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, "rx-queue-size %u", &tmp))
50 else if (unformat (line_input, "tx-queue-size %u", &tmp))
53 return clib_error_return (0, "unknown input `%U'",
54 format_unformat_error, input);
56 unformat_free (line_input);
59 vmxnet3_create_if (vm, &args);
65 VLIB_CLI_COMMAND (vmxnet3_create_command, static) = {
66 .path = "create interface vmxnet3",
67 .short_help = "create interface vmxnet3 <pci-address>"
68 "[rx-queue-size <size>] [tx-queue-size <size>]",
69 .function = vmxnet3_create_command_fn,
74 vmxnet3_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
75 vlib_cli_command_t * cmd)
77 unformat_input_t _line_input, *line_input = &_line_input;
79 vnet_hw_interface_t *hw;
80 vmxnet3_main_t *vmxm = &vmxnet3_main;
82 vnet_main_t *vnm = vnet_get_main ();
84 /* Get a line of input. */
85 if (!unformat_user (input, unformat_line_input, line_input))
88 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
90 if (unformat (line_input, "sw_if_index %d", &sw_if_index))
92 else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
96 return clib_error_return (0, "unknown input `%U'",
97 format_unformat_error, input);
99 unformat_free (line_input);
101 if (sw_if_index == ~0)
102 return clib_error_return (0,
103 "please specify interface name or sw_if_index");
105 hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
106 if (hw == NULL || vmxnet3_device_class.index != hw->dev_class_index)
107 return clib_error_return (0, "not a vmxnet3 interface");
109 vd = pool_elt_at_index (vmxm->devices, hw->dev_instance);
111 vmxnet3_delete_if (vm, vd);
117 VLIB_CLI_COMMAND (vmxnet3_delete_command, static) = {
118 .path = "delete interface vmxnet3",
119 .short_help = "delete interface vmxnet3 "
120 "{<interface> | sw_if_index <sw_idx>}",
121 .function = vmxnet3_delete_command_fn,
125 static clib_error_t *
126 vmxnet3_test_command_fn (vlib_main_t * vm, unformat_input_t * input,
127 vlib_cli_command_t * cmd)
129 unformat_input_t _line_input, *line_input = &_line_input;
130 u32 sw_if_index = ~0;
131 vnet_hw_interface_t *hw;
132 vmxnet3_main_t *vmxm = &vmxnet3_main;
133 vmxnet3_device_t *vd;
134 vnet_main_t *vnm = vnet_get_main ();
135 int enable_elog = 0, disable_elog = 0;
137 /* Get a line of input. */
138 if (!unformat_user (input, unformat_line_input, line_input))
141 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
143 if (unformat (line_input, "sw_if_index %d", &sw_if_index))
145 else if (unformat (line_input, "elog-on"))
147 else if (unformat (line_input, "elog-off"))
149 else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
153 return clib_error_return (0, "unknown input `%U'",
154 format_unformat_error, input);
156 unformat_free (line_input);
158 if (sw_if_index == ~0)
159 return clib_error_return (0,
160 "please specify interface name or sw_if_index");
162 hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
163 if (hw == NULL || vmxnet3_device_class.index != hw->dev_class_index)
164 return clib_error_return (0, "not a vmxnet3 interface");
166 vd = pool_elt_at_index (vmxm->devices, hw->dev_instance);
169 vd->flags |= VMXNET3_DEVICE_F_ELOG;
172 vd->flags &= ~VMXNET3_DEVICE_F_ELOG;
178 VLIB_CLI_COMMAND (vmxnet3_test_command, static) = {
179 .path = "test vmxnet3",
180 .short_help = "test vmxnet3 <interface> | sw_if_index <sw_idx> [irq] "
181 "[elog-on] [elog-off]",
182 .function = vmxnet3_test_command_fn,
187 show_vmxnet3 (vlib_main_t * vm, u32 * hw_if_indices, u8 show_descr,
188 u8 show_one_table, u32 which, u8 show_one_slot, u32 slot)
191 vmxnet3_device_t *vd;
192 vnet_main_t *vnm = &vnet_main;
193 vmxnet3_main_t *vmxm = &vmxnet3_main;
194 vnet_hw_interface_t *hi;
196 vmxnet3_rx_desc *rxd;
197 vmxnet3_rx_comp *rx_comp;
199 vmxnet3_tx_desc *txd;
200 vmxnet3_tx_comp *tx_comp;
206 for (i = 0; i < vec_len (hw_if_indices); i++)
208 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
209 vd = vec_elt_at_index (vmxm->devices, hi->dev_instance);
210 vlib_cli_output (vm, "Interface: %U (ifindex %d)",
211 format_vnet_hw_if_index_name, vnm, hw_if_indices[i],
213 vlib_cli_output (vm, " Version: %u", vd->version);
214 vlib_cli_output (vm, " PCI Address: %U", format_vlib_pci_addr,
216 vlib_cli_output (vm, " Mac Address: %U", format_ethernet_address,
218 vlib_cli_output (vm, " hw if index: %u", vd->hw_if_index);
219 vlib_cli_output (vm, " Device instance: %u", vd->dev_instance);
220 vlib_cli_output (vm, " Number of interrupts: %u", vd->num_intrs);
222 vec_foreach_index (qid, vd->rxqs)
224 rxq = vec_elt_at_index (vd->rxqs, qid);
227 vlib_cli_output (vm, " Queue %u (RX)", qid);
228 vlib_cli_output (vm, " RX completion next index %u",
229 rxq->rx_comp_ring.next);
230 vlib_cli_output (vm, " RX completion generation flag 0x%x",
231 rxq->rx_comp_ring.gen);
233 /* RX descriptors tables */
234 for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
236 vmxnet3_rx_ring *ring = &rxq->rx_ring[rid];
239 " ring %u size %u fill %u "
240 "consume %u produce %u", rid,
241 rxq->size, ring->fill, ring->consume,
245 vlib_cli_output (vm, "RX descriptors table");
246 vlib_cli_output (vm, " %5s %18s %10s",
247 "slot", "address", "flags");
248 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
250 rxd = &rxq->rx_desc[rid][desc_idx];
251 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x",
252 desc_idx, rxd->address, rxd->flags);
255 else if (show_one_table)
257 if (((which == VMXNET3_SHOW_RX_DESC0) && (rid == 0)) ||
258 ((which == VMXNET3_SHOW_RX_DESC1) && (rid == 1)))
260 vlib_cli_output (vm, "RX descriptors table");
261 vlib_cli_output (vm, " %5s %18s %10s",
262 "slot", "address", "flags");
265 rxd = &rxq->rx_desc[rid][slot];
266 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x",
267 slot, rxd->address, rxd->flags);
270 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
272 rxd = &rxq->rx_desc[rid][desc_idx];
273 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x",
274 desc_idx, rxd->address,
281 /* RX completion table */
284 vlib_cli_output (vm, "RX completion descriptors table");
285 vlib_cli_output (vm, " %5s %10s %10s %10s %10s",
286 "slot", "index", "rss", "len", "flags");
287 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
289 rx_comp = &rxq->rx_comp[desc_idx];
290 vlib_cli_output (vm, " %5u 0x%08x %10u %10u 0x%08x",
291 desc_idx, rx_comp->index, rx_comp->rss,
292 rx_comp->len, rx_comp->flags);
295 else if (show_one_table)
297 if (which == VMXNET3_SHOW_RX_COMP)
299 vlib_cli_output (vm, "RX completion descriptors table");
300 vlib_cli_output (vm, " %5s %10s %10s %10s %10s",
301 "slot", "index", "rss", "len", "flags");
304 rx_comp = &rxq->rx_comp[slot];
305 vlib_cli_output (vm, " %5u 0x%08x %10u %10u 0x%08x",
306 slot, rx_comp->index, rx_comp->rss,
307 rx_comp->len, rx_comp->flags);
310 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
312 rx_comp = &rxq->rx_comp[desc_idx];
314 " %5u 0x%08x %10u %10u 0x%08x",
315 desc_idx, rx_comp->index, rx_comp->rss,
316 rx_comp->len, rx_comp->flags);
322 vec_foreach_index (qid, vd->rxqs)
324 txq = vec_elt_at_index (vd->txqs, 0);
325 vlib_cli_output (vm, " Queue %u (TX)", qid);
326 vlib_cli_output (vm, " TX completion next index %u",
327 txq->tx_comp_ring.next);
328 vlib_cli_output (vm, " TX completion generation flag 0x%x",
329 txq->tx_comp_ring.gen);
330 vlib_cli_output (vm, " size %u consume %u produce %u",
331 txq->size, txq->tx_ring.consume,
332 txq->tx_ring.produce);
335 vlib_cli_output (vm, "TX descriptors table");
336 vlib_cli_output (vm, " %5s %18s %10s %10s",
337 "slot", "address", "flags0", "flags1");
338 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
340 txd = &txq->tx_desc[desc_idx];
341 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x 0x%08x",
342 desc_idx, txd->address, txd->flags[0],
346 vlib_cli_output (vm, "TX completion descriptors table");
347 vlib_cli_output (vm, " %5s %10s %10s",
348 "slot", "index", "flags");
349 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
351 tx_comp = &txq->tx_comp[desc_idx];
352 vlib_cli_output (vm, " %5u 0x%08x 0x%08x",
353 desc_idx, tx_comp->index, tx_comp->flags);
356 else if (show_one_table)
358 if (which == VMXNET3_SHOW_TX_DESC)
360 vlib_cli_output (vm, "TX descriptors table");
361 vlib_cli_output (vm, " %5s %18s %10s %10s",
362 "slot", "address", "flags0", "flags1");
365 txd = &txq->tx_desc[slot];
366 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x 0x%08x",
367 slot, txd->address, txd->flags[0],
371 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
373 txd = &txq->tx_desc[desc_idx];
374 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x 0x%08x",
375 desc_idx, txd->address, txd->flags[0],
379 else if (which == VMXNET3_SHOW_TX_COMP)
381 vlib_cli_output (vm, "TX completion descriptors table");
382 vlib_cli_output (vm, " %5s %10s %10s",
383 "slot", "index", "flags");
386 tx_comp = &txq->tx_comp[slot];
387 vlib_cli_output (vm, " %5u 0x%08x 0x%08x",
388 slot, tx_comp->index, tx_comp->flags);
391 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
393 tx_comp = &txq->tx_comp[desc_idx];
394 vlib_cli_output (vm, " %5u 0x%08x 0x%08x",
395 desc_idx, tx_comp->index,
404 static clib_error_t *
405 show_vmxnet3_fn (vlib_main_t * vm, unformat_input_t * input,
406 vlib_cli_command_t * cmd)
408 vmxnet3_main_t *vmxm = &vmxnet3_main;
409 vnet_main_t *vnm = &vnet_main;
410 vmxnet3_device_t *vd;
411 clib_error_t *error = 0;
412 u32 hw_if_index, *hw_if_indices = 0;
413 vnet_hw_interface_t *hi = 0;
414 u8 show_descr = 0, show_one_table = 0, show_one_slot = 0;
415 u32 which = ~0, slot;
417 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
420 (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
422 hi = vnet_get_hw_interface (vnm, hw_if_index);
423 if (vmxnet3_device_class.index != hi->dev_class_index)
425 error = clib_error_return (0, "unknown input `%U'",
426 format_unformat_error, input);
429 vec_add1 (hw_if_indices, hw_if_index);
431 else if (unformat (input, "desc"))
435 vmxnet3_device_t *vd =
436 vec_elt_at_index (vmxm->devices, hi->dev_instance);
438 if (unformat (input, "rx-comp"))
441 which = VMXNET3_SHOW_RX_COMP;
442 if (unformat (input, "%u", &slot))
444 vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, 0);
446 if (slot >= rxq->size)
448 error = clib_error_return (0,
449 "slot size must be < rx queue "
450 "size %u", rxq->size);
456 else if (unformat (input, "rx-desc-0"))
459 which = VMXNET3_SHOW_RX_DESC0;
460 if (unformat (input, "%u", &slot))
462 vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, 0);
464 if (slot >= rxq->size)
466 error = clib_error_return (0,
467 "slot size must be < rx queue "
468 "size %u", rxq->size);
474 else if (unformat (input, "rx-desc-1"))
477 which = VMXNET3_SHOW_RX_DESC1;
478 if (unformat (input, "%u", &slot))
480 vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, 0);
482 if (slot >= rxq->size)
484 error = clib_error_return (0,
485 "slot size must be < rx queue "
486 "size %u", rxq->size);
492 else if (unformat (input, "tx-comp"))
495 which = VMXNET3_SHOW_TX_COMP;
496 if (unformat (input, "%u", &slot))
498 vmxnet3_txq_t *txq = vec_elt_at_index (vd->txqs, 0);
500 if (slot >= txq->size)
502 error = clib_error_return (0,
503 "slot size must be < tx queue "
504 "size %u", txq->size);
510 else if (unformat (input, "tx-desc"))
513 which = VMXNET3_SHOW_TX_DESC;
514 if (unformat (input, "%u", &slot))
516 vmxnet3_txq_t *txq = vec_elt_at_index (vd->txqs, 0);
518 if (slot >= txq->size)
520 error = clib_error_return (0,
521 "slot size must be < tx queue "
522 "size %u", txq->size);
530 error = clib_error_return (0, "unknown input `%U'",
531 format_unformat_error, input);
537 error = clib_error_return (0, "unknown input `%U'",
538 format_unformat_error, input);
543 if (vec_len (hw_if_indices) == 0)
545 pool_foreach (vd, vmxm->devices,
546 vec_add1 (hw_if_indices, vd->hw_if_index);
550 show_vmxnet3 (vm, hw_if_indices, show_descr, show_one_table, which,
551 show_one_slot, slot);
554 vec_free (hw_if_indices);
559 VLIB_CLI_COMMAND (show_vmxnet3_command, static) = {
560 .path = "show vmxnet3",
561 .short_help = "show vmxnet3 [[<interface>] ([desc] | ([rx-comp] | "
562 "[rx-desc-0] | [rx-desc-1] | [tx-comp] | [tx-desc]) [<slot>])]",
563 .function = show_vmxnet3_fn,
568 vmxnet3_cli_init (vlib_main_t * vm)
570 vmxnet3_main_t *vmxm = &vmxnet3_main;
572 /* initialize binary API */
573 vmxnet3_plugin_api_hookup (vm);
575 vmxm->log_default = vlib_log_register_class ("vmxnet3", 0);
579 VLIB_INIT_FUNCTION (vmxnet3_cli_init);
582 * fd.io coding-style-patch-verification: ON
585 * eval: (c-set-style "gnu")