LCOV - code coverage report
Current view: top level - base_comm/resources/hccp/rdma_service/tlv - dl_netco_function.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 58.3 % 36 21
Test Date: 2026-08-18 17:47:01 Functions: 60.0 % 10 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 <errno.h>
      12              : #include "hccp_dl.h"
      13              : #include "rs.h"
      14              : #include "dl_netco_function.h"
      15              : 
      16              : void *gNetcoApiHandle = NULL;
      17              : #ifndef CA_CONFIG_LLT
      18              : struct RsNetcoOps gNetcoOps;
      19              : #else
      20              : struct RsNetcoOps gNetcoOps = {
      21              :     .rsNetcoInit = NetCoInitFactory,
      22              :     .rsNetcoDeinit = NetCoDestruct,
      23              :     .rsNetcoEventDispatch = NetCoFdEventDispatch,
      24              :     .rsNetcoTblAddUpd = NetCoTblAddUpd,
      25              : };
      26              : #endif
      27              : 
      28            1 : STATIC int RsOpenLibnetCoSo(void)
      29              : {
      30              : #ifndef CA_CONFIG_LLT
      31              :     if (gNetcoApiHandle == NULL) {
      32              :         gNetcoApiHandle = HccpDlopen("libnet_co.so", RTLD_NOW);
      33              :         if (gNetcoApiHandle != NULL) {
      34              :             return 0;
      35              :         }
      36              :         hccp_err("HccpDlopen[libnet_co.so] failed! errno=%d, dlerror: %s", errno, dlerror());
      37              :         return -EINVAL;
      38              :     } else {
      39              :         hccp_run_info("netco_api dlopen again!");
      40              :     }
      41              : #endif
      42            1 :     return 0;
      43              : }
      44              : 
      45            1 : STATIC void RsCloseNetcoSo(void)
      46              : {
      47              : #ifndef CA_CONFIG_LLT
      48              :     if (gNetcoApiHandle != NULL) {
      49              :         (void)HccpDlclose(gNetcoApiHandle);
      50              :         gNetcoApiHandle = NULL;
      51              :     }
      52              : #endif
      53            1 :     return;
      54              : }
      55              : 
      56            0 : STATIC int RsNetcoTblApiInit(void)
      57              : {
      58              : #ifndef CA_CONFIG_LLT
      59              :     gNetcoOps.rsNetcoInit = (void *(*)(int, NetCoIpPortArg))HccpDlsym(gNetcoApiHandle, "NetCoInitFactory");
      60              :     DL_API_RET_IS_NULL_CHECK(gNetcoOps.rsNetcoInit, "NetCoInitFactory");
      61              : 
      62              :     gNetcoOps.rsNetcoDeinit = (void (*)(void *))HccpDlsym(gNetcoApiHandle, "NetCoDestruct");
      63              :     DL_API_RET_IS_NULL_CHECK(gNetcoOps.rsNetcoDeinit, "NetCoDestruct");
      64              : 
      65              :     gNetcoOps.rsNetcoEventDispatch = (unsigned int (*)(void *, int, unsigned int))HccpDlsym(gNetcoApiHandle,
      66              :         "NetCoFdEventDispatch");
      67              :     DL_API_RET_IS_NULL_CHECK(gNetcoOps.rsNetcoEventDispatch, "NetCoFdEventDispatch");
      68              : 
      69              :     gNetcoOps.rsNetcoTblAddUpd = (int (*)(void *, unsigned int, char *, unsigned int))HccpDlsym(gNetcoApiHandle,
      70              :         "NetCoTblAddUpd");
      71              :     DL_API_RET_IS_NULL_CHECK(gNetcoOps.rsNetcoTblAddUpd, "NetCoTblAddUpd");
      72              : #endif
      73            0 :     return 0;
      74              : }
      75              : 
      76            1 : STATIC int RsNetcoApiInit(void)
      77              : {
      78              :     int ret;
      79            1 :     ret = RsOpenLibnetCoSo();
      80            1 :     CHK_PRT_RETURN(ret != 0,
      81              :         hccp_err("HccpDlopen[libnet_co.so] failed! ret=[%d],"
      82              :                  "Please check network adapter driver has been installed",
      83              :             ret),
      84              :         ret);
      85              : 
      86            1 :     ret = RsNetcoTblApiInit();
      87            1 :     if (ret != 0) {
      88            1 :         hccp_err("[rs_netco_tbl_api_init]HccpDlopen failed! ret=[%d]", ret);
      89            1 :         RsCloseNetcoSo();
      90            1 :         return ret;
      91              :     }
      92              : 
      93            0 :     return 0;
      94              : }
      95              : 
      96            0 : int RsNslbApiInit(void)
      97              : {
      98              :     int ret;
      99              : 
     100            0 :     ret = RsNetcoApiInit();
     101            0 :     CHK_PRT_RETURN(ret, hccp_err("rs_netco_api_init failed! ret=[%d]", ret), ret);
     102              : 
     103            0 :     return 0;
     104              : }
     105              : 
     106            0 : void RsNslbApiDeinit(void)
     107              : {
     108            0 :     if (gNetcoApiHandle != NULL) {
     109            0 :         (void)HccpDlclose(gNetcoApiHandle);
     110            0 :         gNetcoApiHandle = NULL;
     111              :     }
     112            0 :     return;
     113              : }
     114              : 
     115            1 : void *RsNetcoInit(int epollfd, NetCoIpPortArg ipPortArg)
     116              : {
     117            1 :     if (gNetcoOps.rsNetcoInit == NULL) {
     118              : #ifndef CA_CONFIG_LLT
     119              :         hccp_err("rs_netco_init is null");
     120              :         return NULL;
     121              : #endif
     122              :     }
     123            1 :     return gNetcoOps.rsNetcoInit(epollfd, ipPortArg);
     124              : }
     125              : 
     126            0 : void RsNetcoDeinit(void *co)
     127              : {
     128            0 :     if (gNetcoOps.rsNetcoDeinit == NULL) {
     129              : #ifndef CA_CONFIG_LLT
     130              :         hccp_err("rs_netco_deinit is null");
     131              :         return;
     132              : #endif
     133              :     }
     134            0 :     return gNetcoOps.rsNetcoDeinit(co);
     135              : }
     136              : 
     137            1 : unsigned int RsNetcoEventDispatch(void *co, int fd, unsigned int curEvents)
     138              : {
     139            1 :     if (gNetcoOps.rsNetcoEventDispatch == NULL) {
     140              : #ifndef CA_CONFIG_LLT
     141              :         hccp_err("rs_netco_event_dispatch is null");
     142              :         return EINVAL;
     143              : #endif
     144              :     }
     145            1 :     return gNetcoOps.rsNetcoEventDispatch(co, fd, curEvents);
     146              : }
     147              : 
     148            1 : int RsNetcoTblAddUpd(void *netcoHandle, unsigned int type, char *data, unsigned int dataLen)
     149              : {
     150            1 :     if (gNetcoOps.rsNetcoTblAddUpd == NULL) {
     151              : #ifndef CA_CONFIG_LLT
     152              :         hccp_err("rs_netco_tbl_add_upd is null, type(%u)", type);
     153              :         return -EINVAL;
     154              : #endif
     155              :     }
     156            1 :     return gNetcoOps.rsNetcoTblAddUpd(netcoHandle, type, data, dataLen);
     157              : }
        

Generated by: LCOV version 2.0-1