18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (c) 2013, Cisco Systems, Inc. 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 * 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 348c2ecf20Sopenharmony_ci#include <linux/debugfs.h> 358c2ecf20Sopenharmony_ci#include <linux/module.h> 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci#include "usnic.h" 388c2ecf20Sopenharmony_ci#include "usnic_log.h" 398c2ecf20Sopenharmony_ci#include "usnic_debugfs.h" 408c2ecf20Sopenharmony_ci#include "usnic_ib_qp_grp.h" 418c2ecf20Sopenharmony_ci#include "usnic_transport.h" 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_cistatic struct dentry *debugfs_root; 448c2ecf20Sopenharmony_cistatic struct dentry *flows_dentry; 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_cistatic ssize_t usnic_debugfs_buildinfo_read(struct file *f, char __user *data, 478c2ecf20Sopenharmony_ci size_t count, loff_t *ppos) 488c2ecf20Sopenharmony_ci{ 498c2ecf20Sopenharmony_ci char buf[500]; 508c2ecf20Sopenharmony_ci int res; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci if (*ppos > 0) 538c2ecf20Sopenharmony_ci return 0; 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci res = scnprintf(buf, sizeof(buf), 568c2ecf20Sopenharmony_ci "version: %s\n" 578c2ecf20Sopenharmony_ci "build date: %s\n", 588c2ecf20Sopenharmony_ci DRV_VERSION, DRV_RELDATE); 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci return simple_read_from_buffer(data, count, ppos, buf, res); 618c2ecf20Sopenharmony_ci} 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_cistatic const struct file_operations usnic_debugfs_buildinfo_ops = { 648c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 658c2ecf20Sopenharmony_ci .open = simple_open, 668c2ecf20Sopenharmony_ci .read = usnic_debugfs_buildinfo_read 678c2ecf20Sopenharmony_ci}; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_cistatic ssize_t flowinfo_read(struct file *f, char __user *data, 708c2ecf20Sopenharmony_ci size_t count, loff_t *ppos) 718c2ecf20Sopenharmony_ci{ 728c2ecf20Sopenharmony_ci struct usnic_ib_qp_grp_flow *qp_flow; 738c2ecf20Sopenharmony_ci int n; 748c2ecf20Sopenharmony_ci int left; 758c2ecf20Sopenharmony_ci char *ptr; 768c2ecf20Sopenharmony_ci char buf[512]; 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci qp_flow = f->private_data; 798c2ecf20Sopenharmony_ci ptr = buf; 808c2ecf20Sopenharmony_ci left = count; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci if (*ppos > 0) 838c2ecf20Sopenharmony_ci return 0; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci spin_lock(&qp_flow->qp_grp->lock); 868c2ecf20Sopenharmony_ci n = scnprintf(ptr, left, 878c2ecf20Sopenharmony_ci "QP Grp ID: %d Transport: %s ", 888c2ecf20Sopenharmony_ci qp_flow->qp_grp->grp_id, 898c2ecf20Sopenharmony_ci usnic_transport_to_str(qp_flow->trans_type)); 908c2ecf20Sopenharmony_ci UPDATE_PTR_LEFT(n, ptr, left); 918c2ecf20Sopenharmony_ci if (qp_flow->trans_type == USNIC_TRANSPORT_ROCE_CUSTOM) { 928c2ecf20Sopenharmony_ci n = scnprintf(ptr, left, "Port_Num:%hu\n", 938c2ecf20Sopenharmony_ci qp_flow->usnic_roce.port_num); 948c2ecf20Sopenharmony_ci UPDATE_PTR_LEFT(n, ptr, left); 958c2ecf20Sopenharmony_ci } else if (qp_flow->trans_type == USNIC_TRANSPORT_IPV4_UDP) { 968c2ecf20Sopenharmony_ci n = usnic_transport_sock_to_str(ptr, left, 978c2ecf20Sopenharmony_ci qp_flow->udp.sock); 988c2ecf20Sopenharmony_ci UPDATE_PTR_LEFT(n, ptr, left); 998c2ecf20Sopenharmony_ci n = scnprintf(ptr, left, "\n"); 1008c2ecf20Sopenharmony_ci UPDATE_PTR_LEFT(n, ptr, left); 1018c2ecf20Sopenharmony_ci } 1028c2ecf20Sopenharmony_ci spin_unlock(&qp_flow->qp_grp->lock); 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci return simple_read_from_buffer(data, count, ppos, buf, ptr - buf); 1058c2ecf20Sopenharmony_ci} 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_cistatic const struct file_operations flowinfo_ops = { 1088c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 1098c2ecf20Sopenharmony_ci .open = simple_open, 1108c2ecf20Sopenharmony_ci .read = flowinfo_read, 1118c2ecf20Sopenharmony_ci}; 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_civoid usnic_debugfs_init(void) 1148c2ecf20Sopenharmony_ci{ 1158c2ecf20Sopenharmony_ci debugfs_root = debugfs_create_dir(DRV_NAME, NULL); 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci flows_dentry = debugfs_create_dir("flows", debugfs_root); 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci debugfs_create_file("build-info", S_IRUGO, debugfs_root, 1208c2ecf20Sopenharmony_ci NULL, &usnic_debugfs_buildinfo_ops); 1218c2ecf20Sopenharmony_ci} 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_civoid usnic_debugfs_exit(void) 1248c2ecf20Sopenharmony_ci{ 1258c2ecf20Sopenharmony_ci debugfs_remove_recursive(debugfs_root); 1268c2ecf20Sopenharmony_ci debugfs_root = NULL; 1278c2ecf20Sopenharmony_ci} 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_civoid usnic_debugfs_flow_add(struct usnic_ib_qp_grp_flow *qp_flow) 1308c2ecf20Sopenharmony_ci{ 1318c2ecf20Sopenharmony_ci scnprintf(qp_flow->dentry_name, sizeof(qp_flow->dentry_name), 1328c2ecf20Sopenharmony_ci "%u", qp_flow->flow->flow_id); 1338c2ecf20Sopenharmony_ci qp_flow->dbgfs_dentry = debugfs_create_file(qp_flow->dentry_name, 1348c2ecf20Sopenharmony_ci S_IRUGO, 1358c2ecf20Sopenharmony_ci flows_dentry, 1368c2ecf20Sopenharmony_ci qp_flow, 1378c2ecf20Sopenharmony_ci &flowinfo_ops); 1388c2ecf20Sopenharmony_ci} 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_civoid usnic_debugfs_flow_remove(struct usnic_ib_qp_grp_flow *qp_flow) 1418c2ecf20Sopenharmony_ci{ 1428c2ecf20Sopenharmony_ci debugfs_remove(qp_flow->dbgfs_dentry); 1438c2ecf20Sopenharmony_ci} 144