2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
33 #include <linux/err.h>
34 #include <linux/seq_file.h>
35 #include <linux/slab.h>
37 struct file_operations
;
39 #include <linux/debugfs.h>
40 #include <linux/export.h>
44 static struct dentry
*ipoib_root
;
46 static void format_gid(union ib_gid
*gid
, char *buf
)
50 for (n
= 0, i
= 0; i
< 8; ++i
) {
51 n
+= sprintf(buf
+ n
, "%x",
52 be16_to_cpu(((__be16
*) gid
->raw
)[i
]));
58 static void *ipoib_mcg_seq_start(struct seq_file
*file
, loff_t
*pos
)
60 struct ipoib_mcast_iter
*iter
;
63 iter
= ipoib_mcast_iter_init(file
->private);
68 if (ipoib_mcast_iter_next(iter
)) {
77 static void *ipoib_mcg_seq_next(struct seq_file
*file
, void *iter_ptr
,
80 struct ipoib_mcast_iter
*iter
= iter_ptr
;
84 if (ipoib_mcast_iter_next(iter
)) {
92 static void ipoib_mcg_seq_stop(struct seq_file
*file
, void *iter_ptr
)
97 static int ipoib_mcg_seq_show(struct seq_file
*file
, void *iter_ptr
)
99 struct ipoib_mcast_iter
*iter
= iter_ptr
;
100 char gid_buf
[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
102 unsigned long created
;
103 unsigned int queuelen
, complete
, send_only
;
108 ipoib_mcast_iter_read(iter
, &mgid
, &created
, &queuelen
,
109 &complete
, &send_only
);
111 format_gid(&mgid
, gid_buf
);
120 gid_buf
, created
, queuelen
,
121 complete
? "yes" : "no",
122 send_only
? "yes" : "no");
127 static const struct seq_operations ipoib_mcg_sops
= {
128 .start
= ipoib_mcg_seq_start
,
129 .next
= ipoib_mcg_seq_next
,
130 .stop
= ipoib_mcg_seq_stop
,
131 .show
= ipoib_mcg_seq_show
,
134 DEFINE_SEQ_ATTRIBUTE(ipoib_mcg
);
136 static void *ipoib_path_seq_start(struct seq_file
*file
, loff_t
*pos
)
138 struct ipoib_path_iter
*iter
;
141 iter
= ipoib_path_iter_init(file
->private);
146 if (ipoib_path_iter_next(iter
)) {
155 static void *ipoib_path_seq_next(struct seq_file
*file
, void *iter_ptr
,
158 struct ipoib_path_iter
*iter
= iter_ptr
;
162 if (ipoib_path_iter_next(iter
)) {
170 static void ipoib_path_seq_stop(struct seq_file
*file
, void *iter_ptr
)
172 /* nothing for now */
175 static int ipoib_path_seq_show(struct seq_file
*file
, void *iter_ptr
)
177 struct ipoib_path_iter
*iter
= iter_ptr
;
178 char gid_buf
[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
179 struct ipoib_path path
;
185 ipoib_path_iter_read(iter
, &path
);
187 format_gid(&path
.pathrec
.dgid
, gid_buf
);
192 gid_buf
, sa_path_get_dlid(&path
.pathrec
) ? "yes" : "no");
194 if (sa_path_get_dlid(&path
.pathrec
)) {
195 rate
= ib_rate_to_mbps(path
.pathrec
.rate
);
200 " rate: %8d.%d Gb/sec\n",
201 be32_to_cpu(sa_path_get_dlid(&path
.pathrec
)),
203 rate
/ 1000, rate
% 1000);
206 seq_putc(file
, '\n');
211 static const struct seq_operations ipoib_path_sops
= {
212 .start
= ipoib_path_seq_start
,
213 .next
= ipoib_path_seq_next
,
214 .stop
= ipoib_path_seq_stop
,
215 .show
= ipoib_path_seq_show
,
218 DEFINE_SEQ_ATTRIBUTE(ipoib_path
);
220 void ipoib_create_debug_files(struct net_device
*dev
)
222 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
223 char name
[IFNAMSIZ
+ sizeof("_path")];
225 snprintf(name
, sizeof(name
), "%s_mcg", dev
->name
);
226 priv
->mcg_dentry
= debugfs_create_file(name
, S_IFREG
| S_IRUGO
,
227 ipoib_root
, dev
, &ipoib_mcg_fops
);
229 snprintf(name
, sizeof(name
), "%s_path", dev
->name
);
230 priv
->path_dentry
= debugfs_create_file(name
, S_IFREG
| S_IRUGO
,
231 ipoib_root
, dev
, &ipoib_path_fops
);
234 void ipoib_delete_debug_files(struct net_device
*dev
)
236 struct ipoib_dev_priv
*priv
= ipoib_priv(dev
);
238 debugfs_remove(priv
->mcg_dentry
);
239 debugfs_remove(priv
->path_dentry
);
240 priv
->mcg_dentry
= priv
->path_dentry
= NULL
;
243 void ipoib_register_debugfs(void)
245 ipoib_root
= debugfs_create_dir("ipoib", NULL
);
248 void ipoib_unregister_debugfs(void)
250 debugfs_remove(ipoib_root
);