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