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

Generated by: LCOV version 2.0-1