mpt3sas_debugfs.c 3.7 KB

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