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 : #define _GNU_SOURCE
12 : #include <stdlib.h>
13 : #include <errno.h>
14 : #include <sys/prctl.h>
15 : #include "securec.h"
16 : #include "user_log.h"
17 : #include "dl_hal_function.h"
18 : #include "ra_comm.h"
19 : #include "ra_hdc.h"
20 : #include "ra_hdc_async.h"
21 : #include "ra_hdc_lite.h"
22 : #include "ra_hdc_rdma_notify.h"
23 : #include "ra_hdc_rdma.h"
24 : #include "ra_hdc_socket.h"
25 : #include "ra_hdc_ping.h"
26 : #include "ra_rs_comm.h"
27 : #include "ra_hdc_tlv.h"
28 : #include "ra_rs_err.h"
29 : #include "rs.h"
30 : #include "rs_ping.h"
31 : #include "ra_adp_tlv.h"
32 : #include "ra_adp_ping.h"
33 : #include "ra_adp_socket.h"
34 : #include "ra_hdc_ctx.h"
35 : #include "ra_hdc_async_ctx.h"
36 : #include "ra_adp_ctx.h"
37 : #include "ra_adp_async.h"
38 : #include "ra_adp_verbs.h"
39 : #include "ra_adp.h"
40 :
41 : struct RaHdcServer gHdcServer[RA_MAX_PHY_ID_NUM] = {0};
42 : struct RaHdcInitPara gHdcInitPara = {0};
43 : struct RsPthreadInfo gRaThreadInfo = {0};
44 :
45 : struct RsOps {
46 : int (*rdevInit)(struct rdev rdevInfo, unsigned int notifyType, unsigned int *rdevIndex);
47 : int (*rdevInitWithBackup)(struct rdev rdevInfo, struct rdev backupRdevInfo, unsigned int notifyType,
48 : unsigned int *rdevIndex);
49 : int (*rdevGetPortStatus)(unsigned int phyId, unsigned int rdevIndex, enum PortStatus *status);
50 : int (*rdevDeinit)(unsigned int phyId, unsigned int notifyType, unsigned int rdevIndex);
51 : int (*qpCreate)(unsigned int phyId, unsigned int rdevIndex, struct RsQpNorm qpNorm, struct RsQpResp *qpResp);
52 : int (*qpCreateWithAttrs)(unsigned int phyId, unsigned int rdevIndex, struct RsQpNormWithAttrs *qpNorm,
53 : struct RsQpRespWithAttrs *qpResp);
54 : int (*qpDestroy)(unsigned int phyId, unsigned int rdevIndex, unsigned int qpn);
55 : int (*typicalQpModify)(unsigned int phyId, unsigned int rdevIndex, struct TypicalQp localQpInfo,
56 : struct TypicalQp remoteQpInfo, struct TypicalQpAttr *qpAttr);
57 : int (*qpBatchModify)(unsigned int phyId, unsigned int rdevIndex, int status, int qpn[], int qpnNum);
58 : int (*qpConnectAsync)(unsigned int phyId, unsigned int rdevIndex, unsigned int qpn, int fd);
59 : int (*getQpStatus)(unsigned int phyId, unsigned int rdevIndex, unsigned int qpn, struct RsQpStatusInfo *qpInfo);
60 : int (*mrReg)(unsigned int phyId, unsigned int rdevIndex, unsigned int qpn, struct RdmaMrRegInfo *mrRegInfo);
61 : int (*mrDereg)(unsigned int phyId, unsigned int rdevIndex, unsigned int qpn, char *addr);
62 : int (*registerMr)(unsigned int phyId, unsigned int rdevIndex, struct RdmaMrRegInfo *mrRegInfo, void **mrHandle);
63 : int (*typicalRegisterMr)(unsigned int phyId, unsigned int rdevIndex, struct RdmaMrRegInfo *mrRegInfo,
64 : void **mrHandle);
65 : int (*remapMr)(unsigned int phyId, unsigned int rdevIndex, struct MemRemapInfo memList[], unsigned int memNum);
66 : int (*typicalDeregisterMr)(unsigned int phyId, unsigned int devIndex, unsigned long long addr);
67 : int (*sendWr)(unsigned int phyId, unsigned int rdevIndex, unsigned int qpn, struct SendWr *wr,
68 : struct SendWrRsp *wrRsp);
69 : int (*sendWrList)(struct RsWrlistBaseInfo baseInfo, struct WrInfo *wrList, unsigned int sendNum,
70 : struct SendWrRsp *wrRsp, unsigned int *completeNum);
71 : int (*getNotifyMrInfo)(unsigned int phyId, unsigned int rdevIndex, struct MrInfoT *info);
72 : int (*notifyCfgSet)(unsigned int phyId, unsigned long long va, unsigned long long size);
73 : int (*notifyCfgGet)(unsigned int phyId, unsigned long long *va, unsigned long long *size);
74 : int (*setHostPid)(unsigned int phyId, pid_t hostPid, const char *pidSign);
75 : int (*getInterfaceVersion)(unsigned int opcode, unsigned int *version);
76 : int (*setTsqpDepth)(unsigned int phyId, unsigned int rdevIndex, unsigned int tempDepth, unsigned int *qpNum);
77 : int (*getTsqpDepth)(unsigned int phyId, unsigned int rdevIndex, unsigned int *tempDepth, unsigned int *qpNum);
78 : int (*setQpAttrQos)(unsigned int phyId, unsigned int rdevIndex, unsigned int qpn, struct QosAttr *attr);
79 : int (*setQpAttrTimeout)(unsigned int phyId, unsigned int rdevIndex, unsigned int qpn, unsigned int *timeout);
80 : int (*setQpAttrRetryCnt)(unsigned int phyId, unsigned int rdevIndex, unsigned int qpn, unsigned int *retryCnt);
81 : int (*getCqeErrInfo)(struct CqeErrInfo *info);
82 : int (*getLiteSupport)(unsigned int phyId, unsigned int rdevIndex, int *supportLite);
83 : int (*getLiteRdevCap)(unsigned int phyId, unsigned int rdevIndex, struct LiteRdevCapResp *resp);
84 : int (*getLiteQpCqAttr)(unsigned int phyId, unsigned int rdevIndex, unsigned int qpn, struct LiteQpCqAttrResp *resp);
85 : int (*getLiteMemAttr)(unsigned int phyId, unsigned int rdevIndex, unsigned int qpn, struct LiteMemAttrResp *resp);
86 : int (*getLiteConnectedInfo)(unsigned int phyId, unsigned int rdevIndex, unsigned int qpn,
87 : struct LiteConnectedInfoResp *resp);
88 : int (*getCqeErrInfoNum)(unsigned int phyId, unsigned int rdevIdx, unsigned int *num);
89 : int (*getCqeErrInfoList)(unsigned int phyId, unsigned int rdevIdx, struct CqeErrInfo *info, unsigned int *num);
90 : int (*getTlsEnable)(unsigned int phyId, bool *tlsEnable);
91 : int (*getSecRandom)(int *value);
92 : int (*getHccnCfg)(struct RaInfo *info, enum HccnCfgKey key, char *value, unsigned int *valueLen);
93 : };
94 :
95 : struct RsOps gRaRsOps = {
96 : .rdevInit = RsRdevInit,
97 : .rdevInitWithBackup = RsRdevInitWithBackup,
98 : .rdevGetPortStatus = RsRdevGetPortStatus,
99 : .rdevDeinit = RsRdevDeinit,
100 : .qpCreate = RsQpCreate,
101 : .qpCreateWithAttrs = RsQpCreateWithAttrs,
102 : .qpDestroy = RsQpDestroy,
103 : .typicalQpModify = RsTypicalQpModify,
104 : .qpBatchModify = RsQpBatchModify,
105 : .qpConnectAsync = RsQpConnectAsync,
106 : .getQpStatus = RsGetQpStatus,
107 : .mrReg = RsMrReg,
108 : .mrDereg = RsMrDereg,
109 : .registerMr = RsTypicalRegisterMrV1,
110 : .typicalRegisterMr = RsTypicalRegisterMr,
111 : .remapMr = RsRemapMr,
112 : .typicalDeregisterMr = RsTypicalDeregisterMr,
113 : .sendWr = RsSendWr,
114 : .sendWrList = RsSendWrlist,
115 : .getNotifyMrInfo = RsGetNotifyMrInfo,
116 : .notifyCfgSet = RsNotifyCfgSet,
117 : .notifyCfgGet = RsNotifyCfgGet,
118 : .setHostPid = RsSetHostPid,
119 : .getInterfaceVersion = RsGetInterfaceVersion,
120 : .setTsqpDepth = RsSetTsqpDepth,
121 : .getTsqpDepth = RsGetTsqpDepth,
122 : .setQpAttrQos = RsSetQpAttrQos,
123 : .setQpAttrTimeout = RsSetQpAttrTimeout,
124 : .setQpAttrRetryCnt = RsSetQpAttrRetryCnt,
125 : .getCqeErrInfo = RsGetCqeErrInfo,
126 : .getLiteRdevCap = RsGetLiteRdevCap,
127 : .getLiteQpCqAttr = RsGetLiteQpCqAttr,
128 : .getLiteConnectedInfo = RsGetLiteConnectedInfo,
129 : .getLiteMemAttr = RsGetLiteMemAttr,
130 : .getLiteSupport = RsGetLiteSupport,
131 : .getCqeErrInfoNum = RsGetCqeErrInfoNum,
132 : .getCqeErrInfoList = RsGetCqeErrInfoList,
133 : .getTlsEnable = RsGetTlsEnable,
134 : .getSecRandom = RsDrvGetRandomNum,
135 : .getHccnCfg = RsGetHccnCfg,
136 : };
137 :
138 : struct HdcOps gRaHdcOps = {
139 : .getCapacity = DlDrvHdcGetCapacity,
140 : .clientCreate = DlDrvHdcClientCreate,
141 : .clientDestroy = DlDrvHdcClientDestroy,
142 : .sessionConnect = DlDrvHdcSessionConnect,
143 : .sessionConnectEx = DlHalHdcSessionConnectEx,
144 : .serverCreate = DlDrvHdcServerCreate,
145 : .serverDestroy = DlDrvHdcServerDestroy,
146 : .sessionAccept = DlDrvHdcSessionAccept,
147 : .sessionClose = DlDrvHdcSessionClose,
148 : .freeMsg = DlDrvHdcFreeMsg,
149 : .reuseMsg = DlDrvHdcReuseMsg,
150 : .addMsgBuffer = DlDrvHdcAddMsgBuffer,
151 : .getMsgBuffer = DlDrvHdcGetMsgBuffer,
152 : .recv = DlHalHdcRecv,
153 : .send = DlHalHdcSend,
154 : .allocMsg = DlDrvHdcAllocMsg,
155 : .setSessionReference = DlDrvHdcSetSessionReference,
156 : };
157 :
158 : #define RA_HDC_OPS gRaHdcOps
159 :
160 241 : STATIC void MsgHeadBuildUpHw(char *pSendRcvBuf, struct MsgHead *recvMsgHead, int ret, unsigned int msgDataLen)
161 : {
162 241 : struct MsgHead *pSendRcvHead = NULL;
163 :
164 241 : pSendRcvHead = (struct MsgHead *)pSendRcvBuf;
165 241 : pSendRcvHead->opcode = recvMsgHead->opcode;
166 241 : pSendRcvHead->asyncReqId = recvMsgHead->asyncReqId;
167 241 : pSendRcvHead->ret = ret;
168 241 : pSendRcvHead->msgDataLen = msgDataLen;
169 :
170 241 : return;
171 : }
172 :
173 0 : STATIC int OpMsgErr(char **outBuf, struct MsgHead *recvMsgHead, int *outBufLen, int opRight)
174 : {
175 0 : unsigned int opcode = recvMsgHead->opcode;
176 0 : char *outBufTmp = NULL;
177 0 : int msgRet = 0;
178 :
179 0 : outBufTmp = (char *)calloc(sizeof(struct MsgHead), sizeof(char));
180 0 : CHK_PRT_RETURN(outBufTmp == NULL, hccp_err("send_buf calloc failed."), -ENOMEM);
181 :
182 0 : if (opRight == HAVE_OP_RIGHT) {
183 0 : if (opcode >= RA_RS_OP_MAX_NUM || ((opcode < RA_RS_HDC_SESSION_CLOSE) && (opcode >= RA_RS_EXTER_OP_MAX_NUM))) {
184 0 : msgRet = -EPROTONOSUPPORT;
185 : } else {
186 0 : msgRet = -EPIPE;
187 : }
188 0 : } else if (opRight == TGID_INVALID) {
189 0 : msgRet = -EPERM;
190 : } else {
191 0 : msgRet = -EACCES;
192 : }
193 :
194 0 : MsgHeadBuildUpHw(outBufTmp, recvMsgHead, msgRet, 0);
195 :
196 0 : *outBuf = outBufTmp;
197 0 : *outBufLen = sizeof(struct MsgHead);
198 :
199 0 : return 0;
200 : }
201 :
202 2 : STATIC int RaRsRdevInit(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
203 : {
204 : (void)outLen;
205 2 : unsigned int rdevIndex = 0;
206 2 : union OpRdevInitData *rdevInitData = (union OpRdevInitData *)(inBuf + sizeof(struct MsgHead));
207 :
208 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpRdevInitData), sizeof(struct MsgHead), rcvBufLen, opResult);
209 :
210 2 : *opResult = gRaRsOps.rdevInit(rdevInitData->txData.rdevInfo, NOTIFY, &rdevIndex);
211 2 : if (*opResult != 0) {
212 1 : hccp_err("rdev_init failed ret[%d].", *opResult);
213 1 : return 0;
214 : }
215 :
216 1 : rdevInitData = (union OpRdevInitData *)(outBuf + sizeof(struct MsgHead));
217 1 : rdevInitData->rxData.rdevIndex = rdevIndex;
218 :
219 1 : return 0;
220 : }
221 :
222 2 : STATIC int RaRsRdevInitWithBackup(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
223 : {
224 : (void)outLen;
225 2 : union OpRdevInitWithBackupData *rdevInitData = (union OpRdevInitWithBackupData *)(inBuf + sizeof(struct MsgHead));
226 2 : unsigned int rdevIndex = 0;
227 :
228 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpRdevInitWithBackupData), sizeof(struct MsgHead), rcvBufLen, opResult);
229 :
230 2 : *opResult = gRaRsOps.rdevInitWithBackup(rdevInitData->txData.rdevInfo, rdevInitData->txData.backupRdevInfo, NOTIFY,
231 : &rdevIndex);
232 2 : if (*opResult != 0) {
233 1 : hccp_err("rdev_init_with_backup failed ret[%d].", *opResult);
234 1 : return 0;
235 : }
236 :
237 1 : rdevInitData = (union OpRdevInitWithBackupData *)(outBuf + sizeof(struct MsgHead));
238 1 : rdevInitData->rxData.rdevIndex = rdevIndex;
239 :
240 1 : return 0;
241 : }
242 :
243 2 : STATIC int RaRsRdevGetPortStatus(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
244 : {
245 : (void)outLen;
246 2 : union OpRdevGetPortStatusData *statusData = NULL;
247 2 : enum PortStatus status = PORT_STATUS_DOWN;
248 :
249 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpRdevGetPortStatusData), sizeof(struct MsgHead), rcvBufLen, opResult);
250 :
251 2 : statusData = (union OpRdevGetPortStatusData *)(inBuf + sizeof(struct MsgHead));
252 2 : *opResult = gRaRsOps.rdevGetPortStatus(statusData->txData.phyId, statusData->txData.rdevIndex, &status);
253 2 : if (*opResult != 0) {
254 1 : hccp_err("rdev_get_port_status failed ret[%d].", *opResult);
255 1 : return 0;
256 : }
257 :
258 1 : statusData = (union OpRdevGetPortStatusData *)(outBuf + sizeof(struct MsgHead));
259 1 : statusData->rxData.status = status;
260 :
261 1 : return 0;
262 : }
263 :
264 1 : STATIC int RaRsRdevDeinit(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
265 : {
266 : (void)outBuf;
267 : (void)outLen;
268 1 : union OpRdevDeinitData *rdevDeinitData = (union OpRdevDeinitData *)(inBuf + sizeof(struct MsgHead));
269 :
270 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpRdevDeinitData), sizeof(struct MsgHead), rcvBufLen, opResult);
271 :
272 1 : *opResult = gRaRsOps.rdevDeinit(rdevDeinitData->txData.phyId, NOTIFY, rdevDeinitData->txData.rdevIndex);
273 1 : if (*opResult != 0) {
274 0 : hccp_err("rdev_deinit failed ret[%d].", *opResult);
275 : }
276 :
277 1 : return 0;
278 : }
279 :
280 2 : STATIC int RaRsGetTsqpDepth(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
281 : {
282 : (void)outLen;
283 2 : unsigned int tempDepth = 0;
284 2 : unsigned int qpNum = 0;
285 2 : union OpGetTsqpDepthData *getTsqpDepthData = (union OpGetTsqpDepthData *)(inBuf + sizeof(struct MsgHead));
286 :
287 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpGetTsqpDepthData), sizeof(struct MsgHead), rcvBufLen, opResult);
288 :
289 2 : *opResult = gRaRsOps.getTsqpDepth(getTsqpDepthData->txData.phyId, getTsqpDepthData->txData.rdevIndex, &tempDepth,
290 : &qpNum);
291 2 : if (*opResult != 0) {
292 1 : hccp_err("set_tsqp_depth failed ret[%d].", *opResult);
293 1 : return 0;
294 : }
295 :
296 1 : getTsqpDepthData = (union OpGetTsqpDepthData *)(outBuf + sizeof(struct MsgHead));
297 1 : getTsqpDepthData->rxData.tempDepth = tempDepth;
298 1 : getTsqpDepthData->rxData.qpNum = qpNum;
299 :
300 1 : return 0;
301 : }
302 :
303 2 : STATIC int RaRsSetTsqpDepth(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
304 : {
305 : (void)outLen;
306 2 : unsigned int qpNum = 0;
307 2 : union OpSetTsqpDepthData *setTsqpDepthData = (union OpSetTsqpDepthData *)(inBuf + sizeof(struct MsgHead));
308 :
309 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSetTsqpDepthData), sizeof(struct MsgHead), rcvBufLen, opResult);
310 :
311 2 : *opResult = gRaRsOps.setTsqpDepth(setTsqpDepthData->txData.phyId, setTsqpDepthData->txData.rdevIndex,
312 : setTsqpDepthData->txData.tempDepth, &qpNum);
313 2 : if (*opResult != 0) {
314 1 : hccp_err("set_tsqp_depth failed ret[%d].", *opResult);
315 1 : return 0;
316 : }
317 :
318 1 : setTsqpDepthData = (union OpSetTsqpDepthData *)(outBuf + sizeof(struct MsgHead));
319 1 : setTsqpDepthData->rxData.qpNum = qpNum;
320 :
321 1 : return 0;
322 : }
323 :
324 2 : STATIC int RaRsQpCreate(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
325 : {
326 : (void)outLen;
327 : struct RsQpNorm qpNorm;
328 2 : struct RsQpResp qpResp = {0};
329 2 : union OpQpCreateData *createData = (union OpQpCreateData *)(inBuf + sizeof(struct MsgHead));
330 :
331 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpQpCreateData), sizeof(struct MsgHead), rcvBufLen, opResult);
332 :
333 2 : int qpMode = createData->txData.qpMode;
334 2 : qpNorm.flag = createData->txData.flag;
335 2 : qpNorm.isExp = 1;
336 2 : qpNorm.isExt = 1;
337 2 : if (qpMode == RA_RS_OP_QP_MODE_EXT) {
338 0 : qpNorm.qpMode = RA_RS_OP_QP_MODE;
339 : } else {
340 2 : qpNorm.qpMode = qpMode;
341 : }
342 2 : qpNorm.memAlign = createData->txData.memAlign;
343 :
344 2 : *opResult = gRaRsOps.qpCreate(createData->txData.phyId, createData->txData.rdevIndex, qpNorm, &qpResp);
345 2 : if (*opResult != 0) {
346 1 : hccp_err("qp create failed ret[%d].", *opResult);
347 1 : return 0;
348 : }
349 :
350 1 : createData = (union OpQpCreateData *)(outBuf + sizeof(struct MsgHead));
351 1 : createData->rxData.qpn = qpResp.qpn;
352 1 : createData->rxData.psn = qpResp.psn;
353 1 : createData->rxData.gidIdx = qpResp.gidIdx;
354 :
355 1 : return 0;
356 : }
357 :
358 2 : STATIC int RaRsQpCreateWithAttrs(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
359 : {
360 : (void)outLen;
361 2 : union OpQpCreateWithAttrsData *createData = NULL;
362 2 : struct RsQpNormWithAttrs qpNorm = {0};
363 2 : struct RsQpRespWithAttrs qpResp = {0};
364 :
365 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpQpCreateWithAttrsData), sizeof(struct MsgHead), rcvBufLen, opResult);
366 :
367 2 : createData = (union OpQpCreateWithAttrsData *)(inBuf + sizeof(struct MsgHead));
368 :
369 2 : qpNorm.isExp = 1;
370 2 : qpNorm.isExt = 1;
371 2 : qpNorm.extAttrs = createData->txData.extAttrs;
372 :
373 2 : *opResult = gRaRsOps.qpCreateWithAttrs(createData->txData.phyId, createData->txData.rdevIndex, &qpNorm, &qpResp);
374 2 : if (*opResult != 0) {
375 1 : hccp_err("qp create failed ret[%d].", *opResult);
376 1 : return 0;
377 : }
378 :
379 1 : createData = (union OpQpCreateWithAttrsData *)(outBuf + sizeof(struct MsgHead));
380 1 : createData->rxData.qpn = qpResp.qpn;
381 1 : createData->rxData.psn = qpResp.psn;
382 1 : createData->rxData.gidIdx = qpResp.gidIdx;
383 :
384 1 : return 0;
385 : }
386 :
387 1 : STATIC int RaRsAiQpCreate(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
388 : {
389 : (void)outLen;
390 1 : union OpAiQpCreateData *createData = NULL;
391 1 : struct RsQpNormWithAttrs qpNorm = {0};
392 1 : struct RsQpRespWithAttrs qpResp = {0};
393 :
394 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpAiQpCreateData), sizeof(struct MsgHead), rcvBufLen, opResult);
395 :
396 1 : createData = (union OpAiQpCreateData *)(inBuf + sizeof(struct MsgHead));
397 :
398 1 : qpNorm.isExp = 1;
399 1 : qpNorm.isExt = 1;
400 1 : qpNorm.extAttrs = createData->txData.extAttrs;
401 1 : qpNorm.aiOpSupport = 1;
402 :
403 1 : *opResult = gRaRsOps.qpCreateWithAttrs(createData->txData.phyId, createData->txData.rdevIndex, &qpNorm, &qpResp);
404 1 : if (*opResult != 0) {
405 0 : hccp_err("qp create failed ret[%d].", *opResult);
406 0 : return 0;
407 : }
408 :
409 1 : createData = (union OpAiQpCreateData *)(outBuf + sizeof(struct MsgHead));
410 1 : createData->rxData.qpn = qpResp.qpn;
411 1 : createData->rxData.aiQpAddr = qpResp.aiQpAddr;
412 1 : createData->rxData.sqIndex = qpResp.sqIndex;
413 1 : createData->rxData.dbIndex = qpResp.dbIndex;
414 1 : createData->rxData.psn = qpResp.psn;
415 :
416 1 : return 0;
417 : }
418 :
419 1 : STATIC int RaRsAiQpCreateWithData(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
420 : {
421 : (void)outLen;
422 1 : union OpAiQpCreateWithAttrsData *createData = NULL;
423 1 : struct RsQpNormWithAttrs qpNorm = {0};
424 1 : struct RsQpRespWithAttrs qpResp = {0};
425 :
426 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpAiQpCreateWithAttrsData), sizeof(struct MsgHead), rcvBufLen, opResult);
427 :
428 1 : createData = (union OpAiQpCreateWithAttrsData *)(inBuf + sizeof(struct MsgHead));
429 :
430 1 : qpNorm.isExp = 1;
431 1 : qpNorm.isExt = 1;
432 1 : qpNorm.extAttrs = createData->txData.extAttrs;
433 1 : qpNorm.aiOpSupport = 1;
434 :
435 1 : *opResult = gRaRsOps.qpCreateWithAttrs(createData->txData.phyId, createData->txData.rdevIndex, &qpNorm, &qpResp);
436 1 : if (*opResult != 0) {
437 0 : hccp_err("qp create failed ret[%d].", *opResult);
438 0 : return 0;
439 : }
440 :
441 1 : createData = (union OpAiQpCreateWithAttrsData *)(outBuf + sizeof(struct MsgHead));
442 1 : createData->rxData.qpn = qpResp.qpn;
443 1 : createData->rxData.gidIdx = qpResp.gidIdx;
444 1 : createData->rxData.psn = qpResp.psn;
445 1 : createData->rxData.aiQpAddr = qpResp.aiQpAddr;
446 1 : createData->rxData.sqIndex = qpResp.sqIndex;
447 1 : createData->rxData.dbIndex = qpResp.dbIndex;
448 1 : createData->rxData.aiScqAddr = qpResp.aiScqAddr;
449 1 : createData->rxData.aiRcqAddr = qpResp.aiRcqAddr;
450 1 : (void)memcpy_s(&createData->rxData.dataPlaneInfo, sizeof(struct AiDataPlaneInfo), &qpResp.dataPlaneInfo,
451 : sizeof(struct AiDataPlaneInfo));
452 :
453 1 : return 0;
454 : }
455 :
456 2 : STATIC int RaRsTypicalQpCreate(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
457 : {
458 : (void)outLen;
459 2 : union OpTypicalQpCreateData *createData = (union OpTypicalQpCreateData *)(inBuf + sizeof(struct MsgHead));
460 2 : struct RsQpResp qpResp = {0};
461 : struct RsQpNorm qpNorm;
462 : int qpMode;
463 :
464 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpTypicalQpCreateData), sizeof(struct MsgHead), rcvBufLen, opResult);
465 :
466 2 : qpMode = createData->txData.qpMode;
467 2 : qpNorm.flag = createData->txData.flag;
468 2 : qpNorm.isExp = 1;
469 2 : qpNorm.isExt = 1;
470 2 : if (qpMode == RA_RS_OP_QP_MODE_EXT) {
471 0 : qpNorm.qpMode = RA_RS_OP_QP_MODE;
472 : } else {
473 2 : qpNorm.qpMode = qpMode;
474 : }
475 2 : qpNorm.memAlign = createData->txData.memAlign;
476 :
477 2 : *opResult = gRaRsOps.qpCreate(createData->txData.phyId, createData->txData.rdevIndex, qpNorm, &qpResp);
478 2 : if (*opResult != 0) {
479 1 : hccp_err("qp create failed ret[%d].", *opResult);
480 1 : return 0;
481 : }
482 :
483 1 : createData = (union OpTypicalQpCreateData *)(outBuf + sizeof(struct MsgHead));
484 1 : createData->rxData.qpn = qpResp.qpn;
485 1 : createData->rxData.gidIdx = qpResp.gidIdx;
486 1 : createData->rxData.psn = qpResp.psn;
487 1 : createData->rxData.gid = qpResp.gid;
488 :
489 1 : return 0;
490 : }
491 :
492 1 : STATIC int RaRsQpDestroy(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
493 : {
494 : (void)outBuf;
495 : (void)outLen;
496 1 : union OpQpDestroyData *qpDestroyData = (union OpQpDestroyData *)(inBuf + sizeof(struct MsgHead));
497 :
498 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpQpDestroyData), sizeof(struct MsgHead), rcvBufLen, opResult);
499 :
500 1 : *opResult = gRaRsOps.qpDestroy(qpDestroyData->txData.phyId, qpDestroyData->txData.rdevIndex,
501 : qpDestroyData->txData.qpn);
502 1 : if (*opResult != 0) {
503 0 : hccp_err("qp destroy failed ret[%d].", *opResult);
504 : }
505 :
506 1 : return 0;
507 : }
508 :
509 2 : STATIC int RaRsTypicalQpModify(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
510 : {
511 : (void)outLen;
512 2 : union OpTypicalQpModifyData *qpModifyData = (union OpTypicalQpModifyData *)(inBuf + sizeof(struct MsgHead));
513 2 : struct TypicalQpAttr qpAttr = {0};
514 :
515 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpTypicalQpModifyData), sizeof(struct MsgHead), rcvBufLen, opResult);
516 :
517 2 : *opResult = gRaRsOps.typicalQpModify(qpModifyData->txData.phyId, qpModifyData->txData.rdevIndex,
518 : qpModifyData->txData.localQpInfo, qpModifyData->txData.remoteQpInfo, &qpAttr);
519 2 : if (*opResult != 0) {
520 1 : hccp_err("qp info modify failed ret[%d].", *opResult);
521 1 : return 0;
522 : }
523 :
524 1 : qpModifyData = (union OpTypicalQpModifyData *)(outBuf + sizeof(struct MsgHead));
525 1 : qpModifyData->rxData.udpSport = qpAttr.udpSport;
526 1 : qpModifyData->rxData.pathMtu = qpAttr.pathMtu;
527 :
528 1 : return 0;
529 : }
530 :
531 1 : STATIC int RaRsQpBatchModify(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
532 : {
533 : (void)outBuf;
534 : (void)outLen;
535 1 : union OpQpBatchModifyData *qpBatchModifyData = (union OpQpBatchModifyData *)(inBuf + sizeof(struct MsgHead));
536 :
537 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpQpBatchModifyData), sizeof(struct MsgHead), rcvBufLen, opResult);
538 : HCCP_CHECK_PARAM_LEN_RET_HOST(qpBatchModifyData->txData.qpnNum, 0, RA_MAX_BATCH_QP_MODIFY_NUM, opResult);
539 :
540 2 : *opResult = gRaRsOps.qpBatchModify(qpBatchModifyData->txData.phyId, qpBatchModifyData->txData.rdevIndex,
541 1 : qpBatchModifyData->txData.status, qpBatchModifyData->txData.qpn, qpBatchModifyData->txData.qpnNum);
542 1 : if (*opResult != 0) {
543 1 : hccp_err("qp info modify failed ret[%d].", *opResult);
544 : }
545 :
546 1 : return 0;
547 : }
548 :
549 1 : STATIC int RaRsQpConnectAsync(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
550 : {
551 : (void)outBuf;
552 : (void)outLen;
553 1 : union OpQpConnectData *qpConnectData = (union OpQpConnectData *)(inBuf + sizeof(struct MsgHead));
554 :
555 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpQpConnectData), sizeof(struct MsgHead), rcvBufLen, opResult);
556 :
557 2 : *opResult = gRaRsOps.qpConnectAsync(qpConnectData->txData.phyId, qpConnectData->txData.rdevIndex,
558 1 : qpConnectData->txData.qpn, qpConnectData->txData.fd);
559 1 : if (*opResult != 0) {
560 0 : hccp_err("qp info async failed ret[%d].", *opResult);
561 : }
562 :
563 1 : return 0;
564 : }
565 :
566 2 : STATIC int RaRsGetQpStatus(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
567 : {
568 : (void)outLen;
569 2 : union OpQpStatusData *qpStatusData = (union OpQpStatusData *)(inBuf + sizeof(struct MsgHead));
570 2 : struct RsQpStatusInfo qpInfo = {0};
571 :
572 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpQpStatusData), sizeof(struct MsgHead), rcvBufLen, opResult);
573 :
574 2 : *opResult = gRaRsOps.getQpStatus(qpStatusData->txData.phyId, qpStatusData->txData.rdevIndex,
575 : qpStatusData->txData.qpn, &qpInfo);
576 2 : if (*opResult != 0) {
577 1 : hccp_err("query qp status async failed ret[%d].", *opResult);
578 1 : return 0;
579 : }
580 :
581 1 : qpStatusData = (union OpQpStatusData *)(outBuf + sizeof(struct MsgHead));
582 1 : qpStatusData->rxData.status = qpInfo.status;
583 :
584 1 : return 0;
585 : }
586 :
587 2 : STATIC int RaRsGetQpInfo(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
588 : {
589 : (void)outLen;
590 2 : union OpQpInfoData *qpInfoData = (union OpQpInfoData *)(inBuf + sizeof(struct MsgHead));
591 2 : struct RsQpStatusInfo qpInfo = {0};
592 :
593 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpQpInfoData), sizeof(struct MsgHead), rcvBufLen, opResult);
594 :
595 2 : *opResult = gRaRsOps.getQpStatus(qpInfoData->txData.phyId, qpInfoData->txData.rdevIndex, qpInfoData->txData.qpn,
596 : &qpInfo);
597 2 : if (*opResult != 0) {
598 1 : hccp_err("query qp status async failed ret[%d].", *opResult);
599 1 : return 0;
600 : }
601 :
602 1 : qpInfoData = (union OpQpInfoData *)(outBuf + sizeof(struct MsgHead));
603 1 : qpInfoData->rxData.status = qpInfo.status;
604 1 : qpInfoData->rxData.udpSport = qpInfo.udpSport;
605 :
606 1 : return 0;
607 : }
608 :
609 1 : STATIC int RaRsMrReg(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
610 : {
611 : (void)outLen;
612 1 : union OpMrRegData *regMrData = (union OpMrRegData *)(inBuf + sizeof(struct MsgHead));
613 1 : struct RdmaMrRegInfo mrRegInfo = {0};
614 :
615 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpMrRegData), sizeof(struct MsgHead), rcvBufLen, opResult);
616 :
617 1 : mrRegInfo.addr = regMrData->txData.mrRegAttr.addr;
618 1 : mrRegInfo.len = regMrData->txData.mrRegAttr.len;
619 1 : mrRegInfo.access = regMrData->txData.mrRegAttr.access;
620 1 : *opResult = gRaRsOps.mrReg(regMrData->txData.phyId, regMrData->txData.rdevIndex, regMrData->txData.qpn, &mrRegInfo);
621 1 : if (*opResult != 0) {
622 0 : hccp_err("reg_mr failed ret[%d].", *opResult);
623 0 : return 0;
624 : }
625 :
626 1 : regMrData = (union OpMrRegData *)(outBuf + sizeof(struct MsgHead));
627 1 : regMrData->rxData.lkey = mrRegInfo.lkey;
628 1 : regMrData->rxData.rkey = mrRegInfo.rkey;
629 :
630 1 : return 0;
631 : }
632 :
633 1 : STATIC int RaRsMrDereg(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
634 : {
635 : (void)outBuf;
636 : (void)outLen;
637 1 : union OpMrDeregData *mrDeregData = (union OpMrDeregData *)(inBuf + sizeof(struct MsgHead));
638 :
639 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpMrDeregData), sizeof(struct MsgHead), rcvBufLen, opResult);
640 :
641 1 : *opResult = gRaRsOps.mrDereg(mrDeregData->txData.phyId, mrDeregData->txData.rdevIndex, mrDeregData->txData.qpn,
642 : mrDeregData->txData.addr);
643 1 : if (*opResult != 0) {
644 0 : hccp_err("dereg_mr failed ret[%d].", *opResult);
645 : }
646 :
647 1 : return 0;
648 : }
649 :
650 2 : STATIC int RaRsTypicalMrRegV1(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
651 : {
652 : (void)outLen;
653 2 : union OpTypicalMrRegData *regMrData = (union OpTypicalMrRegData *)(inBuf + sizeof(struct MsgHead));
654 2 : struct RdmaMrRegInfo mrRegInfo = {0};
655 2 : struct ibv_mr *raRsMrHandle = NULL;
656 :
657 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpTypicalMrRegData), sizeof(struct MsgHead), rcvBufLen, opResult);
658 :
659 2 : mrRegInfo.addr = regMrData->txData.mrRegAttr.addr;
660 2 : mrRegInfo.len = regMrData->txData.mrRegAttr.len;
661 2 : mrRegInfo.access = regMrData->txData.mrRegAttr.access;
662 2 : *opResult = gRaRsOps.registerMr(regMrData->txData.phyId, regMrData->txData.rdevIndex, &mrRegInfo,
663 : (void **)&raRsMrHandle);
664 2 : if (*opResult != 0) {
665 0 : hccp_err("reg_mr failed ret[%d].", *opResult);
666 0 : return 0;
667 : }
668 :
669 2 : regMrData = (union OpTypicalMrRegData *)(outBuf + sizeof(struct MsgHead));
670 2 : regMrData->rxData.lkey = mrRegInfo.lkey;
671 2 : regMrData->rxData.rkey = mrRegInfo.rkey;
672 :
673 2 : return 0;
674 : }
675 :
676 2 : STATIC int RaRsTypicalMrReg(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
677 : {
678 : (void)outLen;
679 2 : union OpTypicalMrRegData *regMrData = (union OpTypicalMrRegData *)(inBuf + sizeof(struct MsgHead));
680 2 : struct RdmaMrRegInfo mrRegInfo = {0};
681 2 : struct ibv_mr *raRsMrHandle = NULL;
682 :
683 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpTypicalMrRegData), sizeof(struct MsgHead), rcvBufLen, opResult);
684 :
685 2 : mrRegInfo.addr = regMrData->txData.mrRegAttr.addr;
686 2 : mrRegInfo.len = regMrData->txData.mrRegAttr.len;
687 2 : mrRegInfo.access = regMrData->txData.mrRegAttr.access;
688 2 : *opResult = gRaRsOps.typicalRegisterMr(regMrData->txData.phyId, regMrData->txData.rdevIndex, &mrRegInfo,
689 : (void **)&raRsMrHandle);
690 2 : if (*opResult != 0) {
691 0 : hccp_err("reg_mr failed ret[%d].", *opResult);
692 0 : return 0;
693 : }
694 :
695 2 : regMrData = (union OpTypicalMrRegData *)(outBuf + sizeof(struct MsgHead));
696 2 : regMrData->rxData.lkey = mrRegInfo.lkey;
697 2 : regMrData->rxData.rkey = mrRegInfo.rkey;
698 2 : regMrData->rxData.addr = (uint64_t)(uintptr_t)raRsMrHandle;
699 :
700 2 : return 0;
701 : }
702 :
703 2 : STATIC int RaRsRemapMr(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
704 : {
705 : (void)outBuf;
706 : (void)outLen;
707 2 : union OpRemapMrData *opData = (union OpRemapMrData *)(inBuf + sizeof(struct MsgHead));
708 :
709 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpRemapMrData), sizeof(struct MsgHead), rcvBufLen, opResult);
710 : HCCP_CHECK_PARAM_LEN_RET_HOST(opData->txData.memNum, 0, REMAP_MR_MAX_NUM, opResult);
711 :
712 2 : *opResult = gRaRsOps.remapMr(opData->txData.phyId, opData->txData.rdevIndex, opData->txData.memList,
713 : opData->txData.memNum);
714 2 : if (*opResult) {
715 1 : hccp_err("remap_mr failed ret[%d]", *opResult);
716 : }
717 2 : return 0;
718 : }
719 :
720 3 : STATIC int RaRsTypicalMrDereg(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
721 : {
722 : (void)outBuf;
723 : (void)outLen;
724 3 : union OpTypicalMrDeregData *mrDeregData = (union OpTypicalMrDeregData *)(inBuf + sizeof(struct MsgHead));
725 :
726 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpTypicalMrDeregData), sizeof(struct MsgHead), rcvBufLen, opResult);
727 :
728 6 : *opResult = gRaRsOps.typicalDeregisterMr(mrDeregData->txData.phyId, mrDeregData->txData.rdevIndex,
729 3 : mrDeregData->txData.addr);
730 3 : if (*opResult != 0) {
731 0 : hccp_err("dereg_mr failed ret[%d].", *opResult);
732 : }
733 :
734 3 : return 0;
735 : }
736 :
737 1 : STATIC int RaRsSendWr(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
738 : {
739 : (void)outLen;
740 : int ret;
741 :
742 1 : struct SendWrRsp wrRsp = {0};
743 1 : union OpSendWrData *sendWrData = (union OpSendWrData *)(inBuf + sizeof(struct MsgHead));
744 1 : struct SendWr sWr = {0};
745 :
746 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSendWrData), sizeof(struct MsgHead), rcvBufLen, opResult);
747 :
748 1 : sWr.bufNum = sendWrData->txData.bufNum;
749 1 : sWr.bufList = (struct SgList *)&sendWrData->txData.memList[0];
750 1 : sWr.dstAddr = sendWrData->txData.dstAddr;
751 1 : sWr.op = sendWrData->txData.op;
752 1 : sWr.sendFlag = sendWrData->txData.sendFlags;
753 :
754 1 : ret = gRaRsOps.sendWr(sendWrData->txData.phyId, sendWrData->txData.rdevIndex, sendWrData->txData.qpn, &sWr, &wrRsp);
755 1 : *opResult = ret;
756 1 : if (ret) {
757 0 : if (ret == -ENOENT) {
758 0 : hccp_warn("not found remote mr_info, need try again");
759 : } else {
760 0 : hccp_err("send wr failed ret[%d].", ret);
761 : }
762 : }
763 :
764 1 : sendWrData = (union OpSendWrData *)(outBuf + sizeof(struct MsgHead));
765 1 : sendWrData->rxData.wrRsp = wrRsp;
766 :
767 1 : return 0;
768 : }
769 :
770 4 : STATIC int RaRsSendWrList(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
771 : {
772 : (void)outLen;
773 : int ret;
774 : uint32_t i;
775 4 : unsigned int completeNum = 0;
776 4 : struct SendWrRsp *wrRsp = NULL;
777 4 : struct WrInfo *wrList = NULL;
778 4 : struct RsWrlistBaseInfo baseInfo = {0};
779 4 : union OpSendWrlistData *sendWrlist = (union OpSendWrlistData *)(inBuf + sizeof(struct MsgHead));
780 :
781 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSendWrlistData), sizeof(struct MsgHead), rcvBufLen, opResult);
782 : HCCP_CHECK_PARAM_LEN_RET_HOST(sendWrlist->txData.sendNum, 0, MAX_WR_NUM, opResult);
783 :
784 4 : wrRsp = calloc(sendWrlist->txData.sendNum, sizeof(struct SendWrRsp));
785 4 : CHK_PRT_RETURN(wrRsp == NULL, hccp_err("wr_rsp calloc failed."), -ENOMEM);
786 :
787 4 : wrList = calloc(sendWrlist->txData.sendNum, sizeof(struct WrInfo));
788 4 : if (wrList == NULL) {
789 0 : hccp_err("wr_list calloc failed.");
790 0 : ret = -ENOMEM;
791 0 : goto alloc_wr_list_fail;
792 : }
793 :
794 4 : baseInfo.phyId = sendWrlist->txData.phyId;
795 4 : baseInfo.rdevIndex = sendWrlist->txData.rdevIndex;
796 4 : baseInfo.qpn = sendWrlist->txData.qpn;
797 4 : baseInfo.keyFlag = 0;
798 :
799 4 : for (i = 0; i < sendWrlist->txData.sendNum; i++) {
800 0 : wrList[i].op = sendWrlist->txData.wrlist[i].op;
801 0 : wrList[i].sendFlags = sendWrlist->txData.wrlist[i].sendFlags;
802 0 : wrList[i].dstAddr = sendWrlist->txData.wrlist[i].dstAddr;
803 0 : wrList[i].memList.addr = sendWrlist->txData.wrlist[i].memList.addr;
804 0 : wrList[i].memList.len = sendWrlist->txData.wrlist[i].memList.len;
805 0 : wrList[i].memList.lkey = sendWrlist->txData.wrlist[i].memList.lkey;
806 : }
807 4 : ret = gRaRsOps.sendWrList(baseInfo, wrList, sendWrlist->txData.sendNum, wrRsp, &completeNum);
808 4 : *opResult = ret;
809 4 : if (ret) {
810 2 : if (ret == -ENOENT) {
811 1 : hccp_warn("not found remote mr_info, need try again");
812 : } else {
813 1 : hccp_err("send wr failed ret[%d].", ret);
814 : }
815 : }
816 4 : sendWrlist = (union OpSendWrlistData *)(outBuf + sizeof(struct MsgHead));
817 4 : sendWrlist->rxData.completeNum = completeNum;
818 4 : ret = memcpy_s(sendWrlist->rxData.wrRsp, sizeof(struct SendWrRsp) * MAX_WR_NUM_V1, wrRsp,
819 : completeNum * sizeof(struct SendWrRsp));
820 4 : if (ret) {
821 1 : hccp_err("ra_rs_send_wr_list memcpy_s failed, ret[%d]. ", ret);
822 1 : ret = -ESAFEFUNC;
823 1 : goto copy_wr_rsp_fail;
824 : }
825 :
826 3 : copy_wr_rsp_fail:
827 4 : free(wrList);
828 4 : wrList = NULL;
829 :
830 4 : alloc_wr_list_fail:
831 4 : free(wrRsp);
832 4 : wrRsp = NULL;
833 4 : return 0;
834 : }
835 :
836 1 : STATIC void GetWrListV2(struct WrInfo *wrList, union OpSendWrlistDataV2 *sendWrlist)
837 : {
838 : uint32_t i;
839 1 : for (i = 0; i < sendWrlist->txData.sendNum; i++) {
840 0 : wrList[i].op = sendWrlist->txData.wrlist[i].op;
841 0 : wrList[i].sendFlags = sendWrlist->txData.wrlist[i].sendFlags;
842 0 : wrList[i].dstAddr = sendWrlist->txData.wrlist[i].dstAddr;
843 0 : wrList[i].memList.addr = sendWrlist->txData.wrlist[i].memList.addr;
844 0 : wrList[i].memList.len = sendWrlist->txData.wrlist[i].memList.len;
845 0 : wrList[i].memList.lkey = sendWrlist->txData.wrlist[i].memList.lkey;
846 : }
847 1 : return;
848 : }
849 :
850 1 : STATIC int RaRsSendWrListV2(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
851 : {
852 : (void)outLen;
853 : int ret;
854 1 : unsigned int completeNum = 0;
855 1 : struct WrInfo *wrList = NULL;
856 1 : struct SendWrRsp *wrRsp = NULL;
857 1 : struct RsWrlistBaseInfo baseInfo = {0};
858 1 : union OpSendWrlistDataV2 *sendWrlist = (union OpSendWrlistDataV2 *)(inBuf + sizeof(struct MsgHead));
859 :
860 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSendWrlistDataV2), sizeof(struct MsgHead), rcvBufLen, opResult);
861 : HCCP_CHECK_PARAM_LEN_RET_HOST(sendWrlist->txData.sendNum, 0, MAX_WR_NUM, opResult);
862 :
863 1 : wrRsp = calloc(sendWrlist->txData.sendNum, sizeof(struct SendWrRsp));
864 1 : CHK_PRT_RETURN(wrRsp == NULL, hccp_err("wr_rsp calloc failed."), -ENOMEM);
865 :
866 1 : wrList = calloc(sendWrlist->txData.sendNum, sizeof(struct WrInfo));
867 1 : if (wrList == NULL) {
868 0 : hccp_err("wr_list calloc failed.");
869 0 : ret = -ENOMEM;
870 0 : goto alloc_wr_list_fail;
871 : }
872 :
873 1 : baseInfo.phyId = sendWrlist->txData.phyId;
874 1 : baseInfo.rdevIndex = sendWrlist->txData.rdevIndex;
875 1 : baseInfo.qpn = sendWrlist->txData.qpn;
876 1 : baseInfo.keyFlag = 0;
877 :
878 1 : GetWrListV2(wrList, sendWrlist);
879 1 : ret = gRaRsOps.sendWrList(baseInfo, wrList, sendWrlist->txData.sendNum, wrRsp, &completeNum);
880 1 : *opResult = ret;
881 1 : if (ret) {
882 0 : if (ret == -ENOENT) {
883 0 : hccp_warn("not found remote mr_info, need try again");
884 : } else {
885 0 : hccp_err("send wr failed ret[%d].", ret);
886 : }
887 : }
888 1 : sendWrlist = (union OpSendWrlistDataV2 *)(outBuf + sizeof(struct MsgHead));
889 1 : sendWrlist->rxData.completeNum = completeNum;
890 1 : ret = memcpy_s(sendWrlist->rxData.wrRsp, sizeof(struct SendWrRsp) * MAX_WR_NUM, wrRsp,
891 : completeNum * sizeof(struct SendWrRsp));
892 1 : if (ret) {
893 1 : hccp_err("ra_rs_send_wr_list memcpy_s failed, ret[%d]. ", ret);
894 1 : ret = -ESAFEFUNC;
895 1 : goto copy_wr_rsp_fail;
896 : }
897 :
898 0 : copy_wr_rsp_fail:
899 1 : free(wrList);
900 1 : wrList = NULL;
901 :
902 1 : alloc_wr_list_fail:
903 1 : free(wrRsp);
904 1 : wrRsp = NULL;
905 1 : return 0;
906 : }
907 :
908 1 : STATIC void GetWrList(struct WrInfo *wrList, union OpSendWrlistDataExt *sendWrlist)
909 : {
910 : uint32_t i;
911 1 : for (i = 0; i < sendWrlist->txData.sendNum; i++) {
912 0 : wrList[i].op = sendWrlist->txData.wrlist[i].op;
913 0 : wrList[i].sendFlags = sendWrlist->txData.wrlist[i].sendFlags;
914 0 : wrList[i].immData = sendWrlist->txData.wrlist[i].ext.immData;
915 0 : wrList[i].dstAddr = sendWrlist->txData.wrlist[i].dstAddr;
916 0 : wrList[i].memList.addr = sendWrlist->txData.wrlist[i].memList.addr;
917 0 : wrList[i].memList.len = sendWrlist->txData.wrlist[i].memList.len;
918 0 : wrList[i].memList.lkey = sendWrlist->txData.wrlist[i].memList.lkey;
919 0 : wrList[i].aux.dataType = sendWrlist->txData.wrlist[i].aux.dataType;
920 0 : wrList[i].aux.reduceType = sendWrlist->txData.wrlist[i].aux.reduceType;
921 0 : wrList[i].aux.notifyOffset = sendWrlist->txData.wrlist[i].aux.notifyOffset;
922 : }
923 1 : return;
924 : }
925 :
926 1 : STATIC int RaRsSendWrListExt(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
927 : {
928 : (void)outLen;
929 : int ret;
930 1 : unsigned int completeNum = 0;
931 1 : struct SendWrRsp *wrRsp = NULL;
932 1 : struct WrInfo *wrList = NULL;
933 1 : struct RsWrlistBaseInfo baseInfo = {0};
934 1 : union OpSendWrlistDataExt *sendWrlist = (union OpSendWrlistDataExt *)(inBuf + sizeof(struct MsgHead));
935 :
936 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSendWrlistDataExt), sizeof(struct MsgHead), rcvBufLen, opResult);
937 : HCCP_CHECK_PARAM_LEN_RET_HOST(sendWrlist->txData.sendNum, 0, MAX_WR_NUM, opResult);
938 :
939 1 : wrRsp = calloc(sendWrlist->txData.sendNum, sizeof(struct SendWrRsp));
940 1 : CHK_PRT_RETURN(wrRsp == NULL, hccp_err("wr_rsp calloc failed."), -ENOMEM);
941 :
942 1 : wrList = calloc(sendWrlist->txData.sendNum, sizeof(struct WrInfo));
943 1 : if (wrList == NULL) {
944 0 : hccp_err("wr_list calloc failed.");
945 0 : ret = -ENOMEM;
946 0 : goto alloc_wr_list_fail;
947 : }
948 :
949 1 : baseInfo.phyId = sendWrlist->txData.phyId;
950 1 : baseInfo.rdevIndex = sendWrlist->txData.rdevIndex;
951 1 : baseInfo.qpn = sendWrlist->txData.qpn;
952 1 : baseInfo.keyFlag = 0;
953 1 : GetWrList(wrList, sendWrlist);
954 1 : ret = gRaRsOps.sendWrList(baseInfo, wrList, sendWrlist->txData.sendNum, wrRsp, &completeNum);
955 1 : *opResult = ret;
956 1 : if (ret) {
957 0 : if (ret == -ENOENT) {
958 0 : hccp_warn("not found remote mr_info, need try again");
959 : } else {
960 0 : hccp_err("send wr failed ret[%d].", ret);
961 : }
962 : }
963 1 : sendWrlist = (union OpSendWrlistDataExt *)(outBuf + sizeof(struct MsgHead));
964 1 : sendWrlist->rxData.completeNum = completeNum;
965 1 : ret = memcpy_s(sendWrlist->rxData.wrRsp, sizeof(struct SendWrRsp) * MAX_WR_NUM_V1, wrRsp,
966 : completeNum * sizeof(struct SendWrRsp));
967 1 : if (ret) {
968 1 : hccp_err("ra_rs_send_wr_list_ext memcpy_s failed, ret[%d]. ", ret);
969 1 : ret = -ESAFEFUNC;
970 1 : goto copy_wr_rsp_fail;
971 : }
972 :
973 0 : copy_wr_rsp_fail:
974 1 : free(wrList);
975 1 : wrList = NULL;
976 :
977 1 : alloc_wr_list_fail:
978 1 : free(wrRsp);
979 1 : wrRsp = NULL;
980 1 : return 0;
981 : }
982 :
983 1 : STATIC void GetWrListExtV2(struct WrInfo *wrList, union OpSendWrlistDataExtV2 *sendWrlist)
984 : {
985 : uint32_t i;
986 1 : for (i = 0; i < sendWrlist->txData.sendNum; i++) {
987 0 : wrList[i].op = sendWrlist->txData.wrlist[i].op;
988 0 : wrList[i].sendFlags = sendWrlist->txData.wrlist[i].sendFlags;
989 0 : wrList[i].immData = sendWrlist->txData.wrlist[i].ext.immData;
990 0 : wrList[i].dstAddr = sendWrlist->txData.wrlist[i].dstAddr;
991 0 : wrList[i].memList.addr = sendWrlist->txData.wrlist[i].memList.addr;
992 0 : wrList[i].memList.len = sendWrlist->txData.wrlist[i].memList.len;
993 0 : wrList[i].memList.lkey = sendWrlist->txData.wrlist[i].memList.lkey;
994 0 : wrList[i].aux.dataType = sendWrlist->txData.wrlist[i].aux.dataType;
995 0 : wrList[i].aux.reduceType = sendWrlist->txData.wrlist[i].aux.reduceType;
996 0 : wrList[i].aux.notifyOffset = sendWrlist->txData.wrlist[i].aux.notifyOffset;
997 : }
998 1 : return;
999 : }
1000 :
1001 1 : STATIC int RaRsSendWrListExtV2(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
1002 : {
1003 : (void)outLen;
1004 : int ret;
1005 1 : unsigned int completeNum = 0;
1006 1 : struct WrInfo *wrList = NULL;
1007 1 : struct SendWrRsp *wrRsp = NULL;
1008 1 : struct RsWrlistBaseInfo baseInfo = {0};
1009 1 : union OpSendWrlistDataExtV2 *sendWrlist = (union OpSendWrlistDataExtV2 *)(inBuf + sizeof(struct MsgHead));
1010 :
1011 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSendWrlistDataExtV2), sizeof(struct MsgHead), rcvBufLen, opResult);
1012 : HCCP_CHECK_PARAM_LEN_RET_HOST(sendWrlist->txData.sendNum, 0, MAX_WR_NUM, opResult);
1013 :
1014 1 : wrRsp = calloc(sendWrlist->txData.sendNum, sizeof(struct SendWrRsp));
1015 1 : CHK_PRT_RETURN(wrRsp == NULL, hccp_err("wr_rsp calloc failed."), -ENOMEM);
1016 :
1017 1 : wrList = calloc(sendWrlist->txData.sendNum, sizeof(struct WrInfo));
1018 1 : if (wrList == NULL) {
1019 0 : hccp_err("wr_list calloc failed.");
1020 0 : ret = -ENOMEM;
1021 0 : goto alloc_wr_list_fail;
1022 : }
1023 :
1024 1 : baseInfo.phyId = sendWrlist->txData.phyId;
1025 1 : baseInfo.rdevIndex = sendWrlist->txData.rdevIndex;
1026 1 : baseInfo.qpn = sendWrlist->txData.qpn;
1027 1 : baseInfo.keyFlag = 0;
1028 1 : GetWrListExtV2(wrList, sendWrlist);
1029 1 : ret = gRaRsOps.sendWrList(baseInfo, wrList, sendWrlist->txData.sendNum, wrRsp, &completeNum);
1030 1 : *opResult = ret;
1031 1 : if (ret) {
1032 0 : if (ret == -ENOENT) {
1033 0 : hccp_warn("not found remote mr_info, need try again");
1034 : } else {
1035 0 : hccp_err("send wr failed ret[%d].", ret);
1036 : }
1037 : }
1038 1 : sendWrlist = (union OpSendWrlistDataExtV2 *)(outBuf + sizeof(struct MsgHead));
1039 1 : sendWrlist->rxData.completeNum = completeNum;
1040 1 : ret = memcpy_s(sendWrlist->rxData.wrRsp, sizeof(struct SendWrRsp) * MAX_WR_NUM, wrRsp,
1041 : completeNum * sizeof(struct SendWrRsp));
1042 1 : if (ret) {
1043 1 : hccp_err("ra_rs_send_wr_list_ext_v2 memcpy_s failed, ret[%d]. ", ret);
1044 1 : ret = -ESAFEFUNC;
1045 1 : goto copy_wr_rsp_fail;
1046 : }
1047 :
1048 0 : copy_wr_rsp_fail:
1049 1 : free(wrList);
1050 1 : wrList = NULL;
1051 :
1052 1 : alloc_wr_list_fail:
1053 1 : free(wrRsp);
1054 1 : wrRsp = NULL;
1055 1 : return 0;
1056 : }
1057 :
1058 0 : STATIC int RaRsSendNormalWrlist(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
1059 : {
1060 : (void)outLen;
1061 0 : union OpSendNormalWrlistData *sendWrlistOut = (union OpSendNormalWrlistData *)(outBuf + sizeof(struct MsgHead));
1062 0 : union OpSendNormalWrlistData *sendWrlist = (union OpSendNormalWrlistData *)(inBuf + sizeof(struct MsgHead));
1063 0 : struct RsWrlistBaseInfo baseInfo = {0};
1064 :
1065 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSendNormalWrlistData), sizeof(struct MsgHead), rcvBufLen, opResult);
1066 : HCCP_CHECK_PARAM_LEN_RET_HOST(sendWrlist->txData.sendNum, 0, MAX_WR_NUM, opResult);
1067 :
1068 0 : baseInfo.phyId = sendWrlist->txData.phyId;
1069 0 : baseInfo.rdevIndex = sendWrlist->txData.rdevIndex;
1070 0 : baseInfo.qpn = sendWrlist->txData.qpn;
1071 0 : baseInfo.keyFlag = 1;
1072 :
1073 0 : *opResult = gRaRsOps.sendWrList(baseInfo, sendWrlist->txData.wrlist, sendWrlist->txData.sendNum,
1074 0 : sendWrlistOut->rxData.wrRsp, &sendWrlistOut->rxData.completeNum);
1075 0 : if (*opResult != 0) {
1076 0 : hccp_err("send_wr_list failed ret[%d].", *opResult);
1077 : }
1078 0 : return 0;
1079 : }
1080 :
1081 1 : STATIC int RaRsGetNotifyBa(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
1082 : {
1083 : (void)outLen;
1084 1 : union OpGetNotifyBaData *getNotifyBaData = (union OpGetNotifyBaData *)(inBuf + sizeof(struct MsgHead));
1085 1 : struct MrInfoT info = {0};
1086 :
1087 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpGetNotifyBaData), sizeof(struct MsgHead), rcvBufLen, opResult);
1088 :
1089 1 : *opResult = gRaRsOps.getNotifyMrInfo(getNotifyBaData->txData.phyId, getNotifyBaData->txData.rdevIndex, &info);
1090 1 : if (*opResult != 0) {
1091 0 : hccp_err("reg_notify_mr failed ret[%d].", *opResult);
1092 0 : return 0;
1093 : }
1094 :
1095 1 : getNotifyBaData = (union OpGetNotifyBaData *)(outBuf + sizeof(struct MsgHead));
1096 1 : getNotifyBaData->rxData.va = (unsigned long long)(uintptr_t)info.addr;
1097 1 : getNotifyBaData->rxData.size = info.size;
1098 1 : getNotifyBaData->rxData.access = info.access;
1099 1 : getNotifyBaData->rxData.lkey = info.lkey;
1100 :
1101 1 : return 0;
1102 : }
1103 :
1104 0 : STATIC int RaRsNotifyCfgSet(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
1105 : {
1106 : (void)outBuf;
1107 : (void)outLen;
1108 0 : union OpNotifyCfgSetData *setNotifyBaData = (union OpNotifyCfgSetData *)(inBuf + sizeof(struct MsgHead));
1109 :
1110 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpNotifyCfgSetData), sizeof(struct MsgHead), rcvBufLen, opResult);
1111 :
1112 0 : *opResult = gRaRsOps.notifyCfgSet(setNotifyBaData->txData.phyId, setNotifyBaData->txData.va,
1113 : setNotifyBaData->txData.size);
1114 0 : if (*opResult != 0) {
1115 0 : hccp_err("notify_cfg_set failed ret[%d].", *opResult);
1116 : }
1117 :
1118 0 : return 0;
1119 : }
1120 :
1121 0 : STATIC int RaRsNotifyCfgGet(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
1122 : {
1123 : (void)outLen;
1124 0 : unsigned long long va = 0;
1125 0 : unsigned long long size = 0;
1126 0 : union OpNotifyCfgGetData *getNotifyBaData = (union OpNotifyCfgGetData *)(inBuf + sizeof(struct MsgHead));
1127 :
1128 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpNotifyCfgGetData), sizeof(struct MsgHead), rcvBufLen, opResult);
1129 :
1130 0 : *opResult = gRaRsOps.notifyCfgGet(getNotifyBaData->txData.phyId, &va, &size);
1131 0 : if (*opResult != 0) {
1132 0 : hccp_err("notify_cfg_set failed ret[%d].", *opResult);
1133 0 : return 0;
1134 : }
1135 :
1136 0 : getNotifyBaData = (union OpNotifyCfgGetData *)(outBuf + sizeof(struct MsgHead));
1137 0 : getNotifyBaData->rxData.va = va;
1138 0 : getNotifyBaData->rxData.size = size;
1139 0 : return 0;
1140 : }
1141 :
1142 1 : STATIC int RaSetPid(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
1143 : {
1144 : (void)outBuf;
1145 : (void)outLen;
1146 1 : union OpSetPidData *setPidData = (union OpSetPidData *)(inBuf + sizeof(struct MsgHead));
1147 :
1148 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSetPidData), sizeof(struct MsgHead), rcvBufLen, opResult);
1149 :
1150 1 : hccp_info("ra get pid is [%d]", setPidData->txData.pid);
1151 :
1152 1 : *opResult = gRaRsOps.setHostPid(setPidData->txData.phyId, setPidData->txData.pid, setPidData->txData.pidSign);
1153 :
1154 1 : hccp_info("ra_set_pid finish");
1155 1 : return 0;
1156 : }
1157 :
1158 117 : STATIC int RaRsCloseHdcSession(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
1159 : {
1160 : (void)inBuf;
1161 : (void)outBuf;
1162 : (void)outLen;
1163 : (void)rcvBufLen;
1164 117 : *opResult = 0;
1165 117 : hccp_info("ra_rs_close_hdc_session finish");
1166 117 : return 0;
1167 : }
1168 :
1169 2 : STATIC int RaRsGetInterfaceVersion(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
1170 : {
1171 : (void)outLen;
1172 2 : unsigned int version = 0;
1173 2 : union OpGetVersionData *versionInfoRet = NULL;
1174 2 : union OpGetVersionData *versionInfo = (union OpGetVersionData *)(inBuf + sizeof(struct MsgHead));
1175 :
1176 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpGetVersionData), sizeof(struct MsgHead), rcvBufLen, opResult);
1177 :
1178 2 : *opResult = gRaRsOps.getInterfaceVersion(versionInfo->txData.opcode, &version);
1179 2 : if (*opResult != 0) {
1180 1 : hccp_err("get_interface_version failed, opcode %d, ret %d", versionInfo->txData.opcode, *opResult);
1181 1 : return 0;
1182 : }
1183 :
1184 1 : versionInfoRet = (union OpGetVersionData *)(outBuf + sizeof(struct MsgHead));
1185 1 : versionInfoRet->rxData.version = version;
1186 1 : return 0;
1187 : }
1188 :
1189 0 : STATIC int RaRsSetQpAttrQos(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
1190 : {
1191 : (void)outBuf;
1192 : (void)outLen;
1193 0 : union OpSetQpAttrQosData *attrQosData = (union OpSetQpAttrQosData *)(inBuf + sizeof(struct MsgHead));
1194 :
1195 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSetQpAttrQosData), sizeof(struct MsgHead), rcvBufLen, opResult);
1196 :
1197 0 : *opResult = gRaRsOps.setQpAttrQos(attrQosData->txData.phyId, attrQosData->txData.rdevIndex, attrQosData->txData.qpn,
1198 : &(attrQosData->txData.qosAttr));
1199 0 : if (*opResult != 0) {
1200 0 : hccp_err("set_qp_attr_qos failed ret[%d].", *opResult);
1201 : }
1202 :
1203 0 : return 0;
1204 : }
1205 :
1206 0 : STATIC int RaRsSetQpAttrTimeout(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
1207 : {
1208 : (void)outBuf;
1209 : (void)outLen;
1210 0 : union OpSetQpAttrTimeoutData *attrTimeData = (union OpSetQpAttrTimeoutData *)(inBuf + sizeof(struct MsgHead));
1211 :
1212 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSetQpAttrTimeoutData), sizeof(struct MsgHead), rcvBufLen, opResult);
1213 :
1214 0 : *opResult = gRaRsOps.setQpAttrTimeout(attrTimeData->txData.phyId, attrTimeData->txData.rdevIndex,
1215 : attrTimeData->txData.qpn, &(attrTimeData->txData.timeout));
1216 0 : if (*opResult != 0) {
1217 0 : hccp_err("set_qp_attr_timeout failed ret[%d].", *opResult);
1218 : }
1219 :
1220 0 : return 0;
1221 : }
1222 :
1223 0 : STATIC int RaRsSetQpAttrRetryCnt(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
1224 : {
1225 : (void)outBuf;
1226 : (void)outLen;
1227 0 : union OpSetQpAttrRetryCntData *attrRetryCntData = (union OpSetQpAttrRetryCntData *)(inBuf + sizeof(struct MsgHead));
1228 :
1229 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSetQpAttrRetryCntData), sizeof(struct MsgHead), rcvBufLen, opResult);
1230 :
1231 0 : *opResult = gRaRsOps.setQpAttrRetryCnt(attrRetryCntData->txData.phyId, attrRetryCntData->txData.rdevIndex,
1232 : attrRetryCntData->txData.qpn, &(attrRetryCntData->txData.retryCnt));
1233 0 : if (*opResult != 0) {
1234 0 : hccp_err("set_qp_attr_retry_cnt failed ret[%d].", *opResult);
1235 : }
1236 :
1237 0 : return 0;
1238 : }
1239 :
1240 0 : STATIC int RaRsGetCqeErrInfo(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
1241 : {
1242 : (void)inBuf;
1243 : (void)outLen;
1244 : int ret;
1245 0 : struct CqeErrInfo info = {0};
1246 0 : union OpGetCqeErrInfoData *cqeErrInfoRet = NULL;
1247 :
1248 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpGetCqeErrInfoData), sizeof(struct MsgHead), rcvBufLen, opResult);
1249 :
1250 0 : *opResult = gRaRsOps.getCqeErrInfo(&info);
1251 0 : if (*opResult != 0) {
1252 0 : hccp_err("get_cqe_err_info failed, ret %d", *opResult);
1253 0 : return 0;
1254 : }
1255 :
1256 0 : cqeErrInfoRet = (union OpGetCqeErrInfoData *)(outBuf + sizeof(struct MsgHead));
1257 0 : ret = memcpy_s(&cqeErrInfoRet->rxData.info, sizeof(struct CqeErrInfo), &info, sizeof(struct CqeErrInfo));
1258 0 : CHK_PRT_RETURN(ret, hccp_err("ra_rs_get_cqe_err_info memcpy_s failed, ret[%d]. ", ret), -ESAFEFUNC);
1259 0 : return 0;
1260 : }
1261 :
1262 0 : STATIC int RaRsGetLiteSupport(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
1263 : {
1264 : (void)outLen;
1265 0 : union OpLiteSupportData *liteSupportData = (union OpLiteSupportData *)(inBuf + sizeof(struct MsgHead));
1266 0 : union OpLiteSupportData *liteSupportOut = (union OpLiteSupportData *)(outBuf + sizeof(struct MsgHead));
1267 :
1268 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpLiteSupportData), sizeof(struct MsgHead), rcvBufLen, opResult);
1269 :
1270 0 : *opResult = gRaRsOps.getLiteSupport(liteSupportData->txData.phyId, liteSupportData->txData.rdevIndex,
1271 : &liteSupportOut->rxData.supportLite);
1272 0 : if (*opResult != 0) {
1273 0 : hccp_err("get_lite_support failed ret[%d].", *opResult);
1274 : }
1275 :
1276 0 : return 0;
1277 : }
1278 :
1279 0 : STATIC int RaRsGetLiteRdevCap(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
1280 : {
1281 : (void)outLen;
1282 0 : union OpLiteRdevCapData *liteRdevCapData = (union OpLiteRdevCapData *)(inBuf + sizeof(struct MsgHead));
1283 0 : union OpLiteRdevCapData *liteRdevCapOut = (union OpLiteRdevCapData *)(outBuf + sizeof(struct MsgHead));
1284 :
1285 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpLiteRdevCapData), sizeof(struct MsgHead), rcvBufLen, opResult);
1286 :
1287 0 : *opResult = gRaRsOps.getLiteRdevCap(liteRdevCapData->txData.phyId, liteRdevCapData->txData.rdevIndex,
1288 : (void *)&liteRdevCapOut->rxData.resp);
1289 0 : if (*opResult != 0) {
1290 0 : hccp_err("get_lite_rdev_cap failed ret[%d].", *opResult);
1291 : }
1292 :
1293 0 : return 0;
1294 : }
1295 :
1296 0 : STATIC int RaRsGetLiteQpCqAttr(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
1297 : {
1298 : (void)outLen;
1299 0 : union OpLiteQpCqAttrData *liteQpCqAttrData = (union OpLiteQpCqAttrData *)(inBuf + sizeof(struct MsgHead));
1300 0 : union OpLiteQpCqAttrData *liteQpCqAttrOut = (union OpLiteQpCqAttrData *)(outBuf + sizeof(struct MsgHead));
1301 :
1302 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpLiteQpCqAttrData), sizeof(struct MsgHead), rcvBufLen, opResult);
1303 :
1304 0 : *opResult = gRaRsOps.getLiteQpCqAttr(liteQpCqAttrData->txData.phyId, liteQpCqAttrData->txData.rdevIndex,
1305 : liteQpCqAttrData->txData.qpn, (void *)&liteQpCqAttrOut->rxData.resp);
1306 0 : if (*opResult != 0) {
1307 0 : hccp_err("get_lite_qp_cq_attr failed ret[%d].", *opResult);
1308 : }
1309 :
1310 0 : return 0;
1311 : }
1312 :
1313 0 : STATIC int RaRsGetLiteConnectedInfo(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
1314 : {
1315 : (void)outLen;
1316 0 : union OpLiteConnectedInfoData *liteConnectedInfoData = (union OpLiteConnectedInfoData *)(inBuf +
1317 : sizeof(struct MsgHead));
1318 0 : union OpLiteConnectedInfoData *liteConnectedInfoOut = (union OpLiteConnectedInfoData *)(outBuf +
1319 : sizeof(struct MsgHead));
1320 :
1321 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpLiteConnectedInfoData), sizeof(struct MsgHead), rcvBufLen, opResult);
1322 :
1323 0 : *opResult = gRaRsOps.getLiteConnectedInfo(liteConnectedInfoData->txData.phyId,
1324 : liteConnectedInfoData->txData.rdevIndex, liteConnectedInfoData->txData.qpn,
1325 : (void *)&liteConnectedInfoOut->rxData.resp);
1326 0 : if (*opResult != 0) {
1327 0 : hccp_err("get_lite_connected_info failed ret[%d].", *opResult);
1328 : }
1329 :
1330 0 : return 0;
1331 : }
1332 :
1333 0 : STATIC int RaRsGetLiteMemAttr(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
1334 : {
1335 : (void)outLen;
1336 0 : union OpLiteMemAttrData *liteMemAttrData = (union OpLiteMemAttrData *)(inBuf + sizeof(struct MsgHead));
1337 0 : union OpLiteMemAttrData *liteMemAttrOut = (union OpLiteMemAttrData *)(outBuf + sizeof(struct MsgHead));
1338 :
1339 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpLiteMemAttrData), sizeof(struct MsgHead), rcvBufLen, opResult);
1340 :
1341 0 : *opResult = gRaRsOps.getLiteMemAttr(liteMemAttrData->txData.phyId, liteMemAttrData->txData.rdevIndex,
1342 : liteMemAttrData->txData.qpn, (void *)&liteMemAttrOut->rxData.resp);
1343 0 : if (*opResult != 0) {
1344 0 : hccp_err("get_lite_mem_attr failed ret[%d].", *opResult);
1345 : }
1346 :
1347 0 : return 0;
1348 : }
1349 :
1350 0 : STATIC int RaRsGetCqeErrInfoNum(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
1351 : {
1352 : (void)outLen;
1353 0 : union OpGetCqeErrInfoNumData *cqeErrInfoNum = (union OpGetCqeErrInfoNumData *)(inBuf + sizeof(struct MsgHead));
1354 : unsigned int num;
1355 :
1356 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpGetCqeErrInfoNumData), sizeof(struct MsgHead), rcvBufLen, opResult);
1357 :
1358 0 : *opResult = gRaRsOps.getCqeErrInfoNum(cqeErrInfoNum->txData.phyId, cqeErrInfoNum->txData.rdevIndex, &num);
1359 0 : if (*opResult != 0) {
1360 0 : hccp_err("get_cqe_err_info_num failed, ret %d", *opResult);
1361 0 : return 0;
1362 : }
1363 :
1364 0 : cqeErrInfoNum = (union OpGetCqeErrInfoNumData *)(outBuf + sizeof(struct MsgHead));
1365 0 : cqeErrInfoNum->rxData.num = num;
1366 :
1367 0 : return 0;
1368 : }
1369 :
1370 0 : STATIC int RaRsGetCqeErrInfoList(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
1371 : {
1372 : (void)outLen;
1373 0 : union OpGetCqeErrInfoListData *cqeErrInfoList = (union OpGetCqeErrInfoListData *)(inBuf + sizeof(struct MsgHead));
1374 0 : union OpGetCqeErrInfoListData *cqeErrInfoListRet = (union OpGetCqeErrInfoListData *)(outBuf +
1375 : sizeof(struct MsgHead));
1376 : unsigned int num;
1377 :
1378 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpGetCqeErrInfoListData), sizeof(struct MsgHead), rcvBufLen, opResult);
1379 : HCCP_CHECK_PARAM_LEN_RET_HOST(cqeErrInfoList->txData.num, 0, CQE_ERR_INFO_MAX_NUM, opResult);
1380 :
1381 0 : num = cqeErrInfoList->txData.num;
1382 0 : *opResult = gRaRsOps.getCqeErrInfoList(cqeErrInfoList->txData.phyId, cqeErrInfoList->txData.rdevIndex,
1383 0 : cqeErrInfoListRet->rxData.infoList, &num);
1384 0 : if (*opResult != 0) {
1385 0 : hccp_err("get_cqe_err_info_list failed, ret %d", *opResult);
1386 0 : return 0;
1387 : }
1388 :
1389 0 : cqeErrInfoListRet->rxData.num = num;
1390 :
1391 0 : return 0;
1392 : }
1393 :
1394 2 : STATIC int RaRsGetTlsEnable(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
1395 : {
1396 : (void)outLen;
1397 2 : union OpGetTlsEnableData *opDataRet = (union OpGetTlsEnableData *)(outBuf + sizeof(struct MsgHead));
1398 2 : union OpGetTlsEnableData *opData = (union OpGetTlsEnableData *)(inBuf + sizeof(struct MsgHead));
1399 :
1400 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpGetTlsEnableData), sizeof(struct MsgHead), rcvBufLen, opResult);
1401 :
1402 2 : *opResult = gRaRsOps.getTlsEnable(opData->txData.phyId, &opDataRet->rxData.tlsEnable);
1403 2 : if (*opResult != 0) {
1404 0 : hccp_err("get_tls_enable failed, ret %d", *opResult);
1405 : }
1406 2 : return 0;
1407 : }
1408 :
1409 1 : STATIC int RaRsGetSecRandom(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
1410 : {
1411 : (void)inBuf;
1412 : (void)outLen;
1413 1 : union OpGetSecRandomData *opDataRet = (union OpGetSecRandomData *)(outBuf + sizeof(struct MsgHead));
1414 :
1415 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpGetSecRandomData), sizeof(struct MsgHead), rcvBufLen, opResult);
1416 :
1417 1 : *opResult = gRaRsOps.getSecRandom((int *)&opDataRet->rxData.value);
1418 1 : if (*opResult != 0) {
1419 0 : hccp_err("get sec random failed, ret %d", *opResult);
1420 : }
1421 1 : return 0;
1422 : }
1423 :
1424 1 : STATIC int RaRsGetHccnCfg(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
1425 : {
1426 : (void)outLen;
1427 1 : union OpGetHccnCfgData *opDataRet = (union OpGetHccnCfgData *)(outBuf + sizeof(struct MsgHead));
1428 1 : union OpGetHccnCfgData *opData = (union OpGetHccnCfgData *)(inBuf + sizeof(struct MsgHead));
1429 :
1430 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpGetHccnCfgData), sizeof(struct MsgHead), rcvBufLen, opResult);
1431 :
1432 1 : struct RaInfo raInfo = {
1433 : .mode = NETWORK_OFFLINE,
1434 1 : .phyId = opData->txData.phyId,
1435 : };
1436 1 : opDataRet->rxData.valueLen = HCCN_CFG_MSG_DATA_LEN;
1437 1 : *opResult = gRaRsOps.getHccnCfg(&raInfo, opData->txData.key, opDataRet->rxData.value, &opDataRet->rxData.valueLen);
1438 1 : if (*opResult != 0) {
1439 0 : hccp_err("get hccn cfg failed, ret %d", *opResult);
1440 : }
1441 1 : return 0;
1442 : }
1443 :
1444 : #define US_PRE_SECOND 1000000
1445 : #define US_PRE_MSECOND 1000
1446 : #define MS_PRE_SECOND 1000
1447 :
1448 242 : STATIC void RaTimeInterval(struct timeval *endTime, struct timeval *startTime, long *msec)
1449 : {
1450 : /* if low position is sufficient, then borrow one from the high position */
1451 242 : if (endTime->tv_usec < startTime->tv_usec) {
1452 0 : endTime->tv_sec -= 1;
1453 0 : endTime->tv_usec += US_PRE_SECOND;
1454 : }
1455 :
1456 242 : *msec = (endTime->tv_sec - startTime->tv_sec) * MS_PRE_SECOND +
1457 242 : (endTime->tv_usec - startTime->tv_usec) / US_PRE_MSECOND;
1458 242 : }
1459 :
1460 : #define OP_TYPE_CFG 0
1461 : #define OP_TYPE_QUERY 1
1462 :
1463 242 : STATIC void RaGetOpRight(struct RaHdcOpSec *opSec, unsigned int opcode, unsigned int asyncReqId, int *right)
1464 : {
1465 242 : long timeInterval = 0;
1466 : struct timeval tCur;
1467 : int exeRight;
1468 : int ret;
1469 :
1470 242 : ret = gettimeofday(&tCur, NULL);
1471 242 : if (ret) {
1472 0 : *right = OP_RIGHT_QUERY_ERR;
1473 0 : hccp_err("ra gettimeofday failed ret[%d].", ret);
1474 0 : return;
1475 : }
1476 :
1477 242 : RaTimeInterval(&tCur, &opSec->tLast, &timeInterval);
1478 242 : opSec->tLast = (timeInterval < 0) ? tCur : opSec->tLast;
1479 242 : timeInterval = (timeInterval < 0) ? 0 : timeInterval;
1480 242 : opSec->tLast = (timeInterval == 0) ? opSec->tLast : tCur;
1481 242 : opSec->tokenNum += timeInterval * TOKEN_RATE;
1482 :
1483 242 : if (opSec->tokenNum == 0) {
1484 0 : *right = HAVE_NOT_OP_RIGHT;
1485 0 : hccp_err("ra handle have not op right. opcode[%u].", opcode);
1486 0 : return;
1487 : }
1488 :
1489 242 : exeRight = HAVE_OP_RIGHT;
1490 :
1491 242 : opSec->tokenNum = opSec->tokenNum - 1;
1492 242 : opSec->tokenNum = (opSec->tokenNum > BUCKET_DEPTH) ? BUCKET_DEPTH : opSec->tokenNum;
1493 242 : if (RaIsOpcodeLogSuppressed(opSec->lastOpcode) && opSec->lastOpcode != opcode) {
1494 2 : hccp_dbg("lastOpcode[%u], exeRight[%d], tokenNum[%llu], cfgOpNum[%u], lastOpcodeCnt[%u]", opSec->lastOpcode,
1495 : exeRight, opSec->tokenNum, opSec->cfgOpNum, opSec->lastOpcodeCnt);
1496 240 : } else if (RaIsOpcodeLogSuppressed(opcode)) {
1497 2 : goto out;
1498 : }
1499 :
1500 240 : if (opSec->isAsyncOp) {
1501 1 : hccp_dbg("opcode[%u], reqId[%u], exeRight[%d], tokenNum[%llu], cfgOpNum[%u]", opcode, asyncReqId, exeRight,
1502 : opSec->tokenNum, opSec->cfgOpNum);
1503 : } else {
1504 239 : hccp_dbg("opcode[%u], exeRight[%d], tokenNum[%llu], cfgOpNum[%u]", opcode, exeRight, opSec->tokenNum,
1505 : opSec->cfgOpNum);
1506 : }
1507 :
1508 242 : out:
1509 488 : opSec->lastOpcodeCnt = (opcode == opSec->lastOpcode) ? (opSec->lastOpcodeCnt + 1)
1510 242 : : (RaIsOpcodeLogSuppressed(opcode) ? 1 : 0);
1511 242 : opSec->lastOpcode = opcode;
1512 242 : *right = exeRight;
1513 242 : return;
1514 : }
1515 :
1516 : struct RaOpHandle gRaOpHandle[] = {
1517 : {RA_RS_SOCKET_CONN, RaRsSocketBatchConnect, sizeof(union OpSocketConnectData)},
1518 : {RA_RS_SOCKET_CLOSE, RaRsSocketBatchClose, sizeof(union OpSocketCloseData)},
1519 : {RA_RS_SOCKET_ABORT, RaRsSocketBatchAbort, sizeof(union OpSocketConnectData)},
1520 : {RA_RS_SOCKET_LISTEN_START, RaRsSocketListenStart, sizeof(union OpSocketListenData)},
1521 : {RA_RS_SOCKET_LISTEN_STOP, RaRsSocketListenStop, sizeof(union OpSocketListenData)},
1522 : {RA_RS_GET_SOCKET, RaRsGetSockets, sizeof(union OpSocketInfoData)},
1523 : {RA_RS_SOCKET_SEND, RaRsSocketSend, sizeof(union OpSocketSendData)},
1524 : {RA_RS_SOCKET_RECV, RaRsSocketRecv, sizeof(union OpSocketRecvData)},
1525 : {RA_RS_QP_CREATE, RaRsQpCreate, sizeof(union OpQpCreateData)},
1526 : {RA_RS_QP_CREATE_WITH_ATTRS, RaRsQpCreateWithAttrs, sizeof(union OpQpCreateWithAttrsData)},
1527 : {RA_RS_QP_CREATE_WITH_CQ_WITH_ATTRS, RaRsQpCreateWithCQWithAttrs, sizeof(union OpQpCreateWithCQWithAttrsData)},
1528 : {RA_RS_AI_QP_CREATE, RaRsAiQpCreate, sizeof(union OpAiQpCreateData)},
1529 : {RA_RS_AI_QP_CREATE_WITH_ATTRS, RaRsAiQpCreateWithData, sizeof(union OpAiQpCreateWithAttrsData)},
1530 : {RA_RS_TYPICAL_QP_CREATE, RaRsTypicalQpCreate, sizeof(union OpTypicalQpCreateData)},
1531 : {RA_RS_TYPICAL_CQ_CREATE, RaRsTypicalCqCreate, sizeof(union OpTypicalCqCreateData)},
1532 : {RA_RS_TYPICAL_CQ_DESTROY, RaRsTypicalCqDestroy, sizeof(union OpTypicalCqDestroyData)},
1533 : {RA_RS_QP_DESTROY, RaRsQpDestroy, sizeof(union OpQpDestroyData)},
1534 : {RA_RS_QP_DESTROY_WITHOUT_CQ, RaRsQpDestroyWithoutCQ, sizeof(union OpQpDestroyData)},
1535 : {RA_RS_TYPICAL_QP_MODIFY, RaRsTypicalQpModify, sizeof(union OpTypicalQpModifyData)},
1536 : {RA_RS_QP_BATCH_MODIFY, RaRsQpBatchModify, sizeof(union OpQpBatchModifyData)},
1537 : {RA_RS_QP_CONNECT, RaRsQpConnectAsync, sizeof(union OpQpConnectData)},
1538 : {RA_RS_QP_STATUS, RaRsGetQpStatus, sizeof(union OpQpStatusData)},
1539 : {RA_RS_QP_INFO, RaRsGetQpInfo, sizeof(union OpQpInfoData)},
1540 : {RA_RS_MR_REG, RaRsMrReg, sizeof(union OpMrRegData)},
1541 : {RA_RS_MR_DEREG, RaRsMrDereg, sizeof(union OpMrDeregData)},
1542 : {RA_RS_TYPICAL_MR_REG_V1, RaRsTypicalMrRegV1, sizeof(union OpTypicalMrRegData)},
1543 : {RA_RS_TYPICAL_MR_REG, RaRsTypicalMrReg, sizeof(union OpTypicalMrRegData)},
1544 : {RA_RS_REMAP_MR, RaRsRemapMr, sizeof(union OpRemapMrData)},
1545 : {RA_RS_TYPICAL_MR_DEREG, RaRsTypicalMrDereg, sizeof(union OpTypicalMrDeregData)},
1546 : {RA_RS_SEND_WR, RaRsSendWr, sizeof(union OpSendWrData)},
1547 : {RA_RS_GET_NOTIFY_BA, RaRsGetNotifyBa, sizeof(union OpGetNotifyBaData)},
1548 : {RA_RS_SOCKET_INIT, RaRsSocketInit, sizeof(union OpSocketInitData)},
1549 : {RA_RS_SOCKET_DEINIT, RaRsSocketDeinit, sizeof(union OpSocketDeinitData)},
1550 : {RA_RS_RDEV_INIT, RaRsRdevInit, sizeof(union OpRdevInitData)},
1551 : {RA_RS_RDEV_INIT_WITH_BACKUP, RaRsRdevInitWithBackup, sizeof(union OpRdevInitWithBackupData)},
1552 : {RA_RS_RDEV_GET_PORT_STATUS, RaRsRdevGetPortStatus, sizeof(union OpRdevGetPortStatusData)},
1553 : {RA_RS_RDEV_DEINIT, RaRsRdevDeinit, sizeof(union OpRdevDeinitData)},
1554 : {RA_RS_WLIST_ADD, RaRsSocketWhiteListAdd, sizeof(union OpWlistData)},
1555 : {RA_RS_WLIST_ADD_V2, RaRsSocketWhiteListAddV2, sizeof(union OpWlistDataV2)},
1556 : {RA_RS_WLIST_DEL, RaRsSocketWhiteListDel, sizeof(union OpWlistData)},
1557 : {RA_RS_WLIST_DEL_V2, RaRsSocketWhiteListDelV2, sizeof(union OpWlistDataV2)},
1558 : {RA_RS_ACCEPT_CREDIT_ADD, RaRsSocketCreditAdd, sizeof(union OpAcceptCreditData)},
1559 : {RA_RS_GET_IFNUM, RaRsGetIfnum, sizeof(union OpIfnumData)},
1560 : {RA_RS_GET_IFADDRS, RaRsGetIfaddrs, sizeof(union OpIfaddrData)},
1561 : {RA_RS_GET_IFADDRS_V2, RaRsGetIfaddrsV2, sizeof(union OpIfaddrDataV2)},
1562 : {RA_RS_GET_INTERFACE_VERSION, RaRsGetInterfaceVersion, sizeof(union OpGetVersionData)},
1563 : {RA_RS_SEND_WRLIST, RaRsSendWrList, sizeof(union OpSendWrlistData)},
1564 : {RA_RS_SEND_WRLIST_V2, RaRsSendWrListV2, sizeof(union OpSendWrlistDataV2)},
1565 : {RA_RS_SEND_WRLIST_EXT, RaRsSendWrListExt, sizeof(union OpSendWrlistDataExt)},
1566 : {RA_RS_SEND_WRLIST_EXT_V2, RaRsSendWrListExtV2, sizeof(union OpSendWrlistDataExtV2)},
1567 : {RA_RS_SEND_NORMAL_WRLIST, RaRsSendNormalWrlist, sizeof(union OpSendNormalWrlistData)},
1568 : {RA_RS_SET_TSQP_DEPTH, RaRsSetTsqpDepth, sizeof(union OpSetTsqpDepthData)},
1569 : {RA_RS_GET_TSQP_DEPTH, RaRsGetTsqpDepth, sizeof(union OpGetTsqpDepthData)},
1570 : {RA_RS_HDC_SESSION_CLOSE, RaRsCloseHdcSession, sizeof(union OpSocketRecvData)},
1571 : {RA_RS_GET_VNIC_IP, RaRsGetVnicIp, sizeof(union OpGetVnicIpData)},
1572 : {RA_RS_GET_VNIC_IP_INFOS_V1, RaRsGetVnicIpInfosV1, sizeof(union OpGetVnicIpInfosDataV1)},
1573 : {RA_RS_GET_VNIC_IP_INFOS, RaRsGetVnicIpInfos, sizeof(union OpGetVnicIpInfosData)},
1574 : {RA_RS_NOTIFY_CFG_SET, RaRsNotifyCfgSet, sizeof(union OpNotifyCfgSetData)},
1575 : {RA_RS_NOTIFY_CFG_GET, RaRsNotifyCfgGet, sizeof(union OpNotifyCfgGetData)},
1576 : {RA_RS_SET_PID, RaSetPid, sizeof(union OpSetPidData)},
1577 : {RA_RS_SET_QP_ATTR_QOS, RaRsSetQpAttrQos, sizeof(union OpSetQpAttrQosData)},
1578 : {RA_RS_SET_QP_ATTR_TIMEOUT, RaRsSetQpAttrTimeout, sizeof(union OpSetQpAttrTimeoutData)},
1579 : {RA_RS_SET_QP_ATTR_RETRY_CNT, RaRsSetQpAttrRetryCnt, sizeof(union OpSetQpAttrRetryCntData)},
1580 : {RA_RS_GET_CQE_ERR_INFO, RaRsGetCqeErrInfo, sizeof(union OpGetCqeErrInfoData)},
1581 : {RA_RS_GET_CQE_ERR_INFO_NUM, RaRsGetCqeErrInfoNum, sizeof(union OpGetCqeErrInfoNumData)},
1582 : {RA_RS_GET_CQE_ERR_INFO_LIST, RaRsGetCqeErrInfoList, sizeof(union OpGetCqeErrInfoListData)},
1583 : {RA_RS_GET_LITE_SUPPORT, RaRsGetLiteSupport, sizeof(union OpLiteSupportData)},
1584 : {RA_RS_GET_LITE_RDEV_CAP, RaRsGetLiteRdevCap, sizeof(union OpLiteRdevCapData)},
1585 : {RA_RS_GET_LITE_QP_CQ_ATTR, RaRsGetLiteQpCqAttr, sizeof(union OpLiteQpCqAttrData)},
1586 : {RA_RS_GET_LITE_QP_ATTR, RaRsGetLiteQpAttr, sizeof(union OpLiteQpAttrData)},
1587 : {RA_RS_GET_LITE_CQ_ATTR, RaRsGetLiteCqAttr, sizeof(union OpGetLiteCqAttrData)},
1588 : {RA_RS_GET_LITE_CONNECTED_INFO, RaRsGetLiteConnectedInfo, sizeof(union OpLiteConnectedInfoData)},
1589 : {RA_RS_GET_LITE_MEM_ATTR, RaRsGetLiteMemAttr, sizeof(union OpLiteMemAttrData)},
1590 : {RA_RS_PING_INIT, RaRsPingInit, sizeof(union OpPingInitData)},
1591 : {RA_RS_PING_ADD, RaRsPingTargetAdd, sizeof(union OpPingAddData)},
1592 : {RA_RS_PING_START, RaRsPingTaskStart, sizeof(union OpPingStartData)},
1593 : {RA_RS_PING_GET_RESULTS, RaRsPingGetResults, sizeof(union OpPingResultsData)},
1594 : {RA_RS_PING_STOP, RaRsPingTaskStop, sizeof(union OpPingStopData)},
1595 : {RA_RS_PING_DEL, RaRsPingTargetDel, sizeof(union OpPingDelData)},
1596 : {RA_RS_PING_DEINIT, RaRsPingDeinit, sizeof(union OpPingDeinitData)},
1597 : {RA_RS_TLV_INIT_V1, RaRsTlvInitV1, sizeof(union OpTlvInitDataV1)},
1598 : {RA_RS_TLV_INIT, RaRsTlvInit, sizeof(union OpTlvInitData)},
1599 : {RA_RS_TLV_DEINIT, RaRsTlvDeinit, sizeof(union OpTlvDeinitData)},
1600 : {RA_RS_TLV_REQUEST, RaRsTlvRequest, sizeof(union OpTlvRequestData)},
1601 : {RA_RS_TLV_REQUEST_V2, RaRsTlvRequestV2, sizeof(union OpTlvRequestDataV2)},
1602 : {RA_RS_CUSTOM_CHANNEL_DEPRECATED, RaRsCustomChannel, sizeof(union OpCustomChannelData)},
1603 : {RA_RS_GET_TLS_ENABLE, RaRsGetTlsEnable, sizeof(union OpGetTlsEnableData)},
1604 : {RA_RS_GET_SEC_RANDOM, RaRsGetSecRandom, sizeof(union OpGetSecRandomData)},
1605 : {RA_RS_GET_HCCN_CFG, RaRsGetHccnCfg, sizeof(union OpGetHccnCfgData)},
1606 : {RA_RS_ASYNC_HDC_SESSION_CONNECT, RaRsAsyncHdcSessionConnect, sizeof(union OpAsyncHdcConnectData)},
1607 : {RA_RS_ASYNC_HDC_SESSION_CLOSE, RaRsAsyncHdcSessionClose, sizeof(union OpAsyncHdcCloseData)},
1608 : {RA_RS_GET_DEV_EID_INFO_NUM, RaRsGetDevEidInfoNum, sizeof(union OpGetDevEidInfoNumData)},
1609 : {RA_RS_GET_DEV_EID_INFO_LIST, RaRsGetDevEidInfoList, sizeof(union OpGetDevEidInfoListData)},
1610 : {RA_RS_CTX_INIT, RaRsCtxInit, sizeof(union OpCtxInitData)},
1611 : {RA_RS_CTX_GET_ASYNC_EVENTS, RaRsCtxGetAsyncEvents, sizeof(union OpCtxGetAsyncEventsData)},
1612 : {RA_RS_CTX_DEINIT, RaRsCtxDeinit, sizeof(union OpCtxDeinitData)},
1613 : {RA_RS_GET_EID_BY_IP, RaRsGetEidByIp, sizeof(union OpGetEidByIpData)},
1614 : {RA_RS_GET_IP_BY_EID, RaRsGetIpByEid, sizeof(union OpGetIpByEidData)},
1615 : {RA_RS_GET_TP_INFO_LIST, RaRsGetTpInfoList, sizeof(union OpGetTpInfoListData)},
1616 : {RA_RS_GET_TP_ATTR, RaRsGetTpAttr, sizeof(union OpGetTpAttrData)},
1617 : {RA_RS_SET_TP_ATTR, RaRsSetTpAttr, sizeof(union OpSetTpAttrData)},
1618 : {RA_RS_CTX_TOKEN_ID_ALLOC, RaRsCtxTokenIdAlloc, sizeof(union OpTokenIdAllocData)},
1619 : {RA_RS_CTX_TOKEN_ID_FREE, RaRsCtxTokenIdFree, sizeof(union OpTokenIdFreeData)},
1620 : {RA_RS_LMEM_REG, RaRsLmemReg, sizeof(union OpLmemRegInfoData)},
1621 : {RA_RS_LMEM_UNREG, RaRsLmemUnreg, sizeof(union OpLmemUnregInfoData)},
1622 : {RA_RS_RMEM_IMPORT, RaRsRmemImport, sizeof(union OpRmemImportInfoData)},
1623 : {RA_RS_RMEM_UNIMPORT, RaRsRmemUnimport, sizeof(union OpRmemUnimportInfoData)},
1624 : {RA_RS_CTX_CHAN_CREATE, RaRsCtxChanCreate, sizeof(union OpCtxChanCreateData)},
1625 : {RA_RS_CTX_CHAN_DESTROY, RaRsCtxChanDestroy, sizeof(union OpCtxChanDestroyData)},
1626 : {RA_RS_CTX_CQ_CREATE, RaRsCtxCqCreate, sizeof(union OpCtxCqCreateData)},
1627 : {RA_RS_CTX_CQ_DESTROY, RaRsCtxCqDestroy, sizeof(union OpCtxCqDestroyData)},
1628 : {RA_RS_CTX_QP_CREATE, RaRsCtxQpCreate, sizeof(union OpCtxQpCreateData)},
1629 : {RA_RS_CTX_QUERY_QP_BATCH, RaRsCtxQpQueryBatch, sizeof(union OpCtxQpQueryBatchData)},
1630 : {RA_RS_CTX_QP_DESTROY, RaRsCtxQpDestroy, sizeof(union OpCtxQpDestroyData)},
1631 : {RA_RS_CTX_QP_DESTROY_BATCH, RaRsCtxQpDestroyBatch, sizeof(union OpCtxQpDestroyBatchData)},
1632 : {RA_RS_CTX_QP_IMPORT, RaRsCtxQpImport, sizeof(union OpCtxQpImportData)},
1633 : {RA_RS_CTX_QP_UNIMPORT, RaRsCtxQpUnimport, sizeof(union OpCtxQpUnimportData)},
1634 : {RA_RS_CTX_QP_UNIMPORT_DEPRECATED, RaRsCtxQpUnimportDeprecated, sizeof(union OpCtxQpUnimportData)},
1635 : {RA_RS_CTX_QP_BIND, RaRsCtxQpBind, sizeof(union OpCtxQpBindData)},
1636 : {RA_RS_CTX_QP_UNBIND, RaRsCtxQpUnbind, sizeof(union OpCtxQpUnbindData)},
1637 : {RA_RS_CTX_BATCH_SEND_WR, RaRsCtxBatchSendWr, sizeof(union OpCtxBatchSendWrData)},
1638 : {RA_RS_CTX_UPDATE_CI, RaRsCtxUpdateCi, sizeof(union OpCtxUpdateCiData)},
1639 : {RA_RS_CTX_GET_AUX_INFO, RaRsCtxGetAuxInfo, sizeof(union OpCtxGetAuxInfoData)},
1640 : {RA_RS_CTX_GET_CR_ERR_INFO_LIST, RaRsCtxGetCrErrInfoList, sizeof(union OpCtxGetCrErrInfoListData)},
1641 : {RA_RS_CTX_GET_UB_CONTEXT, RaRsCtxGetUbContext, sizeof(union OpCtxGetContextData)},
1642 : };
1643 :
1644 242 : STATIC int RaCheckParam(char *recvBuf, int rcvBufLen, char **sendBuf, int *sndBufLen, int *paramCheckResult)
1645 : {
1646 : int i;
1647 242 : int ret = 0;
1648 242 : struct MsgHead *recvMsgHead = (struct MsgHead *)recvBuf;
1649 242 : int num = sizeof(gRaOpHandle) / sizeof(gRaOpHandle[0]);
1650 242 : unsigned int dataSize = 0;
1651 :
1652 242 : *paramCheckResult = 1;
1653 242 : if (rcvBufLen < (int)sizeof(struct MsgHead)) { // check rcv_buf_len
1654 0 : hccp_err("rcv_buf_len[%d] from ra is invalid", rcvBufLen);
1655 0 : ret = OpMsgErr(sendBuf, recvMsgHead, sndBufLen, RECV_BUF_LEN_INVALID);
1656 0 : return ret;
1657 : }
1658 :
1659 242 : if (((recvMsgHead->msgDataLen + sizeof(struct MsgHead)) != (unsigned int)rcvBufLen) ||
1660 242 : (recvMsgHead->opcode >= RA_RS_OP_MAX_NUM ||
1661 242 : ((recvMsgHead->opcode < RA_RS_HDC_SESSION_CLOSE) && (recvMsgHead->opcode >= RA_RS_EXTER_OP_MAX_NUM)))) {
1662 0 : hccp_err("rcv data incomplete, because rcvBufLen[%d] != msg_head_len[%u] + msgDataLen[%u] "
1663 : "or opcode[%u] is wrong, RA_RS_OP_MAX_NUM:[%d], RA_RS_EXTER_OP_MAX_NUM:[%d]",
1664 : rcvBufLen, sizeof(struct MsgHead), recvMsgHead->msgDataLen, recvMsgHead->opcode, RA_RS_OP_MAX_NUM,
1665 : RA_RS_EXTER_OP_MAX_NUM);
1666 0 : ret = OpMsgErr(sendBuf, recvMsgHead, sndBufLen, HAVE_OP_RIGHT);
1667 0 : return ret;
1668 : }
1669 13447 : for (i = 0; i < num; i++) {
1670 13447 : if (gRaOpHandle[i].opcode == recvMsgHead->opcode) {
1671 242 : dataSize = gRaOpHandle[i].dataSize;
1672 242 : break;
1673 : }
1674 : }
1675 242 : if (recvMsgHead->opcode != RA_RS_SOCKET_RECV && recvMsgHead->msgDataLen != dataSize) {
1676 0 : hccp_err("rcv data incomplete. because msg_data_len[%d] != op_data_len[%u]", recvMsgHead->msgDataLen, dataSize);
1677 0 : ret = OpMsgErr(sendBuf, recvMsgHead, sndBufLen, RECV_BUF_LEN_INVALID);
1678 0 : return ret;
1679 : }
1680 242 : *paramCheckResult = 0;
1681 242 : return ret;
1682 : }
1683 :
1684 242 : int RaHandle(struct RaHdcOpSec *opSec, char *recvBuf, int rcvBufLen, char **sendBuf, int *sndBufLen,
1685 : unsigned int *closeSession)
1686 : {
1687 : int i;
1688 : int ret;
1689 242 : int opRight = 0;
1690 242 : int paramCheckRet = 0;
1691 242 : int opRet = 0;
1692 242 : struct MsgHead *recvMsgHead = (struct MsgHead *)recvBuf;
1693 242 : int num = sizeof(gRaOpHandle) / sizeof(gRaOpHandle[0]);
1694 :
1695 242 : ret = RaCheckParam(recvBuf, rcvBufLen, sendBuf, sndBufLen, ¶mCheckRet);
1696 242 : CHK_PRT_RETURN(paramCheckRet != 0 || ret != 0,
1697 : hccp_err("ra param check failed. param check ret:[%d] "
1698 : "function call ret:[%d]",
1699 : paramCheckRet, ret),
1700 : ret);
1701 :
1702 242 : RaGetOpRight(opSec, recvMsgHead->opcode, recvMsgHead->asyncReqId, &opRight);
1703 242 : CHK_PRT_RETURN(opRight != HAVE_OP_RIGHT, ret = OpMsgErr(sendBuf, recvMsgHead, sndBufLen, opRight), ret);
1704 :
1705 242 : *sendBuf = (char *)calloc(sizeof(char), recvMsgHead->msgDataLen + sizeof(struct MsgHead));
1706 242 : CHK_PRT_RETURN(*sendBuf == NULL, hccp_err("calloc failed."), -ENOMEM);
1707 :
1708 13447 : for (i = 0; i < num; i++) {
1709 13447 : if (gRaOpHandle[i].opcode == recvMsgHead->opcode) {
1710 242 : ret = gRaOpHandle[i].opHandle(recvBuf, *sendBuf, sndBufLen, &opRet, rcvBufLen);
1711 242 : if (ret) {
1712 1 : hccp_err("ra handle failed. ret:[%d]", ret);
1713 1 : goto out;
1714 : }
1715 241 : MsgHeadBuildUpHw(*sendBuf, recvMsgHead, opRet, recvMsgHead->msgDataLen);
1716 241 : *closeSession = recvMsgHead->opcode == RA_RS_HDC_SESSION_CLOSE ? 1 : 0;
1717 241 : *sndBufLen = recvMsgHead->msgDataLen + sizeof(struct MsgHead);
1718 241 : return ret;
1719 : }
1720 : }
1721 :
1722 0 : hccp_warn("not support opcode:%d", recvMsgHead->opcode);
1723 0 : ret = -EPROTONOSUPPORT;
1724 1 : out:
1725 1 : free(*sendBuf);
1726 1 : *sendBuf = NULL;
1727 1 : return ret;
1728 : }
1729 :
1730 240 : STATIC int RaSendPkt(struct drvHdcMsg *msgRcv, HDC_SESSION session, void *sendBuf, int sndBufLen)
1731 : {
1732 : int ret;
1733 240 : struct drvHdcMsg *msgSnd = NULL;
1734 :
1735 240 : ret = RA_HDC_OPS.reuseMsg(msgRcv);
1736 240 : CHK_PRT_RETURN(ret, hccp_err("reuse msg failed ret %d", ret), ret);
1737 :
1738 240 : msgSnd = msgRcv;
1739 :
1740 240 : ret = RA_HDC_OPS.addMsgBuffer(msgSnd, sendBuf, sndBufLen);
1741 240 : CHK_PRT_RETURN(ret, hccp_err("add msg buffer failed ret %d", ret), ret);
1742 :
1743 240 : ret = RA_HDC_OPS.send(session, msgSnd, 0, RA_HDC_RECV_SEND_TIMEOUT);
1744 240 : CHK_PRT_RETURN(ret, hccp_err("send msg failed ret %d", ret), ret);
1745 :
1746 240 : return 0;
1747 : }
1748 :
1749 242 : STATIC int RecvHandleSendPkt(HDC_SESSION session, unsigned int *closeSession, unsigned int chipId)
1750 : {
1751 : int ret;
1752 242 : void *recvBuf = NULL;
1753 242 : void *sendBuf = NULL;
1754 242 : struct drvHdcMsg *msgRcv = NULL;
1755 : int recvBufCnt, sndBufLen, rcvBufLen;
1756 242 : RsSetCtx(chipId);
1757 242 : ret = RA_HDC_OPS.allocMsg(session, &msgRcv, 1);
1758 242 : CHK_PRT_RETURN(ret, hccp_err("alloc hdc msg failed ret %d", ret), ret);
1759 :
1760 242 : ret = RA_HDC_OPS.recv(session, msgRcv, MAX_HDC_DATA, 0, &recvBufCnt, RA_HDC_RECV_SEND_TIMEOUT);
1761 242 : if (ret) {
1762 1 : hccp_warn("recv hdc msg unsuccessful, ret %d", ret);
1763 1 : goto out;
1764 : }
1765 :
1766 241 : RA_HDC_OPS.getMsgBuffer(msgRcv, 0, (char **)&recvBuf, &rcvBufLen);
1767 241 : if (recvBuf == NULL) {
1768 0 : hccp_warn("rcv_buf_len is NULL, Session disconnect.");
1769 0 : goto out;
1770 : }
1771 :
1772 241 : if (rcvBufLen == 0) {
1773 0 : *closeSession = 1;
1774 0 : hccp_warn("rcv_buf_len is 0, Session disconnect.");
1775 0 : RA_HDC_OPS.freeMsg(msgRcv);
1776 0 : return 0;
1777 : }
1778 :
1779 241 : ret = RaHandle(&gHdcServer[chipId].opSec, recvBuf, rcvBufLen, (char **)&sendBuf, &sndBufLen, closeSession);
1780 241 : if (ret) {
1781 1 : hccp_err("ra_handle failed.");
1782 1 : goto out;
1783 : }
1784 :
1785 240 : ret = RaSendPkt(msgRcv, session, sendBuf, sndBufLen);
1786 240 : if (ret) {
1787 0 : hccp_err("ra send pkt failed ret %d", ret);
1788 0 : goto err;
1789 : }
1790 :
1791 240 : err:
1792 240 : free(sendBuf);
1793 240 : sendBuf = NULL;
1794 242 : out:
1795 242 : RA_HDC_OPS.freeMsg(msgRcv);
1796 242 : return ret;
1797 : }
1798 :
1799 242 : STATIC void RaHdcRecvHandleSendPkt(const unsigned int chipId)
1800 : {
1801 242 : unsigned int closeSession = 0;
1802 : int ret;
1803 :
1804 242 : ret = RecvHandleSendPkt(gHdcServer[chipId].hdcSession, &closeSession, chipId);
1805 242 : if (closeSession != 0 || ret != 0) {
1806 119 : hccp_warn("recv_handle_send_pkt close_session[%u] ret[%d]", closeSession, ret);
1807 119 : RA_PTHREAD_MUTEX_LOCK(&gHdcInitPara.mutex);
1808 119 : gHdcInitPara.connectStatus = HDC_UNCONNECTED;
1809 119 : RA_PTHREAD_MUTEX_UNLOCK(&gHdcInitPara.mutex);
1810 : }
1811 :
1812 242 : return;
1813 : }
1814 :
1815 354 : STATIC void RaHwHdcCloseSession(HDC_SESSION *session)
1816 : {
1817 : int ret;
1818 :
1819 354 : RA_PTHREAD_MUTEX_LOCK(&gHdcInitPara.mutex);
1820 354 : if (session == NULL || *session == NULL) {
1821 236 : goto out;
1822 : }
1823 :
1824 118 : ret = RA_HDC_OPS.sessionClose(*session);
1825 118 : if (ret != 0) {
1826 0 : hccp_warn("RA_HDC_OPS.sessionClose unsuccessful, ret:%d", ret);
1827 : }
1828 118 : *session = NULL;
1829 :
1830 354 : out:
1831 354 : RA_PTHREAD_MUTEX_UNLOCK(&gHdcInitPara.mutex);
1832 354 : return;
1833 : }
1834 :
1835 118 : STATIC void *RaPthread(void *arg)
1836 : {
1837 : (void)arg;
1838 118 : unsigned int chipId = gHdcInitPara.chipId;
1839 : int ret;
1840 :
1841 118 : ret = pthread_detach(pthread_self());
1842 118 : CHK_PRT_RETURN(ret, hccp_err("pthread detach failed ret %d", ret), NULL);
1843 :
1844 118 : (void)prctl(PR_SET_NAME, (uintptr_t) "hccp_ra", 0, 0, 0);
1845 :
1846 118 : RA_PTHREAD_MUTEX_LOCK(&gHdcInitPara.mutex);
1847 118 : gHdcInitPara.threadStatus = THREAD_RUNNING;
1848 118 : RA_PTHREAD_MUTEX_UNLOCK(&gHdcInitPara.mutex);
1849 :
1850 118 : RsGetCurTime(&gRaThreadInfo.lastCheckTime);
1851 118 : ret = strncpy_s((char *)gRaThreadInfo.pthreadName, sizeof(gRaThreadInfo.pthreadName), "ra_thread",
1852 : strlen("ra_thread"));
1853 118 : CHK_PRT_RETURN(ret, hccp_err("strncpy_s pthread name failed, ret[%d]", ret), NULL);
1854 :
1855 118 : hccp_run_info("pthread[%s] is alive!", gRaThreadInfo.pthreadName);
1856 : while (1) {
1857 1221 : if (gHdcInitPara.threadStatus == THREAD_DESTROYING) {
1858 118 : break;
1859 : }
1860 :
1861 1103 : if (gHdcInitPara.connectStatus != HDC_CONNECTED) {
1862 862 : usleep(THREAD_SLEEP_TIME);
1863 862 : continue;
1864 : }
1865 241 : RsHeartbeatAlivePrint(&gRaThreadInfo);
1866 241 : RaHdcRecvHandleSendPkt(chipId);
1867 : }
1868 :
1869 118 : hccp_info("thread [%d] is out", getpid());
1870 118 : RaHwHdcCloseSession(&gHdcServer[chipId].hdcSession);
1871 118 : RA_PTHREAD_MUTEX_LOCK(&gHdcInitPara.mutex);
1872 118 : gHdcInitPara.threadStatus = THREAD_HALT;
1873 118 : RA_PTHREAD_MUTEX_UNLOCK(&gHdcInitPara.mutex);
1874 118 : return NULL;
1875 : }
1876 :
1877 123 : STATIC int RaHdcServerInit(unsigned int chipId, int hdcType)
1878 : {
1879 : int ret;
1880 :
1881 123 : CHK_PRT_RETURN(chipId > HCCP_MAX_CHIP_ID || gHdcServer[chipId].hdcSession != NULL,
1882 : hccp_err("invalid "
1883 : "chip id %u, or hdcSession is not NULL",
1884 : chipId),
1885 : -EINVAL);
1886 122 : CHK_PRT_RETURN(hdcType != HDC_SERVICE_TYPE_RDMA && hdcType != HDC_SERVICE_TYPE_RDMA_V2,
1887 : hccp_err("invalid "
1888 : "hdc_type %d",
1889 : hdcType),
1890 : -EINVAL);
1891 :
1892 122 : RaHdcInitOpSec(&gHdcServer[chipId].opSec, BUCKET_DEPTH, false);
1893 :
1894 122 : ret = RA_HDC_OPS.serverCreate(chipId, hdcType, &gHdcServer[chipId].hdcServer);
1895 122 : CHK_PRT_RETURN(ret, hccp_err("Create Server failed, ret(%d) ", ret), -EINVAL);
1896 :
1897 121 : return 0;
1898 : }
1899 :
1900 241 : void RaHdcInitOpSec(struct RaHdcOpSec *opSec, unsigned long long tokenNum, bool isAsyncOp)
1901 : {
1902 241 : opSec->tokenNum = tokenNum;
1903 241 : opSec->cfgOpNum = 0;
1904 241 : opSec->tLast.tv_sec = 0;
1905 241 : opSec->tLast.tv_usec = 0;
1906 241 : opSec->isAsyncOp = isAsyncOp;
1907 241 : }
1908 :
1909 237 : int RaHdcSessionAccept(unsigned int chipId, HDC_SESSION *session, int initHostTgid)
1910 : {
1911 : int hostTgid;
1912 237 : int ret = 0;
1913 :
1914 237 : ret = RA_HDC_OPS.sessionAccept(gHdcServer[chipId].hdcServer, session);
1915 237 : if (ret != 0) {
1916 118 : hccp_warn("Session accept failed, chipId(%u), ret(%d) ", chipId, ret);
1917 118 : return ret;
1918 : }
1919 :
1920 119 : RA_HDC_OPS.setSessionReference(*session);
1921 119 : ret = DlHalHdcGetSessionAttr(*session, HDC_SESSION_ATTR_PEER_CREATE_PID, &hostTgid);
1922 119 : if (ret) {
1923 0 : hccp_err("Session get host_pid failed, chipId(%u), ret(%d)", chipId, ret);
1924 0 : goto out;
1925 : }
1926 :
1927 119 : if (hostTgid != initHostTgid) {
1928 0 : hccp_warn("host_tgid[%d] from ra not equal to the tgid[%d] from hccp_init, invalid", hostTgid, initHostTgid);
1929 0 : goto out;
1930 : }
1931 :
1932 119 : return 0;
1933 :
1934 0 : out:
1935 0 : RaHdcCloseSession(session);
1936 0 : return ret;
1937 : }
1938 :
1939 3 : int RaHdcAsyncRecvPkt(struct RaHdcAsyncInfo *asyncInfo, unsigned int chipId, void **recvBuf, unsigned int *recvLen)
1940 : {
1941 : (void)chipId;
1942 3 : struct drvHdcMsg *msgRcv = NULL;
1943 3 : void *rcvBuf = NULL;
1944 3 : int rcvLen = 0;
1945 : int ret;
1946 :
1947 3 : ret = RA_HDC_OPS.allocMsg(asyncInfo->hdcSession, &msgRcv, 1);
1948 3 : CHK_PRT_RETURN(ret != 0, hccp_err("alloc hdc msg failed ret %d", ret), ret);
1949 :
1950 3 : ret = RA_HDC_OPS.recv(asyncInfo->hdcSession, msgRcv, MAX_HDC_DATA, 0, &rcvLen, RA_HDC_RECV_SEND_TIMEOUT);
1951 3 : if (ret != 0) {
1952 1 : hccp_warn("recv hdc msg unsuccessful ret %d", ret);
1953 1 : goto out;
1954 : }
1955 :
1956 2 : RA_HDC_OPS.getMsgBuffer(msgRcv, 0, (char **)&rcvBuf, &rcvLen);
1957 2 : if (rcvBuf == NULL || rcvLen == 0) {
1958 2 : hccp_warn("get_msg_buffer unsuccessful, rcvBuf is NULL or rcvLen:%d is 0", rcvLen);
1959 2 : goto out;
1960 : }
1961 :
1962 0 : *recvBuf = (char *)calloc(rcvLen, sizeof(char));
1963 0 : if (*recvBuf == NULL) {
1964 0 : hccp_err("calloc recv_buf failed, errno:%d rcvLen:%d", errno, rcvLen);
1965 0 : ret = -ENOMEM;
1966 0 : goto out;
1967 : }
1968 :
1969 0 : (void)memcpy_s(*recvBuf, rcvLen, rcvBuf, rcvLen);
1970 0 : *recvLen = rcvLen;
1971 :
1972 3 : out:
1973 3 : RA_HDC_OPS.freeMsg(msgRcv);
1974 3 : return ret;
1975 : }
1976 :
1977 1 : int RaHdcAsyncSendPkt(struct RaHdcAsyncInfo *asyncInfo, unsigned int chipId, void *sendBuf, unsigned int sendLen)
1978 : {
1979 1 : struct drvHdcMsg *msgSnd = NULL;
1980 1 : int ret = -EINVAL;
1981 :
1982 1 : RA_PTHREAD_MUTEX_LOCK(&asyncInfo->sendMutex);
1983 : // degrade log level because session will be closed by recv thread and request will be abort
1984 1 : if (asyncInfo->hdcSession == NULL) {
1985 1 : hccp_warn("[async][send_pkt]hdc_session is NULL, chipId(%u)", chipId);
1986 1 : goto alloc_msg_err;
1987 : }
1988 :
1989 0 : ret = RA_HDC_OPS.allocMsg(asyncInfo->hdcSession, &msgSnd, 1);
1990 0 : if (ret != 0) {
1991 0 : hccp_err("[async][send_pkt]HDC alloc msg err ret(%d) chip_id(%u)", ret, chipId);
1992 0 : goto alloc_msg_err;
1993 : }
1994 :
1995 0 : ret = RA_HDC_OPS.addMsgBuffer(msgSnd, sendBuf, sendLen);
1996 0 : if (ret != 0) {
1997 0 : hccp_err("[async][send_pkt]HDC add msg buffer err ret(%d) chip_id(%u)", ret, chipId);
1998 0 : goto msg_err;
1999 : }
2000 :
2001 0 : ret = RA_HDC_OPS.send(asyncInfo->hdcSession, msgSnd, RA_HDC_WAIT_TIMEOUT, RA_HDC_RECV_SEND_TIMEOUT);
2002 0 : if (ret != 0) {
2003 0 : hccp_err("[async][send_pkt]HDC send err ret(%d) chip_id(%u)", ret, chipId);
2004 0 : goto msg_err;
2005 : }
2006 :
2007 0 : msg_err:
2008 0 : RA_HDC_OPS.freeMsg(msgSnd);
2009 1 : alloc_msg_err:
2010 1 : RA_PTHREAD_MUTEX_UNLOCK(&asyncInfo->sendMutex);
2011 1 : return ret;
2012 : }
2013 :
2014 1 : void RaHdcCloseSession(HDC_SESSION *session)
2015 : {
2016 1 : RA_HDC_OPS.sessionClose(*session);
2017 1 : *session = NULL;
2018 1 : return;
2019 : }
2020 :
2021 119 : STATIC void RaHwHdcInit(void *arg)
2022 : {
2023 : (void)arg;
2024 119 : unsigned int chipId = gHdcInitPara.chipId;
2025 : pthread_t tidp;
2026 : int ret;
2027 :
2028 119 : ret = pthread_detach(pthread_self());
2029 119 : if (ret) {
2030 1 : hccp_err("pthread detach failed ret %d", ret);
2031 1 : return;
2032 : }
2033 :
2034 118 : (void)prctl(PR_SET_NAME, (uintptr_t) "hccp_hw_hdc", 0, 0, 0);
2035 :
2036 118 : hccp_info("chip_id(%u)", chipId);
2037 118 : gHdcInitPara.hdcFlag = 1;
2038 :
2039 118 : ret = pthread_create(&tidp, NULL, (void *)RaPthread, NULL);
2040 118 : if (ret) {
2041 0 : hccp_err("Create pthread failed, chipId(%u), ret(%d) ", chipId, ret);
2042 0 : return;
2043 : }
2044 :
2045 : while (1) {
2046 2071 : if (gHdcInitPara.connectStatus != HDC_UNCONNECTED) {
2047 1835 : usleep(HDC_ACCEPT_SLEEP_TIME);
2048 1835 : continue;
2049 : }
2050 236 : RaHwHdcCloseSession(&gHdcServer[chipId].hdcSession);
2051 236 : ret = RaHdcSessionAccept(chipId, &gHdcServer[chipId].hdcSession, (int)gHdcInitPara.hostTgid);
2052 236 : if (ret != 0) {
2053 118 : hccp_warn("Session Accept unsuccessful, chipId(%u), ret(%d) ", chipId, ret);
2054 118 : gHdcInitPara.hdcFlag = 0;
2055 118 : return;
2056 : }
2057 : // original case, should continue to accept: host_tgid != g_hdc_init_para.host_tgid
2058 118 : if (ret == 0 && gHdcServer[chipId].hdcSession == NULL) {
2059 0 : continue;
2060 : }
2061 118 : RA_PTHREAD_MUTEX_LOCK(&gHdcInitPara.mutex);
2062 118 : gHdcInitPara.connectStatus = HDC_CONNECTED;
2063 118 : RA_PTHREAD_MUTEX_UNLOCK(&gHdcInitPara.mutex);
2064 : }
2065 : }
2066 :
2067 121 : STATIC void RaHwHdcDeinit(void)
2068 : {
2069 121 : unsigned int chipId = gHdcInitPara.chipId;
2070 : int ret, tryAgain;
2071 :
2072 121 : RA_PTHREAD_MUTEX_LOCK(&gHdcInitPara.mutex);
2073 121 : gHdcInitPara.threadStatus = THREAD_DESTROYING;
2074 121 : RA_PTHREAD_MUTEX_UNLOCK(&gHdcInitPara.mutex);
2075 :
2076 121 : tryAgain = HDC_TRY_TIME;
2077 839 : while ((gHdcInitPara.threadStatus != THREAD_HALT) && tryAgain != 0) {
2078 718 : usleep(HDC_USLEEP_TIME);
2079 718 : tryAgain--;
2080 : }
2081 121 : if (tryAgain == 0) {
2082 3 : hccp_warn("hdc message thread quit timeout, chipId:%u", chipId);
2083 : }
2084 :
2085 121 : if (gHdcServer[chipId].hdcServer != NULL) {
2086 0 : ret = RA_HDC_OPS.serverDestroy(gHdcServer[chipId].hdcServer);
2087 0 : if (ret != 0) {
2088 0 : hccp_warn("RA_HDC_OPS.server_destroy unsuccessful, ret:%d, chipId:%u", ret, chipId);
2089 : }
2090 0 : gHdcServer[chipId].hdcServer = NULL;
2091 : } else {
2092 121 : hccp_warn("hdc_server is NULL, chipId:%u", chipId);
2093 : }
2094 121 : pthread_mutex_destroy(&gHdcInitPara.mutex);
2095 121 : }
2096 :
2097 124 : STATIC int HccpSetAffinity(unsigned int chipId)
2098 : {
2099 124 : unsigned int phyDevid = chipId;
2100 : int64_t cpuCoreNum;
2101 : int64_t ccpuNum; /* ctrl cpu */
2102 : int64_t dcpuNum; /* data cpu */
2103 : int64_t acpuNum; /* ai cpu */
2104 : cpu_set_t mask;
2105 : int64_t cpuId;
2106 : int ret;
2107 :
2108 124 : ret = DlHalGetDeviceInfo(chipId, MODULE_TYPE_CCPU, INFO_TYPE_CORE_NUM, &ccpuNum);
2109 124 : CHK_PRT_RETURN(ret, hccp_err("get ccpu_num failed, ret(%d)", ret), ret);
2110 :
2111 124 : ret = DlHalGetDeviceInfo(chipId, MODULE_TYPE_DCPU, INFO_TYPE_CORE_NUM, &dcpuNum);
2112 124 : CHK_PRT_RETURN(ret, hccp_err("get dcpu_num failed, ret(%d)", ret), ret);
2113 :
2114 124 : ret = DlHalGetDeviceInfo(chipId, MODULE_TYPE_AICPU, INFO_TYPE_CORE_NUM, &acpuNum);
2115 124 : CHK_PRT_RETURN(ret, hccp_err("get acpu_num failed, ret(%d)", ret), ret);
2116 124 : cpuCoreNum = ccpuNum + dcpuNum + acpuNum;
2117 :
2118 124 : ret = DlHalGetPhyDevIdByudevId(chipId, &phyDevid);
2119 124 : CHK_PRT_RETURN(ret != 0, hccp_err("DlHalGetPhyDevIdByudevId failed, ret(%d) chipId:%u", ret, chipId), ret);
2120 124 : CPU_ZERO(&mask);
2121 124 : cpuId = cpuCoreNum * phyDevid + HCCP_RUN_CPU_CORE;
2122 : /*lint -e574*/
2123 124 : CPU_SET((size_t)cpuId, &mask); // lint !e573
2124 : /*lint +e574*/
2125 124 : hccp_run_info("chipId:%u phyDevid:%u ccpuNum:%lld, dcpuNum:%lld, acpuNum:%lld, cpuId:%lld", chipId, phyDevid,
2126 : ccpuNum, dcpuNum, acpuNum, cpuId);
2127 124 : ret = sched_setaffinity(getpid(), sizeof(mask), &mask); /* hccp use core0 of each chip to setaffinity */
2128 124 : CHK_PRT_RETURN(ret == -1,
2129 : hccp_err("sched_setaffinity failed: ret %d, errno %d chipId:%u phyDevid:%u", ret, errno, chipId, phyDevid),
2130 : -ESYSFUNC);
2131 :
2132 123 : return 0;
2133 : }
2134 :
2135 121 : STATIC int RaHwInit(unsigned int chipId, pid_t pid)
2136 : {
2137 : int ret;
2138 : pthread_t tidp;
2139 121 : int timeout = RA_THREAD_TRY_TIME;
2140 :
2141 121 : gHdcInitPara.chipId = chipId;
2142 121 : gHdcInitPara.hostTgid = pid;
2143 :
2144 121 : ret = pthread_create(&tidp, NULL, (void *)RaHwHdcInit, NULL);
2145 121 : CHK_PRT_RETURN(ret, hccp_err("Create pthread failed, ret(%d) ", ret), -ESYSFUNC);
2146 :
2147 10388 : while (gHdcInitPara.hdcFlag != 1 && timeout > 0) {
2148 10268 : usleep(RA_THREAD_SLEEP_TIME);
2149 10268 : timeout--;
2150 : }
2151 :
2152 120 : CHK_PRT_RETURN(gHdcInitPara.hdcFlag == 0 || timeout == 0,
2153 : hccp_err("HDC server thread create timeout,"
2154 : "flag %d, timeout %d",
2155 : gHdcInitPara.hdcFlag, timeout),
2156 : -ESRCH);
2157 :
2158 118 : return 0;
2159 : }
2160 :
2161 124 : RA_ADP_ATTRI_VISI_DEF int HccpInit(unsigned int chipId, pid_t pid, int hdcType, unsigned int whiteListStatus)
2162 : {
2163 : struct timeval start, end;
2164 124 : float timeCost = 0.0;
2165 : int ret, retTmp;
2166 :
2167 124 : hccp_info("hccp[%u] hdc_type[%d] white_list_status[%u] init start", chipId, hdcType, whiteListStatus);
2168 :
2169 124 : ret = DlHalInit();
2170 124 : if (ret != 0) {
2171 0 : hccp_err("dl_hal_init failed, ret = %d", ret);
2172 0 : return ret;
2173 : }
2174 :
2175 124 : ret = HccpSetAffinity(chipId);
2176 124 : if (ret != 0) {
2177 1 : hccp_err("hccp_set_affinity failed, ret(%d) ", ret);
2178 1 : goto out;
2179 : }
2180 :
2181 123 : RsGetCurTime(&start);
2182 123 : ret = RaHdcServerInit(chipId, hdcType);
2183 123 : if (ret != 0) {
2184 2 : hccp_err("chip_id[%u] hdc_type[%d] ra_hdc_server_init failed, ret[%d] ", chipId, hdcType, ret);
2185 2 : goto out;
2186 : }
2187 :
2188 121 : ret = pthread_mutex_init(&gHdcInitPara.mutex, NULL);
2189 121 : if (ret != 0) {
2190 0 : hccp_err("g_hdc_init_para mutex_init failed ret %d!, normal ret 0", ret);
2191 0 : ret = -ESYSFUNC;
2192 0 : goto out;
2193 : }
2194 :
2195 121 : ret = RaHwInit(chipId, pid);
2196 121 : if (ret != 0) {
2197 3 : hccp_err("ra_init failed, ret(%d) ", ret);
2198 3 : goto hw_init_err;
2199 : }
2200 :
2201 118 : ret = RaHwAsyncInit(chipId, pid);
2202 118 : if (ret != 0) {
2203 0 : hccp_err("ra_hw_async_init failed, ret(%d) ", ret);
2204 0 : goto hw_init_err;
2205 : }
2206 :
2207 118 : RsGetCurTime(&end);
2208 118 : HccpTimeInterval(&end, &start, &timeCost);
2209 118 : hccp_info("ra_hw_init ok cost [%f] ms", timeCost);
2210 :
2211 118 : struct RsInitConfig offlineConfig = {
2212 : .chipId = chipId,
2213 : .hccpMode = NETWORK_OFFLINE,
2214 : .whiteListStatus = whiteListStatus,
2215 : };
2216 :
2217 118 : RsGetCurTime(&start);
2218 118 : ret = RsInit(&offlineConfig);
2219 118 : if (ret != 0) {
2220 0 : hccp_err("rs_init failed (0x%x) ", ret);
2221 0 : goto init_err;
2222 : }
2223 118 : RsGetCurTime(&end);
2224 118 : HccpTimeInterval(&end, &start, &timeCost);
2225 118 : hccp_info("rs_init ok cost [%f] ms", timeCost);
2226 :
2227 118 : RsGetCurTime(&start);
2228 118 : ret = RsBindHostpid(chipId, pid);
2229 118 : if (ret != 0) {
2230 0 : hccp_err("rs_bind_hostpid failed, ret=%d ", ret);
2231 0 : goto bind_hostpid_err;
2232 : }
2233 118 : RsGetCurTime(&end);
2234 118 : HccpTimeInterval(&end, &start, &timeCost);
2235 118 : hccp_info("rs_bind_hostpid ok cost [%f] ms", timeCost);
2236 :
2237 118 : RsGetCurTime(&start);
2238 118 : ret = RsPingHandleInit(chipId, hdcType, whiteListStatus);
2239 118 : if (ret != 0) {
2240 0 : hccp_err("rs_ping_handle_init failed, ret=%d ", ret);
2241 0 : goto bind_hostpid_err;
2242 : }
2243 118 : RsGetCurTime(&end);
2244 118 : HccpTimeInterval(&end, &start, &timeCost);
2245 118 : hccp_info("rs_ping_handle_init ok cost [%f] ms", timeCost);
2246 :
2247 118 : return 0;
2248 0 : bind_hostpid_err:
2249 0 : retTmp = RsDeinit(&offlineConfig);
2250 0 : if (retTmp) {
2251 0 : hccp_err("rs_deinit failed %d ", retTmp);
2252 : }
2253 0 : init_err:
2254 0 : RaHwAsyncDeinit();
2255 3 : hw_init_err:
2256 3 : pthread_mutex_destroy(&gHdcInitPara.mutex);
2257 6 : out:
2258 6 : DlHalDeinit();
2259 6 : return ret;
2260 : }
2261 :
2262 122 : RA_ADP_ATTRI_VISI_DEF int HccpDeinit(unsigned int chipId)
2263 : {
2264 122 : struct RsInitConfig offlineConfig = {
2265 : .chipId = chipId,
2266 : .hccpMode = NETWORK_OFFLINE,
2267 : .whiteListStatus = WHITE_LIST_ENABLE,
2268 : };
2269 : int ret;
2270 :
2271 122 : hccp_info("hccp[%u] deinit start", chipId);
2272 :
2273 122 : ret = RsPingHandleDeinit(chipId);
2274 122 : CHK_PRT_RETURN(ret, hccp_err("rs_ping_handle_deinit failed %d ", ret), ret);
2275 :
2276 122 : ret = RsDeinit(&offlineConfig);
2277 122 : CHK_PRT_RETURN(ret, hccp_err("rs_deinit failed %d ", ret), ret);
2278 :
2279 121 : RaHwHdcDeinit();
2280 :
2281 121 : RaHwAsyncDeinit();
2282 121 : DlHalDeinit();
2283 121 : hccp_info("hccp [%u] deinit success", chipId);
2284 :
2285 121 : return ret;
2286 : }
|