^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Debugfs interface Support for MPT (Message Passing Technology) based
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * controllers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2020 Broadcom Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Authors: Broadcom Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Sreekanth Reddy <sreekanth.reddy@broadcom.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Suganath Prabu <suganath-prabu.subramani@broadcom.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Send feedback to : MPT-FusionLinux.pdl@broadcom.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/uio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <scsi/scsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <scsi/scsi_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "mpt3sas_base.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static struct dentry *mpt3sas_debugfs_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * _debugfs_iocdump_read - copy ioc dump from debugfs buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * @filep: File Pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * @ubuf: Buffer to fill data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * @cnt: Length of the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * @ppos: Offset in the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) _debugfs_iocdump_read(struct file *filp, char __user *ubuf, size_t cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct mpt3sas_debugfs_buffer *debug = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (!debug || !debug->buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return simple_read_from_buffer(ubuf, cnt, ppos, debug->buf, debug->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * _debugfs_iocdump_open : open the ioc_dump debugfs attribute file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) _debugfs_iocdump_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct MPT3SAS_ADAPTER *ioc = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct mpt3sas_debugfs_buffer *debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) debug = kzalloc(sizeof(struct mpt3sas_debugfs_buffer), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) if (!debug)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) debug->buf = (void *)ioc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) debug->len = sizeof(struct MPT3SAS_ADAPTER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) file->private_data = debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * _debugfs_iocdump_release : release the ioc_dump debugfs attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * @inode: inode structure to the corresponds device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * @file: File pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) _debugfs_iocdump_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct mpt3sas_debugfs_buffer *debug = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if (!debug)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) file->private_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) kfree(debug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) static const struct file_operations mpt3sas_debugfs_iocdump_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) .open = _debugfs_iocdump_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) .read = _debugfs_iocdump_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) .release = _debugfs_iocdump_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * mpt3sas_init_debugfs : Create debugfs root for mpt3sas driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) void mpt3sas_init_debugfs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) mpt3sas_debugfs_root = debugfs_create_dir("mpt3sas", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (!mpt3sas_debugfs_root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) pr_info("mpt3sas: Cannot create debugfs root\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * mpt3sas_exit_debugfs : Remove debugfs root for mpt3sas driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) void mpt3sas_exit_debugfs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) debugfs_remove_recursive(mpt3sas_debugfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * mpt3sas_setup_debugfs : Setup debugfs per HBA adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * ioc: MPT3SAS_ADAPTER object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) mpt3sas_setup_debugfs(struct MPT3SAS_ADAPTER *ioc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) char name[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) snprintf(name, sizeof(name), "scsi_host%d", ioc->shost->host_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (!ioc->debugfs_root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) ioc->debugfs_root =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) debugfs_create_dir(name, mpt3sas_debugfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (!ioc->debugfs_root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) dev_err(&ioc->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) "Cannot create per adapter debugfs directory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) snprintf(name, sizeof(name), "ioc_dump");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) ioc->ioc_dump = debugfs_create_file(name, 0444,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) ioc->debugfs_root, ioc, &mpt3sas_debugfs_iocdump_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (!ioc->ioc_dump) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) dev_err(&ioc->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) "Cannot create ioc_dump debugfs file\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) debugfs_remove(ioc->debugfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) snprintf(name, sizeof(name), "host_recovery");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) debugfs_create_u8(name, 0444, ioc->debugfs_root, &ioc->shost_recovery);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * mpt3sas_destroy_debugfs : Destroy debugfs per HBA adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * @ioc: MPT3SAS_ADAPTER object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) void mpt3sas_destroy_debugfs(struct MPT3SAS_ADAPTER *ioc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) debugfs_remove_recursive(ioc->debugfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)