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