FD.io VPP  v19.01.2-3-gf61a1a8
Vector Packet Processing
avf_api.c
Go to the documentation of this file.
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_msg_enum.h>
30 
31 /* define message structures */
32 #define vl_typedefs
33 #include <avf/avf_all_api_h.h>
34 #undef vl_typedefs
35 
36 /* define generated endian-swappers */
37 #define vl_endianfun
38 #include <avf/avf_all_api_h.h>
39 #undef vl_endianfun
40 
41 /* instantiate all the print functions we know about */
42 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
43 #define vl_printfun
44 #include <avf/avf_all_api_h.h>
45 #undef vl_printfun
46 
47 /* get the API version number */
48 #define vl_api_version(n,v) static u32 api_version=(v);
49 #include <avf/avf_all_api_h.h>
50 #undef vl_api_version
51 
53 
54 #define foreach_avf_plugin_api_msg \
55 _(AVF_CREATE, avf_create) \
56 _(AVF_DELETE, avf_delete)
57 
58 static void
60 {
62  avf_main_t *am = &avf_main;
65  int rv;
66 
67  clib_memset (&args, 0, sizeof (avf_create_if_args_t));
68 
69  args.enable_elog = ntohl (mp->enable_elog);
70  args.addr.as_u32 = ntohl (mp->pci_addr);
71  args.rxq_num = ntohs (mp->rxq_num);
72  args.rxq_size = ntohs (mp->rxq_size);
73  args.txq_size = ntohs (mp->txq_size);
74 
75  avf_create_if (vm, &args);
76  rv = args.rv;
77 
78  /* *INDENT-OFF* */
79  REPLY_MACRO2 (VL_API_AVF_CREATE_REPLY + am->msg_id_base,
80  ({
81  rmp->sw_if_index = ntohl (args.sw_if_index);
82  }));
83  /* *INDENT-ON* */
84 }
85 
86 static void
88 {
90  vnet_main_t *vnm = vnet_get_main ();
91  avf_main_t *am = &avf_main;
92  vl_api_avf_delete_reply_t *rmp;
93  avf_device_t *ad;
95  int rv = 0;
96 
97  hw = vnet_get_sup_hw_interface (vnm, htonl (mp->sw_if_index));
98  if (hw == NULL || avf_device_class.index != hw->dev_class_index)
99  {
100  rv = VNET_API_ERROR_INVALID_INTERFACE;
101  goto reply;
102  }
103 
104  ad = pool_elt_at_index (am->devices, hw->dev_instance);
105 
106  avf_delete_if (vm, ad);
107 
108 reply:
109  REPLY_MACRO (VL_API_AVF_DELETE_REPLY + am->msg_id_base);
110 }
111 
112 #define vl_msg_name_crc_list
113 #include <avf/avf_all_api_h.h>
114 #undef vl_msg_name_crc_list
115 
116 static void
118 {
119 #define _(id,n,crc) \
120  vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + avm->msg_id_base);
121  foreach_vl_msg_name_crc_avf;
122 #undef _
123 }
124 
125 /* set tup the API message handling tables */
126 static clib_error_t *
128 {
129  avf_main_t *avm = &avf_main;
130  api_main_t *am = &api_main;
131  u8 *name;
132 
133  /* construct the API name */
134  name = format (0, "avf_%08x%c", api_version, 0);
135 
136  /* ask for a correctly-sized block of API message decode slots */
138  ((char *) name, VL_MSG_FIRST_AVAILABLE);
139 
140 #define _(N,n) \
141  vl_msg_api_set_handlers((VL_API_##N + avm->msg_id_base), \
142  #n, \
143  vl_api_##n##_t_handler, \
144  vl_noop_handler, \
145  vl_api_##n##_t_endian, \
146  vl_api_##n##_t_print, \
147  sizeof(vl_api_##n##_t), 1);
149 #undef _
150 
151  /* set up the (msg_name, crc, message-id) table */
152  setup_message_id_table (avm, am);
153 
154  vec_free (name);
155  return 0;
156 }
157 
159 
160 /*
161  * fd.io coding-style-patch-verification: ON
162  *
163  * Local Variables:
164  * eval: (c-set-style "gnu")
165  * End:
166  */
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
#define REPLY_MACRO2(t, body)
#define NULL
Definition: clib.h:58
VLIB_API_INIT_FUNCTION(avf_plugin_api_hookup)
vlib_pci_addr_t addr
Definition: avf.h:206
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
avf_device_t * devices
Definition: avf.h:196
unsigned char u8
Definition: types.h:56
vnet_device_class_t avf_device_class
static void setup_message_id_table(avf_main_t *avm, api_main_t *am)
Definition: avf_api.c:117
void avf_create_if(vlib_main_t *vm, avf_create_if_args_t *args)
Definition: device.c:1191
static clib_error_t * avf_plugin_api_hookup(vlib_main_t *vm)
Definition: avf_api.c:127
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:511
#define REPLY_MACRO(t)
u8 name[64]
Definition: memclnt.api:152
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:202
vlib_main_t * vm
Definition: buffer.c:301
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
static void vl_api_avf_delete_t_handler(vl_api_avf_delete_t *mp)
Definition: avf_api.c:87
avf_main_t avf_main
Definition: device.c:37
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
u16 msg_id_base
Definition: avf.h:194
void avf_delete_if(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:1134
#define foreach_avf_plugin_api_msg
Definition: avf_api.c:54
api_main_t api_main
Definition: api_shared.c:35
static void vl_api_avf_create_t_handler(vl_api_avf_create_t *mp)
Definition: avf_api.c:59
u16 vl_msg_api_get_msg_ids(const char *name, int n)
Definition: api_shared.c:865