bnxt_debugfs.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* Broadcom NetXtreme-C/E network driver.
  2. *
  3. * Copyright (c) 2017-2018 Broadcom Limited
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. */
  9. #include <linux/debugfs.h>
  10. #include <linux/module.h>
  11. #include <linux/pci.h>
  12. #include "bnxt_hsi.h"
  13. #include <linux/dim.h>
  14. #include "bnxt.h"
  15. #include "bnxt_debugfs.h"
  16. static struct dentry *bnxt_debug_mnt;
  17. static ssize_t debugfs_dim_read(struct file *filep,
  18. char __user *buffer,
  19. size_t count, loff_t *ppos)
  20. {
  21. struct dim *dim = filep->private_data;
  22. int len;
  23. char *buf;
  24. if (*ppos)
  25. return 0;
  26. if (!dim)
  27. return -ENODEV;
  28. buf = kasprintf(GFP_KERNEL,
  29. "state = %d\n" \
  30. "profile_ix = %d\n" \
  31. "mode = %d\n" \
  32. "tune_state = %d\n" \
  33. "steps_right = %d\n" \
  34. "steps_left = %d\n" \
  35. "tired = %d\n",
  36. dim->state,
  37. dim->profile_ix,
  38. dim->mode,
  39. dim->tune_state,
  40. dim->steps_right,
  41. dim->steps_left,
  42. dim->tired);
  43. if (!buf)
  44. return -ENOMEM;
  45. if (count < strlen(buf)) {
  46. kfree(buf);
  47. return -ENOSPC;
  48. }
  49. len = simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
  50. kfree(buf);
  51. return len;
  52. }
  53. static const struct file_operations debugfs_dim_fops = {
  54. .owner = THIS_MODULE,
  55. .open = simple_open,
  56. .read = debugfs_dim_read,
  57. };
  58. static void debugfs_dim_ring_init(struct dim *dim, int ring_idx,
  59. struct dentry *dd)
  60. {
  61. static char qname[12];
  62. snprintf(qname, sizeof(qname), "%d", ring_idx);
  63. debugfs_create_file(qname, 0600, dd, dim, &debugfs_dim_fops);
  64. }
  65. void bnxt_debug_dev_init(struct bnxt *bp)
  66. {
  67. const char *pname = pci_name(bp->pdev);
  68. struct dentry *dir;
  69. int i;
  70. bp->debugfs_pdev = debugfs_create_dir(pname, bnxt_debug_mnt);
  71. dir = debugfs_create_dir("dim", bp->debugfs_pdev);
  72. /* create files for each rx ring */
  73. for (i = 0; i < bp->cp_nr_rings; i++) {
  74. struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring;
  75. if (cpr && bp->bnapi[i]->rx_ring)
  76. debugfs_dim_ring_init(&cpr->dim, i, dir);
  77. }
  78. }
  79. void bnxt_debug_dev_exit(struct bnxt *bp)
  80. {
  81. if (bp) {
  82. debugfs_remove_recursive(bp->debugfs_pdev);
  83. bp->debugfs_pdev = NULL;
  84. }
  85. }
  86. void bnxt_debug_init(void)
  87. {
  88. bnxt_debug_mnt = debugfs_create_dir("bnxt_en", NULL);
  89. }
  90. void bnxt_debug_exit(void)
  91. {
  92. debugfs_remove_recursive(bnxt_debug_mnt);
  93. }