LCOV - code coverage report
Current view: top level - base_comm/resources/hccp/rdma_agent/client/async - ra_ctx.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 89.6 % 134 120
Test Date: 2026-07-28 12:11:00 Functions: 83.3 % 12 10

            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 "user_log.h"
      13              : #include "hccp_ctx.h"
      14              : #include "hccp_async_ctx.h"
      15              : #include "ra_hdc_async_ctx.h"
      16              : #include "ra_ctx.h"
      17              : 
      18            4 : HCCP_ATTRI_VISI_DEF int RaGetEidByIpAsync(void *ctxHandle, struct IpInfo ip[], union HccpEid eid[],
      19              :     unsigned int *num, void **reqHandle)
      20              : {
      21            4 :     struct RaCtxHandle *ctxHandleTmp = NULL;
      22            4 :     int ret = 0;
      23              : 
      24            4 :     CHK_PRT_RETURN(ctxHandle == NULL || ip == NULL || eid == NULL || num == NULL || reqHandle == NULL,
      25              :         hccp_err("[get][eid_by_ip]ctx_handle or ip or eid or num or req_handle is NULL"),
      26              :         ConverReturnCode(RDMA_OP, -EINVAL));
      27              : 
      28            3 :     CHK_PRT_RETURN(*num == 0 || *num > GET_EID_BY_IP_MAX_NUM, hccp_err("[get][eid_by_ip]num(%u) must greater than 0"
      29              :         " and less or equal to %d", *num, GET_EID_BY_IP_MAX_NUM), ConverReturnCode(RDMA_OP, -EINVAL));
      30              : 
      31            2 :     ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
      32              : 
      33            2 :     hccp_run_info("Input parameters: phy_id(%u), devIndex(0x%x)",
      34              :         ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex);
      35            2 :     ret = RaHdcGetEidByIpAsync(ctxHandleTmp, ip, eid, num, reqHandle);
      36            2 :     if (ret != 0) {
      37            1 :         hccp_err("[get][eid_by_ip]ra_hdc_get_eid_by_ip_async failed, ret(%d) phyId(%u), devIndex(0x%x)", ret,
      38              :             ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex);
      39              :     }
      40              : 
      41            2 :     return ret;
      42              : }
      43              : 
      44            2 : HCCP_ATTRI_VISI_DEF int RaCtxLmemRegisterAsync(void *ctxHandle, struct MrRegInfoT *lmemInfo,
      45              :     void **lmemHandle, void **reqHandle)
      46              : {
      47            2 :     struct RaLmemHandle *lmemHandleTmp = NULL;
      48            2 :     struct RaCtxHandle *ctxHandleTmp = NULL;
      49            2 :     int ret = 0;
      50              : 
      51            2 :     CHK_PRT_RETURN(ctxHandle == NULL || lmemInfo == NULL || lmemHandle == NULL || reqHandle == NULL,
      52              :         hccp_err("[init][ra_lmem]ctx_handle or lmem_info or lmem_handle or req_handle is NULL"),
      53              :         ConverReturnCode(RDMA_OP, -EINVAL));
      54              : 
      55            2 :     ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
      56            2 :     lmemHandleTmp = calloc(1, sizeof(struct RaLmemHandle));
      57            2 :     CHK_PRT_RETURN(lmemHandleTmp == NULL,
      58              :         hccp_err("[init][ra_lmem]calloc lmem_handle_tmp failed, errno(%d) phyId(%u) devIndex(%u)",
      59              :         errno, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex), ConverReturnCode(RDMA_OP, -ENOMEM));
      60              : 
      61            2 :     ret = RaHdcCtxLmemRegisterAsync(ctxHandleTmp, lmemInfo, lmemHandleTmp, reqHandle);
      62            2 :     if (ret != 0) {
      63            1 :         hccp_err("[init][ra_lmem]register_async failed, ret(%d) phyId(%u), devIndex(%u)", ret,
      64              :             ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex);
      65            1 :         goto err;
      66              :     }
      67              : 
      68            1 :     *lmemHandle = (void *)lmemHandleTmp;
      69            1 :     return 0;
      70              : 
      71            1 : err:
      72            1 :     free(lmemHandleTmp);
      73            1 :     lmemHandleTmp = NULL;
      74            1 :     return ConverReturnCode(RDMA_OP, ret);
      75              : }
      76              : 
      77            3 : HCCP_ATTRI_VISI_DEF int RaCtxLmemUnregisterAsync(void *ctxHandle, void *lmemHandle, void **reqHandle)
      78              : {
      79            3 :     struct RaLmemHandle *lmemHandleTmp = NULL;
      80            3 :     struct RaCtxHandle *ctxHandleTmp = NULL;
      81              :     int ret;
      82              : 
      83            3 :     CHK_PRT_RETURN(ctxHandle == NULL || lmemHandle == NULL || reqHandle == NULL,
      84              :         hccp_err("[deinit][ra_lmem]ctx_handle or lmem_handle or req_handle is NULL"),
      85              :         ConverReturnCode(RDMA_OP, -EINVAL));
      86              : 
      87            3 :     ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
      88            3 :     lmemHandleTmp = (struct RaLmemHandle *)lmemHandle;
      89            3 :     ret = RaHdcCtxLmemUnregisterAsync(ctxHandleTmp, lmemHandleTmp, reqHandle);
      90            3 :     if (ret != 0) {
      91            1 :         hccp_err("[deinit][ra_lmem]unregister_async failed, ret(%d) phyId(%u), devIndex(%u)", ret,
      92              :             ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex);
      93              :     }
      94              : 
      95            3 :     free(lmemHandleTmp);
      96            3 :     lmemHandleTmp = NULL;
      97            3 :     return ConverReturnCode(RDMA_OP, ret);
      98              : }
      99              : 
     100            3 : HCCP_ATTRI_VISI_DEF int RaCtxQpCreateAsync(void *ctxHandle, struct QpCreateAttr *attr,
     101              :     struct QpCreateInfo *info, void **qpHandle, void **reqHandle)
     102              : {
     103            3 :     struct RaCtxQpHandle *qpHandleTmp = NULL;
     104            3 :     struct RaCtxHandle *ctxHandleTmp = NULL;
     105              :     int ret;
     106              : 
     107            3 :     CHK_PRT_RETURN(ctxHandle == NULL || attr == NULL || info == NULL || qpHandle == NULL || reqHandle == NULL,
     108              :         hccp_err("[init][ra_qp]ctx_handle or attr or info or qp_handle or req_handle is NULL"),
     109              :         ConverReturnCode(RDMA_OP, -EINVAL));
     110              : 
     111            3 :     ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
     112            3 :     qpHandleTmp = calloc(1, sizeof(struct RaCtxQpHandle));
     113            3 :     CHK_PRT_RETURN(qpHandleTmp == NULL,
     114              :         hccp_err("[init][ra_qp]calloc qp_handle_tmp failed, errno(%d) phyId(%u) devIndex(%u)",
     115              :         errno, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex), ConverReturnCode(RDMA_OP, -ENOMEM));
     116              : 
     117            3 :     ret = RaHdcCtxQpCreateAsync(ctxHandleTmp, attr, info, qpHandleTmp, reqHandle);
     118            3 :     if (ret != 0) {
     119            1 :         hccp_err("[init][ra_qp]create_async failed, ret(%d) phyId(%u), devIndex(%u)", ret,
     120              :             ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex);
     121            1 :         goto err;
     122              :     }
     123              : 
     124            2 :     *qpHandle = (void *)qpHandleTmp;
     125            2 :     return 0;
     126              : 
     127            1 : err:
     128            1 :     free(qpHandleTmp);
     129            1 :     qpHandleTmp = NULL;
     130            1 :     return ConverReturnCode(RDMA_OP, ret);
     131              : }
     132              : 
     133            2 : HCCP_ATTRI_VISI_DEF int RaCtxQpDestroyAsync(void *qpHandle, void **reqHandle)
     134              : {
     135            2 :     struct RaCtxQpHandle *qpHandleTmp = NULL;
     136              :     int ret;
     137              : 
     138            2 :     CHK_PRT_RETURN(qpHandle == NULL || reqHandle == NULL, hccp_err("[deinit][ra_qp]qp_handle or req_handle is NULL"),
     139              :         ConverReturnCode(RDMA_OP, -EINVAL));
     140              : 
     141            2 :     qpHandleTmp = (struct RaCtxQpHandle *)qpHandle;
     142            2 :     ret = RaHdcCtxQpDestroyAsync(qpHandleTmp, reqHandle);
     143            2 :     if (ret != 0) {
     144            1 :         hccp_err("[deinit][ra_qp]destroy_async failed, ret(%d) phyId(%u), devIndex(%u) qp_id(%u)",
     145              :             ret, qpHandleTmp->phyId, qpHandleTmp->devIndex, qpHandleTmp->id);
     146              :     }
     147              : 
     148            2 :     free(qpHandleTmp);
     149            2 :     qpHandleTmp = NULL;
     150            2 :     return ConverReturnCode(RDMA_OP, ret);
     151              : }
     152              : 
     153            2 : STATIC void RaFreeQpHandleBatch(void *qpHandle[], unsigned int num)
     154              : {
     155              :     unsigned int i;
     156              : 
     157            4 :     for (i = 0; i < num; ++i) {
     158            2 :         if (qpHandle[i] != NULL) {
     159            2 :             free(qpHandle[i]);
     160            2 :             qpHandle[i] = NULL;
     161              :         }
     162              :     }
     163            2 : }
     164              : 
     165            8 : HCCP_ATTRI_VISI_DEF int RaCtxQpDestroyBatchAsync(void *ctxHandle, void *qpHandle[],
     166              :     unsigned int *num, void **reqHandle)
     167              : {
     168            8 :     struct RaCtxHandle *ctxHandleTmp = NULL;
     169              :     int ret;
     170              : 
     171            8 :     CHK_PRT_RETURN(ctxHandle == NULL || qpHandle == NULL || reqHandle == NULL || num == NULL,
     172              :         hccp_err("[destroy_batch][ra_qp]ctx_handle or qp_handle or req_handle or num is NULL"),
     173              :         ConverReturnCode(RDMA_OP, -EINVAL));
     174            4 :     CHK_PRT_RETURN(*num == 0 || *num > HCCP_MAX_QP_DESTROY_BATCH_NUM,
     175              :         hccp_err("[destroy_batch][ra_qp]num(%u) is out of range(0, %u]", *num, HCCP_MAX_QP_DESTROY_BATCH_NUM),
     176              :         ConverReturnCode(RDMA_OP, -EINVAL));
     177              : 
     178            2 :     ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
     179            2 :     ret = RaHdcCtxQpDestroyBatchAsync(ctxHandleTmp, qpHandle, num, reqHandle);
     180            2 :     if (ret != 0) {
     181            1 :         hccp_err("[destroy_batch][ra_qp]qp_destroy_batch_async failed, ret[%d] phyId[%u] num[%u] devIndex[%u]",
     182              :             ret, ctxHandleTmp->attr.phyId, *num, ctxHandleTmp->devIndex);
     183              :     }
     184              : 
     185            2 :     RaFreeQpHandleBatch(qpHandle, *num);
     186            2 :     return ConverReturnCode(RDMA_OP, ret);
     187              : }
     188              : 
     189            2 : HCCP_ATTRI_VISI_DEF int RaCtxQpImportAsync(void *ctxHandle, struct QpImportInfoT *info, void **remQpHandle,
     190              :     void **reqHandle)
     191              : {
     192            2 :     struct RaCtxRemQpHandle *remQpHandleTmp = NULL;
     193            2 :     struct RaCtxHandle *ctxHandleTmp = NULL;
     194              :     int ret;
     195              : 
     196            2 :     CHK_PRT_RETURN(ctxHandle == NULL || info == NULL || remQpHandle == NULL || reqHandle == NULL,
     197              :         hccp_err("[init][ra_qp]ctx_handle or info or rem_qp_handle or req_handle is NULL"),
     198              :         ConverReturnCode(RDMA_OP, -EINVAL));
     199              : 
     200            2 :     ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
     201            2 :     remQpHandleTmp = calloc(1, sizeof(struct RaCtxRemQpHandle));
     202            2 :     CHK_PRT_RETURN(remQpHandleTmp == NULL,
     203              :         hccp_err("[init][ra_qp]calloc rem_qp_handle_tmp failed, errno(%d) phyId(%u) devIndex(%u)",
     204              :         errno, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex), ConverReturnCode(RDMA_OP, -ENOMEM));
     205              : 
     206            2 :     ret = RaHdcCtxQpImportAsync(ctxHandleTmp, info, remQpHandleTmp, reqHandle);
     207            2 :     if (ret != 0) {
     208            1 :         hccp_err("[init][ra_qp]import_async failed, ret(%d) phyId(%u), devIndex(%u)",
     209              :             ret, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex);
     210            1 :         goto err;
     211              :     }
     212              : 
     213            1 :     *remQpHandle = (void *)remQpHandleTmp;
     214            1 :     return 0;
     215              : 
     216            1 : err:
     217            1 :     free(remQpHandleTmp);
     218            1 :     remQpHandleTmp = NULL;
     219            1 :     return ConverReturnCode(RDMA_OP, ret);
     220              : }
     221              : 
     222            2 : HCCP_ATTRI_VISI_DEF int RaCtxQpUnimportAsync(void *remQpHandle, void **reqHandle)
     223              : {
     224            2 :     struct RaCtxRemQpHandle *remQpHandleTmp = NULL;
     225              :     int ret;
     226              : 
     227            2 :     CHK_PRT_RETURN(remQpHandle == NULL || reqHandle == NULL,
     228              :         hccp_err("[deinit][ra_qp]rem_qp_handle or req_handle is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
     229              : 
     230            2 :     remQpHandleTmp = (struct RaCtxRemQpHandle *)remQpHandle;
     231            2 :     ret = RaHdcCtxQpUnimportAsync(remQpHandleTmp, reqHandle);
     232            2 :     if (ret != 0) {
     233            1 :         hccp_err("[deinit][ra_qp]unimport_async failed, ret(%d) phyId(%u) devIndex(%u) qp_id(%u)",
     234              :             ret, remQpHandleTmp->phyId, remQpHandleTmp->devIndex, remQpHandleTmp->id);
     235              :     }
     236              : 
     237            2 :     free(remQpHandleTmp);
     238            2 :     remQpHandleTmp = NULL;
     239            2 :     return ConverReturnCode(RDMA_OP, ret);
     240              : }
     241              : 
     242            8 : HCCP_ATTRI_VISI_DEF int RaGetTpInfoListAsync(void *ctxHandle, struct GetTpCfg *cfg, struct HccpTpInfo infoList[],
     243              :     unsigned int *num, void **reqHandle)
     244              : {
     245            8 :     struct RaCtxHandle *ctxHandleTmp = NULL;
     246              :     int ret;
     247              : 
     248            8 :     CHK_PRT_RETURN(ctxHandle == NULL || cfg == NULL || reqHandle == NULL,
     249              :         hccp_err("[get][ra_tp_info]ctx_handle or cfg or req_handle is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
     250            5 :     CHK_PRT_RETURN(infoList == NULL || num == NULL,
     251              :         hccp_err("[get][ra_tp_info]info_list or num is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
     252            3 :     CHK_PRT_RETURN(*num == 0 || *num > HCCP_MAX_TPID_INFO_NUM,
     253              :         hccp_err("[get][ra_tp_info]*num(%u) is out of range[0, %d]", *num, HCCP_MAX_TPID_INFO_NUM),
     254              :         ConverReturnCode(RDMA_OP, -EINVAL));
     255              : 
     256            1 :     ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
     257            1 :     ret = RaHdcGetTpInfoListAsync(ctxHandleTmp, cfg, infoList, num, reqHandle);
     258            1 :     CHK_PRT_RETURN(ret != 0, hccp_err("[get][ra_tp_info]get_tp_info_list_async failed, ret[%d] phyId[%u], devIndex"
     259              :         "[%u]", ret, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex), ConverReturnCode(RDMA_OP, ret));
     260              : 
     261            1 :     return ConverReturnCode(RDMA_OP, ret);
     262              : }
     263              : 
     264            0 : HCCP_ATTRI_VISI_DEF int RaGetTpAttrAsync(void *ctxHandle, uint64_t tpHandle, uint32_t *attrBitmap,
     265              :     struct TpAttr *attr, void **reqHandle)
     266              : {
     267            0 :     struct RaCtxHandle *ctxHandleTmp = NULL;
     268              :     int ret;
     269              : 
     270            0 :     CHK_PRT_RETURN(ctxHandle == NULL || attrBitmap == NULL || reqHandle == NULL || attr == NULL,
     271              :         hccp_err("[get][ra_tp_attr]ctx_handle or attr_bitmap or req_handle or attr is NULL"),
     272              :         ConverReturnCode(RDMA_OP, -EINVAL));
     273              : 
     274            0 :     ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
     275            0 :     ret = RaHdcGetTpAttrAsync(ctxHandleTmp, tpHandle, attrBitmap, attr, reqHandle);
     276            0 :     CHK_PRT_RETURN(ret != 0, hccp_err("[get][ra_tp_attr]get_tp_attr_async failed, ret[%d] phyId[%u] devIndex[0x%x]",
     277              :         ret, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex), ConverReturnCode(RDMA_OP, ret));
     278              : 
     279            0 :     return ConverReturnCode(RDMA_OP, ret);
     280              : }
     281              : 
     282            0 : HCCP_ATTRI_VISI_DEF int RaSetTpAttrAsync(void *ctxHandle, uint64_t tpHandle, uint32_t attrBitmap,
     283              :     struct TpAttr *attr, void **reqHandle)
     284              : {
     285            0 :     struct RaCtxHandle *ctxHandleTmp = NULL;
     286              :     int ret;
     287              : 
     288            0 :     CHK_PRT_RETURN(ctxHandle == NULL || attr == NULL || reqHandle == NULL,
     289              :         hccp_err("[set][ra_tp_attr]ctx_handle or attr or req_handle or attr is NULL"),
     290              :         ConverReturnCode(RDMA_OP, -EINVAL));
     291              : 
     292            0 :     ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
     293            0 :     ret = RaHdcSetTpAttrAsync(ctxHandleTmp, tpHandle, attrBitmap, attr, reqHandle);
     294            0 :     CHK_PRT_RETURN(ret != 0, hccp_err("[set][ra_tp_attr]set_tp_attr_async failed, ret[%d] phyId[%u] devIndex[0x%x]",
     295              :         ret, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex), ConverReturnCode(RDMA_OP, ret));
     296              : 
     297            0 :     return ConverReturnCode(RDMA_OP, ret);
     298              : }
        

Generated by: LCOV version 2.0-1