ipoib_fs.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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 "ipoib.h"
  38. static struct dentry *ipoib_root;
  39. static void format_gid(union ib_gid *gid, char *buf)
  40. {
  41. int i, n;
  42. for (n = 0, i = 0; i < 8; ++i) {
  43. n += sprintf(buf + n, "%x",
  44. be16_to_cpu(((__be16 *) gid->raw)[i]));
  45. if (i < 7)
  46. buf[n++] = ':';
  47. }
  48. }
  49. static void *ipoib_mcg_seq_start(struct seq_file *file, loff_t *pos)
  50. {
  51. struct ipoib_mcast_iter *iter;
  52. loff_t n = *pos;
  53. iter = ipoib_mcast_iter_init(file->private);
  54. if (!iter)
  55. return NULL;
  56. while (n--) {
  57. if (ipoib_mcast_iter_next(iter)) {
  58. kfree(iter);
  59. return NULL;
  60. }
  61. }
  62. return iter;
  63. }
  64. static void *ipoib_mcg_seq_next(struct seq_file *file, void *iter_ptr,
  65. loff_t *pos)
  66. {
  67. struct ipoib_mcast_iter *iter = iter_ptr;
  68. (*pos)++;
  69. if (ipoib_mcast_iter_next(iter)) {
  70. kfree(iter);
  71. return NULL;
  72. }
  73. return iter;
  74. }
  75. static void ipoib_mcg_seq_stop(struct seq_file *file, void *iter_ptr)
  76. {
  77. /* nothing for now */
  78. }
  79. static int ipoib_mcg_seq_show(struct seq_file *file, void *iter_ptr)
  80. {
  81. struct ipoib_mcast_iter *iter = iter_ptr;
  82. char gid_buf[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
  83. union ib_gid mgid;
  84. unsigned long created;
  85. unsigned int queuelen, complete, send_only;
  86. if (!iter)
  87. return 0;
  88. ipoib_mcast_iter_read(iter, &mgid, &created, &queuelen,
  89. &complete, &send_only);
  90. format_gid(&mgid, gid_buf);
  91. seq_printf(file,
  92. "GID: %s\n"
  93. " created: %10ld\n"
  94. " queuelen: %9d\n"
  95. " complete: %9s\n"
  96. " send_only: %8s\n"
  97. "\n",
  98. gid_buf, created, queuelen,
  99. complete ? "yes" : "no",
  100. send_only ? "yes" : "no");
  101. return 0;
  102. }
  103. static const struct seq_operations ipoib_mcg_seq_ops = {
  104. .start = ipoib_mcg_seq_start,
  105. .next = ipoib_mcg_seq_next,
  106. .stop = ipoib_mcg_seq_stop,
  107. .show = ipoib_mcg_seq_show,
  108. };
  109. static int ipoib_mcg_open(struct inode *inode, struct file *file)
  110. {
  111. struct seq_file *seq;
  112. int ret;
  113. ret = seq_open(file, &ipoib_mcg_seq_ops);
  114. if (ret)
  115. return ret;
  116. seq = file->private_data;
  117. seq->private = inode->i_private;
  118. return 0;
  119. }
  120. static const struct file_operations ipoib_mcg_fops = {
  121. .owner = THIS_MODULE,
  122. .open = ipoib_mcg_open,
  123. .read = seq_read,
  124. .llseek = seq_lseek,
  125. .release = seq_release
  126. };
  127. static void *ipoib_path_seq_start(struct seq_file *file, loff_t *pos)
  128. {
  129. struct ipoib_path_iter *iter;
  130. loff_t n = *pos;
  131. iter = ipoib_path_iter_init(file->private);
  132. if (!iter)
  133. return NULL;
  134. while (n--) {
  135. if (ipoib_path_iter_next(iter)) {
  136. kfree(iter);
  137. return NULL;
  138. }
  139. }
  140. return iter;
  141. }
  142. static void *ipoib_path_seq_next(struct seq_file *file, void *iter_ptr,
  143. loff_t *pos)
  144. {
  145. struct ipoib_path_iter *iter = iter_ptr;
  146. (*pos)++;
  147. if (ipoib_path_iter_next(iter)) {
  148. kfree(iter);
  149. return NULL;
  150. }
  151. return iter;
  152. }
  153. static void ipoib_path_seq_stop(struct seq_file *file, void *iter_ptr)
  154. {
  155. /* nothing for now */
  156. }
  157. static int ipoib_path_seq_show(struct seq_file *file, void *iter_ptr)
  158. {
  159. struct ipoib_path_iter *iter = iter_ptr;
  160. char gid_buf[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
  161. struct ipoib_path path;
  162. int rate;
  163. if (!iter)
  164. return 0;
  165. ipoib_path_iter_read(iter, &path);
  166. format_gid(&path.pathrec.dgid, gid_buf);
  167. seq_printf(file,
  168. "GID: %s\n"
  169. " complete: %6s\n",
  170. gid_buf, path.pathrec.dlid ? "yes" : "no");
  171. if (path.pathrec.dlid) {
  172. rate = ib_rate_to_mult(path.pathrec.rate) * 25;
  173. seq_printf(file,
  174. " DLID: 0x%04x\n"
  175. " SL: %12d\n"
  176. " rate: %*d%s Gb/sec\n",
  177. be16_to_cpu(path.pathrec.dlid),
  178. path.pathrec.sl,
  179. 10 - ((rate % 10) ? 2 : 0),
  180. rate / 10, rate % 10 ? ".5" : "");
  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. if (priv->mcg_dentry)
  228. debugfs_remove(priv->mcg_dentry);
  229. if (priv->path_dentry)
  230. debugfs_remove(priv->path_dentry);
  231. }
  232. int ipoib_register_debugfs(void)
  233. {
  234. ipoib_root = debugfs_create_dir("ipoib", NULL);
  235. return ipoib_root ? 0 : -ENOMEM;
  236. }
  237. void ipoib_unregister_debugfs(void)
  238. {
  239. debugfs_remove(ipoib_root);
  240. }