FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2019 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 <vnet/vnet.h>
20 
21 #include <rdma/rdma.h>
22 
23 #include <vlibapi/api.h>
24 #include <vlibmemory/api.h>
25 
26 /* define message IDs */
27 #include <rdma/rdma.api_enum.h>
28 #include <rdma/rdma.api_types.h>
29 
31 
32 static rdma_mode_t
33 rdma_api_mode (vl_api_rdma_mode_t mode)
34 {
35  switch (mode)
36  {
37  case RDMA_API_MODE_AUTO:
38  return RDMA_MODE_AUTO;
39  case RDMA_API_MODE_IBV:
40  return RDMA_MODE_IBV;
41  case RDMA_API_MODE_DV:
42  return RDMA_MODE_DV;
43  }
44  return RDMA_MODE_AUTO;
45 }
46 
47 static rdma_rss4_t
48 rdma_api_rss4 (const vl_api_rdma_rss4_t rss4)
49 {
50  switch (rss4)
51  {
52  case RDMA_API_RSS4_AUTO:
53  return RDMA_RSS4_AUTO;
54  case RDMA_API_RSS4_IP:
55  return RDMA_RSS4_IP;
57  return RDMA_RSS4_IP_UDP;
59  return RDMA_RSS4_IP_TCP;
60  }
61  return RDMA_RSS4_AUTO;
62 }
63 
64 static rdma_rss6_t
65 rdma_api_rss6 (const vl_api_rdma_rss6_t rss6)
66 {
67  switch (rss6)
68  {
69  case RDMA_API_RSS6_AUTO:
70  return RDMA_RSS6_AUTO;
71  case RDMA_API_RSS6_IP:
72  return RDMA_RSS6_IP;
74  return RDMA_RSS6_IP_UDP;
76  return RDMA_RSS6_IP_TCP;
77  }
78  return RDMA_RSS6_AUTO;
79 }
80 
81 static void
83 {
85  rdma_main_t *rm = &rdma_main;
88  int rv;
89 
90  clib_memset (&args, 0, sizeof (rdma_create_if_args_t));
91 
92  args.ifname = mp->host_if;
93  args.name = mp->name;
94  args.rxq_num = ntohs (mp->rxq_num);
95  args.rxq_size = ntohs (mp->rxq_size);
96  args.txq_size = ntohs (mp->txq_size);
97  args.mode = rdma_api_mode (mp->mode);
98  args.disable_striding_rq = 0;
99  args.no_multi_seg = mp->no_multi_seg;
100  args.max_pktlen = ntohs (mp->max_pktlen);
101  args.rss4 = rdma_api_rss4 (mp->rss4);
102  args.rss6 = rdma_api_rss6 (mp->rss6);
103  rdma_create_if (vm, &args);
104  rv = args.rv;
105 
106  REPLY_MACRO2 (VL_API_RDMA_CREATE_V3_REPLY + rm->msg_id_base,
107  ({ rmp->sw_if_index = ntohl (args.sw_if_index); }));
108 }
109 
110 static void
112 {
114  rdma_main_t *rm = &rdma_main;
117  int rv;
118 
119  clib_memset (&args, 0, sizeof (rdma_create_if_args_t));
120 
121  args.ifname = mp->host_if;
122  args.name = mp->name;
123  args.rxq_num = ntohs (mp->rxq_num);
124  args.rxq_size = ntohs (mp->rxq_size);
125  args.txq_size = ntohs (mp->txq_size);
126  args.mode = rdma_api_mode (mp->mode);
127  args.disable_striding_rq = 0;
128  args.no_multi_seg = mp->no_multi_seg;
129  args.max_pktlen = ntohs (mp->max_pktlen);
130  rdma_create_if (vm, &args);
131  rv = args.rv;
132 
133  /* *INDENT-OFF* */
134  REPLY_MACRO2 (VL_API_RDMA_CREATE_V2_REPLY + rm->msg_id_base,
135  ({
136  rmp->sw_if_index = ntohl (args.sw_if_index);
137  }));
138  /* *INDENT-ON* */
139 }
140 
141 static void
143 {
145  rdma_main_t *rm = &rdma_main;
148  int rv;
149 
150  clib_memset (&args, 0, sizeof (rdma_create_if_args_t));
151 
152  args.ifname = mp->host_if;
153  args.name = mp->name;
154  args.rxq_num = ntohs (mp->rxq_num);
155  args.rxq_size = ntohs (mp->rxq_size);
156  args.txq_size = ntohs (mp->txq_size);
157  args.mode = rdma_api_mode (mp->mode);
158  args.disable_striding_rq = 0;
159  args.no_multi_seg = 1;
160  args.max_pktlen = 0;
161 
162  rdma_create_if (vm, &args);
163  rv = args.rv;
164 
165  /* *INDENT-OFF* */
166  REPLY_MACRO2 (VL_API_RDMA_CREATE_REPLY + rm->msg_id_base,
167  ({
168  rmp->sw_if_index = ntohl (args.sw_if_index);
169  }));
170  /* *INDENT-ON* */
171 }
172 
173 static void
175 {
177  vnet_main_t *vnm = vnet_get_main ();
178  rdma_main_t *rm = &rdma_main;
179  vl_api_rdma_delete_reply_t *rmp;
180  rdma_device_t *rd;
182  int rv = 0;
183 
184  hw =
186  htonl (mp->sw_if_index));
187  if (hw == NULL || rdma_device_class.index != hw->dev_class_index)
188  {
189  rv = VNET_API_ERROR_INVALID_INTERFACE;
190  goto reply;
191  }
192 
193  rd = pool_elt_at_index (rm->devices, hw->dev_instance);
194 
195  rdma_delete_if (vm, rd);
196 
197 reply:
198  REPLY_MACRO (VL_API_RDMA_DELETE_REPLY + rm->msg_id_base);
199 }
200 
201 /* set tup the API message handling tables */
202 #include <rdma/rdma.api.c>
203 static clib_error_t *
205 {
206  rdma_main_t *rm = &rdma_main;
207 
208  /* ask for a correctly-sized block of API message decode slots */
210  return 0;
211 }
212 
214 
215 /*
216  * fd.io coding-style-patch-verification: ON
217  *
218  * Local Variables:
219  * eval: (c-set-style "gnu")
220  * End:
221  */
vlib.h
vl_api_rdma_create_t::txq_size
u16 txq_size[default=1024]
Definition: rdma.api:49
rdma_main_t::devices
rdma_device_t * devices
Definition: rdma.h:261
RDMA_RSS6_AUTO
@ RDMA_RSS6_AUTO
Definition: rdma.h:188
rdma_create_if_args_t::max_pktlen
u16 max_pktlen
Definition: rdma.h:285
api.h
vl_api_rdma_create_v2_reply_t
Definition: rdma.api:153
ntohs
#define ntohs(x)
Definition: af_xdp.bpf.c:29
rdma_plugin_api_hookup
static clib_error_t * rdma_plugin_api_hookup(vlib_main_t *vm)
Definition: api.c:204
REPLY_MACRO2
#define REPLY_MACRO2(t, body)
Definition: api_helper_macros.h:65
RDMA_API_RSS6_IP_TCP
@ RDMA_API_RSS6_IP_TCP
Definition: rdma.api:97
vl_api_rdma_create_t::name
string name[64]
Definition: rdma.api:46
rdma_create_if
void rdma_create_if(vlib_main_t *vm, rdma_create_if_args_t *args)
Definition: device.c:881
vl_api_rdma_create_v3_t::rxq_size
u16 rxq_size[default=1024]
Definition: rdma.api:123
RDMA_API_MODE_IBV
@ RDMA_API_MODE_IBV
Definition: rdma.api:24
rdma_rss6_t
rdma_rss6_t
Definition: rdma.h:186
rdma_create_if_args_t::rxq_num
u32 rxq_num
Definition: rdma.h:281
rdma_delete_if
void rdma_delete_if(vlib_main_t *vm, rdma_device_t *rd)
Definition: device.c:1052
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
rdma_api_mode
static rdma_mode_t rdma_api_mode(vl_api_rdma_mode_t mode)
Definition: api.c:33
vl_api_rdma_create_v3_t::txq_size
u16 txq_size[default=1024]
Definition: rdma.api:124
vl_api_rdma_create_v2_t::mode
vl_api_rdma_mode_t mode[default=0]
Definition: rdma.api:78
rdma_device_class
vnet_device_class_t rdma_device_class
vl_api_rdma_create_v3_t::no_multi_seg
bool no_multi_seg[default=0]
Definition: rdma.api:126
vl_api_rdma_create_v2_t::txq_size
u16 txq_size[default=1024]
Definition: rdma.api:77
RDMA_RSS4_IP_TCP
@ RDMA_RSS4_IP_TCP
Definition: rdma.h:183
mode
vl_api_tunnel_mode_t mode
Definition: gre.api:48
vl_api_rdma_create_t
Definition: rdma.api:39
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
api.h
RDMA_API_RSS4_IP
@ RDMA_API_RSS4_IP
Definition: rdma.api:87
vl_api_rdma_create_v3_t::rss4
vl_api_rdma_rss4_t rss4[default=0]
Definition: rdma.api:128
vl_api_rdma_create_v3_t_handler
static void vl_api_rdma_create_v3_t_handler(vl_api_rdma_create_v3_t *mp)
Definition: api.c:82
RDMA_RSS4_IP_UDP
@ RDMA_RSS4_IP_UDP
Definition: rdma.h:182
vnet_hw_interface_t::dev_instance
u32 dev_instance
Definition: interface.h:660
RDMA_RSS4_AUTO
@ RDMA_RSS4_AUTO
Definition: rdma.h:180
vl_api_rdma_create_v2_t::host_if
string host_if[64]
Definition: rdma.api:73
vl_api_rdma_create_v3_t
Definition: rdma.api:115
vl_api_rdma_create_v2_t::name
string name[64]
Definition: rdma.api:74
vl_api_rdma_create_v3_t::rxq_num
u16 rxq_num[default=1]
Definition: rdma.api:122
vl_api_rdma_create_v3_t::name
string name[64]
Definition: rdma.api:121
rdma_create_if_args_t::mode
rdma_mode_t mode
Definition: rdma.h:282
rdma_create_if_args_t::txq_size
u32 txq_size
Definition: rdma.h:280
rdma_create_if_args_t::disable_striding_rq
u8 disable_striding_rq
Definition: rdma.h:284
RDMA_API_RSS6_IP_UDP
@ RDMA_API_RSS6_IP_UDP
Definition: rdma.api:96
vl_api_rdma_create_v3_t::rss6
vl_api_rdma_rss6_t rss6[default=0]
Definition: rdma.api:129
vl_api_rdma_create_v2_t::rxq_num
u16 rxq_num[default=1]
Definition: rdma.api:75
rdma_main
rdma_main_t rdma_main
Definition: device.c:47
RDMA_API_RSS6_IP
@ RDMA_API_RSS6_IP
Definition: rdma.api:95
RDMA_API_MODE_DV
@ RDMA_API_MODE_DV
Definition: rdma.api:25
vl_api_rdma_create_v2_t
Definition: rdma.api:67
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
RDMA_MODE_AUTO
@ RDMA_MODE_AUTO
Definition: rdma.h:270
RDMA_API_RSS6_AUTO
@ RDMA_API_RSS6_AUTO
Definition: rdma.api:94
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
rdma_main_t
Definition: rdma.h:258
vnet_get_sup_hw_interface_api_visible_or_null
static vnet_hw_interface_t * vnet_get_sup_hw_interface_api_visible_or_null(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:101
vl_api_rdma_create_v3_t::mode
vl_api_rdma_mode_t mode[default=0]
Definition: rdma.api:125
rdma_api_rss4
static rdma_rss4_t rdma_api_rss4(const vl_api_rdma_rss4_t rss4)
Definition: api.c:48
rdma_create_if_args_t::rv
int rv
Definition: rdma.h:290
vl_api_rdma_create_v3_t::host_if
string host_if[64]
Definition: rdma.api:120
vnet_hw_interface_t::dev_class_index
u32 dev_class_index
Definition: interface.h:659
rdma_create_if_args_t::rxq_size
u32 rxq_size
Definition: rdma.h:279
RDMA_API_RSS4_AUTO
@ RDMA_API_RSS4_AUTO
Definition: rdma.api:86
vl_api_rdma_create_t::host_if
string host_if[64]
Definition: rdma.api:45
rdma_create_if_args_t
Definition: rdma.h:275
VLIB_API_INIT_FUNCTION
VLIB_API_INIT_FUNCTION(af_xdp_plugin_api_hookup)
vl_api_rdma_create_v2_t::max_pktlen
u16 max_pktlen[default=0]
Definition: rdma.api:80
rdma_device_t
Definition: rdma.h:194
vl_api_rdma_create_t_handler
static void vl_api_rdma_create_t_handler(vl_api_rdma_create_t *mp)
Definition: api.c:142
rdma_create_if_args_t::no_multi_seg
u8 no_multi_seg
Definition: rdma.h:283
rdma_rss4_t
rdma_rss4_t
Definition: rdma.h:178
rdma_create_if_args_t::rss6
rdma_rss6_t rss6
Definition: rdma.h:287
RDMA_RSS6_IP_UDP
@ RDMA_RSS6_IP_UDP
Definition: rdma.h:190
RDMA_RSS6_IP_TCP
@ RDMA_RSS6_IP_TCP
Definition: rdma.h:191
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: api.c:801
vl_api_rdma_create_v3_reply_t
Definition: rdma.api:166
vl_api_rdma_delete_t
Definition: rdma.api:179
rdma_api_rss6
static rdma_rss6_t rdma_api_rss6(const vl_api_rdma_rss6_t rss6)
Definition: api.c:65
vl_api_rdma_create_t::rxq_size
u16 rxq_size[default=1024]
Definition: rdma.api:48
vl_api_rdma_delete_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: rdma.api:184
RDMA_API_RSS4_IP_TCP
@ RDMA_API_RSS4_IP_TCP
Definition: rdma.api:89
vl_api_rdma_delete_t_handler
static void vl_api_rdma_delete_t_handler(vl_api_rdma_delete_t *mp)
Definition: api.c:174
RDMA_RSS6_IP
@ RDMA_RSS6_IP
Definition: rdma.h:189
vl_api_rdma_create_t::rxq_num
u16 rxq_num[default=1]
Definition: rdma.api:47
vnet_hw_interface_t
Definition: interface.h:638
vnet_main_t
Definition: vnet.h:76
RDMA_RSS4_IP
@ RDMA_RSS4_IP
Definition: rdma.h:181
vl_api_rdma_create_v2_t_handler
static void vl_api_rdma_create_v2_t_handler(vl_api_rdma_create_v2_t *mp)
Definition: api.c:111
RDMA_MODE_IBV
@ RDMA_MODE_IBV
Definition: rdma.h:271
vl_api_rdma_create_t::mode
vl_api_rdma_mode_t mode[default=0]
Definition: rdma.api:50
rdma_create_if_args_t::name
u8 * name
Definition: rdma.h:278
vl_api_rdma_create_v2_t::rxq_size
u16 rxq_size[default=1024]
Definition: rdma.api:76
rdma_create_if_args_t::rss4
rdma_rss4_t rss4
Definition: rdma.h:286
vl_api_rdma_create_v2_t::no_multi_seg
bool no_multi_seg[default=0]
Definition: rdma.api:79
api_helper_macros.h
rdma_mode_t
rdma_mode_t
Definition: rdma.h:268
vl_api_rdma_create_reply_t
Definition: rdma.api:140
rdma_create_if_args_t::ifname
u8 * ifname
Definition: rdma.h:277
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
vlib_get_main
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:38
clib_error_t
Definition: clib_error.h:21
vl_api_rdma_create_v3_t::max_pktlen
u16 max_pktlen[default=0]
Definition: rdma.api:127
RDMA_API_MODE_AUTO
@ RDMA_API_MODE_AUTO
Definition: rdma.api:23
rv
int __clib_unused rv
Definition: application.c:491
RDMA_MODE_DV
@ RDMA_MODE_DV
Definition: rdma.h:272
vnet.h
RDMA_API_RSS4_IP_UDP
@ RDMA_API_RSS4_IP_UDP
Definition: rdma.api:88
rdma.h
rdma_main_t::msg_id_base
u16 msg_id_base
Definition: rdma.h:263