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