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 <unistd.h>
12 : #include <hccl/hccl_types.h>
13 : #include "hccl_communicator.h"
14 : #include "adapter_hccp_common.h"
15 : #include "../nslbdp/hccl_nslbdp_pub.h"
16 : #include "hccl_h2dtlv.h"
17 :
18 : namespace hccl {
19 :
20 234 : hcclH2dTlv &hcclH2dTlv::GetInstance()
21 : {
22 : static hcclH2dTlv phcclH2dTlv;
23 234 : return phcclH2dTlv;
24 : }
25 :
26 234 : HcclResult hcclH2dTlv::InitHccpChannel(u32 devicePhyId)
27 : {
28 : /* 避免重复初始化 */
29 234 : if (hcclH2dTlvInitFlag_ == true) {
30 21 : HCCL_INFO("hcclNslbDp getHccpInitFlag is init");
31 21 : return HCCL_SUCCESS;
32 : }
33 :
34 213 : u32 phyID = (static_cast<s32>(devicePhyId) == HOST_DEVICE_ID) ? 0 : devicePhyId;
35 : nslb_inithccp_info nslbHccp;
36 213 : nslbHccp.version = NSLBDP_HCCP_VERSION;
37 213 : nslbHccp.phyId = phyID;
38 213 : nslbHccp.nic_posion = NSLBDP_HCCP_NICPOSION;
39 :
40 213 : u32 tlvBuffersize = 0;
41 : void *tlvHandle;
42 213 : HCCL_INFO("Entry InitHccpChannel version:[%u]-phy_id:[%u]-nic_posion:[%u] .",
43 : nslbHccp.version, nslbHccp.phyId, nslbHccp.nic_posion);
44 :
45 213 : HcclResult ret = H2DTlvInit(reinterpret_cast<TlvInitInfo *>(&nslbHccp), &tlvBuffersize, &tlvHandle);
46 213 : if (ret != HCCL_SUCCESS) {
47 212 : return ret;
48 : }
49 :
50 1 : hcclH2dTlvBuffsize_ = tlvBuffersize;
51 1 : hcclH2dTlvHandle_ = tlvHandle;
52 1 : hcclH2dTlvInitFlag_ = true;
53 1 : return HCCL_SUCCESS;
54 : }
55 :
56 0 : void hcclH2dTlv::DeinitHccpChannel()
57 : {
58 0 : if (hcclH2dTlvInitFlag_ == false) {
59 0 : HCCL_INFO("Hccp channel is already deinit.");
60 0 : return;
61 : }
62 0 : if (hcclH2dTlvHandle_ == nullptr) {
63 0 : HCCL_INFO("Try to deinit hccp channel while hcclH2dTlvHandle_ is null.");
64 0 : return;
65 : }
66 0 : HcclResult ret = H2DTlvDeinit(hcclH2dTlvHandle_);
67 0 : if (ret != HCCL_SUCCESS) {
68 0 : HCCL_WARNING("DeInit hccp channel failed ret[%u].", ret);
69 0 : return;
70 : }
71 :
72 0 : hcclH2dTlvBuffsize_ = H2D_TLVBUFFERSIZE;
73 0 : hcclH2dTlvHandle_ = nullptr;
74 0 : hcclH2dTlvInitFlag_ = false;
75 0 : return;
76 : }
77 :
78 0 : bool hcclH2dTlv::GetH2dTlvInitFlag()
79 : {
80 0 : return hcclH2dTlvInitFlag_;
81 : }
82 :
83 0 : unsigned int hcclH2dTlv::GetH2dTlvBufferSize()
84 : {
85 0 : return hcclH2dTlvBuffsize_;
86 : }
87 :
88 0 : void* hcclH2dTlv::GetH2dTlvHandle()
89 : {
90 0 : return hcclH2dTlvHandle_;
91 : }
92 :
93 : }
|