0001
0002 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0003
0004 #include <linux/device.h>
0005 #include <linux/pci.h>
0006
0007 #include "ath5k.h"
0008 #include "reg.h"
0009
0010 #define SIMPLE_SHOW_STORE(name, get, set) \
0011 static ssize_t ath5k_attr_show_##name(struct device *dev, \
0012 struct device_attribute *attr, \
0013 char *buf) \
0014 { \
0015 struct ieee80211_hw *hw = dev_get_drvdata(dev); \
0016 struct ath5k_hw *ah = hw->priv; \
0017 return sysfs_emit(buf, "%d\n", get); \
0018 } \
0019 \
0020 static ssize_t ath5k_attr_store_##name(struct device *dev, \
0021 struct device_attribute *attr, \
0022 const char *buf, size_t count) \
0023 { \
0024 struct ieee80211_hw *hw = dev_get_drvdata(dev); \
0025 struct ath5k_hw *ah = hw->priv; \
0026 int val, ret; \
0027 \
0028 ret = kstrtoint(buf, 10, &val); \
0029 if (ret < 0) \
0030 return ret; \
0031 set(ah, val); \
0032 return count; \
0033 } \
0034 static DEVICE_ATTR(name, 0644, \
0035 ath5k_attr_show_##name, ath5k_attr_store_##name)
0036
0037 #define SIMPLE_SHOW(name, get) \
0038 static ssize_t ath5k_attr_show_##name(struct device *dev, \
0039 struct device_attribute *attr, \
0040 char *buf) \
0041 { \
0042 struct ieee80211_hw *hw = dev_get_drvdata(dev); \
0043 struct ath5k_hw *ah = hw->priv; \
0044 return sysfs_emit(buf, "%d\n", get); \
0045 } \
0046 static DEVICE_ATTR(name, 0444, ath5k_attr_show_##name, NULL)
0047
0048
0049
0050 SIMPLE_SHOW_STORE(ani_mode, ah->ani_state.ani_mode, ath5k_ani_init);
0051 SIMPLE_SHOW_STORE(noise_immunity_level, ah->ani_state.noise_imm_level,
0052 ath5k_ani_set_noise_immunity_level);
0053 SIMPLE_SHOW_STORE(spur_level, ah->ani_state.spur_level,
0054 ath5k_ani_set_spur_immunity_level);
0055 SIMPLE_SHOW_STORE(firstep_level, ah->ani_state.firstep_level,
0056 ath5k_ani_set_firstep_level);
0057 SIMPLE_SHOW_STORE(ofdm_weak_signal_detection, ah->ani_state.ofdm_weak_sig,
0058 ath5k_ani_set_ofdm_weak_signal_detection);
0059 SIMPLE_SHOW_STORE(cck_weak_signal_detection, ah->ani_state.cck_weak_sig,
0060 ath5k_ani_set_cck_weak_signal_detection);
0061 SIMPLE_SHOW(spur_level_max, ah->ani_state.max_spur_level);
0062
0063 static ssize_t ath5k_attr_show_noise_immunity_level_max(struct device *dev,
0064 struct device_attribute *attr,
0065 char *buf)
0066 {
0067 return sysfs_emit(buf, "%d\n", ATH5K_ANI_MAX_NOISE_IMM_LVL);
0068 }
0069 static DEVICE_ATTR(noise_immunity_level_max, 0444,
0070 ath5k_attr_show_noise_immunity_level_max, NULL);
0071
0072 static ssize_t ath5k_attr_show_firstep_level_max(struct device *dev,
0073 struct device_attribute *attr,
0074 char *buf)
0075 {
0076 return sysfs_emit(buf, "%d\n", ATH5K_ANI_MAX_FIRSTEP_LVL);
0077 }
0078 static DEVICE_ATTR(firstep_level_max, 0444,
0079 ath5k_attr_show_firstep_level_max, NULL);
0080
0081 static struct attribute *ath5k_sysfs_entries_ani[] = {
0082 &dev_attr_ani_mode.attr,
0083 &dev_attr_noise_immunity_level.attr,
0084 &dev_attr_spur_level.attr,
0085 &dev_attr_firstep_level.attr,
0086 &dev_attr_ofdm_weak_signal_detection.attr,
0087 &dev_attr_cck_weak_signal_detection.attr,
0088 &dev_attr_noise_immunity_level_max.attr,
0089 &dev_attr_spur_level_max.attr,
0090 &dev_attr_firstep_level_max.attr,
0091 NULL
0092 };
0093
0094 static struct attribute_group ath5k_attribute_group_ani = {
0095 .name = "ani",
0096 .attrs = ath5k_sysfs_entries_ani,
0097 };
0098
0099
0100
0101
0102 int
0103 ath5k_sysfs_register(struct ath5k_hw *ah)
0104 {
0105 struct device *dev = ah->dev;
0106 int err;
0107
0108 err = sysfs_create_group(&dev->kobj, &ath5k_attribute_group_ani);
0109 if (err) {
0110 ATH5K_ERR(ah, "failed to create sysfs group\n");
0111 return err;
0112 }
0113
0114 return 0;
0115 }
0116
0117 void
0118 ath5k_sysfs_unregister(struct ath5k_hw *ah)
0119 {
0120 struct device *dev = ah->dev;
0121
0122 sysfs_remove_group(&dev->kobj, &ath5k_attribute_group_ani);
0123 }