nitrox_debugfs.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/seq_file.h>
  3. #include <linux/debugfs.h>
  4. #include "nitrox_csr.h"
  5. #include "nitrox_dev.h"
  6. static int firmware_show(struct seq_file *s, void *v)
  7. {
  8. struct nitrox_device *ndev = s->private;
  9. seq_printf(s, "Version: %s\n", ndev->hw.fw_name);
  10. return 0;
  11. }
  12. static int firmware_open(struct inode *inode, struct file *file)
  13. {
  14. return single_open(file, firmware_show, inode->i_private);
  15. }
  16. static const struct file_operations firmware_fops = {
  17. .owner = THIS_MODULE,
  18. .open = firmware_open,
  19. .read = seq_read,
  20. .llseek = seq_lseek,
  21. .release = single_release,
  22. };
  23. static int device_show(struct seq_file *s, void *v)
  24. {
  25. struct nitrox_device *ndev = s->private;
  26. seq_printf(s, "NITROX [%d]\n", ndev->idx);
  27. seq_printf(s, " Part Name: %s\n", ndev->hw.partname);
  28. seq_printf(s, " Frequency: %d MHz\n", ndev->hw.freq);
  29. seq_printf(s, " Device ID: 0x%0x\n", ndev->hw.device_id);
  30. seq_printf(s, " Revision ID: 0x%0x\n", ndev->hw.revision_id);
  31. seq_printf(s, " Cores: [AE=%u SE=%u ZIP=%u]\n",
  32. ndev->hw.ae_cores, ndev->hw.se_cores, ndev->hw.zip_cores);
  33. return 0;
  34. }
  35. static int nitrox_open(struct inode *inode, struct file *file)
  36. {
  37. return single_open(file, device_show, inode->i_private);
  38. }
  39. static const struct file_operations nitrox_fops = {
  40. .owner = THIS_MODULE,
  41. .open = nitrox_open,
  42. .read = seq_read,
  43. .llseek = seq_lseek,
  44. .release = single_release,
  45. };
  46. static int stats_show(struct seq_file *s, void *v)
  47. {
  48. struct nitrox_device *ndev = s->private;
  49. seq_printf(s, "NITROX [%d] Request Statistics\n", ndev->idx);
  50. seq_printf(s, " Posted: %llu\n",
  51. (u64)atomic64_read(&ndev->stats.posted));
  52. seq_printf(s, " Completed: %llu\n",
  53. (u64)atomic64_read(&ndev->stats.completed));
  54. seq_printf(s, " Dropped: %llu\n",
  55. (u64)atomic64_read(&ndev->stats.dropped));
  56. return 0;
  57. }
  58. static int nitrox_stats_open(struct inode *inode, struct file *file)
  59. {
  60. return single_open(file, stats_show, inode->i_private);
  61. }
  62. static const struct file_operations nitrox_stats_fops = {
  63. .owner = THIS_MODULE,
  64. .open = nitrox_stats_open,
  65. .read = seq_read,
  66. .llseek = seq_lseek,
  67. .release = single_release,
  68. };
  69. void nitrox_debugfs_exit(struct nitrox_device *ndev)
  70. {
  71. debugfs_remove_recursive(ndev->debugfs_dir);
  72. ndev->debugfs_dir = NULL;
  73. }
  74. int nitrox_debugfs_init(struct nitrox_device *ndev)
  75. {
  76. struct dentry *dir, *f;
  77. dir = debugfs_create_dir(KBUILD_MODNAME, NULL);
  78. if (!dir)
  79. return -ENOMEM;
  80. ndev->debugfs_dir = dir;
  81. f = debugfs_create_file("firmware", 0400, dir, ndev, &firmware_fops);
  82. if (!f)
  83. goto err;
  84. f = debugfs_create_file("device", 0400, dir, ndev, &nitrox_fops);
  85. if (!f)
  86. goto err;
  87. f = debugfs_create_file("stats", 0400, dir, ndev, &nitrox_stats_fops);
  88. if (!f)
  89. goto err;
  90. return 0;
  91. err:
  92. nitrox_debugfs_exit(ndev);
  93. return -ENODEV;
  94. }