sysfs.c 3.5 KB

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