LCOV - code coverage report
Current view: top level - base_comm/resources/southbound_adpt - hcomm_adapter_hccp.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 92.9 % 14 13
Test Date: 2026-08-04 10:52:23 Functions: 70.8 % 24 17

            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 HCOMM_ADAPTER_HCCP_H
      12              : #define HCOMM_ADAPTER_HCCP_H
      13              : 
      14              : #include <vector>
      15              : #include <string>
      16              : 
      17              : #include "hccp.h"
      18              : #include "hccp_ctx.h"
      19              : 
      20              : #include "env_config.h"
      21              : #include "enum_factory.h"
      22              : #include "hccl_rank_graph.h"
      23              : // orion 暂时复用
      24              : #include "ip_address.h"
      25              : 
      26              : namespace hcomm {
      27              : 
      28              : // 暂时放在adapter
      29              : constexpr uint32_t URMA_EID_LEN = 16;
      30              : MAKE_ENUM(HrtNetworkMode, PEER, HDC);
      31              : 
      32              : using Eid = HccpEid; // 使用hccp定义的union表示eid
      33              : // 当前支持编译定义,后续考虑直接使用hccp数据结构
      34              : struct DevEidInfo {
      35              :     std::string name{};
      36              :     CommAddr commAddr{};
      37              :     uint32_t eidIndex{0};
      38              :     uint32_t type{0};
      39              :     uint32_t dieId{0};
      40              :     uint32_t chipId{0};
      41              :     uint32_t funcId{0};
      42              :     uint32_t devFeature{0};
      43              : };
      44              : 
      45              : HcclResult IpAddressToHccpEid(const Hccl::IpAddress &ipAddr, Eid &eid);
      46              : HcclResult IpAddressToReverseHccpEid(const Hccl::IpAddress &ipAddr, Eid &eid);
      47              : HcclResult IpAddressToReverseHcclEid(const Hccl::IpAddress &ipAddr, Hccl::Eid &eid);
      48              : 
      49              : HcclResult RaGetDevEidInfos(const RaInfo &raInfo, std::vector<DevEidInfo> &devEidInfos);
      50              : 
      51              : using RequestHandle = u64;
      52         1431 : MAKE_ENUM(RequestResult,
      53              :     COMPLETED,
      54              :     NOT_COMPLETED, SOCK_E_AGAIN,
      55              :     INVALID_PARA,
      56              :     GET_REQ_RESULT_FAILED, ASYNC_REQUEST_FAILED);
      57              : 
      58              : RequestResult HccpGetAsyncReqResult(RequestHandle &reqHandle);
      59              : 
      60              : using CtxHandle         = void *;
      61              : using JettyHandle       = void *;
      62              : using TargetJettyHandle = void *;
      63              : using JfcHandle         = void *;
      64              : using TokenIdHandle     = void *;
      65              : 
      66              : HcclResult HrtRaDumpJettyContext(JettyHandle jettyHandle, u32 jettyId);
      67              : 
      68          562 : MAKE_ENUM(HrtTransportMode, RM);
      69              : // STANDARD: URMA标准CreateJetty
      70              : // HOST_OFFLOAD: HOST侧展开下沉算子,需要指定sqeBbNum
      71              : // HOST_OPBASE: Host展开单算子,需要指定sqeBbNum,
      72              : // DEV_USED: 在Dev的APICPU展开算子,STARS不能使用UB DirectWQE的task,可以使用UB DbSend task,不需要指定sqeBbNum
      73              : // CACHE_LOCK_DWQE: 该模式下,      STARS仅能使用UB DirectWQE的task,不能使用UB DbSend task,,需要指定sqeBbNum
      74              : // CCU_CCUM_CACHE: 不需要指定sqeBbNum
      75              : // CCU_TA_CACHE: A6 CCU专用
      76         2126 : MAKE_ENUM(HrtJettyMode, STANDARD, HOST_OFFLOAD, HOST_OPBASE, DEV_USED, CACHE_LOCK_DWQE, CCU_CCUM_CACHE, CCU_TA_CACHE);
      77              : MAKE_ENUM(HrtUbJfcMode, NORMAL, STARS_POLL, CCU_POLL, USER_CTL);
      78              : using HrtRaUbCreateJettyParam = struct HrtRaUbJettyCreateParamDef {
      79              :     JfcHandle sjfcHandle{nullptr};
      80              :     JfcHandle rjfcHandle{nullptr};
      81              : 
      82              :     // CCU的DB需要注册,填写tokenValue
      83              :     u32 tokenValue{0};
      84              :     TokenIdHandle tokenIdHandle{0};
      85              : 
      86              :     HrtJettyMode jettyMode{HrtJettyMode::STANDARD};
      87              : 
      88              :     // 如果jettyId为0,则代表UB自行申请jetty,如果jettyId不为0,则代表使用预留jetty id
      89              :     // [1024, 1024 +127]为ccuJetty预留的id
      90              :     // [1024 + 192, 1024 + 192 + 4K - 1]为starsJetty预留的id
      91              :     u32 jettyId{0};
      92              : 
      93              :     // 指定内存,需要填写的参数,CCU类型 和 DEV_USED类型需要填写
      94              :     u64 sqBufVa{0};
      95              :     u32 sqBufSize{0};
      96              :     // 指定sqeBB资源起始id,当前预留
      97              :     u32 sqeBufIndex{0};
      98              : 
      99              :     // HOST_OFFLOAD / HOST_OPBASE / CACHE_LOCK_DWQE 类型的Jetty ,需要指定WQEBB的数目
     100              :     // STADARD 类型Jetty,该参数代表SQ深度
     101              :     u32              sqDepth{0};
     102              :     u32              rqDepth{64};
     103              :     HrtTransportMode transMode{HrtTransportMode::RM}; // 仅能使用RM模式的Jetty
     104              :     u8 errTimeout{16};
     105              :     /// 低 4bit 映射 UB Jetty 创建属性中的 priority(attr.ub.priority = qos & 0xF)
     106              :     u32              qos{EnvConfig::UB_QOS_DEFAULT};
     107              : 
     108           33 :     HrtRaUbJettyCreateParamDef() {}
     109              : 
     110          189 :     HrtRaUbJettyCreateParamDef(JfcHandle sjfcHandle, JfcHandle rjfcHandle,
     111              :         u32 tokenValue, TokenIdHandle tokenIdHandle, HrtJettyMode jettyMode,
     112              :         u32 jettyId, u64 sqBufVa, u32 sqBufSize, u32 sqeBufIndex, u32 sqDepth, u8 errTimeout = 16)
     113          189 :         : sjfcHandle(sjfcHandle), rjfcHandle(rjfcHandle), tokenValue(tokenValue),
     114          189 :           tokenIdHandle(tokenIdHandle), jettyMode(jettyMode), jettyId(jettyId),
     115          189 :           sqBufVa(sqBufVa), sqBufSize(sqBufSize), sqeBufIndex(sqeBufIndex),
     116          189 :           sqDepth(sqDepth), errTimeout(errTimeout)
     117              :     {
     118          189 :     }
     119              : };
     120              : 
     121              : constexpr u32 HRT_UB_QP_KEY_MAX_LEN = 64; // UB 最大的QpKey长度
     122              : 
     123              : using HrtRaUbJettyCreatedOutParam = struct HrtRaUbJettyCreatedOutParamDef {
     124              :     JettyHandle handle{0};
     125              :     u8          key[HRT_UB_QP_KEY_MAX_LEN]{0};
     126              :     u64         jettyVa{0};
     127              :     u32         uasid{0};
     128              :     u32         id{0};
     129              :     u32         keySize{0};
     130              :     u64         dbVa{0};
     131              :     u32         dbTokenId{0};
     132              : };
     133              : 
     134              : HcclResult HccpUbCreateJetty(const CtxHandle ctxhandle, const HrtRaUbCreateJettyParam &in,
     135              :     HrtRaUbJettyCreatedOutParam &out);
     136              : 
     137              : HcclResult HccpUbCreateJettyAsync(const CtxHandle ctxhandle, const HrtRaUbCreateJettyParam &in,
     138              :     std::vector<char> &out, void *&jettyHandle, RequestHandle &reqHandle);
     139              : 
     140            0 : MAKE_ENUM(JettyStatus, RESET, READY, SUSPENDED, ERROR);
     141              : constexpr u32 MAX_JETTY_QUERY_NUM = 128;
     142              : HcclResult RaBatchQueryJettyStatus(const std::vector<JettyHandle> &jettyHandles, std::vector<JettyStatus> &jettyAttrs, u32 &num);
     143              : 
     144              : using HrtRaUbJettyImportedOutParam = struct HrtRaUbJettyImportedOutParamDef {
     145              :     TargetJettyHandle handle{0};
     146              :     u64               targetJettyVa{0};
     147              :     u32               tpn{0};
     148              : };
     149              : 
     150         7171 : MAKE_ENUM(TpProtocol, CTP, RTP, UBOE);
     151              : 
     152              : struct JettyImportCfg {
     153              :     u64 localTpHandle{0};
     154              :     u64 remoteTpHandle{0};
     155              :     u64 localTag{0};  // tag是hccp预留字段,暂不需要赋值
     156              :     u32 localPsn{0};
     157              :     u32 remotePsn{0};
     158              :     TpProtocol protocol{TpProtocol::INVALID};
     159              : };
     160              : 
     161              : HcclResult HccpUbTpImportJetty(const CtxHandle ctxHandle, u8 *key, const u32 keyLen,
     162              :     const u32 tokenValue, const JettyImportCfg &jettyImportCfg,
     163              :     HrtRaUbJettyImportedOutParam &out);
     164              : 
     165              : using HccpUbJettyImportedInParam = struct HccpUbJettyImportedInParamDef {
     166              :     u8 *key{nullptr};
     167              :     u32 keyLen{0};
     168              :     u32 tokenValue{0};
     169              :     JettyImportCfg jettyImportCfg{};
     170              : };
     171              : 
     172              : HcclResult HccpUbTpImportJettyAsync(const CtxHandle ctxHandle,
     173              :     const HccpUbJettyImportedInParam &in, std::vector<char> &out,
     174              :     void *&remQpHandle, RequestHandle &reqHandle);
     175              : 
     176              : HcclResult HccpRaTlvCcuCustomChannel(int32_t devLogicId, void *customIn, void *customOut);
     177              : 
     178              : HcclResult HccpRaTlvRequestForCustomChannel(void *tlvHandle, unsigned int msgType, void *customIn, void *customOut);
     179              : 
     180              : HcclResult HccpRaGetDevBaseAttr(void *ctxHandle, struct DevBaseAttr *attr);
     181              : 
     182              : constexpr u32 GET_UBOE_FLAG_ENABLE_OPCODE = 57;
     183              : constexpr u32 GET_UBOE_FLAG_ENABLE_VERSION = 2;
     184              : constexpr u32 UBOE_DEV_FLAG_RIGHT_SHIFT = 19;
     185              : 
     186              : HcclResult HccpGetUboeFlagEnable(const u32 devPhyId);
     187              : 
     188            4 : inline bool HccpCheckUboeSupported(const u32 devFeature)
     189              : {
     190              :     // 设备特性位掩码, 右移取UBOE标志位, 值为1表示支持
     191            4 :     return (devFeature >> UBOE_DEV_FLAG_RIGHT_SHIFT) & 1;
     192              : }
     193              : } // namespace hcomm
     194              : #endif // HCOMM_ADAPTER_HCCP_H
        

Generated by: LCOV version 2.0-1