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 __DL_HAL_FUNCTION_H__
12 : #define __DL_HAL_FUNCTION_H__
13 :
14 : #include <stdio.h>
15 : #include <dlfcn.h>
16 : #include <stdint.h>
17 : #include "user_log.h"
18 : #include "ascend_hal.h"
19 : #include "ascend_hal_error.h"
20 : #include "ascend_hal_define.h"
21 :
22 : // device info, see hardware_version
23 : #define VER_BIN5 5
24 : #define VER_BIN8 8
25 : #define GET_CHIP_OFFSET 8
26 : #define CHIP_TYPE_910A 1
27 : #define CHIP_TYPE_310P 4
28 : #define CHIP_TYPE_910B_910_93 5
29 :
30 : #define RDMA_CQE_ERR_SENSOR_TYPE 0xC3
31 : #define RDMA_CQE_ERR_RETRY_TIMEOUT_EVENT_TYPE 0x8
32 : /* bit position is 1:event enable; bit position is 0:event disable */
33 : #define RDMA_CQE_ERR_RETRY_TIMEOUT_EVENT_MASK (1U << RDMA_CQE_ERR_RETRY_TIMEOUT_EVENT_TYPE)
34 : /* bit position is 1:fault event; bit position is 0:notify event(one time) */
35 : #define RDMA_CQE_ERR_RETRY_TIMEOUT_EVENT_TYPE_MASK (0U << RDMA_CQE_ERR_RETRY_TIMEOUT_EVENT_TYPE)
36 :
37 : struct DlHalOps {
38 : int (*dlDrvGetDevNum)(unsigned int *numDev);
39 : int (*dlDrvGetLocalDevIdByHostDevId)(unsigned int devId, unsigned int *chipId);
40 : int (*dlDrvGetDevIdByLocalDevId)(unsigned int localDevId, unsigned int *devId);
41 : int (*dlDrvDeviceGetIndexByPhyId)(uint32_t phyId, uint32_t *devIndex);
42 : int (*dlDrvDeviceGetPhyIdByIndex)(unsigned int devIndex, unsigned int *phyId);
43 : int (*dlHalGetPhyDevIdByudevId)(unsigned int udevId, unsigned int *phyDevId);
44 : drvError_t (*dlHalQueryDevPid)(struct halQueryDevpidInfo info, pid_t *devPid);
45 : drvError_t (*dlHalMemBindSibling)(int hostPid, int aicpuPid, unsigned int vfid, unsigned int devId,
46 : unsigned int flag);
47 : drvError_t (*dlDrvQueryProcessHostPid)(int pid, unsigned int *chipId, unsigned int *vfid, unsigned int *hostPid,
48 : unsigned int *cpType);
49 : drvError_t (*dlHalMemGetInfoEx)(unsigned int devId, unsigned int type, struct MemInfo *info);
50 : int (*dlHalGrpQuery)(GroupQueryCmdType cmd, void *inBuff, unsigned int inLen, void *outBuff, unsigned int *outLen);
51 : // HDC
52 : int (*dlHalHdcGetSessionAttr)(HDC_SESSION session, int attr, int *value);
53 : hdcError_t (*dlDrvHdcGetCapacity)(struct drvHdcCapacity *capacity);
54 : hdcError_t (*dlDrvHdcClientCreate)(HDC_CLIENT *client, int maxSessionNum, int serviceType, int flag);
55 : hdcError_t (*dlDrvHdcClientDestroy)(HDC_CLIENT client);
56 : hdcError_t (*dlDrvHdcSessionConnect)(int peerNode, int peerDevid, HDC_CLIENT client, HDC_SESSION *session);
57 : hdcError_t (*dlHalHdcSessionConnectEx)(int peerNode, int peerDevid, int peerPid, HDC_CLIENT client,
58 : HDC_SESSION *session);
59 : hdcError_t (*dlDrvHdcServerCreate)(int devid, int serviceType, HDC_SERVER *pServer);
60 : hdcError_t (*dlDrvHdcServerDestroy)(HDC_SERVER server);
61 : hdcError_t (*dlDrvHdcSessionAccept)(HDC_SERVER server, HDC_SESSION *session);
62 : hdcError_t (*dlDrvHdcSessionClose)(HDC_SESSION session);
63 : hdcError_t (*dlDrvHdcFreeMsg)(struct drvHdcMsg *msg);
64 : hdcError_t (*dlDrvHdcReuseMsg)(struct drvHdcMsg *msg);
65 : hdcError_t (*dlDrvHdcAddMsgBuffer)(struct drvHdcMsg *msg, char *pBuf, int len);
66 : hdcError_t (*dlDrvHdcGetMsgBuffer)(struct drvHdcMsg *msg, int index, char **pBuf, int *pLen);
67 : hdcError_t (*dlHalHdcRecv)(HDC_SESSION session, struct drvHdcMsg *pMsg, int bufLen, UINT64 flag, int *recvBufCount,
68 : UINT32 timeout);
69 : hdcError_t (*dlHalHdcSend)(HDC_SESSION session, struct drvHdcMsg *pMsg, UINT64 flag, UINT32 timeout);
70 : hdcError_t (*dlDrvHdcAllocMsg)(HDC_SESSION session, struct drvHdcMsg **ppMsg, int count);
71 : hdcError_t (*dlDrvHdcSetSessionReference)(HDC_SESSION session);
72 :
73 : int (*dlDrvGetProcessSign)(struct process_sign *sign);
74 :
75 : pid_t (*dlDrvDeviceGetBareTgid)(void);
76 :
77 : int (*dlHalNotifyGetInfo)(uint32_t devId, uint32_t tsId, uint32_t type, uint32_t *val);
78 : int (*dlHalMemAlloc)(void **pp, unsigned long long size, unsigned long long flag);
79 : int (*dlHalMemFree)(void *pp);
80 : int (*dlHalEschedSubmitEvent)(uint32_t devId, struct event_summary *event);
81 :
82 : int (*dlHalGetDeviceInfo)(uint32_t devId, int32_t moduleType, int32_t infoType, int64_t *value);
83 :
84 : int (*dlHalMemCtl)(int type, void *paramValue, size_t paramValueSize, void *outValue, size_t *outSizeRet);
85 :
86 : int (*dlHalBindCgroup)(BIND_CGROUP_TYPE bindType);
87 : int (*dlDrvGetPlatformInfo)(uint32_t *info);
88 :
89 : int (*dlHalGetChipInfo)(unsigned int devId, halChipInfo *chipInfo);
90 :
91 : drvError_t (*dlHalSensorNodeRegister)(uint32_t devid, struct halSensorNodeCfg *cfg, uint64_t *handle);
92 : drvError_t (*dlHalSensorNodeUnregister)(uint32_t devid, uint64_t handle);
93 : drvError_t (*dlHalSensorNodeUpdateState)(uint32_t devid, uint64_t handle, int val, halGeneralEventType_t assertion);
94 :
95 : int (*dlHalBuffAllocAlignEx)(uint64_t size, unsigned int align, unsigned long flag, int grpId, void **buff);
96 : int (*dlHalBuffFree)(void *buff);
97 :
98 : int (*dlHalEschedAttachDevice)(uint32_t devId);
99 : int (*dlHalEschedCreateGrp)(uint32_t devId, uint32_t grpId, GROUP_TYPE type);
100 : int (*dlHalEschedSubscribeEvent)(uint32_t devId, uint32_t grpId, uint32_t threadId, uint64_t eventBitmap);
101 : int (*dlHalEschedWaitEvent)(uint32_t devId, uint32_t grpId, uint32_t threadId, int32_t timeout,
102 : struct event_info *event);
103 : drvError_t (*dlHalResAddrMapV2)(unsigned int devId, struct res_map_info_in *resInfoIn,
104 : struct res_map_info_out *resInfoOut);
105 : drvError_t (*dlHalResAddrUnmapV2)(unsigned int devId, struct res_map_info_in *resInfoIn);
106 : drvError_t (*dlHalMemRegUbSegment)(uint32_t devId, uint64_t va, uint64_t size);
107 : drvError_t (*dlHalMemUnRegUbSegment)(uint32_t devid, uint64_t va);
108 : DVresult (*dlDrvMemGetAttribute)(DVdeviceptr vptr, struct DVattribute *attr);
109 : drvError_t (*dlHalHostRegister)(void *srcPtr, uint64_t size, uint32_t flag, uint32_t devId, void **dstPtr);
110 : drvError_t (*dlHalHostUnregister)(void *src_ptr, uint32_t devid);
111 : drvError_t (*dlHalHostUnregisterEx)(void *src_ptr, uint32_t devid, uint32_t flag);
112 : };
113 :
114 : int DlHalInit(void);
115 : void DlHalDeinit(void);
116 :
117 : int DlDrvGetDevNum(unsigned int *numDev);
118 : int DlDrvGetLocalDevIdByHostDevId(unsigned int devId, unsigned int *chipId);
119 : int DlDrvGetDevIdByLocalDevId(unsigned int localDevId, unsigned int *devId);
120 : int DlDrvDeviceGetIndexByPhyId(uint32_t phyId, uint32_t *devIndex);
121 : int DlDrvDeviceGetPhyIdByIndex(unsigned int devIndex, unsigned int *phyId);
122 : int DlHalGetPhyDevIdByudevId(unsigned int udevId, unsigned int *phyDevId);
123 : drvError_t DlHalQueryDevPid(struct halQueryDevpidInfo info, pid_t *devPid);
124 : drvError_t DlHalMemBindSibling(int hostPid, int aicpuPid, unsigned int vfid, unsigned int devId, unsigned int flag);
125 : drvError_t DlDrvQueryProcessHostPid(int pid, unsigned int *chipId, unsigned int *vfid, unsigned int *hostPid,
126 : unsigned int *cpType);
127 : drvError_t DlHalMemGetInfoEx(unsigned int devId, unsigned int type, struct MemInfo *info);
128 : int DlHalGrpQuery(GroupQueryCmdType cmd, void *inBuff, unsigned int inLen, void *outBuff, unsigned int *outLen);
129 : // HDC
130 : int DlHalHdcGetSessionAttr(HDC_SESSION session, int attr, int *value);
131 : hdcError_t DlDrvHdcGetCapacity(struct drvHdcCapacity *capacity);
132 : hdcError_t DlDrvHdcClientCreate(HDC_CLIENT *client, int maxSessionNum, int serviceType, int flag);
133 : hdcError_t DlDrvHdcClientDestroy(HDC_CLIENT client);
134 : hdcError_t DlDrvHdcSessionConnect(int peerNode, int peerDevid, HDC_CLIENT client, HDC_SESSION *session);
135 : hdcError_t DlHalHdcSessionConnectEx(int peerNode, int peerDevid, int peerPid, HDC_CLIENT client, HDC_SESSION *pSession);
136 : hdcError_t DlDrvHdcServerCreate(int devid, int serviceType, HDC_SERVER *pServer);
137 : hdcError_t DlDrvHdcServerDestroy(HDC_SERVER server);
138 : hdcError_t DlDrvHdcSessionAccept(HDC_SERVER server, HDC_SESSION *session);
139 : hdcError_t DlDrvHdcSessionClose(HDC_SESSION session);
140 : hdcError_t DlDrvHdcFreeMsg(struct drvHdcMsg *msg);
141 : hdcError_t DlDrvHdcReuseMsg(struct drvHdcMsg *msg);
142 : hdcError_t DlDrvHdcAddMsgBuffer(struct drvHdcMsg *msg, char *pBuf, int len);
143 : hdcError_t DlDrvHdcGetMsgBuffer(struct drvHdcMsg *msg, int index, char **pBuf, int *pLen);
144 : hdcError_t DlHalHdcRecv(HDC_SESSION session, struct drvHdcMsg *pMsg, int bufLen, UINT64 flag, int *recvBufCount,
145 : UINT32 timeout);
146 : hdcError_t DlHalHdcSend(HDC_SESSION session, struct drvHdcMsg *pMsg, UINT64 flag, UINT32 timeout);
147 : hdcError_t DlDrvHdcAllocMsg(HDC_SESSION session, struct drvHdcMsg **ppMsg, int count);
148 : hdcError_t DlDrvHdcSetSessionReference(HDC_SESSION session);
149 :
150 : int DlDrvGetProcessSign(struct process_sign *sign);
151 :
152 : pid_t DlDrvDeviceGetBareTgid(void);
153 :
154 : int DlHalNotifyGetInfo(uint32_t devId, uint32_t tsId, uint32_t type, uint32_t *val);
155 : int DlHalMemAlloc(void **pp, unsigned long long size, unsigned long long flag);
156 : int DlHalMemFree(void *pp);
157 : int DlHalEschedSubmitEvent(uint32_t devId, struct event_summary *event);
158 :
159 : // device info, see hardware_version
160 : int DlHalGetDeviceInfo(uint32_t devId, int32_t moduleType, int32_t infoType, int64_t *value);
161 :
162 0 : static inline uint32_t DlHalPlatGetVer(uint64_t deviceInfo)
163 : {
164 0 : return (uint32_t)(deviceInfo & 0xff);
165 : }
166 :
167 69 : static inline uint32_t DlHalPlatGetChip(uint64_t deviceInfo)
168 : {
169 69 : return (uint32_t)((deviceInfo >> GET_CHIP_OFFSET) & 0xff);
170 : }
171 :
172 : int DlHalBindCgroup(BIND_CGROUP_TYPE bindType);
173 : int DlDrvGetPlatformInfo(uint32_t *info);
174 :
175 : int DlHalMemCtl(int type, void *paramValue, size_t paramValueSize, void *outValue, size_t *outSizeRet);
176 : int DlHalBuffAllocAlignEx(uint64_t size, unsigned int align, unsigned long flag, int grpId, void **buff);
177 : int DlHalBuffFree(void *buff);
178 :
179 : int DlHalGetChipInfo(unsigned int devId, halChipInfo *chipInfo);
180 :
181 : int DlHalSensorNodeRegister(uint32_t devid, struct halSensorNodeCfg *cfg, uint64_t *handle);
182 : int DlHalSensorNodeUnregister(uint32_t devid, uint64_t handle);
183 : int DlHalSensorNodeUpdateState(uint32_t devid, uint64_t handle, int val, halGeneralEventType_t assertion);
184 :
185 : int DlHalEschedAttachDevice(uint32_t devId);
186 : int DlHalEschedCreateGrp(uint32_t devId, uint32_t grpId, GROUP_TYPE type);
187 : int DlHalEschedSubscribeEvent(uint32_t devId, uint32_t grpId, uint32_t threadId, uint64_t eventBitmap);
188 : int DlHalEschedWaitEvent(uint32_t devId, uint32_t grpId, uint32_t threadId, int32_t timeout, struct event_info *event);
189 : int DlHalResAddrMapV2(unsigned int devId, struct res_map_info_in *resInfoIn, struct res_map_info_out *resInfoOut);
190 : int DlHalResAddrUnmapV2(unsigned int devId, struct res_map_info_in *resInfoIn);
191 : int DlHalMemRegUbSegment(uint32_t devId, uint64_t va, uint64_t size);
192 : int DlHalMemUnRegUbSegment(uint32_t devId, uint64_t va);
193 : int DlDrvMemGetAttribute(DVdeviceptr vptr, struct DVattribute *attr);
194 : int DlHalHostRegister(void *srcPtr, uint64_t size, uint32_t flag, uint32_t devId, void **dstPtr);
195 : int DlHalHostUnRegister(void *srcPtr, uint32_t devId);
196 : int DlHalHostUnRegisterEx(void *srcPtr, uint32_t devId, uint32_t flag);
197 :
198 : #endif // __DL_HAL_FUNCTION_H__
|