14d7007b4SHiral Patel /* 24d7007b4SHiral Patel * Copyright 2012 Cisco Systems, Inc. All rights reserved. 34d7007b4SHiral Patel * 44d7007b4SHiral Patel * This program is free software; you may redistribute it and/or modify 54d7007b4SHiral Patel * it under the terms of the GNU General Public License as published by 64d7007b4SHiral Patel * the Free Software Foundation; version 2 of the License. 74d7007b4SHiral Patel * 84d7007b4SHiral Patel * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 94d7007b4SHiral Patel * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 104d7007b4SHiral Patel * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 114d7007b4SHiral Patel * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 124d7007b4SHiral Patel * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 134d7007b4SHiral Patel * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 144d7007b4SHiral Patel * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 154d7007b4SHiral Patel * SOFTWARE. 164d7007b4SHiral Patel */ 174d7007b4SHiral Patel 184d7007b4SHiral Patel #include <linux/module.h> 194d7007b4SHiral Patel #include <linux/errno.h> 204d7007b4SHiral Patel #include <linux/debugfs.h> 214d7007b4SHiral Patel #include "fnic.h" 224d7007b4SHiral Patel 234d7007b4SHiral Patel static struct dentry *fnic_trace_debugfs_root; 244d7007b4SHiral Patel static struct dentry *fnic_trace_debugfs_file; 254d7007b4SHiral Patel static struct dentry *fnic_trace_enable; 2667125b02SHiral Patel static struct dentry *fnic_stats_debugfs_root; 2767125b02SHiral Patel 28*abb14148SHiral Shah static struct dentry *fnic_fc_trace_debugfs_file; 29*abb14148SHiral Shah static struct dentry *fnic_fc_rdata_trace_debugfs_file; 30*abb14148SHiral Shah static struct dentry *fnic_fc_trace_enable; 31*abb14148SHiral Shah static struct dentry *fnic_fc_trace_clear; 32*abb14148SHiral Shah 33*abb14148SHiral Shah struct fc_trace_flag_type { 34*abb14148SHiral Shah u8 fc_row_file; 35*abb14148SHiral Shah u8 fc_normal_file; 36*abb14148SHiral Shah u8 fnic_trace; 37*abb14148SHiral Shah u8 fc_trace; 38*abb14148SHiral Shah u8 fc_clear; 39*abb14148SHiral Shah }; 40*abb14148SHiral Shah 41*abb14148SHiral Shah static struct fc_trace_flag_type *fc_trc_flag; 42*abb14148SHiral Shah 4367125b02SHiral Patel /* 4467125b02SHiral Patel * fnic_debugfs_init - Initialize debugfs for fnic debug logging 4567125b02SHiral Patel * 4667125b02SHiral Patel * Description: 4767125b02SHiral Patel * When Debugfs is configured this routine sets up the fnic debugfs 4867125b02SHiral Patel * file system. If not already created, this routine will create the 4967125b02SHiral Patel * fnic directory and statistics directory for trace buffer and 5067125b02SHiral Patel * stats logging. 5167125b02SHiral Patel */ 5267125b02SHiral Patel int fnic_debugfs_init(void) 5367125b02SHiral Patel { 5467125b02SHiral Patel int rc = -1; 5567125b02SHiral Patel fnic_trace_debugfs_root = debugfs_create_dir("fnic", NULL); 5667125b02SHiral Patel if (!fnic_trace_debugfs_root) { 5767125b02SHiral Patel printk(KERN_DEBUG "Cannot create debugfs root\n"); 5867125b02SHiral Patel return rc; 5967125b02SHiral Patel } 6067125b02SHiral Patel 6167125b02SHiral Patel if (!fnic_trace_debugfs_root) { 6267125b02SHiral Patel printk(KERN_DEBUG 6367125b02SHiral Patel "fnic root directory doesn't exist in debugfs\n"); 6467125b02SHiral Patel return rc; 6567125b02SHiral Patel } 6667125b02SHiral Patel 6767125b02SHiral Patel fnic_stats_debugfs_root = debugfs_create_dir("statistics", 6867125b02SHiral Patel fnic_trace_debugfs_root); 6967125b02SHiral Patel if (!fnic_stats_debugfs_root) { 7067125b02SHiral Patel printk(KERN_DEBUG "Cannot create Statistics directory\n"); 7167125b02SHiral Patel return rc; 7267125b02SHiral Patel } 7367125b02SHiral Patel 74*abb14148SHiral Shah /* Allocate memory to structure */ 75*abb14148SHiral Shah fc_trc_flag = (struct fc_trace_flag_type *) 76*abb14148SHiral Shah vmalloc(sizeof(struct fc_trace_flag_type)); 77*abb14148SHiral Shah 78*abb14148SHiral Shah if (fc_trc_flag) { 79*abb14148SHiral Shah fc_trc_flag->fc_row_file = 0; 80*abb14148SHiral Shah fc_trc_flag->fc_normal_file = 1; 81*abb14148SHiral Shah fc_trc_flag->fnic_trace = 2; 82*abb14148SHiral Shah fc_trc_flag->fc_trace = 3; 83*abb14148SHiral Shah fc_trc_flag->fc_clear = 4; 84*abb14148SHiral Shah } 85*abb14148SHiral Shah 8667125b02SHiral Patel rc = 0; 8767125b02SHiral Patel return rc; 8867125b02SHiral Patel } 8967125b02SHiral Patel 9067125b02SHiral Patel /* 9167125b02SHiral Patel * fnic_debugfs_terminate - Tear down debugfs infrastructure 9267125b02SHiral Patel * 9367125b02SHiral Patel * Description: 9467125b02SHiral Patel * When Debugfs is configured this routine removes debugfs file system 9567125b02SHiral Patel * elements that are specific to fnic. 9667125b02SHiral Patel */ 9767125b02SHiral Patel void fnic_debugfs_terminate(void) 9867125b02SHiral Patel { 9967125b02SHiral Patel debugfs_remove(fnic_stats_debugfs_root); 10067125b02SHiral Patel fnic_stats_debugfs_root = NULL; 10167125b02SHiral Patel 10267125b02SHiral Patel debugfs_remove(fnic_trace_debugfs_root); 10367125b02SHiral Patel fnic_trace_debugfs_root = NULL; 104*abb14148SHiral Shah 105*abb14148SHiral Shah if (fc_trc_flag) 106*abb14148SHiral Shah vfree(fc_trc_flag); 10767125b02SHiral Patel } 1084d7007b4SHiral Patel 1094d7007b4SHiral Patel /* 110*abb14148SHiral Shah * fnic_trace_ctrl_open - Open the trace_enable file for fnic_trace 111*abb14148SHiral Shah * Or Open fc_trace_enable file for fc_trace 1124d7007b4SHiral Patel * @inode: The inode pointer. 1134d7007b4SHiral Patel * @file: The file pointer to attach the trace enable/disable flag. 1144d7007b4SHiral Patel * 1154d7007b4SHiral Patel * Description: 116*abb14148SHiral Shah * This routine opens a debugsfs file trace_enable or fc_trace_enable. 1174d7007b4SHiral Patel * 1184d7007b4SHiral Patel * Returns: 1194d7007b4SHiral Patel * This function returns zero if successful. 1204d7007b4SHiral Patel */ 1214d7007b4SHiral Patel static int fnic_trace_ctrl_open(struct inode *inode, struct file *filp) 1224d7007b4SHiral Patel { 1234d7007b4SHiral Patel filp->private_data = inode->i_private; 1244d7007b4SHiral Patel return 0; 1254d7007b4SHiral Patel } 1264d7007b4SHiral Patel 1274d7007b4SHiral Patel /* 128*abb14148SHiral Shah * fnic_trace_ctrl_read - 129*abb14148SHiral Shah * Read trace_enable ,fc_trace_enable 130*abb14148SHiral Shah * or fc_trace_clear debugfs file 1314d7007b4SHiral Patel * @filp: The file pointer to read from. 1324d7007b4SHiral Patel * @ubuf: The buffer to copy the data to. 1334d7007b4SHiral Patel * @cnt: The number of bytes to read. 1344d7007b4SHiral Patel * @ppos: The position in the file to start reading from. 1354d7007b4SHiral Patel * 1364d7007b4SHiral Patel * Description: 137*abb14148SHiral Shah * This routine reads value of variable fnic_tracing_enabled or 138*abb14148SHiral Shah * fnic_fc_tracing_enabled or fnic_fc_trace_cleared 139*abb14148SHiral Shah * and stores into local @buf. 140*abb14148SHiral Shah * It will start reading file at @ppos and 1414d7007b4SHiral Patel * copy up to @cnt of data to @ubuf from @buf. 1424d7007b4SHiral Patel * 1434d7007b4SHiral Patel * Returns: 1444d7007b4SHiral Patel * This function returns the amount of data that was read. 1454d7007b4SHiral Patel */ 1464d7007b4SHiral Patel static ssize_t fnic_trace_ctrl_read(struct file *filp, 1474d7007b4SHiral Patel char __user *ubuf, 1484d7007b4SHiral Patel size_t cnt, loff_t *ppos) 1494d7007b4SHiral Patel { 1504d7007b4SHiral Patel char buf[64]; 1514d7007b4SHiral Patel int len; 152*abb14148SHiral Shah u8 *trace_type; 153*abb14148SHiral Shah len = 0; 154*abb14148SHiral Shah trace_type = (u8 *)filp->private_data; 155*abb14148SHiral Shah if (*trace_type == fc_trc_flag->fnic_trace) 1564d7007b4SHiral Patel len = sprintf(buf, "%u\n", fnic_tracing_enabled); 157*abb14148SHiral Shah else if (*trace_type == fc_trc_flag->fc_trace) 158*abb14148SHiral Shah len = sprintf(buf, "%u\n", fnic_fc_tracing_enabled); 159*abb14148SHiral Shah else if (*trace_type == fc_trc_flag->fc_clear) 160*abb14148SHiral Shah len = sprintf(buf, "%u\n", fnic_fc_trace_cleared); 161*abb14148SHiral Shah else 162*abb14148SHiral Shah pr_err("fnic: Cannot read to any debugfs file\n"); 1634d7007b4SHiral Patel 1644d7007b4SHiral Patel return simple_read_from_buffer(ubuf, cnt, ppos, buf, len); 1654d7007b4SHiral Patel } 1664d7007b4SHiral Patel 1674d7007b4SHiral Patel /* 168*abb14148SHiral Shah * fnic_trace_ctrl_write - 169*abb14148SHiral Shah * Write to trace_enable, fc_trace_enable or 170*abb14148SHiral Shah * fc_trace_clear debugfs file 1714d7007b4SHiral Patel * @filp: The file pointer to write from. 1724d7007b4SHiral Patel * @ubuf: The buffer to copy the data from. 1734d7007b4SHiral Patel * @cnt: The number of bytes to write. 1744d7007b4SHiral Patel * @ppos: The position in the file to start writing to. 1754d7007b4SHiral Patel * 1764d7007b4SHiral Patel * Description: 1774d7007b4SHiral Patel * This routine writes data from user buffer @ubuf to buffer @buf and 178*abb14148SHiral Shah * sets fc_trace_enable ,tracing_enable or fnic_fc_trace_cleared 179*abb14148SHiral Shah * value as per user input. 1804d7007b4SHiral Patel * 1814d7007b4SHiral Patel * Returns: 1824d7007b4SHiral Patel * This function returns the amount of data that was written. 1834d7007b4SHiral Patel */ 1844d7007b4SHiral Patel static ssize_t fnic_trace_ctrl_write(struct file *filp, 1854d7007b4SHiral Patel const char __user *ubuf, 1864d7007b4SHiral Patel size_t cnt, loff_t *ppos) 1874d7007b4SHiral Patel { 1884d7007b4SHiral Patel char buf[64]; 1894d7007b4SHiral Patel unsigned long val; 1904d7007b4SHiral Patel int ret; 191*abb14148SHiral Shah u8 *trace_type; 192*abb14148SHiral Shah trace_type = (u8 *)filp->private_data; 1934d7007b4SHiral Patel 1944d7007b4SHiral Patel if (cnt >= sizeof(buf)) 1954d7007b4SHiral Patel return -EINVAL; 1964d7007b4SHiral Patel 1974d7007b4SHiral Patel if (copy_from_user(&buf, ubuf, cnt)) 1984d7007b4SHiral Patel return -EFAULT; 1994d7007b4SHiral Patel 2004d7007b4SHiral Patel buf[cnt] = 0; 2014d7007b4SHiral Patel 2024d7007b4SHiral Patel ret = kstrtoul(buf, 10, &val); 2034d7007b4SHiral Patel if (ret < 0) 2044d7007b4SHiral Patel return ret; 2054d7007b4SHiral Patel 206*abb14148SHiral Shah if (*trace_type == fc_trc_flag->fnic_trace) 2074d7007b4SHiral Patel fnic_tracing_enabled = val; 208*abb14148SHiral Shah else if (*trace_type == fc_trc_flag->fc_trace) 209*abb14148SHiral Shah fnic_fc_tracing_enabled = val; 210*abb14148SHiral Shah else if (*trace_type == fc_trc_flag->fc_clear) 211*abb14148SHiral Shah fnic_fc_trace_cleared = val; 212*abb14148SHiral Shah else 213*abb14148SHiral Shah pr_err("fnic: cannot write to any debufs file\n"); 214*abb14148SHiral Shah 2154d7007b4SHiral Patel (*ppos)++; 2164d7007b4SHiral Patel 2174d7007b4SHiral Patel return cnt; 2184d7007b4SHiral Patel } 2194d7007b4SHiral Patel 220*abb14148SHiral Shah static const struct file_operations fnic_trace_ctrl_fops = { 221*abb14148SHiral Shah .owner = THIS_MODULE, 222*abb14148SHiral Shah .open = fnic_trace_ctrl_open, 223*abb14148SHiral Shah .read = fnic_trace_ctrl_read, 224*abb14148SHiral Shah .write = fnic_trace_ctrl_write, 225*abb14148SHiral Shah }; 226*abb14148SHiral Shah 2274d7007b4SHiral Patel /* 2284d7007b4SHiral Patel * fnic_trace_debugfs_open - Open the fnic trace log 2294d7007b4SHiral Patel * @inode: The inode pointer 2304d7007b4SHiral Patel * @file: The file pointer to attach the log output 2314d7007b4SHiral Patel * 2324d7007b4SHiral Patel * Description: 2334d7007b4SHiral Patel * This routine is the entry point for the debugfs open file operation. 2344d7007b4SHiral Patel * It allocates the necessary buffer for the log, fills the buffer from 2354d7007b4SHiral Patel * the in-memory log and then returns a pointer to that log in 2364d7007b4SHiral Patel * the private_data field in @file. 2374d7007b4SHiral Patel * 2384d7007b4SHiral Patel * Returns: 2394d7007b4SHiral Patel * This function returns zero if successful. On error it will return 2404d7007b4SHiral Patel * a negative error value. 2414d7007b4SHiral Patel */ 2424d7007b4SHiral Patel static int fnic_trace_debugfs_open(struct inode *inode, 2434d7007b4SHiral Patel struct file *file) 2444d7007b4SHiral Patel { 2454d7007b4SHiral Patel fnic_dbgfs_t *fnic_dbg_prt; 246*abb14148SHiral Shah u8 *rdata_ptr; 247*abb14148SHiral Shah rdata_ptr = (u8 *)inode->i_private; 2484d7007b4SHiral Patel fnic_dbg_prt = kzalloc(sizeof(fnic_dbgfs_t), GFP_KERNEL); 2494d7007b4SHiral Patel if (!fnic_dbg_prt) 2504d7007b4SHiral Patel return -ENOMEM; 2514d7007b4SHiral Patel 252*abb14148SHiral Shah if (*rdata_ptr == fc_trc_flag->fnic_trace) { 253*abb14148SHiral Shah fnic_dbg_prt->buffer = vmalloc(3 * 254*abb14148SHiral Shah (trace_max_pages * PAGE_SIZE)); 2554d7007b4SHiral Patel if (!fnic_dbg_prt->buffer) { 2564d7007b4SHiral Patel kfree(fnic_dbg_prt); 2574d7007b4SHiral Patel return -ENOMEM; 2584d7007b4SHiral Patel } 2594d7007b4SHiral Patel memset((void *)fnic_dbg_prt->buffer, 0, 260*abb14148SHiral Shah 3 * (trace_max_pages * PAGE_SIZE)); 2614d7007b4SHiral Patel fnic_dbg_prt->buffer_len = fnic_get_trace_data(fnic_dbg_prt); 262*abb14148SHiral Shah } else { 263*abb14148SHiral Shah fnic_dbg_prt->buffer = 264*abb14148SHiral Shah vmalloc(3 * (fnic_fc_trace_max_pages * PAGE_SIZE)); 265*abb14148SHiral Shah if (!fnic_dbg_prt->buffer) { 266*abb14148SHiral Shah kfree(fnic_dbg_prt); 267*abb14148SHiral Shah return -ENOMEM; 268*abb14148SHiral Shah } 269*abb14148SHiral Shah memset((void *)fnic_dbg_prt->buffer, 0, 270*abb14148SHiral Shah 3 * (fnic_fc_trace_max_pages * PAGE_SIZE)); 271*abb14148SHiral Shah fnic_dbg_prt->buffer_len = 272*abb14148SHiral Shah fnic_fc_trace_get_data(fnic_dbg_prt, *rdata_ptr); 273*abb14148SHiral Shah } 2744d7007b4SHiral Patel file->private_data = fnic_dbg_prt; 275*abb14148SHiral Shah 2764d7007b4SHiral Patel return 0; 2774d7007b4SHiral Patel } 2784d7007b4SHiral Patel 2794d7007b4SHiral Patel /* 2804d7007b4SHiral Patel * fnic_trace_debugfs_lseek - Seek through a debugfs file 2814d7007b4SHiral Patel * @file: The file pointer to seek through. 2824d7007b4SHiral Patel * @offset: The offset to seek to or the amount to seek by. 2834d7007b4SHiral Patel * @howto: Indicates how to seek. 2844d7007b4SHiral Patel * 2854d7007b4SHiral Patel * Description: 2864d7007b4SHiral Patel * This routine is the entry point for the debugfs lseek file operation. 2874d7007b4SHiral Patel * The @howto parameter indicates whether @offset is the offset to directly 2884d7007b4SHiral Patel * seek to, or if it is a value to seek forward or reverse by. This function 2894d7007b4SHiral Patel * figures out what the new offset of the debugfs file will be and assigns 2904d7007b4SHiral Patel * that value to the f_pos field of @file. 2914d7007b4SHiral Patel * 2924d7007b4SHiral Patel * Returns: 2934d7007b4SHiral Patel * This function returns the new offset if successful and returns a negative 2944d7007b4SHiral Patel * error if unable to process the seek. 2954d7007b4SHiral Patel */ 2964d7007b4SHiral Patel static loff_t fnic_trace_debugfs_lseek(struct file *file, 2974d7007b4SHiral Patel loff_t offset, 2984d7007b4SHiral Patel int howto) 2994d7007b4SHiral Patel { 3004d7007b4SHiral Patel fnic_dbgfs_t *fnic_dbg_prt = file->private_data; 301eb5881d3SAl Viro return fixed_size_llseek(file, offset, howto, 302eb5881d3SAl Viro fnic_dbg_prt->buffer_len); 3034d7007b4SHiral Patel } 3044d7007b4SHiral Patel 3054d7007b4SHiral Patel /* 3064d7007b4SHiral Patel * fnic_trace_debugfs_read - Read a debugfs file 3074d7007b4SHiral Patel * @file: The file pointer to read from. 3084d7007b4SHiral Patel * @ubuf: The buffer to copy the data to. 3094d7007b4SHiral Patel * @nbytes: The number of bytes to read. 3104d7007b4SHiral Patel * @pos: The position in the file to start reading from. 3114d7007b4SHiral Patel * 3124d7007b4SHiral Patel * Description: 3134d7007b4SHiral Patel * This routine reads data from the buffer indicated in the private_data 3144d7007b4SHiral Patel * field of @file. It will start reading at @pos and copy up to @nbytes of 3154d7007b4SHiral Patel * data to @ubuf. 3164d7007b4SHiral Patel * 3174d7007b4SHiral Patel * Returns: 3184d7007b4SHiral Patel * This function returns the amount of data that was read (this could be 3194d7007b4SHiral Patel * less than @nbytes if the end of the file was reached). 3204d7007b4SHiral Patel */ 3214d7007b4SHiral Patel static ssize_t fnic_trace_debugfs_read(struct file *file, 3224d7007b4SHiral Patel char __user *ubuf, 3234d7007b4SHiral Patel size_t nbytes, 3244d7007b4SHiral Patel loff_t *pos) 3254d7007b4SHiral Patel { 3264d7007b4SHiral Patel fnic_dbgfs_t *fnic_dbg_prt = file->private_data; 3274d7007b4SHiral Patel int rc = 0; 3284d7007b4SHiral Patel rc = simple_read_from_buffer(ubuf, nbytes, pos, 3294d7007b4SHiral Patel fnic_dbg_prt->buffer, 3304d7007b4SHiral Patel fnic_dbg_prt->buffer_len); 3314d7007b4SHiral Patel return rc; 3324d7007b4SHiral Patel } 3334d7007b4SHiral Patel 3344d7007b4SHiral Patel /* 3354d7007b4SHiral Patel * fnic_trace_debugfs_release - Release the buffer used to store 3364d7007b4SHiral Patel * debugfs file data 3374d7007b4SHiral Patel * @inode: The inode pointer 3384d7007b4SHiral Patel * @file: The file pointer that contains the buffer to release 3394d7007b4SHiral Patel * 3404d7007b4SHiral Patel * Description: 3414d7007b4SHiral Patel * This routine frees the buffer that was allocated when the debugfs 3424d7007b4SHiral Patel * file was opened. 3434d7007b4SHiral Patel * 3444d7007b4SHiral Patel * Returns: 3454d7007b4SHiral Patel * This function returns zero. 3464d7007b4SHiral Patel */ 3474d7007b4SHiral Patel static int fnic_trace_debugfs_release(struct inode *inode, 3484d7007b4SHiral Patel struct file *file) 3494d7007b4SHiral Patel { 3504d7007b4SHiral Patel fnic_dbgfs_t *fnic_dbg_prt = file->private_data; 3514d7007b4SHiral Patel 3524d7007b4SHiral Patel vfree(fnic_dbg_prt->buffer); 3534d7007b4SHiral Patel kfree(fnic_dbg_prt); 3544d7007b4SHiral Patel return 0; 3554d7007b4SHiral Patel } 3564d7007b4SHiral Patel 3574d7007b4SHiral Patel static const struct file_operations fnic_trace_debugfs_fops = { 3584d7007b4SHiral Patel .owner = THIS_MODULE, 3594d7007b4SHiral Patel .open = fnic_trace_debugfs_open, 3604d7007b4SHiral Patel .llseek = fnic_trace_debugfs_lseek, 3614d7007b4SHiral Patel .read = fnic_trace_debugfs_read, 3624d7007b4SHiral Patel .release = fnic_trace_debugfs_release, 3634d7007b4SHiral Patel }; 3644d7007b4SHiral Patel 3654d7007b4SHiral Patel /* 3664d7007b4SHiral Patel * fnic_trace_debugfs_init - Initialize debugfs for fnic trace logging 3674d7007b4SHiral Patel * 3684d7007b4SHiral Patel * Description: 3694d7007b4SHiral Patel * When Debugfs is configured this routine sets up the fnic debugfs 3704d7007b4SHiral Patel * file system. If not already created, this routine will create the 37167125b02SHiral Patel * create file trace to log fnic trace buffer output into debugfs and 37267125b02SHiral Patel * it will also create file trace_enable to control enable/disable of 37367125b02SHiral Patel * trace logging into trace buffer. 3744d7007b4SHiral Patel */ 3754d7007b4SHiral Patel int fnic_trace_debugfs_init(void) 3764d7007b4SHiral Patel { 3774d7007b4SHiral Patel int rc = -1; 3784d7007b4SHiral Patel if (!fnic_trace_debugfs_root) { 37967125b02SHiral Patel printk(KERN_DEBUG 38067125b02SHiral Patel "FNIC Debugfs root directory doesn't exist\n"); 3814d7007b4SHiral Patel return rc; 3824d7007b4SHiral Patel } 3834d7007b4SHiral Patel fnic_trace_enable = debugfs_create_file("tracing_enable", 3844d7007b4SHiral Patel S_IFREG|S_IRUGO|S_IWUSR, 3854d7007b4SHiral Patel fnic_trace_debugfs_root, 386*abb14148SHiral Shah &(fc_trc_flag->fnic_trace), 387*abb14148SHiral Shah &fnic_trace_ctrl_fops); 3884d7007b4SHiral Patel 3894d7007b4SHiral Patel if (!fnic_trace_enable) { 39067125b02SHiral Patel printk(KERN_DEBUG 39167125b02SHiral Patel "Cannot create trace_enable file under debugfs\n"); 3924d7007b4SHiral Patel return rc; 3934d7007b4SHiral Patel } 3944d7007b4SHiral Patel 3954d7007b4SHiral Patel fnic_trace_debugfs_file = debugfs_create_file("trace", 3964d7007b4SHiral Patel S_IFREG|S_IRUGO|S_IWUSR, 3974d7007b4SHiral Patel fnic_trace_debugfs_root, 398*abb14148SHiral Shah &(fc_trc_flag->fnic_trace), 3994d7007b4SHiral Patel &fnic_trace_debugfs_fops); 4004d7007b4SHiral Patel 4014d7007b4SHiral Patel if (!fnic_trace_debugfs_file) { 40267125b02SHiral Patel printk(KERN_DEBUG 40367125b02SHiral Patel "Cannot create trace file under debugfs\n"); 4044d7007b4SHiral Patel return rc; 4054d7007b4SHiral Patel } 4064d7007b4SHiral Patel rc = 0; 4074d7007b4SHiral Patel return rc; 4084d7007b4SHiral Patel } 4094d7007b4SHiral Patel 4104d7007b4SHiral Patel /* 4114d7007b4SHiral Patel * fnic_trace_debugfs_terminate - Tear down debugfs infrastructure 4124d7007b4SHiral Patel * 4134d7007b4SHiral Patel * Description: 4144d7007b4SHiral Patel * When Debugfs is configured this routine removes debugfs file system 4154d7007b4SHiral Patel * elements that are specific to fnic trace logging. 4164d7007b4SHiral Patel */ 4174d7007b4SHiral Patel void fnic_trace_debugfs_terminate(void) 4184d7007b4SHiral Patel { 4194d7007b4SHiral Patel debugfs_remove(fnic_trace_debugfs_file); 4204d7007b4SHiral Patel fnic_trace_debugfs_file = NULL; 421*abb14148SHiral Shah 4224d7007b4SHiral Patel debugfs_remove(fnic_trace_enable); 4234d7007b4SHiral Patel fnic_trace_enable = NULL; 4244d7007b4SHiral Patel } 425*abb14148SHiral Shah 426*abb14148SHiral Shah /* 427*abb14148SHiral Shah * fnic_fc_trace_debugfs_init - 428*abb14148SHiral Shah * Initialize debugfs for fnic control frame trace logging 429*abb14148SHiral Shah * 430*abb14148SHiral Shah * Description: 431*abb14148SHiral Shah * When Debugfs is configured this routine sets up the fnic_fc debugfs 432*abb14148SHiral Shah * file system. If not already created, this routine will create the 433*abb14148SHiral Shah * create file trace to log fnic fc trace buffer output into debugfs and 434*abb14148SHiral Shah * it will also create file fc_trace_enable to control enable/disable of 435*abb14148SHiral Shah * trace logging into trace buffer. 436*abb14148SHiral Shah */ 437*abb14148SHiral Shah 438*abb14148SHiral Shah int fnic_fc_trace_debugfs_init(void) 439*abb14148SHiral Shah { 440*abb14148SHiral Shah int rc = -1; 441*abb14148SHiral Shah 442*abb14148SHiral Shah if (!fnic_trace_debugfs_root) { 443*abb14148SHiral Shah pr_err("fnic:Debugfs root directory doesn't exist\n"); 444*abb14148SHiral Shah return rc; 445*abb14148SHiral Shah } 446*abb14148SHiral Shah 447*abb14148SHiral Shah fnic_fc_trace_enable = debugfs_create_file("fc_trace_enable", 448*abb14148SHiral Shah S_IFREG|S_IRUGO|S_IWUSR, 449*abb14148SHiral Shah fnic_trace_debugfs_root, 450*abb14148SHiral Shah &(fc_trc_flag->fc_trace), 451*abb14148SHiral Shah &fnic_trace_ctrl_fops); 452*abb14148SHiral Shah 453*abb14148SHiral Shah if (!fnic_fc_trace_enable) { 454*abb14148SHiral Shah pr_err("fnic: Failed create fc_trace_enable file\n"); 455*abb14148SHiral Shah return rc; 456*abb14148SHiral Shah } 457*abb14148SHiral Shah 458*abb14148SHiral Shah fnic_fc_trace_clear = debugfs_create_file("fc_trace_clear", 459*abb14148SHiral Shah S_IFREG|S_IRUGO|S_IWUSR, 460*abb14148SHiral Shah fnic_trace_debugfs_root, 461*abb14148SHiral Shah &(fc_trc_flag->fc_clear), 462*abb14148SHiral Shah &fnic_trace_ctrl_fops); 463*abb14148SHiral Shah 464*abb14148SHiral Shah if (!fnic_fc_trace_clear) { 465*abb14148SHiral Shah pr_err("fnic: Failed to create fc_trace_enable file\n"); 466*abb14148SHiral Shah return rc; 467*abb14148SHiral Shah } 468*abb14148SHiral Shah 469*abb14148SHiral Shah fnic_fc_rdata_trace_debugfs_file = 470*abb14148SHiral Shah debugfs_create_file("fc_trace_rdata", 471*abb14148SHiral Shah S_IFREG|S_IRUGO|S_IWUSR, 472*abb14148SHiral Shah fnic_trace_debugfs_root, 473*abb14148SHiral Shah &(fc_trc_flag->fc_normal_file), 474*abb14148SHiral Shah &fnic_trace_debugfs_fops); 475*abb14148SHiral Shah 476*abb14148SHiral Shah if (!fnic_fc_rdata_trace_debugfs_file) { 477*abb14148SHiral Shah pr_err("fnic: Failed create fc_rdata_trace file\n"); 478*abb14148SHiral Shah return rc; 479*abb14148SHiral Shah } 480*abb14148SHiral Shah 481*abb14148SHiral Shah fnic_fc_trace_debugfs_file = 482*abb14148SHiral Shah debugfs_create_file("fc_trace", 483*abb14148SHiral Shah S_IFREG|S_IRUGO|S_IWUSR, 484*abb14148SHiral Shah fnic_trace_debugfs_root, 485*abb14148SHiral Shah &(fc_trc_flag->fc_row_file), 486*abb14148SHiral Shah &fnic_trace_debugfs_fops); 487*abb14148SHiral Shah 488*abb14148SHiral Shah if (!fnic_fc_trace_debugfs_file) { 489*abb14148SHiral Shah pr_err("fnic: Failed to create fc_trace file\n"); 490*abb14148SHiral Shah return rc; 491*abb14148SHiral Shah } 492*abb14148SHiral Shah rc = 0; 493*abb14148SHiral Shah return rc; 494*abb14148SHiral Shah } 495*abb14148SHiral Shah 496*abb14148SHiral Shah /* 497*abb14148SHiral Shah * fnic_fc_trace_debugfs_terminate - Tear down debugfs infrastructure 498*abb14148SHiral Shah * 499*abb14148SHiral Shah * Description: 500*abb14148SHiral Shah * When Debugfs is configured this routine removes debugfs file system 501*abb14148SHiral Shah * elements that are specific to fnic_fc trace logging. 502*abb14148SHiral Shah */ 503*abb14148SHiral Shah 504*abb14148SHiral Shah void fnic_fc_trace_debugfs_terminate(void) 505*abb14148SHiral Shah { 506*abb14148SHiral Shah debugfs_remove(fnic_fc_trace_debugfs_file); 507*abb14148SHiral Shah fnic_fc_trace_debugfs_file = NULL; 508*abb14148SHiral Shah 509*abb14148SHiral Shah debugfs_remove(fnic_fc_rdata_trace_debugfs_file); 510*abb14148SHiral Shah fnic_fc_rdata_trace_debugfs_file = NULL; 511*abb14148SHiral Shah 512*abb14148SHiral Shah debugfs_remove(fnic_fc_trace_enable); 513*abb14148SHiral Shah fnic_fc_trace_enable = NULL; 514*abb14148SHiral Shah 515*abb14148SHiral Shah debugfs_remove(fnic_fc_trace_clear); 516*abb14148SHiral Shah fnic_fc_trace_clear = NULL; 5174d7007b4SHiral Patel } 51867125b02SHiral Patel 51967125b02SHiral Patel /* 52067125b02SHiral Patel * fnic_reset_stats_open - Open the reset_stats file 52167125b02SHiral Patel * @inode: The inode pointer. 52267125b02SHiral Patel * @file: The file pointer to attach the stats reset flag. 52367125b02SHiral Patel * 52467125b02SHiral Patel * Description: 52567125b02SHiral Patel * This routine opens a debugsfs file reset_stats and stores i_private data 52667125b02SHiral Patel * to debug structure to retrieve later for while performing other 52767125b02SHiral Patel * file oprations. 52867125b02SHiral Patel * 52967125b02SHiral Patel * Returns: 53067125b02SHiral Patel * This function returns zero if successful. 53167125b02SHiral Patel */ 53267125b02SHiral Patel static int fnic_reset_stats_open(struct inode *inode, struct file *file) 53367125b02SHiral Patel { 53467125b02SHiral Patel struct stats_debug_info *debug; 53567125b02SHiral Patel 53667125b02SHiral Patel debug = kzalloc(sizeof(struct stats_debug_info), GFP_KERNEL); 53767125b02SHiral Patel if (!debug) 53867125b02SHiral Patel return -ENOMEM; 53967125b02SHiral Patel 54067125b02SHiral Patel debug->i_private = inode->i_private; 54167125b02SHiral Patel 54267125b02SHiral Patel file->private_data = debug; 54367125b02SHiral Patel 54467125b02SHiral Patel return 0; 54567125b02SHiral Patel } 54667125b02SHiral Patel 54767125b02SHiral Patel /* 54867125b02SHiral Patel * fnic_reset_stats_read - Read a reset_stats debugfs file 54967125b02SHiral Patel * @filp: The file pointer to read from. 55067125b02SHiral Patel * @ubuf: The buffer to copy the data to. 55167125b02SHiral Patel * @cnt: The number of bytes to read. 55267125b02SHiral Patel * @ppos: The position in the file to start reading from. 55367125b02SHiral Patel * 55467125b02SHiral Patel * Description: 55567125b02SHiral Patel * This routine reads value of variable reset_stats 55667125b02SHiral Patel * and stores into local @buf. It will start reading file at @ppos and 55767125b02SHiral Patel * copy up to @cnt of data to @ubuf from @buf. 55867125b02SHiral Patel * 55967125b02SHiral Patel * Returns: 56067125b02SHiral Patel * This function returns the amount of data that was read. 56167125b02SHiral Patel */ 56267125b02SHiral Patel static ssize_t fnic_reset_stats_read(struct file *file, 56367125b02SHiral Patel char __user *ubuf, 56467125b02SHiral Patel size_t cnt, loff_t *ppos) 56567125b02SHiral Patel { 56667125b02SHiral Patel struct stats_debug_info *debug = file->private_data; 56767125b02SHiral Patel struct fnic *fnic = (struct fnic *)debug->i_private; 56867125b02SHiral Patel char buf[64]; 56967125b02SHiral Patel int len; 57067125b02SHiral Patel 57167125b02SHiral Patel len = sprintf(buf, "%u\n", fnic->reset_stats); 57267125b02SHiral Patel 57367125b02SHiral Patel return simple_read_from_buffer(ubuf, cnt, ppos, buf, len); 57467125b02SHiral Patel } 57567125b02SHiral Patel 57667125b02SHiral Patel /* 57767125b02SHiral Patel * fnic_reset_stats_write - Write to reset_stats debugfs file 57867125b02SHiral Patel * @filp: The file pointer to write from. 57967125b02SHiral Patel * @ubuf: The buffer to copy the data from. 58067125b02SHiral Patel * @cnt: The number of bytes to write. 58167125b02SHiral Patel * @ppos: The position in the file to start writing to. 58267125b02SHiral Patel * 58367125b02SHiral Patel * Description: 58467125b02SHiral Patel * This routine writes data from user buffer @ubuf to buffer @buf and 58567125b02SHiral Patel * resets cumulative stats of fnic. 58667125b02SHiral Patel * 58767125b02SHiral Patel * Returns: 58867125b02SHiral Patel * This function returns the amount of data that was written. 58967125b02SHiral Patel */ 59067125b02SHiral Patel static ssize_t fnic_reset_stats_write(struct file *file, 59167125b02SHiral Patel const char __user *ubuf, 59267125b02SHiral Patel size_t cnt, loff_t *ppos) 59367125b02SHiral Patel { 59467125b02SHiral Patel struct stats_debug_info *debug = file->private_data; 59567125b02SHiral Patel struct fnic *fnic = (struct fnic *)debug->i_private; 59667125b02SHiral Patel struct fnic_stats *stats = &fnic->fnic_stats; 59767125b02SHiral Patel u64 *io_stats_p = (u64 *)&stats->io_stats; 59867125b02SHiral Patel u64 *fw_stats_p = (u64 *)&stats->fw_stats; 59967125b02SHiral Patel char buf[64]; 60067125b02SHiral Patel unsigned long val; 60167125b02SHiral Patel int ret; 60267125b02SHiral Patel 60367125b02SHiral Patel if (cnt >= sizeof(buf)) 60467125b02SHiral Patel return -EINVAL; 60567125b02SHiral Patel 60667125b02SHiral Patel if (copy_from_user(&buf, ubuf, cnt)) 60767125b02SHiral Patel return -EFAULT; 60867125b02SHiral Patel 60967125b02SHiral Patel buf[cnt] = 0; 61067125b02SHiral Patel 61167125b02SHiral Patel ret = kstrtoul(buf, 10, &val); 61267125b02SHiral Patel if (ret < 0) 61367125b02SHiral Patel return ret; 61467125b02SHiral Patel 61567125b02SHiral Patel fnic->reset_stats = val; 61667125b02SHiral Patel 61767125b02SHiral Patel if (fnic->reset_stats) { 61867125b02SHiral Patel /* Skip variable is used to avoid descrepancies to Num IOs 61967125b02SHiral Patel * and IO Completions stats. Skip incrementing No IO Compls 62067125b02SHiral Patel * for pending active IOs after reset stats 62167125b02SHiral Patel */ 62267125b02SHiral Patel atomic64_set(&fnic->io_cmpl_skip, 62367125b02SHiral Patel atomic64_read(&stats->io_stats.active_ios)); 62467125b02SHiral Patel memset(&stats->abts_stats, 0, sizeof(struct abort_stats)); 62567125b02SHiral Patel memset(&stats->term_stats, 0, 62667125b02SHiral Patel sizeof(struct terminate_stats)); 62767125b02SHiral Patel memset(&stats->reset_stats, 0, sizeof(struct reset_stats)); 62867125b02SHiral Patel memset(&stats->misc_stats, 0, sizeof(struct misc_stats)); 62967125b02SHiral Patel memset(&stats->vlan_stats, 0, sizeof(struct vlan_stats)); 63067125b02SHiral Patel memset(io_stats_p+1, 0, 63167125b02SHiral Patel sizeof(struct io_path_stats) - sizeof(u64)); 63267125b02SHiral Patel memset(fw_stats_p+1, 0, 63367125b02SHiral Patel sizeof(struct fw_stats) - sizeof(u64)); 63467125b02SHiral Patel } 63567125b02SHiral Patel 63667125b02SHiral Patel (*ppos)++; 63767125b02SHiral Patel return cnt; 63867125b02SHiral Patel } 63967125b02SHiral Patel 64067125b02SHiral Patel /* 64167125b02SHiral Patel * fnic_reset_stats_release - Release the buffer used to store 64267125b02SHiral Patel * debugfs file data 64367125b02SHiral Patel * @inode: The inode pointer 64467125b02SHiral Patel * @file: The file pointer that contains the buffer to release 64567125b02SHiral Patel * 64667125b02SHiral Patel * Description: 64767125b02SHiral Patel * This routine frees the buffer that was allocated when the debugfs 64867125b02SHiral Patel * file was opened. 64967125b02SHiral Patel * 65067125b02SHiral Patel * Returns: 65167125b02SHiral Patel * This function returns zero. 65267125b02SHiral Patel */ 65367125b02SHiral Patel static int fnic_reset_stats_release(struct inode *inode, 65467125b02SHiral Patel struct file *file) 65567125b02SHiral Patel { 65667125b02SHiral Patel struct stats_debug_info *debug = file->private_data; 65767125b02SHiral Patel kfree(debug); 65867125b02SHiral Patel return 0; 65967125b02SHiral Patel } 66067125b02SHiral Patel 66167125b02SHiral Patel /* 66267125b02SHiral Patel * fnic_stats_debugfs_open - Open the stats file for specific host 66367125b02SHiral Patel * and get fnic stats. 66467125b02SHiral Patel * @inode: The inode pointer. 66567125b02SHiral Patel * @file: The file pointer to attach the specific host statistics. 66667125b02SHiral Patel * 66767125b02SHiral Patel * Description: 66867125b02SHiral Patel * This routine opens a debugsfs file stats of specific host and print 66967125b02SHiral Patel * fnic stats. 67067125b02SHiral Patel * 67167125b02SHiral Patel * Returns: 67267125b02SHiral Patel * This function returns zero if successful. 67367125b02SHiral Patel */ 67467125b02SHiral Patel static int fnic_stats_debugfs_open(struct inode *inode, 67567125b02SHiral Patel struct file *file) 67667125b02SHiral Patel { 67767125b02SHiral Patel struct fnic *fnic = inode->i_private; 67867125b02SHiral Patel struct fnic_stats *fnic_stats = &fnic->fnic_stats; 67967125b02SHiral Patel struct stats_debug_info *debug; 68067125b02SHiral Patel int buf_size = 2 * PAGE_SIZE; 68167125b02SHiral Patel 68267125b02SHiral Patel debug = kzalloc(sizeof(struct stats_debug_info), GFP_KERNEL); 68367125b02SHiral Patel if (!debug) 68467125b02SHiral Patel return -ENOMEM; 68567125b02SHiral Patel 68667125b02SHiral Patel debug->debug_buffer = vmalloc(buf_size); 68767125b02SHiral Patel if (!debug->debug_buffer) { 68867125b02SHiral Patel kfree(debug); 68967125b02SHiral Patel return -ENOMEM; 69067125b02SHiral Patel } 69167125b02SHiral Patel 69267125b02SHiral Patel debug->buf_size = buf_size; 69367125b02SHiral Patel memset((void *)debug->debug_buffer, 0, buf_size); 69467125b02SHiral Patel debug->buffer_len = fnic_get_stats_data(debug, fnic_stats); 69567125b02SHiral Patel 69667125b02SHiral Patel file->private_data = debug; 69767125b02SHiral Patel 69867125b02SHiral Patel return 0; 69967125b02SHiral Patel } 70067125b02SHiral Patel 70167125b02SHiral Patel /* 70267125b02SHiral Patel * fnic_stats_debugfs_read - Read a debugfs file 70367125b02SHiral Patel * @file: The file pointer to read from. 70467125b02SHiral Patel * @ubuf: The buffer to copy the data to. 70567125b02SHiral Patel * @nbytes: The number of bytes to read. 70667125b02SHiral Patel * @pos: The position in the file to start reading from. 70767125b02SHiral Patel * 70867125b02SHiral Patel * Description: 70967125b02SHiral Patel * This routine reads data from the buffer indicated in the private_data 71067125b02SHiral Patel * field of @file. It will start reading at @pos and copy up to @nbytes of 71167125b02SHiral Patel * data to @ubuf. 71267125b02SHiral Patel * 71367125b02SHiral Patel * Returns: 71467125b02SHiral Patel * This function returns the amount of data that was read (this could be 71567125b02SHiral Patel * less than @nbytes if the end of the file was reached). 71667125b02SHiral Patel */ 71767125b02SHiral Patel static ssize_t fnic_stats_debugfs_read(struct file *file, 71867125b02SHiral Patel char __user *ubuf, 71967125b02SHiral Patel size_t nbytes, 72067125b02SHiral Patel loff_t *pos) 72167125b02SHiral Patel { 72267125b02SHiral Patel struct stats_debug_info *debug = file->private_data; 72367125b02SHiral Patel int rc = 0; 72467125b02SHiral Patel rc = simple_read_from_buffer(ubuf, nbytes, pos, 72567125b02SHiral Patel debug->debug_buffer, 72667125b02SHiral Patel debug->buffer_len); 72767125b02SHiral Patel return rc; 72867125b02SHiral Patel } 72967125b02SHiral Patel 73067125b02SHiral Patel /* 73167125b02SHiral Patel * fnic_stats_stats_release - Release the buffer used to store 73267125b02SHiral Patel * debugfs file data 73367125b02SHiral Patel * @inode: The inode pointer 73467125b02SHiral Patel * @file: The file pointer that contains the buffer to release 73567125b02SHiral Patel * 73667125b02SHiral Patel * Description: 73767125b02SHiral Patel * This routine frees the buffer that was allocated when the debugfs 73867125b02SHiral Patel * file was opened. 73967125b02SHiral Patel * 74067125b02SHiral Patel * Returns: 74167125b02SHiral Patel * This function returns zero. 74267125b02SHiral Patel */ 74367125b02SHiral Patel static int fnic_stats_debugfs_release(struct inode *inode, 74467125b02SHiral Patel struct file *file) 74567125b02SHiral Patel { 74667125b02SHiral Patel struct stats_debug_info *debug = file->private_data; 74767125b02SHiral Patel vfree(debug->debug_buffer); 74867125b02SHiral Patel kfree(debug); 74967125b02SHiral Patel return 0; 75067125b02SHiral Patel } 75167125b02SHiral Patel 75267125b02SHiral Patel static const struct file_operations fnic_stats_debugfs_fops = { 75367125b02SHiral Patel .owner = THIS_MODULE, 75467125b02SHiral Patel .open = fnic_stats_debugfs_open, 75567125b02SHiral Patel .read = fnic_stats_debugfs_read, 75667125b02SHiral Patel .release = fnic_stats_debugfs_release, 75767125b02SHiral Patel }; 75867125b02SHiral Patel 75967125b02SHiral Patel static const struct file_operations fnic_reset_debugfs_fops = { 76067125b02SHiral Patel .owner = THIS_MODULE, 76167125b02SHiral Patel .open = fnic_reset_stats_open, 76267125b02SHiral Patel .read = fnic_reset_stats_read, 76367125b02SHiral Patel .write = fnic_reset_stats_write, 76467125b02SHiral Patel .release = fnic_reset_stats_release, 76567125b02SHiral Patel }; 76667125b02SHiral Patel 76767125b02SHiral Patel /* 76867125b02SHiral Patel * fnic_stats_init - Initialize stats struct and create stats file per fnic 76967125b02SHiral Patel * 77067125b02SHiral Patel * Description: 77167125b02SHiral Patel * When Debugfs is configured this routine sets up the stats file per fnic 77267125b02SHiral Patel * It will create file stats and reset_stats under statistics/host# directory 77367125b02SHiral Patel * to log per fnic stats. 77467125b02SHiral Patel */ 77567125b02SHiral Patel int fnic_stats_debugfs_init(struct fnic *fnic) 77667125b02SHiral Patel { 77767125b02SHiral Patel int rc = -1; 77867125b02SHiral Patel char name[16]; 77967125b02SHiral Patel 78067125b02SHiral Patel snprintf(name, sizeof(name), "host%d", fnic->lport->host->host_no); 78167125b02SHiral Patel 78267125b02SHiral Patel if (!fnic_stats_debugfs_root) { 78367125b02SHiral Patel printk(KERN_DEBUG "fnic_stats root doesn't exist\n"); 78467125b02SHiral Patel return rc; 78567125b02SHiral Patel } 78667125b02SHiral Patel fnic->fnic_stats_debugfs_host = debugfs_create_dir(name, 78767125b02SHiral Patel fnic_stats_debugfs_root); 78867125b02SHiral Patel if (!fnic->fnic_stats_debugfs_host) { 78967125b02SHiral Patel printk(KERN_DEBUG "Cannot create host directory\n"); 79067125b02SHiral Patel return rc; 79167125b02SHiral Patel } 79267125b02SHiral Patel 79367125b02SHiral Patel fnic->fnic_stats_debugfs_file = debugfs_create_file("stats", 79467125b02SHiral Patel S_IFREG|S_IRUGO|S_IWUSR, 79567125b02SHiral Patel fnic->fnic_stats_debugfs_host, 79667125b02SHiral Patel fnic, 79767125b02SHiral Patel &fnic_stats_debugfs_fops); 79867125b02SHiral Patel if (!fnic->fnic_stats_debugfs_file) { 79967125b02SHiral Patel printk(KERN_DEBUG "Cannot create host stats file\n"); 80067125b02SHiral Patel return rc; 80167125b02SHiral Patel } 80267125b02SHiral Patel 80367125b02SHiral Patel fnic->fnic_reset_debugfs_file = debugfs_create_file("reset_stats", 80467125b02SHiral Patel S_IFREG|S_IRUGO|S_IWUSR, 80567125b02SHiral Patel fnic->fnic_stats_debugfs_host, 80667125b02SHiral Patel fnic, 80767125b02SHiral Patel &fnic_reset_debugfs_fops); 80867125b02SHiral Patel if (!fnic->fnic_reset_debugfs_file) { 80967125b02SHiral Patel printk(KERN_DEBUG "Cannot create host stats file\n"); 81067125b02SHiral Patel return rc; 81167125b02SHiral Patel } 81267125b02SHiral Patel rc = 0; 81367125b02SHiral Patel return rc; 81467125b02SHiral Patel } 81567125b02SHiral Patel 81667125b02SHiral Patel /* 81767125b02SHiral Patel * fnic_stats_debugfs_remove - Tear down debugfs infrastructure of stats 81867125b02SHiral Patel * 81967125b02SHiral Patel * Description: 82067125b02SHiral Patel * When Debugfs is configured this routine removes debugfs file system 82167125b02SHiral Patel * elements that are specific to fnic stats. 82267125b02SHiral Patel */ 82367125b02SHiral Patel void fnic_stats_debugfs_remove(struct fnic *fnic) 82467125b02SHiral Patel { 82567125b02SHiral Patel if (!fnic) 82667125b02SHiral Patel return; 82767125b02SHiral Patel 82867125b02SHiral Patel debugfs_remove(fnic->fnic_stats_debugfs_file); 82967125b02SHiral Patel fnic->fnic_stats_debugfs_file = NULL; 83067125b02SHiral Patel 83167125b02SHiral Patel debugfs_remove(fnic->fnic_reset_debugfs_file); 83267125b02SHiral Patel fnic->fnic_reset_debugfs_file = NULL; 83367125b02SHiral Patel 83467125b02SHiral Patel debugfs_remove(fnic->fnic_stats_debugfs_host); 83567125b02SHiral Patel fnic->fnic_stats_debugfs_host = NULL; 8364d7007b4SHiral Patel } 837