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 (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
));
274 /* Dump Reset Stats */
276 "\n-------------------------------------------\n"
277 "\t\t Reset Statistics\n"
278 "---------------------------------------------\n");
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
));
288 /* Dump Firmware Stats */
290 "\n-------------------------------------------\n"
291 "\t\t Firmware Statistics\n"
292 "---------------------------------------------\n");
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
));
307 /* Dump Miscellenous Stats */
309 "\n---------------------------------------------\n"
310 "\t\t Other Statistics\n"
311 "\n---------------------------------------------\n");
313 jiffies_to_timespec(stats
->misc
.last_isr_time
, &last_isr_tms
);
314 jiffies_to_timespec(stats
->misc
.last_ack_time
, &last_ack_tms
);
317 "Last ISR Time : %llu (%8lu.%8lu)\n"
318 "Last Ack Time : %llu (%8lu.%8lu)\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
));
346 * snic_stats_open - Open the stats file for specific host
349 * This routine opens a debugfs file stats of specific host
352 snic_stats_open(struct inode
*inode
, struct file
*filp
)
354 return single_open(filp
, snic_stats_show
, inode
->i_private
);
357 static const struct file_operations snic_stats_fops
= {
358 .owner
= THIS_MODULE
,
359 .open
= snic_stats_open
,
362 .release
= single_release
,
365 static 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
,
374 * snic_stats_init - Initialize stats struct and create stats file
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
383 snic_stats_debugfs_init(struct snic
*snic
)
387 struct dentry
*de
= NULL
;
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");
396 de
= debugfs_create_dir(name
, snic_glob
->stats_root
);
398 SNIC_DBG("Cannot create host directory\n");
402 snic
->stats_host
= de
;
404 de
= debugfs_create_file("stats",
410 SNIC_DBG("Cannot create host's stats file\n");
414 snic
->stats_file
= de
;
416 de
= debugfs_create_file("reset_stats",
417 S_IFREG
|S_IRUGO
|S_IWUSR
,
420 &snic_reset_stats_fops
);
423 SNIC_DBG("Cannot create host's reset_stats file\n");
427 snic
->reset_stats_file
= de
;
431 } /* end of snic_stats_debugfs_init */
434 * snic_stats_debugfs_remove - Tear down debugfs infrastructure of stats
437 * When Debufs is configured this routine removes debugfs file system
438 * elements that are specific to to snic stats
441 snic_stats_debugfs_remove(struct snic
*snic
)
443 debugfs_remove(snic
->stats_file
);
444 snic
->stats_file
= NULL
;
446 debugfs_remove(snic
->reset_stats_file
);
447 snic
->reset_stats_file
= NULL
;
449 debugfs_remove(snic
->stats_host
);
450 snic
->stats_host
= NULL
;
453 /* Trace Facility related API */
455 snic_trc_seq_start(struct seq_file
*sfp
, loff_t
*pos
)
457 return &snic_glob
->trc
;
461 snic_trc_seq_next(struct seq_file
*sfp
, void *data
, loff_t
*pos
)
467 snic_trc_seq_stop(struct seq_file
*sfp
, void *data
)
471 #define SNIC_TRC_PBLEN 256
473 snic_trc_seq_show(struct seq_file
*sfp
, void *data
)
475 char buf
[SNIC_TRC_PBLEN
];
477 if (snic_get_trc_data(buf
, SNIC_TRC_PBLEN
) > 0)
478 seq_printf(sfp
, "%s\n", buf
);
483 static 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
,
491 snic_trc_open(struct inode
*inode
, struct file
*filp
)
493 return seq_open(filp
, &snic_trc_seq_ops
);
496 static const struct file_operations snic_trc_fops
= {
497 .owner
= THIS_MODULE
,
498 .open
= snic_trc_open
,
501 .release
= seq_release
,
505 * snic_trc_debugfs_init : creates trace/tracing_enable files for trace
509 snic_trc_debugfs_init(void)
511 struct dentry
*de
= NULL
;
514 if (!snic_glob
->trc_root
) {
515 SNIC_ERR("Debugfs root directory for snic doesn't exist.\n");
520 de
= debugfs_create_bool("tracing_enable",
521 S_IFREG
| S_IRUGO
| S_IWUSR
,
523 &snic_glob
->trc
.enable
);
526 SNIC_ERR("Can't create trace_enable file.\n");
530 snic_glob
->trc
.trc_enable
= de
;
532 de
= debugfs_create_file("trace",
533 S_IFREG
| S_IRUGO
| S_IWUSR
,
539 SNIC_ERR("Cann't create trace file.\n");
543 snic_glob
->trc
.trc_file
= de
;
547 } /* end of snic_trc_debugfs_init */
550 * snic_trc_debugfs_term : cleans up the files created for trace under debugfs
553 snic_trc_debugfs_term(void)
555 debugfs_remove(snic_glob
->trc
.trc_file
);
556 snic_glob
->trc
.trc_file
= NULL
;
558 debugfs_remove(snic_glob
->trc
.trc_enable
);
559 snic_glob
->trc
.trc_enable
= NULL
;