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