LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/ccu_device/ccu_comp/ccu_channel/ccu_pfe - ccu_pfe_mgr.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 88.7 % 62 55
Test Date: 2026-07-28 12:11:00 Functions: 100.0 % 5 5

            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 "ccu_pfe_mgr.h"
      12              : 
      13              : #include "hccp_ctx.h"
      14              : 
      15              : #include "ccu_res_specs.h"
      16              : #include "ccu_pfe_cfg_mgr.h"
      17              : #include "hcomm_adapter_hccp.h"
      18              : 
      19              : namespace hcomm {
      20              : 
      21           64 : inline PfeCtx BuildPfeCtx(const uint8_t dieId, const PfeJettyCtxCfg &cfg)
      22              : {
      23           64 :     struct PfeCtx ctx = {0};
      24           64 :     ctx.startJettyId = cfg.startTaJettyId;
      25           64 :     ctx.jettyNum = cfg.size - 1; // PFE给CCU分配的Jetty个数,配置硬件时需减1
      26           64 :     ctx.startLocalJettyCtxId = cfg.startJettyCtxId;
      27              : 
      28           64 :     HCCL_RUN_INFO("[CcuPfeMgr][%s]: dieId[%u] feId[%u], startJettyId[%u], jettyNum(-1)[%u], "
      29              :         "startLocalJettyCtxId[%u], pfe ctx size[%u]", __func__, dieId, cfg.feId,
      30              :         ctx.startJettyId, ctx.jettyNum, ctx.startLocalJettyCtxId, sizeof(PfeCtx));
      31           64 :     return ctx;
      32              : }
      33              : 
      34           64 : inline PfeJettyStrategy BuildStrategy(const PfeJettyCtxCfg &cfg)
      35              : {
      36           64 :     struct PfeJettyStrategy pfeJettyStrategy = {0};
      37           64 :     pfeJettyStrategy.feId  = cfg.feId;
      38           64 :     pfeJettyStrategy.pfeId = cfg.feId;
      39           64 :     pfeJettyStrategy.size  = cfg.size;
      40           64 :     pfeJettyStrategy.startTaJettyId = cfg.startTaJettyId;
      41           64 :     pfeJettyStrategy.startLocalJettyCtxId = cfg.startJettyCtxId;
      42           64 :     return pfeJettyStrategy;
      43              : }
      44              : 
      45           64 : static HcclResult ConfigPfeTable(const int32_t devLogicId, const uint32_t devPhyId, const uint8_t dieId, const uint32_t feId,
      46              :     const uint32_t pfeReservedNum, const PfeCtx &pfeCtx)
      47              : {
      48           64 :     if (UNLIKELY(feId > UINT32_MAX - static_cast<uint32_t>(dieId) * pfeReservedNum)) {
      49            0 :         HCCL_ERROR("[CcuPfeMgr][%s] failed, feId[%u] is greater than expected, "
      50              :             "pfeReservedNum[%u], will exceed the range of uint32_t, devLogicId[%d] devPhyId[%u], "
      51              :             "dieId[%u].", __func__, feId, pfeReservedNum, devLogicId, devPhyId, dieId);
      52            0 :         return HcclResult::HCCL_E_INTERNAL;
      53              :     }
      54              :     // die1 使用后半部分pfe表项,故根据pfe预留数量偏移
      55           64 :     const uint32_t pfeTableOffset = static_cast<uint32_t>(dieId) * pfeReservedNum + feId;
      56              : 
      57           64 :     CustomChannelInfoIn  inBuff{};
      58           64 :     CustomChannelInfoOut outBuff{};
      59           64 :     inBuff.op                          = CcuOpcodeType::CCU_U_OP_SET_PFE;
      60           64 :     inBuff.data.dataInfo.udieIdx       = static_cast<uint32_t>(dieId);
      61           64 :     inBuff.data.dataInfo.dataArraySize = 1;
      62           64 :     inBuff.data.dataInfo.dataLen       = sizeof(struct PfeCtx); // 单个8B
      63           64 :     inBuff.offsetStartIdx              = pfeTableOffset;
      64              : 
      65           64 :     (void)memcpy_s(inBuff.data.dataInfo.dataArray, inBuff.data.dataInfo.dataLen, &pfeCtx,
      66           64 :         inBuff.data.dataInfo.dataLen);
      67              : 
      68           64 :     auto ret = HccpRaTlvCcuCustomChannel(devLogicId,
      69              :         static_cast<void *>(&inBuff), static_cast<void *>(&outBuff));
      70           64 :     if (ret != HCCL_SUCCESS) {
      71            0 :         HCCL_ERROR("[CcuPfeMgr][%s] failed to call ccu driver, "
      72              :             "devLogicId[%d] devPhyId[%u] dieId[%d] op[%s] ret[%d].", __func__, devLogicId, devPhyId, dieId,
      73              :             "SET_PFE", ret);
      74            0 :         return ret;
      75              :     }
      76              :     
      77           64 :     return HcclResult::HCCL_SUCCESS;
      78              : }
      79              : 
      80           87 : HcclResult CcuPfeMgr::Init()
      81              : {
      82              :     std::vector<PfeJettyCtxCfg> cfgs =
      83           87 :         CcuPfeCfgMgr::GetInstance(devLogicId_).GetPfeJettyCtxCfg(dieId_);
      84           87 :     if (UNLIKELY(cfgs.empty())) { // 此处不中断流程,后续jettyCtx分配时会因无pfe配置报错停止
      85           23 :         HCCL_WARNING("[CcuJettyCtxMgr] config pfe table passed, pfe cfgs size is 0, "
      86              :             "devLogicId[%d], dieId[%u].", devLogicId_, dieId_);
      87           23 :         return HcclResult::HCCL_SUCCESS;
      88              :     }
      89              : 
      90           64 :     uint32_t pfeReservedNum = 0;
      91           64 :     (void)CcuResSpecifications::GetInstance(devLogicId_).GetPfeReservedNum(dieId_, pfeReservedNum);
      92           64 :     if (UNLIKELY(pfeReservedNum == 0)) { // 此处不中断流程,后续jettyCtx分配时会因无pfe配置报错停止
      93            0 :         HCCL_WARNING("[CcuPfeMgr] config pfe table passed, pfe reserved num is 0, "
      94              :             "devLogicId[%d], dieId[%u].", devLogicId_, dieId_);
      95            0 :         return HcclResult::HCCL_SUCCESS;
      96              :     }
      97              : 
      98          128 :     for (const auto &cfg : cfgs) {
      99              :         // 分配策略保证cfg中feId均为ccu可用设备
     100           64 :         const uint32_t feId = cfg.feId;
     101           64 :         const auto &iter = pfeJettyMap_.find(feId);
     102           64 :         if (iter != pfeJettyMap_.end()) {
     103            0 :             continue; // 跳过已配置pfe
     104              :         }
     105           64 :         pfeJettyMap_[feId] = BuildStrategy(cfg);
     106              : 
     107           64 :         const auto &pfeCtx = BuildPfeCtx(dieId_, cfg);
     108           64 :         CHK_RET(ConfigPfeTable(devLogicId_, devPhyId_, dieId_, feId, pfeReservedNum, pfeCtx));
     109              :     }
     110              : 
     111           64 :     return HcclResult::HCCL_SUCCESS;
     112           87 : }
     113              : 
     114           80 : HcclResult CcuPfeMgr::GetPfeStrategy(uint32_t feId, PfeJettyStrategy &pfeJettyStrategy) const
     115              : {
     116           80 :     const auto &iter = pfeJettyMap_.find(feId);
     117           80 :     if (iter == pfeJettyMap_.end()) {
     118            2 :         HCCL_ERROR("[CcuPfeMgr][%s] failed, feId[%u] is not found, "
     119              :             "devLogicId[%d], dieId[%u].", __func__, feId, devLogicId_, dieId_);
     120            2 :         return HCCL_E_NOT_FOUND;
     121              :     }
     122              : 
     123           78 :     pfeJettyStrategy = iter->second;
     124           78 :     HCCL_RUN_INFO("[CcuPfeMgr][%s] dieId[%u] feId[%u] pfeId[%u] size[%u] "
     125              :             "startTaJettyId[%u] startLocalJettyCtxId[%u]", __func__, dieId_,
     126              :             pfeJettyStrategy.feId, pfeJettyStrategy.pfeId, pfeJettyStrategy.size,
     127              :             pfeJettyStrategy.startTaJettyId, pfeJettyStrategy.startLocalJettyCtxId);  
     128              : 
     129           78 :     return HCCL_SUCCESS;
     130              : }
     131              : 
     132              : }; // Hccl
        

Generated by: LCOV version 2.0-1