Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  *  QLogic FCoE Offload Driver
0004  *  Copyright (c) 2016-2018 QLogic Corporation
0005  */
0006 #ifdef CONFIG_DEBUG_FS
0007 
0008 #include <linux/uaccess.h>
0009 #include <linux/debugfs.h>
0010 #include <linux/module.h>
0011 
0012 #include "qedf.h"
0013 #include "qedf_dbg.h"
0014 
0015 static struct dentry *qedf_dbg_root;
0016 
0017 /*
0018  * qedf_dbg_host_init - setup the debugfs file for the pf
0019  */
0020 void
0021 qedf_dbg_host_init(struct qedf_dbg_ctx *qedf,
0022             const struct qedf_debugfs_ops *dops,
0023             const struct file_operations *fops)
0024 {
0025     char host_dirname[32];
0026 
0027     QEDF_INFO(qedf, QEDF_LOG_DEBUGFS, "Creating debugfs host node\n");
0028     /* create pf dir */
0029     sprintf(host_dirname, "host%u", qedf->host_no);
0030     qedf->bdf_dentry = debugfs_create_dir(host_dirname, qedf_dbg_root);
0031 
0032     /* create debugfs files */
0033     while (dops) {
0034         if (!(dops->name))
0035             break;
0036 
0037         debugfs_create_file(dops->name, 0600, qedf->bdf_dentry, qedf,
0038                     fops);
0039         dops++;
0040         fops++;
0041     }
0042 }
0043 
0044 /*
0045  * qedf_dbg_host_exit - clear out the pf's debugfs entries
0046  */
0047 void
0048 qedf_dbg_host_exit(struct qedf_dbg_ctx *qedf_dbg)
0049 {
0050     QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "Destroying debugfs host "
0051            "entry\n");
0052     /* remove debugfs  entries of this PF */
0053     debugfs_remove_recursive(qedf_dbg->bdf_dentry);
0054     qedf_dbg->bdf_dentry = NULL;
0055 }
0056 
0057 /*
0058  * qedf_dbg_init - start up debugfs for the driver
0059  */
0060 void
0061 qedf_dbg_init(char *drv_name)
0062 {
0063     QEDF_INFO(NULL, QEDF_LOG_DEBUGFS, "Creating debugfs root node\n");
0064 
0065     /* create qed dir in root of debugfs. NULL means debugfs root */
0066     qedf_dbg_root = debugfs_create_dir(drv_name, NULL);
0067 }
0068 
0069 /*
0070  * qedf_dbg_exit - clean out the driver's debugfs entries
0071  */
0072 void
0073 qedf_dbg_exit(void)
0074 {
0075     QEDF_INFO(NULL, QEDF_LOG_DEBUGFS, "Destroying debugfs root "
0076            "entry\n");
0077 
0078     /* remove qed dir in root of debugfs */
0079     debugfs_remove_recursive(qedf_dbg_root);
0080     qedf_dbg_root = NULL;
0081 }
0082 
0083 const struct qedf_debugfs_ops qedf_debugfs_ops[] = {
0084     { "fp_int", NULL },
0085     { "io_trace", NULL },
0086     { "debug", NULL },
0087     { "stop_io_on_error", NULL},
0088     { "driver_stats", NULL},
0089     { "clear_stats", NULL},
0090     { "offload_stats", NULL},
0091     /* This must be last */
0092     { NULL, NULL }
0093 };
0094 
0095 DECLARE_PER_CPU(struct qedf_percpu_iothread_s, qedf_percpu_iothreads);
0096 
0097 static ssize_t
0098 qedf_dbg_fp_int_cmd_read(struct file *filp, char __user *buffer, size_t count,
0099              loff_t *ppos)
0100 {
0101     size_t cnt = 0;
0102     int id;
0103     struct qedf_fastpath *fp = NULL;
0104     struct qedf_dbg_ctx *qedf_dbg =
0105                 (struct qedf_dbg_ctx *)filp->private_data;
0106     struct qedf_ctx *qedf = container_of(qedf_dbg,
0107         struct qedf_ctx, dbg_ctx);
0108 
0109     QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n");
0110 
0111     cnt = sprintf(buffer, "\nFastpath I/O completions\n\n");
0112 
0113     for (id = 0; id < qedf->num_queues; id++) {
0114         fp = &(qedf->fp_array[id]);
0115         if (fp->sb_id == QEDF_SB_ID_NULL)
0116             continue;
0117         cnt += sprintf((buffer + cnt), "#%d: %lu\n", id,
0118                    fp->completions);
0119     }
0120 
0121     cnt = min_t(int, count, cnt - *ppos);
0122     *ppos += cnt;
0123     return cnt;
0124 }
0125 
0126 static ssize_t
0127 qedf_dbg_fp_int_cmd_write(struct file *filp, const char __user *buffer,
0128               size_t count, loff_t *ppos)
0129 {
0130     if (!count || *ppos)
0131         return 0;
0132 
0133     return count;
0134 }
0135 
0136 static ssize_t
0137 qedf_dbg_debug_cmd_read(struct file *filp, char __user *buffer, size_t count,
0138             loff_t *ppos)
0139 {
0140     int cnt;
0141     struct qedf_dbg_ctx *qedf_dbg =
0142                 (struct qedf_dbg_ctx *)filp->private_data;
0143 
0144     QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "debug mask=0x%x\n", qedf_debug);
0145     cnt = sprintf(buffer, "debug mask = 0x%x\n", qedf_debug);
0146 
0147     cnt = min_t(int, count, cnt - *ppos);
0148     *ppos += cnt;
0149     return cnt;
0150 }
0151 
0152 static ssize_t
0153 qedf_dbg_debug_cmd_write(struct file *filp, const char __user *buffer,
0154              size_t count, loff_t *ppos)
0155 {
0156     uint32_t val;
0157     void *kern_buf;
0158     int rval;
0159     struct qedf_dbg_ctx *qedf_dbg =
0160         (struct qedf_dbg_ctx *)filp->private_data;
0161 
0162     if (!count || *ppos)
0163         return 0;
0164 
0165     kern_buf = memdup_user(buffer, count);
0166     if (IS_ERR(kern_buf))
0167         return PTR_ERR(kern_buf);
0168 
0169     rval = kstrtouint(kern_buf, 10, &val);
0170     kfree(kern_buf);
0171     if (rval)
0172         return rval;
0173 
0174     if (val == 1)
0175         qedf_debug = QEDF_DEFAULT_LOG_MASK;
0176     else
0177         qedf_debug = val;
0178 
0179     QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "Setting debug=0x%x.\n", val);
0180     return count;
0181 }
0182 
0183 static ssize_t
0184 qedf_dbg_stop_io_on_error_cmd_read(struct file *filp, char __user *buffer,
0185                    size_t count, loff_t *ppos)
0186 {
0187     int cnt;
0188     struct qedf_dbg_ctx *qedf_dbg =
0189                 (struct qedf_dbg_ctx *)filp->private_data;
0190     struct qedf_ctx *qedf = container_of(qedf_dbg,
0191         struct qedf_ctx, dbg_ctx);
0192 
0193     QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n");
0194     cnt = sprintf(buffer, "%s\n",
0195         qedf->stop_io_on_error ? "true" : "false");
0196 
0197     cnt = min_t(int, count, cnt - *ppos);
0198     *ppos += cnt;
0199     return cnt;
0200 }
0201 
0202 static ssize_t
0203 qedf_dbg_stop_io_on_error_cmd_write(struct file *filp,
0204                     const char __user *buffer, size_t count,
0205                     loff_t *ppos)
0206 {
0207     void *kern_buf;
0208     struct qedf_dbg_ctx *qedf_dbg =
0209                 (struct qedf_dbg_ctx *)filp->private_data;
0210     struct qedf_ctx *qedf = container_of(qedf_dbg, struct qedf_ctx,
0211         dbg_ctx);
0212 
0213     QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n");
0214 
0215     if (!count || *ppos)
0216         return 0;
0217 
0218     kern_buf = memdup_user(buffer, 6);
0219     if (IS_ERR(kern_buf))
0220         return PTR_ERR(kern_buf);
0221 
0222     if (strncmp(kern_buf, "false", 5) == 0)
0223         qedf->stop_io_on_error = false;
0224     else if (strncmp(kern_buf, "true", 4) == 0)
0225         qedf->stop_io_on_error = true;
0226     else if (strncmp(kern_buf, "now", 3) == 0)
0227         /* Trigger from user to stop all I/O on this host */
0228         set_bit(QEDF_DBG_STOP_IO, &qedf->flags);
0229 
0230     kfree(kern_buf);
0231     return count;
0232 }
0233 
0234 static int
0235 qedf_io_trace_show(struct seq_file *s, void *unused)
0236 {
0237     int i, idx = 0;
0238     struct qedf_ctx *qedf = s->private;
0239     struct qedf_dbg_ctx *qedf_dbg = &qedf->dbg_ctx;
0240     struct qedf_io_log *io_log;
0241     unsigned long flags;
0242 
0243     if (!qedf_io_tracing) {
0244         seq_puts(s, "I/O tracing not enabled.\n");
0245         goto out;
0246     }
0247 
0248     QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n");
0249 
0250     spin_lock_irqsave(&qedf->io_trace_lock, flags);
0251     idx = qedf->io_trace_idx;
0252     for (i = 0; i < QEDF_IO_TRACE_SIZE; i++) {
0253         io_log = &qedf->io_trace_buf[idx];
0254         seq_printf(s, "%d:", io_log->direction);
0255         seq_printf(s, "0x%x:", io_log->task_id);
0256         seq_printf(s, "0x%06x:", io_log->port_id);
0257         seq_printf(s, "%d:", io_log->lun);
0258         seq_printf(s, "0x%02x:", io_log->op);
0259         seq_printf(s, "0x%02x%02x%02x%02x:", io_log->lba[0],
0260             io_log->lba[1], io_log->lba[2], io_log->lba[3]);
0261         seq_printf(s, "%d:", io_log->bufflen);
0262         seq_printf(s, "%d:", io_log->sg_count);
0263         seq_printf(s, "0x%08x:", io_log->result);
0264         seq_printf(s, "%lu:", io_log->jiffies);
0265         seq_printf(s, "%d:", io_log->refcount);
0266         seq_printf(s, "%d:", io_log->req_cpu);
0267         seq_printf(s, "%d:", io_log->int_cpu);
0268         seq_printf(s, "%d:", io_log->rsp_cpu);
0269         seq_printf(s, "%d\n", io_log->sge_type);
0270 
0271         idx++;
0272         if (idx == QEDF_IO_TRACE_SIZE)
0273             idx = 0;
0274     }
0275     spin_unlock_irqrestore(&qedf->io_trace_lock, flags);
0276 
0277 out:
0278     return 0;
0279 }
0280 
0281 static int
0282 qedf_dbg_io_trace_open(struct inode *inode, struct file *file)
0283 {
0284     struct qedf_dbg_ctx *qedf_dbg = inode->i_private;
0285     struct qedf_ctx *qedf = container_of(qedf_dbg,
0286         struct qedf_ctx, dbg_ctx);
0287 
0288     return single_open(file, qedf_io_trace_show, qedf);
0289 }
0290 
0291 /* Based on fip_state enum from libfcoe.h */
0292 static char *fip_state_names[] = {
0293     "FIP_ST_DISABLED",
0294     "FIP_ST_LINK_WAIT",
0295     "FIP_ST_AUTO",
0296     "FIP_ST_NON_FIP",
0297     "FIP_ST_ENABLED",
0298     "FIP_ST_VNMP_START",
0299     "FIP_ST_VNMP_PROBE1",
0300     "FIP_ST_VNMP_PROBE2",
0301     "FIP_ST_VNMP_CLAIM",
0302     "FIP_ST_VNMP_UP",
0303 };
0304 
0305 /* Based on fc_rport_state enum from libfc.h */
0306 static char *fc_rport_state_names[] = {
0307     "RPORT_ST_INIT",
0308     "RPORT_ST_FLOGI",
0309     "RPORT_ST_PLOGI_WAIT",
0310     "RPORT_ST_PLOGI",
0311     "RPORT_ST_PRLI",
0312     "RPORT_ST_RTV",
0313     "RPORT_ST_READY",
0314     "RPORT_ST_ADISC",
0315     "RPORT_ST_DELETE",
0316 };
0317 
0318 static int
0319 qedf_driver_stats_show(struct seq_file *s, void *unused)
0320 {
0321     struct qedf_ctx *qedf = s->private;
0322     struct qedf_rport *fcport;
0323     struct fc_rport_priv *rdata;
0324 
0325     seq_printf(s, "Host WWNN/WWPN: %016llx/%016llx\n",
0326            qedf->wwnn, qedf->wwpn);
0327     seq_printf(s, "Host NPortID: %06x\n", qedf->lport->port_id);
0328     seq_printf(s, "Link State: %s\n", atomic_read(&qedf->link_state) ?
0329         "Up" : "Down");
0330     seq_printf(s, "Logical Link State: %s\n", qedf->lport->link_up ?
0331         "Up" : "Down");
0332     seq_printf(s, "FIP state: %s\n", fip_state_names[qedf->ctlr.state]);
0333     seq_printf(s, "FIP VLAN ID: %d\n", qedf->vlan_id & 0xfff);
0334     seq_printf(s, "FIP 802.1Q Priority: %d\n", qedf->prio);
0335     if (qedf->ctlr.sel_fcf) {
0336         seq_printf(s, "FCF WWPN: %016llx\n",
0337                qedf->ctlr.sel_fcf->switch_name);
0338         seq_printf(s, "FCF MAC: %pM\n", qedf->ctlr.sel_fcf->fcf_mac);
0339     } else {
0340         seq_puts(s, "FCF not selected\n");
0341     }
0342 
0343     seq_puts(s, "\nSGE stats:\n\n");
0344     seq_printf(s, "cmg_mgr free io_reqs: %d\n",
0345         atomic_read(&qedf->cmd_mgr->free_list_cnt));
0346     seq_printf(s, "slow SGEs: %d\n", qedf->slow_sge_ios);
0347     seq_printf(s, "fast SGEs: %d\n\n", qedf->fast_sge_ios);
0348 
0349     seq_puts(s, "Offloaded ports:\n\n");
0350 
0351     rcu_read_lock();
0352     list_for_each_entry_rcu(fcport, &qedf->fcports, peers) {
0353         rdata = fcport->rdata;
0354         if (rdata == NULL)
0355             continue;
0356         seq_printf(s, "%016llx/%016llx/%06x: state=%s, free_sqes=%d, num_active_ios=%d\n",
0357                rdata->rport->node_name, rdata->rport->port_name,
0358                rdata->ids.port_id,
0359                fc_rport_state_names[rdata->rp_state],
0360                atomic_read(&fcport->free_sqes),
0361                atomic_read(&fcport->num_active_ios));
0362     }
0363     rcu_read_unlock();
0364 
0365     return 0;
0366 }
0367 
0368 static int
0369 qedf_dbg_driver_stats_open(struct inode *inode, struct file *file)
0370 {
0371     struct qedf_dbg_ctx *qedf_dbg = inode->i_private;
0372     struct qedf_ctx *qedf = container_of(qedf_dbg,
0373         struct qedf_ctx, dbg_ctx);
0374 
0375     return single_open(file, qedf_driver_stats_show, qedf);
0376 }
0377 
0378 static ssize_t
0379 qedf_dbg_clear_stats_cmd_read(struct file *filp, char __user *buffer,
0380                    size_t count, loff_t *ppos)
0381 {
0382     int cnt = 0;
0383 
0384     /* Essentially a read stub */
0385     cnt = min_t(int, count, cnt - *ppos);
0386     *ppos += cnt;
0387     return cnt;
0388 }
0389 
0390 static ssize_t
0391 qedf_dbg_clear_stats_cmd_write(struct file *filp,
0392                     const char __user *buffer, size_t count,
0393                     loff_t *ppos)
0394 {
0395     struct qedf_dbg_ctx *qedf_dbg =
0396                 (struct qedf_dbg_ctx *)filp->private_data;
0397     struct qedf_ctx *qedf = container_of(qedf_dbg, struct qedf_ctx,
0398         dbg_ctx);
0399 
0400     QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "Clearing stat counters.\n");
0401 
0402     if (!count || *ppos)
0403         return 0;
0404 
0405     /* Clear stat counters exposed by 'stats' node */
0406     qedf->slow_sge_ios = 0;
0407     qedf->fast_sge_ios = 0;
0408 
0409     return count;
0410 }
0411 
0412 static int
0413 qedf_offload_stats_show(struct seq_file *s, void *unused)
0414 {
0415     struct qedf_ctx *qedf = s->private;
0416     struct qed_fcoe_stats *fw_fcoe_stats;
0417 
0418     fw_fcoe_stats = kmalloc(sizeof(struct qed_fcoe_stats), GFP_KERNEL);
0419     if (!fw_fcoe_stats) {
0420         QEDF_ERR(&(qedf->dbg_ctx), "Could not allocate memory for "
0421             "fw_fcoe_stats.\n");
0422         goto out;
0423     }
0424 
0425     /* Query firmware for offload stats */
0426     qed_ops->get_stats(qedf->cdev, fw_fcoe_stats);
0427 
0428     seq_printf(s, "fcoe_rx_byte_cnt=%llu\n"
0429         "fcoe_rx_data_pkt_cnt=%llu\n"
0430         "fcoe_rx_xfer_pkt_cnt=%llu\n"
0431         "fcoe_rx_other_pkt_cnt=%llu\n"
0432         "fcoe_silent_drop_pkt_cmdq_full_cnt=%u\n"
0433         "fcoe_silent_drop_pkt_crc_error_cnt=%u\n"
0434         "fcoe_silent_drop_pkt_task_invalid_cnt=%u\n"
0435         "fcoe_silent_drop_total_pkt_cnt=%u\n"
0436         "fcoe_silent_drop_pkt_rq_full_cnt=%u\n"
0437         "fcoe_tx_byte_cnt=%llu\n"
0438         "fcoe_tx_data_pkt_cnt=%llu\n"
0439         "fcoe_tx_xfer_pkt_cnt=%llu\n"
0440         "fcoe_tx_other_pkt_cnt=%llu\n",
0441         fw_fcoe_stats->fcoe_rx_byte_cnt,
0442         fw_fcoe_stats->fcoe_rx_data_pkt_cnt,
0443         fw_fcoe_stats->fcoe_rx_xfer_pkt_cnt,
0444         fw_fcoe_stats->fcoe_rx_other_pkt_cnt,
0445         fw_fcoe_stats->fcoe_silent_drop_pkt_cmdq_full_cnt,
0446         fw_fcoe_stats->fcoe_silent_drop_pkt_crc_error_cnt,
0447         fw_fcoe_stats->fcoe_silent_drop_pkt_task_invalid_cnt,
0448         fw_fcoe_stats->fcoe_silent_drop_total_pkt_cnt,
0449         fw_fcoe_stats->fcoe_silent_drop_pkt_rq_full_cnt,
0450         fw_fcoe_stats->fcoe_tx_byte_cnt,
0451         fw_fcoe_stats->fcoe_tx_data_pkt_cnt,
0452         fw_fcoe_stats->fcoe_tx_xfer_pkt_cnt,
0453         fw_fcoe_stats->fcoe_tx_other_pkt_cnt);
0454 
0455     kfree(fw_fcoe_stats);
0456 out:
0457     return 0;
0458 }
0459 
0460 static int
0461 qedf_dbg_offload_stats_open(struct inode *inode, struct file *file)
0462 {
0463     struct qedf_dbg_ctx *qedf_dbg = inode->i_private;
0464     struct qedf_ctx *qedf = container_of(qedf_dbg,
0465         struct qedf_ctx, dbg_ctx);
0466 
0467     return single_open(file, qedf_offload_stats_show, qedf);
0468 }
0469 
0470 const struct file_operations qedf_dbg_fops[] = {
0471     qedf_dbg_fileops(qedf, fp_int),
0472     qedf_dbg_fileops_seq(qedf, io_trace),
0473     qedf_dbg_fileops(qedf, debug),
0474     qedf_dbg_fileops(qedf, stop_io_on_error),
0475     qedf_dbg_fileops_seq(qedf, driver_stats),
0476     qedf_dbg_fileops(qedf, clear_stats),
0477     qedf_dbg_fileops_seq(qedf, offload_stats),
0478     /* This must be last */
0479     { },
0480 };
0481 
0482 #else /* CONFIG_DEBUG_FS */
0483 void qedf_dbg_host_init(struct qedf_dbg_ctx *);
0484 void qedf_dbg_host_exit(struct qedf_dbg_ctx *);
0485 void qedf_dbg_init(char *);
0486 void qedf_dbg_exit(void);
0487 #endif /* CONFIG_DEBUG_FS */