]> Git Repo - linux.git/blob - include/uapi/misc/habanalabs.h
enetc: Migrate to PHYLINK and PCS_LYNX
[linux.git] / include / uapi / misc / habanalabs.h
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
2  *
3  * Copyright 2016-2020 HabanaLabs, Ltd.
4  * 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  */
18 #define GOYA_KMD_SRAM_RESERVED_SIZE_FROM_START          0x8000  /* 32KB */
19 #define GAUDI_DRIVER_SRAM_RESERVED_SIZE_FROM_START      0x80    /* 128 bytes */
20
21 #define GAUDI_FIRST_AVAILABLE_W_S_SYNC_OBJECT           48
22 #define GAUDI_FIRST_AVAILABLE_W_S_MONITOR               24
23 /*
24  * Goya queue Numbering
25  *
26  * The external queues (PCI DMA channels) MUST be before the internal queues
27  * and each group (PCI DMA channels and internal) must be contiguous inside
28  * itself but there can be a gap between the two groups (although not
29  * recommended)
30  */
31
32 enum goya_queue_id {
33         GOYA_QUEUE_ID_DMA_0 = 0,
34         GOYA_QUEUE_ID_DMA_1 = 1,
35         GOYA_QUEUE_ID_DMA_2 = 2,
36         GOYA_QUEUE_ID_DMA_3 = 3,
37         GOYA_QUEUE_ID_DMA_4 = 4,
38         GOYA_QUEUE_ID_CPU_PQ = 5,
39         GOYA_QUEUE_ID_MME = 6,  /* Internal queues start here */
40         GOYA_QUEUE_ID_TPC0 = 7,
41         GOYA_QUEUE_ID_TPC1 = 8,
42         GOYA_QUEUE_ID_TPC2 = 9,
43         GOYA_QUEUE_ID_TPC3 = 10,
44         GOYA_QUEUE_ID_TPC4 = 11,
45         GOYA_QUEUE_ID_TPC5 = 12,
46         GOYA_QUEUE_ID_TPC6 = 13,
47         GOYA_QUEUE_ID_TPC7 = 14,
48         GOYA_QUEUE_ID_SIZE
49 };
50
51 /*
52  * Gaudi queue Numbering
53  * External queues (PCI DMA channels) are DMA_0_*, DMA_1_* and DMA_5_*.
54  * Except one CPU queue, all the rest are internal queues.
55  */
56
57 enum gaudi_queue_id {
58         GAUDI_QUEUE_ID_DMA_0_0 = 0,     /* external */
59         GAUDI_QUEUE_ID_DMA_0_1 = 1,     /* external */
60         GAUDI_QUEUE_ID_DMA_0_2 = 2,     /* external */
61         GAUDI_QUEUE_ID_DMA_0_3 = 3,     /* external */
62         GAUDI_QUEUE_ID_DMA_1_0 = 4,     /* external */
63         GAUDI_QUEUE_ID_DMA_1_1 = 5,     /* external */
64         GAUDI_QUEUE_ID_DMA_1_2 = 6,     /* external */
65         GAUDI_QUEUE_ID_DMA_1_3 = 7,     /* external */
66         GAUDI_QUEUE_ID_CPU_PQ = 8,      /* CPU */
67         GAUDI_QUEUE_ID_DMA_2_0 = 9,     /* internal */
68         GAUDI_QUEUE_ID_DMA_2_1 = 10,    /* internal */
69         GAUDI_QUEUE_ID_DMA_2_2 = 11,    /* internal */
70         GAUDI_QUEUE_ID_DMA_2_3 = 12,    /* internal */
71         GAUDI_QUEUE_ID_DMA_3_0 = 13,    /* internal */
72         GAUDI_QUEUE_ID_DMA_3_1 = 14,    /* internal */
73         GAUDI_QUEUE_ID_DMA_3_2 = 15,    /* internal */
74         GAUDI_QUEUE_ID_DMA_3_3 = 16,    /* internal */
75         GAUDI_QUEUE_ID_DMA_4_0 = 17,    /* internal */
76         GAUDI_QUEUE_ID_DMA_4_1 = 18,    /* internal */
77         GAUDI_QUEUE_ID_DMA_4_2 = 19,    /* internal */
78         GAUDI_QUEUE_ID_DMA_4_3 = 20,    /* internal */
79         GAUDI_QUEUE_ID_DMA_5_0 = 21,    /* external */
80         GAUDI_QUEUE_ID_DMA_5_1 = 22,    /* external */
81         GAUDI_QUEUE_ID_DMA_5_2 = 23,    /* external */
82         GAUDI_QUEUE_ID_DMA_5_3 = 24,    /* external */
83         GAUDI_QUEUE_ID_DMA_6_0 = 25,    /* internal */
84         GAUDI_QUEUE_ID_DMA_6_1 = 26,    /* internal */
85         GAUDI_QUEUE_ID_DMA_6_2 = 27,    /* internal */
86         GAUDI_QUEUE_ID_DMA_6_3 = 28,    /* internal */
87         GAUDI_QUEUE_ID_DMA_7_0 = 29,    /* internal */
88         GAUDI_QUEUE_ID_DMA_7_1 = 30,    /* internal */
89         GAUDI_QUEUE_ID_DMA_7_2 = 31,    /* internal */
90         GAUDI_QUEUE_ID_DMA_7_3 = 32,    /* internal */
91         GAUDI_QUEUE_ID_MME_0_0 = 33,    /* internal */
92         GAUDI_QUEUE_ID_MME_0_1 = 34,    /* internal */
93         GAUDI_QUEUE_ID_MME_0_2 = 35,    /* internal */
94         GAUDI_QUEUE_ID_MME_0_3 = 36,    /* internal */
95         GAUDI_QUEUE_ID_MME_1_0 = 37,    /* internal */
96         GAUDI_QUEUE_ID_MME_1_1 = 38,    /* internal */
97         GAUDI_QUEUE_ID_MME_1_2 = 39,    /* internal */
98         GAUDI_QUEUE_ID_MME_1_3 = 40,    /* internal */
99         GAUDI_QUEUE_ID_TPC_0_0 = 41,    /* internal */
100         GAUDI_QUEUE_ID_TPC_0_1 = 42,    /* internal */
101         GAUDI_QUEUE_ID_TPC_0_2 = 43,    /* internal */
102         GAUDI_QUEUE_ID_TPC_0_3 = 44,    /* internal */
103         GAUDI_QUEUE_ID_TPC_1_0 = 45,    /* internal */
104         GAUDI_QUEUE_ID_TPC_1_1 = 46,    /* internal */
105         GAUDI_QUEUE_ID_TPC_1_2 = 47,    /* internal */
106         GAUDI_QUEUE_ID_TPC_1_3 = 48,    /* internal */
107         GAUDI_QUEUE_ID_TPC_2_0 = 49,    /* internal */
108         GAUDI_QUEUE_ID_TPC_2_1 = 50,    /* internal */
109         GAUDI_QUEUE_ID_TPC_2_2 = 51,    /* internal */
110         GAUDI_QUEUE_ID_TPC_2_3 = 52,    /* internal */
111         GAUDI_QUEUE_ID_TPC_3_0 = 53,    /* internal */
112         GAUDI_QUEUE_ID_TPC_3_1 = 54,    /* internal */
113         GAUDI_QUEUE_ID_TPC_3_2 = 55,    /* internal */
114         GAUDI_QUEUE_ID_TPC_3_3 = 56,    /* internal */
115         GAUDI_QUEUE_ID_TPC_4_0 = 57,    /* internal */
116         GAUDI_QUEUE_ID_TPC_4_1 = 58,    /* internal */
117         GAUDI_QUEUE_ID_TPC_4_2 = 59,    /* internal */
118         GAUDI_QUEUE_ID_TPC_4_3 = 60,    /* internal */
119         GAUDI_QUEUE_ID_TPC_5_0 = 61,    /* internal */
120         GAUDI_QUEUE_ID_TPC_5_1 = 62,    /* internal */
121         GAUDI_QUEUE_ID_TPC_5_2 = 63,    /* internal */
122         GAUDI_QUEUE_ID_TPC_5_3 = 64,    /* internal */
123         GAUDI_QUEUE_ID_TPC_6_0 = 65,    /* internal */
124         GAUDI_QUEUE_ID_TPC_6_1 = 66,    /* internal */
125         GAUDI_QUEUE_ID_TPC_6_2 = 67,    /* internal */
126         GAUDI_QUEUE_ID_TPC_6_3 = 68,    /* internal */
127         GAUDI_QUEUE_ID_TPC_7_0 = 69,    /* internal */
128         GAUDI_QUEUE_ID_TPC_7_1 = 70,    /* internal */
129         GAUDI_QUEUE_ID_TPC_7_2 = 71,    /* internal */
130         GAUDI_QUEUE_ID_TPC_7_3 = 72,    /* internal */
131         GAUDI_QUEUE_ID_NIC_0_0 = 73,    /* internal */
132         GAUDI_QUEUE_ID_NIC_0_1 = 74,    /* internal */
133         GAUDI_QUEUE_ID_NIC_0_2 = 75,    /* internal */
134         GAUDI_QUEUE_ID_NIC_0_3 = 76,    /* internal */
135         GAUDI_QUEUE_ID_NIC_1_0 = 77,    /* internal */
136         GAUDI_QUEUE_ID_NIC_1_1 = 78,    /* internal */
137         GAUDI_QUEUE_ID_NIC_1_2 = 79,    /* internal */
138         GAUDI_QUEUE_ID_NIC_1_3 = 80,    /* internal */
139         GAUDI_QUEUE_ID_NIC_2_0 = 81,    /* internal */
140         GAUDI_QUEUE_ID_NIC_2_1 = 82,    /* internal */
141         GAUDI_QUEUE_ID_NIC_2_2 = 83,    /* internal */
142         GAUDI_QUEUE_ID_NIC_2_3 = 84,    /* internal */
143         GAUDI_QUEUE_ID_NIC_3_0 = 85,    /* internal */
144         GAUDI_QUEUE_ID_NIC_3_1 = 86,    /* internal */
145         GAUDI_QUEUE_ID_NIC_3_2 = 87,    /* internal */
146         GAUDI_QUEUE_ID_NIC_3_3 = 88,    /* internal */
147         GAUDI_QUEUE_ID_NIC_4_0 = 89,    /* internal */
148         GAUDI_QUEUE_ID_NIC_4_1 = 90,    /* internal */
149         GAUDI_QUEUE_ID_NIC_4_2 = 91,    /* internal */
150         GAUDI_QUEUE_ID_NIC_4_3 = 92,    /* internal */
151         GAUDI_QUEUE_ID_NIC_5_0 = 93,    /* internal */
152         GAUDI_QUEUE_ID_NIC_5_1 = 94,    /* internal */
153         GAUDI_QUEUE_ID_NIC_5_2 = 95,    /* internal */
154         GAUDI_QUEUE_ID_NIC_5_3 = 96,    /* internal */
155         GAUDI_QUEUE_ID_NIC_6_0 = 97,    /* internal */
156         GAUDI_QUEUE_ID_NIC_6_1 = 98,    /* internal */
157         GAUDI_QUEUE_ID_NIC_6_2 = 99,    /* internal */
158         GAUDI_QUEUE_ID_NIC_6_3 = 100,   /* internal */
159         GAUDI_QUEUE_ID_NIC_7_0 = 101,   /* internal */
160         GAUDI_QUEUE_ID_NIC_7_1 = 102,   /* internal */
161         GAUDI_QUEUE_ID_NIC_7_2 = 103,   /* internal */
162         GAUDI_QUEUE_ID_NIC_7_3 = 104,   /* internal */
163         GAUDI_QUEUE_ID_NIC_8_0 = 105,   /* internal */
164         GAUDI_QUEUE_ID_NIC_8_1 = 106,   /* internal */
165         GAUDI_QUEUE_ID_NIC_8_2 = 107,   /* internal */
166         GAUDI_QUEUE_ID_NIC_8_3 = 108,   /* internal */
167         GAUDI_QUEUE_ID_NIC_9_0 = 109,   /* internal */
168         GAUDI_QUEUE_ID_NIC_9_1 = 110,   /* internal */
169         GAUDI_QUEUE_ID_NIC_9_2 = 111,   /* internal */
170         GAUDI_QUEUE_ID_NIC_9_3 = 112,   /* internal */
171         GAUDI_QUEUE_ID_SIZE
172 };
173
174 /*
175  * Engine Numbering
176  *
177  * Used in the "busy_engines_mask" field in `struct hl_info_hw_idle'
178  */
179
180 enum goya_engine_id {
181         GOYA_ENGINE_ID_DMA_0 = 0,
182         GOYA_ENGINE_ID_DMA_1,
183         GOYA_ENGINE_ID_DMA_2,
184         GOYA_ENGINE_ID_DMA_3,
185         GOYA_ENGINE_ID_DMA_4,
186         GOYA_ENGINE_ID_MME_0,
187         GOYA_ENGINE_ID_TPC_0,
188         GOYA_ENGINE_ID_TPC_1,
189         GOYA_ENGINE_ID_TPC_2,
190         GOYA_ENGINE_ID_TPC_3,
191         GOYA_ENGINE_ID_TPC_4,
192         GOYA_ENGINE_ID_TPC_5,
193         GOYA_ENGINE_ID_TPC_6,
194         GOYA_ENGINE_ID_TPC_7,
195         GOYA_ENGINE_ID_SIZE
196 };
197
198 enum gaudi_engine_id {
199         GAUDI_ENGINE_ID_DMA_0 = 0,
200         GAUDI_ENGINE_ID_DMA_1,
201         GAUDI_ENGINE_ID_DMA_2,
202         GAUDI_ENGINE_ID_DMA_3,
203         GAUDI_ENGINE_ID_DMA_4,
204         GAUDI_ENGINE_ID_DMA_5,
205         GAUDI_ENGINE_ID_DMA_6,
206         GAUDI_ENGINE_ID_DMA_7,
207         GAUDI_ENGINE_ID_MME_0,
208         GAUDI_ENGINE_ID_MME_1,
209         GAUDI_ENGINE_ID_MME_2,
210         GAUDI_ENGINE_ID_MME_3,
211         GAUDI_ENGINE_ID_TPC_0,
212         GAUDI_ENGINE_ID_TPC_1,
213         GAUDI_ENGINE_ID_TPC_2,
214         GAUDI_ENGINE_ID_TPC_3,
215         GAUDI_ENGINE_ID_TPC_4,
216         GAUDI_ENGINE_ID_TPC_5,
217         GAUDI_ENGINE_ID_TPC_6,
218         GAUDI_ENGINE_ID_TPC_7,
219         GAUDI_ENGINE_ID_NIC_0,
220         GAUDI_ENGINE_ID_NIC_1,
221         GAUDI_ENGINE_ID_NIC_2,
222         GAUDI_ENGINE_ID_NIC_3,
223         GAUDI_ENGINE_ID_NIC_4,
224         GAUDI_ENGINE_ID_NIC_5,
225         GAUDI_ENGINE_ID_NIC_6,
226         GAUDI_ENGINE_ID_NIC_7,
227         GAUDI_ENGINE_ID_NIC_8,
228         GAUDI_ENGINE_ID_NIC_9,
229         GAUDI_ENGINE_ID_SIZE
230 };
231
232 enum hl_device_status {
233         HL_DEVICE_STATUS_OPERATIONAL,
234         HL_DEVICE_STATUS_IN_RESET,
235         HL_DEVICE_STATUS_MALFUNCTION
236 };
237
238 /* Opcode for management ioctl
239  *
240  * HW_IP_INFO            - Receive information about different IP blocks in the
241  *                         device.
242  * HL_INFO_HW_EVENTS     - Receive an array describing how many times each event
243  *                         occurred since the last hard reset.
244  * HL_INFO_DRAM_USAGE    - Retrieve the dram usage inside the device and of the
245  *                         specific context. This is relevant only for devices
246  *                         where the dram is managed by the kernel driver
247  * HL_INFO_HW_IDLE       - Retrieve information about the idle status of each
248  *                         internal engine.
249  * HL_INFO_DEVICE_STATUS - Retrieve the device's status. This opcode doesn't
250  *                         require an open context.
251  * HL_INFO_DEVICE_UTILIZATION  - Retrieve the total utilization of the device
252  *                               over the last period specified by the user.
253  *                               The period can be between 100ms to 1s, in
254  *                               resolution of 100ms. The return value is a
255  *                               percentage of the utilization rate.
256  * HL_INFO_HW_EVENTS_AGGREGATE - Receive an array describing how many times each
257  *                               event occurred since the driver was loaded.
258  * HL_INFO_CLK_RATE            - Retrieve the current and maximum clock rate
259  *                               of the device in MHz. The maximum clock rate is
260  *                               configurable via sysfs parameter
261  * HL_INFO_RESET_COUNT   - Retrieve the counts of the soft and hard reset
262  *                         operations performed on the device since the last
263  *                         time the driver was loaded.
264  * HL_INFO_TIME_SYNC     - Retrieve the device's time alongside the host's time
265  *                         for synchronization.
266  * HL_INFO_CS_COUNTERS   - Retrieve command submission counters
267  */
268 #define HL_INFO_HW_IP_INFO              0
269 #define HL_INFO_HW_EVENTS               1
270 #define HL_INFO_DRAM_USAGE              2
271 #define HL_INFO_HW_IDLE                 3
272 #define HL_INFO_DEVICE_STATUS           4
273 #define HL_INFO_DEVICE_UTILIZATION      6
274 #define HL_INFO_HW_EVENTS_AGGREGATE     7
275 #define HL_INFO_CLK_RATE                8
276 #define HL_INFO_RESET_COUNT             9
277 #define HL_INFO_TIME_SYNC               10
278 #define HL_INFO_CS_COUNTERS             11
279
280 #define HL_INFO_VERSION_MAX_LEN 128
281 #define HL_INFO_CARD_NAME_MAX_LEN       16
282
283 struct hl_info_hw_ip_info {
284         __u64 sram_base_address;
285         __u64 dram_base_address;
286         __u64 dram_size;
287         __u32 sram_size;
288         __u32 num_of_events;
289         __u32 device_id; /* PCI Device ID */
290         __u32 module_id; /* For mezzanine cards in servers (From OCP spec.) */
291         __u32 reserved[2];
292         __u32 armcp_cpld_version;
293         __u32 psoc_pci_pll_nr;
294         __u32 psoc_pci_pll_nf;
295         __u32 psoc_pci_pll_od;
296         __u32 psoc_pci_pll_div_factor;
297         __u8 tpc_enabled_mask;
298         __u8 dram_enabled;
299         __u8 pad[2];
300         __u8 armcp_version[HL_INFO_VERSION_MAX_LEN];
301         __u8 card_name[HL_INFO_CARD_NAME_MAX_LEN];
302 };
303
304 struct hl_info_dram_usage {
305         __u64 dram_free_mem;
306         __u64 ctx_dram_mem;
307 };
308
309 struct hl_info_hw_idle {
310         __u32 is_idle;
311         /*
312          * Bitmask of busy engines.
313          * Bits definition is according to `enum <chip>_enging_id'.
314          */
315         __u32 busy_engines_mask;
316 };
317
318 struct hl_info_device_status {
319         __u32 status;
320         __u32 pad;
321 };
322
323 struct hl_info_device_utilization {
324         __u32 utilization;
325         __u32 pad;
326 };
327
328 struct hl_info_clk_rate {
329         __u32 cur_clk_rate_mhz;
330         __u32 max_clk_rate_mhz;
331 };
332
333 struct hl_info_reset_count {
334         __u32 hard_reset_cnt;
335         __u32 soft_reset_cnt;
336 };
337
338 struct hl_info_time_sync {
339         __u64 device_time;
340         __u64 host_time;
341 };
342
343 /**
344  * struct hl_info_cs_counters - command submission counters
345  * @out_of_mem_drop_cnt: dropped due to memory allocation issue
346  * @parsing_drop_cnt: dropped due to error in packet parsing
347  * @queue_full_drop_cnt: dropped due to queue full
348  * @device_in_reset_drop_cnt: dropped due to device in reset
349  */
350 struct hl_cs_counters {
351         __u64 out_of_mem_drop_cnt;
352         __u64 parsing_drop_cnt;
353         __u64 queue_full_drop_cnt;
354         __u64 device_in_reset_drop_cnt;
355 };
356
357 struct hl_info_cs_counters {
358         struct hl_cs_counters cs_counters;
359         struct hl_cs_counters ctx_cs_counters;
360 };
361
362 struct hl_info_args {
363         /* Location of relevant struct in userspace */
364         __u64 return_pointer;
365         /*
366          * The size of the return value. Just like "size" in "snprintf",
367          * it limits how many bytes the kernel can write
368          *
369          * For hw_events array, the size should be
370          * hl_info_hw_ip_info.num_of_events * sizeof(__u32)
371          */
372         __u32 return_size;
373
374         /* HL_INFO_* */
375         __u32 op;
376
377         union {
378                 /* Context ID - Currently not in use */
379                 __u32 ctx_id;
380                 /* Period value for utilization rate (100ms - 1000ms, in 100ms
381                  * resolution.
382                  */
383                 __u32 period_ms;
384         };
385
386         __u32 pad;
387 };
388
389 /* Opcode to create a new command buffer */
390 #define HL_CB_OP_CREATE         0
391 /* Opcode to destroy previously created command buffer */
392 #define HL_CB_OP_DESTROY        1
393
394 /* 2MB minus 32 bytes for 2xMSG_PROT */
395 #define HL_MAX_CB_SIZE          (0x200000 - 32)
396
397 struct hl_cb_in {
398         /* Handle of CB or 0 if we want to create one */
399         __u64 cb_handle;
400         /* HL_CB_OP_* */
401         __u32 op;
402         /* Size of CB. Maximum size is HL_MAX_CB_SIZE. The minimum size that
403          * will be allocated, regardless of this parameter's value, is PAGE_SIZE
404          */
405         __u32 cb_size;
406         /* Context ID - Currently not in use */
407         __u32 ctx_id;
408         __u32 pad;
409 };
410
411 struct hl_cb_out {
412         /* Handle of CB */
413         __u64 cb_handle;
414 };
415
416 union hl_cb_args {
417         struct hl_cb_in in;
418         struct hl_cb_out out;
419 };
420
421 /*
422  * This structure size must always be fixed to 64-bytes for backward
423  * compatibility
424  */
425 struct hl_cs_chunk {
426         union {
427                 /* For external queue, this represents a Handle of CB on the
428                  * Host.
429                  * For internal queue in Goya, this represents an SRAM or
430                  * a DRAM address of the internal CB. In Gaudi, this might also
431                  * represent a mapped host address of the CB.
432                  *
433                  * A mapped host address is in the device address space, after
434                  * a host address was mapped by the device MMU.
435                  */
436                 __u64 cb_handle;
437
438                 /* Relevant only when HL_CS_FLAGS_WAIT is set.
439                  * This holds address of array of u64 values that contain
440                  * signal CS sequence numbers. The wait described by this job
441                  * will listen on all those signals (wait event per signal)
442                  */
443                 __u64 signal_seq_arr;
444         };
445
446         /* Index of queue to put the CB on */
447         __u32 queue_index;
448
449         union {
450                 /*
451                  * Size of command buffer with valid packets
452                  * Can be smaller then actual CB size
453                  */
454                 __u32 cb_size;
455
456                 /* Relevant only when HL_CS_FLAGS_WAIT is set.
457                  * Number of entries in signal_seq_arr
458                  */
459                 __u32 num_signal_seq_arr;
460         };
461
462         /* HL_CS_CHUNK_FLAGS_* */
463         __u32 cs_chunk_flags;
464
465         /* Align structure to 64 bytes */
466         __u32 pad[11];
467 };
468
469 /* SIGNAL and WAIT flags are mutually exclusive */
470 #define HL_CS_FLAGS_FORCE_RESTORE       0x1
471 #define HL_CS_FLAGS_SIGNAL              0x2
472 #define HL_CS_FLAGS_WAIT                0x4
473
474 #define HL_CS_STATUS_SUCCESS            0
475
476 #define HL_MAX_JOBS_PER_CS              512
477
478 struct hl_cs_in {
479
480         /* this holds address of array of hl_cs_chunk for restore phase */
481         __u64 chunks_restore;
482
483         /* holds address of array of hl_cs_chunk for execution phase */
484         __u64 chunks_execute;
485
486         /* this holds address of array of hl_cs_chunk for store phase -
487          * Currently not in use
488          */
489         __u64 chunks_store;
490
491         /* Number of chunks in restore phase array. Maximum number is
492          * HL_MAX_JOBS_PER_CS
493          */
494         __u32 num_chunks_restore;
495
496         /* Number of chunks in execution array. Maximum number is
497          * HL_MAX_JOBS_PER_CS
498          */
499         __u32 num_chunks_execute;
500
501         /* Number of chunks in restore phase array - Currently not in use */
502         __u32 num_chunks_store;
503
504         /* HL_CS_FLAGS_* */
505         __u32 cs_flags;
506
507         /* Context ID - Currently not in use */
508         __u32 ctx_id;
509 };
510
511 struct hl_cs_out {
512         /*
513          * seq holds the sequence number of the CS to pass to wait ioctl. All
514          * values are valid except for 0 and ULLONG_MAX
515          */
516         __u64 seq;
517         /* HL_CS_STATUS_* */
518         __u32 status;
519         __u32 pad;
520 };
521
522 union hl_cs_args {
523         struct hl_cs_in in;
524         struct hl_cs_out out;
525 };
526
527 struct hl_wait_cs_in {
528         /* Command submission sequence number */
529         __u64 seq;
530         /* Absolute timeout to wait in microseconds */
531         __u64 timeout_us;
532         /* Context ID - Currently not in use */
533         __u32 ctx_id;
534         __u32 pad;
535 };
536
537 #define HL_WAIT_CS_STATUS_COMPLETED     0
538 #define HL_WAIT_CS_STATUS_BUSY          1
539 #define HL_WAIT_CS_STATUS_TIMEDOUT      2
540 #define HL_WAIT_CS_STATUS_ABORTED       3
541 #define HL_WAIT_CS_STATUS_INTERRUPTED   4
542
543 struct hl_wait_cs_out {
544         /* HL_WAIT_CS_STATUS_* */
545         __u32 status;
546         __u32 pad;
547 };
548
549 union hl_wait_cs_args {
550         struct hl_wait_cs_in in;
551         struct hl_wait_cs_out out;
552 };
553
554 /* Opcode to allocate device memory */
555 #define HL_MEM_OP_ALLOC                 0
556 /* Opcode to free previously allocated device memory */
557 #define HL_MEM_OP_FREE                  1
558 /* Opcode to map host and device memory */
559 #define HL_MEM_OP_MAP                   2
560 /* Opcode to unmap previously mapped host and device memory */
561 #define HL_MEM_OP_UNMAP                 3
562
563 /* Memory flags */
564 #define HL_MEM_CONTIGUOUS       0x1
565 #define HL_MEM_SHARED           0x2
566 #define HL_MEM_USERPTR          0x4
567
568 struct hl_mem_in {
569         union {
570                 /* HL_MEM_OP_ALLOC- allocate device memory */
571                 struct {
572                         /* Size to alloc */
573                         __u64 mem_size;
574                 } alloc;
575
576                 /* HL_MEM_OP_FREE - free device memory */
577                 struct {
578                         /* Handle returned from HL_MEM_OP_ALLOC */
579                         __u64 handle;
580                 } free;
581
582                 /* HL_MEM_OP_MAP - map device memory */
583                 struct {
584                         /*
585                          * Requested virtual address of mapped memory.
586                          * The driver will try to map the requested region to
587                          * this hint address, as long as the address is valid
588                          * and not already mapped. The user should check the
589                          * returned address of the IOCTL to make sure he got
590                          * the hint address. Passing 0 here means that the
591                          * driver will choose the address itself.
592                          */
593                         __u64 hint_addr;
594                         /* Handle returned from HL_MEM_OP_ALLOC */
595                         __u64 handle;
596                 } map_device;
597
598                 /* HL_MEM_OP_MAP - map host memory */
599                 struct {
600                         /* Address of allocated host memory */
601                         __u64 host_virt_addr;
602                         /*
603                          * Requested virtual address of mapped memory.
604                          * The driver will try to map the requested region to
605                          * this hint address, as long as the address is valid
606                          * and not already mapped. The user should check the
607                          * returned address of the IOCTL to make sure he got
608                          * the hint address. Passing 0 here means that the
609                          * driver will choose the address itself.
610                          */
611                         __u64 hint_addr;
612                         /* Size of allocated host memory */
613                         __u64 mem_size;
614                 } map_host;
615
616                 /* HL_MEM_OP_UNMAP - unmap host memory */
617                 struct {
618                         /* Virtual address returned from HL_MEM_OP_MAP */
619                         __u64 device_virt_addr;
620                 } unmap;
621         };
622
623         /* HL_MEM_OP_* */
624         __u32 op;
625         /* HL_MEM_* flags */
626         __u32 flags;
627         /* Context ID - Currently not in use */
628         __u32 ctx_id;
629         __u32 pad;
630 };
631
632 struct hl_mem_out {
633         union {
634                 /*
635                  * Used for HL_MEM_OP_MAP as the virtual address that was
636                  * assigned in the device VA space.
637                  * A value of 0 means the requested operation failed.
638                  */
639                 __u64 device_virt_addr;
640
641                 /*
642                  * Used for HL_MEM_OP_ALLOC. This is the assigned
643                  * handle for the allocated memory
644                  */
645                 __u64 handle;
646         };
647 };
648
649 union hl_mem_args {
650         struct hl_mem_in in;
651         struct hl_mem_out out;
652 };
653
654 #define HL_DEBUG_MAX_AUX_VALUES         10
655
656 struct hl_debug_params_etr {
657         /* Address in memory to allocate buffer */
658         __u64 buffer_address;
659
660         /* Size of buffer to allocate */
661         __u64 buffer_size;
662
663         /* Sink operation mode: SW fifo, HW fifo, Circular buffer */
664         __u32 sink_mode;
665         __u32 pad;
666 };
667
668 struct hl_debug_params_etf {
669         /* Address in memory to allocate buffer */
670         __u64 buffer_address;
671
672         /* Size of buffer to allocate */
673         __u64 buffer_size;
674
675         /* Sink operation mode: SW fifo, HW fifo, Circular buffer */
676         __u32 sink_mode;
677         __u32 pad;
678 };
679
680 struct hl_debug_params_stm {
681         /* Two bit masks for HW event and Stimulus Port */
682         __u64 he_mask;
683         __u64 sp_mask;
684
685         /* Trace source ID */
686         __u32 id;
687
688         /* Frequency for the timestamp register */
689         __u32 frequency;
690 };
691
692 struct hl_debug_params_bmon {
693         /* Two address ranges that the user can request to filter */
694         __u64 start_addr0;
695         __u64 addr_mask0;
696
697         __u64 start_addr1;
698         __u64 addr_mask1;
699
700         /* Capture window configuration */
701         __u32 bw_win;
702         __u32 win_capture;
703
704         /* Trace source ID */
705         __u32 id;
706         __u32 pad;
707 };
708
709 struct hl_debug_params_spmu {
710         /* Event types selection */
711         __u64 event_types[HL_DEBUG_MAX_AUX_VALUES];
712
713         /* Number of event types selection */
714         __u32 event_types_num;
715         __u32 pad;
716 };
717
718 /* Opcode for ETR component */
719 #define HL_DEBUG_OP_ETR         0
720 /* Opcode for ETF component */
721 #define HL_DEBUG_OP_ETF         1
722 /* Opcode for STM component */
723 #define HL_DEBUG_OP_STM         2
724 /* Opcode for FUNNEL component */
725 #define HL_DEBUG_OP_FUNNEL      3
726 /* Opcode for BMON component */
727 #define HL_DEBUG_OP_BMON        4
728 /* Opcode for SPMU component */
729 #define HL_DEBUG_OP_SPMU        5
730 /* Opcode for timestamp (deprecated) */
731 #define HL_DEBUG_OP_TIMESTAMP   6
732 /* Opcode for setting the device into or out of debug mode. The enable
733  * variable should be 1 for enabling debug mode and 0 for disabling it
734  */
735 #define HL_DEBUG_OP_SET_MODE    7
736
737 struct hl_debug_args {
738         /*
739          * Pointer to user input structure.
740          * This field is relevant to specific opcodes.
741          */
742         __u64 input_ptr;
743         /* Pointer to user output structure */
744         __u64 output_ptr;
745         /* Size of user input structure */
746         __u32 input_size;
747         /* Size of user output structure */
748         __u32 output_size;
749         /* HL_DEBUG_OP_* */
750         __u32 op;
751         /*
752          * Register index in the component, taken from the debug_regs_index enum
753          * in the various ASIC header files
754          */
755         __u32 reg_idx;
756         /* Enable/disable */
757         __u32 enable;
758         /* Context ID - Currently not in use */
759         __u32 ctx_id;
760 };
761
762 /*
763  * Various information operations such as:
764  * - H/W IP information
765  * - Current dram usage
766  *
767  * The user calls this IOCTL with an opcode that describes the required
768  * information. The user should supply a pointer to a user-allocated memory
769  * chunk, which will be filled by the driver with the requested information.
770  *
771  * The user supplies the maximum amount of size to copy into the user's memory,
772  * in order to prevent data corruption in case of differences between the
773  * definitions of structures in kernel and userspace, e.g. in case of old
774  * userspace and new kernel driver
775  */
776 #define HL_IOCTL_INFO   \
777                 _IOWR('H', 0x01, struct hl_info_args)
778
779 /*
780  * Command Buffer
781  * - Request a Command Buffer
782  * - Destroy a Command Buffer
783  *
784  * The command buffers are memory blocks that reside in DMA-able address
785  * space and are physically contiguous so they can be accessed by the device
786  * directly. They are allocated using the coherent DMA API.
787  *
788  * When creating a new CB, the IOCTL returns a handle of it, and the user-space
789  * process needs to use that handle to mmap the buffer so it can access them.
790  *
791  */
792 #define HL_IOCTL_CB             \
793                 _IOWR('H', 0x02, union hl_cb_args)
794
795 /*
796  * Command Submission
797  *
798  * To submit work to the device, the user need to call this IOCTL with a set
799  * of JOBS. That set of JOBS constitutes a CS object.
800  * Each JOB will be enqueued on a specific queue, according to the user's input.
801  * There can be more then one JOB per queue.
802  *
803  * The CS IOCTL will receive three sets of JOBS. One set is for "restore" phase,
804  * a second set is for "execution" phase and a third set is for "store" phase.
805  * The JOBS on the "restore" phase are enqueued only after context-switch
806  * (or if its the first CS for this context). The user can also order the
807  * driver to run the "restore" phase explicitly
808  *
809  * There are two types of queues - external and internal. External queues
810  * are DMA queues which transfer data from/to the Host. All other queues are
811  * internal. The driver will get completion notifications from the device only
812  * on JOBS which are enqueued in the external queues.
813  *
814  * For jobs on external queues, the user needs to create command buffers
815  * through the CB ioctl and give the CB's handle to the CS ioctl. For jobs on
816  * internal queues, the user needs to prepare a "command buffer" with packets
817  * on either the device SRAM/DRAM or the host, and give the device address of
818  * that buffer to the CS ioctl.
819  *
820  * This IOCTL is asynchronous in regard to the actual execution of the CS. This
821  * means it returns immediately after ALL the JOBS were enqueued on their
822  * relevant queues. Therefore, the user mustn't assume the CS has been completed
823  * or has even started to execute.
824  *
825  * Upon successful enqueue, the IOCTL returns a sequence number which the user
826  * can use with the "Wait for CS" IOCTL to check whether the handle's CS
827  * external JOBS have been completed. Note that if the CS has internal JOBS
828  * which can execute AFTER the external JOBS have finished, the driver might
829  * report that the CS has finished executing BEFORE the internal JOBS have
830  * actually finished executing.
831  *
832  * Even though the sequence number increments per CS, the user can NOT
833  * automatically assume that if CS with sequence number N finished, then CS
834  * with sequence number N-1 also finished. The user can make this assumption if
835  * and only if CS N and CS N-1 are exactly the same (same CBs for the same
836  * queues).
837  */
838 #define HL_IOCTL_CS                     \
839                 _IOWR('H', 0x03, union hl_cs_args)
840
841 /*
842  * Wait for Command Submission
843  *
844  * The user can call this IOCTL with a handle it received from the CS IOCTL
845  * to wait until the handle's CS has finished executing. The user will wait
846  * inside the kernel until the CS has finished or until the user-requested
847  * timeout has expired.
848  *
849  * The return value of the IOCTL is a standard Linux error code. The possible
850  * values are:
851  *
852  * EINTR     - Kernel waiting has been interrupted, e.g. due to OS signal
853  *             that the user process received
854  * ETIMEDOUT - The CS has caused a timeout on the device
855  * EIO       - The CS was aborted (usually because the device was reset)
856  * ENODEV    - The device wants to do hard-reset (so user need to close FD)
857  *
858  * The driver also returns a custom define inside the IOCTL which can be:
859  *
860  * HL_WAIT_CS_STATUS_COMPLETED   - The CS has been completed successfully (0)
861  * HL_WAIT_CS_STATUS_BUSY        - The CS is still executing (0)
862  * HL_WAIT_CS_STATUS_TIMEDOUT    - The CS has caused a timeout on the device
863  *                                 (ETIMEDOUT)
864  * HL_WAIT_CS_STATUS_ABORTED     - The CS was aborted, usually because the
865  *                                 device was reset (EIO)
866  * HL_WAIT_CS_STATUS_INTERRUPTED - Waiting for the CS was interrupted (EINTR)
867  *
868  */
869
870 #define HL_IOCTL_WAIT_CS                        \
871                 _IOWR('H', 0x04, union hl_wait_cs_args)
872
873 /*
874  * Memory
875  * - Map host memory to device MMU
876  * - Unmap host memory from device MMU
877  *
878  * This IOCTL allows the user to map host memory to the device MMU
879  *
880  * For host memory, the IOCTL doesn't allocate memory. The user is supposed
881  * to allocate the memory in user-space (malloc/new). The driver pins the
882  * physical pages (up to the allowed limit by the OS), assigns a virtual
883  * address in the device VA space and initializes the device MMU.
884  *
885  * There is an option for the user to specify the requested virtual address.
886  *
887  */
888 #define HL_IOCTL_MEMORY         \
889                 _IOWR('H', 0x05, union hl_mem_args)
890
891 /*
892  * Debug
893  * - Enable/disable the ETR/ETF/FUNNEL/STM/BMON/SPMU debug traces
894  *
895  * This IOCTL allows the user to get debug traces from the chip.
896  *
897  * Before the user can send configuration requests of the various
898  * debug/profile engines, it needs to set the device into debug mode.
899  * This is because the debug/profile infrastructure is shared component in the
900  * device and we can't allow multiple users to access it at the same time.
901  *
902  * Once a user set the device into debug mode, the driver won't allow other
903  * users to "work" with the device, i.e. open a FD. If there are multiple users
904  * opened on the device, the driver won't allow any user to debug the device.
905  *
906  * For each configuration request, the user needs to provide the register index
907  * and essential data such as buffer address and size.
908  *
909  * Once the user has finished using the debug/profile engines, he should
910  * set the device into non-debug mode, i.e. disable debug mode.
911  *
912  * The driver can decide to "kick out" the user if he abuses this interface.
913  *
914  */
915 #define HL_IOCTL_DEBUG          \
916                 _IOWR('H', 0x06, struct hl_debug_args)
917
918 #define HL_COMMAND_START        0x01
919 #define HL_COMMAND_END          0x07
920
921 #endif /* HABANALABS_H_ */
This page took 0.088015 seconds and 4 git commands to generate.