1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright 2014 Cisco Systems, Inc. All rights reserved.
4 #include <linux/module.h>
5 #include <linux/errno.h>
6 #include <linux/debugfs.h>
11 * snic_debugfs_init - Initialize debugfs for snic debug logging
14 * When Debugfs is configured this routine sets up fnic debugfs
15 * filesystem. If not already created. this routine will crate the
16 * fnic directory and statistics directory for trace buffer and
19 void snic_debugfs_init(void)
21 snic_glob
->trc_root
= debugfs_create_dir("snic", NULL
);
23 snic_glob
->stats_root
= debugfs_create_dir("statistics",
28 * snic_debugfs_term - Tear down debugfs intrastructure
31 * When Debufs is configured this routine removes debugfs file system
32 * elements that are specific to snic
35 snic_debugfs_term(void)
37 debugfs_remove(snic_glob
->stats_root
);
38 snic_glob
->stats_root
= NULL
;
40 debugfs_remove(snic_glob
->trc_root
);
41 snic_glob
->trc_root
= NULL
;
45 * snic_reset_stats_open - Open the reset_stats file
48 snic_reset_stats_open(struct inode
*inode
, struct file
*filp
)
50 SNIC_BUG_ON(!inode
->i_private
);
51 filp
->private_data
= inode
->i_private
;
57 * snic_reset_stats_read - Read a reset_stats debugfs file
58 * @filp: The file pointer to read from.
59 * @ubuf: The buffer tocopy the data to.
60 * @cnt: The number of bytes to read.
61 * @ppos: The position in the file to start reading frm.
64 * This routine reads value of variable reset_stats
65 * and stores into local @buf. It will start reading file @ppos and
66 * copy up to @cnt of data to @ubuf from @buf.
69 * This function returns the amount of data that was read.
72 snic_reset_stats_read(struct file
*filp
,
77 struct snic
*snic
= (struct snic
*) filp
->private_data
;
81 len
= sprintf(buf
, "%u\n", snic
->reset_stats
);
83 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, len
);
87 * snic_reset_stats_write - Write to reset_stats debugfs file
88 * @filp: The file pointer to write from
89 * @ubuf: The buffer to copy the data from.
90 * @cnt: The number of bytes to write.
91 * @ppos: The position in the file to start writing to.
94 * This routine writes data from user buffer @ubuf to buffer @buf and
95 * resets cumulative stats of snic.
98 * This function returns the amount of data that was written.
101 snic_reset_stats_write(struct file
*filp
,
102 const char __user
*ubuf
,
106 struct snic
*snic
= (struct snic
*) filp
->private_data
;
107 struct snic_stats
*stats
= &snic
->s_stats
;
108 u64
*io_stats_p
= (u64
*) &stats
->io
;
109 u64
*fw_stats_p
= (u64
*) &stats
->fw
;
114 if (cnt
>= sizeof(buf
))
117 if (copy_from_user(&buf
, ubuf
, cnt
))
122 ret
= kstrtoul(buf
, 10, &val
);
126 snic
->reset_stats
= val
;
128 if (snic
->reset_stats
) {
129 /* Skip variable is used to avoid descrepancies to Num IOs
130 * and IO Completions stats. Skip incrementing No IO Compls
131 * for pending active IOs after reset_stats
133 atomic64_set(&snic
->io_cmpl_skip
,
134 atomic64_read(&stats
->io
.active
));
135 memset(&stats
->abts
, 0, sizeof(struct snic_abort_stats
));
136 memset(&stats
->reset
, 0, sizeof(struct snic_reset_stats
));
137 memset(&stats
->misc
, 0, sizeof(struct snic_misc_stats
));
140 sizeof(struct snic_io_stats
) - sizeof(u64
));
143 sizeof(struct snic_fw_stats
) - sizeof(u64
));
148 SNIC_HOST_INFO(snic
->shost
, "Reset Op: Driver statistics.\n");
154 snic_reset_stats_release(struct inode
*inode
, struct file
*filp
)
156 filp
->private_data
= NULL
;
162 * snic_stats_show - Formats and prints per host specific driver stats.
165 snic_stats_show(struct seq_file
*sfp
, void *data
)
167 struct snic
*snic
= (struct snic
*) sfp
->private;
168 struct snic_stats
*stats
= &snic
->s_stats
;
169 struct timespec64 last_isr_tms
, last_ack_tms
;
175 "------------------------------------------\n"
176 "\t\t IO Statistics\n"
177 "------------------------------------------\n");
179 maxio_tm
= (u64
) atomic64_read(&stats
->io
.max_time
);
181 "Active IOs : %lld\n"
182 "Max Active IOs : %lld\n"
184 "IOs Completed : %lld\n"
185 "IOs Failed : %lld\n"
186 "IOs Not Found : %lld\n"
187 "Memory Alloc Failures : %lld\n"
189 "SCSI Cmd Pointers Null : %lld\n"
190 "Max SGL for any IO : %lld\n"
191 "Max IO Size : %lld Sectors\n"
192 "Max Queuing Time : %lld\n"
193 "Max Completion Time : %lld\n"
194 "Max IO Process Time(FW) : %lld (%u msec)\n",
195 (u64
) atomic64_read(&stats
->io
.active
),
196 (u64
) atomic64_read(&stats
->io
.max_active
),
197 (u64
) atomic64_read(&stats
->io
.num_ios
),
198 (u64
) atomic64_read(&stats
->io
.compl),
199 (u64
) atomic64_read(&stats
->io
.fail
),
200 (u64
) atomic64_read(&stats
->io
.io_not_found
),
201 (u64
) atomic64_read(&stats
->io
.alloc_fail
),
202 (u64
) atomic64_read(&stats
->io
.req_null
),
203 (u64
) atomic64_read(&stats
->io
.sc_null
),
204 (u64
) atomic64_read(&stats
->io
.max_sgl
),
205 (u64
) atomic64_read(&stats
->io
.max_io_sz
),
206 (u64
) atomic64_read(&stats
->io
.max_qtime
),
207 (u64
) atomic64_read(&stats
->io
.max_cmpl_time
),
209 jiffies_to_msecs(maxio_tm
));
211 seq_puts(sfp
, "\nSGL Counters\n");
213 for (i
= 0; i
< SNIC_MAX_SG_DESC_CNT
; i
++) {
216 (u64
) atomic64_read(&stats
->io
.sgl_cnt
[i
]));
218 if ((i
+ 1) % 8 == 0)
222 /* Dump Abort Stats */
224 "\n-------------------------------------------\n"
225 "\t\t Abort Statistics\n"
226 "---------------------------------------------\n");
230 "Aborts Fail : %lld\n"
231 "Aborts Driver Timeout : %lld\n"
232 "Abort FW Timeout : %lld\n"
233 "Abort IO NOT Found : %lld\n"
234 "Abort Queuing Failed : %lld\n",
235 (u64
) atomic64_read(&stats
->abts
.num
),
236 (u64
) atomic64_read(&stats
->abts
.fail
),
237 (u64
) atomic64_read(&stats
->abts
.drv_tmo
),
238 (u64
) atomic64_read(&stats
->abts
.fw_tmo
),
239 (u64
) atomic64_read(&stats
->abts
.io_not_found
),
240 (u64
) atomic64_read(&stats
->abts
.q_fail
));
242 /* Dump Reset Stats */
244 "\n-------------------------------------------\n"
245 "\t\t Reset Statistics\n"
246 "---------------------------------------------\n");
249 "HBA Resets : %lld\n"
250 "HBA Reset Cmpls : %lld\n"
251 "HBA Reset Fail : %lld\n",
252 (u64
) atomic64_read(&stats
->reset
.hba_resets
),
253 (u64
) atomic64_read(&stats
->reset
.hba_reset_cmpl
),
254 (u64
) atomic64_read(&stats
->reset
.hba_reset_fail
));
256 /* Dump Firmware Stats */
258 "\n-------------------------------------------\n"
259 "\t\t Firmware Statistics\n"
260 "---------------------------------------------\n");
263 "Active FW Requests : %lld\n"
264 "Max FW Requests : %lld\n"
265 "FW Out Of Resource Errs : %lld\n"
266 "FW IO Errors : %lld\n"
267 "FW SCSI Errors : %lld\n",
268 (u64
) atomic64_read(&stats
->fw
.actv_reqs
),
269 (u64
) atomic64_read(&stats
->fw
.max_actv_reqs
),
270 (u64
) atomic64_read(&stats
->fw
.out_of_res
),
271 (u64
) atomic64_read(&stats
->fw
.io_errs
),
272 (u64
) atomic64_read(&stats
->fw
.scsi_errs
));
275 /* Dump Miscellenous Stats */
277 "\n---------------------------------------------\n"
278 "\t\t Other Statistics\n"
279 "\n---------------------------------------------\n");
281 jiffies_to_timespec64(stats
->misc
.last_isr_time
, &last_isr_tms
);
282 jiffies_to_timespec64(stats
->misc
.last_ack_time
, &last_ack_tms
);
285 "Last ISR Time : %llu (%8llu.%09lu)\n"
286 "Last Ack Time : %llu (%8llu.%09lu)\n"
288 "IO Cmpl ISRs : %llu\n"
289 "Err Notify ISRs : %llu\n"
290 "Max CQ Entries : %lld\n"
291 "Data Count Mismatch : %lld\n"
292 "IOs w/ Timeout Status : %lld\n"
293 "IOs w/ Aborted Status : %lld\n"
294 "IOs w/ SGL Invalid Stat : %lld\n"
295 "WQ Desc Alloc Fail : %lld\n"
296 "Queue Full : %lld\n"
297 "Queue Ramp Up : %lld\n"
298 "Queue Ramp Down : %lld\n"
299 "Queue Last Queue Depth : %lld\n"
300 "Target Not Ready : %lld\n",
301 (u64
) stats
->misc
.last_isr_time
,
302 last_isr_tms
.tv_sec
, last_isr_tms
.tv_nsec
,
303 (u64
)stats
->misc
.last_ack_time
,
304 last_ack_tms
.tv_sec
, last_ack_tms
.tv_nsec
,
305 (u64
) atomic64_read(&stats
->misc
.ack_isr_cnt
),
306 (u64
) atomic64_read(&stats
->misc
.cmpl_isr_cnt
),
307 (u64
) atomic64_read(&stats
->misc
.errnotify_isr_cnt
),
308 (u64
) atomic64_read(&stats
->misc
.max_cq_ents
),
309 (u64
) atomic64_read(&stats
->misc
.data_cnt_mismat
),
310 (u64
) atomic64_read(&stats
->misc
.io_tmo
),
311 (u64
) atomic64_read(&stats
->misc
.io_aborted
),
312 (u64
) atomic64_read(&stats
->misc
.sgl_inval
),
313 (u64
) atomic64_read(&stats
->misc
.wq_alloc_fail
),
314 (u64
) atomic64_read(&stats
->misc
.qfull
),
315 (u64
) atomic64_read(&stats
->misc
.qsz_rampup
),
316 (u64
) atomic64_read(&stats
->misc
.qsz_rampdown
),
317 (u64
) atomic64_read(&stats
->misc
.last_qsz
),
318 (u64
) atomic64_read(&stats
->misc
.tgt_not_rdy
));
323 DEFINE_SHOW_ATTRIBUTE(snic_stats
);
325 static const struct file_operations snic_reset_stats_fops
= {
326 .owner
= THIS_MODULE
,
327 .open
= snic_reset_stats_open
,
328 .read
= snic_reset_stats_read
,
329 .write
= snic_reset_stats_write
,
330 .release
= snic_reset_stats_release
,
334 * snic_stats_init - Initialize stats struct and create stats file
338 * When debugfs is cofigured this routine sets up the stats file per snic
339 * It will create file stats and reset_stats under statistics/host# directory
340 * to log per snic stats
342 void snic_stats_debugfs_init(struct snic
*snic
)
346 snprintf(name
, sizeof(name
), "host%d", snic
->shost
->host_no
);
348 snic
->stats_host
= debugfs_create_dir(name
, snic_glob
->stats_root
);
350 snic
->stats_file
= debugfs_create_file("stats", S_IFREG
|S_IRUGO
,
351 snic
->stats_host
, snic
,
354 snic
->reset_stats_file
= debugfs_create_file("reset_stats",
355 S_IFREG
|S_IRUGO
|S_IWUSR
,
356 snic
->stats_host
, snic
,
357 &snic_reset_stats_fops
);
361 * snic_stats_debugfs_remove - Tear down debugfs infrastructure of stats
364 * When Debufs is configured this routine removes debugfs file system
365 * elements that are specific to to snic stats
368 snic_stats_debugfs_remove(struct snic
*snic
)
370 debugfs_remove(snic
->stats_file
);
371 snic
->stats_file
= NULL
;
373 debugfs_remove(snic
->reset_stats_file
);
374 snic
->reset_stats_file
= NULL
;
376 debugfs_remove(snic
->stats_host
);
377 snic
->stats_host
= NULL
;
380 /* Trace Facility related API */
382 snic_trc_seq_start(struct seq_file
*sfp
, loff_t
*pos
)
384 return &snic_glob
->trc
;
388 snic_trc_seq_next(struct seq_file
*sfp
, void *data
, loff_t
*pos
)
394 snic_trc_seq_stop(struct seq_file
*sfp
, void *data
)
398 #define SNIC_TRC_PBLEN 256
400 snic_trc_seq_show(struct seq_file
*sfp
, void *data
)
402 char buf
[SNIC_TRC_PBLEN
];
404 if (snic_get_trc_data(buf
, SNIC_TRC_PBLEN
) > 0)
405 seq_printf(sfp
, "%s\n", buf
);
410 static const struct seq_operations snic_trc_sops
= {
411 .start
= snic_trc_seq_start
,
412 .next
= snic_trc_seq_next
,
413 .stop
= snic_trc_seq_stop
,
414 .show
= snic_trc_seq_show
,
417 DEFINE_SEQ_ATTRIBUTE(snic_trc
);
419 #define TRC_ENABLE_FILE "tracing_enable"
420 #define TRC_FILE "trace"
422 * snic_trc_debugfs_init : creates trace/tracing_enable files for trace
425 void snic_trc_debugfs_init(void)
427 debugfs_create_bool(TRC_ENABLE_FILE
, S_IFREG
| S_IRUGO
| S_IWUSR
,
428 snic_glob
->trc_root
, &snic_glob
->trc
.enable
);
430 debugfs_create_file(TRC_FILE
, S_IFREG
| S_IRUGO
| S_IWUSR
,
431 snic_glob
->trc_root
, NULL
, &snic_trc_fops
);
435 * snic_trc_debugfs_term : cleans up the files created for trace under debugfs
438 snic_trc_debugfs_term(void)
440 debugfs_lookup_and_remove(TRC_FILE
, snic_glob
->trc_root
);
441 debugfs_lookup_and_remove(TRC_ENABLE_FILE
, snic_glob
->trc_root
);