ipoib_fs.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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_seq_ops = {
  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. static int ipoib_mcg_open(struct inode *inode, struct file *file)
  111. {
  112. struct seq_file *seq;
  113. int ret;
  114. ret = seq_open(file, &ipoib_mcg_seq_ops);
  115. if (ret)
  116. return ret;
  117. seq = file->private_data;
  118. seq->private = inode->i_private;
  119. return 0;
  120. }
  121. static const struct file_operations ipoib_mcg_fops = {
  122. .owner = THIS_MODULE,
  123. .open = ipoib_mcg_open,
  124. .read = seq_read,
  125. .llseek = seq_lseek,
  126. .release = seq_release
  127. };
  128. static void *ipoib_path_seq_start(struct seq_file *file, loff_t *pos)
  129. {
  130. struct ipoib_path_iter *iter;
  131. loff_t n = *pos;
  132. iter = ipoib_path_iter_init(file->private);
  133. if (!iter)
  134. return NULL;
  135. while (n--) {
  136. if (ipoib_path_iter_next(iter)) {
  137. kfree(iter);
  138. return NULL;
  139. }
  140. }
  141. return iter;
  142. }
  143. static void *ipoib_path_seq_next(struct seq_file *file, void *iter_ptr,
  144. loff_t *pos)
  145. {
  146. struct ipoib_path_iter *iter = iter_ptr;
  147. (*pos)++;
  148. if (ipoib_path_iter_next(iter)) {
  149. kfree(iter);
  150. return NULL;
  151. }
  152. return iter;
  153. }
  154. static void ipoib_path_seq_stop(struct seq_file *file, void *iter_ptr)
  155. {
  156. /* nothing for now */
  157. }
  158. static int ipoib_path_seq_show(struct seq_file *file, void *iter_ptr)
  159. {
  160. struct ipoib_path_iter *iter = iter_ptr;
  161. char gid_buf[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
  162. struct ipoib_path path;
  163. int rate;
  164. if (!iter)
  165. return 0;
  166. ipoib_path_iter_read(iter, &path);
  167. format_gid(&path.pathrec.dgid, gid_buf);
  168. seq_printf(file,
  169. "GID: %s\n"
  170. " complete: %6s\n",
  171. gid_buf, path.pathrec.dlid ? "yes" : "no");
  172. if (path.pathrec.dlid) {
  173. rate = ib_rate_to_mbps(path.pathrec.rate);
  174. seq_printf(file,
  175. " DLID: 0x%04x\n"
  176. " SL: %12d\n"
  177. " rate: %8d.%d Gb/sec\n",
  178. be16_to_cpu(path.pathrec.dlid),
  179. path.pathrec.sl,
  180. rate / 1000, rate % 1000);
  181. }
  182. seq_putc(file, '\n');
  183. return 0;
  184. }
  185. static const struct seq_operations ipoib_path_seq_ops = {
  186. .start = ipoib_path_seq_start,
  187. .next = ipoib_path_seq_next,
  188. .stop = ipoib_path_seq_stop,
  189. .show = ipoib_path_seq_show,
  190. };
  191. static int ipoib_path_open(struct inode *inode, struct file *file)
  192. {
  193. struct seq_file *seq;
  194. int ret;
  195. ret = seq_open(file, &ipoib_path_seq_ops);
  196. if (ret)
  197. return ret;
  198. seq = file->private_data;
  199. seq->private = inode->i_private;
  200. return 0;
  201. }
  202. static const struct file_operations ipoib_path_fops = {
  203. .owner = THIS_MODULE,
  204. .open = ipoib_path_open,
  205. .read = seq_read,
  206. .llseek = seq_lseek,
  207. .release = seq_release
  208. };
  209. void ipoib_create_debug_files(struct net_device *dev)
  210. {
  211. struct ipoib_dev_priv *priv = netdev_priv(dev);
  212. char name[IFNAMSIZ + sizeof "_path"];
  213. snprintf(name, sizeof name, "%s_mcg", dev->name);
  214. priv->mcg_dentry = debugfs_create_file(name, S_IFREG | S_IRUGO,
  215. ipoib_root, dev, &ipoib_mcg_fops);
  216. if (!priv->mcg_dentry)
  217. ipoib_warn(priv, "failed to create mcg debug file\n");
  218. snprintf(name, sizeof name, "%s_path", dev->name);
  219. priv->path_dentry = debugfs_create_file(name, S_IFREG | S_IRUGO,
  220. ipoib_root, dev, &ipoib_path_fops);
  221. if (!priv->path_dentry)
  222. ipoib_warn(priv, "failed to create path debug file\n");
  223. }
  224. void ipoib_delete_debug_files(struct net_device *dev)
  225. {
  226. struct ipoib_dev_priv *priv = netdev_priv(dev);
  227. WARN_ONCE(!priv->mcg_dentry, "null mcg debug file\n");
  228. WARN_ONCE(!priv->path_dentry, "null path debug file\n");
  229. debugfs_remove(priv->mcg_dentry);
  230. debugfs_remove(priv->path_dentry);
  231. priv->mcg_dentry = priv->path_dentry = NULL;
  232. }
  233. int ipoib_register_debugfs(void)
  234. {
  235. ipoib_root = debugfs_create_dir("ipoib", NULL);
  236. return ipoib_root ? 0 : -ENOMEM;
  237. }
  238. void ipoib_unregister_debugfs(void)
  239. {
  240. debugfs_remove(ipoib_root);
  241. }