FD.io VPP
v18.07.1-19-g511ce25
Vector Packet Processing
Main Page
Related Pages
Modules
Namespaces
Data Structures
Source
Files
Symbols
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
52
#include <
vlibapi/api_helper_macros.h
>
53
54
#define foreach_avf_plugin_api_msg \
55
_(AVF_CREATE, avf_create) \
56
_(AVF_DELETE, avf_delete)
57
58
static
void
59
vl_api_avf_create_t_handler
(
vl_api_avf_create_t
* mp)
60
{
61
vlib_main_t
*
vm
=
vlib_get_main
();
62
avf_main_t
*am = &
avf_main
;
63
vl_api_avf_create_reply_t
*rmp;
64
avf_create_if_args_t
args;
65
int
rv;
66
67
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_size
= ntohs (mp->
rxq_size
);
72
args.
txq_size
= ntohs (mp->
txq_size
);
73
74
avf_create_if
(vm, &args);
75
rv = args.
rv
;
76
77
/* *INDENT-OFF* */
78
REPLY_MACRO2
(VL_API_AVF_CREATE_REPLY + am->
msg_id_base
,
79
({
80
rmp->sw_if_index = ntohl (args.sw_if_index);
81
}));
82
/* *INDENT-ON* */
83
}
84
85
static
void
86
vl_api_avf_delete_t_handler
(
vl_api_avf_delete_t
* mp)
87
{
88
vlib_main_t
*
vm
=
vlib_get_main
();
89
vnet_main_t
*vnm =
vnet_get_main
();
90
avf_main_t
*am = &
avf_main
;
91
vl_api_avf_delete_reply_t *rmp;
92
avf_device_t
*ad;
93
vnet_hw_interface_t
*hw;
94
int
rv = 0;
95
96
hw =
vnet_get_sup_hw_interface
(vnm, htonl (mp->
sw_if_index
));
97
if
(hw ==
NULL
||
avf_device_class
.index != hw->
dev_class_index
)
98
{
99
rv = VNET_API_ERROR_INVALID_INTERFACE;
100
goto
reply;
101
}
102
103
ad =
pool_elt_at_index
(am->
devices
, hw->
dev_instance
);
104
105
avf_delete_if
(vm, ad);
106
107
reply:
108
REPLY_MACRO
(VL_API_AVF_DELETE_REPLY + am->
msg_id_base
);
109
}
110
111
#define vl_msg_name_crc_list
112
#include <
avf/avf_all_api_h.h
>
113
#undef vl_msg_name_crc_list
114
115
static
void
116
setup_message_id_table
(
avf_main_t
* avm,
api_main_t
* am)
117
{
118
#define _(id,n,crc) \
119
vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + avm->msg_id_base);
120
foreach_vl_msg_name_crc_avf;
121
#undef _
122
}
123
124
/* set tup the API message handling tables */
125
static
clib_error_t
*
126
avf_plugin_api_hookup
(
vlib_main_t
*
vm
)
127
{
128
avf_main_t
*avm = &
avf_main
;
129
api_main_t
*am = &
api_main
;
130
u8
*name;
131
132
/* construct the API name */
133
name =
format
(0,
"avf_%08x%c"
, api_version, 0);
134
135
/* ask for a correctly-sized block of API message decode slots */
136
avm->
msg_id_base
=
vl_msg_api_get_msg_ids
137
((
char
*) name,
VL_MSG_FIRST_AVAILABLE
);
138
139
#define _(N,n) \
140
vl_msg_api_set_handlers((VL_API_##N + avm->msg_id_base), \
141
#n, \
142
vl_api_##n##_t_handler, \
143
vl_noop_handler, \
144
vl_api_##n##_t_endian, \
145
vl_api_##n##_t_print, \
146
sizeof(vl_api_##n##_t), 1);
147
foreach_avf_plugin_api_msg
;
148
#undef _
149
150
/* set up the (msg_name, crc, message-id) table */
151
setup_message_id_table
(avm, am);
152
153
vec_free
(name);
154
return
0;
155
}
156
157
VLIB_API_INIT_FUNCTION
(
avf_plugin_api_hookup
);
158
159
/*
160
* fd.io coding-style-patch-verification: ON
161
*
162
* Local Variables:
163
* eval: (c-set-style "gnu")
164
* End:
165
*/
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition:
misc.c:47
vnet_get_sup_hw_interface
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
Definition:
interface_funcs.h:92
avf_main_t
Definition:
avf.h:182
REPLY_MACRO2
#define REPLY_MACRO2(t, body)
Definition:
api_helper_macros.h:46
NULL
#define NULL
Definition:
clib.h:55
vl_api_avf_create_t::enable_elog
i32 enable_elog
Definition:
avf.api:36
VLIB_API_INIT_FUNCTION
VLIB_API_INIT_FUNCTION(avf_plugin_api_hookup)
avf_create_if_args_t::addr
vlib_pci_addr_t addr
Definition:
avf.h:201
vl_api_avf_create_t
Definition:
avf.api:30
format
u8 * format(u8 *s, const char *fmt,...)
Definition:
format.c:419
avf_main_t::devices
avf_device_t * devices
Definition:
avf.h:186
avf_device_t
Definition:
avf.h:102
u8
unsigned char u8
Definition:
types.h:56
avf_device_class
vnet_device_class_t avf_device_class
vnet_hw_interface_t::dev_instance
u32 dev_instance
Definition:
interface.h:511
api.h
VL_MSG_FIRST_AVAILABLE
Definition:
vnet_msg_enum.h:25
setup_message_id_table
static void setup_message_id_table(avf_main_t *avm, api_main_t *am)
Definition:
avf_api.c:116
avf_create_if_args_t::txq_size
u16 txq_size
Definition:
avf.h:204
avf_create_if
void avf_create_if(vlib_main_t *vm, avf_create_if_args_t *args)
Definition:
device.c:1066
avf_plugin_api_hookup
static clib_error_t * avf_plugin_api_hookup(vlib_main_t *vm)
Definition:
avf_api.c:126
api_helper_macros.h
ethernet.h
vl_api_avf_create_t::pci_addr
u32 pci_addr
Definition:
avf.api:35
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition:
pool.h:464
unix.h
REPLY_MACRO
#define REPLY_MACRO(t)
Definition:
api_helper_macros.h:30
vl_api_avf_delete_t
Definition:
avf.api:60
vnet_hw_interface_t::dev_class_index
u32 dev_class_index
Definition:
interface.h:510
api_main_t
API main structure, used by both vpp and binary API clients.
Definition:
api_common.h:201
pci.h
vm
vlib_main_t * vm
Definition:
buffer.c:294
vnet_hw_interface_t
Definition:
interface.h:451
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition:
vec.h:339
vl_api_avf_delete_t::sw_if_index
u32 sw_if_index
Definition:
avf.api:65
vl_api_avf_create_t::rxq_size
u16 rxq_size
Definition:
avf.api:37
avf.h
vlib.h
vnet_main_t
Definition:
vnet.h:51
avf_create_if_args_t
Definition:
avf.h:199
vl_api_avf_delete_t_handler
static void vl_api_avf_delete_t_handler(vl_api_avf_delete_t *mp)
Definition:
avf_api.c:86
avf_main
avf_main_t avf_main
Definition:
device.c:36
vlib_get_main
static vlib_main_t * vlib_get_main(void)
Definition:
global_funcs.h:23
avf_main_t::msg_id_base
u16 msg_id_base
Definition:
avf.h:184
clib_error_t
Definition:
clib_error.h:21
avf_delete_if
void avf_delete_if(vlib_main_t *vm, avf_device_t *ad)
Definition:
device.c:1011
avf_create_if_args_t::rxq_size
u16 rxq_size
Definition:
avf.h:203
api.h
vlib_main_t
Definition:
main.h:59
vl_api_avf_create_t::txq_size
u16 txq_size
Definition:
avf.api:38
avf_create_if_args_t::enable_elog
int enable_elog
Definition:
avf.h:202
foreach_avf_plugin_api_msg
#define foreach_avf_plugin_api_msg
Definition:
avf_api.c:54
vl_api_avf_create_reply_t
Definition:
avf.api:47
avf_create_if_args_t::rv
int rv
Definition:
avf.h:206
avf_msg_enum.h
api_main
api_main_t api_main
Definition:
api_shared.c:35
avf_all_api_h.h
vl_api_avf_create_t_handler
static void vl_api_avf_create_t_handler(vl_api_avf_create_t *mp)
Definition:
avf_api.c:59
vl_msg_api_get_msg_ids
u16 vl_msg_api_get_msg_ids(const char *name, int n)
Definition:
api_shared.c:872
src
plugins
avf
avf_api.c
Generated on Fri May 24 2019 10:25:09 for FD.io VPP by
1.8.11