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