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