1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
45struct dentry *megasas_debugfs_root;
46
47static ssize_t
48megasas_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
59static int
60megasas_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
79static int
80megasas_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
92static 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
101
102void 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
111
112void megasas_exit_debugfs(void)
113{
114 debugfs_remove_recursive(megasas_debugfs_root);
115}
116
117
118
119
120
121void
122megasas_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
159
160
161void megasas_destroy_debugfs(struct megasas_instance *instance)
162{
163 debugfs_remove_recursive(instance->debugfs_root);
164}
165
166#else
167void megasas_init_debugfs(void)
168{
169}
170void megasas_exit_debugfs(void)
171{
172}
173void megasas_setup_debugfs(struct megasas_instance *instance)
174{
175}
176void megasas_destroy_debugfs(struct megasas_instance *instance)
177{
178}
179#endif
180