LCOV - code coverage report
Current view: top level - base_comm/resources/southbound_adpt - hcomm_adapter_hccp.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 59.0 % 327 193
Test Date: 2026-08-04 10:52:23 Functions: 78.9 % 19 15

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

Generated by: LCOV version 2.0-1