xref: /OK3568_Linux_fs/kernel/drivers/scsi/qla2xxx/qla_dfs.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * QLogic Fibre Channel HBA Driver
4*4882a593Smuzhiyun  * Copyright (c)  2003-2014 QLogic Corporation
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun #include "qla_def.h"
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #include <linux/debugfs.h>
9*4882a593Smuzhiyun #include <linux/seq_file.h>
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun static struct dentry *qla2x00_dfs_root;
12*4882a593Smuzhiyun static atomic_t qla2x00_dfs_root_count;
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun #define QLA_DFS_RPORT_DEVLOSS_TMO	1
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun static int
qla_dfs_rport_get(struct fc_port * fp,int attr_id,u64 * val)17*4882a593Smuzhiyun qla_dfs_rport_get(struct fc_port *fp, int attr_id, u64 *val)
18*4882a593Smuzhiyun {
19*4882a593Smuzhiyun 	switch (attr_id) {
20*4882a593Smuzhiyun 	case QLA_DFS_RPORT_DEVLOSS_TMO:
21*4882a593Smuzhiyun 		/* Only supported for FC-NVMe devices that are registered. */
22*4882a593Smuzhiyun 		if (!(fp->nvme_flag & NVME_FLAG_REGISTERED))
23*4882a593Smuzhiyun 			return -EIO;
24*4882a593Smuzhiyun 		*val = fp->nvme_remote_port->dev_loss_tmo;
25*4882a593Smuzhiyun 		break;
26*4882a593Smuzhiyun 	default:
27*4882a593Smuzhiyun 		return -EINVAL;
28*4882a593Smuzhiyun 	}
29*4882a593Smuzhiyun 	return 0;
30*4882a593Smuzhiyun }
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun static int
qla_dfs_rport_set(struct fc_port * fp,int attr_id,u64 val)33*4882a593Smuzhiyun qla_dfs_rport_set(struct fc_port *fp, int attr_id, u64 val)
34*4882a593Smuzhiyun {
35*4882a593Smuzhiyun 	switch (attr_id) {
36*4882a593Smuzhiyun 	case QLA_DFS_RPORT_DEVLOSS_TMO:
37*4882a593Smuzhiyun 		/* Only supported for FC-NVMe devices that are registered. */
38*4882a593Smuzhiyun 		if (!(fp->nvme_flag & NVME_FLAG_REGISTERED))
39*4882a593Smuzhiyun 			return -EIO;
40*4882a593Smuzhiyun #if (IS_ENABLED(CONFIG_NVME_FC))
41*4882a593Smuzhiyun 		return nvme_fc_set_remoteport_devloss(fp->nvme_remote_port,
42*4882a593Smuzhiyun 						      val);
43*4882a593Smuzhiyun #else /* CONFIG_NVME_FC */
44*4882a593Smuzhiyun 		return -EINVAL;
45*4882a593Smuzhiyun #endif /* CONFIG_NVME_FC */
46*4882a593Smuzhiyun 	default:
47*4882a593Smuzhiyun 		return -EINVAL;
48*4882a593Smuzhiyun 	}
49*4882a593Smuzhiyun 	return 0;
50*4882a593Smuzhiyun }
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun #define DEFINE_QLA_DFS_RPORT_RW_ATTR(_attr_id, _attr)		\
53*4882a593Smuzhiyun static int qla_dfs_rport_##_attr##_get(void *data, u64 *val)	\
54*4882a593Smuzhiyun {								\
55*4882a593Smuzhiyun 	struct fc_port *fp = data;				\
56*4882a593Smuzhiyun 	return qla_dfs_rport_get(fp, _attr_id, val);		\
57*4882a593Smuzhiyun }								\
58*4882a593Smuzhiyun static int qla_dfs_rport_##_attr##_set(void *data, u64 val)	\
59*4882a593Smuzhiyun {								\
60*4882a593Smuzhiyun 	struct fc_port *fp = data;				\
61*4882a593Smuzhiyun 	return qla_dfs_rport_set(fp, _attr_id, val);		\
62*4882a593Smuzhiyun }								\
63*4882a593Smuzhiyun DEFINE_DEBUGFS_ATTRIBUTE(qla_dfs_rport_##_attr##_fops,		\
64*4882a593Smuzhiyun 		qla_dfs_rport_##_attr##_get,			\
65*4882a593Smuzhiyun 		qla_dfs_rport_##_attr##_set, "%llu\n")
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun /*
68*4882a593Smuzhiyun  * Wrapper for getting fc_port fields.
69*4882a593Smuzhiyun  *
70*4882a593Smuzhiyun  * _attr    : Attribute name.
71*4882a593Smuzhiyun  * _get_val : Accessor macro to retrieve the value.
72*4882a593Smuzhiyun  */
73*4882a593Smuzhiyun #define DEFINE_QLA_DFS_RPORT_FIELD_GET(_attr, _get_val)			\
74*4882a593Smuzhiyun static int qla_dfs_rport_field_##_attr##_get(void *data, u64 *val)	\
75*4882a593Smuzhiyun {									\
76*4882a593Smuzhiyun 	struct fc_port *fp = data;					\
77*4882a593Smuzhiyun 	*val = _get_val;						\
78*4882a593Smuzhiyun 	return 0;							\
79*4882a593Smuzhiyun }									\
80*4882a593Smuzhiyun DEFINE_DEBUGFS_ATTRIBUTE(qla_dfs_rport_field_##_attr##_fops,		\
81*4882a593Smuzhiyun 		qla_dfs_rport_field_##_attr##_get,			\
82*4882a593Smuzhiyun 		NULL, "%llu\n")
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun #define DEFINE_QLA_DFS_RPORT_ACCESS(_attr, _get_val) \
85*4882a593Smuzhiyun 	DEFINE_QLA_DFS_RPORT_FIELD_GET(_attr, _get_val)
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun #define DEFINE_QLA_DFS_RPORT_FIELD(_attr) \
88*4882a593Smuzhiyun 	DEFINE_QLA_DFS_RPORT_FIELD_GET(_attr, fp->_attr)
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun DEFINE_QLA_DFS_RPORT_RW_ATTR(QLA_DFS_RPORT_DEVLOSS_TMO, dev_loss_tmo);
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun DEFINE_QLA_DFS_RPORT_FIELD(disc_state);
93*4882a593Smuzhiyun DEFINE_QLA_DFS_RPORT_FIELD(scan_state);
94*4882a593Smuzhiyun DEFINE_QLA_DFS_RPORT_FIELD(fw_login_state);
95*4882a593Smuzhiyun DEFINE_QLA_DFS_RPORT_FIELD(login_pause);
96*4882a593Smuzhiyun DEFINE_QLA_DFS_RPORT_FIELD(flags);
97*4882a593Smuzhiyun DEFINE_QLA_DFS_RPORT_FIELD(nvme_flag);
98*4882a593Smuzhiyun DEFINE_QLA_DFS_RPORT_FIELD(last_rscn_gen);
99*4882a593Smuzhiyun DEFINE_QLA_DFS_RPORT_FIELD(rscn_gen);
100*4882a593Smuzhiyun DEFINE_QLA_DFS_RPORT_FIELD(login_gen);
101*4882a593Smuzhiyun DEFINE_QLA_DFS_RPORT_FIELD(loop_id);
102*4882a593Smuzhiyun DEFINE_QLA_DFS_RPORT_FIELD_GET(port_id, fp->d_id.b24);
103*4882a593Smuzhiyun DEFINE_QLA_DFS_RPORT_FIELD_GET(sess_kref, kref_read(&fp->sess_kref));
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun void
qla2x00_dfs_create_rport(scsi_qla_host_t * vha,struct fc_port * fp)106*4882a593Smuzhiyun qla2x00_dfs_create_rport(scsi_qla_host_t *vha, struct fc_port *fp)
107*4882a593Smuzhiyun {
108*4882a593Smuzhiyun 	char wwn[32];
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun #define QLA_CREATE_RPORT_FIELD_ATTR(_attr)			\
111*4882a593Smuzhiyun 	debugfs_create_file(#_attr, 0400, fp->dfs_rport_dir,	\
112*4882a593Smuzhiyun 		fp, &qla_dfs_rport_field_##_attr##_fops)
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun 	if (!vha->dfs_rport_root || fp->dfs_rport_dir)
115*4882a593Smuzhiyun 		return;
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun 	sprintf(wwn, "pn-%016llx", wwn_to_u64(fp->port_name));
118*4882a593Smuzhiyun 	fp->dfs_rport_dir = debugfs_create_dir(wwn, vha->dfs_rport_root);
119*4882a593Smuzhiyun 	if (!fp->dfs_rport_dir)
120*4882a593Smuzhiyun 		return;
121*4882a593Smuzhiyun 	if (NVME_TARGET(vha->hw, fp))
122*4882a593Smuzhiyun 		debugfs_create_file("dev_loss_tmo", 0600, fp->dfs_rport_dir,
123*4882a593Smuzhiyun 				    fp, &qla_dfs_rport_dev_loss_tmo_fops);
124*4882a593Smuzhiyun 
125*4882a593Smuzhiyun 	QLA_CREATE_RPORT_FIELD_ATTR(disc_state);
126*4882a593Smuzhiyun 	QLA_CREATE_RPORT_FIELD_ATTR(scan_state);
127*4882a593Smuzhiyun 	QLA_CREATE_RPORT_FIELD_ATTR(fw_login_state);
128*4882a593Smuzhiyun 	QLA_CREATE_RPORT_FIELD_ATTR(login_pause);
129*4882a593Smuzhiyun 	QLA_CREATE_RPORT_FIELD_ATTR(flags);
130*4882a593Smuzhiyun 	QLA_CREATE_RPORT_FIELD_ATTR(nvme_flag);
131*4882a593Smuzhiyun 	QLA_CREATE_RPORT_FIELD_ATTR(last_rscn_gen);
132*4882a593Smuzhiyun 	QLA_CREATE_RPORT_FIELD_ATTR(rscn_gen);
133*4882a593Smuzhiyun 	QLA_CREATE_RPORT_FIELD_ATTR(login_gen);
134*4882a593Smuzhiyun 	QLA_CREATE_RPORT_FIELD_ATTR(loop_id);
135*4882a593Smuzhiyun 	QLA_CREATE_RPORT_FIELD_ATTR(port_id);
136*4882a593Smuzhiyun 	QLA_CREATE_RPORT_FIELD_ATTR(sess_kref);
137*4882a593Smuzhiyun }
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun void
qla2x00_dfs_remove_rport(scsi_qla_host_t * vha,struct fc_port * fp)140*4882a593Smuzhiyun qla2x00_dfs_remove_rport(scsi_qla_host_t *vha, struct fc_port *fp)
141*4882a593Smuzhiyun {
142*4882a593Smuzhiyun 	if (!vha->dfs_rport_root || !fp->dfs_rport_dir)
143*4882a593Smuzhiyun 		return;
144*4882a593Smuzhiyun 	debugfs_remove_recursive(fp->dfs_rport_dir);
145*4882a593Smuzhiyun 	fp->dfs_rport_dir = NULL;
146*4882a593Smuzhiyun }
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun static int
qla2x00_dfs_tgt_sess_show(struct seq_file * s,void * unused)149*4882a593Smuzhiyun qla2x00_dfs_tgt_sess_show(struct seq_file *s, void *unused)
150*4882a593Smuzhiyun {
151*4882a593Smuzhiyun 	scsi_qla_host_t *vha = s->private;
152*4882a593Smuzhiyun 	struct qla_hw_data *ha = vha->hw;
153*4882a593Smuzhiyun 	unsigned long flags;
154*4882a593Smuzhiyun 	struct fc_port *sess = NULL;
155*4882a593Smuzhiyun 	struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun 	seq_printf(s, "%s\n", vha->host_str);
158*4882a593Smuzhiyun 	if (tgt) {
159*4882a593Smuzhiyun 		seq_puts(s, "Port ID   Port Name                Handle\n");
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun 		spin_lock_irqsave(&ha->tgt.sess_lock, flags);
162*4882a593Smuzhiyun 		list_for_each_entry(sess, &vha->vp_fcports, list)
163*4882a593Smuzhiyun 			seq_printf(s, "%02x:%02x:%02x  %8phC  %d\n",
164*4882a593Smuzhiyun 			    sess->d_id.b.domain, sess->d_id.b.area,
165*4882a593Smuzhiyun 			    sess->d_id.b.al_pa, sess->port_name,
166*4882a593Smuzhiyun 			    sess->loop_id);
167*4882a593Smuzhiyun 		spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
168*4882a593Smuzhiyun 	}
169*4882a593Smuzhiyun 
170*4882a593Smuzhiyun 	return 0;
171*4882a593Smuzhiyun }
172*4882a593Smuzhiyun 
173*4882a593Smuzhiyun DEFINE_SHOW_ATTRIBUTE(qla2x00_dfs_tgt_sess);
174*4882a593Smuzhiyun 
175*4882a593Smuzhiyun static int
qla2x00_dfs_tgt_port_database_show(struct seq_file * s,void * unused)176*4882a593Smuzhiyun qla2x00_dfs_tgt_port_database_show(struct seq_file *s, void *unused)
177*4882a593Smuzhiyun {
178*4882a593Smuzhiyun 	scsi_qla_host_t *vha = s->private;
179*4882a593Smuzhiyun 	struct qla_hw_data *ha = vha->hw;
180*4882a593Smuzhiyun 	struct gid_list_info *gid_list;
181*4882a593Smuzhiyun 	dma_addr_t gid_list_dma;
182*4882a593Smuzhiyun 	fc_port_t fc_port;
183*4882a593Smuzhiyun 	char *id_iter;
184*4882a593Smuzhiyun 	int rc, i;
185*4882a593Smuzhiyun 	uint16_t entries, loop_id;
186*4882a593Smuzhiyun 
187*4882a593Smuzhiyun 	seq_printf(s, "%s\n", vha->host_str);
188*4882a593Smuzhiyun 	gid_list = dma_alloc_coherent(&ha->pdev->dev,
189*4882a593Smuzhiyun 				      qla2x00_gid_list_size(ha),
190*4882a593Smuzhiyun 				      &gid_list_dma, GFP_KERNEL);
191*4882a593Smuzhiyun 	if (!gid_list) {
192*4882a593Smuzhiyun 		ql_dbg(ql_dbg_user, vha, 0x7018,
193*4882a593Smuzhiyun 		       "DMA allocation failed for %u\n",
194*4882a593Smuzhiyun 		       qla2x00_gid_list_size(ha));
195*4882a593Smuzhiyun 		return 0;
196*4882a593Smuzhiyun 	}
197*4882a593Smuzhiyun 
198*4882a593Smuzhiyun 	rc = qla24xx_gidlist_wait(vha, gid_list, gid_list_dma,
199*4882a593Smuzhiyun 				  &entries);
200*4882a593Smuzhiyun 	if (rc != QLA_SUCCESS)
201*4882a593Smuzhiyun 		goto out_free_id_list;
202*4882a593Smuzhiyun 
203*4882a593Smuzhiyun 	id_iter = (char *)gid_list;
204*4882a593Smuzhiyun 
205*4882a593Smuzhiyun 	seq_puts(s, "Port Name	Port ID		Loop ID\n");
206*4882a593Smuzhiyun 
207*4882a593Smuzhiyun 	for (i = 0; i < entries; i++) {
208*4882a593Smuzhiyun 		struct gid_list_info *gid =
209*4882a593Smuzhiyun 			(struct gid_list_info *)id_iter;
210*4882a593Smuzhiyun 		loop_id = le16_to_cpu(gid->loop_id);
211*4882a593Smuzhiyun 		memset(&fc_port, 0, sizeof(fc_port_t));
212*4882a593Smuzhiyun 
213*4882a593Smuzhiyun 		fc_port.loop_id = loop_id;
214*4882a593Smuzhiyun 
215*4882a593Smuzhiyun 		rc = qla24xx_gpdb_wait(vha, &fc_port, 0);
216*4882a593Smuzhiyun 		seq_printf(s, "%8phC  %02x%02x%02x  %d\n",
217*4882a593Smuzhiyun 			   fc_port.port_name, fc_port.d_id.b.domain,
218*4882a593Smuzhiyun 			   fc_port.d_id.b.area, fc_port.d_id.b.al_pa,
219*4882a593Smuzhiyun 			   fc_port.loop_id);
220*4882a593Smuzhiyun 		id_iter += ha->gid_list_info_size;
221*4882a593Smuzhiyun 	}
222*4882a593Smuzhiyun out_free_id_list:
223*4882a593Smuzhiyun 	dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
224*4882a593Smuzhiyun 			  gid_list, gid_list_dma);
225*4882a593Smuzhiyun 
226*4882a593Smuzhiyun 	return 0;
227*4882a593Smuzhiyun }
228*4882a593Smuzhiyun 
229*4882a593Smuzhiyun DEFINE_SHOW_ATTRIBUTE(qla2x00_dfs_tgt_port_database);
230*4882a593Smuzhiyun 
231*4882a593Smuzhiyun static int
qla_dfs_fw_resource_cnt_show(struct seq_file * s,void * unused)232*4882a593Smuzhiyun qla_dfs_fw_resource_cnt_show(struct seq_file *s, void *unused)
233*4882a593Smuzhiyun {
234*4882a593Smuzhiyun 	struct scsi_qla_host *vha = s->private;
235*4882a593Smuzhiyun 	uint16_t mb[MAX_IOCB_MB_REG];
236*4882a593Smuzhiyun 	int rc;
237*4882a593Smuzhiyun 	struct qla_hw_data *ha = vha->hw;
238*4882a593Smuzhiyun 	u16 iocbs_used, i;
239*4882a593Smuzhiyun 
240*4882a593Smuzhiyun 	rc = qla24xx_res_count_wait(vha, mb, SIZEOF_IOCB_MB_REG);
241*4882a593Smuzhiyun 	if (rc != QLA_SUCCESS) {
242*4882a593Smuzhiyun 		seq_printf(s, "Mailbox Command failed %d, mb %#x", rc, mb[0]);
243*4882a593Smuzhiyun 	} else {
244*4882a593Smuzhiyun 		seq_puts(s, "FW Resource count\n\n");
245*4882a593Smuzhiyun 		seq_printf(s, "Original TGT exchg count[%d]\n", mb[1]);
246*4882a593Smuzhiyun 		seq_printf(s, "Current TGT exchg count[%d]\n", mb[2]);
247*4882a593Smuzhiyun 		seq_printf(s, "Current Initiator Exchange count[%d]\n", mb[3]);
248*4882a593Smuzhiyun 		seq_printf(s, "Original Initiator Exchange count[%d]\n", mb[6]);
249*4882a593Smuzhiyun 		seq_printf(s, "Current IOCB count[%d]\n", mb[7]);
250*4882a593Smuzhiyun 		seq_printf(s, "Original IOCB count[%d]\n", mb[10]);
251*4882a593Smuzhiyun 		seq_printf(s, "MAX VP count[%d]\n", mb[11]);
252*4882a593Smuzhiyun 		seq_printf(s, "MAX FCF count[%d]\n", mb[12]);
253*4882a593Smuzhiyun 		seq_printf(s, "Current free pageable XCB buffer cnt[%d]\n",
254*4882a593Smuzhiyun 		    mb[20]);
255*4882a593Smuzhiyun 		seq_printf(s, "Original Initiator fast XCB buffer cnt[%d]\n",
256*4882a593Smuzhiyun 		    mb[21]);
257*4882a593Smuzhiyun 		seq_printf(s, "Current free Initiator fast XCB buffer cnt[%d]\n",
258*4882a593Smuzhiyun 		    mb[22]);
259*4882a593Smuzhiyun 		seq_printf(s, "Original Target fast XCB buffer cnt[%d]\n",
260*4882a593Smuzhiyun 		    mb[23]);
261*4882a593Smuzhiyun 	}
262*4882a593Smuzhiyun 
263*4882a593Smuzhiyun 	if (ql2xenforce_iocb_limit) {
264*4882a593Smuzhiyun 		/* lock is not require. It's an estimate. */
265*4882a593Smuzhiyun 		iocbs_used = ha->base_qpair->fwres.iocbs_used;
266*4882a593Smuzhiyun 		for (i = 0; i < ha->max_qpairs; i++) {
267*4882a593Smuzhiyun 			if (ha->queue_pair_map[i])
268*4882a593Smuzhiyun 				iocbs_used += ha->queue_pair_map[i]->fwres.iocbs_used;
269*4882a593Smuzhiyun 		}
270*4882a593Smuzhiyun 
271*4882a593Smuzhiyun 		seq_printf(s, "Driver: estimate iocb used [%d] high water limit [%d]\n",
272*4882a593Smuzhiyun 			   iocbs_used, ha->base_qpair->fwres.iocbs_limit);
273*4882a593Smuzhiyun 	}
274*4882a593Smuzhiyun 
275*4882a593Smuzhiyun 	return 0;
276*4882a593Smuzhiyun }
277*4882a593Smuzhiyun 
278*4882a593Smuzhiyun DEFINE_SHOW_ATTRIBUTE(qla_dfs_fw_resource_cnt);
279*4882a593Smuzhiyun 
280*4882a593Smuzhiyun static int
qla_dfs_tgt_counters_show(struct seq_file * s,void * unused)281*4882a593Smuzhiyun qla_dfs_tgt_counters_show(struct seq_file *s, void *unused)
282*4882a593Smuzhiyun {
283*4882a593Smuzhiyun 	struct scsi_qla_host *vha = s->private;
284*4882a593Smuzhiyun 	struct qla_qpair *qpair = vha->hw->base_qpair;
285*4882a593Smuzhiyun 	uint64_t qla_core_sbt_cmd, core_qla_que_buf, qla_core_ret_ctio,
286*4882a593Smuzhiyun 		core_qla_snd_status, qla_core_ret_sta_ctio, core_qla_free_cmd,
287*4882a593Smuzhiyun 		num_q_full_sent, num_alloc_iocb_failed, num_term_xchg_sent;
288*4882a593Smuzhiyun 	u16 i;
289*4882a593Smuzhiyun 
290*4882a593Smuzhiyun 	qla_core_sbt_cmd = qpair->tgt_counters.qla_core_sbt_cmd;
291*4882a593Smuzhiyun 	core_qla_que_buf = qpair->tgt_counters.core_qla_que_buf;
292*4882a593Smuzhiyun 	qla_core_ret_ctio = qpair->tgt_counters.qla_core_ret_ctio;
293*4882a593Smuzhiyun 	core_qla_snd_status = qpair->tgt_counters.core_qla_snd_status;
294*4882a593Smuzhiyun 	qla_core_ret_sta_ctio = qpair->tgt_counters.qla_core_ret_sta_ctio;
295*4882a593Smuzhiyun 	core_qla_free_cmd = qpair->tgt_counters.core_qla_free_cmd;
296*4882a593Smuzhiyun 	num_q_full_sent = qpair->tgt_counters.num_q_full_sent;
297*4882a593Smuzhiyun 	num_alloc_iocb_failed = qpair->tgt_counters.num_alloc_iocb_failed;
298*4882a593Smuzhiyun 	num_term_xchg_sent = qpair->tgt_counters.num_term_xchg_sent;
299*4882a593Smuzhiyun 
300*4882a593Smuzhiyun 	for (i = 0; i < vha->hw->max_qpairs; i++) {
301*4882a593Smuzhiyun 		qpair = vha->hw->queue_pair_map[i];
302*4882a593Smuzhiyun 		if (!qpair)
303*4882a593Smuzhiyun 			continue;
304*4882a593Smuzhiyun 		qla_core_sbt_cmd += qpair->tgt_counters.qla_core_sbt_cmd;
305*4882a593Smuzhiyun 		core_qla_que_buf += qpair->tgt_counters.core_qla_que_buf;
306*4882a593Smuzhiyun 		qla_core_ret_ctio += qpair->tgt_counters.qla_core_ret_ctio;
307*4882a593Smuzhiyun 		core_qla_snd_status += qpair->tgt_counters.core_qla_snd_status;
308*4882a593Smuzhiyun 		qla_core_ret_sta_ctio +=
309*4882a593Smuzhiyun 		    qpair->tgt_counters.qla_core_ret_sta_ctio;
310*4882a593Smuzhiyun 		core_qla_free_cmd += qpair->tgt_counters.core_qla_free_cmd;
311*4882a593Smuzhiyun 		num_q_full_sent += qpair->tgt_counters.num_q_full_sent;
312*4882a593Smuzhiyun 		num_alloc_iocb_failed +=
313*4882a593Smuzhiyun 		    qpair->tgt_counters.num_alloc_iocb_failed;
314*4882a593Smuzhiyun 		num_term_xchg_sent += qpair->tgt_counters.num_term_xchg_sent;
315*4882a593Smuzhiyun 	}
316*4882a593Smuzhiyun 
317*4882a593Smuzhiyun 	seq_puts(s, "Target Counters\n");
318*4882a593Smuzhiyun 	seq_printf(s, "qla_core_sbt_cmd = %lld\n",
319*4882a593Smuzhiyun 		qla_core_sbt_cmd);
320*4882a593Smuzhiyun 	seq_printf(s, "qla_core_ret_sta_ctio = %lld\n",
321*4882a593Smuzhiyun 		qla_core_ret_sta_ctio);
322*4882a593Smuzhiyun 	seq_printf(s, "qla_core_ret_ctio = %lld\n",
323*4882a593Smuzhiyun 		qla_core_ret_ctio);
324*4882a593Smuzhiyun 	seq_printf(s, "core_qla_que_buf = %lld\n",
325*4882a593Smuzhiyun 		core_qla_que_buf);
326*4882a593Smuzhiyun 	seq_printf(s, "core_qla_snd_status = %lld\n",
327*4882a593Smuzhiyun 		core_qla_snd_status);
328*4882a593Smuzhiyun 	seq_printf(s, "core_qla_free_cmd = %lld\n",
329*4882a593Smuzhiyun 		core_qla_free_cmd);
330*4882a593Smuzhiyun 	seq_printf(s, "num alloc iocb failed = %lld\n",
331*4882a593Smuzhiyun 		num_alloc_iocb_failed);
332*4882a593Smuzhiyun 	seq_printf(s, "num term exchange sent = %lld\n",
333*4882a593Smuzhiyun 		num_term_xchg_sent);
334*4882a593Smuzhiyun 	seq_printf(s, "num Q full sent = %lld\n",
335*4882a593Smuzhiyun 		num_q_full_sent);
336*4882a593Smuzhiyun 
337*4882a593Smuzhiyun 	/* DIF stats */
338*4882a593Smuzhiyun 	seq_printf(s, "DIF Inp Bytes = %lld\n",
339*4882a593Smuzhiyun 		vha->qla_stats.qla_dif_stats.dif_input_bytes);
340*4882a593Smuzhiyun 	seq_printf(s, "DIF Outp Bytes = %lld\n",
341*4882a593Smuzhiyun 		vha->qla_stats.qla_dif_stats.dif_output_bytes);
342*4882a593Smuzhiyun 	seq_printf(s, "DIF Inp Req = %lld\n",
343*4882a593Smuzhiyun 		vha->qla_stats.qla_dif_stats.dif_input_requests);
344*4882a593Smuzhiyun 	seq_printf(s, "DIF Outp Req = %lld\n",
345*4882a593Smuzhiyun 		vha->qla_stats.qla_dif_stats.dif_output_requests);
346*4882a593Smuzhiyun 	seq_printf(s, "DIF Guard err = %d\n",
347*4882a593Smuzhiyun 		vha->qla_stats.qla_dif_stats.dif_guard_err);
348*4882a593Smuzhiyun 	seq_printf(s, "DIF Ref tag err = %d\n",
349*4882a593Smuzhiyun 		vha->qla_stats.qla_dif_stats.dif_ref_tag_err);
350*4882a593Smuzhiyun 	seq_printf(s, "DIF App tag err = %d\n",
351*4882a593Smuzhiyun 		vha->qla_stats.qla_dif_stats.dif_app_tag_err);
352*4882a593Smuzhiyun 	return 0;
353*4882a593Smuzhiyun }
354*4882a593Smuzhiyun 
355*4882a593Smuzhiyun DEFINE_SHOW_ATTRIBUTE(qla_dfs_tgt_counters);
356*4882a593Smuzhiyun 
357*4882a593Smuzhiyun static int
qla2x00_dfs_fce_show(struct seq_file * s,void * unused)358*4882a593Smuzhiyun qla2x00_dfs_fce_show(struct seq_file *s, void *unused)
359*4882a593Smuzhiyun {
360*4882a593Smuzhiyun 	scsi_qla_host_t *vha = s->private;
361*4882a593Smuzhiyun 	uint32_t cnt;
362*4882a593Smuzhiyun 	uint32_t *fce;
363*4882a593Smuzhiyun 	uint64_t fce_start;
364*4882a593Smuzhiyun 	struct qla_hw_data *ha = vha->hw;
365*4882a593Smuzhiyun 
366*4882a593Smuzhiyun 	mutex_lock(&ha->fce_mutex);
367*4882a593Smuzhiyun 
368*4882a593Smuzhiyun 	seq_puts(s, "FCE Trace Buffer\n");
369*4882a593Smuzhiyun 	seq_printf(s, "In Pointer = %llx\n\n", (unsigned long long)ha->fce_wr);
370*4882a593Smuzhiyun 	seq_printf(s, "Base = %llx\n\n", (unsigned long long) ha->fce_dma);
371*4882a593Smuzhiyun 	seq_puts(s, "FCE Enable Registers\n");
372*4882a593Smuzhiyun 	seq_printf(s, "%08x %08x %08x %08x %08x %08x\n",
373*4882a593Smuzhiyun 	    ha->fce_mb[0], ha->fce_mb[2], ha->fce_mb[3], ha->fce_mb[4],
374*4882a593Smuzhiyun 	    ha->fce_mb[5], ha->fce_mb[6]);
375*4882a593Smuzhiyun 
376*4882a593Smuzhiyun 	fce = (uint32_t *) ha->fce;
377*4882a593Smuzhiyun 	fce_start = (unsigned long long) ha->fce_dma;
378*4882a593Smuzhiyun 	for (cnt = 0; cnt < fce_calc_size(ha->fce_bufs) / 4; cnt++) {
379*4882a593Smuzhiyun 		if (cnt % 8 == 0)
380*4882a593Smuzhiyun 			seq_printf(s, "\n%llx: ",
381*4882a593Smuzhiyun 			    (unsigned long long)((cnt * 4) + fce_start));
382*4882a593Smuzhiyun 		else
383*4882a593Smuzhiyun 			seq_putc(s, ' ');
384*4882a593Smuzhiyun 		seq_printf(s, "%08x", *fce++);
385*4882a593Smuzhiyun 	}
386*4882a593Smuzhiyun 
387*4882a593Smuzhiyun 	seq_puts(s, "\nEnd\n");
388*4882a593Smuzhiyun 
389*4882a593Smuzhiyun 	mutex_unlock(&ha->fce_mutex);
390*4882a593Smuzhiyun 
391*4882a593Smuzhiyun 	return 0;
392*4882a593Smuzhiyun }
393*4882a593Smuzhiyun 
394*4882a593Smuzhiyun static int
qla2x00_dfs_fce_open(struct inode * inode,struct file * file)395*4882a593Smuzhiyun qla2x00_dfs_fce_open(struct inode *inode, struct file *file)
396*4882a593Smuzhiyun {
397*4882a593Smuzhiyun 	scsi_qla_host_t *vha = inode->i_private;
398*4882a593Smuzhiyun 	struct qla_hw_data *ha = vha->hw;
399*4882a593Smuzhiyun 	int rval;
400*4882a593Smuzhiyun 
401*4882a593Smuzhiyun 	if (!ha->flags.fce_enabled)
402*4882a593Smuzhiyun 		goto out;
403*4882a593Smuzhiyun 
404*4882a593Smuzhiyun 	mutex_lock(&ha->fce_mutex);
405*4882a593Smuzhiyun 
406*4882a593Smuzhiyun 	/* Pause tracing to flush FCE buffers. */
407*4882a593Smuzhiyun 	rval = qla2x00_disable_fce_trace(vha, &ha->fce_wr, &ha->fce_rd);
408*4882a593Smuzhiyun 	if (rval)
409*4882a593Smuzhiyun 		ql_dbg(ql_dbg_user, vha, 0x705c,
410*4882a593Smuzhiyun 		    "DebugFS: Unable to disable FCE (%d).\n", rval);
411*4882a593Smuzhiyun 
412*4882a593Smuzhiyun 	ha->flags.fce_enabled = 0;
413*4882a593Smuzhiyun 
414*4882a593Smuzhiyun 	mutex_unlock(&ha->fce_mutex);
415*4882a593Smuzhiyun out:
416*4882a593Smuzhiyun 	return single_open(file, qla2x00_dfs_fce_show, vha);
417*4882a593Smuzhiyun }
418*4882a593Smuzhiyun 
419*4882a593Smuzhiyun static int
qla2x00_dfs_fce_release(struct inode * inode,struct file * file)420*4882a593Smuzhiyun qla2x00_dfs_fce_release(struct inode *inode, struct file *file)
421*4882a593Smuzhiyun {
422*4882a593Smuzhiyun 	scsi_qla_host_t *vha = inode->i_private;
423*4882a593Smuzhiyun 	struct qla_hw_data *ha = vha->hw;
424*4882a593Smuzhiyun 	int rval;
425*4882a593Smuzhiyun 
426*4882a593Smuzhiyun 	if (ha->flags.fce_enabled)
427*4882a593Smuzhiyun 		goto out;
428*4882a593Smuzhiyun 
429*4882a593Smuzhiyun 	mutex_lock(&ha->fce_mutex);
430*4882a593Smuzhiyun 
431*4882a593Smuzhiyun 	/* Re-enable FCE tracing. */
432*4882a593Smuzhiyun 	ha->flags.fce_enabled = 1;
433*4882a593Smuzhiyun 	memset(ha->fce, 0, fce_calc_size(ha->fce_bufs));
434*4882a593Smuzhiyun 	rval = qla2x00_enable_fce_trace(vha, ha->fce_dma, ha->fce_bufs,
435*4882a593Smuzhiyun 	    ha->fce_mb, &ha->fce_bufs);
436*4882a593Smuzhiyun 	if (rval) {
437*4882a593Smuzhiyun 		ql_dbg(ql_dbg_user, vha, 0x700d,
438*4882a593Smuzhiyun 		    "DebugFS: Unable to reinitialize FCE (%d).\n", rval);
439*4882a593Smuzhiyun 		ha->flags.fce_enabled = 0;
440*4882a593Smuzhiyun 	}
441*4882a593Smuzhiyun 
442*4882a593Smuzhiyun 	mutex_unlock(&ha->fce_mutex);
443*4882a593Smuzhiyun out:
444*4882a593Smuzhiyun 	return single_release(inode, file);
445*4882a593Smuzhiyun }
446*4882a593Smuzhiyun 
447*4882a593Smuzhiyun static const struct file_operations dfs_fce_ops = {
448*4882a593Smuzhiyun 	.open		= qla2x00_dfs_fce_open,
449*4882a593Smuzhiyun 	.read		= seq_read,
450*4882a593Smuzhiyun 	.llseek		= seq_lseek,
451*4882a593Smuzhiyun 	.release	= qla2x00_dfs_fce_release,
452*4882a593Smuzhiyun };
453*4882a593Smuzhiyun 
454*4882a593Smuzhiyun static int
qla_dfs_naqp_show(struct seq_file * s,void * unused)455*4882a593Smuzhiyun qla_dfs_naqp_show(struct seq_file *s, void *unused)
456*4882a593Smuzhiyun {
457*4882a593Smuzhiyun 	struct scsi_qla_host *vha = s->private;
458*4882a593Smuzhiyun 	struct qla_hw_data *ha = vha->hw;
459*4882a593Smuzhiyun 
460*4882a593Smuzhiyun 	seq_printf(s, "%d\n", ha->tgt.num_act_qpairs);
461*4882a593Smuzhiyun 	return 0;
462*4882a593Smuzhiyun }
463*4882a593Smuzhiyun 
464*4882a593Smuzhiyun static int
qla_dfs_naqp_open(struct inode * inode,struct file * file)465*4882a593Smuzhiyun qla_dfs_naqp_open(struct inode *inode, struct file *file)
466*4882a593Smuzhiyun {
467*4882a593Smuzhiyun 	struct scsi_qla_host *vha = inode->i_private;
468*4882a593Smuzhiyun 
469*4882a593Smuzhiyun 	return single_open(file, qla_dfs_naqp_show, vha);
470*4882a593Smuzhiyun }
471*4882a593Smuzhiyun 
472*4882a593Smuzhiyun static ssize_t
qla_dfs_naqp_write(struct file * file,const char __user * buffer,size_t count,loff_t * pos)473*4882a593Smuzhiyun qla_dfs_naqp_write(struct file *file, const char __user *buffer,
474*4882a593Smuzhiyun     size_t count, loff_t *pos)
475*4882a593Smuzhiyun {
476*4882a593Smuzhiyun 	struct seq_file *s = file->private_data;
477*4882a593Smuzhiyun 	struct scsi_qla_host *vha = s->private;
478*4882a593Smuzhiyun 	struct qla_hw_data *ha = vha->hw;
479*4882a593Smuzhiyun 	char *buf;
480*4882a593Smuzhiyun 	int rc = 0;
481*4882a593Smuzhiyun 	unsigned long num_act_qp;
482*4882a593Smuzhiyun 
483*4882a593Smuzhiyun 	if (!(IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))) {
484*4882a593Smuzhiyun 		pr_err("host%ld: this adapter does not support Multi Q.",
485*4882a593Smuzhiyun 		    vha->host_no);
486*4882a593Smuzhiyun 		return -EINVAL;
487*4882a593Smuzhiyun 	}
488*4882a593Smuzhiyun 
489*4882a593Smuzhiyun 	if (!vha->flags.qpairs_available) {
490*4882a593Smuzhiyun 		pr_err("host%ld: Driver is not setup with Multi Q.",
491*4882a593Smuzhiyun 		    vha->host_no);
492*4882a593Smuzhiyun 		return -EINVAL;
493*4882a593Smuzhiyun 	}
494*4882a593Smuzhiyun 	buf = memdup_user_nul(buffer, count);
495*4882a593Smuzhiyun 	if (IS_ERR(buf)) {
496*4882a593Smuzhiyun 		pr_err("host%ld: fail to copy user buffer.",
497*4882a593Smuzhiyun 		    vha->host_no);
498*4882a593Smuzhiyun 		return PTR_ERR(buf);
499*4882a593Smuzhiyun 	}
500*4882a593Smuzhiyun 
501*4882a593Smuzhiyun 	num_act_qp = simple_strtoul(buf, NULL, 0);
502*4882a593Smuzhiyun 
503*4882a593Smuzhiyun 	if (num_act_qp >= vha->hw->max_qpairs) {
504*4882a593Smuzhiyun 		pr_err("User set invalid number of qpairs %lu. Max = %d",
505*4882a593Smuzhiyun 		    num_act_qp, vha->hw->max_qpairs);
506*4882a593Smuzhiyun 		rc = -EINVAL;
507*4882a593Smuzhiyun 		goto out_free;
508*4882a593Smuzhiyun 	}
509*4882a593Smuzhiyun 
510*4882a593Smuzhiyun 	if (num_act_qp != ha->tgt.num_act_qpairs) {
511*4882a593Smuzhiyun 		ha->tgt.num_act_qpairs = num_act_qp;
512*4882a593Smuzhiyun 		qlt_clr_qp_table(vha);
513*4882a593Smuzhiyun 	}
514*4882a593Smuzhiyun 	rc = count;
515*4882a593Smuzhiyun out_free:
516*4882a593Smuzhiyun 	kfree(buf);
517*4882a593Smuzhiyun 	return rc;
518*4882a593Smuzhiyun }
519*4882a593Smuzhiyun 
520*4882a593Smuzhiyun static const struct file_operations dfs_naqp_ops = {
521*4882a593Smuzhiyun 	.open		= qla_dfs_naqp_open,
522*4882a593Smuzhiyun 	.read		= seq_read,
523*4882a593Smuzhiyun 	.llseek		= seq_lseek,
524*4882a593Smuzhiyun 	.release	= single_release,
525*4882a593Smuzhiyun 	.write		= qla_dfs_naqp_write,
526*4882a593Smuzhiyun };
527*4882a593Smuzhiyun 
528*4882a593Smuzhiyun 
529*4882a593Smuzhiyun int
qla2x00_dfs_setup(scsi_qla_host_t * vha)530*4882a593Smuzhiyun qla2x00_dfs_setup(scsi_qla_host_t *vha)
531*4882a593Smuzhiyun {
532*4882a593Smuzhiyun 	struct qla_hw_data *ha = vha->hw;
533*4882a593Smuzhiyun 
534*4882a593Smuzhiyun 	if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
535*4882a593Smuzhiyun 	    !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
536*4882a593Smuzhiyun 		goto out;
537*4882a593Smuzhiyun 	if (!ha->fce)
538*4882a593Smuzhiyun 		goto out;
539*4882a593Smuzhiyun 
540*4882a593Smuzhiyun 	if (qla2x00_dfs_root)
541*4882a593Smuzhiyun 		goto create_dir;
542*4882a593Smuzhiyun 
543*4882a593Smuzhiyun 	atomic_set(&qla2x00_dfs_root_count, 0);
544*4882a593Smuzhiyun 	qla2x00_dfs_root = debugfs_create_dir(QLA2XXX_DRIVER_NAME, NULL);
545*4882a593Smuzhiyun 
546*4882a593Smuzhiyun create_dir:
547*4882a593Smuzhiyun 	if (ha->dfs_dir)
548*4882a593Smuzhiyun 		goto create_nodes;
549*4882a593Smuzhiyun 
550*4882a593Smuzhiyun 	mutex_init(&ha->fce_mutex);
551*4882a593Smuzhiyun 	ha->dfs_dir = debugfs_create_dir(vha->host_str, qla2x00_dfs_root);
552*4882a593Smuzhiyun 
553*4882a593Smuzhiyun 	atomic_inc(&qla2x00_dfs_root_count);
554*4882a593Smuzhiyun 
555*4882a593Smuzhiyun create_nodes:
556*4882a593Smuzhiyun 	ha->dfs_fw_resource_cnt = debugfs_create_file("fw_resource_count",
557*4882a593Smuzhiyun 	    S_IRUSR, ha->dfs_dir, vha, &qla_dfs_fw_resource_cnt_fops);
558*4882a593Smuzhiyun 
559*4882a593Smuzhiyun 	ha->dfs_tgt_counters = debugfs_create_file("tgt_counters", S_IRUSR,
560*4882a593Smuzhiyun 	    ha->dfs_dir, vha, &qla_dfs_tgt_counters_fops);
561*4882a593Smuzhiyun 
562*4882a593Smuzhiyun 	ha->tgt.dfs_tgt_port_database = debugfs_create_file("tgt_port_database",
563*4882a593Smuzhiyun 	    S_IRUSR,  ha->dfs_dir, vha, &qla2x00_dfs_tgt_port_database_fops);
564*4882a593Smuzhiyun 
565*4882a593Smuzhiyun 	ha->dfs_fce = debugfs_create_file("fce", S_IRUSR, ha->dfs_dir, vha,
566*4882a593Smuzhiyun 	    &dfs_fce_ops);
567*4882a593Smuzhiyun 
568*4882a593Smuzhiyun 	ha->tgt.dfs_tgt_sess = debugfs_create_file("tgt_sess",
569*4882a593Smuzhiyun 		S_IRUSR, ha->dfs_dir, vha, &qla2x00_dfs_tgt_sess_fops);
570*4882a593Smuzhiyun 
571*4882a593Smuzhiyun 	if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha)) {
572*4882a593Smuzhiyun 		ha->tgt.dfs_naqp = debugfs_create_file("naqp",
573*4882a593Smuzhiyun 		    0400, ha->dfs_dir, vha, &dfs_naqp_ops);
574*4882a593Smuzhiyun 		if (!ha->tgt.dfs_naqp) {
575*4882a593Smuzhiyun 			ql_log(ql_log_warn, vha, 0xd011,
576*4882a593Smuzhiyun 			       "Unable to create debugFS naqp node.\n");
577*4882a593Smuzhiyun 			goto out;
578*4882a593Smuzhiyun 		}
579*4882a593Smuzhiyun 	}
580*4882a593Smuzhiyun 	vha->dfs_rport_root = debugfs_create_dir("rports", ha->dfs_dir);
581*4882a593Smuzhiyun 	if (!vha->dfs_rport_root) {
582*4882a593Smuzhiyun 		ql_log(ql_log_warn, vha, 0xd012,
583*4882a593Smuzhiyun 		       "Unable to create debugFS rports node.\n");
584*4882a593Smuzhiyun 		goto out;
585*4882a593Smuzhiyun 	}
586*4882a593Smuzhiyun out:
587*4882a593Smuzhiyun 	return 0;
588*4882a593Smuzhiyun }
589*4882a593Smuzhiyun 
590*4882a593Smuzhiyun int
qla2x00_dfs_remove(scsi_qla_host_t * vha)591*4882a593Smuzhiyun qla2x00_dfs_remove(scsi_qla_host_t *vha)
592*4882a593Smuzhiyun {
593*4882a593Smuzhiyun 	struct qla_hw_data *ha = vha->hw;
594*4882a593Smuzhiyun 
595*4882a593Smuzhiyun 	if (ha->tgt.dfs_naqp) {
596*4882a593Smuzhiyun 		debugfs_remove(ha->tgt.dfs_naqp);
597*4882a593Smuzhiyun 		ha->tgt.dfs_naqp = NULL;
598*4882a593Smuzhiyun 	}
599*4882a593Smuzhiyun 
600*4882a593Smuzhiyun 	if (ha->tgt.dfs_tgt_sess) {
601*4882a593Smuzhiyun 		debugfs_remove(ha->tgt.dfs_tgt_sess);
602*4882a593Smuzhiyun 		ha->tgt.dfs_tgt_sess = NULL;
603*4882a593Smuzhiyun 	}
604*4882a593Smuzhiyun 
605*4882a593Smuzhiyun 	if (ha->tgt.dfs_tgt_port_database) {
606*4882a593Smuzhiyun 		debugfs_remove(ha->tgt.dfs_tgt_port_database);
607*4882a593Smuzhiyun 		ha->tgt.dfs_tgt_port_database = NULL;
608*4882a593Smuzhiyun 	}
609*4882a593Smuzhiyun 
610*4882a593Smuzhiyun 	if (ha->dfs_fw_resource_cnt) {
611*4882a593Smuzhiyun 		debugfs_remove(ha->dfs_fw_resource_cnt);
612*4882a593Smuzhiyun 		ha->dfs_fw_resource_cnt = NULL;
613*4882a593Smuzhiyun 	}
614*4882a593Smuzhiyun 
615*4882a593Smuzhiyun 	if (ha->dfs_tgt_counters) {
616*4882a593Smuzhiyun 		debugfs_remove(ha->dfs_tgt_counters);
617*4882a593Smuzhiyun 		ha->dfs_tgt_counters = NULL;
618*4882a593Smuzhiyun 	}
619*4882a593Smuzhiyun 
620*4882a593Smuzhiyun 	if (ha->dfs_fce) {
621*4882a593Smuzhiyun 		debugfs_remove(ha->dfs_fce);
622*4882a593Smuzhiyun 		ha->dfs_fce = NULL;
623*4882a593Smuzhiyun 	}
624*4882a593Smuzhiyun 
625*4882a593Smuzhiyun 	if (vha->dfs_rport_root) {
626*4882a593Smuzhiyun 		debugfs_remove_recursive(vha->dfs_rport_root);
627*4882a593Smuzhiyun 		vha->dfs_rport_root = NULL;
628*4882a593Smuzhiyun 	}
629*4882a593Smuzhiyun 
630*4882a593Smuzhiyun 	if (ha->dfs_dir) {
631*4882a593Smuzhiyun 		debugfs_remove(ha->dfs_dir);
632*4882a593Smuzhiyun 		ha->dfs_dir = NULL;
633*4882a593Smuzhiyun 		atomic_dec(&qla2x00_dfs_root_count);
634*4882a593Smuzhiyun 	}
635*4882a593Smuzhiyun 
636*4882a593Smuzhiyun 	if (atomic_read(&qla2x00_dfs_root_count) == 0 &&
637*4882a593Smuzhiyun 	    qla2x00_dfs_root) {
638*4882a593Smuzhiyun 		debugfs_remove(qla2x00_dfs_root);
639*4882a593Smuzhiyun 		qla2x00_dfs_root = NULL;
640*4882a593Smuzhiyun 	}
641*4882a593Smuzhiyun 
642*4882a593Smuzhiyun 	return 0;
643*4882a593Smuzhiyun }
644