0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #include <linux/kernel.h>
0029 #include <linux/types.h>
0030 #include <linux/pci.h>
0031 #include <linux/interrupt.h>
0032 #include <linux/compat.h>
0033 #include <linux/irq_poll.h>
0034
0035 #include <scsi/scsi.h>
0036 #include <scsi/scsi_device.h>
0037 #include <scsi/scsi_host.h>
0038
0039 #include "megaraid_sas_fusion.h"
0040 #include "megaraid_sas.h"
0041
0042 #ifdef CONFIG_DEBUG_FS
0043 #include <linux/debugfs.h>
0044
0045 struct dentry *megasas_debugfs_root;
0046
0047 static ssize_t
0048 megasas_debugfs_read(struct file *filp, char __user *ubuf, size_t cnt,
0049 loff_t *ppos)
0050 {
0051 struct megasas_debugfs_buffer *debug = filp->private_data;
0052
0053 if (!debug || !debug->buf)
0054 return 0;
0055
0056 return simple_read_from_buffer(ubuf, cnt, ppos, debug->buf, debug->len);
0057 }
0058
0059 static int
0060 megasas_debugfs_raidmap_open(struct inode *inode, struct file *file)
0061 {
0062 struct megasas_instance *instance = inode->i_private;
0063 struct megasas_debugfs_buffer *debug;
0064 struct fusion_context *fusion;
0065
0066 fusion = instance->ctrl_context;
0067
0068 debug = kzalloc(sizeof(struct megasas_debugfs_buffer), GFP_KERNEL);
0069 if (!debug)
0070 return -ENOMEM;
0071
0072 debug->buf = (void *)fusion->ld_drv_map[(instance->map_id & 1)];
0073 debug->len = fusion->drv_map_sz;
0074 file->private_data = debug;
0075
0076 return 0;
0077 }
0078
0079 static int
0080 megasas_debugfs_release(struct inode *inode, struct file *file)
0081 {
0082 struct megasas_debug_buffer *debug = file->private_data;
0083
0084 if (!debug)
0085 return 0;
0086
0087 file->private_data = NULL;
0088 kfree(debug);
0089 return 0;
0090 }
0091
0092 static const struct file_operations megasas_debugfs_raidmap_fops = {
0093 .owner = THIS_MODULE,
0094 .open = megasas_debugfs_raidmap_open,
0095 .read = megasas_debugfs_read,
0096 .release = megasas_debugfs_release,
0097 };
0098
0099
0100
0101
0102 void megasas_init_debugfs(void)
0103 {
0104 megasas_debugfs_root = debugfs_create_dir("megaraid_sas", NULL);
0105 if (!megasas_debugfs_root)
0106 pr_info("Cannot create debugfs root\n");
0107 }
0108
0109
0110
0111
0112 void megasas_exit_debugfs(void)
0113 {
0114 debugfs_remove_recursive(megasas_debugfs_root);
0115 }
0116
0117
0118
0119
0120
0121 void
0122 megasas_setup_debugfs(struct megasas_instance *instance)
0123 {
0124 char name[64];
0125 struct fusion_context *fusion;
0126
0127 fusion = instance->ctrl_context;
0128
0129 if (fusion) {
0130 snprintf(name, sizeof(name),
0131 "scsi_host%d", instance->host->host_no);
0132 if (!instance->debugfs_root) {
0133 instance->debugfs_root =
0134 debugfs_create_dir(name, megasas_debugfs_root);
0135 if (!instance->debugfs_root) {
0136 dev_err(&instance->pdev->dev,
0137 "Cannot create per adapter debugfs directory\n");
0138 return;
0139 }
0140 }
0141
0142 snprintf(name, sizeof(name), "raidmap_dump");
0143 instance->raidmap_dump =
0144 debugfs_create_file(name, S_IRUGO,
0145 instance->debugfs_root, instance,
0146 &megasas_debugfs_raidmap_fops);
0147 if (!instance->raidmap_dump) {
0148 dev_err(&instance->pdev->dev,
0149 "Cannot create raidmap debugfs file\n");
0150 debugfs_remove(instance->debugfs_root);
0151 return;
0152 }
0153 }
0154
0155 }
0156
0157
0158
0159
0160
0161 void megasas_destroy_debugfs(struct megasas_instance *instance)
0162 {
0163 debugfs_remove_recursive(instance->debugfs_root);
0164 }
0165
0166 #else
0167 void megasas_init_debugfs(void)
0168 {
0169 }
0170 void megasas_exit_debugfs(void)
0171 {
0172 }
0173 void megasas_setup_debugfs(struct megasas_instance *instance)
0174 {
0175 }
0176 void megasas_destroy_debugfs(struct megasas_instance *instance)
0177 {
0178 }
0179 #endif