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 "log.h"
12 : #include "hccl_net_dev_v1.h"
13 : #include "adapter_rts_common.h"
14 : #include "hccl_net_dev.h"
15 :
16 : #ifdef __cplusplus
17 : extern "C" {
18 : #endif
19 : HcclResult __attribute__((weak)) HcclNetDevOpenV2(const HcclNetDevInfos* info, HcclNetDev* netDev);
20 : HcclResult __attribute__((weak)) HcclNetDevCloseV2(HcclNetDev netDev);
21 : HcclResult __attribute__((weak)) HcclNetDevGetAddrV2(HcclNetDev netDev, HcclAddress* addr);
22 : HcclResult __attribute__((weak)) HcclNetDevGetBusAddrV2(HcclDeviceId dstDevId, HcclAddress* busAddr);
23 : HcclResult __attribute__((weak)) HcclNetDevGetNicAddrV2(int32_t devicePhyId, HcclAddress** addr, uint32_t* addrNum);
24 : #ifdef __cplusplus
25 : }
26 : #endif
27 :
28 : using namespace std;
29 :
30 0 : HcclResult HcclNetDevOpen(const HcclNetDevInfos* info, HcclNetDev* netDev)
31 : {
32 0 : CHK_PTR_NULL(netDev);
33 0 : CHK_PTR_NULL(info);
34 : DevType devType;
35 0 : CHK_RET(hrtGetDeviceType(devType));
36 0 : if (devType == DevType::DEV_TYPE_950 || devType == DevType::DEV_TYPE_960) {
37 0 : return HcclNetDevOpenV2(info, netDev);
38 : }
39 0 : return HcclNetDevOpenV1(info, netDev);
40 : }
41 :
42 0 : HcclResult HcclNetDevClose(HcclNetDev netDev)
43 : {
44 : // 先销毁设备
45 0 : CHK_PTR_NULL(netDev);
46 :
47 : DevType devType;
48 0 : CHK_RET(hrtGetDeviceType(devType));
49 0 : if (devType == DevType::DEV_TYPE_950 || devType == DevType::DEV_TYPE_960) {
50 0 : return HcclNetDevCloseV2(netDev);
51 : }
52 :
53 0 : return HcclNetDevCloseV1(netDev);
54 : }
55 :
56 0 : HcclResult HcclNetDevGetAddr(HcclNetDev netDev, HcclAddress* addr)
57 : {
58 0 : CHK_PTR_NULL(netDev);
59 0 : CHK_PTR_NULL(addr);
60 :
61 : DevType devType;
62 0 : CHK_RET(hrtGetDeviceType(devType));
63 0 : if (devType == DevType::DEV_TYPE_950 || devType == DevType::DEV_TYPE_960) {
64 0 : return HcclNetDevGetAddrV2(netDev, addr);
65 : }
66 :
67 0 : return HcclNetDevGetAddrV1(netDev, addr);
68 : }
69 :
70 0 : HcclResult HcclNetDevGetBusAddr(HcclDeviceId dstDevId, HcclAddress* busAddr)
71 : {
72 0 : CHK_PTR_NULL(busAddr);
73 :
74 : DevType devType;
75 0 : CHK_RET(hrtGetDeviceType(devType));
76 0 : if (devType == DevType::DEV_TYPE_950 || devType == DevType::DEV_TYPE_960) {
77 0 : return HcclNetDevGetBusAddrV2(dstDevId, busAddr);
78 : }
79 :
80 0 : return HcclNetDevGetBusAddrV1(dstDevId, busAddr);
81 : }
82 :
83 0 : HcclResult HcclNetDevGetNicAddr(int32_t devicePhyId, HcclAddress** addr, uint32_t* addrNum)
84 : {
85 0 : CHK_PTR_NULL(addrNum);
86 0 : CHK_PTR_NULL(addr);
87 :
88 : DevType devType;
89 0 : CHK_RET(hrtGetDeviceType(devType));
90 0 : if (devType == DevType::DEV_TYPE_950 || devType == DevType::DEV_TYPE_960) {
91 0 : return HcclNetDevGetNicAddrV2(devicePhyId, addr, addrNum);
92 : }
93 :
94 0 : return HcclNetDevGetNicAddrV1(devicePhyId, addr, addrNum);
95 : }
|