pci_debug.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Copyright IBM Corp. 2012
  3. *
  4. * Author(s):
  5. * Jan Glauber <jang@linux.vnet.ibm.com>
  6. */
  7. #define KMSG_COMPONENT "zpci"
  8. #define pr_fmt(fmt) KMSG_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. };
  30. static char *pci_sw_names[] = {
  31. "Allocated pages",
  32. "Mapped pages",
  33. "Unmapped pages",
  34. };
  35. static void pci_sw_counter_show(struct seq_file *m)
  36. {
  37. struct zpci_dev *zdev = m->private;
  38. atomic64_t *counter = &zdev->allocated_pages;
  39. int i;
  40. for (i = 0; i < ARRAY_SIZE(pci_sw_names); i++, counter++)
  41. seq_printf(m, "%26s:\t%llu\n", pci_sw_names[i],
  42. atomic64_read(counter));
  43. }
  44. static int pci_perf_show(struct seq_file *m, void *v)
  45. {
  46. struct zpci_dev *zdev = m->private;
  47. u64 *stat;
  48. int i;
  49. if (!zdev)
  50. return 0;
  51. mutex_lock(&zdev->lock);
  52. if (!zdev->fmb) {
  53. mutex_unlock(&zdev->lock);
  54. seq_puts(m, "FMB statistics disabled\n");
  55. return 0;
  56. }
  57. /* header */
  58. seq_printf(m, "FMB @ %p\n", zdev->fmb);
  59. seq_printf(m, "Update interval: %u ms\n", zdev->fmb_update);
  60. seq_printf(m, "Samples: %u\n", zdev->fmb->samples);
  61. seq_printf(m, "Last update TOD: %Lx\n", zdev->fmb->last_update);
  62. /* hardware counters */
  63. stat = (u64 *) &zdev->fmb->ld_ops;
  64. for (i = 0; i < 4; i++)
  65. seq_printf(m, "%26s:\t%llu\n",
  66. pci_perf_names[i], *(stat + i));
  67. if (zdev->fmb->dma_valid)
  68. for (i = 4; i < 6; i++)
  69. seq_printf(m, "%26s:\t%llu\n",
  70. pci_perf_names[i], *(stat + i));
  71. pci_sw_counter_show(m);
  72. mutex_unlock(&zdev->lock);
  73. return 0;
  74. }
  75. static ssize_t pci_perf_seq_write(struct file *file, const char __user *ubuf,
  76. size_t count, loff_t *off)
  77. {
  78. struct zpci_dev *zdev = ((struct seq_file *) file->private_data)->private;
  79. unsigned long val;
  80. int rc;
  81. if (!zdev)
  82. return 0;
  83. rc = kstrtoul_from_user(ubuf, count, 10, &val);
  84. if (rc)
  85. return rc;
  86. mutex_lock(&zdev->lock);
  87. switch (val) {
  88. case 0:
  89. rc = zpci_fmb_disable_device(zdev);
  90. break;
  91. case 1:
  92. rc = zpci_fmb_enable_device(zdev);
  93. break;
  94. }
  95. mutex_unlock(&zdev->lock);
  96. return rc ? rc : count;
  97. }
  98. static int pci_perf_seq_open(struct inode *inode, struct file *filp)
  99. {
  100. return single_open(filp, pci_perf_show,
  101. file_inode(filp)->i_private);
  102. }
  103. static const struct file_operations debugfs_pci_perf_fops = {
  104. .open = pci_perf_seq_open,
  105. .read = seq_read,
  106. .write = pci_perf_seq_write,
  107. .llseek = seq_lseek,
  108. .release = single_release,
  109. };
  110. void zpci_debug_init_device(struct zpci_dev *zdev)
  111. {
  112. zdev->debugfs_dev = debugfs_create_dir(dev_name(&zdev->pdev->dev),
  113. debugfs_root);
  114. if (IS_ERR(zdev->debugfs_dev))
  115. zdev->debugfs_dev = NULL;
  116. zdev->debugfs_perf = debugfs_create_file("statistics",
  117. S_IFREG | S_IRUGO | S_IWUSR,
  118. zdev->debugfs_dev, zdev,
  119. &debugfs_pci_perf_fops);
  120. if (IS_ERR(zdev->debugfs_perf))
  121. zdev->debugfs_perf = NULL;
  122. }
  123. void zpci_debug_exit_device(struct zpci_dev *zdev)
  124. {
  125. debugfs_remove(zdev->debugfs_perf);
  126. debugfs_remove(zdev->debugfs_dev);
  127. }
  128. int __init zpci_debug_init(void)
  129. {
  130. /* event trace buffer */
  131. pci_debug_msg_id = debug_register("pci_msg", 8, 1, 8 * sizeof(long));
  132. if (!pci_debug_msg_id)
  133. return -EINVAL;
  134. debug_register_view(pci_debug_msg_id, &debug_sprintf_view);
  135. debug_set_level(pci_debug_msg_id, 3);
  136. /* error log */
  137. pci_debug_err_id = debug_register("pci_error", 2, 1, 16);
  138. if (!pci_debug_err_id)
  139. return -EINVAL;
  140. debug_register_view(pci_debug_err_id, &debug_hex_ascii_view);
  141. debug_set_level(pci_debug_err_id, 6);
  142. debugfs_root = debugfs_create_dir("pci", NULL);
  143. return 0;
  144. }
  145. void zpci_debug_exit(void)
  146. {
  147. debug_unregister(pci_debug_msg_id);
  148. debug_unregister(pci_debug_err_id);
  149. debugfs_remove(debugfs_root);
  150. }