ath9k: add some cleanups and minor fixes
[openwrt/svn-archive/archive.git] / package / kernel / mac80211 / patches / 512-ath9k_channelbw_debugfs.patch
1 --- a/drivers/net/wireless/ath/ath9k/debug.c
2 +++ b/drivers/net/wireless/ath/ath9k/debug.c
3 @@ -1918,6 +1918,52 @@ static const struct file_operations fops
4 .owner = THIS_MODULE
5 };
6
7 +
8 +static ssize_t read_file_chan_bw(struct file *file, char __user *user_buf,
9 + size_t count, loff_t *ppos)
10 +{
11 + struct ath_softc *sc = file->private_data;
12 + struct ath_common *common = ath9k_hw_common(sc->sc_ah);
13 + char buf[32];
14 + unsigned int len;
15 +
16 + len = sprintf(buf, "0x%08x\n", common->chan_bw);
17 + return simple_read_from_buffer(user_buf, count, ppos, buf, len);
18 +}
19 +
20 +static ssize_t write_file_chan_bw(struct file *file, const char __user *user_buf,
21 + size_t count, loff_t *ppos)
22 +{
23 + struct ath_softc *sc = file->private_data;
24 + struct ath_common *common = ath9k_hw_common(sc->sc_ah);
25 + unsigned long chan_bw;
26 + char buf[32];
27 + ssize_t len;
28 +
29 + len = min(count, sizeof(buf) - 1);
30 + if (copy_from_user(buf, user_buf, len))
31 + return -EFAULT;
32 +
33 + buf[len] = '\0';
34 + if (kstrtoul(buf, 0, &chan_bw))
35 + return -EINVAL;
36 +
37 + common->chan_bw = chan_bw;
38 + if (!test_bit(SC_OP_INVALID, &sc->sc_flags))
39 + ath9k_ops.config(sc->hw, IEEE80211_CONF_CHANGE_CHANNEL);
40 +
41 + return count;
42 +}
43 +
44 +static const struct file_operations fops_chanbw = {
45 + .read = read_file_chan_bw,
46 + .write = write_file_chan_bw,
47 + .open = simple_open,
48 + .owner = THIS_MODULE,
49 + .llseek = default_llseek,
50 +};
51 +
52 +
53 int ath9k_init_debug(struct ath_hw *ah)
54 {
55 struct ath_common *common = ath9k_hw_common(ah);
56 @@ -1937,6 +1983,8 @@ int ath9k_init_debug(struct ath_hw *ah)
57
58 debugfs_create_file("eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
59 &fops_eeprom);
60 + debugfs_create_file("chanbw", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
61 + sc, &fops_chanbw);
62 debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
63 &fops_dma);
64 debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc,
65 --- a/drivers/net/wireless/ath/ath.h
66 +++ b/drivers/net/wireless/ath/ath.h
67 @@ -129,6 +129,7 @@ struct ath_common {
68 struct ieee80211_hw *hw;
69 int debug_mask;
70 enum ath_device_state state;
71 + u32 chan_bw;
72
73 struct ath_ani ani;
74
75 --- a/drivers/net/wireless/ath/ath9k/common.c
76 +++ b/drivers/net/wireless/ath/ath9k/common.c
77 @@ -52,11 +52,13 @@ EXPORT_SYMBOL(ath9k_cmn_get_hw_crypto_ke
78 /*
79 * Update internal channel flags.
80 */
81 -static void ath9k_cmn_update_ichannel(struct ath9k_channel *ichan,
82 +static void ath9k_cmn_update_ichannel(struct ath_common *common,
83 + struct ath9k_channel *ichan,
84 struct cfg80211_chan_def *chandef)
85 {
86 struct ieee80211_channel *chan = chandef->chan;
87 u16 flags = 0;
88 + int width;
89
90 ichan->channel = chan->center_freq;
91 ichan->chan = chan;
92 @@ -64,7 +66,19 @@ static void ath9k_cmn_update_ichannel(st
93 if (chan->band == IEEE80211_BAND_5GHZ)
94 flags |= CHANNEL_5GHZ;
95
96 - switch (chandef->width) {
97 + switch (common->chan_bw) {
98 + case 5:
99 + width = NL80211_CHAN_WIDTH_5;
100 + break;
101 + case 10:
102 + width = NL80211_CHAN_WIDTH_10;
103 + break;
104 + default:
105 + width = chandef->width;
106 + break;
107 + }
108 +
109 + switch (width) {
110 case NL80211_CHAN_WIDTH_5:
111 flags |= CHANNEL_QUARTER;
112 break;
113 @@ -97,12 +111,13 @@ struct ath9k_channel *ath9k_cmn_get_chan
114 struct cfg80211_chan_def *chandef)
115 {
116 struct ieee80211_channel *curchan = chandef->chan;
117 + struct ath_common *common = ath9k_hw_common(ah);
118 struct ath9k_channel *channel;
119 u8 chan_idx;
120
121 chan_idx = curchan->hw_value;
122 channel = &ah->channels[chan_idx];
123 - ath9k_cmn_update_ichannel(channel, chandef);
124 + ath9k_cmn_update_ichannel(common, channel, chandef);
125
126 return channel;
127 }