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