linux/drivers/scsi/snic/snic_debugfs.c
<<
>>
Prefs
   1/*
   2 * Copyright 2014 Cisco Systems, Inc.  All rights reserved.
   3 *
   4 * This program is free software; you may redistribute it and/or modify
   5 * it under the terms of the GNU General Public License as published by
   6 * the Free Software Foundation; version 2 of the License.
   7 *
   8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   9 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  10 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  11 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  12 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  13 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  14 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  15 * SOFTWARE.
  16 */
  17
  18#include <linux/module.h>
  19#include <linux/errno.h>
  20#include <linux/debugfs.h>
  21
  22#include "snic.h"
  23
  24/*
  25 * snic_debugfs_init - Initialize debugfs for snic debug logging
  26 *
  27 * Description:
  28 * When Debugfs is configured this routine sets up fnic debugfs
  29 * filesystem. If not already created. this routine will crate the
  30 * fnic directory and statistics directory for trace buffer and
  31 * stats logging
  32 */
  33
  34int
  35snic_debugfs_init(void)
  36{
  37        int rc = -1;
  38        struct dentry *de = NULL;
  39
  40        de = debugfs_create_dir("snic", NULL);
  41        if (!de) {
  42                SNIC_DBG("Cannot create debugfs root\n");
  43
  44                return rc;
  45        }
  46        snic_glob->trc_root = de;
  47
  48        de = debugfs_create_dir("statistics", snic_glob->trc_root);
  49        if (!de) {
  50                SNIC_DBG("Cannot create Statistics directory\n");
  51
  52                return rc;
  53        }
  54        snic_glob->stats_root = de;
  55
  56        rc = 0;
  57
  58        return rc;
  59} /* end of snic_debugfs_init */
  60
  61/*
  62 * snic_debugfs_term - Tear down debugfs intrastructure
  63 *
  64 * Description:
  65 * When Debufs is configured this routine removes debugfs file system
  66 * elements that are specific to snic
  67 */
  68void
  69snic_debugfs_term(void)
  70{
  71        debugfs_remove(snic_glob->stats_root);
  72        snic_glob->stats_root = NULL;
  73
  74        debugfs_remove(snic_glob->trc_root);
  75        snic_glob->trc_root = NULL;
  76}
  77
  78/*
  79 * snic_reset_stats_open - Open the reset_stats file
  80 */
  81static int
  82snic_reset_stats_open(struct inode *inode, struct file *filp)
  83{
  84        SNIC_BUG_ON(!inode->i_private);
  85        filp->private_data = inode->i_private;
  86
  87        return 0;
  88}
  89
  90/*
  91 * snic_reset_stats_read - Read a reset_stats debugfs file
  92 * @filp: The file pointer to read from.
  93 * @ubuf: The buffer tocopy the data to.
  94 * @cnt: The number of bytes to read.
  95 * @ppos: The position in the file to start reading frm.
  96 *
  97 * Description:
  98 * This routine reads value of variable reset_stats
  99 * and stores into local @buf. It will start reading file @ppos and
 100 * copy up to @cnt of data to @ubuf from @buf.
 101 *
 102 * Returns:
 103 * This function returns the amount of data that was read.
 104 */
 105static ssize_t
 106snic_reset_stats_read(struct file *filp,
 107                      char __user *ubuf,
 108                      size_t cnt,
 109                      loff_t *ppos)
 110{
 111        struct snic *snic = (struct snic *) filp->private_data;
 112        char buf[64];
 113        int len;
 114
 115        len = sprintf(buf, "%u\n", snic->reset_stats);
 116
 117        return simple_read_from_buffer(ubuf, cnt, ppos, buf, len);
 118}
 119
 120/*
 121 * snic_reset_stats_write - Write to reset_stats debugfs file
 122 * @filp: The file pointer to write from
 123 * @ubuf: The buffer to copy the data from.
 124 * @cnt: The number of bytes to write.
 125 * @ppos: The position in the file to start writing to.
 126 *
 127 * Description:
 128 * This routine writes data from user buffer @ubuf to buffer @buf and
 129 * resets cumulative stats of snic.
 130 *
 131 * Returns:
 132 * This function returns the amount of data that was written.
 133 */
 134static ssize_t
 135snic_reset_stats_write(struct file *filp,
 136                       const char __user *ubuf,
 137                       size_t cnt,
 138                       loff_t *ppos)
 139{
 140        struct snic *snic = (struct snic *) filp->private_data;
 141        struct snic_stats *stats = &snic->s_stats;
 142        u64 *io_stats_p = (u64 *) &stats->io;
 143        u64 *fw_stats_p = (u64 *) &stats->fw;
 144        char buf[64];
 145        unsigned long val;
 146        int ret;
 147
 148        if (cnt >= sizeof(buf))
 149                return -EINVAL;
 150
 151        if (copy_from_user(&buf, ubuf, cnt))
 152                return -EFAULT;
 153
 154        buf[cnt] = '\0';
 155
 156        ret = kstrtoul(buf, 10, &val);
 157        if (ret < 0)
 158                return ret;
 159
 160        snic->reset_stats = val;
 161
 162        if (snic->reset_stats) {
 163                /* Skip variable is used to avoid descrepancies to Num IOs
 164                 * and IO Completions stats. Skip incrementing No IO Compls
 165                 * for pending active IOs after reset_stats
 166                 */
 167                atomic64_set(&snic->io_cmpl_skip,
 168                             atomic64_read(&stats->io.active));
 169                memset(&stats->abts, 0, sizeof(struct snic_abort_stats));
 170                memset(&stats->reset, 0, sizeof(struct snic_reset_stats));
 171                memset(&stats->misc, 0, sizeof(struct snic_misc_stats));
 172                memset(io_stats_p+1,
 173                        0,
 174                        sizeof(struct snic_io_stats) - sizeof(u64));
 175                memset(fw_stats_p+1,
 176                        0,
 177                        sizeof(struct snic_fw_stats) - sizeof(u64));
 178        }
 179
 180        (*ppos)++;
 181
 182        SNIC_HOST_INFO(snic->shost, "Reset Op: Driver statistics.\n");
 183
 184        return cnt;
 185}
 186
 187static int
 188snic_reset_stats_release(struct inode *inode, struct file *filp)
 189{
 190        filp->private_data = NULL;
 191
 192        return 0;
 193}
 194
 195/*
 196 * snic_stats_show - Formats and prints per host specific driver stats.
 197 */
 198static int
 199snic_stats_show(struct seq_file *sfp, void *data)
 200{
 201        struct snic *snic = (struct snic *) sfp->private;
 202        struct snic_stats *stats = &snic->s_stats;
 203        struct timespec last_isr_tms, last_ack_tms;
 204        u64 maxio_tm;
 205        int i;
 206
 207        /* Dump IO Stats */
 208        seq_printf(sfp,
 209                   "------------------------------------------\n"
 210                   "\t\t IO Statistics\n"
 211                   "------------------------------------------\n");
 212
 213        maxio_tm = (u64) atomic64_read(&stats->io.max_time);
 214        seq_printf(sfp,
 215                   "Active IOs                  : %lld\n"
 216                   "Max Active IOs              : %lld\n"
 217                   "Total IOs                   : %lld\n"
 218                   "IOs Completed               : %lld\n"
 219                   "IOs Failed                  : %lld\n"
 220                   "IOs Not Found               : %lld\n"
 221                   "Memory Alloc Failures       : %lld\n"
 222                   "REQs Null                   : %lld\n"
 223                   "SCSI Cmd Pointers Null      : %lld\n"
 224                   "Max SGL for any IO          : %lld\n"
 225                   "Max IO Size                 : %lld Sectors\n"
 226                   "Max Queuing Time            : %lld\n"
 227                   "Max Completion Time         : %lld\n"
 228                   "Max IO Process Time(FW)     : %lld (%u msec)\n",
 229                   (u64) atomic64_read(&stats->io.active),
 230                   (u64) atomic64_read(&stats->io.max_active),
 231                   (u64) atomic64_read(&stats->io.num_ios),
 232                   (u64) atomic64_read(&stats->io.compl),
 233                   (u64) atomic64_read(&stats->io.fail),
 234                   (u64) atomic64_read(&stats->io.io_not_found),
 235                   (u64) atomic64_read(&stats->io.alloc_fail),
 236                   (u64) atomic64_read(&stats->io.req_null),
 237                   (u64) atomic64_read(&stats->io.sc_null),
 238                   (u64) atomic64_read(&stats->io.max_sgl),
 239                   (u64) atomic64_read(&stats->io.max_io_sz),
 240                   (u64) atomic64_read(&stats->io.max_qtime),
 241                   (u64) atomic64_read(&stats->io.max_cmpl_time),
 242                   maxio_tm,
 243                   jiffies_to_msecs(maxio_tm));
 244
 245        seq_puts(sfp, "\nSGL Counters\n");
 246
 247        for (i = 0; i < SNIC_MAX_SG_DESC_CNT; i++) {
 248                seq_printf(sfp,
 249                           "%10lld ",
 250                           (u64) atomic64_read(&stats->io.sgl_cnt[i]));
 251
 252                if ((i + 1) % 8 == 0)
 253                        seq_puts(sfp, "\n");
 254        }
 255
 256        /* Dump Abort Stats */
 257        seq_printf(sfp,
 258                   "\n-------------------------------------------\n"
 259                   "\t\t Abort Statistics\n"
 260                   "---------------------------------------------\n");
 261
 262        seq_printf(sfp,
 263                   "Aborts                      : %lld\n"
 264                   "Aborts Fail                 : %lld\n"
 265                   "Aborts Driver Timeout       : %lld\n"
 266                   "Abort FW Timeout            : %lld\n"
 267                   "Abort IO NOT Found          : %lld\n",
 268                   (u64) atomic64_read(&stats->abts.num),
 269                   (u64) atomic64_read(&stats->abts.fail),
 270                   (u64) atomic64_read(&stats->abts.drv_tmo),
 271                   (u64) atomic64_read(&stats->abts.fw_tmo),
 272                   (u64) atomic64_read(&stats->abts.io_not_found));
 273
 274        /* Dump Reset Stats */
 275        seq_printf(sfp,
 276                   "\n-------------------------------------------\n"
 277                   "\t\t Reset Statistics\n"
 278                   "---------------------------------------------\n");
 279
 280        seq_printf(sfp,
 281                   "HBA Resets                  : %lld\n"
 282                   "HBA Reset Cmpls             : %lld\n"
 283                   "HBA Reset Fail              : %lld\n",
 284                   (u64) atomic64_read(&stats->reset.hba_resets),
 285                   (u64) atomic64_read(&stats->reset.hba_reset_cmpl),
 286                   (u64) atomic64_read(&stats->reset.hba_reset_fail));
 287
 288        /* Dump Firmware Stats */
 289        seq_printf(sfp,
 290                   "\n-------------------------------------------\n"
 291                   "\t\t Firmware Statistics\n"
 292                   "---------------------------------------------\n");
 293
 294        seq_printf(sfp,
 295                "Active FW Requests             : %lld\n"
 296                "Max FW Requests                : %lld\n"
 297                "FW Out Of Resource Errs        : %lld\n"
 298                "FW IO Errors                   : %lld\n"
 299                "FW SCSI Errors                 : %lld\n",
 300                (u64) atomic64_read(&stats->fw.actv_reqs),
 301                (u64) atomic64_read(&stats->fw.max_actv_reqs),
 302                (u64) atomic64_read(&stats->fw.out_of_res),
 303                (u64) atomic64_read(&stats->fw.io_errs),
 304                (u64) atomic64_read(&stats->fw.scsi_errs));
 305
 306
 307        /* Dump Miscellenous Stats */
 308        seq_printf(sfp,
 309                   "\n---------------------------------------------\n"
 310                   "\t\t Other Statistics\n"
 311                   "\n---------------------------------------------\n");
 312
 313        jiffies_to_timespec(stats->misc.last_isr_time, &last_isr_tms);
 314        jiffies_to_timespec(stats->misc.last_ack_time, &last_ack_tms);
 315
 316        seq_printf(sfp,
 317                   "Last ISR Time               : %llu (%8lu.%8lu)\n"
 318                   "Last Ack Time               : %llu (%8lu.%8lu)\n"
 319                   "ISRs                        : %llu\n"
 320                   "Max CQ Entries              : %lld\n"
 321                   "Data Count Mismatch         : %lld\n"
 322                   "IOs w/ Timeout Status       : %lld\n"
 323                   "IOs w/ Aborted Status       : %lld\n"
 324                   "IOs w/ SGL Invalid Stat     : %lld\n"
 325                   "WQ Desc Alloc Fail          : %lld\n"
 326                   "Queue Full                  : %lld\n"
 327                   "Target Not Ready            : %lld\n",
 328                   (u64) stats->misc.last_isr_time,
 329                   last_isr_tms.tv_sec, last_isr_tms.tv_nsec,
 330                   (u64)stats->misc.last_ack_time,
 331                   last_ack_tms.tv_sec, last_ack_tms.tv_nsec,
 332                   (u64) atomic64_read(&stats->misc.isr_cnt),
 333                   (u64) atomic64_read(&stats->misc.max_cq_ents),
 334                   (u64) atomic64_read(&stats->misc.data_cnt_mismat),
 335                   (u64) atomic64_read(&stats->misc.io_tmo),
 336                   (u64) atomic64_read(&stats->misc.io_aborted),
 337                   (u64) atomic64_read(&stats->misc.sgl_inval),
 338                   (u64) atomic64_read(&stats->misc.wq_alloc_fail),
 339                   (u64) atomic64_read(&stats->misc.qfull),
 340                   (u64) atomic64_read(&stats->misc.tgt_not_rdy));
 341
 342        return 0;
 343}
 344
 345/*
 346 * snic_stats_open - Open the stats file for specific host
 347 *
 348 * Description:
 349 * This routine opens a debugfs file stats of specific host
 350 */
 351static int
 352snic_stats_open(struct inode *inode, struct file *filp)
 353{
 354        return single_open(filp, snic_stats_show, inode->i_private);
 355}
 356
 357static const struct file_operations snic_stats_fops = {
 358        .owner  = THIS_MODULE,
 359        .open   = snic_stats_open,
 360        .read   = seq_read,
 361        .llseek = seq_lseek,
 362        .release = single_release,
 363};
 364
 365static const struct file_operations snic_reset_stats_fops = {
 366        .owner = THIS_MODULE,
 367        .open = snic_reset_stats_open,
 368        .read = snic_reset_stats_read,
 369        .write = snic_reset_stats_write,
 370        .release = snic_reset_stats_release,
 371};
 372
 373/*
 374 * snic_stats_init - Initialize stats struct and create stats file
 375 * per snic
 376 *
 377 * Description:
 378 * When debugfs is cofigured this routine sets up the stats file per snic
 379 * It will create file stats and reset_stats under statistics/host# directory
 380 * to log per snic stats
 381 */
 382int
 383snic_stats_debugfs_init(struct snic *snic)
 384{
 385        int rc = -1;
 386        char name[16];
 387        struct dentry *de = NULL;
 388
 389        snprintf(name, sizeof(name), "host%d", snic->shost->host_no);
 390        if (!snic_glob->stats_root) {
 391                SNIC_DBG("snic_stats root doesn't exist\n");
 392
 393                return rc;
 394        }
 395
 396        de = debugfs_create_dir(name, snic_glob->stats_root);
 397        if (!de) {
 398                SNIC_DBG("Cannot create host directory\n");
 399
 400                return rc;
 401        }
 402        snic->stats_host = de;
 403
 404        de = debugfs_create_file("stats",
 405                                S_IFREG|S_IRUGO,
 406                                snic->stats_host,
 407                                snic,
 408                                &snic_stats_fops);
 409        if (!de) {
 410                SNIC_DBG("Cannot create host's stats file\n");
 411
 412                return rc;
 413        }
 414        snic->stats_file = de;
 415
 416        de = debugfs_create_file("reset_stats",
 417                                S_IFREG|S_IRUGO|S_IWUSR,
 418                                snic->stats_host,
 419                                snic,
 420                                &snic_reset_stats_fops);
 421
 422        if (!de) {
 423                SNIC_DBG("Cannot create host's reset_stats file\n");
 424
 425                return rc;
 426        }
 427        snic->reset_stats_file = de;
 428        rc = 0;
 429
 430        return rc;
 431} /* end of snic_stats_debugfs_init */
 432
 433/*
 434 * snic_stats_debugfs_remove - Tear down debugfs infrastructure of stats
 435 *
 436 * Description:
 437 * When Debufs is configured this routine removes debugfs file system
 438 * elements that are specific to to snic stats
 439 */
 440void
 441snic_stats_debugfs_remove(struct snic *snic)
 442{
 443        debugfs_remove(snic->stats_file);
 444        snic->stats_file = NULL;
 445
 446        debugfs_remove(snic->reset_stats_file);
 447        snic->reset_stats_file = NULL;
 448
 449        debugfs_remove(snic->stats_host);
 450        snic->stats_host = NULL;
 451}
 452
 453/* Trace Facility related API */
 454static void *
 455snic_trc_seq_start(struct seq_file *sfp, loff_t *pos)
 456{
 457        return &snic_glob->trc;
 458}
 459
 460static void *
 461snic_trc_seq_next(struct seq_file *sfp, void *data, loff_t *pos)
 462{
 463        return NULL;
 464}
 465
 466static void
 467snic_trc_seq_stop(struct seq_file *sfp, void *data)
 468{
 469}
 470
 471#define SNIC_TRC_PBLEN  256
 472static int
 473snic_trc_seq_show(struct seq_file *sfp, void *data)
 474{
 475        char buf[SNIC_TRC_PBLEN];
 476
 477        if (snic_get_trc_data(buf, SNIC_TRC_PBLEN) > 0)
 478                seq_printf(sfp, "%s\n", buf);
 479
 480        return 0;
 481}
 482
 483static const struct seq_operations snic_trc_seq_ops = {
 484        .start  = snic_trc_seq_start,
 485        .next   = snic_trc_seq_next,
 486        .stop   = snic_trc_seq_stop,
 487        .show   = snic_trc_seq_show,
 488};
 489
 490static int
 491snic_trc_open(struct inode *inode, struct file *filp)
 492{
 493        return seq_open(filp, &snic_trc_seq_ops);
 494}
 495
 496static const struct file_operations snic_trc_fops = {
 497        .owner  = THIS_MODULE,
 498        .open   = snic_trc_open,
 499        .read   = seq_read,
 500        .llseek = seq_lseek,
 501        .release = seq_release,
 502};
 503
 504/*
 505 * snic_trc_debugfs_init : creates trace/tracing_enable files for trace
 506 * under debugfs
 507 */
 508int
 509snic_trc_debugfs_init(void)
 510{
 511        struct dentry *de = NULL;
 512        int ret = -1;
 513
 514        if (!snic_glob->trc_root) {
 515                SNIC_ERR("Debugfs root directory for snic doesn't exist.\n");
 516
 517                return ret;
 518        }
 519
 520        de = debugfs_create_bool("tracing_enable",
 521                                 S_IFREG | S_IRUGO | S_IWUSR,
 522                                 snic_glob->trc_root,
 523                                 &snic_glob->trc.enable);
 524
 525        if (!de) {
 526                SNIC_ERR("Can't create trace_enable file.\n");
 527
 528                return ret;
 529        }
 530        snic_glob->trc.trc_enable = de;
 531
 532        de = debugfs_create_file("trace",
 533                                 S_IFREG | S_IRUGO | S_IWUSR,
 534                                 snic_glob->trc_root,
 535                                 NULL,
 536                                 &snic_trc_fops);
 537
 538        if (!de) {
 539                SNIC_ERR("Cann't create trace file.\n");
 540
 541                return ret;
 542        }
 543        snic_glob->trc.trc_file = de;
 544        ret = 0;
 545
 546        return ret;
 547} /* end of snic_trc_debugfs_init */
 548
 549/*
 550 * snic_trc_debugfs_term : cleans up the files created for trace under debugfs
 551 */
 552void
 553snic_trc_debugfs_term(void)
 554{
 555        debugfs_remove(snic_glob->trc.trc_file);
 556        snic_glob->trc.trc_file = NULL;
 557
 558        debugfs_remove(snic_glob->trc.trc_enable);
 559        snic_glob->trc.trc_enable = NULL;
 560}
 561