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: 50.0 % 92 46
Test Date: 2026-08-25 19:18:03 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:%u", 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:%u", 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:%u", ret, phyId);
      51            0 :         goto free_cq_handle;
      52              :     }
      53            0 :     cqPeer->addr = (unsigned long long)(uintptr_t)ibvCqExt;
      54              : 
      55            0 :     *cqHandle = cqPeer;
      56            0 :     return ret;
      57              : 
      58            0 : free_cq_handle:
      59            0 :     free(cqPeer);
      60            0 :     cqPeer = NULL;
      61            0 :     return ret;
      62              : }
      63              : 
      64            0 : int RaPeerNdaCqDestroy(struct RaRdmaHandle *rdmaHandle, void *cqHandle)
      65              : {
      66            0 :     struct RaCqHandleExt *cqPeer = (struct RaCqHandleExt *)cqHandle;
      67            0 :     unsigned int phyId = rdmaHandle->rdevInfo.phyId;
      68              :     void *ibvCqExt;
      69            0 :     int ret = 0;
      70              : 
      71            0 :     RaPeerMutexLock(phyId);
      72            0 :     RsSetCtx(phyId);
      73            0 :     ibvCqExt = (void *)(uintptr_t)cqPeer->addr;
      74            0 :     ret = RsNdaCqDestroy(phyId, rdmaHandle->rdevIndex, ibvCqExt);
      75            0 :     RaPeerMutexUnlock(phyId);
      76            0 :     if (ret != 0) {
      77            0 :         hccp_err("[destroy][RaNdaCq]RsNdaCqDestroy failed ret:%d phyId:%u", ret, phyId);
      78              :     }
      79            0 :     free(cqPeer);
      80            0 :     cqPeer = NULL;
      81            0 :     return ret;
      82              : }
      83              : 
      84            2 : int RaPeerNdaQpCreate(struct RaRdmaHandle *rdmaHandle, struct NdaQpInitAttr *attr, struct NdaQpInfo *info,
      85              :     void **qpHandle)
      86              : {
      87            2 :     unsigned int phyId = rdmaHandle->rdevInfo.phyId;
      88            2 :     struct RaQpHandle *qpPeer = NULL;
      89            2 :     struct RsQpResp qpResp = {0};
      90            2 :     int ret = 0;
      91              : 
      92            2 :     qpPeer = (struct RaQpHandle *)calloc(1, sizeof(struct RaQpHandle));
      93            2 :     CHK_PRT_RETURN(qpPeer == NULL, hccp_err("[create][RaNdaQp]qpPeer calloc failed phyId:%u", phyId), -ENOMEM);
      94              : 
      95            2 :     RaPeerMutexLock(phyId);
      96            2 :     RsSetCtx(phyId);
      97            2 :     ret = RsNdaQpCreate(phyId, rdmaHandle->rdevIndex, attr, info, &qpResp);
      98            2 :     RaPeerMutexUnlock(phyId);
      99            2 :     if (ret != 0) {
     100            1 :         hccp_err("[create][RaNdaQp]RsNdaQpCreate failed ret:%d phyId:%u", ret, phyId);
     101            1 :         goto free_qp_handle;
     102              :     }
     103            1 :     qpPeer->phyId = phyId;
     104            1 :     qpPeer->qpn = qpResp.qpn;
     105            1 :     qpPeer->psn = qpResp.psn;
     106            1 :     qpPeer->gidIdx = qpResp.gidIdx;
     107            1 :     qpPeer->directFlag = qpResp.directFlag;
     108            1 :     qpPeer->rdevIndex = rdmaHandle->rdevIndex;
     109            1 :     qpPeer->rdmaHandle = rdmaHandle;
     110            1 :     qpPeer->rdmaOps = rdmaHandle->rdmaOps;
     111              : 
     112            1 :     *qpHandle = qpPeer;
     113            1 :     return ret;
     114              : 
     115            1 : free_qp_handle:
     116            1 :     free(qpPeer);
     117            1 :     qpPeer = NULL;
     118            1 :     return ret;
     119              : }
     120              : 
     121            0 : int RaPeerNdaQpDestroy(struct RaQpHandle *qpPeer)
     122              : {
     123            0 :     int ret = 0;
     124              : 
     125            0 :     RaPeerMutexLock(qpPeer->phyId);
     126            0 :     RsSetCtx(qpPeer->phyId);
     127            0 :     ret = RsNdaQpDestroy(qpPeer->phyId, qpPeer->rdevIndex, qpPeer->qpn);
     128            0 :     RaPeerMutexUnlock(qpPeer->phyId);
     129            0 :     if (ret != 0) {
     130            0 :         hccp_err("[destroy][RaNdaQp]RsNdaQpDestroy failed ret:%d phyId:%u", ret, qpPeer->phyId);
     131              :     }
     132            0 :     free(qpPeer);
     133            0 :     qpPeer = NULL;
     134            0 :     return ret;
     135              : }
     136              : 
     137            2 : int RaPeerGetQpHyperFeature(struct RaQpHandle *qpPeer, struct HyperFeature *hyperFeature)
     138              : {
     139            2 :     int ret = 0;
     140              : 
     141            2 :     RaPeerMutexLock(qpPeer->phyId);
     142            2 :     RsSetCtx(qpPeer->phyId);
     143            2 :     ret = RsGetQpHyperFeature(qpPeer->phyId, qpPeer->rdevIndex, qpPeer->qpn, hyperFeature);
     144            2 :     RaPeerMutexUnlock(qpPeer->phyId);
     145            2 :     CHK_PRT_RETURN(ret, hccp_warn("RsGetQpHyperFeature unsuccessful ret(%d) phyId(%u)", ret, qpPeer->phyId), ret);
     146            1 :     return ret;
     147              : }
        

Generated by: LCOV version 2.0-1