sysfs.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // SPDX-License-Identifier: GPL-2.0
  2. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  3. #include <linux/device.h>
  4. #include <linux/pci.h>
  5. #include "ath5k.h"
  6. #include "reg.h"
  7. #define SIMPLE_SHOW_STORE(name, get, set) \
  8. static ssize_t ath5k_attr_show_##name(struct device *dev, \
  9. struct device_attribute *attr, \
  10. char *buf) \
  11. { \
  12. struct ieee80211_hw *hw = dev_get_drvdata(dev); \
  13. struct ath5k_hw *ah = hw->priv; \
  14. return snprintf(buf, PAGE_SIZE, "%d\n", get); \
  15. } \
  16. \
  17. static ssize_t ath5k_attr_store_##name(struct device *dev, \
  18. struct device_attribute *attr, \
  19. const char *buf, size_t count) \
  20. { \
  21. struct ieee80211_hw *hw = dev_get_drvdata(dev); \
  22. struct ath5k_hw *ah = hw->priv; \
  23. int val, ret; \
  24. \
  25. ret = kstrtoint(buf, 10, &val); \
  26. if (ret < 0) \
  27. return ret; \
  28. set(ah, val); \
  29. return count; \
  30. } \
  31. static DEVICE_ATTR(name, 0644, \
  32. ath5k_attr_show_##name, ath5k_attr_store_##name)
  33. #define SIMPLE_SHOW(name, get) \
  34. static ssize_t ath5k_attr_show_##name(struct device *dev, \
  35. struct device_attribute *attr, \
  36. char *buf) \
  37. { \
  38. struct ieee80211_hw *hw = dev_get_drvdata(dev); \
  39. struct ath5k_hw *ah = hw->priv; \
  40. return snprintf(buf, PAGE_SIZE, "%d\n", get); \
  41. } \
  42. static DEVICE_ATTR(name, 0444, ath5k_attr_show_##name, NULL)
  43. /*** ANI ***/
  44. SIMPLE_SHOW_STORE(ani_mode, ah->ani_state.ani_mode, ath5k_ani_init);
  45. SIMPLE_SHOW_STORE(noise_immunity_level, ah->ani_state.noise_imm_level,
  46. ath5k_ani_set_noise_immunity_level);
  47. SIMPLE_SHOW_STORE(spur_level, ah->ani_state.spur_level,
  48. ath5k_ani_set_spur_immunity_level);
  49. SIMPLE_SHOW_STORE(firstep_level, ah->ani_state.firstep_level,
  50. ath5k_ani_set_firstep_level);
  51. SIMPLE_SHOW_STORE(ofdm_weak_signal_detection, ah->ani_state.ofdm_weak_sig,
  52. ath5k_ani_set_ofdm_weak_signal_detection);
  53. SIMPLE_SHOW_STORE(cck_weak_signal_detection, ah->ani_state.cck_weak_sig,
  54. ath5k_ani_set_cck_weak_signal_detection);
  55. SIMPLE_SHOW(spur_level_max, ah->ani_state.max_spur_level);
  56. static ssize_t ath5k_attr_show_noise_immunity_level_max(struct device *dev,
  57. struct device_attribute *attr,
  58. char *buf)
  59. {
  60. return snprintf(buf, PAGE_SIZE, "%d\n", ATH5K_ANI_MAX_NOISE_IMM_LVL);
  61. }
  62. static DEVICE_ATTR(noise_immunity_level_max, 0444,
  63. ath5k_attr_show_noise_immunity_level_max, NULL);
  64. static ssize_t ath5k_attr_show_firstep_level_max(struct device *dev,
  65. struct device_attribute *attr,
  66. char *buf)
  67. {
  68. return snprintf(buf, PAGE_SIZE, "%d\n", ATH5K_ANI_MAX_FIRSTEP_LVL);
  69. }
  70. static DEVICE_ATTR(firstep_level_max, 0444,
  71. ath5k_attr_show_firstep_level_max, NULL);
  72. static struct attribute *ath5k_sysfs_entries_ani[] = {
  73. &dev_attr_ani_mode.attr,
  74. &dev_attr_noise_immunity_level.attr,
  75. &dev_attr_spur_level.attr,
  76. &dev_attr_firstep_level.attr,
  77. &dev_attr_ofdm_weak_signal_detection.attr,
  78. &dev_attr_cck_weak_signal_detection.attr,
  79. &dev_attr_noise_immunity_level_max.attr,
  80. &dev_attr_spur_level_max.attr,
  81. &dev_attr_firstep_level_max.attr,
  82. NULL
  83. };
  84. static struct attribute_group ath5k_attribute_group_ani = {
  85. .name = "ani",
  86. .attrs = ath5k_sysfs_entries_ani,
  87. };
  88. /*** register / unregister ***/
  89. int
  90. ath5k_sysfs_register(struct ath5k_hw *ah)
  91. {
  92. struct device *dev = ah->dev;
  93. int err;
  94. err = sysfs_create_group(&dev->kobj, &ath5k_attribute_group_ani);
  95. if (err) {
  96. ATH5K_ERR(ah, "failed to create sysfs group\n");
  97. return err;
  98. }
  99. return 0;
  100. }
  101. void
  102. ath5k_sysfs_unregister(struct ath5k_hw *ah)
  103. {
  104. struct device *dev = ah->dev;
  105. sysfs_remove_group(&dev->kobj, &ath5k_attribute_group_ani);
  106. }