pci_debug.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * Copyright IBM Corp. 2012
  3. *
  4. * Author(s):
  5. * Jan Glauber <jang@linux.vnet.ibm.com>
  6. */
  7. #define COMPONENT "zPCI"
  8. #define pr_fmt(fmt) COMPONENT ": " fmt
  9. #include <linux/kernel.h>
  10. #include <linux/seq_file.h>
  11. #include <linux/debugfs.h>
  12. #include <linux/export.h>
  13. #include <linux/pci.h>
  14. #include <asm/debug.h>
  15. #include <asm/pci_dma.h>
  16. static struct dentry *debugfs_root;
  17. debug_info_t *pci_debug_msg_id;
  18. EXPORT_SYMBOL_GPL(pci_debug_msg_id);
  19. debug_info_t *pci_debug_err_id;
  20. EXPORT_SYMBOL_GPL(pci_debug_err_id);
  21. static char *pci_perf_names[] = {
  22. /* hardware counters */
  23. "Load operations",
  24. "Store operations",
  25. "Store block operations",
  26. "Refresh operations",
  27. "DMA read bytes",
  28. "DMA write bytes",
  29. /* software counters */
  30. "Allocated pages",
  31. "Mapped pages",
  32. "Unmapped pages",
  33. };
  34. static int pci_perf_show(struct seq_file *m, void *v)
  35. {
  36. struct zpci_dev *zdev = m->private;
  37. u64 *stat;
  38. int i;
  39. if (!zdev)
  40. return 0;
  41. if (!zdev->fmb)
  42. return seq_printf(m, "FMB statistics disabled\n");
  43. /* header */
  44. seq_printf(m, "FMB @ %p\n", zdev->fmb);
  45. seq_printf(m, "Update interval: %u ms\n", zdev->fmb_update);
  46. seq_printf(m, "Samples: %u\n", zdev->fmb->samples);
  47. seq_printf(m, "Last update TOD: %Lx\n", zdev->fmb->last_update);
  48. /* hardware counters */
  49. stat = (u64 *) &zdev->fmb->ld_ops;
  50. for (i = 0; i < 4; i++)
  51. seq_printf(m, "%26s:\t%llu\n",
  52. pci_perf_names[i], *(stat + i));
  53. if (zdev->fmb->dma_valid)
  54. for (i = 4; i < 6; i++)
  55. seq_printf(m, "%26s:\t%llu\n",
  56. pci_perf_names[i], *(stat + i));
  57. /* software counters */
  58. for (i = 6; i < ARRAY_SIZE(pci_perf_names); i++)
  59. seq_printf(m, "%26s:\t%llu\n",
  60. pci_perf_names[i],
  61. atomic64_read((atomic64_t *) (stat + i)));
  62. return 0;
  63. }
  64. static ssize_t pci_perf_seq_write(struct file *file, const char __user *ubuf,
  65. size_t count, loff_t *off)
  66. {
  67. struct zpci_dev *zdev = ((struct seq_file *) file->private_data)->private;
  68. unsigned long val;
  69. int rc;
  70. if (!zdev)
  71. return 0;
  72. rc = kstrtoul_from_user(ubuf, count, 10, &val);
  73. if (rc)
  74. return rc;
  75. switch (val) {
  76. case 0:
  77. rc = zpci_fmb_disable_device(zdev);
  78. if (rc)
  79. return rc;
  80. break;
  81. case 1:
  82. rc = zpci_fmb_enable_device(zdev);
  83. if (rc)
  84. return rc;
  85. break;
  86. }
  87. return count;
  88. }
  89. static int pci_perf_seq_open(struct inode *inode, struct file *filp)
  90. {
  91. return single_open(filp, pci_perf_show,
  92. file_inode(filp)->i_private);
  93. }
  94. static const struct file_operations debugfs_pci_perf_fops = {
  95. .open = pci_perf_seq_open,
  96. .read = seq_read,
  97. .write = pci_perf_seq_write,
  98. .llseek = seq_lseek,
  99. .release = single_release,
  100. };
  101. static int pci_debug_show(struct seq_file *m, void *v)
  102. {
  103. struct zpci_dev *zdev = m->private;
  104. zpci_debug_info(zdev, m);
  105. return 0;
  106. }
  107. static int pci_debug_seq_open(struct inode *inode, struct file *filp)
  108. {
  109. return single_open(filp, pci_debug_show,
  110. file_inode(filp)->i_private);
  111. }
  112. static const struct file_operations debugfs_pci_debug_fops = {
  113. .open = pci_debug_seq_open,
  114. .read = seq_read,
  115. .llseek = seq_lseek,
  116. .release = single_release,
  117. };
  118. void zpci_debug_init_device(struct zpci_dev *zdev)
  119. {
  120. zdev->debugfs_dev = debugfs_create_dir(dev_name(&zdev->pdev->dev),
  121. debugfs_root);
  122. if (IS_ERR(zdev->debugfs_dev))
  123. zdev->debugfs_dev = NULL;
  124. zdev->debugfs_perf = debugfs_create_file("statistics",
  125. S_IFREG | S_IRUGO | S_IWUSR,
  126. zdev->debugfs_dev, zdev,
  127. &debugfs_pci_perf_fops);
  128. if (IS_ERR(zdev->debugfs_perf))
  129. zdev->debugfs_perf = NULL;
  130. zdev->debugfs_debug = debugfs_create_file("debug",
  131. S_IFREG | S_IRUGO | S_IWUSR,
  132. zdev->debugfs_dev, zdev,
  133. &debugfs_pci_debug_fops);
  134. if (IS_ERR(zdev->debugfs_debug))
  135. zdev->debugfs_debug = NULL;
  136. }
  137. void zpci_debug_exit_device(struct zpci_dev *zdev)
  138. {
  139. debugfs_remove(zdev->debugfs_perf);
  140. debugfs_remove(zdev->debugfs_debug);
  141. debugfs_remove(zdev->debugfs_dev);
  142. }
  143. int __init zpci_debug_init(void)
  144. {
  145. /* event trace buffer */
  146. pci_debug_msg_id = debug_register("pci_msg", 16, 1, 16 * sizeof(long));
  147. if (!pci_debug_msg_id)
  148. return -EINVAL;
  149. debug_register_view(pci_debug_msg_id, &debug_sprintf_view);
  150. debug_set_level(pci_debug_msg_id, 3);
  151. /* error log */
  152. pci_debug_err_id = debug_register("pci_error", 2, 1, 16);
  153. if (!pci_debug_err_id)
  154. return -EINVAL;
  155. debug_register_view(pci_debug_err_id, &debug_hex_ascii_view);
  156. debug_set_level(pci_debug_err_id, 6);
  157. debugfs_root = debugfs_create_dir("pci", NULL);
  158. return 0;
  159. }
  160. void zpci_debug_exit(void)
  161. {
  162. if (pci_debug_msg_id)
  163. debug_unregister(pci_debug_msg_id);
  164. if (pci_debug_err_id)
  165. debug_unregister(pci_debug_err_id);
  166. debugfs_remove(debugfs_root);
  167. }