idpf: add native idpf driver plugin
[vpp.git] / src / plugins / idpf / idpf_api.c
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2023 Intel 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 <idpf/idpf.h>
24
25 #include <vlibapi/api.h>
26 #include <vlibmemory/api.h>
27
28 /* define message IDs */
29 #include <idpf/idpf.api_enum.h>
30 #include <idpf/idpf.api_types.h>
31
32 #define REPLY_MSG_ID_BASE (im->msg_id_base)
33 #include <vlibapi/api_helper_macros.h>
34
35 static void
36 vl_api_idpf_create_t_handler (vl_api_idpf_create_t *mp)
37 {
38   vlib_main_t *vm = vlib_get_main ();
39   idpf_main_t *im = &idpf_main;
40   vl_api_idpf_create_reply_t *rmp;
41   idpf_create_if_args_t args;
42   int rv;
43
44   clib_memset (&args, 0, sizeof (idpf_create_if_args_t));
45
46   args.addr.as_u32 = ntohl (mp->pci_addr);
47   args.rxq_single = ntohs (mp->rxq_single);
48   args.txq_single = ntohs (mp->txq_single);
49   args.rxq_num = ntohs (mp->rxq_num);
50   args.txq_num = ntohs (mp->txq_num);
51   args.rxq_size = ntohs (mp->rxq_size);
52   args.txq_size = ntohs (mp->txq_size);
53   args.req_vport_nb = ntohs (mp->req_vport_nb);
54
55   idpf_create_if (vm, &args);
56   rv = args.rv;
57
58   REPLY_MACRO2 (VL_API_IDPF_CREATE_REPLY,
59                 ({ rmp->sw_if_index = ntohl (args.sw_if_index); }));
60 }
61
62 static void
63 vl_api_idpf_delete_t_handler (vl_api_idpf_delete_t *mp)
64 {
65   vlib_main_t *vm = vlib_get_main ();
66   vnet_main_t *vnm = vnet_get_main ();
67   idpf_main_t *im = &idpf_main;
68   vl_api_idpf_delete_reply_t *rmp;
69   vnet_hw_interface_t *hw;
70   int rv = 0;
71
72   hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm,
73                                                       htonl (mp->sw_if_index));
74   if (hw == NULL || idpf_device_class.index != hw->dev_class_index)
75     {
76       rv = VNET_API_ERROR_INVALID_INTERFACE;
77       goto reply;
78     }
79
80   vlib_process_signal_event (vm, idpf_process_node.index,
81                              IDPF_PROCESS_EVENT_DELETE_IF, hw->dev_instance);
82
83 reply:
84   REPLY_MACRO (VL_API_IDPF_DELETE_REPLY);
85 }
86
87 /* set tup the API message handling tables */
88 #include <idpf/idpf.api.c>
89 static clib_error_t *
90 idpf_plugin_api_hookup (vlib_main_t *vm)
91 {
92   idpf_main_t *ivm = &idpf_main;
93   api_main_t *am = vlibapi_get_main ();
94
95   /* ask for a correctly-sized block of API message decode slots */
96   ivm->msg_id_base = setup_message_id_table ();
97
98   vl_api_set_msg_thread_safe (am, ivm->msg_id_base + VL_API_IDPF_DELETE, 1);
99
100   return 0;
101 }
102
103 VLIB_API_INIT_FUNCTION (idpf_plugin_api_hookup);
104
105 /*
106  * fd.io coding-style-patch-verification: ON
107  *
108  * Local Variables:
109  * eval: (c-set-style "gnu")
110  * End:
111  */