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 = { 0 };
37 /* Get a line of input. */
38 if (!unformat_user (input, unformat_line_input, line_input))
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", &tmp))
49 else if (unformat (line_input, "tx-queue-size %u", &tmp))
52 return clib_error_return (0, "unknown input `%U'",
53 format_unformat_error, input);
55 unformat_free (line_input);
58 vmxnet3_create_if (vm, &args);
64 VLIB_CLI_COMMAND (vmxnet3_create_command, static) = {
65 .path = "create interface vmxnet3",
66 .short_help = "create interface vmxnet3 <pci-address>"
67 "[rx-queue-size <size>] [tx-queue-size <size>]",
68 .function = vmxnet3_create_command_fn,
73 vmxnet3_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
74 vlib_cli_command_t * cmd)
76 unformat_input_t _line_input, *line_input = &_line_input;
78 vnet_hw_interface_t *hw;
79 vmxnet3_main_t *vmxm = &vmxnet3_main;
81 vnet_main_t *vnm = vnet_get_main ();
83 /* Get a line of input. */
84 if (!unformat_user (input, unformat_line_input, line_input))
87 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
89 if (unformat (line_input, "sw_if_index %d", &sw_if_index))
91 else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
95 return clib_error_return (0, "unknown input `%U'",
96 format_unformat_error, input);
98 unformat_free (line_input);
100 if (sw_if_index == ~0)
101 return clib_error_return (0,
102 "please specify interface name or sw_if_index");
104 hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
105 if (hw == NULL || vmxnet3_device_class.index != hw->dev_class_index)
106 return clib_error_return (0, "not a vmxnet3 interface");
108 vd = pool_elt_at_index (vmxm->devices, hw->dev_instance);
110 vmxnet3_delete_if (vm, vd);
116 VLIB_CLI_COMMAND (vmxnet3_delete_command, static) = {
117 .path = "delete interface vmxnet3",
118 .short_help = "delete interface vmxnet3 "
119 "{<interface> | sw_if_index <sw_idx>}",
120 .function = vmxnet3_delete_command_fn,
124 static clib_error_t *
125 vmxnet3_test_command_fn (vlib_main_t * vm, unformat_input_t * input,
126 vlib_cli_command_t * cmd)
128 unformat_input_t _line_input, *line_input = &_line_input;
129 u32 sw_if_index = ~0;
130 vnet_hw_interface_t *hw;
131 vmxnet3_main_t *vmxm = &vmxnet3_main;
132 vmxnet3_device_t *vd;
133 vnet_main_t *vnm = vnet_get_main ();
134 int enable_elog = 0, disable_elog = 0;
136 /* Get a line of input. */
137 if (!unformat_user (input, unformat_line_input, line_input))
140 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
142 if (unformat (line_input, "sw_if_index %d", &sw_if_index))
144 else if (unformat (line_input, "elog-on"))
146 else if (unformat (line_input, "elog-off"))
148 else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
152 return clib_error_return (0, "unknown input `%U'",
153 format_unformat_error, input);
155 unformat_free (line_input);
157 if (sw_if_index == ~0)
158 return clib_error_return (0,
159 "please specify interface name or sw_if_index");
161 hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
162 if (hw == NULL || vmxnet3_device_class.index != hw->dev_class_index)
163 return clib_error_return (0, "not a vmxnet3 interface");
165 vd = pool_elt_at_index (vmxm->devices, hw->dev_instance);
168 vd->flags |= VMXNET3_DEVICE_F_ELOG;
171 vd->flags &= ~VMXNET3_DEVICE_F_ELOG;
177 VLIB_CLI_COMMAND (vmxnet3_test_command, static) = {
178 .path = "test vmxnet3",
179 .short_help = "test vmxnet3 <interface> | sw_if_index <sw_idx> [irq] "
180 "[elog-on] [elog-off]",
181 .function = vmxnet3_test_command_fn,
186 show_vmxnet3 (vlib_main_t * vm, u32 * hw_if_indices, u8 show_descr)
189 vmxnet3_device_t *vd;
190 vnet_main_t *vnm = &vnet_main;
191 vmxnet3_main_t *vmxm = &vmxnet3_main;
192 vnet_hw_interface_t *hi;
194 vmxnet3_rx_desc *rxd;
195 vmxnet3_rx_comp *rx_comp;
197 vmxnet3_tx_desc *txd;
198 vmxnet3_tx_comp *tx_comp;
204 for (i = 0; i < vec_len (hw_if_indices); i++)
206 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
207 vd = vec_elt_at_index (vmxm->devices, hi->dev_instance);
208 vlib_cli_output (vm, "Interface: %s (ifindex %d)",
209 hi->name, hw_if_indices[i]);
210 vlib_cli_output (vm, " Version: %u", vd->version);
211 vlib_cli_output (vm, " PCI Address: %U", format_vlib_pci_addr,
213 vlib_cli_output (vm, " Mac Address: %U", format_ethernet_address,
215 vlib_cli_output (vm, " hw if index: %u", vd->hw_if_index);
216 vlib_cli_output (vm, " Device instance: %u", vd->dev_instance);
217 vlib_cli_output (vm, " Number of interrupts: %u", vd->num_intrs);
219 vec_foreach_index (qid, vd->rxqs)
221 rxq = vec_elt_at_index (vd->rxqs, qid);
224 vlib_cli_output (vm, " Queue %u (RX)", qid);
225 vlib_cli_output (vm, " RX completion next index %u",
226 rxq->rx_comp_ring.next);
227 for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
229 vmxnet3_rx_ring *ring = &rxq->rx_ring[rid];
232 " ring %u size %u fill %u "
233 "consume %u produce %u", rid,
234 rxq->size, ring->fill, ring->consume,
238 vlib_cli_output (vm, "RX descriptors table");
239 vlib_cli_output (vm, " %5s %18s %10s",
240 "slot", "address", "flags");
241 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
243 rxd = &rxq->rx_desc[rid][desc_idx];
244 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x",
245 desc_idx, rxd->address, rxd->flags);
247 vlib_cli_output (vm, "RX completion descriptors table");
248 vlib_cli_output (vm, " %5s %10s %10s %10s %10s",
249 "slot", "index", "rss", "len", "flags");
250 for (desc_idx = 0; desc_idx < rxq->size; desc_idx++)
252 rx_comp = &rxq->rx_comp[desc_idx];
253 vlib_cli_output (vm, " %5u 0x%08x %10u %10u 0x%08x",
254 desc_idx, rx_comp->index, rx_comp->rss,
255 rx_comp->len, rx_comp->flags);
261 vec_foreach_index (qid, vd->rxqs)
263 txq = vec_elt_at_index (vd->txqs, 0);
264 vlib_cli_output (vm, " Queue %u (TX)", qid);
265 vlib_cli_output (vm, " TX completion next index %u",
266 txq->tx_comp_ring.next);
267 vlib_cli_output (vm, " size %u consume %u produce %u",
268 txq->size, txq->tx_ring.consume,
269 txq->tx_ring.produce);
272 vlib_cli_output (vm, "TX descriptors table");
273 vlib_cli_output (vm, " %5s %18s %10s %10s",
274 "slot", "address", "flags0", "flags1");
275 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
277 txd = &txq->tx_desc[desc_idx];
278 vlib_cli_output (vm, " %5u 0x%016llx 0x%08x 0x%08x",
279 desc_idx, txd->address, txd->flags[0],
282 vlib_cli_output (vm, "TX completion descriptors table");
283 vlib_cli_output (vm, " %5s %10s %10s",
284 "slot", "index", "flags");
285 for (desc_idx = 0; desc_idx < txq->size; desc_idx++)
287 tx_comp = &txq->tx_comp[desc_idx];
288 vlib_cli_output (vm, " %5u 0x%08x 0x%08x",
289 desc_idx, tx_comp->index, tx_comp->flags);
296 static clib_error_t *
297 show_vmxnet3_fn (vlib_main_t * vm, unformat_input_t * input,
298 vlib_cli_command_t * cmd)
300 vmxnet3_main_t *vmxm = &vmxnet3_main;
301 vnet_main_t *vnm = &vnet_main;
302 vmxnet3_device_t *vd;
303 clib_error_t *error = 0;
304 u32 hw_if_index, *hw_if_indices = 0;
305 vnet_hw_interface_t *hi;
308 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
311 (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
313 hi = vnet_get_hw_interface (vnm, hw_if_index);
314 if (vmxnet3_device_class.index != hi->dev_class_index)
316 error = clib_error_return (0, "unknown input `%U'",
317 format_unformat_error, input);
320 vec_add1 (hw_if_indices, hw_if_index);
322 else if (unformat (input, "descriptors") || unformat (input, "desc"))
326 error = clib_error_return (0, "unknown input `%U'",
327 format_unformat_error, input);
332 if (vec_len (hw_if_indices) == 0)
334 pool_foreach (vd, vmxm->devices,
335 vec_add1 (hw_if_indices, vd->hw_if_index);
339 show_vmxnet3 (vm, hw_if_indices, show_descr);
342 vec_free (hw_if_indices);
347 VLIB_CLI_COMMAND (show_vmxnet3_command, static) = {
348 .path = "show vmxnet3",
349 .short_help = "show vmxnet3 [<interface>]",
350 .function = show_vmxnet3_fn,
355 vmxnet3_cli_init (vlib_main_t * vm)
357 /* initialize binary API */
358 vmxnet3_plugin_api_hookup (vm);
363 VLIB_INIT_FUNCTION (vmxnet3_cli_init);
366 * fd.io coding-style-patch-verification: ON
369 * eval: (c-set-style "gnu")