blob: a47a731e452778d586798442266190be1ab7a723 [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
Dalit Ben Zooraa957082019-03-24 10:15:44 +0200275enum hl_device_status {
276 HL_DEVICE_STATUS_OPERATIONAL,
277 HL_DEVICE_STATUS_IN_RESET,
Ofir Bitton66a76402020-10-05 14:40:10 +0300278 HL_DEVICE_STATUS_MALFUNCTION,
279 HL_DEVICE_STATUS_NEEDS_RESET
Dalit Ben Zooraa957082019-03-24 10:15:44 +0200280};
281
Oded Gabbayf388ec72019-07-16 08:55:04 +0300282/* Opcode for management ioctl
283 *
Oded Gabbay75b3cb22019-08-28 17:32:04 +0300284 * HW_IP_INFO - Receive information about different IP blocks in the
285 * device.
286 * HL_INFO_HW_EVENTS - Receive an array describing how many times each event
287 * occurred since the last hard reset.
288 * HL_INFO_DRAM_USAGE - Retrieve the dram usage inside the device and of the
289 * specific context. This is relevant only for devices
290 * where the dram is managed by the kernel driver
291 * HL_INFO_HW_IDLE - Retrieve information about the idle status of each
292 * internal engine.
Oded Gabbayf388ec72019-07-16 08:55:04 +0300293 * HL_INFO_DEVICE_STATUS - Retrieve the device's status. This opcode doesn't
294 * require an open context.
Oded Gabbay62c1e122019-10-10 15:48:59 +0300295 * HL_INFO_DEVICE_UTILIZATION - Retrieve the total utilization of the device
296 * over the last period specified by the user.
297 * The period can be between 100ms to 1s, in
298 * resolution of 100ms. The return value is a
299 * percentage of the utilization rate.
Oded Gabbaye9730762019-08-28 21:51:52 +0300300 * HL_INFO_HW_EVENTS_AGGREGATE - Receive an array describing how many times each
301 * event occurred since the driver was loaded.
Oded Gabbay62c1e122019-10-10 15:48:59 +0300302 * HL_INFO_CLK_RATE - Retrieve the current and maximum clock rate
303 * of the device in MHz. The maximum clock rate is
304 * configurable via sysfs parameter
Moti Haimovski52c01b02019-11-03 16:26:44 +0200305 * HL_INFO_RESET_COUNT - Retrieve the counts of the soft and hard reset
306 * operations performed on the device since the last
307 * time the driver was loaded.
Tomer Tayar25e7aeb2020-03-31 22:46:36 +0300308 * HL_INFO_TIME_SYNC - Retrieve the device's time alongside the host's time
309 * for synchronization.
Ofir Bittondb491e42020-06-18 09:51:16 +0300310 * HL_INFO_CS_COUNTERS - Retrieve command submission counters
Ofir Bitton0a068ad2020-07-21 10:49:51 +0300311 * HL_INFO_PCI_COUNTERS - Retrieve PCI counters
312 * HL_INFO_CLK_THROTTLE_REASON - Retrieve clock throttling reason
Ofir Bitton843839b2020-07-19 11:08:09 +0300313 * HL_INFO_SYNC_MANAGER - Retrieve sync manager info per dcore
farah kassabri9f306492020-08-09 16:25:53 +0300314 * HL_INFO_TOTAL_ENERGY - Retrieve total energy consumption
Alon Mizrahi429f1572020-12-01 18:44:11 +0200315 * HL_INFO_PLL_FREQUENCY - Retrieve PLL frequency
Yuri Nudelmane307b302021-05-24 11:25:21 +0300316 * HL_INFO_OPEN_STATS - Retrieve info regarding recent device open calls
Oded Gabbayf388ec72019-07-16 08:55:04 +0300317 */
Oded Gabbay75b3cb22019-08-28 17:32:04 +0300318#define HL_INFO_HW_IP_INFO 0
319#define HL_INFO_HW_EVENTS 1
320#define HL_INFO_DRAM_USAGE 2
321#define HL_INFO_HW_IDLE 3
322#define HL_INFO_DEVICE_STATUS 4
323#define HL_INFO_DEVICE_UTILIZATION 6
Oded Gabbaye9730762019-08-28 21:51:52 +0300324#define HL_INFO_HW_EVENTS_AGGREGATE 7
Oded Gabbay62c1e122019-10-10 15:48:59 +0300325#define HL_INFO_CLK_RATE 8
Moti Haimovski52c01b02019-11-03 16:26:44 +0200326#define HL_INFO_RESET_COUNT 9
Tomer Tayar25e7aeb2020-03-31 22:46:36 +0300327#define HL_INFO_TIME_SYNC 10
Ofir Bittondb491e42020-06-18 09:51:16 +0300328#define HL_INFO_CS_COUNTERS 11
Ofir Bitton0a068ad2020-07-21 10:49:51 +0300329#define HL_INFO_PCI_COUNTERS 12
330#define HL_INFO_CLK_THROTTLE_REASON 13
Ofir Bitton843839b2020-07-19 11:08:09 +0300331#define HL_INFO_SYNC_MANAGER 14
farah kassabri9f306492020-08-09 16:25:53 +0300332#define HL_INFO_TOTAL_ENERGY 15
Alon Mizrahi41478642020-11-17 14:25:14 +0200333#define HL_INFO_PLL_FREQUENCY 16
Sagiv Ozeri586f2ca2021-02-23 18:00:05 +0200334#define HL_INFO_POWER 17
Yuri Nudelmane307b302021-05-24 11:25:21 +0300335#define HL_INFO_OPEN_STATS 18
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200336
337#define HL_INFO_VERSION_MAX_LEN 128
Oded Gabbay91edbf22019-10-16 11:53:52 +0300338#define HL_INFO_CARD_NAME_MAX_LEN 16
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200339
340struct hl_info_hw_ip_info {
341 __u64 sram_base_address;
342 __u64 dram_base_address;
343 __u64 dram_size;
344 __u32 sram_size;
345 __u32 num_of_events;
346 __u32 device_id; /* PCI Device ID */
Omer Shpigelmanfca72fb2020-05-03 17:35:54 +0300347 __u32 module_id; /* For mezzanine cards in servers (From OCP spec.) */
Ofir Bittone1fa7242021-01-06 15:40:37 +0200348 __u32 reserved;
349 __u16 first_available_interrupt_id;
350 __u16 reserved2;
Oded Gabbay2f553422020-08-15 16:28:10 +0300351 __u32 cpld_version;
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200352 __u32 psoc_pci_pll_nr;
353 __u32 psoc_pci_pll_nf;
354 __u32 psoc_pci_pll_od;
355 __u32 psoc_pci_pll_div_factor;
356 __u8 tpc_enabled_mask;
357 __u8 dram_enabled;
358 __u8 pad[2];
Oded Gabbay2f553422020-08-15 16:28:10 +0300359 __u8 cpucp_version[HL_INFO_VERSION_MAX_LEN];
Oded Gabbay91edbf22019-10-16 11:53:52 +0300360 __u8 card_name[HL_INFO_CARD_NAME_MAX_LEN];
Ofir Bittone1fa7242021-01-06 15:40:37 +0200361 __u64 reserved3;
Moti Haimovski0eda23d2020-12-07 09:10:34 +0200362 __u64 dram_page_size;
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200363};
364
365struct hl_info_dram_usage {
366 __u64 dram_free_mem;
367 __u64 ctx_dram_mem;
368};
369
Ohad Sharabicf303392021-01-17 16:01:56 +0200370#define HL_BUSY_ENGINES_MASK_EXT_SIZE 2
371
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200372struct hl_info_hw_idle {
373 __u32 is_idle;
Tomer Tayare8960ca2019-07-01 13:59:45 +0000374 /*
375 * Bitmask of busy engines.
376 * Bits definition is according to `enum <chip>_enging_id'.
377 */
378 __u32 busy_engines_mask;
farah kassabrid90416c2020-08-12 17:20:13 +0300379
380 /*
381 * Extended Bitmask of busy engines.
382 * Bits definition is according to `enum <chip>_enging_id'.
383 */
Ohad Sharabicf303392021-01-17 16:01:56 +0200384 __u64 busy_engines_mask_ext[HL_BUSY_ENGINES_MASK_EXT_SIZE];
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200385};
386
Dalit Ben Zooraa957082019-03-24 10:15:44 +0200387struct hl_info_device_status {
388 __u32 status;
389 __u32 pad;
390};
391
Oded Gabbay75b3cb22019-08-28 17:32:04 +0300392struct hl_info_device_utilization {
393 __u32 utilization;
394 __u32 pad;
395};
396
Oded Gabbay62c1e122019-10-10 15:48:59 +0300397struct hl_info_clk_rate {
398 __u32 cur_clk_rate_mhz;
399 __u32 max_clk_rate_mhz;
400};
401
Moti Haimovski52c01b02019-11-03 16:26:44 +0200402struct hl_info_reset_count {
403 __u32 hard_reset_cnt;
404 __u32 soft_reset_cnt;
405};
406
Tomer Tayar25e7aeb2020-03-31 22:46:36 +0300407struct hl_info_time_sync {
408 __u64 device_time;
409 __u64 host_time;
410};
411
Ofir Bittondb491e42020-06-18 09:51:16 +0300412/**
Ofir Bitton0a068ad2020-07-21 10:49:51 +0300413 * struct hl_info_pci_counters - pci counters
414 * @rx_throughput: PCI rx throughput KBps
415 * @tx_throughput: PCI tx throughput KBps
416 * @replay_cnt: PCI replay counter
417 */
418struct hl_info_pci_counters {
419 __u64 rx_throughput;
420 __u64 tx_throughput;
421 __u64 replay_cnt;
422};
423
424#define HL_CLK_THROTTLE_POWER 0x1
425#define HL_CLK_THROTTLE_THERMAL 0x2
426
427/**
428 * struct hl_info_clk_throttle - clock throttling reason
429 * @clk_throttling_reason: each bit represents a clk throttling reason
430 */
431struct hl_info_clk_throttle {
432 __u32 clk_throttling_reason;
433};
434
435/**
farah kassabri9f306492020-08-09 16:25:53 +0300436 * struct hl_info_energy - device energy information
437 * @total_energy_consumption: total device energy consumption
438 */
439struct hl_info_energy {
440 __u64 total_energy_consumption;
441};
442
Alon Mizrahi41478642020-11-17 14:25:14 +0200443#define HL_PLL_NUM_OUTPUTS 4
444
445struct hl_pll_frequency_info {
446 __u16 output[HL_PLL_NUM_OUTPUTS];
447};
448
farah kassabri9f306492020-08-09 16:25:53 +0300449/**
Yuri Nudelmane307b302021-05-24 11:25:21 +0300450 * struct hl_open_stats_info - device open statistics information
451 * @open_counter: ever growing counter, increased on each successful dev open
452 * @last_open_period_ms: duration (ms) device was open last time
453 */
454struct hl_open_stats_info {
455 __u64 open_counter;
456 __u64 last_open_period_ms;
457};
458
459/**
Sagiv Ozeri586f2ca2021-02-23 18:00:05 +0200460 * struct hl_power_info - power information
461 * @power: power consumption
462 */
463struct hl_power_info {
464 __u64 power;
465};
466
467/**
Ofir Bitton843839b2020-07-19 11:08:09 +0300468 * struct hl_info_sync_manager - sync manager information
469 * @first_available_sync_object: first available sob
470 * @first_available_monitor: first available monitor
Ofir Bittone52606d2021-01-27 16:34:37 +0200471 * @first_available_cq: first available cq
Ofir Bitton843839b2020-07-19 11:08:09 +0300472 */
473struct hl_info_sync_manager {
474 __u32 first_available_sync_object;
475 __u32 first_available_monitor;
Ofir Bittone52606d2021-01-27 16:34:37 +0200476 __u32 first_available_cq;
477 __u32 reserved;
Ofir Bitton843839b2020-07-19 11:08:09 +0300478};
479
480/**
Ofir Bittondb491e42020-06-18 09:51:16 +0300481 * struct hl_info_cs_counters - command submission counters
farah kassabrie7536432020-10-12 14:30:26 +0300482 * @total_out_of_mem_drop_cnt: total dropped due to memory allocation issue
483 * @ctx_out_of_mem_drop_cnt: context dropped due to memory allocation issue
484 * @total_parsing_drop_cnt: total dropped due to error in packet parsing
485 * @ctx_parsing_drop_cnt: context dropped due to error in packet parsing
486 * @total_queue_full_drop_cnt: total dropped due to queue full
487 * @ctx_queue_full_drop_cnt: context dropped due to queue full
488 * @total_device_in_reset_drop_cnt: total dropped due to device in reset
489 * @ctx_device_in_reset_drop_cnt: context dropped due to device in reset
490 * @total_max_cs_in_flight_drop_cnt: total dropped due to maximum CS in-flight
491 * @ctx_max_cs_in_flight_drop_cnt: context dropped due to maximum CS in-flight
Alon Mizrahia3fd2832020-12-08 16:14:01 +0200492 * @total_validation_drop_cnt: total dropped due to validation error
493 * @ctx_validation_drop_cnt: context dropped due to validation error
Ofir Bittondb491e42020-06-18 09:51:16 +0300494 */
Ofir Bittondb491e42020-06-18 09:51:16 +0300495struct hl_info_cs_counters {
farah kassabrie7536432020-10-12 14:30:26 +0300496 __u64 total_out_of_mem_drop_cnt;
497 __u64 ctx_out_of_mem_drop_cnt;
498 __u64 total_parsing_drop_cnt;
499 __u64 ctx_parsing_drop_cnt;
500 __u64 total_queue_full_drop_cnt;
501 __u64 ctx_queue_full_drop_cnt;
502 __u64 total_device_in_reset_drop_cnt;
503 __u64 ctx_device_in_reset_drop_cnt;
504 __u64 total_max_cs_in_flight_drop_cnt;
505 __u64 ctx_max_cs_in_flight_drop_cnt;
Alon Mizrahia3fd2832020-12-08 16:14:01 +0200506 __u64 total_validation_drop_cnt;
507 __u64 ctx_validation_drop_cnt;
Ofir Bittondb491e42020-06-18 09:51:16 +0300508};
509
Ofir Bitton843839b2020-07-19 11:08:09 +0300510enum gaudi_dcores {
511 HL_GAUDI_WS_DCORE,
512 HL_GAUDI_WN_DCORE,
513 HL_GAUDI_EN_DCORE,
514 HL_GAUDI_ES_DCORE
515};
516
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200517struct hl_info_args {
518 /* Location of relevant struct in userspace */
519 __u64 return_pointer;
520 /*
521 * The size of the return value. Just like "size" in "snprintf",
522 * it limits how many bytes the kernel can write
523 *
524 * For hw_events array, the size should be
525 * hl_info_hw_ip_info.num_of_events * sizeof(__u32)
526 */
527 __u32 return_size;
528
529 /* HL_INFO_* */
530 __u32 op;
531
Oded Gabbay75b3cb22019-08-28 17:32:04 +0300532 union {
Ofir Bitton843839b2020-07-19 11:08:09 +0300533 /* Dcore id for which the information is relevant.
534 * For Gaudi refer to 'enum gaudi_dcores'
535 */
536 __u32 dcore_id;
Oded Gabbay75b3cb22019-08-28 17:32:04 +0300537 /* Context ID - Currently not in use */
538 __u32 ctx_id;
539 /* Period value for utilization rate (100ms - 1000ms, in 100ms
540 * resolution.
541 */
542 __u32 period_ms;
Alon Mizrahi41478642020-11-17 14:25:14 +0200543 /* PLL frequency retrieval */
544 __u32 pll_index;
Oded Gabbay75b3cb22019-08-28 17:32:04 +0300545 };
546
Oded Gabbayd8dd7b02019-02-16 00:39:23 +0200547 __u32 pad;
548};
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200549
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200550/* Opcode to create a new command buffer */
551#define HL_CB_OP_CREATE 0
552/* Opcode to destroy previously created command buffer */
553#define HL_CB_OP_DESTROY 1
Tomer Tayarf44afb52020-09-02 13:43:32 +0300554/* Opcode to retrieve information about a command buffer */
555#define HL_CB_OP_INFO 2
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200556
Oded Gabbay39b42512020-04-17 12:12:13 +0300557/* 2MB minus 32 bytes for 2xMSG_PROT */
558#define HL_MAX_CB_SIZE (0x200000 - 32)
Oded Gabbay5d101252019-11-10 16:08:26 +0200559
Tomer Tayaref6a0f62020-07-09 16:17:48 +0300560/* Indicates whether the command buffer should be mapped to the device's MMU */
561#define HL_CB_FLAGS_MAP 0x1
562
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200563struct hl_cb_in {
564 /* Handle of CB or 0 if we want to create one */
565 __u64 cb_handle;
566 /* HL_CB_OP_* */
567 __u32 op;
Oded Gabbay5d101252019-11-10 16:08:26 +0200568 /* Size of CB. Maximum size is HL_MAX_CB_SIZE. The minimum size that
569 * will be allocated, regardless of this parameter's value, is PAGE_SIZE
Oded Gabbay541664d32019-02-28 11:55:44 +0200570 */
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200571 __u32 cb_size;
572 /* Context ID - Currently not in use */
573 __u32 ctx_id;
Tomer Tayaref6a0f62020-07-09 16:17:48 +0300574 /* HL_CB_FLAGS_* */
575 __u32 flags;
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200576};
577
578struct hl_cb_out {
Tomer Tayarf44afb52020-09-02 13:43:32 +0300579 union {
580 /* Handle of CB */
581 __u64 cb_handle;
582
583 /* Information about CB */
584 struct {
585 /* Usage count of CB */
586 __u32 usage_cnt;
587 __u32 pad;
588 };
589 };
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200590};
591
592union hl_cb_args {
593 struct hl_cb_in in;
594 struct hl_cb_out out;
595};
596
Tal Cohen4bb1f2f2020-06-03 09:25:27 +0300597/* HL_CS_CHUNK_FLAGS_ values
598 *
599 * HL_CS_CHUNK_FLAGS_USER_ALLOC_CB:
600 * Indicates if the CB was allocated and mapped by userspace.
601 * User allocated CB is a command buffer allocated by the user, via malloc
602 * (or similar). After allocating the CB, the user invokes “memory ioctl”
603 * to map the user memory into a device virtual address. The user provides
604 * this address via the cb_handle field. The interface provides the
605 * ability to create a large CBs, Which aren’t limited to
606 * “HL_MAX_CB_SIZE”. Therefore, it increases the PCI-DMA queues
607 * throughput. This CB allocation method also reduces the use of Linux
608 * DMA-able memory pool. Which are limited and used by other Linux
609 * sub-systems.
610 */
611#define HL_CS_CHUNK_FLAGS_USER_ALLOC_CB 0x1
612
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200613/*
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200614 * This structure size must always be fixed to 64-bytes for backward
615 * compatibility
616 */
617struct hl_cs_chunk {
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300618 union {
619 /* For external queue, this represents a Handle of CB on the
620 * Host.
621 * For internal queue in Goya, this represents an SRAM or
622 * a DRAM address of the internal CB. In Gaudi, this might also
623 * represent a mapped host address of the CB.
624 *
625 * A mapped host address is in the device address space, after
626 * a host address was mapped by the device MMU.
627 */
628 __u64 cb_handle;
629
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300630 /* Relevant only when HL_CS_FLAGS_WAIT or
631 * HL_CS_FLAGS_COLLECTIVE_WAIT is set.
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300632 * This holds address of array of u64 values that contain
633 * signal CS sequence numbers. The wait described by this job
634 * will listen on all those signals (wait event per signal)
635 */
636 __u64 signal_seq_arr;
637 };
638
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200639 /* Index of queue to put the CB on */
640 __u32 queue_index;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300641
642 union {
643 /*
644 * Size of command buffer with valid packets
645 * Can be smaller then actual CB size
646 */
647 __u32 cb_size;
648
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300649 /* Relevant only when HL_CS_FLAGS_WAIT or
650 * HL_CS_FLAGS_COLLECTIVE_WAIT is set.
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300651 * Number of entries in signal_seq_arr
652 */
653 __u32 num_signal_seq_arr;
654 };
655
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200656 /* HL_CS_CHUNK_FLAGS_* */
657 __u32 cs_chunk_flags;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300658
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300659 /* Relevant only when HL_CS_FLAGS_COLLECTIVE_WAIT is set.
660 * This holds the collective engine ID. The wait described by this job
661 * will sync with this engine and with all NICs before completion.
662 */
663 __u32 collective_engine_id;
664
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200665 /* Align structure to 64 bytes */
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300666 __u32 pad[10];
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200667};
668
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300669/* SIGNAL and WAIT/COLLECTIVE_WAIT flags are mutually exclusive */
Ofir Bittonc209e742020-12-03 17:12:09 +0200670#define HL_CS_FLAGS_FORCE_RESTORE 0x1
671#define HL_CS_FLAGS_SIGNAL 0x2
672#define HL_CS_FLAGS_WAIT 0x4
673#define HL_CS_FLAGS_COLLECTIVE_WAIT 0x8
674#define HL_CS_FLAGS_TIMESTAMP 0x20
675#define HL_CS_FLAGS_STAGED_SUBMISSION 0x40
676#define HL_CS_FLAGS_STAGED_SUBMISSION_FIRST 0x80
677#define HL_CS_FLAGS_STAGED_SUBMISSION_LAST 0x100
Alon Mizrahicf393952021-02-22 15:53:24 +0200678#define HL_CS_FLAGS_CUSTOM_TIMEOUT 0x200
Yuri Nudelman8e8125f2021-05-25 14:49:52 +0300679#define HL_CS_FLAGS_SKIP_RESET_ON_TIMEOUT 0x400
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200680
681#define HL_CS_STATUS_SUCCESS 0
682
Oded Gabbay5d101252019-11-10 16:08:26 +0200683#define HL_MAX_JOBS_PER_CS 512
684
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200685struct hl_cs_in {
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300686
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200687 /* this holds address of array of hl_cs_chunk for restore phase */
688 __u64 chunks_restore;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300689
690 /* holds address of array of hl_cs_chunk for execution phase */
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200691 __u64 chunks_execute;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300692
Oded Gabbay131d1ba2021-04-02 22:24:38 +0300693 /* Sequence number of a staged submission CS
694 * valid only if HL_CS_FLAGS_STAGED_SUBMISSION is set
695 */
696 __u64 seq;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300697
Oded Gabbay5d101252019-11-10 16:08:26 +0200698 /* Number of chunks in restore phase array. Maximum number is
699 * HL_MAX_JOBS_PER_CS
700 */
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200701 __u32 num_chunks_restore;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300702
Oded Gabbay5d101252019-11-10 16:08:26 +0200703 /* Number of chunks in execution array. Maximum number is
704 * HL_MAX_JOBS_PER_CS
705 */
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200706 __u32 num_chunks_execute;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300707
Oded Gabbay131d1ba2021-04-02 22:24:38 +0300708 /* timeout in seconds - valid only if HL_CS_FLAGS_CUSTOM_TIMEOUT
709 * is set
710 */
711 __u32 timeout;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300712
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200713 /* HL_CS_FLAGS_* */
714 __u32 cs_flags;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +0300715
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200716 /* Context ID - Currently not in use */
717 __u32 ctx_id;
718};
719
720struct hl_cs_out {
Oded Gabbaye1266002019-03-07 14:20:05 +0200721 /*
722 * seq holds the sequence number of the CS to pass to wait ioctl. All
723 * values are valid except for 0 and ULLONG_MAX
724 */
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200725 __u64 seq;
726 /* HL_CS_STATUS_* */
727 __u32 status;
728 __u32 pad;
729};
730
731union hl_cs_args {
732 struct hl_cs_in in;
733 struct hl_cs_out out;
734};
735
Ofir Bittonab5f5c32021-01-12 18:37:19 +0200736#define HL_WAIT_CS_FLAGS_INTERRUPT 0x2
737#define HL_WAIT_CS_FLAGS_INTERRUPT_MASK 0xFFF00000
738
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200739struct hl_wait_cs_in {
Ofir Bittonab5f5c32021-01-12 18:37:19 +0200740 union {
741 struct {
742 /* Command submission sequence number */
743 __u64 seq;
744 /* Absolute timeout to wait for command submission
745 * in microseconds
746 */
747 __u64 timeout_us;
748 };
749
750 struct {
751 /* User address for completion comparison.
752 * upon interrupt, driver will compare the value pointed
753 * by this address with the supplied target value.
754 * in order not to perform any comparison, set address
755 * to all 1s.
756 * Relevant only when HL_WAIT_CS_FLAGS_INTERRUPT is set
757 */
758 __u64 addr;
759 /* Target value for completion comparison */
760 __u32 target;
761 /* Absolute timeout to wait for interrupt
762 * in microseconds
763 */
764 __u32 interrupt_timeout_us;
765 };
766 };
767
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200768 /* Context ID - Currently not in use */
769 __u32 ctx_id;
Ofir Bittonab5f5c32021-01-12 18:37:19 +0200770 /* HL_WAIT_CS_FLAGS_*
771 * If HL_WAIT_CS_FLAGS_INTERRUPT is set, this field should include
772 * interrupt id according to HL_WAIT_CS_FLAGS_INTERRUPT_MASK, in order
773 * not to specify an interrupt id ,set mask to all 1s.
774 */
775 __u32 flags;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200776};
777
778#define HL_WAIT_CS_STATUS_COMPLETED 0
779#define HL_WAIT_CS_STATUS_BUSY 1
780#define HL_WAIT_CS_STATUS_TIMEDOUT 2
781#define HL_WAIT_CS_STATUS_ABORTED 3
782#define HL_WAIT_CS_STATUS_INTERRUPTED 4
783
Ofir Bittonbd2f4772020-11-10 17:26:22 +0200784#define HL_WAIT_CS_STATUS_FLAG_GONE 0x1
785#define HL_WAIT_CS_STATUS_FLAG_TIMESTAMP_VLD 0x2
Ofir Bitton9d127ad2020-11-10 16:30:53 +0200786
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200787struct hl_wait_cs_out {
788 /* HL_WAIT_CS_STATUS_* */
789 __u32 status;
Ofir Bitton9d127ad2020-11-10 16:30:53 +0200790 /* HL_WAIT_CS_STATUS_FLAG* */
791 __u32 flags;
Ofir Bittonbd2f4772020-11-10 17:26:22 +0200792 /* valid only if HL_WAIT_CS_STATUS_FLAG_TIMESTAMP_VLD is set */
793 __s64 timestamp_nsec;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200794};
795
796union hl_wait_cs_args {
797 struct hl_wait_cs_in in;
798 struct hl_wait_cs_out out;
799};
800
Oded Gabbay3bf1c022020-06-09 16:14:55 +0300801/* Opcode to allocate device memory */
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200802#define HL_MEM_OP_ALLOC 0
803/* Opcode to free previously allocated device memory */
804#define HL_MEM_OP_FREE 1
Oded Gabbay3bf1c022020-06-09 16:14:55 +0300805/* Opcode to map host and device memory */
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200806#define HL_MEM_OP_MAP 2
Oded Gabbay3bf1c022020-06-09 16:14:55 +0300807/* Opcode to unmap previously mapped host and device memory */
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200808#define HL_MEM_OP_UNMAP 3
Ofir Bittond00697f2021-01-05 12:55:06 +0200809/* Opcode to map a hw block */
810#define HL_MEM_OP_MAP_BLOCK 4
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200811
812/* Memory flags */
813#define HL_MEM_CONTIGUOUS 0x1
814#define HL_MEM_SHARED 0x2
815#define HL_MEM_USERPTR 0x4
816
817struct hl_mem_in {
818 union {
819 /* HL_MEM_OP_ALLOC- allocate device memory */
820 struct {
821 /* Size to alloc */
Oded Gabbay230afe72019-02-27 00:19:18 +0200822 __u64 mem_size;
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200823 } alloc;
824
825 /* HL_MEM_OP_FREE - free device memory */
826 struct {
827 /* Handle returned from HL_MEM_OP_ALLOC */
828 __u64 handle;
829 } free;
830
831 /* HL_MEM_OP_MAP - map device memory */
832 struct {
833 /*
834 * Requested virtual address of mapped memory.
Oded Gabbay4c172bb2019-08-30 16:59:33 +0300835 * The driver will try to map the requested region to
836 * this hint address, as long as the address is valid
837 * and not already mapped. The user should check the
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200838 * returned address of the IOCTL to make sure he got
Oded Gabbay4c172bb2019-08-30 16:59:33 +0300839 * the hint address. Passing 0 here means that the
840 * driver will choose the address itself.
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200841 */
842 __u64 hint_addr;
843 /* Handle returned from HL_MEM_OP_ALLOC */
844 __u64 handle;
845 } map_device;
846
847 /* HL_MEM_OP_MAP - map host memory */
848 struct {
849 /* Address of allocated host memory */
850 __u64 host_virt_addr;
851 /*
852 * Requested virtual address of mapped memory.
Oded Gabbay4c172bb2019-08-30 16:59:33 +0300853 * The driver will try to map the requested region to
854 * this hint address, as long as the address is valid
855 * and not already mapped. The user should check the
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200856 * returned address of the IOCTL to make sure he got
Oded Gabbay4c172bb2019-08-30 16:59:33 +0300857 * the hint address. Passing 0 here means that the
858 * driver will choose the address itself.
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200859 */
860 __u64 hint_addr;
861 /* Size of allocated host memory */
Oded Gabbay230afe72019-02-27 00:19:18 +0200862 __u64 mem_size;
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200863 } map_host;
864
Ofir Bittond00697f2021-01-05 12:55:06 +0200865 /* HL_MEM_OP_MAP_BLOCK - map a hw block */
866 struct {
867 /*
Oded Gabbay6df50d22021-02-05 16:04:34 +0200868 * HW block address to map, a handle and size will be
869 * returned to the user and will be used to mmap the
870 * relevant block. Only addresses from configuration
871 * space are allowed.
Ofir Bittond00697f2021-01-05 12:55:06 +0200872 */
873 __u64 block_addr;
874 } map_block;
875
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200876 /* HL_MEM_OP_UNMAP - unmap host memory */
877 struct {
878 /* Virtual address returned from HL_MEM_OP_MAP */
879 __u64 device_virt_addr;
880 } unmap;
881 };
882
883 /* HL_MEM_OP_* */
884 __u32 op;
885 /* HL_MEM_* flags */
886 __u32 flags;
887 /* Context ID - Currently not in use */
888 __u32 ctx_id;
889 __u32 pad;
890};
891
892struct hl_mem_out {
893 union {
894 /*
895 * Used for HL_MEM_OP_MAP as the virtual address that was
896 * assigned in the device VA space.
897 * A value of 0 means the requested operation failed.
898 */
899 __u64 device_virt_addr;
900
901 /*
Oded Gabbay6df50d22021-02-05 16:04:34 +0200902 * Used in HL_MEM_OP_ALLOC
Ofir Bittond00697f2021-01-05 12:55:06 +0200903 * This is the assigned handle for the allocated memory
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200904 */
905 __u64 handle;
Oded Gabbay6df50d22021-02-05 16:04:34 +0200906
907 struct {
908 /*
909 * Used in HL_MEM_OP_MAP_BLOCK.
910 * This is the assigned handle for the mapped block
911 */
912 __u64 block_handle;
913
914 /*
915 * Used in HL_MEM_OP_MAP_BLOCK
916 * This is the size of the mapped block
917 */
918 __u32 block_size;
919
920 __u32 pad;
921 };
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200922 };
923};
924
925union hl_mem_args {
926 struct hl_mem_in in;
927 struct hl_mem_out out;
928};
929
Omer Shpigelman315bc052019-04-01 22:31:22 +0300930#define HL_DEBUG_MAX_AUX_VALUES 10
931
932struct hl_debug_params_etr {
933 /* Address in memory to allocate buffer */
934 __u64 buffer_address;
935
936 /* Size of buffer to allocate */
937 __u64 buffer_size;
938
939 /* Sink operation mode: SW fifo, HW fifo, Circular buffer */
940 __u32 sink_mode;
941 __u32 pad;
942};
943
944struct hl_debug_params_etf {
945 /* Address in memory to allocate buffer */
946 __u64 buffer_address;
947
948 /* Size of buffer to allocate */
949 __u64 buffer_size;
950
951 /* Sink operation mode: SW fifo, HW fifo, Circular buffer */
952 __u32 sink_mode;
953 __u32 pad;
954};
955
956struct hl_debug_params_stm {
957 /* Two bit masks for HW event and Stimulus Port */
958 __u64 he_mask;
959 __u64 sp_mask;
960
961 /* Trace source ID */
962 __u32 id;
963
964 /* Frequency for the timestamp register */
965 __u32 frequency;
966};
967
968struct hl_debug_params_bmon {
Oded Gabbayd6911712019-04-21 16:20:46 +0300969 /* Two address ranges that the user can request to filter */
970 __u64 start_addr0;
971 __u64 addr_mask0;
972
973 __u64 start_addr1;
974 __u64 addr_mask1;
Omer Shpigelman315bc052019-04-01 22:31:22 +0300975
976 /* Capture window configuration */
977 __u32 bw_win;
978 __u32 win_capture;
979
980 /* Trace source ID */
981 __u32 id;
982 __u32 pad;
983};
984
985struct hl_debug_params_spmu {
986 /* Event types selection */
987 __u64 event_types[HL_DEBUG_MAX_AUX_VALUES];
988
989 /* Number of event types selection */
990 __u32 event_types_num;
991 __u32 pad;
992};
993
994/* Opcode for ETR component */
995#define HL_DEBUG_OP_ETR 0
996/* Opcode for ETF component */
997#define HL_DEBUG_OP_ETF 1
998/* Opcode for STM component */
999#define HL_DEBUG_OP_STM 2
1000/* Opcode for FUNNEL component */
1001#define HL_DEBUG_OP_FUNNEL 3
1002/* Opcode for BMON component */
1003#define HL_DEBUG_OP_BMON 4
1004/* Opcode for SPMU component */
1005#define HL_DEBUG_OP_SPMU 5
Tomer Tayar413cf572019-08-27 16:14:18 +00001006/* Opcode for timestamp (deprecated) */
Omer Shpigelman315bc052019-04-01 22:31:22 +03001007#define HL_DEBUG_OP_TIMESTAMP 6
Oded Gabbay2add64e2019-05-04 16:30:00 +03001008/* Opcode for setting the device into or out of debug mode. The enable
1009 * variable should be 1 for enabling debug mode and 0 for disabling it
1010 */
1011#define HL_DEBUG_OP_SET_MODE 7
Omer Shpigelman315bc052019-04-01 22:31:22 +03001012
1013struct hl_debug_args {
1014 /*
1015 * Pointer to user input structure.
1016 * This field is relevant to specific opcodes.
1017 */
1018 __u64 input_ptr;
1019 /* Pointer to user output structure */
1020 __u64 output_ptr;
1021 /* Size of user input structure */
1022 __u32 input_size;
1023 /* Size of user output structure */
1024 __u32 output_size;
1025 /* HL_DEBUG_OP_* */
1026 __u32 op;
1027 /*
1028 * Register index in the component, taken from the debug_regs_index enum
1029 * in the various ASIC header files
1030 */
1031 __u32 reg_idx;
1032 /* Enable/disable */
1033 __u32 enable;
1034 /* Context ID - Currently not in use */
1035 __u32 ctx_id;
1036};
1037
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001038/*
Oded Gabbayd8dd7b02019-02-16 00:39:23 +02001039 * Various information operations such as:
1040 * - H/W IP information
1041 * - Current dram usage
1042 *
1043 * The user calls this IOCTL with an opcode that describes the required
1044 * information. The user should supply a pointer to a user-allocated memory
1045 * chunk, which will be filled by the driver with the requested information.
1046 *
1047 * The user supplies the maximum amount of size to copy into the user's memory,
1048 * in order to prevent data corruption in case of differences between the
1049 * definitions of structures in kernel and userspace, e.g. in case of old
1050 * userspace and new kernel driver
1051 */
1052#define HL_IOCTL_INFO \
1053 _IOWR('H', 0x01, struct hl_info_args)
1054
1055/*
Oded Gabbaybe5d9262019-02-16 00:39:15 +02001056 * Command Buffer
1057 * - Request a Command Buffer
1058 * - Destroy a Command Buffer
1059 *
1060 * The command buffers are memory blocks that reside in DMA-able address
1061 * space and are physically contiguous so they can be accessed by the device
1062 * directly. They are allocated using the coherent DMA API.
1063 *
1064 * When creating a new CB, the IOCTL returns a handle of it, and the user-space
1065 * process needs to use that handle to mmap the buffer so it can access them.
1066 *
Tomer Tayaref6a0f62020-07-09 16:17:48 +03001067 * In some instances, the device must access the command buffer through the
1068 * device's MMU, and thus its memory should be mapped. In these cases, user can
1069 * indicate the driver that such a mapping is required.
1070 * The resulting device virtual address will be used internally by the driver,
1071 * and won't be returned to user.
1072 *
Oded Gabbaybe5d9262019-02-16 00:39:15 +02001073 */
1074#define HL_IOCTL_CB \
1075 _IOWR('H', 0x02, union hl_cb_args)
1076
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001077/*
1078 * Command Submission
1079 *
1080 * To submit work to the device, the user need to call this IOCTL with a set
1081 * of JOBS. That set of JOBS constitutes a CS object.
1082 * Each JOB will be enqueued on a specific queue, according to the user's input.
1083 * There can be more then one JOB per queue.
1084 *
Oded Gabbay131d1ba2021-04-02 22:24:38 +03001085 * The CS IOCTL will receive two sets of JOBS. One set is for "restore" phase
1086 * and a second set is for "execution" phase.
Oded Gabbay90027292019-04-03 09:51:04 +03001087 * The JOBS on the "restore" phase are enqueued only after context-switch
1088 * (or if its the first CS for this context). The user can also order the
1089 * driver to run the "restore" phase explicitly
1090 *
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001091 * There are two types of queues - external and internal. External queues
1092 * are DMA queues which transfer data from/to the Host. All other queues are
1093 * internal. The driver will get completion notifications from the device only
1094 * on JOBS which are enqueued in the external queues.
1095 *
Oded Gabbay541664d32019-02-28 11:55:44 +02001096 * For jobs on external queues, the user needs to create command buffers
1097 * through the CB ioctl and give the CB's handle to the CS ioctl. For jobs on
1098 * internal queues, the user needs to prepare a "command buffer" with packets
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +03001099 * on either the device SRAM/DRAM or the host, and give the device address of
1100 * that buffer to the CS ioctl.
Oded Gabbay541664d32019-02-28 11:55:44 +02001101 *
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001102 * This IOCTL is asynchronous in regard to the actual execution of the CS. This
1103 * means it returns immediately after ALL the JOBS were enqueued on their
1104 * relevant queues. Therefore, the user mustn't assume the CS has been completed
1105 * or has even started to execute.
1106 *
Oded Gabbay90027292019-04-03 09:51:04 +03001107 * Upon successful enqueue, the IOCTL returns a sequence number which the user
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001108 * can use with the "Wait for CS" IOCTL to check whether the handle's CS
1109 * external JOBS have been completed. Note that if the CS has internal JOBS
1110 * which can execute AFTER the external JOBS have finished, the driver might
1111 * report that the CS has finished executing BEFORE the internal JOBS have
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +03001112 * actually finished executing.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001113 *
Oded Gabbay90027292019-04-03 09:51:04 +03001114 * Even though the sequence number increments per CS, the user can NOT
1115 * automatically assume that if CS with sequence number N finished, then CS
1116 * with sequence number N-1 also finished. The user can make this assumption if
1117 * and only if CS N and CS N-1 are exactly the same (same CBs for the same
1118 * queues).
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001119 */
1120#define HL_IOCTL_CS \
1121 _IOWR('H', 0x03, union hl_cs_args)
1122
1123/*
1124 * Wait for Command Submission
1125 *
1126 * The user can call this IOCTL with a handle it received from the CS IOCTL
1127 * to wait until the handle's CS has finished executing. The user will wait
Tomer Tayarf4356142019-10-02 13:53:52 +00001128 * inside the kernel until the CS has finished or until the user-requested
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001129 * timeout has expired.
1130 *
Oded Gabbay681a22f2020-09-07 18:08:51 +03001131 * If the timeout value is 0, the driver won't sleep at all. It will check
1132 * the status of the CS and return immediately
1133 *
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001134 * The return value of the IOCTL is a standard Linux error code. The possible
1135 * values are:
1136 *
1137 * EINTR - Kernel waiting has been interrupted, e.g. due to OS signal
1138 * that the user process received
1139 * ETIMEDOUT - The CS has caused a timeout on the device
1140 * EIO - The CS was aborted (usually because the device was reset)
1141 * ENODEV - The device wants to do hard-reset (so user need to close FD)
1142 *
1143 * The driver also returns a custom define inside the IOCTL which can be:
1144 *
1145 * HL_WAIT_CS_STATUS_COMPLETED - The CS has been completed successfully (0)
1146 * HL_WAIT_CS_STATUS_BUSY - The CS is still executing (0)
1147 * HL_WAIT_CS_STATUS_TIMEDOUT - The CS has caused a timeout on the device
1148 * (ETIMEDOUT)
1149 * HL_WAIT_CS_STATUS_ABORTED - The CS was aborted, usually because the
1150 * device was reset (EIO)
1151 * HL_WAIT_CS_STATUS_INTERRUPTED - Waiting for the CS was interrupted (EINTR)
1152 *
1153 */
1154
1155#define HL_IOCTL_WAIT_CS \
1156 _IOWR('H', 0x04, union hl_wait_cs_args)
1157
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001158/*
1159 * Memory
1160 * - Map host memory to device MMU
1161 * - Unmap host memory from device MMU
1162 *
1163 * This IOCTL allows the user to map host memory to the device MMU
1164 *
1165 * For host memory, the IOCTL doesn't allocate memory. The user is supposed
1166 * to allocate the memory in user-space (malloc/new). The driver pins the
1167 * physical pages (up to the allowed limit by the OS), assigns a virtual
1168 * address in the device VA space and initializes the device MMU.
1169 *
1170 * There is an option for the user to specify the requested virtual address.
1171 *
1172 */
1173#define HL_IOCTL_MEMORY \
1174 _IOWR('H', 0x05, union hl_mem_args)
1175
Omer Shpigelman315bc052019-04-01 22:31:22 +03001176/*
1177 * Debug
1178 * - Enable/disable the ETR/ETF/FUNNEL/STM/BMON/SPMU debug traces
1179 *
1180 * This IOCTL allows the user to get debug traces from the chip.
1181 *
Oded Gabbay2add64e2019-05-04 16:30:00 +03001182 * Before the user can send configuration requests of the various
1183 * debug/profile engines, it needs to set the device into debug mode.
1184 * This is because the debug/profile infrastructure is shared component in the
1185 * device and we can't allow multiple users to access it at the same time.
1186 *
1187 * Once a user set the device into debug mode, the driver won't allow other
1188 * users to "work" with the device, i.e. open a FD. If there are multiple users
1189 * opened on the device, the driver won't allow any user to debug the device.
1190 *
1191 * For each configuration request, the user needs to provide the register index
1192 * and essential data such as buffer address and size.
1193 *
1194 * Once the user has finished using the debug/profile engines, he should
1195 * set the device into non-debug mode, i.e. disable debug mode.
1196 *
1197 * The driver can decide to "kick out" the user if he abuses this interface.
Omer Shpigelman315bc052019-04-01 22:31:22 +03001198 *
1199 */
1200#define HL_IOCTL_DEBUG \
1201 _IOWR('H', 0x06, struct hl_debug_args)
1202
Oded Gabbayd8dd7b02019-02-16 00:39:23 +02001203#define HL_COMMAND_START 0x01
Omer Shpigelman315bc052019-04-01 22:31:22 +03001204#define HL_COMMAND_END 0x07
Oded Gabbaybe5d9262019-02-16 00:39:15 +02001205
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001206#endif /* HABANALABS_H_ */