Path: blob/master/drivers/infiniband/ulp/ipoib/ipoib_fs.c
15112 views
/*1* Copyright (c) 2004 Topspin Communications. All rights reserved.2*3* This software is available to you under a choice of one of two4* licenses. You may choose to be licensed under the terms of the GNU5* General Public License (GPL) Version 2, available from the file6* COPYING in the main directory of this source tree, or the7* OpenIB.org BSD license below:8*9* Redistribution and use in source and binary forms, with or10* without modification, are permitted provided that the following11* conditions are met:12*13* - Redistributions of source code must retain the above14* copyright notice, this list of conditions and the following15* disclaimer.16*17* - Redistributions in binary form must reproduce the above18* copyright notice, this list of conditions and the following19* disclaimer in the documentation and/or other materials20* provided with the distribution.21*22* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,23* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF24* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND25* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS26* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN27* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN28* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE29* SOFTWARE.30*/3132#include <linux/err.h>33#include <linux/seq_file.h>34#include <linux/slab.h>3536struct file_operations;3738#include <linux/debugfs.h>3940#include "ipoib.h"4142static struct dentry *ipoib_root;4344static void format_gid(union ib_gid *gid, char *buf)45{46int i, n;4748for (n = 0, i = 0; i < 8; ++i) {49n += sprintf(buf + n, "%x",50be16_to_cpu(((__be16 *) gid->raw)[i]));51if (i < 7)52buf[n++] = ':';53}54}5556static void *ipoib_mcg_seq_start(struct seq_file *file, loff_t *pos)57{58struct ipoib_mcast_iter *iter;59loff_t n = *pos;6061iter = ipoib_mcast_iter_init(file->private);62if (!iter)63return NULL;6465while (n--) {66if (ipoib_mcast_iter_next(iter)) {67kfree(iter);68return NULL;69}70}7172return iter;73}7475static void *ipoib_mcg_seq_next(struct seq_file *file, void *iter_ptr,76loff_t *pos)77{78struct ipoib_mcast_iter *iter = iter_ptr;7980(*pos)++;8182if (ipoib_mcast_iter_next(iter)) {83kfree(iter);84return NULL;85}8687return iter;88}8990static void ipoib_mcg_seq_stop(struct seq_file *file, void *iter_ptr)91{92/* nothing for now */93}9495static int ipoib_mcg_seq_show(struct seq_file *file, void *iter_ptr)96{97struct ipoib_mcast_iter *iter = iter_ptr;98char gid_buf[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];99union ib_gid mgid;100unsigned long created;101unsigned int queuelen, complete, send_only;102103if (!iter)104return 0;105106ipoib_mcast_iter_read(iter, &mgid, &created, &queuelen,107&complete, &send_only);108109format_gid(&mgid, gid_buf);110111seq_printf(file,112"GID: %s\n"113" created: %10ld\n"114" queuelen: %9d\n"115" complete: %9s\n"116" send_only: %8s\n"117"\n",118gid_buf, created, queuelen,119complete ? "yes" : "no",120send_only ? "yes" : "no");121122return 0;123}124125static const struct seq_operations ipoib_mcg_seq_ops = {126.start = ipoib_mcg_seq_start,127.next = ipoib_mcg_seq_next,128.stop = ipoib_mcg_seq_stop,129.show = ipoib_mcg_seq_show,130};131132static int ipoib_mcg_open(struct inode *inode, struct file *file)133{134struct seq_file *seq;135int ret;136137ret = seq_open(file, &ipoib_mcg_seq_ops);138if (ret)139return ret;140141seq = file->private_data;142seq->private = inode->i_private;143144return 0;145}146147static const struct file_operations ipoib_mcg_fops = {148.owner = THIS_MODULE,149.open = ipoib_mcg_open,150.read = seq_read,151.llseek = seq_lseek,152.release = seq_release153};154155static void *ipoib_path_seq_start(struct seq_file *file, loff_t *pos)156{157struct ipoib_path_iter *iter;158loff_t n = *pos;159160iter = ipoib_path_iter_init(file->private);161if (!iter)162return NULL;163164while (n--) {165if (ipoib_path_iter_next(iter)) {166kfree(iter);167return NULL;168}169}170171return iter;172}173174static void *ipoib_path_seq_next(struct seq_file *file, void *iter_ptr,175loff_t *pos)176{177struct ipoib_path_iter *iter = iter_ptr;178179(*pos)++;180181if (ipoib_path_iter_next(iter)) {182kfree(iter);183return NULL;184}185186return iter;187}188189static void ipoib_path_seq_stop(struct seq_file *file, void *iter_ptr)190{191/* nothing for now */192}193194static int ipoib_path_seq_show(struct seq_file *file, void *iter_ptr)195{196struct ipoib_path_iter *iter = iter_ptr;197char gid_buf[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];198struct ipoib_path path;199int rate;200201if (!iter)202return 0;203204ipoib_path_iter_read(iter, &path);205206format_gid(&path.pathrec.dgid, gid_buf);207208seq_printf(file,209"GID: %s\n"210" complete: %6s\n",211gid_buf, path.pathrec.dlid ? "yes" : "no");212213if (path.pathrec.dlid) {214rate = ib_rate_to_mult(path.pathrec.rate) * 25;215216seq_printf(file,217" DLID: 0x%04x\n"218" SL: %12d\n"219" rate: %*d%s Gb/sec\n",220be16_to_cpu(path.pathrec.dlid),221path.pathrec.sl,22210 - ((rate % 10) ? 2 : 0),223rate / 10, rate % 10 ? ".5" : "");224}225226seq_putc(file, '\n');227228return 0;229}230231static const struct seq_operations ipoib_path_seq_ops = {232.start = ipoib_path_seq_start,233.next = ipoib_path_seq_next,234.stop = ipoib_path_seq_stop,235.show = ipoib_path_seq_show,236};237238static int ipoib_path_open(struct inode *inode, struct file *file)239{240struct seq_file *seq;241int ret;242243ret = seq_open(file, &ipoib_path_seq_ops);244if (ret)245return ret;246247seq = file->private_data;248seq->private = inode->i_private;249250return 0;251}252253static const struct file_operations ipoib_path_fops = {254.owner = THIS_MODULE,255.open = ipoib_path_open,256.read = seq_read,257.llseek = seq_lseek,258.release = seq_release259};260261void ipoib_create_debug_files(struct net_device *dev)262{263struct ipoib_dev_priv *priv = netdev_priv(dev);264char name[IFNAMSIZ + sizeof "_path"];265266snprintf(name, sizeof name, "%s_mcg", dev->name);267priv->mcg_dentry = debugfs_create_file(name, S_IFREG | S_IRUGO,268ipoib_root, dev, &ipoib_mcg_fops);269if (!priv->mcg_dentry)270ipoib_warn(priv, "failed to create mcg debug file\n");271272snprintf(name, sizeof name, "%s_path", dev->name);273priv->path_dentry = debugfs_create_file(name, S_IFREG | S_IRUGO,274ipoib_root, dev, &ipoib_path_fops);275if (!priv->path_dentry)276ipoib_warn(priv, "failed to create path debug file\n");277}278279void ipoib_delete_debug_files(struct net_device *dev)280{281struct ipoib_dev_priv *priv = netdev_priv(dev);282283if (priv->mcg_dentry)284debugfs_remove(priv->mcg_dentry);285if (priv->path_dentry)286debugfs_remove(priv->path_dentry);287}288289int ipoib_register_debugfs(void)290{291ipoib_root = debugfs_create_dir("ipoib", NULL);292return ipoib_root ? 0 : -ENOMEM;293}294295void ipoib_unregister_debugfs(void)296{297debugfs_remove(ipoib_root);298}299300301