blob: 371dfc4243b3d562084218ef75e0a29a2ceea412 [file] [log] [blame]
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
2 *
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +03003 * Copyright 2016-2020 HabanaLabs, Ltd.
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02004 * All Rights Reserved.
5 *
6 */
7
8#ifndef HABANALABS_H_
9#define HABANALABS_H_
10
11#include <linux/types.h>
12#include <linux/ioctl.h>
13
14/*
15 * Defines that are asic-specific but constitutes as ABI between kernel driver
16 * and userspace
17 */
Oded Gabbay466c7822020-05-11 10:32:10 +030018#define GOYA_KMD_SRAM_RESERVED_SIZE_FROM_START 0x8000 /* 32KB */
19#define GAUDI_DRIVER_SRAM_RESERVED_SIZE_FROM_START 0x80 /* 128 bytes */
Oded Gabbay99b9d7b2019-02-16 00:39:13 +020020
Ofir Bitton5de406c2020-09-10 10:56:26 +030021/*
22 * 128 SOBs reserved for collective wait
23 * 16 SOBs reserved for sync stream
24 */
25#define GAUDI_FIRST_AVAILABLE_W_S_SYNC_OBJECT 144
26
27/*
28 * 64 monitors reserved for collective wait
29 * 8 monitors reserved for sync stream
30 */
31#define GAUDI_FIRST_AVAILABLE_W_S_MONITOR 72
32
Oded Gabbay9494a8d2019-02-16 00:39:17 +020033/*
Oded Gabbay466c7822020-05-11 10:32:10 +030034 * Goya queue Numbering
Oded Gabbay9494a8d2019-02-16 00:39:17 +020035 *
Oded Gabbay90027292019-04-03 09:51:04 +030036 * The external queues (PCI DMA channels) MUST be before the internal queues
37 * and each group (PCI DMA channels and internal) must be contiguous inside
Oded Gabbay9494a8d2019-02-16 00:39:17 +020038 * itself but there can be a gap between the two groups (although not
39 * recommended)
40 */
41
42enum goya_queue_id {
43 GOYA_QUEUE_ID_DMA_0 = 0,
Dotan Barak4fd2cb12019-08-12 10:23:33 +030044 GOYA_QUEUE_ID_DMA_1 = 1,
45 GOYA_QUEUE_ID_DMA_2 = 2,
46 GOYA_QUEUE_ID_DMA_3 = 3,
47 GOYA_QUEUE_ID_DMA_4 = 4,
48 GOYA_QUEUE_ID_CPU_PQ = 5,
49 GOYA_QUEUE_ID_MME = 6, /* Internal queues start here */
50 GOYA_QUEUE_ID_TPC0 = 7,
51 GOYA_QUEUE_ID_TPC1 = 8,
52 GOYA_QUEUE_ID_TPC2 = 9,
53 GOYA_QUEUE_ID_TPC3 = 10,
54 GOYA_QUEUE_ID_TPC4 = 11,
55 GOYA_QUEUE_ID_TPC5 = 12,
56 GOYA_QUEUE_ID_TPC6 = 13,
57 GOYA_QUEUE_ID_TPC7 = 14,
Oded Gabbay9494a8d2019-02-16 00:39:17 +020058 GOYA_QUEUE_ID_SIZE
59};
60
Tomer Tayare8960ca2019-07-01 13:59:45 +000061/*
Oded Gabbay466c7822020-05-11 10:32:10 +030062 * Gaudi queue Numbering
63 * External queues (PCI DMA channels) are DMA_0_*, DMA_1_* and DMA_5_*.
64 * Except one CPU queue, all the rest are internal queues.
65 */
66
67enum gaudi_queue_id {
68 GAUDI_QUEUE_ID_DMA_0_0 = 0, /* external */
69 GAUDI_QUEUE_ID_DMA_0_1 = 1, /* external */
70 GAUDI_QUEUE_ID_DMA_0_2 = 2, /* external */
71 GAUDI_QUEUE_ID_DMA_0_3 = 3, /* external */
72 GAUDI_QUEUE_ID_DMA_1_0 = 4, /* external */
73 GAUDI_QUEUE_ID_DMA_1_1 = 5, /* external */
74 GAUDI_QUEUE_ID_DMA_1_2 = 6, /* external */
75 GAUDI_QUEUE_ID_DMA_1_3 = 7, /* external */
76 GAUDI_QUEUE_ID_CPU_PQ = 8, /* CPU */
77 GAUDI_QUEUE_ID_DMA_2_0 = 9, /* internal */
78 GAUDI_QUEUE_ID_DMA_2_1 = 10, /* internal */
79 GAUDI_QUEUE_ID_DMA_2_2 = 11, /* internal */
80 GAUDI_QUEUE_ID_DMA_2_3 = 12, /* internal */
81 GAUDI_QUEUE_ID_DMA_3_0 = 13, /* internal */
82 GAUDI_QUEUE_ID_DMA_3_1 = 14, /* internal */
83 GAUDI_QUEUE_ID_DMA_3_2 = 15, /* internal */
84 GAUDI_QUEUE_ID_DMA_3_3 = 16, /* internal */
85 GAUDI_QUEUE_ID_DMA_4_0 = 17, /* internal */
86 GAUDI_QUEUE_ID_DMA_4_1 = 18, /* internal */
87 GAUDI_QUEUE_ID_DMA_4_2 = 19, /* internal */
88 GAUDI_QUEUE_ID_DMA_4_3 = 20, /* internal */
Ofir Bitton0940cab2020-08-31 08:52:56 +030089 GAUDI_QUEUE_ID_DMA_5_0 = 21, /* internal */
90 GAUDI_QUEUE_ID_DMA_5_1 = 22, /* internal */
91 GAUDI_QUEUE_ID_DMA_5_2 = 23, /* internal */
92 GAUDI_QUEUE_ID_DMA_5_3 = 24, /* internal */
Oded Gabbay466c7822020-05-11 10:32:10 +030093 GAUDI_QUEUE_ID_DMA_6_0 = 25, /* internal */
94 GAUDI_QUEUE_ID_DMA_6_1 = 26, /* internal */
95 GAUDI_QUEUE_ID_DMA_6_2 = 27, /* internal */
96 GAUDI_QUEUE_ID_DMA_6_3 = 28, /* internal */
97 GAUDI_QUEUE_ID_DMA_7_0 = 29, /* internal */
98 GAUDI_QUEUE_ID_DMA_7_1 = 30, /* internal */
99 GAUDI_QUEUE_ID_DMA_7_2 = 31, /* internal */
100 GAUDI_QUEUE_ID_DMA_7_3 = 32, /* internal */
101 GAUDI_QUEUE_ID_MME_0_0 = 33, /* internal */
102 GAUDI_QUEUE_ID_MME_0_1 = 34, /* internal */
103 GAUDI_QUEUE_ID_MME_0_2 = 35, /* internal */
104 GAUDI_QUEUE_ID_MME_0_3 = 36, /* internal */
105 GAUDI_QUEUE_ID_MME_1_0 = 37, /* internal */
106 GAUDI_QUEUE_ID_MME_1_1 = 38, /* internal */
107 GAUDI_QUEUE_ID_MME_1_2 = 39, /* internal */
108 GAUDI_QUEUE_ID_MME_1_3 = 40, /* internal */
109 GAUDI_QUEUE_ID_TPC_0_0 = 41, /* internal */
110 GAUDI_QUEUE_ID_TPC_0_1 = 42, /* internal */
111 GAUDI_QUEUE_ID_TPC_0_2 = 43, /* internal */
112 GAUDI_QUEUE_ID_TPC_0_3 = 44, /* internal */
113 GAUDI_QUEUE_ID_TPC_1_0 = 45, /* internal */
114 GAUDI_QUEUE_ID_TPC_1_1 = 46, /* internal */
115 GAUDI_QUEUE_ID_TPC_1_2 = 47, /* internal */
116 GAUDI_QUEUE_ID_TPC_1_3 = 48, /* internal */
117 GAUDI_QUEUE_ID_TPC_2_0 = 49, /* internal */
118 GAUDI_QUEUE_ID_TPC_2_1 = 50, /* internal */
119 GAUDI_QUEUE_ID_TPC_2_2 = 51, /* internal */
120 GAUDI_QUEUE_ID_TPC_2_3 = 52, /* internal */
121 GAUDI_QUEUE_ID_TPC_3_0 = 53, /* internal */
122 GAUDI_QUEUE_ID_TPC_3_1 = 54, /* internal */
123 GAUDI_QUEUE_ID_TPC_3_2 = 55, /* internal */
124 GAUDI_QUEUE_ID_TPC_3_3 = 56, /* internal */
125 GAUDI_QUEUE_ID_TPC_4_0 = 57, /* internal */
126 GAUDI_QUEUE_ID_TPC_4_1 = 58, /* internal */
127 GAUDI_QUEUE_ID_TPC_4_2 = 59, /* internal */
128 GAUDI_QUEUE_ID_TPC_4_3 = 60, /* internal */
129 GAUDI_QUEUE_ID_TPC_5_0 = 61, /* internal */
130 GAUDI_QUEUE_ID_TPC_5_1 = 62, /* internal */
131 GAUDI_QUEUE_ID_TPC_5_2 = 63, /* internal */
132 GAUDI_QUEUE_ID_TPC_5_3 = 64, /* internal */
133 GAUDI_QUEUE_ID_TPC_6_0 = 65, /* internal */
134 GAUDI_QUEUE_ID_TPC_6_1 = 66, /* internal */
135 GAUDI_QUEUE_ID_TPC_6_2 = 67, /* internal */
136 GAUDI_QUEUE_ID_TPC_6_3 = 68, /* internal */
137 GAUDI_QUEUE_ID_TPC_7_0 = 69, /* internal */
138 GAUDI_QUEUE_ID_TPC_7_1 = 70, /* internal */
139 GAUDI_QUEUE_ID_TPC_7_2 = 71, /* internal */
140 GAUDI_QUEUE_ID_TPC_7_3 = 72, /* internal */
141 GAUDI_QUEUE_ID_NIC_0_0 = 73, /* internal */
142 GAUDI_QUEUE_ID_NIC_0_1 = 74, /* internal */
143 GAUDI_QUEUE_ID_NIC_0_2 = 75, /* internal */
144 GAUDI_QUEUE_ID_NIC_0_3 = 76, /* internal */
145 GAUDI_QUEUE_ID_NIC_1_0 = 77, /* internal */
146 GAUDI_QUEUE_ID_NIC_1_1 = 78, /* internal */
147 GAUDI_QUEUE_ID_NIC_1_2 = 79, /* internal */
148 GAUDI_QUEUE_ID_NIC_1_3 = 80, /* internal */
149 GAUDI_QUEUE_ID_NIC_2_0 = 81, /* internal */
150 GAUDI_QUEUE_ID_NIC_2_1 = 82, /* internal */
151 GAUDI_QUEUE_ID_NIC_2_2 = 83, /* internal */
152 GAUDI_QUEUE_ID_NIC_2_3 = 84, /* internal */
153 GAUDI_QUEUE_ID_NIC_3_0 = 85, /* internal */
154 GAUDI_QUEUE_ID_NIC_3_1 = 86, /* internal */
155 GAUDI_QUEUE_ID_NIC_3_2 = 87, /* internal */
156 GAUDI_QUEUE_ID_NIC_3_3 = 88, /* internal */
157 GAUDI_QUEUE_ID_NIC_4_0 = 89, /* internal */
158 GAUDI_QUEUE_ID_NIC_4_1 = 90, /* internal */
159 GAUDI_QUEUE_ID_NIC_4_2 = 91, /* internal */
160 GAUDI_QUEUE_ID_NIC_4_3 = 92, /* internal */
161 GAUDI_QUEUE_ID_NIC_5_0 = 93, /* internal */
162 GAUDI_QUEUE_ID_NIC_5_1 = 94, /* internal */
163 GAUDI_QUEUE_ID_NIC_5_2 = 95, /* internal */
164 GAUDI_QUEUE_ID_NIC_5_3 = 96, /* internal */
165 GAUDI_QUEUE_ID_NIC_6_0 = 97, /* internal */
166 GAUDI_QUEUE_ID_NIC_6_1 = 98, /* internal */
167 GAUDI_QUEUE_ID_NIC_6_2 = 99, /* internal */
168 GAUDI_QUEUE_ID_NIC_6_3 = 100, /* internal */
169 GAUDI_QUEUE_ID_NIC_7_0 = 101, /* internal */
170 GAUDI_QUEUE_ID_NIC_7_1 = 102, /* internal */
171 GAUDI_QUEUE_ID_NIC_7_2 = 103, /* internal */
172 GAUDI_QUEUE_ID_NIC_7_3 = 104, /* internal */
173 GAUDI_QUEUE_ID_NIC_8_0 = 105, /* internal */
174 GAUDI_QUEUE_ID_NIC_8_1 = 106, /* internal */
175 GAUDI_QUEUE_ID_NIC_8_2 = 107, /* internal */
176 GAUDI_QUEUE_ID_NIC_8_3 = 108, /* internal */
177 GAUDI_QUEUE_ID_NIC_9_0 = 109, /* internal */
178 GAUDI_QUEUE_ID_NIC_9_1 = 110, /* internal */
179 GAUDI_QUEUE_ID_NIC_9_2 = 111, /* internal */
180 GAUDI_QUEUE_ID_NIC_9_3 = 112, /* internal */
181 GAUDI_QUEUE_ID_SIZE
182};
183
184/*
Tomer Tayare8960ca2019-07-01 13:59:45 +0000185 * Engine Numbering
186 *
187 * Used in the "busy_engines_mask" field in `struct hl_info_hw_idle'
188 */
189
190enum goya_engine_id {
191 GOYA_ENGINE_ID_DMA_0 = 0,
192 GOYA_ENGINE_ID_DMA_1,
193 GOYA_ENGINE_ID_DMA_2,
194 GOYA_ENGINE_ID_DMA_3,
195 GOYA_ENGINE_ID_DMA_4,
196 GOYA_ENGINE_ID_MME_0,
197 GOYA_ENGINE_ID_TPC_0,
198 GOYA_ENGINE_ID_TPC_1,
199 GOYA_ENGINE_ID_TPC_2,
200 GOYA_ENGINE_ID_TPC_3,
201 GOYA_ENGINE_ID_TPC_4,
202 GOYA_ENGINE_ID_TPC_5,
203 GOYA_ENGINE_ID_TPC_6,
204 GOYA_ENGINE_ID_TPC_7,
205 GOYA_ENGINE_ID_SIZE
206};
207
Oded Gabbay466c7822020-05-11 10:32:10 +0300208enum gaudi_engine_id {
209 GAUDI_ENGINE_ID_DMA_0 = 0,
210 GAUDI_ENGINE_ID_DMA_1,
211 GAUDI_ENGINE_ID_DMA_2,
212 GAUDI_ENGINE_ID_DMA_3,
213 GAUDI_ENGINE_ID_DMA_4,
214 GAUDI_ENGINE_ID_DMA_5,
215 GAUDI_ENGINE_ID_DMA_6,
216 GAUDI_ENGINE_ID_DMA_7,
217 GAUDI_ENGINE_ID_MME_0,
218 GAUDI_ENGINE_ID_MME_1,
219 GAUDI_ENGINE_ID_MME_2,
220 GAUDI_ENGINE_ID_MME_3,
221 GAUDI_ENGINE_ID_TPC_0,
222 GAUDI_ENGINE_ID_TPC_1,
223 GAUDI_ENGINE_ID_TPC_2,
224 GAUDI_ENGINE_ID_TPC_3,
225 GAUDI_ENGINE_ID_TPC_4,
226 GAUDI_ENGINE_ID_TPC_5,
227 GAUDI_ENGINE_ID_TPC_6,
228 GAUDI_ENGINE_ID_TPC_7,
229 GAUDI_ENGINE_ID_NIC_0,
230 GAUDI_ENGINE_ID_NIC_1,
231 GAUDI_ENGINE_ID_NIC_2,
232 GAUDI_ENGINE_ID_NIC_3,
233 GAUDI_ENGINE_ID_NIC_4,
234 GAUDI_ENGINE_ID_NIC_5,
235 GAUDI_ENGINE_ID_NIC_6,
236 GAUDI_ENGINE_ID_NIC_7,
237 GAUDI_ENGINE_ID_NIC_8,
238 GAUDI_ENGINE_ID_NIC_9,
239 GAUDI_ENGINE_ID_SIZE
240};
241
Bharat Jauhari285c0fa2021-03-25 18:15:40 +0200242/*
243 * ASIC specific PLL index
244 *
245 * Used to retrieve in frequency info of different IPs via
246 * HL_INFO_PLL_FREQUENCY under HL_IOCTL_INFO IOCTL. The enums need to be
247 * used as an index in struct hl_pll_frequency_info
248 */
249
250enum hl_goya_pll_index {
251 HL_GOYA_CPU_PLL = 0,
252 HL_GOYA_IC_PLL,
253 HL_GOYA_MC_PLL,
254 HL_GOYA_MME_PLL,
255 HL_GOYA_PCI_PLL,
256 HL_GOYA_EMMC_PLL,
257 HL_GOYA_TPC_PLL,
258 HL_GOYA_PLL_MAX
259};
260
261enum hl_gaudi_pll_index {
262 HL_GAUDI_CPU_PLL = 0,
263 HL_GAUDI_PCI_PLL,
264 HL_GAUDI_SRAM_PLL,
265 HL_GAUDI_HBM_PLL,
266 HL_GAUDI_NIC_PLL,
267 HL_GAUDI_DMA_PLL,
268 HL_GAUDI_MESH_PLL,
269 HL_GAUDI_MME_PLL,
270 HL_GAUDI_TPC_PLL,
271 HL_GAUDI_IF_PLL,
272 HL_GAUDI_PLL_MAX
273};
274
Oded Gabbay511c1952021-09-01 19:20:00 +0300275/**
276 * enum hl_device_status - Device status information.
277 * @HL_DEVICE_STATUS_OPERATIONAL: Device is operational.
278 * @HL_DEVICE_STATUS_IN_RESET: Device is currently during reset.
279 * @HL_DEVICE_STATUS_MALFUNCTION: Device is unusable.
280 * @HL_DEVICE_STATUS_NEEDS_RESET: Device needs reset because auto reset was disabled.
281 * @HL_DEVICE_STATUS_IN_DEVICE_CREATION: Device is operational but its creation is still in
282 * progress.
283 * @HL_DEVICE_STATUS_LAST: Last status.
284 */
Dalit Ben Zooraa957082019-03-24 10:15:44 +0200285enum hl_device_status {
286 HL_DEVICE_STATUS_OPERATIONAL,
287 HL_DEVICE_STATUS_IN_RESET,
Ofir Bitton66a76402020-10-05 14:40:10 +0300288 HL_DEVICE_STATUS_MALFUNCTION,
Omer Shpigelman71731092021-08-16 13:27:12 +0300289 HL_DEVICE_STATUS_NEEDS_RESET,
290 HL_DEVICE_STATUS_IN_DEVICE_CREATION,
291 HL_DEVICE_STATUS_LAST = HL_DEVICE_STATUS_IN_DEVICE_CREATION
Dalit Ben Zooraa957082019-03-24 10:15:44 +0200292};
293
Oded Gabbay5dc9ffa2021-07-15 10:48:43 +0300294enum hl_server_type {
295 HL_SERVER_TYPE_UNKNOWN = 0,
296 HL_SERVER_GAUDI_HLS1 = 1,
297 HL_SERVER_GAUDI_HLS1H = 2,
298 HL_SERVER_GAUDI_TYPE1 = 3,
299 HL_SERVER_GAUDI_TYPE2 = 4
300};
301
Oded Gabbayf388ec72019-07-16 08:55:04 +0300302/* Opcode for management ioctl
303 *
Oded Gabbay75b3cb22019-08-28 17:32:04 +0300304 * HW_IP_INFO - Receive information about different IP blocks in the
305 * device.
306 * HL_INFO_HW_EVENTS - Receive an array describing how many times each event
307 * occurred since the last hard reset.
308 * HL_INFO_DRAM_USAGE - Retrieve the dram usage inside the device and of the
309 * specific context. This is relevant only for devices
310 * where the dram is managed by the kernel driver
311 * HL_INFO_HW_IDLE - Retrieve information about the idle status of each
312 * internal engine.
Oded Gabbayf388ec72019-07-16 08:55:04 +0300313 * HL_INFO_DEVICE_STATUS - Retrieve the device's status. This opcode doesn't
314 * require an open context.
Oded Gabbay62c1e122019-10-10 15:48:59 +0300315 * HL_INFO_DEVICE_UTILIZATION - Retrieve the total utilization of the device
316 * over the last period specified by the user.
317 * The period can be between 100ms to 1s, in
318 * resolution of 100ms. The return value is a
319 * percentage of the utilization rate.
Oded Gabbaye9730762019-08-28 21:51:52 +0300320 * HL_INFO_HW_EVENTS_AGGREGATE - Receive an array describing how many times each
321 * event occurred since the driver was loaded.
Oded Gabbay62c1e122019-10-10 15:48:59 +0300322 * HL_INFO_CLK_RATE - Retrieve the current and maximum clock rate
323 * of the device in MHz. The maximum clock rate is
324 * configurable via sysfs parameter
Moti Haimovski52c01b02019-11-03 16:26:44 +0200325 * HL_INFO_RESET_COUNT - Retrieve the counts of the soft and hard reset
326 * operations performed on the device since the last
327 * time the driver was loaded.
Tomer Tayar25e7aeb2020-03-31 22:46:36 +0300328 * HL_INFO_TIME_SYNC - Retrieve the device's time alongside the host's time
329 * for synchronization.
Ofir Bittondb491e42020-06-18 09:51:16 +0300330 * HL_INFO_CS_COUNTERS - Retrieve command submission counters
Ofir Bitton0a068ad2020-07-21 10:49:51 +0300331 * HL_INFO_PCI_COUNTERS - Retrieve PCI counters
332 * HL_INFO_CLK_THROTTLE_REASON - Retrieve clock throttling reason
Ofir Bitton843839b2020-07-19 11:08:09 +0300333 * HL_INFO_SYNC_MANAGER - Retrieve sync manager info per dcore
farah kassabri9f306492020-08-09 16:25:53 +0300334 * HL_INFO_TOTAL_ENERGY - Retrieve total energy consumption
Alon Mizrahi429f1572020-12-01 18:44:11 +0200335 * HL_INFO_PLL_FREQUENCY - Retrieve PLL frequency
Tomer Tayar75a5c442021-11-18 10:44:05 +0200336 * HL_INFO_POWER - Retrieve power information
Yuri Nudelmane307b302021-05-24 11:25:21 +0300337 * HL_INFO_OPEN_STATS - Retrieve info regarding recent device open calls
farah kassabri49c052d2021-10-24 19:02:32 +0300338 * HL_INFO_DRAM_REPLACED_ROWS - Retrieve DRAM replaced rows info
339 * HL_INFO_DRAM_PENDING_ROWS - Retrieve DRAM pending rows num
Dani Liberman3e55b5d2021-11-03 10:09:59 +0200340 * HL_INFO_LAST_ERR_OPEN_DEV_TIME - Retrieve timestamp of the last time the device was opened
341 * and CS timeout or razwi error occurred.
342 * HL_INFO_CS_TIMEOUT_EVENT - Retrieve CS timeout timestamp and its related CS sequence number.
343 * HL_INFO_RAZWI_EVENT - Retrieve parameters of razwi:
344 * Timestamp of razwi.
345 * The address which accessing it caused the razwi.
346 * Razwi initiator.
347 * Razwi cause, was it a page fault or MMU access error.
Oded Gabbayf388ec72019-07-16 08:55:04 +0300348 */
Oded Gabbay75b3cb22019-08-28 17:32:04 +0300349#define HL_INFO_HW_IP_INFO 0
350#define HL_INFO_HW_EVENTS 1
351#define HL_INFO_DRAM_USAGE 2
352#define HL_INFO_HW_IDLE 3
353#define HL_INFO_DEVICE_STATUS 4
354#define HL_INFO_DEVICE_UTILIZATION 6
Oded Gabbaye9730762019-08-28 21:51:52 +0300355#define HL_INFO_HW_EVENTS_AGGREGATE 7
Oded Gabbay62c1e122019-10-10 15:48:59 +0300356#define HL_INFO_CLK_RATE 8
Moti Haimovski52c01b02019-11-03 16:26:44 +0200357#define HL_INFO_RESET_COUNT 9
Tomer Tayar25e7aeb2020-03-31 22:46:36 +0300358#define HL_INFO_TIME_SYNC 10
Ofir Bittondb491e42020-06-18 09:51:16 +0300359#define HL_INFO_CS_COUNTERS 11
Ofir Bitton0a068ad2020-07-21 10:49:51 +0300360#define HL_INFO_PCI_COUNTERS 12
361#define HL_INFO_CLK_THROTTLE_REASON 13
Ofir Bitton843839b2020-07-19 11:08:09 +0300362#define HL_INFO_SYNC_MANAGER 14
farah kassabri9f306492020-08-09 16:25:53 +0300363#define HL_INFO_TOTAL_ENERGY 15
Alon Mizrahi41478642020-11-17 14:25:14 +0200364#define HL_INFO_PLL_FREQUENCY 16
Sagiv Ozeri586f2ca2021-02-23 18:00:05 +0200365#define HL_INFO_POWER 17
Yuri Nudelmane307b302021-05-24 11:25:21 +0300366#define HL_INFO_OPEN_STATS 18
farah kassabri49c052d2021-10-24 19:02:32 +0300367#define HL_INFO_DRAM_REPLACED_ROWS 21
368#define HL_INFO_DRAM_PENDING_ROWS 22
Dani Liberman3e55b5d2021-11-03 10:09:59 +0200369#define HL_INFO_LAST_ERR_OPEN_DEV_TIME 23
370#define HL_INFO_CS_TIMEOUT_EVENT 24
371#define HL_INFO_RAZWI_EVENT 25
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200372
Dani Liberman3e55b5d2021-11-03 10:09:59 +0200373#define HL_INFO_VERSION_MAX_LEN 128
Oded Gabbay91edbf22019-10-16 11:53:52 +0300374#define HL_INFO_CARD_NAME_MAX_LEN 16
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200375
Oded Gabbay5dc9ffa2021-07-15 10:48:43 +0300376/**
377 * struct hl_info_hw_ip_info - hardware information on various IPs in the ASIC
378 * @sram_base_address: The first SRAM physical base address that is free to be
379 * used by the user.
380 * @dram_base_address: The first DRAM virtual or physical base address that is
381 * free to be used by the user.
382 * @dram_size: The DRAM size that is available to the user.
383 * @sram_size: The SRAM size that is available to the user.
384 * @num_of_events: The number of events that can be received from the f/w. This
385 * is needed so the user can what is the size of the h/w events
386 * array he needs to pass to the kernel when he wants to fetch
387 * the event counters.
388 * @device_id: PCI device ID of the ASIC.
389 * @module_id: Module ID of the ASIC for mezzanine cards in servers
390 * (From OCP spec).
391 * @first_available_interrupt_id: The first available interrupt ID for the user
392 * to be used when it works with user interrupts.
393 * @server_type: Server type that the Gaudi ASIC is currently installed in.
394 * The value is according to enum hl_server_type
395 * @cpld_version: CPLD version on the board.
396 * @psoc_pci_pll_nr: PCI PLL NR value. Needed by the profiler in some ASICs.
397 * @psoc_pci_pll_nf: PCI PLL NF value. Needed by the profiler in some ASICs.
398 * @psoc_pci_pll_od: PCI PLL OD value. Needed by the profiler in some ASICs.
399 * @psoc_pci_pll_div_factor: PCI PLL DIV factor value. Needed by the profiler
400 * in some ASICs.
401 * @tpc_enabled_mask: Bit-mask that represents which TPCs are enabled. Relevant
402 * for Goya/Gaudi only.
403 * @dram_enabled: Whether the DRAM is enabled.
404 * @cpucp_version: The CPUCP f/w version.
405 * @card_name: The card name as passed by the f/w.
406 * @dram_page_size: The DRAM physical page size.
407 */
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200408struct hl_info_hw_ip_info {
409 __u64 sram_base_address;
410 __u64 dram_base_address;
411 __u64 dram_size;
412 __u32 sram_size;
413 __u32 num_of_events;
Oded Gabbay5dc9ffa2021-07-15 10:48:43 +0300414 __u32 device_id;
415 __u32 module_id;
Ofir Bittone1fa7242021-01-06 15:40:37 +0200416 __u32 reserved;
417 __u16 first_available_interrupt_id;
Oded Gabbay5dc9ffa2021-07-15 10:48:43 +0300418 __u16 server_type;
Oded Gabbay2f553422020-08-15 16:28:10 +0300419 __u32 cpld_version;
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200420 __u32 psoc_pci_pll_nr;
421 __u32 psoc_pci_pll_nf;
422 __u32 psoc_pci_pll_od;
423 __u32 psoc_pci_pll_div_factor;
424 __u8 tpc_enabled_mask;
425 __u8 dram_enabled;
426 __u8 pad[2];
Oded Gabbay2f553422020-08-15 16:28:10 +0300427 __u8 cpucp_version[HL_INFO_VERSION_MAX_LEN];
Oded Gabbay91edbf22019-10-16 11:53:52 +0300428 __u8 card_name[HL_INFO_CARD_NAME_MAX_LEN];
Oded Gabbay5dc9ffa2021-07-15 10:48:43 +0300429 __u64 reserved2;
Moti Haimovski0eda23d2020-12-07 09:10:34 +0200430 __u64 dram_page_size;
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200431};
432
433struct hl_info_dram_usage {
434 __u64 dram_free_mem;
435 __u64 ctx_dram_mem;
436};
437
Ohad Sharabicf303392021-01-17 16:01:56 +0200438#define HL_BUSY_ENGINES_MASK_EXT_SIZE 2
439
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200440struct hl_info_hw_idle {
441 __u32 is_idle;
Tomer Tayare8960ca2019-07-01 13:59:45 +0000442 /*
443 * Bitmask of busy engines.
444 * Bits definition is according to `enum <chip>_enging_id'.
445 */
446 __u32 busy_engines_mask;
farah kassabrid90416c2020-08-12 17:20:13 +0300447
448 /*
449 * Extended Bitmask of busy engines.
450 * Bits definition is according to `enum <chip>_enging_id'.
451 */
Ohad Sharabicf303392021-01-17 16:01:56 +0200452 __u64 busy_engines_mask_ext[HL_BUSY_ENGINES_MASK_EXT_SIZE];
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200453};
454
Dalit Ben Zooraa957082019-03-24 10:15:44 +0200455struct hl_info_device_status {
456 __u32 status;
457 __u32 pad;
458};
459
Oded Gabbay75b3cb22019-08-28 17:32:04 +0300460struct hl_info_device_utilization {
461 __u32 utilization;
462 __u32 pad;
463};
464
Oded Gabbay62c1e122019-10-10 15:48:59 +0300465struct hl_info_clk_rate {
466 __u32 cur_clk_rate_mhz;
467 __u32 max_clk_rate_mhz;
468};
469
Moti Haimovski52c01b02019-11-03 16:26:44 +0200470struct hl_info_reset_count {
471 __u32 hard_reset_cnt;
472 __u32 soft_reset_cnt;
473};
474
Tomer Tayar25e7aeb2020-03-31 22:46:36 +0300475struct hl_info_time_sync {
476 __u64 device_time;
477 __u64 host_time;
478};
479
Ofir Bittondb491e42020-06-18 09:51:16 +0300480/**
Ofir Bitton0a068ad2020-07-21 10:49:51 +0300481 * struct hl_info_pci_counters - pci counters
482 * @rx_throughput: PCI rx throughput KBps
483 * @tx_throughput: PCI tx throughput KBps
484 * @replay_cnt: PCI replay counter
485 */
486struct hl_info_pci_counters {
487 __u64 rx_throughput;
488 __u64 tx_throughput;
489 __u64 replay_cnt;
490};
491
Ofir Bitton1679c7e2021-10-25 09:47:04 +0300492enum hl_clk_throttling_type {
493 HL_CLK_THROTTLE_TYPE_POWER,
494 HL_CLK_THROTTLE_TYPE_THERMAL,
495 HL_CLK_THROTTLE_TYPE_MAX
496};
497
498/* clk_throttling_reason masks */
499#define HL_CLK_THROTTLE_POWER (1 << HL_CLK_THROTTLE_TYPE_POWER)
500#define HL_CLK_THROTTLE_THERMAL (1 << HL_CLK_THROTTLE_TYPE_THERMAL)
Ofir Bitton0a068ad2020-07-21 10:49:51 +0300501
502/**
503 * struct hl_info_clk_throttle - clock throttling reason
504 * @clk_throttling_reason: each bit represents a clk throttling reason
Ofir Bitton1679c7e2021-10-25 09:47:04 +0300505 * @clk_throttling_timestamp_us: represents CPU timestamp in microseconds of the start-event
506 * @clk_throttling_duration_ns: the clock throttle time in nanosec
Ofir Bitton0a068ad2020-07-21 10:49:51 +0300507 */
508struct hl_info_clk_throttle {
509 __u32 clk_throttling_reason;
Ofir Bitton1679c7e2021-10-25 09:47:04 +0300510 __u32 pad;
511 __u64 clk_throttling_timestamp_us[HL_CLK_THROTTLE_TYPE_MAX];
512 __u64 clk_throttling_duration_ns[HL_CLK_THROTTLE_TYPE_MAX];
Ofir Bitton0a068ad2020-07-21 10:49:51 +0300513};
514
515/**
farah kassabri9f306492020-08-09 16:25:53 +0300516 * struct hl_info_energy - device energy information
517 * @total_energy_consumption: total device energy consumption
518 */
519struct hl_info_energy {
520 __u64 total_energy_consumption;
521};
522
Alon Mizrahi41478642020-11-17 14:25:14 +0200523#define HL_PLL_NUM_OUTPUTS 4
524
525struct hl_pll_frequency_info {
526 __u16 output[HL_PLL_NUM_OUTPUTS];
527};
528
farah kassabri9f306492020-08-09 16:25:53 +0300529/**
Yuri Nudelmane307b302021-05-24 11:25:21 +0300530 * struct hl_open_stats_info - device open statistics information
531 * @open_counter: ever growing counter, increased on each successful dev open
532 * @last_open_period_ms: duration (ms) device was open last time
533 */
534struct hl_open_stats_info {
535 __u64 open_counter;
536 __u64 last_open_period_ms;
537};
538
539/**
Sagiv Ozeri586f2ca2021-02-23 18:00:05 +0200540 * struct hl_power_info - power information
541 * @power: power consumption
542 */
543struct hl_power_info {
544 __u64 power;
545};
546
547/**
Ofir Bitton843839b2020-07-19 11:08:09 +0300548 * struct hl_info_sync_manager - sync manager information
549 * @first_available_sync_object: first available sob
550 * @first_available_monitor: first available monitor
Ofir Bittone52606d2021-01-27 16:34:37 +0200551 * @first_available_cq: first available cq
Ofir Bitton843839b2020-07-19 11:08:09 +0300552 */
553struct hl_info_sync_manager {
554 __u32 first_available_sync_object;
555 __u32 first_available_monitor;
Ofir Bittone52606d2021-01-27 16:34:37 +0200556 __u32 first_available_cq;
557 __u32 reserved;
Ofir Bitton843839b2020-07-19 11:08:09 +0300558};
559
560/**
Ofir Bittondb491e42020-06-18 09:51:16 +0300561 * struct hl_info_cs_counters - command submission counters
farah kassabrie7536432020-10-12 14:30:26 +0300562 * @total_out_of_mem_drop_cnt: total dropped due to memory allocation issue
563 * @ctx_out_of_mem_drop_cnt: context dropped due to memory allocation issue
564 * @total_parsing_drop_cnt: total dropped due to error in packet parsing
565 * @ctx_parsing_drop_cnt: context dropped due to error in packet parsing
566 * @total_queue_full_drop_cnt: total dropped due to queue full
567 * @ctx_queue_full_drop_cnt: context dropped due to queue full
568 * @total_device_in_reset_drop_cnt: total dropped due to device in reset
569 * @ctx_device_in_reset_drop_cnt: context dropped due to device in reset
570 * @total_max_cs_in_flight_drop_cnt: total dropped due to maximum CS in-flight
571 * @ctx_max_cs_in_flight_drop_cnt: context dropped due to maximum CS in-flight
Alon Mizrahia3fd2832020-12-08 16:14:01 +0200572 * @total_validation_drop_cnt: total dropped due to validation error
573 * @ctx_validation_drop_cnt: context dropped due to validation error
Ofir Bittondb491e42020-06-18 09:51:16 +0300574 */
Ofir Bittondb491e42020-06-18 09:51:16 +0300575struct hl_info_cs_counters {
farah kassabrie7536432020-10-12 14:30:26 +0300576 __u64 total_out_of_mem_drop_cnt;
577 __u64 ctx_out_of_mem_drop_cnt;
578 __u64 total_parsing_drop_cnt;
579 __u64 ctx_parsing_drop_cnt;
580 __u64 total_queue_full_drop_cnt;
581 __u64 ctx_queue_full_drop_cnt;
582 __u64 total_device_in_reset_drop_cnt;
583 __u64 ctx_device_in_reset_drop_cnt;
584 __u64 total_max_cs_in_flight_drop_cnt;
585 __u64 ctx_max_cs_in_flight_drop_cnt;
Alon Mizrahia3fd2832020-12-08 16:14:01 +0200586 __u64 total_validation_drop_cnt;
587 __u64 ctx_validation_drop_cnt;
Ofir Bittondb491e42020-06-18 09:51:16 +0300588};
589
Dani Liberman3e55b5d2021-11-03 10:09:59 +0200590/**
591 * struct hl_info_last_err_open_dev_time - last error boot information.
592 * @timestamp: timestamp of last time the device was opened and error occurred.
593 */
594struct hl_info_last_err_open_dev_time {
595 __s64 timestamp;
596};
597
598/**
599 * struct hl_info_cs_timeout_event - last CS timeout information.
600 * @timestamp: timestamp when last CS timeout event occurred.
601 * @seq: sequence number of last CS timeout event.
602 */
603struct hl_info_cs_timeout_event {
604 __s64 timestamp;
605 __u64 seq;
606};
607
608#define HL_RAZWI_PAGE_FAULT 0
609#define HL_RAZWI_MMU_ACCESS_ERROR 1
610
611/**
612 * struct hl_info_razwi_event - razwi information.
613 * @timestamp: timestamp of razwi.
614 * @addr: address which accessing it caused razwi.
615 * @engine_id_1: engine id of the razwi initiator, if it was initiated by engine that does not
616 * have engine id it will be set to U16_MAX.
617 * @engine_id_2: second engine id of razwi initiator. Might happen that razwi have 2 possible
618 * engines which one them caused the razwi. In that case, it will contain the
619 * second possible engine id, otherwise it will be set to U16_MAX.
620 * @no_engine_id: if razwi initiator does not have engine id, this field will be set to 1,
621 * otherwise 0.
622 * @error_type: cause of razwi, page fault or access error, otherwise it will be set to U8_MAX.
623 * @pad: padding to 64 bit.
624 */
625struct hl_info_razwi_event {
626 __s64 timestamp;
627 __u64 addr;
628 __u16 engine_id_1;
629 __u16 engine_id_2;
630 __u8 no_engine_id;
631 __u8 error_type;
632 __u8 pad[2];
633};
634
Ofir Bitton843839b2020-07-19 11:08:09 +0300635enum gaudi_dcores {
636 HL_GAUDI_WS_DCORE,
637 HL_GAUDI_WN_DCORE,
638 HL_GAUDI_EN_DCORE,
639 HL_GAUDI_ES_DCORE
640};
641
Oded Gabbay511c1952021-09-01 19:20:00 +0300642/**
643 * struct hl_info_args - Main structure to retrieve device related information.
644 * @return_pointer: User space address of the relevant structure related to HL_INFO_* operation
645 * mentioned in @op.
646 * @return_size: Size of the structure used in @return_pointer, just like "size" in "snprintf", it
647 * limits how many bytes the kernel can write. For hw_events array, the size should be
648 * hl_info_hw_ip_info.num_of_events * sizeof(__u32).
649 * @op: Defines which type of information to be retrieved. Refer HL_INFO_* for details.
650 * @dcore_id: DCORE id for which the information is relevant (for Gaudi refer to enum gaudi_dcores).
651 * @ctx_id: Context ID of the user. Currently not in use.
652 * @period_ms: Period value, in milliseconds, for utilization rate in range 100ms - 1000ms in 100 ms
653 * resolution. Currently not in use.
654 * @pll_index: Index as defined in hl_<asic type>_pll_index enumeration.
655 * @pad: Padding to 64 bit.
656 */
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200657struct hl_info_args {
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200658 __u64 return_pointer;
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200659 __u32 return_size;
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200660 __u32 op;
661
Oded Gabbay75b3cb22019-08-28 17:32:04 +0300662 union {
Ofir Bitton843839b2020-07-19 11:08:09 +0300663 __u32 dcore_id;
Oded Gabbay75b3cb22019-08-28 17:32:04 +0300664 __u32 ctx_id;
Oded Gabbay75b3cb22019-08-28 17:32:04 +0300665 __u32 period_ms;
Alon Mizrahi41478642020-11-17 14:25:14 +0200666 __u32 pll_index;
Oded Gabbay75b3cb22019-08-28 17:32:04 +0300667 };
668
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200669 __u32 pad;
670};
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200671
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200672/* Opcode to create a new command buffer */
673#define HL_CB_OP_CREATE 0
674/* Opcode to destroy previously created command buffer */
675#define HL_CB_OP_DESTROY 1
Tomer Tayarf44afb52020-09-02 13:43:32 +0300676/* Opcode to retrieve information about a command buffer */
677#define HL_CB_OP_INFO 2
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200678
Oded Gabbay39b42512020-04-17 12:12:13 +0300679/* 2MB minus 32 bytes for 2xMSG_PROT */
680#define HL_MAX_CB_SIZE (0x200000 - 32)
Oded Gabbay5d101252019-11-10 16:08:26 +0200681
Tomer Tayaref6a0f62020-07-09 16:17:48 +0300682/* Indicates whether the command buffer should be mapped to the device's MMU */
farah kassabrib9d31ca2021-11-02 11:34:18 +0200683#define HL_CB_FLAGS_MAP 0x1
684
685/* Used with HL_CB_OP_INFO opcode to get the device va address for kernel mapped CB */
686#define HL_CB_FLAGS_GET_DEVICE_VA 0x2
Tomer Tayaref6a0f62020-07-09 16:17:48 +0300687
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200688struct hl_cb_in {
689 /* Handle of CB or 0 if we want to create one */
690 __u64 cb_handle;
691 /* HL_CB_OP_* */
692 __u32 op;
Oded Gabbay5d101252019-11-10 16:08:26 +0200693 /* Size of CB. Maximum size is HL_MAX_CB_SIZE. The minimum size that
694 * will be allocated, regardless of this parameter's value, is PAGE_SIZE
Oded Gabbay541664d32019-02-28 11:55:44 +0200695 */
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200696 __u32 cb_size;
697 /* Context ID - Currently not in use */
698 __u32 ctx_id;
Tomer Tayaref6a0f62020-07-09 16:17:48 +0300699 /* HL_CB_FLAGS_* */
700 __u32 flags;
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200701};
702
703struct hl_cb_out {
Tomer Tayarf44afb52020-09-02 13:43:32 +0300704 union {
705 /* Handle of CB */
706 __u64 cb_handle;
707
farah kassabrib9d31ca2021-11-02 11:34:18 +0200708 union {
709 /* Information about CB */
710 struct {
711 /* Usage count of CB */
712 __u32 usage_cnt;
713 __u32 pad;
714 };
715
716 /* CB mapped address to device MMU */
717 __u64 device_va;
Tomer Tayarf44afb52020-09-02 13:43:32 +0300718 };
719 };
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200720};
721
722union hl_cb_args {
723 struct hl_cb_in in;
724 struct hl_cb_out out;
725};
726
Tal Cohen4bb1f2f2020-06-03 09:25:27 +0300727/* HL_CS_CHUNK_FLAGS_ values
728 *
729 * HL_CS_CHUNK_FLAGS_USER_ALLOC_CB:
730 * Indicates if the CB was allocated and mapped by userspace.
731 * User allocated CB is a command buffer allocated by the user, via malloc
732 * (or similar). After allocating the CB, the user invokes “memory ioctl”
733 * to map the user memory into a device virtual address. The user provides
734 * this address via the cb_handle field. The interface provides the
735 * ability to create a large CBs, Which aren’t limited to
736 * “HL_MAX_CB_SIZE”. Therefore, it increases the PCI-DMA queues
737 * throughput. This CB allocation method also reduces the use of Linux
738 * DMA-able memory pool. Which are limited and used by other Linux
739 * sub-systems.
740 */
741#define HL_CS_CHUNK_FLAGS_USER_ALLOC_CB 0x1
742
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200743/*
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200744 * This structure size must always be fixed to 64-bytes for backward
745 * compatibility
746 */
747struct hl_cs_chunk {
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300748 union {
749 /* For external queue, this represents a Handle of CB on the
750 * Host.
751 * For internal queue in Goya, this represents an SRAM or
752 * a DRAM address of the internal CB. In Gaudi, this might also
753 * represent a mapped host address of the CB.
754 *
755 * A mapped host address is in the device address space, after
756 * a host address was mapped by the device MMU.
757 */
758 __u64 cb_handle;
759
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300760 /* Relevant only when HL_CS_FLAGS_WAIT or
farah kassabridadf17a2021-05-24 18:09:22 +0300761 * HL_CS_FLAGS_COLLECTIVE_WAIT is set
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300762 * This holds address of array of u64 values that contain
farah kassabridadf17a2021-05-24 18:09:22 +0300763 * signal CS sequence numbers. The wait described by
764 * this job will listen on all those signals
765 * (wait event per signal)
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300766 */
767 __u64 signal_seq_arr;
farah kassabridadf17a2021-05-24 18:09:22 +0300768
769 /*
770 * Relevant only when HL_CS_FLAGS_WAIT or
771 * HL_CS_FLAGS_COLLECTIVE_WAIT is set
772 * along with HL_CS_FLAGS_ENCAP_SIGNALS.
773 * This is the CS sequence which has the encapsulated signals.
774 */
775 __u64 encaps_signal_seq;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300776 };
777
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200778 /* Index of queue to put the CB on */
779 __u32 queue_index;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300780
781 union {
782 /*
783 * Size of command buffer with valid packets
784 * Can be smaller then actual CB size
785 */
786 __u32 cb_size;
787
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300788 /* Relevant only when HL_CS_FLAGS_WAIT or
789 * HL_CS_FLAGS_COLLECTIVE_WAIT is set.
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300790 * Number of entries in signal_seq_arr
791 */
792 __u32 num_signal_seq_arr;
farah kassabridadf17a2021-05-24 18:09:22 +0300793
794 /* Relevant only when HL_CS_FLAGS_WAIT or
795 * HL_CS_FLAGS_COLLECTIVE_WAIT is set along
796 * with HL_CS_FLAGS_ENCAP_SIGNALS
797 * This set the signals range that the user want to wait for
798 * out of the whole reserved signals range.
799 * e.g if the signals range is 20, and user don't want
800 * to wait for signal 8, so he set this offset to 7, then
801 * he call the API again with 9 and so on till 20.
802 */
803 __u32 encaps_signal_offset;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300804 };
805
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200806 /* HL_CS_CHUNK_FLAGS_* */
807 __u32 cs_chunk_flags;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300808
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300809 /* Relevant only when HL_CS_FLAGS_COLLECTIVE_WAIT is set.
810 * This holds the collective engine ID. The wait described by this job
811 * will sync with this engine and with all NICs before completion.
812 */
813 __u32 collective_engine_id;
814
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200815 /* Align structure to 64 bytes */
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300816 __u32 pad[10];
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200817};
818
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300819/* SIGNAL and WAIT/COLLECTIVE_WAIT flags are mutually exclusive */
Ofir Bittonc209e742020-12-03 17:12:09 +0200820#define HL_CS_FLAGS_FORCE_RESTORE 0x1
821#define HL_CS_FLAGS_SIGNAL 0x2
822#define HL_CS_FLAGS_WAIT 0x4
823#define HL_CS_FLAGS_COLLECTIVE_WAIT 0x8
824#define HL_CS_FLAGS_TIMESTAMP 0x20
825#define HL_CS_FLAGS_STAGED_SUBMISSION 0x40
826#define HL_CS_FLAGS_STAGED_SUBMISSION_FIRST 0x80
827#define HL_CS_FLAGS_STAGED_SUBMISSION_LAST 0x100
Alon Mizrahicf393952021-02-22 15:53:24 +0200828#define HL_CS_FLAGS_CUSTOM_TIMEOUT 0x200
Yuri Nudelman8e8125f2021-05-25 14:49:52 +0300829#define HL_CS_FLAGS_SKIP_RESET_ON_TIMEOUT 0x400
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200830
farah kassabridadf17a2021-05-24 18:09:22 +0300831/*
832 * The encapsulated signals CS is merged into the existing CS ioctls.
833 * In order to use this feature need to follow the below procedure:
834 * 1. Reserve signals, set the CS type to HL_CS_FLAGS_RESERVE_SIGNALS_ONLY
835 * the output of this API will be the SOB offset from CFG_BASE.
836 * this address will be used to patch CB cmds to do the signaling for this
837 * SOB by incrementing it's value.
838 * for reverting the reservation use HL_CS_FLAGS_UNRESERVE_SIGNALS_ONLY
839 * CS type, note that this might fail if out-of-sync happened to the SOB
840 * value, in case other signaling request to the same SOB occurred between
841 * reserve-unreserve calls.
842 * 2. Use the staged CS to do the encapsulated signaling jobs.
843 * use HL_CS_FLAGS_STAGED_SUBMISSION and HL_CS_FLAGS_STAGED_SUBMISSION_FIRST
844 * along with HL_CS_FLAGS_ENCAP_SIGNALS flag, and set encaps_signal_offset
845 * field. This offset allows app to wait on part of the reserved signals.
846 * 3. Use WAIT/COLLECTIVE WAIT CS along with HL_CS_FLAGS_ENCAP_SIGNALS flag
847 * to wait for the encapsulated signals.
848 */
849#define HL_CS_FLAGS_ENCAP_SIGNALS 0x800
850#define HL_CS_FLAGS_RESERVE_SIGNALS_ONLY 0x1000
851#define HL_CS_FLAGS_UNRESERVE_SIGNALS_ONLY 0x2000
852
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200853#define HL_CS_STATUS_SUCCESS 0
854
Oded Gabbay5d101252019-11-10 16:08:26 +0200855#define HL_MAX_JOBS_PER_CS 512
856
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200857struct hl_cs_in {
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300858
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200859 /* this holds address of array of hl_cs_chunk for restore phase */
860 __u64 chunks_restore;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300861
862 /* holds address of array of hl_cs_chunk for execution phase */
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200863 __u64 chunks_execute;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300864
farah kassabridadf17a2021-05-24 18:09:22 +0300865 union {
866 /*
867 * Sequence number of a staged submission CS
868 * valid only if HL_CS_FLAGS_STAGED_SUBMISSION is set and
869 * HL_CS_FLAGS_STAGED_SUBMISSION_FIRST is unset.
870 */
871 __u64 seq;
872
873 /*
874 * Encapsulated signals handle id
875 * Valid for two flows:
876 * 1. CS with encapsulated signals:
877 * when HL_CS_FLAGS_STAGED_SUBMISSION and
878 * HL_CS_FLAGS_STAGED_SUBMISSION_FIRST
879 * and HL_CS_FLAGS_ENCAP_SIGNALS are set.
880 * 2. unreserve signals:
881 * valid when HL_CS_FLAGS_UNRESERVE_SIGNALS_ONLY is set.
882 */
883 __u32 encaps_sig_handle_id;
884
885 /* Valid only when HL_CS_FLAGS_RESERVE_SIGNALS_ONLY is set */
886 struct {
887 /* Encapsulated signals number */
888 __u32 encaps_signals_count;
889
890 /* Encapsulated signals queue index (stream) */
891 __u32 encaps_signals_q_idx;
892 };
893 };
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300894
Oded Gabbay5d101252019-11-10 16:08:26 +0200895 /* Number of chunks in restore phase array. Maximum number is
896 * HL_MAX_JOBS_PER_CS
897 */
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200898 __u32 num_chunks_restore;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300899
Oded Gabbay5d101252019-11-10 16:08:26 +0200900 /* Number of chunks in execution array. Maximum number is
901 * HL_MAX_JOBS_PER_CS
902 */
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200903 __u32 num_chunks_execute;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300904
Oded Gabbay131d1ba2021-04-02 22:24:38 +0300905 /* timeout in seconds - valid only if HL_CS_FLAGS_CUSTOM_TIMEOUT
906 * is set
907 */
908 __u32 timeout;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300909
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200910 /* HL_CS_FLAGS_* */
911 __u32 cs_flags;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300912
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200913 /* Context ID - Currently not in use */
914 __u32 ctx_id;
915};
916
917struct hl_cs_out {
farah kassabridadf17a2021-05-24 18:09:22 +0300918 union {
919 /*
920 * seq holds the sequence number of the CS to pass to wait
921 * ioctl. All values are valid except for 0 and ULLONG_MAX
922 */
923 __u64 seq;
924
925 /* Valid only when HL_CS_FLAGS_RESERVE_SIGNALS_ONLY is set */
926 struct {
927 /* This is the resereved signal handle id */
928 __u32 handle_id;
929
930 /* This is the signals count */
931 __u32 count;
932 };
933 };
934
935 /* HL_CS_STATUS */
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200936 __u32 status;
farah kassabridadf17a2021-05-24 18:09:22 +0300937
938 /*
939 * SOB base address offset
Dani Liberman1880f7a2021-11-09 11:33:28 +0200940 * Valid only when HL_CS_FLAGS_RESERVE_SIGNALS_ONLY or HL_CS_FLAGS_SIGNAL is set
farah kassabridadf17a2021-05-24 18:09:22 +0300941 */
942 __u32 sob_base_addr_offset;
Dani Liberman1880f7a2021-11-09 11:33:28 +0200943
944 /*
945 * Count of completed signals in SOB before current signal submission.
946 * Valid only when (HL_CS_FLAGS_ENCAP_SIGNALS & HL_CS_FLAGS_STAGED_SUBMISSION)
947 * or HL_CS_FLAGS_SIGNAL is set
948 */
949 __u16 sob_count_before_submission;
950 __u16 pad[3];
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200951};
952
953union hl_cs_args {
954 struct hl_cs_in in;
955 struct hl_cs_out out;
956};
957
farah kassabrib9d31ca2021-11-02 11:34:18 +0200958#define HL_WAIT_CS_FLAGS_INTERRUPT 0x2
959#define HL_WAIT_CS_FLAGS_INTERRUPT_MASK 0xFFF00000
960#define HL_WAIT_CS_FLAGS_MULTI_CS 0x4
961#define HL_WAIT_CS_FLAGS_INTERRUPT_KERNEL_CQ 0x10
Ohad Sharabi215f0c12021-06-14 22:18:41 +0300962
963#define HL_WAIT_MULTI_CS_LIST_MAX_LEN 32
Ofir Bittonab5f5c32021-01-12 18:37:19 +0200964
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200965struct hl_wait_cs_in {
Ofir Bittonab5f5c32021-01-12 18:37:19 +0200966 union {
967 struct {
Ohad Sharabi215f0c12021-06-14 22:18:41 +0300968 /*
969 * In case of wait_cs holds the CS sequence number.
970 * In case of wait for multi CS hold a user pointer to
971 * an array of CS sequence numbers
972 */
Ofir Bittonab5f5c32021-01-12 18:37:19 +0200973 __u64 seq;
974 /* Absolute timeout to wait for command submission
975 * in microseconds
976 */
977 __u64 timeout_us;
978 };
979
980 struct {
farah kassabrib9d31ca2021-11-02 11:34:18 +0200981 union {
982 /* User address for completion comparison.
983 * upon interrupt, driver will compare the value pointed
984 * by this address with the supplied target value.
985 * in order not to perform any comparison, set address
986 * to all 1s.
987 * Relevant only when HL_WAIT_CS_FLAGS_INTERRUPT is set
988 */
989 __u64 addr;
990
991 /* cq_counters_handle to a kernel mapped cb which contains
992 * cq counters.
993 * Relevant only when HL_WAIT_CS_FLAGS_INTERRUPT_KERNEL_CQ is set
994 */
995 __u64 cq_counters_handle;
996 };
997
Ofir Bittonab5f5c32021-01-12 18:37:19 +0200998 /* Target value for completion comparison */
Ofir Bittond62b9a62021-09-23 12:02:23 +0300999 __u64 target;
Ofir Bittonab5f5c32021-01-12 18:37:19 +02001000 };
1001 };
1002
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001003 /* Context ID - Currently not in use */
1004 __u32 ctx_id;
Ohad Sharabi215f0c12021-06-14 22:18:41 +03001005
Ofir Bittonab5f5c32021-01-12 18:37:19 +02001006 /* HL_WAIT_CS_FLAGS_*
1007 * If HL_WAIT_CS_FLAGS_INTERRUPT is set, this field should include
1008 * interrupt id according to HL_WAIT_CS_FLAGS_INTERRUPT_MASK, in order
1009 * not to specify an interrupt id ,set mask to all 1s.
1010 */
1011 __u32 flags;
Ohad Sharabi215f0c12021-06-14 22:18:41 +03001012
Dani Liberman48f31162021-10-14 22:38:41 +03001013 union {
1014 struct {
1015 /* Multi CS API info- valid entries in multi-CS array */
1016 __u8 seq_arr_len;
1017 __u8 pad[7];
1018 };
Ofir Bittond62b9a62021-09-23 12:02:23 +03001019
Dani Liberman48f31162021-10-14 22:38:41 +03001020 /* Absolute timeout to wait for an interrupt in microseconds.
1021 * Relevant only when HL_WAIT_CS_FLAGS_INTERRUPT is set
1022 */
1023 __u64 interrupt_timeout_us;
1024 };
farah kassabrib9d31ca2021-11-02 11:34:18 +02001025
1026 /*
1027 * cq counter offset inside the counters cb pointed by cq_counters_handle above.
1028 * upon interrupt, driver will compare the value pointed
1029 * by this address (cq_counters_handle + cq_counters_offset)
1030 * with the supplied target value.
1031 * relevant only when HL_WAIT_CS_FLAGS_INTERRUPT_KERNEL_CQ is set
1032 */
1033 __u64 cq_counters_offset;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001034};
1035
1036#define HL_WAIT_CS_STATUS_COMPLETED 0
1037#define HL_WAIT_CS_STATUS_BUSY 1
1038#define HL_WAIT_CS_STATUS_TIMEDOUT 2
1039#define HL_WAIT_CS_STATUS_ABORTED 3
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001040
Ofir Bittonbd2f4772020-11-10 17:26:22 +02001041#define HL_WAIT_CS_STATUS_FLAG_GONE 0x1
1042#define HL_WAIT_CS_STATUS_FLAG_TIMESTAMP_VLD 0x2
Ofir Bitton9d127ad2020-11-10 16:30:53 +02001043
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001044struct hl_wait_cs_out {
1045 /* HL_WAIT_CS_STATUS_* */
1046 __u32 status;
Ofir Bitton9d127ad2020-11-10 16:30:53 +02001047 /* HL_WAIT_CS_STATUS_FLAG* */
1048 __u32 flags;
Ohad Sharabi215f0c12021-06-14 22:18:41 +03001049 /*
1050 * valid only if HL_WAIT_CS_STATUS_FLAG_TIMESTAMP_VLD is set
1051 * for wait_cs: timestamp of CS completion
1052 * for wait_multi_cs: timestamp of FIRST CS completion
1053 */
Ofir Bittonbd2f4772020-11-10 17:26:22 +02001054 __s64 timestamp_nsec;
Ohad Sharabi215f0c12021-06-14 22:18:41 +03001055 /* multi CS completion bitmap */
1056 __u32 cs_completion_map;
1057 __u32 pad;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001058};
1059
1060union hl_wait_cs_args {
1061 struct hl_wait_cs_in in;
1062 struct hl_wait_cs_out out;
1063};
1064
Oded Gabbay3bf1c022020-06-09 16:14:55 +03001065/* Opcode to allocate device memory */
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001066#define HL_MEM_OP_ALLOC 0
1067/* Opcode to free previously allocated device memory */
1068#define HL_MEM_OP_FREE 1
Oded Gabbay3bf1c022020-06-09 16:14:55 +03001069/* Opcode to map host and device memory */
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001070#define HL_MEM_OP_MAP 2
Oded Gabbay3bf1c022020-06-09 16:14:55 +03001071/* Opcode to unmap previously mapped host and device memory */
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001072#define HL_MEM_OP_UNMAP 3
Ofir Bittond00697f2021-01-05 12:55:06 +02001073/* Opcode to map a hw block */
1074#define HL_MEM_OP_MAP_BLOCK 4
Oded Gabbaya9498ee2021-04-11 08:26:50 +03001075/* Opcode to create DMA-BUF object for an existing device memory allocation
1076 * and to export an FD of that DMA-BUF back to the caller
1077 */
1078#define HL_MEM_OP_EXPORT_DMABUF_FD 5
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001079
1080/* Memory flags */
1081#define HL_MEM_CONTIGUOUS 0x1
1082#define HL_MEM_SHARED 0x2
1083#define HL_MEM_USERPTR 0x4
Yuri Nudelman486e1972021-06-03 17:51:58 +03001084#define HL_MEM_FORCE_HINT 0x8
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001085
1086struct hl_mem_in {
1087 union {
1088 /* HL_MEM_OP_ALLOC- allocate device memory */
1089 struct {
1090 /* Size to alloc */
Oded Gabbay230afe72019-02-27 00:19:18 +02001091 __u64 mem_size;
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001092 } alloc;
1093
1094 /* HL_MEM_OP_FREE - free device memory */
1095 struct {
1096 /* Handle returned from HL_MEM_OP_ALLOC */
1097 __u64 handle;
1098 } free;
1099
1100 /* HL_MEM_OP_MAP - map device memory */
1101 struct {
1102 /*
1103 * Requested virtual address of mapped memory.
Oded Gabbay4c172bb2019-08-30 16:59:33 +03001104 * The driver will try to map the requested region to
1105 * this hint address, as long as the address is valid
1106 * and not already mapped. The user should check the
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001107 * returned address of the IOCTL to make sure he got
Oded Gabbay4c172bb2019-08-30 16:59:33 +03001108 * the hint address. Passing 0 here means that the
1109 * driver will choose the address itself.
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001110 */
1111 __u64 hint_addr;
1112 /* Handle returned from HL_MEM_OP_ALLOC */
1113 __u64 handle;
1114 } map_device;
1115
1116 /* HL_MEM_OP_MAP - map host memory */
1117 struct {
1118 /* Address of allocated host memory */
1119 __u64 host_virt_addr;
1120 /*
1121 * Requested virtual address of mapped memory.
Oded Gabbay4c172bb2019-08-30 16:59:33 +03001122 * The driver will try to map the requested region to
1123 * this hint address, as long as the address is valid
1124 * and not already mapped. The user should check the
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001125 * returned address of the IOCTL to make sure he got
Oded Gabbay4c172bb2019-08-30 16:59:33 +03001126 * the hint address. Passing 0 here means that the
1127 * driver will choose the address itself.
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001128 */
1129 __u64 hint_addr;
1130 /* Size of allocated host memory */
Oded Gabbay230afe72019-02-27 00:19:18 +02001131 __u64 mem_size;
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001132 } map_host;
1133
Ofir Bittond00697f2021-01-05 12:55:06 +02001134 /* HL_MEM_OP_MAP_BLOCK - map a hw block */
1135 struct {
1136 /*
Oded Gabbay6df50d22021-02-05 16:04:34 +02001137 * HW block address to map, a handle and size will be
1138 * returned to the user and will be used to mmap the
1139 * relevant block. Only addresses from configuration
1140 * space are allowed.
Ofir Bittond00697f2021-01-05 12:55:06 +02001141 */
1142 __u64 block_addr;
1143 } map_block;
1144
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001145 /* HL_MEM_OP_UNMAP - unmap host memory */
1146 struct {
1147 /* Virtual address returned from HL_MEM_OP_MAP */
1148 __u64 device_virt_addr;
1149 } unmap;
Oded Gabbaya9498ee2021-04-11 08:26:50 +03001150
1151 /* HL_MEM_OP_EXPORT_DMABUF_FD */
1152 struct {
1153 /* Handle returned from HL_MEM_OP_ALLOC. In Gaudi,
1154 * where we don't have MMU for the device memory, the
1155 * driver expects a physical address (instead of
1156 * a handle) in the device memory space.
1157 */
1158 __u64 handle;
1159 /* Size of memory allocation. Relevant only for GAUDI */
1160 __u64 mem_size;
1161 } export_dmabuf_fd;
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001162 };
1163
1164 /* HL_MEM_OP_* */
1165 __u32 op;
Oded Gabbaya9498ee2021-04-11 08:26:50 +03001166 /* HL_MEM_* flags.
1167 * For the HL_MEM_OP_EXPORT_DMABUF_FD opcode, this field holds the
1168 * DMA-BUF file/FD flags.
1169 */
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001170 __u32 flags;
1171 /* Context ID - Currently not in use */
1172 __u32 ctx_id;
1173 __u32 pad;
1174};
1175
1176struct hl_mem_out {
1177 union {
1178 /*
1179 * Used for HL_MEM_OP_MAP as the virtual address that was
1180 * assigned in the device VA space.
1181 * A value of 0 means the requested operation failed.
1182 */
1183 __u64 device_virt_addr;
1184
1185 /*
Oded Gabbay6df50d22021-02-05 16:04:34 +02001186 * Used in HL_MEM_OP_ALLOC
Ofir Bittond00697f2021-01-05 12:55:06 +02001187 * This is the assigned handle for the allocated memory
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001188 */
1189 __u64 handle;
Oded Gabbay6df50d22021-02-05 16:04:34 +02001190
1191 struct {
1192 /*
1193 * Used in HL_MEM_OP_MAP_BLOCK.
1194 * This is the assigned handle for the mapped block
1195 */
1196 __u64 block_handle;
1197
1198 /*
1199 * Used in HL_MEM_OP_MAP_BLOCK
1200 * This is the size of the mapped block
1201 */
1202 __u32 block_size;
1203
1204 __u32 pad;
1205 };
Oded Gabbaya9498ee2021-04-11 08:26:50 +03001206
1207 /* Returned in HL_MEM_OP_EXPORT_DMABUF_FD. Represents the
1208 * DMA-BUF object that was created to describe a memory
1209 * allocation on the device's memory space. The FD should be
1210 * passed to the importer driver
1211 */
1212 __s32 fd;
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001213 };
1214};
1215
1216union hl_mem_args {
1217 struct hl_mem_in in;
1218 struct hl_mem_out out;
1219};
1220
Omer Shpigelman315bc052019-04-01 22:31:22 +03001221#define HL_DEBUG_MAX_AUX_VALUES 10
1222
1223struct hl_debug_params_etr {
1224 /* Address in memory to allocate buffer */
1225 __u64 buffer_address;
1226
1227 /* Size of buffer to allocate */
1228 __u64 buffer_size;
1229
1230 /* Sink operation mode: SW fifo, HW fifo, Circular buffer */
1231 __u32 sink_mode;
1232 __u32 pad;
1233};
1234
1235struct hl_debug_params_etf {
1236 /* Address in memory to allocate buffer */
1237 __u64 buffer_address;
1238
1239 /* Size of buffer to allocate */
1240 __u64 buffer_size;
1241
1242 /* Sink operation mode: SW fifo, HW fifo, Circular buffer */
1243 __u32 sink_mode;
1244 __u32 pad;
1245};
1246
1247struct hl_debug_params_stm {
1248 /* Two bit masks for HW event and Stimulus Port */
1249 __u64 he_mask;
1250 __u64 sp_mask;
1251
1252 /* Trace source ID */
1253 __u32 id;
1254
1255 /* Frequency for the timestamp register */
1256 __u32 frequency;
1257};
1258
1259struct hl_debug_params_bmon {
Oded Gabbayd6911712019-04-21 16:20:46 +03001260 /* Two address ranges that the user can request to filter */
1261 __u64 start_addr0;
1262 __u64 addr_mask0;
1263
1264 __u64 start_addr1;
1265 __u64 addr_mask1;
Omer Shpigelman315bc052019-04-01 22:31:22 +03001266
1267 /* Capture window configuration */
1268 __u32 bw_win;
1269 __u32 win_capture;
1270
1271 /* Trace source ID */
1272 __u32 id;
1273 __u32 pad;
1274};
1275
1276struct hl_debug_params_spmu {
1277 /* Event types selection */
1278 __u64 event_types[HL_DEBUG_MAX_AUX_VALUES];
1279
1280 /* Number of event types selection */
1281 __u32 event_types_num;
1282 __u32 pad;
1283};
1284
1285/* Opcode for ETR component */
1286#define HL_DEBUG_OP_ETR 0
1287/* Opcode for ETF component */
1288#define HL_DEBUG_OP_ETF 1
1289/* Opcode for STM component */
1290#define HL_DEBUG_OP_STM 2
1291/* Opcode for FUNNEL component */
1292#define HL_DEBUG_OP_FUNNEL 3
1293/* Opcode for BMON component */
1294#define HL_DEBUG_OP_BMON 4
1295/* Opcode for SPMU component */
1296#define HL_DEBUG_OP_SPMU 5
Tomer Tayar413cf572019-08-27 16:14:18 +00001297/* Opcode for timestamp (deprecated) */
Omer Shpigelman315bc052019-04-01 22:31:22 +03001298#define HL_DEBUG_OP_TIMESTAMP 6
Oded Gabbay2add64e2019-05-04 16:30:00 +03001299/* Opcode for setting the device into or out of debug mode. The enable
1300 * variable should be 1 for enabling debug mode and 0 for disabling it
1301 */
1302#define HL_DEBUG_OP_SET_MODE 7
Omer Shpigelman315bc052019-04-01 22:31:22 +03001303
1304struct hl_debug_args {
1305 /*
1306 * Pointer to user input structure.
1307 * This field is relevant to specific opcodes.
1308 */
1309 __u64 input_ptr;
1310 /* Pointer to user output structure */
1311 __u64 output_ptr;
1312 /* Size of user input structure */
1313 __u32 input_size;
1314 /* Size of user output structure */
1315 __u32 output_size;
1316 /* HL_DEBUG_OP_* */
1317 __u32 op;
1318 /*
1319 * Register index in the component, taken from the debug_regs_index enum
1320 * in the various ASIC header files
1321 */
1322 __u32 reg_idx;
1323 /* Enable/disable */
1324 __u32 enable;
1325 /* Context ID - Currently not in use */
1326 __u32 ctx_id;
1327};
1328
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001329/*
Oded Gabbayd8dd7b02019-02-16 00:39:23 +02001330 * Various information operations such as:
1331 * - H/W IP information
1332 * - Current dram usage
1333 *
1334 * The user calls this IOCTL with an opcode that describes the required
1335 * information. The user should supply a pointer to a user-allocated memory
1336 * chunk, which will be filled by the driver with the requested information.
1337 *
1338 * The user supplies the maximum amount of size to copy into the user's memory,
1339 * in order to prevent data corruption in case of differences between the
1340 * definitions of structures in kernel and userspace, e.g. in case of old
1341 * userspace and new kernel driver
1342 */
1343#define HL_IOCTL_INFO \
1344 _IOWR('H', 0x01, struct hl_info_args)
1345
1346/*
Oded Gabbaybe5d9262019-02-16 00:39:15 +02001347 * Command Buffer
1348 * - Request a Command Buffer
1349 * - Destroy a Command Buffer
1350 *
1351 * The command buffers are memory blocks that reside in DMA-able address
1352 * space and are physically contiguous so they can be accessed by the device
1353 * directly. They are allocated using the coherent DMA API.
1354 *
1355 * When creating a new CB, the IOCTL returns a handle of it, and the user-space
1356 * process needs to use that handle to mmap the buffer so it can access them.
1357 *
Tomer Tayaref6a0f62020-07-09 16:17:48 +03001358 * In some instances, the device must access the command buffer through the
1359 * device's MMU, and thus its memory should be mapped. In these cases, user can
1360 * indicate the driver that such a mapping is required.
1361 * The resulting device virtual address will be used internally by the driver,
1362 * and won't be returned to user.
1363 *
Oded Gabbaybe5d9262019-02-16 00:39:15 +02001364 */
1365#define HL_IOCTL_CB \
1366 _IOWR('H', 0x02, union hl_cb_args)
1367
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001368/*
1369 * Command Submission
1370 *
1371 * To submit work to the device, the user need to call this IOCTL with a set
1372 * of JOBS. That set of JOBS constitutes a CS object.
1373 * Each JOB will be enqueued on a specific queue, according to the user's input.
1374 * There can be more then one JOB per queue.
1375 *
Oded Gabbay131d1ba2021-04-02 22:24:38 +03001376 * The CS IOCTL will receive two sets of JOBS. One set is for "restore" phase
1377 * and a second set is for "execution" phase.
Oded Gabbay90027292019-04-03 09:51:04 +03001378 * The JOBS on the "restore" phase are enqueued only after context-switch
1379 * (or if its the first CS for this context). The user can also order the
1380 * driver to run the "restore" phase explicitly
1381 *
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001382 * There are two types of queues - external and internal. External queues
1383 * are DMA queues which transfer data from/to the Host. All other queues are
1384 * internal. The driver will get completion notifications from the device only
1385 * on JOBS which are enqueued in the external queues.
1386 *
Oded Gabbay541664d32019-02-28 11:55:44 +02001387 * For jobs on external queues, the user needs to create command buffers
1388 * through the CB ioctl and give the CB's handle to the CS ioctl. For jobs on
1389 * internal queues, the user needs to prepare a "command buffer" with packets
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +03001390 * on either the device SRAM/DRAM or the host, and give the device address of
1391 * that buffer to the CS ioctl.
Oded Gabbay541664d32019-02-28 11:55:44 +02001392 *
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001393 * This IOCTL is asynchronous in regard to the actual execution of the CS. This
1394 * means it returns immediately after ALL the JOBS were enqueued on their
1395 * relevant queues. Therefore, the user mustn't assume the CS has been completed
1396 * or has even started to execute.
1397 *
Oded Gabbay90027292019-04-03 09:51:04 +03001398 * Upon successful enqueue, the IOCTL returns a sequence number which the user
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001399 * can use with the "Wait for CS" IOCTL to check whether the handle's CS
1400 * external JOBS have been completed. Note that if the CS has internal JOBS
1401 * which can execute AFTER the external JOBS have finished, the driver might
1402 * report that the CS has finished executing BEFORE the internal JOBS have
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +03001403 * actually finished executing.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001404 *
Oded Gabbay90027292019-04-03 09:51:04 +03001405 * Even though the sequence number increments per CS, the user can NOT
1406 * automatically assume that if CS with sequence number N finished, then CS
1407 * with sequence number N-1 also finished. The user can make this assumption if
1408 * and only if CS N and CS N-1 are exactly the same (same CBs for the same
1409 * queues).
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001410 */
1411#define HL_IOCTL_CS \
1412 _IOWR('H', 0x03, union hl_cs_args)
1413
1414/*
1415 * Wait for Command Submission
1416 *
1417 * The user can call this IOCTL with a handle it received from the CS IOCTL
1418 * to wait until the handle's CS has finished executing. The user will wait
Tomer Tayarf4356142019-10-02 13:53:52 +00001419 * inside the kernel until the CS has finished or until the user-requested
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001420 * timeout has expired.
1421 *
Oded Gabbay681a22f2020-09-07 18:08:51 +03001422 * If the timeout value is 0, the driver won't sleep at all. It will check
1423 * the status of the CS and return immediately
1424 *
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001425 * The return value of the IOCTL is a standard Linux error code. The possible
1426 * values are:
1427 *
1428 * EINTR - Kernel waiting has been interrupted, e.g. due to OS signal
1429 * that the user process received
1430 * ETIMEDOUT - The CS has caused a timeout on the device
1431 * EIO - The CS was aborted (usually because the device was reset)
1432 * ENODEV - The device wants to do hard-reset (so user need to close FD)
1433 *
Rajaravi Krishna Katta4ca57d52021-09-14 18:28:48 +03001434 * The driver also returns a custom define in case the IOCTL call returned 0.
1435 * The define can be one of the following:
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001436 *
1437 * HL_WAIT_CS_STATUS_COMPLETED - The CS has been completed successfully (0)
1438 * HL_WAIT_CS_STATUS_BUSY - The CS is still executing (0)
1439 * HL_WAIT_CS_STATUS_TIMEDOUT - The CS has caused a timeout on the device
1440 * (ETIMEDOUT)
1441 * HL_WAIT_CS_STATUS_ABORTED - The CS was aborted, usually because the
1442 * device was reset (EIO)
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001443 */
1444
1445#define HL_IOCTL_WAIT_CS \
1446 _IOWR('H', 0x04, union hl_wait_cs_args)
1447
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001448/*
1449 * Memory
1450 * - Map host memory to device MMU
1451 * - Unmap host memory from device MMU
1452 *
1453 * This IOCTL allows the user to map host memory to the device MMU
1454 *
1455 * For host memory, the IOCTL doesn't allocate memory. The user is supposed
1456 * to allocate the memory in user-space (malloc/new). The driver pins the
1457 * physical pages (up to the allowed limit by the OS), assigns a virtual
1458 * address in the device VA space and initializes the device MMU.
1459 *
1460 * There is an option for the user to specify the requested virtual address.
1461 *
1462 */
1463#define HL_IOCTL_MEMORY \
1464 _IOWR('H', 0x05, union hl_mem_args)
1465
Omer Shpigelman315bc052019-04-01 22:31:22 +03001466/*
1467 * Debug
1468 * - Enable/disable the ETR/ETF/FUNNEL/STM/BMON/SPMU debug traces
1469 *
1470 * This IOCTL allows the user to get debug traces from the chip.
1471 *
Oded Gabbay2add64e2019-05-04 16:30:00 +03001472 * Before the user can send configuration requests of the various
1473 * debug/profile engines, it needs to set the device into debug mode.
1474 * This is because the debug/profile infrastructure is shared component in the
1475 * device and we can't allow multiple users to access it at the same time.
1476 *
1477 * Once a user set the device into debug mode, the driver won't allow other
1478 * users to "work" with the device, i.e. open a FD. If there are multiple users
1479 * opened on the device, the driver won't allow any user to debug the device.
1480 *
1481 * For each configuration request, the user needs to provide the register index
1482 * and essential data such as buffer address and size.
1483 *
1484 * Once the user has finished using the debug/profile engines, he should
1485 * set the device into non-debug mode, i.e. disable debug mode.
1486 *
1487 * The driver can decide to "kick out" the user if he abuses this interface.
Omer Shpigelman315bc052019-04-01 22:31:22 +03001488 *
1489 */
1490#define HL_IOCTL_DEBUG \
1491 _IOWR('H', 0x06, struct hl_debug_args)
1492
Oded Gabbayd8dd7b02019-02-16 00:39:23 +02001493#define HL_COMMAND_START 0x01
Omer Shpigelman315bc052019-04-01 22:31:22 +03001494#define HL_COMMAND_END 0x07
Oded Gabbaybe5d9262019-02-16 00:39:15 +02001495
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001496#endif /* HABANALABS_H_ */