Merge tag 'ceph-for-4.13-rc8' of git://github.com/ceph/ceph-client
[linux/fpc-iii.git] / drivers / scsi / fnic / fnic_debugfs.c
blob5e3d909cfc5370a552bfb4320d481e58fe45834d
1 /*
2 * Copyright 2012 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>
21 #include <linux/vmalloc.h>
22 #include "fnic.h"
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;
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;
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;
42 static struct fc_trace_flag_type *fc_trc_flag;
45 * fnic_debugfs_init - Initialize debugfs for fnic debug logging
47 * Description:
48 * When Debugfs is configured this routine sets up the fnic debugfs
49 * file system. If not already created, this routine will create the
50 * fnic directory and statistics directory for trace buffer and
51 * stats logging.
53 int fnic_debugfs_init(void)
55 int rc = -1;
56 fnic_trace_debugfs_root = debugfs_create_dir("fnic", NULL);
57 if (!fnic_trace_debugfs_root) {
58 printk(KERN_DEBUG "Cannot create debugfs root\n");
59 return rc;
62 if (!fnic_trace_debugfs_root) {
63 printk(KERN_DEBUG
64 "fnic root directory doesn't exist in debugfs\n");
65 return rc;
68 fnic_stats_debugfs_root = debugfs_create_dir("statistics",
69 fnic_trace_debugfs_root);
70 if (!fnic_stats_debugfs_root) {
71 printk(KERN_DEBUG "Cannot create Statistics directory\n");
72 return rc;
75 /* Allocate memory to structure */
76 fc_trc_flag = (struct fc_trace_flag_type *)
77 vmalloc(sizeof(struct fc_trace_flag_type));
79 if (fc_trc_flag) {
80 fc_trc_flag->fc_row_file = 0;
81 fc_trc_flag->fc_normal_file = 1;
82 fc_trc_flag->fnic_trace = 2;
83 fc_trc_flag->fc_trace = 3;
84 fc_trc_flag->fc_clear = 4;
87 rc = 0;
88 return rc;
92 * fnic_debugfs_terminate - Tear down debugfs infrastructure
94 * Description:
95 * When Debugfs is configured this routine removes debugfs file system
96 * elements that are specific to fnic.
98 void fnic_debugfs_terminate(void)
100 debugfs_remove(fnic_stats_debugfs_root);
101 fnic_stats_debugfs_root = NULL;
103 debugfs_remove(fnic_trace_debugfs_root);
104 fnic_trace_debugfs_root = NULL;
106 if (fc_trc_flag)
107 vfree(fc_trc_flag);
111 * fnic_trace_ctrl_open - Open the trace_enable file for fnic_trace
112 * Or Open fc_trace_enable file for fc_trace
113 * @inode: The inode pointer.
114 * @file: The file pointer to attach the trace enable/disable flag.
116 * Description:
117 * This routine opens a debugsfs file trace_enable or fc_trace_enable.
119 * Returns:
120 * This function returns zero if successful.
122 static int fnic_trace_ctrl_open(struct inode *inode, struct file *filp)
124 filp->private_data = inode->i_private;
125 return 0;
129 * fnic_trace_ctrl_read -
130 * Read trace_enable ,fc_trace_enable
131 * or fc_trace_clear debugfs file
132 * @filp: The file pointer to read from.
133 * @ubuf: The buffer to copy the data to.
134 * @cnt: The number of bytes to read.
135 * @ppos: The position in the file to start reading from.
137 * Description:
138 * This routine reads value of variable fnic_tracing_enabled or
139 * fnic_fc_tracing_enabled or fnic_fc_trace_cleared
140 * and stores into local @buf.
141 * It will start reading file at @ppos and
142 * copy up to @cnt of data to @ubuf from @buf.
144 * Returns:
145 * This function returns the amount of data that was read.
147 static ssize_t fnic_trace_ctrl_read(struct file *filp,
148 char __user *ubuf,
149 size_t cnt, loff_t *ppos)
151 char buf[64];
152 int len;
153 u8 *trace_type;
154 len = 0;
155 trace_type = (u8 *)filp->private_data;
156 if (*trace_type == fc_trc_flag->fnic_trace)
157 len = sprintf(buf, "%u\n", fnic_tracing_enabled);
158 else if (*trace_type == fc_trc_flag->fc_trace)
159 len = sprintf(buf, "%u\n", fnic_fc_tracing_enabled);
160 else if (*trace_type == fc_trc_flag->fc_clear)
161 len = sprintf(buf, "%u\n", fnic_fc_trace_cleared);
162 else
163 pr_err("fnic: Cannot read to any debugfs file\n");
165 return simple_read_from_buffer(ubuf, cnt, ppos, buf, len);
169 * fnic_trace_ctrl_write -
170 * Write to trace_enable, fc_trace_enable or
171 * fc_trace_clear debugfs file
172 * @filp: The file pointer to write from.
173 * @ubuf: The buffer to copy the data from.
174 * @cnt: The number of bytes to write.
175 * @ppos: The position in the file to start writing to.
177 * Description:
178 * This routine writes data from user buffer @ubuf to buffer @buf and
179 * sets fc_trace_enable ,tracing_enable or fnic_fc_trace_cleared
180 * value as per user input.
182 * Returns:
183 * This function returns the amount of data that was written.
185 static ssize_t fnic_trace_ctrl_write(struct file *filp,
186 const char __user *ubuf,
187 size_t cnt, loff_t *ppos)
189 char buf[64];
190 unsigned long val;
191 int ret;
192 u8 *trace_type;
193 trace_type = (u8 *)filp->private_data;
195 if (cnt >= sizeof(buf))
196 return -EINVAL;
198 if (copy_from_user(&buf, ubuf, cnt))
199 return -EFAULT;
201 buf[cnt] = 0;
203 ret = kstrtoul(buf, 10, &val);
204 if (ret < 0)
205 return ret;
207 if (*trace_type == fc_trc_flag->fnic_trace)
208 fnic_tracing_enabled = val;
209 else if (*trace_type == fc_trc_flag->fc_trace)
210 fnic_fc_tracing_enabled = val;
211 else if (*trace_type == fc_trc_flag->fc_clear)
212 fnic_fc_trace_cleared = val;
213 else
214 pr_err("fnic: cannot write to any debugfs file\n");
216 (*ppos)++;
218 return cnt;
221 static const struct file_operations fnic_trace_ctrl_fops = {
222 .owner = THIS_MODULE,
223 .open = fnic_trace_ctrl_open,
224 .read = fnic_trace_ctrl_read,
225 .write = fnic_trace_ctrl_write,
229 * fnic_trace_debugfs_open - Open the fnic trace log
230 * @inode: The inode pointer
231 * @file: The file pointer to attach the log output
233 * Description:
234 * This routine is the entry point for the debugfs open file operation.
235 * It allocates the necessary buffer for the log, fills the buffer from
236 * the in-memory log and then returns a pointer to that log in
237 * the private_data field in @file.
239 * Returns:
240 * This function returns zero if successful. On error it will return
241 * a negative error value.
243 static int fnic_trace_debugfs_open(struct inode *inode,
244 struct file *file)
246 fnic_dbgfs_t *fnic_dbg_prt;
247 u8 *rdata_ptr;
248 rdata_ptr = (u8 *)inode->i_private;
249 fnic_dbg_prt = kzalloc(sizeof(fnic_dbgfs_t), GFP_KERNEL);
250 if (!fnic_dbg_prt)
251 return -ENOMEM;
253 if (*rdata_ptr == fc_trc_flag->fnic_trace) {
254 fnic_dbg_prt->buffer = vmalloc(3 *
255 (trace_max_pages * PAGE_SIZE));
256 if (!fnic_dbg_prt->buffer) {
257 kfree(fnic_dbg_prt);
258 return -ENOMEM;
260 memset((void *)fnic_dbg_prt->buffer, 0,
261 3 * (trace_max_pages * PAGE_SIZE));
262 fnic_dbg_prt->buffer_len = fnic_get_trace_data(fnic_dbg_prt);
263 } else {
264 fnic_dbg_prt->buffer =
265 vmalloc(3 * (fnic_fc_trace_max_pages * PAGE_SIZE));
266 if (!fnic_dbg_prt->buffer) {
267 kfree(fnic_dbg_prt);
268 return -ENOMEM;
270 memset((void *)fnic_dbg_prt->buffer, 0,
271 3 * (fnic_fc_trace_max_pages * PAGE_SIZE));
272 fnic_dbg_prt->buffer_len =
273 fnic_fc_trace_get_data(fnic_dbg_prt, *rdata_ptr);
275 file->private_data = fnic_dbg_prt;
277 return 0;
281 * fnic_trace_debugfs_lseek - Seek through a debugfs file
282 * @file: The file pointer to seek through.
283 * @offset: The offset to seek to or the amount to seek by.
284 * @howto: Indicates how to seek.
286 * Description:
287 * This routine is the entry point for the debugfs lseek file operation.
288 * The @howto parameter indicates whether @offset is the offset to directly
289 * seek to, or if it is a value to seek forward or reverse by. This function
290 * figures out what the new offset of the debugfs file will be and assigns
291 * that value to the f_pos field of @file.
293 * Returns:
294 * This function returns the new offset if successful and returns a negative
295 * error if unable to process the seek.
297 static loff_t fnic_trace_debugfs_lseek(struct file *file,
298 loff_t offset,
299 int howto)
301 fnic_dbgfs_t *fnic_dbg_prt = file->private_data;
302 return fixed_size_llseek(file, offset, howto,
303 fnic_dbg_prt->buffer_len);
307 * fnic_trace_debugfs_read - Read a debugfs file
308 * @file: The file pointer to read from.
309 * @ubuf: The buffer to copy the data to.
310 * @nbytes: The number of bytes to read.
311 * @pos: The position in the file to start reading from.
313 * Description:
314 * This routine reads data from the buffer indicated in the private_data
315 * field of @file. It will start reading at @pos and copy up to @nbytes of
316 * data to @ubuf.
318 * Returns:
319 * This function returns the amount of data that was read (this could be
320 * less than @nbytes if the end of the file was reached).
322 static ssize_t fnic_trace_debugfs_read(struct file *file,
323 char __user *ubuf,
324 size_t nbytes,
325 loff_t *pos)
327 fnic_dbgfs_t *fnic_dbg_prt = file->private_data;
328 int rc = 0;
329 rc = simple_read_from_buffer(ubuf, nbytes, pos,
330 fnic_dbg_prt->buffer,
331 fnic_dbg_prt->buffer_len);
332 return rc;
336 * fnic_trace_debugfs_release - Release the buffer used to store
337 * debugfs file data
338 * @inode: The inode pointer
339 * @file: The file pointer that contains the buffer to release
341 * Description:
342 * This routine frees the buffer that was allocated when the debugfs
343 * file was opened.
345 * Returns:
346 * This function returns zero.
348 static int fnic_trace_debugfs_release(struct inode *inode,
349 struct file *file)
351 fnic_dbgfs_t *fnic_dbg_prt = file->private_data;
353 vfree(fnic_dbg_prt->buffer);
354 kfree(fnic_dbg_prt);
355 return 0;
358 static const struct file_operations fnic_trace_debugfs_fops = {
359 .owner = THIS_MODULE,
360 .open = fnic_trace_debugfs_open,
361 .llseek = fnic_trace_debugfs_lseek,
362 .read = fnic_trace_debugfs_read,
363 .release = fnic_trace_debugfs_release,
367 * fnic_trace_debugfs_init - Initialize debugfs for fnic trace logging
369 * Description:
370 * When Debugfs is configured this routine sets up the fnic debugfs
371 * file system. If not already created, this routine will create the
372 * create file trace to log fnic trace buffer output into debugfs and
373 * it will also create file trace_enable to control enable/disable of
374 * trace logging into trace buffer.
376 int fnic_trace_debugfs_init(void)
378 int rc = -1;
379 if (!fnic_trace_debugfs_root) {
380 printk(KERN_DEBUG
381 "FNIC Debugfs root directory doesn't exist\n");
382 return rc;
384 fnic_trace_enable = debugfs_create_file("tracing_enable",
385 S_IFREG|S_IRUGO|S_IWUSR,
386 fnic_trace_debugfs_root,
387 &(fc_trc_flag->fnic_trace),
388 &fnic_trace_ctrl_fops);
390 if (!fnic_trace_enable) {
391 printk(KERN_DEBUG
392 "Cannot create trace_enable file under debugfs\n");
393 return rc;
396 fnic_trace_debugfs_file = debugfs_create_file("trace",
397 S_IFREG|S_IRUGO|S_IWUSR,
398 fnic_trace_debugfs_root,
399 &(fc_trc_flag->fnic_trace),
400 &fnic_trace_debugfs_fops);
402 if (!fnic_trace_debugfs_file) {
403 printk(KERN_DEBUG
404 "Cannot create trace file under debugfs\n");
405 return rc;
407 rc = 0;
408 return rc;
412 * fnic_trace_debugfs_terminate - Tear down debugfs infrastructure
414 * Description:
415 * When Debugfs is configured this routine removes debugfs file system
416 * elements that are specific to fnic trace logging.
418 void fnic_trace_debugfs_terminate(void)
420 debugfs_remove(fnic_trace_debugfs_file);
421 fnic_trace_debugfs_file = NULL;
423 debugfs_remove(fnic_trace_enable);
424 fnic_trace_enable = NULL;
428 * fnic_fc_trace_debugfs_init -
429 * Initialize debugfs for fnic control frame trace logging
431 * Description:
432 * When Debugfs is configured this routine sets up the fnic_fc debugfs
433 * file system. If not already created, this routine will create the
434 * create file trace to log fnic fc trace buffer output into debugfs and
435 * it will also create file fc_trace_enable to control enable/disable of
436 * trace logging into trace buffer.
439 int fnic_fc_trace_debugfs_init(void)
441 int rc = -1;
443 if (!fnic_trace_debugfs_root) {
444 pr_err("fnic:Debugfs root directory doesn't exist\n");
445 return rc;
448 fnic_fc_trace_enable = debugfs_create_file("fc_trace_enable",
449 S_IFREG|S_IRUGO|S_IWUSR,
450 fnic_trace_debugfs_root,
451 &(fc_trc_flag->fc_trace),
452 &fnic_trace_ctrl_fops);
454 if (!fnic_fc_trace_enable) {
455 pr_err("fnic: Failed create fc_trace_enable file\n");
456 return rc;
459 fnic_fc_trace_clear = debugfs_create_file("fc_trace_clear",
460 S_IFREG|S_IRUGO|S_IWUSR,
461 fnic_trace_debugfs_root,
462 &(fc_trc_flag->fc_clear),
463 &fnic_trace_ctrl_fops);
465 if (!fnic_fc_trace_clear) {
466 pr_err("fnic: Failed to create fc_trace_enable file\n");
467 return rc;
470 fnic_fc_rdata_trace_debugfs_file =
471 debugfs_create_file("fc_trace_rdata",
472 S_IFREG|S_IRUGO|S_IWUSR,
473 fnic_trace_debugfs_root,
474 &(fc_trc_flag->fc_normal_file),
475 &fnic_trace_debugfs_fops);
477 if (!fnic_fc_rdata_trace_debugfs_file) {
478 pr_err("fnic: Failed create fc_rdata_trace file\n");
479 return rc;
482 fnic_fc_trace_debugfs_file =
483 debugfs_create_file("fc_trace",
484 S_IFREG|S_IRUGO|S_IWUSR,
485 fnic_trace_debugfs_root,
486 &(fc_trc_flag->fc_row_file),
487 &fnic_trace_debugfs_fops);
489 if (!fnic_fc_trace_debugfs_file) {
490 pr_err("fnic: Failed to create fc_trace file\n");
491 return rc;
493 rc = 0;
494 return rc;
498 * fnic_fc_trace_debugfs_terminate - Tear down debugfs infrastructure
500 * Description:
501 * When Debugfs is configured this routine removes debugfs file system
502 * elements that are specific to fnic_fc trace logging.
505 void fnic_fc_trace_debugfs_terminate(void)
507 debugfs_remove(fnic_fc_trace_debugfs_file);
508 fnic_fc_trace_debugfs_file = NULL;
510 debugfs_remove(fnic_fc_rdata_trace_debugfs_file);
511 fnic_fc_rdata_trace_debugfs_file = NULL;
513 debugfs_remove(fnic_fc_trace_enable);
514 fnic_fc_trace_enable = NULL;
516 debugfs_remove(fnic_fc_trace_clear);
517 fnic_fc_trace_clear = NULL;
521 * fnic_reset_stats_open - Open the reset_stats file
522 * @inode: The inode pointer.
523 * @file: The file pointer to attach the stats reset flag.
525 * Description:
526 * This routine opens a debugsfs file reset_stats and stores i_private data
527 * to debug structure to retrieve later for while performing other
528 * file oprations.
530 * Returns:
531 * This function returns zero if successful.
533 static int fnic_reset_stats_open(struct inode *inode, struct file *file)
535 struct stats_debug_info *debug;
537 debug = kzalloc(sizeof(struct stats_debug_info), GFP_KERNEL);
538 if (!debug)
539 return -ENOMEM;
541 debug->i_private = inode->i_private;
543 file->private_data = debug;
545 return 0;
549 * fnic_reset_stats_read - Read a reset_stats debugfs file
550 * @filp: The file pointer to read from.
551 * @ubuf: The buffer to copy the data to.
552 * @cnt: The number of bytes to read.
553 * @ppos: The position in the file to start reading from.
555 * Description:
556 * This routine reads value of variable reset_stats
557 * and stores into local @buf. It will start reading file at @ppos and
558 * copy up to @cnt of data to @ubuf from @buf.
560 * Returns:
561 * This function returns the amount of data that was read.
563 static ssize_t fnic_reset_stats_read(struct file *file,
564 char __user *ubuf,
565 size_t cnt, loff_t *ppos)
567 struct stats_debug_info *debug = file->private_data;
568 struct fnic *fnic = (struct fnic *)debug->i_private;
569 char buf[64];
570 int len;
572 len = sprintf(buf, "%u\n", fnic->reset_stats);
574 return simple_read_from_buffer(ubuf, cnt, ppos, buf, len);
578 * fnic_reset_stats_write - Write to reset_stats debugfs file
579 * @filp: The file pointer to write from.
580 * @ubuf: The buffer to copy the data from.
581 * @cnt: The number of bytes to write.
582 * @ppos: The position in the file to start writing to.
584 * Description:
585 * This routine writes data from user buffer @ubuf to buffer @buf and
586 * resets cumulative stats of fnic.
588 * Returns:
589 * This function returns the amount of data that was written.
591 static ssize_t fnic_reset_stats_write(struct file *file,
592 const char __user *ubuf,
593 size_t cnt, loff_t *ppos)
595 struct stats_debug_info *debug = file->private_data;
596 struct fnic *fnic = (struct fnic *)debug->i_private;
597 struct fnic_stats *stats = &fnic->fnic_stats;
598 u64 *io_stats_p = (u64 *)&stats->io_stats;
599 u64 *fw_stats_p = (u64 *)&stats->fw_stats;
600 char buf[64];
601 unsigned long val;
602 int ret;
604 if (cnt >= sizeof(buf))
605 return -EINVAL;
607 if (copy_from_user(&buf, ubuf, cnt))
608 return -EFAULT;
610 buf[cnt] = 0;
612 ret = kstrtoul(buf, 10, &val);
613 if (ret < 0)
614 return ret;
616 fnic->reset_stats = val;
618 if (fnic->reset_stats) {
619 /* Skip variable is used to avoid descrepancies to Num IOs
620 * and IO Completions stats. Skip incrementing No IO Compls
621 * for pending active IOs after reset stats
623 atomic64_set(&fnic->io_cmpl_skip,
624 atomic64_read(&stats->io_stats.active_ios));
625 memset(&stats->abts_stats, 0, sizeof(struct abort_stats));
626 memset(&stats->term_stats, 0,
627 sizeof(struct terminate_stats));
628 memset(&stats->reset_stats, 0, sizeof(struct reset_stats));
629 memset(&stats->misc_stats, 0, sizeof(struct misc_stats));
630 memset(&stats->vlan_stats, 0, sizeof(struct vlan_stats));
631 memset(io_stats_p+1, 0,
632 sizeof(struct io_path_stats) - sizeof(u64));
633 memset(fw_stats_p+1, 0,
634 sizeof(struct fw_stats) - sizeof(u64));
635 getnstimeofday(&stats->stats_timestamps.last_reset_time);
638 (*ppos)++;
639 return cnt;
643 * fnic_reset_stats_release - Release the buffer used to store
644 * debugfs file data
645 * @inode: The inode pointer
646 * @file: The file pointer that contains the buffer to release
648 * Description:
649 * This routine frees the buffer that was allocated when the debugfs
650 * file was opened.
652 * Returns:
653 * This function returns zero.
655 static int fnic_reset_stats_release(struct inode *inode,
656 struct file *file)
658 struct stats_debug_info *debug = file->private_data;
659 kfree(debug);
660 return 0;
664 * fnic_stats_debugfs_open - Open the stats file for specific host
665 * and get fnic stats.
666 * @inode: The inode pointer.
667 * @file: The file pointer to attach the specific host statistics.
669 * Description:
670 * This routine opens a debugsfs file stats of specific host and print
671 * fnic stats.
673 * Returns:
674 * This function returns zero if successful.
676 static int fnic_stats_debugfs_open(struct inode *inode,
677 struct file *file)
679 struct fnic *fnic = inode->i_private;
680 struct fnic_stats *fnic_stats = &fnic->fnic_stats;
681 struct stats_debug_info *debug;
682 int buf_size = 2 * PAGE_SIZE;
684 debug = kzalloc(sizeof(struct stats_debug_info), GFP_KERNEL);
685 if (!debug)
686 return -ENOMEM;
688 debug->debug_buffer = vmalloc(buf_size);
689 if (!debug->debug_buffer) {
690 kfree(debug);
691 return -ENOMEM;
694 debug->buf_size = buf_size;
695 memset((void *)debug->debug_buffer, 0, buf_size);
696 debug->buffer_len = fnic_get_stats_data(debug, fnic_stats);
698 file->private_data = debug;
700 return 0;
704 * fnic_stats_debugfs_read - Read a debugfs file
705 * @file: The file pointer to read from.
706 * @ubuf: The buffer to copy the data to.
707 * @nbytes: The number of bytes to read.
708 * @pos: The position in the file to start reading from.
710 * Description:
711 * This routine reads data from the buffer indicated in the private_data
712 * field of @file. It will start reading at @pos and copy up to @nbytes of
713 * data to @ubuf.
715 * Returns:
716 * This function returns the amount of data that was read (this could be
717 * less than @nbytes if the end of the file was reached).
719 static ssize_t fnic_stats_debugfs_read(struct file *file,
720 char __user *ubuf,
721 size_t nbytes,
722 loff_t *pos)
724 struct stats_debug_info *debug = file->private_data;
725 int rc = 0;
726 rc = simple_read_from_buffer(ubuf, nbytes, pos,
727 debug->debug_buffer,
728 debug->buffer_len);
729 return rc;
733 * fnic_stats_stats_release - Release the buffer used to store
734 * debugfs file data
735 * @inode: The inode pointer
736 * @file: The file pointer that contains the buffer to release
738 * Description:
739 * This routine frees the buffer that was allocated when the debugfs
740 * file was opened.
742 * Returns:
743 * This function returns zero.
745 static int fnic_stats_debugfs_release(struct inode *inode,
746 struct file *file)
748 struct stats_debug_info *debug = file->private_data;
749 vfree(debug->debug_buffer);
750 kfree(debug);
751 return 0;
754 static const struct file_operations fnic_stats_debugfs_fops = {
755 .owner = THIS_MODULE,
756 .open = fnic_stats_debugfs_open,
757 .read = fnic_stats_debugfs_read,
758 .release = fnic_stats_debugfs_release,
761 static const struct file_operations fnic_reset_debugfs_fops = {
762 .owner = THIS_MODULE,
763 .open = fnic_reset_stats_open,
764 .read = fnic_reset_stats_read,
765 .write = fnic_reset_stats_write,
766 .release = fnic_reset_stats_release,
770 * fnic_stats_init - Initialize stats struct and create stats file per fnic
772 * Description:
773 * When Debugfs is configured this routine sets up the stats file per fnic
774 * It will create file stats and reset_stats under statistics/host# directory
775 * to log per fnic stats.
777 int fnic_stats_debugfs_init(struct fnic *fnic)
779 int rc = -1;
780 char name[16];
782 snprintf(name, sizeof(name), "host%d", fnic->lport->host->host_no);
784 if (!fnic_stats_debugfs_root) {
785 printk(KERN_DEBUG "fnic_stats root doesn't exist\n");
786 return rc;
788 fnic->fnic_stats_debugfs_host = debugfs_create_dir(name,
789 fnic_stats_debugfs_root);
790 if (!fnic->fnic_stats_debugfs_host) {
791 printk(KERN_DEBUG "Cannot create host directory\n");
792 return rc;
795 fnic->fnic_stats_debugfs_file = debugfs_create_file("stats",
796 S_IFREG|S_IRUGO|S_IWUSR,
797 fnic->fnic_stats_debugfs_host,
798 fnic,
799 &fnic_stats_debugfs_fops);
800 if (!fnic->fnic_stats_debugfs_file) {
801 printk(KERN_DEBUG "Cannot create host stats file\n");
802 return rc;
805 fnic->fnic_reset_debugfs_file = debugfs_create_file("reset_stats",
806 S_IFREG|S_IRUGO|S_IWUSR,
807 fnic->fnic_stats_debugfs_host,
808 fnic,
809 &fnic_reset_debugfs_fops);
810 if (!fnic->fnic_reset_debugfs_file) {
811 printk(KERN_DEBUG "Cannot create host stats file\n");
812 return rc;
814 rc = 0;
815 return rc;
819 * fnic_stats_debugfs_remove - Tear down debugfs infrastructure of stats
821 * Description:
822 * When Debugfs is configured this routine removes debugfs file system
823 * elements that are specific to fnic stats.
825 void fnic_stats_debugfs_remove(struct fnic *fnic)
827 if (!fnic)
828 return;
830 debugfs_remove(fnic->fnic_stats_debugfs_file);
831 fnic->fnic_stats_debugfs_file = NULL;
833 debugfs_remove(fnic->fnic_reset_debugfs_file);
834 fnic->fnic_reset_debugfs_file = NULL;
836 debugfs_remove(fnic->fnic_stats_debugfs_host);
837 fnic->fnic_stats_debugfs_host = NULL;