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 <vnet/vnet.h>
21 #include <rdma/rdma.h>
23 #include <vlibapi/api.h>
24 #include <vlibmemory/api.h>
26 /* define message IDs */
27 #include <rdma/rdma.api_enum.h>
28 #include <rdma/rdma.api_types.h>
30 #define REPLY_MSG_ID_BASE (rm->msg_id_base)
31 #include <vlibapi/api_helper_macros.h>
34 rdma_api_mode (vl_api_rdma_mode_t mode)
38 case RDMA_API_MODE_AUTO:
39 return RDMA_MODE_AUTO;
40 case RDMA_API_MODE_IBV:
42 case RDMA_API_MODE_DV:
45 return RDMA_MODE_AUTO;
49 rdma_api_rss4 (const vl_api_rdma_rss4_t rss4)
53 case RDMA_API_RSS4_AUTO:
54 return RDMA_RSS4_AUTO;
55 case RDMA_API_RSS4_IP:
57 case RDMA_API_RSS4_IP_UDP:
58 return RDMA_RSS4_IP_UDP;
59 case RDMA_API_RSS4_IP_TCP:
60 return RDMA_RSS4_IP_TCP;
62 return RDMA_RSS4_AUTO;
66 rdma_api_rss6 (const vl_api_rdma_rss6_t rss6)
70 case RDMA_API_RSS6_AUTO:
71 return RDMA_RSS6_AUTO;
72 case RDMA_API_RSS6_IP:
74 case RDMA_API_RSS6_IP_UDP:
75 return RDMA_RSS6_IP_UDP;
76 case RDMA_API_RSS6_IP_TCP:
77 return RDMA_RSS6_IP_TCP;
79 return RDMA_RSS6_AUTO;
83 vl_api_rdma_create_v3_t_handler (vl_api_rdma_create_v3_t *mp)
85 vlib_main_t *vm = vlib_get_main ();
86 rdma_main_t *rm = &rdma_main;
87 vl_api_rdma_create_v3_reply_t *rmp;
88 rdma_create_if_args_t args;
91 clib_memset (&args, 0, sizeof (rdma_create_if_args_t));
93 args.ifname = mp->host_if;
95 args.rxq_num = ntohs (mp->rxq_num);
96 args.rxq_size = ntohs (mp->rxq_size);
97 args.txq_size = ntohs (mp->txq_size);
98 args.mode = rdma_api_mode (mp->mode);
99 args.disable_striding_rq = 0;
100 args.no_multi_seg = mp->no_multi_seg;
101 args.max_pktlen = ntohs (mp->max_pktlen);
102 args.rss4 = rdma_api_rss4 (mp->rss4);
103 args.rss6 = rdma_api_rss6 (mp->rss6);
104 rdma_create_if (vm, &args);
107 REPLY_MACRO2 (VL_API_RDMA_CREATE_V3_REPLY,
108 ({ rmp->sw_if_index = ntohl (args.sw_if_index); }));
112 vl_api_rdma_create_v2_t_handler (vl_api_rdma_create_v2_t * mp)
114 vlib_main_t *vm = vlib_get_main ();
115 rdma_main_t *rm = &rdma_main;
116 vl_api_rdma_create_v2_reply_t *rmp;
117 rdma_create_if_args_t args;
120 clib_memset (&args, 0, sizeof (rdma_create_if_args_t));
122 args.ifname = mp->host_if;
123 args.name = mp->name;
124 args.rxq_num = ntohs (mp->rxq_num);
125 args.rxq_size = ntohs (mp->rxq_size);
126 args.txq_size = ntohs (mp->txq_size);
127 args.mode = rdma_api_mode (mp->mode);
128 args.disable_striding_rq = 0;
129 args.no_multi_seg = mp->no_multi_seg;
130 args.max_pktlen = ntohs (mp->max_pktlen);
131 rdma_create_if (vm, &args);
135 REPLY_MACRO2 (VL_API_RDMA_CREATE_V2_REPLY,
136 ({ rmp->sw_if_index = ntohl (args.sw_if_index); }));
141 vl_api_rdma_create_t_handler (vl_api_rdma_create_t * mp)
143 vlib_main_t *vm = vlib_get_main ();
144 rdma_main_t *rm = &rdma_main;
145 vl_api_rdma_create_reply_t *rmp;
146 rdma_create_if_args_t args;
149 clib_memset (&args, 0, sizeof (rdma_create_if_args_t));
151 args.ifname = mp->host_if;
152 args.name = mp->name;
153 args.rxq_num = ntohs (mp->rxq_num);
154 args.rxq_size = ntohs (mp->rxq_size);
155 args.txq_size = ntohs (mp->txq_size);
156 args.mode = rdma_api_mode (mp->mode);
157 args.disable_striding_rq = 0;
158 args.no_multi_seg = 1;
161 rdma_create_if (vm, &args);
165 REPLY_MACRO2 (VL_API_RDMA_CREATE_REPLY,
166 ({ rmp->sw_if_index = ntohl (args.sw_if_index); }));
171 vl_api_rdma_delete_t_handler (vl_api_rdma_delete_t * mp)
173 vlib_main_t *vm = vlib_get_main ();
174 vnet_main_t *vnm = vnet_get_main ();
175 rdma_main_t *rm = &rdma_main;
176 vl_api_rdma_delete_reply_t *rmp;
178 vnet_hw_interface_t *hw;
182 vnet_get_sup_hw_interface_api_visible_or_null (vnm,
183 htonl (mp->sw_if_index));
184 if (hw == NULL || rdma_device_class.index != hw->dev_class_index)
186 rv = VNET_API_ERROR_INVALID_INTERFACE;
190 rd = pool_elt_at_index (rm->devices, hw->dev_instance);
192 rdma_delete_if (vm, rd);
195 REPLY_MACRO (VL_API_RDMA_DELETE_REPLY);
198 /* set tup the API message handling tables */
199 #include <rdma/rdma.api.c>
200 static clib_error_t *
201 rdma_plugin_api_hookup (vlib_main_t * vm)
203 rdma_main_t *rm = &rdma_main;
205 /* ask for a correctly-sized block of API message decode slots */
206 rm->msg_id_base = setup_message_id_table ();
210 VLIB_API_INIT_FUNCTION (rdma_plugin_api_hookup);
213 * fd.io coding-style-patch-verification: ON
216 * eval: (c-set-style "gnu")