Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * Copyright 2012 Cisco Systems, Inc.  All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * This program is free software; you may redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * it under the terms of the GNU General Public License as published by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * the Free Software Foundation; version 2 of the License.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "fnic.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static struct dentry *fnic_trace_debugfs_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static struct dentry *fnic_trace_debugfs_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static struct dentry *fnic_trace_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static struct dentry *fnic_stats_debugfs_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static struct dentry *fnic_fc_trace_debugfs_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static struct dentry *fnic_fc_rdata_trace_debugfs_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static struct dentry *fnic_fc_trace_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static struct dentry *fnic_fc_trace_clear;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) struct fc_trace_flag_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	u8 fc_row_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	u8 fc_normal_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	u8 fnic_trace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	u8 fc_trace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	u8 fc_clear;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static struct fc_trace_flag_type *fc_trc_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * fnic_debugfs_init - Initialize debugfs for fnic debug logging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * When Debugfs is configured this routine sets up the fnic debugfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * file system. If not already created, this routine will create the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * fnic directory and statistics directory for trace buffer and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * stats logging.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) int fnic_debugfs_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	fnic_trace_debugfs_root = debugfs_create_dir("fnic", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	fnic_stats_debugfs_root = debugfs_create_dir("statistics",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 						fnic_trace_debugfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	/* Allocate memory to structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	fc_trc_flag = (struct fc_trace_flag_type *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		vmalloc(sizeof(struct fc_trace_flag_type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	if (fc_trc_flag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		fc_trc_flag->fc_row_file = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		fc_trc_flag->fc_normal_file = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		fc_trc_flag->fnic_trace = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		fc_trc_flag->fc_trace = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		fc_trc_flag->fc_clear = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * fnic_debugfs_terminate - Tear down debugfs infrastructure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * When Debugfs is configured this routine removes debugfs file system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * elements that are specific to fnic.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) void fnic_debugfs_terminate(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	debugfs_remove(fnic_stats_debugfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	fnic_stats_debugfs_root = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	debugfs_remove(fnic_trace_debugfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	fnic_trace_debugfs_root = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (fc_trc_flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		vfree(fc_trc_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  * fnic_trace_ctrl_read -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  *          Read  trace_enable ,fc_trace_enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  *              or fc_trace_clear debugfs file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  * @filp: The file pointer to read from.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  * @ubuf: The buffer to copy the data to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  * @cnt: The number of bytes to read.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  * @ppos: The position in the file to start reading from.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  * This routine reads value of variable fnic_tracing_enabled or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  * fnic_fc_tracing_enabled or fnic_fc_trace_cleared
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  * and stores into local @buf.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  * It will start reading file at @ppos and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  * copy up to @cnt of data to @ubuf from @buf.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  * This function returns the amount of data that was read.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static ssize_t fnic_trace_ctrl_read(struct file *filp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 				  char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 				  size_t cnt, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	char buf[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	u8 *trace_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	trace_type = (u8 *)filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	if (*trace_type == fc_trc_flag->fnic_trace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		len = sprintf(buf, "%d\n", fnic_tracing_enabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	else if (*trace_type == fc_trc_flag->fc_trace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		len = sprintf(buf, "%d\n", fnic_fc_tracing_enabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	else if (*trace_type == fc_trc_flag->fc_clear)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		len = sprintf(buf, "%d\n", fnic_fc_trace_cleared);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		pr_err("fnic: Cannot read to any debugfs file\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	return simple_read_from_buffer(ubuf, cnt, ppos, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  * fnic_trace_ctrl_write -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  * Write to trace_enable, fc_trace_enable or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  *         fc_trace_clear debugfs file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  * @filp: The file pointer to write from.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)  * @ubuf: The buffer to copy the data from.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)  * @cnt: The number of bytes to write.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)  * @ppos: The position in the file to start writing to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  * This routine writes data from user buffer @ubuf to buffer @buf and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  * sets fc_trace_enable ,tracing_enable or fnic_fc_trace_cleared
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  * value as per user input.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)  * This function returns the amount of data that was written.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static ssize_t fnic_trace_ctrl_write(struct file *filp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 				  const char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 				  size_t cnt, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	char buf[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	u8 *trace_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	trace_type = (u8 *)filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	if (cnt >= sizeof(buf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if (copy_from_user(&buf, ubuf, cnt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	buf[cnt] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	ret = kstrtoul(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	if (*trace_type == fc_trc_flag->fnic_trace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		fnic_tracing_enabled = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	else if (*trace_type == fc_trc_flag->fc_trace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		fnic_fc_tracing_enabled = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	else if (*trace_type == fc_trc_flag->fc_clear)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		fnic_fc_trace_cleared = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		pr_err("fnic: cannot write to any debugfs file\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	(*ppos)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	return cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static const struct file_operations fnic_trace_ctrl_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	.open = simple_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	.read = fnic_trace_ctrl_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	.write = fnic_trace_ctrl_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  * fnic_trace_debugfs_open - Open the fnic trace log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  * @inode: The inode pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  * @file: The file pointer to attach the log output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)  * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)  * This routine is the entry point for the debugfs open file operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)  * It allocates the necessary buffer for the log, fills the buffer from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)  * the in-memory log and then returns a pointer to that log in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)  * the private_data field in @file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)  * This function returns zero if successful. On error it will return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)  * a negative error value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static int fnic_trace_debugfs_open(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 				  struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	fnic_dbgfs_t *fnic_dbg_prt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	u8 *rdata_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	rdata_ptr = (u8 *)inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	fnic_dbg_prt = kzalloc(sizeof(fnic_dbgfs_t), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	if (!fnic_dbg_prt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	if (*rdata_ptr == fc_trc_flag->fnic_trace) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		fnic_dbg_prt->buffer = vmalloc(array3_size(3, trace_max_pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 							   PAGE_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		if (!fnic_dbg_prt->buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			kfree(fnic_dbg_prt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		memset((void *)fnic_dbg_prt->buffer, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		3 * (trace_max_pages * PAGE_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		fnic_dbg_prt->buffer_len = fnic_get_trace_data(fnic_dbg_prt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		fnic_dbg_prt->buffer =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			vmalloc(array3_size(3, fnic_fc_trace_max_pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 					    PAGE_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		if (!fnic_dbg_prt->buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			kfree(fnic_dbg_prt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		memset((void *)fnic_dbg_prt->buffer, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			3 * (fnic_fc_trace_max_pages * PAGE_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		fnic_dbg_prt->buffer_len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 			fnic_fc_trace_get_data(fnic_dbg_prt, *rdata_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	file->private_data = fnic_dbg_prt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  * fnic_trace_debugfs_lseek - Seek through a debugfs file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  * @file: The file pointer to seek through.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)  * @offset: The offset to seek to or the amount to seek by.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)  * @howto: Indicates how to seek.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)  * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)  * This routine is the entry point for the debugfs lseek file operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)  * The @howto parameter indicates whether @offset is the offset to directly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)  * seek to, or if it is a value to seek forward or reverse by. This function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)  * figures out what the new offset of the debugfs file will be and assigns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)  * that value to the f_pos field of @file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)  * This function returns the new offset if successful and returns a negative
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)  * error if unable to process the seek.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) static loff_t fnic_trace_debugfs_lseek(struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 					loff_t offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 					int howto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	fnic_dbgfs_t *fnic_dbg_prt = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	return fixed_size_llseek(file, offset, howto,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 				fnic_dbg_prt->buffer_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)  * fnic_trace_debugfs_read - Read a debugfs file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)  * @file: The file pointer to read from.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)  * @ubuf: The buffer to copy the data to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)  * @nbytes: The number of bytes to read.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)  * @pos: The position in the file to start reading from.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)  * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)  * This routine reads data from the buffer indicated in the private_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)  * field of @file. It will start reading at @pos and copy up to @nbytes of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)  * data to @ubuf.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)  * This function returns the amount of data that was read (this could be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)  * less than @nbytes if the end of the file was reached).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) static ssize_t fnic_trace_debugfs_read(struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 					char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 					size_t nbytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 					loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	fnic_dbgfs_t *fnic_dbg_prt = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	rc = simple_read_from_buffer(ubuf, nbytes, pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 				  fnic_dbg_prt->buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 				  fnic_dbg_prt->buffer_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  * fnic_trace_debugfs_release - Release the buffer used to store
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)  * debugfs file data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)  * @inode: The inode pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)  * @file: The file pointer that contains the buffer to release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)  * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)  * This routine frees the buffer that was allocated when the debugfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)  * file was opened.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)  * This function returns zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) static int fnic_trace_debugfs_release(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 					  struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	fnic_dbgfs_t *fnic_dbg_prt = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	vfree(fnic_dbg_prt->buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	kfree(fnic_dbg_prt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) static const struct file_operations fnic_trace_debugfs_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	.open = fnic_trace_debugfs_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	.llseek = fnic_trace_debugfs_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	.read = fnic_trace_debugfs_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	.release = fnic_trace_debugfs_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)  * fnic_trace_debugfs_init - Initialize debugfs for fnic trace logging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)  * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)  * When Debugfs is configured this routine sets up the fnic debugfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)  * file system. If not already created, this routine will create the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)  * create file trace to log fnic trace buffer output into debugfs and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)  * it will also create file trace_enable to control enable/disable of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)  * trace logging into trace buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) void fnic_trace_debugfs_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	fnic_trace_enable = debugfs_create_file("tracing_enable",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 					S_IFREG|S_IRUGO|S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 					fnic_trace_debugfs_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 					&(fc_trc_flag->fnic_trace),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 					&fnic_trace_ctrl_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	fnic_trace_debugfs_file = debugfs_create_file("trace",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 					S_IFREG|S_IRUGO|S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 					fnic_trace_debugfs_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 					&(fc_trc_flag->fnic_trace),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 					&fnic_trace_debugfs_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)  * fnic_trace_debugfs_terminate - Tear down debugfs infrastructure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)  * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)  * When Debugfs is configured this routine removes debugfs file system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)  * elements that are specific to fnic trace logging.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) void fnic_trace_debugfs_terminate(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	debugfs_remove(fnic_trace_debugfs_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	fnic_trace_debugfs_file = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	debugfs_remove(fnic_trace_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	fnic_trace_enable = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)  * fnic_fc_trace_debugfs_init -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)  * Initialize debugfs for fnic control frame trace logging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)  * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)  * When Debugfs is configured this routine sets up the fnic_fc debugfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)  * file system. If not already created, this routine will create the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)  * create file trace to log fnic fc trace buffer output into debugfs and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)  * it will also create file fc_trace_enable to control enable/disable of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)  * trace logging into trace buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) void fnic_fc_trace_debugfs_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	fnic_fc_trace_enable = debugfs_create_file("fc_trace_enable",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 					S_IFREG|S_IRUGO|S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 					fnic_trace_debugfs_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 					&(fc_trc_flag->fc_trace),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 					&fnic_trace_ctrl_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	fnic_fc_trace_clear = debugfs_create_file("fc_trace_clear",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 					S_IFREG|S_IRUGO|S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 					fnic_trace_debugfs_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 					&(fc_trc_flag->fc_clear),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 					&fnic_trace_ctrl_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	fnic_fc_rdata_trace_debugfs_file =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		debugfs_create_file("fc_trace_rdata",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 				    S_IFREG|S_IRUGO|S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 				    fnic_trace_debugfs_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 				    &(fc_trc_flag->fc_normal_file),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 				    &fnic_trace_debugfs_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	fnic_fc_trace_debugfs_file =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		debugfs_create_file("fc_trace",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 				    S_IFREG|S_IRUGO|S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 				    fnic_trace_debugfs_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 				    &(fc_trc_flag->fc_row_file),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 				    &fnic_trace_debugfs_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)  * fnic_fc_trace_debugfs_terminate - Tear down debugfs infrastructure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)  * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)  * When Debugfs is configured this routine removes debugfs file system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)  * elements that are specific to fnic_fc trace logging.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) void fnic_fc_trace_debugfs_terminate(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	debugfs_remove(fnic_fc_trace_debugfs_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	fnic_fc_trace_debugfs_file = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	debugfs_remove(fnic_fc_rdata_trace_debugfs_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	fnic_fc_rdata_trace_debugfs_file = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	debugfs_remove(fnic_fc_trace_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	fnic_fc_trace_enable = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	debugfs_remove(fnic_fc_trace_clear);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	fnic_fc_trace_clear = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)  * fnic_reset_stats_open - Open the reset_stats file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)  * @inode: The inode pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)  * @file: The file pointer to attach the stats reset flag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)  * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)  * This routine opens a debugsfs file reset_stats and stores i_private data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)  * to debug structure to retrieve later for while performing other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)  * file oprations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)  * This function returns zero if successful.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) static int fnic_reset_stats_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	struct stats_debug_info *debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	debug = kzalloc(sizeof(struct stats_debug_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	if (!debug)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	debug->i_private = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	file->private_data = debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)  * fnic_reset_stats_read - Read a reset_stats debugfs file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)  * @filp: The file pointer to read from.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)  * @ubuf: The buffer to copy the data to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)  * @cnt: The number of bytes to read.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)  * @ppos: The position in the file to start reading from.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)  * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)  * This routine reads value of variable reset_stats
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)  * and stores into local @buf. It will start reading file at @ppos and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)  * copy up to @cnt of data to @ubuf from @buf.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)  * This function returns the amount of data that was read.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) static ssize_t fnic_reset_stats_read(struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 					char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 					size_t cnt, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	struct stats_debug_info *debug = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	struct fnic *fnic = (struct fnic *)debug->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	char buf[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	len = sprintf(buf, "%u\n", fnic->reset_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	return simple_read_from_buffer(ubuf, cnt, ppos, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)  * fnic_reset_stats_write - Write to reset_stats debugfs file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)  * @filp: The file pointer to write from.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)  * @ubuf: The buffer to copy the data from.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)  * @cnt: The number of bytes to write.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)  * @ppos: The position in the file to start writing to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)  * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)  * This routine writes data from user buffer @ubuf to buffer @buf and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)  * resets cumulative stats of fnic.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)  * This function returns the amount of data that was written.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) static ssize_t fnic_reset_stats_write(struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 					const char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 					size_t cnt, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	struct stats_debug_info *debug = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	struct fnic *fnic = (struct fnic *)debug->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	struct fnic_stats *stats = &fnic->fnic_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	u64 *io_stats_p = (u64 *)&stats->io_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	u64 *fw_stats_p = (u64 *)&stats->fw_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	char buf[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	if (cnt >= sizeof(buf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	if (copy_from_user(&buf, ubuf, cnt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	buf[cnt] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	ret = kstrtoul(buf, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	fnic->reset_stats = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	if (fnic->reset_stats) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 		/* Skip variable is used to avoid descrepancies to Num IOs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 		 * and IO Completions stats. Skip incrementing No IO Compls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		 * for pending active IOs after reset stats
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 		atomic64_set(&fnic->io_cmpl_skip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 			atomic64_read(&stats->io_stats.active_ios));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 		memset(&stats->abts_stats, 0, sizeof(struct abort_stats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 		memset(&stats->term_stats, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 			sizeof(struct terminate_stats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 		memset(&stats->reset_stats, 0, sizeof(struct reset_stats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 		memset(&stats->misc_stats, 0, sizeof(struct misc_stats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 		memset(&stats->vlan_stats, 0, sizeof(struct vlan_stats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 		memset(io_stats_p+1, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 			sizeof(struct io_path_stats) - sizeof(u64));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 		memset(fw_stats_p+1, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 			sizeof(struct fw_stats) - sizeof(u64));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 		ktime_get_real_ts64(&stats->stats_timestamps.last_reset_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	(*ppos)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	return cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)  * fnic_reset_stats_release - Release the buffer used to store
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)  * debugfs file data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)  * @inode: The inode pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)  * @file: The file pointer that contains the buffer to release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)  * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)  * This routine frees the buffer that was allocated when the debugfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)  * file was opened.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)  * This function returns zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) static int fnic_reset_stats_release(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 					struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	struct stats_debug_info *debug = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	kfree(debug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)  * fnic_stats_debugfs_open - Open the stats file for specific host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)  * and get fnic stats.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)  * @inode: The inode pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)  * @file: The file pointer to attach the specific host statistics.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)  * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)  * This routine opens a debugsfs file stats of specific host and print
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)  * fnic stats.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)  * This function returns zero if successful.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) static int fnic_stats_debugfs_open(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 					struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	struct fnic *fnic = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	struct fnic_stats *fnic_stats = &fnic->fnic_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	struct stats_debug_info *debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	int buf_size = 2 * PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	debug = kzalloc(sizeof(struct stats_debug_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	if (!debug)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	debug->debug_buffer = vmalloc(buf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	if (!debug->debug_buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 		kfree(debug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	debug->buf_size = buf_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	memset((void *)debug->debug_buffer, 0, buf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	debug->buffer_len = fnic_get_stats_data(debug, fnic_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	file->private_data = debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)  * fnic_stats_debugfs_read - Read a debugfs file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)  * @file: The file pointer to read from.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)  * @ubuf: The buffer to copy the data to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)  * @nbytes: The number of bytes to read.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)  * @pos: The position in the file to start reading from.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)  * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)  * This routine reads data from the buffer indicated in the private_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)  * field of @file. It will start reading at @pos and copy up to @nbytes of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)  * data to @ubuf.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)  * This function returns the amount of data that was read (this could be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)  * less than @nbytes if the end of the file was reached).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) static ssize_t fnic_stats_debugfs_read(struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 					char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 					size_t nbytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 					loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	struct stats_debug_info *debug = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	rc = simple_read_from_buffer(ubuf, nbytes, pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 					debug->debug_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 					debug->buffer_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)  * fnic_stats_stats_release - Release the buffer used to store
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)  * debugfs file data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)  * @inode: The inode pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)  * @file: The file pointer that contains the buffer to release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)  * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)  * This routine frees the buffer that was allocated when the debugfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)  * file was opened.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)  * This function returns zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) static int fnic_stats_debugfs_release(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 					struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	struct stats_debug_info *debug = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	vfree(debug->debug_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	kfree(debug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) static const struct file_operations fnic_stats_debugfs_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	.open = fnic_stats_debugfs_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	.read = fnic_stats_debugfs_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	.release = fnic_stats_debugfs_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) static const struct file_operations fnic_reset_debugfs_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 	.open = fnic_reset_stats_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	.read = fnic_reset_stats_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	.write = fnic_reset_stats_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	.release = fnic_reset_stats_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)  * fnic_stats_init - Initialize stats struct and create stats file per fnic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)  * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)  * When Debugfs is configured this routine sets up the stats file per fnic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)  * It will create file stats and reset_stats under statistics/host# directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)  * to log per fnic stats.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) void fnic_stats_debugfs_init(struct fnic *fnic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 	char name[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 	snprintf(name, sizeof(name), "host%d", fnic->lport->host->host_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	fnic->fnic_stats_debugfs_host = debugfs_create_dir(name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 						fnic_stats_debugfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	fnic->fnic_stats_debugfs_file = debugfs_create_file("stats",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 						S_IFREG|S_IRUGO|S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 						fnic->fnic_stats_debugfs_host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 						fnic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 						&fnic_stats_debugfs_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 	fnic->fnic_reset_debugfs_file = debugfs_create_file("reset_stats",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 						S_IFREG|S_IRUGO|S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 						fnic->fnic_stats_debugfs_host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 						fnic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 						&fnic_reset_debugfs_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)  * fnic_stats_debugfs_remove - Tear down debugfs infrastructure of stats
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)  * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)  * When Debugfs is configured this routine removes debugfs file system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722)  * elements that are specific to fnic stats.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) void fnic_stats_debugfs_remove(struct fnic *fnic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 	if (!fnic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 	debugfs_remove(fnic->fnic_stats_debugfs_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 	fnic->fnic_stats_debugfs_file = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	debugfs_remove(fnic->fnic_reset_debugfs_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 	fnic->fnic_reset_debugfs_file = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 	debugfs_remove(fnic->fnic_stats_debugfs_host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 	fnic->fnic_stats_debugfs_host = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) }