blob: a2002cbf794b57a554918c1c3c0dd326a29353eb [file] [log] [blame]
Oded Gabbayc4d66342019-02-16 00:39:11 +02001/* SPDX-License-Identifier: GPL-2.0
2 *
3 * Copyright 2016-2019 HabanaLabs, Ltd.
4 * All Rights Reserved.
5 *
6 */
7
8#ifndef HABANALABSP_H_
9#define HABANALABSP_H_
10
Oded Gabbay2f553422020-08-15 16:28:10 +030011#include "../include/common/cpucp_if.h"
Greg Kroah-Hartman7b16a152020-07-28 19:18:51 +020012#include "../include/common/qman_if.h"
Moti Haimovski00e1b592020-10-27 10:55:42 +020013#include "../include/hw_ip/mmu/mmu_general.h"
Ofir Bittondb491e42020-06-18 09:51:16 +030014#include <uapi/misc/habanalabs.h>
Oded Gabbay839c4802019-02-16 00:39:16 +020015
Oded Gabbayc4d66342019-02-16 00:39:11 +020016#include <linux/cdev.h>
Oded Gabbay839c4802019-02-16 00:39:16 +020017#include <linux/iopoll.h>
Oded Gabbay1251f232019-02-16 00:39:18 +020018#include <linux/irqreturn.h>
Oded Gabbayeff6f4a2019-02-16 00:39:21 +020019#include <linux/dma-direction.h>
20#include <linux/scatterlist.h>
Omer Shpigelman0feaf862019-02-16 00:39:22 +020021#include <linux/hashtable.h>
Oded Gabbay639781d2021-04-02 01:43:18 +030022#include <linux/debugfs.h>
Yuri Nudelman938b7932021-06-06 10:28:51 +030023#include <linux/rwsem.h>
Tomer Tayar56004702020-08-18 15:06:56 +030024#include <linux/bitfield.h>
Tomer Tayarba7e3892020-10-25 17:47:22 +020025#include <linux/genalloc.h>
26#include <linux/sched/signal.h>
27#include <linux/io-64-nonatomic-lo-hi.h>
28#include <linux/coresight.h>
Tomer Tayardb1a8dd2021-06-15 10:55:43 +030029#include <linux/dma-buf.h>
Oded Gabbayc4d66342019-02-16 00:39:11 +020030
31#define HL_NAME "habanalabs"
32
Oded Gabbay3174ac92020-08-29 11:51:39 +030033/* Use upper bits of mmap offset to store habana driver specific information.
Ofir Bittond00697f2021-01-05 12:55:06 +020034 * bits[63:61] - Encode mmap type
Oded Gabbay3174ac92020-08-29 11:51:39 +030035 * bits[45:0] - mmap offset value
36 *
37 * NOTE: struct vm_area_struct.vm_pgoff uses offset in pages. Hence, these
38 * defines are w.r.t to PAGE_SIZE
39 */
Ofir Bittond00697f2021-01-05 12:55:06 +020040#define HL_MMAP_TYPE_SHIFT (61 - PAGE_SHIFT)
41#define HL_MMAP_TYPE_MASK (0x7ull << HL_MMAP_TYPE_SHIFT)
42#define HL_MMAP_TYPE_BLOCK (0x4ull << HL_MMAP_TYPE_SHIFT)
Oded Gabbay3174ac92020-08-29 11:51:39 +030043#define HL_MMAP_TYPE_CB (0x2ull << HL_MMAP_TYPE_SHIFT)
44
Ofir Bittond00697f2021-01-05 12:55:06 +020045#define HL_MMAP_OFFSET_VALUE_MASK (0x1FFFFFFFFFFFull >> PAGE_SHIFT)
Oded Gabbay3174ac92020-08-29 11:51:39 +030046#define HL_MMAP_OFFSET_VALUE_GET(off) (off & HL_MMAP_OFFSET_VALUE_MASK)
Oded Gabbaybe5d9262019-02-16 00:39:15 +020047
Ofir Bittonadb51292020-10-08 10:27:42 +030048#define HL_PENDING_RESET_PER_SEC 10
49#define HL_PENDING_RESET_MAX_TRIALS 60 /* 10 minutes */
50#define HL_PENDING_RESET_LONG_SEC 60
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +020051
Omer Shpigelmane09498b2020-05-09 12:18:01 +030052#define HL_HARD_RESET_MAX_TIMEOUT 120
Omer Shpigelman4efb6b22021-06-09 10:17:49 +030053#define HL_PLDM_HARD_RESET_MAX_TIMEOUT (HL_HARD_RESET_MAX_TIMEOUT * 3)
Omer Shpigelmane09498b2020-05-09 12:18:01 +030054
Oded Gabbay839c4802019-02-16 00:39:16 +020055#define HL_DEVICE_TIMEOUT_USEC 1000000 /* 1 s */
56
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +020057#define HL_HEARTBEAT_PER_USEC 5000000 /* 5 s */
58
Oded Gabbayd91389b2019-02-16 00:39:19 +020059#define HL_PLL_LOW_JOB_FREQ_USEC 5000000 /* 5 s */
60
Oded Gabbay2f553422020-08-15 16:28:10 +030061#define HL_CPUCP_INFO_TIMEOUT_USEC 10000000 /* 10s */
62#define HL_CPUCP_EEPROM_TIMEOUT_USEC 10000000 /* 10s */
Tomer Tayar3110c602019-03-04 10:22:09 +020063
Omer Shpigelmana1e537b2019-05-13 14:44:50 +030064#define HL_PCI_ELBI_TIMEOUT_MSEC 10 /* 10ms */
65
Oded Gabbayed0fc502019-07-18 11:14:37 +030066#define HL_SIM_MAX_TIMEOUT_US 10000000 /* 10s */
67
Ofir Bittonab5f5c32021-01-12 18:37:19 +020068#define HL_COMMON_USER_INTERRUPT_ID 0xFFF
69
Yuri Nudelman938b7932021-06-06 10:28:51 +030070#define HL_STATE_DUMP_HIST_LEN 5
71
Bharat Jauhari10cab812021-06-21 09:57:19 +030072/* Default value for device reset trigger , an invalid value */
73#define HL_RESET_TRIGGER_DEFAULT 0xFF
74
Yuri Nudelman938b7932021-06-06 10:28:51 +030075#define OBJ_NAMES_HASH_TABLE_BITS 7 /* 1 << 7 buckets */
76#define SYNC_TO_ENGINE_HASH_TABLE_BITS 7 /* 1 << 7 buckets */
77
Omer Shpigelman0feaf862019-02-16 00:39:22 +020078/* Memory */
79#define MEM_HASH_TABLE_BITS 7 /* 1 << 7 buckets */
80
81/* MMU */
82#define MMU_HASH_TABLE_BITS 7 /* 1 << 7 buckets */
83
Moti Haimovskiccf979e2020-10-05 17:59:29 +030084/**
85 * enum hl_mmu_page_table_locaion - mmu page table location
86 * @MMU_DR_PGT: page-table is located on device DRAM.
87 * @MMU_HR_PGT: page-table is located on host memory.
88 * @MMU_NUM_PGT_LOCATIONS: number of page-table locations currently supported.
89 */
90enum hl_mmu_page_table_location {
91 MMU_DR_PGT = 0, /* device-dram-resident MMU PGT */
92 MMU_HR_PGT, /* host resident MMU PGT */
93 MMU_NUM_PGT_LOCATIONS /* num of PGT locations */
94};
95
Ofir Bitton21e7a342020-05-14 18:25:47 +030096/*
97 * HL_RSVD_SOBS 'sync stream' reserved sync objects per QMAN stream
98 * HL_RSVD_MONS 'sync stream' reserved monitors per QMAN stream
99 */
Ofir Bitton5de406c2020-09-10 10:56:26 +0300100#define HL_RSVD_SOBS 2
101#define HL_RSVD_MONS 1
Omer Shpigelmanb0b5d922020-05-07 13:57:36 +0300102
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300103/*
104 * HL_COLLECTIVE_RSVD_MSTR_MONS 'collective' reserved monitors per QMAN stream
105 */
106#define HL_COLLECTIVE_RSVD_MSTR_MONS 2
107
Omer Shpigelmanb0b5d922020-05-07 13:57:36 +0300108#define HL_MAX_SOB_VAL (1 << 15)
109
Ofir Bittonc16d45f2020-06-02 12:28:27 +0300110#define IS_POWER_OF_2(n) (n != 0 && ((n & (n - 1)) == 0))
111#define IS_MAX_PENDING_CS_VALID(n) (IS_POWER_OF_2(n) && (n > 1))
112
Ofir Bittonf4cbfd22020-06-15 17:45:12 +0300113#define HL_PCI_NUM_BARS 6
114
Ofir Bitton843839b2020-07-19 11:08:09 +0300115#define HL_MAX_DCORES 4
116
Ohad Sharabie42a6400f2021-02-17 20:42:48 +0200117/*
118 * Reset Flags
119 *
120 * - HL_RESET_HARD
121 * If set do hard reset to all engines. If not set reset just
122 * compute/DMA engines.
123 *
124 * - HL_RESET_FROM_RESET_THREAD
125 * Set if the caller is the hard-reset thread
126 *
127 * - HL_RESET_HEARTBEAT
128 * Set if reset is due to heartbeat
Koby Elbaz3e0ca9f2021-05-04 20:10:47 +0300129 *
130 * - HL_RESET_TDR
131 * Set if reset is due to TDR
Ofir Bitton23bace62021-06-08 17:24:52 +0300132 *
133 * - HL_RESET_DEVICE_RELEASE
134 * Set if reset is due to device release
Oded Gabbay8d9aa982021-08-09 22:43:37 +0300135 *
136 * - HL_RESET_FW
137 * F/W will perform the reset. No need to ask it to reset the device. This is relevant
138 * only when running with secured f/w
Bharat Jauhari10cab812021-06-21 09:57:19 +0300139 *
140 * - HL_RESET_FW_FATAL_ERR
141 * Set if reset is due to a fatal error from FW
Ohad Sharabie42a6400f2021-02-17 20:42:48 +0200142 */
Bharat Jauhari10cab812021-06-21 09:57:19 +0300143
Ohad Sharabie42a6400f2021-02-17 20:42:48 +0200144#define HL_RESET_HARD (1 << 0)
145#define HL_RESET_FROM_RESET_THREAD (1 << 1)
146#define HL_RESET_HEARTBEAT (1 << 2)
Koby Elbaz3e0ca9f2021-05-04 20:10:47 +0300147#define HL_RESET_TDR (1 << 3)
Ofir Bitton23bace62021-06-08 17:24:52 +0300148#define HL_RESET_DEVICE_RELEASE (1 << 4)
Oded Gabbay8d9aa982021-08-09 22:43:37 +0300149#define HL_RESET_FW (1 << 5)
Bharat Jauhari10cab812021-06-21 09:57:19 +0300150#define HL_RESET_FW_FATAL_ERR (1 << 6)
Ohad Sharabie42a6400f2021-02-17 20:42:48 +0200151
Ofir Bitton2992c1d2020-09-10 09:40:35 +0300152#define HL_MAX_SOBS_PER_MONITOR 8
153
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200154/**
Ofir Bitton3cf74b32020-09-10 09:17:50 +0300155 * struct hl_gen_wait_properties - properties for generating a wait CB
156 * @data: command buffer
157 * @q_idx: queue id is used to extract fence register address
Ofir Bitton2992c1d2020-09-10 09:40:35 +0300158 * @size: offset in command buffer
159 * @sob_base: SOB base to use in this wait CB
Ofir Bitton3cf74b32020-09-10 09:17:50 +0300160 * @sob_val: SOB value to wait for
161 * @mon_id: monitor to use in this wait CB
Ofir Bitton2992c1d2020-09-10 09:40:35 +0300162 * @sob_mask: each bit represents a SOB offset from sob_base to be used
Ofir Bitton3cf74b32020-09-10 09:17:50 +0300163 */
164struct hl_gen_wait_properties {
165 void *data;
166 u32 q_idx;
Ofir Bitton2992c1d2020-09-10 09:40:35 +0300167 u32 size;
168 u16 sob_base;
Ofir Bitton3cf74b32020-09-10 09:17:50 +0300169 u16 sob_val;
170 u16 mon_id;
Ofir Bitton2992c1d2020-09-10 09:40:35 +0300171 u8 sob_mask;
Ofir Bitton3cf74b32020-09-10 09:17:50 +0300172};
173
174/**
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200175 * struct pgt_info - MMU hop page info.
Omer Shpigelman66542c32019-02-24 09:17:55 +0200176 * @node: hash linked-list node for the pgts shadow hash of pgts.
177 * @phys_addr: physical address of the pgt.
178 * @shadow_addr: shadow hop in the host.
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200179 * @ctx: pointer to the owner ctx.
180 * @num_of_ptes: indicates how many ptes are used in the pgt.
181 *
182 * The MMU page tables hierarchy is placed on the DRAM. When a new level (hop)
183 * is needed during mapping, a new page is allocated and this structure holds
184 * its essential information. During unmapping, if no valid PTEs remained in the
185 * page, it is freed with its pgt_info structure.
186 */
187struct pgt_info {
Omer Shpigelman66542c32019-02-24 09:17:55 +0200188 struct hlist_node node;
189 u64 phys_addr;
190 u64 shadow_addr;
191 struct hl_ctx *ctx;
192 int num_of_ptes;
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200193};
194
Oded Gabbayc4d66342019-02-16 00:39:11 +0200195struct hl_device;
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200196struct hl_fpriv;
Oded Gabbayc4d66342019-02-16 00:39:11 +0200197
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200198/**
Ofir Bittonf4cbfd22020-06-15 17:45:12 +0300199 * enum hl_pci_match_mode - pci match mode per region
200 * @PCI_ADDRESS_MATCH_MODE: address match mode
201 * @PCI_BAR_MATCH_MODE: bar match mode
202 */
203enum hl_pci_match_mode {
204 PCI_ADDRESS_MATCH_MODE,
205 PCI_BAR_MATCH_MODE
206};
207
208/**
Oded Gabbay7e1c07d2020-03-26 12:32:56 +0200209 * enum hl_fw_component - F/W components to read version through registers.
Ohad Sharabi50f036d2021-04-11 15:26:28 +0300210 * @FW_COMP_BOOT_FIT: boot fit.
Oded Gabbay7e1c07d2020-03-26 12:32:56 +0200211 * @FW_COMP_PREBOOT: preboot.
Ohad Sharabib31e59b2021-04-22 10:01:22 +0300212 * @FW_COMP_LINUX: linux.
Oded Gabbay7e1c07d2020-03-26 12:32:56 +0200213 */
214enum hl_fw_component {
Ohad Sharabi50f036d2021-04-11 15:26:28 +0300215 FW_COMP_BOOT_FIT,
Ohad Sharabib31e59b2021-04-22 10:01:22 +0300216 FW_COMP_PREBOOT,
217 FW_COMP_LINUX,
Oded Gabbay7e1c07d2020-03-26 12:32:56 +0200218};
219
220/**
Ofir Bitton6a2f5d72021-02-15 13:23:04 +0200221 * enum hl_fw_types - F/W types present in the system
Oded Gabbay596553d2020-10-01 13:46:37 +0300222 * @FW_TYPE_LINUX: Linux image for device CPU
223 * @FW_TYPE_BOOT_CPU: Boot image for device CPU
Ofir Bitton6a2f5d72021-02-15 13:23:04 +0200224 * @FW_TYPE_PREBOOT_CPU: Indicates pre-loaded CPUs are present in the system
225 * (preboot, ppboot etc...)
Oded Gabbay596553d2020-10-01 13:46:37 +0300226 * @FW_TYPE_ALL_TYPES: Mask for all types
227 */
228enum hl_fw_types {
229 FW_TYPE_LINUX = 0x1,
230 FW_TYPE_BOOT_CPU = 0x2,
Ofir Bitton6a2f5d72021-02-15 13:23:04 +0200231 FW_TYPE_PREBOOT_CPU = 0x4,
232 FW_TYPE_ALL_TYPES =
233 (FW_TYPE_LINUX | FW_TYPE_BOOT_CPU | FW_TYPE_PREBOOT_CPU)
Oded Gabbay596553d2020-10-01 13:46:37 +0300234};
235
236/**
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200237 * enum hl_queue_type - Supported QUEUE types.
238 * @QUEUE_TYPE_NA: queue is not available.
239 * @QUEUE_TYPE_EXT: external queue which is a DMA channel that may access the
240 * host.
241 * @QUEUE_TYPE_INT: internal queue that performs DMA inside the device's
242 * memories and/or operates the compute engines.
243 * @QUEUE_TYPE_CPU: S/W queue for communication with the device's CPU.
Tomer Tayarcb596ae2019-10-03 15:22:36 +0000244 * @QUEUE_TYPE_HW: queue of DMA and compute engines jobs, for which completion
245 * notifications are sent by H/W.
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200246 */
247enum hl_queue_type {
248 QUEUE_TYPE_NA,
249 QUEUE_TYPE_EXT,
250 QUEUE_TYPE_INT,
Tomer Tayarcb596ae2019-10-03 15:22:36 +0000251 QUEUE_TYPE_CPU,
252 QUEUE_TYPE_HW
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200253};
254
Omer Shpigelmanb0b5d922020-05-07 13:57:36 +0300255enum hl_cs_type {
256 CS_TYPE_DEFAULT,
257 CS_TYPE_SIGNAL,
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300258 CS_TYPE_WAIT,
farah kassabridadf17a2021-05-24 18:09:22 +0300259 CS_TYPE_COLLECTIVE_WAIT,
260 CS_RESERVE_SIGNALS,
261 CS_UNRESERVE_SIGNALS
Omer Shpigelmanb0b5d922020-05-07 13:57:36 +0300262};
263
264/*
Ofir Bittonf4cbfd22020-06-15 17:45:12 +0300265 * struct hl_inbound_pci_region - inbound region descriptor
266 * @mode: pci match mode for this region
267 * @addr: region target address
268 * @size: region size in bytes
269 * @offset_in_bar: offset within bar (address match mode)
270 * @bar: bar id
271 */
272struct hl_inbound_pci_region {
273 enum hl_pci_match_mode mode;
274 u64 addr;
275 u64 size;
276 u64 offset_in_bar;
277 u8 bar;
278};
279
280/*
281 * struct hl_outbound_pci_region - outbound region descriptor
282 * @addr: region target address
283 * @size: region size in bytes
284 */
285struct hl_outbound_pci_region {
286 u64 addr;
287 u64 size;
288};
289
290/*
Tal Cohen4bb1f2f2020-06-03 09:25:27 +0300291 * enum queue_cb_alloc_flags - Indicates queue support for CBs that
292 * allocated by Kernel or by User
293 * @CB_ALLOC_KERNEL: support only CBs that allocated by Kernel
294 * @CB_ALLOC_USER: support only CBs that allocated by User
295 */
296enum queue_cb_alloc_flags {
297 CB_ALLOC_KERNEL = 0x1,
298 CB_ALLOC_USER = 0x2
299};
300
301/*
Omer Shpigelmanb0b5d922020-05-07 13:57:36 +0300302 * struct hl_hw_sob - H/W SOB info.
303 * @hdev: habanalabs device structure.
304 * @kref: refcount of this SOB. The SOB will reset once the refcount is zero.
305 * @sob_id: id of this SOB.
farah kassabridadf17a2021-05-24 18:09:22 +0300306 * @sob_addr: the sob offset from the base address.
Omer Shpigelmanb0b5d922020-05-07 13:57:36 +0300307 * @q_idx: the H/W queue that uses this SOB.
farah kassabridadf17a2021-05-24 18:09:22 +0300308 * @need_reset: reset indication set when switching to the other sob.
Omer Shpigelmanb0b5d922020-05-07 13:57:36 +0300309 */
310struct hl_hw_sob {
311 struct hl_device *hdev;
312 struct kref kref;
313 u32 sob_id;
farah kassabridadf17a2021-05-24 18:09:22 +0300314 u32 sob_addr;
Omer Shpigelmanb0b5d922020-05-07 13:57:36 +0300315 u32 q_idx;
farah kassabridadf17a2021-05-24 18:09:22 +0300316 bool need_reset;
Omer Shpigelmanb0b5d922020-05-07 13:57:36 +0300317};
318
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300319enum hl_collective_mode {
320 HL_COLLECTIVE_NOT_SUPPORTED = 0x0,
321 HL_COLLECTIVE_MASTER = 0x1,
322 HL_COLLECTIVE_SLAVE = 0x2
323};
324
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200325/**
326 * struct hw_queue_properties - queue information.
327 * @type: queue type.
Tal Cohen4bb1f2f2020-06-03 09:25:27 +0300328 * @queue_cb_alloc_flags: bitmap which indicates if the hw queue supports CB
329 * that allocated by the Kernel driver and therefore,
330 * a CB handle can be provided for jobs on this queue.
331 * Otherwise, a CB address must be provided.
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300332 * @collective_mode: collective mode of current queue
Oded Gabbay4c172bb2019-08-30 16:59:33 +0300333 * @driver_only: true if only the driver is allowed to send a job to this queue,
334 * false otherwise.
Ofir Bitton21e7a342020-05-14 18:25:47 +0300335 * @supports_sync_stream: True if queue supports sync stream
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200336 */
337struct hw_queue_properties {
338 enum hl_queue_type type;
Tal Cohen4bb1f2f2020-06-03 09:25:27 +0300339 enum queue_cb_alloc_flags cb_alloc_flags;
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300340 enum hl_collective_mode collective_mode;
Oded Gabbay4c172bb2019-08-30 16:59:33 +0300341 u8 driver_only;
Ofir Bitton21e7a342020-05-14 18:25:47 +0300342 u8 supports_sync_stream;
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200343};
Oded Gabbayc4d66342019-02-16 00:39:11 +0200344
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200345/**
Oded Gabbay82629c72021-06-29 18:08:05 +0300346 * enum vm_type - virtual memory mapping request information.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200347 * @VM_TYPE_USERPTR: mapping of user memory to device virtual address.
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200348 * @VM_TYPE_PHYS_PACK: mapping of DRAM memory to device virtual address.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200349 */
Oded Gabbay82629c72021-06-29 18:08:05 +0300350enum vm_type {
Omer Shpigelman7b6e4ea2019-11-14 18:23:53 +0000351 VM_TYPE_USERPTR = 0x1,
352 VM_TYPE_PHYS_PACK = 0x2
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200353};
354
355/**
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +0200356 * enum hl_device_hw_state - H/W device state. use this to understand whether
357 * to do reset before hw_init or not
358 * @HL_DEVICE_HW_STATE_CLEAN: H/W state is clean. i.e. after hard reset
359 * @HL_DEVICE_HW_STATE_DIRTY: H/W state is dirty. i.e. we started to execute
360 * hw_init
361 */
362enum hl_device_hw_state {
363 HL_DEVICE_HW_STATE_CLEAN = 0,
364 HL_DEVICE_HW_STATE_DIRTY
365};
366
Ofir Bitton412c41f2020-11-04 15:18:55 +0200367#define HL_MMU_VA_ALIGNMENT_NOT_NEEDED 0
368
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +0200369/**
Omer Shpigelman54bb6742019-11-14 18:23:55 +0000370 * struct hl_mmu_properties - ASIC specific MMU address translation properties.
Omer Shpigelman64a7e292020-01-05 09:05:45 +0000371 * @start_addr: virtual start address of the memory region.
372 * @end_addr: virtual end address of the memory region.
Omer Shpigelman54bb6742019-11-14 18:23:55 +0000373 * @hop0_shift: shift of hop 0 mask.
374 * @hop1_shift: shift of hop 1 mask.
375 * @hop2_shift: shift of hop 2 mask.
376 * @hop3_shift: shift of hop 3 mask.
377 * @hop4_shift: shift of hop 4 mask.
Moti Haimovski7edf3412020-08-23 13:23:13 +0300378 * @hop5_shift: shift of hop 5 mask.
Omer Shpigelman54bb6742019-11-14 18:23:55 +0000379 * @hop0_mask: mask to get the PTE address in hop 0.
380 * @hop1_mask: mask to get the PTE address in hop 1.
381 * @hop2_mask: mask to get the PTE address in hop 2.
382 * @hop3_mask: mask to get the PTE address in hop 3.
383 * @hop4_mask: mask to get the PTE address in hop 4.
Moti Haimovski7edf3412020-08-23 13:23:13 +0300384 * @hop5_mask: mask to get the PTE address in hop 5.
Omer Shpigelman54bb6742019-11-14 18:23:55 +0000385 * @page_size: default page size used to allocate memory.
Moti Haimovski7edf3412020-08-23 13:23:13 +0300386 * @num_hops: The amount of hops supported by the translation table.
Moti Haimovskiccf979e2020-10-05 17:59:29 +0300387 * @host_resident: Should the MMU page table reside in host memory or in the
388 * device DRAM.
Omer Shpigelman54bb6742019-11-14 18:23:55 +0000389 */
390struct hl_mmu_properties {
Omer Shpigelman64a7e292020-01-05 09:05:45 +0000391 u64 start_addr;
392 u64 end_addr;
Omer Shpigelman54bb6742019-11-14 18:23:55 +0000393 u64 hop0_shift;
394 u64 hop1_shift;
395 u64 hop2_shift;
396 u64 hop3_shift;
397 u64 hop4_shift;
Moti Haimovski7edf3412020-08-23 13:23:13 +0300398 u64 hop5_shift;
Omer Shpigelman54bb6742019-11-14 18:23:55 +0000399 u64 hop0_mask;
400 u64 hop1_mask;
401 u64 hop2_mask;
402 u64 hop3_mask;
403 u64 hop4_mask;
Moti Haimovski7edf3412020-08-23 13:23:13 +0300404 u64 hop5_mask;
Omer Shpigelman54bb6742019-11-14 18:23:55 +0000405 u32 page_size;
Moti Haimovski7edf3412020-08-23 13:23:13 +0300406 u32 num_hops;
Moti Haimovskiccf979e2020-10-05 17:59:29 +0300407 u8 host_resident;
Omer Shpigelman54bb6742019-11-14 18:23:55 +0000408};
409
410/**
farah kassabri1ae32b92021-01-31 18:56:03 +0200411 * struct hl_hints_range - hint addresses reserved va range.
412 * @start_addr: start address of the va range.
413 * @end_addr: end address of the va range.
414 */
415struct hl_hints_range {
416 u64 start_addr;
417 u64 end_addr;
418};
419
420/**
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200421 * struct asic_fixed_properties - ASIC specific immutable properties.
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200422 * @hw_queues_props: H/W queues properties.
Oded Gabbay2f553422020-08-15 16:28:10 +0300423 * @cpucp_info: received various information from CPU-CP regarding the H/W, e.g.
Oded Gabbayd91389b2019-02-16 00:39:19 +0200424 * available sensors.
Oded Gabbay839c4802019-02-16 00:39:16 +0200425 * @uboot_ver: F/W U-boot version.
426 * @preboot_ver: F/W Preboot version.
Omer Shpigelman54bb6742019-11-14 18:23:55 +0000427 * @dmmu: DRAM MMU address translation properties.
428 * @pmmu: PCI (host) MMU address translation properties.
Omer Shpigelman64a7e292020-01-05 09:05:45 +0000429 * @pmmu_huge: PCI (host) MMU address translation properties for memory
430 * allocated with huge pages.
farah kassabri1ae32b92021-01-31 18:56:03 +0200431 * @hints_dram_reserved_va_range: dram hint addresses reserved range.
432 * @hints_host_reserved_va_range: host hint addresses reserved range.
433 * @hints_host_hpage_reserved_va_range: host huge page hint addresses reserved
434 * range.
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200435 * @sram_base_address: SRAM physical start address.
436 * @sram_end_address: SRAM physical end address.
437 * @sram_user_base_address - SRAM physical start address for user access.
438 * @dram_base_address: DRAM physical start address.
439 * @dram_end_address: DRAM physical end address.
440 * @dram_user_base_address: DRAM physical start address for user access.
441 * @dram_size: DRAM total size.
442 * @dram_pci_bar_size: size of PCI bar towards DRAM.
Oded Gabbayd91389b2019-02-16 00:39:19 +0200443 * @max_power_default: max power of the device after reset
Koby Elbazcd5def82021-02-23 21:31:27 +0200444 * @dc_power_default: power consumed by the device in mode idle.
Omer Shpigelman27ca384c2019-02-28 10:46:11 +0200445 * @dram_size_for_default_page_mapping: DRAM size needed to map to avoid page
446 * fault.
Tomer Tayarb6f897d2019-03-05 16:48:42 +0200447 * @pcie_dbi_base_address: Base address of the PCIE_DBI block.
448 * @pcie_aux_dbi_reg_addr: Address of the PCIE_AUX DBI register.
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200449 * @mmu_pgt_addr: base physical address in DRAM of MMU page tables.
Omer Shpigelman27ca384c2019-02-28 10:46:11 +0200450 * @mmu_dram_default_page_addr: DRAM default page physical address.
Tomer Tayaref6a0f62020-07-09 16:17:48 +0300451 * @cb_va_start_addr: virtual start address of command buffers which are mapped
452 * to the device's MMU.
453 * @cb_va_end_addr: virtual end address of command buffers which are mapped to
454 * the device's MMU.
farah kassabri1ae32b92021-01-31 18:56:03 +0200455 * @dram_hints_align_mask: dram va hint addresses alignment mask which is used
456 * for hints validity check.
Oded Gabbay2b5bbef2021-07-10 21:12:45 +0300457 * device_dma_offset_for_host_access: the offset to add to host DMA addresses
458 * to enable the device to access them.
Rajaravi Krishna Katta024b7b12021-09-03 08:01:30 +0300459 * @max_freq_value: current max clk frequency.
460 * @clk_pll_index: clock PLL index that specify which PLL determines the clock
461 * we display to the user
Omer Shpigelman0feaf862019-02-16 00:39:22 +0200462 * @mmu_pgt_size: MMU page tables total size.
463 * @mmu_pte_size: PTE size in MMU page tables.
464 * @mmu_hop_table_size: MMU hop table size.
465 * @mmu_hop0_tables_total_size: total size of MMU hop0 tables.
466 * @dram_page_size: page size for MMU DRAM allocation.
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200467 * @cfg_size: configuration space size on SRAM.
468 * @sram_size: total size of SRAM.
469 * @max_asid: maximum number of open contexts (ASIDs).
Oded Gabbay1251f232019-02-16 00:39:18 +0200470 * @num_of_events: number of possible internal H/W IRQs.
Oded Gabbayd91389b2019-02-16 00:39:19 +0200471 * @psoc_pci_pll_nr: PCI PLL NR value.
472 * @psoc_pci_pll_nf: PCI PLL NF value.
473 * @psoc_pci_pll_od: PCI PLL OD value.
474 * @psoc_pci_pll_div_factor: PCI PLL DIV FACTOR 1 value.
Adam Aharone8edded2020-05-26 11:04:30 +0300475 * @psoc_timestamp_frequency: frequency of the psoc timestamp clock.
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200476 * @high_pll: high PLL frequency used by the device.
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200477 * @cb_pool_cb_cnt: number of CBs in the CB pool.
478 * @cb_pool_cb_size: size of each CB in the CB pool.
Ofir Bitton3abc99b2020-06-23 14:50:39 +0300479 * @max_pending_cs: maximum of concurrent pending command submissions
480 * @max_queues: maximum amount of queues in the system
Ohad Sharabie67a60402021-05-02 15:45:21 +0300481 * @fw_preboot_cpu_boot_dev_sts0: bitmap representation of preboot cpu
482 * capabilities reported by FW, bit description
483 * can be found in CPU_BOOT_DEV_STS0
484 * @fw_preboot_cpu_boot_dev_sts1: bitmap representation of preboot cpu
485 * capabilities reported by FW, bit description
486 * can be found in CPU_BOOT_DEV_STS1
487 * @fw_bootfit_cpu_boot_dev_sts0: bitmap representation of boot cpu security
488 * status reported by FW, bit description can be
489 * found in CPU_BOOT_DEV_STS0
490 * @fw_bootfit_cpu_boot_dev_sts1: bitmap representation of boot cpu security
491 * status reported by FW, bit description can be
492 * found in CPU_BOOT_DEV_STS1
493 * @fw_app_cpu_boot_dev_sts0: bitmap representation of application security
494 * status reported by FW, bit description can be
495 * found in CPU_BOOT_DEV_STS0
496 * @fw_app_cpu_boot_dev_sts1: bitmap representation of application security
497 * status reported by FW, bit description can be
498 * found in CPU_BOOT_DEV_STS1
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300499 * @collective_first_sob: first sync object available for collective use
500 * @collective_first_mon: first monitor available for collective use
Ofir Bitton21e7a342020-05-14 18:25:47 +0300501 * @sync_stream_first_sob: first sync object available for sync stream use
502 * @sync_stream_first_mon: first monitor available for sync stream use
Ofir Bitton843839b2020-07-19 11:08:09 +0300503 * @first_available_user_sob: first sob available for the user
504 * @first_available_user_mon: first monitor available for the user
Ofir Bittone1fa7242021-01-06 15:40:37 +0200505 * @first_available_user_msix_interrupt: first available msix interrupt
506 * reserved for the user
Ofir Bittone52606d2021-01-27 16:34:37 +0200507 * @first_available_cq: first available CQ for the user.
Ofir Bitton2d44c6f2021-01-12 14:43:09 +0200508 * @user_interrupt_count: number of user interrupts.
Oded Gabbay5dc9ffa2021-07-15 10:48:43 +0300509 * @server_type: Server type that the ASIC is currently installed in.
510 * The value is according to enum hl_server_type in uapi file.
Ofir Bitton21e7a342020-05-14 18:25:47 +0300511 * @tpc_enabled_mask: which TPCs are enabled.
Omer Shpigelman54bb6742019-11-14 18:23:55 +0000512 * @completion_queues_count: number of completion queues.
Ohad Sharabi4cb45082021-05-20 09:09:03 +0300513 * @fw_security_enabled: true if security measures are enabled in firmware,
514 * false otherwise
Ohad Sharabie67a60402021-05-02 15:45:21 +0300515 * @fw_cpu_boot_dev_sts0_valid: status bits are valid and can be fetched from
516 * BOOT_DEV_STS0
517 * @fw_cpu_boot_dev_sts1_valid: status bits are valid and can be fetched from
518 * BOOT_DEV_STS1
Oded Gabbay7f070c92020-11-09 09:48:31 +0200519 * @dram_supports_virtual_memory: is there an MMU towards the DRAM
Ofir Bittond611b9f2020-11-08 13:10:09 +0200520 * @hard_reset_done_by_fw: true if firmware is handling hard reset flow
Oded Gabbay1530d462020-12-18 19:12:56 +0200521 * @num_functional_hbms: number of functional HBMs in each DCORE.
farah kassabri1ae32b92021-01-31 18:56:03 +0200522 * @hints_range_reservation: device support hint addresses range reservation.
Ofir Bitton41f458f2021-03-10 15:08:44 +0200523 * @iatu_done_by_fw: true if iATU configuration is being done by FW.
Ohad Sharabi6e16ab62021-03-25 10:06:26 +0200524 * @dynamic_fw_load: is dynamic FW load is supported.
Koby Elbaz81217362021-05-03 23:03:15 +0300525 * @gic_interrupts_enable: true if FW is not blocking GIC controller,
526 * false otherwise.
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200527 */
528struct asic_fixed_properties {
Ofir Bitton3abc99b2020-06-23 14:50:39 +0300529 struct hw_queue_properties *hw_queues_props;
Oded Gabbay2f553422020-08-15 16:28:10 +0300530 struct cpucp_info cpucp_info;
Omer Shpigelman54bb6742019-11-14 18:23:55 +0000531 char uboot_ver[VERSION_MAX_LEN];
532 char preboot_ver[VERSION_MAX_LEN];
533 struct hl_mmu_properties dmmu;
534 struct hl_mmu_properties pmmu;
Omer Shpigelman64a7e292020-01-05 09:05:45 +0000535 struct hl_mmu_properties pmmu_huge;
farah kassabri1ae32b92021-01-31 18:56:03 +0200536 struct hl_hints_range hints_dram_reserved_va_range;
537 struct hl_hints_range hints_host_reserved_va_range;
538 struct hl_hints_range hints_host_hpage_reserved_va_range;
Omer Shpigelman54bb6742019-11-14 18:23:55 +0000539 u64 sram_base_address;
540 u64 sram_end_address;
541 u64 sram_user_base_address;
542 u64 dram_base_address;
543 u64 dram_end_address;
544 u64 dram_user_base_address;
545 u64 dram_size;
546 u64 dram_pci_bar_size;
547 u64 max_power_default;
Koby Elbazcd5def82021-02-23 21:31:27 +0200548 u64 dc_power_default;
Omer Shpigelman54bb6742019-11-14 18:23:55 +0000549 u64 dram_size_for_default_page_mapping;
550 u64 pcie_dbi_base_address;
551 u64 pcie_aux_dbi_reg_addr;
552 u64 mmu_pgt_addr;
553 u64 mmu_dram_default_page_addr;
Tomer Tayaref6a0f62020-07-09 16:17:48 +0300554 u64 cb_va_start_addr;
555 u64 cb_va_end_addr;
farah kassabri1ae32b92021-01-31 18:56:03 +0200556 u64 dram_hints_align_mask;
Oded Gabbay2b5bbef2021-07-10 21:12:45 +0300557 u64 device_dma_offset_for_host_access;
Rajaravi Krishna Katta024b7b12021-09-03 08:01:30 +0300558 u64 max_freq_value;
559 u32 clk_pll_index;
Omer Shpigelman54bb6742019-11-14 18:23:55 +0000560 u32 mmu_pgt_size;
561 u32 mmu_pte_size;
562 u32 mmu_hop_table_size;
563 u32 mmu_hop0_tables_total_size;
564 u32 dram_page_size;
565 u32 cfg_size;
566 u32 sram_size;
567 u32 max_asid;
568 u32 num_of_events;
569 u32 psoc_pci_pll_nr;
570 u32 psoc_pci_pll_nf;
571 u32 psoc_pci_pll_od;
572 u32 psoc_pci_pll_div_factor;
Adam Aharone8edded2020-05-26 11:04:30 +0300573 u32 psoc_timestamp_frequency;
Omer Shpigelman54bb6742019-11-14 18:23:55 +0000574 u32 high_pll;
575 u32 cb_pool_cb_cnt;
576 u32 cb_pool_cb_size;
Ofir Bittonc16d45f2020-06-02 12:28:27 +0300577 u32 max_pending_cs;
Ofir Bitton3abc99b2020-06-23 14:50:39 +0300578 u32 max_queues;
Ohad Sharabie67a60402021-05-02 15:45:21 +0300579 u32 fw_preboot_cpu_boot_dev_sts0;
580 u32 fw_preboot_cpu_boot_dev_sts1;
581 u32 fw_bootfit_cpu_boot_dev_sts0;
582 u32 fw_bootfit_cpu_boot_dev_sts1;
583 u32 fw_app_cpu_boot_dev_sts0;
584 u32 fw_app_cpu_boot_dev_sts1;
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300585 u16 collective_first_sob;
586 u16 collective_first_mon;
Ofir Bitton21e7a342020-05-14 18:25:47 +0300587 u16 sync_stream_first_sob;
588 u16 sync_stream_first_mon;
Ofir Bitton843839b2020-07-19 11:08:09 +0300589 u16 first_available_user_sob[HL_MAX_DCORES];
590 u16 first_available_user_mon[HL_MAX_DCORES];
Ofir Bittone1fa7242021-01-06 15:40:37 +0200591 u16 first_available_user_msix_interrupt;
Ofir Bittone52606d2021-01-27 16:34:37 +0200592 u16 first_available_cq[HL_MAX_DCORES];
Ofir Bitton2d44c6f2021-01-12 14:43:09 +0200593 u16 user_interrupt_count;
Oded Gabbay5dc9ffa2021-07-15 10:48:43 +0300594 u16 server_type;
Omer Shpigelman54bb6742019-11-14 18:23:55 +0000595 u8 tpc_enabled_mask;
596 u8 completion_queues_count;
Ohad Sharabi4cb45082021-05-20 09:09:03 +0300597 u8 fw_security_enabled;
Ohad Sharabie67a60402021-05-02 15:45:21 +0300598 u8 fw_cpu_boot_dev_sts0_valid;
599 u8 fw_cpu_boot_dev_sts1_valid;
Oded Gabbay7f070c92020-11-09 09:48:31 +0200600 u8 dram_supports_virtual_memory;
Ofir Bittond611b9f2020-11-08 13:10:09 +0200601 u8 hard_reset_done_by_fw;
Oded Gabbay1530d462020-12-18 19:12:56 +0200602 u8 num_functional_hbms;
farah kassabri1ae32b92021-01-31 18:56:03 +0200603 u8 hints_range_reservation;
Ofir Bitton41f458f2021-03-10 15:08:44 +0200604 u8 iatu_done_by_fw;
Ohad Sharabi6e16ab62021-03-25 10:06:26 +0200605 u8 dynamic_fw_load;
Koby Elbaz81217362021-05-03 23:03:15 +0300606 u8 gic_interrupts_enable;
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200607};
608
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200609/**
Ofir Bittona98d73c2020-07-15 08:52:39 +0300610 * struct hl_fence - software synchronization primitive
611 * @completion: fence is implemented using completion
612 * @refcount: refcount for this fence
Ofir Bitton0811b392020-12-06 17:18:02 +0200613 * @cs_sequence: sequence of the corresponding command submission
Ohad Sharabi72d66252021-08-01 23:02:07 +0300614 * @stream_master_qid_map: streams masters QID bitmap to represent all streams
615 * masters QIDs that multi cs is waiting on
Ofir Bittona98d73c2020-07-15 08:52:39 +0300616 * @error: mark this fence with error
Ofir Bittonbd2f4772020-11-10 17:26:22 +0200617 * @timestamp: timestamp upon completion
Dani Libermanea6eb912021-10-03 15:57:44 +0300618 * @mcs_handling_done: indicates that corresponding command submission has
619 * finished msc handling, this does not mean it was part
620 * of the mcs
Ofir Bittona98d73c2020-07-15 08:52:39 +0300621 */
622struct hl_fence {
623 struct completion completion;
624 struct kref refcount;
Ofir Bitton0811b392020-12-06 17:18:02 +0200625 u64 cs_sequence;
Ohad Sharabi72d66252021-08-01 23:02:07 +0300626 u32 stream_master_qid_map;
Ofir Bittona98d73c2020-07-15 08:52:39 +0300627 int error;
Ofir Bittonbd2f4772020-11-10 17:26:22 +0200628 ktime_t timestamp;
Dani Libermanea6eb912021-10-03 15:57:44 +0300629 u8 mcs_handling_done;
Ofir Bittona98d73c2020-07-15 08:52:39 +0300630};
631
632/**
Omer Shpigelmanb0b5d922020-05-07 13:57:36 +0300633 * struct hl_cs_compl - command submission completion object.
Ofir Bittona98d73c2020-07-15 08:52:39 +0300634 * @base_fence: hl fence object.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200635 * @lock: spinlock to protect fence.
636 * @hdev: habanalabs device structure.
Omer Shpigelmanb0b5d922020-05-07 13:57:36 +0300637 * @hw_sob: the H/W SOB used in this signal/wait CS.
farah kassabrie4cdccd2021-05-26 10:43:36 +0300638 * @encaps_sig_hdl: encaps signals hanlder.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200639 * @cs_seq: command submission sequence number.
Omer Shpigelmanb0b5d922020-05-07 13:57:36 +0300640 * @type: type of the CS - signal/wait.
641 * @sob_val: the SOB value that is used in this signal/wait CS.
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300642 * @sob_group: the SOB group that is used in this collective wait CS.
farah kassabridadf17a2021-05-24 18:09:22 +0300643 * @encaps_signals: indication whether it's a completion object of cs with
644 * encaps signals or not.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200645 */
Omer Shpigelmanb0b5d922020-05-07 13:57:36 +0300646struct hl_cs_compl {
Ofir Bittona98d73c2020-07-15 08:52:39 +0300647 struct hl_fence base_fence;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200648 spinlock_t lock;
649 struct hl_device *hdev;
Omer Shpigelmanb0b5d922020-05-07 13:57:36 +0300650 struct hl_hw_sob *hw_sob;
farah kassabrie4cdccd2021-05-26 10:43:36 +0300651 struct hl_cs_encaps_sig_handle *encaps_sig_hdl;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200652 u64 cs_seq;
Omer Shpigelmanb0b5d922020-05-07 13:57:36 +0300653 enum hl_cs_type type;
654 u16 sob_val;
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300655 u16 sob_group;
farah kassabridadf17a2021-05-24 18:09:22 +0300656 bool encaps_signals;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200657};
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200658
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200659/*
660 * Command Buffers
661 */
662
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200663/**
664 * struct hl_cb_mgr - describes a Command Buffer Manager.
665 * @cb_lock: protects cb_handles.
666 * @cb_handles: an idr to hold all command buffer handles.
667 */
668struct hl_cb_mgr {
669 spinlock_t cb_lock;
670 struct idr cb_handles; /* protected by cb_lock */
671};
672
673/**
674 * struct hl_cb - describes a Command Buffer.
675 * @refcount: reference counter for usage of the CB.
676 * @hdev: pointer to device this CB belongs to.
Tomer Tayarfa8641a12020-09-07 17:36:41 +0300677 * @ctx: pointer to the CB owner's context.
Tomer Tayarf07486742020-08-02 22:51:31 +0300678 * @lock: spinlock to protect mmap flows.
Oded Gabbayc2164772019-02-16 00:39:24 +0200679 * @debugfs_list: node in debugfs list of command buffers.
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200680 * @pool_list: node in pool list of command buffers.
Tomer Tayaref6a0f62020-07-09 16:17:48 +0300681 * @va_block_list: list of virtual addresses blocks of the CB if it is mapped to
682 * the device's MMU.
Oded Gabbayf5b9c8c2020-08-12 10:11:20 +0300683 * @id: the CB's ID.
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200684 * @kernel_address: Holds the CB's kernel virtual address.
685 * @bus_address: Holds the CB's DMA address.
686 * @mmap_size: Holds the CB's size that was mmaped.
687 * @size: holds the CB's size.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200688 * @cs_cnt: holds number of CS that this CB participates in.
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200689 * @mmap: true if the CB is currently mmaped to user.
690 * @is_pool: true if CB was acquired from the pool, false otherwise.
Ofir Bittona04b7cd2020-07-13 13:36:55 +0300691 * @is_internal: internaly allocated
Tomer Tayaref6a0f62020-07-09 16:17:48 +0300692 * @is_mmu_mapped: true if the CB is mapped to the device's MMU.
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200693 */
694struct hl_cb {
695 struct kref refcount;
696 struct hl_device *hdev;
Tomer Tayarfa8641a12020-09-07 17:36:41 +0300697 struct hl_ctx *ctx;
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200698 spinlock_t lock;
Oded Gabbayc2164772019-02-16 00:39:24 +0200699 struct list_head debugfs_list;
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200700 struct list_head pool_list;
Tomer Tayaref6a0f62020-07-09 16:17:48 +0300701 struct list_head va_block_list;
Oded Gabbayf5b9c8c2020-08-12 10:11:20 +0300702 u64 id;
Arnd Bergmann82948e62020-10-26 17:08:06 +0100703 void *kernel_address;
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200704 dma_addr_t bus_address;
705 u32 mmap_size;
706 u32 size;
Tomer Tayarf07486742020-08-02 22:51:31 +0300707 atomic_t cs_cnt;
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200708 u8 mmap;
709 u8 is_pool;
Ofir Bittona04b7cd2020-07-13 13:36:55 +0300710 u8 is_internal;
Tomer Tayaref6a0f62020-07-09 16:17:48 +0300711 u8 is_mmu_mapped;
Oded Gabbaybe5d9262019-02-16 00:39:15 +0200712};
713
714
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200715/*
716 * QUEUES
717 */
718
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300719struct hl_cs;
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200720struct hl_cs_job;
721
Ofir Bittondd9efab2020-06-15 12:09:50 +0300722/* Queue length of external and HW queues */
723#define HL_QUEUE_LENGTH 4096
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200724#define HL_QUEUE_SIZE_IN_BYTES (HL_QUEUE_LENGTH * HL_BD_SIZE)
725
Ofir Bitton22cb8552020-07-08 10:16:27 +0300726#if (HL_MAX_JOBS_PER_CS > HL_QUEUE_LENGTH)
727#error "HL_QUEUE_LENGTH must be greater than HL_MAX_JOBS_PER_CS"
728#endif
729
Ofir Bittondd9efab2020-06-15 12:09:50 +0300730/* HL_CQ_LENGTH is in units of struct hl_cq_entry */
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200731#define HL_CQ_LENGTH HL_QUEUE_LENGTH
732#define HL_CQ_SIZE_IN_BYTES (HL_CQ_LENGTH * HL_CQ_ENTRY_SIZE)
733
Ofir Bittondd9efab2020-06-15 12:09:50 +0300734/* Must be power of 2 */
Oded Gabbay1251f232019-02-16 00:39:18 +0200735#define HL_EQ_LENGTH 64
736#define HL_EQ_SIZE_IN_BYTES (HL_EQ_LENGTH * HL_EQ_ENTRY_SIZE)
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200737
Oded Gabbay6138bbe2020-09-04 20:18:16 +0300738/* Host <-> CPU-CP shared memory size */
Oded Gabbay95b5a8b2019-05-29 17:30:04 +0300739#define HL_CPU_ACCESSIBLE_MEM_SIZE SZ_2M
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200740
741/**
Ofir Bitton3cf74b32020-09-10 09:17:50 +0300742 * struct hl_sync_stream_properties -
743 * describes a H/W queue sync stream properties
Omer Shpigelmanb0b5d922020-05-07 13:57:36 +0300744 * @hw_sob: array of the used H/W SOBs by this H/W queue.
Ofir Bitton3cf74b32020-09-10 09:17:50 +0300745 * @next_sob_val: the next value to use for the currently used SOB.
746 * @base_sob_id: the base SOB id of the SOBs used by this queue.
747 * @base_mon_id: the base MON id of the MONs used by this queue.
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300748 * @collective_mstr_mon_id: the MON ids of the MONs used by this master queue
749 * in order to sync with all slave queues.
750 * @collective_slave_mon_id: the MON id used by this slave queue in order to
751 * sync with its master queue.
752 * @collective_sob_id: current SOB id used by this collective slave queue
753 * to signal its collective master queue upon completion.
Ofir Bitton3cf74b32020-09-10 09:17:50 +0300754 * @curr_sob_offset: the id offset to the currently used SOB from the
755 * HL_RSVD_SOBS that are being used by this queue.
756 */
757struct hl_sync_stream_properties {
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300758 struct hl_hw_sob hw_sob[HL_RSVD_SOBS];
759 u16 next_sob_val;
760 u16 base_sob_id;
761 u16 base_mon_id;
762 u16 collective_mstr_mon_id[HL_COLLECTIVE_RSVD_MSTR_MONS];
763 u16 collective_slave_mon_id;
764 u16 collective_sob_id;
765 u8 curr_sob_offset;
Ofir Bitton3cf74b32020-09-10 09:17:50 +0300766};
767
768/**
farah kassabridadf17a2021-05-24 18:09:22 +0300769 * struct hl_encaps_signals_mgr - describes sync stream encapsulated signals
770 * handlers manager
771 * @lock: protects handles.
772 * @handles: an idr to hold all encapsulated signals handles.
773 */
774struct hl_encaps_signals_mgr {
775 spinlock_t lock;
776 struct idr handles;
777};
778
779/**
Ofir Bitton3cf74b32020-09-10 09:17:50 +0300780 * struct hl_hw_queue - describes a H/W transport queue.
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200781 * @shadow_queue: pointer to a shadow queue that holds pointers to jobs.
Ofir Bitton3cf74b32020-09-10 09:17:50 +0300782 * @sync_stream_prop: sync stream queue properties
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200783 * @queue_type: type of queue.
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300784 * @collective_mode: collective mode of current queue
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200785 * @kernel_address: holds the queue's kernel virtual address.
786 * @bus_address: holds the queue's DMA address.
787 * @pi: holds the queue's pi value.
788 * @ci: holds the queue's ci value, AS CALCULATED BY THE DRIVER (not real ci).
789 * @hw_queue_id: the id of the H/W queue.
Omer Shpigelman1fa185c2020-03-01 19:59:39 +0200790 * @cq_id: the id for the corresponding CQ for this H/W queue.
791 * @msi_vec: the IRQ number of the H/W queue.
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200792 * @int_queue_len: length of internal queue (number of entries).
793 * @valid: is the queue valid (we have array of 32 queues, not all of them
Omer Shpigelmanb0b5d922020-05-07 13:57:36 +0300794 * exist).
Ofir Bitton21e7a342020-05-14 18:25:47 +0300795 * @supports_sync_stream: True if queue supports sync stream
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200796 */
797struct hl_hw_queue {
Ofir Bitton3cf74b32020-09-10 09:17:50 +0300798 struct hl_cs_job **shadow_queue;
799 struct hl_sync_stream_properties sync_stream_prop;
800 enum hl_queue_type queue_type;
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300801 enum hl_collective_mode collective_mode;
Ofir Bitton3cf74b32020-09-10 09:17:50 +0300802 void *kernel_address;
803 dma_addr_t bus_address;
804 u32 pi;
805 atomic_t ci;
806 u32 hw_queue_id;
807 u32 cq_id;
808 u32 msi_vec;
809 u16 int_queue_len;
810 u8 valid;
811 u8 supports_sync_stream;
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200812};
813
814/**
815 * struct hl_cq - describes a completion queue
816 * @hdev: pointer to the device structure
817 * @kernel_address: holds the queue's kernel virtual address
818 * @bus_address: holds the queue's DMA address
Ofir Bitton5574cb22020-07-05 13:35:51 +0300819 * @cq_idx: completion queue index in array
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200820 * @hw_queue_id: the id of the matching H/W queue
821 * @ci: ci inside the queue
822 * @pi: pi inside the queue
823 * @free_slots_cnt: counter of free slots in queue
824 */
825struct hl_cq {
826 struct hl_device *hdev;
Arnd Bergmann82948e62020-10-26 17:08:06 +0100827 void *kernel_address;
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200828 dma_addr_t bus_address;
Ofir Bitton5574cb22020-07-05 13:35:51 +0300829 u32 cq_idx;
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200830 u32 hw_queue_id;
831 u32 ci;
832 u32 pi;
833 atomic_t free_slots_cnt;
834};
Oded Gabbay0861e412019-02-16 00:39:14 +0200835
Oded Gabbay1251f232019-02-16 00:39:18 +0200836/**
Ofir Bitton2d44c6f2021-01-12 14:43:09 +0200837 * struct hl_user_interrupt - holds user interrupt information
838 * @hdev: pointer to the device structure
Ofir Bittonab5f5c32021-01-12 18:37:19 +0200839 * @wait_list_head: head to the list of user threads pending on this interrupt
840 * @wait_list_lock: protects wait_list_head
Ofir Bitton2d44c6f2021-01-12 14:43:09 +0200841 * @interrupt_id: msix interrupt id
842 */
843struct hl_user_interrupt {
844 struct hl_device *hdev;
Ofir Bittonab5f5c32021-01-12 18:37:19 +0200845 struct list_head wait_list_head;
846 spinlock_t wait_list_lock;
Ofir Bitton2d44c6f2021-01-12 14:43:09 +0200847 u32 interrupt_id;
848};
849
850/**
Ofir Bittonab5f5c32021-01-12 18:37:19 +0200851 * struct hl_user_pending_interrupt - holds a context to a user thread
852 * pending on an interrupt
853 * @wait_list_node: node in the list of user threads pending on an interrupt
854 * @fence: hl fence object for interrupt completion
855 */
856struct hl_user_pending_interrupt {
857 struct list_head wait_list_node;
858 struct hl_fence fence;
859};
860
861/**
Oded Gabbay1251f232019-02-16 00:39:18 +0200862 * struct hl_eq - describes the event queue (single one per device)
863 * @hdev: pointer to the device structure
864 * @kernel_address: holds the queue's kernel virtual address
865 * @bus_address: holds the queue's DMA address
866 * @ci: ci inside the queue
Oded Gabbay1242e9f2021-05-19 14:52:14 +0300867 * @prev_eqe_index: the index of the previous event queue entry. The index of
868 * the current entry's index must be +1 of the previous one.
869 * @check_eqe_index: do we need to check the index of the current entry vs. the
870 * previous one. This is for backward compatibility with older
871 * firmwares
Oded Gabbay1251f232019-02-16 00:39:18 +0200872 */
873struct hl_eq {
874 struct hl_device *hdev;
Arnd Bergmann82948e62020-10-26 17:08:06 +0100875 void *kernel_address;
Oded Gabbay1251f232019-02-16 00:39:18 +0200876 dma_addr_t bus_address;
877 u32 ci;
Oded Gabbay1242e9f2021-05-19 14:52:14 +0300878 u32 prev_eqe_index;
879 bool check_eqe_index;
Oded Gabbay1251f232019-02-16 00:39:18 +0200880};
881
Oded Gabbay0861e412019-02-16 00:39:14 +0200882
Oded Gabbayc4d66342019-02-16 00:39:11 +0200883/*
884 * ASICs
885 */
886
887/**
888 * enum hl_asic_type - supported ASIC types.
Oded Gabbayc4d66342019-02-16 00:39:11 +0200889 * @ASIC_INVALID: Invalid ASIC type.
Oded Gabbay29593842019-04-04 14:33:34 +0300890 * @ASIC_GOYA: Goya device.
Oded Gabbay6966d9e2020-03-21 10:58:32 +0200891 * @ASIC_GAUDI: Gaudi device.
Ofir Bittone5042a62021-04-01 13:43:40 +0300892 * @ASIC_GAUDI_SEC: Gaudi secured device (HL-2000).
Oded Gabbayc4d66342019-02-16 00:39:11 +0200893 */
894enum hl_asic_type {
Oded Gabbay29593842019-04-04 14:33:34 +0300895 ASIC_INVALID,
Oded Gabbay6966d9e2020-03-21 10:58:32 +0200896 ASIC_GOYA,
Ofir Bittone5042a62021-04-01 13:43:40 +0300897 ASIC_GAUDI,
898 ASIC_GAUDI_SEC
Oded Gabbayc4d66342019-02-16 00:39:11 +0200899};
900
Oded Gabbayeff6f4a2019-02-16 00:39:21 +0200901struct hl_cs_parser;
902
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200903/**
Oded Gabbayd91389b2019-02-16 00:39:19 +0200904 * enum hl_pm_mng_profile - power management profile.
Oded Gabbay4c172bb2019-08-30 16:59:33 +0300905 * @PM_AUTO: internal clock is set by the Linux driver.
Oded Gabbayd91389b2019-02-16 00:39:19 +0200906 * @PM_MANUAL: internal clock is set by the user.
907 * @PM_LAST: last power management type.
908 */
909enum hl_pm_mng_profile {
910 PM_AUTO = 1,
911 PM_MANUAL,
912 PM_LAST
913};
914
915/**
916 * enum hl_pll_frequency - PLL frequency.
917 * @PLL_HIGH: high frequency.
918 * @PLL_LOW: low frequency.
919 * @PLL_LAST: last frequency values that were configured by the user.
920 */
921enum hl_pll_frequency {
922 PLL_HIGH = 1,
923 PLL_LOW,
924 PLL_LAST
925};
926
Adam Aharone8edded2020-05-26 11:04:30 +0300927#define PLL_REF_CLK 50
928
929enum div_select_defs {
930 DIV_SEL_REF_CLK = 0,
931 DIV_SEL_PLL_CLK = 1,
932 DIV_SEL_DIVIDED_REF = 2,
933 DIV_SEL_DIVIDED_PLL = 3,
934};
935
Ohad Sharabic592c272021-04-21 13:03:21 +0300936enum pci_region {
937 PCI_REGION_CFG,
938 PCI_REGION_SRAM,
939 PCI_REGION_DRAM,
940 PCI_REGION_SP_SRAM,
941 PCI_REGION_NUMBER,
942};
943
944/**
945 * struct pci_mem_region - describe memory region in a PCI bar
946 * @region_base: region base address
947 * @region_size: region size
Ohad Sharabib31e59b2021-04-22 10:01:22 +0300948 * @bar_size: size of the BAR
Ohad Sharabic592c272021-04-21 13:03:21 +0300949 * @offset_in_bar: region offset into the bar
950 * @bar_id: bar ID of the region
951 * @used: if used 1, otherwise 0
952 */
953struct pci_mem_region {
954 u64 region_base;
955 u64 region_size;
Ohad Sharabib31e59b2021-04-22 10:01:22 +0300956 u64 bar_size;
Ohad Sharabi932adf12021-07-18 12:06:41 +0300957 u64 offset_in_bar;
Ohad Sharabic592c272021-04-21 13:03:21 +0300958 u8 bar_id;
959 u8 used;
960};
961
Oded Gabbayd91389b2019-02-16 00:39:19 +0200962/**
Ohad Sharabi22a795b2021-04-08 13:42:00 +0300963 * struct static_fw_load_mgr - static FW load manager
Ohad Sharabi50f036d2021-04-11 15:26:28 +0300964 * @preboot_version_max_off: max offset to preboot version
965 * @boot_fit_version_max_off: max offset to boot fit version
Ohad Sharabi8a43c832021-04-11 10:32:18 +0300966 * @kmd_msg_to_cpu_reg: register address for KDM->CPU messages
967 * @cpu_cmd_status_to_host_reg: register address for CPU command status response
Ohad Sharabia22f0ec2021-04-11 23:06:46 +0300968 * @cpu_boot_status_reg: boot status register
Ohad Sharabie67a60402021-05-02 15:45:21 +0300969 * @cpu_boot_dev_status0_reg: boot device status register 0
970 * @cpu_boot_dev_status1_reg: boot device status register 1
971 * @boot_err0_reg: boot error register 0
972 * @boot_err1_reg: boot error register 1
Ohad Sharabi50f036d2021-04-11 15:26:28 +0300973 * @preboot_version_offset_reg: SRAM offset to preboot version register
974 * @boot_fit_version_offset_reg: SRAM offset to boot fit version register
975 * @sram_offset_mask: mask for getting offset into the SRAM
Koby Elbazb7a71fd2021-06-15 17:07:02 +0300976 * @cpu_reset_wait_msec: used when setting WFE via kmd_msg_to_cpu_reg
Ohad Sharabia22f0ec2021-04-11 23:06:46 +0300977 */
Ohad Sharabi22a795b2021-04-08 13:42:00 +0300978struct static_fw_load_mgr {
Ohad Sharabi50f036d2021-04-11 15:26:28 +0300979 u64 preboot_version_max_off;
980 u64 boot_fit_version_max_off;
Ohad Sharabi8a43c832021-04-11 10:32:18 +0300981 u32 kmd_msg_to_cpu_reg;
982 u32 cpu_cmd_status_to_host_reg;
Ohad Sharabia22f0ec2021-04-11 23:06:46 +0300983 u32 cpu_boot_status_reg;
Ohad Sharabie67a60402021-05-02 15:45:21 +0300984 u32 cpu_boot_dev_status0_reg;
985 u32 cpu_boot_dev_status1_reg;
Ohad Sharabia22f0ec2021-04-11 23:06:46 +0300986 u32 boot_err0_reg;
Ohad Sharabie67a60402021-05-02 15:45:21 +0300987 u32 boot_err1_reg;
Ohad Sharabi50f036d2021-04-11 15:26:28 +0300988 u32 preboot_version_offset_reg;
989 u32 boot_fit_version_offset_reg;
990 u32 sram_offset_mask;
Koby Elbazb7a71fd2021-06-15 17:07:02 +0300991 u32 cpu_reset_wait_msec;
Ohad Sharabi22a795b2021-04-08 13:42:00 +0300992};
993
994/**
Ohad Sharabi8a43c832021-04-11 10:32:18 +0300995 * struct fw_response - FW response to LKD command
996 * @ram_offset: descriptor offset into the RAM
997 * @ram_type: RAM type containing the descriptor (SRAM/DRAM)
998 * @status: command status
999 */
1000struct fw_response {
1001 u32 ram_offset;
1002 u8 ram_type;
1003 u8 status;
1004};
1005
1006/**
Ohad Sharabi22a795b2021-04-08 13:42:00 +03001007 * struct dynamic_fw_load_mgr - dynamic FW load manager
Ohad Sharabi8a43c832021-04-11 10:32:18 +03001008 * @response: FW to LKD response
1009 * @comm_desc: the communication descriptor with FW
1010 * @image_region: region to copy the FW image to
Ohad Sharabib31e59b2021-04-22 10:01:22 +03001011 * @fw_image_size: size of FW image to load
1012 * @wait_for_bl_timeout: timeout for waiting for boot loader to respond
Ohad Sharabi22a795b2021-04-08 13:42:00 +03001013 */
1014struct dynamic_fw_load_mgr {
Ohad Sharabi8a43c832021-04-11 10:32:18 +03001015 struct fw_response response;
1016 struct lkd_fw_comms_desc comm_desc;
1017 struct pci_mem_region *image_region;
1018 size_t fw_image_size;
Ohad Sharabib31e59b2021-04-22 10:01:22 +03001019 u32 wait_for_bl_timeout;
Ohad Sharabi8a43c832021-04-11 10:32:18 +03001020};
1021
1022/**
1023 * struct fw_image_props - properties of FW image
1024 * @image_name: name of the image
1025 * @src_off: offset in src FW to copy from
1026 * @copy_size: amount of bytes to copy (0 to copy the whole binary)
1027 */
1028struct fw_image_props {
1029 char *image_name;
1030 u32 src_off;
1031 u32 copy_size;
Ohad Sharabi22a795b2021-04-08 13:42:00 +03001032};
1033
1034/**
1035 * struct fw_load_mgr - manager FW loading process
Ohad Sharabi8a43c832021-04-11 10:32:18 +03001036 * @dynamic_loader: specific structure for dynamic load
1037 * @static_loader: specific structure for static load
1038 * @boot_fit_img: boot fit image properties
1039 * @linux_img: linux image properties
Ohad Sharabi22a795b2021-04-08 13:42:00 +03001040 * @cpu_timeout: CPU response timeout in usec
1041 * @boot_fit_timeout: Boot fit load timeout in usec
1042 * @skip_bmc: should BMC be skipped
1043 * @sram_bar_id: SRAM bar ID
Ohad Sharabi8a43c832021-04-11 10:32:18 +03001044 * @dram_bar_id: DRAM bar ID
Koby Elbaz3649eae2021-05-18 15:43:47 +03001045 * @linux_loaded: true if linux was loaded so far
Ohad Sharabi22a795b2021-04-08 13:42:00 +03001046 */
1047struct fw_load_mgr {
Ohad Sharabi8a43c832021-04-11 10:32:18 +03001048 union {
1049 struct dynamic_fw_load_mgr dynamic_loader;
1050 struct static_fw_load_mgr static_loader;
1051 };
1052 struct fw_image_props boot_fit_img;
1053 struct fw_image_props linux_img;
Ohad Sharabia22f0ec2021-04-11 23:06:46 +03001054 u32 cpu_timeout;
1055 u32 boot_fit_timeout;
1056 u8 skip_bmc;
Ohad Sharabi50f036d2021-04-11 15:26:28 +03001057 u8 sram_bar_id;
Ohad Sharabi8a43c832021-04-11 10:32:18 +03001058 u8 dram_bar_id;
Koby Elbaz3649eae2021-05-18 15:43:47 +03001059 u8 linux_loaded;
Ohad Sharabia22f0ec2021-04-11 23:06:46 +03001060};
1061
1062/**
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001063 * struct hl_asic_funcs - ASIC specific functions that are can be called from
1064 * common code.
1065 * @early_init: sets up early driver state (pre sw_init), doesn't configure H/W.
1066 * @early_fini: tears down what was done in early_init.
Oded Gabbayd91389b2019-02-16 00:39:19 +02001067 * @late_init: sets up late driver/hw state (post hw_init) - Optional.
1068 * @late_fini: tears down what was done in late_init (pre hw_fini) - Optional.
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001069 * @sw_init: sets up driver state, does not configure H/W.
1070 * @sw_fini: tears down driver state, does not configure H/W.
Oded Gabbay839c4802019-02-16 00:39:16 +02001071 * @hw_init: sets up the H/W state.
1072 * @hw_fini: tears down the H/W state.
Oded Gabbay1251f232019-02-16 00:39:18 +02001073 * @halt_engines: halt engines, needed for reset sequence. This also disables
1074 * interrupts from the device. Should be called before
1075 * hw_fini and before CS rollback.
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001076 * @suspend: handles IP specific H/W or SW changes for suspend.
1077 * @resume: handles IP specific H/W or SW changes for resume.
Zvika Yehudai1ee8e2b2021-07-06 13:50:32 +03001078 * @mmap: maps a memory.
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001079 * @ring_doorbell: increment PI on a given QMAN.
Oded Gabbayb9040c92019-08-08 15:45:58 +03001080 * @pqe_write: Write the PQ entry to the PQ. This is ASIC-specific
1081 * function because the PQs are located in different memory areas
1082 * per ASIC (SRAM, DRAM, Host memory) and therefore, the method of
1083 * writing the PQE must match the destination memory area
1084 * properties.
Oded Gabbayd9c3aa82019-05-01 11:47:04 +03001085 * @asic_dma_alloc_coherent: Allocate coherent DMA memory by calling
1086 * dma_alloc_coherent(). This is ASIC function because
1087 * its implementation is not trivial when the driver
1088 * is loaded in simulation mode (not upstreamed).
1089 * @asic_dma_free_coherent: Free coherent DMA memory by calling
1090 * dma_free_coherent(). This is ASIC function because
1091 * its implementation is not trivial when the driver
1092 * is loaded in simulation mode (not upstreamed).
farah kassabri03df1362020-05-06 11:17:38 +03001093 * @scrub_device_mem: Scrub device memory given an address and size
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001094 * @get_int_queue_base: get the internal queue base address.
1095 * @test_queues: run simple test on all queues for sanity check.
Oded Gabbayd9c3aa82019-05-01 11:47:04 +03001096 * @asic_dma_pool_zalloc: small DMA allocation of coherent memory from DMA pool.
1097 * size of allocation is HL_DMA_POOL_BLK_SIZE.
1098 * @asic_dma_pool_free: free small DMA allocation from pool.
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001099 * @cpu_accessible_dma_pool_alloc: allocate CPU PQ packet from DMA pool.
1100 * @cpu_accessible_dma_pool_free: free CPU PQ packet from DMA pool.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001101 * @hl_dma_unmap_sg: DMA unmap scatter-gather list.
1102 * @cs_parser: parse Command Submission.
1103 * @asic_dma_map_sg: DMA map scatter-gather list.
1104 * @get_dma_desc_list_size: get number of LIN_DMA packets required for CB.
1105 * @add_end_of_cb_packets: Add packets to the end of CB, if device requires it.
Oded Gabbay1251f232019-02-16 00:39:18 +02001106 * @update_eq_ci: update event queue CI.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001107 * @context_switch: called upon ASID context switch.
1108 * @restore_phase_topology: clear all SOBs amd MONs.
Oded Gabbay639781d2021-04-02 01:43:18 +03001109 * @debugfs_read32: debug interface for reading u32 from DRAM/SRAM/Host memory.
1110 * @debugfs_write32: debug interface for writing u32 to DRAM/SRAM/Host memory.
1111 * @debugfs_read64: debug interface for reading u64 from DRAM/SRAM/Host memory.
1112 * @debugfs_write64: debug interface for writing u64 to DRAM/SRAM/Host memory.
1113 * @debugfs_read_dma: debug interface for reading up to 2MB from the device's
1114 * internal memory via DMA engine.
Oded Gabbayd91389b2019-02-16 00:39:19 +02001115 * @add_device_attr: add ASIC specific device attributes.
Oded Gabbay6138bbe2020-09-04 20:18:16 +03001116 * @handle_eqe: handle event queue entry (IRQ) from CPU-CP.
Oded Gabbayd91389b2019-02-16 00:39:19 +02001117 * @set_pll_profile: change PLL profile (manual/automatic).
Oded Gabbay1251f232019-02-16 00:39:18 +02001118 * @get_events_stat: retrieve event queue entries histogram.
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001119 * @read_pte: read MMU page table entry from DRAM.
1120 * @write_pte: write MMU page table entry to DRAM.
Omer Shpigelman7b6e4ea2019-11-14 18:23:53 +00001121 * @mmu_invalidate_cache: flush MMU STLB host/DRAM cache, either with soft
1122 * (L1 only) or hard (L0 & L1) flush.
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001123 * @mmu_invalidate_cache_range: flush specific MMU STLB cache lines with
1124 * ASID-VA-size mask.
Oded Gabbay6138bbe2020-09-04 20:18:16 +03001125 * @send_heartbeat: send is-alive packet to CPU-CP and verify response.
Oded Gabbaye38bfd32020-07-03 20:46:12 +03001126 * @set_clock_gating: enable/disable clock gating per engine according to
1127 * clock gating mask in hdev
1128 * @disable_clock_gating: disable clock gating completely
Omer Shpigelman315bc052019-04-01 22:31:22 +03001129 * @debug_coresight: perform certain actions on Coresight for debugging.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001130 * @is_device_idle: return true if device is idle, false otherwise.
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02001131 * @soft_reset_late_init: perform certain actions needed after soft reset.
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001132 * @hw_queues_lock: acquire H/W queues lock.
1133 * @hw_queues_unlock: release H/W queues lock.
Oded Gabbayd8dd7b02019-02-16 00:39:23 +02001134 * @get_pci_id: retrieve PCI ID.
Oded Gabbayd91389b2019-02-16 00:39:19 +02001135 * @get_eeprom_data: retrieve EEPROM data from F/W.
Oded Gabbay788cacf2020-07-07 17:30:13 +03001136 * @send_cpu_message: send message to F/W. If the message is timedout, the
1137 * driver will eventually reset the device. The timeout can
1138 * be determined by the calling function or it can be 0 and
1139 * then the timeout is the default timeout for the specific
1140 * ASIC
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02001141 * @get_hw_state: retrieve the H/W state
Tomer Tayarb6f897d2019-03-05 16:48:42 +02001142 * @pci_bars_map: Map PCI BARs.
Tomer Tayarb6f897d2019-03-05 16:48:42 +02001143 * @init_iatu: Initialize the iATU unit inside the PCI controller.
Oded Gabbayb2377e02019-04-22 11:49:06 +03001144 * @rreg: Read a register. Needed for simulator support.
1145 * @wreg: Write a register. Needed for simulator support.
Omer Shpigelman89225ce2019-05-01 14:38:38 +03001146 * @halt_coresight: stop the ETF and ETR traces.
Ofir Bittona04b7cd2020-07-13 13:36:55 +03001147 * @ctx_init: context dependent initialization.
Ofir Bitton5de406c2020-09-10 10:56:26 +03001148 * @ctx_fini: context dependent cleanup.
Oded Gabbay62c1e122019-10-10 15:48:59 +03001149 * @get_clk_rate: Retrieve the ASIC current and maximum clock rate in MHz
Omer Shpigelman1fa185c2020-03-01 19:59:39 +02001150 * @get_queue_id_for_cq: Get the H/W queue id related to the given CQ index.
Oded Gabbay7e1c07d2020-03-26 12:32:56 +02001151 * @load_firmware_to_device: load the firmware to the device's memory
Ofir Bitton47f6b412020-04-16 13:47:15 +03001152 * @load_boot_fit_to_device: load boot fit to device's memory
Omer Shpigelmanec2f8a32020-05-07 13:43:05 +03001153 * @get_signal_cb_size: Get signal CB size.
1154 * @get_wait_cb_size: Get wait CB size.
1155 * @gen_signal_cb: Generate a signal CB.
1156 * @gen_wait_cb: Generate a wait CB.
1157 * @reset_sob: Reset a SOB.
Ofir Bitton5fe1c172020-09-10 10:10:55 +03001158 * @reset_sob_group: Reset SOB group
Oded Gabbaycb056b92020-03-29 13:18:30 +03001159 * @set_dma_mask_from_fw: set the DMA mask in the driver according to the
1160 * firmware configuration
Tomer Tayar25e7aeb2020-03-31 22:46:36 +03001161 * @get_device_time: Get the device time.
Ofir Bitton5fe1c172020-09-10 10:10:55 +03001162 * @collective_wait_init_cs: Generate collective master/slave packets
1163 * and place them in the relevant cs jobs
1164 * @collective_wait_create_jobs: allocate collective wait cs jobs
farah kassabri89473a12021-01-12 17:24:00 +02001165 * @scramble_addr: Routine to scramble the address prior of mapping it
Oded Gabbay28bcf1f2021-02-01 21:23:43 +02001166 * in the MMU.
farah kassabri89473a12021-01-12 17:24:00 +02001167 * @descramble_addr: Routine to de-scramble the address prior of
Oded Gabbay28bcf1f2021-02-01 21:23:43 +02001168 * showing it to users.
Ofir Bittond2b980f2021-01-07 12:14:17 +02001169 * @ack_protection_bits_errors: ack and dump all security violations
Ofir Bittond00697f2021-01-05 12:55:06 +02001170 * @get_hw_block_id: retrieve a HW block id to be used by the user to mmap it.
Oded Gabbay6df50d22021-02-05 16:04:34 +02001171 * also returns the size of the block if caller supplies
1172 * a valid pointer for it
Ofir Bittond00697f2021-01-05 12:55:06 +02001173 * @hw_block_mmap: mmap a HW block with a given id.
Oded Gabbay28bcf1f2021-02-01 21:23:43 +02001174 * @enable_events_from_fw: send interrupt to firmware to notify them the
1175 * driver is ready to receive asynchronous events. This
1176 * function should be called during the first init and
1177 * after every hard-reset of the device
Bharat Jauhari285c0fa2021-03-25 18:15:40 +02001178 * @get_msi_info: Retrieve asic-specific MSI ID of the f/w async event
1179 * @map_pll_idx_to_fw_idx: convert driver specific per asic PLL index to
1180 * generic f/w compatible PLL Indexes
Bharat Jauhari4b099012021-05-28 13:14:34 +03001181 * @init_firmware_loader: initialize data for FW loader.
1182 * @init_cpu_scrambler_dram: Enable CPU specific DRAM scrambling
Yuri Nudelman938b7932021-06-06 10:28:51 +03001183 * @state_dump_init: initialize constants required for state dump
farah kassabridadf17a2021-05-24 18:09:22 +03001184 * @get_sob_addr: get SOB base address offset.
Ohad Sharabib9317d52021-07-15 15:20:44 +03001185 * @set_pci_memory_regions: setting properties of PCI memory regions
Ohad Sharabi72d66252021-08-01 23:02:07 +03001186 * @get_stream_master_qid_arr: get pointer to stream masters QID array
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001187 */
1188struct hl_asic_funcs {
1189 int (*early_init)(struct hl_device *hdev);
1190 int (*early_fini)(struct hl_device *hdev);
Oded Gabbayd91389b2019-02-16 00:39:19 +02001191 int (*late_init)(struct hl_device *hdev);
1192 void (*late_fini)(struct hl_device *hdev);
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001193 int (*sw_init)(struct hl_device *hdev);
1194 int (*sw_fini)(struct hl_device *hdev);
Oded Gabbay839c4802019-02-16 00:39:16 +02001195 int (*hw_init)(struct hl_device *hdev);
Oded Gabbay8d9aa982021-08-09 22:43:37 +03001196 void (*hw_fini)(struct hl_device *hdev, bool hard_reset, bool fw_reset);
1197 void (*halt_engines)(struct hl_device *hdev, bool hard_reset, bool fw_reset);
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001198 int (*suspend)(struct hl_device *hdev);
1199 int (*resume)(struct hl_device *hdev);
Zvika Yehudai1ee8e2b2021-07-06 13:50:32 +03001200 int (*mmap)(struct hl_device *hdev, struct vm_area_struct *vma,
Hillf Danton0db57532020-08-23 07:32:42 +08001201 void *cpu_addr, dma_addr_t dma_addr, size_t size);
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001202 void (*ring_doorbell)(struct hl_device *hdev, u32 hw_queue_id, u32 pi);
Oded Gabbayb9040c92019-08-08 15:45:58 +03001203 void (*pqe_write)(struct hl_device *hdev, __le64 *pqe,
1204 struct hl_bd *bd);
Oded Gabbayd9c3aa82019-05-01 11:47:04 +03001205 void* (*asic_dma_alloc_coherent)(struct hl_device *hdev, size_t size,
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001206 dma_addr_t *dma_handle, gfp_t flag);
Oded Gabbayd9c3aa82019-05-01 11:47:04 +03001207 void (*asic_dma_free_coherent)(struct hl_device *hdev, size_t size,
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001208 void *cpu_addr, dma_addr_t dma_handle);
farah kassabri03df1362020-05-06 11:17:38 +03001209 int (*scrub_device_mem)(struct hl_device *hdev, u64 addr, u64 size);
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001210 void* (*get_int_queue_base)(struct hl_device *hdev, u32 queue_id,
1211 dma_addr_t *dma_handle, u16 *queue_len);
1212 int (*test_queues)(struct hl_device *hdev);
Oded Gabbayd9c3aa82019-05-01 11:47:04 +03001213 void* (*asic_dma_pool_zalloc)(struct hl_device *hdev, size_t size,
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001214 gfp_t mem_flags, dma_addr_t *dma_handle);
Oded Gabbayd9c3aa82019-05-01 11:47:04 +03001215 void (*asic_dma_pool_free)(struct hl_device *hdev, void *vaddr,
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001216 dma_addr_t dma_addr);
1217 void* (*cpu_accessible_dma_pool_alloc)(struct hl_device *hdev,
1218 size_t size, dma_addr_t *dma_handle);
1219 void (*cpu_accessible_dma_pool_free)(struct hl_device *hdev,
1220 size_t size, void *vaddr);
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001221 void (*hl_dma_unmap_sg)(struct hl_device *hdev,
Tomer Tayar94cb6692019-05-01 11:28:15 +03001222 struct scatterlist *sgl, int nents,
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001223 enum dma_data_direction dir);
1224 int (*cs_parser)(struct hl_device *hdev, struct hl_cs_parser *parser);
1225 int (*asic_dma_map_sg)(struct hl_device *hdev,
Tomer Tayar94cb6692019-05-01 11:28:15 +03001226 struct scatterlist *sgl, int nents,
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001227 enum dma_data_direction dir);
1228 u32 (*get_dma_desc_list_size)(struct hl_device *hdev,
1229 struct sg_table *sgt);
Oded Gabbay921a4652019-05-12 16:53:16 +03001230 void (*add_end_of_cb_packets)(struct hl_device *hdev,
Arnd Bergmann82948e62020-10-26 17:08:06 +01001231 void *kernel_address, u32 len,
Oded Gabbay926ba4c2020-03-31 11:57:11 +03001232 u64 cq_addr, u32 cq_val, u32 msix_num,
1233 bool eb);
Oded Gabbay1251f232019-02-16 00:39:18 +02001234 void (*update_eq_ci)(struct hl_device *hdev, u32 val);
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001235 int (*context_switch)(struct hl_device *hdev, u32 asid);
1236 void (*restore_phase_topology)(struct hl_device *hdev);
Ofir Bittona5778d12021-02-24 11:51:40 +02001237 int (*debugfs_read32)(struct hl_device *hdev, u64 addr,
1238 bool user_address, u32 *val);
1239 int (*debugfs_write32)(struct hl_device *hdev, u64 addr,
1240 bool user_address, u32 val);
1241 int (*debugfs_read64)(struct hl_device *hdev, u64 addr,
1242 bool user_address, u64 *val);
1243 int (*debugfs_write64)(struct hl_device *hdev, u64 addr,
1244 bool user_address, u64 val);
Oded Gabbay639781d2021-04-02 01:43:18 +03001245 int (*debugfs_read_dma)(struct hl_device *hdev, u64 addr, u32 size,
1246 void *blob_addr);
Oded Gabbayd91389b2019-02-16 00:39:19 +02001247 void (*add_device_attr)(struct hl_device *hdev,
1248 struct attribute_group *dev_attr_grp);
Oded Gabbay1251f232019-02-16 00:39:18 +02001249 void (*handle_eqe)(struct hl_device *hdev,
1250 struct hl_eq_entry *eq_entry);
Oded Gabbayd91389b2019-02-16 00:39:19 +02001251 void (*set_pll_profile)(struct hl_device *hdev,
1252 enum hl_pll_frequency freq);
Oded Gabbaye9730762019-08-28 21:51:52 +03001253 void* (*get_events_stat)(struct hl_device *hdev, bool aggregate,
1254 u32 *size);
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001255 u64 (*read_pte)(struct hl_device *hdev, u64 addr);
1256 void (*write_pte)(struct hl_device *hdev, u64 addr, u64 val);
Omer Shpigelman8ff5f4f2020-05-24 23:06:59 +03001257 int (*mmu_invalidate_cache)(struct hl_device *hdev, bool is_hard,
Omer Shpigelman7b6e4ea2019-11-14 18:23:53 +00001258 u32 flags);
Omer Shpigelman8ff5f4f2020-05-24 23:06:59 +03001259 int (*mmu_invalidate_cache_range)(struct hl_device *hdev, bool is_hard,
Alon Mizrahi08c03a12021-04-08 15:30:59 +03001260 u32 flags, u32 asid, u64 va, u64 size);
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02001261 int (*send_heartbeat)(struct hl_device *hdev);
Oded Gabbaye38bfd32020-07-03 20:46:12 +03001262 void (*set_clock_gating)(struct hl_device *hdev);
Oded Gabbayca624332020-05-09 12:17:21 +03001263 void (*disable_clock_gating)(struct hl_device *hdev);
Omer Shpigelman315bc052019-04-01 22:31:22 +03001264 int (*debug_coresight)(struct hl_device *hdev, void *data);
Ohad Sharabicf303392021-01-17 16:01:56 +02001265 bool (*is_device_idle)(struct hl_device *hdev, u64 *mask_arr,
1266 u8 mask_len, struct seq_file *s);
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02001267 int (*soft_reset_late_init)(struct hl_device *hdev);
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001268 void (*hw_queues_lock)(struct hl_device *hdev);
1269 void (*hw_queues_unlock)(struct hl_device *hdev);
Oded Gabbayd8dd7b02019-02-16 00:39:23 +02001270 u32 (*get_pci_id)(struct hl_device *hdev);
Oded Gabbayd91389b2019-02-16 00:39:19 +02001271 int (*get_eeprom_data)(struct hl_device *hdev, void *data,
1272 size_t max_size);
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001273 int (*send_cpu_message)(struct hl_device *hdev, u32 *msg,
Alon Mizrahi439bc472020-11-10 13:49:10 +02001274 u16 len, u32 timeout, u64 *result);
Tomer Tayarb6f897d2019-03-05 16:48:42 +02001275 int (*pci_bars_map)(struct hl_device *hdev);
Tomer Tayarb6f897d2019-03-05 16:48:42 +02001276 int (*init_iatu)(struct hl_device *hdev);
Oded Gabbayb2377e02019-04-22 11:49:06 +03001277 u32 (*rreg)(struct hl_device *hdev, u32 reg);
1278 void (*wreg)(struct hl_device *hdev, u32 reg, u32 val);
Omer Shpigelman89225ce2019-05-01 14:38:38 +03001279 void (*halt_coresight)(struct hl_device *hdev);
Ofir Bittona04b7cd2020-07-13 13:36:55 +03001280 int (*ctx_init)(struct hl_ctx *ctx);
Ofir Bitton5de406c2020-09-10 10:56:26 +03001281 void (*ctx_fini)(struct hl_ctx *ctx);
Oded Gabbay62c1e122019-10-10 15:48:59 +03001282 int (*get_clk_rate)(struct hl_device *hdev, u32 *cur_clk, u32 *max_clk);
Omer Shpigelman1fa185c2020-03-01 19:59:39 +02001283 u32 (*get_queue_id_for_cq)(struct hl_device *hdev, u32 cq_idx);
Oded Gabbay7e1c07d2020-03-26 12:32:56 +02001284 int (*load_firmware_to_device)(struct hl_device *hdev);
Ofir Bitton47f6b412020-04-16 13:47:15 +03001285 int (*load_boot_fit_to_device)(struct hl_device *hdev);
Omer Shpigelmanec2f8a32020-05-07 13:43:05 +03001286 u32 (*get_signal_cb_size)(struct hl_device *hdev);
1287 u32 (*get_wait_cb_size)(struct hl_device *hdev);
Ofir Bitton2992c1d2020-09-10 09:40:35 +03001288 u32 (*gen_signal_cb)(struct hl_device *hdev, void *data, u16 sob_id,
Alon Mizrahi72ab9ca52020-12-02 19:55:30 +02001289 u32 size, bool eb);
Ofir Bitton2992c1d2020-09-10 09:40:35 +03001290 u32 (*gen_wait_cb)(struct hl_device *hdev,
Ofir Bitton3cf74b32020-09-10 09:17:50 +03001291 struct hl_gen_wait_properties *prop);
Omer Shpigelmanec2f8a32020-05-07 13:43:05 +03001292 void (*reset_sob)(struct hl_device *hdev, void *data);
Ofir Bitton5fe1c172020-09-10 10:10:55 +03001293 void (*reset_sob_group)(struct hl_device *hdev, u16 sob_group);
Oded Gabbaycb056b92020-03-29 13:18:30 +03001294 void (*set_dma_mask_from_fw)(struct hl_device *hdev);
Tomer Tayar25e7aeb2020-03-31 22:46:36 +03001295 u64 (*get_device_time)(struct hl_device *hdev);
farah kassabri8ca20722021-06-20 11:08:19 +03001296 int (*collective_wait_init_cs)(struct hl_cs *cs);
Ofir Bitton5fe1c172020-09-10 10:10:55 +03001297 int (*collective_wait_create_jobs)(struct hl_device *hdev,
farah kassabrie4cdccd2021-05-26 10:43:36 +03001298 struct hl_ctx *ctx, struct hl_cs *cs,
1299 u32 wait_queue_id, u32 collective_engine_id,
1300 u32 encaps_signal_offset);
farah kassabri89473a12021-01-12 17:24:00 +02001301 u64 (*scramble_addr)(struct hl_device *hdev, u64 addr);
1302 u64 (*descramble_addr)(struct hl_device *hdev, u64 addr);
Ofir Bittond2b980f2021-01-07 12:14:17 +02001303 void (*ack_protection_bits_errors)(struct hl_device *hdev);
Ofir Bittond00697f2021-01-05 12:55:06 +02001304 int (*get_hw_block_id)(struct hl_device *hdev, u64 block_addr,
Oded Gabbay6df50d22021-02-05 16:04:34 +02001305 u32 *block_size, u32 *block_id);
Ofir Bittond00697f2021-01-05 12:55:06 +02001306 int (*hw_block_mmap)(struct hl_device *hdev, struct vm_area_struct *vma,
1307 u32 block_id, u32 block_size);
Oded Gabbay28bcf1f2021-02-01 21:23:43 +02001308 void (*enable_events_from_fw)(struct hl_device *hdev);
Oded Gabbay90bd4792021-04-23 15:57:39 +03001309 void (*get_msi_info)(__le32 *table);
Bharat Jauhari285c0fa2021-03-25 18:15:40 +02001310 int (*map_pll_idx_to_fw_idx)(u32 pll_idx);
Ohad Sharabia22f0ec2021-04-11 23:06:46 +03001311 void (*init_firmware_loader)(struct hl_device *hdev);
Bharat Jauhari4b099012021-05-28 13:14:34 +03001312 void (*init_cpu_scrambler_dram)(struct hl_device *hdev);
Yuri Nudelman938b7932021-06-06 10:28:51 +03001313 void (*state_dump_init)(struct hl_device *hdev);
farah kassabridadf17a2021-05-24 18:09:22 +03001314 u32 (*get_sob_addr)(struct hl_device *hdev, u32 sob_id);
Ohad Sharabib9317d52021-07-15 15:20:44 +03001315 void (*set_pci_memory_regions)(struct hl_device *hdev);
Ohad Sharabi72d66252021-08-01 23:02:07 +03001316 u32* (*get_stream_master_qid_arr)(void);
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001317};
Oded Gabbayc4d66342019-02-16 00:39:11 +02001318
Oded Gabbay0861e412019-02-16 00:39:14 +02001319
1320/*
1321 * CONTEXTS
1322 */
1323
1324#define HL_KERNEL_ASID_ID 0
1325
1326/**
Ofir Bitton784b9162020-10-22 11:05:55 +03001327 * enum hl_va_range_type - virtual address range type.
1328 * @HL_VA_RANGE_TYPE_HOST: range type of host pages
1329 * @HL_VA_RANGE_TYPE_HOST_HUGE: range type of host huge pages
1330 * @HL_VA_RANGE_TYPE_DRAM: range type of dram pages
1331 */
1332enum hl_va_range_type {
1333 HL_VA_RANGE_TYPE_HOST,
1334 HL_VA_RANGE_TYPE_HOST_HUGE,
1335 HL_VA_RANGE_TYPE_DRAM,
1336 HL_VA_RANGE_TYPE_MAX
1337};
1338
1339/**
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001340 * struct hl_va_range - virtual addresses range.
1341 * @lock: protects the virtual addresses list.
1342 * @list: list of virtual addresses blocks available for mappings.
1343 * @start_addr: range start address.
1344 * @end_addr: range end address.
Ofir Bitton784b9162020-10-22 11:05:55 +03001345 * @page_size: page size of this va range.
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001346 */
1347struct hl_va_range {
1348 struct mutex lock;
1349 struct list_head list;
1350 u64 start_addr;
1351 u64 end_addr;
Ofir Bitton784b9162020-10-22 11:05:55 +03001352 u32 page_size;
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001353};
1354
1355/**
farah kassabrie7536432020-10-12 14:30:26 +03001356 * struct hl_cs_counters_atomic - command submission counters
1357 * @out_of_mem_drop_cnt: dropped due to memory allocation issue
1358 * @parsing_drop_cnt: dropped due to error in packet parsing
1359 * @queue_full_drop_cnt: dropped due to queue full
1360 * @device_in_reset_drop_cnt: dropped due to device in reset
1361 * @max_cs_in_flight_drop_cnt: dropped due to maximum CS in-flight
Alon Mizrahia3fd2832020-12-08 16:14:01 +02001362 * @validation_drop_cnt: dropped due to error in validation
farah kassabrie7536432020-10-12 14:30:26 +03001363 */
1364struct hl_cs_counters_atomic {
1365 atomic64_t out_of_mem_drop_cnt;
1366 atomic64_t parsing_drop_cnt;
1367 atomic64_t queue_full_drop_cnt;
1368 atomic64_t device_in_reset_drop_cnt;
1369 atomic64_t max_cs_in_flight_drop_cnt;
Alon Mizrahia3fd2832020-12-08 16:14:01 +02001370 atomic64_t validation_drop_cnt;
farah kassabrie7536432020-10-12 14:30:26 +03001371};
1372
1373/**
Tomer Tayardb1a8dd2021-06-15 10:55:43 +03001374 * struct hl_dmabuf_priv - a dma-buf private object.
1375 * @dmabuf: pointer to dma-buf object.
1376 * @ctx: pointer to the dma-buf owner's context.
1377 * @phys_pg_pack: pointer to physical page pack if the dma-buf was exported for
1378 * memory allocation handle.
1379 * @device_address: physical address of the device's memory. Relevant only
1380 * if phys_pg_pack is NULL (dma-buf was exported from address).
1381 * The total size can be taken from the dmabuf object.
1382 */
1383struct hl_dmabuf_priv {
1384 struct dma_buf *dmabuf;
1385 struct hl_ctx *ctx;
1386 struct hl_vm_phys_pg_pack *phys_pg_pack;
1387 uint64_t device_address;
1388};
1389
1390/**
Oded Gabbay0861e412019-02-16 00:39:14 +02001391 * struct hl_ctx - user/kernel context.
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001392 * @mem_hash: holds mapping from virtual address to virtual memory area
1393 * descriptor (hl_vm_phys_pg_list or hl_userptr).
Omer Shpigelman66542c32019-02-24 09:17:55 +02001394 * @mmu_shadow_hash: holds a mapping from shadow address to pgt_info structure.
Oded Gabbay4c172bb2019-08-30 16:59:33 +03001395 * @hpriv: pointer to the private (Kernel Driver) data of the process (fd).
Oded Gabbay0861e412019-02-16 00:39:14 +02001396 * @hdev: pointer to the device structure.
1397 * @refcount: reference counter for the context. Context is released only when
1398 * this hits 0l. It is incremented on CS and CS_WAIT.
Ofir Bittona98d73c2020-07-15 08:52:39 +03001399 * @cs_pending: array of hl fence objects representing pending CS.
Ofir Bitton784b9162020-10-22 11:05:55 +03001400 * @va_range: holds available virtual addresses for host and dram mappings.
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001401 * @mem_hash_lock: protects the mem_hash.
Omer Shpigelman8ff5f4f2020-05-24 23:06:59 +03001402 * @mmu_lock: protects the MMU page tables. Any change to the PGT, modifying the
1403 * MMU hash or walking the PGT requires talking this lock.
Sagiv Ozeria4371c12021-02-23 11:01:08 +02001404 * @hw_block_list_lock: protects the HW block memory list.
Oded Gabbayc2164772019-02-16 00:39:24 +02001405 * @debugfs_list: node in debugfs list of contexts.
Sagiv Ozeria4371c12021-02-23 11:01:08 +02001406 * @hw_block_mem_list: list of HW block virtual mapped addresses.
farah kassabrie7536432020-10-12 14:30:26 +03001407 * @cs_counters: context command submission counters.
Tomer Tayaref6a0f62020-07-09 16:17:48 +03001408 * @cb_va_pool: device VA pool for command buffers which are mapped to the
1409 * device's MMU.
farah kassabridadf17a2021-05-24 18:09:22 +03001410 * @sig_mgr: encaps signals handle manager.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001411 * @cs_sequence: sequence number for CS. Value is assigned to a CS and passed
1412 * to user so user could inquire about CS. It is used as
1413 * index to cs_pending array.
Omer Shpigelman27ca384c2019-02-28 10:46:11 +02001414 * @dram_default_hops: array that holds all hops addresses needed for default
1415 * DRAM mapping.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001416 * @cs_lock: spinlock to protect cs_sequence.
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001417 * @dram_phys_mem: amount of used physical DRAM memory by this context.
Oded Gabbay027d35d2019-04-25 20:15:42 +03001418 * @thread_ctx_switch_token: token to prevent multiple threads of the same
1419 * context from running the context switch phase.
1420 * Only a single thread should run it.
1421 * @thread_ctx_switch_wait_token: token to prevent the threads that didn't run
1422 * the context switch phase from moving to their
1423 * execution phase before the context switch phase
1424 * has finished.
Oded Gabbay0861e412019-02-16 00:39:14 +02001425 * @asid: context's unique address space ID in the device's MMU.
Oded Gabbayb8887512019-07-15 21:55:57 +03001426 * @handle: context's opaque handle for user
Oded Gabbay0861e412019-02-16 00:39:14 +02001427 */
1428struct hl_ctx {
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001429 DECLARE_HASHTABLE(mem_hash, MEM_HASH_TABLE_BITS);
Omer Shpigelman66542c32019-02-24 09:17:55 +02001430 DECLARE_HASHTABLE(mmu_shadow_hash, MMU_HASH_TABLE_BITS);
farah kassabrie7536432020-10-12 14:30:26 +03001431 struct hl_fpriv *hpriv;
1432 struct hl_device *hdev;
1433 struct kref refcount;
1434 struct hl_fence **cs_pending;
Ofir Bitton784b9162020-10-22 11:05:55 +03001435 struct hl_va_range *va_range[HL_VA_RANGE_TYPE_MAX];
farah kassabrie7536432020-10-12 14:30:26 +03001436 struct mutex mem_hash_lock;
1437 struct mutex mmu_lock;
Sagiv Ozeria4371c12021-02-23 11:01:08 +02001438 struct mutex hw_block_list_lock;
farah kassabrie7536432020-10-12 14:30:26 +03001439 struct list_head debugfs_list;
Sagiv Ozeria4371c12021-02-23 11:01:08 +02001440 struct list_head hw_block_mem_list;
farah kassabrie7536432020-10-12 14:30:26 +03001441 struct hl_cs_counters_atomic cs_counters;
1442 struct gen_pool *cb_va_pool;
farah kassabridadf17a2021-05-24 18:09:22 +03001443 struct hl_encaps_signals_mgr sig_mgr;
farah kassabrie7536432020-10-12 14:30:26 +03001444 u64 cs_sequence;
1445 u64 *dram_default_hops;
1446 spinlock_t cs_lock;
1447 atomic64_t dram_phys_mem;
1448 atomic_t thread_ctx_switch_token;
1449 u32 thread_ctx_switch_wait_token;
1450 u32 asid;
1451 u32 handle;
Oded Gabbay0861e412019-02-16 00:39:14 +02001452};
1453
1454/**
1455 * struct hl_ctx_mgr - for handling multiple contexts.
1456 * @ctx_lock: protects ctx_handles.
1457 * @ctx_handles: idr to hold all ctx handles.
1458 */
1459struct hl_ctx_mgr {
1460 struct mutex ctx_lock;
1461 struct idr ctx_handles;
1462};
1463
1464
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001465
1466/*
1467 * COMMAND SUBMISSIONS
1468 */
1469
1470/**
1471 * struct hl_userptr - memory mapping chunk information
1472 * @vm_type: type of the VM.
1473 * @job_node: linked-list node for hanging the object on the Job's list.
Daniel Vetterd4cb1922020-11-27 17:41:17 +01001474 * @pages: pointer to struct page array
1475 * @npages: size of @pages array
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001476 * @sgt: pointer to the scatter-gather table that holds the pages.
1477 * @dir: for DMA unmapping, the direction must be supplied, so save it.
1478 * @debugfs_list: node in debugfs list of command submissions.
Yuri Nudelman714fccb2021-07-27 17:39:42 +03001479 * @pid: the pid of the user process owning the memory
Omer Shpigelman7f74d4d2019-08-12 11:48:46 +03001480 * @addr: user-space virtual address of the start of the memory area.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001481 * @size: size of the memory area to pin & map.
1482 * @dma_mapped: true if the SG was mapped to DMA addresses, false otherwise.
1483 */
1484struct hl_userptr {
Oded Gabbay82629c72021-06-29 18:08:05 +03001485 enum vm_type vm_type; /* must be first */
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001486 struct list_head job_node;
Daniel Vetterd4cb1922020-11-27 17:41:17 +01001487 struct page **pages;
1488 unsigned int npages;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001489 struct sg_table *sgt;
1490 enum dma_data_direction dir;
1491 struct list_head debugfs_list;
Yuri Nudelman714fccb2021-07-27 17:39:42 +03001492 pid_t pid;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001493 u64 addr;
Oded Gabbay00ce0652021-06-29 18:12:46 +03001494 u64 size;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001495 u8 dma_mapped;
1496};
1497
1498/**
1499 * struct hl_cs - command submission.
1500 * @jobs_in_queue_cnt: per each queue, maintain counter of submitted jobs.
1501 * @ctx: the context this CS belongs to.
1502 * @job_list: list of the CS's jobs in the various queues.
1503 * @job_lock: spinlock for the CS's jobs list. Needed for free_job.
1504 * @refcount: reference counter for usage of the CS.
1505 * @fence: pointer to the fence object of this CS.
Omer Shpigelmanb0b5d922020-05-07 13:57:36 +03001506 * @signal_fence: pointer to the fence object of the signal CS (used by wait
1507 * CS only).
Omer Shpigelmanb75f2252020-05-07 14:31:49 +03001508 * @finish_work: workqueue object to run when CS is completed by H/W.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001509 * @work_tdr: delayed work node for TDR.
1510 * @mirror_node : node in device mirror list of command submissions.
Ofir Bitton2795c882020-12-08 13:47:05 +02001511 * @staged_cs_node: node in the staged cs list.
Oded Gabbayc2164772019-02-16 00:39:24 +02001512 * @debugfs_list: node in debugfs list of command submissions.
farah kassabrie4cdccd2021-05-26 10:43:36 +03001513 * @encaps_sig_hdl: holds the encaps signals handle.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001514 * @sequence: the sequence number of this CS.
Ofir Bitton2795c882020-12-08 13:47:05 +02001515 * @staged_sequence: the sequence of the staged submission this CS is part of,
1516 * relevant only if staged_cs is set.
Alon Mizrahicf393952021-02-22 15:53:24 +02001517 * @timeout_jiffies: cs timeout in jiffies.
Yuri Nudelman8e8125f2021-05-25 14:49:52 +03001518 * @submission_time_jiffies: submission time of the cs
Omer Shpigelmanb0b5d922020-05-07 13:57:36 +03001519 * @type: CS_TYPE_*.
farah kassabrie4cdccd2021-05-26 10:43:36 +03001520 * @encaps_sig_hdl_id: encaps signals handle id, set for the first staged cs.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001521 * @submitted: true if CS was submitted to H/W.
1522 * @completed: true if CS was completed by device.
1523 * @timedout : true if CS was timedout.
1524 * @tdr_active: true if TDR was activated for this CS (to prevent
1525 * double TDR activation).
1526 * @aborted: true if CS was aborted due to some device error.
Ofir Bitton0811b392020-12-06 17:18:02 +02001527 * @timestamp: true if a timestmap must be captured upon completion.
1528 * @staged_last: true if this is the last staged CS and needs completion.
1529 * @staged_first: true if this is the first staged CS and we need to receive
1530 * timeout for this CS.
1531 * @staged_cs: true if this CS is part of a staged submission.
Yuri Nudelman8e8125f2021-05-25 14:49:52 +03001532 * @skip_reset_on_timeout: true if we shall not reset the device in case
1533 * timeout occurs (debug scenario).
farah kassabrie4cdccd2021-05-26 10:43:36 +03001534 * @encaps_signals: true if this CS has encaps reserved signals.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001535 */
1536struct hl_cs {
Ofir Bitton3abc99b2020-06-23 14:50:39 +03001537 u16 *jobs_in_queue_cnt;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001538 struct hl_ctx *ctx;
1539 struct list_head job_list;
1540 spinlock_t job_lock;
1541 struct kref refcount;
Ofir Bittona98d73c2020-07-15 08:52:39 +03001542 struct hl_fence *fence;
1543 struct hl_fence *signal_fence;
Omer Shpigelmanb75f2252020-05-07 14:31:49 +03001544 struct work_struct finish_work;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001545 struct delayed_work work_tdr;
1546 struct list_head mirror_node;
Ofir Bitton2795c882020-12-08 13:47:05 +02001547 struct list_head staged_cs_node;
Oded Gabbayc2164772019-02-16 00:39:24 +02001548 struct list_head debugfs_list;
farah kassabrie4cdccd2021-05-26 10:43:36 +03001549 struct hl_cs_encaps_sig_handle *encaps_sig_hdl;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001550 u64 sequence;
Ofir Bitton2795c882020-12-08 13:47:05 +02001551 u64 staged_sequence;
Alon Mizrahicf393952021-02-22 15:53:24 +02001552 u64 timeout_jiffies;
Yuri Nudelman8e8125f2021-05-25 14:49:52 +03001553 u64 submission_time_jiffies;
Omer Shpigelmanb0b5d922020-05-07 13:57:36 +03001554 enum hl_cs_type type;
farah kassabrie4cdccd2021-05-26 10:43:36 +03001555 u32 encaps_sig_hdl_id;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001556 u8 submitted;
1557 u8 completed;
1558 u8 timedout;
1559 u8 tdr_active;
1560 u8 aborted;
Ofir Bittonbd2f4772020-11-10 17:26:22 +02001561 u8 timestamp;
Ofir Bitton0811b392020-12-06 17:18:02 +02001562 u8 staged_last;
1563 u8 staged_first;
1564 u8 staged_cs;
Yuri Nudelman8e8125f2021-05-25 14:49:52 +03001565 u8 skip_reset_on_timeout;
farah kassabrie4cdccd2021-05-26 10:43:36 +03001566 u8 encaps_signals;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001567};
1568
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001569/**
1570 * struct hl_cs_job - command submission job.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001571 * @cs_node: the node to hang on the CS jobs list.
1572 * @cs: the CS this job belongs to.
1573 * @user_cb: the CB we got from the user.
1574 * @patched_cb: in case of patching, this is internal CB which is submitted on
1575 * the queue instead of the CB we got from the IOCTL.
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001576 * @finish_work: workqueue object to run when job is completed.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001577 * @userptr_list: linked-list of userptr mappings that belong to this job and
1578 * wait for completion.
Oded Gabbayc2164772019-02-16 00:39:24 +02001579 * @debugfs_list: node in debugfs list of command submission jobs.
Tomer Tayar649c4592020-08-10 17:30:35 +03001580 * @refcount: reference counter for usage of the CS job.
Tomer Tayarcb596ae2019-10-03 15:22:36 +00001581 * @queue_type: the type of the H/W queue this job is submitted to.
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001582 * @id: the id of this job inside a CS.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001583 * @hw_queue_id: the id of the H/W queue this job is submitted to.
1584 * @user_cb_size: the actual size of the CB we got from the user.
1585 * @job_cb_size: the actual size of the CB that we put on the queue.
farah kassabrie4cdccd2021-05-26 10:43:36 +03001586 * @encaps_sig_wait_offset: encapsulated signals offset, which allow user
1587 * to wait on part of the reserved signals.
Tomer Tayarcb596ae2019-10-03 15:22:36 +00001588 * @is_kernel_allocated_cb: true if the CB handle we got from the user holds a
1589 * handle to a kernel-allocated CB object, false
1590 * otherwise (SRAM/DRAM/host address).
Oded Gabbay926ba4c2020-03-31 11:57:11 +03001591 * @contains_dma_pkt: whether the JOB contains at least one DMA packet. This
1592 * info is needed later, when adding the 2xMSG_PROT at the
1593 * end of the JOB, to know which barriers to put in the
1594 * MSG_PROT packets. Relevant only for GAUDI as GOYA doesn't
1595 * have streams so the engine can't be busy by another
1596 * stream.
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001597 */
1598struct hl_cs_job {
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001599 struct list_head cs_node;
1600 struct hl_cs *cs;
1601 struct hl_cb *user_cb;
1602 struct hl_cb *patched_cb;
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001603 struct work_struct finish_work;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001604 struct list_head userptr_list;
Oded Gabbayc2164772019-02-16 00:39:24 +02001605 struct list_head debugfs_list;
Tomer Tayar649c4592020-08-10 17:30:35 +03001606 struct kref refcount;
Tomer Tayarcb596ae2019-10-03 15:22:36 +00001607 enum hl_queue_type queue_type;
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001608 u32 id;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001609 u32 hw_queue_id;
1610 u32 user_cb_size;
1611 u32 job_cb_size;
farah kassabrie4cdccd2021-05-26 10:43:36 +03001612 u32 encaps_sig_wait_offset;
Tomer Tayarcb596ae2019-10-03 15:22:36 +00001613 u8 is_kernel_allocated_cb;
Oded Gabbay926ba4c2020-03-31 11:57:11 +03001614 u8 contains_dma_pkt;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001615};
1616
1617/**
Tomer Tayarf4356142019-10-02 13:53:52 +00001618 * struct hl_cs_parser - command submission parser properties.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001619 * @user_cb: the CB we got from the user.
1620 * @patched_cb: in case of patching, this is internal CB which is submitted on
1621 * the queue instead of the CB we got from the IOCTL.
1622 * @job_userptr_list: linked-list of userptr mappings that belong to the related
1623 * job and wait for completion.
1624 * @cs_sequence: the sequence number of the related CS.
Tomer Tayarcb596ae2019-10-03 15:22:36 +00001625 * @queue_type: the type of the H/W queue this job is submitted to.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001626 * @ctx_id: the ID of the context the related CS belongs to.
1627 * @hw_queue_id: the id of the H/W queue this job is submitted to.
1628 * @user_cb_size: the actual size of the CB we got from the user.
1629 * @patched_cb_size: the size of the CB after parsing.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001630 * @job_id: the id of the related job inside the related CS.
Tomer Tayarcb596ae2019-10-03 15:22:36 +00001631 * @is_kernel_allocated_cb: true if the CB handle we got from the user holds a
1632 * handle to a kernel-allocated CB object, false
1633 * otherwise (SRAM/DRAM/host address).
Oded Gabbay926ba4c2020-03-31 11:57:11 +03001634 * @contains_dma_pkt: whether the JOB contains at least one DMA packet. This
1635 * info is needed later, when adding the 2xMSG_PROT at the
1636 * end of the JOB, to know which barriers to put in the
1637 * MSG_PROT packets. Relevant only for GAUDI as GOYA doesn't
1638 * have streams so the engine can't be busy by another
1639 * stream.
Ofir Bittonac6fdbf2020-12-03 16:59:28 +02001640 * @completion: true if we need completion for this CS.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001641 */
1642struct hl_cs_parser {
1643 struct hl_cb *user_cb;
1644 struct hl_cb *patched_cb;
1645 struct list_head *job_userptr_list;
1646 u64 cs_sequence;
Tomer Tayarcb596ae2019-10-03 15:22:36 +00001647 enum hl_queue_type queue_type;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001648 u32 ctx_id;
1649 u32 hw_queue_id;
1650 u32 user_cb_size;
1651 u32 patched_cb_size;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001652 u8 job_id;
Tomer Tayarcb596ae2019-10-03 15:22:36 +00001653 u8 is_kernel_allocated_cb;
Oded Gabbay926ba4c2020-03-31 11:57:11 +03001654 u8 contains_dma_pkt;
Ofir Bittonac6fdbf2020-12-03 16:59:28 +02001655 u8 completion;
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001656};
Oded Gabbayd91389b2019-02-16 00:39:19 +02001657
Oded Gabbayc4d66342019-02-16 00:39:11 +02001658/*
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001659 * MEMORY STRUCTURE
1660 */
1661
1662/**
1663 * struct hl_vm_hash_node - hash element from virtual address to virtual
1664 * memory area descriptor (hl_vm_phys_pg_list or
1665 * hl_userptr).
1666 * @node: node to hang on the hash table in context object.
1667 * @vaddr: key virtual address.
1668 * @ptr: value pointer (hl_vm_phys_pg_list or hl_userptr).
1669 */
1670struct hl_vm_hash_node {
1671 struct hlist_node node;
1672 u64 vaddr;
1673 void *ptr;
1674};
1675
1676/**
Sagiv Ozeria4371c12021-02-23 11:01:08 +02001677 * struct hl_vm_hw_block_list_node - list element from user virtual address to
1678 * HW block id.
1679 * @node: node to hang on the list in context object.
1680 * @ctx: the context this node belongs to.
1681 * @vaddr: virtual address of the HW block.
1682 * @size: size of the block.
1683 * @id: HW block id (handle).
1684 */
1685struct hl_vm_hw_block_list_node {
1686 struct list_head node;
1687 struct hl_ctx *ctx;
1688 unsigned long vaddr;
1689 u32 size;
1690 u32 id;
1691};
1692
1693/**
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001694 * struct hl_vm_phys_pg_pack - physical page pack.
1695 * @vm_type: describes the type of the virtual area descriptor.
1696 * @pages: the physical page array.
Omer Shpigelmanbfb1ce12019-03-05 10:59:16 +02001697 * @npages: num physical pages in the pack.
1698 * @total_size: total size of all the pages in this list.
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001699 * @mapping_cnt: number of shared mappings.
Tomer Tayardb1a8dd2021-06-15 10:55:43 +03001700 * @exporting_cnt: number of dma-buf exporting.
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001701 * @asid: the context related to this list.
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001702 * @page_size: size of each page in the pack.
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001703 * @flags: HL_MEM_* flags related to this list.
1704 * @handle: the provided handle related to this list.
1705 * @offset: offset from the first page.
1706 * @contiguous: is contiguous physical memory.
1707 * @created_from_userptr: is product of host virtual address.
1708 */
1709struct hl_vm_phys_pg_pack {
Oded Gabbay82629c72021-06-29 18:08:05 +03001710 enum vm_type vm_type; /* must be first */
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001711 u64 *pages;
Omer Shpigelmanbfb1ce12019-03-05 10:59:16 +02001712 u64 npages;
1713 u64 total_size;
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001714 atomic_t mapping_cnt;
Tomer Tayardb1a8dd2021-06-15 10:55:43 +03001715 u32 exporting_cnt;
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001716 u32 asid;
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001717 u32 page_size;
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001718 u32 flags;
1719 u32 handle;
1720 u32 offset;
1721 u8 contiguous;
1722 u8 created_from_userptr;
1723};
1724
1725/**
1726 * struct hl_vm_va_block - virtual range block information.
1727 * @node: node to hang on the virtual range list in context object.
1728 * @start: virtual range start address.
1729 * @end: virtual range end address.
1730 * @size: virtual range size.
1731 */
1732struct hl_vm_va_block {
1733 struct list_head node;
1734 u64 start;
1735 u64 end;
1736 u64 size;
1737};
1738
1739/**
1740 * struct hl_vm - virtual memory manager for MMU.
1741 * @dram_pg_pool: pool for DRAM physical pages of 2MB.
1742 * @dram_pg_pool_refcount: reference counter for the pool usage.
1743 * @idr_lock: protects the phys_pg_list_handles.
1744 * @phys_pg_pack_handles: idr to hold all device allocations handles.
1745 * @init_done: whether initialization was done. We need this because VM
1746 * initialization might be skipped during device initialization.
1747 */
1748struct hl_vm {
1749 struct gen_pool *dram_pg_pool;
1750 struct kref dram_pg_pool_refcount;
1751 spinlock_t idr_lock;
1752 struct idr phys_pg_pack_handles;
1753 u8 init_done;
1754};
1755
Omer Shpigelman315bc052019-04-01 22:31:22 +03001756
1757/*
1758 * DEBUG, PROFILING STRUCTURE
1759 */
1760
1761/**
1762 * struct hl_debug_params - Coresight debug parameters.
1763 * @input: pointer to component specific input parameters.
1764 * @output: pointer to component specific output parameters.
1765 * @output_size: size of output buffer.
1766 * @reg_idx: relevant register ID.
1767 * @op: component operation to execute.
1768 * @enable: true if to enable component debugging, false otherwise.
1769 */
1770struct hl_debug_params {
1771 void *input;
1772 void *output;
1773 u32 output_size;
1774 u32 reg_idx;
1775 u32 op;
1776 bool enable;
1777};
1778
Omer Shpigelman0feaf862019-02-16 00:39:22 +02001779/*
Oded Gabbayc4d66342019-02-16 00:39:11 +02001780 * FILE PRIVATE STRUCTURE
1781 */
1782
1783/**
1784 * struct hl_fpriv - process information stored in FD private data.
1785 * @hdev: habanalabs device structure.
1786 * @filp: pointer to the given file structure.
1787 * @taskpid: current process ID.
Oded Gabbay86d53072019-07-30 11:49:36 +03001788 * @ctx: current executing context. TODO: remove for multiple ctx per process
Oded Gabbay0861e412019-02-16 00:39:14 +02001789 * @ctx_mgr: context manager to handle multiple context for this FD.
Oded Gabbaybe5d9262019-02-16 00:39:15 +02001790 * @cb_mgr: command buffer manager to handle multiple buffers for this FD.
Oded Gabbayc2164772019-02-16 00:39:24 +02001791 * @debugfs_list: list of relevant ASIC debugfs.
Oded Gabbayeb7caf82019-07-30 11:56:09 +03001792 * @dev_node: node in the device list of file private data
Oded Gabbayc4d66342019-02-16 00:39:11 +02001793 * @refcount: number of related contexts.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001794 * @restore_phase_mutex: lock for context switch and restore phase.
Oded Gabbay4d6a7752019-07-30 09:10:50 +03001795 * @is_control: true for control device, false otherwise
Oded Gabbayc4d66342019-02-16 00:39:11 +02001796 */
1797struct hl_fpriv {
1798 struct hl_device *hdev;
1799 struct file *filp;
1800 struct pid *taskpid;
Oded Gabbay86d53072019-07-30 11:49:36 +03001801 struct hl_ctx *ctx;
Oded Gabbay0861e412019-02-16 00:39:14 +02001802 struct hl_ctx_mgr ctx_mgr;
Oded Gabbaybe5d9262019-02-16 00:39:15 +02001803 struct hl_cb_mgr cb_mgr;
Oded Gabbayc2164772019-02-16 00:39:24 +02001804 struct list_head debugfs_list;
Oded Gabbayeb7caf82019-07-30 11:56:09 +03001805 struct list_head dev_node;
Oded Gabbayc4d66342019-02-16 00:39:11 +02001806 struct kref refcount;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02001807 struct mutex restore_phase_mutex;
Oded Gabbay4d6a7752019-07-30 09:10:50 +03001808 u8 is_control;
Oded Gabbayc4d66342019-02-16 00:39:11 +02001809};
1810
1811
1812/*
Oded Gabbayc2164772019-02-16 00:39:24 +02001813 * DebugFS
1814 */
1815
1816/**
1817 * struct hl_info_list - debugfs file ops.
1818 * @name: file name.
1819 * @show: function to output information.
1820 * @write: function to write to the file.
1821 */
1822struct hl_info_list {
1823 const char *name;
1824 int (*show)(struct seq_file *s, void *data);
1825 ssize_t (*write)(struct file *file, const char __user *buf,
1826 size_t count, loff_t *f_pos);
1827};
1828
1829/**
1830 * struct hl_debugfs_entry - debugfs dentry wrapper.
Oded Gabbayc2164772019-02-16 00:39:24 +02001831 * @info_ent: dentry realted ops.
1832 * @dev_entry: ASIC specific debugfs manager.
1833 */
1834struct hl_debugfs_entry {
Oded Gabbayc2164772019-02-16 00:39:24 +02001835 const struct hl_info_list *info_ent;
1836 struct hl_dbg_device_entry *dev_entry;
1837};
1838
1839/**
1840 * struct hl_dbg_device_entry - ASIC specific debugfs manager.
1841 * @root: root dentry.
1842 * @hdev: habanalabs device structure.
1843 * @entry_arr: array of available hl_debugfs_entry.
1844 * @file_list: list of available debugfs files.
1845 * @file_mutex: protects file_list.
1846 * @cb_list: list of available CBs.
1847 * @cb_spinlock: protects cb_list.
1848 * @cs_list: list of available CSs.
1849 * @cs_spinlock: protects cs_list.
1850 * @cs_job_list: list of available CB jobs.
1851 * @cs_job_spinlock: protects cs_job_list.
1852 * @userptr_list: list of available userptrs (virtual memory chunk descriptor).
1853 * @userptr_spinlock: protects userptr_list.
1854 * @ctx_mem_hash_list: list of available contexts with MMU mappings.
1855 * @ctx_mem_hash_spinlock: protects cb_list.
Oded Gabbay639781d2021-04-02 01:43:18 +03001856 * @blob_desc: descriptor of blob
Yuri Nudelman938b7932021-06-06 10:28:51 +03001857 * @state_dump: data of the system states in case of a bad cs.
1858 * @state_dump_sem: protects state_dump.
Oded Gabbayc2164772019-02-16 00:39:24 +02001859 * @addr: next address to read/write from/to in read/write32.
1860 * @mmu_addr: next virtual address to translate to physical address in mmu_show.
Yuri Nudelman89b21362021-07-29 11:44:28 +03001861 * @userptr_lookup: the target user ptr to look up for on demand.
Oded Gabbayc2164772019-02-16 00:39:24 +02001862 * @mmu_asid: ASID to use while translating in mmu_show.
Yuri Nudelman938b7932021-06-06 10:28:51 +03001863 * @state_dump_head: index of the latest state dump
Oded Gabbayc2164772019-02-16 00:39:24 +02001864 * @i2c_bus: generic u8 debugfs file for bus value to use in i2c_data_read.
Oded Gabbay639781d2021-04-02 01:43:18 +03001865 * @i2c_addr: generic u8 debugfs file for address value to use in i2c_data_read.
1866 * @i2c_reg: generic u8 debugfs file for register value to use in i2c_data_read.
Oded Gabbayc2164772019-02-16 00:39:24 +02001867 */
1868struct hl_dbg_device_entry {
1869 struct dentry *root;
1870 struct hl_device *hdev;
1871 struct hl_debugfs_entry *entry_arr;
1872 struct list_head file_list;
1873 struct mutex file_mutex;
1874 struct list_head cb_list;
1875 spinlock_t cb_spinlock;
1876 struct list_head cs_list;
1877 spinlock_t cs_spinlock;
1878 struct list_head cs_job_list;
1879 spinlock_t cs_job_spinlock;
1880 struct list_head userptr_list;
1881 spinlock_t userptr_spinlock;
1882 struct list_head ctx_mem_hash_list;
1883 spinlock_t ctx_mem_hash_spinlock;
Oded Gabbay639781d2021-04-02 01:43:18 +03001884 struct debugfs_blob_wrapper blob_desc;
Yuri Nudelman938b7932021-06-06 10:28:51 +03001885 char *state_dump[HL_STATE_DUMP_HIST_LEN];
1886 struct rw_semaphore state_dump_sem;
Oded Gabbayc2164772019-02-16 00:39:24 +02001887 u64 addr;
1888 u64 mmu_addr;
Yuri Nudelman89b21362021-07-29 11:44:28 +03001889 u64 userptr_lookup;
Oded Gabbayc2164772019-02-16 00:39:24 +02001890 u32 mmu_asid;
Yuri Nudelman938b7932021-06-06 10:28:51 +03001891 u32 state_dump_head;
Oded Gabbayc2164772019-02-16 00:39:24 +02001892 u8 i2c_bus;
1893 u8 i2c_addr;
1894 u8 i2c_reg;
1895};
1896
Yuri Nudelman938b7932021-06-06 10:28:51 +03001897/**
1898 * struct hl_hw_obj_name_entry - single hw object name, member of
1899 * hl_state_dump_specs
1900 * @node: link to the containing hash table
1901 * @name: hw object name
1902 * @id: object identifier
1903 */
1904struct hl_hw_obj_name_entry {
1905 struct hlist_node node;
1906 const char *name;
1907 u32 id;
1908};
1909
1910enum hl_state_dump_specs_props {
1911 SP_SYNC_OBJ_BASE_ADDR,
1912 SP_NEXT_SYNC_OBJ_ADDR,
1913 SP_SYNC_OBJ_AMOUNT,
1914 SP_MON_OBJ_WR_ADDR_LOW,
1915 SP_MON_OBJ_WR_ADDR_HIGH,
1916 SP_MON_OBJ_WR_DATA,
1917 SP_MON_OBJ_ARM_DATA,
1918 SP_MON_OBJ_STATUS,
1919 SP_MONITORS_AMOUNT,
1920 SP_TPC0_CMDQ,
1921 SP_TPC0_CFG_SO,
1922 SP_NEXT_TPC,
1923 SP_MME_CMDQ,
1924 SP_MME_CFG_SO,
1925 SP_NEXT_MME,
1926 SP_DMA_CMDQ,
1927 SP_DMA_CFG_SO,
1928 SP_DMA_QUEUES_OFFSET,
1929 SP_NUM_OF_MME_ENGINES,
1930 SP_SUB_MME_ENG_NUM,
1931 SP_NUM_OF_DMA_ENGINES,
1932 SP_NUM_OF_TPC_ENGINES,
1933 SP_ENGINE_NUM_OF_QUEUES,
1934 SP_ENGINE_NUM_OF_STREAMS,
1935 SP_ENGINE_NUM_OF_FENCES,
1936 SP_FENCE0_CNT_OFFSET,
1937 SP_FENCE0_RDATA_OFFSET,
1938 SP_CP_STS_OFFSET,
1939 SP_NUM_CORES,
1940
1941 SP_MAX
1942};
1943
1944enum hl_sync_engine_type {
1945 ENGINE_TPC,
1946 ENGINE_DMA,
1947 ENGINE_MME,
1948};
1949
1950/**
Yuri Nudelmanfd2010b2021-06-09 14:04:26 +03001951 * struct hl_mon_state_dump - represents a state dump of a single monitor
1952 * @id: monitor id
1953 * @wr_addr_low: address monitor will write to, low bits
1954 * @wr_addr_high: address monitor will write to, high bits
1955 * @wr_data: data monitor will write
1956 * @arm_data: register value containing monitor configuration
1957 * @status: monitor status
1958 */
1959struct hl_mon_state_dump {
1960 u32 id;
1961 u32 wr_addr_low;
1962 u32 wr_addr_high;
1963 u32 wr_data;
1964 u32 arm_data;
1965 u32 status;
1966};
1967
1968/**
Yuri Nudelman938b7932021-06-06 10:28:51 +03001969 * struct hl_sync_to_engine_map_entry - sync object id to engine mapping entry
1970 * @engine_type: type of the engine
1971 * @engine_id: id of the engine
1972 * @sync_id: id of the sync object
1973 */
1974struct hl_sync_to_engine_map_entry {
1975 struct hlist_node node;
1976 enum hl_sync_engine_type engine_type;
1977 u32 engine_id;
1978 u32 sync_id;
1979};
1980
1981/**
1982 * struct hl_sync_to_engine_map - maps sync object id to associated engine id
1983 * @tb: hash table containing the mapping, each element is of type
1984 * struct hl_sync_to_engine_map_entry
1985 */
1986struct hl_sync_to_engine_map {
1987 DECLARE_HASHTABLE(tb, SYNC_TO_ENGINE_HASH_TABLE_BITS);
1988};
1989
1990/**
1991 * struct hl_state_dump_specs_funcs - virtual functions used by the state dump
1992 * @gen_sync_to_engine_map: generate a hash map from sync obj id to its engine
Yuri Nudelmanfd2010b2021-06-09 14:04:26 +03001993 * @print_single_monitor: format monitor data as string
1994 * @monitor_valid: return true if given monitor dump is valid
1995 * @print_fences_single_engine: format fences data as string
Yuri Nudelman938b7932021-06-06 10:28:51 +03001996 */
1997struct hl_state_dump_specs_funcs {
1998 int (*gen_sync_to_engine_map)(struct hl_device *hdev,
1999 struct hl_sync_to_engine_map *map);
Yuri Nudelmanfd2010b2021-06-09 14:04:26 +03002000 int (*print_single_monitor)(char **buf, size_t *size, size_t *offset,
2001 struct hl_device *hdev,
2002 struct hl_mon_state_dump *mon);
2003 int (*monitor_valid)(struct hl_mon_state_dump *mon);
2004 int (*print_fences_single_engine)(struct hl_device *hdev,
2005 u64 base_offset,
2006 u64 status_base_offset,
2007 enum hl_sync_engine_type engine_type,
2008 u32 engine_id, char **buf,
2009 size_t *size, size_t *offset);
Yuri Nudelman938b7932021-06-06 10:28:51 +03002010};
2011
2012/**
2013 * struct hl_state_dump_specs - defines ASIC known hw objects names
2014 * @so_id_to_str_tb: sync objects names index table
2015 * @monitor_id_to_str_tb: monitors names index table
2016 * @funcs: virtual functions used for state dump
2017 * @sync_namager_names: readable names for sync manager if available (ex: N_E)
2018 * @props: pointer to a per asic const props array required for state dump
2019 */
2020struct hl_state_dump_specs {
2021 DECLARE_HASHTABLE(so_id_to_str_tb, OBJ_NAMES_HASH_TABLE_BITS);
2022 DECLARE_HASHTABLE(monitor_id_to_str_tb, OBJ_NAMES_HASH_TABLE_BITS);
2023 struct hl_state_dump_specs_funcs funcs;
2024 const char * const *sync_namager_names;
2025 s64 *props;
2026};
2027
Oded Gabbayc2164772019-02-16 00:39:24 +02002028
2029/*
Oded Gabbayc4d66342019-02-16 00:39:11 +02002030 * DEVICES
2031 */
2032
Ofir Bitton66a76402020-10-05 14:40:10 +03002033#define HL_STR_MAX 32
2034
Omer Shpigelman71731092021-08-16 13:27:12 +03002035#define HL_DEV_STS_MAX (HL_DEVICE_STATUS_LAST + 1)
Ofir Bitton66a76402020-10-05 14:40:10 +03002036
Oded Gabbayc4d66342019-02-16 00:39:11 +02002037/* Theoretical limit only. A single host can only contain up to 4 or 8 PCIe
Oded Gabbay4d6a7752019-07-30 09:10:50 +03002038 * x16 cards. In extreme cases, there are hosts that can accommodate 16 cards.
Oded Gabbayc4d66342019-02-16 00:39:11 +02002039 */
2040#define HL_MAX_MINORS 256
2041
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02002042/*
2043 * Registers read & write functions.
2044 */
2045
2046u32 hl_rreg(struct hl_device *hdev, u32 reg);
2047void hl_wreg(struct hl_device *hdev, u32 reg, u32 val);
2048
Oded Gabbayb2377e02019-04-22 11:49:06 +03002049#define RREG32(reg) hdev->asic_funcs->rreg(hdev, (reg))
2050#define WREG32(reg, v) hdev->asic_funcs->wreg(hdev, (reg), (v))
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02002051#define DREG32(reg) pr_info("REGISTER: " #reg " : 0x%08X\n", \
Oded Gabbayb2377e02019-04-22 11:49:06 +03002052 hdev->asic_funcs->rreg(hdev, (reg)))
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02002053
2054#define WREG32_P(reg, val, mask) \
2055 do { \
2056 u32 tmp_ = RREG32(reg); \
2057 tmp_ &= (mask); \
2058 tmp_ |= ((val) & ~(mask)); \
2059 WREG32(reg, tmp_); \
2060 } while (0)
2061#define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
2062#define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
2063
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002064#define RMWREG32(reg, val, mask) \
2065 do { \
2066 u32 tmp_ = RREG32(reg); \
2067 tmp_ &= ~(mask); \
2068 tmp_ |= ((val) << __ffs(mask)); \
2069 WREG32(reg, tmp_); \
2070 } while (0)
2071
2072#define RREG32_MASK(reg, mask) ((RREG32(reg) & mask) >> __ffs(mask))
2073
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02002074#define REG_FIELD_SHIFT(reg, field) reg##_##field##_SHIFT
2075#define REG_FIELD_MASK(reg, field) reg##_##field##_MASK
Oded Gabbay8fdacf22019-10-02 14:14:08 +03002076#define WREG32_FIELD(reg, offset, field, val) \
2077 WREG32(mm##reg + offset, (RREG32(mm##reg + offset) & \
2078 ~REG_FIELD_MASK(reg, field)) | \
2079 (val) << REG_FIELD_SHIFT(reg, field))
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02002080
Oded Gabbayed0fc502019-07-18 11:14:37 +03002081/* Timeout should be longer when working with simulator but cap the
2082 * increased timeout to some maximum
2083 */
Oded Gabbayb2377e02019-04-22 11:49:06 +03002084#define hl_poll_timeout(hdev, addr, val, cond, sleep_us, timeout_us) \
2085({ \
Dalit Ben Zoorb1b53772019-04-30 17:18:51 +03002086 ktime_t __timeout; \
Dalit Ben Zoorb1b53772019-04-30 17:18:51 +03002087 if (hdev->pdev) \
2088 __timeout = ktime_add_us(ktime_get(), timeout_us); \
2089 else \
Oded Gabbayed0fc502019-07-18 11:14:37 +03002090 __timeout = ktime_add_us(ktime_get(),\
2091 min((u64)(timeout_us * 10), \
2092 (u64) HL_SIM_MAX_TIMEOUT_US)); \
Oded Gabbayb2377e02019-04-22 11:49:06 +03002093 might_sleep_if(sleep_us); \
2094 for (;;) { \
2095 (val) = RREG32(addr); \
2096 if (cond) \
2097 break; \
2098 if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) { \
2099 (val) = RREG32(addr); \
2100 break; \
2101 } \
2102 if (sleep_us) \
2103 usleep_range((sleep_us >> 2) + 1, sleep_us); \
2104 } \
2105 (cond) ? 0 : -ETIMEDOUT; \
2106})
2107
Oded Gabbaya08b51a2019-05-09 01:48:23 +03002108/*
2109 * address in this macro points always to a memory location in the
2110 * host's (server's) memory. That location is updated asynchronously
Ben Segal2aa4e412019-07-18 12:27:00 +00002111 * either by the direct access of the device or by another core.
2112 *
2113 * To work both in LE and BE architectures, we need to distinguish between the
2114 * two states (device or another core updates the memory location). Therefore,
2115 * if mem_written_by_device is true, the host memory being polled will be
2116 * updated directly by the device. If false, the host memory being polled will
2117 * be updated by host CPU. Required so host knows whether or not the memory
2118 * might need to be byte-swapped before returning value to caller.
Oded Gabbaya08b51a2019-05-09 01:48:23 +03002119 */
Ben Segal2aa4e412019-07-18 12:27:00 +00002120#define hl_poll_timeout_memory(hdev, addr, val, cond, sleep_us, timeout_us, \
2121 mem_written_by_device) \
Oded Gabbaya08b51a2019-05-09 01:48:23 +03002122({ \
2123 ktime_t __timeout; \
Oded Gabbaya08b51a2019-05-09 01:48:23 +03002124 if (hdev->pdev) \
2125 __timeout = ktime_add_us(ktime_get(), timeout_us); \
2126 else \
Oded Gabbayed0fc502019-07-18 11:14:37 +03002127 __timeout = ktime_add_us(ktime_get(),\
2128 min((u64)(timeout_us * 10), \
2129 (u64) HL_SIM_MAX_TIMEOUT_US)); \
Oded Gabbaya08b51a2019-05-09 01:48:23 +03002130 might_sleep_if(sleep_us); \
2131 for (;;) { \
2132 /* Verify we read updates done by other cores or by device */ \
2133 mb(); \
Arnd Bergmann82948e62020-10-26 17:08:06 +01002134 (val) = *((u32 *)(addr)); \
Ben Segal2aa4e412019-07-18 12:27:00 +00002135 if (mem_written_by_device) \
Oded Gabbay6dc66f72019-09-03 11:33:55 +03002136 (val) = le32_to_cpu(*(__le32 *) &(val)); \
Oded Gabbaya08b51a2019-05-09 01:48:23 +03002137 if (cond) \
2138 break; \
2139 if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) { \
Arnd Bergmann82948e62020-10-26 17:08:06 +01002140 (val) = *((u32 *)(addr)); \
Ben Segal2aa4e412019-07-18 12:27:00 +00002141 if (mem_written_by_device) \
Oded Gabbay6dc66f72019-09-03 11:33:55 +03002142 (val) = le32_to_cpu(*(__le32 *) &(val)); \
Oded Gabbaya08b51a2019-05-09 01:48:23 +03002143 break; \
2144 } \
2145 if (sleep_us) \
2146 usleep_range((sleep_us >> 2) + 1, sleep_us); \
2147 } \
2148 (cond) ? 0 : -ETIMEDOUT; \
2149})
2150
2151#define hl_poll_timeout_device_memory(hdev, addr, val, cond, sleep_us, \
2152 timeout_us) \
2153({ \
2154 ktime_t __timeout; \
Oded Gabbaya08b51a2019-05-09 01:48:23 +03002155 if (hdev->pdev) \
2156 __timeout = ktime_add_us(ktime_get(), timeout_us); \
2157 else \
Oded Gabbayed0fc502019-07-18 11:14:37 +03002158 __timeout = ktime_add_us(ktime_get(),\
2159 min((u64)(timeout_us * 10), \
2160 (u64) HL_SIM_MAX_TIMEOUT_US)); \
Oded Gabbaya08b51a2019-05-09 01:48:23 +03002161 might_sleep_if(sleep_us); \
2162 for (;;) { \
2163 (val) = readl(addr); \
2164 if (cond) \
2165 break; \
2166 if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) { \
2167 (val) = readl(addr); \
2168 break; \
2169 } \
2170 if (sleep_us) \
2171 usleep_range((sleep_us >> 2) + 1, sleep_us); \
2172 } \
2173 (cond) ? 0 : -ETIMEDOUT; \
2174})
Oded Gabbayb2377e02019-04-22 11:49:06 +03002175
Oded Gabbayd91389b2019-02-16 00:39:19 +02002176struct hwmon_chip_info;
2177
Oded Gabbayc4d66342019-02-16 00:39:11 +02002178/**
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02002179 * struct hl_device_reset_work - reset workqueue task wrapper.
Ofir Bittonadb51292020-10-08 10:27:42 +03002180 * @wq: work queue for device reset procedure.
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02002181 * @reset_work: reset work to be done.
2182 * @hdev: habanalabs device structure.
Oded Gabbay8d9aa982021-08-09 22:43:37 +03002183 * @fw_reset: whether f/w will do the reset without us sending them a message to do it.
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02002184 */
2185struct hl_device_reset_work {
Ofir Bittonadb51292020-10-08 10:27:42 +03002186 struct workqueue_struct *wq;
2187 struct delayed_work reset_work;
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02002188 struct hl_device *hdev;
Oded Gabbay8d9aa982021-08-09 22:43:37 +03002189 bool fw_reset;
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02002190};
2191
2192/**
Moti Haimovskiccf979e2020-10-05 17:59:29 +03002193 * struct hr_mmu_hop_addrs - used for holding per-device host-resident mmu hop
2194 * information.
2195 * @virt_addr: the virtual address of the hop.
2196 * @phys-addr: the physical address of the hop (used by the device-mmu).
2197 * @shadow_addr: The shadow of the hop used by the driver for walking the hops.
2198 */
2199struct hr_mmu_hop_addrs {
2200 u64 virt_addr;
2201 u64 phys_addr;
2202 u64 shadow_addr;
2203};
Moti Haimovskid83fe662020-08-12 13:33:44 +03002204
2205/**
Moti Haimovskiccf979e2020-10-05 17:59:29 +03002206 * struct hl_mmu_hr_pgt_priv - used for holding per-device mmu host-resident
2207 * page-table internal information.
Moti Haimovskid83fe662020-08-12 13:33:44 +03002208 * @mmu_pgt_pool: pool of page tables used by MMU for allocating hops.
2209 * @mmu_shadow_hop0: shadow array of hop0 tables.
2210 */
Moti Haimovskiccf979e2020-10-05 17:59:29 +03002211struct hl_mmu_hr_priv {
2212 struct gen_pool *mmu_pgt_pool;
2213 struct hr_mmu_hop_addrs *mmu_shadow_hop0;
2214};
2215
2216/**
2217 * struct hl_mmu_dr_pgt_priv - used for holding per-device mmu device-resident
2218 * page-table internal information.
2219 * @mmu_pgt_pool: pool of page tables used by MMU for allocating hops.
2220 * @mmu_shadow_hop0: shadow array of hop0 tables.
2221 */
2222struct hl_mmu_dr_priv {
Moti Haimovskid83fe662020-08-12 13:33:44 +03002223 struct gen_pool *mmu_pgt_pool;
2224 void *mmu_shadow_hop0;
2225};
2226
2227/**
Moti Haimovskiccf979e2020-10-05 17:59:29 +03002228 * struct hl_mmu_priv - used for holding per-device mmu internal information.
2229 * @dr: information on the device-resident MMU, when exists.
2230 * @hr: information on the host-resident MMU, when exists.
2231 */
2232struct hl_mmu_priv {
2233 struct hl_mmu_dr_priv dr;
2234 struct hl_mmu_hr_priv hr;
2235};
2236
2237/**
Moti Haimovski00e1b592020-10-27 10:55:42 +02002238 * struct hl_mmu_per_hop_info - A structure describing one TLB HOP and its entry
2239 * that was created in order to translate a virtual address to a
2240 * physical one.
2241 * @hop_addr: The address of the hop.
2242 * @hop_pte_addr: The address of the hop entry.
2243 * @hop_pte_val: The value in the hop entry.
2244 */
2245struct hl_mmu_per_hop_info {
2246 u64 hop_addr;
2247 u64 hop_pte_addr;
2248 u64 hop_pte_val;
2249};
2250
2251/**
2252 * struct hl_mmu_hop_info - A structure describing the TLB hops and their
2253 * hop-entries that were created in order to translate a virtual address to a
2254 * physical one.
Moti Haimovskib19dc672020-11-18 20:15:29 +02002255 * @scrambled_vaddr: The value of the virtual address after scrambling. This
2256 * address replaces the original virtual-address when mapped
2257 * in the MMU tables.
farah kassabri89473a12021-01-12 17:24:00 +02002258 * @unscrambled_paddr: The un-scrambled physical address.
Moti Haimovski00e1b592020-10-27 10:55:42 +02002259 * @hop_info: Array holding the per-hop information used for the translation.
2260 * @used_hops: The number of hops used for the translation.
farah kassabri89473a12021-01-12 17:24:00 +02002261 * @range_type: virtual address range type.
Moti Haimovski00e1b592020-10-27 10:55:42 +02002262 */
2263struct hl_mmu_hop_info {
Moti Haimovskib19dc672020-11-18 20:15:29 +02002264 u64 scrambled_vaddr;
farah kassabri89473a12021-01-12 17:24:00 +02002265 u64 unscrambled_paddr;
Moti Haimovski00e1b592020-10-27 10:55:42 +02002266 struct hl_mmu_per_hop_info hop_info[MMU_ARCH_5_HOPS];
2267 u32 used_hops;
farah kassabri89473a12021-01-12 17:24:00 +02002268 enum hl_va_range_type range_type;
Moti Haimovski00e1b592020-10-27 10:55:42 +02002269};
2270
2271/**
Moti Haimovskid83fe662020-08-12 13:33:44 +03002272 * struct hl_mmu_funcs - Device related MMU functions.
2273 * @init: initialize the MMU module.
2274 * @fini: release the MMU module.
2275 * @ctx_init: Initialize a context for using the MMU module.
2276 * @ctx_fini: disable a ctx from using the mmu module.
2277 * @map: maps a virtual address to physical address for a context.
2278 * @unmap: unmap a virtual address of a context.
2279 * @flush: flush all writes from all cores to reach device MMU.
2280 * @swap_out: marks all mapping of the given context as swapped out.
2281 * @swap_in: marks all mapping of the given context as swapped in.
Moti Haimovski00e1b592020-10-27 10:55:42 +02002282 * @get_tlb_info: returns the list of hops and hop-entries used that were
2283 * created in order to translate the giver virtual address to a
2284 * physical one.
Moti Haimovskid83fe662020-08-12 13:33:44 +03002285 */
2286struct hl_mmu_funcs {
2287 int (*init)(struct hl_device *hdev);
2288 void (*fini)(struct hl_device *hdev);
2289 int (*ctx_init)(struct hl_ctx *ctx);
2290 void (*ctx_fini)(struct hl_ctx *ctx);
2291 int (*map)(struct hl_ctx *ctx,
2292 u64 virt_addr, u64 phys_addr, u32 page_size,
2293 bool is_dram_addr);
2294 int (*unmap)(struct hl_ctx *ctx,
2295 u64 virt_addr, bool is_dram_addr);
2296 void (*flush)(struct hl_ctx *ctx);
2297 void (*swap_out)(struct hl_ctx *ctx);
2298 void (*swap_in)(struct hl_ctx *ctx);
Moti Haimovski00e1b592020-10-27 10:55:42 +02002299 int (*get_tlb_info)(struct hl_ctx *ctx,
2300 u64 virt_addr, struct hl_mmu_hop_info *hops);
Moti Haimovskid83fe662020-08-12 13:33:44 +03002301};
2302
Oded Gabbay75b3cb22019-08-28 17:32:04 +03002303/**
Ohad Sharabi215f0c12021-06-14 22:18:41 +03002304 * number of user contexts allowed to call wait_for_multi_cs ioctl in
2305 * parallel
2306 */
2307#define MULTI_CS_MAX_USER_CTX 2
2308
2309/**
2310 * struct multi_cs_completion - multi CS wait completion.
2311 * @completion: completion of any of the CS in the list
2312 * @lock: spinlock for the completion structure
2313 * @timestamp: timestamp for the multi-CS completion
Ohad Sharabi72d66252021-08-01 23:02:07 +03002314 * @stream_master_qid_map: bitmap of all stream masters on which the multi-CS
2315 * is waiting
Ohad Sharabi215f0c12021-06-14 22:18:41 +03002316 * @used: 1 if in use, otherwise 0
Ohad Sharabi215f0c12021-06-14 22:18:41 +03002317 */
2318struct multi_cs_completion {
2319 struct completion completion;
2320 spinlock_t lock;
2321 s64 timestamp;
Ohad Sharabi72d66252021-08-01 23:02:07 +03002322 u32 stream_master_qid_map;
Ohad Sharabi215f0c12021-06-14 22:18:41 +03002323 u8 used;
Ohad Sharabi215f0c12021-06-14 22:18:41 +03002324};
2325
2326/**
2327 * struct multi_cs_data - internal data for multi CS call
2328 * @ctx: pointer to the context structure
2329 * @fence_arr: array of fences of all CSs
2330 * @seq_arr: array of CS sequence numbers
2331 * @timeout_us: timeout in usec for waiting for CS to complete
2332 * @timestamp: timestamp of first completed CS
2333 * @wait_status: wait for CS status
2334 * @completion_bitmap: bitmap of completed CSs (1- completed, otherwise 0)
Ohad Sharabi72d66252021-08-01 23:02:07 +03002335 * @stream_master_qid_map: bitmap of all stream master QIDs on which the
2336 * multi-CS is waiting
Ohad Sharabi215f0c12021-06-14 22:18:41 +03002337 * @arr_len: fence_arr and seq_arr array length
Ohad Sharabi215f0c12021-06-14 22:18:41 +03002338 * @gone_cs: indication of gone CS (1- there was gone CS, otherwise 0)
2339 * @update_ts: update timestamp. 1- update the timestamp, otherwise 0.
2340 */
2341struct multi_cs_data {
2342 struct hl_ctx *ctx;
2343 struct hl_fence **fence_arr;
2344 u64 *seq_arr;
2345 s64 timeout_us;
2346 s64 timestamp;
2347 long wait_status;
2348 u32 completion_bitmap;
Ohad Sharabi72d66252021-08-01 23:02:07 +03002349 u32 stream_master_qid_map;
Ohad Sharabi215f0c12021-06-14 22:18:41 +03002350 u8 arr_len;
Ohad Sharabi215f0c12021-06-14 22:18:41 +03002351 u8 gone_cs;
2352 u8 update_ts;
2353};
2354
2355/**
Oded Gabbayc4d66342019-02-16 00:39:11 +02002356 * struct hl_device - habanalabs device structure.
2357 * @pdev: pointer to PCI device, can be NULL in case of simulator device.
Ofir Bittonf4cbfd22020-06-15 17:45:12 +03002358 * @pcie_bar_phys: array of available PCIe bars physical addresses.
2359 * (required only for PCI address match mode)
2360 * @pcie_bar: array of available PCIe bars virtual addresses.
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02002361 * @rmmio: configuration area address on SRAM.
Oded Gabbayc4d66342019-02-16 00:39:11 +02002362 * @cdev: related char device.
Oded Gabbay4d6a7752019-07-30 09:10:50 +03002363 * @cdev_ctrl: char device for control operations only (INFO IOCTL)
2364 * @dev: related kernel basic device structure.
2365 * @dev_ctrl: related kernel device structure for the control device
Oded Gabbayd91389b2019-02-16 00:39:19 +02002366 * @work_freq: delayed work to lower device frequency if possible.
Oded Gabbay6138bbe2020-09-04 20:18:16 +03002367 * @work_heartbeat: delayed work for CPU-CP is-alive check.
Ofir Bittonadb51292020-10-08 10:27:42 +03002368 * @device_reset_work: delayed work which performs hard reset
Oded Gabbay6138bbe2020-09-04 20:18:16 +03002369 * @asic_name: ASIC specific name.
Oded Gabbayc4d66342019-02-16 00:39:11 +02002370 * @asic_type: ASIC specific type.
Oded Gabbay9494a8d2019-02-16 00:39:17 +02002371 * @completion_queue: array of hl_cq.
Ofir Bittonab5f5c32021-01-12 18:37:19 +02002372 * @user_interrupt: array of hl_user_interrupt. upon the corresponding user
2373 * interrupt, driver will monitor the list of fences
2374 * registered to this interrupt.
2375 * @common_user_interrupt: common user interrupt for all user interrupts.
2376 * upon any user interrupt, driver will monitor the
2377 * list of fences registered to this common structure.
Ofir Bitton5574cb22020-07-05 13:35:51 +03002378 * @cq_wq: work queues of completion queues for executing work in process
2379 * context.
Oded Gabbay9494a8d2019-02-16 00:39:17 +02002380 * @eq_wq: work queue of event queue for executing work in process context.
Ofir Bitton8445dde2021-03-18 17:36:57 +02002381 * @sob_reset_wq: work queue for sob reset executions.
Oded Gabbay4c172bb2019-08-30 16:59:33 +03002382 * @kernel_ctx: Kernel driver context structure.
Oded Gabbay9494a8d2019-02-16 00:39:17 +02002383 * @kernel_queues: array of hl_hw_queue.
Tomer Tayar804a72272020-10-30 11:16:23 +02002384 * @cs_mirror_list: CS mirror list for TDR.
2385 * @cs_mirror_lock: protects cs_mirror_list.
Zvika Yehudai38e19d02021-06-15 14:12:20 +03002386 * @kernel_cb_mgr: command buffer manager for creating/destroying/handling CBs.
Oded Gabbay6138bbe2020-09-04 20:18:16 +03002387 * @event_queue: event queue for IRQ from CPU-CP.
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02002388 * @dma_pool: DMA pool for small allocations.
Oded Gabbay6138bbe2020-09-04 20:18:16 +03002389 * @cpu_accessible_dma_mem: Host <-> CPU-CP shared memory CPU address.
2390 * @cpu_accessible_dma_address: Host <-> CPU-CP shared memory DMA address.
2391 * @cpu_accessible_dma_pool: Host <-> CPU-CP shared memory pool.
Oded Gabbay0861e412019-02-16 00:39:14 +02002392 * @asid_bitmap: holds used/available ASIDs.
2393 * @asid_mutex: protects asid_bitmap.
Oded Gabbay6138bbe2020-09-04 20:18:16 +03002394 * @send_cpu_message_lock: enforces only one message in Host <-> CPU-CP queue.
Oded Gabbay19734972019-05-04 17:36:06 +03002395 * @debug_lock: protects critical section of setting debug mode for device
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02002396 * @asic_prop: ASIC specific immutable properties.
2397 * @asic_funcs: ASIC specific functions.
2398 * @asic_specific: ASIC specific information to use only from ASIC files.
Omer Shpigelman0feaf862019-02-16 00:39:22 +02002399 * @vm: virtual memory manager for MMU.
Oded Gabbayd91389b2019-02-16 00:39:19 +02002400 * @hwmon_dev: H/W monitor device.
2401 * @pm_mng_profile: current power management profile.
2402 * @hl_chip_info: ASIC's sensors information.
Ofir Bitton66a76402020-10-05 14:40:10 +03002403 * @device_status_description: device status description.
Oded Gabbayc2164772019-02-16 00:39:24 +02002404 * @hl_debugfs: device's debugfs manager.
Oded Gabbaybe5d9262019-02-16 00:39:15 +02002405 * @cb_pool: list of preallocated CBs.
2406 * @cb_pool_lock: protects the CB pool.
Ofir Bittona04b7cd2020-07-13 13:36:55 +03002407 * @internal_cb_pool_virt_addr: internal command buffer pool virtual address.
2408 * @internal_cb_pool_dma_addr: internal command buffer pool dma address.
2409 * @internal_cb_pool: internal command buffer memory pool.
2410 * @internal_cb_va_base: internal cb pool mmu virtual address base
Oded Gabbayeb7caf82019-07-30 11:56:09 +03002411 * @fpriv_list: list of file private data structures. Each structure is created
2412 * when a user opens the device
2413 * @fpriv_list_lock: protects the fpriv_list
Oded Gabbay86d53072019-07-30 11:49:36 +03002414 * @compute_ctx: current compute context executing.
Ofir Bittondb491e42020-06-18 09:51:16 +03002415 * @aggregated_cs_counters: aggregated cs counters among all contexts
Moti Haimovskid83fe662020-08-12 13:33:44 +03002416 * @mmu_priv: device-specific MMU data.
2417 * @mmu_func: device-related MMU functions.
Ohad Sharabia22f0ec2021-04-11 23:06:46 +03002418 * @fw_loader: FW loader manager.
Ohad Sharabic592c272021-04-21 13:03:21 +03002419 * @pci_mem_region: array of memory regions in the PCI
Yuri Nudelman938b7932021-06-06 10:28:51 +03002420 * @state_dump_specs: constants and dictionaries needed to dump system state.
Ohad Sharabi215f0c12021-06-14 22:18:41 +03002421 * @multi_cs_completion: array of multi-CS completion.
Omer Shpigelman0feaf862019-02-16 00:39:22 +02002422 * @dram_used_mem: current DRAM memory consumption.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02002423 * @timeout_jiffies: device CS timeout value.
Oded Gabbayd91389b2019-02-16 00:39:19 +02002424 * @max_power: the max power of the device, as configured by the sysadmin. This
Oded Gabbay4c172bb2019-08-30 16:59:33 +03002425 * value is saved so in case of hard-reset, the driver will restore
2426 * this value and update the F/W after the re-initialization
Oded Gabbaye38bfd32020-07-03 20:46:12 +03002427 * @clock_gating_mask: is clock gating enabled. bitmask that represents the
2428 * different engines. See debugfs-driver-habanalabs for
2429 * details.
Oded Gabbay27a9e352021-04-12 09:52:05 +03002430 * @boot_error_status_mask: contains a mask of the device boot error status.
2431 * Each bit represents a different error, according to
2432 * the defines in hl_boot_if.h. If the bit is cleared,
2433 * the error will be ignored by the driver during
2434 * device initialization. Mainly used to debug and
2435 * workaround firmware bugs
Tomer Tayardb1a8dd2021-06-15 10:55:43 +03002436 * @dram_pci_bar_start: start bus address of PCIe bar towards DRAM.
Yuri Nudelmane307b302021-05-24 11:25:21 +03002437 * @last_successful_open_jif: timestamp (jiffies) of the last successful
2438 * device open.
2439 * @last_open_session_duration_jif: duration (jiffies) of the last device open
2440 * session.
2441 * @open_counter: number of successful device open operations.
Oded Gabbaycbaa99e2019-03-03 15:13:15 +02002442 * @in_reset: is device in reset flow.
Oded Gabbay75b3cb22019-08-28 17:32:04 +03002443 * @curr_pll_profile: current PLL profile.
Oded Gabbay58361aa2020-08-08 23:34:47 +03002444 * @card_type: Various ASICs have several card types. This indicates the card
2445 * type of the current device.
Oded Gabbay4c172bb2019-08-30 16:59:33 +03002446 * @major: habanalabs kernel driver major.
Oded Gabbayd91389b2019-02-16 00:39:19 +02002447 * @high_pll: high PLL profile frequency.
Oded Gabbay4c172bb2019-08-30 16:59:33 +03002448 * @soft_reset_cnt: number of soft reset since the driver was loaded.
2449 * @hard_reset_cnt: number of hard reset since the driver was loaded.
Ofir Bitton0a068ad2020-07-21 10:49:51 +03002450 * @clk_throttling_reason: bitmask represents the current clk throttling reasons
Oded Gabbayc4d66342019-02-16 00:39:11 +02002451 * @id: device minor.
Oded Gabbay4d6a7752019-07-30 09:10:50 +03002452 * @id_control: minor of the control device
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002453 * @cpu_pci_msb_addr: 50-bit extension bits for the device CPU's 40-bit
2454 * addresses.
Oded Gabbayc4d66342019-02-16 00:39:11 +02002455 * @disabled: is device disabled.
Oded Gabbayd91389b2019-02-16 00:39:19 +02002456 * @late_init_done: is late init stage was done during initialization.
2457 * @hwmon_initialized: is H/W monitor sensors was initialized.
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02002458 * @hard_reset_pending: is there a hard reset work pending.
Oded Gabbay6138bbe2020-09-04 20:18:16 +03002459 * @heartbeat: is heartbeat sanity check towards CPU-CP enabled.
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02002460 * @reset_on_lockup: true if a reset should be done in case of stuck CS, false
2461 * otherwise.
Omer Shpigelman27ca384c2019-02-28 10:46:11 +02002462 * @dram_default_page_mapping: is DRAM default page mapping enabled.
farah kassabri03df1362020-05-06 11:17:38 +03002463 * @memory_scrub: true to perform device memory scrub in various locations,
2464 * such as context-switch, context close, page free, etc.
Omer Shpigelman64a7e292020-01-05 09:05:45 +00002465 * @pmmu_huge_range: is a different virtual addresses range used for PMMU with
2466 * huge pages.
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02002467 * @init_done: is the initialization of the device done.
Oded Gabbaya28ce422019-02-28 10:46:12 +02002468 * @device_cpu_disabled: is the device CPU disabled (due to timeouts)
Oded Gabbayd9973872019-03-07 18:03:23 +02002469 * @dma_mask: the dma mask that was set for this device
Oded Gabbayeb7caf82019-07-30 11:56:09 +03002470 * @in_debug: is device under debug. This, together with fpriv_list, enforces
Oded Gabbay19734972019-05-04 17:36:06 +03002471 * that only a single user is configuring the debug infrastructure.
Oded Gabbaycb056b92020-03-29 13:18:30 +03002472 * @power9_64bit_dma_enable: true to enable 64-bit DMA mask support. Relevant
2473 * only to POWER9 machines.
Tomer Tayarea451f82019-08-08 12:25:52 +00002474 * @cdev_sysfs_created: were char devices and sysfs nodes created.
Omer Shpigelman76cedc72020-03-22 21:12:51 +02002475 * @stop_on_err: true if engines should stop on error.
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +03002476 * @supports_sync_stream: is sync stream supported.
Ofir Bitton21e7a342020-05-14 18:25:47 +03002477 * @sync_stream_queue_idx: helper index for sync stream queues initialization.
Ofir Bitton5fe1c172020-09-10 10:10:55 +03002478 * @collective_mon_idx: helper index for collective initialization
Omer Shpigelman9e5e49c2020-05-10 14:10:15 +03002479 * @supports_coresight: is CoreSight supported.
Oded Gabbay66446822020-05-18 16:48:01 +03002480 * @supports_soft_reset: is soft reset supported.
Oded Gabbaya00f1f52021-09-30 11:36:07 +03002481 * @allow_inference_soft_reset: true if the ASIC supports soft reset that is
2482 * initiated by user or TDR. This is only true
2483 * in inference ASICs, as there is no real-world
2484 * use-case of doing soft-reset in training (due
2485 * to the fact that training runs on multiple
2486 * devices)
Tomer Tayaref6a0f62020-07-09 16:17:48 +03002487 * @supports_cb_mapping: is mapping a CB to the device's MMU supported.
Ofir Bitton66a76402020-10-05 14:40:10 +03002488 * @needs_reset: true if reset_on_lockup is false and device should be reset
2489 * due to lockup.
Ofir Bittonadb51292020-10-08 10:27:42 +03002490 * @process_kill_trial_cnt: number of trials reset thread tried killing
2491 * user processes
2492 * @device_fini_pending: true if device_fini was called and might be
2493 * waiting for the reset thread to finish
Ofir Bitton2795c882020-12-08 13:47:05 +02002494 * @supports_staged_submission: true if staged submissions are supported
Koby Elbaz3e0ca9f2021-05-04 20:10:47 +03002495 * @curr_reset_cause: saves an enumerated reset cause when a hard reset is
2496 * triggered, and cleared after it is shared with preboot.
Bharat Jauhari10cab812021-06-21 09:57:19 +03002497 * @prev_reset_trigger: saves the previous trigger which caused a reset, overidden
2498 * with a new value on next reset
2499 * @reset_trigger_repeated: set if device reset is triggered more than once with
2500 * same cause.
Yuri Nudelman4d041212021-06-13 09:22:20 +03002501 * @skip_reset_on_timeout: Skip device reset if CS has timed out, wait for it to
2502 * complete instead.
Koby Elbazb7a71fd2021-06-15 17:07:02 +03002503 * @device_cpu_is_halted: Flag to indicate whether the device CPU was already
2504 * halted. We can't halt it again because the COMMS
2505 * protocol will throw an error. Relevant only for
2506 * cases where Linux was not loaded to device CPU
Ohad Sharabi215f0c12021-06-14 22:18:41 +03002507 * @supports_wait_for_multi_cs: true if wait for multi CS is supported
Oded Gabbayc4d66342019-02-16 00:39:11 +02002508 */
2509struct hl_device {
2510 struct pci_dev *pdev;
Ofir Bittonf4cbfd22020-06-15 17:45:12 +03002511 u64 pcie_bar_phys[HL_PCI_NUM_BARS];
2512 void __iomem *pcie_bar[HL_PCI_NUM_BARS];
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02002513 void __iomem *rmmio;
Oded Gabbayc4d66342019-02-16 00:39:11 +02002514 struct cdev cdev;
Oded Gabbay4d6a7752019-07-30 09:10:50 +03002515 struct cdev cdev_ctrl;
Oded Gabbayc4d66342019-02-16 00:39:11 +02002516 struct device *dev;
Oded Gabbay4d6a7752019-07-30 09:10:50 +03002517 struct device *dev_ctrl;
Oded Gabbayd91389b2019-02-16 00:39:19 +02002518 struct delayed_work work_freq;
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02002519 struct delayed_work work_heartbeat;
Ofir Bittonadb51292020-10-08 10:27:42 +03002520 struct hl_device_reset_work device_reset_work;
Ofir Bitton66a76402020-10-05 14:40:10 +03002521 char asic_name[HL_STR_MAX];
2522 char status[HL_DEV_STS_MAX][HL_STR_MAX];
Oded Gabbayc4d66342019-02-16 00:39:11 +02002523 enum hl_asic_type asic_type;
Oded Gabbay9494a8d2019-02-16 00:39:17 +02002524 struct hl_cq *completion_queue;
Ofir Bitton2d44c6f2021-01-12 14:43:09 +02002525 struct hl_user_interrupt *user_interrupt;
Ofir Bittonab5f5c32021-01-12 18:37:19 +02002526 struct hl_user_interrupt common_user_interrupt;
Ofir Bitton5574cb22020-07-05 13:35:51 +03002527 struct workqueue_struct **cq_wq;
Oded Gabbay1251f232019-02-16 00:39:18 +02002528 struct workqueue_struct *eq_wq;
Ofir Bitton8445dde2021-03-18 17:36:57 +02002529 struct workqueue_struct *sob_reset_wq;
Oded Gabbay0861e412019-02-16 00:39:14 +02002530 struct hl_ctx *kernel_ctx;
Oded Gabbay9494a8d2019-02-16 00:39:17 +02002531 struct hl_hw_queue *kernel_queues;
Tomer Tayar804a72272020-10-30 11:16:23 +02002532 struct list_head cs_mirror_list;
2533 spinlock_t cs_mirror_lock;
Oded Gabbaybe5d9262019-02-16 00:39:15 +02002534 struct hl_cb_mgr kernel_cb_mgr;
Oded Gabbay1251f232019-02-16 00:39:18 +02002535 struct hl_eq event_queue;
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02002536 struct dma_pool *dma_pool;
2537 void *cpu_accessible_dma_mem;
2538 dma_addr_t cpu_accessible_dma_address;
2539 struct gen_pool *cpu_accessible_dma_pool;
Oded Gabbay0861e412019-02-16 00:39:14 +02002540 unsigned long *asid_bitmap;
2541 struct mutex asid_mutex;
Oded Gabbay9494a8d2019-02-16 00:39:17 +02002542 struct mutex send_cpu_message_lock;
Oded Gabbay19734972019-05-04 17:36:06 +03002543 struct mutex debug_lock;
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02002544 struct asic_fixed_properties asic_prop;
2545 const struct hl_asic_funcs *asic_funcs;
2546 void *asic_specific;
Omer Shpigelman0feaf862019-02-16 00:39:22 +02002547 struct hl_vm vm;
Oded Gabbayd91389b2019-02-16 00:39:19 +02002548 struct device *hwmon_dev;
2549 enum hl_pm_mng_profile pm_mng_profile;
2550 struct hwmon_chip_info *hl_chip_info;
Oded Gabbaybe5d9262019-02-16 00:39:15 +02002551
Oded Gabbayc2164772019-02-16 00:39:24 +02002552 struct hl_dbg_device_entry hl_debugfs;
2553
Oded Gabbaybe5d9262019-02-16 00:39:15 +02002554 struct list_head cb_pool;
2555 spinlock_t cb_pool_lock;
2556
Ofir Bittona04b7cd2020-07-13 13:36:55 +03002557 void *internal_cb_pool_virt_addr;
2558 dma_addr_t internal_cb_pool_dma_addr;
2559 struct gen_pool *internal_cb_pool;
2560 u64 internal_cb_va_base;
2561
Oded Gabbayeb7caf82019-07-30 11:56:09 +03002562 struct list_head fpriv_list;
2563 struct mutex fpriv_list_lock;
2564
Oded Gabbay86d53072019-07-30 11:49:36 +03002565 struct hl_ctx *compute_ctx;
Oded Gabbayd91389b2019-02-16 00:39:19 +02002566
Oded Gabbay23c15ae2020-09-30 14:25:55 +03002567 struct hl_cs_counters_atomic aggregated_cs_counters;
Ofir Bittondb491e42020-06-18 09:51:16 +03002568
Moti Haimovskid83fe662020-08-12 13:33:44 +03002569 struct hl_mmu_priv mmu_priv;
Moti Haimovskiccf979e2020-10-05 17:59:29 +03002570 struct hl_mmu_funcs mmu_func[MMU_NUM_PGT_LOCATIONS];
Moti Haimovskid83fe662020-08-12 13:33:44 +03002571
Ohad Sharabia22f0ec2021-04-11 23:06:46 +03002572 struct fw_load_mgr fw_loader;
2573
Ohad Sharabic592c272021-04-21 13:03:21 +03002574 struct pci_mem_region pci_mem_region[PCI_REGION_NUMBER];
2575
Yuri Nudelman938b7932021-06-06 10:28:51 +03002576 struct hl_state_dump_specs state_dump_specs;
2577
Ohad Sharabi215f0c12021-06-14 22:18:41 +03002578 struct multi_cs_completion multi_cs_completion[
2579 MULTI_CS_MAX_USER_CTX];
Ohad Sharabi72d66252021-08-01 23:02:07 +03002580 u32 *stream_master_qid_arr;
Omer Shpigelman0feaf862019-02-16 00:39:22 +02002581 atomic64_t dram_used_mem;
Oded Gabbaycbaa99e2019-03-03 15:13:15 +02002582 u64 timeout_jiffies;
2583 u64 max_power;
Oded Gabbaye38bfd32020-07-03 20:46:12 +03002584 u64 clock_gating_mask;
Oded Gabbay27a9e352021-04-12 09:52:05 +03002585 u64 boot_error_status_mask;
Tomer Tayardb1a8dd2021-06-15 10:55:43 +03002586 u64 dram_pci_bar_start;
Yuri Nudelmane307b302021-05-24 11:25:21 +03002587 u64 last_successful_open_jif;
2588 u64 last_open_session_duration_jif;
2589 u64 open_counter;
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02002590 atomic_t in_reset;
Oded Gabbayeb7caf82019-07-30 11:56:09 +03002591 enum hl_pll_frequency curr_pll_profile;
Oded Gabbay2f553422020-08-15 16:28:10 +03002592 enum cpucp_card_types card_type;
Oded Gabbayc4d66342019-02-16 00:39:11 +02002593 u32 major;
Oded Gabbayd91389b2019-02-16 00:39:19 +02002594 u32 high_pll;
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02002595 u32 soft_reset_cnt;
2596 u32 hard_reset_cnt;
Ofir Bitton0a068ad2020-07-21 10:49:51 +03002597 u32 clk_throttling_reason;
Oded Gabbayc4d66342019-02-16 00:39:11 +02002598 u16 id;
Oded Gabbay4d6a7752019-07-30 09:10:50 +03002599 u16 id_control;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002600 u16 cpu_pci_msb_addr;
Oded Gabbayc4d66342019-02-16 00:39:11 +02002601 u8 disabled;
Oded Gabbayd91389b2019-02-16 00:39:19 +02002602 u8 late_init_done;
2603 u8 hwmon_initialized;
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02002604 u8 hard_reset_pending;
2605 u8 heartbeat;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02002606 u8 reset_on_lockup;
Omer Shpigelman27ca384c2019-02-28 10:46:11 +02002607 u8 dram_default_page_mapping;
farah kassabri03df1362020-05-06 11:17:38 +03002608 u8 memory_scrub;
Omer Shpigelman64a7e292020-01-05 09:05:45 +00002609 u8 pmmu_huge_range;
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02002610 u8 init_done;
Oded Gabbaya28ce422019-02-28 10:46:12 +02002611 u8 device_cpu_disabled;
Oded Gabbayd9973872019-03-07 18:03:23 +02002612 u8 dma_mask;
Oded Gabbay19734972019-05-04 17:36:06 +03002613 u8 in_debug;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002614 u8 power9_64bit_dma_enable;
Tomer Tayarea451f82019-08-08 12:25:52 +00002615 u8 cdev_sysfs_created;
Omer Shpigelman76cedc72020-03-22 21:12:51 +02002616 u8 stop_on_err;
Omer Shpigelmanf9e5f292020-05-07 13:41:16 +03002617 u8 supports_sync_stream;
Ofir Bitton21e7a342020-05-14 18:25:47 +03002618 u8 sync_stream_queue_idx;
Ofir Bitton5fe1c172020-09-10 10:10:55 +03002619 u8 collective_mon_idx;
Omer Shpigelman9e5e49c2020-05-10 14:10:15 +03002620 u8 supports_coresight;
Oded Gabbay66446822020-05-18 16:48:01 +03002621 u8 supports_soft_reset;
Oded Gabbaya00f1f52021-09-30 11:36:07 +03002622 u8 allow_inference_soft_reset;
Tomer Tayaref6a0f62020-07-09 16:17:48 +03002623 u8 supports_cb_mapping;
Ofir Bitton66a76402020-10-05 14:40:10 +03002624 u8 needs_reset;
Ofir Bittonadb51292020-10-08 10:27:42 +03002625 u8 process_kill_trial_cnt;
2626 u8 device_fini_pending;
Ofir Bitton2795c882020-12-08 13:47:05 +02002627 u8 supports_staged_submission;
Koby Elbaz3e0ca9f2021-05-04 20:10:47 +03002628 u8 curr_reset_cause;
Bharat Jauhari10cab812021-06-21 09:57:19 +03002629 u8 prev_reset_trigger;
2630 u8 reset_trigger_repeated;
Yuri Nudelman4d041212021-06-13 09:22:20 +03002631 u8 skip_reset_on_timeout;
Koby Elbazb7a71fd2021-06-15 17:07:02 +03002632 u8 device_cpu_is_halted;
Ohad Sharabi215f0c12021-06-14 22:18:41 +03002633 u8 supports_wait_for_multi_cs;
Ohad Sharabi72d66252021-08-01 23:02:07 +03002634 u8 stream_master_qid_arr_size;
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02002635
2636 /* Parameters for bring-up */
Oded Gabbay3c681572020-11-02 21:10:39 +02002637 u64 nic_ports_mask;
Ofir Bitton6a2f5d72021-02-15 13:23:04 +02002638 u64 fw_components;
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02002639 u8 mmu_enable;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002640 u8 mmu_huge_page_opt;
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02002641 u8 reset_pcilink;
Oded Gabbay9494a8d2019-02-16 00:39:17 +02002642 u8 cpu_queues_enable;
Oded Gabbay839c4802019-02-16 00:39:16 +02002643 u8 pldm;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002644 u8 axi_drain;
2645 u8 sram_scrambler_enable;
2646 u8 dram_scrambler_enable;
2647 u8 hard_reset_on_fw_events;
2648 u8 bmc_enable;
2649 u8 rl_enable;
Ofir Bittond1ddd902020-10-19 17:04:20 +03002650 u8 reset_on_preboot_fail;
Oded Gabbayd3ee6812021-02-16 22:49:27 +02002651 u8 reset_upon_device_release;
Ofir Bitton84586de2021-05-20 13:30:31 +03002652 u8 reset_if_device_not_idle;
Oded Gabbayc4d66342019-02-16 00:39:11 +02002653};
2654
2655
farah kassabridadf17a2021-05-24 18:09:22 +03002656/**
2657 * struct hl_cs_encaps_sig_handle - encapsulated signals handle structure
2658 * @refcount: refcount used to protect removing this id when several
2659 * wait cs are used to wait of the reserved encaps signals.
2660 * @hdev: pointer to habanalabs device structure.
2661 * @hw_sob: pointer to H/W SOB used in the reservation.
2662 * @cs_seq: staged cs sequence which contains encapsulated signals
2663 * @id: idr handler id to be used to fetch the handler info
2664 * @q_idx: stream queue index
2665 * @pre_sob_val: current SOB value before reservation
2666 * @count: signals number
2667 */
2668struct hl_cs_encaps_sig_handle {
2669 struct kref refcount;
2670 struct hl_device *hdev;
2671 struct hl_hw_sob *hw_sob;
2672 u64 cs_seq;
2673 u32 id;
2674 u32 q_idx;
2675 u32 pre_sob_val;
2676 u32 count;
2677};
2678
Oded Gabbayc4d66342019-02-16 00:39:11 +02002679/*
2680 * IOCTLs
2681 */
2682
2683/**
2684 * typedef hl_ioctl_t - typedef for ioctl function in the driver
2685 * @hpriv: pointer to the FD's private data, which contains state of
2686 * user process
2687 * @data: pointer to the input/output arguments structure of the IOCTL
2688 *
2689 * Return: 0 for success, negative value for error
2690 */
2691typedef int hl_ioctl_t(struct hl_fpriv *hpriv, void *data);
2692
2693/**
2694 * struct hl_ioctl_desc - describes an IOCTL entry of the driver.
2695 * @cmd: the IOCTL code as created by the kernel macros.
2696 * @func: pointer to the driver's function that should be called for this IOCTL.
2697 */
2698struct hl_ioctl_desc {
2699 unsigned int cmd;
2700 hl_ioctl_t *func;
2701};
2702
2703
2704/*
2705 * Kernel module functions that can be accessed by entire module
2706 */
2707
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02002708/**
Yuri Nudelman89b21362021-07-29 11:44:28 +03002709 * hl_get_sg_info() - get number of pages and the DMA address from SG list.
2710 * @sg: the SG list.
2711 * @dma_addr: pointer to DMA address to return.
2712 *
2713 * Calculate the number of consecutive pages described by the SG list. Take the
2714 * offset of the address in the first page, add to it the length and round it up
2715 * to the number of needed pages.
2716 */
2717static inline u32 hl_get_sg_info(struct scatterlist *sg, dma_addr_t *dma_addr)
2718{
2719 *dma_addr = sg_dma_address(sg);
2720
2721 return ((((*dma_addr) & (PAGE_SIZE - 1)) + sg_dma_len(sg)) +
2722 (PAGE_SIZE - 1)) >> PAGE_SHIFT;
2723}
2724
2725/**
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02002726 * hl_mem_area_inside_range() - Checks whether address+size are inside a range.
2727 * @address: The start address of the area we want to validate.
2728 * @size: The size in bytes of the area we want to validate.
2729 * @range_start_address: The start address of the valid range.
2730 * @range_end_address: The end address of the valid range.
2731 *
2732 * Return: true if the area is inside the valid range, false otherwise.
2733 */
Ofir Bitton36545272020-08-06 11:33:27 +03002734static inline bool hl_mem_area_inside_range(u64 address, u64 size,
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02002735 u64 range_start_address, u64 range_end_address)
2736{
2737 u64 end_address = address + size;
2738
2739 if ((address >= range_start_address) &&
2740 (end_address <= range_end_address) &&
2741 (end_address > address))
2742 return true;
2743
2744 return false;
2745}
2746
2747/**
2748 * hl_mem_area_crosses_range() - Checks whether address+size crossing a range.
2749 * @address: The start address of the area we want to validate.
2750 * @size: The size in bytes of the area we want to validate.
2751 * @range_start_address: The start address of the valid range.
2752 * @range_end_address: The end address of the valid range.
2753 *
2754 * Return: true if the area overlaps part or all of the valid range,
2755 * false otherwise.
2756 */
2757static inline bool hl_mem_area_crosses_range(u64 address, u32 size,
2758 u64 range_start_address, u64 range_end_address)
2759{
2760 u64 end_address = address + size;
2761
2762 if ((address >= range_start_address) &&
2763 (address < range_end_address))
2764 return true;
2765
2766 if ((end_address >= range_start_address) &&
2767 (end_address < range_end_address))
2768 return true;
2769
2770 if ((address < range_start_address) &&
2771 (end_address >= range_end_address))
2772 return true;
2773
2774 return false;
2775}
2776
Oded Gabbayc4d66342019-02-16 00:39:11 +02002777int hl_device_open(struct inode *inode, struct file *filp);
Oded Gabbay4d6a7752019-07-30 09:10:50 +03002778int hl_device_open_ctrl(struct inode *inode, struct file *filp);
Ofir Bitton66a76402020-10-05 14:40:10 +03002779bool hl_device_operational(struct hl_device *hdev,
2780 enum hl_device_status *status);
Dalit Ben Zooraa957082019-03-24 10:15:44 +02002781enum hl_device_status hl_device_status(struct hl_device *hdev);
Oded Gabbay19734972019-05-04 17:36:06 +03002782int hl_device_set_debug_mode(struct hl_device *hdev, bool enable);
Oded Gabbayc4d66342019-02-16 00:39:11 +02002783int create_hdev(struct hl_device **dev, struct pci_dev *pdev,
2784 enum hl_asic_type asic_type, int minor);
2785void destroy_hdev(struct hl_device *hdev);
Oded Gabbay9494a8d2019-02-16 00:39:17 +02002786int hl_hw_queues_create(struct hl_device *hdev);
2787void hl_hw_queues_destroy(struct hl_device *hdev);
2788int hl_hw_queue_send_cb_no_cmpl(struct hl_device *hdev, u32 hw_queue_id,
Koby Elbaz8bb8b502021-07-06 20:50:33 +03002789 u32 cb_size, u64 cb_ptr);
2790void hl_hw_queue_submit_bd(struct hl_device *hdev, struct hl_hw_queue *q,
2791 u32 ctl, u32 len, u64 ptr);
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02002792int hl_hw_queue_schedule_cs(struct hl_cs *cs);
Oded Gabbay9494a8d2019-02-16 00:39:17 +02002793u32 hl_hw_queue_add_ptr(u32 ptr, u16 val);
2794void hl_hw_queue_inc_ci_kernel(struct hl_device *hdev, u32 hw_queue_id);
Ofir Bitton0811b392020-12-06 17:18:02 +02002795void hl_hw_queue_update_ci(struct hl_cs *cs);
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02002796void hl_hw_queue_reset(struct hl_device *hdev, bool hard_reset);
Oded Gabbayc4d66342019-02-16 00:39:11 +02002797
Oded Gabbay9494a8d2019-02-16 00:39:17 +02002798#define hl_queue_inc_ptr(p) hl_hw_queue_add_ptr(p, 1)
2799#define hl_pi_2_offset(pi) ((pi) & (HL_QUEUE_LENGTH - 1))
2800
2801int hl_cq_init(struct hl_device *hdev, struct hl_cq *q, u32 hw_queue_id);
2802void hl_cq_fini(struct hl_device *hdev, struct hl_cq *q);
Oded Gabbay1251f232019-02-16 00:39:18 +02002803int hl_eq_init(struct hl_device *hdev, struct hl_eq *q);
2804void hl_eq_fini(struct hl_device *hdev, struct hl_eq *q);
Oded Gabbayf8c8c7d52019-02-16 00:39:20 +02002805void hl_cq_reset(struct hl_device *hdev, struct hl_cq *q);
2806void hl_eq_reset(struct hl_device *hdev, struct hl_eq *q);
Oded Gabbay1251f232019-02-16 00:39:18 +02002807irqreturn_t hl_irq_handler_cq(int irq, void *arg);
2808irqreturn_t hl_irq_handler_eq(int irq, void *arg);
Ofir Bitton2d44c6f2021-01-12 14:43:09 +02002809irqreturn_t hl_irq_handler_user_cq(int irq, void *arg);
2810irqreturn_t hl_irq_handler_default(int irq, void *arg);
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02002811u32 hl_cq_inc_ptr(u32 ptr);
2812
Oded Gabbay0861e412019-02-16 00:39:14 +02002813int hl_asid_init(struct hl_device *hdev);
2814void hl_asid_fini(struct hl_device *hdev);
2815unsigned long hl_asid_alloc(struct hl_device *hdev);
2816void hl_asid_free(struct hl_device *hdev, unsigned long asid);
2817
2818int hl_ctx_create(struct hl_device *hdev, struct hl_fpriv *hpriv);
2819void hl_ctx_free(struct hl_device *hdev, struct hl_ctx *ctx);
2820int hl_ctx_init(struct hl_device *hdev, struct hl_ctx *ctx, bool is_kernel_ctx);
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02002821void hl_ctx_do_release(struct kref *ref);
2822void hl_ctx_get(struct hl_device *hdev, struct hl_ctx *ctx);
Oded Gabbay0861e412019-02-16 00:39:14 +02002823int hl_ctx_put(struct hl_ctx *ctx);
Ofir Bittona98d73c2020-07-15 08:52:39 +03002824struct hl_fence *hl_ctx_get_fence(struct hl_ctx *ctx, u64 seq);
Ohad Sharabic457d5a2021-06-20 11:00:26 +03002825int hl_ctx_get_fences(struct hl_ctx *ctx, u64 *seq_arr,
2826 struct hl_fence **fence, u32 arr_len);
Oded Gabbay0861e412019-02-16 00:39:14 +02002827void hl_ctx_mgr_init(struct hl_ctx_mgr *mgr);
2828void hl_ctx_mgr_fini(struct hl_device *hdev, struct hl_ctx_mgr *mgr);
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02002829
Oded Gabbayc4d66342019-02-16 00:39:11 +02002830int hl_device_init(struct hl_device *hdev, struct class *hclass);
2831void hl_device_fini(struct hl_device *hdev);
2832int hl_device_suspend(struct hl_device *hdev);
2833int hl_device_resume(struct hl_device *hdev);
Ohad Sharabie42a6400f2021-02-17 20:42:48 +02002834int hl_device_reset(struct hl_device *hdev, u32 flags);
Oded Gabbay0861e412019-02-16 00:39:14 +02002835void hl_hpriv_get(struct hl_fpriv *hpriv);
Oded Gabbay278b5f72021-02-18 10:24:02 +02002836int hl_hpriv_put(struct hl_fpriv *hpriv);
Oded Gabbayd91389b2019-02-16 00:39:19 +02002837int hl_device_set_frequency(struct hl_device *hdev, enum hl_pll_frequency freq);
Koby Elbazcd5def82021-02-23 21:31:27 +02002838int hl_device_utilization(struct hl_device *hdev, u32 *utilization);
Omer Shpigelman0feaf862019-02-16 00:39:22 +02002839
Oded Gabbayd91389b2019-02-16 00:39:19 +02002840int hl_build_hwmon_channel_info(struct hl_device *hdev,
Oded Gabbay2f553422020-08-15 16:28:10 +03002841 struct cpucp_sensor *sensors_arr);
Oded Gabbayd91389b2019-02-16 00:39:19 +02002842
2843int hl_sysfs_init(struct hl_device *hdev);
2844void hl_sysfs_fini(struct hl_device *hdev);
2845
2846int hl_hwmon_init(struct hl_device *hdev);
2847void hl_hwmon_fini(struct hl_device *hdev);
Oded Gabbayc4d66342019-02-16 00:39:11 +02002848
Tomer Tayarfa8641a12020-09-07 17:36:41 +03002849int hl_cb_create(struct hl_device *hdev, struct hl_cb_mgr *mgr,
2850 struct hl_ctx *ctx, u32 cb_size, bool internal_cb,
Tomer Tayaref6a0f62020-07-09 16:17:48 +03002851 bool map_cb, u64 *handle);
Oded Gabbaybe5d9262019-02-16 00:39:15 +02002852int hl_cb_destroy(struct hl_device *hdev, struct hl_cb_mgr *mgr, u64 cb_handle);
2853int hl_cb_mmap(struct hl_fpriv *hpriv, struct vm_area_struct *vma);
Ofir Bittond00697f2021-01-05 12:55:06 +02002854int hl_hw_block_mmap(struct hl_fpriv *hpriv, struct vm_area_struct *vma);
Oded Gabbaybe5d9262019-02-16 00:39:15 +02002855struct hl_cb *hl_cb_get(struct hl_device *hdev, struct hl_cb_mgr *mgr,
2856 u32 handle);
2857void hl_cb_put(struct hl_cb *cb);
2858void hl_cb_mgr_init(struct hl_cb_mgr *mgr);
2859void hl_cb_mgr_fini(struct hl_device *hdev, struct hl_cb_mgr *mgr);
Ofir Bittona04b7cd2020-07-13 13:36:55 +03002860struct hl_cb *hl_cb_kernel_create(struct hl_device *hdev, u32 cb_size,
2861 bool internal_cb);
Oded Gabbaybe5d9262019-02-16 00:39:15 +02002862int hl_cb_pool_init(struct hl_device *hdev);
2863int hl_cb_pool_fini(struct hl_device *hdev);
Tomer Tayaref6a0f62020-07-09 16:17:48 +03002864int hl_cb_va_pool_init(struct hl_ctx *ctx);
2865void hl_cb_va_pool_fini(struct hl_ctx *ctx);
Oded Gabbaybe5d9262019-02-16 00:39:15 +02002866
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02002867void hl_cs_rollback_all(struct hl_device *hdev);
Tomer Tayarcb596ae2019-10-03 15:22:36 +00002868struct hl_cs_job *hl_cs_allocate_job(struct hl_device *hdev,
2869 enum hl_queue_type queue_type, bool is_kernel_allocated_cb);
Omer Shpigelmanb0b5d922020-05-07 13:57:36 +03002870void hl_sob_reset_error(struct kref *ref);
Ofir Bitton2992c1d2020-09-10 09:40:35 +03002871int hl_gen_sob_mask(u16 sob_base, u8 sob_mask, u8 *mask);
Ofir Bittona98d73c2020-07-15 08:52:39 +03002872void hl_fence_put(struct hl_fence *fence);
Ohad Sharabic457d5a2021-06-20 11:00:26 +03002873void hl_fences_put(struct hl_fence **fence, int len);
Ofir Bittona98d73c2020-07-15 08:52:39 +03002874void hl_fence_get(struct hl_fence *fence);
Ofir Bitton5de406c2020-09-10 10:56:26 +03002875void cs_get(struct hl_cs *cs);
Ofir Bitton0811b392020-12-06 17:18:02 +02002876bool cs_needs_completion(struct hl_cs *cs);
2877bool cs_needs_timeout(struct hl_cs *cs);
Ofir Bitton2795c882020-12-08 13:47:05 +02002878bool is_staged_cs_last_exists(struct hl_device *hdev, struct hl_cs *cs);
2879struct hl_cs *hl_staged_cs_find_first(struct hl_device *hdev, u64 cs_seq);
Ohad Sharabi215f0c12021-06-14 22:18:41 +03002880void hl_multi_cs_completion_init(struct hl_device *hdev);
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02002881
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02002882void goya_set_asic_funcs(struct hl_device *hdev);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002883void gaudi_set_asic_funcs(struct hl_device *hdev);
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02002884
Omer Shpigelman0feaf862019-02-16 00:39:22 +02002885int hl_vm_ctx_init(struct hl_ctx *ctx);
2886void hl_vm_ctx_fini(struct hl_ctx *ctx);
2887
2888int hl_vm_init(struct hl_device *hdev);
2889void hl_vm_fini(struct hl_device *hdev);
2890
Sagiv Ozeria4371c12021-02-23 11:01:08 +02002891void hl_hw_block_mem_init(struct hl_ctx *ctx);
2892void hl_hw_block_mem_fini(struct hl_ctx *ctx);
2893
Ofir Bittonbe91b912020-10-22 15:04:10 +03002894u64 hl_reserve_va_block(struct hl_device *hdev, struct hl_ctx *ctx,
Ofir Bitton412c41f2020-11-04 15:18:55 +02002895 enum hl_va_range_type type, u32 size, u32 alignment);
Ofir Bittonbe91b912020-10-22 15:04:10 +03002896int hl_unreserve_va_block(struct hl_device *hdev, struct hl_ctx *ctx,
2897 u64 start_addr, u64 size);
Oded Gabbay230afe72019-02-27 00:19:18 +02002898int hl_pin_host_memory(struct hl_device *hdev, u64 addr, u64 size,
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02002899 struct hl_userptr *userptr);
Omer Shpigelman7f74d4d2019-08-12 11:48:46 +03002900void hl_unpin_host_memory(struct hl_device *hdev, struct hl_userptr *userptr);
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02002901void hl_userptr_delete_list(struct hl_device *hdev,
2902 struct list_head *userptr_list);
2903bool hl_userptr_is_pinned(struct hl_device *hdev, u64 addr, u32 size,
2904 struct list_head *userptr_list,
2905 struct hl_userptr **userptr);
2906
Omer Shpigelman0feaf862019-02-16 00:39:22 +02002907int hl_mmu_init(struct hl_device *hdev);
2908void hl_mmu_fini(struct hl_device *hdev);
Omer Shpigelman27ca384c2019-02-28 10:46:11 +02002909int hl_mmu_ctx_init(struct hl_ctx *ctx);
Omer Shpigelman0feaf862019-02-16 00:39:22 +02002910void hl_mmu_ctx_fini(struct hl_ctx *ctx);
Ofir Bitton5c054872020-10-22 15:13:10 +03002911int hl_mmu_map_page(struct hl_ctx *ctx, u64 virt_addr, u64 phys_addr,
Pawel Piskorski7fc40bc2019-12-06 17:32:38 +02002912 u32 page_size, bool flush_pte);
Ofir Bitton5c054872020-10-22 15:13:10 +03002913int hl_mmu_unmap_page(struct hl_ctx *ctx, u64 virt_addr, u32 page_size,
Pawel Piskorski7fc40bc2019-12-06 17:32:38 +02002914 bool flush_pte);
Ofir Bitton5c054872020-10-22 15:13:10 +03002915int hl_mmu_map_contiguous(struct hl_ctx *ctx, u64 virt_addr,
2916 u64 phys_addr, u32 size);
2917int hl_mmu_unmap_contiguous(struct hl_ctx *ctx, u64 virt_addr, u32 size);
Omer Shpigelman0feaf862019-02-16 00:39:22 +02002918void hl_mmu_swap_out(struct hl_ctx *ctx);
2919void hl_mmu_swap_in(struct hl_ctx *ctx);
Moti Haimovskid83fe662020-08-12 13:33:44 +03002920int hl_mmu_if_set_funcs(struct hl_device *hdev);
Moti Haimovskiccf979e2020-10-05 17:59:29 +03002921void hl_mmu_v1_set_funcs(struct hl_device *hdev, struct hl_mmu_funcs *mmu);
Moti Haimovski00e1b592020-10-27 10:55:42 +02002922int hl_mmu_va_to_pa(struct hl_ctx *ctx, u64 virt_addr, u64 *phys_addr);
2923int hl_mmu_get_tlb_info(struct hl_ctx *ctx, u64 virt_addr,
2924 struct hl_mmu_hop_info *hops);
farah kassabri89473a12021-01-12 17:24:00 +02002925u64 hl_mmu_scramble_addr(struct hl_device *hdev, u64 addr);
2926u64 hl_mmu_descramble_addr(struct hl_device *hdev, u64 addr);
Oded Gabbay94883072021-01-11 17:49:30 +02002927bool hl_is_dram_va(struct hl_device *hdev, u64 virt_addr);
Omer Shpigelman0feaf862019-02-16 00:39:22 +02002928
Oded Gabbay7e1c07d2020-03-26 12:32:56 +02002929int hl_fw_load_fw_to_device(struct hl_device *hdev, const char *fw_name,
Ofir Bitton9bb86b62020-10-20 10:45:37 +03002930 void __iomem *dst, u32 src_offset, u32 size);
Tomer Tayar3110c602019-03-04 10:22:09 +02002931int hl_fw_send_pci_access_msg(struct hl_device *hdev, u32 opcode);
2932int hl_fw_send_cpu_message(struct hl_device *hdev, u32 hw_queue_id, u32 *msg,
Alon Mizrahi439bc472020-11-10 13:49:10 +02002933 u16 len, u32 timeout, u64 *result);
Ofir Bittonebd8d122020-05-10 13:41:28 +03002934int hl_fw_unmask_irq(struct hl_device *hdev, u16 event_type);
2935int hl_fw_unmask_irq_arr(struct hl_device *hdev, const u32 *irq_arr,
2936 size_t irq_arr_size);
Tomer Tayar3110c602019-03-04 10:22:09 +02002937int hl_fw_test_cpu_queue(struct hl_device *hdev);
2938void *hl_fw_cpu_accessible_dma_pool_alloc(struct hl_device *hdev, size_t size,
2939 dma_addr_t *dma_handle);
2940void hl_fw_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size,
2941 void *vaddr);
2942int hl_fw_send_heartbeat(struct hl_device *hdev);
Alon Mizrahi41478642020-11-17 14:25:14 +02002943int hl_fw_cpucp_info_get(struct hl_device *hdev,
Ohad Sharabie67a60402021-05-02 15:45:21 +03002944 u32 sts_boot_dev_sts0_reg,
2945 u32 sts_boot_dev_sts1_reg, u32 boot_err0_reg,
2946 u32 boot_err1_reg);
Ohad Sharabie9c20032021-03-22 14:30:52 +02002947int hl_fw_cpucp_handshake(struct hl_device *hdev,
Ohad Sharabie67a60402021-05-02 15:45:21 +03002948 u32 sts_boot_dev_sts0_reg,
2949 u32 sts_boot_dev_sts1_reg, u32 boot_err0_reg,
2950 u32 boot_err1_reg);
Tomer Tayar3110c602019-03-04 10:22:09 +02002951int hl_fw_get_eeprom_data(struct hl_device *hdev, void *data, size_t max_size);
Oded Gabbay2f553422020-08-15 16:28:10 +03002952int hl_fw_cpucp_pci_counters_get(struct hl_device *hdev,
Ofir Bitton0a068ad2020-07-21 10:49:51 +03002953 struct hl_info_pci_counters *counters);
Oded Gabbay2f553422020-08-15 16:28:10 +03002954int hl_fw_cpucp_total_energy_get(struct hl_device *hdev,
farah kassabri9f306492020-08-09 16:25:53 +03002955 u64 *total_energy);
Bharat Jauhari285c0fa2021-03-25 18:15:40 +02002956int get_used_pll_index(struct hl_device *hdev, u32 input_pll_index,
Ohad Sharabie8f93922021-03-15 20:49:28 +02002957 enum pll_index *pll_index);
Bharat Jauhari285c0fa2021-03-25 18:15:40 +02002958int hl_fw_cpucp_pll_info_get(struct hl_device *hdev, u32 pll_index,
Alon Mizrahi41478642020-11-17 14:25:14 +02002959 u16 *pll_freq_arr);
Sagiv Ozeri586f2ca2021-02-23 18:00:05 +02002960int hl_fw_cpucp_power_get(struct hl_device *hdev, u64 *power);
Koby Elbazb7a71fd2021-06-15 17:07:02 +03002961void hl_fw_ask_hard_reset_without_linux(struct hl_device *hdev);
2962void hl_fw_ask_halt_machine_without_linux(struct hl_device *hdev);
Ohad Sharabia22f0ec2021-04-11 23:06:46 +03002963int hl_fw_init_cpu(struct hl_device *hdev);
Ofir Bitton323b7262020-10-04 09:09:19 +03002964int hl_fw_read_preboot_status(struct hl_device *hdev, u32 cpu_boot_status_reg,
Ohad Sharabie67a60402021-05-02 15:45:21 +03002965 u32 sts_boot_dev_sts0_reg,
2966 u32 sts_boot_dev_sts1_reg, u32 boot_err0_reg,
2967 u32 boot_err1_reg, u32 timeout);
Koby Elbaz40803082021-05-20 12:45:58 +03002968int hl_fw_dynamic_send_protocol_cmd(struct hl_device *hdev,
2969 struct fw_load_mgr *fw_loader,
2970 enum comms_cmd cmd, unsigned int size,
2971 bool wait_ok, u32 timeout);
Tomer Tayarb6f897d2019-03-05 16:48:42 +02002972int hl_pci_bars_map(struct hl_device *hdev, const char * const name[3],
2973 bool is_wc[3]);
Ofir Bitton41f458f2021-03-10 15:08:44 +02002974int hl_pci_elbi_read(struct hl_device *hdev, u64 addr, u32 *data);
Tomer Tayarb6f897d2019-03-05 16:48:42 +02002975int hl_pci_iatu_write(struct hl_device *hdev, u32 addr, u32 data);
Ofir Bittonf4cbfd22020-06-15 17:45:12 +03002976int hl_pci_set_inbound_region(struct hl_device *hdev, u8 region,
2977 struct hl_inbound_pci_region *pci_region);
2978int hl_pci_set_outbound_region(struct hl_device *hdev,
2979 struct hl_outbound_pci_region *pci_region);
Ohad Sharabic592c272021-04-21 13:03:21 +03002980enum pci_region hl_get_pci_memory_region(struct hl_device *hdev, u64 addr);
Ofir Bittond1ddd902020-10-19 17:04:20 +03002981int hl_pci_init(struct hl_device *hdev);
Tomer Tayarb6f897d2019-03-05 16:48:42 +02002982void hl_pci_fini(struct hl_device *hdev);
2983
Bharat Jauhari285c0fa2021-03-25 18:15:40 +02002984long hl_get_frequency(struct hl_device *hdev, u32 pll_index,
Ohad Sharabie8f93922021-03-15 20:49:28 +02002985 bool curr);
Bharat Jauhari285c0fa2021-03-25 18:15:40 +02002986void hl_set_frequency(struct hl_device *hdev, u32 pll_index,
Ohad Sharabie8f93922021-03-15 20:49:28 +02002987 u64 freq);
Moti Haimovskid57b83c2020-01-23 18:03:04 +02002988int hl_get_temperature(struct hl_device *hdev,
2989 int sensor_index, u32 attr, long *value);
Moti Haimovski5557b132020-01-21 15:02:06 +02002990int hl_set_temperature(struct hl_device *hdev,
Moti Haimovskid57b83c2020-01-23 18:03:04 +02002991 int sensor_index, u32 attr, long value);
2992int hl_get_voltage(struct hl_device *hdev,
2993 int sensor_index, u32 attr, long *value);
2994int hl_get_current(struct hl_device *hdev,
2995 int sensor_index, u32 attr, long *value);
2996int hl_get_fan_speed(struct hl_device *hdev,
2997 int sensor_index, u32 attr, long *value);
2998int hl_get_pwm_info(struct hl_device *hdev,
2999 int sensor_index, u32 attr, long *value);
Oded Gabbayd91389b2019-02-16 00:39:19 +02003000void hl_set_pwm_info(struct hl_device *hdev, int sensor_index, u32 attr,
3001 long value);
3002u64 hl_get_max_power(struct hl_device *hdev);
Oded Gabbay58361aa2020-08-08 23:34:47 +03003003void hl_set_max_power(struct hl_device *hdev);
Christine Gharzuzi8e708af2020-04-16 16:43:26 +03003004int hl_set_voltage(struct hl_device *hdev,
3005 int sensor_index, u32 attr, long value);
3006int hl_set_current(struct hl_device *hdev,
3007 int sensor_index, u32 attr, long value);
Rajaravi Krishna Katta2b284852021-08-18 08:12:41 +03003008int hl_set_power(struct hl_device *hdev,
3009 int sensor_index, u32 attr, long value);
3010int hl_get_power(struct hl_device *hdev,
3011 int sensor_index, u32 attr, long *value);
Rajaravi Krishna Katta024b7b12021-09-03 08:01:30 +03003012int hl_get_clk_rate(struct hl_device *hdev,
3013 u32 *cur_clk, u32 *max_clk);
3014void hl_set_pll_profile(struct hl_device *hdev, enum hl_pll_frequency freq);
3015void hl_add_device_attr(struct hl_device *hdev,
3016 struct attribute_group *dev_attr_grp);
farah kassabridadf17a2021-05-24 18:09:22 +03003017void hw_sob_get(struct hl_hw_sob *hw_sob);
3018void hw_sob_put(struct hl_hw_sob *hw_sob);
farah kassabrie4cdccd2021-05-26 10:43:36 +03003019void hl_encaps_handle_do_release(struct kref *ref);
3020void hl_hw_queue_encaps_sig_set_sob_info(struct hl_device *hdev,
3021 struct hl_cs *cs, struct hl_cs_job *job,
3022 struct hl_cs_compl *cs_cmpl);
Ofir Bittonab5f5c32021-01-12 18:37:19 +02003023void hl_release_pending_user_interrupts(struct hl_device *hdev);
farah kassabri3817b352021-06-01 16:44:28 +03003024int hl_cs_signal_sob_wraparound_handler(struct hl_device *hdev, u32 q_idx,
farah kassabridadf17a2021-05-24 18:09:22 +03003025 struct hl_hw_sob **hw_sob, u32 count, bool encaps_sig);
Oded Gabbayd91389b2019-02-16 00:39:19 +02003026
Yuri Nudelman938b7932021-06-06 10:28:51 +03003027int hl_state_dump(struct hl_device *hdev);
3028const char *hl_state_dump_get_sync_name(struct hl_device *hdev, u32 sync_id);
Yuri Nudelmanfd2010b2021-06-09 14:04:26 +03003029const char *hl_state_dump_get_monitor_name(struct hl_device *hdev,
3030 struct hl_mon_state_dump *mon);
Yuri Nudelman938b7932021-06-06 10:28:51 +03003031void hl_state_dump_free_sync_to_engine_map(struct hl_sync_to_engine_map *map);
3032__printf(4, 5) int hl_snprintf_resize(char **buf, size_t *size, size_t *offset,
3033 const char *format, ...);
3034char *hl_format_as_binary(char *buf, size_t buf_len, u32 n);
3035const char *hl_sync_engine_to_string(enum hl_sync_engine_type engine_type);
3036
Oded Gabbayc2164772019-02-16 00:39:24 +02003037#ifdef CONFIG_DEBUG_FS
3038
3039void hl_debugfs_init(void);
3040void hl_debugfs_fini(void);
3041void hl_debugfs_add_device(struct hl_device *hdev);
3042void hl_debugfs_remove_device(struct hl_device *hdev);
3043void hl_debugfs_add_file(struct hl_fpriv *hpriv);
3044void hl_debugfs_remove_file(struct hl_fpriv *hpriv);
3045void hl_debugfs_add_cb(struct hl_cb *cb);
3046void hl_debugfs_remove_cb(struct hl_cb *cb);
3047void hl_debugfs_add_cs(struct hl_cs *cs);
3048void hl_debugfs_remove_cs(struct hl_cs *cs);
3049void hl_debugfs_add_job(struct hl_device *hdev, struct hl_cs_job *job);
3050void hl_debugfs_remove_job(struct hl_device *hdev, struct hl_cs_job *job);
3051void hl_debugfs_add_userptr(struct hl_device *hdev, struct hl_userptr *userptr);
3052void hl_debugfs_remove_userptr(struct hl_device *hdev,
3053 struct hl_userptr *userptr);
3054void hl_debugfs_add_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx);
3055void hl_debugfs_remove_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx);
Yuri Nudelman938b7932021-06-06 10:28:51 +03003056void hl_debugfs_set_state_dump(struct hl_device *hdev, char *data,
3057 unsigned long length);
Oded Gabbayc2164772019-02-16 00:39:24 +02003058
3059#else
3060
3061static inline void __init hl_debugfs_init(void)
3062{
3063}
3064
3065static inline void hl_debugfs_fini(void)
3066{
3067}
3068
3069static inline void hl_debugfs_add_device(struct hl_device *hdev)
3070{
3071}
3072
3073static inline void hl_debugfs_remove_device(struct hl_device *hdev)
3074{
3075}
3076
3077static inline void hl_debugfs_add_file(struct hl_fpriv *hpriv)
3078{
3079}
3080
3081static inline void hl_debugfs_remove_file(struct hl_fpriv *hpriv)
3082{
3083}
3084
3085static inline void hl_debugfs_add_cb(struct hl_cb *cb)
3086{
3087}
3088
3089static inline void hl_debugfs_remove_cb(struct hl_cb *cb)
3090{
3091}
3092
3093static inline void hl_debugfs_add_cs(struct hl_cs *cs)
3094{
3095}
3096
3097static inline void hl_debugfs_remove_cs(struct hl_cs *cs)
3098{
3099}
3100
3101static inline void hl_debugfs_add_job(struct hl_device *hdev,
3102 struct hl_cs_job *job)
3103{
3104}
3105
3106static inline void hl_debugfs_remove_job(struct hl_device *hdev,
3107 struct hl_cs_job *job)
3108{
3109}
3110
3111static inline void hl_debugfs_add_userptr(struct hl_device *hdev,
3112 struct hl_userptr *userptr)
3113{
3114}
3115
3116static inline void hl_debugfs_remove_userptr(struct hl_device *hdev,
3117 struct hl_userptr *userptr)
3118{
3119}
3120
3121static inline void hl_debugfs_add_ctx_mem_hash(struct hl_device *hdev,
3122 struct hl_ctx *ctx)
3123{
3124}
3125
3126static inline void hl_debugfs_remove_ctx_mem_hash(struct hl_device *hdev,
3127 struct hl_ctx *ctx)
3128{
3129}
3130
Yuri Nudelmanfd2010b2021-06-09 14:04:26 +03003131static inline void hl_debugfs_set_state_dump(struct hl_device *hdev,
3132 char *data, unsigned long length)
Yuri Nudelman938b7932021-06-06 10:28:51 +03003133{
3134}
3135
Oded Gabbayc2164772019-02-16 00:39:24 +02003136#endif
3137
Oded Gabbaybe5d9262019-02-16 00:39:15 +02003138/* IOCTLs */
3139long hl_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
Oded Gabbay4d6a7752019-07-30 09:10:50 +03003140long hl_ioctl_control(struct file *filep, unsigned int cmd, unsigned long arg);
Oded Gabbaybe5d9262019-02-16 00:39:15 +02003141int hl_cb_ioctl(struct hl_fpriv *hpriv, void *data);
Oded Gabbayeff6f4a2019-02-16 00:39:21 +02003142int hl_cs_ioctl(struct hl_fpriv *hpriv, void *data);
Ofir Bittonab5f5c32021-01-12 18:37:19 +02003143int hl_wait_ioctl(struct hl_fpriv *hpriv, void *data);
Omer Shpigelman0feaf862019-02-16 00:39:22 +02003144int hl_mem_ioctl(struct hl_fpriv *hpriv, void *data);
Oded Gabbaybe5d9262019-02-16 00:39:15 +02003145
Oded Gabbayc4d66342019-02-16 00:39:11 +02003146#endif /* HABANALABSP_H_ */