scif_debugfs.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Intel MIC Platform Software Stack (MPSS)
  3. *
  4. * Copyright(c) 2014 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. * Intel SCIF driver.
  16. *
  17. */
  18. #include <linux/debugfs.h>
  19. #include <linux/seq_file.h>
  20. #include "../common/mic_dev.h"
  21. #include "scif_main.h"
  22. /* Debugfs parent dir */
  23. static struct dentry *scif_dbg;
  24. static int scif_dev_test(struct seq_file *s, void *unused)
  25. {
  26. int node;
  27. seq_printf(s, "Total Nodes %d Self Node Id %d Maxid %d\n",
  28. scif_info.total, scif_info.nodeid,
  29. scif_info.maxid);
  30. if (!scif_dev)
  31. return 0;
  32. seq_printf(s, "%-16s\t%-16s\n", "node_id", "state");
  33. for (node = 0; node <= scif_info.maxid; node++)
  34. seq_printf(s, "%-16d\t%-16s\n", scif_dev[node].node,
  35. _scifdev_alive(&scif_dev[node]) ?
  36. "Running" : "Offline");
  37. return 0;
  38. }
  39. static int scif_dev_test_open(struct inode *inode, struct file *file)
  40. {
  41. return single_open(file, scif_dev_test, inode->i_private);
  42. }
  43. static int scif_dev_test_release(struct inode *inode, struct file *file)
  44. {
  45. return single_release(inode, file);
  46. }
  47. static const struct file_operations scif_dev_ops = {
  48. .owner = THIS_MODULE,
  49. .open = scif_dev_test_open,
  50. .read = seq_read,
  51. .llseek = seq_lseek,
  52. .release = scif_dev_test_release
  53. };
  54. static void scif_display_window(struct scif_window *window, struct seq_file *s)
  55. {
  56. int j;
  57. struct scatterlist *sg;
  58. scif_pinned_pages_t pin = window->pinned_pages;
  59. seq_printf(s, "window %p type %d temp %d offset 0x%llx ",
  60. window, window->type, window->temp, window->offset);
  61. seq_printf(s, "nr_pages 0x%llx nr_contig_chunks 0x%x prot %d ",
  62. window->nr_pages, window->nr_contig_chunks, window->prot);
  63. seq_printf(s, "ref_count %d magic 0x%llx peer_window 0x%llx ",
  64. window->ref_count, window->magic, window->peer_window);
  65. seq_printf(s, "unreg_state 0x%x va_for_temp 0x%lx\n",
  66. window->unreg_state, window->va_for_temp);
  67. for (j = 0; j < window->nr_contig_chunks; j++)
  68. seq_printf(s, "page[%d] dma_addr 0x%llx num_pages 0x%llx\n", j,
  69. window->dma_addr[j], window->num_pages[j]);
  70. if (window->type == SCIF_WINDOW_SELF && pin)
  71. for (j = 0; j < window->nr_pages; j++)
  72. seq_printf(s, "page[%d] = pinned_pages %p address %p\n",
  73. j, pin->pages[j],
  74. page_address(pin->pages[j]));
  75. if (window->st)
  76. for_each_sg(window->st->sgl, sg, window->st->nents, j)
  77. seq_printf(s, "sg[%d] dma addr 0x%llx length 0x%x\n",
  78. j, sg_dma_address(sg), sg_dma_len(sg));
  79. }
  80. static void scif_display_all_windows(struct list_head *head, struct seq_file *s)
  81. {
  82. struct list_head *item;
  83. struct scif_window *window;
  84. list_for_each(item, head) {
  85. window = list_entry(item, struct scif_window, list);
  86. scif_display_window(window, s);
  87. }
  88. }
  89. static int scif_rma_test(struct seq_file *s, void *unused)
  90. {
  91. struct scif_endpt *ep;
  92. struct list_head *pos;
  93. mutex_lock(&scif_info.connlock);
  94. list_for_each(pos, &scif_info.connected) {
  95. ep = list_entry(pos, struct scif_endpt, list);
  96. seq_printf(s, "ep %p self windows\n", ep);
  97. mutex_lock(&ep->rma_info.rma_lock);
  98. scif_display_all_windows(&ep->rma_info.reg_list, s);
  99. seq_printf(s, "ep %p remote windows\n", ep);
  100. scif_display_all_windows(&ep->rma_info.remote_reg_list, s);
  101. mutex_unlock(&ep->rma_info.rma_lock);
  102. }
  103. mutex_unlock(&scif_info.connlock);
  104. return 0;
  105. }
  106. static int scif_rma_test_open(struct inode *inode, struct file *file)
  107. {
  108. return single_open(file, scif_rma_test, inode->i_private);
  109. }
  110. static int scif_rma_test_release(struct inode *inode, struct file *file)
  111. {
  112. return single_release(inode, file);
  113. }
  114. static const struct file_operations scif_rma_ops = {
  115. .owner = THIS_MODULE,
  116. .open = scif_rma_test_open,
  117. .read = seq_read,
  118. .llseek = seq_lseek,
  119. .release = scif_rma_test_release
  120. };
  121. void __init scif_init_debugfs(void)
  122. {
  123. scif_dbg = debugfs_create_dir(KBUILD_MODNAME, NULL);
  124. if (!scif_dbg) {
  125. dev_err(scif_info.mdev.this_device,
  126. "can't create debugfs dir scif\n");
  127. return;
  128. }
  129. debugfs_create_file("scif_dev", 0444, scif_dbg, NULL, &scif_dev_ops);
  130. debugfs_create_file("scif_rma", 0444, scif_dbg, NULL, &scif_rma_ops);
  131. debugfs_create_u8("en_msg_log", 0666, scif_dbg, &scif_info.en_msg_log);
  132. debugfs_create_u8("p2p_enable", 0666, scif_dbg, &scif_info.p2p_enable);
  133. }
  134. void scif_exit_debugfs(void)
  135. {
  136. debugfs_remove_recursive(scif_dbg);
  137. }