mac80211: merge another round of upstream fixes
[openwrt.git] / package / kernel / mac80211 / patches / 300-pending_work.patch
1 --- a/drivers/net/wireless/ath/ath10k/mac.c
2 +++ b/drivers/net/wireless/ath/ath10k/mac.c
3 @@ -1351,12 +1351,12 @@ static int ath10k_update_channel_list(st
4                         ch->allow_vht = true;
5  
6                         ch->allow_ibss =
7 -                               !(channel->flags & IEEE80211_CHAN_NO_IBSS);
8 +                               !(channel->flags & IEEE80211_CHAN_NO_IR);
9  
10                         ch->ht40plus =
11                                 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
12  
13 -                       passive = channel->flags & IEEE80211_CHAN_PASSIVE_SCAN;
14 +                       passive = channel->flags & IEEE80211_CHAN_NO_IR;
15                         ch->passive = passive;
16  
17                         ch->freq = channel->center_freq;
18 --- a/drivers/net/wireless/ath/ath9k/Kconfig
19 +++ b/drivers/net/wireless/ath/ath9k/Kconfig
20 @@ -90,7 +90,7 @@ config ATH9K_DFS_CERTIFIED
21  
22  config ATH9K_TX99
23         bool "Atheros ath9k TX99 testing support"
24 -       depends on CFG80211_CERTIFICATION_ONUS
25 +       depends on ATH9K_DEBUGFS && CFG80211_CERTIFICATION_ONUS
26         default n
27         ---help---
28           Say N. This should only be enabled on systems undergoing
29 @@ -108,6 +108,14 @@ config ATH9K_TX99
30           be evaluated to meet the RF exposure limits set forth in the
31           governmental SAR regulations.
32  
33 +config ATH9K_WOW
34 +       bool "Wake on Wireless LAN support (EXPERIMENTAL)"
35 +       depends on ATH9K && PM
36 +       default n
37 +       ---help---
38 +         This option enables Wake on Wireless LAN support for certain cards.
39 +         Currently, AR9462 is supported.
40 +
41  config ATH9K_LEGACY_RATE_CONTROL
42         bool "Atheros ath9k rate control"
43         depends on ATH9K
44 --- a/drivers/net/wireless/ath/ath9k/Makefile
45 +++ b/drivers/net/wireless/ath/ath9k/Makefile
46 @@ -13,9 +13,9 @@ ath9k-$(CPTCFG_ATH9K_PCI) += pci.o
47  ath9k-$(CPTCFG_ATH9K_AHB) += ahb.o
48  ath9k-$(CPTCFG_ATH9K_DEBUGFS) += debug.o
49  ath9k-$(CPTCFG_ATH9K_DFS_DEBUGFS) += dfs_debug.o
50 -ath9k-$(CPTCFG_ATH9K_DFS_CERTIFIED) += \
51 -               dfs.o
52 -ath9k-$(CONFIG_PM_SLEEP) += wow.o
53 +ath9k-$(CPTCFG_ATH9K_DFS_CERTIFIED) += dfs.o
54 +ath9k-$(CPTCFG_ATH9K_TX99) += tx99.o
55 +ath9k-$(CPTCFG_ATH9K_WOW) += wow.o
56  
57  obj-$(CPTCFG_ATH9K) += ath9k.o
58  
59 @@ -41,6 +41,8 @@ ath9k_hw-y:=  \
60                 ar9003_eeprom.o \
61                 ar9003_paprd.o
62  
63 +ath9k_hw-$(CPTCFG_ATH9K_WOW) += ar9003_wow.o
64 +
65  ath9k_hw-$(CPTCFG_ATH9K_BTCOEX_SUPPORT) += btcoex.o \
66                                            ar9003_mci.o
67  obj-$(CPTCFG_ATH9K_HW) += ath9k_hw.o
68 --- a/drivers/net/wireless/ath/ath9k/ar9003_hw.c
69 +++ b/drivers/net/wireless/ath/ath9k/ar9003_hw.c
70 @@ -581,6 +581,13 @@ static void ar9003_tx_gain_table_mode6(s
71                         ar9580_1p0_type6_tx_gain_table);
72  }
73  
74 +static void ar9003_tx_gain_table_mode7(struct ath_hw *ah)
75 +{
76 +       if (AR_SREV_9340(ah))
77 +               INIT_INI_ARRAY(&ah->iniModesTxGain,
78 +                              ar9340_cus227_tx_gain_table_1p0);
79 +}
80 +
81  typedef void (*ath_txgain_tab)(struct ath_hw *ah);
82  
83  static void ar9003_tx_gain_table_apply(struct ath_hw *ah)
84 @@ -593,6 +600,7 @@ static void ar9003_tx_gain_table_apply(s
85                 ar9003_tx_gain_table_mode4,
86                 ar9003_tx_gain_table_mode5,
87                 ar9003_tx_gain_table_mode6,
88 +               ar9003_tx_gain_table_mode7,
89         };
90         int idx = ar9003_hw_get_tx_gain_idx(ah);
91  
92 @@ -750,6 +758,9 @@ static void ar9003_hw_init_mode_gain_reg
93  static void ar9003_hw_configpcipowersave(struct ath_hw *ah,
94                                          bool power_off)
95  {
96 +       unsigned int i;
97 +       struct ar5416IniArray *array;
98 +
99         /*
100          * Increase L1 Entry Latency. Some WB222 boards don't have
101          * this change in eeprom/OTP.
102 @@ -775,18 +786,13 @@ static void ar9003_hw_configpcipowersave
103          * Configire PCIE after Ini init. SERDES values now come from ini file
104          * This enables PCIe low power mode.
105          */
106 -       if (ah->config.pcieSerDesWrite) {
107 -               unsigned int i;
108 -               struct ar5416IniArray *array;
109 -
110 -               array = power_off ? &ah->iniPcieSerdes :
111 -                                   &ah->iniPcieSerdesLowPower;
112 -
113 -               for (i = 0; i < array->ia_rows; i++) {
114 -                       REG_WRITE(ah,
115 -                                 INI_RA(array, i, 0),
116 -                                 INI_RA(array, i, 1));
117 -               }
118 +       array = power_off ? &ah->iniPcieSerdes :
119 +               &ah->iniPcieSerdesLowPower;
120 +
121 +       for (i = 0; i < array->ia_rows; i++) {
122 +               REG_WRITE(ah,
123 +                         INI_RA(array, i, 0),
124 +                         INI_RA(array, i, 1));
125         }
126  }
127  
128 --- a/drivers/net/wireless/ath/ath9k/ar9340_initvals.h
129 +++ b/drivers/net/wireless/ath/ath9k/ar9340_initvals.h
130 @@ -1447,4 +1447,106 @@ static const u32 ar9340_1p0_soc_preamble
131         {0x00007038, 0x000004c2},
132  };
133  
134 +static const u32 ar9340_cus227_tx_gain_table_1p0[][5] = {
135 +       /* Addr      5G_HT20     5G_HT40     2G_HT40     2G_HT20   */
136 +       {0x0000a2dc, 0x0380c7fc, 0x0380c7fc, 0x03aaa352, 0x03aaa352},
137 +       {0x0000a2e0, 0x0000f800, 0x0000f800, 0x03ccc584, 0x03ccc584},
138 +       {0x0000a2e4, 0x03ff0000, 0x03ff0000, 0x03f0f800, 0x03f0f800},
139 +       {0x0000a2e8, 0x00000000, 0x00000000, 0x03ff0000, 0x03ff0000},
140 +       {0x0000a410, 0x000050d9, 0x000050d9, 0x000050d9, 0x000050d9},
141 +       {0x0000a500, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
142 +       {0x0000a504, 0x06000003, 0x06000003, 0x04000002, 0x04000002},
143 +       {0x0000a508, 0x0a000020, 0x0a000020, 0x08000004, 0x08000004},
144 +       {0x0000a50c, 0x10000023, 0x10000023, 0x0b000200, 0x0b000200},
145 +       {0x0000a510, 0x16000220, 0x16000220, 0x0f000202, 0x0f000202},
146 +       {0x0000a514, 0x1c000223, 0x1c000223, 0x11000400, 0x11000400},
147 +       {0x0000a518, 0x21002220, 0x21002220, 0x15000402, 0x15000402},
148 +       {0x0000a51c, 0x27002223, 0x27002223, 0x19000404, 0x19000404},
149 +       {0x0000a520, 0x2c022220, 0x2c022220, 0x1b000603, 0x1b000603},
150 +       {0x0000a524, 0x30022222, 0x30022222, 0x1f000a02, 0x1f000a02},
151 +       {0x0000a528, 0x35022225, 0x35022225, 0x23000a04, 0x23000a04},
152 +       {0x0000a52c, 0x3b02222a, 0x3b02222a, 0x26000a20, 0x26000a20},
153 +       {0x0000a530, 0x3f02222c, 0x3f02222c, 0x2a000e20, 0x2a000e20},
154 +       {0x0000a534, 0x4202242a, 0x4202242a, 0x2e000e22, 0x2e000e22},
155 +       {0x0000a538, 0x4702244a, 0x4702244a, 0x31000e24, 0x31000e24},
156 +       {0x0000a53c, 0x4b02244c, 0x4b02244c, 0x34001640, 0x34001640},
157 +       {0x0000a540, 0x4e02246c, 0x4e02246c, 0x38001660, 0x38001660},
158 +       {0x0000a544, 0x5302266c, 0x5302266c, 0x3b001861, 0x3b001861},
159 +       {0x0000a548, 0x5702286c, 0x5702286c, 0x3e001a81, 0x3e001a81},
160 +       {0x0000a54c, 0x5c02486b, 0x5c02486b, 0x42001a83, 0x42001a83},
161 +       {0x0000a550, 0x61024a6c, 0x61024a6c, 0x44001c84, 0x44001c84},
162 +       {0x0000a554, 0x66026a6c, 0x66026a6c, 0x48001ce3, 0x48001ce3},
163 +       {0x0000a558, 0x6b026e6c, 0x6b026e6c, 0x4c001ce5, 0x4c001ce5},
164 +       {0x0000a55c, 0x7002708c, 0x7002708c, 0x50001ce9, 0x50001ce9},
165 +       {0x0000a560, 0x7302b08a, 0x7302b08a, 0x54001ceb, 0x54001ceb},
166 +       {0x0000a564, 0x7702b08c, 0x7702b08c, 0x56001eec, 0x56001eec},
167 +       {0x0000a568, 0x7702b08c, 0x7702b08c, 0x56001eec, 0x56001eec},
168 +       {0x0000a56c, 0x7702b08c, 0x7702b08c, 0x56001eec, 0x56001eec},
169 +       {0x0000a570, 0x7702b08c, 0x7702b08c, 0x56001eec, 0x56001eec},
170 +       {0x0000a574, 0x7702b08c, 0x7702b08c, 0x56001eec, 0x56001eec},
171 +       {0x0000a578, 0x7702b08c, 0x7702b08c, 0x56001eec, 0x56001eec},
172 +       {0x0000a57c, 0x7702b08c, 0x7702b08c, 0x56001eec, 0x56001eec},
173 +       {0x0000a580, 0x00800000, 0x00800000, 0x00800000, 0x00800000},
174 +       {0x0000a584, 0x06800003, 0x06800003, 0x04800002, 0x04800002},
175 +       {0x0000a588, 0x0a800020, 0x0a800020, 0x08800004, 0x08800004},
176 +       {0x0000a58c, 0x10800023, 0x10800023, 0x0b800200, 0x0b800200},
177 +       {0x0000a590, 0x16800220, 0x16800220, 0x0f800202, 0x0f800202},
178 +       {0x0000a594, 0x1c800223, 0x1c800223, 0x11800400, 0x11800400},
179 +       {0x0000a598, 0x21820220, 0x21820220, 0x15800402, 0x15800402},
180 +       {0x0000a59c, 0x27820223, 0x27820223, 0x19800404, 0x19800404},
181 +       {0x0000a5a0, 0x2b822220, 0x2b822220, 0x1b800603, 0x1b800603},
182 +       {0x0000a5a4, 0x2f822222, 0x2f822222, 0x1f800a02, 0x1f800a02},
183 +       {0x0000a5a8, 0x34822225, 0x34822225, 0x23800a04, 0x23800a04},
184 +       {0x0000a5ac, 0x3a82222a, 0x3a82222a, 0x26800a20, 0x26800a20},
185 +       {0x0000a5b0, 0x3e82222c, 0x3e82222c, 0x2a800e20, 0x2a800e20},
186 +       {0x0000a5b4, 0x4282242a, 0x4282242a, 0x2e800e22, 0x2e800e22},
187 +       {0x0000a5b8, 0x4782244a, 0x4782244a, 0x31800e24, 0x31800e24},
188 +       {0x0000a5bc, 0x4b82244c, 0x4b82244c, 0x34801640, 0x34801640},
189 +       {0x0000a5c0, 0x4e82246c, 0x4e82246c, 0x38801660, 0x38801660},
190 +       {0x0000a5c4, 0x5382266c, 0x5382266c, 0x3b801861, 0x3b801861},
191 +       {0x0000a5c8, 0x5782286c, 0x5782286c, 0x3e801a81, 0x3e801a81},
192 +       {0x0000a5cc, 0x5c84286b, 0x5c84286b, 0x42801a83, 0x42801a83},
193 +       {0x0000a5d0, 0x61842a6c, 0x61842a6c, 0x44801c84, 0x44801c84},
194 +       {0x0000a5d4, 0x66862a6c, 0x66862a6c, 0x48801ce3, 0x48801ce3},
195 +       {0x0000a5d8, 0x6b862e6c, 0x6b862e6c, 0x4c801ce5, 0x4c801ce5},
196 +       {0x0000a5dc, 0x7086308c, 0x7086308c, 0x50801ce9, 0x50801ce9},
197 +       {0x0000a5e0, 0x738a308a, 0x738a308a, 0x54801ceb, 0x54801ceb},
198 +       {0x0000a5e4, 0x778a308c, 0x778a308c, 0x56801eec, 0x56801eec},
199 +       {0x0000a5e8, 0x778a308c, 0x778a308c, 0x56801eec, 0x56801eec},
200 +       {0x0000a5ec, 0x778a308c, 0x778a308c, 0x56801eec, 0x56801eec},
201 +       {0x0000a5f0, 0x778a308c, 0x778a308c, 0x56801eec, 0x56801eec},
202 +       {0x0000a5f4, 0x778a308c, 0x778a308c, 0x56801eec, 0x56801eec},
203 +       {0x0000a5f8, 0x778a308c, 0x778a308c, 0x56801eec, 0x56801eec},
204 +       {0x0000a5fc, 0x778a308c, 0x778a308c, 0x56801eec, 0x56801eec},
205 +       {0x0000a600, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
206 +       {0x0000a604, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
207 +       {0x0000a608, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
208 +       {0x0000a60c, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
209 +       {0x0000a610, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
210 +       {0x0000a614, 0x01404000, 0x01404000, 0x01404000, 0x01404000},
211 +       {0x0000a618, 0x01404501, 0x01404501, 0x01404501, 0x01404501},
212 +       {0x0000a61c, 0x02008802, 0x02008802, 0x02008501, 0x02008501},
213 +       {0x0000a620, 0x0300cc03, 0x0300cc03, 0x0280ca03, 0x0280ca03},
214 +       {0x0000a624, 0x0300cc03, 0x0300cc03, 0x03010c04, 0x03010c04},
215 +       {0x0000a628, 0x0300cc03, 0x0300cc03, 0x04014c04, 0x04014c04},
216 +       {0x0000a62c, 0x03810c03, 0x03810c03, 0x04015005, 0x04015005},
217 +       {0x0000a630, 0x03810e04, 0x03810e04, 0x04015005, 0x04015005},
218 +       {0x0000a634, 0x03810e04, 0x03810e04, 0x04015005, 0x04015005},
219 +       {0x0000a638, 0x03810e04, 0x03810e04, 0x04015005, 0x04015005},
220 +       {0x0000a63c, 0x03810e04, 0x03810e04, 0x04015005, 0x04015005},
221 +       {0x0000b2dc, 0x0380c7fc, 0x0380c7fc, 0x03aaa352, 0x03aaa352},
222 +       {0x0000b2e0, 0x0000f800, 0x0000f800, 0x03ccc584, 0x03ccc584},
223 +       {0x0000b2e4, 0x03ff0000, 0x03ff0000, 0x03f0f800, 0x03f0f800},
224 +       {0x0000b2e8, 0x00000000, 0x00000000, 0x03ff0000, 0x03ff0000},
225 +       {0x00016044, 0x056db2db, 0x056db2db, 0x03b6d2e4, 0x03b6d2e4},
226 +       {0x00016048, 0x24925666, 0x24925666, 0x8e481266, 0x8e481266},
227 +       {0x00016280, 0x01000015, 0x01000015, 0x01001015, 0x01001015},
228 +       {0x00016288, 0x30318000, 0x30318000, 0x00318000, 0x00318000},
229 +       {0x00016444, 0x056db2db, 0x056db2db, 0x03b6d2e4, 0x03b6d2e4},
230 +       {0x00016448, 0x24925666, 0x24925666, 0x8e481266, 0x8e481266},
231 +       {0x0000a3a4, 0x00000011, 0x00000011, 0x00000011, 0x00000011},
232 +       {0x0000a3a8, 0x3c3c3c3c, 0x3c3c3c3c, 0x3c3c3c3c, 0x3c3c3c3c},
233 +       {0x0000a3ac, 0x30303030, 0x30303030, 0x30303030, 0x30303030},
234 +};
235 +
236  #endif /* INITVALS_9340_H */
237 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
238 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
239 @@ -459,6 +459,7 @@ void ath_check_ani(struct ath_softc *sc)
240  int ath_update_survey_stats(struct ath_softc *sc);
241  void ath_update_survey_nf(struct ath_softc *sc, int channel);
242  void ath9k_queue_reset(struct ath_softc *sc, enum ath_reset_type type);
243 +void ath_ps_full_sleep(unsigned long data);
244  
245  /**********/
246  /* BTCOEX */
247 @@ -570,6 +571,34 @@ static inline void ath_fill_led_pin(stru
248  }
249  #endif
250  
251 +/************************/
252 +/* Wake on Wireless LAN */
253 +/************************/
254 +
255 +#ifdef CONFIG_ATH9K_WOW
256 +void ath9k_init_wow(struct ieee80211_hw *hw);
257 +int ath9k_suspend(struct ieee80211_hw *hw,
258 +                 struct cfg80211_wowlan *wowlan);
259 +int ath9k_resume(struct ieee80211_hw *hw);
260 +void ath9k_set_wakeup(struct ieee80211_hw *hw, bool enabled);
261 +#else
262 +static inline void ath9k_init_wow(struct ieee80211_hw *hw)
263 +{
264 +}
265 +static inline int ath9k_suspend(struct ieee80211_hw *hw,
266 +                               struct cfg80211_wowlan *wowlan)
267 +{
268 +       return 0;
269 +}
270 +static inline int ath9k_resume(struct ieee80211_hw *hw)
271 +{
272 +       return 0;
273 +}
274 +static inline void ath9k_set_wakeup(struct ieee80211_hw *hw, bool enabled)
275 +{
276 +}
277 +#endif /* CONFIG_ATH9K_WOW */
278 +
279  /*******************************/
280  /* Antenna diversity/combining */
281  /*******************************/
282 @@ -723,6 +752,7 @@ struct ath_softc {
283         struct work_struct hw_check_work;
284         struct work_struct hw_reset_work;
285         struct completion paprd_complete;
286 +       wait_queue_head_t tx_wait;
287  
288         unsigned int hw_busy_count;
289         unsigned long sc_flags;
290 @@ -759,6 +789,7 @@ struct ath_softc {
291         struct delayed_work tx_complete_work;
292         struct delayed_work hw_pll_work;
293         struct timer_list rx_poll_timer;
294 +       struct timer_list sleep_timer;
295  
296  #ifdef CPTCFG_ATH9K_BTCOEX_SUPPORT
297         struct ath_btcoex btcoex;
298 @@ -783,7 +814,7 @@ struct ath_softc {
299         bool tx99_state;
300         s16 tx99_power;
301  
302 -#ifdef CONFIG_PM_SLEEP
303 +#ifdef CONFIG_ATH9K_WOW
304         atomic_t wow_got_bmiss_intr;
305         atomic_t wow_sleep_proc_intr; /* in the middle of WoW sleep ? */
306         u32 wow_intr_before_sleep;
307 @@ -946,10 +977,25 @@ struct fft_sample_ht20_40 {
308         u8 data[SPECTRAL_HT20_40_NUM_BINS];
309  } __packed;
310  
311 -int ath9k_tx99_init(struct ath_softc *sc);
312 -void ath9k_tx99_deinit(struct ath_softc *sc);
313 +/********/
314 +/* TX99 */
315 +/********/
316 +
317 +#ifdef CONFIG_ATH9K_TX99
318 +void ath9k_tx99_init_debug(struct ath_softc *sc);
319  int ath9k_tx99_send(struct ath_softc *sc, struct sk_buff *skb,
320                     struct ath_tx_control *txctl);
321 +#else
322 +static inline void ath9k_tx99_init_debug(struct ath_softc *sc)
323 +{
324 +}
325 +static inline int ath9k_tx99_send(struct ath_softc *sc,
326 +                                 struct sk_buff *skb,
327 +                                 struct ath_tx_control *txctl)
328 +{
329 +       return 0;
330 +}
331 +#endif /* CONFIG_ATH9K_TX99 */
332  
333  void ath9k_tasklet(unsigned long data);
334  int ath_cabq_update(struct ath_softc *);
335 @@ -966,6 +1012,9 @@ extern bool is_ath9k_unloaded;
336  
337  u8 ath9k_parse_mpdudensity(u8 mpdudensity);
338  irqreturn_t ath_isr(int irq, void *dev);
339 +int ath_reset(struct ath_softc *sc);
340 +void ath_cancel_work(struct ath_softc *sc);
341 +void ath_restart_work(struct ath_softc *sc);
342  int ath9k_init_device(u16 devid, struct ath_softc *sc,
343                     const struct ath_bus_ops *bus_ops);
344  void ath9k_deinit_device(struct ath_softc *sc);
345 --- a/drivers/net/wireless/ath/ath9k/debug.c
346 +++ b/drivers/net/wireless/ath/ath9k/debug.c
347 @@ -1782,111 +1782,6 @@ void ath9k_deinit_debug(struct ath_softc
348         }
349  }
350  
351 -static ssize_t read_file_tx99(struct file *file, char __user *user_buf,
352 -                             size_t count, loff_t *ppos)
353 -{
354 -       struct ath_softc *sc = file->private_data;
355 -       char buf[3];
356 -       unsigned int len;
357 -
358 -       len = sprintf(buf, "%d\n", sc->tx99_state);
359 -       return simple_read_from_buffer(user_buf, count, ppos, buf, len);
360 -}
361 -
362 -static ssize_t write_file_tx99(struct file *file, const char __user *user_buf,
363 -                              size_t count, loff_t *ppos)
364 -{
365 -       struct ath_softc *sc = file->private_data;
366 -       struct ath_common *common = ath9k_hw_common(sc->sc_ah);
367 -       char buf[32];
368 -       bool start;
369 -       ssize_t len;
370 -       int r;
371 -
372 -       if (sc->nvifs > 1)
373 -               return -EOPNOTSUPP;
374 -
375 -       len = min(count, sizeof(buf) - 1);
376 -       if (copy_from_user(buf, user_buf, len))
377 -               return -EFAULT;
378 -
379 -       if (strtobool(buf, &start))
380 -               return -EINVAL;
381 -
382 -       if (start == sc->tx99_state) {
383 -               if (!start)
384 -                       return count;
385 -               ath_dbg(common, XMIT, "Resetting TX99\n");
386 -               ath9k_tx99_deinit(sc);
387 -       }
388 -
389 -       if (!start) {
390 -               ath9k_tx99_deinit(sc);
391 -               return count;
392 -       }
393 -
394 -       r = ath9k_tx99_init(sc);
395 -       if (r)
396 -               return r;
397 -
398 -       return count;
399 -}
400 -
401 -static const struct file_operations fops_tx99 = {
402 -       .read = read_file_tx99,
403 -       .write = write_file_tx99,
404 -       .open = simple_open,
405 -       .owner = THIS_MODULE,
406 -       .llseek = default_llseek,
407 -};
408 -
409 -static ssize_t read_file_tx99_power(struct file *file,
410 -                                   char __user *user_buf,
411 -                                   size_t count, loff_t *ppos)
412 -{
413 -       struct ath_softc *sc = file->private_data;
414 -       char buf[32];
415 -       unsigned int len;
416 -
417 -       len = sprintf(buf, "%d (%d dBm)\n",
418 -                     sc->tx99_power,
419 -                     sc->tx99_power / 2);
420 -
421 -       return simple_read_from_buffer(user_buf, count, ppos, buf, len);
422 -}
423 -
424 -static ssize_t write_file_tx99_power(struct file *file,
425 -                                    const char __user *user_buf,
426 -                                    size_t count, loff_t *ppos)
427 -{
428 -       struct ath_softc *sc = file->private_data;
429 -       int r;
430 -       u8 tx_power;
431 -
432 -       r = kstrtou8_from_user(user_buf, count, 0, &tx_power);
433 -       if (r)
434 -               return r;
435 -
436 -       if (tx_power > MAX_RATE_POWER)
437 -               return -EINVAL;
438 -
439 -       sc->tx99_power = tx_power;
440 -
441 -       ath9k_ps_wakeup(sc);
442 -       ath9k_hw_tx99_set_txpower(sc->sc_ah, sc->tx99_power);
443 -       ath9k_ps_restore(sc);
444 -
445 -       return count;
446 -}
447 -
448 -static const struct file_operations fops_tx99_power = {
449 -       .read = read_file_tx99_power,
450 -       .write = write_file_tx99_power,
451 -       .open = simple_open,
452 -       .owner = THIS_MODULE,
453 -       .llseek = default_llseek,
454 -};
455 -
456  int ath9k_init_debug(struct ath_hw *ah)
457  {
458         struct ath_common *common = ath9k_hw_common(ah);
459 @@ -1903,6 +1798,7 @@ int ath9k_init_debug(struct ath_hw *ah)
460  #endif
461  
462         ath9k_dfs_init_debug(sc);
463 +       ath9k_tx99_init_debug(sc);
464  
465         debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc,
466                             &fops_dma);
467 @@ -1978,15 +1874,6 @@ int ath9k_init_debug(struct ath_hw *ah)
468         debugfs_create_file("btcoex", S_IRUSR, sc->debug.debugfs_phy, sc,
469                             &fops_btcoex);
470  #endif
471 -       if (config_enabled(CPTCFG_ATH9K_TX99) &&
472 -           AR_SREV_9300_20_OR_LATER(ah)) {
473 -               debugfs_create_file("tx99", S_IRUSR | S_IWUSR,
474 -                                   sc->debug.debugfs_phy, sc,
475 -                                   &fops_tx99);
476 -               debugfs_create_file("tx99_power", S_IRUSR | S_IWUSR,
477 -                                   sc->debug.debugfs_phy, sc,
478 -                                   &fops_tx99_power);
479 -       }
480  
481         return 0;
482  }
483 --- a/drivers/net/wireless/ath/ath9k/hw.c
484 +++ b/drivers/net/wireless/ath/ath9k/hw.c
485 @@ -17,6 +17,7 @@
486  #include <linux/io.h>
487  #include <linux/slab.h>
488  #include <linux/module.h>
489 +#include <linux/time.h>
490  #include <asm/unaligned.h>
491  
492  #include "hw.h"
493 @@ -454,7 +455,6 @@ static void ath9k_hw_init_config(struct 
494         }
495  
496         ah->config.rx_intr_mitigation = true;
497 -       ah->config.pcieSerDesWrite = true;
498  
499         /*
500          * We need this for PCI devices only (Cardbus, PCI, miniPCI)
501 @@ -1502,8 +1502,9 @@ static bool ath9k_hw_channel_change(stru
502         int r;
503  
504         if (pCap->hw_caps & ATH9K_HW_CAP_FCC_BAND_SWITCH) {
505 -               band_switch = IS_CHAN_5GHZ(ah->curchan) != IS_CHAN_5GHZ(chan);
506 -               mode_diff = (chan->channelFlags != ah->curchan->channelFlags);
507 +               u32 flags_diff = chan->channelFlags ^ ah->curchan->channelFlags;
508 +               band_switch = !!(flags_diff & CHANNEL_5GHZ);
509 +               mode_diff = !!(flags_diff & ~CHANNEL_HT);
510         }
511  
512         for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
513 @@ -1815,7 +1816,7 @@ static int ath9k_hw_do_fastcc(struct ath
514          * If cross-band fcc is not supoprted, bail out if channelFlags differ.
515          */
516         if (!(pCap->hw_caps & ATH9K_HW_CAP_FCC_BAND_SWITCH) &&
517 -           chan->channelFlags != ah->curchan->channelFlags)
518 +           ((chan->channelFlags ^ ah->curchan->channelFlags) & ~CHANNEL_HT))
519                 goto fail;
520  
521         if (!ath9k_hw_check_alive(ah))
522 @@ -1856,10 +1857,12 @@ int ath9k_hw_reset(struct ath_hw *ah, st
523                    struct ath9k_hw_cal_data *caldata, bool fastcc)
524  {
525         struct ath_common *common = ath9k_hw_common(ah);
526 +       struct timespec ts;
527         u32 saveLedState;
528         u32 saveDefAntenna;
529         u32 macStaId1;
530         u64 tsf = 0;
531 +       s64 usec = 0;
532         int r;
533         bool start_mci_reset = false;
534         bool save_fullsleep = ah->chip_fullsleep;
535 @@ -1902,10 +1905,10 @@ int ath9k_hw_reset(struct ath_hw *ah, st
536  
537         macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
538  
539 -       /* For chips on which RTC reset is done, save TSF before it gets cleared */
540 -       if (AR_SREV_9100(ah) ||
541 -           (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)))
542 -               tsf = ath9k_hw_gettsf64(ah);
543 +       /* Save TSF before chip reset, a cold reset clears it */
544 +       tsf = ath9k_hw_gettsf64(ah);
545 +       getrawmonotonic(&ts);
546 +       usec = ts.tv_sec * 1000 + ts.tv_nsec / 1000;
547  
548         saveLedState = REG_READ(ah, AR_CFG_LED) &
549                 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
550 @@ -1938,8 +1941,9 @@ int ath9k_hw_reset(struct ath_hw *ah, st
551         }
552  
553         /* Restore TSF */
554 -       if (tsf)
555 -               ath9k_hw_settsf64(ah, tsf);
556 +       getrawmonotonic(&ts);
557 +       usec = ts.tv_sec * 1000 + ts.tv_nsec / 1000 - usec;
558 +       ath9k_hw_settsf64(ah, tsf + usec);
559  
560         if (AR_SREV_9280_20_OR_LATER(ah))
561                 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
562 --- a/drivers/net/wireless/ath/ath9k/hw.h
563 +++ b/drivers/net/wireless/ath/ath9k/hw.h
564 @@ -283,7 +283,6 @@ struct ath9k_ops_config {
565         int additional_swba_backoff;
566         int ack_6mb;
567         u32 cwm_ignore_extcca;
568 -       bool pcieSerDesWrite;
569         u8 pcie_clock_req;
570         u32 pcie_waen;
571         u8 analog_shiftreg;
572 @@ -920,7 +919,7 @@ struct ath_hw {
573         /* Enterprise mode cap */
574         u32 ent_mode;
575  
576 -#ifdef CONFIG_PM_SLEEP
577 +#ifdef CONFIG_ATH9K_WOW
578         u32 wow_event_mask;
579  #endif
580         bool is_clk_25mhz;
581 @@ -1126,7 +1125,7 @@ ath9k_hw_get_btcoex_scheme(struct ath_hw
582  #endif /* CPTCFG_ATH9K_BTCOEX_SUPPORT */
583  
584  
585 -#ifdef CONFIG_PM_SLEEP
586 +#ifdef CONFIG_ATH9K_WOW
587  const char *ath9k_hw_wow_event_to_string(u32 wow_event);
588  void ath9k_hw_wow_apply_pattern(struct ath_hw *ah, u8 *user_pattern,
589                                 u8 *user_mask, int pattern_count,
590 --- a/drivers/net/wireless/ath/ath9k/init.c
591 +++ b/drivers/net/wireless/ath/ath9k/init.c
592 @@ -683,6 +683,7 @@ static int ath9k_init_softc(u16 devid, s
593         common = ath9k_hw_common(ah);
594         sc->dfs_detector = dfs_pattern_detector_init(common, NL80211_DFS_UNSET);
595         sc->tx99_power = MAX_RATE_POWER + 1;
596 +       init_waitqueue_head(&sc->tx_wait);
597  
598         if (!pdata) {
599                 ah->ah_flags |= AH_USE_EEPROM;
600 @@ -730,6 +731,7 @@ static int ath9k_init_softc(u16 devid, s
601         tasklet_init(&sc->bcon_tasklet, ath9k_beacon_tasklet,
602                      (unsigned long)sc);
603  
604 +       setup_timer(&sc->sleep_timer, ath_ps_full_sleep, (unsigned long)sc);
605         INIT_WORK(&sc->hw_reset_work, ath_reset_work);
606         INIT_WORK(&sc->hw_check_work, ath_hw_check);
607         INIT_WORK(&sc->paprd_work, ath_paprd_calibrate);
608 @@ -845,7 +847,8 @@ static const struct ieee80211_iface_limi
609  };
610  
611  static const struct ieee80211_iface_limit if_dfs_limits[] = {
612 -       { .max = 1,     .types = BIT(NL80211_IFTYPE_AP) },
613 +       { .max = 1,     .types = BIT(NL80211_IFTYPE_AP) |
614 +                                BIT(NL80211_IFTYPE_ADHOC) },
615  };
616  
617  static const struct ieee80211_iface_combination if_comb[] = {
618 @@ -862,20 +865,11 @@ static const struct ieee80211_iface_comb
619                 .max_interfaces = 1,
620                 .num_different_channels = 1,
621                 .beacon_int_infra_match = true,
622 -               .radar_detect_widths =  BIT(NL80211_CHAN_NO_HT) |
623 -                                       BIT(NL80211_CHAN_HT20),
624 +               .radar_detect_widths =  BIT(NL80211_CHAN_WIDTH_20_NOHT) |
625 +                                       BIT(NL80211_CHAN_WIDTH_20),
626         }
627  };
628  
629 -#ifdef CONFIG_PM
630 -static const struct wiphy_wowlan_support ath9k_wowlan_support = {
631 -       .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT,
632 -       .n_patterns = MAX_NUM_USER_PATTERN,
633 -       .pattern_min_len = 1,
634 -       .pattern_max_len = MAX_PATTERN_SIZE,
635 -};
636 -#endif
637 -
638  void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
639  {
640         struct ath_hw *ah = sc->sc_ah;
641 @@ -925,16 +919,6 @@ void ath9k_set_hw_capab(struct ath_softc
642         hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_5_10_MHZ;
643         hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
644  
645 -#ifdef CONFIG_PM_SLEEP
646 -       if ((ah->caps.hw_caps & ATH9K_HW_WOW_DEVICE_CAPABLE) &&
647 -           (sc->driver_data & ATH9K_PCI_WOW) &&
648 -           device_can_wakeup(sc->dev))
649 -               hw->wiphy->wowlan = &ath9k_wowlan_support;
650 -
651 -       atomic_set(&sc->wow_sleep_proc_intr, -1);
652 -       atomic_set(&sc->wow_got_bmiss_intr, -1);
653 -#endif
654 -
655         hw->queues = 4;
656         hw->max_rates = 4;
657         hw->channel_change_time = 5000;
658 @@ -960,6 +944,7 @@ void ath9k_set_hw_capab(struct ath_softc
659                 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
660                         &sc->sbands[IEEE80211_BAND_5GHZ];
661  
662 +       ath9k_init_wow(hw);
663         ath9k_reload_chainmask_settings(sc);
664  
665         SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
666 @@ -1058,6 +1043,7 @@ static void ath9k_deinit_softc(struct at
667                 if (ATH_TXQ_SETUP(sc, i))
668                         ath_tx_cleanupq(sc, &sc->tx.txq[i]);
669  
670 +       del_timer_sync(&sc->sleep_timer);
671         ath9k_hw_deinit(sc->sc_ah);
672         if (sc->dfs_detector != NULL)
673                 sc->dfs_detector->exit(sc->dfs_detector);
674 --- a/drivers/net/wireless/ath/ath9k/main.c
675 +++ b/drivers/net/wireless/ath/ath9k/main.c
676 @@ -82,6 +82,22 @@ static bool ath9k_setpower(struct ath_so
677         return ret;
678  }
679  
680 +void ath_ps_full_sleep(unsigned long data)
681 +{
682 +       struct ath_softc *sc = (struct ath_softc *) data;
683 +       struct ath_common *common = ath9k_hw_common(sc->sc_ah);
684 +       bool reset;
685 +
686 +       spin_lock(&common->cc_lock);
687 +       ath_hw_cycle_counters_update(common);
688 +       spin_unlock(&common->cc_lock);
689 +
690 +       ath9k_hw_setrxabort(sc->sc_ah, 1);
691 +       ath9k_hw_stopdmarecv(sc->sc_ah, &reset);
692 +
693 +       ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_FULL_SLEEP);
694 +}
695 +
696  void ath9k_ps_wakeup(struct ath_softc *sc)
697  {
698         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
699 @@ -92,6 +108,7 @@ void ath9k_ps_wakeup(struct ath_softc *s
700         if (++sc->ps_usecount != 1)
701                 goto unlock;
702  
703 +       del_timer_sync(&sc->sleep_timer);
704         power_mode = sc->sc_ah->power_mode;
705         ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
706  
707 @@ -117,17 +134,17 @@ void ath9k_ps_restore(struct ath_softc *
708         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
709         enum ath9k_power_mode mode;
710         unsigned long flags;
711 -       bool reset;
712  
713         spin_lock_irqsave(&sc->sc_pm_lock, flags);
714         if (--sc->ps_usecount != 0)
715                 goto unlock;
716  
717         if (sc->ps_idle) {
718 -               ath9k_hw_setrxabort(sc->sc_ah, 1);
719 -               ath9k_hw_stopdmarecv(sc->sc_ah, &reset);
720 -               mode = ATH9K_PM_FULL_SLEEP;
721 -       } else if (sc->ps_enabled &&
722 +               mod_timer(&sc->sleep_timer, jiffies + HZ / 10);
723 +               goto unlock;
724 +       }
725 +
726 +       if (sc->ps_enabled &&
727                    !(sc->ps_flags & (PS_WAIT_FOR_BEACON |
728                                      PS_WAIT_FOR_CAB |
729                                      PS_WAIT_FOR_PSPOLL_DATA |
730 @@ -163,13 +180,13 @@ static void __ath_cancel_work(struct ath
731  #endif
732  }
733  
734 -static void ath_cancel_work(struct ath_softc *sc)
735 +void ath_cancel_work(struct ath_softc *sc)
736  {
737         __ath_cancel_work(sc);
738         cancel_work_sync(&sc->hw_reset_work);
739  }
740  
741 -static void ath_restart_work(struct ath_softc *sc)
742 +void ath_restart_work(struct ath_softc *sc)
743  {
744         ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
745  
746 @@ -487,6 +504,8 @@ void ath9k_tasklet(unsigned long data)
747                         ath_tx_edma_tasklet(sc);
748                 else
749                         ath_tx_tasklet(sc);
750 +
751 +               wake_up(&sc->tx_wait);
752         }
753  
754         ath9k_btcoex_handle_interrupt(sc, status);
755 @@ -579,7 +598,8 @@ irqreturn_t ath_isr(int irq, void *dev)
756  
757                 goto chip_reset;
758         }
759 -#ifdef CONFIG_PM_SLEEP
760 +
761 +#ifdef CONFIG_ATH9K_WOW
762         if (status & ATH9K_INT_BMISS) {
763                 if (atomic_read(&sc->wow_sleep_proc_intr) == 0) {
764                         ath_dbg(common, ANY, "during WoW we got a BMISS\n");
765 @@ -588,6 +608,8 @@ irqreturn_t ath_isr(int irq, void *dev)
766                 }
767         }
768  #endif
769 +
770 +
771         if (status & ATH9K_INT_SWBA)
772                 tasklet_schedule(&sc->bcon_tasklet);
773  
774 @@ -627,7 +649,7 @@ chip_reset:
775  #undef SCHED_INTR
776  }
777  
778 -static int ath_reset(struct ath_softc *sc)
779 +int ath_reset(struct ath_softc *sc)
780  {
781         int r;
782  
783 @@ -1817,13 +1839,31 @@ static void ath9k_set_coverage_class(str
784         mutex_unlock(&sc->mutex);
785  }
786  
787 +static bool ath9k_has_tx_pending(struct ath_softc *sc)
788 +{
789 +       int i, npend;
790 +
791 +       for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
792 +               if (!ATH_TXQ_SETUP(sc, i))
793 +                       continue;
794 +
795 +               if (!sc->tx.txq[i].axq_depth)
796 +                       continue;
797 +
798 +               npend = ath9k_has_pending_frames(sc, &sc->tx.txq[i]);
799 +               if (npend)
800 +                       break;
801 +       }
802 +
803 +       return !!npend;
804 +}
805 +
806  static void ath9k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
807  {
808         struct ath_softc *sc = hw->priv;
809         struct ath_hw *ah = sc->sc_ah;
810         struct ath_common *common = ath9k_hw_common(ah);
811 -       int timeout = 200; /* ms */
812 -       int i, j;
813 +       int timeout = HZ / 5; /* 200 ms */
814         bool drain_txq;
815  
816         mutex_lock(&sc->mutex);
817 @@ -1841,25 +1881,9 @@ static void ath9k_flush(struct ieee80211
818                 return;
819         }
820  
821 -       for (j = 0; j < timeout; j++) {
822 -               bool npend = false;
823 -
824 -               if (j)
825 -                       usleep_range(1000, 2000);
826 -
827 -               for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
828 -                       if (!ATH_TXQ_SETUP(sc, i))
829 -                               continue;
830 -
831 -                       npend = ath9k_has_pending_frames(sc, &sc->tx.txq[i]);
832 -
833 -                       if (npend)
834 -                               break;
835 -               }
836 -
837 -               if (!npend)
838 -                   break;
839 -       }
840 +       if (wait_event_timeout(sc->tx_wait, !ath9k_has_tx_pending(sc),
841 +                              timeout) > 0)
842 +               drop = false;
843  
844         if (drop) {
845                 ath9k_ps_wakeup(sc);
846 @@ -2021,333 +2045,6 @@ static int ath9k_get_antenna(struct ieee
847         return 0;
848  }
849  
850 -#ifdef CONFIG_PM_SLEEP
851 -
852 -static void ath9k_wow_map_triggers(struct ath_softc *sc,
853 -                                  struct cfg80211_wowlan *wowlan,
854 -                                  u32 *wow_triggers)
855 -{
856 -       if (wowlan->disconnect)
857 -               *wow_triggers |= AH_WOW_LINK_CHANGE |
858 -                                AH_WOW_BEACON_MISS;
859 -       if (wowlan->magic_pkt)
860 -               *wow_triggers |= AH_WOW_MAGIC_PATTERN_EN;
861 -
862 -       if (wowlan->n_patterns)
863 -               *wow_triggers |= AH_WOW_USER_PATTERN_EN;
864 -
865 -       sc->wow_enabled = *wow_triggers;
866 -
867 -}
868 -
869 -static void ath9k_wow_add_disassoc_deauth_pattern(struct ath_softc *sc)
870 -{
871 -       struct ath_hw *ah = sc->sc_ah;
872 -       struct ath_common *common = ath9k_hw_common(ah);
873 -       int pattern_count = 0;
874 -       int i, byte_cnt;
875 -       u8 dis_deauth_pattern[MAX_PATTERN_SIZE];
876 -       u8 dis_deauth_mask[MAX_PATTERN_SIZE];
877 -
878 -       memset(dis_deauth_pattern, 0, MAX_PATTERN_SIZE);
879 -       memset(dis_deauth_mask, 0, MAX_PATTERN_SIZE);
880 -
881 -       /*
882 -        * Create Dissassociate / Deauthenticate packet filter
883 -        *
884 -        *     2 bytes        2 byte    6 bytes   6 bytes  6 bytes
885 -        *  +--------------+----------+---------+--------+--------+----
886 -        *  + Frame Control+ Duration +   DA    +  SA    +  BSSID +
887 -        *  +--------------+----------+---------+--------+--------+----
888 -        *
889 -        * The above is the management frame format for disassociate/
890 -        * deauthenticate pattern, from this we need to match the first byte
891 -        * of 'Frame Control' and DA, SA, and BSSID fields
892 -        * (skipping 2nd byte of FC and Duration feild.
893 -        *
894 -        * Disassociate pattern
895 -        * --------------------
896 -        * Frame control = 00 00 1010
897 -        * DA, SA, BSSID = x:x:x:x:x:x
898 -        * Pattern will be A0000000 | x:x:x:x:x:x | x:x:x:x:x:x
899 -        *                          | x:x:x:x:x:x  -- 22 bytes
900 -        *
901 -        * Deauthenticate pattern
902 -        * ----------------------
903 -        * Frame control = 00 00 1100
904 -        * DA, SA, BSSID = x:x:x:x:x:x
905 -        * Pattern will be C0000000 | x:x:x:x:x:x | x:x:x:x:x:x
906 -        *                          | x:x:x:x:x:x  -- 22 bytes
907 -        */
908 -
909 -       /* Create Disassociate Pattern first */
910 -
911 -       byte_cnt = 0;
912 -
913 -       /* Fill out the mask with all FF's */
914 -
915 -       for (i = 0; i < MAX_PATTERN_MASK_SIZE; i++)
916 -               dis_deauth_mask[i] = 0xff;
917 -
918 -       /* copy the first byte of frame control field */
919 -       dis_deauth_pattern[byte_cnt] = 0xa0;
920 -       byte_cnt++;
921 -
922 -       /* skip 2nd byte of frame control and Duration field */
923 -       byte_cnt += 3;
924 -
925 -       /*
926 -        * need not match the destination mac address, it can be a broadcast
927 -        * mac address or an unicast to this station
928 -        */
929 -       byte_cnt += 6;
930 -
931 -       /* copy the source mac address */
932 -       memcpy((dis_deauth_pattern + byte_cnt), common->curbssid, ETH_ALEN);
933 -
934 -       byte_cnt += 6;
935 -
936 -       /* copy the bssid, its same as the source mac address */
937 -
938 -       memcpy((dis_deauth_pattern + byte_cnt), common->curbssid, ETH_ALEN);
939 -
940 -       /* Create Disassociate pattern mask */
941 -
942 -       dis_deauth_mask[0] = 0xfe;
943 -       dis_deauth_mask[1] = 0x03;
944 -       dis_deauth_mask[2] = 0xc0;
945 -
946 -       ath_dbg(common, WOW, "Adding disassoc/deauth patterns for WoW\n");
947 -
948 -       ath9k_hw_wow_apply_pattern(ah, dis_deauth_pattern, dis_deauth_mask,
949 -                                  pattern_count, byte_cnt);
950 -
951 -       pattern_count++;
952 -       /*
953 -        * for de-authenticate pattern, only the first byte of the frame
954 -        * control field gets changed from 0xA0 to 0xC0
955 -        */
956 -       dis_deauth_pattern[0] = 0xC0;
957 -
958 -       ath9k_hw_wow_apply_pattern(ah, dis_deauth_pattern, dis_deauth_mask,
959 -                                  pattern_count, byte_cnt);
960 -
961 -}
962 -
963 -static void ath9k_wow_add_pattern(struct ath_softc *sc,
964 -                                 struct cfg80211_wowlan *wowlan)
965 -{
966 -       struct ath_hw *ah = sc->sc_ah;
967 -       struct ath9k_wow_pattern *wow_pattern = NULL;
968 -       struct cfg80211_pkt_pattern *patterns = wowlan->patterns;
969 -       int mask_len;
970 -       s8 i = 0;
971 -
972 -       if (!wowlan->n_patterns)
973 -               return;
974 -
975 -       /*
976 -        * Add the new user configured patterns
977 -        */
978 -       for (i = 0; i < wowlan->n_patterns; i++) {
979 -
980 -               wow_pattern = kzalloc(sizeof(*wow_pattern), GFP_KERNEL);
981 -
982 -               if (!wow_pattern)
983 -                       return;
984 -
985 -               /*
986 -                * TODO: convert the generic user space pattern to
987 -                * appropriate chip specific/802.11 pattern.
988 -                */
989 -
990 -               mask_len = DIV_ROUND_UP(wowlan->patterns[i].pattern_len, 8);
991 -               memset(wow_pattern->pattern_bytes, 0, MAX_PATTERN_SIZE);
992 -               memset(wow_pattern->mask_bytes, 0, MAX_PATTERN_SIZE);
993 -               memcpy(wow_pattern->pattern_bytes, patterns[i].pattern,
994 -                      patterns[i].pattern_len);
995 -               memcpy(wow_pattern->mask_bytes, patterns[i].mask, mask_len);
996 -               wow_pattern->pattern_len = patterns[i].pattern_len;
997 -
998 -               /*
999 -                * just need to take care of deauth and disssoc pattern,
1000 -                * make sure we don't overwrite them.
1001 -                */
1002 -
1003 -               ath9k_hw_wow_apply_pattern(ah, wow_pattern->pattern_bytes,
1004 -                                          wow_pattern->mask_bytes,
1005 -                                          i + 2,
1006 -                                          wow_pattern->pattern_len);
1007 -               kfree(wow_pattern);
1008 -
1009 -       }
1010 -
1011 -}
1012 -
1013 -static int ath9k_suspend(struct ieee80211_hw *hw,
1014 -                        struct cfg80211_wowlan *wowlan)
1015 -{
1016 -       struct ath_softc *sc = hw->priv;
1017 -       struct ath_hw *ah = sc->sc_ah;
1018 -       struct ath_common *common = ath9k_hw_common(ah);
1019 -       u32 wow_triggers_enabled = 0;
1020 -       int ret = 0;
1021 -
1022 -       mutex_lock(&sc->mutex);
1023 -
1024 -       ath_cancel_work(sc);
1025 -       ath_stop_ani(sc);
1026 -       del_timer_sync(&sc->rx_poll_timer);
1027 -
1028 -       if (test_bit(SC_OP_INVALID, &sc->sc_flags)) {
1029 -               ath_dbg(common, ANY, "Device not present\n");
1030 -               ret = -EINVAL;
1031 -               goto fail_wow;
1032 -       }
1033 -
1034 -       if (WARN_ON(!wowlan)) {
1035 -               ath_dbg(common, WOW, "None of the WoW triggers enabled\n");
1036 -               ret = -EINVAL;
1037 -               goto fail_wow;
1038 -       }
1039 -
1040 -       if (!device_can_wakeup(sc->dev)) {
1041 -               ath_dbg(common, WOW, "device_can_wakeup failed, WoW is not enabled\n");
1042 -               ret = 1;
1043 -               goto fail_wow;
1044 -       }
1045 -
1046 -       /*
1047 -        * none of the sta vifs are associated
1048 -        * and we are not currently handling multivif
1049 -        * cases, for instance we have to seperately
1050 -        * configure 'keep alive frame' for each
1051 -        * STA.
1052 -        */
1053 -
1054 -       if (!test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags)) {
1055 -               ath_dbg(common, WOW, "None of the STA vifs are associated\n");
1056 -               ret = 1;
1057 -               goto fail_wow;
1058 -       }
1059 -
1060 -       if (sc->nvifs > 1) {
1061 -               ath_dbg(common, WOW, "WoW for multivif is not yet supported\n");
1062 -               ret = 1;
1063 -               goto fail_wow;
1064 -       }
1065 -
1066 -       ath9k_wow_map_triggers(sc, wowlan, &wow_triggers_enabled);
1067 -
1068 -       ath_dbg(common, WOW, "WoW triggers enabled 0x%x\n",
1069 -               wow_triggers_enabled);
1070 -
1071 -       ath9k_ps_wakeup(sc);
1072 -
1073 -       ath9k_stop_btcoex(sc);
1074 -
1075 -       /*
1076 -        * Enable wake up on recieving disassoc/deauth
1077 -        * frame by default.
1078 -        */
1079 -       ath9k_wow_add_disassoc_deauth_pattern(sc);
1080 -
1081 -       if (wow_triggers_enabled & AH_WOW_USER_PATTERN_EN)
1082 -               ath9k_wow_add_pattern(sc, wowlan);
1083 -
1084 -       spin_lock_bh(&sc->sc_pcu_lock);
1085 -       /*
1086 -        * To avoid false wake, we enable beacon miss interrupt only
1087 -        * when we go to sleep. We save the current interrupt mask
1088 -        * so we can restore it after the system wakes up
1089 -        */
1090 -       sc->wow_intr_before_sleep = ah->imask;
1091 -       ah->imask &= ~ATH9K_INT_GLOBAL;
1092 -       ath9k_hw_disable_interrupts(ah);
1093 -       ah->imask = ATH9K_INT_BMISS | ATH9K_INT_GLOBAL;
1094 -       ath9k_hw_set_interrupts(ah);
1095 -       ath9k_hw_enable_interrupts(ah);
1096 -
1097 -       spin_unlock_bh(&sc->sc_pcu_lock);
1098 -
1099 -       /*
1100 -        * we can now sync irq and kill any running tasklets, since we already
1101 -        * disabled interrupts and not holding a spin lock
1102 -        */
1103 -       synchronize_irq(sc->irq);
1104 -       tasklet_kill(&sc->intr_tq);
1105 -
1106 -       ath9k_hw_wow_enable(ah, wow_triggers_enabled);
1107 -
1108 -       ath9k_ps_restore(sc);
1109 -       ath_dbg(common, ANY, "WoW enabled in ath9k\n");
1110 -       atomic_inc(&sc->wow_sleep_proc_intr);
1111 -
1112 -fail_wow:
1113 -       mutex_unlock(&sc->mutex);
1114 -       return ret;
1115 -}
1116 -
1117 -static int ath9k_resume(struct ieee80211_hw *hw)
1118 -{
1119 -       struct ath_softc *sc = hw->priv;
1120 -       struct ath_hw *ah = sc->sc_ah;
1121 -       struct ath_common *common = ath9k_hw_common(ah);
1122 -       u32 wow_status;
1123 -
1124 -       mutex_lock(&sc->mutex);
1125 -
1126 -       ath9k_ps_wakeup(sc);
1127 -
1128 -       spin_lock_bh(&sc->sc_pcu_lock);
1129 -
1130 -       ath9k_hw_disable_interrupts(ah);
1131 -       ah->imask = sc->wow_intr_before_sleep;
1132 -       ath9k_hw_set_interrupts(ah);
1133 -       ath9k_hw_enable_interrupts(ah);
1134 -
1135 -       spin_unlock_bh(&sc->sc_pcu_lock);
1136 -
1137 -       wow_status = ath9k_hw_wow_wakeup(ah);
1138 -
1139 -       if (atomic_read(&sc->wow_got_bmiss_intr) == 0) {
1140 -               /*
1141 -                * some devices may not pick beacon miss
1142 -                * as the reason they woke up so we add
1143 -                * that here for that shortcoming.
1144 -                */
1145 -               wow_status |= AH_WOW_BEACON_MISS;
1146 -               atomic_dec(&sc->wow_got_bmiss_intr);
1147 -               ath_dbg(common, ANY, "Beacon miss interrupt picked up during WoW sleep\n");
1148 -       }
1149 -
1150 -       atomic_dec(&sc->wow_sleep_proc_intr);
1151 -
1152 -       if (wow_status) {
1153 -               ath_dbg(common, ANY, "Waking up due to WoW triggers %s with WoW status = %x\n",
1154 -                       ath9k_hw_wow_event_to_string(wow_status), wow_status);
1155 -       }
1156 -
1157 -       ath_restart_work(sc);
1158 -       ath9k_start_btcoex(sc);
1159 -
1160 -       ath9k_ps_restore(sc);
1161 -       mutex_unlock(&sc->mutex);
1162 -
1163 -       return 0;
1164 -}
1165 -
1166 -static void ath9k_set_wakeup(struct ieee80211_hw *hw, bool enabled)
1167 -{
1168 -       struct ath_softc *sc = hw->priv;
1169 -
1170 -       mutex_lock(&sc->mutex);
1171 -       device_init_wakeup(sc->dev, 1);
1172 -       device_set_wakeup_enable(sc->dev, enabled);
1173 -       mutex_unlock(&sc->mutex);
1174 -}
1175 -
1176 -#endif
1177  static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
1178  {
1179         struct ath_softc *sc = hw->priv;
1180 @@ -2373,134 +2070,6 @@ static void ath9k_channel_switch_beacon(
1181         sc->csa_vif = vif;
1182  }
1183  
1184 -static void ath9k_tx99_stop(struct ath_softc *sc)
1185 -{
1186 -       struct ath_hw *ah = sc->sc_ah;
1187 -       struct ath_common *common = ath9k_hw_common(ah);
1188 -
1189 -       ath_drain_all_txq(sc);
1190 -       ath_startrecv(sc);
1191 -
1192 -       ath9k_hw_set_interrupts(ah);
1193 -       ath9k_hw_enable_interrupts(ah);
1194 -
1195 -       ieee80211_wake_queues(sc->hw);
1196 -
1197 -       kfree_skb(sc->tx99_skb);
1198 -       sc->tx99_skb = NULL;
1199 -       sc->tx99_state = false;
1200 -
1201 -       ath9k_hw_tx99_stop(sc->sc_ah);
1202 -       ath_dbg(common, XMIT, "TX99 stopped\n");
1203 -}
1204 -
1205 -static struct sk_buff *ath9k_build_tx99_skb(struct ath_softc *sc)
1206 -{
1207 -       static u8 PN9Data[] = {0xff, 0x87, 0xb8, 0x59, 0xb7, 0xa1, 0xcc, 0x24,
1208 -                              0x57, 0x5e, 0x4b, 0x9c, 0x0e, 0xe9, 0xea, 0x50,
1209 -                              0x2a, 0xbe, 0xb4, 0x1b, 0xb6, 0xb0, 0x5d, 0xf1,
1210 -                              0xe6, 0x9a, 0xe3, 0x45, 0xfd, 0x2c, 0x53, 0x18,
1211 -                              0x0c, 0xca, 0xc9, 0xfb, 0x49, 0x37, 0xe5, 0xa8,
1212 -                              0x51, 0x3b, 0x2f, 0x61, 0xaa, 0x72, 0x18, 0x84,
1213 -                              0x02, 0x23, 0x23, 0xab, 0x63, 0x89, 0x51, 0xb3,
1214 -                              0xe7, 0x8b, 0x72, 0x90, 0x4c, 0xe8, 0xfb, 0xc0};
1215 -       u32 len = 1200;
1216 -       struct ieee80211_hw *hw = sc->hw;
1217 -       struct ieee80211_hdr *hdr;
1218 -       struct ieee80211_tx_info *tx_info;
1219 -       struct sk_buff *skb;
1220 -
1221 -       skb = alloc_skb(len, GFP_KERNEL);
1222 -       if (!skb)
1223 -               return NULL;
1224 -
1225 -       skb_put(skb, len);
1226 -
1227 -       memset(skb->data, 0, len);
1228 -
1229 -       hdr = (struct ieee80211_hdr *)skb->data;
1230 -       hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA);
1231 -       hdr->duration_id = 0;
1232 -
1233 -       memcpy(hdr->addr1, hw->wiphy->perm_addr, ETH_ALEN);
1234 -       memcpy(hdr->addr2, hw->wiphy->perm_addr, ETH_ALEN);
1235 -       memcpy(hdr->addr3, hw->wiphy->perm_addr, ETH_ALEN);
1236 -
1237 -       hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
1238 -
1239 -       tx_info = IEEE80211_SKB_CB(skb);
1240 -       memset(tx_info, 0, sizeof(*tx_info));
1241 -       tx_info->band = hw->conf.chandef.chan->band;
1242 -       tx_info->flags = IEEE80211_TX_CTL_NO_ACK;
1243 -       tx_info->control.vif = sc->tx99_vif;
1244 -
1245 -       memcpy(skb->data + sizeof(*hdr), PN9Data, sizeof(PN9Data));
1246 -
1247 -       return skb;
1248 -}
1249 -
1250 -void ath9k_tx99_deinit(struct ath_softc *sc)
1251 -{
1252 -       ath_reset(sc);
1253 -
1254 -       ath9k_ps_wakeup(sc);
1255 -       ath9k_tx99_stop(sc);
1256 -       ath9k_ps_restore(sc);
1257 -}
1258 -
1259 -int ath9k_tx99_init(struct ath_softc *sc)
1260 -{
1261 -       struct ieee80211_hw *hw = sc->hw;
1262 -       struct ath_hw *ah = sc->sc_ah;
1263 -       struct ath_common *common = ath9k_hw_common(ah);
1264 -       struct ath_tx_control txctl;
1265 -       int r;
1266 -
1267 -       if (sc->sc_flags & SC_OP_INVALID) {
1268 -               ath_err(common,
1269 -                       "driver is in invalid state unable to use TX99");
1270 -               return -EINVAL;
1271 -       }
1272 -
1273 -       sc->tx99_skb = ath9k_build_tx99_skb(sc);
1274 -       if (!sc->tx99_skb)
1275 -               return -ENOMEM;
1276 -
1277 -       memset(&txctl, 0, sizeof(txctl));
1278 -       txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO];
1279 -
1280 -       ath_reset(sc);
1281 -
1282 -       ath9k_ps_wakeup(sc);
1283 -
1284 -       ath9k_hw_disable_interrupts(ah);
1285 -       atomic_set(&ah->intr_ref_cnt, -1);
1286 -       ath_drain_all_txq(sc);
1287 -       ath_stoprecv(sc);
1288 -
1289 -       sc->tx99_state = true;
1290 -
1291 -       ieee80211_stop_queues(hw);
1292 -
1293 -       if (sc->tx99_power == MAX_RATE_POWER + 1)
1294 -               sc->tx99_power = MAX_RATE_POWER;
1295 -
1296 -       ath9k_hw_tx99_set_txpower(ah, sc->tx99_power);
1297 -       r = ath9k_tx99_send(sc, sc->tx99_skb, &txctl);
1298 -       if (r) {
1299 -               ath_dbg(common, XMIT, "Failed to xmit TX99 skb\n");
1300 -               return r;
1301 -       }
1302 -
1303 -       ath_dbg(common, XMIT, "TX99 xmit started using %d ( %ddBm)\n",
1304 -               sc->tx99_power,
1305 -               sc->tx99_power / 2);
1306 -
1307 -       /* We leave the harware awake as it will be chugging on */
1308 -
1309 -       return 0;
1310 -}
1311 -
1312  struct ieee80211_ops ath9k_ops = {
1313         .tx                 = ath9k_tx,
1314         .start              = ath9k_start,
1315 @@ -2531,7 +2100,7 @@ struct ieee80211_ops ath9k_ops = {
1316         .set_antenna        = ath9k_set_antenna,
1317         .get_antenna        = ath9k_get_antenna,
1318  
1319 -#ifdef CONFIG_PM_SLEEP
1320 +#ifdef CONFIG_ATH9K_WOW
1321         .suspend            = ath9k_suspend,
1322         .resume             = ath9k_resume,
1323         .set_wakeup         = ath9k_set_wakeup,
1324 --- a/drivers/net/wireless/ath/ath9k/wow.c
1325 +++ b/drivers/net/wireless/ath/ath9k/wow.c
1326 @@ -1,5 +1,5 @@
1327  /*
1328 - * Copyright (c) 2012 Qualcomm Atheros, Inc.
1329 + * Copyright (c) 2013 Qualcomm Atheros, Inc.
1330   *
1331   * Permission to use, copy, modify, and/or distribute this software for any
1332   * purpose with or without fee is hereby granted, provided that the above
1333 @@ -14,409 +14,348 @@
1334   * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1335   */
1336  
1337 -#include <linux/export.h>
1338  #include "ath9k.h"
1339 -#include "reg.h"
1340 -#include "hw-ops.h"
1341  
1342 -const char *ath9k_hw_wow_event_to_string(u32 wow_event)
1343 +static const struct wiphy_wowlan_support ath9k_wowlan_support = {
1344 +       .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT,
1345 +       .n_patterns = MAX_NUM_USER_PATTERN,
1346 +       .pattern_min_len = 1,
1347 +       .pattern_max_len = MAX_PATTERN_SIZE,
1348 +};
1349 +
1350 +static void ath9k_wow_map_triggers(struct ath_softc *sc,
1351 +                                  struct cfg80211_wowlan *wowlan,
1352 +                                  u32 *wow_triggers)
1353  {
1354 -       if (wow_event & AH_WOW_MAGIC_PATTERN_EN)
1355 -               return "Magic pattern";
1356 -       if (wow_event & AH_WOW_USER_PATTERN_EN)
1357 -               return "User pattern";
1358 -       if (wow_event & AH_WOW_LINK_CHANGE)
1359 -               return "Link change";
1360 -       if (wow_event & AH_WOW_BEACON_MISS)
1361 -               return "Beacon miss";
1362 +       if (wowlan->disconnect)
1363 +               *wow_triggers |= AH_WOW_LINK_CHANGE |
1364 +                                AH_WOW_BEACON_MISS;
1365 +       if (wowlan->magic_pkt)
1366 +               *wow_triggers |= AH_WOW_MAGIC_PATTERN_EN;
1367 +
1368 +       if (wowlan->n_patterns)
1369 +               *wow_triggers |= AH_WOW_USER_PATTERN_EN;
1370 +
1371 +       sc->wow_enabled = *wow_triggers;
1372  
1373 -       return  "unknown reason";
1374  }
1375 -EXPORT_SYMBOL(ath9k_hw_wow_event_to_string);
1376  
1377 -static void ath9k_hw_set_powermode_wow_sleep(struct ath_hw *ah)
1378 +static void ath9k_wow_add_disassoc_deauth_pattern(struct ath_softc *sc)
1379  {
1380 +       struct ath_hw *ah = sc->sc_ah;
1381         struct ath_common *common = ath9k_hw_common(ah);
1382 +       int pattern_count = 0;
1383 +       int i, byte_cnt;
1384 +       u8 dis_deauth_pattern[MAX_PATTERN_SIZE];
1385 +       u8 dis_deauth_mask[MAX_PATTERN_SIZE];
1386  
1387 -       REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1388 +       memset(dis_deauth_pattern, 0, MAX_PATTERN_SIZE);
1389 +       memset(dis_deauth_mask, 0, MAX_PATTERN_SIZE);
1390  
1391 -       /* set rx disable bit */
1392 -       REG_WRITE(ah, AR_CR, AR_CR_RXD);
1393 +       /*
1394 +        * Create Dissassociate / Deauthenticate packet filter
1395 +        *
1396 +        *     2 bytes        2 byte    6 bytes   6 bytes  6 bytes
1397 +        *  +--------------+----------+---------+--------+--------+----
1398 +        *  + Frame Control+ Duration +   DA    +  SA    +  BSSID +
1399 +        *  +--------------+----------+---------+--------+--------+----
1400 +        *
1401 +        * The above is the management frame format for disassociate/
1402 +        * deauthenticate pattern, from this we need to match the first byte
1403 +        * of 'Frame Control' and DA, SA, and BSSID fields
1404 +        * (skipping 2nd byte of FC and Duration feild.
1405 +        *
1406 +        * Disassociate pattern
1407 +        * --------------------
1408 +        * Frame control = 00 00 1010
1409 +        * DA, SA, BSSID = x:x:x:x:x:x
1410 +        * Pattern will be A0000000 | x:x:x:x:x:x | x:x:x:x:x:x
1411 +        *                          | x:x:x:x:x:x  -- 22 bytes
1412 +        *
1413 +        * Deauthenticate pattern
1414 +        * ----------------------
1415 +        * Frame control = 00 00 1100
1416 +        * DA, SA, BSSID = x:x:x:x:x:x
1417 +        * Pattern will be C0000000 | x:x:x:x:x:x | x:x:x:x:x:x
1418 +        *                          | x:x:x:x:x:x  -- 22 bytes
1419 +        */
1420  
1421 -       if (!ath9k_hw_wait(ah, AR_CR, AR_CR_RXE, 0, AH_WAIT_TIMEOUT)) {
1422 -               ath_err(common, "Failed to stop Rx DMA in 10ms AR_CR=0x%08x AR_DIAG_SW=0x%08x\n",
1423 -                       REG_READ(ah, AR_CR), REG_READ(ah, AR_DIAG_SW));
1424 -               return;
1425 -       }
1426 +       /* Create Disassociate Pattern first */
1427  
1428 -       REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_ON_INT);
1429 -}
1430 +       byte_cnt = 0;
1431  
1432 -static void ath9k_wow_create_keep_alive_pattern(struct ath_hw *ah)
1433 -{
1434 -       struct ath_common *common = ath9k_hw_common(ah);
1435 -       u8 sta_mac_addr[ETH_ALEN], ap_mac_addr[ETH_ALEN];
1436 -       u32 ctl[13] = {0};
1437 -       u32 data_word[KAL_NUM_DATA_WORDS];
1438 -       u8 i;
1439 -       u32 wow_ka_data_word0;
1440 -
1441 -       memcpy(sta_mac_addr, common->macaddr, ETH_ALEN);
1442 -       memcpy(ap_mac_addr, common->curbssid, ETH_ALEN);
1443 -
1444 -       /* set the transmit buffer */
1445 -       ctl[0] = (KAL_FRAME_LEN | (MAX_RATE_POWER << 16));
1446 -       ctl[1] = 0;
1447 -       ctl[3] = 0xb;   /* OFDM_6M hardware value for this rate */
1448 -       ctl[4] = 0;
1449 -       ctl[7] = (ah->txchainmask) << 2;
1450 -       ctl[2] = 0xf << 16; /* tx_tries 0 */
1451 -
1452 -       for (i = 0; i < KAL_NUM_DESC_WORDS; i++)
1453 -               REG_WRITE(ah, (AR_WOW_KA_DESC_WORD2 + i * 4), ctl[i]);
1454 -
1455 -       REG_WRITE(ah, (AR_WOW_KA_DESC_WORD2 + i * 4), ctl[i]);
1456 -
1457 -       data_word[0] = (KAL_FRAME_TYPE << 2) | (KAL_FRAME_SUB_TYPE << 4) |
1458 -                      (KAL_TO_DS << 8) | (KAL_DURATION_ID << 16);
1459 -       data_word[1] = (ap_mac_addr[3] << 24) | (ap_mac_addr[2] << 16) |
1460 -                      (ap_mac_addr[1] << 8) | (ap_mac_addr[0]);
1461 -       data_word[2] = (sta_mac_addr[1] << 24) | (sta_mac_addr[0] << 16) |
1462 -                      (ap_mac_addr[5] << 8) | (ap_mac_addr[4]);
1463 -       data_word[3] = (sta_mac_addr[5] << 24) | (sta_mac_addr[4] << 16) |
1464 -                      (sta_mac_addr[3] << 8) | (sta_mac_addr[2]);
1465 -       data_word[4] = (ap_mac_addr[3] << 24) | (ap_mac_addr[2] << 16) |
1466 -                      (ap_mac_addr[1] << 8) | (ap_mac_addr[0]);
1467 -       data_word[5] = (ap_mac_addr[5] << 8) | (ap_mac_addr[4]);
1468 -
1469 -       if (AR_SREV_9462_20(ah)) {
1470 -               /* AR9462 2.0 has an extra descriptor word (time based
1471 -                * discard) compared to other chips */
1472 -               REG_WRITE(ah, (AR_WOW_KA_DESC_WORD2 + (12 * 4)), 0);
1473 -               wow_ka_data_word0 = AR_WOW_TXBUF(13);
1474 -       } else {
1475 -               wow_ka_data_word0 = AR_WOW_TXBUF(12);
1476 -       }
1477 +       /* Fill out the mask with all FF's */
1478  
1479 -       for (i = 0; i < KAL_NUM_DATA_WORDS; i++)
1480 -               REG_WRITE(ah, (wow_ka_data_word0 + i*4), data_word[i]);
1481 +       for (i = 0; i < MAX_PATTERN_MASK_SIZE; i++)
1482 +               dis_deauth_mask[i] = 0xff;
1483  
1484 -}
1485 +       /* copy the first byte of frame control field */
1486 +       dis_deauth_pattern[byte_cnt] = 0xa0;
1487 +       byte_cnt++;
1488  
1489 -void ath9k_hw_wow_apply_pattern(struct ath_hw *ah, u8 *user_pattern,
1490 -                               u8 *user_mask, int pattern_count,
1491 -                               int pattern_len)
1492 -{
1493 -       int i;
1494 -       u32 pattern_val, mask_val;
1495 -       u32 set, clr;
1496 +       /* skip 2nd byte of frame control and Duration field */
1497 +       byte_cnt += 3;
1498  
1499 -       /* FIXME: should check count by querying the hardware capability */
1500 -       if (pattern_count >= MAX_NUM_PATTERN)
1501 -               return;
1502 +       /*
1503 +        * need not match the destination mac address, it can be a broadcast
1504 +        * mac address or an unicast to this station
1505 +        */
1506 +       byte_cnt += 6;
1507  
1508 -       REG_SET_BIT(ah, AR_WOW_PATTERN, BIT(pattern_count));
1509 +       /* copy the source mac address */
1510 +       memcpy((dis_deauth_pattern + byte_cnt), common->curbssid, ETH_ALEN);
1511  
1512 -       /* set the registers for pattern */
1513 -       for (i = 0; i < MAX_PATTERN_SIZE; i += 4) {
1514 -               memcpy(&pattern_val, user_pattern, 4);
1515 -               REG_WRITE(ah, (AR_WOW_TB_PATTERN(pattern_count) + i),
1516 -                         pattern_val);
1517 -               user_pattern += 4;
1518 -       }
1519 +       byte_cnt += 6;
1520  
1521 -       /* set the registers for mask */
1522 -       for (i = 0; i < MAX_PATTERN_MASK_SIZE; i += 4) {
1523 -               memcpy(&mask_val, user_mask, 4);
1524 -               REG_WRITE(ah, (AR_WOW_TB_MASK(pattern_count) + i), mask_val);
1525 -               user_mask += 4;
1526 -       }
1527 +       /* copy the bssid, its same as the source mac address */
1528  
1529 -       /* set the pattern length to be matched
1530 -        *
1531 -        * AR_WOW_LENGTH1_REG1
1532 -        * bit 31:24 pattern 0 length
1533 -        * bit 23:16 pattern 1 length
1534 -        * bit 15:8 pattern 2 length
1535 -        * bit 7:0 pattern 3 length
1536 -        *
1537 -        * AR_WOW_LENGTH1_REG2
1538 -        * bit 31:24 pattern 4 length
1539 -        * bit 23:16 pattern 5 length
1540 -        * bit 15:8 pattern 6 length
1541 -        * bit 7:0 pattern 7 length
1542 -        *
1543 -        * the below logic writes out the new
1544 -        * pattern length for the corresponding
1545 -        * pattern_count, while masking out the
1546 -        * other fields
1547 -        */
1548 +       memcpy((dis_deauth_pattern + byte_cnt), common->curbssid, ETH_ALEN);
1549  
1550 -       ah->wow_event_mask |= BIT(pattern_count + AR_WOW_PAT_FOUND_SHIFT);
1551 +       /* Create Disassociate pattern mask */
1552  
1553 -       if (pattern_count < 4) {
1554 -               /* Pattern 0-3 uses AR_WOW_LENGTH1 register */
1555 -               set = (pattern_len & AR_WOW_LENGTH_MAX) <<
1556 -                      AR_WOW_LEN1_SHIFT(pattern_count);
1557 -               clr = AR_WOW_LENGTH1_MASK(pattern_count);
1558 -               REG_RMW(ah, AR_WOW_LENGTH1, set, clr);
1559 -       } else {
1560 -               /* Pattern 4-7 uses AR_WOW_LENGTH2 register */
1561 -               set = (pattern_len & AR_WOW_LENGTH_MAX) <<
1562 -                      AR_WOW_LEN2_SHIFT(pattern_count);
1563 -               clr = AR_WOW_LENGTH2_MASK(pattern_count);
1564 -               REG_RMW(ah, AR_WOW_LENGTH2, set, clr);
1565 -       }
1566 +       dis_deauth_mask[0] = 0xfe;
1567 +       dis_deauth_mask[1] = 0x03;
1568 +       dis_deauth_mask[2] = 0xc0;
1569  
1570 -}
1571 -EXPORT_SYMBOL(ath9k_hw_wow_apply_pattern);
1572 +       ath_dbg(common, WOW, "Adding disassoc/deauth patterns for WoW\n");
1573  
1574 -u32 ath9k_hw_wow_wakeup(struct ath_hw *ah)
1575 -{
1576 -       u32 wow_status = 0;
1577 -       u32 val = 0, rval;
1578 +       ath9k_hw_wow_apply_pattern(ah, dis_deauth_pattern, dis_deauth_mask,
1579 +                                  pattern_count, byte_cnt);
1580  
1581 +       pattern_count++;
1582         /*
1583 -        * read the WoW status register to know
1584 -        * the wakeup reason
1585 +        * for de-authenticate pattern, only the first byte of the frame
1586 +        * control field gets changed from 0xA0 to 0xC0
1587          */
1588 -       rval = REG_READ(ah, AR_WOW_PATTERN);
1589 -       val = AR_WOW_STATUS(rval);
1590 +       dis_deauth_pattern[0] = 0xC0;
1591  
1592 -       /*
1593 -        * mask only the WoW events that we have enabled. Sometimes
1594 -        * we have spurious WoW events from the AR_WOW_PATTERN
1595 -        * register. This mask will clean it up.
1596 -        */
1597 +       ath9k_hw_wow_apply_pattern(ah, dis_deauth_pattern, dis_deauth_mask,
1598 +                                  pattern_count, byte_cnt);
1599  
1600 -       val &= ah->wow_event_mask;
1601 +}
1602  
1603 -       if (val) {
1604 -               if (val & AR_WOW_MAGIC_PAT_FOUND)
1605 -                       wow_status |= AH_WOW_MAGIC_PATTERN_EN;
1606 -               if (AR_WOW_PATTERN_FOUND(val))
1607 -                       wow_status |= AH_WOW_USER_PATTERN_EN;
1608 -               if (val & AR_WOW_KEEP_ALIVE_FAIL)
1609 -                       wow_status |= AH_WOW_LINK_CHANGE;
1610 -               if (val & AR_WOW_BEACON_FAIL)
1611 -                       wow_status |= AH_WOW_BEACON_MISS;
1612 -       }
1613 +static void ath9k_wow_add_pattern(struct ath_softc *sc,
1614 +                                 struct cfg80211_wowlan *wowlan)
1615 +{
1616 +       struct ath_hw *ah = sc->sc_ah;
1617 +       struct ath9k_wow_pattern *wow_pattern = NULL;
1618 +       struct cfg80211_pkt_pattern *patterns = wowlan->patterns;
1619 +       int mask_len;
1620 +       s8 i = 0;
1621 +
1622 +       if (!wowlan->n_patterns)
1623 +               return;
1624  
1625         /*
1626 -        * set and clear WOW_PME_CLEAR registers for the chip to
1627 -        * generate next wow signal.
1628 -        * disable D3 before accessing other registers ?
1629 +        * Add the new user configured patterns
1630          */
1631 +       for (i = 0; i < wowlan->n_patterns; i++) {
1632  
1633 -       /* do we need to check the bit value 0x01000000 (7-10) ?? */
1634 -       REG_RMW(ah, AR_PCIE_PM_CTRL, AR_PMCTRL_WOW_PME_CLR,
1635 -               AR_PMCTRL_PWR_STATE_D1D3);
1636 +               wow_pattern = kzalloc(sizeof(*wow_pattern), GFP_KERNEL);
1637  
1638 -       /*
1639 -        * clear all events
1640 -        */
1641 -       REG_WRITE(ah, AR_WOW_PATTERN,
1642 -                 AR_WOW_CLEAR_EVENTS(REG_READ(ah, AR_WOW_PATTERN)));
1643 +               if (!wow_pattern)
1644 +                       return;
1645  
1646 -       /*
1647 -        * restore the beacon threshold to init value
1648 -        */
1649 -       REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
1650 +               /*
1651 +                * TODO: convert the generic user space pattern to
1652 +                * appropriate chip specific/802.11 pattern.
1653 +                */
1654  
1655 -       /*
1656 -        * Restore the way the PCI-E reset, Power-On-Reset, external
1657 -        * PCIE_POR_SHORT pins are tied to its original value.
1658 -        * Previously just before WoW sleep, we untie the PCI-E
1659 -        * reset to our Chip's Power On Reset so that any PCI-E
1660 -        * reset from the bus will not reset our chip
1661 -        */
1662 -       if (ah->is_pciexpress)
1663 -               ath9k_hw_configpcipowersave(ah, false);
1664 +               mask_len = DIV_ROUND_UP(wowlan->patterns[i].pattern_len, 8);
1665 +               memset(wow_pattern->pattern_bytes, 0, MAX_PATTERN_SIZE);
1666 +               memset(wow_pattern->mask_bytes, 0, MAX_PATTERN_SIZE);
1667 +               memcpy(wow_pattern->pattern_bytes, patterns[i].pattern,
1668 +                      patterns[i].pattern_len);
1669 +               memcpy(wow_pattern->mask_bytes, patterns[i].mask, mask_len);
1670 +               wow_pattern->pattern_len = patterns[i].pattern_len;
1671 +
1672 +               /*
1673 +                * just need to take care of deauth and disssoc pattern,
1674 +                * make sure we don't overwrite them.
1675 +                */
1676 +
1677 +               ath9k_hw_wow_apply_pattern(ah, wow_pattern->pattern_bytes,
1678 +                                          wow_pattern->mask_bytes,
1679 +                                          i + 2,
1680 +                                          wow_pattern->pattern_len);
1681 +               kfree(wow_pattern);
1682  
1683 -       ah->wow_event_mask = 0;
1684 +       }
1685  
1686 -       return wow_status;
1687  }
1688 -EXPORT_SYMBOL(ath9k_hw_wow_wakeup);
1689  
1690 -void ath9k_hw_wow_enable(struct ath_hw *ah, u32 pattern_enable)
1691 +int ath9k_suspend(struct ieee80211_hw *hw,
1692 +                 struct cfg80211_wowlan *wowlan)
1693  {
1694 -       u32 wow_event_mask;
1695 -       u32 set, clr;
1696 +       struct ath_softc *sc = hw->priv;
1697 +       struct ath_hw *ah = sc->sc_ah;
1698 +       struct ath_common *common = ath9k_hw_common(ah);
1699 +       u32 wow_triggers_enabled = 0;
1700 +       int ret = 0;
1701  
1702 -       /*
1703 -        * wow_event_mask is a mask to the AR_WOW_PATTERN register to
1704 -        * indicate which WoW events we have enabled. The WoW events
1705 -        * are from the 'pattern_enable' in this function and
1706 -        * 'pattern_count' of ath9k_hw_wow_apply_pattern()
1707 -        */
1708 -       wow_event_mask = ah->wow_event_mask;
1709 +       mutex_lock(&sc->mutex);
1710  
1711 -       /*
1712 -        * Untie Power-on-Reset from the PCI-E-Reset. When we are in
1713 -        * WOW sleep, we do want the Reset from the PCI-E to disturb
1714 -        * our hw state
1715 -        */
1716 -       if (ah->is_pciexpress) {
1717 -               /*
1718 -                * we need to untie the internal POR (power-on-reset)
1719 -                * to the external PCI-E reset. We also need to tie
1720 -                * the PCI-E Phy reset to the PCI-E reset.
1721 -                */
1722 -               set = AR_WA_RESET_EN | AR_WA_POR_SHORT;
1723 -               clr = AR_WA_UNTIE_RESET_EN | AR_WA_D3_L1_DISABLE;
1724 -               REG_RMW(ah, AR_WA, set, clr);
1725 +       ath_cancel_work(sc);
1726 +       ath_stop_ani(sc);
1727 +       del_timer_sync(&sc->rx_poll_timer);
1728 +
1729 +       if (test_bit(SC_OP_INVALID, &sc->sc_flags)) {
1730 +               ath_dbg(common, ANY, "Device not present\n");
1731 +               ret = -EINVAL;
1732 +               goto fail_wow;
1733         }
1734  
1735 -       /*
1736 -        * set the power states appropriately and enable PME
1737 -        */
1738 -       set = AR_PMCTRL_HOST_PME_EN | AR_PMCTRL_PWR_PM_CTRL_ENA |
1739 -             AR_PMCTRL_AUX_PWR_DET | AR_PMCTRL_WOW_PME_CLR;
1740 +       if (WARN_ON(!wowlan)) {
1741 +               ath_dbg(common, WOW, "None of the WoW triggers enabled\n");
1742 +               ret = -EINVAL;
1743 +               goto fail_wow;
1744 +       }
1745  
1746 -       /*
1747 -        * set and clear WOW_PME_CLEAR registers for the chip
1748 -        * to generate next wow signal.
1749 -        */
1750 -       REG_SET_BIT(ah, AR_PCIE_PM_CTRL, set);
1751 -       clr = AR_PMCTRL_WOW_PME_CLR;
1752 -       REG_CLR_BIT(ah, AR_PCIE_PM_CTRL, clr);
1753 +       if (!device_can_wakeup(sc->dev)) {
1754 +               ath_dbg(common, WOW, "device_can_wakeup failed, WoW is not enabled\n");
1755 +               ret = 1;
1756 +               goto fail_wow;
1757 +       }
1758  
1759         /*
1760 -        * Setup for:
1761 -        *      - beacon misses
1762 -        *      - magic pattern
1763 -        *      - keep alive timeout
1764 -        *      - pattern matching
1765 +        * none of the sta vifs are associated
1766 +        * and we are not currently handling multivif
1767 +        * cases, for instance we have to seperately
1768 +        * configure 'keep alive frame' for each
1769 +        * STA.
1770          */
1771  
1772 -       /*
1773 -        * Program default values for pattern backoff, aifs/slot/KAL count,
1774 -        * beacon miss timeout, KAL timeout, etc.
1775 -        */
1776 -       set = AR_WOW_BACK_OFF_SHIFT(AR_WOW_PAT_BACKOFF);
1777 -       REG_SET_BIT(ah, AR_WOW_PATTERN, set);
1778 +       if (!test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags)) {
1779 +               ath_dbg(common, WOW, "None of the STA vifs are associated\n");
1780 +               ret = 1;
1781 +               goto fail_wow;
1782 +       }
1783 +
1784 +       if (sc->nvifs > 1) {
1785 +               ath_dbg(common, WOW, "WoW for multivif is not yet supported\n");
1786 +               ret = 1;
1787 +               goto fail_wow;
1788 +       }
1789  
1790 -       set = AR_WOW_AIFS_CNT(AR_WOW_CNT_AIFS_CNT) |
1791 -             AR_WOW_SLOT_CNT(AR_WOW_CNT_SLOT_CNT) |
1792 -             AR_WOW_KEEP_ALIVE_CNT(AR_WOW_CNT_KA_CNT);
1793 -       REG_SET_BIT(ah, AR_WOW_COUNT, set);
1794 -
1795 -       if (pattern_enable & AH_WOW_BEACON_MISS)
1796 -               set = AR_WOW_BEACON_TIMO;
1797 -       /* We are not using beacon miss, program a large value */
1798 -       else
1799 -               set = AR_WOW_BEACON_TIMO_MAX;
1800 +       ath9k_wow_map_triggers(sc, wowlan, &wow_triggers_enabled);
1801  
1802 -       REG_WRITE(ah, AR_WOW_BCN_TIMO, set);
1803 +       ath_dbg(common, WOW, "WoW triggers enabled 0x%x\n",
1804 +               wow_triggers_enabled);
1805  
1806 -       /*
1807 -        * Keep alive timo in ms except AR9280
1808 -        */
1809 -       if (!pattern_enable)
1810 -               set = AR_WOW_KEEP_ALIVE_NEVER;
1811 -       else
1812 -               set = KAL_TIMEOUT * 32;
1813 +       ath9k_ps_wakeup(sc);
1814  
1815 -       REG_WRITE(ah, AR_WOW_KEEP_ALIVE_TIMO, set);
1816 +       ath9k_stop_btcoex(sc);
1817  
1818         /*
1819 -        * Keep alive delay in us. based on 'power on clock',
1820 -        * therefore in usec
1821 +        * Enable wake up on recieving disassoc/deauth
1822 +        * frame by default.
1823          */
1824 -       set = KAL_DELAY * 1000;
1825 -       REG_WRITE(ah, AR_WOW_KEEP_ALIVE_DELAY, set);
1826 +       ath9k_wow_add_disassoc_deauth_pattern(sc);
1827  
1828 -       /*
1829 -        * Create keep alive pattern to respond to beacons
1830 -        */
1831 -       ath9k_wow_create_keep_alive_pattern(ah);
1832 +       if (wow_triggers_enabled & AH_WOW_USER_PATTERN_EN)
1833 +               ath9k_wow_add_pattern(sc, wowlan);
1834  
1835 +       spin_lock_bh(&sc->sc_pcu_lock);
1836         /*
1837 -        * Configure MAC WoW Registers
1838 +        * To avoid false wake, we enable beacon miss interrupt only
1839 +        * when we go to sleep. We save the current interrupt mask
1840 +        * so we can restore it after the system wakes up
1841          */
1842 -       set = 0;
1843 -       /* Send keep alive timeouts anyway */
1844 -       clr = AR_WOW_KEEP_ALIVE_AUTO_DIS;
1845 -
1846 -       if (pattern_enable & AH_WOW_LINK_CHANGE)
1847 -               wow_event_mask |= AR_WOW_KEEP_ALIVE_FAIL;
1848 -       else
1849 -               set = AR_WOW_KEEP_ALIVE_FAIL_DIS;
1850 +       sc->wow_intr_before_sleep = ah->imask;
1851 +       ah->imask &= ~ATH9K_INT_GLOBAL;
1852 +       ath9k_hw_disable_interrupts(ah);
1853 +       ah->imask = ATH9K_INT_BMISS | ATH9K_INT_GLOBAL;
1854 +       ath9k_hw_set_interrupts(ah);
1855 +       ath9k_hw_enable_interrupts(ah);
1856  
1857 -       set = AR_WOW_KEEP_ALIVE_FAIL_DIS;
1858 -       REG_RMW(ah, AR_WOW_KEEP_ALIVE, set, clr);
1859 +       spin_unlock_bh(&sc->sc_pcu_lock);
1860  
1861         /*
1862 -        * we are relying on a bmiss failure. ensure we have
1863 -        * enough threshold to prevent false positives
1864 +        * we can now sync irq and kill any running tasklets, since we already
1865 +        * disabled interrupts and not holding a spin lock
1866          */
1867 -       REG_RMW_FIELD(ah, AR_RSSI_THR, AR_RSSI_THR_BM_THR,
1868 -                     AR_WOW_BMISSTHRESHOLD);
1869 +       synchronize_irq(sc->irq);
1870 +       tasklet_kill(&sc->intr_tq);
1871 +
1872 +       ath9k_hw_wow_enable(ah, wow_triggers_enabled);
1873  
1874 -       set = 0;
1875 -       clr = 0;
1876 +       ath9k_ps_restore(sc);
1877 +       ath_dbg(common, ANY, "WoW enabled in ath9k\n");
1878 +       atomic_inc(&sc->wow_sleep_proc_intr);
1879  
1880 -       if (pattern_enable & AH_WOW_BEACON_MISS) {
1881 -               set = AR_WOW_BEACON_FAIL_EN;
1882 -               wow_event_mask |= AR_WOW_BEACON_FAIL;
1883 -       } else {
1884 -               clr = AR_WOW_BEACON_FAIL_EN;
1885 +fail_wow:
1886 +       mutex_unlock(&sc->mutex);
1887 +       return ret;
1888 +}
1889 +
1890 +int ath9k_resume(struct ieee80211_hw *hw)
1891 +{
1892 +       struct ath_softc *sc = hw->priv;
1893 +       struct ath_hw *ah = sc->sc_ah;
1894 +       struct ath_common *common = ath9k_hw_common(ah);
1895 +       u32 wow_status;
1896 +
1897 +       mutex_lock(&sc->mutex);
1898 +
1899 +       ath9k_ps_wakeup(sc);
1900 +
1901 +       spin_lock_bh(&sc->sc_pcu_lock);
1902 +
1903 +       ath9k_hw_disable_interrupts(ah);
1904 +       ah->imask = sc->wow_intr_before_sleep;
1905 +       ath9k_hw_set_interrupts(ah);
1906 +       ath9k_hw_enable_interrupts(ah);
1907 +
1908 +       spin_unlock_bh(&sc->sc_pcu_lock);
1909 +
1910 +       wow_status = ath9k_hw_wow_wakeup(ah);
1911 +
1912 +       if (atomic_read(&sc->wow_got_bmiss_intr) == 0) {
1913 +               /*
1914 +                * some devices may not pick beacon miss
1915 +                * as the reason they woke up so we add
1916 +                * that here for that shortcoming.
1917 +                */
1918 +               wow_status |= AH_WOW_BEACON_MISS;
1919 +               atomic_dec(&sc->wow_got_bmiss_intr);
1920 +               ath_dbg(common, ANY, "Beacon miss interrupt picked up during WoW sleep\n");
1921         }
1922  
1923 -       REG_RMW(ah, AR_WOW_BCN_EN, set, clr);
1924 +       atomic_dec(&sc->wow_sleep_proc_intr);
1925  
1926 -       set = 0;
1927 -       clr = 0;
1928 -       /*
1929 -        * Enable the magic packet registers
1930 -        */
1931 -       if (pattern_enable & AH_WOW_MAGIC_PATTERN_EN) {
1932 -               set = AR_WOW_MAGIC_EN;
1933 -               wow_event_mask |= AR_WOW_MAGIC_PAT_FOUND;
1934 -       } else {
1935 -               clr = AR_WOW_MAGIC_EN;
1936 +       if (wow_status) {
1937 +               ath_dbg(common, ANY, "Waking up due to WoW triggers %s with WoW status = %x\n",
1938 +                       ath9k_hw_wow_event_to_string(wow_status), wow_status);
1939         }
1940 -       set |= AR_WOW_MAC_INTR_EN;
1941 -       REG_RMW(ah, AR_WOW_PATTERN, set, clr);
1942  
1943 -       REG_WRITE(ah, AR_WOW_PATTERN_MATCH_LT_256B,
1944 -                 AR_WOW_PATTERN_SUPPORTED);
1945 +       ath_restart_work(sc);
1946 +       ath9k_start_btcoex(sc);
1947  
1948 -       /*
1949 -        * Set the power states appropriately and enable PME
1950 -        */
1951 -       clr = 0;
1952 -       set = AR_PMCTRL_PWR_STATE_D1D3 | AR_PMCTRL_HOST_PME_EN |
1953 -             AR_PMCTRL_PWR_PM_CTRL_ENA;
1954 +       ath9k_ps_restore(sc);
1955 +       mutex_unlock(&sc->mutex);
1956  
1957 -       clr = AR_PCIE_PM_CTRL_ENA;
1958 -       REG_RMW(ah, AR_PCIE_PM_CTRL, set, clr);
1959 +       return 0;
1960 +}
1961  
1962 -       /*
1963 -        * this is needed to prevent the chip waking up
1964 -        * the host within 3-4 seconds with certain
1965 -        * platform/BIOS. The fix is to enable
1966 -        * D1 & D3 to match original definition and
1967 -        * also match the OTP value. Anyway this
1968 -        * is more related to SW WOW.
1969 -        */
1970 -       clr = AR_PMCTRL_PWR_STATE_D1D3;
1971 -       REG_CLR_BIT(ah, AR_PCIE_PM_CTRL, clr);
1972 +void ath9k_set_wakeup(struct ieee80211_hw *hw, bool enabled)
1973 +{
1974 +       struct ath_softc *sc = hw->priv;
1975  
1976 -       set = AR_PMCTRL_PWR_STATE_D1D3_REAL;
1977 -       REG_SET_BIT(ah, AR_PCIE_PM_CTRL, set);
1978 +       mutex_lock(&sc->mutex);
1979 +       device_init_wakeup(sc->dev, 1);
1980 +       device_set_wakeup_enable(sc->dev, enabled);
1981 +       mutex_unlock(&sc->mutex);
1982 +}
1983  
1984 -       REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PRESERVE_SEQNUM);
1985 +void ath9k_init_wow(struct ieee80211_hw *hw)
1986 +{
1987 +       struct ath_softc *sc = hw->priv;
1988  
1989 -       /* to bring down WOW power low margin */
1990 -       set = BIT(13);
1991 -       REG_SET_BIT(ah, AR_PCIE_PHY_REG3, set);
1992 -       /* HW WoW */
1993 -       clr = BIT(5);
1994 -       REG_CLR_BIT(ah, AR_PCU_MISC_MODE3, clr);
1995 +       if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_WOW_DEVICE_CAPABLE) &&
1996 +           (sc->driver_data & ATH9K_PCI_WOW) &&
1997 +           device_can_wakeup(sc->dev))
1998 +               hw->wiphy->wowlan = &ath9k_wowlan_support;
1999  
2000 -       ath9k_hw_set_powermode_wow_sleep(ah);
2001 -       ah->wow_event_mask = wow_event_mask;
2002 +       atomic_set(&sc->wow_sleep_proc_intr, -1);
2003 +       atomic_set(&sc->wow_got_bmiss_intr, -1);
2004  }
2005 -EXPORT_SYMBOL(ath9k_hw_wow_enable);
2006 --- a/drivers/net/wireless/ath/ath9k/xmit.c
2007 +++ b/drivers/net/wireless/ath/ath9k/xmit.c
2008 @@ -1786,6 +1786,9 @@ bool ath_drain_all_txq(struct ath_softc 
2009                 if (!ATH_TXQ_SETUP(sc, i))
2010                         continue;
2011  
2012 +               if (!sc->tx.txq[i].axq_depth)
2013 +                       continue;
2014 +
2015                 if (ath9k_hw_numtxpending(ah, sc->tx.txq[i].axq_qnum))
2016                         npend |= BIT(i);
2017         }
2018 @@ -2749,6 +2752,8 @@ void ath_tx_node_cleanup(struct ath_soft
2019         }
2020  }
2021  
2022 +#ifdef CONFIG_ATH9K_TX99
2023 +
2024  int ath9k_tx99_send(struct ath_softc *sc, struct sk_buff *skb,
2025                     struct ath_tx_control *txctl)
2026  {
2027 @@ -2791,3 +2796,5 @@ int ath9k_tx99_send(struct ath_softc *sc
2028  
2029         return 0;
2030  }
2031 +
2032 +#endif /* CONFIG_ATH9K_TX99 */
2033 --- a/drivers/net/wireless/ath/regd.c
2034 +++ b/drivers/net/wireless/ath/regd.c
2035 @@ -37,17 +37,17 @@ static int __ath_regd_init(struct ath_re
2036  
2037  /* We enable active scan on these a case by case basis by regulatory domain */
2038  #define ATH9K_2GHZ_CH12_13     REG_RULE(2467-10, 2472+10, 40, 0, 20,\
2039 -                                       NL80211_RRF_PASSIVE_SCAN)
2040 +                                       NL80211_RRF_NO_IR)
2041  #define ATH9K_2GHZ_CH14                REG_RULE(2484-10, 2484+10, 40, 0, 20,\
2042 -                               NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_OFDM)
2043 +                               NL80211_RRF_NO_IR | NL80211_RRF_NO_OFDM)
2044  
2045  /* We allow IBSS on these on a case by case basis by regulatory domain */
2046  #define ATH9K_5GHZ_5150_5350   REG_RULE(5150-10, 5350+10, 80, 0, 30,\
2047 -                               NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
2048 +                               NL80211_RRF_NO_IR)
2049  #define ATH9K_5GHZ_5470_5850   REG_RULE(5470-10, 5850+10, 80, 0, 30,\
2050 -                               NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
2051 +                               NL80211_RRF_NO_IR)
2052  #define ATH9K_5GHZ_5725_5850   REG_RULE(5725-10, 5850+10, 80, 0, 30,\
2053 -                               NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
2054 +                               NL80211_RRF_NO_IR)
2055  
2056  #define ATH9K_2GHZ_ALL         ATH9K_2GHZ_CH01_11, \
2057                                 ATH9K_2GHZ_CH12_13, \
2058 @@ -224,17 +224,16 @@ ath_reg_apply_beaconing_flags(struct wip
2059                                  * regulatory_hint().
2060                                  */
2061                                 if (!(reg_rule->flags &
2062 -                                   NL80211_RRF_NO_IBSS))
2063 +                                   NL80211_RRF_NO_IR))
2064                                         ch->flags &=
2065 -                                         ~IEEE80211_CHAN_NO_IBSS;
2066 +                                         ~IEEE80211_CHAN_NO_IR;
2067                                 if (!(reg_rule->flags &
2068 -                                   NL80211_RRF_PASSIVE_SCAN))
2069 +                                   NL80211_RRF_NO_IR))
2070                                         ch->flags &=
2071 -                                         ~IEEE80211_CHAN_PASSIVE_SCAN;
2072 +                                         ~IEEE80211_CHAN_NO_IR;
2073                         } else {
2074                                 if (ch->beacon_found)
2075 -                                       ch->flags &= ~(IEEE80211_CHAN_NO_IBSS |
2076 -                                         IEEE80211_CHAN_PASSIVE_SCAN);
2077 +                                       ch->flags &= ~IEEE80211_CHAN_NO_IR;
2078                         }
2079                 }
2080         }
2081 @@ -260,11 +259,11 @@ ath_reg_apply_active_scan_flags(struct w
2082          */
2083         if (initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) {
2084                 ch = &sband->channels[11]; /* CH 12 */
2085 -               if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
2086 -                       ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
2087 +               if (ch->flags & IEEE80211_CHAN_NO_IR)
2088 +                       ch->flags &= ~IEEE80211_CHAN_NO_IR;
2089                 ch = &sband->channels[12]; /* CH 13 */
2090 -               if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
2091 -                       ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
2092 +               if (ch->flags & IEEE80211_CHAN_NO_IR)
2093 +                       ch->flags &= ~IEEE80211_CHAN_NO_IR;
2094                 return;
2095         }
2096  
2097 @@ -278,17 +277,17 @@ ath_reg_apply_active_scan_flags(struct w
2098         ch = &sband->channels[11]; /* CH 12 */
2099         reg_rule = freq_reg_info(wiphy, ch->center_freq);
2100         if (!IS_ERR(reg_rule)) {
2101 -               if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN))
2102 -                       if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
2103 -                               ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
2104 +               if (!(reg_rule->flags & NL80211_RRF_NO_IR))
2105 +                       if (ch->flags & IEEE80211_CHAN_NO_IR)
2106 +                               ch->flags &= ~IEEE80211_CHAN_NO_IR;
2107         }
2108  
2109         ch = &sband->channels[12]; /* CH 13 */
2110         reg_rule = freq_reg_info(wiphy, ch->center_freq);
2111         if (!IS_ERR(reg_rule)) {
2112 -               if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN))
2113 -                       if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
2114 -                               ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
2115 +               if (!(reg_rule->flags & NL80211_RRF_NO_IR))
2116 +                       if (ch->flags & IEEE80211_CHAN_NO_IR)
2117 +                               ch->flags &= ~IEEE80211_CHAN_NO_IR;
2118         }
2119  }
2120  
2121 @@ -320,8 +319,8 @@ static void ath_reg_apply_radar_flags(st
2122                  */
2123                 if (!(ch->flags & IEEE80211_CHAN_DISABLED))
2124                         ch->flags |= IEEE80211_CHAN_RADAR |
2125 -                                    IEEE80211_CHAN_NO_IBSS |
2126 -                                    IEEE80211_CHAN_PASSIVE_SCAN;
2127 +                                    IEEE80211_CHAN_NO_IR |
2128 +                                    IEEE80211_CHAN_NO_IR;
2129         }
2130  }
2131  
2132 --- a/drivers/net/wireless/brcm80211/brcmfmac/p2p.c
2133 +++ b/drivers/net/wireless/brcm80211/brcmfmac/p2p.c
2134 @@ -812,7 +812,7 @@ static s32 brcmf_p2p_run_escan(struct br
2135                         struct ieee80211_channel *chan = request->channels[i];
2136  
2137                         if (chan->flags & (IEEE80211_CHAN_RADAR |
2138 -                                          IEEE80211_CHAN_PASSIVE_SCAN))
2139 +                                          IEEE80211_CHAN_NO_IR))
2140                                 continue;
2141  
2142                         chanspecs[i] = channel_to_chanspec(&p2p->cfg->d11inf,
2143 --- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
2144 +++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
2145 @@ -202,9 +202,9 @@ static struct ieee80211_supported_band _
2146  
2147  /* This is to override regulatory domains defined in cfg80211 module (reg.c)
2148   * By default world regulatory domain defined in reg.c puts the flags
2149 - * NL80211_RRF_PASSIVE_SCAN and NL80211_RRF_NO_IBSS for 5GHz channels (for
2150 - * 36..48 and 149..165). With respect to these flags, wpa_supplicant doesn't
2151 - * start p2p operations on 5GHz channels. All the changes in world regulatory
2152 + * NL80211_RRF_NO_IR for 5GHz channels (for * 36..48 and 149..165).
2153 + * With respect to these flags, wpa_supplicant doesn't * start p2p
2154 + * operations on 5GHz channels. All the changes in world regulatory
2155   * domain are to be done here.
2156   */
2157  static const struct ieee80211_regdomain brcmf_regdom = {
2158 @@ -5197,10 +5197,10 @@ static s32 brcmf_construct_reginfo(struc
2159                                         if (channel & WL_CHAN_RADAR)
2160                                                 band_chan_arr[index].flags |=
2161                                                         (IEEE80211_CHAN_RADAR |
2162 -                                                       IEEE80211_CHAN_NO_IBSS);
2163 +                                                       IEEE80211_CHAN_NO_IR);
2164                                         if (channel & WL_CHAN_PASSIVE)
2165                                                 band_chan_arr[index].flags |=
2166 -                                                   IEEE80211_CHAN_PASSIVE_SCAN;
2167 +                                                   IEEE80211_CHAN_NO_IR;
2168                                 }
2169                         }
2170                         if (!update)
2171 --- a/drivers/net/wireless/brcm80211/brcmsmac/channel.c
2172 +++ b/drivers/net/wireless/brcm80211/brcmsmac/channel.c
2173 @@ -59,23 +59,20 @@
2174  
2175  #define BRCM_2GHZ_2412_2462    REG_RULE(2412-10, 2462+10, 40, 0, 19, 0)
2176  #define BRCM_2GHZ_2467_2472    REG_RULE(2467-10, 2472+10, 20, 0, 19, \
2177 -                                        NL80211_RRF_PASSIVE_SCAN | \
2178 -                                        NL80211_RRF_NO_IBSS)
2179 +                                        NL80211_RRF_NO_IR)
2180  
2181  #define BRCM_5GHZ_5180_5240    REG_RULE(5180-10, 5240+10, 40, 0, 21, \
2182 -                                        NL80211_RRF_PASSIVE_SCAN | \
2183 -                                        NL80211_RRF_NO_IBSS)
2184 +                                        NL80211_RRF_NO_IR)
2185  #define BRCM_5GHZ_5260_5320    REG_RULE(5260-10, 5320+10, 40, 0, 21, \
2186 -                                        NL80211_RRF_PASSIVE_SCAN | \
2187 +                                        NL80211_RRF_NO_IR | \
2188                                          NL80211_RRF_DFS | \
2189 -                                        NL80211_RRF_NO_IBSS)
2190 +                                        NL80211_RRF_NO_IR)
2191  #define BRCM_5GHZ_5500_5700    REG_RULE(5500-10, 5700+10, 40, 0, 21, \
2192 -                                        NL80211_RRF_PASSIVE_SCAN | \
2193 +                                        NL80211_RRF_NO_IR | \
2194                                          NL80211_RRF_DFS | \
2195 -                                        NL80211_RRF_NO_IBSS)
2196 +                                        NL80211_RRF_NO_IR)
2197  #define BRCM_5GHZ_5745_5825    REG_RULE(5745-10, 5825+10, 40, 0, 21, \
2198 -                                        NL80211_RRF_PASSIVE_SCAN | \
2199 -                                        NL80211_RRF_NO_IBSS)
2200 +                                        NL80211_RRF_NO_IR)
2201  
2202  static const struct ieee80211_regdomain brcms_regdom_x2 = {
2203         .n_reg_rules = 6,
2204 @@ -395,7 +392,7 @@ brcms_c_channel_set_chanspec(struct brcm
2205                 brcms_c_set_gmode(wlc, wlc->protection->gmode_user, false);
2206  
2207         brcms_b_set_chanspec(wlc->hw, chanspec,
2208 -                             !!(ch->flags & IEEE80211_CHAN_PASSIVE_SCAN),
2209 +                             !!(ch->flags & IEEE80211_CHAN_NO_IR),
2210                               &txpwr);
2211  }
2212  
2213 @@ -657,8 +654,8 @@ static void brcms_reg_apply_radar_flags(
2214                  */
2215                 if (!(ch->flags & IEEE80211_CHAN_DISABLED))
2216                         ch->flags |= IEEE80211_CHAN_RADAR |
2217 -                                    IEEE80211_CHAN_NO_IBSS |
2218 -                                    IEEE80211_CHAN_PASSIVE_SCAN;
2219 +                                    IEEE80211_CHAN_NO_IR |
2220 +                                    IEEE80211_CHAN_NO_IR;
2221         }
2222  }
2223  
2224 @@ -688,14 +685,13 @@ brcms_reg_apply_beaconing_flags(struct w
2225                                 if (IS_ERR(rule))
2226                                         continue;
2227  
2228 -                               if (!(rule->flags & NL80211_RRF_NO_IBSS))
2229 -                                       ch->flags &= ~IEEE80211_CHAN_NO_IBSS;
2230 -                               if (!(rule->flags & NL80211_RRF_PASSIVE_SCAN))
2231 +                               if (!(rule->flags & NL80211_RRF_NO_IR))
2232 +                                       ch->flags &= ~IEEE80211_CHAN_NO_IR;
2233 +                               if (!(rule->flags & NL80211_RRF_NO_IR))
2234                                         ch->flags &=
2235 -                                               ~IEEE80211_CHAN_PASSIVE_SCAN;
2236 +                                               ~IEEE80211_CHAN_NO_IR;
2237                         } else if (ch->beacon_found) {
2238 -                               ch->flags &= ~(IEEE80211_CHAN_NO_IBSS |
2239 -                                              IEEE80211_CHAN_PASSIVE_SCAN);
2240 +                               ch->flags &= ~IEEE80211_CHAN_NO_IR;
2241                         }
2242                 }
2243         }
2244 --- a/drivers/net/wireless/brcm80211/brcmsmac/mac80211_if.c
2245 +++ b/drivers/net/wireless/brcm80211/brcmsmac/mac80211_if.c
2246 @@ -125,13 +125,13 @@ static struct ieee80211_channel brcms_2g
2247         CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
2248         CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
2249         CHAN2GHZ(12, 2467,
2250 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
2251 +                IEEE80211_CHAN_NO_IR |
2252                  IEEE80211_CHAN_NO_HT40PLUS),
2253         CHAN2GHZ(13, 2472,
2254 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
2255 +                IEEE80211_CHAN_NO_IR |
2256                  IEEE80211_CHAN_NO_HT40PLUS),
2257         CHAN2GHZ(14, 2484,
2258 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
2259 +                IEEE80211_CHAN_NO_IR |
2260                  IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS |
2261                  IEEE80211_CHAN_NO_OFDM)
2262  };
2263 @@ -144,51 +144,51 @@ static struct ieee80211_channel brcms_5g
2264         CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
2265         /* UNII-2 */
2266         CHAN5GHZ(52,
2267 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2268 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
2269 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2270 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40MINUS),
2271         CHAN5GHZ(56,
2272 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2273 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
2274 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2275 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40PLUS),
2276         CHAN5GHZ(60,
2277 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2278 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
2279 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2280 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40MINUS),
2281         CHAN5GHZ(64,
2282 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2283 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
2284 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2285 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40PLUS),
2286         /* MID */
2287         CHAN5GHZ(100,
2288 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2289 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
2290 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2291 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40MINUS),
2292         CHAN5GHZ(104,
2293 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2294 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
2295 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2296 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40PLUS),
2297         CHAN5GHZ(108,
2298 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2299 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
2300 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2301 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40MINUS),
2302         CHAN5GHZ(112,
2303 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2304 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
2305 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2306 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40PLUS),
2307         CHAN5GHZ(116,
2308 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2309 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
2310 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2311 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40MINUS),
2312         CHAN5GHZ(120,
2313 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2314 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
2315 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2316 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40PLUS),
2317         CHAN5GHZ(124,
2318 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2319 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
2320 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2321 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40MINUS),
2322         CHAN5GHZ(128,
2323 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2324 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
2325 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2326 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40PLUS),
2327         CHAN5GHZ(132,
2328 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2329 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
2330 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2331 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40MINUS),
2332         CHAN5GHZ(136,
2333 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2334 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
2335 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2336 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40PLUS),
2337         CHAN5GHZ(140,
2338 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2339 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
2340 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2341 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40PLUS |
2342                  IEEE80211_CHAN_NO_HT40MINUS),
2343         /* UNII-3 */
2344         CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
2345 --- a/drivers/net/wireless/cw1200/scan.c
2346 +++ b/drivers/net/wireless/cw1200/scan.c
2347 @@ -197,9 +197,9 @@ void cw1200_scan_work(struct work_struct
2348                         if ((*it)->band != first->band)
2349                                 break;
2350                         if (((*it)->flags ^ first->flags) &
2351 -                                       IEEE80211_CHAN_PASSIVE_SCAN)
2352 +                                       IEEE80211_CHAN_NO_IR)
2353                                 break;
2354 -                       if (!(first->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
2355 +                       if (!(first->flags & IEEE80211_CHAN_NO_IR) &&
2356                             (*it)->max_power != first->max_power)
2357                                 break;
2358                 }
2359 @@ -210,7 +210,7 @@ void cw1200_scan_work(struct work_struct
2360                 else
2361                         scan.max_tx_rate = WSM_TRANSMIT_RATE_1;
2362                 scan.num_probes =
2363 -                       (first->flags & IEEE80211_CHAN_PASSIVE_SCAN) ? 0 : 2;
2364 +                       (first->flags & IEEE80211_CHAN_NO_IR) ? 0 : 2;
2365                 scan.num_ssids = priv->scan.n_ssids;
2366                 scan.ssids = &priv->scan.ssids[0];
2367                 scan.num_channels = it - priv->scan.curr;
2368 @@ -233,7 +233,7 @@ void cw1200_scan_work(struct work_struct
2369                 }
2370                 for (i = 0; i < scan.num_channels; ++i) {
2371                         scan.ch[i].number = priv->scan.curr[i]->hw_value;
2372 -                       if (priv->scan.curr[i]->flags & IEEE80211_CHAN_PASSIVE_SCAN) {
2373 +                       if (priv->scan.curr[i]->flags & IEEE80211_CHAN_NO_IR) {
2374                                 scan.ch[i].min_chan_time = 50;
2375                                 scan.ch[i].max_chan_time = 100;
2376                         } else {
2377 @@ -241,7 +241,7 @@ void cw1200_scan_work(struct work_struct
2378                                 scan.ch[i].max_chan_time = 25;
2379                         }
2380                 }
2381 -               if (!(first->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
2382 +               if (!(first->flags & IEEE80211_CHAN_NO_IR) &&
2383                     priv->scan.output_power != first->max_power) {
2384                         priv->scan.output_power = first->max_power;
2385                         wsm_set_output_power(priv,
2386 --- a/drivers/net/wireless/ipw2x00/ipw2100.c
2387 +++ b/drivers/net/wireless/ipw2x00/ipw2100.c
2388 @@ -1934,10 +1934,10 @@ static int ipw2100_wdev_init(struct net_
2389                         bg_band->channels[i].max_power = geo->bg[i].max_power;
2390                         if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY)
2391                                 bg_band->channels[i].flags |=
2392 -                                       IEEE80211_CHAN_PASSIVE_SCAN;
2393 +                                       IEEE80211_CHAN_NO_IR;
2394                         if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS)
2395                                 bg_band->channels[i].flags |=
2396 -                                       IEEE80211_CHAN_NO_IBSS;
2397 +                                       IEEE80211_CHAN_NO_IR;
2398                         if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)
2399                                 bg_band->channels[i].flags |=
2400                                         IEEE80211_CHAN_RADAR;
2401 --- a/drivers/net/wireless/ipw2x00/ipw2200.c
2402 +++ b/drivers/net/wireless/ipw2x00/ipw2200.c
2403 @@ -11472,10 +11472,10 @@ static int ipw_wdev_init(struct net_devi
2404                         bg_band->channels[i].max_power = geo->bg[i].max_power;
2405                         if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY)
2406                                 bg_band->channels[i].flags |=
2407 -                                       IEEE80211_CHAN_PASSIVE_SCAN;
2408 +                                       IEEE80211_CHAN_NO_IR;
2409                         if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS)
2410                                 bg_band->channels[i].flags |=
2411 -                                       IEEE80211_CHAN_NO_IBSS;
2412 +                                       IEEE80211_CHAN_NO_IR;
2413                         if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)
2414                                 bg_band->channels[i].flags |=
2415                                         IEEE80211_CHAN_RADAR;
2416 @@ -11511,10 +11511,10 @@ static int ipw_wdev_init(struct net_devi
2417                         a_band->channels[i].max_power = geo->a[i].max_power;
2418                         if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY)
2419                                 a_band->channels[i].flags |=
2420 -                                       IEEE80211_CHAN_PASSIVE_SCAN;
2421 +                                       IEEE80211_CHAN_NO_IR;
2422                         if (geo->a[i].flags & LIBIPW_CH_NO_IBSS)
2423                                 a_band->channels[i].flags |=
2424 -                                       IEEE80211_CHAN_NO_IBSS;
2425 +                                       IEEE80211_CHAN_NO_IR;
2426                         if (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT)
2427                                 a_band->channels[i].flags |=
2428                                         IEEE80211_CHAN_RADAR;
2429 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
2430 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
2431 @@ -1595,7 +1595,7 @@ il3945_get_channels_for_scan(struct il_p
2432                  *  and use long active_dwell time.
2433                  */
2434                 if (!is_active || il_is_channel_passive(ch_info) ||
2435 -                   (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
2436 +                   (chan->flags & IEEE80211_CHAN_NO_IR)) {
2437                         scan_ch->type = 0;      /* passive */
2438                         if (IL_UCODE_API(il->ucode_ver) == 1)
2439                                 scan_ch->active_dwell =
2440 --- a/drivers/net/wireless/iwlegacy/4965-mac.c
2441 +++ b/drivers/net/wireless/iwlegacy/4965-mac.c
2442 @@ -805,7 +805,7 @@ il4965_get_channels_for_scan(struct il_p
2443                 }
2444  
2445                 if (!is_active || il_is_channel_passive(ch_info) ||
2446 -                   (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN))
2447 +                   (chan->flags & IEEE80211_CHAN_NO_IR))
2448                         scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
2449                 else
2450                         scan_ch->type = SCAN_CHANNEL_TYPE_ACTIVE;
2451 --- a/drivers/net/wireless/iwlegacy/common.c
2452 +++ b/drivers/net/wireless/iwlegacy/common.c
2453 @@ -3447,10 +3447,10 @@ il_init_geos(struct il_priv *il)
2454  
2455                 if (il_is_channel_valid(ch)) {
2456                         if (!(ch->flags & EEPROM_CHANNEL_IBSS))
2457 -                               geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
2458 +                               geo_ch->flags |= IEEE80211_CHAN_NO_IR;
2459  
2460                         if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
2461 -                               geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
2462 +                               geo_ch->flags |= IEEE80211_CHAN_NO_IR;
2463  
2464                         if (ch->flags & EEPROM_CHANNEL_RADAR)
2465                                 geo_ch->flags |= IEEE80211_CHAN_RADAR;
2466 --- a/drivers/net/wireless/iwlegacy/debug.c
2467 +++ b/drivers/net/wireless/iwlegacy/debug.c
2468 @@ -567,12 +567,12 @@ il_dbgfs_channels_read(struct file *file
2469                                       flags & IEEE80211_CHAN_RADAR ?
2470                                       " (IEEE 802.11h required)" : "",
2471                                       ((channels[i].
2472 -                                       flags & IEEE80211_CHAN_NO_IBSS) ||
2473 +                                       flags & IEEE80211_CHAN_NO_IR) ||
2474                                        (channels[i].
2475                                         flags & IEEE80211_CHAN_RADAR)) ? "" :
2476                                       ", IBSS",
2477                                       channels[i].
2478 -                                     flags & IEEE80211_CHAN_PASSIVE_SCAN ?
2479 +                                     flags & IEEE80211_CHAN_NO_IR ?
2480                                       "passive only" : "active/passive");
2481         }
2482         supp_band = il_get_hw_mode(il, IEEE80211_BAND_5GHZ);
2483 @@ -594,12 +594,12 @@ il_dbgfs_channels_read(struct file *file
2484                                       flags & IEEE80211_CHAN_RADAR ?
2485                                       " (IEEE 802.11h required)" : "",
2486                                       ((channels[i].
2487 -                                       flags & IEEE80211_CHAN_NO_IBSS) ||
2488 +                                       flags & IEEE80211_CHAN_NO_IR) ||
2489                                        (channels[i].
2490                                         flags & IEEE80211_CHAN_RADAR)) ? "" :
2491                                       ", IBSS",
2492                                       channels[i].
2493 -                                     flags & IEEE80211_CHAN_PASSIVE_SCAN ?
2494 +                                     flags & IEEE80211_CHAN_NO_IR ?
2495                                       "passive only" : "active/passive");
2496         }
2497         ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2498 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
2499 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
2500 @@ -352,12 +352,12 @@ static ssize_t iwl_dbgfs_channels_read(s
2501                                         channels[i].max_power,
2502                                         channels[i].flags & IEEE80211_CHAN_RADAR ?
2503                                         " (IEEE 802.11h required)" : "",
2504 -                                       ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
2505 +                                       ((channels[i].flags & IEEE80211_CHAN_NO_IR)
2506                                         || (channels[i].flags &
2507                                         IEEE80211_CHAN_RADAR)) ? "" :
2508                                         ", IBSS",
2509                                         channels[i].flags &
2510 -                                       IEEE80211_CHAN_PASSIVE_SCAN ?
2511 +                                       IEEE80211_CHAN_NO_IR ?
2512                                         "passive only" : "active/passive");
2513         }
2514         supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
2515 @@ -375,12 +375,12 @@ static ssize_t iwl_dbgfs_channels_read(s
2516                                         channels[i].max_power,
2517                                         channels[i].flags & IEEE80211_CHAN_RADAR ?
2518                                         " (IEEE 802.11h required)" : "",
2519 -                                       ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
2520 +                                       ((channels[i].flags & IEEE80211_CHAN_NO_IR)
2521                                         || (channels[i].flags &
2522                                         IEEE80211_CHAN_RADAR)) ? "" :
2523                                         ", IBSS",
2524                                         channels[i].flags &
2525 -                                       IEEE80211_CHAN_PASSIVE_SCAN ?
2526 +                                       IEEE80211_CHAN_NO_IR ?
2527                                         "passive only" : "active/passive");
2528         }
2529         ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2530 --- a/drivers/net/wireless/iwlwifi/dvm/scan.c
2531 +++ b/drivers/net/wireless/iwlwifi/dvm/scan.c
2532 @@ -544,7 +544,7 @@ static int iwl_get_channels_for_scan(str
2533                 channel = chan->hw_value;
2534                 scan_ch->channel = cpu_to_le16(channel);
2535  
2536 -               if (!is_active || (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN))
2537 +               if (!is_active || (chan->flags & IEEE80211_CHAN_NO_IR))
2538                         scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
2539                 else
2540                         scan_ch->type = SCAN_CHANNEL_TYPE_ACTIVE;
2541 --- a/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c
2542 +++ b/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c
2543 @@ -614,10 +614,10 @@ static int iwl_init_channel_map(struct d
2544                         channel->flags = IEEE80211_CHAN_NO_HT40;
2545  
2546                         if (!(eeprom_ch->flags & EEPROM_CHANNEL_IBSS))
2547 -                               channel->flags |= IEEE80211_CHAN_NO_IBSS;
2548 +                               channel->flags |= IEEE80211_CHAN_NO_IR;
2549  
2550                         if (!(eeprom_ch->flags & EEPROM_CHANNEL_ACTIVE))
2551 -                               channel->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
2552 +                               channel->flags |= IEEE80211_CHAN_NO_IR;
2553  
2554                         if (eeprom_ch->flags & EEPROM_CHANNEL_RADAR)
2555                                 channel->flags |= IEEE80211_CHAN_RADAR;
2556 --- a/drivers/net/wireless/iwlwifi/iwl-nvm-parse.c
2557 +++ b/drivers/net/wireless/iwlwifi/iwl-nvm-parse.c
2558 @@ -223,10 +223,10 @@ static int iwl_init_channel_map(struct d
2559                         channel->flags |= IEEE80211_CHAN_NO_160MHZ;
2560  
2561                 if (!(ch_flags & NVM_CHANNEL_IBSS))
2562 -                       channel->flags |= IEEE80211_CHAN_NO_IBSS;
2563 +                       channel->flags |= IEEE80211_CHAN_NO_IR;
2564  
2565                 if (!(ch_flags & NVM_CHANNEL_ACTIVE))
2566 -                       channel->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
2567 +                       channel->flags |= IEEE80211_CHAN_NO_IR;
2568  
2569                 if (ch_flags & NVM_CHANNEL_RADAR)
2570                         channel->flags |= IEEE80211_CHAN_RADAR;
2571 --- a/drivers/net/wireless/iwlwifi/mvm/scan.c
2572 +++ b/drivers/net/wireless/iwlwifi/mvm/scan.c
2573 @@ -192,7 +192,7 @@ static void iwl_mvm_scan_fill_channels(s
2574         for (i = 0; i < cmd->channel_count; i++) {
2575                 chan->channel = cpu_to_le16(req->channels[i]->hw_value);
2576                 chan->type = cpu_to_le32(type);
2577 -               if (req->channels[i]->flags & IEEE80211_CHAN_PASSIVE_SCAN)
2578 +               if (req->channels[i]->flags & IEEE80211_CHAN_NO_IR)
2579                         chan->type &= cpu_to_le32(~SCAN_CHANNEL_TYPE_ACTIVE);
2580                 chan->active_dwell = cpu_to_le16(active_dwell);
2581                 chan->passive_dwell = cpu_to_le16(passive_dwell);
2582 @@ -642,7 +642,7 @@ static void iwl_build_channel_cfg(struct
2583                 channels->iter_count[index] = cpu_to_le16(1);
2584                 channels->iter_interval[index] = 0;
2585  
2586 -               if (!(s_band->channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN))
2587 +               if (!(s_band->channels[i].flags & IEEE80211_CHAN_NO_IR))
2588                         channels->type[index] |=
2589                                 cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_ACTIVE);
2590  
2591 --- a/drivers/net/wireless/mac80211_hwsim.c
2592 +++ b/drivers/net/wireless/mac80211_hwsim.c
2593 @@ -159,7 +159,7 @@ static const struct ieee80211_regdomain 
2594         .reg_rules = {
2595                 REG_RULE(2412-10, 2462+10, 40, 0, 20, 0),
2596                 REG_RULE(5725-10, 5850+10, 40, 0, 30,
2597 -                       NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
2598 +                        NL80211_RRF_NO_IR),
2599         }
2600  };
2601  
2602 @@ -1485,7 +1485,7 @@ static void hw_scan_work(struct work_str
2603                     req->channels[hwsim->scan_chan_idx]->center_freq);
2604  
2605         hwsim->tmp_chan = req->channels[hwsim->scan_chan_idx];
2606 -       if (hwsim->tmp_chan->flags & IEEE80211_CHAN_PASSIVE_SCAN ||
2607 +       if (hwsim->tmp_chan->flags & IEEE80211_CHAN_NO_IR ||
2608             !req->n_ssids) {
2609                 dwell = 120;
2610         } else {
2611 --- a/drivers/net/wireless/mwifiex/cfg80211.c
2612 +++ b/drivers/net/wireless/mwifiex/cfg80211.c
2613 @@ -50,24 +50,24 @@ static const struct ieee80211_regdomain 
2614                 REG_RULE(2412-10, 2462+10, 40, 3, 20, 0),
2615                 /* Channel 12 - 13 */
2616                 REG_RULE(2467-10, 2472+10, 20, 3, 20,
2617 -                        NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
2618 +                        NL80211_RRF_NO_IR),
2619                 /* Channel 14 */
2620                 REG_RULE(2484-10, 2484+10, 20, 3, 20,
2621 -                        NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
2622 +                        NL80211_RRF_NO_IR |
2623                          NL80211_RRF_NO_OFDM),
2624                 /* Channel 36 - 48 */
2625                 REG_RULE(5180-10, 5240+10, 40, 3, 20,
2626 -                        NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
2627 +                        NL80211_RRF_NO_IR),
2628                 /* Channel 149 - 165 */
2629                 REG_RULE(5745-10, 5825+10, 40, 3, 20,
2630 -                        NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
2631 +                        NL80211_RRF_NO_IR),
2632                 /* Channel 52 - 64 */
2633                 REG_RULE(5260-10, 5320+10, 40, 3, 30,
2634 -                        NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
2635 +                        NL80211_RRF_NO_IR |
2636                          NL80211_RRF_DFS),
2637                 /* Channel 100 - 140 */
2638                 REG_RULE(5500-10, 5700+10, 40, 3, 30,
2639 -                        NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
2640 +                        NL80211_RRF_NO_IR |
2641                          NL80211_RRF_DFS),
2642         }
2643  };
2644 @@ -1968,7 +1968,7 @@ mwifiex_cfg80211_scan(struct wiphy *wiph
2645                 user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
2646                 user_scan_cfg->chan_list[i].radio_type = chan->band;
2647  
2648 -               if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
2649 +               if (chan->flags & IEEE80211_CHAN_NO_IR)
2650                         user_scan_cfg->chan_list[i].scan_type =
2651                                                 MWIFIEX_SCAN_TYPE_PASSIVE;
2652                 else
2653 --- a/drivers/net/wireless/mwifiex/scan.c
2654 +++ b/drivers/net/wireless/mwifiex/scan.c
2655 @@ -515,14 +515,14 @@ mwifiex_scan_create_channel_list(struct 
2656                                 scan_chan_list[chan_idx].max_scan_time =
2657                                         cpu_to_le16((u16) user_scan_in->
2658                                         chan_list[0].scan_time);
2659 -                       else if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
2660 +                       else if (ch->flags & IEEE80211_CHAN_NO_IR)
2661                                 scan_chan_list[chan_idx].max_scan_time =
2662                                         cpu_to_le16(adapter->passive_scan_time);
2663                         else
2664                                 scan_chan_list[chan_idx].max_scan_time =
2665                                         cpu_to_le16(adapter->active_scan_time);
2666  
2667 -                       if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
2668 +                       if (ch->flags & IEEE80211_CHAN_NO_IR)
2669                                 scan_chan_list[chan_idx].chan_scan_mode_bitmap
2670                                         |= MWIFIEX_PASSIVE_SCAN;
2671                         else
2672 --- a/drivers/net/wireless/rt2x00/rt2x00lib.h
2673 +++ b/drivers/net/wireless/rt2x00/rt2x00lib.h
2674 @@ -146,7 +146,7 @@ void rt2x00queue_remove_l2pad(struct sk_
2675   * @local: frame is not from mac80211
2676   */
2677  int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb,
2678 -                              bool local);
2679 +                              struct ieee80211_sta *sta, bool local);
2680  
2681  /**
2682   * rt2x00queue_update_beacon - Send new beacon from mac80211
2683 --- a/drivers/net/wireless/rt2x00/rt2x00mac.c
2684 +++ b/drivers/net/wireless/rt2x00/rt2x00mac.c
2685 @@ -90,7 +90,7 @@ static int rt2x00mac_tx_rts_cts(struct r
2686                                   frag_skb->data, data_length, tx_info,
2687                                   (struct ieee80211_rts *)(skb->data));
2688  
2689 -       retval = rt2x00queue_write_tx_frame(queue, skb, true);
2690 +       retval = rt2x00queue_write_tx_frame(queue, skb, NULL, true);
2691         if (retval) {
2692                 dev_kfree_skb_any(skb);
2693                 rt2x00_warn(rt2x00dev, "Failed to send RTS/CTS frame\n");
2694 @@ -151,7 +151,7 @@ void rt2x00mac_tx(struct ieee80211_hw *h
2695                         goto exit_fail;
2696         }
2697  
2698 -       if (unlikely(rt2x00queue_write_tx_frame(queue, skb, false)))
2699 +       if (unlikely(rt2x00queue_write_tx_frame(queue, skb, control->sta, false)))
2700                 goto exit_fail;
2701  
2702         /*
2703 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
2704 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
2705 @@ -635,7 +635,7 @@ static void rt2x00queue_bar_check(struct
2706  }
2707  
2708  int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb,
2709 -                              bool local)
2710 +                              struct ieee80211_sta *sta, bool local)
2711  {
2712         struct ieee80211_tx_info *tx_info;
2713         struct queue_entry *entry;
2714 @@ -649,7 +649,7 @@ int rt2x00queue_write_tx_frame(struct da
2715          * after that we are free to use the skb->cb array
2716          * for our information.
2717          */
2718 -       rt2x00queue_create_tx_descriptor(queue->rt2x00dev, skb, &txdesc, NULL);
2719 +       rt2x00queue_create_tx_descriptor(queue->rt2x00dev, skb, &txdesc, sta);
2720  
2721         /*
2722          * All information is retrieved from the skb->cb array,
2723 --- a/drivers/net/wireless/rtl818x/rtl8187/dev.c
2724 +++ b/drivers/net/wireless/rtl818x/rtl8187/dev.c
2725 @@ -416,7 +416,7 @@ static int rtl8187_init_urbs(struct ieee
2726         struct rtl8187_rx_info *info;
2727         int ret = 0;
2728  
2729 -       while (skb_queue_len(&priv->rx_queue) < 16) {
2730 +       while (skb_queue_len(&priv->rx_queue) < 32) {
2731                 skb = __dev_alloc_skb(RTL8187_MAX_RX, GFP_KERNEL);
2732                 if (!skb) {
2733                         ret = -ENOMEM;
2734 --- a/drivers/net/wireless/rtlwifi/base.c
2735 +++ b/drivers/net/wireless/rtlwifi/base.c
2736 @@ -1078,8 +1078,8 @@ u8 rtl_is_special_data(struct ieee80211_
2737  
2738         ip = (struct iphdr *)((u8 *) skb->data + mac_hdr_len +
2739                               SNAP_SIZE + PROTOC_TYPE_SIZE);
2740 -       ether_type = *(u16 *) ((u8 *) skb->data + mac_hdr_len + SNAP_SIZE);
2741 -       /*      ether_type = ntohs(ether_type); */
2742 +       ether_type = be16_to_cpu(*(__be16 *)((u8 *)skb->data + mac_hdr_len +
2743 +                                            SNAP_SIZE));
2744  
2745         if (ETH_P_IP == ether_type) {
2746                 if (IPPROTO_UDP == ip->protocol) {
2747 --- a/drivers/net/wireless/rtlwifi/regd.c
2748 +++ b/drivers/net/wireless/rtlwifi/regd.c
2749 @@ -59,30 +59,27 @@ static struct country_code_to_enum_rd al
2750   */
2751  #define RTL819x_2GHZ_CH12_13   \
2752         REG_RULE(2467-10, 2472+10, 40, 0, 20,\
2753 -       NL80211_RRF_PASSIVE_SCAN)
2754 +       NL80211_RRF_NO_IR)
2755  
2756  #define RTL819x_2GHZ_CH14      \
2757         REG_RULE(2484-10, 2484+10, 40, 0, 20, \
2758 -       NL80211_RRF_PASSIVE_SCAN | \
2759 +       NL80211_RRF_NO_IR | \
2760         NL80211_RRF_NO_OFDM)
2761  
2762  /* 5G chan 36 - chan 64*/
2763  #define RTL819x_5GHZ_5150_5350 \
2764         REG_RULE(5150-10, 5350+10, 40, 0, 30, \
2765 -       NL80211_RRF_PASSIVE_SCAN | \
2766 -       NL80211_RRF_NO_IBSS)
2767 +       NL80211_RRF_NO_IR)
2768  
2769  /* 5G chan 100 - chan 165*/
2770  #define RTL819x_5GHZ_5470_5850 \
2771         REG_RULE(5470-10, 5850+10, 40, 0, 30, \
2772 -       NL80211_RRF_PASSIVE_SCAN | \
2773 -       NL80211_RRF_NO_IBSS)
2774 +       NL80211_RRF_NO_IR)
2775  
2776  /* 5G chan 149 - chan 165*/
2777  #define RTL819x_5GHZ_5725_5850 \
2778         REG_RULE(5725-10, 5850+10, 40, 0, 30, \
2779 -       NL80211_RRF_PASSIVE_SCAN | \
2780 -       NL80211_RRF_NO_IBSS)
2781 +       NL80211_RRF_NO_IR)
2782  
2783  #define RTL819x_5GHZ_ALL       \
2784         (RTL819x_5GHZ_5150_5350, RTL819x_5GHZ_5470_5850)
2785 @@ -185,16 +182,15 @@ static void _rtl_reg_apply_beaconing_fla
2786                                  *regulatory_hint().
2787                                  */
2788  
2789 -                               if (!(reg_rule->flags & NL80211_RRF_NO_IBSS))
2790 -                                       ch->flags &= ~IEEE80211_CHAN_NO_IBSS;
2791 +                               if (!(reg_rule->flags & NL80211_RRF_NO_IR))
2792 +                                       ch->flags &= ~IEEE80211_CHAN_NO_IR;
2793                                 if (!(reg_rule->
2794 -                                    flags & NL80211_RRF_PASSIVE_SCAN))
2795 +                                    flags & NL80211_RRF_NO_IR))
2796                                         ch->flags &=
2797 -                                           ~IEEE80211_CHAN_PASSIVE_SCAN;
2798 +                                           ~IEEE80211_CHAN_NO_IR;
2799                         } else {
2800                                 if (ch->beacon_found)
2801 -                                       ch->flags &= ~(IEEE80211_CHAN_NO_IBSS |
2802 -                                                 IEEE80211_CHAN_PASSIVE_SCAN);
2803 +                                       ch->flags &= ~IEEE80211_CHAN_NO_IR;
2804                         }
2805                 }
2806         }
2807 @@ -219,11 +215,11 @@ static void _rtl_reg_apply_active_scan_f
2808          */
2809         if (initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) {
2810                 ch = &sband->channels[11];      /* CH 12 */
2811 -               if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
2812 -                       ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
2813 +               if (ch->flags & IEEE80211_CHAN_NO_IR)
2814 +                       ch->flags &= ~IEEE80211_CHAN_NO_IR;
2815                 ch = &sband->channels[12];      /* CH 13 */
2816 -               if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
2817 -                       ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
2818 +               if (ch->flags & IEEE80211_CHAN_NO_IR)
2819 +                       ch->flags &= ~IEEE80211_CHAN_NO_IR;
2820                 return;
2821         }
2822  
2823 @@ -237,17 +233,17 @@ static void _rtl_reg_apply_active_scan_f
2824         ch = &sband->channels[11];      /* CH 12 */
2825         reg_rule = freq_reg_info(wiphy, ch->center_freq);
2826         if (!IS_ERR(reg_rule)) {
2827 -               if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN))
2828 -                       if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
2829 -                               ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
2830 +               if (!(reg_rule->flags & NL80211_RRF_NO_IR))
2831 +                       if (ch->flags & IEEE80211_CHAN_NO_IR)
2832 +                               ch->flags &= ~IEEE80211_CHAN_NO_IR;
2833         }
2834  
2835         ch = &sband->channels[12];      /* CH 13 */
2836         reg_rule = freq_reg_info(wiphy, ch->center_freq);
2837         if (!IS_ERR(reg_rule)) {
2838 -               if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN))
2839 -                       if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
2840 -                               ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
2841 +               if (!(reg_rule->flags & NL80211_RRF_NO_IR))
2842 +                       if (ch->flags & IEEE80211_CHAN_NO_IR)
2843 +                               ch->flags &= ~IEEE80211_CHAN_NO_IR;
2844         }
2845  }
2846  
2847 @@ -284,8 +280,8 @@ static void _rtl_reg_apply_radar_flags(s
2848                  */
2849                 if (!(ch->flags & IEEE80211_CHAN_DISABLED))
2850                         ch->flags |= IEEE80211_CHAN_RADAR |
2851 -                           IEEE80211_CHAN_NO_IBSS |
2852 -                           IEEE80211_CHAN_PASSIVE_SCAN;
2853 +                           IEEE80211_CHAN_NO_IR |
2854 +                           IEEE80211_CHAN_NO_IR;
2855         }
2856  }
2857  
2858 --- a/drivers/net/wireless/ti/wl12xx/scan.c
2859 +++ b/drivers/net/wireless/ti/wl12xx/scan.c
2860 @@ -47,7 +47,7 @@ static int wl1271_get_scan_channels(stru
2861                      * In active scans, we only scan channels not
2862                      * marked as passive.
2863                      */
2864 -                   (passive || !(flags & IEEE80211_CHAN_PASSIVE_SCAN))) {
2865 +                   (passive || !(flags & IEEE80211_CHAN_NO_IR))) {
2866                         wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ",
2867                                      req->channels[i]->band,
2868                                      req->channels[i]->center_freq);
2869 --- a/drivers/net/wireless/ti/wlcore/cmd.c
2870 +++ b/drivers/net/wireless/ti/wlcore/cmd.c
2871 @@ -1688,7 +1688,7 @@ int wlcore_cmd_regdomain_config_locked(s
2872  
2873                         if (channel->flags & (IEEE80211_CHAN_DISABLED |
2874                                               IEEE80211_CHAN_RADAR |
2875 -                                             IEEE80211_CHAN_PASSIVE_SCAN))
2876 +                                             IEEE80211_CHAN_NO_IR))
2877                                 continue;
2878  
2879                         ch_bit_idx = wlcore_get_reg_conf_ch_idx(b, ch);
2880 --- a/drivers/net/wireless/ti/wlcore/main.c
2881 +++ b/drivers/net/wireless/ti/wlcore/main.c
2882 @@ -91,8 +91,7 @@ static void wl1271_reg_notify(struct wip
2883                         continue;
2884  
2885                 if (ch->flags & IEEE80211_CHAN_RADAR)
2886 -                       ch->flags |= IEEE80211_CHAN_NO_IBSS |
2887 -                                    IEEE80211_CHAN_PASSIVE_SCAN;
2888 +                       ch->flags |= IEEE80211_CHAN_NO_IR;
2889  
2890         }
2891  
2892 --- a/drivers/net/wireless/ti/wlcore/scan.c
2893 +++ b/drivers/net/wireless/ti/wlcore/scan.c
2894 @@ -189,14 +189,14 @@ wlcore_scan_get_channels(struct wl1271 *
2895                 flags = req_channels[i]->flags;
2896  
2897                 if (force_passive)
2898 -                       flags |= IEEE80211_CHAN_PASSIVE_SCAN;
2899 +                       flags |= IEEE80211_CHAN_NO_IR;
2900  
2901                 if ((req_channels[i]->band == band) &&
2902                     !(flags & IEEE80211_CHAN_DISABLED) &&
2903                     (!!(flags & IEEE80211_CHAN_RADAR) == radar) &&
2904                     /* if radar is set, we ignore the passive flag */
2905                     (radar ||
2906 -                    !!(flags & IEEE80211_CHAN_PASSIVE_SCAN) == passive)) {
2907 +                    !!(flags & IEEE80211_CHAN_NO_IR) == passive)) {
2908  
2909  
2910                         if (flags & IEEE80211_CHAN_RADAR) {
2911 @@ -221,7 +221,7 @@ wlcore_scan_get_channels(struct wl1271 *
2912                             (band == IEEE80211_BAND_2GHZ) &&
2913                             (channels[j].channel >= 12) &&
2914                             (channels[j].channel <= 14) &&
2915 -                           (flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
2916 +                           (flags & IEEE80211_CHAN_NO_IR) &&
2917                             !force_passive) {
2918                                 /* pactive channels treated as DFS */
2919                                 channels[j].flags = SCAN_CHANNEL_FLAGS_DFS;
2920 @@ -244,7 +244,7 @@ wlcore_scan_get_channels(struct wl1271 *
2921                                      max_dwell_time_active,
2922                                      flags & IEEE80211_CHAN_RADAR ?
2923                                         ", DFS" : "",
2924 -                                    flags & IEEE80211_CHAN_PASSIVE_SCAN ?
2925 +                                    flags & IEEE80211_CHAN_NO_IR ?
2926                                         ", PASSIVE" : "");
2927                         j++;
2928                 }
2929 --- a/include/net/cfg80211.h
2930 +++ b/include/net/cfg80211.h
2931 @@ -91,9 +91,8 @@ enum ieee80211_band {
2932   * Channel flags set by the regulatory control code.
2933   *
2934   * @IEEE80211_CHAN_DISABLED: This channel is disabled.
2935 - * @IEEE80211_CHAN_PASSIVE_SCAN: Only passive scanning is permitted
2936 - *     on this channel.
2937 - * @IEEE80211_CHAN_NO_IBSS: IBSS is not allowed on this channel.
2938 + * @IEEE80211_CHAN_NO_IR: do not initiate radiation, this includes
2939 + *     sending probe requests or beaconing.
2940   * @IEEE80211_CHAN_RADAR: Radar detection is required on this channel.
2941   * @IEEE80211_CHAN_NO_HT40PLUS: extension channel above this channel
2942   *     is not permitted.
2943 @@ -113,8 +112,8 @@ enum ieee80211_band {
2944   */
2945  enum ieee80211_channel_flags {
2946         IEEE80211_CHAN_DISABLED         = 1<<0,
2947 -       IEEE80211_CHAN_PASSIVE_SCAN     = 1<<1,
2948 -       IEEE80211_CHAN_NO_IBSS          = 1<<2,
2949 +       IEEE80211_CHAN_NO_IR            = 1<<1,
2950 +       /* hole at 1<<2 */
2951         IEEE80211_CHAN_RADAR            = 1<<3,
2952         IEEE80211_CHAN_NO_HT40PLUS      = 1<<4,
2953         IEEE80211_CHAN_NO_HT40MINUS     = 1<<5,
2954 @@ -4149,6 +4148,7 @@ void cfg80211_radar_event(struct wiphy *
2955  /**
2956   * cfg80211_cac_event - Channel availability check (CAC) event
2957   * @netdev: network device
2958 + * @chandef: chandef for the current channel
2959   * @event: type of event
2960   * @gfp: context flags
2961   *
2962 @@ -4157,6 +4157,7 @@ void cfg80211_radar_event(struct wiphy *
2963   * also by full-MAC drivers.
2964   */
2965  void cfg80211_cac_event(struct net_device *netdev,
2966 +                       const struct cfg80211_chan_def *chandef,
2967                         enum nl80211_radar_event event, gfp_t gfp);
2968  
2969  
2970 @@ -4282,7 +4283,8 @@ bool cfg80211_reg_can_beacon(struct wiph
2971   * @dev: the device which switched channels
2972   * @chandef: the new channel definition
2973   *
2974 - * Acquires wdev_lock, so must only be called from sleepable driver context!
2975 + * Caller must acquire wdev_lock, therefore must only be called from sleepable
2976 + * driver context!
2977   */
2978  void cfg80211_ch_switch_notify(struct net_device *dev,
2979                                struct cfg80211_chan_def *chandef);
2980 --- a/include/uapi/linux/nl80211.h
2981 +++ b/include/uapi/linux/nl80211.h
2982 @@ -1508,6 +1508,12 @@ enum nl80211_commands {
2983   *     to react to radar events, e.g. initiate a channel switch or leave the
2984   *     IBSS network.
2985   *
2986 + * @NL80211_ATTR_SUPPORT_5_MHZ: A flag indicating that the device supports
2987 + *     5 MHz channel bandwidth.
2988 + *
2989 + * @NL80211_ATTR_SUPPORT_10_MHZ: A flag indicating that the device supports
2990 + *     10 MHz channel bandwidth.
2991 + *
2992   * @NL80211_ATTR_MAX: highest attribute number currently defined
2993   * @__NL80211_ATTR_AFTER_LAST: internal use
2994   */
2995 @@ -1824,6 +1830,9 @@ enum nl80211_attrs {
2996  
2997         NL80211_ATTR_HANDLE_DFS,
2998  
2999 +       NL80211_ATTR_SUPPORT_5_MHZ,
3000 +       NL80211_ATTR_SUPPORT_10_MHZ,
3001 +
3002         /* add attributes here, update the policy in nl80211.c */
3003  
3004         __NL80211_ATTR_AFTER_LAST,
3005 @@ -2224,10 +2233,9 @@ enum nl80211_band_attr {
3006   * @NL80211_FREQUENCY_ATTR_FREQ: Frequency in MHz
3007   * @NL80211_FREQUENCY_ATTR_DISABLED: Channel is disabled in current
3008   *     regulatory domain.
3009 - * @NL80211_FREQUENCY_ATTR_PASSIVE_SCAN: Only passive scanning is
3010 - *     permitted on this channel in current regulatory domain.
3011 - * @NL80211_FREQUENCY_ATTR_NO_IBSS: IBSS networks are not permitted
3012 - *     on this channel in current regulatory domain.
3013 + * @NL80211_FREQUENCY_ATTR_NO_IR: no mechanisms that initiate radiation
3014 + *     are permitted on this channel, this includes sending probe
3015 + *     requests, or modes of operation that require beaconing.
3016   * @NL80211_FREQUENCY_ATTR_RADAR: Radar detection is mandatory
3017   *     on this channel in current regulatory domain.
3018   * @NL80211_FREQUENCY_ATTR_MAX_TX_POWER: Maximum transmission power in mBm
3019 @@ -2254,8 +2262,8 @@ enum nl80211_frequency_attr {
3020         __NL80211_FREQUENCY_ATTR_INVALID,
3021         NL80211_FREQUENCY_ATTR_FREQ,
3022         NL80211_FREQUENCY_ATTR_DISABLED,
3023 -       NL80211_FREQUENCY_ATTR_PASSIVE_SCAN,
3024 -       NL80211_FREQUENCY_ATTR_NO_IBSS,
3025 +       NL80211_FREQUENCY_ATTR_NO_IR,
3026 +       __NL80211_FREQUENCY_ATTR_NO_IBSS,
3027         NL80211_FREQUENCY_ATTR_RADAR,
3028         NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
3029         NL80211_FREQUENCY_ATTR_DFS_STATE,
3030 @@ -2271,6 +2279,9 @@ enum nl80211_frequency_attr {
3031  };
3032  
3033  #define NL80211_FREQUENCY_ATTR_MAX_TX_POWER NL80211_FREQUENCY_ATTR_MAX_TX_POWER
3034 +#define NL80211_FREQUENCY_ATTR_PASSIVE_SCAN    NL80211_FREQUENCY_ATTR_NO_IR
3035 +#define NL80211_FREQUENCY_ATTR_NO_IBSS         NL80211_FREQUENCY_ATTR_NO_IR
3036 +#define NL80211_FREQUENCY_ATTR_NO_IR           NL80211_FREQUENCY_ATTR_NO_IR
3037  
3038  /**
3039   * enum nl80211_bitrate_attr - bitrate attributes
3040 @@ -2413,8 +2424,9 @@ enum nl80211_sched_scan_match_attr {
3041   * @NL80211_RRF_DFS: DFS support is required to be used
3042   * @NL80211_RRF_PTP_ONLY: this is only for Point To Point links
3043   * @NL80211_RRF_PTMP_ONLY: this is only for Point To Multi Point links
3044 - * @NL80211_RRF_PASSIVE_SCAN: passive scan is required
3045 - * @NL80211_RRF_NO_IBSS: no IBSS is allowed
3046 + * @NL80211_RRF_NO_IR: no mechanisms that initiate radiation are allowed,
3047 + *     this includes probe requests or modes of operation that require
3048 + *     beaconing.
3049   */
3050  enum nl80211_reg_rule_flags {
3051         NL80211_RRF_NO_OFDM             = 1<<0,
3052 @@ -2424,10 +2436,17 @@ enum nl80211_reg_rule_flags {
3053         NL80211_RRF_DFS                 = 1<<4,
3054         NL80211_RRF_PTP_ONLY            = 1<<5,
3055         NL80211_RRF_PTMP_ONLY           = 1<<6,
3056 -       NL80211_RRF_PASSIVE_SCAN        = 1<<7,
3057 -       NL80211_RRF_NO_IBSS             = 1<<8,
3058 +       NL80211_RRF_NO_IR               = 1<<7,
3059 +       __NL80211_RRF_NO_IBSS           = 1<<8,
3060  };
3061  
3062 +#define NL80211_RRF_PASSIVE_SCAN       NL80211_RRF_NO_IR
3063 +#define NL80211_RRF_NO_IBSS            NL80211_RRF_NO_IR
3064 +#define NL80211_RRF_NO_IR              NL80211_RRF_NO_IR
3065 +
3066 +/* For backport compatibility with older userspace */
3067 +#define NL80211_RRF_NO_IR_ALL          (NL80211_RRF_NO_IR | __NL80211_RRF_NO_IBSS)
3068 +
3069  /**
3070   * enum nl80211_dfs_regions - regulatory DFS regions
3071   *
3072 --- a/net/mac80211/cfg.c
3073 +++ b/net/mac80211/cfg.c
3074 @@ -846,7 +846,7 @@ static int ieee80211_set_probe_resp(stru
3075         if (!resp || !resp_len)
3076                 return 1;
3077  
3078 -       old = rtnl_dereference(sdata->u.ap.probe_resp);
3079 +       old = sdata_dereference(sdata->u.ap.probe_resp, sdata);
3080  
3081         new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
3082         if (!new)
3083 @@ -870,7 +870,8 @@ int ieee80211_assign_beacon(struct ieee8
3084         int size, err;
3085         u32 changed = BSS_CHANGED_BEACON;
3086  
3087 -       old = rtnl_dereference(sdata->u.ap.beacon);
3088 +       old = sdata_dereference(sdata->u.ap.beacon, sdata);
3089 +
3090  
3091         /* Need to have a beacon head if we don't have one yet */
3092         if (!params->head && !old)
3093 @@ -947,7 +948,7 @@ static int ieee80211_start_ap(struct wip
3094                       BSS_CHANGED_P2P_PS;
3095         int err;
3096  
3097 -       old = rtnl_dereference(sdata->u.ap.beacon);
3098 +       old = sdata_dereference(sdata->u.ap.beacon, sdata);
3099         if (old)
3100                 return -EALREADY;
3101  
3102 @@ -1001,7 +1002,8 @@ static int ieee80211_start_ap(struct wip
3103  
3104         err = drv_start_ap(sdata->local, sdata);
3105         if (err) {
3106 -               old = rtnl_dereference(sdata->u.ap.beacon);
3107 +               old = sdata_dereference(sdata->u.ap.beacon, sdata);
3108 +
3109                 if (old)
3110                         kfree_rcu(old, rcu_head);
3111                 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
3112 @@ -1032,7 +1034,7 @@ static int ieee80211_change_beacon(struc
3113         if (sdata->vif.csa_active)
3114                 return -EBUSY;
3115  
3116 -       old = rtnl_dereference(sdata->u.ap.beacon);
3117 +       old = sdata_dereference(sdata->u.ap.beacon, sdata);
3118         if (!old)
3119                 return -ENOENT;
3120  
3121 @@ -1050,15 +1052,18 @@ static int ieee80211_stop_ap(struct wiph
3122         struct ieee80211_local *local = sdata->local;
3123         struct beacon_data *old_beacon;
3124         struct probe_resp *old_probe_resp;
3125 +       struct cfg80211_chan_def chandef;
3126  
3127 -       old_beacon = rtnl_dereference(sdata->u.ap.beacon);
3128 +       old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
3129         if (!old_beacon)
3130                 return -ENOENT;
3131 -       old_probe_resp = rtnl_dereference(sdata->u.ap.probe_resp);
3132 +       old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
3133  
3134         /* abort any running channel switch */
3135         sdata->vif.csa_active = false;
3136 -       cancel_work_sync(&sdata->csa_finalize_work);
3137 +       kfree(sdata->u.ap.next_beacon);
3138 +       sdata->u.ap.next_beacon = NULL;
3139 +
3140         cancel_work_sync(&sdata->u.ap.request_smps_work);
3141  
3142         /* turn off carrier for this interface and dependent VLANs */
3143 @@ -1091,8 +1096,10 @@ static int ieee80211_stop_ap(struct wiph
3144         ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
3145  
3146         if (sdata->wdev.cac_started) {
3147 +               chandef = sdata->vif.bss_conf.chandef;
3148                 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
3149 -               cfg80211_cac_event(sdata->dev, NL80211_RADAR_CAC_ABORTED,
3150 +               cfg80211_cac_event(sdata->dev, &chandef,
3151 +                                  NL80211_RADAR_CAC_ABORTED,
3152                                    GFP_KERNEL);
3153         }
3154  
3155 @@ -1368,7 +1375,7 @@ static int sta_apply_parameters(struct i
3156                         changed |=
3157                               ieee80211_mps_set_sta_local_pm(sta,
3158                                                              params->local_pm);
3159 -               ieee80211_bss_info_change_notify(sdata, changed);
3160 +               ieee80211_mbss_info_change_notify(sdata, changed);
3161  #endif
3162         }
3163  
3164 @@ -1953,7 +1960,7 @@ static int ieee80211_change_bss(struct w
3165         enum ieee80211_band band;
3166         u32 changed = 0;
3167  
3168 -       if (!rtnl_dereference(sdata->u.ap.beacon))
3169 +       if (!sdata_dereference(sdata->u.ap.beacon, sdata))
3170                 return -ENOENT;
3171  
3172         band = ieee80211_get_sdata_band(sdata);
3173 @@ -2964,27 +2971,33 @@ void ieee80211_csa_finalize_work(struct 
3174         struct ieee80211_local *local = sdata->local;
3175         int err, changed = 0;
3176  
3177 +       sdata_lock(sdata);
3178 +       /* AP might have been stopped while waiting for the lock. */
3179 +       if (!sdata->vif.csa_active)
3180 +               goto unlock;
3181 +
3182         if (!ieee80211_sdata_running(sdata))
3183 -               return;
3184 +               goto unlock;
3185  
3186         sdata->radar_required = sdata->csa_radar_required;
3187 -       err = ieee80211_vif_change_channel(sdata, &local->csa_chandef,
3188 -                                          &changed);
3189 +       err = ieee80211_vif_change_channel(sdata, &changed);
3190         if (WARN_ON(err < 0))
3191 -               return;
3192 +               goto unlock;
3193  
3194         if (!local->use_chanctx) {
3195 -               local->_oper_chandef = local->csa_chandef;
3196 +               local->_oper_chandef = sdata->csa_chandef;
3197                 ieee80211_hw_config(local, 0);
3198         }
3199  
3200         ieee80211_bss_info_change_notify(sdata, changed);
3201  
3202 +       sdata->vif.csa_active = false;
3203         switch (sdata->vif.type) {
3204         case NL80211_IFTYPE_AP:
3205                 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon);
3206                 if (err < 0)
3207 -                       return;
3208 +                       goto unlock;
3209 +
3210                 changed |= err;
3211                 kfree(sdata->u.ap.next_beacon);
3212                 sdata->u.ap.next_beacon = NULL;
3213 @@ -2998,20 +3011,22 @@ void ieee80211_csa_finalize_work(struct 
3214         case NL80211_IFTYPE_MESH_POINT:
3215                 err = ieee80211_mesh_finish_csa(sdata);
3216                 if (err < 0)
3217 -                       return;
3218 +                       goto unlock;
3219                 break;
3220  #endif
3221         default:
3222                 WARN_ON(1);
3223 -               return;
3224 +               goto unlock;
3225         }
3226 -       sdata->vif.csa_active = false;
3227  
3228         ieee80211_wake_queues_by_reason(&sdata->local->hw,
3229                                         IEEE80211_MAX_QUEUE_MAP,
3230                                         IEEE80211_QUEUE_STOP_REASON_CSA);
3231  
3232 -       cfg80211_ch_switch_notify(sdata->dev, &local->csa_chandef);
3233 +       cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
3234 +
3235 +unlock:
3236 +       sdata_unlock(sdata);
3237  }
3238  
3239  static int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3240 @@ -3024,6 +3039,8 @@ static int ieee80211_channel_switch(stru
3241         struct ieee80211_if_mesh __maybe_unused *ifmsh;
3242         int err, num_chanctx;
3243  
3244 +       lockdep_assert_held(&sdata->wdev.mtx);
3245 +
3246         if (!list_empty(&local->roc_list) || local->scanning)
3247                 return -EBUSY;
3248  
3249 @@ -3120,9 +3137,17 @@ static int ieee80211_channel_switch(stru
3250                     params->chandef.chan->band)
3251                         return -EINVAL;
3252  
3253 +               ifmsh->chsw_init = true;
3254 +               if (!ifmsh->pre_value)
3255 +                       ifmsh->pre_value = 1;
3256 +               else
3257 +                       ifmsh->pre_value++;
3258 +
3259                 err = ieee80211_mesh_csa_beacon(sdata, params, true);
3260 -               if (err < 0)
3261 +               if (err < 0) {
3262 +                       ifmsh->chsw_init = false;
3263                         return err;
3264 +               }
3265                 break;
3266  #endif
3267         default:
3268 @@ -3136,7 +3161,7 @@ static int ieee80211_channel_switch(stru
3269                                 IEEE80211_MAX_QUEUE_MAP,
3270                                 IEEE80211_QUEUE_STOP_REASON_CSA);
3271  
3272 -       local->csa_chandef = params->chandef;
3273 +       sdata->csa_chandef = params->chandef;
3274         sdata->vif.csa_active = true;
3275  
3276         ieee80211_bss_info_change_notify(sdata, err);
3277 --- a/net/mac80211/iface.c
3278 +++ b/net/mac80211/iface.c
3279 @@ -749,6 +749,7 @@ static void ieee80211_do_stop(struct iee
3280         u32 hw_reconf_flags = 0;
3281         int i, flushed;
3282         struct ps_data *ps;
3283 +       struct cfg80211_chan_def chandef;
3284  
3285         clear_bit(SDATA_STATE_RUNNING, &sdata->state);
3286  
3287 @@ -828,11 +829,13 @@ static void ieee80211_do_stop(struct iee
3288         cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
3289  
3290         if (sdata->wdev.cac_started) {
3291 +               chandef = sdata->vif.bss_conf.chandef;
3292                 WARN_ON(local->suspended);
3293                 mutex_lock(&local->iflist_mtx);
3294                 ieee80211_vif_release_channel(sdata);
3295                 mutex_unlock(&local->iflist_mtx);
3296 -               cfg80211_cac_event(sdata->dev, NL80211_RADAR_CAC_ABORTED,
3297 +               cfg80211_cac_event(sdata->dev, &chandef,
3298 +                                  NL80211_RADAR_CAC_ABORTED,
3299                                    GFP_KERNEL);
3300         }
3301  
3302 @@ -1340,7 +1343,6 @@ static void ieee80211_setup_sdata(struct
3303                 sdata->vif.bss_conf.bssid = NULL;
3304                 break;
3305         case NL80211_IFTYPE_AP_VLAN:
3306 -               break;
3307         case NL80211_IFTYPE_P2P_DEVICE:
3308                 sdata->vif.bss_conf.bssid = sdata->vif.addr;
3309                 break;
3310 --- a/net/mac80211/mlme.c
3311 +++ b/net/mac80211/mlme.c
3312 @@ -886,8 +886,7 @@ static void ieee80211_chswitch_work(stru
3313         if (!ifmgd->associated)
3314                 goto out;
3315  
3316 -       ret = ieee80211_vif_change_channel(sdata, &local->csa_chandef,
3317 -                                          &changed);
3318 +       ret = ieee80211_vif_change_channel(sdata, &changed);
3319         if (ret) {
3320                 sdata_info(sdata,
3321                            "vif channel switch failed, disconnecting\n");
3322 @@ -897,7 +896,7 @@ static void ieee80211_chswitch_work(stru
3323         }
3324  
3325         if (!local->use_chanctx) {
3326 -               local->_oper_chandef = local->csa_chandef;
3327 +               local->_oper_chandef = sdata->csa_chandef;
3328                 /* Call "hw_config" only if doing sw channel switch.
3329                  * Otherwise update the channel directly
3330                  */
3331 @@ -908,7 +907,7 @@ static void ieee80211_chswitch_work(stru
3332         }
3333  
3334         /* XXX: shouldn't really modify cfg80211-owned data! */
3335 -       ifmgd->associated->channel = local->csa_chandef.chan;
3336 +       ifmgd->associated->channel = sdata->csa_chandef.chan;
3337  
3338         /* XXX: wait for a beacon first? */
3339         ieee80211_wake_queues_by_reason(&local->hw,
3340 @@ -1035,7 +1034,7 @@ ieee80211_sta_process_chanswitch(struct 
3341         }
3342         mutex_unlock(&local->chanctx_mtx);
3343  
3344 -       local->csa_chandef = csa_ie.chandef;
3345 +       sdata->csa_chandef = csa_ie.chandef;
3346  
3347         if (csa_ie.mode)
3348                 ieee80211_stop_queues_by_reason(&local->hw,
3349 @@ -1398,10 +1397,12 @@ void ieee80211_dfs_cac_timer_work(struct
3350         struct ieee80211_sub_if_data *sdata =
3351                 container_of(delayed_work, struct ieee80211_sub_if_data,
3352                              dfs_cac_timer_work);
3353 +       struct cfg80211_chan_def chandef = sdata->vif.bss_conf.chandef;
3354  
3355         ieee80211_vif_release_channel(sdata);
3356 -
3357 -       cfg80211_cac_event(sdata->dev, NL80211_RADAR_CAC_FINISHED, GFP_KERNEL);
3358 +       cfg80211_cac_event(sdata->dev, &chandef,
3359 +                          NL80211_RADAR_CAC_FINISHED,
3360 +                          GFP_KERNEL);
3361  }
3362  
3363  /* MLME */
3364 --- a/net/mac80211/rx.c
3365 +++ b/net/mac80211/rx.c
3366 @@ -729,9 +729,7 @@ static void ieee80211_release_reorder_fr
3367         lockdep_assert_held(&tid_agg_rx->reorder_lock);
3368  
3369         while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) {
3370 -               index = ieee80211_sn_sub(tid_agg_rx->head_seq_num,
3371 -                                        tid_agg_rx->ssn) %
3372 -                                                       tid_agg_rx->buf_size;
3373 +               index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
3374                 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
3375                                                 frames);
3376         }
3377 @@ -757,8 +755,7 @@ static void ieee80211_sta_reorder_releas
3378         lockdep_assert_held(&tid_agg_rx->reorder_lock);
3379  
3380         /* release the buffer until next missing frame */
3381 -       index = ieee80211_sn_sub(tid_agg_rx->head_seq_num,
3382 -                                tid_agg_rx->ssn) % tid_agg_rx->buf_size;
3383 +       index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
3384         if (!tid_agg_rx->reorder_buf[index] &&
3385             tid_agg_rx->stored_mpdu_num) {
3386                 /*
3387 @@ -793,15 +790,11 @@ static void ieee80211_sta_reorder_releas
3388         } else while (tid_agg_rx->reorder_buf[index]) {
3389                 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
3390                                                 frames);
3391 -               index = ieee80211_sn_sub(tid_agg_rx->head_seq_num,
3392 -                                        tid_agg_rx->ssn) %
3393 -                                                       tid_agg_rx->buf_size;
3394 +               index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
3395         }
3396  
3397         if (tid_agg_rx->stored_mpdu_num) {
3398 -               j = index = ieee80211_sn_sub(tid_agg_rx->head_seq_num,
3399 -                                            tid_agg_rx->ssn) %
3400 -                                                       tid_agg_rx->buf_size;
3401 +               j = index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
3402  
3403                 for (; j != (index - 1) % tid_agg_rx->buf_size;
3404                      j = (j + 1) % tid_agg_rx->buf_size) {
3405 @@ -861,8 +854,7 @@ static bool ieee80211_sta_manage_reorder
3406  
3407         /* Now the new frame is always in the range of the reordering buffer */
3408  
3409 -       index = ieee80211_sn_sub(mpdu_seq_num,
3410 -                                tid_agg_rx->ssn) % tid_agg_rx->buf_size;
3411 +       index = mpdu_seq_num % tid_agg_rx->buf_size;
3412  
3413         /* check if we already stored this frame */
3414         if (tid_agg_rx->reorder_buf[index]) {
3415 @@ -911,7 +903,8 @@ static void ieee80211_rx_reorder_ampdu(s
3416         u16 sc;
3417         u8 tid, ack_policy;
3418  
3419 -       if (!ieee80211_is_data_qos(hdr->frame_control))
3420 +       if (!ieee80211_is_data_qos(hdr->frame_control) ||
3421 +           is_multicast_ether_addr(hdr->addr1))
3422                 goto dont_reorder;
3423  
3424         /*
3425 --- a/net/mac80211/scan.c
3426 +++ b/net/mac80211/scan.c
3427 @@ -526,7 +526,7 @@ static int __ieee80211_start_scan(struct
3428                 ieee80211_hw_config(local, 0);
3429  
3430                 if ((req->channels[0]->flags &
3431 -                    IEEE80211_CHAN_PASSIVE_SCAN) ||
3432 +                    IEEE80211_CHAN_NO_IR) ||
3433                     !local->scan_req->n_ssids) {
3434                         next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
3435                 } else {
3436 @@ -572,7 +572,7 @@ ieee80211_scan_get_channel_time(struct i
3437          * TODO: channel switching also consumes quite some time,
3438          * add that delay as well to get a better estimation
3439          */
3440 -       if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
3441 +       if (chan->flags & IEEE80211_CHAN_NO_IR)
3442                 return IEEE80211_PASSIVE_CHANNEL_TIME;
3443         return IEEE80211_PROBE_DELAY + IEEE80211_CHANNEL_TIME;
3444  }
3445 @@ -696,7 +696,7 @@ static void ieee80211_scan_state_set_cha
3446          *
3447          * In any case, it is not necessary for a passive scan.
3448          */
3449 -       if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN ||
3450 +       if (chan->flags & IEEE80211_CHAN_NO_IR ||
3451             !local->scan_req->n_ssids) {
3452                 *next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
3453                 local->next_scan_state = SCAN_DECISION;
3454 @@ -881,7 +881,7 @@ int ieee80211_request_ibss_scan(struct i
3455                                 struct ieee80211_channel *tmp_ch =
3456                                     &local->hw.wiphy->bands[band]->channels[i];
3457  
3458 -                               if (tmp_ch->flags & (IEEE80211_CHAN_NO_IBSS |
3459 +                               if (tmp_ch->flags & (IEEE80211_CHAN_NO_IR |
3460                                                      IEEE80211_CHAN_DISABLED))
3461                                         continue;
3462  
3463 @@ -895,7 +895,7 @@ int ieee80211_request_ibss_scan(struct i
3464  
3465                 local->int_scan_req->n_channels = n_ch;
3466         } else {
3467 -               if (WARN_ON_ONCE(chan->flags & (IEEE80211_CHAN_NO_IBSS |
3468 +               if (WARN_ON_ONCE(chan->flags & (IEEE80211_CHAN_NO_IR |
3469                                                 IEEE80211_CHAN_DISABLED)))
3470                         goto unlock;
3471  
3472 --- a/net/mac80211/tx.c
3473 +++ b/net/mac80211/tx.c
3474 @@ -1728,8 +1728,7 @@ netdev_tx_t ieee80211_monitor_start_xmit
3475          * radar detection by itself. We can do that later by adding a
3476          * monitor flag interfaces used for AP support.
3477          */
3478 -       if ((chan->flags & (IEEE80211_CHAN_NO_IBSS | IEEE80211_CHAN_RADAR |
3479 -                           IEEE80211_CHAN_PASSIVE_SCAN)))
3480 +       if ((chan->flags & (IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_RADAR)))
3481                 goto fail_rcu;
3482  
3483         ieee80211_xmit(sdata, skb, chan->band);
3484 --- a/net/mac80211/util.c
3485 +++ b/net/mac80211/util.c
3486 @@ -2259,14 +2259,17 @@ u64 ieee80211_calculate_rx_timestamp(str
3487  void ieee80211_dfs_cac_cancel(struct ieee80211_local *local)
3488  {
3489         struct ieee80211_sub_if_data *sdata;
3490 +       struct cfg80211_chan_def chandef;
3491  
3492         mutex_lock(&local->iflist_mtx);
3493         list_for_each_entry(sdata, &local->interfaces, list) {
3494                 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
3495  
3496                 if (sdata->wdev.cac_started) {
3497 +                       chandef = sdata->vif.bss_conf.chandef;
3498                         ieee80211_vif_release_channel(sdata);
3499                         cfg80211_cac_event(sdata->dev,
3500 +                                          &chandef,
3501                                            NL80211_RADAR_CAC_ABORTED,
3502                                            GFP_KERNEL);
3503                 }
3504 @@ -2459,14 +2462,9 @@ int ieee80211_send_action_csa(struct iee
3505                           WLAN_EID_CHAN_SWITCH_PARAM_TX_RESTRICT : 0x00;
3506                 put_unaligned_le16(WLAN_REASON_MESH_CHAN, pos); /* Reason Cd */
3507                 pos += 2;
3508 -               if (!ifmsh->pre_value)
3509 -                       ifmsh->pre_value = 1;
3510 -               else
3511 -                       ifmsh->pre_value++;
3512                 pre_value = cpu_to_le16(ifmsh->pre_value);
3513                 memcpy(pos, &pre_value, 2);             /* Precedence Value */
3514                 pos += 2;
3515 -               ifmsh->chsw_init = true;
3516         }
3517  
3518         ieee80211_tx_skb(sdata, skb);
3519 --- a/net/wireless/chan.c
3520 +++ b/net/wireless/chan.c
3521 @@ -277,6 +277,32 @@ void cfg80211_set_dfs_state(struct wiphy
3522                                      width, dfs_state);
3523  }
3524  
3525 +static u32 cfg80211_get_start_freq(u32 center_freq,
3526 +                                  u32 bandwidth)
3527 +{
3528 +       u32 start_freq;
3529 +
3530 +       if (bandwidth <= 20)
3531 +               start_freq = center_freq;
3532 +       else
3533 +               start_freq = center_freq - bandwidth/2 + 10;
3534 +
3535 +       return start_freq;
3536 +}
3537 +
3538 +static u32 cfg80211_get_end_freq(u32 center_freq,
3539 +                                u32 bandwidth)
3540 +{
3541 +       u32 end_freq;
3542 +
3543 +       if (bandwidth <= 20)
3544 +               end_freq = center_freq;
3545 +       else
3546 +               end_freq = center_freq + bandwidth/2 - 10;
3547 +
3548 +       return end_freq;
3549 +}
3550 +
3551  static int cfg80211_get_chans_dfs_required(struct wiphy *wiphy,
3552                                             u32 center_freq,
3553                                             u32 bandwidth)
3554 @@ -284,13 +310,8 @@ static int cfg80211_get_chans_dfs_requir
3555         struct ieee80211_channel *c;
3556         u32 freq, start_freq, end_freq;
3557  
3558 -       if (bandwidth <= 20) {
3559 -               start_freq = center_freq;
3560 -               end_freq = center_freq;
3561 -       } else {
3562 -               start_freq = center_freq - bandwidth/2 + 10;
3563 -               end_freq = center_freq + bandwidth/2 - 10;
3564 -       }
3565 +       start_freq = cfg80211_get_start_freq(center_freq, bandwidth);
3566 +       end_freq = cfg80211_get_end_freq(center_freq, bandwidth);
3567  
3568         for (freq = start_freq; freq <= end_freq; freq += 20) {
3569                 c = ieee80211_get_channel(wiphy, freq);
3570 @@ -330,33 +351,159 @@ int cfg80211_chandef_dfs_required(struct
3571  }
3572  EXPORT_SYMBOL(cfg80211_chandef_dfs_required);
3573  
3574 -static bool cfg80211_secondary_chans_ok(struct wiphy *wiphy,
3575 -                                       u32 center_freq, u32 bandwidth,
3576 -                                       u32 prohibited_flags)
3577 +static int cfg80211_get_chans_dfs_usable(struct wiphy *wiphy,
3578 +                                        u32 center_freq,
3579 +                                        u32 bandwidth)
3580  {
3581         struct ieee80211_channel *c;
3582         u32 freq, start_freq, end_freq;
3583 +       int count = 0;
3584  
3585 -       if (bandwidth <= 20) {
3586 -               start_freq = center_freq;
3587 -               end_freq = center_freq;
3588 -       } else {
3589 -               start_freq = center_freq - bandwidth/2 + 10;
3590 -               end_freq = center_freq + bandwidth/2 - 10;
3591 +       start_freq = cfg80211_get_start_freq(center_freq, bandwidth);
3592 +       end_freq = cfg80211_get_end_freq(center_freq, bandwidth);
3593 +
3594 +       /*
3595 +        * Check entire range of channels for the bandwidth.
3596 +        * Check all channels are DFS channels (DFS_USABLE or
3597 +        * DFS_AVAILABLE). Return number of usable channels
3598 +        * (require CAC). Allow DFS and non-DFS channel mix.
3599 +        */
3600 +       for (freq = start_freq; freq <= end_freq; freq += 20) {
3601 +               c = ieee80211_get_channel(wiphy, freq);
3602 +               if (!c)
3603 +                       return -EINVAL;
3604 +
3605 +               if (c->flags & IEEE80211_CHAN_DISABLED)
3606 +                       return -EINVAL;
3607 +
3608 +               if (c->flags & IEEE80211_CHAN_RADAR) {
3609 +                       if (c->dfs_state == NL80211_DFS_UNAVAILABLE)
3610 +                               return -EINVAL;
3611 +
3612 +                       if (c->dfs_state == NL80211_DFS_USABLE)
3613 +                               count++;
3614 +               }
3615 +       }
3616 +
3617 +       return count;
3618 +}
3619 +
3620 +bool cfg80211_chandef_dfs_usable(struct wiphy *wiphy,
3621 +                                const struct cfg80211_chan_def *chandef)
3622 +{
3623 +       int width;
3624 +       int r1, r2 = 0;
3625 +
3626 +       if (WARN_ON(!cfg80211_chandef_valid(chandef)))
3627 +               return false;
3628 +
3629 +       width = cfg80211_chandef_get_width(chandef);
3630 +       if (width < 0)
3631 +               return false;
3632 +
3633 +       r1 = cfg80211_get_chans_dfs_usable(wiphy, chandef->center_freq1,
3634 +                                         width);
3635 +
3636 +       if (r1 < 0)
3637 +               return false;
3638 +
3639 +       switch (chandef->width) {
3640 +       case NL80211_CHAN_WIDTH_80P80:
3641 +               WARN_ON(!chandef->center_freq2);
3642 +               r2 = cfg80211_get_chans_dfs_usable(wiphy,
3643 +                                                  chandef->center_freq2,
3644 +                                                  width);
3645 +               if (r2 < 0)
3646 +                       return false;
3647 +               break;
3648 +       default:
3649 +               WARN_ON(chandef->center_freq2);
3650 +               break;
3651         }
3652  
3653 +       return (r1 + r2 > 0);
3654 +}
3655 +
3656 +
3657 +static bool cfg80211_get_chans_dfs_available(struct wiphy *wiphy,
3658 +                                            u32 center_freq,
3659 +                                            u32 bandwidth)
3660 +{
3661 +       struct ieee80211_channel *c;
3662 +       u32 freq, start_freq, end_freq;
3663 +
3664 +       start_freq = cfg80211_get_start_freq(center_freq, bandwidth);
3665 +       end_freq = cfg80211_get_end_freq(center_freq, bandwidth);
3666 +
3667 +       /*
3668 +        * Check entire range of channels for the bandwidth.
3669 +        * If any channel in between is disabled or has not
3670 +        * had gone through CAC return false
3671 +        */
3672         for (freq = start_freq; freq <= end_freq; freq += 20) {
3673                 c = ieee80211_get_channel(wiphy, freq);
3674                 if (!c)
3675                         return false;
3676  
3677 -               /* check for radar flags */
3678 -               if ((prohibited_flags & c->flags & IEEE80211_CHAN_RADAR) &&
3679 +               if (c->flags & IEEE80211_CHAN_DISABLED)
3680 +                       return false;
3681 +
3682 +               if ((c->flags & IEEE80211_CHAN_RADAR)  &&
3683                     (c->dfs_state != NL80211_DFS_AVAILABLE))
3684                         return false;
3685 +       }
3686 +
3687 +       return true;
3688 +}
3689 +
3690 +static bool cfg80211_chandef_dfs_available(struct wiphy *wiphy,
3691 +                               const struct cfg80211_chan_def *chandef)
3692 +{
3693 +       int width;
3694 +       int r;
3695 +
3696 +       if (WARN_ON(!cfg80211_chandef_valid(chandef)))
3697 +               return false;
3698  
3699 -               /* check for the other flags */
3700 -               if (c->flags & prohibited_flags & ~IEEE80211_CHAN_RADAR)
3701 +       width = cfg80211_chandef_get_width(chandef);
3702 +       if (width < 0)
3703 +               return false;
3704 +
3705 +       r = cfg80211_get_chans_dfs_available(wiphy, chandef->center_freq1,
3706 +                                            width);
3707 +
3708 +       /* If any of channels unavailable for cf1 just return */
3709 +       if (!r)
3710 +               return r;
3711 +
3712 +       switch (chandef->width) {
3713 +       case NL80211_CHAN_WIDTH_80P80:
3714 +               WARN_ON(!chandef->center_freq2);
3715 +               r = cfg80211_get_chans_dfs_available(wiphy,
3716 +                                                    chandef->center_freq2,
3717 +                                                    width);
3718 +       default:
3719 +               WARN_ON(chandef->center_freq2);
3720 +               break;
3721 +       }
3722 +
3723 +       return r;
3724 +}
3725 +
3726 +
3727 +static bool cfg80211_secondary_chans_ok(struct wiphy *wiphy,
3728 +                                       u32 center_freq, u32 bandwidth,
3729 +                                       u32 prohibited_flags)
3730 +{
3731 +       struct ieee80211_channel *c;
3732 +       u32 freq, start_freq, end_freq;
3733 +
3734 +       start_freq = cfg80211_get_start_freq(center_freq, bandwidth);
3735 +       end_freq = cfg80211_get_end_freq(center_freq, bandwidth);
3736 +
3737 +       for (freq = start_freq; freq <= end_freq; freq += 20) {
3738 +               c = ieee80211_get_channel(wiphy, freq);
3739 +               if (!c || c->flags & prohibited_flags)
3740                         return false;
3741         }
3742  
3743 @@ -462,14 +609,19 @@ bool cfg80211_reg_can_beacon(struct wiph
3744                              struct cfg80211_chan_def *chandef)
3745  {
3746         bool res;
3747 +       u32 prohibited_flags = IEEE80211_CHAN_DISABLED |
3748 +                              IEEE80211_CHAN_NO_IR |
3749 +                              IEEE80211_CHAN_RADAR;
3750  
3751         trace_cfg80211_reg_can_beacon(wiphy, chandef);
3752  
3753 -       res = cfg80211_chandef_usable(wiphy, chandef,
3754 -                                     IEEE80211_CHAN_DISABLED |
3755 -                                     IEEE80211_CHAN_PASSIVE_SCAN |
3756 -                                     IEEE80211_CHAN_NO_IBSS |
3757 -                                     IEEE80211_CHAN_RADAR);
3758 +       if (cfg80211_chandef_dfs_required(wiphy, chandef) > 0 &&
3759 +           cfg80211_chandef_dfs_available(wiphy, chandef)) {
3760 +               /* We can skip IEEE80211_CHAN_NO_IR if chandef dfs available */
3761 +               prohibited_flags = IEEE80211_CHAN_DISABLED;
3762 +       }
3763 +
3764 +       res = cfg80211_chandef_usable(wiphy, chandef, prohibited_flags);
3765  
3766         trace_cfg80211_return_bool(res);
3767         return res;
3768 --- a/net/wireless/core.h
3769 +++ b/net/wireless/core.h
3770 @@ -382,6 +382,19 @@ int cfg80211_can_use_iftype_chan(struct 
3771                                  enum cfg80211_chan_mode chanmode,
3772                                  u8 radar_detect);
3773  
3774 +/**
3775 + * cfg80211_chandef_dfs_usable - checks if chandef is DFS usable
3776 + * @wiphy: the wiphy to validate against
3777 + * @chandef: the channel definition to check
3778 + *
3779 + * Checks if chandef is usable and we can/need start CAC on such channel.
3780 + *
3781 + * Return: Return true if all channels available and at least
3782 + *        one channel require CAC (NL80211_DFS_USABLE)
3783 + */
3784 +bool cfg80211_chandef_dfs_usable(struct wiphy *wiphy,
3785 +                                const struct cfg80211_chan_def *chandef);
3786 +
3787  void cfg80211_set_dfs_state(struct wiphy *wiphy,
3788                             const struct cfg80211_chan_def *chandef,
3789                             enum nl80211_dfs_state dfs_state);
3790 --- a/net/wireless/genregdb.awk
3791 +++ b/net/wireless/genregdb.awk
3792 @@ -107,10 +107,13 @@ active && /^[ \t]*\(/ {
3793                 } else if (flagarray[arg] == "PTMP-ONLY") {
3794                         flags = flags "\n\t\t\tNL80211_RRF_PTMP_ONLY | "
3795                 } else if (flagarray[arg] == "PASSIVE-SCAN") {
3796 -                       flags = flags "\n\t\t\tNL80211_RRF_PASSIVE_SCAN | "
3797 +                       flags = flags "\n\t\t\tNL80211_RRF_NO_IR | "
3798                 } else if (flagarray[arg] == "NO-IBSS") {
3799 -                       flags = flags "\n\t\t\tNL80211_RRF_NO_IBSS | "
3800 +                       flags = flags "\n\t\t\tNL80211_RRF_NO_IR | "
3801 +               } else if (flagarray[arg] == "NO-IR") {
3802 +                       flags = flags "\n\t\t\tNL80211_RRF_NO_IR | "
3803                 }
3804 +
3805         }
3806         flags = flags "0"
3807         printf "\t\tREG_RULE(%d, %d, %d, %d, %d, %s),\n", start, end, bw, gain, power, flags
3808 --- a/net/wireless/ibss.c
3809 +++ b/net/wireless/ibss.c
3810 @@ -274,7 +274,7 @@ int cfg80211_ibss_wext_join(struct cfg80
3811  
3812                         for (i = 0; i < sband->n_channels; i++) {
3813                                 chan = &sband->channels[i];
3814 -                               if (chan->flags & IEEE80211_CHAN_NO_IBSS)
3815 +                               if (chan->flags & IEEE80211_CHAN_NO_IR)
3816                                         continue;
3817                                 if (chan->flags & IEEE80211_CHAN_DISABLED)
3818                                         continue;
3819 @@ -345,7 +345,7 @@ int cfg80211_ibss_wext_siwfreq(struct ne
3820                 chan = ieee80211_get_channel(wdev->wiphy, freq);
3821                 if (!chan)
3822                         return -EINVAL;
3823 -               if (chan->flags & IEEE80211_CHAN_NO_IBSS ||
3824 +               if (chan->flags & IEEE80211_CHAN_NO_IR ||
3825                     chan->flags & IEEE80211_CHAN_DISABLED)
3826                         return -EINVAL;
3827         }
3828 --- a/net/wireless/mesh.c
3829 +++ b/net/wireless/mesh.c
3830 @@ -141,8 +141,7 @@ int __cfg80211_join_mesh(struct cfg80211
3831  
3832                         for (i = 0; i < sband->n_channels; i++) {
3833                                 chan = &sband->channels[i];
3834 -                               if (chan->flags & (IEEE80211_CHAN_NO_IBSS |
3835 -                                                  IEEE80211_CHAN_PASSIVE_SCAN |
3836 +                               if (chan->flags & (IEEE80211_CHAN_NO_IR |
3837                                                    IEEE80211_CHAN_DISABLED |
3838                                                    IEEE80211_CHAN_RADAR))
3839                                         continue;
3840 --- a/net/wireless/mlme.c
3841 +++ b/net/wireless/mlme.c
3842 @@ -763,12 +763,12 @@ void cfg80211_radar_event(struct wiphy *
3843  EXPORT_SYMBOL(cfg80211_radar_event);
3844  
3845  void cfg80211_cac_event(struct net_device *netdev,
3846 +                       const struct cfg80211_chan_def *chandef,
3847                         enum nl80211_radar_event event, gfp_t gfp)
3848  {
3849         struct wireless_dev *wdev = netdev->ieee80211_ptr;
3850         struct wiphy *wiphy = wdev->wiphy;
3851         struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
3852 -       struct cfg80211_chan_def chandef;
3853         unsigned long timeout;
3854  
3855         trace_cfg80211_cac_event(netdev, event);
3856 @@ -779,14 +779,12 @@ void cfg80211_cac_event(struct net_devic
3857         if (WARN_ON(!wdev->channel))
3858                 return;
3859  
3860 -       cfg80211_chandef_create(&chandef, wdev->channel, NL80211_CHAN_NO_HT);
3861 -
3862         switch (event) {
3863         case NL80211_RADAR_CAC_FINISHED:
3864                 timeout = wdev->cac_start_time +
3865                           msecs_to_jiffies(IEEE80211_DFS_MIN_CAC_TIME_MS);
3866                 WARN_ON(!time_after_eq(jiffies, timeout));
3867 -               cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_AVAILABLE);
3868 +               cfg80211_set_dfs_state(wiphy, chandef, NL80211_DFS_AVAILABLE);
3869                 break;
3870         case NL80211_RADAR_CAC_ABORTED:
3871                 break;
3872 @@ -796,6 +794,6 @@ void cfg80211_cac_event(struct net_devic
3873         }
3874         wdev->cac_started = false;
3875  
3876 -       nl80211_radar_notify(rdev, &chandef, event, netdev, gfp);
3877 +       nl80211_radar_notify(rdev, chandef, event, netdev, gfp);
3878  }
3879  EXPORT_SYMBOL(cfg80211_cac_event);
3880 --- a/net/wireless/nl80211.c
3881 +++ b/net/wireless/nl80211.c
3882 @@ -545,12 +545,12 @@ static int nl80211_msg_put_channel(struc
3883         if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
3884             nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
3885                 goto nla_put_failure;
3886 -       if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
3887 -           nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
3888 -               goto nla_put_failure;
3889 -       if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
3890 -           nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
3891 -               goto nla_put_failure;
3892 +       if (chan->flags & IEEE80211_CHAN_NO_IR) {
3893 +               if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
3894 +                       goto nla_put_failure;
3895 +               if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
3896 +                       goto nla_put_failure;
3897 +       }
3898         if (chan->flags & IEEE80211_CHAN_RADAR) {
3899                 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
3900                         goto nla_put_failure;
3901 @@ -1229,7 +1229,8 @@ static int nl80211_send_wiphy(struct cfg
3902                     nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
3903                         goto nla_put_failure;
3904                 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
3905 -                   nla_put_flag(msg, WIPHY_FLAG_SUPPORTS_5_10_MHZ))
3906 +                   (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
3907 +                    nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
3908                         goto nla_put_failure;
3909  
3910                 state->split_start++;
3911 @@ -2170,7 +2171,7 @@ static inline u64 wdev_id(struct wireles
3912  }
3913  
3914  static int nl80211_send_chandef(struct sk_buff *msg,
3915 -                                struct cfg80211_chan_def *chandef)
3916 +                               const struct cfg80211_chan_def *chandef)
3917  {
3918         WARN_ON(!cfg80211_chandef_valid(chandef));
3919  
3920 @@ -3219,6 +3220,7 @@ static int nl80211_start_ap(struct sk_bu
3921                         return PTR_ERR(params.acl);
3922         }
3923  
3924 +       wdev_lock(wdev);
3925         err = rdev_start_ap(rdev, dev, &params);
3926         if (!err) {
3927                 wdev->preset_chandef = params.chandef;
3928 @@ -3227,6 +3229,7 @@ static int nl80211_start_ap(struct sk_bu
3929                 wdev->ssid_len = params.ssid_len;
3930                 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
3931         }
3932 +       wdev_unlock(wdev);
3933  
3934         kfree(params.acl);
3935  
3936 @@ -3255,7 +3258,11 @@ static int nl80211_set_beacon(struct sk_
3937         if (err)
3938                 return err;
3939  
3940 -       return rdev_change_beacon(rdev, dev, &params);
3941 +       wdev_lock(wdev);
3942 +       err = rdev_change_beacon(rdev, dev, &params);
3943 +       wdev_unlock(wdev);
3944 +
3945 +       return err;
3946  }
3947  
3948  static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
3949 @@ -4461,7 +4468,9 @@ static int nl80211_set_bss(struct sk_buf
3950  {
3951         struct cfg80211_registered_device *rdev = info->user_ptr[0];
3952         struct net_device *dev = info->user_ptr[1];
3953 +       struct wireless_dev *wdev = dev->ieee80211_ptr;
3954         struct bss_parameters params;
3955 +       int err;
3956  
3957         memset(&params, 0, sizeof(params));
3958         /* default to not changing parameters */
3959 @@ -4527,7 +4536,11 @@ static int nl80211_set_bss(struct sk_buf
3960             dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3961                 return -EOPNOTSUPP;
3962  
3963 -       return rdev_change_bss(rdev, dev, &params);
3964 +       wdev_lock(wdev);
3965 +       err = rdev_change_bss(rdev, dev, &params);
3966 +       wdev_unlock(wdev);
3967 +
3968 +       return err;
3969  }
3970  
3971  static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
3972 @@ -5653,7 +5666,7 @@ static int nl80211_start_radar_detection
3973         if (err == 0)
3974                 return -EINVAL;
3975  
3976 -       if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
3977 +       if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
3978                 return -EINVAL;
3979  
3980         if (!rdev->ops->start_radar_detection)
3981 @@ -5793,7 +5806,11 @@ skip_beacons:
3982         if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
3983                 params.block_tx = true;
3984  
3985 -       return rdev_channel_switch(rdev, dev, &params);
3986 +       wdev_lock(wdev);
3987 +       err = rdev_channel_switch(rdev, dev, &params);
3988 +       wdev_unlock(wdev);
3989 +
3990 +       return err;
3991  }
3992  
3993  static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
3994 @@ -10809,21 +10826,18 @@ void cfg80211_ch_switch_notify(struct ne
3995         struct wiphy *wiphy = wdev->wiphy;
3996         struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
3997  
3998 -       trace_cfg80211_ch_switch_notify(dev, chandef);
3999 +       ASSERT_WDEV_LOCK(wdev);
4000  
4001 -       wdev_lock(wdev);
4002 +       trace_cfg80211_ch_switch_notify(dev, chandef);
4003  
4004         if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
4005                     wdev->iftype != NL80211_IFTYPE_P2P_GO &&
4006                     wdev->iftype != NL80211_IFTYPE_ADHOC &&
4007                     wdev->iftype != NL80211_IFTYPE_MESH_POINT))
4008 -               goto out;
4009 +               return;
4010  
4011         wdev->channel = chandef->chan;
4012         nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
4013 -out:
4014 -       wdev_unlock(wdev);
4015 -       return;
4016  }
4017  EXPORT_SYMBOL(cfg80211_ch_switch_notify);
4018  
4019 @@ -10882,7 +10896,7 @@ EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
4020  
4021  void
4022  nl80211_radar_notify(struct cfg80211_registered_device *rdev,
4023 -                    struct cfg80211_chan_def *chandef,
4024 +                    const struct cfg80211_chan_def *chandef,
4025                      enum nl80211_radar_event event,
4026                      struct net_device *netdev, gfp_t gfp)
4027  {
4028 --- a/net/wireless/nl80211.h
4029 +++ b/net/wireless/nl80211.h
4030 @@ -70,7 +70,7 @@ int nl80211_send_mgmt(struct cfg80211_re
4031  
4032  void
4033  nl80211_radar_notify(struct cfg80211_registered_device *rdev,
4034 -                    struct cfg80211_chan_def *chandef,
4035 +                    const struct cfg80211_chan_def *chandef,
4036                      enum nl80211_radar_event event,
4037                      struct net_device *netdev, gfp_t gfp);
4038  
4039 --- a/net/wireless/reg.c
4040 +++ b/net/wireless/reg.c
4041 @@ -163,35 +163,29 @@ static const struct ieee80211_regdomain 
4042                 REG_RULE(2412-10, 2462+10, 40, 6, 20, 0),
4043                 /* IEEE 802.11b/g, channels 12..13. */
4044                 REG_RULE(2467-10, 2472+10, 40, 6, 20,
4045 -                       NL80211_RRF_PASSIVE_SCAN |
4046 -                       NL80211_RRF_NO_IBSS),
4047 +                       NL80211_RRF_NO_IR),
4048                 /* IEEE 802.11 channel 14 - Only JP enables
4049                  * this and for 802.11b only */
4050                 REG_RULE(2484-10, 2484+10, 20, 6, 20,
4051 -                       NL80211_RRF_PASSIVE_SCAN |
4052 -                       NL80211_RRF_NO_IBSS |
4053 +                       NL80211_RRF_NO_IR |
4054                         NL80211_RRF_NO_OFDM),
4055                 /* IEEE 802.11a, channel 36..48 */
4056                 REG_RULE(5180-10, 5240+10, 160, 6, 20,
4057 -                        NL80211_RRF_PASSIVE_SCAN |
4058 -                        NL80211_RRF_NO_IBSS),
4059 +                        NL80211_RRF_NO_IR),
4060  
4061                 /* IEEE 802.11a, channel 52..64 - DFS required */
4062                 REG_RULE(5260-10, 5320+10, 160, 6, 20,
4063 -                       NL80211_RRF_PASSIVE_SCAN |
4064 -                       NL80211_RRF_NO_IBSS |
4065 +                       NL80211_RRF_NO_IR |
4066                         NL80211_RRF_DFS),
4067  
4068                 /* IEEE 802.11a, channel 100..144 - DFS required */
4069                 REG_RULE(5500-10, 5720+10, 160, 6, 20,
4070 -                       NL80211_RRF_PASSIVE_SCAN |
4071 -                       NL80211_RRF_NO_IBSS |
4072 +                       NL80211_RRF_NO_IR |
4073                         NL80211_RRF_DFS),
4074  
4075                 /* IEEE 802.11a, channel 149..165 */
4076                 REG_RULE(5745-10, 5825+10, 80, 6, 20,
4077 -                       NL80211_RRF_PASSIVE_SCAN |
4078 -                       NL80211_RRF_NO_IBSS),
4079 +                       NL80211_RRF_NO_IR),
4080  
4081                 /* IEEE 802.11ad (60gHz), channels 1..3 */
4082                 REG_RULE(56160+2160*1-1080, 56160+2160*3+1080, 2160, 0, 0, 0),
4083 @@ -698,10 +692,8 @@ regdom_intersect(const struct ieee80211_
4084  static u32 map_regdom_flags(u32 rd_flags)
4085  {
4086         u32 channel_flags = 0;
4087 -       if (rd_flags & NL80211_RRF_PASSIVE_SCAN)
4088 -               channel_flags |= IEEE80211_CHAN_PASSIVE_SCAN;
4089 -       if (rd_flags & NL80211_RRF_NO_IBSS)
4090 -               channel_flags |= IEEE80211_CHAN_NO_IBSS;
4091 +       if (rd_flags & NL80211_RRF_NO_IR_ALL)
4092 +               channel_flags |= IEEE80211_CHAN_NO_IR;
4093         if (rd_flags & NL80211_RRF_DFS)
4094                 channel_flags |= IEEE80211_CHAN_RADAR;
4095         if (rd_flags & NL80211_RRF_NO_OFDM)
4096 @@ -1066,13 +1058,8 @@ static void handle_reg_beacon(struct wip
4097         chan_before.center_freq = chan->center_freq;
4098         chan_before.flags = chan->flags;
4099  
4100 -       if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) {
4101 -               chan->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
4102 -               channel_changed = true;
4103 -       }
4104 -
4105 -       if (chan->flags & IEEE80211_CHAN_NO_IBSS) {
4106 -               chan->flags &= ~IEEE80211_CHAN_NO_IBSS;
4107 +       if (chan->flags & IEEE80211_CHAN_NO_IR) {
4108 +               chan->flags &= ~IEEE80211_CHAN_NO_IR;
4109                 channel_changed = true;
4110         }
4111  
4112 --- /dev/null
4113 +++ b/drivers/net/wireless/ath/ath9k/ar9003_wow.c
4114 @@ -0,0 +1,422 @@
4115 +/*
4116 + * Copyright (c) 2012 Qualcomm Atheros, Inc.
4117 + *
4118 + * Permission to use, copy, modify, and/or distribute this software for any
4119 + * purpose with or without fee is hereby granted, provided that the above
4120 + * copyright notice and this permission notice appear in all copies.
4121 + *
4122 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
4123 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
4124 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
4125 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
4126 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
4127 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
4128 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
4129 + */
4130 +
4131 +#include <linux/export.h>
4132 +#include "ath9k.h"
4133 +#include "reg.h"
4134 +#include "hw-ops.h"
4135 +
4136 +const char *ath9k_hw_wow_event_to_string(u32 wow_event)
4137 +{
4138 +       if (wow_event & AH_WOW_MAGIC_PATTERN_EN)
4139 +               return "Magic pattern";
4140 +       if (wow_event & AH_WOW_USER_PATTERN_EN)
4141 +               return "User pattern";
4142 +       if (wow_event & AH_WOW_LINK_CHANGE)
4143 +               return "Link change";
4144 +       if (wow_event & AH_WOW_BEACON_MISS)
4145 +               return "Beacon miss";
4146 +
4147 +       return  "unknown reason";
4148 +}
4149 +EXPORT_SYMBOL(ath9k_hw_wow_event_to_string);
4150 +
4151 +static void ath9k_hw_set_powermode_wow_sleep(struct ath_hw *ah)
4152 +{
4153 +       struct ath_common *common = ath9k_hw_common(ah);
4154 +
4155 +       REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
4156 +
4157 +       /* set rx disable bit */
4158 +       REG_WRITE(ah, AR_CR, AR_CR_RXD);
4159 +
4160 +       if (!ath9k_hw_wait(ah, AR_CR, AR_CR_RXE, 0, AH_WAIT_TIMEOUT)) {
4161 +               ath_err(common, "Failed to stop Rx DMA in 10ms AR_CR=0x%08x AR_DIAG_SW=0x%08x\n",
4162 +                       REG_READ(ah, AR_CR), REG_READ(ah, AR_DIAG_SW));
4163 +               return;
4164 +       }
4165 +
4166 +       REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_ON_INT);
4167 +}
4168 +
4169 +static void ath9k_wow_create_keep_alive_pattern(struct ath_hw *ah)
4170 +{
4171 +       struct ath_common *common = ath9k_hw_common(ah);
4172 +       u8 sta_mac_addr[ETH_ALEN], ap_mac_addr[ETH_ALEN];
4173 +       u32 ctl[13] = {0};
4174 +       u32 data_word[KAL_NUM_DATA_WORDS];
4175 +       u8 i;
4176 +       u32 wow_ka_data_word0;
4177 +
4178 +       memcpy(sta_mac_addr, common->macaddr, ETH_ALEN);
4179 +       memcpy(ap_mac_addr, common->curbssid, ETH_ALEN);
4180 +
4181 +       /* set the transmit buffer */
4182 +       ctl[0] = (KAL_FRAME_LEN | (MAX_RATE_POWER << 16));
4183 +       ctl[1] = 0;
4184 +       ctl[3] = 0xb;   /* OFDM_6M hardware value for this rate */
4185 +       ctl[4] = 0;
4186 +       ctl[7] = (ah->txchainmask) << 2;
4187 +       ctl[2] = 0xf << 16; /* tx_tries 0 */
4188 +
4189 +       for (i = 0; i < KAL_NUM_DESC_WORDS; i++)
4190 +               REG_WRITE(ah, (AR_WOW_KA_DESC_WORD2 + i * 4), ctl[i]);
4191 +
4192 +       REG_WRITE(ah, (AR_WOW_KA_DESC_WORD2 + i * 4), ctl[i]);
4193 +
4194 +       data_word[0] = (KAL_FRAME_TYPE << 2) | (KAL_FRAME_SUB_TYPE << 4) |
4195 +                      (KAL_TO_DS << 8) | (KAL_DURATION_ID << 16);
4196 +       data_word[1] = (ap_mac_addr[3] << 24) | (ap_mac_addr[2] << 16) |
4197 +                      (ap_mac_addr[1] << 8) | (ap_mac_addr[0]);
4198 +       data_word[2] = (sta_mac_addr[1] << 24) | (sta_mac_addr[0] << 16) |
4199 +                      (ap_mac_addr[5] << 8) | (ap_mac_addr[4]);
4200 +       data_word[3] = (sta_mac_addr[5] << 24) | (sta_mac_addr[4] << 16) |
4201 +                      (sta_mac_addr[3] << 8) | (sta_mac_addr[2]);
4202 +       data_word[4] = (ap_mac_addr[3] << 24) | (ap_mac_addr[2] << 16) |
4203 +                      (ap_mac_addr[1] << 8) | (ap_mac_addr[0]);
4204 +       data_word[5] = (ap_mac_addr[5] << 8) | (ap_mac_addr[4]);
4205 +
4206 +       if (AR_SREV_9462_20(ah)) {
4207 +               /* AR9462 2.0 has an extra descriptor word (time based
4208 +                * discard) compared to other chips */
4209 +               REG_WRITE(ah, (AR_WOW_KA_DESC_WORD2 + (12 * 4)), 0);
4210 +               wow_ka_data_word0 = AR_WOW_TXBUF(13);
4211 +       } else {
4212 +               wow_ka_data_word0 = AR_WOW_TXBUF(12);
4213 +       }
4214 +
4215 +       for (i = 0; i < KAL_NUM_DATA_WORDS; i++)
4216 +               REG_WRITE(ah, (wow_ka_data_word0 + i*4), data_word[i]);
4217 +
4218 +}
4219 +
4220 +void ath9k_hw_wow_apply_pattern(struct ath_hw *ah, u8 *user_pattern,
4221 +                               u8 *user_mask, int pattern_count,
4222 +                               int pattern_len)
4223 +{
4224 +       int i;
4225 +       u32 pattern_val, mask_val;
4226 +       u32 set, clr;
4227 +
4228 +       /* FIXME: should check count by querying the hardware capability */
4229 +       if (pattern_count >= MAX_NUM_PATTERN)
4230 +               return;
4231 +
4232 +       REG_SET_BIT(ah, AR_WOW_PATTERN, BIT(pattern_count));
4233 +
4234 +       /* set the registers for pattern */
4235 +       for (i = 0; i < MAX_PATTERN_SIZE; i += 4) {
4236 +               memcpy(&pattern_val, user_pattern, 4);
4237 +               REG_WRITE(ah, (AR_WOW_TB_PATTERN(pattern_count) + i),
4238 +                         pattern_val);
4239 +               user_pattern += 4;
4240 +       }
4241 +
4242 +       /* set the registers for mask */
4243 +       for (i = 0; i < MAX_PATTERN_MASK_SIZE; i += 4) {
4244 +               memcpy(&mask_val, user_mask, 4);
4245 +               REG_WRITE(ah, (AR_WOW_TB_MASK(pattern_count) + i), mask_val);
4246 +               user_mask += 4;
4247 +       }
4248 +
4249 +       /* set the pattern length to be matched
4250 +        *
4251 +        * AR_WOW_LENGTH1_REG1
4252 +        * bit 31:24 pattern 0 length
4253 +        * bit 23:16 pattern 1 length
4254 +        * bit 15:8 pattern 2 length
4255 +        * bit 7:0 pattern 3 length
4256 +        *
4257 +        * AR_WOW_LENGTH1_REG2
4258 +        * bit 31:24 pattern 4 length
4259 +        * bit 23:16 pattern 5 length
4260 +        * bit 15:8 pattern 6 length
4261 +        * bit 7:0 pattern 7 length
4262 +        *
4263 +        * the below logic writes out the new
4264 +        * pattern length for the corresponding
4265 +        * pattern_count, while masking out the
4266 +        * other fields
4267 +        */
4268 +
4269 +       ah->wow_event_mask |= BIT(pattern_count + AR_WOW_PAT_FOUND_SHIFT);
4270 +
4271 +       if (pattern_count < 4) {
4272 +               /* Pattern 0-3 uses AR_WOW_LENGTH1 register */
4273 +               set = (pattern_len & AR_WOW_LENGTH_MAX) <<
4274 +                      AR_WOW_LEN1_SHIFT(pattern_count);
4275 +               clr = AR_WOW_LENGTH1_MASK(pattern_count);
4276 +               REG_RMW(ah, AR_WOW_LENGTH1, set, clr);
4277 +       } else {
4278 +               /* Pattern 4-7 uses AR_WOW_LENGTH2 register */
4279 +               set = (pattern_len & AR_WOW_LENGTH_MAX) <<
4280 +                      AR_WOW_LEN2_SHIFT(pattern_count);
4281 +               clr = AR_WOW_LENGTH2_MASK(pattern_count);
4282 +               REG_RMW(ah, AR_WOW_LENGTH2, set, clr);
4283 +       }
4284 +
4285 +}
4286 +EXPORT_SYMBOL(ath9k_hw_wow_apply_pattern);
4287 +
4288 +u32 ath9k_hw_wow_wakeup(struct ath_hw *ah)
4289 +{
4290 +       u32 wow_status = 0;
4291 +       u32 val = 0, rval;
4292 +
4293 +       /*
4294 +        * read the WoW status register to know
4295 +        * the wakeup reason
4296 +        */
4297 +       rval = REG_READ(ah, AR_WOW_PATTERN);
4298 +       val = AR_WOW_STATUS(rval);
4299 +
4300 +       /*
4301 +        * mask only the WoW events that we have enabled. Sometimes
4302 +        * we have spurious WoW events from the AR_WOW_PATTERN
4303 +        * register. This mask will clean it up.
4304 +        */
4305 +
4306 +       val &= ah->wow_event_mask;
4307 +
4308 +       if (val) {
4309 +               if (val & AR_WOW_MAGIC_PAT_FOUND)
4310 +                       wow_status |= AH_WOW_MAGIC_PATTERN_EN;
4311 +               if (AR_WOW_PATTERN_FOUND(val))
4312 +                       wow_status |= AH_WOW_USER_PATTERN_EN;
4313 +               if (val & AR_WOW_KEEP_ALIVE_FAIL)
4314 +                       wow_status |= AH_WOW_LINK_CHANGE;
4315 +               if (val & AR_WOW_BEACON_FAIL)
4316 +                       wow_status |= AH_WOW_BEACON_MISS;
4317 +       }
4318 +
4319 +       /*
4320 +        * set and clear WOW_PME_CLEAR registers for the chip to
4321 +        * generate next wow signal.
4322 +        * disable D3 before accessing other registers ?
4323 +        */
4324 +
4325 +       /* do we need to check the bit value 0x01000000 (7-10) ?? */
4326 +       REG_RMW(ah, AR_PCIE_PM_CTRL, AR_PMCTRL_WOW_PME_CLR,
4327 +               AR_PMCTRL_PWR_STATE_D1D3);
4328 +
4329 +       /*
4330 +        * clear all events
4331 +        */
4332 +       REG_WRITE(ah, AR_WOW_PATTERN,
4333 +                 AR_WOW_CLEAR_EVENTS(REG_READ(ah, AR_WOW_PATTERN)));
4334 +
4335 +       /*
4336 +        * restore the beacon threshold to init value
4337 +        */
4338 +       REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
4339 +
4340 +       /*
4341 +        * Restore the way the PCI-E reset, Power-On-Reset, external
4342 +        * PCIE_POR_SHORT pins are tied to its original value.
4343 +        * Previously just before WoW sleep, we untie the PCI-E
4344 +        * reset to our Chip's Power On Reset so that any PCI-E
4345 +        * reset from the bus will not reset our chip
4346 +        */
4347 +       if (ah->is_pciexpress)
4348 +               ath9k_hw_configpcipowersave(ah, false);
4349 +
4350 +       ah->wow_event_mask = 0;
4351 +
4352 +       return wow_status;
4353 +}
4354 +EXPORT_SYMBOL(ath9k_hw_wow_wakeup);
4355 +
4356 +void ath9k_hw_wow_enable(struct ath_hw *ah, u32 pattern_enable)
4357 +{
4358 +       u32 wow_event_mask;
4359 +       u32 set, clr;
4360 +
4361 +       /*
4362 +        * wow_event_mask is a mask to the AR_WOW_PATTERN register to
4363 +        * indicate which WoW events we have enabled. The WoW events
4364 +        * are from the 'pattern_enable' in this function and
4365 +        * 'pattern_count' of ath9k_hw_wow_apply_pattern()
4366 +        */
4367 +       wow_event_mask = ah->wow_event_mask;
4368 +
4369 +       /*
4370 +        * Untie Power-on-Reset from the PCI-E-Reset. When we are in
4371 +        * WOW sleep, we do want the Reset from the PCI-E to disturb
4372 +        * our hw state
4373 +        */
4374 +       if (ah->is_pciexpress) {
4375 +               /*
4376 +                * we need to untie the internal POR (power-on-reset)
4377 +                * to the external PCI-E reset. We also need to tie
4378 +                * the PCI-E Phy reset to the PCI-E reset.
4379 +                */
4380 +               set = AR_WA_RESET_EN | AR_WA_POR_SHORT;
4381 +               clr = AR_WA_UNTIE_RESET_EN | AR_WA_D3_L1_DISABLE;
4382 +               REG_RMW(ah, AR_WA, set, clr);
4383 +       }
4384 +
4385 +       /*
4386 +        * set the power states appropriately and enable PME
4387 +        */
4388 +       set = AR_PMCTRL_HOST_PME_EN | AR_PMCTRL_PWR_PM_CTRL_ENA |
4389 +             AR_PMCTRL_AUX_PWR_DET | AR_PMCTRL_WOW_PME_CLR;
4390 +
4391 +       /*
4392 +        * set and clear WOW_PME_CLEAR registers for the chip
4393 +        * to generate next wow signal.
4394 +        */
4395 +       REG_SET_BIT(ah, AR_PCIE_PM_CTRL, set);
4396 +       clr = AR_PMCTRL_WOW_PME_CLR;
4397 +       REG_CLR_BIT(ah, AR_PCIE_PM_CTRL, clr);
4398 +
4399 +       /*
4400 +        * Setup for:
4401 +        *      - beacon misses
4402 +        *      - magic pattern
4403 +        *      - keep alive timeout
4404 +        *      - pattern matching
4405 +        */
4406 +
4407 +       /*
4408 +        * Program default values for pattern backoff, aifs/slot/KAL count,
4409 +        * beacon miss timeout, KAL timeout, etc.
4410 +        */
4411 +       set = AR_WOW_BACK_OFF_SHIFT(AR_WOW_PAT_BACKOFF);
4412 +       REG_SET_BIT(ah, AR_WOW_PATTERN, set);
4413 +
4414 +       set = AR_WOW_AIFS_CNT(AR_WOW_CNT_AIFS_CNT) |
4415 +             AR_WOW_SLOT_CNT(AR_WOW_CNT_SLOT_CNT) |
4416 +             AR_WOW_KEEP_ALIVE_CNT(AR_WOW_CNT_KA_CNT);
4417 +       REG_SET_BIT(ah, AR_WOW_COUNT, set);
4418 +
4419 +       if (pattern_enable & AH_WOW_BEACON_MISS)
4420 +               set = AR_WOW_BEACON_TIMO;
4421 +       /* We are not using beacon miss, program a large value */
4422 +       else
4423 +               set = AR_WOW_BEACON_TIMO_MAX;
4424 +
4425 +       REG_WRITE(ah, AR_WOW_BCN_TIMO, set);
4426 +
4427 +       /*
4428 +        * Keep alive timo in ms except AR9280
4429 +        */
4430 +       if (!pattern_enable)
4431 +               set = AR_WOW_KEEP_ALIVE_NEVER;
4432 +       else
4433 +               set = KAL_TIMEOUT * 32;
4434 +
4435 +       REG_WRITE(ah, AR_WOW_KEEP_ALIVE_TIMO, set);
4436 +
4437 +       /*
4438 +        * Keep alive delay in us. based on 'power on clock',
4439 +        * therefore in usec
4440 +        */
4441 +       set = KAL_DELAY * 1000;
4442 +       REG_WRITE(ah, AR_WOW_KEEP_ALIVE_DELAY, set);
4443 +
4444 +       /*
4445 +        * Create keep alive pattern to respond to beacons
4446 +        */
4447 +       ath9k_wow_create_keep_alive_pattern(ah);
4448 +
4449 +       /*
4450 +        * Configure MAC WoW Registers
4451 +        */
4452 +       set = 0;
4453 +       /* Send keep alive timeouts anyway */
4454 +       clr = AR_WOW_KEEP_ALIVE_AUTO_DIS;
4455 +
4456 +       if (pattern_enable & AH_WOW_LINK_CHANGE)
4457 +               wow_event_mask |= AR_WOW_KEEP_ALIVE_FAIL;
4458 +       else
4459 +               set = AR_WOW_KEEP_ALIVE_FAIL_DIS;
4460 +
4461 +       set = AR_WOW_KEEP_ALIVE_FAIL_DIS;
4462 +       REG_RMW(ah, AR_WOW_KEEP_ALIVE, set, clr);
4463 +
4464 +       /*
4465 +        * we are relying on a bmiss failure. ensure we have
4466 +        * enough threshold to prevent false positives
4467 +        */
4468 +       REG_RMW_FIELD(ah, AR_RSSI_THR, AR_RSSI_THR_BM_THR,
4469 +                     AR_WOW_BMISSTHRESHOLD);
4470 +
4471 +       set = 0;
4472 +       clr = 0;
4473 +
4474 +       if (pattern_enable & AH_WOW_BEACON_MISS) {
4475 +               set = AR_WOW_BEACON_FAIL_EN;
4476 +               wow_event_mask |= AR_WOW_BEACON_FAIL;
4477 +       } else {
4478 +               clr = AR_WOW_BEACON_FAIL_EN;
4479 +       }
4480 +
4481 +       REG_RMW(ah, AR_WOW_BCN_EN, set, clr);
4482 +
4483 +       set = 0;
4484 +       clr = 0;
4485 +       /*
4486 +        * Enable the magic packet registers
4487 +        */
4488 +       if (pattern_enable & AH_WOW_MAGIC_PATTERN_EN) {
4489 +               set = AR_WOW_MAGIC_EN;
4490 +               wow_event_mask |= AR_WOW_MAGIC_PAT_FOUND;
4491 +       } else {
4492 +               clr = AR_WOW_MAGIC_EN;
4493 +       }
4494 +       set |= AR_WOW_MAC_INTR_EN;
4495 +       REG_RMW(ah, AR_WOW_PATTERN, set, clr);
4496 +
4497 +       REG_WRITE(ah, AR_WOW_PATTERN_MATCH_LT_256B,
4498 +                 AR_WOW_PATTERN_SUPPORTED);
4499 +
4500 +       /*
4501 +        * Set the power states appropriately and enable PME
4502 +        */
4503 +       clr = 0;
4504 +       set = AR_PMCTRL_PWR_STATE_D1D3 | AR_PMCTRL_HOST_PME_EN |
4505 +             AR_PMCTRL_PWR_PM_CTRL_ENA;
4506 +
4507 +       clr = AR_PCIE_PM_CTRL_ENA;
4508 +       REG_RMW(ah, AR_PCIE_PM_CTRL, set, clr);
4509 +
4510 +       /*
4511 +        * this is needed to prevent the chip waking up
4512 +        * the host within 3-4 seconds with certain
4513 +        * platform/BIOS. The fix is to enable
4514 +        * D1 & D3 to match original definition and
4515 +        * also match the OTP value. Anyway this
4516 +        * is more related to SW WOW.
4517 +        */
4518 +       clr = AR_PMCTRL_PWR_STATE_D1D3;
4519 +       REG_CLR_BIT(ah, AR_PCIE_PM_CTRL, clr);
4520 +
4521 +       set = AR_PMCTRL_PWR_STATE_D1D3_REAL;
4522 +       REG_SET_BIT(ah, AR_PCIE_PM_CTRL, set);
4523 +
4524 +       REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PRESERVE_SEQNUM);
4525 +
4526 +       /* to bring down WOW power low margin */
4527 +       set = BIT(13);
4528 +       REG_SET_BIT(ah, AR_PCIE_PHY_REG3, set);
4529 +       /* HW WoW */
4530 +       clr = BIT(5);
4531 +       REG_CLR_BIT(ah, AR_PCU_MISC_MODE3, clr);
4532 +
4533 +       ath9k_hw_set_powermode_wow_sleep(ah);
4534 +       ah->wow_event_mask = wow_event_mask;
4535 +}
4536 +EXPORT_SYMBOL(ath9k_hw_wow_enable);
4537 --- /dev/null
4538 +++ b/drivers/net/wireless/ath/ath9k/tx99.c
4539 @@ -0,0 +1,263 @@
4540 +/*
4541 + * Copyright (c) 2013 Qualcomm Atheros, Inc.
4542 + *
4543 + * Permission to use, copy, modify, and/or distribute this software for any
4544 + * purpose with or without fee is hereby granted, provided that the above
4545 + * copyright notice and this permission notice appear in all copies.
4546 + *
4547 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
4548 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
4549 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
4550 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
4551 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
4552 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
4553 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
4554 + */
4555 +
4556 +#include "ath9k.h"
4557 +
4558 +static void ath9k_tx99_stop(struct ath_softc *sc)
4559 +{
4560 +       struct ath_hw *ah = sc->sc_ah;
4561 +       struct ath_common *common = ath9k_hw_common(ah);
4562 +
4563 +       ath_drain_all_txq(sc);
4564 +       ath_startrecv(sc);
4565 +
4566 +       ath9k_hw_set_interrupts(ah);
4567 +       ath9k_hw_enable_interrupts(ah);
4568 +
4569 +       ieee80211_wake_queues(sc->hw);
4570 +
4571 +       kfree_skb(sc->tx99_skb);
4572 +       sc->tx99_skb = NULL;
4573 +       sc->tx99_state = false;
4574 +
4575 +       ath9k_hw_tx99_stop(sc->sc_ah);
4576 +       ath_dbg(common, XMIT, "TX99 stopped\n");
4577 +}
4578 +
4579 +static struct sk_buff *ath9k_build_tx99_skb(struct ath_softc *sc)
4580 +{
4581 +       static u8 PN9Data[] = {0xff, 0x87, 0xb8, 0x59, 0xb7, 0xa1, 0xcc, 0x24,
4582 +                              0x57, 0x5e, 0x4b, 0x9c, 0x0e, 0xe9, 0xea, 0x50,
4583 +                              0x2a, 0xbe, 0xb4, 0x1b, 0xb6, 0xb0, 0x5d, 0xf1,
4584 +                              0xe6, 0x9a, 0xe3, 0x45, 0xfd, 0x2c, 0x53, 0x18,
4585 +                              0x0c, 0xca, 0xc9, 0xfb, 0x49, 0x37, 0xe5, 0xa8,
4586 +                              0x51, 0x3b, 0x2f, 0x61, 0xaa, 0x72, 0x18, 0x84,
4587 +                              0x02, 0x23, 0x23, 0xab, 0x63, 0x89, 0x51, 0xb3,
4588 +                              0xe7, 0x8b, 0x72, 0x90, 0x4c, 0xe8, 0xfb, 0xc0};
4589 +       u32 len = 1200;
4590 +       struct ieee80211_hw *hw = sc->hw;
4591 +       struct ieee80211_hdr *hdr;
4592 +       struct ieee80211_tx_info *tx_info;
4593 +       struct sk_buff *skb;
4594 +
4595 +       skb = alloc_skb(len, GFP_KERNEL);
4596 +       if (!skb)
4597 +               return NULL;
4598 +
4599 +       skb_put(skb, len);
4600 +
4601 +       memset(skb->data, 0, len);
4602 +
4603 +       hdr = (struct ieee80211_hdr *)skb->data;
4604 +       hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA);
4605 +       hdr->duration_id = 0;
4606 +
4607 +       memcpy(hdr->addr1, hw->wiphy->perm_addr, ETH_ALEN);
4608 +       memcpy(hdr->addr2, hw->wiphy->perm_addr, ETH_ALEN);
4609 +       memcpy(hdr->addr3, hw->wiphy->perm_addr, ETH_ALEN);
4610 +
4611 +       hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
4612 +
4613 +       tx_info = IEEE80211_SKB_CB(skb);
4614 +       memset(tx_info, 0, sizeof(*tx_info));
4615 +       tx_info->band = hw->conf.chandef.chan->band;
4616 +       tx_info->flags = IEEE80211_TX_CTL_NO_ACK;
4617 +       tx_info->control.vif = sc->tx99_vif;
4618 +
4619 +       memcpy(skb->data + sizeof(*hdr), PN9Data, sizeof(PN9Data));
4620 +
4621 +       return skb;
4622 +}
4623 +
4624 +static void ath9k_tx99_deinit(struct ath_softc *sc)
4625 +{
4626 +       ath_reset(sc);
4627 +
4628 +       ath9k_ps_wakeup(sc);
4629 +       ath9k_tx99_stop(sc);
4630 +       ath9k_ps_restore(sc);
4631 +}
4632 +
4633 +static int ath9k_tx99_init(struct ath_softc *sc)
4634 +{
4635 +       struct ieee80211_hw *hw = sc->hw;
4636 +       struct ath_hw *ah = sc->sc_ah;
4637 +       struct ath_common *common = ath9k_hw_common(ah);
4638 +       struct ath_tx_control txctl;
4639 +       int r;
4640 +
4641 +       if (test_bit(SC_OP_INVALID, &sc->sc_flags)) {
4642 +               ath_err(common,
4643 +                       "driver is in invalid state unable to use TX99");
4644 +               return -EINVAL;
4645 +       }
4646 +
4647 +       sc->tx99_skb = ath9k_build_tx99_skb(sc);
4648 +       if (!sc->tx99_skb)
4649 +               return -ENOMEM;
4650 +
4651 +       memset(&txctl, 0, sizeof(txctl));
4652 +       txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO];
4653 +
4654 +       ath_reset(sc);
4655 +
4656 +       ath9k_ps_wakeup(sc);
4657 +
4658 +       ath9k_hw_disable_interrupts(ah);
4659 +       atomic_set(&ah->intr_ref_cnt, -1);
4660 +       ath_drain_all_txq(sc);
4661 +       ath_stoprecv(sc);
4662 +
4663 +       sc->tx99_state = true;
4664 +
4665 +       ieee80211_stop_queues(hw);
4666 +
4667 +       if (sc->tx99_power == MAX_RATE_POWER + 1)
4668 +               sc->tx99_power = MAX_RATE_POWER;
4669 +
4670 +       ath9k_hw_tx99_set_txpower(ah, sc->tx99_power);
4671 +       r = ath9k_tx99_send(sc, sc->tx99_skb, &txctl);
4672 +       if (r) {
4673 +               ath_dbg(common, XMIT, "Failed to xmit TX99 skb\n");
4674 +               return r;
4675 +       }
4676 +
4677 +       ath_dbg(common, XMIT, "TX99 xmit started using %d ( %ddBm)\n",
4678 +               sc->tx99_power,
4679 +               sc->tx99_power / 2);
4680 +
4681 +       /* We leave the harware awake as it will be chugging on */
4682 +
4683 +       return 0;
4684 +}
4685 +
4686 +static ssize_t read_file_tx99(struct file *file, char __user *user_buf,
4687 +                             size_t count, loff_t *ppos)
4688 +{
4689 +       struct ath_softc *sc = file->private_data;
4690 +       char buf[3];
4691 +       unsigned int len;
4692 +
4693 +       len = sprintf(buf, "%d\n", sc->tx99_state);
4694 +       return simple_read_from_buffer(user_buf, count, ppos, buf, len);
4695 +}
4696 +
4697 +static ssize_t write_file_tx99(struct file *file, const char __user *user_buf,
4698 +                              size_t count, loff_t *ppos)
4699 +{
4700 +       struct ath_softc *sc = file->private_data;
4701 +       struct ath_common *common = ath9k_hw_common(sc->sc_ah);
4702 +       char buf[32];
4703 +       bool start;
4704 +       ssize_t len;
4705 +       int r;
4706 +
4707 +       if (sc->nvifs > 1)
4708 +               return -EOPNOTSUPP;
4709 +
4710 +       len = min(count, sizeof(buf) - 1);
4711 +       if (copy_from_user(buf, user_buf, len))
4712 +               return -EFAULT;
4713 +
4714 +       if (strtobool(buf, &start))
4715 +               return -EINVAL;
4716 +
4717 +       if (start == sc->tx99_state) {
4718 +               if (!start)
4719 +                       return count;
4720 +               ath_dbg(common, XMIT, "Resetting TX99\n");
4721 +               ath9k_tx99_deinit(sc);
4722 +       }
4723 +
4724 +       if (!start) {
4725 +               ath9k_tx99_deinit(sc);
4726 +               return count;
4727 +       }
4728 +
4729 +       r = ath9k_tx99_init(sc);
4730 +       if (r)
4731 +               return r;
4732 +
4733 +       return count;
4734 +}
4735 +
4736 +static const struct file_operations fops_tx99 = {
4737 +       .read = read_file_tx99,
4738 +       .write = write_file_tx99,
4739 +       .open = simple_open,
4740 +       .owner = THIS_MODULE,
4741 +       .llseek = default_llseek,
4742 +};
4743 +
4744 +static ssize_t read_file_tx99_power(struct file *file,
4745 +                                   char __user *user_buf,
4746 +                                   size_t count, loff_t *ppos)
4747 +{
4748 +       struct ath_softc *sc = file->private_data;
4749 +       char buf[32];
4750 +       unsigned int len;
4751 +
4752 +       len = sprintf(buf, "%d (%d dBm)\n",
4753 +                     sc->tx99_power,
4754 +                     sc->tx99_power / 2);
4755 +
4756 +       return simple_read_from_buffer(user_buf, count, ppos, buf, len);
4757 +}
4758 +
4759 +static ssize_t write_file_tx99_power(struct file *file,
4760 +                                    const char __user *user_buf,
4761 +                                    size_t count, loff_t *ppos)
4762 +{
4763 +       struct ath_softc *sc = file->private_data;
4764 +       int r;
4765 +       u8 tx_power;
4766 +
4767 +       r = kstrtou8_from_user(user_buf, count, 0, &tx_power);
4768 +       if (r)
4769 +               return r;
4770 +
4771 +       if (tx_power > MAX_RATE_POWER)
4772 +               return -EINVAL;
4773 +
4774 +       sc->tx99_power = tx_power;
4775 +
4776 +       ath9k_ps_wakeup(sc);
4777 +       ath9k_hw_tx99_set_txpower(sc->sc_ah, sc->tx99_power);
4778 +       ath9k_ps_restore(sc);
4779 +
4780 +       return count;
4781 +}
4782 +
4783 +static const struct file_operations fops_tx99_power = {
4784 +       .read = read_file_tx99_power,
4785 +       .write = write_file_tx99_power,
4786 +       .open = simple_open,
4787 +       .owner = THIS_MODULE,
4788 +       .llseek = default_llseek,
4789 +};
4790 +
4791 +void ath9k_tx99_init_debug(struct ath_softc *sc)
4792 +{
4793 +       if (!AR_SREV_9300_20_OR_LATER(sc->sc_ah))
4794 +               return;
4795 +
4796 +       debugfs_create_file("tx99", S_IRUSR | S_IWUSR,
4797 +                           sc->debug.debugfs_phy, sc,
4798 +                           &fops_tx99);
4799 +       debugfs_create_file("tx99_power", S_IRUSR | S_IWUSR,
4800 +                           sc->debug.debugfs_phy, sc,
4801 +                           &fops_tx99_power);
4802 +}
4803 --- a/drivers/net/wireless/ath/ath9k/dfs_debug.c
4804 +++ b/drivers/net/wireless/ath/ath9k/dfs_debug.c
4805 @@ -44,14 +44,20 @@ static ssize_t read_file_dfs(struct file
4806         if (buf == NULL)
4807                 return -ENOMEM;
4808  
4809 -       if (sc->dfs_detector)
4810 -               dfs_pool_stats = sc->dfs_detector->get_stats(sc->dfs_detector);
4811 -
4812         len += scnprintf(buf + len, size - len, "DFS support for "
4813                          "macVersion = 0x%x, macRev = 0x%x: %s\n",
4814                          hw_ver->macVersion, hw_ver->macRev,
4815                          (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_DFS) ?
4816                                         "enabled" : "disabled");
4817 +
4818 +       if (!sc->dfs_detector) {
4819 +               len += scnprintf(buf + len, size - len,
4820 +                               "DFS detector not enabled\n");
4821 +               goto exit;
4822 +       }
4823 +
4824 +       dfs_pool_stats = sc->dfs_detector->get_stats(sc->dfs_detector);
4825 +
4826         len += scnprintf(buf + len, size - len, "Pulse detector statistics:\n");
4827         ATH9K_DFS_STAT("pulse events reported   ", pulses_total);
4828         ATH9K_DFS_STAT("invalid pulse events    ", pulses_no_dfs);
4829 @@ -76,6 +82,7 @@ static ssize_t read_file_dfs(struct file
4830         ATH9K_DFS_POOL_STAT("Seqs. alloc error       ", pseq_alloc_error);
4831         ATH9K_DFS_POOL_STAT("Seqs. in use            ", pseq_used);
4832  
4833 +exit:
4834         if (len > size)
4835                 len = size;
4836  
4837 --- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
4838 +++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
4839 @@ -641,11 +641,12 @@ static void ar9003_hw_override_ini(struc
4840                 else
4841                         ah->enabled_cals &= ~TX_IQ_CAL;
4842  
4843 -               if (REG_READ(ah, AR_PHY_CL_CAL_CTL) & AR_PHY_CL_CAL_ENABLE)
4844 -                       ah->enabled_cals |= TX_CL_CAL;
4845 -               else
4846 -                       ah->enabled_cals &= ~TX_CL_CAL;
4847         }
4848 +
4849 +       if (REG_READ(ah, AR_PHY_CL_CAL_CTL) & AR_PHY_CL_CAL_ENABLE)
4850 +               ah->enabled_cals |= TX_CL_CAL;
4851 +       else
4852 +               ah->enabled_cals &= ~TX_CL_CAL;
4853  }
4854  
4855  static void ar9003_hw_prog_ini(struct ath_hw *ah,
4856 @@ -701,6 +702,54 @@ static int ar9550_hw_get_modes_txgain_in
4857         return ret;
4858  }
4859  
4860 +static void ar9003_doubler_fix(struct ath_hw *ah)
4861 +{
4862 +       if (AR_SREV_9300(ah) || AR_SREV_9580(ah) || AR_SREV_9550(ah)) {
4863 +               REG_RMW(ah, AR_PHY_65NM_CH0_RXTX2,
4864 +                       1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
4865 +                       1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S, 0);
4866 +               REG_RMW(ah, AR_PHY_65NM_CH1_RXTX2,
4867 +                       1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
4868 +                       1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S, 0);
4869 +               REG_RMW(ah, AR_PHY_65NM_CH2_RXTX2,
4870 +                       1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
4871 +                       1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S, 0);
4872 +
4873 +               udelay(200);
4874 +
4875 +               REG_CLR_BIT(ah, AR_PHY_65NM_CH0_RXTX2,
4876 +                           AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK);
4877 +               REG_CLR_BIT(ah, AR_PHY_65NM_CH1_RXTX2,
4878 +                           AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK);
4879 +               REG_CLR_BIT(ah, AR_PHY_65NM_CH2_RXTX2,
4880 +                           AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK);
4881 +
4882 +               udelay(1);
4883 +
4884 +               REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_RXTX2,
4885 +                             AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK, 1);
4886 +               REG_RMW_FIELD(ah, AR_PHY_65NM_CH1_RXTX2,
4887 +                             AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK, 1);
4888 +               REG_RMW_FIELD(ah, AR_PHY_65NM_CH2_RXTX2,
4889 +                             AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK, 1);
4890 +
4891 +               udelay(200);
4892 +
4893 +               REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_SYNTH12,
4894 +                             AR_PHY_65NM_CH0_SYNTH12_VREFMUL3, 0xf);
4895 +
4896 +               REG_RMW(ah, AR_PHY_65NM_CH0_RXTX2, 0,
4897 +                       1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
4898 +                       1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S);
4899 +               REG_RMW(ah, AR_PHY_65NM_CH1_RXTX2, 0,
4900 +                       1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
4901 +                       1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S);
4902 +               REG_RMW(ah, AR_PHY_65NM_CH2_RXTX2, 0,
4903 +                       1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
4904 +                       1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S);
4905 +       }
4906 +}
4907 +
4908  static int ar9003_hw_process_ini(struct ath_hw *ah,
4909                                  struct ath9k_channel *chan)
4910  {
4911 @@ -726,6 +775,8 @@ static int ar9003_hw_process_ini(struct 
4912                                            modesIndex);
4913         }
4914  
4915 +       ar9003_doubler_fix(ah);
4916 +
4917         /*
4918          * RXGAIN initvals.
4919          */
4920 --- a/drivers/net/wireless/ath/ath9k/ar9003_phy.h
4921 +++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.h
4922 @@ -656,13 +656,24 @@
4923  #define AR_PHY_SYNTH4_LONG_SHIFT_SELECT   ((AR_SREV_9462(ah) || AR_SREV_9565(ah)) ? 0x00000001 : 0x00000002)
4924  #define AR_PHY_SYNTH4_LONG_SHIFT_SELECT_S ((AR_SREV_9462(ah) || AR_SREV_9565(ah)) ? 0 : 1)
4925  #define AR_PHY_65NM_CH0_SYNTH7      0x16098
4926 +#define AR_PHY_65NM_CH0_SYNTH12     0x160ac
4927  #define AR_PHY_65NM_CH0_BIAS1       0x160c0
4928  #define AR_PHY_65NM_CH0_BIAS2       0x160c4
4929  #define AR_PHY_65NM_CH0_BIAS4       0x160cc
4930 +#define AR_PHY_65NM_CH0_RXTX2       0x16104
4931 +#define AR_PHY_65NM_CH1_RXTX2       0x16504
4932 +#define AR_PHY_65NM_CH2_RXTX2       0x16904
4933  #define AR_PHY_65NM_CH0_RXTX4       0x1610c
4934  #define AR_PHY_65NM_CH1_RXTX4       0x1650c
4935  #define AR_PHY_65NM_CH2_RXTX4       0x1690c
4936  
4937 +#define AR_PHY_65NM_CH0_SYNTH12_VREFMUL3           0x00780000
4938 +#define AR_PHY_65NM_CH0_SYNTH12_VREFMUL3_S         19
4939 +#define AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK         0x00000004
4940 +#define AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S       2
4941 +#define AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK        0x00000008
4942 +#define AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S      3
4943 +
4944  #define AR_CH0_TOP     (AR_SREV_9300(ah) ? 0x16288 : \
4945                          (((AR_SREV_9462(ah) || AR_SREV_9565(ah)) ? 0x1628c : 0x16280)))
4946  #define AR_CH0_TOP_XPABIASLVL (AR_SREV_9550(ah) ? 0x3c0 : 0x300)
4947 --- a/drivers/net/wireless/rt2x00/rt2x00dev.c
4948 +++ b/drivers/net/wireless/rt2x00/rt2x00dev.c
4949 @@ -181,6 +181,7 @@ static void rt2x00lib_autowakeup(struct 
4950  static void rt2x00lib_bc_buffer_iter(void *data, u8 *mac,
4951                                      struct ieee80211_vif *vif)
4952  {
4953 +       struct ieee80211_tx_control control = {};
4954         struct rt2x00_dev *rt2x00dev = data;
4955         struct sk_buff *skb;
4956  
4957 @@ -195,7 +196,7 @@ static void rt2x00lib_bc_buffer_iter(voi
4958          */
4959         skb = ieee80211_get_buffered_bc(rt2x00dev->hw, vif);
4960         while (skb) {
4961 -               rt2x00mac_tx(rt2x00dev->hw, NULL, skb);
4962 +               rt2x00mac_tx(rt2x00dev->hw, &control, skb);
4963                 skb = ieee80211_get_buffered_bc(rt2x00dev->hw, vif);
4964         }
4965  }
4966 --- a/drivers/net/wireless/ath/ath9k/ar9003_calib.c
4967 +++ b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
4968 @@ -1040,8 +1040,8 @@ static void ar9003_hw_cl_cal_post_proc(s
4969         }
4970  }
4971  
4972 -static bool ar9003_hw_init_cal(struct ath_hw *ah,
4973 -                              struct ath9k_channel *chan)
4974 +static bool ar9003_hw_init_cal_pcoem(struct ath_hw *ah,
4975 +                                    struct ath9k_channel *chan)
4976  {
4977         struct ath_common *common = ath9k_hw_common(ah);
4978         struct ath9k_hw_cal_data *caldata = ah->caldata;
4979 @@ -1228,13 +1228,109 @@ skip_tx_iqcal:
4980         return true;
4981  }
4982  
4983 +static bool ar9003_hw_init_cal_soc(struct ath_hw *ah,
4984 +                                  struct ath9k_channel *chan)
4985 +{
4986 +       struct ath_common *common = ath9k_hw_common(ah);
4987 +       struct ath9k_hw_cal_data *caldata = ah->caldata;
4988 +       bool txiqcal_done = false;
4989 +       bool is_reusable = true, status = true;
4990 +       bool run_agc_cal = false, sep_iq_cal = false;
4991 +
4992 +       /* Use chip chainmask only for calibration */
4993 +       ar9003_hw_set_chain_masks(ah, ah->caps.rx_chainmask, ah->caps.tx_chainmask);
4994 +
4995 +       if (ah->enabled_cals & TX_CL_CAL) {
4996 +               REG_SET_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_CL_CAL_ENABLE);
4997 +               run_agc_cal = true;
4998 +       }
4999 +
5000 +       if (IS_CHAN_HALF_RATE(chan) || IS_CHAN_QUARTER_RATE(chan))
5001 +               goto skip_tx_iqcal;
5002 +
5003 +       /* Do Tx IQ Calibration */
5004 +       REG_RMW_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_1,
5005 +                     AR_PHY_TX_IQCAL_CONTROL_1_IQCORR_I_Q_COFF_DELPT,
5006 +                     DELPT);
5007 +
5008 +       /*
5009 +        * For AR9485 or later chips, TxIQ cal runs as part of
5010 +        * AGC calibration. Specifically, AR9550 in SoC chips.
5011 +        */
5012 +       if (ah->enabled_cals & TX_IQ_ON_AGC_CAL) {
5013 +               txiqcal_done = true;
5014 +               run_agc_cal = true;
5015 +       } else {
5016 +               sep_iq_cal = true;
5017 +               run_agc_cal = true;
5018 +       }
5019 +
5020 +       /*
5021 +        * In the SoC family, this will run for AR9300, AR9331 and AR9340.
5022 +        */
5023 +       if (sep_iq_cal) {
5024 +               txiqcal_done = ar9003_hw_tx_iq_cal_run(ah);
5025 +               REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
5026 +               udelay(5);
5027 +               REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
5028 +       }
5029 +
5030 +skip_tx_iqcal:
5031 +       if (run_agc_cal || !(ah->ah_flags & AH_FASTCC)) {
5032 +               /* Calibrate the AGC */
5033 +               REG_WRITE(ah, AR_PHY_AGC_CONTROL,
5034 +                         REG_READ(ah, AR_PHY_AGC_CONTROL) |
5035 +                         AR_PHY_AGC_CONTROL_CAL);
5036 +
5037 +               /* Poll for offset calibration complete */
5038 +               status = ath9k_hw_wait(ah, AR_PHY_AGC_CONTROL,
5039 +                                      AR_PHY_AGC_CONTROL_CAL,
5040 +                                      0, AH_WAIT_TIMEOUT);
5041 +       }
5042 +
5043 +       if (!status) {
5044 +               ath_dbg(common, CALIBRATE,
5045 +                       "offset calibration failed to complete in %d ms; noisy environment?\n",
5046 +                       AH_WAIT_TIMEOUT / 1000);
5047 +               return false;
5048 +       }
5049 +
5050 +       if (txiqcal_done)
5051 +               ar9003_hw_tx_iq_cal_post_proc(ah, is_reusable);
5052 +
5053 +       /* Revert chainmask to runtime parameters */
5054 +       ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
5055 +
5056 +       /* Initialize list pointers */
5057 +       ah->cal_list = ah->cal_list_last = ah->cal_list_curr = NULL;
5058 +
5059 +       INIT_CAL(&ah->iq_caldata);
5060 +       INSERT_CAL(ah, &ah->iq_caldata);
5061 +       ath_dbg(common, CALIBRATE, "enabling IQ Calibration\n");
5062 +
5063 +       /* Initialize current pointer to first element in list */
5064 +       ah->cal_list_curr = ah->cal_list;
5065 +
5066 +       if (ah->cal_list_curr)
5067 +               ath9k_hw_reset_calibration(ah, ah->cal_list_curr);
5068 +
5069 +       if (caldata)
5070 +               caldata->CalValid = 0;
5071 +
5072 +       return true;
5073 +}
5074 +
5075  void ar9003_hw_attach_calib_ops(struct ath_hw *ah)
5076  {
5077         struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
5078         struct ath_hw_ops *ops = ath9k_hw_ops(ah);
5079  
5080 +       if (AR_SREV_9485(ah) || AR_SREV_9462(ah) || AR_SREV_9565(ah))
5081 +               priv_ops->init_cal = ar9003_hw_init_cal_pcoem;
5082 +       else
5083 +               priv_ops->init_cal = ar9003_hw_init_cal_soc;
5084 +
5085         priv_ops->init_cal_settings = ar9003_hw_init_cal_settings;
5086 -       priv_ops->init_cal = ar9003_hw_init_cal;
5087         priv_ops->setup_calibration = ar9003_hw_setup_calibration;
5088  
5089         ops->calibrate = ar9003_hw_calibrate;
5090 --- a/drivers/net/wireless/ath/ath9k/common.c
5091 +++ b/drivers/net/wireless/ath/ath9k/common.c
5092 @@ -98,10 +98,8 @@ struct ath9k_channel *ath9k_cmn_get_chan
5093  {
5094         struct ieee80211_channel *curchan = chandef->chan;
5095         struct ath9k_channel *channel;
5096 -       u8 chan_idx;
5097  
5098 -       chan_idx = curchan->hw_value;
5099 -       channel = &ah->channels[chan_idx];
5100 +       channel = &ah->channels[curchan->hw_value];
5101         ath9k_cmn_update_ichannel(channel, chandef);
5102  
5103         return channel;
5104 --- a/net/mac80211/rc80211_minstrel_ht.c
5105 +++ b/net/mac80211/rc80211_minstrel_ht.c
5106 @@ -226,7 +226,7 @@ minstrel_ht_calc_tp(struct minstrel_ht_s
5107                 nsecs = 1000 * mi->overhead / MINSTREL_TRUNC(mi->avg_ampdu_len);
5108  
5109         nsecs += minstrel_mcs_groups[group].duration[rate];
5110 -       tp = 1000000 * ((mr->probability * 1000) / nsecs);
5111 +       tp = 1000000 * ((prob * 1000) / nsecs);
5112  
5113         mr->cur_tp = MINSTREL_TRUNC(tp);
5114  }
5115 --- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
5116 +++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
5117 @@ -3984,18 +3984,20 @@ static void ar9003_hw_quick_drop_apply(s
5118         int quick_drop;
5119         s32 t[3], f[3] = {5180, 5500, 5785};
5120  
5121 -       if (!(pBase->miscConfiguration & BIT(1)))
5122 +       if (!(pBase->miscConfiguration & BIT(4)))
5123                 return;
5124  
5125 -       if (freq < 4000)
5126 -               quick_drop = eep->modalHeader2G.quick_drop;
5127 -       else {
5128 -               t[0] = eep->base_ext1.quick_drop_low;
5129 -               t[1] = eep->modalHeader5G.quick_drop;
5130 -               t[2] = eep->base_ext1.quick_drop_high;
5131 -               quick_drop = ar9003_hw_power_interpolate(freq, f, t, 3);
5132 +       if (AR_SREV_9300(ah) || AR_SREV_9580(ah) || AR_SREV_9340(ah)) {
5133 +               if (freq < 4000) {
5134 +                       quick_drop = eep->modalHeader2G.quick_drop;
5135 +               } else {
5136 +                       t[0] = eep->base_ext1.quick_drop_low;
5137 +                       t[1] = eep->modalHeader5G.quick_drop;
5138 +                       t[2] = eep->base_ext1.quick_drop_high;
5139 +                       quick_drop = ar9003_hw_power_interpolate(freq, f, t, 3);
5140 +               }
5141 +               REG_RMW_FIELD(ah, AR_PHY_AGC, AR_PHY_AGC_QUICK_DROP, quick_drop);
5142         }
5143 -       REG_RMW_FIELD(ah, AR_PHY_AGC, AR_PHY_AGC_QUICK_DROP, quick_drop);
5144  }
5145  
5146  static void ar9003_hw_txend_to_xpa_off_apply(struct ath_hw *ah, bool is2ghz)
5147 @@ -4035,7 +4037,7 @@ static void ar9003_hw_xlna_bias_strength
5148         struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
5149         u8 bias;
5150  
5151 -       if (!(eep->baseEepHeader.featureEnable & 0x40))
5152 +       if (!(eep->baseEepHeader.miscConfiguration & 0x40))
5153                 return;
5154  
5155         if (!AR_SREV_9300(ah))
5156 --- a/net/mac80211/ieee80211_i.h
5157 +++ b/net/mac80211/ieee80211_i.h
5158 @@ -735,6 +735,7 @@ struct ieee80211_sub_if_data {
5159         int csa_counter_offset_beacon;
5160         int csa_counter_offset_presp;
5161         bool csa_radar_required;
5162 +       struct cfg80211_chan_def csa_chandef;
5163  
5164         /* used to reconfigure hardware SM PS */
5165         struct work_struct recalc_smps;
5166 @@ -811,6 +812,9 @@ static inline void sdata_unlock(struct i
5167         __release(&sdata->wdev.mtx);
5168  }
5169  
5170 +#define sdata_dereference(p, sdata) \
5171 +       rcu_dereference_protected(p, lockdep_is_held(&sdata->wdev.mtx))
5172 +
5173  static inline void
5174  sdata_assert_lock(struct ieee80211_sub_if_data *sdata)
5175  {
5176 @@ -1098,7 +1102,6 @@ struct ieee80211_local {
5177         enum mac80211_scan_state next_scan_state;
5178         struct delayed_work scan_work;
5179         struct ieee80211_sub_if_data __rcu *scan_sdata;
5180 -       struct cfg80211_chan_def csa_chandef;
5181         /* For backward compatibility only -- do not use */
5182         struct cfg80211_chan_def _oper_chandef;
5183  
5184 @@ -1236,6 +1239,7 @@ struct ieee80211_csa_ie {
5185         u8 mode;
5186         u8 count;
5187         u8 ttl;
5188 +       u16 pre_value;
5189  };
5190  
5191  /* Parsed Information Elements */
5192 @@ -1738,7 +1742,6 @@ ieee80211_vif_change_bandwidth(struct ie
5193  /* NOTE: only use ieee80211_vif_change_channel() for channel switch */
5194  int __must_check
5195  ieee80211_vif_change_channel(struct ieee80211_sub_if_data *sdata,
5196 -                            const struct cfg80211_chan_def *chandef,
5197                              u32 *changed);
5198  void ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata);
5199  void ieee80211_vif_vlan_copy_chanctx(struct ieee80211_sub_if_data *sdata);
5200 --- a/net/mac80211/chan.c
5201 +++ b/net/mac80211/chan.c
5202 @@ -411,12 +411,12 @@ int ieee80211_vif_use_channel(struct iee
5203  }
5204  
5205  int ieee80211_vif_change_channel(struct ieee80211_sub_if_data *sdata,
5206 -                                const struct cfg80211_chan_def *chandef,
5207                                  u32 *changed)
5208  {
5209         struct ieee80211_local *local = sdata->local;
5210         struct ieee80211_chanctx_conf *conf;
5211         struct ieee80211_chanctx *ctx;
5212 +       const struct cfg80211_chan_def *chandef = &sdata->csa_chandef;
5213         int ret;
5214         u32 chanctx_changed = 0;
5215  
5216 --- a/net/mac80211/ibss.c
5217 +++ b/net/mac80211/ibss.c
5218 @@ -550,12 +550,12 @@ int ieee80211_ibss_finish_csa(struct iee
5219                                         capability);
5220                 /* XXX: should not really modify cfg80211 data */
5221                 if (cbss) {
5222 -                       cbss->channel = sdata->local->csa_chandef.chan;
5223 +                       cbss->channel = sdata->csa_chandef.chan;
5224                         cfg80211_put_bss(sdata->local->hw.wiphy, cbss);
5225                 }
5226         }
5227  
5228 -       ifibss->chandef = sdata->local->csa_chandef;
5229 +       ifibss->chandef = sdata->csa_chandef;
5230  
5231         /* generate the beacon */
5232         err = ieee80211_ibss_csa_beacon(sdata, NULL);
5233 @@ -922,7 +922,7 @@ ieee80211_ibss_process_chanswitch(struct
5234                                 IEEE80211_MAX_QUEUE_MAP,
5235                                 IEEE80211_QUEUE_STOP_REASON_CSA);
5236  
5237 -       sdata->local->csa_chandef = params.chandef;
5238 +       sdata->csa_chandef = params.chandef;
5239         sdata->vif.csa_active = true;
5240  
5241         ieee80211_bss_info_change_notify(sdata, err);
5242 --- a/net/mac80211/mesh.c
5243 +++ b/net/mac80211/mesh.c
5244 @@ -943,14 +943,19 @@ ieee80211_mesh_process_chnswitch(struct 
5245                  params.chandef.chan->center_freq);
5246  
5247         params.block_tx = csa_ie.mode & WLAN_EID_CHAN_SWITCH_PARAM_TX_RESTRICT;
5248 -       if (beacon)
5249 +       if (beacon) {
5250                 ifmsh->chsw_ttl = csa_ie.ttl - 1;
5251 -       else
5252 -               ifmsh->chsw_ttl = 0;
5253 +               if (ifmsh->pre_value >= csa_ie.pre_value)
5254 +                       return false;
5255 +               ifmsh->pre_value = csa_ie.pre_value;
5256 +       }
5257  
5258 -       if (ifmsh->chsw_ttl > 0)
5259 +       if (ifmsh->chsw_ttl < ifmsh->mshcfg.dot11MeshTTL) {
5260                 if (ieee80211_mesh_csa_beacon(sdata, &params, false) < 0)
5261                         return false;
5262 +       } else {
5263 +               return false;
5264 +       }
5265  
5266         sdata->csa_radar_required = params.radar_required;
5267  
5268 @@ -959,7 +964,7 @@ ieee80211_mesh_process_chnswitch(struct 
5269                                 IEEE80211_MAX_QUEUE_MAP,
5270                                 IEEE80211_QUEUE_STOP_REASON_CSA);
5271  
5272 -       sdata->local->csa_chandef = params.chandef;
5273 +       sdata->csa_chandef = params.chandef;
5274         sdata->vif.csa_active = true;
5275  
5276         ieee80211_bss_info_change_notify(sdata, err);
5277 @@ -1163,7 +1168,6 @@ static int mesh_fwd_csa_frame(struct iee
5278         offset_ttl = (len < 42) ? 7 : 10;
5279         *(pos + offset_ttl) -= 1;
5280         *(pos + offset_ttl + 1) &= ~WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR;
5281 -       sdata->u.mesh.chsw_ttl = *(pos + offset_ttl);
5282  
5283         memcpy(mgmt_fwd, mgmt, len);
5284         eth_broadcast_addr(mgmt_fwd->da);
5285 @@ -1182,7 +1186,7 @@ static void mesh_rx_csa_frame(struct iee
5286         u16 pre_value;
5287         bool fwd_csa = true;
5288         size_t baselen;
5289 -       u8 *pos, ttl;
5290 +       u8 *pos;
5291  
5292         if (mgmt->u.action.u.measurement.action_code !=
5293             WLAN_ACTION_SPCT_CHL_SWITCH)
5294 @@ -1193,8 +1197,8 @@ static void mesh_rx_csa_frame(struct iee
5295                            u.action.u.chan_switch.variable);
5296         ieee802_11_parse_elems(pos, len - baselen, false, &elems);
5297  
5298 -       ttl = elems.mesh_chansw_params_ie->mesh_ttl;
5299 -       if (!--ttl)
5300 +       ifmsh->chsw_ttl = elems.mesh_chansw_params_ie->mesh_ttl;
5301 +       if (!--ifmsh->chsw_ttl)
5302                 fwd_csa = false;
5303  
5304         pre_value = le16_to_cpu(elems.mesh_chansw_params_ie->mesh_pre_value);
5305 --- a/net/mac80211/spectmgmt.c
5306 +++ b/net/mac80211/spectmgmt.c
5307 @@ -78,6 +78,8 @@ int ieee80211_parse_ch_switch_ie(struct 
5308         if (elems->mesh_chansw_params_ie) {
5309                 csa_ie->ttl = elems->mesh_chansw_params_ie->mesh_ttl;
5310                 csa_ie->mode = elems->mesh_chansw_params_ie->mesh_flags;
5311 +               csa_ie->pre_value = le16_to_cpu(
5312 +                               elems->mesh_chansw_params_ie->mesh_pre_value);
5313         }
5314  
5315         new_freq = ieee80211_channel_to_frequency(new_chan_no, new_band);
5316 --- a/drivers/net/wireless/ath/ath6kl/cfg80211.c
5317 +++ b/drivers/net/wireless/ath/ath6kl/cfg80211.c
5318 @@ -1109,7 +1109,9 @@ void ath6kl_cfg80211_ch_switch_notify(st
5319                                 (mode == WMI_11G_HT20) ?
5320                                         NL80211_CHAN_HT20 : NL80211_CHAN_NO_HT);
5321  
5322 +       mutex_lock(vif->wdev->mtx);
5323         cfg80211_ch_switch_notify(vif->ndev, &chandef);
5324 +       mutex_unlock(vif->wdev->mtx);
5325  }
5326  
5327  static int ath6kl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,