2 * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
4 * Copyright (c) 2004 Topspin Communications. All rights reserved.
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #include <linux/err.h>
39 #include <linux/seq_file.h>
41 struct file_operations;
43 #include <linux/debugfs.h>
47 static struct dentry *ipoib_root;
49 static void format_gid(union ib_gid *gid, char *buf)
53 for (n = 0, i = 0; i < 8; ++i) {
54 n += sprintf(buf + n, "%x",
55 be16_to_cpu(((__be16 *) gid->raw)[i]));
61 static void *ipoib_mcg_seq_start(struct seq_file *file, loff_t *pos)
63 struct ipoib_mcast_iter *iter;
66 iter = ipoib_mcast_iter_init(file->private);
71 if (ipoib_mcast_iter_next(iter)) {
80 static void *ipoib_mcg_seq_next(struct seq_file *file, void *iter_ptr,
83 struct ipoib_mcast_iter *iter = iter_ptr;
87 if (ipoib_mcast_iter_next(iter)) {
95 static void ipoib_mcg_seq_stop(struct seq_file *file, void *iter_ptr)
100 static int ipoib_mcg_seq_show(struct seq_file *file, void *iter_ptr)
102 struct ipoib_mcast_iter *iter = iter_ptr;
103 char gid_buf[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
105 unsigned long created;
106 unsigned int queuelen, complete, send_only;
111 ipoib_mcast_iter_read(iter, &mgid, &created, &queuelen,
112 &complete, &send_only);
114 format_gid(&mgid, gid_buf);
123 gid_buf, created, queuelen,
124 complete ? "yes" : "no",
125 send_only ? "yes" : "no");
130 static const struct seq_operations ipoib_mcg_seq_ops = {
131 .start = ipoib_mcg_seq_start,
132 .next = ipoib_mcg_seq_next,
133 .stop = ipoib_mcg_seq_stop,
134 .show = ipoib_mcg_seq_show,
137 static int ipoib_mcg_open(struct inode *inode, struct file *file)
139 struct seq_file *seq;
142 ret = seq_open(file, &ipoib_mcg_seq_ops);
146 seq = file->private_data;
147 seq->private = inode->i_private;
152 static const struct file_operations ipoib_mcg_fops = {
153 .owner = THIS_MODULE,
154 .open = ipoib_mcg_open,
157 .release = seq_release
160 static void *ipoib_path_seq_start(struct seq_file *file, loff_t *pos)
162 struct ipoib_path_iter *iter;
165 iter = ipoib_path_iter_init(file->private);
170 if (ipoib_path_iter_next(iter)) {
179 static void *ipoib_path_seq_next(struct seq_file *file, void *iter_ptr,
182 struct ipoib_path_iter *iter = iter_ptr;
186 if (ipoib_path_iter_next(iter)) {
194 static void ipoib_path_seq_stop(struct seq_file *file, void *iter_ptr)
196 /* nothing for now */
199 static int ipoib_path_seq_show(struct seq_file *file, void *iter_ptr)
201 struct ipoib_path_iter *iter = iter_ptr;
202 char gid_buf[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
203 struct ipoib_path path;
209 ipoib_path_iter_read(iter, &path);
211 format_gid(&path.pathrec.dgid, gid_buf);
216 gid_buf, path.pathrec.dlid ? "yes" : "no");
218 if (path.pathrec.dlid) {
219 rate = ib_rate_to_mult(path.pathrec.rate) * 25;
224 " rate: %*d%s Gb/sec\n",
225 be16_to_cpu(path.pathrec.dlid),
227 10 - ((rate % 10) ? 2 : 0),
228 rate / 10, rate % 10 ? ".5" : "");
231 seq_putc(file, '\n');
236 static const struct seq_operations ipoib_path_seq_ops = {
237 .start = ipoib_path_seq_start,
238 .next = ipoib_path_seq_next,
239 .stop = ipoib_path_seq_stop,
240 .show = ipoib_path_seq_show,
243 static int ipoib_path_open(struct inode *inode, struct file *file)
245 struct seq_file *seq;
248 ret = seq_open(file, &ipoib_path_seq_ops);
252 seq = file->private_data;
253 seq->private = inode->i_private;
258 static const struct file_operations ipoib_path_fops = {
259 .owner = THIS_MODULE,
260 .open = ipoib_path_open,
263 .release = seq_release
266 void ipoib_create_debug_files(struct ifnet *dev)
268 struct ipoib_dev_priv *priv = dev->if_softc;
269 char name[IFNAMSIZ + sizeof "_path"];
271 snprintf(name, sizeof name, "%s_mcg", if_name(dev));
272 priv->mcg_dentry = debugfs_create_file(name, S_IFREG | S_IRUGO,
273 ipoib_root, dev, &ipoib_mcg_fops);
274 if (!priv->mcg_dentry)
275 ipoib_warn(priv, "failed to create mcg debug file\n");
277 snprintf(name, sizeof name, "%s_path", if_name(dev));
278 priv->path_dentry = debugfs_create_file(name, S_IFREG | S_IRUGO,
279 ipoib_root, dev, &ipoib_path_fops);
280 if (!priv->path_dentry)
281 ipoib_warn(priv, "failed to create path debug file\n");
284 void ipoib_delete_debug_files(struct ifnet *dev)
286 struct ipoib_dev_priv *priv = dev->if_softc;
288 if (priv->mcg_dentry)
289 debugfs_remove(priv->mcg_dentry);
290 if (priv->path_dentry)
291 debugfs_remove(priv->path_dentry);
294 int ipoib_register_debugfs(void)
296 ipoib_root = debugfs_create_dir("ipoib", NULL);
297 return ipoib_root ? 0 : -ENOMEM;
300 void ipoib_unregister_debugfs(void)
302 debugfs_remove(ipoib_root);