dm thin metadata: fix __udivdi3 undefined on 32-bit
[linux/fpc-iii.git] / drivers / scsi / snic / snic_debugfs.c
blob1686f019625178fe5064688c6f0ef920489588ce
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 (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 */
275 seq_printf(sfp,
276 "\n-------------------------------------------\n"
277 "\t\t Reset Statistics\n"
278 "---------------------------------------------\n");
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));
288 /* Dump Firmware Stats */
289 seq_printf(sfp,
290 "\n-------------------------------------------\n"
291 "\t\t Firmware Statistics\n"
292 "---------------------------------------------\n");
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));
307 /* Dump Miscellenous Stats */
308 seq_printf(sfp,
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);
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));
342 return 0;
346 * snic_stats_open - Open the stats file for specific host
348 * Description:
349 * This routine opens a debugfs file stats of specific host
351 static int
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,
360 .read = seq_read,
361 .llseek = seq_lseek,
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
375 * per snic
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
383 snic_stats_debugfs_init(struct snic *snic)
385 int rc = -1;
386 char name[16];
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");
393 return rc;
396 de = debugfs_create_dir(name, snic_glob->stats_root);
397 if (!de) {
398 SNIC_DBG("Cannot create host directory\n");
400 return rc;
402 snic->stats_host = de;
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");
412 return rc;
414 snic->stats_file = de;
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);
422 if (!de) {
423 SNIC_DBG("Cannot create host's reset_stats file\n");
425 return rc;
427 snic->reset_stats_file = de;
428 rc = 0;
430 return rc;
431 } /* end of snic_stats_debugfs_init */
434 * snic_stats_debugfs_remove - Tear down debugfs infrastructure of stats
436 * Description:
437 * When Debufs is configured this routine removes debugfs file system
438 * elements that are specific to to snic stats
440 void
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 */
454 static void *
455 snic_trc_seq_start(struct seq_file *sfp, loff_t *pos)
457 return &snic_glob->trc;
460 static void *
461 snic_trc_seq_next(struct seq_file *sfp, void *data, loff_t *pos)
463 return NULL;
466 static void
467 snic_trc_seq_stop(struct seq_file *sfp, void *data)
471 #define SNIC_TRC_PBLEN 256
472 static int
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);
480 return 0;
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,
490 static int
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,
499 .read = seq_read,
500 .llseek = seq_lseek,
501 .release = seq_release,
505 * snic_trc_debugfs_init : creates trace/tracing_enable files for trace
506 * under debugfs
509 snic_trc_debugfs_init(void)
511 struct dentry *de = NULL;
512 int ret = -1;
514 if (!snic_glob->trc_root) {
515 SNIC_ERR("Debugfs root directory for snic doesn't exist.\n");
517 return ret;
520 de = debugfs_create_bool("tracing_enable",
521 S_IFREG | S_IRUGO | S_IWUSR,
522 snic_glob->trc_root,
523 &snic_glob->trc.enable);
525 if (!de) {
526 SNIC_ERR("Can't create trace_enable file.\n");
528 return ret;
530 snic_glob->trc.trc_enable = de;
532 de = debugfs_create_file("trace",
533 S_IFREG | S_IRUGO | S_IWUSR,
534 snic_glob->trc_root,
535 NULL,
536 &snic_trc_fops);
538 if (!de) {
539 SNIC_ERR("Cann't create trace file.\n");
541 return ret;
543 snic_glob->trc.trc_file = de;
544 ret = 0;
546 return ret;
547 } /* end of snic_trc_debugfs_init */
550 * snic_trc_debugfs_term : cleans up the files created for trace under debugfs
552 void
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;