FD.io VPP  v20.01-48-g3e0dafb74
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.api_enum.h>
30 #include <avf/avf.api_types.h>
31 
33 
34 static void
36 {
38  avf_main_t *am = &avf_main;
41  int rv;
42 
43  clib_memset (&args, 0, sizeof (avf_create_if_args_t));
44 
45  args.enable_elog = ntohl (mp->enable_elog);
46  args.addr.as_u32 = ntohl (mp->pci_addr);
47  args.rxq_num = ntohs (mp->rxq_num);
48  args.rxq_size = ntohs (mp->rxq_size);
49  args.txq_size = ntohs (mp->txq_size);
50 
51  avf_create_if (vm, &args);
52  rv = args.rv;
53 
54  /* *INDENT-OFF* */
55  REPLY_MACRO2 (VL_API_AVF_CREATE_REPLY + am->msg_id_base,
56  ({
57  rmp->sw_if_index = ntohl (args.sw_if_index);
58  }));
59  /* *INDENT-ON* */
60 }
61 
62 static void
64 {
66  vnet_main_t *vnm = vnet_get_main ();
67  avf_main_t *am = &avf_main;
68  vl_api_avf_delete_reply_t *rmp;
69  avf_device_t *ad;
71  int rv = 0;
72 
73  hw =
75  htonl (mp->sw_if_index));
76  if (hw == NULL || avf_device_class.index != hw->dev_class_index)
77  {
78  rv = VNET_API_ERROR_INVALID_INTERFACE;
79  goto reply;
80  }
81 
82  ad = pool_elt_at_index (am->devices, hw->dev_instance);
83 
84  avf_delete_if (vm, ad);
85 
86 reply:
87  REPLY_MACRO (VL_API_AVF_DELETE_REPLY + am->msg_id_base);
88 }
89 
90 /* set tup the API message handling tables */
91 #include <avf/avf.api.c>
92 static clib_error_t *
94 {
95  avf_main_t *avm = &avf_main;
96 
97  /* ask for a correctly-sized block of API message decode slots */
99  return 0;
100 }
101 
103 
104 /*
105  * fd.io coding-style-patch-verification: ON
106  *
107  * Local Variables:
108  * eval: (c-set-style "gnu")
109  * End:
110  */
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
#define REPLY_MACRO2(t, body)
#define NULL
Definition: clib.h:58
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
VLIB_API_INIT_FUNCTION(avf_plugin_api_hookup)
vlib_pci_addr_t addr
Definition: avf.h:233
avf_device_t * devices
Definition: avf.h:223
vnet_device_class_t avf_device_class
void avf_create_if(vlib_main_t *vm, avf_create_if_args_t *args)
Definition: device.c:1322
static clib_error_t * avf_plugin_api_hookup(vlib_main_t *vm)
Definition: avf_api.c:93
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:519
#define REPLY_MACRO(t)
vlib_main_t * vm
Definition: in2out_ed.c:1810
vl_api_interface_index_t sw_if_index
Definition: avf.api:69
static vnet_hw_interface_t * vnet_get_sup_hw_interface_api_visible_or_null(vnet_main_t *vnm, u32 sw_if_index)
static void vl_api_avf_delete_t_handler(vl_api_avf_delete_t *mp)
Definition: avf_api.c:63
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:221
void avf_delete_if(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:1265
static void setup_message_id_table(snat_main_t *sm, api_main_t *am)
Definition: nat_api.c:3410
static void vl_api_avf_create_t_handler(vl_api_avf_create_t *mp)
Definition: avf_api.c:35