1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2516304b0SJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
3516304b0SJoe Perches
440ca22eaSBruno Randolf #include <linux/device.h>
540ca22eaSBruno Randolf #include <linux/pci.h>
640ca22eaSBruno Randolf
740ca22eaSBruno Randolf #include "ath5k.h"
840ca22eaSBruno Randolf #include "reg.h"
940ca22eaSBruno Randolf
1040ca22eaSBruno Randolf #define SIMPLE_SHOW_STORE(name, get, set) \
1140ca22eaSBruno Randolf static ssize_t ath5k_attr_show_##name(struct device *dev, \
1240ca22eaSBruno Randolf struct device_attribute *attr, \
1340ca22eaSBruno Randolf char *buf) \
1440ca22eaSBruno Randolf { \
1595acbd43SPavel Roskin struct ieee80211_hw *hw = dev_get_drvdata(dev); \
16e0d687bdSPavel Roskin struct ath5k_hw *ah = hw->priv; \
17*65b4b8aaSQing Wang return sysfs_emit(buf, "%d\n", get); \
1840ca22eaSBruno Randolf } \
1940ca22eaSBruno Randolf \
2040ca22eaSBruno Randolf static ssize_t ath5k_attr_store_##name(struct device *dev, \
2140ca22eaSBruno Randolf struct device_attribute *attr, \
2240ca22eaSBruno Randolf const char *buf, size_t count) \
2340ca22eaSBruno Randolf { \
2495acbd43SPavel Roskin struct ieee80211_hw *hw = dev_get_drvdata(dev); \
25e0d687bdSPavel Roskin struct ath5k_hw *ah = hw->priv; \
26e2df64c1SPavel Roskin int val, ret; \
2740ca22eaSBruno Randolf \
28e2df64c1SPavel Roskin ret = kstrtoint(buf, 10, &val); \
29e2df64c1SPavel Roskin if (ret < 0) \
30e2df64c1SPavel Roskin return ret; \
31e0d687bdSPavel Roskin set(ah, val); \
3240ca22eaSBruno Randolf return count; \
3340ca22eaSBruno Randolf } \
342ef00c53SJoe Perches static DEVICE_ATTR(name, 0644, \
3540ca22eaSBruno Randolf ath5k_attr_show_##name, ath5k_attr_store_##name)
3640ca22eaSBruno Randolf
3740ca22eaSBruno Randolf #define SIMPLE_SHOW(name, get) \
3840ca22eaSBruno Randolf static ssize_t ath5k_attr_show_##name(struct device *dev, \
3940ca22eaSBruno Randolf struct device_attribute *attr, \
4040ca22eaSBruno Randolf char *buf) \
4140ca22eaSBruno Randolf { \
4295acbd43SPavel Roskin struct ieee80211_hw *hw = dev_get_drvdata(dev); \
43e0d687bdSPavel Roskin struct ath5k_hw *ah = hw->priv; \
44*65b4b8aaSQing Wang return sysfs_emit(buf, "%d\n", get); \
4540ca22eaSBruno Randolf } \
462ef00c53SJoe Perches static DEVICE_ATTR(name, 0444, ath5k_attr_show_##name, NULL)
4740ca22eaSBruno Randolf
4840ca22eaSBruno Randolf /*** ANI ***/
4940ca22eaSBruno Randolf
50e0d687bdSPavel Roskin SIMPLE_SHOW_STORE(ani_mode, ah->ani_state.ani_mode, ath5k_ani_init);
51e0d687bdSPavel Roskin SIMPLE_SHOW_STORE(noise_immunity_level, ah->ani_state.noise_imm_level,
5240ca22eaSBruno Randolf ath5k_ani_set_noise_immunity_level);
53e0d687bdSPavel Roskin SIMPLE_SHOW_STORE(spur_level, ah->ani_state.spur_level,
5440ca22eaSBruno Randolf ath5k_ani_set_spur_immunity_level);
55e0d687bdSPavel Roskin SIMPLE_SHOW_STORE(firstep_level, ah->ani_state.firstep_level,
5640ca22eaSBruno Randolf ath5k_ani_set_firstep_level);
57e0d687bdSPavel Roskin SIMPLE_SHOW_STORE(ofdm_weak_signal_detection, ah->ani_state.ofdm_weak_sig,
5840ca22eaSBruno Randolf ath5k_ani_set_ofdm_weak_signal_detection);
59e0d687bdSPavel Roskin SIMPLE_SHOW_STORE(cck_weak_signal_detection, ah->ani_state.cck_weak_sig,
6040ca22eaSBruno Randolf ath5k_ani_set_cck_weak_signal_detection);
61e0d687bdSPavel Roskin SIMPLE_SHOW(spur_level_max, ah->ani_state.max_spur_level);
6240ca22eaSBruno Randolf
ath5k_attr_show_noise_immunity_level_max(struct device * dev,struct device_attribute * attr,char * buf)6340ca22eaSBruno Randolf static ssize_t ath5k_attr_show_noise_immunity_level_max(struct device *dev,
6440ca22eaSBruno Randolf struct device_attribute *attr,
6540ca22eaSBruno Randolf char *buf)
6640ca22eaSBruno Randolf {
67*65b4b8aaSQing Wang return sysfs_emit(buf, "%d\n", ATH5K_ANI_MAX_NOISE_IMM_LVL);
6840ca22eaSBruno Randolf }
692ef00c53SJoe Perches static DEVICE_ATTR(noise_immunity_level_max, 0444,
7040ca22eaSBruno Randolf ath5k_attr_show_noise_immunity_level_max, NULL);
7140ca22eaSBruno Randolf
ath5k_attr_show_firstep_level_max(struct device * dev,struct device_attribute * attr,char * buf)7240ca22eaSBruno Randolf static ssize_t ath5k_attr_show_firstep_level_max(struct device *dev,
7340ca22eaSBruno Randolf struct device_attribute *attr,
7440ca22eaSBruno Randolf char *buf)
7540ca22eaSBruno Randolf {
76*65b4b8aaSQing Wang return sysfs_emit(buf, "%d\n", ATH5K_ANI_MAX_FIRSTEP_LVL);
7740ca22eaSBruno Randolf }
782ef00c53SJoe Perches static DEVICE_ATTR(firstep_level_max, 0444,
7940ca22eaSBruno Randolf ath5k_attr_show_firstep_level_max, NULL);
8040ca22eaSBruno Randolf
8140ca22eaSBruno Randolf static struct attribute *ath5k_sysfs_entries_ani[] = {
8240ca22eaSBruno Randolf &dev_attr_ani_mode.attr,
8340ca22eaSBruno Randolf &dev_attr_noise_immunity_level.attr,
8440ca22eaSBruno Randolf &dev_attr_spur_level.attr,
8540ca22eaSBruno Randolf &dev_attr_firstep_level.attr,
8640ca22eaSBruno Randolf &dev_attr_ofdm_weak_signal_detection.attr,
8740ca22eaSBruno Randolf &dev_attr_cck_weak_signal_detection.attr,
8840ca22eaSBruno Randolf &dev_attr_noise_immunity_level_max.attr,
8940ca22eaSBruno Randolf &dev_attr_spur_level_max.attr,
9040ca22eaSBruno Randolf &dev_attr_firstep_level_max.attr,
9140ca22eaSBruno Randolf NULL
9240ca22eaSBruno Randolf };
9340ca22eaSBruno Randolf
9440ca22eaSBruno Randolf static struct attribute_group ath5k_attribute_group_ani = {
9540ca22eaSBruno Randolf .name = "ani",
9640ca22eaSBruno Randolf .attrs = ath5k_sysfs_entries_ani,
9740ca22eaSBruno Randolf };
9840ca22eaSBruno Randolf
9940ca22eaSBruno Randolf
10040ca22eaSBruno Randolf /*** register / unregister ***/
10140ca22eaSBruno Randolf
10240ca22eaSBruno Randolf int
ath5k_sysfs_register(struct ath5k_hw * ah)103e0d687bdSPavel Roskin ath5k_sysfs_register(struct ath5k_hw *ah)
10440ca22eaSBruno Randolf {
105e0d687bdSPavel Roskin struct device *dev = ah->dev;
10640ca22eaSBruno Randolf int err;
10740ca22eaSBruno Randolf
10840ca22eaSBruno Randolf err = sysfs_create_group(&dev->kobj, &ath5k_attribute_group_ani);
10940ca22eaSBruno Randolf if (err) {
110e0d687bdSPavel Roskin ATH5K_ERR(ah, "failed to create sysfs group\n");
11140ca22eaSBruno Randolf return err;
11240ca22eaSBruno Randolf }
11340ca22eaSBruno Randolf
11440ca22eaSBruno Randolf return 0;
11540ca22eaSBruno Randolf }
11640ca22eaSBruno Randolf
11740ca22eaSBruno Randolf void
ath5k_sysfs_unregister(struct ath5k_hw * ah)118e0d687bdSPavel Roskin ath5k_sysfs_unregister(struct ath5k_hw *ah)
11940ca22eaSBruno Randolf {
120e0d687bdSPavel Roskin struct device *dev = ah->dev;
12140ca22eaSBruno Randolf
12240ca22eaSBruno Randolf sysfs_remove_group(&dev->kobj, &ath5k_attribute_group_ani);
12340ca22eaSBruno Randolf }
124