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 238 : STATIC void MsgHeadBuildUpHw(char *pSendRcvBuf, struct MsgHead *recvMsgHead, int ret,
169 : unsigned int msgDataLen)
170 : {
171 238 : struct MsgHead *pSendRcvHead = NULL;
172 :
173 238 : pSendRcvHead = (struct MsgHead *)pSendRcvBuf;
174 238 : pSendRcvHead->opcode = recvMsgHead->opcode;
175 238 : pSendRcvHead->asyncReqId = recvMsgHead->asyncReqId;
176 238 : pSendRcvHead->ret = ret;
177 238 : pSendRcvHead->msgDataLen = msgDataLen;
178 :
179 238 : 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 116 : STATIC int RaRsCloseHdcSession(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
1167 : {
1168 116 : *opResult = 0;
1169 116 : hccp_info("ra_rs_close_hdc_session finish");
1170 116 : 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 239 : 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 239 : if (endTime->tv_usec < startTime->tv_usec) {
1463 0 : endTime->tv_sec -= 1;
1464 0 : endTime->tv_usec += US_PRE_SECOND;
1465 : }
1466 :
1467 239 : *msec = (endTime->tv_sec - startTime->tv_sec) * MS_PRE_SECOND +
1468 239 : (endTime->tv_usec - startTime->tv_usec) / US_PRE_MSECOND;
1469 239 : }
1470 :
1471 : #define OP_TYPE_CFG 0
1472 : #define OP_TYPE_QUERY 1
1473 :
1474 239 : STATIC void RaGetOpRight(struct RaHdcOpSec *opSec, unsigned int opcode, unsigned int asyncReqId, int *right)
1475 : {
1476 239 : long timeInterval = 0;
1477 : struct timeval tCur;
1478 : int exeRight;
1479 : int ret;
1480 :
1481 239 : ret = gettimeofday(&tCur, NULL);
1482 239 : 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 239 : RaTimeInterval(&tCur, &opSec->tLast, &timeInterval);
1489 239 : opSec->tLast = (timeInterval < 0) ? tCur : opSec->tLast;
1490 239 : timeInterval = (timeInterval < 0) ? 0 : timeInterval;
1491 239 : opSec->tLast = (timeInterval == 0) ? opSec->tLast : tCur;
1492 239 : opSec->tokenNum += timeInterval * TOKEN_RATE;
1493 :
1494 239 : 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 239 : exeRight = HAVE_OP_RIGHT;
1501 :
1502 239 : opSec->tokenNum = opSec->tokenNum - 1;
1503 239 : opSec->tokenNum = (opSec->tokenNum > BUCKET_DEPTH) ? BUCKET_DEPTH : opSec->tokenNum;
1504 239 : 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 237 : } else if (RaIsOpcodeLogSuppressed(opcode)) {
1508 2 : goto out;
1509 : }
1510 :
1511 237 : 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 236 : hccp_dbg("opcode[%u], exeRight[%d], tokenNum[%llu], cfgOpNum[%u]",
1516 : opcode, exeRight, opSec->tokenNum, opSec->cfgOpNum);
1517 : }
1518 :
1519 239 : out:
1520 239 : opSec->lastOpcodeCnt = (opcode == opSec->lastOpcode) ? (opSec->lastOpcodeCnt + 1) :
1521 235 : (RaIsOpcodeLogSuppressed(opcode) ? 1 : 0);
1522 239 : opSec->lastOpcode = opcode;
1523 239 : *right = exeRight;
1524 239 : 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_GET_TLS_ENABLE, RaRsGetTlsEnable, sizeof(union OpGetTlsEnableData)},
1614 : {RA_RS_GET_SEC_RANDOM, RaRsGetSecRandom, sizeof(union OpGetSecRandomData)},
1615 : {RA_RS_GET_HCCN_CFG, RaRsGetHccnCfg, sizeof(union OpGetHccnCfgData)},
1616 : {RA_RS_ASYNC_HDC_SESSION_CONNECT, RaRsAsyncHdcSessionConnect, sizeof(union OpAsyncHdcConnectData)},
1617 : {RA_RS_ASYNC_HDC_SESSION_CLOSE, RaRsAsyncHdcSessionClose, sizeof(union OpAsyncHdcCloseData)},
1618 : {RA_RS_GET_DEV_EID_INFO_NUM, RaRsGetDevEidInfoNum, sizeof(union OpGetDevEidInfoNumData)},
1619 : {RA_RS_GET_DEV_EID_INFO_LIST, RaRsGetDevEidInfoList, sizeof(union OpGetDevEidInfoListData)},
1620 : {RA_RS_CTX_INIT, RaRsCtxInit, sizeof(union OpCtxInitData)},
1621 : {RA_RS_CTX_GET_ASYNC_EVENTS, RaRsCtxGetAsyncEvents, sizeof(union OpCtxGetAsyncEventsData)},
1622 : {RA_RS_CTX_DEINIT, RaRsCtxDeinit, sizeof(union OpCtxDeinitData)},
1623 : {RA_RS_GET_EID_BY_IP, RaRsGetEidByIp, sizeof(union OpGetEidByIpData)},
1624 : {RA_RS_GET_TP_INFO_LIST, RaRsGetTpInfoList, sizeof(union OpGetTpInfoListData)},
1625 : {RA_RS_GET_TP_ATTR, RaRsGetTpAttr, sizeof(union OpGetTpAttrData)},
1626 : {RA_RS_SET_TP_ATTR, RaRsSetTpAttr, sizeof(union OpSetTpAttrData)},
1627 : {RA_RS_CTX_TOKEN_ID_ALLOC, RaRsCtxTokenIdAlloc, sizeof(union OpTokenIdAllocData)},
1628 : {RA_RS_CTX_TOKEN_ID_FREE, RaRsCtxTokenIdFree, sizeof(union OpTokenIdFreeData)},
1629 : {RA_RS_LMEM_REG, RaRsLmemReg, sizeof(union OpLmemRegInfoData)},
1630 : {RA_RS_LMEM_UNREG, RaRsLmemUnreg, sizeof(union OpLmemUnregInfoData)},
1631 : {RA_RS_RMEM_IMPORT, RaRsRmemImport, sizeof(union OpRmemImportInfoData)},
1632 : {RA_RS_RMEM_UNIMPORT, RaRsRmemUnimport, sizeof(union OpRmemUnimportInfoData)},
1633 : {RA_RS_CTX_CHAN_CREATE, RaRsCtxChanCreate, sizeof(union OpCtxChanCreateData)},
1634 : {RA_RS_CTX_CHAN_DESTROY, RaRsCtxChanDestroy, sizeof(union OpCtxChanDestroyData)},
1635 : {RA_RS_CTX_CQ_CREATE, RaRsCtxCqCreate, sizeof(union OpCtxCqCreateData)},
1636 : {RA_RS_CTX_CQ_DESTROY, RaRsCtxCqDestroy, sizeof(union OpCtxCqDestroyData)},
1637 : {RA_RS_CTX_QP_CREATE, RaRsCtxQpCreate, sizeof(union OpCtxQpCreateData)},
1638 : {RA_RS_CTX_QUERY_QP_BATCH, RaRsCtxQpQueryBatch, sizeof(union OpCtxQpQueryBatchData)},
1639 : {RA_RS_CTX_QP_DESTROY, RaRsCtxQpDestroy, sizeof(union OpCtxQpDestroyData)},
1640 : {RA_RS_CTX_QP_DESTROY_BATCH, RaRsCtxQpDestroyBatch, sizeof(union OpCtxQpDestroyBatchData)},
1641 : {RA_RS_CTX_QP_IMPORT, RaRsCtxQpImport, sizeof(union OpCtxQpImportData)},
1642 : {RA_RS_CTX_QP_UNIMPORT, RaRsCtxQpUnimport, sizeof(union OpCtxQpUnimportData)},
1643 : {RA_RS_CTX_QP_BIND, RaRsCtxQpBind, sizeof(union OpCtxQpBindData)},
1644 : {RA_RS_CTX_QP_UNBIND, RaRsCtxQpUnbind, sizeof(union OpCtxQpUnbindData)},
1645 : {RA_RS_CTX_BATCH_SEND_WR, RaRsCtxBatchSendWr, sizeof(union OpCtxBatchSendWrData)},
1646 : {RA_RS_CTX_UPDATE_CI, RaRsCtxUpdateCi, sizeof(union OpCtxUpdateCiData)},
1647 : {RA_RS_CTX_GET_AUX_INFO, RaRsCtxGetAuxInfo, sizeof(union OpCtxGetAuxInfoData)},
1648 : {RA_RS_CTX_GET_CR_ERR_INFO_LIST, RaRsCtxGetCrErrInfoList, sizeof(union OpCtxGetCrErrInfoListData)},
1649 : {RA_RS_CTX_GET_UB_CONTEXT, RaRsCtxGetUbContext, sizeof(union OpCtxGetContextData)},
1650 : };
1651 :
1652 239 : STATIC int RaCheckParam(char *recvBuf, int rcvBufLen, char **sendBuf, int *sndBufLen, int *paramCheckResult)
1653 : {
1654 : int i;
1655 239 : int ret = 0;
1656 239 : struct MsgHead *recvMsgHead = (struct MsgHead *)recvBuf;
1657 239 : int num = sizeof(gRaOpHandle) / sizeof(gRaOpHandle[0]);
1658 239 : unsigned int dataSize = 0;
1659 :
1660 239 : *paramCheckResult = 1;
1661 239 : if (rcvBufLen < (int)sizeof(struct MsgHead)) { // check rcv_buf_len
1662 0 : hccp_err("rcv_buf_len[%d] form ra is invalid", rcvBufLen);
1663 0 : ret = OpMsgErr(sendBuf, recvMsgHead, sndBufLen, RECV_BUF_LEN_INVALID);
1664 0 : return ret;
1665 : }
1666 :
1667 239 : if (((recvMsgHead->msgDataLen + sizeof(struct MsgHead)) != (unsigned int)rcvBufLen) ||
1668 239 : (recvMsgHead->opcode >= RA_RS_OP_MAX_NUM ||
1669 239 : ((recvMsgHead->opcode < RA_RS_HDC_SESSION_CLOSE) && (recvMsgHead->opcode >= RA_RS_EXTER_OP_MAX_NUM)))) {
1670 0 : hccp_err("rcv data incomplete, because rcvBufLen[%d] != msg_head_len[%u] + msgDataLen[%u] \
1671 : or opcode[%u] is wrong, RA_RS_OP_MAX_NUM:[%d], RA_RS_EXTER_OP_MAX_NUM:[%d]",
1672 : rcvBufLen, sizeof(struct MsgHead), recvMsgHead->msgDataLen, recvMsgHead->opcode,
1673 : RA_RS_OP_MAX_NUM, RA_RS_EXTER_OP_MAX_NUM);
1674 0 : ret = OpMsgErr(sendBuf, recvMsgHead, sndBufLen, HAVE_OP_RIGHT);
1675 0 : return ret;
1676 : }
1677 13115 : for (i = 0; i < num; i++) {
1678 13115 : if (gRaOpHandle[i].opcode == recvMsgHead->opcode) {
1679 239 : dataSize = gRaOpHandle[i].dataSize;
1680 239 : break;
1681 : }
1682 : }
1683 239 : if (recvMsgHead->opcode != RA_RS_SOCKET_RECV && recvMsgHead->msgDataLen != dataSize) {
1684 0 : hccp_err("rcv data incomplete. because msg_data_len[%d] != op_data_len[%u]",
1685 : recvMsgHead->msgDataLen, dataSize);
1686 0 : ret = OpMsgErr(sendBuf, recvMsgHead, sndBufLen, RECV_BUF_LEN_INVALID);
1687 0 : return ret;
1688 : }
1689 239 : *paramCheckResult = 0;
1690 239 : return ret;
1691 : }
1692 :
1693 239 : int RaHandle(struct RaHdcOpSec *opSec, char *recvBuf, int rcvBufLen, char **sendBuf, int *sndBufLen,
1694 : unsigned int *closeSession)
1695 : {
1696 : int i;
1697 : int ret;
1698 239 : int opRight = 0;
1699 239 : int paramCheckRet = 0;
1700 239 : int opRet = 0;
1701 239 : struct MsgHead *recvMsgHead = (struct MsgHead *)recvBuf;
1702 239 : int num = sizeof(gRaOpHandle) / sizeof(gRaOpHandle[0]);
1703 :
1704 239 : ret = RaCheckParam(recvBuf, rcvBufLen, sendBuf, sndBufLen, ¶mCheckRet);
1705 239 : CHK_PRT_RETURN(paramCheckRet != 0 || ret != 0, hccp_err("ra param check failed. param check ret:[%d]"
1706 : "function call ret:[%d]", paramCheckRet, ret), ret);
1707 :
1708 239 : RaGetOpRight(opSec, recvMsgHead->opcode, recvMsgHead->asyncReqId, &opRight);
1709 239 : CHK_PRT_RETURN(opRight != HAVE_OP_RIGHT, ret = OpMsgErr(sendBuf, recvMsgHead, sndBufLen, opRight), ret);
1710 :
1711 239 : *sendBuf = (char *)calloc(sizeof(char), recvMsgHead->msgDataLen + sizeof(struct MsgHead));
1712 239 : CHK_PRT_RETURN(*sendBuf == NULL, hccp_err("calloc failed."), -ENOMEM);
1713 :
1714 13115 : for (i = 0; i < num; i++) {
1715 13115 : if (gRaOpHandle[i].opcode == recvMsgHead->opcode) {
1716 239 : ret = gRaOpHandle[i].opHandle(recvBuf, *sendBuf, sndBufLen, &opRet, rcvBufLen);
1717 239 : if (ret) {
1718 1 : hccp_err("ra handle failed. ret:[%d]", ret);
1719 1 : goto out;
1720 : }
1721 238 : MsgHeadBuildUpHw(*sendBuf, recvMsgHead, opRet, recvMsgHead->msgDataLen);
1722 238 : *closeSession = recvMsgHead->opcode == RA_RS_HDC_SESSION_CLOSE ? 1 : 0;
1723 238 : *sndBufLen = recvMsgHead->msgDataLen + sizeof(struct MsgHead);
1724 238 : return ret;
1725 : }
1726 : }
1727 :
1728 0 : hccp_warn("not support opcode:%d", recvMsgHead->opcode);
1729 0 : ret = -EPROTONOSUPPORT;
1730 1 : out:
1731 1 : free(*sendBuf);
1732 1 : *sendBuf = NULL;
1733 1 : return ret;
1734 : }
1735 :
1736 237 : STATIC int RaSendPkt(struct drvHdcMsg *msgRcv, HDC_SESSION session, void *sendBuf, int sndBufLen)
1737 : {
1738 : int ret;
1739 237 : struct drvHdcMsg *msgSnd = NULL;
1740 :
1741 237 : ret = RA_HDC_OPS.reuseMsg(msgRcv);
1742 237 : CHK_PRT_RETURN(ret, hccp_err("reuse msg failed ret %d", ret), ret);
1743 :
1744 237 : msgSnd = msgRcv;
1745 :
1746 237 : ret = RA_HDC_OPS.addMsgBuffer(msgSnd, sendBuf, sndBufLen);
1747 237 : CHK_PRT_RETURN(ret, hccp_err("add msg buffer failed ret %d", ret), ret);
1748 :
1749 237 : ret = RA_HDC_OPS.send(session, msgSnd, 0, RA_HDC_RECV_SEND_TIMEOUT);
1750 237 : CHK_PRT_RETURN(ret, hccp_err("send msg failed ret %d", ret), ret);
1751 :
1752 237 : return 0;
1753 : }
1754 :
1755 239 : STATIC int RecvHandleSendPkt(HDC_SESSION session, unsigned int *closeSession, unsigned int chipId)
1756 : {
1757 : int ret;
1758 239 : void *recvBuf = NULL;
1759 239 : void *sendBuf = NULL;
1760 239 : struct drvHdcMsg *msgRcv = NULL;
1761 : int recvBufCnt, sndBufLen, rcvBufLen;
1762 239 : RsSetCtx(chipId);
1763 239 : ret = RA_HDC_OPS.allocMsg(session, &msgRcv, 1);
1764 239 : CHK_PRT_RETURN(ret, hccp_err("alloc hdc msg failed ret %d", ret), ret);
1765 :
1766 239 : ret = RA_HDC_OPS.recv(session, msgRcv, MAX_HDC_DATA, 0, &recvBufCnt, RA_HDC_RECV_SEND_TIMEOUT);
1767 239 : if (ret) {
1768 1 : hccp_warn("recv hdc msg unsuccessful, ret %d", ret);
1769 1 : goto out;
1770 : }
1771 :
1772 238 : RA_HDC_OPS.getMsgBuffer(msgRcv, 0, (char **)&recvBuf, &rcvBufLen);
1773 238 : if (recvBuf == NULL) {
1774 0 : hccp_warn("rcv_buf_len is NULL, Session disconnect.");
1775 0 : goto out;
1776 : }
1777 :
1778 238 : if (rcvBufLen == 0) {
1779 0 : *closeSession = 1;
1780 0 : hccp_warn("rcv_buf_len is 0, Session disconnect.");
1781 0 : RA_HDC_OPS.freeMsg(msgRcv);
1782 0 : return 0;
1783 : }
1784 :
1785 238 : ret = RaHandle(&gHdcServer[chipId].opSec, recvBuf, rcvBufLen, (char **)&sendBuf, &sndBufLen,
1786 : closeSession);
1787 238 : if (ret) {
1788 1 : hccp_err("ra_handle failed.");
1789 1 : goto out;
1790 : }
1791 :
1792 237 : ret = RaSendPkt(msgRcv, session, sendBuf, sndBufLen);
1793 237 : if (ret) {
1794 0 : hccp_err("ra send pkt failed ret %d", ret);
1795 0 : goto err;
1796 : }
1797 :
1798 237 : err:
1799 237 : free(sendBuf);
1800 237 : sendBuf = NULL;
1801 239 : out:
1802 239 : RA_HDC_OPS.freeMsg(msgRcv);
1803 239 : return ret;
1804 : }
1805 :
1806 239 : STATIC void RaHdcRecvHandleSendPkt(const unsigned int chipId)
1807 : {
1808 239 : unsigned int closeSession = 0;
1809 : int ret;
1810 :
1811 239 : ret = RecvHandleSendPkt(gHdcServer[chipId].hdcSession, &closeSession, chipId);
1812 239 : if (closeSession != 0 || ret != 0) {
1813 118 : hccp_warn("recv_handle_send_pkt close_session[%u] ret[%d]", closeSession, ret);
1814 118 : RA_PTHREAD_MUTEX_LOCK(&gHdcInitPara.mutex);
1815 118 : gHdcInitPara.connectStatus = HDC_UNCONNECTED;
1816 118 : RA_PTHREAD_MUTEX_UNLOCK(&gHdcInitPara.mutex);
1817 : }
1818 :
1819 239 : return;
1820 : }
1821 :
1822 351 : STATIC void RaHwHdcCloseSession(HDC_SESSION *session)
1823 : {
1824 : int ret;
1825 :
1826 351 : RA_PTHREAD_MUTEX_LOCK(&gHdcInitPara.mutex);
1827 351 : if (session == NULL || *session == NULL) {
1828 234 : goto out;
1829 : }
1830 :
1831 117 : ret = RA_HDC_OPS.sessionClose(*session);
1832 117 : if (ret != 0) {
1833 0 : hccp_warn("RA_HDC_OPS.sessionClose unsuccessful, ret:%d", ret);
1834 : }
1835 117 : *session = NULL;
1836 :
1837 351 : out:
1838 351 : RA_PTHREAD_MUTEX_UNLOCK(&gHdcInitPara.mutex);
1839 351 : return;
1840 : }
1841 :
1842 117 : STATIC void *RaPthread(void *arg)
1843 : {
1844 117 : unsigned int chipId = gHdcInitPara.chipId;
1845 : int ret;
1846 :
1847 117 : ret = pthread_detach(pthread_self());
1848 117 : CHK_PRT_RETURN(ret, hccp_err("pthread detach failed ret %d", ret), NULL);
1849 :
1850 117 : (void)prctl(PR_SET_NAME, (unsigned long)"hccp_ra");
1851 :
1852 117 : RA_PTHREAD_MUTEX_LOCK(&gHdcInitPara.mutex);
1853 117 : gHdcInitPara.threadStatus = THREAD_RUNNING;
1854 117 : RA_PTHREAD_MUTEX_UNLOCK(&gHdcInitPara.mutex);
1855 :
1856 117 : RsGetCurTime(&gRaThreadInfo.lastCheckTime);
1857 117 : ret = strncpy_s((char *)gRaThreadInfo.pthreadName, sizeof(gRaThreadInfo.pthreadName),
1858 : "ra_thread", strlen("ra_thread"));
1859 117 : CHK_PRT_RETURN(ret, hccp_err("strncpy_s pthread name failed, ret[%d]", ret), NULL);
1860 :
1861 117 : hccp_run_info("pthread[%s] is alive!", gRaThreadInfo.pthreadName);
1862 : while (1) {
1863 1201 : if (gHdcInitPara.threadStatus == THREAD_DESTROYING) {
1864 117 : break;
1865 : }
1866 :
1867 1084 : if (gHdcInitPara.connectStatus != HDC_CONNECTED) {
1868 846 : usleep(THREAD_SLEEP_TIME);
1869 846 : continue;
1870 : }
1871 238 : RsHeartbeatAlivePrint(&gRaThreadInfo);
1872 238 : RaHdcRecvHandleSendPkt(chipId);
1873 : }
1874 :
1875 117 : hccp_info("thread [%d] is out", getpid());
1876 117 : RaHwHdcCloseSession(&gHdcServer[chipId].hdcSession);
1877 117 : RA_PTHREAD_MUTEX_LOCK(&gHdcInitPara.mutex);
1878 117 : gHdcInitPara.threadStatus = THREAD_HALT;
1879 117 : RA_PTHREAD_MUTEX_UNLOCK(&gHdcInitPara.mutex);
1880 117 : return NULL;
1881 : }
1882 :
1883 122 : STATIC int RaHdcServerInit(unsigned int chipId, int hdcType)
1884 : {
1885 : int ret;
1886 :
1887 122 : CHK_PRT_RETURN(chipId > HCCP_MAX_CHIP_ID || gHdcServer[chipId].hdcSession != NULL, hccp_err("invalid "
1888 : "chip id %u, or hdcSession is not NULL", chipId), -EINVAL);
1889 121 : CHK_PRT_RETURN(hdcType != HDC_SERVICE_TYPE_RDMA && hdcType != HDC_SERVICE_TYPE_RDMA_V2, hccp_err("invalid "
1890 : "hdc_type %d", hdcType), -EINVAL);
1891 :
1892 121 : RaHdcInitOpSec(&gHdcServer[chipId].opSec, BUCKET_DEPTH, false);
1893 :
1894 121 : ret = RA_HDC_OPS.serverCreate(chipId, hdcType, &gHdcServer[chipId].hdcServer);
1895 121 : CHK_PRT_RETURN(ret, hccp_err("Create Server failed, ret(%d) ", ret), -EINVAL);
1896 :
1897 120 : return 0;
1898 : }
1899 :
1900 239 : void RaHdcInitOpSec(struct RaHdcOpSec *opSec, unsigned long long tokenNum, bool isAsyncOp)
1901 : {
1902 239 : opSec->tokenNum = tokenNum;
1903 239 : opSec->cfgOpNum = 0;
1904 239 : opSec->tLast.tv_sec = 0;
1905 239 : opSec->tLast.tv_usec = 0;
1906 239 : opSec->isAsyncOp = isAsyncOp;
1907 239 : }
1908 :
1909 235 : int RaHdcSessionAccept(unsigned int chipId, HDC_SESSION *session, int initHostTgid)
1910 : {
1911 : int hostTgid;
1912 235 : int ret = 0;
1913 :
1914 235 : ret = RA_HDC_OPS.sessionAccept(gHdcServer[chipId].hdcServer, session);
1915 235 : if (ret != 0) {
1916 117 : hccp_warn("Session accept failed, chipId(%u), ret(%d) ", chipId, ret);
1917 117 : return ret;
1918 : }
1919 :
1920 118 : RA_HDC_OPS.setSessionReference(*session);
1921 118 : ret = DlHalHdcGetSessionAttr(*session, HDC_SESSION_ATTR_PEER_CREATE_PID, &hostTgid);
1922 118 : if (ret) {
1923 0 : hccp_err("Session get host_pid failed, chipId(%u), ret(%d)", chipId, ret);
1924 0 : goto out;
1925 : }
1926 :
1927 118 : if (hostTgid != initHostTgid) {
1928 0 : hccp_warn("host_tgid[%d] from ra not equal to the tgid[%d] from hccp_init, invalid", hostTgid, initHostTgid);
1929 0 : goto out;
1930 : }
1931 :
1932 118 : return 0;
1933 :
1934 0 : out:
1935 0 : RaHdcCloseSession(session);
1936 0 : return ret;
1937 : }
1938 :
1939 3 : int RaHdcAsyncRecvPkt(struct RaHdcAsyncInfo *asyncInfo, unsigned int chipId, void **recvBuf,
1940 : unsigned int *recvLen)
1941 : {
1942 3 : struct drvHdcMsg *msgRcv = NULL;
1943 3 : void *rcvBuf = NULL;
1944 3 : int rcvLen = 0;
1945 : int ret;
1946 :
1947 3 : ret = RA_HDC_OPS.allocMsg(asyncInfo->hdcSession, &msgRcv, 1);
1948 3 : CHK_PRT_RETURN(ret != 0, hccp_err("alloc hdc msg failed ret %d", ret), ret);
1949 :
1950 3 : ret = RA_HDC_OPS.recv(asyncInfo->hdcSession, msgRcv, MAX_HDC_DATA, 0, &rcvLen, RA_HDC_RECV_SEND_TIMEOUT);
1951 3 : if (ret != 0) {
1952 1 : hccp_warn("recv hdc msg unsuccessful ret %d", ret);
1953 1 : goto out;
1954 : }
1955 :
1956 2 : RA_HDC_OPS.getMsgBuffer(msgRcv, 0, (char **)&rcvBuf, &rcvLen);
1957 2 : if (rcvBuf == NULL || rcvLen == 0) {
1958 2 : hccp_warn("get_msg_buffer unsuccessful, rcvBuf is NULL or rcvLen:%d is 0", rcvLen);
1959 2 : goto out;
1960 : }
1961 :
1962 0 : *recvBuf = (char *)calloc(rcvLen, sizeof(char));
1963 0 : if (*recvBuf == NULL) {
1964 0 : hccp_err("calloc recv_buf failed, errno:%d rcvLen:%d", errno, rcvLen);
1965 0 : ret = -ENOMEM;
1966 0 : goto out;
1967 : }
1968 :
1969 0 : (void)memcpy_s(*recvBuf, rcvLen, rcvBuf, rcvLen);
1970 0 : *recvLen = rcvLen;
1971 :
1972 3 : out:
1973 3 : RA_HDC_OPS.freeMsg(msgRcv);
1974 3 : return ret;
1975 : }
1976 :
1977 1 : int RaHdcAsyncSendPkt(struct RaHdcAsyncInfo *asyncInfo, unsigned int chipId, void *sendBuf,
1978 : unsigned int sendLen)
1979 : {
1980 1 : struct drvHdcMsg *msgSnd = NULL;
1981 1 : int ret = -EINVAL;
1982 :
1983 1 : RA_PTHREAD_MUTEX_LOCK(&asyncInfo->sendMutex);
1984 : // degrade log level because session will be closed by recv thread and request will be abort
1985 1 : if (asyncInfo->hdcSession == NULL) {
1986 1 : hccp_warn("[async][send_pkt]hdc_session is NULL, chipId(%u)", chipId);
1987 1 : goto alloc_msg_err;
1988 : }
1989 :
1990 0 : ret = RA_HDC_OPS.allocMsg(asyncInfo->hdcSession, &msgSnd, 1);
1991 0 : if (ret != 0) {
1992 0 : hccp_err("[async][send_pkt]HDC alloc msg err ret(%d) chip_id(%u)", ret, chipId);
1993 0 : goto alloc_msg_err;
1994 : }
1995 :
1996 0 : ret = RA_HDC_OPS.addMsgBuffer(msgSnd, sendBuf, sendLen);
1997 0 : if (ret != 0) {
1998 0 : hccp_err("[async][send_pkt]HDC add msg buffer err ret(%d) chip_id(%u)", ret, chipId);
1999 0 : goto msg_err;
2000 : }
2001 :
2002 0 : ret = RA_HDC_OPS.send(asyncInfo->hdcSession, msgSnd, RA_HDC_WAIT_TIMEOUT, RA_HDC_RECV_SEND_TIMEOUT);
2003 0 : if (ret != 0) {
2004 0 : hccp_err("[async][send_pkt]HDC send err ret(%d) chip_id(%u)", ret, chipId);
2005 0 : goto msg_err;
2006 : }
2007 :
2008 0 : msg_err:
2009 0 : RA_HDC_OPS.freeMsg(msgSnd);
2010 1 : alloc_msg_err:
2011 1 : RA_PTHREAD_MUTEX_UNLOCK(&asyncInfo->sendMutex);
2012 1 : return ret;
2013 : }
2014 :
2015 1 : void RaHdcCloseSession(HDC_SESSION *session)
2016 : {
2017 1 : RA_HDC_OPS.sessionClose(*session);
2018 1 : *session = NULL;
2019 1 : return;
2020 : }
2021 :
2022 118 : STATIC void RaHwHdcInit(void *arg)
2023 : {
2024 118 : unsigned int chipId = gHdcInitPara.chipId;
2025 : pthread_t tidp;
2026 : int ret;
2027 :
2028 118 : ret = pthread_detach(pthread_self());
2029 118 : if (ret) {
2030 1 : hccp_err("pthread detach failed ret %d", ret);
2031 1 : return;
2032 : }
2033 :
2034 117 : (void)prctl(PR_SET_NAME, (unsigned long)"hccp_hw_hdc");
2035 :
2036 117 : hccp_info("chip_id(%u)", chipId);
2037 117 : gHdcInitPara.hdcFlag = 1;
2038 :
2039 117 : ret = pthread_create(&tidp, NULL, (void *)RaPthread, NULL);
2040 117 : if (ret) {
2041 0 : hccp_err("Create pthread failed, chipId(%u), ret(%d) ", chipId, ret);
2042 0 : return;
2043 : }
2044 :
2045 : while (1) {
2046 1994 : if (gHdcInitPara.connectStatus != HDC_UNCONNECTED) {
2047 1760 : usleep(HDC_ACCEPT_SLEEP_TIME);
2048 1760 : continue;
2049 : }
2050 234 : RaHwHdcCloseSession(&gHdcServer[chipId].hdcSession);
2051 234 : ret = RaHdcSessionAccept(chipId, &gHdcServer[chipId].hdcSession, (int)gHdcInitPara.hostTgid);
2052 234 : if (ret != 0) {
2053 117 : hccp_warn("Session Accept unsuccessful, chipId(%u), ret(%d) ", chipId, ret);
2054 117 : gHdcInitPara.hdcFlag = 0;
2055 117 : return;
2056 : }
2057 : // original case, should continue to accept: host_tgid != g_hdc_init_para.host_tgid
2058 117 : if (ret == 0 && gHdcServer[chipId].hdcSession == NULL) {
2059 0 : continue;
2060 : }
2061 117 : RA_PTHREAD_MUTEX_LOCK(&gHdcInitPara.mutex);
2062 117 : gHdcInitPara.connectStatus = HDC_CONNECTED;
2063 117 : RA_PTHREAD_MUTEX_UNLOCK(&gHdcInitPara.mutex);
2064 : }
2065 : }
2066 :
2067 120 : STATIC void RaHwHdcDeinit(void)
2068 : {
2069 120 : unsigned int chipId = gHdcInitPara.chipId;
2070 : int ret, tryAgain;
2071 :
2072 120 : RA_PTHREAD_MUTEX_LOCK(&gHdcInitPara.mutex);
2073 120 : gHdcInitPara.threadStatus = THREAD_DESTROYING;
2074 120 : RA_PTHREAD_MUTEX_UNLOCK(&gHdcInitPara.mutex);
2075 :
2076 120 : tryAgain = HDC_TRY_TIME;
2077 837 : while ((gHdcInitPara.threadStatus != THREAD_HALT) && tryAgain != 0) {
2078 717 : usleep(HDC_USLEEP_TIME);
2079 717 : tryAgain--;
2080 : }
2081 120 : if (tryAgain == 0) {
2082 3 : hccp_warn("hdc message thread quit timeout, chipId:%u", chipId);
2083 : }
2084 :
2085 120 : if (gHdcServer[chipId].hdcServer != NULL) {
2086 0 : ret = RA_HDC_OPS.serverDestroy(gHdcServer[chipId].hdcServer);
2087 0 : if (ret != 0) {
2088 0 : hccp_warn("RA_HDC_OPS.server_destroy unsuccessful, ret:%d, chipId:%u", ret, chipId);
2089 : }
2090 0 : gHdcServer[chipId].hdcServer = NULL;
2091 : } else {
2092 120 : hccp_warn("hdc_server is NULL, chipId:%u", chipId);
2093 : }
2094 120 : pthread_mutex_destroy(&gHdcInitPara.mutex);
2095 120 : }
2096 :
2097 123 : STATIC int HccpSetAffinity(unsigned int chipId)
2098 : {
2099 123 : unsigned int phyDevid = chipId;
2100 : int64_t cpuCoreNum;
2101 : int64_t ccpuNum; /* ctrl cpu */
2102 : int64_t dcpuNum; /* data cpu */
2103 : int64_t acpuNum; /* ai cpu */
2104 : cpu_set_t mask;
2105 : int64_t cpuId;
2106 : int ret;
2107 :
2108 123 : ret = DlHalGetDeviceInfo(chipId, MODULE_TYPE_CCPU, INFO_TYPE_CORE_NUM, &ccpuNum);
2109 123 : CHK_PRT_RETURN(ret, hccp_err("get ccpu_num failed, ret(%d)", ret), ret);
2110 :
2111 123 : ret = DlHalGetDeviceInfo(chipId, MODULE_TYPE_DCPU, INFO_TYPE_CORE_NUM, &dcpuNum);
2112 123 : CHK_PRT_RETURN(ret, hccp_err("get dcpu_num failed, ret(%d)", ret), ret);
2113 :
2114 123 : ret = DlHalGetDeviceInfo(chipId, MODULE_TYPE_AICPU, INFO_TYPE_CORE_NUM, &acpuNum);
2115 123 : CHK_PRT_RETURN(ret, hccp_err("get acpu_num failed, ret(%d)", ret), ret);
2116 123 : cpuCoreNum = ccpuNum + dcpuNum + acpuNum;
2117 :
2118 123 : ret = DlHalGetPhyDevIdByudevId(chipId, &phyDevid);
2119 123 : CHK_PRT_RETURN(ret != 0, hccp_err("DlHalGetPhyDevIdByudevId failed, ret(%d) chipId:%u", ret, chipId), ret);
2120 123 : CPU_ZERO(&mask);
2121 123 : cpuId = cpuCoreNum * phyDevid + HCCP_RUN_CPU_CORE;
2122 : /*lint -e574*/
2123 123 : CPU_SET((size_t)cpuId, &mask); //lint !e573
2124 : /*lint +e574*/
2125 123 : hccp_run_info("chipId:%u phyDevid:%u ccpuNum:%lld, dcpuNum:%lld, acpuNum:%lld, cpuId:%lld",
2126 : chipId, phyDevid, ccpuNum, dcpuNum, acpuNum, cpuId);
2127 123 : ret = sched_setaffinity(getpid(), sizeof(mask), &mask); /* hccp use core0 of each chip to setaffinity */
2128 123 : CHK_PRT_RETURN(ret == -1, hccp_err("sched_setaffinity failed: ret %d, errno %d chipId:%u phyDevid:%u",
2129 : ret, errno, chipId, phyDevid), -ESYSFUNC);
2130 :
2131 122 : return 0;
2132 : }
2133 :
2134 120 : STATIC int RaHwInit(unsigned int chipId, pid_t pid)
2135 : {
2136 : int ret;
2137 : pthread_t tidp;
2138 120 : int timeout = RA_THREAD_TRY_TIME;
2139 :
2140 120 : gHdcInitPara.chipId = chipId;
2141 120 : gHdcInitPara.hostTgid = pid;
2142 :
2143 120 : ret = pthread_create(&tidp, NULL, (void *)RaHwHdcInit, NULL);
2144 120 : CHK_PRT_RETURN(ret, hccp_err("Create pthread failed, ret(%d) ", ret), -ESYSFUNC);
2145 :
2146 10240 : while (gHdcInitPara.hdcFlag != 1 && timeout > 0) {
2147 10121 : usleep(RA_THREAD_SLEEP_TIME);
2148 10121 : timeout--;
2149 : }
2150 :
2151 119 : CHK_PRT_RETURN(gHdcInitPara.hdcFlag == 0 || timeout == 0, hccp_err("HDC server thread create timeout,"
2152 : "flag %d, timeout %d", gHdcInitPara.hdcFlag, timeout), -ESRCH);
2153 :
2154 117 : return 0;
2155 : }
2156 :
2157 123 : RA_ADP_ATTRI_VISI_DEF int HccpInit(unsigned int chipId, pid_t pid, int hdcType, unsigned int whiteListStatus)
2158 : {
2159 : struct timeval start, end;
2160 123 : float timeCost = 0.0;
2161 : int ret, retTmp;
2162 :
2163 123 : hccp_info("hccp[%u] hdc_type[%d] white_list_status[%u] init start", chipId, hdcType, whiteListStatus);
2164 :
2165 123 : ret = DlHalInit();
2166 123 : if (ret != 0) {
2167 0 : hccp_err("dl_hal_init failed, ret = %d", ret);
2168 0 : return ret;
2169 : }
2170 :
2171 123 : ret = HccpSetAffinity(chipId);
2172 123 : if (ret != 0) {
2173 1 : hccp_err("hccp_set_affinity failed, ret(%d) ", ret);
2174 1 : goto out;
2175 : }
2176 :
2177 122 : RsGetCurTime(&start);
2178 122 : ret = RaHdcServerInit(chipId, hdcType);
2179 122 : if (ret != 0) {
2180 2 : hccp_err("chip_id[%u] hdc_type[%d] ra_hdc_server_init failed, ret[%d] ", chipId, hdcType, ret);
2181 2 : goto out;
2182 : }
2183 :
2184 120 : ret = pthread_mutex_init(&gHdcInitPara.mutex, NULL);
2185 120 : if (ret != 0) {
2186 0 : hccp_err("g_hdc_init_para mutex_init failed ret %d!, normal ret 0", ret);
2187 0 : ret = -ESYSFUNC;
2188 0 : goto out;
2189 : }
2190 :
2191 120 : ret = RaHwInit(chipId, pid);
2192 120 : if (ret != 0) {
2193 3 : hccp_err("ra_init failed, ret(%d) ", ret);
2194 3 : goto hw_init_err;
2195 : }
2196 :
2197 117 : ret = RaHwAsyncInit(chipId, pid);
2198 117 : if (ret != 0) {
2199 0 : hccp_err("ra_hw_async_init failed, ret(%d) ", ret);
2200 0 : goto hw_init_err;
2201 : }
2202 :
2203 117 : RsGetCurTime(&end);
2204 117 : HccpTimeInterval(&end, &start, &timeCost);
2205 117 : hccp_info("ra_hw_init ok cost [%f] ms", timeCost);
2206 :
2207 117 : struct RsInitConfig offlineConfig = {
2208 : .chipId = chipId,
2209 : .hccpMode = NETWORK_OFFLINE,
2210 : .whiteListStatus = whiteListStatus,
2211 : };
2212 :
2213 117 : RsGetCurTime(&start);
2214 117 : ret = RsInit(&offlineConfig);
2215 117 : if (ret != 0) {
2216 0 : hccp_err("rs_init failed (0x%x) ", ret);
2217 0 : goto init_err;
2218 : }
2219 117 : RsGetCurTime(&end);
2220 117 : HccpTimeInterval(&end, &start, &timeCost);
2221 117 : hccp_info("rs_init ok cost [%f] ms", timeCost);
2222 :
2223 117 : RsGetCurTime(&start);
2224 117 : ret = RsBindHostpid(chipId, pid);
2225 117 : if (ret != 0) {
2226 0 : hccp_err("rs_bind_hostpid failed, ret=%d ", ret);
2227 0 : goto bind_hostpid_err;
2228 : }
2229 117 : RsGetCurTime(&end);
2230 117 : HccpTimeInterval(&end, &start, &timeCost);
2231 117 : hccp_info("rs_bind_hostpid ok cost [%f] ms", timeCost);
2232 :
2233 117 : RsGetCurTime(&start);
2234 117 : ret = RsPingHandleInit(chipId, hdcType, whiteListStatus);
2235 117 : if (ret != 0) {
2236 0 : hccp_err("rs_ping_handle_init failed, ret=%d ", ret);
2237 0 : goto bind_hostpid_err;
2238 : }
2239 117 : RsGetCurTime(&end);
2240 117 : HccpTimeInterval(&end, &start, &timeCost);
2241 117 : hccp_info("rs_ping_handle_init ok cost [%f] ms", timeCost);
2242 :
2243 117 : return 0;
2244 0 : bind_hostpid_err:
2245 0 : retTmp = RsDeinit(&offlineConfig);
2246 0 : if (retTmp) {
2247 0 : hccp_err("rs_deinit failed %d ", retTmp);
2248 : }
2249 0 : init_err:
2250 0 : RaHwAsyncDeinit();
2251 3 : hw_init_err:
2252 3 : pthread_mutex_destroy(&gHdcInitPara.mutex);
2253 6 : out:
2254 6 : DlHalDeinit();
2255 6 : return ret;
2256 : }
2257 :
2258 121 : RA_ADP_ATTRI_VISI_DEF int HccpDeinit(unsigned int chipId)
2259 : {
2260 121 : struct RsInitConfig offlineConfig = {
2261 : .chipId = chipId,
2262 : .hccpMode = NETWORK_OFFLINE,
2263 : .whiteListStatus = WHITE_LIST_ENABLE,
2264 : };
2265 : int ret;
2266 :
2267 121 : hccp_info("hccp[%u] deinit start", chipId);
2268 :
2269 121 : ret = RsPingHandleDeinit(chipId);
2270 121 : CHK_PRT_RETURN(ret, hccp_err("rs_ping_handle_deinit failed %d ", ret), ret);
2271 :
2272 121 : ret = RsDeinit(&offlineConfig);
2273 121 : CHK_PRT_RETURN(ret, hccp_err("rs_deinit failed %d ", ret), ret);
2274 :
2275 120 : RaHwHdcDeinit();
2276 :
2277 120 : RaHwAsyncDeinit();
2278 120 : DlHalDeinit();
2279 120 : hccp_info("hccp [%u] deinit success", chipId);
2280 :
2281 120 : return ret;
2282 : }
|