1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include <linux/module.h>
19#include <linux/errno.h>
20#include <linux/debugfs.h>
21#include "fnic.h"
22
23static struct dentry *fnic_trace_debugfs_root;
24static struct dentry *fnic_trace_debugfs_file;
25static struct dentry *fnic_trace_enable;
26static struct dentry *fnic_stats_debugfs_root;
27
28static struct dentry *fnic_fc_trace_debugfs_file;
29static struct dentry *fnic_fc_rdata_trace_debugfs_file;
30static struct dentry *fnic_fc_trace_enable;
31static struct dentry *fnic_fc_trace_clear;
32
33struct fc_trace_flag_type {
34 u8 fc_row_file;
35 u8 fc_normal_file;
36 u8 fnic_trace;
37 u8 fc_trace;
38 u8 fc_clear;
39};
40
41static struct fc_trace_flag_type *fc_trc_flag;
42
43
44
45
46
47
48
49
50
51
52int fnic_debugfs_init(void)
53{
54 int rc = -1;
55 fnic_trace_debugfs_root = debugfs_create_dir("fnic", NULL);
56 if (!fnic_trace_debugfs_root) {
57 printk(KERN_DEBUG "Cannot create debugfs root\n");
58 return rc;
59 }
60
61 if (!fnic_trace_debugfs_root) {
62 printk(KERN_DEBUG
63 "fnic root directory doesn't exist in debugfs\n");
64 return rc;
65 }
66
67 fnic_stats_debugfs_root = debugfs_create_dir("statistics",
68 fnic_trace_debugfs_root);
69 if (!fnic_stats_debugfs_root) {
70 printk(KERN_DEBUG "Cannot create Statistics directory\n");
71 return rc;
72 }
73
74
75 fc_trc_flag = (struct fc_trace_flag_type *)
76 vmalloc(sizeof(struct fc_trace_flag_type));
77
78 if (fc_trc_flag) {
79 fc_trc_flag->fc_row_file = 0;
80 fc_trc_flag->fc_normal_file = 1;
81 fc_trc_flag->fnic_trace = 2;
82 fc_trc_flag->fc_trace = 3;
83 fc_trc_flag->fc_clear = 4;
84 }
85
86 rc = 0;
87 return rc;
88}
89
90
91
92
93
94
95
96
97void fnic_debugfs_terminate(void)
98{
99 debugfs_remove(fnic_stats_debugfs_root);
100 fnic_stats_debugfs_root = NULL;
101
102 debugfs_remove(fnic_trace_debugfs_root);
103 fnic_trace_debugfs_root = NULL;
104
105 if (fc_trc_flag)
106 vfree(fc_trc_flag);
107}
108
109
110
111
112
113
114
115
116
117
118
119
120
121static int fnic_trace_ctrl_open(struct inode *inode, struct file *filp)
122{
123 filp->private_data = inode->i_private;
124 return 0;
125}
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146static ssize_t fnic_trace_ctrl_read(struct file *filp,
147 char __user *ubuf,
148 size_t cnt, loff_t *ppos)
149{
150 char buf[64];
151 int len;
152 u8 *trace_type;
153 len = 0;
154 trace_type = (u8 *)filp->private_data;
155 if (*trace_type == fc_trc_flag->fnic_trace)
156 len = sprintf(buf, "%u\n", fnic_tracing_enabled);
157 else if (*trace_type == fc_trc_flag->fc_trace)
158 len = sprintf(buf, "%u\n", fnic_fc_tracing_enabled);
159 else if (*trace_type == fc_trc_flag->fc_clear)
160 len = sprintf(buf, "%u\n", fnic_fc_trace_cleared);
161 else
162 pr_err("fnic: Cannot read to any debugfs file\n");
163
164 return simple_read_from_buffer(ubuf, cnt, ppos, buf, len);
165}
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184static ssize_t fnic_trace_ctrl_write(struct file *filp,
185 const char __user *ubuf,
186 size_t cnt, loff_t *ppos)
187{
188 char buf[64];
189 unsigned long val;
190 int ret;
191 u8 *trace_type;
192 trace_type = (u8 *)filp->private_data;
193
194 if (cnt >= sizeof(buf))
195 return -EINVAL;
196
197 if (copy_from_user(&buf, ubuf, cnt))
198 return -EFAULT;
199
200 buf[cnt] = 0;
201
202 ret = kstrtoul(buf, 10, &val);
203 if (ret < 0)
204 return ret;
205
206 if (*trace_type == fc_trc_flag->fnic_trace)
207 fnic_tracing_enabled = val;
208 else if (*trace_type == fc_trc_flag->fc_trace)
209 fnic_fc_tracing_enabled = val;
210 else if (*trace_type == fc_trc_flag->fc_clear)
211 fnic_fc_trace_cleared = val;
212 else
213 pr_err("fnic: cannot write to any debufs file\n");
214
215 (*ppos)++;
216
217 return cnt;
218}
219
220static const struct file_operations fnic_trace_ctrl_fops = {
221 .owner = THIS_MODULE,
222 .open = fnic_trace_ctrl_open,
223 .read = fnic_trace_ctrl_read,
224 .write = fnic_trace_ctrl_write,
225};
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242static int fnic_trace_debugfs_open(struct inode *inode,
243 struct file *file)
244{
245 fnic_dbgfs_t *fnic_dbg_prt;
246 u8 *rdata_ptr;
247 rdata_ptr = (u8 *)inode->i_private;
248 fnic_dbg_prt = kzalloc(sizeof(fnic_dbgfs_t), GFP_KERNEL);
249 if (!fnic_dbg_prt)
250 return -ENOMEM;
251
252 if (*rdata_ptr == fc_trc_flag->fnic_trace) {
253 fnic_dbg_prt->buffer = vmalloc(3 *
254 (trace_max_pages * PAGE_SIZE));
255 if (!fnic_dbg_prt->buffer) {
256 kfree(fnic_dbg_prt);
257 return -ENOMEM;
258 }
259 memset((void *)fnic_dbg_prt->buffer, 0,
260 3 * (trace_max_pages * PAGE_SIZE));
261 fnic_dbg_prt->buffer_len = fnic_get_trace_data(fnic_dbg_prt);
262 } else {
263 fnic_dbg_prt->buffer =
264 vmalloc(3 * (fnic_fc_trace_max_pages * PAGE_SIZE));
265 if (!fnic_dbg_prt->buffer) {
266 kfree(fnic_dbg_prt);
267 return -ENOMEM;
268 }
269 memset((void *)fnic_dbg_prt->buffer, 0,
270 3 * (fnic_fc_trace_max_pages * PAGE_SIZE));
271 fnic_dbg_prt->buffer_len =
272 fnic_fc_trace_get_data(fnic_dbg_prt, *rdata_ptr);
273 }
274 file->private_data = fnic_dbg_prt;
275
276 return 0;
277}
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296static loff_t fnic_trace_debugfs_lseek(struct file *file,
297 loff_t offset,
298 int howto)
299{
300 fnic_dbgfs_t *fnic_dbg_prt = file->private_data;
301 return fixed_size_llseek(file, offset, howto,
302 fnic_dbg_prt->buffer_len);
303}
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321static ssize_t fnic_trace_debugfs_read(struct file *file,
322 char __user *ubuf,
323 size_t nbytes,
324 loff_t *pos)
325{
326 fnic_dbgfs_t *fnic_dbg_prt = file->private_data;
327 int rc = 0;
328 rc = simple_read_from_buffer(ubuf, nbytes, pos,
329 fnic_dbg_prt->buffer,
330 fnic_dbg_prt->buffer_len);
331 return rc;
332}
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347static int fnic_trace_debugfs_release(struct inode *inode,
348 struct file *file)
349{
350 fnic_dbgfs_t *fnic_dbg_prt = file->private_data;
351
352 vfree(fnic_dbg_prt->buffer);
353 kfree(fnic_dbg_prt);
354 return 0;
355}
356
357static const struct file_operations fnic_trace_debugfs_fops = {
358 .owner = THIS_MODULE,
359 .open = fnic_trace_debugfs_open,
360 .llseek = fnic_trace_debugfs_lseek,
361 .read = fnic_trace_debugfs_read,
362 .release = fnic_trace_debugfs_release,
363};
364
365
366
367
368
369
370
371
372
373
374
375int fnic_trace_debugfs_init(void)
376{
377 int rc = -1;
378 if (!fnic_trace_debugfs_root) {
379 printk(KERN_DEBUG
380 "FNIC Debugfs root directory doesn't exist\n");
381 return rc;
382 }
383 fnic_trace_enable = debugfs_create_file("tracing_enable",
384 S_IFREG|S_IRUGO|S_IWUSR,
385 fnic_trace_debugfs_root,
386 &(fc_trc_flag->fnic_trace),
387 &fnic_trace_ctrl_fops);
388
389 if (!fnic_trace_enable) {
390 printk(KERN_DEBUG
391 "Cannot create trace_enable file under debugfs\n");
392 return rc;
393 }
394
395 fnic_trace_debugfs_file = debugfs_create_file("trace",
396 S_IFREG|S_IRUGO|S_IWUSR,
397 fnic_trace_debugfs_root,
398 &(fc_trc_flag->fnic_trace),
399 &fnic_trace_debugfs_fops);
400
401 if (!fnic_trace_debugfs_file) {
402 printk(KERN_DEBUG
403 "Cannot create trace file under debugfs\n");
404 return rc;
405 }
406 rc = 0;
407 return rc;
408}
409
410
411
412
413
414
415
416
417void fnic_trace_debugfs_terminate(void)
418{
419 debugfs_remove(fnic_trace_debugfs_file);
420 fnic_trace_debugfs_file = NULL;
421
422 debugfs_remove(fnic_trace_enable);
423 fnic_trace_enable = NULL;
424}
425
426
427
428
429
430
431
432
433
434
435
436
437
438int fnic_fc_trace_debugfs_init(void)
439{
440 int rc = -1;
441
442 if (!fnic_trace_debugfs_root) {
443 pr_err("fnic:Debugfs root directory doesn't exist\n");
444 return rc;
445 }
446
447 fnic_fc_trace_enable = debugfs_create_file("fc_trace_enable",
448 S_IFREG|S_IRUGO|S_IWUSR,
449 fnic_trace_debugfs_root,
450 &(fc_trc_flag->fc_trace),
451 &fnic_trace_ctrl_fops);
452
453 if (!fnic_fc_trace_enable) {
454 pr_err("fnic: Failed create fc_trace_enable file\n");
455 return rc;
456 }
457
458 fnic_fc_trace_clear = debugfs_create_file("fc_trace_clear",
459 S_IFREG|S_IRUGO|S_IWUSR,
460 fnic_trace_debugfs_root,
461 &(fc_trc_flag->fc_clear),
462 &fnic_trace_ctrl_fops);
463
464 if (!fnic_fc_trace_clear) {
465 pr_err("fnic: Failed to create fc_trace_enable file\n");
466 return rc;
467 }
468
469 fnic_fc_rdata_trace_debugfs_file =
470 debugfs_create_file("fc_trace_rdata",
471 S_IFREG|S_IRUGO|S_IWUSR,
472 fnic_trace_debugfs_root,
473 &(fc_trc_flag->fc_normal_file),
474 &fnic_trace_debugfs_fops);
475
476 if (!fnic_fc_rdata_trace_debugfs_file) {
477 pr_err("fnic: Failed create fc_rdata_trace file\n");
478 return rc;
479 }
480
481 fnic_fc_trace_debugfs_file =
482 debugfs_create_file("fc_trace",
483 S_IFREG|S_IRUGO|S_IWUSR,
484 fnic_trace_debugfs_root,
485 &(fc_trc_flag->fc_row_file),
486 &fnic_trace_debugfs_fops);
487
488 if (!fnic_fc_trace_debugfs_file) {
489 pr_err("fnic: Failed to create fc_trace file\n");
490 return rc;
491 }
492 rc = 0;
493 return rc;
494}
495
496
497
498
499
500
501
502
503
504void fnic_fc_trace_debugfs_terminate(void)
505{
506 debugfs_remove(fnic_fc_trace_debugfs_file);
507 fnic_fc_trace_debugfs_file = NULL;
508
509 debugfs_remove(fnic_fc_rdata_trace_debugfs_file);
510 fnic_fc_rdata_trace_debugfs_file = NULL;
511
512 debugfs_remove(fnic_fc_trace_enable);
513 fnic_fc_trace_enable = NULL;
514
515 debugfs_remove(fnic_fc_trace_clear);
516 fnic_fc_trace_clear = NULL;
517}
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532static int fnic_reset_stats_open(struct inode *inode, struct file *file)
533{
534 struct stats_debug_info *debug;
535
536 debug = kzalloc(sizeof(struct stats_debug_info), GFP_KERNEL);
537 if (!debug)
538 return -ENOMEM;
539
540 debug->i_private = inode->i_private;
541
542 file->private_data = debug;
543
544 return 0;
545}
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562static ssize_t fnic_reset_stats_read(struct file *file,
563 char __user *ubuf,
564 size_t cnt, loff_t *ppos)
565{
566 struct stats_debug_info *debug = file->private_data;
567 struct fnic *fnic = (struct fnic *)debug->i_private;
568 char buf[64];
569 int len;
570
571 len = sprintf(buf, "%u\n", fnic->reset_stats);
572
573 return simple_read_from_buffer(ubuf, cnt, ppos, buf, len);
574}
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590static ssize_t fnic_reset_stats_write(struct file *file,
591 const char __user *ubuf,
592 size_t cnt, loff_t *ppos)
593{
594 struct stats_debug_info *debug = file->private_data;
595 struct fnic *fnic = (struct fnic *)debug->i_private;
596 struct fnic_stats *stats = &fnic->fnic_stats;
597 u64 *io_stats_p = (u64 *)&stats->io_stats;
598 u64 *fw_stats_p = (u64 *)&stats->fw_stats;
599 char buf[64];
600 unsigned long val;
601 int ret;
602
603 if (cnt >= sizeof(buf))
604 return -EINVAL;
605
606 if (copy_from_user(&buf, ubuf, cnt))
607 return -EFAULT;
608
609 buf[cnt] = 0;
610
611 ret = kstrtoul(buf, 10, &val);
612 if (ret < 0)
613 return ret;
614
615 fnic->reset_stats = val;
616
617 if (fnic->reset_stats) {
618
619
620
621
622 atomic64_set(&fnic->io_cmpl_skip,
623 atomic64_read(&stats->io_stats.active_ios));
624 memset(&stats->abts_stats, 0, sizeof(struct abort_stats));
625 memset(&stats->term_stats, 0,
626 sizeof(struct terminate_stats));
627 memset(&stats->reset_stats, 0, sizeof(struct reset_stats));
628 memset(&stats->misc_stats, 0, sizeof(struct misc_stats));
629 memset(&stats->vlan_stats, 0, sizeof(struct vlan_stats));
630 memset(io_stats_p+1, 0,
631 sizeof(struct io_path_stats) - sizeof(u64));
632 memset(fw_stats_p+1, 0,
633 sizeof(struct fw_stats) - sizeof(u64));
634 }
635
636 (*ppos)++;
637 return cnt;
638}
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653static int fnic_reset_stats_release(struct inode *inode,
654 struct file *file)
655{
656 struct stats_debug_info *debug = file->private_data;
657 kfree(debug);
658 return 0;
659}
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674static int fnic_stats_debugfs_open(struct inode *inode,
675 struct file *file)
676{
677 struct fnic *fnic = inode->i_private;
678 struct fnic_stats *fnic_stats = &fnic->fnic_stats;
679 struct stats_debug_info *debug;
680 int buf_size = 2 * PAGE_SIZE;
681
682 debug = kzalloc(sizeof(struct stats_debug_info), GFP_KERNEL);
683 if (!debug)
684 return -ENOMEM;
685
686 debug->debug_buffer = vmalloc(buf_size);
687 if (!debug->debug_buffer) {
688 kfree(debug);
689 return -ENOMEM;
690 }
691
692 debug->buf_size = buf_size;
693 memset((void *)debug->debug_buffer, 0, buf_size);
694 debug->buffer_len = fnic_get_stats_data(debug, fnic_stats);
695
696 file->private_data = debug;
697
698 return 0;
699}
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717static ssize_t fnic_stats_debugfs_read(struct file *file,
718 char __user *ubuf,
719 size_t nbytes,
720 loff_t *pos)
721{
722 struct stats_debug_info *debug = file->private_data;
723 int rc = 0;
724 rc = simple_read_from_buffer(ubuf, nbytes, pos,
725 debug->debug_buffer,
726 debug->buffer_len);
727 return rc;
728}
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743static int fnic_stats_debugfs_release(struct inode *inode,
744 struct file *file)
745{
746 struct stats_debug_info *debug = file->private_data;
747 vfree(debug->debug_buffer);
748 kfree(debug);
749 return 0;
750}
751
752static const struct file_operations fnic_stats_debugfs_fops = {
753 .owner = THIS_MODULE,
754 .open = fnic_stats_debugfs_open,
755 .read = fnic_stats_debugfs_read,
756 .release = fnic_stats_debugfs_release,
757};
758
759static const struct file_operations fnic_reset_debugfs_fops = {
760 .owner = THIS_MODULE,
761 .open = fnic_reset_stats_open,
762 .read = fnic_reset_stats_read,
763 .write = fnic_reset_stats_write,
764 .release = fnic_reset_stats_release,
765};
766
767
768
769
770
771
772
773
774
775int fnic_stats_debugfs_init(struct fnic *fnic)
776{
777 int rc = -1;
778 char name[16];
779
780 snprintf(name, sizeof(name), "host%d", fnic->lport->host->host_no);
781
782 if (!fnic_stats_debugfs_root) {
783 printk(KERN_DEBUG "fnic_stats root doesn't exist\n");
784 return rc;
785 }
786 fnic->fnic_stats_debugfs_host = debugfs_create_dir(name,
787 fnic_stats_debugfs_root);
788 if (!fnic->fnic_stats_debugfs_host) {
789 printk(KERN_DEBUG "Cannot create host directory\n");
790 return rc;
791 }
792
793 fnic->fnic_stats_debugfs_file = debugfs_create_file("stats",
794 S_IFREG|S_IRUGO|S_IWUSR,
795 fnic->fnic_stats_debugfs_host,
796 fnic,
797 &fnic_stats_debugfs_fops);
798 if (!fnic->fnic_stats_debugfs_file) {
799 printk(KERN_DEBUG "Cannot create host stats file\n");
800 return rc;
801 }
802
803 fnic->fnic_reset_debugfs_file = debugfs_create_file("reset_stats",
804 S_IFREG|S_IRUGO|S_IWUSR,
805 fnic->fnic_stats_debugfs_host,
806 fnic,
807 &fnic_reset_debugfs_fops);
808 if (!fnic->fnic_reset_debugfs_file) {
809 printk(KERN_DEBUG "Cannot create host stats file\n");
810 return rc;
811 }
812 rc = 0;
813 return rc;
814}
815
816
817
818
819
820
821
822
823void fnic_stats_debugfs_remove(struct fnic *fnic)
824{
825 if (!fnic)
826 return;
827
828 debugfs_remove(fnic->fnic_stats_debugfs_file);
829 fnic->fnic_stats_debugfs_file = NULL;
830
831 debugfs_remove(fnic->fnic_reset_debugfs_file);
832 fnic->fnic_reset_debugfs_file = NULL;
833
834 debugfs_remove(fnic->fnic_stats_debugfs_host);
835 fnic->fnic_stats_debugfs_host = NULL;
836}
837