LCOV - code coverage report
Current view: top level - base_comm/resources/hccp/rdma_agent/client - ra_rdma.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 98.4 % 64 63
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 <stdlib.h>
      12              : #include <string.h>
      13              : #include <errno.h>
      14              : #include "hccp.h"
      15              : #include "ra.h"
      16              : #include "ra_rs_comm.h"
      17              : #include "ra_client_host.h"
      18              : #include "ra_rdma.h"
      19              : 
      20            3 : HCCP_ATTRI_VISI_DEF int RaSendNormalWrlist(void *qpHandle, struct WrInfo wr[], struct SendWrRsp opRsp[],
      21              :     unsigned int sendNum, unsigned int *completeNum)
      22              : {
      23            3 :     struct WrlistSendCompleteNum wrlistNum = {0};
      24            3 :     struct RaQpHandle *raQpHandle = NULL;
      25              :     unsigned int i;
      26              :     int ret;
      27              : 
      28            3 :     CHK_PRT_RETURN(qpHandle == NULL || wr == NULL || opRsp == NULL || sendNum == 0 || completeNum == NULL,
      29              :         hccp_err("[send][ra_wrlist]qp_handle or wr or op_rsp or complete_num is NULL or send_num is zero, para error!"),
      30              :         ConverReturnCode(RDMA_OP, -EINVAL));
      31              : 
      32            3 :     raQpHandle = (struct RaQpHandle *)qpHandle;
      33            3 :     CHK_PRT_RETURN(raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raSendNormalWrlist == NULL,
      34              :         hccp_err("[send][ra_wrlist]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_send_normal_wrlist is NULL, invalid"),
      35              :         ConverReturnCode(RDMA_OP, -EINVAL));
      36              : 
      37            3 :     for (i = 0; i < sendNum; i++) {
      38            2 :         CHK_PRT_RETURN(wr[i].memList.len > MAX_SG_LIST_LEN_MAX,
      39              :             hccp_err("[send][ra_wrlist]wr[%u] mem_list.len(%u) > %d", i, wr[i].memList.len, MAX_SG_LIST_LEN_MAX),
      40              :             ConverReturnCode(RDMA_OP, -EINVAL));
      41              :     }
      42              : 
      43            1 :     wrlistNum.sendNum = sendNum;
      44            1 :     wrlistNum.completeNum = completeNum;
      45            1 :     ret = raQpHandle->rdmaOps->raSendNormalWrlist(raQpHandle, wr, opRsp, wrlistNum);
      46            1 :     return ConverReturnCode(RDMA_OP, ret);
      47              : }
      48              : 
      49            4 : void RaRdevSaveNotifyMr(struct RaRdmaHandle *rdmaHandle, int ret, uint64_t va, uint64_t size)
      50              : {
      51              :     // ret != 0 means unsuccessful, no need to save notify mr info
      52            4 :     if (ret != 0) {
      53            0 :         return;
      54              :     }
      55              : 
      56            4 :     rdmaHandle->notifyVa = va;
      57            4 :     rdmaHandle->notifySize = size;
      58              : }
      59              : 
      60            1 : STATIC void RaRdevCheckNotifyMr(struct RaRdmaHandle *rdmaHandle, uint64_t va, uint64_t size)
      61              : {
      62            1 :     if ((rdmaHandle->notifyVa <= (va + size)) && (va <= (rdmaHandle->notifyVa + rdmaHandle->notifySize))) {
      63            1 :         hccp_run_warn("[check][ra_mr]phyId:%u notify{va:0x%llx size:0x%llx} overlap input{va:0x%llx size:0x%llx}",
      64              :             rdmaHandle->rdevInfo.phyId, rdmaHandle->notifyVa, rdmaHandle->notifySize, va, size);
      65              :     }
      66            1 : }
      67              : 
      68            2 : HCCP_ATTRI_VISI_DEF int RaRegisterMr(const void *rdmaHandle, struct MrInfoT *info, void **mrHandle)
      69              : {
      70            2 :     struct RaRdmaHandle *rdmaHandleTmp = NULL;
      71              :     int ret;
      72              : 
      73            2 :     CHK_PRT_RETURN(rdmaHandle == NULL || info == NULL || mrHandle == NULL,
      74              :         hccp_err("[init][ra_mr]rdma_handle or info or mr_handle is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
      75              : 
      76            1 :     rdmaHandleTmp = (struct RaRdmaHandle *)rdmaHandle;
      77            1 :     CHK_PRT_RETURN(rdmaHandleTmp->rdmaOps == NULL || rdmaHandleTmp->rdmaOps->raRegisterMr == NULL,
      78              :         hccp_err("[init][ra_mr]rdma_ops or rdma_ops->ra_register_mr is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
      79              : 
      80            1 :     RaRdevCheckNotifyMr(rdmaHandleTmp, (uint64_t)(uintptr_t)info->addr, info->size);
      81            1 :     ret = rdmaHandleTmp->rdmaOps->raRegisterMr(rdmaHandleTmp, info, mrHandle);
      82            1 :     return ConverReturnCode(RDMA_OP, ret);
      83              : }
      84              : 
      85            1 : HCCP_ATTRI_VISI_DEF int RaRemapMr(const void *rdmaHandle, struct MemRemapInfo info[], unsigned int num)
      86              : {
      87            1 :     struct RaRdmaHandle *rdmaHandleTmp = NULL;
      88              :     int ret;
      89              : 
      90            1 :     CHK_PRT_RETURN(rdmaHandle == NULL || info == NULL || num == 0 || num > REMAP_MR_MAX_NUM,
      91              :         hccp_err("[remap][ra_mr]rdma_handle or info is NULL or num:%u is out of range (0:%u]", num, REMAP_MR_MAX_NUM),
      92              :         ConverReturnCode(RDMA_OP, -EINVAL));
      93              : 
      94            1 :     rdmaHandleTmp = (struct RaRdmaHandle *)rdmaHandle;
      95            1 :     CHK_PRT_RETURN(rdmaHandleTmp->rdmaOps == NULL || rdmaHandleTmp->rdmaOps->raRemapMr == NULL,
      96              :         hccp_err("[remap][ra_mr]rdma_ops or rdma_ops->ra_remap_mr is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
      97              : 
      98            1 :     ret = rdmaHandleTmp->rdmaOps->raRemapMr(rdmaHandleTmp, info, num);
      99            1 :     return ConverReturnCode(RDMA_OP, ret);
     100              : }
     101              : 
     102            2 : HCCP_ATTRI_VISI_DEF int RaDeregisterMr(const void *rdmaHandle, void *mrHandle)
     103              : {
     104            2 :     struct RaRdmaHandle *rdmaHandleTmp = NULL;
     105              :     int ret;
     106              : 
     107            2 :     CHK_PRT_RETURN(rdmaHandle == NULL || mrHandle == NULL, hccp_err("[deinit][ra_mr]rdma_handle or mr_handle is NULL"),
     108              :         ConverReturnCode(RDMA_OP, -EINVAL));
     109              : 
     110            1 :     rdmaHandleTmp = (struct RaRdmaHandle *)rdmaHandle;
     111            1 :     CHK_PRT_RETURN(rdmaHandleTmp->rdmaOps == NULL || rdmaHandleTmp->rdmaOps->raDeregisterMr == NULL,
     112              :         hccp_err("[deinit][ra_mr]rdma_ops or rdma_ops->ra_deregister_mr is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
     113              : 
     114            1 :     ret = rdmaHandleTmp->rdmaOps->raDeregisterMr(rdmaHandleTmp, mrHandle);
     115            1 :     return ConverReturnCode(RDMA_OP, ret);
     116              : }
     117              : 
     118            5 : HCCP_ATTRI_VISI_DEF int RaGetLbMax(void *rdevHandle, int *lbMax)
     119              : {
     120            5 :     struct RaRdmaHandle *rdevHandleTmp = (struct RaRdmaHandle *)rdevHandle;
     121            5 :     int ret = 0;
     122              : 
     123            5 :     CHK_PRT_RETURN(rdevHandle == NULL || lbMax == NULL, hccp_err("[get][lbMax]rdevHandle or lbMax is NULL, invalid"),
     124              :         ConverReturnCode(RDMA_OP, -EINVAL));
     125              : 
     126            3 :     CHK_PRT_RETURN(rdevHandleTmp->rdmaOps == NULL || rdevHandleTmp->rdmaOps->raGetLbMax == NULL,
     127              :         hccp_err("[get][lbMax]rdmaOps is NULL or rdmaOps->raGetLbMax is NULL, invalid"),
     128              :         ConverReturnCode(RDMA_OP, -EINVAL));
     129              : 
     130            1 :     ret = rdevHandleTmp->rdmaOps->raGetLbMax(rdevHandleTmp, lbMax);
     131            1 :     return ConverReturnCode(RDMA_OP, ret);
     132              : }
     133              : 
     134            4 : HCCP_ATTRI_VISI_DEF int RaSetQpLbValue(void *qpHandle, int lbValue)
     135              : {
     136            4 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
     137            4 :     int ret = 0;
     138              : 
     139            4 :     CHK_PRT_RETURN(qpHandle == NULL, hccp_err("[set][lbValue]qpHandle is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
     140              : 
     141            3 :     CHK_PRT_RETURN(raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raSetQpLbValue == NULL,
     142              :         hccp_err("[set][lbValue]rdmaOps is NULL or rdmaOps->raSetQpLbValue is NULL"),
     143              :         ConverReturnCode(RDMA_OP, -EINVAL));
     144              : 
     145            1 :     ret = raQpHandle->rdmaOps->raSetQpLbValue(raQpHandle, lbValue);
     146            1 :     return ConverReturnCode(RDMA_OP, ret);
     147              : }
     148              : 
     149            5 : HCCP_ATTRI_VISI_DEF int RaGetQpLbValue(void *qpHandle, int *lbValue)
     150              : {
     151            5 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
     152            5 :     int ret = 0;
     153              : 
     154            5 :     CHK_PRT_RETURN(qpHandle == NULL || lbValue == NULL, hccp_err("[get][lbValue]qpHandle or lbValue is NULL"),
     155              :         ConverReturnCode(RDMA_OP, -EINVAL));
     156              : 
     157            3 :     CHK_PRT_RETURN(raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raGetQpLbValue == NULL,
     158              :         hccp_err("[get][lbValue]rdmaOps is NULL or rdmaOps->raGetQpLbValue is NULL"),
     159              :         ConverReturnCode(RDMA_OP, -EINVAL));
     160              : 
     161            1 :     ret = raQpHandle->rdmaOps->raGetQpLbValue(raQpHandle, lbValue);
     162            1 :     return ConverReturnCode(RDMA_OP, ret);
     163              : }
        

Generated by: LCOV version 2.0-1