Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * AMD Passthrough DMA device driver
0004  * -- Based on the CCP driver
0005  *
0006  * Copyright (C) 2016,2021 Advanced Micro Devices, Inc.
0007  *
0008  * Author: Sanjay R Mehta <sanju.mehta@amd.com>
0009  * Author: Gary R Hook <gary.hook@amd.com>
0010  */
0011 
0012 #include <linux/debugfs.h>
0013 #include <linux/seq_file.h>
0014 
0015 #include "ptdma.h"
0016 
0017 /* DebugFS helpers */
0018 #define RI_VERSION_NUM  0x0000003F
0019 
0020 #define RI_NUM_VQM  0x00078000
0021 #define RI_NVQM_SHIFT   15
0022 
0023 static int pt_debugfs_info_show(struct seq_file *s, void *p)
0024 {
0025     struct pt_device *pt = s->private;
0026     unsigned int regval;
0027 
0028     seq_printf(s, "Device name: %s\n", dev_name(pt->dev));
0029     seq_printf(s, "   # Queues: %d\n", 1);
0030     seq_printf(s, "     # Cmds: %d\n", pt->cmd_count);
0031 
0032     regval = ioread32(pt->io_regs + CMD_PT_VERSION);
0033 
0034     seq_printf(s, "    Version: %d\n", regval & RI_VERSION_NUM);
0035     seq_puts(s, "    Engines:");
0036     seq_puts(s, "\n");
0037     seq_printf(s, "     Queues: %d\n", (regval & RI_NUM_VQM) >> RI_NVQM_SHIFT);
0038 
0039     return 0;
0040 }
0041 
0042 /*
0043  * Return a formatted buffer containing the current
0044  * statistics of queue for PTDMA
0045  */
0046 static int pt_debugfs_stats_show(struct seq_file *s, void *p)
0047 {
0048     struct pt_device *pt = s->private;
0049 
0050     seq_printf(s, "Total Interrupts Handled: %ld\n", pt->total_interrupts);
0051 
0052     return 0;
0053 }
0054 
0055 static int pt_debugfs_queue_show(struct seq_file *s, void *p)
0056 {
0057     struct pt_cmd_queue *cmd_q = s->private;
0058     unsigned int regval;
0059 
0060     if (!cmd_q)
0061         return 0;
0062 
0063     seq_printf(s, "               Pass-Thru: %ld\n", cmd_q->total_pt_ops);
0064 
0065     regval = ioread32(cmd_q->reg_control + 0x000C);
0066 
0067     seq_puts(s, "      Enabled Interrupts:");
0068     if (regval & INT_EMPTY_QUEUE)
0069         seq_puts(s, " EMPTY");
0070     if (regval & INT_QUEUE_STOPPED)
0071         seq_puts(s, " STOPPED");
0072     if (regval & INT_ERROR)
0073         seq_puts(s, " ERROR");
0074     if (regval & INT_COMPLETION)
0075         seq_puts(s, " COMPLETION");
0076     seq_puts(s, "\n");
0077 
0078     return 0;
0079 }
0080 
0081 DEFINE_SHOW_ATTRIBUTE(pt_debugfs_info);
0082 DEFINE_SHOW_ATTRIBUTE(pt_debugfs_queue);
0083 DEFINE_SHOW_ATTRIBUTE(pt_debugfs_stats);
0084 
0085 void ptdma_debugfs_setup(struct pt_device *pt)
0086 {
0087     struct pt_cmd_queue *cmd_q;
0088     struct dentry *debugfs_q_instance;
0089 
0090     if (!debugfs_initialized())
0091         return;
0092 
0093     debugfs_create_file("info", 0400, pt->dma_dev.dbg_dev_root, pt,
0094                 &pt_debugfs_info_fops);
0095 
0096     debugfs_create_file("stats", 0400, pt->dma_dev.dbg_dev_root, pt,
0097                 &pt_debugfs_stats_fops);
0098 
0099     cmd_q = &pt->cmd_q;
0100 
0101     debugfs_q_instance =
0102         debugfs_create_dir("q", pt->dma_dev.dbg_dev_root);
0103 
0104     debugfs_create_file("stats", 0400, debugfs_q_instance, cmd_q,
0105                 &pt_debugfs_queue_fops);
0106 }