hs-test: more debug output in http3 test
[vpp.git] / src / plugins / avf / avf_api.c
1 /*
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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  *------------------------------------------------------------------
16  */
17
18 #include <vlib/vlib.h>
19 #include <vlib/unix/unix.h>
20 #include <vlib/pci/pci.h>
21 #include <vnet/ethernet/ethernet.h>
22
23 #include <avf/avf.h>
24
25 #include <vlibapi/api.h>
26 #include <vlibmemory/api.h>
27
28 /* define message IDs */
29 #include <avf/avf.api_enum.h>
30 #include <avf/avf.api_types.h>
31
32 #define REPLY_MSG_ID_BASE (am->msg_id_base)
33 #include <vlibapi/api_helper_macros.h>
34
35 static void
36 vl_api_avf_create_t_handler (vl_api_avf_create_t * mp)
37 {
38   vlib_main_t *vm = vlib_get_main ();
39   avf_main_t *am = &avf_main;
40   vl_api_avf_create_reply_t *rmp;
41   avf_create_if_args_t args;
42   int rv;
43
44   clib_memset (&args, 0, sizeof (avf_create_if_args_t));
45
46   args.enable_elog = ntohl (mp->enable_elog);
47   args.addr.as_u32 = ntohl (mp->pci_addr);
48   args.rxq_num = ntohs (mp->rxq_num);
49   args.rxq_size = ntohs (mp->rxq_size);
50   args.txq_size = ntohs (mp->txq_size);
51
52   avf_create_if (vm, &args);
53   rv = args.rv;
54
55   REPLY_MACRO2 (VL_API_AVF_CREATE_REPLY,
56                 ({ rmp->sw_if_index = ntohl (args.sw_if_index); }));
57 }
58
59 static void
60 vl_api_avf_delete_t_handler (vl_api_avf_delete_t * mp)
61 {
62   vlib_main_t *vm = vlib_get_main ();
63   vnet_main_t *vnm = vnet_get_main ();
64   avf_main_t *am = &avf_main;
65   vl_api_avf_delete_reply_t *rmp;
66   vnet_hw_interface_t *hw;
67   int rv = 0;
68
69   hw =
70     vnet_get_sup_hw_interface_api_visible_or_null (vnm,
71                                                    htonl (mp->sw_if_index));
72   if (hw == NULL || avf_device_class.index != hw->dev_class_index)
73     {
74       rv = VNET_API_ERROR_INVALID_INTERFACE;
75       goto reply;
76     }
77
78   vlib_process_signal_event (vm, avf_process_node.index,
79                              AVF_PROCESS_EVENT_DELETE_IF, hw->dev_instance);
80
81 reply:
82   REPLY_MACRO (VL_API_AVF_DELETE_REPLY);
83 }
84
85 /* set tup the API message handling tables */
86 #include <avf/avf.api.c>
87 static clib_error_t *
88 avf_plugin_api_hookup (vlib_main_t * vm)
89 {
90   avf_main_t *avm = &avf_main;
91   api_main_t *am = vlibapi_get_main ();
92
93   /* ask for a correctly-sized block of API message decode slots */
94   avm->msg_id_base = setup_message_id_table ();
95
96   vl_api_set_msg_thread_safe (am, avm->msg_id_base + VL_API_AVF_DELETE, 1);
97
98   return 0;
99 }
100
101 VLIB_API_INIT_FUNCTION (avf_plugin_api_hookup);
102
103 /*
104  * fd.io coding-style-patch-verification: ON
105  *
106  * Local Variables:
107  * eval: (c-set-style "gnu")
108  * End:
109  */