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 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)
190 vmxnet3_device_t *vd;
191 vnet_main_t *vnm = &vnet_main;
192 vmxnet3_main_t *vmxm = &vmxnet3_main;
193 vnet_hw_interface_t *hi;
195 vmxnet3_rx_desc *rxd;
196 vmxnet3_rx_comp *rx_comp;
198 vmxnet3_tx_desc *txd;
199 vmxnet3_tx_comp *tx_comp;
205 for (i = 0; i < vec_len (hw_if_indices); i++)
207 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
208 vd = vec_elt_at_index (vmxm->devices, hi->dev_instance);
209 vlib_cli_output (vm, "Interface: %s (ifindex %d)",
210 hi->name, hw_if_indices[i]);
211 vlib_cli_output (vm, " Version: %u", vd->version);
212 vlib_cli_output (vm, " PCI Address: %U", format_vlib_pci_addr,
214 vlib_cli_output (vm, " Mac Address: %U", format_ethernet_address,
216 vlib_cli_output (vm, " hw if index: %u", vd->hw_if_index);
217 vlib_cli_output (vm, " Device instance: %u", vd->dev_instance);
218 vlib_cli_output (vm, " Number of interrupts: %u", vd->num_intrs);
220 vec_foreach_index (qid, vd->rxqs)
222 rxq = vec_elt_at_index (vd->rxqs, qid);
225 vlib_cli_output (vm, " Queue %u (RX)", qid);
226 vlib_cli_output (vm, " RX completion next index %u",
227 rxq->rx_comp_ring.next);
228 for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
230 vmxnet3_rx_ring *ring = &rxq->rx_ring[rid];
233 " ring %u size %u fill %u "
234 "consume %u produce %u", rid,
235 rxq->size, ring->fill, ring->consume,
239 vlib_cli_output (vm, "RX descriptors table");
240 vlib_cli_output (vm, " %5s %18s %10s",
241 "slot", "address", "flags");
242 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
244 rxd = &rxq->rx_desc[rid][desc_idx];
245 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x",
246 desc_idx, rxd->address, rxd->flags);
248 vlib_cli_output (vm, "RX completion descriptors table");
249 vlib_cli_output (vm, " %5s %10s %10s %10s %10s",
250 "slot", "index", "rss", "len", "flags");
251 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
253 rx_comp = &rxq->rx_comp[desc_idx];
254 vlib_cli_output (vm, " %5u 0x%08x %10u %10u 0x%08x",
255 desc_idx, rx_comp->index, rx_comp->rss,
256 rx_comp->len, rx_comp->flags);
262 vec_foreach_index (qid, vd->rxqs)
264 txq = vec_elt_at_index (vd->txqs, 0);
265 vlib_cli_output (vm, " Queue %u (TX)", qid);
266 vlib_cli_output (vm, " TX completion next index %u",
267 txq->tx_comp_ring.next);
268 vlib_cli_output (vm, " size %u consume %u produce %u",
269 txq->size, txq->tx_ring.consume,
270 txq->tx_ring.produce);
273 vlib_cli_output (vm, "TX descriptors table");
274 vlib_cli_output (vm, " %5s %18s %10s %10s",
275 "slot", "address", "flags0", "flags1");
276 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
278 txd = &txq->tx_desc[desc_idx];
279 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x 0x%08x",
280 desc_idx, txd->address, txd->flags[0],
283 vlib_cli_output (vm, "TX completion descriptors table");
284 vlib_cli_output (vm, " %5s %10s %10s",
285 "slot", "index", "flags");
286 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
288 tx_comp = &txq->tx_comp[desc_idx];
289 vlib_cli_output (vm, " %5u 0x%08x 0x%08x",
290 desc_idx, tx_comp->index, tx_comp->flags);
297 static clib_error_t *
298 show_vmxnet3_fn (vlib_main_t * vm, unformat_input_t * input,
299 vlib_cli_command_t * cmd)
301 vmxnet3_main_t *vmxm = &vmxnet3_main;
302 vnet_main_t *vnm = &vnet_main;
303 vmxnet3_device_t *vd;
304 clib_error_t *error = 0;
305 u32 hw_if_index, *hw_if_indices = 0;
306 vnet_hw_interface_t *hi;
309 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
312 (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
314 hi = vnet_get_hw_interface (vnm, hw_if_index);
315 if (vmxnet3_device_class.index != hi->dev_class_index)
317 error = clib_error_return (0, "unknown input `%U'",
318 format_unformat_error, input);
321 vec_add1 (hw_if_indices, hw_if_index);
323 else if (unformat (input, "descriptors") || unformat (input, "desc"))
327 error = clib_error_return (0, "unknown input `%U'",
328 format_unformat_error, input);
333 if (vec_len (hw_if_indices) == 0)
335 pool_foreach (vd, vmxm->devices,
336 vec_add1 (hw_if_indices, vd->hw_if_index);
340 show_vmxnet3 (vm, hw_if_indices, show_descr);
343 vec_free (hw_if_indices);
348 VLIB_CLI_COMMAND (show_vmxnet3_command, static) = {
349 .path = "show vmxnet3",
350 .short_help = "show vmxnet3 [<interface>]",
351 .function = show_vmxnet3_fn,
356 vmxnet3_cli_init (vlib_main_t * vm)
358 /* initialize binary API */
359 vmxnet3_plugin_api_hookup (vm);
364 VLIB_INIT_FUNCTION (vmxnet3_cli_init);
367 * fd.io coding-style-patch-verification: ON
370 * eval: (c-set-style "gnu")