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