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