mic_debugfs.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * Intel MIC Platform Software Stack (MPSS)
  3. *
  4. * Copyright(c) 2013 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License, version 2, as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * The full GNU General Public License is included in this distribution in
  16. * the file called "COPYING".
  17. *
  18. * Intel MIC Host driver.
  19. *
  20. */
  21. #include <linux/debugfs.h>
  22. #include <linux/pci.h>
  23. #include <linux/seq_file.h>
  24. #include <linux/mic_common.h>
  25. #include "../common/mic_dev.h"
  26. #include "mic_device.h"
  27. #include "mic_smpt.h"
  28. /* Debugfs parent dir */
  29. static struct dentry *mic_dbg;
  30. static int mic_smpt_show(struct seq_file *s, void *pos)
  31. {
  32. int i;
  33. struct mic_device *mdev = s->private;
  34. unsigned long flags;
  35. seq_printf(s, "MIC %-2d |%-10s| %-14s %-10s\n",
  36. mdev->id, "SMPT entry", "SW DMA addr", "RefCount");
  37. seq_puts(s, "====================================================\n");
  38. if (mdev->smpt) {
  39. struct mic_smpt_info *smpt_info = mdev->smpt;
  40. spin_lock_irqsave(&smpt_info->smpt_lock, flags);
  41. for (i = 0; i < smpt_info->info.num_reg; i++) {
  42. seq_printf(s, "%9s|%-10d| %-#14llx %-10lld\n",
  43. " ", i, smpt_info->entry[i].dma_addr,
  44. smpt_info->entry[i].ref_count);
  45. }
  46. spin_unlock_irqrestore(&smpt_info->smpt_lock, flags);
  47. }
  48. seq_puts(s, "====================================================\n");
  49. return 0;
  50. }
  51. static int mic_smpt_debug_open(struct inode *inode, struct file *file)
  52. {
  53. return single_open(file, mic_smpt_show, inode->i_private);
  54. }
  55. static int mic_smpt_debug_release(struct inode *inode, struct file *file)
  56. {
  57. return single_release(inode, file);
  58. }
  59. static const struct file_operations smpt_file_ops = {
  60. .owner = THIS_MODULE,
  61. .open = mic_smpt_debug_open,
  62. .read = seq_read,
  63. .llseek = seq_lseek,
  64. .release = mic_smpt_debug_release
  65. };
  66. static int mic_post_code_show(struct seq_file *s, void *pos)
  67. {
  68. struct mic_device *mdev = s->private;
  69. u32 reg = mdev->ops->get_postcode(mdev);
  70. seq_printf(s, "%c%c", reg & 0xff, (reg >> 8) & 0xff);
  71. return 0;
  72. }
  73. static int mic_post_code_debug_open(struct inode *inode, struct file *file)
  74. {
  75. return single_open(file, mic_post_code_show, inode->i_private);
  76. }
  77. static int mic_post_code_debug_release(struct inode *inode, struct file *file)
  78. {
  79. return single_release(inode, file);
  80. }
  81. static const struct file_operations post_code_ops = {
  82. .owner = THIS_MODULE,
  83. .open = mic_post_code_debug_open,
  84. .read = seq_read,
  85. .llseek = seq_lseek,
  86. .release = mic_post_code_debug_release
  87. };
  88. static int mic_msi_irq_info_show(struct seq_file *s, void *pos)
  89. {
  90. struct mic_device *mdev = s->private;
  91. int reg;
  92. int i, j;
  93. u16 entry;
  94. u16 vector;
  95. struct pci_dev *pdev = mdev->pdev;
  96. if (pci_dev_msi_enabled(pdev)) {
  97. for (i = 0; i < mdev->irq_info.num_vectors; i++) {
  98. if (pdev->msix_enabled) {
  99. entry = mdev->irq_info.msix_entries[i].entry;
  100. vector = mdev->irq_info.msix_entries[i].vector;
  101. } else {
  102. entry = 0;
  103. vector = pdev->irq;
  104. }
  105. reg = mdev->intr_ops->read_msi_to_src_map(mdev, entry);
  106. seq_printf(s, "%s %-10d %s %-10d MXAR[%d]: %08X\n",
  107. "IRQ:", vector, "Entry:", entry, i, reg);
  108. seq_printf(s, "%-10s", "offset:");
  109. for (j = (MIC_NUM_OFFSETS - 1); j >= 0; j--)
  110. seq_printf(s, "%4d ", j);
  111. seq_puts(s, "\n");
  112. seq_printf(s, "%-10s", "count:");
  113. for (j = (MIC_NUM_OFFSETS - 1); j >= 0; j--)
  114. seq_printf(s, "%4d ",
  115. (mdev->irq_info.mic_msi_map[i] &
  116. BIT(j)) ? 1 : 0);
  117. seq_puts(s, "\n\n");
  118. }
  119. } else {
  120. seq_puts(s, "MSI/MSIx interrupts not enabled\n");
  121. }
  122. return 0;
  123. }
  124. static int mic_msi_irq_info_debug_open(struct inode *inode, struct file *file)
  125. {
  126. return single_open(file, mic_msi_irq_info_show, inode->i_private);
  127. }
  128. static int
  129. mic_msi_irq_info_debug_release(struct inode *inode, struct file *file)
  130. {
  131. return single_release(inode, file);
  132. }
  133. static const struct file_operations msi_irq_info_ops = {
  134. .owner = THIS_MODULE,
  135. .open = mic_msi_irq_info_debug_open,
  136. .read = seq_read,
  137. .llseek = seq_lseek,
  138. .release = mic_msi_irq_info_debug_release
  139. };
  140. /**
  141. * mic_create_debug_dir - Initialize MIC debugfs entries.
  142. */
  143. void mic_create_debug_dir(struct mic_device *mdev)
  144. {
  145. char name[16];
  146. if (!mic_dbg)
  147. return;
  148. scnprintf(name, sizeof(name), "mic%d", mdev->id);
  149. mdev->dbg_dir = debugfs_create_dir(name, mic_dbg);
  150. if (!mdev->dbg_dir)
  151. return;
  152. debugfs_create_file("smpt", 0444, mdev->dbg_dir, mdev, &smpt_file_ops);
  153. debugfs_create_file("post_code", 0444, mdev->dbg_dir, mdev,
  154. &post_code_ops);
  155. debugfs_create_file("msi_irq_info", 0444, mdev->dbg_dir, mdev,
  156. &msi_irq_info_ops);
  157. }
  158. /**
  159. * mic_delete_debug_dir - Uninitialize MIC debugfs entries.
  160. */
  161. void mic_delete_debug_dir(struct mic_device *mdev)
  162. {
  163. if (!mdev->dbg_dir)
  164. return;
  165. debugfs_remove_recursive(mdev->dbg_dir);
  166. }
  167. /**
  168. * mic_init_debugfs - Initialize global debugfs entry.
  169. */
  170. void __init mic_init_debugfs(void)
  171. {
  172. mic_dbg = debugfs_create_dir(KBUILD_MODNAME, NULL);
  173. if (!mic_dbg)
  174. pr_err("can't create debugfs dir\n");
  175. }
  176. /**
  177. * mic_exit_debugfs - Uninitialize global debugfs entry
  178. */
  179. void mic_exit_debugfs(void)
  180. {
  181. debugfs_remove(mic_dbg);
  182. }