xref: /openbmc/linux/drivers/scsi/qedf/qedf_debugfs.c (revision ce7e0a84e5d7396acff78faacd2e39906cd8a598)
13287e96aSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
261d8658bSDupuis, Chad /*
361d8658bSDupuis, Chad  *  QLogic FCoE Offload Driver
45d1c8b5bSChad Dupuis  *  Copyright (c) 2016-2018 QLogic Corporation
561d8658bSDupuis, Chad  */
661d8658bSDupuis, Chad #ifdef CONFIG_DEBUG_FS
761d8658bSDupuis, Chad 
861d8658bSDupuis, Chad #include <linux/uaccess.h>
961d8658bSDupuis, Chad #include <linux/debugfs.h>
1061d8658bSDupuis, Chad #include <linux/module.h>
1161d8658bSDupuis, Chad 
1261d8658bSDupuis, Chad #include "qedf.h"
1361d8658bSDupuis, Chad #include "qedf_dbg.h"
1461d8658bSDupuis, Chad 
1561d8658bSDupuis, Chad static struct dentry *qedf_dbg_root;
1661d8658bSDupuis, Chad 
17*ce7e0a84SLee Jones /*
1861d8658bSDupuis, Chad  * qedf_dbg_host_init - setup the debugfs file for the pf
19*ce7e0a84SLee Jones  */
2061d8658bSDupuis, Chad void
2161d8658bSDupuis, Chad qedf_dbg_host_init(struct qedf_dbg_ctx *qedf,
22d9ea463aSArnd Bergmann 		    const struct qedf_debugfs_ops *dops,
23d9ea463aSArnd Bergmann 		    const struct file_operations *fops)
2461d8658bSDupuis, Chad {
2561d8658bSDupuis, Chad 	char host_dirname[32];
2661d8658bSDupuis, Chad 
2761d8658bSDupuis, Chad 	QEDF_INFO(qedf, QEDF_LOG_DEBUGFS, "Creating debugfs host node\n");
2861d8658bSDupuis, Chad 	/* create pf dir */
2961d8658bSDupuis, Chad 	sprintf(host_dirname, "host%u", qedf->host_no);
3061d8658bSDupuis, Chad 	qedf->bdf_dentry = debugfs_create_dir(host_dirname, qedf_dbg_root);
3161d8658bSDupuis, Chad 
3261d8658bSDupuis, Chad 	/* create debugfs files */
3361d8658bSDupuis, Chad 	while (dops) {
3461d8658bSDupuis, Chad 		if (!(dops->name))
3561d8658bSDupuis, Chad 			break;
3661d8658bSDupuis, Chad 
3726febfb3SGreg Kroah-Hartman 		debugfs_create_file(dops->name, 0600, qedf->bdf_dentry, qedf,
3861d8658bSDupuis, Chad 				    fops);
3961d8658bSDupuis, Chad 		dops++;
4061d8658bSDupuis, Chad 		fops++;
4161d8658bSDupuis, Chad 	}
4261d8658bSDupuis, Chad }
4361d8658bSDupuis, Chad 
44*ce7e0a84SLee Jones /*
4561d8658bSDupuis, Chad  * qedf_dbg_host_exit - clear out the pf's debugfs entries
46*ce7e0a84SLee Jones  */
4761d8658bSDupuis, Chad void
48e82e6ff7SSaurav Kashyap qedf_dbg_host_exit(struct qedf_dbg_ctx *qedf_dbg)
4961d8658bSDupuis, Chad {
50e82e6ff7SSaurav Kashyap 	QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "Destroying debugfs host "
5161d8658bSDupuis, Chad 		   "entry\n");
5261d8658bSDupuis, Chad 	/* remove debugfs  entries of this PF */
53e82e6ff7SSaurav Kashyap 	debugfs_remove_recursive(qedf_dbg->bdf_dentry);
54e82e6ff7SSaurav Kashyap 	qedf_dbg->bdf_dentry = NULL;
5561d8658bSDupuis, Chad }
5661d8658bSDupuis, Chad 
57*ce7e0a84SLee Jones /*
5861d8658bSDupuis, Chad  * qedf_dbg_init - start up debugfs for the driver
59*ce7e0a84SLee Jones  */
6061d8658bSDupuis, Chad void
6161d8658bSDupuis, Chad qedf_dbg_init(char *drv_name)
6261d8658bSDupuis, Chad {
6361d8658bSDupuis, Chad 	QEDF_INFO(NULL, QEDF_LOG_DEBUGFS, "Creating debugfs root node\n");
6461d8658bSDupuis, Chad 
6561d8658bSDupuis, Chad 	/* create qed dir in root of debugfs. NULL means debugfs root */
6661d8658bSDupuis, Chad 	qedf_dbg_root = debugfs_create_dir(drv_name, NULL);
6761d8658bSDupuis, Chad }
6861d8658bSDupuis, Chad 
69*ce7e0a84SLee Jones /*
7061d8658bSDupuis, Chad  * qedf_dbg_exit - clean out the driver's debugfs entries
71*ce7e0a84SLee Jones  */
7261d8658bSDupuis, Chad void
7361d8658bSDupuis, Chad qedf_dbg_exit(void)
7461d8658bSDupuis, Chad {
7561d8658bSDupuis, Chad 	QEDF_INFO(NULL, QEDF_LOG_DEBUGFS, "Destroying debugfs root "
7661d8658bSDupuis, Chad 		   "entry\n");
7761d8658bSDupuis, Chad 
7861d8658bSDupuis, Chad 	/* remove qed dir in root of debugfs */
7961d8658bSDupuis, Chad 	debugfs_remove_recursive(qedf_dbg_root);
8061d8658bSDupuis, Chad 	qedf_dbg_root = NULL;
8161d8658bSDupuis, Chad }
8261d8658bSDupuis, Chad 
83d9ea463aSArnd Bergmann const struct qedf_debugfs_ops qedf_debugfs_ops[] = {
8461d8658bSDupuis, Chad 	{ "fp_int", NULL },
8561d8658bSDupuis, Chad 	{ "io_trace", NULL },
8661d8658bSDupuis, Chad 	{ "debug", NULL },
8761d8658bSDupuis, Chad 	{ "stop_io_on_error", NULL},
8861d8658bSDupuis, Chad 	{ "driver_stats", NULL},
8961d8658bSDupuis, Chad 	{ "clear_stats", NULL},
9061d8658bSDupuis, Chad 	{ "offload_stats", NULL},
9161d8658bSDupuis, Chad 	/* This must be last */
9261d8658bSDupuis, Chad 	{ NULL, NULL }
9361d8658bSDupuis, Chad };
9461d8658bSDupuis, Chad 
9561d8658bSDupuis, Chad DECLARE_PER_CPU(struct qedf_percpu_iothread_s, qedf_percpu_iothreads);
9661d8658bSDupuis, Chad 
9761d8658bSDupuis, Chad static ssize_t
9861d8658bSDupuis, Chad qedf_dbg_fp_int_cmd_read(struct file *filp, char __user *buffer, size_t count,
9961d8658bSDupuis, Chad 			 loff_t *ppos)
10061d8658bSDupuis, Chad {
10161d8658bSDupuis, Chad 	size_t cnt = 0;
10261d8658bSDupuis, Chad 	int id;
10361d8658bSDupuis, Chad 	struct qedf_fastpath *fp = NULL;
10461d8658bSDupuis, Chad 	struct qedf_dbg_ctx *qedf_dbg =
10561d8658bSDupuis, Chad 				(struct qedf_dbg_ctx *)filp->private_data;
10661d8658bSDupuis, Chad 	struct qedf_ctx *qedf = container_of(qedf_dbg,
10761d8658bSDupuis, Chad 	    struct qedf_ctx, dbg_ctx);
10861d8658bSDupuis, Chad 
10961d8658bSDupuis, Chad 	QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n");
11061d8658bSDupuis, Chad 
11161d8658bSDupuis, Chad 	cnt = sprintf(buffer, "\nFastpath I/O completions\n\n");
11261d8658bSDupuis, Chad 
11361d8658bSDupuis, Chad 	for (id = 0; id < qedf->num_queues; id++) {
11461d8658bSDupuis, Chad 		fp = &(qedf->fp_array[id]);
11561d8658bSDupuis, Chad 		if (fp->sb_id == QEDF_SB_ID_NULL)
11661d8658bSDupuis, Chad 			continue;
11761d8658bSDupuis, Chad 		cnt += sprintf((buffer + cnt), "#%d: %lu\n", id,
11861d8658bSDupuis, Chad 			       fp->completions);
11961d8658bSDupuis, Chad 	}
12061d8658bSDupuis, Chad 
12161d8658bSDupuis, Chad 	cnt = min_t(int, count, cnt - *ppos);
12261d8658bSDupuis, Chad 	*ppos += cnt;
12361d8658bSDupuis, Chad 	return cnt;
12461d8658bSDupuis, Chad }
12561d8658bSDupuis, Chad 
12661d8658bSDupuis, Chad static ssize_t
12761d8658bSDupuis, Chad qedf_dbg_fp_int_cmd_write(struct file *filp, const char __user *buffer,
12861d8658bSDupuis, Chad 			  size_t count, loff_t *ppos)
12961d8658bSDupuis, Chad {
13061d8658bSDupuis, Chad 	if (!count || *ppos)
13161d8658bSDupuis, Chad 		return 0;
13261d8658bSDupuis, Chad 
13361d8658bSDupuis, Chad 	return count;
13461d8658bSDupuis, Chad }
13561d8658bSDupuis, Chad 
13661d8658bSDupuis, Chad static ssize_t
13761d8658bSDupuis, Chad qedf_dbg_debug_cmd_read(struct file *filp, char __user *buffer, size_t count,
13861d8658bSDupuis, Chad 			loff_t *ppos)
13961d8658bSDupuis, Chad {
14061d8658bSDupuis, Chad 	int cnt;
141e82e6ff7SSaurav Kashyap 	struct qedf_dbg_ctx *qedf_dbg =
14261d8658bSDupuis, Chad 				(struct qedf_dbg_ctx *)filp->private_data;
14361d8658bSDupuis, Chad 
144e82e6ff7SSaurav Kashyap 	QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "debug mask=0x%x\n", qedf_debug);
14561d8658bSDupuis, Chad 	cnt = sprintf(buffer, "debug mask = 0x%x\n", qedf_debug);
14661d8658bSDupuis, Chad 
14761d8658bSDupuis, Chad 	cnt = min_t(int, count, cnt - *ppos);
14861d8658bSDupuis, Chad 	*ppos += cnt;
14961d8658bSDupuis, Chad 	return cnt;
15061d8658bSDupuis, Chad }
15161d8658bSDupuis, Chad 
15261d8658bSDupuis, Chad static ssize_t
15361d8658bSDupuis, Chad qedf_dbg_debug_cmd_write(struct file *filp, const char __user *buffer,
15461d8658bSDupuis, Chad 			 size_t count, loff_t *ppos)
15561d8658bSDupuis, Chad {
15661d8658bSDupuis, Chad 	uint32_t val;
15761d8658bSDupuis, Chad 	void *kern_buf;
15861d8658bSDupuis, Chad 	int rval;
159e82e6ff7SSaurav Kashyap 	struct qedf_dbg_ctx *qedf_dbg =
16061d8658bSDupuis, Chad 	    (struct qedf_dbg_ctx *)filp->private_data;
16161d8658bSDupuis, Chad 
16261d8658bSDupuis, Chad 	if (!count || *ppos)
16361d8658bSDupuis, Chad 		return 0;
16461d8658bSDupuis, Chad 
16561d8658bSDupuis, Chad 	kern_buf = memdup_user(buffer, count);
16661d8658bSDupuis, Chad 	if (IS_ERR(kern_buf))
16761d8658bSDupuis, Chad 		return PTR_ERR(kern_buf);
16861d8658bSDupuis, Chad 
16961d8658bSDupuis, Chad 	rval = kstrtouint(kern_buf, 10, &val);
17061d8658bSDupuis, Chad 	kfree(kern_buf);
17161d8658bSDupuis, Chad 	if (rval)
17261d8658bSDupuis, Chad 		return rval;
17361d8658bSDupuis, Chad 
17461d8658bSDupuis, Chad 	if (val == 1)
17561d8658bSDupuis, Chad 		qedf_debug = QEDF_DEFAULT_LOG_MASK;
17661d8658bSDupuis, Chad 	else
17761d8658bSDupuis, Chad 		qedf_debug = val;
17861d8658bSDupuis, Chad 
179e82e6ff7SSaurav Kashyap 	QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "Setting debug=0x%x.\n", val);
18061d8658bSDupuis, Chad 	return count;
18161d8658bSDupuis, Chad }
18261d8658bSDupuis, Chad 
18361d8658bSDupuis, Chad static ssize_t
18461d8658bSDupuis, Chad qedf_dbg_stop_io_on_error_cmd_read(struct file *filp, char __user *buffer,
18561d8658bSDupuis, Chad 				   size_t count, loff_t *ppos)
18661d8658bSDupuis, Chad {
18761d8658bSDupuis, Chad 	int cnt;
18861d8658bSDupuis, Chad 	struct qedf_dbg_ctx *qedf_dbg =
18961d8658bSDupuis, Chad 				(struct qedf_dbg_ctx *)filp->private_data;
19061d8658bSDupuis, Chad 	struct qedf_ctx *qedf = container_of(qedf_dbg,
19161d8658bSDupuis, Chad 	    struct qedf_ctx, dbg_ctx);
19261d8658bSDupuis, Chad 
19361d8658bSDupuis, Chad 	QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n");
19461d8658bSDupuis, Chad 	cnt = sprintf(buffer, "%s\n",
19561d8658bSDupuis, Chad 	    qedf->stop_io_on_error ? "true" : "false");
19661d8658bSDupuis, Chad 
19761d8658bSDupuis, Chad 	cnt = min_t(int, count, cnt - *ppos);
19861d8658bSDupuis, Chad 	*ppos += cnt;
19961d8658bSDupuis, Chad 	return cnt;
20061d8658bSDupuis, Chad }
20161d8658bSDupuis, Chad 
20261d8658bSDupuis, Chad static ssize_t
20361d8658bSDupuis, Chad qedf_dbg_stop_io_on_error_cmd_write(struct file *filp,
20461d8658bSDupuis, Chad 				    const char __user *buffer, size_t count,
20561d8658bSDupuis, Chad 				    loff_t *ppos)
20661d8658bSDupuis, Chad {
20761d8658bSDupuis, Chad 	void *kern_buf;
20861d8658bSDupuis, Chad 	struct qedf_dbg_ctx *qedf_dbg =
20961d8658bSDupuis, Chad 				(struct qedf_dbg_ctx *)filp->private_data;
21061d8658bSDupuis, Chad 	struct qedf_ctx *qedf = container_of(qedf_dbg, struct qedf_ctx,
21161d8658bSDupuis, Chad 	    dbg_ctx);
21261d8658bSDupuis, Chad 
21361d8658bSDupuis, Chad 	QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n");
21461d8658bSDupuis, Chad 
21561d8658bSDupuis, Chad 	if (!count || *ppos)
21661d8658bSDupuis, Chad 		return 0;
21761d8658bSDupuis, Chad 
21861d8658bSDupuis, Chad 	kern_buf = memdup_user(buffer, 6);
21961d8658bSDupuis, Chad 	if (IS_ERR(kern_buf))
22061d8658bSDupuis, Chad 		return PTR_ERR(kern_buf);
22161d8658bSDupuis, Chad 
22261d8658bSDupuis, Chad 	if (strncmp(kern_buf, "false", 5) == 0)
22361d8658bSDupuis, Chad 		qedf->stop_io_on_error = false;
22461d8658bSDupuis, Chad 	else if (strncmp(kern_buf, "true", 4) == 0)
22561d8658bSDupuis, Chad 		qedf->stop_io_on_error = true;
22661d8658bSDupuis, Chad 	else if (strncmp(kern_buf, "now", 3) == 0)
22761d8658bSDupuis, Chad 		/* Trigger from user to stop all I/O on this host */
22861d8658bSDupuis, Chad 		set_bit(QEDF_DBG_STOP_IO, &qedf->flags);
22961d8658bSDupuis, Chad 
23061d8658bSDupuis, Chad 	kfree(kern_buf);
23161d8658bSDupuis, Chad 	return count;
23261d8658bSDupuis, Chad }
23361d8658bSDupuis, Chad 
23461d8658bSDupuis, Chad static int
23561d8658bSDupuis, Chad qedf_io_trace_show(struct seq_file *s, void *unused)
23661d8658bSDupuis, Chad {
23761d8658bSDupuis, Chad 	int i, idx = 0;
23861d8658bSDupuis, Chad 	struct qedf_ctx *qedf = s->private;
23961d8658bSDupuis, Chad 	struct qedf_dbg_ctx *qedf_dbg = &qedf->dbg_ctx;
24061d8658bSDupuis, Chad 	struct qedf_io_log *io_log;
24161d8658bSDupuis, Chad 	unsigned long flags;
24261d8658bSDupuis, Chad 
24361d8658bSDupuis, Chad 	if (!qedf_io_tracing) {
24461d8658bSDupuis, Chad 		seq_puts(s, "I/O tracing not enabled.\n");
24561d8658bSDupuis, Chad 		goto out;
24661d8658bSDupuis, Chad 	}
24761d8658bSDupuis, Chad 
24861d8658bSDupuis, Chad 	QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n");
24961d8658bSDupuis, Chad 
25061d8658bSDupuis, Chad 	spin_lock_irqsave(&qedf->io_trace_lock, flags);
25161d8658bSDupuis, Chad 	idx = qedf->io_trace_idx;
25261d8658bSDupuis, Chad 	for (i = 0; i < QEDF_IO_TRACE_SIZE; i++) {
25361d8658bSDupuis, Chad 		io_log = &qedf->io_trace_buf[idx];
25461d8658bSDupuis, Chad 		seq_printf(s, "%d:", io_log->direction);
25561d8658bSDupuis, Chad 		seq_printf(s, "0x%x:", io_log->task_id);
25661d8658bSDupuis, Chad 		seq_printf(s, "0x%06x:", io_log->port_id);
25761d8658bSDupuis, Chad 		seq_printf(s, "%d:", io_log->lun);
25861d8658bSDupuis, Chad 		seq_printf(s, "0x%02x:", io_log->op);
25961d8658bSDupuis, Chad 		seq_printf(s, "0x%02x%02x%02x%02x:", io_log->lba[0],
26061d8658bSDupuis, Chad 		    io_log->lba[1], io_log->lba[2], io_log->lba[3]);
26161d8658bSDupuis, Chad 		seq_printf(s, "%d:", io_log->bufflen);
26261d8658bSDupuis, Chad 		seq_printf(s, "%d:", io_log->sg_count);
26361d8658bSDupuis, Chad 		seq_printf(s, "0x%08x:", io_log->result);
26461d8658bSDupuis, Chad 		seq_printf(s, "%lu:", io_log->jiffies);
26561d8658bSDupuis, Chad 		seq_printf(s, "%d:", io_log->refcount);
26661d8658bSDupuis, Chad 		seq_printf(s, "%d:", io_log->req_cpu);
26761d8658bSDupuis, Chad 		seq_printf(s, "%d:", io_log->int_cpu);
26861d8658bSDupuis, Chad 		seq_printf(s, "%d:", io_log->rsp_cpu);
26961d8658bSDupuis, Chad 		seq_printf(s, "%d\n", io_log->sge_type);
27061d8658bSDupuis, Chad 
27161d8658bSDupuis, Chad 		idx++;
27261d8658bSDupuis, Chad 		if (idx == QEDF_IO_TRACE_SIZE)
27361d8658bSDupuis, Chad 			idx = 0;
27461d8658bSDupuis, Chad 	}
27561d8658bSDupuis, Chad 	spin_unlock_irqrestore(&qedf->io_trace_lock, flags);
27661d8658bSDupuis, Chad 
27761d8658bSDupuis, Chad out:
27861d8658bSDupuis, Chad 	return 0;
27961d8658bSDupuis, Chad }
28061d8658bSDupuis, Chad 
28161d8658bSDupuis, Chad static int
28261d8658bSDupuis, Chad qedf_dbg_io_trace_open(struct inode *inode, struct file *file)
28361d8658bSDupuis, Chad {
28461d8658bSDupuis, Chad 	struct qedf_dbg_ctx *qedf_dbg = inode->i_private;
28561d8658bSDupuis, Chad 	struct qedf_ctx *qedf = container_of(qedf_dbg,
28661d8658bSDupuis, Chad 	    struct qedf_ctx, dbg_ctx);
28761d8658bSDupuis, Chad 
28861d8658bSDupuis, Chad 	return single_open(file, qedf_io_trace_show, qedf);
28961d8658bSDupuis, Chad }
29061d8658bSDupuis, Chad 
291892f63d4SChad Dupuis /* Based on fip_state enum from libfcoe.h */
292892f63d4SChad Dupuis static char *fip_state_names[] = {
293892f63d4SChad Dupuis 	"FIP_ST_DISABLED",
294892f63d4SChad Dupuis 	"FIP_ST_LINK_WAIT",
295892f63d4SChad Dupuis 	"FIP_ST_AUTO",
296892f63d4SChad Dupuis 	"FIP_ST_NON_FIP",
297892f63d4SChad Dupuis 	"FIP_ST_ENABLED",
298892f63d4SChad Dupuis 	"FIP_ST_VNMP_START",
299892f63d4SChad Dupuis 	"FIP_ST_VNMP_PROBE1",
300892f63d4SChad Dupuis 	"FIP_ST_VNMP_PROBE2",
301892f63d4SChad Dupuis 	"FIP_ST_VNMP_CLAIM",
302892f63d4SChad Dupuis 	"FIP_ST_VNMP_UP",
303892f63d4SChad Dupuis };
304892f63d4SChad Dupuis 
305892f63d4SChad Dupuis /* Based on fc_rport_state enum from libfc.h */
306892f63d4SChad Dupuis static char *fc_rport_state_names[] = {
307892f63d4SChad Dupuis 	"RPORT_ST_INIT",
308892f63d4SChad Dupuis 	"RPORT_ST_FLOGI",
309892f63d4SChad Dupuis 	"RPORT_ST_PLOGI_WAIT",
310892f63d4SChad Dupuis 	"RPORT_ST_PLOGI",
311892f63d4SChad Dupuis 	"RPORT_ST_PRLI",
312892f63d4SChad Dupuis 	"RPORT_ST_RTV",
313892f63d4SChad Dupuis 	"RPORT_ST_READY",
314892f63d4SChad Dupuis 	"RPORT_ST_ADISC",
315892f63d4SChad Dupuis 	"RPORT_ST_DELETE",
316892f63d4SChad Dupuis };
317892f63d4SChad Dupuis 
31861d8658bSDupuis, Chad static int
31961d8658bSDupuis, Chad qedf_driver_stats_show(struct seq_file *s, void *unused)
32061d8658bSDupuis, Chad {
32161d8658bSDupuis, Chad 	struct qedf_ctx *qedf = s->private;
32261d8658bSDupuis, Chad 	struct qedf_rport *fcport;
32361d8658bSDupuis, Chad 	struct fc_rport_priv *rdata;
32461d8658bSDupuis, Chad 
325892f63d4SChad Dupuis 	seq_printf(s, "Host WWNN/WWPN: %016llx/%016llx\n",
326892f63d4SChad Dupuis 		   qedf->wwnn, qedf->wwpn);
327892f63d4SChad Dupuis 	seq_printf(s, "Host NPortID: %06x\n", qedf->lport->port_id);
328892f63d4SChad Dupuis 	seq_printf(s, "Link State: %s\n", atomic_read(&qedf->link_state) ?
329892f63d4SChad Dupuis 	    "Up" : "Down");
330892f63d4SChad Dupuis 	seq_printf(s, "Logical Link State: %s\n", qedf->lport->link_up ?
331892f63d4SChad Dupuis 	    "Up" : "Down");
332892f63d4SChad Dupuis 	seq_printf(s, "FIP state: %s\n", fip_state_names[qedf->ctlr.state]);
333892f63d4SChad Dupuis 	seq_printf(s, "FIP VLAN ID: %d\n", qedf->vlan_id & 0xfff);
334892f63d4SChad Dupuis 	seq_printf(s, "FIP 802.1Q Priority: %d\n", qedf->prio);
335892f63d4SChad Dupuis 	if (qedf->ctlr.sel_fcf) {
336892f63d4SChad Dupuis 		seq_printf(s, "FCF WWPN: %016llx\n",
337892f63d4SChad Dupuis 			   qedf->ctlr.sel_fcf->switch_name);
338892f63d4SChad Dupuis 		seq_printf(s, "FCF MAC: %pM\n", qedf->ctlr.sel_fcf->fcf_mac);
339892f63d4SChad Dupuis 	} else {
340892f63d4SChad Dupuis 		seq_puts(s, "FCF not selected\n");
341892f63d4SChad Dupuis 	}
342892f63d4SChad Dupuis 
343892f63d4SChad Dupuis 	seq_puts(s, "\nSGE stats:\n\n");
34461d8658bSDupuis, Chad 	seq_printf(s, "cmg_mgr free io_reqs: %d\n",
34561d8658bSDupuis, Chad 	    atomic_read(&qedf->cmd_mgr->free_list_cnt));
34661d8658bSDupuis, Chad 	seq_printf(s, "slow SGEs: %d\n", qedf->slow_sge_ios);
34761d8658bSDupuis, Chad 	seq_printf(s, "fast SGEs: %d\n\n", qedf->fast_sge_ios);
34861d8658bSDupuis, Chad 
34961d8658bSDupuis, Chad 	seq_puts(s, "Offloaded ports:\n\n");
35061d8658bSDupuis, Chad 
35161d8658bSDupuis, Chad 	rcu_read_lock();
35261d8658bSDupuis, Chad 	list_for_each_entry_rcu(fcport, &qedf->fcports, peers) {
35361d8658bSDupuis, Chad 		rdata = fcport->rdata;
35461d8658bSDupuis, Chad 		if (rdata == NULL)
35561d8658bSDupuis, Chad 			continue;
356892f63d4SChad Dupuis 		seq_printf(s, "%016llx/%016llx/%06x: state=%s, free_sqes=%d, num_active_ios=%d\n",
357892f63d4SChad Dupuis 			   rdata->rport->node_name, rdata->rport->port_name,
358892f63d4SChad Dupuis 			   rdata->ids.port_id,
359892f63d4SChad Dupuis 			   fc_rport_state_names[rdata->rp_state],
360892f63d4SChad Dupuis 			   atomic_read(&fcport->free_sqes),
36161d8658bSDupuis, Chad 			   atomic_read(&fcport->num_active_ios));
36261d8658bSDupuis, Chad 	}
36361d8658bSDupuis, Chad 	rcu_read_unlock();
36461d8658bSDupuis, Chad 
36561d8658bSDupuis, Chad 	return 0;
36661d8658bSDupuis, Chad }
36761d8658bSDupuis, Chad 
36861d8658bSDupuis, Chad static int
36961d8658bSDupuis, Chad qedf_dbg_driver_stats_open(struct inode *inode, struct file *file)
37061d8658bSDupuis, Chad {
37161d8658bSDupuis, Chad 	struct qedf_dbg_ctx *qedf_dbg = inode->i_private;
37261d8658bSDupuis, Chad 	struct qedf_ctx *qedf = container_of(qedf_dbg,
37361d8658bSDupuis, Chad 	    struct qedf_ctx, dbg_ctx);
37461d8658bSDupuis, Chad 
37561d8658bSDupuis, Chad 	return single_open(file, qedf_driver_stats_show, qedf);
37661d8658bSDupuis, Chad }
37761d8658bSDupuis, Chad 
37861d8658bSDupuis, Chad static ssize_t
37961d8658bSDupuis, Chad qedf_dbg_clear_stats_cmd_read(struct file *filp, char __user *buffer,
38061d8658bSDupuis, Chad 				   size_t count, loff_t *ppos)
38161d8658bSDupuis, Chad {
38261d8658bSDupuis, Chad 	int cnt = 0;
38361d8658bSDupuis, Chad 
38461d8658bSDupuis, Chad 	/* Essentially a read stub */
38561d8658bSDupuis, Chad 	cnt = min_t(int, count, cnt - *ppos);
38661d8658bSDupuis, Chad 	*ppos += cnt;
38761d8658bSDupuis, Chad 	return cnt;
38861d8658bSDupuis, Chad }
38961d8658bSDupuis, Chad 
39061d8658bSDupuis, Chad static ssize_t
39161d8658bSDupuis, Chad qedf_dbg_clear_stats_cmd_write(struct file *filp,
39261d8658bSDupuis, Chad 				    const char __user *buffer, size_t count,
39361d8658bSDupuis, Chad 				    loff_t *ppos)
39461d8658bSDupuis, Chad {
39561d8658bSDupuis, Chad 	struct qedf_dbg_ctx *qedf_dbg =
39661d8658bSDupuis, Chad 				(struct qedf_dbg_ctx *)filp->private_data;
39761d8658bSDupuis, Chad 	struct qedf_ctx *qedf = container_of(qedf_dbg, struct qedf_ctx,
39861d8658bSDupuis, Chad 	    dbg_ctx);
39961d8658bSDupuis, Chad 
40061d8658bSDupuis, Chad 	QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "Clearing stat counters.\n");
40161d8658bSDupuis, Chad 
40261d8658bSDupuis, Chad 	if (!count || *ppos)
40361d8658bSDupuis, Chad 		return 0;
40461d8658bSDupuis, Chad 
40561d8658bSDupuis, Chad 	/* Clear stat counters exposed by 'stats' node */
40661d8658bSDupuis, Chad 	qedf->slow_sge_ios = 0;
40761d8658bSDupuis, Chad 	qedf->fast_sge_ios = 0;
40861d8658bSDupuis, Chad 
40961d8658bSDupuis, Chad 	return count;
41061d8658bSDupuis, Chad }
41161d8658bSDupuis, Chad 
41261d8658bSDupuis, Chad static int
41361d8658bSDupuis, Chad qedf_offload_stats_show(struct seq_file *s, void *unused)
41461d8658bSDupuis, Chad {
41561d8658bSDupuis, Chad 	struct qedf_ctx *qedf = s->private;
41661d8658bSDupuis, Chad 	struct qed_fcoe_stats *fw_fcoe_stats;
41761d8658bSDupuis, Chad 
41861d8658bSDupuis, Chad 	fw_fcoe_stats = kmalloc(sizeof(struct qed_fcoe_stats), GFP_KERNEL);
41961d8658bSDupuis, Chad 	if (!fw_fcoe_stats) {
42061d8658bSDupuis, Chad 		QEDF_ERR(&(qedf->dbg_ctx), "Could not allocate memory for "
42161d8658bSDupuis, Chad 		    "fw_fcoe_stats.\n");
42261d8658bSDupuis, Chad 		goto out;
42361d8658bSDupuis, Chad 	}
42461d8658bSDupuis, Chad 
42561d8658bSDupuis, Chad 	/* Query firmware for offload stats */
42661d8658bSDupuis, Chad 	qed_ops->get_stats(qedf->cdev, fw_fcoe_stats);
42761d8658bSDupuis, Chad 
42861d8658bSDupuis, Chad 	seq_printf(s, "fcoe_rx_byte_cnt=%llu\n"
42961d8658bSDupuis, Chad 	    "fcoe_rx_data_pkt_cnt=%llu\n"
43061d8658bSDupuis, Chad 	    "fcoe_rx_xfer_pkt_cnt=%llu\n"
43161d8658bSDupuis, Chad 	    "fcoe_rx_other_pkt_cnt=%llu\n"
43261d8658bSDupuis, Chad 	    "fcoe_silent_drop_pkt_cmdq_full_cnt=%u\n"
43361d8658bSDupuis, Chad 	    "fcoe_silent_drop_pkt_crc_error_cnt=%u\n"
43461d8658bSDupuis, Chad 	    "fcoe_silent_drop_pkt_task_invalid_cnt=%u\n"
43561d8658bSDupuis, Chad 	    "fcoe_silent_drop_total_pkt_cnt=%u\n"
43661d8658bSDupuis, Chad 	    "fcoe_silent_drop_pkt_rq_full_cnt=%u\n"
43761d8658bSDupuis, Chad 	    "fcoe_tx_byte_cnt=%llu\n"
43861d8658bSDupuis, Chad 	    "fcoe_tx_data_pkt_cnt=%llu\n"
43961d8658bSDupuis, Chad 	    "fcoe_tx_xfer_pkt_cnt=%llu\n"
44061d8658bSDupuis, Chad 	    "fcoe_tx_other_pkt_cnt=%llu\n",
44161d8658bSDupuis, Chad 	    fw_fcoe_stats->fcoe_rx_byte_cnt,
44261d8658bSDupuis, Chad 	    fw_fcoe_stats->fcoe_rx_data_pkt_cnt,
44361d8658bSDupuis, Chad 	    fw_fcoe_stats->fcoe_rx_xfer_pkt_cnt,
44461d8658bSDupuis, Chad 	    fw_fcoe_stats->fcoe_rx_other_pkt_cnt,
44561d8658bSDupuis, Chad 	    fw_fcoe_stats->fcoe_silent_drop_pkt_cmdq_full_cnt,
44661d8658bSDupuis, Chad 	    fw_fcoe_stats->fcoe_silent_drop_pkt_crc_error_cnt,
44761d8658bSDupuis, Chad 	    fw_fcoe_stats->fcoe_silent_drop_pkt_task_invalid_cnt,
44861d8658bSDupuis, Chad 	    fw_fcoe_stats->fcoe_silent_drop_total_pkt_cnt,
44961d8658bSDupuis, Chad 	    fw_fcoe_stats->fcoe_silent_drop_pkt_rq_full_cnt,
45061d8658bSDupuis, Chad 	    fw_fcoe_stats->fcoe_tx_byte_cnt,
45161d8658bSDupuis, Chad 	    fw_fcoe_stats->fcoe_tx_data_pkt_cnt,
45261d8658bSDupuis, Chad 	    fw_fcoe_stats->fcoe_tx_xfer_pkt_cnt,
45361d8658bSDupuis, Chad 	    fw_fcoe_stats->fcoe_tx_other_pkt_cnt);
45461d8658bSDupuis, Chad 
45561d8658bSDupuis, Chad 	kfree(fw_fcoe_stats);
45661d8658bSDupuis, Chad out:
45761d8658bSDupuis, Chad 	return 0;
45861d8658bSDupuis, Chad }
45961d8658bSDupuis, Chad 
46061d8658bSDupuis, Chad static int
46161d8658bSDupuis, Chad qedf_dbg_offload_stats_open(struct inode *inode, struct file *file)
46261d8658bSDupuis, Chad {
46361d8658bSDupuis, Chad 	struct qedf_dbg_ctx *qedf_dbg = inode->i_private;
46461d8658bSDupuis, Chad 	struct qedf_ctx *qedf = container_of(qedf_dbg,
46561d8658bSDupuis, Chad 	    struct qedf_ctx, dbg_ctx);
46661d8658bSDupuis, Chad 
46761d8658bSDupuis, Chad 	return single_open(file, qedf_offload_stats_show, qedf);
46861d8658bSDupuis, Chad }
46961d8658bSDupuis, Chad 
47061d8658bSDupuis, Chad const struct file_operations qedf_dbg_fops[] = {
47161d8658bSDupuis, Chad 	qedf_dbg_fileops(qedf, fp_int),
47261d8658bSDupuis, Chad 	qedf_dbg_fileops_seq(qedf, io_trace),
47361d8658bSDupuis, Chad 	qedf_dbg_fileops(qedf, debug),
47461d8658bSDupuis, Chad 	qedf_dbg_fileops(qedf, stop_io_on_error),
47561d8658bSDupuis, Chad 	qedf_dbg_fileops_seq(qedf, driver_stats),
47661d8658bSDupuis, Chad 	qedf_dbg_fileops(qedf, clear_stats),
47761d8658bSDupuis, Chad 	qedf_dbg_fileops_seq(qedf, offload_stats),
47861d8658bSDupuis, Chad 	/* This must be last */
479efacae6dSKees Cook 	{ },
48061d8658bSDupuis, Chad };
48161d8658bSDupuis, Chad 
48261d8658bSDupuis, Chad #else /* CONFIG_DEBUG_FS */
48361d8658bSDupuis, Chad void qedf_dbg_host_init(struct qedf_dbg_ctx *);
48461d8658bSDupuis, Chad void qedf_dbg_host_exit(struct qedf_dbg_ctx *);
48561d8658bSDupuis, Chad void qedf_dbg_init(char *);
48661d8658bSDupuis, Chad void qedf_dbg_exit(void);
48761d8658bSDupuis, Chad #endif /* CONFIG_DEBUG_FS */
488