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: %U (ifindex %d)",
210 format_vnet_hw_if_index_name, vnm, hw_if_indices[i],
212 vlib_cli_output (vm, " Version: %u", vd->version);
213 vlib_cli_output (vm, " PCI Address: %U", format_vlib_pci_addr,
215 vlib_cli_output (vm, " Mac Address: %U", format_ethernet_address,
217 vlib_cli_output (vm, " hw if index: %u", vd->hw_if_index);
218 vlib_cli_output (vm, " Device instance: %u", vd->dev_instance);
219 vlib_cli_output (vm, " Number of interrupts: %u", vd->num_intrs);
221 vec_foreach_index (qid, vd->rxqs)
223 rxq = vec_elt_at_index (vd->rxqs, qid);
226 vlib_cli_output (vm, " Queue %u (RX)", qid);
227 vlib_cli_output (vm, " RX completion next index %u",
228 rxq->rx_comp_ring.next);
229 for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
231 vmxnet3_rx_ring *ring = &rxq->rx_ring[rid];
234 " ring %u size %u fill %u "
235 "consume %u produce %u", rid,
236 rxq->size, ring->fill, ring->consume,
240 vlib_cli_output (vm, "RX descriptors table");
241 vlib_cli_output (vm, " %5s %18s %10s",
242 "slot", "address", "flags");
243 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
245 rxd = &rxq->rx_desc[rid][desc_idx];
246 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x",
247 desc_idx, rxd->address, rxd->flags);
249 vlib_cli_output (vm, "RX completion descriptors table");
250 vlib_cli_output (vm, " %5s %10s %10s %10s %10s",
251 "slot", "index", "rss", "len", "flags");
252 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
254 rx_comp = &rxq->rx_comp[desc_idx];
255 vlib_cli_output (vm, " %5u 0x%08x %10u %10u 0x%08x",
256 desc_idx, rx_comp->index, rx_comp->rss,
257 rx_comp->len, rx_comp->flags);
263 vec_foreach_index (qid, vd->rxqs)
265 txq = vec_elt_at_index (vd->txqs, 0);
266 vlib_cli_output (vm, " Queue %u (TX)", qid);
267 vlib_cli_output (vm, " TX completion next index %u",
268 txq->tx_comp_ring.next);
269 vlib_cli_output (vm, " size %u consume %u produce %u",
270 txq->size, txq->tx_ring.consume,
271 txq->tx_ring.produce);
274 vlib_cli_output (vm, "TX descriptors table");
275 vlib_cli_output (vm, " %5s %18s %10s %10s",
276 "slot", "address", "flags0", "flags1");
277 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
279 txd = &txq->tx_desc[desc_idx];
280 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x 0x%08x",
281 desc_idx, txd->address, txd->flags[0],
284 vlib_cli_output (vm, "TX completion descriptors table");
285 vlib_cli_output (vm, " %5s %10s %10s",
286 "slot", "index", "flags");
287 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
289 tx_comp = &txq->tx_comp[desc_idx];
290 vlib_cli_output (vm, " %5u 0x%08x 0x%08x",
291 desc_idx, tx_comp->index, tx_comp->flags);
298 static clib_error_t *
299 show_vmxnet3_fn (vlib_main_t * vm, unformat_input_t * input,
300 vlib_cli_command_t * cmd)
302 vmxnet3_main_t *vmxm = &vmxnet3_main;
303 vnet_main_t *vnm = &vnet_main;
304 vmxnet3_device_t *vd;
305 clib_error_t *error = 0;
306 u32 hw_if_index, *hw_if_indices = 0;
307 vnet_hw_interface_t *hi;
310 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
313 (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
315 hi = vnet_get_hw_interface (vnm, hw_if_index);
316 if (vmxnet3_device_class.index != hi->dev_class_index)
318 error = clib_error_return (0, "unknown input `%U'",
319 format_unformat_error, input);
322 vec_add1 (hw_if_indices, hw_if_index);
324 else if (unformat (input, "descriptors") || unformat (input, "desc"))
328 error = clib_error_return (0, "unknown input `%U'",
329 format_unformat_error, input);
334 if (vec_len (hw_if_indices) == 0)
336 pool_foreach (vd, vmxm->devices,
337 vec_add1 (hw_if_indices, vd->hw_if_index);
341 show_vmxnet3 (vm, hw_if_indices, show_descr);
344 vec_free (hw_if_indices);
349 VLIB_CLI_COMMAND (show_vmxnet3_command, static) = {
350 .path = "show vmxnet3",
351 .short_help = "show vmxnet3 [<interface>]",
352 .function = show_vmxnet3_fn,
357 vmxnet3_cli_init (vlib_main_t * vm)
359 /* initialize binary API */
360 vmxnet3_plugin_api_hookup (vm);
365 VLIB_INIT_FUNCTION (vmxnet3_cli_init);
368 * fd.io coding-style-patch-verification: ON
371 * eval: (c-set-style "gnu")