2019-02-16 01:39:24 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
|
|
|
/*
|
2021-12-01 00:02:21 +03:00
|
|
|
* Copyright 2016-2021 HabanaLabs, Ltd.
|
2019-02-16 01:39:24 +03:00
|
|
|
* All Rights Reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "habanalabs.h"
|
2020-07-28 20:18:51 +03:00
|
|
|
#include "../include/hw_ip/mmu/mmu_general.h"
|
2019-02-16 01:39:24 +03:00
|
|
|
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/uaccess.h>
|
2021-04-02 01:43:18 +03:00
|
|
|
#include <linux/vmalloc.h>
|
2022-03-23 18:21:56 +03:00
|
|
|
#include <linux/iommu.h>
|
2019-02-16 01:39:24 +03:00
|
|
|
|
|
|
|
#define MMU_ADDR_BUF_SIZE 40
|
|
|
|
#define MMU_ASID_BUF_SIZE 10
|
|
|
|
#define MMU_KBUF_SIZE (MMU_ADDR_BUF_SIZE + MMU_ASID_BUF_SIZE)
|
2021-10-12 20:52:46 +03:00
|
|
|
#define I2C_MAX_TRANSACTION_LEN 8
|
2019-02-16 01:39:24 +03:00
|
|
|
|
|
|
|
static struct dentry *hl_debug_root;
|
|
|
|
|
|
|
|
static int hl_debugfs_i2c_read(struct hl_device *hdev, u8 i2c_bus, u8 i2c_addr,
|
2021-10-12 20:52:46 +03:00
|
|
|
u8 i2c_reg, u8 i2c_len, u64 *val)
|
2019-02-16 01:39:24 +03:00
|
|
|
{
|
2020-08-15 16:28:10 +03:00
|
|
|
struct cpucp_packet pkt;
|
2019-02-16 01:39:24 +03:00
|
|
|
int rc;
|
|
|
|
|
2020-10-05 14:40:10 +03:00
|
|
|
if (!hl_device_operational(hdev, NULL))
|
2019-02-26 12:23:34 +03:00
|
|
|
return -EBUSY;
|
2019-02-16 01:39:24 +03:00
|
|
|
|
2021-10-12 20:52:46 +03:00
|
|
|
if (i2c_len > I2C_MAX_TRANSACTION_LEN) {
|
|
|
|
dev_err(hdev->dev, "I2C transaction length %u, exceeds maximum of %u\n",
|
|
|
|
i2c_len, I2C_MAX_TRANSACTION_LEN);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-02-16 01:39:24 +03:00
|
|
|
memset(&pkt, 0, sizeof(pkt));
|
|
|
|
|
2020-08-15 16:28:10 +03:00
|
|
|
pkt.ctl = cpu_to_le32(CPUCP_PACKET_I2C_RD <<
|
|
|
|
CPUCP_PKT_CTL_OPCODE_SHIFT);
|
2019-02-16 01:39:24 +03:00
|
|
|
pkt.i2c_bus = i2c_bus;
|
|
|
|
pkt.i2c_addr = i2c_addr;
|
|
|
|
pkt.i2c_reg = i2c_reg;
|
2021-10-12 20:52:46 +03:00
|
|
|
pkt.i2c_len = i2c_len;
|
2019-02-16 01:39:24 +03:00
|
|
|
|
|
|
|
rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
|
2021-10-12 20:52:46 +03:00
|
|
|
0, val);
|
2019-02-16 01:39:24 +03:00
|
|
|
if (rc)
|
|
|
|
dev_err(hdev->dev, "Failed to read from I2C, error %d\n", rc);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hl_debugfs_i2c_write(struct hl_device *hdev, u8 i2c_bus, u8 i2c_addr,
|
2021-10-12 20:52:46 +03:00
|
|
|
u8 i2c_reg, u8 i2c_len, u64 val)
|
2019-02-16 01:39:24 +03:00
|
|
|
{
|
2020-08-15 16:28:10 +03:00
|
|
|
struct cpucp_packet pkt;
|
2019-02-16 01:39:24 +03:00
|
|
|
int rc;
|
|
|
|
|
2020-10-05 14:40:10 +03:00
|
|
|
if (!hl_device_operational(hdev, NULL))
|
2019-02-26 12:23:34 +03:00
|
|
|
return -EBUSY;
|
2019-02-16 01:39:24 +03:00
|
|
|
|
2021-10-12 20:52:46 +03:00
|
|
|
if (i2c_len > I2C_MAX_TRANSACTION_LEN) {
|
|
|
|
dev_err(hdev->dev, "I2C transaction length %u, exceeds maximum of %u\n",
|
|
|
|
i2c_len, I2C_MAX_TRANSACTION_LEN);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-02-16 01:39:24 +03:00
|
|
|
memset(&pkt, 0, sizeof(pkt));
|
|
|
|
|
2020-08-15 16:28:10 +03:00
|
|
|
pkt.ctl = cpu_to_le32(CPUCP_PACKET_I2C_WR <<
|
|
|
|
CPUCP_PKT_CTL_OPCODE_SHIFT);
|
2019-02-16 01:39:24 +03:00
|
|
|
pkt.i2c_bus = i2c_bus;
|
|
|
|
pkt.i2c_addr = i2c_addr;
|
|
|
|
pkt.i2c_reg = i2c_reg;
|
2021-10-12 20:52:46 +03:00
|
|
|
pkt.i2c_len = i2c_len;
|
2019-08-08 17:00:54 +03:00
|
|
|
pkt.value = cpu_to_le64(val);
|
2019-02-16 01:39:24 +03:00
|
|
|
|
|
|
|
rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
|
2020-07-07 17:30:13 +03:00
|
|
|
0, NULL);
|
2019-02-16 01:39:24 +03:00
|
|
|
|
|
|
|
if (rc)
|
|
|
|
dev_err(hdev->dev, "Failed to write to I2C, error %d\n", rc);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hl_debugfs_led_set(struct hl_device *hdev, u8 led, u8 state)
|
|
|
|
{
|
2020-08-15 16:28:10 +03:00
|
|
|
struct cpucp_packet pkt;
|
2019-02-16 01:39:24 +03:00
|
|
|
int rc;
|
|
|
|
|
2020-10-05 14:40:10 +03:00
|
|
|
if (!hl_device_operational(hdev, NULL))
|
2019-02-16 01:39:24 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
memset(&pkt, 0, sizeof(pkt));
|
|
|
|
|
2020-08-15 16:28:10 +03:00
|
|
|
pkt.ctl = cpu_to_le32(CPUCP_PACKET_LED_SET <<
|
|
|
|
CPUCP_PKT_CTL_OPCODE_SHIFT);
|
2019-08-08 17:00:54 +03:00
|
|
|
pkt.led_index = cpu_to_le32(led);
|
|
|
|
pkt.value = cpu_to_le64(state);
|
2019-02-16 01:39:24 +03:00
|
|
|
|
|
|
|
rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
|
2020-07-07 17:30:13 +03:00
|
|
|
0, NULL);
|
2019-02-16 01:39:24 +03:00
|
|
|
|
|
|
|
if (rc)
|
|
|
|
dev_err(hdev->dev, "Failed to set LED %d, error %d\n", led, rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int command_buffers_show(struct seq_file *s, void *data)
|
|
|
|
{
|
|
|
|
struct hl_debugfs_entry *entry = s->private;
|
|
|
|
struct hl_dbg_device_entry *dev_entry = entry->dev_entry;
|
|
|
|
struct hl_cb *cb;
|
|
|
|
bool first = true;
|
|
|
|
|
|
|
|
spin_lock(&dev_entry->cb_spinlock);
|
|
|
|
|
|
|
|
list_for_each_entry(cb, &dev_entry->cb_list, debugfs_list) {
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
seq_puts(s, "\n");
|
|
|
|
seq_puts(s, " CB ID CTX ID CB size CB RefCnt mmap? CS counter\n");
|
|
|
|
seq_puts(s, "---------------------------------------------------------------\n");
|
|
|
|
}
|
|
|
|
seq_printf(s,
|
2020-08-12 10:11:20 +03:00
|
|
|
" %03llu %d 0x%08x %d %d %d\n",
|
2022-03-29 14:16:04 +03:00
|
|
|
cb->buf->handle, cb->ctx->asid, cb->size,
|
|
|
|
kref_read(&cb->buf->refcount),
|
|
|
|
atomic_read(&cb->buf->mmap), atomic_read(&cb->cs_cnt));
|
2019-02-16 01:39:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock(&dev_entry->cb_spinlock);
|
|
|
|
|
|
|
|
if (!first)
|
|
|
|
seq_puts(s, "\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int command_submission_show(struct seq_file *s, void *data)
|
|
|
|
{
|
|
|
|
struct hl_debugfs_entry *entry = s->private;
|
|
|
|
struct hl_dbg_device_entry *dev_entry = entry->dev_entry;
|
|
|
|
struct hl_cs *cs;
|
|
|
|
bool first = true;
|
|
|
|
|
|
|
|
spin_lock(&dev_entry->cs_spinlock);
|
|
|
|
|
|
|
|
list_for_each_entry(cs, &dev_entry->cs_list, debugfs_list) {
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
seq_puts(s, "\n");
|
2022-06-27 15:05:28 +03:00
|
|
|
seq_puts(s, " CS ID CS TYPE CTX ASID CS RefCnt Submitted Completed\n");
|
|
|
|
seq_puts(s, "----------------------------------------------------------------\n");
|
2019-02-16 01:39:24 +03:00
|
|
|
}
|
|
|
|
seq_printf(s,
|
2022-06-27 15:05:28 +03:00
|
|
|
" %llu %d %d %d %d %d\n",
|
|
|
|
cs->sequence, cs->type, cs->ctx->asid,
|
2019-02-16 01:39:24 +03:00
|
|
|
kref_read(&cs->refcount),
|
|
|
|
cs->submitted, cs->completed);
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock(&dev_entry->cs_spinlock);
|
|
|
|
|
|
|
|
if (!first)
|
|
|
|
seq_puts(s, "\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int command_submission_jobs_show(struct seq_file *s, void *data)
|
|
|
|
{
|
|
|
|
struct hl_debugfs_entry *entry = s->private;
|
|
|
|
struct hl_dbg_device_entry *dev_entry = entry->dev_entry;
|
|
|
|
struct hl_cs_job *job;
|
|
|
|
bool first = true;
|
|
|
|
|
|
|
|
spin_lock(&dev_entry->cs_job_spinlock);
|
|
|
|
|
|
|
|
list_for_each_entry(job, &dev_entry->cs_job_list, debugfs_list) {
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
seq_puts(s, "\n");
|
2022-06-27 15:05:28 +03:00
|
|
|
seq_puts(s, " JOB ID CS ID CS TYPE CTX ASID JOB RefCnt H/W Queue\n");
|
|
|
|
seq_puts(s, "---------------------------------------------------------------\n");
|
2019-02-16 01:39:24 +03:00
|
|
|
}
|
|
|
|
if (job->cs)
|
|
|
|
seq_printf(s,
|
2022-06-27 15:05:28 +03:00
|
|
|
" %02d %llu %d %d %d %d\n",
|
|
|
|
job->id, job->cs->sequence, job->cs->type,
|
|
|
|
job->cs->ctx->asid, kref_read(&job->refcount),
|
|
|
|
job->hw_queue_id);
|
2019-02-16 01:39:24 +03:00
|
|
|
else
|
|
|
|
seq_printf(s,
|
2022-06-27 15:05:28 +03:00
|
|
|
" %02d 0 0 %d %d %d\n",
|
2020-08-10 17:30:35 +03:00
|
|
|
job->id, HL_KERNEL_ASID_ID,
|
|
|
|
kref_read(&job->refcount), job->hw_queue_id);
|
2019-02-16 01:39:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock(&dev_entry->cs_job_spinlock);
|
|
|
|
|
|
|
|
if (!first)
|
|
|
|
seq_puts(s, "\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int userptr_show(struct seq_file *s, void *data)
|
|
|
|
{
|
|
|
|
struct hl_debugfs_entry *entry = s->private;
|
|
|
|
struct hl_dbg_device_entry *dev_entry = entry->dev_entry;
|
|
|
|
struct hl_userptr *userptr;
|
|
|
|
char dma_dir[4][30] = {"DMA_BIDIRECTIONAL", "DMA_TO_DEVICE",
|
|
|
|
"DMA_FROM_DEVICE", "DMA_NONE"};
|
|
|
|
bool first = true;
|
|
|
|
|
|
|
|
spin_lock(&dev_entry->userptr_spinlock);
|
|
|
|
|
|
|
|
list_for_each_entry(userptr, &dev_entry->userptr_list, debugfs_list) {
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
seq_puts(s, "\n");
|
2021-07-27 17:39:42 +03:00
|
|
|
seq_puts(s, " pid user virtual address size dma dir\n");
|
2019-02-16 01:39:24 +03:00
|
|
|
seq_puts(s, "----------------------------------------------------------\n");
|
|
|
|
}
|
2021-07-27 17:39:42 +03:00
|
|
|
seq_printf(s, " %-7d 0x%-14llx %-10llu %-30s\n",
|
|
|
|
userptr->pid, userptr->addr, userptr->size,
|
|
|
|
dma_dir[userptr->dir]);
|
2019-02-16 01:39:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock(&dev_entry->userptr_spinlock);
|
|
|
|
|
|
|
|
if (!first)
|
|
|
|
seq_puts(s, "\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vm_show(struct seq_file *s, void *data)
|
|
|
|
{
|
|
|
|
struct hl_debugfs_entry *entry = s->private;
|
|
|
|
struct hl_dbg_device_entry *dev_entry = entry->dev_entry;
|
2021-02-23 12:01:08 +03:00
|
|
|
struct hl_vm_hw_block_list_node *lnode;
|
2019-02-16 01:39:24 +03:00
|
|
|
struct hl_ctx *ctx;
|
|
|
|
struct hl_vm *vm;
|
|
|
|
struct hl_vm_hash_node *hnode;
|
|
|
|
struct hl_userptr *userptr;
|
|
|
|
struct hl_vm_phys_pg_pack *phys_pg_pack = NULL;
|
2021-10-14 12:10:31 +03:00
|
|
|
struct hl_va_range *va_range;
|
|
|
|
struct hl_vm_va_block *va_block;
|
2021-06-29 18:08:05 +03:00
|
|
|
enum vm_type *vm_type;
|
2019-02-16 01:39:24 +03:00
|
|
|
bool once = true;
|
2019-03-05 11:59:16 +03:00
|
|
|
u64 j;
|
2019-02-16 01:39:24 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!dev_entry->hdev->mmu_enable)
|
|
|
|
return 0;
|
|
|
|
|
2023-02-23 19:17:02 +03:00
|
|
|
mutex_lock(&dev_entry->ctx_mem_hash_mutex);
|
2019-02-16 01:39:24 +03:00
|
|
|
|
|
|
|
list_for_each_entry(ctx, &dev_entry->ctx_mem_hash_list, debugfs_list) {
|
|
|
|
once = false;
|
|
|
|
seq_puts(s, "\n\n----------------------------------------------------");
|
|
|
|
seq_puts(s, "\n----------------------------------------------------\n\n");
|
|
|
|
seq_printf(s, "ctx asid: %u\n", ctx->asid);
|
|
|
|
|
|
|
|
seq_puts(s, "\nmappings:\n\n");
|
|
|
|
seq_puts(s, " virtual address size handle\n");
|
|
|
|
seq_puts(s, "----------------------------------------------------\n");
|
|
|
|
mutex_lock(&ctx->mem_hash_lock);
|
|
|
|
hash_for_each(ctx->mem_hash, i, hnode, node) {
|
|
|
|
vm_type = hnode->ptr;
|
|
|
|
|
|
|
|
if (*vm_type == VM_TYPE_USERPTR) {
|
|
|
|
userptr = hnode->ptr;
|
|
|
|
seq_printf(s,
|
2021-06-29 18:12:46 +03:00
|
|
|
" 0x%-14llx %-10llu\n",
|
2019-02-16 01:39:24 +03:00
|
|
|
hnode->vaddr, userptr->size);
|
|
|
|
} else {
|
|
|
|
phys_pg_pack = hnode->ptr;
|
|
|
|
seq_printf(s,
|
2019-03-05 11:59:16 +03:00
|
|
|
" 0x%-14llx %-10llu %-4u\n",
|
2019-02-16 01:39:24 +03:00
|
|
|
hnode->vaddr, phys_pg_pack->total_size,
|
|
|
|
phys_pg_pack->handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mutex_unlock(&ctx->mem_hash_lock);
|
|
|
|
|
2021-02-23 12:01:08 +03:00
|
|
|
if (ctx->asid != HL_KERNEL_ASID_ID &&
|
|
|
|
!list_empty(&ctx->hw_block_mem_list)) {
|
|
|
|
seq_puts(s, "\nhw_block mappings:\n\n");
|
2022-08-03 16:36:02 +03:00
|
|
|
seq_puts(s,
|
|
|
|
" virtual address block size mapped size HW block id\n");
|
|
|
|
seq_puts(s,
|
|
|
|
"---------------------------------------------------------------\n");
|
2021-02-23 12:01:08 +03:00
|
|
|
mutex_lock(&ctx->hw_block_list_lock);
|
2022-08-03 16:36:02 +03:00
|
|
|
list_for_each_entry(lnode, &ctx->hw_block_mem_list, node) {
|
2021-02-23 12:01:08 +03:00
|
|
|
seq_printf(s,
|
2022-08-03 16:36:02 +03:00
|
|
|
" 0x%-14lx %-6u %-6u %-9u\n",
|
|
|
|
lnode->vaddr, lnode->block_size, lnode->mapped_size,
|
|
|
|
lnode->id);
|
2021-02-23 12:01:08 +03:00
|
|
|
}
|
|
|
|
mutex_unlock(&ctx->hw_block_list_lock);
|
|
|
|
}
|
|
|
|
|
2019-02-16 01:39:24 +03:00
|
|
|
vm = &ctx->hdev->vm;
|
|
|
|
spin_lock(&vm->idr_lock);
|
|
|
|
|
|
|
|
if (!idr_is_empty(&vm->phys_pg_pack_handles))
|
|
|
|
seq_puts(s, "\n\nallocations:\n");
|
|
|
|
|
|
|
|
idr_for_each_entry(&vm->phys_pg_pack_handles, phys_pg_pack, i) {
|
|
|
|
if (phys_pg_pack->asid != ctx->asid)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
seq_printf(s, "\nhandle: %u\n", phys_pg_pack->handle);
|
|
|
|
seq_printf(s, "page size: %u\n\n",
|
|
|
|
phys_pg_pack->page_size);
|
|
|
|
seq_puts(s, " physical address\n");
|
|
|
|
seq_puts(s, "---------------------\n");
|
2019-03-05 11:59:16 +03:00
|
|
|
for (j = 0 ; j < phys_pg_pack->npages ; j++) {
|
2019-02-16 01:39:24 +03:00
|
|
|
seq_printf(s, " 0x%-14llx\n",
|
2019-03-05 11:59:16 +03:00
|
|
|
phys_pg_pack->pages[j]);
|
2019-02-16 01:39:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock(&vm->idr_lock);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-02-23 19:17:02 +03:00
|
|
|
mutex_unlock(&dev_entry->ctx_mem_hash_mutex);
|
2019-02-16 01:39:24 +03:00
|
|
|
|
2021-12-01 00:02:21 +03:00
|
|
|
ctx = hl_get_compute_ctx(dev_entry->hdev);
|
2021-10-14 12:10:31 +03:00
|
|
|
if (ctx) {
|
|
|
|
seq_puts(s, "\nVA ranges:\n\n");
|
|
|
|
for (i = HL_VA_RANGE_TYPE_HOST ; i < HL_VA_RANGE_TYPE_MAX ; ++i) {
|
|
|
|
va_range = ctx->va_range[i];
|
|
|
|
seq_printf(s, " va_range %d\n", i);
|
|
|
|
seq_puts(s, "---------------------\n");
|
|
|
|
mutex_lock(&va_range->lock);
|
|
|
|
list_for_each_entry(va_block, &va_range->list, node) {
|
|
|
|
seq_printf(s, "%#16llx - %#16llx (%#llx)\n",
|
|
|
|
va_block->start, va_block->end,
|
|
|
|
va_block->size);
|
|
|
|
}
|
|
|
|
mutex_unlock(&va_range->lock);
|
|
|
|
seq_puts(s, "\n");
|
|
|
|
}
|
|
|
|
hl_ctx_put(ctx);
|
|
|
|
}
|
|
|
|
|
2019-02-16 01:39:24 +03:00
|
|
|
if (!once)
|
|
|
|
seq_puts(s, "\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-07-29 11:44:28 +03:00
|
|
|
static int userptr_lookup_show(struct seq_file *s, void *data)
|
|
|
|
{
|
|
|
|
struct hl_debugfs_entry *entry = s->private;
|
|
|
|
struct hl_dbg_device_entry *dev_entry = entry->dev_entry;
|
|
|
|
struct scatterlist *sg;
|
|
|
|
struct hl_userptr *userptr;
|
|
|
|
bool first = true;
|
|
|
|
u64 total_npages, npages, sg_start, sg_end;
|
|
|
|
dma_addr_t dma_addr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
spin_lock(&dev_entry->userptr_spinlock);
|
|
|
|
|
|
|
|
list_for_each_entry(userptr, &dev_entry->userptr_list, debugfs_list) {
|
|
|
|
if (dev_entry->userptr_lookup >= userptr->addr &&
|
|
|
|
dev_entry->userptr_lookup < userptr->addr + userptr->size) {
|
|
|
|
total_npages = 0;
|
2022-03-24 17:34:49 +03:00
|
|
|
for_each_sgtable_dma_sg(userptr->sgt, sg, i) {
|
2021-07-29 11:44:28 +03:00
|
|
|
npages = hl_get_sg_info(sg, &dma_addr);
|
|
|
|
sg_start = userptr->addr +
|
|
|
|
total_npages * PAGE_SIZE;
|
|
|
|
sg_end = userptr->addr +
|
|
|
|
(total_npages + npages) * PAGE_SIZE;
|
|
|
|
|
|
|
|
if (dev_entry->userptr_lookup >= sg_start &&
|
|
|
|
dev_entry->userptr_lookup < sg_end) {
|
|
|
|
dma_addr += (dev_entry->userptr_lookup -
|
|
|
|
sg_start);
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
seq_puts(s, "\n");
|
|
|
|
seq_puts(s, " user virtual address dma address pid region start region size\n");
|
|
|
|
seq_puts(s, "---------------------------------------------------------------------------------------\n");
|
|
|
|
}
|
|
|
|
seq_printf(s, " 0x%-18llx 0x%-16llx %-8u 0x%-16llx %-12llu\n",
|
|
|
|
dev_entry->userptr_lookup,
|
|
|
|
(u64)dma_addr, userptr->pid,
|
|
|
|
userptr->addr, userptr->size);
|
|
|
|
}
|
|
|
|
total_npages += npages;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock(&dev_entry->userptr_spinlock);
|
|
|
|
|
|
|
|
if (!first)
|
|
|
|
seq_puts(s, "\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t userptr_lookup_write(struct file *file, const char __user *buf,
|
|
|
|
size_t count, loff_t *f_pos)
|
|
|
|
{
|
|
|
|
struct seq_file *s = file->private_data;
|
|
|
|
struct hl_debugfs_entry *entry = s->private;
|
|
|
|
struct hl_dbg_device_entry *dev_entry = entry->dev_entry;
|
|
|
|
ssize_t rc;
|
|
|
|
u64 value;
|
|
|
|
|
|
|
|
rc = kstrtoull_from_user(buf, count, 16, &value);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
dev_entry->userptr_lookup = value;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2019-02-16 01:39:24 +03:00
|
|
|
static int mmu_show(struct seq_file *s, void *data)
|
|
|
|
{
|
|
|
|
struct hl_debugfs_entry *entry = s->private;
|
|
|
|
struct hl_dbg_device_entry *dev_entry = entry->dev_entry;
|
|
|
|
struct hl_device *hdev = dev_entry->hdev;
|
2019-05-29 17:30:04 +03:00
|
|
|
struct hl_ctx *ctx;
|
2021-01-12 18:24:00 +03:00
|
|
|
struct hl_mmu_hop_info hops_info = {0};
|
|
|
|
u64 virt_addr = dev_entry->mmu_addr, phys_addr;
|
2020-10-27 11:55:42 +03:00
|
|
|
int i;
|
2019-02-16 01:39:24 +03:00
|
|
|
|
|
|
|
if (!hdev->mmu_enable)
|
|
|
|
return 0;
|
|
|
|
|
2019-05-29 17:30:04 +03:00
|
|
|
if (dev_entry->mmu_asid == HL_KERNEL_ASID_ID)
|
|
|
|
ctx = hdev->kernel_ctx;
|
|
|
|
else
|
2021-12-01 00:02:21 +03:00
|
|
|
ctx = hl_get_compute_ctx(hdev);
|
2019-05-29 17:30:04 +03:00
|
|
|
|
2019-02-16 01:39:24 +03:00
|
|
|
if (!ctx) {
|
|
|
|
dev_err(hdev->dev, "no ctx available\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-10-27 11:55:42 +03:00
|
|
|
if (hl_mmu_get_tlb_info(ctx, virt_addr, &hops_info)) {
|
|
|
|
dev_err(hdev->dev, "virt addr 0x%llx is not mapped to phys addr\n",
|
|
|
|
virt_addr);
|
2022-06-27 17:21:39 +03:00
|
|
|
goto put_ctx;
|
2019-02-16 01:39:24 +03:00
|
|
|
}
|
|
|
|
|
2021-07-29 11:54:50 +03:00
|
|
|
hl_mmu_va_to_pa(ctx, virt_addr, &phys_addr);
|
2021-01-12 18:24:00 +03:00
|
|
|
|
|
|
|
if (hops_info.scrambled_vaddr &&
|
|
|
|
(dev_entry->mmu_addr != hops_info.scrambled_vaddr))
|
|
|
|
seq_printf(s,
|
|
|
|
"asid: %u, virt_addr: 0x%llx, scrambled virt_addr: 0x%llx,\nphys_addr: 0x%llx, scrambled_phys_addr: 0x%llx\n",
|
|
|
|
dev_entry->mmu_asid, dev_entry->mmu_addr,
|
|
|
|
hops_info.scrambled_vaddr,
|
|
|
|
hops_info.unscrambled_paddr, phys_addr);
|
|
|
|
else
|
|
|
|
seq_printf(s,
|
|
|
|
"asid: %u, virt_addr: 0x%llx, phys_addr: 0x%llx\n",
|
|
|
|
dev_entry->mmu_asid, dev_entry->mmu_addr, phys_addr);
|
2019-02-16 01:39:24 +03:00
|
|
|
|
2020-10-27 11:55:42 +03:00
|
|
|
for (i = 0 ; i < hops_info.used_hops ; i++) {
|
|
|
|
seq_printf(s, "hop%d_addr: 0x%llx\n",
|
|
|
|
i, hops_info.hop_info[i].hop_addr);
|
|
|
|
seq_printf(s, "hop%d_pte_addr: 0x%llx\n",
|
|
|
|
i, hops_info.hop_info[i].hop_pte_addr);
|
|
|
|
seq_printf(s, "hop%d_pte: 0x%llx\n",
|
|
|
|
i, hops_info.hop_info[i].hop_pte_val);
|
2019-02-16 01:39:24 +03:00
|
|
|
}
|
|
|
|
|
2022-06-27 17:21:39 +03:00
|
|
|
put_ctx:
|
|
|
|
if (dev_entry->mmu_asid != HL_KERNEL_ASID_ID)
|
|
|
|
hl_ctx_put(ctx);
|
|
|
|
|
2019-02-16 01:39:24 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-06-07 08:21:48 +03:00
|
|
|
static ssize_t mmu_asid_va_write(struct file *file, const char __user *buf,
|
2019-02-16 01:39:24 +03:00
|
|
|
size_t count, loff_t *f_pos)
|
|
|
|
{
|
|
|
|
struct seq_file *s = file->private_data;
|
|
|
|
struct hl_debugfs_entry *entry = s->private;
|
|
|
|
struct hl_dbg_device_entry *dev_entry = entry->dev_entry;
|
|
|
|
struct hl_device *hdev = dev_entry->hdev;
|
2019-05-04 16:56:08 +03:00
|
|
|
char kbuf[MMU_KBUF_SIZE];
|
2019-02-16 01:39:24 +03:00
|
|
|
char *c;
|
|
|
|
ssize_t rc;
|
|
|
|
|
|
|
|
if (!hdev->mmu_enable)
|
|
|
|
return count;
|
|
|
|
|
2019-05-04 16:56:08 +03:00
|
|
|
if (count > sizeof(kbuf) - 1)
|
|
|
|
goto err;
|
2019-02-16 01:39:24 +03:00
|
|
|
if (copy_from_user(kbuf, buf, count))
|
|
|
|
goto err;
|
2019-05-04 16:56:08 +03:00
|
|
|
kbuf[count] = 0;
|
2019-02-16 01:39:24 +03:00
|
|
|
|
|
|
|
c = strchr(kbuf, ' ');
|
|
|
|
if (!c)
|
|
|
|
goto err;
|
2019-05-04 16:56:08 +03:00
|
|
|
*c = '\0';
|
2019-02-16 01:39:24 +03:00
|
|
|
|
2019-05-04 16:56:08 +03:00
|
|
|
rc = kstrtouint(kbuf, 10, &dev_entry->mmu_asid);
|
2019-02-16 01:39:24 +03:00
|
|
|
if (rc)
|
|
|
|
goto err;
|
|
|
|
|
2019-05-04 16:56:08 +03:00
|
|
|
if (strncmp(c+1, "0x", 2))
|
2019-02-16 01:39:24 +03:00
|
|
|
goto err;
|
2019-05-04 16:56:08 +03:00
|
|
|
rc = kstrtoull(c+3, 16, &dev_entry->mmu_addr);
|
2019-02-16 01:39:24 +03:00
|
|
|
if (rc)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
|
|
|
|
err:
|
|
|
|
dev_err(hdev->dev, "usage: echo <asid> <0xaddr> > mmu\n");
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2022-06-27 17:21:39 +03:00
|
|
|
static int mmu_ack_error(struct seq_file *s, void *data)
|
|
|
|
{
|
|
|
|
struct hl_debugfs_entry *entry = s->private;
|
|
|
|
struct hl_dbg_device_entry *dev_entry = entry->dev_entry;
|
|
|
|
struct hl_device *hdev = dev_entry->hdev;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (!hdev->mmu_enable)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!dev_entry->mmu_cap_mask) {
|
|
|
|
dev_err(hdev->dev, "mmu_cap_mask is not set\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = hdev->asic_funcs->ack_mmu_errors(hdev, dev_entry->mmu_cap_mask);
|
|
|
|
if (rc)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t mmu_ack_error_value_write(struct file *file,
|
|
|
|
const char __user *buf,
|
|
|
|
size_t count, loff_t *f_pos)
|
|
|
|
{
|
|
|
|
struct seq_file *s = file->private_data;
|
|
|
|
struct hl_debugfs_entry *entry = s->private;
|
|
|
|
struct hl_dbg_device_entry *dev_entry = entry->dev_entry;
|
|
|
|
struct hl_device *hdev = dev_entry->hdev;
|
|
|
|
char kbuf[MMU_KBUF_SIZE];
|
|
|
|
ssize_t rc;
|
|
|
|
|
|
|
|
if (!hdev->mmu_enable)
|
|
|
|
return count;
|
|
|
|
|
|
|
|
if (count > sizeof(kbuf) - 1)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (copy_from_user(kbuf, buf, count))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
kbuf[count] = 0;
|
|
|
|
|
|
|
|
if (strncmp(kbuf, "0x", 2))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
rc = kstrtoull(kbuf, 16, &dev_entry->mmu_cap_mask);
|
|
|
|
if (rc)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
err:
|
|
|
|
dev_err(hdev->dev, "usage: echo <0xmmu_cap_mask > > mmu_error\n");
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-07-01 16:59:45 +03:00
|
|
|
static int engines_show(struct seq_file *s, void *data)
|
|
|
|
{
|
|
|
|
struct hl_debugfs_entry *entry = s->private;
|
|
|
|
struct hl_dbg_device_entry *dev_entry = entry->dev_entry;
|
|
|
|
struct hl_device *hdev = dev_entry->hdev;
|
2022-07-03 17:40:57 +03:00
|
|
|
struct engines_data eng_data;
|
2019-07-01 16:59:45 +03:00
|
|
|
|
2021-11-23 16:15:22 +03:00
|
|
|
if (hdev->reset_info.in_reset) {
|
2019-11-18 10:41:08 +03:00
|
|
|
dev_warn_ratelimited(hdev->dev,
|
|
|
|
"Can't check device idle during reset\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-07-03 17:40:57 +03:00
|
|
|
eng_data.actual_size = 0;
|
2022-07-09 12:34:17 +03:00
|
|
|
eng_data.allocated_buf_size = HL_ENGINES_DATA_MAX_SIZE;
|
2022-07-03 17:40:57 +03:00
|
|
|
eng_data.buf = vmalloc(eng_data.allocated_buf_size);
|
|
|
|
if (!eng_data.buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
hdev->asic_funcs->is_device_idle(hdev, NULL, 0, &eng_data);
|
|
|
|
|
|
|
|
if (eng_data.actual_size > eng_data.allocated_buf_size) {
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"Engines data size (%d Bytes) is bigger than allocated size (%u Bytes)\n",
|
|
|
|
eng_data.actual_size, eng_data.allocated_buf_size);
|
|
|
|
vfree(eng_data.buf);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
seq_write(s, eng_data.buf, eng_data.actual_size);
|
|
|
|
|
|
|
|
vfree(eng_data.buf);
|
2019-07-01 16:59:45 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-04-11 17:11:23 +03:00
|
|
|
static ssize_t hl_memory_scrub(struct file *f, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
|
|
|
|
struct hl_device *hdev = entry->hdev;
|
2022-06-02 11:55:00 +03:00
|
|
|
u64 val = hdev->memory_scrub_val;
|
2022-04-11 17:11:23 +03:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (!hl_device_operational(hdev, NULL)) {
|
|
|
|
dev_warn_ratelimited(hdev->dev, "Can't scrub memory, device is not operational\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_lock(&hdev->fpriv_list_lock);
|
|
|
|
if (hdev->is_compute_ctx_active) {
|
|
|
|
mutex_unlock(&hdev->fpriv_list_lock);
|
|
|
|
dev_err(hdev->dev, "can't scrub dram, context exist\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
hdev->is_in_dram_scrub = true;
|
|
|
|
mutex_unlock(&hdev->fpriv_list_lock);
|
|
|
|
|
|
|
|
rc = hdev->asic_funcs->scrub_device_dram(hdev, val);
|
|
|
|
|
|
|
|
mutex_lock(&hdev->fpriv_list_lock);
|
|
|
|
hdev->is_in_dram_scrub = false;
|
|
|
|
mutex_unlock(&hdev->fpriv_list_lock);
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2019-06-16 16:48:29 +03:00
|
|
|
static bool hl_is_device_va(struct hl_device *hdev, u64 addr)
|
|
|
|
{
|
|
|
|
struct asic_fixed_properties *prop = &hdev->asic_prop;
|
|
|
|
|
|
|
|
if (!hdev->mmu_enable)
|
|
|
|
goto out;
|
|
|
|
|
2020-11-09 10:48:31 +03:00
|
|
|
if (prop->dram_supports_virtual_memory &&
|
2020-01-05 12:05:45 +03:00
|
|
|
(addr >= prop->dmmu.start_addr && addr < prop->dmmu.end_addr))
|
2019-06-16 16:48:29 +03:00
|
|
|
return true;
|
|
|
|
|
2020-01-05 12:05:45 +03:00
|
|
|
if (addr >= prop->pmmu.start_addr &&
|
|
|
|
addr < prop->pmmu.end_addr)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (addr >= prop->pmmu_huge.start_addr &&
|
|
|
|
addr < prop->pmmu_huge.end_addr)
|
2019-06-16 16:48:29 +03:00
|
|
|
return true;
|
|
|
|
out:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-04-02 01:43:18 +03:00
|
|
|
static bool hl_is_device_internal_memory_va(struct hl_device *hdev, u64 addr,
|
|
|
|
u32 size)
|
|
|
|
{
|
|
|
|
struct asic_fixed_properties *prop = &hdev->asic_prop;
|
|
|
|
u64 dram_start_addr, dram_end_addr;
|
|
|
|
|
|
|
|
if (!hdev->mmu_enable)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (prop->dram_supports_virtual_memory) {
|
|
|
|
dram_start_addr = prop->dmmu.start_addr;
|
|
|
|
dram_end_addr = prop->dmmu.end_addr;
|
|
|
|
} else {
|
|
|
|
dram_start_addr = prop->dram_base_address;
|
|
|
|
dram_end_addr = prop->dram_end_address;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hl_mem_area_inside_range(addr, size, dram_start_addr,
|
|
|
|
dram_end_addr))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (hl_mem_area_inside_range(addr, size, prop->sram_base_address,
|
|
|
|
prop->sram_end_address))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-02-24 12:51:40 +03:00
|
|
|
static int device_va_to_pa(struct hl_device *hdev, u64 virt_addr, u32 size,
|
|
|
|
u64 *phys_addr)
|
2019-03-12 14:53:17 +03:00
|
|
|
{
|
2021-02-24 12:51:40 +03:00
|
|
|
struct hl_vm_phys_pg_pack *phys_pg_pack;
|
2021-12-01 00:02:21 +03:00
|
|
|
struct hl_ctx *ctx;
|
2021-02-24 12:51:40 +03:00
|
|
|
struct hl_vm_hash_node *hnode;
|
2021-07-10 20:00:35 +03:00
|
|
|
u64 end_address, range_size;
|
2021-02-24 12:51:40 +03:00
|
|
|
struct hl_userptr *userptr;
|
2021-06-29 18:08:05 +03:00
|
|
|
enum vm_type *vm_type;
|
2021-02-24 12:51:40 +03:00
|
|
|
bool valid = false;
|
|
|
|
int i, rc = 0;
|
2019-03-12 14:53:17 +03:00
|
|
|
|
2021-12-01 00:02:21 +03:00
|
|
|
ctx = hl_get_compute_ctx(hdev);
|
|
|
|
|
2019-03-12 14:53:17 +03:00
|
|
|
if (!ctx) {
|
|
|
|
dev_err(hdev->dev, "no ctx available\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2021-02-24 12:51:40 +03:00
|
|
|
/* Verify address is mapped */
|
|
|
|
mutex_lock(&ctx->mem_hash_lock);
|
|
|
|
hash_for_each(ctx->mem_hash, i, hnode, node) {
|
|
|
|
vm_type = hnode->ptr;
|
|
|
|
|
|
|
|
if (*vm_type == VM_TYPE_USERPTR) {
|
|
|
|
userptr = hnode->ptr;
|
|
|
|
range_size = userptr->size;
|
|
|
|
} else {
|
|
|
|
phys_pg_pack = hnode->ptr;
|
|
|
|
range_size = phys_pg_pack->total_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
end_address = virt_addr + size;
|
|
|
|
if ((virt_addr >= hnode->vaddr) &&
|
|
|
|
(end_address <= hnode->vaddr + range_size)) {
|
|
|
|
valid = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mutex_unlock(&ctx->mem_hash_lock);
|
|
|
|
|
|
|
|
if (!valid) {
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"virt addr 0x%llx is not mapped\n",
|
|
|
|
virt_addr);
|
2022-06-27 17:21:39 +03:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto put_ctx;
|
2021-02-24 12:51:40 +03:00
|
|
|
}
|
|
|
|
|
2020-10-27 11:55:42 +03:00
|
|
|
rc = hl_mmu_va_to_pa(ctx, virt_addr, phys_addr);
|
|
|
|
if (rc) {
|
2021-02-24 12:51:40 +03:00
|
|
|
dev_err(hdev->dev,
|
|
|
|
"virt addr 0x%llx is not mapped to phys addr\n",
|
|
|
|
virt_addr);
|
2020-10-27 11:55:42 +03:00
|
|
|
rc = -EINVAL;
|
2019-03-12 14:53:17 +03:00
|
|
|
}
|
|
|
|
|
2022-06-27 17:21:39 +03:00
|
|
|
put_ctx:
|
|
|
|
hl_ctx_put(ctx);
|
|
|
|
|
2019-03-12 14:53:17 +03:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2022-03-23 18:21:56 +03:00
|
|
|
static int hl_access_dev_mem_by_region(struct hl_device *hdev, u64 addr,
|
|
|
|
u64 *val, enum debugfs_access_type acc_type, bool *found)
|
|
|
|
{
|
|
|
|
size_t acc_size = (acc_type == DEBUGFS_READ64 || acc_type == DEBUGFS_WRITE64) ?
|
|
|
|
sizeof(u64) : sizeof(u32);
|
|
|
|
struct pci_mem_region *mem_reg;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < PCI_REGION_NUMBER; i++) {
|
|
|
|
mem_reg = &hdev->pci_mem_region[i];
|
|
|
|
if (!mem_reg->used)
|
|
|
|
continue;
|
|
|
|
if (addr >= mem_reg->region_base &&
|
|
|
|
addr <= mem_reg->region_base + mem_reg->region_size - acc_size) {
|
|
|
|
*found = true;
|
2022-06-27 16:59:02 +03:00
|
|
|
return hdev->asic_funcs->access_dev_mem(hdev, i, addr, val, acc_type);
|
2022-03-23 18:21:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hl_access_host_mem(struct hl_device *hdev, u64 addr, u64 *val,
|
|
|
|
enum debugfs_access_type acc_type)
|
|
|
|
{
|
|
|
|
struct asic_fixed_properties *prop = &hdev->asic_prop;
|
|
|
|
u64 offset = prop->device_dma_offset_for_host_access;
|
|
|
|
|
|
|
|
switch (acc_type) {
|
|
|
|
case DEBUGFS_READ32:
|
|
|
|
*val = *(u32 *) phys_to_virt(addr - offset);
|
|
|
|
break;
|
|
|
|
case DEBUGFS_WRITE32:
|
|
|
|
*(u32 *) phys_to_virt(addr - offset) = *val;
|
|
|
|
break;
|
|
|
|
case DEBUGFS_READ64:
|
|
|
|
*val = *(u64 *) phys_to_virt(addr - offset);
|
|
|
|
break;
|
|
|
|
case DEBUGFS_WRITE64:
|
|
|
|
*(u64 *) phys_to_virt(addr - offset) = *val;
|
|
|
|
break;
|
2022-04-05 11:45:51 +03:00
|
|
|
default:
|
|
|
|
dev_err(hdev->dev, "hostmem access-type %d id not supported\n", acc_type);
|
|
|
|
break;
|
2022-03-23 18:21:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hl_access_mem(struct hl_device *hdev, u64 addr, u64 *val,
|
2022-06-27 17:21:39 +03:00
|
|
|
enum debugfs_access_type acc_type)
|
2022-03-23 18:21:56 +03:00
|
|
|
{
|
|
|
|
size_t acc_size = (acc_type == DEBUGFS_READ64 || acc_type == DEBUGFS_WRITE64) ?
|
|
|
|
sizeof(u64) : sizeof(u32);
|
|
|
|
u64 host_start = hdev->asic_prop.host_base_address;
|
|
|
|
u64 host_end = hdev->asic_prop.host_end_address;
|
|
|
|
bool user_address, found = false;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
user_address = hl_is_device_va(hdev, addr);
|
|
|
|
if (user_address) {
|
|
|
|
rc = device_va_to_pa(hdev, addr, acc_size, &addr);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = hl_access_dev_mem_by_region(hdev, addr, val, acc_type, &found);
|
|
|
|
if (rc) {
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"Failed reading addr %#llx from dev mem (%d)\n",
|
|
|
|
addr, rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
return 0;
|
|
|
|
|
2022-04-11 15:36:32 +03:00
|
|
|
if (!user_address || device_iommu_mapped(&hdev->pdev->dev)) {
|
2022-03-23 18:21:56 +03:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addr >= host_start && addr <= host_end - acc_size) {
|
|
|
|
hl_access_host_mem(hdev, addr, val, acc_type);
|
|
|
|
} else {
|
|
|
|
rc = -EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
dev_err(hdev->dev, "invalid addr %#llx\n", addr);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2019-02-16 01:39:24 +03:00
|
|
|
static ssize_t hl_data_read32(struct file *f, char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
|
|
|
|
struct hl_device *hdev = entry->hdev;
|
2022-03-23 18:21:56 +03:00
|
|
|
u64 value64, addr = entry->addr;
|
2021-02-24 12:51:40 +03:00
|
|
|
char tmp_buf[32];
|
2019-02-16 01:39:24 +03:00
|
|
|
ssize_t rc;
|
2021-02-24 12:51:40 +03:00
|
|
|
u32 val;
|
2019-02-16 01:39:24 +03:00
|
|
|
|
2021-11-23 16:15:22 +03:00
|
|
|
if (hdev->reset_info.in_reset) {
|
2019-11-18 10:41:08 +03:00
|
|
|
dev_warn_ratelimited(hdev->dev, "Can't read during reset\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-02-16 01:39:24 +03:00
|
|
|
if (*ppos)
|
|
|
|
return 0;
|
|
|
|
|
2022-03-23 18:21:56 +03:00
|
|
|
rc = hl_access_mem(hdev, addr, &value64, DEBUGFS_READ32);
|
|
|
|
if (rc)
|
2019-02-16 01:39:24 +03:00
|
|
|
return rc;
|
2022-03-23 18:21:56 +03:00
|
|
|
|
|
|
|
val = value64; /* downcast back to 32 */
|
2019-02-16 01:39:24 +03:00
|
|
|
|
|
|
|
sprintf(tmp_buf, "0x%08x\n", val);
|
2019-05-04 16:56:08 +03:00
|
|
|
return simple_read_from_buffer(buf, count, ppos, tmp_buf,
|
|
|
|
strlen(tmp_buf));
|
2019-02-16 01:39:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t hl_data_write32(struct file *f, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
|
|
|
|
struct hl_device *hdev = entry->hdev;
|
2022-03-23 18:21:56 +03:00
|
|
|
u64 value64, addr = entry->addr;
|
2019-02-16 01:39:24 +03:00
|
|
|
u32 value;
|
|
|
|
ssize_t rc;
|
|
|
|
|
2021-11-23 16:15:22 +03:00
|
|
|
if (hdev->reset_info.in_reset) {
|
2019-11-18 10:41:08 +03:00
|
|
|
dev_warn_ratelimited(hdev->dev, "Can't write during reset\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-02-16 01:39:24 +03:00
|
|
|
rc = kstrtouint_from_user(buf, count, 16, &value);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2022-03-23 18:21:56 +03:00
|
|
|
value64 = value;
|
|
|
|
rc = hl_access_mem(hdev, addr, &value64, DEBUGFS_WRITE32);
|
|
|
|
if (rc)
|
2019-02-16 01:39:24 +03:00
|
|
|
return rc;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2019-11-12 10:40:11 +03:00
|
|
|
static ssize_t hl_data_read64(struct file *f, char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
|
|
|
|
struct hl_device *hdev = entry->hdev;
|
|
|
|
u64 addr = entry->addr;
|
2021-02-24 12:51:40 +03:00
|
|
|
char tmp_buf[32];
|
2019-11-12 10:40:11 +03:00
|
|
|
ssize_t rc;
|
2021-02-24 12:51:40 +03:00
|
|
|
u64 val;
|
2019-11-12 10:40:11 +03:00
|
|
|
|
2021-11-23 16:15:22 +03:00
|
|
|
if (hdev->reset_info.in_reset) {
|
2021-04-02 01:43:18 +03:00
|
|
|
dev_warn_ratelimited(hdev->dev, "Can't read during reset\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-11-12 10:40:11 +03:00
|
|
|
if (*ppos)
|
|
|
|
return 0;
|
|
|
|
|
2022-03-23 18:21:56 +03:00
|
|
|
rc = hl_access_mem(hdev, addr, &val, DEBUGFS_READ64);
|
|
|
|
if (rc)
|
2019-11-12 10:40:11 +03:00
|
|
|
return rc;
|
|
|
|
|
|
|
|
sprintf(tmp_buf, "0x%016llx\n", val);
|
|
|
|
return simple_read_from_buffer(buf, count, ppos, tmp_buf,
|
|
|
|
strlen(tmp_buf));
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t hl_data_write64(struct file *f, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
|
|
|
|
struct hl_device *hdev = entry->hdev;
|
|
|
|
u64 addr = entry->addr;
|
|
|
|
u64 value;
|
|
|
|
ssize_t rc;
|
|
|
|
|
2021-11-23 16:15:22 +03:00
|
|
|
if (hdev->reset_info.in_reset) {
|
2021-04-02 01:43:18 +03:00
|
|
|
dev_warn_ratelimited(hdev->dev, "Can't write during reset\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-11-12 10:40:11 +03:00
|
|
|
rc = kstrtoull_from_user(buf, count, 16, &value);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2022-03-23 18:21:56 +03:00
|
|
|
rc = hl_access_mem(hdev, addr, &value, DEBUGFS_WRITE64);
|
|
|
|
if (rc)
|
2019-11-12 10:40:11 +03:00
|
|
|
return rc;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2021-04-02 01:43:18 +03:00
|
|
|
static ssize_t hl_dma_size_write(struct file *f, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
|
|
|
|
struct hl_device *hdev = entry->hdev;
|
|
|
|
u64 addr = entry->addr;
|
|
|
|
ssize_t rc;
|
|
|
|
u32 size;
|
|
|
|
|
2021-11-23 16:15:22 +03:00
|
|
|
if (hdev->reset_info.in_reset) {
|
2021-04-02 01:43:18 +03:00
|
|
|
dev_warn_ratelimited(hdev->dev, "Can't DMA during reset\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
rc = kstrtouint_from_user(buf, count, 16, &size);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
if (!size) {
|
|
|
|
dev_err(hdev->dev, "DMA read failed. size can't be 0\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size > SZ_128M) {
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"DMA read failed. size can't be larger than 128MB\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hl_is_device_internal_memory_va(hdev, addr, size)) {
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"DMA read failed. Invalid 0x%010llx + 0x%08x\n",
|
|
|
|
addr, size);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free the previous allocation, if there was any */
|
2022-03-22 15:32:40 +03:00
|
|
|
entry->data_dma_blob_desc.size = 0;
|
|
|
|
vfree(entry->data_dma_blob_desc.data);
|
2021-04-02 01:43:18 +03:00
|
|
|
|
2022-03-22 15:32:40 +03:00
|
|
|
entry->data_dma_blob_desc.data = vmalloc(size);
|
|
|
|
if (!entry->data_dma_blob_desc.data)
|
2021-04-02 01:43:18 +03:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
rc = hdev->asic_funcs->debugfs_read_dma(hdev, addr, size,
|
2022-03-22 15:32:40 +03:00
|
|
|
entry->data_dma_blob_desc.data);
|
2021-04-02 01:43:18 +03:00
|
|
|
if (rc) {
|
|
|
|
dev_err(hdev->dev, "Failed to DMA from 0x%010llx\n", addr);
|
2022-03-22 15:32:40 +03:00
|
|
|
vfree(entry->data_dma_blob_desc.data);
|
|
|
|
entry->data_dma_blob_desc.data = NULL;
|
2021-04-02 01:43:18 +03:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:32:40 +03:00
|
|
|
entry->data_dma_blob_desc.size = size;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t hl_monitor_dump_trigger(struct file *f, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
|
|
|
|
struct hl_device *hdev = entry->hdev;
|
|
|
|
u32 size, trig;
|
|
|
|
ssize_t rc;
|
|
|
|
|
|
|
|
if (hdev->reset_info.in_reset) {
|
|
|
|
dev_warn_ratelimited(hdev->dev, "Can't dump monitors during reset\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
rc = kstrtouint_from_user(buf, count, 10, &trig);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
if (trig != 1) {
|
|
|
|
dev_err(hdev->dev, "Must write 1 to trigger monitor dump\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = sizeof(struct cpucp_monitor_dump);
|
|
|
|
|
|
|
|
/* Free the previous allocation, if there was any */
|
|
|
|
entry->mon_dump_blob_desc.size = 0;
|
|
|
|
vfree(entry->mon_dump_blob_desc.data);
|
|
|
|
|
|
|
|
entry->mon_dump_blob_desc.data = vmalloc(size);
|
|
|
|
if (!entry->mon_dump_blob_desc.data)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
rc = hdev->asic_funcs->get_monitor_dump(hdev, entry->mon_dump_blob_desc.data);
|
|
|
|
if (rc) {
|
|
|
|
dev_err(hdev->dev, "Failed to dump monitors\n");
|
|
|
|
vfree(entry->mon_dump_blob_desc.data);
|
|
|
|
entry->mon_dump_blob_desc.data = NULL;
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
entry->mon_dump_blob_desc.size = size;
|
2021-04-02 01:43:18 +03:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2019-02-16 01:39:24 +03:00
|
|
|
static ssize_t hl_get_power_state(struct file *f, char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
|
|
|
|
struct hl_device *hdev = entry->hdev;
|
|
|
|
char tmp_buf[200];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (*ppos)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (hdev->pdev->current_state == PCI_D0)
|
|
|
|
i = 1;
|
|
|
|
else if (hdev->pdev->current_state == PCI_D3hot)
|
|
|
|
i = 2;
|
|
|
|
else
|
|
|
|
i = 3;
|
|
|
|
|
|
|
|
sprintf(tmp_buf,
|
|
|
|
"current power state: %d\n1 - D0\n2 - D3hot\n3 - Unknown\n", i);
|
2019-05-04 16:56:08 +03:00
|
|
|
return simple_read_from_buffer(buf, count, ppos, tmp_buf,
|
|
|
|
strlen(tmp_buf));
|
2019-02-16 01:39:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t hl_set_power_state(struct file *f, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
|
|
|
|
struct hl_device *hdev = entry->hdev;
|
|
|
|
u32 value;
|
|
|
|
ssize_t rc;
|
|
|
|
|
|
|
|
rc = kstrtouint_from_user(buf, count, 10, &value);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
if (value == 1) {
|
|
|
|
pci_set_power_state(hdev->pdev, PCI_D0);
|
|
|
|
pci_restore_state(hdev->pdev);
|
|
|
|
rc = pci_enable_device(hdev->pdev);
|
2022-02-24 09:58:05 +03:00
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
2019-02-16 01:39:24 +03:00
|
|
|
} else if (value == 2) {
|
|
|
|
pci_save_state(hdev->pdev);
|
|
|
|
pci_disable_device(hdev->pdev);
|
|
|
|
pci_set_power_state(hdev->pdev, PCI_D3hot);
|
|
|
|
} else {
|
|
|
|
dev_dbg(hdev->dev, "invalid power state value %u\n", value);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t hl_i2c_data_read(struct file *f, char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
|
|
|
|
struct hl_device *hdev = entry->hdev;
|
|
|
|
char tmp_buf[32];
|
2021-10-12 20:52:46 +03:00
|
|
|
u64 val;
|
2019-02-16 01:39:24 +03:00
|
|
|
ssize_t rc;
|
|
|
|
|
|
|
|
if (*ppos)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
rc = hl_debugfs_i2c_read(hdev, entry->i2c_bus, entry->i2c_addr,
|
2021-10-12 20:52:46 +03:00
|
|
|
entry->i2c_reg, entry->i2c_len, &val);
|
2019-02-16 01:39:24 +03:00
|
|
|
if (rc) {
|
|
|
|
dev_err(hdev->dev,
|
2021-10-12 20:52:46 +03:00
|
|
|
"Failed to read from I2C bus %d, addr %d, reg %d, len %d\n",
|
|
|
|
entry->i2c_bus, entry->i2c_addr, entry->i2c_reg, entry->i2c_len);
|
2019-02-16 01:39:24 +03:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2021-10-12 20:52:46 +03:00
|
|
|
sprintf(tmp_buf, "%#02llx\n", val);
|
2019-05-04 16:56:08 +03:00
|
|
|
rc = simple_read_from_buffer(buf, count, ppos, tmp_buf,
|
|
|
|
strlen(tmp_buf));
|
2019-02-16 01:39:24 +03:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t hl_i2c_data_write(struct file *f, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
|
|
|
|
struct hl_device *hdev = entry->hdev;
|
2021-10-12 20:52:46 +03:00
|
|
|
u64 value;
|
2019-02-16 01:39:24 +03:00
|
|
|
ssize_t rc;
|
|
|
|
|
2021-10-12 20:52:46 +03:00
|
|
|
rc = kstrtou64_from_user(buf, count, 16, &value);
|
2019-02-16 01:39:24 +03:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
rc = hl_debugfs_i2c_write(hdev, entry->i2c_bus, entry->i2c_addr,
|
2021-10-12 20:52:46 +03:00
|
|
|
entry->i2c_reg, entry->i2c_len, value);
|
2019-02-16 01:39:24 +03:00
|
|
|
if (rc) {
|
|
|
|
dev_err(hdev->dev,
|
2021-10-12 20:52:46 +03:00
|
|
|
"Failed to write %#02llx to I2C bus %d, addr %d, reg %d, len %d\n",
|
|
|
|
value, entry->i2c_bus, entry->i2c_addr, entry->i2c_reg, entry->i2c_len);
|
2019-02-16 01:39:24 +03:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t hl_led0_write(struct file *f, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
|
|
|
|
struct hl_device *hdev = entry->hdev;
|
|
|
|
u32 value;
|
|
|
|
ssize_t rc;
|
|
|
|
|
|
|
|
rc = kstrtouint_from_user(buf, count, 10, &value);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
value = value ? 1 : 0;
|
|
|
|
|
|
|
|
hl_debugfs_led_set(hdev, 0, value);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t hl_led1_write(struct file *f, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
|
|
|
|
struct hl_device *hdev = entry->hdev;
|
|
|
|
u32 value;
|
|
|
|
ssize_t rc;
|
|
|
|
|
|
|
|
rc = kstrtouint_from_user(buf, count, 10, &value);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
value = value ? 1 : 0;
|
|
|
|
|
|
|
|
hl_debugfs_led_set(hdev, 1, value);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t hl_led2_write(struct file *f, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
|
|
|
|
struct hl_device *hdev = entry->hdev;
|
|
|
|
u32 value;
|
|
|
|
ssize_t rc;
|
|
|
|
|
|
|
|
rc = kstrtouint_from_user(buf, count, 10, &value);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
value = value ? 1 : 0;
|
|
|
|
|
|
|
|
hl_debugfs_led_set(hdev, 2, value);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t hl_device_read(struct file *f, char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
2019-05-04 16:56:08 +03:00
|
|
|
static const char *help =
|
|
|
|
"Valid values: disable, enable, suspend, resume, cpu_timeout\n";
|
|
|
|
return simple_read_from_buffer(buf, count, ppos, help, strlen(help));
|
2019-02-16 01:39:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t hl_device_write(struct file *f, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
|
|
|
|
struct hl_device *hdev = entry->hdev;
|
2019-05-04 16:56:08 +03:00
|
|
|
char data[30] = {0};
|
2019-02-16 01:39:24 +03:00
|
|
|
|
|
|
|
/* don't allow partial writes */
|
|
|
|
if (*ppos != 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
simple_write_to_buffer(data, 29, ppos, buf, count);
|
|
|
|
|
|
|
|
if (strncmp("disable", data, strlen("disable")) == 0) {
|
|
|
|
hdev->disabled = true;
|
|
|
|
} else if (strncmp("enable", data, strlen("enable")) == 0) {
|
|
|
|
hdev->disabled = false;
|
|
|
|
} else if (strncmp("suspend", data, strlen("suspend")) == 0) {
|
|
|
|
hdev->asic_funcs->suspend(hdev);
|
|
|
|
} else if (strncmp("resume", data, strlen("resume")) == 0) {
|
|
|
|
hdev->asic_funcs->resume(hdev);
|
2019-02-28 11:46:12 +03:00
|
|
|
} else if (strncmp("cpu_timeout", data, strlen("cpu_timeout")) == 0) {
|
|
|
|
hdev->device_cpu_disabled = true;
|
2019-02-16 01:39:24 +03:00
|
|
|
} else {
|
|
|
|
dev_err(hdev->dev,
|
2019-02-28 11:46:12 +03:00
|
|
|
"Valid values: disable, enable, suspend, resume, cpu_timeout\n");
|
2019-02-16 01:39:24 +03:00
|
|
|
count = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2020-05-09 12:17:21 +03:00
|
|
|
static ssize_t hl_clk_gate_read(struct file *f, char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
2022-01-06 00:14:45 +03:00
|
|
|
return 0;
|
2020-05-09 12:17:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t hl_clk_gate_write(struct file *f, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2020-03-22 22:12:51 +03:00
|
|
|
static ssize_t hl_stop_on_err_read(struct file *f, char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
|
|
|
|
struct hl_device *hdev = entry->hdev;
|
|
|
|
char tmp_buf[200];
|
|
|
|
ssize_t rc;
|
|
|
|
|
2022-01-12 21:08:01 +03:00
|
|
|
if (!hdev->asic_prop.configurable_stop_on_err)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2020-03-22 22:12:51 +03:00
|
|
|
if (*ppos)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
sprintf(tmp_buf, "%d\n", hdev->stop_on_err);
|
|
|
|
rc = simple_read_from_buffer(buf, strlen(tmp_buf) + 1, ppos, tmp_buf,
|
|
|
|
strlen(tmp_buf) + 1);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t hl_stop_on_err_write(struct file *f, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
|
|
|
|
struct hl_device *hdev = entry->hdev;
|
|
|
|
u32 value;
|
|
|
|
ssize_t rc;
|
|
|
|
|
2022-01-12 21:08:01 +03:00
|
|
|
if (!hdev->asic_prop.configurable_stop_on_err)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2021-11-23 16:15:22 +03:00
|
|
|
if (hdev->reset_info.in_reset) {
|
2020-03-22 22:12:51 +03:00
|
|
|
dev_warn_ratelimited(hdev->dev,
|
|
|
|
"Can't change stop on error during reset\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = kstrtouint_from_user(buf, count, 10, &value);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
hdev->stop_on_err = value ? 1 : 0;
|
|
|
|
|
2021-02-17 21:42:48 +03:00
|
|
|
hl_device_reset(hdev, 0);
|
2020-03-22 22:12:51 +03:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2021-01-07 13:14:17 +03:00
|
|
|
static ssize_t hl_security_violations_read(struct file *f, char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
|
|
|
|
struct hl_device *hdev = entry->hdev;
|
|
|
|
|
|
|
|
hdev->asic_funcs->ack_protection_bits_errors(hdev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-06-06 10:28:51 +03:00
|
|
|
static ssize_t hl_state_dump_read(struct file *f, char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
|
|
|
|
ssize_t rc;
|
|
|
|
|
|
|
|
down_read(&entry->state_dump_sem);
|
|
|
|
if (!entry->state_dump[entry->state_dump_head])
|
|
|
|
rc = 0;
|
|
|
|
else
|
|
|
|
rc = simple_read_from_buffer(
|
|
|
|
buf, count, ppos,
|
|
|
|
entry->state_dump[entry->state_dump_head],
|
|
|
|
strlen(entry->state_dump[entry->state_dump_head]));
|
|
|
|
up_read(&entry->state_dump_sem);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t hl_state_dump_write(struct file *f, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
|
|
|
|
struct hl_device *hdev = entry->hdev;
|
|
|
|
ssize_t rc;
|
|
|
|
u32 size;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
rc = kstrtouint_from_user(buf, count, 10, &size);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
if (size <= 0 || size >= ARRAY_SIZE(entry->state_dump)) {
|
|
|
|
dev_err(hdev->dev, "Invalid number of dumps to skip\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entry->state_dump[entry->state_dump_head]) {
|
|
|
|
down_write(&entry->state_dump_sem);
|
|
|
|
for (i = 0; i < size; ++i) {
|
|
|
|
vfree(entry->state_dump[entry->state_dump_head]);
|
|
|
|
entry->state_dump[entry->state_dump_head] = NULL;
|
|
|
|
if (entry->state_dump_head > 0)
|
|
|
|
entry->state_dump_head--;
|
|
|
|
else
|
|
|
|
entry->state_dump_head =
|
|
|
|
ARRAY_SIZE(entry->state_dump) - 1;
|
|
|
|
}
|
|
|
|
up_write(&entry->state_dump_sem);
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2021-09-02 10:18:01 +03:00
|
|
|
static ssize_t hl_timeout_locked_read(struct file *f, char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
|
|
|
|
struct hl_device *hdev = entry->hdev;
|
|
|
|
char tmp_buf[200];
|
|
|
|
ssize_t rc;
|
|
|
|
|
|
|
|
if (*ppos)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
sprintf(tmp_buf, "%d\n",
|
|
|
|
jiffies_to_msecs(hdev->timeout_jiffies) / 1000);
|
|
|
|
rc = simple_read_from_buffer(buf, strlen(tmp_buf) + 1, ppos, tmp_buf,
|
|
|
|
strlen(tmp_buf) + 1);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t hl_timeout_locked_write(struct file *f, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
|
|
|
|
struct hl_device *hdev = entry->hdev;
|
|
|
|
u32 value;
|
|
|
|
ssize_t rc;
|
|
|
|
|
|
|
|
rc = kstrtouint_from_user(buf, count, 10, &value);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
hdev->timeout_jiffies = msecs_to_jiffies(value * 1000);
|
|
|
|
else
|
|
|
|
hdev->timeout_jiffies = MAX_SCHEDULE_TIMEOUT;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2022-06-26 18:20:03 +03:00
|
|
|
static ssize_t hl_check_razwi_happened(struct file *f, char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
|
|
|
|
struct hl_device *hdev = entry->hdev;
|
|
|
|
|
|
|
|
hdev->asic_funcs->check_if_razwi_happened(hdev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-04-11 17:11:23 +03:00
|
|
|
static const struct file_operations hl_mem_scrub_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.write = hl_memory_scrub,
|
|
|
|
};
|
|
|
|
|
2019-02-16 01:39:24 +03:00
|
|
|
static const struct file_operations hl_data32b_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.read = hl_data_read32,
|
|
|
|
.write = hl_data_write32
|
|
|
|
};
|
|
|
|
|
2019-11-12 10:40:11 +03:00
|
|
|
static const struct file_operations hl_data64b_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.read = hl_data_read64,
|
|
|
|
.write = hl_data_write64
|
|
|
|
};
|
|
|
|
|
2021-04-02 01:43:18 +03:00
|
|
|
static const struct file_operations hl_dma_size_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.write = hl_dma_size_write
|
|
|
|
};
|
|
|
|
|
2022-03-22 15:32:40 +03:00
|
|
|
static const struct file_operations hl_monitor_dump_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.write = hl_monitor_dump_trigger
|
|
|
|
};
|
|
|
|
|
2019-02-16 01:39:24 +03:00
|
|
|
static const struct file_operations hl_i2c_data_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.read = hl_i2c_data_read,
|
|
|
|
.write = hl_i2c_data_write
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct file_operations hl_power_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.read = hl_get_power_state,
|
|
|
|
.write = hl_set_power_state
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct file_operations hl_led0_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.write = hl_led0_write
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct file_operations hl_led1_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.write = hl_led1_write
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct file_operations hl_led2_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.write = hl_led2_write
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct file_operations hl_device_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.read = hl_device_read,
|
|
|
|
.write = hl_device_write
|
|
|
|
};
|
|
|
|
|
2020-05-09 12:17:21 +03:00
|
|
|
static const struct file_operations hl_clk_gate_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.read = hl_clk_gate_read,
|
|
|
|
.write = hl_clk_gate_write
|
|
|
|
};
|
|
|
|
|
2020-03-22 22:12:51 +03:00
|
|
|
static const struct file_operations hl_stop_on_err_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.read = hl_stop_on_err_read,
|
|
|
|
.write = hl_stop_on_err_write
|
|
|
|
};
|
|
|
|
|
2021-01-07 13:14:17 +03:00
|
|
|
static const struct file_operations hl_security_violations_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.read = hl_security_violations_read
|
|
|
|
};
|
|
|
|
|
2021-06-06 10:28:51 +03:00
|
|
|
static const struct file_operations hl_state_dump_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.read = hl_state_dump_read,
|
|
|
|
.write = hl_state_dump_write
|
|
|
|
};
|
|
|
|
|
2021-09-02 10:18:01 +03:00
|
|
|
static const struct file_operations hl_timeout_locked_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.read = hl_timeout_locked_read,
|
|
|
|
.write = hl_timeout_locked_write
|
|
|
|
};
|
|
|
|
|
2022-06-26 18:20:03 +03:00
|
|
|
static const struct file_operations hl_razwi_check_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.read = hl_check_razwi_happened
|
|
|
|
};
|
|
|
|
|
2019-02-16 01:39:24 +03:00
|
|
|
static const struct hl_info_list hl_debugfs_list[] = {
|
|
|
|
{"command_buffers", command_buffers_show, NULL},
|
|
|
|
{"command_submission", command_submission_show, NULL},
|
|
|
|
{"command_submission_jobs", command_submission_jobs_show, NULL},
|
|
|
|
{"userptr", userptr_show, NULL},
|
|
|
|
{"vm", vm_show, NULL},
|
2021-07-29 11:44:28 +03:00
|
|
|
{"userptr_lookup", userptr_lookup_show, userptr_lookup_write},
|
2020-06-07 08:21:48 +03:00
|
|
|
{"mmu", mmu_show, mmu_asid_va_write},
|
2022-06-27 17:21:39 +03:00
|
|
|
{"mmu_error", mmu_ack_error, mmu_ack_error_value_write},
|
|
|
|
{"engines", engines_show, NULL},
|
2019-02-16 01:39:24 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static int hl_debugfs_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
struct hl_debugfs_entry *node = inode->i_private;
|
|
|
|
|
|
|
|
return single_open(file, node->info_ent->show, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t hl_debugfs_write(struct file *file, const char __user *buf,
|
|
|
|
size_t count, loff_t *f_pos)
|
|
|
|
{
|
|
|
|
struct hl_debugfs_entry *node = file->f_inode->i_private;
|
|
|
|
|
|
|
|
if (node->info_ent->write)
|
|
|
|
return node->info_ent->write(file, buf, count, f_pos);
|
|
|
|
else
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations hl_debugfs_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = hl_debugfs_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.write = hl_debugfs_write,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = single_release,
|
|
|
|
};
|
|
|
|
|
2023-01-23 00:04:10 +03:00
|
|
|
static void add_secured_nodes(struct hl_dbg_device_entry *dev_entry, struct dentry *root)
|
2022-06-30 09:54:59 +03:00
|
|
|
{
|
|
|
|
debugfs_create_u8("i2c_bus",
|
|
|
|
0644,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2022-06-30 09:54:59 +03:00
|
|
|
&dev_entry->i2c_bus);
|
|
|
|
|
|
|
|
debugfs_create_u8("i2c_addr",
|
|
|
|
0644,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2022-06-30 09:54:59 +03:00
|
|
|
&dev_entry->i2c_addr);
|
|
|
|
|
|
|
|
debugfs_create_u8("i2c_reg",
|
|
|
|
0644,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2022-06-30 09:54:59 +03:00
|
|
|
&dev_entry->i2c_reg);
|
|
|
|
|
|
|
|
debugfs_create_u8("i2c_len",
|
|
|
|
0644,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2022-06-30 09:54:59 +03:00
|
|
|
&dev_entry->i2c_len);
|
|
|
|
|
|
|
|
debugfs_create_file("i2c_data",
|
|
|
|
0644,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2022-06-30 09:54:59 +03:00
|
|
|
dev_entry,
|
|
|
|
&hl_i2c_data_fops);
|
|
|
|
|
|
|
|
debugfs_create_file("led0",
|
|
|
|
0200,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2022-06-30 09:54:59 +03:00
|
|
|
dev_entry,
|
|
|
|
&hl_led0_fops);
|
|
|
|
|
|
|
|
debugfs_create_file("led1",
|
|
|
|
0200,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2022-06-30 09:54:59 +03:00
|
|
|
dev_entry,
|
|
|
|
&hl_led1_fops);
|
|
|
|
|
|
|
|
debugfs_create_file("led2",
|
|
|
|
0200,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2022-06-30 09:54:59 +03:00
|
|
|
dev_entry,
|
|
|
|
&hl_led2_fops);
|
|
|
|
}
|
|
|
|
|
2023-01-23 00:04:10 +03:00
|
|
|
static void add_files_to_device(struct hl_device *hdev, struct hl_dbg_device_entry *dev_entry,
|
|
|
|
struct dentry *root)
|
2019-02-16 01:39:24 +03:00
|
|
|
{
|
|
|
|
int count = ARRAY_SIZE(hl_debugfs_list);
|
|
|
|
struct hl_debugfs_entry *entry;
|
|
|
|
int i;
|
|
|
|
|
2022-04-11 17:11:23 +03:00
|
|
|
debugfs_create_x64("memory_scrub_val",
|
|
|
|
0644,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2022-06-02 11:55:00 +03:00
|
|
|
&hdev->memory_scrub_val);
|
2022-04-11 17:11:23 +03:00
|
|
|
|
|
|
|
debugfs_create_file("memory_scrub",
|
|
|
|
0200,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2022-04-11 17:11:23 +03:00
|
|
|
dev_entry,
|
|
|
|
&hl_mem_scrub_fops);
|
|
|
|
|
2019-02-16 01:39:24 +03:00
|
|
|
debugfs_create_x64("addr",
|
|
|
|
0644,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2019-02-16 01:39:24 +03:00
|
|
|
&dev_entry->addr);
|
|
|
|
|
|
|
|
debugfs_create_file("data32",
|
|
|
|
0644,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2019-02-16 01:39:24 +03:00
|
|
|
dev_entry,
|
|
|
|
&hl_data32b_fops);
|
|
|
|
|
2019-11-12 10:40:11 +03:00
|
|
|
debugfs_create_file("data64",
|
|
|
|
0644,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2019-11-12 10:40:11 +03:00
|
|
|
dev_entry,
|
|
|
|
&hl_data64b_fops);
|
|
|
|
|
2019-02-16 01:39:24 +03:00
|
|
|
debugfs_create_file("set_power_state",
|
|
|
|
0200,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2019-02-16 01:39:24 +03:00
|
|
|
dev_entry,
|
|
|
|
&hl_power_fops);
|
|
|
|
|
|
|
|
debugfs_create_file("device",
|
|
|
|
0200,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2019-02-16 01:39:24 +03:00
|
|
|
dev_entry,
|
|
|
|
&hl_device_fops);
|
|
|
|
|
2020-05-09 12:17:21 +03:00
|
|
|
debugfs_create_file("clk_gate",
|
|
|
|
0200,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2020-05-09 12:17:21 +03:00
|
|
|
dev_entry,
|
|
|
|
&hl_clk_gate_fops);
|
|
|
|
|
2020-03-22 22:12:51 +03:00
|
|
|
debugfs_create_file("stop_on_err",
|
|
|
|
0644,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2020-03-22 22:12:51 +03:00
|
|
|
dev_entry,
|
|
|
|
&hl_stop_on_err_fops);
|
|
|
|
|
2021-01-07 13:14:17 +03:00
|
|
|
debugfs_create_file("dump_security_violations",
|
|
|
|
0644,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2021-01-07 13:14:17 +03:00
|
|
|
dev_entry,
|
|
|
|
&hl_security_violations_fops);
|
|
|
|
|
2022-06-26 18:20:03 +03:00
|
|
|
debugfs_create_file("dump_razwi_events",
|
|
|
|
0644,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2022-06-26 18:20:03 +03:00
|
|
|
dev_entry,
|
|
|
|
&hl_razwi_check_fops);
|
|
|
|
|
2021-04-02 01:43:18 +03:00
|
|
|
debugfs_create_file("dma_size",
|
|
|
|
0200,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2021-04-02 01:43:18 +03:00
|
|
|
dev_entry,
|
|
|
|
&hl_dma_size_fops);
|
|
|
|
|
|
|
|
debugfs_create_blob("data_dma",
|
|
|
|
0400,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2022-03-22 15:32:40 +03:00
|
|
|
&dev_entry->data_dma_blob_desc);
|
|
|
|
|
|
|
|
debugfs_create_file("monitor_dump_trig",
|
|
|
|
0200,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2022-03-22 15:32:40 +03:00
|
|
|
dev_entry,
|
|
|
|
&hl_monitor_dump_fops);
|
|
|
|
|
|
|
|
debugfs_create_blob("monitor_dump",
|
|
|
|
0400,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2022-03-22 15:32:40 +03:00
|
|
|
&dev_entry->mon_dump_blob_desc);
|
2021-04-02 01:43:18 +03:00
|
|
|
|
2021-06-13 09:22:20 +03:00
|
|
|
debugfs_create_x8("skip_reset_on_timeout",
|
|
|
|
0644,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2021-11-23 16:15:22 +03:00
|
|
|
&hdev->reset_info.skip_reset_on_timeout);
|
2021-06-13 09:22:20 +03:00
|
|
|
|
2021-06-06 10:28:51 +03:00
|
|
|
debugfs_create_file("state_dump",
|
|
|
|
0600,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2021-06-06 10:28:51 +03:00
|
|
|
dev_entry,
|
|
|
|
&hl_state_dump_fops);
|
|
|
|
|
2021-09-02 10:18:01 +03:00
|
|
|
debugfs_create_file("timeout_locked",
|
|
|
|
0644,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2021-09-02 10:18:01 +03:00
|
|
|
dev_entry,
|
|
|
|
&hl_timeout_locked_fops);
|
|
|
|
|
2022-09-30 16:37:41 +03:00
|
|
|
debugfs_create_u32("device_release_watchdog_timeout",
|
|
|
|
0644,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2022-09-30 16:37:41 +03:00
|
|
|
&hdev->device_release_watchdog_timeout_sec);
|
|
|
|
|
2019-02-16 01:39:24 +03:00
|
|
|
for (i = 0, entry = dev_entry->entry_arr ; i < count ; i++, entry++) {
|
2021-02-16 18:08:28 +03:00
|
|
|
debugfs_create_file(hl_debugfs_list[i].name,
|
2019-02-16 01:39:24 +03:00
|
|
|
0444,
|
2023-01-23 00:04:10 +03:00
|
|
|
root,
|
2019-02-16 01:39:24 +03:00
|
|
|
entry,
|
|
|
|
&hl_debugfs_fops);
|
|
|
|
entry->info_ent = &hl_debugfs_list[i];
|
|
|
|
entry->dev_entry = dev_entry;
|
|
|
|
}
|
2023-01-23 00:04:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void hl_debugfs_add_device(struct hl_device *hdev)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs;
|
|
|
|
int count = ARRAY_SIZE(hl_debugfs_list);
|
|
|
|
|
|
|
|
dev_entry->hdev = hdev;
|
|
|
|
dev_entry->entry_arr = kmalloc_array(count,
|
|
|
|
sizeof(struct hl_debugfs_entry),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!dev_entry->entry_arr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dev_entry->data_dma_blob_desc.size = 0;
|
|
|
|
dev_entry->data_dma_blob_desc.data = NULL;
|
|
|
|
dev_entry->mon_dump_blob_desc.size = 0;
|
|
|
|
dev_entry->mon_dump_blob_desc.data = NULL;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&dev_entry->file_list);
|
|
|
|
INIT_LIST_HEAD(&dev_entry->cb_list);
|
|
|
|
INIT_LIST_HEAD(&dev_entry->cs_list);
|
|
|
|
INIT_LIST_HEAD(&dev_entry->cs_job_list);
|
|
|
|
INIT_LIST_HEAD(&dev_entry->userptr_list);
|
|
|
|
INIT_LIST_HEAD(&dev_entry->ctx_mem_hash_list);
|
|
|
|
mutex_init(&dev_entry->file_mutex);
|
|
|
|
init_rwsem(&dev_entry->state_dump_sem);
|
|
|
|
spin_lock_init(&dev_entry->cb_spinlock);
|
|
|
|
spin_lock_init(&dev_entry->cs_spinlock);
|
|
|
|
spin_lock_init(&dev_entry->cs_job_spinlock);
|
|
|
|
spin_lock_init(&dev_entry->userptr_spinlock);
|
2023-02-23 19:17:02 +03:00
|
|
|
mutex_init(&dev_entry->ctx_mem_hash_mutex);
|
2023-01-23 00:04:10 +03:00
|
|
|
|
|
|
|
dev_entry->root = debugfs_create_dir(dev_name(hdev->dev),
|
|
|
|
hl_debug_root);
|
2022-06-30 09:54:59 +03:00
|
|
|
|
2023-01-23 00:04:10 +03:00
|
|
|
add_files_to_device(hdev, dev_entry, dev_entry->root);
|
2022-06-30 09:54:59 +03:00
|
|
|
if (!hdev->asic_prop.fw_security_enabled)
|
2023-01-23 00:04:10 +03:00
|
|
|
add_secured_nodes(dev_entry, dev_entry->root);
|
2019-02-16 01:39:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void hl_debugfs_remove_device(struct hl_device *hdev)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *entry = &hdev->hl_debugfs;
|
2021-06-06 10:28:51 +03:00
|
|
|
int i;
|
2019-02-16 01:39:24 +03:00
|
|
|
|
|
|
|
debugfs_remove_recursive(entry->root);
|
|
|
|
|
2023-02-23 19:17:02 +03:00
|
|
|
mutex_destroy(&entry->ctx_mem_hash_mutex);
|
2019-02-16 01:39:24 +03:00
|
|
|
mutex_destroy(&entry->file_mutex);
|
2021-04-02 01:43:18 +03:00
|
|
|
|
2022-03-22 15:32:40 +03:00
|
|
|
vfree(entry->data_dma_blob_desc.data);
|
|
|
|
vfree(entry->mon_dump_blob_desc.data);
|
2021-04-02 01:43:18 +03:00
|
|
|
|
2021-06-06 10:28:51 +03:00
|
|
|
for (i = 0; i < ARRAY_SIZE(entry->state_dump); ++i)
|
|
|
|
vfree(entry->state_dump[i]);
|
|
|
|
|
2019-02-16 01:39:24 +03:00
|
|
|
kfree(entry->entry_arr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void hl_debugfs_add_file(struct hl_fpriv *hpriv)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *dev_entry = &hpriv->hdev->hl_debugfs;
|
|
|
|
|
|
|
|
mutex_lock(&dev_entry->file_mutex);
|
|
|
|
list_add(&hpriv->debugfs_list, &dev_entry->file_list);
|
|
|
|
mutex_unlock(&dev_entry->file_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void hl_debugfs_remove_file(struct hl_fpriv *hpriv)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *dev_entry = &hpriv->hdev->hl_debugfs;
|
|
|
|
|
|
|
|
mutex_lock(&dev_entry->file_mutex);
|
|
|
|
list_del(&hpriv->debugfs_list);
|
|
|
|
mutex_unlock(&dev_entry->file_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void hl_debugfs_add_cb(struct hl_cb *cb)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *dev_entry = &cb->hdev->hl_debugfs;
|
|
|
|
|
|
|
|
spin_lock(&dev_entry->cb_spinlock);
|
|
|
|
list_add(&cb->debugfs_list, &dev_entry->cb_list);
|
|
|
|
spin_unlock(&dev_entry->cb_spinlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void hl_debugfs_remove_cb(struct hl_cb *cb)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *dev_entry = &cb->hdev->hl_debugfs;
|
|
|
|
|
|
|
|
spin_lock(&dev_entry->cb_spinlock);
|
|
|
|
list_del(&cb->debugfs_list);
|
|
|
|
spin_unlock(&dev_entry->cb_spinlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void hl_debugfs_add_cs(struct hl_cs *cs)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *dev_entry = &cs->ctx->hdev->hl_debugfs;
|
|
|
|
|
|
|
|
spin_lock(&dev_entry->cs_spinlock);
|
|
|
|
list_add(&cs->debugfs_list, &dev_entry->cs_list);
|
|
|
|
spin_unlock(&dev_entry->cs_spinlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void hl_debugfs_remove_cs(struct hl_cs *cs)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *dev_entry = &cs->ctx->hdev->hl_debugfs;
|
|
|
|
|
|
|
|
spin_lock(&dev_entry->cs_spinlock);
|
|
|
|
list_del(&cs->debugfs_list);
|
|
|
|
spin_unlock(&dev_entry->cs_spinlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void hl_debugfs_add_job(struct hl_device *hdev, struct hl_cs_job *job)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs;
|
|
|
|
|
|
|
|
spin_lock(&dev_entry->cs_job_spinlock);
|
|
|
|
list_add(&job->debugfs_list, &dev_entry->cs_job_list);
|
|
|
|
spin_unlock(&dev_entry->cs_job_spinlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void hl_debugfs_remove_job(struct hl_device *hdev, struct hl_cs_job *job)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs;
|
|
|
|
|
|
|
|
spin_lock(&dev_entry->cs_job_spinlock);
|
|
|
|
list_del(&job->debugfs_list);
|
|
|
|
spin_unlock(&dev_entry->cs_job_spinlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void hl_debugfs_add_userptr(struct hl_device *hdev, struct hl_userptr *userptr)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs;
|
|
|
|
|
|
|
|
spin_lock(&dev_entry->userptr_spinlock);
|
|
|
|
list_add(&userptr->debugfs_list, &dev_entry->userptr_list);
|
|
|
|
spin_unlock(&dev_entry->userptr_spinlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void hl_debugfs_remove_userptr(struct hl_device *hdev,
|
|
|
|
struct hl_userptr *userptr)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs;
|
|
|
|
|
|
|
|
spin_lock(&dev_entry->userptr_spinlock);
|
|
|
|
list_del(&userptr->debugfs_list);
|
|
|
|
spin_unlock(&dev_entry->userptr_spinlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void hl_debugfs_add_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs;
|
|
|
|
|
2023-02-23 19:17:02 +03:00
|
|
|
mutex_lock(&dev_entry->ctx_mem_hash_mutex);
|
2019-02-16 01:39:24 +03:00
|
|
|
list_add(&ctx->debugfs_list, &dev_entry->ctx_mem_hash_list);
|
2023-02-23 19:17:02 +03:00
|
|
|
mutex_unlock(&dev_entry->ctx_mem_hash_mutex);
|
2019-02-16 01:39:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void hl_debugfs_remove_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs;
|
|
|
|
|
2023-02-23 19:17:02 +03:00
|
|
|
mutex_lock(&dev_entry->ctx_mem_hash_mutex);
|
2019-02-16 01:39:24 +03:00
|
|
|
list_del(&ctx->debugfs_list);
|
2023-02-23 19:17:02 +03:00
|
|
|
mutex_unlock(&dev_entry->ctx_mem_hash_mutex);
|
2019-02-16 01:39:24 +03:00
|
|
|
}
|
|
|
|
|
2021-06-06 10:28:51 +03:00
|
|
|
/**
|
|
|
|
* hl_debugfs_set_state_dump - register state dump making it accessible via
|
|
|
|
* debugfs
|
|
|
|
* @hdev: pointer to the device structure
|
|
|
|
* @data: the actual dump data
|
|
|
|
* @length: the length of the data
|
|
|
|
*/
|
|
|
|
void hl_debugfs_set_state_dump(struct hl_device *hdev, char *data,
|
|
|
|
unsigned long length)
|
|
|
|
{
|
|
|
|
struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs;
|
|
|
|
|
|
|
|
down_write(&dev_entry->state_dump_sem);
|
|
|
|
|
|
|
|
dev_entry->state_dump_head = (dev_entry->state_dump_head + 1) %
|
|
|
|
ARRAY_SIZE(dev_entry->state_dump);
|
|
|
|
vfree(dev_entry->state_dump[dev_entry->state_dump_head]);
|
|
|
|
dev_entry->state_dump[dev_entry->state_dump_head] = data;
|
|
|
|
|
|
|
|
up_write(&dev_entry->state_dump_sem);
|
|
|
|
}
|
|
|
|
|
2019-02-16 01:39:24 +03:00
|
|
|
void __init hl_debugfs_init(void)
|
|
|
|
{
|
|
|
|
hl_debug_root = debugfs_create_dir("habanalabs", NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void hl_debugfs_fini(void)
|
|
|
|
{
|
|
|
|
debugfs_remove_recursive(hl_debug_root);
|
|
|
|
}
|