LCOV - code coverage report
Current view: top level - base_comm/resources/hccp/rdma_service/ctx - dl_ccu_function.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 42.6 % 47 20
Test Date: 2026-08-18 17:47:01 Functions: 50.0 % 12 6

            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 "hccp_dl.h"
      12              : #include "hccp_tlv.h"
      13              : #include "dl_ccu_function.h"
      14              : 
      15              : void *gCcuApiHandle = NULL;
      16              : #ifndef CA_CONFIG_LLT
      17              : struct RsCcuOps gCcuOps;
      18              : #else
      19              : struct RsCcuOps gCcuOps = {
      20              :     .rsCcuInit = ccu_init,
      21              :     .rsCcuUninit = ccu_uninit,
      22              :     .rsCcuCustomChannel = ccu_custom_channel,
      23              :     .rsCcuGetCqeBaseAddr = ccu_get_cqe_base_addr,
      24              :     .rsCcuGetMemInfo = ccu_get_mem_info,
      25              :     .rsCcuTlvRequest = ccu_tlv_request,
      26              : };
      27              : #endif
      28              : 
      29            1 : STATIC int RsCcuDeviceApiInit(void)
      30              : {
      31              : #ifndef CA_CONFIG_LLT
      32              :     gCcuOps.rsCcuInit = (int (*)(void))HccpDlsym(gCcuApiHandle, "ccu_init");
      33              :     DL_API_RET_IS_NULL_CHECK(gCcuOps.rsCcuInit, "ccu_init");
      34              : 
      35              :     gCcuOps.rsCcuUninit = (int (*)(void))HccpDlsym(gCcuApiHandle, "ccu_uninit");
      36              :     DL_API_RET_IS_NULL_CHECK(gCcuOps.rsCcuUninit, "ccu_uninit");
      37              : 
      38              :     gCcuOps.rsCcuCustomChannel = (int (*)(const struct channel_info_in *in,
      39              :         struct channel_info_out *out))HccpDlsym(gCcuApiHandle, "ccu_custom_channel");
      40              :     DL_API_RET_IS_NULL_CHECK(gCcuOps.rsCcuCustomChannel, "ccu_custom_channel");
      41              : 
      42              :     gCcuOps.rsCcuGetCqeBaseAddr = (unsigned long long (*)(unsigned int dieId))HccpDlsym(gCcuApiHandle,
      43              :         "ccu_get_cqe_base_addr");
      44              :     DL_API_RET_IS_NULL_CHECK(gCcuOps.rsCcuGetCqeBaseAddr, "ccu_get_cqe_base_addr");
      45              : 
      46              :     gCcuOps.rsCcuGetMemInfo = (int (*)(unsigned int dieId, unsigned long long memTypeBitmap,
      47              :         struct ccu_mem_rsp *rsp))HccpDlsym(gCcuApiHandle, "ccu_get_mem_info");
      48              :     DL_API_RET_IS_NULL_CHECK(gCcuOps.rsCcuGetMemInfo, "ccu_get_mem_info");
      49              : 
      50              :     gCcuOps.rsCcuTlvRequest = (int (*)(struct ccu_tlv_request_info *tlvRequestInfo))HccpDlsym(gCcuApiHandle,
      51              :         "ccu_tlv_request");
      52              :     DL_API_RET_IS_NULL_INFO(gCcuOps.rsCcuTlvRequest, "ccu_tlv_request");
      53              : #endif
      54            1 :     return 0;
      55              : }
      56              : 
      57            1 : STATIC int RsOpenCcuSo(void)
      58              : {
      59              : #ifndef CA_CONFIG_LLT
      60              :     if (gCcuApiHandle == NULL) {
      61              :         gCcuApiHandle = HccpDlopen("libccu-user-drv.so", RTLD_NOW);
      62              :         if (gCcuApiHandle != NULL) {
      63              :             return 0;
      64              :         }
      65              :         return -EINVAL;
      66              :     } else {
      67              :         hccp_run_info("ccu_api dlopen again!");
      68              :     }
      69              : #endif
      70            1 :     return 0;
      71              : }
      72              : 
      73            1 : STATIC void RsCloseCcuSo(void)
      74              : {
      75              : #ifndef CA_CONFIG_LLT
      76              :     if (gCcuApiHandle != NULL) {
      77              :         (void)HccpDlclose(gCcuApiHandle);
      78              :         gCcuApiHandle = NULL;
      79              :     }
      80              : #endif
      81            1 :     return;
      82              : }
      83              : 
      84            0 : int RsCcuApiInit(void)
      85              : {
      86              :     int ret;
      87              : 
      88            0 :     ret = RsOpenCcuSo();
      89            0 :     CHK_PRT_RETURN(ret,
      90              :         hccp_err("HccpDlopen[libccu-user-drv.so] failed! ret=[%d],"
      91              :                  "Please check ccu driver has been installed",
      92              :             ret),
      93              :         ret);
      94              : 
      95            0 :     ret = RsCcuDeviceApiInit();
      96            0 :     if (ret != 0) {
      97            0 :         hccp_err("[rs_ccu_device_api_init]HccpDlopen failed! ret=[%d]", ret);
      98            0 :         RsCloseCcuSo();
      99            0 :         return ret;
     100              :     }
     101            0 :     return 0;
     102              : }
     103              : 
     104            0 : void RsCcuApiDeinit(void)
     105              : {
     106            0 :     RsCloseCcuSo();
     107            0 :     return;
     108              : }
     109              : 
     110            0 : int RsCcuInit(void)
     111              : {
     112            0 :     if (gCcuApiHandle == NULL || gCcuOps.rsCcuInit == NULL) {
     113              : #ifndef CA_CONFIG_LLT
     114              :         hccp_err("g_ccu_api_handle is NULL or rs_ccu_init is NULL");
     115              :         return -EINVAL;
     116              : #endif
     117              :     }
     118            0 :     return gCcuOps.rsCcuInit();
     119              : }
     120              : 
     121            0 : int RsCcuCustomChannel(const struct channel_info_in *in, struct channel_info_out *out)
     122              : {
     123            0 :     if (gCcuApiHandle == NULL || gCcuOps.rsCcuCustomChannel == NULL) {
     124              : #ifndef CA_CONFIG_LLT
     125              :         hccp_err("g_ccu_api_handle is NULL or rs_ccu_custom_channel is NULL");
     126              :         return -EINVAL;
     127              : #endif
     128              :     }
     129            0 :     return gCcuOps.rsCcuCustomChannel(in, out);
     130              : }
     131              : 
     132            1 : int RsCcuGetCqeBaseAddr(unsigned int dieId, unsigned long long *cqeBaseAddr)
     133              : {
     134            1 :     if (gCcuApiHandle == NULL || gCcuOps.rsCcuGetCqeBaseAddr == NULL) {
     135              : #ifndef CA_CONFIG_LLT
     136              :         hccp_err("g_ccu_api_handle is NULL or rs_ccu_get_cqe_base_addr is NULL");
     137              :         return -EINVAL;
     138              : #endif
     139              :     }
     140            1 :     CHK_PRT_RETURN(cqeBaseAddr == NULL, hccp_err("cqe_base_addr is null, dieId:%u", dieId), -EINVAL);
     141            1 :     *cqeBaseAddr = gCcuOps.rsCcuGetCqeBaseAddr(dieId);
     142            1 :     return 0;
     143              : }
     144              : 
     145            0 : int RsCcuUninit(void)
     146              : {
     147            0 :     if (gCcuApiHandle == NULL || gCcuOps.rsCcuUninit == NULL) {
     148              : #ifndef CA_CONFIG_LLT
     149              :         hccp_err("g_ccu_api_handle is NULL or rs_ccu_uninit is NULL");
     150              :         return -EINVAL;
     151              : #endif
     152              :     }
     153            0 :     return gCcuOps.rsCcuUninit();
     154              : }
     155              : 
     156            0 : int RsCcuGetMemInfo(char *dataIn, char *dataOut, unsigned int *bufferSize)
     157              : {
     158            0 :     struct ccu_mem_rsp *rsp = (struct ccu_mem_rsp *)dataOut;
     159            0 :     struct CcuMemReq *memReq = (struct CcuMemReq *)dataIn;
     160              : 
     161            0 :     if (gCcuApiHandle == NULL || gCcuOps.rsCcuGetMemInfo == NULL) {
     162              : #ifndef CA_CONFIG_LLT
     163              :         hccp_err("g_ccu_api_handle is NULL or rsCcuGetMemInfo is NULL");
     164              :         return -EINVAL;
     165              : #endif
     166              :     }
     167            0 :     *bufferSize = sizeof(struct ccu_mem_rsp);
     168            0 :     return gCcuOps.rsCcuGetMemInfo(memReq->udieIdx, memReq->memTypeBitmap, rsp);
     169              : }
     170              : 
     171            1 : bool isCcuTlvReqExist(void)
     172              : {
     173            1 :     if (gCcuApiHandle == NULL || gCcuOps.rsCcuTlvRequest == NULL) {
     174              : #ifndef CA_CONFIG_LLT
     175              :         hccp_info("g_ccu_api_handle is NULL or rsCcuTlvRequest is NULL");
     176              :         return false;
     177              : #endif
     178              :     }
     179            1 :     return true;
     180              : }
     181              : 
     182            1 : int RsCcuTlvRequest(unsigned int type, char *dataIn, char *dataOut, unsigned int dataInlength,
     183              :     unsigned int *dataOutLength, unsigned int dataOutMaxLength)
     184              : {
     185            1 :     int ret = 0;
     186            1 :     struct ccu_tlv_request_info tlvRequestInfo = {
     187              :         .ccuMsg = type,
     188              :         .dataIn = dataIn,
     189              :         .dataInLength = dataInlength,
     190              :         .dataOut = dataOut,
     191              :         .dataOutMaxLength = dataOutMaxLength,
     192              :     };
     193            1 :     ret = gCcuOps.rsCcuTlvRequest(&tlvRequestInfo);
     194            1 :     *dataOutLength = tlvRequestInfo.dataOutLength;
     195            1 :     return ret;
     196              : }
        

Generated by: LCOV version 2.0-1