Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dmaengine: ptdma: Add debugfs entries for PTDMA

Expose data about the configuration and operation of the
PTDMA through debugfs entries: device name, capabilities,
configuration, statistics.

Signed-off-by: Sanjay R Mehta <sanju.mehta@amd.com>
Link: https://lore.kernel.org/r/1629208559-51964-4-git-send-email-Sanju.Mehta@amd.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Sanjay R Mehta and committed by
Vinod Koul
e2fb2e2a b0b4a6b1

+118 -1
+1 -1
drivers/dma/ptdma/Makefile
··· 5 5 6 6 obj-$(CONFIG_AMD_PTDMA) += ptdma.o 7 7 8 - ptdma-objs := ptdma-dev.o ptdma-dmaengine.o 8 + ptdma-objs := ptdma-dev.o ptdma-dmaengine.o ptdma-debugfs.o 9 9 10 10 ptdma-$(CONFIG_PCI) += ptdma-pci.o
+106
drivers/dma/ptdma/ptdma-debugfs.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * AMD Passthrough DMA device driver 4 + * -- Based on the CCP driver 5 + * 6 + * Copyright (C) 2016,2021 Advanced Micro Devices, Inc. 7 + * 8 + * Author: Sanjay R Mehta <sanju.mehta@amd.com> 9 + * Author: Gary R Hook <gary.hook@amd.com> 10 + */ 11 + 12 + #include <linux/debugfs.h> 13 + #include <linux/seq_file.h> 14 + 15 + #include "ptdma.h" 16 + 17 + /* DebugFS helpers */ 18 + #define RI_VERSION_NUM 0x0000003F 19 + 20 + #define RI_NUM_VQM 0x00078000 21 + #define RI_NVQM_SHIFT 15 22 + 23 + static int pt_debugfs_info_show(struct seq_file *s, void *p) 24 + { 25 + struct pt_device *pt = s->private; 26 + unsigned int regval; 27 + 28 + seq_printf(s, "Device name: %s\n", dev_name(pt->dev)); 29 + seq_printf(s, " # Queues: %d\n", 1); 30 + seq_printf(s, " # Cmds: %d\n", pt->cmd_count); 31 + 32 + regval = ioread32(pt->io_regs + CMD_PT_VERSION); 33 + 34 + seq_printf(s, " Version: %d\n", regval & RI_VERSION_NUM); 35 + seq_puts(s, " Engines:"); 36 + seq_puts(s, "\n"); 37 + seq_printf(s, " Queues: %d\n", (regval & RI_NUM_VQM) >> RI_NVQM_SHIFT); 38 + 39 + return 0; 40 + } 41 + 42 + /* 43 + * Return a formatted buffer containing the current 44 + * statistics of queue for PTDMA 45 + */ 46 + static int pt_debugfs_stats_show(struct seq_file *s, void *p) 47 + { 48 + struct pt_device *pt = s->private; 49 + 50 + seq_printf(s, "Total Interrupts Handled: %ld\n", pt->total_interrupts); 51 + 52 + return 0; 53 + } 54 + 55 + static int pt_debugfs_queue_show(struct seq_file *s, void *p) 56 + { 57 + struct pt_cmd_queue *cmd_q = s->private; 58 + unsigned int regval; 59 + 60 + if (!cmd_q) 61 + return 0; 62 + 63 + seq_printf(s, " Pass-Thru: %ld\n", cmd_q->total_pt_ops); 64 + 65 + regval = ioread32(cmd_q->reg_control + 0x000C); 66 + 67 + seq_puts(s, " Enabled Interrupts:"); 68 + if (regval & INT_EMPTY_QUEUE) 69 + seq_puts(s, " EMPTY"); 70 + if (regval & INT_QUEUE_STOPPED) 71 + seq_puts(s, " STOPPED"); 72 + if (regval & INT_ERROR) 73 + seq_puts(s, " ERROR"); 74 + if (regval & INT_COMPLETION) 75 + seq_puts(s, " COMPLETION"); 76 + seq_puts(s, "\n"); 77 + 78 + return 0; 79 + } 80 + 81 + DEFINE_SHOW_ATTRIBUTE(pt_debugfs_info); 82 + DEFINE_SHOW_ATTRIBUTE(pt_debugfs_queue); 83 + DEFINE_SHOW_ATTRIBUTE(pt_debugfs_stats); 84 + 85 + void ptdma_debugfs_setup(struct pt_device *pt) 86 + { 87 + struct pt_cmd_queue *cmd_q; 88 + struct dentry *debugfs_q_instance; 89 + 90 + if (!debugfs_initialized()) 91 + return; 92 + 93 + debugfs_create_file("info", 0400, pt->dma_dev.dbg_dev_root, pt, 94 + &pt_debugfs_info_fops); 95 + 96 + debugfs_create_file("stats", 0400, pt->dma_dev.dbg_dev_root, pt, 97 + &pt_debugfs_stats_fops); 98 + 99 + cmd_q = &pt->cmd_q; 100 + 101 + debugfs_q_instance = 102 + debugfs_create_dir("q", pt->dma_dev.dbg_dev_root); 103 + 104 + debugfs_create_file("stats", 0400, debugfs_q_instance, cmd_q, 105 + &pt_debugfs_queue_fops); 106 + }
+5
drivers/dma/ptdma/ptdma-dev.c
··· 102 102 struct ptdma_desc desc; 103 103 104 104 cmd_q->cmd_error = 0; 105 + cmd_q->total_pt_ops++; 105 106 memset(&desc, 0, sizeof(desc)); 106 107 desc.dw0 = CMD_DESC_DW0_VAL; 107 108 desc.length = pt_engine->src_len; ··· 151 150 u32 status; 152 151 153 152 pt_core_disable_queue_interrupts(pt); 153 + pt->total_interrupts++; 154 154 status = ioread32(cmd_q->reg_control + 0x0010); 155 155 if (status) { 156 156 cmd_q->int_status = status; ··· 251 249 ret = pt_dmaengine_register(pt); 252 250 if (ret) 253 251 goto e_dmaengine; 252 + 253 + /* Set up debugfs entries */ 254 + ptdma_debugfs_setup(pt); 254 255 255 256 return 0; 256 257
+6
drivers/dma/ptdma/ptdma.h
··· 216 216 u32 q_status; 217 217 u32 q_int_status; 218 218 u32 cmd_error; 219 + /* Queue Statistics */ 220 + unsigned long total_pt_ops; 219 221 } ____cacheline_aligned; 220 222 221 223 struct pt_device { ··· 255 253 struct kmem_cache *dma_desc_cache; 256 254 257 255 wait_queue_head_t lsb_queue; 256 + 257 + /* Device Statistics */ 258 + unsigned long total_interrupts; 258 259 259 260 struct pt_tasklet_data tdata; 260 261 }; ··· 312 307 int pt_dmaengine_register(struct pt_device *pt); 313 308 void pt_dmaengine_unregister(struct pt_device *pt); 314 309 310 + void ptdma_debugfs_setup(struct pt_device *pt); 315 311 int pt_core_init(struct pt_device *pt); 316 312 void pt_core_destroy(struct pt_device *pt); 317 313