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