LCOV - code coverage report
Current view: top level - base_comm/resources/hccp/rdma_service - dl_ibv_extend_function.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 61.0 % 41 25
Test Date: 2026-08-04 10:52:23 Functions: 57.1 % 14 8

            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 <pthread.h>
      12              : #include "hccp_dl.h"
      13              : #include "dl_ibv_extend_function.h"
      14              : 
      15              : void *gRoceIbvExtendApiHandle = NULL;
      16              : #ifndef CA_CONFIG_LLT
      17              : STATIC struct RsIbvExtendOps gIbvExtendOps = {0};
      18              : #else
      19              : struct RsIbvExtendOps gIbvExtendOps = {
      20              :     .rsIbvExtendGetVersion = ibv_extend_get_version,
      21              :     .rsIbvExtendCheckVersion = ibv_extend_check_version,
      22              :     .rsIbvOpenExtend = ibv_open_extend,
      23              :     .rsIbvCloseExtend = ibv_close_extend,
      24              :     .rsIbvQueryDeviceExtend = ibv_query_device_extend,
      25              :     .rsIbvCreateQpExtend = ibv_create_qp_extend,
      26              :     .rsIbvCreateCqExtend = ibv_create_cq_extend,
      27              :     .rsIbvDestroyQpExtend = ibv_destroy_qp_extend,
      28              :     .rsIbvDestroyCqExtend = ibv_destroy_cq_extend,
      29              : };
      30              : #endif
      31              : 
      32            0 : STATIC int RsIbvExtendIbvApiInit(void)
      33              : {
      34              : #ifndef CA_CONFIG_LLT
      35              :     gIbvExtendOps.rsIbvExtendGetVersion = (const char* (*)(uint32_t *, uint32_t *, uint32_t *))
      36              :         HccpDlsym(gRoceIbvExtendApiHandle, "ibv_extend_get_version");
      37              :     DL_API_RET_IS_NULL_CHECK(gIbvExtendOps.rsIbvExtendGetVersion, "ibv_extend_get_version");
      38              :     gIbvExtendOps.rsIbvExtendCheckVersion = (int (*)(uint32_t, uint32_t, uint32_t))
      39              :         HccpDlsym(gRoceIbvExtendApiHandle, "ibv_extend_check_version");
      40              :     DL_API_RET_IS_NULL_CHECK(gIbvExtendOps.rsIbvExtendCheckVersion, "ibv_extend_check_version");
      41              :     gIbvExtendOps.rsIbvOpenExtend = (struct ibv_context_extend* (*)(struct ibv_context *))
      42              :         HccpDlsym(gRoceIbvExtendApiHandle, "ibv_open_extend");
      43              :     DL_API_RET_IS_NULL_CHECK(gIbvExtendOps.rsIbvOpenExtend, "ibv_open_extend");
      44              :     gIbvExtendOps.rsIbvCloseExtend = (int (*)(struct ibv_context_extend *))
      45              :         HccpDlsym(gRoceIbvExtendApiHandle, "ibv_close_extend");
      46              :     DL_API_RET_IS_NULL_CHECK(gIbvExtendOps.rsIbvCloseExtend, "ibv_close_extend");
      47              :     gIbvExtendOps.rsIbvQueryDeviceExtend = (int (*)(struct ibv_context_extend *, struct ibv_device_attr_extend *))
      48              :         HccpDlsym(gRoceIbvExtendApiHandle, "ibv_query_device_extend");
      49              :     DL_API_RET_IS_NULL_CHECK(gIbvExtendOps.rsIbvQueryDeviceExtend, "ibv_query_device_extend");
      50              :     gIbvExtendOps.rsIbvCreateQpExtend = (struct ibv_qp_extend* (*)(struct ibv_context_extend *,
      51              :         struct ibv_qp_init_attr_extend *)) HccpDlsym(gRoceIbvExtendApiHandle, "ibv_create_qp_extend");
      52              :     DL_API_RET_IS_NULL_CHECK(gIbvExtendOps.rsIbvCreateQpExtend, "ibv_create_qp_extend");
      53              :     gIbvExtendOps.rsIbvCreateCqExtend = (struct ibv_cq_extend* (*)(struct ibv_context_extend *,
      54              :         struct ibv_cq_init_attr_extend *)) HccpDlsym(gRoceIbvExtendApiHandle, "ibv_create_cq_extend");
      55              :     DL_API_RET_IS_NULL_CHECK(gIbvExtendOps.rsIbvCreateCqExtend, "ibv_create_cq_extend");
      56              :     gIbvExtendOps.rsIbvDestroyQpExtend = (int (*)(struct ibv_context_extend *,
      57              :         struct ibv_qp_extend *)) HccpDlsym(gRoceIbvExtendApiHandle, "ibv_destroy_qp_extend");
      58              :     DL_API_RET_IS_NULL_CHECK(gIbvExtendOps.rsIbvDestroyQpExtend, "ibv_destroy_qp_extend");
      59              :     gIbvExtendOps.rsIbvDestroyCqExtend = (int (*)(struct ibv_context_extend *,
      60              :         struct ibv_cq_extend *)) HccpDlsym(gRoceIbvExtendApiHandle, "ibv_destroy_cq_extend");
      61              :     DL_API_RET_IS_NULL_CHECK(gIbvExtendOps.rsIbvDestroyCqExtend, "ibv_destroy_cq_extend");
      62              : #endif
      63            0 :     return 0;
      64              : }
      65              : 
      66            0 : STATIC int RsOpenIbvExtendSo(void)
      67              : {
      68              : #ifndef CA_CONFIG_LLT
      69              :     if (gRoceIbvExtendApiHandle == NULL) {
      70              :         gRoceIbvExtendApiHandle = HccpDlopen("libibv_extend.so", RTLD_NOW | RTLD_GLOBAL);
      71              :         if (gRoceIbvExtendApiHandle != NULL) {
      72              :             return 0;
      73              :         }
      74              :         return -EINVAL;
      75              :     } else {
      76              :         hccp_run_info("IbvExtendApi dlopen again!");
      77              :     }
      78              : #endif
      79            0 :     return 0;
      80              : }
      81              : 
      82           38 : STATIC void RsCloseIbvExtendSo(void)
      83              : {
      84              : #ifndef CA_CONFIG_LLT
      85              :     if (gRoceIbvExtendApiHandle != NULL) {
      86              :         (void)HccpDlclose(gRoceIbvExtendApiHandle);
      87              :         gRoceIbvExtendApiHandle = NULL;
      88              :     }
      89              : #endif
      90           38 :     return;
      91              : }
      92              : 
      93            0 : int RsIbvExtendApiInit(void)
      94              : {
      95              : #ifndef CA_CONFIG_LLT
      96              :     int ret = 0;
      97              : 
      98              :     ret = RsOpenIbvExtendSo();
      99              :     if (ret != 0) {
     100              :         hccp_warn("HccpDlopen[libibv_extend.so] doesn't exist!");
     101              :         return 0;
     102              :     }
     103              : 
     104              :     ret = RsIbvExtendIbvApiInit();
     105              :     if (ret != 0) {
     106              :         hccp_err("RsIbvExtendIbvApiInit failed! ret:%d", ret);
     107              :         RsCloseIbvExtendSo();
     108              :         return ret;
     109              :     }
     110              : #endif
     111            0 :     return 0;
     112              : }
     113              : 
     114           38 : void RsIbvExtendApiDeinit(void)
     115              : {
     116           38 :     RsCloseIbvExtendSo();
     117           38 :     return;
     118              : }
     119              : 
     120            0 : const char *RsIbvExtendGetVersion(uint32_t *major, uint32_t *minor, uint32_t *patch)
     121              : {
     122            0 :     if (gIbvExtendOps.rsIbvExtendGetVersion == NULL) {
     123              : #ifndef CA_CONFIG_LLT
     124              :         return NULL;
     125              : #endif
     126              :     }
     127            0 :     return gIbvExtendOps.rsIbvExtendGetVersion(major, minor, patch);
     128              : }
     129              : 
     130            0 : int RsIbvExtendCheckVersion(uint32_t driverMajor, uint32_t driverMinor, uint32_t driverPatch)
     131              : {
     132            0 :     if (gIbvExtendOps.rsIbvExtendCheckVersion == NULL) {
     133              : #ifndef CA_CONFIG_LLT
     134              :         return -EINVAL;
     135              : #endif
     136              :     }
     137            0 :     return gIbvExtendOps.rsIbvExtendCheckVersion(driverMajor, driverMinor, driverPatch);
     138              : }
     139              : 
     140           31 : struct ibv_context_extend *RsIbvOpenExtend(struct ibv_context *context)
     141              : {
     142           31 :     if (gIbvExtendOps.rsIbvOpenExtend == NULL) {
     143              : #ifndef CA_CONFIG_LLT
     144              :         return NULL;
     145              : #endif
     146              :     }
     147           31 :     return gIbvExtendOps.rsIbvOpenExtend(context);
     148              : }
     149              : 
     150           31 : int RsIbvCloseExtend(struct ibv_context_extend *context)
     151              : {
     152           31 :     if (context == NULL) {
     153            0 :         return 0;
     154              :     }
     155              : 
     156           31 :     if (gIbvExtendOps.rsIbvCloseExtend == NULL) {
     157              : #ifndef CA_CONFIG_LLT
     158              :         return 0;
     159              : #endif
     160              :     }
     161           31 :     return gIbvExtendOps.rsIbvCloseExtend(context);
     162              : }
     163              : 
     164            0 : int RsIbvQueryDeviceExtend(struct ibv_context_extend *context, struct ibv_device_attr_extend *extDevAttr)
     165              : {
     166            0 :     if (gIbvExtendOps.rsIbvQueryDeviceExtend == NULL) {
     167              : #ifndef CA_CONFIG_LLT
     168              :         hccp_err("rsIbvQueryDeviceExtend is null");
     169              :         return -EINVAL;
     170              : #endif
     171              :     }
     172            0 :     return gIbvExtendOps.rsIbvQueryDeviceExtend(context, extDevAttr);
     173              : }
     174              : 
     175            1 : struct ibv_cq_extend *RsIbvCreateCqExtend(struct ibv_context_extend *context,
     176              :     struct ibv_cq_init_attr_extend *cqInitAttr)
     177              : {
     178            1 :     if (gIbvExtendOps.rsIbvCreateCqExtend == NULL) {
     179              : #ifndef CA_CONFIG_LLT
     180              :         hccp_err("rsIbvCreateCqExtend is null");
     181              :         return NULL;
     182              : #endif
     183              :     }
     184            1 :     return gIbvExtendOps.rsIbvCreateCqExtend(context, cqInitAttr);
     185              : }
     186              : 
     187            1 : int RsIbvDestroyCqExtend(struct ibv_context_extend *context, void *ibvCqExt)
     188              : {
     189            1 :     struct ibv_cq_extend *cqExtend = (struct ibv_cq_extend *)ibvCqExt;
     190              : 
     191            1 :     if (gIbvExtendOps.rsIbvDestroyCqExtend == NULL) {
     192              : #ifndef CA_CONFIG_LLT
     193              :         hccp_err("rsIbvDestroyCqExtend is null");
     194              :         return -EINVAL;
     195              : #endif
     196              :     }
     197            1 :     return gIbvExtendOps.rsIbvDestroyCqExtend(context, cqExtend);
     198              : }
     199              : 
     200            3 : struct ibv_qp_extend *RsIbvCreateQpExtend(struct ibv_context_extend *context,
     201              :     struct ibv_qp_init_attr_extend *qpInitAttr)
     202              : {
     203            3 :     if (gIbvExtendOps.rsIbvCreateQpExtend == NULL) {
     204              : #ifndef CA_CONFIG_LLT
     205              :         hccp_err("rsIbvCreateQpExtend is null");
     206              :         return NULL;
     207              : #endif
     208              :     }
     209            3 :     return gIbvExtendOps.rsIbvCreateQpExtend(context, qpInitAttr);
     210              : }
     211              : 
     212            3 : int RsIbvDestroyQpExtend(struct ibv_context_extend *context, struct ibv_qp_extend *qpExtend)
     213              : {
     214            3 :     if (gIbvExtendOps.rsIbvDestroyQpExtend == NULL) {
     215              : #ifndef CA_CONFIG_LLT
     216              :         hccp_err("rsIbvDestroyQpExtend is null");
     217              :         return -EINVAL;
     218              : #endif
     219              :     }
     220            3 :     return gIbvExtendOps.rsIbvDestroyQpExtend(context, qpExtend);
     221              : }
        

Generated by: LCOV version 2.0-1