• Home
  • Raw
  • Download

Lines Matching +full:ctx +full:- +full:asid

1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright 2016-2021 HabanaLabs, Ltd.
30 return -EBUSY; in hl_debugfs_i2c_read()
33 dev_err(hdev->dev, "I2C transaction length %u, exceeds maximum of %u\n", in hl_debugfs_i2c_read()
35 return -EINVAL; in hl_debugfs_i2c_read()
47 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), in hl_debugfs_i2c_read()
50 dev_err(hdev->dev, "Failed to read from I2C, error %d\n", rc); in hl_debugfs_i2c_read()
62 return -EBUSY; in hl_debugfs_i2c_write()
65 dev_err(hdev->dev, "I2C transaction length %u, exceeds maximum of %u\n", in hl_debugfs_i2c_write()
67 return -EINVAL; in hl_debugfs_i2c_write()
80 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), in hl_debugfs_i2c_write()
84 dev_err(hdev->dev, "Failed to write to I2C, error %d\n", rc); in hl_debugfs_i2c_write()
104 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), in hl_debugfs_led_set()
108 dev_err(hdev->dev, "Failed to set LED %d, error %d\n", led, rc); in hl_debugfs_led_set()
113 struct hl_debugfs_entry *entry = s->private; in command_buffers_show()
114 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in command_buffers_show()
118 spin_lock(&dev_entry->cb_spinlock); in command_buffers_show()
120 list_for_each_entry(cb, &dev_entry->cb_list, debugfs_list) { in command_buffers_show()
124 seq_puts(s, " CB ID CTX ID CB size CB RefCnt mmap? CS counter\n"); in command_buffers_show()
125 seq_puts(s, "---------------------------------------------------------------\n"); in command_buffers_show()
129 cb->buf->handle, cb->ctx->asid, cb->size, in command_buffers_show()
130 kref_read(&cb->buf->refcount), in command_buffers_show()
131 atomic_read(&cb->buf->mmap), atomic_read(&cb->cs_cnt)); in command_buffers_show()
134 spin_unlock(&dev_entry->cb_spinlock); in command_buffers_show()
144 struct hl_debugfs_entry *entry = s->private; in command_submission_show()
145 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in command_submission_show()
149 spin_lock(&dev_entry->cs_spinlock); in command_submission_show()
151 list_for_each_entry(cs, &dev_entry->cs_list, debugfs_list) { in command_submission_show()
155 seq_puts(s, " CS ID CS TYPE CTX ASID CS RefCnt Submitted Completed\n"); in command_submission_show()
156 seq_puts(s, "----------------------------------------------------------------\n"); in command_submission_show()
160 cs->sequence, cs->type, cs->ctx->asid, in command_submission_show()
161 kref_read(&cs->refcount), in command_submission_show()
162 cs->submitted, cs->completed); in command_submission_show()
165 spin_unlock(&dev_entry->cs_spinlock); in command_submission_show()
175 struct hl_debugfs_entry *entry = s->private; in command_submission_jobs_show()
176 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in command_submission_jobs_show()
180 spin_lock(&dev_entry->cs_job_spinlock); in command_submission_jobs_show()
182 list_for_each_entry(job, &dev_entry->cs_job_list, debugfs_list) { in command_submission_jobs_show()
186 seq_puts(s, " JOB ID CS ID CS TYPE CTX ASID JOB RefCnt H/W Queue\n"); in command_submission_jobs_show()
187 seq_puts(s, "---------------------------------------------------------------\n"); in command_submission_jobs_show()
189 if (job->cs) in command_submission_jobs_show()
192 job->id, job->cs->sequence, job->cs->type, in command_submission_jobs_show()
193 job->cs->ctx->asid, kref_read(&job->refcount), in command_submission_jobs_show()
194 job->hw_queue_id); in command_submission_jobs_show()
198 job->id, HL_KERNEL_ASID_ID, in command_submission_jobs_show()
199 kref_read(&job->refcount), job->hw_queue_id); in command_submission_jobs_show()
202 spin_unlock(&dev_entry->cs_job_spinlock); in command_submission_jobs_show()
212 struct hl_debugfs_entry *entry = s->private; in userptr_show()
213 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in userptr_show()
219 spin_lock(&dev_entry->userptr_spinlock); in userptr_show()
221 list_for_each_entry(userptr, &dev_entry->userptr_list, debugfs_list) { in userptr_show()
226 seq_puts(s, "----------------------------------------------------------\n"); in userptr_show()
228 seq_printf(s, " %-7d 0x%-14llx %-10llu %-30s\n", in userptr_show()
229 userptr->pid, userptr->addr, userptr->size, in userptr_show()
230 dma_dir[userptr->dir]); in userptr_show()
233 spin_unlock(&dev_entry->userptr_spinlock); in userptr_show()
243 struct hl_debugfs_entry *entry = s->private; in vm_show()
244 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in vm_show()
246 struct hl_ctx *ctx; in vm_show() local
258 mutex_lock(&dev_entry->ctx_mem_hash_mutex); in vm_show()
260 list_for_each_entry(ctx, &dev_entry->ctx_mem_hash_list, debugfs_list) { in vm_show()
262 seq_puts(s, "\n\n----------------------------------------------------"); in vm_show()
263 seq_puts(s, "\n----------------------------------------------------\n\n"); in vm_show()
264 seq_printf(s, "ctx asid: %u\n", ctx->asid); in vm_show()
268 seq_puts(s, "----------------------------------------------------\n"); in vm_show()
269 mutex_lock(&ctx->mem_hash_lock); in vm_show()
270 hash_for_each(ctx->mem_hash, i, hnode, node) { in vm_show()
271 vm_type = hnode->ptr; in vm_show()
274 userptr = hnode->ptr; in vm_show()
276 " 0x%-14llx %-10llu\n", in vm_show()
277 hnode->vaddr, userptr->size); in vm_show()
279 phys_pg_pack = hnode->ptr; in vm_show()
281 " 0x%-14llx %-10llu %-4u\n", in vm_show()
282 hnode->vaddr, phys_pg_pack->total_size, in vm_show()
283 phys_pg_pack->handle); in vm_show()
286 mutex_unlock(&ctx->mem_hash_lock); in vm_show()
288 if (ctx->asid != HL_KERNEL_ASID_ID && in vm_show()
289 !list_empty(&ctx->hw_block_mem_list)) { in vm_show()
294 "---------------------------------------------------------------\n"); in vm_show()
295 mutex_lock(&ctx->hw_block_list_lock); in vm_show()
296 list_for_each_entry(lnode, &ctx->hw_block_mem_list, node) { in vm_show()
298 " 0x%-14lx %-6u %-6u %-9u\n", in vm_show()
299 lnode->vaddr, lnode->block_size, lnode->mapped_size, in vm_show()
300 lnode->id); in vm_show()
302 mutex_unlock(&ctx->hw_block_list_lock); in vm_show()
305 vm = &ctx->hdev->vm; in vm_show()
306 spin_lock(&vm->idr_lock); in vm_show()
308 if (!idr_is_empty(&vm->phys_pg_pack_handles)) in vm_show()
311 idr_for_each_entry(&vm->phys_pg_pack_handles, phys_pg_pack, i) { in vm_show()
312 if (phys_pg_pack->asid != ctx->asid) in vm_show()
315 seq_printf(s, "\nhandle: %u\n", phys_pg_pack->handle); in vm_show()
317 phys_pg_pack->page_size); in vm_show()
319 seq_puts(s, "---------------------\n"); in vm_show()
320 for (j = 0 ; j < phys_pg_pack->npages ; j++) { in vm_show()
321 seq_printf(s, " 0x%-14llx\n", in vm_show()
322 phys_pg_pack->pages[j]); in vm_show()
325 spin_unlock(&vm->idr_lock); in vm_show()
329 mutex_unlock(&dev_entry->ctx_mem_hash_mutex); in vm_show()
331 ctx = hl_get_compute_ctx(dev_entry->hdev); in vm_show()
332 if (ctx) { in vm_show()
335 va_range = ctx->va_range[i]; in vm_show()
337 seq_puts(s, "---------------------\n"); in vm_show()
338 mutex_lock(&va_range->lock); in vm_show()
339 list_for_each_entry(va_block, &va_range->list, node) { in vm_show()
340 seq_printf(s, "%#16llx - %#16llx (%#llx)\n", in vm_show()
341 va_block->start, va_block->end, in vm_show()
342 va_block->size); in vm_show()
344 mutex_unlock(&va_range->lock); in vm_show()
347 hl_ctx_put(ctx); in vm_show()
358 struct hl_debugfs_entry *entry = s->private; in userptr_lookup_show()
359 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in userptr_lookup_show()
367 spin_lock(&dev_entry->userptr_spinlock); in userptr_lookup_show()
369 list_for_each_entry(userptr, &dev_entry->userptr_list, debugfs_list) { in userptr_lookup_show()
370 if (dev_entry->userptr_lookup >= userptr->addr && in userptr_lookup_show()
371 dev_entry->userptr_lookup < userptr->addr + userptr->size) { in userptr_lookup_show()
373 for_each_sgtable_dma_sg(userptr->sgt, sg, i) { in userptr_lookup_show()
375 sg_start = userptr->addr + in userptr_lookup_show()
377 sg_end = userptr->addr + in userptr_lookup_show()
380 if (dev_entry->userptr_lookup >= sg_start && in userptr_lookup_show()
381 dev_entry->userptr_lookup < sg_end) { in userptr_lookup_show()
382 dma_addr += (dev_entry->userptr_lookup - in userptr_lookup_show()
388 …seq_puts(s, "-------------------------------------------------------------------------------------… in userptr_lookup_show()
390 seq_printf(s, " 0x%-18llx 0x%-16llx %-8u 0x%-16llx %-12llu\n", in userptr_lookup_show()
391 dev_entry->userptr_lookup, in userptr_lookup_show()
392 (u64)dma_addr, userptr->pid, in userptr_lookup_show()
393 userptr->addr, userptr->size); in userptr_lookup_show()
400 spin_unlock(&dev_entry->userptr_spinlock); in userptr_lookup_show()
411 struct seq_file *s = file->private_data; in userptr_lookup_write()
412 struct hl_debugfs_entry *entry = s->private; in userptr_lookup_write()
413 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in userptr_lookup_write()
421 dev_entry->userptr_lookup = value; in userptr_lookup_write()
428 struct hl_debugfs_entry *entry = s->private; in mmu_show()
429 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in mmu_show()
430 struct hl_device *hdev = dev_entry->hdev; in mmu_show()
431 struct hl_ctx *ctx; in mmu_show() local
433 u64 virt_addr = dev_entry->mmu_addr, phys_addr; in mmu_show()
436 if (dev_entry->mmu_asid == HL_KERNEL_ASID_ID) in mmu_show()
437 ctx = hdev->kernel_ctx; in mmu_show()
439 ctx = hl_get_compute_ctx(hdev); in mmu_show()
441 if (!ctx) { in mmu_show()
442 dev_err(hdev->dev, "no ctx available\n"); in mmu_show()
446 if (hl_mmu_get_tlb_info(ctx, virt_addr, &hops_info)) { in mmu_show()
447 dev_err(hdev->dev, "virt addr 0x%llx is not mapped to phys addr\n", in mmu_show()
452 hl_mmu_va_to_pa(ctx, virt_addr, &phys_addr); in mmu_show()
455 (dev_entry->mmu_addr != hops_info.scrambled_vaddr)) in mmu_show()
457 …"asid: %u, virt_addr: 0x%llx, scrambled virt_addr: 0x%llx,\nphys_addr: 0x%llx, scrambled_phys_addr… in mmu_show()
458 dev_entry->mmu_asid, dev_entry->mmu_addr, in mmu_show()
463 "asid: %u, virt_addr: 0x%llx, phys_addr: 0x%llx\n", in mmu_show()
464 dev_entry->mmu_asid, dev_entry->mmu_addr, phys_addr); in mmu_show()
476 if (dev_entry->mmu_asid != HL_KERNEL_ASID_ID) in mmu_show()
477 hl_ctx_put(ctx); in mmu_show()
485 struct seq_file *s = file->private_data; in mmu_asid_va_write()
486 struct hl_debugfs_entry *entry = s->private; in mmu_asid_va_write()
487 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in mmu_asid_va_write()
488 struct hl_device *hdev = dev_entry->hdev; in mmu_asid_va_write()
493 if (count > sizeof(kbuf) - 1) in mmu_asid_va_write()
504 rc = kstrtouint(kbuf, 10, &dev_entry->mmu_asid); in mmu_asid_va_write()
510 rc = kstrtoull(c+3, 16, &dev_entry->mmu_addr); in mmu_asid_va_write()
517 dev_err(hdev->dev, "usage: echo <asid> <0xaddr> > mmu\n"); in mmu_asid_va_write()
519 return -EINVAL; in mmu_asid_va_write()
524 struct hl_debugfs_entry *entry = s->private; in mmu_ack_error()
525 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in mmu_ack_error()
526 struct hl_device *hdev = dev_entry->hdev; in mmu_ack_error()
529 if (!dev_entry->mmu_cap_mask) { in mmu_ack_error()
530 dev_err(hdev->dev, "mmu_cap_mask is not set\n"); in mmu_ack_error()
534 rc = hdev->asic_funcs->ack_mmu_errors(hdev, dev_entry->mmu_cap_mask); in mmu_ack_error()
540 return -EINVAL; in mmu_ack_error()
547 struct seq_file *s = file->private_data; in mmu_ack_error_value_write()
548 struct hl_debugfs_entry *entry = s->private; in mmu_ack_error_value_write()
549 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in mmu_ack_error_value_write()
550 struct hl_device *hdev = dev_entry->hdev; in mmu_ack_error_value_write()
554 if (count > sizeof(kbuf) - 1) in mmu_ack_error_value_write()
565 rc = kstrtoull(kbuf, 16, &dev_entry->mmu_cap_mask); in mmu_ack_error_value_write()
571 dev_err(hdev->dev, "usage: echo <0xmmu_cap_mask > > mmu_error\n"); in mmu_ack_error_value_write()
573 return -EINVAL; in mmu_ack_error_value_write()
578 struct hl_debugfs_entry *entry = s->private; in engines_show()
579 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in engines_show()
580 struct hl_device *hdev = dev_entry->hdev; in engines_show()
583 if (hdev->reset_info.in_reset) { in engines_show()
584 dev_warn_ratelimited(hdev->dev, in engines_show()
593 return -ENOMEM; in engines_show()
595 hdev->asic_funcs->is_device_idle(hdev, NULL, 0, &eng_data); in engines_show()
598 dev_err(hdev->dev, in engines_show()
602 return -ENOMEM; in engines_show()
615 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_memory_scrub()
616 struct hl_device *hdev = entry->hdev; in hl_memory_scrub()
617 u64 val = hdev->memory_scrub_val; in hl_memory_scrub()
621 dev_warn_ratelimited(hdev->dev, "Can't scrub memory, device is not operational\n"); in hl_memory_scrub()
622 return -EIO; in hl_memory_scrub()
625 mutex_lock(&hdev->fpriv_list_lock); in hl_memory_scrub()
626 if (hdev->is_compute_ctx_active) { in hl_memory_scrub()
627 mutex_unlock(&hdev->fpriv_list_lock); in hl_memory_scrub()
628 dev_err(hdev->dev, "can't scrub dram, context exist\n"); in hl_memory_scrub()
629 return -EBUSY; in hl_memory_scrub()
631 hdev->is_in_dram_scrub = true; in hl_memory_scrub()
632 mutex_unlock(&hdev->fpriv_list_lock); in hl_memory_scrub()
634 rc = hdev->asic_funcs->scrub_device_dram(hdev, val); in hl_memory_scrub()
636 mutex_lock(&hdev->fpriv_list_lock); in hl_memory_scrub()
637 hdev->is_in_dram_scrub = false; in hl_memory_scrub()
638 mutex_unlock(&hdev->fpriv_list_lock); in hl_memory_scrub()
647 struct asic_fixed_properties *prop = &hdev->asic_prop; in hl_is_device_va()
649 if (prop->dram_supports_virtual_memory && in hl_is_device_va()
650 (addr >= prop->dmmu.start_addr && addr < prop->dmmu.end_addr)) in hl_is_device_va()
653 if (addr >= prop->pmmu.start_addr && in hl_is_device_va()
654 addr < prop->pmmu.end_addr) in hl_is_device_va()
657 if (addr >= prop->pmmu_huge.start_addr && in hl_is_device_va()
658 addr < prop->pmmu_huge.end_addr) in hl_is_device_va()
667 struct asic_fixed_properties *prop = &hdev->asic_prop; in hl_is_device_internal_memory_va()
670 if (prop->dram_supports_virtual_memory) { in hl_is_device_internal_memory_va()
671 dram_start_addr = prop->dmmu.start_addr; in hl_is_device_internal_memory_va()
672 dram_end_addr = prop->dmmu.end_addr; in hl_is_device_internal_memory_va()
674 dram_start_addr = prop->dram_base_address; in hl_is_device_internal_memory_va()
675 dram_end_addr = prop->dram_end_address; in hl_is_device_internal_memory_va()
682 if (hl_mem_area_inside_range(addr, size, prop->sram_base_address, in hl_is_device_internal_memory_va()
683 prop->sram_end_address)) in hl_is_device_internal_memory_va()
693 struct hl_ctx *ctx; in device_va_to_pa() local
701 ctx = hl_get_compute_ctx(hdev); in device_va_to_pa()
703 if (!ctx) { in device_va_to_pa()
704 dev_err(hdev->dev, "no ctx available\n"); in device_va_to_pa()
705 return -EINVAL; in device_va_to_pa()
709 mutex_lock(&ctx->mem_hash_lock); in device_va_to_pa()
710 hash_for_each(ctx->mem_hash, i, hnode, node) { in device_va_to_pa()
711 vm_type = hnode->ptr; in device_va_to_pa()
714 userptr = hnode->ptr; in device_va_to_pa()
715 range_size = userptr->size; in device_va_to_pa()
717 phys_pg_pack = hnode->ptr; in device_va_to_pa()
718 range_size = phys_pg_pack->total_size; in device_va_to_pa()
722 if ((virt_addr >= hnode->vaddr) && in device_va_to_pa()
723 (end_address <= hnode->vaddr + range_size)) { in device_va_to_pa()
728 mutex_unlock(&ctx->mem_hash_lock); in device_va_to_pa()
731 dev_err(hdev->dev, in device_va_to_pa()
734 rc = -EINVAL; in device_va_to_pa()
738 rc = hl_mmu_va_to_pa(ctx, virt_addr, phys_addr); in device_va_to_pa()
740 dev_err(hdev->dev, in device_va_to_pa()
743 rc = -EINVAL; in device_va_to_pa()
747 hl_ctx_put(ctx); in device_va_to_pa()
761 mem_reg = &hdev->pci_mem_region[i]; in hl_access_dev_mem_by_region()
762 if (!mem_reg->used) in hl_access_dev_mem_by_region()
764 if (addr >= mem_reg->region_base && in hl_access_dev_mem_by_region()
765 addr <= mem_reg->region_base + mem_reg->region_size - acc_size) { in hl_access_dev_mem_by_region()
767 return hdev->asic_funcs->access_dev_mem(hdev, i, addr, val, acc_type); in hl_access_dev_mem_by_region()
776 struct asic_fixed_properties *prop = &hdev->asic_prop; in hl_access_host_mem()
777 u64 offset = prop->device_dma_offset_for_host_access; in hl_access_host_mem()
781 *val = *(u32 *) phys_to_virt(addr - offset); in hl_access_host_mem()
784 *(u32 *) phys_to_virt(addr - offset) = *val; in hl_access_host_mem()
787 *val = *(u64 *) phys_to_virt(addr - offset); in hl_access_host_mem()
790 *(u64 *) phys_to_virt(addr - offset) = *val; in hl_access_host_mem()
793 dev_err(hdev->dev, "hostmem access-type %d id not supported\n", acc_type); in hl_access_host_mem()
803 u64 host_start = hdev->asic_prop.host_base_address; in hl_access_mem()
804 u64 host_end = hdev->asic_prop.host_end_address; in hl_access_mem()
817 dev_err(hdev->dev, in hl_access_mem()
826 if (!user_address || device_iommu_mapped(&hdev->pdev->dev)) { in hl_access_mem()
827 rc = -EINVAL; in hl_access_mem()
831 if (addr >= host_start && addr <= host_end - acc_size) { in hl_access_mem()
834 rc = -EINVAL; in hl_access_mem()
840 dev_err(hdev->dev, "invalid addr %#llx\n", addr); in hl_access_mem()
847 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_data_read32()
848 struct hl_device *hdev = entry->hdev; in hl_data_read32()
849 u64 value64, addr = entry->addr; in hl_data_read32()
854 if (hdev->reset_info.in_reset) { in hl_data_read32()
855 dev_warn_ratelimited(hdev->dev, "Can't read during reset\n"); in hl_data_read32()
876 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_data_write32()
877 struct hl_device *hdev = entry->hdev; in hl_data_write32()
878 u64 value64, addr = entry->addr; in hl_data_write32()
882 if (hdev->reset_info.in_reset) { in hl_data_write32()
883 dev_warn_ratelimited(hdev->dev, "Can't write during reset\n"); in hl_data_write32()
902 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_data_read64()
903 struct hl_device *hdev = entry->hdev; in hl_data_read64()
904 u64 addr = entry->addr; in hl_data_read64()
909 if (hdev->reset_info.in_reset) { in hl_data_read64()
910 dev_warn_ratelimited(hdev->dev, "Can't read during reset\n"); in hl_data_read64()
929 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_data_write64()
930 struct hl_device *hdev = entry->hdev; in hl_data_write64()
931 u64 addr = entry->addr; in hl_data_write64()
935 if (hdev->reset_info.in_reset) { in hl_data_write64()
936 dev_warn_ratelimited(hdev->dev, "Can't write during reset\n"); in hl_data_write64()
954 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_dma_size_write()
955 struct hl_device *hdev = entry->hdev; in hl_dma_size_write()
956 u64 addr = entry->addr; in hl_dma_size_write()
960 if (hdev->reset_info.in_reset) { in hl_dma_size_write()
961 dev_warn_ratelimited(hdev->dev, "Can't DMA during reset\n"); in hl_dma_size_write()
969 dev_err(hdev->dev, "DMA read failed. size can't be 0\n"); in hl_dma_size_write()
970 return -EINVAL; in hl_dma_size_write()
974 dev_err(hdev->dev, in hl_dma_size_write()
976 return -EINVAL; in hl_dma_size_write()
980 dev_err(hdev->dev, in hl_dma_size_write()
983 return -EINVAL; in hl_dma_size_write()
987 entry->data_dma_blob_desc.size = 0; in hl_dma_size_write()
988 vfree(entry->data_dma_blob_desc.data); in hl_dma_size_write()
990 entry->data_dma_blob_desc.data = vmalloc(size); in hl_dma_size_write()
991 if (!entry->data_dma_blob_desc.data) in hl_dma_size_write()
992 return -ENOMEM; in hl_dma_size_write()
994 rc = hdev->asic_funcs->debugfs_read_dma(hdev, addr, size, in hl_dma_size_write()
995 entry->data_dma_blob_desc.data); in hl_dma_size_write()
997 dev_err(hdev->dev, "Failed to DMA from 0x%010llx\n", addr); in hl_dma_size_write()
998 vfree(entry->data_dma_blob_desc.data); in hl_dma_size_write()
999 entry->data_dma_blob_desc.data = NULL; in hl_dma_size_write()
1000 return -EIO; in hl_dma_size_write()
1003 entry->data_dma_blob_desc.size = size; in hl_dma_size_write()
1011 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_monitor_dump_trigger()
1012 struct hl_device *hdev = entry->hdev; in hl_monitor_dump_trigger()
1016 if (hdev->reset_info.in_reset) { in hl_monitor_dump_trigger()
1017 dev_warn_ratelimited(hdev->dev, "Can't dump monitors during reset\n"); in hl_monitor_dump_trigger()
1025 dev_err(hdev->dev, "Must write 1 to trigger monitor dump\n"); in hl_monitor_dump_trigger()
1026 return -EINVAL; in hl_monitor_dump_trigger()
1032 entry->mon_dump_blob_desc.size = 0; in hl_monitor_dump_trigger()
1033 vfree(entry->mon_dump_blob_desc.data); in hl_monitor_dump_trigger()
1035 entry->mon_dump_blob_desc.data = vmalloc(size); in hl_monitor_dump_trigger()
1036 if (!entry->mon_dump_blob_desc.data) in hl_monitor_dump_trigger()
1037 return -ENOMEM; in hl_monitor_dump_trigger()
1039 rc = hdev->asic_funcs->get_monitor_dump(hdev, entry->mon_dump_blob_desc.data); in hl_monitor_dump_trigger()
1041 dev_err(hdev->dev, "Failed to dump monitors\n"); in hl_monitor_dump_trigger()
1042 vfree(entry->mon_dump_blob_desc.data); in hl_monitor_dump_trigger()
1043 entry->mon_dump_blob_desc.data = NULL; in hl_monitor_dump_trigger()
1044 return -EIO; in hl_monitor_dump_trigger()
1047 entry->mon_dump_blob_desc.size = size; in hl_monitor_dump_trigger()
1055 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_get_power_state()
1056 struct hl_device *hdev = entry->hdev; in hl_get_power_state()
1063 if (hdev->pdev->current_state == PCI_D0) in hl_get_power_state()
1065 else if (hdev->pdev->current_state == PCI_D3hot) in hl_get_power_state()
1071 "current power state: %d\n1 - D0\n2 - D3hot\n3 - Unknown\n", i); in hl_get_power_state()
1079 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_set_power_state()
1080 struct hl_device *hdev = entry->hdev; in hl_set_power_state()
1089 pci_set_power_state(hdev->pdev, PCI_D0); in hl_set_power_state()
1090 pci_restore_state(hdev->pdev); in hl_set_power_state()
1091 rc = pci_enable_device(hdev->pdev); in hl_set_power_state()
1095 pci_save_state(hdev->pdev); in hl_set_power_state()
1096 pci_disable_device(hdev->pdev); in hl_set_power_state()
1097 pci_set_power_state(hdev->pdev, PCI_D3hot); in hl_set_power_state()
1099 dev_dbg(hdev->dev, "invalid power state value %u\n", value); in hl_set_power_state()
1100 return -EINVAL; in hl_set_power_state()
1109 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_i2c_data_read()
1110 struct hl_device *hdev = entry->hdev; in hl_i2c_data_read()
1118 rc = hl_debugfs_i2c_read(hdev, entry->i2c_bus, entry->i2c_addr, in hl_i2c_data_read()
1119 entry->i2c_reg, entry->i2c_len, &val); in hl_i2c_data_read()
1121 dev_err(hdev->dev, in hl_i2c_data_read()
1123 entry->i2c_bus, entry->i2c_addr, entry->i2c_reg, entry->i2c_len); in hl_i2c_data_read()
1137 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_i2c_data_write()
1138 struct hl_device *hdev = entry->hdev; in hl_i2c_data_write()
1146 rc = hl_debugfs_i2c_write(hdev, entry->i2c_bus, entry->i2c_addr, in hl_i2c_data_write()
1147 entry->i2c_reg, entry->i2c_len, value); in hl_i2c_data_write()
1149 dev_err(hdev->dev, in hl_i2c_data_write()
1151 value, entry->i2c_bus, entry->i2c_addr, entry->i2c_reg, entry->i2c_len); in hl_i2c_data_write()
1161 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_led0_write()
1162 struct hl_device *hdev = entry->hdev; in hl_led0_write()
1180 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_led1_write()
1181 struct hl_device *hdev = entry->hdev; in hl_led1_write()
1199 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_led2_write()
1200 struct hl_device *hdev = entry->hdev; in hl_led2_write()
1226 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_device_write()
1227 struct hl_device *hdev = entry->hdev; in hl_device_write()
1237 hdev->disabled = true; in hl_device_write()
1239 hdev->disabled = false; in hl_device_write()
1241 hdev->asic_funcs->suspend(hdev); in hl_device_write()
1243 hdev->asic_funcs->resume(hdev); in hl_device_write()
1245 hdev->device_cpu_disabled = true; in hl_device_write()
1247 dev_err(hdev->dev, in hl_device_write()
1249 count = -EINVAL; in hl_device_write()
1270 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_stop_on_err_read()
1271 struct hl_device *hdev = entry->hdev; in hl_stop_on_err_read()
1275 if (!hdev->asic_prop.configurable_stop_on_err) in hl_stop_on_err_read()
1276 return -EOPNOTSUPP; in hl_stop_on_err_read()
1281 sprintf(tmp_buf, "%d\n", hdev->stop_on_err); in hl_stop_on_err_read()
1291 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_stop_on_err_write()
1292 struct hl_device *hdev = entry->hdev; in hl_stop_on_err_write()
1296 if (!hdev->asic_prop.configurable_stop_on_err) in hl_stop_on_err_write()
1297 return -EOPNOTSUPP; in hl_stop_on_err_write()
1299 if (hdev->reset_info.in_reset) { in hl_stop_on_err_write()
1300 dev_warn_ratelimited(hdev->dev, in hl_stop_on_err_write()
1309 hdev->stop_on_err = value ? 1 : 0; in hl_stop_on_err_write()
1319 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_security_violations_read()
1320 struct hl_device *hdev = entry->hdev; in hl_security_violations_read()
1322 hdev->asic_funcs->ack_protection_bits_errors(hdev); in hl_security_violations_read()
1330 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_state_dump_read()
1333 down_read(&entry->state_dump_sem); in hl_state_dump_read()
1334 if (!entry->state_dump[entry->state_dump_head]) in hl_state_dump_read()
1339 entry->state_dump[entry->state_dump_head], in hl_state_dump_read()
1340 strlen(entry->state_dump[entry->state_dump_head])); in hl_state_dump_read()
1341 up_read(&entry->state_dump_sem); in hl_state_dump_read()
1349 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_state_dump_write()
1350 struct hl_device *hdev = entry->hdev; in hl_state_dump_write()
1359 if (size <= 0 || size >= ARRAY_SIZE(entry->state_dump)) { in hl_state_dump_write()
1360 dev_err(hdev->dev, "Invalid number of dumps to skip\n"); in hl_state_dump_write()
1361 return -EINVAL; in hl_state_dump_write()
1364 if (entry->state_dump[entry->state_dump_head]) { in hl_state_dump_write()
1365 down_write(&entry->state_dump_sem); in hl_state_dump_write()
1367 vfree(entry->state_dump[entry->state_dump_head]); in hl_state_dump_write()
1368 entry->state_dump[entry->state_dump_head] = NULL; in hl_state_dump_write()
1369 if (entry->state_dump_head > 0) in hl_state_dump_write()
1370 entry->state_dump_head--; in hl_state_dump_write()
1372 entry->state_dump_head = in hl_state_dump_write()
1373 ARRAY_SIZE(entry->state_dump) - 1; in hl_state_dump_write()
1375 up_write(&entry->state_dump_sem); in hl_state_dump_write()
1384 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_timeout_locked_read()
1385 struct hl_device *hdev = entry->hdev; in hl_timeout_locked_read()
1393 jiffies_to_msecs(hdev->timeout_jiffies) / 1000); in hl_timeout_locked_read()
1403 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_timeout_locked_write()
1404 struct hl_device *hdev = entry->hdev; in hl_timeout_locked_write()
1413 hdev->timeout_jiffies = msecs_to_jiffies(value * 1000); in hl_timeout_locked_write()
1415 hdev->timeout_jiffies = MAX_SCHEDULE_TIMEOUT; in hl_timeout_locked_write()
1423 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_check_razwi_happened()
1424 struct hl_device *hdev = entry->hdev; in hl_check_razwi_happened()
1426 hdev->asic_funcs->check_if_razwi_happened(hdev); in hl_check_razwi_happened()
1539 struct hl_debugfs_entry *node = inode->i_private; in hl_debugfs_open()
1541 return single_open(file, node->info_ent->show, node); in hl_debugfs_open()
1547 struct hl_debugfs_entry *node = file->f_inode->i_private; in hl_debugfs_write()
1549 if (node->info_ent->write) in hl_debugfs_write()
1550 return node->info_ent->write(file, buf, count, f_pos); in hl_debugfs_write()
1552 return -EINVAL; in hl_debugfs_write()
1570 &dev_entry->i2c_bus); in add_secured_nodes()
1575 &dev_entry->i2c_addr); in add_secured_nodes()
1580 &dev_entry->i2c_reg); in add_secured_nodes()
1585 &dev_entry->i2c_len); in add_secured_nodes()
1622 &hdev->memory_scrub_val); in add_files_to_device()
1633 &dev_entry->addr); in add_files_to_device()
1692 &dev_entry->data_dma_blob_desc); in add_files_to_device()
1703 &dev_entry->mon_dump_blob_desc); in add_files_to_device()
1708 &hdev->reset_info.skip_reset_on_timeout); in add_files_to_device()
1725 &hdev->device_release_watchdog_timeout_sec); in add_files_to_device()
1727 for (i = 0, entry = dev_entry->entry_arr ; i < count ; i++, entry++) { in add_files_to_device()
1733 entry->info_ent = &hl_debugfs_list[i]; in add_files_to_device()
1734 entry->dev_entry = dev_entry; in add_files_to_device()
1740 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_device_init()
1743 dev_entry->hdev = hdev; in hl_debugfs_device_init()
1744 dev_entry->entry_arr = kmalloc_array(count, sizeof(struct hl_debugfs_entry), GFP_KERNEL); in hl_debugfs_device_init()
1745 if (!dev_entry->entry_arr) in hl_debugfs_device_init()
1746 return -ENOMEM; in hl_debugfs_device_init()
1748 dev_entry->data_dma_blob_desc.size = 0; in hl_debugfs_device_init()
1749 dev_entry->data_dma_blob_desc.data = NULL; in hl_debugfs_device_init()
1750 dev_entry->mon_dump_blob_desc.size = 0; in hl_debugfs_device_init()
1751 dev_entry->mon_dump_blob_desc.data = NULL; in hl_debugfs_device_init()
1753 INIT_LIST_HEAD(&dev_entry->file_list); in hl_debugfs_device_init()
1754 INIT_LIST_HEAD(&dev_entry->cb_list); in hl_debugfs_device_init()
1755 INIT_LIST_HEAD(&dev_entry->cs_list); in hl_debugfs_device_init()
1756 INIT_LIST_HEAD(&dev_entry->cs_job_list); in hl_debugfs_device_init()
1757 INIT_LIST_HEAD(&dev_entry->userptr_list); in hl_debugfs_device_init()
1758 INIT_LIST_HEAD(&dev_entry->ctx_mem_hash_list); in hl_debugfs_device_init()
1759 mutex_init(&dev_entry->file_mutex); in hl_debugfs_device_init()
1760 init_rwsem(&dev_entry->state_dump_sem); in hl_debugfs_device_init()
1761 spin_lock_init(&dev_entry->cb_spinlock); in hl_debugfs_device_init()
1762 spin_lock_init(&dev_entry->cs_spinlock); in hl_debugfs_device_init()
1763 spin_lock_init(&dev_entry->cs_job_spinlock); in hl_debugfs_device_init()
1764 spin_lock_init(&dev_entry->userptr_spinlock); in hl_debugfs_device_init()
1765 mutex_init(&dev_entry->ctx_mem_hash_mutex); in hl_debugfs_device_init()
1772 struct hl_dbg_device_entry *entry = &hdev->hl_debugfs; in hl_debugfs_device_fini()
1775 mutex_destroy(&entry->ctx_mem_hash_mutex); in hl_debugfs_device_fini()
1776 mutex_destroy(&entry->file_mutex); in hl_debugfs_device_fini()
1778 vfree(entry->data_dma_blob_desc.data); in hl_debugfs_device_fini()
1779 vfree(entry->mon_dump_blob_desc.data); in hl_debugfs_device_fini()
1781 for (i = 0; i < ARRAY_SIZE(entry->state_dump); ++i) in hl_debugfs_device_fini()
1782 vfree(entry->state_dump[i]); in hl_debugfs_device_fini()
1784 kfree(entry->entry_arr); in hl_debugfs_device_fini()
1789 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_add_device()
1791 dev_entry->root = debugfs_create_dir(dev_name(hdev->dev), hl_debug_root); in hl_debugfs_add_device()
1793 add_files_to_device(hdev, dev_entry, dev_entry->root); in hl_debugfs_add_device()
1794 if (!hdev->asic_prop.fw_security_enabled) in hl_debugfs_add_device()
1795 add_secured_nodes(dev_entry, dev_entry->root); in hl_debugfs_add_device()
1800 struct hl_dbg_device_entry *entry = &hdev->hl_debugfs; in hl_debugfs_remove_device()
1802 debugfs_remove_recursive(entry->root); in hl_debugfs_remove_device()
1807 struct hl_dbg_device_entry *dev_entry = &hpriv->hdev->hl_debugfs; in hl_debugfs_add_file()
1809 mutex_lock(&dev_entry->file_mutex); in hl_debugfs_add_file()
1810 list_add(&hpriv->debugfs_list, &dev_entry->file_list); in hl_debugfs_add_file()
1811 mutex_unlock(&dev_entry->file_mutex); in hl_debugfs_add_file()
1816 struct hl_dbg_device_entry *dev_entry = &hpriv->hdev->hl_debugfs; in hl_debugfs_remove_file()
1818 mutex_lock(&dev_entry->file_mutex); in hl_debugfs_remove_file()
1819 list_del(&hpriv->debugfs_list); in hl_debugfs_remove_file()
1820 mutex_unlock(&dev_entry->file_mutex); in hl_debugfs_remove_file()
1825 struct hl_dbg_device_entry *dev_entry = &cb->hdev->hl_debugfs; in hl_debugfs_add_cb()
1827 spin_lock(&dev_entry->cb_spinlock); in hl_debugfs_add_cb()
1828 list_add(&cb->debugfs_list, &dev_entry->cb_list); in hl_debugfs_add_cb()
1829 spin_unlock(&dev_entry->cb_spinlock); in hl_debugfs_add_cb()
1834 struct hl_dbg_device_entry *dev_entry = &cb->hdev->hl_debugfs; in hl_debugfs_remove_cb()
1836 spin_lock(&dev_entry->cb_spinlock); in hl_debugfs_remove_cb()
1837 list_del(&cb->debugfs_list); in hl_debugfs_remove_cb()
1838 spin_unlock(&dev_entry->cb_spinlock); in hl_debugfs_remove_cb()
1843 struct hl_dbg_device_entry *dev_entry = &cs->ctx->hdev->hl_debugfs; in hl_debugfs_add_cs()
1845 spin_lock(&dev_entry->cs_spinlock); in hl_debugfs_add_cs()
1846 list_add(&cs->debugfs_list, &dev_entry->cs_list); in hl_debugfs_add_cs()
1847 spin_unlock(&dev_entry->cs_spinlock); in hl_debugfs_add_cs()
1852 struct hl_dbg_device_entry *dev_entry = &cs->ctx->hdev->hl_debugfs; in hl_debugfs_remove_cs()
1854 spin_lock(&dev_entry->cs_spinlock); in hl_debugfs_remove_cs()
1855 list_del(&cs->debugfs_list); in hl_debugfs_remove_cs()
1856 spin_unlock(&dev_entry->cs_spinlock); in hl_debugfs_remove_cs()
1861 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_add_job()
1863 spin_lock(&dev_entry->cs_job_spinlock); in hl_debugfs_add_job()
1864 list_add(&job->debugfs_list, &dev_entry->cs_job_list); in hl_debugfs_add_job()
1865 spin_unlock(&dev_entry->cs_job_spinlock); in hl_debugfs_add_job()
1870 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_remove_job()
1872 spin_lock(&dev_entry->cs_job_spinlock); in hl_debugfs_remove_job()
1873 list_del(&job->debugfs_list); in hl_debugfs_remove_job()
1874 spin_unlock(&dev_entry->cs_job_spinlock); in hl_debugfs_remove_job()
1879 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_add_userptr()
1881 spin_lock(&dev_entry->userptr_spinlock); in hl_debugfs_add_userptr()
1882 list_add(&userptr->debugfs_list, &dev_entry->userptr_list); in hl_debugfs_add_userptr()
1883 spin_unlock(&dev_entry->userptr_spinlock); in hl_debugfs_add_userptr()
1889 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_remove_userptr()
1891 spin_lock(&dev_entry->userptr_spinlock); in hl_debugfs_remove_userptr()
1892 list_del(&userptr->debugfs_list); in hl_debugfs_remove_userptr()
1893 spin_unlock(&dev_entry->userptr_spinlock); in hl_debugfs_remove_userptr()
1896 void hl_debugfs_add_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx) in hl_debugfs_add_ctx_mem_hash() argument
1898 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_add_ctx_mem_hash()
1900 mutex_lock(&dev_entry->ctx_mem_hash_mutex); in hl_debugfs_add_ctx_mem_hash()
1901 list_add(&ctx->debugfs_list, &dev_entry->ctx_mem_hash_list); in hl_debugfs_add_ctx_mem_hash()
1902 mutex_unlock(&dev_entry->ctx_mem_hash_mutex); in hl_debugfs_add_ctx_mem_hash()
1905 void hl_debugfs_remove_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx) in hl_debugfs_remove_ctx_mem_hash() argument
1907 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_remove_ctx_mem_hash()
1909 mutex_lock(&dev_entry->ctx_mem_hash_mutex); in hl_debugfs_remove_ctx_mem_hash()
1910 list_del(&ctx->debugfs_list); in hl_debugfs_remove_ctx_mem_hash()
1911 mutex_unlock(&dev_entry->ctx_mem_hash_mutex); in hl_debugfs_remove_ctx_mem_hash()
1915 * hl_debugfs_set_state_dump - register state dump making it accessible via
1924 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_set_state_dump()
1926 down_write(&dev_entry->state_dump_sem); in hl_debugfs_set_state_dump()
1928 dev_entry->state_dump_head = (dev_entry->state_dump_head + 1) % in hl_debugfs_set_state_dump()
1929 ARRAY_SIZE(dev_entry->state_dump); in hl_debugfs_set_state_dump()
1930 vfree(dev_entry->state_dump[dev_entry->state_dump_head]); in hl_debugfs_set_state_dump()
1931 dev_entry->state_dump[dev_entry->state_dump_head] = data; in hl_debugfs_set_state_dump()
1933 up_write(&dev_entry->state_dump_sem); in hl_debugfs_set_state_dump()