IB: simplify static rate encoding
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / infiniband / ulp / ipoib / ipoib_fs.c
blob5dde380e8dbe9c2653c0014020f32ebc8e87732d
1 /*
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
12 * conditions are met:
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
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
30 * SOFTWARE.
32 * $Id: ipoib_fs.c 1389 2004-12-27 22:56:47Z roland $
35 #include <linux/err.h>
36 #include <linux/seq_file.h>
38 struct file_operations;
40 #include <linux/debugfs.h>
42 #include "ipoib.h"
44 static struct dentry *ipoib_root;
46 static void format_gid(union ib_gid *gid, char *buf)
48 int i, n;
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++] = ':';
58 static void *ipoib_mcg_seq_start(struct seq_file *file, loff_t *pos)
60 struct ipoib_mcast_iter *iter;
61 loff_t n = *pos;
63 iter = ipoib_mcast_iter_init(file->private);
64 if (!iter)
65 return NULL;
67 while (n--) {
68 if (ipoib_mcast_iter_next(iter)) {
69 kfree(iter);
70 return NULL;
74 return iter;
77 static void *ipoib_mcg_seq_next(struct seq_file *file, void *iter_ptr,
78 loff_t *pos)
80 struct ipoib_mcast_iter *iter = iter_ptr;
82 (*pos)++;
84 if (ipoib_mcast_iter_next(iter)) {
85 kfree(iter);
86 return NULL;
89 return iter;
92 static void ipoib_mcg_seq_stop(struct seq_file *file, void *iter_ptr)
94 /* nothing for now */
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"];
101 union ib_gid mgid;
102 unsigned long created;
103 unsigned int queuelen, complete, send_only;
105 if (!iter)
106 return 0;
108 ipoib_mcast_iter_read(iter, &mgid, &created, &queuelen,
109 &complete, &send_only);
111 format_gid(&mgid, gid_buf);
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");
124 return 0;
127 static 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,
134 static int ipoib_mcg_open(struct inode *inode, struct file *file)
136 struct seq_file *seq;
137 int ret;
139 ret = seq_open(file, &ipoib_mcg_seq_ops);
140 if (ret)
141 return ret;
143 seq = file->private_data;
144 seq->private = inode->u.generic_ip;
146 return 0;
149 static 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
157 static void *ipoib_path_seq_start(struct seq_file *file, loff_t *pos)
159 struct ipoib_path_iter *iter;
160 loff_t n = *pos;
162 iter = ipoib_path_iter_init(file->private);
163 if (!iter)
164 return NULL;
166 while (n--) {
167 if (ipoib_path_iter_next(iter)) {
168 kfree(iter);
169 return NULL;
173 return iter;
176 static void *ipoib_path_seq_next(struct seq_file *file, void *iter_ptr,
177 loff_t *pos)
179 struct ipoib_path_iter *iter = iter_ptr;
181 (*pos)++;
183 if (ipoib_path_iter_next(iter)) {
184 kfree(iter);
185 return NULL;
188 return iter;
191 static void ipoib_path_seq_stop(struct seq_file *file, void *iter_ptr)
193 /* nothing for now */
196 static int ipoib_path_seq_show(struct seq_file *file, void *iter_ptr)
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;
203 if (!iter)
204 return 0;
206 ipoib_path_iter_read(iter, &path);
208 format_gid(&path.pathrec.dgid, gid_buf);
210 seq_printf(file,
211 "GID: %s\n"
212 " complete: %6s\n",
213 gid_buf, path.pathrec.dlid ? "yes" : "no");
215 if (path.pathrec.dlid) {
216 rate = ib_rate_to_mult(path.pathrec.rate) * 25;
218 seq_printf(file,
219 " DLID: 0x%04x\n"
220 " SL: %12d\n"
221 " rate: %*d%s Gb/sec\n",
222 be16_to_cpu(path.pathrec.dlid),
223 path.pathrec.sl,
224 10 - ((rate % 10) ? 2 : 0),
225 rate / 10, rate % 10 ? ".5" : "");
228 seq_putc(file, '\n');
230 return 0;
233 static struct seq_operations ipoib_path_seq_ops = {
234 .start = ipoib_path_seq_start,
235 .next = ipoib_path_seq_next,
236 .stop = ipoib_path_seq_stop,
237 .show = ipoib_path_seq_show,
240 static int ipoib_path_open(struct inode *inode, struct file *file)
242 struct seq_file *seq;
243 int ret;
245 ret = seq_open(file, &ipoib_path_seq_ops);
246 if (ret)
247 return ret;
249 seq = file->private_data;
250 seq->private = inode->u.generic_ip;
252 return 0;
255 static struct file_operations ipoib_path_fops = {
256 .owner = THIS_MODULE,
257 .open = ipoib_path_open,
258 .read = seq_read,
259 .llseek = seq_lseek,
260 .release = seq_release
263 void ipoib_create_debug_files(struct net_device *dev)
265 struct ipoib_dev_priv *priv = netdev_priv(dev);
266 char name[IFNAMSIZ + sizeof "_path"];
268 snprintf(name, sizeof name, "%s_mcg", dev->name);
269 priv->mcg_dentry = debugfs_create_file(name, S_IFREG | S_IRUGO,
270 ipoib_root, dev, &ipoib_mcg_fops);
271 if (!priv->mcg_dentry)
272 ipoib_warn(priv, "failed to create mcg debug file\n");
274 snprintf(name, sizeof name, "%s_path", dev->name);
275 priv->path_dentry = debugfs_create_file(name, S_IFREG | S_IRUGO,
276 ipoib_root, dev, &ipoib_path_fops);
277 if (!priv->path_dentry)
278 ipoib_warn(priv, "failed to create path debug file\n");
281 void ipoib_delete_debug_files(struct net_device *dev)
283 struct ipoib_dev_priv *priv = netdev_priv(dev);
285 if (priv->mcg_dentry)
286 debugfs_remove(priv->mcg_dentry);
287 if (priv->path_dentry)
288 debugfs_remove(priv->path_dentry);
291 int ipoib_register_debugfs(void)
293 ipoib_root = debugfs_create_dir("ipoib", NULL);
294 return ipoib_root ? 0 : -ENOMEM;
297 void ipoib_unregister_debugfs(void)
299 debugfs_remove(ipoib_root);