140ca22eaSBruno Randolf #include <linux/device.h> 240ca22eaSBruno Randolf #include <linux/pci.h> 340ca22eaSBruno Randolf 440ca22eaSBruno Randolf #include "base.h" 540ca22eaSBruno Randolf #include "ath5k.h" 640ca22eaSBruno Randolf #include "reg.h" 740ca22eaSBruno Randolf 840ca22eaSBruno Randolf #define SIMPLE_SHOW_STORE(name, get, set) \ 940ca22eaSBruno Randolf static ssize_t ath5k_attr_show_##name(struct device *dev, \ 1040ca22eaSBruno Randolf struct device_attribute *attr, \ 1140ca22eaSBruno Randolf char *buf) \ 1240ca22eaSBruno Randolf { \ 1395acbd43SPavel Roskin struct ieee80211_hw *hw = dev_get_drvdata(dev); \ 14*e0d687bdSPavel Roskin struct ath5k_hw *ah = hw->priv; \ 1540ca22eaSBruno Randolf return snprintf(buf, PAGE_SIZE, "%d\n", get); \ 1640ca22eaSBruno Randolf } \ 1740ca22eaSBruno Randolf \ 1840ca22eaSBruno Randolf static ssize_t ath5k_attr_store_##name(struct device *dev, \ 1940ca22eaSBruno Randolf struct device_attribute *attr, \ 2040ca22eaSBruno Randolf const char *buf, size_t count) \ 2140ca22eaSBruno Randolf { \ 2295acbd43SPavel Roskin struct ieee80211_hw *hw = dev_get_drvdata(dev); \ 23*e0d687bdSPavel Roskin struct ath5k_hw *ah = hw->priv; \ 24e2df64c1SPavel Roskin int val, ret; \ 2540ca22eaSBruno Randolf \ 26e2df64c1SPavel Roskin ret = kstrtoint(buf, 10, &val); \ 27e2df64c1SPavel Roskin if (ret < 0) \ 28e2df64c1SPavel Roskin return ret; \ 29*e0d687bdSPavel Roskin set(ah, val); \ 3040ca22eaSBruno Randolf return count; \ 3140ca22eaSBruno Randolf } \ 3240ca22eaSBruno Randolf static DEVICE_ATTR(name, S_IRUGO | S_IWUSR, \ 3340ca22eaSBruno Randolf ath5k_attr_show_##name, ath5k_attr_store_##name) 3440ca22eaSBruno Randolf 3540ca22eaSBruno Randolf #define SIMPLE_SHOW(name, get) \ 3640ca22eaSBruno Randolf static ssize_t ath5k_attr_show_##name(struct device *dev, \ 3740ca22eaSBruno Randolf struct device_attribute *attr, \ 3840ca22eaSBruno Randolf char *buf) \ 3940ca22eaSBruno Randolf { \ 4095acbd43SPavel Roskin struct ieee80211_hw *hw = dev_get_drvdata(dev); \ 41*e0d687bdSPavel Roskin struct ath5k_hw *ah = hw->priv; \ 4240ca22eaSBruno Randolf return snprintf(buf, PAGE_SIZE, "%d\n", get); \ 4340ca22eaSBruno Randolf } \ 4440ca22eaSBruno Randolf static DEVICE_ATTR(name, S_IRUGO, ath5k_attr_show_##name, NULL) 4540ca22eaSBruno Randolf 4640ca22eaSBruno Randolf /*** ANI ***/ 4740ca22eaSBruno Randolf 48*e0d687bdSPavel Roskin SIMPLE_SHOW_STORE(ani_mode, ah->ani_state.ani_mode, ath5k_ani_init); 49*e0d687bdSPavel Roskin SIMPLE_SHOW_STORE(noise_immunity_level, ah->ani_state.noise_imm_level, 5040ca22eaSBruno Randolf ath5k_ani_set_noise_immunity_level); 51*e0d687bdSPavel Roskin SIMPLE_SHOW_STORE(spur_level, ah->ani_state.spur_level, 5240ca22eaSBruno Randolf ath5k_ani_set_spur_immunity_level); 53*e0d687bdSPavel Roskin SIMPLE_SHOW_STORE(firstep_level, ah->ani_state.firstep_level, 5440ca22eaSBruno Randolf ath5k_ani_set_firstep_level); 55*e0d687bdSPavel Roskin SIMPLE_SHOW_STORE(ofdm_weak_signal_detection, ah->ani_state.ofdm_weak_sig, 5640ca22eaSBruno Randolf ath5k_ani_set_ofdm_weak_signal_detection); 57*e0d687bdSPavel Roskin SIMPLE_SHOW_STORE(cck_weak_signal_detection, ah->ani_state.cck_weak_sig, 5840ca22eaSBruno Randolf ath5k_ani_set_cck_weak_signal_detection); 59*e0d687bdSPavel Roskin SIMPLE_SHOW(spur_level_max, ah->ani_state.max_spur_level); 6040ca22eaSBruno Randolf 6140ca22eaSBruno Randolf static ssize_t ath5k_attr_show_noise_immunity_level_max(struct device *dev, 6240ca22eaSBruno Randolf struct device_attribute *attr, 6340ca22eaSBruno Randolf char *buf) 6440ca22eaSBruno Randolf { 6540ca22eaSBruno Randolf return snprintf(buf, PAGE_SIZE, "%d\n", ATH5K_ANI_MAX_NOISE_IMM_LVL); 6640ca22eaSBruno Randolf } 6740ca22eaSBruno Randolf static DEVICE_ATTR(noise_immunity_level_max, S_IRUGO, 6840ca22eaSBruno Randolf ath5k_attr_show_noise_immunity_level_max, NULL); 6940ca22eaSBruno Randolf 7040ca22eaSBruno Randolf static ssize_t ath5k_attr_show_firstep_level_max(struct device *dev, 7140ca22eaSBruno Randolf struct device_attribute *attr, 7240ca22eaSBruno Randolf char *buf) 7340ca22eaSBruno Randolf { 7440ca22eaSBruno Randolf return snprintf(buf, PAGE_SIZE, "%d\n", ATH5K_ANI_MAX_FIRSTEP_LVL); 7540ca22eaSBruno Randolf } 7640ca22eaSBruno Randolf static DEVICE_ATTR(firstep_level_max, S_IRUGO, 7740ca22eaSBruno Randolf ath5k_attr_show_firstep_level_max, NULL); 7840ca22eaSBruno Randolf 7940ca22eaSBruno Randolf static struct attribute *ath5k_sysfs_entries_ani[] = { 8040ca22eaSBruno Randolf &dev_attr_ani_mode.attr, 8140ca22eaSBruno Randolf &dev_attr_noise_immunity_level.attr, 8240ca22eaSBruno Randolf &dev_attr_spur_level.attr, 8340ca22eaSBruno Randolf &dev_attr_firstep_level.attr, 8440ca22eaSBruno Randolf &dev_attr_ofdm_weak_signal_detection.attr, 8540ca22eaSBruno Randolf &dev_attr_cck_weak_signal_detection.attr, 8640ca22eaSBruno Randolf &dev_attr_noise_immunity_level_max.attr, 8740ca22eaSBruno Randolf &dev_attr_spur_level_max.attr, 8840ca22eaSBruno Randolf &dev_attr_firstep_level_max.attr, 8940ca22eaSBruno Randolf NULL 9040ca22eaSBruno Randolf }; 9140ca22eaSBruno Randolf 9240ca22eaSBruno Randolf static struct attribute_group ath5k_attribute_group_ani = { 9340ca22eaSBruno Randolf .name = "ani", 9440ca22eaSBruno Randolf .attrs = ath5k_sysfs_entries_ani, 9540ca22eaSBruno Randolf }; 9640ca22eaSBruno Randolf 9740ca22eaSBruno Randolf 9840ca22eaSBruno Randolf /*** register / unregister ***/ 9940ca22eaSBruno Randolf 10040ca22eaSBruno Randolf int 101*e0d687bdSPavel Roskin ath5k_sysfs_register(struct ath5k_hw *ah) 10240ca22eaSBruno Randolf { 103*e0d687bdSPavel Roskin struct device *dev = ah->dev; 10440ca22eaSBruno Randolf int err; 10540ca22eaSBruno Randolf 10640ca22eaSBruno Randolf err = sysfs_create_group(&dev->kobj, &ath5k_attribute_group_ani); 10740ca22eaSBruno Randolf if (err) { 108*e0d687bdSPavel Roskin ATH5K_ERR(ah, "failed to create sysfs group\n"); 10940ca22eaSBruno Randolf return err; 11040ca22eaSBruno Randolf } 11140ca22eaSBruno Randolf 11240ca22eaSBruno Randolf return 0; 11340ca22eaSBruno Randolf } 11440ca22eaSBruno Randolf 11540ca22eaSBruno Randolf void 116*e0d687bdSPavel Roskin ath5k_sysfs_unregister(struct ath5k_hw *ah) 11740ca22eaSBruno Randolf { 118*e0d687bdSPavel Roskin struct device *dev = ah->dev; 11940ca22eaSBruno Randolf 12040ca22eaSBruno Randolf sysfs_remove_group(&dev->kobj, &ath5k_attribute_group_ani); 12140ca22eaSBruno Randolf } 122