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-07-28 12:11:00 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          633 : 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          238 : MAKE_ENUM(HrtTransportMode, RM);
      67              : // STANDARD: URMA标准CreateJetty
      68              : // HOST_OFFLOAD: HOST侧展开下沉算子,需要指定sqeBbNum
      69              : // HOST_OPBASE: Host展开单算子,需要指定sqeBbNum,
      70              : // DEV_USED: 在Dev的APICPU展开算子,STARS不能使用UB DirectWQE的task,可以使用UB DbSend task,不需要指定sqeBbNum
      71              : // CACHE_LOCK_DWQE: 该模式下,      STARS仅能使用UB DirectWQE的task,不能使用UB DbSend task,,需要指定sqeBbNum
      72              : // CCU_CCUM_CACHE: 不需要指定sqeBbNum
      73              : // CCU_TA_CACHE: A6 CCU专用
      74         1118 : MAKE_ENUM(HrtJettyMode, STANDARD, HOST_OFFLOAD, HOST_OPBASE, DEV_USED, CACHE_LOCK_DWQE, CCU_CCUM_CACHE, CCU_TA_CACHE);
      75              : MAKE_ENUM(HrtUbJfcMode, NORMAL, STARS_POLL, CCU_POLL, USER_CTL);
      76              : using HrtRaUbCreateJettyParam = struct HrtRaUbJettyCreateParamDef {
      77              :     JfcHandle sjfcHandle{nullptr};
      78              :     JfcHandle rjfcHandle{nullptr};
      79              : 
      80              :     // CCU的DB需要注册,填写tokenValue
      81              :     u32 tokenValue{0};
      82              :     TokenIdHandle tokenIdHandle{0};
      83              : 
      84              :     HrtJettyMode jettyMode{HrtJettyMode::STANDARD};
      85              : 
      86              :     // 如果jettyId为0,则代表UB自行申请jetty,如果jettyId不为0,则代表使用预留jetty id
      87              :     // [1024, 1024 +127]为ccuJetty预留的id
      88              :     // [1024 + 192, 1024 + 192 + 4K - 1]为starsJetty预留的id
      89              :     u32 jettyId{0};
      90              : 
      91              :     // 指定内存,需要填写的参数,CCU类型 和 DEV_USED类型需要填写
      92              :     u64 sqBufVa{0};
      93              :     u32 sqBufSize{0};
      94              :     // 指定sqeBB资源起始id,当前预留
      95              :     u32 sqeBufIndex{0};
      96              : 
      97              :     // HOST_OFFLOAD / HOST_OPBASE / CACHE_LOCK_DWQE 类型的Jetty ,需要指定WQEBB的数目
      98              :     // STADARD 类型Jetty,该参数代表SQ深度
      99              :     u32              sqDepth{0};
     100              :     u32              rqDepth{64};
     101              :     HrtTransportMode transMode{HrtTransportMode::RM}; // 仅能使用RM模式的Jetty
     102              :     u8 errTimeout{16};
     103              :     /// 低 4bit 映射 UB Jetty 创建属性中的 priority(attr.ub.priority = qos & 0xF)
     104              :     u32              qos{EnvConfig::UB_QOS_DEFAULT};
     105              : 
     106           30 :     HrtRaUbJettyCreateParamDef() {}
     107              : 
     108           80 :     HrtRaUbJettyCreateParamDef(JfcHandle sjfcHandle, JfcHandle rjfcHandle,
     109              :         u32 tokenValue, TokenIdHandle tokenIdHandle, HrtJettyMode jettyMode,
     110              :         u32 jettyId, u64 sqBufVa, u32 sqBufSize, u32 sqeBufIndex, u32 sqDepth, u8 errTimeout = 16)
     111           80 :         : sjfcHandle(sjfcHandle), rjfcHandle(rjfcHandle), tokenValue(tokenValue),
     112           80 :           tokenIdHandle(tokenIdHandle), jettyMode(jettyMode), jettyId(jettyId),
     113           80 :           sqBufVa(sqBufVa), sqBufSize(sqBufSize), sqeBufIndex(sqeBufIndex),
     114           80 :           sqDepth(sqDepth), errTimeout(errTimeout)
     115              :     {
     116           80 :     }
     117              : };
     118              : 
     119              : constexpr u32 HRT_UB_QP_KEY_MAX_LEN = 64; // UB 最大的QpKey长度
     120              : 
     121              : using HrtRaUbJettyCreatedOutParam = struct HrtRaUbJettyCreatedOutParamDef {
     122              :     JettyHandle handle{0};
     123              :     u8          key[HRT_UB_QP_KEY_MAX_LEN]{0};
     124              :     u64         jettyVa{0};
     125              :     u32         uasid{0};
     126              :     u32         id{0};
     127              :     u32         keySize{0};
     128              :     u64         dbVa{0};
     129              :     u32         dbTokenId{0};
     130              : };
     131              : 
     132              : HcclResult HccpUbCreateJetty(const CtxHandle ctxhandle, const HrtRaUbCreateJettyParam &in,
     133              :     HrtRaUbJettyCreatedOutParam &out);
     134              : 
     135              : HcclResult HccpUbCreateJettyAsync(const CtxHandle ctxhandle, const HrtRaUbCreateJettyParam &in,
     136              :     std::vector<char> &out, void *&jettyHandle, RequestHandle &reqHandle);
     137              : 
     138            0 : MAKE_ENUM(JettyStatus, RESET, READY, SUSPENDED, ERROR);
     139              : constexpr u32 MAX_JETTY_QUERY_NUM = 128;
     140              : HcclResult RaBatchQueryJettyStatus(const std::vector<JettyHandle> &jettyHandles, std::vector<JettyStatus> &jettyAttrs, u32 &num);
     141              : 
     142              : using HrtRaUbJettyImportedOutParam = struct HrtRaUbJettyImportedOutParamDef {
     143              :     TargetJettyHandle handle{0};
     144              :     u64               targetJettyVa{0};
     145              :     u32               tpn{0};
     146              : };
     147              : 
     148         3417 : MAKE_ENUM(TpProtocol, CTP, RTP, UBOE);
     149              : 
     150              : struct JettyImportCfg {
     151              :     u64 localTpHandle{0};
     152              :     u64 remoteTpHandle{0};
     153              :     u64 localTag{0};  // tag是hccp预留字段,暂不需要赋值
     154              :     u32 localPsn{0};
     155              :     u32 remotePsn{0};
     156              :     TpProtocol protocol{TpProtocol::INVALID};
     157              : };
     158              : 
     159              : HcclResult HccpUbTpImportJetty(const CtxHandle ctxHandle, u8 *key, const u32 keyLen,
     160              :     const u32 tokenValue, const JettyImportCfg &jettyImportCfg,
     161              :     HrtRaUbJettyImportedOutParam &out);
     162              : 
     163              : using HccpUbJettyImportedInParam = struct HccpUbJettyImportedInParamDef {
     164              :     u8 *key{nullptr};
     165              :     u32 keyLen{0};
     166              :     u32 tokenValue{0};
     167              :     JettyImportCfg jettyImportCfg{};
     168              : };
     169              : 
     170              : HcclResult HccpUbTpImportJettyAsync(const CtxHandle ctxHandle,
     171              :     const HccpUbJettyImportedInParam &in, std::vector<char> &out,
     172              :     void *&remQpHandle, RequestHandle &reqHandle);
     173              : 
     174              : HcclResult HccpRaTlvCcuCustomChannel(int32_t devLogicId, void *customIn, void *customOut);
     175              : 
     176              : HcclResult HccpRaTlvRequestForCustomChannel(void *tlvHandle, unsigned int msgType, void *customIn, void *customOut);
     177              : 
     178              : HcclResult HccpRaGetDevBaseAttr(void *ctxHandle, struct DevBaseAttr *attr);
     179              : 
     180              : constexpr u32 GET_UBOE_FLAG_ENABLE_OPCODE = 57;
     181              : constexpr u32 GET_UBOE_FLAG_ENABLE_VERSION = 2;
     182              : constexpr u32 UBOE_DEV_FLAG_RIGHT_SHIFT = 19;
     183              : 
     184              : HcclResult HccpGetUboeFlagEnable(const u32 devPhyId);
     185              : 
     186            4 : inline bool HccpCheckUboeSupported(const u32 devFeature)
     187              : {
     188              :     // 设备特性位掩码, 右移取UBOE标志位, 值为1表示支持
     189            4 :     return (devFeature >> UBOE_DEV_FLAG_RIGHT_SHIFT) & 1;
     190              : }
     191              : } // namespace hcomm
     192              : #endif // HCOMM_ADAPTER_HCCP_H
        

Generated by: LCOV version 2.0-1