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> |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 29 | |
| 30 | #define HL_NAME "habanalabs" |
| 31 | |
Oded Gabbay | 3174ac9 | 2020-08-29 11:51:39 +0300 | [diff] [blame] | 32 | /* Use upper bits of mmap offset to store habana driver specific information. |
Ofir Bitton | d00697f | 2021-01-05 12:55:06 +0200 | [diff] [blame] | 33 | * bits[63:61] - Encode mmap type |
Oded Gabbay | 3174ac9 | 2020-08-29 11:51:39 +0300 | [diff] [blame] | 34 | * bits[45:0] - mmap offset value |
| 35 | * |
| 36 | * NOTE: struct vm_area_struct.vm_pgoff uses offset in pages. Hence, these |
| 37 | * defines are w.r.t to PAGE_SIZE |
| 38 | */ |
Ofir Bitton | d00697f | 2021-01-05 12:55:06 +0200 | [diff] [blame] | 39 | #define HL_MMAP_TYPE_SHIFT (61 - PAGE_SHIFT) |
| 40 | #define HL_MMAP_TYPE_MASK (0x7ull << HL_MMAP_TYPE_SHIFT) |
| 41 | #define HL_MMAP_TYPE_BLOCK (0x4ull << HL_MMAP_TYPE_SHIFT) |
Oded Gabbay | 3174ac9 | 2020-08-29 11:51:39 +0300 | [diff] [blame] | 42 | #define HL_MMAP_TYPE_CB (0x2ull << HL_MMAP_TYPE_SHIFT) |
| 43 | |
Ofir Bitton | d00697f | 2021-01-05 12:55:06 +0200 | [diff] [blame] | 44 | #define HL_MMAP_OFFSET_VALUE_MASK (0x1FFFFFFFFFFFull >> PAGE_SHIFT) |
Oded Gabbay | 3174ac9 | 2020-08-29 11:51:39 +0300 | [diff] [blame] | 45 | #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] | 46 | |
Ofir Bitton | adb5129 | 2020-10-08 10:27:42 +0300 | [diff] [blame] | 47 | #define HL_PENDING_RESET_PER_SEC 10 |
| 48 | #define HL_PENDING_RESET_MAX_TRIALS 60 /* 10 minutes */ |
| 49 | #define HL_PENDING_RESET_LONG_SEC 60 |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 50 | |
Omer Shpigelman | e09498b | 2020-05-09 12:18:01 +0300 | [diff] [blame] | 51 | #define HL_HARD_RESET_MAX_TIMEOUT 120 |
Omer Shpigelman | 4efb6b2 | 2021-06-09 10:17:49 +0300 | [diff] [blame] | 52 | #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] | 53 | |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 54 | #define HL_DEVICE_TIMEOUT_USEC 1000000 /* 1 s */ |
| 55 | |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 56 | #define HL_HEARTBEAT_PER_USEC 5000000 /* 5 s */ |
| 57 | |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 58 | #define HL_PLL_LOW_JOB_FREQ_USEC 5000000 /* 5 s */ |
| 59 | |
Oded Gabbay | 2f55342 | 2020-08-15 16:28:10 +0300 | [diff] [blame] | 60 | #define HL_CPUCP_INFO_TIMEOUT_USEC 10000000 /* 10s */ |
| 61 | #define HL_CPUCP_EEPROM_TIMEOUT_USEC 10000000 /* 10s */ |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 62 | |
Omer Shpigelman | a1e537b | 2019-05-13 14:44:50 +0300 | [diff] [blame] | 63 | #define HL_PCI_ELBI_TIMEOUT_MSEC 10 /* 10ms */ |
| 64 | |
Oded Gabbay | ed0fc50 | 2019-07-18 11:14:37 +0300 | [diff] [blame] | 65 | #define HL_SIM_MAX_TIMEOUT_US 10000000 /* 10s */ |
| 66 | |
Ofir Bitton | ab5f5c3 | 2021-01-12 18:37:19 +0200 | [diff] [blame] | 67 | #define HL_COMMON_USER_INTERRUPT_ID 0xFFF |
| 68 | |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 69 | #define HL_STATE_DUMP_HIST_LEN 5 |
| 70 | |
| 71 | #define OBJ_NAMES_HASH_TABLE_BITS 7 /* 1 << 7 buckets */ |
| 72 | #define SYNC_TO_ENGINE_HASH_TABLE_BITS 7 /* 1 << 7 buckets */ |
| 73 | |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 74 | /* Memory */ |
| 75 | #define MEM_HASH_TABLE_BITS 7 /* 1 << 7 buckets */ |
| 76 | |
| 77 | /* MMU */ |
| 78 | #define MMU_HASH_TABLE_BITS 7 /* 1 << 7 buckets */ |
| 79 | |
Moti Haimovski | ccf979e | 2020-10-05 17:59:29 +0300 | [diff] [blame] | 80 | /** |
| 81 | * enum hl_mmu_page_table_locaion - mmu page table location |
| 82 | * @MMU_DR_PGT: page-table is located on device DRAM. |
| 83 | * @MMU_HR_PGT: page-table is located on host memory. |
| 84 | * @MMU_NUM_PGT_LOCATIONS: number of page-table locations currently supported. |
| 85 | */ |
| 86 | enum hl_mmu_page_table_location { |
| 87 | MMU_DR_PGT = 0, /* device-dram-resident MMU PGT */ |
| 88 | MMU_HR_PGT, /* host resident MMU PGT */ |
| 89 | MMU_NUM_PGT_LOCATIONS /* num of PGT locations */ |
| 90 | }; |
| 91 | |
Ofir Bitton | 21e7a34 | 2020-05-14 18:25:47 +0300 | [diff] [blame] | 92 | /* |
| 93 | * HL_RSVD_SOBS 'sync stream' reserved sync objects per QMAN stream |
| 94 | * HL_RSVD_MONS 'sync stream' reserved monitors per QMAN stream |
| 95 | */ |
Ofir Bitton | 5de406c | 2020-09-10 10:56:26 +0300 | [diff] [blame] | 96 | #define HL_RSVD_SOBS 2 |
| 97 | #define HL_RSVD_MONS 1 |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 98 | |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 99 | /* |
| 100 | * HL_COLLECTIVE_RSVD_MSTR_MONS 'collective' reserved monitors per QMAN stream |
| 101 | */ |
| 102 | #define HL_COLLECTIVE_RSVD_MSTR_MONS 2 |
| 103 | |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 104 | #define HL_MAX_SOB_VAL (1 << 15) |
| 105 | |
Ofir Bitton | c16d45f | 2020-06-02 12:28:27 +0300 | [diff] [blame] | 106 | #define IS_POWER_OF_2(n) (n != 0 && ((n & (n - 1)) == 0)) |
| 107 | #define IS_MAX_PENDING_CS_VALID(n) (IS_POWER_OF_2(n) && (n > 1)) |
| 108 | |
Ofir Bitton | f4cbfd2 | 2020-06-15 17:45:12 +0300 | [diff] [blame] | 109 | #define HL_PCI_NUM_BARS 6 |
| 110 | |
Ofir Bitton | 843839b | 2020-07-19 11:08:09 +0300 | [diff] [blame] | 111 | #define HL_MAX_DCORES 4 |
| 112 | |
Ohad Sharabi | e42a6400f | 2021-02-17 20:42:48 +0200 | [diff] [blame] | 113 | /* |
| 114 | * Reset Flags |
| 115 | * |
| 116 | * - HL_RESET_HARD |
| 117 | * If set do hard reset to all engines. If not set reset just |
| 118 | * compute/DMA engines. |
| 119 | * |
| 120 | * - HL_RESET_FROM_RESET_THREAD |
| 121 | * Set if the caller is the hard-reset thread |
| 122 | * |
| 123 | * - HL_RESET_HEARTBEAT |
| 124 | * Set if reset is due to heartbeat |
Koby Elbaz | 3e0ca9f | 2021-05-04 20:10:47 +0300 | [diff] [blame] | 125 | * |
| 126 | * - HL_RESET_TDR |
| 127 | * Set if reset is due to TDR |
Ofir Bitton | 23bace6 | 2021-06-08 17:24:52 +0300 | [diff] [blame] | 128 | * |
| 129 | * - HL_RESET_DEVICE_RELEASE |
| 130 | * Set if reset is due to device release |
Ohad Sharabi | e42a6400f | 2021-02-17 20:42:48 +0200 | [diff] [blame] | 131 | */ |
| 132 | #define HL_RESET_HARD (1 << 0) |
| 133 | #define HL_RESET_FROM_RESET_THREAD (1 << 1) |
| 134 | #define HL_RESET_HEARTBEAT (1 << 2) |
Koby Elbaz | 3e0ca9f | 2021-05-04 20:10:47 +0300 | [diff] [blame] | 135 | #define HL_RESET_TDR (1 << 3) |
Ofir Bitton | 23bace6 | 2021-06-08 17:24:52 +0300 | [diff] [blame] | 136 | #define HL_RESET_DEVICE_RELEASE (1 << 4) |
Ohad Sharabi | e42a6400f | 2021-02-17 20:42:48 +0200 | [diff] [blame] | 137 | |
Ofir Bitton | 2992c1d | 2020-09-10 09:40:35 +0300 | [diff] [blame] | 138 | #define HL_MAX_SOBS_PER_MONITOR 8 |
| 139 | |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 140 | /** |
Ofir Bitton | 3cf74b3 | 2020-09-10 09:17:50 +0300 | [diff] [blame] | 141 | * struct hl_gen_wait_properties - properties for generating a wait CB |
| 142 | * @data: command buffer |
| 143 | * @q_idx: queue id is used to extract fence register address |
Ofir Bitton | 2992c1d | 2020-09-10 09:40:35 +0300 | [diff] [blame] | 144 | * @size: offset in command buffer |
| 145 | * @sob_base: SOB base to use in this wait CB |
Ofir Bitton | 3cf74b3 | 2020-09-10 09:17:50 +0300 | [diff] [blame] | 146 | * @sob_val: SOB value to wait for |
| 147 | * @mon_id: monitor to use in this wait CB |
Ofir Bitton | 2992c1d | 2020-09-10 09:40:35 +0300 | [diff] [blame] | 148 | * @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] | 149 | */ |
| 150 | struct hl_gen_wait_properties { |
| 151 | void *data; |
| 152 | u32 q_idx; |
Ofir Bitton | 2992c1d | 2020-09-10 09:40:35 +0300 | [diff] [blame] | 153 | u32 size; |
| 154 | u16 sob_base; |
Ofir Bitton | 3cf74b3 | 2020-09-10 09:17:50 +0300 | [diff] [blame] | 155 | u16 sob_val; |
| 156 | u16 mon_id; |
Ofir Bitton | 2992c1d | 2020-09-10 09:40:35 +0300 | [diff] [blame] | 157 | u8 sob_mask; |
Ofir Bitton | 3cf74b3 | 2020-09-10 09:17:50 +0300 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | /** |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 161 | * struct pgt_info - MMU hop page info. |
Omer Shpigelman | 66542c3 | 2019-02-24 09:17:55 +0200 | [diff] [blame] | 162 | * @node: hash linked-list node for the pgts shadow hash of pgts. |
| 163 | * @phys_addr: physical address of the pgt. |
| 164 | * @shadow_addr: shadow hop in the host. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 165 | * @ctx: pointer to the owner ctx. |
| 166 | * @num_of_ptes: indicates how many ptes are used in the pgt. |
| 167 | * |
| 168 | * The MMU page tables hierarchy is placed on the DRAM. When a new level (hop) |
| 169 | * is needed during mapping, a new page is allocated and this structure holds |
| 170 | * its essential information. During unmapping, if no valid PTEs remained in the |
| 171 | * page, it is freed with its pgt_info structure. |
| 172 | */ |
| 173 | struct pgt_info { |
Omer Shpigelman | 66542c3 | 2019-02-24 09:17:55 +0200 | [diff] [blame] | 174 | struct hlist_node node; |
| 175 | u64 phys_addr; |
| 176 | u64 shadow_addr; |
| 177 | struct hl_ctx *ctx; |
| 178 | int num_of_ptes; |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 179 | }; |
| 180 | |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 181 | struct hl_device; |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 182 | struct hl_fpriv; |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 183 | |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 184 | /** |
Ofir Bitton | f4cbfd2 | 2020-06-15 17:45:12 +0300 | [diff] [blame] | 185 | * enum hl_pci_match_mode - pci match mode per region |
| 186 | * @PCI_ADDRESS_MATCH_MODE: address match mode |
| 187 | * @PCI_BAR_MATCH_MODE: bar match mode |
| 188 | */ |
| 189 | enum hl_pci_match_mode { |
| 190 | PCI_ADDRESS_MATCH_MODE, |
| 191 | PCI_BAR_MATCH_MODE |
| 192 | }; |
| 193 | |
| 194 | /** |
Oded Gabbay | 7e1c07d | 2020-03-26 12:32:56 +0200 | [diff] [blame] | 195 | * enum hl_fw_component - F/W components to read version through registers. |
Ohad Sharabi | 50f036d | 2021-04-11 15:26:28 +0300 | [diff] [blame] | 196 | * @FW_COMP_BOOT_FIT: boot fit. |
Oded Gabbay | 7e1c07d | 2020-03-26 12:32:56 +0200 | [diff] [blame] | 197 | * @FW_COMP_PREBOOT: preboot. |
Ohad Sharabi | b31e59b | 2021-04-22 10:01:22 +0300 | [diff] [blame] | 198 | * @FW_COMP_LINUX: linux. |
Oded Gabbay | 7e1c07d | 2020-03-26 12:32:56 +0200 | [diff] [blame] | 199 | */ |
| 200 | enum hl_fw_component { |
Ohad Sharabi | 50f036d | 2021-04-11 15:26:28 +0300 | [diff] [blame] | 201 | FW_COMP_BOOT_FIT, |
Ohad Sharabi | b31e59b | 2021-04-22 10:01:22 +0300 | [diff] [blame] | 202 | FW_COMP_PREBOOT, |
| 203 | FW_COMP_LINUX, |
Oded Gabbay | 7e1c07d | 2020-03-26 12:32:56 +0200 | [diff] [blame] | 204 | }; |
| 205 | |
| 206 | /** |
Ofir Bitton | 6a2f5d7 | 2021-02-15 13:23:04 +0200 | [diff] [blame] | 207 | * enum hl_fw_types - F/W types present in the system |
Oded Gabbay | 596553d | 2020-10-01 13:46:37 +0300 | [diff] [blame] | 208 | * @FW_TYPE_LINUX: Linux image for device CPU |
| 209 | * @FW_TYPE_BOOT_CPU: Boot image for device CPU |
Ofir Bitton | 6a2f5d7 | 2021-02-15 13:23:04 +0200 | [diff] [blame] | 210 | * @FW_TYPE_PREBOOT_CPU: Indicates pre-loaded CPUs are present in the system |
| 211 | * (preboot, ppboot etc...) |
Oded Gabbay | 596553d | 2020-10-01 13:46:37 +0300 | [diff] [blame] | 212 | * @FW_TYPE_ALL_TYPES: Mask for all types |
| 213 | */ |
| 214 | enum hl_fw_types { |
| 215 | FW_TYPE_LINUX = 0x1, |
| 216 | FW_TYPE_BOOT_CPU = 0x2, |
Ofir Bitton | 6a2f5d7 | 2021-02-15 13:23:04 +0200 | [diff] [blame] | 217 | FW_TYPE_PREBOOT_CPU = 0x4, |
| 218 | FW_TYPE_ALL_TYPES = |
| 219 | (FW_TYPE_LINUX | FW_TYPE_BOOT_CPU | FW_TYPE_PREBOOT_CPU) |
Oded Gabbay | 596553d | 2020-10-01 13:46:37 +0300 | [diff] [blame] | 220 | }; |
| 221 | |
| 222 | /** |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 223 | * enum hl_queue_type - Supported QUEUE types. |
| 224 | * @QUEUE_TYPE_NA: queue is not available. |
| 225 | * @QUEUE_TYPE_EXT: external queue which is a DMA channel that may access the |
| 226 | * host. |
| 227 | * @QUEUE_TYPE_INT: internal queue that performs DMA inside the device's |
| 228 | * memories and/or operates the compute engines. |
| 229 | * @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] | 230 | * @QUEUE_TYPE_HW: queue of DMA and compute engines jobs, for which completion |
| 231 | * notifications are sent by H/W. |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 232 | */ |
| 233 | enum hl_queue_type { |
| 234 | QUEUE_TYPE_NA, |
| 235 | QUEUE_TYPE_EXT, |
| 236 | QUEUE_TYPE_INT, |
Tomer Tayar | cb596ae | 2019-10-03 15:22:36 +0000 | [diff] [blame] | 237 | QUEUE_TYPE_CPU, |
| 238 | QUEUE_TYPE_HW |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 239 | }; |
| 240 | |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 241 | enum hl_cs_type { |
| 242 | CS_TYPE_DEFAULT, |
| 243 | CS_TYPE_SIGNAL, |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 244 | CS_TYPE_WAIT, |
| 245 | CS_TYPE_COLLECTIVE_WAIT |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 246 | }; |
| 247 | |
| 248 | /* |
Ofir Bitton | f4cbfd2 | 2020-06-15 17:45:12 +0300 | [diff] [blame] | 249 | * struct hl_inbound_pci_region - inbound region descriptor |
| 250 | * @mode: pci match mode for this region |
| 251 | * @addr: region target address |
| 252 | * @size: region size in bytes |
| 253 | * @offset_in_bar: offset within bar (address match mode) |
| 254 | * @bar: bar id |
| 255 | */ |
| 256 | struct hl_inbound_pci_region { |
| 257 | enum hl_pci_match_mode mode; |
| 258 | u64 addr; |
| 259 | u64 size; |
| 260 | u64 offset_in_bar; |
| 261 | u8 bar; |
| 262 | }; |
| 263 | |
| 264 | /* |
| 265 | * struct hl_outbound_pci_region - outbound region descriptor |
| 266 | * @addr: region target address |
| 267 | * @size: region size in bytes |
| 268 | */ |
| 269 | struct hl_outbound_pci_region { |
| 270 | u64 addr; |
| 271 | u64 size; |
| 272 | }; |
| 273 | |
| 274 | /* |
Tal Cohen | 4bb1f2f | 2020-06-03 09:25:27 +0300 | [diff] [blame] | 275 | * enum queue_cb_alloc_flags - Indicates queue support for CBs that |
| 276 | * allocated by Kernel or by User |
| 277 | * @CB_ALLOC_KERNEL: support only CBs that allocated by Kernel |
| 278 | * @CB_ALLOC_USER: support only CBs that allocated by User |
| 279 | */ |
| 280 | enum queue_cb_alloc_flags { |
| 281 | CB_ALLOC_KERNEL = 0x1, |
| 282 | CB_ALLOC_USER = 0x2 |
| 283 | }; |
| 284 | |
| 285 | /* |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 286 | * struct hl_hw_sob - H/W SOB info. |
| 287 | * @hdev: habanalabs device structure. |
| 288 | * @kref: refcount of this SOB. The SOB will reset once the refcount is zero. |
| 289 | * @sob_id: id of this SOB. |
| 290 | * @q_idx: the H/W queue that uses this SOB. |
| 291 | */ |
| 292 | struct hl_hw_sob { |
| 293 | struct hl_device *hdev; |
| 294 | struct kref kref; |
| 295 | u32 sob_id; |
| 296 | u32 q_idx; |
| 297 | }; |
| 298 | |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 299 | enum hl_collective_mode { |
| 300 | HL_COLLECTIVE_NOT_SUPPORTED = 0x0, |
| 301 | HL_COLLECTIVE_MASTER = 0x1, |
| 302 | HL_COLLECTIVE_SLAVE = 0x2 |
| 303 | }; |
| 304 | |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 305 | /** |
| 306 | * struct hw_queue_properties - queue information. |
| 307 | * @type: queue type. |
Tal Cohen | 4bb1f2f | 2020-06-03 09:25:27 +0300 | [diff] [blame] | 308 | * @queue_cb_alloc_flags: bitmap which indicates if the hw queue supports CB |
| 309 | * that allocated by the Kernel driver and therefore, |
| 310 | * a CB handle can be provided for jobs on this queue. |
| 311 | * Otherwise, a CB address must be provided. |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 312 | * @collective_mode: collective mode of current queue |
Oded Gabbay | 4c172bb | 2019-08-30 16:59:33 +0300 | [diff] [blame] | 313 | * @driver_only: true if only the driver is allowed to send a job to this queue, |
| 314 | * false otherwise. |
Ofir Bitton | 21e7a34 | 2020-05-14 18:25:47 +0300 | [diff] [blame] | 315 | * @supports_sync_stream: True if queue supports sync stream |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 316 | */ |
| 317 | struct hw_queue_properties { |
| 318 | enum hl_queue_type type; |
Tal Cohen | 4bb1f2f | 2020-06-03 09:25:27 +0300 | [diff] [blame] | 319 | enum queue_cb_alloc_flags cb_alloc_flags; |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 320 | enum hl_collective_mode collective_mode; |
Oded Gabbay | 4c172bb | 2019-08-30 16:59:33 +0300 | [diff] [blame] | 321 | u8 driver_only; |
Ofir Bitton | 21e7a34 | 2020-05-14 18:25:47 +0300 | [diff] [blame] | 322 | u8 supports_sync_stream; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 323 | }; |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 324 | |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 325 | /** |
Oded Gabbay | 82629c7 | 2021-06-29 18:08:05 +0300 | [diff] [blame] | 326 | * enum vm_type - virtual memory mapping request information. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 327 | * @VM_TYPE_USERPTR: mapping of user memory to device virtual address. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 328 | * @VM_TYPE_PHYS_PACK: mapping of DRAM memory to device virtual address. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 329 | */ |
Oded Gabbay | 82629c7 | 2021-06-29 18:08:05 +0300 | [diff] [blame] | 330 | enum vm_type { |
Omer Shpigelman | 7b6e4ea | 2019-11-14 18:23:53 +0000 | [diff] [blame] | 331 | VM_TYPE_USERPTR = 0x1, |
| 332 | VM_TYPE_PHYS_PACK = 0x2 |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 333 | }; |
| 334 | |
| 335 | /** |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 336 | * enum hl_device_hw_state - H/W device state. use this to understand whether |
| 337 | * to do reset before hw_init or not |
| 338 | * @HL_DEVICE_HW_STATE_CLEAN: H/W state is clean. i.e. after hard reset |
| 339 | * @HL_DEVICE_HW_STATE_DIRTY: H/W state is dirty. i.e. we started to execute |
| 340 | * hw_init |
| 341 | */ |
| 342 | enum hl_device_hw_state { |
| 343 | HL_DEVICE_HW_STATE_CLEAN = 0, |
| 344 | HL_DEVICE_HW_STATE_DIRTY |
| 345 | }; |
| 346 | |
Ofir Bitton | 412c41f | 2020-11-04 15:18:55 +0200 | [diff] [blame] | 347 | #define HL_MMU_VA_ALIGNMENT_NOT_NEEDED 0 |
| 348 | |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 349 | /** |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 350 | * struct hl_mmu_properties - ASIC specific MMU address translation properties. |
Omer Shpigelman | 64a7e29 | 2020-01-05 09:05:45 +0000 | [diff] [blame] | 351 | * @start_addr: virtual start address of the memory region. |
| 352 | * @end_addr: virtual end address of the memory region. |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 353 | * @hop0_shift: shift of hop 0 mask. |
| 354 | * @hop1_shift: shift of hop 1 mask. |
| 355 | * @hop2_shift: shift of hop 2 mask. |
| 356 | * @hop3_shift: shift of hop 3 mask. |
| 357 | * @hop4_shift: shift of hop 4 mask. |
Moti Haimovski | 7edf341 | 2020-08-23 13:23:13 +0300 | [diff] [blame] | 358 | * @hop5_shift: shift of hop 5 mask. |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 359 | * @hop0_mask: mask to get the PTE address in hop 0. |
| 360 | * @hop1_mask: mask to get the PTE address in hop 1. |
| 361 | * @hop2_mask: mask to get the PTE address in hop 2. |
| 362 | * @hop3_mask: mask to get the PTE address in hop 3. |
| 363 | * @hop4_mask: mask to get the PTE address in hop 4. |
Moti Haimovski | 7edf341 | 2020-08-23 13:23:13 +0300 | [diff] [blame] | 364 | * @hop5_mask: mask to get the PTE address in hop 5. |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 365 | * @page_size: default page size used to allocate memory. |
Moti Haimovski | 7edf341 | 2020-08-23 13:23:13 +0300 | [diff] [blame] | 366 | * @num_hops: The amount of hops supported by the translation table. |
Moti Haimovski | ccf979e | 2020-10-05 17:59:29 +0300 | [diff] [blame] | 367 | * @host_resident: Should the MMU page table reside in host memory or in the |
| 368 | * device DRAM. |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 369 | */ |
| 370 | struct hl_mmu_properties { |
Omer Shpigelman | 64a7e29 | 2020-01-05 09:05:45 +0000 | [diff] [blame] | 371 | u64 start_addr; |
| 372 | u64 end_addr; |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 373 | u64 hop0_shift; |
| 374 | u64 hop1_shift; |
| 375 | u64 hop2_shift; |
| 376 | u64 hop3_shift; |
| 377 | u64 hop4_shift; |
Moti Haimovski | 7edf341 | 2020-08-23 13:23:13 +0300 | [diff] [blame] | 378 | u64 hop5_shift; |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 379 | u64 hop0_mask; |
| 380 | u64 hop1_mask; |
| 381 | u64 hop2_mask; |
| 382 | u64 hop3_mask; |
| 383 | u64 hop4_mask; |
Moti Haimovski | 7edf341 | 2020-08-23 13:23:13 +0300 | [diff] [blame] | 384 | u64 hop5_mask; |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 385 | u32 page_size; |
Moti Haimovski | 7edf341 | 2020-08-23 13:23:13 +0300 | [diff] [blame] | 386 | u32 num_hops; |
Moti Haimovski | ccf979e | 2020-10-05 17:59:29 +0300 | [diff] [blame] | 387 | u8 host_resident; |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 388 | }; |
| 389 | |
| 390 | /** |
farah kassabri | 1ae32b9 | 2021-01-31 18:56:03 +0200 | [diff] [blame] | 391 | * struct hl_hints_range - hint addresses reserved va range. |
| 392 | * @start_addr: start address of the va range. |
| 393 | * @end_addr: end address of the va range. |
| 394 | */ |
| 395 | struct hl_hints_range { |
| 396 | u64 start_addr; |
| 397 | u64 end_addr; |
| 398 | }; |
| 399 | |
| 400 | /** |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 401 | * struct asic_fixed_properties - ASIC specific immutable properties. |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 402 | * @hw_queues_props: H/W queues properties. |
Oded Gabbay | 2f55342 | 2020-08-15 16:28:10 +0300 | [diff] [blame] | 403 | * @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] | 404 | * available sensors. |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 405 | * @uboot_ver: F/W U-boot version. |
| 406 | * @preboot_ver: F/W Preboot version. |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 407 | * @dmmu: DRAM MMU address translation properties. |
| 408 | * @pmmu: PCI (host) MMU address translation properties. |
Omer Shpigelman | 64a7e29 | 2020-01-05 09:05:45 +0000 | [diff] [blame] | 409 | * @pmmu_huge: PCI (host) MMU address translation properties for memory |
| 410 | * allocated with huge pages. |
farah kassabri | 1ae32b9 | 2021-01-31 18:56:03 +0200 | [diff] [blame] | 411 | * @hints_dram_reserved_va_range: dram hint addresses reserved range. |
| 412 | * @hints_host_reserved_va_range: host hint addresses reserved range. |
| 413 | * @hints_host_hpage_reserved_va_range: host huge page hint addresses reserved |
| 414 | * range. |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 415 | * @sram_base_address: SRAM physical start address. |
| 416 | * @sram_end_address: SRAM physical end address. |
| 417 | * @sram_user_base_address - SRAM physical start address for user access. |
| 418 | * @dram_base_address: DRAM physical start address. |
| 419 | * @dram_end_address: DRAM physical end address. |
| 420 | * @dram_user_base_address: DRAM physical start address for user access. |
| 421 | * @dram_size: DRAM total size. |
| 422 | * @dram_pci_bar_size: size of PCI bar towards DRAM. |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 423 | * @max_power_default: max power of the device after reset |
Koby Elbaz | cd5def8 | 2021-02-23 21:31:27 +0200 | [diff] [blame] | 424 | * @dc_power_default: power consumed by the device in mode idle. |
Omer Shpigelman | 27ca384c | 2019-02-28 10:46:11 +0200 | [diff] [blame] | 425 | * @dram_size_for_default_page_mapping: DRAM size needed to map to avoid page |
| 426 | * fault. |
Tomer Tayar | b6f897d | 2019-03-05 16:48:42 +0200 | [diff] [blame] | 427 | * @pcie_dbi_base_address: Base address of the PCIE_DBI block. |
| 428 | * @pcie_aux_dbi_reg_addr: Address of the PCIE_AUX DBI register. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 429 | * @mmu_pgt_addr: base physical address in DRAM of MMU page tables. |
Omer Shpigelman | 27ca384c | 2019-02-28 10:46:11 +0200 | [diff] [blame] | 430 | * @mmu_dram_default_page_addr: DRAM default page physical address. |
Tomer Tayar | ef6a0f6 | 2020-07-09 16:17:48 +0300 | [diff] [blame] | 431 | * @cb_va_start_addr: virtual start address of command buffers which are mapped |
| 432 | * to the device's MMU. |
| 433 | * @cb_va_end_addr: virtual end address of command buffers which are mapped to |
| 434 | * the device's MMU. |
farah kassabri | 1ae32b9 | 2021-01-31 18:56:03 +0200 | [diff] [blame] | 435 | * @dram_hints_align_mask: dram va hint addresses alignment mask which is used |
| 436 | * for hints validity check. |
Oded Gabbay | 2b5bbef | 2021-07-10 21:12:45 +0300 | [diff] [blame] | 437 | * device_dma_offset_for_host_access: the offset to add to host DMA addresses |
| 438 | * to enable the device to access them. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 439 | * @mmu_pgt_size: MMU page tables total size. |
| 440 | * @mmu_pte_size: PTE size in MMU page tables. |
| 441 | * @mmu_hop_table_size: MMU hop table size. |
| 442 | * @mmu_hop0_tables_total_size: total size of MMU hop0 tables. |
| 443 | * @dram_page_size: page size for MMU DRAM allocation. |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 444 | * @cfg_size: configuration space size on SRAM. |
| 445 | * @sram_size: total size of SRAM. |
| 446 | * @max_asid: maximum number of open contexts (ASIDs). |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 447 | * @num_of_events: number of possible internal H/W IRQs. |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 448 | * @psoc_pci_pll_nr: PCI PLL NR value. |
| 449 | * @psoc_pci_pll_nf: PCI PLL NF value. |
| 450 | * @psoc_pci_pll_od: PCI PLL OD value. |
| 451 | * @psoc_pci_pll_div_factor: PCI PLL DIV FACTOR 1 value. |
Adam Aharon | e8edded | 2020-05-26 11:04:30 +0300 | [diff] [blame] | 452 | * @psoc_timestamp_frequency: frequency of the psoc timestamp clock. |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 453 | * @high_pll: high PLL frequency used by the device. |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 454 | * @cb_pool_cb_cnt: number of CBs in the CB pool. |
| 455 | * @cb_pool_cb_size: size of each CB in the CB pool. |
Ofir Bitton | 3abc99b | 2020-06-23 14:50:39 +0300 | [diff] [blame] | 456 | * @max_pending_cs: maximum of concurrent pending command submissions |
| 457 | * @max_queues: maximum amount of queues in the system |
Ohad Sharabi | e67a6040 | 2021-05-02 15:45:21 +0300 | [diff] [blame] | 458 | * @fw_preboot_cpu_boot_dev_sts0: bitmap representation of preboot cpu |
| 459 | * capabilities reported by FW, bit description |
| 460 | * can be found in CPU_BOOT_DEV_STS0 |
| 461 | * @fw_preboot_cpu_boot_dev_sts1: bitmap representation of preboot cpu |
| 462 | * capabilities reported by FW, bit description |
| 463 | * can be found in CPU_BOOT_DEV_STS1 |
| 464 | * @fw_bootfit_cpu_boot_dev_sts0: bitmap representation of boot cpu security |
| 465 | * status reported by FW, bit description can be |
| 466 | * found in CPU_BOOT_DEV_STS0 |
| 467 | * @fw_bootfit_cpu_boot_dev_sts1: bitmap representation of boot cpu security |
| 468 | * status reported by FW, bit description can be |
| 469 | * found in CPU_BOOT_DEV_STS1 |
| 470 | * @fw_app_cpu_boot_dev_sts0: bitmap representation of application security |
| 471 | * status reported by FW, bit description can be |
| 472 | * found in CPU_BOOT_DEV_STS0 |
| 473 | * @fw_app_cpu_boot_dev_sts1: bitmap representation of application security |
| 474 | * status reported by FW, bit description can be |
| 475 | * found in CPU_BOOT_DEV_STS1 |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 476 | * @collective_first_sob: first sync object available for collective use |
| 477 | * @collective_first_mon: first monitor available for collective use |
Ofir Bitton | 21e7a34 | 2020-05-14 18:25:47 +0300 | [diff] [blame] | 478 | * @sync_stream_first_sob: first sync object available for sync stream use |
| 479 | * @sync_stream_first_mon: first monitor available for sync stream use |
Ofir Bitton | 843839b | 2020-07-19 11:08:09 +0300 | [diff] [blame] | 480 | * @first_available_user_sob: first sob available for the user |
| 481 | * @first_available_user_mon: first monitor available for the user |
Ofir Bitton | e1fa724 | 2021-01-06 15:40:37 +0200 | [diff] [blame] | 482 | * @first_available_user_msix_interrupt: first available msix interrupt |
| 483 | * reserved for the user |
Ofir Bitton | e52606d | 2021-01-27 16:34:37 +0200 | [diff] [blame] | 484 | * @first_available_cq: first available CQ for the user. |
Ofir Bitton | 2d44c6f | 2021-01-12 14:43:09 +0200 | [diff] [blame] | 485 | * @user_interrupt_count: number of user interrupts. |
Ofir Bitton | 21e7a34 | 2020-05-14 18:25:47 +0300 | [diff] [blame] | 486 | * @tpc_enabled_mask: which TPCs are enabled. |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 487 | * @completion_queues_count: number of completion queues. |
Ohad Sharabi | 4cb4508 | 2021-05-20 09:09:03 +0300 | [diff] [blame] | 488 | * @fw_security_enabled: true if security measures are enabled in firmware, |
| 489 | * false otherwise |
Ohad Sharabi | e67a6040 | 2021-05-02 15:45:21 +0300 | [diff] [blame] | 490 | * @fw_cpu_boot_dev_sts0_valid: status bits are valid and can be fetched from |
| 491 | * BOOT_DEV_STS0 |
| 492 | * @fw_cpu_boot_dev_sts1_valid: status bits are valid and can be fetched from |
| 493 | * BOOT_DEV_STS1 |
Oded Gabbay | 7f070c9 | 2020-11-09 09:48:31 +0200 | [diff] [blame] | 494 | * @dram_supports_virtual_memory: is there an MMU towards the DRAM |
Ofir Bitton | d611b9f | 2020-11-08 13:10:09 +0200 | [diff] [blame] | 495 | * @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] | 496 | * @num_functional_hbms: number of functional HBMs in each DCORE. |
farah kassabri | 1ae32b9 | 2021-01-31 18:56:03 +0200 | [diff] [blame] | 497 | * @hints_range_reservation: device support hint addresses range reservation. |
Ofir Bitton | 41f458f | 2021-03-10 15:08:44 +0200 | [diff] [blame] | 498 | * @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] | 499 | * @dynamic_fw_load: is dynamic FW load is supported. |
Koby Elbaz | 8121736 | 2021-05-03 23:03:15 +0300 | [diff] [blame] | 500 | * @gic_interrupts_enable: true if FW is not blocking GIC controller, |
| 501 | * false otherwise. |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 502 | */ |
| 503 | struct asic_fixed_properties { |
Ofir Bitton | 3abc99b | 2020-06-23 14:50:39 +0300 | [diff] [blame] | 504 | struct hw_queue_properties *hw_queues_props; |
Oded Gabbay | 2f55342 | 2020-08-15 16:28:10 +0300 | [diff] [blame] | 505 | struct cpucp_info cpucp_info; |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 506 | char uboot_ver[VERSION_MAX_LEN]; |
| 507 | char preboot_ver[VERSION_MAX_LEN]; |
| 508 | struct hl_mmu_properties dmmu; |
| 509 | struct hl_mmu_properties pmmu; |
Omer Shpigelman | 64a7e29 | 2020-01-05 09:05:45 +0000 | [diff] [blame] | 510 | struct hl_mmu_properties pmmu_huge; |
farah kassabri | 1ae32b9 | 2021-01-31 18:56:03 +0200 | [diff] [blame] | 511 | struct hl_hints_range hints_dram_reserved_va_range; |
| 512 | struct hl_hints_range hints_host_reserved_va_range; |
| 513 | struct hl_hints_range hints_host_hpage_reserved_va_range; |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 514 | u64 sram_base_address; |
| 515 | u64 sram_end_address; |
| 516 | u64 sram_user_base_address; |
| 517 | u64 dram_base_address; |
| 518 | u64 dram_end_address; |
| 519 | u64 dram_user_base_address; |
| 520 | u64 dram_size; |
| 521 | u64 dram_pci_bar_size; |
| 522 | u64 max_power_default; |
Koby Elbaz | cd5def8 | 2021-02-23 21:31:27 +0200 | [diff] [blame] | 523 | u64 dc_power_default; |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 524 | u64 dram_size_for_default_page_mapping; |
| 525 | u64 pcie_dbi_base_address; |
| 526 | u64 pcie_aux_dbi_reg_addr; |
| 527 | u64 mmu_pgt_addr; |
| 528 | u64 mmu_dram_default_page_addr; |
Tomer Tayar | ef6a0f6 | 2020-07-09 16:17:48 +0300 | [diff] [blame] | 529 | u64 cb_va_start_addr; |
| 530 | u64 cb_va_end_addr; |
farah kassabri | 1ae32b9 | 2021-01-31 18:56:03 +0200 | [diff] [blame] | 531 | u64 dram_hints_align_mask; |
Oded Gabbay | 2b5bbef | 2021-07-10 21:12:45 +0300 | [diff] [blame] | 532 | u64 device_dma_offset_for_host_access; |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 533 | u32 mmu_pgt_size; |
| 534 | u32 mmu_pte_size; |
| 535 | u32 mmu_hop_table_size; |
| 536 | u32 mmu_hop0_tables_total_size; |
| 537 | u32 dram_page_size; |
| 538 | u32 cfg_size; |
| 539 | u32 sram_size; |
| 540 | u32 max_asid; |
| 541 | u32 num_of_events; |
| 542 | u32 psoc_pci_pll_nr; |
| 543 | u32 psoc_pci_pll_nf; |
| 544 | u32 psoc_pci_pll_od; |
| 545 | u32 psoc_pci_pll_div_factor; |
Adam Aharon | e8edded | 2020-05-26 11:04:30 +0300 | [diff] [blame] | 546 | u32 psoc_timestamp_frequency; |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 547 | u32 high_pll; |
| 548 | u32 cb_pool_cb_cnt; |
| 549 | u32 cb_pool_cb_size; |
Ofir Bitton | c16d45f | 2020-06-02 12:28:27 +0300 | [diff] [blame] | 550 | u32 max_pending_cs; |
Ofir Bitton | 3abc99b | 2020-06-23 14:50:39 +0300 | [diff] [blame] | 551 | u32 max_queues; |
Ohad Sharabi | e67a6040 | 2021-05-02 15:45:21 +0300 | [diff] [blame] | 552 | u32 fw_preboot_cpu_boot_dev_sts0; |
| 553 | u32 fw_preboot_cpu_boot_dev_sts1; |
| 554 | u32 fw_bootfit_cpu_boot_dev_sts0; |
| 555 | u32 fw_bootfit_cpu_boot_dev_sts1; |
| 556 | u32 fw_app_cpu_boot_dev_sts0; |
| 557 | u32 fw_app_cpu_boot_dev_sts1; |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 558 | u16 collective_first_sob; |
| 559 | u16 collective_first_mon; |
Ofir Bitton | 21e7a34 | 2020-05-14 18:25:47 +0300 | [diff] [blame] | 560 | u16 sync_stream_first_sob; |
| 561 | u16 sync_stream_first_mon; |
Ofir Bitton | 843839b | 2020-07-19 11:08:09 +0300 | [diff] [blame] | 562 | u16 first_available_user_sob[HL_MAX_DCORES]; |
| 563 | u16 first_available_user_mon[HL_MAX_DCORES]; |
Ofir Bitton | e1fa724 | 2021-01-06 15:40:37 +0200 | [diff] [blame] | 564 | u16 first_available_user_msix_interrupt; |
Ofir Bitton | e52606d | 2021-01-27 16:34:37 +0200 | [diff] [blame] | 565 | u16 first_available_cq[HL_MAX_DCORES]; |
Ofir Bitton | 2d44c6f | 2021-01-12 14:43:09 +0200 | [diff] [blame] | 566 | u16 user_interrupt_count; |
Omer Shpigelman | 54bb674 | 2019-11-14 18:23:55 +0000 | [diff] [blame] | 567 | u8 tpc_enabled_mask; |
| 568 | u8 completion_queues_count; |
Ohad Sharabi | 4cb4508 | 2021-05-20 09:09:03 +0300 | [diff] [blame] | 569 | u8 fw_security_enabled; |
Ohad Sharabi | e67a6040 | 2021-05-02 15:45:21 +0300 | [diff] [blame] | 570 | u8 fw_cpu_boot_dev_sts0_valid; |
| 571 | u8 fw_cpu_boot_dev_sts1_valid; |
Oded Gabbay | 7f070c9 | 2020-11-09 09:48:31 +0200 | [diff] [blame] | 572 | u8 dram_supports_virtual_memory; |
Ofir Bitton | d611b9f | 2020-11-08 13:10:09 +0200 | [diff] [blame] | 573 | u8 hard_reset_done_by_fw; |
Oded Gabbay | 1530d46 | 2020-12-18 19:12:56 +0200 | [diff] [blame] | 574 | u8 num_functional_hbms; |
farah kassabri | 1ae32b9 | 2021-01-31 18:56:03 +0200 | [diff] [blame] | 575 | u8 hints_range_reservation; |
Ofir Bitton | 41f458f | 2021-03-10 15:08:44 +0200 | [diff] [blame] | 576 | u8 iatu_done_by_fw; |
Ohad Sharabi | 6e16ab6 | 2021-03-25 10:06:26 +0200 | [diff] [blame] | 577 | u8 dynamic_fw_load; |
Koby Elbaz | 8121736 | 2021-05-03 23:03:15 +0300 | [diff] [blame] | 578 | u8 gic_interrupts_enable; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 579 | }; |
| 580 | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 581 | /** |
Ofir Bitton | a98d73c | 2020-07-15 08:52:39 +0300 | [diff] [blame] | 582 | * struct hl_fence - software synchronization primitive |
| 583 | * @completion: fence is implemented using completion |
| 584 | * @refcount: refcount for this fence |
Ofir Bitton | 0811b39 | 2020-12-06 17:18:02 +0200 | [diff] [blame] | 585 | * @cs_sequence: sequence of the corresponding command submission |
Ofir Bitton | a98d73c | 2020-07-15 08:52:39 +0300 | [diff] [blame] | 586 | * @error: mark this fence with error |
Ofir Bitton | bd2f477 | 2020-11-10 17:26:22 +0200 | [diff] [blame] | 587 | * @timestamp: timestamp upon completion |
Ofir Bitton | a98d73c | 2020-07-15 08:52:39 +0300 | [diff] [blame] | 588 | * |
| 589 | */ |
| 590 | struct hl_fence { |
| 591 | struct completion completion; |
| 592 | struct kref refcount; |
Ofir Bitton | 0811b39 | 2020-12-06 17:18:02 +0200 | [diff] [blame] | 593 | u64 cs_sequence; |
Ofir Bitton | a98d73c | 2020-07-15 08:52:39 +0300 | [diff] [blame] | 594 | int error; |
Ofir Bitton | bd2f477 | 2020-11-10 17:26:22 +0200 | [diff] [blame] | 595 | ktime_t timestamp; |
Ofir Bitton | a98d73c | 2020-07-15 08:52:39 +0300 | [diff] [blame] | 596 | }; |
| 597 | |
| 598 | /** |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 599 | * struct hl_cs_compl - command submission completion object. |
Ofir Bitton | 8445dde | 2021-03-18 17:36:57 +0200 | [diff] [blame] | 600 | * @sob_reset_work: workqueue object to run SOB reset flow. |
Ofir Bitton | a98d73c | 2020-07-15 08:52:39 +0300 | [diff] [blame] | 601 | * @base_fence: hl fence object. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 602 | * @lock: spinlock to protect fence. |
| 603 | * @hdev: habanalabs device structure. |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 604 | * @hw_sob: the H/W SOB used in this signal/wait CS. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 605 | * @cs_seq: command submission sequence number. |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 606 | * @type: type of the CS - signal/wait. |
| 607 | * @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] | 608 | * @sob_group: the SOB group that is used in this collective wait CS. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 609 | */ |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 610 | struct hl_cs_compl { |
Ofir Bitton | 8445dde | 2021-03-18 17:36:57 +0200 | [diff] [blame] | 611 | struct work_struct sob_reset_work; |
Ofir Bitton | a98d73c | 2020-07-15 08:52:39 +0300 | [diff] [blame] | 612 | struct hl_fence base_fence; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 613 | spinlock_t lock; |
| 614 | struct hl_device *hdev; |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 615 | struct hl_hw_sob *hw_sob; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 616 | u64 cs_seq; |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 617 | enum hl_cs_type type; |
| 618 | u16 sob_val; |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 619 | u16 sob_group; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 620 | }; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 621 | |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 622 | /* |
| 623 | * Command Buffers |
| 624 | */ |
| 625 | |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 626 | /** |
| 627 | * struct hl_cb_mgr - describes a Command Buffer Manager. |
| 628 | * @cb_lock: protects cb_handles. |
| 629 | * @cb_handles: an idr to hold all command buffer handles. |
| 630 | */ |
| 631 | struct hl_cb_mgr { |
| 632 | spinlock_t cb_lock; |
| 633 | struct idr cb_handles; /* protected by cb_lock */ |
| 634 | }; |
| 635 | |
| 636 | /** |
| 637 | * struct hl_cb - describes a Command Buffer. |
| 638 | * @refcount: reference counter for usage of the CB. |
| 639 | * @hdev: pointer to device this CB belongs to. |
Tomer Tayar | fa8641a1 | 2020-09-07 17:36:41 +0300 | [diff] [blame] | 640 | * @ctx: pointer to the CB owner's context. |
Tomer Tayar | f0748674 | 2020-08-02 22:51:31 +0300 | [diff] [blame] | 641 | * @lock: spinlock to protect mmap flows. |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 642 | * @debugfs_list: node in debugfs list of command buffers. |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 643 | * @pool_list: node in pool list of command buffers. |
Tomer Tayar | ef6a0f6 | 2020-07-09 16:17:48 +0300 | [diff] [blame] | 644 | * @va_block_list: list of virtual addresses blocks of the CB if it is mapped to |
| 645 | * the device's MMU. |
Oded Gabbay | f5b9c8c | 2020-08-12 10:11:20 +0300 | [diff] [blame] | 646 | * @id: the CB's ID. |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 647 | * @kernel_address: Holds the CB's kernel virtual address. |
| 648 | * @bus_address: Holds the CB's DMA address. |
| 649 | * @mmap_size: Holds the CB's size that was mmaped. |
| 650 | * @size: holds the CB's size. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 651 | * @cs_cnt: holds number of CS that this CB participates in. |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 652 | * @mmap: true if the CB is currently mmaped to user. |
| 653 | * @is_pool: true if CB was acquired from the pool, false otherwise. |
Ofir Bitton | a04b7cd | 2020-07-13 13:36:55 +0300 | [diff] [blame] | 654 | * @is_internal: internaly allocated |
Tomer Tayar | ef6a0f6 | 2020-07-09 16:17:48 +0300 | [diff] [blame] | 655 | * @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] | 656 | */ |
| 657 | struct hl_cb { |
| 658 | struct kref refcount; |
| 659 | struct hl_device *hdev; |
Tomer Tayar | fa8641a1 | 2020-09-07 17:36:41 +0300 | [diff] [blame] | 660 | struct hl_ctx *ctx; |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 661 | spinlock_t lock; |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 662 | struct list_head debugfs_list; |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 663 | struct list_head pool_list; |
Tomer Tayar | ef6a0f6 | 2020-07-09 16:17:48 +0300 | [diff] [blame] | 664 | struct list_head va_block_list; |
Oded Gabbay | f5b9c8c | 2020-08-12 10:11:20 +0300 | [diff] [blame] | 665 | u64 id; |
Arnd Bergmann | 82948e6 | 2020-10-26 17:08:06 +0100 | [diff] [blame] | 666 | void *kernel_address; |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 667 | dma_addr_t bus_address; |
| 668 | u32 mmap_size; |
| 669 | u32 size; |
Tomer Tayar | f0748674 | 2020-08-02 22:51:31 +0300 | [diff] [blame] | 670 | atomic_t cs_cnt; |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 671 | u8 mmap; |
| 672 | u8 is_pool; |
Ofir Bitton | a04b7cd | 2020-07-13 13:36:55 +0300 | [diff] [blame] | 673 | u8 is_internal; |
Tomer Tayar | ef6a0f6 | 2020-07-09 16:17:48 +0300 | [diff] [blame] | 674 | u8 is_mmu_mapped; |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 675 | }; |
| 676 | |
| 677 | |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 678 | /* |
| 679 | * QUEUES |
| 680 | */ |
| 681 | |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 682 | struct hl_cs; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 683 | struct hl_cs_job; |
| 684 | |
Ofir Bitton | dd9efab | 2020-06-15 12:09:50 +0300 | [diff] [blame] | 685 | /* Queue length of external and HW queues */ |
| 686 | #define HL_QUEUE_LENGTH 4096 |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 687 | #define HL_QUEUE_SIZE_IN_BYTES (HL_QUEUE_LENGTH * HL_BD_SIZE) |
| 688 | |
Ofir Bitton | 22cb855 | 2020-07-08 10:16:27 +0300 | [diff] [blame] | 689 | #if (HL_MAX_JOBS_PER_CS > HL_QUEUE_LENGTH) |
| 690 | #error "HL_QUEUE_LENGTH must be greater than HL_MAX_JOBS_PER_CS" |
| 691 | #endif |
| 692 | |
Ofir Bitton | dd9efab | 2020-06-15 12:09:50 +0300 | [diff] [blame] | 693 | /* HL_CQ_LENGTH is in units of struct hl_cq_entry */ |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 694 | #define HL_CQ_LENGTH HL_QUEUE_LENGTH |
| 695 | #define HL_CQ_SIZE_IN_BYTES (HL_CQ_LENGTH * HL_CQ_ENTRY_SIZE) |
| 696 | |
Ofir Bitton | dd9efab | 2020-06-15 12:09:50 +0300 | [diff] [blame] | 697 | /* Must be power of 2 */ |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 698 | #define HL_EQ_LENGTH 64 |
| 699 | #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] | 700 | |
Oded Gabbay | 6138bbe | 2020-09-04 20:18:16 +0300 | [diff] [blame] | 701 | /* Host <-> CPU-CP shared memory size */ |
Oded Gabbay | 95b5a8b | 2019-05-29 17:30:04 +0300 | [diff] [blame] | 702 | #define HL_CPU_ACCESSIBLE_MEM_SIZE SZ_2M |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 703 | |
| 704 | /** |
Ofir Bitton | 3cf74b3 | 2020-09-10 09:17:50 +0300 | [diff] [blame] | 705 | * struct hl_sync_stream_properties - |
| 706 | * describes a H/W queue sync stream properties |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 707 | * @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] | 708 | * @next_sob_val: the next value to use for the currently used SOB. |
| 709 | * @base_sob_id: the base SOB id of the SOBs used by this queue. |
| 710 | * @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] | 711 | * @collective_mstr_mon_id: the MON ids of the MONs used by this master queue |
| 712 | * in order to sync with all slave queues. |
| 713 | * @collective_slave_mon_id: the MON id used by this slave queue in order to |
| 714 | * sync with its master queue. |
| 715 | * @collective_sob_id: current SOB id used by this collective slave queue |
| 716 | * to signal its collective master queue upon completion. |
Ofir Bitton | 3cf74b3 | 2020-09-10 09:17:50 +0300 | [diff] [blame] | 717 | * @curr_sob_offset: the id offset to the currently used SOB from the |
| 718 | * HL_RSVD_SOBS that are being used by this queue. |
| 719 | */ |
| 720 | struct hl_sync_stream_properties { |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 721 | struct hl_hw_sob hw_sob[HL_RSVD_SOBS]; |
| 722 | u16 next_sob_val; |
| 723 | u16 base_sob_id; |
| 724 | u16 base_mon_id; |
| 725 | u16 collective_mstr_mon_id[HL_COLLECTIVE_RSVD_MSTR_MONS]; |
| 726 | u16 collective_slave_mon_id; |
| 727 | u16 collective_sob_id; |
| 728 | u8 curr_sob_offset; |
Ofir Bitton | 3cf74b3 | 2020-09-10 09:17:50 +0300 | [diff] [blame] | 729 | }; |
| 730 | |
| 731 | /** |
| 732 | * struct hl_hw_queue - describes a H/W transport queue. |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 733 | * @shadow_queue: pointer to a shadow queue that holds pointers to jobs. |
Ofir Bitton | 3cf74b3 | 2020-09-10 09:17:50 +0300 | [diff] [blame] | 734 | * @sync_stream_prop: sync stream queue properties |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 735 | * @queue_type: type of queue. |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 736 | * @collective_mode: collective mode of current queue |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 737 | * @kernel_address: holds the queue's kernel virtual address. |
| 738 | * @bus_address: holds the queue's DMA address. |
| 739 | * @pi: holds the queue's pi value. |
| 740 | * @ci: holds the queue's ci value, AS CALCULATED BY THE DRIVER (not real ci). |
| 741 | * @hw_queue_id: the id of the H/W queue. |
Omer Shpigelman | 1fa185c | 2020-03-01 19:59:39 +0200 | [diff] [blame] | 742 | * @cq_id: the id for the corresponding CQ for this H/W queue. |
| 743 | * @msi_vec: the IRQ number of the H/W queue. |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 744 | * @int_queue_len: length of internal queue (number of entries). |
| 745 | * @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] | 746 | * exist). |
Ofir Bitton | 21e7a34 | 2020-05-14 18:25:47 +0300 | [diff] [blame] | 747 | * @supports_sync_stream: True if queue supports sync stream |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 748 | */ |
| 749 | struct hl_hw_queue { |
Ofir Bitton | 3cf74b3 | 2020-09-10 09:17:50 +0300 | [diff] [blame] | 750 | struct hl_cs_job **shadow_queue; |
| 751 | struct hl_sync_stream_properties sync_stream_prop; |
| 752 | enum hl_queue_type queue_type; |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 753 | enum hl_collective_mode collective_mode; |
Ofir Bitton | 3cf74b3 | 2020-09-10 09:17:50 +0300 | [diff] [blame] | 754 | void *kernel_address; |
| 755 | dma_addr_t bus_address; |
| 756 | u32 pi; |
| 757 | atomic_t ci; |
| 758 | u32 hw_queue_id; |
| 759 | u32 cq_id; |
| 760 | u32 msi_vec; |
| 761 | u16 int_queue_len; |
| 762 | u8 valid; |
| 763 | u8 supports_sync_stream; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 764 | }; |
| 765 | |
| 766 | /** |
| 767 | * struct hl_cq - describes a completion queue |
| 768 | * @hdev: pointer to the device structure |
| 769 | * @kernel_address: holds the queue's kernel virtual address |
| 770 | * @bus_address: holds the queue's DMA address |
Ofir Bitton | 5574cb2 | 2020-07-05 13:35:51 +0300 | [diff] [blame] | 771 | * @cq_idx: completion queue index in array |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 772 | * @hw_queue_id: the id of the matching H/W queue |
| 773 | * @ci: ci inside the queue |
| 774 | * @pi: pi inside the queue |
| 775 | * @free_slots_cnt: counter of free slots in queue |
| 776 | */ |
| 777 | struct hl_cq { |
| 778 | struct hl_device *hdev; |
Arnd Bergmann | 82948e6 | 2020-10-26 17:08:06 +0100 | [diff] [blame] | 779 | void *kernel_address; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 780 | dma_addr_t bus_address; |
Ofir Bitton | 5574cb2 | 2020-07-05 13:35:51 +0300 | [diff] [blame] | 781 | u32 cq_idx; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 782 | u32 hw_queue_id; |
| 783 | u32 ci; |
| 784 | u32 pi; |
| 785 | atomic_t free_slots_cnt; |
| 786 | }; |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 787 | |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 788 | /** |
Ofir Bitton | 2d44c6f | 2021-01-12 14:43:09 +0200 | [diff] [blame] | 789 | * struct hl_user_interrupt - holds user interrupt information |
| 790 | * @hdev: pointer to the device structure |
Ofir Bitton | ab5f5c3 | 2021-01-12 18:37:19 +0200 | [diff] [blame] | 791 | * @wait_list_head: head to the list of user threads pending on this interrupt |
| 792 | * @wait_list_lock: protects wait_list_head |
Ofir Bitton | 2d44c6f | 2021-01-12 14:43:09 +0200 | [diff] [blame] | 793 | * @interrupt_id: msix interrupt id |
| 794 | */ |
| 795 | struct hl_user_interrupt { |
| 796 | struct hl_device *hdev; |
Ofir Bitton | ab5f5c3 | 2021-01-12 18:37:19 +0200 | [diff] [blame] | 797 | struct list_head wait_list_head; |
| 798 | spinlock_t wait_list_lock; |
Ofir Bitton | 2d44c6f | 2021-01-12 14:43:09 +0200 | [diff] [blame] | 799 | u32 interrupt_id; |
| 800 | }; |
| 801 | |
| 802 | /** |
Ofir Bitton | ab5f5c3 | 2021-01-12 18:37:19 +0200 | [diff] [blame] | 803 | * struct hl_user_pending_interrupt - holds a context to a user thread |
| 804 | * pending on an interrupt |
| 805 | * @wait_list_node: node in the list of user threads pending on an interrupt |
| 806 | * @fence: hl fence object for interrupt completion |
| 807 | */ |
| 808 | struct hl_user_pending_interrupt { |
| 809 | struct list_head wait_list_node; |
| 810 | struct hl_fence fence; |
| 811 | }; |
| 812 | |
| 813 | /** |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 814 | * struct hl_eq - describes the event queue (single one per device) |
| 815 | * @hdev: pointer to the device structure |
| 816 | * @kernel_address: holds the queue's kernel virtual address |
| 817 | * @bus_address: holds the queue's DMA address |
| 818 | * @ci: ci inside the queue |
Oded Gabbay | 1242e9f | 2021-05-19 14:52:14 +0300 | [diff] [blame] | 819 | * @prev_eqe_index: the index of the previous event queue entry. The index of |
| 820 | * the current entry's index must be +1 of the previous one. |
| 821 | * @check_eqe_index: do we need to check the index of the current entry vs. the |
| 822 | * previous one. This is for backward compatibility with older |
| 823 | * firmwares |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 824 | */ |
| 825 | struct hl_eq { |
| 826 | struct hl_device *hdev; |
Arnd Bergmann | 82948e6 | 2020-10-26 17:08:06 +0100 | [diff] [blame] | 827 | void *kernel_address; |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 828 | dma_addr_t bus_address; |
| 829 | u32 ci; |
Oded Gabbay | 1242e9f | 2021-05-19 14:52:14 +0300 | [diff] [blame] | 830 | u32 prev_eqe_index; |
| 831 | bool check_eqe_index; |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 832 | }; |
| 833 | |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 834 | |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 835 | /* |
| 836 | * ASICs |
| 837 | */ |
| 838 | |
| 839 | /** |
| 840 | * enum hl_asic_type - supported ASIC types. |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 841 | * @ASIC_INVALID: Invalid ASIC type. |
Oded Gabbay | 2959384 | 2019-04-04 14:33:34 +0300 | [diff] [blame] | 842 | * @ASIC_GOYA: Goya device. |
Oded Gabbay | 6966d9e | 2020-03-21 10:58:32 +0200 | [diff] [blame] | 843 | * @ASIC_GAUDI: Gaudi device. |
Ofir Bitton | e5042a6 | 2021-04-01 13:43:40 +0300 | [diff] [blame] | 844 | * @ASIC_GAUDI_SEC: Gaudi secured device (HL-2000). |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 845 | */ |
| 846 | enum hl_asic_type { |
Oded Gabbay | 2959384 | 2019-04-04 14:33:34 +0300 | [diff] [blame] | 847 | ASIC_INVALID, |
Oded Gabbay | 6966d9e | 2020-03-21 10:58:32 +0200 | [diff] [blame] | 848 | ASIC_GOYA, |
Ofir Bitton | e5042a6 | 2021-04-01 13:43:40 +0300 | [diff] [blame] | 849 | ASIC_GAUDI, |
| 850 | ASIC_GAUDI_SEC |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 851 | }; |
| 852 | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 853 | struct hl_cs_parser; |
| 854 | |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 855 | /** |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 856 | * enum hl_pm_mng_profile - power management profile. |
Oded Gabbay | 4c172bb | 2019-08-30 16:59:33 +0300 | [diff] [blame] | 857 | * @PM_AUTO: internal clock is set by the Linux driver. |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 858 | * @PM_MANUAL: internal clock is set by the user. |
| 859 | * @PM_LAST: last power management type. |
| 860 | */ |
| 861 | enum hl_pm_mng_profile { |
| 862 | PM_AUTO = 1, |
| 863 | PM_MANUAL, |
| 864 | PM_LAST |
| 865 | }; |
| 866 | |
| 867 | /** |
| 868 | * enum hl_pll_frequency - PLL frequency. |
| 869 | * @PLL_HIGH: high frequency. |
| 870 | * @PLL_LOW: low frequency. |
| 871 | * @PLL_LAST: last frequency values that were configured by the user. |
| 872 | */ |
| 873 | enum hl_pll_frequency { |
| 874 | PLL_HIGH = 1, |
| 875 | PLL_LOW, |
| 876 | PLL_LAST |
| 877 | }; |
| 878 | |
Adam Aharon | e8edded | 2020-05-26 11:04:30 +0300 | [diff] [blame] | 879 | #define PLL_REF_CLK 50 |
| 880 | |
| 881 | enum div_select_defs { |
| 882 | DIV_SEL_REF_CLK = 0, |
| 883 | DIV_SEL_PLL_CLK = 1, |
| 884 | DIV_SEL_DIVIDED_REF = 2, |
| 885 | DIV_SEL_DIVIDED_PLL = 3, |
| 886 | }; |
| 887 | |
Ohad Sharabi | c592c27 | 2021-04-21 13:03:21 +0300 | [diff] [blame] | 888 | enum pci_region { |
| 889 | PCI_REGION_CFG, |
| 890 | PCI_REGION_SRAM, |
| 891 | PCI_REGION_DRAM, |
| 892 | PCI_REGION_SP_SRAM, |
| 893 | PCI_REGION_NUMBER, |
| 894 | }; |
| 895 | |
| 896 | /** |
| 897 | * struct pci_mem_region - describe memory region in a PCI bar |
| 898 | * @region_base: region base address |
| 899 | * @region_size: region size |
Ohad Sharabi | b31e59b | 2021-04-22 10:01:22 +0300 | [diff] [blame] | 900 | * @bar_size: size of the BAR |
Ohad Sharabi | c592c27 | 2021-04-21 13:03:21 +0300 | [diff] [blame] | 901 | * @offset_in_bar: region offset into the bar |
| 902 | * @bar_id: bar ID of the region |
| 903 | * @used: if used 1, otherwise 0 |
| 904 | */ |
| 905 | struct pci_mem_region { |
| 906 | u64 region_base; |
| 907 | u64 region_size; |
Ohad Sharabi | b31e59b | 2021-04-22 10:01:22 +0300 | [diff] [blame] | 908 | u64 bar_size; |
Ohad Sharabi | c592c27 | 2021-04-21 13:03:21 +0300 | [diff] [blame] | 909 | u32 offset_in_bar; |
| 910 | u8 bar_id; |
| 911 | u8 used; |
| 912 | }; |
| 913 | |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 914 | /** |
Ohad Sharabi | 22a795b | 2021-04-08 13:42:00 +0300 | [diff] [blame] | 915 | * struct static_fw_load_mgr - static FW load manager |
Ohad Sharabi | 50f036d | 2021-04-11 15:26:28 +0300 | [diff] [blame] | 916 | * @preboot_version_max_off: max offset to preboot version |
| 917 | * @boot_fit_version_max_off: max offset to boot fit version |
Ohad Sharabi | 8a43c83 | 2021-04-11 10:32:18 +0300 | [diff] [blame] | 918 | * @kmd_msg_to_cpu_reg: register address for KDM->CPU messages |
| 919 | * @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] | 920 | * @cpu_boot_status_reg: boot status register |
Ohad Sharabi | e67a6040 | 2021-05-02 15:45:21 +0300 | [diff] [blame] | 921 | * @cpu_boot_dev_status0_reg: boot device status register 0 |
| 922 | * @cpu_boot_dev_status1_reg: boot device status register 1 |
| 923 | * @boot_err0_reg: boot error register 0 |
| 924 | * @boot_err1_reg: boot error register 1 |
Ohad Sharabi | 50f036d | 2021-04-11 15:26:28 +0300 | [diff] [blame] | 925 | * @preboot_version_offset_reg: SRAM offset to preboot version register |
| 926 | * @boot_fit_version_offset_reg: SRAM offset to boot fit version register |
| 927 | * @sram_offset_mask: mask for getting offset into the SRAM |
Koby Elbaz | b7a71fd | 2021-06-15 17:07:02 +0300 | [diff] [blame] | 928 | * @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] | 929 | */ |
Ohad Sharabi | 22a795b | 2021-04-08 13:42:00 +0300 | [diff] [blame] | 930 | struct static_fw_load_mgr { |
Ohad Sharabi | 50f036d | 2021-04-11 15:26:28 +0300 | [diff] [blame] | 931 | u64 preboot_version_max_off; |
| 932 | u64 boot_fit_version_max_off; |
Ohad Sharabi | 8a43c83 | 2021-04-11 10:32:18 +0300 | [diff] [blame] | 933 | u32 kmd_msg_to_cpu_reg; |
| 934 | u32 cpu_cmd_status_to_host_reg; |
Ohad Sharabi | a22f0ec | 2021-04-11 23:06:46 +0300 | [diff] [blame] | 935 | u32 cpu_boot_status_reg; |
Ohad Sharabi | e67a6040 | 2021-05-02 15:45:21 +0300 | [diff] [blame] | 936 | u32 cpu_boot_dev_status0_reg; |
| 937 | u32 cpu_boot_dev_status1_reg; |
Ohad Sharabi | a22f0ec | 2021-04-11 23:06:46 +0300 | [diff] [blame] | 938 | u32 boot_err0_reg; |
Ohad Sharabi | e67a6040 | 2021-05-02 15:45:21 +0300 | [diff] [blame] | 939 | u32 boot_err1_reg; |
Ohad Sharabi | 50f036d | 2021-04-11 15:26:28 +0300 | [diff] [blame] | 940 | u32 preboot_version_offset_reg; |
| 941 | u32 boot_fit_version_offset_reg; |
| 942 | u32 sram_offset_mask; |
Koby Elbaz | b7a71fd | 2021-06-15 17:07:02 +0300 | [diff] [blame] | 943 | u32 cpu_reset_wait_msec; |
Ohad Sharabi | 22a795b | 2021-04-08 13:42:00 +0300 | [diff] [blame] | 944 | }; |
| 945 | |
| 946 | /** |
Ohad Sharabi | 8a43c83 | 2021-04-11 10:32:18 +0300 | [diff] [blame] | 947 | * struct fw_response - FW response to LKD command |
| 948 | * @ram_offset: descriptor offset into the RAM |
| 949 | * @ram_type: RAM type containing the descriptor (SRAM/DRAM) |
| 950 | * @status: command status |
| 951 | */ |
| 952 | struct fw_response { |
| 953 | u32 ram_offset; |
| 954 | u8 ram_type; |
| 955 | u8 status; |
| 956 | }; |
| 957 | |
| 958 | /** |
Ohad Sharabi | 22a795b | 2021-04-08 13:42:00 +0300 | [diff] [blame] | 959 | * struct dynamic_fw_load_mgr - dynamic FW load manager |
Ohad Sharabi | 8a43c83 | 2021-04-11 10:32:18 +0300 | [diff] [blame] | 960 | * @response: FW to LKD response |
| 961 | * @comm_desc: the communication descriptor with FW |
| 962 | * @image_region: region to copy the FW image to |
Ohad Sharabi | b31e59b | 2021-04-22 10:01:22 +0300 | [diff] [blame] | 963 | * @fw_image_size: size of FW image to load |
| 964 | * @wait_for_bl_timeout: timeout for waiting for boot loader to respond |
Ohad Sharabi | 22a795b | 2021-04-08 13:42:00 +0300 | [diff] [blame] | 965 | */ |
| 966 | struct dynamic_fw_load_mgr { |
Ohad Sharabi | 8a43c83 | 2021-04-11 10:32:18 +0300 | [diff] [blame] | 967 | struct fw_response response; |
| 968 | struct lkd_fw_comms_desc comm_desc; |
| 969 | struct pci_mem_region *image_region; |
| 970 | size_t fw_image_size; |
Ohad Sharabi | b31e59b | 2021-04-22 10:01:22 +0300 | [diff] [blame] | 971 | u32 wait_for_bl_timeout; |
Ohad Sharabi | 8a43c83 | 2021-04-11 10:32:18 +0300 | [diff] [blame] | 972 | }; |
| 973 | |
| 974 | /** |
| 975 | * struct fw_image_props - properties of FW image |
| 976 | * @image_name: name of the image |
| 977 | * @src_off: offset in src FW to copy from |
| 978 | * @copy_size: amount of bytes to copy (0 to copy the whole binary) |
| 979 | */ |
| 980 | struct fw_image_props { |
| 981 | char *image_name; |
| 982 | u32 src_off; |
| 983 | u32 copy_size; |
Ohad Sharabi | 22a795b | 2021-04-08 13:42:00 +0300 | [diff] [blame] | 984 | }; |
| 985 | |
| 986 | /** |
| 987 | * struct fw_load_mgr - manager FW loading process |
Ohad Sharabi | 8a43c83 | 2021-04-11 10:32:18 +0300 | [diff] [blame] | 988 | * @dynamic_loader: specific structure for dynamic load |
| 989 | * @static_loader: specific structure for static load |
| 990 | * @boot_fit_img: boot fit image properties |
| 991 | * @linux_img: linux image properties |
Ohad Sharabi | 22a795b | 2021-04-08 13:42:00 +0300 | [diff] [blame] | 992 | * @cpu_timeout: CPU response timeout in usec |
| 993 | * @boot_fit_timeout: Boot fit load timeout in usec |
| 994 | * @skip_bmc: should BMC be skipped |
| 995 | * @sram_bar_id: SRAM bar ID |
Ohad Sharabi | 8a43c83 | 2021-04-11 10:32:18 +0300 | [diff] [blame] | 996 | * @dram_bar_id: DRAM bar ID |
Koby Elbaz | 3649eae | 2021-05-18 15:43:47 +0300 | [diff] [blame] | 997 | * @linux_loaded: true if linux was loaded so far |
Ohad Sharabi | 22a795b | 2021-04-08 13:42:00 +0300 | [diff] [blame] | 998 | */ |
| 999 | struct fw_load_mgr { |
Ohad Sharabi | 8a43c83 | 2021-04-11 10:32:18 +0300 | [diff] [blame] | 1000 | union { |
| 1001 | struct dynamic_fw_load_mgr dynamic_loader; |
| 1002 | struct static_fw_load_mgr static_loader; |
| 1003 | }; |
| 1004 | struct fw_image_props boot_fit_img; |
| 1005 | struct fw_image_props linux_img; |
Ohad Sharabi | a22f0ec | 2021-04-11 23:06:46 +0300 | [diff] [blame] | 1006 | u32 cpu_timeout; |
| 1007 | u32 boot_fit_timeout; |
| 1008 | u8 skip_bmc; |
Ohad Sharabi | 50f036d | 2021-04-11 15:26:28 +0300 | [diff] [blame] | 1009 | u8 sram_bar_id; |
Ohad Sharabi | 8a43c83 | 2021-04-11 10:32:18 +0300 | [diff] [blame] | 1010 | u8 dram_bar_id; |
Koby Elbaz | 3649eae | 2021-05-18 15:43:47 +0300 | [diff] [blame] | 1011 | u8 linux_loaded; |
Ohad Sharabi | a22f0ec | 2021-04-11 23:06:46 +0300 | [diff] [blame] | 1012 | }; |
| 1013 | |
| 1014 | /** |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 1015 | * struct hl_asic_funcs - ASIC specific functions that are can be called from |
| 1016 | * common code. |
| 1017 | * @early_init: sets up early driver state (pre sw_init), doesn't configure H/W. |
| 1018 | * @early_fini: tears down what was done in early_init. |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 1019 | * @late_init: sets up late driver/hw state (post hw_init) - Optional. |
| 1020 | * @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] | 1021 | * @sw_init: sets up driver state, does not configure H/W. |
| 1022 | * @sw_fini: tears down driver state, does not configure H/W. |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 1023 | * @hw_init: sets up the H/W state. |
| 1024 | * @hw_fini: tears down the H/W state. |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 1025 | * @halt_engines: halt engines, needed for reset sequence. This also disables |
| 1026 | * interrupts from the device. Should be called before |
| 1027 | * hw_fini and before CS rollback. |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 1028 | * @suspend: handles IP specific H/W or SW changes for suspend. |
| 1029 | * @resume: handles IP specific H/W or SW changes for resume. |
Zvika Yehudai | 1ee8e2b | 2021-07-06 13:50:32 +0300 | [diff] [blame] | 1030 | * @mmap: maps a memory. |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1031 | * @ring_doorbell: increment PI on a given QMAN. |
Oded Gabbay | b9040c9 | 2019-08-08 15:45:58 +0300 | [diff] [blame] | 1032 | * @pqe_write: Write the PQ entry to the PQ. This is ASIC-specific |
| 1033 | * function because the PQs are located in different memory areas |
| 1034 | * per ASIC (SRAM, DRAM, Host memory) and therefore, the method of |
| 1035 | * writing the PQE must match the destination memory area |
| 1036 | * properties. |
Oded Gabbay | d9c3aa8 | 2019-05-01 11:47:04 +0300 | [diff] [blame] | 1037 | * @asic_dma_alloc_coherent: Allocate coherent DMA memory by calling |
| 1038 | * dma_alloc_coherent(). This is ASIC function because |
| 1039 | * its implementation is not trivial when the driver |
| 1040 | * is loaded in simulation mode (not upstreamed). |
| 1041 | * @asic_dma_free_coherent: Free coherent DMA memory by calling |
| 1042 | * dma_free_coherent(). This is ASIC function because |
| 1043 | * its implementation is not trivial when the driver |
| 1044 | * is loaded in simulation mode (not upstreamed). |
farah kassabri | 03df136 | 2020-05-06 11:17:38 +0300 | [diff] [blame] | 1045 | * @scrub_device_mem: Scrub device memory given an address and size |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1046 | * @get_int_queue_base: get the internal queue base address. |
| 1047 | * @test_queues: run simple test on all queues for sanity check. |
Oded Gabbay | d9c3aa8 | 2019-05-01 11:47:04 +0300 | [diff] [blame] | 1048 | * @asic_dma_pool_zalloc: small DMA allocation of coherent memory from DMA pool. |
| 1049 | * size of allocation is HL_DMA_POOL_BLK_SIZE. |
| 1050 | * @asic_dma_pool_free: free small DMA allocation from pool. |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1051 | * @cpu_accessible_dma_pool_alloc: allocate CPU PQ packet from DMA pool. |
| 1052 | * @cpu_accessible_dma_pool_free: free CPU PQ packet from DMA pool. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1053 | * @hl_dma_unmap_sg: DMA unmap scatter-gather list. |
| 1054 | * @cs_parser: parse Command Submission. |
| 1055 | * @asic_dma_map_sg: DMA map scatter-gather list. |
| 1056 | * @get_dma_desc_list_size: get number of LIN_DMA packets required for CB. |
| 1057 | * @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] | 1058 | * @update_eq_ci: update event queue CI. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1059 | * @context_switch: called upon ASID context switch. |
| 1060 | * @restore_phase_topology: clear all SOBs amd MONs. |
Oded Gabbay | 639781d | 2021-04-02 01:43:18 +0300 | [diff] [blame] | 1061 | * @debugfs_read32: debug interface for reading u32 from DRAM/SRAM/Host memory. |
| 1062 | * @debugfs_write32: debug interface for writing u32 to DRAM/SRAM/Host memory. |
| 1063 | * @debugfs_read64: debug interface for reading u64 from DRAM/SRAM/Host memory. |
| 1064 | * @debugfs_write64: debug interface for writing u64 to DRAM/SRAM/Host memory. |
| 1065 | * @debugfs_read_dma: debug interface for reading up to 2MB from the device's |
| 1066 | * internal memory via DMA engine. |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 1067 | * @add_device_attr: add ASIC specific device attributes. |
Oded Gabbay | 6138bbe | 2020-09-04 20:18:16 +0300 | [diff] [blame] | 1068 | * @handle_eqe: handle event queue entry (IRQ) from CPU-CP. |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 1069 | * @set_pll_profile: change PLL profile (manual/automatic). |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 1070 | * @get_events_stat: retrieve event queue entries histogram. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1071 | * @read_pte: read MMU page table entry from DRAM. |
| 1072 | * @write_pte: write MMU page table entry to DRAM. |
Omer Shpigelman | 7b6e4ea | 2019-11-14 18:23:53 +0000 | [diff] [blame] | 1073 | * @mmu_invalidate_cache: flush MMU STLB host/DRAM cache, either with soft |
| 1074 | * (L1 only) or hard (L0 & L1) flush. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1075 | * @mmu_invalidate_cache_range: flush specific MMU STLB cache lines with |
| 1076 | * ASID-VA-size mask. |
Oded Gabbay | 6138bbe | 2020-09-04 20:18:16 +0300 | [diff] [blame] | 1077 | * @send_heartbeat: send is-alive packet to CPU-CP and verify response. |
Oded Gabbay | e38bfd3 | 2020-07-03 20:46:12 +0300 | [diff] [blame] | 1078 | * @set_clock_gating: enable/disable clock gating per engine according to |
| 1079 | * clock gating mask in hdev |
| 1080 | * @disable_clock_gating: disable clock gating completely |
Omer Shpigelman | 315bc05 | 2019-04-01 22:31:22 +0300 | [diff] [blame] | 1081 | * @debug_coresight: perform certain actions on Coresight for debugging. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1082 | * @is_device_idle: return true if device is idle, false otherwise. |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 1083 | * @soft_reset_late_init: perform certain actions needed after soft reset. |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1084 | * @hw_queues_lock: acquire H/W queues lock. |
| 1085 | * @hw_queues_unlock: release H/W queues lock. |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 1086 | * @get_pci_id: retrieve PCI ID. |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 1087 | * @get_eeprom_data: retrieve EEPROM data from F/W. |
Oded Gabbay | 788cacf | 2020-07-07 17:30:13 +0300 | [diff] [blame] | 1088 | * @send_cpu_message: send message to F/W. If the message is timedout, the |
| 1089 | * driver will eventually reset the device. The timeout can |
| 1090 | * be determined by the calling function or it can be 0 and |
| 1091 | * then the timeout is the default timeout for the specific |
| 1092 | * ASIC |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 1093 | * @get_hw_state: retrieve the H/W state |
Tomer Tayar | b6f897d | 2019-03-05 16:48:42 +0200 | [diff] [blame] | 1094 | * @pci_bars_map: Map PCI BARs. |
Tomer Tayar | b6f897d | 2019-03-05 16:48:42 +0200 | [diff] [blame] | 1095 | * @init_iatu: Initialize the iATU unit inside the PCI controller. |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 1096 | * @rreg: Read a register. Needed for simulator support. |
| 1097 | * @wreg: Write a register. Needed for simulator support. |
Omer Shpigelman | 89225ce | 2019-05-01 14:38:38 +0300 | [diff] [blame] | 1098 | * @halt_coresight: stop the ETF and ETR traces. |
Ofir Bitton | a04b7cd | 2020-07-13 13:36:55 +0300 | [diff] [blame] | 1099 | * @ctx_init: context dependent initialization. |
Ofir Bitton | 5de406c | 2020-09-10 10:56:26 +0300 | [diff] [blame] | 1100 | * @ctx_fini: context dependent cleanup. |
Oded Gabbay | 62c1e12 | 2019-10-10 15:48:59 +0300 | [diff] [blame] | 1101 | * @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] | 1102 | * @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] | 1103 | * @load_firmware_to_device: load the firmware to the device's memory |
Ofir Bitton | 47f6b41 | 2020-04-16 13:47:15 +0300 | [diff] [blame] | 1104 | * @load_boot_fit_to_device: load boot fit to device's memory |
Omer Shpigelman | ec2f8a3 | 2020-05-07 13:43:05 +0300 | [diff] [blame] | 1105 | * @get_signal_cb_size: Get signal CB size. |
| 1106 | * @get_wait_cb_size: Get wait CB size. |
| 1107 | * @gen_signal_cb: Generate a signal CB. |
| 1108 | * @gen_wait_cb: Generate a wait CB. |
| 1109 | * @reset_sob: Reset a SOB. |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 1110 | * @reset_sob_group: Reset SOB group |
Oded Gabbay | cb056b9 | 2020-03-29 13:18:30 +0300 | [diff] [blame] | 1111 | * @set_dma_mask_from_fw: set the DMA mask in the driver according to the |
| 1112 | * firmware configuration |
Tomer Tayar | 25e7aeb | 2020-03-31 22:46:36 +0300 | [diff] [blame] | 1113 | * @get_device_time: Get the device time. |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 1114 | * @collective_wait_init_cs: Generate collective master/slave packets |
| 1115 | * and place them in the relevant cs jobs |
| 1116 | * @collective_wait_create_jobs: allocate collective wait cs jobs |
farah kassabri | 89473a1 | 2021-01-12 17:24:00 +0200 | [diff] [blame] | 1117 | * @scramble_addr: Routine to scramble the address prior of mapping it |
Oded Gabbay | 28bcf1f | 2021-02-01 21:23:43 +0200 | [diff] [blame] | 1118 | * in the MMU. |
farah kassabri | 89473a1 | 2021-01-12 17:24:00 +0200 | [diff] [blame] | 1119 | * @descramble_addr: Routine to de-scramble the address prior of |
Oded Gabbay | 28bcf1f | 2021-02-01 21:23:43 +0200 | [diff] [blame] | 1120 | * showing it to users. |
Ofir Bitton | d2b980f | 2021-01-07 12:14:17 +0200 | [diff] [blame] | 1121 | * @ack_protection_bits_errors: ack and dump all security violations |
Ofir Bitton | d00697f | 2021-01-05 12:55:06 +0200 | [diff] [blame] | 1122 | * @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] | 1123 | * also returns the size of the block if caller supplies |
| 1124 | * a valid pointer for it |
Ofir Bitton | d00697f | 2021-01-05 12:55:06 +0200 | [diff] [blame] | 1125 | * @hw_block_mmap: mmap a HW block with a given id. |
Oded Gabbay | 28bcf1f | 2021-02-01 21:23:43 +0200 | [diff] [blame] | 1126 | * @enable_events_from_fw: send interrupt to firmware to notify them the |
| 1127 | * driver is ready to receive asynchronous events. This |
| 1128 | * function should be called during the first init and |
| 1129 | * after every hard-reset of the device |
Bharat Jauhari | 285c0fa | 2021-03-25 18:15:40 +0200 | [diff] [blame] | 1130 | * @get_msi_info: Retrieve asic-specific MSI ID of the f/w async event |
| 1131 | * @map_pll_idx_to_fw_idx: convert driver specific per asic PLL index to |
| 1132 | * generic f/w compatible PLL Indexes |
Bharat Jauhari | 4b09901 | 2021-05-28 13:14:34 +0300 | [diff] [blame] | 1133 | * @init_firmware_loader: initialize data for FW loader. |
| 1134 | * @init_cpu_scrambler_dram: Enable CPU specific DRAM scrambling |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 1135 | * @state_dump_init: initialize constants required for state dump |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 1136 | */ |
| 1137 | struct hl_asic_funcs { |
| 1138 | int (*early_init)(struct hl_device *hdev); |
| 1139 | int (*early_fini)(struct hl_device *hdev); |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 1140 | int (*late_init)(struct hl_device *hdev); |
| 1141 | void (*late_fini)(struct hl_device *hdev); |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 1142 | int (*sw_init)(struct hl_device *hdev); |
| 1143 | int (*sw_fini)(struct hl_device *hdev); |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 1144 | int (*hw_init)(struct hl_device *hdev); |
| 1145 | void (*hw_fini)(struct hl_device *hdev, bool hard_reset); |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 1146 | void (*halt_engines)(struct hl_device *hdev, bool hard_reset); |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 1147 | int (*suspend)(struct hl_device *hdev); |
| 1148 | int (*resume)(struct hl_device *hdev); |
Zvika Yehudai | 1ee8e2b | 2021-07-06 13:50:32 +0300 | [diff] [blame] | 1149 | int (*mmap)(struct hl_device *hdev, struct vm_area_struct *vma, |
Hillf Danton | 0db5753 | 2020-08-23 07:32:42 +0800 | [diff] [blame] | 1150 | void *cpu_addr, dma_addr_t dma_addr, size_t size); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1151 | 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] | 1152 | void (*pqe_write)(struct hl_device *hdev, __le64 *pqe, |
| 1153 | struct hl_bd *bd); |
Oded Gabbay | d9c3aa8 | 2019-05-01 11:47:04 +0300 | [diff] [blame] | 1154 | void* (*asic_dma_alloc_coherent)(struct hl_device *hdev, size_t size, |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 1155 | dma_addr_t *dma_handle, gfp_t flag); |
Oded Gabbay | d9c3aa8 | 2019-05-01 11:47:04 +0300 | [diff] [blame] | 1156 | void (*asic_dma_free_coherent)(struct hl_device *hdev, size_t size, |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 1157 | void *cpu_addr, dma_addr_t dma_handle); |
farah kassabri | 03df136 | 2020-05-06 11:17:38 +0300 | [diff] [blame] | 1158 | int (*scrub_device_mem)(struct hl_device *hdev, u64 addr, u64 size); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1159 | void* (*get_int_queue_base)(struct hl_device *hdev, u32 queue_id, |
| 1160 | dma_addr_t *dma_handle, u16 *queue_len); |
| 1161 | int (*test_queues)(struct hl_device *hdev); |
Oded Gabbay | d9c3aa8 | 2019-05-01 11:47:04 +0300 | [diff] [blame] | 1162 | void* (*asic_dma_pool_zalloc)(struct hl_device *hdev, size_t size, |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1163 | gfp_t mem_flags, dma_addr_t *dma_handle); |
Oded Gabbay | d9c3aa8 | 2019-05-01 11:47:04 +0300 | [diff] [blame] | 1164 | void (*asic_dma_pool_free)(struct hl_device *hdev, void *vaddr, |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1165 | dma_addr_t dma_addr); |
| 1166 | void* (*cpu_accessible_dma_pool_alloc)(struct hl_device *hdev, |
| 1167 | size_t size, dma_addr_t *dma_handle); |
| 1168 | void (*cpu_accessible_dma_pool_free)(struct hl_device *hdev, |
| 1169 | size_t size, void *vaddr); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1170 | void (*hl_dma_unmap_sg)(struct hl_device *hdev, |
Tomer Tayar | 94cb669 | 2019-05-01 11:28:15 +0300 | [diff] [blame] | 1171 | struct scatterlist *sgl, int nents, |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1172 | enum dma_data_direction dir); |
| 1173 | int (*cs_parser)(struct hl_device *hdev, struct hl_cs_parser *parser); |
| 1174 | int (*asic_dma_map_sg)(struct hl_device *hdev, |
Tomer Tayar | 94cb669 | 2019-05-01 11:28:15 +0300 | [diff] [blame] | 1175 | struct scatterlist *sgl, int nents, |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1176 | enum dma_data_direction dir); |
| 1177 | u32 (*get_dma_desc_list_size)(struct hl_device *hdev, |
| 1178 | struct sg_table *sgt); |
Oded Gabbay | 921a465 | 2019-05-12 16:53:16 +0300 | [diff] [blame] | 1179 | void (*add_end_of_cb_packets)(struct hl_device *hdev, |
Arnd Bergmann | 82948e6 | 2020-10-26 17:08:06 +0100 | [diff] [blame] | 1180 | void *kernel_address, u32 len, |
Oded Gabbay | 926ba4c | 2020-03-31 11:57:11 +0300 | [diff] [blame] | 1181 | u64 cq_addr, u32 cq_val, u32 msix_num, |
| 1182 | bool eb); |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 1183 | void (*update_eq_ci)(struct hl_device *hdev, u32 val); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1184 | int (*context_switch)(struct hl_device *hdev, u32 asid); |
| 1185 | void (*restore_phase_topology)(struct hl_device *hdev); |
Ofir Bitton | a5778d1 | 2021-02-24 11:51:40 +0200 | [diff] [blame] | 1186 | int (*debugfs_read32)(struct hl_device *hdev, u64 addr, |
| 1187 | bool user_address, u32 *val); |
| 1188 | int (*debugfs_write32)(struct hl_device *hdev, u64 addr, |
| 1189 | bool user_address, u32 val); |
| 1190 | int (*debugfs_read64)(struct hl_device *hdev, u64 addr, |
| 1191 | bool user_address, u64 *val); |
| 1192 | int (*debugfs_write64)(struct hl_device *hdev, u64 addr, |
| 1193 | bool user_address, u64 val); |
Oded Gabbay | 639781d | 2021-04-02 01:43:18 +0300 | [diff] [blame] | 1194 | int (*debugfs_read_dma)(struct hl_device *hdev, u64 addr, u32 size, |
| 1195 | void *blob_addr); |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 1196 | void (*add_device_attr)(struct hl_device *hdev, |
| 1197 | struct attribute_group *dev_attr_grp); |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 1198 | void (*handle_eqe)(struct hl_device *hdev, |
| 1199 | struct hl_eq_entry *eq_entry); |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 1200 | void (*set_pll_profile)(struct hl_device *hdev, |
| 1201 | enum hl_pll_frequency freq); |
Oded Gabbay | e973076 | 2019-08-28 21:51:52 +0300 | [diff] [blame] | 1202 | void* (*get_events_stat)(struct hl_device *hdev, bool aggregate, |
| 1203 | u32 *size); |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1204 | u64 (*read_pte)(struct hl_device *hdev, u64 addr); |
| 1205 | void (*write_pte)(struct hl_device *hdev, u64 addr, u64 val); |
Omer Shpigelman | 8ff5f4f | 2020-05-24 23:06:59 +0300 | [diff] [blame] | 1206 | int (*mmu_invalidate_cache)(struct hl_device *hdev, bool is_hard, |
Omer Shpigelman | 7b6e4ea | 2019-11-14 18:23:53 +0000 | [diff] [blame] | 1207 | u32 flags); |
Omer Shpigelman | 8ff5f4f | 2020-05-24 23:06:59 +0300 | [diff] [blame] | 1208 | int (*mmu_invalidate_cache_range)(struct hl_device *hdev, bool is_hard, |
Alon Mizrahi | 08c03a1 | 2021-04-08 15:30:59 +0300 | [diff] [blame] | 1209 | u32 flags, u32 asid, u64 va, u64 size); |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 1210 | int (*send_heartbeat)(struct hl_device *hdev); |
Oded Gabbay | e38bfd3 | 2020-07-03 20:46:12 +0300 | [diff] [blame] | 1211 | void (*set_clock_gating)(struct hl_device *hdev); |
Oded Gabbay | ca62433 | 2020-05-09 12:17:21 +0300 | [diff] [blame] | 1212 | void (*disable_clock_gating)(struct hl_device *hdev); |
Omer Shpigelman | 315bc05 | 2019-04-01 22:31:22 +0300 | [diff] [blame] | 1213 | int (*debug_coresight)(struct hl_device *hdev, void *data); |
Ohad Sharabi | cf30339 | 2021-01-17 16:01:56 +0200 | [diff] [blame] | 1214 | bool (*is_device_idle)(struct hl_device *hdev, u64 *mask_arr, |
| 1215 | u8 mask_len, struct seq_file *s); |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 1216 | int (*soft_reset_late_init)(struct hl_device *hdev); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1217 | void (*hw_queues_lock)(struct hl_device *hdev); |
| 1218 | void (*hw_queues_unlock)(struct hl_device *hdev); |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 1219 | u32 (*get_pci_id)(struct hl_device *hdev); |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 1220 | int (*get_eeprom_data)(struct hl_device *hdev, void *data, |
| 1221 | size_t max_size); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1222 | int (*send_cpu_message)(struct hl_device *hdev, u32 *msg, |
Alon Mizrahi | 439bc47 | 2020-11-10 13:49:10 +0200 | [diff] [blame] | 1223 | u16 len, u32 timeout, u64 *result); |
Tomer Tayar | b6f897d | 2019-03-05 16:48:42 +0200 | [diff] [blame] | 1224 | int (*pci_bars_map)(struct hl_device *hdev); |
Tomer Tayar | b6f897d | 2019-03-05 16:48:42 +0200 | [diff] [blame] | 1225 | int (*init_iatu)(struct hl_device *hdev); |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 1226 | u32 (*rreg)(struct hl_device *hdev, u32 reg); |
| 1227 | void (*wreg)(struct hl_device *hdev, u32 reg, u32 val); |
Omer Shpigelman | 89225ce | 2019-05-01 14:38:38 +0300 | [diff] [blame] | 1228 | void (*halt_coresight)(struct hl_device *hdev); |
Ofir Bitton | a04b7cd | 2020-07-13 13:36:55 +0300 | [diff] [blame] | 1229 | int (*ctx_init)(struct hl_ctx *ctx); |
Ofir Bitton | 5de406c | 2020-09-10 10:56:26 +0300 | [diff] [blame] | 1230 | void (*ctx_fini)(struct hl_ctx *ctx); |
Oded Gabbay | 62c1e12 | 2019-10-10 15:48:59 +0300 | [diff] [blame] | 1231 | 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] | 1232 | 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] | 1233 | int (*load_firmware_to_device)(struct hl_device *hdev); |
Ofir Bitton | 47f6b41 | 2020-04-16 13:47:15 +0300 | [diff] [blame] | 1234 | int (*load_boot_fit_to_device)(struct hl_device *hdev); |
Omer Shpigelman | ec2f8a3 | 2020-05-07 13:43:05 +0300 | [diff] [blame] | 1235 | u32 (*get_signal_cb_size)(struct hl_device *hdev); |
| 1236 | u32 (*get_wait_cb_size)(struct hl_device *hdev); |
Ofir Bitton | 2992c1d | 2020-09-10 09:40:35 +0300 | [diff] [blame] | 1237 | 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] | 1238 | u32 size, bool eb); |
Ofir Bitton | 2992c1d | 2020-09-10 09:40:35 +0300 | [diff] [blame] | 1239 | u32 (*gen_wait_cb)(struct hl_device *hdev, |
Ofir Bitton | 3cf74b3 | 2020-09-10 09:17:50 +0300 | [diff] [blame] | 1240 | struct hl_gen_wait_properties *prop); |
Omer Shpigelman | ec2f8a3 | 2020-05-07 13:43:05 +0300 | [diff] [blame] | 1241 | void (*reset_sob)(struct hl_device *hdev, void *data); |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 1242 | void (*reset_sob_group)(struct hl_device *hdev, u16 sob_group); |
Oded Gabbay | cb056b9 | 2020-03-29 13:18:30 +0300 | [diff] [blame] | 1243 | void (*set_dma_mask_from_fw)(struct hl_device *hdev); |
Tomer Tayar | 25e7aeb | 2020-03-31 22:46:36 +0300 | [diff] [blame] | 1244 | u64 (*get_device_time)(struct hl_device *hdev); |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 1245 | void (*collective_wait_init_cs)(struct hl_cs *cs); |
| 1246 | int (*collective_wait_create_jobs)(struct hl_device *hdev, |
| 1247 | struct hl_ctx *ctx, struct hl_cs *cs, u32 wait_queue_id, |
| 1248 | u32 collective_engine_id); |
farah kassabri | 89473a1 | 2021-01-12 17:24:00 +0200 | [diff] [blame] | 1249 | u64 (*scramble_addr)(struct hl_device *hdev, u64 addr); |
| 1250 | u64 (*descramble_addr)(struct hl_device *hdev, u64 addr); |
Ofir Bitton | d2b980f | 2021-01-07 12:14:17 +0200 | [diff] [blame] | 1251 | void (*ack_protection_bits_errors)(struct hl_device *hdev); |
Ofir Bitton | d00697f | 2021-01-05 12:55:06 +0200 | [diff] [blame] | 1252 | int (*get_hw_block_id)(struct hl_device *hdev, u64 block_addr, |
Oded Gabbay | 6df50d2 | 2021-02-05 16:04:34 +0200 | [diff] [blame] | 1253 | u32 *block_size, u32 *block_id); |
Ofir Bitton | d00697f | 2021-01-05 12:55:06 +0200 | [diff] [blame] | 1254 | int (*hw_block_mmap)(struct hl_device *hdev, struct vm_area_struct *vma, |
| 1255 | u32 block_id, u32 block_size); |
Oded Gabbay | 28bcf1f | 2021-02-01 21:23:43 +0200 | [diff] [blame] | 1256 | void (*enable_events_from_fw)(struct hl_device *hdev); |
Oded Gabbay | 90bd479 | 2021-04-23 15:57:39 +0300 | [diff] [blame] | 1257 | void (*get_msi_info)(__le32 *table); |
Bharat Jauhari | 285c0fa | 2021-03-25 18:15:40 +0200 | [diff] [blame] | 1258 | int (*map_pll_idx_to_fw_idx)(u32 pll_idx); |
Ohad Sharabi | a22f0ec | 2021-04-11 23:06:46 +0300 | [diff] [blame] | 1259 | void (*init_firmware_loader)(struct hl_device *hdev); |
Bharat Jauhari | 4b09901 | 2021-05-28 13:14:34 +0300 | [diff] [blame] | 1260 | void (*init_cpu_scrambler_dram)(struct hl_device *hdev); |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 1261 | void (*state_dump_init)(struct hl_device *hdev); |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 1262 | }; |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 1263 | |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 1264 | |
| 1265 | /* |
| 1266 | * CONTEXTS |
| 1267 | */ |
| 1268 | |
| 1269 | #define HL_KERNEL_ASID_ID 0 |
| 1270 | |
| 1271 | /** |
Ofir Bitton | 784b916 | 2020-10-22 11:05:55 +0300 | [diff] [blame] | 1272 | * enum hl_va_range_type - virtual address range type. |
| 1273 | * @HL_VA_RANGE_TYPE_HOST: range type of host pages |
| 1274 | * @HL_VA_RANGE_TYPE_HOST_HUGE: range type of host huge pages |
| 1275 | * @HL_VA_RANGE_TYPE_DRAM: range type of dram pages |
| 1276 | */ |
| 1277 | enum hl_va_range_type { |
| 1278 | HL_VA_RANGE_TYPE_HOST, |
| 1279 | HL_VA_RANGE_TYPE_HOST_HUGE, |
| 1280 | HL_VA_RANGE_TYPE_DRAM, |
| 1281 | HL_VA_RANGE_TYPE_MAX |
| 1282 | }; |
| 1283 | |
| 1284 | /** |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1285 | * struct hl_va_range - virtual addresses range. |
| 1286 | * @lock: protects the virtual addresses list. |
| 1287 | * @list: list of virtual addresses blocks available for mappings. |
| 1288 | * @start_addr: range start address. |
| 1289 | * @end_addr: range end address. |
Ofir Bitton | 784b916 | 2020-10-22 11:05:55 +0300 | [diff] [blame] | 1290 | * @page_size: page size of this va range. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1291 | */ |
| 1292 | struct hl_va_range { |
| 1293 | struct mutex lock; |
| 1294 | struct list_head list; |
| 1295 | u64 start_addr; |
| 1296 | u64 end_addr; |
Ofir Bitton | 784b916 | 2020-10-22 11:05:55 +0300 | [diff] [blame] | 1297 | u32 page_size; |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1298 | }; |
| 1299 | |
| 1300 | /** |
farah kassabri | e753643 | 2020-10-12 14:30:26 +0300 | [diff] [blame] | 1301 | * struct hl_cs_counters_atomic - command submission counters |
| 1302 | * @out_of_mem_drop_cnt: dropped due to memory allocation issue |
| 1303 | * @parsing_drop_cnt: dropped due to error in packet parsing |
| 1304 | * @queue_full_drop_cnt: dropped due to queue full |
| 1305 | * @device_in_reset_drop_cnt: dropped due to device in reset |
| 1306 | * @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] | 1307 | * @validation_drop_cnt: dropped due to error in validation |
farah kassabri | e753643 | 2020-10-12 14:30:26 +0300 | [diff] [blame] | 1308 | */ |
| 1309 | struct hl_cs_counters_atomic { |
| 1310 | atomic64_t out_of_mem_drop_cnt; |
| 1311 | atomic64_t parsing_drop_cnt; |
| 1312 | atomic64_t queue_full_drop_cnt; |
| 1313 | atomic64_t device_in_reset_drop_cnt; |
| 1314 | atomic64_t max_cs_in_flight_drop_cnt; |
Alon Mizrahi | a3fd283 | 2020-12-08 16:14:01 +0200 | [diff] [blame] | 1315 | atomic64_t validation_drop_cnt; |
farah kassabri | e753643 | 2020-10-12 14:30:26 +0300 | [diff] [blame] | 1316 | }; |
| 1317 | |
| 1318 | /** |
Ofir Bitton | d3f139c | 2020-11-18 15:46:57 +0200 | [diff] [blame] | 1319 | * struct hl_pending_cb - pending command buffer structure |
| 1320 | * @cb_node: cb node in pending cb list |
| 1321 | * @cb: command buffer to send in next submission |
| 1322 | * @cb_size: command buffer size |
| 1323 | * @hw_queue_id: destination queue id |
| 1324 | */ |
| 1325 | struct hl_pending_cb { |
| 1326 | struct list_head cb_node; |
| 1327 | struct hl_cb *cb; |
| 1328 | u32 cb_size; |
| 1329 | u32 hw_queue_id; |
| 1330 | }; |
| 1331 | |
| 1332 | /** |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 1333 | * struct hl_ctx - user/kernel context. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1334 | * @mem_hash: holds mapping from virtual address to virtual memory area |
| 1335 | * descriptor (hl_vm_phys_pg_list or hl_userptr). |
Omer Shpigelman | 66542c3 | 2019-02-24 09:17:55 +0200 | [diff] [blame] | 1336 | * @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] | 1337 | * @hpriv: pointer to the private (Kernel Driver) data of the process (fd). |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 1338 | * @hdev: pointer to the device structure. |
| 1339 | * @refcount: reference counter for the context. Context is released only when |
| 1340 | * this hits 0l. It is incremented on CS and CS_WAIT. |
Ofir Bitton | a98d73c | 2020-07-15 08:52:39 +0300 | [diff] [blame] | 1341 | * @cs_pending: array of hl fence objects representing pending CS. |
Ofir Bitton | 784b916 | 2020-10-22 11:05:55 +0300 | [diff] [blame] | 1342 | * @va_range: holds available virtual addresses for host and dram mappings. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1343 | * @mem_hash_lock: protects the mem_hash. |
Omer Shpigelman | 8ff5f4f | 2020-05-24 23:06:59 +0300 | [diff] [blame] | 1344 | * @mmu_lock: protects the MMU page tables. Any change to the PGT, modifying the |
| 1345 | * MMU hash or walking the PGT requires talking this lock. |
Sagiv Ozeri | a4371c1 | 2021-02-23 11:01:08 +0200 | [diff] [blame] | 1346 | * @hw_block_list_lock: protects the HW block memory list. |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1347 | * @debugfs_list: node in debugfs list of contexts. |
Ofir Bitton | d3f139c | 2020-11-18 15:46:57 +0200 | [diff] [blame] | 1348 | * pending_cb_list: list of pending command buffers waiting to be sent upon |
| 1349 | * next user command submission context. |
Sagiv Ozeri | a4371c1 | 2021-02-23 11:01:08 +0200 | [diff] [blame] | 1350 | * @hw_block_mem_list: list of HW block virtual mapped addresses. |
farah kassabri | e753643 | 2020-10-12 14:30:26 +0300 | [diff] [blame] | 1351 | * @cs_counters: context command submission counters. |
Tomer Tayar | ef6a0f6 | 2020-07-09 16:17:48 +0300 | [diff] [blame] | 1352 | * @cb_va_pool: device VA pool for command buffers which are mapped to the |
| 1353 | * device's MMU. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1354 | * @cs_sequence: sequence number for CS. Value is assigned to a CS and passed |
| 1355 | * to user so user could inquire about CS. It is used as |
| 1356 | * index to cs_pending array. |
Omer Shpigelman | 27ca384c | 2019-02-28 10:46:11 +0200 | [diff] [blame] | 1357 | * @dram_default_hops: array that holds all hops addresses needed for default |
| 1358 | * DRAM mapping. |
Ofir Bitton | d3f139c | 2020-11-18 15:46:57 +0200 | [diff] [blame] | 1359 | * @pending_cb_lock: spinlock to protect pending cb list |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1360 | * @cs_lock: spinlock to protect cs_sequence. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1361 | * @dram_phys_mem: amount of used physical DRAM memory by this context. |
Oded Gabbay | 027d35d | 2019-04-25 20:15:42 +0300 | [diff] [blame] | 1362 | * @thread_ctx_switch_token: token to prevent multiple threads of the same |
| 1363 | * context from running the context switch phase. |
| 1364 | * Only a single thread should run it. |
Ofir Bitton | d3f139c | 2020-11-18 15:46:57 +0200 | [diff] [blame] | 1365 | * @thread_pending_cb_token: token to prevent multiple threads from processing |
| 1366 | * the pending CB list. Only a single thread should |
| 1367 | * process the list since it is protected by a |
| 1368 | * spinlock and we don't want to halt the entire |
| 1369 | * command submission sequence. |
Oded Gabbay | 027d35d | 2019-04-25 20:15:42 +0300 | [diff] [blame] | 1370 | * @thread_ctx_switch_wait_token: token to prevent the threads that didn't run |
| 1371 | * the context switch phase from moving to their |
| 1372 | * execution phase before the context switch phase |
| 1373 | * has finished. |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 1374 | * @asid: context's unique address space ID in the device's MMU. |
Oded Gabbay | b888751 | 2019-07-15 21:55:57 +0300 | [diff] [blame] | 1375 | * @handle: context's opaque handle for user |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 1376 | */ |
| 1377 | struct hl_ctx { |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1378 | DECLARE_HASHTABLE(mem_hash, MEM_HASH_TABLE_BITS); |
Omer Shpigelman | 66542c3 | 2019-02-24 09:17:55 +0200 | [diff] [blame] | 1379 | DECLARE_HASHTABLE(mmu_shadow_hash, MMU_HASH_TABLE_BITS); |
farah kassabri | e753643 | 2020-10-12 14:30:26 +0300 | [diff] [blame] | 1380 | struct hl_fpriv *hpriv; |
| 1381 | struct hl_device *hdev; |
| 1382 | struct kref refcount; |
| 1383 | struct hl_fence **cs_pending; |
Ofir Bitton | 784b916 | 2020-10-22 11:05:55 +0300 | [diff] [blame] | 1384 | struct hl_va_range *va_range[HL_VA_RANGE_TYPE_MAX]; |
farah kassabri | e753643 | 2020-10-12 14:30:26 +0300 | [diff] [blame] | 1385 | struct mutex mem_hash_lock; |
| 1386 | struct mutex mmu_lock; |
Sagiv Ozeri | a4371c1 | 2021-02-23 11:01:08 +0200 | [diff] [blame] | 1387 | struct mutex hw_block_list_lock; |
farah kassabri | e753643 | 2020-10-12 14:30:26 +0300 | [diff] [blame] | 1388 | struct list_head debugfs_list; |
Ofir Bitton | d3f139c | 2020-11-18 15:46:57 +0200 | [diff] [blame] | 1389 | struct list_head pending_cb_list; |
Sagiv Ozeri | a4371c1 | 2021-02-23 11:01:08 +0200 | [diff] [blame] | 1390 | struct list_head hw_block_mem_list; |
farah kassabri | e753643 | 2020-10-12 14:30:26 +0300 | [diff] [blame] | 1391 | struct hl_cs_counters_atomic cs_counters; |
| 1392 | struct gen_pool *cb_va_pool; |
| 1393 | u64 cs_sequence; |
| 1394 | u64 *dram_default_hops; |
Ofir Bitton | d3f139c | 2020-11-18 15:46:57 +0200 | [diff] [blame] | 1395 | spinlock_t pending_cb_lock; |
farah kassabri | e753643 | 2020-10-12 14:30:26 +0300 | [diff] [blame] | 1396 | spinlock_t cs_lock; |
| 1397 | atomic64_t dram_phys_mem; |
| 1398 | atomic_t thread_ctx_switch_token; |
Ofir Bitton | d3f139c | 2020-11-18 15:46:57 +0200 | [diff] [blame] | 1399 | atomic_t thread_pending_cb_token; |
farah kassabri | e753643 | 2020-10-12 14:30:26 +0300 | [diff] [blame] | 1400 | u32 thread_ctx_switch_wait_token; |
| 1401 | u32 asid; |
| 1402 | u32 handle; |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 1403 | }; |
| 1404 | |
| 1405 | /** |
| 1406 | * struct hl_ctx_mgr - for handling multiple contexts. |
| 1407 | * @ctx_lock: protects ctx_handles. |
| 1408 | * @ctx_handles: idr to hold all ctx handles. |
| 1409 | */ |
| 1410 | struct hl_ctx_mgr { |
| 1411 | struct mutex ctx_lock; |
| 1412 | struct idr ctx_handles; |
| 1413 | }; |
| 1414 | |
| 1415 | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1416 | |
| 1417 | /* |
| 1418 | * COMMAND SUBMISSIONS |
| 1419 | */ |
| 1420 | |
| 1421 | /** |
| 1422 | * struct hl_userptr - memory mapping chunk information |
| 1423 | * @vm_type: type of the VM. |
| 1424 | * @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] | 1425 | * @pages: pointer to struct page array |
| 1426 | * @npages: size of @pages array |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1427 | * @sgt: pointer to the scatter-gather table that holds the pages. |
| 1428 | * @dir: for DMA unmapping, the direction must be supplied, so save it. |
| 1429 | * @debugfs_list: node in debugfs list of command submissions. |
Omer Shpigelman | 7f74d4d | 2019-08-12 11:48:46 +0300 | [diff] [blame] | 1430 | * @addr: user-space virtual address of the start of the memory area. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1431 | * @size: size of the memory area to pin & map. |
| 1432 | * @dma_mapped: true if the SG was mapped to DMA addresses, false otherwise. |
| 1433 | */ |
| 1434 | struct hl_userptr { |
Oded Gabbay | 82629c7 | 2021-06-29 18:08:05 +0300 | [diff] [blame] | 1435 | enum vm_type vm_type; /* must be first */ |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1436 | struct list_head job_node; |
Daniel Vetter | d4cb192 | 2020-11-27 17:41:17 +0100 | [diff] [blame] | 1437 | struct page **pages; |
| 1438 | unsigned int npages; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1439 | struct sg_table *sgt; |
| 1440 | enum dma_data_direction dir; |
| 1441 | struct list_head debugfs_list; |
| 1442 | u64 addr; |
Oded Gabbay | 00ce065 | 2021-06-29 18:12:46 +0300 | [diff] [blame] | 1443 | u64 size; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1444 | u8 dma_mapped; |
| 1445 | }; |
| 1446 | |
| 1447 | /** |
| 1448 | * struct hl_cs - command submission. |
| 1449 | * @jobs_in_queue_cnt: per each queue, maintain counter of submitted jobs. |
| 1450 | * @ctx: the context this CS belongs to. |
| 1451 | * @job_list: list of the CS's jobs in the various queues. |
| 1452 | * @job_lock: spinlock for the CS's jobs list. Needed for free_job. |
| 1453 | * @refcount: reference counter for usage of the CS. |
| 1454 | * @fence: pointer to the fence object of this CS. |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 1455 | * @signal_fence: pointer to the fence object of the signal CS (used by wait |
| 1456 | * CS only). |
Omer Shpigelman | b75f225 | 2020-05-07 14:31:49 +0300 | [diff] [blame] | 1457 | * @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] | 1458 | * @work_tdr: delayed work node for TDR. |
| 1459 | * @mirror_node : node in device mirror list of command submissions. |
Ofir Bitton | 2795c88 | 2020-12-08 13:47:05 +0200 | [diff] [blame] | 1460 | * @staged_cs_node: node in the staged cs list. |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1461 | * @debugfs_list: node in debugfs list of command submissions. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1462 | * @sequence: the sequence number of this CS. |
Ofir Bitton | 2795c88 | 2020-12-08 13:47:05 +0200 | [diff] [blame] | 1463 | * @staged_sequence: the sequence of the staged submission this CS is part of, |
| 1464 | * relevant only if staged_cs is set. |
Alon Mizrahi | cf39395 | 2021-02-22 15:53:24 +0200 | [diff] [blame] | 1465 | * @timeout_jiffies: cs timeout in jiffies. |
Yuri Nudelman | 8e8125f | 2021-05-25 14:49:52 +0300 | [diff] [blame] | 1466 | * @submission_time_jiffies: submission time of the cs |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 1467 | * @type: CS_TYPE_*. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1468 | * @submitted: true if CS was submitted to H/W. |
| 1469 | * @completed: true if CS was completed by device. |
| 1470 | * @timedout : true if CS was timedout. |
| 1471 | * @tdr_active: true if TDR was activated for this CS (to prevent |
| 1472 | * double TDR activation). |
| 1473 | * @aborted: true if CS was aborted due to some device error. |
Ofir Bitton | 0811b39 | 2020-12-06 17:18:02 +0200 | [diff] [blame] | 1474 | * @timestamp: true if a timestmap must be captured upon completion. |
| 1475 | * @staged_last: true if this is the last staged CS and needs completion. |
| 1476 | * @staged_first: true if this is the first staged CS and we need to receive |
| 1477 | * timeout for this CS. |
| 1478 | * @staged_cs: true if this CS is part of a staged submission. |
Yuri Nudelman | 8e8125f | 2021-05-25 14:49:52 +0300 | [diff] [blame] | 1479 | * @skip_reset_on_timeout: true if we shall not reset the device in case |
| 1480 | * timeout occurs (debug scenario). |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1481 | */ |
| 1482 | struct hl_cs { |
Ofir Bitton | 3abc99b | 2020-06-23 14:50:39 +0300 | [diff] [blame] | 1483 | u16 *jobs_in_queue_cnt; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1484 | struct hl_ctx *ctx; |
| 1485 | struct list_head job_list; |
| 1486 | spinlock_t job_lock; |
| 1487 | struct kref refcount; |
Ofir Bitton | a98d73c | 2020-07-15 08:52:39 +0300 | [diff] [blame] | 1488 | struct hl_fence *fence; |
| 1489 | struct hl_fence *signal_fence; |
Omer Shpigelman | b75f225 | 2020-05-07 14:31:49 +0300 | [diff] [blame] | 1490 | struct work_struct finish_work; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1491 | struct delayed_work work_tdr; |
| 1492 | struct list_head mirror_node; |
Ofir Bitton | 2795c88 | 2020-12-08 13:47:05 +0200 | [diff] [blame] | 1493 | struct list_head staged_cs_node; |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1494 | struct list_head debugfs_list; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1495 | u64 sequence; |
Ofir Bitton | 2795c88 | 2020-12-08 13:47:05 +0200 | [diff] [blame] | 1496 | u64 staged_sequence; |
Alon Mizrahi | cf39395 | 2021-02-22 15:53:24 +0200 | [diff] [blame] | 1497 | u64 timeout_jiffies; |
Yuri Nudelman | 8e8125f | 2021-05-25 14:49:52 +0300 | [diff] [blame] | 1498 | u64 submission_time_jiffies; |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 1499 | enum hl_cs_type type; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1500 | u8 submitted; |
| 1501 | u8 completed; |
| 1502 | u8 timedout; |
| 1503 | u8 tdr_active; |
| 1504 | u8 aborted; |
Ofir Bitton | bd2f477 | 2020-11-10 17:26:22 +0200 | [diff] [blame] | 1505 | u8 timestamp; |
Ofir Bitton | 0811b39 | 2020-12-06 17:18:02 +0200 | [diff] [blame] | 1506 | u8 staged_last; |
| 1507 | u8 staged_first; |
| 1508 | u8 staged_cs; |
Yuri Nudelman | 8e8125f | 2021-05-25 14:49:52 +0300 | [diff] [blame] | 1509 | u8 skip_reset_on_timeout; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1510 | }; |
| 1511 | |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1512 | /** |
| 1513 | * struct hl_cs_job - command submission job. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1514 | * @cs_node: the node to hang on the CS jobs list. |
| 1515 | * @cs: the CS this job belongs to. |
| 1516 | * @user_cb: the CB we got from the user. |
| 1517 | * @patched_cb: in case of patching, this is internal CB which is submitted on |
| 1518 | * the queue instead of the CB we got from the IOCTL. |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1519 | * @finish_work: workqueue object to run when job is completed. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1520 | * @userptr_list: linked-list of userptr mappings that belong to this job and |
| 1521 | * wait for completion. |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1522 | * @debugfs_list: node in debugfs list of command submission jobs. |
Tomer Tayar | 649c459 | 2020-08-10 17:30:35 +0300 | [diff] [blame] | 1523 | * @refcount: reference counter for usage of the CS job. |
Tomer Tayar | cb596ae | 2019-10-03 15:22:36 +0000 | [diff] [blame] | 1524 | * @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] | 1525 | * @id: the id of this job inside a CS. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1526 | * @hw_queue_id: the id of the H/W queue this job is submitted to. |
| 1527 | * @user_cb_size: the actual size of the CB we got from the user. |
| 1528 | * @job_cb_size: the actual size of the CB that we put on the queue. |
Tomer Tayar | cb596ae | 2019-10-03 15:22:36 +0000 | [diff] [blame] | 1529 | * @is_kernel_allocated_cb: true if the CB handle we got from the user holds a |
| 1530 | * handle to a kernel-allocated CB object, false |
| 1531 | * otherwise (SRAM/DRAM/host address). |
Oded Gabbay | 926ba4c | 2020-03-31 11:57:11 +0300 | [diff] [blame] | 1532 | * @contains_dma_pkt: whether the JOB contains at least one DMA packet. This |
| 1533 | * info is needed later, when adding the 2xMSG_PROT at the |
| 1534 | * end of the JOB, to know which barriers to put in the |
| 1535 | * MSG_PROT packets. Relevant only for GAUDI as GOYA doesn't |
| 1536 | * have streams so the engine can't be busy by another |
| 1537 | * stream. |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1538 | */ |
| 1539 | struct hl_cs_job { |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1540 | struct list_head cs_node; |
| 1541 | struct hl_cs *cs; |
| 1542 | struct hl_cb *user_cb; |
| 1543 | struct hl_cb *patched_cb; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1544 | struct work_struct finish_work; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1545 | struct list_head userptr_list; |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1546 | struct list_head debugfs_list; |
Tomer Tayar | 649c459 | 2020-08-10 17:30:35 +0300 | [diff] [blame] | 1547 | struct kref refcount; |
Tomer Tayar | cb596ae | 2019-10-03 15:22:36 +0000 | [diff] [blame] | 1548 | enum hl_queue_type queue_type; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1549 | u32 id; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1550 | u32 hw_queue_id; |
| 1551 | u32 user_cb_size; |
| 1552 | u32 job_cb_size; |
Tomer Tayar | cb596ae | 2019-10-03 15:22:36 +0000 | [diff] [blame] | 1553 | u8 is_kernel_allocated_cb; |
Oded Gabbay | 926ba4c | 2020-03-31 11:57:11 +0300 | [diff] [blame] | 1554 | u8 contains_dma_pkt; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1555 | }; |
| 1556 | |
| 1557 | /** |
Tomer Tayar | f435614 | 2019-10-02 13:53:52 +0000 | [diff] [blame] | 1558 | * struct hl_cs_parser - command submission parser properties. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1559 | * @user_cb: the CB we got from the user. |
| 1560 | * @patched_cb: in case of patching, this is internal CB which is submitted on |
| 1561 | * the queue instead of the CB we got from the IOCTL. |
| 1562 | * @job_userptr_list: linked-list of userptr mappings that belong to the related |
| 1563 | * job and wait for completion. |
| 1564 | * @cs_sequence: the sequence number of the related CS. |
Tomer Tayar | cb596ae | 2019-10-03 15:22:36 +0000 | [diff] [blame] | 1565 | * @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] | 1566 | * @ctx_id: the ID of the context the related CS belongs to. |
| 1567 | * @hw_queue_id: the id of the H/W queue this job is submitted to. |
| 1568 | * @user_cb_size: the actual size of the CB we got from the user. |
| 1569 | * @patched_cb_size: the size of the CB after parsing. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1570 | * @job_id: the id of the related job inside the related CS. |
Tomer Tayar | cb596ae | 2019-10-03 15:22:36 +0000 | [diff] [blame] | 1571 | * @is_kernel_allocated_cb: true if the CB handle we got from the user holds a |
| 1572 | * handle to a kernel-allocated CB object, false |
| 1573 | * otherwise (SRAM/DRAM/host address). |
Oded Gabbay | 926ba4c | 2020-03-31 11:57:11 +0300 | [diff] [blame] | 1574 | * @contains_dma_pkt: whether the JOB contains at least one DMA packet. This |
| 1575 | * info is needed later, when adding the 2xMSG_PROT at the |
| 1576 | * end of the JOB, to know which barriers to put in the |
| 1577 | * MSG_PROT packets. Relevant only for GAUDI as GOYA doesn't |
| 1578 | * have streams so the engine can't be busy by another |
| 1579 | * stream. |
Ofir Bitton | ac6fdbf | 2020-12-03 16:59:28 +0200 | [diff] [blame] | 1580 | * @completion: true if we need completion for this CS. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1581 | */ |
| 1582 | struct hl_cs_parser { |
| 1583 | struct hl_cb *user_cb; |
| 1584 | struct hl_cb *patched_cb; |
| 1585 | struct list_head *job_userptr_list; |
| 1586 | u64 cs_sequence; |
Tomer Tayar | cb596ae | 2019-10-03 15:22:36 +0000 | [diff] [blame] | 1587 | enum hl_queue_type queue_type; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1588 | u32 ctx_id; |
| 1589 | u32 hw_queue_id; |
| 1590 | u32 user_cb_size; |
| 1591 | u32 patched_cb_size; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1592 | u8 job_id; |
Tomer Tayar | cb596ae | 2019-10-03 15:22:36 +0000 | [diff] [blame] | 1593 | u8 is_kernel_allocated_cb; |
Oded Gabbay | 926ba4c | 2020-03-31 11:57:11 +0300 | [diff] [blame] | 1594 | u8 contains_dma_pkt; |
Ofir Bitton | ac6fdbf | 2020-12-03 16:59:28 +0200 | [diff] [blame] | 1595 | u8 completion; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1596 | }; |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 1597 | |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 1598 | /* |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1599 | * MEMORY STRUCTURE |
| 1600 | */ |
| 1601 | |
| 1602 | /** |
| 1603 | * struct hl_vm_hash_node - hash element from virtual address to virtual |
| 1604 | * memory area descriptor (hl_vm_phys_pg_list or |
| 1605 | * hl_userptr). |
| 1606 | * @node: node to hang on the hash table in context object. |
| 1607 | * @vaddr: key virtual address. |
| 1608 | * @ptr: value pointer (hl_vm_phys_pg_list or hl_userptr). |
| 1609 | */ |
| 1610 | struct hl_vm_hash_node { |
| 1611 | struct hlist_node node; |
| 1612 | u64 vaddr; |
| 1613 | void *ptr; |
| 1614 | }; |
| 1615 | |
| 1616 | /** |
Sagiv Ozeri | a4371c1 | 2021-02-23 11:01:08 +0200 | [diff] [blame] | 1617 | * struct hl_vm_hw_block_list_node - list element from user virtual address to |
| 1618 | * HW block id. |
| 1619 | * @node: node to hang on the list in context object. |
| 1620 | * @ctx: the context this node belongs to. |
| 1621 | * @vaddr: virtual address of the HW block. |
| 1622 | * @size: size of the block. |
| 1623 | * @id: HW block id (handle). |
| 1624 | */ |
| 1625 | struct hl_vm_hw_block_list_node { |
| 1626 | struct list_head node; |
| 1627 | struct hl_ctx *ctx; |
| 1628 | unsigned long vaddr; |
| 1629 | u32 size; |
| 1630 | u32 id; |
| 1631 | }; |
| 1632 | |
| 1633 | /** |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1634 | * struct hl_vm_phys_pg_pack - physical page pack. |
| 1635 | * @vm_type: describes the type of the virtual area descriptor. |
| 1636 | * @pages: the physical page array. |
Omer Shpigelman | bfb1ce1 | 2019-03-05 10:59:16 +0200 | [diff] [blame] | 1637 | * @npages: num physical pages in the pack. |
| 1638 | * @total_size: total size of all the pages in this list. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1639 | * @mapping_cnt: number of shared mappings. |
| 1640 | * @asid: the context related to this list. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1641 | * @page_size: size of each page in the pack. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1642 | * @flags: HL_MEM_* flags related to this list. |
| 1643 | * @handle: the provided handle related to this list. |
| 1644 | * @offset: offset from the first page. |
| 1645 | * @contiguous: is contiguous physical memory. |
| 1646 | * @created_from_userptr: is product of host virtual address. |
| 1647 | */ |
| 1648 | struct hl_vm_phys_pg_pack { |
Oded Gabbay | 82629c7 | 2021-06-29 18:08:05 +0300 | [diff] [blame] | 1649 | enum vm_type vm_type; /* must be first */ |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1650 | u64 *pages; |
Omer Shpigelman | bfb1ce1 | 2019-03-05 10:59:16 +0200 | [diff] [blame] | 1651 | u64 npages; |
| 1652 | u64 total_size; |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1653 | atomic_t mapping_cnt; |
| 1654 | u32 asid; |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1655 | u32 page_size; |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1656 | u32 flags; |
| 1657 | u32 handle; |
| 1658 | u32 offset; |
| 1659 | u8 contiguous; |
| 1660 | u8 created_from_userptr; |
| 1661 | }; |
| 1662 | |
| 1663 | /** |
| 1664 | * struct hl_vm_va_block - virtual range block information. |
| 1665 | * @node: node to hang on the virtual range list in context object. |
| 1666 | * @start: virtual range start address. |
| 1667 | * @end: virtual range end address. |
| 1668 | * @size: virtual range size. |
| 1669 | */ |
| 1670 | struct hl_vm_va_block { |
| 1671 | struct list_head node; |
| 1672 | u64 start; |
| 1673 | u64 end; |
| 1674 | u64 size; |
| 1675 | }; |
| 1676 | |
| 1677 | /** |
| 1678 | * struct hl_vm - virtual memory manager for MMU. |
| 1679 | * @dram_pg_pool: pool for DRAM physical pages of 2MB. |
| 1680 | * @dram_pg_pool_refcount: reference counter for the pool usage. |
| 1681 | * @idr_lock: protects the phys_pg_list_handles. |
| 1682 | * @phys_pg_pack_handles: idr to hold all device allocations handles. |
| 1683 | * @init_done: whether initialization was done. We need this because VM |
| 1684 | * initialization might be skipped during device initialization. |
| 1685 | */ |
| 1686 | struct hl_vm { |
| 1687 | struct gen_pool *dram_pg_pool; |
| 1688 | struct kref dram_pg_pool_refcount; |
| 1689 | spinlock_t idr_lock; |
| 1690 | struct idr phys_pg_pack_handles; |
| 1691 | u8 init_done; |
| 1692 | }; |
| 1693 | |
Omer Shpigelman | 315bc05 | 2019-04-01 22:31:22 +0300 | [diff] [blame] | 1694 | |
| 1695 | /* |
| 1696 | * DEBUG, PROFILING STRUCTURE |
| 1697 | */ |
| 1698 | |
| 1699 | /** |
| 1700 | * struct hl_debug_params - Coresight debug parameters. |
| 1701 | * @input: pointer to component specific input parameters. |
| 1702 | * @output: pointer to component specific output parameters. |
| 1703 | * @output_size: size of output buffer. |
| 1704 | * @reg_idx: relevant register ID. |
| 1705 | * @op: component operation to execute. |
| 1706 | * @enable: true if to enable component debugging, false otherwise. |
| 1707 | */ |
| 1708 | struct hl_debug_params { |
| 1709 | void *input; |
| 1710 | void *output; |
| 1711 | u32 output_size; |
| 1712 | u32 reg_idx; |
| 1713 | u32 op; |
| 1714 | bool enable; |
| 1715 | }; |
| 1716 | |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 1717 | /* |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 1718 | * FILE PRIVATE STRUCTURE |
| 1719 | */ |
| 1720 | |
| 1721 | /** |
| 1722 | * struct hl_fpriv - process information stored in FD private data. |
| 1723 | * @hdev: habanalabs device structure. |
| 1724 | * @filp: pointer to the given file structure. |
| 1725 | * @taskpid: current process ID. |
Oded Gabbay | 86d5307 | 2019-07-30 11:49:36 +0300 | [diff] [blame] | 1726 | * @ctx: current executing context. TODO: remove for multiple ctx per process |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 1727 | * @ctx_mgr: context manager to handle multiple context for this FD. |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 1728 | * @cb_mgr: command buffer manager to handle multiple buffers for this FD. |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1729 | * @debugfs_list: list of relevant ASIC debugfs. |
Oded Gabbay | eb7caf8 | 2019-07-30 11:56:09 +0300 | [diff] [blame] | 1730 | * @dev_node: node in the device list of file private data |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 1731 | * @refcount: number of related contexts. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1732 | * @restore_phase_mutex: lock for context switch and restore phase. |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 1733 | * @is_control: true for control device, false otherwise |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 1734 | */ |
| 1735 | struct hl_fpriv { |
| 1736 | struct hl_device *hdev; |
| 1737 | struct file *filp; |
| 1738 | struct pid *taskpid; |
Oded Gabbay | 86d5307 | 2019-07-30 11:49:36 +0300 | [diff] [blame] | 1739 | struct hl_ctx *ctx; |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 1740 | struct hl_ctx_mgr ctx_mgr; |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 1741 | struct hl_cb_mgr cb_mgr; |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1742 | struct list_head debugfs_list; |
Oded Gabbay | eb7caf8 | 2019-07-30 11:56:09 +0300 | [diff] [blame] | 1743 | struct list_head dev_node; |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 1744 | struct kref refcount; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 1745 | struct mutex restore_phase_mutex; |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 1746 | u8 is_control; |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 1747 | }; |
| 1748 | |
| 1749 | |
| 1750 | /* |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1751 | * DebugFS |
| 1752 | */ |
| 1753 | |
| 1754 | /** |
| 1755 | * struct hl_info_list - debugfs file ops. |
| 1756 | * @name: file name. |
| 1757 | * @show: function to output information. |
| 1758 | * @write: function to write to the file. |
| 1759 | */ |
| 1760 | struct hl_info_list { |
| 1761 | const char *name; |
| 1762 | int (*show)(struct seq_file *s, void *data); |
| 1763 | ssize_t (*write)(struct file *file, const char __user *buf, |
| 1764 | size_t count, loff_t *f_pos); |
| 1765 | }; |
| 1766 | |
| 1767 | /** |
| 1768 | * struct hl_debugfs_entry - debugfs dentry wrapper. |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1769 | * @info_ent: dentry realted ops. |
| 1770 | * @dev_entry: ASIC specific debugfs manager. |
| 1771 | */ |
| 1772 | struct hl_debugfs_entry { |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1773 | const struct hl_info_list *info_ent; |
| 1774 | struct hl_dbg_device_entry *dev_entry; |
| 1775 | }; |
| 1776 | |
| 1777 | /** |
| 1778 | * struct hl_dbg_device_entry - ASIC specific debugfs manager. |
| 1779 | * @root: root dentry. |
| 1780 | * @hdev: habanalabs device structure. |
| 1781 | * @entry_arr: array of available hl_debugfs_entry. |
| 1782 | * @file_list: list of available debugfs files. |
| 1783 | * @file_mutex: protects file_list. |
| 1784 | * @cb_list: list of available CBs. |
| 1785 | * @cb_spinlock: protects cb_list. |
| 1786 | * @cs_list: list of available CSs. |
| 1787 | * @cs_spinlock: protects cs_list. |
| 1788 | * @cs_job_list: list of available CB jobs. |
| 1789 | * @cs_job_spinlock: protects cs_job_list. |
| 1790 | * @userptr_list: list of available userptrs (virtual memory chunk descriptor). |
| 1791 | * @userptr_spinlock: protects userptr_list. |
| 1792 | * @ctx_mem_hash_list: list of available contexts with MMU mappings. |
| 1793 | * @ctx_mem_hash_spinlock: protects cb_list. |
Oded Gabbay | 639781d | 2021-04-02 01:43:18 +0300 | [diff] [blame] | 1794 | * @blob_desc: descriptor of blob |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 1795 | * @state_dump: data of the system states in case of a bad cs. |
| 1796 | * @state_dump_sem: protects state_dump. |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1797 | * @addr: next address to read/write from/to in read/write32. |
| 1798 | * @mmu_addr: next virtual address to translate to physical address in mmu_show. |
| 1799 | * @mmu_asid: ASID to use while translating in mmu_show. |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 1800 | * @state_dump_head: index of the latest state dump |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1801 | * @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] | 1802 | * @i2c_addr: generic u8 debugfs file for address value to use in i2c_data_read. |
| 1803 | * @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] | 1804 | */ |
| 1805 | struct hl_dbg_device_entry { |
| 1806 | struct dentry *root; |
| 1807 | struct hl_device *hdev; |
| 1808 | struct hl_debugfs_entry *entry_arr; |
| 1809 | struct list_head file_list; |
| 1810 | struct mutex file_mutex; |
| 1811 | struct list_head cb_list; |
| 1812 | spinlock_t cb_spinlock; |
| 1813 | struct list_head cs_list; |
| 1814 | spinlock_t cs_spinlock; |
| 1815 | struct list_head cs_job_list; |
| 1816 | spinlock_t cs_job_spinlock; |
| 1817 | struct list_head userptr_list; |
| 1818 | spinlock_t userptr_spinlock; |
| 1819 | struct list_head ctx_mem_hash_list; |
| 1820 | spinlock_t ctx_mem_hash_spinlock; |
Oded Gabbay | 639781d | 2021-04-02 01:43:18 +0300 | [diff] [blame] | 1821 | struct debugfs_blob_wrapper blob_desc; |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 1822 | char *state_dump[HL_STATE_DUMP_HIST_LEN]; |
| 1823 | struct rw_semaphore state_dump_sem; |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1824 | u64 addr; |
| 1825 | u64 mmu_addr; |
| 1826 | u32 mmu_asid; |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 1827 | u32 state_dump_head; |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1828 | u8 i2c_bus; |
| 1829 | u8 i2c_addr; |
| 1830 | u8 i2c_reg; |
| 1831 | }; |
| 1832 | |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 1833 | /** |
| 1834 | * struct hl_hw_obj_name_entry - single hw object name, member of |
| 1835 | * hl_state_dump_specs |
| 1836 | * @node: link to the containing hash table |
| 1837 | * @name: hw object name |
| 1838 | * @id: object identifier |
| 1839 | */ |
| 1840 | struct hl_hw_obj_name_entry { |
| 1841 | struct hlist_node node; |
| 1842 | const char *name; |
| 1843 | u32 id; |
| 1844 | }; |
| 1845 | |
| 1846 | enum hl_state_dump_specs_props { |
| 1847 | SP_SYNC_OBJ_BASE_ADDR, |
| 1848 | SP_NEXT_SYNC_OBJ_ADDR, |
| 1849 | SP_SYNC_OBJ_AMOUNT, |
| 1850 | SP_MON_OBJ_WR_ADDR_LOW, |
| 1851 | SP_MON_OBJ_WR_ADDR_HIGH, |
| 1852 | SP_MON_OBJ_WR_DATA, |
| 1853 | SP_MON_OBJ_ARM_DATA, |
| 1854 | SP_MON_OBJ_STATUS, |
| 1855 | SP_MONITORS_AMOUNT, |
| 1856 | SP_TPC0_CMDQ, |
| 1857 | SP_TPC0_CFG_SO, |
| 1858 | SP_NEXT_TPC, |
| 1859 | SP_MME_CMDQ, |
| 1860 | SP_MME_CFG_SO, |
| 1861 | SP_NEXT_MME, |
| 1862 | SP_DMA_CMDQ, |
| 1863 | SP_DMA_CFG_SO, |
| 1864 | SP_DMA_QUEUES_OFFSET, |
| 1865 | SP_NUM_OF_MME_ENGINES, |
| 1866 | SP_SUB_MME_ENG_NUM, |
| 1867 | SP_NUM_OF_DMA_ENGINES, |
| 1868 | SP_NUM_OF_TPC_ENGINES, |
| 1869 | SP_ENGINE_NUM_OF_QUEUES, |
| 1870 | SP_ENGINE_NUM_OF_STREAMS, |
| 1871 | SP_ENGINE_NUM_OF_FENCES, |
| 1872 | SP_FENCE0_CNT_OFFSET, |
| 1873 | SP_FENCE0_RDATA_OFFSET, |
| 1874 | SP_CP_STS_OFFSET, |
| 1875 | SP_NUM_CORES, |
| 1876 | |
| 1877 | SP_MAX |
| 1878 | }; |
| 1879 | |
| 1880 | enum hl_sync_engine_type { |
| 1881 | ENGINE_TPC, |
| 1882 | ENGINE_DMA, |
| 1883 | ENGINE_MME, |
| 1884 | }; |
| 1885 | |
| 1886 | /** |
Yuri Nudelman | fd2010b | 2021-06-09 14:04:26 +0300 | [diff] [blame] | 1887 | * struct hl_mon_state_dump - represents a state dump of a single monitor |
| 1888 | * @id: monitor id |
| 1889 | * @wr_addr_low: address monitor will write to, low bits |
| 1890 | * @wr_addr_high: address monitor will write to, high bits |
| 1891 | * @wr_data: data monitor will write |
| 1892 | * @arm_data: register value containing monitor configuration |
| 1893 | * @status: monitor status |
| 1894 | */ |
| 1895 | struct hl_mon_state_dump { |
| 1896 | u32 id; |
| 1897 | u32 wr_addr_low; |
| 1898 | u32 wr_addr_high; |
| 1899 | u32 wr_data; |
| 1900 | u32 arm_data; |
| 1901 | u32 status; |
| 1902 | }; |
| 1903 | |
| 1904 | /** |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 1905 | * struct hl_sync_to_engine_map_entry - sync object id to engine mapping entry |
| 1906 | * @engine_type: type of the engine |
| 1907 | * @engine_id: id of the engine |
| 1908 | * @sync_id: id of the sync object |
| 1909 | */ |
| 1910 | struct hl_sync_to_engine_map_entry { |
| 1911 | struct hlist_node node; |
| 1912 | enum hl_sync_engine_type engine_type; |
| 1913 | u32 engine_id; |
| 1914 | u32 sync_id; |
| 1915 | }; |
| 1916 | |
| 1917 | /** |
| 1918 | * struct hl_sync_to_engine_map - maps sync object id to associated engine id |
| 1919 | * @tb: hash table containing the mapping, each element is of type |
| 1920 | * struct hl_sync_to_engine_map_entry |
| 1921 | */ |
| 1922 | struct hl_sync_to_engine_map { |
| 1923 | DECLARE_HASHTABLE(tb, SYNC_TO_ENGINE_HASH_TABLE_BITS); |
| 1924 | }; |
| 1925 | |
| 1926 | /** |
| 1927 | * struct hl_state_dump_specs_funcs - virtual functions used by the state dump |
| 1928 | * @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] | 1929 | * @print_single_monitor: format monitor data as string |
| 1930 | * @monitor_valid: return true if given monitor dump is valid |
| 1931 | * @print_fences_single_engine: format fences data as string |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 1932 | */ |
| 1933 | struct hl_state_dump_specs_funcs { |
| 1934 | int (*gen_sync_to_engine_map)(struct hl_device *hdev, |
| 1935 | struct hl_sync_to_engine_map *map); |
Yuri Nudelman | fd2010b | 2021-06-09 14:04:26 +0300 | [diff] [blame] | 1936 | int (*print_single_monitor)(char **buf, size_t *size, size_t *offset, |
| 1937 | struct hl_device *hdev, |
| 1938 | struct hl_mon_state_dump *mon); |
| 1939 | int (*monitor_valid)(struct hl_mon_state_dump *mon); |
| 1940 | int (*print_fences_single_engine)(struct hl_device *hdev, |
| 1941 | u64 base_offset, |
| 1942 | u64 status_base_offset, |
| 1943 | enum hl_sync_engine_type engine_type, |
| 1944 | u32 engine_id, char **buf, |
| 1945 | size_t *size, size_t *offset); |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 1946 | }; |
| 1947 | |
| 1948 | /** |
| 1949 | * struct hl_state_dump_specs - defines ASIC known hw objects names |
| 1950 | * @so_id_to_str_tb: sync objects names index table |
| 1951 | * @monitor_id_to_str_tb: monitors names index table |
| 1952 | * @funcs: virtual functions used for state dump |
| 1953 | * @sync_namager_names: readable names for sync manager if available (ex: N_E) |
| 1954 | * @props: pointer to a per asic const props array required for state dump |
| 1955 | */ |
| 1956 | struct hl_state_dump_specs { |
| 1957 | DECLARE_HASHTABLE(so_id_to_str_tb, OBJ_NAMES_HASH_TABLE_BITS); |
| 1958 | DECLARE_HASHTABLE(monitor_id_to_str_tb, OBJ_NAMES_HASH_TABLE_BITS); |
| 1959 | struct hl_state_dump_specs_funcs funcs; |
| 1960 | const char * const *sync_namager_names; |
| 1961 | s64 *props; |
| 1962 | }; |
| 1963 | |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 1964 | |
| 1965 | /* |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 1966 | * DEVICES |
| 1967 | */ |
| 1968 | |
Ofir Bitton | 66a7640 | 2020-10-05 14:40:10 +0300 | [diff] [blame] | 1969 | #define HL_STR_MAX 32 |
| 1970 | |
| 1971 | #define HL_DEV_STS_MAX (HL_DEVICE_STATUS_NEEDS_RESET + 1) |
| 1972 | |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 1973 | /* 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] | 1974 | * 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] | 1975 | */ |
| 1976 | #define HL_MAX_MINORS 256 |
| 1977 | |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 1978 | /* |
| 1979 | * Registers read & write functions. |
| 1980 | */ |
| 1981 | |
| 1982 | u32 hl_rreg(struct hl_device *hdev, u32 reg); |
| 1983 | void hl_wreg(struct hl_device *hdev, u32 reg, u32 val); |
| 1984 | |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 1985 | #define RREG32(reg) hdev->asic_funcs->rreg(hdev, (reg)) |
| 1986 | #define WREG32(reg, v) hdev->asic_funcs->wreg(hdev, (reg), (v)) |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 1987 | #define DREG32(reg) pr_info("REGISTER: " #reg " : 0x%08X\n", \ |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 1988 | hdev->asic_funcs->rreg(hdev, (reg))) |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 1989 | |
| 1990 | #define WREG32_P(reg, val, mask) \ |
| 1991 | do { \ |
| 1992 | u32 tmp_ = RREG32(reg); \ |
| 1993 | tmp_ &= (mask); \ |
| 1994 | tmp_ |= ((val) & ~(mask)); \ |
| 1995 | WREG32(reg, tmp_); \ |
| 1996 | } while (0) |
| 1997 | #define WREG32_AND(reg, and) WREG32_P(reg, 0, and) |
| 1998 | #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or)) |
| 1999 | |
Oded Gabbay | ac0ae6a | 2020-05-11 10:29:27 +0300 | [diff] [blame] | 2000 | #define RMWREG32(reg, val, mask) \ |
| 2001 | do { \ |
| 2002 | u32 tmp_ = RREG32(reg); \ |
| 2003 | tmp_ &= ~(mask); \ |
| 2004 | tmp_ |= ((val) << __ffs(mask)); \ |
| 2005 | WREG32(reg, tmp_); \ |
| 2006 | } while (0) |
| 2007 | |
| 2008 | #define RREG32_MASK(reg, mask) ((RREG32(reg) & mask) >> __ffs(mask)) |
| 2009 | |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2010 | #define REG_FIELD_SHIFT(reg, field) reg##_##field##_SHIFT |
| 2011 | #define REG_FIELD_MASK(reg, field) reg##_##field##_MASK |
Oded Gabbay | 8fdacf2 | 2019-10-02 14:14:08 +0300 | [diff] [blame] | 2012 | #define WREG32_FIELD(reg, offset, field, val) \ |
| 2013 | WREG32(mm##reg + offset, (RREG32(mm##reg + offset) & \ |
| 2014 | ~REG_FIELD_MASK(reg, field)) | \ |
| 2015 | (val) << REG_FIELD_SHIFT(reg, field)) |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2016 | |
Oded Gabbay | ed0fc50 | 2019-07-18 11:14:37 +0300 | [diff] [blame] | 2017 | /* Timeout should be longer when working with simulator but cap the |
| 2018 | * increased timeout to some maximum |
| 2019 | */ |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 2020 | #define hl_poll_timeout(hdev, addr, val, cond, sleep_us, timeout_us) \ |
| 2021 | ({ \ |
Dalit Ben Zoor | b1b5377 | 2019-04-30 17:18:51 +0300 | [diff] [blame] | 2022 | ktime_t __timeout; \ |
Dalit Ben Zoor | b1b5377 | 2019-04-30 17:18:51 +0300 | [diff] [blame] | 2023 | if (hdev->pdev) \ |
| 2024 | __timeout = ktime_add_us(ktime_get(), timeout_us); \ |
| 2025 | else \ |
Oded Gabbay | ed0fc50 | 2019-07-18 11:14:37 +0300 | [diff] [blame] | 2026 | __timeout = ktime_add_us(ktime_get(),\ |
| 2027 | min((u64)(timeout_us * 10), \ |
| 2028 | (u64) HL_SIM_MAX_TIMEOUT_US)); \ |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 2029 | might_sleep_if(sleep_us); \ |
| 2030 | for (;;) { \ |
| 2031 | (val) = RREG32(addr); \ |
| 2032 | if (cond) \ |
| 2033 | break; \ |
| 2034 | if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) { \ |
| 2035 | (val) = RREG32(addr); \ |
| 2036 | break; \ |
| 2037 | } \ |
| 2038 | if (sleep_us) \ |
| 2039 | usleep_range((sleep_us >> 2) + 1, sleep_us); \ |
| 2040 | } \ |
| 2041 | (cond) ? 0 : -ETIMEDOUT; \ |
| 2042 | }) |
| 2043 | |
Oded Gabbay | a08b51a | 2019-05-09 01:48:23 +0300 | [diff] [blame] | 2044 | /* |
| 2045 | * address in this macro points always to a memory location in the |
| 2046 | * host's (server's) memory. That location is updated asynchronously |
Ben Segal | 2aa4e41 | 2019-07-18 12:27:00 +0000 | [diff] [blame] | 2047 | * either by the direct access of the device or by another core. |
| 2048 | * |
| 2049 | * To work both in LE and BE architectures, we need to distinguish between the |
| 2050 | * two states (device or another core updates the memory location). Therefore, |
| 2051 | * if mem_written_by_device is true, the host memory being polled will be |
| 2052 | * updated directly by the device. If false, the host memory being polled will |
| 2053 | * be updated by host CPU. Required so host knows whether or not the memory |
| 2054 | * might need to be byte-swapped before returning value to caller. |
Oded Gabbay | a08b51a | 2019-05-09 01:48:23 +0300 | [diff] [blame] | 2055 | */ |
Ben Segal | 2aa4e41 | 2019-07-18 12:27:00 +0000 | [diff] [blame] | 2056 | #define hl_poll_timeout_memory(hdev, addr, val, cond, sleep_us, timeout_us, \ |
| 2057 | mem_written_by_device) \ |
Oded Gabbay | a08b51a | 2019-05-09 01:48:23 +0300 | [diff] [blame] | 2058 | ({ \ |
| 2059 | ktime_t __timeout; \ |
Oded Gabbay | a08b51a | 2019-05-09 01:48:23 +0300 | [diff] [blame] | 2060 | if (hdev->pdev) \ |
| 2061 | __timeout = ktime_add_us(ktime_get(), timeout_us); \ |
| 2062 | else \ |
Oded Gabbay | ed0fc50 | 2019-07-18 11:14:37 +0300 | [diff] [blame] | 2063 | __timeout = ktime_add_us(ktime_get(),\ |
| 2064 | min((u64)(timeout_us * 10), \ |
| 2065 | (u64) HL_SIM_MAX_TIMEOUT_US)); \ |
Oded Gabbay | a08b51a | 2019-05-09 01:48:23 +0300 | [diff] [blame] | 2066 | might_sleep_if(sleep_us); \ |
| 2067 | for (;;) { \ |
| 2068 | /* Verify we read updates done by other cores or by device */ \ |
| 2069 | mb(); \ |
Arnd Bergmann | 82948e6 | 2020-10-26 17:08:06 +0100 | [diff] [blame] | 2070 | (val) = *((u32 *)(addr)); \ |
Ben Segal | 2aa4e41 | 2019-07-18 12:27:00 +0000 | [diff] [blame] | 2071 | if (mem_written_by_device) \ |
Oded Gabbay | 6dc66f7 | 2019-09-03 11:33:55 +0300 | [diff] [blame] | 2072 | (val) = le32_to_cpu(*(__le32 *) &(val)); \ |
Oded Gabbay | a08b51a | 2019-05-09 01:48:23 +0300 | [diff] [blame] | 2073 | if (cond) \ |
| 2074 | break; \ |
| 2075 | if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) { \ |
Arnd Bergmann | 82948e6 | 2020-10-26 17:08:06 +0100 | [diff] [blame] | 2076 | (val) = *((u32 *)(addr)); \ |
Ben Segal | 2aa4e41 | 2019-07-18 12:27:00 +0000 | [diff] [blame] | 2077 | if (mem_written_by_device) \ |
Oded Gabbay | 6dc66f7 | 2019-09-03 11:33:55 +0300 | [diff] [blame] | 2078 | (val) = le32_to_cpu(*(__le32 *) &(val)); \ |
Oded Gabbay | a08b51a | 2019-05-09 01:48:23 +0300 | [diff] [blame] | 2079 | break; \ |
| 2080 | } \ |
| 2081 | if (sleep_us) \ |
| 2082 | usleep_range((sleep_us >> 2) + 1, sleep_us); \ |
| 2083 | } \ |
| 2084 | (cond) ? 0 : -ETIMEDOUT; \ |
| 2085 | }) |
| 2086 | |
| 2087 | #define hl_poll_timeout_device_memory(hdev, addr, val, cond, sleep_us, \ |
| 2088 | timeout_us) \ |
| 2089 | ({ \ |
| 2090 | ktime_t __timeout; \ |
Oded Gabbay | a08b51a | 2019-05-09 01:48:23 +0300 | [diff] [blame] | 2091 | if (hdev->pdev) \ |
| 2092 | __timeout = ktime_add_us(ktime_get(), timeout_us); \ |
| 2093 | else \ |
Oded Gabbay | ed0fc50 | 2019-07-18 11:14:37 +0300 | [diff] [blame] | 2094 | __timeout = ktime_add_us(ktime_get(),\ |
| 2095 | min((u64)(timeout_us * 10), \ |
| 2096 | (u64) HL_SIM_MAX_TIMEOUT_US)); \ |
Oded Gabbay | a08b51a | 2019-05-09 01:48:23 +0300 | [diff] [blame] | 2097 | might_sleep_if(sleep_us); \ |
| 2098 | for (;;) { \ |
| 2099 | (val) = readl(addr); \ |
| 2100 | if (cond) \ |
| 2101 | break; \ |
| 2102 | if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) { \ |
| 2103 | (val) = readl(addr); \ |
| 2104 | break; \ |
| 2105 | } \ |
| 2106 | if (sleep_us) \ |
| 2107 | usleep_range((sleep_us >> 2) + 1, sleep_us); \ |
| 2108 | } \ |
| 2109 | (cond) ? 0 : -ETIMEDOUT; \ |
| 2110 | }) |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 2111 | |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2112 | struct hwmon_chip_info; |
| 2113 | |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2114 | /** |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2115 | * struct hl_device_reset_work - reset workqueue task wrapper. |
Ofir Bitton | adb5129 | 2020-10-08 10:27:42 +0300 | [diff] [blame] | 2116 | * @wq: work queue for device reset procedure. |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2117 | * @reset_work: reset work to be done. |
| 2118 | * @hdev: habanalabs device structure. |
| 2119 | */ |
| 2120 | struct hl_device_reset_work { |
Ofir Bitton | adb5129 | 2020-10-08 10:27:42 +0300 | [diff] [blame] | 2121 | struct workqueue_struct *wq; |
| 2122 | struct delayed_work reset_work; |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2123 | struct hl_device *hdev; |
| 2124 | }; |
| 2125 | |
| 2126 | /** |
Moti Haimovski | ccf979e | 2020-10-05 17:59:29 +0300 | [diff] [blame] | 2127 | * struct hr_mmu_hop_addrs - used for holding per-device host-resident mmu hop |
| 2128 | * information. |
| 2129 | * @virt_addr: the virtual address of the hop. |
| 2130 | * @phys-addr: the physical address of the hop (used by the device-mmu). |
| 2131 | * @shadow_addr: The shadow of the hop used by the driver for walking the hops. |
| 2132 | */ |
| 2133 | struct hr_mmu_hop_addrs { |
| 2134 | u64 virt_addr; |
| 2135 | u64 phys_addr; |
| 2136 | u64 shadow_addr; |
| 2137 | }; |
Moti Haimovski | d83fe66 | 2020-08-12 13:33:44 +0300 | [diff] [blame] | 2138 | |
| 2139 | /** |
Moti Haimovski | ccf979e | 2020-10-05 17:59:29 +0300 | [diff] [blame] | 2140 | * struct hl_mmu_hr_pgt_priv - used for holding per-device mmu host-resident |
| 2141 | * page-table internal information. |
Moti Haimovski | d83fe66 | 2020-08-12 13:33:44 +0300 | [diff] [blame] | 2142 | * @mmu_pgt_pool: pool of page tables used by MMU for allocating hops. |
| 2143 | * @mmu_shadow_hop0: shadow array of hop0 tables. |
| 2144 | */ |
Moti Haimovski | ccf979e | 2020-10-05 17:59:29 +0300 | [diff] [blame] | 2145 | struct hl_mmu_hr_priv { |
| 2146 | struct gen_pool *mmu_pgt_pool; |
| 2147 | struct hr_mmu_hop_addrs *mmu_shadow_hop0; |
| 2148 | }; |
| 2149 | |
| 2150 | /** |
| 2151 | * struct hl_mmu_dr_pgt_priv - used for holding per-device mmu device-resident |
| 2152 | * page-table internal information. |
| 2153 | * @mmu_pgt_pool: pool of page tables used by MMU for allocating hops. |
| 2154 | * @mmu_shadow_hop0: shadow array of hop0 tables. |
| 2155 | */ |
| 2156 | struct hl_mmu_dr_priv { |
Moti Haimovski | d83fe66 | 2020-08-12 13:33:44 +0300 | [diff] [blame] | 2157 | struct gen_pool *mmu_pgt_pool; |
| 2158 | void *mmu_shadow_hop0; |
| 2159 | }; |
| 2160 | |
| 2161 | /** |
Moti Haimovski | ccf979e | 2020-10-05 17:59:29 +0300 | [diff] [blame] | 2162 | * struct hl_mmu_priv - used for holding per-device mmu internal information. |
| 2163 | * @dr: information on the device-resident MMU, when exists. |
| 2164 | * @hr: information on the host-resident MMU, when exists. |
| 2165 | */ |
| 2166 | struct hl_mmu_priv { |
| 2167 | struct hl_mmu_dr_priv dr; |
| 2168 | struct hl_mmu_hr_priv hr; |
| 2169 | }; |
| 2170 | |
| 2171 | /** |
Moti Haimovski | 00e1b59 | 2020-10-27 10:55:42 +0200 | [diff] [blame] | 2172 | * struct hl_mmu_per_hop_info - A structure describing one TLB HOP and its entry |
| 2173 | * that was created in order to translate a virtual address to a |
| 2174 | * physical one. |
| 2175 | * @hop_addr: The address of the hop. |
| 2176 | * @hop_pte_addr: The address of the hop entry. |
| 2177 | * @hop_pte_val: The value in the hop entry. |
| 2178 | */ |
| 2179 | struct hl_mmu_per_hop_info { |
| 2180 | u64 hop_addr; |
| 2181 | u64 hop_pte_addr; |
| 2182 | u64 hop_pte_val; |
| 2183 | }; |
| 2184 | |
| 2185 | /** |
| 2186 | * struct hl_mmu_hop_info - A structure describing the TLB hops and their |
| 2187 | * hop-entries that were created in order to translate a virtual address to a |
| 2188 | * physical one. |
Moti Haimovski | b19dc67 | 2020-11-18 20:15:29 +0200 | [diff] [blame] | 2189 | * @scrambled_vaddr: The value of the virtual address after scrambling. This |
| 2190 | * address replaces the original virtual-address when mapped |
| 2191 | * in the MMU tables. |
farah kassabri | 89473a1 | 2021-01-12 17:24:00 +0200 | [diff] [blame] | 2192 | * @unscrambled_paddr: The un-scrambled physical address. |
Moti Haimovski | 00e1b59 | 2020-10-27 10:55:42 +0200 | [diff] [blame] | 2193 | * @hop_info: Array holding the per-hop information used for the translation. |
| 2194 | * @used_hops: The number of hops used for the translation. |
farah kassabri | 89473a1 | 2021-01-12 17:24:00 +0200 | [diff] [blame] | 2195 | * @range_type: virtual address range type. |
Moti Haimovski | 00e1b59 | 2020-10-27 10:55:42 +0200 | [diff] [blame] | 2196 | */ |
| 2197 | struct hl_mmu_hop_info { |
Moti Haimovski | b19dc67 | 2020-11-18 20:15:29 +0200 | [diff] [blame] | 2198 | u64 scrambled_vaddr; |
farah kassabri | 89473a1 | 2021-01-12 17:24:00 +0200 | [diff] [blame] | 2199 | u64 unscrambled_paddr; |
Moti Haimovski | 00e1b59 | 2020-10-27 10:55:42 +0200 | [diff] [blame] | 2200 | struct hl_mmu_per_hop_info hop_info[MMU_ARCH_5_HOPS]; |
| 2201 | u32 used_hops; |
farah kassabri | 89473a1 | 2021-01-12 17:24:00 +0200 | [diff] [blame] | 2202 | enum hl_va_range_type range_type; |
Moti Haimovski | 00e1b59 | 2020-10-27 10:55:42 +0200 | [diff] [blame] | 2203 | }; |
| 2204 | |
| 2205 | /** |
Moti Haimovski | d83fe66 | 2020-08-12 13:33:44 +0300 | [diff] [blame] | 2206 | * struct hl_mmu_funcs - Device related MMU functions. |
| 2207 | * @init: initialize the MMU module. |
| 2208 | * @fini: release the MMU module. |
| 2209 | * @ctx_init: Initialize a context for using the MMU module. |
| 2210 | * @ctx_fini: disable a ctx from using the mmu module. |
| 2211 | * @map: maps a virtual address to physical address for a context. |
| 2212 | * @unmap: unmap a virtual address of a context. |
| 2213 | * @flush: flush all writes from all cores to reach device MMU. |
| 2214 | * @swap_out: marks all mapping of the given context as swapped out. |
| 2215 | * @swap_in: marks all mapping of the given context as swapped in. |
Moti Haimovski | 00e1b59 | 2020-10-27 10:55:42 +0200 | [diff] [blame] | 2216 | * @get_tlb_info: returns the list of hops and hop-entries used that were |
| 2217 | * created in order to translate the giver virtual address to a |
| 2218 | * physical one. |
Moti Haimovski | d83fe66 | 2020-08-12 13:33:44 +0300 | [diff] [blame] | 2219 | */ |
| 2220 | struct hl_mmu_funcs { |
| 2221 | int (*init)(struct hl_device *hdev); |
| 2222 | void (*fini)(struct hl_device *hdev); |
| 2223 | int (*ctx_init)(struct hl_ctx *ctx); |
| 2224 | void (*ctx_fini)(struct hl_ctx *ctx); |
| 2225 | int (*map)(struct hl_ctx *ctx, |
| 2226 | u64 virt_addr, u64 phys_addr, u32 page_size, |
| 2227 | bool is_dram_addr); |
| 2228 | int (*unmap)(struct hl_ctx *ctx, |
| 2229 | u64 virt_addr, bool is_dram_addr); |
| 2230 | void (*flush)(struct hl_ctx *ctx); |
| 2231 | void (*swap_out)(struct hl_ctx *ctx); |
| 2232 | void (*swap_in)(struct hl_ctx *ctx); |
Moti Haimovski | 00e1b59 | 2020-10-27 10:55:42 +0200 | [diff] [blame] | 2233 | int (*get_tlb_info)(struct hl_ctx *ctx, |
| 2234 | u64 virt_addr, struct hl_mmu_hop_info *hops); |
Moti Haimovski | d83fe66 | 2020-08-12 13:33:44 +0300 | [diff] [blame] | 2235 | }; |
| 2236 | |
Oded Gabbay | 75b3cb2 | 2019-08-28 17:32:04 +0300 | [diff] [blame] | 2237 | /** |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2238 | * struct hl_device - habanalabs device structure. |
| 2239 | * @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] | 2240 | * @pcie_bar_phys: array of available PCIe bars physical addresses. |
| 2241 | * (required only for PCI address match mode) |
| 2242 | * @pcie_bar: array of available PCIe bars virtual addresses. |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2243 | * @rmmio: configuration area address on SRAM. |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2244 | * @cdev: related char device. |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 2245 | * @cdev_ctrl: char device for control operations only (INFO IOCTL) |
| 2246 | * @dev: related kernel basic device structure. |
| 2247 | * @dev_ctrl: related kernel device structure for the control device |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2248 | * @work_freq: delayed work to lower device frequency if possible. |
Oded Gabbay | 6138bbe | 2020-09-04 20:18:16 +0300 | [diff] [blame] | 2249 | * @work_heartbeat: delayed work for CPU-CP is-alive check. |
Ofir Bitton | adb5129 | 2020-10-08 10:27:42 +0300 | [diff] [blame] | 2250 | * @device_reset_work: delayed work which performs hard reset |
Oded Gabbay | 6138bbe | 2020-09-04 20:18:16 +0300 | [diff] [blame] | 2251 | * @asic_name: ASIC specific name. |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2252 | * @asic_type: ASIC specific type. |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2253 | * @completion_queue: array of hl_cq. |
Ofir Bitton | ab5f5c3 | 2021-01-12 18:37:19 +0200 | [diff] [blame] | 2254 | * @user_interrupt: array of hl_user_interrupt. upon the corresponding user |
| 2255 | * interrupt, driver will monitor the list of fences |
| 2256 | * registered to this interrupt. |
| 2257 | * @common_user_interrupt: common user interrupt for all user interrupts. |
| 2258 | * upon any user interrupt, driver will monitor the |
| 2259 | * list of fences registered to this common structure. |
Ofir Bitton | 5574cb2 | 2020-07-05 13:35:51 +0300 | [diff] [blame] | 2260 | * @cq_wq: work queues of completion queues for executing work in process |
| 2261 | * context. |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2262 | * @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] | 2263 | * @sob_reset_wq: work queue for sob reset executions. |
Oded Gabbay | 4c172bb | 2019-08-30 16:59:33 +0300 | [diff] [blame] | 2264 | * @kernel_ctx: Kernel driver context structure. |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2265 | * @kernel_queues: array of hl_hw_queue. |
Tomer Tayar | 804a7227 | 2020-10-30 11:16:23 +0200 | [diff] [blame] | 2266 | * @cs_mirror_list: CS mirror list for TDR. |
| 2267 | * @cs_mirror_lock: protects cs_mirror_list. |
Zvika Yehudai | 38e19d0 | 2021-06-15 14:12:20 +0300 | [diff] [blame] | 2268 | * @kernel_cb_mgr: command buffer manager for creating/destroying/handling CBs. |
Oded Gabbay | 6138bbe | 2020-09-04 20:18:16 +0300 | [diff] [blame] | 2269 | * @event_queue: event queue for IRQ from CPU-CP. |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2270 | * @dma_pool: DMA pool for small allocations. |
Oded Gabbay | 6138bbe | 2020-09-04 20:18:16 +0300 | [diff] [blame] | 2271 | * @cpu_accessible_dma_mem: Host <-> CPU-CP shared memory CPU address. |
| 2272 | * @cpu_accessible_dma_address: Host <-> CPU-CP shared memory DMA address. |
| 2273 | * @cpu_accessible_dma_pool: Host <-> CPU-CP shared memory pool. |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 2274 | * @asid_bitmap: holds used/available ASIDs. |
| 2275 | * @asid_mutex: protects asid_bitmap. |
Oded Gabbay | 6138bbe | 2020-09-04 20:18:16 +0300 | [diff] [blame] | 2276 | * @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] | 2277 | * @debug_lock: protects critical section of setting debug mode for device |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2278 | * @asic_prop: ASIC specific immutable properties. |
| 2279 | * @asic_funcs: ASIC specific functions. |
| 2280 | * @asic_specific: ASIC specific information to use only from ASIC files. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 2281 | * @vm: virtual memory manager for MMU. |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2282 | * @hwmon_dev: H/W monitor device. |
| 2283 | * @pm_mng_profile: current power management profile. |
| 2284 | * @hl_chip_info: ASIC's sensors information. |
Ofir Bitton | 66a7640 | 2020-10-05 14:40:10 +0300 | [diff] [blame] | 2285 | * @device_status_description: device status description. |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 2286 | * @hl_debugfs: device's debugfs manager. |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 2287 | * @cb_pool: list of preallocated CBs. |
| 2288 | * @cb_pool_lock: protects the CB pool. |
Ofir Bitton | a04b7cd | 2020-07-13 13:36:55 +0300 | [diff] [blame] | 2289 | * @internal_cb_pool_virt_addr: internal command buffer pool virtual address. |
| 2290 | * @internal_cb_pool_dma_addr: internal command buffer pool dma address. |
| 2291 | * @internal_cb_pool: internal command buffer memory pool. |
| 2292 | * @internal_cb_va_base: internal cb pool mmu virtual address base |
Oded Gabbay | eb7caf8 | 2019-07-30 11:56:09 +0300 | [diff] [blame] | 2293 | * @fpriv_list: list of file private data structures. Each structure is created |
| 2294 | * when a user opens the device |
| 2295 | * @fpriv_list_lock: protects the fpriv_list |
Oded Gabbay | 86d5307 | 2019-07-30 11:49:36 +0300 | [diff] [blame] | 2296 | * @compute_ctx: current compute context executing. |
Ofir Bitton | db491e4 | 2020-06-18 09:51:16 +0300 | [diff] [blame] | 2297 | * @aggregated_cs_counters: aggregated cs counters among all contexts |
Moti Haimovski | d83fe66 | 2020-08-12 13:33:44 +0300 | [diff] [blame] | 2298 | * @mmu_priv: device-specific MMU data. |
| 2299 | * @mmu_func: device-related MMU functions. |
Ohad Sharabi | a22f0ec | 2021-04-11 23:06:46 +0300 | [diff] [blame] | 2300 | * @fw_loader: FW loader manager. |
Ohad Sharabi | c592c27 | 2021-04-21 13:03:21 +0300 | [diff] [blame] | 2301 | * @pci_mem_region: array of memory regions in the PCI |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 2302 | * @state_dump_specs: constants and dictionaries needed to dump system state. |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 2303 | * @dram_used_mem: current DRAM memory consumption. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2304 | * @timeout_jiffies: device CS timeout value. |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2305 | * @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] | 2306 | * value is saved so in case of hard-reset, the driver will restore |
| 2307 | * this value and update the F/W after the re-initialization |
Oded Gabbay | e38bfd3 | 2020-07-03 20:46:12 +0300 | [diff] [blame] | 2308 | * @clock_gating_mask: is clock gating enabled. bitmask that represents the |
| 2309 | * different engines. See debugfs-driver-habanalabs for |
| 2310 | * details. |
Oded Gabbay | 27a9e35 | 2021-04-12 09:52:05 +0300 | [diff] [blame] | 2311 | * @boot_error_status_mask: contains a mask of the device boot error status. |
| 2312 | * Each bit represents a different error, according to |
| 2313 | * the defines in hl_boot_if.h. If the bit is cleared, |
| 2314 | * the error will be ignored by the driver during |
| 2315 | * device initialization. Mainly used to debug and |
| 2316 | * workaround firmware bugs |
Yuri Nudelman | e307b30 | 2021-05-24 11:25:21 +0300 | [diff] [blame] | 2317 | * @last_successful_open_jif: timestamp (jiffies) of the last successful |
| 2318 | * device open. |
| 2319 | * @last_open_session_duration_jif: duration (jiffies) of the last device open |
| 2320 | * session. |
| 2321 | * @open_counter: number of successful device open operations. |
Oded Gabbay | cbaa99e | 2019-03-03 15:13:15 +0200 | [diff] [blame] | 2322 | * @in_reset: is device in reset flow. |
Oded Gabbay | 75b3cb2 | 2019-08-28 17:32:04 +0300 | [diff] [blame] | 2323 | * @curr_pll_profile: current PLL profile. |
Oded Gabbay | 58361aa | 2020-08-08 23:34:47 +0300 | [diff] [blame] | 2324 | * @card_type: Various ASICs have several card types. This indicates the card |
| 2325 | * type of the current device. |
Oded Gabbay | 4c172bb | 2019-08-30 16:59:33 +0300 | [diff] [blame] | 2326 | * @major: habanalabs kernel driver major. |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2327 | * @high_pll: high PLL profile frequency. |
Oded Gabbay | 4c172bb | 2019-08-30 16:59:33 +0300 | [diff] [blame] | 2328 | * @soft_reset_cnt: number of soft reset since the driver was loaded. |
| 2329 | * @hard_reset_cnt: number of hard reset since the driver was loaded. |
Ofir Bitton | 0a068ad | 2020-07-21 10:49:51 +0300 | [diff] [blame] | 2330 | * @clk_throttling_reason: bitmask represents the current clk throttling reasons |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2331 | * @id: device minor. |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 2332 | * @id_control: minor of the control device |
Oded Gabbay | ac0ae6a | 2020-05-11 10:29:27 +0300 | [diff] [blame] | 2333 | * @cpu_pci_msb_addr: 50-bit extension bits for the device CPU's 40-bit |
| 2334 | * addresses. |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2335 | * @disabled: is device disabled. |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2336 | * @late_init_done: is late init stage was done during initialization. |
| 2337 | * @hwmon_initialized: is H/W monitor sensors was initialized. |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2338 | * @hard_reset_pending: is there a hard reset work pending. |
Oded Gabbay | 6138bbe | 2020-09-04 20:18:16 +0300 | [diff] [blame] | 2339 | * @heartbeat: is heartbeat sanity check towards CPU-CP enabled. |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2340 | * @reset_on_lockup: true if a reset should be done in case of stuck CS, false |
| 2341 | * otherwise. |
Omer Shpigelman | 27ca384c | 2019-02-28 10:46:11 +0200 | [diff] [blame] | 2342 | * @dram_default_page_mapping: is DRAM default page mapping enabled. |
farah kassabri | 03df136 | 2020-05-06 11:17:38 +0300 | [diff] [blame] | 2343 | * @memory_scrub: true to perform device memory scrub in various locations, |
| 2344 | * such as context-switch, context close, page free, etc. |
Omer Shpigelman | 64a7e29 | 2020-01-05 09:05:45 +0000 | [diff] [blame] | 2345 | * @pmmu_huge_range: is a different virtual addresses range used for PMMU with |
| 2346 | * huge pages. |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2347 | * @init_done: is the initialization of the device done. |
Oded Gabbay | a28ce42 | 2019-02-28 10:46:12 +0200 | [diff] [blame] | 2348 | * @device_cpu_disabled: is the device CPU disabled (due to timeouts) |
Oded Gabbay | d997387 | 2019-03-07 18:03:23 +0200 | [diff] [blame] | 2349 | * @dma_mask: the dma mask that was set for this device |
Oded Gabbay | eb7caf8 | 2019-07-30 11:56:09 +0300 | [diff] [blame] | 2350 | * @in_debug: is device under debug. This, together with fpriv_list, enforces |
Oded Gabbay | 1973497 | 2019-05-04 17:36:06 +0300 | [diff] [blame] | 2351 | * that only a single user is configuring the debug infrastructure. |
Oded Gabbay | cb056b9 | 2020-03-29 13:18:30 +0300 | [diff] [blame] | 2352 | * @power9_64bit_dma_enable: true to enable 64-bit DMA mask support. Relevant |
| 2353 | * only to POWER9 machines. |
Tomer Tayar | ea451f8 | 2019-08-08 12:25:52 +0000 | [diff] [blame] | 2354 | * @cdev_sysfs_created: were char devices and sysfs nodes created. |
Omer Shpigelman | 76cedc7 | 2020-03-22 21:12:51 +0200 | [diff] [blame] | 2355 | * @stop_on_err: true if engines should stop on error. |
Omer Shpigelman | f9e5f29 | 2020-05-07 13:41:16 +0300 | [diff] [blame] | 2356 | * @supports_sync_stream: is sync stream supported. |
Ofir Bitton | 21e7a34 | 2020-05-14 18:25:47 +0300 | [diff] [blame] | 2357 | * @sync_stream_queue_idx: helper index for sync stream queues initialization. |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 2358 | * @collective_mon_idx: helper index for collective initialization |
Omer Shpigelman | 9e5e49c | 2020-05-10 14:10:15 +0300 | [diff] [blame] | 2359 | * @supports_coresight: is CoreSight supported. |
Oded Gabbay | 6644682 | 2020-05-18 16:48:01 +0300 | [diff] [blame] | 2360 | * @supports_soft_reset: is soft reset supported. |
Ofir Bitton | 23bace6 | 2021-06-08 17:24:52 +0300 | [diff] [blame] | 2361 | * @allow_external_soft_reset: true if soft reset initiated by user or TDR is |
| 2362 | * allowed. |
Tomer Tayar | ef6a0f6 | 2020-07-09 16:17:48 +0300 | [diff] [blame] | 2363 | * @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] | 2364 | * @needs_reset: true if reset_on_lockup is false and device should be reset |
| 2365 | * due to lockup. |
Ofir Bitton | adb5129 | 2020-10-08 10:27:42 +0300 | [diff] [blame] | 2366 | * @process_kill_trial_cnt: number of trials reset thread tried killing |
| 2367 | * user processes |
| 2368 | * @device_fini_pending: true if device_fini was called and might be |
| 2369 | * waiting for the reset thread to finish |
Ofir Bitton | 2795c88 | 2020-12-08 13:47:05 +0200 | [diff] [blame] | 2370 | * @supports_staged_submission: true if staged submissions are supported |
Koby Elbaz | 3e0ca9f | 2021-05-04 20:10:47 +0300 | [diff] [blame] | 2371 | * @curr_reset_cause: saves an enumerated reset cause when a hard reset is |
| 2372 | * triggered, and cleared after it is shared with preboot. |
Yuri Nudelman | 4d04121 | 2021-06-13 09:22:20 +0300 | [diff] [blame] | 2373 | * @skip_reset_on_timeout: Skip device reset if CS has timed out, wait for it to |
| 2374 | * complete instead. |
Koby Elbaz | b7a71fd | 2021-06-15 17:07:02 +0300 | [diff] [blame] | 2375 | * @device_cpu_is_halted: Flag to indicate whether the device CPU was already |
| 2376 | * halted. We can't halt it again because the COMMS |
| 2377 | * protocol will throw an error. Relevant only for |
| 2378 | * cases where Linux was not loaded to device CPU |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2379 | */ |
| 2380 | struct hl_device { |
| 2381 | struct pci_dev *pdev; |
Ofir Bitton | f4cbfd2 | 2020-06-15 17:45:12 +0300 | [diff] [blame] | 2382 | u64 pcie_bar_phys[HL_PCI_NUM_BARS]; |
| 2383 | void __iomem *pcie_bar[HL_PCI_NUM_BARS]; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2384 | void __iomem *rmmio; |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2385 | struct cdev cdev; |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 2386 | struct cdev cdev_ctrl; |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2387 | struct device *dev; |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 2388 | struct device *dev_ctrl; |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2389 | struct delayed_work work_freq; |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2390 | struct delayed_work work_heartbeat; |
Ofir Bitton | adb5129 | 2020-10-08 10:27:42 +0300 | [diff] [blame] | 2391 | struct hl_device_reset_work device_reset_work; |
Ofir Bitton | 66a7640 | 2020-10-05 14:40:10 +0300 | [diff] [blame] | 2392 | char asic_name[HL_STR_MAX]; |
| 2393 | char status[HL_DEV_STS_MAX][HL_STR_MAX]; |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2394 | enum hl_asic_type asic_type; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2395 | struct hl_cq *completion_queue; |
Ofir Bitton | 2d44c6f | 2021-01-12 14:43:09 +0200 | [diff] [blame] | 2396 | struct hl_user_interrupt *user_interrupt; |
Ofir Bitton | ab5f5c3 | 2021-01-12 18:37:19 +0200 | [diff] [blame] | 2397 | struct hl_user_interrupt common_user_interrupt; |
Ofir Bitton | 5574cb2 | 2020-07-05 13:35:51 +0300 | [diff] [blame] | 2398 | struct workqueue_struct **cq_wq; |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 2399 | struct workqueue_struct *eq_wq; |
Ofir Bitton | 8445dde | 2021-03-18 17:36:57 +0200 | [diff] [blame] | 2400 | struct workqueue_struct *sob_reset_wq; |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 2401 | struct hl_ctx *kernel_ctx; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2402 | struct hl_hw_queue *kernel_queues; |
Tomer Tayar | 804a7227 | 2020-10-30 11:16:23 +0200 | [diff] [blame] | 2403 | struct list_head cs_mirror_list; |
| 2404 | spinlock_t cs_mirror_lock; |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 2405 | struct hl_cb_mgr kernel_cb_mgr; |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 2406 | struct hl_eq event_queue; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2407 | struct dma_pool *dma_pool; |
| 2408 | void *cpu_accessible_dma_mem; |
| 2409 | dma_addr_t cpu_accessible_dma_address; |
| 2410 | struct gen_pool *cpu_accessible_dma_pool; |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 2411 | unsigned long *asid_bitmap; |
| 2412 | struct mutex asid_mutex; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2413 | struct mutex send_cpu_message_lock; |
Oded Gabbay | 1973497 | 2019-05-04 17:36:06 +0300 | [diff] [blame] | 2414 | struct mutex debug_lock; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2415 | struct asic_fixed_properties asic_prop; |
| 2416 | const struct hl_asic_funcs *asic_funcs; |
| 2417 | void *asic_specific; |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 2418 | struct hl_vm vm; |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2419 | struct device *hwmon_dev; |
| 2420 | enum hl_pm_mng_profile pm_mng_profile; |
| 2421 | struct hwmon_chip_info *hl_chip_info; |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 2422 | |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 2423 | struct hl_dbg_device_entry hl_debugfs; |
| 2424 | |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 2425 | struct list_head cb_pool; |
| 2426 | spinlock_t cb_pool_lock; |
| 2427 | |
Ofir Bitton | a04b7cd | 2020-07-13 13:36:55 +0300 | [diff] [blame] | 2428 | void *internal_cb_pool_virt_addr; |
| 2429 | dma_addr_t internal_cb_pool_dma_addr; |
| 2430 | struct gen_pool *internal_cb_pool; |
| 2431 | u64 internal_cb_va_base; |
| 2432 | |
Oded Gabbay | eb7caf8 | 2019-07-30 11:56:09 +0300 | [diff] [blame] | 2433 | struct list_head fpriv_list; |
| 2434 | struct mutex fpriv_list_lock; |
| 2435 | |
Oded Gabbay | 86d5307 | 2019-07-30 11:49:36 +0300 | [diff] [blame] | 2436 | struct hl_ctx *compute_ctx; |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2437 | |
Oded Gabbay | 23c15ae | 2020-09-30 14:25:55 +0300 | [diff] [blame] | 2438 | struct hl_cs_counters_atomic aggregated_cs_counters; |
Ofir Bitton | db491e4 | 2020-06-18 09:51:16 +0300 | [diff] [blame] | 2439 | |
Moti Haimovski | d83fe66 | 2020-08-12 13:33:44 +0300 | [diff] [blame] | 2440 | struct hl_mmu_priv mmu_priv; |
Moti Haimovski | ccf979e | 2020-10-05 17:59:29 +0300 | [diff] [blame] | 2441 | struct hl_mmu_funcs mmu_func[MMU_NUM_PGT_LOCATIONS]; |
Moti Haimovski | d83fe66 | 2020-08-12 13:33:44 +0300 | [diff] [blame] | 2442 | |
Ohad Sharabi | a22f0ec | 2021-04-11 23:06:46 +0300 | [diff] [blame] | 2443 | struct fw_load_mgr fw_loader; |
| 2444 | |
Ohad Sharabi | c592c27 | 2021-04-21 13:03:21 +0300 | [diff] [blame] | 2445 | struct pci_mem_region pci_mem_region[PCI_REGION_NUMBER]; |
| 2446 | |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 2447 | struct hl_state_dump_specs state_dump_specs; |
| 2448 | |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 2449 | atomic64_t dram_used_mem; |
Oded Gabbay | cbaa99e | 2019-03-03 15:13:15 +0200 | [diff] [blame] | 2450 | u64 timeout_jiffies; |
| 2451 | u64 max_power; |
Oded Gabbay | e38bfd3 | 2020-07-03 20:46:12 +0300 | [diff] [blame] | 2452 | u64 clock_gating_mask; |
Oded Gabbay | 27a9e35 | 2021-04-12 09:52:05 +0300 | [diff] [blame] | 2453 | u64 boot_error_status_mask; |
Yuri Nudelman | e307b30 | 2021-05-24 11:25:21 +0300 | [diff] [blame] | 2454 | u64 last_successful_open_jif; |
| 2455 | u64 last_open_session_duration_jif; |
| 2456 | u64 open_counter; |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2457 | atomic_t in_reset; |
Oded Gabbay | eb7caf8 | 2019-07-30 11:56:09 +0300 | [diff] [blame] | 2458 | enum hl_pll_frequency curr_pll_profile; |
Oded Gabbay | 2f55342 | 2020-08-15 16:28:10 +0300 | [diff] [blame] | 2459 | enum cpucp_card_types card_type; |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2460 | u32 major; |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2461 | u32 high_pll; |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2462 | u32 soft_reset_cnt; |
| 2463 | u32 hard_reset_cnt; |
Ofir Bitton | 0a068ad | 2020-07-21 10:49:51 +0300 | [diff] [blame] | 2464 | u32 clk_throttling_reason; |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2465 | u16 id; |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 2466 | u16 id_control; |
Oded Gabbay | ac0ae6a | 2020-05-11 10:29:27 +0300 | [diff] [blame] | 2467 | u16 cpu_pci_msb_addr; |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2468 | u8 disabled; |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2469 | u8 late_init_done; |
| 2470 | u8 hwmon_initialized; |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2471 | u8 hard_reset_pending; |
| 2472 | u8 heartbeat; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2473 | u8 reset_on_lockup; |
Omer Shpigelman | 27ca384c | 2019-02-28 10:46:11 +0200 | [diff] [blame] | 2474 | u8 dram_default_page_mapping; |
farah kassabri | 03df136 | 2020-05-06 11:17:38 +0300 | [diff] [blame] | 2475 | u8 memory_scrub; |
Omer Shpigelman | 64a7e29 | 2020-01-05 09:05:45 +0000 | [diff] [blame] | 2476 | u8 pmmu_huge_range; |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2477 | u8 init_done; |
Oded Gabbay | a28ce42 | 2019-02-28 10:46:12 +0200 | [diff] [blame] | 2478 | u8 device_cpu_disabled; |
Oded Gabbay | d997387 | 2019-03-07 18:03:23 +0200 | [diff] [blame] | 2479 | u8 dma_mask; |
Oded Gabbay | 1973497 | 2019-05-04 17:36:06 +0300 | [diff] [blame] | 2480 | u8 in_debug; |
Oded Gabbay | ac0ae6a | 2020-05-11 10:29:27 +0300 | [diff] [blame] | 2481 | u8 power9_64bit_dma_enable; |
Tomer Tayar | ea451f8 | 2019-08-08 12:25:52 +0000 | [diff] [blame] | 2482 | u8 cdev_sysfs_created; |
Omer Shpigelman | 76cedc7 | 2020-03-22 21:12:51 +0200 | [diff] [blame] | 2483 | u8 stop_on_err; |
Omer Shpigelman | f9e5f29 | 2020-05-07 13:41:16 +0300 | [diff] [blame] | 2484 | u8 supports_sync_stream; |
Ofir Bitton | 21e7a34 | 2020-05-14 18:25:47 +0300 | [diff] [blame] | 2485 | u8 sync_stream_queue_idx; |
Ofir Bitton | 5fe1c17 | 2020-09-10 10:10:55 +0300 | [diff] [blame] | 2486 | u8 collective_mon_idx; |
Omer Shpigelman | 9e5e49c | 2020-05-10 14:10:15 +0300 | [diff] [blame] | 2487 | u8 supports_coresight; |
Oded Gabbay | 6644682 | 2020-05-18 16:48:01 +0300 | [diff] [blame] | 2488 | u8 supports_soft_reset; |
Ofir Bitton | 23bace6 | 2021-06-08 17:24:52 +0300 | [diff] [blame] | 2489 | u8 allow_external_soft_reset; |
Tomer Tayar | ef6a0f6 | 2020-07-09 16:17:48 +0300 | [diff] [blame] | 2490 | u8 supports_cb_mapping; |
Ofir Bitton | 66a7640 | 2020-10-05 14:40:10 +0300 | [diff] [blame] | 2491 | u8 needs_reset; |
Ofir Bitton | adb5129 | 2020-10-08 10:27:42 +0300 | [diff] [blame] | 2492 | u8 process_kill_trial_cnt; |
| 2493 | u8 device_fini_pending; |
Ofir Bitton | 2795c88 | 2020-12-08 13:47:05 +0200 | [diff] [blame] | 2494 | u8 supports_staged_submission; |
Koby Elbaz | 3e0ca9f | 2021-05-04 20:10:47 +0300 | [diff] [blame] | 2495 | u8 curr_reset_cause; |
Yuri Nudelman | 4d04121 | 2021-06-13 09:22:20 +0300 | [diff] [blame] | 2496 | u8 skip_reset_on_timeout; |
Koby Elbaz | b7a71fd | 2021-06-15 17:07:02 +0300 | [diff] [blame] | 2497 | u8 device_cpu_is_halted; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2498 | |
| 2499 | /* Parameters for bring-up */ |
Oded Gabbay | 3c68157 | 2020-11-02 21:10:39 +0200 | [diff] [blame] | 2500 | u64 nic_ports_mask; |
Ofir Bitton | 6a2f5d7 | 2021-02-15 13:23:04 +0200 | [diff] [blame] | 2501 | u64 fw_components; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2502 | u8 mmu_enable; |
Oded Gabbay | ac0ae6a | 2020-05-11 10:29:27 +0300 | [diff] [blame] | 2503 | u8 mmu_huge_page_opt; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2504 | u8 reset_pcilink; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2505 | u8 cpu_queues_enable; |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2506 | u8 pldm; |
Oded Gabbay | ac0ae6a | 2020-05-11 10:29:27 +0300 | [diff] [blame] | 2507 | u8 axi_drain; |
| 2508 | u8 sram_scrambler_enable; |
| 2509 | u8 dram_scrambler_enable; |
| 2510 | u8 hard_reset_on_fw_events; |
| 2511 | u8 bmc_enable; |
| 2512 | u8 rl_enable; |
Ofir Bitton | d1ddd90 | 2020-10-19 17:04:20 +0300 | [diff] [blame] | 2513 | u8 reset_on_preboot_fail; |
Oded Gabbay | d3ee681 | 2021-02-16 22:49:27 +0200 | [diff] [blame] | 2514 | u8 reset_upon_device_release; |
Ofir Bitton | 84586de | 2021-05-20 13:30:31 +0300 | [diff] [blame] | 2515 | u8 reset_if_device_not_idle; |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2516 | }; |
| 2517 | |
| 2518 | |
| 2519 | /* |
| 2520 | * IOCTLs |
| 2521 | */ |
| 2522 | |
| 2523 | /** |
| 2524 | * typedef hl_ioctl_t - typedef for ioctl function in the driver |
| 2525 | * @hpriv: pointer to the FD's private data, which contains state of |
| 2526 | * user process |
| 2527 | * @data: pointer to the input/output arguments structure of the IOCTL |
| 2528 | * |
| 2529 | * Return: 0 for success, negative value for error |
| 2530 | */ |
| 2531 | typedef int hl_ioctl_t(struct hl_fpriv *hpriv, void *data); |
| 2532 | |
| 2533 | /** |
| 2534 | * struct hl_ioctl_desc - describes an IOCTL entry of the driver. |
| 2535 | * @cmd: the IOCTL code as created by the kernel macros. |
| 2536 | * @func: pointer to the driver's function that should be called for this IOCTL. |
| 2537 | */ |
| 2538 | struct hl_ioctl_desc { |
| 2539 | unsigned int cmd; |
| 2540 | hl_ioctl_t *func; |
| 2541 | }; |
| 2542 | |
| 2543 | |
| 2544 | /* |
| 2545 | * Kernel module functions that can be accessed by entire module |
| 2546 | */ |
| 2547 | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2548 | /** |
| 2549 | * hl_mem_area_inside_range() - Checks whether address+size are inside a range. |
| 2550 | * @address: The start address of the area we want to validate. |
| 2551 | * @size: The size in bytes of the area we want to validate. |
| 2552 | * @range_start_address: The start address of the valid range. |
| 2553 | * @range_end_address: The end address of the valid range. |
| 2554 | * |
| 2555 | * Return: true if the area is inside the valid range, false otherwise. |
| 2556 | */ |
Ofir Bitton | 3654527 | 2020-08-06 11:33:27 +0300 | [diff] [blame] | 2557 | static inline bool hl_mem_area_inside_range(u64 address, u64 size, |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2558 | u64 range_start_address, u64 range_end_address) |
| 2559 | { |
| 2560 | u64 end_address = address + size; |
| 2561 | |
| 2562 | if ((address >= range_start_address) && |
| 2563 | (end_address <= range_end_address) && |
| 2564 | (end_address > address)) |
| 2565 | return true; |
| 2566 | |
| 2567 | return false; |
| 2568 | } |
| 2569 | |
| 2570 | /** |
| 2571 | * hl_mem_area_crosses_range() - Checks whether address+size crossing a range. |
| 2572 | * @address: The start address of the area we want to validate. |
| 2573 | * @size: The size in bytes of the area we want to validate. |
| 2574 | * @range_start_address: The start address of the valid range. |
| 2575 | * @range_end_address: The end address of the valid range. |
| 2576 | * |
| 2577 | * Return: true if the area overlaps part or all of the valid range, |
| 2578 | * false otherwise. |
| 2579 | */ |
| 2580 | static inline bool hl_mem_area_crosses_range(u64 address, u32 size, |
| 2581 | u64 range_start_address, u64 range_end_address) |
| 2582 | { |
| 2583 | u64 end_address = address + size; |
| 2584 | |
| 2585 | if ((address >= range_start_address) && |
| 2586 | (address < range_end_address)) |
| 2587 | return true; |
| 2588 | |
| 2589 | if ((end_address >= range_start_address) && |
| 2590 | (end_address < range_end_address)) |
| 2591 | return true; |
| 2592 | |
| 2593 | if ((address < range_start_address) && |
| 2594 | (end_address >= range_end_address)) |
| 2595 | return true; |
| 2596 | |
| 2597 | return false; |
| 2598 | } |
| 2599 | |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2600 | int hl_device_open(struct inode *inode, struct file *filp); |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 2601 | int hl_device_open_ctrl(struct inode *inode, struct file *filp); |
Ofir Bitton | 66a7640 | 2020-10-05 14:40:10 +0300 | [diff] [blame] | 2602 | bool hl_device_operational(struct hl_device *hdev, |
| 2603 | enum hl_device_status *status); |
Dalit Ben Zoor | aa95708 | 2019-03-24 10:15:44 +0200 | [diff] [blame] | 2604 | enum hl_device_status hl_device_status(struct hl_device *hdev); |
Oded Gabbay | 1973497 | 2019-05-04 17:36:06 +0300 | [diff] [blame] | 2605 | int hl_device_set_debug_mode(struct hl_device *hdev, bool enable); |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2606 | int create_hdev(struct hl_device **dev, struct pci_dev *pdev, |
| 2607 | enum hl_asic_type asic_type, int minor); |
| 2608 | void destroy_hdev(struct hl_device *hdev); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2609 | int hl_hw_queues_create(struct hl_device *hdev); |
| 2610 | void hl_hw_queues_destroy(struct hl_device *hdev); |
| 2611 | 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^] | 2612 | u32 cb_size, u64 cb_ptr); |
| 2613 | void hl_hw_queue_submit_bd(struct hl_device *hdev, struct hl_hw_queue *q, |
| 2614 | u32 ctl, u32 len, u64 ptr); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2615 | int hl_hw_queue_schedule_cs(struct hl_cs *cs); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2616 | u32 hl_hw_queue_add_ptr(u32 ptr, u16 val); |
| 2617 | 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] | 2618 | void hl_hw_queue_update_ci(struct hl_cs *cs); |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2619 | void hl_hw_queue_reset(struct hl_device *hdev, bool hard_reset); |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2620 | |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2621 | #define hl_queue_inc_ptr(p) hl_hw_queue_add_ptr(p, 1) |
| 2622 | #define hl_pi_2_offset(pi) ((pi) & (HL_QUEUE_LENGTH - 1)) |
| 2623 | |
| 2624 | int hl_cq_init(struct hl_device *hdev, struct hl_cq *q, u32 hw_queue_id); |
| 2625 | void hl_cq_fini(struct hl_device *hdev, struct hl_cq *q); |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 2626 | int hl_eq_init(struct hl_device *hdev, struct hl_eq *q); |
| 2627 | void hl_eq_fini(struct hl_device *hdev, struct hl_eq *q); |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2628 | void hl_cq_reset(struct hl_device *hdev, struct hl_cq *q); |
| 2629 | void hl_eq_reset(struct hl_device *hdev, struct hl_eq *q); |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 2630 | irqreturn_t hl_irq_handler_cq(int irq, void *arg); |
| 2631 | irqreturn_t hl_irq_handler_eq(int irq, void *arg); |
Ofir Bitton | 2d44c6f | 2021-01-12 14:43:09 +0200 | [diff] [blame] | 2632 | irqreturn_t hl_irq_handler_user_cq(int irq, void *arg); |
| 2633 | irqreturn_t hl_irq_handler_default(int irq, void *arg); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2634 | u32 hl_cq_inc_ptr(u32 ptr); |
| 2635 | |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 2636 | int hl_asid_init(struct hl_device *hdev); |
| 2637 | void hl_asid_fini(struct hl_device *hdev); |
| 2638 | unsigned long hl_asid_alloc(struct hl_device *hdev); |
| 2639 | void hl_asid_free(struct hl_device *hdev, unsigned long asid); |
| 2640 | |
| 2641 | int hl_ctx_create(struct hl_device *hdev, struct hl_fpriv *hpriv); |
| 2642 | void hl_ctx_free(struct hl_device *hdev, struct hl_ctx *ctx); |
| 2643 | 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] | 2644 | void hl_ctx_do_release(struct kref *ref); |
| 2645 | void hl_ctx_get(struct hl_device *hdev, struct hl_ctx *ctx); |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 2646 | int hl_ctx_put(struct hl_ctx *ctx); |
Ofir Bitton | a98d73c | 2020-07-15 08:52:39 +0300 | [diff] [blame] | 2647 | struct hl_fence *hl_ctx_get_fence(struct hl_ctx *ctx, u64 seq); |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 2648 | void hl_ctx_mgr_init(struct hl_ctx_mgr *mgr); |
| 2649 | 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] | 2650 | |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2651 | int hl_device_init(struct hl_device *hdev, struct class *hclass); |
| 2652 | void hl_device_fini(struct hl_device *hdev); |
| 2653 | int hl_device_suspend(struct hl_device *hdev); |
| 2654 | int hl_device_resume(struct hl_device *hdev); |
Ohad Sharabi | e42a6400f | 2021-02-17 20:42:48 +0200 | [diff] [blame] | 2655 | int hl_device_reset(struct hl_device *hdev, u32 flags); |
Oded Gabbay | 0861e41 | 2019-02-16 00:39:14 +0200 | [diff] [blame] | 2656 | void hl_hpriv_get(struct hl_fpriv *hpriv); |
Oded Gabbay | 278b5f7 | 2021-02-18 10:24:02 +0200 | [diff] [blame] | 2657 | int hl_hpriv_put(struct hl_fpriv *hpriv); |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2658 | 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] | 2659 | int hl_device_utilization(struct hl_device *hdev, u32 *utilization); |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 2660 | |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2661 | int hl_build_hwmon_channel_info(struct hl_device *hdev, |
Oded Gabbay | 2f55342 | 2020-08-15 16:28:10 +0300 | [diff] [blame] | 2662 | struct cpucp_sensor *sensors_arr); |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2663 | |
| 2664 | int hl_sysfs_init(struct hl_device *hdev); |
| 2665 | void hl_sysfs_fini(struct hl_device *hdev); |
| 2666 | |
| 2667 | int hl_hwmon_init(struct hl_device *hdev); |
| 2668 | void hl_hwmon_fini(struct hl_device *hdev); |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2669 | |
Tomer Tayar | fa8641a1 | 2020-09-07 17:36:41 +0300 | [diff] [blame] | 2670 | int hl_cb_create(struct hl_device *hdev, struct hl_cb_mgr *mgr, |
| 2671 | struct hl_ctx *ctx, u32 cb_size, bool internal_cb, |
Tomer Tayar | ef6a0f6 | 2020-07-09 16:17:48 +0300 | [diff] [blame] | 2672 | bool map_cb, u64 *handle); |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 2673 | int hl_cb_destroy(struct hl_device *hdev, struct hl_cb_mgr *mgr, u64 cb_handle); |
| 2674 | 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] | 2675 | 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] | 2676 | struct hl_cb *hl_cb_get(struct hl_device *hdev, struct hl_cb_mgr *mgr, |
| 2677 | u32 handle); |
| 2678 | void hl_cb_put(struct hl_cb *cb); |
| 2679 | void hl_cb_mgr_init(struct hl_cb_mgr *mgr); |
| 2680 | 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] | 2681 | struct hl_cb *hl_cb_kernel_create(struct hl_device *hdev, u32 cb_size, |
| 2682 | bool internal_cb); |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 2683 | int hl_cb_pool_init(struct hl_device *hdev); |
| 2684 | int hl_cb_pool_fini(struct hl_device *hdev); |
Tomer Tayar | ef6a0f6 | 2020-07-09 16:17:48 +0300 | [diff] [blame] | 2685 | int hl_cb_va_pool_init(struct hl_ctx *ctx); |
| 2686 | void hl_cb_va_pool_fini(struct hl_ctx *ctx); |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 2687 | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2688 | void hl_cs_rollback_all(struct hl_device *hdev); |
Ofir Bitton | d3f139c | 2020-11-18 15:46:57 +0200 | [diff] [blame] | 2689 | void hl_pending_cb_list_flush(struct hl_ctx *ctx); |
Tomer Tayar | cb596ae | 2019-10-03 15:22:36 +0000 | [diff] [blame] | 2690 | struct hl_cs_job *hl_cs_allocate_job(struct hl_device *hdev, |
| 2691 | enum hl_queue_type queue_type, bool is_kernel_allocated_cb); |
Omer Shpigelman | b0b5d92 | 2020-05-07 13:57:36 +0300 | [diff] [blame] | 2692 | void hl_sob_reset_error(struct kref *ref); |
Ofir Bitton | 2992c1d | 2020-09-10 09:40:35 +0300 | [diff] [blame] | 2693 | 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] | 2694 | void hl_fence_put(struct hl_fence *fence); |
| 2695 | void hl_fence_get(struct hl_fence *fence); |
Ofir Bitton | 5de406c | 2020-09-10 10:56:26 +0300 | [diff] [blame] | 2696 | void cs_get(struct hl_cs *cs); |
Ofir Bitton | 0811b39 | 2020-12-06 17:18:02 +0200 | [diff] [blame] | 2697 | bool cs_needs_completion(struct hl_cs *cs); |
| 2698 | bool cs_needs_timeout(struct hl_cs *cs); |
Ofir Bitton | 2795c88 | 2020-12-08 13:47:05 +0200 | [diff] [blame] | 2699 | bool is_staged_cs_last_exists(struct hl_device *hdev, struct hl_cs *cs); |
| 2700 | struct hl_cs *hl_staged_cs_find_first(struct hl_device *hdev, u64 cs_seq); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2701 | |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2702 | void goya_set_asic_funcs(struct hl_device *hdev); |
Oded Gabbay | ac0ae6a | 2020-05-11 10:29:27 +0300 | [diff] [blame] | 2703 | void gaudi_set_asic_funcs(struct hl_device *hdev); |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2704 | |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 2705 | int hl_vm_ctx_init(struct hl_ctx *ctx); |
| 2706 | void hl_vm_ctx_fini(struct hl_ctx *ctx); |
| 2707 | |
| 2708 | int hl_vm_init(struct hl_device *hdev); |
| 2709 | void hl_vm_fini(struct hl_device *hdev); |
| 2710 | |
Sagiv Ozeri | a4371c1 | 2021-02-23 11:01:08 +0200 | [diff] [blame] | 2711 | void hl_hw_block_mem_init(struct hl_ctx *ctx); |
| 2712 | void hl_hw_block_mem_fini(struct hl_ctx *ctx); |
| 2713 | |
Ofir Bitton | be91b91 | 2020-10-22 15:04:10 +0300 | [diff] [blame] | 2714 | 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] | 2715 | enum hl_va_range_type type, u32 size, u32 alignment); |
Ofir Bitton | be91b91 | 2020-10-22 15:04:10 +0300 | [diff] [blame] | 2716 | int hl_unreserve_va_block(struct hl_device *hdev, struct hl_ctx *ctx, |
| 2717 | u64 start_addr, u64 size); |
Oded Gabbay | 230afe7 | 2019-02-27 00:19:18 +0200 | [diff] [blame] | 2718 | 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] | 2719 | struct hl_userptr *userptr); |
Omer Shpigelman | 7f74d4d | 2019-08-12 11:48:46 +0300 | [diff] [blame] | 2720 | 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] | 2721 | void hl_userptr_delete_list(struct hl_device *hdev, |
| 2722 | struct list_head *userptr_list); |
| 2723 | bool hl_userptr_is_pinned(struct hl_device *hdev, u64 addr, u32 size, |
| 2724 | struct list_head *userptr_list, |
| 2725 | struct hl_userptr **userptr); |
| 2726 | |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 2727 | int hl_mmu_init(struct hl_device *hdev); |
| 2728 | void hl_mmu_fini(struct hl_device *hdev); |
Omer Shpigelman | 27ca384c | 2019-02-28 10:46:11 +0200 | [diff] [blame] | 2729 | int hl_mmu_ctx_init(struct hl_ctx *ctx); |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 2730 | void hl_mmu_ctx_fini(struct hl_ctx *ctx); |
Ofir Bitton | 5c05487 | 2020-10-22 15:13:10 +0300 | [diff] [blame] | 2731 | 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] | 2732 | u32 page_size, bool flush_pte); |
Ofir Bitton | 5c05487 | 2020-10-22 15:13:10 +0300 | [diff] [blame] | 2733 | 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] | 2734 | bool flush_pte); |
Ofir Bitton | 5c05487 | 2020-10-22 15:13:10 +0300 | [diff] [blame] | 2735 | int hl_mmu_map_contiguous(struct hl_ctx *ctx, u64 virt_addr, |
| 2736 | u64 phys_addr, u32 size); |
| 2737 | 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] | 2738 | void hl_mmu_swap_out(struct hl_ctx *ctx); |
| 2739 | void hl_mmu_swap_in(struct hl_ctx *ctx); |
Moti Haimovski | d83fe66 | 2020-08-12 13:33:44 +0300 | [diff] [blame] | 2740 | int hl_mmu_if_set_funcs(struct hl_device *hdev); |
Moti Haimovski | ccf979e | 2020-10-05 17:59:29 +0300 | [diff] [blame] | 2741 | 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] | 2742 | int hl_mmu_va_to_pa(struct hl_ctx *ctx, u64 virt_addr, u64 *phys_addr); |
| 2743 | int hl_mmu_get_tlb_info(struct hl_ctx *ctx, u64 virt_addr, |
| 2744 | struct hl_mmu_hop_info *hops); |
farah kassabri | 89473a1 | 2021-01-12 17:24:00 +0200 | [diff] [blame] | 2745 | u64 hl_mmu_scramble_addr(struct hl_device *hdev, u64 addr); |
| 2746 | u64 hl_mmu_descramble_addr(struct hl_device *hdev, u64 addr); |
Oded Gabbay | 9488307 | 2021-01-11 17:49:30 +0200 | [diff] [blame] | 2747 | bool hl_is_dram_va(struct hl_device *hdev, u64 virt_addr); |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 2748 | |
Oded Gabbay | 7e1c07d | 2020-03-26 12:32:56 +0200 | [diff] [blame] | 2749 | 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] | 2750 | void __iomem *dst, u32 src_offset, u32 size); |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 2751 | int hl_fw_send_pci_access_msg(struct hl_device *hdev, u32 opcode); |
| 2752 | 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] | 2753 | u16 len, u32 timeout, u64 *result); |
Ofir Bitton | ebd8d12 | 2020-05-10 13:41:28 +0300 | [diff] [blame] | 2754 | int hl_fw_unmask_irq(struct hl_device *hdev, u16 event_type); |
| 2755 | int hl_fw_unmask_irq_arr(struct hl_device *hdev, const u32 *irq_arr, |
| 2756 | size_t irq_arr_size); |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 2757 | int hl_fw_test_cpu_queue(struct hl_device *hdev); |
| 2758 | void *hl_fw_cpu_accessible_dma_pool_alloc(struct hl_device *hdev, size_t size, |
| 2759 | dma_addr_t *dma_handle); |
| 2760 | void hl_fw_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size, |
| 2761 | void *vaddr); |
| 2762 | int hl_fw_send_heartbeat(struct hl_device *hdev); |
Alon Mizrahi | 4147864 | 2020-11-17 14:25:14 +0200 | [diff] [blame] | 2763 | int hl_fw_cpucp_info_get(struct hl_device *hdev, |
Ohad Sharabi | e67a6040 | 2021-05-02 15:45:21 +0300 | [diff] [blame] | 2764 | u32 sts_boot_dev_sts0_reg, |
| 2765 | u32 sts_boot_dev_sts1_reg, u32 boot_err0_reg, |
| 2766 | u32 boot_err1_reg); |
Ohad Sharabi | e9c2003 | 2021-03-22 14:30:52 +0200 | [diff] [blame] | 2767 | int hl_fw_cpucp_handshake(struct hl_device *hdev, |
Ohad Sharabi | e67a6040 | 2021-05-02 15:45:21 +0300 | [diff] [blame] | 2768 | u32 sts_boot_dev_sts0_reg, |
| 2769 | u32 sts_boot_dev_sts1_reg, u32 boot_err0_reg, |
| 2770 | u32 boot_err1_reg); |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 2771 | 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] | 2772 | int hl_fw_cpucp_pci_counters_get(struct hl_device *hdev, |
Ofir Bitton | 0a068ad | 2020-07-21 10:49:51 +0300 | [diff] [blame] | 2773 | struct hl_info_pci_counters *counters); |
Oded Gabbay | 2f55342 | 2020-08-15 16:28:10 +0300 | [diff] [blame] | 2774 | int hl_fw_cpucp_total_energy_get(struct hl_device *hdev, |
farah kassabri | 9f30649 | 2020-08-09 16:25:53 +0300 | [diff] [blame] | 2775 | u64 *total_energy); |
Bharat Jauhari | 285c0fa | 2021-03-25 18:15:40 +0200 | [diff] [blame] | 2776 | 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] | 2777 | enum pll_index *pll_index); |
Bharat Jauhari | 285c0fa | 2021-03-25 18:15:40 +0200 | [diff] [blame] | 2778 | 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] | 2779 | u16 *pll_freq_arr); |
Sagiv Ozeri | 586f2ca | 2021-02-23 18:00:05 +0200 | [diff] [blame] | 2780 | int hl_fw_cpucp_power_get(struct hl_device *hdev, u64 *power); |
Koby Elbaz | b7a71fd | 2021-06-15 17:07:02 +0300 | [diff] [blame] | 2781 | void hl_fw_ask_hard_reset_without_linux(struct hl_device *hdev); |
| 2782 | void hl_fw_ask_halt_machine_without_linux(struct hl_device *hdev); |
Ohad Sharabi | a22f0ec | 2021-04-11 23:06:46 +0300 | [diff] [blame] | 2783 | int hl_fw_init_cpu(struct hl_device *hdev); |
Ofir Bitton | 323b726 | 2020-10-04 09:09:19 +0300 | [diff] [blame] | 2784 | 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] | 2785 | u32 sts_boot_dev_sts0_reg, |
| 2786 | u32 sts_boot_dev_sts1_reg, u32 boot_err0_reg, |
| 2787 | u32 boot_err1_reg, u32 timeout); |
Koby Elbaz | 4080308 | 2021-05-20 12:45:58 +0300 | [diff] [blame] | 2788 | int hl_fw_dynamic_send_protocol_cmd(struct hl_device *hdev, |
| 2789 | struct fw_load_mgr *fw_loader, |
| 2790 | enum comms_cmd cmd, unsigned int size, |
| 2791 | bool wait_ok, u32 timeout); |
Tomer Tayar | b6f897d | 2019-03-05 16:48:42 +0200 | [diff] [blame] | 2792 | int hl_pci_bars_map(struct hl_device *hdev, const char * const name[3], |
| 2793 | bool is_wc[3]); |
Ofir Bitton | 41f458f | 2021-03-10 15:08:44 +0200 | [diff] [blame] | 2794 | 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] | 2795 | 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] | 2796 | int hl_pci_set_inbound_region(struct hl_device *hdev, u8 region, |
| 2797 | struct hl_inbound_pci_region *pci_region); |
| 2798 | int hl_pci_set_outbound_region(struct hl_device *hdev, |
| 2799 | struct hl_outbound_pci_region *pci_region); |
Ohad Sharabi | c592c27 | 2021-04-21 13:03:21 +0300 | [diff] [blame] | 2800 | 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] | 2801 | int hl_pci_init(struct hl_device *hdev); |
Tomer Tayar | b6f897d | 2019-03-05 16:48:42 +0200 | [diff] [blame] | 2802 | void hl_pci_fini(struct hl_device *hdev); |
| 2803 | |
Bharat Jauhari | 285c0fa | 2021-03-25 18:15:40 +0200 | [diff] [blame] | 2804 | long hl_get_frequency(struct hl_device *hdev, u32 pll_index, |
Ohad Sharabi | e8f9392 | 2021-03-15 20:49:28 +0200 | [diff] [blame] | 2805 | bool curr); |
Bharat Jauhari | 285c0fa | 2021-03-25 18:15:40 +0200 | [diff] [blame] | 2806 | void hl_set_frequency(struct hl_device *hdev, u32 pll_index, |
Ohad Sharabi | e8f9392 | 2021-03-15 20:49:28 +0200 | [diff] [blame] | 2807 | u64 freq); |
Moti Haimovski | d57b83c | 2020-01-23 18:03:04 +0200 | [diff] [blame] | 2808 | int hl_get_temperature(struct hl_device *hdev, |
| 2809 | int sensor_index, u32 attr, long *value); |
Moti Haimovski | 5557b13 | 2020-01-21 15:02:06 +0200 | [diff] [blame] | 2810 | int hl_set_temperature(struct hl_device *hdev, |
Moti Haimovski | d57b83c | 2020-01-23 18:03:04 +0200 | [diff] [blame] | 2811 | int sensor_index, u32 attr, long value); |
| 2812 | int hl_get_voltage(struct hl_device *hdev, |
| 2813 | int sensor_index, u32 attr, long *value); |
| 2814 | int hl_get_current(struct hl_device *hdev, |
| 2815 | int sensor_index, u32 attr, long *value); |
| 2816 | int hl_get_fan_speed(struct hl_device *hdev, |
| 2817 | int sensor_index, u32 attr, long *value); |
| 2818 | int hl_get_pwm_info(struct hl_device *hdev, |
| 2819 | int sensor_index, u32 attr, long *value); |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2820 | void hl_set_pwm_info(struct hl_device *hdev, int sensor_index, u32 attr, |
| 2821 | long value); |
| 2822 | u64 hl_get_max_power(struct hl_device *hdev); |
Oded Gabbay | 58361aa | 2020-08-08 23:34:47 +0300 | [diff] [blame] | 2823 | void hl_set_max_power(struct hl_device *hdev); |
Christine Gharzuzi | 8e708af | 2020-04-16 16:43:26 +0300 | [diff] [blame] | 2824 | int hl_set_voltage(struct hl_device *hdev, |
| 2825 | int sensor_index, u32 attr, long value); |
| 2826 | int hl_set_current(struct hl_device *hdev, |
| 2827 | int sensor_index, u32 attr, long value); |
Ofir Bitton | ab5f5c3 | 2021-01-12 18:37:19 +0200 | [diff] [blame] | 2828 | void hl_release_pending_user_interrupts(struct hl_device *hdev); |
farah kassabri | 3817b35 | 2021-06-01 16:44:28 +0300 | [diff] [blame] | 2829 | int hl_cs_signal_sob_wraparound_handler(struct hl_device *hdev, u32 q_idx, |
| 2830 | struct hl_hw_sob **hw_sob, u32 count); |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 2831 | |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 2832 | int hl_state_dump(struct hl_device *hdev); |
| 2833 | 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] | 2834 | const char *hl_state_dump_get_monitor_name(struct hl_device *hdev, |
| 2835 | struct hl_mon_state_dump *mon); |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 2836 | void hl_state_dump_free_sync_to_engine_map(struct hl_sync_to_engine_map *map); |
| 2837 | __printf(4, 5) int hl_snprintf_resize(char **buf, size_t *size, size_t *offset, |
| 2838 | const char *format, ...); |
| 2839 | char *hl_format_as_binary(char *buf, size_t buf_len, u32 n); |
| 2840 | const char *hl_sync_engine_to_string(enum hl_sync_engine_type engine_type); |
| 2841 | |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 2842 | #ifdef CONFIG_DEBUG_FS |
| 2843 | |
| 2844 | void hl_debugfs_init(void); |
| 2845 | void hl_debugfs_fini(void); |
| 2846 | void hl_debugfs_add_device(struct hl_device *hdev); |
| 2847 | void hl_debugfs_remove_device(struct hl_device *hdev); |
| 2848 | void hl_debugfs_add_file(struct hl_fpriv *hpriv); |
| 2849 | void hl_debugfs_remove_file(struct hl_fpriv *hpriv); |
| 2850 | void hl_debugfs_add_cb(struct hl_cb *cb); |
| 2851 | void hl_debugfs_remove_cb(struct hl_cb *cb); |
| 2852 | void hl_debugfs_add_cs(struct hl_cs *cs); |
| 2853 | void hl_debugfs_remove_cs(struct hl_cs *cs); |
| 2854 | void hl_debugfs_add_job(struct hl_device *hdev, struct hl_cs_job *job); |
| 2855 | void hl_debugfs_remove_job(struct hl_device *hdev, struct hl_cs_job *job); |
| 2856 | void hl_debugfs_add_userptr(struct hl_device *hdev, struct hl_userptr *userptr); |
| 2857 | void hl_debugfs_remove_userptr(struct hl_device *hdev, |
| 2858 | struct hl_userptr *userptr); |
| 2859 | void hl_debugfs_add_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx); |
| 2860 | 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] | 2861 | void hl_debugfs_set_state_dump(struct hl_device *hdev, char *data, |
| 2862 | unsigned long length); |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 2863 | |
| 2864 | #else |
| 2865 | |
| 2866 | static inline void __init hl_debugfs_init(void) |
| 2867 | { |
| 2868 | } |
| 2869 | |
| 2870 | static inline void hl_debugfs_fini(void) |
| 2871 | { |
| 2872 | } |
| 2873 | |
| 2874 | static inline void hl_debugfs_add_device(struct hl_device *hdev) |
| 2875 | { |
| 2876 | } |
| 2877 | |
| 2878 | static inline void hl_debugfs_remove_device(struct hl_device *hdev) |
| 2879 | { |
| 2880 | } |
| 2881 | |
| 2882 | static inline void hl_debugfs_add_file(struct hl_fpriv *hpriv) |
| 2883 | { |
| 2884 | } |
| 2885 | |
| 2886 | static inline void hl_debugfs_remove_file(struct hl_fpriv *hpriv) |
| 2887 | { |
| 2888 | } |
| 2889 | |
| 2890 | static inline void hl_debugfs_add_cb(struct hl_cb *cb) |
| 2891 | { |
| 2892 | } |
| 2893 | |
| 2894 | static inline void hl_debugfs_remove_cb(struct hl_cb *cb) |
| 2895 | { |
| 2896 | } |
| 2897 | |
| 2898 | static inline void hl_debugfs_add_cs(struct hl_cs *cs) |
| 2899 | { |
| 2900 | } |
| 2901 | |
| 2902 | static inline void hl_debugfs_remove_cs(struct hl_cs *cs) |
| 2903 | { |
| 2904 | } |
| 2905 | |
| 2906 | static inline void hl_debugfs_add_job(struct hl_device *hdev, |
| 2907 | struct hl_cs_job *job) |
| 2908 | { |
| 2909 | } |
| 2910 | |
| 2911 | static inline void hl_debugfs_remove_job(struct hl_device *hdev, |
| 2912 | struct hl_cs_job *job) |
| 2913 | { |
| 2914 | } |
| 2915 | |
| 2916 | static inline void hl_debugfs_add_userptr(struct hl_device *hdev, |
| 2917 | struct hl_userptr *userptr) |
| 2918 | { |
| 2919 | } |
| 2920 | |
| 2921 | static inline void hl_debugfs_remove_userptr(struct hl_device *hdev, |
| 2922 | struct hl_userptr *userptr) |
| 2923 | { |
| 2924 | } |
| 2925 | |
| 2926 | static inline void hl_debugfs_add_ctx_mem_hash(struct hl_device *hdev, |
| 2927 | struct hl_ctx *ctx) |
| 2928 | { |
| 2929 | } |
| 2930 | |
| 2931 | static inline void hl_debugfs_remove_ctx_mem_hash(struct hl_device *hdev, |
| 2932 | struct hl_ctx *ctx) |
| 2933 | { |
| 2934 | } |
| 2935 | |
Yuri Nudelman | fd2010b | 2021-06-09 14:04:26 +0300 | [diff] [blame] | 2936 | static inline void hl_debugfs_set_state_dump(struct hl_device *hdev, |
| 2937 | char *data, unsigned long length) |
Yuri Nudelman | 938b793 | 2021-06-06 10:28:51 +0300 | [diff] [blame] | 2938 | { |
| 2939 | } |
| 2940 | |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 2941 | #endif |
| 2942 | |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 2943 | /* IOCTLs */ |
| 2944 | long hl_ioctl(struct file *filep, unsigned int cmd, unsigned long arg); |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 2945 | 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] | 2946 | int hl_cb_ioctl(struct hl_fpriv *hpriv, void *data); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2947 | int hl_cs_ioctl(struct hl_fpriv *hpriv, void *data); |
Ofir Bitton | ab5f5c3 | 2021-01-12 18:37:19 +0200 | [diff] [blame] | 2948 | int hl_wait_ioctl(struct hl_fpriv *hpriv, void *data); |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 2949 | int hl_mem_ioctl(struct hl_fpriv *hpriv, void *data); |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 2950 | |
Oded Gabbay | c4d6634 | 2019-02-16 00:39:11 +0200 | [diff] [blame] | 2951 | #endif /* HABANALABSP_H_ */ |