mac80211: merge a big batch of upstream changes/improvements
[openwrt.git] / package / kernel / mac80211 / patches / 512-ath9k_channelbw_debugfs.patch
1 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
2 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
3 @@ -701,6 +701,7 @@ struct ath_softc {
4         struct ieee80211_hw *hw;
5         struct device *dev;
6  
7 +       u32 chan_bw;
8         struct survey_info *cur_survey;
9         struct survey_info survey[ATH9K_NUM_CHANNELS];
10  
11 @@ -905,6 +906,7 @@ struct fft_sample_ht20 {
12         u8 data[SPECTRAL_HT20_NUM_BINS];
13  } __packed;
14  
15 +int ath9k_config(struct ieee80211_hw *hw, u32 changed);
16  void ath9k_tasklet(unsigned long data);
17  int ath_cabq_update(struct ath_softc *);
18  
19 --- a/drivers/net/wireless/ath/ath9k/debug.c
20 +++ b/drivers/net/wireless/ath/ath9k/debug.c
21 @@ -1918,6 +1918,50 @@ static const struct file_operations fops
22         .owner = THIS_MODULE
23  };
24  
25 +
26 +static ssize_t read_file_chan_bw(struct file *file, char __user *user_buf,
27 +                            size_t count, loff_t *ppos)
28 +{
29 +       struct ath_softc *sc = file->private_data;
30 +       char buf[32];
31 +       unsigned int len;
32 +
33 +       len = sprintf(buf, "0x%08x\n", sc->chan_bw);
34 +       return simple_read_from_buffer(user_buf, count, ppos, buf, len);
35 +}
36 +
37 +static ssize_t write_file_chan_bw(struct file *file, const char __user *user_buf,
38 +                            size_t count, loff_t *ppos)
39 +{
40 +       struct ath_softc *sc = file->private_data;
41 +       unsigned long chan_bw;
42 +       char buf[32];
43 +       ssize_t len;
44 +
45 +       len = min(count, sizeof(buf) - 1);
46 +       if (copy_from_user(buf, user_buf, len))
47 +               return -EFAULT;
48 +
49 +       buf[len] = '\0';
50 +       if (kstrtoul(buf, 0, &chan_bw))
51 +               return -EINVAL;
52 +
53 +       sc->chan_bw = chan_bw;
54 +       if (!test_bit(SC_OP_INVALID, &sc->sc_flags))
55 +               ath9k_config(sc->hw, IEEE80211_CONF_CHANGE_CHANNEL);
56 +
57 +       return count;
58 +}
59 +
60 +static const struct file_operations fops_chanbw = {
61 +       .read = read_file_chan_bw,
62 +       .write = write_file_chan_bw,
63 +       .open = simple_open,
64 +       .owner = THIS_MODULE,
65 +       .llseek = default_llseek,
66 +};
67 +
68 +
69  int ath9k_init_debug(struct ath_hw *ah)
70  {
71         struct ath_common *common = ath9k_hw_common(ah);
72 @@ -1937,6 +1981,8 @@ int ath9k_init_debug(struct ath_hw *ah)
73  
74         debugfs_create_file("eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
75                             &fops_eeprom);
76 +       debugfs_create_file("chanbw", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
77 +                           sc, &fops_chanbw);
78         debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
79                             &fops_dma);
80         debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc,
81 --- a/drivers/net/wireless/ath/ath9k/main.c
82 +++ b/drivers/net/wireless/ath/ath9k/main.c
83 @@ -1146,7 +1146,7 @@ int ath9k_spectral_scan_config(struct ie
84         return 0;
85  }
86  
87 -static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
88 +int ath9k_config(struct ieee80211_hw *hw, u32 changed)
89  {
90         struct ath_softc *sc = hw->priv;
91         struct ath_hw *ah = sc->sc_ah;
92 @@ -1200,8 +1200,10 @@ static int ath9k_config(struct ieee80211
93  
94         if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) || reset_channel) {
95                 struct ieee80211_channel *curchan = hw->conf.chandef.chan;
96 +               struct ath9k_channel *hchan;
97                 int pos = curchan->hw_value;
98                 int old_pos = -1;
99 +               u32 oldflags;
100                 unsigned long flags;
101  
102                 if (ah->curchan)
103 @@ -1238,7 +1240,23 @@ static int ath9k_config(struct ieee80211
104                         memset(&sc->survey[pos], 0, sizeof(struct survey_info));
105                 }
106  
107 -               if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) {
108 +               hchan = &sc->sc_ah->channels[pos];
109 +               oldflags = hchan->channelFlags;
110 +               switch (sc->chan_bw) {
111 +               case 5:
112 +                       hchan->channelFlags &= ~CHANNEL_HALF;
113 +                       hchan->channelFlags |= CHANNEL_QUARTER;
114 +                       break;
115 +               case 10:
116 +                       hchan->channelFlags &= ~CHANNEL_QUARTER;
117 +                       hchan->channelFlags |= CHANNEL_HALF;
118 +                       break;
119 +               default:
120 +                       hchan->channelFlags &= ~(CHANNEL_HALF | CHANNEL_QUARTER);
121 +                       break;
122 +               }
123 +
124 +               if (ath_set_channel(sc, hw, hchan) < 0) {
125                         ath_err(common, "Unable to set channel\n");
126                         mutex_unlock(&sc->mutex);
127                         ath9k_ps_restore(sc);