pci_debug.c 4.4 KB

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