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

Generated by: LCOV version 2.0-1