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