Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 1 | /* 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 Gabbay | 2f55342 | 2020-08-15 16:28:10 +0300 | [diff] [blame] | 11 | #include "../include/common/cpucp_if.h" |
Greg Kroah-Hartman | 7b16a15 | 2020-07-28 19:18:51 +0200 | [diff] [blame] | 12 | #include "../include/common/qman_if.h" |
Moti Haimovski | 00e1b59 | 2020-10-27 10:55:42 +0200 | [diff] [blame] | 13 | #include "../include/hw_ip/mmu/mmu_general.h" |
Ofir Bitton | db491e4 | 2020-06-18 09:51:16 +0300 | [diff] [blame] | 14 | #include <uapi/misc/habanalabs.h> |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 15 | |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 16 | #include <linux/cdev.h> |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 17 | #include <linux/iopoll.h> |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 18 | #include <linux/irqreturn.h> |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 19 | #include <linux/dma-direction.h> |
| 20 | #include <linux/scatterlist.h> |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 21 | #include <linux/hashtable.h> |
Oded Gabbay | 639781d | 2021-04-02 01:43:18 +0300 | [diff] [blame] | 22 | #include <linux/debugfs.h> |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 23 | #include <linux/rwsem.h> |
Tomer Tayar | 5600470 | 2020-08-18 15:06:56 +0300 | [diff] [blame] | 24 | #include <linux/bitfield.h> |
Tomer Tayar | ba7e389 | 2020-10-25 17:47:22 +0200 | [diff] [blame] | 25 | #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 Tayar | db1a8dd | 2021-06-15 10:55:43 +0300 | [diff] [blame] | 29 | #include <linux/dma-buf.h> |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 30 | |
| 31 | #define HL_NAME "habanalabs" |
| 32 | |
Oded Gabbay | 3174ac9 | 2020-08-29 11:51:39 +0300 | [diff] [blame] | 33 | /* Use upper bits of mmap offset to store habana driver specific information. |
Ofir Bitton | d00697f | 2021-01-05 12:55:06 +0200 | [diff] [blame] | 34 | * bits[63:61] - Encode mmap type |
Oded Gabbay | 3174ac9 | 2020-08-29 11:51:39 +0300 | [diff] [blame] | 35 | * 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 Bitton | d00697f | 2021-01-05 12:55:06 +0200 | [diff] [blame] | 40 | #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 Gabbay | 3174ac9 | 2020-08-29 11:51:39 +0300 | [diff] [blame] | 43 | #define HL_MMAP_TYPE_CB (0x2ull << HL_MMAP_TYPE_SHIFT) |
| 44 | |
Ofir Bitton | d00697f | 2021-01-05 12:55:06 +0200 | [diff] [blame] | 45 | #define HL_MMAP_OFFSET_VALUE_MASK (0x1FFFFFFFFFFFull >> PAGE_SHIFT) |
Oded Gabbay | 3174ac9 | 2020-08-29 11:51:39 +0300 | [diff] [blame] | 46 | #define HL_MMAP_OFFSET_VALUE_GET(off) (off & HL_MMAP_OFFSET_VALUE_MASK) |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 47 | |
Ofir Bitton | adb5129 | 2020-10-08 10:27:42 +0300 | [diff] [blame] | 48 | #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 Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 51 | |
Omer Shpigelman | e09498b | 2020-05-09 12:18:01 +0300 | [diff] [blame] | 52 | #define HL_HARD_RESET_MAX_TIMEOUT 120 |
Omer Shpigelman | 4efb6b2 | 2021-06-09 10:17:49 +0300 | [diff] [blame] | 53 | #define HL_PLDM_HARD_RESET_MAX_TIMEOUT (HL_HARD_RESET_MAX_TIMEOUT * 3) |
Omer Shpigelman | e09498b | 2020-05-09 12:18:01 +0300 | [diff] [blame] | 54 | |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 55 | #define HL_DEVICE_TIMEOUT_USEC 1000000 /* 1 s */ |
| 56 | |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 57 | #define HL_HEARTBEAT_PER_USEC 5000000 /* 5 s */ |
| 58 | |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 59 | #define HL_PLL_LOW_JOB_FREQ_USEC 5000000 /* 5 s */ |
| 60 | |
Oded Gabbay | 2f55342 | 2020-08-15 16:28:10 +0300 | [diff] [blame] | 61 | #define HL_CPUCP_INFO_TIMEOUT_USEC 10000000 /* 10s */ |
| 62 | #define HL_CPUCP_EEPROM_TIMEOUT_USEC 10000000 /* 10s */ |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 63 | |
Omer Shpigelman | a1e537b | 2019-05-13 14:44:50 +0300 | [diff] [blame] | 64 | #define HL_PCI_ELBI_TIMEOUT_MSEC 10 /* 10ms */ |
| 65 | |
Oded Gabbay | ed0fc50 | 2019-07-18 11:14:37 +0300 | [diff] [blame] | 66 | #define HL_SIM_MAX_TIMEOUT_US 10000000 /* 10s */ |
| 67 | |
Ofir Bitton | ab5f5c3 | 2021-01-12 18:37:19 +0200 | [diff] [blame] | 68 | #define HL_COMMON_USER_INTERRUPT_ID 0xFFF |
| 69 | |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 70 | #define HL_STATE_DUMP_HIST_LEN 5 |
| 71 | |
Bharat Jauhari | 10cab81 | 2021-06-21 09:57:19 +0300 | [diff] [blame] | 72 | /* Default value for device reset trigger , an invalid value */ |
| 73 | #define HL_RESET_TRIGGER_DEFAULT 0xFF |
| 74 | |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 75 | #define OBJ_NAMES_HASH_TABLE_BITS 7 /* 1 << 7 buckets */ |
| 76 | #define SYNC_TO_ENGINE_HASH_TABLE_BITS 7 /* 1 << 7 buckets */ |
| 77 | |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 78 | /* 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 Haimovski | ccf979e | 2020-10-05 17:59:29 +0300 | [diff] [blame] | 84 | /** |
| 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 | */ |
| 90 | enum 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 Bitton | 21e7a34 | 2020-05-14 18:25:47 +0300 | [diff] [blame] | 96 | /* |
| 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 Bitton | 5de406c | 2020-09-10 10:56:26 +0300 | [diff] [blame] | 100 | #define HL_RSVD_SOBS 2 |
| 101 | #define HL_RSVD_MONS 1 |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 102 | |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 103 | /* |
| 104 | * HL_COLLECTIVE_RSVD_MSTR_MONS 'collective' reserved monitors per QMAN stream |
| 105 | */ |
| 106 | #define HL_COLLECTIVE_RSVD_MSTR_MONS 2 |
| 107 | |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 108 | #define HL_MAX_SOB_VAL (1 << 15) |
| 109 | |
Ofir Bitton | c16d45f | 2020-06-02 12:28:27 +0300 | [diff] [blame] | 110 | #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 Bitton | f4cbfd2 | 2020-06-15 17:45:12 +0300 | [diff] [blame] | 113 | #define HL_PCI_NUM_BARS 6 |
| 114 | |
Ofir Bitton | 843839b | 2020-07-19 11:08:09 +0300 | [diff] [blame] | 115 | #define HL_MAX_DCORES 4 |
| 116 | |
Ohad Sharabi | e42a6400f | 2021-02-17 20:42:48 +0200 | [diff] [blame] | 117 | /* |
| 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 Elbaz | 3e0ca9f | 2021-05-04 20:10:47 +0300 | [diff] [blame] | 129 | * |
| 130 | * - HL_RESET_TDR |
| 131 | * Set if reset is due to TDR |
Ofir Bitton | 23bace6 | 2021-06-08 17:24:52 +0300 | [diff] [blame] | 132 | * |
| 133 | * - HL_RESET_DEVICE_RELEASE |
| 134 | * Set if reset is due to device release |
Oded Gabbay | 8d9aa98 | 2021-08-09 22:43:37 +0300 | [diff] [blame] | 135 | * |
| 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 Jauhari | 10cab81 | 2021-06-21 09:57:19 +0300 | [diff] [blame] | 139 | * |
| 140 | * - HL_RESET_FW_FATAL_ERR |
| 141 | * Set if reset is due to a fatal error from FW |
Ohad Sharabi | e42a6400f | 2021-02-17 20:42:48 +0200 | [diff] [blame] | 142 | */ |
Bharat Jauhari | 10cab81 | 2021-06-21 09:57:19 +0300 | [diff] [blame] | 143 | |
Ohad Sharabi | e42a6400f | 2021-02-17 20:42:48 +0200 | [diff] [blame] | 144 | #define HL_RESET_HARD (1 << 0) |
| 145 | #define HL_RESET_FROM_RESET_THREAD (1 << 1) |
| 146 | #define HL_RESET_HEARTBEAT (1 << 2) |
Koby Elbaz | 3e0ca9f | 2021-05-04 20:10:47 +0300 | [diff] [blame] | 147 | #define HL_RESET_TDR (1 << 3) |
Ofir Bitton | 23bace6 | 2021-06-08 17:24:52 +0300 | [diff] [blame] | 148 | #define HL_RESET_DEVICE_RELEASE (1 << 4) |
Oded Gabbay | 8d9aa98 | 2021-08-09 22:43:37 +0300 | [diff] [blame] | 149 | #define HL_RESET_FW (1 << 5) |
Bharat Jauhari | 10cab81 | 2021-06-21 09:57:19 +0300 | [diff] [blame] | 150 | #define HL_RESET_FW_FATAL_ERR (1 << 6) |
Ohad Sharabi | e42a6400f | 2021-02-17 20:42:48 +0200 | [diff] [blame] | 151 | |
Ofir Bitton | 2992c1d | 2020-09-10 09:40:35 +0300 | [diff] [blame] | 152 | #define HL_MAX_SOBS_PER_MONITOR 8 |
| 153 | |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 154 | /** |
Ofir Bitton | 3cf74b3 | 2020-09-10 09:17:50 +0300 | [diff] [blame] | 155 | * 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 Bitton | 2992c1d | 2020-09-10 09:40:35 +0300 | [diff] [blame] | 158 | * @size: offset in command buffer |
| 159 | * @sob_base: SOB base to use in this wait CB |
Ofir Bitton | 3cf74b3 | 2020-09-10 09:17:50 +0300 | [diff] [blame] | 160 | * @sob_val: SOB value to wait for |
| 161 | * @mon_id: monitor to use in this wait CB |
Ofir Bitton | 2992c1d | 2020-09-10 09:40:35 +0300 | [diff] [blame] | 162 | * @sob_mask: each bit represents a SOB offset from sob_base to be used |
Ofir Bitton | 3cf74b3 | 2020-09-10 09:17:50 +0300 | [diff] [blame] | 163 | */ |
| 164 | struct hl_gen_wait_properties { |
| 165 | void *data; |
| 166 | u32 q_idx; |
Ofir Bitton | 2992c1d | 2020-09-10 09:40:35 +0300 | [diff] [blame] | 167 | u32 size; |
| 168 | u16 sob_base; |
Ofir Bitton | 3cf74b3 | 2020-09-10 09:17:50 +0300 | [diff] [blame] | 169 | u16 sob_val; |
| 170 | u16 mon_id; |
Ofir Bitton | 2992c1d | 2020-09-10 09:40:35 +0300 | [diff] [blame] | 171 | u8 sob_mask; |
Ofir Bitton | 3cf74b3 | 2020-09-10 09:17:50 +0300 | [diff] [blame] | 172 | }; |
| 173 | |
| 174 | /** |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 175 | * struct pgt_info - MMU hop page info. |
Omer Shpigelman | 66542c3 | 2019-02-24 09:17:55 +0200 | [diff] [blame] | 176 | * @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 Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 179 | * @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 | */ |
| 187 | struct pgt_info { |
Omer Shpigelman | 66542c3 | 2019-02-24 09:17:55 +0200 | [diff] [blame] | 188 | struct hlist_node node; |
| 189 | u64 phys_addr; |
| 190 | u64 shadow_addr; |
| 191 | struct hl_ctx *ctx; |
| 192 | int num_of_ptes; |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 193 | }; |
| 194 | |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 195 | struct hl_device; |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 196 | struct hl_fpriv; |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 197 | |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 198 | /** |
Ofir Bitton | f4cbfd2 | 2020-06-15 17:45:12 +0300 | [diff] [blame] | 199 | * 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 | */ |
| 203 | enum hl_pci_match_mode { |
| 204 | PCI_ADDRESS_MATCH_MODE, |
| 205 | PCI_BAR_MATCH_MODE |
| 206 | }; |
| 207 | |
| 208 | /** |
Oded Gabbay | 7e1c07d | 2020-03-26 12:32:56 +0200 | [diff] [blame] | 209 | * enum hl_fw_component - F/W components to read version through registers. |
Ohad Sharabi | 50f036d | 2021-04-11 15:26:28 +0300 | [diff] [blame] | 210 | * @FW_COMP_BOOT_FIT: boot fit. |
Oded Gabbay | 7e1c07d | 2020-03-26 12:32:56 +0200 | [diff] [blame] | 211 | * @FW_COMP_PREBOOT: preboot. |
Ohad Sharabi | b31e59b | 2021-04-22 10:01:22 +0300 | [diff] [blame] | 212 | * @FW_COMP_LINUX: linux. |
Oded Gabbay | 7e1c07d | 2020-03-26 12:32:56 +0200 | [diff] [blame] | 213 | */ |
| 214 | enum hl_fw_component { |
Ohad Sharabi | 50f036d | 2021-04-11 15:26:28 +0300 | [diff] [blame] | 215 | FW_COMP_BOOT_FIT, |
Ohad Sharabi | b31e59b | 2021-04-22 10:01:22 +0300 | [diff] [blame] | 216 | FW_COMP_PREBOOT, |
| 217 | FW_COMP_LINUX, |
Oded Gabbay | 7e1c07d | 2020-03-26 12:32:56 +0200 | [diff] [blame] | 218 | }; |
| 219 | |
| 220 | /** |
Ofir Bitton | 6a2f5d7 | 2021-02-15 13:23:04 +0200 | [diff] [blame] | 221 | * enum hl_fw_types - F/W types present in the system |
Oded Gabbay | 596553d | 2020-10-01 13:46:37 +0300 | [diff] [blame] | 222 | * @FW_TYPE_LINUX: Linux image for device CPU |
| 223 | * @FW_TYPE_BOOT_CPU: Boot image for device CPU |
Ofir Bitton | 6a2f5d7 | 2021-02-15 13:23:04 +0200 | [diff] [blame] | 224 | * @FW_TYPE_PREBOOT_CPU: Indicates pre-loaded CPUs are present in the system |
| 225 | * (preboot, ppboot etc...) |
Oded Gabbay | 596553d | 2020-10-01 13:46:37 +0300 | [diff] [blame] | 226 | * @FW_TYPE_ALL_TYPES: Mask for all types |
| 227 | */ |
| 228 | enum hl_fw_types { |
| 229 | FW_TYPE_LINUX = 0x1, |
| 230 | FW_TYPE_BOOT_CPU = 0x2, |
Ofir Bitton | 6a2f5d7 | 2021-02-15 13:23:04 +0200 | [diff] [blame] | 231 | FW_TYPE_PREBOOT_CPU = 0x4, |
| 232 | FW_TYPE_ALL_TYPES = |
| 233 | (FW_TYPE_LINUX | FW_TYPE_BOOT_CPU | FW_TYPE_PREBOOT_CPU) |
Oded Gabbay | 596553d | 2020-10-01 13:46:37 +0300 | [diff] [blame] | 234 | }; |
| 235 | |
| 236 | /** |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 237 | * 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 Tayar | cb596ae | 2019-10-03 15:22:36 +0000 | [diff] [blame] | 244 | * @QUEUE_TYPE_HW: queue of DMA and compute engines jobs, for which completion |
| 245 | * notifications are sent by H/W. |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 246 | */ |
| 247 | enum hl_queue_type { |
| 248 | QUEUE_TYPE_NA, |
| 249 | QUEUE_TYPE_EXT, |
| 250 | QUEUE_TYPE_INT, |
Tomer Tayar | cb596ae | 2019-10-03 15:22:36 +0000 | [diff] [blame] | 251 | QUEUE_TYPE_CPU, |
| 252 | QUEUE_TYPE_HW |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 253 | }; |
| 254 | |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 255 | enum hl_cs_type { |
| 256 | CS_TYPE_DEFAULT, |
| 257 | CS_TYPE_SIGNAL, |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 258 | CS_TYPE_WAIT, |
farah kassabri | dadf17a | 2021-05-24 18:09:22 +0300 | [diff] [blame] | 259 | CS_TYPE_COLLECTIVE_WAIT, |
| 260 | CS_RESERVE_SIGNALS, |
| 261 | CS_UNRESERVE_SIGNALS |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 262 | }; |
| 263 | |
| 264 | /* |
Ofir Bitton | f4cbfd2 | 2020-06-15 17:45:12 +0300 | [diff] [blame] | 265 | * 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 | */ |
| 272 | struct 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 | */ |
| 285 | struct hl_outbound_pci_region { |
| 286 | u64 addr; |
| 287 | u64 size; |
| 288 | }; |
| 289 | |
| 290 | /* |
Tal Cohen | 4bb1f2f | 2020-06-03 09:25:27 +0300 | [diff] [blame] | 291 | * 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 | */ |
| 296 | enum queue_cb_alloc_flags { |
| 297 | CB_ALLOC_KERNEL = 0x1, |
| 298 | CB_ALLOC_USER = 0x2 |
| 299 | }; |
| 300 | |
| 301 | /* |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 302 | * 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 kassabri | dadf17a | 2021-05-24 18:09:22 +0300 | [diff] [blame] | 306 | * @sob_addr: the sob offset from the base address. |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 307 | * @q_idx: the H/W queue that uses this SOB. |
farah kassabri | dadf17a | 2021-05-24 18:09:22 +0300 | [diff] [blame] | 308 | * @need_reset: reset indication set when switching to the other sob. |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 309 | */ |
| 310 | struct hl_hw_sob { |
| 311 | struct hl_device *hdev; |
| 312 | struct kref kref; |
| 313 | u32 sob_id; |
farah kassabri | dadf17a | 2021-05-24 18:09:22 +0300 | [diff] [blame] | 314 | u32 sob_addr; |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 315 | u32 q_idx; |
farah kassabri | dadf17a | 2021-05-24 18:09:22 +0300 | [diff] [blame] | 316 | bool need_reset; |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 317 | }; |
| 318 | |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 319 | enum hl_collective_mode { |
| 320 | HL_COLLECTIVE_NOT_SUPPORTED = 0x0, |
| 321 | HL_COLLECTIVE_MASTER = 0x1, |
| 322 | HL_COLLECTIVE_SLAVE = 0x2 |
| 323 | }; |
| 324 | |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 325 | /** |
| 326 | * struct hw_queue_properties - queue information. |
| 327 | * @type: queue type. |
Tal Cohen | 4bb1f2f | 2020-06-03 09:25:27 +0300 | [diff] [blame] | 328 | * @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 Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 332 | * @collective_mode: collective mode of current queue |
Oded Gabbay | 4c172bb | 2019-08-30 16:59:33 +0300 | [diff] [blame] | 333 | * @driver_only: true if only the driver is allowed to send a job to this queue, |
| 334 | * false otherwise. |
Ofir Bitton | 21e7a34 | 2020-05-14 18:25:47 +0300 | [diff] [blame] | 335 | * @supports_sync_stream: True if queue supports sync stream |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 336 | */ |
| 337 | struct hw_queue_properties { |
| 338 | enum hl_queue_type type; |
Tal Cohen | 4bb1f2f | 2020-06-03 09:25:27 +0300 | [diff] [blame] | 339 | enum queue_cb_alloc_flags cb_alloc_flags; |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 340 | enum hl_collective_mode collective_mode; |
Oded Gabbay | 4c172bb | 2019-08-30 16:59:33 +0300 | [diff] [blame] | 341 | u8 driver_only; |
Ofir Bitton | 21e7a34 | 2020-05-14 18:25:47 +0300 | [diff] [blame] | 342 | u8 supports_sync_stream; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 343 | }; |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 344 | |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 345 | /** |
Oded Gabbay | 82629c7 | 2021-06-29 18:08:05 +0300 | [diff] [blame] | 346 | * enum vm_type - virtual memory mapping request information. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 347 | * @VM_TYPE_USERPTR: mapping of user memory to device virtual address. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 348 | * @VM_TYPE_PHYS_PACK: mapping of DRAM memory to device virtual address. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 349 | */ |
Oded Gabbay | 82629c7 | 2021-06-29 18:08:05 +0300 | [diff] [blame] | 350 | enum vm_type { |
Omer Shpigelman | 7b6e4ea | 2019-11-14 18:23:53 +0000 | [diff] [blame] | 351 | VM_TYPE_USERPTR = 0x1, |
| 352 | VM_TYPE_PHYS_PACK = 0x2 |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 353 | }; |
| 354 | |
| 355 | /** |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 356 | * 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 | */ |
| 362 | enum hl_device_hw_state { |
| 363 | HL_DEVICE_HW_STATE_CLEAN = 0, |
| 364 | HL_DEVICE_HW_STATE_DIRTY |
| 365 | }; |
| 366 | |
Ofir Bitton | 412c41f | 2020-11-04 15:18:55 +0200 | [diff] [blame] | 367 | #define HL_MMU_VA_ALIGNMENT_NOT_NEEDED 0 |
| 368 | |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 369 | /** |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 370 | * struct hl_mmu_properties - ASIC specific MMU address translation properties. |
Omer Shpigelman | 64a7e29 | 2020-01-05 09:05:45 +0000 | [diff] [blame] | 371 | * @start_addr: virtual start address of the memory region. |
| 372 | * @end_addr: virtual end address of the memory region. |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 373 | * @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 Haimovski | 7edf341 | 2020-08-23 13:23:13 +0300 | [diff] [blame] | 378 | * @hop5_shift: shift of hop 5 mask. |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 379 | * @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 Haimovski | 7edf341 | 2020-08-23 13:23:13 +0300 | [diff] [blame] | 384 | * @hop5_mask: mask to get the PTE address in hop 5. |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 385 | * @page_size: default page size used to allocate memory. |
Moti Haimovski | 7edf341 | 2020-08-23 13:23:13 +0300 | [diff] [blame] | 386 | * @num_hops: The amount of hops supported by the translation table. |
Moti Haimovski | ccf979e | 2020-10-05 17:59:29 +0300 | [diff] [blame] | 387 | * @host_resident: Should the MMU page table reside in host memory or in the |
| 388 | * device DRAM. |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 389 | */ |
| 390 | struct hl_mmu_properties { |
Omer Shpigelman | 64a7e29 | 2020-01-05 09:05:45 +0000 | [diff] [blame] | 391 | u64 start_addr; |
| 392 | u64 end_addr; |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 393 | u64 hop0_shift; |
| 394 | u64 hop1_shift; |
| 395 | u64 hop2_shift; |
| 396 | u64 hop3_shift; |
| 397 | u64 hop4_shift; |
Moti Haimovski | 7edf341 | 2020-08-23 13:23:13 +0300 | [diff] [blame] | 398 | u64 hop5_shift; |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 399 | u64 hop0_mask; |
| 400 | u64 hop1_mask; |
| 401 | u64 hop2_mask; |
| 402 | u64 hop3_mask; |
| 403 | u64 hop4_mask; |
Moti Haimovski | 7edf341 | 2020-08-23 13:23:13 +0300 | [diff] [blame] | 404 | u64 hop5_mask; |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 405 | u32 page_size; |
Moti Haimovski | 7edf341 | 2020-08-23 13:23:13 +0300 | [diff] [blame] | 406 | u32 num_hops; |
Moti Haimovski | ccf979e | 2020-10-05 17:59:29 +0300 | [diff] [blame] | 407 | u8 host_resident; |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 408 | }; |
| 409 | |
| 410 | /** |
farah kassabri | 1ae32b9 | 2021-01-31 18:56:03 +0200 | [diff] [blame] | 411 | * 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 | */ |
| 415 | struct hl_hints_range { |
| 416 | u64 start_addr; |
| 417 | u64 end_addr; |
| 418 | }; |
| 419 | |
| 420 | /** |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 421 | * struct asic_fixed_properties - ASIC specific immutable properties. |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 422 | * @hw_queues_props: H/W queues properties. |
Oded Gabbay | 2f55342 | 2020-08-15 16:28:10 +0300 | [diff] [blame] | 423 | * @cpucp_info: received various information from CPU-CP regarding the H/W, e.g. |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 424 | * available sensors. |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 425 | * @uboot_ver: F/W U-boot version. |
| 426 | * @preboot_ver: F/W Preboot version. |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 427 | * @dmmu: DRAM MMU address translation properties. |
| 428 | * @pmmu: PCI (host) MMU address translation properties. |
Omer Shpigelman | 64a7e29 | 2020-01-05 09:05:45 +0000 | [diff] [blame] | 429 | * @pmmu_huge: PCI (host) MMU address translation properties for memory |
| 430 | * allocated with huge pages. |
farah kassabri | 1ae32b9 | 2021-01-31 18:56:03 +0200 | [diff] [blame] | 431 | * @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 Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 435 | * @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 Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 443 | * @max_power_default: max power of the device after reset |
Koby Elbaz | cd5def8 | 2021-02-23 21:31:27 +0200 | [diff] [blame] | 444 | * @dc_power_default: power consumed by the device in mode idle. |
Omer Shpigelman | 27ca384c | 2019-02-28 10:46:11 +0200 | [diff] [blame] | 445 | * @dram_size_for_default_page_mapping: DRAM size needed to map to avoid page |
| 446 | * fault. |
Tomer Tayar | b6f897d | 2019-03-05 16:48:42 +0200 | [diff] [blame] | 447 | * @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 Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 449 | * @mmu_pgt_addr: base physical address in DRAM of MMU page tables. |
Omer Shpigelman | 27ca384c | 2019-02-28 10:46:11 +0200 | [diff] [blame] | 450 | * @mmu_dram_default_page_addr: DRAM default page physical address. |
Tomer Tayar | ef6a0f6 | 2020-07-09 16:17:48 +0300 | [diff] [blame] | 451 | * @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 kassabri | 1ae32b9 | 2021-01-31 18:56:03 +0200 | [diff] [blame] | 455 | * @dram_hints_align_mask: dram va hint addresses alignment mask which is used |
| 456 | * for hints validity check. |
Oded Gabbay | 2b5bbef | 2021-07-10 21:12:45 +0300 | [diff] [blame] | 457 | * device_dma_offset_for_host_access: the offset to add to host DMA addresses |
| 458 | * to enable the device to access them. |
Rajaravi Krishna Katta | 024b7b1 | 2021-09-03 08:01:30 +0300 | [diff] [blame] | 459 | * @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 Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 462 | * @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 Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 467 | * @cfg_size: configuration space size on SRAM. |
| 468 | * @sram_size: total size of SRAM. |
| 469 | * @max_asid: maximum number of open contexts (ASIDs). |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 470 | * @num_of_events: number of possible internal H/W IRQs. |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 471 | * @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 Aharon | e8edded | 2020-05-26 11:04:30 +0300 | [diff] [blame] | 475 | * @psoc_timestamp_frequency: frequency of the psoc timestamp clock. |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 476 | * @high_pll: high PLL frequency used by the device. |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 477 | * @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 Bitton | 3abc99b | 2020-06-23 14:50:39 +0300 | [diff] [blame] | 479 | * @max_pending_cs: maximum of concurrent pending command submissions |
| 480 | * @max_queues: maximum amount of queues in the system |
Ohad Sharabi | e67a6040 | 2021-05-02 15:45:21 +0300 | [diff] [blame] | 481 | * @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 Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 499 | * @collective_first_sob: first sync object available for collective use |
| 500 | * @collective_first_mon: first monitor available for collective use |
Ofir Bitton | 21e7a34 | 2020-05-14 18:25:47 +0300 | [diff] [blame] | 501 | * @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 Bitton | 843839b | 2020-07-19 11:08:09 +0300 | [diff] [blame] | 503 | * @first_available_user_sob: first sob available for the user |
| 504 | * @first_available_user_mon: first monitor available for the user |
Ofir Bitton | e1fa724 | 2021-01-06 15:40:37 +0200 | [diff] [blame] | 505 | * @first_available_user_msix_interrupt: first available msix interrupt |
| 506 | * reserved for the user |
Ofir Bitton | e52606d | 2021-01-27 16:34:37 +0200 | [diff] [blame] | 507 | * @first_available_cq: first available CQ for the user. |
Ofir Bitton | 2d44c6f | 2021-01-12 14:43:09 +0200 | [diff] [blame] | 508 | * @user_interrupt_count: number of user interrupts. |
Oded Gabbay | 5dc9ffa | 2021-07-15 10:48:43 +0300 | [diff] [blame] | 509 | * @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 Bitton | 21e7a34 | 2020-05-14 18:25:47 +0300 | [diff] [blame] | 511 | * @tpc_enabled_mask: which TPCs are enabled. |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 512 | * @completion_queues_count: number of completion queues. |
Ohad Sharabi | 4cb4508 | 2021-05-20 09:09:03 +0300 | [diff] [blame] | 513 | * @fw_security_enabled: true if security measures are enabled in firmware, |
| 514 | * false otherwise |
Ohad Sharabi | e67a6040 | 2021-05-02 15:45:21 +0300 | [diff] [blame] | 515 | * @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 Gabbay | 7f070c9 | 2020-11-09 09:48:31 +0200 | [diff] [blame] | 519 | * @dram_supports_virtual_memory: is there an MMU towards the DRAM |
Ofir Bitton | d611b9f | 2020-11-08 13:10:09 +0200 | [diff] [blame] | 520 | * @hard_reset_done_by_fw: true if firmware is handling hard reset flow |
Oded Gabbay | 1530d46 | 2020-12-18 19:12:56 +0200 | [diff] [blame] | 521 | * @num_functional_hbms: number of functional HBMs in each DCORE. |
farah kassabri | 1ae32b9 | 2021-01-31 18:56:03 +0200 | [diff] [blame] | 522 | * @hints_range_reservation: device support hint addresses range reservation. |
Ofir Bitton | 41f458f | 2021-03-10 15:08:44 +0200 | [diff] [blame] | 523 | * @iatu_done_by_fw: true if iATU configuration is being done by FW. |
Ohad Sharabi | 6e16ab6 | 2021-03-25 10:06:26 +0200 | [diff] [blame] | 524 | * @dynamic_fw_load: is dynamic FW load is supported. |
Koby Elbaz | 8121736 | 2021-05-03 23:03:15 +0300 | [diff] [blame] | 525 | * @gic_interrupts_enable: true if FW is not blocking GIC controller, |
| 526 | * false otherwise. |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 527 | */ |
| 528 | struct asic_fixed_properties { |
Ofir Bitton | 3abc99b | 2020-06-23 14:50:39 +0300 | [diff] [blame] | 529 | struct hw_queue_properties *hw_queues_props; |
Oded Gabbay | 2f55342 | 2020-08-15 16:28:10 +0300 | [diff] [blame] | 530 | struct cpucp_info cpucp_info; |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 531 | 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 Shpigelman | 64a7e29 | 2020-01-05 09:05:45 +0000 | [diff] [blame] | 535 | struct hl_mmu_properties pmmu_huge; |
farah kassabri | 1ae32b9 | 2021-01-31 18:56:03 +0200 | [diff] [blame] | 536 | 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 Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 539 | 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 Elbaz | cd5def8 | 2021-02-23 21:31:27 +0200 | [diff] [blame] | 548 | u64 dc_power_default; |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 549 | 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 Tayar | ef6a0f6 | 2020-07-09 16:17:48 +0300 | [diff] [blame] | 554 | u64 cb_va_start_addr; |
| 555 | u64 cb_va_end_addr; |
farah kassabri | 1ae32b9 | 2021-01-31 18:56:03 +0200 | [diff] [blame] | 556 | u64 dram_hints_align_mask; |
Oded Gabbay | 2b5bbef | 2021-07-10 21:12:45 +0300 | [diff] [blame] | 557 | u64 device_dma_offset_for_host_access; |
Rajaravi Krishna Katta | 024b7b1 | 2021-09-03 08:01:30 +0300 | [diff] [blame] | 558 | u64 max_freq_value; |
| 559 | u32 clk_pll_index; |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 560 | 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 Aharon | e8edded | 2020-05-26 11:04:30 +0300 | [diff] [blame] | 573 | u32 psoc_timestamp_frequency; |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 574 | u32 high_pll; |
| 575 | u32 cb_pool_cb_cnt; |
| 576 | u32 cb_pool_cb_size; |
Ofir Bitton | c16d45f | 2020-06-02 12:28:27 +0300 | [diff] [blame] | 577 | u32 max_pending_cs; |
Ofir Bitton | 3abc99b | 2020-06-23 14:50:39 +0300 | [diff] [blame] | 578 | u32 max_queues; |
Ohad Sharabi | e67a6040 | 2021-05-02 15:45:21 +0300 | [diff] [blame] | 579 | 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 Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 585 | u16 collective_first_sob; |
| 586 | u16 collective_first_mon; |
Ofir Bitton | 21e7a34 | 2020-05-14 18:25:47 +0300 | [diff] [blame] | 587 | u16 sync_stream_first_sob; |
| 588 | u16 sync_stream_first_mon; |
Ofir Bitton | 843839b | 2020-07-19 11:08:09 +0300 | [diff] [blame] | 589 | u16 first_available_user_sob[HL_MAX_DCORES]; |
| 590 | u16 first_available_user_mon[HL_MAX_DCORES]; |
Ofir Bitton | e1fa724 | 2021-01-06 15:40:37 +0200 | [diff] [blame] | 591 | u16 first_available_user_msix_interrupt; |
Ofir Bitton | e52606d | 2021-01-27 16:34:37 +0200 | [diff] [blame] | 592 | u16 first_available_cq[HL_MAX_DCORES]; |
Ofir Bitton | 2d44c6f | 2021-01-12 14:43:09 +0200 | [diff] [blame] | 593 | u16 user_interrupt_count; |
Oded Gabbay | 5dc9ffa | 2021-07-15 10:48:43 +0300 | [diff] [blame] | 594 | u16 server_type; |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 595 | u8 tpc_enabled_mask; |
| 596 | u8 completion_queues_count; |
Ohad Sharabi | 4cb4508 | 2021-05-20 09:09:03 +0300 | [diff] [blame] | 597 | u8 fw_security_enabled; |
Ohad Sharabi | e67a6040 | 2021-05-02 15:45:21 +0300 | [diff] [blame] | 598 | u8 fw_cpu_boot_dev_sts0_valid; |
| 599 | u8 fw_cpu_boot_dev_sts1_valid; |
Oded Gabbay | 7f070c9 | 2020-11-09 09:48:31 +0200 | [diff] [blame] | 600 | u8 dram_supports_virtual_memory; |
Ofir Bitton | d611b9f | 2020-11-08 13:10:09 +0200 | [diff] [blame] | 601 | u8 hard_reset_done_by_fw; |
Oded Gabbay | 1530d46 | 2020-12-18 19:12:56 +0200 | [diff] [blame] | 602 | u8 num_functional_hbms; |
farah kassabri | 1ae32b9 | 2021-01-31 18:56:03 +0200 | [diff] [blame] | 603 | u8 hints_range_reservation; |
Ofir Bitton | 41f458f | 2021-03-10 15:08:44 +0200 | [diff] [blame] | 604 | u8 iatu_done_by_fw; |
Ohad Sharabi | 6e16ab6 | 2021-03-25 10:06:26 +0200 | [diff] [blame] | 605 | u8 dynamic_fw_load; |
Koby Elbaz | 8121736 | 2021-05-03 23:03:15 +0300 | [diff] [blame] | 606 | u8 gic_interrupts_enable; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 607 | }; |
| 608 | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 609 | /** |
Ofir Bitton | a98d73c | 2020-07-15 08:52:39 +0300 | [diff] [blame] | 610 | * struct hl_fence - software synchronization primitive |
| 611 | * @completion: fence is implemented using completion |
| 612 | * @refcount: refcount for this fence |
Ofir Bitton | 0811b39 | 2020-12-06 17:18:02 +0200 | [diff] [blame] | 613 | * @cs_sequence: sequence of the corresponding command submission |
Ohad Sharabi | 72d6625 | 2021-08-01 23:02:07 +0300 | [diff] [blame] | 614 | * @stream_master_qid_map: streams masters QID bitmap to represent all streams |
| 615 | * masters QIDs that multi cs is waiting on |
Ofir Bitton | a98d73c | 2020-07-15 08:52:39 +0300 | [diff] [blame] | 616 | * @error: mark this fence with error |
Ofir Bitton | bd2f477 | 2020-11-10 17:26:22 +0200 | [diff] [blame] | 617 | * @timestamp: timestamp upon completion |
Dani Liberman | ea6eb91 | 2021-10-03 15:57:44 +0300 | [diff] [blame] | 618 | * @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 Bitton | a98d73c | 2020-07-15 08:52:39 +0300 | [diff] [blame] | 621 | */ |
| 622 | struct hl_fence { |
| 623 | struct completion completion; |
| 624 | struct kref refcount; |
Ofir Bitton | 0811b39 | 2020-12-06 17:18:02 +0200 | [diff] [blame] | 625 | u64 cs_sequence; |
Ohad Sharabi | 72d6625 | 2021-08-01 23:02:07 +0300 | [diff] [blame] | 626 | u32 stream_master_qid_map; |
Ofir Bitton | a98d73c | 2020-07-15 08:52:39 +0300 | [diff] [blame] | 627 | int error; |
Ofir Bitton | bd2f477 | 2020-11-10 17:26:22 +0200 | [diff] [blame] | 628 | ktime_t timestamp; |
Dani Liberman | ea6eb91 | 2021-10-03 15:57:44 +0300 | [diff] [blame] | 629 | u8 mcs_handling_done; |
Ofir Bitton | a98d73c | 2020-07-15 08:52:39 +0300 | [diff] [blame] | 630 | }; |
| 631 | |
| 632 | /** |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 633 | * struct hl_cs_compl - command submission completion object. |
Ofir Bitton | a98d73c | 2020-07-15 08:52:39 +0300 | [diff] [blame] | 634 | * @base_fence: hl fence object. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 635 | * @lock: spinlock to protect fence. |
| 636 | * @hdev: habanalabs device structure. |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 637 | * @hw_sob: the H/W SOB used in this signal/wait CS. |
farah kassabri | e4cdccd | 2021-05-26 10:43:36 +0300 | [diff] [blame] | 638 | * @encaps_sig_hdl: encaps signals hanlder. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 639 | * @cs_seq: command submission sequence number. |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 640 | * @type: type of the CS - signal/wait. |
| 641 | * @sob_val: the SOB value that is used in this signal/wait CS. |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 642 | * @sob_group: the SOB group that is used in this collective wait CS. |
farah kassabri | dadf17a | 2021-05-24 18:09:22 +0300 | [diff] [blame] | 643 | * @encaps_signals: indication whether it's a completion object of cs with |
| 644 | * encaps signals or not. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 645 | */ |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 646 | struct hl_cs_compl { |
Ofir Bitton | a98d73c | 2020-07-15 08:52:39 +0300 | [diff] [blame] | 647 | struct hl_fence base_fence; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 648 | spinlock_t lock; |
| 649 | struct hl_device *hdev; |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 650 | struct hl_hw_sob *hw_sob; |
farah kassabri | e4cdccd | 2021-05-26 10:43:36 +0300 | [diff] [blame] | 651 | struct hl_cs_encaps_sig_handle *encaps_sig_hdl; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 652 | u64 cs_seq; |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 653 | enum hl_cs_type type; |
| 654 | u16 sob_val; |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 655 | u16 sob_group; |
farah kassabri | dadf17a | 2021-05-24 18:09:22 +0300 | [diff] [blame] | 656 | bool encaps_signals; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 657 | }; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 658 | |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 659 | /* |
| 660 | * Command Buffers |
| 661 | */ |
| 662 | |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 663 | /** |
| 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 | */ |
| 668 | struct 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 Tayar | fa8641a1 | 2020-09-07 17:36:41 +0300 | [diff] [blame] | 677 | * @ctx: pointer to the CB owner's context. |
Tomer Tayar | f0748674 | 2020-08-02 22:51:31 +0300 | [diff] [blame] | 678 | * @lock: spinlock to protect mmap flows. |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 679 | * @debugfs_list: node in debugfs list of command buffers. |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 680 | * @pool_list: node in pool list of command buffers. |
Tomer Tayar | ef6a0f6 | 2020-07-09 16:17:48 +0300 | [diff] [blame] | 681 | * @va_block_list: list of virtual addresses blocks of the CB if it is mapped to |
| 682 | * the device's MMU. |
Oded Gabbay | f5b9c8c | 2020-08-12 10:11:20 +0300 | [diff] [blame] | 683 | * @id: the CB's ID. |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 684 | * @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 Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 688 | * @cs_cnt: holds number of CS that this CB participates in. |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 689 | * @mmap: true if the CB is currently mmaped to user. |
| 690 | * @is_pool: true if CB was acquired from the pool, false otherwise. |
Ofir Bitton | a04b7cd | 2020-07-13 13:36:55 +0300 | [diff] [blame] | 691 | * @is_internal: internaly allocated |
Tomer Tayar | ef6a0f6 | 2020-07-09 16:17:48 +0300 | [diff] [blame] | 692 | * @is_mmu_mapped: true if the CB is mapped to the device's MMU. |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 693 | */ |
| 694 | struct hl_cb { |
| 695 | struct kref refcount; |
| 696 | struct hl_device *hdev; |
Tomer Tayar | fa8641a1 | 2020-09-07 17:36:41 +0300 | [diff] [blame] | 697 | struct hl_ctx *ctx; |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 698 | spinlock_t lock; |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 699 | struct list_head debugfs_list; |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 700 | struct list_head pool_list; |
Tomer Tayar | ef6a0f6 | 2020-07-09 16:17:48 +0300 | [diff] [blame] | 701 | struct list_head va_block_list; |
Oded Gabbay | f5b9c8c | 2020-08-12 10:11:20 +0300 | [diff] [blame] | 702 | u64 id; |
Arnd Bergmann | 82948e6 | 2020-10-26 17:08:06 +0100 | [diff] [blame] | 703 | void *kernel_address; |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 704 | dma_addr_t bus_address; |
| 705 | u32 mmap_size; |
| 706 | u32 size; |
Tomer Tayar | f0748674 | 2020-08-02 22:51:31 +0300 | [diff] [blame] | 707 | atomic_t cs_cnt; |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 708 | u8 mmap; |
| 709 | u8 is_pool; |
Ofir Bitton | a04b7cd | 2020-07-13 13:36:55 +0300 | [diff] [blame] | 710 | u8 is_internal; |
Tomer Tayar | ef6a0f6 | 2020-07-09 16:17:48 +0300 | [diff] [blame] | 711 | u8 is_mmu_mapped; |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 712 | }; |
| 713 | |
| 714 | |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 715 | /* |
| 716 | * QUEUES |
| 717 | */ |
| 718 | |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 719 | struct hl_cs; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 720 | struct hl_cs_job; |
| 721 | |
Ofir Bitton | dd9efab | 2020-06-15 12:09:50 +0300 | [diff] [blame] | 722 | /* Queue length of external and HW queues */ |
| 723 | #define HL_QUEUE_LENGTH 4096 |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 724 | #define HL_QUEUE_SIZE_IN_BYTES (HL_QUEUE_LENGTH * HL_BD_SIZE) |
| 725 | |
Ofir Bitton | 22cb855 | 2020-07-08 10:16:27 +0300 | [diff] [blame] | 726 | #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 Bitton | dd9efab | 2020-06-15 12:09:50 +0300 | [diff] [blame] | 730 | /* HL_CQ_LENGTH is in units of struct hl_cq_entry */ |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 731 | #define HL_CQ_LENGTH HL_QUEUE_LENGTH |
| 732 | #define HL_CQ_SIZE_IN_BYTES (HL_CQ_LENGTH * HL_CQ_ENTRY_SIZE) |
| 733 | |
Ofir Bitton | dd9efab | 2020-06-15 12:09:50 +0300 | [diff] [blame] | 734 | /* Must be power of 2 */ |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 735 | #define HL_EQ_LENGTH 64 |
| 736 | #define HL_EQ_SIZE_IN_BYTES (HL_EQ_LENGTH * HL_EQ_ENTRY_SIZE) |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 737 | |
Oded Gabbay | 6138bbe | 2020-09-04 20:18:16 +0300 | [diff] [blame] | 738 | /* Host <-> CPU-CP shared memory size */ |
Oded Gabbay | 95b5a8b | 2019-05-29 17:30:04 +0300 | [diff] [blame] | 739 | #define HL_CPU_ACCESSIBLE_MEM_SIZE SZ_2M |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 740 | |
| 741 | /** |
Ofir Bitton | 3cf74b3 | 2020-09-10 09:17:50 +0300 | [diff] [blame] | 742 | * struct hl_sync_stream_properties - |
| 743 | * describes a H/W queue sync stream properties |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 744 | * @hw_sob: array of the used H/W SOBs by this H/W queue. |
Ofir Bitton | 3cf74b3 | 2020-09-10 09:17:50 +0300 | [diff] [blame] | 745 | * @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 Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 748 | * @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 Bitton | 3cf74b3 | 2020-09-10 09:17:50 +0300 | [diff] [blame] | 754 | * @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 | */ |
| 757 | struct hl_sync_stream_properties { |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 758 | 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 Bitton | 3cf74b3 | 2020-09-10 09:17:50 +0300 | [diff] [blame] | 766 | }; |
| 767 | |
| 768 | /** |
farah kassabri | dadf17a | 2021-05-24 18:09:22 +0300 | [diff] [blame] | 769 | * 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 | */ |
| 774 | struct hl_encaps_signals_mgr { |
| 775 | spinlock_t lock; |
| 776 | struct idr handles; |
| 777 | }; |
| 778 | |
| 779 | /** |
Ofir Bitton | 3cf74b3 | 2020-09-10 09:17:50 +0300 | [diff] [blame] | 780 | * struct hl_hw_queue - describes a H/W transport queue. |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 781 | * @shadow_queue: pointer to a shadow queue that holds pointers to jobs. |
Ofir Bitton | 3cf74b3 | 2020-09-10 09:17:50 +0300 | [diff] [blame] | 782 | * @sync_stream_prop: sync stream queue properties |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 783 | * @queue_type: type of queue. |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 784 | * @collective_mode: collective mode of current queue |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 785 | * @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 Shpigelman | 1fa185c | 2020-03-01 19:59:39 +0200 | [diff] [blame] | 790 | * @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 Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 792 | * @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 Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 794 | * exist). |
Ofir Bitton | 21e7a34 | 2020-05-14 18:25:47 +0300 | [diff] [blame] | 795 | * @supports_sync_stream: True if queue supports sync stream |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 796 | */ |
| 797 | struct hl_hw_queue { |
Ofir Bitton | 3cf74b3 | 2020-09-10 09:17:50 +0300 | [diff] [blame] | 798 | struct hl_cs_job **shadow_queue; |
| 799 | struct hl_sync_stream_properties sync_stream_prop; |
| 800 | enum hl_queue_type queue_type; |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 801 | enum hl_collective_mode collective_mode; |
Ofir Bitton | 3cf74b3 | 2020-09-10 09:17:50 +0300 | [diff] [blame] | 802 | 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 Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 812 | }; |
| 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 Bitton | 5574cb2 | 2020-07-05 13:35:51 +0300 | [diff] [blame] | 819 | * @cq_idx: completion queue index in array |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 820 | * @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 | */ |
| 825 | struct hl_cq { |
| 826 | struct hl_device *hdev; |
Arnd Bergmann | 82948e6 | 2020-10-26 17:08:06 +0100 | [diff] [blame] | 827 | void *kernel_address; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 828 | dma_addr_t bus_address; |
Ofir Bitton | 5574cb2 | 2020-07-05 13:35:51 +0300 | [diff] [blame] | 829 | u32 cq_idx; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 830 | u32 hw_queue_id; |
| 831 | u32 ci; |
| 832 | u32 pi; |
| 833 | atomic_t free_slots_cnt; |
| 834 | }; |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 835 | |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 836 | /** |
Ofir Bitton | 2d44c6f | 2021-01-12 14:43:09 +0200 | [diff] [blame] | 837 | * struct hl_user_interrupt - holds user interrupt information |
| 838 | * @hdev: pointer to the device structure |
Ofir Bitton | ab5f5c3 | 2021-01-12 18:37:19 +0200 | [diff] [blame] | 839 | * @wait_list_head: head to the list of user threads pending on this interrupt |
| 840 | * @wait_list_lock: protects wait_list_head |
Ofir Bitton | 2d44c6f | 2021-01-12 14:43:09 +0200 | [diff] [blame] | 841 | * @interrupt_id: msix interrupt id |
| 842 | */ |
| 843 | struct hl_user_interrupt { |
| 844 | struct hl_device *hdev; |
Ofir Bitton | ab5f5c3 | 2021-01-12 18:37:19 +0200 | [diff] [blame] | 845 | struct list_head wait_list_head; |
| 846 | spinlock_t wait_list_lock; |
Ofir Bitton | 2d44c6f | 2021-01-12 14:43:09 +0200 | [diff] [blame] | 847 | u32 interrupt_id; |
| 848 | }; |
| 849 | |
| 850 | /** |
Ofir Bitton | ab5f5c3 | 2021-01-12 18:37:19 +0200 | [diff] [blame] | 851 | * 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 | */ |
| 856 | struct hl_user_pending_interrupt { |
| 857 | struct list_head wait_list_node; |
| 858 | struct hl_fence fence; |
| 859 | }; |
| 860 | |
| 861 | /** |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 862 | * 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 Gabbay | 1242e9f | 2021-05-19 14:52:14 +0300 | [diff] [blame] | 867 | * @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 Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 872 | */ |
| 873 | struct hl_eq { |
| 874 | struct hl_device *hdev; |
Arnd Bergmann | 82948e6 | 2020-10-26 17:08:06 +0100 | [diff] [blame] | 875 | void *kernel_address; |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 876 | dma_addr_t bus_address; |
| 877 | u32 ci; |
Oded Gabbay | 1242e9f | 2021-05-19 14:52:14 +0300 | [diff] [blame] | 878 | u32 prev_eqe_index; |
| 879 | bool check_eqe_index; |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 880 | }; |
| 881 | |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 882 | |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 883 | /* |
| 884 | * ASICs |
| 885 | */ |
| 886 | |
| 887 | /** |
| 888 | * enum hl_asic_type - supported ASIC types. |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 889 | * @ASIC_INVALID: Invalid ASIC type. |
Oded Gabbay | 2959384 | 2019-04-04 14:33:34 +0300 | [diff] [blame] | 890 | * @ASIC_GOYA: Goya device. |
Oded Gabbay | 6966d9e | 2020-03-21 10:58:32 +0200 | [diff] [blame] | 891 | * @ASIC_GAUDI: Gaudi device. |
Ofir Bitton | e5042a6 | 2021-04-01 13:43:40 +0300 | [diff] [blame] | 892 | * @ASIC_GAUDI_SEC: Gaudi secured device (HL-2000). |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 893 | */ |
| 894 | enum hl_asic_type { |
Oded Gabbay | 2959384 | 2019-04-04 14:33:34 +0300 | [diff] [blame] | 895 | ASIC_INVALID, |
Oded Gabbay | 6966d9e | 2020-03-21 10:58:32 +0200 | [diff] [blame] | 896 | ASIC_GOYA, |
Ofir Bitton | e5042a6 | 2021-04-01 13:43:40 +0300 | [diff] [blame] | 897 | ASIC_GAUDI, |
| 898 | ASIC_GAUDI_SEC |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 899 | }; |
| 900 | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 901 | struct hl_cs_parser; |
| 902 | |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 903 | /** |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 904 | * enum hl_pm_mng_profile - power management profile. |
Oded Gabbay | 4c172bb | 2019-08-30 16:59:33 +0300 | [diff] [blame] | 905 | * @PM_AUTO: internal clock is set by the Linux driver. |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 906 | * @PM_MANUAL: internal clock is set by the user. |
| 907 | * @PM_LAST: last power management type. |
| 908 | */ |
| 909 | enum 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 | */ |
| 921 | enum hl_pll_frequency { |
| 922 | PLL_HIGH = 1, |
| 923 | PLL_LOW, |
| 924 | PLL_LAST |
| 925 | }; |
| 926 | |
Adam Aharon | e8edded | 2020-05-26 11:04:30 +0300 | [diff] [blame] | 927 | #define PLL_REF_CLK 50 |
| 928 | |
| 929 | enum 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 Sharabi | c592c27 | 2021-04-21 13:03:21 +0300 | [diff] [blame] | 936 | enum 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 Sharabi | b31e59b | 2021-04-22 10:01:22 +0300 | [diff] [blame] | 948 | * @bar_size: size of the BAR |
Ohad Sharabi | c592c27 | 2021-04-21 13:03:21 +0300 | [diff] [blame] | 949 | * @offset_in_bar: region offset into the bar |
| 950 | * @bar_id: bar ID of the region |
| 951 | * @used: if used 1, otherwise 0 |
| 952 | */ |
| 953 | struct pci_mem_region { |
| 954 | u64 region_base; |
| 955 | u64 region_size; |
Ohad Sharabi | b31e59b | 2021-04-22 10:01:22 +0300 | [diff] [blame] | 956 | u64 bar_size; |
Ohad Sharabi | 932adf1 | 2021-07-18 12:06:41 +0300 | [diff] [blame] | 957 | u64 offset_in_bar; |
Ohad Sharabi | c592c27 | 2021-04-21 13:03:21 +0300 | [diff] [blame] | 958 | u8 bar_id; |
| 959 | u8 used; |
| 960 | }; |
| 961 | |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 962 | /** |
Ohad Sharabi | 22a795b | 2021-04-08 13:42:00 +0300 | [diff] [blame] | 963 | * struct static_fw_load_mgr - static FW load manager |
Ohad Sharabi | 50f036d | 2021-04-11 15:26:28 +0300 | [diff] [blame] | 964 | * @preboot_version_max_off: max offset to preboot version |
| 965 | * @boot_fit_version_max_off: max offset to boot fit version |
Ohad Sharabi | 8a43c83 | 2021-04-11 10:32:18 +0300 | [diff] [blame] | 966 | * @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 Sharabi | a22f0ec | 2021-04-11 23:06:46 +0300 | [diff] [blame] | 968 | * @cpu_boot_status_reg: boot status register |
Ohad Sharabi | e67a6040 | 2021-05-02 15:45:21 +0300 | [diff] [blame] | 969 | * @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 Sharabi | 50f036d | 2021-04-11 15:26:28 +0300 | [diff] [blame] | 973 | * @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 Elbaz | b7a71fd | 2021-06-15 17:07:02 +0300 | [diff] [blame] | 976 | * @cpu_reset_wait_msec: used when setting WFE via kmd_msg_to_cpu_reg |
Ohad Sharabi | a22f0ec | 2021-04-11 23:06:46 +0300 | [diff] [blame] | 977 | */ |
Ohad Sharabi | 22a795b | 2021-04-08 13:42:00 +0300 | [diff] [blame] | 978 | struct static_fw_load_mgr { |
Ohad Sharabi | 50f036d | 2021-04-11 15:26:28 +0300 | [diff] [blame] | 979 | u64 preboot_version_max_off; |
| 980 | u64 boot_fit_version_max_off; |
Ohad Sharabi | 8a43c83 | 2021-04-11 10:32:18 +0300 | [diff] [blame] | 981 | u32 kmd_msg_to_cpu_reg; |
| 982 | u32 cpu_cmd_status_to_host_reg; |
Ohad Sharabi | a22f0ec | 2021-04-11 23:06:46 +0300 | [diff] [blame] | 983 | u32 cpu_boot_status_reg; |
Ohad Sharabi | e67a6040 | 2021-05-02 15:45:21 +0300 | [diff] [blame] | 984 | u32 cpu_boot_dev_status0_reg; |
| 985 | u32 cpu_boot_dev_status1_reg; |
Ohad Sharabi | a22f0ec | 2021-04-11 23:06:46 +0300 | [diff] [blame] | 986 | u32 boot_err0_reg; |
Ohad Sharabi | e67a6040 | 2021-05-02 15:45:21 +0300 | [diff] [blame] | 987 | u32 boot_err1_reg; |
Ohad Sharabi | 50f036d | 2021-04-11 15:26:28 +0300 | [diff] [blame] | 988 | u32 preboot_version_offset_reg; |
| 989 | u32 boot_fit_version_offset_reg; |
| 990 | u32 sram_offset_mask; |
Koby Elbaz | b7a71fd | 2021-06-15 17:07:02 +0300 | [diff] [blame] | 991 | u32 cpu_reset_wait_msec; |
Ohad Sharabi | 22a795b | 2021-04-08 13:42:00 +0300 | [diff] [blame] | 992 | }; |
| 993 | |
| 994 | /** |
Ohad Sharabi | 8a43c83 | 2021-04-11 10:32:18 +0300 | [diff] [blame] | 995 | * 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 | */ |
| 1000 | struct fw_response { |
| 1001 | u32 ram_offset; |
| 1002 | u8 ram_type; |
| 1003 | u8 status; |
| 1004 | }; |
| 1005 | |
| 1006 | /** |
Ohad Sharabi | 22a795b | 2021-04-08 13:42:00 +0300 | [diff] [blame] | 1007 | * struct dynamic_fw_load_mgr - dynamic FW load manager |
Ohad Sharabi | 8a43c83 | 2021-04-11 10:32:18 +0300 | [diff] [blame] | 1008 | * @response: FW to LKD response |
| 1009 | * @comm_desc: the communication descriptor with FW |
| 1010 | * @image_region: region to copy the FW image to |
Ohad Sharabi | b31e59b | 2021-04-22 10:01:22 +0300 | [diff] [blame] | 1011 | * @fw_image_size: size of FW image to load |
| 1012 | * @wait_for_bl_timeout: timeout for waiting for boot loader to respond |
Ohad Sharabi | 22a795b | 2021-04-08 13:42:00 +0300 | [diff] [blame] | 1013 | */ |
| 1014 | struct dynamic_fw_load_mgr { |
Ohad Sharabi | 8a43c83 | 2021-04-11 10:32:18 +0300 | [diff] [blame] | 1015 | 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 Sharabi | b31e59b | 2021-04-22 10:01:22 +0300 | [diff] [blame] | 1019 | u32 wait_for_bl_timeout; |
Ohad Sharabi | 8a43c83 | 2021-04-11 10:32:18 +0300 | [diff] [blame] | 1020 | }; |
| 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 | */ |
| 1028 | struct fw_image_props { |
| 1029 | char *image_name; |
| 1030 | u32 src_off; |
| 1031 | u32 copy_size; |
Ohad Sharabi | 22a795b | 2021-04-08 13:42:00 +0300 | [diff] [blame] | 1032 | }; |
| 1033 | |
| 1034 | /** |
| 1035 | * struct fw_load_mgr - manager FW loading process |
Ohad Sharabi | 8a43c83 | 2021-04-11 10:32:18 +0300 | [diff] [blame] | 1036 | * @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 Sharabi | 22a795b | 2021-04-08 13:42:00 +0300 | [diff] [blame] | 1040 | * @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 Sharabi | 8a43c83 | 2021-04-11 10:32:18 +0300 | [diff] [blame] | 1044 | * @dram_bar_id: DRAM bar ID |
Koby Elbaz | 3649eae | 2021-05-18 15:43:47 +0300 | [diff] [blame] | 1045 | * @linux_loaded: true if linux was loaded so far |
Ohad Sharabi | 22a795b | 2021-04-08 13:42:00 +0300 | [diff] [blame] | 1046 | */ |
| 1047 | struct fw_load_mgr { |
Ohad Sharabi | 8a43c83 | 2021-04-11 10:32:18 +0300 | [diff] [blame] | 1048 | 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 Sharabi | a22f0ec | 2021-04-11 23:06:46 +0300 | [diff] [blame] | 1054 | u32 cpu_timeout; |
| 1055 | u32 boot_fit_timeout; |
| 1056 | u8 skip_bmc; |
Ohad Sharabi | 50f036d | 2021-04-11 15:26:28 +0300 | [diff] [blame] | 1057 | u8 sram_bar_id; |
Ohad Sharabi | 8a43c83 | 2021-04-11 10:32:18 +0300 | [diff] [blame] | 1058 | u8 dram_bar_id; |
Koby Elbaz | 3649eae | 2021-05-18 15:43:47 +0300 | [diff] [blame] | 1059 | u8 linux_loaded; |
Ohad Sharabi | a22f0ec | 2021-04-11 23:06:46 +0300 | [diff] [blame] | 1060 | }; |
| 1061 | |
| 1062 | /** |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 1063 | * 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 Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 1067 | * @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 Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 1069 | * @sw_init: sets up driver state, does not configure H/W. |
| 1070 | * @sw_fini: tears down driver state, does not configure H/W. |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 1071 | * @hw_init: sets up the H/W state. |
| 1072 | * @hw_fini: tears down the H/W state. |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 1073 | * @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 Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 1076 | * @suspend: handles IP specific H/W or SW changes for suspend. |
| 1077 | * @resume: handles IP specific H/W or SW changes for resume. |
Zvika Yehudai | 1ee8e2b | 2021-07-06 13:50:32 +0300 | [diff] [blame] | 1078 | * @mmap: maps a memory. |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1079 | * @ring_doorbell: increment PI on a given QMAN. |
Oded Gabbay | b9040c9 | 2019-08-08 15:45:58 +0300 | [diff] [blame] | 1080 | * @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 Gabbay | d9c3aa8 | 2019-05-01 11:47:04 +0300 | [diff] [blame] | 1085 | * @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 kassabri | 03df136 | 2020-05-06 11:17:38 +0300 | [diff] [blame] | 1093 | * @scrub_device_mem: Scrub device memory given an address and size |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1094 | * @get_int_queue_base: get the internal queue base address. |
| 1095 | * @test_queues: run simple test on all queues for sanity check. |
Oded Gabbay | d9c3aa8 | 2019-05-01 11:47:04 +0300 | [diff] [blame] | 1096 | * @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 Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1099 | * @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 Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1101 | * @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 Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 1106 | * @update_eq_ci: update event queue CI. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1107 | * @context_switch: called upon ASID context switch. |
| 1108 | * @restore_phase_topology: clear all SOBs amd MONs. |
Oded Gabbay | 639781d | 2021-04-02 01:43:18 +0300 | [diff] [blame] | 1109 | * @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 Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 1115 | * @add_device_attr: add ASIC specific device attributes. |
Oded Gabbay | 6138bbe | 2020-09-04 20:18:16 +0300 | [diff] [blame] | 1116 | * @handle_eqe: handle event queue entry (IRQ) from CPU-CP. |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 1117 | * @set_pll_profile: change PLL profile (manual/automatic). |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 1118 | * @get_events_stat: retrieve event queue entries histogram. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1119 | * @read_pte: read MMU page table entry from DRAM. |
| 1120 | * @write_pte: write MMU page table entry to DRAM. |
Omer Shpigelman | 7b6e4ea | 2019-11-14 18:23:53 +0000 | [diff] [blame] | 1121 | * @mmu_invalidate_cache: flush MMU STLB host/DRAM cache, either with soft |
| 1122 | * (L1 only) or hard (L0 & L1) flush. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1123 | * @mmu_invalidate_cache_range: flush specific MMU STLB cache lines with |
| 1124 | * ASID-VA-size mask. |
Oded Gabbay | 6138bbe | 2020-09-04 20:18:16 +0300 | [diff] [blame] | 1125 | * @send_heartbeat: send is-alive packet to CPU-CP and verify response. |
Oded Gabbay | e38bfd3 | 2020-07-03 20:46:12 +0300 | [diff] [blame] | 1126 | * @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 Shpigelman | 315bc05 | 2019-04-01 22:31:22 +0300 | [diff] [blame] | 1129 | * @debug_coresight: perform certain actions on Coresight for debugging. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1130 | * @is_device_idle: return true if device is idle, false otherwise. |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 1131 | * @soft_reset_late_init: perform certain actions needed after soft reset. |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1132 | * @hw_queues_lock: acquire H/W queues lock. |
| 1133 | * @hw_queues_unlock: release H/W queues lock. |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 1134 | * @get_pci_id: retrieve PCI ID. |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 1135 | * @get_eeprom_data: retrieve EEPROM data from F/W. |
Oded Gabbay | 788cacf | 2020-07-07 17:30:13 +0300 | [diff] [blame] | 1136 | * @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 Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 1141 | * @get_hw_state: retrieve the H/W state |
Tomer Tayar | b6f897d | 2019-03-05 16:48:42 +0200 | [diff] [blame] | 1142 | * @pci_bars_map: Map PCI BARs. |
Tomer Tayar | b6f897d | 2019-03-05 16:48:42 +0200 | [diff] [blame] | 1143 | * @init_iatu: Initialize the iATU unit inside the PCI controller. |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 1144 | * @rreg: Read a register. Needed for simulator support. |
| 1145 | * @wreg: Write a register. Needed for simulator support. |
Omer Shpigelman | 89225ce | 2019-05-01 14:38:38 +0300 | [diff] [blame] | 1146 | * @halt_coresight: stop the ETF and ETR traces. |
Ofir Bitton | a04b7cd | 2020-07-13 13:36:55 +0300 | [diff] [blame] | 1147 | * @ctx_init: context dependent initialization. |
Ofir Bitton | 5de406c | 2020-09-10 10:56:26 +0300 | [diff] [blame] | 1148 | * @ctx_fini: context dependent cleanup. |
Oded Gabbay | 62c1e12 | 2019-10-10 15:48:59 +0300 | [diff] [blame] | 1149 | * @get_clk_rate: Retrieve the ASIC current and maximum clock rate in MHz |
Omer Shpigelman | 1fa185c | 2020-03-01 19:59:39 +0200 | [diff] [blame] | 1150 | * @get_queue_id_for_cq: Get the H/W queue id related to the given CQ index. |
Oded Gabbay | 7e1c07d | 2020-03-26 12:32:56 +0200 | [diff] [blame] | 1151 | * @load_firmware_to_device: load the firmware to the device's memory |
Ofir Bitton | 47f6b41 | 2020-04-16 13:47:15 +0300 | [diff] [blame] | 1152 | * @load_boot_fit_to_device: load boot fit to device's memory |
Omer Shpigelman | ec2f8a3 | 2020-05-07 13:43:05 +0300 | [diff] [blame] | 1153 | * @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 Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 1158 | * @reset_sob_group: Reset SOB group |
Oded Gabbay | cb056b9 | 2020-03-29 13:18:30 +0300 | [diff] [blame] | 1159 | * @set_dma_mask_from_fw: set the DMA mask in the driver according to the |
| 1160 | * firmware configuration |
Tomer Tayar | 25e7aeb | 2020-03-31 22:46:36 +0300 | [diff] [blame] | 1161 | * @get_device_time: Get the device time. |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 1162 | * @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 kassabri | 89473a1 | 2021-01-12 17:24:00 +0200 | [diff] [blame] | 1165 | * @scramble_addr: Routine to scramble the address prior of mapping it |
Oded Gabbay | 28bcf1f | 2021-02-01 21:23:43 +0200 | [diff] [blame] | 1166 | * in the MMU. |
farah kassabri | 89473a1 | 2021-01-12 17:24:00 +0200 | [diff] [blame] | 1167 | * @descramble_addr: Routine to de-scramble the address prior of |
Oded Gabbay | 28bcf1f | 2021-02-01 21:23:43 +0200 | [diff] [blame] | 1168 | * showing it to users. |
Ofir Bitton | d2b980f | 2021-01-07 12:14:17 +0200 | [diff] [blame] | 1169 | * @ack_protection_bits_errors: ack and dump all security violations |
Ofir Bitton | d00697f | 2021-01-05 12:55:06 +0200 | [diff] [blame] | 1170 | * @get_hw_block_id: retrieve a HW block id to be used by the user to mmap it. |
Oded Gabbay | 6df50d2 | 2021-02-05 16:04:34 +0200 | [diff] [blame] | 1171 | * also returns the size of the block if caller supplies |
| 1172 | * a valid pointer for it |
Ofir Bitton | d00697f | 2021-01-05 12:55:06 +0200 | [diff] [blame] | 1173 | * @hw_block_mmap: mmap a HW block with a given id. |
Oded Gabbay | 28bcf1f | 2021-02-01 21:23:43 +0200 | [diff] [blame] | 1174 | * @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 Jauhari | 285c0fa | 2021-03-25 18:15:40 +0200 | [diff] [blame] | 1178 | * @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 Jauhari | 4b09901 | 2021-05-28 13:14:34 +0300 | [diff] [blame] | 1181 | * @init_firmware_loader: initialize data for FW loader. |
| 1182 | * @init_cpu_scrambler_dram: Enable CPU specific DRAM scrambling |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 1183 | * @state_dump_init: initialize constants required for state dump |
farah kassabri | dadf17a | 2021-05-24 18:09:22 +0300 | [diff] [blame] | 1184 | * @get_sob_addr: get SOB base address offset. |
Ohad Sharabi | b9317d5 | 2021-07-15 15:20:44 +0300 | [diff] [blame] | 1185 | * @set_pci_memory_regions: setting properties of PCI memory regions |
Ohad Sharabi | 72d6625 | 2021-08-01 23:02:07 +0300 | [diff] [blame] | 1186 | * @get_stream_master_qid_arr: get pointer to stream masters QID array |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 1187 | */ |
| 1188 | struct hl_asic_funcs { |
| 1189 | int (*early_init)(struct hl_device *hdev); |
| 1190 | int (*early_fini)(struct hl_device *hdev); |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 1191 | int (*late_init)(struct hl_device *hdev); |
| 1192 | void (*late_fini)(struct hl_device *hdev); |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 1193 | int (*sw_init)(struct hl_device *hdev); |
| 1194 | int (*sw_fini)(struct hl_device *hdev); |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 1195 | int (*hw_init)(struct hl_device *hdev); |
Oded Gabbay | 8d9aa98 | 2021-08-09 22:43:37 +0300 | [diff] [blame] | 1196 | 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 Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 1198 | int (*suspend)(struct hl_device *hdev); |
| 1199 | int (*resume)(struct hl_device *hdev); |
Zvika Yehudai | 1ee8e2b | 2021-07-06 13:50:32 +0300 | [diff] [blame] | 1200 | int (*mmap)(struct hl_device *hdev, struct vm_area_struct *vma, |
Hillf Danton | 0db5753 | 2020-08-23 07:32:42 +0800 | [diff] [blame] | 1201 | void *cpu_addr, dma_addr_t dma_addr, size_t size); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1202 | void (*ring_doorbell)(struct hl_device *hdev, u32 hw_queue_id, u32 pi); |
Oded Gabbay | b9040c9 | 2019-08-08 15:45:58 +0300 | [diff] [blame] | 1203 | void (*pqe_write)(struct hl_device *hdev, __le64 *pqe, |
| 1204 | struct hl_bd *bd); |
Oded Gabbay | d9c3aa8 | 2019-05-01 11:47:04 +0300 | [diff] [blame] | 1205 | void* (*asic_dma_alloc_coherent)(struct hl_device *hdev, size_t size, |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 1206 | dma_addr_t *dma_handle, gfp_t flag); |
Oded Gabbay | d9c3aa8 | 2019-05-01 11:47:04 +0300 | [diff] [blame] | 1207 | void (*asic_dma_free_coherent)(struct hl_device *hdev, size_t size, |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 1208 | void *cpu_addr, dma_addr_t dma_handle); |
farah kassabri | 03df136 | 2020-05-06 11:17:38 +0300 | [diff] [blame] | 1209 | int (*scrub_device_mem)(struct hl_device *hdev, u64 addr, u64 size); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1210 | 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 Gabbay | d9c3aa8 | 2019-05-01 11:47:04 +0300 | [diff] [blame] | 1213 | void* (*asic_dma_pool_zalloc)(struct hl_device *hdev, size_t size, |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1214 | gfp_t mem_flags, dma_addr_t *dma_handle); |
Oded Gabbay | d9c3aa8 | 2019-05-01 11:47:04 +0300 | [diff] [blame] | 1215 | void (*asic_dma_pool_free)(struct hl_device *hdev, void *vaddr, |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1216 | 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 Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1221 | void (*hl_dma_unmap_sg)(struct hl_device *hdev, |
Tomer Tayar | 94cb669 | 2019-05-01 11:28:15 +0300 | [diff] [blame] | 1222 | struct scatterlist *sgl, int nents, |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1223 | 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 Tayar | 94cb669 | 2019-05-01 11:28:15 +0300 | [diff] [blame] | 1226 | struct scatterlist *sgl, int nents, |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1227 | enum dma_data_direction dir); |
| 1228 | u32 (*get_dma_desc_list_size)(struct hl_device *hdev, |
| 1229 | struct sg_table *sgt); |
Oded Gabbay | 921a465 | 2019-05-12 16:53:16 +0300 | [diff] [blame] | 1230 | void (*add_end_of_cb_packets)(struct hl_device *hdev, |
Arnd Bergmann | 82948e6 | 2020-10-26 17:08:06 +0100 | [diff] [blame] | 1231 | void *kernel_address, u32 len, |
Oded Gabbay | 926ba4c | 2020-03-31 11:57:11 +0300 | [diff] [blame] | 1232 | u64 cq_addr, u32 cq_val, u32 msix_num, |
| 1233 | bool eb); |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 1234 | void (*update_eq_ci)(struct hl_device *hdev, u32 val); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1235 | int (*context_switch)(struct hl_device *hdev, u32 asid); |
| 1236 | void (*restore_phase_topology)(struct hl_device *hdev); |
Ofir Bitton | a5778d1 | 2021-02-24 11:51:40 +0200 | [diff] [blame] | 1237 | 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 Gabbay | 639781d | 2021-04-02 01:43:18 +0300 | [diff] [blame] | 1245 | int (*debugfs_read_dma)(struct hl_device *hdev, u64 addr, u32 size, |
| 1246 | void *blob_addr); |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 1247 | void (*add_device_attr)(struct hl_device *hdev, |
| 1248 | struct attribute_group *dev_attr_grp); |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 1249 | void (*handle_eqe)(struct hl_device *hdev, |
| 1250 | struct hl_eq_entry *eq_entry); |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 1251 | void (*set_pll_profile)(struct hl_device *hdev, |
| 1252 | enum hl_pll_frequency freq); |
Oded Gabbay | e973076 | 2019-08-28 21:51:52 +0300 | [diff] [blame] | 1253 | void* (*get_events_stat)(struct hl_device *hdev, bool aggregate, |
| 1254 | u32 *size); |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1255 | u64 (*read_pte)(struct hl_device *hdev, u64 addr); |
| 1256 | void (*write_pte)(struct hl_device *hdev, u64 addr, u64 val); |
Omer Shpigelman | 8ff5f4f | 2020-05-24 23:06:59 +0300 | [diff] [blame] | 1257 | int (*mmu_invalidate_cache)(struct hl_device *hdev, bool is_hard, |
Omer Shpigelman | 7b6e4ea | 2019-11-14 18:23:53 +0000 | [diff] [blame] | 1258 | u32 flags); |
Omer Shpigelman | 8ff5f4f | 2020-05-24 23:06:59 +0300 | [diff] [blame] | 1259 | int (*mmu_invalidate_cache_range)(struct hl_device *hdev, bool is_hard, |
Alon Mizrahi | 08c03a1 | 2021-04-08 15:30:59 +0300 | [diff] [blame] | 1260 | u32 flags, u32 asid, u64 va, u64 size); |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 1261 | int (*send_heartbeat)(struct hl_device *hdev); |
Oded Gabbay | e38bfd3 | 2020-07-03 20:46:12 +0300 | [diff] [blame] | 1262 | void (*set_clock_gating)(struct hl_device *hdev); |
Oded Gabbay | ca62433 | 2020-05-09 12:17:21 +0300 | [diff] [blame] | 1263 | void (*disable_clock_gating)(struct hl_device *hdev); |
Omer Shpigelman | 315bc05 | 2019-04-01 22:31:22 +0300 | [diff] [blame] | 1264 | int (*debug_coresight)(struct hl_device *hdev, void *data); |
Ohad Sharabi | cf30339 | 2021-01-17 16:01:56 +0200 | [diff] [blame] | 1265 | bool (*is_device_idle)(struct hl_device *hdev, u64 *mask_arr, |
| 1266 | u8 mask_len, struct seq_file *s); |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 1267 | int (*soft_reset_late_init)(struct hl_device *hdev); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1268 | void (*hw_queues_lock)(struct hl_device *hdev); |
| 1269 | void (*hw_queues_unlock)(struct hl_device *hdev); |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 1270 | u32 (*get_pci_id)(struct hl_device *hdev); |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 1271 | int (*get_eeprom_data)(struct hl_device *hdev, void *data, |
| 1272 | size_t max_size); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1273 | int (*send_cpu_message)(struct hl_device *hdev, u32 *msg, |
Alon Mizrahi | 439bc47 | 2020-11-10 13:49:10 +0200 | [diff] [blame] | 1274 | u16 len, u32 timeout, u64 *result); |
Tomer Tayar | b6f897d | 2019-03-05 16:48:42 +0200 | [diff] [blame] | 1275 | int (*pci_bars_map)(struct hl_device *hdev); |
Tomer Tayar | b6f897d | 2019-03-05 16:48:42 +0200 | [diff] [blame] | 1276 | int (*init_iatu)(struct hl_device *hdev); |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 1277 | u32 (*rreg)(struct hl_device *hdev, u32 reg); |
| 1278 | void (*wreg)(struct hl_device *hdev, u32 reg, u32 val); |
Omer Shpigelman | 89225ce | 2019-05-01 14:38:38 +0300 | [diff] [blame] | 1279 | void (*halt_coresight)(struct hl_device *hdev); |
Ofir Bitton | a04b7cd | 2020-07-13 13:36:55 +0300 | [diff] [blame] | 1280 | int (*ctx_init)(struct hl_ctx *ctx); |
Ofir Bitton | 5de406c | 2020-09-10 10:56:26 +0300 | [diff] [blame] | 1281 | void (*ctx_fini)(struct hl_ctx *ctx); |
Oded Gabbay | 62c1e12 | 2019-10-10 15:48:59 +0300 | [diff] [blame] | 1282 | int (*get_clk_rate)(struct hl_device *hdev, u32 *cur_clk, u32 *max_clk); |
Omer Shpigelman | 1fa185c | 2020-03-01 19:59:39 +0200 | [diff] [blame] | 1283 | u32 (*get_queue_id_for_cq)(struct hl_device *hdev, u32 cq_idx); |
Oded Gabbay | 7e1c07d | 2020-03-26 12:32:56 +0200 | [diff] [blame] | 1284 | int (*load_firmware_to_device)(struct hl_device *hdev); |
Ofir Bitton | 47f6b41 | 2020-04-16 13:47:15 +0300 | [diff] [blame] | 1285 | int (*load_boot_fit_to_device)(struct hl_device *hdev); |
Omer Shpigelman | ec2f8a3 | 2020-05-07 13:43:05 +0300 | [diff] [blame] | 1286 | u32 (*get_signal_cb_size)(struct hl_device *hdev); |
| 1287 | u32 (*get_wait_cb_size)(struct hl_device *hdev); |
Ofir Bitton | 2992c1d | 2020-09-10 09:40:35 +0300 | [diff] [blame] | 1288 | u32 (*gen_signal_cb)(struct hl_device *hdev, void *data, u16 sob_id, |
Alon Mizrahi | 72ab9ca5 | 2020-12-02 19:55:30 +0200 | [diff] [blame] | 1289 | u32 size, bool eb); |
Ofir Bitton | 2992c1d | 2020-09-10 09:40:35 +0300 | [diff] [blame] | 1290 | u32 (*gen_wait_cb)(struct hl_device *hdev, |
Ofir Bitton | 3cf74b3 | 2020-09-10 09:17:50 +0300 | [diff] [blame] | 1291 | struct hl_gen_wait_properties *prop); |
Omer Shpigelman | ec2f8a3 | 2020-05-07 13:43:05 +0300 | [diff] [blame] | 1292 | void (*reset_sob)(struct hl_device *hdev, void *data); |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 1293 | void (*reset_sob_group)(struct hl_device *hdev, u16 sob_group); |
Oded Gabbay | cb056b9 | 2020-03-29 13:18:30 +0300 | [diff] [blame] | 1294 | void (*set_dma_mask_from_fw)(struct hl_device *hdev); |
Tomer Tayar | 25e7aeb | 2020-03-31 22:46:36 +0300 | [diff] [blame] | 1295 | u64 (*get_device_time)(struct hl_device *hdev); |
farah kassabri | 8ca2072 | 2021-06-20 11:08:19 +0300 | [diff] [blame] | 1296 | int (*collective_wait_init_cs)(struct hl_cs *cs); |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 1297 | int (*collective_wait_create_jobs)(struct hl_device *hdev, |
farah kassabri | e4cdccd | 2021-05-26 10:43:36 +0300 | [diff] [blame] | 1298 | struct hl_ctx *ctx, struct hl_cs *cs, |
| 1299 | u32 wait_queue_id, u32 collective_engine_id, |
| 1300 | u32 encaps_signal_offset); |
farah kassabri | 89473a1 | 2021-01-12 17:24:00 +0200 | [diff] [blame] | 1301 | u64 (*scramble_addr)(struct hl_device *hdev, u64 addr); |
| 1302 | u64 (*descramble_addr)(struct hl_device *hdev, u64 addr); |
Ofir Bitton | d2b980f | 2021-01-07 12:14:17 +0200 | [diff] [blame] | 1303 | void (*ack_protection_bits_errors)(struct hl_device *hdev); |
Ofir Bitton | d00697f | 2021-01-05 12:55:06 +0200 | [diff] [blame] | 1304 | int (*get_hw_block_id)(struct hl_device *hdev, u64 block_addr, |
Oded Gabbay | 6df50d2 | 2021-02-05 16:04:34 +0200 | [diff] [blame] | 1305 | u32 *block_size, u32 *block_id); |
Ofir Bitton | d00697f | 2021-01-05 12:55:06 +0200 | [diff] [blame] | 1306 | int (*hw_block_mmap)(struct hl_device *hdev, struct vm_area_struct *vma, |
| 1307 | u32 block_id, u32 block_size); |
Oded Gabbay | 28bcf1f | 2021-02-01 21:23:43 +0200 | [diff] [blame] | 1308 | void (*enable_events_from_fw)(struct hl_device *hdev); |
Oded Gabbay | 90bd479 | 2021-04-23 15:57:39 +0300 | [diff] [blame] | 1309 | void (*get_msi_info)(__le32 *table); |
Bharat Jauhari | 285c0fa | 2021-03-25 18:15:40 +0200 | [diff] [blame] | 1310 | int (*map_pll_idx_to_fw_idx)(u32 pll_idx); |
Ohad Sharabi | a22f0ec | 2021-04-11 23:06:46 +0300 | [diff] [blame] | 1311 | void (*init_firmware_loader)(struct hl_device *hdev); |
Bharat Jauhari | 4b09901 | 2021-05-28 13:14:34 +0300 | [diff] [blame] | 1312 | void (*init_cpu_scrambler_dram)(struct hl_device *hdev); |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 1313 | void (*state_dump_init)(struct hl_device *hdev); |
farah kassabri | dadf17a | 2021-05-24 18:09:22 +0300 | [diff] [blame] | 1314 | u32 (*get_sob_addr)(struct hl_device *hdev, u32 sob_id); |
Ohad Sharabi | b9317d5 | 2021-07-15 15:20:44 +0300 | [diff] [blame] | 1315 | void (*set_pci_memory_regions)(struct hl_device *hdev); |
Ohad Sharabi | 72d6625 | 2021-08-01 23:02:07 +0300 | [diff] [blame] | 1316 | u32* (*get_stream_master_qid_arr)(void); |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 1317 | }; |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 1318 | |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 1319 | |
| 1320 | /* |
| 1321 | * CONTEXTS |
| 1322 | */ |
| 1323 | |
| 1324 | #define HL_KERNEL_ASID_ID 0 |
| 1325 | |
| 1326 | /** |
Ofir Bitton | 784b916 | 2020-10-22 11:05:55 +0300 | [diff] [blame] | 1327 | * 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 | */ |
| 1332 | enum 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 Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1340 | * 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 Bitton | 784b916 | 2020-10-22 11:05:55 +0300 | [diff] [blame] | 1345 | * @page_size: page size of this va range. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1346 | */ |
| 1347 | struct hl_va_range { |
| 1348 | struct mutex lock; |
| 1349 | struct list_head list; |
| 1350 | u64 start_addr; |
| 1351 | u64 end_addr; |
Ofir Bitton | 784b916 | 2020-10-22 11:05:55 +0300 | [diff] [blame] | 1352 | u32 page_size; |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1353 | }; |
| 1354 | |
| 1355 | /** |
farah kassabri | e753643 | 2020-10-12 14:30:26 +0300 | [diff] [blame] | 1356 | * 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 Mizrahi | a3fd283 | 2020-12-08 16:14:01 +0200 | [diff] [blame] | 1362 | * @validation_drop_cnt: dropped due to error in validation |
farah kassabri | e753643 | 2020-10-12 14:30:26 +0300 | [diff] [blame] | 1363 | */ |
| 1364 | struct 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 Mizrahi | a3fd283 | 2020-12-08 16:14:01 +0200 | [diff] [blame] | 1370 | atomic64_t validation_drop_cnt; |
farah kassabri | e753643 | 2020-10-12 14:30:26 +0300 | [diff] [blame] | 1371 | }; |
| 1372 | |
| 1373 | /** |
Tomer Tayar | db1a8dd | 2021-06-15 10:55:43 +0300 | [diff] [blame] | 1374 | * 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 | */ |
| 1383 | struct 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 Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 1391 | * struct hl_ctx - user/kernel context. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1392 | * @mem_hash: holds mapping from virtual address to virtual memory area |
| 1393 | * descriptor (hl_vm_phys_pg_list or hl_userptr). |
Omer Shpigelman | 66542c3 | 2019-02-24 09:17:55 +0200 | [diff] [blame] | 1394 | * @mmu_shadow_hash: holds a mapping from shadow address to pgt_info structure. |
Oded Gabbay | 4c172bb | 2019-08-30 16:59:33 +0300 | [diff] [blame] | 1395 | * @hpriv: pointer to the private (Kernel Driver) data of the process (fd). |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 1396 | * @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 Bitton | a98d73c | 2020-07-15 08:52:39 +0300 | [diff] [blame] | 1399 | * @cs_pending: array of hl fence objects representing pending CS. |
Ofir Bitton | 784b916 | 2020-10-22 11:05:55 +0300 | [diff] [blame] | 1400 | * @va_range: holds available virtual addresses for host and dram mappings. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1401 | * @mem_hash_lock: protects the mem_hash. |
Omer Shpigelman | 8ff5f4f | 2020-05-24 23:06:59 +0300 | [diff] [blame] | 1402 | * @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 Ozeri | a4371c1 | 2021-02-23 11:01:08 +0200 | [diff] [blame] | 1404 | * @hw_block_list_lock: protects the HW block memory list. |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1405 | * @debugfs_list: node in debugfs list of contexts. |
Sagiv Ozeri | a4371c1 | 2021-02-23 11:01:08 +0200 | [diff] [blame] | 1406 | * @hw_block_mem_list: list of HW block virtual mapped addresses. |
farah kassabri | e753643 | 2020-10-12 14:30:26 +0300 | [diff] [blame] | 1407 | * @cs_counters: context command submission counters. |
Tomer Tayar | ef6a0f6 | 2020-07-09 16:17:48 +0300 | [diff] [blame] | 1408 | * @cb_va_pool: device VA pool for command buffers which are mapped to the |
| 1409 | * device's MMU. |
farah kassabri | dadf17a | 2021-05-24 18:09:22 +0300 | [diff] [blame] | 1410 | * @sig_mgr: encaps signals handle manager. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1411 | * @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 Shpigelman | 27ca384c | 2019-02-28 10:46:11 +0200 | [diff] [blame] | 1414 | * @dram_default_hops: array that holds all hops addresses needed for default |
| 1415 | * DRAM mapping. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1416 | * @cs_lock: spinlock to protect cs_sequence. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1417 | * @dram_phys_mem: amount of used physical DRAM memory by this context. |
Oded Gabbay | 027d35d | 2019-04-25 20:15:42 +0300 | [diff] [blame] | 1418 | * @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 Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 1425 | * @asid: context's unique address space ID in the device's MMU. |
Oded Gabbay | b888751 | 2019-07-15 21:55:57 +0300 | [diff] [blame] | 1426 | * @handle: context's opaque handle for user |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 1427 | */ |
| 1428 | struct hl_ctx { |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1429 | DECLARE_HASHTABLE(mem_hash, MEM_HASH_TABLE_BITS); |
Omer Shpigelman | 66542c3 | 2019-02-24 09:17:55 +0200 | [diff] [blame] | 1430 | DECLARE_HASHTABLE(mmu_shadow_hash, MMU_HASH_TABLE_BITS); |
farah kassabri | e753643 | 2020-10-12 14:30:26 +0300 | [diff] [blame] | 1431 | struct hl_fpriv *hpriv; |
| 1432 | struct hl_device *hdev; |
| 1433 | struct kref refcount; |
| 1434 | struct hl_fence **cs_pending; |
Ofir Bitton | 784b916 | 2020-10-22 11:05:55 +0300 | [diff] [blame] | 1435 | struct hl_va_range *va_range[HL_VA_RANGE_TYPE_MAX]; |
farah kassabri | e753643 | 2020-10-12 14:30:26 +0300 | [diff] [blame] | 1436 | struct mutex mem_hash_lock; |
| 1437 | struct mutex mmu_lock; |
Sagiv Ozeri | a4371c1 | 2021-02-23 11:01:08 +0200 | [diff] [blame] | 1438 | struct mutex hw_block_list_lock; |
farah kassabri | e753643 | 2020-10-12 14:30:26 +0300 | [diff] [blame] | 1439 | struct list_head debugfs_list; |
Sagiv Ozeri | a4371c1 | 2021-02-23 11:01:08 +0200 | [diff] [blame] | 1440 | struct list_head hw_block_mem_list; |
farah kassabri | e753643 | 2020-10-12 14:30:26 +0300 | [diff] [blame] | 1441 | struct hl_cs_counters_atomic cs_counters; |
| 1442 | struct gen_pool *cb_va_pool; |
farah kassabri | dadf17a | 2021-05-24 18:09:22 +0300 | [diff] [blame] | 1443 | struct hl_encaps_signals_mgr sig_mgr; |
farah kassabri | e753643 | 2020-10-12 14:30:26 +0300 | [diff] [blame] | 1444 | 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 Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 1452 | }; |
| 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 | */ |
| 1459 | struct hl_ctx_mgr { |
| 1460 | struct mutex ctx_lock; |
| 1461 | struct idr ctx_handles; |
| 1462 | }; |
| 1463 | |
| 1464 | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1465 | |
| 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 Vetter | d4cb192 | 2020-11-27 17:41:17 +0100 | [diff] [blame] | 1474 | * @pages: pointer to struct page array |
| 1475 | * @npages: size of @pages array |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1476 | * @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 Nudelman | 714fccb | 2021-07-27 17:39:42 +0300 | [diff] [blame] | 1479 | * @pid: the pid of the user process owning the memory |
Omer Shpigelman | 7f74d4d | 2019-08-12 11:48:46 +0300 | [diff] [blame] | 1480 | * @addr: user-space virtual address of the start of the memory area. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1481 | * @size: size of the memory area to pin & map. |
| 1482 | * @dma_mapped: true if the SG was mapped to DMA addresses, false otherwise. |
| 1483 | */ |
| 1484 | struct hl_userptr { |
Oded Gabbay | 82629c7 | 2021-06-29 18:08:05 +0300 | [diff] [blame] | 1485 | enum vm_type vm_type; /* must be first */ |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1486 | struct list_head job_node; |
Daniel Vetter | d4cb192 | 2020-11-27 17:41:17 +0100 | [diff] [blame] | 1487 | struct page **pages; |
| 1488 | unsigned int npages; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1489 | struct sg_table *sgt; |
| 1490 | enum dma_data_direction dir; |
| 1491 | struct list_head debugfs_list; |
Yuri Nudelman | 714fccb | 2021-07-27 17:39:42 +0300 | [diff] [blame] | 1492 | pid_t pid; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1493 | u64 addr; |
Oded Gabbay | 00ce065 | 2021-06-29 18:12:46 +0300 | [diff] [blame] | 1494 | u64 size; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1495 | 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 Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 1506 | * @signal_fence: pointer to the fence object of the signal CS (used by wait |
| 1507 | * CS only). |
Omer Shpigelman | b75f225 | 2020-05-07 14:31:49 +0300 | [diff] [blame] | 1508 | * @finish_work: workqueue object to run when CS is completed by H/W. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1509 | * @work_tdr: delayed work node for TDR. |
| 1510 | * @mirror_node : node in device mirror list of command submissions. |
Ofir Bitton | 2795c88 | 2020-12-08 13:47:05 +0200 | [diff] [blame] | 1511 | * @staged_cs_node: node in the staged cs list. |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1512 | * @debugfs_list: node in debugfs list of command submissions. |
farah kassabri | e4cdccd | 2021-05-26 10:43:36 +0300 | [diff] [blame] | 1513 | * @encaps_sig_hdl: holds the encaps signals handle. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1514 | * @sequence: the sequence number of this CS. |
Ofir Bitton | 2795c88 | 2020-12-08 13:47:05 +0200 | [diff] [blame] | 1515 | * @staged_sequence: the sequence of the staged submission this CS is part of, |
| 1516 | * relevant only if staged_cs is set. |
Alon Mizrahi | cf39395 | 2021-02-22 15:53:24 +0200 | [diff] [blame] | 1517 | * @timeout_jiffies: cs timeout in jiffies. |
Yuri Nudelman | 8e8125f | 2021-05-25 14:49:52 +0300 | [diff] [blame] | 1518 | * @submission_time_jiffies: submission time of the cs |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 1519 | * @type: CS_TYPE_*. |
farah kassabri | e4cdccd | 2021-05-26 10:43:36 +0300 | [diff] [blame] | 1520 | * @encaps_sig_hdl_id: encaps signals handle id, set for the first staged cs. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1521 | * @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 Bitton | 0811b39 | 2020-12-06 17:18:02 +0200 | [diff] [blame] | 1527 | * @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 Nudelman | 8e8125f | 2021-05-25 14:49:52 +0300 | [diff] [blame] | 1532 | * @skip_reset_on_timeout: true if we shall not reset the device in case |
| 1533 | * timeout occurs (debug scenario). |
farah kassabri | e4cdccd | 2021-05-26 10:43:36 +0300 | [diff] [blame] | 1534 | * @encaps_signals: true if this CS has encaps reserved signals. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1535 | */ |
| 1536 | struct hl_cs { |
Ofir Bitton | 3abc99b | 2020-06-23 14:50:39 +0300 | [diff] [blame] | 1537 | u16 *jobs_in_queue_cnt; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1538 | struct hl_ctx *ctx; |
| 1539 | struct list_head job_list; |
| 1540 | spinlock_t job_lock; |
| 1541 | struct kref refcount; |
Ofir Bitton | a98d73c | 2020-07-15 08:52:39 +0300 | [diff] [blame] | 1542 | struct hl_fence *fence; |
| 1543 | struct hl_fence *signal_fence; |
Omer Shpigelman | b75f225 | 2020-05-07 14:31:49 +0300 | [diff] [blame] | 1544 | struct work_struct finish_work; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1545 | struct delayed_work work_tdr; |
| 1546 | struct list_head mirror_node; |
Ofir Bitton | 2795c88 | 2020-12-08 13:47:05 +0200 | [diff] [blame] | 1547 | struct list_head staged_cs_node; |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1548 | struct list_head debugfs_list; |
farah kassabri | e4cdccd | 2021-05-26 10:43:36 +0300 | [diff] [blame] | 1549 | struct hl_cs_encaps_sig_handle *encaps_sig_hdl; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1550 | u64 sequence; |
Ofir Bitton | 2795c88 | 2020-12-08 13:47:05 +0200 | [diff] [blame] | 1551 | u64 staged_sequence; |
Alon Mizrahi | cf39395 | 2021-02-22 15:53:24 +0200 | [diff] [blame] | 1552 | u64 timeout_jiffies; |
Yuri Nudelman | 8e8125f | 2021-05-25 14:49:52 +0300 | [diff] [blame] | 1553 | u64 submission_time_jiffies; |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 1554 | enum hl_cs_type type; |
farah kassabri | e4cdccd | 2021-05-26 10:43:36 +0300 | [diff] [blame] | 1555 | u32 encaps_sig_hdl_id; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1556 | u8 submitted; |
| 1557 | u8 completed; |
| 1558 | u8 timedout; |
| 1559 | u8 tdr_active; |
| 1560 | u8 aborted; |
Ofir Bitton | bd2f477 | 2020-11-10 17:26:22 +0200 | [diff] [blame] | 1561 | u8 timestamp; |
Ofir Bitton | 0811b39 | 2020-12-06 17:18:02 +0200 | [diff] [blame] | 1562 | u8 staged_last; |
| 1563 | u8 staged_first; |
| 1564 | u8 staged_cs; |
Yuri Nudelman | 8e8125f | 2021-05-25 14:49:52 +0300 | [diff] [blame] | 1565 | u8 skip_reset_on_timeout; |
farah kassabri | e4cdccd | 2021-05-26 10:43:36 +0300 | [diff] [blame] | 1566 | u8 encaps_signals; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1567 | }; |
| 1568 | |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1569 | /** |
| 1570 | * struct hl_cs_job - command submission job. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1571 | * @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 Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1576 | * @finish_work: workqueue object to run when job is completed. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1577 | * @userptr_list: linked-list of userptr mappings that belong to this job and |
| 1578 | * wait for completion. |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1579 | * @debugfs_list: node in debugfs list of command submission jobs. |
Tomer Tayar | 649c459 | 2020-08-10 17:30:35 +0300 | [diff] [blame] | 1580 | * @refcount: reference counter for usage of the CS job. |
Tomer Tayar | cb596ae | 2019-10-03 15:22:36 +0000 | [diff] [blame] | 1581 | * @queue_type: the type of the H/W queue this job is submitted to. |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1582 | * @id: the id of this job inside a CS. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1583 | * @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 kassabri | e4cdccd | 2021-05-26 10:43:36 +0300 | [diff] [blame] | 1586 | * @encaps_sig_wait_offset: encapsulated signals offset, which allow user |
| 1587 | * to wait on part of the reserved signals. |
Tomer Tayar | cb596ae | 2019-10-03 15:22:36 +0000 | [diff] [blame] | 1588 | * @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 Gabbay | 926ba4c | 2020-03-31 11:57:11 +0300 | [diff] [blame] | 1591 | * @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 Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1597 | */ |
| 1598 | struct hl_cs_job { |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1599 | struct list_head cs_node; |
| 1600 | struct hl_cs *cs; |
| 1601 | struct hl_cb *user_cb; |
| 1602 | struct hl_cb *patched_cb; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1603 | struct work_struct finish_work; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1604 | struct list_head userptr_list; |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1605 | struct list_head debugfs_list; |
Tomer Tayar | 649c459 | 2020-08-10 17:30:35 +0300 | [diff] [blame] | 1606 | struct kref refcount; |
Tomer Tayar | cb596ae | 2019-10-03 15:22:36 +0000 | [diff] [blame] | 1607 | enum hl_queue_type queue_type; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1608 | u32 id; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1609 | u32 hw_queue_id; |
| 1610 | u32 user_cb_size; |
| 1611 | u32 job_cb_size; |
farah kassabri | e4cdccd | 2021-05-26 10:43:36 +0300 | [diff] [blame] | 1612 | u32 encaps_sig_wait_offset; |
Tomer Tayar | cb596ae | 2019-10-03 15:22:36 +0000 | [diff] [blame] | 1613 | u8 is_kernel_allocated_cb; |
Oded Gabbay | 926ba4c | 2020-03-31 11:57:11 +0300 | [diff] [blame] | 1614 | u8 contains_dma_pkt; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1615 | }; |
| 1616 | |
| 1617 | /** |
Tomer Tayar | f435614 | 2019-10-02 13:53:52 +0000 | [diff] [blame] | 1618 | * struct hl_cs_parser - command submission parser properties. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1619 | * @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 Tayar | cb596ae | 2019-10-03 15:22:36 +0000 | [diff] [blame] | 1625 | * @queue_type: the type of the H/W queue this job is submitted to. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1626 | * @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 Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1630 | * @job_id: the id of the related job inside the related CS. |
Tomer Tayar | cb596ae | 2019-10-03 15:22:36 +0000 | [diff] [blame] | 1631 | * @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 Gabbay | 926ba4c | 2020-03-31 11:57:11 +0300 | [diff] [blame] | 1634 | * @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 Bitton | ac6fdbf | 2020-12-03 16:59:28 +0200 | [diff] [blame] | 1640 | * @completion: true if we need completion for this CS. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1641 | */ |
| 1642 | struct 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 Tayar | cb596ae | 2019-10-03 15:22:36 +0000 | [diff] [blame] | 1647 | enum hl_queue_type queue_type; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1648 | u32 ctx_id; |
| 1649 | u32 hw_queue_id; |
| 1650 | u32 user_cb_size; |
| 1651 | u32 patched_cb_size; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1652 | u8 job_id; |
Tomer Tayar | cb596ae | 2019-10-03 15:22:36 +0000 | [diff] [blame] | 1653 | u8 is_kernel_allocated_cb; |
Oded Gabbay | 926ba4c | 2020-03-31 11:57:11 +0300 | [diff] [blame] | 1654 | u8 contains_dma_pkt; |
Ofir Bitton | ac6fdbf | 2020-12-03 16:59:28 +0200 | [diff] [blame] | 1655 | u8 completion; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1656 | }; |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 1657 | |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 1658 | /* |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1659 | * 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 | */ |
| 1670 | struct hl_vm_hash_node { |
| 1671 | struct hlist_node node; |
| 1672 | u64 vaddr; |
| 1673 | void *ptr; |
| 1674 | }; |
| 1675 | |
| 1676 | /** |
Sagiv Ozeri | a4371c1 | 2021-02-23 11:01:08 +0200 | [diff] [blame] | 1677 | * 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 | */ |
| 1685 | struct 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 Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1694 | * 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 Shpigelman | bfb1ce1 | 2019-03-05 10:59:16 +0200 | [diff] [blame] | 1697 | * @npages: num physical pages in the pack. |
| 1698 | * @total_size: total size of all the pages in this list. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1699 | * @mapping_cnt: number of shared mappings. |
Tomer Tayar | db1a8dd | 2021-06-15 10:55:43 +0300 | [diff] [blame] | 1700 | * @exporting_cnt: number of dma-buf exporting. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1701 | * @asid: the context related to this list. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1702 | * @page_size: size of each page in the pack. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1703 | * @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 | */ |
| 1709 | struct hl_vm_phys_pg_pack { |
Oded Gabbay | 82629c7 | 2021-06-29 18:08:05 +0300 | [diff] [blame] | 1710 | enum vm_type vm_type; /* must be first */ |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1711 | u64 *pages; |
Omer Shpigelman | bfb1ce1 | 2019-03-05 10:59:16 +0200 | [diff] [blame] | 1712 | u64 npages; |
| 1713 | u64 total_size; |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1714 | atomic_t mapping_cnt; |
Tomer Tayar | db1a8dd | 2021-06-15 10:55:43 +0300 | [diff] [blame] | 1715 | u32 exporting_cnt; |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1716 | u32 asid; |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1717 | u32 page_size; |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1718 | 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 | */ |
| 1732 | struct 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 | */ |
| 1748 | struct 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 Shpigelman | 315bc05 | 2019-04-01 22:31:22 +0300 | [diff] [blame] | 1756 | |
| 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 | */ |
| 1770 | struct 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 Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1779 | /* |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 1780 | * 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 Gabbay | 86d5307 | 2019-07-30 11:49:36 +0300 | [diff] [blame] | 1788 | * @ctx: current executing context. TODO: remove for multiple ctx per process |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 1789 | * @ctx_mgr: context manager to handle multiple context for this FD. |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 1790 | * @cb_mgr: command buffer manager to handle multiple buffers for this FD. |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1791 | * @debugfs_list: list of relevant ASIC debugfs. |
Oded Gabbay | eb7caf8 | 2019-07-30 11:56:09 +0300 | [diff] [blame] | 1792 | * @dev_node: node in the device list of file private data |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 1793 | * @refcount: number of related contexts. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1794 | * @restore_phase_mutex: lock for context switch and restore phase. |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 1795 | * @is_control: true for control device, false otherwise |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 1796 | */ |
| 1797 | struct hl_fpriv { |
| 1798 | struct hl_device *hdev; |
| 1799 | struct file *filp; |
| 1800 | struct pid *taskpid; |
Oded Gabbay | 86d5307 | 2019-07-30 11:49:36 +0300 | [diff] [blame] | 1801 | struct hl_ctx *ctx; |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 1802 | struct hl_ctx_mgr ctx_mgr; |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 1803 | struct hl_cb_mgr cb_mgr; |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1804 | struct list_head debugfs_list; |
Oded Gabbay | eb7caf8 | 2019-07-30 11:56:09 +0300 | [diff] [blame] | 1805 | struct list_head dev_node; |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 1806 | struct kref refcount; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1807 | struct mutex restore_phase_mutex; |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 1808 | u8 is_control; |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 1809 | }; |
| 1810 | |
| 1811 | |
| 1812 | /* |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1813 | * 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 | */ |
| 1822 | struct 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 Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1831 | * @info_ent: dentry realted ops. |
| 1832 | * @dev_entry: ASIC specific debugfs manager. |
| 1833 | */ |
| 1834 | struct hl_debugfs_entry { |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1835 | 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 Gabbay | 639781d | 2021-04-02 01:43:18 +0300 | [diff] [blame] | 1856 | * @blob_desc: descriptor of blob |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 1857 | * @state_dump: data of the system states in case of a bad cs. |
| 1858 | * @state_dump_sem: protects state_dump. |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1859 | * @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 Nudelman | 89b2136 | 2021-07-29 11:44:28 +0300 | [diff] [blame] | 1861 | * @userptr_lookup: the target user ptr to look up for on demand. |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1862 | * @mmu_asid: ASID to use while translating in mmu_show. |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 1863 | * @state_dump_head: index of the latest state dump |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1864 | * @i2c_bus: generic u8 debugfs file for bus value to use in i2c_data_read. |
Oded Gabbay | 639781d | 2021-04-02 01:43:18 +0300 | [diff] [blame] | 1865 | * @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 Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1867 | */ |
| 1868 | struct 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 Gabbay | 639781d | 2021-04-02 01:43:18 +0300 | [diff] [blame] | 1884 | struct debugfs_blob_wrapper blob_desc; |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 1885 | char *state_dump[HL_STATE_DUMP_HIST_LEN]; |
| 1886 | struct rw_semaphore state_dump_sem; |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1887 | u64 addr; |
| 1888 | u64 mmu_addr; |
Yuri Nudelman | 89b2136 | 2021-07-29 11:44:28 +0300 | [diff] [blame] | 1889 | u64 userptr_lookup; |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1890 | u32 mmu_asid; |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 1891 | u32 state_dump_head; |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1892 | u8 i2c_bus; |
| 1893 | u8 i2c_addr; |
| 1894 | u8 i2c_reg; |
| 1895 | }; |
| 1896 | |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 1897 | /** |
| 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 | */ |
| 1904 | struct hl_hw_obj_name_entry { |
| 1905 | struct hlist_node node; |
| 1906 | const char *name; |
| 1907 | u32 id; |
| 1908 | }; |
| 1909 | |
| 1910 | enum 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 | |
| 1944 | enum hl_sync_engine_type { |
| 1945 | ENGINE_TPC, |
| 1946 | ENGINE_DMA, |
| 1947 | ENGINE_MME, |
| 1948 | }; |
| 1949 | |
| 1950 | /** |
Yuri Nudelman | fd2010b | 2021-06-09 14:04:26 +0300 | [diff] [blame] | 1951 | * 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 | */ |
| 1959 | struct 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 Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 1969 | * 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 | */ |
| 1974 | struct 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 | */ |
| 1986 | struct 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 Nudelman | fd2010b | 2021-06-09 14:04:26 +0300 | [diff] [blame] | 1993 | * @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 Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 1996 | */ |
| 1997 | struct 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 Nudelman | fd2010b | 2021-06-09 14:04:26 +0300 | [diff] [blame] | 2000 | 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 Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 2010 | }; |
| 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 | */ |
| 2020 | struct 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 Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 2028 | |
| 2029 | /* |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2030 | * DEVICES |
| 2031 | */ |
| 2032 | |
Ofir Bitton | 66a7640 | 2020-10-05 14:40:10 +0300 | [diff] [blame] | 2033 | #define HL_STR_MAX 32 |
| 2034 | |
Omer Shpigelman | 7173109 | 2021-08-16 13:27:12 +0300 | [diff] [blame] | 2035 | #define HL_DEV_STS_MAX (HL_DEVICE_STATUS_LAST + 1) |
Ofir Bitton | 66a7640 | 2020-10-05 14:40:10 +0300 | [diff] [blame] | 2036 | |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2037 | /* Theoretical limit only. A single host can only contain up to 4 or 8 PCIe |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 2038 | * x16 cards. In extreme cases, there are hosts that can accommodate 16 cards. |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2039 | */ |
| 2040 | #define HL_MAX_MINORS 256 |
| 2041 | |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2042 | /* |
| 2043 | * Registers read & write functions. |
| 2044 | */ |
| 2045 | |
| 2046 | u32 hl_rreg(struct hl_device *hdev, u32 reg); |
| 2047 | void hl_wreg(struct hl_device *hdev, u32 reg, u32 val); |
| 2048 | |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 2049 | #define RREG32(reg) hdev->asic_funcs->rreg(hdev, (reg)) |
| 2050 | #define WREG32(reg, v) hdev->asic_funcs->wreg(hdev, (reg), (v)) |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2051 | #define DREG32(reg) pr_info("REGISTER: " #reg " : 0x%08X\n", \ |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 2052 | hdev->asic_funcs->rreg(hdev, (reg))) |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2053 | |
| 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 Gabbay | ac0ae6a | 2020-05-11 10:29:27 +0300 | [diff] [blame] | 2064 | #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 Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2074 | #define REG_FIELD_SHIFT(reg, field) reg##_##field##_SHIFT |
| 2075 | #define REG_FIELD_MASK(reg, field) reg##_##field##_MASK |
Oded Gabbay | 8fdacf2 | 2019-10-02 14:14:08 +0300 | [diff] [blame] | 2076 | #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 Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2080 | |
Oded Gabbay | ed0fc50 | 2019-07-18 11:14:37 +0300 | [diff] [blame] | 2081 | /* Timeout should be longer when working with simulator but cap the |
| 2082 | * increased timeout to some maximum |
| 2083 | */ |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 2084 | #define hl_poll_timeout(hdev, addr, val, cond, sleep_us, timeout_us) \ |
| 2085 | ({ \ |
Dalit Ben Zoor | b1b5377 | 2019-04-30 17:18:51 +0300 | [diff] [blame] | 2086 | ktime_t __timeout; \ |
Dalit Ben Zoor | b1b5377 | 2019-04-30 17:18:51 +0300 | [diff] [blame] | 2087 | if (hdev->pdev) \ |
| 2088 | __timeout = ktime_add_us(ktime_get(), timeout_us); \ |
| 2089 | else \ |
Oded Gabbay | ed0fc50 | 2019-07-18 11:14:37 +0300 | [diff] [blame] | 2090 | __timeout = ktime_add_us(ktime_get(),\ |
| 2091 | min((u64)(timeout_us * 10), \ |
| 2092 | (u64) HL_SIM_MAX_TIMEOUT_US)); \ |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 2093 | 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 Gabbay | a08b51a | 2019-05-09 01:48:23 +0300 | [diff] [blame] | 2108 | /* |
| 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 Segal | 2aa4e41 | 2019-07-18 12:27:00 +0000 | [diff] [blame] | 2111 | * 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 Gabbay | a08b51a | 2019-05-09 01:48:23 +0300 | [diff] [blame] | 2119 | */ |
Ben Segal | 2aa4e41 | 2019-07-18 12:27:00 +0000 | [diff] [blame] | 2120 | #define hl_poll_timeout_memory(hdev, addr, val, cond, sleep_us, timeout_us, \ |
| 2121 | mem_written_by_device) \ |
Oded Gabbay | a08b51a | 2019-05-09 01:48:23 +0300 | [diff] [blame] | 2122 | ({ \ |
| 2123 | ktime_t __timeout; \ |
Oded Gabbay | a08b51a | 2019-05-09 01:48:23 +0300 | [diff] [blame] | 2124 | if (hdev->pdev) \ |
| 2125 | __timeout = ktime_add_us(ktime_get(), timeout_us); \ |
| 2126 | else \ |
Oded Gabbay | ed0fc50 | 2019-07-18 11:14:37 +0300 | [diff] [blame] | 2127 | __timeout = ktime_add_us(ktime_get(),\ |
| 2128 | min((u64)(timeout_us * 10), \ |
| 2129 | (u64) HL_SIM_MAX_TIMEOUT_US)); \ |
Oded Gabbay | a08b51a | 2019-05-09 01:48:23 +0300 | [diff] [blame] | 2130 | might_sleep_if(sleep_us); \ |
| 2131 | for (;;) { \ |
| 2132 | /* Verify we read updates done by other cores or by device */ \ |
| 2133 | mb(); \ |
Arnd Bergmann | 82948e6 | 2020-10-26 17:08:06 +0100 | [diff] [blame] | 2134 | (val) = *((u32 *)(addr)); \ |
Ben Segal | 2aa4e41 | 2019-07-18 12:27:00 +0000 | [diff] [blame] | 2135 | if (mem_written_by_device) \ |
Oded Gabbay | 6dc66f7 | 2019-09-03 11:33:55 +0300 | [diff] [blame] | 2136 | (val) = le32_to_cpu(*(__le32 *) &(val)); \ |
Oded Gabbay | a08b51a | 2019-05-09 01:48:23 +0300 | [diff] [blame] | 2137 | if (cond) \ |
| 2138 | break; \ |
| 2139 | if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) { \ |
Arnd Bergmann | 82948e6 | 2020-10-26 17:08:06 +0100 | [diff] [blame] | 2140 | (val) = *((u32 *)(addr)); \ |
Ben Segal | 2aa4e41 | 2019-07-18 12:27:00 +0000 | [diff] [blame] | 2141 | if (mem_written_by_device) \ |
Oded Gabbay | 6dc66f7 | 2019-09-03 11:33:55 +0300 | [diff] [blame] | 2142 | (val) = le32_to_cpu(*(__le32 *) &(val)); \ |
Oded Gabbay | a08b51a | 2019-05-09 01:48:23 +0300 | [diff] [blame] | 2143 | 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 Gabbay | a08b51a | 2019-05-09 01:48:23 +0300 | [diff] [blame] | 2155 | if (hdev->pdev) \ |
| 2156 | __timeout = ktime_add_us(ktime_get(), timeout_us); \ |
| 2157 | else \ |
Oded Gabbay | ed0fc50 | 2019-07-18 11:14:37 +0300 | [diff] [blame] | 2158 | __timeout = ktime_add_us(ktime_get(),\ |
| 2159 | min((u64)(timeout_us * 10), \ |
| 2160 | (u64) HL_SIM_MAX_TIMEOUT_US)); \ |
Oded Gabbay | a08b51a | 2019-05-09 01:48:23 +0300 | [diff] [blame] | 2161 | 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 Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 2175 | |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2176 | struct hwmon_chip_info; |
| 2177 | |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2178 | /** |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2179 | * struct hl_device_reset_work - reset workqueue task wrapper. |
Ofir Bitton | adb5129 | 2020-10-08 10:27:42 +0300 | [diff] [blame] | 2180 | * @wq: work queue for device reset procedure. |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2181 | * @reset_work: reset work to be done. |
| 2182 | * @hdev: habanalabs device structure. |
Oded Gabbay | 8d9aa98 | 2021-08-09 22:43:37 +0300 | [diff] [blame] | 2183 | * @fw_reset: whether f/w will do the reset without us sending them a message to do it. |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2184 | */ |
| 2185 | struct hl_device_reset_work { |
Ofir Bitton | adb5129 | 2020-10-08 10:27:42 +0300 | [diff] [blame] | 2186 | struct workqueue_struct *wq; |
| 2187 | struct delayed_work reset_work; |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2188 | struct hl_device *hdev; |
Oded Gabbay | 8d9aa98 | 2021-08-09 22:43:37 +0300 | [diff] [blame] | 2189 | bool fw_reset; |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2190 | }; |
| 2191 | |
| 2192 | /** |
Moti Haimovski | ccf979e | 2020-10-05 17:59:29 +0300 | [diff] [blame] | 2193 | * 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 | */ |
| 2199 | struct hr_mmu_hop_addrs { |
| 2200 | u64 virt_addr; |
| 2201 | u64 phys_addr; |
| 2202 | u64 shadow_addr; |
| 2203 | }; |
Moti Haimovski | d83fe66 | 2020-08-12 13:33:44 +0300 | [diff] [blame] | 2204 | |
| 2205 | /** |
Moti Haimovski | ccf979e | 2020-10-05 17:59:29 +0300 | [diff] [blame] | 2206 | * struct hl_mmu_hr_pgt_priv - used for holding per-device mmu host-resident |
| 2207 | * page-table internal information. |
Moti Haimovski | d83fe66 | 2020-08-12 13:33:44 +0300 | [diff] [blame] | 2208 | * @mmu_pgt_pool: pool of page tables used by MMU for allocating hops. |
| 2209 | * @mmu_shadow_hop0: shadow array of hop0 tables. |
| 2210 | */ |
Moti Haimovski | ccf979e | 2020-10-05 17:59:29 +0300 | [diff] [blame] | 2211 | struct 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 | */ |
| 2222 | struct hl_mmu_dr_priv { |
Moti Haimovski | d83fe66 | 2020-08-12 13:33:44 +0300 | [diff] [blame] | 2223 | struct gen_pool *mmu_pgt_pool; |
| 2224 | void *mmu_shadow_hop0; |
| 2225 | }; |
| 2226 | |
| 2227 | /** |
Moti Haimovski | ccf979e | 2020-10-05 17:59:29 +0300 | [diff] [blame] | 2228 | * 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 | */ |
| 2232 | struct hl_mmu_priv { |
| 2233 | struct hl_mmu_dr_priv dr; |
| 2234 | struct hl_mmu_hr_priv hr; |
| 2235 | }; |
| 2236 | |
| 2237 | /** |
Moti Haimovski | 00e1b59 | 2020-10-27 10:55:42 +0200 | [diff] [blame] | 2238 | * 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 | */ |
| 2245 | struct 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 Haimovski | b19dc67 | 2020-11-18 20:15:29 +0200 | [diff] [blame] | 2255 | * @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 kassabri | 89473a1 | 2021-01-12 17:24:00 +0200 | [diff] [blame] | 2258 | * @unscrambled_paddr: The un-scrambled physical address. |
Moti Haimovski | 00e1b59 | 2020-10-27 10:55:42 +0200 | [diff] [blame] | 2259 | * @hop_info: Array holding the per-hop information used for the translation. |
| 2260 | * @used_hops: The number of hops used for the translation. |
farah kassabri | 89473a1 | 2021-01-12 17:24:00 +0200 | [diff] [blame] | 2261 | * @range_type: virtual address range type. |
Moti Haimovski | 00e1b59 | 2020-10-27 10:55:42 +0200 | [diff] [blame] | 2262 | */ |
| 2263 | struct hl_mmu_hop_info { |
Moti Haimovski | b19dc67 | 2020-11-18 20:15:29 +0200 | [diff] [blame] | 2264 | u64 scrambled_vaddr; |
farah kassabri | 89473a1 | 2021-01-12 17:24:00 +0200 | [diff] [blame] | 2265 | u64 unscrambled_paddr; |
Moti Haimovski | 00e1b59 | 2020-10-27 10:55:42 +0200 | [diff] [blame] | 2266 | struct hl_mmu_per_hop_info hop_info[MMU_ARCH_5_HOPS]; |
| 2267 | u32 used_hops; |
farah kassabri | 89473a1 | 2021-01-12 17:24:00 +0200 | [diff] [blame] | 2268 | enum hl_va_range_type range_type; |
Moti Haimovski | 00e1b59 | 2020-10-27 10:55:42 +0200 | [diff] [blame] | 2269 | }; |
| 2270 | |
| 2271 | /** |
Moti Haimovski | d83fe66 | 2020-08-12 13:33:44 +0300 | [diff] [blame] | 2272 | * 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 Haimovski | 00e1b59 | 2020-10-27 10:55:42 +0200 | [diff] [blame] | 2282 | * @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 Haimovski | d83fe66 | 2020-08-12 13:33:44 +0300 | [diff] [blame] | 2285 | */ |
| 2286 | struct 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 Haimovski | 00e1b59 | 2020-10-27 10:55:42 +0200 | [diff] [blame] | 2299 | int (*get_tlb_info)(struct hl_ctx *ctx, |
| 2300 | u64 virt_addr, struct hl_mmu_hop_info *hops); |
Moti Haimovski | d83fe66 | 2020-08-12 13:33:44 +0300 | [diff] [blame] | 2301 | }; |
| 2302 | |
Oded Gabbay | 75b3cb2 | 2019-08-28 17:32:04 +0300 | [diff] [blame] | 2303 | /** |
Ohad Sharabi | 215f0c1 | 2021-06-14 22:18:41 +0300 | [diff] [blame] | 2304 | * 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 Sharabi | 72d6625 | 2021-08-01 23:02:07 +0300 | [diff] [blame] | 2314 | * @stream_master_qid_map: bitmap of all stream masters on which the multi-CS |
| 2315 | * is waiting |
Ohad Sharabi | 215f0c1 | 2021-06-14 22:18:41 +0300 | [diff] [blame] | 2316 | * @used: 1 if in use, otherwise 0 |
Ohad Sharabi | 215f0c1 | 2021-06-14 22:18:41 +0300 | [diff] [blame] | 2317 | */ |
| 2318 | struct multi_cs_completion { |
| 2319 | struct completion completion; |
| 2320 | spinlock_t lock; |
| 2321 | s64 timestamp; |
Ohad Sharabi | 72d6625 | 2021-08-01 23:02:07 +0300 | [diff] [blame] | 2322 | u32 stream_master_qid_map; |
Ohad Sharabi | 215f0c1 | 2021-06-14 22:18:41 +0300 | [diff] [blame] | 2323 | u8 used; |
Ohad Sharabi | 215f0c1 | 2021-06-14 22:18:41 +0300 | [diff] [blame] | 2324 | }; |
| 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 Sharabi | 72d6625 | 2021-08-01 23:02:07 +0300 | [diff] [blame] | 2335 | * @stream_master_qid_map: bitmap of all stream master QIDs on which the |
| 2336 | * multi-CS is waiting |
Ohad Sharabi | 215f0c1 | 2021-06-14 22:18:41 +0300 | [diff] [blame] | 2337 | * @arr_len: fence_arr and seq_arr array length |
Ohad Sharabi | 215f0c1 | 2021-06-14 22:18:41 +0300 | [diff] [blame] | 2338 | * @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 | */ |
| 2341 | struct 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 Sharabi | 72d6625 | 2021-08-01 23:02:07 +0300 | [diff] [blame] | 2349 | u32 stream_master_qid_map; |
Ohad Sharabi | 215f0c1 | 2021-06-14 22:18:41 +0300 | [diff] [blame] | 2350 | u8 arr_len; |
Ohad Sharabi | 215f0c1 | 2021-06-14 22:18:41 +0300 | [diff] [blame] | 2351 | u8 gone_cs; |
| 2352 | u8 update_ts; |
| 2353 | }; |
| 2354 | |
| 2355 | /** |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2356 | * struct hl_device - habanalabs device structure. |
| 2357 | * @pdev: pointer to PCI device, can be NULL in case of simulator device. |
Ofir Bitton | f4cbfd2 | 2020-06-15 17:45:12 +0300 | [diff] [blame] | 2358 | * @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 Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2361 | * @rmmio: configuration area address on SRAM. |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2362 | * @cdev: related char device. |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 2363 | * @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 Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2366 | * @work_freq: delayed work to lower device frequency if possible. |
Oded Gabbay | 6138bbe | 2020-09-04 20:18:16 +0300 | [diff] [blame] | 2367 | * @work_heartbeat: delayed work for CPU-CP is-alive check. |
Ofir Bitton | adb5129 | 2020-10-08 10:27:42 +0300 | [diff] [blame] | 2368 | * @device_reset_work: delayed work which performs hard reset |
Oded Gabbay | 6138bbe | 2020-09-04 20:18:16 +0300 | [diff] [blame] | 2369 | * @asic_name: ASIC specific name. |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2370 | * @asic_type: ASIC specific type. |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2371 | * @completion_queue: array of hl_cq. |
Ofir Bitton | ab5f5c3 | 2021-01-12 18:37:19 +0200 | [diff] [blame] | 2372 | * @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 Bitton | 5574cb2 | 2020-07-05 13:35:51 +0300 | [diff] [blame] | 2378 | * @cq_wq: work queues of completion queues for executing work in process |
| 2379 | * context. |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2380 | * @eq_wq: work queue of event queue for executing work in process context. |
Ofir Bitton | 8445dde | 2021-03-18 17:36:57 +0200 | [diff] [blame] | 2381 | * @sob_reset_wq: work queue for sob reset executions. |
Oded Gabbay | 4c172bb | 2019-08-30 16:59:33 +0300 | [diff] [blame] | 2382 | * @kernel_ctx: Kernel driver context structure. |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2383 | * @kernel_queues: array of hl_hw_queue. |
Tomer Tayar | 804a7227 | 2020-10-30 11:16:23 +0200 | [diff] [blame] | 2384 | * @cs_mirror_list: CS mirror list for TDR. |
| 2385 | * @cs_mirror_lock: protects cs_mirror_list. |
Zvika Yehudai | 38e19d0 | 2021-06-15 14:12:20 +0300 | [diff] [blame] | 2386 | * @kernel_cb_mgr: command buffer manager for creating/destroying/handling CBs. |
Oded Gabbay | 6138bbe | 2020-09-04 20:18:16 +0300 | [diff] [blame] | 2387 | * @event_queue: event queue for IRQ from CPU-CP. |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2388 | * @dma_pool: DMA pool for small allocations. |
Oded Gabbay | 6138bbe | 2020-09-04 20:18:16 +0300 | [diff] [blame] | 2389 | * @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 Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 2392 | * @asid_bitmap: holds used/available ASIDs. |
| 2393 | * @asid_mutex: protects asid_bitmap. |
Oded Gabbay | 6138bbe | 2020-09-04 20:18:16 +0300 | [diff] [blame] | 2394 | * @send_cpu_message_lock: enforces only one message in Host <-> CPU-CP queue. |
Oded Gabbay | 1973497 | 2019-05-04 17:36:06 +0300 | [diff] [blame] | 2395 | * @debug_lock: protects critical section of setting debug mode for device |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2396 | * @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 Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 2399 | * @vm: virtual memory manager for MMU. |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2400 | * @hwmon_dev: H/W monitor device. |
| 2401 | * @pm_mng_profile: current power management profile. |
| 2402 | * @hl_chip_info: ASIC's sensors information. |
Ofir Bitton | 66a7640 | 2020-10-05 14:40:10 +0300 | [diff] [blame] | 2403 | * @device_status_description: device status description. |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 2404 | * @hl_debugfs: device's debugfs manager. |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 2405 | * @cb_pool: list of preallocated CBs. |
| 2406 | * @cb_pool_lock: protects the CB pool. |
Ofir Bitton | a04b7cd | 2020-07-13 13:36:55 +0300 | [diff] [blame] | 2407 | * @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 Gabbay | eb7caf8 | 2019-07-30 11:56:09 +0300 | [diff] [blame] | 2411 | * @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 Gabbay | 86d5307 | 2019-07-30 11:49:36 +0300 | [diff] [blame] | 2414 | * @compute_ctx: current compute context executing. |
Ofir Bitton | db491e4 | 2020-06-18 09:51:16 +0300 | [diff] [blame] | 2415 | * @aggregated_cs_counters: aggregated cs counters among all contexts |
Moti Haimovski | d83fe66 | 2020-08-12 13:33:44 +0300 | [diff] [blame] | 2416 | * @mmu_priv: device-specific MMU data. |
| 2417 | * @mmu_func: device-related MMU functions. |
Ohad Sharabi | a22f0ec | 2021-04-11 23:06:46 +0300 | [diff] [blame] | 2418 | * @fw_loader: FW loader manager. |
Ohad Sharabi | c592c27 | 2021-04-21 13:03:21 +0300 | [diff] [blame] | 2419 | * @pci_mem_region: array of memory regions in the PCI |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 2420 | * @state_dump_specs: constants and dictionaries needed to dump system state. |
Ohad Sharabi | 215f0c1 | 2021-06-14 22:18:41 +0300 | [diff] [blame] | 2421 | * @multi_cs_completion: array of multi-CS completion. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 2422 | * @dram_used_mem: current DRAM memory consumption. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2423 | * @timeout_jiffies: device CS timeout value. |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2424 | * @max_power: the max power of the device, as configured by the sysadmin. This |
Oded Gabbay | 4c172bb | 2019-08-30 16:59:33 +0300 | [diff] [blame] | 2425 | * 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 Gabbay | e38bfd3 | 2020-07-03 20:46:12 +0300 | [diff] [blame] | 2427 | * @clock_gating_mask: is clock gating enabled. bitmask that represents the |
| 2428 | * different engines. See debugfs-driver-habanalabs for |
| 2429 | * details. |
Oded Gabbay | 27a9e35 | 2021-04-12 09:52:05 +0300 | [diff] [blame] | 2430 | * @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 Tayar | db1a8dd | 2021-06-15 10:55:43 +0300 | [diff] [blame] | 2436 | * @dram_pci_bar_start: start bus address of PCIe bar towards DRAM. |
Yuri Nudelman | e307b30 | 2021-05-24 11:25:21 +0300 | [diff] [blame] | 2437 | * @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 Gabbay | cbaa99e | 2019-03-03 15:13:15 +0200 | [diff] [blame] | 2442 | * @in_reset: is device in reset flow. |
Oded Gabbay | 75b3cb2 | 2019-08-28 17:32:04 +0300 | [diff] [blame] | 2443 | * @curr_pll_profile: current PLL profile. |
Oded Gabbay | 58361aa | 2020-08-08 23:34:47 +0300 | [diff] [blame] | 2444 | * @card_type: Various ASICs have several card types. This indicates the card |
| 2445 | * type of the current device. |
Oded Gabbay | 4c172bb | 2019-08-30 16:59:33 +0300 | [diff] [blame] | 2446 | * @major: habanalabs kernel driver major. |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2447 | * @high_pll: high PLL profile frequency. |
Oded Gabbay | 4c172bb | 2019-08-30 16:59:33 +0300 | [diff] [blame] | 2448 | * @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 Bitton | 0a068ad | 2020-07-21 10:49:51 +0300 | [diff] [blame] | 2450 | * @clk_throttling_reason: bitmask represents the current clk throttling reasons |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2451 | * @id: device minor. |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 2452 | * @id_control: minor of the control device |
Oded Gabbay | ac0ae6a | 2020-05-11 10:29:27 +0300 | [diff] [blame] | 2453 | * @cpu_pci_msb_addr: 50-bit extension bits for the device CPU's 40-bit |
| 2454 | * addresses. |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2455 | * @disabled: is device disabled. |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2456 | * @late_init_done: is late init stage was done during initialization. |
| 2457 | * @hwmon_initialized: is H/W monitor sensors was initialized. |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2458 | * @hard_reset_pending: is there a hard reset work pending. |
Oded Gabbay | 6138bbe | 2020-09-04 20:18:16 +0300 | [diff] [blame] | 2459 | * @heartbeat: is heartbeat sanity check towards CPU-CP enabled. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2460 | * @reset_on_lockup: true if a reset should be done in case of stuck CS, false |
| 2461 | * otherwise. |
Omer Shpigelman | 27ca384c | 2019-02-28 10:46:11 +0200 | [diff] [blame] | 2462 | * @dram_default_page_mapping: is DRAM default page mapping enabled. |
farah kassabri | 03df136 | 2020-05-06 11:17:38 +0300 | [diff] [blame] | 2463 | * @memory_scrub: true to perform device memory scrub in various locations, |
| 2464 | * such as context-switch, context close, page free, etc. |
Omer Shpigelman | 64a7e29 | 2020-01-05 09:05:45 +0000 | [diff] [blame] | 2465 | * @pmmu_huge_range: is a different virtual addresses range used for PMMU with |
| 2466 | * huge pages. |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2467 | * @init_done: is the initialization of the device done. |
Oded Gabbay | a28ce42 | 2019-02-28 10:46:12 +0200 | [diff] [blame] | 2468 | * @device_cpu_disabled: is the device CPU disabled (due to timeouts) |
Oded Gabbay | d997387 | 2019-03-07 18:03:23 +0200 | [diff] [blame] | 2469 | * @dma_mask: the dma mask that was set for this device |
Oded Gabbay | eb7caf8 | 2019-07-30 11:56:09 +0300 | [diff] [blame] | 2470 | * @in_debug: is device under debug. This, together with fpriv_list, enforces |
Oded Gabbay | 1973497 | 2019-05-04 17:36:06 +0300 | [diff] [blame] | 2471 | * that only a single user is configuring the debug infrastructure. |
Oded Gabbay | cb056b9 | 2020-03-29 13:18:30 +0300 | [diff] [blame] | 2472 | * @power9_64bit_dma_enable: true to enable 64-bit DMA mask support. Relevant |
| 2473 | * only to POWER9 machines. |
Tomer Tayar | ea451f8 | 2019-08-08 12:25:52 +0000 | [diff] [blame] | 2474 | * @cdev_sysfs_created: were char devices and sysfs nodes created. |
Omer Shpigelman | 76cedc7 | 2020-03-22 21:12:51 +0200 | [diff] [blame] | 2475 | * @stop_on_err: true if engines should stop on error. |
Omer Shpigelman | f9e5f29 | 2020-05-07 13:41:16 +0300 | [diff] [blame] | 2476 | * @supports_sync_stream: is sync stream supported. |
Ofir Bitton | 21e7a34 | 2020-05-14 18:25:47 +0300 | [diff] [blame] | 2477 | * @sync_stream_queue_idx: helper index for sync stream queues initialization. |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 2478 | * @collective_mon_idx: helper index for collective initialization |
Omer Shpigelman | 9e5e49c | 2020-05-10 14:10:15 +0300 | [diff] [blame] | 2479 | * @supports_coresight: is CoreSight supported. |
Oded Gabbay | 6644682 | 2020-05-18 16:48:01 +0300 | [diff] [blame] | 2480 | * @supports_soft_reset: is soft reset supported. |
Oded Gabbay | a00f1f5 | 2021-09-30 11:36:07 +0300 | [diff] [blame] | 2481 | * @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 Tayar | ef6a0f6 | 2020-07-09 16:17:48 +0300 | [diff] [blame] | 2487 | * @supports_cb_mapping: is mapping a CB to the device's MMU supported. |
Ofir Bitton | 66a7640 | 2020-10-05 14:40:10 +0300 | [diff] [blame] | 2488 | * @needs_reset: true if reset_on_lockup is false and device should be reset |
| 2489 | * due to lockup. |
Ofir Bitton | adb5129 | 2020-10-08 10:27:42 +0300 | [diff] [blame] | 2490 | * @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 Bitton | 2795c88 | 2020-12-08 13:47:05 +0200 | [diff] [blame] | 2494 | * @supports_staged_submission: true if staged submissions are supported |
Koby Elbaz | 3e0ca9f | 2021-05-04 20:10:47 +0300 | [diff] [blame] | 2495 | * @curr_reset_cause: saves an enumerated reset cause when a hard reset is |
| 2496 | * triggered, and cleared after it is shared with preboot. |
Bharat Jauhari | 10cab81 | 2021-06-21 09:57:19 +0300 | [diff] [blame] | 2497 | * @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 Nudelman | 4d04121 | 2021-06-13 09:22:20 +0300 | [diff] [blame] | 2501 | * @skip_reset_on_timeout: Skip device reset if CS has timed out, wait for it to |
| 2502 | * complete instead. |
Koby Elbaz | b7a71fd | 2021-06-15 17:07:02 +0300 | [diff] [blame] | 2503 | * @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 Sharabi | 215f0c1 | 2021-06-14 22:18:41 +0300 | [diff] [blame] | 2507 | * @supports_wait_for_multi_cs: true if wait for multi CS is supported |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2508 | */ |
| 2509 | struct hl_device { |
| 2510 | struct pci_dev *pdev; |
Ofir Bitton | f4cbfd2 | 2020-06-15 17:45:12 +0300 | [diff] [blame] | 2511 | u64 pcie_bar_phys[HL_PCI_NUM_BARS]; |
| 2512 | void __iomem *pcie_bar[HL_PCI_NUM_BARS]; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2513 | void __iomem *rmmio; |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2514 | struct cdev cdev; |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 2515 | struct cdev cdev_ctrl; |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2516 | struct device *dev; |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 2517 | struct device *dev_ctrl; |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2518 | struct delayed_work work_freq; |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2519 | struct delayed_work work_heartbeat; |
Ofir Bitton | adb5129 | 2020-10-08 10:27:42 +0300 | [diff] [blame] | 2520 | struct hl_device_reset_work device_reset_work; |
Ofir Bitton | 66a7640 | 2020-10-05 14:40:10 +0300 | [diff] [blame] | 2521 | char asic_name[HL_STR_MAX]; |
| 2522 | char status[HL_DEV_STS_MAX][HL_STR_MAX]; |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2523 | enum hl_asic_type asic_type; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2524 | struct hl_cq *completion_queue; |
Ofir Bitton | 2d44c6f | 2021-01-12 14:43:09 +0200 | [diff] [blame] | 2525 | struct hl_user_interrupt *user_interrupt; |
Ofir Bitton | ab5f5c3 | 2021-01-12 18:37:19 +0200 | [diff] [blame] | 2526 | struct hl_user_interrupt common_user_interrupt; |
Ofir Bitton | 5574cb2 | 2020-07-05 13:35:51 +0300 | [diff] [blame] | 2527 | struct workqueue_struct **cq_wq; |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 2528 | struct workqueue_struct *eq_wq; |
Ofir Bitton | 8445dde | 2021-03-18 17:36:57 +0200 | [diff] [blame] | 2529 | struct workqueue_struct *sob_reset_wq; |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 2530 | struct hl_ctx *kernel_ctx; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2531 | struct hl_hw_queue *kernel_queues; |
Tomer Tayar | 804a7227 | 2020-10-30 11:16:23 +0200 | [diff] [blame] | 2532 | struct list_head cs_mirror_list; |
| 2533 | spinlock_t cs_mirror_lock; |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 2534 | struct hl_cb_mgr kernel_cb_mgr; |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 2535 | struct hl_eq event_queue; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2536 | 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 Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 2540 | unsigned long *asid_bitmap; |
| 2541 | struct mutex asid_mutex; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2542 | struct mutex send_cpu_message_lock; |
Oded Gabbay | 1973497 | 2019-05-04 17:36:06 +0300 | [diff] [blame] | 2543 | struct mutex debug_lock; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2544 | struct asic_fixed_properties asic_prop; |
| 2545 | const struct hl_asic_funcs *asic_funcs; |
| 2546 | void *asic_specific; |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 2547 | struct hl_vm vm; |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2548 | struct device *hwmon_dev; |
| 2549 | enum hl_pm_mng_profile pm_mng_profile; |
| 2550 | struct hwmon_chip_info *hl_chip_info; |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 2551 | |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 2552 | struct hl_dbg_device_entry hl_debugfs; |
| 2553 | |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 2554 | struct list_head cb_pool; |
| 2555 | spinlock_t cb_pool_lock; |
| 2556 | |
Ofir Bitton | a04b7cd | 2020-07-13 13:36:55 +0300 | [diff] [blame] | 2557 | 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 Gabbay | eb7caf8 | 2019-07-30 11:56:09 +0300 | [diff] [blame] | 2562 | struct list_head fpriv_list; |
| 2563 | struct mutex fpriv_list_lock; |
| 2564 | |
Oded Gabbay | 86d5307 | 2019-07-30 11:49:36 +0300 | [diff] [blame] | 2565 | struct hl_ctx *compute_ctx; |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2566 | |
Oded Gabbay | 23c15ae | 2020-09-30 14:25:55 +0300 | [diff] [blame] | 2567 | struct hl_cs_counters_atomic aggregated_cs_counters; |
Ofir Bitton | db491e4 | 2020-06-18 09:51:16 +0300 | [diff] [blame] | 2568 | |
Moti Haimovski | d83fe66 | 2020-08-12 13:33:44 +0300 | [diff] [blame] | 2569 | struct hl_mmu_priv mmu_priv; |
Moti Haimovski | ccf979e | 2020-10-05 17:59:29 +0300 | [diff] [blame] | 2570 | struct hl_mmu_funcs mmu_func[MMU_NUM_PGT_LOCATIONS]; |
Moti Haimovski | d83fe66 | 2020-08-12 13:33:44 +0300 | [diff] [blame] | 2571 | |
Ohad Sharabi | a22f0ec | 2021-04-11 23:06:46 +0300 | [diff] [blame] | 2572 | struct fw_load_mgr fw_loader; |
| 2573 | |
Ohad Sharabi | c592c27 | 2021-04-21 13:03:21 +0300 | [diff] [blame] | 2574 | struct pci_mem_region pci_mem_region[PCI_REGION_NUMBER]; |
| 2575 | |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 2576 | struct hl_state_dump_specs state_dump_specs; |
| 2577 | |
Ohad Sharabi | 215f0c1 | 2021-06-14 22:18:41 +0300 | [diff] [blame] | 2578 | struct multi_cs_completion multi_cs_completion[ |
| 2579 | MULTI_CS_MAX_USER_CTX]; |
Ohad Sharabi | 72d6625 | 2021-08-01 23:02:07 +0300 | [diff] [blame] | 2580 | u32 *stream_master_qid_arr; |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 2581 | atomic64_t dram_used_mem; |
Oded Gabbay | cbaa99e | 2019-03-03 15:13:15 +0200 | [diff] [blame] | 2582 | u64 timeout_jiffies; |
| 2583 | u64 max_power; |
Oded Gabbay | e38bfd3 | 2020-07-03 20:46:12 +0300 | [diff] [blame] | 2584 | u64 clock_gating_mask; |
Oded Gabbay | 27a9e35 | 2021-04-12 09:52:05 +0300 | [diff] [blame] | 2585 | u64 boot_error_status_mask; |
Tomer Tayar | db1a8dd | 2021-06-15 10:55:43 +0300 | [diff] [blame] | 2586 | u64 dram_pci_bar_start; |
Yuri Nudelman | e307b30 | 2021-05-24 11:25:21 +0300 | [diff] [blame] | 2587 | u64 last_successful_open_jif; |
| 2588 | u64 last_open_session_duration_jif; |
| 2589 | u64 open_counter; |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2590 | atomic_t in_reset; |
Oded Gabbay | eb7caf8 | 2019-07-30 11:56:09 +0300 | [diff] [blame] | 2591 | enum hl_pll_frequency curr_pll_profile; |
Oded Gabbay | 2f55342 | 2020-08-15 16:28:10 +0300 | [diff] [blame] | 2592 | enum cpucp_card_types card_type; |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2593 | u32 major; |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2594 | u32 high_pll; |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2595 | u32 soft_reset_cnt; |
| 2596 | u32 hard_reset_cnt; |
Ofir Bitton | 0a068ad | 2020-07-21 10:49:51 +0300 | [diff] [blame] | 2597 | u32 clk_throttling_reason; |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2598 | u16 id; |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 2599 | u16 id_control; |
Oded Gabbay | ac0ae6a | 2020-05-11 10:29:27 +0300 | [diff] [blame] | 2600 | u16 cpu_pci_msb_addr; |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2601 | u8 disabled; |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2602 | u8 late_init_done; |
| 2603 | u8 hwmon_initialized; |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2604 | u8 hard_reset_pending; |
| 2605 | u8 heartbeat; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2606 | u8 reset_on_lockup; |
Omer Shpigelman | 27ca384c | 2019-02-28 10:46:11 +0200 | [diff] [blame] | 2607 | u8 dram_default_page_mapping; |
farah kassabri | 03df136 | 2020-05-06 11:17:38 +0300 | [diff] [blame] | 2608 | u8 memory_scrub; |
Omer Shpigelman | 64a7e29 | 2020-01-05 09:05:45 +0000 | [diff] [blame] | 2609 | u8 pmmu_huge_range; |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2610 | u8 init_done; |
Oded Gabbay | a28ce42 | 2019-02-28 10:46:12 +0200 | [diff] [blame] | 2611 | u8 device_cpu_disabled; |
Oded Gabbay | d997387 | 2019-03-07 18:03:23 +0200 | [diff] [blame] | 2612 | u8 dma_mask; |
Oded Gabbay | 1973497 | 2019-05-04 17:36:06 +0300 | [diff] [blame] | 2613 | u8 in_debug; |
Oded Gabbay | ac0ae6a | 2020-05-11 10:29:27 +0300 | [diff] [blame] | 2614 | u8 power9_64bit_dma_enable; |
Tomer Tayar | ea451f8 | 2019-08-08 12:25:52 +0000 | [diff] [blame] | 2615 | u8 cdev_sysfs_created; |
Omer Shpigelman | 76cedc7 | 2020-03-22 21:12:51 +0200 | [diff] [blame] | 2616 | u8 stop_on_err; |
Omer Shpigelman | f9e5f29 | 2020-05-07 13:41:16 +0300 | [diff] [blame] | 2617 | u8 supports_sync_stream; |
Ofir Bitton | 21e7a34 | 2020-05-14 18:25:47 +0300 | [diff] [blame] | 2618 | u8 sync_stream_queue_idx; |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 2619 | u8 collective_mon_idx; |
Omer Shpigelman | 9e5e49c | 2020-05-10 14:10:15 +0300 | [diff] [blame] | 2620 | u8 supports_coresight; |
Oded Gabbay | 6644682 | 2020-05-18 16:48:01 +0300 | [diff] [blame] | 2621 | u8 supports_soft_reset; |
Oded Gabbay | a00f1f5 | 2021-09-30 11:36:07 +0300 | [diff] [blame] | 2622 | u8 allow_inference_soft_reset; |
Tomer Tayar | ef6a0f6 | 2020-07-09 16:17:48 +0300 | [diff] [blame] | 2623 | u8 supports_cb_mapping; |
Ofir Bitton | 66a7640 | 2020-10-05 14:40:10 +0300 | [diff] [blame] | 2624 | u8 needs_reset; |
Ofir Bitton | adb5129 | 2020-10-08 10:27:42 +0300 | [diff] [blame] | 2625 | u8 process_kill_trial_cnt; |
| 2626 | u8 device_fini_pending; |
Ofir Bitton | 2795c88 | 2020-12-08 13:47:05 +0200 | [diff] [blame] | 2627 | u8 supports_staged_submission; |
Koby Elbaz | 3e0ca9f | 2021-05-04 20:10:47 +0300 | [diff] [blame] | 2628 | u8 curr_reset_cause; |
Bharat Jauhari | 10cab81 | 2021-06-21 09:57:19 +0300 | [diff] [blame] | 2629 | u8 prev_reset_trigger; |
| 2630 | u8 reset_trigger_repeated; |
Yuri Nudelman | 4d04121 | 2021-06-13 09:22:20 +0300 | [diff] [blame] | 2631 | u8 skip_reset_on_timeout; |
Koby Elbaz | b7a71fd | 2021-06-15 17:07:02 +0300 | [diff] [blame] | 2632 | u8 device_cpu_is_halted; |
Ohad Sharabi | 215f0c1 | 2021-06-14 22:18:41 +0300 | [diff] [blame] | 2633 | u8 supports_wait_for_multi_cs; |
Ohad Sharabi | 72d6625 | 2021-08-01 23:02:07 +0300 | [diff] [blame] | 2634 | u8 stream_master_qid_arr_size; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2635 | |
| 2636 | /* Parameters for bring-up */ |
Oded Gabbay | 3c68157 | 2020-11-02 21:10:39 +0200 | [diff] [blame] | 2637 | u64 nic_ports_mask; |
Ofir Bitton | 6a2f5d7 | 2021-02-15 13:23:04 +0200 | [diff] [blame] | 2638 | u64 fw_components; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2639 | u8 mmu_enable; |
Oded Gabbay | ac0ae6a | 2020-05-11 10:29:27 +0300 | [diff] [blame] | 2640 | u8 mmu_huge_page_opt; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2641 | u8 reset_pcilink; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2642 | u8 cpu_queues_enable; |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2643 | u8 pldm; |
Oded Gabbay | ac0ae6a | 2020-05-11 10:29:27 +0300 | [diff] [blame] | 2644 | 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 Bitton | d1ddd90 | 2020-10-19 17:04:20 +0300 | [diff] [blame] | 2650 | u8 reset_on_preboot_fail; |
Oded Gabbay | d3ee681 | 2021-02-16 22:49:27 +0200 | [diff] [blame] | 2651 | u8 reset_upon_device_release; |
Ofir Bitton | 84586de | 2021-05-20 13:30:31 +0300 | [diff] [blame] | 2652 | u8 reset_if_device_not_idle; |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2653 | }; |
| 2654 | |
| 2655 | |
farah kassabri | dadf17a | 2021-05-24 18:09:22 +0300 | [diff] [blame] | 2656 | /** |
| 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 | */ |
| 2668 | struct 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 Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2679 | /* |
| 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 | */ |
| 2691 | typedef 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 | */ |
| 2698 | struct 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 Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2708 | /** |
Yuri Nudelman | 89b2136 | 2021-07-29 11:44:28 +0300 | [diff] [blame] | 2709 | * 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 | */ |
| 2717 | static 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 Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2726 | * 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 Bitton | 3654527 | 2020-08-06 11:33:27 +0300 | [diff] [blame] | 2734 | static inline bool hl_mem_area_inside_range(u64 address, u64 size, |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2735 | 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 | */ |
| 2757 | static 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 Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2777 | int hl_device_open(struct inode *inode, struct file *filp); |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 2778 | int hl_device_open_ctrl(struct inode *inode, struct file *filp); |
Ofir Bitton | 66a7640 | 2020-10-05 14:40:10 +0300 | [diff] [blame] | 2779 | bool hl_device_operational(struct hl_device *hdev, |
| 2780 | enum hl_device_status *status); |
Dalit Ben Zoor | aa95708 | 2019-03-24 10:15:44 +0200 | [diff] [blame] | 2781 | enum hl_device_status hl_device_status(struct hl_device *hdev); |
Oded Gabbay | 1973497 | 2019-05-04 17:36:06 +0300 | [diff] [blame] | 2782 | int hl_device_set_debug_mode(struct hl_device *hdev, bool enable); |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2783 | int create_hdev(struct hl_device **dev, struct pci_dev *pdev, |
| 2784 | enum hl_asic_type asic_type, int minor); |
| 2785 | void destroy_hdev(struct hl_device *hdev); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2786 | int hl_hw_queues_create(struct hl_device *hdev); |
| 2787 | void hl_hw_queues_destroy(struct hl_device *hdev); |
| 2788 | int hl_hw_queue_send_cb_no_cmpl(struct hl_device *hdev, u32 hw_queue_id, |
Koby Elbaz | 8bb8b50 | 2021-07-06 20:50:33 +0300 | [diff] [blame] | 2789 | u32 cb_size, u64 cb_ptr); |
| 2790 | void hl_hw_queue_submit_bd(struct hl_device *hdev, struct hl_hw_queue *q, |
| 2791 | u32 ctl, u32 len, u64 ptr); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2792 | int hl_hw_queue_schedule_cs(struct hl_cs *cs); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2793 | u32 hl_hw_queue_add_ptr(u32 ptr, u16 val); |
| 2794 | void hl_hw_queue_inc_ci_kernel(struct hl_device *hdev, u32 hw_queue_id); |
Ofir Bitton | 0811b39 | 2020-12-06 17:18:02 +0200 | [diff] [blame] | 2795 | void hl_hw_queue_update_ci(struct hl_cs *cs); |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2796 | void hl_hw_queue_reset(struct hl_device *hdev, bool hard_reset); |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2797 | |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2798 | #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 | |
| 2801 | int hl_cq_init(struct hl_device *hdev, struct hl_cq *q, u32 hw_queue_id); |
| 2802 | void hl_cq_fini(struct hl_device *hdev, struct hl_cq *q); |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 2803 | int hl_eq_init(struct hl_device *hdev, struct hl_eq *q); |
| 2804 | void hl_eq_fini(struct hl_device *hdev, struct hl_eq *q); |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2805 | void hl_cq_reset(struct hl_device *hdev, struct hl_cq *q); |
| 2806 | void hl_eq_reset(struct hl_device *hdev, struct hl_eq *q); |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 2807 | irqreturn_t hl_irq_handler_cq(int irq, void *arg); |
| 2808 | irqreturn_t hl_irq_handler_eq(int irq, void *arg); |
Ofir Bitton | 2d44c6f | 2021-01-12 14:43:09 +0200 | [diff] [blame] | 2809 | irqreturn_t hl_irq_handler_user_cq(int irq, void *arg); |
| 2810 | irqreturn_t hl_irq_handler_default(int irq, void *arg); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2811 | u32 hl_cq_inc_ptr(u32 ptr); |
| 2812 | |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 2813 | int hl_asid_init(struct hl_device *hdev); |
| 2814 | void hl_asid_fini(struct hl_device *hdev); |
| 2815 | unsigned long hl_asid_alloc(struct hl_device *hdev); |
| 2816 | void hl_asid_free(struct hl_device *hdev, unsigned long asid); |
| 2817 | |
| 2818 | int hl_ctx_create(struct hl_device *hdev, struct hl_fpriv *hpriv); |
| 2819 | void hl_ctx_free(struct hl_device *hdev, struct hl_ctx *ctx); |
| 2820 | int hl_ctx_init(struct hl_device *hdev, struct hl_ctx *ctx, bool is_kernel_ctx); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2821 | void hl_ctx_do_release(struct kref *ref); |
| 2822 | void hl_ctx_get(struct hl_device *hdev, struct hl_ctx *ctx); |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 2823 | int hl_ctx_put(struct hl_ctx *ctx); |
Ofir Bitton | a98d73c | 2020-07-15 08:52:39 +0300 | [diff] [blame] | 2824 | struct hl_fence *hl_ctx_get_fence(struct hl_ctx *ctx, u64 seq); |
Ohad Sharabi | c457d5a | 2021-06-20 11:00:26 +0300 | [diff] [blame] | 2825 | int hl_ctx_get_fences(struct hl_ctx *ctx, u64 *seq_arr, |
| 2826 | struct hl_fence **fence, u32 arr_len); |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 2827 | void hl_ctx_mgr_init(struct hl_ctx_mgr *mgr); |
| 2828 | void hl_ctx_mgr_fini(struct hl_device *hdev, struct hl_ctx_mgr *mgr); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2829 | |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2830 | int hl_device_init(struct hl_device *hdev, struct class *hclass); |
| 2831 | void hl_device_fini(struct hl_device *hdev); |
| 2832 | int hl_device_suspend(struct hl_device *hdev); |
| 2833 | int hl_device_resume(struct hl_device *hdev); |
Ohad Sharabi | e42a6400f | 2021-02-17 20:42:48 +0200 | [diff] [blame] | 2834 | int hl_device_reset(struct hl_device *hdev, u32 flags); |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 2835 | void hl_hpriv_get(struct hl_fpriv *hpriv); |
Oded Gabbay | 278b5f7 | 2021-02-18 10:24:02 +0200 | [diff] [blame] | 2836 | int hl_hpriv_put(struct hl_fpriv *hpriv); |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2837 | int hl_device_set_frequency(struct hl_device *hdev, enum hl_pll_frequency freq); |
Koby Elbaz | cd5def8 | 2021-02-23 21:31:27 +0200 | [diff] [blame] | 2838 | int hl_device_utilization(struct hl_device *hdev, u32 *utilization); |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 2839 | |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2840 | int hl_build_hwmon_channel_info(struct hl_device *hdev, |
Oded Gabbay | 2f55342 | 2020-08-15 16:28:10 +0300 | [diff] [blame] | 2841 | struct cpucp_sensor *sensors_arr); |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2842 | |
| 2843 | int hl_sysfs_init(struct hl_device *hdev); |
| 2844 | void hl_sysfs_fini(struct hl_device *hdev); |
| 2845 | |
| 2846 | int hl_hwmon_init(struct hl_device *hdev); |
| 2847 | void hl_hwmon_fini(struct hl_device *hdev); |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2848 | |
Tomer Tayar | fa8641a1 | 2020-09-07 17:36:41 +0300 | [diff] [blame] | 2849 | int hl_cb_create(struct hl_device *hdev, struct hl_cb_mgr *mgr, |
| 2850 | struct hl_ctx *ctx, u32 cb_size, bool internal_cb, |
Tomer Tayar | ef6a0f6 | 2020-07-09 16:17:48 +0300 | [diff] [blame] | 2851 | bool map_cb, u64 *handle); |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 2852 | int hl_cb_destroy(struct hl_device *hdev, struct hl_cb_mgr *mgr, u64 cb_handle); |
| 2853 | int hl_cb_mmap(struct hl_fpriv *hpriv, struct vm_area_struct *vma); |
Ofir Bitton | d00697f | 2021-01-05 12:55:06 +0200 | [diff] [blame] | 2854 | int hl_hw_block_mmap(struct hl_fpriv *hpriv, struct vm_area_struct *vma); |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 2855 | struct hl_cb *hl_cb_get(struct hl_device *hdev, struct hl_cb_mgr *mgr, |
| 2856 | u32 handle); |
| 2857 | void hl_cb_put(struct hl_cb *cb); |
| 2858 | void hl_cb_mgr_init(struct hl_cb_mgr *mgr); |
| 2859 | void hl_cb_mgr_fini(struct hl_device *hdev, struct hl_cb_mgr *mgr); |
Ofir Bitton | a04b7cd | 2020-07-13 13:36:55 +0300 | [diff] [blame] | 2860 | struct hl_cb *hl_cb_kernel_create(struct hl_device *hdev, u32 cb_size, |
| 2861 | bool internal_cb); |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 2862 | int hl_cb_pool_init(struct hl_device *hdev); |
| 2863 | int hl_cb_pool_fini(struct hl_device *hdev); |
Tomer Tayar | ef6a0f6 | 2020-07-09 16:17:48 +0300 | [diff] [blame] | 2864 | int hl_cb_va_pool_init(struct hl_ctx *ctx); |
| 2865 | void hl_cb_va_pool_fini(struct hl_ctx *ctx); |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 2866 | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2867 | void hl_cs_rollback_all(struct hl_device *hdev); |
Tomer Tayar | cb596ae | 2019-10-03 15:22:36 +0000 | [diff] [blame] | 2868 | struct hl_cs_job *hl_cs_allocate_job(struct hl_device *hdev, |
| 2869 | enum hl_queue_type queue_type, bool is_kernel_allocated_cb); |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 2870 | void hl_sob_reset_error(struct kref *ref); |
Ofir Bitton | 2992c1d | 2020-09-10 09:40:35 +0300 | [diff] [blame] | 2871 | int hl_gen_sob_mask(u16 sob_base, u8 sob_mask, u8 *mask); |
Ofir Bitton | a98d73c | 2020-07-15 08:52:39 +0300 | [diff] [blame] | 2872 | void hl_fence_put(struct hl_fence *fence); |
Ohad Sharabi | c457d5a | 2021-06-20 11:00:26 +0300 | [diff] [blame] | 2873 | void hl_fences_put(struct hl_fence **fence, int len); |
Ofir Bitton | a98d73c | 2020-07-15 08:52:39 +0300 | [diff] [blame] | 2874 | void hl_fence_get(struct hl_fence *fence); |
Ofir Bitton | 5de406c | 2020-09-10 10:56:26 +0300 | [diff] [blame] | 2875 | void cs_get(struct hl_cs *cs); |
Ofir Bitton | 0811b39 | 2020-12-06 17:18:02 +0200 | [diff] [blame] | 2876 | bool cs_needs_completion(struct hl_cs *cs); |
| 2877 | bool cs_needs_timeout(struct hl_cs *cs); |
Ofir Bitton | 2795c88 | 2020-12-08 13:47:05 +0200 | [diff] [blame] | 2878 | bool is_staged_cs_last_exists(struct hl_device *hdev, struct hl_cs *cs); |
| 2879 | struct hl_cs *hl_staged_cs_find_first(struct hl_device *hdev, u64 cs_seq); |
Ohad Sharabi | 215f0c1 | 2021-06-14 22:18:41 +0300 | [diff] [blame] | 2880 | void hl_multi_cs_completion_init(struct hl_device *hdev); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2881 | |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2882 | void goya_set_asic_funcs(struct hl_device *hdev); |
Oded Gabbay | ac0ae6a | 2020-05-11 10:29:27 +0300 | [diff] [blame] | 2883 | void gaudi_set_asic_funcs(struct hl_device *hdev); |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2884 | |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 2885 | int hl_vm_ctx_init(struct hl_ctx *ctx); |
| 2886 | void hl_vm_ctx_fini(struct hl_ctx *ctx); |
| 2887 | |
| 2888 | int hl_vm_init(struct hl_device *hdev); |
| 2889 | void hl_vm_fini(struct hl_device *hdev); |
| 2890 | |
Sagiv Ozeri | a4371c1 | 2021-02-23 11:01:08 +0200 | [diff] [blame] | 2891 | void hl_hw_block_mem_init(struct hl_ctx *ctx); |
| 2892 | void hl_hw_block_mem_fini(struct hl_ctx *ctx); |
| 2893 | |
Ofir Bitton | be91b91 | 2020-10-22 15:04:10 +0300 | [diff] [blame] | 2894 | u64 hl_reserve_va_block(struct hl_device *hdev, struct hl_ctx *ctx, |
Ofir Bitton | 412c41f | 2020-11-04 15:18:55 +0200 | [diff] [blame] | 2895 | enum hl_va_range_type type, u32 size, u32 alignment); |
Ofir Bitton | be91b91 | 2020-10-22 15:04:10 +0300 | [diff] [blame] | 2896 | int hl_unreserve_va_block(struct hl_device *hdev, struct hl_ctx *ctx, |
| 2897 | u64 start_addr, u64 size); |
Oded Gabbay | 230afe7 | 2019-02-27 00:19:18 +0200 | [diff] [blame] | 2898 | int hl_pin_host_memory(struct hl_device *hdev, u64 addr, u64 size, |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2899 | struct hl_userptr *userptr); |
Omer Shpigelman | 7f74d4d | 2019-08-12 11:48:46 +0300 | [diff] [blame] | 2900 | void hl_unpin_host_memory(struct hl_device *hdev, struct hl_userptr *userptr); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2901 | void hl_userptr_delete_list(struct hl_device *hdev, |
| 2902 | struct list_head *userptr_list); |
| 2903 | bool 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 Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 2907 | int hl_mmu_init(struct hl_device *hdev); |
| 2908 | void hl_mmu_fini(struct hl_device *hdev); |
Omer Shpigelman | 27ca384c | 2019-02-28 10:46:11 +0200 | [diff] [blame] | 2909 | int hl_mmu_ctx_init(struct hl_ctx *ctx); |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 2910 | void hl_mmu_ctx_fini(struct hl_ctx *ctx); |
Ofir Bitton | 5c05487 | 2020-10-22 15:13:10 +0300 | [diff] [blame] | 2911 | int hl_mmu_map_page(struct hl_ctx *ctx, u64 virt_addr, u64 phys_addr, |
Pawel Piskorski | 7fc40bc | 2019-12-06 17:32:38 +0200 | [diff] [blame] | 2912 | u32 page_size, bool flush_pte); |
Ofir Bitton | 5c05487 | 2020-10-22 15:13:10 +0300 | [diff] [blame] | 2913 | int hl_mmu_unmap_page(struct hl_ctx *ctx, u64 virt_addr, u32 page_size, |
Pawel Piskorski | 7fc40bc | 2019-12-06 17:32:38 +0200 | [diff] [blame] | 2914 | bool flush_pte); |
Ofir Bitton | 5c05487 | 2020-10-22 15:13:10 +0300 | [diff] [blame] | 2915 | int hl_mmu_map_contiguous(struct hl_ctx *ctx, u64 virt_addr, |
| 2916 | u64 phys_addr, u32 size); |
| 2917 | int hl_mmu_unmap_contiguous(struct hl_ctx *ctx, u64 virt_addr, u32 size); |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 2918 | void hl_mmu_swap_out(struct hl_ctx *ctx); |
| 2919 | void hl_mmu_swap_in(struct hl_ctx *ctx); |
Moti Haimovski | d83fe66 | 2020-08-12 13:33:44 +0300 | [diff] [blame] | 2920 | int hl_mmu_if_set_funcs(struct hl_device *hdev); |
Moti Haimovski | ccf979e | 2020-10-05 17:59:29 +0300 | [diff] [blame] | 2921 | void hl_mmu_v1_set_funcs(struct hl_device *hdev, struct hl_mmu_funcs *mmu); |
Moti Haimovski | 00e1b59 | 2020-10-27 10:55:42 +0200 | [diff] [blame] | 2922 | int hl_mmu_va_to_pa(struct hl_ctx *ctx, u64 virt_addr, u64 *phys_addr); |
| 2923 | int hl_mmu_get_tlb_info(struct hl_ctx *ctx, u64 virt_addr, |
| 2924 | struct hl_mmu_hop_info *hops); |
farah kassabri | 89473a1 | 2021-01-12 17:24:00 +0200 | [diff] [blame] | 2925 | u64 hl_mmu_scramble_addr(struct hl_device *hdev, u64 addr); |
| 2926 | u64 hl_mmu_descramble_addr(struct hl_device *hdev, u64 addr); |
Oded Gabbay | 9488307 | 2021-01-11 17:49:30 +0200 | [diff] [blame] | 2927 | bool hl_is_dram_va(struct hl_device *hdev, u64 virt_addr); |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 2928 | |
Oded Gabbay | 7e1c07d | 2020-03-26 12:32:56 +0200 | [diff] [blame] | 2929 | int hl_fw_load_fw_to_device(struct hl_device *hdev, const char *fw_name, |
Ofir Bitton | 9bb86b6 | 2020-10-20 10:45:37 +0300 | [diff] [blame] | 2930 | void __iomem *dst, u32 src_offset, u32 size); |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 2931 | int hl_fw_send_pci_access_msg(struct hl_device *hdev, u32 opcode); |
| 2932 | int hl_fw_send_cpu_message(struct hl_device *hdev, u32 hw_queue_id, u32 *msg, |
Alon Mizrahi | 439bc47 | 2020-11-10 13:49:10 +0200 | [diff] [blame] | 2933 | u16 len, u32 timeout, u64 *result); |
Ofir Bitton | ebd8d12 | 2020-05-10 13:41:28 +0300 | [diff] [blame] | 2934 | int hl_fw_unmask_irq(struct hl_device *hdev, u16 event_type); |
| 2935 | int hl_fw_unmask_irq_arr(struct hl_device *hdev, const u32 *irq_arr, |
| 2936 | size_t irq_arr_size); |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 2937 | int hl_fw_test_cpu_queue(struct hl_device *hdev); |
| 2938 | void *hl_fw_cpu_accessible_dma_pool_alloc(struct hl_device *hdev, size_t size, |
| 2939 | dma_addr_t *dma_handle); |
| 2940 | void hl_fw_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size, |
| 2941 | void *vaddr); |
| 2942 | int hl_fw_send_heartbeat(struct hl_device *hdev); |
Alon Mizrahi | 4147864 | 2020-11-17 14:25:14 +0200 | [diff] [blame] | 2943 | int hl_fw_cpucp_info_get(struct hl_device *hdev, |
Ohad Sharabi | e67a6040 | 2021-05-02 15:45:21 +0300 | [diff] [blame] | 2944 | u32 sts_boot_dev_sts0_reg, |
| 2945 | u32 sts_boot_dev_sts1_reg, u32 boot_err0_reg, |
| 2946 | u32 boot_err1_reg); |
Ohad Sharabi | e9c2003 | 2021-03-22 14:30:52 +0200 | [diff] [blame] | 2947 | int hl_fw_cpucp_handshake(struct hl_device *hdev, |
Ohad Sharabi | e67a6040 | 2021-05-02 15:45:21 +0300 | [diff] [blame] | 2948 | u32 sts_boot_dev_sts0_reg, |
| 2949 | u32 sts_boot_dev_sts1_reg, u32 boot_err0_reg, |
| 2950 | u32 boot_err1_reg); |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 2951 | int hl_fw_get_eeprom_data(struct hl_device *hdev, void *data, size_t max_size); |
Oded Gabbay | 2f55342 | 2020-08-15 16:28:10 +0300 | [diff] [blame] | 2952 | int hl_fw_cpucp_pci_counters_get(struct hl_device *hdev, |
Ofir Bitton | 0a068ad | 2020-07-21 10:49:51 +0300 | [diff] [blame] | 2953 | struct hl_info_pci_counters *counters); |
Oded Gabbay | 2f55342 | 2020-08-15 16:28:10 +0300 | [diff] [blame] | 2954 | int hl_fw_cpucp_total_energy_get(struct hl_device *hdev, |
farah kassabri | 9f30649 | 2020-08-09 16:25:53 +0300 | [diff] [blame] | 2955 | u64 *total_energy); |
Bharat Jauhari | 285c0fa | 2021-03-25 18:15:40 +0200 | [diff] [blame] | 2956 | int get_used_pll_index(struct hl_device *hdev, u32 input_pll_index, |
Ohad Sharabi | e8f9392 | 2021-03-15 20:49:28 +0200 | [diff] [blame] | 2957 | enum pll_index *pll_index); |
Bharat Jauhari | 285c0fa | 2021-03-25 18:15:40 +0200 | [diff] [blame] | 2958 | int hl_fw_cpucp_pll_info_get(struct hl_device *hdev, u32 pll_index, |
Alon Mizrahi | 4147864 | 2020-11-17 14:25:14 +0200 | [diff] [blame] | 2959 | u16 *pll_freq_arr); |
Sagiv Ozeri | 586f2ca | 2021-02-23 18:00:05 +0200 | [diff] [blame] | 2960 | int hl_fw_cpucp_power_get(struct hl_device *hdev, u64 *power); |
Koby Elbaz | b7a71fd | 2021-06-15 17:07:02 +0300 | [diff] [blame] | 2961 | void hl_fw_ask_hard_reset_without_linux(struct hl_device *hdev); |
| 2962 | void hl_fw_ask_halt_machine_without_linux(struct hl_device *hdev); |
Ohad Sharabi | a22f0ec | 2021-04-11 23:06:46 +0300 | [diff] [blame] | 2963 | int hl_fw_init_cpu(struct hl_device *hdev); |
Ofir Bitton | 323b726 | 2020-10-04 09:09:19 +0300 | [diff] [blame] | 2964 | int hl_fw_read_preboot_status(struct hl_device *hdev, u32 cpu_boot_status_reg, |
Ohad Sharabi | e67a6040 | 2021-05-02 15:45:21 +0300 | [diff] [blame] | 2965 | 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 Elbaz | 4080308 | 2021-05-20 12:45:58 +0300 | [diff] [blame] | 2968 | int 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 Tayar | b6f897d | 2019-03-05 16:48:42 +0200 | [diff] [blame] | 2972 | int hl_pci_bars_map(struct hl_device *hdev, const char * const name[3], |
| 2973 | bool is_wc[3]); |
Ofir Bitton | 41f458f | 2021-03-10 15:08:44 +0200 | [diff] [blame] | 2974 | int hl_pci_elbi_read(struct hl_device *hdev, u64 addr, u32 *data); |
Tomer Tayar | b6f897d | 2019-03-05 16:48:42 +0200 | [diff] [blame] | 2975 | int hl_pci_iatu_write(struct hl_device *hdev, u32 addr, u32 data); |
Ofir Bitton | f4cbfd2 | 2020-06-15 17:45:12 +0300 | [diff] [blame] | 2976 | int hl_pci_set_inbound_region(struct hl_device *hdev, u8 region, |
| 2977 | struct hl_inbound_pci_region *pci_region); |
| 2978 | int hl_pci_set_outbound_region(struct hl_device *hdev, |
| 2979 | struct hl_outbound_pci_region *pci_region); |
Ohad Sharabi | c592c27 | 2021-04-21 13:03:21 +0300 | [diff] [blame] | 2980 | enum pci_region hl_get_pci_memory_region(struct hl_device *hdev, u64 addr); |
Ofir Bitton | d1ddd90 | 2020-10-19 17:04:20 +0300 | [diff] [blame] | 2981 | int hl_pci_init(struct hl_device *hdev); |
Tomer Tayar | b6f897d | 2019-03-05 16:48:42 +0200 | [diff] [blame] | 2982 | void hl_pci_fini(struct hl_device *hdev); |
| 2983 | |
Bharat Jauhari | 285c0fa | 2021-03-25 18:15:40 +0200 | [diff] [blame] | 2984 | long hl_get_frequency(struct hl_device *hdev, u32 pll_index, |
Ohad Sharabi | e8f9392 | 2021-03-15 20:49:28 +0200 | [diff] [blame] | 2985 | bool curr); |
Bharat Jauhari | 285c0fa | 2021-03-25 18:15:40 +0200 | [diff] [blame] | 2986 | void hl_set_frequency(struct hl_device *hdev, u32 pll_index, |
Ohad Sharabi | e8f9392 | 2021-03-15 20:49:28 +0200 | [diff] [blame] | 2987 | u64 freq); |
Moti Haimovski | d57b83c | 2020-01-23 18:03:04 +0200 | [diff] [blame] | 2988 | int hl_get_temperature(struct hl_device *hdev, |
| 2989 | int sensor_index, u32 attr, long *value); |
Moti Haimovski | 5557b13 | 2020-01-21 15:02:06 +0200 | [diff] [blame] | 2990 | int hl_set_temperature(struct hl_device *hdev, |
Moti Haimovski | d57b83c | 2020-01-23 18:03:04 +0200 | [diff] [blame] | 2991 | int sensor_index, u32 attr, long value); |
| 2992 | int hl_get_voltage(struct hl_device *hdev, |
| 2993 | int sensor_index, u32 attr, long *value); |
| 2994 | int hl_get_current(struct hl_device *hdev, |
| 2995 | int sensor_index, u32 attr, long *value); |
| 2996 | int hl_get_fan_speed(struct hl_device *hdev, |
| 2997 | int sensor_index, u32 attr, long *value); |
| 2998 | int hl_get_pwm_info(struct hl_device *hdev, |
| 2999 | int sensor_index, u32 attr, long *value); |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 3000 | void hl_set_pwm_info(struct hl_device *hdev, int sensor_index, u32 attr, |
| 3001 | long value); |
| 3002 | u64 hl_get_max_power(struct hl_device *hdev); |
Oded Gabbay | 58361aa | 2020-08-08 23:34:47 +0300 | [diff] [blame] | 3003 | void hl_set_max_power(struct hl_device *hdev); |
Christine Gharzuzi | 8e708af | 2020-04-16 16:43:26 +0300 | [diff] [blame] | 3004 | int hl_set_voltage(struct hl_device *hdev, |
| 3005 | int sensor_index, u32 attr, long value); |
| 3006 | int hl_set_current(struct hl_device *hdev, |
| 3007 | int sensor_index, u32 attr, long value); |
Rajaravi Krishna Katta | 2b28485 | 2021-08-18 08:12:41 +0300 | [diff] [blame] | 3008 | int hl_set_power(struct hl_device *hdev, |
| 3009 | int sensor_index, u32 attr, long value); |
| 3010 | int hl_get_power(struct hl_device *hdev, |
| 3011 | int sensor_index, u32 attr, long *value); |
Rajaravi Krishna Katta | 024b7b1 | 2021-09-03 08:01:30 +0300 | [diff] [blame] | 3012 | int hl_get_clk_rate(struct hl_device *hdev, |
| 3013 | u32 *cur_clk, u32 *max_clk); |
| 3014 | void hl_set_pll_profile(struct hl_device *hdev, enum hl_pll_frequency freq); |
| 3015 | void hl_add_device_attr(struct hl_device *hdev, |
| 3016 | struct attribute_group *dev_attr_grp); |
farah kassabri | dadf17a | 2021-05-24 18:09:22 +0300 | [diff] [blame] | 3017 | void hw_sob_get(struct hl_hw_sob *hw_sob); |
| 3018 | void hw_sob_put(struct hl_hw_sob *hw_sob); |
farah kassabri | e4cdccd | 2021-05-26 10:43:36 +0300 | [diff] [blame] | 3019 | void hl_encaps_handle_do_release(struct kref *ref); |
| 3020 | void 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 Bitton | ab5f5c3 | 2021-01-12 18:37:19 +0200 | [diff] [blame] | 3023 | void hl_release_pending_user_interrupts(struct hl_device *hdev); |
farah kassabri | 3817b35 | 2021-06-01 16:44:28 +0300 | [diff] [blame] | 3024 | int hl_cs_signal_sob_wraparound_handler(struct hl_device *hdev, u32 q_idx, |
farah kassabri | dadf17a | 2021-05-24 18:09:22 +0300 | [diff] [blame] | 3025 | struct hl_hw_sob **hw_sob, u32 count, bool encaps_sig); |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 3026 | |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 3027 | int hl_state_dump(struct hl_device *hdev); |
| 3028 | const char *hl_state_dump_get_sync_name(struct hl_device *hdev, u32 sync_id); |
Yuri Nudelman | fd2010b | 2021-06-09 14:04:26 +0300 | [diff] [blame] | 3029 | const char *hl_state_dump_get_monitor_name(struct hl_device *hdev, |
| 3030 | struct hl_mon_state_dump *mon); |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 3031 | void 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, ...); |
| 3034 | char *hl_format_as_binary(char *buf, size_t buf_len, u32 n); |
| 3035 | const char *hl_sync_engine_to_string(enum hl_sync_engine_type engine_type); |
| 3036 | |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 3037 | #ifdef CONFIG_DEBUG_FS |
| 3038 | |
| 3039 | void hl_debugfs_init(void); |
| 3040 | void hl_debugfs_fini(void); |
| 3041 | void hl_debugfs_add_device(struct hl_device *hdev); |
| 3042 | void hl_debugfs_remove_device(struct hl_device *hdev); |
| 3043 | void hl_debugfs_add_file(struct hl_fpriv *hpriv); |
| 3044 | void hl_debugfs_remove_file(struct hl_fpriv *hpriv); |
| 3045 | void hl_debugfs_add_cb(struct hl_cb *cb); |
| 3046 | void hl_debugfs_remove_cb(struct hl_cb *cb); |
| 3047 | void hl_debugfs_add_cs(struct hl_cs *cs); |
| 3048 | void hl_debugfs_remove_cs(struct hl_cs *cs); |
| 3049 | void hl_debugfs_add_job(struct hl_device *hdev, struct hl_cs_job *job); |
| 3050 | void hl_debugfs_remove_job(struct hl_device *hdev, struct hl_cs_job *job); |
| 3051 | void hl_debugfs_add_userptr(struct hl_device *hdev, struct hl_userptr *userptr); |
| 3052 | void hl_debugfs_remove_userptr(struct hl_device *hdev, |
| 3053 | struct hl_userptr *userptr); |
| 3054 | void hl_debugfs_add_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx); |
| 3055 | void hl_debugfs_remove_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx); |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 3056 | void hl_debugfs_set_state_dump(struct hl_device *hdev, char *data, |
| 3057 | unsigned long length); |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 3058 | |
| 3059 | #else |
| 3060 | |
| 3061 | static inline void __init hl_debugfs_init(void) |
| 3062 | { |
| 3063 | } |
| 3064 | |
| 3065 | static inline void hl_debugfs_fini(void) |
| 3066 | { |
| 3067 | } |
| 3068 | |
| 3069 | static inline void hl_debugfs_add_device(struct hl_device *hdev) |
| 3070 | { |
| 3071 | } |
| 3072 | |
| 3073 | static inline void hl_debugfs_remove_device(struct hl_device *hdev) |
| 3074 | { |
| 3075 | } |
| 3076 | |
| 3077 | static inline void hl_debugfs_add_file(struct hl_fpriv *hpriv) |
| 3078 | { |
| 3079 | } |
| 3080 | |
| 3081 | static inline void hl_debugfs_remove_file(struct hl_fpriv *hpriv) |
| 3082 | { |
| 3083 | } |
| 3084 | |
| 3085 | static inline void hl_debugfs_add_cb(struct hl_cb *cb) |
| 3086 | { |
| 3087 | } |
| 3088 | |
| 3089 | static inline void hl_debugfs_remove_cb(struct hl_cb *cb) |
| 3090 | { |
| 3091 | } |
| 3092 | |
| 3093 | static inline void hl_debugfs_add_cs(struct hl_cs *cs) |
| 3094 | { |
| 3095 | } |
| 3096 | |
| 3097 | static inline void hl_debugfs_remove_cs(struct hl_cs *cs) |
| 3098 | { |
| 3099 | } |
| 3100 | |
| 3101 | static inline void hl_debugfs_add_job(struct hl_device *hdev, |
| 3102 | struct hl_cs_job *job) |
| 3103 | { |
| 3104 | } |
| 3105 | |
| 3106 | static inline void hl_debugfs_remove_job(struct hl_device *hdev, |
| 3107 | struct hl_cs_job *job) |
| 3108 | { |
| 3109 | } |
| 3110 | |
| 3111 | static inline void hl_debugfs_add_userptr(struct hl_device *hdev, |
| 3112 | struct hl_userptr *userptr) |
| 3113 | { |
| 3114 | } |
| 3115 | |
| 3116 | static inline void hl_debugfs_remove_userptr(struct hl_device *hdev, |
| 3117 | struct hl_userptr *userptr) |
| 3118 | { |
| 3119 | } |
| 3120 | |
| 3121 | static inline void hl_debugfs_add_ctx_mem_hash(struct hl_device *hdev, |
| 3122 | struct hl_ctx *ctx) |
| 3123 | { |
| 3124 | } |
| 3125 | |
| 3126 | static inline void hl_debugfs_remove_ctx_mem_hash(struct hl_device *hdev, |
| 3127 | struct hl_ctx *ctx) |
| 3128 | { |
| 3129 | } |
| 3130 | |
Yuri Nudelman | fd2010b | 2021-06-09 14:04:26 +0300 | [diff] [blame] | 3131 | static inline void hl_debugfs_set_state_dump(struct hl_device *hdev, |
| 3132 | char *data, unsigned long length) |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 3133 | { |
| 3134 | } |
| 3135 | |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 3136 | #endif |
| 3137 | |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 3138 | /* IOCTLs */ |
| 3139 | long hl_ioctl(struct file *filep, unsigned int cmd, unsigned long arg); |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 3140 | long hl_ioctl_control(struct file *filep, unsigned int cmd, unsigned long arg); |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 3141 | int hl_cb_ioctl(struct hl_fpriv *hpriv, void *data); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3142 | int hl_cs_ioctl(struct hl_fpriv *hpriv, void *data); |
Ofir Bitton | ab5f5c3 | 2021-01-12 18:37:19 +0200 | [diff] [blame] | 3143 | int hl_wait_ioctl(struct hl_fpriv *hpriv, void *data); |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 3144 | int hl_mem_ioctl(struct hl_fpriv *hpriv, void *data); |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 3145 | |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 3146 | #endif /* HABANALABSP_H_ */ |