debugfs.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // SPDX-License-Identifier: BSD-3-Clause-Clear
  2. /*
  3. * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2021-2024 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include "core.h"
  7. #include "debugfs.h"
  8. #include "debugfs_htt_stats.h"
  9. static ssize_t ath12k_write_simulate_radar(struct file *file,
  10. const char __user *user_buf,
  11. size_t count, loff_t *ppos)
  12. {
  13. struct ath12k *ar = file->private_data;
  14. int ret;
  15. mutex_lock(&ar->conf_mutex);
  16. ret = ath12k_wmi_simulate_radar(ar);
  17. if (ret)
  18. goto exit;
  19. ret = count;
  20. exit:
  21. mutex_unlock(&ar->conf_mutex);
  22. return ret;
  23. }
  24. static const struct file_operations fops_simulate_radar = {
  25. .write = ath12k_write_simulate_radar,
  26. .open = simple_open
  27. };
  28. void ath12k_debugfs_soc_create(struct ath12k_base *ab)
  29. {
  30. bool dput_needed;
  31. char soc_name[64] = { 0 };
  32. struct dentry *debugfs_ath12k;
  33. debugfs_ath12k = debugfs_lookup("ath12k", NULL);
  34. if (debugfs_ath12k) {
  35. /* a dentry from lookup() needs dput() after we don't use it */
  36. dput_needed = true;
  37. } else {
  38. debugfs_ath12k = debugfs_create_dir("ath12k", NULL);
  39. if (IS_ERR_OR_NULL(debugfs_ath12k))
  40. return;
  41. dput_needed = false;
  42. }
  43. scnprintf(soc_name, sizeof(soc_name), "%s-%s", ath12k_bus_str(ab->hif.bus),
  44. dev_name(ab->dev));
  45. ab->debugfs_soc = debugfs_create_dir(soc_name, debugfs_ath12k);
  46. if (dput_needed)
  47. dput(debugfs_ath12k);
  48. }
  49. void ath12k_debugfs_soc_destroy(struct ath12k_base *ab)
  50. {
  51. debugfs_remove_recursive(ab->debugfs_soc);
  52. ab->debugfs_soc = NULL;
  53. /* We are not removing ath12k directory on purpose, even if it
  54. * would be empty. This simplifies the directory handling and it's
  55. * a minor cosmetic issue to leave an empty ath12k directory to
  56. * debugfs.
  57. */
  58. }
  59. void ath12k_debugfs_register(struct ath12k *ar)
  60. {
  61. struct ath12k_base *ab = ar->ab;
  62. struct ieee80211_hw *hw = ar->ah->hw;
  63. char pdev_name[5];
  64. char buf[100] = {0};
  65. scnprintf(pdev_name, sizeof(pdev_name), "%s%d", "mac", ar->pdev_idx);
  66. ar->debug.debugfs_pdev = debugfs_create_dir(pdev_name, ab->debugfs_soc);
  67. /* Create a symlink under ieee80211/phy* */
  68. scnprintf(buf, sizeof(buf), "../../ath12k/%pd2", ar->debug.debugfs_pdev);
  69. ar->debug.debugfs_pdev_symlink = debugfs_create_symlink("ath12k",
  70. hw->wiphy->debugfsdir,
  71. buf);
  72. if (ar->mac.sbands[NL80211_BAND_5GHZ].channels) {
  73. debugfs_create_file("dfs_simulate_radar", 0200,
  74. ar->debug.debugfs_pdev, ar,
  75. &fops_simulate_radar);
  76. }
  77. ath12k_debugfs_htt_stats_register(ar);
  78. }
  79. void ath12k_debugfs_unregister(struct ath12k *ar)
  80. {
  81. if (!ar->debug.debugfs_pdev)
  82. return;
  83. /* Remove symlink under ieee80211/phy* */
  84. debugfs_remove(ar->debug.debugfs_pdev_symlink);
  85. debugfs_remove_recursive(ar->debug.debugfs_pdev);
  86. ar->debug.debugfs_pdev_symlink = NULL;
  87. ar->debug.debugfs_pdev = NULL;
  88. }