LCOV - code coverage report
Current view: top level - base_comm/resources/hccp/rdma_agent/comm/ctx - ra_ctx_comm.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 89 89
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 9 9

            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 <errno.h>
      12              : #include "securec.h"
      13              : #include "user_log.h"
      14              : #include "ra_ctx_comm.h"
      15              : 
      16            6 : int RaCtxPrepareLmemRegister(struct MrRegInfoT *lmemInfo, struct MemRegAttrT *memAttr)
      17              : {
      18            6 :     struct RaTokenIdHandle *tokenIdHandle = NULL;
      19            6 :     bool isTokenIdValid = false;
      20              : 
      21            6 :     memAttr->mem = lmemInfo->in.mem;
      22            6 :     isTokenIdValid = lmemInfo->in.ub.flags.bs.tokenIdValid == 1;
      23            6 :     CHK_PRT_RETURN(isTokenIdValid && lmemInfo->in.ub.tokenIdHandle == NULL,
      24              :         hccp_err("[init][ra_ctx_lmem]lmem_info specify token id, but tokenIdHandle is NULL"), -EINVAL);
      25            5 :     memAttr->ub.flags = lmemInfo->in.ub.flags;
      26            5 :     memAttr->ub.tokenValue = lmemInfo->in.ub.tokenValue;
      27            5 :     tokenIdHandle = (struct RaTokenIdHandle *)(lmemInfo->in.ub.tokenIdHandle);
      28            5 :     memAttr->ub.tokenIdAddr = isTokenIdValid ? tokenIdHandle->addr : 0;
      29              : 
      30            5 :     return 0;
      31              : }
      32              : 
      33            3 : void RaCtxGetLmemInfo(struct MemRegInfoT *memInfo, struct MrRegInfoT *lmemInfo, struct RaLmemHandle *lmemHandle)
      34              : {
      35            3 :     lmemInfo->out.key = memInfo->key;
      36            3 :     lmemInfo->out.ub.tokenId = memInfo->ub.tokenId;
      37            3 :     lmemInfo->out.ub.targetSegHandle = memInfo->ub.targetSegHandle;
      38            3 :     lmemHandle->addr = lmemInfo->out.ub.targetSegHandle;
      39            3 : }
      40              : 
      41            3 : void RaCtxPrepareRmemImport(struct MrImportInfoT *rmemInfo, struct MemImportAttrT *memAttr)
      42              : {
      43            3 :     memAttr->key = rmemInfo->in.key;
      44            3 :     memAttr->ub.flags = rmemInfo->in.ub.flags;
      45            3 :     memAttr->ub.mappingAddr = rmemInfo->in.ub.mappingAddr;
      46            3 :     memAttr->ub.tokenValue = rmemInfo->in.ub.tokenValue;
      47            3 : }
      48              : 
      49            4 : void RaCtxPrepareCqCreate(struct CqInfoT *info, struct CtxCqAttr *cqAttr)
      50              : {
      51            4 :     struct RaChanHandle *chanHandle = NULL;
      52              : 
      53            4 :     cqAttr->depth = info->in.depth;
      54            4 :     cqAttr->ub.userCtx = info->in.ub.userCtx;
      55            4 :     cqAttr->ub.mode = info->in.ub.mode;
      56            4 :     cqAttr->ub.ceqn = info->in.ub.ceqn;
      57            4 :     cqAttr->ub.flag = info->in.ub.flag;
      58            4 :     if (info->in.chanHandle != NULL) {
      59            1 :         chanHandle = (struct RaChanHandle *)info->in.chanHandle;
      60            1 :         cqAttr->chanAddr = chanHandle->addr;
      61              :     }
      62            4 : }
      63              : 
      64            3 : void RaCtxGetCqCreateInfo(struct CtxCqInfo *cqInfo, struct CqInfoT *info)
      65              : {
      66            3 :     info->out.va = cqInfo->addr;
      67            3 :     info->out.id = cqInfo->ub.id;
      68            3 :     info->out.cqeSize = cqInfo->ub.cqeSize;
      69            3 :     info->out.bufAddr = cqInfo->ub.bufAddr;
      70            3 :     info->out.swdbAddr = cqInfo->ub.swdbAddr;
      71            3 : }
      72              : 
      73            8 : int RaCtxPrepareQpCreate(struct QpCreateAttr *qpAttr, struct CtxQpAttr *ctxQpAttr)
      74              : {
      75            8 :     struct RaTokenIdHandle *tokenIdHandle = NULL;
      76              : 
      77            8 :     CHK_PRT_RETURN(qpAttr->scqHandle == NULL, hccp_err("[init][ra_ctx_qp]scq_handle is NULL"), -EINVAL);
      78            7 :     CHK_PRT_RETURN(qpAttr->rcqHandle == NULL, hccp_err("[init][ra_ctx_qp]rcq_handle is NULL"), -EINVAL);
      79              : 
      80            6 :     ctxQpAttr->scqIndex = ((struct RaCqHandle *)qpAttr->scqHandle)->addr;
      81            6 :     ctxQpAttr->rcqIndex = ((struct RaCqHandle *)qpAttr->rcqHandle)->addr;
      82            6 :     ctxQpAttr->srqIndex = 0;
      83            6 :     ctxQpAttr->sqDepth = qpAttr->sqDepth;
      84            6 :     ctxQpAttr->rqDepth = qpAttr->rqDepth;
      85            6 :     ctxQpAttr->transportMode = qpAttr->transportMode;
      86              : 
      87            6 :     ctxQpAttr->ub.mode = qpAttr->ub.mode;
      88            6 :     ctxQpAttr->ub.jettyId = qpAttr->ub.jettyId;
      89            6 :     ctxQpAttr->ub.flag = qpAttr->ub.flag;
      90            6 :     ctxQpAttr->ub.jfsFlag = qpAttr->ub.jfsFlag;
      91            6 :     ctxQpAttr->ub.tokenValue = qpAttr->ub.tokenValue;
      92            6 :     ctxQpAttr->ub.priority = qpAttr->ub.priority;
      93            6 :     ctxQpAttr->ub.rnrRetry = qpAttr->ub.rnrRetry;
      94            6 :     ctxQpAttr->ub.errTimeout = qpAttr->ub.errTimeout;
      95              : 
      96            6 :     if (qpAttr->ub.tokenIdHandle != NULL) {
      97            1 :         tokenIdHandle = (struct RaTokenIdHandle *)(qpAttr->ub.tokenIdHandle);
      98            1 :         ctxQpAttr->ub.tokenIdAddr = tokenIdHandle->addr;
      99              :     }
     100              : 
     101            6 :     return 0;
     102              : }
     103              : 
     104            4 : void RaCtxGetQpCreateInfo(struct RaCtxHandle *ctxHandle, struct QpCreateAttr *qpAttr, struct QpCreateInfo *qpInfo,
     105              :     struct RaCtxQpHandle *qpHandle)
     106              : {
     107            4 :     qpHandle->devIndex = ctxHandle->devIndex;
     108            4 :     qpHandle->phyId = ctxHandle->attr.phyId;
     109            4 :     qpHandle->ctxHandle = ctxHandle;
     110            4 :     qpHandle->protocol = ctxHandle->protocol;
     111            4 :     qpHandle->id = qpInfo->ub.id;
     112            4 :     (void)memcpy_s(&qpHandle->qpAttr, sizeof(struct QpCreateAttr), qpAttr, sizeof(struct QpCreateAttr));
     113            4 :     (void)memcpy_s(&qpHandle->qpInfo, sizeof(struct QpCreateInfo), qpInfo, sizeof(struct QpCreateInfo));
     114            4 : }
     115              : 
     116            4 : void RaCtxPrepareQpImport(struct QpImportInfoT *qpInfo, struct RaRsJettyImportAttr *importAttr)
     117              : {
     118            4 :     importAttr->mode = qpInfo->in.ub.mode;
     119            4 :     importAttr->tokenValue = qpInfo->in.ub.tokenValue;
     120            4 :     importAttr->policy = qpInfo->in.ub.policy;
     121            4 :     importAttr->type = qpInfo->in.ub.type;
     122            4 :     importAttr->flag = qpInfo->in.ub.flag;
     123            4 :     importAttr->expImportCfg = qpInfo->in.ub.expImportCfg;
     124            4 :     importAttr->tpType = qpInfo->in.ub.tpType;
     125            4 : }
     126              : 
     127            2 : void RaCtxGetQpImportInfo(struct RaCtxHandle *ctxHandle, struct QpImportInfoT *qpInfo,
     128              :     struct RaRsJettyImportInfo *importInfo, struct RaCtxRemQpHandle *qpHandle)
     129              : {
     130            2 :     qpInfo->out.ub.tjettyHandle = importInfo->tjettyHandle;
     131            2 :     qpInfo->out.ub.tpn = importInfo->tpn;
     132            2 :     qpHandle->devIndex = ctxHandle->devIndex;
     133            2 :     qpHandle->phyId = ctxHandle->attr.phyId;
     134            2 :     qpHandle->protocol = ctxHandle->protocol;
     135            2 :     qpHandle->qpKey = qpInfo->in.key;
     136            2 : }
        

Generated by: LCOV version 2.0-1