Skip to content

Commit e2fb2e2

Browse files
Sanjay R Mehtavinodkoul
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent b0b4a6b commit e2fb2e2

File tree

4 files changed

+118
-1
lines changed

4 files changed

+118
-1
lines changed

drivers/dma/ptdma/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66
obj-$(CONFIG_AMD_PTDMA) += ptdma.o
77

8-
ptdma-objs := ptdma-dev.o ptdma-dmaengine.o
8+
ptdma-objs := ptdma-dev.o ptdma-dmaengine.o ptdma-debugfs.o
99

1010
ptdma-$(CONFIG_PCI) += ptdma-pci.o

drivers/dma/ptdma/ptdma-debugfs.c

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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 <[email protected]>
9+
* Author: Gary R Hook <[email protected]>
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+
}

drivers/dma/ptdma/ptdma-dev.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ int pt_core_perform_passthru(struct pt_cmd_queue *cmd_q,
102102
struct ptdma_desc desc;
103103

104104
cmd_q->cmd_error = 0;
105+
cmd_q->total_pt_ops++;
105106
memset(&desc, 0, sizeof(desc));
106107
desc.dw0 = CMD_DESC_DW0_VAL;
107108
desc.length = pt_engine->src_len;
@@ -150,6 +151,7 @@ static irqreturn_t pt_core_irq_handler(int irq, void *data)
150151
u32 status;
151152

152153
pt_core_disable_queue_interrupts(pt);
154+
pt->total_interrupts++;
153155
status = ioread32(cmd_q->reg_control + 0x0010);
154156
if (status) {
155157
cmd_q->int_status = status;
@@ -250,6 +252,9 @@ int pt_core_init(struct pt_device *pt)
250252
if (ret)
251253
goto e_dmaengine;
252254

255+
/* Set up debugfs entries */
256+
ptdma_debugfs_setup(pt);
257+
253258
return 0;
254259

255260
e_dmaengine:

drivers/dma/ptdma/ptdma.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ struct pt_cmd_queue {
216216
u32 q_status;
217217
u32 q_int_status;
218218
u32 cmd_error;
219+
/* Queue Statistics */
220+
unsigned long total_pt_ops;
219221
} ____cacheline_aligned;
220222

221223
struct pt_device {
@@ -254,6 +256,9 @@ struct pt_device {
254256

255257
wait_queue_head_t lsb_queue;
256258

259+
/* Device Statistics */
260+
unsigned long total_interrupts;
261+
257262
struct pt_tasklet_data tdata;
258263
};
259264

@@ -307,6 +312,7 @@ struct pt_dev_vdata {
307312
int pt_dmaengine_register(struct pt_device *pt);
308313
void pt_dmaengine_unregister(struct pt_device *pt);
309314

315+
void ptdma_debugfs_setup(struct pt_device *pt);
310316
int pt_core_init(struct pt_device *pt);
311317
void pt_core_destroy(struct pt_device *pt);
312318

0 commit comments

Comments
 (0)