bnxt_debugfs.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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/net_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 net_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 struct dentry *debugfs_dim_ring_init(struct net_dim *dim, int ring_idx,
  59. struct dentry *dd)
  60. {
  61. static char qname[16];
  62. snprintf(qname, 10, "%d", ring_idx);
  63. return debugfs_create_file(qname, 0600, dd,
  64. dim, &debugfs_dim_fops);
  65. }
  66. void bnxt_debug_dev_init(struct bnxt *bp)
  67. {
  68. const char *pname = pci_name(bp->pdev);
  69. struct dentry *pdevf;
  70. int i;
  71. bp->debugfs_pdev = debugfs_create_dir(pname, bnxt_debug_mnt);
  72. if (bp->debugfs_pdev) {
  73. pdevf = debugfs_create_dir("dim", bp->debugfs_pdev);
  74. if (!pdevf) {
  75. pr_err("failed to create debugfs entry %s/dim\n",
  76. pname);
  77. return;
  78. }
  79. bp->debugfs_dim = pdevf;
  80. /* create files for each rx ring */
  81. for (i = 0; i < bp->cp_nr_rings; i++) {
  82. struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring;
  83. if (cpr && bp->bnapi[i]->rx_ring) {
  84. pdevf = debugfs_dim_ring_init(&cpr->dim, i,
  85. bp->debugfs_dim);
  86. if (!pdevf)
  87. pr_err("failed to create debugfs entry %s/dim/%d\n",
  88. pname, i);
  89. }
  90. }
  91. } else {
  92. pr_err("failed to create debugfs entry %s\n", pname);
  93. }
  94. }
  95. void bnxt_debug_dev_exit(struct bnxt *bp)
  96. {
  97. if (bp) {
  98. debugfs_remove_recursive(bp->debugfs_pdev);
  99. bp->debugfs_pdev = NULL;
  100. }
  101. }
  102. void bnxt_debug_init(void)
  103. {
  104. bnxt_debug_mnt = debugfs_create_dir("bnxt_en", NULL);
  105. if (!bnxt_debug_mnt)
  106. pr_err("failed to init bnxt_en debugfs\n");
  107. }
  108. void bnxt_debug_exit(void)
  109. {
  110. debugfs_remove_recursive(bnxt_debug_mnt);
  111. }