18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright 2014 Cisco Systems, Inc.  All rights reserved.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * This program is free software; you may redistribute it and/or modify
58c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by
68c2ecf20Sopenharmony_ci * the Free Software Foundation; version 2 of the License.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
98c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
108c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
118c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
128c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
138c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
148c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
158c2ecf20Sopenharmony_ci * SOFTWARE.
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#include <linux/module.h>
198c2ecf20Sopenharmony_ci#include <linux/errno.h>
208c2ecf20Sopenharmony_ci#include <linux/debugfs.h>
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#include "snic.h"
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/*
258c2ecf20Sopenharmony_ci * snic_debugfs_init - Initialize debugfs for snic debug logging
268c2ecf20Sopenharmony_ci *
278c2ecf20Sopenharmony_ci * Description:
288c2ecf20Sopenharmony_ci * When Debugfs is configured this routine sets up fnic debugfs
298c2ecf20Sopenharmony_ci * filesystem. If not already created. this routine will crate the
308c2ecf20Sopenharmony_ci * fnic directory and statistics directory for trace buffer and
318c2ecf20Sopenharmony_ci * stats logging
328c2ecf20Sopenharmony_ci */
338c2ecf20Sopenharmony_civoid snic_debugfs_init(void)
348c2ecf20Sopenharmony_ci{
358c2ecf20Sopenharmony_ci	snic_glob->trc_root = debugfs_create_dir("snic", NULL);
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci	snic_glob->stats_root = debugfs_create_dir("statistics",
388c2ecf20Sopenharmony_ci						   snic_glob->trc_root);
398c2ecf20Sopenharmony_ci}
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci/*
428c2ecf20Sopenharmony_ci * snic_debugfs_term - Tear down debugfs intrastructure
438c2ecf20Sopenharmony_ci *
448c2ecf20Sopenharmony_ci * Description:
458c2ecf20Sopenharmony_ci * When Debufs is configured this routine removes debugfs file system
468c2ecf20Sopenharmony_ci * elements that are specific to snic
478c2ecf20Sopenharmony_ci */
488c2ecf20Sopenharmony_civoid
498c2ecf20Sopenharmony_cisnic_debugfs_term(void)
508c2ecf20Sopenharmony_ci{
518c2ecf20Sopenharmony_ci	debugfs_remove(snic_glob->stats_root);
528c2ecf20Sopenharmony_ci	snic_glob->stats_root = NULL;
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci	debugfs_remove(snic_glob->trc_root);
558c2ecf20Sopenharmony_ci	snic_glob->trc_root = NULL;
568c2ecf20Sopenharmony_ci}
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci/*
598c2ecf20Sopenharmony_ci * snic_reset_stats_open - Open the reset_stats file
608c2ecf20Sopenharmony_ci */
618c2ecf20Sopenharmony_cistatic int
628c2ecf20Sopenharmony_cisnic_reset_stats_open(struct inode *inode, struct file *filp)
638c2ecf20Sopenharmony_ci{
648c2ecf20Sopenharmony_ci	SNIC_BUG_ON(!inode->i_private);
658c2ecf20Sopenharmony_ci	filp->private_data = inode->i_private;
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci	return 0;
688c2ecf20Sopenharmony_ci}
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci/*
718c2ecf20Sopenharmony_ci * snic_reset_stats_read - Read a reset_stats debugfs file
728c2ecf20Sopenharmony_ci * @filp: The file pointer to read from.
738c2ecf20Sopenharmony_ci * @ubuf: The buffer tocopy the data to.
748c2ecf20Sopenharmony_ci * @cnt: The number of bytes to read.
758c2ecf20Sopenharmony_ci * @ppos: The position in the file to start reading frm.
768c2ecf20Sopenharmony_ci *
778c2ecf20Sopenharmony_ci * Description:
788c2ecf20Sopenharmony_ci * This routine reads value of variable reset_stats
798c2ecf20Sopenharmony_ci * and stores into local @buf. It will start reading file @ppos and
808c2ecf20Sopenharmony_ci * copy up to @cnt of data to @ubuf from @buf.
818c2ecf20Sopenharmony_ci *
828c2ecf20Sopenharmony_ci * Returns:
838c2ecf20Sopenharmony_ci * This function returns the amount of data that was read.
848c2ecf20Sopenharmony_ci */
858c2ecf20Sopenharmony_cistatic ssize_t
868c2ecf20Sopenharmony_cisnic_reset_stats_read(struct file *filp,
878c2ecf20Sopenharmony_ci		      char __user *ubuf,
888c2ecf20Sopenharmony_ci		      size_t cnt,
898c2ecf20Sopenharmony_ci		      loff_t *ppos)
908c2ecf20Sopenharmony_ci{
918c2ecf20Sopenharmony_ci	struct snic *snic = (struct snic *) filp->private_data;
928c2ecf20Sopenharmony_ci	char buf[64];
938c2ecf20Sopenharmony_ci	int len;
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	len = sprintf(buf, "%u\n", snic->reset_stats);
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	return simple_read_from_buffer(ubuf, cnt, ppos, buf, len);
988c2ecf20Sopenharmony_ci}
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci/*
1018c2ecf20Sopenharmony_ci * snic_reset_stats_write - Write to reset_stats debugfs file
1028c2ecf20Sopenharmony_ci * @filp: The file pointer to write from
1038c2ecf20Sopenharmony_ci * @ubuf: The buffer to copy the data from.
1048c2ecf20Sopenharmony_ci * @cnt: The number of bytes to write.
1058c2ecf20Sopenharmony_ci * @ppos: The position in the file to start writing to.
1068c2ecf20Sopenharmony_ci *
1078c2ecf20Sopenharmony_ci * Description:
1088c2ecf20Sopenharmony_ci * This routine writes data from user buffer @ubuf to buffer @buf and
1098c2ecf20Sopenharmony_ci * resets cumulative stats of snic.
1108c2ecf20Sopenharmony_ci *
1118c2ecf20Sopenharmony_ci * Returns:
1128c2ecf20Sopenharmony_ci * This function returns the amount of data that was written.
1138c2ecf20Sopenharmony_ci */
1148c2ecf20Sopenharmony_cistatic ssize_t
1158c2ecf20Sopenharmony_cisnic_reset_stats_write(struct file *filp,
1168c2ecf20Sopenharmony_ci		       const char __user *ubuf,
1178c2ecf20Sopenharmony_ci		       size_t cnt,
1188c2ecf20Sopenharmony_ci		       loff_t *ppos)
1198c2ecf20Sopenharmony_ci{
1208c2ecf20Sopenharmony_ci	struct snic *snic = (struct snic *) filp->private_data;
1218c2ecf20Sopenharmony_ci	struct snic_stats *stats = &snic->s_stats;
1228c2ecf20Sopenharmony_ci	u64 *io_stats_p = (u64 *) &stats->io;
1238c2ecf20Sopenharmony_ci	u64 *fw_stats_p = (u64 *) &stats->fw;
1248c2ecf20Sopenharmony_ci	char buf[64];
1258c2ecf20Sopenharmony_ci	unsigned long val;
1268c2ecf20Sopenharmony_ci	int ret;
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci	if (cnt >= sizeof(buf))
1298c2ecf20Sopenharmony_ci		return -EINVAL;
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci	if (copy_from_user(&buf, ubuf, cnt))
1328c2ecf20Sopenharmony_ci		return -EFAULT;
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci	buf[cnt] = '\0';
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci	ret = kstrtoul(buf, 10, &val);
1378c2ecf20Sopenharmony_ci	if (ret < 0)
1388c2ecf20Sopenharmony_ci		return ret;
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci	snic->reset_stats = val;
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci	if (snic->reset_stats) {
1438c2ecf20Sopenharmony_ci		/* Skip variable is used to avoid descrepancies to Num IOs
1448c2ecf20Sopenharmony_ci		 * and IO Completions stats. Skip incrementing No IO Compls
1458c2ecf20Sopenharmony_ci		 * for pending active IOs after reset_stats
1468c2ecf20Sopenharmony_ci		 */
1478c2ecf20Sopenharmony_ci		atomic64_set(&snic->io_cmpl_skip,
1488c2ecf20Sopenharmony_ci			     atomic64_read(&stats->io.active));
1498c2ecf20Sopenharmony_ci		memset(&stats->abts, 0, sizeof(struct snic_abort_stats));
1508c2ecf20Sopenharmony_ci		memset(&stats->reset, 0, sizeof(struct snic_reset_stats));
1518c2ecf20Sopenharmony_ci		memset(&stats->misc, 0, sizeof(struct snic_misc_stats));
1528c2ecf20Sopenharmony_ci		memset(io_stats_p+1,
1538c2ecf20Sopenharmony_ci			0,
1548c2ecf20Sopenharmony_ci			sizeof(struct snic_io_stats) - sizeof(u64));
1558c2ecf20Sopenharmony_ci		memset(fw_stats_p+1,
1568c2ecf20Sopenharmony_ci			0,
1578c2ecf20Sopenharmony_ci			sizeof(struct snic_fw_stats) - sizeof(u64));
1588c2ecf20Sopenharmony_ci	}
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci	(*ppos)++;
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci	SNIC_HOST_INFO(snic->shost, "Reset Op: Driver statistics.\n");
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci	return cnt;
1658c2ecf20Sopenharmony_ci}
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_cistatic int
1688c2ecf20Sopenharmony_cisnic_reset_stats_release(struct inode *inode, struct file *filp)
1698c2ecf20Sopenharmony_ci{
1708c2ecf20Sopenharmony_ci	filp->private_data = NULL;
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci	return 0;
1738c2ecf20Sopenharmony_ci}
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci/*
1768c2ecf20Sopenharmony_ci * snic_stats_show - Formats and prints per host specific driver stats.
1778c2ecf20Sopenharmony_ci */
1788c2ecf20Sopenharmony_cistatic int
1798c2ecf20Sopenharmony_cisnic_stats_show(struct seq_file *sfp, void *data)
1808c2ecf20Sopenharmony_ci{
1818c2ecf20Sopenharmony_ci	struct snic *snic = (struct snic *) sfp->private;
1828c2ecf20Sopenharmony_ci	struct snic_stats *stats = &snic->s_stats;
1838c2ecf20Sopenharmony_ci	struct timespec64 last_isr_tms, last_ack_tms;
1848c2ecf20Sopenharmony_ci	u64 maxio_tm;
1858c2ecf20Sopenharmony_ci	int i;
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci	/* Dump IO Stats */
1888c2ecf20Sopenharmony_ci	seq_printf(sfp,
1898c2ecf20Sopenharmony_ci		   "------------------------------------------\n"
1908c2ecf20Sopenharmony_ci		   "\t\t IO Statistics\n"
1918c2ecf20Sopenharmony_ci		   "------------------------------------------\n");
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci	maxio_tm = (u64) atomic64_read(&stats->io.max_time);
1948c2ecf20Sopenharmony_ci	seq_printf(sfp,
1958c2ecf20Sopenharmony_ci		   "Active IOs                  : %lld\n"
1968c2ecf20Sopenharmony_ci		   "Max Active IOs              : %lld\n"
1978c2ecf20Sopenharmony_ci		   "Total IOs                   : %lld\n"
1988c2ecf20Sopenharmony_ci		   "IOs Completed               : %lld\n"
1998c2ecf20Sopenharmony_ci		   "IOs Failed                  : %lld\n"
2008c2ecf20Sopenharmony_ci		   "IOs Not Found               : %lld\n"
2018c2ecf20Sopenharmony_ci		   "Memory Alloc Failures       : %lld\n"
2028c2ecf20Sopenharmony_ci		   "REQs Null                   : %lld\n"
2038c2ecf20Sopenharmony_ci		   "SCSI Cmd Pointers Null      : %lld\n"
2048c2ecf20Sopenharmony_ci		   "Max SGL for any IO          : %lld\n"
2058c2ecf20Sopenharmony_ci		   "Max IO Size                 : %lld Sectors\n"
2068c2ecf20Sopenharmony_ci		   "Max Queuing Time            : %lld\n"
2078c2ecf20Sopenharmony_ci		   "Max Completion Time         : %lld\n"
2088c2ecf20Sopenharmony_ci		   "Max IO Process Time(FW)     : %lld (%u msec)\n",
2098c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->io.active),
2108c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->io.max_active),
2118c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->io.num_ios),
2128c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->io.compl),
2138c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->io.fail),
2148c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->io.io_not_found),
2158c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->io.alloc_fail),
2168c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->io.req_null),
2178c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->io.sc_null),
2188c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->io.max_sgl),
2198c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->io.max_io_sz),
2208c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->io.max_qtime),
2218c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->io.max_cmpl_time),
2228c2ecf20Sopenharmony_ci		   maxio_tm,
2238c2ecf20Sopenharmony_ci		   jiffies_to_msecs(maxio_tm));
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci	seq_puts(sfp, "\nSGL Counters\n");
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci	for (i = 0; i < SNIC_MAX_SG_DESC_CNT; i++) {
2288c2ecf20Sopenharmony_ci		seq_printf(sfp,
2298c2ecf20Sopenharmony_ci			   "%10lld ",
2308c2ecf20Sopenharmony_ci			   (u64) atomic64_read(&stats->io.sgl_cnt[i]));
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci		if ((i + 1) % 8 == 0)
2338c2ecf20Sopenharmony_ci			seq_puts(sfp, "\n");
2348c2ecf20Sopenharmony_ci	}
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci	/* Dump Abort Stats */
2378c2ecf20Sopenharmony_ci	seq_printf(sfp,
2388c2ecf20Sopenharmony_ci		   "\n-------------------------------------------\n"
2398c2ecf20Sopenharmony_ci		   "\t\t Abort Statistics\n"
2408c2ecf20Sopenharmony_ci		   "---------------------------------------------\n");
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_ci	seq_printf(sfp,
2438c2ecf20Sopenharmony_ci		   "Aborts                      : %lld\n"
2448c2ecf20Sopenharmony_ci		   "Aborts Fail                 : %lld\n"
2458c2ecf20Sopenharmony_ci		   "Aborts Driver Timeout       : %lld\n"
2468c2ecf20Sopenharmony_ci		   "Abort FW Timeout            : %lld\n"
2478c2ecf20Sopenharmony_ci		   "Abort IO NOT Found          : %lld\n"
2488c2ecf20Sopenharmony_ci		   "Abort Queuing Failed        : %lld\n",
2498c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->abts.num),
2508c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->abts.fail),
2518c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->abts.drv_tmo),
2528c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->abts.fw_tmo),
2538c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->abts.io_not_found),
2548c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->abts.q_fail));
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_ci	/* Dump Reset Stats */
2578c2ecf20Sopenharmony_ci	seq_printf(sfp,
2588c2ecf20Sopenharmony_ci		   "\n-------------------------------------------\n"
2598c2ecf20Sopenharmony_ci		   "\t\t Reset Statistics\n"
2608c2ecf20Sopenharmony_ci		   "---------------------------------------------\n");
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci	seq_printf(sfp,
2638c2ecf20Sopenharmony_ci		   "HBA Resets                  : %lld\n"
2648c2ecf20Sopenharmony_ci		   "HBA Reset Cmpls             : %lld\n"
2658c2ecf20Sopenharmony_ci		   "HBA Reset Fail              : %lld\n",
2668c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->reset.hba_resets),
2678c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->reset.hba_reset_cmpl),
2688c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->reset.hba_reset_fail));
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci	/* Dump Firmware Stats */
2718c2ecf20Sopenharmony_ci	seq_printf(sfp,
2728c2ecf20Sopenharmony_ci		   "\n-------------------------------------------\n"
2738c2ecf20Sopenharmony_ci		   "\t\t Firmware Statistics\n"
2748c2ecf20Sopenharmony_ci		   "---------------------------------------------\n");
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci	seq_printf(sfp,
2778c2ecf20Sopenharmony_ci		"Active FW Requests             : %lld\n"
2788c2ecf20Sopenharmony_ci		"Max FW Requests                : %lld\n"
2798c2ecf20Sopenharmony_ci		"FW Out Of Resource Errs        : %lld\n"
2808c2ecf20Sopenharmony_ci		"FW IO Errors                   : %lld\n"
2818c2ecf20Sopenharmony_ci		"FW SCSI Errors                 : %lld\n",
2828c2ecf20Sopenharmony_ci		(u64) atomic64_read(&stats->fw.actv_reqs),
2838c2ecf20Sopenharmony_ci		(u64) atomic64_read(&stats->fw.max_actv_reqs),
2848c2ecf20Sopenharmony_ci		(u64) atomic64_read(&stats->fw.out_of_res),
2858c2ecf20Sopenharmony_ci		(u64) atomic64_read(&stats->fw.io_errs),
2868c2ecf20Sopenharmony_ci		(u64) atomic64_read(&stats->fw.scsi_errs));
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_ci	/* Dump Miscellenous Stats */
2908c2ecf20Sopenharmony_ci	seq_printf(sfp,
2918c2ecf20Sopenharmony_ci		   "\n---------------------------------------------\n"
2928c2ecf20Sopenharmony_ci		   "\t\t Other Statistics\n"
2938c2ecf20Sopenharmony_ci		   "\n---------------------------------------------\n");
2948c2ecf20Sopenharmony_ci
2958c2ecf20Sopenharmony_ci	jiffies_to_timespec64(stats->misc.last_isr_time, &last_isr_tms);
2968c2ecf20Sopenharmony_ci	jiffies_to_timespec64(stats->misc.last_ack_time, &last_ack_tms);
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci	seq_printf(sfp,
2998c2ecf20Sopenharmony_ci		   "Last ISR Time               : %llu (%8llu.%09lu)\n"
3008c2ecf20Sopenharmony_ci		   "Last Ack Time               : %llu (%8llu.%09lu)\n"
3018c2ecf20Sopenharmony_ci		   "Ack ISRs                    : %llu\n"
3028c2ecf20Sopenharmony_ci		   "IO Cmpl ISRs                : %llu\n"
3038c2ecf20Sopenharmony_ci		   "Err Notify ISRs             : %llu\n"
3048c2ecf20Sopenharmony_ci		   "Max CQ Entries              : %lld\n"
3058c2ecf20Sopenharmony_ci		   "Data Count Mismatch         : %lld\n"
3068c2ecf20Sopenharmony_ci		   "IOs w/ Timeout Status       : %lld\n"
3078c2ecf20Sopenharmony_ci		   "IOs w/ Aborted Status       : %lld\n"
3088c2ecf20Sopenharmony_ci		   "IOs w/ SGL Invalid Stat     : %lld\n"
3098c2ecf20Sopenharmony_ci		   "WQ Desc Alloc Fail          : %lld\n"
3108c2ecf20Sopenharmony_ci		   "Queue Full                  : %lld\n"
3118c2ecf20Sopenharmony_ci		   "Queue Ramp Up               : %lld\n"
3128c2ecf20Sopenharmony_ci		   "Queue Ramp Down             : %lld\n"
3138c2ecf20Sopenharmony_ci		   "Queue Last Queue Depth      : %lld\n"
3148c2ecf20Sopenharmony_ci		   "Target Not Ready            : %lld\n",
3158c2ecf20Sopenharmony_ci		   (u64) stats->misc.last_isr_time,
3168c2ecf20Sopenharmony_ci		   last_isr_tms.tv_sec, last_isr_tms.tv_nsec,
3178c2ecf20Sopenharmony_ci		   (u64)stats->misc.last_ack_time,
3188c2ecf20Sopenharmony_ci		   last_ack_tms.tv_sec, last_ack_tms.tv_nsec,
3198c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->misc.ack_isr_cnt),
3208c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->misc.cmpl_isr_cnt),
3218c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->misc.errnotify_isr_cnt),
3228c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->misc.max_cq_ents),
3238c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->misc.data_cnt_mismat),
3248c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->misc.io_tmo),
3258c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->misc.io_aborted),
3268c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->misc.sgl_inval),
3278c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->misc.wq_alloc_fail),
3288c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->misc.qfull),
3298c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->misc.qsz_rampup),
3308c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->misc.qsz_rampdown),
3318c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->misc.last_qsz),
3328c2ecf20Sopenharmony_ci		   (u64) atomic64_read(&stats->misc.tgt_not_rdy));
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_ci	return 0;
3358c2ecf20Sopenharmony_ci}
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci/*
3388c2ecf20Sopenharmony_ci * snic_stats_open - Open the stats file for specific host
3398c2ecf20Sopenharmony_ci *
3408c2ecf20Sopenharmony_ci * Description:
3418c2ecf20Sopenharmony_ci * This routine opens a debugfs file stats of specific host
3428c2ecf20Sopenharmony_ci */
3438c2ecf20Sopenharmony_cistatic int
3448c2ecf20Sopenharmony_cisnic_stats_open(struct inode *inode, struct file *filp)
3458c2ecf20Sopenharmony_ci{
3468c2ecf20Sopenharmony_ci	return single_open(filp, snic_stats_show, inode->i_private);
3478c2ecf20Sopenharmony_ci}
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_cistatic const struct file_operations snic_stats_fops = {
3508c2ecf20Sopenharmony_ci	.owner	= THIS_MODULE,
3518c2ecf20Sopenharmony_ci	.open	= snic_stats_open,
3528c2ecf20Sopenharmony_ci	.read	= seq_read,
3538c2ecf20Sopenharmony_ci	.llseek = seq_lseek,
3548c2ecf20Sopenharmony_ci	.release = single_release,
3558c2ecf20Sopenharmony_ci};
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_cistatic const struct file_operations snic_reset_stats_fops = {
3588c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
3598c2ecf20Sopenharmony_ci	.open = snic_reset_stats_open,
3608c2ecf20Sopenharmony_ci	.read = snic_reset_stats_read,
3618c2ecf20Sopenharmony_ci	.write = snic_reset_stats_write,
3628c2ecf20Sopenharmony_ci	.release = snic_reset_stats_release,
3638c2ecf20Sopenharmony_ci};
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_ci/*
3668c2ecf20Sopenharmony_ci * snic_stats_init - Initialize stats struct and create stats file
3678c2ecf20Sopenharmony_ci * per snic
3688c2ecf20Sopenharmony_ci *
3698c2ecf20Sopenharmony_ci * Description:
3708c2ecf20Sopenharmony_ci * When debugfs is cofigured this routine sets up the stats file per snic
3718c2ecf20Sopenharmony_ci * It will create file stats and reset_stats under statistics/host# directory
3728c2ecf20Sopenharmony_ci * to log per snic stats
3738c2ecf20Sopenharmony_ci */
3748c2ecf20Sopenharmony_civoid snic_stats_debugfs_init(struct snic *snic)
3758c2ecf20Sopenharmony_ci{
3768c2ecf20Sopenharmony_ci	char name[16];
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_ci	snprintf(name, sizeof(name), "host%d", snic->shost->host_no);
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ci	snic->stats_host = debugfs_create_dir(name, snic_glob->stats_root);
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_ci	snic->stats_file = debugfs_create_file("stats", S_IFREG|S_IRUGO,
3838c2ecf20Sopenharmony_ci					       snic->stats_host, snic,
3848c2ecf20Sopenharmony_ci					       &snic_stats_fops);
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci	snic->reset_stats_file = debugfs_create_file("reset_stats",
3878c2ecf20Sopenharmony_ci						     S_IFREG|S_IRUGO|S_IWUSR,
3888c2ecf20Sopenharmony_ci						     snic->stats_host, snic,
3898c2ecf20Sopenharmony_ci						     &snic_reset_stats_fops);
3908c2ecf20Sopenharmony_ci}
3918c2ecf20Sopenharmony_ci
3928c2ecf20Sopenharmony_ci/*
3938c2ecf20Sopenharmony_ci * snic_stats_debugfs_remove - Tear down debugfs infrastructure of stats
3948c2ecf20Sopenharmony_ci *
3958c2ecf20Sopenharmony_ci * Description:
3968c2ecf20Sopenharmony_ci * When Debufs is configured this routine removes debugfs file system
3978c2ecf20Sopenharmony_ci * elements that are specific to to snic stats
3988c2ecf20Sopenharmony_ci */
3998c2ecf20Sopenharmony_civoid
4008c2ecf20Sopenharmony_cisnic_stats_debugfs_remove(struct snic *snic)
4018c2ecf20Sopenharmony_ci{
4028c2ecf20Sopenharmony_ci	debugfs_remove(snic->stats_file);
4038c2ecf20Sopenharmony_ci	snic->stats_file = NULL;
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ci	debugfs_remove(snic->reset_stats_file);
4068c2ecf20Sopenharmony_ci	snic->reset_stats_file = NULL;
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_ci	debugfs_remove(snic->stats_host);
4098c2ecf20Sopenharmony_ci	snic->stats_host = NULL;
4108c2ecf20Sopenharmony_ci}
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_ci/* Trace Facility related API */
4138c2ecf20Sopenharmony_cistatic void *
4148c2ecf20Sopenharmony_cisnic_trc_seq_start(struct seq_file *sfp, loff_t *pos)
4158c2ecf20Sopenharmony_ci{
4168c2ecf20Sopenharmony_ci	return &snic_glob->trc;
4178c2ecf20Sopenharmony_ci}
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_cistatic void *
4208c2ecf20Sopenharmony_cisnic_trc_seq_next(struct seq_file *sfp, void *data, loff_t *pos)
4218c2ecf20Sopenharmony_ci{
4228c2ecf20Sopenharmony_ci	return NULL;
4238c2ecf20Sopenharmony_ci}
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_cistatic void
4268c2ecf20Sopenharmony_cisnic_trc_seq_stop(struct seq_file *sfp, void *data)
4278c2ecf20Sopenharmony_ci{
4288c2ecf20Sopenharmony_ci}
4298c2ecf20Sopenharmony_ci
4308c2ecf20Sopenharmony_ci#define SNIC_TRC_PBLEN	256
4318c2ecf20Sopenharmony_cistatic int
4328c2ecf20Sopenharmony_cisnic_trc_seq_show(struct seq_file *sfp, void *data)
4338c2ecf20Sopenharmony_ci{
4348c2ecf20Sopenharmony_ci	char buf[SNIC_TRC_PBLEN];
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_ci	if (snic_get_trc_data(buf, SNIC_TRC_PBLEN) > 0)
4378c2ecf20Sopenharmony_ci		seq_printf(sfp, "%s\n", buf);
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_ci	return 0;
4408c2ecf20Sopenharmony_ci}
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_cistatic const struct seq_operations snic_trc_sops = {
4438c2ecf20Sopenharmony_ci	.start	= snic_trc_seq_start,
4448c2ecf20Sopenharmony_ci	.next	= snic_trc_seq_next,
4458c2ecf20Sopenharmony_ci	.stop	= snic_trc_seq_stop,
4468c2ecf20Sopenharmony_ci	.show	= snic_trc_seq_show,
4478c2ecf20Sopenharmony_ci};
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_ciDEFINE_SEQ_ATTRIBUTE(snic_trc);
4508c2ecf20Sopenharmony_ci
4518c2ecf20Sopenharmony_ci/*
4528c2ecf20Sopenharmony_ci * snic_trc_debugfs_init : creates trace/tracing_enable files for trace
4538c2ecf20Sopenharmony_ci * under debugfs
4548c2ecf20Sopenharmony_ci */
4558c2ecf20Sopenharmony_civoid snic_trc_debugfs_init(void)
4568c2ecf20Sopenharmony_ci{
4578c2ecf20Sopenharmony_ci	snic_glob->trc.trc_enable = debugfs_create_bool("tracing_enable",
4588c2ecf20Sopenharmony_ci							S_IFREG | S_IRUGO | S_IWUSR,
4598c2ecf20Sopenharmony_ci							snic_glob->trc_root,
4608c2ecf20Sopenharmony_ci							&snic_glob->trc.enable);
4618c2ecf20Sopenharmony_ci
4628c2ecf20Sopenharmony_ci	snic_glob->trc.trc_file = debugfs_create_file("trace",
4638c2ecf20Sopenharmony_ci						      S_IFREG | S_IRUGO | S_IWUSR,
4648c2ecf20Sopenharmony_ci						      snic_glob->trc_root, NULL,
4658c2ecf20Sopenharmony_ci						      &snic_trc_fops);
4668c2ecf20Sopenharmony_ci}
4678c2ecf20Sopenharmony_ci
4688c2ecf20Sopenharmony_ci/*
4698c2ecf20Sopenharmony_ci * snic_trc_debugfs_term : cleans up the files created for trace under debugfs
4708c2ecf20Sopenharmony_ci */
4718c2ecf20Sopenharmony_civoid
4728c2ecf20Sopenharmony_cisnic_trc_debugfs_term(void)
4738c2ecf20Sopenharmony_ci{
4748c2ecf20Sopenharmony_ci	debugfs_remove(snic_glob->trc.trc_file);
4758c2ecf20Sopenharmony_ci	snic_glob->trc.trc_file = NULL;
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ci	debugfs_remove(snic_glob->trc.trc_enable);
4788c2ecf20Sopenharmony_ci	snic_glob->trc.trc_enable = NULL;
4798c2ecf20Sopenharmony_ci}
480