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