Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 // Copyright 2014 Cisco Systems, Inc.  All rights reserved.
0003 
0004 #include <linux/module.h>
0005 #include <linux/errno.h>
0006 #include <linux/debugfs.h>
0007 
0008 #include "snic.h"
0009 
0010 /*
0011  * snic_debugfs_init - Initialize debugfs for snic debug logging
0012  *
0013  * Description:
0014  * When Debugfs is configured this routine sets up fnic debugfs
0015  * filesystem. If not already created. this routine will crate the
0016  * fnic directory and statistics directory for trace buffer and
0017  * stats logging
0018  */
0019 void snic_debugfs_init(void)
0020 {
0021     snic_glob->trc_root = debugfs_create_dir("snic", NULL);
0022 
0023     snic_glob->stats_root = debugfs_create_dir("statistics",
0024                            snic_glob->trc_root);
0025 }
0026 
0027 /*
0028  * snic_debugfs_term - Tear down debugfs intrastructure
0029  *
0030  * Description:
0031  * When Debufs is configured this routine removes debugfs file system
0032  * elements that are specific to snic
0033  */
0034 void
0035 snic_debugfs_term(void)
0036 {
0037     debugfs_remove(snic_glob->stats_root);
0038     snic_glob->stats_root = NULL;
0039 
0040     debugfs_remove(snic_glob->trc_root);
0041     snic_glob->trc_root = NULL;
0042 }
0043 
0044 /*
0045  * snic_reset_stats_open - Open the reset_stats file
0046  */
0047 static int
0048 snic_reset_stats_open(struct inode *inode, struct file *filp)
0049 {
0050     SNIC_BUG_ON(!inode->i_private);
0051     filp->private_data = inode->i_private;
0052 
0053     return 0;
0054 }
0055 
0056 /*
0057  * snic_reset_stats_read - Read a reset_stats debugfs file
0058  * @filp: The file pointer to read from.
0059  * @ubuf: The buffer tocopy the data to.
0060  * @cnt: The number of bytes to read.
0061  * @ppos: The position in the file to start reading frm.
0062  *
0063  * Description:
0064  * This routine reads value of variable reset_stats
0065  * and stores into local @buf. It will start reading file @ppos and
0066  * copy up to @cnt of data to @ubuf from @buf.
0067  *
0068  * Returns:
0069  * This function returns the amount of data that was read.
0070  */
0071 static ssize_t
0072 snic_reset_stats_read(struct file *filp,
0073               char __user *ubuf,
0074               size_t cnt,
0075               loff_t *ppos)
0076 {
0077     struct snic *snic = (struct snic *) filp->private_data;
0078     char buf[64];
0079     int len;
0080 
0081     len = sprintf(buf, "%u\n", snic->reset_stats);
0082 
0083     return simple_read_from_buffer(ubuf, cnt, ppos, buf, len);
0084 }
0085 
0086 /*
0087  * snic_reset_stats_write - Write to reset_stats debugfs file
0088  * @filp: The file pointer to write from
0089  * @ubuf: The buffer to copy the data from.
0090  * @cnt: The number of bytes to write.
0091  * @ppos: The position in the file to start writing to.
0092  *
0093  * Description:
0094  * This routine writes data from user buffer @ubuf to buffer @buf and
0095  * resets cumulative stats of snic.
0096  *
0097  * Returns:
0098  * This function returns the amount of data that was written.
0099  */
0100 static ssize_t
0101 snic_reset_stats_write(struct file *filp,
0102                const char __user *ubuf,
0103                size_t cnt,
0104                loff_t *ppos)
0105 {
0106     struct snic *snic = (struct snic *) filp->private_data;
0107     struct snic_stats *stats = &snic->s_stats;
0108     u64 *io_stats_p = (u64 *) &stats->io;
0109     u64 *fw_stats_p = (u64 *) &stats->fw;
0110     char buf[64];
0111     unsigned long val;
0112     int ret;
0113 
0114     if (cnt >= sizeof(buf))
0115         return -EINVAL;
0116 
0117     if (copy_from_user(&buf, ubuf, cnt))
0118         return -EFAULT;
0119 
0120     buf[cnt] = '\0';
0121 
0122     ret = kstrtoul(buf, 10, &val);
0123     if (ret < 0)
0124         return ret;
0125 
0126     snic->reset_stats = val;
0127 
0128     if (snic->reset_stats) {
0129         /* Skip variable is used to avoid descrepancies to Num IOs
0130          * and IO Completions stats. Skip incrementing No IO Compls
0131          * for pending active IOs after reset_stats
0132          */
0133         atomic64_set(&snic->io_cmpl_skip,
0134                  atomic64_read(&stats->io.active));
0135         memset(&stats->abts, 0, sizeof(struct snic_abort_stats));
0136         memset(&stats->reset, 0, sizeof(struct snic_reset_stats));
0137         memset(&stats->misc, 0, sizeof(struct snic_misc_stats));
0138         memset(io_stats_p+1,
0139             0,
0140             sizeof(struct snic_io_stats) - sizeof(u64));
0141         memset(fw_stats_p+1,
0142             0,
0143             sizeof(struct snic_fw_stats) - sizeof(u64));
0144     }
0145 
0146     (*ppos)++;
0147 
0148     SNIC_HOST_INFO(snic->shost, "Reset Op: Driver statistics.\n");
0149 
0150     return cnt;
0151 }
0152 
0153 static int
0154 snic_reset_stats_release(struct inode *inode, struct file *filp)
0155 {
0156     filp->private_data = NULL;
0157 
0158     return 0;
0159 }
0160 
0161 /*
0162  * snic_stats_show - Formats and prints per host specific driver stats.
0163  */
0164 static int
0165 snic_stats_show(struct seq_file *sfp, void *data)
0166 {
0167     struct snic *snic = (struct snic *) sfp->private;
0168     struct snic_stats *stats = &snic->s_stats;
0169     struct timespec64 last_isr_tms, last_ack_tms;
0170     u64 maxio_tm;
0171     int i;
0172 
0173     /* Dump IO Stats */
0174     seq_printf(sfp,
0175            "------------------------------------------\n"
0176            "\t\t IO Statistics\n"
0177            "------------------------------------------\n");
0178 
0179     maxio_tm = (u64) atomic64_read(&stats->io.max_time);
0180     seq_printf(sfp,
0181            "Active IOs                  : %lld\n"
0182            "Max Active IOs              : %lld\n"
0183            "Total IOs                   : %lld\n"
0184            "IOs Completed               : %lld\n"
0185            "IOs Failed                  : %lld\n"
0186            "IOs Not Found               : %lld\n"
0187            "Memory Alloc Failures       : %lld\n"
0188            "REQs Null                   : %lld\n"
0189            "SCSI Cmd Pointers Null      : %lld\n"
0190            "Max SGL for any IO          : %lld\n"
0191            "Max IO Size                 : %lld Sectors\n"
0192            "Max Queuing Time            : %lld\n"
0193            "Max Completion Time         : %lld\n"
0194            "Max IO Process Time(FW)     : %lld (%u msec)\n",
0195            (u64) atomic64_read(&stats->io.active),
0196            (u64) atomic64_read(&stats->io.max_active),
0197            (u64) atomic64_read(&stats->io.num_ios),
0198            (u64) atomic64_read(&stats->io.compl),
0199            (u64) atomic64_read(&stats->io.fail),
0200            (u64) atomic64_read(&stats->io.io_not_found),
0201            (u64) atomic64_read(&stats->io.alloc_fail),
0202            (u64) atomic64_read(&stats->io.req_null),
0203            (u64) atomic64_read(&stats->io.sc_null),
0204            (u64) atomic64_read(&stats->io.max_sgl),
0205            (u64) atomic64_read(&stats->io.max_io_sz),
0206            (u64) atomic64_read(&stats->io.max_qtime),
0207            (u64) atomic64_read(&stats->io.max_cmpl_time),
0208            maxio_tm,
0209            jiffies_to_msecs(maxio_tm));
0210 
0211     seq_puts(sfp, "\nSGL Counters\n");
0212 
0213     for (i = 0; i < SNIC_MAX_SG_DESC_CNT; i++) {
0214         seq_printf(sfp,
0215                "%10lld ",
0216                (u64) atomic64_read(&stats->io.sgl_cnt[i]));
0217 
0218         if ((i + 1) % 8 == 0)
0219             seq_puts(sfp, "\n");
0220     }
0221 
0222     /* Dump Abort Stats */
0223     seq_printf(sfp,
0224            "\n-------------------------------------------\n"
0225            "\t\t Abort Statistics\n"
0226            "---------------------------------------------\n");
0227 
0228     seq_printf(sfp,
0229            "Aborts                      : %lld\n"
0230            "Aborts Fail                 : %lld\n"
0231            "Aborts Driver Timeout       : %lld\n"
0232            "Abort FW Timeout            : %lld\n"
0233            "Abort IO NOT Found          : %lld\n"
0234            "Abort Queuing Failed        : %lld\n",
0235            (u64) atomic64_read(&stats->abts.num),
0236            (u64) atomic64_read(&stats->abts.fail),
0237            (u64) atomic64_read(&stats->abts.drv_tmo),
0238            (u64) atomic64_read(&stats->abts.fw_tmo),
0239            (u64) atomic64_read(&stats->abts.io_not_found),
0240            (u64) atomic64_read(&stats->abts.q_fail));
0241 
0242     /* Dump Reset Stats */
0243     seq_printf(sfp,
0244            "\n-------------------------------------------\n"
0245            "\t\t Reset Statistics\n"
0246            "---------------------------------------------\n");
0247 
0248     seq_printf(sfp,
0249            "HBA Resets                  : %lld\n"
0250            "HBA Reset Cmpls             : %lld\n"
0251            "HBA Reset Fail              : %lld\n",
0252            (u64) atomic64_read(&stats->reset.hba_resets),
0253            (u64) atomic64_read(&stats->reset.hba_reset_cmpl),
0254            (u64) atomic64_read(&stats->reset.hba_reset_fail));
0255 
0256     /* Dump Firmware Stats */
0257     seq_printf(sfp,
0258            "\n-------------------------------------------\n"
0259            "\t\t Firmware Statistics\n"
0260            "---------------------------------------------\n");
0261 
0262     seq_printf(sfp,
0263         "Active FW Requests             : %lld\n"
0264         "Max FW Requests                : %lld\n"
0265         "FW Out Of Resource Errs        : %lld\n"
0266         "FW IO Errors                   : %lld\n"
0267         "FW SCSI Errors                 : %lld\n",
0268         (u64) atomic64_read(&stats->fw.actv_reqs),
0269         (u64) atomic64_read(&stats->fw.max_actv_reqs),
0270         (u64) atomic64_read(&stats->fw.out_of_res),
0271         (u64) atomic64_read(&stats->fw.io_errs),
0272         (u64) atomic64_read(&stats->fw.scsi_errs));
0273 
0274 
0275     /* Dump Miscellenous Stats */
0276     seq_printf(sfp,
0277            "\n---------------------------------------------\n"
0278            "\t\t Other Statistics\n"
0279            "\n---------------------------------------------\n");
0280 
0281     jiffies_to_timespec64(stats->misc.last_isr_time, &last_isr_tms);
0282     jiffies_to_timespec64(stats->misc.last_ack_time, &last_ack_tms);
0283 
0284     seq_printf(sfp,
0285            "Last ISR Time               : %llu (%8llu.%09lu)\n"
0286            "Last Ack Time               : %llu (%8llu.%09lu)\n"
0287            "Ack ISRs                    : %llu\n"
0288            "IO Cmpl ISRs                : %llu\n"
0289            "Err Notify ISRs             : %llu\n"
0290            "Max CQ Entries              : %lld\n"
0291            "Data Count Mismatch         : %lld\n"
0292            "IOs w/ Timeout Status       : %lld\n"
0293            "IOs w/ Aborted Status       : %lld\n"
0294            "IOs w/ SGL Invalid Stat     : %lld\n"
0295            "WQ Desc Alloc Fail          : %lld\n"
0296            "Queue Full                  : %lld\n"
0297            "Queue Ramp Up               : %lld\n"
0298            "Queue Ramp Down             : %lld\n"
0299            "Queue Last Queue Depth      : %lld\n"
0300            "Target Not Ready            : %lld\n",
0301            (u64) stats->misc.last_isr_time,
0302            last_isr_tms.tv_sec, last_isr_tms.tv_nsec,
0303            (u64)stats->misc.last_ack_time,
0304            last_ack_tms.tv_sec, last_ack_tms.tv_nsec,
0305            (u64) atomic64_read(&stats->misc.ack_isr_cnt),
0306            (u64) atomic64_read(&stats->misc.cmpl_isr_cnt),
0307            (u64) atomic64_read(&stats->misc.errnotify_isr_cnt),
0308            (u64) atomic64_read(&stats->misc.max_cq_ents),
0309            (u64) atomic64_read(&stats->misc.data_cnt_mismat),
0310            (u64) atomic64_read(&stats->misc.io_tmo),
0311            (u64) atomic64_read(&stats->misc.io_aborted),
0312            (u64) atomic64_read(&stats->misc.sgl_inval),
0313            (u64) atomic64_read(&stats->misc.wq_alloc_fail),
0314            (u64) atomic64_read(&stats->misc.qfull),
0315            (u64) atomic64_read(&stats->misc.qsz_rampup),
0316            (u64) atomic64_read(&stats->misc.qsz_rampdown),
0317            (u64) atomic64_read(&stats->misc.last_qsz),
0318            (u64) atomic64_read(&stats->misc.tgt_not_rdy));
0319 
0320     return 0;
0321 }
0322 
0323 DEFINE_SHOW_ATTRIBUTE(snic_stats);
0324 
0325 static const struct file_operations snic_reset_stats_fops = {
0326     .owner = THIS_MODULE,
0327     .open = snic_reset_stats_open,
0328     .read = snic_reset_stats_read,
0329     .write = snic_reset_stats_write,
0330     .release = snic_reset_stats_release,
0331 };
0332 
0333 /*
0334  * snic_stats_init - Initialize stats struct and create stats file
0335  * per snic
0336  *
0337  * Description:
0338  * When debugfs is cofigured this routine sets up the stats file per snic
0339  * It will create file stats and reset_stats under statistics/host# directory
0340  * to log per snic stats
0341  */
0342 void snic_stats_debugfs_init(struct snic *snic)
0343 {
0344     char name[16];
0345 
0346     snprintf(name, sizeof(name), "host%d", snic->shost->host_no);
0347 
0348     snic->stats_host = debugfs_create_dir(name, snic_glob->stats_root);
0349 
0350     snic->stats_file = debugfs_create_file("stats", S_IFREG|S_IRUGO,
0351                            snic->stats_host, snic,
0352                            &snic_stats_fops);
0353 
0354     snic->reset_stats_file = debugfs_create_file("reset_stats",
0355                              S_IFREG|S_IRUGO|S_IWUSR,
0356                              snic->stats_host, snic,
0357                              &snic_reset_stats_fops);
0358 }
0359 
0360 /*
0361  * snic_stats_debugfs_remove - Tear down debugfs infrastructure of stats
0362  *
0363  * Description:
0364  * When Debufs is configured this routine removes debugfs file system
0365  * elements that are specific to to snic stats
0366  */
0367 void
0368 snic_stats_debugfs_remove(struct snic *snic)
0369 {
0370     debugfs_remove(snic->stats_file);
0371     snic->stats_file = NULL;
0372 
0373     debugfs_remove(snic->reset_stats_file);
0374     snic->reset_stats_file = NULL;
0375 
0376     debugfs_remove(snic->stats_host);
0377     snic->stats_host = NULL;
0378 }
0379 
0380 /* Trace Facility related API */
0381 static void *
0382 snic_trc_seq_start(struct seq_file *sfp, loff_t *pos)
0383 {
0384     return &snic_glob->trc;
0385 }
0386 
0387 static void *
0388 snic_trc_seq_next(struct seq_file *sfp, void *data, loff_t *pos)
0389 {
0390     return NULL;
0391 }
0392 
0393 static void
0394 snic_trc_seq_stop(struct seq_file *sfp, void *data)
0395 {
0396 }
0397 
0398 #define SNIC_TRC_PBLEN  256
0399 static int
0400 snic_trc_seq_show(struct seq_file *sfp, void *data)
0401 {
0402     char buf[SNIC_TRC_PBLEN];
0403 
0404     if (snic_get_trc_data(buf, SNIC_TRC_PBLEN) > 0)
0405         seq_printf(sfp, "%s\n", buf);
0406 
0407     return 0;
0408 }
0409 
0410 static const struct seq_operations snic_trc_sops = {
0411     .start  = snic_trc_seq_start,
0412     .next   = snic_trc_seq_next,
0413     .stop   = snic_trc_seq_stop,
0414     .show   = snic_trc_seq_show,
0415 };
0416 
0417 DEFINE_SEQ_ATTRIBUTE(snic_trc);
0418 
0419 #define TRC_ENABLE_FILE "tracing_enable"
0420 #define TRC_FILE    "trace"
0421 /*
0422  * snic_trc_debugfs_init : creates trace/tracing_enable files for trace
0423  * under debugfs
0424  */
0425 void snic_trc_debugfs_init(void)
0426 {
0427     debugfs_create_bool(TRC_ENABLE_FILE, S_IFREG | S_IRUGO | S_IWUSR,
0428                 snic_glob->trc_root, &snic_glob->trc.enable);
0429 
0430     debugfs_create_file(TRC_FILE, S_IFREG | S_IRUGO | S_IWUSR,
0431                 snic_glob->trc_root, NULL, &snic_trc_fops);
0432 }
0433 
0434 /*
0435  * snic_trc_debugfs_term : cleans up the files created for trace under debugfs
0436  */
0437 void
0438 snic_trc_debugfs_term(void)
0439 {
0440     debugfs_remove(debugfs_lookup(TRC_FILE, snic_glob->trc_root));
0441     debugfs_remove(debugfs_lookup(TRC_ENABLE_FILE, snic_glob->trc_root));
0442 }