LCOV - code coverage report
Current view: top level - base_comm/resources/hccp/rdma_service - dl_ibverbs_function.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 75.9 % 224 170
Test Date: 2026-08-04 10:52:23 Functions: 74.0 % 73 54

            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 <pthread.h>
      12              : #include "ra_rs_err.h"
      13              : #include "dl_ibv_extend_function.h"
      14              : #include "dl_ibverbs_function.h"
      15              : 
      16              : static pthread_mutex_t gRoceUserApiLock = PTHREAD_MUTEX_INITIALIZER;
      17              : static int gRoceUserApiRefcnt = 0;
      18              : void *gIbverbsApiHandle = NULL;
      19              : void *gRoceUserApiHandle = NULL;
      20              : void *gHrnApiHandle = NULL;
      21              : #ifndef CA_CONFIG_LLT
      22              : struct RsIbverbsOps gIbverbsOps;
      23              : struct RsRoceUserOps gRoceUserOps;
      24              : struct RsHrnOps gHrnOps;
      25              : #else
      26              : struct RsIbverbsOps gIbverbsOps = {
      27              :     .rsIbvFreeDeviceList = ibv_free_device_list,
      28              :     .rsIbvAckCqEvents = ibv_ack_cq_events,
      29              :     .rsIbvGetDeviceName = ibv_get_device_name,
      30              :     .rsIbvWcStatusStr = ibv_wc_status_str,
      31              :     .rsIbvQueryGidType = ibv_query_gid_type,
      32              :     .rsIbvDeregMr = ibv_dereg_mr,
      33              :     .rsIbvQueryQp = ibv_query_qp,
      34              :     .rsIbvDestroyQp = ibv_destroy_qp,
      35              :     .rsIbvGetCqEvent = ibv_get_cq_event,
      36              :     .rsIbvDestroyCq = ibv_destroy_cq,
      37              :     .rsIbvModifyQp = ibv_modify_qp,
      38              :     .rsIbvQueryDevice = ibv_query_device,
      39              :     .rsIbvQueryPort = ibv_query_port,
      40              :     .rsIbvQueryGid = ibv_query_gid,
      41              :     .rsIbvCloseDevice = ibv_close_device,
      42              :     .rsIbvDeallocPd = ibv_dealloc_pd,
      43              :     .rsIbvDestroyCompChannel = ibv_destroy_comp_channel,
      44              :     .rsIbvOpenDevice = ibv_open_device,
      45              :     .rsIbvAllocPd = ibv_alloc_pd,
      46              :     .rsIbvGetDeviceList = ibv_get_device_list,
      47              :     .rsIbvCreateCq = ibv_create_cq,
      48              :     .rsIbvRegMr = ibv_reg_mr,
      49              :     .rsIbvCreateQp = ibv_create_qp,
      50              :     .rsIbvCreateCompChannel = ibv_create_comp_channel,
      51              :     .rsIbvCreateSrq = ibv_create_srq,
      52              :     .rsIbvDestroySrq = ibv_destroy_srq,
      53              :     .rsIbvCreateAh = ibv_create_ah,
      54              :     .rsIbvDestroyAh = ibv_destroy_ah,
      55              : };
      56              : 
      57              : struct RsRoceUserOps gRoceUserOps = {
      58              :     .rsRoceSetTsqpDepth = roce_set_tsqp_depth,
      59              :     .rsRoceGetTsqpDepth = roce_get_tsqp_depth,
      60              :     .rsRoceGetRoceDevData = roce_get_roce_dev_data,
      61              :     .rsIbvExpQueryNotify = ibv_exp_query_notify,
      62              :     .rsIbvExpPostSend = ibv_exp_post_send,
      63              :     .rsIbvExpRegMr = ibv_exp_reg_mr,
      64              :     .rsIbvExpCreateQp = ibv_exp_create_qp,
      65              :     .rsIbvExtPostSend = ibv_ext_post_send,
      66              :     .rsIbvExpCreateCq = ibv_exp_create_cq,
      67              :     .rsIbvExpQueryDevice = ibv_exp_query_device,
      68              :     .rsRoceInitMemPool = roce_init_mem_pool,
      69              :     .rsRoceDeinitMemPool = roce_deinit_mem_pool,
      70              :     .rsRoceQueryQpc = roce_query_qpc,
      71              :     .rsIbvExpCreateAh = ibv_exp_create_ah,
      72              :     .rsRoceMmapAiDbReg = roce_mmap_ai_db_reg,
      73              :     .rsRoceUnmmapAiDbReg = roce_unmmap_ai_db_reg,
      74              :     .rsRoceGetCqDataPlaneInfo = roce_get_cq_data_plane_info,
      75              :     .rsRoceGetQpDataPlaneInfo = roce_get_qp_data_plane_info,
      76              :     .rsRoceRemapMr = roce_remap_mr,
      77              :     .rsRoceGetApiVersion = roce_get_api_version,
      78              : };
      79              : 
      80              : struct RsHrnOps gHrnOps = {
      81              :     .rsRoceSetQpLbValue = roce_set_qp_lb_value,
      82              :     .rsRoceGetQpLbValue = roce_get_qp_lb_value,
      83              :     .rsRoceGetQpNum = roce_get_qp_num,
      84              : };
      85              : #endif
      86              : 
      87            0 : STATIC int RsContextOpsApiInit(void)
      88              : {
      89              : #ifndef CA_CONFIG_LLT
      90              :     gIbverbsOps.rsIbvQueryDevice = (int (*)(struct ibv_context*, struct ibv_device_attr *))
      91              :         HccpDlsym(gIbverbsApiHandle, "ibv_query_device");
      92              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvQueryDevice, "ibv_query_device");
      93              : 
      94              :     gIbverbsOps.rsIbvQueryPort = (int (*)(struct ibv_context*, uint8_t, struct ibv_port_attr*))
      95              :         HccpDlsym(gIbverbsApiHandle, "ibv_query_port");
      96              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvQueryPort, "ibv_query_port");
      97              : 
      98              :     gIbverbsOps.rsIbvQueryGid = (int (*)(struct ibv_context*, uint8_t, int, union ibv_gid*))
      99              :         HccpDlsym(gIbverbsApiHandle, "ibv_query_gid");
     100              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvQueryGid, "ibv_query_gid");
     101              : 
     102              :     gIbverbsOps.rsIbvAllocPd = (struct ibv_pd* (*)(struct ibv_context*))
     103              :         HccpDlsym(gIbverbsApiHandle, "ibv_alloc_pd");
     104              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvAllocPd, "ibv_alloc_pd");
     105              : 
     106              :     gIbverbsOps.rsIbvDeallocPd = (int (*)(struct ibv_pd*))
     107              :         HccpDlsym(gIbverbsApiHandle, "ibv_dealloc_pd");
     108              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvDeallocPd, "ibv_dealloc_pd");
     109              : 
     110              :     gIbverbsOps.rsIbvCreateCq = (struct ibv_cq* (*)(struct ibv_context*, int, void*,
     111              :         struct ibv_comp_channel*, int))
     112              :         HccpDlsym(gIbverbsApiHandle, "ibv_create_cq");
     113              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvCreateCq, "ibv_create_cq");
     114              : 
     115              :     gIbverbsOps.rsIbvDestroyCq = (int (*)(struct ibv_cq*))
     116              :         HccpDlsym(gIbverbsApiHandle, "ibv_destroy_cq");
     117              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvDestroyCq, "ibv_destroy_cq");
     118              : 
     119              :     gIbverbsOps.rsIbvCreateCompChannel = (struct ibv_comp_channel* (*)(struct ibv_context *))
     120              :         HccpDlsym(gIbverbsApiHandle, "ibv_create_comp_channel");
     121              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvCreateCompChannel, "ibv_create_comp_channel");
     122              : 
     123              :     gIbverbsOps.rsIbvDestroyCompChannel = (int (*)(struct ibv_comp_channel *))
     124              :         HccpDlsym(gIbverbsApiHandle, "ibv_destroy_comp_channel");
     125              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvDestroyCompChannel, "ibv_destroy_comp_channel");
     126              : 
     127              :     gIbverbsOps.rsIbvCreateSrq = (struct ibv_srq* (*)(struct ibv_pd *pd, struct ibv_srq_init_attr *srqInitAttr))
     128              :         HccpDlsym(gIbverbsApiHandle, "ibv_create_srq");
     129              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvCreateSrq, "ibv_create_srq");
     130              : 
     131              :     gIbverbsOps.rsIbvDestroySrq = (int (*)(struct ibv_srq*))
     132              :         HccpDlsym(gIbverbsApiHandle, "ibv_destroy_srq");
     133              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvDestroySrq, "ibv_destroy_srq");
     134              : 
     135              :     gIbverbsOps.rsIbvQueryGidType = (int (*)(struct ibv_context*, uint8_t, unsigned int,
     136              :         enum ibv_gid_type_sysfs*))
     137              :         HccpDlsym(gIbverbsApiHandle, "ibv_query_gid_type");
     138              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvQueryGidType, "ibv_query_gid_type");
     139              : 
     140              :     gIbverbsOps.rsIbvCreateAh = (struct ibv_ah* (*)(struct ibv_pd *, struct ibv_ah_attr *))
     141              :         HccpDlsym(gIbverbsApiHandle, "ibv_create_ah");
     142              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvCreateAh, "ibv_create_ah");
     143              : 
     144              :     gIbverbsOps.rsIbvDestroyAh = (int (*)(struct ibv_ah *))
     145              :         HccpDlsym(gIbverbsApiHandle, "ibv_destroy_ah");
     146              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvDestroyAh, "ibv_destroy_ah");
     147              : #endif
     148            0 :     return 0;
     149              : }
     150              : 
     151            0 : STATIC int RsQpOpsApiInit(void)
     152              : {
     153              : #ifndef CA_CONFIG_LLT
     154              :     gIbverbsOps.rsIbvQueryQp = (int (*)(struct ibv_qp*, struct ibv_qp_attr*, int, struct ibv_qp_init_attr*))
     155              :         HccpDlsym(gIbverbsApiHandle, "ibv_query_qp");
     156              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvQueryQp, "ibv_query_qp");
     157              : 
     158              :     gIbverbsOps.rsIbvGetCqEvent = (int (*)(struct ibv_comp_channel*, struct ibv_cq**, void**))
     159              :         HccpDlsym(gIbverbsApiHandle, "ibv_get_cq_event");
     160              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvGetCqEvent, "ibv_get_cq_event");
     161              : 
     162              :     gIbverbsOps.rsIbvAckCqEvents = (void (*)(struct ibv_cq*, unsigned int))
     163              :         HccpDlsym(gIbverbsApiHandle, "ibv_ack_cq_events");
     164              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvAckCqEvents, "ibv_ack_cq_events");
     165              : 
     166              :     gIbverbsOps.rsIbvModifyQp = (int (*)(struct ibv_qp*, struct ibv_qp_attr*, int))
     167              :         HccpDlsym(gIbverbsApiHandle, "ibv_modify_qp");
     168              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvModifyQp, "ibv_modify_qp");
     169              : #endif
     170            0 :     return 0;
     171              : }
     172              : 
     173            0 : STATIC int RsPdOpsApiInit(void)
     174              : {
     175              : #ifndef CA_CONFIG_LLT
     176              :     gIbverbsOps.rsIbvRegMr = (struct ibv_mr* (*)(struct ibv_pd*, void*, size_t, int))
     177              :         HccpDlsym(gIbverbsApiHandle, "ibv_reg_mr");
     178              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvRegMr, "ibv_reg_mr");
     179              : 
     180              :     gIbverbsOps.rsIbvDeregMr = (int (*)(struct ibv_mr*))
     181              :         HccpDlsym(gIbverbsApiHandle, "ibv_dereg_mr");
     182              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvDeregMr, "ibv_dereg_mr");
     183              : 
     184              :     gIbverbsOps.rsIbvCreateQp = (struct ibv_qp* (*)(struct ibv_pd*, struct ibv_qp_init_attr*))
     185              :         HccpDlsym(gIbverbsApiHandle, "ibv_create_qp");
     186              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvCreateQp, "ibv_create_qp");
     187              : 
     188              :     gIbverbsOps.rsIbvDestroyQp = (int (*)(struct ibv_qp*))
     189              :         HccpDlsym(gIbverbsApiHandle, "ibv_destroy_qp");
     190              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvDestroyQp, "ibv_destroy_qp");
     191              : #endif
     192            0 :     return 0;
     193              : }
     194              : 
     195            0 : STATIC int RsDeviceOpsApiInit(void)
     196              : {
     197              : #ifndef CA_CONFIG_LLT
     198              :     gIbverbsOps.rsIbvGetDeviceList = (struct ibv_device** (*)(int *))
     199              :         HccpDlsym(gIbverbsApiHandle, "ibv_get_device_list");
     200              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvGetDeviceList, "ibv_get_device_list");
     201              : 
     202              :     gIbverbsOps.rsIbvFreeDeviceList = (void (*)(struct ibv_device**))
     203              :         HccpDlsym(gIbverbsApiHandle, "ibv_free_device_list");
     204              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvFreeDeviceList, "ibv_free_device_list");
     205              : 
     206              :     gIbverbsOps.rsIbvGetDeviceName = (const char* (*)(struct ibv_device*))
     207              :         HccpDlsym(gIbverbsApiHandle, "ibv_get_device_name");
     208              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvGetDeviceName, "ibv_get_device_name");
     209              : 
     210              :     gIbverbsOps.rsIbvCloseDevice = (int (*)(struct ibv_context*))
     211              :         HccpDlsym(gIbverbsApiHandle, "ibv_close_device");
     212              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvCloseDevice, "ibv_close_device");
     213              : 
     214              :     gIbverbsOps.rsIbvOpenDevice = (struct ibv_context* (*)(struct ibv_device*))
     215              :         HccpDlsym(gIbverbsApiHandle, "ibv_open_device");
     216              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvOpenDevice, "ibv_open_device");
     217              : 
     218              :     gIbverbsOps.rsIbvWcStatusStr = (const char* (*)(enum ibv_wc_status))
     219              :         HccpDlsym(gIbverbsApiHandle, "ibv_wc_status_str");
     220              :     DL_API_RET_IS_NULL_CHECK(gIbverbsOps.rsIbvWcStatusStr, "ibv_wc_status_str");
     221              : #endif
     222            0 :     return 0;
     223              : }
     224              : 
     225            0 : STATIC int RsOpenIbverbsSo(void)
     226              : {
     227              : #ifndef CA_CONFIG_LLT
     228              :     if (gIbverbsApiHandle == NULL) {
     229              :         gIbverbsApiHandle = HccpDlopen("libibverbs.so", RTLD_NOW);
     230              :         if (gIbverbsApiHandle != NULL) {
     231              :             return 0;
     232              :         }
     233              : 
     234              :         gIbverbsApiHandle = HccpDlopen("libibverbs.so.1", RTLD_NOW);
     235              :         if (gIbverbsApiHandle != 0) {
     236              :             return 0;
     237              :         }
     238              :         return -EINVAL;
     239              :     } else {
     240              :             hccp_run_info("ibverbs_api dlopen again!");
     241              :         }
     242              : #endif
     243            0 :     return 0;
     244              : }
     245              : 
     246           38 : STATIC void RsCloseIbverbsSo(void)
     247              : {
     248           38 :     if (gIbverbsApiHandle != NULL) {
     249            0 :         (void)HccpDlclose(gIbverbsApiHandle);
     250            0 :         gIbverbsApiHandle = NULL;
     251              :     }
     252           38 :     return;
     253              : }
     254              : 
     255            0 : STATIC int RsIbverbsApiInit(void)
     256              : {
     257              : #ifndef CA_CONFIG_LLT
     258              :     int ret;
     259              : 
     260              :     ret = RsOpenIbverbsSo();
     261              :     CHK_PRT_RETURN(ret, hccp_err("HccpDlopen[libibverbs.so or libibverbs.so.1] failed! ret=[%d],"\
     262              :     "Please check network adapter driver has been installed", ret), ret);
     263              : 
     264              :     ret = RsContextOpsApiInit();
     265              :     if (ret) {
     266              :         hccp_err("[rs_context_ops_api_init]HccpDlopen failed! ret=[%d]", ret);
     267              :         RsCloseIbverbsSo();
     268              :         return ret;
     269              :     }
     270              : 
     271              :     ret = RsQpOpsApiInit();
     272              :     if (ret) {
     273              :         hccp_err("[rs_qp_ops_api_init]HccpDlopen failed! ret=[%d]", ret);
     274              :         RsCloseIbverbsSo();
     275              :         return ret;
     276              :     }
     277              : 
     278              :     ret = RsPdOpsApiInit();
     279              :     if (ret) {
     280              :         hccp_err("[rs_pd_ops_api_init]HccpDlopen failed! ret=[%d]", ret);
     281              :         RsCloseIbverbsSo();
     282              :         return ret;
     283              :     }
     284              : 
     285              :     ret = RsDeviceOpsApiInit();
     286              :     if (ret) {
     287              :         hccp_err("[rs_device_ops_api_init]HccpDlopen failed! ret=[%d]", ret);
     288              :         RsCloseIbverbsSo();
     289              :         return ret;
     290              :     }
     291              : #endif
     292            0 :     return 0;
     293              : }
     294              : 
     295              : #ifdef CUSTOM_INTERFACE
     296            1 : STATIC int RsOpenRoceUserSo(enum SoType *type)
     297              : {
     298            1 :     pthread_mutex_lock(&gRoceUserApiLock);
     299              : #ifndef CA_CONFIG_LLT
     300              :     if (gRoceUserApiHandle == NULL) {
     301              :         gRoceUserApiHandle = HccpDlopen("libhns-rdmav17.so", RTLD_NOW);
     302              :         if (gRoceUserApiHandle != NULL) {
     303              :             *type = SO_TYPE_EXP;
     304              :             goto out;
     305              :         }
     306              : 
     307              :         gRoceUserApiHandle = HccpDlopen("libhns-rdmav25.so", RTLD_NOW);
     308              :         if (gRoceUserApiHandle != NULL) {
     309              :             *type = SO_TYPE_EXT;
     310              :             goto out;
     311              :         }
     312              : 
     313              :         gRoceUserApiHandle = HccpDlopen("libhrn0-rdmav17.so", RTLD_NOW);
     314              :         if (gRoceUserApiHandle != NULL) {
     315              :             *type = SO_TYPE_EXP;
     316              :             goto out;
     317              :         }
     318              : 
     319              :         pthread_mutex_unlock(&gRoceUserApiLock);
     320              :         return -EINVAL;
     321              :     } else {
     322              :         hccp_run_info("dlopen roce_user_api again, gRoceUserApiRefcnt:%d", gRoceUserApiRefcnt + 1);
     323              :     }
     324              : 
     325              : out:
     326              : #endif
     327            1 :     gRoceUserApiRefcnt++;
     328            1 :     pthread_mutex_unlock(&gRoceUserApiLock);
     329            1 :     return 0;
     330              : }
     331              : #endif
     332              : 
     333           39 : STATIC void RsCloseRoceUserSo(void)
     334              : {
     335           39 :     pthread_mutex_lock(&gRoceUserApiLock);
     336              : #ifndef CA_CONFIG_LLT
     337              :     if (gRoceUserApiHandle != NULL) {
     338              :         gRoceUserApiRefcnt--;
     339              :         if (gRoceUserApiRefcnt > 0) {
     340              :             goto out;
     341              :         }
     342              : 
     343              :         hccp_run_info("dlclose roce_user_api, gRoceUserApiRefcnt:%d", gRoceUserApiRefcnt);
     344              :         (void)HccpDlclose(gRoceUserApiHandle);
     345              :         gRoceUserApiHandle = NULL;
     346              :         gRoceUserApiRefcnt = 0;
     347              :     }
     348              : out:
     349              : #endif
     350           39 :     pthread_mutex_unlock(&gRoceUserApiLock);
     351           39 :     return;
     352              : }
     353              : 
     354              : #ifdef CUSTOM_INTERFACE
     355            0 : STATIC int RsRoceUserIbvApiInit(void)
     356              : {
     357              : #ifndef CA_CONFIG_LLT
     358              :     gRoceUserOps.rsIbvExpCreateQp = (struct ibv_qp* (*)(struct ibv_pd *pd,
     359              :         struct ibv_exp_qp_init_attr *qpInitAttr, struct rdma_lite_device_qp_attr *qpResp))
     360              :         HccpDlsym(gRoceUserApiHandle, "ibv_exp_create_qp");
     361              :     DL_API_RET_IS_NULL_CHECK(gRoceUserOps.rsIbvExpCreateQp, "ibv_exp_create_qp");
     362              :     gRoceUserOps.rsIbvExpRegMr = (struct ibv_mr* (*)(struct ibv_pd *pd, void *addr, size_t length,
     363              :         int access, struct roce_process_sign roceSign))
     364              :         HccpDlsym(gRoceUserApiHandle, "ibv_exp_reg_mr");
     365              :     DL_API_RET_IS_NULL_CHECK(gRoceUserOps.rsIbvExpRegMr, "ibv_exp_reg_mr");
     366              :     gRoceUserOps.rsIbvExpQueryNotify = (int (*)(struct ibv_context *context,
     367              :         unsigned long long *notifyVa, unsigned long long *size))
     368              :         HccpDlsym(gRoceUserApiHandle, "ibv_exp_query_notify");
     369              :     DL_API_RET_IS_NULL_CHECK(gRoceUserOps.rsIbvExpQueryNotify, "ibv_exp_query_notify");
     370              :     gRoceUserOps.rsIbvExpPostSend = (int (*)(struct ibv_qp *qp, struct ibv_send_wr *wr,
     371              :         struct ibv_send_wr **badWr, struct wr_exp_rsp *expRsp))
     372              :         HccpDlsym(gRoceUserApiHandle, "ibv_exp_post_send");
     373              :     DL_API_RET_IS_NULL_CHECK(gRoceUserOps.rsIbvExpPostSend, "ibv_exp_post_send");
     374              :     gRoceUserOps.rsIbvExpCreateCq = (struct ibv_cq* (*)(struct ibv_context*, int, void*,
     375              :         struct ibv_comp_channel*, int, struct rdma_lite_device_cq_init_attr*, struct rdma_lite_device_cq_attr*))
     376              :         HccpDlsym(gRoceUserApiHandle, "ibv_exp_create_cq");
     377              :     DL_API_RET_IS_NULL_CHECK(gRoceUserOps.rsIbvExpCreateCq, "ibv_exp_create_cq");
     378              :     gRoceUserOps.rsIbvExpQueryDevice = (int (*)(struct ibv_context*, struct dev_cap_info*))
     379              :         HccpDlsym(gRoceUserApiHandle, "ibv_exp_query_device");
     380              :     DL_API_RET_IS_NULL_CHECK(gRoceUserOps.rsIbvExpQueryDevice, "ibv_exp_query_device");
     381              :     gRoceUserOps.rsIbvExpCreateAh = (struct ibv_ah* (*)(struct ibv_pd *pd, struct ibv_exp_ah_attr *attrx))
     382              :         HccpDlsym(gRoceUserApiHandle, "ibv_exp_create_ah");
     383              :     DL_API_RET_IS_NULL_CHECK(gRoceUserOps.rsIbvExpCreateAh, "ibv_exp_create_ah");
     384              : #endif
     385            0 :     return 0;
     386              : }
     387              : #endif
     388              : 
     389              : #ifdef CUSTOM_INTERFACE
     390            0 : STATIC int RsRoceUserDrvApiInit(void)
     391              : {
     392              : #ifndef CA_CONFIG_LLT
     393              :     gRoceUserOps.rsRoceGetRoceDevData = (int (*)(const char *devName, struct roce_dev_data *rdevData))
     394              :         HccpDlsym(gRoceUserApiHandle, "roce_get_roce_dev_data");
     395              :     DL_API_RET_IS_NULL_CHECK(gRoceUserOps.rsRoceGetRoceDevData, "roce_get_roce_dev_data");
     396              :     gRoceUserOps.rsRoceGetTsqpDepth = (int (*)(const char *devName, unsigned int rdevIndex,
     397              :         unsigned int *tempDepth, unsigned int *qpNum, unsigned int *sqDepth))
     398              :         HccpDlsym(gRoceUserApiHandle, "roce_get_tsqp_depth");
     399              :     DL_API_RET_IS_NULL_CHECK(gRoceUserOps.rsRoceGetTsqpDepth, "roce_get_tsqp_depth");
     400              :     gRoceUserOps.rsRoceSetTsqpDepth = (int (*)(const char *devName, unsigned int rdevIndex,
     401              :         unsigned int tempDepth, unsigned int *qpNum, unsigned int *sqDepth))
     402              :         HccpDlsym(gRoceUserApiHandle, "roce_set_tsqp_depth");
     403              :     DL_API_RET_IS_NULL_CHECK(gRoceUserOps.rsRoceSetTsqpDepth, "roce_set_tsqp_depth");
     404              :     gRoceUserOps.rsRoceInitMemPool = (int (*)(const struct roce_mem_cq_qp_attr *,
     405              :         struct rdma_lite_device_mem_attr *, unsigned int)) HccpDlsym(gRoceUserApiHandle, "roce_init_mem_pool");
     406              :     DL_API_RET_IS_NULL_CHECK(gRoceUserOps.rsRoceInitMemPool, "roce_init_mem_pool");
     407              :     gRoceUserOps.rsRoceDeinitMemPool = (int (*)(unsigned int))
     408              :         HccpDlsym(gRoceUserApiHandle, "roce_deinit_mem_pool");
     409              :     DL_API_RET_IS_NULL_CHECK(gRoceUserOps.rsRoceDeinitMemPool, "roce_deinit_mem_pool");
     410              :     gRoceUserOps.rsRoceQueryQpc = (int (*)(struct ibv_qp *qp, struct hns_roce_qpc_attr_val *attrVal,
     411              :         unsigned int attrMask)) HccpDlsym(gRoceUserApiHandle, "roce_query_qpc");
     412              :     DL_API_RET_IS_NULL_CHECK(gRoceUserOps.rsRoceQueryQpc, "roce_query_qpc");
     413              :     gRoceUserOps.rsRoceMmapAiDbReg = (int (*)(struct ibv_context *context, unsigned int tgid))
     414              :         HccpDlsym(gRoceUserApiHandle, "roce_mmap_ai_db_reg");
     415              :     DL_API_RET_IS_NULL_CHECK(gRoceUserOps.rsRoceMmapAiDbReg, "roce_mmap_ai_db_reg");
     416              :     gRoceUserOps.rsRoceUnmmapAiDbReg = (int (*)(struct ibv_context *context))
     417              :         HccpDlsym(gRoceUserApiHandle, "roce_unmmap_ai_db_reg");
     418              :     DL_API_RET_IS_NULL_CHECK(gRoceUserOps.rsRoceUnmmapAiDbReg, "roce_unmmap_ai_db_reg");
     419              :     gRoceUserOps.rsRoceGetCqDataPlaneInfo = (int (*)(struct ibv_cq *cq,
     420              :         struct hns_roce_cq_data_plane_info *info)) HccpDlsym(gRoceUserApiHandle, "roce_get_cq_data_plane_info");
     421              :     DL_API_RET_IS_NULL_CHECK(gRoceUserOps.rsRoceGetCqDataPlaneInfo, "roce_get_cq_data_plane_info");
     422              :     gRoceUserOps.rsRoceGetQpDataPlaneInfo = (int (*)(struct ibv_qp *qp,
     423              :         struct hns_roce_qp_data_plane_info *info)) HccpDlsym(gRoceUserApiHandle, "roce_get_qp_data_plane_info");
     424              :     DL_API_RET_IS_NULL_CHECK(gRoceUserOps.rsRoceGetQpDataPlaneInfo, "roce_get_qp_data_plane_info");
     425              :     gRoceUserOps.rsRoceRemapMr = (int (*)(struct ibv_mr *mr, struct hns_roce_mr_remap_info info[],
     426              :         unsigned int num)) HccpDlsym(gRoceUserApiHandle, "roce_remap_mr");
     427              :     DL_API_RET_IS_NULL_CHECK(gRoceUserOps.rsRoceRemapMr, "roce_remap_mr");
     428              :     gRoceUserOps.rsRoceGetApiVersion = (unsigned int (*)(void))
     429              :         HccpDlsym(gRoceUserApiHandle, "roce_get_api_version");
     430              :     DL_API_RET_IS_NULL_CHECK(gRoceUserOps.rsRoceGetApiVersion, "roce_get_api_version");
     431              : #endif
     432            0 :     return 0;
     433              : }
     434              : #endif
     435              : 
     436              : #ifdef CUSTOM_INTERFACE
     437            1 : STATIC int RsRoceUserApiInit(void)
     438              : {
     439            1 :     enum SoType type = SO_TYPE_INVALID;
     440            1 :     int ret = 0;
     441              : 
     442            1 :     ret = RsOpenRoceUserSo(&type);
     443            1 :     CHK_PRT_RETURN(ret != 0, hccp_err("HccpDlopen[libhns-rdmav17.so or libhns-rdmav25.so or libhrn0-rdmav17.so]"
     444              :         "failed! ret=[%d]. Please check network adapter driver has been installed.", ret), ret);
     445              : 
     446              : #ifndef CA_CONFIG_LLT
     447              :     ret = RsRoceUserIbvApiInit();
     448              :     if (ret != 0) {
     449              :         hccp_err("rs_roce_user_ibv_api_init failed! ret=[%d]", ret);
     450              :         goto close_roce_user_so;
     451              :     }
     452              : 
     453              :     ret = RsRoceUserDrvApiInit();
     454              :     if (ret != 0) {
     455              :         hccp_err("rs_roce_user_drv_api_init failed! ret=[%d]", ret);
     456              :         goto close_roce_user_so;
     457              :     }
     458              : 
     459              :     if (type == SO_TYPE_EXT) {
     460              :         gRoceUserOps.rsIbvExtPostSend = (int (*)(struct ibv_qp *qp, struct ibv_send_wr *wr,
     461              :             struct ibv_send_wr **badWr, struct ibv_post_send_ext_attr *extAttr,
     462              :             struct ibv_post_send_ext_resp *extResp))
     463              :             HccpDlsym(gRoceUserApiHandle, "ibv_ext_post_send");
     464              :         if (gRoceUserOps.rsIbvExtPostSend == NULL) {
     465              :             ret = -EINVAL;
     466              :             hccp_err("ibv_ext_post_send is null");
     467              :             goto close_roce_user_so;
     468              :         }
     469              :     }
     470              :     return 0;
     471              : 
     472              : close_roce_user_so:
     473              :     RsCloseRoceUserSo();
     474              : #endif
     475            1 :     return ret;
     476              : }
     477              : #endif
     478              : 
     479            0 : STATIC int RsHrnIbvApiInit(void)
     480              : {
     481              : #ifndef CA_CONFIG_LLT
     482              :     gHrnOps.rsRoceSetQpLbValue = (int (*)(struct ibv_qp *qp, int lbValue))
     483              :         HccpDlsym(gHrnApiHandle, "roce_set_qp_lb_value");
     484              :     gHrnOps.rsRoceGetQpLbValue = (int (*)(struct ibv_qp *qp, int *lbValue))
     485              :         HccpDlsym(gHrnApiHandle, "roce_get_qp_lb_value");
     486              :     gHrnOps.rsRoceGetQpNum = (int (*)(struct ibv_context *context, int *qpNum))
     487              :         HccpDlsym(gHrnApiHandle, "roce_get_qp_num");
     488              : #endif
     489            0 :     return 0;
     490              : }
     491              : 
     492            0 : STATIC int RsOpenHrnSo(void)
     493              : {
     494              : #ifndef CA_CONFIG_LLT
     495              :     if (gHrnApiHandle == NULL) {
     496              :         gHrnApiHandle = HccpDlopen("libhrn5-rdmav34.so", RTLD_NOW);
     497              :         if (gHrnApiHandle != NULL) {
     498              :             return 0;
     499              :         }
     500              :         return -EINVAL;
     501              :     } else {
     502              :         hccp_run_info("HrnApi dlopen again!");
     503              :     }
     504              : #endif
     505            0 :     return 0;
     506              : }
     507              : 
     508           38 : STATIC void RsCloseHrnSo(void)
     509              : {
     510              : #ifndef CA_CONFIG_LLT
     511              :     if (gHrnApiHandle != NULL) {
     512              :         (void)HccpDlclose(gHrnApiHandle);
     513              :         gHrnApiHandle = NULL;
     514              :     }
     515              : #endif
     516           38 :     return;
     517              : }
     518              : 
     519            0 : int RsHrnApiInit(void)
     520              : {
     521              : #ifndef CA_CONFIG_LLT
     522              :     int ret = 0;
     523              : 
     524              :     ret = RsOpenHrnSo();
     525              :     if (ret != 0) {
     526              :         hccp_warn("HccpDlopen[libhrn3-rdmav34.so] doesn't exist!");
     527              :         return 0;
     528              :     }
     529              : 
     530              :     ret = RsHrnIbvApiInit();
     531              :     if (ret != 0) {
     532              :         hccp_err("RsHrnIbvApiInit failed! ret:%d", ret);
     533              :         RsCloseHrnSo();
     534              :         return ret;
     535              :     }
     536              : #endif
     537            0 :     return 0;
     538              : }
     539              : 
     540           38 : DL_ATTRI_VISI_DEF int RsApiInit(void)
     541              : {
     542              : #ifndef CA_CONFIG_LLT
     543              :     int ret;
     544              :     ret = RsIbverbsApiInit();
     545              :     CHK_PRT_RETURN(ret, hccp_err("rs_ibverbs_api_init failed! ret=[%d]", ret), ret);
     546              :     ret = RsHrnApiInit();
     547              :     if (ret != 0) {
     548              :         hccp_err("RsHrnApiInit failed! ret=[%d]", ret);
     549              :         RsCloseIbverbsSo();
     550              :         return ret;
     551              :     }
     552              :     ret = RsIbvExtendApiInit();
     553              :     if (ret != 0) {
     554              :         hccp_err("RsHrnApiInit failed! ret=[%d]", ret);
     555              :         RsCloseHrnSo();
     556              :         RsCloseIbverbsSo();
     557              :         return ret;
     558              :     }
     559              : #ifdef CUSTOM_INTERFACE
     560              :     ret = RsRoceUserApiInit();
     561              :     if (ret != 0) {
     562              :         hccp_err("rs_roce_user_api_init failed! ret=[%d]", ret);
     563              :         RsCloseHrnSo();
     564              :         RsCloseIbverbsSo();
     565              :         RsIbvExtendApiDeinit();
     566              :         return ret;
     567              :     }
     568              : #endif
     569              : #endif
     570           38 :     return 0;
     571              : }
     572              : 
     573           38 : DL_ATTRI_VISI_DEF void RsApiDeinit(void)
     574              : {
     575           38 :     RsCloseIbverbsSo();
     576           38 :     RsCloseHrnSo();
     577           38 :     RsIbvExtendApiDeinit();
     578           38 :     RsCloseRoceUserSo();
     579           38 :     return;
     580              : }
     581              : 
     582            5 : struct ibv_mr *RsIbvExpRegMr(struct ibv_pd *pd, void *addr, size_t length, int access,
     583              :     struct roce_process_sign roceSign)
     584              : {
     585            5 :     if (gRoceUserOps.rsIbvExpRegMr == NULL) {
     586              : #ifndef CA_CONFIG_LLT
     587              :         hccp_err("rs_ibv_exp_reg_mr is null");
     588              :         return NULL;
     589              : #endif
     590              :     }
     591            5 :     return gRoceUserOps.rsIbvExpRegMr(pd, addr, length, access, roceSign);
     592              : }
     593              : 
     594           41 : struct ibv_qp *RsIbvExpCreateQp(
     595              :     struct ibv_pd *pd, struct ibv_exp_qp_init_attr *qpInitAttr, struct rdma_lite_device_qp_attr *qpResp)
     596              : {
     597           41 :     if (gRoceUserOps.rsIbvExpCreateQp == NULL) {
     598              : #ifndef CA_CONFIG_LLT
     599              :         hccp_err("rs_ibv_exp_create_qp is null");
     600              :         return NULL;
     601              : #endif
     602              :     }
     603           41 :     return gRoceUserOps.rsIbvExpCreateQp(pd, qpInitAttr, qpResp);
     604              : }
     605              : 
     606            1 : int RsRoceSetTsqpDepth(const char *devName, unsigned int rdevIndex, unsigned int tempDepth,
     607              :     unsigned int *qpNum, unsigned int *sqDepth)
     608              : {
     609            1 :     if (gRoceUserOps.rsRoceSetTsqpDepth == NULL) {
     610              : #ifndef CA_CONFIG_LLT
     611              :         hccp_err("rs_roce_set_tsqp_depth is null");
     612              :         return -EINVAL;
     613              : #endif
     614              :     }
     615            1 :     return gRoceUserOps.rsRoceSetTsqpDepth(devName, rdevIndex, tempDepth, qpNum, sqDepth);
     616              : }
     617              : 
     618           31 : int RsRoceGetTsqpDepth(const char *devName, unsigned int rdevIndex, unsigned int *tempDepth,
     619              :     unsigned int *qpNum, unsigned int *sqDepth)
     620              : {
     621           31 :     if (gRoceUserOps.rsRoceGetTsqpDepth == NULL) {
     622              : #ifndef CA_CONFIG_LLT
     623              :         hccp_err("rs_roce_get_tsqp_depth is null");
     624              :         return -EINVAL;
     625              : #endif
     626              :     }
     627           31 :     return gRoceUserOps.rsRoceGetTsqpDepth(devName, rdevIndex, tempDepth, qpNum, sqDepth);
     628              : }
     629              : 
     630           25 : int RsRoceGetRoceDevData(const char *devName, struct roce_dev_data *rdevData)
     631              : {
     632           25 :     if (gRoceUserOps.rsRoceGetRoceDevData == NULL) {
     633              : #ifndef CA_CONFIG_LLT
     634              :         hccp_err("rs_roce_get_roce_dev_data is null");
     635              :         return -EINVAL;
     636              : #endif
     637              :     }
     638           25 :     return gRoceUserOps.rsRoceGetRoceDevData(devName, rdevData);
     639              : }
     640              : 
     641           26 : int RsIbvExpQueryNotify(struct ibv_context *context, unsigned long long *notifyVa,
     642              :     unsigned long long *size)
     643              : {
     644           26 :     if (gRoceUserOps.rsIbvExpQueryNotify == NULL) {
     645              : #ifndef CA_CONFIG_LLT
     646              :         hccp_err("rs_ibv_exp_query_notify is null");
     647              :         return -EINVAL;
     648              : #endif
     649              :     }
     650           26 :     return gRoceUserOps.rsIbvExpQueryNotify(context, notifyVa, size);
     651              : }
     652            3 : int RsIbvExpPostSend(struct ibv_qp *qp, struct ibv_send_wr *wr, struct ibv_send_wr **badWr,
     653              :     struct wr_exp_rsp *expRsp)
     654              : {
     655            3 :     if (gRoceUserOps.rsIbvExpPostSend == NULL) {
     656              : #ifndef CA_CONFIG_LLT
     657              :         hccp_err("rs_ibv_exp_post_send is null");
     658              :         return -EINVAL;
     659              : #endif
     660              :     }
     661            3 :     return gRoceUserOps.rsIbvExpPostSend(qp, wr, badWr, expRsp);
     662              : }
     663              : 
     664            1 : int RsIbvExtPostSend(struct ibv_qp *qp, struct ibv_send_wr *wr, struct ibv_send_wr **badWr,
     665              :     struct ibv_post_send_ext_attr *extAttr, struct ibv_post_send_ext_resp *extResp)
     666              : {
     667            1 :     if (gRoceUserOps.rsIbvExtPostSend == NULL) {
     668              : #ifndef CA_CONFIG_LLT
     669              :         hccp_err("rs_ibv_ext_post_send is null");
     670              :         return -EINVAL;
     671              : #endif
     672              :     }
     673            1 :     return gRoceUserOps.rsIbvExtPostSend(qp, wr, badWr, extAttr, extResp);
     674              : }
     675              : 
     676           31 : void RsIbvFreeDeviceList(struct ibv_device **list)
     677              : {
     678           31 :     if (gIbverbsOps.rsIbvFreeDeviceList == NULL) {
     679              : #ifndef CA_CONFIG_LLT
     680              :         hccp_err("rs_ibv_free_device_list is null");
     681              :         return;
     682              : #endif
     683              :     }
     684           31 :     gIbverbsOps.rsIbvFreeDeviceList(list);
     685           31 : }
     686              : 
     687           66 : void RsIbvAckCqEvents(struct ibv_cq *cq, unsigned int nevents)
     688              : {
     689           66 :     if (gIbverbsOps.rsIbvAckCqEvents == NULL) {
     690              : #ifndef CA_CONFIG_LLT
     691              :         hccp_err("rs_ibv_ack_cq_events is null");
     692              :         return;
     693              : #endif
     694              :     }
     695           66 :     gIbverbsOps.rsIbvAckCqEvents(cq, nevents);
     696           66 : }
     697              : 
     698           28 : const char *RsIbvGetDeviceName(struct ibv_device *device)
     699              : {
     700           28 :     if (gIbverbsOps.rsIbvGetDeviceName == NULL) {
     701              : #ifndef CA_CONFIG_LLT
     702              :         hccp_err("rs_ibv_get_device_name is null");
     703              :         return NULL;
     704              : #endif
     705              :     }
     706           28 :     return gIbverbsOps.rsIbvGetDeviceName(device);
     707              : }
     708              : 
     709            2 : const char *RsIbvWcStatusStr(enum ibv_wc_status status)
     710              : {
     711            2 :     if (gIbverbsOps.rsIbvWcStatusStr == NULL) {
     712              : #ifndef CA_CONFIG_LLT
     713              :         hccp_err("rs_ibv_wc_status_str is null");
     714              :         return NULL;
     715              : #endif
     716              :     }
     717            2 :     return gIbverbsOps.rsIbvWcStatusStr(status);
     718              : }
     719              : 
     720          201 : int RsIbvQueryGidType(struct ibv_context *context, uint8_t portNum, unsigned int index,
     721              :     enum ibv_gid_type_sysfs *type)
     722              : {
     723          201 :     if (gIbverbsOps.rsIbvQueryGidType == NULL) {
     724              : #ifndef CA_CONFIG_LLT
     725              :         hccp_err("rs_ibv_query_gid_type is null");
     726              :         return -EINVAL;
     727              : #endif
     728              :     }
     729          201 :     return gIbverbsOps.rsIbvQueryGidType(context, portNum, index, type);
     730              : }
     731              : 
     732           37 : int RsIbvDeregMr(struct ibv_mr *mr)
     733              : {
     734           37 :     if (gIbverbsOps.rsIbvDeregMr == NULL) {
     735              : #ifndef CA_CONFIG_LLT
     736              :         hccp_err("rs_ibv_dereg_mr is null");
     737              :         return -EINVAL;
     738              : #endif
     739              :     }
     740           37 :     return gIbverbsOps.rsIbvDeregMr(mr);
     741              : }
     742              : 
     743            1 : int RsIbvPostSend(struct ibv_qp *qp, struct ibv_send_wr *wr, struct ibv_send_wr **badWr)
     744              : {
     745            1 :     return ibv_post_send(qp, wr, badWr);
     746              : }
     747              : 
     748            0 : int RsIbvPostRecv(struct ibv_qp *qp, struct ibv_recv_wr *wr, struct ibv_recv_wr **badWr)
     749              : {
     750            0 :     return ibv_post_recv(qp, wr, badWr);
     751              : }
     752              : 
     753           67 : int RsIbvQueryQp(struct ibv_qp *qp, struct ibv_qp_attr *attr, int attrMask, struct ibv_qp_init_attr *initAttr)
     754              : {
     755           67 :     if (gIbverbsOps.rsIbvQueryQp == NULL) {
     756              : #ifndef CA_CONFIG_LLT
     757              :         hccp_err("rs_ibv_query_qp is null");
     758              :         return -EINVAL;
     759              : #endif
     760              :     }
     761           67 :     return gIbverbsOps.rsIbvQueryQp(qp, attr, attrMask, initAttr);
     762              : }
     763              : 
     764           44 : int RsIbvDestroyQp(struct ibv_qp *qp)
     765              : {
     766           44 :     if (gIbverbsOps.rsIbvDestroyQp == NULL) {
     767              : #ifndef CA_CONFIG_LLT
     768              :         hccp_err("rs_ibv_destroy_qp is null");
     769              :         return -EINVAL;
     770              : #endif
     771              :     }
     772           44 :     return gIbverbsOps.rsIbvDestroyQp(qp);
     773              : }
     774              : 
     775            9 : int RsIbvGetCqEvent(struct ibv_comp_channel *channel, struct ibv_cq **cq, void **cqContext)
     776              : {
     777            9 :     if (gIbverbsOps.rsIbvGetCqEvent == NULL) {
     778              : #ifndef CA_CONFIG_LLT
     779              :         hccp_err("rs_ibv_get_cq_event is null");
     780              :         return -EINVAL;
     781              : #endif
     782              :     }
     783            9 :     return gIbverbsOps.rsIbvGetCqEvent(channel, cq, cqContext);
     784              : }
     785              : 
     786            1 : int RsIbvPollCq(struct ibv_cq *cq, int numEntries, struct ibv_wc *wc)
     787              : {
     788            1 :     return ibv_poll_cq(cq, numEntries, wc);
     789              : }
     790              : 
     791            4 : int RsIbvReqNotifyCq(struct ibv_cq *cq, int solicitedOnly)
     792              : {
     793            4 :     return ibv_req_notify_cq(cq, solicitedOnly);
     794              : }
     795              : 
     796          108 : int RsIbvDestroyCq(struct ibv_cq *cq)
     797              : {
     798          108 :     if (gIbverbsOps.rsIbvDestroyCq == NULL) {
     799              : #ifndef CA_CONFIG_LLT
     800              :         hccp_err("rs_ibv_destroy_cq is null");
     801              :         return -EINVAL;
     802              : #endif
     803              :     }
     804          108 :     return gIbverbsOps.rsIbvDestroyCq(cq);
     805              : }
     806              : 
     807          108 : int RsIbvModifyQp(struct ibv_qp *qp, struct ibv_qp_attr *attr, int attrMask)
     808              : {
     809          108 :     if (gIbverbsOps.rsIbvModifyQp == NULL) {
     810              : #ifndef CA_CONFIG_LLT
     811              :         hccp_err("rs_ibv_modify_qp is null");
     812              :         return -EINVAL;
     813              : #endif
     814              :     }
     815          108 :     return gIbverbsOps.rsIbvModifyQp(qp, attr, attrMask);
     816              : }
     817              : 
     818           28 : int RsIbvQueryDevice(struct ibv_context *context, struct ibv_device_attr *deviceAttr)
     819              : {
     820           28 :     if (gIbverbsOps.rsIbvQueryDevice == NULL) {
     821              : #ifndef CA_CONFIG_LLT
     822              :         hccp_err("rs_ibv_query_device is null");
     823              :         return -EINVAL;
     824              : #endif
     825              :     }
     826           28 :     return gIbverbsOps.rsIbvQueryDevice(context, deviceAttr);
     827              : }
     828              : 
     829          125 : int RsIbvQueryPort(struct ibv_context *context, uint8_t portNum, struct ibv_port_attr *portAttr)
     830              : {
     831          125 :     if (gIbverbsOps.rsIbvQueryPort == NULL) {
     832              : #ifndef CA_CONFIG_LLT
     833              :         hccp_err("rs_ibv_query_port is null");
     834              :         return -EINVAL;
     835              : #endif
     836              :     }
     837          125 :     return gIbverbsOps.rsIbvQueryPort(context, portNum, portAttr);
     838              : }
     839              : 
     840          139 : int RsIbvQueryGid(struct ibv_context *context, uint8_t portNum, int index, union ibv_gid *gid)
     841              : {
     842          139 :     if (gIbverbsOps.rsIbvQueryGid == NULL) {
     843              : #ifndef CA_CONFIG_LLT
     844              :         hccp_err("rs_ibv_query_gid is null");
     845              :         return -EINVAL;
     846              : #endif
     847              :     }
     848          139 :     return gIbverbsOps.rsIbvQueryGid(context, portNum, index, gid);
     849              : }
     850              : 
     851           38 : int RsIbvCloseDevice(struct ibv_context *context)
     852              : {
     853           38 :     if (gIbverbsOps.rsIbvCloseDevice == NULL) {
     854              : #ifndef CA_CONFIG_LLT
     855              :         hccp_err("rs_ibv_close_device is null");
     856              :         return -EINVAL;
     857              : #endif
     858              :     }
     859           38 :     return gIbverbsOps.rsIbvCloseDevice(context);
     860              : }
     861              : 
     862           29 : int RsIbvDeallocPd(struct ibv_pd *pd)
     863              : {
     864           29 :     if (gIbverbsOps.rsIbvDeallocPd == NULL) {
     865              : #ifndef CA_CONFIG_LLT
     866              :         hccp_err("rs_ibv_dealloc_pd is null");
     867              :         return -EINVAL;
     868              : #endif
     869              :     }
     870           29 :     return gIbverbsOps.rsIbvDeallocPd(pd);
     871              : }
     872              : 
     873           54 : int RsIbvDestroyCompChannel(struct ibv_comp_channel *channel)
     874              : {
     875           54 :     if (gIbverbsOps.rsIbvDestroyCompChannel == NULL) {
     876              : #ifndef CA_CONFIG_LLT
     877              :         hccp_err("rs_ibv_destroy_comp_channel is null");
     878              :         return -EINVAL;
     879              : #endif
     880              :     }
     881           54 :     return gIbverbsOps.rsIbvDestroyCompChannel(channel);
     882              : }
     883              : 
     884           34 : struct ibv_context *RsIbvOpenDevice(struct ibv_device *device)
     885              : {
     886           34 :     if (gIbverbsOps.rsIbvOpenDevice == NULL) {
     887              : #ifndef CA_CONFIG_LLT
     888              :         hccp_err("rs_ibv_open_device is null");
     889              :         return NULL;
     890              : #endif
     891              :     }
     892           34 :     return gIbverbsOps.rsIbvOpenDevice(device);
     893              : }
     894              : 
     895           28 : struct ibv_pd *RsIbvAllocPd(struct ibv_context *context)
     896              : {
     897           28 :     if (gIbverbsOps.rsIbvAllocPd == NULL) {
     898              : #ifndef CA_CONFIG_LLT
     899              :         hccp_err("rs_ibv_alloc_pd is null");
     900              :         return NULL;
     901              : #endif
     902              :     }
     903           28 :     return gIbverbsOps.rsIbvAllocPd(context);
     904              : }
     905              : 
     906           31 : struct ibv_device **RsIbvGetDeviceList(int *numDevices)
     907              : {
     908           31 :     if (gIbverbsOps.rsIbvGetDeviceList == NULL) {
     909              : #ifndef CA_CONFIG_LLT
     910              :         hccp_err("rs_ibv_get_device_list is null");
     911              :         return NULL;
     912              : #endif
     913              :     }
     914           31 :     return gIbverbsOps.rsIbvGetDeviceList(numDevices);
     915              : }
     916              : 
     917           97 : struct ibv_cq *RsIbvCreateCq(struct ibv_context *context, int cqe, void *cqContext,
     918              :     struct ibv_comp_channel *channel, int compVector)
     919              : {
     920           97 :     if (gIbverbsOps.rsIbvCreateCq == NULL) {
     921              : #ifndef CA_CONFIG_LLT
     922              :         hccp_err("rs_ibv_create_cq is null");
     923              :         return NULL;
     924              : #endif
     925              :     }
     926           97 :     return gIbverbsOps.rsIbvCreateCq(context, cqe, cqContext, channel, compVector);
     927              : }
     928              : 
     929           32 : struct ibv_mr *RsIbvRegMr(struct ibv_pd *pd, void *addr, size_t length, int access)
     930              : {
     931           32 :     if (gIbverbsOps.rsIbvRegMr == NULL) {
     932              : #ifndef CA_CONFIG_LLT
     933              :         hccp_err("rs_ibv_reg_mr is null");
     934              :         return NULL;
     935              : #endif
     936              :     }
     937           32 :     return gIbverbsOps.rsIbvRegMr(pd, addr, length, access);
     938              : }
     939              : 
     940            4 : struct ibv_qp *RsIbvCreateQp(struct ibv_pd *pd, struct ibv_qp_init_attr *qpInitAttr)
     941              : {
     942            4 :     if (gIbverbsOps.rsIbvCreateQp == NULL) {
     943              : #ifndef CA_CONFIG_LLT
     944              :         hccp_err("rs_ibv_create_qp is null");
     945              :         return NULL;
     946              : #endif
     947              :     }
     948            4 :     return gIbverbsOps.rsIbvCreateQp(pd, qpInitAttr);
     949              : }
     950              : 
     951           55 : struct ibv_comp_channel *RsIbvCreateCompChannel(struct ibv_context *context)
     952              : {
     953           55 :     if (gIbverbsOps.rsIbvCreateCompChannel == NULL) {
     954              : #ifndef CA_CONFIG_LLT
     955              :         hccp_err("rs_ibv_create_comp_channel is null");
     956              :         return NULL;
     957              : #endif
     958              :     }
     959           55 :     return gIbverbsOps.rsIbvCreateCompChannel(context);
     960              : }
     961              : 
     962            1 : struct ibv_srq *RsIbvCreateSrq(struct ibv_pd *pd, struct ibv_srq_init_attr *srqInitAttr)
     963              : {
     964            1 :     if (gIbverbsOps.rsIbvCreateSrq == NULL) {
     965              : #ifndef CA_CONFIG_LLT
     966              :         hccp_err("rs_ibv_create_srq is null");
     967              :         return NULL;
     968              : #endif
     969              :     }
     970            1 :     return gIbverbsOps.rsIbvCreateSrq(pd, srqInitAttr);
     971              : }
     972              : 
     973            1 : int RsIbvDestroySrq(struct ibv_srq *srq)
     974              : {
     975            1 :     if (gIbverbsOps.rsIbvDestroySrq == NULL) {
     976              : #ifndef CA_CONFIG_LLT
     977              :         hccp_err("rs_ibv_destroy_srq is null");
     978              :         return -EINVAL;
     979              : #endif
     980              :     }
     981            1 :     return gIbverbsOps.rsIbvDestroySrq(srq);
     982              : }
     983              : 
     984            0 : struct ibv_ah *RsIbvCreateAh(struct ibv_pd *pd, struct ibv_ah_attr *attr)
     985              : {
     986            0 :     if (gIbverbsOps.rsIbvCreateAh == NULL) {
     987              : #ifndef CA_CONFIG_LLT
     988              :         hccp_err("rs_ibv_create_ah is null");
     989              :         return NULL;
     990              : #endif
     991              :     }
     992            0 :     return gIbverbsOps.rsIbvCreateAh(pd, attr);
     993              : }
     994              : 
     995            0 : int RsIbvDestroyAh(struct ibv_ah *ah)
     996              : {
     997            0 :     if (gIbverbsOps.rsIbvDestroyAh == NULL) {
     998              : #ifndef CA_CONFIG_LLT
     999              :         hccp_err("rs_ibv_destroy_ah is null");
    1000              :         return -EINVAL;
    1001              : #endif
    1002              :     }
    1003            0 :     return gIbverbsOps.rsIbvDestroyAh(ah);
    1004              : }
    1005              : 
    1006           12 : struct ibv_cq *RsIbvExpCreateCq(struct ibv_context *context, int cqe, void *cqContext,
    1007              :     struct ibv_comp_channel *channel, int compVector, struct rdma_lite_device_cq_init_attr *attr,
    1008              :     struct rdma_lite_device_cq_attr *cqResp)
    1009              : {
    1010           12 :     if (gRoceUserOps.rsIbvExpCreateCq == NULL) {
    1011              : #ifndef CA_CONFIG_LLT
    1012              :         hccp_err("rs_ibv_exp_create_cq is null");
    1013              :         return NULL;
    1014              : #endif
    1015              :     }
    1016           12 :     return gRoceUserOps.rsIbvExpCreateCq(context, cqe, cqContext, channel, compVector, attr, cqResp);
    1017              : }
    1018              : 
    1019            2 : int RsIbvExpQueryDevice(struct ibv_context *context, struct dev_cap_info *cap)
    1020              : {
    1021            2 :     if (gRoceUserOps.rsIbvExpQueryDevice == NULL) {
    1022              : #ifndef CA_CONFIG_LLT
    1023              :         hccp_err("rs_ibv_exp_query_device is null");
    1024              :         return -EINVAL;
    1025              : #endif
    1026              :     }
    1027            2 :     return gRoceUserOps.rsIbvExpQueryDevice(context, cap);
    1028              : }
    1029              : 
    1030            0 : int RsRoceInitMemPool(const struct roce_mem_cq_qp_attr *memAttr, struct rdma_lite_device_mem_attr *memData,
    1031              :     unsigned int devId)
    1032              : {
    1033            0 :     if (gRoceUserOps.rsRoceInitMemPool == NULL) {
    1034              : #ifndef CA_CONFIG_LLT
    1035              :         hccp_err("rs_roce_init_mem_pool is null");
    1036              :         return -EINVAL;
    1037              : #endif
    1038              :     }
    1039            0 :     return gRoceUserOps.rsRoceInitMemPool(memAttr, memData, devId);
    1040              : }
    1041              : 
    1042            0 : int RsRoceDeinitMemPool(unsigned int memIdx)
    1043              : {
    1044            0 :     if (gRoceUserOps.rsRoceDeinitMemPool == NULL) {
    1045              : #ifndef CA_CONFIG_LLT
    1046              :         hccp_err("rs_roce_deinit_mem_pool is null");
    1047              :         return -EINVAL;
    1048              : #endif
    1049              :     }
    1050            0 :     return gRoceUserOps.rsRoceDeinitMemPool(memIdx);
    1051              : }
    1052              : 
    1053            0 : int RsRoceQueryQpc(struct ibv_qp *qp, struct hns_roce_qpc_attr_val *attrVal, unsigned int attrMask)
    1054              : {
    1055            0 :     if (gRoceUserOps.rsRoceQueryQpc == NULL) {
    1056              : #ifndef CA_CONFIG_LLT
    1057              :         hccp_err("rs_roce_query_qpc is null");
    1058              :         return -EINVAL;
    1059              : #endif
    1060              :     }
    1061            0 :     return gRoceUserOps.rsRoceQueryQpc(qp, attrVal, attrMask);
    1062              : }
    1063              : 
    1064            0 : struct ibv_ah *RsIbvExpCreateAh(struct ibv_pd *pd, struct ibv_exp_ah_attr *attrx)
    1065              : {
    1066            0 :     if (gRoceUserOps.rsIbvExpCreateAh == NULL) {
    1067              : #ifndef CA_CONFIG_LLT
    1068              :         hccp_err("rs_ibv_exp_create_ah is null");
    1069              :         return NULL;
    1070              : #endif
    1071              :     }
    1072            0 :     return gRoceUserOps.rsIbvExpCreateAh(pd, attrx);
    1073              : }
    1074              : 
    1075           31 : int RsRoceMmapAiDbReg(struct ibv_context *context, unsigned int tgid)
    1076              : {
    1077           31 :     if (gRoceUserOps.rsRoceMmapAiDbReg == NULL) {
    1078              : #ifndef CA_CONFIG_LLT
    1079              :         hccp_err("rs_roce_mmap_ai_db_reg is null");
    1080              :         return -EINVAL;
    1081              : #endif
    1082              :     }
    1083           31 :     return gRoceUserOps.rsRoceMmapAiDbReg(context, tgid);
    1084              : }
    1085              : 
    1086           30 : int RsRoceUnmmapAiDbReg(struct ibv_context *context)
    1087              : {
    1088           30 :     if (gRoceUserOps.rsRoceUnmmapAiDbReg == NULL) {
    1089              : #ifndef CA_CONFIG_LLT
    1090              :         hccp_err("rs_roce_unmmap_ai_db_reg is null");
    1091              :         return -EINVAL;
    1092              : #endif
    1093              :     }
    1094           30 :     return gRoceUserOps.rsRoceUnmmapAiDbReg(context);
    1095              : }
    1096              : 
    1097            8 : int RsRoceGetCqDataPlaneInfo(struct ibv_cq *cq, struct hns_roce_cq_data_plane_info *info)
    1098              : {
    1099            8 :     if (gRoceUserOps.rsRoceGetCqDataPlaneInfo == NULL) {
    1100              : #ifndef CA_CONFIG_LLT
    1101              :         hccp_err("rs_roce_get_cq_data_plane_info is null");
    1102              :         return -EINVAL;
    1103              : #endif
    1104              :     }
    1105            8 :     return gRoceUserOps.rsRoceGetCqDataPlaneInfo(cq, info);
    1106              : }
    1107              : 
    1108            4 : int RsRoceGetQpDataPlaneInfo(struct ibv_qp *qp, struct hns_roce_qp_data_plane_info *info)
    1109              : {
    1110            4 :     if (gRoceUserOps.rsRoceGetQpDataPlaneInfo == NULL) {
    1111              : #ifndef CA_CONFIG_LLT
    1112              :         hccp_err("rs_roce_get_qp_data_plane_info is null");
    1113              :         return -EINVAL;
    1114              : #endif
    1115              :     }
    1116            4 :     return gRoceUserOps.rsRoceGetQpDataPlaneInfo(qp, info);
    1117              : }
    1118              : 
    1119            0 : int RsRoceRemapMr(struct ibv_mr *mr, struct hns_roce_mr_remap_info info[], unsigned int num)
    1120              : {
    1121            0 :     if (gRoceUserOps.rsRoceRemapMr == NULL) {
    1122              : #ifndef CA_CONFIG_LLT
    1123              :         hccp_err("rs_roce_remap_mr is null");
    1124              :         return -EINVAL;
    1125              : #endif
    1126              :     }
    1127            0 :     return gRoceUserOps.rsRoceRemapMr(mr, info, num);
    1128              : }
    1129              : 
    1130            1 : unsigned int RsRoceGetApiVersion(void)
    1131              : {
    1132            1 :     if (gRoceUserOps.rsRoceGetApiVersion != NULL) {
    1133            1 :         return gRoceUserOps.rsRoceGetApiVersion();
    1134              :     }
    1135              : 
    1136            0 :     return 0;
    1137              : }
    1138              : 
    1139            1 : int RsRoceSetQpLbValue(struct ibv_qp *qp, int lbValue)
    1140              : {
    1141            1 :     if (gHrnOps.rsRoceSetQpLbValue == NULL) {
    1142            0 :         hccp_run_warn("rsRoceSetQpLbValue is null");
    1143            0 :         return -ENOTSUPP;
    1144              :     }
    1145            1 :     return gHrnOps.rsRoceSetQpLbValue(qp, lbValue);
    1146              : }
    1147              : 
    1148            2 : int RsRoceGetQpLbValue(struct ibv_qp *qp, int *lbValue)
    1149              : {
    1150            2 :     CHK_PRT_RETURN(lbValue == NULL, hccp_err("param error, lbValue is NULL"), -EINVAL);
    1151              : 
    1152            1 :     if (gHrnOps.rsRoceGetQpLbValue == NULL) {
    1153            0 :         *lbValue = 0;
    1154            0 :         return 0;
    1155              :     }
    1156            1 :     return gHrnOps.rsRoceGetQpLbValue(qp, lbValue);
    1157              : }
    1158              : 
    1159            2 : int RsRoceGetQpNum(struct ibv_context *context, int *qpNum)
    1160              : {
    1161            2 :     CHK_PRT_RETURN(qpNum == NULL, hccp_err("param error, qpNum is NULL"), -EINVAL);
    1162              : 
    1163            1 :     if (gHrnOps.rsRoceGetQpNum == NULL) {
    1164            0 :         *qpNum = 0;
    1165            0 :         return 0;
    1166              :     }
    1167            1 :     return gHrnOps.rsRoceGetQpNum(context, qpNum);
    1168              : }
        

Generated by: LCOV version 2.0-1