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 \
71 static void vl_api_##n##_t_handler \
72 (vl_api_##n##_t * mp) \
74 vat_main_t * vam = avf_test_main.vat_main; \
75 i32 retval = ntohl(mp->retval); \
76 if (vam->async_mode) { \
77 vam->async_errors += (retval < 0); \
79 vam->retval = retval; \
80 vam->result_ready = 1; \
83 foreach_standard_reply_retval_handler;
86 #define foreach_vpe_api_reply_msg \
87 _(AVF_CREATE_REPLY, avf_create_reply) \
88 _(AVF_DELETE_REPLY, avf_delete_reply)
92 api_avf_create (vat_main_t * vam)
94 unformat_input_t *i = vam->input;
95 vl_api_avf_create_t *mp;
96 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", &args.rxq_size))
115 else if (unformat (i, "tx-queue-size %u", &args.txq_size))
119 clib_warning ("unknown input '%U'", format_unformat_error, i);
126 mp->pci_addr = clib_host_to_net_u32 (args.addr.as_u32);
127 mp->enable_elog = clib_host_to_net_u16 (args.enable_elog);
128 mp->rxq_size = clib_host_to_net_u16 (args.rxq_size);
129 mp->txq_size = clib_host_to_net_u16 (args.txq_size);
139 api_avf_delete (vat_main_t * vam)
141 unformat_input_t *i = vam->input;
142 vl_api_avf_delete_t *mp;
144 u8 index_defined = 0;
147 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
149 if (unformat (i, "sw_if_index %u", &sw_if_index))
153 clib_warning ("unknown input '%U'", format_unformat_error, i);
160 errmsg ("missing sw_if_index\n");
166 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
175 * List of messages that the api test plugin sends,
176 * and that the data plane plugin processes
178 #define foreach_vpe_api_msg \
179 _(avf_create, "<pci-address> [rx-queue-size <size>] " \
180 "[tx-queue-size <size>]") \
181 _(avf_delete, "<sw_if_index>")
184 avf_vat_api_hookup (vat_main_t * vam)
186 avf_test_main_t *avm __attribute__ ((unused)) = &avf_test_main;
188 vl_msg_api_set_handlers((VL_API_##N + avm->msg_id_base), \
190 vl_api_##n##_t_handler, \
192 vl_api_##n##_t_endian, \
193 vl_api_##n##_t_print, \
194 sizeof(vl_api_##n##_t), 1);
195 foreach_vpe_api_reply_msg;
199 hash_set_mem (vam->function_by_name, #n, api_##n);
203 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
209 vat_plugin_register (vat_main_t * vam)
211 avf_test_main_t *avm = &avf_test_main;
216 name = format (0, "avf_%08x%c", api_version, 0);
217 avm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
219 if (avm->msg_id_base != (u16) ~ 0)
220 avf_vat_api_hookup (vam);
228 * fd.io coding-style-patch-verification: ON
231 * eval: (c-set-style "gnu")