ath9k: add a fix to improve reliability of high bitrates on AR93xx/AR95xx
[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 @@ -454,7 +454,6 @@ static void ath9k_hw_init_config(struct 
486         }
487  
488         ah->config.rx_intr_mitigation = true;
489 -       ah->config.pcieSerDesWrite = true;
490  
491         /*
492          * We need this for PCI devices only (Cardbus, PCI, miniPCI)
493 --- a/drivers/net/wireless/ath/ath9k/hw.h
494 +++ b/drivers/net/wireless/ath/ath9k/hw.h
495 @@ -283,7 +283,6 @@ struct ath9k_ops_config {
496         int additional_swba_backoff;
497         int ack_6mb;
498         u32 cwm_ignore_extcca;
499 -       bool pcieSerDesWrite;
500         u8 pcie_clock_req;
501         u32 pcie_waen;
502         u8 analog_shiftreg;
503 @@ -920,7 +919,7 @@ struct ath_hw {
504         /* Enterprise mode cap */
505         u32 ent_mode;
506  
507 -#ifdef CONFIG_PM_SLEEP
508 +#ifdef CONFIG_ATH9K_WOW
509         u32 wow_event_mask;
510  #endif
511         bool is_clk_25mhz;
512 @@ -1126,7 +1125,7 @@ ath9k_hw_get_btcoex_scheme(struct ath_hw
513  #endif /* CPTCFG_ATH9K_BTCOEX_SUPPORT */
514  
515  
516 -#ifdef CONFIG_PM_SLEEP
517 +#ifdef CONFIG_ATH9K_WOW
518  const char *ath9k_hw_wow_event_to_string(u32 wow_event);
519  void ath9k_hw_wow_apply_pattern(struct ath_hw *ah, u8 *user_pattern,
520                                 u8 *user_mask, int pattern_count,
521 --- a/drivers/net/wireless/ath/ath9k/init.c
522 +++ b/drivers/net/wireless/ath/ath9k/init.c
523 @@ -683,6 +683,7 @@ static int ath9k_init_softc(u16 devid, s
524         common = ath9k_hw_common(ah);
525         sc->dfs_detector = dfs_pattern_detector_init(common, NL80211_DFS_UNSET);
526         sc->tx99_power = MAX_RATE_POWER + 1;
527 +       init_waitqueue_head(&sc->tx_wait);
528  
529         if (!pdata) {
530                 ah->ah_flags |= AH_USE_EEPROM;
531 @@ -730,6 +731,7 @@ static int ath9k_init_softc(u16 devid, s
532         tasklet_init(&sc->bcon_tasklet, ath9k_beacon_tasklet,
533                      (unsigned long)sc);
534  
535 +       setup_timer(&sc->sleep_timer, ath_ps_full_sleep, (unsigned long)sc);
536         INIT_WORK(&sc->hw_reset_work, ath_reset_work);
537         INIT_WORK(&sc->hw_check_work, ath_hw_check);
538         INIT_WORK(&sc->paprd_work, ath_paprd_calibrate);
539 @@ -845,7 +847,8 @@ static const struct ieee80211_iface_limi
540  };
541  
542  static const struct ieee80211_iface_limit if_dfs_limits[] = {
543 -       { .max = 1,     .types = BIT(NL80211_IFTYPE_AP) },
544 +       { .max = 1,     .types = BIT(NL80211_IFTYPE_AP) |
545 +                                BIT(NL80211_IFTYPE_ADHOC) },
546  };
547  
548  static const struct ieee80211_iface_combination if_comb[] = {
549 @@ -862,20 +865,11 @@ static const struct ieee80211_iface_comb
550                 .max_interfaces = 1,
551                 .num_different_channels = 1,
552                 .beacon_int_infra_match = true,
553 -               .radar_detect_widths =  BIT(NL80211_CHAN_NO_HT) |
554 -                                       BIT(NL80211_CHAN_HT20),
555 +               .radar_detect_widths =  BIT(NL80211_CHAN_WIDTH_20_NOHT) |
556 +                                       BIT(NL80211_CHAN_WIDTH_20),
557         }
558  };
559  
560 -#ifdef CONFIG_PM
561 -static const struct wiphy_wowlan_support ath9k_wowlan_support = {
562 -       .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT,
563 -       .n_patterns = MAX_NUM_USER_PATTERN,
564 -       .pattern_min_len = 1,
565 -       .pattern_max_len = MAX_PATTERN_SIZE,
566 -};
567 -#endif
568 -
569  void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
570  {
571         struct ath_hw *ah = sc->sc_ah;
572 @@ -925,16 +919,6 @@ void ath9k_set_hw_capab(struct ath_softc
573         hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_5_10_MHZ;
574         hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
575  
576 -#ifdef CONFIG_PM_SLEEP
577 -       if ((ah->caps.hw_caps & ATH9K_HW_WOW_DEVICE_CAPABLE) &&
578 -           (sc->driver_data & ATH9K_PCI_WOW) &&
579 -           device_can_wakeup(sc->dev))
580 -               hw->wiphy->wowlan = &ath9k_wowlan_support;
581 -
582 -       atomic_set(&sc->wow_sleep_proc_intr, -1);
583 -       atomic_set(&sc->wow_got_bmiss_intr, -1);
584 -#endif
585 -
586         hw->queues = 4;
587         hw->max_rates = 4;
588         hw->channel_change_time = 5000;
589 @@ -960,6 +944,7 @@ void ath9k_set_hw_capab(struct ath_softc
590                 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
591                         &sc->sbands[IEEE80211_BAND_5GHZ];
592  
593 +       ath9k_init_wow(hw);
594         ath9k_reload_chainmask_settings(sc);
595  
596         SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
597 @@ -1058,6 +1043,7 @@ static void ath9k_deinit_softc(struct at
598                 if (ATH_TXQ_SETUP(sc, i))
599                         ath_tx_cleanupq(sc, &sc->tx.txq[i]);
600  
601 +       del_timer_sync(&sc->sleep_timer);
602         ath9k_hw_deinit(sc->sc_ah);
603         if (sc->dfs_detector != NULL)
604                 sc->dfs_detector->exit(sc->dfs_detector);
605 --- a/drivers/net/wireless/ath/ath9k/main.c
606 +++ b/drivers/net/wireless/ath/ath9k/main.c
607 @@ -82,6 +82,22 @@ static bool ath9k_setpower(struct ath_so
608         return ret;
609  }
610  
611 +void ath_ps_full_sleep(unsigned long data)
612 +{
613 +       struct ath_softc *sc = (struct ath_softc *) data;
614 +       struct ath_common *common = ath9k_hw_common(sc->sc_ah);
615 +       bool reset;
616 +
617 +       spin_lock(&common->cc_lock);
618 +       ath_hw_cycle_counters_update(common);
619 +       spin_unlock(&common->cc_lock);
620 +
621 +       ath9k_hw_setrxabort(sc->sc_ah, 1);
622 +       ath9k_hw_stopdmarecv(sc->sc_ah, &reset);
623 +
624 +       ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_FULL_SLEEP);
625 +}
626 +
627  void ath9k_ps_wakeup(struct ath_softc *sc)
628  {
629         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
630 @@ -92,6 +108,7 @@ void ath9k_ps_wakeup(struct ath_softc *s
631         if (++sc->ps_usecount != 1)
632                 goto unlock;
633  
634 +       del_timer_sync(&sc->sleep_timer);
635         power_mode = sc->sc_ah->power_mode;
636         ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
637  
638 @@ -117,17 +134,17 @@ void ath9k_ps_restore(struct ath_softc *
639         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
640         enum ath9k_power_mode mode;
641         unsigned long flags;
642 -       bool reset;
643  
644         spin_lock_irqsave(&sc->sc_pm_lock, flags);
645         if (--sc->ps_usecount != 0)
646                 goto unlock;
647  
648         if (sc->ps_idle) {
649 -               ath9k_hw_setrxabort(sc->sc_ah, 1);
650 -               ath9k_hw_stopdmarecv(sc->sc_ah, &reset);
651 -               mode = ATH9K_PM_FULL_SLEEP;
652 -       } else if (sc->ps_enabled &&
653 +               mod_timer(&sc->sleep_timer, jiffies + HZ / 10);
654 +               goto unlock;
655 +       }
656 +
657 +       if (sc->ps_enabled &&
658                    !(sc->ps_flags & (PS_WAIT_FOR_BEACON |
659                                      PS_WAIT_FOR_CAB |
660                                      PS_WAIT_FOR_PSPOLL_DATA |
661 @@ -163,13 +180,13 @@ static void __ath_cancel_work(struct ath
662  #endif
663  }
664  
665 -static void ath_cancel_work(struct ath_softc *sc)
666 +void ath_cancel_work(struct ath_softc *sc)
667  {
668         __ath_cancel_work(sc);
669         cancel_work_sync(&sc->hw_reset_work);
670  }
671  
672 -static void ath_restart_work(struct ath_softc *sc)
673 +void ath_restart_work(struct ath_softc *sc)
674  {
675         ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
676  
677 @@ -487,6 +504,8 @@ void ath9k_tasklet(unsigned long data)
678                         ath_tx_edma_tasklet(sc);
679                 else
680                         ath_tx_tasklet(sc);
681 +
682 +               wake_up(&sc->tx_wait);
683         }
684  
685         ath9k_btcoex_handle_interrupt(sc, status);
686 @@ -579,7 +598,8 @@ irqreturn_t ath_isr(int irq, void *dev)
687  
688                 goto chip_reset;
689         }
690 -#ifdef CONFIG_PM_SLEEP
691 +
692 +#ifdef CONFIG_ATH9K_WOW
693         if (status & ATH9K_INT_BMISS) {
694                 if (atomic_read(&sc->wow_sleep_proc_intr) == 0) {
695                         ath_dbg(common, ANY, "during WoW we got a BMISS\n");
696 @@ -588,6 +608,8 @@ irqreturn_t ath_isr(int irq, void *dev)
697                 }
698         }
699  #endif
700 +
701 +
702         if (status & ATH9K_INT_SWBA)
703                 tasklet_schedule(&sc->bcon_tasklet);
704  
705 @@ -627,7 +649,7 @@ chip_reset:
706  #undef SCHED_INTR
707  }
708  
709 -static int ath_reset(struct ath_softc *sc)
710 +int ath_reset(struct ath_softc *sc)
711  {
712         int r;
713  
714 @@ -1817,13 +1839,31 @@ static void ath9k_set_coverage_class(str
715         mutex_unlock(&sc->mutex);
716  }
717  
718 +static bool ath9k_has_tx_pending(struct ath_softc *sc)
719 +{
720 +       int i, npend;
721 +
722 +       for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
723 +               if (!ATH_TXQ_SETUP(sc, i))
724 +                       continue;
725 +
726 +               if (!sc->tx.txq[i].axq_depth)
727 +                       continue;
728 +
729 +               npend = ath9k_has_pending_frames(sc, &sc->tx.txq[i]);
730 +               if (npend)
731 +                       break;
732 +       }
733 +
734 +       return !!npend;
735 +}
736 +
737  static void ath9k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
738  {
739         struct ath_softc *sc = hw->priv;
740         struct ath_hw *ah = sc->sc_ah;
741         struct ath_common *common = ath9k_hw_common(ah);
742 -       int timeout = 200; /* ms */
743 -       int i, j;
744 +       int timeout = HZ / 5; /* 200 ms */
745         bool drain_txq;
746  
747         mutex_lock(&sc->mutex);
748 @@ -1841,25 +1881,9 @@ static void ath9k_flush(struct ieee80211
749                 return;
750         }
751  
752 -       for (j = 0; j < timeout; j++) {
753 -               bool npend = false;
754 -
755 -               if (j)
756 -                       usleep_range(1000, 2000);
757 -
758 -               for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
759 -                       if (!ATH_TXQ_SETUP(sc, i))
760 -                               continue;
761 -
762 -                       npend = ath9k_has_pending_frames(sc, &sc->tx.txq[i]);
763 -
764 -                       if (npend)
765 -                               break;
766 -               }
767 -
768 -               if (!npend)
769 -                   break;
770 -       }
771 +       if (wait_event_timeout(sc->tx_wait, !ath9k_has_tx_pending(sc),
772 +                              timeout) > 0)
773 +               drop = false;
774  
775         if (drop) {
776                 ath9k_ps_wakeup(sc);
777 @@ -2021,333 +2045,6 @@ static int ath9k_get_antenna(struct ieee
778         return 0;
779  }
780  
781 -#ifdef CONFIG_PM_SLEEP
782 -
783 -static void ath9k_wow_map_triggers(struct ath_softc *sc,
784 -                                  struct cfg80211_wowlan *wowlan,
785 -                                  u32 *wow_triggers)
786 -{
787 -       if (wowlan->disconnect)
788 -               *wow_triggers |= AH_WOW_LINK_CHANGE |
789 -                                AH_WOW_BEACON_MISS;
790 -       if (wowlan->magic_pkt)
791 -               *wow_triggers |= AH_WOW_MAGIC_PATTERN_EN;
792 -
793 -       if (wowlan->n_patterns)
794 -               *wow_triggers |= AH_WOW_USER_PATTERN_EN;
795 -
796 -       sc->wow_enabled = *wow_triggers;
797 -
798 -}
799 -
800 -static void ath9k_wow_add_disassoc_deauth_pattern(struct ath_softc *sc)
801 -{
802 -       struct ath_hw *ah = sc->sc_ah;
803 -       struct ath_common *common = ath9k_hw_common(ah);
804 -       int pattern_count = 0;
805 -       int i, byte_cnt;
806 -       u8 dis_deauth_pattern[MAX_PATTERN_SIZE];
807 -       u8 dis_deauth_mask[MAX_PATTERN_SIZE];
808 -
809 -       memset(dis_deauth_pattern, 0, MAX_PATTERN_SIZE);
810 -       memset(dis_deauth_mask, 0, MAX_PATTERN_SIZE);
811 -
812 -       /*
813 -        * Create Dissassociate / Deauthenticate packet filter
814 -        *
815 -        *     2 bytes        2 byte    6 bytes   6 bytes  6 bytes
816 -        *  +--------------+----------+---------+--------+--------+----
817 -        *  + Frame Control+ Duration +   DA    +  SA    +  BSSID +
818 -        *  +--------------+----------+---------+--------+--------+----
819 -        *
820 -        * The above is the management frame format for disassociate/
821 -        * deauthenticate pattern, from this we need to match the first byte
822 -        * of 'Frame Control' and DA, SA, and BSSID fields
823 -        * (skipping 2nd byte of FC and Duration feild.
824 -        *
825 -        * Disassociate pattern
826 -        * --------------------
827 -        * Frame control = 00 00 1010
828 -        * DA, SA, BSSID = x:x:x:x:x:x
829 -        * Pattern will be A0000000 | x:x:x:x:x:x | x:x:x:x:x:x
830 -        *                          | x:x:x:x:x:x  -- 22 bytes
831 -        *
832 -        * Deauthenticate pattern
833 -        * ----------------------
834 -        * Frame control = 00 00 1100
835 -        * DA, SA, BSSID = x:x:x:x:x:x
836 -        * Pattern will be C0000000 | x:x:x:x:x:x | x:x:x:x:x:x
837 -        *                          | x:x:x:x:x:x  -- 22 bytes
838 -        */
839 -
840 -       /* Create Disassociate Pattern first */
841 -
842 -       byte_cnt = 0;
843 -
844 -       /* Fill out the mask with all FF's */
845 -
846 -       for (i = 0; i < MAX_PATTERN_MASK_SIZE; i++)
847 -               dis_deauth_mask[i] = 0xff;
848 -
849 -       /* copy the first byte of frame control field */
850 -       dis_deauth_pattern[byte_cnt] = 0xa0;
851 -       byte_cnt++;
852 -
853 -       /* skip 2nd byte of frame control and Duration field */
854 -       byte_cnt += 3;
855 -
856 -       /*
857 -        * need not match the destination mac address, it can be a broadcast
858 -        * mac address or an unicast to this station
859 -        */
860 -       byte_cnt += 6;
861 -
862 -       /* copy the source mac address */
863 -       memcpy((dis_deauth_pattern + byte_cnt), common->curbssid, ETH_ALEN);
864 -
865 -       byte_cnt += 6;
866 -
867 -       /* copy the bssid, its same as the source mac address */
868 -
869 -       memcpy((dis_deauth_pattern + byte_cnt), common->curbssid, ETH_ALEN);
870 -
871 -       /* Create Disassociate pattern mask */
872 -
873 -       dis_deauth_mask[0] = 0xfe;
874 -       dis_deauth_mask[1] = 0x03;
875 -       dis_deauth_mask[2] = 0xc0;
876 -
877 -       ath_dbg(common, WOW, "Adding disassoc/deauth patterns for WoW\n");
878 -
879 -       ath9k_hw_wow_apply_pattern(ah, dis_deauth_pattern, dis_deauth_mask,
880 -                                  pattern_count, byte_cnt);
881 -
882 -       pattern_count++;
883 -       /*
884 -        * for de-authenticate pattern, only the first byte of the frame
885 -        * control field gets changed from 0xA0 to 0xC0
886 -        */
887 -       dis_deauth_pattern[0] = 0xC0;
888 -
889 -       ath9k_hw_wow_apply_pattern(ah, dis_deauth_pattern, dis_deauth_mask,
890 -                                  pattern_count, byte_cnt);
891 -
892 -}
893 -
894 -static void ath9k_wow_add_pattern(struct ath_softc *sc,
895 -                                 struct cfg80211_wowlan *wowlan)
896 -{
897 -       struct ath_hw *ah = sc->sc_ah;
898 -       struct ath9k_wow_pattern *wow_pattern = NULL;
899 -       struct cfg80211_pkt_pattern *patterns = wowlan->patterns;
900 -       int mask_len;
901 -       s8 i = 0;
902 -
903 -       if (!wowlan->n_patterns)
904 -               return;
905 -
906 -       /*
907 -        * Add the new user configured patterns
908 -        */
909 -       for (i = 0; i < wowlan->n_patterns; i++) {
910 -
911 -               wow_pattern = kzalloc(sizeof(*wow_pattern), GFP_KERNEL);
912 -
913 -               if (!wow_pattern)
914 -                       return;
915 -
916 -               /*
917 -                * TODO: convert the generic user space pattern to
918 -                * appropriate chip specific/802.11 pattern.
919 -                */
920 -
921 -               mask_len = DIV_ROUND_UP(wowlan->patterns[i].pattern_len, 8);
922 -               memset(wow_pattern->pattern_bytes, 0, MAX_PATTERN_SIZE);
923 -               memset(wow_pattern->mask_bytes, 0, MAX_PATTERN_SIZE);
924 -               memcpy(wow_pattern->pattern_bytes, patterns[i].pattern,
925 -                      patterns[i].pattern_len);
926 -               memcpy(wow_pattern->mask_bytes, patterns[i].mask, mask_len);
927 -               wow_pattern->pattern_len = patterns[i].pattern_len;
928 -
929 -               /*
930 -                * just need to take care of deauth and disssoc pattern,
931 -                * make sure we don't overwrite them.
932 -                */
933 -
934 -               ath9k_hw_wow_apply_pattern(ah, wow_pattern->pattern_bytes,
935 -                                          wow_pattern->mask_bytes,
936 -                                          i + 2,
937 -                                          wow_pattern->pattern_len);
938 -               kfree(wow_pattern);
939 -
940 -       }
941 -
942 -}
943 -
944 -static int ath9k_suspend(struct ieee80211_hw *hw,
945 -                        struct cfg80211_wowlan *wowlan)
946 -{
947 -       struct ath_softc *sc = hw->priv;
948 -       struct ath_hw *ah = sc->sc_ah;
949 -       struct ath_common *common = ath9k_hw_common(ah);
950 -       u32 wow_triggers_enabled = 0;
951 -       int ret = 0;
952 -
953 -       mutex_lock(&sc->mutex);
954 -
955 -       ath_cancel_work(sc);
956 -       ath_stop_ani(sc);
957 -       del_timer_sync(&sc->rx_poll_timer);
958 -
959 -       if (test_bit(SC_OP_INVALID, &sc->sc_flags)) {
960 -               ath_dbg(common, ANY, "Device not present\n");
961 -               ret = -EINVAL;
962 -               goto fail_wow;
963 -       }
964 -
965 -       if (WARN_ON(!wowlan)) {
966 -               ath_dbg(common, WOW, "None of the WoW triggers enabled\n");
967 -               ret = -EINVAL;
968 -               goto fail_wow;
969 -       }
970 -
971 -       if (!device_can_wakeup(sc->dev)) {
972 -               ath_dbg(common, WOW, "device_can_wakeup failed, WoW is not enabled\n");
973 -               ret = 1;
974 -               goto fail_wow;
975 -       }
976 -
977 -       /*
978 -        * none of the sta vifs are associated
979 -        * and we are not currently handling multivif
980 -        * cases, for instance we have to seperately
981 -        * configure 'keep alive frame' for each
982 -        * STA.
983 -        */
984 -
985 -       if (!test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags)) {
986 -               ath_dbg(common, WOW, "None of the STA vifs are associated\n");
987 -               ret = 1;
988 -               goto fail_wow;
989 -       }
990 -
991 -       if (sc->nvifs > 1) {
992 -               ath_dbg(common, WOW, "WoW for multivif is not yet supported\n");
993 -               ret = 1;
994 -               goto fail_wow;
995 -       }
996 -
997 -       ath9k_wow_map_triggers(sc, wowlan, &wow_triggers_enabled);
998 -
999 -       ath_dbg(common, WOW, "WoW triggers enabled 0x%x\n",
1000 -               wow_triggers_enabled);
1001 -
1002 -       ath9k_ps_wakeup(sc);
1003 -
1004 -       ath9k_stop_btcoex(sc);
1005 -
1006 -       /*
1007 -        * Enable wake up on recieving disassoc/deauth
1008 -        * frame by default.
1009 -        */
1010 -       ath9k_wow_add_disassoc_deauth_pattern(sc);
1011 -
1012 -       if (wow_triggers_enabled & AH_WOW_USER_PATTERN_EN)
1013 -               ath9k_wow_add_pattern(sc, wowlan);
1014 -
1015 -       spin_lock_bh(&sc->sc_pcu_lock);
1016 -       /*
1017 -        * To avoid false wake, we enable beacon miss interrupt only
1018 -        * when we go to sleep. We save the current interrupt mask
1019 -        * so we can restore it after the system wakes up
1020 -        */
1021 -       sc->wow_intr_before_sleep = ah->imask;
1022 -       ah->imask &= ~ATH9K_INT_GLOBAL;
1023 -       ath9k_hw_disable_interrupts(ah);
1024 -       ah->imask = ATH9K_INT_BMISS | ATH9K_INT_GLOBAL;
1025 -       ath9k_hw_set_interrupts(ah);
1026 -       ath9k_hw_enable_interrupts(ah);
1027 -
1028 -       spin_unlock_bh(&sc->sc_pcu_lock);
1029 -
1030 -       /*
1031 -        * we can now sync irq and kill any running tasklets, since we already
1032 -        * disabled interrupts and not holding a spin lock
1033 -        */
1034 -       synchronize_irq(sc->irq);
1035 -       tasklet_kill(&sc->intr_tq);
1036 -
1037 -       ath9k_hw_wow_enable(ah, wow_triggers_enabled);
1038 -
1039 -       ath9k_ps_restore(sc);
1040 -       ath_dbg(common, ANY, "WoW enabled in ath9k\n");
1041 -       atomic_inc(&sc->wow_sleep_proc_intr);
1042 -
1043 -fail_wow:
1044 -       mutex_unlock(&sc->mutex);
1045 -       return ret;
1046 -}
1047 -
1048 -static int ath9k_resume(struct ieee80211_hw *hw)
1049 -{
1050 -       struct ath_softc *sc = hw->priv;
1051 -       struct ath_hw *ah = sc->sc_ah;
1052 -       struct ath_common *common = ath9k_hw_common(ah);
1053 -       u32 wow_status;
1054 -
1055 -       mutex_lock(&sc->mutex);
1056 -
1057 -       ath9k_ps_wakeup(sc);
1058 -
1059 -       spin_lock_bh(&sc->sc_pcu_lock);
1060 -
1061 -       ath9k_hw_disable_interrupts(ah);
1062 -       ah->imask = sc->wow_intr_before_sleep;
1063 -       ath9k_hw_set_interrupts(ah);
1064 -       ath9k_hw_enable_interrupts(ah);
1065 -
1066 -       spin_unlock_bh(&sc->sc_pcu_lock);
1067 -
1068 -       wow_status = ath9k_hw_wow_wakeup(ah);
1069 -
1070 -       if (atomic_read(&sc->wow_got_bmiss_intr) == 0) {
1071 -               /*
1072 -                * some devices may not pick beacon miss
1073 -                * as the reason they woke up so we add
1074 -                * that here for that shortcoming.
1075 -                */
1076 -               wow_status |= AH_WOW_BEACON_MISS;
1077 -               atomic_dec(&sc->wow_got_bmiss_intr);
1078 -               ath_dbg(common, ANY, "Beacon miss interrupt picked up during WoW sleep\n");
1079 -       }
1080 -
1081 -       atomic_dec(&sc->wow_sleep_proc_intr);
1082 -
1083 -       if (wow_status) {
1084 -               ath_dbg(common, ANY, "Waking up due to WoW triggers %s with WoW status = %x\n",
1085 -                       ath9k_hw_wow_event_to_string(wow_status), wow_status);
1086 -       }
1087 -
1088 -       ath_restart_work(sc);
1089 -       ath9k_start_btcoex(sc);
1090 -
1091 -       ath9k_ps_restore(sc);
1092 -       mutex_unlock(&sc->mutex);
1093 -
1094 -       return 0;
1095 -}
1096 -
1097 -static void ath9k_set_wakeup(struct ieee80211_hw *hw, bool enabled)
1098 -{
1099 -       struct ath_softc *sc = hw->priv;
1100 -
1101 -       mutex_lock(&sc->mutex);
1102 -       device_init_wakeup(sc->dev, 1);
1103 -       device_set_wakeup_enable(sc->dev, enabled);
1104 -       mutex_unlock(&sc->mutex);
1105 -}
1106 -
1107 -#endif
1108  static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
1109  {
1110         struct ath_softc *sc = hw->priv;
1111 @@ -2373,134 +2070,6 @@ static void ath9k_channel_switch_beacon(
1112         sc->csa_vif = vif;
1113  }
1114  
1115 -static void ath9k_tx99_stop(struct ath_softc *sc)
1116 -{
1117 -       struct ath_hw *ah = sc->sc_ah;
1118 -       struct ath_common *common = ath9k_hw_common(ah);
1119 -
1120 -       ath_drain_all_txq(sc);
1121 -       ath_startrecv(sc);
1122 -
1123 -       ath9k_hw_set_interrupts(ah);
1124 -       ath9k_hw_enable_interrupts(ah);
1125 -
1126 -       ieee80211_wake_queues(sc->hw);
1127 -
1128 -       kfree_skb(sc->tx99_skb);
1129 -       sc->tx99_skb = NULL;
1130 -       sc->tx99_state = false;
1131 -
1132 -       ath9k_hw_tx99_stop(sc->sc_ah);
1133 -       ath_dbg(common, XMIT, "TX99 stopped\n");
1134 -}
1135 -
1136 -static struct sk_buff *ath9k_build_tx99_skb(struct ath_softc *sc)
1137 -{
1138 -       static u8 PN9Data[] = {0xff, 0x87, 0xb8, 0x59, 0xb7, 0xa1, 0xcc, 0x24,
1139 -                              0x57, 0x5e, 0x4b, 0x9c, 0x0e, 0xe9, 0xea, 0x50,
1140 -                              0x2a, 0xbe, 0xb4, 0x1b, 0xb6, 0xb0, 0x5d, 0xf1,
1141 -                              0xe6, 0x9a, 0xe3, 0x45, 0xfd, 0x2c, 0x53, 0x18,
1142 -                              0x0c, 0xca, 0xc9, 0xfb, 0x49, 0x37, 0xe5, 0xa8,
1143 -                              0x51, 0x3b, 0x2f, 0x61, 0xaa, 0x72, 0x18, 0x84,
1144 -                              0x02, 0x23, 0x23, 0xab, 0x63, 0x89, 0x51, 0xb3,
1145 -                              0xe7, 0x8b, 0x72, 0x90, 0x4c, 0xe8, 0xfb, 0xc0};
1146 -       u32 len = 1200;
1147 -       struct ieee80211_hw *hw = sc->hw;
1148 -       struct ieee80211_hdr *hdr;
1149 -       struct ieee80211_tx_info *tx_info;
1150 -       struct sk_buff *skb;
1151 -
1152 -       skb = alloc_skb(len, GFP_KERNEL);
1153 -       if (!skb)
1154 -               return NULL;
1155 -
1156 -       skb_put(skb, len);
1157 -
1158 -       memset(skb->data, 0, len);
1159 -
1160 -       hdr = (struct ieee80211_hdr *)skb->data;
1161 -       hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA);
1162 -       hdr->duration_id = 0;
1163 -
1164 -       memcpy(hdr->addr1, hw->wiphy->perm_addr, ETH_ALEN);
1165 -       memcpy(hdr->addr2, hw->wiphy->perm_addr, ETH_ALEN);
1166 -       memcpy(hdr->addr3, hw->wiphy->perm_addr, ETH_ALEN);
1167 -
1168 -       hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
1169 -
1170 -       tx_info = IEEE80211_SKB_CB(skb);
1171 -       memset(tx_info, 0, sizeof(*tx_info));
1172 -       tx_info->band = hw->conf.chandef.chan->band;
1173 -       tx_info->flags = IEEE80211_TX_CTL_NO_ACK;
1174 -       tx_info->control.vif = sc->tx99_vif;
1175 -
1176 -       memcpy(skb->data + sizeof(*hdr), PN9Data, sizeof(PN9Data));
1177 -
1178 -       return skb;
1179 -}
1180 -
1181 -void ath9k_tx99_deinit(struct ath_softc *sc)
1182 -{
1183 -       ath_reset(sc);
1184 -
1185 -       ath9k_ps_wakeup(sc);
1186 -       ath9k_tx99_stop(sc);
1187 -       ath9k_ps_restore(sc);
1188 -}
1189 -
1190 -int ath9k_tx99_init(struct ath_softc *sc)
1191 -{
1192 -       struct ieee80211_hw *hw = sc->hw;
1193 -       struct ath_hw *ah = sc->sc_ah;
1194 -       struct ath_common *common = ath9k_hw_common(ah);
1195 -       struct ath_tx_control txctl;
1196 -       int r;
1197 -
1198 -       if (sc->sc_flags & SC_OP_INVALID) {
1199 -               ath_err(common,
1200 -                       "driver is in invalid state unable to use TX99");
1201 -               return -EINVAL;
1202 -       }
1203 -
1204 -       sc->tx99_skb = ath9k_build_tx99_skb(sc);
1205 -       if (!sc->tx99_skb)
1206 -               return -ENOMEM;
1207 -
1208 -       memset(&txctl, 0, sizeof(txctl));
1209 -       txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO];
1210 -
1211 -       ath_reset(sc);
1212 -
1213 -       ath9k_ps_wakeup(sc);
1214 -
1215 -       ath9k_hw_disable_interrupts(ah);
1216 -       atomic_set(&ah->intr_ref_cnt, -1);
1217 -       ath_drain_all_txq(sc);
1218 -       ath_stoprecv(sc);
1219 -
1220 -       sc->tx99_state = true;
1221 -
1222 -       ieee80211_stop_queues(hw);
1223 -
1224 -       if (sc->tx99_power == MAX_RATE_POWER + 1)
1225 -               sc->tx99_power = MAX_RATE_POWER;
1226 -
1227 -       ath9k_hw_tx99_set_txpower(ah, sc->tx99_power);
1228 -       r = ath9k_tx99_send(sc, sc->tx99_skb, &txctl);
1229 -       if (r) {
1230 -               ath_dbg(common, XMIT, "Failed to xmit TX99 skb\n");
1231 -               return r;
1232 -       }
1233 -
1234 -       ath_dbg(common, XMIT, "TX99 xmit started using %d ( %ddBm)\n",
1235 -               sc->tx99_power,
1236 -               sc->tx99_power / 2);
1237 -
1238 -       /* We leave the harware awake as it will be chugging on */
1239 -
1240 -       return 0;
1241 -}
1242 -
1243  struct ieee80211_ops ath9k_ops = {
1244         .tx                 = ath9k_tx,
1245         .start              = ath9k_start,
1246 @@ -2531,7 +2100,7 @@ struct ieee80211_ops ath9k_ops = {
1247         .set_antenna        = ath9k_set_antenna,
1248         .get_antenna        = ath9k_get_antenna,
1249  
1250 -#ifdef CONFIG_PM_SLEEP
1251 +#ifdef CONFIG_ATH9K_WOW
1252         .suspend            = ath9k_suspend,
1253         .resume             = ath9k_resume,
1254         .set_wakeup         = ath9k_set_wakeup,
1255 --- a/drivers/net/wireless/ath/ath9k/wow.c
1256 +++ b/drivers/net/wireless/ath/ath9k/wow.c
1257 @@ -1,5 +1,5 @@
1258  /*
1259 - * Copyright (c) 2012 Qualcomm Atheros, Inc.
1260 + * Copyright (c) 2013 Qualcomm Atheros, Inc.
1261   *
1262   * Permission to use, copy, modify, and/or distribute this software for any
1263   * purpose with or without fee is hereby granted, provided that the above
1264 @@ -14,409 +14,348 @@
1265   * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1266   */
1267  
1268 -#include <linux/export.h>
1269  #include "ath9k.h"
1270 -#include "reg.h"
1271 -#include "hw-ops.h"
1272  
1273 -const char *ath9k_hw_wow_event_to_string(u32 wow_event)
1274 +static const struct wiphy_wowlan_support ath9k_wowlan_support = {
1275 +       .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT,
1276 +       .n_patterns = MAX_NUM_USER_PATTERN,
1277 +       .pattern_min_len = 1,
1278 +       .pattern_max_len = MAX_PATTERN_SIZE,
1279 +};
1280 +
1281 +static void ath9k_wow_map_triggers(struct ath_softc *sc,
1282 +                                  struct cfg80211_wowlan *wowlan,
1283 +                                  u32 *wow_triggers)
1284  {
1285 -       if (wow_event & AH_WOW_MAGIC_PATTERN_EN)
1286 -               return "Magic pattern";
1287 -       if (wow_event & AH_WOW_USER_PATTERN_EN)
1288 -               return "User pattern";
1289 -       if (wow_event & AH_WOW_LINK_CHANGE)
1290 -               return "Link change";
1291 -       if (wow_event & AH_WOW_BEACON_MISS)
1292 -               return "Beacon miss";
1293 +       if (wowlan->disconnect)
1294 +               *wow_triggers |= AH_WOW_LINK_CHANGE |
1295 +                                AH_WOW_BEACON_MISS;
1296 +       if (wowlan->magic_pkt)
1297 +               *wow_triggers |= AH_WOW_MAGIC_PATTERN_EN;
1298 +
1299 +       if (wowlan->n_patterns)
1300 +               *wow_triggers |= AH_WOW_USER_PATTERN_EN;
1301 +
1302 +       sc->wow_enabled = *wow_triggers;
1303  
1304 -       return  "unknown reason";
1305  }
1306 -EXPORT_SYMBOL(ath9k_hw_wow_event_to_string);
1307  
1308 -static void ath9k_hw_set_powermode_wow_sleep(struct ath_hw *ah)
1309 +static void ath9k_wow_add_disassoc_deauth_pattern(struct ath_softc *sc)
1310  {
1311 +       struct ath_hw *ah = sc->sc_ah;
1312         struct ath_common *common = ath9k_hw_common(ah);
1313 +       int pattern_count = 0;
1314 +       int i, byte_cnt;
1315 +       u8 dis_deauth_pattern[MAX_PATTERN_SIZE];
1316 +       u8 dis_deauth_mask[MAX_PATTERN_SIZE];
1317  
1318 -       REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1319 +       memset(dis_deauth_pattern, 0, MAX_PATTERN_SIZE);
1320 +       memset(dis_deauth_mask, 0, MAX_PATTERN_SIZE);
1321  
1322 -       /* set rx disable bit */
1323 -       REG_WRITE(ah, AR_CR, AR_CR_RXD);
1324 +       /*
1325 +        * Create Dissassociate / Deauthenticate packet filter
1326 +        *
1327 +        *     2 bytes        2 byte    6 bytes   6 bytes  6 bytes
1328 +        *  +--------------+----------+---------+--------+--------+----
1329 +        *  + Frame Control+ Duration +   DA    +  SA    +  BSSID +
1330 +        *  +--------------+----------+---------+--------+--------+----
1331 +        *
1332 +        * The above is the management frame format for disassociate/
1333 +        * deauthenticate pattern, from this we need to match the first byte
1334 +        * of 'Frame Control' and DA, SA, and BSSID fields
1335 +        * (skipping 2nd byte of FC and Duration feild.
1336 +        *
1337 +        * Disassociate pattern
1338 +        * --------------------
1339 +        * Frame control = 00 00 1010
1340 +        * DA, SA, BSSID = x:x:x:x:x:x
1341 +        * Pattern will be A0000000 | x:x:x:x:x:x | x:x:x:x:x:x
1342 +        *                          | x:x:x:x:x:x  -- 22 bytes
1343 +        *
1344 +        * Deauthenticate pattern
1345 +        * ----------------------
1346 +        * Frame control = 00 00 1100
1347 +        * DA, SA, BSSID = x:x:x:x:x:x
1348 +        * Pattern will be C0000000 | x:x:x:x:x:x | x:x:x:x:x:x
1349 +        *                          | x:x:x:x:x:x  -- 22 bytes
1350 +        */
1351  
1352 -       if (!ath9k_hw_wait(ah, AR_CR, AR_CR_RXE, 0, AH_WAIT_TIMEOUT)) {
1353 -               ath_err(common, "Failed to stop Rx DMA in 10ms AR_CR=0x%08x AR_DIAG_SW=0x%08x\n",
1354 -                       REG_READ(ah, AR_CR), REG_READ(ah, AR_DIAG_SW));
1355 -               return;
1356 -       }
1357 +       /* Create Disassociate Pattern first */
1358  
1359 -       REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_ON_INT);
1360 -}
1361 +       byte_cnt = 0;
1362  
1363 -static void ath9k_wow_create_keep_alive_pattern(struct ath_hw *ah)
1364 -{
1365 -       struct ath_common *common = ath9k_hw_common(ah);
1366 -       u8 sta_mac_addr[ETH_ALEN], ap_mac_addr[ETH_ALEN];
1367 -       u32 ctl[13] = {0};
1368 -       u32 data_word[KAL_NUM_DATA_WORDS];
1369 -       u8 i;
1370 -       u32 wow_ka_data_word0;
1371 -
1372 -       memcpy(sta_mac_addr, common->macaddr, ETH_ALEN);
1373 -       memcpy(ap_mac_addr, common->curbssid, ETH_ALEN);
1374 -
1375 -       /* set the transmit buffer */
1376 -       ctl[0] = (KAL_FRAME_LEN | (MAX_RATE_POWER << 16));
1377 -       ctl[1] = 0;
1378 -       ctl[3] = 0xb;   /* OFDM_6M hardware value for this rate */
1379 -       ctl[4] = 0;
1380 -       ctl[7] = (ah->txchainmask) << 2;
1381 -       ctl[2] = 0xf << 16; /* tx_tries 0 */
1382 -
1383 -       for (i = 0; i < KAL_NUM_DESC_WORDS; i++)
1384 -               REG_WRITE(ah, (AR_WOW_KA_DESC_WORD2 + i * 4), ctl[i]);
1385 -
1386 -       REG_WRITE(ah, (AR_WOW_KA_DESC_WORD2 + i * 4), ctl[i]);
1387 -
1388 -       data_word[0] = (KAL_FRAME_TYPE << 2) | (KAL_FRAME_SUB_TYPE << 4) |
1389 -                      (KAL_TO_DS << 8) | (KAL_DURATION_ID << 16);
1390 -       data_word[1] = (ap_mac_addr[3] << 24) | (ap_mac_addr[2] << 16) |
1391 -                      (ap_mac_addr[1] << 8) | (ap_mac_addr[0]);
1392 -       data_word[2] = (sta_mac_addr[1] << 24) | (sta_mac_addr[0] << 16) |
1393 -                      (ap_mac_addr[5] << 8) | (ap_mac_addr[4]);
1394 -       data_word[3] = (sta_mac_addr[5] << 24) | (sta_mac_addr[4] << 16) |
1395 -                      (sta_mac_addr[3] << 8) | (sta_mac_addr[2]);
1396 -       data_word[4] = (ap_mac_addr[3] << 24) | (ap_mac_addr[2] << 16) |
1397 -                      (ap_mac_addr[1] << 8) | (ap_mac_addr[0]);
1398 -       data_word[5] = (ap_mac_addr[5] << 8) | (ap_mac_addr[4]);
1399 -
1400 -       if (AR_SREV_9462_20(ah)) {
1401 -               /* AR9462 2.0 has an extra descriptor word (time based
1402 -                * discard) compared to other chips */
1403 -               REG_WRITE(ah, (AR_WOW_KA_DESC_WORD2 + (12 * 4)), 0);
1404 -               wow_ka_data_word0 = AR_WOW_TXBUF(13);
1405 -       } else {
1406 -               wow_ka_data_word0 = AR_WOW_TXBUF(12);
1407 -       }
1408 +       /* Fill out the mask with all FF's */
1409  
1410 -       for (i = 0; i < KAL_NUM_DATA_WORDS; i++)
1411 -               REG_WRITE(ah, (wow_ka_data_word0 + i*4), data_word[i]);
1412 +       for (i = 0; i < MAX_PATTERN_MASK_SIZE; i++)
1413 +               dis_deauth_mask[i] = 0xff;
1414  
1415 -}
1416 +       /* copy the first byte of frame control field */
1417 +       dis_deauth_pattern[byte_cnt] = 0xa0;
1418 +       byte_cnt++;
1419  
1420 -void ath9k_hw_wow_apply_pattern(struct ath_hw *ah, u8 *user_pattern,
1421 -                               u8 *user_mask, int pattern_count,
1422 -                               int pattern_len)
1423 -{
1424 -       int i;
1425 -       u32 pattern_val, mask_val;
1426 -       u32 set, clr;
1427 +       /* skip 2nd byte of frame control and Duration field */
1428 +       byte_cnt += 3;
1429  
1430 -       /* FIXME: should check count by querying the hardware capability */
1431 -       if (pattern_count >= MAX_NUM_PATTERN)
1432 -               return;
1433 +       /*
1434 +        * need not match the destination mac address, it can be a broadcast
1435 +        * mac address or an unicast to this station
1436 +        */
1437 +       byte_cnt += 6;
1438  
1439 -       REG_SET_BIT(ah, AR_WOW_PATTERN, BIT(pattern_count));
1440 +       /* copy the source mac address */
1441 +       memcpy((dis_deauth_pattern + byte_cnt), common->curbssid, ETH_ALEN);
1442  
1443 -       /* set the registers for pattern */
1444 -       for (i = 0; i < MAX_PATTERN_SIZE; i += 4) {
1445 -               memcpy(&pattern_val, user_pattern, 4);
1446 -               REG_WRITE(ah, (AR_WOW_TB_PATTERN(pattern_count) + i),
1447 -                         pattern_val);
1448 -               user_pattern += 4;
1449 -       }
1450 +       byte_cnt += 6;
1451  
1452 -       /* set the registers for mask */
1453 -       for (i = 0; i < MAX_PATTERN_MASK_SIZE; i += 4) {
1454 -               memcpy(&mask_val, user_mask, 4);
1455 -               REG_WRITE(ah, (AR_WOW_TB_MASK(pattern_count) + i), mask_val);
1456 -               user_mask += 4;
1457 -       }
1458 +       /* copy the bssid, its same as the source mac address */
1459  
1460 -       /* set the pattern length to be matched
1461 -        *
1462 -        * AR_WOW_LENGTH1_REG1
1463 -        * bit 31:24 pattern 0 length
1464 -        * bit 23:16 pattern 1 length
1465 -        * bit 15:8 pattern 2 length
1466 -        * bit 7:0 pattern 3 length
1467 -        *
1468 -        * AR_WOW_LENGTH1_REG2
1469 -        * bit 31:24 pattern 4 length
1470 -        * bit 23:16 pattern 5 length
1471 -        * bit 15:8 pattern 6 length
1472 -        * bit 7:0 pattern 7 length
1473 -        *
1474 -        * the below logic writes out the new
1475 -        * pattern length for the corresponding
1476 -        * pattern_count, while masking out the
1477 -        * other fields
1478 -        */
1479 +       memcpy((dis_deauth_pattern + byte_cnt), common->curbssid, ETH_ALEN);
1480  
1481 -       ah->wow_event_mask |= BIT(pattern_count + AR_WOW_PAT_FOUND_SHIFT);
1482 +       /* Create Disassociate pattern mask */
1483  
1484 -       if (pattern_count < 4) {
1485 -               /* Pattern 0-3 uses AR_WOW_LENGTH1 register */
1486 -               set = (pattern_len & AR_WOW_LENGTH_MAX) <<
1487 -                      AR_WOW_LEN1_SHIFT(pattern_count);
1488 -               clr = AR_WOW_LENGTH1_MASK(pattern_count);
1489 -               REG_RMW(ah, AR_WOW_LENGTH1, set, clr);
1490 -       } else {
1491 -               /* Pattern 4-7 uses AR_WOW_LENGTH2 register */
1492 -               set = (pattern_len & AR_WOW_LENGTH_MAX) <<
1493 -                      AR_WOW_LEN2_SHIFT(pattern_count);
1494 -               clr = AR_WOW_LENGTH2_MASK(pattern_count);
1495 -               REG_RMW(ah, AR_WOW_LENGTH2, set, clr);
1496 -       }
1497 +       dis_deauth_mask[0] = 0xfe;
1498 +       dis_deauth_mask[1] = 0x03;
1499 +       dis_deauth_mask[2] = 0xc0;
1500  
1501 -}
1502 -EXPORT_SYMBOL(ath9k_hw_wow_apply_pattern);
1503 +       ath_dbg(common, WOW, "Adding disassoc/deauth patterns for WoW\n");
1504  
1505 -u32 ath9k_hw_wow_wakeup(struct ath_hw *ah)
1506 -{
1507 -       u32 wow_status = 0;
1508 -       u32 val = 0, rval;
1509 +       ath9k_hw_wow_apply_pattern(ah, dis_deauth_pattern, dis_deauth_mask,
1510 +                                  pattern_count, byte_cnt);
1511  
1512 +       pattern_count++;
1513         /*
1514 -        * read the WoW status register to know
1515 -        * the wakeup reason
1516 +        * for de-authenticate pattern, only the first byte of the frame
1517 +        * control field gets changed from 0xA0 to 0xC0
1518          */
1519 -       rval = REG_READ(ah, AR_WOW_PATTERN);
1520 -       val = AR_WOW_STATUS(rval);
1521 +       dis_deauth_pattern[0] = 0xC0;
1522  
1523 -       /*
1524 -        * mask only the WoW events that we have enabled. Sometimes
1525 -        * we have spurious WoW events from the AR_WOW_PATTERN
1526 -        * register. This mask will clean it up.
1527 -        */
1528 +       ath9k_hw_wow_apply_pattern(ah, dis_deauth_pattern, dis_deauth_mask,
1529 +                                  pattern_count, byte_cnt);
1530  
1531 -       val &= ah->wow_event_mask;
1532 +}
1533  
1534 -       if (val) {
1535 -               if (val & AR_WOW_MAGIC_PAT_FOUND)
1536 -                       wow_status |= AH_WOW_MAGIC_PATTERN_EN;
1537 -               if (AR_WOW_PATTERN_FOUND(val))
1538 -                       wow_status |= AH_WOW_USER_PATTERN_EN;
1539 -               if (val & AR_WOW_KEEP_ALIVE_FAIL)
1540 -                       wow_status |= AH_WOW_LINK_CHANGE;
1541 -               if (val & AR_WOW_BEACON_FAIL)
1542 -                       wow_status |= AH_WOW_BEACON_MISS;
1543 -       }
1544 +static void ath9k_wow_add_pattern(struct ath_softc *sc,
1545 +                                 struct cfg80211_wowlan *wowlan)
1546 +{
1547 +       struct ath_hw *ah = sc->sc_ah;
1548 +       struct ath9k_wow_pattern *wow_pattern = NULL;
1549 +       struct cfg80211_pkt_pattern *patterns = wowlan->patterns;
1550 +       int mask_len;
1551 +       s8 i = 0;
1552 +
1553 +       if (!wowlan->n_patterns)
1554 +               return;
1555  
1556         /*
1557 -        * set and clear WOW_PME_CLEAR registers for the chip to
1558 -        * generate next wow signal.
1559 -        * disable D3 before accessing other registers ?
1560 +        * Add the new user configured patterns
1561          */
1562 +       for (i = 0; i < wowlan->n_patterns; i++) {
1563  
1564 -       /* do we need to check the bit value 0x01000000 (7-10) ?? */
1565 -       REG_RMW(ah, AR_PCIE_PM_CTRL, AR_PMCTRL_WOW_PME_CLR,
1566 -               AR_PMCTRL_PWR_STATE_D1D3);
1567 +               wow_pattern = kzalloc(sizeof(*wow_pattern), GFP_KERNEL);
1568  
1569 -       /*
1570 -        * clear all events
1571 -        */
1572 -       REG_WRITE(ah, AR_WOW_PATTERN,
1573 -                 AR_WOW_CLEAR_EVENTS(REG_READ(ah, AR_WOW_PATTERN)));
1574 +               if (!wow_pattern)
1575 +                       return;
1576  
1577 -       /*
1578 -        * restore the beacon threshold to init value
1579 -        */
1580 -       REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
1581 +               /*
1582 +                * TODO: convert the generic user space pattern to
1583 +                * appropriate chip specific/802.11 pattern.
1584 +                */
1585  
1586 -       /*
1587 -        * Restore the way the PCI-E reset, Power-On-Reset, external
1588 -        * PCIE_POR_SHORT pins are tied to its original value.
1589 -        * Previously just before WoW sleep, we untie the PCI-E
1590 -        * reset to our Chip's Power On Reset so that any PCI-E
1591 -        * reset from the bus will not reset our chip
1592 -        */
1593 -       if (ah->is_pciexpress)
1594 -               ath9k_hw_configpcipowersave(ah, false);
1595 +               mask_len = DIV_ROUND_UP(wowlan->patterns[i].pattern_len, 8);
1596 +               memset(wow_pattern->pattern_bytes, 0, MAX_PATTERN_SIZE);
1597 +               memset(wow_pattern->mask_bytes, 0, MAX_PATTERN_SIZE);
1598 +               memcpy(wow_pattern->pattern_bytes, patterns[i].pattern,
1599 +                      patterns[i].pattern_len);
1600 +               memcpy(wow_pattern->mask_bytes, patterns[i].mask, mask_len);
1601 +               wow_pattern->pattern_len = patterns[i].pattern_len;
1602 +
1603 +               /*
1604 +                * just need to take care of deauth and disssoc pattern,
1605 +                * make sure we don't overwrite them.
1606 +                */
1607 +
1608 +               ath9k_hw_wow_apply_pattern(ah, wow_pattern->pattern_bytes,
1609 +                                          wow_pattern->mask_bytes,
1610 +                                          i + 2,
1611 +                                          wow_pattern->pattern_len);
1612 +               kfree(wow_pattern);
1613  
1614 -       ah->wow_event_mask = 0;
1615 +       }
1616  
1617 -       return wow_status;
1618  }
1619 -EXPORT_SYMBOL(ath9k_hw_wow_wakeup);
1620  
1621 -void ath9k_hw_wow_enable(struct ath_hw *ah, u32 pattern_enable)
1622 +int ath9k_suspend(struct ieee80211_hw *hw,
1623 +                 struct cfg80211_wowlan *wowlan)
1624  {
1625 -       u32 wow_event_mask;
1626 -       u32 set, clr;
1627 +       struct ath_softc *sc = hw->priv;
1628 +       struct ath_hw *ah = sc->sc_ah;
1629 +       struct ath_common *common = ath9k_hw_common(ah);
1630 +       u32 wow_triggers_enabled = 0;
1631 +       int ret = 0;
1632  
1633 -       /*
1634 -        * wow_event_mask is a mask to the AR_WOW_PATTERN register to
1635 -        * indicate which WoW events we have enabled. The WoW events
1636 -        * are from the 'pattern_enable' in this function and
1637 -        * 'pattern_count' of ath9k_hw_wow_apply_pattern()
1638 -        */
1639 -       wow_event_mask = ah->wow_event_mask;
1640 +       mutex_lock(&sc->mutex);
1641  
1642 -       /*
1643 -        * Untie Power-on-Reset from the PCI-E-Reset. When we are in
1644 -        * WOW sleep, we do want the Reset from the PCI-E to disturb
1645 -        * our hw state
1646 -        */
1647 -       if (ah->is_pciexpress) {
1648 -               /*
1649 -                * we need to untie the internal POR (power-on-reset)
1650 -                * to the external PCI-E reset. We also need to tie
1651 -                * the PCI-E Phy reset to the PCI-E reset.
1652 -                */
1653 -               set = AR_WA_RESET_EN | AR_WA_POR_SHORT;
1654 -               clr = AR_WA_UNTIE_RESET_EN | AR_WA_D3_L1_DISABLE;
1655 -               REG_RMW(ah, AR_WA, set, clr);
1656 +       ath_cancel_work(sc);
1657 +       ath_stop_ani(sc);
1658 +       del_timer_sync(&sc->rx_poll_timer);
1659 +
1660 +       if (test_bit(SC_OP_INVALID, &sc->sc_flags)) {
1661 +               ath_dbg(common, ANY, "Device not present\n");
1662 +               ret = -EINVAL;
1663 +               goto fail_wow;
1664         }
1665  
1666 -       /*
1667 -        * set the power states appropriately and enable PME
1668 -        */
1669 -       set = AR_PMCTRL_HOST_PME_EN | AR_PMCTRL_PWR_PM_CTRL_ENA |
1670 -             AR_PMCTRL_AUX_PWR_DET | AR_PMCTRL_WOW_PME_CLR;
1671 +       if (WARN_ON(!wowlan)) {
1672 +               ath_dbg(common, WOW, "None of the WoW triggers enabled\n");
1673 +               ret = -EINVAL;
1674 +               goto fail_wow;
1675 +       }
1676  
1677 -       /*
1678 -        * set and clear WOW_PME_CLEAR registers for the chip
1679 -        * to generate next wow signal.
1680 -        */
1681 -       REG_SET_BIT(ah, AR_PCIE_PM_CTRL, set);
1682 -       clr = AR_PMCTRL_WOW_PME_CLR;
1683 -       REG_CLR_BIT(ah, AR_PCIE_PM_CTRL, clr);
1684 +       if (!device_can_wakeup(sc->dev)) {
1685 +               ath_dbg(common, WOW, "device_can_wakeup failed, WoW is not enabled\n");
1686 +               ret = 1;
1687 +               goto fail_wow;
1688 +       }
1689  
1690         /*
1691 -        * Setup for:
1692 -        *      - beacon misses
1693 -        *      - magic pattern
1694 -        *      - keep alive timeout
1695 -        *      - pattern matching
1696 +        * none of the sta vifs are associated
1697 +        * and we are not currently handling multivif
1698 +        * cases, for instance we have to seperately
1699 +        * configure 'keep alive frame' for each
1700 +        * STA.
1701          */
1702  
1703 -       /*
1704 -        * Program default values for pattern backoff, aifs/slot/KAL count,
1705 -        * beacon miss timeout, KAL timeout, etc.
1706 -        */
1707 -       set = AR_WOW_BACK_OFF_SHIFT(AR_WOW_PAT_BACKOFF);
1708 -       REG_SET_BIT(ah, AR_WOW_PATTERN, set);
1709 +       if (!test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags)) {
1710 +               ath_dbg(common, WOW, "None of the STA vifs are associated\n");
1711 +               ret = 1;
1712 +               goto fail_wow;
1713 +       }
1714 +
1715 +       if (sc->nvifs > 1) {
1716 +               ath_dbg(common, WOW, "WoW for multivif is not yet supported\n");
1717 +               ret = 1;
1718 +               goto fail_wow;
1719 +       }
1720  
1721 -       set = AR_WOW_AIFS_CNT(AR_WOW_CNT_AIFS_CNT) |
1722 -             AR_WOW_SLOT_CNT(AR_WOW_CNT_SLOT_CNT) |
1723 -             AR_WOW_KEEP_ALIVE_CNT(AR_WOW_CNT_KA_CNT);
1724 -       REG_SET_BIT(ah, AR_WOW_COUNT, set);
1725 -
1726 -       if (pattern_enable & AH_WOW_BEACON_MISS)
1727 -               set = AR_WOW_BEACON_TIMO;
1728 -       /* We are not using beacon miss, program a large value */
1729 -       else
1730 -               set = AR_WOW_BEACON_TIMO_MAX;
1731 +       ath9k_wow_map_triggers(sc, wowlan, &wow_triggers_enabled);
1732  
1733 -       REG_WRITE(ah, AR_WOW_BCN_TIMO, set);
1734 +       ath_dbg(common, WOW, "WoW triggers enabled 0x%x\n",
1735 +               wow_triggers_enabled);
1736  
1737 -       /*
1738 -        * Keep alive timo in ms except AR9280
1739 -        */
1740 -       if (!pattern_enable)
1741 -               set = AR_WOW_KEEP_ALIVE_NEVER;
1742 -       else
1743 -               set = KAL_TIMEOUT * 32;
1744 +       ath9k_ps_wakeup(sc);
1745  
1746 -       REG_WRITE(ah, AR_WOW_KEEP_ALIVE_TIMO, set);
1747 +       ath9k_stop_btcoex(sc);
1748  
1749         /*
1750 -        * Keep alive delay in us. based on 'power on clock',
1751 -        * therefore in usec
1752 +        * Enable wake up on recieving disassoc/deauth
1753 +        * frame by default.
1754          */
1755 -       set = KAL_DELAY * 1000;
1756 -       REG_WRITE(ah, AR_WOW_KEEP_ALIVE_DELAY, set);
1757 +       ath9k_wow_add_disassoc_deauth_pattern(sc);
1758  
1759 -       /*
1760 -        * Create keep alive pattern to respond to beacons
1761 -        */
1762 -       ath9k_wow_create_keep_alive_pattern(ah);
1763 +       if (wow_triggers_enabled & AH_WOW_USER_PATTERN_EN)
1764 +               ath9k_wow_add_pattern(sc, wowlan);
1765  
1766 +       spin_lock_bh(&sc->sc_pcu_lock);
1767         /*
1768 -        * Configure MAC WoW Registers
1769 +        * To avoid false wake, we enable beacon miss interrupt only
1770 +        * when we go to sleep. We save the current interrupt mask
1771 +        * so we can restore it after the system wakes up
1772          */
1773 -       set = 0;
1774 -       /* Send keep alive timeouts anyway */
1775 -       clr = AR_WOW_KEEP_ALIVE_AUTO_DIS;
1776 -
1777 -       if (pattern_enable & AH_WOW_LINK_CHANGE)
1778 -               wow_event_mask |= AR_WOW_KEEP_ALIVE_FAIL;
1779 -       else
1780 -               set = AR_WOW_KEEP_ALIVE_FAIL_DIS;
1781 +       sc->wow_intr_before_sleep = ah->imask;
1782 +       ah->imask &= ~ATH9K_INT_GLOBAL;
1783 +       ath9k_hw_disable_interrupts(ah);
1784 +       ah->imask = ATH9K_INT_BMISS | ATH9K_INT_GLOBAL;
1785 +       ath9k_hw_set_interrupts(ah);
1786 +       ath9k_hw_enable_interrupts(ah);
1787  
1788 -       set = AR_WOW_KEEP_ALIVE_FAIL_DIS;
1789 -       REG_RMW(ah, AR_WOW_KEEP_ALIVE, set, clr);
1790 +       spin_unlock_bh(&sc->sc_pcu_lock);
1791  
1792         /*
1793 -        * we are relying on a bmiss failure. ensure we have
1794 -        * enough threshold to prevent false positives
1795 +        * we can now sync irq and kill any running tasklets, since we already
1796 +        * disabled interrupts and not holding a spin lock
1797          */
1798 -       REG_RMW_FIELD(ah, AR_RSSI_THR, AR_RSSI_THR_BM_THR,
1799 -                     AR_WOW_BMISSTHRESHOLD);
1800 +       synchronize_irq(sc->irq);
1801 +       tasklet_kill(&sc->intr_tq);
1802 +
1803 +       ath9k_hw_wow_enable(ah, wow_triggers_enabled);
1804  
1805 -       set = 0;
1806 -       clr = 0;
1807 +       ath9k_ps_restore(sc);
1808 +       ath_dbg(common, ANY, "WoW enabled in ath9k\n");
1809 +       atomic_inc(&sc->wow_sleep_proc_intr);
1810  
1811 -       if (pattern_enable & AH_WOW_BEACON_MISS) {
1812 -               set = AR_WOW_BEACON_FAIL_EN;
1813 -               wow_event_mask |= AR_WOW_BEACON_FAIL;
1814 -       } else {
1815 -               clr = AR_WOW_BEACON_FAIL_EN;
1816 +fail_wow:
1817 +       mutex_unlock(&sc->mutex);
1818 +       return ret;
1819 +}
1820 +
1821 +int ath9k_resume(struct ieee80211_hw *hw)
1822 +{
1823 +       struct ath_softc *sc = hw->priv;
1824 +       struct ath_hw *ah = sc->sc_ah;
1825 +       struct ath_common *common = ath9k_hw_common(ah);
1826 +       u32 wow_status;
1827 +
1828 +       mutex_lock(&sc->mutex);
1829 +
1830 +       ath9k_ps_wakeup(sc);
1831 +
1832 +       spin_lock_bh(&sc->sc_pcu_lock);
1833 +
1834 +       ath9k_hw_disable_interrupts(ah);
1835 +       ah->imask = sc->wow_intr_before_sleep;
1836 +       ath9k_hw_set_interrupts(ah);
1837 +       ath9k_hw_enable_interrupts(ah);
1838 +
1839 +       spin_unlock_bh(&sc->sc_pcu_lock);
1840 +
1841 +       wow_status = ath9k_hw_wow_wakeup(ah);
1842 +
1843 +       if (atomic_read(&sc->wow_got_bmiss_intr) == 0) {
1844 +               /*
1845 +                * some devices may not pick beacon miss
1846 +                * as the reason they woke up so we add
1847 +                * that here for that shortcoming.
1848 +                */
1849 +               wow_status |= AH_WOW_BEACON_MISS;
1850 +               atomic_dec(&sc->wow_got_bmiss_intr);
1851 +               ath_dbg(common, ANY, "Beacon miss interrupt picked up during WoW sleep\n");
1852         }
1853  
1854 -       REG_RMW(ah, AR_WOW_BCN_EN, set, clr);
1855 +       atomic_dec(&sc->wow_sleep_proc_intr);
1856  
1857 -       set = 0;
1858 -       clr = 0;
1859 -       /*
1860 -        * Enable the magic packet registers
1861 -        */
1862 -       if (pattern_enable & AH_WOW_MAGIC_PATTERN_EN) {
1863 -               set = AR_WOW_MAGIC_EN;
1864 -               wow_event_mask |= AR_WOW_MAGIC_PAT_FOUND;
1865 -       } else {
1866 -               clr = AR_WOW_MAGIC_EN;
1867 +       if (wow_status) {
1868 +               ath_dbg(common, ANY, "Waking up due to WoW triggers %s with WoW status = %x\n",
1869 +                       ath9k_hw_wow_event_to_string(wow_status), wow_status);
1870         }
1871 -       set |= AR_WOW_MAC_INTR_EN;
1872 -       REG_RMW(ah, AR_WOW_PATTERN, set, clr);
1873  
1874 -       REG_WRITE(ah, AR_WOW_PATTERN_MATCH_LT_256B,
1875 -                 AR_WOW_PATTERN_SUPPORTED);
1876 +       ath_restart_work(sc);
1877 +       ath9k_start_btcoex(sc);
1878  
1879 -       /*
1880 -        * Set the power states appropriately and enable PME
1881 -        */
1882 -       clr = 0;
1883 -       set = AR_PMCTRL_PWR_STATE_D1D3 | AR_PMCTRL_HOST_PME_EN |
1884 -             AR_PMCTRL_PWR_PM_CTRL_ENA;
1885 +       ath9k_ps_restore(sc);
1886 +       mutex_unlock(&sc->mutex);
1887  
1888 -       clr = AR_PCIE_PM_CTRL_ENA;
1889 -       REG_RMW(ah, AR_PCIE_PM_CTRL, set, clr);
1890 +       return 0;
1891 +}
1892  
1893 -       /*
1894 -        * this is needed to prevent the chip waking up
1895 -        * the host within 3-4 seconds with certain
1896 -        * platform/BIOS. The fix is to enable
1897 -        * D1 & D3 to match original definition and
1898 -        * also match the OTP value. Anyway this
1899 -        * is more related to SW WOW.
1900 -        */
1901 -       clr = AR_PMCTRL_PWR_STATE_D1D3;
1902 -       REG_CLR_BIT(ah, AR_PCIE_PM_CTRL, clr);
1903 +void ath9k_set_wakeup(struct ieee80211_hw *hw, bool enabled)
1904 +{
1905 +       struct ath_softc *sc = hw->priv;
1906  
1907 -       set = AR_PMCTRL_PWR_STATE_D1D3_REAL;
1908 -       REG_SET_BIT(ah, AR_PCIE_PM_CTRL, set);
1909 +       mutex_lock(&sc->mutex);
1910 +       device_init_wakeup(sc->dev, 1);
1911 +       device_set_wakeup_enable(sc->dev, enabled);
1912 +       mutex_unlock(&sc->mutex);
1913 +}
1914  
1915 -       REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PRESERVE_SEQNUM);
1916 +void ath9k_init_wow(struct ieee80211_hw *hw)
1917 +{
1918 +       struct ath_softc *sc = hw->priv;
1919  
1920 -       /* to bring down WOW power low margin */
1921 -       set = BIT(13);
1922 -       REG_SET_BIT(ah, AR_PCIE_PHY_REG3, set);
1923 -       /* HW WoW */
1924 -       clr = BIT(5);
1925 -       REG_CLR_BIT(ah, AR_PCU_MISC_MODE3, clr);
1926 +       if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_WOW_DEVICE_CAPABLE) &&
1927 +           (sc->driver_data & ATH9K_PCI_WOW) &&
1928 +           device_can_wakeup(sc->dev))
1929 +               hw->wiphy->wowlan = &ath9k_wowlan_support;
1930  
1931 -       ath9k_hw_set_powermode_wow_sleep(ah);
1932 -       ah->wow_event_mask = wow_event_mask;
1933 +       atomic_set(&sc->wow_sleep_proc_intr, -1);
1934 +       atomic_set(&sc->wow_got_bmiss_intr, -1);
1935  }
1936 -EXPORT_SYMBOL(ath9k_hw_wow_enable);
1937 --- a/drivers/net/wireless/ath/ath9k/xmit.c
1938 +++ b/drivers/net/wireless/ath/ath9k/xmit.c
1939 @@ -1786,6 +1786,9 @@ bool ath_drain_all_txq(struct ath_softc 
1940                 if (!ATH_TXQ_SETUP(sc, i))
1941                         continue;
1942  
1943 +               if (!sc->tx.txq[i].axq_depth)
1944 +                       continue;
1945 +
1946                 if (ath9k_hw_numtxpending(ah, sc->tx.txq[i].axq_qnum))
1947                         npend |= BIT(i);
1948         }
1949 @@ -2749,6 +2752,8 @@ void ath_tx_node_cleanup(struct ath_soft
1950         }
1951  }
1952  
1953 +#ifdef CONFIG_ATH9K_TX99
1954 +
1955  int ath9k_tx99_send(struct ath_softc *sc, struct sk_buff *skb,
1956                     struct ath_tx_control *txctl)
1957  {
1958 @@ -2791,3 +2796,5 @@ int ath9k_tx99_send(struct ath_softc *sc
1959  
1960         return 0;
1961  }
1962 +
1963 +#endif /* CONFIG_ATH9K_TX99 */
1964 --- a/drivers/net/wireless/ath/regd.c
1965 +++ b/drivers/net/wireless/ath/regd.c
1966 @@ -37,17 +37,17 @@ static int __ath_regd_init(struct ath_re
1967  
1968  /* We enable active scan on these a case by case basis by regulatory domain */
1969  #define ATH9K_2GHZ_CH12_13     REG_RULE(2467-10, 2472+10, 40, 0, 20,\
1970 -                                       NL80211_RRF_PASSIVE_SCAN)
1971 +                                       NL80211_RRF_NO_IR)
1972  #define ATH9K_2GHZ_CH14                REG_RULE(2484-10, 2484+10, 40, 0, 20,\
1973 -                               NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_OFDM)
1974 +                               NL80211_RRF_NO_IR | NL80211_RRF_NO_OFDM)
1975  
1976  /* We allow IBSS on these on a case by case basis by regulatory domain */
1977  #define ATH9K_5GHZ_5150_5350   REG_RULE(5150-10, 5350+10, 80, 0, 30,\
1978 -                               NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
1979 +                               NL80211_RRF_NO_IR)
1980  #define ATH9K_5GHZ_5470_5850   REG_RULE(5470-10, 5850+10, 80, 0, 30,\
1981 -                               NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
1982 +                               NL80211_RRF_NO_IR)
1983  #define ATH9K_5GHZ_5725_5850   REG_RULE(5725-10, 5850+10, 80, 0, 30,\
1984 -                               NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
1985 +                               NL80211_RRF_NO_IR)
1986  
1987  #define ATH9K_2GHZ_ALL         ATH9K_2GHZ_CH01_11, \
1988                                 ATH9K_2GHZ_CH12_13, \
1989 @@ -224,17 +224,16 @@ ath_reg_apply_beaconing_flags(struct wip
1990                                  * regulatory_hint().
1991                                  */
1992                                 if (!(reg_rule->flags &
1993 -                                   NL80211_RRF_NO_IBSS))
1994 +                                   NL80211_RRF_NO_IR))
1995                                         ch->flags &=
1996 -                                         ~IEEE80211_CHAN_NO_IBSS;
1997 +                                         ~IEEE80211_CHAN_NO_IR;
1998                                 if (!(reg_rule->flags &
1999 -                                   NL80211_RRF_PASSIVE_SCAN))
2000 +                                   NL80211_RRF_NO_IR))
2001                                         ch->flags &=
2002 -                                         ~IEEE80211_CHAN_PASSIVE_SCAN;
2003 +                                         ~IEEE80211_CHAN_NO_IR;
2004                         } else {
2005                                 if (ch->beacon_found)
2006 -                                       ch->flags &= ~(IEEE80211_CHAN_NO_IBSS |
2007 -                                         IEEE80211_CHAN_PASSIVE_SCAN);
2008 +                                       ch->flags &= ~IEEE80211_CHAN_NO_IR;
2009                         }
2010                 }
2011         }
2012 @@ -260,11 +259,11 @@ ath_reg_apply_active_scan_flags(struct w
2013          */
2014         if (initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) {
2015                 ch = &sband->channels[11]; /* CH 12 */
2016 -               if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
2017 -                       ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
2018 +               if (ch->flags & IEEE80211_CHAN_NO_IR)
2019 +                       ch->flags &= ~IEEE80211_CHAN_NO_IR;
2020                 ch = &sband->channels[12]; /* CH 13 */
2021 -               if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
2022 -                       ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
2023 +               if (ch->flags & IEEE80211_CHAN_NO_IR)
2024 +                       ch->flags &= ~IEEE80211_CHAN_NO_IR;
2025                 return;
2026         }
2027  
2028 @@ -278,17 +277,17 @@ ath_reg_apply_active_scan_flags(struct w
2029         ch = &sband->channels[11]; /* CH 12 */
2030         reg_rule = freq_reg_info(wiphy, ch->center_freq);
2031         if (!IS_ERR(reg_rule)) {
2032 -               if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN))
2033 -                       if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
2034 -                               ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
2035 +               if (!(reg_rule->flags & NL80211_RRF_NO_IR))
2036 +                       if (ch->flags & IEEE80211_CHAN_NO_IR)
2037 +                               ch->flags &= ~IEEE80211_CHAN_NO_IR;
2038         }
2039  
2040         ch = &sband->channels[12]; /* CH 13 */
2041         reg_rule = freq_reg_info(wiphy, ch->center_freq);
2042         if (!IS_ERR(reg_rule)) {
2043 -               if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN))
2044 -                       if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
2045 -                               ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
2046 +               if (!(reg_rule->flags & NL80211_RRF_NO_IR))
2047 +                       if (ch->flags & IEEE80211_CHAN_NO_IR)
2048 +                               ch->flags &= ~IEEE80211_CHAN_NO_IR;
2049         }
2050  }
2051  
2052 @@ -320,8 +319,8 @@ static void ath_reg_apply_radar_flags(st
2053                  */
2054                 if (!(ch->flags & IEEE80211_CHAN_DISABLED))
2055                         ch->flags |= IEEE80211_CHAN_RADAR |
2056 -                                    IEEE80211_CHAN_NO_IBSS |
2057 -                                    IEEE80211_CHAN_PASSIVE_SCAN;
2058 +                                    IEEE80211_CHAN_NO_IR |
2059 +                                    IEEE80211_CHAN_NO_IR;
2060         }
2061  }
2062  
2063 --- a/drivers/net/wireless/brcm80211/brcmfmac/p2p.c
2064 +++ b/drivers/net/wireless/brcm80211/brcmfmac/p2p.c
2065 @@ -812,7 +812,7 @@ static s32 brcmf_p2p_run_escan(struct br
2066                         struct ieee80211_channel *chan = request->channels[i];
2067  
2068                         if (chan->flags & (IEEE80211_CHAN_RADAR |
2069 -                                          IEEE80211_CHAN_PASSIVE_SCAN))
2070 +                                          IEEE80211_CHAN_NO_IR))
2071                                 continue;
2072  
2073                         chanspecs[i] = channel_to_chanspec(&p2p->cfg->d11inf,
2074 --- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
2075 +++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
2076 @@ -202,9 +202,9 @@ static struct ieee80211_supported_band _
2077  
2078  /* This is to override regulatory domains defined in cfg80211 module (reg.c)
2079   * By default world regulatory domain defined in reg.c puts the flags
2080 - * NL80211_RRF_PASSIVE_SCAN and NL80211_RRF_NO_IBSS for 5GHz channels (for
2081 - * 36..48 and 149..165). With respect to these flags, wpa_supplicant doesn't
2082 - * start p2p operations on 5GHz channels. All the changes in world regulatory
2083 + * NL80211_RRF_NO_IR for 5GHz channels (for * 36..48 and 149..165).
2084 + * With respect to these flags, wpa_supplicant doesn't * start p2p
2085 + * operations on 5GHz channels. All the changes in world regulatory
2086   * domain are to be done here.
2087   */
2088  static const struct ieee80211_regdomain brcmf_regdom = {
2089 @@ -5197,10 +5197,10 @@ static s32 brcmf_construct_reginfo(struc
2090                                         if (channel & WL_CHAN_RADAR)
2091                                                 band_chan_arr[index].flags |=
2092                                                         (IEEE80211_CHAN_RADAR |
2093 -                                                       IEEE80211_CHAN_NO_IBSS);
2094 +                                                       IEEE80211_CHAN_NO_IR);
2095                                         if (channel & WL_CHAN_PASSIVE)
2096                                                 band_chan_arr[index].flags |=
2097 -                                                   IEEE80211_CHAN_PASSIVE_SCAN;
2098 +                                                   IEEE80211_CHAN_NO_IR;
2099                                 }
2100                         }
2101                         if (!update)
2102 --- a/drivers/net/wireless/brcm80211/brcmsmac/channel.c
2103 +++ b/drivers/net/wireless/brcm80211/brcmsmac/channel.c
2104 @@ -59,23 +59,20 @@
2105  
2106  #define BRCM_2GHZ_2412_2462    REG_RULE(2412-10, 2462+10, 40, 0, 19, 0)
2107  #define BRCM_2GHZ_2467_2472    REG_RULE(2467-10, 2472+10, 20, 0, 19, \
2108 -                                        NL80211_RRF_PASSIVE_SCAN | \
2109 -                                        NL80211_RRF_NO_IBSS)
2110 +                                        NL80211_RRF_NO_IR)
2111  
2112  #define BRCM_5GHZ_5180_5240    REG_RULE(5180-10, 5240+10, 40, 0, 21, \
2113 -                                        NL80211_RRF_PASSIVE_SCAN | \
2114 -                                        NL80211_RRF_NO_IBSS)
2115 +                                        NL80211_RRF_NO_IR)
2116  #define BRCM_5GHZ_5260_5320    REG_RULE(5260-10, 5320+10, 40, 0, 21, \
2117 -                                        NL80211_RRF_PASSIVE_SCAN | \
2118 +                                        NL80211_RRF_NO_IR | \
2119                                          NL80211_RRF_DFS | \
2120 -                                        NL80211_RRF_NO_IBSS)
2121 +                                        NL80211_RRF_NO_IR)
2122  #define BRCM_5GHZ_5500_5700    REG_RULE(5500-10, 5700+10, 40, 0, 21, \
2123 -                                        NL80211_RRF_PASSIVE_SCAN | \
2124 +                                        NL80211_RRF_NO_IR | \
2125                                          NL80211_RRF_DFS | \
2126 -                                        NL80211_RRF_NO_IBSS)
2127 +                                        NL80211_RRF_NO_IR)
2128  #define BRCM_5GHZ_5745_5825    REG_RULE(5745-10, 5825+10, 40, 0, 21, \
2129 -                                        NL80211_RRF_PASSIVE_SCAN | \
2130 -                                        NL80211_RRF_NO_IBSS)
2131 +                                        NL80211_RRF_NO_IR)
2132  
2133  static const struct ieee80211_regdomain brcms_regdom_x2 = {
2134         .n_reg_rules = 6,
2135 @@ -395,7 +392,7 @@ brcms_c_channel_set_chanspec(struct brcm
2136                 brcms_c_set_gmode(wlc, wlc->protection->gmode_user, false);
2137  
2138         brcms_b_set_chanspec(wlc->hw, chanspec,
2139 -                             !!(ch->flags & IEEE80211_CHAN_PASSIVE_SCAN),
2140 +                             !!(ch->flags & IEEE80211_CHAN_NO_IR),
2141                               &txpwr);
2142  }
2143  
2144 @@ -657,8 +654,8 @@ static void brcms_reg_apply_radar_flags(
2145                  */
2146                 if (!(ch->flags & IEEE80211_CHAN_DISABLED))
2147                         ch->flags |= IEEE80211_CHAN_RADAR |
2148 -                                    IEEE80211_CHAN_NO_IBSS |
2149 -                                    IEEE80211_CHAN_PASSIVE_SCAN;
2150 +                                    IEEE80211_CHAN_NO_IR |
2151 +                                    IEEE80211_CHAN_NO_IR;
2152         }
2153  }
2154  
2155 @@ -688,14 +685,13 @@ brcms_reg_apply_beaconing_flags(struct w
2156                                 if (IS_ERR(rule))
2157                                         continue;
2158  
2159 -                               if (!(rule->flags & NL80211_RRF_NO_IBSS))
2160 -                                       ch->flags &= ~IEEE80211_CHAN_NO_IBSS;
2161 -                               if (!(rule->flags & NL80211_RRF_PASSIVE_SCAN))
2162 +                               if (!(rule->flags & NL80211_RRF_NO_IR))
2163 +                                       ch->flags &= ~IEEE80211_CHAN_NO_IR;
2164 +                               if (!(rule->flags & NL80211_RRF_NO_IR))
2165                                         ch->flags &=
2166 -                                               ~IEEE80211_CHAN_PASSIVE_SCAN;
2167 +                                               ~IEEE80211_CHAN_NO_IR;
2168                         } else if (ch->beacon_found) {
2169 -                               ch->flags &= ~(IEEE80211_CHAN_NO_IBSS |
2170 -                                              IEEE80211_CHAN_PASSIVE_SCAN);
2171 +                               ch->flags &= ~IEEE80211_CHAN_NO_IR;
2172                         }
2173                 }
2174         }
2175 --- a/drivers/net/wireless/brcm80211/brcmsmac/mac80211_if.c
2176 +++ b/drivers/net/wireless/brcm80211/brcmsmac/mac80211_if.c
2177 @@ -125,13 +125,13 @@ static struct ieee80211_channel brcms_2g
2178         CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
2179         CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
2180         CHAN2GHZ(12, 2467,
2181 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
2182 +                IEEE80211_CHAN_NO_IR |
2183                  IEEE80211_CHAN_NO_HT40PLUS),
2184         CHAN2GHZ(13, 2472,
2185 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
2186 +                IEEE80211_CHAN_NO_IR |
2187                  IEEE80211_CHAN_NO_HT40PLUS),
2188         CHAN2GHZ(14, 2484,
2189 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
2190 +                IEEE80211_CHAN_NO_IR |
2191                  IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS |
2192                  IEEE80211_CHAN_NO_OFDM)
2193  };
2194 @@ -144,51 +144,51 @@ static struct ieee80211_channel brcms_5g
2195         CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
2196         /* UNII-2 */
2197         CHAN5GHZ(52,
2198 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2199 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
2200 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2201 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40MINUS),
2202         CHAN5GHZ(56,
2203 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2204 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
2205 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2206 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40PLUS),
2207         CHAN5GHZ(60,
2208 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2209 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
2210 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2211 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40MINUS),
2212         CHAN5GHZ(64,
2213 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2214 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
2215 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2216 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40PLUS),
2217         /* MID */
2218         CHAN5GHZ(100,
2219 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2220 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
2221 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2222 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40MINUS),
2223         CHAN5GHZ(104,
2224 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2225 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
2226 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2227 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40PLUS),
2228         CHAN5GHZ(108,
2229 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2230 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
2231 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2232 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40MINUS),
2233         CHAN5GHZ(112,
2234 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2235 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
2236 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2237 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40PLUS),
2238         CHAN5GHZ(116,
2239 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2240 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
2241 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2242 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40MINUS),
2243         CHAN5GHZ(120,
2244 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2245 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
2246 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2247 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40PLUS),
2248         CHAN5GHZ(124,
2249 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2250 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
2251 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2252 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40MINUS),
2253         CHAN5GHZ(128,
2254 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2255 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
2256 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2257 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40PLUS),
2258         CHAN5GHZ(132,
2259 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2260 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
2261 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2262 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40MINUS),
2263         CHAN5GHZ(136,
2264 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2265 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
2266 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2267 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40PLUS),
2268         CHAN5GHZ(140,
2269 -                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
2270 -                IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
2271 +                IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR |
2272 +                IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40PLUS |
2273                  IEEE80211_CHAN_NO_HT40MINUS),
2274         /* UNII-3 */
2275         CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
2276 --- a/drivers/net/wireless/cw1200/scan.c
2277 +++ b/drivers/net/wireless/cw1200/scan.c
2278 @@ -197,9 +197,9 @@ void cw1200_scan_work(struct work_struct
2279                         if ((*it)->band != first->band)
2280                                 break;
2281                         if (((*it)->flags ^ first->flags) &
2282 -                                       IEEE80211_CHAN_PASSIVE_SCAN)
2283 +                                       IEEE80211_CHAN_NO_IR)
2284                                 break;
2285 -                       if (!(first->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
2286 +                       if (!(first->flags & IEEE80211_CHAN_NO_IR) &&
2287                             (*it)->max_power != first->max_power)
2288                                 break;
2289                 }
2290 @@ -210,7 +210,7 @@ void cw1200_scan_work(struct work_struct
2291                 else
2292                         scan.max_tx_rate = WSM_TRANSMIT_RATE_1;
2293                 scan.num_probes =
2294 -                       (first->flags & IEEE80211_CHAN_PASSIVE_SCAN) ? 0 : 2;
2295 +                       (first->flags & IEEE80211_CHAN_NO_IR) ? 0 : 2;
2296                 scan.num_ssids = priv->scan.n_ssids;
2297                 scan.ssids = &priv->scan.ssids[0];
2298                 scan.num_channels = it - priv->scan.curr;
2299 @@ -233,7 +233,7 @@ void cw1200_scan_work(struct work_struct
2300                 }
2301                 for (i = 0; i < scan.num_channels; ++i) {
2302                         scan.ch[i].number = priv->scan.curr[i]->hw_value;
2303 -                       if (priv->scan.curr[i]->flags & IEEE80211_CHAN_PASSIVE_SCAN) {
2304 +                       if (priv->scan.curr[i]->flags & IEEE80211_CHAN_NO_IR) {
2305                                 scan.ch[i].min_chan_time = 50;
2306                                 scan.ch[i].max_chan_time = 100;
2307                         } else {
2308 @@ -241,7 +241,7 @@ void cw1200_scan_work(struct work_struct
2309                                 scan.ch[i].max_chan_time = 25;
2310                         }
2311                 }
2312 -               if (!(first->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
2313 +               if (!(first->flags & IEEE80211_CHAN_NO_IR) &&
2314                     priv->scan.output_power != first->max_power) {
2315                         priv->scan.output_power = first->max_power;
2316                         wsm_set_output_power(priv,
2317 --- a/drivers/net/wireless/ipw2x00/ipw2100.c
2318 +++ b/drivers/net/wireless/ipw2x00/ipw2100.c
2319 @@ -1934,10 +1934,10 @@ static int ipw2100_wdev_init(struct net_
2320                         bg_band->channels[i].max_power = geo->bg[i].max_power;
2321                         if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY)
2322                                 bg_band->channels[i].flags |=
2323 -                                       IEEE80211_CHAN_PASSIVE_SCAN;
2324 +                                       IEEE80211_CHAN_NO_IR;
2325                         if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS)
2326                                 bg_band->channels[i].flags |=
2327 -                                       IEEE80211_CHAN_NO_IBSS;
2328 +                                       IEEE80211_CHAN_NO_IR;
2329                         if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)
2330                                 bg_band->channels[i].flags |=
2331                                         IEEE80211_CHAN_RADAR;
2332 --- a/drivers/net/wireless/ipw2x00/ipw2200.c
2333 +++ b/drivers/net/wireless/ipw2x00/ipw2200.c
2334 @@ -11472,10 +11472,10 @@ static int ipw_wdev_init(struct net_devi
2335                         bg_band->channels[i].max_power = geo->bg[i].max_power;
2336                         if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY)
2337                                 bg_band->channels[i].flags |=
2338 -                                       IEEE80211_CHAN_PASSIVE_SCAN;
2339 +                                       IEEE80211_CHAN_NO_IR;
2340                         if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS)
2341                                 bg_band->channels[i].flags |=
2342 -                                       IEEE80211_CHAN_NO_IBSS;
2343 +                                       IEEE80211_CHAN_NO_IR;
2344                         if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)
2345                                 bg_band->channels[i].flags |=
2346                                         IEEE80211_CHAN_RADAR;
2347 @@ -11511,10 +11511,10 @@ static int ipw_wdev_init(struct net_devi
2348                         a_band->channels[i].max_power = geo->a[i].max_power;
2349                         if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY)
2350                                 a_band->channels[i].flags |=
2351 -                                       IEEE80211_CHAN_PASSIVE_SCAN;
2352 +                                       IEEE80211_CHAN_NO_IR;
2353                         if (geo->a[i].flags & LIBIPW_CH_NO_IBSS)
2354                                 a_band->channels[i].flags |=
2355 -                                       IEEE80211_CHAN_NO_IBSS;
2356 +                                       IEEE80211_CHAN_NO_IR;
2357                         if (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT)
2358                                 a_band->channels[i].flags |=
2359                                         IEEE80211_CHAN_RADAR;
2360 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
2361 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
2362 @@ -1595,7 +1595,7 @@ il3945_get_channels_for_scan(struct il_p
2363                  *  and use long active_dwell time.
2364                  */
2365                 if (!is_active || il_is_channel_passive(ch_info) ||
2366 -                   (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
2367 +                   (chan->flags & IEEE80211_CHAN_NO_IR)) {
2368                         scan_ch->type = 0;      /* passive */
2369                         if (IL_UCODE_API(il->ucode_ver) == 1)
2370                                 scan_ch->active_dwell =
2371 --- a/drivers/net/wireless/iwlegacy/4965-mac.c
2372 +++ b/drivers/net/wireless/iwlegacy/4965-mac.c
2373 @@ -805,7 +805,7 @@ il4965_get_channels_for_scan(struct il_p
2374                 }
2375  
2376                 if (!is_active || il_is_channel_passive(ch_info) ||
2377 -                   (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN))
2378 +                   (chan->flags & IEEE80211_CHAN_NO_IR))
2379                         scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
2380                 else
2381                         scan_ch->type = SCAN_CHANNEL_TYPE_ACTIVE;
2382 --- a/drivers/net/wireless/iwlegacy/common.c
2383 +++ b/drivers/net/wireless/iwlegacy/common.c
2384 @@ -3447,10 +3447,10 @@ il_init_geos(struct il_priv *il)
2385  
2386                 if (il_is_channel_valid(ch)) {
2387                         if (!(ch->flags & EEPROM_CHANNEL_IBSS))
2388 -                               geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
2389 +                               geo_ch->flags |= IEEE80211_CHAN_NO_IR;
2390  
2391                         if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
2392 -                               geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
2393 +                               geo_ch->flags |= IEEE80211_CHAN_NO_IR;
2394  
2395                         if (ch->flags & EEPROM_CHANNEL_RADAR)
2396                                 geo_ch->flags |= IEEE80211_CHAN_RADAR;
2397 --- a/drivers/net/wireless/iwlegacy/debug.c
2398 +++ b/drivers/net/wireless/iwlegacy/debug.c
2399 @@ -567,12 +567,12 @@ il_dbgfs_channels_read(struct file *file
2400                                       flags & IEEE80211_CHAN_RADAR ?
2401                                       " (IEEE 802.11h required)" : "",
2402                                       ((channels[i].
2403 -                                       flags & IEEE80211_CHAN_NO_IBSS) ||
2404 +                                       flags & IEEE80211_CHAN_NO_IR) ||
2405                                        (channels[i].
2406                                         flags & IEEE80211_CHAN_RADAR)) ? "" :
2407                                       ", IBSS",
2408                                       channels[i].
2409 -                                     flags & IEEE80211_CHAN_PASSIVE_SCAN ?
2410 +                                     flags & IEEE80211_CHAN_NO_IR ?
2411                                       "passive only" : "active/passive");
2412         }
2413         supp_band = il_get_hw_mode(il, IEEE80211_BAND_5GHZ);
2414 @@ -594,12 +594,12 @@ il_dbgfs_channels_read(struct file *file
2415                                       flags & IEEE80211_CHAN_RADAR ?
2416                                       " (IEEE 802.11h required)" : "",
2417                                       ((channels[i].
2418 -                                       flags & IEEE80211_CHAN_NO_IBSS) ||
2419 +                                       flags & IEEE80211_CHAN_NO_IR) ||
2420                                        (channels[i].
2421                                         flags & IEEE80211_CHAN_RADAR)) ? "" :
2422                                       ", IBSS",
2423                                       channels[i].
2424 -                                     flags & IEEE80211_CHAN_PASSIVE_SCAN ?
2425 +                                     flags & IEEE80211_CHAN_NO_IR ?
2426                                       "passive only" : "active/passive");
2427         }
2428         ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2429 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
2430 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
2431 @@ -352,12 +352,12 @@ static ssize_t iwl_dbgfs_channels_read(s
2432                                         channels[i].max_power,
2433                                         channels[i].flags & IEEE80211_CHAN_RADAR ?
2434                                         " (IEEE 802.11h required)" : "",
2435 -                                       ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
2436 +                                       ((channels[i].flags & IEEE80211_CHAN_NO_IR)
2437                                         || (channels[i].flags &
2438                                         IEEE80211_CHAN_RADAR)) ? "" :
2439                                         ", IBSS",
2440                                         channels[i].flags &
2441 -                                       IEEE80211_CHAN_PASSIVE_SCAN ?
2442 +                                       IEEE80211_CHAN_NO_IR ?
2443                                         "passive only" : "active/passive");
2444         }
2445         supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
2446 @@ -375,12 +375,12 @@ static ssize_t iwl_dbgfs_channels_read(s
2447                                         channels[i].max_power,
2448                                         channels[i].flags & IEEE80211_CHAN_RADAR ?
2449                                         " (IEEE 802.11h required)" : "",
2450 -                                       ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
2451 +                                       ((channels[i].flags & IEEE80211_CHAN_NO_IR)
2452                                         || (channels[i].flags &
2453                                         IEEE80211_CHAN_RADAR)) ? "" :
2454                                         ", IBSS",
2455                                         channels[i].flags &
2456 -                                       IEEE80211_CHAN_PASSIVE_SCAN ?
2457 +                                       IEEE80211_CHAN_NO_IR ?
2458                                         "passive only" : "active/passive");
2459         }
2460         ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2461 --- a/drivers/net/wireless/iwlwifi/dvm/scan.c
2462 +++ b/drivers/net/wireless/iwlwifi/dvm/scan.c
2463 @@ -544,7 +544,7 @@ static int iwl_get_channels_for_scan(str
2464                 channel = chan->hw_value;
2465                 scan_ch->channel = cpu_to_le16(channel);
2466  
2467 -               if (!is_active || (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN))
2468 +               if (!is_active || (chan->flags & IEEE80211_CHAN_NO_IR))
2469                         scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
2470                 else
2471                         scan_ch->type = SCAN_CHANNEL_TYPE_ACTIVE;
2472 --- a/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c
2473 +++ b/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c
2474 @@ -614,10 +614,10 @@ static int iwl_init_channel_map(struct d
2475                         channel->flags = IEEE80211_CHAN_NO_HT40;
2476  
2477                         if (!(eeprom_ch->flags & EEPROM_CHANNEL_IBSS))
2478 -                               channel->flags |= IEEE80211_CHAN_NO_IBSS;
2479 +                               channel->flags |= IEEE80211_CHAN_NO_IR;
2480  
2481                         if (!(eeprom_ch->flags & EEPROM_CHANNEL_ACTIVE))
2482 -                               channel->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
2483 +                               channel->flags |= IEEE80211_CHAN_NO_IR;
2484  
2485                         if (eeprom_ch->flags & EEPROM_CHANNEL_RADAR)
2486                                 channel->flags |= IEEE80211_CHAN_RADAR;
2487 --- a/drivers/net/wireless/iwlwifi/iwl-nvm-parse.c
2488 +++ b/drivers/net/wireless/iwlwifi/iwl-nvm-parse.c
2489 @@ -223,10 +223,10 @@ static int iwl_init_channel_map(struct d
2490                         channel->flags |= IEEE80211_CHAN_NO_160MHZ;
2491  
2492                 if (!(ch_flags & NVM_CHANNEL_IBSS))
2493 -                       channel->flags |= IEEE80211_CHAN_NO_IBSS;
2494 +                       channel->flags |= IEEE80211_CHAN_NO_IR;
2495  
2496                 if (!(ch_flags & NVM_CHANNEL_ACTIVE))
2497 -                       channel->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
2498 +                       channel->flags |= IEEE80211_CHAN_NO_IR;
2499  
2500                 if (ch_flags & NVM_CHANNEL_RADAR)
2501                         channel->flags |= IEEE80211_CHAN_RADAR;
2502 --- a/drivers/net/wireless/iwlwifi/mvm/scan.c
2503 +++ b/drivers/net/wireless/iwlwifi/mvm/scan.c
2504 @@ -192,7 +192,7 @@ static void iwl_mvm_scan_fill_channels(s
2505         for (i = 0; i < cmd->channel_count; i++) {
2506                 chan->channel = cpu_to_le16(req->channels[i]->hw_value);
2507                 chan->type = cpu_to_le32(type);
2508 -               if (req->channels[i]->flags & IEEE80211_CHAN_PASSIVE_SCAN)
2509 +               if (req->channels[i]->flags & IEEE80211_CHAN_NO_IR)
2510                         chan->type &= cpu_to_le32(~SCAN_CHANNEL_TYPE_ACTIVE);
2511                 chan->active_dwell = cpu_to_le16(active_dwell);
2512                 chan->passive_dwell = cpu_to_le16(passive_dwell);
2513 @@ -642,7 +642,7 @@ static void iwl_build_channel_cfg(struct
2514                 channels->iter_count[index] = cpu_to_le16(1);
2515                 channels->iter_interval[index] = 0;
2516  
2517 -               if (!(s_band->channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN))
2518 +               if (!(s_band->channels[i].flags & IEEE80211_CHAN_NO_IR))
2519                         channels->type[index] |=
2520                                 cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_ACTIVE);
2521  
2522 --- a/drivers/net/wireless/mac80211_hwsim.c
2523 +++ b/drivers/net/wireless/mac80211_hwsim.c
2524 @@ -159,7 +159,7 @@ static const struct ieee80211_regdomain 
2525         .reg_rules = {
2526                 REG_RULE(2412-10, 2462+10, 40, 0, 20, 0),
2527                 REG_RULE(5725-10, 5850+10, 40, 0, 30,
2528 -                       NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
2529 +                        NL80211_RRF_NO_IR),
2530         }
2531  };
2532  
2533 @@ -1485,7 +1485,7 @@ static void hw_scan_work(struct work_str
2534                     req->channels[hwsim->scan_chan_idx]->center_freq);
2535  
2536         hwsim->tmp_chan = req->channels[hwsim->scan_chan_idx];
2537 -       if (hwsim->tmp_chan->flags & IEEE80211_CHAN_PASSIVE_SCAN ||
2538 +       if (hwsim->tmp_chan->flags & IEEE80211_CHAN_NO_IR ||
2539             !req->n_ssids) {
2540                 dwell = 120;
2541         } else {
2542 --- a/drivers/net/wireless/mwifiex/cfg80211.c
2543 +++ b/drivers/net/wireless/mwifiex/cfg80211.c
2544 @@ -50,24 +50,24 @@ static const struct ieee80211_regdomain 
2545                 REG_RULE(2412-10, 2462+10, 40, 3, 20, 0),
2546                 /* Channel 12 - 13 */
2547                 REG_RULE(2467-10, 2472+10, 20, 3, 20,
2548 -                        NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
2549 +                        NL80211_RRF_NO_IR),
2550                 /* Channel 14 */
2551                 REG_RULE(2484-10, 2484+10, 20, 3, 20,
2552 -                        NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
2553 +                        NL80211_RRF_NO_IR |
2554                          NL80211_RRF_NO_OFDM),
2555                 /* Channel 36 - 48 */
2556                 REG_RULE(5180-10, 5240+10, 40, 3, 20,
2557 -                        NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
2558 +                        NL80211_RRF_NO_IR),
2559                 /* Channel 149 - 165 */
2560                 REG_RULE(5745-10, 5825+10, 40, 3, 20,
2561 -                        NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
2562 +                        NL80211_RRF_NO_IR),
2563                 /* Channel 52 - 64 */
2564                 REG_RULE(5260-10, 5320+10, 40, 3, 30,
2565 -                        NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
2566 +                        NL80211_RRF_NO_IR |
2567                          NL80211_RRF_DFS),
2568                 /* Channel 100 - 140 */
2569                 REG_RULE(5500-10, 5700+10, 40, 3, 30,
2570 -                        NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
2571 +                        NL80211_RRF_NO_IR |
2572                          NL80211_RRF_DFS),
2573         }
2574  };
2575 @@ -1968,7 +1968,7 @@ mwifiex_cfg80211_scan(struct wiphy *wiph
2576                 user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
2577                 user_scan_cfg->chan_list[i].radio_type = chan->band;
2578  
2579 -               if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
2580 +               if (chan->flags & IEEE80211_CHAN_NO_IR)
2581                         user_scan_cfg->chan_list[i].scan_type =
2582                                                 MWIFIEX_SCAN_TYPE_PASSIVE;
2583                 else
2584 --- a/drivers/net/wireless/mwifiex/scan.c
2585 +++ b/drivers/net/wireless/mwifiex/scan.c
2586 @@ -515,14 +515,14 @@ mwifiex_scan_create_channel_list(struct 
2587                                 scan_chan_list[chan_idx].max_scan_time =
2588                                         cpu_to_le16((u16) user_scan_in->
2589                                         chan_list[0].scan_time);
2590 -                       else if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
2591 +                       else if (ch->flags & IEEE80211_CHAN_NO_IR)
2592                                 scan_chan_list[chan_idx].max_scan_time =
2593                                         cpu_to_le16(adapter->passive_scan_time);
2594                         else
2595                                 scan_chan_list[chan_idx].max_scan_time =
2596                                         cpu_to_le16(adapter->active_scan_time);
2597  
2598 -                       if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
2599 +                       if (ch->flags & IEEE80211_CHAN_NO_IR)
2600                                 scan_chan_list[chan_idx].chan_scan_mode_bitmap
2601                                         |= MWIFIEX_PASSIVE_SCAN;
2602                         else
2603 --- a/drivers/net/wireless/rt2x00/rt2x00lib.h
2604 +++ b/drivers/net/wireless/rt2x00/rt2x00lib.h
2605 @@ -146,7 +146,7 @@ void rt2x00queue_remove_l2pad(struct sk_
2606   * @local: frame is not from mac80211
2607   */
2608  int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb,
2609 -                              bool local);
2610 +                              struct ieee80211_sta *sta, bool local);
2611  
2612  /**
2613   * rt2x00queue_update_beacon - Send new beacon from mac80211
2614 --- a/drivers/net/wireless/rt2x00/rt2x00mac.c
2615 +++ b/drivers/net/wireless/rt2x00/rt2x00mac.c
2616 @@ -90,7 +90,7 @@ static int rt2x00mac_tx_rts_cts(struct r
2617                                   frag_skb->data, data_length, tx_info,
2618                                   (struct ieee80211_rts *)(skb->data));
2619  
2620 -       retval = rt2x00queue_write_tx_frame(queue, skb, true);
2621 +       retval = rt2x00queue_write_tx_frame(queue, skb, NULL, true);
2622         if (retval) {
2623                 dev_kfree_skb_any(skb);
2624                 rt2x00_warn(rt2x00dev, "Failed to send RTS/CTS frame\n");
2625 @@ -151,7 +151,7 @@ void rt2x00mac_tx(struct ieee80211_hw *h
2626                         goto exit_fail;
2627         }
2628  
2629 -       if (unlikely(rt2x00queue_write_tx_frame(queue, skb, false)))
2630 +       if (unlikely(rt2x00queue_write_tx_frame(queue, skb, control->sta, false)))
2631                 goto exit_fail;
2632  
2633         /*
2634 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
2635 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
2636 @@ -635,7 +635,7 @@ static void rt2x00queue_bar_check(struct
2637  }
2638  
2639  int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb,
2640 -                              bool local)
2641 +                              struct ieee80211_sta *sta, bool local)
2642  {
2643         struct ieee80211_tx_info *tx_info;
2644         struct queue_entry *entry;
2645 @@ -649,7 +649,7 @@ int rt2x00queue_write_tx_frame(struct da
2646          * after that we are free to use the skb->cb array
2647          * for our information.
2648          */
2649 -       rt2x00queue_create_tx_descriptor(queue->rt2x00dev, skb, &txdesc, NULL);
2650 +       rt2x00queue_create_tx_descriptor(queue->rt2x00dev, skb, &txdesc, sta);
2651  
2652         /*
2653          * All information is retrieved from the skb->cb array,
2654 --- a/drivers/net/wireless/rtl818x/rtl8187/dev.c
2655 +++ b/drivers/net/wireless/rtl818x/rtl8187/dev.c
2656 @@ -416,7 +416,7 @@ static int rtl8187_init_urbs(struct ieee
2657         struct rtl8187_rx_info *info;
2658         int ret = 0;
2659  
2660 -       while (skb_queue_len(&priv->rx_queue) < 16) {
2661 +       while (skb_queue_len(&priv->rx_queue) < 32) {
2662                 skb = __dev_alloc_skb(RTL8187_MAX_RX, GFP_KERNEL);
2663                 if (!skb) {
2664                         ret = -ENOMEM;
2665 --- a/drivers/net/wireless/rtlwifi/base.c
2666 +++ b/drivers/net/wireless/rtlwifi/base.c
2667 @@ -1078,8 +1078,8 @@ u8 rtl_is_special_data(struct ieee80211_
2668  
2669         ip = (struct iphdr *)((u8 *) skb->data + mac_hdr_len +
2670                               SNAP_SIZE + PROTOC_TYPE_SIZE);
2671 -       ether_type = *(u16 *) ((u8 *) skb->data + mac_hdr_len + SNAP_SIZE);
2672 -       /*      ether_type = ntohs(ether_type); */
2673 +       ether_type = be16_to_cpu(*(__be16 *)((u8 *)skb->data + mac_hdr_len +
2674 +                                            SNAP_SIZE));
2675  
2676         if (ETH_P_IP == ether_type) {
2677                 if (IPPROTO_UDP == ip->protocol) {
2678 --- a/drivers/net/wireless/rtlwifi/regd.c
2679 +++ b/drivers/net/wireless/rtlwifi/regd.c
2680 @@ -59,30 +59,27 @@ static struct country_code_to_enum_rd al
2681   */
2682  #define RTL819x_2GHZ_CH12_13   \
2683         REG_RULE(2467-10, 2472+10, 40, 0, 20,\
2684 -       NL80211_RRF_PASSIVE_SCAN)
2685 +       NL80211_RRF_NO_IR)
2686  
2687  #define RTL819x_2GHZ_CH14      \
2688         REG_RULE(2484-10, 2484+10, 40, 0, 20, \
2689 -       NL80211_RRF_PASSIVE_SCAN | \
2690 +       NL80211_RRF_NO_IR | \
2691         NL80211_RRF_NO_OFDM)
2692  
2693  /* 5G chan 36 - chan 64*/
2694  #define RTL819x_5GHZ_5150_5350 \
2695         REG_RULE(5150-10, 5350+10, 40, 0, 30, \
2696 -       NL80211_RRF_PASSIVE_SCAN | \
2697 -       NL80211_RRF_NO_IBSS)
2698 +       NL80211_RRF_NO_IR)
2699  
2700  /* 5G chan 100 - chan 165*/
2701  #define RTL819x_5GHZ_5470_5850 \
2702         REG_RULE(5470-10, 5850+10, 40, 0, 30, \
2703 -       NL80211_RRF_PASSIVE_SCAN | \
2704 -       NL80211_RRF_NO_IBSS)
2705 +       NL80211_RRF_NO_IR)
2706  
2707  /* 5G chan 149 - chan 165*/
2708  #define RTL819x_5GHZ_5725_5850 \
2709         REG_RULE(5725-10, 5850+10, 40, 0, 30, \
2710 -       NL80211_RRF_PASSIVE_SCAN | \
2711 -       NL80211_RRF_NO_IBSS)
2712 +       NL80211_RRF_NO_IR)
2713  
2714  #define RTL819x_5GHZ_ALL       \
2715         (RTL819x_5GHZ_5150_5350, RTL819x_5GHZ_5470_5850)
2716 @@ -185,16 +182,15 @@ static void _rtl_reg_apply_beaconing_fla
2717                                  *regulatory_hint().
2718                                  */
2719  
2720 -                               if (!(reg_rule->flags & NL80211_RRF_NO_IBSS))
2721 -                                       ch->flags &= ~IEEE80211_CHAN_NO_IBSS;
2722 +                               if (!(reg_rule->flags & NL80211_RRF_NO_IR))
2723 +                                       ch->flags &= ~IEEE80211_CHAN_NO_IR;
2724                                 if (!(reg_rule->
2725 -                                    flags & NL80211_RRF_PASSIVE_SCAN))
2726 +                                    flags & NL80211_RRF_NO_IR))
2727                                         ch->flags &=
2728 -                                           ~IEEE80211_CHAN_PASSIVE_SCAN;
2729 +                                           ~IEEE80211_CHAN_NO_IR;
2730                         } else {
2731                                 if (ch->beacon_found)
2732 -                                       ch->flags &= ~(IEEE80211_CHAN_NO_IBSS |
2733 -                                                 IEEE80211_CHAN_PASSIVE_SCAN);
2734 +                                       ch->flags &= ~IEEE80211_CHAN_NO_IR;
2735                         }
2736                 }
2737         }
2738 @@ -219,11 +215,11 @@ static void _rtl_reg_apply_active_scan_f
2739          */
2740         if (initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) {
2741                 ch = &sband->channels[11];      /* CH 12 */
2742 -               if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
2743 -                       ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
2744 +               if (ch->flags & IEEE80211_CHAN_NO_IR)
2745 +                       ch->flags &= ~IEEE80211_CHAN_NO_IR;
2746                 ch = &sband->channels[12];      /* CH 13 */
2747 -               if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
2748 -                       ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
2749 +               if (ch->flags & IEEE80211_CHAN_NO_IR)
2750 +                       ch->flags &= ~IEEE80211_CHAN_NO_IR;
2751                 return;
2752         }
2753  
2754 @@ -237,17 +233,17 @@ static void _rtl_reg_apply_active_scan_f
2755         ch = &sband->channels[11];      /* CH 12 */
2756         reg_rule = freq_reg_info(wiphy, ch->center_freq);
2757         if (!IS_ERR(reg_rule)) {
2758 -               if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN))
2759 -                       if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
2760 -                               ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
2761 +               if (!(reg_rule->flags & NL80211_RRF_NO_IR))
2762 +                       if (ch->flags & IEEE80211_CHAN_NO_IR)
2763 +                               ch->flags &= ~IEEE80211_CHAN_NO_IR;
2764         }
2765  
2766         ch = &sband->channels[12];      /* CH 13 */
2767         reg_rule = freq_reg_info(wiphy, ch->center_freq);
2768         if (!IS_ERR(reg_rule)) {
2769 -               if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN))
2770 -                       if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
2771 -                               ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
2772 +               if (!(reg_rule->flags & NL80211_RRF_NO_IR))
2773 +                       if (ch->flags & IEEE80211_CHAN_NO_IR)
2774 +                               ch->flags &= ~IEEE80211_CHAN_NO_IR;
2775         }
2776  }
2777  
2778 @@ -284,8 +280,8 @@ static void _rtl_reg_apply_radar_flags(s
2779                  */
2780                 if (!(ch->flags & IEEE80211_CHAN_DISABLED))
2781                         ch->flags |= IEEE80211_CHAN_RADAR |
2782 -                           IEEE80211_CHAN_NO_IBSS |
2783 -                           IEEE80211_CHAN_PASSIVE_SCAN;
2784 +                           IEEE80211_CHAN_NO_IR |
2785 +                           IEEE80211_CHAN_NO_IR;
2786         }
2787  }
2788  
2789 --- a/drivers/net/wireless/ti/wl12xx/scan.c
2790 +++ b/drivers/net/wireless/ti/wl12xx/scan.c
2791 @@ -47,7 +47,7 @@ static int wl1271_get_scan_channels(stru
2792                      * In active scans, we only scan channels not
2793                      * marked as passive.
2794                      */
2795 -                   (passive || !(flags & IEEE80211_CHAN_PASSIVE_SCAN))) {
2796 +                   (passive || !(flags & IEEE80211_CHAN_NO_IR))) {
2797                         wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ",
2798                                      req->channels[i]->band,
2799                                      req->channels[i]->center_freq);
2800 --- a/drivers/net/wireless/ti/wlcore/cmd.c
2801 +++ b/drivers/net/wireless/ti/wlcore/cmd.c
2802 @@ -1688,7 +1688,7 @@ int wlcore_cmd_regdomain_config_locked(s
2803  
2804                         if (channel->flags & (IEEE80211_CHAN_DISABLED |
2805                                               IEEE80211_CHAN_RADAR |
2806 -                                             IEEE80211_CHAN_PASSIVE_SCAN))
2807 +                                             IEEE80211_CHAN_NO_IR))
2808                                 continue;
2809  
2810                         ch_bit_idx = wlcore_get_reg_conf_ch_idx(b, ch);
2811 --- a/drivers/net/wireless/ti/wlcore/main.c
2812 +++ b/drivers/net/wireless/ti/wlcore/main.c
2813 @@ -91,8 +91,7 @@ static void wl1271_reg_notify(struct wip
2814                         continue;
2815  
2816                 if (ch->flags & IEEE80211_CHAN_RADAR)
2817 -                       ch->flags |= IEEE80211_CHAN_NO_IBSS |
2818 -                                    IEEE80211_CHAN_PASSIVE_SCAN;
2819 +                       ch->flags |= IEEE80211_CHAN_NO_IR;
2820  
2821         }
2822  
2823 --- a/drivers/net/wireless/ti/wlcore/scan.c
2824 +++ b/drivers/net/wireless/ti/wlcore/scan.c
2825 @@ -189,14 +189,14 @@ wlcore_scan_get_channels(struct wl1271 *
2826                 flags = req_channels[i]->flags;
2827  
2828                 if (force_passive)
2829 -                       flags |= IEEE80211_CHAN_PASSIVE_SCAN;
2830 +                       flags |= IEEE80211_CHAN_NO_IR;
2831  
2832                 if ((req_channels[i]->band == band) &&
2833                     !(flags & IEEE80211_CHAN_DISABLED) &&
2834                     (!!(flags & IEEE80211_CHAN_RADAR) == radar) &&
2835                     /* if radar is set, we ignore the passive flag */
2836                     (radar ||
2837 -                    !!(flags & IEEE80211_CHAN_PASSIVE_SCAN) == passive)) {
2838 +                    !!(flags & IEEE80211_CHAN_NO_IR) == passive)) {
2839  
2840  
2841                         if (flags & IEEE80211_CHAN_RADAR) {
2842 @@ -221,7 +221,7 @@ wlcore_scan_get_channels(struct wl1271 *
2843                             (band == IEEE80211_BAND_2GHZ) &&
2844                             (channels[j].channel >= 12) &&
2845                             (channels[j].channel <= 14) &&
2846 -                           (flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
2847 +                           (flags & IEEE80211_CHAN_NO_IR) &&
2848                             !force_passive) {
2849                                 /* pactive channels treated as DFS */
2850                                 channels[j].flags = SCAN_CHANNEL_FLAGS_DFS;
2851 @@ -244,7 +244,7 @@ wlcore_scan_get_channels(struct wl1271 *
2852                                      max_dwell_time_active,
2853                                      flags & IEEE80211_CHAN_RADAR ?
2854                                         ", DFS" : "",
2855 -                                    flags & IEEE80211_CHAN_PASSIVE_SCAN ?
2856 +                                    flags & IEEE80211_CHAN_NO_IR ?
2857                                         ", PASSIVE" : "");
2858                         j++;
2859                 }
2860 --- a/include/net/cfg80211.h
2861 +++ b/include/net/cfg80211.h
2862 @@ -91,9 +91,8 @@ enum ieee80211_band {
2863   * Channel flags set by the regulatory control code.
2864   *
2865   * @IEEE80211_CHAN_DISABLED: This channel is disabled.
2866 - * @IEEE80211_CHAN_PASSIVE_SCAN: Only passive scanning is permitted
2867 - *     on this channel.
2868 - * @IEEE80211_CHAN_NO_IBSS: IBSS is not allowed on this channel.
2869 + * @IEEE80211_CHAN_NO_IR: do not initiate radiation, this includes
2870 + *     sending probe requests or beaconing.
2871   * @IEEE80211_CHAN_RADAR: Radar detection is required on this channel.
2872   * @IEEE80211_CHAN_NO_HT40PLUS: extension channel above this channel
2873   *     is not permitted.
2874 @@ -113,8 +112,8 @@ enum ieee80211_band {
2875   */
2876  enum ieee80211_channel_flags {
2877         IEEE80211_CHAN_DISABLED         = 1<<0,
2878 -       IEEE80211_CHAN_PASSIVE_SCAN     = 1<<1,
2879 -       IEEE80211_CHAN_NO_IBSS          = 1<<2,
2880 +       IEEE80211_CHAN_NO_IR            = 1<<1,
2881 +       /* hole at 1<<2 */
2882         IEEE80211_CHAN_RADAR            = 1<<3,
2883         IEEE80211_CHAN_NO_HT40PLUS      = 1<<4,
2884         IEEE80211_CHAN_NO_HT40MINUS     = 1<<5,
2885 @@ -4149,6 +4148,7 @@ void cfg80211_radar_event(struct wiphy *
2886  /**
2887   * cfg80211_cac_event - Channel availability check (CAC) event
2888   * @netdev: network device
2889 + * @chandef: chandef for the current channel
2890   * @event: type of event
2891   * @gfp: context flags
2892   *
2893 @@ -4157,6 +4157,7 @@ void cfg80211_radar_event(struct wiphy *
2894   * also by full-MAC drivers.
2895   */
2896  void cfg80211_cac_event(struct net_device *netdev,
2897 +                       const struct cfg80211_chan_def *chandef,
2898                         enum nl80211_radar_event event, gfp_t gfp);
2899  
2900  
2901 --- a/include/uapi/linux/nl80211.h
2902 +++ b/include/uapi/linux/nl80211.h
2903 @@ -1508,6 +1508,9 @@ enum nl80211_commands {
2904   *     to react to radar events, e.g. initiate a channel switch or leave the
2905   *     IBSS network.
2906   *
2907 + * @NL80211_ATTR_SUPPORT_5_10_MHZ: A flag indicating that the device supports
2908 + *     5 MHz and 10 MHz channel bandwidth.
2909 + *
2910   * @NL80211_ATTR_MAX: highest attribute number currently defined
2911   * @__NL80211_ATTR_AFTER_LAST: internal use
2912   */
2913 @@ -1824,6 +1827,8 @@ enum nl80211_attrs {
2914  
2915         NL80211_ATTR_HANDLE_DFS,
2916  
2917 +       NL80211_ATTR_SUPPORT_5_10_MHZ,
2918 +
2919         /* add attributes here, update the policy in nl80211.c */
2920  
2921         __NL80211_ATTR_AFTER_LAST,
2922 @@ -2224,10 +2229,9 @@ enum nl80211_band_attr {
2923   * @NL80211_FREQUENCY_ATTR_FREQ: Frequency in MHz
2924   * @NL80211_FREQUENCY_ATTR_DISABLED: Channel is disabled in current
2925   *     regulatory domain.
2926 - * @NL80211_FREQUENCY_ATTR_PASSIVE_SCAN: Only passive scanning is
2927 - *     permitted on this channel in current regulatory domain.
2928 - * @NL80211_FREQUENCY_ATTR_NO_IBSS: IBSS networks are not permitted
2929 - *     on this channel in current regulatory domain.
2930 + * @NL80211_FREQUENCY_ATTR_NO_IR: no mechanisms that initiate radiation
2931 + *     are permitted on this channel, this includes sending probe
2932 + *     requests, or modes of operation that require beaconing.
2933   * @NL80211_FREQUENCY_ATTR_RADAR: Radar detection is mandatory
2934   *     on this channel in current regulatory domain.
2935   * @NL80211_FREQUENCY_ATTR_MAX_TX_POWER: Maximum transmission power in mBm
2936 @@ -2254,8 +2258,8 @@ enum nl80211_frequency_attr {
2937         __NL80211_FREQUENCY_ATTR_INVALID,
2938         NL80211_FREQUENCY_ATTR_FREQ,
2939         NL80211_FREQUENCY_ATTR_DISABLED,
2940 -       NL80211_FREQUENCY_ATTR_PASSIVE_SCAN,
2941 -       NL80211_FREQUENCY_ATTR_NO_IBSS,
2942 +       NL80211_FREQUENCY_ATTR_NO_IR,
2943 +       __NL80211_FREQUENCY_ATTR_NO_IBSS,
2944         NL80211_FREQUENCY_ATTR_RADAR,
2945         NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
2946         NL80211_FREQUENCY_ATTR_DFS_STATE,
2947 @@ -2271,6 +2275,9 @@ enum nl80211_frequency_attr {
2948  };
2949  
2950  #define NL80211_FREQUENCY_ATTR_MAX_TX_POWER NL80211_FREQUENCY_ATTR_MAX_TX_POWER
2951 +#define NL80211_FREQUENCY_ATTR_PASSIVE_SCAN    NL80211_FREQUENCY_ATTR_NO_IR
2952 +#define NL80211_FREQUENCY_ATTR_NO_IBSS         NL80211_FREQUENCY_ATTR_NO_IR
2953 +#define NL80211_FREQUENCY_ATTR_NO_IR           NL80211_FREQUENCY_ATTR_NO_IR
2954  
2955  /**
2956   * enum nl80211_bitrate_attr - bitrate attributes
2957 @@ -2413,8 +2420,9 @@ enum nl80211_sched_scan_match_attr {
2958   * @NL80211_RRF_DFS: DFS support is required to be used
2959   * @NL80211_RRF_PTP_ONLY: this is only for Point To Point links
2960   * @NL80211_RRF_PTMP_ONLY: this is only for Point To Multi Point links
2961 - * @NL80211_RRF_PASSIVE_SCAN: passive scan is required
2962 - * @NL80211_RRF_NO_IBSS: no IBSS is allowed
2963 + * @NL80211_RRF_NO_IR: no mechanisms that initiate radiation are allowed,
2964 + *     this includes probe requests or modes of operation that require
2965 + *     beaconing.
2966   */
2967  enum nl80211_reg_rule_flags {
2968         NL80211_RRF_NO_OFDM             = 1<<0,
2969 @@ -2424,10 +2432,17 @@ enum nl80211_reg_rule_flags {
2970         NL80211_RRF_DFS                 = 1<<4,
2971         NL80211_RRF_PTP_ONLY            = 1<<5,
2972         NL80211_RRF_PTMP_ONLY           = 1<<6,
2973 -       NL80211_RRF_PASSIVE_SCAN        = 1<<7,
2974 -       NL80211_RRF_NO_IBSS             = 1<<8,
2975 +       NL80211_RRF_NO_IR               = 1<<7,
2976 +       __NL80211_RRF_NO_IBSS           = 1<<8,
2977  };
2978  
2979 +#define NL80211_RRF_PASSIVE_SCAN       NL80211_RRF_NO_IR
2980 +#define NL80211_RRF_NO_IBSS            NL80211_RRF_NO_IR
2981 +#define NL80211_RRF_NO_IR              NL80211_RRF_NO_IR
2982 +
2983 +/* For backport compatibility with older userspace */
2984 +#define NL80211_RRF_NO_IR_ALL          (NL80211_RRF_NO_IR | __NL80211_RRF_NO_IBSS)
2985 +
2986  /**
2987   * enum nl80211_dfs_regions - regulatory DFS regions
2988   *
2989 --- a/net/mac80211/cfg.c
2990 +++ b/net/mac80211/cfg.c
2991 @@ -1050,6 +1050,7 @@ static int ieee80211_stop_ap(struct wiph
2992         struct ieee80211_local *local = sdata->local;
2993         struct beacon_data *old_beacon;
2994         struct probe_resp *old_probe_resp;
2995 +       struct cfg80211_chan_def chandef;
2996  
2997         old_beacon = rtnl_dereference(sdata->u.ap.beacon);
2998         if (!old_beacon)
2999 @@ -1091,8 +1092,10 @@ static int ieee80211_stop_ap(struct wiph
3000         ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
3001  
3002         if (sdata->wdev.cac_started) {
3003 +               chandef = sdata->vif.bss_conf.chandef;
3004                 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
3005 -               cfg80211_cac_event(sdata->dev, NL80211_RADAR_CAC_ABORTED,
3006 +               cfg80211_cac_event(sdata->dev, &chandef,
3007 +                                  NL80211_RADAR_CAC_ABORTED,
3008                                    GFP_KERNEL);
3009         }
3010  
3011 --- a/net/mac80211/iface.c
3012 +++ b/net/mac80211/iface.c
3013 @@ -749,6 +749,7 @@ static void ieee80211_do_stop(struct iee
3014         u32 hw_reconf_flags = 0;
3015         int i, flushed;
3016         struct ps_data *ps;
3017 +       struct cfg80211_chan_def chandef;
3018  
3019         clear_bit(SDATA_STATE_RUNNING, &sdata->state);
3020  
3021 @@ -828,11 +829,13 @@ static void ieee80211_do_stop(struct iee
3022         cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
3023  
3024         if (sdata->wdev.cac_started) {
3025 +               chandef = sdata->vif.bss_conf.chandef;
3026                 WARN_ON(local->suspended);
3027                 mutex_lock(&local->iflist_mtx);
3028                 ieee80211_vif_release_channel(sdata);
3029                 mutex_unlock(&local->iflist_mtx);
3030 -               cfg80211_cac_event(sdata->dev, NL80211_RADAR_CAC_ABORTED,
3031 +               cfg80211_cac_event(sdata->dev, &chandef,
3032 +                                  NL80211_RADAR_CAC_ABORTED,
3033                                    GFP_KERNEL);
3034         }
3035  
3036 @@ -1340,7 +1343,6 @@ static void ieee80211_setup_sdata(struct
3037                 sdata->vif.bss_conf.bssid = NULL;
3038                 break;
3039         case NL80211_IFTYPE_AP_VLAN:
3040 -               break;
3041         case NL80211_IFTYPE_P2P_DEVICE:
3042                 sdata->vif.bss_conf.bssid = sdata->vif.addr;
3043                 break;
3044 --- a/net/mac80211/mlme.c
3045 +++ b/net/mac80211/mlme.c
3046 @@ -1398,10 +1398,12 @@ void ieee80211_dfs_cac_timer_work(struct
3047         struct ieee80211_sub_if_data *sdata =
3048                 container_of(delayed_work, struct ieee80211_sub_if_data,
3049                              dfs_cac_timer_work);
3050 +       struct cfg80211_chan_def chandef = sdata->vif.bss_conf.chandef;
3051  
3052         ieee80211_vif_release_channel(sdata);
3053 -
3054 -       cfg80211_cac_event(sdata->dev, NL80211_RADAR_CAC_FINISHED, GFP_KERNEL);
3055 +       cfg80211_cac_event(sdata->dev, &chandef,
3056 +                          NL80211_RADAR_CAC_FINISHED,
3057 +                          GFP_KERNEL);
3058  }
3059  
3060  /* MLME */
3061 --- a/net/mac80211/rx.c
3062 +++ b/net/mac80211/rx.c
3063 @@ -729,9 +729,7 @@ static void ieee80211_release_reorder_fr
3064         lockdep_assert_held(&tid_agg_rx->reorder_lock);
3065  
3066         while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) {
3067 -               index = ieee80211_sn_sub(tid_agg_rx->head_seq_num,
3068 -                                        tid_agg_rx->ssn) %
3069 -                                                       tid_agg_rx->buf_size;
3070 +               index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
3071                 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
3072                                                 frames);
3073         }
3074 @@ -757,8 +755,7 @@ static void ieee80211_sta_reorder_releas
3075         lockdep_assert_held(&tid_agg_rx->reorder_lock);
3076  
3077         /* release the buffer until next missing frame */
3078 -       index = ieee80211_sn_sub(tid_agg_rx->head_seq_num,
3079 -                                tid_agg_rx->ssn) % tid_agg_rx->buf_size;
3080 +       index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
3081         if (!tid_agg_rx->reorder_buf[index] &&
3082             tid_agg_rx->stored_mpdu_num) {
3083                 /*
3084 @@ -793,15 +790,11 @@ static void ieee80211_sta_reorder_releas
3085         } else while (tid_agg_rx->reorder_buf[index]) {
3086                 ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
3087                                                 frames);
3088 -               index = ieee80211_sn_sub(tid_agg_rx->head_seq_num,
3089 -                                        tid_agg_rx->ssn) %
3090 -                                                       tid_agg_rx->buf_size;
3091 +               index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
3092         }
3093  
3094         if (tid_agg_rx->stored_mpdu_num) {
3095 -               j = index = ieee80211_sn_sub(tid_agg_rx->head_seq_num,
3096 -                                            tid_agg_rx->ssn) %
3097 -                                                       tid_agg_rx->buf_size;
3098 +               j = index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
3099  
3100                 for (; j != (index - 1) % tid_agg_rx->buf_size;
3101                      j = (j + 1) % tid_agg_rx->buf_size) {
3102 @@ -861,8 +854,7 @@ static bool ieee80211_sta_manage_reorder
3103  
3104         /* Now the new frame is always in the range of the reordering buffer */
3105  
3106 -       index = ieee80211_sn_sub(mpdu_seq_num,
3107 -                                tid_agg_rx->ssn) % tid_agg_rx->buf_size;
3108 +       index = mpdu_seq_num % tid_agg_rx->buf_size;
3109  
3110         /* check if we already stored this frame */
3111         if (tid_agg_rx->reorder_buf[index]) {
3112 --- a/net/mac80211/scan.c
3113 +++ b/net/mac80211/scan.c
3114 @@ -526,7 +526,7 @@ static int __ieee80211_start_scan(struct
3115                 ieee80211_hw_config(local, 0);
3116  
3117                 if ((req->channels[0]->flags &
3118 -                    IEEE80211_CHAN_PASSIVE_SCAN) ||
3119 +                    IEEE80211_CHAN_NO_IR) ||
3120                     !local->scan_req->n_ssids) {
3121                         next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
3122                 } else {
3123 @@ -572,7 +572,7 @@ ieee80211_scan_get_channel_time(struct i
3124          * TODO: channel switching also consumes quite some time,
3125          * add that delay as well to get a better estimation
3126          */
3127 -       if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
3128 +       if (chan->flags & IEEE80211_CHAN_NO_IR)
3129                 return IEEE80211_PASSIVE_CHANNEL_TIME;
3130         return IEEE80211_PROBE_DELAY + IEEE80211_CHANNEL_TIME;
3131  }
3132 @@ -696,7 +696,7 @@ static void ieee80211_scan_state_set_cha
3133          *
3134          * In any case, it is not necessary for a passive scan.
3135          */
3136 -       if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN ||
3137 +       if (chan->flags & IEEE80211_CHAN_NO_IR ||
3138             !local->scan_req->n_ssids) {
3139                 *next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
3140                 local->next_scan_state = SCAN_DECISION;
3141 @@ -881,7 +881,7 @@ int ieee80211_request_ibss_scan(struct i
3142                                 struct ieee80211_channel *tmp_ch =
3143                                     &local->hw.wiphy->bands[band]->channels[i];
3144  
3145 -                               if (tmp_ch->flags & (IEEE80211_CHAN_NO_IBSS |
3146 +                               if (tmp_ch->flags & (IEEE80211_CHAN_NO_IR |
3147                                                      IEEE80211_CHAN_DISABLED))
3148                                         continue;
3149  
3150 @@ -895,7 +895,7 @@ int ieee80211_request_ibss_scan(struct i
3151  
3152                 local->int_scan_req->n_channels = n_ch;
3153         } else {
3154 -               if (WARN_ON_ONCE(chan->flags & (IEEE80211_CHAN_NO_IBSS |
3155 +               if (WARN_ON_ONCE(chan->flags & (IEEE80211_CHAN_NO_IR |
3156                                                 IEEE80211_CHAN_DISABLED)))
3157                         goto unlock;
3158  
3159 --- a/net/mac80211/tx.c
3160 +++ b/net/mac80211/tx.c
3161 @@ -1728,8 +1728,7 @@ netdev_tx_t ieee80211_monitor_start_xmit
3162          * radar detection by itself. We can do that later by adding a
3163          * monitor flag interfaces used for AP support.
3164          */
3165 -       if ((chan->flags & (IEEE80211_CHAN_NO_IBSS | IEEE80211_CHAN_RADAR |
3166 -                           IEEE80211_CHAN_PASSIVE_SCAN)))
3167 +       if ((chan->flags & (IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_RADAR)))
3168                 goto fail_rcu;
3169  
3170         ieee80211_xmit(sdata, skb, chan->band);
3171 --- a/net/mac80211/util.c
3172 +++ b/net/mac80211/util.c
3173 @@ -2259,14 +2259,17 @@ u64 ieee80211_calculate_rx_timestamp(str
3174  void ieee80211_dfs_cac_cancel(struct ieee80211_local *local)
3175  {
3176         struct ieee80211_sub_if_data *sdata;
3177 +       struct cfg80211_chan_def chandef;
3178  
3179         mutex_lock(&local->iflist_mtx);
3180         list_for_each_entry(sdata, &local->interfaces, list) {
3181                 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
3182  
3183                 if (sdata->wdev.cac_started) {
3184 +                       chandef = sdata->vif.bss_conf.chandef;
3185                         ieee80211_vif_release_channel(sdata);
3186                         cfg80211_cac_event(sdata->dev,
3187 +                                          &chandef,
3188                                            NL80211_RADAR_CAC_ABORTED,
3189                                            GFP_KERNEL);
3190                 }
3191 --- a/net/wireless/chan.c
3192 +++ b/net/wireless/chan.c
3193 @@ -277,6 +277,32 @@ void cfg80211_set_dfs_state(struct wiphy
3194                                      width, dfs_state);
3195  }
3196  
3197 +static u32 cfg80211_get_start_freq(u32 center_freq,
3198 +                                  u32 bandwidth)
3199 +{
3200 +       u32 start_freq;
3201 +
3202 +       if (bandwidth <= 20)
3203 +               start_freq = center_freq;
3204 +       else
3205 +               start_freq = center_freq - bandwidth/2 + 10;
3206 +
3207 +       return start_freq;
3208 +}
3209 +
3210 +static u32 cfg80211_get_end_freq(u32 center_freq,
3211 +                                u32 bandwidth)
3212 +{
3213 +       u32 end_freq;
3214 +
3215 +       if (bandwidth <= 20)
3216 +               end_freq = center_freq;
3217 +       else
3218 +               end_freq = center_freq + bandwidth/2 - 10;
3219 +
3220 +       return end_freq;
3221 +}
3222 +
3223  static int cfg80211_get_chans_dfs_required(struct wiphy *wiphy,
3224                                             u32 center_freq,
3225                                             u32 bandwidth)
3226 @@ -284,13 +310,8 @@ static int cfg80211_get_chans_dfs_requir
3227         struct ieee80211_channel *c;
3228         u32 freq, start_freq, end_freq;
3229  
3230 -       if (bandwidth <= 20) {
3231 -               start_freq = center_freq;
3232 -               end_freq = center_freq;
3233 -       } else {
3234 -               start_freq = center_freq - bandwidth/2 + 10;
3235 -               end_freq = center_freq + bandwidth/2 - 10;
3236 -       }
3237 +       start_freq = cfg80211_get_start_freq(center_freq, bandwidth);
3238 +       end_freq = cfg80211_get_end_freq(center_freq, bandwidth);
3239  
3240         for (freq = start_freq; freq <= end_freq; freq += 20) {
3241                 c = ieee80211_get_channel(wiphy, freq);
3242 @@ -330,33 +351,159 @@ int cfg80211_chandef_dfs_required(struct
3243  }
3244  EXPORT_SYMBOL(cfg80211_chandef_dfs_required);
3245  
3246 -static bool cfg80211_secondary_chans_ok(struct wiphy *wiphy,
3247 -                                       u32 center_freq, u32 bandwidth,
3248 -                                       u32 prohibited_flags)
3249 +static int cfg80211_get_chans_dfs_usable(struct wiphy *wiphy,
3250 +                                        u32 center_freq,
3251 +                                        u32 bandwidth)
3252  {
3253         struct ieee80211_channel *c;
3254         u32 freq, start_freq, end_freq;
3255 +       int count = 0;
3256  
3257 -       if (bandwidth <= 20) {
3258 -               start_freq = center_freq;
3259 -               end_freq = center_freq;
3260 -       } else {
3261 -               start_freq = center_freq - bandwidth/2 + 10;
3262 -               end_freq = center_freq + bandwidth/2 - 10;
3263 +       start_freq = cfg80211_get_start_freq(center_freq, bandwidth);
3264 +       end_freq = cfg80211_get_end_freq(center_freq, bandwidth);
3265 +
3266 +       /*
3267 +        * Check entire range of channels for the bandwidth.
3268 +        * Check all channels are DFS channels (DFS_USABLE or
3269 +        * DFS_AVAILABLE). Return number of usable channels
3270 +        * (require CAC). Allow DFS and non-DFS channel mix.
3271 +        */
3272 +       for (freq = start_freq; freq <= end_freq; freq += 20) {
3273 +               c = ieee80211_get_channel(wiphy, freq);
3274 +               if (!c)
3275 +                       return -EINVAL;
3276 +
3277 +               if (c->flags & IEEE80211_CHAN_DISABLED)
3278 +                       return -EINVAL;
3279 +
3280 +               if (c->flags & IEEE80211_CHAN_RADAR) {
3281 +                       if (c->dfs_state == NL80211_DFS_UNAVAILABLE)
3282 +                               return -EINVAL;
3283 +
3284 +                       if (c->dfs_state == NL80211_DFS_USABLE)
3285 +                               count++;
3286 +               }
3287 +       }
3288 +
3289 +       return count;
3290 +}
3291 +
3292 +bool cfg80211_chandef_dfs_usable(struct wiphy *wiphy,
3293 +                                const struct cfg80211_chan_def *chandef)
3294 +{
3295 +       int width;
3296 +       int r1, r2 = 0;
3297 +
3298 +       if (WARN_ON(!cfg80211_chandef_valid(chandef)))
3299 +               return false;
3300 +
3301 +       width = cfg80211_chandef_get_width(chandef);
3302 +       if (width < 0)
3303 +               return false;
3304 +
3305 +       r1 = cfg80211_get_chans_dfs_usable(wiphy, chandef->center_freq1,
3306 +                                         width);
3307 +
3308 +       if (r1 < 0)
3309 +               return false;
3310 +
3311 +       switch (chandef->width) {
3312 +       case NL80211_CHAN_WIDTH_80P80:
3313 +               WARN_ON(!chandef->center_freq2);
3314 +               r2 = cfg80211_get_chans_dfs_usable(wiphy,
3315 +                                                  chandef->center_freq2,
3316 +                                                  width);
3317 +               if (r2 < 0)
3318 +                       return false;
3319 +               break;
3320 +       default:
3321 +               WARN_ON(chandef->center_freq2);
3322 +               break;
3323         }
3324  
3325 +       return (r1 + r2 > 0);
3326 +}
3327 +
3328 +
3329 +static bool cfg80211_get_chans_dfs_available(struct wiphy *wiphy,
3330 +                                            u32 center_freq,
3331 +                                            u32 bandwidth)
3332 +{
3333 +       struct ieee80211_channel *c;
3334 +       u32 freq, start_freq, end_freq;
3335 +
3336 +       start_freq = cfg80211_get_start_freq(center_freq, bandwidth);
3337 +       end_freq = cfg80211_get_end_freq(center_freq, bandwidth);
3338 +
3339 +       /*
3340 +        * Check entire range of channels for the bandwidth.
3341 +        * If any channel in between is disabled or has not
3342 +        * had gone through CAC return false
3343 +        */
3344         for (freq = start_freq; freq <= end_freq; freq += 20) {
3345                 c = ieee80211_get_channel(wiphy, freq);
3346                 if (!c)
3347                         return false;
3348  
3349 -               /* check for radar flags */
3350 -               if ((prohibited_flags & c->flags & IEEE80211_CHAN_RADAR) &&
3351 +               if (c->flags & IEEE80211_CHAN_DISABLED)
3352 +                       return false;
3353 +
3354 +               if ((c->flags & IEEE80211_CHAN_RADAR)  &&
3355                     (c->dfs_state != NL80211_DFS_AVAILABLE))
3356                         return false;
3357 +       }
3358 +
3359 +       return true;
3360 +}
3361 +
3362 +static bool cfg80211_chandef_dfs_available(struct wiphy *wiphy,
3363 +                               const struct cfg80211_chan_def *chandef)
3364 +{
3365 +       int width;
3366 +       int r;
3367 +
3368 +       if (WARN_ON(!cfg80211_chandef_valid(chandef)))
3369 +               return false;
3370  
3371 -               /* check for the other flags */
3372 -               if (c->flags & prohibited_flags & ~IEEE80211_CHAN_RADAR)
3373 +       width = cfg80211_chandef_get_width(chandef);
3374 +       if (width < 0)
3375 +               return false;
3376 +
3377 +       r = cfg80211_get_chans_dfs_available(wiphy, chandef->center_freq1,
3378 +                                            width);
3379 +
3380 +       /* If any of channels unavailable for cf1 just return */
3381 +       if (!r)
3382 +               return r;
3383 +
3384 +       switch (chandef->width) {
3385 +       case NL80211_CHAN_WIDTH_80P80:
3386 +               WARN_ON(!chandef->center_freq2);
3387 +               r = cfg80211_get_chans_dfs_available(wiphy,
3388 +                                                    chandef->center_freq2,
3389 +                                                    width);
3390 +       default:
3391 +               WARN_ON(chandef->center_freq2);
3392 +               break;
3393 +       }
3394 +
3395 +       return r;
3396 +}
3397 +
3398 +
3399 +static bool cfg80211_secondary_chans_ok(struct wiphy *wiphy,
3400 +                                       u32 center_freq, u32 bandwidth,
3401 +                                       u32 prohibited_flags)
3402 +{
3403 +       struct ieee80211_channel *c;
3404 +       u32 freq, start_freq, end_freq;
3405 +
3406 +       start_freq = cfg80211_get_start_freq(center_freq, bandwidth);
3407 +       end_freq = cfg80211_get_end_freq(center_freq, bandwidth);
3408 +
3409 +       for (freq = start_freq; freq <= end_freq; freq += 20) {
3410 +               c = ieee80211_get_channel(wiphy, freq);
3411 +               if (!c || c->flags & prohibited_flags)
3412                         return false;
3413         }
3414  
3415 @@ -462,14 +609,19 @@ bool cfg80211_reg_can_beacon(struct wiph
3416                              struct cfg80211_chan_def *chandef)
3417  {
3418         bool res;
3419 +       u32 prohibited_flags = IEEE80211_CHAN_DISABLED |
3420 +                              IEEE80211_CHAN_NO_IR |
3421 +                              IEEE80211_CHAN_RADAR;
3422  
3423         trace_cfg80211_reg_can_beacon(wiphy, chandef);
3424  
3425 -       res = cfg80211_chandef_usable(wiphy, chandef,
3426 -                                     IEEE80211_CHAN_DISABLED |
3427 -                                     IEEE80211_CHAN_PASSIVE_SCAN |
3428 -                                     IEEE80211_CHAN_NO_IBSS |
3429 -                                     IEEE80211_CHAN_RADAR);
3430 +       if (cfg80211_chandef_dfs_required(wiphy, chandef) > 0 &&
3431 +           cfg80211_chandef_dfs_available(wiphy, chandef)) {
3432 +               /* We can skip IEEE80211_CHAN_NO_IR if chandef dfs available */
3433 +               prohibited_flags = IEEE80211_CHAN_DISABLED;
3434 +       }
3435 +
3436 +       res = cfg80211_chandef_usable(wiphy, chandef, prohibited_flags);
3437  
3438         trace_cfg80211_return_bool(res);
3439         return res;
3440 --- a/net/wireless/core.h
3441 +++ b/net/wireless/core.h
3442 @@ -382,6 +382,19 @@ int cfg80211_can_use_iftype_chan(struct 
3443                                  enum cfg80211_chan_mode chanmode,
3444                                  u8 radar_detect);
3445  
3446 +/**
3447 + * cfg80211_chandef_dfs_usable - checks if chandef is DFS usable
3448 + * @wiphy: the wiphy to validate against
3449 + * @chandef: the channel definition to check
3450 + *
3451 + * Checks if chandef is usable and we can/need start CAC on such channel.
3452 + *
3453 + * Return: Return true if all channels available and at least
3454 + *        one channel require CAC (NL80211_DFS_USABLE)
3455 + */
3456 +bool cfg80211_chandef_dfs_usable(struct wiphy *wiphy,
3457 +                                const struct cfg80211_chan_def *chandef);
3458 +
3459  void cfg80211_set_dfs_state(struct wiphy *wiphy,
3460                             const struct cfg80211_chan_def *chandef,
3461                             enum nl80211_dfs_state dfs_state);
3462 --- a/net/wireless/genregdb.awk
3463 +++ b/net/wireless/genregdb.awk
3464 @@ -107,10 +107,13 @@ active && /^[ \t]*\(/ {
3465                 } else if (flagarray[arg] == "PTMP-ONLY") {
3466                         flags = flags "\n\t\t\tNL80211_RRF_PTMP_ONLY | "
3467                 } else if (flagarray[arg] == "PASSIVE-SCAN") {
3468 -                       flags = flags "\n\t\t\tNL80211_RRF_PASSIVE_SCAN | "
3469 +                       flags = flags "\n\t\t\tNL80211_RRF_NO_IR | "
3470                 } else if (flagarray[arg] == "NO-IBSS") {
3471 -                       flags = flags "\n\t\t\tNL80211_RRF_NO_IBSS | "
3472 +                       flags = flags "\n\t\t\tNL80211_RRF_NO_IR | "
3473 +               } else if (flagarray[arg] == "NO-IR") {
3474 +                       flags = flags "\n\t\t\tNL80211_RRF_NO_IR | "
3475                 }
3476 +
3477         }
3478         flags = flags "0"
3479         printf "\t\tREG_RULE(%d, %d, %d, %d, %d, %s),\n", start, end, bw, gain, power, flags
3480 --- a/net/wireless/ibss.c
3481 +++ b/net/wireless/ibss.c
3482 @@ -274,7 +274,7 @@ int cfg80211_ibss_wext_join(struct cfg80
3483  
3484                         for (i = 0; i < sband->n_channels; i++) {
3485                                 chan = &sband->channels[i];
3486 -                               if (chan->flags & IEEE80211_CHAN_NO_IBSS)
3487 +                               if (chan->flags & IEEE80211_CHAN_NO_IR)
3488                                         continue;
3489                                 if (chan->flags & IEEE80211_CHAN_DISABLED)
3490                                         continue;
3491 @@ -345,7 +345,7 @@ int cfg80211_ibss_wext_siwfreq(struct ne
3492                 chan = ieee80211_get_channel(wdev->wiphy, freq);
3493                 if (!chan)
3494                         return -EINVAL;
3495 -               if (chan->flags & IEEE80211_CHAN_NO_IBSS ||
3496 +               if (chan->flags & IEEE80211_CHAN_NO_IR ||
3497                     chan->flags & IEEE80211_CHAN_DISABLED)
3498                         return -EINVAL;
3499         }
3500 --- a/net/wireless/mesh.c
3501 +++ b/net/wireless/mesh.c
3502 @@ -141,8 +141,7 @@ int __cfg80211_join_mesh(struct cfg80211
3503  
3504                         for (i = 0; i < sband->n_channels; i++) {
3505                                 chan = &sband->channels[i];
3506 -                               if (chan->flags & (IEEE80211_CHAN_NO_IBSS |
3507 -                                                  IEEE80211_CHAN_PASSIVE_SCAN |
3508 +                               if (chan->flags & (IEEE80211_CHAN_NO_IR |
3509                                                    IEEE80211_CHAN_DISABLED |
3510                                                    IEEE80211_CHAN_RADAR))
3511                                         continue;
3512 --- a/net/wireless/mlme.c
3513 +++ b/net/wireless/mlme.c
3514 @@ -763,12 +763,12 @@ void cfg80211_radar_event(struct wiphy *
3515  EXPORT_SYMBOL(cfg80211_radar_event);
3516  
3517  void cfg80211_cac_event(struct net_device *netdev,
3518 +                       const struct cfg80211_chan_def *chandef,
3519                         enum nl80211_radar_event event, gfp_t gfp)
3520  {
3521         struct wireless_dev *wdev = netdev->ieee80211_ptr;
3522         struct wiphy *wiphy = wdev->wiphy;
3523         struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
3524 -       struct cfg80211_chan_def chandef;
3525         unsigned long timeout;
3526  
3527         trace_cfg80211_cac_event(netdev, event);
3528 @@ -779,14 +779,12 @@ void cfg80211_cac_event(struct net_devic
3529         if (WARN_ON(!wdev->channel))
3530                 return;
3531  
3532 -       cfg80211_chandef_create(&chandef, wdev->channel, NL80211_CHAN_NO_HT);
3533 -
3534         switch (event) {
3535         case NL80211_RADAR_CAC_FINISHED:
3536                 timeout = wdev->cac_start_time +
3537                           msecs_to_jiffies(IEEE80211_DFS_MIN_CAC_TIME_MS);
3538                 WARN_ON(!time_after_eq(jiffies, timeout));
3539 -               cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_AVAILABLE);
3540 +               cfg80211_set_dfs_state(wiphy, chandef, NL80211_DFS_AVAILABLE);
3541                 break;
3542         case NL80211_RADAR_CAC_ABORTED:
3543                 break;
3544 @@ -796,6 +794,6 @@ void cfg80211_cac_event(struct net_devic
3545         }
3546         wdev->cac_started = false;
3547  
3548 -       nl80211_radar_notify(rdev, &chandef, event, netdev, gfp);
3549 +       nl80211_radar_notify(rdev, chandef, event, netdev, gfp);
3550  }
3551  EXPORT_SYMBOL(cfg80211_cac_event);
3552 --- a/net/wireless/nl80211.c
3553 +++ b/net/wireless/nl80211.c
3554 @@ -545,12 +545,12 @@ static int nl80211_msg_put_channel(struc
3555         if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
3556             nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
3557                 goto nla_put_failure;
3558 -       if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
3559 -           nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
3560 -               goto nla_put_failure;
3561 -       if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
3562 -           nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
3563 -               goto nla_put_failure;
3564 +       if (chan->flags & IEEE80211_CHAN_NO_IR) {
3565 +               if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
3566 +                       goto nla_put_failure;
3567 +               if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
3568 +                       goto nla_put_failure;
3569 +       }
3570         if (chan->flags & IEEE80211_CHAN_RADAR) {
3571                 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
3572                         goto nla_put_failure;
3573 @@ -1229,7 +1229,7 @@ static int nl80211_send_wiphy(struct cfg
3574                     nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
3575                         goto nla_put_failure;
3576                 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
3577 -                   nla_put_flag(msg, WIPHY_FLAG_SUPPORTS_5_10_MHZ))
3578 +                   nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_10_MHZ))
3579                         goto nla_put_failure;
3580  
3581                 state->split_start++;
3582 @@ -2170,7 +2170,7 @@ static inline u64 wdev_id(struct wireles
3583  }
3584  
3585  static int nl80211_send_chandef(struct sk_buff *msg,
3586 -                                struct cfg80211_chan_def *chandef)
3587 +                               const struct cfg80211_chan_def *chandef)
3588  {
3589         WARN_ON(!cfg80211_chandef_valid(chandef));
3590  
3591 @@ -5653,7 +5653,7 @@ static int nl80211_start_radar_detection
3592         if (err == 0)
3593                 return -EINVAL;
3594  
3595 -       if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
3596 +       if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
3597                 return -EINVAL;
3598  
3599         if (!rdev->ops->start_radar_detection)
3600 @@ -10882,7 +10882,7 @@ EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
3601  
3602  void
3603  nl80211_radar_notify(struct cfg80211_registered_device *rdev,
3604 -                    struct cfg80211_chan_def *chandef,
3605 +                    const struct cfg80211_chan_def *chandef,
3606                      enum nl80211_radar_event event,
3607                      struct net_device *netdev, gfp_t gfp)
3608  {
3609 --- a/net/wireless/nl80211.h
3610 +++ b/net/wireless/nl80211.h
3611 @@ -70,7 +70,7 @@ int nl80211_send_mgmt(struct cfg80211_re
3612  
3613  void
3614  nl80211_radar_notify(struct cfg80211_registered_device *rdev,
3615 -                    struct cfg80211_chan_def *chandef,
3616 +                    const struct cfg80211_chan_def *chandef,
3617                      enum nl80211_radar_event event,
3618                      struct net_device *netdev, gfp_t gfp);
3619  
3620 --- a/net/wireless/reg.c
3621 +++ b/net/wireless/reg.c
3622 @@ -163,35 +163,29 @@ static const struct ieee80211_regdomain 
3623                 REG_RULE(2412-10, 2462+10, 40, 6, 20, 0),
3624                 /* IEEE 802.11b/g, channels 12..13. */
3625                 REG_RULE(2467-10, 2472+10, 40, 6, 20,
3626 -                       NL80211_RRF_PASSIVE_SCAN |
3627 -                       NL80211_RRF_NO_IBSS),
3628 +                       NL80211_RRF_NO_IR),
3629                 /* IEEE 802.11 channel 14 - Only JP enables
3630                  * this and for 802.11b only */
3631                 REG_RULE(2484-10, 2484+10, 20, 6, 20,
3632 -                       NL80211_RRF_PASSIVE_SCAN |
3633 -                       NL80211_RRF_NO_IBSS |
3634 +                       NL80211_RRF_NO_IR |
3635                         NL80211_RRF_NO_OFDM),
3636                 /* IEEE 802.11a, channel 36..48 */
3637                 REG_RULE(5180-10, 5240+10, 160, 6, 20,
3638 -                        NL80211_RRF_PASSIVE_SCAN |
3639 -                        NL80211_RRF_NO_IBSS),
3640 +                        NL80211_RRF_NO_IR),
3641  
3642                 /* IEEE 802.11a, channel 52..64 - DFS required */
3643                 REG_RULE(5260-10, 5320+10, 160, 6, 20,
3644 -                       NL80211_RRF_PASSIVE_SCAN |
3645 -                       NL80211_RRF_NO_IBSS |
3646 +                       NL80211_RRF_NO_IR |
3647                         NL80211_RRF_DFS),
3648  
3649                 /* IEEE 802.11a, channel 100..144 - DFS required */
3650                 REG_RULE(5500-10, 5720+10, 160, 6, 20,
3651 -                       NL80211_RRF_PASSIVE_SCAN |
3652 -                       NL80211_RRF_NO_IBSS |
3653 +                       NL80211_RRF_NO_IR |
3654                         NL80211_RRF_DFS),
3655  
3656                 /* IEEE 802.11a, channel 149..165 */
3657                 REG_RULE(5745-10, 5825+10, 80, 6, 20,
3658 -                       NL80211_RRF_PASSIVE_SCAN |
3659 -                       NL80211_RRF_NO_IBSS),
3660 +                       NL80211_RRF_NO_IR),
3661  
3662                 /* IEEE 802.11ad (60gHz), channels 1..3 */
3663                 REG_RULE(56160+2160*1-1080, 56160+2160*3+1080, 2160, 0, 0, 0),
3664 @@ -698,10 +692,8 @@ regdom_intersect(const struct ieee80211_
3665  static u32 map_regdom_flags(u32 rd_flags)
3666  {
3667         u32 channel_flags = 0;
3668 -       if (rd_flags & NL80211_RRF_PASSIVE_SCAN)
3669 -               channel_flags |= IEEE80211_CHAN_PASSIVE_SCAN;
3670 -       if (rd_flags & NL80211_RRF_NO_IBSS)
3671 -               channel_flags |= IEEE80211_CHAN_NO_IBSS;
3672 +       if (rd_flags & NL80211_RRF_NO_IR_ALL)
3673 +               channel_flags |= IEEE80211_CHAN_NO_IR;
3674         if (rd_flags & NL80211_RRF_DFS)
3675                 channel_flags |= IEEE80211_CHAN_RADAR;
3676         if (rd_flags & NL80211_RRF_NO_OFDM)
3677 @@ -1066,13 +1058,8 @@ static void handle_reg_beacon(struct wip
3678         chan_before.center_freq = chan->center_freq;
3679         chan_before.flags = chan->flags;
3680  
3681 -       if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) {
3682 -               chan->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
3683 -               channel_changed = true;
3684 -       }
3685 -
3686 -       if (chan->flags & IEEE80211_CHAN_NO_IBSS) {
3687 -               chan->flags &= ~IEEE80211_CHAN_NO_IBSS;
3688 +       if (chan->flags & IEEE80211_CHAN_NO_IR) {
3689 +               chan->flags &= ~IEEE80211_CHAN_NO_IR;
3690                 channel_changed = true;
3691         }
3692  
3693 --- /dev/null
3694 +++ b/drivers/net/wireless/ath/ath9k/ar9003_wow.c
3695 @@ -0,0 +1,422 @@
3696 +/*
3697 + * Copyright (c) 2012 Qualcomm Atheros, Inc.
3698 + *
3699 + * Permission to use, copy, modify, and/or distribute this software for any
3700 + * purpose with or without fee is hereby granted, provided that the above
3701 + * copyright notice and this permission notice appear in all copies.
3702 + *
3703 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
3704 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
3705 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
3706 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
3707 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
3708 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
3709 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3710 + */
3711 +
3712 +#include <linux/export.h>
3713 +#include "ath9k.h"
3714 +#include "reg.h"
3715 +#include "hw-ops.h"
3716 +
3717 +const char *ath9k_hw_wow_event_to_string(u32 wow_event)
3718 +{
3719 +       if (wow_event & AH_WOW_MAGIC_PATTERN_EN)
3720 +               return "Magic pattern";
3721 +       if (wow_event & AH_WOW_USER_PATTERN_EN)
3722 +               return "User pattern";
3723 +       if (wow_event & AH_WOW_LINK_CHANGE)
3724 +               return "Link change";
3725 +       if (wow_event & AH_WOW_BEACON_MISS)
3726 +               return "Beacon miss";
3727 +
3728 +       return  "unknown reason";
3729 +}
3730 +EXPORT_SYMBOL(ath9k_hw_wow_event_to_string);
3731 +
3732 +static void ath9k_hw_set_powermode_wow_sleep(struct ath_hw *ah)
3733 +{
3734 +       struct ath_common *common = ath9k_hw_common(ah);
3735 +
3736 +       REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
3737 +
3738 +       /* set rx disable bit */
3739 +       REG_WRITE(ah, AR_CR, AR_CR_RXD);
3740 +
3741 +       if (!ath9k_hw_wait(ah, AR_CR, AR_CR_RXE, 0, AH_WAIT_TIMEOUT)) {
3742 +               ath_err(common, "Failed to stop Rx DMA in 10ms AR_CR=0x%08x AR_DIAG_SW=0x%08x\n",
3743 +                       REG_READ(ah, AR_CR), REG_READ(ah, AR_DIAG_SW));
3744 +               return;
3745 +       }
3746 +
3747 +       REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_ON_INT);
3748 +}
3749 +
3750 +static void ath9k_wow_create_keep_alive_pattern(struct ath_hw *ah)
3751 +{
3752 +       struct ath_common *common = ath9k_hw_common(ah);
3753 +       u8 sta_mac_addr[ETH_ALEN], ap_mac_addr[ETH_ALEN];
3754 +       u32 ctl[13] = {0};
3755 +       u32 data_word[KAL_NUM_DATA_WORDS];
3756 +       u8 i;
3757 +       u32 wow_ka_data_word0;
3758 +
3759 +       memcpy(sta_mac_addr, common->macaddr, ETH_ALEN);
3760 +       memcpy(ap_mac_addr, common->curbssid, ETH_ALEN);
3761 +
3762 +       /* set the transmit buffer */
3763 +       ctl[0] = (KAL_FRAME_LEN | (MAX_RATE_POWER << 16));
3764 +       ctl[1] = 0;
3765 +       ctl[3] = 0xb;   /* OFDM_6M hardware value for this rate */
3766 +       ctl[4] = 0;
3767 +       ctl[7] = (ah->txchainmask) << 2;
3768 +       ctl[2] = 0xf << 16; /* tx_tries 0 */
3769 +
3770 +       for (i = 0; i < KAL_NUM_DESC_WORDS; i++)
3771 +               REG_WRITE(ah, (AR_WOW_KA_DESC_WORD2 + i * 4), ctl[i]);
3772 +
3773 +       REG_WRITE(ah, (AR_WOW_KA_DESC_WORD2 + i * 4), ctl[i]);
3774 +
3775 +       data_word[0] = (KAL_FRAME_TYPE << 2) | (KAL_FRAME_SUB_TYPE << 4) |
3776 +                      (KAL_TO_DS << 8) | (KAL_DURATION_ID << 16);
3777 +       data_word[1] = (ap_mac_addr[3] << 24) | (ap_mac_addr[2] << 16) |
3778 +                      (ap_mac_addr[1] << 8) | (ap_mac_addr[0]);
3779 +       data_word[2] = (sta_mac_addr[1] << 24) | (sta_mac_addr[0] << 16) |
3780 +                      (ap_mac_addr[5] << 8) | (ap_mac_addr[4]);
3781 +       data_word[3] = (sta_mac_addr[5] << 24) | (sta_mac_addr[4] << 16) |
3782 +                      (sta_mac_addr[3] << 8) | (sta_mac_addr[2]);
3783 +       data_word[4] = (ap_mac_addr[3] << 24) | (ap_mac_addr[2] << 16) |
3784 +                      (ap_mac_addr[1] << 8) | (ap_mac_addr[0]);
3785 +       data_word[5] = (ap_mac_addr[5] << 8) | (ap_mac_addr[4]);
3786 +
3787 +       if (AR_SREV_9462_20(ah)) {
3788 +               /* AR9462 2.0 has an extra descriptor word (time based
3789 +                * discard) compared to other chips */
3790 +               REG_WRITE(ah, (AR_WOW_KA_DESC_WORD2 + (12 * 4)), 0);
3791 +               wow_ka_data_word0 = AR_WOW_TXBUF(13);
3792 +       } else {
3793 +               wow_ka_data_word0 = AR_WOW_TXBUF(12);
3794 +       }
3795 +
3796 +       for (i = 0; i < KAL_NUM_DATA_WORDS; i++)
3797 +               REG_WRITE(ah, (wow_ka_data_word0 + i*4), data_word[i]);
3798 +
3799 +}
3800 +
3801 +void ath9k_hw_wow_apply_pattern(struct ath_hw *ah, u8 *user_pattern,
3802 +                               u8 *user_mask, int pattern_count,
3803 +                               int pattern_len)
3804 +{
3805 +       int i;
3806 +       u32 pattern_val, mask_val;
3807 +       u32 set, clr;
3808 +
3809 +       /* FIXME: should check count by querying the hardware capability */
3810 +       if (pattern_count >= MAX_NUM_PATTERN)
3811 +               return;
3812 +
3813 +       REG_SET_BIT(ah, AR_WOW_PATTERN, BIT(pattern_count));
3814 +
3815 +       /* set the registers for pattern */
3816 +       for (i = 0; i < MAX_PATTERN_SIZE; i += 4) {
3817 +               memcpy(&pattern_val, user_pattern, 4);
3818 +               REG_WRITE(ah, (AR_WOW_TB_PATTERN(pattern_count) + i),
3819 +                         pattern_val);
3820 +               user_pattern += 4;
3821 +       }
3822 +
3823 +       /* set the registers for mask */
3824 +       for (i = 0; i < MAX_PATTERN_MASK_SIZE; i += 4) {
3825 +               memcpy(&mask_val, user_mask, 4);
3826 +               REG_WRITE(ah, (AR_WOW_TB_MASK(pattern_count) + i), mask_val);
3827 +               user_mask += 4;
3828 +       }
3829 +
3830 +       /* set the pattern length to be matched
3831 +        *
3832 +        * AR_WOW_LENGTH1_REG1
3833 +        * bit 31:24 pattern 0 length
3834 +        * bit 23:16 pattern 1 length
3835 +        * bit 15:8 pattern 2 length
3836 +        * bit 7:0 pattern 3 length
3837 +        *
3838 +        * AR_WOW_LENGTH1_REG2
3839 +        * bit 31:24 pattern 4 length
3840 +        * bit 23:16 pattern 5 length
3841 +        * bit 15:8 pattern 6 length
3842 +        * bit 7:0 pattern 7 length
3843 +        *
3844 +        * the below logic writes out the new
3845 +        * pattern length for the corresponding
3846 +        * pattern_count, while masking out the
3847 +        * other fields
3848 +        */
3849 +
3850 +       ah->wow_event_mask |= BIT(pattern_count + AR_WOW_PAT_FOUND_SHIFT);
3851 +
3852 +       if (pattern_count < 4) {
3853 +               /* Pattern 0-3 uses AR_WOW_LENGTH1 register */
3854 +               set = (pattern_len & AR_WOW_LENGTH_MAX) <<
3855 +                      AR_WOW_LEN1_SHIFT(pattern_count);
3856 +               clr = AR_WOW_LENGTH1_MASK(pattern_count);
3857 +               REG_RMW(ah, AR_WOW_LENGTH1, set, clr);
3858 +       } else {
3859 +               /* Pattern 4-7 uses AR_WOW_LENGTH2 register */
3860 +               set = (pattern_len & AR_WOW_LENGTH_MAX) <<
3861 +                      AR_WOW_LEN2_SHIFT(pattern_count);
3862 +               clr = AR_WOW_LENGTH2_MASK(pattern_count);
3863 +               REG_RMW(ah, AR_WOW_LENGTH2, set, clr);
3864 +       }
3865 +
3866 +}
3867 +EXPORT_SYMBOL(ath9k_hw_wow_apply_pattern);
3868 +
3869 +u32 ath9k_hw_wow_wakeup(struct ath_hw *ah)
3870 +{
3871 +       u32 wow_status = 0;
3872 +       u32 val = 0, rval;
3873 +
3874 +       /*
3875 +        * read the WoW status register to know
3876 +        * the wakeup reason
3877 +        */
3878 +       rval = REG_READ(ah, AR_WOW_PATTERN);
3879 +       val = AR_WOW_STATUS(rval);
3880 +
3881 +       /*
3882 +        * mask only the WoW events that we have enabled. Sometimes
3883 +        * we have spurious WoW events from the AR_WOW_PATTERN
3884 +        * register. This mask will clean it up.
3885 +        */
3886 +
3887 +       val &= ah->wow_event_mask;
3888 +
3889 +       if (val) {
3890 +               if (val & AR_WOW_MAGIC_PAT_FOUND)
3891 +                       wow_status |= AH_WOW_MAGIC_PATTERN_EN;
3892 +               if (AR_WOW_PATTERN_FOUND(val))
3893 +                       wow_status |= AH_WOW_USER_PATTERN_EN;
3894 +               if (val & AR_WOW_KEEP_ALIVE_FAIL)
3895 +                       wow_status |= AH_WOW_LINK_CHANGE;
3896 +               if (val & AR_WOW_BEACON_FAIL)
3897 +                       wow_status |= AH_WOW_BEACON_MISS;
3898 +       }
3899 +
3900 +       /*
3901 +        * set and clear WOW_PME_CLEAR registers for the chip to
3902 +        * generate next wow signal.
3903 +        * disable D3 before accessing other registers ?
3904 +        */
3905 +
3906 +       /* do we need to check the bit value 0x01000000 (7-10) ?? */
3907 +       REG_RMW(ah, AR_PCIE_PM_CTRL, AR_PMCTRL_WOW_PME_CLR,
3908 +               AR_PMCTRL_PWR_STATE_D1D3);
3909 +
3910 +       /*
3911 +        * clear all events
3912 +        */
3913 +       REG_WRITE(ah, AR_WOW_PATTERN,
3914 +                 AR_WOW_CLEAR_EVENTS(REG_READ(ah, AR_WOW_PATTERN)));
3915 +
3916 +       /*
3917 +        * restore the beacon threshold to init value
3918 +        */
3919 +       REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
3920 +
3921 +       /*
3922 +        * Restore the way the PCI-E reset, Power-On-Reset, external
3923 +        * PCIE_POR_SHORT pins are tied to its original value.
3924 +        * Previously just before WoW sleep, we untie the PCI-E
3925 +        * reset to our Chip's Power On Reset so that any PCI-E
3926 +        * reset from the bus will not reset our chip
3927 +        */
3928 +       if (ah->is_pciexpress)
3929 +               ath9k_hw_configpcipowersave(ah, false);
3930 +
3931 +       ah->wow_event_mask = 0;
3932 +
3933 +       return wow_status;
3934 +}
3935 +EXPORT_SYMBOL(ath9k_hw_wow_wakeup);
3936 +
3937 +void ath9k_hw_wow_enable(struct ath_hw *ah, u32 pattern_enable)
3938 +{
3939 +       u32 wow_event_mask;
3940 +       u32 set, clr;
3941 +
3942 +       /*
3943 +        * wow_event_mask is a mask to the AR_WOW_PATTERN register to
3944 +        * indicate which WoW events we have enabled. The WoW events
3945 +        * are from the 'pattern_enable' in this function and
3946 +        * 'pattern_count' of ath9k_hw_wow_apply_pattern()
3947 +        */
3948 +       wow_event_mask = ah->wow_event_mask;
3949 +
3950 +       /*
3951 +        * Untie Power-on-Reset from the PCI-E-Reset. When we are in
3952 +        * WOW sleep, we do want the Reset from the PCI-E to disturb
3953 +        * our hw state
3954 +        */
3955 +       if (ah->is_pciexpress) {
3956 +               /*
3957 +                * we need to untie the internal POR (power-on-reset)
3958 +                * to the external PCI-E reset. We also need to tie
3959 +                * the PCI-E Phy reset to the PCI-E reset.
3960 +                */
3961 +               set = AR_WA_RESET_EN | AR_WA_POR_SHORT;
3962 +               clr = AR_WA_UNTIE_RESET_EN | AR_WA_D3_L1_DISABLE;
3963 +               REG_RMW(ah, AR_WA, set, clr);
3964 +       }
3965 +
3966 +       /*
3967 +        * set the power states appropriately and enable PME
3968 +        */
3969 +       set = AR_PMCTRL_HOST_PME_EN | AR_PMCTRL_PWR_PM_CTRL_ENA |
3970 +             AR_PMCTRL_AUX_PWR_DET | AR_PMCTRL_WOW_PME_CLR;
3971 +
3972 +       /*
3973 +        * set and clear WOW_PME_CLEAR registers for the chip
3974 +        * to generate next wow signal.
3975 +        */
3976 +       REG_SET_BIT(ah, AR_PCIE_PM_CTRL, set);
3977 +       clr = AR_PMCTRL_WOW_PME_CLR;
3978 +       REG_CLR_BIT(ah, AR_PCIE_PM_CTRL, clr);
3979 +
3980 +       /*
3981 +        * Setup for:
3982 +        *      - beacon misses
3983 +        *      - magic pattern
3984 +        *      - keep alive timeout
3985 +        *      - pattern matching
3986 +        */
3987 +
3988 +       /*
3989 +        * Program default values for pattern backoff, aifs/slot/KAL count,
3990 +        * beacon miss timeout, KAL timeout, etc.
3991 +        */
3992 +       set = AR_WOW_BACK_OFF_SHIFT(AR_WOW_PAT_BACKOFF);
3993 +       REG_SET_BIT(ah, AR_WOW_PATTERN, set);
3994 +
3995 +       set = AR_WOW_AIFS_CNT(AR_WOW_CNT_AIFS_CNT) |
3996 +             AR_WOW_SLOT_CNT(AR_WOW_CNT_SLOT_CNT) |
3997 +             AR_WOW_KEEP_ALIVE_CNT(AR_WOW_CNT_KA_CNT);
3998 +       REG_SET_BIT(ah, AR_WOW_COUNT, set);
3999 +
4000 +       if (pattern_enable & AH_WOW_BEACON_MISS)
4001 +               set = AR_WOW_BEACON_TIMO;
4002 +       /* We are not using beacon miss, program a large value */
4003 +       else
4004 +               set = AR_WOW_BEACON_TIMO_MAX;
4005 +
4006 +       REG_WRITE(ah, AR_WOW_BCN_TIMO, set);
4007 +
4008 +       /*
4009 +        * Keep alive timo in ms except AR9280
4010 +        */
4011 +       if (!pattern_enable)
4012 +               set = AR_WOW_KEEP_ALIVE_NEVER;
4013 +       else
4014 +               set = KAL_TIMEOUT * 32;
4015 +
4016 +       REG_WRITE(ah, AR_WOW_KEEP_ALIVE_TIMO, set);
4017 +
4018 +       /*
4019 +        * Keep alive delay in us. based on 'power on clock',
4020 +        * therefore in usec
4021 +        */
4022 +       set = KAL_DELAY * 1000;
4023 +       REG_WRITE(ah, AR_WOW_KEEP_ALIVE_DELAY, set);
4024 +
4025 +       /*
4026 +        * Create keep alive pattern to respond to beacons
4027 +        */
4028 +       ath9k_wow_create_keep_alive_pattern(ah);
4029 +
4030 +       /*
4031 +        * Configure MAC WoW Registers
4032 +        */
4033 +       set = 0;
4034 +       /* Send keep alive timeouts anyway */
4035 +       clr = AR_WOW_KEEP_ALIVE_AUTO_DIS;
4036 +
4037 +       if (pattern_enable & AH_WOW_LINK_CHANGE)
4038 +               wow_event_mask |= AR_WOW_KEEP_ALIVE_FAIL;
4039 +       else
4040 +               set = AR_WOW_KEEP_ALIVE_FAIL_DIS;
4041 +
4042 +       set = AR_WOW_KEEP_ALIVE_FAIL_DIS;
4043 +       REG_RMW(ah, AR_WOW_KEEP_ALIVE, set, clr);
4044 +
4045 +       /*
4046 +        * we are relying on a bmiss failure. ensure we have
4047 +        * enough threshold to prevent false positives
4048 +        */
4049 +       REG_RMW_FIELD(ah, AR_RSSI_THR, AR_RSSI_THR_BM_THR,
4050 +                     AR_WOW_BMISSTHRESHOLD);
4051 +
4052 +       set = 0;
4053 +       clr = 0;
4054 +
4055 +       if (pattern_enable & AH_WOW_BEACON_MISS) {
4056 +               set = AR_WOW_BEACON_FAIL_EN;
4057 +               wow_event_mask |= AR_WOW_BEACON_FAIL;
4058 +       } else {
4059 +               clr = AR_WOW_BEACON_FAIL_EN;
4060 +       }
4061 +
4062 +       REG_RMW(ah, AR_WOW_BCN_EN, set, clr);
4063 +
4064 +       set = 0;
4065 +       clr = 0;
4066 +       /*
4067 +        * Enable the magic packet registers
4068 +        */
4069 +       if (pattern_enable & AH_WOW_MAGIC_PATTERN_EN) {
4070 +               set = AR_WOW_MAGIC_EN;
4071 +               wow_event_mask |= AR_WOW_MAGIC_PAT_FOUND;
4072 +       } else {
4073 +               clr = AR_WOW_MAGIC_EN;
4074 +       }
4075 +       set |= AR_WOW_MAC_INTR_EN;
4076 +       REG_RMW(ah, AR_WOW_PATTERN, set, clr);
4077 +
4078 +       REG_WRITE(ah, AR_WOW_PATTERN_MATCH_LT_256B,
4079 +                 AR_WOW_PATTERN_SUPPORTED);
4080 +
4081 +       /*
4082 +        * Set the power states appropriately and enable PME
4083 +        */
4084 +       clr = 0;
4085 +       set = AR_PMCTRL_PWR_STATE_D1D3 | AR_PMCTRL_HOST_PME_EN |
4086 +             AR_PMCTRL_PWR_PM_CTRL_ENA;
4087 +
4088 +       clr = AR_PCIE_PM_CTRL_ENA;
4089 +       REG_RMW(ah, AR_PCIE_PM_CTRL, set, clr);
4090 +
4091 +       /*
4092 +        * this is needed to prevent the chip waking up
4093 +        * the host within 3-4 seconds with certain
4094 +        * platform/BIOS. The fix is to enable
4095 +        * D1 & D3 to match original definition and
4096 +        * also match the OTP value. Anyway this
4097 +        * is more related to SW WOW.
4098 +        */
4099 +       clr = AR_PMCTRL_PWR_STATE_D1D3;
4100 +       REG_CLR_BIT(ah, AR_PCIE_PM_CTRL, clr);
4101 +
4102 +       set = AR_PMCTRL_PWR_STATE_D1D3_REAL;
4103 +       REG_SET_BIT(ah, AR_PCIE_PM_CTRL, set);
4104 +
4105 +       REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PRESERVE_SEQNUM);
4106 +
4107 +       /* to bring down WOW power low margin */
4108 +       set = BIT(13);
4109 +       REG_SET_BIT(ah, AR_PCIE_PHY_REG3, set);
4110 +       /* HW WoW */
4111 +       clr = BIT(5);
4112 +       REG_CLR_BIT(ah, AR_PCU_MISC_MODE3, clr);
4113 +
4114 +       ath9k_hw_set_powermode_wow_sleep(ah);
4115 +       ah->wow_event_mask = wow_event_mask;
4116 +}
4117 +EXPORT_SYMBOL(ath9k_hw_wow_enable);
4118 --- /dev/null
4119 +++ b/drivers/net/wireless/ath/ath9k/tx99.c
4120 @@ -0,0 +1,263 @@
4121 +/*
4122 + * Copyright (c) 2013 Qualcomm Atheros, Inc.
4123 + *
4124 + * Permission to use, copy, modify, and/or distribute this software for any
4125 + * purpose with or without fee is hereby granted, provided that the above
4126 + * copyright notice and this permission notice appear in all copies.
4127 + *
4128 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
4129 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
4130 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
4131 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
4132 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
4133 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
4134 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
4135 + */
4136 +
4137 +#include "ath9k.h"
4138 +
4139 +static void ath9k_tx99_stop(struct ath_softc *sc)
4140 +{
4141 +       struct ath_hw *ah = sc->sc_ah;
4142 +       struct ath_common *common = ath9k_hw_common(ah);
4143 +
4144 +       ath_drain_all_txq(sc);
4145 +       ath_startrecv(sc);
4146 +
4147 +       ath9k_hw_set_interrupts(ah);
4148 +       ath9k_hw_enable_interrupts(ah);
4149 +
4150 +       ieee80211_wake_queues(sc->hw);
4151 +
4152 +       kfree_skb(sc->tx99_skb);
4153 +       sc->tx99_skb = NULL;
4154 +       sc->tx99_state = false;
4155 +
4156 +       ath9k_hw_tx99_stop(sc->sc_ah);
4157 +       ath_dbg(common, XMIT, "TX99 stopped\n");
4158 +}
4159 +
4160 +static struct sk_buff *ath9k_build_tx99_skb(struct ath_softc *sc)
4161 +{
4162 +       static u8 PN9Data[] = {0xff, 0x87, 0xb8, 0x59, 0xb7, 0xa1, 0xcc, 0x24,
4163 +                              0x57, 0x5e, 0x4b, 0x9c, 0x0e, 0xe9, 0xea, 0x50,
4164 +                              0x2a, 0xbe, 0xb4, 0x1b, 0xb6, 0xb0, 0x5d, 0xf1,
4165 +                              0xe6, 0x9a, 0xe3, 0x45, 0xfd, 0x2c, 0x53, 0x18,
4166 +                              0x0c, 0xca, 0xc9, 0xfb, 0x49, 0x37, 0xe5, 0xa8,
4167 +                              0x51, 0x3b, 0x2f, 0x61, 0xaa, 0x72, 0x18, 0x84,
4168 +                              0x02, 0x23, 0x23, 0xab, 0x63, 0x89, 0x51, 0xb3,
4169 +                              0xe7, 0x8b, 0x72, 0x90, 0x4c, 0xe8, 0xfb, 0xc0};
4170 +       u32 len = 1200;
4171 +       struct ieee80211_hw *hw = sc->hw;
4172 +       struct ieee80211_hdr *hdr;
4173 +       struct ieee80211_tx_info *tx_info;
4174 +       struct sk_buff *skb;
4175 +
4176 +       skb = alloc_skb(len, GFP_KERNEL);
4177 +       if (!skb)
4178 +               return NULL;
4179 +
4180 +       skb_put(skb, len);
4181 +
4182 +       memset(skb->data, 0, len);
4183 +
4184 +       hdr = (struct ieee80211_hdr *)skb->data;
4185 +       hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA);
4186 +       hdr->duration_id = 0;
4187 +
4188 +       memcpy(hdr->addr1, hw->wiphy->perm_addr, ETH_ALEN);
4189 +       memcpy(hdr->addr2, hw->wiphy->perm_addr, ETH_ALEN);
4190 +       memcpy(hdr->addr3, hw->wiphy->perm_addr, ETH_ALEN);
4191 +
4192 +       hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
4193 +
4194 +       tx_info = IEEE80211_SKB_CB(skb);
4195 +       memset(tx_info, 0, sizeof(*tx_info));
4196 +       tx_info->band = hw->conf.chandef.chan->band;
4197 +       tx_info->flags = IEEE80211_TX_CTL_NO_ACK;
4198 +       tx_info->control.vif = sc->tx99_vif;
4199 +
4200 +       memcpy(skb->data + sizeof(*hdr), PN9Data, sizeof(PN9Data));
4201 +
4202 +       return skb;
4203 +}
4204 +
4205 +static void ath9k_tx99_deinit(struct ath_softc *sc)
4206 +{
4207 +       ath_reset(sc);
4208 +
4209 +       ath9k_ps_wakeup(sc);
4210 +       ath9k_tx99_stop(sc);
4211 +       ath9k_ps_restore(sc);
4212 +}
4213 +
4214 +static int ath9k_tx99_init(struct ath_softc *sc)
4215 +{
4216 +       struct ieee80211_hw *hw = sc->hw;
4217 +       struct ath_hw *ah = sc->sc_ah;
4218 +       struct ath_common *common = ath9k_hw_common(ah);
4219 +       struct ath_tx_control txctl;
4220 +       int r;
4221 +
4222 +       if (test_bit(SC_OP_INVALID, &sc->sc_flags)) {
4223 +               ath_err(common,
4224 +                       "driver is in invalid state unable to use TX99");
4225 +               return -EINVAL;
4226 +       }
4227 +
4228 +       sc->tx99_skb = ath9k_build_tx99_skb(sc);
4229 +       if (!sc->tx99_skb)
4230 +               return -ENOMEM;
4231 +
4232 +       memset(&txctl, 0, sizeof(txctl));
4233 +       txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO];
4234 +
4235 +       ath_reset(sc);
4236 +
4237 +       ath9k_ps_wakeup(sc);
4238 +
4239 +       ath9k_hw_disable_interrupts(ah);
4240 +       atomic_set(&ah->intr_ref_cnt, -1);
4241 +       ath_drain_all_txq(sc);
4242 +       ath_stoprecv(sc);
4243 +
4244 +       sc->tx99_state = true;
4245 +
4246 +       ieee80211_stop_queues(hw);
4247 +
4248 +       if (sc->tx99_power == MAX_RATE_POWER + 1)
4249 +               sc->tx99_power = MAX_RATE_POWER;
4250 +
4251 +       ath9k_hw_tx99_set_txpower(ah, sc->tx99_power);
4252 +       r = ath9k_tx99_send(sc, sc->tx99_skb, &txctl);
4253 +       if (r) {
4254 +               ath_dbg(common, XMIT, "Failed to xmit TX99 skb\n");
4255 +               return r;
4256 +       }
4257 +
4258 +       ath_dbg(common, XMIT, "TX99 xmit started using %d ( %ddBm)\n",
4259 +               sc->tx99_power,
4260 +               sc->tx99_power / 2);
4261 +
4262 +       /* We leave the harware awake as it will be chugging on */
4263 +
4264 +       return 0;
4265 +}
4266 +
4267 +static ssize_t read_file_tx99(struct file *file, char __user *user_buf,
4268 +                             size_t count, loff_t *ppos)
4269 +{
4270 +       struct ath_softc *sc = file->private_data;
4271 +       char buf[3];
4272 +       unsigned int len;
4273 +
4274 +       len = sprintf(buf, "%d\n", sc->tx99_state);
4275 +       return simple_read_from_buffer(user_buf, count, ppos, buf, len);
4276 +}
4277 +
4278 +static ssize_t write_file_tx99(struct file *file, const char __user *user_buf,
4279 +                              size_t count, loff_t *ppos)
4280 +{
4281 +       struct ath_softc *sc = file->private_data;
4282 +       struct ath_common *common = ath9k_hw_common(sc->sc_ah);
4283 +       char buf[32];
4284 +       bool start;
4285 +       ssize_t len;
4286 +       int r;
4287 +
4288 +       if (sc->nvifs > 1)
4289 +               return -EOPNOTSUPP;
4290 +
4291 +       len = min(count, sizeof(buf) - 1);
4292 +       if (copy_from_user(buf, user_buf, len))
4293 +               return -EFAULT;
4294 +
4295 +       if (strtobool(buf, &start))
4296 +               return -EINVAL;
4297 +
4298 +       if (start == sc->tx99_state) {
4299 +               if (!start)
4300 +                       return count;
4301 +               ath_dbg(common, XMIT, "Resetting TX99\n");
4302 +               ath9k_tx99_deinit(sc);
4303 +       }
4304 +
4305 +       if (!start) {
4306 +               ath9k_tx99_deinit(sc);
4307 +               return count;
4308 +       }
4309 +
4310 +       r = ath9k_tx99_init(sc);
4311 +       if (r)
4312 +               return r;
4313 +
4314 +       return count;
4315 +}
4316 +
4317 +static const struct file_operations fops_tx99 = {
4318 +       .read = read_file_tx99,
4319 +       .write = write_file_tx99,
4320 +       .open = simple_open,
4321 +       .owner = THIS_MODULE,
4322 +       .llseek = default_llseek,
4323 +};
4324 +
4325 +static ssize_t read_file_tx99_power(struct file *file,
4326 +                                   char __user *user_buf,
4327 +                                   size_t count, loff_t *ppos)
4328 +{
4329 +       struct ath_softc *sc = file->private_data;
4330 +       char buf[32];
4331 +       unsigned int len;
4332 +
4333 +       len = sprintf(buf, "%d (%d dBm)\n",
4334 +                     sc->tx99_power,
4335 +                     sc->tx99_power / 2);
4336 +
4337 +       return simple_read_from_buffer(user_buf, count, ppos, buf, len);
4338 +}
4339 +
4340 +static ssize_t write_file_tx99_power(struct file *file,
4341 +                                    const char __user *user_buf,
4342 +                                    size_t count, loff_t *ppos)
4343 +{
4344 +       struct ath_softc *sc = file->private_data;
4345 +       int r;
4346 +       u8 tx_power;
4347 +
4348 +       r = kstrtou8_from_user(user_buf, count, 0, &tx_power);
4349 +       if (r)
4350 +               return r;
4351 +
4352 +       if (tx_power > MAX_RATE_POWER)
4353 +               return -EINVAL;
4354 +
4355 +       sc->tx99_power = tx_power;
4356 +
4357 +       ath9k_ps_wakeup(sc);
4358 +       ath9k_hw_tx99_set_txpower(sc->sc_ah, sc->tx99_power);
4359 +       ath9k_ps_restore(sc);
4360 +
4361 +       return count;
4362 +}
4363 +
4364 +static const struct file_operations fops_tx99_power = {
4365 +       .read = read_file_tx99_power,
4366 +       .write = write_file_tx99_power,
4367 +       .open = simple_open,
4368 +       .owner = THIS_MODULE,
4369 +       .llseek = default_llseek,
4370 +};
4371 +
4372 +void ath9k_tx99_init_debug(struct ath_softc *sc)
4373 +{
4374 +       if (!AR_SREV_9300_20_OR_LATER(sc->sc_ah))
4375 +               return;
4376 +
4377 +       debugfs_create_file("tx99", S_IRUSR | S_IWUSR,
4378 +                           sc->debug.debugfs_phy, sc,
4379 +                           &fops_tx99);
4380 +       debugfs_create_file("tx99_power", S_IRUSR | S_IWUSR,
4381 +                           sc->debug.debugfs_phy, sc,
4382 +                           &fops_tx99_power);
4383 +}
4384 --- a/drivers/net/wireless/ath/ath9k/dfs_debug.c
4385 +++ b/drivers/net/wireless/ath/ath9k/dfs_debug.c
4386 @@ -44,14 +44,20 @@ static ssize_t read_file_dfs(struct file
4387         if (buf == NULL)
4388                 return -ENOMEM;
4389  
4390 -       if (sc->dfs_detector)
4391 -               dfs_pool_stats = sc->dfs_detector->get_stats(sc->dfs_detector);
4392 -
4393         len += scnprintf(buf + len, size - len, "DFS support for "
4394                          "macVersion = 0x%x, macRev = 0x%x: %s\n",
4395                          hw_ver->macVersion, hw_ver->macRev,
4396                          (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_DFS) ?
4397                                         "enabled" : "disabled");
4398 +
4399 +       if (!sc->dfs_detector) {
4400 +               len += scnprintf(buf + len, size - len,
4401 +                               "DFS detector not enabled\n");
4402 +               goto exit;
4403 +       }
4404 +
4405 +       dfs_pool_stats = sc->dfs_detector->get_stats(sc->dfs_detector);
4406 +
4407         len += scnprintf(buf + len, size - len, "Pulse detector statistics:\n");
4408         ATH9K_DFS_STAT("pulse events reported   ", pulses_total);
4409         ATH9K_DFS_STAT("invalid pulse events    ", pulses_no_dfs);
4410 @@ -76,6 +82,7 @@ static ssize_t read_file_dfs(struct file
4411         ATH9K_DFS_POOL_STAT("Seqs. alloc error       ", pseq_alloc_error);
4412         ATH9K_DFS_POOL_STAT("Seqs. in use            ", pseq_used);
4413  
4414 +exit:
4415         if (len > size)
4416                 len = size;
4417  
4418 --- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
4419 +++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
4420 @@ -701,6 +701,54 @@ static int ar9550_hw_get_modes_txgain_in
4421         return ret;
4422  }
4423  
4424 +static void ar9003_doubler_fix(struct ath_hw *ah)
4425 +{
4426 +       if (AR_SREV_9300(ah) || AR_SREV_9580(ah) || AR_SREV_9550(ah)) {
4427 +               REG_RMW(ah, AR_PHY_65NM_CH0_RXTX2,
4428 +                       1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
4429 +                       1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S, 0);
4430 +               REG_RMW(ah, AR_PHY_65NM_CH1_RXTX2,
4431 +                       1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
4432 +                       1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S, 0);
4433 +               REG_RMW(ah, AR_PHY_65NM_CH2_RXTX2,
4434 +                       1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
4435 +                       1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S, 0);
4436 +
4437 +               udelay(200);
4438 +
4439 +               REG_CLR_BIT(ah, AR_PHY_65NM_CH0_RXTX2,
4440 +                           AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK);
4441 +               REG_CLR_BIT(ah, AR_PHY_65NM_CH1_RXTX2,
4442 +                           AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK);
4443 +               REG_CLR_BIT(ah, AR_PHY_65NM_CH2_RXTX2,
4444 +                           AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK);
4445 +
4446 +               udelay(1);
4447 +
4448 +               REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_RXTX2,
4449 +                             AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK, 1);
4450 +               REG_RMW_FIELD(ah, AR_PHY_65NM_CH1_RXTX2,
4451 +                             AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK, 1);
4452 +               REG_RMW_FIELD(ah, AR_PHY_65NM_CH2_RXTX2,
4453 +                             AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK, 1);
4454 +
4455 +               udelay(200);
4456 +
4457 +               REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_SYNTH12,
4458 +                             AR_PHY_65NM_CH0_SYNTH12_VREFMUL3, 0xf);
4459 +
4460 +               REG_RMW(ah, AR_PHY_65NM_CH0_RXTX2, 0,
4461 +                       1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
4462 +                       1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S);
4463 +               REG_RMW(ah, AR_PHY_65NM_CH1_RXTX2, 0,
4464 +                       1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
4465 +                       1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S);
4466 +               REG_RMW(ah, AR_PHY_65NM_CH2_RXTX2, 0,
4467 +                       1 << AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S |
4468 +                       1 << AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S);
4469 +       }
4470 +}
4471 +
4472  static int ar9003_hw_process_ini(struct ath_hw *ah,
4473                                  struct ath9k_channel *chan)
4474  {
4475 @@ -726,6 +774,8 @@ static int ar9003_hw_process_ini(struct 
4476                                            modesIndex);
4477         }
4478  
4479 +       ar9003_doubler_fix(ah);
4480 +
4481         /*
4482          * RXGAIN initvals.
4483          */
4484 --- a/drivers/net/wireless/ath/ath9k/ar9003_phy.h
4485 +++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.h
4486 @@ -656,13 +656,24 @@
4487  #define AR_PHY_SYNTH4_LONG_SHIFT_SELECT   ((AR_SREV_9462(ah) || AR_SREV_9565(ah)) ? 0x00000001 : 0x00000002)
4488  #define AR_PHY_SYNTH4_LONG_SHIFT_SELECT_S ((AR_SREV_9462(ah) || AR_SREV_9565(ah)) ? 0 : 1)
4489  #define AR_PHY_65NM_CH0_SYNTH7      0x16098
4490 +#define AR_PHY_65NM_CH0_SYNTH12     0x160ac
4491  #define AR_PHY_65NM_CH0_BIAS1       0x160c0
4492  #define AR_PHY_65NM_CH0_BIAS2       0x160c4
4493  #define AR_PHY_65NM_CH0_BIAS4       0x160cc
4494 +#define AR_PHY_65NM_CH0_RXTX2       0x16104
4495 +#define AR_PHY_65NM_CH1_RXTX2       0x16504
4496 +#define AR_PHY_65NM_CH2_RXTX2       0x16904
4497  #define AR_PHY_65NM_CH0_RXTX4       0x1610c
4498  #define AR_PHY_65NM_CH1_RXTX4       0x1650c
4499  #define AR_PHY_65NM_CH2_RXTX4       0x1690c
4500  
4501 +#define AR_PHY_65NM_CH0_SYNTH12_VREFMUL3           0x00780000
4502 +#define AR_PHY_65NM_CH0_SYNTH12_VREFMUL3_S         19
4503 +#define AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK         0x00000004
4504 +#define AR_PHY_65NM_CH0_RXTX2_SYNTHON_MASK_S       2
4505 +#define AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK        0x00000008
4506 +#define AR_PHY_65NM_CH0_RXTX2_SYNTHOVR_MASK_S      3
4507 +
4508  #define AR_CH0_TOP     (AR_SREV_9300(ah) ? 0x16288 : \
4509                          (((AR_SREV_9462(ah) || AR_SREV_9565(ah)) ? 0x1628c : 0x16280)))
4510  #define AR_CH0_TOP_XPABIASLVL (AR_SREV_9550(ah) ? 0x3c0 : 0x300)