Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | */ |
| 32 | |
Roland Dreier | 9adec1a | 2005-04-16 15:26:07 -0700 | [diff] [blame] | 33 | #include <linux/err.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/seq_file.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame^] | 35 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Roland Dreier | 9adec1a | 2005-04-16 15:26:07 -0700 | [diff] [blame] | 37 | struct file_operations; |
| 38 | |
| 39 | #include <linux/debugfs.h> |
| 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include "ipoib.h" |
| 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | static struct dentry *ipoib_root; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 45 | static void format_gid(union ib_gid *gid, char *buf) |
| 46 | { |
| 47 | int i, n; |
| 48 | |
| 49 | for (n = 0, i = 0; i < 8; ++i) { |
| 50 | n += sprintf(buf + n, "%x", |
| 51 | be16_to_cpu(((__be16 *) gid->raw)[i])); |
| 52 | if (i < 7) |
| 53 | buf[n++] = ':'; |
| 54 | } |
| 55 | } |
| 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | static void *ipoib_mcg_seq_start(struct seq_file *file, loff_t *pos) |
| 58 | { |
| 59 | struct ipoib_mcast_iter *iter; |
| 60 | loff_t n = *pos; |
| 61 | |
| 62 | iter = ipoib_mcast_iter_init(file->private); |
| 63 | if (!iter) |
| 64 | return NULL; |
| 65 | |
| 66 | while (n--) { |
| 67 | if (ipoib_mcast_iter_next(iter)) { |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 68 | kfree(iter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | return NULL; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | return iter; |
| 74 | } |
| 75 | |
| 76 | static void *ipoib_mcg_seq_next(struct seq_file *file, void *iter_ptr, |
| 77 | loff_t *pos) |
| 78 | { |
| 79 | struct ipoib_mcast_iter *iter = iter_ptr; |
| 80 | |
| 81 | (*pos)++; |
| 82 | |
| 83 | if (ipoib_mcast_iter_next(iter)) { |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 84 | kfree(iter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | return NULL; |
| 86 | } |
| 87 | |
| 88 | return iter; |
| 89 | } |
| 90 | |
| 91 | static void ipoib_mcg_seq_stop(struct seq_file *file, void *iter_ptr) |
| 92 | { |
| 93 | /* nothing for now */ |
| 94 | } |
| 95 | |
| 96 | static int ipoib_mcg_seq_show(struct seq_file *file, void *iter_ptr) |
| 97 | { |
| 98 | struct ipoib_mcast_iter *iter = iter_ptr; |
| 99 | char gid_buf[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"]; |
| 100 | union ib_gid mgid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | unsigned long created; |
| 102 | unsigned int queuelen, complete, send_only; |
| 103 | |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 104 | if (!iter) |
| 105 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 107 | ipoib_mcast_iter_read(iter, &mgid, &created, &queuelen, |
| 108 | &complete, &send_only); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 110 | format_gid(&mgid, gid_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
| 112 | seq_printf(file, |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 113 | "GID: %s\n" |
| 114 | " created: %10ld\n" |
| 115 | " queuelen: %9d\n" |
| 116 | " complete: %9s\n" |
| 117 | " send_only: %8s\n" |
| 118 | "\n", |
| 119 | gid_buf, created, queuelen, |
| 120 | complete ? "yes" : "no", |
| 121 | send_only ? "yes" : "no"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |
Jan Engelhardt | 1cf18d5a | 2008-01-22 20:45:30 +0100 | [diff] [blame] | 126 | static const struct seq_operations ipoib_mcg_seq_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | .start = ipoib_mcg_seq_start, |
| 128 | .next = ipoib_mcg_seq_next, |
| 129 | .stop = ipoib_mcg_seq_stop, |
| 130 | .show = ipoib_mcg_seq_show, |
| 131 | }; |
| 132 | |
| 133 | static int ipoib_mcg_open(struct inode *inode, struct file *file) |
| 134 | { |
| 135 | struct seq_file *seq; |
| 136 | int ret; |
| 137 | |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 138 | ret = seq_open(file, &ipoib_mcg_seq_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | if (ret) |
| 140 | return ret; |
| 141 | |
| 142 | seq = file->private_data; |
Theodore Ts'o | 8e18e29 | 2006-09-27 01:50:46 -0700 | [diff] [blame] | 143 | seq->private = inode->i_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 145 | return 0; |
| 146 | } |
| 147 | |
Arjan van de Ven | 2b8693c | 2007-02-12 00:55:32 -0800 | [diff] [blame] | 148 | static const struct file_operations ipoib_mcg_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | .owner = THIS_MODULE, |
| 150 | .open = ipoib_mcg_open, |
| 151 | .read = seq_read, |
| 152 | .llseek = seq_lseek, |
| 153 | .release = seq_release |
| 154 | }; |
| 155 | |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 156 | static void *ipoib_path_seq_start(struct seq_file *file, loff_t *pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 158 | struct ipoib_path_iter *iter; |
| 159 | loff_t n = *pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 161 | iter = ipoib_path_iter_init(file->private); |
| 162 | if (!iter) |
| 163 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 165 | while (n--) { |
| 166 | if (ipoib_path_iter_next(iter)) { |
| 167 | kfree(iter); |
| 168 | return NULL; |
| 169 | } |
| 170 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 172 | return iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 175 | static void *ipoib_path_seq_next(struct seq_file *file, void *iter_ptr, |
| 176 | loff_t *pos) |
| 177 | { |
| 178 | struct ipoib_path_iter *iter = iter_ptr; |
| 179 | |
| 180 | (*pos)++; |
| 181 | |
| 182 | if (ipoib_path_iter_next(iter)) { |
| 183 | kfree(iter); |
| 184 | return NULL; |
| 185 | } |
| 186 | |
| 187 | return iter; |
| 188 | } |
| 189 | |
| 190 | static void ipoib_path_seq_stop(struct seq_file *file, void *iter_ptr) |
| 191 | { |
| 192 | /* nothing for now */ |
| 193 | } |
| 194 | |
| 195 | static int ipoib_path_seq_show(struct seq_file *file, void *iter_ptr) |
| 196 | { |
| 197 | struct ipoib_path_iter *iter = iter_ptr; |
| 198 | char gid_buf[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"]; |
| 199 | struct ipoib_path path; |
| 200 | int rate; |
| 201 | |
| 202 | if (!iter) |
| 203 | return 0; |
| 204 | |
| 205 | ipoib_path_iter_read(iter, &path); |
| 206 | |
| 207 | format_gid(&path.pathrec.dgid, gid_buf); |
| 208 | |
| 209 | seq_printf(file, |
| 210 | "GID: %s\n" |
| 211 | " complete: %6s\n", |
| 212 | gid_buf, path.pathrec.dlid ? "yes" : "no"); |
| 213 | |
| 214 | if (path.pathrec.dlid) { |
Jack Morgenstein | bf6a9e3 | 2006-04-10 09:43:47 -0700 | [diff] [blame] | 215 | rate = ib_rate_to_mult(path.pathrec.rate) * 25; |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 216 | |
| 217 | seq_printf(file, |
| 218 | " DLID: 0x%04x\n" |
| 219 | " SL: %12d\n" |
| 220 | " rate: %*d%s Gb/sec\n", |
| 221 | be16_to_cpu(path.pathrec.dlid), |
| 222 | path.pathrec.sl, |
| 223 | 10 - ((rate % 10) ? 2 : 0), |
| 224 | rate / 10, rate % 10 ? ".5" : ""); |
| 225 | } |
| 226 | |
| 227 | seq_putc(file, '\n'); |
| 228 | |
| 229 | return 0; |
| 230 | } |
| 231 | |
Jan Engelhardt | 1cf18d5a | 2008-01-22 20:45:30 +0100 | [diff] [blame] | 232 | static const struct seq_operations ipoib_path_seq_ops = { |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 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 | |
| 239 | static 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; |
Theodore Ts'o | 8e18e29 | 2006-09-27 01:50:46 -0700 | [diff] [blame] | 249 | seq->private = inode->i_private; |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 250 | |
| 251 | return 0; |
| 252 | } |
| 253 | |
Arjan van de Ven | 2b8693c | 2007-02-12 00:55:32 -0800 | [diff] [blame] | 254 | static const struct file_operations ipoib_path_fops = { |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 255 | .owner = THIS_MODULE, |
| 256 | .open = ipoib_path_open, |
| 257 | .read = seq_read, |
| 258 | .llseek = seq_lseek, |
| 259 | .release = seq_release |
| 260 | }; |
| 261 | |
| 262 | void ipoib_create_debug_files(struct net_device *dev) |
| 263 | { |
| 264 | struct ipoib_dev_priv *priv = netdev_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 | if (!priv->mcg_dentry) |
| 271 | ipoib_warn(priv, "failed to create mcg debug file\n"); |
| 272 | |
| 273 | snprintf(name, sizeof name, "%s_path", dev->name); |
| 274 | priv->path_dentry = debugfs_create_file(name, S_IFREG | S_IRUGO, |
| 275 | ipoib_root, dev, &ipoib_path_fops); |
| 276 | if (!priv->path_dentry) |
| 277 | ipoib_warn(priv, "failed to create path debug file\n"); |
| 278 | } |
| 279 | |
| 280 | void ipoib_delete_debug_files(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | { |
| 282 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 283 | |
Roland Dreier | 9adec1a | 2005-04-16 15:26:07 -0700 | [diff] [blame] | 284 | if (priv->mcg_dentry) |
| 285 | debugfs_remove(priv->mcg_dentry); |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 286 | if (priv->path_dentry) |
| 287 | debugfs_remove(priv->path_dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | int ipoib_register_debugfs(void) |
| 291 | { |
Roland Dreier | 9adec1a | 2005-04-16 15:26:07 -0700 | [diff] [blame] | 292 | ipoib_root = debugfs_create_dir("ipoib", NULL); |
| 293 | return ipoib_root ? 0 : -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | void ipoib_unregister_debugfs(void) |
| 297 | { |
Roland Dreier | 9adec1a | 2005-04-16 15:26:07 -0700 | [diff] [blame] | 298 | debugfs_remove(ipoib_root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |