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