Path: blob/main/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_fs.c
39566 views
/*-1* SPDX-License-Identifier: BSD-2-Clause OR GPL-2.02*3* Copyright (c) 2004 Topspin Communications. All rights reserved.4*5* This software is available to you under a choice of one of two6* licenses. You may choose to be licensed under the terms of the GNU7* General Public License (GPL) Version 2, available from the file8* COPYING in the main directory of this source tree, or the9* OpenIB.org BSD license below:10*11* Redistribution and use in source and binary forms, with or12* without modification, are permitted provided that the following13* conditions are met:14*15* - Redistributions of source code must retain the above16* copyright notice, this list of conditions and the following17* disclaimer.18*19* - Redistributions in binary form must reproduce the above20* copyright notice, this list of conditions and the following21* disclaimer in the documentation and/or other materials22* provided with the distribution.23*24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE31* SOFTWARE.32*/3334#include <sys/cdefs.h>35#include <linux/err.h>36#include <linux/seq_file.h>3738struct file_operations;3940#include <linux/debugfs.h>4142#include "ipoib.h"4344static struct dentry *ipoib_root;4546static void format_gid(union ib_gid *gid, char *buf)47{48int i, n;4950for (n = 0, i = 0; i < 8; ++i) {51n += sprintf(buf + n, "%x",52be16_to_cpu(((__be16 *) gid->raw)[i]));53if (i < 7)54buf[n++] = ':';55}56}5758static void *ipoib_mcg_seq_start(struct seq_file *file, loff_t *pos)59{60struct ipoib_mcast_iter *iter;61loff_t n = *pos;6263iter = ipoib_mcast_iter_init(file->private);64if (!iter)65return NULL;6667while (n--) {68if (ipoib_mcast_iter_next(iter)) {69kfree(iter);70return NULL;71}72}7374return iter;75}7677static void *ipoib_mcg_seq_next(struct seq_file *file, void *iter_ptr,78loff_t *pos)79{80struct ipoib_mcast_iter *iter = iter_ptr;8182(*pos)++;8384if (ipoib_mcast_iter_next(iter)) {85kfree(iter);86return NULL;87}8889return iter;90}9192static void ipoib_mcg_seq_stop(struct seq_file *file, void *iter_ptr)93{94/* nothing for now */95}9697static int ipoib_mcg_seq_show(struct seq_file *file, void *iter_ptr)98{99struct ipoib_mcast_iter *iter = iter_ptr;100char gid_buf[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];101union ib_gid mgid;102unsigned long created;103unsigned int queuelen, complete, send_only;104105if (!iter)106return 0;107108ipoib_mcast_iter_read(iter, &mgid, &created, &queuelen,109&complete, &send_only);110111format_gid(&mgid, gid_buf);112113seq_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",120gid_buf, created, queuelen,121complete ? "yes" : "no",122send_only ? "yes" : "no");123124return 0;125}126127static 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};133134static int ipoib_mcg_open(struct inode *inode, struct file *file)135{136struct seq_file *seq;137int ret;138139ret = seq_open(file, &ipoib_mcg_seq_ops);140if (ret)141return ret;142143seq = file->private_data;144seq->private = inode->i_private;145146return 0;147}148149static 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_release155};156157static void *ipoib_path_seq_start(struct seq_file *file, loff_t *pos)158{159struct ipoib_path_iter *iter;160loff_t n = *pos;161162iter = ipoib_path_iter_init(file->private);163if (!iter)164return NULL;165166while (n--) {167if (ipoib_path_iter_next(iter)) {168kfree(iter);169return NULL;170}171}172173return iter;174}175176static void *ipoib_path_seq_next(struct seq_file *file, void *iter_ptr,177loff_t *pos)178{179struct ipoib_path_iter *iter = iter_ptr;180181(*pos)++;182183if (ipoib_path_iter_next(iter)) {184kfree(iter);185return NULL;186}187188return iter;189}190191static void ipoib_path_seq_stop(struct seq_file *file, void *iter_ptr)192{193/* nothing for now */194}195196static int ipoib_path_seq_show(struct seq_file *file, void *iter_ptr)197{198struct ipoib_path_iter *iter = iter_ptr;199char gid_buf[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];200struct ipoib_path path;201int rate;202203if (!iter)204return 0;205206ipoib_path_iter_read(iter, &path);207208format_gid(&path.pathrec.dgid, gid_buf);209210seq_printf(file,211"GID: %s\n"212" complete: %6s\n",213gid_buf, path.pathrec.dlid ? "yes" : "no");214215if (path.pathrec.dlid) {216rate = ib_rate_to_mult(path.pathrec.rate) * 25;217218seq_printf(file,219" DLID: 0x%04x\n"220" SL: %12d\n"221" rate: %*d%s Gb/sec\n",222be16_to_cpu(path.pathrec.dlid),223path.pathrec.sl,22410 - ((rate % 10) ? 2 : 0),225rate / 10, rate % 10 ? ".5" : "");226}227228seq_putc(file, '\n');229230return 0;231}232233static const 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,238};239240static int ipoib_path_open(struct inode *inode, struct file *file)241{242struct seq_file *seq;243int ret;244245ret = seq_open(file, &ipoib_path_seq_ops);246if (ret)247return ret;248249seq = file->private_data;250seq->private = inode->i_private;251252return 0;253}254255static const 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_release261};262263void ipoib_create_debug_files(if_t dev)264{265struct ipoib_dev_priv *priv = dev->if_softc;266char name[IFNAMSIZ + sizeof "_path"];267268snprintf(name, sizeof name, "%s_mcg", if_name(dev));269priv->mcg_dentry = debugfs_create_file(name, S_IFREG | S_IRUGO,270ipoib_root, dev, &ipoib_mcg_fops);271if (!priv->mcg_dentry)272ipoib_warn(priv, "failed to create mcg debug file\n");273274snprintf(name, sizeof name, "%s_path", if_name(dev));275priv->path_dentry = debugfs_create_file(name, S_IFREG | S_IRUGO,276ipoib_root, dev, &ipoib_path_fops);277if (!priv->path_dentry)278ipoib_warn(priv, "failed to create path debug file\n");279}280281void ipoib_delete_debug_files(if_t dev)282{283struct ipoib_dev_priv *priv = dev->if_softc;284285if (priv->mcg_dentry)286debugfs_remove(priv->mcg_dentry);287if (priv->path_dentry)288debugfs_remove(priv->path_dentry);289}290291int ipoib_register_debugfs(void)292{293ipoib_root = debugfs_create_dir("ipoib", NULL);294return ipoib_root ? 0 : -ENOMEM;295}296297void ipoib_unregister_debugfs(void)298{299debugfs_remove(ipoib_root);300}301302303