linux/drivers/misc/mic/host/mic_debugfs.c
<<
>>
Prefs
   1/*
   2 * Intel MIC Platform Software Stack (MPSS)
   3 *
   4 * Copyright(c) 2013 Intel Corporation.
   5 *
   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.
   9 *
  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.
  14 *
  15 * The full GNU General Public License is included in this distribution in
  16 * the file called "COPYING".
  17 *
  18 * Intel MIC Host driver.
  19 *
  20 */
  21#include <linux/debugfs.h>
  22#include <linux/pci.h>
  23#include <linux/seq_file.h>
  24
  25#include <linux/mic_common.h>
  26#include "../common/mic_dev.h"
  27#include "mic_device.h"
  28#include "mic_smpt.h"
  29
  30/* Debugfs parent dir */
  31static struct dentry *mic_dbg;
  32
  33static int mic_smpt_show(struct seq_file *s, void *pos)
  34{
  35        int i;
  36        struct mic_device *mdev = s->private;
  37        unsigned long flags;
  38
  39        seq_printf(s, "MIC %-2d |%-10s| %-14s %-10s\n",
  40                   mdev->id, "SMPT entry", "SW DMA addr", "RefCount");
  41        seq_puts(s, "====================================================\n");
  42
  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);
  50                }
  51                spin_unlock_irqrestore(&smpt_info->smpt_lock, flags);
  52        }
  53        seq_puts(s, "====================================================\n");
  54        return 0;
  55}
  56
  57static int mic_smpt_debug_open(struct inode *inode, struct file *file)
  58{
  59        return single_open(file, mic_smpt_show, inode->i_private);
  60}
  61
  62static int mic_smpt_debug_release(struct inode *inode, struct file *file)
  63{
  64        return single_release(inode, file);
  65}
  66
  67static 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
  73};
  74
  75static int mic_post_code_show(struct seq_file *s, void *pos)
  76{
  77        struct mic_device *mdev = s->private;
  78        u32 reg = mdev->ops->get_postcode(mdev);
  79
  80        seq_printf(s, "%c%c", reg & 0xff, (reg >> 8) & 0xff);
  81        return 0;
  82}
  83
  84static int mic_post_code_debug_open(struct inode *inode, struct file *file)
  85{
  86        return single_open(file, mic_post_code_show, inode->i_private);
  87}
  88
  89static int mic_post_code_debug_release(struct inode *inode, struct file *file)
  90{
  91        return single_release(inode, file);
  92}
  93
  94static 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
 100};
 101
 102static int mic_msi_irq_info_show(struct seq_file *s, void *pos)
 103{
 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;
 110
 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;
 119                        }
 120
 121                        reg = mdev->intr_ops->read_msi_to_src_map(mdev, entry);
 122
 123                        seq_printf(s, "%s %-10d %s %-10d MXAR[%d]: %08X\n",
 124                                   "IRQ:", vector, "Entry:", entry, i, reg);
 125
 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");
 130
 131
 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");
 138                }
 139        } else {
 140                seq_puts(s, "MSI/MSIx interrupts not enabled\n");
 141        }
 142
 143        return 0;
 144}
 145
 146static int mic_msi_irq_info_debug_open(struct inode *inode, struct file *file)
 147{
 148        return single_open(file, mic_msi_irq_info_show, inode->i_private);
 149}
 150
 151static int
 152mic_msi_irq_info_debug_release(struct inode *inode, struct file *file)
 153{
 154        return single_release(inode, file);
 155}
 156
 157static 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
 163};
 164
 165/**
 166 * mic_create_debug_dir - Initialize MIC debugfs entries.
 167 */
 168void mic_create_debug_dir(struct mic_device *mdev)
 169{
 170        char name[16];
 171
 172        if (!mic_dbg)
 173                return;
 174
 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;
 179
 180        debugfs_create_file("smpt", 0444, mdev->dbg_dir, mdev, &smpt_file_ops);
 181
 182        debugfs_create_file("post_code", 0444, mdev->dbg_dir, mdev,
 183                            &post_code_ops);
 184
 185        debugfs_create_file("msi_irq_info", 0444, mdev->dbg_dir, mdev,
 186                            &msi_irq_info_ops);
 187}
 188
 189/**
 190 * mic_delete_debug_dir - Uninitialize MIC debugfs entries.
 191 */
 192void mic_delete_debug_dir(struct mic_device *mdev)
 193{
 194        if (!mdev->dbg_dir)
 195                return;
 196
 197        debugfs_remove_recursive(mdev->dbg_dir);
 198}
 199
 200/**
 201 * mic_init_debugfs - Initialize global debugfs entry.
 202 */
 203void __init mic_init_debugfs(void)
 204{
 205        mic_dbg = debugfs_create_dir(KBUILD_MODNAME, NULL);
 206        if (!mic_dbg)
 207                pr_err("can't create debugfs dir\n");
 208}
 209
 210/**
 211 * mic_exit_debugfs - Uninitialize global debugfs entry
 212 */
 213void mic_exit_debugfs(void)
 214{
 215        debugfs_remove(mic_dbg);
 216}
 217