megaraid_sas_debugfs.c 4.5 KB

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