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: 56.0 % 50 28
Test Date: 2026-08-18 17:47:01 Functions: 52.9 % 17 9

            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              :     .rsIbvModifyQpExtend = ibv_modify_qp_extend,
      30              :     .rsIbvQueryQpSupportedHyroceFeature = ibv_query_qp_supported_hyroce_feature,
      31              :     .rsIbvNegoQpHyroceFeature = ibv_nego_qp_hyroce_feature,
      32              : };
      33              : #endif
      34              : 
      35            0 : STATIC int RsIbvExtendIbvApiInit(void)
      36              : {
      37              : #ifndef CA_CONFIG_LLT
      38              :     gIbvExtendOps.rsIbvExtendGetVersion = (const char *(*)(uint32_t *, uint32_t *,
      39              :         uint32_t *))HccpDlsym(gRoceIbvExtendApiHandle, "ibv_extend_get_version");
      40              :     DL_API_RET_IS_NULL_CHECK(gIbvExtendOps.rsIbvExtendGetVersion, "ibv_extend_get_version");
      41              :     gIbvExtendOps.rsIbvExtendCheckVersion = (int (*)(uint32_t, uint32_t, uint32_t))HccpDlsym(gRoceIbvExtendApiHandle,
      42              :         "ibv_extend_check_version");
      43              :     DL_API_RET_IS_NULL_CHECK(gIbvExtendOps.rsIbvExtendCheckVersion, "ibv_extend_check_version");
      44              :     gIbvExtendOps.rsIbvOpenExtend = (struct ibv_context_extend * (*)(struct ibv_context *))
      45              :         HccpDlsym(gRoceIbvExtendApiHandle, "ibv_open_extend");
      46              :     DL_API_RET_IS_NULL_CHECK(gIbvExtendOps.rsIbvOpenExtend, "ibv_open_extend");
      47              :     gIbvExtendOps.rsIbvCloseExtend = (int (*)(struct ibv_context_extend *))HccpDlsym(gRoceIbvExtendApiHandle,
      48              :         "ibv_close_extend");
      49              :     DL_API_RET_IS_NULL_CHECK(gIbvExtendOps.rsIbvCloseExtend, "ibv_close_extend");
      50              :     gIbvExtendOps.rsIbvQueryDeviceExtend = (int (*)(struct ibv_context_extend *,
      51              :         struct ibv_device_attr_extend *))HccpDlsym(gRoceIbvExtendApiHandle, "ibv_query_device_extend");
      52              :     DL_API_RET_IS_NULL_CHECK(gIbvExtendOps.rsIbvQueryDeviceExtend, "ibv_query_device_extend");
      53              :     gIbvExtendOps.rsIbvCreateQpExtend = (struct ibv_qp_extend *
      54              :                                          (*)(struct ibv_context_extend *, struct ibv_qp_init_attr_extend *))
      55              :         HccpDlsym(gRoceIbvExtendApiHandle, "ibv_create_qp_extend");
      56              :     DL_API_RET_IS_NULL_CHECK(gIbvExtendOps.rsIbvCreateQpExtend, "ibv_create_qp_extend");
      57              :     gIbvExtendOps.rsIbvCreateCqExtend = (struct ibv_cq_extend *
      58              :                                          (*)(struct ibv_context_extend *, struct ibv_cq_init_attr_extend *))
      59              :         HccpDlsym(gRoceIbvExtendApiHandle, "ibv_create_cq_extend");
      60              :     DL_API_RET_IS_NULL_CHECK(gIbvExtendOps.rsIbvCreateCqExtend, "ibv_create_cq_extend");
      61              :     gIbvExtendOps.rsIbvDestroyQpExtend = (int (*)(struct ibv_context_extend *,
      62              :         struct ibv_qp_extend *))HccpDlsym(gRoceIbvExtendApiHandle, "ibv_destroy_qp_extend");
      63              :     DL_API_RET_IS_NULL_CHECK(gIbvExtendOps.rsIbvDestroyQpExtend, "ibv_destroy_qp_extend");
      64              :     gIbvExtendOps.rsIbvDestroyCqExtend = (int (*)(struct ibv_context_extend *,
      65              :         struct ibv_cq_extend *))HccpDlsym(gRoceIbvExtendApiHandle, "ibv_destroy_cq_extend");
      66              :     DL_API_RET_IS_NULL_CHECK(gIbvExtendOps.rsIbvDestroyCqExtend, "ibv_destroy_cq_extend");
      67              :     gIbvExtendOps.rsIbvModifyQpExtend = (int (*)(struct ibv_context_extend *, struct ibv_qp_attr_extend *,
      68              :         int))HccpDlsym(gRoceIbvExtendApiHandle, "ibv_modify_qp_extend");
      69              :     DL_API_RET_IS_NULL_INFO(gIbvExtendOps.rsIbvModifyQpExtend, "ibv_modify_qp_extend");
      70              :     gIbvExtendOps.rsIbvQueryQpSupportedHyroceFeature = (int (*)(struct ibv_context_extend *, struct ibv_qp *, uint32_t,
      71              :         uint32_t, struct ibv_hyroce_feature *))HccpDlsym(gRoceIbvExtendApiHandle,
      72              :         "ibv_query_qp_supported_hyroce_feature");
      73              :     DL_API_RET_IS_NULL_INFO(gIbvExtendOps.rsIbvQueryQpSupportedHyroceFeature, "ibv_query_qp_supported_hyroce_feature");
      74              :     gIbvExtendOps.rsIbvNegoQpHyroceFeature = (int (*)(struct ibv_context_extend *, struct ibv_qp *,
      75              :         const struct ibv_hyroce_feature *, struct ibv_hyroce_feature *, uint32_t *))HccpDlsym(gRoceIbvExtendApiHandle,
      76              :         "ibv_nego_qp_hyroce_feature");
      77              :     DL_API_RET_IS_NULL_INFO(gIbvExtendOps.rsIbvNegoQpHyroceFeature, "ibv_nego_qp_hyroce_feature");
      78              : #endif
      79            0 :     return 0;
      80              : }
      81              : 
      82            0 : STATIC int RsOpenIbvExtendSo(void)
      83              : {
      84              : #ifndef CA_CONFIG_LLT
      85              :     if (gRoceIbvExtendApiHandle == NULL) {
      86              :         gRoceIbvExtendApiHandle = HccpDlopen("libibv_extend.so", RTLD_NOW | RTLD_GLOBAL);
      87              :         if (gRoceIbvExtendApiHandle != NULL) {
      88              :             return 0;
      89              :         }
      90              :         return -EINVAL;
      91              :     } else {
      92              :         hccp_run_info("IbvExtendApi dlopen again!");
      93              :     }
      94              : #endif
      95            0 :     return 0;
      96              : }
      97              : 
      98           39 : STATIC void RsCloseIbvExtendSo(void)
      99              : {
     100              : #ifndef CA_CONFIG_LLT
     101              :     if (gRoceIbvExtendApiHandle != NULL) {
     102              :         (void)HccpDlclose(gRoceIbvExtendApiHandle);
     103              :         gRoceIbvExtendApiHandle = NULL;
     104              :     }
     105              : #endif
     106           39 :     return;
     107              : }
     108              : 
     109            0 : int RsIbvExtendApiInit(void)
     110              : {
     111              : #ifndef CA_CONFIG_LLT
     112              :     int ret = 0;
     113              : 
     114              :     ret = RsOpenIbvExtendSo();
     115              :     if (ret != 0) {
     116              :         hccp_warn("HccpDlopen[libibv_extend.so] doesn't exist!");
     117              :         return 0;
     118              :     }
     119              : 
     120              :     ret = RsIbvExtendIbvApiInit();
     121              :     if (ret != 0) {
     122              :         hccp_err("RsIbvExtendIbvApiInit failed! ret:%d", ret);
     123              :         RsCloseIbvExtendSo();
     124              :         return ret;
     125              :     }
     126              : #endif
     127            0 :     return 0;
     128              : }
     129              : 
     130           39 : void RsIbvExtendApiDeinit(void)
     131              : {
     132           39 :     RsCloseIbvExtendSo();
     133           39 :     return;
     134              : }
     135              : 
     136            0 : const char *RsIbvExtendGetVersion(uint32_t *major, uint32_t *minor, uint32_t *patch)
     137              : {
     138            0 :     if (gIbvExtendOps.rsIbvExtendGetVersion == NULL) {
     139              : #ifndef CA_CONFIG_LLT
     140              :         return NULL;
     141              : #endif
     142              :     }
     143            0 :     return gIbvExtendOps.rsIbvExtendGetVersion(major, minor, patch);
     144              : }
     145              : 
     146            0 : int RsIbvExtendCheckVersion(uint32_t driverMajor, uint32_t driverMinor, uint32_t driverPatch)
     147              : {
     148            0 :     if (gIbvExtendOps.rsIbvExtendCheckVersion == NULL) {
     149              : #ifndef CA_CONFIG_LLT
     150              :         return -EINVAL;
     151              : #endif
     152              :     }
     153            0 :     return gIbvExtendOps.rsIbvExtendCheckVersion(driverMajor, driverMinor, driverPatch);
     154              : }
     155              : 
     156           32 : struct ibv_context_extend *RsIbvOpenExtend(struct ibv_context *context)
     157              : {
     158           32 :     if (gIbvExtendOps.rsIbvOpenExtend == NULL) {
     159              : #ifndef CA_CONFIG_LLT
     160              :         return NULL;
     161              : #endif
     162              :     }
     163           32 :     return gIbvExtendOps.rsIbvOpenExtend(context);
     164              : }
     165              : 
     166           31 : int RsIbvCloseExtend(struct ibv_context_extend *context)
     167              : {
     168           31 :     if (context == NULL) {
     169            0 :         return 0;
     170              :     }
     171              : 
     172           31 :     if (gIbvExtendOps.rsIbvCloseExtend == NULL) {
     173              : #ifndef CA_CONFIG_LLT
     174              :         return 0;
     175              : #endif
     176              :     }
     177           31 :     return gIbvExtendOps.rsIbvCloseExtend(context);
     178              : }
     179              : 
     180            0 : int RsIbvQueryDeviceExtend(struct ibv_context_extend *context, struct ibv_device_attr_extend *extDevAttr)
     181              : {
     182            0 :     if (gIbvExtendOps.rsIbvQueryDeviceExtend == NULL) {
     183              : #ifndef CA_CONFIG_LLT
     184              :         hccp_err("rsIbvQueryDeviceExtend is null");
     185              :         return -EINVAL;
     186              : #endif
     187              :     }
     188            0 :     return gIbvExtendOps.rsIbvQueryDeviceExtend(context, extDevAttr);
     189              : }
     190              : 
     191            1 : struct ibv_cq_extend *RsIbvCreateCqExtend(struct ibv_context_extend *context,
     192              :     struct ibv_cq_init_attr_extend *cqInitAttr)
     193              : {
     194            1 :     if (gIbvExtendOps.rsIbvCreateCqExtend == NULL) {
     195              : #ifndef CA_CONFIG_LLT
     196              :         hccp_err("rsIbvCreateCqExtend is null");
     197              :         return NULL;
     198              : #endif
     199              :     }
     200            1 :     return gIbvExtendOps.rsIbvCreateCqExtend(context, cqInitAttr);
     201              : }
     202              : 
     203            1 : int RsIbvDestroyCqExtend(struct ibv_context_extend *context, void *ibvCqExt)
     204              : {
     205            1 :     struct ibv_cq_extend *cqExtend = (struct ibv_cq_extend *)ibvCqExt;
     206              : 
     207            1 :     if (gIbvExtendOps.rsIbvDestroyCqExtend == NULL) {
     208              : #ifndef CA_CONFIG_LLT
     209              :         hccp_err("rsIbvDestroyCqExtend is null");
     210              :         return -EINVAL;
     211              : #endif
     212              :     }
     213            1 :     return gIbvExtendOps.rsIbvDestroyCqExtend(context, cqExtend);
     214              : }
     215              : 
     216            3 : struct ibv_qp_extend *RsIbvCreateQpExtend(struct ibv_context_extend *context,
     217              :     struct ibv_qp_init_attr_extend *qpInitAttr)
     218              : {
     219            3 :     if (gIbvExtendOps.rsIbvCreateQpExtend == NULL) {
     220              : #ifndef CA_CONFIG_LLT
     221              :         hccp_err("rsIbvCreateQpExtend is null");
     222              :         return NULL;
     223              : #endif
     224              :     }
     225            3 :     return gIbvExtendOps.rsIbvCreateQpExtend(context, qpInitAttr);
     226              : }
     227              : 
     228            3 : int RsIbvDestroyQpExtend(struct ibv_context_extend *context, struct ibv_qp_extend *qpExtend)
     229              : {
     230            3 :     if (gIbvExtendOps.rsIbvDestroyQpExtend == NULL) {
     231              : #ifndef CA_CONFIG_LLT
     232              :         hccp_err("rsIbvDestroyQpExtend is null");
     233              :         return -EINVAL;
     234              : #endif
     235              :     }
     236            3 :     return gIbvExtendOps.rsIbvDestroyQpExtend(context, qpExtend);
     237              : }
     238              : 
     239            0 : int RsIbvModifyQpExtend(struct ibv_context_extend *context, struct ibv_qp_attr_extend *attr, int attr_mask)
     240              : {
     241            0 :     if (gIbvExtendOps.rsIbvModifyQpExtend == NULL) {
     242              : #ifndef CA_CONFIG_LLT
     243              :         hccp_warn("rsIbvModifyQpExtend is null");
     244              :         return -EINVAL;
     245              : #endif
     246              :     }
     247            0 :     return gIbvExtendOps.rsIbvModifyQpExtend(context, attr, attr_mask);
     248              : }
     249              : 
     250            3 : int RsIbvQueryQpSupportedHyroceFeature(struct ibv_context_extend *context, struct ibv_qp *qp, uint32_t sl, uint32_t tc,
     251              :     struct ibv_hyroce_feature *feature)
     252              : {
     253            3 :     if (gIbvExtendOps.rsIbvQueryQpSupportedHyroceFeature == NULL) {
     254              : #ifndef CA_CONFIG_LLT
     255              :         hccp_warn("rsIbvQueryQpSupportedHyroceFeature is null");
     256              :         return -EINVAL;
     257              : #endif
     258              :     }
     259            3 :     return gIbvExtendOps.rsIbvQueryQpSupportedHyroceFeature(context, qp, sl, tc, feature);
     260              : }
     261              : 
     262            0 : int RsIbvNegoQpHyroceFeature(struct ibv_context_extend *context, struct ibv_qp *qp,
     263              :     const struct ibv_hyroce_feature *input, struct ibv_hyroce_feature *output, uint32_t *needMoreNego)
     264              : {
     265            0 :     if (gIbvExtendOps.rsIbvNegoQpHyroceFeature == NULL) {
     266              : #ifndef CA_CONFIG_LLT
     267              :         hccp_warn("rsIbvNegoQpHyroceFeature is null");
     268              :         return -EINVAL;
     269              : #endif
     270              :     }
     271            0 :     return gIbvExtendOps.rsIbvNegoQpHyroceFeature(context, qp, input, output, needMoreNego);
     272              : }
        

Generated by: LCOV version 2.0-1