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