LCOV - code coverage report
Current view: top level - base_comm/resources/hccp/rdma_agent/peer - ra_peer_nda.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 51.1 % 90 46
Test Date: 2026-08-18 17:47:01 Functions: 50.0 % 6 3

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2026 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 <stdlib.h>
      12              : #include <errno.h>
      13              : #include "securec.h"
      14              : #include "ra_comm.h"
      15              : #include "rs_nda.h"
      16              : #include "ra_peer.h"
      17              : #include "ra_peer_nda.h"
      18              : 
      19            2 : int RaPeerNdaGetDirectFlag(struct RaRdmaHandle *rdmaHandle, int *directFlag)
      20              : {
      21            2 :     unsigned int phyId = rdmaHandle->rdevInfo.phyId;
      22            2 :     int ret = 0;
      23              : 
      24            2 :     RaPeerMutexLock(phyId);
      25            2 :     RsSetCtx(phyId);
      26            2 :     ret = RsNdaGetDirectFlag(phyId, rdmaHandle->rdevIndex, directFlag);
      27            2 :     RaPeerMutexUnlock(phyId);
      28            2 :     if (ret != 0) {
      29            1 :         hccp_err("[get][directFlag]RsNdaGetDirectFlag failed ret:%d phyId:%d", ret, phyId);
      30              :     }
      31            2 :     return ret;
      32              : }
      33              : 
      34            0 : int RaPeerNdaCqCreate(struct RaRdmaHandle *rdmaHandle, struct NdaCqInitAttr *attr, struct NdaCqInfo *info,
      35              :     void **cqHandle)
      36              : {
      37            0 :     unsigned int phyId = rdmaHandle->rdevInfo.phyId;
      38            0 :     struct RaCqHandleExt *cqPeer = NULL;
      39            0 :     void *ibvCqExt = NULL;
      40            0 :     int ret = 0;
      41              : 
      42            0 :     cqPeer = (struct RaCqHandleExt *)calloc(1, sizeof(struct RaCqHandleExt));
      43            0 :     CHK_PRT_RETURN(cqPeer == NULL, hccp_err("[create][RaNdaCq]cqPeer calloc failed phyId:%d", phyId), -ENOMEM);
      44              : 
      45            0 :     RaPeerMutexLock(phyId);
      46            0 :     RsSetCtx(phyId);
      47            0 :     ret = RsNdaCqCreate(phyId, rdmaHandle->rdevIndex, attr, info, &ibvCqExt);
      48            0 :     RaPeerMutexUnlock(phyId);
      49            0 :     if (ret != 0) {
      50            0 :         hccp_err("[create][RaNdaCq]RsNdaCqCreate failed ret:%d phyId:%d", ret, phyId);
      51            0 :         goto free_cq_handle;
      52              :     }
      53            0 :     cqPeer->addr = (unsigned long long)(uintptr_t)ibvCqExt;
      54            0 :     cqPeer->rdmaHandle = rdmaHandle;
      55              : 
      56            0 :     *cqHandle = cqPeer;
      57            0 :     return ret;
      58              : 
      59            0 : free_cq_handle:
      60            0 :     free(cqPeer);
      61            0 :     cqPeer = NULL;
      62            0 :     return ret;
      63              : }
      64              : 
      65            0 : int RaPeerNdaCqDestroy(struct RaRdmaHandle *rdmaHandle, void *cqHandle)
      66              : {
      67            0 :     struct RaCqHandleExt *cqPeer = (struct RaCqHandleExt *)cqHandle;
      68            0 :     unsigned int phyId = rdmaHandle->rdevInfo.phyId;
      69              :     void *ibvCqExt;
      70            0 :     int ret = 0;
      71              : 
      72            0 :     RaPeerMutexLock(phyId);
      73            0 :     RsSetCtx(phyId);
      74            0 :     ibvCqExt = (void *)(uintptr_t)cqPeer->addr;
      75            0 :     ret = RsNdaCqDestroy(phyId, rdmaHandle->rdevIndex, ibvCqExt);
      76            0 :     RaPeerMutexUnlock(phyId);
      77            0 :     CHK_PRT_RETURN(ret != 0, hccp_err("[destroy][RaNdaCq]RsNdaCqDestroy failed, ret:%d phyId:%d", ret, phyId), ret);
      78              : 
      79            0 :     return ret;
      80              : }
      81              : 
      82            2 : int RaPeerNdaQpCreate(struct RaRdmaHandle *rdmaHandle, struct NdaQpInitAttr *attr, struct NdaQpInfo *info,
      83              :     void **qpHandle)
      84              : {
      85            2 :     unsigned int phyId = rdmaHandle->rdevInfo.phyId;
      86            2 :     struct RaQpHandle *qpPeer = NULL;
      87            2 :     struct RsQpResp qpResp = {0};
      88            2 :     int ret = 0;
      89              : 
      90            2 :     qpPeer = (struct RaQpHandle *)calloc(1, sizeof(struct RaQpHandle));
      91            2 :     CHK_PRT_RETURN(qpPeer == NULL, hccp_err("[create][RaNdaQp]qpPeer calloc failed phyId:%d", phyId), -ENOMEM);
      92              : 
      93            2 :     RaPeerMutexLock(phyId);
      94            2 :     RsSetCtx(phyId);
      95            2 :     ret = RsNdaQpCreate(phyId, rdmaHandle->rdevIndex, attr, info, &qpResp);
      96            2 :     RaPeerMutexUnlock(phyId);
      97            2 :     if (ret != 0) {
      98            1 :         hccp_err("[create][RaNdaQp]RsNdaQpCreate failed ret:%d phyId:%d", ret, phyId);
      99            1 :         goto free_qp_handle;
     100              :     }
     101            1 :     qpPeer->phyId = phyId;
     102            1 :     qpPeer->qpn = qpResp.qpn;
     103            1 :     qpPeer->psn = qpResp.psn;
     104            1 :     qpPeer->gidIdx = qpResp.gidIdx;
     105            1 :     qpPeer->directFlag = qpResp.directFlag;
     106            1 :     qpPeer->rdevIndex = rdmaHandle->rdevIndex;
     107            1 :     qpPeer->rdmaHandle = rdmaHandle;
     108            1 :     qpPeer->rdmaOps = rdmaHandle->rdmaOps;
     109              : 
     110            1 :     *qpHandle = qpPeer;
     111            1 :     return ret;
     112              : 
     113            1 : free_qp_handle:
     114            1 :     free(qpPeer);
     115            1 :     qpPeer = NULL;
     116            1 :     return ret;
     117              : }
     118              : 
     119            0 : int RaPeerNdaQpDestroy(struct RaQpHandle *qpPeer)
     120              : {
     121            0 :     int ret = 0;
     122              : 
     123            0 :     RaPeerMutexLock(qpPeer->phyId);
     124            0 :     RsSetCtx(qpPeer->phyId);
     125            0 :     ret = RsNdaQpDestroy(qpPeer->phyId, qpPeer->rdevIndex, qpPeer->qpn);
     126            0 :     RaPeerMutexUnlock(qpPeer->phyId);
     127            0 :     if (ret != 0) {
     128            0 :         hccp_err("[destroy][RaNdaQp]RsNdaQpDestroy failed ret:%d phyId:%d", ret, qpPeer->phyId);
     129              :     }
     130            0 :     free(qpPeer);
     131            0 :     qpPeer = NULL;
     132            0 :     return ret;
     133              : }
     134              : 
     135            2 : int RaPeerGetQpHyperFeature(struct RaQpHandle *qpPeer, struct HyperFeature *hyperFeature)
     136              : {
     137            2 :     int ret = 0;
     138              : 
     139            2 :     RaPeerMutexLock(qpPeer->phyId);
     140            2 :     RsSetCtx(qpPeer->phyId);
     141            2 :     ret = RsGetQpHyperFeature(qpPeer->phyId, qpPeer->rdevIndex, qpPeer->qpn, hyperFeature);
     142            2 :     RaPeerMutexUnlock(qpPeer->phyId);
     143            2 :     CHK_PRT_RETURN(ret, hccp_warn("RsGetQpHyperFeature unsuccessful ret(%d) phyId(%u)", ret, qpPeer->phyId), ret);
     144            1 :     return ret;
     145              : }
        

Generated by: LCOV version 2.0-1