ipoib_fs.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. struct file_operations;
  35. #include <linux/debugfs.h>
  36. #include "ipoib.h"
  37. static struct dentry *ipoib_root;
  38. static void format_gid(union ib_gid *gid, char *buf)
  39. {
  40. int i, n;
  41. for (n = 0, i = 0; i < 8; ++i) {
  42. n += sprintf(buf + n, "%x",
  43. be16_to_cpu(((__be16 *) gid->raw)[i]));
  44. if (i < 7)
  45. buf[n++] = ':';
  46. }
  47. }
  48. static void *ipoib_mcg_seq_start(struct seq_file *file, loff_t *pos)
  49. {
  50. struct ipoib_mcast_iter *iter;
  51. loff_t n = *pos;
  52. iter = ipoib_mcast_iter_init(file->private);
  53. if (!iter)
  54. return NULL;
  55. while (n--) {
  56. if (ipoib_mcast_iter_next(iter)) {
  57. kfree(iter);
  58. return NULL;
  59. }
  60. }
  61. return iter;
  62. }
  63. static void *ipoib_mcg_seq_next(struct seq_file *file, void *iter_ptr,
  64. loff_t *pos)
  65. {
  66. struct ipoib_mcast_iter *iter = iter_ptr;
  67. (*pos)++;
  68. if (ipoib_mcast_iter_next(iter)) {
  69. kfree(iter);
  70. return NULL;
  71. }
  72. return iter;
  73. }
  74. static void ipoib_mcg_seq_stop(struct seq_file *file, void *iter_ptr)
  75. {
  76. /* nothing for now */
  77. }
  78. static int ipoib_mcg_seq_show(struct seq_file *file, void *iter_ptr)
  79. {
  80. struct ipoib_mcast_iter *iter = iter_ptr;
  81. char gid_buf[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
  82. union ib_gid mgid;
  83. unsigned long created;
  84. unsigned int queuelen, complete, send_only;
  85. if (!iter)
  86. return 0;
  87. ipoib_mcast_iter_read(iter, &mgid, &created, &queuelen,
  88. &complete, &send_only);
  89. format_gid(&mgid, gid_buf);
  90. seq_printf(file,
  91. "GID: %s\n"
  92. " created: %10ld\n"
  93. " queuelen: %9d\n"
  94. " complete: %9s\n"
  95. " send_only: %8s\n"
  96. "\n",
  97. gid_buf, created, queuelen,
  98. complete ? "yes" : "no",
  99. send_only ? "yes" : "no");
  100. return 0;
  101. }
  102. static const struct seq_operations ipoib_mcg_seq_ops = {
  103. .start = ipoib_mcg_seq_start,
  104. .next = ipoib_mcg_seq_next,
  105. .stop = ipoib_mcg_seq_stop,
  106. .show = ipoib_mcg_seq_show,
  107. };
  108. static int ipoib_mcg_open(struct inode *inode, struct file *file)
  109. {
  110. struct seq_file *seq;
  111. int ret;
  112. ret = seq_open(file, &ipoib_mcg_seq_ops);
  113. if (ret)
  114. return ret;
  115. seq = file->private_data;
  116. seq->private = inode->i_private;
  117. return 0;
  118. }
  119. static const struct file_operations ipoib_mcg_fops = {
  120. .owner = THIS_MODULE,
  121. .open = ipoib_mcg_open,
  122. .read = seq_read,
  123. .llseek = seq_lseek,
  124. .release = seq_release
  125. };
  126. static void *ipoib_path_seq_start(struct seq_file *file, loff_t *pos)
  127. {
  128. struct ipoib_path_iter *iter;
  129. loff_t n = *pos;
  130. iter = ipoib_path_iter_init(file->private);
  131. if (!iter)
  132. return NULL;
  133. while (n--) {
  134. if (ipoib_path_iter_next(iter)) {
  135. kfree(iter);
  136. return NULL;
  137. }
  138. }
  139. return iter;
  140. }
  141. static void *ipoib_path_seq_next(struct seq_file *file, void *iter_ptr,
  142. loff_t *pos)
  143. {
  144. struct ipoib_path_iter *iter = iter_ptr;
  145. (*pos)++;
  146. if (ipoib_path_iter_next(iter)) {
  147. kfree(iter);
  148. return NULL;
  149. }
  150. return iter;
  151. }
  152. static void ipoib_path_seq_stop(struct seq_file *file, void *iter_ptr)
  153. {
  154. /* nothing for now */
  155. }
  156. static int ipoib_path_seq_show(struct seq_file *file, void *iter_ptr)
  157. {
  158. struct ipoib_path_iter *iter = iter_ptr;
  159. char gid_buf[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
  160. struct ipoib_path path;
  161. int rate;
  162. if (!iter)
  163. return 0;
  164. ipoib_path_iter_read(iter, &path);
  165. format_gid(&path.pathrec.dgid, gid_buf);
  166. seq_printf(file,
  167. "GID: %s\n"
  168. " complete: %6s\n",
  169. gid_buf, path.pathrec.dlid ? "yes" : "no");
  170. if (path.pathrec.dlid) {
  171. rate = ib_rate_to_mult(path.pathrec.rate) * 25;
  172. seq_printf(file,
  173. " DLID: 0x%04x\n"
  174. " SL: %12d\n"
  175. " rate: %*d%s Gb/sec\n",
  176. be16_to_cpu(path.pathrec.dlid),
  177. path.pathrec.sl,
  178. 10 - ((rate % 10) ? 2 : 0),
  179. rate / 10, rate % 10 ? ".5" : "");
  180. }
  181. seq_putc(file, '\n');
  182. return 0;
  183. }
  184. static const struct seq_operations ipoib_path_seq_ops = {
  185. .start = ipoib_path_seq_start,
  186. .next = ipoib_path_seq_next,
  187. .stop = ipoib_path_seq_stop,
  188. .show = ipoib_path_seq_show,
  189. };
  190. static int ipoib_path_open(struct inode *inode, struct file *file)
  191. {
  192. struct seq_file *seq;
  193. int ret;
  194. ret = seq_open(file, &ipoib_path_seq_ops);
  195. if (ret)
  196. return ret;
  197. seq = file->private_data;
  198. seq->private = inode->i_private;
  199. return 0;
  200. }
  201. static const struct file_operations ipoib_path_fops = {
  202. .owner = THIS_MODULE,
  203. .open = ipoib_path_open,
  204. .read = seq_read,
  205. .llseek = seq_lseek,
  206. .release = seq_release
  207. };
  208. void ipoib_create_debug_files(struct net_device *dev)
  209. {
  210. struct ipoib_dev_priv *priv = netdev_priv(dev);
  211. char name[IFNAMSIZ + sizeof "_path"];
  212. snprintf(name, sizeof name, "%s_mcg", dev->name);
  213. priv->mcg_dentry = debugfs_create_file(name, S_IFREG | S_IRUGO,
  214. ipoib_root, dev, &ipoib_mcg_fops);
  215. if (!priv->mcg_dentry)
  216. ipoib_warn(priv, "failed to create mcg debug file\n");
  217. snprintf(name, sizeof name, "%s_path", dev->name);
  218. priv->path_dentry = debugfs_create_file(name, S_IFREG | S_IRUGO,
  219. ipoib_root, dev, &ipoib_path_fops);
  220. if (!priv->path_dentry)
  221. ipoib_warn(priv, "failed to create path debug file\n");
  222. }
  223. void ipoib_delete_debug_files(struct net_device *dev)
  224. {
  225. struct ipoib_dev_priv *priv = netdev_priv(dev);
  226. if (priv->mcg_dentry)
  227. debugfs_remove(priv->mcg_dentry);
  228. if (priv->path_dentry)
  229. debugfs_remove(priv->path_dentry);
  230. }
  231. int ipoib_register_debugfs(void)
  232. {
  233. ipoib_root = debugfs_create_dir("ipoib", NULL);
  234. return ipoib_root ? 0 : -ENOMEM;
  235. }
  236. void ipoib_unregister_debugfs(void)
  237. {
  238. debugfs_remove(ipoib_root);
  239. }