1*516304b0SJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 2*516304b0SJoe Perches 340ca22eaSBruno Randolf #include <linux/device.h> 440ca22eaSBruno Randolf #include <linux/pci.h> 540ca22eaSBruno Randolf 640ca22eaSBruno Randolf #include "ath5k.h" 740ca22eaSBruno Randolf #include "reg.h" 840ca22eaSBruno Randolf 940ca22eaSBruno Randolf #define SIMPLE_SHOW_STORE(name, get, set) \ 1040ca22eaSBruno Randolf static ssize_t ath5k_attr_show_##name(struct device *dev, \ 1140ca22eaSBruno Randolf struct device_attribute *attr, \ 1240ca22eaSBruno Randolf char *buf) \ 1340ca22eaSBruno Randolf { \ 1495acbd43SPavel Roskin struct ieee80211_hw *hw = dev_get_drvdata(dev); \ 15e0d687bdSPavel Roskin struct ath5k_hw *ah = hw->priv; \ 1640ca22eaSBruno Randolf return snprintf(buf, PAGE_SIZE, "%d\n", get); \ 1740ca22eaSBruno Randolf } \ 1840ca22eaSBruno Randolf \ 1940ca22eaSBruno Randolf static ssize_t ath5k_attr_store_##name(struct device *dev, \ 2040ca22eaSBruno Randolf struct device_attribute *attr, \ 2140ca22eaSBruno Randolf const char *buf, size_t count) \ 2240ca22eaSBruno Randolf { \ 2395acbd43SPavel Roskin struct ieee80211_hw *hw = dev_get_drvdata(dev); \ 24e0d687bdSPavel Roskin struct ath5k_hw *ah = hw->priv; \ 25e2df64c1SPavel Roskin int val, ret; \ 2640ca22eaSBruno Randolf \ 27e2df64c1SPavel Roskin ret = kstrtoint(buf, 10, &val); \ 28e2df64c1SPavel Roskin if (ret < 0) \ 29e2df64c1SPavel Roskin return ret; \ 30e0d687bdSPavel Roskin set(ah, val); \ 3140ca22eaSBruno Randolf return count; \ 3240ca22eaSBruno Randolf } \ 3340ca22eaSBruno Randolf static DEVICE_ATTR(name, S_IRUGO | S_IWUSR, \ 3440ca22eaSBruno Randolf ath5k_attr_show_##name, ath5k_attr_store_##name) 3540ca22eaSBruno Randolf 3640ca22eaSBruno Randolf #define SIMPLE_SHOW(name, get) \ 3740ca22eaSBruno Randolf static ssize_t ath5k_attr_show_##name(struct device *dev, \ 3840ca22eaSBruno Randolf struct device_attribute *attr, \ 3940ca22eaSBruno Randolf char *buf) \ 4040ca22eaSBruno Randolf { \ 4195acbd43SPavel Roskin struct ieee80211_hw *hw = dev_get_drvdata(dev); \ 42e0d687bdSPavel Roskin struct ath5k_hw *ah = hw->priv; \ 4340ca22eaSBruno Randolf return snprintf(buf, PAGE_SIZE, "%d\n", get); \ 4440ca22eaSBruno Randolf } \ 4540ca22eaSBruno Randolf static DEVICE_ATTR(name, S_IRUGO, ath5k_attr_show_##name, NULL) 4640ca22eaSBruno Randolf 4740ca22eaSBruno Randolf /*** ANI ***/ 4840ca22eaSBruno Randolf 49e0d687bdSPavel Roskin SIMPLE_SHOW_STORE(ani_mode, ah->ani_state.ani_mode, ath5k_ani_init); 50e0d687bdSPavel Roskin SIMPLE_SHOW_STORE(noise_immunity_level, ah->ani_state.noise_imm_level, 5140ca22eaSBruno Randolf ath5k_ani_set_noise_immunity_level); 52e0d687bdSPavel Roskin SIMPLE_SHOW_STORE(spur_level, ah->ani_state.spur_level, 5340ca22eaSBruno Randolf ath5k_ani_set_spur_immunity_level); 54e0d687bdSPavel Roskin SIMPLE_SHOW_STORE(firstep_level, ah->ani_state.firstep_level, 5540ca22eaSBruno Randolf ath5k_ani_set_firstep_level); 56e0d687bdSPavel Roskin SIMPLE_SHOW_STORE(ofdm_weak_signal_detection, ah->ani_state.ofdm_weak_sig, 5740ca22eaSBruno Randolf ath5k_ani_set_ofdm_weak_signal_detection); 58e0d687bdSPavel Roskin SIMPLE_SHOW_STORE(cck_weak_signal_detection, ah->ani_state.cck_weak_sig, 5940ca22eaSBruno Randolf ath5k_ani_set_cck_weak_signal_detection); 60e0d687bdSPavel Roskin SIMPLE_SHOW(spur_level_max, ah->ani_state.max_spur_level); 6140ca22eaSBruno Randolf 6240ca22eaSBruno Randolf static ssize_t ath5k_attr_show_noise_immunity_level_max(struct device *dev, 6340ca22eaSBruno Randolf struct device_attribute *attr, 6440ca22eaSBruno Randolf char *buf) 6540ca22eaSBruno Randolf { 6640ca22eaSBruno Randolf return snprintf(buf, PAGE_SIZE, "%d\n", ATH5K_ANI_MAX_NOISE_IMM_LVL); 6740ca22eaSBruno Randolf } 6840ca22eaSBruno Randolf static DEVICE_ATTR(noise_immunity_level_max, S_IRUGO, 6940ca22eaSBruno Randolf ath5k_attr_show_noise_immunity_level_max, NULL); 7040ca22eaSBruno Randolf 7140ca22eaSBruno Randolf static ssize_t ath5k_attr_show_firstep_level_max(struct device *dev, 7240ca22eaSBruno Randolf struct device_attribute *attr, 7340ca22eaSBruno Randolf char *buf) 7440ca22eaSBruno Randolf { 7540ca22eaSBruno Randolf return snprintf(buf, PAGE_SIZE, "%d\n", ATH5K_ANI_MAX_FIRSTEP_LVL); 7640ca22eaSBruno Randolf } 7740ca22eaSBruno Randolf static DEVICE_ATTR(firstep_level_max, S_IRUGO, 7840ca22eaSBruno Randolf ath5k_attr_show_firstep_level_max, NULL); 7940ca22eaSBruno Randolf 8040ca22eaSBruno Randolf static struct attribute *ath5k_sysfs_entries_ani[] = { 8140ca22eaSBruno Randolf &dev_attr_ani_mode.attr, 8240ca22eaSBruno Randolf &dev_attr_noise_immunity_level.attr, 8340ca22eaSBruno Randolf &dev_attr_spur_level.attr, 8440ca22eaSBruno Randolf &dev_attr_firstep_level.attr, 8540ca22eaSBruno Randolf &dev_attr_ofdm_weak_signal_detection.attr, 8640ca22eaSBruno Randolf &dev_attr_cck_weak_signal_detection.attr, 8740ca22eaSBruno Randolf &dev_attr_noise_immunity_level_max.attr, 8840ca22eaSBruno Randolf &dev_attr_spur_level_max.attr, 8940ca22eaSBruno Randolf &dev_attr_firstep_level_max.attr, 9040ca22eaSBruno Randolf NULL 9140ca22eaSBruno Randolf }; 9240ca22eaSBruno Randolf 9340ca22eaSBruno Randolf static struct attribute_group ath5k_attribute_group_ani = { 9440ca22eaSBruno Randolf .name = "ani", 9540ca22eaSBruno Randolf .attrs = ath5k_sysfs_entries_ani, 9640ca22eaSBruno Randolf }; 9740ca22eaSBruno Randolf 9840ca22eaSBruno Randolf 9940ca22eaSBruno Randolf /*** register / unregister ***/ 10040ca22eaSBruno Randolf 10140ca22eaSBruno Randolf int 102e0d687bdSPavel Roskin ath5k_sysfs_register(struct ath5k_hw *ah) 10340ca22eaSBruno Randolf { 104e0d687bdSPavel Roskin struct device *dev = ah->dev; 10540ca22eaSBruno Randolf int err; 10640ca22eaSBruno Randolf 10740ca22eaSBruno Randolf err = sysfs_create_group(&dev->kobj, &ath5k_attribute_group_ani); 10840ca22eaSBruno Randolf if (err) { 109e0d687bdSPavel Roskin ATH5K_ERR(ah, "failed to create sysfs group\n"); 11040ca22eaSBruno Randolf return err; 11140ca22eaSBruno Randolf } 11240ca22eaSBruno Randolf 11340ca22eaSBruno Randolf return 0; 11440ca22eaSBruno Randolf } 11540ca22eaSBruno Randolf 11640ca22eaSBruno Randolf void 117e0d687bdSPavel Roskin ath5k_sysfs_unregister(struct ath5k_hw *ah) 11840ca22eaSBruno Randolf { 119e0d687bdSPavel Roskin struct device *dev = ah->dev; 12040ca22eaSBruno Randolf 12140ca22eaSBruno Randolf sysfs_remove_group(&dev->kobj, &ath5k_attribute_group_ani); 12240ca22eaSBruno Randolf } 123