Linux Audio

Check our new training course

Linux kernel drivers training

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