1e65e175bSOded Gabbay /* SPDX-License-Identifier: GPL-2.0
2e65e175bSOded Gabbay *
3e65e175bSOded Gabbay * Copyright 2016-2022 HabanaLabs, Ltd.
4e65e175bSOded Gabbay * All Rights Reserved.
5e65e175bSOded Gabbay *
6e65e175bSOded Gabbay */
7e65e175bSOded Gabbay
8e65e175bSOded Gabbay #ifndef HABANALABSP_H_
9e65e175bSOded Gabbay #define HABANALABSP_H_
10e65e175bSOded Gabbay
11e65e175bSOded Gabbay #include "../include/common/cpucp_if.h"
12e65e175bSOded Gabbay #include "../include/common/qman_if.h"
13e65e175bSOded Gabbay #include "../include/hw_ip/mmu/mmu_general.h"
14e65e175bSOded Gabbay #include <uapi/drm/habanalabs_accel.h>
15e65e175bSOded Gabbay
16e65e175bSOded Gabbay #include <linux/cdev.h>
17e65e175bSOded Gabbay #include <linux/iopoll.h>
18e65e175bSOded Gabbay #include <linux/irqreturn.h>
19e65e175bSOded Gabbay #include <linux/dma-direction.h>
20e65e175bSOded Gabbay #include <linux/scatterlist.h>
21e65e175bSOded Gabbay #include <linux/hashtable.h>
22e65e175bSOded Gabbay #include <linux/debugfs.h>
23e65e175bSOded Gabbay #include <linux/rwsem.h>
24e65e175bSOded Gabbay #include <linux/eventfd.h>
25e65e175bSOded Gabbay #include <linux/bitfield.h>
26e65e175bSOded Gabbay #include <linux/genalloc.h>
27e65e175bSOded Gabbay #include <linux/sched/signal.h>
28e65e175bSOded Gabbay #include <linux/io-64-nonatomic-lo-hi.h>
29e65e175bSOded Gabbay #include <linux/coresight.h>
30e65e175bSOded Gabbay #include <linux/dma-buf.h>
31e65e175bSOded Gabbay
32f7d67c1cSKoby Elbaz #include "security.h"
33f7d67c1cSKoby Elbaz
34e65e175bSOded Gabbay #define HL_NAME "habanalabs"
35e65e175bSOded Gabbay
36e65e175bSOded Gabbay struct hl_device;
37e65e175bSOded Gabbay struct hl_fpriv;
38e65e175bSOded Gabbay
39d8b9cea5SOfir Bitton #define PCI_VENDOR_ID_HABANALABS 0x1da3
40d8b9cea5SOfir Bitton
41e65e175bSOded Gabbay /* Use upper bits of mmap offset to store habana driver specific information.
42e65e175bSOded Gabbay * bits[63:59] - Encode mmap type
43e65e175bSOded Gabbay * bits[45:0] - mmap offset value
44e65e175bSOded Gabbay *
45e65e175bSOded Gabbay * NOTE: struct vm_area_struct.vm_pgoff uses offset in pages. Hence, these
46e65e175bSOded Gabbay * defines are w.r.t to PAGE_SIZE
47e65e175bSOded Gabbay */
48e65e175bSOded Gabbay #define HL_MMAP_TYPE_SHIFT (59 - PAGE_SHIFT)
49e65e175bSOded Gabbay #define HL_MMAP_TYPE_MASK (0x1full << HL_MMAP_TYPE_SHIFT)
50e65e175bSOded Gabbay #define HL_MMAP_TYPE_TS_BUFF (0x10ull << HL_MMAP_TYPE_SHIFT)
51e65e175bSOded Gabbay #define HL_MMAP_TYPE_BLOCK (0x4ull << HL_MMAP_TYPE_SHIFT)
52e65e175bSOded Gabbay #define HL_MMAP_TYPE_CB (0x2ull << HL_MMAP_TYPE_SHIFT)
53e65e175bSOded Gabbay
54e65e175bSOded Gabbay #define HL_MMAP_OFFSET_VALUE_MASK (0x1FFFFFFFFFFFull >> PAGE_SHIFT)
55e65e175bSOded Gabbay #define HL_MMAP_OFFSET_VALUE_GET(off) (off & HL_MMAP_OFFSET_VALUE_MASK)
56e65e175bSOded Gabbay
57e65e175bSOded Gabbay #define HL_PENDING_RESET_PER_SEC 10
58e65e175bSOded Gabbay #define HL_PENDING_RESET_MAX_TRIALS 60 /* 10 minutes */
59e65e175bSOded Gabbay #define HL_PENDING_RESET_LONG_SEC 60
60e65e175bSOded Gabbay /*
61e65e175bSOded Gabbay * In device fini, wait 10 minutes for user processes to be terminated after we kill them.
62e65e175bSOded Gabbay * This is needed to prevent situation of clearing resources while user processes are still alive.
63e65e175bSOded Gabbay */
64e65e175bSOded Gabbay #define HL_WAIT_PROCESS_KILL_ON_DEVICE_FINI 600
65e65e175bSOded Gabbay
66e65e175bSOded Gabbay #define HL_HARD_RESET_MAX_TIMEOUT 120
67e65e175bSOded Gabbay #define HL_PLDM_HARD_RESET_MAX_TIMEOUT (HL_HARD_RESET_MAX_TIMEOUT * 3)
68e65e175bSOded Gabbay
69e65e175bSOded Gabbay #define HL_DEVICE_TIMEOUT_USEC 1000000 /* 1 s */
70e65e175bSOded Gabbay
71e65e175bSOded Gabbay #define HL_HEARTBEAT_PER_USEC 5000000 /* 5 s */
72e65e175bSOded Gabbay
73e65e175bSOded Gabbay #define HL_PLL_LOW_JOB_FREQ_USEC 5000000 /* 5 s */
74e65e175bSOded Gabbay
75e65e175bSOded Gabbay #define HL_CPUCP_INFO_TIMEOUT_USEC 10000000 /* 10s */
76e65e175bSOded Gabbay #define HL_CPUCP_EEPROM_TIMEOUT_USEC 10000000 /* 10s */
77e65e175bSOded Gabbay #define HL_CPUCP_MON_DUMP_TIMEOUT_USEC 10000000 /* 10s */
78e65e175bSOded Gabbay #define HL_CPUCP_SEC_ATTEST_INFO_TINEOUT_USEC 10000000 /* 10s */
79e65e175bSOded Gabbay
80e65e175bSOded Gabbay #define HL_FW_STATUS_POLL_INTERVAL_USEC 10000 /* 10ms */
81e65e175bSOded Gabbay #define HL_FW_COMMS_STATUS_PLDM_POLL_INTERVAL_USEC 1000000 /* 1s */
82e65e175bSOded Gabbay
83e65e175bSOded Gabbay #define HL_PCI_ELBI_TIMEOUT_MSEC 10 /* 10ms */
84e65e175bSOded Gabbay
85e65e175bSOded Gabbay #define HL_SIM_MAX_TIMEOUT_US 100000000 /* 100s */
86e65e175bSOded Gabbay
87e65e175bSOded Gabbay #define HL_INVALID_QUEUE UINT_MAX
88e65e175bSOded Gabbay
89e65e175bSOded Gabbay #define HL_COMMON_USER_CQ_INTERRUPT_ID 0xFFF
90e65e175bSOded Gabbay #define HL_COMMON_DEC_INTERRUPT_ID 0xFFE
91e65e175bSOded Gabbay
92e65e175bSOded Gabbay #define HL_STATE_DUMP_HIST_LEN 5
93e65e175bSOded Gabbay
94e65e175bSOded Gabbay /* Default value for device reset trigger , an invalid value */
95e65e175bSOded Gabbay #define HL_RESET_TRIGGER_DEFAULT 0xFF
96e65e175bSOded Gabbay
97e65e175bSOded Gabbay #define OBJ_NAMES_HASH_TABLE_BITS 7 /* 1 << 7 buckets */
98e65e175bSOded Gabbay #define SYNC_TO_ENGINE_HASH_TABLE_BITS 7 /* 1 << 7 buckets */
99e65e175bSOded Gabbay
100e65e175bSOded Gabbay /* Memory */
101e65e175bSOded Gabbay #define MEM_HASH_TABLE_BITS 7 /* 1 << 7 buckets */
102e65e175bSOded Gabbay
103e65e175bSOded Gabbay /* MMU */
104e65e175bSOded Gabbay #define MMU_HASH_TABLE_BITS 7 /* 1 << 7 buckets */
105e65e175bSOded Gabbay
106e65e175bSOded Gabbay /**
107e65e175bSOded Gabbay * enum hl_mmu_page_table_location - mmu page table location
108e65e175bSOded Gabbay * @MMU_DR_PGT: page-table is located on device DRAM.
109e65e175bSOded Gabbay * @MMU_HR_PGT: page-table is located on host memory.
110e65e175bSOded Gabbay * @MMU_NUM_PGT_LOCATIONS: number of page-table locations currently supported.
111e65e175bSOded Gabbay */
112e65e175bSOded Gabbay enum hl_mmu_page_table_location {
113e65e175bSOded Gabbay MMU_DR_PGT = 0, /* device-dram-resident MMU PGT */
114e65e175bSOded Gabbay MMU_HR_PGT, /* host resident MMU PGT */
115e65e175bSOded Gabbay MMU_NUM_PGT_LOCATIONS /* num of PGT locations */
116e65e175bSOded Gabbay };
117e65e175bSOded Gabbay
118e65e175bSOded Gabbay /*
119e65e175bSOded Gabbay * HL_RSVD_SOBS 'sync stream' reserved sync objects per QMAN stream
120e65e175bSOded Gabbay * HL_RSVD_MONS 'sync stream' reserved monitors per QMAN stream
121e65e175bSOded Gabbay */
122e65e175bSOded Gabbay #define HL_RSVD_SOBS 2
123e65e175bSOded Gabbay #define HL_RSVD_MONS 1
124e65e175bSOded Gabbay
125e65e175bSOded Gabbay /*
126e65e175bSOded Gabbay * HL_COLLECTIVE_RSVD_MSTR_MONS 'collective' reserved monitors per QMAN stream
127e65e175bSOded Gabbay */
128e65e175bSOded Gabbay #define HL_COLLECTIVE_RSVD_MSTR_MONS 2
129e65e175bSOded Gabbay
130e65e175bSOded Gabbay #define HL_MAX_SOB_VAL (1 << 15)
131e65e175bSOded Gabbay
132e65e175bSOded Gabbay #define IS_POWER_OF_2(n) (n != 0 && ((n & (n - 1)) == 0))
133e65e175bSOded Gabbay #define IS_MAX_PENDING_CS_VALID(n) (IS_POWER_OF_2(n) && (n > 1))
134e65e175bSOded Gabbay
135e65e175bSOded Gabbay #define HL_PCI_NUM_BARS 6
136e65e175bSOded Gabbay
137e65e175bSOded Gabbay /* Completion queue entry relates to completed job */
138e65e175bSOded Gabbay #define HL_COMPLETION_MODE_JOB 0
139e65e175bSOded Gabbay /* Completion queue entry relates to completed command submission */
140e65e175bSOded Gabbay #define HL_COMPLETION_MODE_CS 1
141e65e175bSOded Gabbay
142e65e175bSOded Gabbay #define HL_MAX_DCORES 8
143e65e175bSOded Gabbay
144e65e175bSOded Gabbay /* DMA alloc/free wrappers */
145e65e175bSOded Gabbay #define hl_asic_dma_alloc_coherent(hdev, size, dma_handle, flags) \
146e65e175bSOded Gabbay hl_asic_dma_alloc_coherent_caller(hdev, size, dma_handle, flags, __func__)
147e65e175bSOded Gabbay
148e65e175bSOded Gabbay #define hl_asic_dma_pool_zalloc(hdev, size, mem_flags, dma_handle) \
149e65e175bSOded Gabbay hl_asic_dma_pool_zalloc_caller(hdev, size, mem_flags, dma_handle, __func__)
150e65e175bSOded Gabbay
151e65e175bSOded Gabbay #define hl_asic_dma_free_coherent(hdev, size, cpu_addr, dma_handle) \
152e65e175bSOded Gabbay hl_asic_dma_free_coherent_caller(hdev, size, cpu_addr, dma_handle, __func__)
153e65e175bSOded Gabbay
154e65e175bSOded Gabbay #define hl_asic_dma_pool_free(hdev, vaddr, dma_addr) \
155e65e175bSOded Gabbay hl_asic_dma_pool_free_caller(hdev, vaddr, dma_addr, __func__)
156e65e175bSOded Gabbay
157e65e175bSOded Gabbay /*
158e65e175bSOded Gabbay * Reset Flags
159e65e175bSOded Gabbay *
160e65e175bSOded Gabbay * - HL_DRV_RESET_HARD
161e65e175bSOded Gabbay * If set do hard reset to all engines. If not set reset just
162e65e175bSOded Gabbay * compute/DMA engines.
163e65e175bSOded Gabbay *
164e65e175bSOded Gabbay * - HL_DRV_RESET_FROM_RESET_THR
165e65e175bSOded Gabbay * Set if the caller is the hard-reset thread
166e65e175bSOded Gabbay *
167e65e175bSOded Gabbay * - HL_DRV_RESET_HEARTBEAT
168e65e175bSOded Gabbay * Set if reset is due to heartbeat
169e65e175bSOded Gabbay *
170e65e175bSOded Gabbay * - HL_DRV_RESET_TDR
171e65e175bSOded Gabbay * Set if reset is due to TDR
172e65e175bSOded Gabbay *
173e65e175bSOded Gabbay * - HL_DRV_RESET_DEV_RELEASE
174e65e175bSOded Gabbay * Set if reset is due to device release
175e65e175bSOded Gabbay *
176e65e175bSOded Gabbay * - HL_DRV_RESET_BYPASS_REQ_TO_FW
177e65e175bSOded Gabbay * F/W will perform the reset. No need to ask it to reset the device. This is relevant
178e65e175bSOded Gabbay * only when running with secured f/w
179e65e175bSOded Gabbay *
180e65e175bSOded Gabbay * - HL_DRV_RESET_FW_FATAL_ERR
181e65e175bSOded Gabbay * Set if reset is due to a fatal error from FW
182e65e175bSOded Gabbay *
183e65e175bSOded Gabbay * - HL_DRV_RESET_DELAY
184e65e175bSOded Gabbay * Set if a delay should be added before the reset
185e65e175bSOded Gabbay *
186e65e175bSOded Gabbay * - HL_DRV_RESET_FROM_WD_THR
187e65e175bSOded Gabbay * Set if the caller is the device release watchdog thread
188e65e175bSOded Gabbay */
189e65e175bSOded Gabbay
190e65e175bSOded Gabbay #define HL_DRV_RESET_HARD (1 << 0)
191e65e175bSOded Gabbay #define HL_DRV_RESET_FROM_RESET_THR (1 << 1)
192e65e175bSOded Gabbay #define HL_DRV_RESET_HEARTBEAT (1 << 2)
193e65e175bSOded Gabbay #define HL_DRV_RESET_TDR (1 << 3)
194e65e175bSOded Gabbay #define HL_DRV_RESET_DEV_RELEASE (1 << 4)
195e65e175bSOded Gabbay #define HL_DRV_RESET_BYPASS_REQ_TO_FW (1 << 5)
196e65e175bSOded Gabbay #define HL_DRV_RESET_FW_FATAL_ERR (1 << 6)
197e65e175bSOded Gabbay #define HL_DRV_RESET_DELAY (1 << 7)
198e65e175bSOded Gabbay #define HL_DRV_RESET_FROM_WD_THR (1 << 8)
199e65e175bSOded Gabbay
200e65e175bSOded Gabbay /*
201e65e175bSOded Gabbay * Security
202e65e175bSOded Gabbay */
203e65e175bSOded Gabbay
204e65e175bSOded Gabbay #define HL_PB_SHARED 1
205e65e175bSOded Gabbay #define HL_PB_NA 0
206e65e175bSOded Gabbay #define HL_PB_SINGLE_INSTANCE 1
207e65e175bSOded Gabbay #define HL_BLOCK_SIZE 0x1000
208e65e175bSOded Gabbay #define HL_BLOCK_GLBL_ERR_MASK 0xF40
209e65e175bSOded Gabbay #define HL_BLOCK_GLBL_ERR_ADDR 0xF44
210e65e175bSOded Gabbay #define HL_BLOCK_GLBL_ERR_CAUSE 0xF48
211e65e175bSOded Gabbay #define HL_BLOCK_GLBL_SEC_OFFS 0xF80
212e65e175bSOded Gabbay #define HL_BLOCK_GLBL_SEC_SIZE (HL_BLOCK_SIZE - HL_BLOCK_GLBL_SEC_OFFS)
213e65e175bSOded Gabbay #define HL_BLOCK_GLBL_SEC_LEN (HL_BLOCK_GLBL_SEC_SIZE / sizeof(u32))
214e65e175bSOded Gabbay #define UNSET_GLBL_SEC_BIT(array, b) ((array)[((b) / 32)] |= (1 << ((b) % 32)))
215e65e175bSOded Gabbay
216e65e175bSOded Gabbay enum hl_protection_levels {
217e65e175bSOded Gabbay SECURED_LVL,
218e65e175bSOded Gabbay PRIVILEGED_LVL,
219e65e175bSOded Gabbay NON_SECURED_LVL
220e65e175bSOded Gabbay };
221e65e175bSOded Gabbay
222e65e175bSOded Gabbay /**
223e65e175bSOded Gabbay * struct iterate_module_ctx - HW module iterator
224e65e175bSOded Gabbay * @fn: function to apply to each HW module instance
225e65e175bSOded Gabbay * @data: optional internal data to the function iterator
226e65e175bSOded Gabbay * @rc: return code for optional use of iterator/iterator-caller
227e65e175bSOded Gabbay */
228e65e175bSOded Gabbay struct iterate_module_ctx {
229e65e175bSOded Gabbay /*
230e65e175bSOded Gabbay * callback for the HW module iterator
231e65e175bSOded Gabbay * @hdev: pointer to the habanalabs device structure
232e65e175bSOded Gabbay * @block: block (ASIC specific definition can be dcore/hdcore)
233e65e175bSOded Gabbay * @inst: HW module instance within the block
234e65e175bSOded Gabbay * @offset: current HW module instance offset from the 1-st HW module instance
235e65e175bSOded Gabbay * in the 1-st block
236e65e175bSOded Gabbay * @ctx: the iterator context.
237e65e175bSOded Gabbay */
238e65e175bSOded Gabbay void (*fn)(struct hl_device *hdev, int block, int inst, u32 offset,
239e65e175bSOded Gabbay struct iterate_module_ctx *ctx);
240e65e175bSOded Gabbay void *data;
241e65e175bSOded Gabbay int rc;
242e65e175bSOded Gabbay };
243e65e175bSOded Gabbay
244e65e175bSOded Gabbay struct hl_block_glbl_sec {
245e65e175bSOded Gabbay u32 sec_array[HL_BLOCK_GLBL_SEC_LEN];
246e65e175bSOded Gabbay };
247e65e175bSOded Gabbay
248e65e175bSOded Gabbay #define HL_MAX_SOBS_PER_MONITOR 8
249e65e175bSOded Gabbay
250e65e175bSOded Gabbay /**
251e65e175bSOded Gabbay * struct hl_gen_wait_properties - properties for generating a wait CB
252e65e175bSOded Gabbay * @data: command buffer
253e65e175bSOded Gabbay * @q_idx: queue id is used to extract fence register address
254e65e175bSOded Gabbay * @size: offset in command buffer
255e65e175bSOded Gabbay * @sob_base: SOB base to use in this wait CB
256e65e175bSOded Gabbay * @sob_val: SOB value to wait for
257e65e175bSOded Gabbay * @mon_id: monitor to use in this wait CB
258e65e175bSOded Gabbay * @sob_mask: each bit represents a SOB offset from sob_base to be used
259e65e175bSOded Gabbay */
260e65e175bSOded Gabbay struct hl_gen_wait_properties {
261e65e175bSOded Gabbay void *data;
262e65e175bSOded Gabbay u32 q_idx;
263e65e175bSOded Gabbay u32 size;
264e65e175bSOded Gabbay u16 sob_base;
265e65e175bSOded Gabbay u16 sob_val;
266e65e175bSOded Gabbay u16 mon_id;
267e65e175bSOded Gabbay u8 sob_mask;
268e65e175bSOded Gabbay };
269e65e175bSOded Gabbay
270e65e175bSOded Gabbay /**
271e65e175bSOded Gabbay * struct pgt_info - MMU hop page info.
272e65e175bSOded Gabbay * @node: hash linked-list node for the pgts on host (shadow pgts for device resident MMU and
273e65e175bSOded Gabbay * actual pgts for host resident MMU).
274e65e175bSOded Gabbay * @phys_addr: physical address of the pgt.
275e65e175bSOded Gabbay * @virt_addr: host virtual address of the pgt (see above device/host resident).
276e65e175bSOded Gabbay * @shadow_addr: shadow hop in the host for device resident MMU.
277e65e175bSOded Gabbay * @ctx: pointer to the owner ctx.
278e65e175bSOded Gabbay * @num_of_ptes: indicates how many ptes are used in the pgt. used only for dynamically
279e65e175bSOded Gabbay * allocated HOPs (all HOPs but HOP0)
280e65e175bSOded Gabbay *
281e65e175bSOded Gabbay * The MMU page tables hierarchy can be placed either on the device's DRAM (in which case shadow
282e65e175bSOded Gabbay * pgts will be stored on host memory) or on host memory (in which case no shadow is required).
283e65e175bSOded Gabbay *
284e65e175bSOded Gabbay * When a new level (hop) is needed during mapping this structure will be used to describe
285e65e175bSOded Gabbay * the newly allocated hop as well as to track number of PTEs in it.
286e65e175bSOded Gabbay * During unmapping, if no valid PTEs remained in the page of a newly allocated hop, it is
287e65e175bSOded Gabbay * freed with its pgt_info structure.
288e65e175bSOded Gabbay */
289e65e175bSOded Gabbay struct pgt_info {
290e65e175bSOded Gabbay struct hlist_node node;
291e65e175bSOded Gabbay u64 phys_addr;
292e65e175bSOded Gabbay u64 virt_addr;
293e65e175bSOded Gabbay u64 shadow_addr;
294e65e175bSOded Gabbay struct hl_ctx *ctx;
295e65e175bSOded Gabbay int num_of_ptes;
296e65e175bSOded Gabbay };
297e65e175bSOded Gabbay
298e65e175bSOded Gabbay /**
299e65e175bSOded Gabbay * enum hl_pci_match_mode - pci match mode per region
300e65e175bSOded Gabbay * @PCI_ADDRESS_MATCH_MODE: address match mode
301e65e175bSOded Gabbay * @PCI_BAR_MATCH_MODE: bar match mode
302e65e175bSOded Gabbay */
303e65e175bSOded Gabbay enum hl_pci_match_mode {
304e65e175bSOded Gabbay PCI_ADDRESS_MATCH_MODE,
305e65e175bSOded Gabbay PCI_BAR_MATCH_MODE
306e65e175bSOded Gabbay };
307e65e175bSOded Gabbay
308e65e175bSOded Gabbay /**
309e65e175bSOded Gabbay * enum hl_fw_component - F/W components to read version through registers.
310e65e175bSOded Gabbay * @FW_COMP_BOOT_FIT: boot fit.
311e65e175bSOded Gabbay * @FW_COMP_PREBOOT: preboot.
312e65e175bSOded Gabbay * @FW_COMP_LINUX: linux.
313e65e175bSOded Gabbay */
314e65e175bSOded Gabbay enum hl_fw_component {
315e65e175bSOded Gabbay FW_COMP_BOOT_FIT,
316e65e175bSOded Gabbay FW_COMP_PREBOOT,
317e65e175bSOded Gabbay FW_COMP_LINUX,
318e65e175bSOded Gabbay };
319e65e175bSOded Gabbay
320e65e175bSOded Gabbay /**
321e65e175bSOded Gabbay * enum hl_fw_types - F/W types present in the system
322e65e175bSOded Gabbay * @FW_TYPE_NONE: no FW component indication
323e65e175bSOded Gabbay * @FW_TYPE_LINUX: Linux image for device CPU
324e65e175bSOded Gabbay * @FW_TYPE_BOOT_CPU: Boot image for device CPU
325e65e175bSOded Gabbay * @FW_TYPE_PREBOOT_CPU: Indicates pre-loaded CPUs are present in the system
326e65e175bSOded Gabbay * (preboot, ppboot etc...)
327e65e175bSOded Gabbay * @FW_TYPE_ALL_TYPES: Mask for all types
328e65e175bSOded Gabbay */
329e65e175bSOded Gabbay enum hl_fw_types {
330e65e175bSOded Gabbay FW_TYPE_NONE = 0x0,
331e65e175bSOded Gabbay FW_TYPE_LINUX = 0x1,
332e65e175bSOded Gabbay FW_TYPE_BOOT_CPU = 0x2,
333e65e175bSOded Gabbay FW_TYPE_PREBOOT_CPU = 0x4,
334e65e175bSOded Gabbay FW_TYPE_ALL_TYPES =
335e65e175bSOded Gabbay (FW_TYPE_LINUX | FW_TYPE_BOOT_CPU | FW_TYPE_PREBOOT_CPU)
336e65e175bSOded Gabbay };
337e65e175bSOded Gabbay
338e65e175bSOded Gabbay /**
339e65e175bSOded Gabbay * enum hl_queue_type - Supported QUEUE types.
340e65e175bSOded Gabbay * @QUEUE_TYPE_NA: queue is not available.
341e65e175bSOded Gabbay * @QUEUE_TYPE_EXT: external queue which is a DMA channel that may access the
342e65e175bSOded Gabbay * host.
343e65e175bSOded Gabbay * @QUEUE_TYPE_INT: internal queue that performs DMA inside the device's
344e65e175bSOded Gabbay * memories and/or operates the compute engines.
345e65e175bSOded Gabbay * @QUEUE_TYPE_CPU: S/W queue for communication with the device's CPU.
346e65e175bSOded Gabbay * @QUEUE_TYPE_HW: queue of DMA and compute engines jobs, for which completion
347e65e175bSOded Gabbay * notifications are sent by H/W.
348e65e175bSOded Gabbay */
349e65e175bSOded Gabbay enum hl_queue_type {
350e65e175bSOded Gabbay QUEUE_TYPE_NA,
351e65e175bSOded Gabbay QUEUE_TYPE_EXT,
352e65e175bSOded Gabbay QUEUE_TYPE_INT,
353e65e175bSOded Gabbay QUEUE_TYPE_CPU,
354e65e175bSOded Gabbay QUEUE_TYPE_HW
355e65e175bSOded Gabbay };
356e65e175bSOded Gabbay
357e65e175bSOded Gabbay enum hl_cs_type {
358e65e175bSOded Gabbay CS_TYPE_DEFAULT,
359e65e175bSOded Gabbay CS_TYPE_SIGNAL,
360e65e175bSOded Gabbay CS_TYPE_WAIT,
361e65e175bSOded Gabbay CS_TYPE_COLLECTIVE_WAIT,
362e65e175bSOded Gabbay CS_RESERVE_SIGNALS,
363e65e175bSOded Gabbay CS_UNRESERVE_SIGNALS,
36420faaeecSOhad Sharabi CS_TYPE_ENGINE_CORE,
365f7f0085eSKoby Elbaz CS_TYPE_ENGINES,
36620faaeecSOhad Sharabi CS_TYPE_FLUSH_PCI_HBW_WRITES,
367e65e175bSOded Gabbay };
368e65e175bSOded Gabbay
369e65e175bSOded Gabbay /*
370e65e175bSOded Gabbay * struct hl_inbound_pci_region - inbound region descriptor
371e65e175bSOded Gabbay * @mode: pci match mode for this region
372e65e175bSOded Gabbay * @addr: region target address
373e65e175bSOded Gabbay * @size: region size in bytes
374e65e175bSOded Gabbay * @offset_in_bar: offset within bar (address match mode)
375e65e175bSOded Gabbay * @bar: bar id
376e65e175bSOded Gabbay */
377e65e175bSOded Gabbay struct hl_inbound_pci_region {
378e65e175bSOded Gabbay enum hl_pci_match_mode mode;
379e65e175bSOded Gabbay u64 addr;
380e65e175bSOded Gabbay u64 size;
381e65e175bSOded Gabbay u64 offset_in_bar;
382e65e175bSOded Gabbay u8 bar;
383e65e175bSOded Gabbay };
384e65e175bSOded Gabbay
385e65e175bSOded Gabbay /*
386e65e175bSOded Gabbay * struct hl_outbound_pci_region - outbound region descriptor
387e65e175bSOded Gabbay * @addr: region target address
388e65e175bSOded Gabbay * @size: region size in bytes
389e65e175bSOded Gabbay */
390e65e175bSOded Gabbay struct hl_outbound_pci_region {
391e65e175bSOded Gabbay u64 addr;
392e65e175bSOded Gabbay u64 size;
393e65e175bSOded Gabbay };
394e65e175bSOded Gabbay
395e65e175bSOded Gabbay /*
396e65e175bSOded Gabbay * enum queue_cb_alloc_flags - Indicates queue support for CBs that
397e65e175bSOded Gabbay * allocated by Kernel or by User
398e65e175bSOded Gabbay * @CB_ALLOC_KERNEL: support only CBs that allocated by Kernel
399e65e175bSOded Gabbay * @CB_ALLOC_USER: support only CBs that allocated by User
400e65e175bSOded Gabbay */
401e65e175bSOded Gabbay enum queue_cb_alloc_flags {
402e65e175bSOded Gabbay CB_ALLOC_KERNEL = 0x1,
403e65e175bSOded Gabbay CB_ALLOC_USER = 0x2
404e65e175bSOded Gabbay };
405e65e175bSOded Gabbay
406e65e175bSOded Gabbay /*
407e65e175bSOded Gabbay * struct hl_hw_sob - H/W SOB info.
408e65e175bSOded Gabbay * @hdev: habanalabs device structure.
409e65e175bSOded Gabbay * @kref: refcount of this SOB. The SOB will reset once the refcount is zero.
410e65e175bSOded Gabbay * @sob_id: id of this SOB.
411e65e175bSOded Gabbay * @sob_addr: the sob offset from the base address.
412e65e175bSOded Gabbay * @q_idx: the H/W queue that uses this SOB.
413e65e175bSOded Gabbay * @need_reset: reset indication set when switching to the other sob.
414e65e175bSOded Gabbay */
415e65e175bSOded Gabbay struct hl_hw_sob {
416e65e175bSOded Gabbay struct hl_device *hdev;
417e65e175bSOded Gabbay struct kref kref;
418e65e175bSOded Gabbay u32 sob_id;
419e65e175bSOded Gabbay u32 sob_addr;
420e65e175bSOded Gabbay u32 q_idx;
421e65e175bSOded Gabbay bool need_reset;
422e65e175bSOded Gabbay };
423e65e175bSOded Gabbay
424e65e175bSOded Gabbay enum hl_collective_mode {
425e65e175bSOded Gabbay HL_COLLECTIVE_NOT_SUPPORTED = 0x0,
426e65e175bSOded Gabbay HL_COLLECTIVE_MASTER = 0x1,
427e65e175bSOded Gabbay HL_COLLECTIVE_SLAVE = 0x2
428e65e175bSOded Gabbay };
429e65e175bSOded Gabbay
430e65e175bSOded Gabbay /**
431e65e175bSOded Gabbay * struct hw_queue_properties - queue information.
432e65e175bSOded Gabbay * @type: queue type.
433e65e175bSOded Gabbay * @cb_alloc_flags: bitmap which indicates if the hw queue supports CB
434e65e175bSOded Gabbay * that allocated by the Kernel driver and therefore,
435e65e175bSOded Gabbay * a CB handle can be provided for jobs on this queue.
436e65e175bSOded Gabbay * Otherwise, a CB address must be provided.
437e65e175bSOded Gabbay * @collective_mode: collective mode of current queue
438e65e175bSOded Gabbay * @driver_only: true if only the driver is allowed to send a job to this queue,
439e65e175bSOded Gabbay * false otherwise.
440e65e175bSOded Gabbay * @binned: True if the queue is binned out and should not be used
441e65e175bSOded Gabbay * @supports_sync_stream: True if queue supports sync stream
442e65e175bSOded Gabbay */
443e65e175bSOded Gabbay struct hw_queue_properties {
444e65e175bSOded Gabbay enum hl_queue_type type;
445e65e175bSOded Gabbay enum queue_cb_alloc_flags cb_alloc_flags;
446e65e175bSOded Gabbay enum hl_collective_mode collective_mode;
447e65e175bSOded Gabbay u8 driver_only;
448e65e175bSOded Gabbay u8 binned;
449e65e175bSOded Gabbay u8 supports_sync_stream;
450e65e175bSOded Gabbay };
451e65e175bSOded Gabbay
452e65e175bSOded Gabbay /**
453e65e175bSOded Gabbay * enum vm_type - virtual memory mapping request information.
454e65e175bSOded Gabbay * @VM_TYPE_USERPTR: mapping of user memory to device virtual address.
455e65e175bSOded Gabbay * @VM_TYPE_PHYS_PACK: mapping of DRAM memory to device virtual address.
456e65e175bSOded Gabbay */
457e65e175bSOded Gabbay enum vm_type {
458e65e175bSOded Gabbay VM_TYPE_USERPTR = 0x1,
459e65e175bSOded Gabbay VM_TYPE_PHYS_PACK = 0x2
460e65e175bSOded Gabbay };
461e65e175bSOded Gabbay
462e65e175bSOded Gabbay /**
463e65e175bSOded Gabbay * enum mmu_op_flags - mmu operation relevant information.
464e65e175bSOded Gabbay * @MMU_OP_USERPTR: operation on user memory (host resident).
465e65e175bSOded Gabbay * @MMU_OP_PHYS_PACK: operation on DRAM (device resident).
466e65e175bSOded Gabbay * @MMU_OP_CLEAR_MEMCACHE: operation has to clear memcache.
467e65e175bSOded Gabbay * @MMU_OP_SKIP_LOW_CACHE_INV: operation is allowed to skip parts of cache invalidation.
468e65e175bSOded Gabbay */
469e65e175bSOded Gabbay enum mmu_op_flags {
470e65e175bSOded Gabbay MMU_OP_USERPTR = 0x1,
471e65e175bSOded Gabbay MMU_OP_PHYS_PACK = 0x2,
472e65e175bSOded Gabbay MMU_OP_CLEAR_MEMCACHE = 0x4,
473e65e175bSOded Gabbay MMU_OP_SKIP_LOW_CACHE_INV = 0x8,
474e65e175bSOded Gabbay };
475e65e175bSOded Gabbay
476e65e175bSOded Gabbay
477e65e175bSOded Gabbay /**
478e65e175bSOded Gabbay * enum hl_device_hw_state - H/W device state. use this to understand whether
479e65e175bSOded Gabbay * to do reset before hw_init or not
480e65e175bSOded Gabbay * @HL_DEVICE_HW_STATE_CLEAN: H/W state is clean. i.e. after hard reset
481e65e175bSOded Gabbay * @HL_DEVICE_HW_STATE_DIRTY: H/W state is dirty. i.e. we started to execute
482e65e175bSOded Gabbay * hw_init
483e65e175bSOded Gabbay */
484e65e175bSOded Gabbay enum hl_device_hw_state {
485e65e175bSOded Gabbay HL_DEVICE_HW_STATE_CLEAN = 0,
486e65e175bSOded Gabbay HL_DEVICE_HW_STATE_DIRTY
487e65e175bSOded Gabbay };
488e65e175bSOded Gabbay
489e65e175bSOded Gabbay #define HL_MMU_VA_ALIGNMENT_NOT_NEEDED 0
490e65e175bSOded Gabbay
491e65e175bSOded Gabbay /**
492e65e175bSOded Gabbay * struct hl_mmu_properties - ASIC specific MMU address translation properties.
493e65e175bSOded Gabbay * @start_addr: virtual start address of the memory region.
494e65e175bSOded Gabbay * @end_addr: virtual end address of the memory region.
495e65e175bSOded Gabbay * @hop_shifts: array holds HOPs shifts.
496e65e175bSOded Gabbay * @hop_masks: array holds HOPs masks.
497e65e175bSOded Gabbay * @last_mask: mask to get the bit indicating this is the last hop.
498e65e175bSOded Gabbay * @pgt_size: size for page tables.
499e65e175bSOded Gabbay * @supported_pages_mask: bitmask for supported page size (relevant only for MMUs
500e65e175bSOded Gabbay * supporting multiple page size).
501e65e175bSOded Gabbay * @page_size: default page size used to allocate memory.
502e65e175bSOded Gabbay * @num_hops: The amount of hops supported by the translation table.
503e65e175bSOded Gabbay * @hop_table_size: HOP table size.
504e65e175bSOded Gabbay * @hop0_tables_total_size: total size for all HOP0 tables.
505e65e175bSOded Gabbay * @host_resident: Should the MMU page table reside in host memory or in the
506e65e175bSOded Gabbay * device DRAM.
507e65e175bSOded Gabbay */
508e65e175bSOded Gabbay struct hl_mmu_properties {
509e65e175bSOded Gabbay u64 start_addr;
510e65e175bSOded Gabbay u64 end_addr;
511e65e175bSOded Gabbay u64 hop_shifts[MMU_HOP_MAX];
512e65e175bSOded Gabbay u64 hop_masks[MMU_HOP_MAX];
513e65e175bSOded Gabbay u64 last_mask;
514e65e175bSOded Gabbay u64 pgt_size;
515e65e175bSOded Gabbay u64 supported_pages_mask;
516e65e175bSOded Gabbay u32 page_size;
517e65e175bSOded Gabbay u32 num_hops;
518e65e175bSOded Gabbay u32 hop_table_size;
519e65e175bSOded Gabbay u32 hop0_tables_total_size;
520e65e175bSOded Gabbay u8 host_resident;
521e65e175bSOded Gabbay };
522e65e175bSOded Gabbay
523e65e175bSOded Gabbay /**
524e65e175bSOded Gabbay * struct hl_hints_range - hint addresses reserved va range.
525e65e175bSOded Gabbay * @start_addr: start address of the va range.
526e65e175bSOded Gabbay * @end_addr: end address of the va range.
527e65e175bSOded Gabbay */
528e65e175bSOded Gabbay struct hl_hints_range {
529e65e175bSOded Gabbay u64 start_addr;
530e65e175bSOded Gabbay u64 end_addr;
531e65e175bSOded Gabbay };
532e65e175bSOded Gabbay
533e65e175bSOded Gabbay /**
534e65e175bSOded Gabbay * struct asic_fixed_properties - ASIC specific immutable properties.
535e65e175bSOded Gabbay * @hw_queues_props: H/W queues properties.
536f7d67c1cSKoby Elbaz * @special_blocks: points to an array containing special blocks info.
537f7d67c1cSKoby Elbaz * @skip_special_blocks_cfg: special blocks skip configs.
538e65e175bSOded Gabbay * @cpucp_info: received various information from CPU-CP regarding the H/W, e.g.
539e65e175bSOded Gabbay * available sensors.
540e65e175bSOded Gabbay * @uboot_ver: F/W U-boot version.
541e65e175bSOded Gabbay * @preboot_ver: F/W Preboot version.
542e65e175bSOded Gabbay * @dmmu: DRAM MMU address translation properties.
543e65e175bSOded Gabbay * @pmmu: PCI (host) MMU address translation properties.
544e65e175bSOded Gabbay * @pmmu_huge: PCI (host) MMU address translation properties for memory
545e65e175bSOded Gabbay * allocated with huge pages.
546e65e175bSOded Gabbay * @hints_dram_reserved_va_range: dram hint addresses reserved range.
547e65e175bSOded Gabbay * @hints_host_reserved_va_range: host hint addresses reserved range.
548e65e175bSOded Gabbay * @hints_host_hpage_reserved_va_range: host huge page hint addresses reserved
549e65e175bSOded Gabbay * range.
550e65e175bSOded Gabbay * @sram_base_address: SRAM physical start address.
551e65e175bSOded Gabbay * @sram_end_address: SRAM physical end address.
552e65e175bSOded Gabbay * @sram_user_base_address - SRAM physical start address for user access.
553e65e175bSOded Gabbay * @dram_base_address: DRAM physical start address.
554e65e175bSOded Gabbay * @dram_end_address: DRAM physical end address.
555e65e175bSOded Gabbay * @dram_user_base_address: DRAM physical start address for user access.
556e65e175bSOded Gabbay * @dram_size: DRAM total size.
557e65e175bSOded Gabbay * @dram_pci_bar_size: size of PCI bar towards DRAM.
558e65e175bSOded Gabbay * @max_power_default: max power of the device after reset.
559e65e175bSOded Gabbay * @dc_power_default: power consumed by the device in mode idle.
560e65e175bSOded Gabbay * @dram_size_for_default_page_mapping: DRAM size needed to map to avoid page
561e65e175bSOded Gabbay * fault.
562e65e175bSOded Gabbay * @pcie_dbi_base_address: Base address of the PCIE_DBI block.
563e65e175bSOded Gabbay * @pcie_aux_dbi_reg_addr: Address of the PCIE_AUX DBI register.
564e65e175bSOded Gabbay * @mmu_pgt_addr: base physical address in DRAM of MMU page tables.
565e65e175bSOded Gabbay * @mmu_dram_default_page_addr: DRAM default page physical address.
566e65e175bSOded Gabbay * @tpc_enabled_mask: which TPCs are enabled.
567e65e175bSOded Gabbay * @tpc_binning_mask: which TPCs are binned. 0 means usable and 1 means binned.
568e65e175bSOded Gabbay * @dram_enabled_mask: which DRAMs are enabled.
569e65e175bSOded Gabbay * @dram_binning_mask: which DRAMs are binned. 0 means usable, 1 means binned.
570e65e175bSOded Gabbay * @dram_hints_align_mask: dram va hint addresses alignment mask which is used
571e65e175bSOded Gabbay * for hints validity check.
572e65e175bSOded Gabbay * @cfg_base_address: config space base address.
573e65e175bSOded Gabbay * @mmu_cache_mng_addr: address of the MMU cache.
574e65e175bSOded Gabbay * @mmu_cache_mng_size: size of the MMU cache.
575e65e175bSOded Gabbay * @device_dma_offset_for_host_access: the offset to add to host DMA addresses
576e65e175bSOded Gabbay * to enable the device to access them.
577e65e175bSOded Gabbay * @host_base_address: host physical start address for host DMA from device
578e65e175bSOded Gabbay * @host_end_address: host physical end address for host DMA from device
579e65e175bSOded Gabbay * @max_freq_value: current max clk frequency.
5807fc0d011SOfir Bitton * @engine_core_interrupt_reg_addr: interrupt register address for engine core to use
5817fc0d011SOfir Bitton * in order to raise events toward FW.
582e65e175bSOded Gabbay * @clk_pll_index: clock PLL index that specify which PLL determines the clock
583e65e175bSOded Gabbay * we display to the user
584e65e175bSOded Gabbay * @mmu_pgt_size: MMU page tables total size.
585e65e175bSOded Gabbay * @mmu_pte_size: PTE size in MMU page tables.
586e65e175bSOded Gabbay * @mmu_hop_table_size: MMU hop table size.
587e65e175bSOded Gabbay * @mmu_hop0_tables_total_size: total size of MMU hop0 tables.
588e65e175bSOded Gabbay * @dram_page_size: page size for MMU DRAM allocation.
589e65e175bSOded Gabbay * @cfg_size: configuration space size on SRAM.
590e65e175bSOded Gabbay * @sram_size: total size of SRAM.
591e65e175bSOded Gabbay * @max_asid: maximum number of open contexts (ASIDs).
592e65e175bSOded Gabbay * @num_of_events: number of possible internal H/W IRQs.
593e65e175bSOded Gabbay * @psoc_pci_pll_nr: PCI PLL NR value.
594e65e175bSOded Gabbay * @psoc_pci_pll_nf: PCI PLL NF value.
595e65e175bSOded Gabbay * @psoc_pci_pll_od: PCI PLL OD value.
596e65e175bSOded Gabbay * @psoc_pci_pll_div_factor: PCI PLL DIV FACTOR 1 value.
597e65e175bSOded Gabbay * @psoc_timestamp_frequency: frequency of the psoc timestamp clock.
598e65e175bSOded Gabbay * @high_pll: high PLL frequency used by the device.
599e65e175bSOded Gabbay * @cb_pool_cb_cnt: number of CBs in the CB pool.
600e65e175bSOded Gabbay * @cb_pool_cb_size: size of each CB in the CB pool.
601e65e175bSOded Gabbay * @decoder_enabled_mask: which decoders are enabled.
602958e4797SOfir Bitton * @decoder_binning_mask: which decoders are binned, 0 means usable and 1 means binned.
603958e4797SOfir Bitton * @rotator_enabled_mask: which rotators are enabled.
604e65e175bSOded Gabbay * @edma_enabled_mask: which EDMAs are enabled.
605e65e175bSOded Gabbay * @edma_binning_mask: which EDMAs are binned, 0 means usable and 1 means
606e65e175bSOded Gabbay * binned (at most one binned DMA).
607e65e175bSOded Gabbay * @max_pending_cs: maximum of concurrent pending command submissions
608e65e175bSOded Gabbay * @max_queues: maximum amount of queues in the system
609e65e175bSOded Gabbay * @fw_preboot_cpu_boot_dev_sts0: bitmap representation of preboot cpu
610e65e175bSOded Gabbay * capabilities reported by FW, bit description
611e65e175bSOded Gabbay * can be found in CPU_BOOT_DEV_STS0
612e65e175bSOded Gabbay * @fw_preboot_cpu_boot_dev_sts1: bitmap representation of preboot cpu
613e65e175bSOded Gabbay * capabilities reported by FW, bit description
614e65e175bSOded Gabbay * can be found in CPU_BOOT_DEV_STS1
615e65e175bSOded Gabbay * @fw_bootfit_cpu_boot_dev_sts0: bitmap representation of boot cpu security
616e65e175bSOded Gabbay * status reported by FW, bit description can be
617e65e175bSOded Gabbay * found in CPU_BOOT_DEV_STS0
618e65e175bSOded Gabbay * @fw_bootfit_cpu_boot_dev_sts1: bitmap representation of boot cpu security
619e65e175bSOded Gabbay * status reported by FW, bit description can be
620e65e175bSOded Gabbay * found in CPU_BOOT_DEV_STS1
621e65e175bSOded Gabbay * @fw_app_cpu_boot_dev_sts0: bitmap representation of application security
622e65e175bSOded Gabbay * status reported by FW, bit description can be
623e65e175bSOded Gabbay * found in CPU_BOOT_DEV_STS0
624e65e175bSOded Gabbay * @fw_app_cpu_boot_dev_sts1: bitmap representation of application security
625e65e175bSOded Gabbay * status reported by FW, bit description can be
626e65e175bSOded Gabbay * found in CPU_BOOT_DEV_STS1
627e65e175bSOded Gabbay * @max_dec: maximum number of decoders
628e65e175bSOded Gabbay * @hmmu_hif_enabled_mask: mask of HMMUs/HIFs that are not isolated (enabled)
629e65e175bSOded Gabbay * 1- enabled, 0- isolated.
630e65e175bSOded Gabbay * @faulty_dram_cluster_map: mask of faulty DRAM cluster.
631e65e175bSOded Gabbay * 1- faulty cluster, 0- good cluster.
632e65e175bSOded Gabbay * @xbar_edge_enabled_mask: mask of XBAR_EDGEs that are not isolated (enabled)
633e65e175bSOded Gabbay * 1- enabled, 0- isolated.
634e65e175bSOded Gabbay * @device_mem_alloc_default_page_size: may be different than dram_page_size only for ASICs for
635e65e175bSOded Gabbay * which the property supports_user_set_page_size is true
636e65e175bSOded Gabbay * (i.e. the DRAM supports multiple page sizes), otherwise
637e65e175bSOded Gabbay * it will shall be equal to dram_page_size.
638f7f0085eSKoby Elbaz * @num_engine_cores: number of engine cpu cores.
639f7f0085eSKoby Elbaz * @max_num_of_engines: maximum number of all engines in the ASIC.
640f7d67c1cSKoby Elbaz * @num_of_special_blocks: special_blocks array size.
641f7d67c1cSKoby Elbaz * @glbl_err_cause_num: global err cause number.
64220faaeecSOhad Sharabi * @hbw_flush_reg: register to read to generate HBW flush. value of 0 means HBW flush is
64320faaeecSOhad Sharabi * not supported.
644e65e175bSOded Gabbay * @collective_first_sob: first sync object available for collective use
645e65e175bSOded Gabbay * @collective_first_mon: first monitor available for collective use
646e65e175bSOded Gabbay * @sync_stream_first_sob: first sync object available for sync stream use
647e65e175bSOded Gabbay * @sync_stream_first_mon: first monitor available for sync stream use
648e65e175bSOded Gabbay * @first_available_user_sob: first sob available for the user
649e65e175bSOded Gabbay * @first_available_user_mon: first monitor available for the user
650e65e175bSOded Gabbay * @first_available_user_interrupt: first available interrupt reserved for the user
651e65e175bSOded Gabbay * @first_available_cq: first available CQ for the user.
652e65e175bSOded Gabbay * @user_interrupt_count: number of user interrupts.
653e65e175bSOded Gabbay * @user_dec_intr_count: number of decoder interrupts exposed to user.
6544713ace3SOfir Bitton * @tpc_interrupt_id: interrupt id for TPC to use in order to raise events towards the host.
655802f25b6STal Cohen * @eq_interrupt_id: interrupt id for EQ, uses to synchronize EQ interrupts in hard-reset.
656e65e175bSOded Gabbay * @cache_line_size: device cache line size.
657e65e175bSOded Gabbay * @server_type: Server type that the ASIC is currently installed in.
658e65e175bSOded Gabbay * The value is according to enum hl_server_type in uapi file.
659e65e175bSOded Gabbay * @completion_queues_count: number of completion queues.
660e65e175bSOded Gabbay * @completion_mode: 0 - job based completion, 1 - cs based completion
661e65e175bSOded Gabbay * @mme_master_slave_mode: 0 - Each MME works independently, 1 - MME works
662e65e175bSOded Gabbay * in Master/Slave mode
663e65e175bSOded Gabbay * @fw_security_enabled: true if security measures are enabled in firmware,
664e65e175bSOded Gabbay * false otherwise
665e65e175bSOded Gabbay * @fw_cpu_boot_dev_sts0_valid: status bits are valid and can be fetched from
666e65e175bSOded Gabbay * BOOT_DEV_STS0
667e65e175bSOded Gabbay * @fw_cpu_boot_dev_sts1_valid: status bits are valid and can be fetched from
668e65e175bSOded Gabbay * BOOT_DEV_STS1
669e65e175bSOded Gabbay * @dram_supports_virtual_memory: is there an MMU towards the DRAM
670e65e175bSOded Gabbay * @hard_reset_done_by_fw: true if firmware is handling hard reset flow
671e65e175bSOded Gabbay * @num_functional_hbms: number of functional HBMs in each DCORE.
672e65e175bSOded Gabbay * @hints_range_reservation: device support hint addresses range reservation.
673e65e175bSOded Gabbay * @iatu_done_by_fw: true if iATU configuration is being done by FW.
674e65e175bSOded Gabbay * @dynamic_fw_load: is dynamic FW load is supported.
675e65e175bSOded Gabbay * @gic_interrupts_enable: true if FW is not blocking GIC controller,
676e65e175bSOded Gabbay * false otherwise.
677e65e175bSOded Gabbay * @use_get_power_for_reset_history: To support backward compatibility for Goya
678e65e175bSOded Gabbay * and Gaudi
679e65e175bSOded Gabbay * @supports_compute_reset: is a reset which is not a hard-reset supported by this asic.
680e65e175bSOded Gabbay * @allow_inference_soft_reset: true if the ASIC supports soft reset that is
681e65e175bSOded Gabbay * initiated by user or TDR. This is only true
682e65e175bSOded Gabbay * in inference ASICs, as there is no real-world
683e65e175bSOded Gabbay * use-case of doing soft-reset in training (due
684e65e175bSOded Gabbay * to the fact that training runs on multiple
685e65e175bSOded Gabbay * devices)
686e65e175bSOded Gabbay * @configurable_stop_on_err: is stop-on-error option configurable via debugfs.
687e65e175bSOded Gabbay * @set_max_power_on_device_init: true if need to set max power in F/W on device init.
688e65e175bSOded Gabbay * @supports_user_set_page_size: true if user can set the allocation page size.
689e65e175bSOded Gabbay * @dma_mask: the dma mask to be set for this device
690e65e175bSOded Gabbay * @supports_advanced_cpucp_rc: true if new cpucp opcodes are supported.
691f7f0085eSKoby Elbaz * @supports_engine_modes: true if changing engines/engine_cores modes is supported.
692e65e175bSOded Gabbay */
693e65e175bSOded Gabbay struct asic_fixed_properties {
694e65e175bSOded Gabbay struct hw_queue_properties *hw_queues_props;
695f7d67c1cSKoby Elbaz struct hl_special_block_info *special_blocks;
696f7d67c1cSKoby Elbaz struct hl_skip_blocks_cfg skip_special_blocks_cfg;
697e65e175bSOded Gabbay struct cpucp_info cpucp_info;
698e65e175bSOded Gabbay char uboot_ver[VERSION_MAX_LEN];
699e65e175bSOded Gabbay char preboot_ver[VERSION_MAX_LEN];
700e65e175bSOded Gabbay struct hl_mmu_properties dmmu;
701e65e175bSOded Gabbay struct hl_mmu_properties pmmu;
702e65e175bSOded Gabbay struct hl_mmu_properties pmmu_huge;
703e65e175bSOded Gabbay struct hl_hints_range hints_dram_reserved_va_range;
704e65e175bSOded Gabbay struct hl_hints_range hints_host_reserved_va_range;
705e65e175bSOded Gabbay struct hl_hints_range hints_host_hpage_reserved_va_range;
706e65e175bSOded Gabbay u64 sram_base_address;
707e65e175bSOded Gabbay u64 sram_end_address;
708e65e175bSOded Gabbay u64 sram_user_base_address;
709e65e175bSOded Gabbay u64 dram_base_address;
710e65e175bSOded Gabbay u64 dram_end_address;
711e65e175bSOded Gabbay u64 dram_user_base_address;
712e65e175bSOded Gabbay u64 dram_size;
713e65e175bSOded Gabbay u64 dram_pci_bar_size;
714e65e175bSOded Gabbay u64 max_power_default;
715e65e175bSOded Gabbay u64 dc_power_default;
716e65e175bSOded Gabbay u64 dram_size_for_default_page_mapping;
717e65e175bSOded Gabbay u64 pcie_dbi_base_address;
718e65e175bSOded Gabbay u64 pcie_aux_dbi_reg_addr;
719e65e175bSOded Gabbay u64 mmu_pgt_addr;
720e65e175bSOded Gabbay u64 mmu_dram_default_page_addr;
721e65e175bSOded Gabbay u64 tpc_enabled_mask;
722e65e175bSOded Gabbay u64 tpc_binning_mask;
723e65e175bSOded Gabbay u64 dram_enabled_mask;
724e65e175bSOded Gabbay u64 dram_binning_mask;
725e65e175bSOded Gabbay u64 dram_hints_align_mask;
726e65e175bSOded Gabbay u64 cfg_base_address;
727e65e175bSOded Gabbay u64 mmu_cache_mng_addr;
728e65e175bSOded Gabbay u64 mmu_cache_mng_size;
729e65e175bSOded Gabbay u64 device_dma_offset_for_host_access;
730e65e175bSOded Gabbay u64 host_base_address;
731e65e175bSOded Gabbay u64 host_end_address;
732e65e175bSOded Gabbay u64 max_freq_value;
7337fc0d011SOfir Bitton u64 engine_core_interrupt_reg_addr;
734e65e175bSOded Gabbay u32 clk_pll_index;
735e65e175bSOded Gabbay u32 mmu_pgt_size;
736e65e175bSOded Gabbay u32 mmu_pte_size;
737e65e175bSOded Gabbay u32 mmu_hop_table_size;
738e65e175bSOded Gabbay u32 mmu_hop0_tables_total_size;
739e65e175bSOded Gabbay u32 dram_page_size;
740e65e175bSOded Gabbay u32 cfg_size;
741e65e175bSOded Gabbay u32 sram_size;
742e65e175bSOded Gabbay u32 max_asid;
743e65e175bSOded Gabbay u32 num_of_events;
744e65e175bSOded Gabbay u32 psoc_pci_pll_nr;
745e65e175bSOded Gabbay u32 psoc_pci_pll_nf;
746e65e175bSOded Gabbay u32 psoc_pci_pll_od;
747e65e175bSOded Gabbay u32 psoc_pci_pll_div_factor;
748e65e175bSOded Gabbay u32 psoc_timestamp_frequency;
749e65e175bSOded Gabbay u32 high_pll;
750e65e175bSOded Gabbay u32 cb_pool_cb_cnt;
751e65e175bSOded Gabbay u32 cb_pool_cb_size;
752e65e175bSOded Gabbay u32 decoder_enabled_mask;
753e65e175bSOded Gabbay u32 decoder_binning_mask;
754958e4797SOfir Bitton u32 rotator_enabled_mask;
755e65e175bSOded Gabbay u32 edma_enabled_mask;
756e65e175bSOded Gabbay u32 edma_binning_mask;
757e65e175bSOded Gabbay u32 max_pending_cs;
758e65e175bSOded Gabbay u32 max_queues;
759e65e175bSOded Gabbay u32 fw_preboot_cpu_boot_dev_sts0;
760e65e175bSOded Gabbay u32 fw_preboot_cpu_boot_dev_sts1;
761e65e175bSOded Gabbay u32 fw_bootfit_cpu_boot_dev_sts0;
762e65e175bSOded Gabbay u32 fw_bootfit_cpu_boot_dev_sts1;
763e65e175bSOded Gabbay u32 fw_app_cpu_boot_dev_sts0;
764e65e175bSOded Gabbay u32 fw_app_cpu_boot_dev_sts1;
765e65e175bSOded Gabbay u32 max_dec;
766e65e175bSOded Gabbay u32 hmmu_hif_enabled_mask;
767e65e175bSOded Gabbay u32 faulty_dram_cluster_map;
768e65e175bSOded Gabbay u32 xbar_edge_enabled_mask;
769e65e175bSOded Gabbay u32 device_mem_alloc_default_page_size;
770e65e175bSOded Gabbay u32 num_engine_cores;
771f7f0085eSKoby Elbaz u32 max_num_of_engines;
772f7d67c1cSKoby Elbaz u32 num_of_special_blocks;
773f7d67c1cSKoby Elbaz u32 glbl_err_cause_num;
77420faaeecSOhad Sharabi u32 hbw_flush_reg;
775e65e175bSOded Gabbay u16 collective_first_sob;
776e65e175bSOded Gabbay u16 collective_first_mon;
777e65e175bSOded Gabbay u16 sync_stream_first_sob;
778e65e175bSOded Gabbay u16 sync_stream_first_mon;
779e65e175bSOded Gabbay u16 first_available_user_sob[HL_MAX_DCORES];
780e65e175bSOded Gabbay u16 first_available_user_mon[HL_MAX_DCORES];
781e65e175bSOded Gabbay u16 first_available_user_interrupt;
782e65e175bSOded Gabbay u16 first_available_cq[HL_MAX_DCORES];
783e65e175bSOded Gabbay u16 user_interrupt_count;
784e65e175bSOded Gabbay u16 user_dec_intr_count;
7854713ace3SOfir Bitton u16 tpc_interrupt_id;
786802f25b6STal Cohen u16 eq_interrupt_id;
787e65e175bSOded Gabbay u16 cache_line_size;
788e65e175bSOded Gabbay u16 server_type;
789e65e175bSOded Gabbay u8 completion_queues_count;
790e65e175bSOded Gabbay u8 completion_mode;
791e65e175bSOded Gabbay u8 mme_master_slave_mode;
792e65e175bSOded Gabbay u8 fw_security_enabled;
793e65e175bSOded Gabbay u8 fw_cpu_boot_dev_sts0_valid;
794e65e175bSOded Gabbay u8 fw_cpu_boot_dev_sts1_valid;
795e65e175bSOded Gabbay u8 dram_supports_virtual_memory;
796e65e175bSOded Gabbay u8 hard_reset_done_by_fw;
797e65e175bSOded Gabbay u8 num_functional_hbms;
798e65e175bSOded Gabbay u8 hints_range_reservation;
799e65e175bSOded Gabbay u8 iatu_done_by_fw;
800e65e175bSOded Gabbay u8 dynamic_fw_load;
801e65e175bSOded Gabbay u8 gic_interrupts_enable;
802e65e175bSOded Gabbay u8 use_get_power_for_reset_history;
803e65e175bSOded Gabbay u8 supports_compute_reset;
804e65e175bSOded Gabbay u8 allow_inference_soft_reset;
805e65e175bSOded Gabbay u8 configurable_stop_on_err;
806e65e175bSOded Gabbay u8 set_max_power_on_device_init;
807e65e175bSOded Gabbay u8 supports_user_set_page_size;
808e65e175bSOded Gabbay u8 dma_mask;
809e65e175bSOded Gabbay u8 supports_advanced_cpucp_rc;
810f7f0085eSKoby Elbaz u8 supports_engine_modes;
811e65e175bSOded Gabbay };
812e65e175bSOded Gabbay
813e65e175bSOded Gabbay /**
814e65e175bSOded Gabbay * struct hl_fence - software synchronization primitive
815e65e175bSOded Gabbay * @completion: fence is implemented using completion
816e65e175bSOded Gabbay * @refcount: refcount for this fence
817e65e175bSOded Gabbay * @cs_sequence: sequence of the corresponding command submission
818e65e175bSOded Gabbay * @stream_master_qid_map: streams masters QID bitmap to represent all streams
819e65e175bSOded Gabbay * masters QIDs that multi cs is waiting on
820e65e175bSOded Gabbay * @error: mark this fence with error
821e65e175bSOded Gabbay * @timestamp: timestamp upon completion
822e65e175bSOded Gabbay * @mcs_handling_done: indicates that corresponding command submission has
823e65e175bSOded Gabbay * finished msc handling, this does not mean it was part
824e65e175bSOded Gabbay * of the mcs
825e65e175bSOded Gabbay */
826e65e175bSOded Gabbay struct hl_fence {
827e65e175bSOded Gabbay struct completion completion;
828e65e175bSOded Gabbay struct kref refcount;
829e65e175bSOded Gabbay u64 cs_sequence;
830e65e175bSOded Gabbay u32 stream_master_qid_map;
831e65e175bSOded Gabbay int error;
832e65e175bSOded Gabbay ktime_t timestamp;
833e65e175bSOded Gabbay u8 mcs_handling_done;
834e65e175bSOded Gabbay };
835e65e175bSOded Gabbay
836e65e175bSOded Gabbay /**
837e65e175bSOded Gabbay * struct hl_cs_compl - command submission completion object.
838e65e175bSOded Gabbay * @base_fence: hl fence object.
839e65e175bSOded Gabbay * @lock: spinlock to protect fence.
840e65e175bSOded Gabbay * @hdev: habanalabs device structure.
841e65e175bSOded Gabbay * @hw_sob: the H/W SOB used in this signal/wait CS.
842e65e175bSOded Gabbay * @encaps_sig_hdl: encaps signals handler.
843e65e175bSOded Gabbay * @cs_seq: command submission sequence number.
844e65e175bSOded Gabbay * @type: type of the CS - signal/wait.
845e65e175bSOded Gabbay * @sob_val: the SOB value that is used in this signal/wait CS.
846e65e175bSOded Gabbay * @sob_group: the SOB group that is used in this collective wait CS.
847e65e175bSOded Gabbay * @encaps_signals: indication whether it's a completion object of cs with
848e65e175bSOded Gabbay * encaps signals or not.
849e65e175bSOded Gabbay */
850e65e175bSOded Gabbay struct hl_cs_compl {
851e65e175bSOded Gabbay struct hl_fence base_fence;
852e65e175bSOded Gabbay spinlock_t lock;
853e65e175bSOded Gabbay struct hl_device *hdev;
854e65e175bSOded Gabbay struct hl_hw_sob *hw_sob;
855e65e175bSOded Gabbay struct hl_cs_encaps_sig_handle *encaps_sig_hdl;
856e65e175bSOded Gabbay u64 cs_seq;
857e65e175bSOded Gabbay enum hl_cs_type type;
858e65e175bSOded Gabbay u16 sob_val;
859e65e175bSOded Gabbay u16 sob_group;
860e65e175bSOded Gabbay bool encaps_signals;
861e65e175bSOded Gabbay };
862e65e175bSOded Gabbay
863e65e175bSOded Gabbay /*
864e65e175bSOded Gabbay * Command Buffers
865e65e175bSOded Gabbay */
866e65e175bSOded Gabbay
867e65e175bSOded Gabbay /**
868e65e175bSOded Gabbay * struct hl_ts_buff - describes a timestamp buffer.
869e65e175bSOded Gabbay * @kernel_buff_address: Holds the internal buffer's kernel virtual address.
870e65e175bSOded Gabbay * @user_buff_address: Holds the user buffer's kernel virtual address.
871e65e175bSOded Gabbay * @kernel_buff_size: Holds the internal kernel buffer size.
872e65e175bSOded Gabbay */
873e65e175bSOded Gabbay struct hl_ts_buff {
874e65e175bSOded Gabbay void *kernel_buff_address;
875e65e175bSOded Gabbay void *user_buff_address;
876e65e175bSOded Gabbay u32 kernel_buff_size;
877e65e175bSOded Gabbay };
878e65e175bSOded Gabbay
879e65e175bSOded Gabbay struct hl_mmap_mem_buf;
880e65e175bSOded Gabbay
881e65e175bSOded Gabbay /**
882e65e175bSOded Gabbay * struct hl_mem_mgr - describes unified memory manager for mappable memory chunks.
883e65e175bSOded Gabbay * @dev: back pointer to the owning device
884e65e175bSOded Gabbay * @lock: protects handles
885e65e175bSOded Gabbay * @handles: an idr holding all active handles to the memory buffers in the system.
886e65e175bSOded Gabbay */
887e65e175bSOded Gabbay struct hl_mem_mgr {
888e65e175bSOded Gabbay struct device *dev;
889e65e175bSOded Gabbay spinlock_t lock;
890e65e175bSOded Gabbay struct idr handles;
891e65e175bSOded Gabbay };
892e65e175bSOded Gabbay
893e65e175bSOded Gabbay /**
894e65e175bSOded Gabbay * struct hl_mmap_mem_buf_behavior - describes unified memory manager buffer behavior
895e65e175bSOded Gabbay * @topic: string identifier used for logging
896e65e175bSOded Gabbay * @mem_id: memory type identifier, embedded in the handle and used to identify
897e65e175bSOded Gabbay * the memory type by handle.
898e65e175bSOded Gabbay * @alloc: callback executed on buffer allocation, shall allocate the memory,
899e65e175bSOded Gabbay * set it under buffer private, and set mappable size.
900e65e175bSOded Gabbay * @mmap: callback executed on mmap, must map the buffer to vma
901e65e175bSOded Gabbay * @release: callback executed on release, must free the resources used by the buffer
902e65e175bSOded Gabbay */
903e65e175bSOded Gabbay struct hl_mmap_mem_buf_behavior {
904e65e175bSOded Gabbay const char *topic;
905e65e175bSOded Gabbay u64 mem_id;
906e65e175bSOded Gabbay
907e65e175bSOded Gabbay int (*alloc)(struct hl_mmap_mem_buf *buf, gfp_t gfp, void *args);
908e65e175bSOded Gabbay int (*mmap)(struct hl_mmap_mem_buf *buf, struct vm_area_struct *vma, void *args);
909e65e175bSOded Gabbay void (*release)(struct hl_mmap_mem_buf *buf);
910e65e175bSOded Gabbay };
911e65e175bSOded Gabbay
912e65e175bSOded Gabbay /**
913e65e175bSOded Gabbay * struct hl_mmap_mem_buf - describes a single unified memory buffer
914e65e175bSOded Gabbay * @behavior: buffer behavior
915e65e175bSOded Gabbay * @mmg: back pointer to the unified memory manager
916e65e175bSOded Gabbay * @refcount: reference counter for buffer users
917e65e175bSOded Gabbay * @private: pointer to buffer behavior private data
918e65e175bSOded Gabbay * @mmap: atomic boolean indicating whether or not the buffer is mapped right now
919e65e175bSOded Gabbay * @real_mapped_size: the actual size of buffer mapped, after part of it may be released,
920e65e175bSOded Gabbay * may change at runtime.
921e65e175bSOded Gabbay * @mappable_size: the original mappable size of the buffer, does not change after
922e65e175bSOded Gabbay * the allocation.
923e65e175bSOded Gabbay * @handle: the buffer id in mmg handles store
924e65e175bSOded Gabbay */
925e65e175bSOded Gabbay struct hl_mmap_mem_buf {
926e65e175bSOded Gabbay struct hl_mmap_mem_buf_behavior *behavior;
927e65e175bSOded Gabbay struct hl_mem_mgr *mmg;
928e65e175bSOded Gabbay struct kref refcount;
929e65e175bSOded Gabbay void *private;
930e65e175bSOded Gabbay atomic_t mmap;
931e65e175bSOded Gabbay u64 real_mapped_size;
932e65e175bSOded Gabbay u64 mappable_size;
933e65e175bSOded Gabbay u64 handle;
934e65e175bSOded Gabbay };
935e65e175bSOded Gabbay
936e65e175bSOded Gabbay /**
937e65e175bSOded Gabbay * struct hl_cb - describes a Command Buffer.
938e65e175bSOded Gabbay * @hdev: pointer to device this CB belongs to.
939e65e175bSOded Gabbay * @ctx: pointer to the CB owner's context.
940e65e175bSOded Gabbay * @buf: back pointer to the parent mappable memory buffer
941e65e175bSOded Gabbay * @debugfs_list: node in debugfs list of command buffers.
942e65e175bSOded Gabbay * @pool_list: node in pool list of command buffers.
943e65e175bSOded Gabbay * @kernel_address: Holds the CB's kernel virtual address.
944e65e175bSOded Gabbay * @virtual_addr: Holds the CB's virtual address.
945e65e175bSOded Gabbay * @bus_address: Holds the CB's DMA address.
946e65e175bSOded Gabbay * @size: holds the CB's size.
947e65e175bSOded Gabbay * @roundup_size: holds the cb size after roundup to page size.
948e65e175bSOded Gabbay * @cs_cnt: holds number of CS that this CB participates in.
949e65e175bSOded Gabbay * @is_handle_destroyed: atomic boolean indicating whether or not the CB handle was destroyed.
950e65e175bSOded Gabbay * @is_pool: true if CB was acquired from the pool, false otherwise.
951e65e175bSOded Gabbay * @is_internal: internally allocated
952e65e175bSOded Gabbay * @is_mmu_mapped: true if the CB is mapped to the device's MMU.
953e65e175bSOded Gabbay */
954e65e175bSOded Gabbay struct hl_cb {
955e65e175bSOded Gabbay struct hl_device *hdev;
956e65e175bSOded Gabbay struct hl_ctx *ctx;
957e65e175bSOded Gabbay struct hl_mmap_mem_buf *buf;
958e65e175bSOded Gabbay struct list_head debugfs_list;
959e65e175bSOded Gabbay struct list_head pool_list;
960e65e175bSOded Gabbay void *kernel_address;
961e65e175bSOded Gabbay u64 virtual_addr;
962e65e175bSOded Gabbay dma_addr_t bus_address;
963e65e175bSOded Gabbay u32 size;
964e65e175bSOded Gabbay u32 roundup_size;
965e65e175bSOded Gabbay atomic_t cs_cnt;
966e65e175bSOded Gabbay atomic_t is_handle_destroyed;
967e65e175bSOded Gabbay u8 is_pool;
968e65e175bSOded Gabbay u8 is_internal;
969e65e175bSOded Gabbay u8 is_mmu_mapped;
970e65e175bSOded Gabbay };
971e65e175bSOded Gabbay
972e65e175bSOded Gabbay
973e65e175bSOded Gabbay /*
974e65e175bSOded Gabbay * QUEUES
975e65e175bSOded Gabbay */
976e65e175bSOded Gabbay
977e65e175bSOded Gabbay struct hl_cs_job;
978e65e175bSOded Gabbay
979e65e175bSOded Gabbay /* Queue length of external and HW queues */
980e65e175bSOded Gabbay #define HL_QUEUE_LENGTH 4096
981e65e175bSOded Gabbay #define HL_QUEUE_SIZE_IN_BYTES (HL_QUEUE_LENGTH * HL_BD_SIZE)
982e65e175bSOded Gabbay
983e65e175bSOded Gabbay #if (HL_MAX_JOBS_PER_CS > HL_QUEUE_LENGTH)
984e65e175bSOded Gabbay #error "HL_QUEUE_LENGTH must be greater than HL_MAX_JOBS_PER_CS"
985e65e175bSOded Gabbay #endif
986e65e175bSOded Gabbay
987e65e175bSOded Gabbay /* HL_CQ_LENGTH is in units of struct hl_cq_entry */
988e65e175bSOded Gabbay #define HL_CQ_LENGTH HL_QUEUE_LENGTH
989e65e175bSOded Gabbay #define HL_CQ_SIZE_IN_BYTES (HL_CQ_LENGTH * HL_CQ_ENTRY_SIZE)
990e65e175bSOded Gabbay
991e65e175bSOded Gabbay /* Must be power of 2 */
992e65e175bSOded Gabbay #define HL_EQ_LENGTH 64
993e65e175bSOded Gabbay #define HL_EQ_SIZE_IN_BYTES (HL_EQ_LENGTH * HL_EQ_ENTRY_SIZE)
994e65e175bSOded Gabbay
995e65e175bSOded Gabbay /* Host <-> CPU-CP shared memory size */
996e65e175bSOded Gabbay #define HL_CPU_ACCESSIBLE_MEM_SIZE SZ_2M
997e65e175bSOded Gabbay
998e65e175bSOded Gabbay /**
999e65e175bSOded Gabbay * struct hl_sync_stream_properties -
1000e65e175bSOded Gabbay * describes a H/W queue sync stream properties
1001e65e175bSOded Gabbay * @hw_sob: array of the used H/W SOBs by this H/W queue.
1002e65e175bSOded Gabbay * @next_sob_val: the next value to use for the currently used SOB.
1003e65e175bSOded Gabbay * @base_sob_id: the base SOB id of the SOBs used by this queue.
1004e65e175bSOded Gabbay * @base_mon_id: the base MON id of the MONs used by this queue.
1005e65e175bSOded Gabbay * @collective_mstr_mon_id: the MON ids of the MONs used by this master queue
1006e65e175bSOded Gabbay * in order to sync with all slave queues.
1007e65e175bSOded Gabbay * @collective_slave_mon_id: the MON id used by this slave queue in order to
1008e65e175bSOded Gabbay * sync with its master queue.
1009e65e175bSOded Gabbay * @collective_sob_id: current SOB id used by this collective slave queue
1010e65e175bSOded Gabbay * to signal its collective master queue upon completion.
1011e65e175bSOded Gabbay * @curr_sob_offset: the id offset to the currently used SOB from the
1012e65e175bSOded Gabbay * HL_RSVD_SOBS that are being used by this queue.
1013e65e175bSOded Gabbay */
1014e65e175bSOded Gabbay struct hl_sync_stream_properties {
1015e65e175bSOded Gabbay struct hl_hw_sob hw_sob[HL_RSVD_SOBS];
1016e65e175bSOded Gabbay u16 next_sob_val;
1017e65e175bSOded Gabbay u16 base_sob_id;
1018e65e175bSOded Gabbay u16 base_mon_id;
1019e65e175bSOded Gabbay u16 collective_mstr_mon_id[HL_COLLECTIVE_RSVD_MSTR_MONS];
1020e65e175bSOded Gabbay u16 collective_slave_mon_id;
1021e65e175bSOded Gabbay u16 collective_sob_id;
1022e65e175bSOded Gabbay u8 curr_sob_offset;
1023e65e175bSOded Gabbay };
1024e65e175bSOded Gabbay
1025e65e175bSOded Gabbay /**
1026e65e175bSOded Gabbay * struct hl_encaps_signals_mgr - describes sync stream encapsulated signals
1027e65e175bSOded Gabbay * handlers manager
1028e65e175bSOded Gabbay * @lock: protects handles.
1029e65e175bSOded Gabbay * @handles: an idr to hold all encapsulated signals handles.
1030e65e175bSOded Gabbay */
1031e65e175bSOded Gabbay struct hl_encaps_signals_mgr {
1032e65e175bSOded Gabbay spinlock_t lock;
1033e65e175bSOded Gabbay struct idr handles;
1034e65e175bSOded Gabbay };
1035e65e175bSOded Gabbay
1036e65e175bSOded Gabbay /**
1037e65e175bSOded Gabbay * struct hl_hw_queue - describes a H/W transport queue.
1038e65e175bSOded Gabbay * @shadow_queue: pointer to a shadow queue that holds pointers to jobs.
1039e65e175bSOded Gabbay * @sync_stream_prop: sync stream queue properties
1040e65e175bSOded Gabbay * @queue_type: type of queue.
1041e65e175bSOded Gabbay * @collective_mode: collective mode of current queue
1042e65e175bSOded Gabbay * @kernel_address: holds the queue's kernel virtual address.
1043e65e175bSOded Gabbay * @bus_address: holds the queue's DMA address.
1044e65e175bSOded Gabbay * @pi: holds the queue's pi value.
1045e65e175bSOded Gabbay * @ci: holds the queue's ci value, AS CALCULATED BY THE DRIVER (not real ci).
1046e65e175bSOded Gabbay * @hw_queue_id: the id of the H/W queue.
1047e65e175bSOded Gabbay * @cq_id: the id for the corresponding CQ for this H/W queue.
1048e65e175bSOded Gabbay * @msi_vec: the IRQ number of the H/W queue.
1049e65e175bSOded Gabbay * @int_queue_len: length of internal queue (number of entries).
1050e65e175bSOded Gabbay * @valid: is the queue valid (we have array of 32 queues, not all of them
1051e65e175bSOded Gabbay * exist).
1052e65e175bSOded Gabbay * @supports_sync_stream: True if queue supports sync stream
1053e65e175bSOded Gabbay */
1054e65e175bSOded Gabbay struct hl_hw_queue {
1055e65e175bSOded Gabbay struct hl_cs_job **shadow_queue;
1056e65e175bSOded Gabbay struct hl_sync_stream_properties sync_stream_prop;
1057e65e175bSOded Gabbay enum hl_queue_type queue_type;
1058e65e175bSOded Gabbay enum hl_collective_mode collective_mode;
1059e65e175bSOded Gabbay void *kernel_address;
1060e65e175bSOded Gabbay dma_addr_t bus_address;
1061e65e175bSOded Gabbay u32 pi;
1062e65e175bSOded Gabbay atomic_t ci;
1063e65e175bSOded Gabbay u32 hw_queue_id;
1064e65e175bSOded Gabbay u32 cq_id;
1065e65e175bSOded Gabbay u32 msi_vec;
1066e65e175bSOded Gabbay u16 int_queue_len;
1067e65e175bSOded Gabbay u8 valid;
1068e65e175bSOded Gabbay u8 supports_sync_stream;
1069e65e175bSOded Gabbay };
1070e65e175bSOded Gabbay
1071e65e175bSOded Gabbay /**
1072e65e175bSOded Gabbay * struct hl_cq - describes a completion queue
1073e65e175bSOded Gabbay * @hdev: pointer to the device structure
1074e65e175bSOded Gabbay * @kernel_address: holds the queue's kernel virtual address
1075e65e175bSOded Gabbay * @bus_address: holds the queue's DMA address
1076e65e175bSOded Gabbay * @cq_idx: completion queue index in array
1077e65e175bSOded Gabbay * @hw_queue_id: the id of the matching H/W queue
1078e65e175bSOded Gabbay * @ci: ci inside the queue
1079e65e175bSOded Gabbay * @pi: pi inside the queue
1080e65e175bSOded Gabbay * @free_slots_cnt: counter of free slots in queue
1081e65e175bSOded Gabbay */
1082e65e175bSOded Gabbay struct hl_cq {
1083e65e175bSOded Gabbay struct hl_device *hdev;
1084e65e175bSOded Gabbay void *kernel_address;
1085e65e175bSOded Gabbay dma_addr_t bus_address;
1086e65e175bSOded Gabbay u32 cq_idx;
1087e65e175bSOded Gabbay u32 hw_queue_id;
1088e65e175bSOded Gabbay u32 ci;
1089e65e175bSOded Gabbay u32 pi;
1090e65e175bSOded Gabbay atomic_t free_slots_cnt;
1091e65e175bSOded Gabbay };
1092e65e175bSOded Gabbay
10939a7d530aSOfir Bitton enum hl_user_interrupt_type {
10949a7d530aSOfir Bitton HL_USR_INTERRUPT_CQ = 0,
10959a7d530aSOfir Bitton HL_USR_INTERRUPT_DECODER,
1096e1ef053eSOfir Bitton HL_USR_INTERRUPT_TPC,
1097e1ef053eSOfir Bitton HL_USR_INTERRUPT_UNEXPECTED
10989a7d530aSOfir Bitton };
10999a7d530aSOfir Bitton
1100e65e175bSOded Gabbay /**
1101e65e175bSOded Gabbay * struct hl_user_interrupt - holds user interrupt information
1102e65e175bSOded Gabbay * @hdev: pointer to the device structure
11039a7d530aSOfir Bitton * @type: user interrupt type
1104e65e175bSOded Gabbay * @wait_list_head: head to the list of user threads pending on this interrupt
1105e65e175bSOded Gabbay * @wait_list_lock: protects wait_list_head
1106bcfcd084SOfir Bitton * @timestamp: last timestamp taken upon interrupt
1107e65e175bSOded Gabbay * @interrupt_id: msix interrupt id
1108e65e175bSOded Gabbay */
1109e65e175bSOded Gabbay struct hl_user_interrupt {
1110e65e175bSOded Gabbay struct hl_device *hdev;
11119a7d530aSOfir Bitton enum hl_user_interrupt_type type;
1112e65e175bSOded Gabbay struct list_head wait_list_head;
1113e65e175bSOded Gabbay spinlock_t wait_list_lock;
1114bcfcd084SOfir Bitton ktime_t timestamp;
1115e65e175bSOded Gabbay u32 interrupt_id;
1116e65e175bSOded Gabbay };
1117e65e175bSOded Gabbay
1118e65e175bSOded Gabbay /**
1119e65e175bSOded Gabbay * struct timestamp_reg_free_node - holds the timestamp registration free objects node
1120e65e175bSOded Gabbay * @free_objects_node: node in the list free_obj_jobs
1121e65e175bSOded Gabbay * @cq_cb: pointer to cq command buffer to be freed
1122e65e175bSOded Gabbay * @buf: pointer to timestamp buffer to be freed
1123e65e175bSOded Gabbay */
1124e65e175bSOded Gabbay struct timestamp_reg_free_node {
1125e65e175bSOded Gabbay struct list_head free_objects_node;
1126e65e175bSOded Gabbay struct hl_cb *cq_cb;
1127e65e175bSOded Gabbay struct hl_mmap_mem_buf *buf;
1128e65e175bSOded Gabbay };
1129e65e175bSOded Gabbay
1130e65e175bSOded Gabbay /* struct timestamp_reg_work_obj - holds the timestamp registration free objects job
1131e65e175bSOded Gabbay * the job will be to pass over the free_obj_jobs list and put refcount to objects
1132e65e175bSOded Gabbay * in each node of the list
1133e65e175bSOded Gabbay * @free_obj: workqueue object to free timestamp registration node objects
1134e65e175bSOded Gabbay * @hdev: pointer to the device structure
1135e65e175bSOded Gabbay * @free_obj_head: list of free jobs nodes (node type timestamp_reg_free_node)
1136e65e175bSOded Gabbay */
1137e65e175bSOded Gabbay struct timestamp_reg_work_obj {
1138e65e175bSOded Gabbay struct work_struct free_obj;
1139e65e175bSOded Gabbay struct hl_device *hdev;
1140e65e175bSOded Gabbay struct list_head *free_obj_head;
1141e65e175bSOded Gabbay };
1142e65e175bSOded Gabbay
1143e65e175bSOded Gabbay /* struct timestamp_reg_info - holds the timestamp registration related data.
1144e65e175bSOded Gabbay * @buf: pointer to the timestamp buffer which include both user/kernel buffers.
1145e65e175bSOded Gabbay * relevant only when doing timestamps records registration.
1146e65e175bSOded Gabbay * @cq_cb: pointer to CQ counter CB.
1147e65e175bSOded Gabbay * @timestamp_kernel_addr: timestamp handle address, where to set timestamp
1148e65e175bSOded Gabbay * relevant only when doing timestamps records
1149e65e175bSOded Gabbay * registration.
1150e65e175bSOded Gabbay * @in_use: indicates if the node already in use. relevant only when doing
1151e65e175bSOded Gabbay * timestamps records registration, since in this case the driver
1152e65e175bSOded Gabbay * will have it's own buffer which serve as a records pool instead of
1153e65e175bSOded Gabbay * allocating records dynamically.
1154e65e175bSOded Gabbay */
1155e65e175bSOded Gabbay struct timestamp_reg_info {
1156e65e175bSOded Gabbay struct hl_mmap_mem_buf *buf;
1157e65e175bSOded Gabbay struct hl_cb *cq_cb;
1158e65e175bSOded Gabbay u64 *timestamp_kernel_addr;
1159e65e175bSOded Gabbay u8 in_use;
1160e65e175bSOded Gabbay };
1161e65e175bSOded Gabbay
1162e65e175bSOded Gabbay /**
1163e65e175bSOded Gabbay * struct hl_user_pending_interrupt - holds a context to a user thread
1164e65e175bSOded Gabbay * pending on an interrupt
1165e65e175bSOded Gabbay * @ts_reg_info: holds the timestamps registration nodes info
1166e65e175bSOded Gabbay * @wait_list_node: node in the list of user threads pending on an interrupt
1167e65e175bSOded Gabbay * @fence: hl fence object for interrupt completion
1168e65e175bSOded Gabbay * @cq_target_value: CQ target value
1169e65e175bSOded Gabbay * @cq_kernel_addr: CQ kernel address, to be used in the cq interrupt
1170e65e175bSOded Gabbay * handler for target value comparison
1171e65e175bSOded Gabbay */
1172e65e175bSOded Gabbay struct hl_user_pending_interrupt {
1173e65e175bSOded Gabbay struct timestamp_reg_info ts_reg_info;
1174e65e175bSOded Gabbay struct list_head wait_list_node;
1175e65e175bSOded Gabbay struct hl_fence fence;
1176e65e175bSOded Gabbay u64 cq_target_value;
1177e65e175bSOded Gabbay u64 *cq_kernel_addr;
1178e65e175bSOded Gabbay };
1179e65e175bSOded Gabbay
1180e65e175bSOded Gabbay /**
1181e65e175bSOded Gabbay * struct hl_eq - describes the event queue (single one per device)
1182e65e175bSOded Gabbay * @hdev: pointer to the device structure
1183e65e175bSOded Gabbay * @kernel_address: holds the queue's kernel virtual address
1184e65e175bSOded Gabbay * @bus_address: holds the queue's DMA address
1185e65e175bSOded Gabbay * @ci: ci inside the queue
1186e65e175bSOded Gabbay * @prev_eqe_index: the index of the previous event queue entry. The index of
1187e65e175bSOded Gabbay * the current entry's index must be +1 of the previous one.
1188e65e175bSOded Gabbay * @check_eqe_index: do we need to check the index of the current entry vs. the
1189e65e175bSOded Gabbay * previous one. This is for backward compatibility with older
1190e65e175bSOded Gabbay * firmwares
1191e65e175bSOded Gabbay */
1192e65e175bSOded Gabbay struct hl_eq {
1193e65e175bSOded Gabbay struct hl_device *hdev;
1194e65e175bSOded Gabbay void *kernel_address;
1195e65e175bSOded Gabbay dma_addr_t bus_address;
1196e65e175bSOded Gabbay u32 ci;
1197e65e175bSOded Gabbay u32 prev_eqe_index;
1198e65e175bSOded Gabbay bool check_eqe_index;
1199e65e175bSOded Gabbay };
1200e65e175bSOded Gabbay
1201e65e175bSOded Gabbay /**
1202e65e175bSOded Gabbay * struct hl_dec - describes a decoder sw instance.
1203e65e175bSOded Gabbay * @hdev: pointer to the device structure.
12049cf56f0dSTomer Tayar * @abnrm_intr_work: workqueue work item to run when decoder generates an error interrupt.
1205e65e175bSOded Gabbay * @core_id: ID of the decoder.
1206e65e175bSOded Gabbay * @base_addr: base address of the decoder.
1207e65e175bSOded Gabbay */
1208e65e175bSOded Gabbay struct hl_dec {
1209e65e175bSOded Gabbay struct hl_device *hdev;
12109cf56f0dSTomer Tayar struct work_struct abnrm_intr_work;
1211e65e175bSOded Gabbay u32 core_id;
1212e65e175bSOded Gabbay u32 base_addr;
1213e65e175bSOded Gabbay };
1214e65e175bSOded Gabbay
1215e65e175bSOded Gabbay /**
1216e65e175bSOded Gabbay * enum hl_asic_type - supported ASIC types.
1217e65e175bSOded Gabbay * @ASIC_INVALID: Invalid ASIC type.
1218e65e175bSOded Gabbay * @ASIC_GOYA: Goya device (HL-1000).
1219e65e175bSOded Gabbay * @ASIC_GAUDI: Gaudi device (HL-2000).
1220e65e175bSOded Gabbay * @ASIC_GAUDI_SEC: Gaudi secured device (HL-2000).
1221e65e175bSOded Gabbay * @ASIC_GAUDI2: Gaudi2 device.
1222e65e175bSOded Gabbay * @ASIC_GAUDI2B: Gaudi2B device.
12239aa2cba7SOded Gabbay * @ASIC_GAUDI2C: Gaudi2C device.
1224e65e175bSOded Gabbay */
1225e65e175bSOded Gabbay enum hl_asic_type {
1226e65e175bSOded Gabbay ASIC_INVALID,
1227e65e175bSOded Gabbay ASIC_GOYA,
1228e65e175bSOded Gabbay ASIC_GAUDI,
1229e65e175bSOded Gabbay ASIC_GAUDI_SEC,
1230e65e175bSOded Gabbay ASIC_GAUDI2,
1231e65e175bSOded Gabbay ASIC_GAUDI2B,
12329aa2cba7SOded Gabbay ASIC_GAUDI2C,
1233e65e175bSOded Gabbay };
1234e65e175bSOded Gabbay
1235e65e175bSOded Gabbay struct hl_cs_parser;
1236e65e175bSOded Gabbay
1237e65e175bSOded Gabbay /**
1238e65e175bSOded Gabbay * enum hl_pm_mng_profile - power management profile.
1239e65e175bSOded Gabbay * @PM_AUTO: internal clock is set by the Linux driver.
1240e65e175bSOded Gabbay * @PM_MANUAL: internal clock is set by the user.
1241e65e175bSOded Gabbay * @PM_LAST: last power management type.
1242e65e175bSOded Gabbay */
1243e65e175bSOded Gabbay enum hl_pm_mng_profile {
1244e65e175bSOded Gabbay PM_AUTO = 1,
1245e65e175bSOded Gabbay PM_MANUAL,
1246e65e175bSOded Gabbay PM_LAST
1247e65e175bSOded Gabbay };
1248e65e175bSOded Gabbay
1249e65e175bSOded Gabbay /**
1250e65e175bSOded Gabbay * enum hl_pll_frequency - PLL frequency.
1251e65e175bSOded Gabbay * @PLL_HIGH: high frequency.
1252e65e175bSOded Gabbay * @PLL_LOW: low frequency.
1253e65e175bSOded Gabbay * @PLL_LAST: last frequency values that were configured by the user.
1254e65e175bSOded Gabbay */
1255e65e175bSOded Gabbay enum hl_pll_frequency {
1256e65e175bSOded Gabbay PLL_HIGH = 1,
1257e65e175bSOded Gabbay PLL_LOW,
1258e65e175bSOded Gabbay PLL_LAST
1259e65e175bSOded Gabbay };
1260e65e175bSOded Gabbay
1261e65e175bSOded Gabbay #define PLL_REF_CLK 50
1262e65e175bSOded Gabbay
1263e65e175bSOded Gabbay enum div_select_defs {
1264e65e175bSOded Gabbay DIV_SEL_REF_CLK = 0,
1265e65e175bSOded Gabbay DIV_SEL_PLL_CLK = 1,
1266e65e175bSOded Gabbay DIV_SEL_DIVIDED_REF = 2,
1267e65e175bSOded Gabbay DIV_SEL_DIVIDED_PLL = 3,
1268e65e175bSOded Gabbay };
1269e65e175bSOded Gabbay
1270e65e175bSOded Gabbay enum debugfs_access_type {
1271e65e175bSOded Gabbay DEBUGFS_READ8,
1272e65e175bSOded Gabbay DEBUGFS_WRITE8,
1273e65e175bSOded Gabbay DEBUGFS_READ32,
1274e65e175bSOded Gabbay DEBUGFS_WRITE32,
1275e65e175bSOded Gabbay DEBUGFS_READ64,
1276e65e175bSOded Gabbay DEBUGFS_WRITE64,
1277e65e175bSOded Gabbay };
1278e65e175bSOded Gabbay
1279e65e175bSOded Gabbay enum pci_region {
1280e65e175bSOded Gabbay PCI_REGION_CFG,
1281e65e175bSOded Gabbay PCI_REGION_SRAM,
1282e65e175bSOded Gabbay PCI_REGION_DRAM,
1283e65e175bSOded Gabbay PCI_REGION_SP_SRAM,
1284e65e175bSOded Gabbay PCI_REGION_NUMBER,
1285e65e175bSOded Gabbay };
1286e65e175bSOded Gabbay
1287e65e175bSOded Gabbay /**
1288e65e175bSOded Gabbay * struct pci_mem_region - describe memory region in a PCI bar
1289e65e175bSOded Gabbay * @region_base: region base address
1290e65e175bSOded Gabbay * @region_size: region size
1291e65e175bSOded Gabbay * @bar_size: size of the BAR
1292e65e175bSOded Gabbay * @offset_in_bar: region offset into the bar
1293e65e175bSOded Gabbay * @bar_id: bar ID of the region
1294e65e175bSOded Gabbay * @used: if used 1, otherwise 0
1295e65e175bSOded Gabbay */
1296e65e175bSOded Gabbay struct pci_mem_region {
1297e65e175bSOded Gabbay u64 region_base;
1298e65e175bSOded Gabbay u64 region_size;
1299e65e175bSOded Gabbay u64 bar_size;
1300e65e175bSOded Gabbay u64 offset_in_bar;
1301e65e175bSOded Gabbay u8 bar_id;
1302e65e175bSOded Gabbay u8 used;
1303e65e175bSOded Gabbay };
1304e65e175bSOded Gabbay
1305e65e175bSOded Gabbay /**
1306e65e175bSOded Gabbay * struct static_fw_load_mgr - static FW load manager
1307e65e175bSOded Gabbay * @preboot_version_max_off: max offset to preboot version
1308e65e175bSOded Gabbay * @boot_fit_version_max_off: max offset to boot fit version
1309e65e175bSOded Gabbay * @kmd_msg_to_cpu_reg: register address for KDM->CPU messages
1310e65e175bSOded Gabbay * @cpu_cmd_status_to_host_reg: register address for CPU command status response
1311e65e175bSOded Gabbay * @cpu_boot_status_reg: boot status register
1312e65e175bSOded Gabbay * @cpu_boot_dev_status0_reg: boot device status register 0
1313e65e175bSOded Gabbay * @cpu_boot_dev_status1_reg: boot device status register 1
1314e65e175bSOded Gabbay * @boot_err0_reg: boot error register 0
1315e65e175bSOded Gabbay * @boot_err1_reg: boot error register 1
1316e65e175bSOded Gabbay * @preboot_version_offset_reg: SRAM offset to preboot version register
1317e65e175bSOded Gabbay * @boot_fit_version_offset_reg: SRAM offset to boot fit version register
1318e65e175bSOded Gabbay * @sram_offset_mask: mask for getting offset into the SRAM
1319e65e175bSOded Gabbay * @cpu_reset_wait_msec: used when setting WFE via kmd_msg_to_cpu_reg
1320e65e175bSOded Gabbay */
1321e65e175bSOded Gabbay struct static_fw_load_mgr {
1322e65e175bSOded Gabbay u64 preboot_version_max_off;
1323e65e175bSOded Gabbay u64 boot_fit_version_max_off;
1324e65e175bSOded Gabbay u32 kmd_msg_to_cpu_reg;
1325e65e175bSOded Gabbay u32 cpu_cmd_status_to_host_reg;
1326e65e175bSOded Gabbay u32 cpu_boot_status_reg;
1327e65e175bSOded Gabbay u32 cpu_boot_dev_status0_reg;
1328e65e175bSOded Gabbay u32 cpu_boot_dev_status1_reg;
1329e65e175bSOded Gabbay u32 boot_err0_reg;
1330e65e175bSOded Gabbay u32 boot_err1_reg;
1331e65e175bSOded Gabbay u32 preboot_version_offset_reg;
1332e65e175bSOded Gabbay u32 boot_fit_version_offset_reg;
1333e65e175bSOded Gabbay u32 sram_offset_mask;
1334e65e175bSOded Gabbay u32 cpu_reset_wait_msec;
1335e65e175bSOded Gabbay };
1336e65e175bSOded Gabbay
1337e65e175bSOded Gabbay /**
1338e65e175bSOded Gabbay * struct fw_response - FW response to LKD command
1339e65e175bSOded Gabbay * @ram_offset: descriptor offset into the RAM
1340e65e175bSOded Gabbay * @ram_type: RAM type containing the descriptor (SRAM/DRAM)
1341e65e175bSOded Gabbay * @status: command status
1342e65e175bSOded Gabbay */
1343e65e175bSOded Gabbay struct fw_response {
1344e65e175bSOded Gabbay u32 ram_offset;
1345e65e175bSOded Gabbay u8 ram_type;
1346e65e175bSOded Gabbay u8 status;
1347e65e175bSOded Gabbay };
1348e65e175bSOded Gabbay
1349e65e175bSOded Gabbay /**
1350e65e175bSOded Gabbay * struct dynamic_fw_load_mgr - dynamic FW load manager
1351e65e175bSOded Gabbay * @response: FW to LKD response
1352e65e175bSOded Gabbay * @comm_desc: the communication descriptor with FW
1353e65e175bSOded Gabbay * @image_region: region to copy the FW image to
1354e65e175bSOded Gabbay * @fw_image_size: size of FW image to load
1355e65e175bSOded Gabbay * @wait_for_bl_timeout: timeout for waiting for boot loader to respond
1356e65e175bSOded Gabbay * @fw_desc_valid: true if FW descriptor has been validated and hence the data can be used
1357e65e175bSOded Gabbay */
1358e65e175bSOded Gabbay struct dynamic_fw_load_mgr {
1359e65e175bSOded Gabbay struct fw_response response;
1360e65e175bSOded Gabbay struct lkd_fw_comms_desc comm_desc;
1361e65e175bSOded Gabbay struct pci_mem_region *image_region;
1362e65e175bSOded Gabbay size_t fw_image_size;
1363e65e175bSOded Gabbay u32 wait_for_bl_timeout;
1364e65e175bSOded Gabbay bool fw_desc_valid;
1365e65e175bSOded Gabbay };
1366e65e175bSOded Gabbay
1367e65e175bSOded Gabbay /**
1368e65e175bSOded Gabbay * struct pre_fw_load_props - needed properties for pre-FW load
1369e65e175bSOded Gabbay * @cpu_boot_status_reg: cpu_boot_status register address
1370e65e175bSOded Gabbay * @sts_boot_dev_sts0_reg: sts_boot_dev_sts0 register address
1371e65e175bSOded Gabbay * @sts_boot_dev_sts1_reg: sts_boot_dev_sts1 register address
1372e65e175bSOded Gabbay * @boot_err0_reg: boot_err0 register address
1373e65e175bSOded Gabbay * @boot_err1_reg: boot_err1 register address
1374e65e175bSOded Gabbay * @wait_for_preboot_timeout: timeout to poll for preboot ready
1375e65e175bSOded Gabbay */
1376e65e175bSOded Gabbay struct pre_fw_load_props {
1377e65e175bSOded Gabbay u32 cpu_boot_status_reg;
1378e65e175bSOded Gabbay u32 sts_boot_dev_sts0_reg;
1379e65e175bSOded Gabbay u32 sts_boot_dev_sts1_reg;
1380e65e175bSOded Gabbay u32 boot_err0_reg;
1381e65e175bSOded Gabbay u32 boot_err1_reg;
1382e65e175bSOded Gabbay u32 wait_for_preboot_timeout;
1383e65e175bSOded Gabbay };
1384e65e175bSOded Gabbay
1385e65e175bSOded Gabbay /**
1386e65e175bSOded Gabbay * struct fw_image_props - properties of FW image
1387e65e175bSOded Gabbay * @image_name: name of the image
1388e65e175bSOded Gabbay * @src_off: offset in src FW to copy from
1389e65e175bSOded Gabbay * @copy_size: amount of bytes to copy (0 to copy the whole binary)
1390e65e175bSOded Gabbay */
1391e65e175bSOded Gabbay struct fw_image_props {
1392e65e175bSOded Gabbay char *image_name;
1393e65e175bSOded Gabbay u32 src_off;
1394e65e175bSOded Gabbay u32 copy_size;
1395e65e175bSOded Gabbay };
1396e65e175bSOded Gabbay
1397e65e175bSOded Gabbay /**
1398e65e175bSOded Gabbay * struct fw_load_mgr - manager FW loading process
1399e65e175bSOded Gabbay * @dynamic_loader: specific structure for dynamic load
1400e65e175bSOded Gabbay * @static_loader: specific structure for static load
1401e65e175bSOded Gabbay * @pre_fw_load_props: parameter for pre FW load
1402e65e175bSOded Gabbay * @boot_fit_img: boot fit image properties
1403e65e175bSOded Gabbay * @linux_img: linux image properties
1404e65e175bSOded Gabbay * @cpu_timeout: CPU response timeout in usec
1405e65e175bSOded Gabbay * @boot_fit_timeout: Boot fit load timeout in usec
1406e65e175bSOded Gabbay * @skip_bmc: should BMC be skipped
1407e65e175bSOded Gabbay * @sram_bar_id: SRAM bar ID
1408e65e175bSOded Gabbay * @dram_bar_id: DRAM bar ID
1409e65e175bSOded Gabbay * @fw_comp_loaded: bitmask of loaded FW components. set bit meaning loaded
1410e65e175bSOded Gabbay * component. values are set according to enum hl_fw_types.
1411e65e175bSOded Gabbay */
1412e65e175bSOded Gabbay struct fw_load_mgr {
1413e65e175bSOded Gabbay union {
1414e65e175bSOded Gabbay struct dynamic_fw_load_mgr dynamic_loader;
1415e65e175bSOded Gabbay struct static_fw_load_mgr static_loader;
1416e65e175bSOded Gabbay };
1417e65e175bSOded Gabbay struct pre_fw_load_props pre_fw_load;
1418e65e175bSOded Gabbay struct fw_image_props boot_fit_img;
1419e65e175bSOded Gabbay struct fw_image_props linux_img;
1420e65e175bSOded Gabbay u32 cpu_timeout;
1421e65e175bSOded Gabbay u32 boot_fit_timeout;
1422e65e175bSOded Gabbay u8 skip_bmc;
1423e65e175bSOded Gabbay u8 sram_bar_id;
1424e65e175bSOded Gabbay u8 dram_bar_id;
1425e65e175bSOded Gabbay u8 fw_comp_loaded;
1426e65e175bSOded Gabbay };
1427e65e175bSOded Gabbay
1428e65e175bSOded Gabbay struct hl_cs;
1429e65e175bSOded Gabbay
1430e65e175bSOded Gabbay /**
1431e65e175bSOded Gabbay * struct engines_data - asic engines data
1432e65e175bSOded Gabbay * @buf: buffer for engines data in ascii
1433e65e175bSOded Gabbay * @actual_size: actual size of data that was written by the driver to the allocated buffer
1434e65e175bSOded Gabbay * @allocated_buf_size: total size of allocated buffer
1435e65e175bSOded Gabbay */
1436e65e175bSOded Gabbay struct engines_data {
1437e65e175bSOded Gabbay char *buf;
1438e65e175bSOded Gabbay int actual_size;
1439e65e175bSOded Gabbay u32 allocated_buf_size;
1440e65e175bSOded Gabbay };
1441e65e175bSOded Gabbay
1442e65e175bSOded Gabbay /**
1443e65e175bSOded Gabbay * struct hl_asic_funcs - ASIC specific functions that are can be called from
1444e65e175bSOded Gabbay * common code.
1445e65e175bSOded Gabbay * @early_init: sets up early driver state (pre sw_init), doesn't configure H/W.
1446e65e175bSOded Gabbay * @early_fini: tears down what was done in early_init.
1447e65e175bSOded Gabbay * @late_init: sets up late driver/hw state (post hw_init) - Optional.
1448e65e175bSOded Gabbay * @late_fini: tears down what was done in late_init (pre hw_fini) - Optional.
1449e65e175bSOded Gabbay * @sw_init: sets up driver state, does not configure H/W.
1450e65e175bSOded Gabbay * @sw_fini: tears down driver state, does not configure H/W.
1451e65e175bSOded Gabbay * @hw_init: sets up the H/W state.
1452e65e175bSOded Gabbay * @hw_fini: tears down the H/W state.
1453e65e175bSOded Gabbay * @halt_engines: halt engines, needed for reset sequence. This also disables
1454e65e175bSOded Gabbay * interrupts from the device. Should be called before
1455e65e175bSOded Gabbay * hw_fini and before CS rollback.
1456e65e175bSOded Gabbay * @suspend: handles IP specific H/W or SW changes for suspend.
1457e65e175bSOded Gabbay * @resume: handles IP specific H/W or SW changes for resume.
1458e65e175bSOded Gabbay * @mmap: maps a memory.
1459e65e175bSOded Gabbay * @ring_doorbell: increment PI on a given QMAN.
1460e65e175bSOded Gabbay * @pqe_write: Write the PQ entry to the PQ. This is ASIC-specific
1461e65e175bSOded Gabbay * function because the PQs are located in different memory areas
1462e65e175bSOded Gabbay * per ASIC (SRAM, DRAM, Host memory) and therefore, the method of
1463e65e175bSOded Gabbay * writing the PQE must match the destination memory area
1464e65e175bSOded Gabbay * properties.
1465e65e175bSOded Gabbay * @asic_dma_alloc_coherent: Allocate coherent DMA memory by calling
1466e65e175bSOded Gabbay * dma_alloc_coherent(). This is ASIC function because
1467e65e175bSOded Gabbay * its implementation is not trivial when the driver
1468e65e175bSOded Gabbay * is loaded in simulation mode (not upstreamed).
1469e65e175bSOded Gabbay * @asic_dma_free_coherent: Free coherent DMA memory by calling
1470e65e175bSOded Gabbay * dma_free_coherent(). This is ASIC function because
1471e65e175bSOded Gabbay * its implementation is not trivial when the driver
1472e65e175bSOded Gabbay * is loaded in simulation mode (not upstreamed).
1473e65e175bSOded Gabbay * @scrub_device_mem: Scrub the entire SRAM and DRAM.
1474e65e175bSOded Gabbay * @scrub_device_dram: Scrub the dram memory of the device.
1475e65e175bSOded Gabbay * @get_int_queue_base: get the internal queue base address.
1476e65e175bSOded Gabbay * @test_queues: run simple test on all queues for sanity check.
1477e65e175bSOded Gabbay * @asic_dma_pool_zalloc: small DMA allocation of coherent memory from DMA pool.
1478e65e175bSOded Gabbay * size of allocation is HL_DMA_POOL_BLK_SIZE.
1479e65e175bSOded Gabbay * @asic_dma_pool_free: free small DMA allocation from pool.
1480e65e175bSOded Gabbay * @cpu_accessible_dma_pool_alloc: allocate CPU PQ packet from DMA pool.
1481e65e175bSOded Gabbay * @cpu_accessible_dma_pool_free: free CPU PQ packet from DMA pool.
1482e65e175bSOded Gabbay * @asic_dma_unmap_single: unmap a single DMA buffer
1483e65e175bSOded Gabbay * @asic_dma_map_single: map a single buffer to a DMA
1484e65e175bSOded Gabbay * @hl_dma_unmap_sgtable: DMA unmap scatter-gather table.
1485e65e175bSOded Gabbay * @cs_parser: parse Command Submission.
1486e65e175bSOded Gabbay * @asic_dma_map_sgtable: DMA map scatter-gather table.
1487e65e175bSOded Gabbay * @add_end_of_cb_packets: Add packets to the end of CB, if device requires it.
1488e65e175bSOded Gabbay * @update_eq_ci: update event queue CI.
1489e65e175bSOded Gabbay * @context_switch: called upon ASID context switch.
1490e65e175bSOded Gabbay * @restore_phase_topology: clear all SOBs amd MONs.
1491e65e175bSOded Gabbay * @debugfs_read_dma: debug interface for reading up to 2MB from the device's
1492e65e175bSOded Gabbay * internal memory via DMA engine.
1493e65e175bSOded Gabbay * @add_device_attr: add ASIC specific device attributes.
1494e65e175bSOded Gabbay * @handle_eqe: handle event queue entry (IRQ) from CPU-CP.
1495e65e175bSOded Gabbay * @get_events_stat: retrieve event queue entries histogram.
1496e65e175bSOded Gabbay * @read_pte: read MMU page table entry from DRAM.
1497e65e175bSOded Gabbay * @write_pte: write MMU page table entry to DRAM.
1498e65e175bSOded Gabbay * @mmu_invalidate_cache: flush MMU STLB host/DRAM cache, either with soft
1499e65e175bSOded Gabbay * (L1 only) or hard (L0 & L1) flush.
1500e65e175bSOded Gabbay * @mmu_invalidate_cache_range: flush specific MMU STLB cache lines with ASID-VA-size mask.
1501e65e175bSOded Gabbay * @mmu_prefetch_cache_range: pre-fetch specific MMU STLB cache lines with ASID-VA-size mask.
1502e65e175bSOded Gabbay * @send_heartbeat: send is-alive packet to CPU-CP and verify response.
1503e65e175bSOded Gabbay * @debug_coresight: perform certain actions on Coresight for debugging.
1504e65e175bSOded Gabbay * @is_device_idle: return true if device is idle, false otherwise.
1505e65e175bSOded Gabbay * @compute_reset_late_init: perform certain actions needed after a compute reset
1506e65e175bSOded Gabbay * @hw_queues_lock: acquire H/W queues lock.
1507e65e175bSOded Gabbay * @hw_queues_unlock: release H/W queues lock.
1508e65e175bSOded Gabbay * @get_pci_id: retrieve PCI ID.
1509e65e175bSOded Gabbay * @get_eeprom_data: retrieve EEPROM data from F/W.
1510e65e175bSOded Gabbay * @get_monitor_dump: retrieve monitor registers dump from F/W.
1511e65e175bSOded Gabbay * @send_cpu_message: send message to F/W. If the message is timedout, the
1512e65e175bSOded Gabbay * driver will eventually reset the device. The timeout can
1513e65e175bSOded Gabbay * be determined by the calling function or it can be 0 and
1514e65e175bSOded Gabbay * then the timeout is the default timeout for the specific
1515e65e175bSOded Gabbay * ASIC
1516e65e175bSOded Gabbay * @get_hw_state: retrieve the H/W state
1517e65e175bSOded Gabbay * @pci_bars_map: Map PCI BARs.
1518e65e175bSOded Gabbay * @init_iatu: Initialize the iATU unit inside the PCI controller.
1519e65e175bSOded Gabbay * @rreg: Read a register. Needed for simulator support.
1520e65e175bSOded Gabbay * @wreg: Write a register. Needed for simulator support.
1521e65e175bSOded Gabbay * @halt_coresight: stop the ETF and ETR traces.
1522e65e175bSOded Gabbay * @ctx_init: context dependent initialization.
1523e65e175bSOded Gabbay * @ctx_fini: context dependent cleanup.
1524e65e175bSOded Gabbay * @pre_schedule_cs: Perform pre-CS-scheduling operations.
1525e65e175bSOded Gabbay * @get_queue_id_for_cq: Get the H/W queue id related to the given CQ index.
1526e65e175bSOded Gabbay * @load_firmware_to_device: load the firmware to the device's memory
1527e65e175bSOded Gabbay * @load_boot_fit_to_device: load boot fit to device's memory
1528e65e175bSOded Gabbay * @get_signal_cb_size: Get signal CB size.
1529e65e175bSOded Gabbay * @get_wait_cb_size: Get wait CB size.
1530e65e175bSOded Gabbay * @gen_signal_cb: Generate a signal CB.
1531e65e175bSOded Gabbay * @gen_wait_cb: Generate a wait CB.
1532e65e175bSOded Gabbay * @reset_sob: Reset a SOB.
1533e65e175bSOded Gabbay * @reset_sob_group: Reset SOB group
1534e65e175bSOded Gabbay * @get_device_time: Get the device time.
1535e65e175bSOded Gabbay * @pb_print_security_errors: print security errors according block and cause
1536e65e175bSOded Gabbay * @collective_wait_init_cs: Generate collective master/slave packets
1537e65e175bSOded Gabbay * and place them in the relevant cs jobs
1538e65e175bSOded Gabbay * @collective_wait_create_jobs: allocate collective wait cs jobs
1539e65e175bSOded Gabbay * @get_dec_base_addr: get the base address of a given decoder.
1540e65e175bSOded Gabbay * @scramble_addr: Routine to scramble the address prior of mapping it
1541e65e175bSOded Gabbay * in the MMU.
1542e65e175bSOded Gabbay * @descramble_addr: Routine to de-scramble the address prior of
1543e65e175bSOded Gabbay * showing it to users.
1544e65e175bSOded Gabbay * @ack_protection_bits_errors: ack and dump all security violations
1545e65e175bSOded Gabbay * @get_hw_block_id: retrieve a HW block id to be used by the user to mmap it.
1546e65e175bSOded Gabbay * also returns the size of the block if caller supplies
1547e65e175bSOded Gabbay * a valid pointer for it
1548e65e175bSOded Gabbay * @hw_block_mmap: mmap a HW block with a given id.
1549e65e175bSOded Gabbay * @enable_events_from_fw: send interrupt to firmware to notify them the
1550e65e175bSOded Gabbay * driver is ready to receive asynchronous events. This
1551e65e175bSOded Gabbay * function should be called during the first init and
1552e65e175bSOded Gabbay * after every hard-reset of the device
1553e65e175bSOded Gabbay * @ack_mmu_errors: check and ack mmu errors, page fault, access violation.
1554e65e175bSOded Gabbay * @get_msi_info: Retrieve asic-specific MSI ID of the f/w async event
1555e65e175bSOded Gabbay * @map_pll_idx_to_fw_idx: convert driver specific per asic PLL index to
1556e65e175bSOded Gabbay * generic f/w compatible PLL Indexes
1557e65e175bSOded Gabbay * @init_firmware_preload_params: initialize pre FW-load parameters.
1558e65e175bSOded Gabbay * @init_firmware_loader: initialize data for FW loader.
1559e65e175bSOded Gabbay * @init_cpu_scrambler_dram: Enable CPU specific DRAM scrambling
1560e65e175bSOded Gabbay * @state_dump_init: initialize constants required for state dump
1561e65e175bSOded Gabbay * @get_sob_addr: get SOB base address offset.
1562e65e175bSOded Gabbay * @set_pci_memory_regions: setting properties of PCI memory regions
1563e65e175bSOded Gabbay * @get_stream_master_qid_arr: get pointer to stream masters QID array
1564e65e175bSOded Gabbay * @check_if_razwi_happened: check if there was a razwi due to RR violation.
1565e65e175bSOded Gabbay * @access_dev_mem: access device memory
1566e65e175bSOded Gabbay * @set_dram_bar_base: set the base of the DRAM BAR
1567e65e175bSOded Gabbay * @set_engine_cores: set a config command to engine cores
1568f7f0085eSKoby Elbaz * @set_engines: set a config command to user engines
1569e65e175bSOded Gabbay * @send_device_activity: indication to FW about device availability
1570e65e175bSOded Gabbay * @set_dram_properties: set DRAM related properties.
1571ab509d81SOhad Sharabi * @set_binning_masks: set binning/enable masks for all relevant components.
1572e65e175bSOded Gabbay */
1573e65e175bSOded Gabbay struct hl_asic_funcs {
1574e65e175bSOded Gabbay int (*early_init)(struct hl_device *hdev);
1575e65e175bSOded Gabbay int (*early_fini)(struct hl_device *hdev);
1576e65e175bSOded Gabbay int (*late_init)(struct hl_device *hdev);
1577e65e175bSOded Gabbay void (*late_fini)(struct hl_device *hdev);
1578e65e175bSOded Gabbay int (*sw_init)(struct hl_device *hdev);
1579e65e175bSOded Gabbay int (*sw_fini)(struct hl_device *hdev);
1580e65e175bSOded Gabbay int (*hw_init)(struct hl_device *hdev);
15815e09ae92SDafna Hirschfeld int (*hw_fini)(struct hl_device *hdev, bool hard_reset, bool fw_reset);
1582e65e175bSOded Gabbay void (*halt_engines)(struct hl_device *hdev, bool hard_reset, bool fw_reset);
1583e65e175bSOded Gabbay int (*suspend)(struct hl_device *hdev);
1584e65e175bSOded Gabbay int (*resume)(struct hl_device *hdev);
1585e65e175bSOded Gabbay int (*mmap)(struct hl_device *hdev, struct vm_area_struct *vma,
1586e65e175bSOded Gabbay void *cpu_addr, dma_addr_t dma_addr, size_t size);
1587e65e175bSOded Gabbay void (*ring_doorbell)(struct hl_device *hdev, u32 hw_queue_id, u32 pi);
1588e65e175bSOded Gabbay void (*pqe_write)(struct hl_device *hdev, __le64 *pqe,
1589e65e175bSOded Gabbay struct hl_bd *bd);
1590e65e175bSOded Gabbay void* (*asic_dma_alloc_coherent)(struct hl_device *hdev, size_t size,
1591e65e175bSOded Gabbay dma_addr_t *dma_handle, gfp_t flag);
1592e65e175bSOded Gabbay void (*asic_dma_free_coherent)(struct hl_device *hdev, size_t size,
1593e65e175bSOded Gabbay void *cpu_addr, dma_addr_t dma_handle);
1594e65e175bSOded Gabbay int (*scrub_device_mem)(struct hl_device *hdev);
1595e65e175bSOded Gabbay int (*scrub_device_dram)(struct hl_device *hdev, u64 val);
1596e65e175bSOded Gabbay void* (*get_int_queue_base)(struct hl_device *hdev, u32 queue_id,
1597e65e175bSOded Gabbay dma_addr_t *dma_handle, u16 *queue_len);
1598e65e175bSOded Gabbay int (*test_queues)(struct hl_device *hdev);
1599e65e175bSOded Gabbay void* (*asic_dma_pool_zalloc)(struct hl_device *hdev, size_t size,
1600e65e175bSOded Gabbay gfp_t mem_flags, dma_addr_t *dma_handle);
1601e65e175bSOded Gabbay void (*asic_dma_pool_free)(struct hl_device *hdev, void *vaddr,
1602e65e175bSOded Gabbay dma_addr_t dma_addr);
1603e65e175bSOded Gabbay void* (*cpu_accessible_dma_pool_alloc)(struct hl_device *hdev,
1604e65e175bSOded Gabbay size_t size, dma_addr_t *dma_handle);
1605e65e175bSOded Gabbay void (*cpu_accessible_dma_pool_free)(struct hl_device *hdev,
1606e65e175bSOded Gabbay size_t size, void *vaddr);
1607e65e175bSOded Gabbay void (*asic_dma_unmap_single)(struct hl_device *hdev,
1608e65e175bSOded Gabbay dma_addr_t dma_addr, int len,
1609e65e175bSOded Gabbay enum dma_data_direction dir);
1610e65e175bSOded Gabbay dma_addr_t (*asic_dma_map_single)(struct hl_device *hdev,
1611e65e175bSOded Gabbay void *addr, int len,
1612e65e175bSOded Gabbay enum dma_data_direction dir);
1613e65e175bSOded Gabbay void (*hl_dma_unmap_sgtable)(struct hl_device *hdev,
1614e65e175bSOded Gabbay struct sg_table *sgt,
1615e65e175bSOded Gabbay enum dma_data_direction dir);
1616e65e175bSOded Gabbay int (*cs_parser)(struct hl_device *hdev, struct hl_cs_parser *parser);
1617e65e175bSOded Gabbay int (*asic_dma_map_sgtable)(struct hl_device *hdev, struct sg_table *sgt,
1618e65e175bSOded Gabbay enum dma_data_direction dir);
1619e65e175bSOded Gabbay void (*add_end_of_cb_packets)(struct hl_device *hdev,
1620e65e175bSOded Gabbay void *kernel_address, u32 len,
1621e65e175bSOded Gabbay u32 original_len,
1622e65e175bSOded Gabbay u64 cq_addr, u32 cq_val, u32 msix_num,
1623e65e175bSOded Gabbay bool eb);
1624e65e175bSOded Gabbay void (*update_eq_ci)(struct hl_device *hdev, u32 val);
1625e65e175bSOded Gabbay int (*context_switch)(struct hl_device *hdev, u32 asid);
1626e65e175bSOded Gabbay void (*restore_phase_topology)(struct hl_device *hdev);
1627e65e175bSOded Gabbay int (*debugfs_read_dma)(struct hl_device *hdev, u64 addr, u32 size,
1628e65e175bSOded Gabbay void *blob_addr);
1629e65e175bSOded Gabbay void (*add_device_attr)(struct hl_device *hdev, struct attribute_group *dev_clk_attr_grp,
1630e65e175bSOded Gabbay struct attribute_group *dev_vrm_attr_grp);
1631e65e175bSOded Gabbay void (*handle_eqe)(struct hl_device *hdev,
1632e65e175bSOded Gabbay struct hl_eq_entry *eq_entry);
1633e65e175bSOded Gabbay void* (*get_events_stat)(struct hl_device *hdev, bool aggregate,
1634e65e175bSOded Gabbay u32 *size);
1635e65e175bSOded Gabbay u64 (*read_pte)(struct hl_device *hdev, u64 addr);
1636e65e175bSOded Gabbay void (*write_pte)(struct hl_device *hdev, u64 addr, u64 val);
1637e65e175bSOded Gabbay int (*mmu_invalidate_cache)(struct hl_device *hdev, bool is_hard,
1638e65e175bSOded Gabbay u32 flags);
1639e65e175bSOded Gabbay int (*mmu_invalidate_cache_range)(struct hl_device *hdev, bool is_hard,
1640e65e175bSOded Gabbay u32 flags, u32 asid, u64 va, u64 size);
1641e65e175bSOded Gabbay int (*mmu_prefetch_cache_range)(struct hl_ctx *ctx, u32 flags, u32 asid, u64 va, u64 size);
1642e65e175bSOded Gabbay int (*send_heartbeat)(struct hl_device *hdev);
1643e65e175bSOded Gabbay int (*debug_coresight)(struct hl_device *hdev, struct hl_ctx *ctx, void *data);
1644e65e175bSOded Gabbay bool (*is_device_idle)(struct hl_device *hdev, u64 *mask_arr, u8 mask_len,
1645e65e175bSOded Gabbay struct engines_data *e);
1646e65e175bSOded Gabbay int (*compute_reset_late_init)(struct hl_device *hdev);
1647e65e175bSOded Gabbay void (*hw_queues_lock)(struct hl_device *hdev);
1648e65e175bSOded Gabbay void (*hw_queues_unlock)(struct hl_device *hdev);
1649e65e175bSOded Gabbay u32 (*get_pci_id)(struct hl_device *hdev);
1650e65e175bSOded Gabbay int (*get_eeprom_data)(struct hl_device *hdev, void *data, size_t max_size);
1651e65e175bSOded Gabbay int (*get_monitor_dump)(struct hl_device *hdev, void *data);
1652e65e175bSOded Gabbay int (*send_cpu_message)(struct hl_device *hdev, u32 *msg,
1653e65e175bSOded Gabbay u16 len, u32 timeout, u64 *result);
1654e65e175bSOded Gabbay int (*pci_bars_map)(struct hl_device *hdev);
1655e65e175bSOded Gabbay int (*init_iatu)(struct hl_device *hdev);
1656e65e175bSOded Gabbay u32 (*rreg)(struct hl_device *hdev, u32 reg);
1657e65e175bSOded Gabbay void (*wreg)(struct hl_device *hdev, u32 reg, u32 val);
1658e65e175bSOded Gabbay void (*halt_coresight)(struct hl_device *hdev, struct hl_ctx *ctx);
1659e65e175bSOded Gabbay int (*ctx_init)(struct hl_ctx *ctx);
1660e65e175bSOded Gabbay void (*ctx_fini)(struct hl_ctx *ctx);
1661e65e175bSOded Gabbay int (*pre_schedule_cs)(struct hl_cs *cs);
1662e65e175bSOded Gabbay u32 (*get_queue_id_for_cq)(struct hl_device *hdev, u32 cq_idx);
1663e65e175bSOded Gabbay int (*load_firmware_to_device)(struct hl_device *hdev);
1664e65e175bSOded Gabbay int (*load_boot_fit_to_device)(struct hl_device *hdev);
1665e65e175bSOded Gabbay u32 (*get_signal_cb_size)(struct hl_device *hdev);
1666e65e175bSOded Gabbay u32 (*get_wait_cb_size)(struct hl_device *hdev);
1667e65e175bSOded Gabbay u32 (*gen_signal_cb)(struct hl_device *hdev, void *data, u16 sob_id,
1668e65e175bSOded Gabbay u32 size, bool eb);
1669e65e175bSOded Gabbay u32 (*gen_wait_cb)(struct hl_device *hdev,
1670e65e175bSOded Gabbay struct hl_gen_wait_properties *prop);
1671e65e175bSOded Gabbay void (*reset_sob)(struct hl_device *hdev, void *data);
1672e65e175bSOded Gabbay void (*reset_sob_group)(struct hl_device *hdev, u16 sob_group);
1673e65e175bSOded Gabbay u64 (*get_device_time)(struct hl_device *hdev);
1674e65e175bSOded Gabbay void (*pb_print_security_errors)(struct hl_device *hdev,
1675e65e175bSOded Gabbay u32 block_addr, u32 cause, u32 offended_addr);
1676e65e175bSOded Gabbay int (*collective_wait_init_cs)(struct hl_cs *cs);
1677e65e175bSOded Gabbay int (*collective_wait_create_jobs)(struct hl_device *hdev,
1678e65e175bSOded Gabbay struct hl_ctx *ctx, struct hl_cs *cs,
1679e65e175bSOded Gabbay u32 wait_queue_id, u32 collective_engine_id,
1680e65e175bSOded Gabbay u32 encaps_signal_offset);
1681e65e175bSOded Gabbay u32 (*get_dec_base_addr)(struct hl_device *hdev, u32 core_id);
1682e65e175bSOded Gabbay u64 (*scramble_addr)(struct hl_device *hdev, u64 addr);
1683e65e175bSOded Gabbay u64 (*descramble_addr)(struct hl_device *hdev, u64 addr);
1684e65e175bSOded Gabbay void (*ack_protection_bits_errors)(struct hl_device *hdev);
1685e65e175bSOded Gabbay int (*get_hw_block_id)(struct hl_device *hdev, u64 block_addr,
1686e65e175bSOded Gabbay u32 *block_size, u32 *block_id);
1687e65e175bSOded Gabbay int (*hw_block_mmap)(struct hl_device *hdev, struct vm_area_struct *vma,
1688e65e175bSOded Gabbay u32 block_id, u32 block_size);
1689e65e175bSOded Gabbay void (*enable_events_from_fw)(struct hl_device *hdev);
1690e65e175bSOded Gabbay int (*ack_mmu_errors)(struct hl_device *hdev, u64 mmu_cap_mask);
1691e65e175bSOded Gabbay void (*get_msi_info)(__le32 *table);
1692e65e175bSOded Gabbay int (*map_pll_idx_to_fw_idx)(u32 pll_idx);
1693e65e175bSOded Gabbay void (*init_firmware_preload_params)(struct hl_device *hdev);
1694e65e175bSOded Gabbay void (*init_firmware_loader)(struct hl_device *hdev);
1695e65e175bSOded Gabbay void (*init_cpu_scrambler_dram)(struct hl_device *hdev);
1696e65e175bSOded Gabbay void (*state_dump_init)(struct hl_device *hdev);
1697e65e175bSOded Gabbay u32 (*get_sob_addr)(struct hl_device *hdev, u32 sob_id);
1698e65e175bSOded Gabbay void (*set_pci_memory_regions)(struct hl_device *hdev);
1699e65e175bSOded Gabbay u32* (*get_stream_master_qid_arr)(void);
1700e65e175bSOded Gabbay void (*check_if_razwi_happened)(struct hl_device *hdev);
1701e65e175bSOded Gabbay int (*mmu_get_real_page_size)(struct hl_device *hdev, struct hl_mmu_properties *mmu_prop,
1702e65e175bSOded Gabbay u32 page_size, u32 *real_page_size, bool is_dram_addr);
1703e65e175bSOded Gabbay int (*access_dev_mem)(struct hl_device *hdev, enum pci_region region_type,
1704e65e175bSOded Gabbay u64 addr, u64 *val, enum debugfs_access_type acc_type);
1705e65e175bSOded Gabbay u64 (*set_dram_bar_base)(struct hl_device *hdev, u64 addr);
1706e65e175bSOded Gabbay int (*set_engine_cores)(struct hl_device *hdev, u32 *core_ids,
1707e65e175bSOded Gabbay u32 num_cores, u32 core_command);
1708f7f0085eSKoby Elbaz int (*set_engines)(struct hl_device *hdev, u32 *engine_ids,
1709f7f0085eSKoby Elbaz u32 num_engines, u32 engine_command);
1710e65e175bSOded Gabbay int (*send_device_activity)(struct hl_device *hdev, bool open);
1711e65e175bSOded Gabbay int (*set_dram_properties)(struct hl_device *hdev);
1712ab509d81SOhad Sharabi int (*set_binning_masks)(struct hl_device *hdev);
1713e65e175bSOded Gabbay };
1714e65e175bSOded Gabbay
1715e65e175bSOded Gabbay
1716e65e175bSOded Gabbay /*
1717e65e175bSOded Gabbay * CONTEXTS
1718e65e175bSOded Gabbay */
1719e65e175bSOded Gabbay
1720e65e175bSOded Gabbay #define HL_KERNEL_ASID_ID 0
1721e65e175bSOded Gabbay
1722e65e175bSOded Gabbay /**
1723e65e175bSOded Gabbay * enum hl_va_range_type - virtual address range type.
1724e65e175bSOded Gabbay * @HL_VA_RANGE_TYPE_HOST: range type of host pages
1725e65e175bSOded Gabbay * @HL_VA_RANGE_TYPE_HOST_HUGE: range type of host huge pages
1726e65e175bSOded Gabbay * @HL_VA_RANGE_TYPE_DRAM: range type of dram pages
1727e65e175bSOded Gabbay */
1728e65e175bSOded Gabbay enum hl_va_range_type {
1729e65e175bSOded Gabbay HL_VA_RANGE_TYPE_HOST,
1730e65e175bSOded Gabbay HL_VA_RANGE_TYPE_HOST_HUGE,
1731e65e175bSOded Gabbay HL_VA_RANGE_TYPE_DRAM,
1732e65e175bSOded Gabbay HL_VA_RANGE_TYPE_MAX
1733e65e175bSOded Gabbay };
1734e65e175bSOded Gabbay
1735e65e175bSOded Gabbay /**
1736e65e175bSOded Gabbay * struct hl_va_range - virtual addresses range.
1737e65e175bSOded Gabbay * @lock: protects the virtual addresses list.
1738e65e175bSOded Gabbay * @list: list of virtual addresses blocks available for mappings.
1739e65e175bSOded Gabbay * @start_addr: range start address.
1740e65e175bSOded Gabbay * @end_addr: range end address.
1741e65e175bSOded Gabbay * @page_size: page size of this va range.
1742e65e175bSOded Gabbay */
1743e65e175bSOded Gabbay struct hl_va_range {
1744e65e175bSOded Gabbay struct mutex lock;
1745e65e175bSOded Gabbay struct list_head list;
1746e65e175bSOded Gabbay u64 start_addr;
1747e65e175bSOded Gabbay u64 end_addr;
1748e65e175bSOded Gabbay u32 page_size;
1749e65e175bSOded Gabbay };
1750e65e175bSOded Gabbay
1751e65e175bSOded Gabbay /**
1752e65e175bSOded Gabbay * struct hl_cs_counters_atomic - command submission counters
1753e65e175bSOded Gabbay * @out_of_mem_drop_cnt: dropped due to memory allocation issue
1754e65e175bSOded Gabbay * @parsing_drop_cnt: dropped due to error in packet parsing
1755e65e175bSOded Gabbay * @queue_full_drop_cnt: dropped due to queue full
1756e65e175bSOded Gabbay * @device_in_reset_drop_cnt: dropped due to device in reset
1757e65e175bSOded Gabbay * @max_cs_in_flight_drop_cnt: dropped due to maximum CS in-flight
1758e65e175bSOded Gabbay * @validation_drop_cnt: dropped due to error in validation
1759e65e175bSOded Gabbay */
1760e65e175bSOded Gabbay struct hl_cs_counters_atomic {
1761e65e175bSOded Gabbay atomic64_t out_of_mem_drop_cnt;
1762e65e175bSOded Gabbay atomic64_t parsing_drop_cnt;
1763e65e175bSOded Gabbay atomic64_t queue_full_drop_cnt;
1764e65e175bSOded Gabbay atomic64_t device_in_reset_drop_cnt;
1765e65e175bSOded Gabbay atomic64_t max_cs_in_flight_drop_cnt;
1766e65e175bSOded Gabbay atomic64_t validation_drop_cnt;
1767e65e175bSOded Gabbay };
1768e65e175bSOded Gabbay
1769e65e175bSOded Gabbay /**
1770e65e175bSOded Gabbay * struct hl_dmabuf_priv - a dma-buf private object.
1771e65e175bSOded Gabbay * @dmabuf: pointer to dma-buf object.
1772e65e175bSOded Gabbay * @ctx: pointer to the dma-buf owner's context.
1773e65e175bSOded Gabbay * @phys_pg_pack: pointer to physical page pack if the dma-buf was exported
1774e65e175bSOded Gabbay * where virtual memory is supported.
1775e65e175bSOded Gabbay * @memhash_hnode: pointer to the memhash node. this object holds the export count.
1776e65e175bSOded Gabbay * @device_address: physical address of the device's memory. Relevant only
1777e65e175bSOded Gabbay * if phys_pg_pack is NULL (dma-buf was exported from address).
1778e65e175bSOded Gabbay * The total size can be taken from the dmabuf object.
1779e65e175bSOded Gabbay */
1780e65e175bSOded Gabbay struct hl_dmabuf_priv {
1781e65e175bSOded Gabbay struct dma_buf *dmabuf;
1782e65e175bSOded Gabbay struct hl_ctx *ctx;
1783e65e175bSOded Gabbay struct hl_vm_phys_pg_pack *phys_pg_pack;
1784e65e175bSOded Gabbay struct hl_vm_hash_node *memhash_hnode;
1785e65e175bSOded Gabbay uint64_t device_address;
1786e65e175bSOded Gabbay };
1787e65e175bSOded Gabbay
1788e65e175bSOded Gabbay #define HL_CS_OUTCOME_HISTORY_LEN 256
1789e65e175bSOded Gabbay
1790e65e175bSOded Gabbay /**
1791e65e175bSOded Gabbay * struct hl_cs_outcome - represents a single completed CS outcome
1792e65e175bSOded Gabbay * @list_link: link to either container's used list or free list
1793e65e175bSOded Gabbay * @map_link: list to the container hash map
1794e65e175bSOded Gabbay * @ts: completion ts
1795e65e175bSOded Gabbay * @seq: the original cs sequence
1796e65e175bSOded Gabbay * @error: error code cs completed with, if any
1797e65e175bSOded Gabbay */
1798e65e175bSOded Gabbay struct hl_cs_outcome {
1799e65e175bSOded Gabbay struct list_head list_link;
1800e65e175bSOded Gabbay struct hlist_node map_link;
1801e65e175bSOded Gabbay ktime_t ts;
1802e65e175bSOded Gabbay u64 seq;
1803e65e175bSOded Gabbay int error;
1804e65e175bSOded Gabbay };
1805e65e175bSOded Gabbay
1806e65e175bSOded Gabbay /**
1807e65e175bSOded Gabbay * struct hl_cs_outcome_store - represents a limited store of completed CS outcomes
1808e65e175bSOded Gabbay * @outcome_map: index of completed CS searchable by sequence number
1809e65e175bSOded Gabbay * @used_list: list of outcome objects currently in use
1810e65e175bSOded Gabbay * @free_list: list of outcome objects currently not in use
1811e65e175bSOded Gabbay * @nodes_pool: a static pool of pre-allocated outcome objects
1812e65e175bSOded Gabbay * @db_lock: any operation on the store must take this lock
1813e65e175bSOded Gabbay */
1814e65e175bSOded Gabbay struct hl_cs_outcome_store {
1815e65e175bSOded Gabbay DECLARE_HASHTABLE(outcome_map, 8);
1816e65e175bSOded Gabbay struct list_head used_list;
1817e65e175bSOded Gabbay struct list_head free_list;
1818e65e175bSOded Gabbay struct hl_cs_outcome nodes_pool[HL_CS_OUTCOME_HISTORY_LEN];
1819e65e175bSOded Gabbay spinlock_t db_lock;
1820e65e175bSOded Gabbay };
1821e65e175bSOded Gabbay
1822e65e175bSOded Gabbay /**
1823e65e175bSOded Gabbay * struct hl_ctx - user/kernel context.
1824e65e175bSOded Gabbay * @mem_hash: holds mapping from virtual address to virtual memory area
1825e65e175bSOded Gabbay * descriptor (hl_vm_phys_pg_list or hl_userptr).
1826e65e175bSOded Gabbay * @mmu_shadow_hash: holds a mapping from shadow address to pgt_info structure.
1827e65e175bSOded Gabbay * @hr_mmu_phys_hash: if host-resident MMU is used, holds a mapping from
1828e65e175bSOded Gabbay * MMU-hop-page physical address to its host-resident
1829e65e175bSOded Gabbay * pgt_info structure.
1830e65e175bSOded Gabbay * @hpriv: pointer to the private (Kernel Driver) data of the process (fd).
1831e65e175bSOded Gabbay * @hdev: pointer to the device structure.
1832e65e175bSOded Gabbay * @refcount: reference counter for the context. Context is released only when
1833f7f0085eSKoby Elbaz * this hits 0. It is incremented on CS and CS_WAIT.
1834e65e175bSOded Gabbay * @cs_pending: array of hl fence objects representing pending CS.
1835e65e175bSOded Gabbay * @outcome_store: storage data structure used to remember outcomes of completed
1836e65e175bSOded Gabbay * command submissions for a long time after CS id wraparound.
1837e65e175bSOded Gabbay * @va_range: holds available virtual addresses for host and dram mappings.
1838e65e175bSOded Gabbay * @mem_hash_lock: protects the mem_hash.
1839e65e175bSOded Gabbay * @hw_block_list_lock: protects the HW block memory list.
1840e65e175bSOded Gabbay * @debugfs_list: node in debugfs list of contexts.
1841e65e175bSOded Gabbay * @hw_block_mem_list: list of HW block virtual mapped addresses.
1842e65e175bSOded Gabbay * @cs_counters: context command submission counters.
1843e65e175bSOded Gabbay * @cb_va_pool: device VA pool for command buffers which are mapped to the
1844e65e175bSOded Gabbay * device's MMU.
1845e65e175bSOded Gabbay * @sig_mgr: encaps signals handle manager.
1846e65e175bSOded Gabbay * @cb_va_pool_base: the base address for the device VA pool
1847e65e175bSOded Gabbay * @cs_sequence: sequence number for CS. Value is assigned to a CS and passed
1848e65e175bSOded Gabbay * to user so user could inquire about CS. It is used as
1849e65e175bSOded Gabbay * index to cs_pending array.
1850e65e175bSOded Gabbay * @dram_default_hops: array that holds all hops addresses needed for default
1851e65e175bSOded Gabbay * DRAM mapping.
1852e65e175bSOded Gabbay * @cs_lock: spinlock to protect cs_sequence.
1853e65e175bSOded Gabbay * @dram_phys_mem: amount of used physical DRAM memory by this context.
1854e65e175bSOded Gabbay * @thread_ctx_switch_token: token to prevent multiple threads of the same
1855e65e175bSOded Gabbay * context from running the context switch phase.
1856e65e175bSOded Gabbay * Only a single thread should run it.
1857e65e175bSOded Gabbay * @thread_ctx_switch_wait_token: token to prevent the threads that didn't run
1858e65e175bSOded Gabbay * the context switch phase from moving to their
1859e65e175bSOded Gabbay * execution phase before the context switch phase
1860e65e175bSOded Gabbay * has finished.
1861e65e175bSOded Gabbay * @asid: context's unique address space ID in the device's MMU.
1862e65e175bSOded Gabbay * @handle: context's opaque handle for user
1863e65e175bSOded Gabbay */
1864e65e175bSOded Gabbay struct hl_ctx {
1865e65e175bSOded Gabbay DECLARE_HASHTABLE(mem_hash, MEM_HASH_TABLE_BITS);
1866e65e175bSOded Gabbay DECLARE_HASHTABLE(mmu_shadow_hash, MMU_HASH_TABLE_BITS);
1867e65e175bSOded Gabbay DECLARE_HASHTABLE(hr_mmu_phys_hash, MMU_HASH_TABLE_BITS);
1868e65e175bSOded Gabbay struct hl_fpriv *hpriv;
1869e65e175bSOded Gabbay struct hl_device *hdev;
1870e65e175bSOded Gabbay struct kref refcount;
1871e65e175bSOded Gabbay struct hl_fence **cs_pending;
1872e65e175bSOded Gabbay struct hl_cs_outcome_store outcome_store;
1873e65e175bSOded Gabbay struct hl_va_range *va_range[HL_VA_RANGE_TYPE_MAX];
1874e65e175bSOded Gabbay struct mutex mem_hash_lock;
1875e65e175bSOded Gabbay struct mutex hw_block_list_lock;
1876e65e175bSOded Gabbay struct list_head debugfs_list;
1877e65e175bSOded Gabbay struct list_head hw_block_mem_list;
1878e65e175bSOded Gabbay struct hl_cs_counters_atomic cs_counters;
1879e65e175bSOded Gabbay struct gen_pool *cb_va_pool;
1880e65e175bSOded Gabbay struct hl_encaps_signals_mgr sig_mgr;
1881e65e175bSOded Gabbay u64 cb_va_pool_base;
1882e65e175bSOded Gabbay u64 cs_sequence;
1883e65e175bSOded Gabbay u64 *dram_default_hops;
1884e65e175bSOded Gabbay spinlock_t cs_lock;
1885e65e175bSOded Gabbay atomic64_t dram_phys_mem;
1886e65e175bSOded Gabbay atomic_t thread_ctx_switch_token;
1887e65e175bSOded Gabbay u32 thread_ctx_switch_wait_token;
1888e65e175bSOded Gabbay u32 asid;
1889e65e175bSOded Gabbay u32 handle;
1890e65e175bSOded Gabbay };
1891e65e175bSOded Gabbay
1892e65e175bSOded Gabbay /**
1893e65e175bSOded Gabbay * struct hl_ctx_mgr - for handling multiple contexts.
1894e65e175bSOded Gabbay * @lock: protects ctx_handles.
1895e65e175bSOded Gabbay * @handles: idr to hold all ctx handles.
1896e65e175bSOded Gabbay */
1897e65e175bSOded Gabbay struct hl_ctx_mgr {
1898e65e175bSOded Gabbay struct mutex lock;
1899e65e175bSOded Gabbay struct idr handles;
1900e65e175bSOded Gabbay };
1901e65e175bSOded Gabbay
1902e65e175bSOded Gabbay
1903e65e175bSOded Gabbay /*
1904e65e175bSOded Gabbay * COMMAND SUBMISSIONS
1905e65e175bSOded Gabbay */
1906e65e175bSOded Gabbay
1907e65e175bSOded Gabbay /**
1908e65e175bSOded Gabbay * struct hl_userptr - memory mapping chunk information
1909e65e175bSOded Gabbay * @vm_type: type of the VM.
1910e65e175bSOded Gabbay * @job_node: linked-list node for hanging the object on the Job's list.
1911e65e175bSOded Gabbay * @pages: pointer to struct page array
1912e65e175bSOded Gabbay * @npages: size of @pages array
1913e65e175bSOded Gabbay * @sgt: pointer to the scatter-gather table that holds the pages.
1914e65e175bSOded Gabbay * @dir: for DMA unmapping, the direction must be supplied, so save it.
1915e65e175bSOded Gabbay * @debugfs_list: node in debugfs list of command submissions.
1916e65e175bSOded Gabbay * @pid: the pid of the user process owning the memory
1917e65e175bSOded Gabbay * @addr: user-space virtual address of the start of the memory area.
1918e65e175bSOded Gabbay * @size: size of the memory area to pin & map.
1919e65e175bSOded Gabbay * @dma_mapped: true if the SG was mapped to DMA addresses, false otherwise.
1920e65e175bSOded Gabbay */
1921e65e175bSOded Gabbay struct hl_userptr {
1922e65e175bSOded Gabbay enum vm_type vm_type; /* must be first */
1923e65e175bSOded Gabbay struct list_head job_node;
1924e65e175bSOded Gabbay struct page **pages;
1925e65e175bSOded Gabbay unsigned int npages;
1926e65e175bSOded Gabbay struct sg_table *sgt;
1927e65e175bSOded Gabbay enum dma_data_direction dir;
1928e65e175bSOded Gabbay struct list_head debugfs_list;
1929e65e175bSOded Gabbay pid_t pid;
1930e65e175bSOded Gabbay u64 addr;
1931e65e175bSOded Gabbay u64 size;
1932e65e175bSOded Gabbay u8 dma_mapped;
1933e65e175bSOded Gabbay };
1934e65e175bSOded Gabbay
1935e65e175bSOded Gabbay /**
1936e65e175bSOded Gabbay * struct hl_cs - command submission.
1937e65e175bSOded Gabbay * @jobs_in_queue_cnt: per each queue, maintain counter of submitted jobs.
1938e65e175bSOded Gabbay * @ctx: the context this CS belongs to.
1939e65e175bSOded Gabbay * @job_list: list of the CS's jobs in the various queues.
1940e65e175bSOded Gabbay * @job_lock: spinlock for the CS's jobs list. Needed for free_job.
1941e65e175bSOded Gabbay * @refcount: reference counter for usage of the CS.
1942e65e175bSOded Gabbay * @fence: pointer to the fence object of this CS.
1943e65e175bSOded Gabbay * @signal_fence: pointer to the fence object of the signal CS (used by wait
1944e65e175bSOded Gabbay * CS only).
1945e65e175bSOded Gabbay * @finish_work: workqueue object to run when CS is completed by H/W.
1946e65e175bSOded Gabbay * @work_tdr: delayed work node for TDR.
1947e65e175bSOded Gabbay * @mirror_node : node in device mirror list of command submissions.
1948e65e175bSOded Gabbay * @staged_cs_node: node in the staged cs list.
1949e65e175bSOded Gabbay * @debugfs_list: node in debugfs list of command submissions.
1950e65e175bSOded Gabbay * @encaps_sig_hdl: holds the encaps signals handle.
1951e65e175bSOded Gabbay * @sequence: the sequence number of this CS.
1952e65e175bSOded Gabbay * @staged_sequence: the sequence of the staged submission this CS is part of,
1953e65e175bSOded Gabbay * relevant only if staged_cs is set.
1954e65e175bSOded Gabbay * @timeout_jiffies: cs timeout in jiffies.
1955e65e175bSOded Gabbay * @submission_time_jiffies: submission time of the cs
1956e65e175bSOded Gabbay * @type: CS_TYPE_*.
1957e65e175bSOded Gabbay * @jobs_cnt: counter of submitted jobs on all queues.
1958e65e175bSOded Gabbay * @encaps_sig_hdl_id: encaps signals handle id, set for the first staged cs.
195975b6984eSOfir Bitton * @completion_timestamp: timestamp of the last completed cs job.
1960e65e175bSOded Gabbay * @sob_addr_offset: sob offset from the configuration base address.
1961e65e175bSOded Gabbay * @initial_sob_count: count of completed signals in SOB before current submission of signal or
1962e65e175bSOded Gabbay * cs with encaps signals.
1963e65e175bSOded Gabbay * @submitted: true if CS was submitted to H/W.
1964e65e175bSOded Gabbay * @completed: true if CS was completed by device.
1965e65e175bSOded Gabbay * @timedout : true if CS was timedout.
1966e65e175bSOded Gabbay * @tdr_active: true if TDR was activated for this CS (to prevent
1967e65e175bSOded Gabbay * double TDR activation).
1968e65e175bSOded Gabbay * @aborted: true if CS was aborted due to some device error.
1969e65e175bSOded Gabbay * @timestamp: true if a timestamp must be captured upon completion.
1970e65e175bSOded Gabbay * @staged_last: true if this is the last staged CS and needs completion.
1971e65e175bSOded Gabbay * @staged_first: true if this is the first staged CS and we need to receive
1972e65e175bSOded Gabbay * timeout for this CS.
1973e65e175bSOded Gabbay * @staged_cs: true if this CS is part of a staged submission.
1974e65e175bSOded Gabbay * @skip_reset_on_timeout: true if we shall not reset the device in case
1975e65e175bSOded Gabbay * timeout occurs (debug scenario).
1976e65e175bSOded Gabbay * @encaps_signals: true if this CS has encaps reserved signals.
1977e65e175bSOded Gabbay */
1978e65e175bSOded Gabbay struct hl_cs {
1979e65e175bSOded Gabbay u16 *jobs_in_queue_cnt;
1980e65e175bSOded Gabbay struct hl_ctx *ctx;
1981e65e175bSOded Gabbay struct list_head job_list;
1982e65e175bSOded Gabbay spinlock_t job_lock;
1983e65e175bSOded Gabbay struct kref refcount;
1984e65e175bSOded Gabbay struct hl_fence *fence;
1985e65e175bSOded Gabbay struct hl_fence *signal_fence;
1986e65e175bSOded Gabbay struct work_struct finish_work;
1987e65e175bSOded Gabbay struct delayed_work work_tdr;
1988e65e175bSOded Gabbay struct list_head mirror_node;
1989e65e175bSOded Gabbay struct list_head staged_cs_node;
1990e65e175bSOded Gabbay struct list_head debugfs_list;
1991e65e175bSOded Gabbay struct hl_cs_encaps_sig_handle *encaps_sig_hdl;
199275b6984eSOfir Bitton ktime_t completion_timestamp;
1993e65e175bSOded Gabbay u64 sequence;
1994e65e175bSOded Gabbay u64 staged_sequence;
1995e65e175bSOded Gabbay u64 timeout_jiffies;
1996e65e175bSOded Gabbay u64 submission_time_jiffies;
1997e65e175bSOded Gabbay enum hl_cs_type type;
1998e65e175bSOded Gabbay u32 jobs_cnt;
1999e65e175bSOded Gabbay u32 encaps_sig_hdl_id;
2000e65e175bSOded Gabbay u32 sob_addr_offset;
2001e65e175bSOded Gabbay u16 initial_sob_count;
2002e65e175bSOded Gabbay u8 submitted;
2003e65e175bSOded Gabbay u8 completed;
2004e65e175bSOded Gabbay u8 timedout;
2005e65e175bSOded Gabbay u8 tdr_active;
2006e65e175bSOded Gabbay u8 aborted;
2007e65e175bSOded Gabbay u8 timestamp;
2008e65e175bSOded Gabbay u8 staged_last;
2009e65e175bSOded Gabbay u8 staged_first;
2010e65e175bSOded Gabbay u8 staged_cs;
2011e65e175bSOded Gabbay u8 skip_reset_on_timeout;
2012e65e175bSOded Gabbay u8 encaps_signals;
2013e65e175bSOded Gabbay };
2014e65e175bSOded Gabbay
2015e65e175bSOded Gabbay /**
2016e65e175bSOded Gabbay * struct hl_cs_job - command submission job.
2017e65e175bSOded Gabbay * @cs_node: the node to hang on the CS jobs list.
2018e65e175bSOded Gabbay * @cs: the CS this job belongs to.
2019e65e175bSOded Gabbay * @user_cb: the CB we got from the user.
2020e65e175bSOded Gabbay * @patched_cb: in case of patching, this is internal CB which is submitted on
2021e65e175bSOded Gabbay * the queue instead of the CB we got from the IOCTL.
2022e65e175bSOded Gabbay * @finish_work: workqueue object to run when job is completed.
2023e65e175bSOded Gabbay * @userptr_list: linked-list of userptr mappings that belong to this job and
2024e65e175bSOded Gabbay * wait for completion.
2025e65e175bSOded Gabbay * @debugfs_list: node in debugfs list of command submission jobs.
2026e65e175bSOded Gabbay * @refcount: reference counter for usage of the CS job.
2027e65e175bSOded Gabbay * @queue_type: the type of the H/W queue this job is submitted to.
202875b6984eSOfir Bitton * @timestamp: timestamp upon job completion
2029e65e175bSOded Gabbay * @id: the id of this job inside a CS.
2030e65e175bSOded Gabbay * @hw_queue_id: the id of the H/W queue this job is submitted to.
2031e65e175bSOded Gabbay * @user_cb_size: the actual size of the CB we got from the user.
2032e65e175bSOded Gabbay * @job_cb_size: the actual size of the CB that we put on the queue.
2033e65e175bSOded Gabbay * @encaps_sig_wait_offset: encapsulated signals offset, which allow user
2034e65e175bSOded Gabbay * to wait on part of the reserved signals.
2035e65e175bSOded Gabbay * @is_kernel_allocated_cb: true if the CB handle we got from the user holds a
2036e65e175bSOded Gabbay * handle to a kernel-allocated CB object, false
2037e65e175bSOded Gabbay * otherwise (SRAM/DRAM/host address).
2038e65e175bSOded Gabbay * @contains_dma_pkt: whether the JOB contains at least one DMA packet. This
2039e65e175bSOded Gabbay * info is needed later, when adding the 2xMSG_PROT at the
2040e65e175bSOded Gabbay * end of the JOB, to know which barriers to put in the
2041e65e175bSOded Gabbay * MSG_PROT packets. Relevant only for GAUDI as GOYA doesn't
2042e65e175bSOded Gabbay * have streams so the engine can't be busy by another
2043e65e175bSOded Gabbay * stream.
2044e65e175bSOded Gabbay */
2045e65e175bSOded Gabbay struct hl_cs_job {
2046e65e175bSOded Gabbay struct list_head cs_node;
2047e65e175bSOded Gabbay struct hl_cs *cs;
2048e65e175bSOded Gabbay struct hl_cb *user_cb;
2049e65e175bSOded Gabbay struct hl_cb *patched_cb;
2050e65e175bSOded Gabbay struct work_struct finish_work;
2051e65e175bSOded Gabbay struct list_head userptr_list;
2052e65e175bSOded Gabbay struct list_head debugfs_list;
2053e65e175bSOded Gabbay struct kref refcount;
2054e65e175bSOded Gabbay enum hl_queue_type queue_type;
205575b6984eSOfir Bitton ktime_t timestamp;
2056e65e175bSOded Gabbay u32 id;
2057e65e175bSOded Gabbay u32 hw_queue_id;
2058e65e175bSOded Gabbay u32 user_cb_size;
2059e65e175bSOded Gabbay u32 job_cb_size;
2060e65e175bSOded Gabbay u32 encaps_sig_wait_offset;
2061e65e175bSOded Gabbay u8 is_kernel_allocated_cb;
2062e65e175bSOded Gabbay u8 contains_dma_pkt;
2063e65e175bSOded Gabbay };
2064e65e175bSOded Gabbay
2065e65e175bSOded Gabbay /**
2066e65e175bSOded Gabbay * struct hl_cs_parser - command submission parser properties.
2067e65e175bSOded Gabbay * @user_cb: the CB we got from the user.
2068e65e175bSOded Gabbay * @patched_cb: in case of patching, this is internal CB which is submitted on
2069e65e175bSOded Gabbay * the queue instead of the CB we got from the IOCTL.
2070e65e175bSOded Gabbay * @job_userptr_list: linked-list of userptr mappings that belong to the related
2071e65e175bSOded Gabbay * job and wait for completion.
2072e65e175bSOded Gabbay * @cs_sequence: the sequence number of the related CS.
2073e65e175bSOded Gabbay * @queue_type: the type of the H/W queue this job is submitted to.
2074e65e175bSOded Gabbay * @ctx_id: the ID of the context the related CS belongs to.
2075e65e175bSOded Gabbay * @hw_queue_id: the id of the H/W queue this job is submitted to.
2076e65e175bSOded Gabbay * @user_cb_size: the actual size of the CB we got from the user.
2077e65e175bSOded Gabbay * @patched_cb_size: the size of the CB after parsing.
2078e65e175bSOded Gabbay * @job_id: the id of the related job inside the related CS.
2079e65e175bSOded Gabbay * @is_kernel_allocated_cb: true if the CB handle we got from the user holds a
2080e65e175bSOded Gabbay * handle to a kernel-allocated CB object, false
2081e65e175bSOded Gabbay * otherwise (SRAM/DRAM/host address).
2082e65e175bSOded Gabbay * @contains_dma_pkt: whether the JOB contains at least one DMA packet. This
2083e65e175bSOded Gabbay * info is needed later, when adding the 2xMSG_PROT at the
2084e65e175bSOded Gabbay * end of the JOB, to know which barriers to put in the
2085e65e175bSOded Gabbay * MSG_PROT packets. Relevant only for GAUDI as GOYA doesn't
2086e65e175bSOded Gabbay * have streams so the engine can't be busy by another
2087e65e175bSOded Gabbay * stream.
2088e65e175bSOded Gabbay * @completion: true if we need completion for this CS.
2089e65e175bSOded Gabbay */
2090e65e175bSOded Gabbay struct hl_cs_parser {
2091e65e175bSOded Gabbay struct hl_cb *user_cb;
2092e65e175bSOded Gabbay struct hl_cb *patched_cb;
2093e65e175bSOded Gabbay struct list_head *job_userptr_list;
2094e65e175bSOded Gabbay u64 cs_sequence;
2095e65e175bSOded Gabbay enum hl_queue_type queue_type;
2096e65e175bSOded Gabbay u32 ctx_id;
2097e65e175bSOded Gabbay u32 hw_queue_id;
2098e65e175bSOded Gabbay u32 user_cb_size;
2099e65e175bSOded Gabbay u32 patched_cb_size;
2100e65e175bSOded Gabbay u8 job_id;
2101e65e175bSOded Gabbay u8 is_kernel_allocated_cb;
2102e65e175bSOded Gabbay u8 contains_dma_pkt;
2103e65e175bSOded Gabbay u8 completion;
2104e65e175bSOded Gabbay };
2105e65e175bSOded Gabbay
2106e65e175bSOded Gabbay /*
2107e65e175bSOded Gabbay * MEMORY STRUCTURE
2108e65e175bSOded Gabbay */
2109e65e175bSOded Gabbay
2110e65e175bSOded Gabbay /**
2111e65e175bSOded Gabbay * struct hl_vm_hash_node - hash element from virtual address to virtual
2112e65e175bSOded Gabbay * memory area descriptor (hl_vm_phys_pg_list or
2113e65e175bSOded Gabbay * hl_userptr).
2114e65e175bSOded Gabbay * @node: node to hang on the hash table in context object.
2115e65e175bSOded Gabbay * @vaddr: key virtual address.
2116e65e175bSOded Gabbay * @handle: memory handle for device memory allocation.
2117e65e175bSOded Gabbay * @ptr: value pointer (hl_vm_phys_pg_list or hl_userptr).
2118e65e175bSOded Gabbay * @export_cnt: number of exports from within the VA block.
2119e65e175bSOded Gabbay */
2120e65e175bSOded Gabbay struct hl_vm_hash_node {
2121e65e175bSOded Gabbay struct hlist_node node;
2122e65e175bSOded Gabbay u64 vaddr;
2123e65e175bSOded Gabbay u64 handle;
2124e65e175bSOded Gabbay void *ptr;
2125e65e175bSOded Gabbay int export_cnt;
2126e65e175bSOded Gabbay };
2127e65e175bSOded Gabbay
2128e65e175bSOded Gabbay /**
2129e65e175bSOded Gabbay * struct hl_vm_hw_block_list_node - list element from user virtual address to
2130e65e175bSOded Gabbay * HW block id.
2131e65e175bSOded Gabbay * @node: node to hang on the list in context object.
2132e65e175bSOded Gabbay * @ctx: the context this node belongs to.
2133e65e175bSOded Gabbay * @vaddr: virtual address of the HW block.
2134e65e175bSOded Gabbay * @block_size: size of the block.
2135e65e175bSOded Gabbay * @mapped_size: size of the block which is mapped. May change if partial un-mappings are done.
2136e65e175bSOded Gabbay * @id: HW block id (handle).
2137e65e175bSOded Gabbay */
2138e65e175bSOded Gabbay struct hl_vm_hw_block_list_node {
2139e65e175bSOded Gabbay struct list_head node;
2140e65e175bSOded Gabbay struct hl_ctx *ctx;
2141e65e175bSOded Gabbay unsigned long vaddr;
2142e65e175bSOded Gabbay u32 block_size;
2143e65e175bSOded Gabbay u32 mapped_size;
2144e65e175bSOded Gabbay u32 id;
2145e65e175bSOded Gabbay };
2146e65e175bSOded Gabbay
2147e65e175bSOded Gabbay /**
2148e65e175bSOded Gabbay * struct hl_vm_phys_pg_pack - physical page pack.
2149e65e175bSOded Gabbay * @vm_type: describes the type of the virtual area descriptor.
2150e65e175bSOded Gabbay * @pages: the physical page array.
2151e65e175bSOded Gabbay * @npages: num physical pages in the pack.
2152e65e175bSOded Gabbay * @total_size: total size of all the pages in this list.
2153e65e175bSOded Gabbay * @exported_size: buffer exported size.
2154e65e175bSOded Gabbay * @node: used to attach to deletion list that is used when all the allocations are cleared
2155e65e175bSOded Gabbay * at the teardown of the context.
2156e65e175bSOded Gabbay * @mapping_cnt: number of shared mappings.
2157e65e175bSOded Gabbay * @asid: the context related to this list.
2158e65e175bSOded Gabbay * @page_size: size of each page in the pack.
2159e65e175bSOded Gabbay * @flags: HL_MEM_* flags related to this list.
2160e65e175bSOded Gabbay * @handle: the provided handle related to this list.
2161e65e175bSOded Gabbay * @offset: offset from the first page.
2162e65e175bSOded Gabbay * @contiguous: is contiguous physical memory.
2163e65e175bSOded Gabbay * @created_from_userptr: is product of host virtual address.
2164e65e175bSOded Gabbay */
2165e65e175bSOded Gabbay struct hl_vm_phys_pg_pack {
2166e65e175bSOded Gabbay enum vm_type vm_type; /* must be first */
2167e65e175bSOded Gabbay u64 *pages;
2168e65e175bSOded Gabbay u64 npages;
2169e65e175bSOded Gabbay u64 total_size;
2170e65e175bSOded Gabbay u64 exported_size;
2171e65e175bSOded Gabbay struct list_head node;
2172e65e175bSOded Gabbay atomic_t mapping_cnt;
2173e65e175bSOded Gabbay u32 asid;
2174e65e175bSOded Gabbay u32 page_size;
2175e65e175bSOded Gabbay u32 flags;
2176e65e175bSOded Gabbay u32 handle;
2177e65e175bSOded Gabbay u32 offset;
2178e65e175bSOded Gabbay u8 contiguous;
2179e65e175bSOded Gabbay u8 created_from_userptr;
2180e65e175bSOded Gabbay };
2181e65e175bSOded Gabbay
2182e65e175bSOded Gabbay /**
2183e65e175bSOded Gabbay * struct hl_vm_va_block - virtual range block information.
2184e65e175bSOded Gabbay * @node: node to hang on the virtual range list in context object.
2185e65e175bSOded Gabbay * @start: virtual range start address.
2186e65e175bSOded Gabbay * @end: virtual range end address.
2187e65e175bSOded Gabbay * @size: virtual range size.
2188e65e175bSOded Gabbay */
2189e65e175bSOded Gabbay struct hl_vm_va_block {
2190e65e175bSOded Gabbay struct list_head node;
2191e65e175bSOded Gabbay u64 start;
2192e65e175bSOded Gabbay u64 end;
2193e65e175bSOded Gabbay u64 size;
2194e65e175bSOded Gabbay };
2195e65e175bSOded Gabbay
2196e65e175bSOded Gabbay /**
2197e65e175bSOded Gabbay * struct hl_vm - virtual memory manager for MMU.
2198e65e175bSOded Gabbay * @dram_pg_pool: pool for DRAM physical pages of 2MB.
2199e65e175bSOded Gabbay * @dram_pg_pool_refcount: reference counter for the pool usage.
2200e65e175bSOded Gabbay * @idr_lock: protects the phys_pg_list_handles.
2201e65e175bSOded Gabbay * @phys_pg_pack_handles: idr to hold all device allocations handles.
2202e65e175bSOded Gabbay * @init_done: whether initialization was done. We need this because VM
2203e65e175bSOded Gabbay * initialization might be skipped during device initialization.
2204e65e175bSOded Gabbay */
2205e65e175bSOded Gabbay struct hl_vm {
2206e65e175bSOded Gabbay struct gen_pool *dram_pg_pool;
2207e65e175bSOded Gabbay struct kref dram_pg_pool_refcount;
2208e65e175bSOded Gabbay spinlock_t idr_lock;
2209e65e175bSOded Gabbay struct idr phys_pg_pack_handles;
2210e65e175bSOded Gabbay u8 init_done;
2211e65e175bSOded Gabbay };
2212e65e175bSOded Gabbay
2213e65e175bSOded Gabbay
2214e65e175bSOded Gabbay /*
2215e65e175bSOded Gabbay * DEBUG, PROFILING STRUCTURE
2216e65e175bSOded Gabbay */
2217e65e175bSOded Gabbay
2218e65e175bSOded Gabbay /**
2219e65e175bSOded Gabbay * struct hl_debug_params - Coresight debug parameters.
2220e65e175bSOded Gabbay * @input: pointer to component specific input parameters.
2221e65e175bSOded Gabbay * @output: pointer to component specific output parameters.
2222e65e175bSOded Gabbay * @output_size: size of output buffer.
2223e65e175bSOded Gabbay * @reg_idx: relevant register ID.
2224e65e175bSOded Gabbay * @op: component operation to execute.
2225e65e175bSOded Gabbay * @enable: true if to enable component debugging, false otherwise.
2226e65e175bSOded Gabbay */
2227e65e175bSOded Gabbay struct hl_debug_params {
2228e65e175bSOded Gabbay void *input;
2229e65e175bSOded Gabbay void *output;
2230e65e175bSOded Gabbay u32 output_size;
2231e65e175bSOded Gabbay u32 reg_idx;
2232e65e175bSOded Gabbay u32 op;
2233e65e175bSOded Gabbay bool enable;
2234e65e175bSOded Gabbay };
2235e65e175bSOded Gabbay
2236e65e175bSOded Gabbay /**
2237e65e175bSOded Gabbay * struct hl_notifier_event - holds the notifier data structure
2238e65e175bSOded Gabbay * @eventfd: the event file descriptor to raise the notifications
2239e65e175bSOded Gabbay * @lock: mutex lock to protect the notifier data flows
2240e65e175bSOded Gabbay * @events_mask: indicates the bitmap events
2241e65e175bSOded Gabbay */
2242e65e175bSOded Gabbay struct hl_notifier_event {
2243e65e175bSOded Gabbay struct eventfd_ctx *eventfd;
2244e65e175bSOded Gabbay struct mutex lock;
2245e65e175bSOded Gabbay u64 events_mask;
2246e65e175bSOded Gabbay };
2247e65e175bSOded Gabbay
2248e65e175bSOded Gabbay /*
2249e65e175bSOded Gabbay * FILE PRIVATE STRUCTURE
2250e65e175bSOded Gabbay */
2251e65e175bSOded Gabbay
2252e65e175bSOded Gabbay /**
2253e65e175bSOded Gabbay * struct hl_fpriv - process information stored in FD private data.
2254e65e175bSOded Gabbay * @hdev: habanalabs device structure.
2255e65e175bSOded Gabbay * @filp: pointer to the given file structure.
2256e65e175bSOded Gabbay * @taskpid: current process ID.
2257e65e175bSOded Gabbay * @ctx: current executing context. TODO: remove for multiple ctx per process
2258e65e175bSOded Gabbay * @ctx_mgr: context manager to handle multiple context for this FD.
2259e65e175bSOded Gabbay * @mem_mgr: manager descriptor for memory exportable via mmap
2260e65e175bSOded Gabbay * @notifier_event: notifier eventfd towards user process
2261e65e175bSOded Gabbay * @debugfs_list: list of relevant ASIC debugfs.
2262e65e175bSOded Gabbay * @dev_node: node in the device list of file private data
2263e65e175bSOded Gabbay * @refcount: number of related contexts.
2264e65e175bSOded Gabbay * @restore_phase_mutex: lock for context switch and restore phase.
2265e65e175bSOded Gabbay * @ctx_lock: protects the pointer to current executing context pointer. TODO: remove for multiple
2266e65e175bSOded Gabbay * ctx per process.
2267e65e175bSOded Gabbay */
2268e65e175bSOded Gabbay struct hl_fpriv {
2269e65e175bSOded Gabbay struct hl_device *hdev;
2270e65e175bSOded Gabbay struct file *filp;
2271e65e175bSOded Gabbay struct pid *taskpid;
2272e65e175bSOded Gabbay struct hl_ctx *ctx;
2273e65e175bSOded Gabbay struct hl_ctx_mgr ctx_mgr;
2274e65e175bSOded Gabbay struct hl_mem_mgr mem_mgr;
2275e65e175bSOded Gabbay struct hl_notifier_event notifier_event;
2276e65e175bSOded Gabbay struct list_head debugfs_list;
2277e65e175bSOded Gabbay struct list_head dev_node;
2278e65e175bSOded Gabbay struct kref refcount;
2279e65e175bSOded Gabbay struct mutex restore_phase_mutex;
2280e65e175bSOded Gabbay struct mutex ctx_lock;
2281e65e175bSOded Gabbay };
2282e65e175bSOded Gabbay
2283e65e175bSOded Gabbay
2284e65e175bSOded Gabbay /*
2285e65e175bSOded Gabbay * DebugFS
2286e65e175bSOded Gabbay */
2287e65e175bSOded Gabbay
2288e65e175bSOded Gabbay /**
2289e65e175bSOded Gabbay * struct hl_info_list - debugfs file ops.
2290e65e175bSOded Gabbay * @name: file name.
2291e65e175bSOded Gabbay * @show: function to output information.
2292e65e175bSOded Gabbay * @write: function to write to the file.
2293e65e175bSOded Gabbay */
2294e65e175bSOded Gabbay struct hl_info_list {
2295e65e175bSOded Gabbay const char *name;
2296e65e175bSOded Gabbay int (*show)(struct seq_file *s, void *data);
2297e65e175bSOded Gabbay ssize_t (*write)(struct file *file, const char __user *buf,
2298e65e175bSOded Gabbay size_t count, loff_t *f_pos);
2299e65e175bSOded Gabbay };
2300e65e175bSOded Gabbay
2301e65e175bSOded Gabbay /**
2302e65e175bSOded Gabbay * struct hl_debugfs_entry - debugfs dentry wrapper.
2303e65e175bSOded Gabbay * @info_ent: dentry related ops.
2304e65e175bSOded Gabbay * @dev_entry: ASIC specific debugfs manager.
2305e65e175bSOded Gabbay */
2306e65e175bSOded Gabbay struct hl_debugfs_entry {
2307e65e175bSOded Gabbay const struct hl_info_list *info_ent;
2308e65e175bSOded Gabbay struct hl_dbg_device_entry *dev_entry;
2309e65e175bSOded Gabbay };
2310e65e175bSOded Gabbay
2311e65e175bSOded Gabbay /**
2312e65e175bSOded Gabbay * struct hl_dbg_device_entry - ASIC specific debugfs manager.
2313e65e175bSOded Gabbay * @root: root dentry.
2314e65e175bSOded Gabbay * @hdev: habanalabs device structure.
2315e65e175bSOded Gabbay * @entry_arr: array of available hl_debugfs_entry.
2316e65e175bSOded Gabbay * @file_list: list of available debugfs files.
2317e65e175bSOded Gabbay * @file_mutex: protects file_list.
2318e65e175bSOded Gabbay * @cb_list: list of available CBs.
2319e65e175bSOded Gabbay * @cb_spinlock: protects cb_list.
2320e65e175bSOded Gabbay * @cs_list: list of available CSs.
2321e65e175bSOded Gabbay * @cs_spinlock: protects cs_list.
2322e65e175bSOded Gabbay * @cs_job_list: list of available CB jobs.
2323e65e175bSOded Gabbay * @cs_job_spinlock: protects cs_job_list.
2324e65e175bSOded Gabbay * @userptr_list: list of available userptrs (virtual memory chunk descriptor).
2325e65e175bSOded Gabbay * @userptr_spinlock: protects userptr_list.
2326e65e175bSOded Gabbay * @ctx_mem_hash_list: list of available contexts with MMU mappings.
23277ffb5cedSKoby Elbaz * @ctx_mem_hash_mutex: protects list of available contexts with MMU mappings.
2328e65e175bSOded Gabbay * @data_dma_blob_desc: data DMA descriptor of blob.
2329e65e175bSOded Gabbay * @mon_dump_blob_desc: monitor dump descriptor of blob.
2330e65e175bSOded Gabbay * @state_dump: data of the system states in case of a bad cs.
2331e65e175bSOded Gabbay * @state_dump_sem: protects state_dump.
2332e65e175bSOded Gabbay * @addr: next address to read/write from/to in read/write32.
2333e65e175bSOded Gabbay * @mmu_addr: next virtual address to translate to physical address in mmu_show.
2334e65e175bSOded Gabbay * @mmu_cap_mask: mmu hw capability mask, to be used in mmu_ack_error.
2335e65e175bSOded Gabbay * @userptr_lookup: the target user ptr to look up for on demand.
2336e65e175bSOded Gabbay * @mmu_asid: ASID to use while translating in mmu_show.
2337e65e175bSOded Gabbay * @state_dump_head: index of the latest state dump
2338e65e175bSOded Gabbay * @i2c_bus: generic u8 debugfs file for bus value to use in i2c_data_read.
2339e65e175bSOded Gabbay * @i2c_addr: generic u8 debugfs file for address value to use in i2c_data_read.
2340e65e175bSOded Gabbay * @i2c_reg: generic u8 debugfs file for register value to use in i2c_data_read.
2341e65e175bSOded Gabbay * @i2c_len: generic u8 debugfs file for length value to use in i2c_data_read.
2342e65e175bSOded Gabbay */
2343e65e175bSOded Gabbay struct hl_dbg_device_entry {
2344e65e175bSOded Gabbay struct dentry *root;
2345e65e175bSOded Gabbay struct hl_device *hdev;
2346e65e175bSOded Gabbay struct hl_debugfs_entry *entry_arr;
2347e65e175bSOded Gabbay struct list_head file_list;
2348e65e175bSOded Gabbay struct mutex file_mutex;
2349e65e175bSOded Gabbay struct list_head cb_list;
2350e65e175bSOded Gabbay spinlock_t cb_spinlock;
2351e65e175bSOded Gabbay struct list_head cs_list;
2352e65e175bSOded Gabbay spinlock_t cs_spinlock;
2353e65e175bSOded Gabbay struct list_head cs_job_list;
2354e65e175bSOded Gabbay spinlock_t cs_job_spinlock;
2355e65e175bSOded Gabbay struct list_head userptr_list;
2356e65e175bSOded Gabbay spinlock_t userptr_spinlock;
2357e65e175bSOded Gabbay struct list_head ctx_mem_hash_list;
23587ffb5cedSKoby Elbaz struct mutex ctx_mem_hash_mutex;
2359e65e175bSOded Gabbay struct debugfs_blob_wrapper data_dma_blob_desc;
2360e65e175bSOded Gabbay struct debugfs_blob_wrapper mon_dump_blob_desc;
2361e65e175bSOded Gabbay char *state_dump[HL_STATE_DUMP_HIST_LEN];
2362e65e175bSOded Gabbay struct rw_semaphore state_dump_sem;
2363e65e175bSOded Gabbay u64 addr;
2364e65e175bSOded Gabbay u64 mmu_addr;
2365e65e175bSOded Gabbay u64 mmu_cap_mask;
2366e65e175bSOded Gabbay u64 userptr_lookup;
2367e65e175bSOded Gabbay u32 mmu_asid;
2368e65e175bSOded Gabbay u32 state_dump_head;
2369e65e175bSOded Gabbay u8 i2c_bus;
2370e65e175bSOded Gabbay u8 i2c_addr;
2371e65e175bSOded Gabbay u8 i2c_reg;
2372e65e175bSOded Gabbay u8 i2c_len;
2373e65e175bSOded Gabbay };
2374e65e175bSOded Gabbay
2375e65e175bSOded Gabbay /**
2376e65e175bSOded Gabbay * struct hl_hw_obj_name_entry - single hw object name, member of
2377e65e175bSOded Gabbay * hl_state_dump_specs
2378e65e175bSOded Gabbay * @node: link to the containing hash table
2379e65e175bSOded Gabbay * @name: hw object name
2380e65e175bSOded Gabbay * @id: object identifier
2381e65e175bSOded Gabbay */
2382e65e175bSOded Gabbay struct hl_hw_obj_name_entry {
2383e65e175bSOded Gabbay struct hlist_node node;
2384e65e175bSOded Gabbay const char *name;
2385e65e175bSOded Gabbay u32 id;
2386e65e175bSOded Gabbay };
2387e65e175bSOded Gabbay
2388e65e175bSOded Gabbay enum hl_state_dump_specs_props {
2389e65e175bSOded Gabbay SP_SYNC_OBJ_BASE_ADDR,
2390e65e175bSOded Gabbay SP_NEXT_SYNC_OBJ_ADDR,
2391e65e175bSOded Gabbay SP_SYNC_OBJ_AMOUNT,
2392e65e175bSOded Gabbay SP_MON_OBJ_WR_ADDR_LOW,
2393e65e175bSOded Gabbay SP_MON_OBJ_WR_ADDR_HIGH,
2394e65e175bSOded Gabbay SP_MON_OBJ_WR_DATA,
2395e65e175bSOded Gabbay SP_MON_OBJ_ARM_DATA,
2396e65e175bSOded Gabbay SP_MON_OBJ_STATUS,
2397e65e175bSOded Gabbay SP_MONITORS_AMOUNT,
2398e65e175bSOded Gabbay SP_TPC0_CMDQ,
2399e65e175bSOded Gabbay SP_TPC0_CFG_SO,
2400e65e175bSOded Gabbay SP_NEXT_TPC,
2401e65e175bSOded Gabbay SP_MME_CMDQ,
2402e65e175bSOded Gabbay SP_MME_CFG_SO,
2403e65e175bSOded Gabbay SP_NEXT_MME,
2404e65e175bSOded Gabbay SP_DMA_CMDQ,
2405e65e175bSOded Gabbay SP_DMA_CFG_SO,
2406e65e175bSOded Gabbay SP_DMA_QUEUES_OFFSET,
2407e65e175bSOded Gabbay SP_NUM_OF_MME_ENGINES,
2408e65e175bSOded Gabbay SP_SUB_MME_ENG_NUM,
2409e65e175bSOded Gabbay SP_NUM_OF_DMA_ENGINES,
2410e65e175bSOded Gabbay SP_NUM_OF_TPC_ENGINES,
2411e65e175bSOded Gabbay SP_ENGINE_NUM_OF_QUEUES,
2412e65e175bSOded Gabbay SP_ENGINE_NUM_OF_STREAMS,
2413e65e175bSOded Gabbay SP_ENGINE_NUM_OF_FENCES,
2414e65e175bSOded Gabbay SP_FENCE0_CNT_OFFSET,
2415e65e175bSOded Gabbay SP_FENCE0_RDATA_OFFSET,
2416e65e175bSOded Gabbay SP_CP_STS_OFFSET,
2417e65e175bSOded Gabbay SP_NUM_CORES,
2418e65e175bSOded Gabbay
2419e65e175bSOded Gabbay SP_MAX
2420e65e175bSOded Gabbay };
2421e65e175bSOded Gabbay
2422e65e175bSOded Gabbay enum hl_sync_engine_type {
2423e65e175bSOded Gabbay ENGINE_TPC,
2424e65e175bSOded Gabbay ENGINE_DMA,
2425e65e175bSOded Gabbay ENGINE_MME,
2426e65e175bSOded Gabbay };
2427e65e175bSOded Gabbay
2428e65e175bSOded Gabbay /**
2429e65e175bSOded Gabbay * struct hl_mon_state_dump - represents a state dump of a single monitor
2430e65e175bSOded Gabbay * @id: monitor id
2431e65e175bSOded Gabbay * @wr_addr_low: address monitor will write to, low bits
2432e65e175bSOded Gabbay * @wr_addr_high: address monitor will write to, high bits
2433e65e175bSOded Gabbay * @wr_data: data monitor will write
2434e65e175bSOded Gabbay * @arm_data: register value containing monitor configuration
2435e65e175bSOded Gabbay * @status: monitor status
2436e65e175bSOded Gabbay */
2437e65e175bSOded Gabbay struct hl_mon_state_dump {
2438e65e175bSOded Gabbay u32 id;
2439e65e175bSOded Gabbay u32 wr_addr_low;
2440e65e175bSOded Gabbay u32 wr_addr_high;
2441e65e175bSOded Gabbay u32 wr_data;
2442e65e175bSOded Gabbay u32 arm_data;
2443e65e175bSOded Gabbay u32 status;
2444e65e175bSOded Gabbay };
2445e65e175bSOded Gabbay
2446e65e175bSOded Gabbay /**
2447e65e175bSOded Gabbay * struct hl_sync_to_engine_map_entry - sync object id to engine mapping entry
2448e65e175bSOded Gabbay * @engine_type: type of the engine
2449e65e175bSOded Gabbay * @engine_id: id of the engine
2450e65e175bSOded Gabbay * @sync_id: id of the sync object
2451e65e175bSOded Gabbay */
2452e65e175bSOded Gabbay struct hl_sync_to_engine_map_entry {
2453e65e175bSOded Gabbay struct hlist_node node;
2454e65e175bSOded Gabbay enum hl_sync_engine_type engine_type;
2455e65e175bSOded Gabbay u32 engine_id;
2456e65e175bSOded Gabbay u32 sync_id;
2457e65e175bSOded Gabbay };
2458e65e175bSOded Gabbay
2459e65e175bSOded Gabbay /**
2460e65e175bSOded Gabbay * struct hl_sync_to_engine_map - maps sync object id to associated engine id
2461e65e175bSOded Gabbay * @tb: hash table containing the mapping, each element is of type
2462e65e175bSOded Gabbay * struct hl_sync_to_engine_map_entry
2463e65e175bSOded Gabbay */
2464e65e175bSOded Gabbay struct hl_sync_to_engine_map {
2465e65e175bSOded Gabbay DECLARE_HASHTABLE(tb, SYNC_TO_ENGINE_HASH_TABLE_BITS);
2466e65e175bSOded Gabbay };
2467e65e175bSOded Gabbay
2468e65e175bSOded Gabbay /**
2469e65e175bSOded Gabbay * struct hl_state_dump_specs_funcs - virtual functions used by the state dump
2470e65e175bSOded Gabbay * @gen_sync_to_engine_map: generate a hash map from sync obj id to its engine
2471e65e175bSOded Gabbay * @print_single_monitor: format monitor data as string
2472e65e175bSOded Gabbay * @monitor_valid: return true if given monitor dump is valid
2473e65e175bSOded Gabbay * @print_fences_single_engine: format fences data as string
2474e65e175bSOded Gabbay */
2475e65e175bSOded Gabbay struct hl_state_dump_specs_funcs {
2476e65e175bSOded Gabbay int (*gen_sync_to_engine_map)(struct hl_device *hdev,
2477e65e175bSOded Gabbay struct hl_sync_to_engine_map *map);
2478e65e175bSOded Gabbay int (*print_single_monitor)(char **buf, size_t *size, size_t *offset,
2479e65e175bSOded Gabbay struct hl_device *hdev,
2480e65e175bSOded Gabbay struct hl_mon_state_dump *mon);
2481e65e175bSOded Gabbay int (*monitor_valid)(struct hl_mon_state_dump *mon);
2482e65e175bSOded Gabbay int (*print_fences_single_engine)(struct hl_device *hdev,
2483e65e175bSOded Gabbay u64 base_offset,
2484e65e175bSOded Gabbay u64 status_base_offset,
2485e65e175bSOded Gabbay enum hl_sync_engine_type engine_type,
2486e65e175bSOded Gabbay u32 engine_id, char **buf,
2487e65e175bSOded Gabbay size_t *size, size_t *offset);
2488e65e175bSOded Gabbay };
2489e65e175bSOded Gabbay
2490e65e175bSOded Gabbay /**
2491e65e175bSOded Gabbay * struct hl_state_dump_specs - defines ASIC known hw objects names
2492e65e175bSOded Gabbay * @so_id_to_str_tb: sync objects names index table
2493e65e175bSOded Gabbay * @monitor_id_to_str_tb: monitors names index table
2494e65e175bSOded Gabbay * @funcs: virtual functions used for state dump
2495e65e175bSOded Gabbay * @sync_namager_names: readable names for sync manager if available (ex: N_E)
2496e65e175bSOded Gabbay * @props: pointer to a per asic const props array required for state dump
2497e65e175bSOded Gabbay */
2498e65e175bSOded Gabbay struct hl_state_dump_specs {
2499e65e175bSOded Gabbay DECLARE_HASHTABLE(so_id_to_str_tb, OBJ_NAMES_HASH_TABLE_BITS);
2500e65e175bSOded Gabbay DECLARE_HASHTABLE(monitor_id_to_str_tb, OBJ_NAMES_HASH_TABLE_BITS);
2501e65e175bSOded Gabbay struct hl_state_dump_specs_funcs funcs;
2502e65e175bSOded Gabbay const char * const *sync_namager_names;
2503e65e175bSOded Gabbay s64 *props;
2504e65e175bSOded Gabbay };
2505e65e175bSOded Gabbay
2506e65e175bSOded Gabbay
2507e65e175bSOded Gabbay /*
2508e65e175bSOded Gabbay * DEVICES
2509e65e175bSOded Gabbay */
2510e65e175bSOded Gabbay
2511*cd0a1835SKoby Elbaz #define HL_STR_MAX 64
2512e65e175bSOded Gabbay
2513e65e175bSOded Gabbay #define HL_DEV_STS_MAX (HL_DEVICE_STATUS_LAST + 1)
2514e65e175bSOded Gabbay
2515e65e175bSOded Gabbay /* Theoretical limit only. A single host can only contain up to 4 or 8 PCIe
2516e65e175bSOded Gabbay * x16 cards. In extreme cases, there are hosts that can accommodate 16 cards.
2517e65e175bSOded Gabbay */
2518e65e175bSOded Gabbay #define HL_MAX_MINORS 256
2519e65e175bSOded Gabbay
2520e65e175bSOded Gabbay /*
2521e65e175bSOded Gabbay * Registers read & write functions.
2522e65e175bSOded Gabbay */
2523e65e175bSOded Gabbay
2524e65e175bSOded Gabbay u32 hl_rreg(struct hl_device *hdev, u32 reg);
2525e65e175bSOded Gabbay void hl_wreg(struct hl_device *hdev, u32 reg, u32 val);
2526e65e175bSOded Gabbay
2527e65e175bSOded Gabbay #define RREG32(reg) hdev->asic_funcs->rreg(hdev, (reg))
2528e65e175bSOded Gabbay #define WREG32(reg, v) hdev->asic_funcs->wreg(hdev, (reg), (v))
2529e65e175bSOded Gabbay #define DREG32(reg) pr_info("REGISTER: " #reg " : 0x%08X\n", \
2530e65e175bSOded Gabbay hdev->asic_funcs->rreg(hdev, (reg)))
2531e65e175bSOded Gabbay
2532e65e175bSOded Gabbay #define WREG32_P(reg, val, mask) \
2533e65e175bSOded Gabbay do { \
2534e65e175bSOded Gabbay u32 tmp_ = RREG32(reg); \
2535e65e175bSOded Gabbay tmp_ &= (mask); \
2536e65e175bSOded Gabbay tmp_ |= ((val) & ~(mask)); \
2537e65e175bSOded Gabbay WREG32(reg, tmp_); \
2538e65e175bSOded Gabbay } while (0)
2539e65e175bSOded Gabbay #define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
2540e65e175bSOded Gabbay #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
2541e65e175bSOded Gabbay
2542e65e175bSOded Gabbay #define RMWREG32_SHIFTED(reg, val, mask) WREG32_P(reg, val, ~(mask))
2543e65e175bSOded Gabbay
2544e65e175bSOded Gabbay #define RMWREG32(reg, val, mask) RMWREG32_SHIFTED(reg, (val) << __ffs(mask), mask)
2545e65e175bSOded Gabbay
2546e65e175bSOded Gabbay #define RREG32_MASK(reg, mask) ((RREG32(reg) & mask) >> __ffs(mask))
2547e65e175bSOded Gabbay
2548e65e175bSOded Gabbay #define REG_FIELD_SHIFT(reg, field) reg##_##field##_SHIFT
2549e65e175bSOded Gabbay #define REG_FIELD_MASK(reg, field) reg##_##field##_MASK
2550e65e175bSOded Gabbay #define WREG32_FIELD(reg, offset, field, val) \
2551e65e175bSOded Gabbay WREG32(mm##reg + offset, (RREG32(mm##reg + offset) & \
2552e65e175bSOded Gabbay ~REG_FIELD_MASK(reg, field)) | \
2553e65e175bSOded Gabbay (val) << REG_FIELD_SHIFT(reg, field))
2554e65e175bSOded Gabbay
2555e65e175bSOded Gabbay /* Timeout should be longer when working with simulator but cap the
2556e65e175bSOded Gabbay * increased timeout to some maximum
2557e65e175bSOded Gabbay */
2558e65e175bSOded Gabbay #define hl_poll_timeout_common(hdev, addr, val, cond, sleep_us, timeout_us, elbi) \
2559e65e175bSOded Gabbay ({ \
2560e65e175bSOded Gabbay ktime_t __timeout; \
2561e65e175bSOded Gabbay u32 __elbi_read; \
2562e65e175bSOded Gabbay int __rc = 0; \
2563e65e175bSOded Gabbay __timeout = ktime_add_us(ktime_get(), timeout_us); \
2564e65e175bSOded Gabbay might_sleep_if(sleep_us); \
2565e65e175bSOded Gabbay for (;;) { \
2566e65e175bSOded Gabbay if (elbi) { \
2567e65e175bSOded Gabbay __rc = hl_pci_elbi_read(hdev, addr, &__elbi_read); \
2568e65e175bSOded Gabbay if (__rc) \
2569e65e175bSOded Gabbay break; \
2570e65e175bSOded Gabbay (val) = __elbi_read; \
2571e65e175bSOded Gabbay } else {\
2572e65e175bSOded Gabbay (val) = RREG32(lower_32_bits(addr)); \
2573e65e175bSOded Gabbay } \
2574e65e175bSOded Gabbay if (cond) \
2575e65e175bSOded Gabbay break; \
2576e65e175bSOded Gabbay if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) { \
2577e65e175bSOded Gabbay if (elbi) { \
2578e65e175bSOded Gabbay __rc = hl_pci_elbi_read(hdev, addr, &__elbi_read); \
2579e65e175bSOded Gabbay if (__rc) \
2580e65e175bSOded Gabbay break; \
2581e65e175bSOded Gabbay (val) = __elbi_read; \
2582e65e175bSOded Gabbay } else {\
2583e65e175bSOded Gabbay (val) = RREG32(lower_32_bits(addr)); \
2584e65e175bSOded Gabbay } \
2585e65e175bSOded Gabbay break; \
2586e65e175bSOded Gabbay } \
2587e65e175bSOded Gabbay if (sleep_us) \
2588e65e175bSOded Gabbay usleep_range((sleep_us >> 2) + 1, sleep_us); \
2589e65e175bSOded Gabbay } \
2590e65e175bSOded Gabbay __rc ? __rc : ((cond) ? 0 : -ETIMEDOUT); \
2591e65e175bSOded Gabbay })
2592e65e175bSOded Gabbay
2593e65e175bSOded Gabbay #define hl_poll_timeout(hdev, addr, val, cond, sleep_us, timeout_us) \
2594e65e175bSOded Gabbay hl_poll_timeout_common(hdev, addr, val, cond, sleep_us, timeout_us, false)
2595e65e175bSOded Gabbay
2596e65e175bSOded Gabbay #define hl_poll_timeout_elbi(hdev, addr, val, cond, sleep_us, timeout_us) \
2597e65e175bSOded Gabbay hl_poll_timeout_common(hdev, addr, val, cond, sleep_us, timeout_us, true)
2598e65e175bSOded Gabbay
2599e65e175bSOded Gabbay /*
2600e65e175bSOded Gabbay * poll array of register addresses.
2601e65e175bSOded Gabbay * condition is satisfied if all registers values match the expected value.
2602e65e175bSOded Gabbay * once some register in the array satisfies the condition it will not be polled again,
2603e65e175bSOded Gabbay * this is done both for efficiency and due to some registers are "clear on read".
2604e65e175bSOded Gabbay * TODO: use read from PCI bar in other places in the code (SW-91406)
2605e65e175bSOded Gabbay */
2606e65e175bSOded Gabbay #define hl_poll_reg_array_timeout_common(hdev, addr_arr, arr_size, expected_val, sleep_us, \
2607e65e175bSOded Gabbay timeout_us, elbi) \
2608e65e175bSOded Gabbay ({ \
2609e65e175bSOded Gabbay ktime_t __timeout; \
2610e65e175bSOded Gabbay u64 __elem_bitmask; \
2611e65e175bSOded Gabbay u32 __read_val; \
2612e65e175bSOded Gabbay u8 __arr_idx; \
2613e65e175bSOded Gabbay int __rc = 0; \
2614e65e175bSOded Gabbay \
2615e65e175bSOded Gabbay __timeout = ktime_add_us(ktime_get(), timeout_us); \
2616e65e175bSOded Gabbay might_sleep_if(sleep_us); \
2617e65e175bSOded Gabbay if (arr_size >= 64) \
2618e65e175bSOded Gabbay __rc = -EINVAL; \
2619e65e175bSOded Gabbay else \
2620e65e175bSOded Gabbay __elem_bitmask = BIT_ULL(arr_size) - 1; \
2621e65e175bSOded Gabbay for (;;) { \
2622e65e175bSOded Gabbay if (__rc) \
2623e65e175bSOded Gabbay break; \
2624e65e175bSOded Gabbay for (__arr_idx = 0; __arr_idx < (arr_size); __arr_idx++) { \
2625e65e175bSOded Gabbay if (!(__elem_bitmask & BIT_ULL(__arr_idx))) \
2626e65e175bSOded Gabbay continue; \
2627e65e175bSOded Gabbay if (elbi) { \
2628e65e175bSOded Gabbay __rc = hl_pci_elbi_read(hdev, (addr_arr)[__arr_idx], &__read_val); \
2629e65e175bSOded Gabbay if (__rc) \
2630e65e175bSOded Gabbay break; \
2631e65e175bSOded Gabbay } else { \
2632e65e175bSOded Gabbay __read_val = RREG32(lower_32_bits(addr_arr[__arr_idx])); \
2633e65e175bSOded Gabbay } \
2634e65e175bSOded Gabbay if (__read_val == (expected_val)) \
2635e65e175bSOded Gabbay __elem_bitmask &= ~BIT_ULL(__arr_idx); \
2636e65e175bSOded Gabbay } \
2637e65e175bSOded Gabbay if (__rc || (__elem_bitmask == 0)) \
2638e65e175bSOded Gabbay break; \
2639e65e175bSOded Gabbay if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) \
2640e65e175bSOded Gabbay break; \
2641e65e175bSOded Gabbay if (sleep_us) \
2642e65e175bSOded Gabbay usleep_range((sleep_us >> 2) + 1, sleep_us); \
2643e65e175bSOded Gabbay } \
2644e65e175bSOded Gabbay __rc ? __rc : ((__elem_bitmask == 0) ? 0 : -ETIMEDOUT); \
2645e65e175bSOded Gabbay })
2646e65e175bSOded Gabbay
2647e65e175bSOded Gabbay #define hl_poll_reg_array_timeout(hdev, addr_arr, arr_size, expected_val, sleep_us, \
2648e65e175bSOded Gabbay timeout_us) \
2649e65e175bSOded Gabbay hl_poll_reg_array_timeout_common(hdev, addr_arr, arr_size, expected_val, sleep_us, \
2650e65e175bSOded Gabbay timeout_us, false)
2651e65e175bSOded Gabbay
2652e65e175bSOded Gabbay #define hl_poll_reg_array_timeout_elbi(hdev, addr_arr, arr_size, expected_val, sleep_us, \
2653e65e175bSOded Gabbay timeout_us) \
2654e65e175bSOded Gabbay hl_poll_reg_array_timeout_common(hdev, addr_arr, arr_size, expected_val, sleep_us, \
2655e65e175bSOded Gabbay timeout_us, true)
2656e65e175bSOded Gabbay
2657e65e175bSOded Gabbay /*
2658e65e175bSOded Gabbay * address in this macro points always to a memory location in the
2659e65e175bSOded Gabbay * host's (server's) memory. That location is updated asynchronously
2660e65e175bSOded Gabbay * either by the direct access of the device or by another core.
2661e65e175bSOded Gabbay *
2662e65e175bSOded Gabbay * To work both in LE and BE architectures, we need to distinguish between the
2663e65e175bSOded Gabbay * two states (device or another core updates the memory location). Therefore,
2664e65e175bSOded Gabbay * if mem_written_by_device is true, the host memory being polled will be
2665e65e175bSOded Gabbay * updated directly by the device. If false, the host memory being polled will
2666e65e175bSOded Gabbay * be updated by host CPU. Required so host knows whether or not the memory
2667e65e175bSOded Gabbay * might need to be byte-swapped before returning value to caller.
2668e65e175bSOded Gabbay */
2669e65e175bSOded Gabbay #define hl_poll_timeout_memory(hdev, addr, val, cond, sleep_us, timeout_us, \
2670e65e175bSOded Gabbay mem_written_by_device) \
2671e65e175bSOded Gabbay ({ \
2672e65e175bSOded Gabbay ktime_t __timeout; \
267356921023SOded Gabbay \
2674e65e175bSOded Gabbay __timeout = ktime_add_us(ktime_get(), timeout_us); \
2675e65e175bSOded Gabbay might_sleep_if(sleep_us); \
2676e65e175bSOded Gabbay for (;;) { \
2677e65e175bSOded Gabbay /* Verify we read updates done by other cores or by device */ \
2678e65e175bSOded Gabbay mb(); \
2679e65e175bSOded Gabbay (val) = *((u32 *)(addr)); \
2680e65e175bSOded Gabbay if (mem_written_by_device) \
2681e65e175bSOded Gabbay (val) = le32_to_cpu(*(__le32 *) &(val)); \
2682e65e175bSOded Gabbay if (cond) \
2683e65e175bSOded Gabbay break; \
2684e65e175bSOded Gabbay if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) { \
2685e65e175bSOded Gabbay (val) = *((u32 *)(addr)); \
2686e65e175bSOded Gabbay if (mem_written_by_device) \
2687e65e175bSOded Gabbay (val) = le32_to_cpu(*(__le32 *) &(val)); \
2688e65e175bSOded Gabbay break; \
2689e65e175bSOded Gabbay } \
2690e65e175bSOded Gabbay if (sleep_us) \
2691e65e175bSOded Gabbay usleep_range((sleep_us >> 2) + 1, sleep_us); \
2692e65e175bSOded Gabbay } \
2693e65e175bSOded Gabbay (cond) ? 0 : -ETIMEDOUT; \
2694e65e175bSOded Gabbay })
2695e65e175bSOded Gabbay
2696e65e175bSOded Gabbay #define HL_USR_MAPPED_BLK_INIT(blk, base, sz) \
2697e65e175bSOded Gabbay ({ \
2698e65e175bSOded Gabbay struct user_mapped_block *p = blk; \
2699e65e175bSOded Gabbay \
2700e65e175bSOded Gabbay p->address = base; \
2701e65e175bSOded Gabbay p->size = sz; \
2702e65e175bSOded Gabbay })
2703e65e175bSOded Gabbay
27049a7d530aSOfir Bitton #define HL_USR_INTR_STRUCT_INIT(usr_intr, hdev, intr_id, intr_type) \
2705e65e175bSOded Gabbay ({ \
2706e65e175bSOded Gabbay usr_intr.hdev = hdev; \
2707e65e175bSOded Gabbay usr_intr.interrupt_id = intr_id; \
27089a7d530aSOfir Bitton usr_intr.type = intr_type; \
2709e65e175bSOded Gabbay INIT_LIST_HEAD(&usr_intr.wait_list_head); \
2710e65e175bSOded Gabbay spin_lock_init(&usr_intr.wait_list_lock); \
2711e65e175bSOded Gabbay })
2712e65e175bSOded Gabbay
2713e65e175bSOded Gabbay struct hwmon_chip_info;
2714e65e175bSOded Gabbay
2715e65e175bSOded Gabbay /**
2716e65e175bSOded Gabbay * struct hl_device_reset_work - reset work wrapper.
2717e65e175bSOded Gabbay * @reset_work: reset work to be done.
2718e65e175bSOded Gabbay * @hdev: habanalabs device structure.
2719e65e175bSOded Gabbay * @flags: reset flags.
2720e65e175bSOded Gabbay */
2721e65e175bSOded Gabbay struct hl_device_reset_work {
2722e65e175bSOded Gabbay struct delayed_work reset_work;
2723e65e175bSOded Gabbay struct hl_device *hdev;
2724e65e175bSOded Gabbay u32 flags;
2725e65e175bSOded Gabbay };
2726e65e175bSOded Gabbay
2727e65e175bSOded Gabbay /**
2728e65e175bSOded Gabbay * struct hl_mmu_hr_pgt_priv - used for holding per-device mmu host-resident
2729e65e175bSOded Gabbay * page-table internal information.
2730e65e175bSOded Gabbay * @mmu_pgt_pool: pool of page tables used by a host-resident MMU for
2731e65e175bSOded Gabbay * allocating hops.
2732e65e175bSOded Gabbay * @mmu_asid_hop0: per-ASID array of host-resident hop0 tables.
2733e65e175bSOded Gabbay */
2734e65e175bSOded Gabbay struct hl_mmu_hr_priv {
2735e65e175bSOded Gabbay struct gen_pool *mmu_pgt_pool;
2736e65e175bSOded Gabbay struct pgt_info *mmu_asid_hop0;
2737e65e175bSOded Gabbay };
2738e65e175bSOded Gabbay
2739e65e175bSOded Gabbay /**
2740e65e175bSOded Gabbay * struct hl_mmu_dr_pgt_priv - used for holding per-device mmu device-resident
2741e65e175bSOded Gabbay * page-table internal information.
2742e65e175bSOded Gabbay * @mmu_pgt_pool: pool of page tables used by MMU for allocating hops.
2743e65e175bSOded Gabbay * @mmu_shadow_hop0: shadow array of hop0 tables.
2744e65e175bSOded Gabbay */
2745e65e175bSOded Gabbay struct hl_mmu_dr_priv {
2746e65e175bSOded Gabbay struct gen_pool *mmu_pgt_pool;
2747e65e175bSOded Gabbay void *mmu_shadow_hop0;
2748e65e175bSOded Gabbay };
2749e65e175bSOded Gabbay
2750e65e175bSOded Gabbay /**
2751e65e175bSOded Gabbay * struct hl_mmu_priv - used for holding per-device mmu internal information.
2752e65e175bSOded Gabbay * @dr: information on the device-resident MMU, when exists.
2753e65e175bSOded Gabbay * @hr: information on the host-resident MMU, when exists.
2754e65e175bSOded Gabbay */
2755e65e175bSOded Gabbay struct hl_mmu_priv {
2756e65e175bSOded Gabbay struct hl_mmu_dr_priv dr;
2757e65e175bSOded Gabbay struct hl_mmu_hr_priv hr;
2758e65e175bSOded Gabbay };
2759e65e175bSOded Gabbay
2760e65e175bSOded Gabbay /**
2761e65e175bSOded Gabbay * struct hl_mmu_per_hop_info - A structure describing one TLB HOP and its entry
2762e65e175bSOded Gabbay * that was created in order to translate a virtual address to a
2763e65e175bSOded Gabbay * physical one.
2764e65e175bSOded Gabbay * @hop_addr: The address of the hop.
2765e65e175bSOded Gabbay * @hop_pte_addr: The address of the hop entry.
2766e65e175bSOded Gabbay * @hop_pte_val: The value in the hop entry.
2767e65e175bSOded Gabbay */
2768e65e175bSOded Gabbay struct hl_mmu_per_hop_info {
2769e65e175bSOded Gabbay u64 hop_addr;
2770e65e175bSOded Gabbay u64 hop_pte_addr;
2771e65e175bSOded Gabbay u64 hop_pte_val;
2772e65e175bSOded Gabbay };
2773e65e175bSOded Gabbay
2774e65e175bSOded Gabbay /**
2775e65e175bSOded Gabbay * struct hl_mmu_hop_info - A structure describing the TLB hops and their
2776e65e175bSOded Gabbay * hop-entries that were created in order to translate a virtual address to a
2777e65e175bSOded Gabbay * physical one.
2778e65e175bSOded Gabbay * @scrambled_vaddr: The value of the virtual address after scrambling. This
2779e65e175bSOded Gabbay * address replaces the original virtual-address when mapped
2780e65e175bSOded Gabbay * in the MMU tables.
2781e65e175bSOded Gabbay * @unscrambled_paddr: The un-scrambled physical address.
2782e65e175bSOded Gabbay * @hop_info: Array holding the per-hop information used for the translation.
2783e65e175bSOded Gabbay * @used_hops: The number of hops used for the translation.
2784e65e175bSOded Gabbay * @range_type: virtual address range type.
2785e65e175bSOded Gabbay */
2786e65e175bSOded Gabbay struct hl_mmu_hop_info {
2787e65e175bSOded Gabbay u64 scrambled_vaddr;
2788e65e175bSOded Gabbay u64 unscrambled_paddr;
2789e65e175bSOded Gabbay struct hl_mmu_per_hop_info hop_info[MMU_ARCH_6_HOPS];
2790e65e175bSOded Gabbay u32 used_hops;
2791e65e175bSOded Gabbay enum hl_va_range_type range_type;
2792e65e175bSOded Gabbay };
2793e65e175bSOded Gabbay
2794e65e175bSOded Gabbay /**
2795e65e175bSOded Gabbay * struct hl_hr_mmu_funcs - Device related host resident MMU functions.
2796e65e175bSOded Gabbay * @get_hop0_pgt_info: get page table info structure for HOP0.
2797e65e175bSOded Gabbay * @get_pgt_info: get page table info structure for HOP other than HOP0.
2798e65e175bSOded Gabbay * @add_pgt_info: add page table info structure to hash.
2799e65e175bSOded Gabbay * @get_tlb_mapping_params: get mapping parameters needed for getting TLB info for specific mapping.
2800e65e175bSOded Gabbay */
2801e65e175bSOded Gabbay struct hl_hr_mmu_funcs {
2802e65e175bSOded Gabbay struct pgt_info *(*get_hop0_pgt_info)(struct hl_ctx *ctx);
2803e65e175bSOded Gabbay struct pgt_info *(*get_pgt_info)(struct hl_ctx *ctx, u64 phys_hop_addr);
2804e65e175bSOded Gabbay void (*add_pgt_info)(struct hl_ctx *ctx, struct pgt_info *pgt_info, dma_addr_t phys_addr);
2805e65e175bSOded Gabbay int (*get_tlb_mapping_params)(struct hl_device *hdev, struct hl_mmu_properties **mmu_prop,
2806e65e175bSOded Gabbay struct hl_mmu_hop_info *hops,
2807e65e175bSOded Gabbay u64 virt_addr, bool *is_huge);
2808e65e175bSOded Gabbay };
2809e65e175bSOded Gabbay
2810e65e175bSOded Gabbay /**
2811e65e175bSOded Gabbay * struct hl_mmu_funcs - Device related MMU functions.
2812e65e175bSOded Gabbay * @init: initialize the MMU module.
2813e65e175bSOded Gabbay * @fini: release the MMU module.
2814e65e175bSOded Gabbay * @ctx_init: Initialize a context for using the MMU module.
2815e65e175bSOded Gabbay * @ctx_fini: disable a ctx from using the mmu module.
2816e65e175bSOded Gabbay * @map: maps a virtual address to physical address for a context.
2817e65e175bSOded Gabbay * @unmap: unmap a virtual address of a context.
2818e65e175bSOded Gabbay * @flush: flush all writes from all cores to reach device MMU.
2819e65e175bSOded Gabbay * @swap_out: marks all mapping of the given context as swapped out.
2820e65e175bSOded Gabbay * @swap_in: marks all mapping of the given context as swapped in.
2821e65e175bSOded Gabbay * @get_tlb_info: returns the list of hops and hop-entries used that were
2822e65e175bSOded Gabbay * created in order to translate the giver virtual address to a
2823e65e175bSOded Gabbay * physical one.
2824e65e175bSOded Gabbay * @hr_funcs: functions specific to host resident MMU.
2825e65e175bSOded Gabbay */
2826e65e175bSOded Gabbay struct hl_mmu_funcs {
2827e65e175bSOded Gabbay int (*init)(struct hl_device *hdev);
2828e65e175bSOded Gabbay void (*fini)(struct hl_device *hdev);
2829e65e175bSOded Gabbay int (*ctx_init)(struct hl_ctx *ctx);
2830e65e175bSOded Gabbay void (*ctx_fini)(struct hl_ctx *ctx);
2831e65e175bSOded Gabbay int (*map)(struct hl_ctx *ctx, u64 virt_addr, u64 phys_addr, u32 page_size,
2832e65e175bSOded Gabbay bool is_dram_addr);
2833e65e175bSOded Gabbay int (*unmap)(struct hl_ctx *ctx, u64 virt_addr, bool is_dram_addr);
2834e65e175bSOded Gabbay void (*flush)(struct hl_ctx *ctx);
2835e65e175bSOded Gabbay void (*swap_out)(struct hl_ctx *ctx);
2836e65e175bSOded Gabbay void (*swap_in)(struct hl_ctx *ctx);
2837e65e175bSOded Gabbay int (*get_tlb_info)(struct hl_ctx *ctx, u64 virt_addr, struct hl_mmu_hop_info *hops);
2838e65e175bSOded Gabbay struct hl_hr_mmu_funcs hr_funcs;
2839e65e175bSOded Gabbay };
2840e65e175bSOded Gabbay
2841e65e175bSOded Gabbay /**
2842e65e175bSOded Gabbay * struct hl_prefetch_work - prefetch work structure handler
2843e65e175bSOded Gabbay * @prefetch_work: actual work struct.
2844e65e175bSOded Gabbay * @ctx: compute context.
2845e65e175bSOded Gabbay * @va: virtual address to pre-fetch.
2846e65e175bSOded Gabbay * @size: pre-fetch size.
2847e65e175bSOded Gabbay * @flags: operation flags.
2848e65e175bSOded Gabbay * @asid: ASID for maintenance operation.
2849e65e175bSOded Gabbay */
2850e65e175bSOded Gabbay struct hl_prefetch_work {
2851e65e175bSOded Gabbay struct work_struct prefetch_work;
2852e65e175bSOded Gabbay struct hl_ctx *ctx;
2853e65e175bSOded Gabbay u64 va;
2854e65e175bSOded Gabbay u64 size;
2855e65e175bSOded Gabbay u32 flags;
2856e65e175bSOded Gabbay u32 asid;
2857e65e175bSOded Gabbay };
2858e65e175bSOded Gabbay
2859e65e175bSOded Gabbay /*
2860e65e175bSOded Gabbay * number of user contexts allowed to call wait_for_multi_cs ioctl in
2861e65e175bSOded Gabbay * parallel
2862e65e175bSOded Gabbay */
2863e65e175bSOded Gabbay #define MULTI_CS_MAX_USER_CTX 2
2864e65e175bSOded Gabbay
2865e65e175bSOded Gabbay /**
2866e65e175bSOded Gabbay * struct multi_cs_completion - multi CS wait completion.
2867e65e175bSOded Gabbay * @completion: completion of any of the CS in the list
2868e65e175bSOded Gabbay * @lock: spinlock for the completion structure
2869e65e175bSOded Gabbay * @timestamp: timestamp for the multi-CS completion
2870e65e175bSOded Gabbay * @stream_master_qid_map: bitmap of all stream masters on which the multi-CS
2871e65e175bSOded Gabbay * is waiting
2872e65e175bSOded Gabbay * @used: 1 if in use, otherwise 0
2873e65e175bSOded Gabbay */
2874e65e175bSOded Gabbay struct multi_cs_completion {
2875e65e175bSOded Gabbay struct completion completion;
2876e65e175bSOded Gabbay spinlock_t lock;
2877e65e175bSOded Gabbay s64 timestamp;
2878e65e175bSOded Gabbay u32 stream_master_qid_map;
2879e65e175bSOded Gabbay u8 used;
2880e65e175bSOded Gabbay };
2881e65e175bSOded Gabbay
2882e65e175bSOded Gabbay /**
2883e65e175bSOded Gabbay * struct multi_cs_data - internal data for multi CS call
2884e65e175bSOded Gabbay * @ctx: pointer to the context structure
2885e65e175bSOded Gabbay * @fence_arr: array of fences of all CSs
2886e65e175bSOded Gabbay * @seq_arr: array of CS sequence numbers
2887e65e175bSOded Gabbay * @timeout_jiffies: timeout in jiffies for waiting for CS to complete
2888e65e175bSOded Gabbay * @timestamp: timestamp of first completed CS
2889e65e175bSOded Gabbay * @wait_status: wait for CS status
2890e65e175bSOded Gabbay * @completion_bitmap: bitmap of completed CSs (1- completed, otherwise 0)
2891e65e175bSOded Gabbay * @arr_len: fence_arr and seq_arr array length
2892e65e175bSOded Gabbay * @gone_cs: indication of gone CS (1- there was gone CS, otherwise 0)
2893e65e175bSOded Gabbay * @update_ts: update timestamp. 1- update the timestamp, otherwise 0.
2894e65e175bSOded Gabbay */
2895e65e175bSOded Gabbay struct multi_cs_data {
2896e65e175bSOded Gabbay struct hl_ctx *ctx;
2897e65e175bSOded Gabbay struct hl_fence **fence_arr;
2898e65e175bSOded Gabbay u64 *seq_arr;
2899e65e175bSOded Gabbay s64 timeout_jiffies;
2900e65e175bSOded Gabbay s64 timestamp;
2901e65e175bSOded Gabbay long wait_status;
2902e65e175bSOded Gabbay u32 completion_bitmap;
2903e65e175bSOded Gabbay u8 arr_len;
2904e65e175bSOded Gabbay u8 gone_cs;
2905e65e175bSOded Gabbay u8 update_ts;
2906e65e175bSOded Gabbay };
2907e65e175bSOded Gabbay
2908e65e175bSOded Gabbay /**
2909e65e175bSOded Gabbay * struct hl_clk_throttle_timestamp - current/last clock throttling timestamp
2910e65e175bSOded Gabbay * @start: timestamp taken when 'start' event is received in driver
2911e65e175bSOded Gabbay * @end: timestamp taken when 'end' event is received in driver
2912e65e175bSOded Gabbay */
2913e65e175bSOded Gabbay struct hl_clk_throttle_timestamp {
2914e65e175bSOded Gabbay ktime_t start;
2915e65e175bSOded Gabbay ktime_t end;
2916e65e175bSOded Gabbay };
2917e65e175bSOded Gabbay
2918e65e175bSOded Gabbay /**
2919e65e175bSOded Gabbay * struct hl_clk_throttle - keeps current/last clock throttling timestamps
2920e65e175bSOded Gabbay * @timestamp: timestamp taken by driver and firmware, index 0 refers to POWER
2921e65e175bSOded Gabbay * index 1 refers to THERMAL
2922e65e175bSOded Gabbay * @lock: protects this structure as it can be accessed from both event queue
2923e65e175bSOded Gabbay * context and info_ioctl context
2924e65e175bSOded Gabbay * @current_reason: bitmask represents the current clk throttling reasons
2925e65e175bSOded Gabbay * @aggregated_reason: bitmask represents aggregated clk throttling reasons since driver load
2926e65e175bSOded Gabbay */
2927e65e175bSOded Gabbay struct hl_clk_throttle {
2928e65e175bSOded Gabbay struct hl_clk_throttle_timestamp timestamp[HL_CLK_THROTTLE_TYPE_MAX];
2929e65e175bSOded Gabbay struct mutex lock;
2930e65e175bSOded Gabbay u32 current_reason;
2931e65e175bSOded Gabbay u32 aggregated_reason;
2932e65e175bSOded Gabbay };
2933e65e175bSOded Gabbay
2934e65e175bSOded Gabbay /**
2935e65e175bSOded Gabbay * struct user_mapped_block - describes a hw block allowed to be mmapped by user
2936e65e175bSOded Gabbay * @address: physical HW block address
2937e65e175bSOded Gabbay * @size: allowed size for mmap
2938e65e175bSOded Gabbay */
2939e65e175bSOded Gabbay struct user_mapped_block {
2940e65e175bSOded Gabbay u32 address;
2941e65e175bSOded Gabbay u32 size;
2942e65e175bSOded Gabbay };
2943e65e175bSOded Gabbay
2944e65e175bSOded Gabbay /**
2945e65e175bSOded Gabbay * struct cs_timeout_info - info of last CS timeout occurred.
2946e65e175bSOded Gabbay * @timestamp: CS timeout timestamp.
2947e65e175bSOded Gabbay * @write_enable: if set writing to CS parameters in the structure is enabled. otherwise - disabled,
2948e65e175bSOded Gabbay * so the first (root cause) CS timeout will not be overwritten.
2949e65e175bSOded Gabbay * @seq: CS timeout sequence number.
2950e65e175bSOded Gabbay */
2951e65e175bSOded Gabbay struct cs_timeout_info {
2952e65e175bSOded Gabbay ktime_t timestamp;
2953e65e175bSOded Gabbay atomic_t write_enable;
2954e65e175bSOded Gabbay u64 seq;
2955e65e175bSOded Gabbay };
2956e65e175bSOded Gabbay
2957e65e175bSOded Gabbay #define MAX_QMAN_STREAMS_INFO 4
2958e65e175bSOded Gabbay #define OPCODE_INFO_MAX_ADDR_SIZE 8
2959e65e175bSOded Gabbay /**
2960e65e175bSOded Gabbay * struct undefined_opcode_info - info about last undefined opcode error
2961e65e175bSOded Gabbay * @timestamp: timestamp of the undefined opcode error
2962e65e175bSOded Gabbay * @cb_addr_streams: CB addresses (per stream) that are currently exists in the PQ
2963e65e175bSOded Gabbay * entries. In case all streams array entries are
2964e65e175bSOded Gabbay * filled with values, it means the execution was in Lower-CP.
2965e65e175bSOded Gabbay * @cq_addr: the address of the current handled command buffer
2966e65e175bSOded Gabbay * @cq_size: the size of the current handled command buffer
2967e65e175bSOded Gabbay * @cb_addr_streams_len: num of streams - actual len of cb_addr_streams array.
2968e65e175bSOded Gabbay * should be equal to 1 in case of undefined opcode
2969e65e175bSOded Gabbay * in Upper-CP (specific stream) and equal to 4 in case
2970e65e175bSOded Gabbay * of undefined opcode in Lower-CP.
2971e65e175bSOded Gabbay * @engine_id: engine-id that the error occurred on
2972e65e175bSOded Gabbay * @stream_id: the stream id the error occurred on. In case the stream equals to
2973e65e175bSOded Gabbay * MAX_QMAN_STREAMS_INFO it means the error occurred on a Lower-CP.
2974e65e175bSOded Gabbay * @write_enable: if set, writing to undefined opcode parameters in the structure
2975e65e175bSOded Gabbay * is enable so the first (root cause) undefined opcode will not be
2976e65e175bSOded Gabbay * overwritten.
2977e65e175bSOded Gabbay */
2978e65e175bSOded Gabbay struct undefined_opcode_info {
2979e65e175bSOded Gabbay ktime_t timestamp;
2980e65e175bSOded Gabbay u64 cb_addr_streams[MAX_QMAN_STREAMS_INFO][OPCODE_INFO_MAX_ADDR_SIZE];
2981e65e175bSOded Gabbay u64 cq_addr;
2982e65e175bSOded Gabbay u32 cq_size;
2983e65e175bSOded Gabbay u32 cb_addr_streams_len;
2984e65e175bSOded Gabbay u32 engine_id;
2985e65e175bSOded Gabbay u32 stream_id;
2986e65e175bSOded Gabbay bool write_enable;
2987e65e175bSOded Gabbay };
2988e65e175bSOded Gabbay
2989e65e175bSOded Gabbay /**
299078baccbdSKoby Elbaz * struct page_fault_info - page fault information.
299178baccbdSKoby Elbaz * @page_fault: holds information collected during a page fault.
2992e65e175bSOded Gabbay * @user_mappings: buffer containing user mappings.
2993e65e175bSOded Gabbay * @num_of_user_mappings: number of user mappings.
299478baccbdSKoby Elbaz * @page_fault_detected: if set as 1, then a page-fault was discovered for the
299578baccbdSKoby Elbaz * first time after the driver has finished booting-up.
299678baccbdSKoby Elbaz * Since we're looking for the page-fault's root cause,
299778baccbdSKoby Elbaz * we don't care of the others that might follow it-
299878baccbdSKoby Elbaz * so once changed to 1, it will remain that way.
2999571d1a72SKoby Elbaz * @page_fault_info_available: indicates that a page fault info is now available.
3000e65e175bSOded Gabbay */
3001e65e175bSOded Gabbay struct page_fault_info {
300278baccbdSKoby Elbaz struct hl_page_fault_info page_fault;
3003e65e175bSOded Gabbay struct hl_user_mapping *user_mappings;
3004e65e175bSOded Gabbay u64 num_of_user_mappings;
300578baccbdSKoby Elbaz atomic_t page_fault_detected;
3006571d1a72SKoby Elbaz bool page_fault_info_available;
300778baccbdSKoby Elbaz };
300878baccbdSKoby Elbaz
300978baccbdSKoby Elbaz /**
301078baccbdSKoby Elbaz * struct razwi_info - RAZWI information.
301178baccbdSKoby Elbaz * @razwi: holds information collected during a RAZWI
301278baccbdSKoby Elbaz * @razwi_detected: if set as 1, then a RAZWI was discovered for the
301378baccbdSKoby Elbaz * first time after the driver has finished booting-up.
301478baccbdSKoby Elbaz * Since we're looking for the RAZWI's root cause,
301578baccbdSKoby Elbaz * we don't care of the others that might follow it-
301678baccbdSKoby Elbaz * so once changed to 1, it will remain that way.
3017571d1a72SKoby Elbaz * @razwi_info_available: indicates that a RAZWI info is now available.
301878baccbdSKoby Elbaz */
301978baccbdSKoby Elbaz struct razwi_info {
302078baccbdSKoby Elbaz struct hl_info_razwi_event razwi;
302178baccbdSKoby Elbaz atomic_t razwi_detected;
3022571d1a72SKoby Elbaz bool razwi_info_available;
3023e65e175bSOded Gabbay };
3024e65e175bSOded Gabbay
3025e65e175bSOded Gabbay /**
3026313e9f63SMoti Haimovski * struct hw_err_info - HW error information.
3027313e9f63SMoti Haimovski * @event: holds information on the event.
3028313e9f63SMoti Haimovski * @event_detected: if set as 1, then a HW event was discovered for the
3029313e9f63SMoti Haimovski * first time after the driver has finished booting-up.
3030313e9f63SMoti Haimovski * currently we assume that only fatal events (that require hard-reset) are
3031313e9f63SMoti Haimovski * reported so we don't care of the others that might follow it.
3032313e9f63SMoti Haimovski * so once changed to 1, it will remain that way.
3033313e9f63SMoti Haimovski * TODO: support multiple events.
3034313e9f63SMoti Haimovski * @event_info_available: indicates that a HW event info is now available.
3035313e9f63SMoti Haimovski */
3036313e9f63SMoti Haimovski struct hw_err_info {
3037313e9f63SMoti Haimovski struct hl_info_hw_err_event event;
3038313e9f63SMoti Haimovski atomic_t event_detected;
3039313e9f63SMoti Haimovski bool event_info_available;
3040313e9f63SMoti Haimovski };
3041313e9f63SMoti Haimovski
3042313e9f63SMoti Haimovski /**
3043313e9f63SMoti Haimovski * struct fw_err_info - FW error information.
3044313e9f63SMoti Haimovski * @event: holds information on the event.
3045313e9f63SMoti Haimovski * @event_detected: if set as 1, then a FW event was discovered for the
3046313e9f63SMoti Haimovski * first time after the driver has finished booting-up.
3047313e9f63SMoti Haimovski * currently we assume that only fatal events (that require hard-reset) are
3048313e9f63SMoti Haimovski * reported so we don't care of the others that might follow it.
3049313e9f63SMoti Haimovski * so once changed to 1, it will remain that way.
3050313e9f63SMoti Haimovski * TODO: support multiple events.
3051313e9f63SMoti Haimovski * @event_info_available: indicates that a HW event info is now available.
3052313e9f63SMoti Haimovski */
3053313e9f63SMoti Haimovski struct fw_err_info {
3054313e9f63SMoti Haimovski struct hl_info_fw_err_event event;
3055313e9f63SMoti Haimovski atomic_t event_detected;
3056313e9f63SMoti Haimovski bool event_info_available;
3057313e9f63SMoti Haimovski };
3058313e9f63SMoti Haimovski
3059313e9f63SMoti Haimovski /**
3060e65e175bSOded Gabbay * struct hl_error_info - holds information collected during an error.
3061e65e175bSOded Gabbay * @cs_timeout: CS timeout error information.
306278baccbdSKoby Elbaz * @razwi_info: RAZWI information.
306378baccbdSKoby Elbaz * @undef_opcode: undefined opcode information.
306478baccbdSKoby Elbaz * @page_fault_info: page fault information.
3065313e9f63SMoti Haimovski * @hw_err: (fatal) hardware error information.
3066313e9f63SMoti Haimovski * @fw_err: firmware error information.
3067e65e175bSOded Gabbay */
3068e65e175bSOded Gabbay struct hl_error_info {
3069e65e175bSOded Gabbay struct cs_timeout_info cs_timeout;
307078baccbdSKoby Elbaz struct razwi_info razwi_info;
3071e65e175bSOded Gabbay struct undefined_opcode_info undef_opcode;
307278baccbdSKoby Elbaz struct page_fault_info page_fault_info;
3073313e9f63SMoti Haimovski struct hw_err_info hw_err;
3074313e9f63SMoti Haimovski struct fw_err_info fw_err;
3075e65e175bSOded Gabbay };
3076e65e175bSOded Gabbay
3077e65e175bSOded Gabbay /**
3078e65e175bSOded Gabbay * struct hl_reset_info - holds current device reset information.
3079e65e175bSOded Gabbay * @lock: lock to protect critical reset flows.
3080e65e175bSOded Gabbay * @compute_reset_cnt: number of compute resets since the driver was loaded.
3081e65e175bSOded Gabbay * @hard_reset_cnt: number of hard resets since the driver was loaded.
3082e65e175bSOded Gabbay * @hard_reset_schedule_flags: hard reset is scheduled to after current compute reset,
3083e65e175bSOded Gabbay * here we hold the hard reset flags.
3084e65e175bSOded Gabbay * @in_reset: is device in reset flow.
3085e65e175bSOded Gabbay * @in_compute_reset: Device is currently in reset but not in hard-reset.
3086e65e175bSOded Gabbay * @needs_reset: true if reset_on_lockup is false and device should be reset
3087e65e175bSOded Gabbay * due to lockup.
3088e65e175bSOded Gabbay * @hard_reset_pending: is there a hard reset work pending.
3089e65e175bSOded Gabbay * @curr_reset_cause: saves an enumerated reset cause when a hard reset is
3090e65e175bSOded Gabbay * triggered, and cleared after it is shared with preboot.
3091e65e175bSOded Gabbay * @prev_reset_trigger: saves the previous trigger which caused a reset, overridden
3092e65e175bSOded Gabbay * with a new value on next reset
3093e65e175bSOded Gabbay * @reset_trigger_repeated: set if device reset is triggered more than once with
3094e65e175bSOded Gabbay * same cause.
3095e65e175bSOded Gabbay * @skip_reset_on_timeout: Skip device reset if CS has timed out, wait for it to
3096e65e175bSOded Gabbay * complete instead.
3097e65e175bSOded Gabbay * @watchdog_active: true if a device release watchdog work is scheduled.
3098e65e175bSOded Gabbay */
3099e65e175bSOded Gabbay struct hl_reset_info {
3100e65e175bSOded Gabbay spinlock_t lock;
3101e65e175bSOded Gabbay u32 compute_reset_cnt;
3102e65e175bSOded Gabbay u32 hard_reset_cnt;
3103e65e175bSOded Gabbay u32 hard_reset_schedule_flags;
3104e65e175bSOded Gabbay u8 in_reset;
3105e65e175bSOded Gabbay u8 in_compute_reset;
3106e65e175bSOded Gabbay u8 needs_reset;
3107e65e175bSOded Gabbay u8 hard_reset_pending;
3108e65e175bSOded Gabbay u8 curr_reset_cause;
3109e65e175bSOded Gabbay u8 prev_reset_trigger;
3110e65e175bSOded Gabbay u8 reset_trigger_repeated;
3111e65e175bSOded Gabbay u8 skip_reset_on_timeout;
3112e65e175bSOded Gabbay u8 watchdog_active;
3113e65e175bSOded Gabbay };
3114e65e175bSOded Gabbay
3115e65e175bSOded Gabbay /**
3116e65e175bSOded Gabbay * struct hl_device - habanalabs device structure.
3117e65e175bSOded Gabbay * @pdev: pointer to PCI device, can be NULL in case of simulator device.
3118e65e175bSOded Gabbay * @pcie_bar_phys: array of available PCIe bars physical addresses.
3119e65e175bSOded Gabbay * (required only for PCI address match mode)
3120e65e175bSOded Gabbay * @pcie_bar: array of available PCIe bars virtual addresses.
3121e65e175bSOded Gabbay * @rmmio: configuration area address on SRAM.
3122323adae9SOded Gabbay * @hclass: pointer to the habanalabs class.
3123e65e175bSOded Gabbay * @cdev: related char device.
3124e65e175bSOded Gabbay * @cdev_ctrl: char device for control operations only (INFO IOCTL)
3125e65e175bSOded Gabbay * @dev: related kernel basic device structure.
3126e65e175bSOded Gabbay * @dev_ctrl: related kernel device structure for the control device
3127e65e175bSOded Gabbay * @work_heartbeat: delayed work for CPU-CP is-alive check.
3128e65e175bSOded Gabbay * @device_reset_work: delayed work which performs hard reset
3129e65e175bSOded Gabbay * @device_release_watchdog_work: watchdog work that performs hard reset if user doesn't release
3130e65e175bSOded Gabbay * device upon certain error cases.
3131e65e175bSOded Gabbay * @asic_name: ASIC specific name.
3132e65e175bSOded Gabbay * @asic_type: ASIC specific type.
3133e65e175bSOded Gabbay * @completion_queue: array of hl_cq.
3134e65e175bSOded Gabbay * @user_interrupt: array of hl_user_interrupt. upon the corresponding user
3135e65e175bSOded Gabbay * interrupt, driver will monitor the list of fences
3136e65e175bSOded Gabbay * registered to this interrupt.
31374713ace3SOfir Bitton * @tpc_interrupt: single TPC interrupt for all TPCs.
3138e1ef053eSOfir Bitton * @unexpected_error_interrupt: single interrupt for unexpected user error indication.
3139e65e175bSOded Gabbay * @common_user_cq_interrupt: common user CQ interrupt for all user CQ interrupts.
3140e65e175bSOded Gabbay * upon any user CQ interrupt, driver will monitor the
3141e65e175bSOded Gabbay * list of fences registered to this common structure.
3142e65e175bSOded Gabbay * @common_decoder_interrupt: common decoder interrupt for all user decoder interrupts.
3143e65e175bSOded Gabbay * @shadow_cs_queue: pointer to a shadow queue that holds pointers to
3144e65e175bSOded Gabbay * outstanding command submissions.
3145e65e175bSOded Gabbay * @cq_wq: work queues of completion queues for executing work in process
3146e65e175bSOded Gabbay * context.
3147e65e175bSOded Gabbay * @eq_wq: work queue of event queue for executing work in process context.
3148e65e175bSOded Gabbay * @cs_cmplt_wq: work queue of CS completions for executing work in process
3149e65e175bSOded Gabbay * context.
3150e65e175bSOded Gabbay * @ts_free_obj_wq: work queue for timestamp registration objects release.
3151e65e175bSOded Gabbay * @prefetch_wq: work queue for MMU pre-fetch operations.
3152e65e175bSOded Gabbay * @reset_wq: work queue for device reset procedure.
3153e65e175bSOded Gabbay * @kernel_ctx: Kernel driver context structure.
3154e65e175bSOded Gabbay * @kernel_queues: array of hl_hw_queue.
3155e65e175bSOded Gabbay * @cs_mirror_list: CS mirror list for TDR.
3156e65e175bSOded Gabbay * @cs_mirror_lock: protects cs_mirror_list.
3157e65e175bSOded Gabbay * @kernel_mem_mgr: memory manager for memory buffers with lifespan of driver.
3158e65e175bSOded Gabbay * @event_queue: event queue for IRQ from CPU-CP.
3159e65e175bSOded Gabbay * @dma_pool: DMA pool for small allocations.
3160e65e175bSOded Gabbay * @cpu_accessible_dma_mem: Host <-> CPU-CP shared memory CPU address.
3161e65e175bSOded Gabbay * @cpu_accessible_dma_address: Host <-> CPU-CP shared memory DMA address.
3162e65e175bSOded Gabbay * @cpu_accessible_dma_pool: Host <-> CPU-CP shared memory pool.
3163e65e175bSOded Gabbay * @asid_bitmap: holds used/available ASIDs.
3164e65e175bSOded Gabbay * @asid_mutex: protects asid_bitmap.
3165e65e175bSOded Gabbay * @send_cpu_message_lock: enforces only one message in Host <-> CPU-CP queue.
3166e65e175bSOded Gabbay * @debug_lock: protects critical section of setting debug mode for device
3167e65e175bSOded Gabbay * @mmu_lock: protects the MMU page tables and invalidation h/w. Although the
3168e65e175bSOded Gabbay * page tables are per context, the invalidation h/w is per MMU.
3169e65e175bSOded Gabbay * Therefore, we can't allow multiple contexts (we only have two,
3170e65e175bSOded Gabbay * user and kernel) to access the invalidation h/w at the same time.
3171e65e175bSOded Gabbay * In addition, any change to the PGT, modifying the MMU hash or
3172e65e175bSOded Gabbay * walking the PGT requires talking this lock.
3173e65e175bSOded Gabbay * @asic_prop: ASIC specific immutable properties.
3174e65e175bSOded Gabbay * @asic_funcs: ASIC specific functions.
3175e65e175bSOded Gabbay * @asic_specific: ASIC specific information to use only from ASIC files.
3176e65e175bSOded Gabbay * @vm: virtual memory manager for MMU.
3177e65e175bSOded Gabbay * @hwmon_dev: H/W monitor device.
3178e65e175bSOded Gabbay * @hl_chip_info: ASIC's sensors information.
3179e65e175bSOded Gabbay * @device_status_description: device status description.
3180e65e175bSOded Gabbay * @hl_debugfs: device's debugfs manager.
3181e65e175bSOded Gabbay * @cb_pool: list of pre allocated CBs.
3182e65e175bSOded Gabbay * @cb_pool_lock: protects the CB pool.
3183e65e175bSOded Gabbay * @internal_cb_pool_virt_addr: internal command buffer pool virtual address.
3184e65e175bSOded Gabbay * @internal_cb_pool_dma_addr: internal command buffer pool dma address.
3185e65e175bSOded Gabbay * @internal_cb_pool: internal command buffer memory pool.
3186e65e175bSOded Gabbay * @internal_cb_va_base: internal cb pool mmu virtual address base
3187e65e175bSOded Gabbay * @fpriv_list: list of file private data structures. Each structure is created
3188e65e175bSOded Gabbay * when a user opens the device
3189e65e175bSOded Gabbay * @fpriv_ctrl_list: list of file private data structures. Each structure is created
3190e65e175bSOded Gabbay * when a user opens the control device
3191e65e175bSOded Gabbay * @fpriv_list_lock: protects the fpriv_list
3192e65e175bSOded Gabbay * @fpriv_ctrl_list_lock: protects the fpriv_ctrl_list
3193e65e175bSOded Gabbay * @aggregated_cs_counters: aggregated cs counters among all contexts
3194e65e175bSOded Gabbay * @mmu_priv: device-specific MMU data.
3195e65e175bSOded Gabbay * @mmu_func: device-related MMU functions.
3196e65e175bSOded Gabbay * @dec: list of decoder sw instance
3197e65e175bSOded Gabbay * @fw_loader: FW loader manager.
3198e65e175bSOded Gabbay * @pci_mem_region: array of memory regions in the PCI
3199e65e175bSOded Gabbay * @state_dump_specs: constants and dictionaries needed to dump system state.
3200e65e175bSOded Gabbay * @multi_cs_completion: array of multi-CS completion.
3201e65e175bSOded Gabbay * @clk_throttling: holds information about current/previous clock throttling events
3202e65e175bSOded Gabbay * @captured_err_info: holds information about errors.
3203e65e175bSOded Gabbay * @reset_info: holds current device reset information.
3204e65e175bSOded Gabbay * @stream_master_qid_arr: pointer to array with QIDs of master streams.
32053071247cSDafna Hirschfeld * @fw_inner_major_ver: the major of current loaded preboot inner version.
32063071247cSDafna Hirschfeld * @fw_inner_minor_ver: the minor of current loaded preboot inner version.
3207dd5667ffSDafna Hirschfeld * @fw_sw_major_ver: the major of current loaded preboot SW version.
3208dd5667ffSDafna Hirschfeld * @fw_sw_minor_ver: the minor of current loaded preboot SW version.
3209dd5667ffSDafna Hirschfeld * @fw_sw_sub_minor_ver: the sub-minor of current loaded preboot SW version.
3210e65e175bSOded Gabbay * @dram_used_mem: current DRAM memory consumption.
3211e65e175bSOded Gabbay * @memory_scrub_val: the value to which the dram will be scrubbed to using cb scrub_device_dram
3212e65e175bSOded Gabbay * @timeout_jiffies: device CS timeout value.
3213e65e175bSOded Gabbay * @max_power: the max power of the device, as configured by the sysadmin. This
3214e65e175bSOded Gabbay * value is saved so in case of hard-reset, the driver will restore
3215e65e175bSOded Gabbay * this value and update the F/W after the re-initialization
3216e65e175bSOded Gabbay * @boot_error_status_mask: contains a mask of the device boot error status.
3217e65e175bSOded Gabbay * Each bit represents a different error, according to
3218e65e175bSOded Gabbay * the defines in hl_boot_if.h. If the bit is cleared,
3219e65e175bSOded Gabbay * the error will be ignored by the driver during
3220e65e175bSOded Gabbay * device initialization. Mainly used to debug and
3221e65e175bSOded Gabbay * workaround firmware bugs
3222e65e175bSOded Gabbay * @dram_pci_bar_start: start bus address of PCIe bar towards DRAM.
3223e65e175bSOded Gabbay * @last_successful_open_ktime: timestamp (ktime) of the last successful device open.
3224e65e175bSOded Gabbay * @last_successful_open_jif: timestamp (jiffies) of the last successful
3225e65e175bSOded Gabbay * device open.
3226e65e175bSOded Gabbay * @last_open_session_duration_jif: duration (jiffies) of the last device open
3227e65e175bSOded Gabbay * session.
3228e65e175bSOded Gabbay * @open_counter: number of successful device open operations.
3229e65e175bSOded Gabbay * @fw_poll_interval_usec: FW status poll interval in usec.
3230e65e175bSOded Gabbay * used for CPU boot status
3231e65e175bSOded Gabbay * @fw_comms_poll_interval_usec: FW comms/protocol poll interval in usec.
3232e65e175bSOded Gabbay * used for COMMs protocols cmds(COMMS_STS_*)
3233e65e175bSOded Gabbay * @dram_binning: contains mask of drams that is received from the f/w which indicates which
3234e65e175bSOded Gabbay * drams are binned-out
3235e65e175bSOded Gabbay * @tpc_binning: contains mask of tpc engines that is received from the f/w which indicates which
3236e65e175bSOded Gabbay * tpc engines are binned-out
3237d43bce6eSTomer Tayar * @dmabuf_export_cnt: number of dma-buf exporting.
3238e65e175bSOded Gabbay * @card_type: Various ASICs have several card types. This indicates the card
3239e65e175bSOded Gabbay * type of the current device.
3240e65e175bSOded Gabbay * @major: habanalabs kernel driver major.
3241e65e175bSOded Gabbay * @high_pll: high PLL profile frequency.
3242e65e175bSOded Gabbay * @decoder_binning: contains mask of decoder engines that is received from the f/w which
3243e65e175bSOded Gabbay * indicates which decoder engines are binned-out
3244e65e175bSOded Gabbay * @edma_binning: contains mask of edma engines that is received from the f/w which
3245e65e175bSOded Gabbay * indicates which edma engines are binned-out
3246e65e175bSOded Gabbay * @device_release_watchdog_timeout_sec: device release watchdog timeout value in seconds.
3247e65e175bSOded Gabbay * @rotator_binning: contains mask of rotators engines that is received from the f/w
3248e65e175bSOded Gabbay * which indicates which rotator engines are binned-out(Gaudi3 and above).
3249e65e175bSOded Gabbay * @id: device minor.
3250e65e175bSOded Gabbay * @id_control: minor of the control device.
3251e65e175bSOded Gabbay * @cdev_idx: char device index. Used for setting its name.
3252e65e175bSOded Gabbay * @cpu_pci_msb_addr: 50-bit extension bits for the device CPU's 40-bit
3253e65e175bSOded Gabbay * addresses.
3254e65e175bSOded Gabbay * @is_in_dram_scrub: true if dram scrub operation is on going.
3255e65e175bSOded Gabbay * @disabled: is device disabled.
3256e65e175bSOded Gabbay * @late_init_done: is late init stage was done during initialization.
3257e65e175bSOded Gabbay * @hwmon_initialized: is H/W monitor sensors was initialized.
3258e65e175bSOded Gabbay * @reset_on_lockup: true if a reset should be done in case of stuck CS, false
3259e65e175bSOded Gabbay * otherwise.
3260e65e175bSOded Gabbay * @dram_default_page_mapping: is DRAM default page mapping enabled.
3261e65e175bSOded Gabbay * @memory_scrub: true to perform device memory scrub in various locations,
3262e65e175bSOded Gabbay * such as context-switch, context close, page free, etc.
3263e65e175bSOded Gabbay * @pmmu_huge_range: is a different virtual addresses range used for PMMU with
3264e65e175bSOded Gabbay * huge pages.
3265e65e175bSOded Gabbay * @init_done: is the initialization of the device done.
3266e65e175bSOded Gabbay * @device_cpu_disabled: is the device CPU disabled (due to timeouts)
3267e65e175bSOded Gabbay * @in_debug: whether the device is in a state where the profiling/tracing infrastructure
3268e65e175bSOded Gabbay * can be used. This indication is needed because in some ASICs we need to do
3269e65e175bSOded Gabbay * specific operations to enable that infrastructure.
32703b9abb4fSTomer Tayar * @cdev_sysfs_debugfs_created: were char devices and sysfs/debugfs files created.
3271e65e175bSOded Gabbay * @stop_on_err: true if engines should stop on error.
3272e65e175bSOded Gabbay * @supports_sync_stream: is sync stream supported.
3273e65e175bSOded Gabbay * @sync_stream_queue_idx: helper index for sync stream queues initialization.
3274e65e175bSOded Gabbay * @collective_mon_idx: helper index for collective initialization
3275e65e175bSOded Gabbay * @supports_coresight: is CoreSight supported.
3276e65e175bSOded Gabbay * @supports_cb_mapping: is mapping a CB to the device's MMU supported.
3277e65e175bSOded Gabbay * @process_kill_trial_cnt: number of trials reset thread tried killing
3278e65e175bSOded Gabbay * user processes
3279e65e175bSOded Gabbay * @device_fini_pending: true if device_fini was called and might be
3280e65e175bSOded Gabbay * waiting for the reset thread to finish
3281e65e175bSOded Gabbay * @supports_staged_submission: true if staged submissions are supported
3282e65e175bSOded Gabbay * @device_cpu_is_halted: Flag to indicate whether the device CPU was already
3283e65e175bSOded Gabbay * halted. We can't halt it again because the COMMS
3284e65e175bSOded Gabbay * protocol will throw an error. Relevant only for
3285e65e175bSOded Gabbay * cases where Linux was not loaded to device CPU
3286e65e175bSOded Gabbay * @supports_wait_for_multi_cs: true if wait for multi CS is supported
3287e65e175bSOded Gabbay * @is_compute_ctx_active: Whether there is an active compute context executing.
3288e65e175bSOded Gabbay * @compute_ctx_in_release: true if the current compute context is being released.
3289e65e175bSOded Gabbay * @supports_mmu_prefetch: true if prefetch is supported, otherwise false.
3290e65e175bSOded Gabbay * @reset_upon_device_release: reset the device when the user closes the file descriptor of the
3291e65e175bSOded Gabbay * device.
329266116a39SSagiv Ozeri * @supports_ctx_switch: true if a ctx switch is required upon first submission.
329366116a39SSagiv Ozeri * @support_preboot_binning: true if we support read binning info from preboot.
3294e65e175bSOded Gabbay * @nic_ports_mask: Controls which NIC ports are enabled. Used only for testing.
3295e65e175bSOded Gabbay * @fw_components: Controls which f/w components to load to the device. There are multiple f/w
3296e65e175bSOded Gabbay * stages and sometimes we want to stop at a certain stage. Used only for testing.
3297583f12a8SOfir Bitton * @mmu_disable: Disable the device MMU(s). Used only for testing.
3298e65e175bSOded Gabbay * @cpu_queues_enable: Whether to enable queues communication vs. the f/w. Used only for testing.
3299e65e175bSOded Gabbay * @pldm: Whether we are running in Palladium environment. Used only for testing.
3300e65e175bSOded Gabbay * @hard_reset_on_fw_events: Whether to do device hard-reset when a fatal event is received from
3301e65e175bSOded Gabbay * the f/w. Used only for testing.
3302e65e175bSOded Gabbay * @bmc_enable: Whether we are running in a box with BMC. Used only for testing.
3303e65e175bSOded Gabbay * @reset_on_preboot_fail: Whether to reset the device if preboot f/w fails to load.
3304e65e175bSOded Gabbay * Used only for testing.
3305e65e175bSOded Gabbay * @heartbeat: Controls if we want to enable the heartbeat mechanism vs. the f/w, which verifies
3306e65e175bSOded Gabbay * that the f/w is always alive. Used only for testing.
3307e65e175bSOded Gabbay */
3308e65e175bSOded Gabbay struct hl_device {
3309e65e175bSOded Gabbay struct pci_dev *pdev;
3310e65e175bSOded Gabbay u64 pcie_bar_phys[HL_PCI_NUM_BARS];
3311e65e175bSOded Gabbay void __iomem *pcie_bar[HL_PCI_NUM_BARS];
3312e65e175bSOded Gabbay void __iomem *rmmio;
3313323adae9SOded Gabbay struct class *hclass;
3314e65e175bSOded Gabbay struct cdev cdev;
3315e65e175bSOded Gabbay struct cdev cdev_ctrl;
3316e65e175bSOded Gabbay struct device *dev;
3317e65e175bSOded Gabbay struct device *dev_ctrl;
3318e65e175bSOded Gabbay struct delayed_work work_heartbeat;
3319e65e175bSOded Gabbay struct hl_device_reset_work device_reset_work;
3320e65e175bSOded Gabbay struct hl_device_reset_work device_release_watchdog_work;
3321e65e175bSOded Gabbay char asic_name[HL_STR_MAX];
3322e65e175bSOded Gabbay char status[HL_DEV_STS_MAX][HL_STR_MAX];
3323e65e175bSOded Gabbay enum hl_asic_type asic_type;
3324e65e175bSOded Gabbay struct hl_cq *completion_queue;
3325e65e175bSOded Gabbay struct hl_user_interrupt *user_interrupt;
33264713ace3SOfir Bitton struct hl_user_interrupt tpc_interrupt;
3327e1ef053eSOfir Bitton struct hl_user_interrupt unexpected_error_interrupt;
3328e65e175bSOded Gabbay struct hl_user_interrupt common_user_cq_interrupt;
3329e65e175bSOded Gabbay struct hl_user_interrupt common_decoder_interrupt;
3330e65e175bSOded Gabbay struct hl_cs **shadow_cs_queue;
3331e65e175bSOded Gabbay struct workqueue_struct **cq_wq;
3332e65e175bSOded Gabbay struct workqueue_struct *eq_wq;
3333e65e175bSOded Gabbay struct workqueue_struct *cs_cmplt_wq;
3334e65e175bSOded Gabbay struct workqueue_struct *ts_free_obj_wq;
3335e65e175bSOded Gabbay struct workqueue_struct *prefetch_wq;
3336e65e175bSOded Gabbay struct workqueue_struct *reset_wq;
3337e65e175bSOded Gabbay struct hl_ctx *kernel_ctx;
3338e65e175bSOded Gabbay struct hl_hw_queue *kernel_queues;
3339e65e175bSOded Gabbay struct list_head cs_mirror_list;
3340e65e175bSOded Gabbay spinlock_t cs_mirror_lock;
3341e65e175bSOded Gabbay struct hl_mem_mgr kernel_mem_mgr;
3342e65e175bSOded Gabbay struct hl_eq event_queue;
3343e65e175bSOded Gabbay struct dma_pool *dma_pool;
3344e65e175bSOded Gabbay void *cpu_accessible_dma_mem;
3345e65e175bSOded Gabbay dma_addr_t cpu_accessible_dma_address;
3346e65e175bSOded Gabbay struct gen_pool *cpu_accessible_dma_pool;
3347e65e175bSOded Gabbay unsigned long *asid_bitmap;
3348e65e175bSOded Gabbay struct mutex asid_mutex;
3349e65e175bSOded Gabbay struct mutex send_cpu_message_lock;
3350e65e175bSOded Gabbay struct mutex debug_lock;
3351e65e175bSOded Gabbay struct mutex mmu_lock;
3352e65e175bSOded Gabbay struct asic_fixed_properties asic_prop;
3353e65e175bSOded Gabbay const struct hl_asic_funcs *asic_funcs;
3354e65e175bSOded Gabbay void *asic_specific;
3355e65e175bSOded Gabbay struct hl_vm vm;
3356e65e175bSOded Gabbay struct device *hwmon_dev;
3357e65e175bSOded Gabbay struct hwmon_chip_info *hl_chip_info;
3358e65e175bSOded Gabbay
3359e65e175bSOded Gabbay struct hl_dbg_device_entry hl_debugfs;
3360e65e175bSOded Gabbay
3361e65e175bSOded Gabbay struct list_head cb_pool;
3362e65e175bSOded Gabbay spinlock_t cb_pool_lock;
3363e65e175bSOded Gabbay
3364e65e175bSOded Gabbay void *internal_cb_pool_virt_addr;
3365e65e175bSOded Gabbay dma_addr_t internal_cb_pool_dma_addr;
3366e65e175bSOded Gabbay struct gen_pool *internal_cb_pool;
3367e65e175bSOded Gabbay u64 internal_cb_va_base;
3368e65e175bSOded Gabbay
3369e65e175bSOded Gabbay struct list_head fpriv_list;
3370e65e175bSOded Gabbay struct list_head fpriv_ctrl_list;
3371e65e175bSOded Gabbay struct mutex fpriv_list_lock;
3372e65e175bSOded Gabbay struct mutex fpriv_ctrl_list_lock;
3373e65e175bSOded Gabbay
3374e65e175bSOded Gabbay struct hl_cs_counters_atomic aggregated_cs_counters;
3375e65e175bSOded Gabbay
3376e65e175bSOded Gabbay struct hl_mmu_priv mmu_priv;
3377e65e175bSOded Gabbay struct hl_mmu_funcs mmu_func[MMU_NUM_PGT_LOCATIONS];
3378e65e175bSOded Gabbay
3379e65e175bSOded Gabbay struct hl_dec *dec;
3380e65e175bSOded Gabbay
3381e65e175bSOded Gabbay struct fw_load_mgr fw_loader;
3382e65e175bSOded Gabbay
3383e65e175bSOded Gabbay struct pci_mem_region pci_mem_region[PCI_REGION_NUMBER];
3384e65e175bSOded Gabbay
3385e65e175bSOded Gabbay struct hl_state_dump_specs state_dump_specs;
3386e65e175bSOded Gabbay
3387e65e175bSOded Gabbay struct multi_cs_completion multi_cs_completion[
3388e65e175bSOded Gabbay MULTI_CS_MAX_USER_CTX];
3389e65e175bSOded Gabbay struct hl_clk_throttle clk_throttling;
3390e65e175bSOded Gabbay struct hl_error_info captured_err_info;
3391e65e175bSOded Gabbay
3392e65e175bSOded Gabbay struct hl_reset_info reset_info;
3393e65e175bSOded Gabbay
3394e65e175bSOded Gabbay u32 *stream_master_qid_arr;
33953071247cSDafna Hirschfeld u32 fw_inner_major_ver;
33963071247cSDafna Hirschfeld u32 fw_inner_minor_ver;
3397dd5667ffSDafna Hirschfeld u32 fw_sw_major_ver;
3398dd5667ffSDafna Hirschfeld u32 fw_sw_minor_ver;
3399dd5667ffSDafna Hirschfeld u32 fw_sw_sub_minor_ver;
3400e65e175bSOded Gabbay atomic64_t dram_used_mem;
3401e65e175bSOded Gabbay u64 memory_scrub_val;
3402e65e175bSOded Gabbay u64 timeout_jiffies;
3403e65e175bSOded Gabbay u64 max_power;
3404e65e175bSOded Gabbay u64 boot_error_status_mask;
3405e65e175bSOded Gabbay u64 dram_pci_bar_start;
3406e65e175bSOded Gabbay u64 last_successful_open_jif;
3407e65e175bSOded Gabbay u64 last_open_session_duration_jif;
3408e65e175bSOded Gabbay u64 open_counter;
3409e65e175bSOded Gabbay u64 fw_poll_interval_usec;
3410e65e175bSOded Gabbay ktime_t last_successful_open_ktime;
3411e65e175bSOded Gabbay u64 fw_comms_poll_interval_usec;
3412e65e175bSOded Gabbay u64 dram_binning;
3413e65e175bSOded Gabbay u64 tpc_binning;
3414d43bce6eSTomer Tayar atomic_t dmabuf_export_cnt;
3415e65e175bSOded Gabbay enum cpucp_card_types card_type;
3416e65e175bSOded Gabbay u32 major;
3417e65e175bSOded Gabbay u32 high_pll;
3418e65e175bSOded Gabbay u32 decoder_binning;
3419e65e175bSOded Gabbay u32 edma_binning;
3420e65e175bSOded Gabbay u32 device_release_watchdog_timeout_sec;
3421e65e175bSOded Gabbay u32 rotator_binning;
3422e65e175bSOded Gabbay u16 id;
3423e65e175bSOded Gabbay u16 id_control;
3424e65e175bSOded Gabbay u16 cdev_idx;
3425e65e175bSOded Gabbay u16 cpu_pci_msb_addr;
3426e65e175bSOded Gabbay u8 is_in_dram_scrub;
3427e65e175bSOded Gabbay u8 disabled;
3428e65e175bSOded Gabbay u8 late_init_done;
3429e65e175bSOded Gabbay u8 hwmon_initialized;
3430e65e175bSOded Gabbay u8 reset_on_lockup;
3431e65e175bSOded Gabbay u8 dram_default_page_mapping;
3432e65e175bSOded Gabbay u8 memory_scrub;
3433e65e175bSOded Gabbay u8 pmmu_huge_range;
3434e65e175bSOded Gabbay u8 init_done;
3435e65e175bSOded Gabbay u8 device_cpu_disabled;
3436e65e175bSOded Gabbay u8 in_debug;
34373b9abb4fSTomer Tayar u8 cdev_sysfs_debugfs_created;
3438e65e175bSOded Gabbay u8 stop_on_err;
3439e65e175bSOded Gabbay u8 supports_sync_stream;
3440e65e175bSOded Gabbay u8 sync_stream_queue_idx;
3441e65e175bSOded Gabbay u8 collective_mon_idx;
3442e65e175bSOded Gabbay u8 supports_coresight;
3443e65e175bSOded Gabbay u8 supports_cb_mapping;
3444e65e175bSOded Gabbay u8 process_kill_trial_cnt;
3445e65e175bSOded Gabbay u8 device_fini_pending;
3446e65e175bSOded Gabbay u8 supports_staged_submission;
3447e65e175bSOded Gabbay u8 device_cpu_is_halted;
3448e65e175bSOded Gabbay u8 supports_wait_for_multi_cs;
3449e65e175bSOded Gabbay u8 stream_master_qid_arr_size;
3450e65e175bSOded Gabbay u8 is_compute_ctx_active;
3451e65e175bSOded Gabbay u8 compute_ctx_in_release;
3452e65e175bSOded Gabbay u8 supports_mmu_prefetch;
3453e65e175bSOded Gabbay u8 reset_upon_device_release;
3454e65e175bSOded Gabbay u8 supports_ctx_switch;
3455e65e175bSOded Gabbay u8 support_preboot_binning;
3456e65e175bSOded Gabbay
345766116a39SSagiv Ozeri /* Parameters for bring-up to be upstreamed */
3458e65e175bSOded Gabbay u64 nic_ports_mask;
3459e65e175bSOded Gabbay u64 fw_components;
3460583f12a8SOfir Bitton u8 mmu_disable;
3461e65e175bSOded Gabbay u8 cpu_queues_enable;
3462e65e175bSOded Gabbay u8 pldm;
3463e65e175bSOded Gabbay u8 hard_reset_on_fw_events;
3464e65e175bSOded Gabbay u8 bmc_enable;
3465e65e175bSOded Gabbay u8 reset_on_preboot_fail;
3466e65e175bSOded Gabbay u8 heartbeat;
3467e65e175bSOded Gabbay };
3468e65e175bSOded Gabbay
3469e65e175bSOded Gabbay
3470e65e175bSOded Gabbay /**
3471e65e175bSOded Gabbay * struct hl_cs_encaps_sig_handle - encapsulated signals handle structure
3472e65e175bSOded Gabbay * @refcount: refcount used to protect removing this id when several
3473e65e175bSOded Gabbay * wait cs are used to wait of the reserved encaps signals.
3474e65e175bSOded Gabbay * @hdev: pointer to habanalabs device structure.
3475e65e175bSOded Gabbay * @hw_sob: pointer to H/W SOB used in the reservation.
3476e65e175bSOded Gabbay * @ctx: pointer to the user's context data structure
3477e65e175bSOded Gabbay * @cs_seq: staged cs sequence which contains encapsulated signals
3478e65e175bSOded Gabbay * @id: idr handler id to be used to fetch the handler info
3479e65e175bSOded Gabbay * @q_idx: stream queue index
3480e65e175bSOded Gabbay * @pre_sob_val: current SOB value before reservation
3481e65e175bSOded Gabbay * @count: signals number
3482e65e175bSOded Gabbay */
3483e65e175bSOded Gabbay struct hl_cs_encaps_sig_handle {
3484e65e175bSOded Gabbay struct kref refcount;
3485e65e175bSOded Gabbay struct hl_device *hdev;
3486e65e175bSOded Gabbay struct hl_hw_sob *hw_sob;
3487e65e175bSOded Gabbay struct hl_ctx *ctx;
3488e65e175bSOded Gabbay u64 cs_seq;
3489e65e175bSOded Gabbay u32 id;
3490e65e175bSOded Gabbay u32 q_idx;
3491e65e175bSOded Gabbay u32 pre_sob_val;
3492e65e175bSOded Gabbay u32 count;
3493e65e175bSOded Gabbay };
3494e65e175bSOded Gabbay
3495313e9f63SMoti Haimovski /**
3496313e9f63SMoti Haimovski * struct hl_info_fw_err_info - firmware error information structure
3497313e9f63SMoti Haimovski * @err_type: The type of error detected (or reported).
3498313e9f63SMoti Haimovski * @event_mask: Pointer to the event mask to be modified with the detected error flag
3499313e9f63SMoti Haimovski * (can be NULL)
3500313e9f63SMoti Haimovski * @event_id: The id of the event that reported the error
3501313e9f63SMoti Haimovski * (applicable when err_type is HL_INFO_FW_REPORTED_ERR).
3502313e9f63SMoti Haimovski */
3503313e9f63SMoti Haimovski struct hl_info_fw_err_info {
3504313e9f63SMoti Haimovski enum hl_info_fw_err_type err_type;
3505313e9f63SMoti Haimovski u64 *event_mask;
3506313e9f63SMoti Haimovski u16 event_id;
3507313e9f63SMoti Haimovski };
3508313e9f63SMoti Haimovski
3509e65e175bSOded Gabbay /*
3510e65e175bSOded Gabbay * IOCTLs
3511e65e175bSOded Gabbay */
3512e65e175bSOded Gabbay
3513e65e175bSOded Gabbay /**
3514e65e175bSOded Gabbay * typedef hl_ioctl_t - typedef for ioctl function in the driver
3515e65e175bSOded Gabbay * @hpriv: pointer to the FD's private data, which contains state of
3516e65e175bSOded Gabbay * user process
3517e65e175bSOded Gabbay * @data: pointer to the input/output arguments structure of the IOCTL
3518e65e175bSOded Gabbay *
3519e65e175bSOded Gabbay * Return: 0 for success, negative value for error
3520e65e175bSOded Gabbay */
3521e65e175bSOded Gabbay typedef int hl_ioctl_t(struct hl_fpriv *hpriv, void *data);
3522e65e175bSOded Gabbay
3523e65e175bSOded Gabbay /**
3524e65e175bSOded Gabbay * struct hl_ioctl_desc - describes an IOCTL entry of the driver.
3525e65e175bSOded Gabbay * @cmd: the IOCTL code as created by the kernel macros.
3526e65e175bSOded Gabbay * @func: pointer to the driver's function that should be called for this IOCTL.
3527e65e175bSOded Gabbay */
3528e65e175bSOded Gabbay struct hl_ioctl_desc {
3529e65e175bSOded Gabbay unsigned int cmd;
3530e65e175bSOded Gabbay hl_ioctl_t *func;
3531e65e175bSOded Gabbay };
3532e65e175bSOded Gabbay
hl_is_fw_sw_ver_below(struct hl_device * hdev,u32 fw_sw_major,u32 fw_sw_minor)3533a12428acSDafna Hirschfeld static inline bool hl_is_fw_sw_ver_below(struct hl_device *hdev, u32 fw_sw_major, u32 fw_sw_minor)
3534ec484931SDani Liberman {
3535a12428acSDafna Hirschfeld if (hdev->fw_sw_major_ver < fw_sw_major)
3536a12428acSDafna Hirschfeld return true;
3537a12428acSDafna Hirschfeld if (hdev->fw_sw_major_ver > fw_sw_major)
3538a12428acSDafna Hirschfeld return false;
3539a12428acSDafna Hirschfeld if (hdev->fw_sw_minor_ver < fw_sw_minor)
3540a12428acSDafna Hirschfeld return true;
3541a12428acSDafna Hirschfeld return false;
3542ec484931SDani Liberman }
3543e65e175bSOded Gabbay
3544e65e175bSOded Gabbay /*
3545e65e175bSOded Gabbay * Kernel module functions that can be accessed by entire module
3546e65e175bSOded Gabbay */
3547e65e175bSOded Gabbay
3548e65e175bSOded Gabbay /**
3549e65e175bSOded Gabbay * hl_get_sg_info() - get number of pages and the DMA address from SG list.
3550e65e175bSOded Gabbay * @sg: the SG list.
3551e65e175bSOded Gabbay * @dma_addr: pointer to DMA address to return.
3552e65e175bSOded Gabbay *
3553e65e175bSOded Gabbay * Calculate the number of consecutive pages described by the SG list. Take the
3554e65e175bSOded Gabbay * offset of the address in the first page, add to it the length and round it up
3555e65e175bSOded Gabbay * to the number of needed pages.
3556e65e175bSOded Gabbay */
hl_get_sg_info(struct scatterlist * sg,dma_addr_t * dma_addr)3557e65e175bSOded Gabbay static inline u32 hl_get_sg_info(struct scatterlist *sg, dma_addr_t *dma_addr)
3558e65e175bSOded Gabbay {
3559e65e175bSOded Gabbay *dma_addr = sg_dma_address(sg);
3560e65e175bSOded Gabbay
3561e65e175bSOded Gabbay return ((((*dma_addr) & (PAGE_SIZE - 1)) + sg_dma_len(sg)) +
3562e65e175bSOded Gabbay (PAGE_SIZE - 1)) >> PAGE_SHIFT;
3563e65e175bSOded Gabbay }
3564e65e175bSOded Gabbay
3565e65e175bSOded Gabbay /**
3566e65e175bSOded Gabbay * hl_mem_area_inside_range() - Checks whether address+size are inside a range.
3567e65e175bSOded Gabbay * @address: The start address of the area we want to validate.
3568e65e175bSOded Gabbay * @size: The size in bytes of the area we want to validate.
3569e65e175bSOded Gabbay * @range_start_address: The start address of the valid range.
3570e65e175bSOded Gabbay * @range_end_address: The end address of the valid range.
3571e65e175bSOded Gabbay *
3572e65e175bSOded Gabbay * Return: true if the area is inside the valid range, false otherwise.
3573e65e175bSOded Gabbay */
hl_mem_area_inside_range(u64 address,u64 size,u64 range_start_address,u64 range_end_address)3574e65e175bSOded Gabbay static inline bool hl_mem_area_inside_range(u64 address, u64 size,
3575e65e175bSOded Gabbay u64 range_start_address, u64 range_end_address)
3576e65e175bSOded Gabbay {
3577e65e175bSOded Gabbay u64 end_address = address + size;
3578e65e175bSOded Gabbay
3579e65e175bSOded Gabbay if ((address >= range_start_address) &&
3580e65e175bSOded Gabbay (end_address <= range_end_address) &&
3581e65e175bSOded Gabbay (end_address > address))
3582e65e175bSOded Gabbay return true;
3583e65e175bSOded Gabbay
3584e65e175bSOded Gabbay return false;
3585e65e175bSOded Gabbay }
3586e65e175bSOded Gabbay
3587e65e175bSOded Gabbay /**
3588e65e175bSOded Gabbay * hl_mem_area_crosses_range() - Checks whether address+size crossing a range.
3589e65e175bSOded Gabbay * @address: The start address of the area we want to validate.
3590e65e175bSOded Gabbay * @size: The size in bytes of the area we want to validate.
3591e65e175bSOded Gabbay * @range_start_address: The start address of the valid range.
3592e65e175bSOded Gabbay * @range_end_address: The end address of the valid range.
3593e65e175bSOded Gabbay *
3594e65e175bSOded Gabbay * Return: true if the area overlaps part or all of the valid range,
3595e65e175bSOded Gabbay * false otherwise.
3596e65e175bSOded Gabbay */
hl_mem_area_crosses_range(u64 address,u32 size,u64 range_start_address,u64 range_end_address)3597e65e175bSOded Gabbay static inline bool hl_mem_area_crosses_range(u64 address, u32 size,
3598e65e175bSOded Gabbay u64 range_start_address, u64 range_end_address)
3599e65e175bSOded Gabbay {
3600e65e175bSOded Gabbay u64 end_address = address + size - 1;
3601e65e175bSOded Gabbay
3602e65e175bSOded Gabbay return ((address <= range_end_address) && (range_start_address <= end_address));
3603e65e175bSOded Gabbay }
3604e65e175bSOded Gabbay
3605e65e175bSOded Gabbay uint64_t hl_set_dram_bar_default(struct hl_device *hdev, u64 addr);
36064a2e9d11SDafna Hirschfeld void *hl_cpu_accessible_dma_pool_alloc(struct hl_device *hdev, size_t size, dma_addr_t *dma_handle);
36074a2e9d11SDafna Hirschfeld void hl_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size, void *vaddr);
3608e65e175bSOded Gabbay void *hl_asic_dma_alloc_coherent_caller(struct hl_device *hdev, size_t size, dma_addr_t *dma_handle,
3609e65e175bSOded Gabbay gfp_t flag, const char *caller);
3610e65e175bSOded Gabbay void hl_asic_dma_free_coherent_caller(struct hl_device *hdev, size_t size, void *cpu_addr,
3611e65e175bSOded Gabbay dma_addr_t dma_handle, const char *caller);
3612e65e175bSOded Gabbay void *hl_asic_dma_pool_zalloc_caller(struct hl_device *hdev, size_t size, gfp_t mem_flags,
3613e65e175bSOded Gabbay dma_addr_t *dma_handle, const char *caller);
3614e65e175bSOded Gabbay void hl_asic_dma_pool_free_caller(struct hl_device *hdev, void *vaddr, dma_addr_t dma_addr,
3615e65e175bSOded Gabbay const char *caller);
3616e65e175bSOded Gabbay int hl_dma_map_sgtable(struct hl_device *hdev, struct sg_table *sgt, enum dma_data_direction dir);
3617e65e175bSOded Gabbay void hl_dma_unmap_sgtable(struct hl_device *hdev, struct sg_table *sgt,
3618e65e175bSOded Gabbay enum dma_data_direction dir);
3619e65e175bSOded Gabbay int hl_access_sram_dram_region(struct hl_device *hdev, u64 addr, u64 *val,
3620e65e175bSOded Gabbay enum debugfs_access_type acc_type, enum pci_region region_type, bool set_dram_bar);
3621e65e175bSOded Gabbay int hl_access_cfg_region(struct hl_device *hdev, u64 addr, u64 *val,
3622e65e175bSOded Gabbay enum debugfs_access_type acc_type);
3623e65e175bSOded Gabbay int hl_access_dev_mem(struct hl_device *hdev, enum pci_region region_type,
3624e65e175bSOded Gabbay u64 addr, u64 *val, enum debugfs_access_type acc_type);
3625e65e175bSOded Gabbay int hl_device_open(struct inode *inode, struct file *filp);
3626e65e175bSOded Gabbay int hl_device_open_ctrl(struct inode *inode, struct file *filp);
3627e65e175bSOded Gabbay bool hl_device_operational(struct hl_device *hdev,
3628e65e175bSOded Gabbay enum hl_device_status *status);
3629e65e175bSOded Gabbay bool hl_ctrl_device_operational(struct hl_device *hdev,
3630e65e175bSOded Gabbay enum hl_device_status *status);
3631e65e175bSOded Gabbay enum hl_device_status hl_device_status(struct hl_device *hdev);
3632e65e175bSOded Gabbay int hl_device_set_debug_mode(struct hl_device *hdev, struct hl_ctx *ctx, bool enable);
3633e65e175bSOded Gabbay int hl_hw_queues_create(struct hl_device *hdev);
3634e65e175bSOded Gabbay void hl_hw_queues_destroy(struct hl_device *hdev);
3635e65e175bSOded Gabbay int hl_hw_queue_send_cb_no_cmpl(struct hl_device *hdev, u32 hw_queue_id,
3636e65e175bSOded Gabbay u32 cb_size, u64 cb_ptr);
3637e65e175bSOded Gabbay void hl_hw_queue_submit_bd(struct hl_device *hdev, struct hl_hw_queue *q,
3638e65e175bSOded Gabbay u32 ctl, u32 len, u64 ptr);
3639e65e175bSOded Gabbay int hl_hw_queue_schedule_cs(struct hl_cs *cs);
3640e65e175bSOded Gabbay u32 hl_hw_queue_add_ptr(u32 ptr, u16 val);
3641e65e175bSOded Gabbay void hl_hw_queue_inc_ci_kernel(struct hl_device *hdev, u32 hw_queue_id);
3642e65e175bSOded Gabbay void hl_hw_queue_update_ci(struct hl_cs *cs);
3643e65e175bSOded Gabbay void hl_hw_queue_reset(struct hl_device *hdev, bool hard_reset);
3644e65e175bSOded Gabbay
3645e65e175bSOded Gabbay #define hl_queue_inc_ptr(p) hl_hw_queue_add_ptr(p, 1)
3646e65e175bSOded Gabbay #define hl_pi_2_offset(pi) ((pi) & (HL_QUEUE_LENGTH - 1))
3647e65e175bSOded Gabbay
3648e65e175bSOded Gabbay int hl_cq_init(struct hl_device *hdev, struct hl_cq *q, u32 hw_queue_id);
3649e65e175bSOded Gabbay void hl_cq_fini(struct hl_device *hdev, struct hl_cq *q);
3650e65e175bSOded Gabbay int hl_eq_init(struct hl_device *hdev, struct hl_eq *q);
3651e65e175bSOded Gabbay void hl_eq_fini(struct hl_device *hdev, struct hl_eq *q);
3652e65e175bSOded Gabbay void hl_cq_reset(struct hl_device *hdev, struct hl_cq *q);
3653e65e175bSOded Gabbay void hl_eq_reset(struct hl_device *hdev, struct hl_eq *q);
3654e65e175bSOded Gabbay irqreturn_t hl_irq_handler_cq(int irq, void *arg);
3655e65e175bSOded Gabbay irqreturn_t hl_irq_handler_eq(int irq, void *arg);
3656e65e175bSOded Gabbay irqreturn_t hl_irq_handler_dec_abnrm(int irq, void *arg);
3657e65e175bSOded Gabbay irqreturn_t hl_irq_handler_user_interrupt(int irq, void *arg);
365860122358STal Cohen irqreturn_t hl_irq_user_interrupt_thread_handler(int irq, void *arg);
3659e65e175bSOded Gabbay u32 hl_cq_inc_ptr(u32 ptr);
3660e65e175bSOded Gabbay
3661e65e175bSOded Gabbay int hl_asid_init(struct hl_device *hdev);
3662e65e175bSOded Gabbay void hl_asid_fini(struct hl_device *hdev);
3663e65e175bSOded Gabbay unsigned long hl_asid_alloc(struct hl_device *hdev);
3664e65e175bSOded Gabbay void hl_asid_free(struct hl_device *hdev, unsigned long asid);
3665e65e175bSOded Gabbay
3666e65e175bSOded Gabbay int hl_ctx_create(struct hl_device *hdev, struct hl_fpriv *hpriv);
3667e65e175bSOded Gabbay void hl_ctx_free(struct hl_device *hdev, struct hl_ctx *ctx);
3668e65e175bSOded Gabbay int hl_ctx_init(struct hl_device *hdev, struct hl_ctx *ctx, bool is_kernel_ctx);
3669e65e175bSOded Gabbay void hl_ctx_do_release(struct kref *ref);
3670e65e175bSOded Gabbay void hl_ctx_get(struct hl_ctx *ctx);
3671e65e175bSOded Gabbay int hl_ctx_put(struct hl_ctx *ctx);
3672e65e175bSOded Gabbay struct hl_ctx *hl_get_compute_ctx(struct hl_device *hdev);
3673e65e175bSOded Gabbay struct hl_fence *hl_ctx_get_fence(struct hl_ctx *ctx, u64 seq);
3674e65e175bSOded Gabbay int hl_ctx_get_fences(struct hl_ctx *ctx, u64 *seq_arr,
3675e65e175bSOded Gabbay struct hl_fence **fence, u32 arr_len);
3676e65e175bSOded Gabbay void hl_ctx_mgr_init(struct hl_ctx_mgr *mgr);
3677e65e175bSOded Gabbay void hl_ctx_mgr_fini(struct hl_device *hdev, struct hl_ctx_mgr *mgr);
3678e65e175bSOded Gabbay
3679323adae9SOded Gabbay int hl_device_init(struct hl_device *hdev);
3680e65e175bSOded Gabbay void hl_device_fini(struct hl_device *hdev);
3681e65e175bSOded Gabbay int hl_device_suspend(struct hl_device *hdev);
3682e65e175bSOded Gabbay int hl_device_resume(struct hl_device *hdev);
3683e65e175bSOded Gabbay int hl_device_reset(struct hl_device *hdev, u32 flags);
3684e65e175bSOded Gabbay int hl_device_cond_reset(struct hl_device *hdev, u32 flags, u64 event_mask);
3685e65e175bSOded Gabbay void hl_hpriv_get(struct hl_fpriv *hpriv);
3686e65e175bSOded Gabbay int hl_hpriv_put(struct hl_fpriv *hpriv);
3687e65e175bSOded Gabbay int hl_device_utilization(struct hl_device *hdev, u32 *utilization);
3688e65e175bSOded Gabbay
3689e65e175bSOded Gabbay int hl_build_hwmon_channel_info(struct hl_device *hdev,
3690e65e175bSOded Gabbay struct cpucp_sensor *sensors_arr);
3691e65e175bSOded Gabbay
3692e65e175bSOded Gabbay void hl_notifier_event_send_all(struct hl_device *hdev, u64 event_mask);
3693e65e175bSOded Gabbay
3694e65e175bSOded Gabbay int hl_sysfs_init(struct hl_device *hdev);
3695e65e175bSOded Gabbay void hl_sysfs_fini(struct hl_device *hdev);
3696e65e175bSOded Gabbay
3697e65e175bSOded Gabbay int hl_hwmon_init(struct hl_device *hdev);
3698e65e175bSOded Gabbay void hl_hwmon_fini(struct hl_device *hdev);
3699e65e175bSOded Gabbay void hl_hwmon_release_resources(struct hl_device *hdev);
3700e65e175bSOded Gabbay
3701e65e175bSOded Gabbay int hl_cb_create(struct hl_device *hdev, struct hl_mem_mgr *mmg,
3702e65e175bSOded Gabbay struct hl_ctx *ctx, u32 cb_size, bool internal_cb,
3703e65e175bSOded Gabbay bool map_cb, u64 *handle);
3704e65e175bSOded Gabbay int hl_cb_destroy(struct hl_mem_mgr *mmg, u64 cb_handle);
3705e65e175bSOded Gabbay int hl_hw_block_mmap(struct hl_fpriv *hpriv, struct vm_area_struct *vma);
3706e65e175bSOded Gabbay struct hl_cb *hl_cb_get(struct hl_mem_mgr *mmg, u64 handle);
3707e65e175bSOded Gabbay void hl_cb_put(struct hl_cb *cb);
3708e65e175bSOded Gabbay struct hl_cb *hl_cb_kernel_create(struct hl_device *hdev, u32 cb_size,
3709e65e175bSOded Gabbay bool internal_cb);
3710e65e175bSOded Gabbay int hl_cb_pool_init(struct hl_device *hdev);
3711e65e175bSOded Gabbay int hl_cb_pool_fini(struct hl_device *hdev);
3712e65e175bSOded Gabbay int hl_cb_va_pool_init(struct hl_ctx *ctx);
3713e65e175bSOded Gabbay void hl_cb_va_pool_fini(struct hl_ctx *ctx);
3714e65e175bSOded Gabbay
3715e65e175bSOded Gabbay void hl_cs_rollback_all(struct hl_device *hdev, bool skip_wq_flush);
3716e65e175bSOded Gabbay struct hl_cs_job *hl_cs_allocate_job(struct hl_device *hdev,
3717e65e175bSOded Gabbay enum hl_queue_type queue_type, bool is_kernel_allocated_cb);
3718e65e175bSOded Gabbay void hl_sob_reset_error(struct kref *ref);
3719e65e175bSOded Gabbay int hl_gen_sob_mask(u16 sob_base, u8 sob_mask, u8 *mask);
3720e65e175bSOded Gabbay void hl_fence_put(struct hl_fence *fence);
3721e65e175bSOded Gabbay void hl_fences_put(struct hl_fence **fence, int len);
3722e65e175bSOded Gabbay void hl_fence_get(struct hl_fence *fence);
3723e65e175bSOded Gabbay void cs_get(struct hl_cs *cs);
3724e65e175bSOded Gabbay bool cs_needs_completion(struct hl_cs *cs);
3725e65e175bSOded Gabbay bool cs_needs_timeout(struct hl_cs *cs);
3726e65e175bSOded Gabbay bool is_staged_cs_last_exists(struct hl_device *hdev, struct hl_cs *cs);
3727e65e175bSOded Gabbay struct hl_cs *hl_staged_cs_find_first(struct hl_device *hdev, u64 cs_seq);
3728e65e175bSOded Gabbay void hl_multi_cs_completion_init(struct hl_device *hdev);
3729d43bce6eSTomer Tayar u32 hl_get_active_cs_num(struct hl_device *hdev);
3730e65e175bSOded Gabbay
3731e65e175bSOded Gabbay void goya_set_asic_funcs(struct hl_device *hdev);
3732e65e175bSOded Gabbay void gaudi_set_asic_funcs(struct hl_device *hdev);
3733e65e175bSOded Gabbay void gaudi2_set_asic_funcs(struct hl_device *hdev);
3734e65e175bSOded Gabbay
3735e65e175bSOded Gabbay int hl_vm_ctx_init(struct hl_ctx *ctx);
3736e65e175bSOded Gabbay void hl_vm_ctx_fini(struct hl_ctx *ctx);
3737e65e175bSOded Gabbay
3738e65e175bSOded Gabbay int hl_vm_init(struct hl_device *hdev);
3739e65e175bSOded Gabbay void hl_vm_fini(struct hl_device *hdev);
3740e65e175bSOded Gabbay
3741e65e175bSOded Gabbay void hl_hw_block_mem_init(struct hl_ctx *ctx);
3742e65e175bSOded Gabbay void hl_hw_block_mem_fini(struct hl_ctx *ctx);
3743e65e175bSOded Gabbay
3744e65e175bSOded Gabbay u64 hl_reserve_va_block(struct hl_device *hdev, struct hl_ctx *ctx,
3745e65e175bSOded Gabbay enum hl_va_range_type type, u64 size, u32 alignment);
3746e65e175bSOded Gabbay int hl_unreserve_va_block(struct hl_device *hdev, struct hl_ctx *ctx,
3747e65e175bSOded Gabbay u64 start_addr, u64 size);
3748e65e175bSOded Gabbay int hl_pin_host_memory(struct hl_device *hdev, u64 addr, u64 size,
3749e65e175bSOded Gabbay struct hl_userptr *userptr);
3750e65e175bSOded Gabbay void hl_unpin_host_memory(struct hl_device *hdev, struct hl_userptr *userptr);
3751e65e175bSOded Gabbay void hl_userptr_delete_list(struct hl_device *hdev,
3752e65e175bSOded Gabbay struct list_head *userptr_list);
3753e65e175bSOded Gabbay bool hl_userptr_is_pinned(struct hl_device *hdev, u64 addr, u32 size,
3754e65e175bSOded Gabbay struct list_head *userptr_list,
3755e65e175bSOded Gabbay struct hl_userptr **userptr);
3756e65e175bSOded Gabbay
3757e65e175bSOded Gabbay int hl_mmu_init(struct hl_device *hdev);
3758e65e175bSOded Gabbay void hl_mmu_fini(struct hl_device *hdev);
3759e65e175bSOded Gabbay int hl_mmu_ctx_init(struct hl_ctx *ctx);
3760e65e175bSOded Gabbay void hl_mmu_ctx_fini(struct hl_ctx *ctx);
3761e65e175bSOded Gabbay int hl_mmu_map_page(struct hl_ctx *ctx, u64 virt_addr, u64 phys_addr,
3762e65e175bSOded Gabbay u32 page_size, bool flush_pte);
3763e65e175bSOded Gabbay int hl_mmu_get_real_page_size(struct hl_device *hdev, struct hl_mmu_properties *mmu_prop,
3764e65e175bSOded Gabbay u32 page_size, u32 *real_page_size, bool is_dram_addr);
3765e65e175bSOded Gabbay int hl_mmu_unmap_page(struct hl_ctx *ctx, u64 virt_addr, u32 page_size,
3766e65e175bSOded Gabbay bool flush_pte);
3767e65e175bSOded Gabbay int hl_mmu_map_contiguous(struct hl_ctx *ctx, u64 virt_addr,
3768e65e175bSOded Gabbay u64 phys_addr, u32 size);
3769e65e175bSOded Gabbay int hl_mmu_unmap_contiguous(struct hl_ctx *ctx, u64 virt_addr, u32 size);
3770e65e175bSOded Gabbay int hl_mmu_invalidate_cache(struct hl_device *hdev, bool is_hard, u32 flags);
3771e65e175bSOded Gabbay int hl_mmu_invalidate_cache_range(struct hl_device *hdev, bool is_hard,
3772e65e175bSOded Gabbay u32 flags, u32 asid, u64 va, u64 size);
3773e65e175bSOded Gabbay int hl_mmu_prefetch_cache_range(struct hl_ctx *ctx, u32 flags, u32 asid, u64 va, u64 size);
3774e65e175bSOded Gabbay u64 hl_mmu_get_next_hop_addr(struct hl_ctx *ctx, u64 curr_pte);
3775e65e175bSOded Gabbay u64 hl_mmu_get_hop_pte_phys_addr(struct hl_ctx *ctx, struct hl_mmu_properties *mmu_prop,
3776e65e175bSOded Gabbay u8 hop_idx, u64 hop_addr, u64 virt_addr);
3777e65e175bSOded Gabbay void hl_mmu_hr_flush(struct hl_ctx *ctx);
3778e65e175bSOded Gabbay int hl_mmu_hr_init(struct hl_device *hdev, struct hl_mmu_hr_priv *hr_priv, u32 hop_table_size,
3779e65e175bSOded Gabbay u64 pgt_size);
3780e65e175bSOded Gabbay void hl_mmu_hr_fini(struct hl_device *hdev, struct hl_mmu_hr_priv *hr_priv, u32 hop_table_size);
3781e65e175bSOded Gabbay void hl_mmu_hr_free_hop_remove_pgt(struct pgt_info *pgt_info, struct hl_mmu_hr_priv *hr_priv,
3782e65e175bSOded Gabbay u32 hop_table_size);
3783e65e175bSOded Gabbay u64 hl_mmu_hr_pte_phys_to_virt(struct hl_ctx *ctx, struct pgt_info *pgt, u64 phys_pte_addr,
3784e65e175bSOded Gabbay u32 hop_table_size);
3785e65e175bSOded Gabbay void hl_mmu_hr_write_pte(struct hl_ctx *ctx, struct pgt_info *pgt_info, u64 phys_pte_addr,
3786e65e175bSOded Gabbay u64 val, u32 hop_table_size);
3787e65e175bSOded Gabbay void hl_mmu_hr_clear_pte(struct hl_ctx *ctx, struct pgt_info *pgt_info, u64 phys_pte_addr,
3788e65e175bSOded Gabbay u32 hop_table_size);
3789e65e175bSOded Gabbay int hl_mmu_hr_put_pte(struct hl_ctx *ctx, struct pgt_info *pgt_info, struct hl_mmu_hr_priv *hr_priv,
3790e65e175bSOded Gabbay u32 hop_table_size);
3791e65e175bSOded Gabbay void hl_mmu_hr_get_pte(struct hl_ctx *ctx, struct hl_hr_mmu_funcs *hr_func, u64 phys_hop_addr);
3792e65e175bSOded Gabbay struct pgt_info *hl_mmu_hr_get_next_hop_pgt_info(struct hl_ctx *ctx,
3793e65e175bSOded Gabbay struct hl_hr_mmu_funcs *hr_func,
3794e65e175bSOded Gabbay u64 curr_pte);
3795e65e175bSOded Gabbay struct pgt_info *hl_mmu_hr_alloc_hop(struct hl_ctx *ctx, struct hl_mmu_hr_priv *hr_priv,
3796e65e175bSOded Gabbay struct hl_hr_mmu_funcs *hr_func,
3797e65e175bSOded Gabbay struct hl_mmu_properties *mmu_prop);
3798e65e175bSOded Gabbay struct pgt_info *hl_mmu_hr_get_alloc_next_hop(struct hl_ctx *ctx,
3799e65e175bSOded Gabbay struct hl_mmu_hr_priv *hr_priv,
3800e65e175bSOded Gabbay struct hl_hr_mmu_funcs *hr_func,
3801e65e175bSOded Gabbay struct hl_mmu_properties *mmu_prop,
3802e65e175bSOded Gabbay u64 curr_pte, bool *is_new_hop);
3803e65e175bSOded Gabbay int hl_mmu_hr_get_tlb_info(struct hl_ctx *ctx, u64 virt_addr, struct hl_mmu_hop_info *hops,
3804e65e175bSOded Gabbay struct hl_hr_mmu_funcs *hr_func);
3805e65e175bSOded Gabbay int hl_mmu_if_set_funcs(struct hl_device *hdev);
3806e65e175bSOded Gabbay void hl_mmu_v1_set_funcs(struct hl_device *hdev, struct hl_mmu_funcs *mmu);
3807e65e175bSOded Gabbay void hl_mmu_v2_hr_set_funcs(struct hl_device *hdev, struct hl_mmu_funcs *mmu);
3808e65e175bSOded Gabbay int hl_mmu_va_to_pa(struct hl_ctx *ctx, u64 virt_addr, u64 *phys_addr);
3809e65e175bSOded Gabbay int hl_mmu_get_tlb_info(struct hl_ctx *ctx, u64 virt_addr,
3810e65e175bSOded Gabbay struct hl_mmu_hop_info *hops);
3811e65e175bSOded Gabbay u64 hl_mmu_scramble_addr(struct hl_device *hdev, u64 addr);
3812e65e175bSOded Gabbay u64 hl_mmu_descramble_addr(struct hl_device *hdev, u64 addr);
3813e65e175bSOded Gabbay bool hl_is_dram_va(struct hl_device *hdev, u64 virt_addr);
3814e65e175bSOded Gabbay
3815e65e175bSOded Gabbay int hl_fw_load_fw_to_device(struct hl_device *hdev, const char *fw_name,
3816e65e175bSOded Gabbay void __iomem *dst, u32 src_offset, u32 size);
3817e65e175bSOded Gabbay int hl_fw_send_pci_access_msg(struct hl_device *hdev, u32 opcode, u64 value);
3818e65e175bSOded Gabbay int hl_fw_send_cpu_message(struct hl_device *hdev, u32 hw_queue_id, u32 *msg,
3819e65e175bSOded Gabbay u16 len, u32 timeout, u64 *result);
3820e65e175bSOded Gabbay int hl_fw_unmask_irq(struct hl_device *hdev, u16 event_type);
3821e65e175bSOded Gabbay int hl_fw_unmask_irq_arr(struct hl_device *hdev, const u32 *irq_arr,
3822e65e175bSOded Gabbay size_t irq_arr_size);
3823e65e175bSOded Gabbay int hl_fw_test_cpu_queue(struct hl_device *hdev);
3824e65e175bSOded Gabbay void *hl_fw_cpu_accessible_dma_pool_alloc(struct hl_device *hdev, size_t size,
3825e65e175bSOded Gabbay dma_addr_t *dma_handle);
3826e65e175bSOded Gabbay void hl_fw_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size,
3827e65e175bSOded Gabbay void *vaddr);
3828e65e175bSOded Gabbay int hl_fw_send_heartbeat(struct hl_device *hdev);
3829e65e175bSOded Gabbay int hl_fw_cpucp_info_get(struct hl_device *hdev,
3830e65e175bSOded Gabbay u32 sts_boot_dev_sts0_reg,
3831e65e175bSOded Gabbay u32 sts_boot_dev_sts1_reg, u32 boot_err0_reg,
3832e65e175bSOded Gabbay u32 boot_err1_reg);
3833e65e175bSOded Gabbay int hl_fw_cpucp_handshake(struct hl_device *hdev,
3834e65e175bSOded Gabbay u32 sts_boot_dev_sts0_reg,
3835e65e175bSOded Gabbay u32 sts_boot_dev_sts1_reg, u32 boot_err0_reg,
3836e65e175bSOded Gabbay u32 boot_err1_reg);
3837e65e175bSOded Gabbay int hl_fw_get_eeprom_data(struct hl_device *hdev, void *data, size_t max_size);
3838e65e175bSOded Gabbay int hl_fw_get_monitor_dump(struct hl_device *hdev, void *data);
3839e65e175bSOded Gabbay int hl_fw_cpucp_pci_counters_get(struct hl_device *hdev,
3840e65e175bSOded Gabbay struct hl_info_pci_counters *counters);
3841e65e175bSOded Gabbay int hl_fw_cpucp_total_energy_get(struct hl_device *hdev,
3842e65e175bSOded Gabbay u64 *total_energy);
3843e65e175bSOded Gabbay int get_used_pll_index(struct hl_device *hdev, u32 input_pll_index,
3844e65e175bSOded Gabbay enum pll_index *pll_index);
3845e65e175bSOded Gabbay int hl_fw_cpucp_pll_info_get(struct hl_device *hdev, u32 pll_index,
3846e65e175bSOded Gabbay u16 *pll_freq_arr);
3847e65e175bSOded Gabbay int hl_fw_cpucp_power_get(struct hl_device *hdev, u64 *power);
3848e65e175bSOded Gabbay void hl_fw_ask_hard_reset_without_linux(struct hl_device *hdev);
3849e65e175bSOded Gabbay void hl_fw_ask_halt_machine_without_linux(struct hl_device *hdev);
3850e65e175bSOded Gabbay int hl_fw_init_cpu(struct hl_device *hdev);
3851e65e175bSOded Gabbay int hl_fw_wait_preboot_ready(struct hl_device *hdev);
3852e65e175bSOded Gabbay int hl_fw_read_preboot_status(struct hl_device *hdev);
3853e65e175bSOded Gabbay int hl_fw_dynamic_send_protocol_cmd(struct hl_device *hdev,
3854e65e175bSOded Gabbay struct fw_load_mgr *fw_loader,
3855e65e175bSOded Gabbay enum comms_cmd cmd, unsigned int size,
3856e65e175bSOded Gabbay bool wait_ok, u32 timeout);
3857e65e175bSOded Gabbay int hl_fw_dram_replaced_row_get(struct hl_device *hdev,
3858e65e175bSOded Gabbay struct cpucp_hbm_row_info *info);
3859e65e175bSOded Gabbay int hl_fw_dram_pending_row_get(struct hl_device *hdev, u32 *pend_rows_num);
3860e65e175bSOded Gabbay int hl_fw_cpucp_engine_core_asid_set(struct hl_device *hdev, u32 asid);
3861e65e175bSOded Gabbay int hl_fw_send_device_activity(struct hl_device *hdev, bool open);
3862cc7b790dSDafna Hirschfeld int hl_fw_send_soft_reset(struct hl_device *hdev);
3863e65e175bSOded Gabbay int hl_pci_bars_map(struct hl_device *hdev, const char * const name[3],
3864e65e175bSOded Gabbay bool is_wc[3]);
3865e65e175bSOded Gabbay int hl_pci_elbi_read(struct hl_device *hdev, u64 addr, u32 *data);
3866e65e175bSOded Gabbay int hl_pci_iatu_write(struct hl_device *hdev, u32 addr, u32 data);
3867e65e175bSOded Gabbay int hl_pci_set_inbound_region(struct hl_device *hdev, u8 region,
3868e65e175bSOded Gabbay struct hl_inbound_pci_region *pci_region);
3869e65e175bSOded Gabbay int hl_pci_set_outbound_region(struct hl_device *hdev,
3870e65e175bSOded Gabbay struct hl_outbound_pci_region *pci_region);
3871e65e175bSOded Gabbay enum pci_region hl_get_pci_memory_region(struct hl_device *hdev, u64 addr);
3872e65e175bSOded Gabbay int hl_pci_init(struct hl_device *hdev);
3873e65e175bSOded Gabbay void hl_pci_fini(struct hl_device *hdev);
3874e65e175bSOded Gabbay
3875e65e175bSOded Gabbay long hl_fw_get_frequency(struct hl_device *hdev, u32 pll_index, bool curr);
3876e65e175bSOded Gabbay void hl_fw_set_frequency(struct hl_device *hdev, u32 pll_index, u64 freq);
3877e65e175bSOded Gabbay int hl_get_temperature(struct hl_device *hdev, int sensor_index, u32 attr, long *value);
3878e65e175bSOded Gabbay int hl_set_temperature(struct hl_device *hdev, int sensor_index, u32 attr, long value);
3879e65e175bSOded Gabbay int hl_get_voltage(struct hl_device *hdev, int sensor_index, u32 attr, long *value);
3880e65e175bSOded Gabbay int hl_get_current(struct hl_device *hdev, int sensor_index, u32 attr, long *value);
3881e65e175bSOded Gabbay int hl_get_fan_speed(struct hl_device *hdev, int sensor_index, u32 attr, long *value);
3882e65e175bSOded Gabbay int hl_get_pwm_info(struct hl_device *hdev, int sensor_index, u32 attr, long *value);
3883e65e175bSOded Gabbay void hl_set_pwm_info(struct hl_device *hdev, int sensor_index, u32 attr, long value);
3884e65e175bSOded Gabbay long hl_fw_get_max_power(struct hl_device *hdev);
3885e65e175bSOded Gabbay void hl_fw_set_max_power(struct hl_device *hdev);
3886e65e175bSOded Gabbay int hl_fw_get_sec_attest_info(struct hl_device *hdev, struct cpucp_sec_attest_info *sec_attest_info,
3887e65e175bSOded Gabbay u32 nonce);
3888e65e175bSOded Gabbay int hl_set_voltage(struct hl_device *hdev, int sensor_index, u32 attr, long value);
3889e65e175bSOded Gabbay int hl_set_current(struct hl_device *hdev, int sensor_index, u32 attr, long value);
3890e65e175bSOded Gabbay int hl_set_power(struct hl_device *hdev, int sensor_index, u32 attr, long value);
3891e65e175bSOded Gabbay int hl_get_power(struct hl_device *hdev, int sensor_index, u32 attr, long *value);
3892e65e175bSOded Gabbay int hl_fw_get_clk_rate(struct hl_device *hdev, u32 *cur_clk, u32 *max_clk);
3893e65e175bSOded Gabbay void hl_fw_set_pll_profile(struct hl_device *hdev);
3894e65e175bSOded Gabbay void hl_sysfs_add_dev_clk_attr(struct hl_device *hdev, struct attribute_group *dev_clk_attr_grp);
3895e65e175bSOded Gabbay void hl_sysfs_add_dev_vrm_attr(struct hl_device *hdev, struct attribute_group *dev_vrm_attr_grp);
3896e65e175bSOded Gabbay int hl_fw_send_generic_request(struct hl_device *hdev, enum hl_passthrough_type sub_opcode,
3897e65e175bSOded Gabbay dma_addr_t buff, u32 *size);
3898e65e175bSOded Gabbay
3899e65e175bSOded Gabbay void hw_sob_get(struct hl_hw_sob *hw_sob);
3900e65e175bSOded Gabbay void hw_sob_put(struct hl_hw_sob *hw_sob);
3901e65e175bSOded Gabbay void hl_encaps_release_handle_and_put_ctx(struct kref *ref);
3902e65e175bSOded Gabbay void hl_encaps_release_handle_and_put_sob_ctx(struct kref *ref);
3903e65e175bSOded Gabbay void hl_hw_queue_encaps_sig_set_sob_info(struct hl_device *hdev,
3904e65e175bSOded Gabbay struct hl_cs *cs, struct hl_cs_job *job,
3905e65e175bSOded Gabbay struct hl_cs_compl *cs_cmpl);
3906e65e175bSOded Gabbay
3907e65e175bSOded Gabbay int hl_dec_init(struct hl_device *hdev);
3908e65e175bSOded Gabbay void hl_dec_fini(struct hl_device *hdev);
3909e65e175bSOded Gabbay void hl_dec_ctx_fini(struct hl_ctx *ctx);
3910e65e175bSOded Gabbay
3911e65e175bSOded Gabbay void hl_release_pending_user_interrupts(struct hl_device *hdev);
39129a4e44a4SKoby Elbaz void hl_abort_waiting_for_cs_completions(struct hl_device *hdev);
3913e65e175bSOded Gabbay int hl_cs_signal_sob_wraparound_handler(struct hl_device *hdev, u32 q_idx,
3914e65e175bSOded Gabbay struct hl_hw_sob **hw_sob, u32 count, bool encaps_sig);
3915e65e175bSOded Gabbay
3916e65e175bSOded Gabbay int hl_state_dump(struct hl_device *hdev);
3917e65e175bSOded Gabbay const char *hl_state_dump_get_sync_name(struct hl_device *hdev, u32 sync_id);
3918e65e175bSOded Gabbay const char *hl_state_dump_get_monitor_name(struct hl_device *hdev,
3919e65e175bSOded Gabbay struct hl_mon_state_dump *mon);
3920e65e175bSOded Gabbay void hl_state_dump_free_sync_to_engine_map(struct hl_sync_to_engine_map *map);
3921e65e175bSOded Gabbay __printf(4, 5) int hl_snprintf_resize(char **buf, size_t *size, size_t *offset,
3922e65e175bSOded Gabbay const char *format, ...);
3923e65e175bSOded Gabbay char *hl_format_as_binary(char *buf, size_t buf_len, u32 n);
3924e65e175bSOded Gabbay const char *hl_sync_engine_to_string(enum hl_sync_engine_type engine_type);
3925e65e175bSOded Gabbay
3926e2a079a2STomer Tayar void hl_mem_mgr_init(struct device *dev, struct hl_mem_mgr *mmg);
3927e65e175bSOded Gabbay void hl_mem_mgr_fini(struct hl_mem_mgr *mmg);
39282e8e9a89STomer Tayar void hl_mem_mgr_idr_destroy(struct hl_mem_mgr *mmg);
3929e65e175bSOded Gabbay int hl_mem_mgr_mmap(struct hl_mem_mgr *mmg, struct vm_area_struct *vma,
3930e65e175bSOded Gabbay void *args);
3931e65e175bSOded Gabbay struct hl_mmap_mem_buf *hl_mmap_mem_buf_get(struct hl_mem_mgr *mmg,
3932e65e175bSOded Gabbay u64 handle);
3933e65e175bSOded Gabbay int hl_mmap_mem_buf_put_handle(struct hl_mem_mgr *mmg, u64 handle);
3934e65e175bSOded Gabbay int hl_mmap_mem_buf_put(struct hl_mmap_mem_buf *buf);
3935e65e175bSOded Gabbay struct hl_mmap_mem_buf *
3936e65e175bSOded Gabbay hl_mmap_mem_buf_alloc(struct hl_mem_mgr *mmg,
3937e65e175bSOded Gabbay struct hl_mmap_mem_buf_behavior *behavior, gfp_t gfp,
3938e65e175bSOded Gabbay void *args);
3939e65e175bSOded Gabbay __printf(2, 3) void hl_engine_data_sprintf(struct engines_data *e, const char *fmt, ...);
3940e65e175bSOded Gabbay void hl_capture_razwi(struct hl_device *hdev, u64 addr, u16 *engine_id, u16 num_of_engines,
3941e65e175bSOded Gabbay u8 flags);
3942e65e175bSOded Gabbay void hl_handle_razwi(struct hl_device *hdev, u64 addr, u16 *engine_id, u16 num_of_engines,
3943e65e175bSOded Gabbay u8 flags, u64 *event_mask);
3944e65e175bSOded Gabbay void hl_capture_page_fault(struct hl_device *hdev, u64 addr, u16 eng_id, bool is_pmmu);
3945e65e175bSOded Gabbay void hl_handle_page_fault(struct hl_device *hdev, u64 addr, u16 eng_id, bool is_pmmu,
3946e65e175bSOded Gabbay u64 *event_mask);
3947313e9f63SMoti Haimovski void hl_handle_critical_hw_err(struct hl_device *hdev, u16 event_id, u64 *event_mask);
3948313e9f63SMoti Haimovski void hl_handle_fw_err(struct hl_device *hdev, struct hl_info_fw_err_info *info);
3949e6f49e96SDani Liberman void hl_enable_err_info_capture(struct hl_error_info *captured_err_info);
3950e65e175bSOded Gabbay
3951e65e175bSOded Gabbay #ifdef CONFIG_DEBUG_FS
3952e65e175bSOded Gabbay
3953e65e175bSOded Gabbay void hl_debugfs_init(void);
3954e65e175bSOded Gabbay void hl_debugfs_fini(void);
39553b9abb4fSTomer Tayar int hl_debugfs_device_init(struct hl_device *hdev);
39563b9abb4fSTomer Tayar void hl_debugfs_device_fini(struct hl_device *hdev);
3957e65e175bSOded Gabbay void hl_debugfs_add_device(struct hl_device *hdev);
3958e65e175bSOded Gabbay void hl_debugfs_remove_device(struct hl_device *hdev);
3959e65e175bSOded Gabbay void hl_debugfs_add_file(struct hl_fpriv *hpriv);
3960e65e175bSOded Gabbay void hl_debugfs_remove_file(struct hl_fpriv *hpriv);
3961e65e175bSOded Gabbay void hl_debugfs_add_cb(struct hl_cb *cb);
3962e65e175bSOded Gabbay void hl_debugfs_remove_cb(struct hl_cb *cb);
3963e65e175bSOded Gabbay void hl_debugfs_add_cs(struct hl_cs *cs);
3964e65e175bSOded Gabbay void hl_debugfs_remove_cs(struct hl_cs *cs);
3965e65e175bSOded Gabbay void hl_debugfs_add_job(struct hl_device *hdev, struct hl_cs_job *job);
3966e65e175bSOded Gabbay void hl_debugfs_remove_job(struct hl_device *hdev, struct hl_cs_job *job);
3967e65e175bSOded Gabbay void hl_debugfs_add_userptr(struct hl_device *hdev, struct hl_userptr *userptr);
3968e65e175bSOded Gabbay void hl_debugfs_remove_userptr(struct hl_device *hdev,
3969e65e175bSOded Gabbay struct hl_userptr *userptr);
3970e65e175bSOded Gabbay void hl_debugfs_add_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx);
3971e65e175bSOded Gabbay void hl_debugfs_remove_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx);
3972e65e175bSOded Gabbay void hl_debugfs_set_state_dump(struct hl_device *hdev, char *data,
3973e65e175bSOded Gabbay unsigned long length);
3974e65e175bSOded Gabbay
3975e65e175bSOded Gabbay #else
3976e65e175bSOded Gabbay
hl_debugfs_init(void)3977e65e175bSOded Gabbay static inline void __init hl_debugfs_init(void)
3978e65e175bSOded Gabbay {
3979e65e175bSOded Gabbay }
3980e65e175bSOded Gabbay
hl_debugfs_fini(void)3981e65e175bSOded Gabbay static inline void hl_debugfs_fini(void)
3982e65e175bSOded Gabbay {
3983e65e175bSOded Gabbay }
3984e65e175bSOded Gabbay
hl_debugfs_device_init(struct hl_device * hdev)398578e9b217SArnd Bergmann static inline int hl_debugfs_device_init(struct hl_device *hdev)
398678e9b217SArnd Bergmann {
398778e9b217SArnd Bergmann return 0;
398878e9b217SArnd Bergmann }
398978e9b217SArnd Bergmann
hl_debugfs_device_fini(struct hl_device * hdev)399078e9b217SArnd Bergmann static inline void hl_debugfs_device_fini(struct hl_device *hdev)
399178e9b217SArnd Bergmann {
399278e9b217SArnd Bergmann }
399378e9b217SArnd Bergmann
hl_debugfs_add_device(struct hl_device * hdev)3994e65e175bSOded Gabbay static inline void hl_debugfs_add_device(struct hl_device *hdev)
3995e65e175bSOded Gabbay {
3996e65e175bSOded Gabbay }
3997e65e175bSOded Gabbay
hl_debugfs_remove_device(struct hl_device * hdev)3998e65e175bSOded Gabbay static inline void hl_debugfs_remove_device(struct hl_device *hdev)
3999e65e175bSOded Gabbay {
4000e65e175bSOded Gabbay }
4001e65e175bSOded Gabbay
hl_debugfs_add_file(struct hl_fpriv * hpriv)4002e65e175bSOded Gabbay static inline void hl_debugfs_add_file(struct hl_fpriv *hpriv)
4003e65e175bSOded Gabbay {
4004e65e175bSOded Gabbay }
4005e65e175bSOded Gabbay
hl_debugfs_remove_file(struct hl_fpriv * hpriv)4006e65e175bSOded Gabbay static inline void hl_debugfs_remove_file(struct hl_fpriv *hpriv)
4007e65e175bSOded Gabbay {
4008e65e175bSOded Gabbay }
4009e65e175bSOded Gabbay
hl_debugfs_add_cb(struct hl_cb * cb)4010e65e175bSOded Gabbay static inline void hl_debugfs_add_cb(struct hl_cb *cb)
4011e65e175bSOded Gabbay {
4012e65e175bSOded Gabbay }
4013e65e175bSOded Gabbay
hl_debugfs_remove_cb(struct hl_cb * cb)4014e65e175bSOded Gabbay static inline void hl_debugfs_remove_cb(struct hl_cb *cb)
4015e65e175bSOded Gabbay {
4016e65e175bSOded Gabbay }
4017e65e175bSOded Gabbay
hl_debugfs_add_cs(struct hl_cs * cs)4018e65e175bSOded Gabbay static inline void hl_debugfs_add_cs(struct hl_cs *cs)
4019e65e175bSOded Gabbay {
4020e65e175bSOded Gabbay }
4021e65e175bSOded Gabbay
hl_debugfs_remove_cs(struct hl_cs * cs)4022e65e175bSOded Gabbay static inline void hl_debugfs_remove_cs(struct hl_cs *cs)
4023e65e175bSOded Gabbay {
4024e65e175bSOded Gabbay }
4025e65e175bSOded Gabbay
hl_debugfs_add_job(struct hl_device * hdev,struct hl_cs_job * job)4026e65e175bSOded Gabbay static inline void hl_debugfs_add_job(struct hl_device *hdev,
4027e65e175bSOded Gabbay struct hl_cs_job *job)
4028e65e175bSOded Gabbay {
4029e65e175bSOded Gabbay }
4030e65e175bSOded Gabbay
hl_debugfs_remove_job(struct hl_device * hdev,struct hl_cs_job * job)4031e65e175bSOded Gabbay static inline void hl_debugfs_remove_job(struct hl_device *hdev,
4032e65e175bSOded Gabbay struct hl_cs_job *job)
4033e65e175bSOded Gabbay {
4034e65e175bSOded Gabbay }
4035e65e175bSOded Gabbay
hl_debugfs_add_userptr(struct hl_device * hdev,struct hl_userptr * userptr)4036e65e175bSOded Gabbay static inline void hl_debugfs_add_userptr(struct hl_device *hdev,
4037e65e175bSOded Gabbay struct hl_userptr *userptr)
4038e65e175bSOded Gabbay {
4039e65e175bSOded Gabbay }
4040e65e175bSOded Gabbay
hl_debugfs_remove_userptr(struct hl_device * hdev,struct hl_userptr * userptr)4041e65e175bSOded Gabbay static inline void hl_debugfs_remove_userptr(struct hl_device *hdev,
4042e65e175bSOded Gabbay struct hl_userptr *userptr)
4043e65e175bSOded Gabbay {
4044e65e175bSOded Gabbay }
4045e65e175bSOded Gabbay
hl_debugfs_add_ctx_mem_hash(struct hl_device * hdev,struct hl_ctx * ctx)4046e65e175bSOded Gabbay static inline void hl_debugfs_add_ctx_mem_hash(struct hl_device *hdev,
4047e65e175bSOded Gabbay struct hl_ctx *ctx)
4048e65e175bSOded Gabbay {
4049e65e175bSOded Gabbay }
4050e65e175bSOded Gabbay
hl_debugfs_remove_ctx_mem_hash(struct hl_device * hdev,struct hl_ctx * ctx)4051e65e175bSOded Gabbay static inline void hl_debugfs_remove_ctx_mem_hash(struct hl_device *hdev,
4052e65e175bSOded Gabbay struct hl_ctx *ctx)
4053e65e175bSOded Gabbay {
4054e65e175bSOded Gabbay }
4055e65e175bSOded Gabbay
hl_debugfs_set_state_dump(struct hl_device * hdev,char * data,unsigned long length)4056e65e175bSOded Gabbay static inline void hl_debugfs_set_state_dump(struct hl_device *hdev,
4057e65e175bSOded Gabbay char *data, unsigned long length)
4058e65e175bSOded Gabbay {
4059e65e175bSOded Gabbay }
4060e65e175bSOded Gabbay
4061e65e175bSOded Gabbay #endif
4062e65e175bSOded Gabbay
4063e65e175bSOded Gabbay /* Security */
4064e65e175bSOded Gabbay int hl_unsecure_register(struct hl_device *hdev, u32 mm_reg_addr, int offset,
4065e65e175bSOded Gabbay const u32 pb_blocks[], struct hl_block_glbl_sec sgs_array[],
4066e65e175bSOded Gabbay int array_size);
4067e65e175bSOded Gabbay int hl_unsecure_registers(struct hl_device *hdev, const u32 mm_reg_array[],
4068e65e175bSOded Gabbay int mm_array_size, int offset, const u32 pb_blocks[],
4069e65e175bSOded Gabbay struct hl_block_glbl_sec sgs_array[], int blocks_array_size);
4070e65e175bSOded Gabbay void hl_config_glbl_sec(struct hl_device *hdev, const u32 pb_blocks[],
4071e65e175bSOded Gabbay struct hl_block_glbl_sec sgs_array[], u32 block_offset,
4072e65e175bSOded Gabbay int array_size);
4073e65e175bSOded Gabbay void hl_secure_block(struct hl_device *hdev,
4074e65e175bSOded Gabbay struct hl_block_glbl_sec sgs_array[], int array_size);
4075e65e175bSOded Gabbay int hl_init_pb_with_mask(struct hl_device *hdev, u32 num_dcores,
4076e65e175bSOded Gabbay u32 dcore_offset, u32 num_instances, u32 instance_offset,
4077e65e175bSOded Gabbay const u32 pb_blocks[], u32 blocks_array_size,
4078e65e175bSOded Gabbay const u32 *regs_array, u32 regs_array_size, u64 mask);
4079e65e175bSOded Gabbay int hl_init_pb(struct hl_device *hdev, u32 num_dcores, u32 dcore_offset,
4080e65e175bSOded Gabbay u32 num_instances, u32 instance_offset,
4081e65e175bSOded Gabbay const u32 pb_blocks[], u32 blocks_array_size,
4082e65e175bSOded Gabbay const u32 *regs_array, u32 regs_array_size);
4083e65e175bSOded Gabbay int hl_init_pb_ranges_with_mask(struct hl_device *hdev, u32 num_dcores,
4084e65e175bSOded Gabbay u32 dcore_offset, u32 num_instances, u32 instance_offset,
4085e65e175bSOded Gabbay const u32 pb_blocks[], u32 blocks_array_size,
4086e65e175bSOded Gabbay const struct range *regs_range_array, u32 regs_range_array_size,
4087e65e175bSOded Gabbay u64 mask);
4088e65e175bSOded Gabbay int hl_init_pb_ranges(struct hl_device *hdev, u32 num_dcores,
4089e65e175bSOded Gabbay u32 dcore_offset, u32 num_instances, u32 instance_offset,
4090e65e175bSOded Gabbay const u32 pb_blocks[], u32 blocks_array_size,
4091e65e175bSOded Gabbay const struct range *regs_range_array,
4092e65e175bSOded Gabbay u32 regs_range_array_size);
4093e65e175bSOded Gabbay int hl_init_pb_single_dcore(struct hl_device *hdev, u32 dcore_offset,
4094e65e175bSOded Gabbay u32 num_instances, u32 instance_offset,
4095e65e175bSOded Gabbay const u32 pb_blocks[], u32 blocks_array_size,
4096e65e175bSOded Gabbay const u32 *regs_array, u32 regs_array_size);
4097e65e175bSOded Gabbay int hl_init_pb_ranges_single_dcore(struct hl_device *hdev, u32 dcore_offset,
4098e65e175bSOded Gabbay u32 num_instances, u32 instance_offset,
4099e65e175bSOded Gabbay const u32 pb_blocks[], u32 blocks_array_size,
4100e65e175bSOded Gabbay const struct range *regs_range_array,
4101e65e175bSOded Gabbay u32 regs_range_array_size);
4102e65e175bSOded Gabbay void hl_ack_pb(struct hl_device *hdev, u32 num_dcores, u32 dcore_offset,
4103e65e175bSOded Gabbay u32 num_instances, u32 instance_offset,
4104e65e175bSOded Gabbay const u32 pb_blocks[], u32 blocks_array_size);
4105e65e175bSOded Gabbay void hl_ack_pb_with_mask(struct hl_device *hdev, u32 num_dcores,
4106e65e175bSOded Gabbay u32 dcore_offset, u32 num_instances, u32 instance_offset,
4107e65e175bSOded Gabbay const u32 pb_blocks[], u32 blocks_array_size, u64 mask);
4108e65e175bSOded Gabbay void hl_ack_pb_single_dcore(struct hl_device *hdev, u32 dcore_offset,
4109e65e175bSOded Gabbay u32 num_instances, u32 instance_offset,
4110e65e175bSOded Gabbay const u32 pb_blocks[], u32 blocks_array_size);
4111e65e175bSOded Gabbay
4112e65e175bSOded Gabbay /* IOCTLs */
4113e65e175bSOded Gabbay long hl_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
4114e65e175bSOded Gabbay long hl_ioctl_control(struct file *filep, unsigned int cmd, unsigned long arg);
4115e65e175bSOded Gabbay int hl_cb_ioctl(struct hl_fpriv *hpriv, void *data);
4116e65e175bSOded Gabbay int hl_cs_ioctl(struct hl_fpriv *hpriv, void *data);
4117e65e175bSOded Gabbay int hl_wait_ioctl(struct hl_fpriv *hpriv, void *data);
4118e65e175bSOded Gabbay int hl_mem_ioctl(struct hl_fpriv *hpriv, void *data);
4119e65e175bSOded Gabbay
4120e65e175bSOded Gabbay #endif /* HABANALABSP_H_ */
4121