18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (c) 2004 Topspin Communications. All rights reserved. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two 58c2ecf20Sopenharmony_ci * licenses. You may choose to be licensed under the terms of the GNU 68c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file 78c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the 88c2ecf20Sopenharmony_ci * OpenIB.org BSD license below: 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or 118c2ecf20Sopenharmony_ci * without modification, are permitted provided that the following 128c2ecf20Sopenharmony_ci * conditions are met: 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * - Redistributions of source code must retain the above 158c2ecf20Sopenharmony_ci * copyright notice, this list of conditions and the following 168c2ecf20Sopenharmony_ci * disclaimer. 178c2ecf20Sopenharmony_ci * 188c2ecf20Sopenharmony_ci * - Redistributions in binary form must reproduce the above 198c2ecf20Sopenharmony_ci * copyright notice, this list of conditions and the following 208c2ecf20Sopenharmony_ci * disclaimer in the documentation and/or other materials 218c2ecf20Sopenharmony_ci * provided with the distribution. 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 248c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 258c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 268c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 278c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 288c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 298c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 308c2ecf20Sopenharmony_ci * SOFTWARE. 318c2ecf20Sopenharmony_ci */ 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#include <linux/err.h> 348c2ecf20Sopenharmony_ci#include <linux/seq_file.h> 358c2ecf20Sopenharmony_ci#include <linux/slab.h> 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cistruct file_operations; 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#include <linux/debugfs.h> 408c2ecf20Sopenharmony_ci#include <linux/export.h> 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#include "ipoib.h" 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cistatic struct dentry *ipoib_root; 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_cistatic void format_gid(union ib_gid *gid, char *buf) 478c2ecf20Sopenharmony_ci{ 488c2ecf20Sopenharmony_ci int i, n; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci for (n = 0, i = 0; i < 8; ++i) { 518c2ecf20Sopenharmony_ci n += sprintf(buf + n, "%x", 528c2ecf20Sopenharmony_ci be16_to_cpu(((__be16 *) gid->raw)[i])); 538c2ecf20Sopenharmony_ci if (i < 7) 548c2ecf20Sopenharmony_ci buf[n++] = ':'; 558c2ecf20Sopenharmony_ci } 568c2ecf20Sopenharmony_ci} 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_cistatic void *ipoib_mcg_seq_start(struct seq_file *file, loff_t *pos) 598c2ecf20Sopenharmony_ci{ 608c2ecf20Sopenharmony_ci struct ipoib_mcast_iter *iter; 618c2ecf20Sopenharmony_ci loff_t n = *pos; 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci iter = ipoib_mcast_iter_init(file->private); 648c2ecf20Sopenharmony_ci if (!iter) 658c2ecf20Sopenharmony_ci return NULL; 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci while (n--) { 688c2ecf20Sopenharmony_ci if (ipoib_mcast_iter_next(iter)) { 698c2ecf20Sopenharmony_ci kfree(iter); 708c2ecf20Sopenharmony_ci return NULL; 718c2ecf20Sopenharmony_ci } 728c2ecf20Sopenharmony_ci } 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci return iter; 758c2ecf20Sopenharmony_ci} 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_cistatic void *ipoib_mcg_seq_next(struct seq_file *file, void *iter_ptr, 788c2ecf20Sopenharmony_ci loff_t *pos) 798c2ecf20Sopenharmony_ci{ 808c2ecf20Sopenharmony_ci struct ipoib_mcast_iter *iter = iter_ptr; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci (*pos)++; 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci if (ipoib_mcast_iter_next(iter)) { 858c2ecf20Sopenharmony_ci kfree(iter); 868c2ecf20Sopenharmony_ci return NULL; 878c2ecf20Sopenharmony_ci } 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci return iter; 908c2ecf20Sopenharmony_ci} 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_cistatic void ipoib_mcg_seq_stop(struct seq_file *file, void *iter_ptr) 938c2ecf20Sopenharmony_ci{ 948c2ecf20Sopenharmony_ci /* nothing for now */ 958c2ecf20Sopenharmony_ci} 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_cistatic int ipoib_mcg_seq_show(struct seq_file *file, void *iter_ptr) 988c2ecf20Sopenharmony_ci{ 998c2ecf20Sopenharmony_ci struct ipoib_mcast_iter *iter = iter_ptr; 1008c2ecf20Sopenharmony_ci char gid_buf[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"]; 1018c2ecf20Sopenharmony_ci union ib_gid mgid; 1028c2ecf20Sopenharmony_ci unsigned long created; 1038c2ecf20Sopenharmony_ci unsigned int queuelen, complete, send_only; 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci if (!iter) 1068c2ecf20Sopenharmony_ci return 0; 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci ipoib_mcast_iter_read(iter, &mgid, &created, &queuelen, 1098c2ecf20Sopenharmony_ci &complete, &send_only); 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci format_gid(&mgid, gid_buf); 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci seq_printf(file, 1148c2ecf20Sopenharmony_ci "GID: %s\n" 1158c2ecf20Sopenharmony_ci " created: %10ld\n" 1168c2ecf20Sopenharmony_ci " queuelen: %9d\n" 1178c2ecf20Sopenharmony_ci " complete: %9s\n" 1188c2ecf20Sopenharmony_ci " send_only: %8s\n" 1198c2ecf20Sopenharmony_ci "\n", 1208c2ecf20Sopenharmony_ci gid_buf, created, queuelen, 1218c2ecf20Sopenharmony_ci complete ? "yes" : "no", 1228c2ecf20Sopenharmony_ci send_only ? "yes" : "no"); 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci return 0; 1258c2ecf20Sopenharmony_ci} 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_cistatic const struct seq_operations ipoib_mcg_sops = { 1288c2ecf20Sopenharmony_ci .start = ipoib_mcg_seq_start, 1298c2ecf20Sopenharmony_ci .next = ipoib_mcg_seq_next, 1308c2ecf20Sopenharmony_ci .stop = ipoib_mcg_seq_stop, 1318c2ecf20Sopenharmony_ci .show = ipoib_mcg_seq_show, 1328c2ecf20Sopenharmony_ci}; 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ciDEFINE_SEQ_ATTRIBUTE(ipoib_mcg); 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_cistatic void *ipoib_path_seq_start(struct seq_file *file, loff_t *pos) 1378c2ecf20Sopenharmony_ci{ 1388c2ecf20Sopenharmony_ci struct ipoib_path_iter *iter; 1398c2ecf20Sopenharmony_ci loff_t n = *pos; 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci iter = ipoib_path_iter_init(file->private); 1428c2ecf20Sopenharmony_ci if (!iter) 1438c2ecf20Sopenharmony_ci return NULL; 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci while (n--) { 1468c2ecf20Sopenharmony_ci if (ipoib_path_iter_next(iter)) { 1478c2ecf20Sopenharmony_ci kfree(iter); 1488c2ecf20Sopenharmony_ci return NULL; 1498c2ecf20Sopenharmony_ci } 1508c2ecf20Sopenharmony_ci } 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci return iter; 1538c2ecf20Sopenharmony_ci} 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_cistatic void *ipoib_path_seq_next(struct seq_file *file, void *iter_ptr, 1568c2ecf20Sopenharmony_ci loff_t *pos) 1578c2ecf20Sopenharmony_ci{ 1588c2ecf20Sopenharmony_ci struct ipoib_path_iter *iter = iter_ptr; 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci (*pos)++; 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci if (ipoib_path_iter_next(iter)) { 1638c2ecf20Sopenharmony_ci kfree(iter); 1648c2ecf20Sopenharmony_ci return NULL; 1658c2ecf20Sopenharmony_ci } 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci return iter; 1688c2ecf20Sopenharmony_ci} 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_cistatic void ipoib_path_seq_stop(struct seq_file *file, void *iter_ptr) 1718c2ecf20Sopenharmony_ci{ 1728c2ecf20Sopenharmony_ci /* nothing for now */ 1738c2ecf20Sopenharmony_ci} 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_cistatic int ipoib_path_seq_show(struct seq_file *file, void *iter_ptr) 1768c2ecf20Sopenharmony_ci{ 1778c2ecf20Sopenharmony_ci struct ipoib_path_iter *iter = iter_ptr; 1788c2ecf20Sopenharmony_ci char gid_buf[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"]; 1798c2ecf20Sopenharmony_ci struct ipoib_path path; 1808c2ecf20Sopenharmony_ci int rate; 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci if (!iter) 1838c2ecf20Sopenharmony_ci return 0; 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci ipoib_path_iter_read(iter, &path); 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci format_gid(&path.pathrec.dgid, gid_buf); 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci seq_printf(file, 1908c2ecf20Sopenharmony_ci "GID: %s\n" 1918c2ecf20Sopenharmony_ci " complete: %6s\n", 1928c2ecf20Sopenharmony_ci gid_buf, sa_path_get_dlid(&path.pathrec) ? "yes" : "no"); 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci if (sa_path_get_dlid(&path.pathrec)) { 1958c2ecf20Sopenharmony_ci rate = ib_rate_to_mbps(path.pathrec.rate); 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci seq_printf(file, 1988c2ecf20Sopenharmony_ci " DLID: 0x%04x\n" 1998c2ecf20Sopenharmony_ci " SL: %12d\n" 2008c2ecf20Sopenharmony_ci " rate: %8d.%d Gb/sec\n", 2018c2ecf20Sopenharmony_ci be32_to_cpu(sa_path_get_dlid(&path.pathrec)), 2028c2ecf20Sopenharmony_ci path.pathrec.sl, 2038c2ecf20Sopenharmony_ci rate / 1000, rate % 1000); 2048c2ecf20Sopenharmony_ci } 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci seq_putc(file, '\n'); 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ci return 0; 2098c2ecf20Sopenharmony_ci} 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_cistatic const struct seq_operations ipoib_path_sops = { 2128c2ecf20Sopenharmony_ci .start = ipoib_path_seq_start, 2138c2ecf20Sopenharmony_ci .next = ipoib_path_seq_next, 2148c2ecf20Sopenharmony_ci .stop = ipoib_path_seq_stop, 2158c2ecf20Sopenharmony_ci .show = ipoib_path_seq_show, 2168c2ecf20Sopenharmony_ci}; 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ciDEFINE_SEQ_ATTRIBUTE(ipoib_path); 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_civoid ipoib_create_debug_files(struct net_device *dev) 2218c2ecf20Sopenharmony_ci{ 2228c2ecf20Sopenharmony_ci struct ipoib_dev_priv *priv = ipoib_priv(dev); 2238c2ecf20Sopenharmony_ci char name[IFNAMSIZ + sizeof("_path")]; 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci snprintf(name, sizeof(name), "%s_mcg", dev->name); 2268c2ecf20Sopenharmony_ci priv->mcg_dentry = debugfs_create_file(name, S_IFREG | S_IRUGO, 2278c2ecf20Sopenharmony_ci ipoib_root, dev, &ipoib_mcg_fops); 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci snprintf(name, sizeof(name), "%s_path", dev->name); 2308c2ecf20Sopenharmony_ci priv->path_dentry = debugfs_create_file(name, S_IFREG | S_IRUGO, 2318c2ecf20Sopenharmony_ci ipoib_root, dev, &ipoib_path_fops); 2328c2ecf20Sopenharmony_ci} 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_civoid ipoib_delete_debug_files(struct net_device *dev) 2358c2ecf20Sopenharmony_ci{ 2368c2ecf20Sopenharmony_ci struct ipoib_dev_priv *priv = ipoib_priv(dev); 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci debugfs_remove(priv->mcg_dentry); 2398c2ecf20Sopenharmony_ci debugfs_remove(priv->path_dentry); 2408c2ecf20Sopenharmony_ci priv->mcg_dentry = priv->path_dentry = NULL; 2418c2ecf20Sopenharmony_ci} 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_civoid ipoib_register_debugfs(void) 2448c2ecf20Sopenharmony_ci{ 2458c2ecf20Sopenharmony_ci ipoib_root = debugfs_create_dir("ipoib", NULL); 2468c2ecf20Sopenharmony_ci} 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_civoid ipoib_unregister_debugfs(void) 2498c2ecf20Sopenharmony_ci{ 2508c2ecf20Sopenharmony_ci debugfs_remove(ipoib_root); 2518c2ecf20Sopenharmony_ci} 252