Linux 4.18.10
[linux/fpc-iii.git] / drivers / misc / mic / host / mic_debugfs.c
blob0a9daba8bb5de8ee3809c6da1a6a6023bf78a853
1 /*
2 * Intel MIC Platform Software Stack (MPSS)
4 * Copyright(c) 2013 Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License, version 2, as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * The full GNU General Public License is included in this distribution in
16 * the file called "COPYING".
18 * Intel MIC Host driver.
21 #include <linux/debugfs.h>
22 #include <linux/pci.h>
23 #include <linux/seq_file.h>
25 #include <linux/mic_common.h>
26 #include "../common/mic_dev.h"
27 #include "mic_device.h"
28 #include "mic_smpt.h"
30 /* Debugfs parent dir */
31 static struct dentry *mic_dbg;
33 static int mic_smpt_show(struct seq_file *s, void *pos)
35 int i;
36 struct mic_device *mdev = s->private;
37 unsigned long flags;
39 seq_printf(s, "MIC %-2d |%-10s| %-14s %-10s\n",
40 mdev->id, "SMPT entry", "SW DMA addr", "RefCount");
41 seq_puts(s, "====================================================\n");
43 if (mdev->smpt) {
44 struct mic_smpt_info *smpt_info = mdev->smpt;
45 spin_lock_irqsave(&smpt_info->smpt_lock, flags);
46 for (i = 0; i < smpt_info->info.num_reg; i++) {
47 seq_printf(s, "%9s|%-10d| %-#14llx %-10lld\n",
48 " ", i, smpt_info->entry[i].dma_addr,
49 smpt_info->entry[i].ref_count);
51 spin_unlock_irqrestore(&smpt_info->smpt_lock, flags);
53 seq_puts(s, "====================================================\n");
54 return 0;
57 static int mic_smpt_debug_open(struct inode *inode, struct file *file)
59 return single_open(file, mic_smpt_show, inode->i_private);
62 static int mic_smpt_debug_release(struct inode *inode, struct file *file)
64 return single_release(inode, file);
67 static const struct file_operations smpt_file_ops = {
68 .owner = THIS_MODULE,
69 .open = mic_smpt_debug_open,
70 .read = seq_read,
71 .llseek = seq_lseek,
72 .release = mic_smpt_debug_release
75 static int mic_post_code_show(struct seq_file *s, void *pos)
77 struct mic_device *mdev = s->private;
78 u32 reg = mdev->ops->get_postcode(mdev);
80 seq_printf(s, "%c%c", reg & 0xff, (reg >> 8) & 0xff);
81 return 0;
84 static int mic_post_code_debug_open(struct inode *inode, struct file *file)
86 return single_open(file, mic_post_code_show, inode->i_private);
89 static int mic_post_code_debug_release(struct inode *inode, struct file *file)
91 return single_release(inode, file);
94 static const struct file_operations post_code_ops = {
95 .owner = THIS_MODULE,
96 .open = mic_post_code_debug_open,
97 .read = seq_read,
98 .llseek = seq_lseek,
99 .release = mic_post_code_debug_release
102 static int mic_msi_irq_info_show(struct seq_file *s, void *pos)
104 struct mic_device *mdev = s->private;
105 int reg;
106 int i, j;
107 u16 entry;
108 u16 vector;
109 struct pci_dev *pdev = mdev->pdev;
111 if (pci_dev_msi_enabled(pdev)) {
112 for (i = 0; i < mdev->irq_info.num_vectors; i++) {
113 if (pdev->msix_enabled) {
114 entry = mdev->irq_info.msix_entries[i].entry;
115 vector = mdev->irq_info.msix_entries[i].vector;
116 } else {
117 entry = 0;
118 vector = pdev->irq;
121 reg = mdev->intr_ops->read_msi_to_src_map(mdev, entry);
123 seq_printf(s, "%s %-10d %s %-10d MXAR[%d]: %08X\n",
124 "IRQ:", vector, "Entry:", entry, i, reg);
126 seq_printf(s, "%-10s", "offset:");
127 for (j = (MIC_NUM_OFFSETS - 1); j >= 0; j--)
128 seq_printf(s, "%4d ", j);
129 seq_puts(s, "\n");
132 seq_printf(s, "%-10s", "count:");
133 for (j = (MIC_NUM_OFFSETS - 1); j >= 0; j--)
134 seq_printf(s, "%4d ",
135 (mdev->irq_info.mic_msi_map[i] &
136 BIT(j)) ? 1 : 0);
137 seq_puts(s, "\n\n");
139 } else {
140 seq_puts(s, "MSI/MSIx interrupts not enabled\n");
143 return 0;
146 static int mic_msi_irq_info_debug_open(struct inode *inode, struct file *file)
148 return single_open(file, mic_msi_irq_info_show, inode->i_private);
151 static int
152 mic_msi_irq_info_debug_release(struct inode *inode, struct file *file)
154 return single_release(inode, file);
157 static const struct file_operations msi_irq_info_ops = {
158 .owner = THIS_MODULE,
159 .open = mic_msi_irq_info_debug_open,
160 .read = seq_read,
161 .llseek = seq_lseek,
162 .release = mic_msi_irq_info_debug_release
166 * mic_create_debug_dir - Initialize MIC debugfs entries.
168 void mic_create_debug_dir(struct mic_device *mdev)
170 char name[16];
172 if (!mic_dbg)
173 return;
175 scnprintf(name, sizeof(name), "mic%d", mdev->id);
176 mdev->dbg_dir = debugfs_create_dir(name, mic_dbg);
177 if (!mdev->dbg_dir)
178 return;
180 debugfs_create_file("smpt", 0444, mdev->dbg_dir, mdev, &smpt_file_ops);
182 debugfs_create_file("post_code", 0444, mdev->dbg_dir, mdev,
183 &post_code_ops);
185 debugfs_create_file("msi_irq_info", 0444, mdev->dbg_dir, mdev,
186 &msi_irq_info_ops);
190 * mic_delete_debug_dir - Uninitialize MIC debugfs entries.
192 void mic_delete_debug_dir(struct mic_device *mdev)
194 if (!mdev->dbg_dir)
195 return;
197 debugfs_remove_recursive(mdev->dbg_dir);
201 * mic_init_debugfs - Initialize global debugfs entry.
203 void __init mic_init_debugfs(void)
205 mic_dbg = debugfs_create_dir(KBUILD_MODNAME, NULL);
206 if (!mic_dbg)
207 pr_err("can't create debugfs dir\n");
211 * mic_exit_debugfs - Uninitialize global debugfs entry
213 void mic_exit_debugfs(void)
215 debugfs_remove(mic_dbg);