Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Debugfs interface Support for MPT (Message Passing Technology) based
0004  * controllers.
0005  *
0006  * Copyright (C) 2020  Broadcom Inc.
0007  *
0008  * Authors: Broadcom Inc.
0009  * Sreekanth Reddy  <sreekanth.reddy@broadcom.com>
0010  * Suganath Prabu <suganath-prabu.subramani@broadcom.com>
0011  *
0012  * Send feedback to : MPT-FusionLinux.pdl@broadcom.com)
0013  *
0014  **/
0015 
0016 #include <linux/kernel.h>
0017 #include <linux/types.h>
0018 #include <linux/pci.h>
0019 #include <linux/interrupt.h>
0020 #include <linux/compat.h>
0021 #include <linux/uio.h>
0022 
0023 #include <scsi/scsi.h>
0024 #include <scsi/scsi_device.h>
0025 #include <scsi/scsi_host.h>
0026 #include "mpt3sas_base.h"
0027 #include <linux/debugfs.h>
0028 
0029 static struct dentry *mpt3sas_debugfs_root;
0030 
0031 /*
0032  * _debugfs_iocdump_read - copy ioc dump from debugfs buffer
0033  * @filep:  File Pointer
0034  * @ubuf:   Buffer to fill data
0035  * @cnt:    Length of the buffer
0036  * @ppos:   Offset in the file
0037  */
0038 
0039 static ssize_t
0040 _debugfs_iocdump_read(struct file *filp, char __user *ubuf, size_t cnt,
0041     loff_t *ppos)
0042 
0043 {
0044     struct mpt3sas_debugfs_buffer *debug = filp->private_data;
0045 
0046     if (!debug || !debug->buf)
0047         return 0;
0048 
0049     return simple_read_from_buffer(ubuf, cnt, ppos, debug->buf, debug->len);
0050 }
0051 
0052 /*
0053  * _debugfs_iocdump_open :  open the ioc_dump debugfs attribute file
0054  */
0055 static int
0056 _debugfs_iocdump_open(struct inode *inode, struct file *file)
0057 {
0058     struct MPT3SAS_ADAPTER *ioc = inode->i_private;
0059     struct mpt3sas_debugfs_buffer *debug;
0060 
0061     debug = kzalloc(sizeof(struct mpt3sas_debugfs_buffer), GFP_KERNEL);
0062     if (!debug)
0063         return -ENOMEM;
0064 
0065     debug->buf = (void *)ioc;
0066     debug->len = sizeof(struct MPT3SAS_ADAPTER);
0067     file->private_data = debug;
0068     return 0;
0069 }
0070 
0071 /*
0072  * _debugfs_iocdump_release :   release the ioc_dump debugfs attribute
0073  * @inode: inode structure to the corresponds device
0074  * @file: File pointer
0075  */
0076 static int
0077 _debugfs_iocdump_release(struct inode *inode, struct file *file)
0078 {
0079     struct mpt3sas_debugfs_buffer *debug = file->private_data;
0080 
0081     if (!debug)
0082         return 0;
0083 
0084     file->private_data = NULL;
0085     kfree(debug);
0086     return 0;
0087 }
0088 
0089 static const struct file_operations mpt3sas_debugfs_iocdump_fops = {
0090     .owner      = THIS_MODULE,
0091     .open           = _debugfs_iocdump_open,
0092     .read           = _debugfs_iocdump_read,
0093     .release        = _debugfs_iocdump_release,
0094 };
0095 
0096 /*
0097  * mpt3sas_init_debugfs :   Create debugfs root for mpt3sas driver
0098  */
0099 void mpt3sas_init_debugfs(void)
0100 {
0101     mpt3sas_debugfs_root = debugfs_create_dir("mpt3sas", NULL);
0102     if (!mpt3sas_debugfs_root)
0103         pr_info("mpt3sas: Cannot create debugfs root\n");
0104 }
0105 
0106 /*
0107  * mpt3sas_exit_debugfs :   Remove debugfs root for mpt3sas driver
0108  */
0109 void mpt3sas_exit_debugfs(void)
0110 {
0111     debugfs_remove_recursive(mpt3sas_debugfs_root);
0112 }
0113 
0114 /*
0115  * mpt3sas_setup_debugfs :  Setup debugfs per HBA adapter
0116  * ioc:             MPT3SAS_ADAPTER object
0117  */
0118 void
0119 mpt3sas_setup_debugfs(struct MPT3SAS_ADAPTER *ioc)
0120 {
0121     char name[64];
0122 
0123     snprintf(name, sizeof(name), "scsi_host%d", ioc->shost->host_no);
0124     if (!ioc->debugfs_root) {
0125         ioc->debugfs_root =
0126             debugfs_create_dir(name, mpt3sas_debugfs_root);
0127         if (!ioc->debugfs_root) {
0128             dev_err(&ioc->pdev->dev,
0129                 "Cannot create per adapter debugfs directory\n");
0130             return;
0131         }
0132     }
0133 
0134     snprintf(name, sizeof(name), "ioc_dump");
0135     ioc->ioc_dump = debugfs_create_file(name, 0444,
0136         ioc->debugfs_root, ioc, &mpt3sas_debugfs_iocdump_fops);
0137     if (!ioc->ioc_dump) {
0138         dev_err(&ioc->pdev->dev,
0139             "Cannot create ioc_dump debugfs file\n");
0140         debugfs_remove(ioc->debugfs_root);
0141         return;
0142     }
0143 
0144     snprintf(name, sizeof(name), "host_recovery");
0145     debugfs_create_u8(name, 0444, ioc->debugfs_root, &ioc->shost_recovery);
0146 
0147 }
0148 
0149 /*
0150  * mpt3sas_destroy_debugfs :    Destroy debugfs per HBA adapter
0151  * @ioc:    MPT3SAS_ADAPTER object
0152  */
0153 void mpt3sas_destroy_debugfs(struct MPT3SAS_ADAPTER *ioc)
0154 {
0155     debugfs_remove_recursive(ioc->debugfs_root);
0156 }
0157