ipoib_fs.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. * Copyright (c) 2004 Topspin Communications. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/err.h>
  33. #include <linux/seq_file.h>
  34. #include <linux/slab.h>
  35. struct file_operations;
  36. #include <linux/debugfs.h>
  37. #include <linux/export.h>
  38. #include "ipoib.h"
  39. static struct dentry *ipoib_root;
  40. static void format_gid(union ib_gid *gid, char *buf)
  41. {
  42. int i, n;
  43. for (n = 0, i = 0; i < 8; ++i) {
  44. n += sprintf(buf + n, "%x",
  45. be16_to_cpu(((__be16 *) gid->raw)[i]));
  46. if (i < 7)
  47. buf[n++] = ':';
  48. }
  49. }
  50. static void *ipoib_mcg_seq_start(struct seq_file *file, loff_t *pos)
  51. {
  52. struct ipoib_mcast_iter *iter;
  53. loff_t n = *pos;
  54. iter = ipoib_mcast_iter_init(file->private);
  55. if (!iter)
  56. return NULL;
  57. while (n--) {
  58. if (ipoib_mcast_iter_next(iter)) {
  59. kfree(iter);
  60. return NULL;
  61. }
  62. }
  63. return iter;
  64. }
  65. static void *ipoib_mcg_seq_next(struct seq_file *file, void *iter_ptr,
  66. loff_t *pos)
  67. {
  68. struct ipoib_mcast_iter *iter = iter_ptr;
  69. (*pos)++;
  70. if (ipoib_mcast_iter_next(iter)) {
  71. kfree(iter);
  72. return NULL;
  73. }
  74. return iter;
  75. }
  76. static void ipoib_mcg_seq_stop(struct seq_file *file, void *iter_ptr)
  77. {
  78. /* nothing for now */
  79. }
  80. static int ipoib_mcg_seq_show(struct seq_file *file, void *iter_ptr)
  81. {
  82. struct ipoib_mcast_iter *iter = iter_ptr;
  83. char gid_buf[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
  84. union ib_gid mgid;
  85. unsigned long created;
  86. unsigned int queuelen, complete, send_only;
  87. if (!iter)
  88. return 0;
  89. ipoib_mcast_iter_read(iter, &mgid, &created, &queuelen,
  90. &complete, &send_only);
  91. format_gid(&mgid, gid_buf);
  92. seq_printf(file,
  93. "GID: %s\n"
  94. " created: %10ld\n"
  95. " queuelen: %9d\n"
  96. " complete: %9s\n"
  97. " send_only: %8s\n"
  98. "\n",
  99. gid_buf, created, queuelen,
  100. complete ? "yes" : "no",
  101. send_only ? "yes" : "no");
  102. return 0;
  103. }
  104. static const struct seq_operations ipoib_mcg_sops = {
  105. .start = ipoib_mcg_seq_start,
  106. .next = ipoib_mcg_seq_next,
  107. .stop = ipoib_mcg_seq_stop,
  108. .show = ipoib_mcg_seq_show,
  109. };
  110. DEFINE_SEQ_ATTRIBUTE(ipoib_mcg);
  111. static void *ipoib_path_seq_start(struct seq_file *file, loff_t *pos)
  112. {
  113. struct ipoib_path_iter *iter;
  114. loff_t n = *pos;
  115. iter = ipoib_path_iter_init(file->private);
  116. if (!iter)
  117. return NULL;
  118. while (n--) {
  119. if (ipoib_path_iter_next(iter)) {
  120. kfree(iter);
  121. return NULL;
  122. }
  123. }
  124. return iter;
  125. }
  126. static void *ipoib_path_seq_next(struct seq_file *file, void *iter_ptr,
  127. loff_t *pos)
  128. {
  129. struct ipoib_path_iter *iter = iter_ptr;
  130. (*pos)++;
  131. if (ipoib_path_iter_next(iter)) {
  132. kfree(iter);
  133. return NULL;
  134. }
  135. return iter;
  136. }
  137. static void ipoib_path_seq_stop(struct seq_file *file, void *iter_ptr)
  138. {
  139. /* nothing for now */
  140. }
  141. static int ipoib_path_seq_show(struct seq_file *file, void *iter_ptr)
  142. {
  143. struct ipoib_path_iter *iter = iter_ptr;
  144. char gid_buf[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
  145. struct ipoib_path path;
  146. int rate;
  147. if (!iter)
  148. return 0;
  149. ipoib_path_iter_read(iter, &path);
  150. format_gid(&path.pathrec.dgid, gid_buf);
  151. seq_printf(file,
  152. "GID: %s\n"
  153. " complete: %6s\n",
  154. gid_buf, sa_path_get_dlid(&path.pathrec) ? "yes" : "no");
  155. if (sa_path_get_dlid(&path.pathrec)) {
  156. rate = ib_rate_to_mbps(path.pathrec.rate);
  157. seq_printf(file,
  158. " DLID: 0x%04x\n"
  159. " SL: %12d\n"
  160. " rate: %8d.%d Gb/sec\n",
  161. be32_to_cpu(sa_path_get_dlid(&path.pathrec)),
  162. path.pathrec.sl,
  163. rate / 1000, rate % 1000);
  164. }
  165. seq_putc(file, '\n');
  166. return 0;
  167. }
  168. static const struct seq_operations ipoib_path_sops = {
  169. .start = ipoib_path_seq_start,
  170. .next = ipoib_path_seq_next,
  171. .stop = ipoib_path_seq_stop,
  172. .show = ipoib_path_seq_show,
  173. };
  174. DEFINE_SEQ_ATTRIBUTE(ipoib_path);
  175. void ipoib_create_debug_files(struct net_device *dev)
  176. {
  177. struct ipoib_dev_priv *priv = ipoib_priv(dev);
  178. char name[IFNAMSIZ + sizeof("_path")];
  179. snprintf(name, sizeof(name), "%s_mcg", dev->name);
  180. priv->mcg_dentry = debugfs_create_file(name, S_IFREG | S_IRUGO,
  181. ipoib_root, dev, &ipoib_mcg_fops);
  182. snprintf(name, sizeof(name), "%s_path", dev->name);
  183. priv->path_dentry = debugfs_create_file(name, S_IFREG | S_IRUGO,
  184. ipoib_root, dev, &ipoib_path_fops);
  185. }
  186. void ipoib_delete_debug_files(struct net_device *dev)
  187. {
  188. struct ipoib_dev_priv *priv = ipoib_priv(dev);
  189. debugfs_remove(priv->mcg_dentry);
  190. debugfs_remove(priv->path_dentry);
  191. priv->mcg_dentry = priv->path_dentry = NULL;
  192. }
  193. void ipoib_register_debugfs(void)
  194. {
  195. ipoib_root = debugfs_create_dir("ipoib", NULL);
  196. }
  197. void ipoib_unregister_debugfs(void)
  198. {
  199. debugfs_remove(ipoib_root);
  200. }