Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #include "securec.h"
12 : #include "user_log.h"
13 : #include "hccp_common.h"
14 : #include "hccp_ctx.h"
15 : #include "ra.h"
16 : #include "ra_hdc_ctx.h"
17 : #include "ra_peer_ctx.h"
18 : #include "ra_ctx.h"
19 :
20 : struct RaCtxOps gRaHdcCtxOps = {
21 : .raCtxInit = RaHdcCtxInit,
22 : .raCtxGetAsyncEvents = RaHdcCtxGetAsyncEvents,
23 : .raCtxDeinit = RaHdcCtxDeinit,
24 : .raCtxGetEidByIp = RaHdcGetEidByIp,
25 : .raCtxGetIpByEid = RaHdcGetIpByEid,
26 : .raCtxTokenIdAlloc = RaHdcCtxTokenIdAlloc,
27 : .raCtxTokenIdFree = RaHdcCtxTokenIdFree,
28 : .raCtxLmemRegister = RaHdcCtxLmemRegister,
29 : .raCtxLmemUnregister = RaHdcCtxLmemUnregister,
30 : .raCtxRmemImport = RaHdcCtxRmemImport,
31 : .raCtxRmemUnimport = RaHdcCtxRmemUnimport,
32 : .raCtxChanCreate = RaHdcCtxChanCreate,
33 : .raCtxChanDestroy = RaHdcCtxChanDestroy,
34 : .raCtxCqCreate = RaHdcCtxCqCreate,
35 : .raCtxCqDestroy = RaHdcCtxCqDestroy,
36 : .raCtxQpCreate = RaHdcCtxQpCreate,
37 : .raCtxQpDestroy = RaHdcCtxQpDestroy,
38 : .raCtxQpImport = RaHdcCtxQpImport,
39 : .raCtxQpUnimport = RaHdcCtxQpUnimport,
40 : .raCtxQpBind = RaHdcCtxQpBind,
41 : .raCtxQpUnbind = RaHdcCtxQpUnbind,
42 : .raCtxBatchSendWr = RaHdcCtxBatchSendWr,
43 : .raCtxUpdateCi = RaHdcCtxUpdateCi,
44 : .raCtxQueryQpBatch = RaHdcCtxQpQueryBatch,
45 : .raCtxGetAuxInfo = RaHdcCtxGetAuxInfo,
46 : .raCtxGetJettyContext = RaHdcCtxGetJettyContext,
47 : };
48 :
49 : struct RaCtxOps gRaPeerCtxOps = {
50 : .raCtxInit = RaPeerCtxInit,
51 : .raCtxGetAsyncEvents = RaPeerCtxGetAsyncEvents,
52 : .raCtxDeinit = RaPeerCtxDeinit,
53 : .raCtxGetEidByIp = RaPeerGetEidByIp,
54 : .raCtxGetIpByEid = RaPeerGetIpByEid,
55 : .raCtxTokenIdAlloc = RaPeerCtxTokenIdAlloc,
56 : .raCtxTokenIdFree = RaPeerCtxTokenIdFree,
57 : .raCtxLmemRegister = RaPeerCtxLmemRegister,
58 : .raCtxLmemUnregister = RaPeerCtxLmemUnregister,
59 : .raCtxRmemImport = RaPeerCtxRmemImport,
60 : .raCtxRmemUnimport = RaPeerCtxRmemUnimport,
61 : .raCtxChanCreate = RaPeerCtxChanCreate,
62 : .raCtxChanDestroy = RaPeerCtxChanDestroy,
63 : .raCtxCqCreate = RaPeerCtxCqCreate,
64 : .raCtxCqDestroy = RaPeerCtxCqDestroy,
65 : .raCtxQpCreate = RaPeerCtxQpCreate,
66 : .raCtxQpDestroy = RaPeerCtxQpDestroy,
67 : .raCtxQpImport = RaPeerCtxQpImport,
68 : .raCtxQpUnimport = RaPeerCtxQpUnimport,
69 : .raCtxQpBind = RaPeerCtxQpBind,
70 : .raCtxQpUnbind = RaPeerCtxQpUnbind,
71 : .raCtxBatchSendWr = NULL,
72 : .raCtxUpdateCi = NULL,
73 : .raCtxQueryQpBatch = NULL,
74 : .raCtxGetAuxInfo = NULL,
75 : .raCtxGetJettyContext = RaPeerCtxGetJettyContext,
76 : };
77 :
78 3 : HCCP_ATTRI_VISI_DEF int RaGetDevEidInfoNum(struct RaInfo info, unsigned int *num)
79 : {
80 : int ret;
81 :
82 3 : CHK_PRT_RETURN(num == NULL, hccp_err("[get][eid]num is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
83 3 : CHK_PRT_RETURN(info.phyId >= RA_MAX_PHY_ID_NUM, hccp_err("[get][eid]phy_id(%u) must smaller than %u",
84 : info.phyId, RA_MAX_PHY_ID_NUM), ConverReturnCode(RDMA_OP, -EINVAL));
85 :
86 3 : hccp_run_info("Input parameters: phy_id[%u], nic_position:[%d]", info.phyId, info.mode);
87 3 : if (info.mode == NETWORK_OFFLINE) {
88 1 : ret = RaHdcGetDevEidInfoNum(info, num);
89 1 : CHK_PRT_RETURN(ret != 0, hccp_err("[get][eid]ra_hdc_get_dev_eid_info_num failed, ret(%d) phyId(%u)",
90 : ret, info.phyId), ConverReturnCode(RDMA_OP, ret));
91 2 : } else if (info.mode == NETWORK_PEER_ONLINE) {
92 2 : ret = RaPeerGetDevEidInfoNum(info, num);
93 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[get][eid]ra_peer_get_dev_eid_info_num failed, ret(%d) phyId(%u)",
94 : ret, info.phyId), ConverReturnCode(RDMA_OP, ret));
95 : } else {
96 0 : hccp_err("[get][eid]mode(%d) do not support, phyId(%u)", info.mode, info.phyId);
97 0 : return ConverReturnCode(RDMA_OP, -EINVAL);
98 : }
99 :
100 2 : return 0;
101 : }
102 :
103 3 : HCCP_ATTRI_VISI_DEF int RaGetDevEidInfoList(struct RaInfo info, struct HccpDevEidInfo infoList[],
104 : unsigned int *num)
105 : {
106 : int ret;
107 :
108 3 : CHK_PRT_RETURN(infoList == NULL || num == NULL, hccp_err("[get][eid]info_list or num is NULL"),
109 : ConverReturnCode(RDMA_OP, -EINVAL));
110 3 : CHK_PRT_RETURN(info.phyId >= RA_MAX_PHY_ID_NUM, hccp_err("[get][eid]phy_id(%u) must smaller than %u",
111 : info.phyId, RA_MAX_PHY_ID_NUM), ConverReturnCode(RDMA_OP, -EINVAL));
112 :
113 3 : hccp_run_info("Input parameters: phy_id[%u], nic_position:[%d]", info.phyId, info.mode);
114 3 : if (info.mode == NETWORK_OFFLINE) {
115 1 : ret = RaHdcGetDevEidInfoList(info.phyId, infoList, num);
116 1 : CHK_PRT_RETURN(ret != 0, hccp_err("[get][eid]ra_hdc_get_dev_eid_info_list failed, ret(%d) phyId(%u)",
117 : ret, info.phyId), ConverReturnCode(RDMA_OP, ret));
118 2 : } else if (info.mode == NETWORK_PEER_ONLINE) {
119 2 : ret = RaPeerGetDevEidInfoList(info.phyId, infoList, num);
120 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[get][eid]ra_peer_get_dev_eid_info_list failed, ret(%d) phyId(%u)",
121 : ret, info.phyId), ConverReturnCode(RDMA_OP, ret));
122 : } else {
123 0 : hccp_err("[get][eid]mode(%d) do not support, phyId(%u)", info.mode, info.phyId);
124 0 : return ConverReturnCode(RDMA_OP, -EINVAL);
125 : }
126 :
127 2 : return 0;
128 : }
129 :
130 1 : STATIC int RaGetInitCtxHandle(struct CtxInitCfg *cfg, struct CtxInitAttr *attr,
131 : struct RaCtxHandle *ctxHandle)
132 : {
133 1 : ctxHandle->protocol = PROTOCOL_UDMA;
134 :
135 1 : if (cfg->mode == NETWORK_OFFLINE) {
136 1 : ctxHandle->ctxOps = &gRaHdcCtxOps;
137 0 : } else if (cfg->mode == NETWORK_PEER_ONLINE) {
138 0 : ctxHandle->ctxOps = &gRaPeerCtxOps;
139 : } else {
140 0 : hccp_err("[init][ra_ctx]mode(%d) do not support, phyId(%u)", cfg->mode, attr->phyId);
141 0 : return -EINVAL;
142 : }
143 :
144 1 : CHK_PRT_RETURN(ctxHandle->ctxOps->raCtxInit == NULL, hccp_err("[init][ra_ctx]ra_ctx_init is NULL, phyId(%u)",
145 : attr->phyId), -EINVAL);
146 :
147 1 : (void)memcpy_s(&(ctxHandle->attr), sizeof(struct CtxInitAttr), attr, sizeof(struct CtxInitAttr));
148 1 : return 0;
149 : }
150 :
151 1 : HCCP_ATTRI_VISI_DEF int RaCtxInit(struct CtxInitCfg *cfg, struct CtxInitAttr *attr, void **ctxHandle)
152 : {
153 1 : struct RaCtxHandle *ctxHandleTmp = NULL;
154 : int ret;
155 :
156 1 : CHK_PRT_RETURN(cfg == NULL || attr == NULL || ctxHandle == NULL,
157 : hccp_err("[init][ra_ctx]cfg or attr or ctx_handle is NULL"), ConverReturnCode(HCCP_INIT, -EINVAL));
158 1 : CHK_PRT_RETURN(attr->phyId >= RA_MAX_PHY_ID_NUM, hccp_err("[init][ra_ctx]phy_id(%u) must smaller than %u",
159 : attr->phyId, RA_MAX_PHY_ID_NUM), ConverReturnCode(HCCP_INIT, -EINVAL));
160 :
161 1 : ctxHandleTmp = calloc(1, sizeof(struct RaCtxHandle));
162 1 : CHK_PRT_RETURN(ctxHandleTmp == NULL, hccp_err("[init][ra_ctx]calloc ctx_handle failed, errno(%d) phyId(%u)",
163 : errno, attr->phyId), ConverReturnCode(HCCP_INIT, -ENOMEM));
164 :
165 1 : ret = RaGetInitCtxHandle(cfg, attr, ctxHandleTmp);
166 1 : if (ret != 0) {
167 0 : hccp_err("[init][ra_ctx]ra_get_init_ctx_handle failed, ret(%d) phyId(%u)", ret, attr->phyId);
168 0 : goto err;
169 : }
170 :
171 1 : hccp_run_info("Input parameters: phy_id[%u], nic_position:[%d]", attr->phyId, cfg->mode);
172 1 : ret = ctxHandleTmp->ctxOps->raCtxInit(ctxHandleTmp, attr, &(ctxHandleTmp->devIndex),
173 : &(ctxHandleTmp->devAttr));
174 1 : if (ret != 0) {
175 0 : hccp_err("[init][ra_ctx]ctx init failed, ret(%d) phyId(%u)", ret, attr->phyId);
176 0 : goto err;
177 : }
178 :
179 1 : *ctxHandle = (void *)ctxHandleTmp;
180 1 : return 0;
181 :
182 0 : err:
183 0 : free(ctxHandleTmp);
184 0 : ctxHandleTmp = NULL;
185 0 : return ConverReturnCode(HCCP_INIT, ret);
186 : }
187 :
188 1 : HCCP_ATTRI_VISI_DEF int RaGetDevBaseAttr(void *ctxHandle, struct DevBaseAttr *attr)
189 : {
190 1 : struct RaCtxHandle *ctxHandleTmp = NULL;
191 :
192 1 : CHK_PRT_RETURN(ctxHandle == NULL || attr == NULL, hccp_err("[get][dev_attr]ctx_handle or attr is NULL"),
193 : ConverReturnCode(RDMA_OP, -EINVAL));
194 :
195 1 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
196 1 : (void)memcpy_s(attr, sizeof(struct DevBaseAttr), &(ctxHandleTmp->devAttr), sizeof(struct DevBaseAttr));
197 :
198 1 : hccp_info("[get][dev_attr]phy_id(%u), devIndex(%u)", ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex);
199 1 : return 0;
200 : }
201 :
202 0 : HCCP_ATTRI_VISI_DEF int RaCtxGetAsyncEvents(void *ctxHandle, struct AsyncEvent events[], unsigned int *num)
203 : {
204 0 : struct RaCtxHandle *ctxHandleTmp = NULL;
205 0 : int ret = 0;
206 :
207 0 : CHK_PRT_RETURN(ctxHandle == NULL || events == NULL || num == NULL,
208 : hccp_err("[get][async_events]ctx_handle or events or num is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
209 :
210 0 : CHK_PRT_RETURN(*num == 0 || *num > ASYNC_EVENT_MAX_NUM, hccp_err("[get][async_events]num:%u must greater than 0"
211 : " and less or equal to %d", *num, ASYNC_EVENT_MAX_NUM), ConverReturnCode(RDMA_OP, -EINVAL));
212 :
213 0 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
214 0 : CHK_PRT_RETURN(ctxHandleTmp->ctxOps == NULL || ctxHandleTmp->ctxOps->raCtxGetAsyncEvents == NULL,
215 : hccp_err("[get][async_events]ctx_ops or ra_ctx_get_async_events is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
216 :
217 0 : ret = ctxHandleTmp->ctxOps->raCtxGetAsyncEvents(ctxHandleTmp, events, num);
218 0 : CHK_PRT_RETURN(ret != 0, hccp_err("[get][async_events]get async events failed, ret:%d phyId(%u) devIndex:0x%x",
219 : ret, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex), ConverReturnCode(RDMA_OP, ret));
220 :
221 0 : return ConverReturnCode(RDMA_OP, ret);
222 : }
223 :
224 1 : HCCP_ATTRI_VISI_DEF int RaCtxDeinit(void *ctxHandle)
225 : {
226 1 : struct RaCtxHandle *ctxHandleTmp = NULL;
227 : int ret;
228 :
229 1 : CHK_PRT_RETURN(ctxHandle == NULL, hccp_err("[deinit][ra_ctx]ctx_handle is NULL"),
230 : ConverReturnCode(RDMA_OP, -EINVAL));
231 :
232 1 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
233 1 : CHK_PRT_RETURN(ctxHandleTmp->ctxOps == NULL || ctxHandleTmp->ctxOps->raCtxDeinit == NULL,
234 : hccp_err("[deinit][ra_ctx]ctx_ops or ra_ctx_deinit is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
235 :
236 1 : hccp_run_info("Input parameters: phy_id[%u], devIndex[%u], protocol[%d]",
237 : ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex, ctxHandleTmp->protocol);
238 1 : ret = ctxHandleTmp->ctxOps->raCtxDeinit(ctxHandleTmp);
239 1 : if (ret != 0) {
240 0 : hccp_err("[deinit][ra_ctx]ctx deinit failed, ret(%d) phyId(%u) devIndex(%u)",
241 : ret, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex);
242 : }
243 :
244 1 : ctxHandleTmp->ctxOps = NULL;
245 1 : free(ctxHandleTmp);
246 1 : ctxHandleTmp = NULL;
247 1 : return ConverReturnCode(HCCP_INIT, ret);
248 : }
249 :
250 5 : HCCP_ATTRI_VISI_DEF int RaGetEidByIp(void *ctxHandle, struct IpInfo ip[], union HccpEid eid[], unsigned int *num)
251 : {
252 5 : struct RaCtxHandle *ctxHandleTmp = NULL;
253 5 : int ret = 0;
254 :
255 5 : CHK_PRT_RETURN(ctxHandle == NULL || ip == NULL || eid == NULL || num == NULL,
256 : hccp_err("[get][eid_by_ip]ctx_handle or ip or eid or num is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
257 :
258 4 : CHK_PRT_RETURN(*num == 0 || *num > HCCP_EID_IP_QUERY_MAX_NUM, hccp_err("[get][eid_by_ip]num(%u) must greater than 0"
259 : " and less or equal to %d", *num, HCCP_EID_IP_QUERY_MAX_NUM), ConverReturnCode(RDMA_OP, -EINVAL));
260 :
261 3 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
262 :
263 3 : CHK_PRT_RETURN(ctxHandleTmp->ctxOps == NULL || ctxHandleTmp->ctxOps->raCtxGetEidByIp == NULL,
264 : hccp_err("[get][eid_by_ip]ctx_ops or ra_ctx_get_eid_by_ip is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
265 :
266 2 : hccp_run_info("Input parameters: phyId:%u, devIndex:0x%x num:%u",
267 : ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex, *num);
268 :
269 2 : ret = ctxHandleTmp->ctxOps->raCtxGetEidByIp(ctxHandle, ip, eid, num);
270 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[get][eid_by_ip]ra_ctx_get_eid_by_ip failed, ret(%d) phyId(%u) devIndex(0x%x)",
271 : ret, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex), ConverReturnCode(RDMA_OP, ret));
272 :
273 1 : return ConverReturnCode(RDMA_OP, ret);
274 : }
275 :
276 5 : HCCP_ATTRI_VISI_DEF int RaGetIpByEid(void *ctxHandle, union HccpEid eid[], struct IpInfo ip[], unsigned int *num)
277 : {
278 5 : struct RaCtxHandle *ctxHandleTmp = NULL;
279 5 : int ret = 0;
280 :
281 5 : CHK_PRT_RETURN(ctxHandle == NULL || eid == NULL || ip == NULL || num == NULL,
282 : hccp_err("[get][IpByEid]ctxHandle or eid or ip or num is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
283 :
284 4 : CHK_PRT_RETURN(*num == 0 || *num > HCCP_EID_IP_QUERY_MAX_NUM, hccp_err("[get][IpByEid]num(%u) must greater than 0"
285 : " and less or equal to %d", *num, HCCP_EID_IP_QUERY_MAX_NUM), ConverReturnCode(RDMA_OP, -EINVAL));
286 :
287 3 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
288 :
289 3 : CHK_PRT_RETURN(ctxHandleTmp->ctxOps == NULL || ctxHandleTmp->ctxOps->raCtxGetIpByEid == NULL,
290 : hccp_err("[get][IpByEid]ctxOps or raCtxGetIpByEid is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
291 :
292 2 : hccp_run_info("Input parameters: phy_id:%u, devIndex:0x%x num:%u",
293 : ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex, *num);
294 :
295 2 : ret = ctxHandleTmp->ctxOps->raCtxGetIpByEid(ctxHandle, eid, ip, num);
296 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[get][IpByEid]raCtxGetIpByEid failed, ret(%d) phyId(%u) devIndex(0x%x)",
297 : ret, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex), ConverReturnCode(RDMA_OP, ret));
298 :
299 1 : return ConverReturnCode(RDMA_OP, ret);
300 : }
301 :
302 4 : HCCP_ATTRI_VISI_DEF int RaCtxTokenIdAlloc(void *ctxHandle, struct HccpTokenId *info, void **tokenIdHandle)
303 : {
304 4 : struct RaTokenIdHandle *tokenIdHandleTmp = NULL;
305 4 : struct RaCtxHandle *ctxHandleTmp = NULL;
306 : int ret;
307 :
308 4 : CHK_PRT_RETURN(ctxHandle == NULL || info == NULL || tokenIdHandle == NULL,
309 : hccp_err("[init][ra_token_id]ctx_handle or info or token_id_handle is NULL"),
310 : ConverReturnCode(RDMA_OP, -EINVAL));
311 :
312 3 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
313 3 : CHK_PRT_RETURN(ctxHandleTmp->ctxOps == NULL || ctxHandleTmp->ctxOps->raCtxTokenIdAlloc == NULL,
314 : hccp_err("[init][ra_token_id]ctx_ops or ra_ctx_token_id_alloc is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
315 :
316 3 : tokenIdHandleTmp = (struct RaTokenIdHandle *)calloc(1, sizeof(struct RaTokenIdHandle));
317 3 : CHK_PRT_RETURN(tokenIdHandleTmp == NULL,
318 : hccp_err("[init][ra_token_id]calloc token_id_handle_tmp failed, errno(%d) phyId(%u) devIndex(%u)",
319 : errno, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex), ConverReturnCode(RDMA_OP, -ENOMEM));
320 :
321 3 : ret = ctxHandleTmp->ctxOps->raCtxTokenIdAlloc(ctxHandleTmp, info, tokenIdHandleTmp);
322 3 : if (ret != 0) {
323 1 : hccp_err("[init][ra_token_id]alloc failed, ret(%d) phyId(%u) devIndex(%u)",
324 : ret, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex);
325 1 : goto err;
326 : }
327 :
328 2 : *tokenIdHandle = (void *)tokenIdHandleTmp;
329 2 : return 0;
330 :
331 1 : err:
332 1 : free(tokenIdHandleTmp);
333 1 : tokenIdHandleTmp = NULL;
334 1 : return ConverReturnCode(RDMA_OP, ret);
335 : }
336 :
337 3 : HCCP_ATTRI_VISI_DEF int RaCtxTokenIdFree(void *ctxHandle, void *tokenIdHandle)
338 : {
339 3 : struct RaTokenIdHandle *tokenIdHandleTmp = NULL;
340 3 : struct RaCtxHandle *ctxHandleTmp = NULL;
341 : int ret;
342 :
343 3 : CHK_PRT_RETURN(ctxHandle == NULL || tokenIdHandle == NULL,
344 : hccp_err("[deinit][ra_token_id]ctx_handle or token_id_handle is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
345 :
346 2 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
347 2 : CHK_PRT_RETURN(ctxHandleTmp->ctxOps == NULL || ctxHandleTmp->ctxOps->raCtxTokenIdFree == NULL,
348 : hccp_err("[deinit][ra_token_id]ctx_ops or ra_ctx_token_id_free is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
349 :
350 2 : tokenIdHandleTmp = (struct RaTokenIdHandle *)tokenIdHandle;
351 2 : ret = ctxHandleTmp->ctxOps->raCtxTokenIdFree(ctxHandleTmp, tokenIdHandleTmp);
352 2 : if (ret != 0) {
353 1 : hccp_err("[deinit][ra_token_id]free failed, ret(%d) phyId(%u) devIndex(%u)",
354 : ret, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex);
355 : }
356 :
357 2 : free(tokenIdHandleTmp);
358 2 : tokenIdHandleTmp = NULL;
359 2 : return ConverReturnCode(RDMA_OP, ret);
360 : }
361 :
362 2 : HCCP_ATTRI_VISI_DEF int RaCtxLmemRegister(void *ctxHandle, struct MrRegInfoT *lmemInfo, void **lmemHandle)
363 : {
364 2 : struct RaLmemHandle *lmemHandleTmp = NULL;
365 2 : struct RaCtxHandle *ctxHandleTmp = NULL;
366 : int ret;
367 :
368 2 : CHK_PRT_RETURN(ctxHandle == NULL || lmemInfo == NULL || lmemHandle == NULL,
369 : hccp_err("[init][ra_lmem]ctx_handle or lmem_info or lmem_handle is NULL"),
370 : ConverReturnCode(RDMA_OP, -EINVAL));
371 :
372 2 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
373 2 : CHK_PRT_RETURN(ctxHandleTmp->ctxOps == NULL || ctxHandleTmp->ctxOps->raCtxLmemRegister == NULL,
374 : hccp_err("[init][ra_lmem]ctx_ops or ra_ctx_lmem_register is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
375 :
376 2 : lmemHandleTmp = calloc(1, sizeof(struct RaLmemHandle));
377 2 : CHK_PRT_RETURN(lmemHandleTmp == NULL,
378 : hccp_err("[init][ra_lmem]calloc lmem_handle_tmp failed, errno(%d) phyId(%u) devIndex(%u)",
379 : errno, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex), ConverReturnCode(RDMA_OP, -ENOMEM));
380 :
381 2 : ret = ctxHandleTmp->ctxOps->raCtxLmemRegister(ctxHandleTmp, lmemInfo, lmemHandleTmp);
382 2 : if (ret != 0) {
383 0 : hccp_err("[init][ra_lmem]register failed, ret(%d) phyId(%u) devIndex(%u)",
384 : ret, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex);
385 0 : goto err;
386 : }
387 :
388 2 : *lmemHandle = (void *)lmemHandleTmp;
389 2 : return 0;
390 :
391 0 : err:
392 0 : free(lmemHandleTmp);
393 0 : lmemHandleTmp = NULL;
394 0 : return ConverReturnCode(RDMA_OP, ret);
395 : }
396 :
397 1 : HCCP_ATTRI_VISI_DEF int RaCtxLmemUnregister(void *ctxHandle, void *lmemHandle)
398 : {
399 1 : struct RaLmemHandle *lmemHandleTmp = NULL;
400 1 : struct RaCtxHandle *ctxHandleTmp = NULL;
401 : int ret;
402 :
403 1 : CHK_PRT_RETURN(ctxHandle == NULL || lmemHandle == NULL,
404 : hccp_err("[deinit][ra_lmem]ctx_handle or lmem_handle is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
405 :
406 1 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
407 1 : CHK_PRT_RETURN(ctxHandleTmp->ctxOps == NULL || ctxHandleTmp->ctxOps->raCtxLmemUnregister == NULL,
408 : hccp_err("[deinit][ra_lmem]ctx_ops or ra_ctx_lmem_unregister is NULL"),
409 : ConverReturnCode(RDMA_OP, -EINVAL));
410 :
411 1 : lmemHandleTmp = (struct RaLmemHandle *)lmemHandle;
412 1 : ret = ctxHandleTmp->ctxOps->raCtxLmemUnregister(ctxHandleTmp, lmemHandleTmp);
413 1 : if (ret != 0) {
414 0 : hccp_err("[deinit][ra_lmem]unregister failed, ret(%d) phyId(%u) devIndex(%u)",
415 : ret, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex);
416 : }
417 :
418 1 : free(lmemHandleTmp);
419 1 : lmemHandleTmp = NULL;
420 1 : return ConverReturnCode(RDMA_OP, ret);
421 : }
422 :
423 1 : HCCP_ATTRI_VISI_DEF int RaCtxRmemImport(void *ctxHandle, struct MrImportInfoT *rmemInfo, void **rmemHandle)
424 : {
425 1 : struct RaRmemHandle *rmemHandleTmp = NULL;
426 1 : struct RaCtxHandle *ctxHandleTmp = NULL;
427 : int ret;
428 :
429 1 : CHK_PRT_RETURN(ctxHandle == NULL || rmemInfo == NULL || rmemHandle == NULL,
430 : hccp_err("[init][ra_rmem]ctx_handle or rmem_info or rmem_handle is NULL"),
431 : ConverReturnCode(RDMA_OP, -EINVAL));
432 :
433 1 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
434 1 : CHK_PRT_RETURN(ctxHandleTmp->ctxOps == NULL || ctxHandleTmp->ctxOps->raCtxRmemImport == NULL,
435 : hccp_err("[init][ra_rmem]ctx_ops is NULL or ra_ctx_rmem_import ops is NULL"),
436 : ConverReturnCode(RDMA_OP, -EINVAL));
437 :
438 1 : rmemHandleTmp = calloc(1, sizeof(struct RaRmemHandle));
439 1 : CHK_PRT_RETURN(rmemHandleTmp == NULL,
440 : hccp_err("[init][ra_rmem]calloc rmem_handle_tmp failed, errno(%d) phyId(%u) devIndex(%u)",
441 : errno, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex), ConverReturnCode(RDMA_OP, -ENOMEM));
442 :
443 1 : ret = ctxHandleTmp->ctxOps->raCtxRmemImport(ctxHandleTmp, rmemInfo);
444 1 : if (ret != 0) {
445 0 : hccp_err("[init][ra_lmem]import failed, ret(%d) phyId(%u) devIndex(%u)",
446 : ret, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex);
447 0 : goto err;
448 : }
449 :
450 1 : rmemHandleTmp->key = rmemInfo->in.key;
451 1 : rmemHandleTmp->addr = rmemInfo->out.ub.targetSegHandle;
452 1 : *rmemHandle = (void *)rmemHandleTmp;
453 1 : return 0;
454 :
455 0 : err:
456 0 : free(rmemHandleTmp);
457 0 : rmemHandleTmp = NULL;
458 0 : return ConverReturnCode(RDMA_OP, ret);
459 : }
460 :
461 1 : HCCP_ATTRI_VISI_DEF int RaCtxRmemUnimport(void *ctxHandle, void *rmemHandle)
462 : {
463 1 : struct RaRmemHandle *rmemHandleTmp = NULL;
464 1 : struct RaCtxHandle *ctxHandleTmp = NULL;
465 : int ret;
466 :
467 1 : CHK_PRT_RETURN(ctxHandle == NULL || rmemHandle == NULL,
468 : hccp_err("[deinit][ra_rmem]ctx_handle or rmem_handle is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
469 :
470 1 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
471 1 : CHK_PRT_RETURN(ctxHandleTmp->ctxOps == NULL || ctxHandleTmp->ctxOps->raCtxRmemUnimport == NULL,
472 : hccp_err("[deinit][ra_rmem]ctx_ops or ra_ctx_rmem_unimport is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
473 :
474 1 : rmemHandleTmp = (struct RaRmemHandle *)rmemHandle;
475 1 : ret = ctxHandleTmp->ctxOps->raCtxRmemUnimport(ctxHandleTmp, rmemHandleTmp);
476 1 : if (ret != 0) {
477 0 : hccp_err("[deinit][ra_rmem]unimport failed, ret(%d) phyId(%u) devIndex(%u)",
478 : ret, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex);
479 : }
480 :
481 1 : free(rmemHandleTmp);
482 1 : rmemHandleTmp = NULL;
483 1 : return ConverReturnCode(RDMA_OP, ret);
484 : }
485 :
486 1 : HCCP_ATTRI_VISI_DEF int RaCtxChanCreate(void *ctxHandle, struct ChanInfoT *chanInfo, void **chanHandle)
487 : {
488 1 : struct RaChanHandle *chanHandleTmp = NULL;
489 1 : struct RaCtxHandle *ctxHandleTmp = NULL;
490 : int ret;
491 :
492 1 : CHK_PRT_RETURN(ctxHandle == NULL || chanInfo == NULL || chanHandle == NULL,
493 : hccp_err("[init][ra_chan]ctx_handle or chan_info or chan_handle is NULL"),
494 : ConverReturnCode(RDMA_OP, -EINVAL));
495 :
496 1 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
497 1 : CHK_PRT_RETURN(ctxHandleTmp->ctxOps == NULL || ctxHandleTmp->ctxOps->raCtxChanCreate == NULL,
498 : hccp_err("[init][ra_chan]ctx_ops or ra_ctx_chan_create ops is NULL"),
499 : ConverReturnCode(RDMA_OP, -EINVAL));
500 :
501 1 : chanHandleTmp = (struct RaChanHandle *)calloc(1, sizeof(struct RaChanHandle));
502 1 : CHK_PRT_RETURN(chanHandleTmp == NULL,
503 : hccp_err("[init][ra_chan]calloc chan_handle_tmp failed, errno(%d) phyId(%u) devIndex(%u)",
504 : errno, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex), ConverReturnCode(RDMA_OP, -ENOMEM));
505 :
506 1 : ret = ctxHandleTmp->ctxOps->raCtxChanCreate(ctxHandleTmp, chanInfo, chanHandleTmp);
507 1 : if (ret != 0) {
508 0 : hccp_err("[init][ra_chan]create failed, ret(%d)", ret);
509 0 : goto err;
510 : }
511 :
512 1 : *chanHandle = (void *)chanHandleTmp;
513 1 : return 0;
514 :
515 0 : err:
516 0 : free(chanHandleTmp);
517 0 : chanHandleTmp = NULL;
518 0 : return ConverReturnCode(RDMA_OP, ret);
519 : }
520 :
521 1 : HCCP_ATTRI_VISI_DEF int RaCtxChanDestroy(void *ctxHandle, void *chanHandle)
522 : {
523 1 : struct RaChanHandle *chanHandleTmp = NULL;
524 1 : struct RaCtxHandle *ctxHandleTmp = NULL;
525 : int ret;
526 :
527 1 : CHK_PRT_RETURN(ctxHandle == NULL || chanHandle == NULL,
528 : hccp_err("[deinit][ra_chan]ctx_handle or chan_handle is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
529 :
530 1 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
531 1 : CHK_PRT_RETURN(ctxHandleTmp->ctxOps == NULL || ctxHandleTmp->ctxOps->raCtxChanDestroy == NULL,
532 : hccp_err("[deinit][ra_chan]ctx_ops or ra_ctx_chan_destroy is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
533 :
534 1 : chanHandleTmp = (struct RaChanHandle *)chanHandle;
535 1 : ret = ctxHandleTmp->ctxOps->raCtxChanDestroy(ctxHandleTmp, chanHandleTmp);
536 1 : if (ret != 0) {
537 0 : hccp_err("[deinit][ra_chan]destroy failed, ret(%d) phyId(%u) devIndex(%u)",
538 : ret, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex);
539 : }
540 :
541 1 : free(chanHandleTmp);
542 1 : chanHandleTmp = NULL;
543 1 : return ConverReturnCode(RDMA_OP, ret);
544 : }
545 :
546 4 : HCCP_ATTRI_VISI_DEF int RaCtxCqCreate(void *ctxHandle, struct CqInfoT *info, void **cqHandle)
547 : {
548 4 : struct RaCtxHandle *ctxHandleTmp = NULL;
549 4 : struct RaCqHandle *cqHandleTmp = NULL;
550 : int ret;
551 :
552 4 : CHK_PRT_RETURN(ctxHandle == NULL || info == NULL || cqHandle == NULL,
553 : hccp_err("[init][ra_cq]ctx_handle or info or cq_handle is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
554 :
555 3 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
556 3 : CHK_PRT_RETURN(ctxHandleTmp->ctxOps == NULL || ctxHandleTmp->ctxOps->raCtxCqCreate == NULL,
557 : hccp_err("[init][ra_cq]ctx_ops or ra_ctx_cq_create ops is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
558 :
559 3 : cqHandleTmp = (struct RaCqHandle *)calloc(1, sizeof(struct RaCqHandle));
560 3 : CHK_PRT_RETURN(cqHandleTmp == NULL,
561 : hccp_err("[init][ra_cq]calloc cq_handle_tmp failed, errno(%d) phyId(%u) devIndex(%u)",
562 : errno, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex), ConverReturnCode(RDMA_OP, -ENOMEM));
563 :
564 3 : ret = ctxHandleTmp->ctxOps->raCtxCqCreate(ctxHandleTmp, info, cqHandleTmp);
565 3 : if (ret != 0) {
566 0 : hccp_err("[init][ra_cq]create failed, ret(%d) phyId(%u) devIndex(%u)",
567 : ret, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex);
568 0 : goto err;
569 : }
570 :
571 3 : *cqHandle = (void *)cqHandleTmp;
572 3 : return 0;
573 :
574 0 : err:
575 0 : free(cqHandleTmp);
576 0 : cqHandleTmp = NULL;
577 0 : return ConverReturnCode(RDMA_OP, ret);
578 : }
579 :
580 2 : HCCP_ATTRI_VISI_DEF int RaCtxCqDestroy(void *ctxHandle, void *cqHandle)
581 : {
582 2 : struct RaCtxHandle *ctxHandleTmp = NULL;
583 2 : struct RaCqHandle *cqHandleTmp = NULL;
584 : int ret;
585 :
586 2 : CHK_PRT_RETURN(ctxHandle == NULL || cqHandle == NULL,
587 : hccp_err("[deinit][ra_cq]ctx_handle or cq_handle is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
588 :
589 2 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
590 2 : CHK_PRT_RETURN(ctxHandleTmp->ctxOps == NULL || ctxHandleTmp->ctxOps->raCtxCqDestroy == NULL,
591 : hccp_err("[deinit][ra_cq]ctx_ops or ra_ctx_cq_destroy is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
592 :
593 2 : cqHandleTmp = (struct RaCqHandle *)cqHandle;
594 2 : ret = ctxHandleTmp->ctxOps->raCtxCqDestroy(ctxHandleTmp, cqHandleTmp);
595 2 : if (ret != 0) {
596 0 : hccp_err("[deinit][ra_cq]destroy failed, ret(%d) phyId(%u) devIndex(%u)",
597 : ret, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex);
598 : }
599 :
600 2 : free(cqHandleTmp);
601 2 : cqHandleTmp = NULL;
602 2 : return ConverReturnCode(RDMA_OP, ret);
603 : }
604 :
605 4 : HCCP_ATTRI_VISI_DEF int RaCtxQpCreate(void *ctxHandle, struct QpCreateAttr *attr, struct QpCreateInfo *info,
606 : void **qpHandle)
607 : {
608 4 : struct RaCtxQpHandle *qpHandleTmp = NULL;
609 4 : struct RaCtxHandle *ctxHandleTmp = NULL;
610 : int ret;
611 :
612 4 : CHK_PRT_RETURN(ctxHandle == NULL || attr == NULL || info == NULL || qpHandle == NULL,
613 : hccp_err("[init][ra_qp]ctx_handle or attr or info or qp_handle is NULL"),
614 : ConverReturnCode(RDMA_OP, -EINVAL));
615 :
616 3 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
617 3 : CHK_PRT_RETURN(ctxHandleTmp->ctxOps == NULL || ctxHandleTmp->ctxOps->raCtxQpCreate == NULL,
618 : hccp_err("[init][ra_qp]ctx_ops or ra_ctx_qp_create is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
619 :
620 3 : qpHandleTmp = calloc(1, sizeof(struct RaCtxQpHandle));
621 3 : CHK_PRT_RETURN(qpHandleTmp == NULL,
622 : hccp_err("[init][ra_qp]calloc qp_handle_tmp failed, errno(%d) phyId(%u) devIndex(%u)",
623 : errno, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex), ConverReturnCode(RDMA_OP, -ENOMEM));
624 :
625 3 : ret = ctxHandleTmp->ctxOps->raCtxQpCreate(ctxHandleTmp, attr, info, qpHandleTmp);
626 3 : if (ret != 0) {
627 0 : hccp_err("[init][ra_qp]create failed, ret(%d) phyId(%u) devIndex(%u)",
628 : ret, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex);
629 0 : goto err;
630 : }
631 :
632 3 : *qpHandle = (void *)qpHandleTmp;
633 3 : return 0;
634 :
635 0 : err:
636 0 : free(qpHandleTmp);
637 0 : qpHandleTmp = NULL;
638 0 : return ConverReturnCode(RDMA_OP, ret);
639 : }
640 :
641 6 : STATIC int QpQueryBatchParamCheck(void *qpHandle[], unsigned int *num, unsigned int phyId, unsigned int ids[])
642 : {
643 6 : struct RaCtxQpHandle *qpHandleTmp = NULL;
644 : unsigned int i;
645 :
646 8 : for (i = 0; i < *num; i++) {
647 7 : qpHandleTmp = (struct RaCtxQpHandle *)qpHandle[i];
648 7 : CHK_PRT_RETURN(qpHandleTmp == NULL, hccp_err("[query][ra_qp]qp_handle[%u] is NULL", i), -EINVAL);
649 6 : CHK_PRT_RETURN(qpHandleTmp->phyId != phyId,
650 : hccp_err("[query][ra_qp]qp_handle[%u] comes from different devices, phyId[%u] != qpHandle[0]->phyId(%u)",
651 : i, qpHandleTmp->phyId, phyId), -EINVAL);
652 5 : CHK_PRT_RETURN(qpHandleTmp->ctxHandle == NULL || qpHandleTmp->ctxHandle->ctxOps == NULL ||
653 : qpHandleTmp->ctxHandle->ctxOps->raCtxQueryQpBatch == NULL,
654 : hccp_err("[query][ra_qp]ctx_handle or ctx_ops or ra_ctx_query_qp_batch is NULL"), -EINVAL);
655 :
656 2 : ids[i] = qpHandleTmp->id;
657 : }
658 :
659 1 : return 0;
660 : }
661 :
662 6 : HCCP_ATTRI_VISI_DEF int RaCtxQpQueryBatch(void *qpHandle[], struct JettyAttr attr[], unsigned int *num)
663 : {
664 6 : struct RaCtxQpHandle *qpHandleTmp = NULL;
665 6 : unsigned int ids[HCCP_MAX_QP_QUERY_NUM] = {0};
666 : unsigned int phyId, devIndex;
667 : int ret;
668 :
669 6 : CHK_PRT_RETURN(qpHandle == NULL || attr == NULL, hccp_err("[query][ra_qp]qp_handle or attr is NULL"),
670 : ConverReturnCode(RDMA_OP, -EINVAL));
671 4 : CHK_PRT_RETURN(num == NULL, hccp_err("num is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
672 3 : CHK_PRT_RETURN(*num == 0 || *num > HCCP_MAX_QP_QUERY_NUM, hccp_err("[query][ra_qp]num(%u) is out of range(0, %u]",
673 : *num, HCCP_MAX_QP_QUERY_NUM), ConverReturnCode(RDMA_OP, -EINVAL));
674 :
675 2 : qpHandleTmp = (struct RaCtxQpHandle *)qpHandle[0];
676 2 : CHK_PRT_RETURN(qpHandleTmp == NULL, hccp_err("[query][ra_qp]qp_handle[0] is NULL"), -EINVAL);
677 2 : phyId = qpHandleTmp->phyId;
678 2 : devIndex = qpHandleTmp->devIndex;
679 :
680 2 : ret = QpQueryBatchParamCheck(qpHandle, num, phyId, ids);
681 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[query][ra_qp]qp_query_batch_param_check failed, ret(%d)", ret),
682 : ConverReturnCode(RDMA_OP, ret));
683 :
684 2 : ret = qpHandleTmp->ctxHandle->ctxOps->raCtxQueryQpBatch(phyId, devIndex, ids, attr, num);
685 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[query][ra_qp]query_qp_batch failed, ret(%d)", ret),
686 : ConverReturnCode(RDMA_OP, ret));
687 :
688 1 : return ConverReturnCode(RDMA_OP, ret);
689 : }
690 :
691 2 : HCCP_ATTRI_VISI_DEF int RaCtxQpDestroy(void *qpHandle)
692 : {
693 2 : struct RaCtxQpHandle *qpHandleTmp = NULL;
694 : int ret;
695 :
696 2 : CHK_PRT_RETURN(qpHandle == NULL, hccp_err("[deinit][ra_qp]qp_handle is NULL"),
697 : ConverReturnCode(RDMA_OP, -EINVAL));
698 :
699 2 : qpHandleTmp = (struct RaCtxQpHandle *)qpHandle;
700 2 : CHK_PRT_RETURN(qpHandleTmp->ctxHandle == NULL || qpHandleTmp->ctxHandle->ctxOps == NULL ||
701 : qpHandleTmp->ctxHandle->ctxOps->raCtxQpDestroy == NULL, hccp_err("[deinit][ra_qp]ctx_handle or ctx_ops "
702 : "or ra_ctx_qp_destroy is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
703 :
704 2 : ret = qpHandleTmp->ctxHandle->ctxOps->raCtxQpDestroy(qpHandleTmp);
705 2 : if (ret == -ENODEV) {
706 0 : hccp_warn("[deinit][ra_qp]destroy unsuccessful, ret(%d) phyId(%u) devIndex(%u) qp_id(%u)",
707 : ret, qpHandleTmp->phyId, qpHandleTmp->devIndex, qpHandleTmp->id);
708 0 : goto out;
709 : }
710 2 : if (ret != 0) {
711 0 : hccp_err("[deinit][ra_qp]destroy failed, ret(%d) phyId(%u) devIndex(%u) qp_id(%u)",
712 : ret, qpHandleTmp->phyId, qpHandleTmp->devIndex, qpHandleTmp->id);
713 : }
714 :
715 2 : out:
716 2 : free(qpHandleTmp);
717 2 : qpHandleTmp = NULL;
718 2 : return ConverReturnCode(RDMA_OP, ret);
719 : }
720 :
721 4 : HCCP_ATTRI_VISI_DEF int RaCtxGetTpInfoList(void *ctxHandle, struct GetTpCfg *cfg, struct HccpTpInfo infoList[],
722 : unsigned int *num)
723 : {
724 4 : struct RaCtxHandle *ctxHandleTmp = NULL;
725 4 : int ret = 0;
726 :
727 4 : CHK_PRT_RETURN(ctxHandle == NULL || cfg == NULL,
728 : hccp_err("[get][RaTpInfo]ctxHandle or cfg is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
729 3 : CHK_PRT_RETURN(infoList == NULL || num == NULL,
730 : hccp_err("[get][RaTpInfo]infoList or num is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
731 2 : CHK_PRT_RETURN(*num == 0 || *num > HCCP_MAX_TPID_INFO_NUM,
732 : hccp_err("[get][RaTpInfo]*num(%u) is out of range[0, %d]", *num, HCCP_MAX_TPID_INFO_NUM),
733 : ConverReturnCode(RDMA_OP, -EINVAL));
734 :
735 1 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
736 1 : ret = RaPeerCtxGetTpInfoList(ctxHandleTmp, cfg, infoList, num);
737 1 : return ConverReturnCode(RDMA_OP, ret);
738 : }
739 :
740 3 : HCCP_ATTRI_VISI_DEF int RaCtxGetTpAttr(void *ctxHandle, uint64_t tpHandle, uint32_t *attrBitmap, struct TpAttr *attr)
741 : {
742 3 : struct RaCtxHandle *ctxHandleTmp = NULL;
743 3 : int ret = 0;
744 :
745 3 : CHK_PRT_RETURN(ctxHandle == NULL || attrBitmap == NULL || attr == NULL,
746 : hccp_err("[get][RaTpAttr]ctxHandle or attrBitmap or attr is NULL"),
747 : ConverReturnCode(RDMA_OP, -EINVAL));
748 :
749 2 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
750 2 : ret = RaPeerCtxGetTpAttr(ctxHandleTmp, tpHandle, attrBitmap, attr);
751 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[get][RaTpAttr]RaPeerCtxGetTpAttr failed, ret[%d] phyId[%u] devIndex[0x%x]",
752 : ret, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex), ConverReturnCode(RDMA_OP, ret));
753 :
754 1 : return ConverReturnCode(RDMA_OP, ret);
755 : }
756 :
757 3 : HCCP_ATTRI_VISI_DEF int RaCtxSetTpAttr(void *ctxHandle, uint64_t tpHandle, uint32_t attrBitmap, struct TpAttr *attr)
758 : {
759 3 : struct RaCtxHandle *ctxHandleTmp = NULL;
760 3 : int ret = 0;
761 :
762 3 : CHK_PRT_RETURN(ctxHandle == NULL || attr == NULL,
763 : hccp_err("[set][RaTpAttr]ctxHandle or attr or attr is NULL"),
764 : ConverReturnCode(RDMA_OP, -EINVAL));
765 :
766 2 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
767 2 : ret = RaPeerCtxSetTpAttr(ctxHandleTmp, tpHandle, attrBitmap, attr);
768 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[set][RaTpAttr]RaPeerCtxSetTpAttr failed, ret[%d] phyId[%u] devIndex[0x%x]",
769 : ret, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex), ConverReturnCode(RDMA_OP, ret));
770 :
771 1 : return ConverReturnCode(RDMA_OP, ret);
772 : }
773 :
774 1 : HCCP_ATTRI_VISI_DEF int RaCtxQpImport(void *ctxHandle, struct QpImportInfoT *qpInfo, void **remQpHandle)
775 : {
776 1 : struct RaCtxRemQpHandle *remQpHandleTmp = NULL;
777 1 : struct RaCtxHandle *ctxHandleTmp = NULL;
778 : int ret;
779 :
780 1 : CHK_PRT_RETURN(ctxHandle == NULL || qpInfo == NULL || remQpHandle == NULL,
781 : hccp_err("[init][ra_qp]ctx_handle or qp_info or rem_qp_handle is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
782 :
783 1 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
784 1 : CHK_PRT_RETURN(ctxHandleTmp->ctxOps == NULL || ctxHandleTmp->ctxOps->raCtxQpImport == NULL,
785 : hccp_err("[init][ra_qp]ctx_ops or ra_ctx_qp_import is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
786 :
787 1 : remQpHandleTmp = calloc(1, sizeof(struct RaCtxRemQpHandle));
788 1 : CHK_PRT_RETURN(remQpHandleTmp == NULL,
789 : hccp_err("[init][ra_qp]calloc rem_qp_handle_tmp failed, errno(%d) phyId(%u) devIndex(%u)",
790 : errno, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex), ConverReturnCode(RDMA_OP, -ENOMEM));
791 :
792 1 : ret = ctxHandleTmp->ctxOps->raCtxQpImport(ctxHandleTmp, qpInfo, remQpHandleTmp);
793 1 : if (ret != 0) {
794 0 : hccp_err("[init][ra_qp]import failed, ret(%d) phyId(%u) devIndex(%u)",
795 : ret, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex);
796 0 : goto err;
797 : }
798 :
799 1 : *remQpHandle = (void *)remQpHandleTmp;
800 1 : return 0;
801 :
802 0 : err:
803 0 : free(remQpHandleTmp);
804 0 : remQpHandleTmp = NULL;
805 0 : return ConverReturnCode(RDMA_OP, ret);
806 : }
807 :
808 1 : HCCP_ATTRI_VISI_DEF int RaCtxQpUnimport(void *ctxHandle, void *remQpHandle)
809 : {
810 1 : struct RaCtxRemQpHandle *remQpHandleTmp = NULL;
811 1 : struct RaCtxHandle *ctxHandleTmp = NULL;
812 : int ret;
813 :
814 1 : CHK_PRT_RETURN(ctxHandle == NULL || remQpHandle == NULL,
815 : hccp_err("[deinit][ra_qp]ctx_handle or rem_qp_handle is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
816 :
817 1 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
818 1 : CHK_PRT_RETURN(ctxHandleTmp->ctxOps == NULL || ctxHandleTmp->ctxOps->raCtxQpUnimport == NULL,
819 : hccp_err("[deinit][ra_qp]ctx_ops or ra_ctx_qp_unimport is NULL"),
820 : ConverReturnCode(RDMA_OP, -EINVAL));
821 :
822 1 : remQpHandleTmp = (struct RaCtxRemQpHandle *)remQpHandle;
823 1 : ret = ctxHandleTmp->ctxOps->raCtxQpUnimport(remQpHandleTmp);
824 1 : if (ret != 0) {
825 0 : hccp_err("[deinit][ra_qp]unimport failed, ret(%d) phyId(%u) devIndex(%u) qp_id(%u)",
826 : ret, remQpHandleTmp->phyId, remQpHandleTmp->devIndex, remQpHandleTmp->id);
827 : }
828 :
829 1 : free(remQpHandleTmp);
830 1 : remQpHandleTmp = NULL;
831 1 : return ConverReturnCode(RDMA_OP, ret);
832 : }
833 :
834 1 : HCCP_ATTRI_VISI_DEF int RaCtxQpBind(void *qpHandle, void *remQpHandle)
835 : {
836 1 : struct RaCtxRemQpHandle *remQpHandleTmp = NULL;
837 1 : struct RaCtxQpHandle *qpHandleTmp = NULL;
838 : int ret;
839 :
840 1 : CHK_PRT_RETURN(qpHandle == NULL || remQpHandle == NULL,
841 : hccp_err("[init][ra_qp]qp_handle or rem_qp_handle is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
842 :
843 1 : qpHandleTmp = (struct RaCtxQpHandle *)qpHandle;
844 1 : CHK_PRT_RETURN(qpHandleTmp->ctxHandle == NULL || qpHandleTmp->ctxHandle->ctxOps == NULL ||
845 : qpHandleTmp->ctxHandle->ctxOps->raCtxQpBind == NULL, hccp_err("[init][ra_qp]ctx_handle or ctx_ops "
846 : "or ra_ctx_qp_bind is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
847 :
848 1 : remQpHandleTmp = (struct RaCtxRemQpHandle *)remQpHandle;
849 1 : ret = qpHandleTmp->ctxHandle->ctxOps->raCtxQpBind(qpHandleTmp, remQpHandleTmp);
850 1 : CHK_PRT_RETURN(ret != 0, hccp_err("[init][ra_qp]bind failed, ret(%d) phyId(%u) devIndex(%u) "
851 : "local_id(%u) remote_id(%u)", ret, qpHandleTmp->ctxHandle->attr.phyId, qpHandleTmp->ctxHandle->devIndex,
852 : qpHandleTmp->id, remQpHandleTmp->id), ConverReturnCode(RDMA_OP, ret));
853 :
854 1 : return 0;
855 : }
856 :
857 2 : HCCP_ATTRI_VISI_DEF int RaCtxQpUnbind(void *qpHandle)
858 : {
859 2 : struct RaCtxQpHandle *qpHandleTmp = NULL;
860 : int ret;
861 :
862 2 : CHK_PRT_RETURN(qpHandle == NULL, hccp_err("[deinit][ra_qp]qp_handle is NULL"),
863 : ConverReturnCode(RDMA_OP, -EINVAL));
864 :
865 2 : qpHandleTmp = (struct RaCtxQpHandle *)qpHandle;
866 2 : CHK_PRT_RETURN(qpHandleTmp->ctxHandle == NULL || qpHandleTmp->ctxHandle->ctxOps == NULL ||
867 : qpHandleTmp->ctxHandle->ctxOps->raCtxQpUnbind == NULL, hccp_err("[deinit][ra_qp]ctx_handle or ctx_ops "
868 : "or ra_ctx_qp_unbind is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
869 :
870 2 : ret = qpHandleTmp->ctxHandle->ctxOps->raCtxQpUnbind(qpHandleTmp);
871 2 : CHK_PRT_RETURN(ret == -ENODEV, hccp_warn("[deinit][ra_qp]unbind unsuccessful, ret(%d) phyId(%u) devIndex(%u)",
872 : ret, qpHandleTmp->ctxHandle->attr.phyId, qpHandleTmp->ctxHandle->devIndex),
873 : ConverReturnCode(RDMA_OP, ret));
874 :
875 1 : CHK_PRT_RETURN(ret != 0, hccp_err("[deinit][ra_qp]unbind failed, ret(%d) phyId(%u) devIndex(%u)",
876 : ret, qpHandleTmp->ctxHandle->attr.phyId, qpHandleTmp->ctxHandle->devIndex),
877 : ConverReturnCode(RDMA_OP, ret));
878 1 : return ConverReturnCode(RDMA_OP, ret);
879 : }
880 :
881 2 : STATIC int RaCtxBatchSendWrCheck(struct RaCtxQpHandle *qpHandle, struct SendWrData wrList[],
882 : unsigned int num)
883 : {
884 2 : enum ProtocolTypeT protocol = qpHandle->protocol;
885 2 : bool isInline = false;
886 : unsigned int i, j;
887 :
888 4 : for (i = 0; i < num; i++) {
889 : // NOP opcode no need to check
890 2 : if (protocol == PROTOCOL_UDMA && wrList[i].ub.opcode == RA_UB_OPC_NOP) {
891 0 : continue;
892 : }
893 :
894 2 : CHK_PRT_RETURN(wrList[i].rmemHandle == NULL, hccp_err("[send][ra_qp]wr[%u] rmem_handle is NULL", i), -EINVAL);
895 :
896 3 : isInline = ((protocol == PROTOCOL_RDMA && (wrList[i].rdma.flags & RA_SEND_INLINE) != 0) ||
897 1 : (protocol == PROTOCOL_UDMA && wrList[i].ub.flags.bs.inlineFlag != 0));
898 2 : if (!isInline) {
899 0 : CHK_PRT_RETURN((wrList[i].sges == NULL), hccp_err("[send][ra_qp]wr[%u] sges is NULL", i), -EINVAL);
900 :
901 0 : for (j = 0; j < wrList[i].numSge; j++) {
902 0 : CHK_PRT_RETURN((wrList[i].sges[j].lmemHandle == NULL),
903 : hccp_err("[send][ra_qp]wr[%u] sges[%u] lmem_handle is NULL", i, j), -EINVAL);
904 : }
905 2 : } else if (wrList[i].inlineData == NULL) {
906 0 : hccp_err("[send][ra_qp]wr[%u] inline_data is NULL", i);
907 0 : return -EINVAL;
908 : }
909 :
910 2 : if (protocol == PROTOCOL_UDMA) {
911 1 : if (wrList[i].ub.remQpHandle == NULL ||
912 1 : (wrList[i].ub.opcode == RA_UB_OPC_WRITE_NOTIFY && wrList[i].ub.notifyInfo.notifyHandle == NULL)) {
913 0 : hccp_err("[send][ra_qp]wr[%u] opcode[%d] rem_qp_handle or notify_handle is NULL",
914 : i, wrList[i].ub.opcode);
915 0 : return -EINVAL;
916 : }
917 :
918 : // checkreduce, only write & write with notify & read op supportreduce
919 1 : if ((wrList[i].ub.opcode != RA_UB_OPC_WRITE && wrList[i].ub.opcode != RA_UB_OPC_WRITE_NOTIFY
920 0 : && wrList[i].ub.opcode != RA_UB_OPC_READ) && wrList[i].ub.reduceInfo.reduceEn) {
921 0 : hccp_err("[send][ra_qp]wr[%u] opcode[%d] not supportreduce", i, wrList[i].ub.opcode);
922 0 : return -EINVAL;
923 : }
924 : }
925 : }
926 :
927 2 : return 0;
928 : }
929 :
930 2 : HCCP_ATTRI_VISI_DEF int RaBatchSendWr(void *qpHandle, struct SendWrData wrList[], struct SendWrResp opResp[],
931 : unsigned int num, unsigned int *completeNum)
932 : {
933 2 : struct RaCtxQpHandle *qpHandleTmp = NULL;
934 : int ret;
935 :
936 2 : CHK_PRT_RETURN(qpHandle == NULL || wrList == NULL || opResp == NULL || num == 0 || completeNum == NULL,
937 : hccp_err("[send][ra_qp]qp_handle or wr_list or op_resp or complete_num is NULL, or num[%u] is 0", num),
938 : ConverReturnCode(RDMA_OP, -EINVAL));
939 :
940 2 : qpHandleTmp = (struct RaCtxQpHandle *)qpHandle;
941 2 : CHK_PRT_RETURN(qpHandleTmp->ctxHandle == NULL || qpHandleTmp->ctxHandle->ctxOps == NULL ||
942 : qpHandleTmp->ctxHandle->ctxOps->raCtxBatchSendWr == NULL,
943 : hccp_err("[send][ra_qp]ctx_handle or ctx_ops or ra_ctx_batch_send_wr is NULL"),
944 : ConverReturnCode(RDMA_OP, -EINVAL));
945 :
946 2 : ret = RaCtxBatchSendWrCheck(qpHandleTmp, wrList, num);
947 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[send][ra_qp]check failed, ret(%d), protocol(%d) phyId(%u), devIndex(%u)",
948 : ret, qpHandleTmp->protocol, qpHandleTmp->ctxHandle->attr.phyId, qpHandleTmp->ctxHandle->devIndex),
949 : ConverReturnCode(RDMA_OP, ret));
950 :
951 2 : ret = qpHandleTmp->ctxHandle->ctxOps->raCtxBatchSendWr(qpHandleTmp, wrList, opResp, num, completeNum);
952 2 : return ConverReturnCode(RDMA_OP, ret);
953 : }
954 :
955 1 : HCCP_ATTRI_VISI_DEF int RaCtxUpdateCi(void *qpHandle, uint16_t ci)
956 : {
957 1 : struct RaCtxQpHandle *qpHandleTmp = NULL;
958 : int ret;
959 :
960 1 : CHK_PRT_RETURN(qpHandle == NULL, hccp_err("[update][ra_qp]qp_handle is NULL"),
961 : ConverReturnCode(RDMA_OP, -EINVAL));
962 :
963 1 : qpHandleTmp = (struct RaCtxQpHandle *)qpHandle;
964 1 : CHK_PRT_RETURN(qpHandleTmp->ctxHandle == NULL || qpHandleTmp->ctxHandle->ctxOps == NULL ||
965 : qpHandleTmp->ctxHandle->ctxOps->raCtxUpdateCi == NULL, hccp_err("[update][ra_qp]ctx_handle or ctx_ops "
966 : "or ra_ctx_update_ci is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
967 :
968 1 : ret = qpHandleTmp->ctxHandle->ctxOps->raCtxUpdateCi(qpHandleTmp, ci);
969 1 : return ConverReturnCode(RDMA_OP, ret);
970 : }
971 :
972 5 : HCCP_ATTRI_VISI_DEF int RaCtxGetAuxInfo(void *ctxHandle, struct HccpAuxInfoIn *in, struct HccpAuxInfoOut *out)
973 : {
974 5 : struct RaCtxHandle *ctxHandleTmp = NULL;
975 5 : int ret = 0;
976 :
977 5 : CHK_PRT_RETURN(ctxHandle == NULL || in == NULL || out == NULL,
978 : hccp_err("[get][aux_info]ctx_handle or in or out is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
979 :
980 4 : CHK_PRT_RETURN(in->type < AUX_INFO_IN_TYPE_CQE || in->type >= AUX_INFO_IN_TYPE_MAX,
981 : hccp_err("[get][aux_info]in->type(%d) must greater or equal to %d and less than %d", in->type,
982 : AUX_INFO_IN_TYPE_CQE, AUX_INFO_IN_TYPE_MAX), ConverReturnCode(RDMA_OP, -EINVAL));
983 :
984 3 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
985 3 : CHK_PRT_RETURN(ctxHandleTmp->ctxOps == NULL || ctxHandleTmp->ctxOps->raCtxGetAuxInfo == NULL,
986 : hccp_err("[get][aux_info]ctx_ops or ra_ctx_get_aux_info is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
987 :
988 2 : ret = ctxHandleTmp->ctxOps->raCtxGetAuxInfo(ctxHandle, in, out);
989 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[get][aux_info]ra_ctx_get_aux_info failed, ret(%d) phyId(%u) devIndex(0x%x)",
990 : ret, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex), ConverReturnCode(RDMA_OP, ret));
991 :
992 1 : return ConverReturnCode(RDMA_OP, ret);
993 : }
994 :
995 7 : HCCP_ATTRI_VISI_DEF int RaCtxGetCrErrInfoList(void *ctxHandle, struct CrErrInfo *infoList,
996 : unsigned int *num)
997 : {
998 7 : struct RaCtxHandle *ctxHandleTmp = NULL;
999 : int ret;
1000 :
1001 7 : CHK_PRT_RETURN(ctxHandle == NULL || infoList == NULL || num == NULL,
1002 : hccp_err("[get][cr_err_info_list]ctx_handle or info_list or num is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
1003 :
1004 4 : CHK_PRT_RETURN(*num == 0 || *num > CR_ERR_INFO_MAX_NUM, hccp_err("[get][cr_err_info_list]num:%u must greater "
1005 : "than 0 and less or equal to %d", *num, CR_ERR_INFO_MAX_NUM), ConverReturnCode(RDMA_OP, -EINVAL));
1006 :
1007 2 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
1008 :
1009 2 : hccp_run_info("Input parameters: phy_id(%u), devIndex(0x%x) num(%u)",
1010 : ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex, *num);
1011 :
1012 2 : ret = RaHdcCtxGetCrErrInfoList(ctxHandleTmp, infoList, num);
1013 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[get][cr_err_info_list]ra_hdc_ctx_get_cr_err_info_list failed, ret:%d "
1014 : "phyId:%u devIndex:0x%x", ret, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex),
1015 : ConverReturnCode(RDMA_OP, ret));
1016 :
1017 1 : return ConverReturnCode(RDMA_OP, ret);
1018 : }
1019 :
1020 8 : HCCP_ATTRI_VISI_DEF int RaCtxGetJettyContext(void *qpHandle, uint8_t context[], unsigned int *len)
1021 : {
1022 8 : struct RaCtxQpHandle *qpHandleTmp = NULL;
1023 8 : int ret = 0;
1024 :
1025 8 : CHK_PRT_RETURN(qpHandle == NULL || context == NULL || len == NULL,
1026 : hccp_err("[get][jettyContext]qpHandle or context or len is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
1027 :
1028 5 : CHK_PRT_RETURN(*len < CONTEXT_MAX_LEN, hccp_err("[get][jettyContext]len:%u less than %d", *len,
1029 : CONTEXT_MAX_LEN), ConverReturnCode(RDMA_OP, -EINVAL));
1030 :
1031 4 : qpHandleTmp = (struct RaCtxQpHandle *)qpHandle;
1032 4 : CHK_PRT_RETURN(qpHandleTmp->ctxHandle == NULL || qpHandleTmp->ctxHandle->ctxOps == NULL ||
1033 : qpHandleTmp->ctxHandle->ctxOps->raCtxGetJettyContext == NULL, hccp_err("[get][jettyContext]ctxHandle or"
1034 : " ctxOps or raCtxGetJettyContext is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
1035 :
1036 2 : hccp_run_info("Input parameters: phyId:%u, devIndex:0x%x jettyId:%u len:%u",
1037 : qpHandleTmp->phyId, qpHandleTmp->devIndex, qpHandleTmp->qpInfo.ub.id, *len);
1038 :
1039 2 : ret = qpHandleTmp->ctxHandle->ctxOps->raCtxGetJettyContext(qpHandleTmp, context, len);
1040 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[get][jettyContext]raCtxGetJettyContext failed, ret:%d phyId:%u devIndex"
1041 : ":0x%x", ret, qpHandleTmp->phyId, qpHandleTmp->devIndex), ConverReturnCode(RDMA_OP, ret));
1042 :
1043 1 : return ConverReturnCode(RDMA_OP, ret);
1044 : }
|