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
32 * $Id: ipoib_fs.c 1389 2004-12-27 22:56:47Z roland $
35 #include <linux/pagemap.h>
36 #include <linux/seq_file.h>
41 IPOIB_MAGIC
= 0x49504942 /* "IPIB" */
44 static DECLARE_MUTEX(ipoib_fs_mutex
);
45 static struct dentry
*ipoib_root
;
46 static struct super_block
*ipoib_sb
;
47 static LIST_HEAD(ipoib_device_list
);
49 static void *ipoib_mcg_seq_start(struct seq_file
*file
, loff_t
*pos
)
51 struct ipoib_mcast_iter
*iter
;
54 iter
= ipoib_mcast_iter_init(file
->private);
59 if (ipoib_mcast_iter_next(iter
)) {
60 ipoib_mcast_iter_free(iter
);
68 static void *ipoib_mcg_seq_next(struct seq_file
*file
, void *iter_ptr
,
71 struct ipoib_mcast_iter
*iter
= iter_ptr
;
75 if (ipoib_mcast_iter_next(iter
)) {
76 ipoib_mcast_iter_free(iter
);
83 static void ipoib_mcg_seq_stop(struct seq_file
*file
, void *iter_ptr
)
88 static int ipoib_mcg_seq_show(struct seq_file
*file
, void *iter_ptr
)
90 struct ipoib_mcast_iter
*iter
= iter_ptr
;
91 char gid_buf
[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
94 unsigned long created
;
95 unsigned int queuelen
, complete
, send_only
;
98 ipoib_mcast_iter_read(iter
, &mgid
, &created
, &queuelen
,
99 &complete
, &send_only
);
101 for (n
= 0, i
= 0; i
< sizeof mgid
/ 2; ++i
) {
102 n
+= sprintf(gid_buf
+ n
, "%x",
103 be16_to_cpu(((u16
*)mgid
.raw
)[i
]));
104 if (i
< sizeof mgid
/ 2 - 1)
109 seq_printf(file
, "GID: %*s", -(1 + (int) sizeof gid_buf
), gid_buf
);
112 " created: %10ld queuelen: %4d complete: %d send_only: %d\n",
113 created
, queuelen
, complete
, send_only
);
118 static struct seq_operations ipoib_seq_ops
= {
119 .start
= ipoib_mcg_seq_start
,
120 .next
= ipoib_mcg_seq_next
,
121 .stop
= ipoib_mcg_seq_stop
,
122 .show
= ipoib_mcg_seq_show
,
125 static int ipoib_mcg_open(struct inode
*inode
, struct file
*file
)
127 struct seq_file
*seq
;
130 ret
= seq_open(file
, &ipoib_seq_ops
);
134 seq
= file
->private_data
;
135 seq
->private = inode
->u
.generic_ip
;
140 static struct file_operations ipoib_fops
= {
141 .owner
= THIS_MODULE
,
142 .open
= ipoib_mcg_open
,
145 .release
= seq_release
148 static struct inode
*ipoib_get_inode(void)
150 struct inode
*inode
= new_inode(ipoib_sb
);
153 inode
->i_mode
= S_IFREG
| S_IRUGO
;
156 inode
->i_blksize
= PAGE_CACHE_SIZE
;
158 inode
->i_atime
= inode
->i_mtime
= inode
->i_ctime
= CURRENT_TIME
;
159 inode
->i_fop
= &ipoib_fops
;
165 static int __ipoib_create_debug_file(struct net_device
*dev
)
167 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
168 struct dentry
*dentry
;
170 char name
[IFNAMSIZ
+ sizeof "_mcg"];
172 snprintf(name
, sizeof name
, "%s_mcg", dev
->name
);
174 dentry
= d_alloc_name(ipoib_root
, name
);
178 inode
= ipoib_get_inode();
184 inode
->u
.generic_ip
= dev
;
185 priv
->mcg_dentry
= dentry
;
187 d_add(dentry
, inode
);
192 int ipoib_create_debug_file(struct net_device
*dev
)
194 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
196 down(&ipoib_fs_mutex
);
198 list_add_tail(&priv
->fs_list
, &ipoib_device_list
);
207 return __ipoib_create_debug_file(dev
);
210 void ipoib_delete_debug_file(struct net_device
*dev
)
212 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
214 down(&ipoib_fs_mutex
);
215 list_del(&priv
->fs_list
);
222 if (priv
->mcg_dentry
) {
223 d_drop(priv
->mcg_dentry
);
224 simple_unlink(ipoib_root
->d_inode
, priv
->mcg_dentry
);
228 static int ipoib_fill_super(struct super_block
*sb
, void *data
, int silent
)
230 static struct tree_descr ipoib_files
[] = {
233 struct ipoib_dev_priv
*priv
;
236 ret
= simple_fill_super(sb
, IPOIB_MAGIC
, ipoib_files
);
240 ipoib_root
= sb
->s_root
;
242 down(&ipoib_fs_mutex
);
246 list_for_each_entry(priv
, &ipoib_device_list
, fs_list
) {
247 ret
= __ipoib_create_debug_file(priv
->dev
);
257 static struct super_block
*ipoib_get_sb(struct file_system_type
*fs_type
,
258 int flags
, const char *dev_name
, void *data
)
260 return get_sb_single(fs_type
, flags
, data
, ipoib_fill_super
);
263 static void ipoib_kill_sb(struct super_block
*sb
)
265 down(&ipoib_fs_mutex
);
269 kill_litter_super(sb
);
272 static struct file_system_type ipoib_fs_type
= {
273 .owner
= THIS_MODULE
,
274 .name
= "ipoib_debugfs",
275 .get_sb
= ipoib_get_sb
,
276 .kill_sb
= ipoib_kill_sb
,
279 int ipoib_register_debugfs(void)
281 return register_filesystem(&ipoib_fs_type
);
284 void ipoib_unregister_debugfs(void)
286 unregister_filesystem(&ipoib_fs_type
);