LCOV - code coverage report
Current view: top level - base_comm/resources/hccp/rdma_agent/client - ra_host.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 94.2 % 1078 1015
Test Date: 2026-07-28 12:11:00 Functions: 96.3 % 81 78

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : 
      11              : #include <sys/epoll.h>
      12              : #include <stdlib.h>
      13              : #include <string.h>
      14              : #include <dlfcn.h>
      15              : #include "securec.h"
      16              : #include "hccp.h"
      17              : #include "ra_client_host.h"
      18              : #include "ra.h"
      19              : #include "ra_init.h"
      20              : #include "ra_rdma.h"
      21              : #include "ra_hdc.h"
      22              : #include "ra_hdc_rdma_notify.h"
      23              : #include "ra_hdc_rdma.h"
      24              : #include "ra_hdc_rdma_verbs.h"
      25              : #include "ra_hdc_socket.h"
      26              : #include "ra_peer.h"
      27              : #include "ra_peer_socket.h"
      28              : #include "ra_rs_comm.h"
      29              : #include "ra_rs_err.h"
      30              : 
      31              : static unsigned int gWhiteListSwitch = 0;
      32              : 
      33              : /* socket: nic on device, need use hdc channel, support: 910, 310 */
      34              : struct RaSocketOps gRaHdcSocketOps = {
      35              :     .raSocketInit = RaHdcSocketInit,
      36              :     .raSocketDeinit = RaHdcSocketDeinit,
      37              :     .raSocketBatchConnect = RaHdcSocketBatchConnect,
      38              :     .raSocketBatchClose = RaHdcSocketBatchClose,
      39              :     .raSocketBatchAbort = RaHdcSocketBatchAbort,
      40              :     .raSocketListenStart = RaHdcSocketListenStart,
      41              :     .raSocketListenStop = RaHdcSocketListenStop,
      42              :     .raGetSockets = RaHdcGetSockets,
      43              :     .raSocketSend = RaHdcSocketSend,
      44              :     .raSocketRecv = RaHdcSocketRecv,
      45              :     .raGetClientSocketErrInfo = NULL,
      46              :     .raGetServerSocketErrInfo = NULL,
      47              :     .raSocketSetWhiteListStatus = NULL,
      48              :     .raSocketGetWhiteListStatus = NULL,
      49              :     .raSocketWhiteListAdd = RaHdcSocketWhiteListAdd,
      50              :     .raSocketWhiteListDel = RaHdcSocketWhiteListDel,
      51              :     .raSocketAcceptCreditAdd = RaHdcSocketAcceptCreditAdd,
      52              : };
      53              : 
      54              : /* socket: nic on host/device, support: cx6, 1822 */
      55              : struct RaSocketOps gRaPeerSocketOps = {
      56              :     .raSocketInit = NULL,
      57              :     .raSocketDeinit = RaPeerSocketDeinit,
      58              :     .raSocketBatchConnect = RaPeerSocketBatchConnect,
      59              :     .raSocketBatchClose = RaPeerSocketBatchClose,
      60              :     .raSocketBatchAbort = RaPeerSocketBatchAbort,
      61              :     .raSocketListenStart = RaPeerSocketListenStart,
      62              :     .raSocketListenStop = RaPeerSocketListenStop,
      63              :     .raGetSockets = RaPeerGetSockets,
      64              :     .raSocketSend = RaPeerSocketSend,
      65              :     .raSocketRecv = RaPeerSocketRecv,
      66              :     .raGetClientSocketErrInfo = RaPeerGetClientSocketErrInfo,
      67              :     .raGetServerSocketErrInfo = RaPeerGetServerSocketErrInfo,
      68              :     .raSocketSetWhiteListStatus = NULL,
      69              :     .raSocketGetWhiteListStatus = NULL,
      70              :     .raSocketWhiteListAdd = RaPeerSocketWhiteListAdd,
      71              :     .raSocketWhiteListDel = RaPeerSocketWhiteListDel,
      72              :     .raSocketAcceptCreditAdd = RaPeerSocketAcceptCreditAdd,
      73              : };
      74              : 
      75              : /* rdma: nic on device, need use hdc channel, support:910 */
      76              : struct RaRdmaOps gRaHdcRdmaOps = {
      77              :     .raRdevInit = RaHdcRdevInit,
      78              :     .raRdevGetPortStatus = RaHdcRdevGetPortStatus,
      79              :     .raGetLbMax = NULL,
      80              :     .raRdevDeinit = RaHdcRdevDeinit,
      81              :     .raSetTsqpDepth = RaHdcSetTsqpDepth,
      82              :     .raGetTsqpDepth = RaHdcGetTsqpDepth,
      83              :     .raQpCreate = RaHdcQpCreate,
      84              :     .raQpCreateWithAttrs = RaHdcQpCreateWithAttrs,
      85              :     .raAiQpCreate = RaHdcAiQpCreate,
      86              :     .raAiQpCreateWithAttrs = RaHdcAiQpCreateWithAttrs,
      87              :     .raTypicalQpCreate = RaHdcTypicalQpCreate,
      88              :     .raTypicalCqCreate = RaHdcTypicalCqCreate,
      89              :     .raTypicalCqDestroy = RaHdcTypicalCqDestroy,
      90              :     .raQpCreateWithCQWithAttrs = RaHdcQpCreateWithCQWithAttrs,
      91              :     .raLoopbackQpCreate = NULL,
      92              :     .raQpDestroy = RaHdcQpDestroy,
      93              :     .raQpDestroyWithoutCQ = RaHdcQpDestroyWithoutCQ,
      94              :     .raTypicalQpModify = RaHdcTypicalQpModify,
      95              :     .raQpBatchModify = RaHdcQpBatchModify,
      96              :     .raSetQpLbValue = NULL,
      97              :     .raGetQpLbValue = NULL,
      98              :     .raQpConnectAsync = RaHdcQpConnectAsync,
      99              :     .raGetQpStatus = RaHdcGetQpStatus,
     100              :     .raMrReg = RaHdcMrReg,
     101              :     .raMrDereg = RaHdcMrDereg,
     102              :     .raRegisterMr = RaHdcTypicalMrReg,
     103              :     .raRemapMr = RaHdcRemapMr,
     104              :     .raDeregisterMr = RaHdcTypicalMrDereg,
     105              :     .raSendWr = RaHdcSendWr,
     106              :     .raSendWrV2 = RaHdcSendWrV2,
     107              :     .raSendWrVerbs = RaHdcSendWrVerbs,
     108              :     .raRecvWrVerbs = RaHdcRecvWrVerbs,
     109              :     .raTypicalSendWr = RaHdcTypicalSendWr,
     110              :     .raSendWrlist = RaHdcSendWrlist,
     111              :     .raSendWrlistExt = RaHdcSendWrlistExt,
     112              :     .raSendNormalWrlist = RaHdcSendNormalWrlist,
     113              :     .raGetNotifyBaseAddr = RaHdcGetNotifyBaseAddr,
     114              :     .raGetNotifyMrInfo = RaHdcGetNotifyMrInfo,
     115              :     .raRecvWrlist = RaHdcRecvWrlist,
     116              :     .raPollCq = RaHdcPollCq,
     117              :     .raPollTypicalCq = RaHdcPollTypicalCq,
     118              :     .raGetQpContext = NULL,
     119              :     .raNormalQpCreate = NULL,
     120              :     .raNormalQpDestroy = NULL,
     121              :     .raCqCreate = NULL,
     122              :     .raCqDestroy = NULL,
     123              :     .raSetQpAttrQos = RaHdcSetQpAttrQos,
     124              :     .raSetQpAttrTimeout = RaHdcSetQpAttrTimeout,
     125              :     .raSetQpAttrRetryCnt = RaHdcSetQpAttrRetryCnt,
     126              :     .raCreateCompChannel = NULL,
     127              :     .raDestroyCompChannel = NULL,
     128              :     .raCreateSrq = NULL,
     129              :     .raDestroySrq = NULL,
     130              : };
     131              : 
     132              : /* rdma: nic on host/device, support:cx6 1822 */
     133              : struct RaRdmaOps gRaPeerRdmaOps = {
     134              :     .raRdevInit = RaPeerRdevInit,
     135              :     .raRdevGetPortStatus = NULL,
     136              :     .raGetLbMax = RaPeerGetLbMax,
     137              :     .raRdevDeinit = RaPeerRdevDeinit,
     138              :     .raSetTsqpDepth = RaPeerSetTsqpDepth,
     139              :     .raGetTsqpDepth = RaPeerGetTsqpDepth,
     140              :     .raQpCreate = RaPeerQpCreate,
     141              :     .raQpCreateWithAttrs = RaPeerQpCreateWithAttrs,
     142              :     .raAiQpCreate = NULL,
     143              :     .raAiQpCreateWithAttrs = NULL,
     144              :     .raTypicalQpCreate = NULL,
     145              :     .raTypicalCqCreate = NULL,
     146              :     .raTypicalCqDestroy = NULL,
     147              :     .raQpCreateWithCQWithAttrs = NULL,
     148              :     .raLoopbackQpCreate = RaPeerLoopbackQpCreate,
     149              :     .raQpDestroy = RaPeerQpDestroy,
     150              :     .raQpDestroyWithoutCQ = NULL,
     151              :     .raTypicalQpModify = RaPeerTypicalQpModify,
     152              :     .raQpBatchModify = NULL,
     153              :     .raSetQpLbValue = RaPeerSetQpLbValue,
     154              :     .raGetQpLbValue = RaPeerGetQpLbValue,
     155              :     .raQpConnectAsync = RaPeerQpConnectAsync,
     156              :     .raGetQpStatus = RaPeerGetQpStatus,
     157              :     .raMrReg = RaPeerMrReg,
     158              :     .raMrDereg = RaPeerMrDereg,
     159              :     .raRegisterMr = RaPeerRegisterMr,
     160              :     .raRemapMr = NULL,
     161              :     .raDeregisterMr = RaPeerDeregisterMr,
     162              :     .raSendWr = RaPeerSendWr,
     163              :     .raSendWrV2 = NULL,
     164              :     .raSendWrVerbs = NULL,
     165              :     .raRecvWrVerbs = NULL,
     166              :     .raTypicalSendWr = NULL,
     167              :     .raSendWrlist = RaPeerSendWrlist,
     168              :     .raSendWrlistExt = NULL,
     169              :     .raSendNormalWrlist = NULL,
     170              :     .raGetNotifyBaseAddr = RaPeerGetNotifyBaseAddr,
     171              :     .raGetNotifyMrInfo = NULL,
     172              :     .raRecvWrlist = RaPeerRecvWrlist,
     173              :     .raPollCq = NULL,
     174              :     .raPollTypicalCq = NULL,
     175              :     .raGetQpContext = RaPeerGetQpContext,
     176              :     .raNormalQpCreate = RaPeerNormalQpCreate,
     177              :     .raNormalQpDestroy = RaPeerNormalQpDestroy,
     178              :     .raCqCreate = RaPeerCqCreate,
     179              :     .raCqDestroy = RaPeerCqDestroy,
     180              :     .raSetQpAttrQos = RaPeerSetQpAttrQos,
     181              :     .raSetQpAttrTimeout = RaPeerSetQpAttrTimeout,
     182              :     .raSetQpAttrRetryCnt = RaPeerSetQpAttrRetryCnt,
     183              :     .raCreateCompChannel = RaPeerCreateCompChannel,
     184              :     .raDestroyCompChannel = RaPeerDestroyCompChannel,
     185              :     .raCreateSrq = RaPeerCreateSrq,
     186              :     .raDestroySrq = RaPeerDestroySrq,
     187              : };
     188              : 
     189              : struct ErrcodeInfo gErrcodeInfoList[] = {
     190              :     {-EPERM, 1, 0},
     191              :     {-EAGAIN, 1, 1},
     192              :     {-EACCES, 1, 2},
     193              :     {-EINVAL, 1, 3},
     194              :     {-ESYSFUNC, 1, 4},
     195              :     {-EADDRINUSE, 1, 5},
     196              :     {-EADDRNOTAVAIL, 1, 6},
     197              :     {-ESOCKCLOSED, 1, 7},
     198              :     {-EUSERS, TYPE_CODE_OR_ENV_ERR, 8},
     199              :     {-ENOENT, 2, 0},
     200              :     {-ESRCH, 2, 1},
     201              :     {-ENODEV, 2, 2},
     202              :     {-ENOSPC, 2, 3},
     203              :     {-EPROTONOSUPPORT, 2, 4},
     204              :     {-EFILEOPER, 2, 5},
     205              :     {-ENOMEM, 3, 0},
     206              :     {-EFAULT, 3, 1},
     207              :     {-EEXIST, 3, 2},
     208              :     {-EPIPE, 3, 3},
     209              :     {-ENOLINK, 3, 4},
     210              :     {-ENETUNREACH, 3, 5},
     211              :     {-ESAFEFUNC, 3, 6},
     212              :     {-EDEFAULT, 3, 7},
     213              :     {-EINVALIDIP, 3, 8},
     214              :     {-EOPENSRC, 5, 1},
     215              :     {-ENOTSUPP, 5, 2},
     216              : };
     217              : 
     218           41 : int RaInetPton(int family, union HccpIpAddr ip, char netAddr[], unsigned int len)
     219              : {
     220           41 :     const char *str = inet_ntop(family, &(ip.addr), netAddr, len);
     221           41 :     CHK_PRT_RETURN(str == NULL, hccp_err("[ntop_convert][ra_inet]the ip failed err(%d)", errno), -EINVAL);
     222           37 :     return 0;
     223              : }
     224              : 
     225            8 : HCCP_ATTRI_VISI_DEF int RaSocketInit(int mode, struct rdev rdevInfo, void **socketHandle)
     226              : {
     227            8 :     struct RaSocketHandle *socketHandleTmp = NULL;
     228              :     int ret;
     229            8 :     char localIp[MAX_IP_LEN] = {0};
     230              : 
     231            8 :     CHK_PRT_RETURN(rdevInfo.phyId >= RA_MAX_PHY_ID_NUM || socketHandle == NULL,
     232              :         hccp_err("[init][ra_socket]phyId(%u) is invalid! it must be [0,%d) or socket is null!",
     233              :                  rdevInfo.phyId, RA_MAX_PHY_ID_NUM), ConverReturnCode(HCCP_INIT, -EINVAL));
     234              : 
     235            7 :     ret = RaInetPton(rdevInfo.family, rdevInfo.localIp, localIp, MAX_IP_LEN);
     236            7 :     CHK_PRT_RETURN(ret, hccp_err("[init][ra_socket]ra_inet_pton for local_ip failed, ret(%d)", ret),
     237              :         ConverReturnCode(HCCP_INIT, ret));
     238              : 
     239            6 :     hccp_run_info("socket init:mode=%d phyId=%u family=%d ip=%s", mode, rdevInfo.phyId, rdevInfo.family, localIp);
     240              : 
     241            6 :     socketHandleTmp = calloc(1, sizeof(struct RaSocketHandle));
     242            6 :     CHK_PRT_RETURN(socketHandleTmp == NULL,
     243              :         hccp_err("[init][ra_socket]calloc socketHandleTmp failed, ret(%d)", ret),
     244              :         ConverReturnCode(HCCP_INIT, -ENOMEM));
     245              : 
     246            5 :     if (mode == NETWORK_OFFLINE) {
     247            4 :         socketHandleTmp->socketOps = &gRaHdcSocketOps;
     248            1 :     } else if (mode == NETWORK_PEER_ONLINE) {
     249            0 :         socketHandleTmp->socketOps = &gRaPeerSocketOps;
     250              :     } else {
     251            1 :         hccp_err("[init][ra_socket]Wrong mode(%d), do not support", mode);
     252            1 :         ret = -EINVAL;
     253            1 :         goto err;
     254              :     }
     255              : 
     256            4 :     ret = memcpy_s(&(socketHandleTmp->rdevInfo), sizeof(struct rdev), &rdevInfo, sizeof(struct rdev));
     257            4 :     if (ret) {
     258            1 :         hccp_err("[init][ra_socket]memcpy_s for rdev_info failed, ret(%d)", ret);
     259            1 :         ret = -ESAFEFUNC;
     260            1 :         goto err;
     261              :     }
     262              : 
     263            3 :     if (rdevInfo.family == AF_INET && rdevInfo.localIp.addr.s_addr < RA_VNIC_MAX &&
     264            3 :         socketHandleTmp->socketOps->raSocketInit != NULL) {
     265              :         // HDC模式只支持IPv4
     266            3 :         if (rdevInfo.localIp.addr.s_addr < RA_VNIC_MAX) {
     267            3 :             ret = socketHandleTmp->socketOps->raSocketInit(rdevInfo);
     268            3 :             if (ret) {
     269            2 :                 hccp_err("[init][ra_socket]ra socket init failed, ret(%d)", ret);
     270            2 :                 goto err;
     271              :             }
     272              :         }
     273              :     }
     274            1 :     *socketHandle = (void*)socketHandleTmp;
     275            1 :     return ret;
     276            4 : err:
     277            4 :     free(socketHandleTmp);
     278            4 :     socketHandleTmp = NULL;
     279            4 :     return ConverReturnCode(HCCP_INIT, ret);
     280              : }
     281              : 
     282            7 : HCCP_ATTRI_VISI_DEF int RaSocketInitV1(int mode, struct SocketInitInfoT socketInit, void **socketHandle)
     283              : {
     284              :     // 支持IPv4/IPv6 socket初始化
     285              :     // IPv6需要输入scope id
     286            7 :     struct RaSocketHandle *socketHandleTmp = NULL;
     287            7 :     char localIp[MAX_IP_LEN] = {0};
     288              :     int ret;
     289              : 
     290            7 :     CHK_PRT_RETURN(socketInit.rdevInfo.phyId >= RA_MAX_PHY_ID_NUM || socketHandle == NULL,
     291              :         hccp_err("[init][ra_socket]phyId(%u) is invalid! it must be [0,%d) or socket is null!",
     292              :                  socketInit.rdevInfo.phyId, RA_MAX_PHY_ID_NUM), ConverReturnCode(HCCP_INIT, -EINVAL));
     293              : 
     294            6 :     ret = RaInetPton(socketInit.rdevInfo.family, socketInit.rdevInfo.localIp, localIp, MAX_IP_LEN);
     295            6 :     CHK_PRT_RETURN(ret, hccp_err("[init][ra_socket]ra_inet_pton for local_ip failed, ret(%d)", ret),
     296              :         ConverReturnCode(HCCP_INIT, ret));
     297              : 
     298            5 :     hccp_run_info("socket init:mode=%d phyId=%u scope_id=%d family=%d ip=%s", mode, socketInit.rdevInfo.phyId,
     299              :         socketInit.scopeId, socketInit.rdevInfo.family, localIp);
     300              : 
     301            5 :     socketHandleTmp = calloc(1, sizeof(struct RaSocketHandle));
     302            5 :     CHK_PRT_RETURN(socketHandleTmp == NULL, hccp_err("[init][ra_socket]calloc for socket_handle failed"),
     303              :         ConverReturnCode(HCCP_INIT, -ENOMEM));
     304              : 
     305            4 :     if (mode == NETWORK_OFFLINE) {
     306            1 :         socketHandleTmp->socketOps = &gRaHdcSocketOps;
     307            1 :         socketHandleTmp->scopeId = socketInit.scopeId;
     308            3 :     } else if (mode == NETWORK_PEER_ONLINE) {
     309            2 :         socketHandleTmp->socketOps = &gRaPeerSocketOps;
     310            2 :         socketHandleTmp->scopeId = socketInit.scopeId;
     311              :     } else {
     312            1 :         hccp_err("[init][ra_socket]Wrong mode(%d), do not support", mode);
     313            1 :         ret = -EINVAL;
     314            1 :         goto err;
     315              :     }
     316              : 
     317            3 :     ret = memcpy_s(&(socketHandleTmp->rdevInfo), sizeof(struct rdev), &socketInit.rdevInfo, sizeof(struct rdev));
     318            3 :     if (ret) {
     319            1 :         hccp_err("[init][ra_socket]memcpy_s for rdev_info failed, ret(%d)", ret);
     320            1 :         ret = -ESAFEFUNC;
     321            1 :         goto err;
     322              :     }
     323              : 
     324            2 :     if (socketInit.rdevInfo.family == AF_INET && socketInit.rdevInfo.localIp.addr.s_addr < RA_VNIC_MAX &&
     325            1 :         socketHandleTmp->socketOps->raSocketInit != NULL) {
     326              :         // HDC模式只支持IPv4
     327            1 :         if (socketInit.rdevInfo.localIp.addr.s_addr < RA_VNIC_MAX) {
     328            1 :             ret = socketHandleTmp->socketOps->raSocketInit(socketInit.rdevInfo);
     329            1 :             if (ret) {
     330            1 :                 hccp_err("[init][ra_socket]ra socket init v1 failed, ret(%d)", ret);
     331            1 :                 goto err;
     332              :             }
     333              :         }
     334              :     }
     335            1 :     *socketHandle = (void*)socketHandleTmp;
     336            1 :     return ret;
     337            3 : err:
     338            3 :     free(socketHandleTmp);
     339            3 :     socketHandleTmp = NULL;
     340            3 :     return ConverReturnCode(HCCP_INIT, ret);
     341              : }
     342              : 
     343            4 : HCCP_ATTRI_VISI_DEF int RaSocketDeinit(void *socketHandle)
     344              : {
     345            4 :     struct RaSocketHandle *socketHandleTmp = NULL;
     346              :     struct rdev rdevInfo;
     347            4 :     char localIp[MAX_IP_LEN] = {0};
     348              :     int ret;
     349              : 
     350            4 :     CHK_PRT_RETURN(socketHandle == NULL, hccp_err("[deinit][ra_socket]socket_handle is NULL"),
     351              :         ConverReturnCode(HCCP_INIT, -EINVAL));
     352              : 
     353            3 :     socketHandleTmp = (struct RaSocketHandle *)socketHandle;
     354            3 :     rdevInfo = socketHandleTmp->rdevInfo;
     355            3 :     CHK_PRT_RETURN(rdevInfo.phyId >= RA_MAX_PHY_ID_NUM,
     356              :         hccp_err("[deinit][ra_socket]phyId(%u) >= %u. invalid", rdevInfo.phyId, RA_MAX_PHY_ID_NUM),
     357              :         ConverReturnCode(HCCP_INIT, -EINVAL));
     358              : 
     359            2 :     ret = RaInetPton(rdevInfo.family, rdevInfo.localIp, localIp, MAX_IP_LEN);
     360            2 :     CHK_PRT_RETURN(ret, hccp_err("[deinit][ra_socket]ra_inet_pton for local_ip failed, ret(%d)", ret),
     361              :         ConverReturnCode(HCCP_INIT, ret));
     362              : 
     363            2 :     hccp_run_info("Input parameters: phyId[%u] family[%d] local_ip[%s]", rdevInfo.phyId, rdevInfo.family, localIp);
     364              : 
     365            2 :     ret = socketHandleTmp->socketOps->raSocketDeinit(rdevInfo);
     366            2 :     if (ret) {
     367            1 :         hccp_err("[deinit][ra_socket]ra socket deinit failed, ret(%d)", ret);
     368              :     }
     369              : 
     370            2 :     socketHandleTmp->socketOps = NULL;
     371            2 :     free(socketHandleTmp);
     372            2 :     socketHandleTmp = NULL;
     373            2 :     return ConverReturnCode(HCCP_INIT, ret);
     374              : }
     375              : 
     376           10 : STATIC int RaRdevInitCheckIp(int mode, struct rdev rdevInfo, char localIp[])
     377              : {
     378           10 :     struct InterfaceInfo *interfaceInfos = NULL;
     379           10 :     char interfaceIp[MAX_IP_LEN] = { 0 };
     380           10 :     struct RaGetIfattr config = { 0 };
     381              :     unsigned int i, interfaceVersion;
     382           10 :     unsigned int num = 0;
     383              :     int ret;
     384              : 
     385           10 :     config.phyId = rdevInfo.phyId;
     386           10 :     config.nicPosition = (unsigned int)mode;
     387           10 :     if (config.nicPosition == NETWORK_OFFLINE) {
     388            7 :         ret = RaGetInterfaceVersion(config.phyId, RA_RS_GET_IFNUM, &interfaceVersion);
     389            7 :         if (ret != 0 || interfaceVersion != RA_RS_GET_IFNUM_VERSION) {
     390            7 :             num = MAX_INTERFACE_NUM;
     391            7 :             goto get_addrs;
     392              :         }
     393              :     }
     394              :     /* get the number of interfaces */
     395            3 :     ret = RaGetIfnum(&config, &num);
     396            3 :     CHK_PRT_RETURN(ret != 0 || num == 0, hccp_err("[check][ip]get_ifnum failed, ret(%d) or num is 0", ret), -EINVAL);
     397              : 
     398            0 : get_addrs:
     399              :     /* calloc for interface_infos according to the real num */
     400            7 :     interfaceInfos = calloc(num, sizeof(struct InterfaceInfo));
     401            7 :     CHK_PRT_RETURN(interfaceInfos == NULL, hccp_err("[check][ip]calloc for interface_infos failed"), -EINVAL);
     402              : 
     403            6 :     ret = RaGetIfaddrs(&config, interfaceInfos, &num);
     404            6 :     if (ret != 0 || (num == 0)) {
     405            4 :         hccp_err("[check][ip]ra_get_ifaddrs for interface_infos failed, ret(%d), num(%u)", ret, num);
     406            4 :         free(interfaceInfos);
     407            4 :         return -EINVALIDIP;
     408              :     }
     409              : 
     410           10 :     for (i = 0; i < num; i++) {
     411            9 :         if (interfaceInfos[i].family != rdevInfo.family) {
     412            8 :             continue;
     413              :         }
     414              : 
     415            1 :         ret = RaInetPton(interfaceInfos[i].family, interfaceInfos[i].ifaddr.ip, interfaceIp, MAX_IP_LEN);
     416            1 :         if (ret != 0) {
     417            1 :             hccp_err("[check][ip]ra_inet_pton for interface_infos[%u] failed, ret(%d)", i, ret);
     418            1 :             free(interfaceInfos);
     419            1 :             return ret;
     420              :         }
     421              : 
     422            0 :         ret = strncmp(interfaceIp, localIp, MAX_IP_LEN - 1);
     423            0 :         if (ret == 0) {
     424            0 :             free(interfaceInfos);
     425            0 :             return 0;
     426              :         }
     427              :     }
     428            1 :     hccp_err("[check][ip]failed, ret(%d) the IP address(%s) in the ranktable is inconsistent with the IP(%s)"\
     429              :         "address of the network adapter, please make sure they're consistent. "\
     430              :         "num(%u)", ret, localIp, interfaceIp, num);
     431              : 
     432            1 :     free(interfaceInfos);
     433            1 :     return -EINVALIDIP;
     434              : }
     435              : 
     436           14 : int RaRdevInitCheck(int mode, struct rdev rdevInfo, char localIp[], unsigned int num, void *rdmaHandle)
     437              : {
     438              :     int ret;
     439              : 
     440           14 :     CHK_PRT_RETURN(rdevInfo.phyId >= RA_MAX_PHY_ID_NUM, hccp_err("[check][ra_rdev_init]phyId(%u) is invalid!"
     441              :         "it must greater or equal to 0 and less than %d!", rdevInfo.phyId, RA_MAX_PHY_ID_NUM), -EINVAL);
     442              : 
     443           13 :     CHK_PRT_RETURN(rdmaHandle == NULL, hccp_err("[check][ra_rdev_init]phyId(%u) rdma_handle is null!",
     444              :         rdevInfo.phyId), -EINVAL);
     445              : 
     446           12 :     ret = RaInetPton(rdevInfo.family, rdevInfo.localIp, localIp, num);
     447           12 :     CHK_PRT_RETURN(ret, hccp_err("[check][ra_rdev_init]ra_inet_pton for local_ip failed, ret(%d)", ret), -EINVAL);
     448              : 
     449           11 :     ret = RaRdevInitCheckIp(mode, rdevInfo, localIp);
     450           11 :     CHK_PRT_RETURN(ret, hccp_err("[check][ra_rdev_init]ra_rdev_init_check_ip failed, ret(%d)", ret), ret);
     451              : 
     452            2 :     return 0;
     453              : }
     454              : 
     455            5 : STATIC int RaGetInitRdmaHandle(int mode, struct RaRdmaHandle *rdmaHandle)
     456              : {
     457            5 :     if (mode == NETWORK_OFFLINE) {
     458            2 :         (void)RaHdcRdmaSetOps(rdmaHandle, &gRaHdcRdmaOps);
     459            3 :     } else if (mode == NETWORK_PEER_ONLINE) {
     460            2 :         (void)RaHdcRdmaSetOps(rdmaHandle, &gRaPeerRdmaOps);
     461              :     } else {
     462            1 :         hccp_err("[init][ra_rdev]Wrong mode(%d), do not support", mode);
     463            1 :         return -EINVAL;
     464              :     }
     465              : 
     466            4 :     CHK_PRT_RETURN(rdmaHandle->rdmaOps->raRdevInit == NULL, hccp_err("[init][ra_rdev] ra_rdev_init is NULL!"),
     467              :         -EINVAL);
     468            4 :     return 0;
     469              : }
     470              : 
     471            2 : STATIC void RaGenerateGidByRdevInfo(struct RaRdmaHandle *rdmaHandle)
     472              : {
     473              : #define RA_GID_SEQ_NUM   4
     474              : #define RA_GID_SEQ_ZERO  0
     475              : #define RA_GID_SEQ_ONE   1
     476              : #define RA_GID_SEQ_TWO   2
     477              : #define RA_GID_SEQ_THREE 3
     478            2 :     union HccpIpAddr localIp = rdmaHandle->rdevInfo.localIp;
     479            2 :     int family = rdmaHandle->rdevInfo.family;
     480              :     unsigned int gidV4[RA_GID_SEQ_NUM];
     481              : 
     482            2 :     if (family == AF_INET6) {
     483            0 :         (void)memcpy_s(rdmaHandle->gid, HCCP_GID_RAW_LEN, &(localIp.addr6), HCCP_GID_RAW_LEN);
     484              :     } else {
     485            2 :         gidV4[RA_GID_SEQ_ZERO] = 0;
     486            2 :         gidV4[RA_GID_SEQ_ONE] = 0;
     487              :         /* The gid format generated by ipv4 is filled with 0xFFFF in [33, 48] */
     488            2 :         gidV4[RA_GID_SEQ_TWO]   = htonl(0x0000FFFF);
     489            2 :         gidV4[RA_GID_SEQ_THREE] = localIp.addr.s_addr;
     490            2 :         (void)memcpy_s(rdmaHandle->gid, HCCP_GID_RAW_LEN, gidV4, HCCP_GID_RAW_LEN);
     491              :     }
     492              : 
     493            2 :     return;
     494              : }
     495              : 
     496           17 : STATIC int RaRdevInitWithBackupInfo(struct RdevInitInfo initInfo, struct rdev rdevInfo,
     497              :     struct RaBackupInfo backupInfo, void **rdmaHandle)
     498              : {
     499           17 :     struct RaRdmaHandle *rdmaHandleTmp = NULL;
     500           17 :     char localIp[MAX_IP_LEN] = {0};
     501              :     unsigned int rdevIndex;
     502              :     int ret;
     503              : 
     504           17 :     ret = RaRdevInitCheck(initInfo.mode, rdevInfo, localIp, MAX_IP_LEN, rdmaHandle);
     505           17 :     CHK_PRT_RETURN(ret, hccp_err("[init][ra_rdev]ra_rdev_init_check failed ,ret(%d)", ret),
     506              :         ConverReturnCode(HCCP_INIT, ret));
     507              : 
     508            6 :     hccp_run_info("rdev_init:mode=%d phyId=%u family=%d ip=%s notify_type=%u", initInfo.mode, rdevInfo.phyId,
     509              :         rdevInfo.family, localIp, initInfo.notifyType);
     510              : 
     511            6 :     rdmaHandleTmp = calloc(1, sizeof(struct RaRdmaHandle));
     512            6 :     CHK_PRT_RETURN(rdmaHandleTmp == NULL, hccp_err("[init][ra_rdev]calloc for rdma_handle failed"),
     513              :         ConverReturnCode(HCCP_INIT, -ENOMEM));
     514              : 
     515              :     // disabled_lite_thread will be invalid if enabled_910a_lite is false
     516            5 :     rdmaHandleTmp->disabledLiteThread = initInfo.disabledLiteThread;
     517            5 :     rdmaHandleTmp->enabled910aLite = initInfo.enabled910aLite;
     518            5 :     rdmaHandleTmp->enabled2mbLite = initInfo.enabled2mbLite;
     519            5 :     (void)memcpy_s(&rdmaHandleTmp->backupInfo, sizeof(struct RaBackupInfo),
     520              :         &backupInfo, sizeof(struct RaBackupInfo));
     521              : 
     522            5 :     ret = RaGetInitRdmaHandle(initInfo.mode, rdmaHandleTmp);
     523            5 :     if (ret) {
     524            1 :         hccp_err("[init][ra_rdev] get rdma handle failed, ret(%d)", ret);
     525            1 :         goto err;
     526              :     }
     527              : 
     528            4 :     ret = memcpy_s(&(rdmaHandleTmp->rdevInfo), sizeof(struct rdev), &rdevInfo, sizeof(struct rdev));
     529            4 :     if (ret) {
     530            1 :         hccp_err("[init][ra_rdev]memcpy_s for rdev_info failed, ret(%d)", ret);
     531            1 :         ret = -ESAFEFUNC;
     532            1 :         goto err;
     533              :     }
     534              : 
     535            3 :     ret = rdmaHandleTmp->rdmaOps->raRdevInit(rdmaHandleTmp, initInfo.notifyType, rdevInfo, &rdevIndex);
     536            3 :     if (ret) {
     537            1 :         hccp_err("[init][ra_rdev]ra rdev init failed, ret(%d)", ret);
     538            1 :         goto err;
     539              :     }
     540              : 
     541            2 :     rdmaHandleTmp->rdevIndex = rdevIndex;
     542            2 :     RaGenerateGidByRdevInfo(rdmaHandleTmp);
     543            2 :     *rdmaHandle = (void *)rdmaHandleTmp;
     544              : 
     545              :     // save rdev handle for helper
     546            2 :     RaRdevSetHandle(rdevInfo.phyId, *rdmaHandle);
     547              : 
     548            2 :     return ret;
     549            3 : err:
     550            3 :     free(rdmaHandleTmp);
     551            3 :     rdmaHandleTmp = NULL;
     552            3 :     return ConverReturnCode(HCCP_INIT, ret);
     553              : }
     554              : 
     555            2 : HCCP_ATTRI_VISI_DEF int RaRdevInitWithBackup(struct RdevInitInfo *initInfo, struct rdev *rdevInfo,
     556              :     struct rdev *backupRdevInfo, void **rdmaHandle)
     557              : {
     558            2 :     struct RaBackupInfo backupInfo = { 0 };
     559              : 
     560            2 :     if (initInfo == NULL || rdevInfo == NULL || backupRdevInfo == NULL || rdmaHandle == NULL) {
     561            1 :         hccp_err("[init][ra_rdev]init_info or rdev_info or backup_rdev_info or rdma_handle is NULL");
     562            1 :         return -EINVAL;
     563              :     }
     564              : 
     565            1 :     backupInfo.backupFlag = true;
     566            1 :     (void)memcpy_s(&backupInfo.rdevInfo, sizeof(struct rdev), backupRdevInfo, sizeof(struct rdev));
     567              : 
     568            1 :     return RaRdevInitWithBackupInfo(*initInfo, *rdevInfo, backupInfo, rdmaHandle);
     569              : }
     570              : 
     571           16 : HCCP_ATTRI_VISI_DEF int RaRdevInitV2(struct RdevInitInfo initInfo, struct rdev rdevInfo, void **rdmaHandle)
     572              : {
     573           16 :     struct RaBackupInfo backupInfo = { 0 };
     574              : 
     575           16 :     return RaRdevInitWithBackupInfo(initInfo, rdevInfo, backupInfo, rdmaHandle);
     576              : }
     577              : 
     578           16 : HCCP_ATTRI_VISI_DEF int RaRdevInit(int mode, unsigned int notifyType, struct rdev rdevInfo, void **rdmaHandle)
     579              : {
     580           16 :     struct RdevInitInfo initInfo = { 0 };
     581           16 :     initInfo.mode = mode;
     582           16 :     initInfo.notifyType = notifyType;
     583           16 :     initInfo.disabledLiteThread = false; // will start lite thread by default
     584           16 :     initInfo.enabled910aLite = false; // will disabled lite on 910A by default
     585           16 :     initInfo.enabled2mbLite = false; // will disabled lite on 2MB page align scenario by default
     586              : 
     587           16 :     return RaRdevInitV2(initInfo, rdevInfo, rdmaHandle);
     588              : }
     589              : 
     590            5 : STATIC int RaRdevDeinitParaCheck(void *rdmaHandle, struct RaRdmaHandle **rdmaHandleTmp)
     591              : {
     592              :     int ret;
     593            5 :     char localIp[MAX_IP_LEN] = {0};
     594              :     struct rdev rdevInfo;
     595              : 
     596            5 :     *rdmaHandleTmp = (struct RaRdmaHandle *)rdmaHandle;
     597            5 :     rdevInfo = (*rdmaHandleTmp)->rdevInfo;
     598            5 :     CHK_PRT_RETURN(rdevInfo.phyId >= RA_MAX_PHY_ID_NUM, hccp_err("[deinit][ra_rdev]phyId(%u)"
     599              :         "must smaller than %u", rdevInfo.phyId, RA_MAX_PHY_ID_NUM), -EINVAL);
     600              : 
     601            4 :     ret = RaInetPton(rdevInfo.family, rdevInfo.localIp, localIp, MAX_IP_LEN);
     602            4 :     CHK_PRT_RETURN(ret, hccp_err("[deinit][ra_rdev]ra_inet_pton for local_ip failed, ret(%d)", ret), ret);
     603              : 
     604            3 :     CHK_PRT_RETURN((*rdmaHandleTmp)->rdmaOps == NULL || (*rdmaHandleTmp)->rdmaOps->raRdevDeinit == NULL,
     605              :         hccp_err("[deinit][ra_rdev]rdma_ops is NULL or ra_rdev_deinit is NULL"), -EINVAL);
     606              : 
     607            2 :     hccp_run_info("Input parameters: phyId[%u] rdev_index[%u] family[%d] local_ip[%s]",
     608              :         rdevInfo.phyId, (*rdmaHandleTmp)->rdevIndex, rdevInfo.family, localIp);
     609              : 
     610            2 :     return 0;
     611              : }
     612              : 
     613            5 : HCCP_ATTRI_VISI_DEF int RaRdevGetPortStatus(void *rdmaHandle, enum PortStatus *status)
     614              : {
     615            5 :     struct RaRdmaHandle *rdmaHandleTmp = (struct RaRdmaHandle *)rdmaHandle;
     616              :     unsigned int phyId;
     617              :     int ret;
     618              : 
     619            5 :     CHK_PRT_RETURN(rdmaHandle == NULL || status == NULL,
     620              :         hccp_err("[get][ra_port_status]rdma_handle or status is NULL, invalid"),
     621              :         ConverReturnCode(RDMA_OP, -EINVAL));
     622              : 
     623            4 :     phyId = rdmaHandleTmp->rdevInfo.phyId;
     624            4 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
     625              :         hccp_err("[get][ra_port_status]phyId(%u) must smaller than %u", phyId, RA_MAX_PHY_ID_NUM),
     626              :         ConverReturnCode(RDMA_OP, -EINVAL));
     627              : 
     628            3 :     CHK_PRT_RETURN(rdmaHandleTmp->rdmaOps == NULL || rdmaHandleTmp->rdmaOps->raRdevGetPortStatus == NULL,
     629              :         hccp_err("[get][ra_port_status]rdma_ops is NULL or ra_rdev_get_port_status is NULL, invalid"),
     630              :         ConverReturnCode(RDMA_OP, -EINVAL));
     631              : 
     632            2 :     ret = rdmaHandleTmp->rdmaOps->raRdevGetPortStatus(rdmaHandleTmp, status);
     633            2 :     return ConverReturnCode(RDMA_OP, ret);
     634              : }
     635              : 
     636            6 : HCCP_ATTRI_VISI_DEF int RaRdevDeinit(void *rdmaHandle, unsigned int notifyType)
     637              : {
     638            6 :     struct RaRdmaHandle *rdmaHandleTmp = NULL;
     639              :     unsigned int phyId;
     640              :     int ret;
     641              : 
     642            6 :     CHK_PRT_RETURN(rdmaHandle == NULL, hccp_err("[deinit][ra_rdev] rdma_handle is NULL"),
     643              :         ConverReturnCode(HCCP_INIT, -EINVAL));
     644              : 
     645            5 :     ret = RaRdevDeinitParaCheck(rdmaHandle, &rdmaHandleTmp);
     646            5 :     CHK_PRT_RETURN(ret, hccp_err("[deinit][ra_rdev] para check failed, ret(%d)", ret),
     647              :         ConverReturnCode(HCCP_INIT, ret));
     648              : 
     649            2 :     phyId = rdmaHandleTmp->rdevInfo.phyId;
     650              : 
     651            2 :     ret = rdmaHandleTmp->rdmaOps->raRdevDeinit(rdmaHandleTmp, notifyType);
     652            2 :     if (ret) {
     653            0 :         hccp_err("[deinit][ra_rdev]ra rdv deinit failed, ret(%d)", ret);
     654            0 :         goto free_rdma_handle;
     655              :     }
     656              : 
     657            2 : free_rdma_handle:
     658            2 :     rdmaHandleTmp->rdmaOps = NULL;
     659            2 :     free(rdmaHandleTmp);
     660            2 :     rdmaHandleTmp = NULL;
     661            2 :     RaRdevSetHandle(phyId, NULL);
     662            2 :     return ConverReturnCode(HCCP_INIT, ret);
     663              : }
     664              : 
     665            2 : HCCP_ATTRI_VISI_DEF int RaRdevGetSupportLite(void *rdmaHandle, int *supportLite)
     666              : {
     667            2 :     struct RaRdmaHandle *rdmaHandleTmp = NULL;
     668              : 
     669            2 :     CHK_PRT_RETURN(rdmaHandle == NULL || supportLite == NULL,
     670              :         hccp_err("[get][ra_rdev]rdma_handle is NULL or support_lite is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
     671              : 
     672            1 :     rdmaHandleTmp = (struct RaRdmaHandle *)rdmaHandle;
     673            1 :     *supportLite = rdmaHandleTmp->supportLite;
     674              : 
     675            1 :     hccp_dbg("[get][ra_rdev]support_lite:%d", *supportLite);
     676              : 
     677            1 :     return 0;
     678              : }
     679              : 
     680            4 : HCCP_ATTRI_VISI_DEF int RaSocketBatchConnect(struct SocketConnectInfoT conn[], unsigned int num)
     681              : {
     682            4 :     struct RaSocketHandle *socketHandle = NULL;
     683            4 :     char remoteIp[MAX_IP_LEN] = {0};
     684            4 :     char localIp[MAX_IP_LEN] = {0};
     685              :     unsigned int i;
     686              :     int ret;
     687              : 
     688            4 :     CHK_PRT_RETURN(conn == NULL || num == 0 || num > MAX_SOCKET_NUM,
     689              :         hccp_err("[batch_connect][ra_socket]conn is NULL or num[%u] is zero or num is greater than %d", num,
     690              :         MAX_SOCKET_NUM), ConverReturnCode(SOCKET_OP, -EINVAL));
     691              : 
     692            4 :     for (i = 0; i < num; i++) {
     693            3 :         socketHandle = (struct RaSocketHandle *)conn[i].socketHandle;
     694            3 :         if (socketHandle == NULL || socketHandle->socketOps == NULL ||
     695            2 :             socketHandle->socketOps->raSocketBatchConnect == NULL) {
     696            1 :             hccp_err("[batch_connect][ra_socket]socket_handle or func is NULL");
     697            1 :             return ConverReturnCode(SOCKET_OP, -EINVAL);
     698              :         }
     699              : 
     700            2 :         CHK_PRT_RETURN(socketHandle->rdevInfo.phyId >= RA_MAX_PHY_ID_NUM,
     701              :             hccp_err("[batch_connect][ra_socket]phyId(%u) must smaller than %u", socketHandle->rdevInfo.phyId,
     702              :             RA_MAX_PHY_ID_NUM), ConverReturnCode(SOCKET_OP, -EINVAL));
     703              : 
     704            1 :         CHK_PRT_RETURN(strlen(conn[i].tag) >= SOCK_CONN_TAG_SIZE,
     705              :             hccp_err("[batch_connect][ra_socket]conn tag len(%d) more than max len(%d)", strlen(conn[i].tag),
     706              :             SOCK_CONN_TAG_SIZE), ConverReturnCode(SOCKET_OP, -EINVAL));
     707              : 
     708            1 :         ret = RaInetPton(socketHandle->rdevInfo.family, socketHandle->rdevInfo.localIp, localIp, MAX_IP_LEN);
     709            1 :         CHK_PRT_RETURN(ret, hccp_err("[batch_connect][ra_socket]ra_inet_pton for local_ip failed, ret(%d)", ret),
     710              :             ConverReturnCode(SOCKET_OP, ret));
     711              : 
     712            1 :         ret = RaInetPton(socketHandle->rdevInfo.family, conn[i].remoteIp, remoteIp, MAX_IP_LEN);
     713            1 :         CHK_PRT_RETURN(ret, hccp_err("[batch_connect][ra_socket]ra_inet_pton for remote_ip failed, ret(%d)", ret),
     714              :             ConverReturnCode(SOCKET_OP, ret));
     715              : 
     716            1 :         hccp_run_info("Input parameters: [%u]th, phyId[%u], localIp[%s], remoteIp[%s], port[%u], tag[%s], cnt[%u]",
     717              :             i, socketHandle->rdevInfo.phyId, localIp, remoteIp, conn[i].port, conn[i].tag,
     718              :             socketHandle->connectCnt);
     719              :     }
     720              : 
     721            1 :     socketHandle->connectCnt++;
     722            1 :     ret = socketHandle->socketOps->raSocketBatchConnect(socketHandle->rdevInfo.phyId, conn, num);
     723            1 :     return ConverReturnCode(SOCKET_OP, ret);
     724              : }
     725              : 
     726            4 : HCCP_ATTRI_VISI_DEF int RaSocketBatchClose(struct SocketCloseInfoT conn[], unsigned int num)
     727              : {
     728            4 :     struct RaSocketHandle *socketHandle = NULL;
     729            4 :     char localIp[MAX_IP_LEN] = {0};
     730            4 :     unsigned int phyId = 0;
     731              :     unsigned int i;
     732              :     int ret;
     733              : 
     734            4 :     CHK_PRT_RETURN(conn == NULL || num == 0 || num > MAX_SOCKET_NUM,
     735              :         hccp_err("[batch_close][ra_socket]conn is NULL or num[%u] is zero or num is greater than %d", num,
     736              :         MAX_SOCKET_NUM), ConverReturnCode(SOCKET_OP, -EINVAL));
     737              : 
     738            4 :     for (i = 0; i < num; i++) {
     739            3 :         socketHandle = (struct RaSocketHandle *)conn[i].socketHandle;
     740            3 :         if (socketHandle == NULL || socketHandle->socketOps == NULL ||
     741            2 :             socketHandle->socketOps->raSocketBatchClose == NULL) {
     742            1 :             hccp_warn("[batch_close][ra_socket]socket_handle or func is NULL, no need to close");
     743            1 :             return 0;
     744              :         }
     745            2 :         phyId = socketHandle->rdevInfo.phyId;
     746            2 :         CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
     747              :             hccp_err("[batch_close][ra_socket]phyId(%u) must smaller than %u", phyId, RA_MAX_PHY_ID_NUM),
     748              :             ConverReturnCode(SOCKET_OP, -EINVAL));
     749              : 
     750            1 :         ret = RaInetPton(socketHandle->rdevInfo.family, socketHandle->rdevInfo.localIp, localIp, MAX_IP_LEN);
     751            1 :         CHK_PRT_RETURN(ret, hccp_err("[batch_connect][ra_socket]ra_inet_pton for local_ip failed, ret(%d)", ret),
     752              :             ConverReturnCode(SOCKET_OP, ret));
     753              : 
     754            1 :         hccp_run_info("Input parameters: [%u]th, phyId[%u], localIp[%s], cnt[%u]", i, phyId,
     755              :             localIp, socketHandle->closeCnt);
     756              :     }
     757              : 
     758            1 :     socketHandle->closeCnt++;
     759            1 :     ret = socketHandle->socketOps->raSocketBatchClose(phyId, conn, num);
     760            1 :     return ConverReturnCode(SOCKET_OP, ret);
     761              : }
     762              : 
     763            5 : HCCP_ATTRI_VISI_DEF int RaSocketBatchAbort(struct SocketConnectInfoT conn[], unsigned int num)
     764              : {
     765            5 :     struct RaSocketHandle *socketHandle = NULL;
     766            5 :     char remoteIp[MAX_IP_LEN] = {0};
     767            5 :     char localIp[MAX_IP_LEN] = {0};
     768            5 :     unsigned int phyId = 0;
     769              :     unsigned int i;
     770              :     int ret;
     771              : 
     772            5 :     CHK_PRT_RETURN(conn == NULL || num == 0 || num > MAX_SOCKET_NUM,
     773              :         hccp_err("[batch_abort][ra_socket]conn is NULL or num[%u] is zero or num is greater than %d",
     774              :         num, MAX_SOCKET_NUM), ConverReturnCode(SOCKET_OP, -EINVAL));
     775              : 
     776            5 :     for (i = 0; i < num; i++) {
     777            4 :         socketHandle = (struct RaSocketHandle *)conn[i].socketHandle;
     778            4 :         CHK_PRT_RETURN(socketHandle == NULL || socketHandle->socketOps == NULL ||
     779              :             socketHandle->socketOps->raSocketBatchAbort == NULL,
     780              :             hccp_err("[batch_abort][ra_socket]socket_handle or func is NULL"),
     781              :             ConverReturnCode(SOCKET_OP, -EINVAL));
     782              : 
     783            3 :         phyId = socketHandle->rdevInfo.phyId;
     784            3 :         CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
     785              :             hccp_err("[batch_abort][ra_socket]phyId(%u) must smaller than %u", phyId, RA_MAX_PHY_ID_NUM),
     786              :             ConverReturnCode(SOCKET_OP, -EINVAL));
     787              : 
     788            3 :         ret = RaInetPton(socketHandle->rdevInfo.family, socketHandle->rdevInfo.localIp, localIp, MAX_IP_LEN);
     789            3 :         CHK_PRT_RETURN(ret, hccp_err("[batch_abort][ra_socket]ra_inet_pton for local_ip failed, ret(%d)", ret),
     790              :             ConverReturnCode(SOCKET_OP, ret));
     791              : 
     792            1 :         ret = RaInetPton(socketHandle->rdevInfo.family, conn[i].remoteIp, remoteIp, MAX_IP_LEN);
     793            1 :         CHK_PRT_RETURN(ret, hccp_err("[batch_abort][ra_socket]ra_inet_pton for remote_ip failed, ret(%d)", ret),
     794              :             ConverReturnCode(SOCKET_OP, ret));
     795              : 
     796            1 :         hccp_run_info("Input parameters: [%u]th, phyId[%u], localIp[%s], remoteIp[%s], tag[%s], cnt[%u]",
     797              :             i, phyId, localIp, remoteIp, conn[i].tag, socketHandle->abortCnt);
     798              :     }
     799              : 
     800            1 :     socketHandle->abortCnt++;
     801            1 :     ret = socketHandle->socketOps->raSocketBatchAbort(phyId, conn, num);
     802            1 :     return ConverReturnCode(SOCKET_OP, ret);
     803              : }
     804              : 
     805            4 : HCCP_ATTRI_VISI_DEF int RaSocketListenStart(struct SocketListenInfoT conn[], unsigned int num)
     806              : {
     807            4 :     struct RaSocketHandle *socketHandle = NULL;
     808            4 :     char localIp[MAX_IP_LEN] = {0};
     809            4 :     unsigned int phyId = 0;
     810              :     unsigned int i;
     811              :     int ret;
     812              : 
     813            4 :     CHK_PRT_RETURN(conn == NULL || num == 0 || num > MAX_SOCKET_NUM,
     814              :         hccp_err("[listen_start][ra_socket]conn is NULL or num[%u] is zero or num is greater than %d", num,
     815              :         MAX_SOCKET_NUM), ConverReturnCode(SOCKET_OP, -EINVAL));
     816              : 
     817            4 :     for (i = 0; i < num; i++) {
     818            3 :         socketHandle = (struct RaSocketHandle *)conn[i].socketHandle;
     819            3 :         if (socketHandle == NULL || socketHandle->socketOps == NULL ||
     820            2 :             socketHandle->socketOps->raSocketListenStart == NULL) {
     821            1 :             hccp_err("[listen_start][ra_socket]socket_handle or func is NULL");
     822            1 :             return ConverReturnCode(SOCKET_OP, -EINVAL);
     823              :         }
     824            2 :         phyId = socketHandle->rdevInfo.phyId;
     825            2 :         CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
     826              :             hccp_err("[listen_start][ra_socket]phyId(%u) must smaller than %u", phyId, RA_MAX_PHY_ID_NUM),
     827              :             ConverReturnCode(SOCKET_OP, -EINVAL));
     828              : 
     829            1 :         ret = RaInetPton(socketHandle->rdevInfo.family, socketHandle->rdevInfo.localIp, localIp, MAX_IP_LEN);
     830            1 :         CHK_PRT_RETURN(ret, hccp_err("[listen_start][ra_socket]ra_inet_pton for server_ip failed, ret(%d)", ret),
     831              :             ConverReturnCode(SOCKET_OP, ret));
     832              : 
     833            1 :         hccp_run_info("Input parameters: [%u]th, phyId[%u], localIp[%s], port[%u]",
     834              :             i, phyId, localIp, conn[i].port);
     835              :     }
     836              : 
     837            1 :     ret = socketHandle->socketOps->raSocketListenStart(phyId, conn, num);
     838            1 :     return ConverReturnCode(SOCKET_OP, ret);
     839              : }
     840              : 
     841            4 : HCCP_ATTRI_VISI_DEF int RaSocketListenStop(struct SocketListenInfoT conn[], unsigned int num)
     842              : {
     843            4 :     struct RaSocketHandle *socketHandle = NULL;
     844            4 :     char localIp[MAX_IP_LEN] = {0};
     845            4 :     unsigned int phyId = 0;
     846              :     unsigned int i;
     847              :     int ret;
     848              : 
     849            4 :     CHK_PRT_RETURN(conn == NULL || num == 0 || num > MAX_SOCKET_NUM,
     850              :         hccp_err("[listen_stop][ra_socket]conn is NULL or num[%u] is zero or num is greater than %d", num,
     851              :         MAX_SOCKET_NUM), ConverReturnCode(SOCKET_OP, -EINVAL));
     852              : 
     853            4 :     for (i = 0; i < num; i++) {
     854            3 :         socketHandle = (struct RaSocketHandle *)conn[i].socketHandle;
     855            3 :         if (socketHandle == NULL || socketHandle->socketOps == NULL ||
     856            2 :             socketHandle->socketOps->raSocketListenStop == NULL) {
     857            1 :             hccp_err("[listen_stop][ra_socket]socket_handle or func is NULL");
     858            1 :             return ConverReturnCode(SOCKET_OP, -EINVAL);
     859              :         }
     860              : 
     861            2 :         phyId = socketHandle->rdevInfo.phyId;
     862            2 :         CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
     863              :             hccp_err("[listen_stop][ra_socket]phyId(%u) must smaller than %u", phyId, RA_MAX_PHY_ID_NUM),
     864              :             ConverReturnCode(SOCKET_OP, -EINVAL));
     865              : 
     866            1 :         ret = RaInetPton(socketHandle->rdevInfo.family, socketHandle->rdevInfo.localIp, localIp, MAX_IP_LEN);
     867            1 :         CHK_PRT_RETURN(ret, hccp_err("[listen_stop][ra_socket]ra_inet_pton for server_ip failed, ret(%d)", ret),
     868              :             ConverReturnCode(SOCKET_OP, ret));
     869              : 
     870            1 :         hccp_run_info("Input parameters: [%u]th, phyId[%u], localIp[%s]", i, phyId, localIp);
     871              :     }
     872              : 
     873            1 :     ret = socketHandle->socketOps->raSocketListenStop(phyId, conn, num);
     874            1 :     return ConverReturnCode(SOCKET_OP, ret);
     875              : }
     876              : 
     877            4 : HCCP_ATTRI_VISI_DEF int RaGetSockets(unsigned int role, struct SocketInfoT conn[], unsigned int num,
     878              :     unsigned int *connectedNum)
     879              : {
     880              :     unsigned int i;
     881            4 :     struct RaSocketHandle *socketHandle = NULL;
     882            4 :     char localIp[MAX_IP_LEN] = {0};
     883            4 :     char remoteIp[MAX_IP_LEN] = {0};
     884              :     int ret;
     885            4 :     unsigned int phyId = 0;
     886              : 
     887            4 :     CHK_PRT_RETURN(conn == NULL || connectedNum == NULL || num == 0 || num > MAX_SOCKET_NUM,
     888              :         hccp_err("[get][ra_socket]conn or connected_num is NULL or num[%u] is zero or num greater than %d", num,
     889              :         MAX_SOCKET_NUM), ConverReturnCode(SOCKET_OP, -EINVAL));
     890              : 
     891            4 :     for (i = 0; i < num; i++) {
     892            3 :         socketHandle = (struct RaSocketHandle *)conn[i].socketHandle;
     893            3 :         if (socketHandle == NULL || socketHandle->socketOps == NULL ||
     894            2 :             socketHandle->socketOps->raGetSockets == NULL) {
     895            1 :             hccp_err("[get][ra_socket]socket_handle or func is NULL");
     896            1 :             return ConverReturnCode(SOCKET_OP, -EINVAL);
     897              :         }
     898              : 
     899            2 :         phyId = socketHandle->rdevInfo.phyId;
     900            2 :         CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
     901              :             hccp_err("[get][ra_socket]phyId(%u) must smaller than %u", phyId, RA_MAX_PHY_ID_NUM),
     902              :             ConverReturnCode(SOCKET_OP, -EINVAL));
     903              : 
     904            1 :         ret = RaInetPton(socketHandle->rdevInfo.family, socketHandle->rdevInfo.localIp, localIp, MAX_IP_LEN);
     905            1 :         CHK_PRT_RETURN(ret, hccp_err("[get][ra_socket]ra_inet_pton for local_ip failed, ret(%d)", ret),
     906              :             ConverReturnCode(SOCKET_OP, ret));
     907              : 
     908            1 :         ret = RaInetPton(socketHandle->rdevInfo.family, conn[i].remoteIp, remoteIp, MAX_IP_LEN);
     909            1 :         CHK_PRT_RETURN(ret, hccp_err("[get][ra_socket]ra_inet_pton for remote_ip failed, ret(%d)", ret),
     910              :             ConverReturnCode(SOCKET_OP, ret));
     911              :     }
     912              : 
     913            1 :     ret = socketHandle->socketOps->raGetSockets(phyId, role, conn, num);
     914            1 :     if (ret >= 0) {
     915            1 :         *connectedNum = (unsigned int)ret;
     916            1 :         return 0;
     917              :     }
     918              : 
     919            0 :     *connectedNum = 0;
     920            0 :     return ConverReturnCode(SOCKET_OP, ret);
     921              : }
     922              : 
     923            5 : HCCP_ATTRI_VISI_DEF int RaSocketRecv(const void *fdHandle, void *data, unsigned long long size,
     924              :     unsigned long long *receivedSize)
     925              : {
     926              :     int ret;
     927              :     unsigned int phyId;
     928            5 :     const struct RaSocketHandle *socketHandleTmp = NULL;
     929            5 :     const struct SocketHdcInfo *fdHandleTmp = (const struct SocketHdcInfo *)fdHandle;
     930              : 
     931            5 :     CHK_PRT_RETURN(fdHandle == NULL || data == NULL || size == 0 || receivedSize == NULL,
     932              :         hccp_err("[recv][ra_socket]fd_handle or data or received_size is NULL or size[%llu] is 0", size),
     933              :         ConverReturnCode(SOCKET_OP, -EINVAL));
     934              : 
     935            4 :     socketHandleTmp = (const struct RaSocketHandle *)(fdHandleTmp->socketHandle);
     936            4 :     if (socketHandleTmp == NULL || socketHandleTmp->socketOps == NULL ||
     937            3 :         socketHandleTmp->socketOps->raSocketRecv == NULL) {
     938            1 :         hccp_err("[recv][ra_socket]socket_handle_tmp or func is NULL");
     939            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
     940              :     }
     941            3 :     phyId = socketHandleTmp->rdevInfo.phyId;
     942            3 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
     943              :         hccp_err("[recv][ra_socket]phyId(%u) must smaller than %u", phyId, RA_MAX_PHY_ID_NUM),
     944              :         ConverReturnCode(SOCKET_OP, -EINVAL));
     945              : 
     946            2 :     ret = socketHandleTmp->socketOps->raSocketRecv(phyId, fdHandle, data, size);
     947            2 :     if (ret > 0) {
     948            1 :         *receivedSize = (unsigned long long)(unsigned int)ret;
     949            1 :         return 0;
     950            1 :     } else if (ret == 0) {
     951            1 :         hccp_warn("[recv][ra_socket]socket has been closed. received_size is 0");
     952            1 :         ret = -ESOCKCLOSED;
     953              :     }
     954              : 
     955            1 :     *receivedSize = 0;
     956            1 :     return ConverReturnCode(SOCKET_OP, ret);
     957              : }
     958              : 
     959            5 : HCCP_ATTRI_VISI_DEF int RaSocketSend(const void *fdHandle, const void *data, unsigned long long size,
     960              :     unsigned long long *sentSize)
     961              : {
     962              :     int ret;
     963              :     unsigned int phyId;
     964            5 :     const struct RaSocketHandle *socketHandleTmp = NULL;
     965            5 :     const struct SocketHdcInfo *fdHandleTmp = (const struct SocketHdcInfo *)fdHandle;
     966              : 
     967            5 :     CHK_PRT_RETURN(fdHandle == NULL || data == NULL || sentSize == NULL || size == 0,
     968              :         hccp_err("[send][ra_socket]fd_handle or data or sent_size is NULL or size[%llu] is 0", size),
     969              :         ConverReturnCode(SOCKET_OP, -EINVAL));
     970              : 
     971            4 :     socketHandleTmp = (const struct RaSocketHandle *)(fdHandleTmp->socketHandle);
     972            4 :     if (socketHandleTmp == NULL || socketHandleTmp->socketOps == NULL ||
     973            3 :         socketHandleTmp->socketOps->raSocketSend == NULL) {
     974            1 :         hccp_err("[send][ra_socket]socket_handle_tmp or func is NULL");
     975            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
     976              :     }
     977              : 
     978            3 :     phyId = socketHandleTmp->rdevInfo.phyId;
     979            3 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
     980              :         hccp_err("[send][ra_socket]phyId(%u) must smaller than %u", phyId, RA_MAX_PHY_ID_NUM),
     981              :         ConverReturnCode(SOCKET_OP, -EINVAL));
     982              : 
     983            2 :     ret = socketHandleTmp->socketOps->raSocketSend(phyId, fdHandle, data, size);
     984            2 :     if (ret > 0) {
     985            1 :         *sentSize = (unsigned long long)(unsigned int)ret;
     986            1 :         return 0;
     987            1 :     } else if (ret == 0) {
     988            1 :         hccp_warn("[send][ra_socket]socket has been closed. sent_size is 0");
     989            1 :         ret = -ESOCKCLOSED;
     990              :     }
     991              : 
     992            1 :     *sentSize = 0;
     993            1 :     return ConverReturnCode(SOCKET_OP, ret);
     994              : }
     995              : 
     996            0 : HCCP_ATTRI_VISI_DEF int RaEpollCtlAdd(const void *fdHandle, enum RaEpollEvent event)
     997              : {
     998            0 :     CHK_PRT_RETURN(fdHandle == NULL, hccp_err("[ra_epoll_ctl_add]fd_handle is NULL"),
     999              :         ConverReturnCode(SOCKET_OP, -EINVAL));
    1000              : 
    1001            0 :     CHK_PRT_RETURN(event != RA_EPOLLIN && event != RA_EPOLLONESHOT,
    1002              :         hccp_err("[ra_epoll_ctl_add]wrong event, only RA_EPOLLIN and RA_EPOLLONESHOT are supported."),
    1003              :         ConverReturnCode(SOCKET_OP, -EINVAL));
    1004              : 
    1005            0 :     int ret = RaPeerEpollCtlAdd(fdHandle, event);
    1006            0 :     CHK_PRT_RETURN(ret, hccp_err("[ra_epoll_ctl_add]ra_peer_epoll_ctl_add failed ret(%d)", ret),
    1007              :         ConverReturnCode(SOCKET_OP, ret));
    1008              : 
    1009            0 :     return 0;
    1010              : }
    1011              : 
    1012            0 : HCCP_ATTRI_VISI_DEF int RaEpollCtlMod(const void *fdHandle, enum RaEpollEvent event)
    1013              : {
    1014            0 :     CHK_PRT_RETURN(fdHandle == NULL, hccp_err("[ra_epoll_ctl_mod]fd_handle is NULL"),
    1015              :         ConverReturnCode(SOCKET_OP, -EINVAL));
    1016              : 
    1017            0 :     CHK_PRT_RETURN(event != RA_EPOLLIN && event != RA_EPOLLONESHOT,
    1018              :         hccp_err("[ra_epoll_ctl_mod]wrong event, only RA_EPOLLIN and RA_EPOLLONESHOT are supported."),
    1019              :         ConverReturnCode(SOCKET_OP, -EINVAL));
    1020              : 
    1021            0 :     int ret = RaPeerEpollCtlMod(fdHandle, event);
    1022            0 :     CHK_PRT_RETURN(ret, hccp_err("[ra_epoll_ctl_mod]ra_peer_epoll_ctl_mod failed ret(%d)", ret),
    1023              :         ConverReturnCode(SOCKET_OP, ret));
    1024              : 
    1025            0 :     return 0;
    1026              : }
    1027              : 
    1028            0 : HCCP_ATTRI_VISI_DEF int RaEpollCtlDel(const void *fdHandle)
    1029              : {
    1030            0 :     CHK_PRT_RETURN(fdHandle == NULL, hccp_err("[ra_epoll_ctl_del]fd_handle is NULL"),
    1031              :         ConverReturnCode(SOCKET_OP, -EINVAL));
    1032              : 
    1033            0 :     int ret = RaPeerEpollCtlDel(fdHandle);
    1034            0 :     CHK_PRT_RETURN(ret, hccp_err("[ra_epoll_ctl_del]ra_peer_epoll_ctl_del failed ret(%d)", ret),
    1035              :         ConverReturnCode(SOCKET_OP, ret));
    1036              : 
    1037            0 :     return 0;
    1038              : }
    1039              : 
    1040            3 : HCCP_ATTRI_VISI_DEF int RaSetTcpRecvCallback(const void *socketHandle, const void *callback)
    1041              : {
    1042            3 :     const struct RaSocketHandle *socketHandleTmp = (const struct RaSocketHandle *)socketHandle;
    1043              :     unsigned int phyId;
    1044              : 
    1045            3 :     CHK_PRT_RETURN(socketHandleTmp == NULL || callback == NULL,
    1046              :         hccp_err("[ra_socket]socket_handle is NULL or callback is NULL"),
    1047              :         ConverReturnCode(SOCKET_OP, -EINVAL));
    1048              : 
    1049            2 :     phyId = socketHandleTmp->rdevInfo.phyId;
    1050            2 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
    1051              :         hccp_err("[ra_socket]phyId(%u) must smaller than %u", phyId, RA_MAX_PHY_ID_NUM),
    1052              :         ConverReturnCode(SOCKET_OP, -EINVAL));
    1053              : 
    1054            1 :     RaPeerSetTcpRecvCallback(phyId, callback);
    1055              : 
    1056            1 :     return 0;
    1057              : }
    1058              : 
    1059            4 : HCCP_ATTRI_VISI_DEF int RaGetTsqpDepth(void *rdevHandle, unsigned int *tempDepth, unsigned int *qpNum)
    1060              : {
    1061            4 :     struct RaRdmaHandle *rdmaHandleTmp = (struct RaRdmaHandle *)rdevHandle;
    1062              :     unsigned int phyId;
    1063              :     int ret;
    1064              : 
    1065            4 :     CHK_PRT_RETURN(rdevHandle == NULL || rdmaHandleTmp->rdmaOps == NULL ||
    1066              :         rdmaHandleTmp->rdmaOps->raGetTsqpDepth == NULL,
    1067              :         hccp_err("[get][ra_tsqp_depth]rdev_handle is NULL or func is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
    1068              : 
    1069            3 :     CHK_PRT_RETURN(tempDepth == NULL || qpNum == NULL, hccp_err("[get][ra_tsqp_depth]temp_depth or qp_num is NULL"),
    1070              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1071              : 
    1072            2 :     phyId = rdmaHandleTmp->rdevInfo.phyId;
    1073            2 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
    1074              :         hccp_err("[get][ra_tsqp_depth]phyId(%u) is invalid! it must greater or equal to 0 and less than %d!",
    1075              :         phyId, RA_MAX_PHY_ID_NUM), ConverReturnCode(RDMA_OP, -EINVAL));
    1076              : 
    1077            1 :     hccp_info("Input parameters: phyId[%u], rdevIndex[%u]", phyId, rdmaHandleTmp->rdevIndex);
    1078              : 
    1079            1 :     ret = rdmaHandleTmp->rdmaOps->raGetTsqpDepth(rdmaHandleTmp, tempDepth, qpNum);
    1080            1 :     return ConverReturnCode(RDMA_OP, ret);
    1081              : }
    1082              : 
    1083            5 : HCCP_ATTRI_VISI_DEF int RaSetTsqpDepth(void *rdevHandle, unsigned int tempDepth, unsigned int *qpNum)
    1084              : {
    1085            5 :     struct RaRdmaHandle *rdmaHandleTmp = (struct RaRdmaHandle *)rdevHandle;
    1086              :     unsigned int phyId;
    1087              :     int ret;
    1088              : 
    1089            5 :     CHK_PRT_RETURN(rdevHandle == NULL || rdmaHandleTmp->rdmaOps == NULL ||
    1090              :         rdmaHandleTmp->rdmaOps->raSetTsqpDepth == NULL,
    1091              :         hccp_err("[set][ra_tsqp_depth]rdev_handle is NULL or func is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
    1092              : 
    1093            4 :     CHK_PRT_RETURN(qpNum == NULL, hccp_err("[set][ra_tsqp_depth]qp_num is NULL"),
    1094              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1095              : 
    1096            3 :     CHK_PRT_RETURN(tempDepth < RA_MIN_TEMPTH_DEPTH || tempDepth > RA_MAX_TEMPTH_DEPTH,
    1097              :         hccp_err("[set][ra_tsqp_depth]param error! temp_depth(%u) can not smaller than %d or bigger than %d",
    1098              :         tempDepth, RA_MIN_TEMPTH_DEPTH, RA_MAX_TEMPTH_DEPTH), ConverReturnCode(RDMA_OP, -EINVAL));
    1099              : 
    1100            2 :     phyId = rdmaHandleTmp->rdevInfo.phyId;
    1101            2 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
    1102              :         hccp_err("[set][ra_tsqp_depth]phyId(%u) is invalid! it must greater or equal to 0 and less than %d!",
    1103              :         phyId, RA_MAX_PHY_ID_NUM), ConverReturnCode(RDMA_OP, -EINVAL));
    1104              : 
    1105            1 :     hccp_run_info("Input parameters: phyId[%u], rdevIndex[%u], tempDepth[%u]",
    1106              :         phyId, rdmaHandleTmp->rdevIndex, tempDepth);
    1107              : 
    1108            1 :     ret = rdmaHandleTmp->rdmaOps->raSetTsqpDepth(rdmaHandleTmp, tempDepth, qpNum);
    1109            1 :     return ConverReturnCode(RDMA_OP, ret);
    1110              : }
    1111              : 
    1112            9 : HCCP_ATTRI_VISI_DEF int RaQpCreate(void *rdevHandle, int flag, int qpMode, void **qpHandle)
    1113              : {
    1114            9 :     struct RaRdmaHandle *rdmaHandleTmp = (struct RaRdmaHandle *)rdevHandle;
    1115              :     unsigned int phyId;
    1116              :     int ret;
    1117              : 
    1118            9 :     CHK_PRT_RETURN(rdevHandle == NULL || rdmaHandleTmp->rdmaOps == NULL ||
    1119              :         rdmaHandleTmp->rdmaOps->raQpCreate == NULL,
    1120              :         hccp_err("[create][ra_qp]rdev_handle is NULL or func is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
    1121              : 
    1122            6 :     CHK_PRT_RETURN(qpHandle == NULL, hccp_err("[create][ra_qp]qp_handle is NULL"),
    1123              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1124              : 
    1125              :     /* 0 means RC mode */
    1126            5 :     CHK_PRT_RETURN(flag != 0, hccp_err("[create][ra_qp]The flag(%d) is invalid, expect 0", flag),
    1127              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1128              : 
    1129            4 :     phyId = rdmaHandleTmp->rdevInfo.phyId;
    1130            4 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
    1131              :         hccp_err("[create][ra_qp]phyId(%u) must greater or equal to 0 and less than %d!", phyId, RA_MAX_PHY_ID_NUM),
    1132              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1133              : 
    1134            3 :     CHK_PRT_RETURN(qpMode < 0 || qpMode >= RA_RS_ERR_QP_MODE,
    1135              :         hccp_err("[create][ra_qp]QP mode(%d) must greater or equal to 0 and less than %d", qpMode, RA_RS_ERR_QP_MODE),
    1136              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1137              : 
    1138            2 :     hccp_run_info("Input parameters: phyId[%u], flag[%d] qpMode [%d]", phyId, flag, qpMode);
    1139              : 
    1140            2 :     ret = rdmaHandleTmp->rdmaOps->raQpCreate(rdmaHandleTmp, flag, qpMode, qpHandle);
    1141            2 :     CHK_PRT_RETURN(ret != 0 || *qpHandle == NULL,
    1142              :         hccp_err("[create][ra_qp]create qp failed, ret(%d) phyId(%u)", ret, phyId),
    1143              :         ConverReturnCode(RDMA_OP, ret));
    1144              : 
    1145            2 :     return 0;
    1146              : }
    1147              : 
    1148            8 : HCCP_ATTRI_VISI_DEF int RaQpCreateWithAttrs(void *rdevHandle, struct QpExtAttrs *extAttrs, void **qpHandle)
    1149              : {
    1150            8 :     struct RaRdmaHandle *rdmaHandleTmp = (struct RaRdmaHandle *)rdevHandle;
    1151              :     unsigned int phyId;
    1152              :     int ret;
    1153              : 
    1154            8 :     CHK_PRT_RETURN(rdevHandle == NULL || rdmaHandleTmp->rdmaOps == NULL ||
    1155              :         rdmaHandleTmp->rdmaOps->raQpCreateWithAttrs == NULL,
    1156              :         hccp_err("[create][ra_qp_with_attrs]rdev_handle is NULL or func is NULL"),
    1157              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1158              : 
    1159            6 :     CHK_PRT_RETURN(qpHandle == NULL, hccp_err("[create][ra_qp_with_attrs]qp_handle is NULL"),
    1160              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1161              : 
    1162            5 :     CHK_PRT_RETURN(extAttrs == NULL, hccp_err("[create][ra_qp_with_attrs]ext_attrs is NULL"),
    1163              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1164              : 
    1165            4 :     CHK_PRT_RETURN(extAttrs->version != QP_CREATE_WITH_ATTR_VERSION,
    1166              :         hccp_err("[create][ra_qp_with_attrs]attr version[%d] mismatch, expect [%d]", extAttrs->version,
    1167              :         QP_CREATE_WITH_ATTR_VERSION), ConverReturnCode(RDMA_OP, -EINVAL));
    1168              : 
    1169            3 :     CHK_PRT_RETURN(extAttrs->qpMode < 0 || extAttrs->qpMode >= RA_RS_ERR_QP_MODE,
    1170              :         hccp_err("[create][ra_qp_with_attrs]QP mode[%d] must greater or equal to 0 and less than %d",
    1171              :         extAttrs->qpMode, RA_RS_ERR_QP_MODE), ConverReturnCode(RDMA_OP, -EINVAL));
    1172              :     // no need and disallow to set data_plane_flag, set it to default value 0
    1173            2 :     extAttrs->dataPlaneFlag.value = 0;
    1174              : 
    1175            2 :     phyId = rdmaHandleTmp->rdevInfo.phyId;
    1176            2 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
    1177              :         hccp_err("[create][ra_qp_with_attrs]phyId(%u) must greater or equal to 0 and less than %d!", phyId,
    1178              :         RA_MAX_PHY_ID_NUM), ConverReturnCode(RDMA_OP, -EINVAL));
    1179              : 
    1180            1 :     hccp_run_info("Input parameters: phyId[%u] qp_mode[%d] cq_attr{%d,%d,%d,%d} qpAttr.cap{%u,%u,%u,%u,%u}"\
    1181              :         " qp_type[%u] sqSigAll[%d], cnt[%u], useResvMem[%u], resvMemPoolId[%u]", phyId, extAttrs->qpMode,
    1182              :         extAttrs->cqAttr.sendCqDepth, extAttrs->cqAttr.sendCqCompVector,
    1183              :         extAttrs->cqAttr.recvCqDepth, extAttrs->cqAttr.recvCqCompVector,
    1184              :         extAttrs->qpAttr.cap.max_send_wr, extAttrs->qpAttr.cap.max_recv_wr,
    1185              :         extAttrs->qpAttr.cap.max_send_sge, extAttrs->qpAttr.cap.max_recv_sge,
    1186              :         extAttrs->qpAttr.cap.max_inline_data, extAttrs->qpAttr.qp_type, extAttrs->qpAttr.sq_sig_all,
    1187              :         rdmaHandleTmp->qpCnt, extAttrs->cstmFlag.bs.useResvMem, extAttrs->resvMemPoolId);
    1188              : 
    1189            1 :     rdmaHandleTmp->qpCnt++;
    1190            1 :     ret = rdmaHandleTmp->rdmaOps->raQpCreateWithAttrs(rdmaHandleTmp, extAttrs, qpHandle);
    1191            1 :     CHK_PRT_RETURN(ret != 0 || *qpHandle == NULL,
    1192              :         hccp_err("[create][ra_qp_with_attrs]create qp failed, ret(%d) phyId(%u)", ret, phyId),
    1193              :         ConverReturnCode(RDMA_OP, ret));
    1194              : 
    1195            1 :     return 0;
    1196              : }
    1197              : 
    1198            6 : HCCP_ATTRI_VISI_DEF int RaAiQpCreate(void *rdevHandle, struct QpExtAttrs *attrs, struct AiQpInfo *info,
    1199              :     void **qpHandle)
    1200              : {
    1201            6 :     struct RaRdmaHandle *rdmaHandleTmp = (struct RaRdmaHandle *)rdevHandle;
    1202            6 :     unsigned int interfaceVersion = 0;
    1203              :     unsigned int phyId;
    1204              :     int ret;
    1205              : 
    1206            6 :     CHK_PRT_RETURN(rdevHandle == NULL || rdmaHandleTmp->rdmaOps == NULL ||
    1207              :         rdmaHandleTmp->rdmaOps->raAiQpCreate == NULL ||
    1208              :         rdmaHandleTmp->rdmaOps->raAiQpCreateWithAttrs == NULL,
    1209              :         hccp_err("[create][ra_ai_qp]rdev_handle is NULL or func is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
    1210              : 
    1211            5 :     CHK_PRT_RETURN(info == NULL || qpHandle == NULL, hccp_err("[create][ra_ai_qp]info is NULL or qp_handle is NULL"),
    1212              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1213              : 
    1214            4 :     CHK_PRT_RETURN(attrs == NULL, hccp_err("[create][ra_ai_qp]attrs is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
    1215              : 
    1216            3 :     CHK_PRT_RETURN(attrs->version != QP_CREATE_WITH_ATTR_VERSION,
    1217              :         hccp_err("[create][ra_ai_qp]attr version[%d] mismatch, expect [%d]", attrs->version,
    1218              :         QP_CREATE_WITH_ATTR_VERSION), ConverReturnCode(RDMA_OP, -EINVAL));
    1219              : 
    1220            2 :     CHK_PRT_RETURN(attrs->qpMode < 0 || attrs->qpMode >= RA_RS_ERR_QP_MODE,
    1221              :         hccp_err("[create][ra_ai_qp]QP mode[%d] must greater or equal to 0 and less than %d", attrs->qpMode,
    1222              :         RA_RS_ERR_QP_MODE), ConverReturnCode(RDMA_OP, -EINVAL));
    1223              : 
    1224            1 :     phyId = rdmaHandleTmp->rdevInfo.phyId;
    1225            1 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
    1226              :         hccp_err("[create][ra_ai_qp]phyId(%u) must greater or equal to 0 and less than %d!", phyId,
    1227              :         RA_MAX_PHY_ID_NUM), ConverReturnCode(RDMA_OP, -EINVAL));
    1228              : 
    1229            1 :     hccp_run_info("Input parameters: phyId[%u] qp_mode[%d] cq_attr{%d,%d,%d,%d} cqCstm[%d] "
    1230              :         "qpAttr.cap{%u,%u,%u,%u,%u} qp_type[%u] sqSigAll[%d]", phyId, attrs->qpMode,
    1231              :         attrs->cqAttr.sendCqDepth, attrs->cqAttr.sendCqCompVector,
    1232              :         attrs->cqAttr.recvCqDepth, attrs->cqAttr.recvCqCompVector, attrs->dataPlaneFlag.bs.cqCstm,
    1233              :         attrs->qpAttr.cap.max_send_wr, attrs->qpAttr.cap.max_recv_wr,
    1234              :         attrs->qpAttr.cap.max_send_sge, attrs->qpAttr.cap.max_recv_sge,
    1235              :         attrs->qpAttr.cap.max_inline_data, attrs->qpAttr.qp_type, attrs->qpAttr.sq_sig_all);
    1236              : 
    1237            1 :     ret = RaGetInterfaceVersion(phyId, RA_RS_AI_QP_CREATE_WITH_ATTRS, &interfaceVersion);
    1238            1 :     if (ret == 0 && interfaceVersion >= RA_RS_OPCODE_BASE_VERSION) {
    1239            1 :         ret = rdmaHandleTmp->rdmaOps->raAiQpCreateWithAttrs(rdmaHandleTmp, attrs, info, qpHandle);
    1240              :     } else {
    1241              :         // origin procedure: not support to process data_plane_flag.bs.cq_cstm
    1242            0 :         ret = rdmaHandleTmp->rdmaOps->raAiQpCreate(rdmaHandleTmp, attrs, info, qpHandle);
    1243              :     }
    1244            1 :     CHK_PRT_RETURN(ret != 0 || *qpHandle == NULL, hccp_err("[create][ra_ai_qp]create qp failed, ret(%d) phyId(%u)",
    1245              :         ret, phyId), ConverReturnCode(RDMA_OP, ret));
    1246              : 
    1247            1 :     return 0;
    1248              : }
    1249              : 
    1250            8 : HCCP_ATTRI_VISI_DEF int RaTypicalQpCreate(void *rdevHandle, int flag, int qpMode, struct TypicalQp *qpInfo,
    1251              :     void **qpHandle)
    1252              : {
    1253            8 :     struct RaRdmaHandle *rdmaHandleTmp = (struct RaRdmaHandle *)rdevHandle;
    1254              :     unsigned int phyId;
    1255              :     int ret;
    1256              : 
    1257            8 :     CHK_PRT_RETURN(rdevHandle == NULL || rdmaHandleTmp->rdmaOps == NULL ||
    1258              :         rdmaHandleTmp->rdmaOps->raTypicalQpCreate == NULL,
    1259              :         hccp_err("[create][ra_typical_qp]rdev_handle is NULL or func is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
    1260              : 
    1261            6 :     CHK_PRT_RETURN(qpHandle == NULL, hccp_err("[create][ra_typical_qp]qp_handle is NULL"),
    1262              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1263              : 
    1264            5 :     CHK_PRT_RETURN(qpInfo == NULL, hccp_err("[create][ra_typical_qp]qp_info is NULL"),
    1265              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1266              : 
    1267            4 :     CHK_PRT_RETURN(flag != 0, hccp_err("[create][ra_typical_qp]The flag(%d) is invalid, expect 0", flag),
    1268              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1269              : 
    1270            3 :     phyId = rdmaHandleTmp->rdevInfo.phyId;
    1271            3 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
    1272              :         hccp_err("[create][ra_typical_qp]phyId(%u) must greater or equal to 0 and less than %d!", phyId,
    1273              :         RA_MAX_PHY_ID_NUM), ConverReturnCode(RDMA_OP, -EINVAL));
    1274              : 
    1275            2 :     CHK_PRT_RETURN(qpMode < 0 || qpMode >= RA_RS_ERR_QP_MODE,
    1276              :         hccp_err("[create][ra_typical_qp]QP mode(%d) must greater or equal to 0 and less than %d", qpMode,
    1277              :         RA_RS_ERR_QP_MODE), ConverReturnCode(RDMA_OP, -EINVAL));
    1278              : 
    1279            1 :     hccp_run_info("Input parameters: phyId[%u], flag[%d] qpMode[%d]", phyId, flag, qpMode);
    1280              : 
    1281            1 :     ret = rdmaHandleTmp->rdmaOps->raTypicalQpCreate(rdmaHandleTmp, flag, qpMode, qpInfo, qpHandle);
    1282            1 :     CHK_PRT_RETURN(ret != 0 || *qpHandle == NULL,
    1283              :         hccp_err("[create][ra_typical_qp]create qp failed, ret(%d) phyId(%u)", ret, phyId),
    1284              :         ConverReturnCode(RDMA_OP, ret));
    1285              : 
    1286            1 :     return 0;
    1287              : }
    1288              : 
    1289            6 : HCCP_ATTRI_VISI_DEF int RaLoopbackQpCreate(void *rdevHandle, struct LoopbackQpPair *qpPair, void **qpHandle)
    1290              : {
    1291            6 :     struct RaRdmaHandle *rdmaHandleTmp = (struct RaRdmaHandle *)rdevHandle;
    1292              :     unsigned int phyId;
    1293              :     int ret;
    1294              : 
    1295            6 :     CHK_PRT_RETURN(rdmaHandleTmp == NULL || rdmaHandleTmp->rdmaOps == NULL ||
    1296              :         rdmaHandleTmp->rdmaOps->raLoopbackQpCreate == NULL,
    1297              :         hccp_err("[create][ra_loopback_qp]rdev_handle is NULL or func is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
    1298              : 
    1299            5 :     CHK_PRT_RETURN(qpPair == NULL, hccp_err("[create][ra_loopback_qp]qp_pair is NULL"),
    1300              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1301              : 
    1302            4 :     CHK_PRT_RETURN(qpHandle == NULL, hccp_err("[create][ra_loopback_qp]qp_handle is NULL"),
    1303              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1304              : 
    1305            3 :     phyId = rdmaHandleTmp->rdevInfo.phyId;
    1306            3 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
    1307              :         hccp_err("[create][ra_loopback_qp]phyId(%u) must greater or equal to 0 and less than %d!", phyId, RA_MAX_PHY_ID_NUM),
    1308              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1309              : 
    1310            2 :     hccp_run_info("Input parameters: phyId[%u]", phyId);
    1311            2 :     ret = rdmaHandleTmp->rdmaOps->raLoopbackQpCreate(rdmaHandleTmp, qpPair, qpHandle);
    1312            2 :     CHK_PRT_RETURN(ret != 0 || *qpHandle == NULL,
    1313              :         hccp_err("[create][ra_loopback_qp]create qp failed, ret(%d) phyId(%u)", ret, phyId),
    1314              :         ConverReturnCode(RDMA_OP, ret));
    1315              : 
    1316            1 :     return 0;
    1317              : }
    1318              : 
    1319            9 : HCCP_ATTRI_VISI_DEF int RaQpDestroy(void *qpHandle)
    1320              : {
    1321            9 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    1322              :     int ret;
    1323              : 
    1324            9 :     CHK_PRT_RETURN(qpHandle == NULL,
    1325              :         hccp_err("[destroy][ra_qp]qp_handle is NULL"),
    1326              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1327              : 
    1328            8 :     CHK_PRT_RETURN(raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raQpDestroy == NULL,
    1329              :         hccp_err("[destroy][ra_qp]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_qp_destroy is NULL, invalid"),
    1330              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1331              : 
    1332            7 :     hccp_run_info("Input parameters: qpn[%u], phyId[%u], rdevIndex[%u] qpMode[%d] flag[%d]",
    1333              :         raQpHandle->qpn, raQpHandle->phyId, raQpHandle->rdevIndex, raQpHandle->qpMode, raQpHandle->flag);
    1334              : 
    1335            7 :     ret = raQpHandle->rdmaOps->raQpDestroy(raQpHandle);
    1336            7 :     return ConverReturnCode(RDMA_OP, ret);
    1337              : }
    1338              : 
    1339            3 : HCCP_ATTRI_VISI_DEF int RaQpConnectAsync(void *qpHandle, const void *fdHandle)
    1340              : {
    1341            3 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    1342              :     int ret;
    1343              : 
    1344            3 :     CHK_PRT_RETURN(qpHandle == NULL || fdHandle == NULL,
    1345              :         hccp_err("[connect_async][ra_qp]ra_qp_handle or fd_handle is NULL, para error!"),
    1346              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1347              : 
    1348            2 :     CHK_PRT_RETURN(raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raQpConnectAsync == NULL,
    1349              :         hccp_err("[connect_async][ra_qp]rdma_ops or ra_qp_handle->rdma_ops->ra_qp_connect_async is NULL, invalid"),
    1350              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1351              : 
    1352            1 :     ret = raQpHandle->rdmaOps->raQpConnectAsync(raQpHandle, fdHandle);
    1353            1 :     return ConverReturnCode(RDMA_OP, ret);
    1354              : }
    1355              : 
    1356            3 : HCCP_ATTRI_VISI_DEF int RaGetQpStatus(void *qpHandle, int *status)
    1357              : {
    1358            3 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    1359              :     int ret;
    1360              : 
    1361            3 :     CHK_PRT_RETURN(qpHandle == NULL || status == NULL,
    1362              :         hccp_err("[get][ra_qp_status]ra_qp_handle or status is NULL, para error!"),
    1363              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1364              : 
    1365            2 :     CHK_PRT_RETURN(raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raGetQpStatus == NULL,
    1366              :         hccp_err("[get][ra_qp_status]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_get_qp_status is NULL, invalid"),
    1367              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1368              : 
    1369            1 :     ret = raQpHandle->rdmaOps->raGetQpStatus(raQpHandle, status);
    1370            1 :     return ConverReturnCode(RDMA_OP, ret);
    1371              : }
    1372              : 
    1373            3 : HCCP_ATTRI_VISI_DEF int RaMrReg(void *qpHandle, struct MrInfoT *info)
    1374              : {
    1375            3 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    1376              :     int ret;
    1377              : 
    1378            3 :     CHK_PRT_RETURN(qpHandle == NULL || info == NULL,
    1379              :         hccp_err("[reg][ra_mr]qp_handle is NULL or info is NULL, para error!"),
    1380              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1381              : 
    1382            2 :     CHK_PRT_RETURN(raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raMrReg == NULL,
    1383              :         hccp_err("[reg][ra_mr]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_mr_reg is NULL, invalid"),
    1384              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1385              : 
    1386            1 :     ret = raQpHandle->rdmaOps->raMrReg(raQpHandle, info);
    1387            1 :     return ConverReturnCode(RDMA_OP, ret);
    1388              : }
    1389              : 
    1390            3 : HCCP_ATTRI_VISI_DEF int RaMrDereg(void *qpHandle, struct MrInfoT *info)
    1391              : {
    1392            3 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    1393              :     int ret;
    1394              : 
    1395            3 :     CHK_PRT_RETURN(qpHandle == NULL || info == NULL || info->addr == NULL,
    1396              :         hccp_err("[dereg][ra_mr]qp_handle or info or addr is NULL, para error!"),
    1397              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1398              : 
    1399            2 :     CHK_PRT_RETURN(raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raMrDereg == NULL,
    1400              :         hccp_err("[dereg][ra_mr]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_mr_dereg is NULL, invalid"),
    1401              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1402              : 
    1403            1 :     ret = raQpHandle->rdmaOps->raMrDereg(raQpHandle, info);
    1404            1 :     return ConverReturnCode(RDMA_OP, ret);
    1405              : }
    1406              : 
    1407            3 : HCCP_ATTRI_VISI_DEF int RaSendWr(void *qpHandle, struct SendWr *wr, struct SendWrRsp *opRsp)
    1408              : {
    1409            3 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    1410              :     int ret;
    1411              : 
    1412            3 :     CHK_PRT_RETURN(qpHandle == NULL || wr == NULL || wr->bufList == NULL || opRsp == NULL,
    1413              :         hccp_err("[send][ra_wr]qp_handle or wr or buf_list or op_rsp is NULL, para error!"),
    1414              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1415              : 
    1416            2 :     CHK_PRT_RETURN(wr->bufList->len > MAX_SG_LIST_LEN_MAX,
    1417              :         hccp_err("[send][ra_wr]sg list len is more than 2G, len(%u)", wr->bufList->len),
    1418              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1419              : 
    1420            2 :     CHK_PRT_RETURN(raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raSendWr == NULL,
    1421              :         hccp_err("[send][ra_wr]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_send_wr is NULL, invalid"),
    1422              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1423              : 
    1424            1 :     ret = raQpHandle->rdmaOps->raSendWr(raQpHandle, wr, opRsp);
    1425            1 :     RaRdevIncSendWrNum();
    1426            1 :     return ConverReturnCode(RDMA_OP, ret);
    1427              : }
    1428              : 
    1429            4 : HCCP_ATTRI_VISI_DEF int RaSendWrV2(void *qpHandle, struct SendWrV2 *wr, struct SendWrRsp *opRsp)
    1430              : {
    1431            4 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    1432              :     int ret;
    1433              : 
    1434            4 :     CHK_PRT_RETURN(qpHandle == NULL || wr == NULL || wr->bufList == NULL || opRsp == NULL,
    1435              :         hccp_err("[send][ra_wr]qp_handle or wr or buf_list or op_rsp is NULL, para error!"),
    1436              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1437              : 
    1438            3 :     CHK_PRT_RETURN(wr->bufList->len > MAX_SG_LIST_LEN_MAX,
    1439              :         hccp_err("[send][ra_wr]sg list len is more than 2G, len(%u)", wr->bufList->len),
    1440              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1441              : 
    1442            2 :     CHK_PRT_RETURN(raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raSendWrV2 == NULL,
    1443              :         hccp_err("[send][ra_wr]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_send_wr_v2 is NULL, invalid"),
    1444              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1445              : 
    1446            1 :     ret = raQpHandle->rdmaOps->raSendWrV2(raQpHandle, wr, opRsp);
    1447            1 :     RaRdevIncSendWrNum();
    1448            1 :     return ConverReturnCode(RDMA_OP, ret);
    1449              : }
    1450              : 
    1451            5 : HCCP_ATTRI_VISI_DEF int RaSendWrlist(void *qpHandle, struct SendWrlistData wr[], struct SendWrRsp opRsp[],
    1452              :     unsigned int sendNum, unsigned int *completeNum)
    1453              : {
    1454              :     int ret;
    1455              :     unsigned int i;
    1456            5 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    1457            5 :     struct WrlistSendCompleteNum wrlistNum = {0};
    1458              : 
    1459            5 :     CHK_PRT_RETURN(qpHandle == NULL || wr == NULL || opRsp == NULL || sendNum == 0 || completeNum == NULL,
    1460              :         hccp_err("[send][ra_wrlist]qp_handle or wr or op_rsp or complete_num is NULL or send_num is zero, para error!"),
    1461              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1462              : 
    1463            5 :     for (i = 0; i < sendNum; i++) {
    1464            3 :         if (wr[i].memList.len > MAX_SG_LIST_LEN_MAX) {
    1465            1 :             hccp_err("[send][ra_wrlist]sg list len is more than 2G, len(%u)", wr[i].memList.len);
    1466            1 :             return ConverReturnCode(RDMA_OP, -EINVAL);
    1467              :         }
    1468              :     }
    1469              : 
    1470            2 :     CHK_PRT_RETURN(raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raSendWrlist == NULL,
    1471              :         hccp_err("[send][ra_wrlist]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_send_wr is NULL, invalid"),
    1472              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1473              : 
    1474            0 :     wrlistNum.sendNum = sendNum;
    1475            0 :     wrlistNum.completeNum = completeNum;
    1476            0 :     ret = raQpHandle->rdmaOps->raSendWrlist(raQpHandle, wr, opRsp, wrlistNum);
    1477            0 :     return ConverReturnCode(RDMA_OP, ret);
    1478              : }
    1479              : 
    1480            1 : HCCP_ATTRI_VISI_DEF int RaSendWrlistExt(void *qpHandle, struct SendWrlistDataExt wr[],
    1481              :     struct SendWrRsp opRsp[], unsigned int sendNum, unsigned int *completeNum)
    1482              : {
    1483            1 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    1484            1 :     struct WrlistSendCompleteNum wrlistNum = {0};
    1485              :     unsigned int i;
    1486              :     int ret;
    1487              : 
    1488            1 :     CHK_PRT_RETURN(qpHandle == NULL || wr == NULL || opRsp == NULL || sendNum == 0 || completeNum == NULL,
    1489              :         hccp_err("[send][ra_wrlist]qp_handle or wr or op_rsp or complete_num is NULL"\
    1490              :             "or send_num is zero, para error!"),
    1491              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1492              : 
    1493            2 :     for (i = 0; i < sendNum; i++) {
    1494            1 :         if (wr[i].memList.len > MAX_SG_LIST_LEN_MAX) {
    1495            0 :             hccp_err("[send][ra_wrlist]sg list len is more than 2G, len(%u)", wr[i].memList.len);
    1496            0 :             return ConverReturnCode(RDMA_OP, -EINVAL);
    1497              :         }
    1498              :     }
    1499              : 
    1500            1 :     CHK_PRT_RETURN(raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raSendWrlistExt == NULL,
    1501              :         hccp_err("[send][ra_wrlist]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_send_wr is NULL, invalid"),
    1502              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1503              : 
    1504            0 :     wrlistNum.sendNum = sendNum;
    1505            0 :     wrlistNum.completeNum = completeNum;
    1506            0 :     ret = raQpHandle->rdmaOps->raSendWrlistExt(raQpHandle, wr, opRsp, wrlistNum);
    1507            0 :     return ConverReturnCode(RDMA_OP, ret);
    1508              : }
    1509              : 
    1510            3 : HCCP_ATTRI_VISI_DEF int RaGetNotifyBaseAddr(void *rdevHandle, unsigned long long *va, unsigned long long *size)
    1511              : {
    1512            3 :     struct RaRdmaHandle *rdevHandleTmp = (struct RaRdmaHandle *)rdevHandle;
    1513              :     int ret;
    1514              : 
    1515            3 :     CHK_PRT_RETURN(rdevHandle == NULL || va == NULL || size == NULL,
    1516              :         hccp_err("[get][ra_notify_base_addr]rdev_handle or va or size is NULL, invalid"),
    1517              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1518              : 
    1519            2 :     CHK_PRT_RETURN(rdevHandleTmp->rdmaOps == NULL || rdevHandleTmp->rdmaOps->raGetNotifyBaseAddr == NULL,
    1520              :         hccp_err("[get][ra_notify_base_addr]rdma_ops is NULL or ra_get_notify_base_addr is NULL, invalid"),
    1521              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1522              : 
    1523            2 :     ret = rdevHandleTmp->rdmaOps->raGetNotifyBaseAddr(rdevHandleTmp, va, size);
    1524            2 :     RaRdevSaveNotifyMr(rdevHandleTmp, ret, *va, *size);
    1525            2 :     return ConverReturnCode(RDMA_OP, ret);
    1526              : }
    1527              : 
    1528            3 : HCCP_ATTRI_VISI_DEF int RaGetNotifyMrInfo(void *rdevHandle, struct MrInfoT *info)
    1529              : {
    1530            3 :     struct RaRdmaHandle *rdevHandleTmp = (struct RaRdmaHandle *)rdevHandle;
    1531              :     int ret;
    1532              : 
    1533            3 :     CHK_PRT_RETURN(rdevHandle == NULL || info == NULL,
    1534              :         hccp_err("[get][ra_notify_mr_info]rdev_handle or info is NULL, invalid"),
    1535              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1536              : 
    1537            2 :     CHK_PRT_RETURN(rdevHandleTmp->rdmaOps == NULL || rdevHandleTmp->rdmaOps->raGetNotifyMrInfo == NULL,
    1538              :         hccp_err("[get][ra_notify_mr_info]rdma_ops is NULL or ra_get_notify_mr_info is NULL, invalid"),
    1539              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1540              : 
    1541            2 :     ret = rdevHandleTmp->rdmaOps->raGetNotifyMrInfo(rdevHandleTmp, info);
    1542            2 :     RaRdevSaveNotifyMr(rdevHandleTmp, ret, (uint64_t)(uintptr_t)info->addr, info->size);
    1543            2 :     return ConverReturnCode(RDMA_OP, ret);
    1544              : }
    1545              : 
    1546            3 : HCCP_ATTRI_VISI_DEF int RaSocketGetWhiteListStatus(unsigned int *enable)
    1547              : {
    1548            3 :     CHK_PRT_RETURN(enable == NULL, hccp_err("[get][ra_socket_white_list_status]white list switch enable is NULL"),
    1549              :         ConverReturnCode(SOCKET_OP, -EINVAL));
    1550              : 
    1551            2 :     *enable = gWhiteListSwitch;
    1552            2 :     hccp_info("white list status: enable[%u]", *enable);
    1553            2 :     return 0;
    1554              : }
    1555              : 
    1556            4 : HCCP_ATTRI_VISI_DEF int RaSocketSetWhiteListStatus(unsigned int enable)
    1557              : {
    1558            4 :     hccp_run_info("Input parameters: enable[%u]", enable);
    1559              : 
    1560            4 :     CHK_PRT_RETURN(enable != WHITE_LIST_DISABLE && enable != WHITE_LIST_ENABLE,
    1561              :         hccp_err("[set][ra_socket_white_list_status]white list switch is invalid, enable(%u)", enable),
    1562              :         ConverReturnCode(SOCKET_OP, -EINVAL));
    1563              : 
    1564            3 :     gWhiteListSwitch = enable;
    1565            3 :     return 0;
    1566              : }
    1567              : 
    1568            3 : HCCP_ATTRI_VISI_DEF int RaSocketWhiteListAdd(void *socketHandle, struct SocketWlistInfoT whiteList[],
    1569              :     unsigned int num)
    1570              : {
    1571            3 :     struct RaSocketHandle *socketHandleTmp = NULL;
    1572            3 :     char localIp[MAX_IP_LEN] = {0};
    1573              :     unsigned int phyId;
    1574              :     int ret;
    1575              : 
    1576            3 :     CHK_PRT_RETURN(whiteList == NULL || num > MAX_WLIST_NUM || num == 0,
    1577              :         hccp_err("[add][ra_socket_white_list]white_list is NULL, or num(%u) > %u or = 0, invalid",
    1578              :             num, MAX_WLIST_NUM),
    1579              :         ConverReturnCode(SOCKET_OP, -EINVAL));
    1580              : 
    1581            2 :     socketHandleTmp = (struct RaSocketHandle *)socketHandle;
    1582            2 :     if (socketHandleTmp == NULL || socketHandleTmp->socketOps == NULL ||
    1583            2 :         socketHandleTmp->socketOps->raSocketWhiteListAdd == NULL) {
    1584            0 :         hccp_err("[add][ra_socket_white_list]socket_handle or func is NULL");
    1585            0 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    1586              :     }
    1587              : 
    1588            2 :     ret = RaInetPton(socketHandleTmp->rdevInfo.family, socketHandleTmp->rdevInfo.localIp,
    1589              :                        localIp, MAX_IP_LEN);
    1590            2 :     CHK_PRT_RETURN(ret, hccp_err("[add][ra_socket_white_list]ra_inet_pton for local_ip failed, ret(%d)", ret),
    1591              :         ConverReturnCode(SOCKET_OP, ret));
    1592              : 
    1593            2 :     phyId = socketHandleTmp->rdevInfo.phyId;
    1594            2 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
    1595              :         hccp_err("[add][ra_socket_white_list]phyId(%u) must smaller than %u", phyId, RA_MAX_PHY_ID_NUM),
    1596              :         ConverReturnCode(SOCKET_OP, -EINVAL));
    1597              : 
    1598            1 :     hccp_info("Input parameters: phyId[%u], localIp[%s], num[%u]", phyId, localIp, num);
    1599              : 
    1600            1 :     ret = socketHandleTmp->socketOps->raSocketWhiteListAdd(socketHandleTmp->rdevInfo, whiteList, num);
    1601            1 :     return ConverReturnCode(SOCKET_OP, ret);
    1602              : }
    1603              : 
    1604            3 : HCCP_ATTRI_VISI_DEF int RaSocketWhiteListDel(void *socketHandle, struct SocketWlistInfoT whiteList[],
    1605              :     unsigned int num)
    1606              : {
    1607            3 :     struct RaSocketHandle *socketHandleTmp = NULL;
    1608            3 :     char localIp[MAX_IP_LEN] = {0};
    1609              :     unsigned int phyId;
    1610              :     int ret;
    1611              : 
    1612            3 :     if (whiteList == NULL || num > MAX_WLIST_NUM || num == 0) {
    1613            1 :         hccp_err("[del][ra_socket_white_list]white_list is NULL, or num (%u) > %u or = 0, invalid", num, MAX_WLIST_NUM);
    1614            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    1615              :     }
    1616            2 :     socketHandleTmp = (struct RaSocketHandle *)socketHandle;
    1617            2 :     if (socketHandleTmp == NULL || socketHandleTmp->socketOps == NULL ||
    1618            2 :         socketHandleTmp->socketOps->raSocketWhiteListDel == NULL) {
    1619            0 :         hccp_err("[del][ra_socket_white_list]socket_handle or func is NULL");
    1620            0 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    1621              :     }
    1622            2 :     ret = RaInetPton(socketHandleTmp->rdevInfo.family, socketHandleTmp->rdevInfo.localIp, localIp,
    1623              :         MAX_IP_LEN);
    1624            2 :     if (ret) {
    1625            0 :         hccp_err("[del][ra_socket_white_list]ra_inet_pton for local_ip failed, ret(%d)", ret);
    1626            0 :         return ConverReturnCode(SOCKET_OP, ret);
    1627              :     }
    1628              : 
    1629            2 :     phyId = socketHandleTmp->rdevInfo.phyId;
    1630            2 :     if (phyId >= RA_MAX_PHY_ID_NUM) {
    1631            1 :         hccp_err("[del][ra_socket_white_list]phyId(%u) must smaller than %u", phyId, RA_MAX_PHY_ID_NUM);
    1632            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    1633              :     }
    1634              : 
    1635            1 :     hccp_info("Input parameters: phyId[%u], localIp[%s], num[%u]", phyId, localIp, num);
    1636              : 
    1637            1 :     ret = socketHandleTmp->socketOps->raSocketWhiteListDel(socketHandleTmp->rdevInfo, whiteList, num);
    1638            1 :     return ConverReturnCode(SOCKET_OP, ret);
    1639              : }
    1640              : 
    1641           12 : STATIC int RaIfaddrInfoConverter(unsigned int phyId, bool isAll, struct InterfaceInfo interfaceInfos[],
    1642              :     unsigned int *num)
    1643              : {
    1644           12 :     struct IfaddrInfo *ifaddrInfos = NULL;
    1645           12 :     unsigned int interfaceVersionV2 = 0;
    1646           12 :     unsigned int interfaceVersion = 0;
    1647              :     unsigned int i;
    1648              :     int ret;
    1649              : 
    1650           12 :     ret = RaGetInterfaceVersion(phyId, RA_RS_GET_IFADDRS, &interfaceVersion);
    1651           12 :     CHK_PRT_RETURN(ret != 0 || interfaceVersion == 0,
    1652              :         hccp_err("[converter][ra_ifaddr]get interface version failed, ret(%d), phyId(%u), interfaceVersion(%u)",
    1653              :             ret, phyId, interfaceVersion), -EINVAL);
    1654              : 
    1655            9 :     ret = RaGetInterfaceVersion(phyId, RA_RS_GET_IFADDRS_V2, &interfaceVersionV2);
    1656            9 :     CHK_PRT_RETURN(ret != 0,
    1657              :         hccp_err("[converter][ra_ifaddr]get interface version failed, ret(%d), phyId(%u), interfaceVersion(%u)",
    1658              :             ret, phyId, interfaceVersion), -EINVAL);
    1659              : 
    1660            9 :     CHK_PRT_RETURN(interfaceVersionV2 < GET_IFADDRS_VERSION_3 && isAll,
    1661              :         hccp_err("[converter][ra_ifaddr]current version do not support get all device ip addr, interfaceVersion(%u), "
    1662              :             "interfaceVersionV2(%u), isAll(%d)", interfaceVersion, interfaceVersionV2, isAll), -EPROTONOSUPPORT);
    1663              : 
    1664            9 :     if (interfaceVersion == GET_IFADDRS_VERSION_1) {
    1665            3 :         ifaddrInfos = calloc(*num, sizeof(struct IfaddrInfo));
    1666            3 :         if (ifaddrInfos == NULL) {
    1667            1 :             hccp_err("[converter][ra_ifaddr]calloc for ifaddr_infos failed");
    1668            1 :             return -EINVAL;
    1669              :         }
    1670              : 
    1671            2 :         ret = RaHdcGetIfaddrs(phyId, ifaddrInfos, num);
    1672            2 :         if (ret) {
    1673            1 :             hccp_err("[converter][ra_ifaddr]ra_hdc_get_ifaddrs failed, ret(%d), phyId(%u), num(%u)",
    1674              :                 ret, phyId, *num);
    1675            1 :             free(ifaddrInfos);
    1676            1 :             return ret;
    1677              :         }
    1678              : 
    1679            5 :         for (i = 0; i < *num; i++) {
    1680              :             // device 网卡只支持IPv4
    1681            4 :             interfaceInfos[i].family = AF_INET;
    1682            4 :             interfaceInfos[i].scopeId = 0;
    1683            4 :             ret = memcpy_s(&(interfaceInfos[i].ifaddr.ip), sizeof(union HccpIpAddr), &(ifaddrInfos[i].ip),
    1684              :                 sizeof(union HccpIpAddr));
    1685            4 :             if (ret) {
    1686            0 :                 hccp_err("[converter][ra_ifaddr]memcpy_s interface[%u] ip failed, ret(%d)", i, ret);
    1687            0 :                 free(ifaddrInfos);
    1688            0 :                 return -ESAFEFUNC;
    1689              :             }
    1690              : 
    1691            4 :             ret = memcpy_s(&(interfaceInfos[i].ifaddr.mask), sizeof(struct in_addr), &(ifaddrInfos[i].mask),
    1692              :                 sizeof(struct in_addr));
    1693            4 :             if (ret) {
    1694            0 :                 hccp_err("[converter][ra_ifaddr]memcpy_s interface[%u] mask failed, ret(%d)", i, ret);
    1695            0 :                 free(ifaddrInfos);
    1696            0 :                 return -ESAFEFUNC;
    1697              :             }
    1698              :         }
    1699              : 
    1700            1 :         free(ifaddrInfos);
    1701            6 :     } else if (interfaceVersion == GET_IFADDRS_VERSION_2) { /* version 2 support IPV6 and IPV4 */
    1702            5 :         ret = RaHdcGetIfaddrsV2(phyId, isAll, interfaceInfos, num);
    1703            5 :         CHK_PRT_RETURN(ret,
    1704              :             hccp_err("[converter][ra_ifaddr]ra_hdc_get_ifaddrs_v2 failed, ret(%d), phyId(%u), isAll(%d), num(%u)",
    1705              :                 ret, phyId, isAll, *num), ret);
    1706              :     } else {
    1707            1 :         hccp_err("[converter][ra_ifaddr]interface version not support, interfaceVersion(%u)", interfaceVersion);
    1708            1 :         return -EINVAL;
    1709              :     }
    1710              : 
    1711            4 :     return 0;
    1712              : }
    1713              : 
    1714           10 : HCCP_ATTRI_VISI_DEF int RaGetIfnum(struct RaGetIfattr *config, unsigned int *num)
    1715              : {
    1716           10 :     unsigned int interfaceVersion = 0;
    1717              :     int ret;
    1718              : 
    1719           10 :     CHK_PRT_RETURN(config == NULL || num == NULL, hccp_err("[get][ra_ifnum]config or num is NULL"),
    1720              :         ConverReturnCode(OTHERS, -EINVAL));
    1721              : 
    1722            9 :     CHK_PRT_RETURN(config->phyId >= RA_MAX_PHY_ID_NUM,
    1723              :         hccp_err("[get][ra_ifnum]phyId(%u) is invalid! it must greater or equal to 0 and less than %d!",
    1724              :         config->phyId, RA_MAX_PHY_ID_NUM),
    1725              :         ConverReturnCode(OTHERS, -EINVAL));
    1726              : 
    1727            7 :     hccp_run_info("Input parameters: phyId[%u], nicPosition:[%u], isAll:[%d]",
    1728              :         config->phyId, config->nicPosition, config->isAll);
    1729              : 
    1730            7 :     ret = RaGetInterfaceVersion(config->phyId, RA_RS_GET_IFADDRS_V2, &interfaceVersion);
    1731            7 :     CHK_PRT_RETURN(ret != 0,
    1732              :         hccp_err("[get][ra_ifnum]get interface version failed, ret(%d), phyId(%u), interfaceVersion(%u)", ret,
    1733              :         config->phyId, interfaceVersion),
    1734              :         ConverReturnCode(OTHERS, -EINVAL));
    1735              : 
    1736            7 :     CHK_PRT_RETURN(interfaceVersion < GET_IFADDRS_VERSION_3 && config->nicPosition == NETWORK_OFFLINE &&
    1737              :         config->isAll,
    1738              :         hccp_err("[get][ra_ifnum]current version do not support get all ip num, interfaceVersion(%u), isAll(%d)",
    1739              :         interfaceVersion, config->isAll),
    1740              :         ConverReturnCode(OTHERS, -ENOTSUPP));
    1741              : 
    1742            6 :     if (config->nicPosition == NETWORK_OFFLINE) {
    1743            1 :         ret = RaHdcGetIfnum(config->phyId, config->isAll, num);
    1744            1 :         CHK_PRT_RETURN(ret, hccp_err("[get][ra_ifnum]ra_hdc_get_ifnum failed, ret(%d)", ret),
    1745              :             ConverReturnCode(OTHERS, ret));
    1746            5 :     } else if (config->nicPosition == NETWORK_PEER_ONLINE) {
    1747            2 :         ret = RaPeerGetIfnum(config->phyId, num);
    1748            2 :         CHK_PRT_RETURN(ret, hccp_err("[get][ra_ifnum]ra_peer_get_ifnum failed, ret(%d)", ret),
    1749              :             ConverReturnCode(OTHERS, ret));
    1750              :     } else {
    1751            3 :         hccp_err("[get][ra_ifnum]Wrong mode, do not support online mode");
    1752            3 :         return ConverReturnCode(OTHERS, -EPROTONOSUPPORT);
    1753              :     }
    1754              : 
    1755            3 :     CHK_PRT_RETURN((*num) > MAX_SUPPORT_IFNUM,
    1756              :         hccp_err("[get][ra_ifnum]get interface num(%d)! It must greater or equal to 0 and less or equal to %d", (*num),
    1757              :         MAX_SUPPORT_IFNUM), ConverReturnCode(OTHERS, -EINVAL));
    1758              : 
    1759            3 :     return 0;
    1760              : }
    1761              : 
    1762           12 : HCCP_ATTRI_VISI_DEF int RaGetIfaddrs(struct RaGetIfattr *config, struct InterfaceInfo interfaceInfos[],
    1763              :     unsigned int *num)
    1764              : {
    1765              :     int ret;
    1766              : 
    1767           12 :     CHK_PRT_RETURN(config == NULL || interfaceInfos == NULL || num == NULL,
    1768              :         hccp_err("[get][ra_ifaddrs]config or interface_infos or num is NULL"), ConverReturnCode(OTHERS, -EINVAL));
    1769              : 
    1770           11 :     CHK_PRT_RETURN(config->phyId >= RA_MAX_PHY_ID_NUM,
    1771              :         hccp_err("[get][ra_ifaddrs]phyId(%u) is invalid! it must greater or equal to 0 and less than %d!",
    1772              :         config->phyId, RA_MAX_PHY_ID_NUM), ConverReturnCode(OTHERS, -EINVAL));
    1773              : 
    1774           10 :     CHK_PRT_RETURN(*num == 0, hccp_err("[get][ra_ifaddrs]interface num(%u) is invalid! it must greater than 0", *num),
    1775              :         ConverReturnCode(OTHERS, -EINVAL));
    1776              : 
    1777            9 :     hccp_run_info("Input parameters: phyId[%u], nicPosition:[%u], isAll[%d], interface num[%u]",
    1778              :         config->phyId, config->nicPosition, config->isAll, *num);
    1779              : 
    1780            9 :     if (config->nicPosition == NETWORK_OFFLINE) {
    1781            6 :         CHK_PRT_RETURN(*num > MAX_INTERFACE_NUM,
    1782              :             hccp_err("[get][ra_ifaddrs]interface num(%u) is invalid! it must be less than %d!", *num, MAX_INTERFACE_NUM),
    1783              :             ConverReturnCode(OTHERS, -EINVAL));
    1784              : 
    1785            5 :         ret = RaIfaddrInfoConverter(config->phyId, config->isAll, interfaceInfos, num);
    1786            5 :         CHK_PRT_RETURN(ret, hccp_err("[get][ra_ifaddrs]ra_hdc_get_ifaddrs failed, ret(%d)", ret),
    1787              :             ConverReturnCode(OTHERS, ret));
    1788            3 :     } else if (config->nicPosition == NETWORK_PEER_ONLINE) {
    1789            1 :         ret = RaPeerGetIfaddrs(config->phyId, interfaceInfos, num);
    1790            1 :         CHK_PRT_RETURN(ret, hccp_err("[get][ra_ifaddrs]ra_peer_get_ifaddrs failed, ret(%d)", ret),
    1791              :             ConverReturnCode(OTHERS, ret));
    1792              :     } else {
    1793            2 :         hccp_err("[get][ra_ifaddrs]Wrong mode, do not support online mode");
    1794            2 :         return ConverReturnCode(OTHERS, -EPROTONOSUPPORT);
    1795              :     }
    1796            3 :     return 0;
    1797              : }
    1798              : 
    1799           41 : HCCP_ATTRI_VISI_DEF int RaGetInterfaceVersion(unsigned int phyId, unsigned int interfaceOpcode,
    1800              :     unsigned int* interfaceVersion)
    1801              : {
    1802              :     int ret;
    1803              : 
    1804           41 :     if (interfaceVersion == NULL || phyId >= RA_MAX_PHY_ID_NUM || interfaceOpcode >= RA_RS_EXTER_OP_MAX_NUM) {
    1805            1 :         hccp_err("[get][ra_interface_version]para is invalid! interface_version is NULL or phyId(%u) is"\
    1806              :             "greater than [%u] or interface_opcode(%u) more than [%u]", phyId, RA_MAX_PHY_ID_NUM, interfaceOpcode,
    1807              :             RA_RS_EXTER_OP_MAX_NUM);
    1808            1 :         return ConverReturnCode(OTHERS, -EINVAL);
    1809              :     }
    1810              : 
    1811           40 :     ret = RaHdcGetInterfaceVersion(phyId, interfaceOpcode, interfaceVersion);
    1812           40 :     return ConverReturnCode(OTHERS, ret);
    1813              : }
    1814              : 
    1815          535 : int ConverReturnCode(enum ModuleType module, int erroCode)
    1816              : {
    1817              :     unsigned int i;
    1818          535 :     unsigned int num = sizeof(gErrcodeInfoList) / sizeof(gErrcodeInfoList[0]);
    1819          535 :     int ret = CONVER_ERROR_CODE(module, DEFAULT_ERRCODE_TYPE, DEFAULT_MODULE_ERRCODE);
    1820              : 
    1821          535 :     if (erroCode == 0) {
    1822          138 :         return 0;
    1823              :     }
    1824              : 
    1825          397 :     if (erroCode / ACL_ERRCODE_DIGIT) {        /* ACL error codes are transparently transmitted */
    1826            2 :         return erroCode;
    1827              :     }
    1828              : 
    1829         1878 :     for (i = 0; i < num; i++) {
    1830         1877 :         if (erroCode == gErrcodeInfoList[i].origErrcode) {
    1831          394 :             ret = CONVER_ERROR_CODE(module, gErrcodeInfoList[i].errType, gErrcodeInfoList[i].moduleErrcode);
    1832          394 :             break;
    1833              :         }
    1834              :     }
    1835              : 
    1836          395 :     if (erroCode != -EAGAIN) {  // 防止刷屏
    1837          395 :         hccp_info("ConverReturnCode: orig_errcode[%d] curr_errcode[%d]", erroCode, ret);
    1838              :     }
    1839          395 :     return ret;
    1840              : }
    1841              : 
    1842            4 : HCCP_ATTRI_VISI_DEF int RaRecvWrlist(void *qpHandle, struct RecvWrlistData *wr, unsigned int recvNum,
    1843              :     unsigned int *completeNum)
    1844              : {
    1845              :     int ret;
    1846              :     unsigned int i;
    1847            4 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    1848              : 
    1849            4 :     if (qpHandle == NULL || wr == NULL || recvNum == 0 || completeNum == NULL) {
    1850            1 :         hccp_err("[recv][ra_wrlist]qp_handle or wr or complete_num is NULL or recv_num[%u] is zero, para error!",
    1851              :             recvNum);
    1852            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    1853              :     }
    1854              : 
    1855            5 :     for (i = 0; i < recvNum; i++) {
    1856            3 :         if (wr[i].memList.len > MAX_SG_LIST_LEN_MAX) {
    1857            1 :             hccp_err("[recv][ra_wrlist]sg list len is more than 2G, len(%u)", wr[i].memList.len);
    1858            1 :             return ConverReturnCode(RDMA_OP, -EINVAL);
    1859              :         }
    1860              :     }
    1861            2 :     if (raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raRecvWrlist == NULL) {
    1862            1 :         hccp_err("[recv][ra_wrlist]rdma_ops or ra_recv_wrlist is NULL, invalid");
    1863            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    1864              :     }
    1865            1 :     ret = raQpHandle->rdmaOps->raRecvWrlist(raQpHandle, wr, recvNum, completeNum);
    1866            1 :     return ConverReturnCode(RDMA_OP, ret);
    1867              : }
    1868              : 
    1869            3 : HCCP_ATTRI_VISI_DEF int RaGetQpContext(void *qpHandle, void** qp, void** sendCq, void** recvCq)
    1870              : {
    1871              :     int ret;
    1872            3 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    1873              : 
    1874            3 :     if (qpHandle == NULL || qp == NULL || sendCq == NULL || recvCq == NULL) {
    1875            1 :         hccp_err("[request][ra_get_qp_context]qp_handle or qp or sendCq or recvCq is NULL, para error!");
    1876            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    1877              :     }
    1878              : 
    1879            2 :     if (raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raGetQpContext == NULL) {
    1880            1 :         hccp_err("[get][ra_get_qp_context]rdma_ops is NULL or ra_get_qp_context is NULL, invalid");
    1881            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    1882              :     }
    1883            1 :     CHK_PRT_RETURN(raQpHandle->phyId >= RA_MAX_PHY_ID_NUM,
    1884              :         hccp_err("[get][rs_get_qp_context]qpPeer->phyId[%u] >= max_dev_num[%u], input is invalid", raQpHandle->phyId,
    1885              :         RA_MAX_PHY_ID_NUM), -EINVAL);
    1886              : 
    1887            1 :     ret = raQpHandle->rdmaOps->raGetQpContext(raQpHandle, qp, sendCq, recvCq);
    1888            1 :     return ConverReturnCode(RDMA_OP, ret);
    1889              : }
    1890              : 
    1891            4 : HCCP_ATTRI_VISI_DEF int RaCqCreate(void *rdevHandle, struct CqAttr *attr)
    1892              : {
    1893            4 :     struct RaRdmaHandle *rdmaHandleTmp = (struct RaRdmaHandle *)rdevHandle;
    1894              :     unsigned int phyId;
    1895              :     int ret;
    1896              : 
    1897            4 :     CHK_PRT_RETURN(rdevHandle == NULL || rdmaHandleTmp->rdmaOps == NULL ||
    1898              :         rdmaHandleTmp->rdmaOps->raCqCreate == NULL || attr == NULL || attr->ibSendCq == NULL ||
    1899              :         attr->ibRecvCq == NULL || attr->qpContext == NULL, hccp_err("[create][ra_cq]para is NULL or func is NULL"),
    1900              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1901              : 
    1902            3 :     phyId = rdmaHandleTmp->rdevInfo.phyId;
    1903            3 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
    1904              :         hccp_err("[create][ra_cq]phyId(%u) must less than %d!", phyId, RA_MAX_PHY_ID_NUM),
    1905              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1906              : 
    1907            2 :     hccp_run_info("Input parameters: phyId[%u]", phyId);
    1908              : 
    1909            2 :     ret = rdmaHandleTmp->rdmaOps->raCqCreate(rdmaHandleTmp, attr);
    1910            2 :     CHK_PRT_RETURN(ret != 0 || *attr->ibSendCq == NULL || *attr->ibRecvCq == NULL || *attr->qpContext == NULL,
    1911              :         hccp_err("[create][ra_cq]create cp failed, ret(%d) phyId(%u)", ret, phyId),
    1912              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1913              : 
    1914            0 :     return 0;
    1915              : }
    1916              : 
    1917            4 : HCCP_ATTRI_VISI_DEF int RaCqDestroy(void *rdevHandle, struct CqAttr *attr)
    1918              : {
    1919            4 :     struct RaRdmaHandle *rdmaHandleTmp = (struct RaRdmaHandle *)rdevHandle;
    1920              :     unsigned int phyId;
    1921              :     int ret;
    1922              : 
    1923            4 :     CHK_PRT_RETURN(rdevHandle == NULL || rdmaHandleTmp->rdmaOps == NULL || 
    1924              :         rdmaHandleTmp->rdmaOps->raCqDestroy == NULL || attr == NULL || attr->ibSendCq == NULL ||
    1925              :         attr->ibRecvCq == NULL || attr->qpContext == NULL, hccp_err("[destroy][ra_cq]para is NULL or func is NULL"),
    1926              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1927              : 
    1928            3 :     phyId = rdmaHandleTmp->rdevInfo.phyId;
    1929            3 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
    1930              :         hccp_err("[destroy][ra_cq]phyId(%u) must less than %d!", phyId, RA_MAX_PHY_ID_NUM),
    1931              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1932              : 
    1933            2 :     hccp_run_info("Input parameters: phyId[%u]", phyId);
    1934              : 
    1935            2 :     ret = rdmaHandleTmp->rdmaOps->raCqDestroy(rdmaHandleTmp, attr);
    1936            2 :     CHK_PRT_RETURN(ret != 0 || *attr->ibSendCq == NULL || *attr->ibRecvCq == NULL ||
    1937              :                    *attr->qpContext == NULL,
    1938              :         hccp_err("[destroy][ra_cq]destroy cp failed, ret(%d) phyId(%u)", ret, phyId),
    1939              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1940              : 
    1941            0 :     return 0;
    1942              : }
    1943              : 
    1944            5 : HCCP_ATTRI_VISI_DEF int RaNormalQpCreate(void *rdevHandle, struct ibv_qp_init_attr *qpInitAttr, void **qpHandle,
    1945              :     void **qp)
    1946              : {
    1947            5 :     struct RaRdmaHandle *rdmaHandleTmp = (struct RaRdmaHandle *)rdevHandle;
    1948              :     unsigned int phyId;
    1949              :     int ret;
    1950              : 
    1951            5 :     if (rdevHandle == NULL || rdmaHandleTmp->rdmaOps == NULL ||
    1952            5 :         rdmaHandleTmp->rdmaOps->raNormalQpCreate == NULL || qpInitAttr == NULL || qp == NULL) {
    1953            1 :         hccp_err("[create][ra_normal_qp]para is NULL or func is NULL");
    1954            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    1955              :     }
    1956              : 
    1957            4 :     if (qpHandle == NULL) {
    1958            1 :         hccp_err("[create][ra_normal_qp]qp_handle is NULL");
    1959            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    1960              :     }
    1961              : 
    1962            3 :     phyId = rdmaHandleTmp->rdevInfo.phyId;
    1963            3 :     if (phyId >= RA_MAX_PHY_ID_NUM) {
    1964            1 :         hccp_err("[create][ra_normal_qp]phyId(%u) must less than %d!", phyId, RA_MAX_PHY_ID_NUM);
    1965            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    1966              :     }
    1967              : 
    1968            2 :     hccp_run_info("Input parameters: phyId[%u]", phyId);
    1969              : 
    1970            2 :     ret = rdmaHandleTmp->rdmaOps->raNormalQpCreate(rdmaHandleTmp, qpInitAttr, qpHandle, qp);
    1971            2 :     if (ret != 0 || *qpHandle == NULL) {
    1972            1 :         hccp_err("[create][ra_normal_qp]create qp failed, ret(%d) phyId(%u)", ret, phyId);
    1973            1 :         return ConverReturnCode(RDMA_OP, ret);
    1974              :     }
    1975              : 
    1976            1 :     return 0;
    1977              : }
    1978              : 
    1979            5 : HCCP_ATTRI_VISI_DEF int RaNormalQpDestroy(void *qpHandle)
    1980              : {
    1981              :     int ret;
    1982            5 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    1983              : 
    1984            5 :     if (qpHandle == NULL) {
    1985            1 :         hccp_err("[destroy][ra_normal_qp]qp_handle is NULL");
    1986            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    1987              :     }
    1988              : 
    1989            4 :     if (raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raNormalQpDestroy == NULL) {
    1990            3 :         hccp_err("[destroy][ra_qp]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_normal_qp_destroy is NULL, invalid");
    1991            3 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    1992              :     }
    1993              : 
    1994            1 :     hccp_run_info("Input parameters: qpn[%u], phyId[%u], rdevIndex[%u]",
    1995              :         raQpHandle->qpn, raQpHandle->phyId, raQpHandle->rdevIndex);
    1996              : 
    1997            1 :     ret = raQpHandle->rdmaOps->raNormalQpDestroy(raQpHandle);
    1998            1 :     return ConverReturnCode(RDMA_OP, ret);
    1999              : }
    2000              : 
    2001            6 : HCCP_ATTRI_VISI_DEF int RaSetQpAttrQos(void *qpHandle, struct QosAttr *attr)
    2002              : {
    2003              :     int ret;
    2004            6 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    2005              : 
    2006            6 :     if (qpHandle == NULL || attr == NULL) {
    2007            2 :         hccp_err("[set][ra_qp_attr_qos]qp_handle or attr is NULL, para error!");
    2008            2 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2009              :     }
    2010              : 
    2011            4 :     if (raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raSetQpAttrQos == NULL) {
    2012            3 :         hccp_err("[set][ra_qp_attr_qos]rdma_ops is NULL or rdma_ops->ra_set_qp_attr_qos is NULL, invalid");
    2013            3 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2014              :     }
    2015              : 
    2016            1 :     ret = raQpHandle->rdmaOps->raSetQpAttrQos(raQpHandle, attr);
    2017            1 :     return ConverReturnCode(RDMA_OP, ret);
    2018              : }
    2019              : 
    2020            6 : HCCP_ATTRI_VISI_DEF int RaSetQpAttrTimeout(void *qpHandle, unsigned int *timeout)
    2021              : {
    2022              :     int ret;
    2023            6 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    2024              : 
    2025            6 :     if (qpHandle == NULL || timeout == NULL) {
    2026            2 :         hccp_err("[set][ra_qp_attr_timeout]qp_handle or timeout is NULL, para error!");
    2027            2 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2028              :     }
    2029              : 
    2030            4 :     if (raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raSetQpAttrTimeout == NULL) {
    2031            3 :         hccp_err("[set][ra_qp_attr_timeout]rdma_ops is NULL or rdma_ops->ra_set_qp_attr_timeout is NULL, invalid");
    2032            3 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2033              :     }
    2034              : 
    2035            1 :     ret = raQpHandle->rdmaOps->raSetQpAttrTimeout(raQpHandle, timeout);
    2036            1 :     return ConverReturnCode(RDMA_OP, ret);
    2037              : }
    2038              : 
    2039            6 : HCCP_ATTRI_VISI_DEF int RaSetQpAttrRetryCnt(void *qpHandle, unsigned int *retryCnt)
    2040              : {
    2041              :     int ret;
    2042            6 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    2043              : 
    2044            6 :     if (qpHandle == NULL || retryCnt == NULL) {
    2045            2 :         hccp_err("[set][ra_qp_attr_retry_cnt]qp_handle or retry_cnt is NULL, para error!");
    2046            2 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2047              :     }
    2048              : 
    2049            4 :     if (raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raSetQpAttrRetryCnt == NULL) {
    2050            3 :         hccp_err("[set][ra_qp_attr_retry_cnt]rdma_ops is NULL or rdma_ops->ra_set_qp_attr_retry_cnt is NULL, invalid");
    2051            3 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2052              :     }
    2053              : 
    2054            1 :     ret = raQpHandle->rdmaOps->raSetQpAttrRetryCnt(raQpHandle, retryCnt);
    2055            1 :     return ConverReturnCode(RDMA_OP, ret);
    2056              : }
    2057              : 
    2058            6 : HCCP_ATTRI_VISI_DEF int RaCreateCompChannel(const void *rdmaHandle, void **compChannel)
    2059              : {
    2060              :     int ret;
    2061            6 :     struct RaRdmaHandle *raRdmaHandle = (struct RaRdmaHandle *)rdmaHandle;
    2062              : 
    2063            6 :     if (rdmaHandle == NULL) {
    2064            1 :         hccp_err("[ra_create_comp_channel]rdma_handle(%p) is NULL, para error!", rdmaHandle);
    2065            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2066              :     }
    2067              : 
    2068            5 :     if (compChannel == NULL) {
    2069            1 :         hccp_err("[ra_create_comp_channel]comp_channel is NULL");
    2070            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2071              :     }
    2072              : 
    2073            4 :     if (raRdmaHandle->rdmaOps == NULL || raRdmaHandle->rdmaOps->raCreateCompChannel == NULL) {
    2074            2 :         hccp_err("[ra_create_comp_channel]rdma_ops is NULL or ra_rdma_handle->rdma_ops->ra_create_comp_channel "
    2075              :             "is NULL, invalid");
    2076            2 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2077              :     }
    2078              : 
    2079            2 :     ret = raRdmaHandle->rdmaOps->raCreateCompChannel(raRdmaHandle, compChannel);
    2080            2 :     return ConverReturnCode(RDMA_OP, ret);
    2081              : }
    2082              : 
    2083            6 : HCCP_ATTRI_VISI_DEF int RaDestroyCompChannel(const void *rdmaHandle, void *compChannel)
    2084              : {
    2085              :     int ret;
    2086            6 :     struct RaRdmaHandle *raRdmaHandle = (struct RaRdmaHandle *)rdmaHandle;
    2087              : 
    2088            6 :     if (rdmaHandle == NULL) {
    2089            1 :         hccp_err("[ra_destroy_comp_channel]rdma_handle(%p) is NULL, para error!", rdmaHandle);
    2090            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2091              :     }
    2092              : 
    2093            5 :     if (compChannel == NULL) {
    2094            2 :         hccp_err("[ra_destroy_comp_channel]comp_channel is NULL");
    2095            2 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2096              :     }
    2097              : 
    2098            3 :     if (raRdmaHandle->rdmaOps == NULL || raRdmaHandle->rdmaOps->raDestroyCompChannel == NULL) {
    2099            1 :         hccp_err("[ra_destroy_comp_channel]rdma_ops is NULL or ra_rdma_handle->rdma_ops->ra_destroy_comp_channel "
    2100              :             "is NULL, invalid");
    2101            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2102              :     }
    2103              : 
    2104            2 :     ret = raRdmaHandle->rdmaOps->raDestroyCompChannel(compChannel);
    2105            2 :     return ConverReturnCode(RDMA_OP, ret);
    2106              : }
    2107              : 
    2108            4 : HCCP_ATTRI_VISI_DEF int RaGetCqeErrInfo(unsigned int phyId, struct CqeErrInfo *info)
    2109              : {
    2110              :     int ret;
    2111              : 
    2112            4 :     if (info == NULL) {
    2113            2 :         hccp_err("[ra_get_cqe_err_info]cqe_err_info is NULL, para error!");
    2114            2 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2115              :     }
    2116              : 
    2117            2 :     if (phyId >= RA_MAX_PHY_ID_NUM) {
    2118            1 :         hccp_err("[ra_get_cqe_err_info]phyId(%u) must greater or equal to 0 and less than %d!",
    2119              :             phyId, RA_MAX_PHY_ID_NUM);
    2120            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2121              :     }
    2122              : 
    2123            1 :     ret = RaHdcGetCqeErrInfo(phyId, info);
    2124            1 :     return ConverReturnCode(RDMA_OP, ret);
    2125              : }
    2126              : 
    2127            3 : HCCP_ATTRI_VISI_DEF int RaRdevGetCqeErrInfoList(void *rdmaHandle, struct CqeErrInfo *infoList,
    2128              :     unsigned int *num)
    2129              : {
    2130            3 :     struct RaRdmaHandle *raRdmaHandle = (struct RaRdmaHandle *)rdmaHandle;
    2131              :     int ret;
    2132              : 
    2133            3 :     if (rdmaHandle == NULL || infoList == NULL || num == NULL) {
    2134            1 :         hccp_err("[get][cqe_err_info_list]rdma_handle or info_list or num is NULL, para error!");
    2135            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2136              :     }
    2137              : 
    2138            2 :     if (*num == 0 || *num > CQE_ERR_INFO_MAX_NUM) {
    2139            1 :         hccp_err("[get][cqe_err_info_list]num(%u) is invalid!", *num);
    2140            1 :         return ConverReturnCode(OTHERS, -EINVAL);
    2141              :     }
    2142              : 
    2143            1 :     ret = RaHdcGetCqeErrInfoList(raRdmaHandle, infoList, num);
    2144            1 :     return ConverReturnCode(RDMA_OP, ret);
    2145              : }
    2146              : 
    2147            3 : HCCP_ATTRI_VISI_DEF int RaGetQpAttr(void *qpHandle, struct QpAttr *attr)
    2148              : {
    2149            3 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    2150              : 
    2151            3 :     if (qpHandle == NULL || attr == NULL) {
    2152            2 :         hccp_err("[get][get_qp_attr]qp_handle or attr is NULL, para error!");
    2153            2 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2154              :     }
    2155              : 
    2156            1 :     attr->qpn = raQpHandle->qpn;
    2157            1 :     attr->udpSport = raQpHandle->typicalQpAttr.udpSport;
    2158            1 :     attr->pathMtu = raQpHandle->typicalQpAttr.pathMtu;
    2159            1 :     attr->psn = raQpHandle->psn;
    2160            1 :     attr->gidIdx = raQpHandle->gidIdx;
    2161            1 :     (void)memcpy_s(attr->gid, HCCP_GID_RAW_LEN, raQpHandle->rdmaHandle->gid, HCCP_GID_RAW_LEN);
    2162            1 :     return 0;
    2163              : }
    2164              : 
    2165            5 : HCCP_ATTRI_VISI_DEF int RaCreateSrq(const void *rdmaHandle, struct SrqAttr *attr)
    2166              : {
    2167              :     int ret;
    2168            5 :     struct RaRdmaHandle *raRdmaHandle = (struct RaRdmaHandle *)rdmaHandle;
    2169              : 
    2170            5 :     if (rdmaHandle == NULL) {
    2171            1 :         hccp_err("[ra_create_srq]rdma_handle(%p) is NULL, para error!", rdmaHandle);
    2172            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2173              :     }
    2174              : 
    2175            4 :     if (attr == NULL) {
    2176            1 :         hccp_err("[ra_create_srq]srq_attr is NULL");
    2177            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2178              :     }
    2179              : 
    2180              :     // 创建srq&srq cq
    2181            3 :     if (raRdmaHandle->rdmaOps == NULL || raRdmaHandle->rdmaOps->raCreateSrq == NULL) {
    2182            1 :         hccp_err("[ra_create_srq]rdma_ops is NULL or ra_rdma_handle->rdma_ops->ra_create_srq "
    2183              :             "is NULL, invalid");
    2184            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2185              :     }
    2186              : 
    2187            2 :     ret = raRdmaHandle->rdmaOps->raCreateSrq(raRdmaHandle, attr);
    2188            2 :     return ConverReturnCode(RDMA_OP, ret);
    2189              : }
    2190              : 
    2191            5 : HCCP_ATTRI_VISI_DEF int RaDestroySrq(const void *rdmaHandle, struct SrqAttr *attr)
    2192              : {
    2193              :     int ret;
    2194            5 :     struct RaRdmaHandle *raRdmaHandle = (struct RaRdmaHandle *)rdmaHandle;
    2195              : 
    2196            5 :     if (rdmaHandle == NULL) {
    2197            1 :         hccp_err("[ra_destroy_srq]rdma_handle(%p) is NULL, para error!", rdmaHandle);
    2198            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2199              :     }
    2200              : 
    2201            4 :     if (attr == NULL) {
    2202            1 :         hccp_err("[ra_destroy_srq]srq_handle is NULL");
    2203            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2204              :     }
    2205              : 
    2206              :     // 销毁srq&srq cq
    2207            3 :     if (raRdmaHandle->rdmaOps == NULL || raRdmaHandle->rdmaOps->raDestroySrq == NULL) {
    2208            1 :         hccp_err("[ra_destroy_srq]rdma_ops is NULL or ra_rdma_handle->rdma_ops->ra_destroy_srq "
    2209              :             "is NULL, invalid");
    2210            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2211              :     }
    2212              : 
    2213            2 :     ret = raRdmaHandle->rdmaOps->raDestroySrq(raRdmaHandle, attr);
    2214            2 :     return ConverReturnCode(RDMA_OP, ret);
    2215              : }
    2216              : 
    2217            3 : HCCP_ATTRI_VISI_DEF int RaCreateEventHandle(int *eventHandle)
    2218              : {
    2219              :     int ret;
    2220              : 
    2221            3 :     if (eventHandle == NULL) {
    2222            1 :         hccp_err("[ra_create_event_handle]event_handle is NULL");
    2223            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    2224              :     }
    2225              : 
    2226            2 :     ret = RaPeerCreateEventHandle(eventHandle);
    2227            2 :     if (ret) {
    2228            1 :         hccp_err("[ra_create_event_handle]ra_peer_create_event_handle failed ret(%d)", ret);
    2229            1 :         return ConverReturnCode(SOCKET_OP, ret);
    2230              :     }
    2231            1 :     return 0;
    2232              : }
    2233              : 
    2234            6 : HCCP_ATTRI_VISI_DEF int RaCtlEventHandle(int eventHandle, const void *fdHandle, int opcode,
    2235              :     enum RaEpollEvent event)
    2236              : {
    2237              :     int ret;
    2238              : 
    2239            6 :     if (eventHandle < 0) {
    2240            1 :         hccp_err("[ra_ctl_event_handle]event_handle[%d] is invalid", eventHandle);
    2241            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    2242              :     }
    2243            5 :     if (fdHandle == NULL) {
    2244            1 :         hccp_err("[ra_ctl_event_handle]fd_handle is NULL");
    2245            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    2246              :     }
    2247            4 :     if (opcode != EPOLL_CTL_ADD && opcode != EPOLL_CTL_DEL && opcode != EPOLL_CTL_MOD) {
    2248            1 :         hccp_err("[ra_ctl_event_handle]opcode[%d] invalid, valid opcode includes {%d, %d, %d}",
    2249              :             opcode, EPOLL_CTL_ADD, EPOLL_CTL_DEL, EPOLL_CTL_MOD);
    2250            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    2251              :     }
    2252            3 :     if (event >= RA_EPOLLINVALD) {
    2253            1 :         hccp_err("[ra_ctl_event_handle]event[%d] invalid, valid range [0, %d)", event, RA_EPOLLINVALD);
    2254            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    2255              :     }
    2256              : 
    2257            2 :     ret = RaPeerCtlEventHandle(eventHandle, fdHandle, opcode, event);
    2258            2 :     if (ret) {
    2259            1 :         hccp_err("[ra_ctl_event_handle]ra_peer_ctl_event_handle failed ret(%d)", ret);
    2260            1 :         return ConverReturnCode(SOCKET_OP, ret);
    2261              :     }
    2262            1 :     return 0;
    2263              : }
    2264              : 
    2265            7 : HCCP_ATTRI_VISI_DEF int RaWaitEventHandle(int eventHandle, struct SocketEventInfoT *eventInfos, int timeout,
    2266              :     unsigned int maxevents, unsigned int *eventsNum)
    2267              : {
    2268              :     int ret;
    2269              : 
    2270            7 :     if (eventHandle < 0) {
    2271            1 :         hccp_err("[ra_wait_event_handle]event_handle[%d] is invalid", eventHandle);
    2272            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    2273              :     }
    2274              : 
    2275            6 :     if (eventInfos == NULL) {
    2276            1 :         hccp_err("[ra_wait_event_handle]event_infos is NULL");
    2277            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    2278              :     }
    2279              : 
    2280            5 :     if (timeout < -1) {
    2281            1 :         hccp_err("[ra_wait_event_handle]timeout[%d] is invalid", timeout);
    2282            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    2283              :     }
    2284              : 
    2285            4 :     if (maxevents > MAX_SOCKET_EVENT_NUM) {
    2286            1 :         hccp_err("[ra_wait_event_handle]maxevents[%u] exceeds %u", maxevents, MAX_SOCKET_EVENT_NUM);
    2287            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    2288              :     }
    2289              : 
    2290            3 :     if (eventsNum == NULL) {
    2291            1 :         hccp_err("[ra_wait_event_handle]events_num is NULL");
    2292            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    2293              :     }
    2294              : 
    2295            2 :     ret = RaPeerWaitEventHandle(eventHandle, eventInfos, timeout, maxevents, eventsNum);
    2296            2 :     if (ret) {
    2297            1 :         hccp_err("[ra_wait_event_handle]ra_peer_wait_event_handle failed ret(%d)", ret);
    2298            1 :         return ConverReturnCode(SOCKET_OP, ret);
    2299              :     }
    2300            1 :     return 0;
    2301              : }
    2302              : 
    2303            3 : HCCP_ATTRI_VISI_DEF int RaDestroyEventHandle(int *eventHandle)
    2304              : {
    2305              :     int ret;
    2306              : 
    2307            3 :     if (eventHandle == NULL) {
    2308            1 :         hccp_err("[ra_destroy_event_handle]event_handle is NULL");
    2309            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    2310              :     }
    2311              : 
    2312            2 :     ret = RaPeerDestroyEventHandle(eventHandle);
    2313            2 :     if (ret) {
    2314            1 :         hccp_err("[ra_destroy_event_handle]ra_peer_destroy_event_handle failed ret(%d)", ret);
    2315            1 :         return ConverReturnCode(SOCKET_OP, ret);
    2316              :     }
    2317            1 :     return 0;
    2318              : }
    2319              : 
    2320            4 : HCCP_ATTRI_VISI_DEF int RaPollCq(void *qpHandle, bool isSendCq, unsigned int numEntries, void *wc)
    2321              : {
    2322              :     int ret;
    2323            4 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    2324              : 
    2325            4 :     if (qpHandle == NULL || wc == NULL) {
    2326            1 :         hccp_err("[ra_poll]qp_handle is NULL or wc is NULL, para error!");
    2327            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2328              :     }
    2329              : 
    2330            3 :     if (raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raPollCq == NULL) {
    2331            1 :         hccp_err("[ra_poll]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_poll_cq is NULL, invalid");
    2332            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2333              :     }
    2334              : 
    2335            2 :     ret = raQpHandle->rdmaOps->raPollCq(raQpHandle, isSendCq, numEntries, wc);
    2336            2 :     if (ret < 0) {
    2337            1 :         return ConverReturnCode(RDMA_OP, ret);
    2338              :     }
    2339            1 :     return ret;
    2340              : }
    2341              : 
    2342            3 : HCCP_ATTRI_VISI_DEF int RaTypicalQpModify(void *qpHandle, struct TypicalQp *localQpInfo,
    2343              :     struct TypicalQp *remoteQpInfo)
    2344              : {
    2345            3 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    2346              :     unsigned int phyId;
    2347              :     int ret;
    2348              : 
    2349            3 :     if (qpHandle == NULL || raQpHandle->rdmaOps == NULL ||
    2350            2 :         raQpHandle->rdmaOps->raTypicalQpModify == NULL) {
    2351            1 :         hccp_err("[modify][ra_qp]qp_handle is NULL or func is NULL");
    2352            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2353              :     }
    2354              : 
    2355            2 :     if (localQpInfo == NULL || remoteQpInfo == NULL) {
    2356            1 :         hccp_err("[modify][ra_qp]local_qp_info is NULL or remote_qp_info is NULL");
    2357            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2358              :     }
    2359              : 
    2360            1 :     phyId = raQpHandle->phyId;
    2361            1 :     if (phyId >= RA_MAX_PHY_ID_NUM) {
    2362            0 :         hccp_err("[modify][ra_qp]phyId(%u) must greater or equal to 0 and less than %d!", phyId, RA_MAX_PHY_ID_NUM);
    2363            0 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2364              :     }
    2365              : 
    2366            1 :     hccp_run_info("Input parameters: phyId[%u] local_qpn[%u] remote_qpn[%u]",
    2367              :         phyId, localQpInfo->qpn, remoteQpInfo->qpn);
    2368              : 
    2369            1 :     ret = raQpHandle->rdmaOps->raTypicalQpModify(raQpHandle, localQpInfo, remoteQpInfo);
    2370            1 :     if (ret != 0) {
    2371            0 :         hccp_err("[modify][ra_qp]modify qp failed, ret(%d) phyId(%u)", ret, phyId);
    2372            0 :         return ConverReturnCode(RDMA_OP, ret);
    2373              :     }
    2374              : 
    2375            1 :     return 0;
    2376              : }
    2377              : 
    2378            2 : HCCP_ATTRI_VISI_DEF int RaTypicalSendWr(void *qpHandle, struct SendWr *wr, struct SendWrRsp *opRsp)
    2379              : {
    2380            2 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    2381              :     int ret;
    2382              : 
    2383            2 :     if (qpHandle == NULL || wr == NULL || wr->bufList == NULL || opRsp == NULL) {
    2384            1 :         hccp_err("[send][ra_wr]qp_handle or wr or buf_list or op_rsp is NULL, para error!");
    2385            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2386              :     }
    2387              : 
    2388            1 :     if (wr->bufList->len > MAX_SG_LIST_LEN_MAX) {
    2389            0 :         hccp_err("[send][ra_wr]sg list len is more than 2G, len(%u)", wr->bufList->len);
    2390            0 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2391              :     }
    2392              : 
    2393            1 :     if (raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raTypicalSendWr == NULL) {
    2394            0 :         hccp_err("[send][ra_wr]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_typical_send_wr is NULL, invalid");
    2395            0 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2396              :     }
    2397              : 
    2398            1 :     ret = raQpHandle->rdmaOps->raTypicalSendWr(raQpHandle, wr, opRsp);
    2399            1 :     return ConverReturnCode(RDMA_OP, ret);
    2400              : }
    2401              : 
    2402            5 : HCCP_ATTRI_VISI_DEF int RaSocketGetVnicIpInfos(unsigned int phyId, enum IdType type, unsigned int ids[],
    2403              :     unsigned int num, struct IpInfo infos[])
    2404              : {
    2405              :     int ret;
    2406              : 
    2407            5 :     if (ids == NULL || num == 0 || infos == NULL) {
    2408            1 :         hccp_err("[get][vnic_ip]ids is NULL or num:%u == 0 or infos is NULL", num);
    2409            1 :         return ConverReturnCode(OTHERS, -EINVAL);
    2410              :     }
    2411              : 
    2412            4 :     if (phyId >= RA_MAX_PHY_ID_NUM) {
    2413            1 :         hccp_err("[get][vnic_ip]phyId(%u) is invalid! it must greater or equal to 0 and less than %d!",
    2414              :             phyId, RA_MAX_PHY_ID_NUM);
    2415            1 :         return ConverReturnCode(OTHERS, -EINVAL);
    2416              :     }
    2417              : 
    2418            3 :     if (type != PHY_ID_VNIC_IP && type != SDID_VNIC_IP) {
    2419            1 :         hccp_err("[get][vnic_ip]type[%u] invalid", type);
    2420            1 :         return ConverReturnCode(OTHERS, -EINVAL);
    2421              :     }
    2422              : 
    2423            2 :     ret = RaHdcGetVnicIpInfos(phyId, type, ids, num, infos);
    2424            2 :     if (ret) {
    2425            2 :         hccp_err("[get][vnic_ip]ra_hdc_get_vnic_ip_infos failed, ret(%d)", ret);
    2426            2 :         return ConverReturnCode(OTHERS, ret);
    2427              :     }
    2428            0 :     return 0;
    2429              : }
    2430              : 
    2431            5 : int RaQpBatchModifyCheckParam(void *rdmaHandle, void *qpHandle[], unsigned int num, int expectStatus)
    2432              : {
    2433              :     unsigned int i;
    2434              : 
    2435            5 :     if (rdmaHandle == NULL || num == 0 || qpHandle == NULL ||
    2436            2 :         ((expectStatus != RA_QP_STATUS_CONNECTED) && (expectStatus != RA_QP_STATUS_PAUSE))) {
    2437            1 :         hccp_err("[batch_modify][check param]expect_status is %d or rdma_handle is NULL or num[%u] is 0!",
    2438              :             expectStatus, num);
    2439            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2440              :     }
    2441              : 
    2442            7 :     for (i = 0; i < num; i++) {
    2443            4 :         if (qpHandle[i] == NULL) {
    2444            1 :             hccp_err("[modify][ra_qp]qp_handle[%u] is NULL", i);
    2445            1 :             return ConverReturnCode(RDMA_OP, -EINVAL);
    2446              :         }
    2447              :     }
    2448              : 
    2449            3 :     return 0;
    2450              : }
    2451              : 
    2452            5 : HCCP_ATTRI_VISI_DEF int RaQpBatchModify(void *rdmaHandle, void *qpHandle[], unsigned int num, int expectStatus)
    2453              : {
    2454            5 :     struct RaRdmaHandle *raRdmaHandle = NULL;
    2455              :     unsigned int phyId;
    2456              :     int ret;
    2457              : 
    2458            5 :     ret = RaQpBatchModifyCheckParam(rdmaHandle, qpHandle, num, expectStatus);
    2459            5 :     CHK_PRT_RETURN(ret, hccp_err("ra_qp_batch_modify_check_param invalid[%d]", ret), ret);
    2460              : 
    2461            3 :     raRdmaHandle = (struct RaRdmaHandle *)rdmaHandle;
    2462            3 :     phyId = raRdmaHandle->rdevInfo.phyId;
    2463            3 :     if (phyId >= RA_MAX_PHY_ID_NUM || raRdmaHandle->rdmaOps == NULL ||
    2464            2 :         raRdmaHandle->rdmaOps->raQpBatchModify == NULL) {
    2465            1 :         hccp_err("[modify][ra_qp]phyId(%u) must greater or equal to 0 and less than %d or ops is NULL or "
    2466              :                  "ra_rdma_handle->rdma_ops->ra_qp_batch_modify is NULL!", phyId, RA_MAX_PHY_ID_NUM);
    2467            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2468              :     }
    2469              : 
    2470            2 :     hccp_run_info("Input parameters: phyId[%u] num[%u] expect_status[%d]", phyId, num, expectStatus);
    2471              : 
    2472              :     // avoid poll_cq thread to poll cq
    2473            2 :     if ((raRdmaHandle->supportLite != 0) && expectStatus == RA_QP_STATUS_PAUSE) {
    2474            1 :         RA_PTHREAD_MUTEX_LOCK(&raRdmaHandle->rdevMutex);
    2475              :     }
    2476            2 :     ret = raRdmaHandle->rdmaOps->raQpBatchModify(rdmaHandle, qpHandle, num, expectStatus);
    2477            2 :     if (ret != 0) {
    2478            0 :         hccp_err("[modify][ra_qp_batch_modify]modify qp to [%d] failed, ret[%d] phyId[%u]",
    2479              :             expectStatus, ret, phyId);
    2480              :     }
    2481            2 :     if ((raRdmaHandle->supportLite != 0) && expectStatus == RA_QP_STATUS_PAUSE) {
    2482            1 :         RA_PTHREAD_MUTEX_UNLOCK(&raRdmaHandle->rdevMutex);
    2483              :     }
    2484              : 
    2485            2 :     return ret;
    2486              : }
        

Generated by: LCOV version 2.0-1