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 *------------------------------------------------------------------
18 #include <vlib/vlib.h>
19 #include <vlib/unix/unix.h>
20 #include <vlib/pci/pci.h>
21 #include <vnet/ethernet/ethernet.h>
22 #include <vnet/format_fns.h>
25 #include <vlibapi/api.h>
26 #include <vlibmemory/api.h>
28 #include <vppinfra/error.h>
29 #include <vmxnet3/vmxnet3.h>
31 #define __plugin_msg_base vmxnet3_test_main.msg_id_base
32 #include <vlibapi/vat_helper_macros.h>
34 /* declare message IDs */
35 #include <vmxnet3/vmxnet3.api_enum.h>
36 #include <vmxnet3/vmxnet3.api_types.h>
37 #include <vpp/api/vpe.api_types.h>
41 /* API message ID base */
45 } vmxnet3_test_main_t;
47 vmxnet3_test_main_t vmxnet3_test_main;
49 /* vmxnet3 create API */
51 api_vmxnet3_create (vat_main_t * vam)
53 unformat_input_t *i = vam->input;
54 vl_api_vmxnet3_create_t *mp;
55 vmxnet3_create_if_args_t args;
59 clib_memset (&args, 0, sizeof (vmxnet3_create_if_args_t));
61 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
63 if (unformat (i, "%U", unformat_vlib_pci_addr, &args.addr))
65 else if (unformat (i, "elog"))
67 else if (unformat (i, "bind"))
69 else if (unformat (i, "gso"))
71 else if (unformat (i, "rx-queue-size %u", &size))
73 else if (unformat (i, "tx-queue-size %u", &size))
75 else if (unformat (i, "num-tx-queues %u", &size))
77 else if (unformat (i, "num-rx-queues %u", &size))
81 clib_warning ("unknown input '%U'", format_unformat_error, i);
86 M (VMXNET3_CREATE, mp);
88 mp->pci_addr = clib_host_to_net_u32 (args.addr.as_u32);
89 mp->enable_elog = clib_host_to_net_u16 (args.enable_elog);
90 mp->rxq_size = clib_host_to_net_u16 (args.rxq_size);
91 mp->txq_size = clib_host_to_net_u16 (args.txq_size);
92 mp->txq_num = clib_host_to_net_u16 (args.txq_num);
93 mp->rxq_num = clib_host_to_net_u16 (args.rxq_num);
95 mp->enable_gso = args.enable_gso;
103 /* vmxnet3-create reply handler */
105 vl_api_vmxnet3_create_reply_t_handler (vl_api_vmxnet3_create_reply_t * mp)
107 vat_main_t *vam = vmxnet3_test_main.vat_main;
108 i32 retval = ntohl (mp->retval);
112 fformat (vam->ofp, "created vmxnet3 with sw_if_index %d\n",
113 ntohl (mp->sw_if_index));
116 vam->retval = retval;
117 vam->result_ready = 1;
118 vam->regenerate_interface_table = 1;
121 /* vmxnet3 delete API */
123 api_vmxnet3_delete (vat_main_t * vam)
125 unformat_input_t *i = vam->input;
126 vl_api_vmxnet3_delete_t *mp;
128 u8 index_defined = 0;
131 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
133 if (unformat (i, "sw_if_index %u", &sw_if_index))
137 clib_warning ("unknown input '%U'", format_unformat_error, i);
144 errmsg ("missing sw_if_index\n");
148 M (VMXNET3_DELETE, mp);
150 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
159 api_vmxnet3_dump (vat_main_t * vam)
161 vmxnet3_test_main_t *vxm = &vmxnet3_test_main;
162 vl_api_vmxnet3_dump_t *mp;
163 vl_api_control_ping_t *mp_ping;
166 if (vam->json_output)
168 clib_warning ("JSON output not supported for vmxnet3_dump");
172 M (VMXNET3_DUMP, mp);
175 /* Use a control ping for synchronization */
178 vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
179 mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
180 mp_ping->_vl_msg_id = htons (vxm->ping_id);
181 mp_ping->client_index = vam->my_client_index;
183 fformat (vam->ofp, "Sending ping id=%d\n", vxm->ping_id);
185 vam->result_ready = 0;
193 api_sw_vmxnet3_interface_dump (vat_main_t * vam)
195 vmxnet3_test_main_t *vxm = &vmxnet3_test_main;
196 vl_api_sw_vmxnet3_interface_dump_t *mp;
197 vl_api_control_ping_t *mp_ping;
199 u32 sw_if_index = ~0;
200 unformat_input_t *i = vam->input;
202 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
204 if (unformat (i, "sw_if_index %d", &sw_if_index))
210 if (vam->json_output)
212 clib_warning ("JSON output not supported for vmxnet3_dump");
216 M (SW_VMXNET3_INTERFACE_DUMP, mp);
217 mp->sw_if_index = ntohl (sw_if_index);
220 /* Use a control ping for synchronization */
223 vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
224 mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
225 mp_ping->_vl_msg_id = htons (vxm->ping_id);
226 mp_ping->client_index = vam->my_client_index;
228 fformat (vam->ofp, "Sending ping id=%d\n", vxm->ping_id);
230 vam->result_ready = 0;
238 format_pci_addr (u8 * s, va_list * va)
240 vlib_pci_addr_t *addr = va_arg (*va, vlib_pci_addr_t *);
241 return format (s, "%04x:%02x:%02x.%x", addr->domain, addr->bus,
242 addr->slot, addr->function);
246 vl_api_vmxnet3_details_t_handler (vl_api_vmxnet3_details_t * mp)
248 vat_main_t *vam = vmxnet3_test_main.vat_main;
249 u32 pci_addr = ntohl (mp->pci_addr);
252 fformat (vam->ofp, "%s: sw_if_index %u mac %U\n"
256 mp->if_name, ntohl (mp->sw_if_index), format_ethernet_address,
257 mp->hw_addr, mp->version,
258 format_pci_addr, &pci_addr, mp->admin_up_down ? "up" : "down");
259 for (qid = 0; qid < mp->rx_count; qid++)
261 vl_api_vmxnet3_rx_list_t *rx_list = &mp->rx_list[qid];
264 " RX completion next index %u\n"
265 " ring 0 size %u fill %u consume %u produce %u\n"
266 " ring 1 size %u fill %u consume %u produce %u\n",
268 ntohs (rx_list->rx_next),
269 ntohs (rx_list->rx_qsize), ntohs (rx_list->rx_fill[0]),
270 ntohs (rx_list->rx_consume[0]),
271 ntohs (rx_list->rx_produce[0]),
272 ntohs (rx_list->rx_qsize), ntohs (rx_list->rx_fill[1]),
273 ntohs (rx_list->rx_consume[1]),
274 ntohs (rx_list->rx_produce[1]));
276 for (qid = 0; qid < mp->tx_count; qid++)
278 vl_api_vmxnet3_tx_list_t *tx_list = &mp->tx_list[qid];
281 " TX completion next index %u\n"
282 " size %u consume %u produce %u\n",
284 ntohs (tx_list->tx_next),
285 ntohs (tx_list->tx_qsize), ntohs (tx_list->tx_consume),
286 ntohs (tx_list->tx_produce));
290 static void vl_api_sw_vmxnet3_interface_details_t_handler
291 (vl_api_sw_vmxnet3_interface_details_t * mp)
293 vat_main_t *vam = vmxnet3_test_main.vat_main;
294 u32 pci_addr = ntohl (mp->pci_addr);
297 fformat (vam->ofp, "%s: sw_if_index %u mac %U\n"
301 mp->if_name, ntohl (mp->sw_if_index), format_ethernet_address,
302 mp->hw_addr, mp->version,
303 format_pci_addr, &pci_addr, mp->admin_up_down ? "up" : "down");
304 for (qid = 0; qid < mp->rx_count; qid++)
306 vl_api_vmxnet3_rx_list_t *rx_list = &mp->rx_list[qid];
309 " RX completion next index %u\n"
310 " ring 0 size %u fill %u consume %u produce %u\n"
311 " ring 1 size %u fill %u consume %u produce %u\n",
313 ntohs (rx_list->rx_next),
314 ntohs (rx_list->rx_qsize), ntohs (rx_list->rx_fill[0]),
315 ntohs (rx_list->rx_consume[0]),
316 ntohs (rx_list->rx_produce[0]),
317 ntohs (rx_list->rx_qsize), ntohs (rx_list->rx_fill[1]),
318 ntohs (rx_list->rx_consume[1]),
319 ntohs (rx_list->rx_produce[1]));
321 for (qid = 0; qid < mp->tx_count; qid++)
323 vl_api_vmxnet3_tx_list_t *tx_list = &mp->tx_list[qid];
326 " TX completion next index %u\n"
327 " size %u consume %u produce %u\n",
329 ntohs (tx_list->tx_next),
330 ntohs (tx_list->tx_qsize), ntohs (tx_list->tx_consume),
331 ntohs (tx_list->tx_produce));
335 #include <vmxnet3/vmxnet3.api_test.c>
338 * fd.io coding-style-patch-verification: ON
341 * eval: (c-set-style "gnu")