Linux 4.18.10
[linux/fpc-iii.git] / drivers / scsi / snic / snic_debugfs.c
blob269ddf791a73ff67723446498f5ff148054dc27b
1 /*
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
15 * SOFTWARE.
18 #include <linux/module.h>
19 #include <linux/errno.h>
20 #include <linux/debugfs.h>
22 #include "snic.h"
25 * snic_debugfs_init - Initialize debugfs for snic debug logging
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
34 int
35 snic_debugfs_init(void)
37 int rc = -1;
38 struct dentry *de = NULL;
40 de = debugfs_create_dir("snic", NULL);
41 if (!de) {
42 SNIC_DBG("Cannot create debugfs root\n");
44 return rc;
46 snic_glob->trc_root = de;
48 de = debugfs_create_dir("statistics", snic_glob->trc_root);
49 if (!de) {
50 SNIC_DBG("Cannot create Statistics directory\n");
52 return rc;
54 snic_glob->stats_root = de;
56 rc = 0;
58 return rc;
59 } /* end of snic_debugfs_init */
62 * snic_debugfs_term - Tear down debugfs intrastructure
64 * Description:
65 * When Debufs is configured this routine removes debugfs file system
66 * elements that are specific to snic
68 void
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
81 static int
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;
87 return 0;
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.
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.
102 * Returns:
103 * This function returns the amount of data that was read.
105 static ssize_t
106 snic_reset_stats_read(struct file *filp,
107 char __user *ubuf,
108 size_t cnt,
109 loff_t *ppos)
111 struct snic *snic = (struct snic *) filp->private_data;
112 char buf[64];
113 int len;
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.
127 * Description:
128 * This routine writes data from user buffer @ubuf to buffer @buf and
129 * resets cumulative stats of snic.
131 * Returns:
132 * This function returns the amount of data that was written.
134 static ssize_t
135 snic_reset_stats_write(struct file *filp,
136 const char __user *ubuf,
137 size_t cnt,
138 loff_t *ppos)
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;
148 if (cnt >= sizeof(buf))
149 return -EINVAL;
151 if (copy_from_user(&buf, ubuf, cnt))
152 return -EFAULT;
154 buf[cnt] = '\0';
156 ret = kstrtoul(buf, 10, &val);
157 if (ret < 0)
158 return ret;
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));
172 memset(io_stats_p+1,
174 sizeof(struct snic_io_stats) - sizeof(u64));
175 memset(fw_stats_p+1,
177 sizeof(struct snic_fw_stats) - sizeof(u64));
180 (*ppos)++;
182 SNIC_HOST_INFO(snic->shost, "Reset Op: Driver statistics.\n");
184 return cnt;
187 static int
188 snic_reset_stats_release(struct inode *inode, struct file *filp)
190 filp->private_data = NULL;
192 return 0;
196 * snic_stats_show - Formats and prints per host specific driver stats.
198 static int
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;
204 u64 maxio_tm;
205 int i;
207 /* Dump IO Stats */
208 seq_printf(sfp,
209 "------------------------------------------\n"
210 "\t\t IO Statistics\n"
211 "------------------------------------------\n");
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));
245 seq_puts(sfp, "\nSGL Counters\n");
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]));
252 if ((i + 1) % 8 == 0)
253 seq_puts(sfp, "\n");
256 /* Dump Abort Stats */
257 seq_printf(sfp,
258 "\n-------------------------------------------\n"
259 "\t\t Abort Statistics\n"
260 "---------------------------------------------\n");
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 "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 */
277 seq_printf(sfp,
278 "\n-------------------------------------------\n"
279 "\t\t Reset Statistics\n"
280 "---------------------------------------------\n");
282 seq_printf(sfp,
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 */
291 seq_printf(sfp,
292 "\n-------------------------------------------\n"
293 "\t\t Firmware Statistics\n"
294 "---------------------------------------------\n");
296 seq_printf(sfp,
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 */
310 seq_printf(sfp,
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);
318 seq_printf(sfp,
319 "Last ISR Time : %llu (%8lu.%8lu)\n"
320 "Last Ack Time : %llu (%8lu.%8lu)\n"
321 "Ack ISRs : %llu\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));
354 return 0;
358 * snic_stats_open - Open the stats file for specific host
360 * Description:
361 * This routine opens a debugfs file stats of specific host
363 static int
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,
372 .read = seq_read,
373 .llseek = seq_lseek,
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
387 * per snic
389 * Description:
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)
397 int rc = -1;
398 char name[16];
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");
405 return rc;
408 de = debugfs_create_dir(name, snic_glob->stats_root);
409 if (!de) {
410 SNIC_DBG("Cannot create host directory\n");
412 return rc;
414 snic->stats_host = de;
416 de = debugfs_create_file("stats",
417 S_IFREG|S_IRUGO,
418 snic->stats_host,
419 snic,
420 &snic_stats_fops);
421 if (!de) {
422 SNIC_DBG("Cannot create host's stats file\n");
424 return rc;
426 snic->stats_file = de;
428 de = debugfs_create_file("reset_stats",
429 S_IFREG|S_IRUGO|S_IWUSR,
430 snic->stats_host,
431 snic,
432 &snic_reset_stats_fops);
434 if (!de) {
435 SNIC_DBG("Cannot create host's reset_stats file\n");
437 return rc;
439 snic->reset_stats_file = de;
440 rc = 0;
442 return rc;
443 } /* end of snic_stats_debugfs_init */
446 * snic_stats_debugfs_remove - Tear down debugfs infrastructure of stats
448 * Description:
449 * When Debufs is configured this routine removes debugfs file system
450 * elements that are specific to to snic stats
452 void
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 */
466 static void *
467 snic_trc_seq_start(struct seq_file *sfp, loff_t *pos)
469 return &snic_glob->trc;
472 static void *
473 snic_trc_seq_next(struct seq_file *sfp, void *data, loff_t *pos)
475 return NULL;
478 static void
479 snic_trc_seq_stop(struct seq_file *sfp, void *data)
483 #define SNIC_TRC_PBLEN 256
484 static int
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);
492 return 0;
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,
502 static int
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,
511 .read = seq_read,
512 .llseek = seq_lseek,
513 .release = seq_release,
517 * snic_trc_debugfs_init : creates trace/tracing_enable files for trace
518 * under debugfs
521 snic_trc_debugfs_init(void)
523 struct dentry *de = NULL;
524 int ret = -1;
526 if (!snic_glob->trc_root) {
527 SNIC_ERR("Debugfs root directory for snic doesn't exist.\n");
529 return ret;
532 de = debugfs_create_bool("tracing_enable",
533 S_IFREG | S_IRUGO | S_IWUSR,
534 snic_glob->trc_root,
535 &snic_glob->trc.enable);
537 if (!de) {
538 SNIC_ERR("Can't create trace_enable file.\n");
540 return ret;
542 snic_glob->trc.trc_enable = de;
544 de = debugfs_create_file("trace",
545 S_IFREG | S_IRUGO | S_IWUSR,
546 snic_glob->trc_root,
547 NULL,
548 &snic_trc_fops);
550 if (!de) {
551 SNIC_ERR("Cannot create trace file.\n");
553 return ret;
555 snic_glob->trc.trc_file = de;
556 ret = 0;
558 return ret;
559 } /* end of snic_trc_debugfs_init */
562 * snic_trc_debugfs_term : cleans up the files created for trace under debugfs
564 void
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;