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;
99 memset (&args, 0, sizeof (avf_create_if_args_t));
101 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
103 if (unformat (i, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3]))
105 args.addr.domain = x[0];
106 args.addr.bus = x[1];
107 args.addr.slot = x[2];
108 args.addr.function = x[3];
110 else if (unformat (i, "elog"))
111 args.enable_elog = 1;
112 else if (unformat (i, "rx-queue-size %u", &args.rxq_size))
114 else if (unformat (i, "tx-queue-size %u", &args.txq_size))
118 clib_warning ("unknown input '%U'", format_unformat_error, i);
125 mp->pci_addr = clib_host_to_net_u32 (args.addr.as_u32);
126 mp->enable_elog = clib_host_to_net_u16 (args.enable_elog);
127 mp->rxq_size = clib_host_to_net_u16 (args.rxq_size);
128 mp->txq_size = clib_host_to_net_u16 (args.txq_size);
136 /* avf-create reply handler */
138 vl_api_avf_create_reply_t_handler (vl_api_avf_create_reply_t * mp)
140 vat_main_t *vam = avf_test_main.vat_main;
141 i32 retval = ntohl (mp->retval);
145 fformat (vam->ofp, "created avf with sw_if_index %d\n",
146 ntohl (mp->sw_if_index));
149 vam->retval = retval;
150 vam->result_ready = 1;
151 vam->regenerate_interface_table = 1;
156 api_avf_delete (vat_main_t * vam)
158 unformat_input_t *i = vam->input;
159 vl_api_avf_delete_t *mp;
161 u8 index_defined = 0;
164 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
166 if (unformat (i, "sw_if_index %u", &sw_if_index))
170 clib_warning ("unknown input '%U'", format_unformat_error, i);
177 errmsg ("missing sw_if_index\n");
183 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
192 * List of messages that the api test plugin sends,
193 * and that the data plane plugin processes
195 #define foreach_vpe_api_msg \
196 _(avf_create, "<pci-address> [rx-queue-size <size>] " \
197 "[tx-queue-size <size>]") \
198 _(avf_delete, "<sw_if_index>")
201 avf_vat_api_hookup (vat_main_t * vam)
203 avf_test_main_t *avm __attribute__ ((unused)) = &avf_test_main;
205 vl_msg_api_set_handlers((VL_API_##N + avm->msg_id_base), \
207 vl_api_##n##_t_handler, \
209 vl_api_##n##_t_endian, \
210 vl_api_##n##_t_print, \
211 sizeof(vl_api_##n##_t), 1);
212 foreach_vpe_api_reply_msg;
216 hash_set_mem (vam->function_by_name, #n, api_##n);
220 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
226 vat_plugin_register (vat_main_t * vam)
228 avf_test_main_t *avm = &avf_test_main;
233 name = format (0, "avf_%08x%c", api_version, 0);
234 avm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
236 if (avm->msg_id_base != (u16) ~ 0)
237 avf_vat_api_hookup (vam);
245 * fd.io coding-style-patch-verification: ON
248 * eval: (c-set-style "gnu")