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 "hcomm_adapter_hccp.h"
12 :
13 : #include "log.h"
14 : #include "orion_adpt_utils.h"
15 : #include "hccp_tlv.h"
16 : #include "hccp_common.h"
17 :
18 : #include "hccp_async.h"
19 : #include "hccp_async_ctx.h"
20 : #include "enum_factory.h"
21 :
22 : #include "hccp_tlv_hdc_manager.h"
23 : #include "exception_handler.h"
24 :
25 : namespace hcomm {
26 :
27 200 : HcclResult IpAddressToHccpEid(const Hccl::IpAddress &ipAddr, Eid &eid)
28 : {
29 200 : HCCL_INFO("EID ipAddr[%s]", ipAddr.Describe().c_str());
30 200 : int32_t sRet = memcpy_s(eid.raw, sizeof(eid.raw), ipAddr.GetEid().raw, sizeof(ipAddr.GetEid().raw));
31 200 : if (sRet != EOK) {
32 0 : HCCL_ERROR("[%s] memcpy failed[%d].", __func__, sRet);
33 0 : return HcclResult::HCCL_E_MEMORY;
34 : }
35 200 : HCCL_INFO("[IpAddressToHccpEid] hccpEid.in6.subnetPrefix[%016llx], hccpEid.in6.interfaceId[%016llx]",
36 : eid.in6.subnetPrefix, eid.in6.interfaceId);
37 200 : return HcclResult::HCCL_SUCCESS;
38 : }
39 :
40 0 : HcclResult IpAddressToReverseHccpEid(const Hccl::IpAddress &ipAddr, Eid &eid)
41 : {
42 0 : HCCL_INFO("EID ipAddr[%s]", ipAddr.Describe().c_str());
43 0 : int32_t sRet = memcpy_s(eid.raw, sizeof(eid.raw),
44 0 : ipAddr.GetReverseEid().raw, sizeof(ipAddr.GetReverseEid().raw));
45 0 : if (sRet != EOK) {
46 0 : HCCL_ERROR("[%s] memcpy failed[%d].", __func__, sRet);
47 0 : return HcclResult::HCCL_E_MEMORY;
48 : }
49 0 : HCCL_INFO("[IpAddressToHccpEid] hccpEid.in6.subnetPrefix[%016llx], hccpEid.in6.interfaceId[%016llx]",
50 : eid.in6.subnetPrefix, eid.in6.interfaceId);
51 0 : return HcclResult::HCCL_SUCCESS;
52 : }
53 :
54 64 : HcclResult IpAddressToReverseHcclEid(const Hccl::IpAddress &ipAddr, Hccl::Eid &eid)
55 : {
56 64 : HCCL_INFO("EID ipAddr[%s]", ipAddr.Describe().c_str());
57 64 : int32_t sRet = memcpy_s(eid.raw, sizeof(eid.raw),
58 64 : ipAddr.GetReverseEid().raw, sizeof(ipAddr.GetReverseEid().raw));
59 64 : if (sRet != EOK) {
60 0 : HCCL_ERROR("[%s] memcpy failed[%d].", __func__, sRet);
61 0 : return HcclResult::HCCL_E_MEMORY;
62 : }
63 64 : HCCL_INFO("[IpAddressToHccpEid] hccpEid.in6.subnetPrefix[%016llx], hccpEid.in6.interfaceId[%016llx]",
64 : eid.in6.subnetPrefix, eid.in6.interfaceId);
65 64 : return HcclResult::HCCL_SUCCESS;
66 : }
67 :
68 39 : inline Hccl::IpAddress HccpEidToIpAddress(Eid& hccpEid)
69 : {
70 39 : Hccl::Eid eid{};
71 39 : HCCL_INFO("[HccpEidToIpAddress] hccpEid.in6.subnetPrefix[%016llx], hccpEid.in6.interfaceId[%016llx]",
72 : hccpEid.in6.subnetPrefix, hccpEid.in6.interfaceId);
73 39 : s32 sRet = memcpy_s(eid.raw, sizeof(eid.raw), hccpEid.raw, sizeof(hccpEid.raw));
74 39 : if (sRet != EOK) {
75 0 : HCCL_ERROR("failed to change eid to ip");
76 0 : return Hccl::IpAddress{}; // 暂时不处理
77 : }
78 39 : return Hccl::IpAddress(eid);
79 : }
80 :
81 13 : HcclResult RaGetDevEidInfos(const RaInfo &raInfo, std::vector<DevEidInfo> &devEidInfos)
82 : {
83 13 : uint32_t num = 0;
84 26 : int32_t ret = RaGetDevEidInfoNum(raInfo, &num);
85 13 : if (ret != 0) {
86 0 : HCCL_ERROR("call RaGetDevEidInfoNum failed, error code =%d.", ret);
87 0 : return HcclResult::HCCL_E_NETWORK;
88 : }
89 :
90 52 : struct HccpDevEidInfo infoList[num] = {};
91 13 : ret = RaGetDevEidInfoList(raInfo, infoList, &num);
92 13 : if (ret != 0) {
93 0 : HCCL_ERROR("call RaGetDevEidInfoList failed, error code =%d.", ret);
94 0 : return HcclResult::HCCL_E_NETWORK;
95 : }
96 :
97 13 : devEidInfos.resize(num);
98 52 : for (uint32_t i = 0; i < num; i++) {
99 39 : devEidInfos[i].name = (infoList[i].name);
100 39 : Hccl::IpAddress ipAddr = HccpEidToIpAddress(infoList[i].eid);
101 39 : CHK_RET(IpAddressToCommAddr(ipAddr, devEidInfos[i].commAddr));
102 39 : devEidInfos[i].type = infoList[i].type;
103 39 : devEidInfos[i].eidIndex = infoList[i].eidIndex;
104 39 : devEidInfos[i].dieId = infoList[i].dieId;
105 39 : devEidInfos[i].chipId = infoList[i].chipId;
106 39 : devEidInfos[i].funcId = infoList[i].funcId;
107 : }
108 :
109 13 : return HcclResult::HCCL_SUCCESS;
110 13 : }
111 :
112 211 : RequestResult HccpGetAsyncReqResult(RequestHandle &reqHandle)
113 : {
114 211 : if (reqHandle == 0) {
115 0 : HCCL_ERROR("[%s] failed, reqHandle is 0.", __func__);
116 0 : return RequestResult::INVALID_PARA;
117 : }
118 :
119 211 : int reqResult = 0;
120 211 : int32_t ret = RaGetAsyncReqResult(reinterpret_cast<void *>(reqHandle), &reqResult);
121 : // 返回 OTHERS_EAGAIN 代表查询到异步任务未完成,需要重新查询,此时保留handle
122 211 : if (ret == OTHERS_EAGAIN) {
123 0 : return RequestResult::NOT_COMPLETED;
124 : }
125 :
126 : // 返回码非0代表调用查询接口失败,当前仅入参错误时触发
127 211 : if (ret != 0) {
128 0 : HCCL_ERROR("[%s] failed to get asynchronous request result[%d], "
129 : "reqhandle[%llx].", __func__, ret, reqHandle);
130 0 : return RequestResult::GET_REQ_RESULT_FAILED;
131 : }
132 :
133 211 : RequestHandle tmpReqHandle = reqHandle;
134 : // 返回码为 0 时,reqResult为异步任务完成结果,0代表成功,其他值代表失败
135 : // SOCK_EAGAIN 为 socket 类执行结果,代表 socket 接口失败需要重试
136 211 : if (reqResult == SOCK_EAGAIN) {
137 0 : return RequestResult::SOCK_E_AGAIN;
138 : }
139 :
140 211 : if (reqResult != 0) {
141 0 : HCCL_ERROR("[%s] failed, the asynchronous request "
142 : "error[%d], reqhandle[%llx].", __func__, reqResult, tmpReqHandle);
143 0 : return RequestResult::ASYNC_REQUEST_FAILED;
144 : }
145 :
146 211 : return RequestResult::COMPLETED;
147 : }
148 :
149 : const std::map<HrtTransportMode, TransportModeT> HRT_TRANSPORT_MODE_MAP
150 : = {{HrtTransportMode::RM, TransportModeT::CONN_RM}};
151 : const std::map<HrtJettyMode, JettyMode> HRT_JETTY_MODE_MAP
152 : = {{HrtJettyMode::STANDARD, JettyMode::JETTY_MODE_URMA_NORMAL},
153 : {HrtJettyMode::HOST_OFFLOAD, JettyMode::JETTY_MODE_USER_CTL_NORMAL},
154 : {HrtJettyMode::HOST_OPBASE, JettyMode::JETTY_MODE_USER_CTL_NORMAL},
155 : {HrtJettyMode::DEV_USED, JettyMode::JETTY_MODE_USER_CTL_NORMAL},
156 : {HrtJettyMode::CACHE_LOCK_DWQE, JettyMode::JETTY_MODE_CACHE_LOCK_DWQE},
157 : {HrtJettyMode::CCU_CCUM_CACHE, JettyMode::JETTY_MODE_CCU},
158 : {HrtJettyMode::CCU_TA_CACHE, JettyMode::JETTY_MODE_CCU_TA_CACHE}};
159 :
160 : constexpr uint8_t RNR_RETRY = 7;
161 : constexpr uint32_t RQ_DEPTH = 256;
162 :
163 64 : HcclResult HccpUbCreateJetty(const CtxHandle ctxHandle, const HrtRaUbCreateJettyParam &in, HrtRaUbJettyCreatedOutParam &out)
164 : {
165 64 : struct QpCreateAttr attr{};
166 64 : attr.scqHandle = reinterpret_cast<void *>(in.sjfcHandle);
167 64 : attr.rcqHandle = reinterpret_cast<void *>(in.rjfcHandle);
168 64 : attr.srqHandle = reinterpret_cast<void *>(in.sjfcHandle);
169 64 : attr.rqDepth = RQ_DEPTH;
170 64 : attr.sqDepth = in.sqDepth;
171 64 : attr.transportMode = HRT_TRANSPORT_MODE_MAP.at(in.transMode);
172 64 : attr.ub.mode = HRT_JETTY_MODE_MAP.at(in.jettyMode);
173 :
174 64 : attr.ub.tokenValue = in.tokenValue;
175 64 : attr.ub.tokenIdHandle = reinterpret_cast<void *>(in.tokenIdHandle);
176 64 : attr.ub.flag.value = 0;
177 : /* errTime配置值:0-31
178 : 0-7代表芯片配置值b00:512ms
179 : 8-15代表芯片配置值b01:1s
180 : 16-23代表芯片配置值b10:8s
181 : 24-31代表芯片配置值b11:32s
182 : */
183 64 : attr.ub.errTimeout = in.errTimeout;
184 64 : attr.ub.priority = static_cast<uint8_t>(in.qos & 0xFU);
185 64 : attr.ub.rnrRetry = RNR_RETRY;
186 64 : attr.ub.flag.bs.shareJfr = 1;
187 64 : attr.ub.jettyId = in.jettyId;
188 : // 在continue模式下+配置了wqe的fence标记,并且远端有一些权限校验错误/内存异常错误,硬件会直接挂死
189 : // jfs_flag 的 error_suspend 设置为 1,
190 64 : attr.ub.jfsFlag.bs.errorSuspend = 1;
191 :
192 64 : if (in.jettyMode == HrtJettyMode::CCU_TA_CACHE) {
193 4 : attr.ub.tokenValue = in.tokenValue;
194 4 : attr.ub.taCacheMode.lockFlag = true;
195 4 : attr.ub.taCacheMode.sqeBufIdx = in.sqeBufIndex;
196 : } else {
197 60 : attr.ub.extMode.sqebbNum = in.sqDepth;
198 : }
199 :
200 64 : if (in.jettyMode == HrtJettyMode::HOST_OFFLOAD) {
201 0 : attr.ub.extMode.piType = 1;
202 64 : } else if (in.jettyMode == HrtJettyMode::CCU_CCUM_CACHE) {
203 60 : attr.ub.tokenValue = in.tokenValue;
204 60 : attr.ub.extMode.cstmFlag.bs.sqCstm = 1;
205 60 : attr.ub.extMode.sq.buffSize = in.sqBufSize;
206 60 : attr.ub.extMode.sq.buffVa = in.sqBufVa;
207 4 : } else if (in.jettyMode == HrtJettyMode::DEV_USED) {
208 0 : attr.ub.extMode.cstmFlag.bs.sqCstm = 1;
209 0 : attr.ub.extMode.sq.buffSize = in.sqBufSize;
210 0 : attr.ub.extMode.sq.buffVa = in.sqBufVa;
211 : }
212 :
213 : // 其他Mode暂时不需要额外更新特定字段
214 64 : HCCL_INFO("Create jetty, input params: attr.ub.jettyId[%u], attr.rqDepth[%u], "
215 : "attr.sqDepth[%u], attr.transportMode[%d], attr.ub.mode[%d], "
216 : "attr.ub.extMode.sqebbNum[%u], attr.ub.extMode.sq.buffVa[%llx], "
217 : "attr.ub.extMode.sq.buffSize[%u], attr.ub.extMode.piType[%u], "
218 : "attr.ub.priority[%u], timeout[%u], attr.ub.taCacheMode.sqeBufIdx[%u].",
219 : attr.ub.jettyId, attr.rqDepth, attr.sqDepth, attr.transportMode,
220 : attr.ub.mode, attr.ub.extMode.sqebbNum, attr.ub.extMode.sq.buffVa,
221 : attr.ub.extMode.sq.buffSize, attr.ub.extMode.piType,
222 : attr.ub.priority, attr.ub.errTimeout, attr.ub.taCacheMode.sqeBufIdx);
223 :
224 64 : struct QpCreateInfo info {};
225 64 : void *qpHandle = nullptr;
226 64 : int32_t ret = RaCtxQpCreate(ctxHandle, &attr, &info, &qpHandle);
227 64 : if (ret != 0) {
228 0 : HCCL_ERROR("[%s] failed, ctxHandle[%p] jetty_id[%u] JettyMode[%s] "
229 : "sqDepth[%u] sq.buffVa[%llx] sq.buffSize[%u].", __func__,
230 : ctxHandle, attr.ub.jettyId, in.jettyMode.Describe().c_str(),
231 : attr.sqDepth, attr.ub.extMode.sq.buffVa,
232 : attr.ub.extMode.sq.buffSize);
233 0 : return HcclResult::HCCL_E_NETWORK;
234 : }
235 :
236 : // 适配URMA,直接组装WQE的TOKENID需要进行移位,包括CCU与AICPU
237 64 : constexpr u32 URMA_TOKEN_ID_RIGHT_SHIFT = 8;
238 :
239 64 : out.handle = reinterpret_cast<JettyHandle>(qpHandle);
240 64 : out.id = info.ub.id;
241 64 : out.uasid = info.ub.uasid;
242 64 : out.jettyVa = info.va;
243 64 : out.dbVa = info.ub.dbAddr;
244 64 : out.dbTokenId = info.ub.dbTokenId >> URMA_TOKEN_ID_RIGHT_SHIFT;
245 :
246 64 : int32_t sRet = memcpy_s(out.key, sizeof(out.key), info.key.value, info.key.size);
247 64 : if (sRet != 0) {
248 0 : HCCL_ERROR("[%s] failed, memcpy failed[%d].", __func__, sRet);
249 0 : return HcclResult::HCCL_E_MEMORY;
250 : }
251 64 : out.keySize = info.key.size;
252 64 : attr.ub.tokenValue = 0; // 清理栈中的敏感信息
253 64 : HCCL_INFO("[%s], output params: out.id[%u], out.dbVa[%llx]", __func__, out.id, out.dbVa);
254 :
255 64 : return HcclResult::HCCL_SUCCESS;
256 : }
257 :
258 0 : HcclResult HccpUbCreateJettyAsync(const CtxHandle ctxhandle, const HrtRaUbCreateJettyParam &in,
259 : std::vector<char> &out, void *&jettyHandle, RequestHandle &reqHandle)
260 : {
261 0 : struct QpCreateAttr attr {};
262 0 : attr.scqHandle = reinterpret_cast<void *>(in.sjfcHandle);
263 0 : attr.rcqHandle = reinterpret_cast<void *>(in.rjfcHandle);
264 0 : attr.srqHandle = reinterpret_cast<void *>(in.sjfcHandle);
265 0 : attr.rqDepth = RQ_DEPTH;
266 0 : attr.sqDepth = in.sqDepth;
267 0 : attr.transportMode = HRT_TRANSPORT_MODE_MAP.at(in.transMode);
268 0 : attr.ub.mode = HRT_JETTY_MODE_MAP.at(in.jettyMode);
269 :
270 0 : attr.ub.tokenValue = in.tokenValue;
271 0 : attr.ub.tokenIdHandle = reinterpret_cast<void *>(in.tokenIdHandle);
272 0 : attr.ub.flag.value = 0;
273 : /* errTime配置值:0-31
274 : 0-7代表芯片配置值b00:128ms
275 : 8-15代表芯片配置值b01:1s
276 : 16-23代表芯片配置值b10:8s
277 : 24-31代表芯片配置值b11:64s
278 : */
279 0 : attr.ub.errTimeout = in.errTimeout;
280 0 : attr.ub.priority = static_cast<uint8_t>(in.qos & 0xFU);
281 0 : attr.ub.rnrRetry = RNR_RETRY;
282 0 : attr.ub.flag.bs.shareJfr = 1;
283 0 : attr.ub.jettyId = in.jettyId;
284 : // 在continue模式下+配置了wqe的fence标记,并且远端有一些权限校验错误/内存异常错误,硬件会直接挂死
285 : // jfs_flag 的 error_suspend 设置为 1,
286 0 : attr.ub.jfsFlag.bs.errorSuspend = 1;
287 :
288 0 : if (in.jettyMode == HrtJettyMode::CCU_TA_CACHE) {
289 0 : attr.ub.tokenValue = in.tokenValue;
290 0 : attr.ub.taCacheMode.lockFlag = true;
291 0 : attr.ub.taCacheMode.sqeBufIdx = in.sqeBufIndex;
292 : } else {
293 0 : attr.ub.extMode.sqebbNum = in.sqDepth;
294 : }
295 :
296 0 : if (in.jettyMode == HrtJettyMode::HOST_OFFLOAD) {
297 0 : attr.ub.extMode.piType = 1;
298 0 : } else if (in.jettyMode == HrtJettyMode::CCU_CCUM_CACHE) {
299 0 : attr.ub.tokenValue = in.tokenValue;
300 0 : attr.ub.extMode.cstmFlag.bs.sqCstm = 1;
301 0 : attr.ub.extMode.sq.buffSize = in.sqBufSize;
302 0 : attr.ub.extMode.sq.buffVa = in.sqBufVa;
303 0 : } else if (in.jettyMode == HrtJettyMode::DEV_USED) {
304 0 : attr.ub.extMode.cstmFlag.bs.sqCstm = 1;
305 0 : attr.ub.extMode.sq.buffSize = in.sqBufSize;
306 0 : attr.ub.extMode.sq.buffVa = in.sqBufVa;
307 : }
308 :
309 : // 其他Mode暂时不需要额外更新特定字段
310 0 : HCCL_INFO("Create jetty, input params: attr.ub.jettyId[%u], attr.rqDepth[%u], "
311 : "attr.sqDepth[%u], attr.transportMode[%d], attr.ub.mode[%d], "
312 : "attr.ub.extMode.sqebbNum[%u], attr.ub.extMode.sq.buffVa[%llx], "
313 : "attr.ub.extMode.sq.buffSize[%u], attr.ub.extMode.piType[%u], "
314 : "attr.ub.priority[%u], timeout[%u], attr.ub.taCacheMode.sqeBufIdx[%u].",
315 : attr.ub.jettyId, attr.rqDepth, attr.sqDepth, attr.transportMode, attr.ub.mode,
316 : attr.ub.extMode.sqebbNum, attr.ub.extMode.sq.buffVa, attr.ub.extMode.sq.buffSize,
317 : attr.ub.extMode.piType, attr.ub.priority, attr.ub.errTimeout,
318 : attr.ub.taCacheMode.sqeBufIdx);
319 :
320 0 : void *raReqHandle = nullptr;
321 0 : out.resize(sizeof(QpCreateInfo));
322 0 : s32 ret = RaCtxQpCreateAsync(ctxhandle, &attr, reinterpret_cast<QpCreateInfo *>(out.data()),
323 : &jettyHandle, &raReqHandle);
324 0 : if (ret != 0 || !raReqHandle) {
325 0 : HCCL_ERROR("[%s] failed, call interface error[%d], raReqHandle[%p], "
326 : "ctxHanlde[%p].", __func__, ret, raReqHandle, ctxhandle);
327 0 : return HcclResult::HCCL_E_NETWORK;
328 : }
329 0 : attr.ub.tokenValue = 0; // 清理栈中的token信息
330 0 : HCCL_INFO("[%s] ok, get handle[%llu].", __func__, reinterpret_cast<RequestHandle>(raReqHandle));
331 0 : reqHandle = reinterpret_cast<RequestHandle>(raReqHandle);
332 0 : return HcclResult::HCCL_SUCCESS;
333 : }
334 :
335 64 : static HcclResult ImportJetty(const CtxHandle ctxHandle, u8 *key,
336 : const u32 keyLen, const u32 tokenValue, const JettyImportExpCfg &cfg,
337 : const JettyImportMode mode, const TpProtocol protocol,
338 : HrtRaUbJettyImportedOutParam &out)
339 : {
340 64 : if (mode == JettyImportMode::JETTY_IMPORT_MODE_NORMAL) {
341 0 : HCCL_ERROR("[%s] currently not support JETTY_IMPORT_MODE_NORMAL.",
342 : __func__);
343 0 : return HcclResult::HCCL_E_NOT_SUPPORT;
344 : }
345 :
346 64 : if (protocol != TpProtocol::RTP && protocol != TpProtocol::CTP) {
347 0 : HCCL_ERROR("[%s] failed, tp protocol[%s] is not expected.",
348 : __func__, protocol.Describe().c_str());
349 0 : return HcclResult::HCCL_E_NOT_SUPPORT;
350 : }
351 :
352 64 : struct QpImportInfoT info {};
353 64 : int res = memcpy_s(info.in.key.value, sizeof(info.in.key.value), key, keyLen);
354 64 : if (res != 0) {
355 0 : HCCL_ERROR("[%s] memcpy_s failed, ret = %d", __func__, res);
356 0 : return HcclResult::HCCL_E_MEMORY;
357 : }
358 64 : info.in.key.size = keyLen;
359 :
360 64 : info.in.ub.mode = mode;
361 64 : info.in.ub.tokenValue = tokenValue;
362 64 : info.in.ub.policy = JettyGrpPolicy::JETTY_GRP_POLICY_RR;
363 64 : info.in.ub.type = TargetType::TARGET_TYPE_JETTY;
364 :
365 64 : info.in.ub.flag.value = 0;
366 64 : info.in.ub.flag.bs.tokenPolicy = TOKEN_POLICY_PLAIN_TEXT;
367 :
368 64 : info.in.ub.expImportCfg = cfg;
369 : // tp_type: 0->RTP, 1->CTP
370 64 : info.in.ub.tpType = protocol == TpProtocol::RTP ? 0 : 1;
371 :
372 64 : void *remQpHandle = nullptr;
373 64 : int32_t ret = RaCtxQpImport(ctxHandle, &info, &remQpHandle);
374 64 : if (ret != 0) {
375 0 : HCCL_ERROR("[%s] failed, ctxHandle[%p] loc tp handle[%llx] "
376 : "rmt tp handle[%llx] loc tag[%llu] loc psn[%u] rmt psn[%u]"
377 : "protocol[%s].", __func__, ctxHandle, cfg.tpHandle, cfg.peerTpHandle,
378 : cfg.tag, cfg.txPsn, cfg.rxPsn, protocol.Describe().c_str());
379 0 : return HcclResult::HCCL_E_NETWORK;
380 : }
381 :
382 64 : out.handle = reinterpret_cast<TargetJettyHandle>(remQpHandle);
383 64 : out.targetJettyVa = info.out.ub.tjettyHandle;
384 64 : out.tpn = info.out.ub.tpn;
385 64 : info.in.ub.tokenValue = 0; // 清理栈中的敏感信息
386 64 : return HcclResult::HCCL_SUCCESS;
387 : }
388 :
389 64 : static struct JettyImportExpCfg GetTpImportCfg(const JettyImportCfg &jettyImportCfg)
390 : {
391 64 : struct JettyImportExpCfg cfg = {};
392 :
393 64 : cfg.tpHandle = jettyImportCfg.localTpHandle;
394 64 : cfg.peerTpHandle = jettyImportCfg.remoteTpHandle;
395 64 : cfg.tag = jettyImportCfg.localTag;
396 64 : cfg.txPsn = jettyImportCfg.localPsn;
397 64 : cfg.rxPsn = jettyImportCfg.remotePsn;
398 :
399 64 : return cfg;
400 : }
401 :
402 64 : HcclResult HccpUbTpImportJetty(const CtxHandle ctxHandle, u8 *key, const u32 keyLen,
403 : const u32 tokenValue, const JettyImportCfg &jettyImportCfg,
404 : HrtRaUbJettyImportedOutParam &out)
405 : {
406 64 : struct JettyImportExpCfg cfg = GetTpImportCfg(jettyImportCfg);
407 64 : const auto mode = JettyImportMode::JETTY_IMPORT_MODE_EXP;
408 64 : return ImportJetty(ctxHandle, key, keyLen, tokenValue,
409 128 : cfg, mode, jettyImportCfg.protocol, out);
410 : }
411 :
412 0 : static HcclResult ImportJettyAsync(CtxHandle ctxHandle, const HccpUbJettyImportedInParam &in,
413 : std::vector<char> &out, void *&remQpHandle, const JettyImportExpCfg &cfg, JettyImportMode mode,
414 : TpProtocol protocol, RequestHandle &reqHandle)
415 : {
416 0 : if (mode == JettyImportMode::JETTY_IMPORT_MODE_NORMAL) {
417 0 : HCCL_ERROR("[%s] currently not support JETTY_IMPORT_MODE_NORMAL.",
418 : __func__);
419 0 : return HcclResult::HCCL_E_NOT_SUPPORT;
420 : }
421 :
422 0 : out.resize(sizeof(QpImportInfoT));
423 0 : struct QpImportInfoT *info = reinterpret_cast<QpImportInfoT *>(out.data());
424 :
425 0 : s32 ret = memcpy_s(info->in.key.value, sizeof(info->in.key.value), in.key, in.keyLen);
426 0 : if (ret != 0) {
427 0 : HCCL_ERROR("[%s] memcpy_s failed, ret=%d.", __func__, ret);
428 0 : return HcclResult::HCCL_E_MEMORY;
429 : }
430 :
431 0 : info->in.key.size = in.keyLen;
432 0 : info->in.ub.mode = mode;
433 0 : info->in.ub.tokenValue = in.tokenValue;
434 0 : info->in.ub.policy = JettyGrpPolicy::JETTY_GRP_POLICY_RR;
435 0 : info->in.ub.type = TargetType::TARGET_TYPE_JETTY;
436 :
437 0 : info->in.ub.flag.value = 0;
438 0 : info->in.ub.flag.bs.tokenPolicy = TOKEN_POLICY_PLAIN_TEXT;
439 :
440 0 : info->in.ub.expImportCfg = cfg;
441 :
442 0 : if (protocol != TpProtocol::RTP && protocol != TpProtocol::CTP) {
443 0 : HCCL_ERROR("[%s] failed, tp protocol[%s] is not expected.",
444 : __func__, protocol.Describe().c_str());
445 0 : return HcclResult::HCCL_E_PARA;
446 : }
447 : // tp_type: 0->RTP, 1->CTP
448 0 : info->in.ub.tpType = protocol == TpProtocol::RTP ? 0 : 1;
449 :
450 0 : void *raReqHandle = nullptr;
451 0 : ret = RaCtxQpImportAsync(ctxHandle, info, &remQpHandle, &raReqHandle);
452 0 : if (ret != 0 || !raReqHandle) {
453 0 : HCCL_ERROR("[%s] failed, call interface error[%d] raReqHandle[%p], "
454 : "ctxHandle[%p].", __func__, ret, raReqHandle, ctxHandle);
455 0 : return HcclResult::HCCL_E_NETWORK;
456 : }
457 0 : info->in.ub.tokenValue = 0;
458 0 : HCCL_INFO("[%s] ok, get handle[%llu]", __func__, reinterpret_cast<RequestHandle>(raReqHandle));
459 0 : reqHandle = reinterpret_cast<RequestHandle>(raReqHandle);
460 0 : return HcclResult::HCCL_SUCCESS;
461 : }
462 :
463 0 : HcclResult HccpUbTpImportJettyAsync(const CtxHandle ctxHandle, const HccpUbJettyImportedInParam &in,
464 : std::vector<char> &out, void *&remQpHandle, RequestHandle &reqHandle)
465 : {
466 0 : struct JettyImportExpCfg cfg = GetTpImportCfg(in.jettyImportCfg);
467 0 : const auto mode = JettyImportMode::JETTY_IMPORT_MODE_EXP;
468 0 : return ImportJettyAsync(ctxHandle, in, out, remQpHandle,
469 0 : cfg, mode, in.jettyImportCfg.protocol, reqHandle);
470 : }
471 :
472 287 : HcclResult HccpRaTlvCcuCustomChannel(int32_t devLogicId, void *customIn, void *customOut)
473 : {
474 : // 当前复用legacy流程单例,后续需整改
475 : EXCEPTION_HANDLE_BEGIN
476 287 : auto tlvHandle = Hccl::HccpTlvHdcManager::GetInstance().GetTlvHandle(devLogicId);
477 287 : CHK_RET(HccpRaTlvRequestForCustomChannel(tlvHandle, MSG_TYPE_CCU_DISPATCH_CMD, customIn, customOut));
478 0 : EXCEPTION_HANDLE_END
479 287 : return HcclResult::HCCL_SUCCESS;
480 : }
481 :
482 297 : HcclResult HccpRaTlvRequestForCustomChannel(void *tlvHandle, unsigned int msgType, void *customIn, void *customOut)
483 : {
484 297 : CHK_PTR_NULL(tlvHandle);
485 296 : CHK_PTR_NULL(customIn);
486 295 : CHK_PTR_NULL(customOut);
487 :
488 294 : struct TlvMsg sendMsg {};
489 294 : sendMsg.type = msgType;
490 294 : sendMsg.length = sizeof(CustomChanInfoIn);
491 294 : sendMsg.data = static_cast<char *>(customIn);
492 :
493 294 : struct TlvMsg recvMsg {};
494 294 : recvMsg.type = msgType;
495 294 : recvMsg.length = sizeof(CustomChanInfoOut);
496 294 : recvMsg.data = static_cast<char *>(customOut);
497 :
498 294 : int ret = RaTlvRequest(tlvHandle, TLV_MODULE_TYPE_CCU, &sendMsg, &recvMsg);
499 294 : if (ret != 0) {
500 1 : HCCL_ERROR("[%s] RaTlvRequest fail, tlvHandle[%p], ret[%d]",
501 : __func__, tlvHandle, ret);
502 1 : return HCCL_E_NETWORK;
503 : }
504 293 : return HCCL_SUCCESS;
505 : }
506 :
507 2 : HcclResult RaBatchQueryJettyStatus(const std::vector<JettyHandle> &jettyHandles, std::vector<JettyStatus> &jettyAttrs, u32 &num)
508 : {
509 2 : if (jettyHandles.size() != num) {
510 1 : HCCL_ERROR("jettyHandles size[%zu] not equal to num[%u]", jettyHandles.size(), num);
511 1 : return HCCL_E_PARA;
512 : }
513 2 : std::vector<struct JettyAttr> raJettyAttrs(MAX_JETTY_QUERY_NUM);
514 1 : std::vector<void*> qp_handle(jettyHandles.size());
515 1 : for (size_t i = 0; i < jettyHandles.size(); ++i) {
516 0 : qp_handle[i] = reinterpret_cast<void*>(jettyHandles[i]);
517 : }
518 1 : auto ret = RaCtxQpQueryBatch(qp_handle.data(), raJettyAttrs.data(), &num);
519 1 : if (ret != 0) {
520 0 : HCCL_ERROR("RaBatchQueryJettyAttr failed.ret[%d]", ret);
521 0 : return HCCL_E_NETWORK;
522 : }
523 1 : if (num != jettyHandles.size()) {
524 0 : HCCL_ERROR("jettyAttrs num[%zu] not equal to input jettyHandles size[%zu]", num, jettyHandles.size());
525 0 : return HCCL_E_PARA;
526 : }
527 :
528 1 : for (u32 i = 0; i < num; i++) {
529 0 : JettyStatus jettyStatus = static_cast<JettyStatus::Value>(static_cast<int>(raJettyAttrs[i].state));
530 0 : jettyAttrs.push_back(jettyStatus);
531 : }
532 1 : return HCCL_SUCCESS;
533 1 : }
534 :
535 3 : HcclResult HccpGetUboeFlagEnable(const u32 devPhyId)
536 : {
537 3 : u32 uboeVersion = 0;
538 3 : s32 versionRet = RaGetInterfaceVersion(devPhyId, GET_UBOE_FLAG_ENABLE_OPCODE, &uboeVersion);
539 3 : CHK_PRT_RET(versionRet != 0,
540 : HCCL_ERROR("[%s] RaGetInterfaceVersion failed, devPhyId=%u, versionRet=%d", __func__, devPhyId, versionRet),
541 : HCCL_E_INTERNAL);
542 2 : CHK_PRT_RET(uboeVersion < GET_UBOE_FLAG_ENABLE_VERSION,
543 : HCCL_ERROR("[%s] this package does not support to get uboe flag, "
544 : "please change new package. uboeVersion[%u].", __func__, uboeVersion), HCCL_E_NOT_SUPPORT);
545 1 : return HCCL_SUCCESS;
546 : }
547 :
548 10 : HcclResult HccpRaGetDevBaseAttr(void *ctxHandle, struct DevBaseAttr *attr)
549 : {
550 10 : int ret = RaGetDevBaseAttr(ctxHandle, attr);
551 10 : if (ret != 0) {
552 0 : HCCL_ERROR("[%s] RaGetDevBaseAttr failed, ctxHandle[%p], attr[%p], ret[%d]", __func__, ctxHandle, attr, ret);
553 0 : return HCCL_E_NETWORK;
554 : }
555 10 : HCCL_INFO("HccpRaGetDevBaseAttr success, sqMaxDepth[%u], rqMaxDepth[%u], sqMaxSge[%u], rqMaxSge[%u], maxReadSize[%u], maxWriteSize[%u]",
556 : attr->sqMaxDepth, attr->rqMaxDepth, attr->sqMaxSge, attr->rqMaxSge, attr->maxReadSize, attr->maxWriteSize);
557 10 : return HCCL_SUCCESS;
558 : }
559 :
560 : } // namespace hcomm
|