1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright (c) 2013, Cisco Systems, Inc. All rights reserved.
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * This software is available to you under a choice of one of two
5*4882a593Smuzhiyun * licenses. You may choose to be licensed under the terms of the GNU
6*4882a593Smuzhiyun * General Public License (GPL) Version 2, available from the file
7*4882a593Smuzhiyun * COPYING in the main directory of this source tree, or the
8*4882a593Smuzhiyun * BSD license below:
9*4882a593Smuzhiyun *
10*4882a593Smuzhiyun * Redistribution and use in source and binary forms, with or
11*4882a593Smuzhiyun * without modification, are permitted provided that the following
12*4882a593Smuzhiyun * conditions are met:
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun * - Redistributions of source code must retain the above
15*4882a593Smuzhiyun * copyright notice, this list of conditions and the following
16*4882a593Smuzhiyun * disclaimer.
17*4882a593Smuzhiyun *
18*4882a593Smuzhiyun * - Redistributions in binary form must reproduce the above
19*4882a593Smuzhiyun * copyright notice, this list of conditions and the following
20*4882a593Smuzhiyun * disclaimer in the documentation and/or other materials
21*4882a593Smuzhiyun * provided with the distribution.
22*4882a593Smuzhiyun *
23*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24*4882a593Smuzhiyun * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25*4882a593Smuzhiyun * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26*4882a593Smuzhiyun * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27*4882a593Smuzhiyun * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28*4882a593Smuzhiyun * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29*4882a593Smuzhiyun * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30*4882a593Smuzhiyun * SOFTWARE.
31*4882a593Smuzhiyun *
32*4882a593Smuzhiyun */
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun #include <linux/debugfs.h>
35*4882a593Smuzhiyun #include <linux/module.h>
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun #include "usnic.h"
38*4882a593Smuzhiyun #include "usnic_log.h"
39*4882a593Smuzhiyun #include "usnic_debugfs.h"
40*4882a593Smuzhiyun #include "usnic_ib_qp_grp.h"
41*4882a593Smuzhiyun #include "usnic_transport.h"
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun static struct dentry *debugfs_root;
44*4882a593Smuzhiyun static struct dentry *flows_dentry;
45*4882a593Smuzhiyun
usnic_debugfs_buildinfo_read(struct file * f,char __user * data,size_t count,loff_t * ppos)46*4882a593Smuzhiyun static ssize_t usnic_debugfs_buildinfo_read(struct file *f, char __user *data,
47*4882a593Smuzhiyun size_t count, loff_t *ppos)
48*4882a593Smuzhiyun {
49*4882a593Smuzhiyun char buf[500];
50*4882a593Smuzhiyun int res;
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun if (*ppos > 0)
53*4882a593Smuzhiyun return 0;
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun res = scnprintf(buf, sizeof(buf),
56*4882a593Smuzhiyun "version: %s\n"
57*4882a593Smuzhiyun "build date: %s\n",
58*4882a593Smuzhiyun DRV_VERSION, DRV_RELDATE);
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun return simple_read_from_buffer(data, count, ppos, buf, res);
61*4882a593Smuzhiyun }
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun static const struct file_operations usnic_debugfs_buildinfo_ops = {
64*4882a593Smuzhiyun .owner = THIS_MODULE,
65*4882a593Smuzhiyun .open = simple_open,
66*4882a593Smuzhiyun .read = usnic_debugfs_buildinfo_read
67*4882a593Smuzhiyun };
68*4882a593Smuzhiyun
flowinfo_read(struct file * f,char __user * data,size_t count,loff_t * ppos)69*4882a593Smuzhiyun static ssize_t flowinfo_read(struct file *f, char __user *data,
70*4882a593Smuzhiyun size_t count, loff_t *ppos)
71*4882a593Smuzhiyun {
72*4882a593Smuzhiyun struct usnic_ib_qp_grp_flow *qp_flow;
73*4882a593Smuzhiyun int n;
74*4882a593Smuzhiyun int left;
75*4882a593Smuzhiyun char *ptr;
76*4882a593Smuzhiyun char buf[512];
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun qp_flow = f->private_data;
79*4882a593Smuzhiyun ptr = buf;
80*4882a593Smuzhiyun left = count;
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun if (*ppos > 0)
83*4882a593Smuzhiyun return 0;
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun spin_lock(&qp_flow->qp_grp->lock);
86*4882a593Smuzhiyun n = scnprintf(ptr, left,
87*4882a593Smuzhiyun "QP Grp ID: %d Transport: %s ",
88*4882a593Smuzhiyun qp_flow->qp_grp->grp_id,
89*4882a593Smuzhiyun usnic_transport_to_str(qp_flow->trans_type));
90*4882a593Smuzhiyun UPDATE_PTR_LEFT(n, ptr, left);
91*4882a593Smuzhiyun if (qp_flow->trans_type == USNIC_TRANSPORT_ROCE_CUSTOM) {
92*4882a593Smuzhiyun n = scnprintf(ptr, left, "Port_Num:%hu\n",
93*4882a593Smuzhiyun qp_flow->usnic_roce.port_num);
94*4882a593Smuzhiyun UPDATE_PTR_LEFT(n, ptr, left);
95*4882a593Smuzhiyun } else if (qp_flow->trans_type == USNIC_TRANSPORT_IPV4_UDP) {
96*4882a593Smuzhiyun n = usnic_transport_sock_to_str(ptr, left,
97*4882a593Smuzhiyun qp_flow->udp.sock);
98*4882a593Smuzhiyun UPDATE_PTR_LEFT(n, ptr, left);
99*4882a593Smuzhiyun n = scnprintf(ptr, left, "\n");
100*4882a593Smuzhiyun UPDATE_PTR_LEFT(n, ptr, left);
101*4882a593Smuzhiyun }
102*4882a593Smuzhiyun spin_unlock(&qp_flow->qp_grp->lock);
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun return simple_read_from_buffer(data, count, ppos, buf, ptr - buf);
105*4882a593Smuzhiyun }
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun static const struct file_operations flowinfo_ops = {
108*4882a593Smuzhiyun .owner = THIS_MODULE,
109*4882a593Smuzhiyun .open = simple_open,
110*4882a593Smuzhiyun .read = flowinfo_read,
111*4882a593Smuzhiyun };
112*4882a593Smuzhiyun
usnic_debugfs_init(void)113*4882a593Smuzhiyun void usnic_debugfs_init(void)
114*4882a593Smuzhiyun {
115*4882a593Smuzhiyun debugfs_root = debugfs_create_dir(DRV_NAME, NULL);
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun flows_dentry = debugfs_create_dir("flows", debugfs_root);
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun debugfs_create_file("build-info", S_IRUGO, debugfs_root,
120*4882a593Smuzhiyun NULL, &usnic_debugfs_buildinfo_ops);
121*4882a593Smuzhiyun }
122*4882a593Smuzhiyun
usnic_debugfs_exit(void)123*4882a593Smuzhiyun void usnic_debugfs_exit(void)
124*4882a593Smuzhiyun {
125*4882a593Smuzhiyun debugfs_remove_recursive(debugfs_root);
126*4882a593Smuzhiyun debugfs_root = NULL;
127*4882a593Smuzhiyun }
128*4882a593Smuzhiyun
usnic_debugfs_flow_add(struct usnic_ib_qp_grp_flow * qp_flow)129*4882a593Smuzhiyun void usnic_debugfs_flow_add(struct usnic_ib_qp_grp_flow *qp_flow)
130*4882a593Smuzhiyun {
131*4882a593Smuzhiyun scnprintf(qp_flow->dentry_name, sizeof(qp_flow->dentry_name),
132*4882a593Smuzhiyun "%u", qp_flow->flow->flow_id);
133*4882a593Smuzhiyun qp_flow->dbgfs_dentry = debugfs_create_file(qp_flow->dentry_name,
134*4882a593Smuzhiyun S_IRUGO,
135*4882a593Smuzhiyun flows_dentry,
136*4882a593Smuzhiyun qp_flow,
137*4882a593Smuzhiyun &flowinfo_ops);
138*4882a593Smuzhiyun }
139*4882a593Smuzhiyun
usnic_debugfs_flow_remove(struct usnic_ib_qp_grp_flow * qp_flow)140*4882a593Smuzhiyun void usnic_debugfs_flow_remove(struct usnic_ib_qp_grp_flow *qp_flow)
141*4882a593Smuzhiyun {
142*4882a593Smuzhiyun debugfs_remove(qp_flow->dbgfs_dentry);
143*4882a593Smuzhiyun }
144