ipoib_fs.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. * $Id: ipoib_fs.c 1389 2004-12-27 22:56:47Z roland $
  33. */
  34. #include <linux/err.h>
  35. #include <linux/seq_file.h>
  36. struct file_operations;
  37. #include <linux/debugfs.h>
  38. #include "ipoib.h"
  39. static struct dentry *ipoib_root;
  40. static void *ipoib_mcg_seq_start(struct seq_file *file, loff_t *pos)
  41. {
  42. struct ipoib_mcast_iter *iter;
  43. loff_t n = *pos;
  44. iter = ipoib_mcast_iter_init(file->private);
  45. if (!iter)
  46. return NULL;
  47. while (n--) {
  48. if (ipoib_mcast_iter_next(iter)) {
  49. ipoib_mcast_iter_free(iter);
  50. return NULL;
  51. }
  52. }
  53. return iter;
  54. }
  55. static void *ipoib_mcg_seq_next(struct seq_file *file, void *iter_ptr,
  56. loff_t *pos)
  57. {
  58. struct ipoib_mcast_iter *iter = iter_ptr;
  59. (*pos)++;
  60. if (ipoib_mcast_iter_next(iter)) {
  61. ipoib_mcast_iter_free(iter);
  62. return NULL;
  63. }
  64. return iter;
  65. }
  66. static void ipoib_mcg_seq_stop(struct seq_file *file, void *iter_ptr)
  67. {
  68. /* nothing for now */
  69. }
  70. static int ipoib_mcg_seq_show(struct seq_file *file, void *iter_ptr)
  71. {
  72. struct ipoib_mcast_iter *iter = iter_ptr;
  73. char gid_buf[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
  74. union ib_gid mgid;
  75. int i, n;
  76. unsigned long created;
  77. unsigned int queuelen, complete, send_only;
  78. if (iter) {
  79. ipoib_mcast_iter_read(iter, &mgid, &created, &queuelen,
  80. &complete, &send_only);
  81. for (n = 0, i = 0; i < sizeof mgid / 2; ++i) {
  82. n += sprintf(gid_buf + n, "%x",
  83. be16_to_cpu(((__be16 *) mgid.raw)[i]));
  84. if (i < sizeof mgid / 2 - 1)
  85. gid_buf[n++] = ':';
  86. }
  87. }
  88. seq_printf(file, "GID: %*s", -(1 + (int) sizeof gid_buf), gid_buf);
  89. seq_printf(file,
  90. " created: %10ld queuelen: %4d complete: %d send_only: %d\n",
  91. created, queuelen, complete, send_only);
  92. return 0;
  93. }
  94. static struct seq_operations ipoib_seq_ops = {
  95. .start = ipoib_mcg_seq_start,
  96. .next = ipoib_mcg_seq_next,
  97. .stop = ipoib_mcg_seq_stop,
  98. .show = ipoib_mcg_seq_show,
  99. };
  100. static int ipoib_mcg_open(struct inode *inode, struct file *file)
  101. {
  102. struct seq_file *seq;
  103. int ret;
  104. ret = seq_open(file, &ipoib_seq_ops);
  105. if (ret)
  106. return ret;
  107. seq = file->private_data;
  108. seq->private = inode->u.generic_ip;
  109. return 0;
  110. }
  111. static struct file_operations ipoib_fops = {
  112. .owner = THIS_MODULE,
  113. .open = ipoib_mcg_open,
  114. .read = seq_read,
  115. .llseek = seq_lseek,
  116. .release = seq_release
  117. };
  118. int ipoib_create_debug_file(struct net_device *dev)
  119. {
  120. struct ipoib_dev_priv *priv = netdev_priv(dev);
  121. char name[IFNAMSIZ + sizeof "_mcg"];
  122. snprintf(name, sizeof name, "%s_mcg", dev->name);
  123. priv->mcg_dentry = debugfs_create_file(name, S_IFREG | S_IRUGO,
  124. ipoib_root, dev, &ipoib_fops);
  125. return priv->mcg_dentry ? 0 : -ENOMEM;
  126. }
  127. void ipoib_delete_debug_file(struct net_device *dev)
  128. {
  129. struct ipoib_dev_priv *priv = netdev_priv(dev);
  130. if (priv->mcg_dentry)
  131. debugfs_remove(priv->mcg_dentry);
  132. }
  133. int ipoib_register_debugfs(void)
  134. {
  135. ipoib_root = debugfs_create_dir("ipoib", NULL);
  136. return ipoib_root ? 0 : -ENOMEM;
  137. }
  138. void ipoib_unregister_debugfs(void)
  139. {
  140. debugfs_remove(ipoib_root);
  141. }