LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/ccu_transport - ccu_conn.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 2 2
Test Date: 2026-08-18 17:47:01 Functions: 41.7 % 12 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              : #ifndef CCU_CONN_H
      12              : #define CCU_CONN_H
      13              : 
      14              : #include "env_config.h"
      15              : #include "tp_mgr.h"
      16              : #include "ccu_jetty_.h"
      17              : #include "ccu_dev_mgr_imp.h"
      18              : #include "hcomm_adapter_hccp.h"
      19              : 
      20              : namespace hcomm {
      21              : 
      22          132 : MAKE_ENUM(
      23              :     CcuConnStatus,
      24              :     INIT,          // 初始化
      25              :     EXCHANGEABLE,  // 可与对端交换
      26              :     CONNECTED,     // 建链完成
      27              :     CONN_INVALID); // 链接错误
      28              : 
      29              : class CcuConnection {
      30              : public:
      31              :     CcuConnection(
      32              :         const CommAddr& locAddr, const CommAddr& rmtAddr, const CcuChannelInfo& channelInfo,
      33              :         const std::vector<CcuJetty*>& ccuJettys, uint32_t qos);
      34              :     CcuConnection(const CcuConnection& that) = delete;
      35              :     CcuConnection& operator=(const CcuConnection& other) = delete;
      36              :     ~CcuConnection();
      37              : 
      38              :     // 用于建链过程CcuTransport调用
      39              :     HcclResult Init();
      40              :     CcuConnStatus GetStatus();
      41              :     HcclResult Serialize(std::vector<char>& dtoData);
      42              :     HcclResult Deserialize(const std::vector<char>& dtoData);
      43              :     HcclResult ImportJetty();
      44              :     HcclResult Clean();
      45              : 
      46              :     uint32_t GetChannelId() const;
      47              :     uint32_t GetDieId() const;
      48              :     int32_t GetDevLogicId() const;
      49              :     uint64_t GetRmtCcuBufAddr() const;
      50              :     uint32_t GetRmtCcuBufTokenId() const;
      51              :     uint32_t GetRmtCcuBufTokenValue() const;
      52              :     HcclResult Describe(std::string& dfxMsg);
      53              : 
      54              : protected:
      55              :     TpProtocol tpProtocol_{TpProtocol::INVALID};
      56              : 
      57              : private:
      58           85 :     MAKE_ENUM(
      59              :         InnerStatus, INIT, TP_INFO_GETTING, TP_ATTR_GETTING, JETTY_CREATING, EXCHANGEABLE, JETTY_IMPORTING, CONNECTED,
      60              :         CONN_INVALID);
      61              : 
      62              :     struct ImportJettyCtx {
      63              :         // 保存对端的key,传递数据结构时不需要整个copy
      64              :         u8 remoteQpKey[HRT_UB_QP_KEY_MAX_LEN]{0};
      65              :         HccpUbJettyImportedInParam inParam{};
      66              :         HrtRaUbJettyImportedOutParam outParam{};
      67              :     };
      68              : 
      69              : private:
      70              :     HcclResult StatusMachine();
      71              :     HcclResult UpdateInitStatus();
      72              :     HcclResult UpdateExchangeStatus();
      73              : 
      74              :     HcclResult GetLocalCcuRmaBufferInfo();
      75              :     HcclResult CreateJetty();
      76              :     HcclResult GetTpInfo();
      77              :     HcclResult GetTpAttr();
      78              :     HcclResult GetTaTimeOut();
      79              :     GetTpInfoParam MakeGetTpInfoParam() const;
      80              :     void GenerateLocalPsn();
      81              :     void ResetRequestCtxs();
      82              :     HcclResult StartImportJettyRequest(uint32_t jettyIndex, RequestHandle& reqHandle);
      83              :     HcclResult CheckRequestResults();
      84              :     HcclResult ConfigChannel();
      85              :     HcclResult ReleaseConnRes();
      86              :     HcclResult ReturnErrorStatus(const std::string& funcName);
      87              :     std::string Describe();
      88              : 
      89              : private:
      90              :     CcuConnStatus status_{CcuConnStatus::CONN_INVALID};
      91              :     InnerStatus innerStatus_{InnerStatus::CONN_INVALID};
      92              :     bool isJettyCreated_{false};
      93              :     bool isJettyImported_{false};
      94              : 
      95              :     CommAddr locAddr_{};
      96              :     CommAddr rmtAddr_{};
      97              :     CcuChannelInfo channelInfo_{};
      98              :     std::vector<CcuJetty*> ccuJettys_;
      99              :     uint32_t qos_{EnvConfig::UB_QOS_DEFAULT};
     100              : 
     101              :     int32_t devLogicId_{0};
     102              :     uint32_t devPhyId_{0};
     103              :     uint32_t dieId_{0};
     104              :     uint32_t funcId_{0};
     105              :     CtxHandle ctxHandle_{nullptr};
     106              :     uint32_t jettyNum_{0};
     107              : 
     108              :     // 通过ccu comp 获取 ccu buffer信息
     109              :     uint64_t ccuBufAddr_{0};
     110              :     uint32_t ccuBufTokenId_{0};
     111              :     uint32_t ccuBufTokenValue_{0};
     112              : 
     113              :     std::vector<ImportJettyCtx> importJettyCtxs_; // 记录import jetty相关信息
     114              :     JettyImportCfg jettyImportCfg_{};             // import配置信息,因复用TpHandle只需一份
     115              : 
     116              :     // 交换后获取对端ccu buffer信息
     117              :     uint64_t rmtCcuBufAddr_{0};
     118              :     uint32_t rmtCcuBufTokenId_{0};
     119              :     uint32_t rmtCcuBufTokenValue_{0};
     120              : 
     121              :     // 感知tp获取tp handle,import jetty后urma提供tpn
     122              :     TpInfo tpInfo_{};
     123              :     TpAttrInfo tpAttrInfo_{};
     124              : 
     125              :     // 异步import上下文信息
     126              :     std::vector<RequestHandle> reqHandles_;
     127              :     std::vector<std::vector<char>> reqDataBuffers_;
     128              :     std::vector<void*> remoteJettyHandlePtrs_;
     129              : 
     130              :     u8 errTimeout_{8};
     131              : 
     132              :     HcclResult CalcTotalTimeout(CtxHandle ctxHandle, TpHandle tpHandle, uint32_t& outTotalTimeoutMs);
     133              : };
     134              : 
     135              : class CcuRtpConnection : public CcuConnection {
     136              : public:
     137              :     CcuRtpConnection(
     138              :         const CommAddr& locAddr, const CommAddr& rmtAddr, const CcuChannelInfo& channelInfo,
     139              :         const std::vector<CcuJetty*>& ccuJettys, uint32_t qos);
     140              : };
     141              : 
     142              : class CcuCtpConnection : public CcuConnection {
     143              : public:
     144              :     CcuCtpConnection(
     145              :         const CommAddr& locAddr, const CommAddr& rmtAddr, const CcuChannelInfo& channelInfo,
     146              :         const std::vector<CcuJetty*>& ccuJettys, uint32_t qos);
     147              : };
     148              : 
     149              : } // namespace hcomm
     150              : 
     151              : #endif // CCU_CONN_H
        

Generated by: LCOV version 2.0-1