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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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 *------------------------------------------------------------------
18 #include <vlib/vlib.h>
19 #include <vlib/unix/unix.h>
20 #include <vlib/pci/pci.h>
21 #include <vnet/ethernet/ethernet.h>
24 #include <vlibapi/api.h>
25 #include <vlibmemory/api.h>
27 #include <vppinfra/error.h>
28 #include <rdma/rdma.h>
30 #define __plugin_msg_base rdma_test_main.msg_id_base
31 #include <vlibapi/vat_helper_macros.h>
33 /* declare message IDs */
34 #include <rdma/rdma.api_enum.h>
35 #include <rdma/rdma.api_types.h>
39 /* API message ID base */
44 rdma_test_main_t rdma_test_main;
46 static vl_api_rdma_mode_t
47 api_rdma_mode (rdma_mode_t mode)
52 return RDMA_API_MODE_AUTO;
54 return RDMA_API_MODE_IBV;
56 return RDMA_API_MODE_DV;
61 static vl_api_rdma_rss4_t
62 api_rdma_rss4 (rdma_rss4_t rss4)
67 return RDMA_API_RSS4_AUTO;
69 return RDMA_API_RSS4_IP;
70 case RDMA_RSS4_IP_UDP:
71 return RDMA_API_RSS4_IP_UDP;
72 case RDMA_RSS4_IP_TCP:
73 return RDMA_API_RSS4_IP_TCP;
78 static vl_api_rdma_rss6_t
79 api_rdma_rss6 (rdma_rss6_t rss6)
84 return RDMA_API_RSS6_AUTO;
86 return RDMA_API_RSS6_IP;
87 case RDMA_RSS6_IP_UDP:
88 return RDMA_API_RSS6_IP_UDP;
89 case RDMA_RSS6_IP_TCP:
90 return RDMA_API_RSS6_IP_TCP;
97 api_rdma_create (vat_main_t * vam)
99 vl_api_rdma_create_t *mp;
100 rdma_create_if_args_t args;
103 if (!unformat_user (vam->input, unformat_rdma_create_if_args, &args))
105 clib_warning ("unknown input `%U'", format_unformat_error, vam->input);
111 snprintf ((char *) mp->host_if, sizeof (mp->host_if), "%s", args.ifname);
112 snprintf ((char *) mp->name, sizeof (mp->name), "%s", args.name);
113 mp->rxq_num = clib_host_to_net_u16 (args.rxq_num);
114 mp->rxq_size = clib_host_to_net_u16 (args.rxq_size);
115 mp->txq_size = clib_host_to_net_u16 (args.txq_size);
116 mp->mode = api_rdma_mode (args.mode);
125 api_rdma_create_v2 (vat_main_t * vam)
127 vl_api_rdma_create_v2_t *mp;
128 rdma_create_if_args_t args;
131 if (!unformat_user (vam->input, unformat_rdma_create_if_args, &args))
133 clib_warning ("unknown input `%U'", format_unformat_error, vam->input);
137 M (RDMA_CREATE_V2, mp);
139 snprintf ((char *) mp->host_if, sizeof (mp->host_if), "%s", args.ifname);
141 snprintf ((char *) mp->name, sizeof (mp->name), "%s", args.name);
144 mp->rxq_num = clib_host_to_net_u16 (args.rxq_num);
145 mp->rxq_size = clib_host_to_net_u16 (args.rxq_size);
146 mp->txq_size = clib_host_to_net_u16 (args.txq_size);
147 mp->mode = api_rdma_mode (args.mode);
148 mp->no_multi_seg = args.no_multi_seg;
149 mp->max_pktlen = clib_host_to_net_u16 (args.max_pktlen);
158 api_rdma_create_v3 (vat_main_t *vam)
160 vl_api_rdma_create_v3_t *mp;
161 rdma_create_if_args_t args;
164 if (!unformat_user (vam->input, unformat_rdma_create_if_args, &args))
166 clib_warning ("unknown input `%U'", format_unformat_error, vam->input);
170 M (RDMA_CREATE_V3, mp);
172 snprintf ((char *) mp->host_if, sizeof (mp->host_if), "%s", args.ifname);
174 snprintf ((char *) mp->name, sizeof (mp->name), "%s", args.name);
177 mp->rxq_num = clib_host_to_net_u16 (args.rxq_num);
178 mp->rxq_size = clib_host_to_net_u16 (args.rxq_size);
179 mp->txq_size = clib_host_to_net_u16 (args.txq_size);
180 mp->mode = api_rdma_mode (args.mode);
181 mp->no_multi_seg = args.no_multi_seg;
182 mp->max_pktlen = clib_host_to_net_u16 (args.max_pktlen);
183 mp->rss4 = api_rdma_rss4 (args.rss4);
184 mp->rss6 = api_rdma_rss6 (args.rss6);
192 /* rdma-create reply handler */
194 vl_api_rdma_create_reply_t_handler (vl_api_rdma_create_reply_t * mp)
196 vat_main_t *vam = rdma_test_main.vat_main;
197 i32 retval = ntohl (mp->retval);
201 fformat (vam->ofp, "created rdma with sw_if_index %d\n",
202 ntohl (mp->sw_if_index));
205 vam->retval = retval;
206 vam->result_ready = 1;
207 vam->regenerate_interface_table = 1;
210 /* rdma-create reply handler */
212 vl_api_rdma_create_v2_reply_t_handler (vl_api_rdma_create_v2_reply_t * mp)
214 vat_main_t *vam = rdma_test_main.vat_main;
215 i32 retval = ntohl (mp->retval);
219 fformat (vam->ofp, "created rdma with sw_if_index %d\n",
220 ntohl (mp->sw_if_index));
223 vam->retval = retval;
224 vam->result_ready = 1;
225 vam->regenerate_interface_table = 1;
228 /* rdma-create reply handler v3 */
230 vl_api_rdma_create_v3_reply_t_handler (vl_api_rdma_create_v3_reply_t *mp)
232 vat_main_t *vam = rdma_test_main.vat_main;
233 i32 retval = ntohl (mp->retval);
237 fformat (vam->ofp, "created rdma with sw_if_index %d\n",
238 ntohl (mp->sw_if_index));
241 vam->retval = retval;
242 vam->result_ready = 1;
243 vam->regenerate_interface_table = 1;
246 /* rdma delete API */
248 api_rdma_delete (vat_main_t * vam)
250 unformat_input_t *i = vam->input;
251 vl_api_rdma_delete_t *mp;
253 u8 index_defined = 0;
256 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
258 if (unformat (i, "sw_if_index %u", &sw_if_index))
262 clib_warning ("unknown input '%U'", format_unformat_error, i);
269 errmsg ("missing sw_if_index\n");
275 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
283 #include <rdma/rdma.api_test.c>
286 * fd.io coding-style-patch-verification: ON
289 * eval: (c-set-style "gnu")