1 // SPDX-License-Identifier: GPL-2.0
3 * Debugfs interface Support for MPT (Message Passing Technology) based
6 * Copyright (C) 2020 Broadcom Inc.
8 * Authors: Broadcom Inc.
9 * Sreekanth Reddy <sreekanth.reddy@broadcom.com>
10 * Suganath Prabu <suganath-prabu.subramani@broadcom.com>
12 * Send feedback to : MPT-FusionLinux.pdl@broadcom.com)
16 #include <linux/kernel.h>
17 #include <linux/types.h>
18 #include <linux/pci.h>
19 #include <linux/interrupt.h>
20 #include <linux/compat.h>
21 #include <linux/uio.h>
23 #include <scsi/scsi.h>
24 #include <scsi/scsi_device.h>
25 #include <scsi/scsi_host.h>
26 #include "mpt3sas_base.h"
27 #include <linux/debugfs.h>
29 static struct dentry *mpt3sas_debugfs_root;
32 * _debugfs_iocdump_read - copy ioc dump from debugfs buffer
33 * @filep: File Pointer
34 * @ubuf: Buffer to fill data
35 * @cnt: Length of the buffer
36 * @ppos: Offset in the file
40 _debugfs_iocdump_read(struct file *filp, char __user *ubuf, size_t cnt,
44 struct mpt3sas_debugfs_buffer *debug = filp->private_data;
46 if (!debug || !debug->buf)
49 return simple_read_from_buffer(ubuf, cnt, ppos, debug->buf, debug->len);
53 * _debugfs_iocdump_open : open the ioc_dump debugfs attribute file
56 _debugfs_iocdump_open(struct inode *inode, struct file *file)
58 struct MPT3SAS_ADAPTER *ioc = inode->i_private;
59 struct mpt3sas_debugfs_buffer *debug;
61 debug = kzalloc(sizeof(struct mpt3sas_debugfs_buffer), GFP_KERNEL);
65 debug->buf = (void *)ioc;
66 debug->len = sizeof(struct MPT3SAS_ADAPTER);
67 file->private_data = debug;
72 * _debugfs_iocdump_release : release the ioc_dump debugfs attribute
73 * @inode: inode structure to the corresponds device
77 _debugfs_iocdump_release(struct inode *inode, struct file *file)
79 struct mpt3sas_debugfs_buffer *debug = file->private_data;
84 file->private_data = NULL;
89 static const struct file_operations mpt3sas_debugfs_iocdump_fops = {
91 .open = _debugfs_iocdump_open,
92 .read = _debugfs_iocdump_read,
93 .release = _debugfs_iocdump_release,
97 * mpt3sas_init_debugfs : Create debugfs root for mpt3sas driver
99 void mpt3sas_init_debugfs(void)
101 mpt3sas_debugfs_root = debugfs_create_dir("mpt3sas", NULL);
102 if (!mpt3sas_debugfs_root)
103 pr_info("mpt3sas: Cannot create debugfs root\n");
107 * mpt3sas_exit_debugfs : Remove debugfs root for mpt3sas driver
109 void mpt3sas_exit_debugfs(void)
111 debugfs_remove_recursive(mpt3sas_debugfs_root);
115 * mpt3sas_setup_debugfs : Setup debugfs per HBA adapter
116 * ioc: MPT3SAS_ADAPTER object
119 mpt3sas_setup_debugfs(struct MPT3SAS_ADAPTER *ioc)
123 snprintf(name, sizeof(name), "scsi_host%d", ioc->shost->host_no);
124 if (!ioc->debugfs_root) {
126 debugfs_create_dir(name, mpt3sas_debugfs_root);
127 if (!ioc->debugfs_root) {
128 dev_err(&ioc->pdev->dev,
129 "Cannot create per adapter debugfs directory\n");
134 snprintf(name, sizeof(name), "ioc_dump");
135 ioc->ioc_dump = debugfs_create_file(name, 0444,
136 ioc->debugfs_root, ioc, &mpt3sas_debugfs_iocdump_fops);
137 if (!ioc->ioc_dump) {
138 dev_err(&ioc->pdev->dev,
139 "Cannot create ioc_dump debugfs file\n");
140 debugfs_remove(ioc->debugfs_root);
144 snprintf(name, sizeof(name), "host_recovery");
145 debugfs_create_u8(name, 0444, ioc->debugfs_root, &ioc->shost_recovery);
150 * mpt3sas_destroy_debugfs : Destroy debugfs per HBA adapter
151 * @ioc: MPT3SAS_ADAPTER object
153 void mpt3sas_destroy_debugfs(struct MPT3SAS_ADAPTER *ioc)
155 debugfs_remove_recursive(ioc->debugfs_root);