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>
24 #include <vlibapi/api.h>
25 #include <vlibmemory/api.h>
27 #include <vppinfra/error.h>
30 #define __plugin_msg_base avf_test_main.msg_id_base
31 #include <vlibapi/vat_helper_macros.h>
33 /* declare message IDs */
34 #include <avf/avf_msg_enum.h>
36 /* define message structures */
38 #include <avf/avf_all_api_h.h>
41 /* declare message handlers for each api */
43 #include <avf/avf_all_api_h.h>
46 /* instantiate all the print functions we know about */
47 #define vl_print(handle, ...)
49 #include <avf/avf_all_api_h.h>
52 /* get API version number */
53 #define vl_api_version(n,v) static u32 api_version=(v);
54 #include <avf/avf_all_api_h.h>
59 /* API message ID base */
64 avf_test_main_t avf_test_main;
66 #define foreach_standard_reply_retval_handler \
70 static void vl_api_##n##_t_handler \
71 (vl_api_##n##_t * mp) \
73 vat_main_t * vam = avf_test_main.vat_main; \
74 i32 retval = ntohl(mp->retval); \
75 if (vam->async_mode) { \
76 vam->async_errors += (retval < 0); \
78 vam->retval = retval; \
79 vam->result_ready = 1; \
82 foreach_standard_reply_retval_handler;
85 #define foreach_vpe_api_reply_msg \
86 _(AVF_CREATE_REPLY, avf_create_reply) \
87 _(AVF_DELETE_REPLY, avf_delete_reply)
91 api_avf_create (vat_main_t * vam)
93 unformat_input_t *i = vam->input;
94 vl_api_avf_create_t *mp;
95 avf_create_if_args_t args;
100 memset (&args, 0, sizeof (avf_create_if_args_t));
102 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
104 if (unformat (i, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3]))
106 args.addr.domain = x[0];
107 args.addr.bus = x[1];
108 args.addr.slot = x[2];
109 args.addr.function = x[3];
111 else if (unformat (i, "elog"))
112 args.enable_elog = 1;
113 else if (unformat (i, "rx-queue-size %u", &tmp))
115 else if (unformat (i, "tx-queue-size %u", &tmp))
117 else if (unformat (i, "num-rx-queues %u", &tmp))
121 clib_warning ("unknown input '%U'", format_unformat_error, i);
128 mp->pci_addr = clib_host_to_net_u32 (args.addr.as_u32);
129 mp->enable_elog = clib_host_to_net_u16 (args.enable_elog);
130 mp->rxq_num = clib_host_to_net_u16 (args.rxq_num);
131 mp->rxq_size = clib_host_to_net_u16 (args.rxq_size);
132 mp->txq_size = clib_host_to_net_u16 (args.txq_size);
140 /* avf-create reply handler */
142 vl_api_avf_create_reply_t_handler (vl_api_avf_create_reply_t * mp)
144 vat_main_t *vam = avf_test_main.vat_main;
145 i32 retval = ntohl (mp->retval);
149 fformat (vam->ofp, "created avf with sw_if_index %d\n",
150 ntohl (mp->sw_if_index));
153 vam->retval = retval;
154 vam->result_ready = 1;
155 vam->regenerate_interface_table = 1;
160 api_avf_delete (vat_main_t * vam)
162 unformat_input_t *i = vam->input;
163 vl_api_avf_delete_t *mp;
165 u8 index_defined = 0;
168 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
170 if (unformat (i, "sw_if_index %u", &sw_if_index))
174 clib_warning ("unknown input '%U'", format_unformat_error, i);
181 errmsg ("missing sw_if_index\n");
187 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
196 * List of messages that the api test plugin sends,
197 * and that the data plane plugin processes
199 #define foreach_vpe_api_msg \
200 _(avf_create, "<pci-address> [rx-queue-size <size>] " \
201 "[tx-queue-size <size>] [num-rx-queues <size>]") \
202 _(avf_delete, "<sw_if_index>")
205 avf_vat_api_hookup (vat_main_t * vam)
207 avf_test_main_t *avm __attribute__ ((unused)) = &avf_test_main;
209 vl_msg_api_set_handlers((VL_API_##N + avm->msg_id_base), \
211 vl_api_##n##_t_handler, \
213 vl_api_##n##_t_endian, \
214 vl_api_##n##_t_print, \
215 sizeof(vl_api_##n##_t), 1);
216 foreach_vpe_api_reply_msg;
220 hash_set_mem (vam->function_by_name, #n, api_##n);
224 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
230 vat_plugin_register (vat_main_t * vam)
232 avf_test_main_t *avm = &avf_test_main;
237 name = format (0, "avf_%08x%c", api_version, 0);
238 avm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
240 if (avm->msg_id_base != (u16) ~ 0)
241 avf_vat_api_hookup (vam);
249 * fd.io coding-style-patch-verification: ON
252 * eval: (c-set-style "gnu")