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 #include <vlibapi/api_helper_macros.h>
33 rdma_api_mode (vl_api_rdma_mode_t mode)
37 case RDMA_API_MODE_AUTO:
38 return RDMA_MODE_AUTO;
39 case RDMA_API_MODE_IBV:
41 case RDMA_API_MODE_DV:
44 return RDMA_MODE_AUTO;
48 rdma_api_rss4 (const vl_api_rdma_rss4_t rss4)
52 case RDMA_API_RSS4_AUTO:
53 return RDMA_RSS4_AUTO;
54 case RDMA_API_RSS4_IP:
56 case RDMA_API_RSS4_IP_UDP:
57 return RDMA_RSS4_IP_UDP;
58 case RDMA_API_RSS4_IP_TCP:
59 return RDMA_RSS4_IP_TCP;
61 return RDMA_RSS4_AUTO;
65 rdma_api_rss6 (const vl_api_rdma_rss6_t rss6)
69 case RDMA_API_RSS6_AUTO:
70 return RDMA_RSS6_AUTO;
71 case RDMA_API_RSS6_IP:
73 case RDMA_API_RSS6_IP_UDP:
74 return RDMA_RSS6_IP_UDP;
75 case RDMA_API_RSS6_IP_TCP:
76 return RDMA_RSS6_IP_TCP;
78 return RDMA_RSS6_AUTO;
82 vl_api_rdma_create_v3_t_handler (vl_api_rdma_create_v3_t *mp)
84 vlib_main_t *vm = vlib_get_main ();
85 rdma_main_t *rm = &rdma_main;
86 vl_api_rdma_create_v3_reply_t *rmp;
87 rdma_create_if_args_t args;
90 clib_memset (&args, 0, sizeof (rdma_create_if_args_t));
92 args.ifname = mp->host_if;
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);
106 REPLY_MACRO2 (VL_API_RDMA_CREATE_V3_REPLY + rm->msg_id_base,
107 ({ rmp->sw_if_index = ntohl (args.sw_if_index); }));
111 vl_api_rdma_create_v2_t_handler (vl_api_rdma_create_v2_t * mp)
113 vlib_main_t *vm = vlib_get_main ();
114 rdma_main_t *rm = &rdma_main;
115 vl_api_rdma_create_v2_reply_t *rmp;
116 rdma_create_if_args_t args;
119 clib_memset (&args, 0, sizeof (rdma_create_if_args_t));
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);
134 REPLY_MACRO2 (VL_API_RDMA_CREATE_V2_REPLY + rm->msg_id_base,
136 rmp->sw_if_index = ntohl (args.sw_if_index);
142 vl_api_rdma_create_t_handler (vl_api_rdma_create_t * mp)
144 vlib_main_t *vm = vlib_get_main ();
145 rdma_main_t *rm = &rdma_main;
146 vl_api_rdma_create_reply_t *rmp;
147 rdma_create_if_args_t args;
150 clib_memset (&args, 0, sizeof (rdma_create_if_args_t));
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;
162 rdma_create_if (vm, &args);
166 REPLY_MACRO2 (VL_API_RDMA_CREATE_REPLY + rm->msg_id_base,
168 rmp->sw_if_index = ntohl (args.sw_if_index);
174 vl_api_rdma_delete_t_handler (vl_api_rdma_delete_t * mp)
176 vlib_main_t *vm = vlib_get_main ();
177 vnet_main_t *vnm = vnet_get_main ();
178 rdma_main_t *rm = &rdma_main;
179 vl_api_rdma_delete_reply_t *rmp;
181 vnet_hw_interface_t *hw;
185 vnet_get_sup_hw_interface_api_visible_or_null (vnm,
186 htonl (mp->sw_if_index));
187 if (hw == NULL || rdma_device_class.index != hw->dev_class_index)
189 rv = VNET_API_ERROR_INVALID_INTERFACE;
193 rd = pool_elt_at_index (rm->devices, hw->dev_instance);
195 rdma_delete_if (vm, rd);
198 REPLY_MACRO (VL_API_RDMA_DELETE_REPLY + rm->msg_id_base);
201 /* set tup the API message handling tables */
202 #include <rdma/rdma.api.c>
203 static clib_error_t *
204 rdma_plugin_api_hookup (vlib_main_t * vm)
206 rdma_main_t *rm = &rdma_main;
208 /* ask for a correctly-sized block of API message decode slots */
209 rm->msg_id_base = setup_message_id_table ();
213 VLIB_API_INIT_FUNCTION (rdma_plugin_api_hookup);
216 * fd.io coding-style-patch-verification: ON
219 * eval: (c-set-style "gnu")