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