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