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

1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright 2016-2021 HabanaLabs, Ltd.
28 return -EBUSY; in hl_debugfs_i2c_read()
31 dev_err(hdev->dev, "I2C transaction length %u, exceeds maximum of %u\n", in hl_debugfs_i2c_read()
33 return -EINVAL; in hl_debugfs_i2c_read()
45 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), 0, val); in hl_debugfs_i2c_read()
46 if (rc && rc != -EAGAIN) in hl_debugfs_i2c_read()
47 dev_err(hdev->dev, "Failed to read from I2C, error %d\n", rc); in hl_debugfs_i2c_read()
59 return -EBUSY; in hl_debugfs_i2c_write()
62 dev_err(hdev->dev, "I2C transaction length %u, exceeds maximum of %u\n", in hl_debugfs_i2c_write()
64 return -EINVAL; in hl_debugfs_i2c_write()
77 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), 0, NULL); in hl_debugfs_i2c_write()
78 if (rc && rc != -EAGAIN) in hl_debugfs_i2c_write()
79 dev_err(hdev->dev, "Failed to write to I2C, error %d\n", rc); in hl_debugfs_i2c_write()
99 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), 0, NULL); in hl_debugfs_led_set()
100 if (rc && rc != -EAGAIN) in hl_debugfs_led_set()
101 dev_err(hdev->dev, "Failed to set LED %d, error %d\n", led, rc); in hl_debugfs_led_set()
106 struct hl_debugfs_entry *entry = s->private; in command_buffers_show()
107 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in command_buffers_show()
111 spin_lock(&dev_entry->cb_spinlock); in command_buffers_show()
113 list_for_each_entry(cb, &dev_entry->cb_list, debugfs_list) { in command_buffers_show()
117 seq_puts(s, " CB ID CTX ID CB size CB RefCnt mmap? CS counter\n"); in command_buffers_show()
118 seq_puts(s, "---------------------------------------------------------------\n"); in command_buffers_show()
122 cb->buf->handle, cb->ctx->asid, cb->size, in command_buffers_show()
123 kref_read(&cb->buf->refcount), in command_buffers_show()
124 atomic_read(&cb->buf->mmap), atomic_read(&cb->cs_cnt)); in command_buffers_show()
127 spin_unlock(&dev_entry->cb_spinlock); in command_buffers_show()
137 struct hl_debugfs_entry *entry = s->private; in command_submission_show()
138 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in command_submission_show()
142 spin_lock(&dev_entry->cs_spinlock); in command_submission_show()
144 list_for_each_entry(cs, &dev_entry->cs_list, debugfs_list) { in command_submission_show()
148 seq_puts(s, " CS ID CS TYPE CTX ASID CS RefCnt Submitted Completed\n"); in command_submission_show()
149 seq_puts(s, "----------------------------------------------------------------\n"); in command_submission_show()
153 cs->sequence, cs->type, cs->ctx->asid, in command_submission_show()
154 kref_read(&cs->refcount), in command_submission_show()
155 cs->submitted, cs->completed); in command_submission_show()
158 spin_unlock(&dev_entry->cs_spinlock); in command_submission_show()
168 struct hl_debugfs_entry *entry = s->private; in command_submission_jobs_show()
169 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in command_submission_jobs_show()
173 spin_lock(&dev_entry->cs_job_spinlock); in command_submission_jobs_show()
175 list_for_each_entry(job, &dev_entry->cs_job_list, debugfs_list) { in command_submission_jobs_show()
179 seq_puts(s, " JOB ID CS ID CS TYPE CTX ASID JOB RefCnt H/W Queue\n"); in command_submission_jobs_show()
180 seq_puts(s, "---------------------------------------------------------------\n"); in command_submission_jobs_show()
182 if (job->cs) in command_submission_jobs_show()
185 job->id, job->cs->sequence, job->cs->type, in command_submission_jobs_show()
186 job->cs->ctx->asid, kref_read(&job->refcount), in command_submission_jobs_show()
187 job->hw_queue_id); in command_submission_jobs_show()
191 job->id, HL_KERNEL_ASID_ID, in command_submission_jobs_show()
192 kref_read(&job->refcount), job->hw_queue_id); in command_submission_jobs_show()
195 spin_unlock(&dev_entry->cs_job_spinlock); in command_submission_jobs_show()
205 struct hl_debugfs_entry *entry = s->private; in userptr_show()
206 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in userptr_show()
212 spin_lock(&dev_entry->userptr_spinlock); in userptr_show()
214 list_for_each_entry(userptr, &dev_entry->userptr_list, debugfs_list) { in userptr_show()
219 seq_puts(s, "----------------------------------------------------------\n"); in userptr_show()
221 seq_printf(s, " %-7d 0x%-14llx %-10llu %-30s\n", in userptr_show()
222 userptr->pid, userptr->addr, userptr->size, in userptr_show()
223 dma_dir[userptr->dir]); in userptr_show()
226 spin_unlock(&dev_entry->userptr_spinlock); in userptr_show()
236 struct hl_debugfs_entry *entry = s->private; in vm_show()
237 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in vm_show()
239 struct hl_ctx *ctx; in vm_show() local
251 mutex_lock(&dev_entry->ctx_mem_hash_mutex); in vm_show()
253 list_for_each_entry(ctx, &dev_entry->ctx_mem_hash_list, debugfs_list) { in vm_show()
255 seq_puts(s, "\n\n----------------------------------------------------"); in vm_show()
256 seq_puts(s, "\n----------------------------------------------------\n\n"); in vm_show()
257 seq_printf(s, "ctx asid: %u\n", ctx->asid); in vm_show()
261 seq_puts(s, "----------------------------------------------------\n"); in vm_show()
262 mutex_lock(&ctx->mem_hash_lock); in vm_show()
263 hash_for_each(ctx->mem_hash, i, hnode, node) { in vm_show()
264 vm_type = hnode->ptr; in vm_show()
267 userptr = hnode->ptr; in vm_show()
269 " 0x%-14llx %-10llu\n", in vm_show()
270 hnode->vaddr, userptr->size); in vm_show()
272 phys_pg_pack = hnode->ptr; in vm_show()
274 " 0x%-14llx %-10llu %-4u\n", in vm_show()
275 hnode->vaddr, phys_pg_pack->total_size, in vm_show()
276 phys_pg_pack->handle); in vm_show()
279 mutex_unlock(&ctx->mem_hash_lock); in vm_show()
281 if (ctx->asid != HL_KERNEL_ASID_ID && in vm_show()
282 !list_empty(&ctx->hw_block_mem_list)) { in vm_show()
287 "---------------------------------------------------------------\n"); in vm_show()
288 mutex_lock(&ctx->hw_block_list_lock); in vm_show()
289 list_for_each_entry(lnode, &ctx->hw_block_mem_list, node) { in vm_show()
291 " 0x%-14lx %-6u %-6u %-9u\n", in vm_show()
292 lnode->vaddr, lnode->block_size, lnode->mapped_size, in vm_show()
293 lnode->id); in vm_show()
295 mutex_unlock(&ctx->hw_block_list_lock); in vm_show()
298 vm = &ctx->hdev->vm; in vm_show()
299 spin_lock(&vm->idr_lock); in vm_show()
301 if (!idr_is_empty(&vm->phys_pg_pack_handles)) in vm_show()
304 idr_for_each_entry(&vm->phys_pg_pack_handles, phys_pg_pack, i) { in vm_show()
305 if (phys_pg_pack->asid != ctx->asid) in vm_show()
308 seq_printf(s, "\nhandle: %u\n", phys_pg_pack->handle); in vm_show()
310 phys_pg_pack->page_size); in vm_show()
312 seq_puts(s, "---------------------\n"); in vm_show()
313 for (j = 0 ; j < phys_pg_pack->npages ; j++) { in vm_show()
314 seq_printf(s, " 0x%-14llx\n", in vm_show()
315 phys_pg_pack->pages[j]); in vm_show()
318 spin_unlock(&vm->idr_lock); in vm_show()
322 mutex_unlock(&dev_entry->ctx_mem_hash_mutex); in vm_show()
324 ctx = hl_get_compute_ctx(dev_entry->hdev); in vm_show()
325 if (ctx) { in vm_show()
328 va_range = ctx->va_range[i]; in vm_show()
330 seq_puts(s, "---------------------\n"); in vm_show()
331 mutex_lock(&va_range->lock); in vm_show()
332 list_for_each_entry(va_block, &va_range->list, node) { in vm_show()
333 seq_printf(s, "%#16llx - %#16llx (%#llx)\n", in vm_show()
334 va_block->start, va_block->end, in vm_show()
335 va_block->size); in vm_show()
337 mutex_unlock(&va_range->lock); in vm_show()
340 hl_ctx_put(ctx); in vm_show()
351 struct hl_debugfs_entry *entry = s->private; in userptr_lookup_show()
352 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in userptr_lookup_show()
360 spin_lock(&dev_entry->userptr_spinlock); in userptr_lookup_show()
362 list_for_each_entry(userptr, &dev_entry->userptr_list, debugfs_list) { in userptr_lookup_show()
363 if (dev_entry->userptr_lookup >= userptr->addr && in userptr_lookup_show()
364 dev_entry->userptr_lookup < userptr->addr + userptr->size) { in userptr_lookup_show()
366 for_each_sgtable_dma_sg(userptr->sgt, sg, i) { in userptr_lookup_show()
368 sg_start = userptr->addr + in userptr_lookup_show()
370 sg_end = userptr->addr + in userptr_lookup_show()
373 if (dev_entry->userptr_lookup >= sg_start && in userptr_lookup_show()
374 dev_entry->userptr_lookup < sg_end) { in userptr_lookup_show()
375 dma_addr += (dev_entry->userptr_lookup - in userptr_lookup_show()
381 …seq_puts(s, "-------------------------------------------------------------------------------------… in userptr_lookup_show()
383 seq_printf(s, " 0x%-18llx 0x%-16llx %-8u 0x%-16llx %-12llu\n", in userptr_lookup_show()
384 dev_entry->userptr_lookup, in userptr_lookup_show()
385 (u64)dma_addr, userptr->pid, in userptr_lookup_show()
386 userptr->addr, userptr->size); in userptr_lookup_show()
393 spin_unlock(&dev_entry->userptr_spinlock); in userptr_lookup_show()
404 struct seq_file *s = file->private_data; in userptr_lookup_write()
405 struct hl_debugfs_entry *entry = s->private; in userptr_lookup_write()
406 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in userptr_lookup_write()
414 dev_entry->userptr_lookup = value; in userptr_lookup_write()
421 struct hl_debugfs_entry *entry = s->private; in mmu_show()
422 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in mmu_show()
423 struct hl_device *hdev = dev_entry->hdev; in mmu_show()
424 struct hl_ctx *ctx; in mmu_show() local
426 u64 virt_addr = dev_entry->mmu_addr, phys_addr; in mmu_show()
429 if (dev_entry->mmu_asid == HL_KERNEL_ASID_ID) in mmu_show()
430 ctx = hdev->kernel_ctx; in mmu_show()
432 ctx = hl_get_compute_ctx(hdev); in mmu_show()
434 if (!ctx) { in mmu_show()
435 dev_err(hdev->dev, "no ctx available\n"); in mmu_show()
439 if (hl_mmu_get_tlb_info(ctx, virt_addr, &hops_info)) { in mmu_show()
440 dev_err(hdev->dev, "virt addr 0x%llx is not mapped to phys addr\n", in mmu_show()
445 hl_mmu_va_to_pa(ctx, virt_addr, &phys_addr); in mmu_show()
448 (dev_entry->mmu_addr != hops_info.scrambled_vaddr)) in mmu_show()
450 …"asid: %u, virt_addr: 0x%llx, scrambled virt_addr: 0x%llx,\nphys_addr: 0x%llx, scrambled_phys_addr… in mmu_show()
451 dev_entry->mmu_asid, dev_entry->mmu_addr, in mmu_show()
456 "asid: %u, virt_addr: 0x%llx, phys_addr: 0x%llx\n", in mmu_show()
457 dev_entry->mmu_asid, dev_entry->mmu_addr, phys_addr); in mmu_show()
469 if (dev_entry->mmu_asid != HL_KERNEL_ASID_ID) in mmu_show()
470 hl_ctx_put(ctx); in mmu_show()
478 struct seq_file *s = file->private_data; in mmu_asid_va_write()
479 struct hl_debugfs_entry *entry = s->private; in mmu_asid_va_write()
480 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in mmu_asid_va_write()
481 struct hl_device *hdev = dev_entry->hdev; in mmu_asid_va_write()
486 if (count > sizeof(kbuf) - 1) in mmu_asid_va_write()
497 rc = kstrtouint(kbuf, 10, &dev_entry->mmu_asid); in mmu_asid_va_write()
503 rc = kstrtoull(c+3, 16, &dev_entry->mmu_addr); in mmu_asid_va_write()
510 dev_err(hdev->dev, "usage: echo <asid> <0xaddr> > mmu\n"); in mmu_asid_va_write()
512 return -EINVAL; in mmu_asid_va_write()
517 struct hl_debugfs_entry *entry = s->private; in mmu_ack_error()
518 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in mmu_ack_error()
519 struct hl_device *hdev = dev_entry->hdev; in mmu_ack_error()
522 if (!dev_entry->mmu_cap_mask) { in mmu_ack_error()
523 dev_err(hdev->dev, "mmu_cap_mask is not set\n"); in mmu_ack_error()
527 rc = hdev->asic_funcs->ack_mmu_errors(hdev, dev_entry->mmu_cap_mask); in mmu_ack_error()
533 return -EINVAL; in mmu_ack_error()
540 struct seq_file *s = file->private_data; in mmu_ack_error_value_write()
541 struct hl_debugfs_entry *entry = s->private; in mmu_ack_error_value_write()
542 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in mmu_ack_error_value_write()
543 struct hl_device *hdev = dev_entry->hdev; in mmu_ack_error_value_write()
547 if (count > sizeof(kbuf) - 1) in mmu_ack_error_value_write()
558 rc = kstrtoull(kbuf, 16, &dev_entry->mmu_cap_mask); in mmu_ack_error_value_write()
564 dev_err(hdev->dev, "usage: echo <0xmmu_cap_mask > > mmu_error\n"); in mmu_ack_error_value_write()
566 return -EINVAL; in mmu_ack_error_value_write()
571 struct hl_debugfs_entry *entry = s->private; in engines_show()
572 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in engines_show()
573 struct hl_device *hdev = dev_entry->hdev; in engines_show()
576 if (hdev->reset_info.in_reset) { in engines_show()
577 dev_warn_ratelimited(hdev->dev, in engines_show()
586 return -ENOMEM; in engines_show()
588 hdev->asic_funcs->is_device_idle(hdev, NULL, 0, &eng_data); in engines_show()
591 dev_err(hdev->dev, in engines_show()
595 return -ENOMEM; in engines_show()
608 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_memory_scrub()
609 struct hl_device *hdev = entry->hdev; in hl_memory_scrub()
610 u64 val = hdev->memory_scrub_val; in hl_memory_scrub()
614 dev_warn_ratelimited(hdev->dev, "Can't scrub memory, device is not operational\n"); in hl_memory_scrub()
615 return -EIO; in hl_memory_scrub()
618 mutex_lock(&hdev->fpriv_list_lock); in hl_memory_scrub()
619 if (hdev->is_compute_ctx_active) { in hl_memory_scrub()
620 mutex_unlock(&hdev->fpriv_list_lock); in hl_memory_scrub()
621 dev_err(hdev->dev, "can't scrub dram, context exist\n"); in hl_memory_scrub()
622 return -EBUSY; in hl_memory_scrub()
624 hdev->is_in_dram_scrub = true; in hl_memory_scrub()
625 mutex_unlock(&hdev->fpriv_list_lock); in hl_memory_scrub()
627 rc = hdev->asic_funcs->scrub_device_dram(hdev, val); in hl_memory_scrub()
629 mutex_lock(&hdev->fpriv_list_lock); in hl_memory_scrub()
630 hdev->is_in_dram_scrub = false; in hl_memory_scrub()
631 mutex_unlock(&hdev->fpriv_list_lock); in hl_memory_scrub()
640 struct asic_fixed_properties *prop = &hdev->asic_prop; in hl_is_device_va()
642 if (prop->dram_supports_virtual_memory && in hl_is_device_va()
643 (addr >= prop->dmmu.start_addr && addr < prop->dmmu.end_addr)) in hl_is_device_va()
646 if (addr >= prop->pmmu.start_addr && in hl_is_device_va()
647 addr < prop->pmmu.end_addr) in hl_is_device_va()
650 if (addr >= prop->pmmu_huge.start_addr && in hl_is_device_va()
651 addr < prop->pmmu_huge.end_addr) in hl_is_device_va()
660 struct asic_fixed_properties *prop = &hdev->asic_prop; in hl_is_device_internal_memory_va()
663 if (prop->dram_supports_virtual_memory) { in hl_is_device_internal_memory_va()
664 dram_start_addr = prop->dmmu.start_addr; in hl_is_device_internal_memory_va()
665 dram_end_addr = prop->dmmu.end_addr; in hl_is_device_internal_memory_va()
667 dram_start_addr = prop->dram_base_address; in hl_is_device_internal_memory_va()
668 dram_end_addr = prop->dram_end_address; in hl_is_device_internal_memory_va()
675 if (hl_mem_area_inside_range(addr, size, prop->sram_base_address, in hl_is_device_internal_memory_va()
676 prop->sram_end_address)) in hl_is_device_internal_memory_va()
686 struct hl_ctx *ctx; in device_va_to_pa() local
694 ctx = hl_get_compute_ctx(hdev); in device_va_to_pa()
696 if (!ctx) { in device_va_to_pa()
697 dev_err(hdev->dev, "no ctx available\n"); in device_va_to_pa()
698 return -EINVAL; in device_va_to_pa()
702 mutex_lock(&ctx->mem_hash_lock); in device_va_to_pa()
703 hash_for_each(ctx->mem_hash, i, hnode, node) { in device_va_to_pa()
704 vm_type = hnode->ptr; in device_va_to_pa()
707 userptr = hnode->ptr; in device_va_to_pa()
708 range_size = userptr->size; in device_va_to_pa()
710 phys_pg_pack = hnode->ptr; in device_va_to_pa()
711 range_size = phys_pg_pack->total_size; in device_va_to_pa()
715 if ((virt_addr >= hnode->vaddr) && in device_va_to_pa()
716 (end_address <= hnode->vaddr + range_size)) { in device_va_to_pa()
721 mutex_unlock(&ctx->mem_hash_lock); in device_va_to_pa()
724 dev_err(hdev->dev, in device_va_to_pa()
727 rc = -EINVAL; in device_va_to_pa()
731 rc = hl_mmu_va_to_pa(ctx, virt_addr, phys_addr); in device_va_to_pa()
733 dev_err(hdev->dev, in device_va_to_pa()
736 rc = -EINVAL; in device_va_to_pa()
740 hl_ctx_put(ctx); in device_va_to_pa()
754 mem_reg = &hdev->pci_mem_region[i]; in hl_access_dev_mem_by_region()
755 if (!mem_reg->used) in hl_access_dev_mem_by_region()
757 if (addr >= mem_reg->region_base && in hl_access_dev_mem_by_region()
758 addr <= mem_reg->region_base + mem_reg->region_size - acc_size) { in hl_access_dev_mem_by_region()
760 return hdev->asic_funcs->access_dev_mem(hdev, i, addr, val, acc_type); in hl_access_dev_mem_by_region()
769 struct asic_fixed_properties *prop = &hdev->asic_prop; in hl_access_host_mem()
770 u64 offset = prop->device_dma_offset_for_host_access; in hl_access_host_mem()
774 *val = *(u32 *) phys_to_virt(addr - offset); in hl_access_host_mem()
777 *(u32 *) phys_to_virt(addr - offset) = *val; in hl_access_host_mem()
780 *val = *(u64 *) phys_to_virt(addr - offset); in hl_access_host_mem()
783 *(u64 *) phys_to_virt(addr - offset) = *val; in hl_access_host_mem()
786 dev_err(hdev->dev, "hostmem access-type %d id not supported\n", acc_type); in hl_access_host_mem()
796 u64 host_start = hdev->asic_prop.host_base_address; in hl_access_mem()
797 u64 host_end = hdev->asic_prop.host_end_address; in hl_access_mem()
810 dev_err(hdev->dev, in hl_access_mem()
819 if (!user_address || device_iommu_mapped(&hdev->pdev->dev)) { in hl_access_mem()
820 rc = -EINVAL; in hl_access_mem()
824 if (addr >= host_start && addr <= host_end - acc_size) { in hl_access_mem()
827 rc = -EINVAL; in hl_access_mem()
833 dev_err(hdev->dev, "invalid addr %#llx\n", addr); in hl_access_mem()
840 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_data_read32()
841 struct hl_device *hdev = entry->hdev; in hl_data_read32()
842 u64 value64, addr = entry->addr; in hl_data_read32()
847 if (hdev->reset_info.in_reset) { in hl_data_read32()
848 dev_warn_ratelimited(hdev->dev, "Can't read during reset\n"); in hl_data_read32()
869 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_data_write32()
870 struct hl_device *hdev = entry->hdev; in hl_data_write32()
871 u64 value64, addr = entry->addr; in hl_data_write32()
875 if (hdev->reset_info.in_reset) { in hl_data_write32()
876 dev_warn_ratelimited(hdev->dev, "Can't write during reset\n"); in hl_data_write32()
895 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_data_read64()
896 struct hl_device *hdev = entry->hdev; in hl_data_read64()
897 u64 addr = entry->addr; in hl_data_read64()
902 if (hdev->reset_info.in_reset) { in hl_data_read64()
903 dev_warn_ratelimited(hdev->dev, "Can't read during reset\n"); in hl_data_read64()
922 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_data_write64()
923 struct hl_device *hdev = entry->hdev; in hl_data_write64()
924 u64 addr = entry->addr; in hl_data_write64()
928 if (hdev->reset_info.in_reset) { in hl_data_write64()
929 dev_warn_ratelimited(hdev->dev, "Can't write during reset\n"); in hl_data_write64()
947 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_dma_size_write()
948 struct hl_device *hdev = entry->hdev; in hl_dma_size_write()
949 u64 addr = entry->addr; in hl_dma_size_write()
953 if (hdev->reset_info.in_reset) { in hl_dma_size_write()
954 dev_warn_ratelimited(hdev->dev, "Can't DMA during reset\n"); in hl_dma_size_write()
962 dev_err(hdev->dev, "DMA read failed. size can't be 0\n"); in hl_dma_size_write()
963 return -EINVAL; in hl_dma_size_write()
967 dev_err(hdev->dev, in hl_dma_size_write()
969 return -EINVAL; in hl_dma_size_write()
973 dev_err(hdev->dev, in hl_dma_size_write()
976 return -EINVAL; in hl_dma_size_write()
980 entry->data_dma_blob_desc.size = 0; in hl_dma_size_write()
981 vfree(entry->data_dma_blob_desc.data); in hl_dma_size_write()
983 entry->data_dma_blob_desc.data = vmalloc(size); in hl_dma_size_write()
984 if (!entry->data_dma_blob_desc.data) in hl_dma_size_write()
985 return -ENOMEM; in hl_dma_size_write()
987 rc = hdev->asic_funcs->debugfs_read_dma(hdev, addr, size, in hl_dma_size_write()
988 entry->data_dma_blob_desc.data); in hl_dma_size_write()
990 dev_err(hdev->dev, "Failed to DMA from 0x%010llx\n", addr); in hl_dma_size_write()
991 vfree(entry->data_dma_blob_desc.data); in hl_dma_size_write()
992 entry->data_dma_blob_desc.data = NULL; in hl_dma_size_write()
993 return -EIO; in hl_dma_size_write()
996 entry->data_dma_blob_desc.size = size; in hl_dma_size_write()
1004 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_monitor_dump_trigger()
1005 struct hl_device *hdev = entry->hdev; in hl_monitor_dump_trigger()
1009 if (hdev->reset_info.in_reset) { in hl_monitor_dump_trigger()
1010 dev_warn_ratelimited(hdev->dev, "Can't dump monitors during reset\n"); in hl_monitor_dump_trigger()
1018 dev_err(hdev->dev, "Must write 1 to trigger monitor dump\n"); in hl_monitor_dump_trigger()
1019 return -EINVAL; in hl_monitor_dump_trigger()
1025 entry->mon_dump_blob_desc.size = 0; in hl_monitor_dump_trigger()
1026 vfree(entry->mon_dump_blob_desc.data); in hl_monitor_dump_trigger()
1028 entry->mon_dump_blob_desc.data = vmalloc(size); in hl_monitor_dump_trigger()
1029 if (!entry->mon_dump_blob_desc.data) in hl_monitor_dump_trigger()
1030 return -ENOMEM; in hl_monitor_dump_trigger()
1032 rc = hdev->asic_funcs->get_monitor_dump(hdev, entry->mon_dump_blob_desc.data); in hl_monitor_dump_trigger()
1034 dev_err(hdev->dev, "Failed to dump monitors\n"); in hl_monitor_dump_trigger()
1035 vfree(entry->mon_dump_blob_desc.data); in hl_monitor_dump_trigger()
1036 entry->mon_dump_blob_desc.data = NULL; in hl_monitor_dump_trigger()
1037 return -EIO; in hl_monitor_dump_trigger()
1040 entry->mon_dump_blob_desc.size = size; in hl_monitor_dump_trigger()
1048 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_get_power_state()
1049 struct hl_device *hdev = entry->hdev; in hl_get_power_state()
1056 if (hdev->pdev->current_state == PCI_D0) in hl_get_power_state()
1058 else if (hdev->pdev->current_state == PCI_D3hot) in hl_get_power_state()
1064 "current power state: %d\n1 - D0\n2 - D3hot\n3 - Unknown\n", i); in hl_get_power_state()
1072 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_set_power_state()
1073 struct hl_device *hdev = entry->hdev; in hl_set_power_state()
1082 pci_set_power_state(hdev->pdev, PCI_D0); in hl_set_power_state()
1083 pci_restore_state(hdev->pdev); in hl_set_power_state()
1084 rc = pci_enable_device(hdev->pdev); in hl_set_power_state()
1088 pci_save_state(hdev->pdev); in hl_set_power_state()
1089 pci_disable_device(hdev->pdev); in hl_set_power_state()
1090 pci_set_power_state(hdev->pdev, PCI_D3hot); in hl_set_power_state()
1092 dev_dbg(hdev->dev, "invalid power state value %u\n", value); in hl_set_power_state()
1093 return -EINVAL; in hl_set_power_state()
1102 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_i2c_data_read()
1103 struct hl_device *hdev = entry->hdev; in hl_i2c_data_read()
1111 rc = hl_debugfs_i2c_read(hdev, entry->i2c_bus, entry->i2c_addr, in hl_i2c_data_read()
1112 entry->i2c_reg, entry->i2c_len, &val); in hl_i2c_data_read()
1114 dev_err(hdev->dev, in hl_i2c_data_read()
1116 entry->i2c_bus, entry->i2c_addr, entry->i2c_reg, entry->i2c_len); in hl_i2c_data_read()
1130 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_i2c_data_write()
1131 struct hl_device *hdev = entry->hdev; in hl_i2c_data_write()
1139 rc = hl_debugfs_i2c_write(hdev, entry->i2c_bus, entry->i2c_addr, in hl_i2c_data_write()
1140 entry->i2c_reg, entry->i2c_len, value); in hl_i2c_data_write()
1142 dev_err(hdev->dev, in hl_i2c_data_write()
1144 value, entry->i2c_bus, entry->i2c_addr, entry->i2c_reg, entry->i2c_len); in hl_i2c_data_write()
1154 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_led0_write()
1155 struct hl_device *hdev = entry->hdev; in hl_led0_write()
1173 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_led1_write()
1174 struct hl_device *hdev = entry->hdev; in hl_led1_write()
1192 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_led2_write()
1193 struct hl_device *hdev = entry->hdev; in hl_led2_write()
1219 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_device_write()
1220 struct hl_device *hdev = entry->hdev; in hl_device_write()
1230 hdev->disabled = true; in hl_device_write()
1232 hdev->disabled = false; in hl_device_write()
1234 hdev->asic_funcs->suspend(hdev); in hl_device_write()
1236 hdev->asic_funcs->resume(hdev); in hl_device_write()
1238 hdev->device_cpu_disabled = true; in hl_device_write()
1240 dev_err(hdev->dev, in hl_device_write()
1242 count = -EINVAL; in hl_device_write()
1263 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_stop_on_err_read()
1264 struct hl_device *hdev = entry->hdev; in hl_stop_on_err_read()
1268 if (!hdev->asic_prop.configurable_stop_on_err) in hl_stop_on_err_read()
1269 return -EOPNOTSUPP; in hl_stop_on_err_read()
1274 sprintf(tmp_buf, "%d\n", hdev->stop_on_err); in hl_stop_on_err_read()
1284 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_stop_on_err_write()
1285 struct hl_device *hdev = entry->hdev; in hl_stop_on_err_write()
1289 if (!hdev->asic_prop.configurable_stop_on_err) in hl_stop_on_err_write()
1290 return -EOPNOTSUPP; in hl_stop_on_err_write()
1292 if (hdev->reset_info.in_reset) { in hl_stop_on_err_write()
1293 dev_warn_ratelimited(hdev->dev, in hl_stop_on_err_write()
1302 hdev->stop_on_err = value ? 1 : 0; in hl_stop_on_err_write()
1312 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_security_violations_read()
1313 struct hl_device *hdev = entry->hdev; in hl_security_violations_read()
1315 hdev->asic_funcs->ack_protection_bits_errors(hdev); in hl_security_violations_read()
1323 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_state_dump_read()
1326 down_read(&entry->state_dump_sem); in hl_state_dump_read()
1327 if (!entry->state_dump[entry->state_dump_head]) in hl_state_dump_read()
1332 entry->state_dump[entry->state_dump_head], in hl_state_dump_read()
1333 strlen(entry->state_dump[entry->state_dump_head])); in hl_state_dump_read()
1334 up_read(&entry->state_dump_sem); in hl_state_dump_read()
1342 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_state_dump_write()
1343 struct hl_device *hdev = entry->hdev; in hl_state_dump_write()
1352 if (size <= 0 || size >= ARRAY_SIZE(entry->state_dump)) { in hl_state_dump_write()
1353 dev_err(hdev->dev, "Invalid number of dumps to skip\n"); in hl_state_dump_write()
1354 return -EINVAL; in hl_state_dump_write()
1357 if (entry->state_dump[entry->state_dump_head]) { in hl_state_dump_write()
1358 down_write(&entry->state_dump_sem); in hl_state_dump_write()
1360 vfree(entry->state_dump[entry->state_dump_head]); in hl_state_dump_write()
1361 entry->state_dump[entry->state_dump_head] = NULL; in hl_state_dump_write()
1362 if (entry->state_dump_head > 0) in hl_state_dump_write()
1363 entry->state_dump_head--; in hl_state_dump_write()
1365 entry->state_dump_head = in hl_state_dump_write()
1366 ARRAY_SIZE(entry->state_dump) - 1; in hl_state_dump_write()
1368 up_write(&entry->state_dump_sem); in hl_state_dump_write()
1377 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_timeout_locked_read()
1378 struct hl_device *hdev = entry->hdev; in hl_timeout_locked_read()
1386 jiffies_to_msecs(hdev->timeout_jiffies) / 1000); in hl_timeout_locked_read()
1396 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_timeout_locked_write()
1397 struct hl_device *hdev = entry->hdev; in hl_timeout_locked_write()
1406 hdev->timeout_jiffies = msecs_to_jiffies(value * 1000); in hl_timeout_locked_write()
1408 hdev->timeout_jiffies = MAX_SCHEDULE_TIMEOUT; in hl_timeout_locked_write()
1416 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_check_razwi_happened()
1417 struct hl_device *hdev = entry->hdev; in hl_check_razwi_happened()
1419 hdev->asic_funcs->check_if_razwi_happened(hdev); in hl_check_razwi_happened()
1532 struct hl_debugfs_entry *node = inode->i_private; in hl_debugfs_open()
1534 return single_open(file, node->info_ent->show, node); in hl_debugfs_open()
1540 struct hl_debugfs_entry *node = file->f_inode->i_private; in hl_debugfs_write()
1542 if (node->info_ent->write) in hl_debugfs_write()
1543 return node->info_ent->write(file, buf, count, f_pos); in hl_debugfs_write()
1545 return -EINVAL; in hl_debugfs_write()
1563 &dev_entry->i2c_bus); in add_secured_nodes()
1568 &dev_entry->i2c_addr); in add_secured_nodes()
1573 &dev_entry->i2c_reg); in add_secured_nodes()
1578 &dev_entry->i2c_len); in add_secured_nodes()
1615 &hdev->memory_scrub_val); in add_files_to_device()
1626 &dev_entry->addr); in add_files_to_device()
1685 &dev_entry->data_dma_blob_desc); in add_files_to_device()
1696 &dev_entry->mon_dump_blob_desc); in add_files_to_device()
1701 &hdev->reset_info.skip_reset_on_timeout); in add_files_to_device()
1718 &hdev->device_release_watchdog_timeout_sec); in add_files_to_device()
1723 &hdev->asic_prop.server_type); in add_files_to_device()
1725 for (i = 0, entry = dev_entry->entry_arr ; i < count ; i++, entry++) { in add_files_to_device()
1731 entry->info_ent = &hl_debugfs_list[i]; in add_files_to_device()
1732 entry->dev_entry = dev_entry; in add_files_to_device()
1738 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_device_init()
1741 dev_entry->hdev = hdev; in hl_debugfs_device_init()
1742 dev_entry->entry_arr = kmalloc_array(count, sizeof(struct hl_debugfs_entry), GFP_KERNEL); in hl_debugfs_device_init()
1743 if (!dev_entry->entry_arr) in hl_debugfs_device_init()
1744 return -ENOMEM; in hl_debugfs_device_init()
1746 dev_entry->data_dma_blob_desc.size = 0; in hl_debugfs_device_init()
1747 dev_entry->data_dma_blob_desc.data = NULL; in hl_debugfs_device_init()
1748 dev_entry->mon_dump_blob_desc.size = 0; in hl_debugfs_device_init()
1749 dev_entry->mon_dump_blob_desc.data = NULL; in hl_debugfs_device_init()
1751 INIT_LIST_HEAD(&dev_entry->file_list); in hl_debugfs_device_init()
1752 INIT_LIST_HEAD(&dev_entry->cb_list); in hl_debugfs_device_init()
1753 INIT_LIST_HEAD(&dev_entry->cs_list); in hl_debugfs_device_init()
1754 INIT_LIST_HEAD(&dev_entry->cs_job_list); in hl_debugfs_device_init()
1755 INIT_LIST_HEAD(&dev_entry->userptr_list); in hl_debugfs_device_init()
1756 INIT_LIST_HEAD(&dev_entry->ctx_mem_hash_list); in hl_debugfs_device_init()
1757 mutex_init(&dev_entry->file_mutex); in hl_debugfs_device_init()
1758 init_rwsem(&dev_entry->state_dump_sem); in hl_debugfs_device_init()
1759 spin_lock_init(&dev_entry->cb_spinlock); in hl_debugfs_device_init()
1760 spin_lock_init(&dev_entry->cs_spinlock); in hl_debugfs_device_init()
1761 spin_lock_init(&dev_entry->cs_job_spinlock); in hl_debugfs_device_init()
1762 spin_lock_init(&dev_entry->userptr_spinlock); in hl_debugfs_device_init()
1763 mutex_init(&dev_entry->ctx_mem_hash_mutex); in hl_debugfs_device_init()
1770 struct hl_dbg_device_entry *entry = &hdev->hl_debugfs; in hl_debugfs_device_fini()
1773 mutex_destroy(&entry->ctx_mem_hash_mutex); in hl_debugfs_device_fini()
1774 mutex_destroy(&entry->file_mutex); in hl_debugfs_device_fini()
1776 vfree(entry->data_dma_blob_desc.data); in hl_debugfs_device_fini()
1777 vfree(entry->mon_dump_blob_desc.data); in hl_debugfs_device_fini()
1779 for (i = 0; i < ARRAY_SIZE(entry->state_dump); ++i) in hl_debugfs_device_fini()
1780 vfree(entry->state_dump[i]); in hl_debugfs_device_fini()
1782 kfree(entry->entry_arr); in hl_debugfs_device_fini()
1787 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_add_device()
1789 dev_entry->root = hdev->drm.accel->debugfs_root; in hl_debugfs_add_device()
1791 add_files_to_device(hdev, dev_entry, dev_entry->root); in hl_debugfs_add_device()
1793 if (!hdev->asic_prop.fw_security_enabled) in hl_debugfs_add_device()
1794 add_secured_nodes(dev_entry, dev_entry->root); in hl_debugfs_add_device()
1799 struct hl_dbg_device_entry *dev_entry = &hpriv->hdev->hl_debugfs; in hl_debugfs_add_file()
1801 mutex_lock(&dev_entry->file_mutex); in hl_debugfs_add_file()
1802 list_add(&hpriv->debugfs_list, &dev_entry->file_list); in hl_debugfs_add_file()
1803 mutex_unlock(&dev_entry->file_mutex); in hl_debugfs_add_file()
1808 struct hl_dbg_device_entry *dev_entry = &hpriv->hdev->hl_debugfs; in hl_debugfs_remove_file()
1810 mutex_lock(&dev_entry->file_mutex); in hl_debugfs_remove_file()
1811 list_del(&hpriv->debugfs_list); in hl_debugfs_remove_file()
1812 mutex_unlock(&dev_entry->file_mutex); in hl_debugfs_remove_file()
1817 struct hl_dbg_device_entry *dev_entry = &cb->hdev->hl_debugfs; in hl_debugfs_add_cb()
1819 spin_lock(&dev_entry->cb_spinlock); in hl_debugfs_add_cb()
1820 list_add(&cb->debugfs_list, &dev_entry->cb_list); in hl_debugfs_add_cb()
1821 spin_unlock(&dev_entry->cb_spinlock); in hl_debugfs_add_cb()
1826 struct hl_dbg_device_entry *dev_entry = &cb->hdev->hl_debugfs; in hl_debugfs_remove_cb()
1828 spin_lock(&dev_entry->cb_spinlock); in hl_debugfs_remove_cb()
1829 list_del(&cb->debugfs_list); in hl_debugfs_remove_cb()
1830 spin_unlock(&dev_entry->cb_spinlock); in hl_debugfs_remove_cb()
1835 struct hl_dbg_device_entry *dev_entry = &cs->ctx->hdev->hl_debugfs; in hl_debugfs_add_cs()
1837 spin_lock(&dev_entry->cs_spinlock); in hl_debugfs_add_cs()
1838 list_add(&cs->debugfs_list, &dev_entry->cs_list); in hl_debugfs_add_cs()
1839 spin_unlock(&dev_entry->cs_spinlock); in hl_debugfs_add_cs()
1844 struct hl_dbg_device_entry *dev_entry = &cs->ctx->hdev->hl_debugfs; in hl_debugfs_remove_cs()
1846 spin_lock(&dev_entry->cs_spinlock); in hl_debugfs_remove_cs()
1847 list_del(&cs->debugfs_list); in hl_debugfs_remove_cs()
1848 spin_unlock(&dev_entry->cs_spinlock); in hl_debugfs_remove_cs()
1853 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_add_job()
1855 spin_lock(&dev_entry->cs_job_spinlock); in hl_debugfs_add_job()
1856 list_add(&job->debugfs_list, &dev_entry->cs_job_list); in hl_debugfs_add_job()
1857 spin_unlock(&dev_entry->cs_job_spinlock); in hl_debugfs_add_job()
1862 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_remove_job()
1864 spin_lock(&dev_entry->cs_job_spinlock); in hl_debugfs_remove_job()
1865 list_del(&job->debugfs_list); in hl_debugfs_remove_job()
1866 spin_unlock(&dev_entry->cs_job_spinlock); in hl_debugfs_remove_job()
1871 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_add_userptr()
1873 spin_lock(&dev_entry->userptr_spinlock); in hl_debugfs_add_userptr()
1874 list_add(&userptr->debugfs_list, &dev_entry->userptr_list); in hl_debugfs_add_userptr()
1875 spin_unlock(&dev_entry->userptr_spinlock); in hl_debugfs_add_userptr()
1881 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_remove_userptr()
1883 spin_lock(&dev_entry->userptr_spinlock); in hl_debugfs_remove_userptr()
1884 list_del(&userptr->debugfs_list); in hl_debugfs_remove_userptr()
1885 spin_unlock(&dev_entry->userptr_spinlock); in hl_debugfs_remove_userptr()
1888 void hl_debugfs_add_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx) in hl_debugfs_add_ctx_mem_hash() argument
1890 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_add_ctx_mem_hash()
1892 mutex_lock(&dev_entry->ctx_mem_hash_mutex); in hl_debugfs_add_ctx_mem_hash()
1893 list_add(&ctx->debugfs_list, &dev_entry->ctx_mem_hash_list); in hl_debugfs_add_ctx_mem_hash()
1894 mutex_unlock(&dev_entry->ctx_mem_hash_mutex); in hl_debugfs_add_ctx_mem_hash()
1897 void hl_debugfs_remove_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx) in hl_debugfs_remove_ctx_mem_hash() argument
1899 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_remove_ctx_mem_hash()
1901 mutex_lock(&dev_entry->ctx_mem_hash_mutex); in hl_debugfs_remove_ctx_mem_hash()
1902 list_del(&ctx->debugfs_list); in hl_debugfs_remove_ctx_mem_hash()
1903 mutex_unlock(&dev_entry->ctx_mem_hash_mutex); in hl_debugfs_remove_ctx_mem_hash()
1907 * hl_debugfs_set_state_dump - register state dump making it accessible via
1916 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_set_state_dump()
1918 down_write(&dev_entry->state_dump_sem); in hl_debugfs_set_state_dump()
1920 dev_entry->state_dump_head = (dev_entry->state_dump_head + 1) % in hl_debugfs_set_state_dump()
1921 ARRAY_SIZE(dev_entry->state_dump); in hl_debugfs_set_state_dump()
1922 vfree(dev_entry->state_dump[dev_entry->state_dump_head]); in hl_debugfs_set_state_dump()
1923 dev_entry->state_dump[dev_entry->state_dump_head] = data; in hl_debugfs_set_state_dump()
1925 up_write(&dev_entry->state_dump_sem); in hl_debugfs_set_state_dump()