lkdtm: Add Control Flow Integrity test
[linux/fpc-iii.git] / drivers / scsi / megaraid / megaraid_sas_debugfs.c
blobc69760775efaf692cf548ff1e7b877d33e274f23
1 /*
2 * Linux MegaRAID driver for SAS based RAID controllers
4 * Copyright (c) 2003-2018 LSI Corporation.
5 * Copyright (c) 2003-2018 Avago Technologies.
6 * Copyright (c) 2003-2018 Broadcom Inc.
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.
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.
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/>.
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>
26 * Send feedback to: megaraidlinux.pdl@broadcom.com
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>
35 #include <scsi/scsi.h>
36 #include <scsi/scsi_device.h>
37 #include <scsi/scsi_host.h>
39 #include "megaraid_sas_fusion.h"
40 #include "megaraid_sas.h"
42 #ifdef CONFIG_DEBUG_FS
43 #include <linux/debugfs.h>
45 struct dentry *megasas_debugfs_root;
47 static ssize_t
48 megasas_debugfs_read(struct file *filp, char __user *ubuf, size_t cnt,
49 loff_t *ppos)
51 struct megasas_debugfs_buffer *debug = filp->private_data;
53 if (!debug || !debug->buf)
54 return 0;
56 return simple_read_from_buffer(ubuf, cnt, ppos, debug->buf, debug->len);
59 static int
60 megasas_debugfs_raidmap_open(struct inode *inode, struct file *file)
62 struct megasas_instance *instance = inode->i_private;
63 struct megasas_debugfs_buffer *debug;
64 struct fusion_context *fusion;
66 fusion = instance->ctrl_context;
68 debug = kzalloc(sizeof(struct megasas_debugfs_buffer), GFP_KERNEL);
69 if (!debug)
70 return -ENOMEM;
72 debug->buf = (void *)fusion->ld_drv_map[(instance->map_id & 1)];
73 debug->len = fusion->drv_map_sz;
74 file->private_data = debug;
76 return 0;
79 static int
80 megasas_debugfs_release(struct inode *inode, struct file *file)
82 struct megasas_debug_buffer *debug = file->private_data;
84 if (!debug)
85 return 0;
87 file->private_data = NULL;
88 kfree(debug);
89 return 0;
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,
100 * megasas_init_debugfs : Create debugfs root for megaraid_sas driver
102 void megasas_init_debugfs(void)
104 megasas_debugfs_root = debugfs_create_dir("megaraid_sas", NULL);
105 if (!megasas_debugfs_root)
106 pr_info("Cannot create debugfs root\n");
110 * megasas_exit_debugfs : Remove debugfs root for megaraid_sas driver
112 void megasas_exit_debugfs(void)
114 debugfs_remove_recursive(megasas_debugfs_root);
118 * megasas_setup_debugfs : Setup debugfs per Fusion adapter
119 * instance: Soft instance of adapter
121 void
122 megasas_setup_debugfs(struct megasas_instance *instance)
124 char name[64];
125 struct fusion_context *fusion;
127 fusion = instance->ctrl_context;
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;
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;
158 * megasas_destroy_debugfs : Destroy debugfs per Fusion adapter
159 * instance: Soft instance of adapter
161 void megasas_destroy_debugfs(struct megasas_instance *instance)
163 debugfs_remove_recursive(instance->debugfs_root);
166 #else
167 void megasas_init_debugfs(void)
170 void megasas_exit_debugfs(void)
173 void megasas_setup_debugfs(struct megasas_instance *instance)
176 void megasas_destroy_debugfs(struct megasas_instance *instance)
179 #endif /*CONFIG_DEBUG_FS*/