2 * Copyright 2014 Cisco Systems, Inc. All rights reserved.
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.
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
18 #include <linux/module.h>
19 #include <linux/errno.h>
20 #include <linux/debugfs.h>
25 * snic_debugfs_init - Initialize debugfs for snic debug logging
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
35 snic_debugfs_init(void)
38 struct dentry
*de
= NULL
;
40 de
= debugfs_create_dir("snic", NULL
);
42 SNIC_DBG("Cannot create debugfs root\n");
46 snic_glob
->trc_root
= de
;
48 de
= debugfs_create_dir("statistics", snic_glob
->trc_root
);
50 SNIC_DBG("Cannot create Statistics directory\n");
54 snic_glob
->stats_root
= de
;
59 } /* end of snic_debugfs_init */
62 * snic_debugfs_term - Tear down debugfs intrastructure
65 * When Debufs is configured this routine removes debugfs file system
66 * elements that are specific to snic
69 snic_debugfs_term(void)
71 debugfs_remove(snic_glob
->stats_root
);
72 snic_glob
->stats_root
= NULL
;
74 debugfs_remove(snic_glob
->trc_root
);
75 snic_glob
->trc_root
= NULL
;
79 * snic_reset_stats_open - Open the reset_stats file
82 snic_reset_stats_open(struct inode
*inode
, struct file
*filp
)
84 SNIC_BUG_ON(!inode
->i_private
);
85 filp
->private_data
= inode
->i_private
;
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.
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.
103 * This function returns the amount of data that was read.
106 snic_reset_stats_read(struct file
*filp
,
111 struct snic
*snic
= (struct snic
*) filp
->private_data
;
115 len
= sprintf(buf
, "%u\n", snic
->reset_stats
);
117 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, len
);
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.
128 * This routine writes data from user buffer @ubuf to buffer @buf and
129 * resets cumulative stats of snic.
132 * This function returns the amount of data that was written.
135 snic_reset_stats_write(struct file
*filp
,
136 const char __user
*ubuf
,
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
;
148 if (cnt
>= sizeof(buf
))
151 if (copy_from_user(&buf
, ubuf
, cnt
))
156 ret
= kstrtoul(buf
, 10, &val
);
160 snic
->reset_stats
= val
;
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
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
));
174 sizeof(struct snic_io_stats
) - sizeof(u64
));
177 sizeof(struct snic_fw_stats
) - sizeof(u64
));
182 SNIC_HOST_INFO(snic
->shost
, "Reset Op: Driver statistics.\n");
188 snic_reset_stats_release(struct inode
*inode
, struct file
*filp
)
190 filp
->private_data
= NULL
;
196 * snic_stats_show - Formats and prints per host specific driver stats.
199 snic_stats_show(struct seq_file
*sfp
, void *data
)
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
;
209 "------------------------------------------\n"
210 "\t\t IO Statistics\n"
211 "------------------------------------------\n");
213 maxio_tm
= (u64
) atomic64_read(&stats
->io
.max_time
);
215 "Active IOs : %lld\n"
216 "Max Active 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"
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
),
243 jiffies_to_msecs(maxio_tm
));
245 seq_puts(sfp
, "\nSGL Counters\n");
247 for (i
= 0; i
< SNIC_MAX_SG_DESC_CNT
; i
++) {
250 (u64
) atomic64_read(&stats
->io
.sgl_cnt
[i
]));
252 if ((i
+ 1) % 8 == 0)
256 /* Dump Abort Stats */
258 "\n-------------------------------------------\n"
259 "\t\t Abort Statistics\n"
260 "---------------------------------------------\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 "Abort Queuing Failed : %lld\n",
269 (u64
) atomic64_read(&stats
->abts
.num
),
270 (u64
) atomic64_read(&stats
->abts
.fail
),
271 (u64
) atomic64_read(&stats
->abts
.drv_tmo
),
272 (u64
) atomic64_read(&stats
->abts
.fw_tmo
),
273 (u64
) atomic64_read(&stats
->abts
.io_not_found
),
274 (u64
) atomic64_read(&stats
->abts
.q_fail
));
276 /* Dump Reset Stats */
278 "\n-------------------------------------------\n"
279 "\t\t Reset Statistics\n"
280 "---------------------------------------------\n");
283 "HBA Resets : %lld\n"
284 "HBA Reset Cmpls : %lld\n"
285 "HBA Reset Fail : %lld\n",
286 (u64
) atomic64_read(&stats
->reset
.hba_resets
),
287 (u64
) atomic64_read(&stats
->reset
.hba_reset_cmpl
),
288 (u64
) atomic64_read(&stats
->reset
.hba_reset_fail
));
290 /* Dump Firmware Stats */
292 "\n-------------------------------------------\n"
293 "\t\t Firmware Statistics\n"
294 "---------------------------------------------\n");
297 "Active FW Requests : %lld\n"
298 "Max FW Requests : %lld\n"
299 "FW Out Of Resource Errs : %lld\n"
300 "FW IO Errors : %lld\n"
301 "FW SCSI Errors : %lld\n",
302 (u64
) atomic64_read(&stats
->fw
.actv_reqs
),
303 (u64
) atomic64_read(&stats
->fw
.max_actv_reqs
),
304 (u64
) atomic64_read(&stats
->fw
.out_of_res
),
305 (u64
) atomic64_read(&stats
->fw
.io_errs
),
306 (u64
) atomic64_read(&stats
->fw
.scsi_errs
));
309 /* Dump Miscellenous Stats */
311 "\n---------------------------------------------\n"
312 "\t\t Other Statistics\n"
313 "\n---------------------------------------------\n");
315 jiffies_to_timespec(stats
->misc
.last_isr_time
, &last_isr_tms
);
316 jiffies_to_timespec(stats
->misc
.last_ack_time
, &last_ack_tms
);
319 "Last ISR Time : %llu (%8lu.%8lu)\n"
320 "Last Ack Time : %llu (%8lu.%8lu)\n"
322 "IO Cmpl ISRs : %llu\n"
323 "Err Notify ISRs : %llu\n"
324 "Max CQ Entries : %lld\n"
325 "Data Count Mismatch : %lld\n"
326 "IOs w/ Timeout Status : %lld\n"
327 "IOs w/ Aborted Status : %lld\n"
328 "IOs w/ SGL Invalid Stat : %lld\n"
329 "WQ Desc Alloc Fail : %lld\n"
330 "Queue Full : %lld\n"
331 "Queue Ramp Up : %lld\n"
332 "Queue Ramp Down : %lld\n"
333 "Queue Last Queue Depth : %lld\n"
334 "Target Not Ready : %lld\n",
335 (u64
) stats
->misc
.last_isr_time
,
336 last_isr_tms
.tv_sec
, last_isr_tms
.tv_nsec
,
337 (u64
)stats
->misc
.last_ack_time
,
338 last_ack_tms
.tv_sec
, last_ack_tms
.tv_nsec
,
339 (u64
) atomic64_read(&stats
->misc
.ack_isr_cnt
),
340 (u64
) atomic64_read(&stats
->misc
.cmpl_isr_cnt
),
341 (u64
) atomic64_read(&stats
->misc
.errnotify_isr_cnt
),
342 (u64
) atomic64_read(&stats
->misc
.max_cq_ents
),
343 (u64
) atomic64_read(&stats
->misc
.data_cnt_mismat
),
344 (u64
) atomic64_read(&stats
->misc
.io_tmo
),
345 (u64
) atomic64_read(&stats
->misc
.io_aborted
),
346 (u64
) atomic64_read(&stats
->misc
.sgl_inval
),
347 (u64
) atomic64_read(&stats
->misc
.wq_alloc_fail
),
348 (u64
) atomic64_read(&stats
->misc
.qfull
),
349 (u64
) atomic64_read(&stats
->misc
.qsz_rampup
),
350 (u64
) atomic64_read(&stats
->misc
.qsz_rampdown
),
351 (u64
) atomic64_read(&stats
->misc
.last_qsz
),
352 (u64
) atomic64_read(&stats
->misc
.tgt_not_rdy
));
358 * snic_stats_open - Open the stats file for specific host
361 * This routine opens a debugfs file stats of specific host
364 snic_stats_open(struct inode
*inode
, struct file
*filp
)
366 return single_open(filp
, snic_stats_show
, inode
->i_private
);
369 static const struct file_operations snic_stats_fops
= {
370 .owner
= THIS_MODULE
,
371 .open
= snic_stats_open
,
374 .release
= single_release
,
377 static const struct file_operations snic_reset_stats_fops
= {
378 .owner
= THIS_MODULE
,
379 .open
= snic_reset_stats_open
,
380 .read
= snic_reset_stats_read
,
381 .write
= snic_reset_stats_write
,
382 .release
= snic_reset_stats_release
,
386 * snic_stats_init - Initialize stats struct and create stats file
390 * When debugfs is cofigured this routine sets up the stats file per snic
391 * It will create file stats and reset_stats under statistics/host# directory
392 * to log per snic stats
395 snic_stats_debugfs_init(struct snic
*snic
)
399 struct dentry
*de
= NULL
;
401 snprintf(name
, sizeof(name
), "host%d", snic
->shost
->host_no
);
402 if (!snic_glob
->stats_root
) {
403 SNIC_DBG("snic_stats root doesn't exist\n");
408 de
= debugfs_create_dir(name
, snic_glob
->stats_root
);
410 SNIC_DBG("Cannot create host directory\n");
414 snic
->stats_host
= de
;
416 de
= debugfs_create_file("stats",
422 SNIC_DBG("Cannot create host's stats file\n");
426 snic
->stats_file
= de
;
428 de
= debugfs_create_file("reset_stats",
429 S_IFREG
|S_IRUGO
|S_IWUSR
,
432 &snic_reset_stats_fops
);
435 SNIC_DBG("Cannot create host's reset_stats file\n");
439 snic
->reset_stats_file
= de
;
443 } /* end of snic_stats_debugfs_init */
446 * snic_stats_debugfs_remove - Tear down debugfs infrastructure of stats
449 * When Debufs is configured this routine removes debugfs file system
450 * elements that are specific to to snic stats
453 snic_stats_debugfs_remove(struct snic
*snic
)
455 debugfs_remove(snic
->stats_file
);
456 snic
->stats_file
= NULL
;
458 debugfs_remove(snic
->reset_stats_file
);
459 snic
->reset_stats_file
= NULL
;
461 debugfs_remove(snic
->stats_host
);
462 snic
->stats_host
= NULL
;
465 /* Trace Facility related API */
467 snic_trc_seq_start(struct seq_file
*sfp
, loff_t
*pos
)
469 return &snic_glob
->trc
;
473 snic_trc_seq_next(struct seq_file
*sfp
, void *data
, loff_t
*pos
)
479 snic_trc_seq_stop(struct seq_file
*sfp
, void *data
)
483 #define SNIC_TRC_PBLEN 256
485 snic_trc_seq_show(struct seq_file
*sfp
, void *data
)
487 char buf
[SNIC_TRC_PBLEN
];
489 if (snic_get_trc_data(buf
, SNIC_TRC_PBLEN
) > 0)
490 seq_printf(sfp
, "%s\n", buf
);
495 static const struct seq_operations snic_trc_seq_ops
= {
496 .start
= snic_trc_seq_start
,
497 .next
= snic_trc_seq_next
,
498 .stop
= snic_trc_seq_stop
,
499 .show
= snic_trc_seq_show
,
503 snic_trc_open(struct inode
*inode
, struct file
*filp
)
505 return seq_open(filp
, &snic_trc_seq_ops
);
508 static const struct file_operations snic_trc_fops
= {
509 .owner
= THIS_MODULE
,
510 .open
= snic_trc_open
,
513 .release
= seq_release
,
517 * snic_trc_debugfs_init : creates trace/tracing_enable files for trace
521 snic_trc_debugfs_init(void)
523 struct dentry
*de
= NULL
;
526 if (!snic_glob
->trc_root
) {
527 SNIC_ERR("Debugfs root directory for snic doesn't exist.\n");
532 de
= debugfs_create_bool("tracing_enable",
533 S_IFREG
| S_IRUGO
| S_IWUSR
,
535 &snic_glob
->trc
.enable
);
538 SNIC_ERR("Can't create trace_enable file.\n");
542 snic_glob
->trc
.trc_enable
= de
;
544 de
= debugfs_create_file("trace",
545 S_IFREG
| S_IRUGO
| S_IWUSR
,
551 SNIC_ERR("Cannot create trace file.\n");
555 snic_glob
->trc
.trc_file
= de
;
559 } /* end of snic_trc_debugfs_init */
562 * snic_trc_debugfs_term : cleans up the files created for trace under debugfs
565 snic_trc_debugfs_term(void)
567 debugfs_remove(snic_glob
->trc
.trc_file
);
568 snic_glob
->trc
.trc_file
= NULL
;
570 debugfs_remove(snic_glob
->trc
.trc_enable
);
571 snic_glob
->trc
.trc_enable
= NULL
;