Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * QLogic Fibre Channel HBA Driver
0004  * Copyright (c)  2003-2014 QLogic Corporation
0005  */
0006 #include "qla_def.h"
0007 
0008 #include <linux/debugfs.h>
0009 #include <linux/seq_file.h>
0010 
0011 static struct dentry *qla2x00_dfs_root;
0012 static atomic_t qla2x00_dfs_root_count;
0013 
0014 #define QLA_DFS_RPORT_DEVLOSS_TMO   1
0015 
0016 static int
0017 qla_dfs_rport_get(struct fc_port *fp, int attr_id, u64 *val)
0018 {
0019     switch (attr_id) {
0020     case QLA_DFS_RPORT_DEVLOSS_TMO:
0021         /* Only supported for FC-NVMe devices that are registered. */
0022         if (!(fp->nvme_flag & NVME_FLAG_REGISTERED))
0023             return -EIO;
0024         *val = fp->nvme_remote_port->dev_loss_tmo;
0025         break;
0026     default:
0027         return -EINVAL;
0028     }
0029     return 0;
0030 }
0031 
0032 static int
0033 qla_dfs_rport_set(struct fc_port *fp, int attr_id, u64 val)
0034 {
0035     switch (attr_id) {
0036     case QLA_DFS_RPORT_DEVLOSS_TMO:
0037         /* Only supported for FC-NVMe devices that are registered. */
0038         if (!(fp->nvme_flag & NVME_FLAG_REGISTERED))
0039             return -EIO;
0040 #if (IS_ENABLED(CONFIG_NVME_FC))
0041         return nvme_fc_set_remoteport_devloss(fp->nvme_remote_port,
0042                               val);
0043 #else /* CONFIG_NVME_FC */
0044         return -EINVAL;
0045 #endif /* CONFIG_NVME_FC */
0046     default:
0047         return -EINVAL;
0048     }
0049     return 0;
0050 }
0051 
0052 #define DEFINE_QLA_DFS_RPORT_RW_ATTR(_attr_id, _attr)       \
0053 static int qla_dfs_rport_##_attr##_get(void *data, u64 *val)    \
0054 {                               \
0055     struct fc_port *fp = data;              \
0056     return qla_dfs_rport_get(fp, _attr_id, val);        \
0057 }                               \
0058 static int qla_dfs_rport_##_attr##_set(void *data, u64 val) \
0059 {                               \
0060     struct fc_port *fp = data;              \
0061     return qla_dfs_rport_set(fp, _attr_id, val);        \
0062 }                               \
0063 DEFINE_DEBUGFS_ATTRIBUTE(qla_dfs_rport_##_attr##_fops,      \
0064         qla_dfs_rport_##_attr##_get,            \
0065         qla_dfs_rport_##_attr##_set, "%llu\n")
0066 
0067 /*
0068  * Wrapper for getting fc_port fields.
0069  *
0070  * _attr    : Attribute name.
0071  * _get_val : Accessor macro to retrieve the value.
0072  */
0073 #define DEFINE_QLA_DFS_RPORT_FIELD_GET(_attr, _get_val)         \
0074 static int qla_dfs_rport_field_##_attr##_get(void *data, u64 *val)  \
0075 {                                   \
0076     struct fc_port *fp = data;                  \
0077     *val = _get_val;                        \
0078     return 0;                           \
0079 }                                   \
0080 DEFINE_DEBUGFS_ATTRIBUTE(qla_dfs_rport_field_##_attr##_fops,        \
0081         qla_dfs_rport_field_##_attr##_get,          \
0082         NULL, "%llu\n")
0083 
0084 #define DEFINE_QLA_DFS_RPORT_ACCESS(_attr, _get_val) \
0085     DEFINE_QLA_DFS_RPORT_FIELD_GET(_attr, _get_val)
0086 
0087 #define DEFINE_QLA_DFS_RPORT_FIELD(_attr) \
0088     DEFINE_QLA_DFS_RPORT_FIELD_GET(_attr, fp->_attr)
0089 
0090 DEFINE_QLA_DFS_RPORT_RW_ATTR(QLA_DFS_RPORT_DEVLOSS_TMO, dev_loss_tmo);
0091 
0092 DEFINE_QLA_DFS_RPORT_FIELD(disc_state);
0093 DEFINE_QLA_DFS_RPORT_FIELD(scan_state);
0094 DEFINE_QLA_DFS_RPORT_FIELD(fw_login_state);
0095 DEFINE_QLA_DFS_RPORT_FIELD(login_pause);
0096 DEFINE_QLA_DFS_RPORT_FIELD(flags);
0097 DEFINE_QLA_DFS_RPORT_FIELD(nvme_flag);
0098 DEFINE_QLA_DFS_RPORT_FIELD(last_rscn_gen);
0099 DEFINE_QLA_DFS_RPORT_FIELD(rscn_gen);
0100 DEFINE_QLA_DFS_RPORT_FIELD(login_gen);
0101 DEFINE_QLA_DFS_RPORT_FIELD(loop_id);
0102 DEFINE_QLA_DFS_RPORT_FIELD_GET(port_id, fp->d_id.b24);
0103 DEFINE_QLA_DFS_RPORT_FIELD_GET(sess_kref, kref_read(&fp->sess_kref));
0104 
0105 void
0106 qla2x00_dfs_create_rport(scsi_qla_host_t *vha, struct fc_port *fp)
0107 {
0108     char wwn[32];
0109 
0110 #define QLA_CREATE_RPORT_FIELD_ATTR(_attr)          \
0111     debugfs_create_file(#_attr, 0400, fp->dfs_rport_dir,    \
0112         fp, &qla_dfs_rport_field_##_attr##_fops)
0113 
0114     if (!vha->dfs_rport_root || fp->dfs_rport_dir)
0115         return;
0116 
0117     sprintf(wwn, "pn-%016llx", wwn_to_u64(fp->port_name));
0118     fp->dfs_rport_dir = debugfs_create_dir(wwn, vha->dfs_rport_root);
0119     if (!fp->dfs_rport_dir)
0120         return;
0121     if (NVME_TARGET(vha->hw, fp))
0122         debugfs_create_file("dev_loss_tmo", 0600, fp->dfs_rport_dir,
0123                     fp, &qla_dfs_rport_dev_loss_tmo_fops);
0124 
0125     QLA_CREATE_RPORT_FIELD_ATTR(disc_state);
0126     QLA_CREATE_RPORT_FIELD_ATTR(scan_state);
0127     QLA_CREATE_RPORT_FIELD_ATTR(fw_login_state);
0128     QLA_CREATE_RPORT_FIELD_ATTR(login_pause);
0129     QLA_CREATE_RPORT_FIELD_ATTR(flags);
0130     QLA_CREATE_RPORT_FIELD_ATTR(nvme_flag);
0131     QLA_CREATE_RPORT_FIELD_ATTR(last_rscn_gen);
0132     QLA_CREATE_RPORT_FIELD_ATTR(rscn_gen);
0133     QLA_CREATE_RPORT_FIELD_ATTR(login_gen);
0134     QLA_CREATE_RPORT_FIELD_ATTR(loop_id);
0135     QLA_CREATE_RPORT_FIELD_ATTR(port_id);
0136     QLA_CREATE_RPORT_FIELD_ATTR(sess_kref);
0137 }
0138 
0139 void
0140 qla2x00_dfs_remove_rport(scsi_qla_host_t *vha, struct fc_port *fp)
0141 {
0142     if (!vha->dfs_rport_root || !fp->dfs_rport_dir)
0143         return;
0144     debugfs_remove_recursive(fp->dfs_rport_dir);
0145     fp->dfs_rport_dir = NULL;
0146 }
0147 
0148 static int
0149 qla2x00_dfs_tgt_sess_show(struct seq_file *s, void *unused)
0150 {
0151     scsi_qla_host_t *vha = s->private;
0152     struct qla_hw_data *ha = vha->hw;
0153     unsigned long flags;
0154     struct fc_port *sess = NULL;
0155     struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
0156 
0157     seq_printf(s, "%s\n", vha->host_str);
0158     if (tgt) {
0159         seq_puts(s, "Port ID   Port Name                Handle\n");
0160 
0161         spin_lock_irqsave(&ha->tgt.sess_lock, flags);
0162         list_for_each_entry(sess, &vha->vp_fcports, list)
0163             seq_printf(s, "%02x:%02x:%02x  %8phC  %d\n",
0164                 sess->d_id.b.domain, sess->d_id.b.area,
0165                 sess->d_id.b.al_pa, sess->port_name,
0166                 sess->loop_id);
0167         spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
0168     }
0169 
0170     return 0;
0171 }
0172 
0173 DEFINE_SHOW_ATTRIBUTE(qla2x00_dfs_tgt_sess);
0174 
0175 static int
0176 qla2x00_dfs_tgt_port_database_show(struct seq_file *s, void *unused)
0177 {
0178     scsi_qla_host_t *vha = s->private;
0179     struct qla_hw_data *ha = vha->hw;
0180     struct gid_list_info *gid_list;
0181     dma_addr_t gid_list_dma;
0182     fc_port_t fc_port;
0183     char *id_iter;
0184     int rc, i;
0185     uint16_t entries, loop_id;
0186 
0187     seq_printf(s, "%s\n", vha->host_str);
0188     gid_list = dma_alloc_coherent(&ha->pdev->dev,
0189                       qla2x00_gid_list_size(ha),
0190                       &gid_list_dma, GFP_KERNEL);
0191     if (!gid_list) {
0192         ql_dbg(ql_dbg_user, vha, 0x7018,
0193                "DMA allocation failed for %u\n",
0194                qla2x00_gid_list_size(ha));
0195         return 0;
0196     }
0197 
0198     rc = qla24xx_gidlist_wait(vha, gid_list, gid_list_dma,
0199                   &entries);
0200     if (rc != QLA_SUCCESS)
0201         goto out_free_id_list;
0202 
0203     id_iter = (char *)gid_list;
0204 
0205     seq_puts(s, "Port Name  Port ID     Loop ID\n");
0206 
0207     for (i = 0; i < entries; i++) {
0208         struct gid_list_info *gid =
0209             (struct gid_list_info *)id_iter;
0210         loop_id = le16_to_cpu(gid->loop_id);
0211         memset(&fc_port, 0, sizeof(fc_port_t));
0212 
0213         fc_port.loop_id = loop_id;
0214 
0215         rc = qla24xx_gpdb_wait(vha, &fc_port, 0);
0216         seq_printf(s, "%8phC  %02x%02x%02x  %d\n",
0217                fc_port.port_name, fc_port.d_id.b.domain,
0218                fc_port.d_id.b.area, fc_port.d_id.b.al_pa,
0219                fc_port.loop_id);
0220         id_iter += ha->gid_list_info_size;
0221     }
0222 out_free_id_list:
0223     dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
0224               gid_list, gid_list_dma);
0225 
0226     return 0;
0227 }
0228 
0229 DEFINE_SHOW_ATTRIBUTE(qla2x00_dfs_tgt_port_database);
0230 
0231 static int
0232 qla_dfs_fw_resource_cnt_show(struct seq_file *s, void *unused)
0233 {
0234     struct scsi_qla_host *vha = s->private;
0235     uint16_t mb[MAX_IOCB_MB_REG];
0236     int rc;
0237     struct qla_hw_data *ha = vha->hw;
0238     u16 iocbs_used, i;
0239 
0240     rc = qla24xx_res_count_wait(vha, mb, SIZEOF_IOCB_MB_REG);
0241     if (rc != QLA_SUCCESS) {
0242         seq_printf(s, "Mailbox Command failed %d, mb %#x", rc, mb[0]);
0243     } else {
0244         seq_puts(s, "FW Resource count\n\n");
0245         seq_printf(s, "Original TGT exchg count[%d]\n", mb[1]);
0246         seq_printf(s, "Current TGT exchg count[%d]\n", mb[2]);
0247         seq_printf(s, "Current Initiator Exchange count[%d]\n", mb[3]);
0248         seq_printf(s, "Original Initiator Exchange count[%d]\n", mb[6]);
0249         seq_printf(s, "Current IOCB count[%d]\n", mb[7]);
0250         seq_printf(s, "Original IOCB count[%d]\n", mb[10]);
0251         seq_printf(s, "MAX VP count[%d]\n", mb[11]);
0252         seq_printf(s, "MAX FCF count[%d]\n", mb[12]);
0253         seq_printf(s, "Current free pageable XCB buffer cnt[%d]\n",
0254             mb[20]);
0255         seq_printf(s, "Original Initiator fast XCB buffer cnt[%d]\n",
0256             mb[21]);
0257         seq_printf(s, "Current free Initiator fast XCB buffer cnt[%d]\n",
0258             mb[22]);
0259         seq_printf(s, "Original Target fast XCB buffer cnt[%d]\n",
0260             mb[23]);
0261     }
0262 
0263     if (ql2xenforce_iocb_limit) {
0264         /* lock is not require. It's an estimate. */
0265         iocbs_used = ha->base_qpair->fwres.iocbs_used;
0266         for (i = 0; i < ha->max_qpairs; i++) {
0267             if (ha->queue_pair_map[i])
0268                 iocbs_used += ha->queue_pair_map[i]->fwres.iocbs_used;
0269         }
0270 
0271         seq_printf(s, "Driver: estimate iocb used [%d] high water limit [%d]\n",
0272                iocbs_used, ha->base_qpair->fwres.iocbs_limit);
0273     }
0274 
0275     return 0;
0276 }
0277 
0278 DEFINE_SHOW_ATTRIBUTE(qla_dfs_fw_resource_cnt);
0279 
0280 static int
0281 qla_dfs_tgt_counters_show(struct seq_file *s, void *unused)
0282 {
0283     struct scsi_qla_host *vha = s->private;
0284     struct qla_qpair *qpair = vha->hw->base_qpair;
0285     uint64_t qla_core_sbt_cmd, core_qla_que_buf, qla_core_ret_ctio,
0286         core_qla_snd_status, qla_core_ret_sta_ctio, core_qla_free_cmd,
0287         num_q_full_sent, num_alloc_iocb_failed, num_term_xchg_sent;
0288     u16 i;
0289     fc_port_t *fcport = NULL;
0290 
0291     if (qla2x00_chip_is_down(vha))
0292         return 0;
0293 
0294     qla_core_sbt_cmd = qpair->tgt_counters.qla_core_sbt_cmd;
0295     core_qla_que_buf = qpair->tgt_counters.core_qla_que_buf;
0296     qla_core_ret_ctio = qpair->tgt_counters.qla_core_ret_ctio;
0297     core_qla_snd_status = qpair->tgt_counters.core_qla_snd_status;
0298     qla_core_ret_sta_ctio = qpair->tgt_counters.qla_core_ret_sta_ctio;
0299     core_qla_free_cmd = qpair->tgt_counters.core_qla_free_cmd;
0300     num_q_full_sent = qpair->tgt_counters.num_q_full_sent;
0301     num_alloc_iocb_failed = qpair->tgt_counters.num_alloc_iocb_failed;
0302     num_term_xchg_sent = qpair->tgt_counters.num_term_xchg_sent;
0303 
0304     for (i = 0; i < vha->hw->max_qpairs; i++) {
0305         qpair = vha->hw->queue_pair_map[i];
0306         if (!qpair)
0307             continue;
0308         qla_core_sbt_cmd += qpair->tgt_counters.qla_core_sbt_cmd;
0309         core_qla_que_buf += qpair->tgt_counters.core_qla_que_buf;
0310         qla_core_ret_ctio += qpair->tgt_counters.qla_core_ret_ctio;
0311         core_qla_snd_status += qpair->tgt_counters.core_qla_snd_status;
0312         qla_core_ret_sta_ctio +=
0313             qpair->tgt_counters.qla_core_ret_sta_ctio;
0314         core_qla_free_cmd += qpair->tgt_counters.core_qla_free_cmd;
0315         num_q_full_sent += qpair->tgt_counters.num_q_full_sent;
0316         num_alloc_iocb_failed +=
0317             qpair->tgt_counters.num_alloc_iocb_failed;
0318         num_term_xchg_sent += qpair->tgt_counters.num_term_xchg_sent;
0319     }
0320 
0321     seq_puts(s, "Target Counters\n");
0322     seq_printf(s, "qla_core_sbt_cmd = %lld\n",
0323         qla_core_sbt_cmd);
0324     seq_printf(s, "qla_core_ret_sta_ctio = %lld\n",
0325         qla_core_ret_sta_ctio);
0326     seq_printf(s, "qla_core_ret_ctio = %lld\n",
0327         qla_core_ret_ctio);
0328     seq_printf(s, "core_qla_que_buf = %lld\n",
0329         core_qla_que_buf);
0330     seq_printf(s, "core_qla_snd_status = %lld\n",
0331         core_qla_snd_status);
0332     seq_printf(s, "core_qla_free_cmd = %lld\n",
0333         core_qla_free_cmd);
0334     seq_printf(s, "num alloc iocb failed = %lld\n",
0335         num_alloc_iocb_failed);
0336     seq_printf(s, "num term exchange sent = %lld\n",
0337         num_term_xchg_sent);
0338     seq_printf(s, "num Q full sent = %lld\n",
0339         num_q_full_sent);
0340 
0341     /* DIF stats */
0342     seq_printf(s, "DIF Inp Bytes = %lld\n",
0343         vha->qla_stats.qla_dif_stats.dif_input_bytes);
0344     seq_printf(s, "DIF Outp Bytes = %lld\n",
0345         vha->qla_stats.qla_dif_stats.dif_output_bytes);
0346     seq_printf(s, "DIF Inp Req = %lld\n",
0347         vha->qla_stats.qla_dif_stats.dif_input_requests);
0348     seq_printf(s, "DIF Outp Req = %lld\n",
0349         vha->qla_stats.qla_dif_stats.dif_output_requests);
0350     seq_printf(s, "DIF Guard err = %d\n",
0351         vha->qla_stats.qla_dif_stats.dif_guard_err);
0352     seq_printf(s, "DIF Ref tag err = %d\n",
0353         vha->qla_stats.qla_dif_stats.dif_ref_tag_err);
0354     seq_printf(s, "DIF App tag err = %d\n",
0355         vha->qla_stats.qla_dif_stats.dif_app_tag_err);
0356 
0357     seq_puts(s, "\n");
0358     seq_puts(s, "Initiator Error Counters\n");
0359     seq_printf(s, "HW Error Count =     %14lld\n",
0360            vha->hw_err_cnt);
0361     seq_printf(s, "Link Down Count =    %14lld\n",
0362            vha->short_link_down_cnt);
0363     seq_printf(s, "Interface Err Count =    %14lld\n",
0364            vha->interface_err_cnt);
0365     seq_printf(s, "Cmd Timeout Count =  %14lld\n",
0366            vha->cmd_timeout_cnt);
0367     seq_printf(s, "Reset Count =        %14lld\n",
0368            vha->reset_cmd_err_cnt);
0369     seq_puts(s, "\n");
0370 
0371     list_for_each_entry(fcport, &vha->vp_fcports, list) {
0372         if (!fcport->rport)
0373             continue;
0374 
0375         seq_printf(s, "Target Num = %7d Link Down Count = %14lld\n",
0376                fcport->rport->number, fcport->tgt_short_link_down_cnt);
0377     }
0378     seq_puts(s, "\n");
0379 
0380     return 0;
0381 }
0382 
0383 DEFINE_SHOW_ATTRIBUTE(qla_dfs_tgt_counters);
0384 
0385 static int
0386 qla2x00_dfs_fce_show(struct seq_file *s, void *unused)
0387 {
0388     scsi_qla_host_t *vha = s->private;
0389     uint32_t cnt;
0390     uint32_t *fce;
0391     uint64_t fce_start;
0392     struct qla_hw_data *ha = vha->hw;
0393 
0394     mutex_lock(&ha->fce_mutex);
0395 
0396     seq_puts(s, "FCE Trace Buffer\n");
0397     seq_printf(s, "In Pointer = %llx\n\n", (unsigned long long)ha->fce_wr);
0398     seq_printf(s, "Base = %llx\n\n", (unsigned long long) ha->fce_dma);
0399     seq_puts(s, "FCE Enable Registers\n");
0400     seq_printf(s, "%08x %08x %08x %08x %08x %08x\n",
0401         ha->fce_mb[0], ha->fce_mb[2], ha->fce_mb[3], ha->fce_mb[4],
0402         ha->fce_mb[5], ha->fce_mb[6]);
0403 
0404     fce = (uint32_t *) ha->fce;
0405     fce_start = (unsigned long long) ha->fce_dma;
0406     for (cnt = 0; cnt < fce_calc_size(ha->fce_bufs) / 4; cnt++) {
0407         if (cnt % 8 == 0)
0408             seq_printf(s, "\n%llx: ",
0409                 (unsigned long long)((cnt * 4) + fce_start));
0410         else
0411             seq_putc(s, ' ');
0412         seq_printf(s, "%08x", *fce++);
0413     }
0414 
0415     seq_puts(s, "\nEnd\n");
0416 
0417     mutex_unlock(&ha->fce_mutex);
0418 
0419     return 0;
0420 }
0421 
0422 static int
0423 qla2x00_dfs_fce_open(struct inode *inode, struct file *file)
0424 {
0425     scsi_qla_host_t *vha = inode->i_private;
0426     struct qla_hw_data *ha = vha->hw;
0427     int rval;
0428 
0429     if (!ha->flags.fce_enabled)
0430         goto out;
0431 
0432     mutex_lock(&ha->fce_mutex);
0433 
0434     /* Pause tracing to flush FCE buffers. */
0435     rval = qla2x00_disable_fce_trace(vha, &ha->fce_wr, &ha->fce_rd);
0436     if (rval)
0437         ql_dbg(ql_dbg_user, vha, 0x705c,
0438             "DebugFS: Unable to disable FCE (%d).\n", rval);
0439 
0440     ha->flags.fce_enabled = 0;
0441 
0442     mutex_unlock(&ha->fce_mutex);
0443 out:
0444     return single_open(file, qla2x00_dfs_fce_show, vha);
0445 }
0446 
0447 static int
0448 qla2x00_dfs_fce_release(struct inode *inode, struct file *file)
0449 {
0450     scsi_qla_host_t *vha = inode->i_private;
0451     struct qla_hw_data *ha = vha->hw;
0452     int rval;
0453 
0454     if (ha->flags.fce_enabled)
0455         goto out;
0456 
0457     mutex_lock(&ha->fce_mutex);
0458 
0459     /* Re-enable FCE tracing. */
0460     ha->flags.fce_enabled = 1;
0461     memset(ha->fce, 0, fce_calc_size(ha->fce_bufs));
0462     rval = qla2x00_enable_fce_trace(vha, ha->fce_dma, ha->fce_bufs,
0463         ha->fce_mb, &ha->fce_bufs);
0464     if (rval) {
0465         ql_dbg(ql_dbg_user, vha, 0x700d,
0466             "DebugFS: Unable to reinitialize FCE (%d).\n", rval);
0467         ha->flags.fce_enabled = 0;
0468     }
0469 
0470     mutex_unlock(&ha->fce_mutex);
0471 out:
0472     return single_release(inode, file);
0473 }
0474 
0475 static const struct file_operations dfs_fce_ops = {
0476     .open       = qla2x00_dfs_fce_open,
0477     .read       = seq_read,
0478     .llseek     = seq_lseek,
0479     .release    = qla2x00_dfs_fce_release,
0480 };
0481 
0482 static int
0483 qla_dfs_naqp_show(struct seq_file *s, void *unused)
0484 {
0485     struct scsi_qla_host *vha = s->private;
0486     struct qla_hw_data *ha = vha->hw;
0487 
0488     seq_printf(s, "%d\n", ha->tgt.num_act_qpairs);
0489     return 0;
0490 }
0491 
0492 static int
0493 qla_dfs_naqp_open(struct inode *inode, struct file *file)
0494 {
0495     struct scsi_qla_host *vha = inode->i_private;
0496 
0497     return single_open(file, qla_dfs_naqp_show, vha);
0498 }
0499 
0500 static ssize_t
0501 qla_dfs_naqp_write(struct file *file, const char __user *buffer,
0502     size_t count, loff_t *pos)
0503 {
0504     struct seq_file *s = file->private_data;
0505     struct scsi_qla_host *vha = s->private;
0506     struct qla_hw_data *ha = vha->hw;
0507     char *buf;
0508     int rc = 0;
0509     unsigned long num_act_qp;
0510 
0511     if (!(IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))) {
0512         pr_err("host%ld: this adapter does not support Multi Q.",
0513             vha->host_no);
0514         return -EINVAL;
0515     }
0516 
0517     if (!vha->flags.qpairs_available) {
0518         pr_err("host%ld: Driver is not setup with Multi Q.",
0519             vha->host_no);
0520         return -EINVAL;
0521     }
0522     buf = memdup_user_nul(buffer, count);
0523     if (IS_ERR(buf)) {
0524         pr_err("host%ld: fail to copy user buffer.",
0525             vha->host_no);
0526         return PTR_ERR(buf);
0527     }
0528 
0529     num_act_qp = simple_strtoul(buf, NULL, 0);
0530 
0531     if (num_act_qp >= vha->hw->max_qpairs) {
0532         pr_err("User set invalid number of qpairs %lu. Max = %d",
0533             num_act_qp, vha->hw->max_qpairs);
0534         rc = -EINVAL;
0535         goto out_free;
0536     }
0537 
0538     if (num_act_qp != ha->tgt.num_act_qpairs) {
0539         ha->tgt.num_act_qpairs = num_act_qp;
0540         qlt_clr_qp_table(vha);
0541     }
0542     rc = count;
0543 out_free:
0544     kfree(buf);
0545     return rc;
0546 }
0547 
0548 static const struct file_operations dfs_naqp_ops = {
0549     .open       = qla_dfs_naqp_open,
0550     .read       = seq_read,
0551     .llseek     = seq_lseek,
0552     .release    = single_release,
0553     .write      = qla_dfs_naqp_write,
0554 };
0555 
0556 
0557 int
0558 qla2x00_dfs_setup(scsi_qla_host_t *vha)
0559 {
0560     struct qla_hw_data *ha = vha->hw;
0561 
0562     if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
0563         !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
0564         goto out;
0565     if (!ha->fce)
0566         goto out;
0567 
0568     if (qla2x00_dfs_root)
0569         goto create_dir;
0570 
0571     atomic_set(&qla2x00_dfs_root_count, 0);
0572     qla2x00_dfs_root = debugfs_create_dir(QLA2XXX_DRIVER_NAME, NULL);
0573 
0574 create_dir:
0575     if (ha->dfs_dir)
0576         goto create_nodes;
0577 
0578     mutex_init(&ha->fce_mutex);
0579     ha->dfs_dir = debugfs_create_dir(vha->host_str, qla2x00_dfs_root);
0580 
0581     atomic_inc(&qla2x00_dfs_root_count);
0582 
0583 create_nodes:
0584     ha->dfs_fw_resource_cnt = debugfs_create_file("fw_resource_count",
0585         S_IRUSR, ha->dfs_dir, vha, &qla_dfs_fw_resource_cnt_fops);
0586 
0587     ha->dfs_tgt_counters = debugfs_create_file("tgt_counters", S_IRUSR,
0588         ha->dfs_dir, vha, &qla_dfs_tgt_counters_fops);
0589 
0590     ha->tgt.dfs_tgt_port_database = debugfs_create_file("tgt_port_database",
0591         S_IRUSR,  ha->dfs_dir, vha, &qla2x00_dfs_tgt_port_database_fops);
0592 
0593     ha->dfs_fce = debugfs_create_file("fce", S_IRUSR, ha->dfs_dir, vha,
0594         &dfs_fce_ops);
0595 
0596     ha->tgt.dfs_tgt_sess = debugfs_create_file("tgt_sess",
0597         S_IRUSR, ha->dfs_dir, vha, &qla2x00_dfs_tgt_sess_fops);
0598 
0599     if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha)) {
0600         ha->tgt.dfs_naqp = debugfs_create_file("naqp",
0601             0400, ha->dfs_dir, vha, &dfs_naqp_ops);
0602         if (!ha->tgt.dfs_naqp) {
0603             ql_log(ql_log_warn, vha, 0xd011,
0604                    "Unable to create debugFS naqp node.\n");
0605             goto out;
0606         }
0607     }
0608     vha->dfs_rport_root = debugfs_create_dir("rports", ha->dfs_dir);
0609     if (!vha->dfs_rport_root) {
0610         ql_log(ql_log_warn, vha, 0xd012,
0611                "Unable to create debugFS rports node.\n");
0612         goto out;
0613     }
0614 out:
0615     return 0;
0616 }
0617 
0618 int
0619 qla2x00_dfs_remove(scsi_qla_host_t *vha)
0620 {
0621     struct qla_hw_data *ha = vha->hw;
0622 
0623     if (ha->tgt.dfs_naqp) {
0624         debugfs_remove(ha->tgt.dfs_naqp);
0625         ha->tgt.dfs_naqp = NULL;
0626     }
0627 
0628     if (ha->tgt.dfs_tgt_sess) {
0629         debugfs_remove(ha->tgt.dfs_tgt_sess);
0630         ha->tgt.dfs_tgt_sess = NULL;
0631     }
0632 
0633     if (ha->tgt.dfs_tgt_port_database) {
0634         debugfs_remove(ha->tgt.dfs_tgt_port_database);
0635         ha->tgt.dfs_tgt_port_database = NULL;
0636     }
0637 
0638     if (ha->dfs_fw_resource_cnt) {
0639         debugfs_remove(ha->dfs_fw_resource_cnt);
0640         ha->dfs_fw_resource_cnt = NULL;
0641     }
0642 
0643     if (ha->dfs_tgt_counters) {
0644         debugfs_remove(ha->dfs_tgt_counters);
0645         ha->dfs_tgt_counters = NULL;
0646     }
0647 
0648     if (ha->dfs_fce) {
0649         debugfs_remove(ha->dfs_fce);
0650         ha->dfs_fce = NULL;
0651     }
0652 
0653     if (vha->dfs_rport_root) {
0654         debugfs_remove_recursive(vha->dfs_rport_root);
0655         vha->dfs_rport_root = NULL;
0656     }
0657 
0658     if (ha->dfs_dir) {
0659         debugfs_remove(ha->dfs_dir);
0660         ha->dfs_dir = NULL;
0661         atomic_dec(&qla2x00_dfs_root_count);
0662     }
0663 
0664     if (atomic_read(&qla2x00_dfs_root_count) == 0 &&
0665         qla2x00_dfs_root) {
0666         debugfs_remove(qla2x00_dfs_root);
0667         qla2x00_dfs_root = NULL;
0668     }
0669 
0670     return 0;
0671 }