root/drivers/scsi/megaraid/megaraid_sas_debugfs.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. megasas_debugfs_read
  2. megasas_debugfs_raidmap_open
  3. megasas_debugfs_release
  4. megasas_init_debugfs
  5. megasas_exit_debugfs
  6. megasas_setup_debugfs
  7. megasas_destroy_debugfs
  8. megasas_init_debugfs
  9. megasas_exit_debugfs
  10. megasas_setup_debugfs
  11. megasas_destroy_debugfs

   1 /*
   2  *  Linux MegaRAID driver for SAS based RAID controllers
   3  *
   4  *  Copyright (c) 2003-2018  LSI Corporation.
   5  *  Copyright (c) 2003-2018  Avago Technologies.
   6  *  Copyright (c) 2003-2018  Broadcom Inc.
   7  *
   8  *  This program is free software; you can redistribute it and/or
   9  *  modify it under the terms of the GNU General Public License
  10  *  as published by the Free Software Foundation; either version 2
  11  *  of the License, or (at your option) any later version.
  12  *
  13  *  This program is distributed in the hope that it will be useful,
  14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16  *  GNU General Public License for more details.
  17  *
  18  *  You should have received a copy of the GNU General Public License
  19  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  20  *
  21  *  Authors: Broadcom Inc.
  22  *           Kashyap Desai <kashyap.desai@broadcom.com>
  23  *           Sumit Saxena <sumit.saxena@broadcom.com>
  24  *           Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
  25  *
  26  *  Send feedback to: megaraidlinux.pdl@broadcom.com
  27  */
  28 #include <linux/kernel.h>
  29 #include <linux/types.h>
  30 #include <linux/pci.h>
  31 #include <linux/interrupt.h>
  32 #include <linux/compat.h>
  33 #include <linux/irq_poll.h>
  34 
  35 #include <scsi/scsi.h>
  36 #include <scsi/scsi_device.h>
  37 #include <scsi/scsi_host.h>
  38 
  39 #include "megaraid_sas_fusion.h"
  40 #include "megaraid_sas.h"
  41 
  42 #ifdef CONFIG_DEBUG_FS
  43 #include <linux/debugfs.h>
  44 
  45 struct dentry *megasas_debugfs_root;
  46 
  47 static ssize_t
  48 megasas_debugfs_read(struct file *filp, char __user *ubuf, size_t cnt,
  49                       loff_t *ppos)
  50 {
  51         struct megasas_debugfs_buffer *debug = filp->private_data;
  52 
  53         if (!debug || !debug->buf)
  54                 return 0;
  55 
  56         return simple_read_from_buffer(ubuf, cnt, ppos, debug->buf, debug->len);
  57 }
  58 
  59 static int
  60 megasas_debugfs_raidmap_open(struct inode *inode, struct file *file)
  61 {
  62         struct megasas_instance *instance = inode->i_private;
  63         struct megasas_debugfs_buffer *debug;
  64         struct fusion_context *fusion;
  65 
  66         fusion = instance->ctrl_context;
  67 
  68         debug = kzalloc(sizeof(struct megasas_debugfs_buffer), GFP_KERNEL);
  69         if (!debug)
  70                 return -ENOMEM;
  71 
  72         debug->buf = (void *)fusion->ld_drv_map[(instance->map_id & 1)];
  73         debug->len = fusion->drv_map_sz;
  74         file->private_data = debug;
  75 
  76         return 0;
  77 }
  78 
  79 static int
  80 megasas_debugfs_release(struct inode *inode, struct file *file)
  81 {
  82         struct megasas_debug_buffer *debug = file->private_data;
  83 
  84         if (!debug)
  85                 return 0;
  86 
  87         file->private_data = NULL;
  88         kfree(debug);
  89         return 0;
  90 }
  91 
  92 static const struct file_operations megasas_debugfs_raidmap_fops = {
  93         .owner          = THIS_MODULE,
  94         .open           = megasas_debugfs_raidmap_open,
  95         .read           = megasas_debugfs_read,
  96         .release        = megasas_debugfs_release,
  97 };
  98 
  99 /*
 100  * megasas_init_debugfs :       Create debugfs root for megaraid_sas driver
 101  */
 102 void megasas_init_debugfs(void)
 103 {
 104         megasas_debugfs_root = debugfs_create_dir("megaraid_sas", NULL);
 105         if (!megasas_debugfs_root)
 106                 pr_info("Cannot create debugfs root\n");
 107 }
 108 
 109 /*
 110  * megasas_exit_debugfs :       Remove debugfs root for megaraid_sas driver
 111  */
 112 void megasas_exit_debugfs(void)
 113 {
 114         debugfs_remove_recursive(megasas_debugfs_root);
 115 }
 116 
 117 /*
 118  * megasas_setup_debugfs :      Setup debugfs per Fusion adapter
 119  * instance:                            Soft instance of adapter
 120  */
 121 void
 122 megasas_setup_debugfs(struct megasas_instance *instance)
 123 {
 124         char name[64];
 125         struct fusion_context *fusion;
 126 
 127         fusion = instance->ctrl_context;
 128 
 129         if (fusion) {
 130                 snprintf(name, sizeof(name),
 131                          "scsi_host%d", instance->host->host_no);
 132                 if (!instance->debugfs_root) {
 133                         instance->debugfs_root =
 134                                 debugfs_create_dir(name, megasas_debugfs_root);
 135                         if (!instance->debugfs_root) {
 136                                 dev_err(&instance->pdev->dev,
 137                                         "Cannot create per adapter debugfs directory\n");
 138                                 return;
 139                         }
 140                 }
 141 
 142                 snprintf(name, sizeof(name), "raidmap_dump");
 143                 instance->raidmap_dump =
 144                         debugfs_create_file(name, S_IRUGO,
 145                                             instance->debugfs_root, instance,
 146                                             &megasas_debugfs_raidmap_fops);
 147                 if (!instance->raidmap_dump) {
 148                         dev_err(&instance->pdev->dev,
 149                                 "Cannot create raidmap debugfs file\n");
 150                         debugfs_remove(instance->debugfs_root);
 151                         return;
 152                 }
 153         }
 154 
 155 }
 156 
 157 /*
 158  * megasas_destroy_debugfs :    Destroy debugfs per Fusion adapter
 159  * instance:                                    Soft instance of adapter
 160  */
 161 void megasas_destroy_debugfs(struct megasas_instance *instance)
 162 {
 163         debugfs_remove_recursive(instance->debugfs_root);
 164 }
 165 
 166 #else
 167 void megasas_init_debugfs(void)
 168 {
 169 }
 170 void megasas_exit_debugfs(void)
 171 {
 172 }
 173 void megasas_setup_debugfs(struct megasas_instance *instance)
 174 {
 175 }
 176 void megasas_destroy_debugfs(struct megasas_instance *instance)
 177 {
 178 }
 179 #endif /*CONFIG_DEBUG_FS*/

/* [<][>][^][v][top][bottom][index][help] */