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