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