a790183f74e3acfbbacef11d07e9502c9ebc5381
[openwrt.git] / package / kernel / mac80211 / patches / 300-pending_work.patch
1 commit 82ed9e3ccc02797df2ffe4b78127c4cd5f799a41
2 Author: Felix Fietkau <nbd@openwrt.org>
3 Date:   Tue Feb 11 15:54:13 2014 +0100
4
5     mac80211: send control port protocol frames to the VO queue
6     
7     Improves reliability of wifi connections with WPA, since authentication
8     frames are prioritized over normal traffic and also typically exempt
9     from aggregation.
10     
11     Cc: stable@vger.kernel.org
12     Signed-off-by: Felix Fietkau <nbd@openwrt.org>
13
14 commit d4426800f71e972feaa33e04c5801fc730627bdd
15 Author: Stanislaw Gruszka <stf_xl@wp.pl>
16 Date:   Mon Feb 10 22:38:28 2014 +0100
17
18     rtl8187: fix regression on MIPS without coherent DMA
19     
20     This patch fixes regression caused by commit a16dad77634 "MIPS: Fix
21     potencial corruption". That commit fixes one corruption scenario in
22     cost of adding another one, which actually start to cause crashes
23     on Yeeloong laptop when rtl8187 driver is used.
24     
25     For correct DMA read operation on machines without DMA coherence, kernel
26     have to invalidate cache, such it will refill later with new data that
27     device wrote to memory, when that data is needed to process. We can only
28     invalidate full cache line. Hence when cache line includes both dma
29     buffer and some other data (written in cache, but not yet in main
30     memory), the other data can not hit memory due to invalidation. That
31     happen on rtl8187 where struct rtl8187_priv fields are located just
32     before and after small buffers that are passed to USB layer and DMA
33     is performed on them.
34     
35     To fix the problem we align buffers and reserve space after them to make
36     them match cache line.
37     
38     This patch does not resolve all possible MIPS problems entirely, for
39     that we have to assure that we always map cache aligned buffers for DMA,
40     what can be complex or even not possible. But patch fixes visible and
41     reproducible regression and seems other possible corruptions do not
42     happen in practice, since Yeeloong laptop works stable without rtl8187
43     driver.
44     
45     Bug report:
46     https://bugzilla.kernel.org/show_bug.cgi?id=54391
47     
48     Reported-by: Petr Pisar <petr.pisar@atlas.cz>
49     Bisected-by: Tom Li <biergaizi2009@gmail.com>
50     Reported-and-tested-by: Tom Li <biergaizi2009@gmail.com>
51     Cc: stable@vger.kernel.org
52     Signed-off-by: Stanislaw Gruszka <stf_xl@wp.pl>
53
54 commit e2f141d67ad1e7fe10aaab61811e8a409dfb2442
55 Author: Sujith Manoharan <c_manoha@qca.qualcomm.com>
56 Date:   Fri Feb 7 10:29:55 2014 +0530
57
58     ath9k: Calculate IQ-CAL median
59     
60     This patch adds a routine to calculate the median IQ correction
61     values for AR955x, which is used for outlier detection.
62     The normal method which is used for all other chips is
63     bypassed for AR955x.
64     
65     Signed-off-by: Sujith Manoharan <c_manoha@qca.qualcomm.com>
66
67 commit c52a6fce0820c8d0687443ab86058ae03b478c8f
68 Author: Sujith Manoharan <c_manoha@qca.qualcomm.com>
69 Date:   Fri Feb 7 10:29:54 2014 +0530
70
71     ath9k: Expand the IQ coefficient array
72     
73     This will be used for storing data for mutiple
74     IQ calibration runs, for AR955x.
75     
76     Signed-off-by: Sujith Manoharan <c_manoha@qca.qualcomm.com>
77
78 commit 034969ff5c2b6431d10e07c1938f0b916da85cc3
79 Author: Sujith Manoharan <c_manoha@qca.qualcomm.com>
80 Date:   Fri Feb 7 10:29:53 2014 +0530
81
82     ath9k: Modify IQ calibration for AR955x
83     
84     IQ calibration post-processing for AR955x is different
85     from other chips - instead of just doing it as part
86     of AGC calibration once, it is triggered 3 times and
87     a median is determined. This patch adds initial support
88     for changing the calibration behavior for AR955x.
89     
90     Also, to simplify things, a helper routine to issue/poll
91     AGC calibration is used.
92     
93     For non-AR955x chips, the iqcal_idx (which will be used
94     in subsequent patches) is set to zero.
95     
96     Signed-off-by: Sujith Manoharan <c_manoha@qca.qualcomm.com>
97
98 commit 9b1ed6454e6f3511f24266be99b4e403f243f6a8
99 Author: Sujith Manoharan <c_manoha@qca.qualcomm.com>
100 Date:   Fri Feb 7 10:29:52 2014 +0530
101
102     ath9k: Fix magnitude/phase calculation
103     
104     Incorrect values are programmed in the registers
105     containing the IQ correction coefficients by the IQ-CAL
106     post-processing code. Fix this.
107     
108     Signed-off-by: Sujith Manoharan <c_manoha@qca.qualcomm.com>
109
110 commit 36f93484f96f79171dcecb67c5ef0c3de22531a6
111 Author: Sujith Manoharan <c_manoha@qca.qualcomm.com>
112 Date:   Fri Feb 7 10:29:51 2014 +0530
113
114     ath9k: Rename ar9003_hw_tx_iqcal_load_avg_2_passes
115     
116     Use ar9003_hw_tx_iq_cal_outlier_detection instead.
117     
118     Signed-off-by: Sujith Manoharan <c_manoha@qca.qualcomm.com>
119
120 commit 3af09a7f5d21dd5fd15b973ce6a91a575da30417
121 Author: Sujith Manoharan <c_manoha@qca.qualcomm.com>
122 Date:   Fri Feb 7 10:29:50 2014 +0530
123
124     ath9k: Check explicitly for IQ calibration
125     
126     In chips like AR955x, the initvals contain the information
127     whether IQ calibration is to be done in the HW when an
128     AGC calibration is triggered. Check if IQ-CAL is enabled
129     in the initvals before flagging 'txiqcal_done' as true.
130     
131     Signed-off-by: Sujith Manoharan <c_manoha@qca.qualcomm.com>
132
133 commit cb4969634b93c4643a32cc3fbd27d2b288b25771
134 Author: Sujith Manoharan <c_manoha@qca.qualcomm.com>
135 Date:   Fri Feb 7 10:29:49 2014 +0530
136
137     ath9k: Fix IQ cal post processing for SoC
138     
139     Calibration data is not reused for SoC chips, so
140     call ar9003_hw_tx_iq_cal_post_proc() with the correct
141     argument. The 'is_reusable' flag is currently used
142     only for PC-OEM chips, but it makes things clearer to
143     specify it explicity.
144     
145     Signed-off-by: Sujith Manoharan <c_manoha@qca.qualcomm.com>
146
147 commit e138e0ef9560c46ce93dbb22a728a57888e94d1c
148 Author: Sujith Manoharan <c_manoha@qca.qualcomm.com>
149 Date:   Mon Feb 3 13:31:37 2014 +0530
150
151     ath9k: Fix TX power calculation
152     
153     The commit, "ath9k_hw: Fix incorrect Tx control power in AR9003 template"
154     fixed the incorrect values in the eeprom templates, but if
155     boards have already been calibrated with incorrect values,
156     they would still be using the wrong TX power. Fix this by assigning
157     a default value in such cases.
158     
159     Cc: Rajkumar Manoharan <rmanohar@qti.qualcomm.com>
160     Signed-off-by: Sujith Manoharan <c_manoha@qca.qualcomm.com>
161
162 commit b9f268b5b01331c3c82179abca551429450e9417
163 Author: Michal Kazior <michal.kazior@tieto.com>
164 Date:   Wed Jan 29 14:22:27 2014 +0100
165
166     cfg80211: consider existing DFS interfaces
167     
168     It was possible to break interface combinations in
169     the following way:
170     
171      combo 1: iftype = AP, num_ifaces = 2, num_chans = 2,
172      combo 2: iftype = AP, num_ifaces = 1, num_chans = 1, radar = HT20
173     
174     With the above interface combinations it was
175     possible to:
176     
177      step 1. start AP on DFS channel by matching combo 2
178      step 2. start AP on non-DFS channel by matching combo 1
179     
180     This was possible beacuse (step 2) did not consider
181     if other interfaces require radar detection.
182     
183     The patch changes how cfg80211 tracks channels -
184     instead of channel itself now a complete chandef
185     is stored.
186     
187     Signed-off-by: Michal Kazior <michal.kazior@tieto.com>
188     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
189
190 commit bc9c62f5f511cc395c62dbf4cdd437f23db53b28
191 Author: Antonio Quartulli <antonio@open-mesh.com>
192 Date:   Wed Jan 29 17:53:43 2014 +0100
193
194     cfg80211: fix channel configuration in IBSS join
195     
196     When receiving an IBSS_JOINED event select the BSS object
197     based on the {bssid, channel} couple rather than the bssid
198     only.
199     With the current approach if another cell having the same
200     BSSID (but using a different channel) exists then cfg80211
201     picks up the wrong BSS object.
202     The result is a mismatching channel configuration between
203     cfg80211 and the driver, that can lead to any sort of
204     problem.
205     
206     The issue can be triggered by having an IBSS sitting on
207     given channel and then asking the driver to create a new
208     cell using the same BSSID but with a different frequency.
209     By passing the channel to cfg80211_get_bss() we can solve
210     this ambiguity and retrieve/create the correct BSS object.
211     All the users of cfg80211_ibss_joined() have been changed
212     accordingly.
213     
214     Moreover WARN when cfg80211_ibss_joined() gets a NULL
215     channel as argument and remove a bogus call of the same
216     function in ath6kl (it does not make sense to call
217     cfg80211_ibss_joined() with a zero BSSID on ibss-leave).
218     
219     Cc: Kalle Valo <kvalo@qca.qualcomm.com>
220     Cc: Arend van Spriel <arend@broadcom.com>
221     Cc: Bing Zhao <bzhao@marvell.com>
222     Cc: Jussi Kivilinna <jussi.kivilinna@iki.fi>
223     Cc: libertas-dev@lists.infradead.org
224     Acked-by: Kalle Valo <kvalo@qca.qualcomm.com>
225     Signed-off-by: Antonio Quartulli <antonio@open-mesh.com>
226     [minor code cleanup in ath6kl]
227     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
228
229 commit 7e0c41cb41f215aba2c39b1c237bb4d42ec49a85
230 Author: Johannes Berg <johannes.berg@intel.com>
231 Date:   Fri Jan 24 14:41:44 2014 +0100
232
233     mac80211: fix bufferable MMPDU RX handling
234     
235     Action, disassoc and deauth frames are bufferable, and as such don't
236     have the PM bit in the frame control field reserved which means we
237     need to react to the bit when receiving in such a frame.
238     
239     Fix this by introducing a new helper ieee80211_is_bufferable_mmpdu()
240     and using it for the RX path that currently ignores the PM bit in
241     any non-data frames for doze->wake transitions, but listens to it in
242     all frames for wake->doze transitions, both of which are wrong.
243     
244     Also use the new helper in the TX path to clean up the code.
245     
246     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
247
248 commit fc0df6d2343636e3f48a069330d5b972e3d8659d
249 Author: Janusz Dziedzic <janusz.dziedzic@tieto.com>
250 Date:   Fri Jan 24 14:29:21 2014 +0100
251
252     cfg80211: set preset_chandef after channel switch
253     
254     Set preset_chandef in channel switch notification.
255     In other case we will have old preset_chandef.
256     
257     Signed-off-by: Janusz Dziedzic <janusz.dziedzic@tieto.com>
258     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
259
260 commit cdec895e2344987ff171cece96e25d7407a3ebf6
261 Author: Simon Wunderlich <simon@open-mesh.com>
262 Date:   Fri Jan 24 23:48:29 2014 +0100
263
264     mac80211: send ibss probe responses with noack flag
265     
266     Responding to probe requests for scanning clients will often create
267     excessive retries, as it happens quite often that the scanning client
268     already left the channel. Therefore do it like hostapd and send probe
269     responses for wildcard SSID only once by using the noack flag.
270     
271     Signed-off-by: Simon Wunderlich <simon@open-mesh.com>
272     [fix typo & 'wildcard SSID' in commit log]
273     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
274
275 commit 0b865d1e6b9c05052adae9315df7cb195dc60c3b
276 Author: Luciano Coelho <luciano.coelho@intel.com>
277 Date:   Tue Jan 28 17:09:08 2014 +0200
278
279     mac80211: ibss: remove unnecessary call to release channel
280     
281     The ieee80211_vif_use_channel() function calls
282     ieee80211_vif_release_channel(), so there's no need to call it
283     explicitly in __ieee80211_sta_join_ibss().
284     
285     Signed-off-by: Luciano Coelho <luciano.coelho@intel.com>
286     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
287
288 commit e1b6c17e971f0a51ff86c2dac2584c63cd999cd7
289 Author: Michal Kazior <michal.kazior@tieto.com>
290 Date:   Wed Jan 29 07:56:21 2014 +0100
291
292     mac80211: add missing CSA locking
293     
294     The patch adds a missing sdata lock and adds a few
295     lockdeps for easier maintenance.
296     
297     Signed-off-by: Michal Kazior <michal.kazior@tieto.com>
298     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
299
300 commit ad17ba7d14d225b109b73c177cd446afb8050598
301 Author: Michal Kazior <michal.kazior@tieto.com>
302 Date:   Wed Jan 29 07:56:20 2014 +0100
303
304     mac80211: fix sdata->radar_required locking
305     
306     radar_required setting wasn't protected by
307     local->mtx in some places. This should prevent
308     from scanning/radar detection/roc colliding.
309     
310     Signed-off-by: Michal Kazior <michal.kazior@tieto.com>
311     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
312
313 commit 5fcd5f1808813a3d9e502fd756e01bee8a79c85d
314 Author: Michal Kazior <michal.kazior@tieto.com>
315 Date:   Wed Jan 29 07:56:19 2014 +0100
316
317     mac80211: move csa_active setting in STA CSA
318     
319     The sdata->vif.csa_active could be left set after,
320     e.g. channel context constraints check fail in STA
321     mode leaving the interface in a strange state for
322     a brief period of time until it is disconnected.
323     This was harmless but ugly.
324     
325     Signed-off-by: Michal Kazior <michal.kazior@tieto.com>
326     Reviewed-by: Luciano Coelho <luciano.coelho@intel.com>
327     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
328
329 commit e486da4b7eed71821c6b4c1bb9ac62ffd3ab13e9
330 Author: Michal Kazior <michal.kazior@tieto.com>
331 Date:   Wed Jan 29 07:56:18 2014 +0100
332
333     mac80211: fix possible memory leak on AP CSA failure
334     
335     If CSA for AP interface failed and the interface
336     was not stopped afterwards another CSA request
337     would leak sdata->u.ap.next_beacon.
338     
339     Signed-off-by: Michal Kazior <michal.kazior@tieto.com>
340     Reviewed-by: Luciano Coelho <luciano.coelho@intel.com>
341     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
342
343 commit 3a77ba08940682bf3d52cf14f980337324af9d4a
344 Author: Johannes Berg <johannes.berg@intel.com>
345 Date:   Sat Feb 1 00:33:29 2014 +0100
346
347     mac80211: fix fragmentation code, particularly for encryption
348     
349     The "new" fragmentation code (since my rewrite almost 5 years ago)
350     erroneously sets skb->len rather than using skb_trim() to adjust
351     the length of the first fragment after copying out all the others.
352     This leaves the skb tail pointer pointing to after where the data
353     originally ended, and thus causes the encryption MIC to be written
354     at that point, rather than where it belongs: immediately after the
355     data.
356     
357     The impact of this is that if software encryption is done, then
358      a) encryption doesn't work for the first fragment, the connection
359         becomes unusable as the first fragment will never be properly
360         verified at the receiver, the MIC is practically guaranteed to
361         be wrong
362      b) we leak up to 8 bytes of plaintext (!) of the packet out into
363         the air
364     
365     This is only mitigated by the fact that many devices are capable
366     of doing encryption in hardware, in which case this can't happen
367     as the tail pointer is irrelevant in that case. Additionally,
368     fragmentation is not used very frequently and would normally have
369     to be configured manually.
370     
371     Fix this by using skb_trim() properly.
372     
373     Cc: stable@vger.kernel.org
374     Fixes: 2de8e0d999b8 ("mac80211: rewrite fragmentation")
375     Reported-by: Jouni Malinen <j@w1.fi>
376     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
377
378 commit de5f242e0c10e841017e37eb8c38974a642dbca8
379 Author: Sujith Manoharan <c_manoha@qca.qualcomm.com>
380 Date:   Tue Jan 28 06:21:59 2014 +0530
381
382     ath9k: Fix build error on ARM
383     
384     Use mdelay instead of udelay to fix this error:
385     
386     ERROR: "__bad_udelay" [drivers/net/wireless/ath/ath9k/ath9k_hw.ko] undefined!
387     make[1]: *** [__modpost] Error 1
388     make: *** [modules] Error 2
389     
390     Reported-by: Josh Boyer <jwboyer@fedoraproject.org>
391     Signed-off-by: Sujith Manoharan <c_manoha@qca.qualcomm.com>
392
393 commit 8e3ea7a51dfc61810fcefd947f6edcf61125252a
394 Author: Geert Uytterhoeven <geert@linux-m68k.org>
395 Date:   Sun Jan 26 11:53:21 2014 +0100
396
397     ath9k: Fix uninitialized variable in ath9k_has_tx_pending()
398     
399     drivers/net/wireless/ath/ath9k/main.c: In function â€˜ath9k_has_tx_pending’:
400     drivers/net/wireless/ath/ath9k/main.c:1869: warning: â€˜npend’ may be used uninitialized in this function
401     
402     Introduced by commit 10e2318103f5941aa70c318afe34bc41f1b98529 ("ath9k:
403     optimize ath9k_flush").
404     
405     Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
406
407 commit a4a634a6937ebdd827fa58e8fcdb8ca49a3769f6
408 Author: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
409 Date:   Mon Jan 27 11:07:42 2014 +0200
410
411     mac80211: release the channel in error path in start_ap
412     
413     When the driver cannot start the AP or when the assignement
414     of the beacon goes wrong, we need to unassign the vif.
415     
416     Cc: stable@vger.kernel.org
417     Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
418     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
419
420 commit dfb6889a75c601aedb7450b7e606668e77da6679
421 Author: Johannes Berg <johannes.berg@intel.com>
422 Date:   Wed Jan 22 11:14:19 2014 +0200
423
424     cfg80211: send scan results from work queue
425     
426     Due to the previous commit, when a scan finishes, it is in theory
427     possible to hit the following sequence:
428      1. interface starts being removed
429      2. scan is cancelled by driver and cfg80211 is notified
430      3. scan done work is scheduled
431      4. interface is removed completely, rdev->scan_req is freed,
432         event sent to userspace but scan done work remains pending
433      5. new scan is requested on another virtual interface
434      6. scan done work runs, freeing the still-running scan
435     
436     To fix this situation, hang on to the scan done message and block
437     new scans while that is the case, and only send the message from
438     the work function, regardless of whether the scan_req is already
439     freed from interface removal. This makes step 5 above impossible
440     and changes step 6 to be
441      5. scan done work runs, sending the scan done message
442     
443     As this can't work for wext, so we send the message immediately,
444     but this shouldn't be an issue since we still return -EBUSY.
445     
446     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
447
448 commit 45b7ab41fc08627d9a8428cb413d5d84662a9707
449 Author: Johannes Berg <johannes.berg@intel.com>
450 Date:   Wed Jan 22 11:14:18 2014 +0200
451
452     cfg80211: fix scan done race
453     
454     When an interface/wdev is removed, any ongoing scan should be
455     cancelled by the driver. This will make it call cfg80211, which
456     only queues a work struct. If interface/wdev removal is quick
457     enough, this can leave the scan request pending and processed
458     only after the interface is gone, causing a use-after-free.
459     
460     Fix this by making sure the scan request is not pending after
461     the interface is destroyed. We can't flush or cancel the work
462     item due to locking concerns, but when it'll run it shouldn't
463     find anything to do. This leaves a potential issue, if a new
464     scan gets requested before the work runs, it prematurely stops
465     the running scan, potentially causing another crash. I'll fix
466     that in the next patch.
467     
468     This was particularly observed with P2P_DEVICE wdevs, likely
469     because freeing them is quicker than freeing netdevs.
470     
471     Reported-by: Andrei Otcheretianski <andrei.otcheretianski@intel.com>
472     Fixes: 4a58e7c38443 ("cfg80211: don't "leak" uncompleted scans")
473     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
474
475 commit ae04fa489ab31b5a10d3cc8399f52761175d4321
476 Author: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
477 Date:   Thu Jan 23 14:28:16 2014 +0200
478
479     mac80211: avoid deadlock revealed by lockdep
480     
481     sdata->u.ap.request_smps_work can’t be flushed synchronously
482     under wdev_lock(wdev) since ieee80211_request_smps_ap_work
483     itself locks the same lock.
484     While at it, reset the driver_smps_mode when the ap is
485     stopped to its default: OFF.
486     
487     This solves:
488     
489     ======================================================
490     [ INFO: possible circular locking dependency detected ]
491     3.12.0-ipeer+ #2 Tainted: G           O
492     -------------------------------------------------------
493     rmmod/2867 is trying to acquire lock:
494       ((&sdata->u.ap.request_smps_work)){+.+...}, at: [<c105b8d0>] flush_work+0x0/0x90
495     
496     but task is already holding lock:
497       (&wdev->mtx){+.+.+.}, at: [<f9b32626>] cfg80211_stop_ap+0x26/0x230 [cfg80211]
498     
499     which lock already depends on the new lock.
500     
501     the existing dependency chain (in reverse order) is:
502     
503     -> #1 (&wdev->mtx){+.+.+.}:
504             [<c10aefa9>] lock_acquire+0x79/0xe0
505             [<c1607a1a>] mutex_lock_nested+0x4a/0x360
506             [<fb06288b>] ieee80211_request_smps_ap_work+0x2b/0x50 [mac80211]
507             [<c105cdd8>] process_one_work+0x198/0x450
508             [<c105d469>] worker_thread+0xf9/0x320
509             [<c10669ff>] kthread+0x9f/0xb0
510             [<c1613397>] ret_from_kernel_thread+0x1b/0x28
511     
512     -> #0 ((&sdata->u.ap.request_smps_work)){+.+...}:
513             [<c10ae9df>] __lock_acquire+0x183f/0x1910
514             [<c10aefa9>] lock_acquire+0x79/0xe0
515             [<c105b917>] flush_work+0x47/0x90
516             [<c105d867>] __cancel_work_timer+0x67/0xe0
517             [<c105d90f>] cancel_work_sync+0xf/0x20
518             [<fb0765cc>] ieee80211_stop_ap+0x8c/0x340 [mac80211]
519             [<f9b3268c>] cfg80211_stop_ap+0x8c/0x230 [cfg80211]
520             [<f9b0d8f9>] cfg80211_leave+0x79/0x100 [cfg80211]
521             [<f9b0da72>] cfg80211_netdev_notifier_call+0xf2/0x4f0 [cfg80211]
522             [<c160f2c9>] notifier_call_chain+0x59/0x130
523             [<c106c6de>] __raw_notifier_call_chain+0x1e/0x30
524             [<c106c70f>] raw_notifier_call_chain+0x1f/0x30
525             [<c14f8213>] call_netdevice_notifiers_info+0x33/0x70
526             [<c14f8263>] call_netdevice_notifiers+0x13/0x20
527             [<c14f82a4>] __dev_close_many+0x34/0xb0
528             [<c14f83fe>] dev_close_many+0x6e/0xc0
529             [<c14f9c77>] rollback_registered_many+0xa7/0x1f0
530             [<c14f9dd4>] unregister_netdevice_many+0x14/0x60
531             [<fb06f4d9>] ieee80211_remove_interfaces+0xe9/0x170 [mac80211]
532             [<fb055116>] ieee80211_unregister_hw+0x56/0x110 [mac80211]
533             [<fa3e9396>] iwl_op_mode_mvm_stop+0x26/0xe0 [iwlmvm]
534             [<f9b9d8ca>] _iwl_op_mode_stop+0x3a/0x70 [iwlwifi]
535             [<f9b9d96f>] iwl_opmode_deregister+0x6f/0x90 [iwlwifi]
536             [<fa405179>] __exit_compat+0xd/0x19 [iwlmvm]
537             [<c10b8bf9>] SyS_delete_module+0x179/0x2b0
538             [<c1613421>] sysenter_do_call+0x12/0x32
539     
540     Fixes: 687da132234f ("mac80211: implement SMPS for AP")
541     Cc: <stable@vger.kernel.org> [3.13]
542     Reported-by: Ilan Peer <ilan.peer@intel.com>
543     Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
544     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
545
546 commit 178b205e96217164fd7c30113464250d0b6f5eca
547 Author: Johannes Berg <johannes.berg@intel.com>
548 Date:   Thu Jan 23 16:32:29 2014 +0100
549
550     cfg80211: re-enable 5/10 MHz support
551     
552     Unfortunately I forgot this during the merge window, but the
553     patch seems small enough to go in as a fix. The userspace API
554     bug that was the reason for disabling it has long been fixed.
555     
556     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
557
558 commit 110a1c79acda14edc83b7c8dc5af9c7ddd23eb61
559 Author: Pontus Fuchs <pontus.fuchs@gmail.com>
560 Date:   Thu Jan 16 15:00:40 2014 +0100
561
562     nl80211: Reset split_start when netlink skb is exhausted
563     
564     When the netlink skb is exhausted split_start is left set. In the
565     subsequent retry, with a larger buffer, the dump is continued from the
566     failing point instead of from the beginning.
567     
568     This was causing my rt28xx based USB dongle to now show up when
569     running "iw list" with an old iw version without split dump support.
570     
571     Cc: stable@vger.kernel.org
572     Fixes: 3713b4e364ef ("nl80211: allow splitting wiphy information in dumps")
573     Signed-off-by: Pontus Fuchs <pontus.fuchs@gmail.com>
574     [avoid the entire workaround when state->split is set]
575     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
576
577 commit b4c31b45ffc7ef110fa9ecc34d7878fe7c5b9da4
578 Author: Eliad Peller <eliad@wizery.com>
579 Date:   Sun Jan 12 11:06:37 2014 +0200
580
581     mac80211: move roc cookie assignment earlier
582     
583     ieee80211_start_roc_work() might add a new roc
584     to existing roc, and tell cfg80211 it has already
585     started.
586     
587     However, this might happen before the roc cookie
588     was set, resulting in REMAIN_ON_CHANNEL (started)
589     event with null cookie. Consequently, it can make
590     wpa_supplicant go out of sync.
591     
592     Fix it by setting the roc cookie earlier.
593     
594     Cc: stable@vger.kernel.org
595     Signed-off-by: Eliad Peller <eliad@wizery.com>
596     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
597
598 commit cfdc9157bfd7bcf88ab4dae08873a9907eba984c
599 Author: Johannes Berg <johannes.berg@intel.com>
600 Date:   Fri Jan 24 14:06:29 2014 +0100
601
602     nl80211: send event when AP operation is stopped
603     
604     There are a few cases, e.g. suspend, where an AP interface is
605     stopped by the kernel rather than by userspace request, most
606     commonly when suspending. To let userspace know about this,
607     send the NL80211_CMD_STOP_AP command as an event every time
608     an AP interface is stopped. This also happens when userspace
609     did in fact request the AP stop, but that's not a problem.
610     
611     For full-MAC drivers this may need to be extended to also
612     cover cases where the device stopped the AP operation for
613     some reason, this a bit more complicated because then all
614     cfg80211 state also needs to be reset; such API is not part
615     of this patch.
616     
617     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
618
619 commit d5d567eda7704f190379ca852a8f9a4112e3eee3
620 Author: Johannes Berg <johannes.berg@intel.com>
621 Date:   Thu Jan 23 16:20:29 2014 +0100
622
623     mac80211: add length check in ieee80211_is_robust_mgmt_frame()
624     
625     A few places weren't checking that the frame passed to the
626     function actually has enough data even though the function
627     clearly documents it must have a payload byte. Make this
628     safer by changing the function to take an skb and checking
629     the length inside. The old version is preserved for now as
630     the rtl* drivers use it and don't have a correct skb.
631     
632     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
633
634 commit f8f6d212a047fc65c7d3442dfc038f65517236fc
635 Author: Johannes Berg <johannes.berg@intel.com>
636 Date:   Fri Jan 24 10:53:53 2014 +0100
637
638     nl80211: fix scheduled scan RSSI matchset attribute confusion
639     
640     The scheduled scan matchsets were intended to be a list of filters,
641     with the found BSS having to pass at least one of them to be passed
642     to the host. When the RSSI attribute was added, however, this was
643     broken and currently wpa_supplicant adds that attribute in its own
644     matchset; however, it doesn't intend that to mean that anything
645     that passes the RSSI filter should be passed to the host, instead
646     it wants it to mean that everything needs to also have higher RSSI.
647     
648     This is semantically problematic because we have a list of filters
649     like [ SSID1, SSID2, SSID3, RSSI ] with no real indication which
650     one should be OR'ed and which one AND'ed.
651     
652     To fix this, move the RSSI filter attribute into each matchset. As
653     we need to stay backward compatible, treat a matchset with only the
654     RSSI attribute as a "default RSSI filter" for all other matchsets,
655     but only if there are other matchsets (an RSSI-only matchset by
656     itself is still desirable.)
657     
658     To make driver implementation easier, keep a global min_rssi_thold
659     for the entire request as well. The only affected driver is ath6kl.
660     
661     I found this when I looked into the code after Raja Mani submitted
662     a patch fixing the n_match_sets calculation to disregard the RSSI,
663     but that patch didn't address the semantic issue.
664     
665     Reported-by: Raja Mani <rmani@qti.qualcomm.com>
666     Acked-by: Luciano Coelho <luciano.coelho@intel.com>
667     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
668
669 commit de553e8545e65a6dc4e45f43df7e1443d4291922
670 Author: Johannes Berg <johannes.berg@intel.com>
671 Date:   Fri Jan 24 10:17:47 2014 +0100
672
673     nl80211: check nla_parse() return values
674     
675     If there's a policy, then nla_parse() return values must be
676     checked, otherwise the policy is useless and there's nothing
677     that ensures the attributes are actually what we expect them
678     to be.
679     
680     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
681
682 commit 652204a0733e9e1c54661d6f9d36e2e1e3b22bb1
683 Author: Karl Beldan <karl.beldan@rivierawaves.com>
684 Date:   Thu Jan 23 20:06:34 2014 +0100
685
686     mac80211: send {ADD,DEL}BA on AC_VO like other mgmt frames, as per spec
687     
688     ATM, {ADD,DEL}BA and BAR frames are sent on the AC matching the TID of
689     the BA parameters. In the discussion [1] about this patch, Johannes
690     recalled that it fixed some races with the DELBA and indeed this
691     behavior was introduced in [2].
692     While [2] is right for the BARs, the part queueing the {ADD,DEL}BAs on
693     their BA params TID AC violates the spec and is more a workaround for
694     some drivers. Helmut expressed some concerns wrt such drivers, in
695     particular DELBAs in rt2x00.
696     
697     ATM, DELBAs are sent after a driver has called (hence "purposely")
698     ieee80211_start_tx_ba_cb_irqsafe and Johannes and Emmanuel gave some
699     details wrt intentions behind the split of the IEEE80211_AMPDU_TX_STOP_*
700     given to the driver ampdu_action supposed to call this function, which
701     could prove handy to people trying to do the right thing in faulty
702     drivers (if their fw/hw don't get in their way).
703     
704     [1] http://mid.gmane.org/1390391564-18481-1-git-send-email-karl.beldan@gmail.com
705     [2] Commit: cf6bb79ad828 ("mac80211: Use appropriate TID for sending BAR, ADDBA and DELBA frames")
706     
707     Signed-off-by: Karl Beldan <karl.beldan@rivierawaves.com>
708     Cc: Helmut Schaa <helmut.schaa@googlemail.com>
709     Cc: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
710     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
711 --- a/drivers/net/wireless/ath/ath6kl/cfg80211.c
712 +++ b/drivers/net/wireless/ath/ath6kl/cfg80211.c
713 @@ -790,7 +790,7 @@ void ath6kl_cfg80211_connect_event(struc
714         if (nw_type & ADHOC_NETWORK) {
715                 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "ad-hoc %s selected\n",
716                            nw_type & ADHOC_CREATOR ? "creator" : "joiner");
717 -               cfg80211_ibss_joined(vif->ndev, bssid, GFP_KERNEL);
718 +               cfg80211_ibss_joined(vif->ndev, bssid, chan, GFP_KERNEL);
719                 cfg80211_put_bss(ar->wiphy, bss);
720                 return;
721         }
722 @@ -861,13 +861,9 @@ void ath6kl_cfg80211_disconnect_event(st
723         }
724  
725         if (vif->nw_type & ADHOC_NETWORK) {
726 -               if (vif->wdev.iftype != NL80211_IFTYPE_ADHOC) {
727 +               if (vif->wdev.iftype != NL80211_IFTYPE_ADHOC)
728                         ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
729                                    "%s: ath6k not in ibss mode\n", __func__);
730 -                       return;
731 -               }
732 -               memset(bssid, 0, ETH_ALEN);
733 -               cfg80211_ibss_joined(vif->ndev, bssid, GFP_KERNEL);
734                 return;
735         }
736  
737 @@ -3256,6 +3252,15 @@ static int ath6kl_cfg80211_sscan_start(s
738         struct ath6kl_vif *vif = netdev_priv(dev);
739         u16 interval;
740         int ret, rssi_thold;
741 +       int n_match_sets = request->n_match_sets;
742 +
743 +       /*
744 +        * If there's a matchset w/o an SSID, then assume it's just for
745 +        * the RSSI (nothing else is currently supported) and ignore it.
746 +        * The device only supports a global RSSI filter that we set below.
747 +        */
748 +       if (n_match_sets == 1 && !request->match_sets[0].ssid.ssid_len)
749 +               n_match_sets = 0;
750  
751         if (ar->state != ATH6KL_STATE_ON)
752                 return -EIO;
753 @@ -3268,11 +3273,11 @@ static int ath6kl_cfg80211_sscan_start(s
754         ret = ath6kl_set_probed_ssids(ar, vif, request->ssids,
755                                       request->n_ssids,
756                                       request->match_sets,
757 -                                     request->n_match_sets);
758 +                                     n_match_sets);
759         if (ret < 0)
760                 return ret;
761  
762 -       if (!request->n_match_sets) {
763 +       if (!n_match_sets) {
764                 ret = ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
765                                                ALL_BSS_FILTER, 0);
766                 if (ret < 0)
767 @@ -3286,12 +3291,12 @@ static int ath6kl_cfg80211_sscan_start(s
768  
769         if (test_bit(ATH6KL_FW_CAPABILITY_RSSI_SCAN_THOLD,
770                      ar->fw_capabilities)) {
771 -               if (request->rssi_thold <= NL80211_SCAN_RSSI_THOLD_OFF)
772 +               if (request->min_rssi_thold <= NL80211_SCAN_RSSI_THOLD_OFF)
773                         rssi_thold = 0;
774 -               else if (request->rssi_thold < -127)
775 +               else if (request->min_rssi_thold < -127)
776                         rssi_thold = -127;
777                 else
778 -                       rssi_thold = request->rssi_thold;
779 +                       rssi_thold = request->min_rssi_thold;
780  
781                 ret = ath6kl_wmi_set_rssi_filter_cmd(ar->wmi, vif->fw_vif_idx,
782                                                      rssi_thold);
783 --- a/drivers/net/wireless/ath/ath9k/hw.c
784 +++ b/drivers/net/wireless/ath/ath9k/hw.c
785 @@ -1316,7 +1316,7 @@ static bool ath9k_hw_set_reset(struct at
786         if (AR_SREV_9300_20_OR_LATER(ah))
787                 udelay(50);
788         else if (AR_SREV_9100(ah))
789 -               udelay(10000);
790 +               mdelay(10);
791         else
792                 udelay(100);
793  
794 @@ -2051,9 +2051,8 @@ static bool ath9k_hw_set_power_awake(str
795  
796         REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
797                     AR_RTC_FORCE_WAKE_EN);
798 -
799         if (AR_SREV_9100(ah))
800 -               udelay(10000);
801 +               mdelay(10);
802         else
803                 udelay(50);
804  
805 --- a/drivers/net/wireless/ath/ath9k/main.c
806 +++ b/drivers/net/wireless/ath/ath9k/main.c
807 @@ -1866,7 +1866,7 @@ static void ath9k_set_coverage_class(str
808  
809  static bool ath9k_has_tx_pending(struct ath_softc *sc)
810  {
811 -       int i, npend;
812 +       int i, npend = 0;
813  
814         for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
815                 if (!ATH_TXQ_SETUP(sc, i))
816 --- a/drivers/net/wireless/iwlwifi/mvm/scan.c
817 +++ b/drivers/net/wireless/iwlwifi/mvm/scan.c
818 @@ -595,6 +595,9 @@ static void iwl_scan_offload_build_ssid(
819          * config match list.
820          */
821         for (i = 0; i < req->n_match_sets && i < PROBE_OPTION_MAX; i++) {
822 +               /* skip empty SSID matchsets */
823 +               if (!req->match_sets[i].ssid.ssid_len)
824 +                       continue;
825                 scan->direct_scan[i].id = WLAN_EID_SSID;
826                 scan->direct_scan[i].len = req->match_sets[i].ssid.ssid_len;
827                 memcpy(scan->direct_scan[i].ssid, req->match_sets[i].ssid.ssid,
828 --- a/drivers/net/wireless/rtlwifi/rtl8188ee/trx.c
829 +++ b/drivers/net/wireless/rtlwifi/rtl8188ee/trx.c
830 @@ -452,7 +452,7 @@ bool rtl88ee_rx_query_desc(struct ieee80
831                         /* During testing, hdr was NULL */
832                         return false;
833                 }
834 -               if ((ieee80211_is_robust_mgmt_frame(hdr)) &&
835 +               if ((_ieee80211_is_robust_mgmt_frame(hdr)) &&
836                     (ieee80211_has_protected(hdr->frame_control)))
837                         rx_status->flag &= ~RX_FLAG_DECRYPTED;
838                 else
839 --- a/drivers/net/wireless/rtlwifi/rtl8192ce/trx.c
840 +++ b/drivers/net/wireless/rtlwifi/rtl8192ce/trx.c
841 @@ -393,7 +393,7 @@ bool rtl92ce_rx_query_desc(struct ieee80
842                         /* In testing, hdr was NULL here */
843                         return false;
844                 }
845 -               if ((ieee80211_is_robust_mgmt_frame(hdr)) &&
846 +               if ((_ieee80211_is_robust_mgmt_frame(hdr)) &&
847                     (ieee80211_has_protected(hdr->frame_control)))
848                         rx_status->flag &= ~RX_FLAG_DECRYPTED;
849                 else
850 --- a/drivers/net/wireless/rtlwifi/rtl8192se/trx.c
851 +++ b/drivers/net/wireless/rtlwifi/rtl8192se/trx.c
852 @@ -310,7 +310,7 @@ bool rtl92se_rx_query_desc(struct ieee80
853                         /* during testing, hdr was NULL here */
854                         return false;
855                 }
856 -               if ((ieee80211_is_robust_mgmt_frame(hdr)) &&
857 +               if ((_ieee80211_is_robust_mgmt_frame(hdr)) &&
858                         (ieee80211_has_protected(hdr->frame_control)))
859                         rx_status->flag &= ~RX_FLAG_DECRYPTED;
860                 else
861 --- a/drivers/net/wireless/rtlwifi/rtl8723ae/trx.c
862 +++ b/drivers/net/wireless/rtlwifi/rtl8723ae/trx.c
863 @@ -334,7 +334,7 @@ bool rtl8723ae_rx_query_desc(struct ieee
864                         /* during testing, hdr could be NULL here */
865                         return false;
866                 }
867 -               if ((ieee80211_is_robust_mgmt_frame(hdr)) &&
868 +               if ((_ieee80211_is_robust_mgmt_frame(hdr)) &&
869                         (ieee80211_has_protected(hdr->frame_control)))
870                         rx_status->flag &= ~RX_FLAG_DECRYPTED;
871                 else
872 --- a/include/linux/ieee80211.h
873 +++ b/include/linux/ieee80211.h
874 @@ -597,6 +597,20 @@ static inline int ieee80211_is_qos_nullf
875  }
876  
877  /**
878 + * ieee80211_is_bufferable_mmpdu - check if frame is bufferable MMPDU
879 + * @fc: frame control field in little-endian byteorder
880 + */
881 +static inline bool ieee80211_is_bufferable_mmpdu(__le16 fc)
882 +{
883 +       /* IEEE 802.11-2012, definition of "bufferable management frame";
884 +        * note that this ignores the IBSS special case. */
885 +       return ieee80211_is_mgmt(fc) &&
886 +              (ieee80211_is_action(fc) ||
887 +               ieee80211_is_disassoc(fc) ||
888 +               ieee80211_is_deauth(fc));
889 +}
890 +
891 +/**
892   * ieee80211_is_first_frag - check if IEEE80211_SCTL_FRAG is not set
893   * @seq_ctrl: frame sequence control bytes in little-endian byteorder
894   */
895 @@ -2192,10 +2206,10 @@ static inline u8 *ieee80211_get_DA(struc
896  }
897  
898  /**
899 - * ieee80211_is_robust_mgmt_frame - check if frame is a robust management frame
900 + * _ieee80211_is_robust_mgmt_frame - check if frame is a robust management frame
901   * @hdr: the frame (buffer must include at least the first octet of payload)
902   */
903 -static inline bool ieee80211_is_robust_mgmt_frame(struct ieee80211_hdr *hdr)
904 +static inline bool _ieee80211_is_robust_mgmt_frame(struct ieee80211_hdr *hdr)
905  {
906         if (ieee80211_is_disassoc(hdr->frame_control) ||
907             ieee80211_is_deauth(hdr->frame_control))
908 @@ -2224,6 +2238,17 @@ static inline bool ieee80211_is_robust_m
909  }
910  
911  /**
912 + * ieee80211_is_robust_mgmt_frame - check if skb contains a robust mgmt frame
913 + * @skb: the skb containing the frame, length will be checked
914 + */
915 +static inline bool ieee80211_is_robust_mgmt_frame(struct sk_buff *skb)
916 +{
917 +       if (skb->len < 25)
918 +               return false;
919 +       return _ieee80211_is_robust_mgmt_frame((void *)skb->data);
920 +}
921 +
922 +/**
923   * ieee80211_is_public_action - check if frame is a public action frame
924   * @hdr: the frame
925   * @len: length of the frame
926 --- a/include/net/cfg80211.h
927 +++ b/include/net/cfg80211.h
928 @@ -1395,9 +1395,11 @@ struct cfg80211_scan_request {
929   * struct cfg80211_match_set - sets of attributes to match
930   *
931   * @ssid: SSID to be matched
932 + * @rssi_thold: don't report scan results below this threshold (in s32 dBm)
933   */
934  struct cfg80211_match_set {
935         struct cfg80211_ssid ssid;
936 +       s32 rssi_thold;
937  };
938  
939  /**
940 @@ -1420,7 +1422,8 @@ struct cfg80211_match_set {
941   * @dev: the interface
942   * @scan_start: start time of the scheduled scan
943   * @channels: channels to scan
944 - * @rssi_thold: don't report scan results below this threshold (in s32 dBm)
945 + * @min_rssi_thold: for drivers only supporting a single threshold, this
946 + *     contains the minimum over all matchsets
947   */
948  struct cfg80211_sched_scan_request {
949         struct cfg80211_ssid *ssids;
950 @@ -1433,7 +1436,7 @@ struct cfg80211_sched_scan_request {
951         u32 flags;
952         struct cfg80211_match_set *match_sets;
953         int n_match_sets;
954 -       s32 rssi_thold;
955 +       s32 min_rssi_thold;
956  
957         /* internal */
958         struct wiphy *wiphy;
959 @@ -3130,8 +3133,8 @@ struct cfg80211_cached_keys;
960   * @identifier: (private) Identifier used in nl80211 to identify this
961   *     wireless device if it has no netdev
962   * @current_bss: (private) Used by the internal configuration code
963 - * @channel: (private) Used by the internal configuration code to track
964 - *     the user-set AP, monitor and WDS channel
965 + * @chandef: (private) Used by the internal configuration code to track
966 + *     the user-set channel definition.
967   * @preset_chandef: (private) Used by the internal configuration code to
968   *     track the channel to be used for AP later
969   * @bssid: (private) Used by the internal configuration code
970 @@ -3195,9 +3198,7 @@ struct wireless_dev {
971  
972         struct cfg80211_internal_bss *current_bss; /* associated / joined */
973         struct cfg80211_chan_def preset_chandef;
974 -
975 -       /* for AP and mesh channel tracking */
976 -       struct ieee80211_channel *channel;
977 +       struct cfg80211_chan_def chandef;
978  
979         bool ibss_fixed;
980         bool ibss_dfs_possible;
981 @@ -3879,6 +3880,7 @@ void cfg80211_michael_mic_failure(struct
982   *
983   * @dev: network device
984   * @bssid: the BSSID of the IBSS joined
985 + * @channel: the channel of the IBSS joined
986   * @gfp: allocation flags
987   *
988   * This function notifies cfg80211 that the device joined an IBSS or
989 @@ -3888,7 +3890,8 @@ void cfg80211_michael_mic_failure(struct
990   * with the locally generated beacon -- this guarantees that there is
991   * always a scan result for this IBSS. cfg80211 will handle the rest.
992   */
993 -void cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid, gfp_t gfp);
994 +void cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid,
995 +                         struct ieee80211_channel *channel, gfp_t gfp);
996  
997  /**
998   * cfg80211_notify_new_candidate - notify cfg80211 of a new mesh peer candidate
999 --- a/include/uapi/linux/nl80211.h
1000 +++ b/include/uapi/linux/nl80211.h
1001 @@ -2442,9 +2442,15 @@ enum nl80211_reg_rule_attr {
1002   * enum nl80211_sched_scan_match_attr - scheduled scan match attributes
1003   * @__NL80211_SCHED_SCAN_MATCH_ATTR_INVALID: attribute number 0 is reserved
1004   * @NL80211_SCHED_SCAN_MATCH_ATTR_SSID: SSID to be used for matching,
1005 - * only report BSS with matching SSID.
1006 + *     only report BSS with matching SSID.
1007   * @NL80211_SCHED_SCAN_MATCH_ATTR_RSSI: RSSI threshold (in dBm) for reporting a
1008 - *     BSS in scan results. Filtering is turned off if not specified.
1009 + *     BSS in scan results. Filtering is turned off if not specified. Note that
1010 + *     if this attribute is in a match set of its own, then it is treated as
1011 + *     the default value for all matchsets with an SSID, rather than being a
1012 + *     matchset of its own without an RSSI filter. This is due to problems with
1013 + *     how this API was implemented in the past. Also, due to the same problem,
1014 + *     the only way to create a matchset with only an RSSI filter (with this
1015 + *     attribute) is if there's only a single matchset with the RSSI attribute.
1016   * @NL80211_SCHED_SCAN_MATCH_ATTR_MAX: highest scheduled scan filter
1017   *     attribute number currently defined
1018   * @__NL80211_SCHED_SCAN_MATCH_ATTR_AFTER_LAST: internal use
1019 --- a/net/mac80211/agg-tx.c
1020 +++ b/net/mac80211/agg-tx.c
1021 @@ -107,7 +107,7 @@ static void ieee80211_send_addba_request
1022         mgmt->u.action.u.addba_req.start_seq_num =
1023                                         cpu_to_le16(start_seq_num << 4);
1024  
1025 -       ieee80211_tx_skb_tid(sdata, skb, tid);
1026 +       ieee80211_tx_skb(sdata, skb);
1027  }
1028  
1029  void ieee80211_send_bar(struct ieee80211_vif *vif, u8 *ra, u16 tid, u16 ssn)
1030 --- a/net/mac80211/cfg.c
1031 +++ b/net/mac80211/cfg.c
1032 @@ -970,9 +970,9 @@ static int ieee80211_start_ap(struct wip
1033         /* TODO: make hostapd tell us what it wants */
1034         sdata->smps_mode = IEEE80211_SMPS_OFF;
1035         sdata->needed_rx_chains = sdata->local->rx_chains;
1036 -       sdata->radar_required = params->radar_required;
1037  
1038         mutex_lock(&local->mtx);
1039 +       sdata->radar_required = params->radar_required;
1040         err = ieee80211_vif_use_channel(sdata, &params->chandef,
1041                                         IEEE80211_CHANCTX_SHARED);
1042         mutex_unlock(&local->mtx);
1043 @@ -1021,8 +1021,10 @@ static int ieee80211_start_ap(struct wip
1044                                         IEEE80211_P2P_OPPPS_ENABLE_BIT;
1045  
1046         err = ieee80211_assign_beacon(sdata, &params->beacon);
1047 -       if (err < 0)
1048 +       if (err < 0) {
1049 +               ieee80211_vif_release_channel(sdata);
1050                 return err;
1051 +       }
1052         changed |= err;
1053  
1054         err = drv_start_ap(sdata->local, sdata);
1055 @@ -1032,6 +1034,7 @@ static int ieee80211_start_ap(struct wip
1056                 if (old)
1057                         kfree_rcu(old, rcu_head);
1058                 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
1059 +               ieee80211_vif_release_channel(sdata);
1060                 return err;
1061         }
1062  
1063 @@ -1053,6 +1056,7 @@ static int ieee80211_change_beacon(struc
1064         int err;
1065  
1066         sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1067 +       sdata_assert_lock(sdata);
1068  
1069         /* don't allow changing the beacon while CSA is in place - offset
1070          * of channel switch counter may change
1071 @@ -1080,6 +1084,8 @@ static int ieee80211_stop_ap(struct wiph
1072         struct probe_resp *old_probe_resp;
1073         struct cfg80211_chan_def chandef;
1074  
1075 +       sdata_assert_lock(sdata);
1076 +
1077         old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
1078         if (!old_beacon)
1079                 return -ENOENT;
1080 @@ -1090,8 +1096,6 @@ static int ieee80211_stop_ap(struct wiph
1081         kfree(sdata->u.ap.next_beacon);
1082         sdata->u.ap.next_beacon = NULL;
1083  
1084 -       cancel_work_sync(&sdata->u.ap.request_smps_work);
1085 -
1086         /* turn off carrier for this interface and dependent VLANs */
1087         list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1088                 netif_carrier_off(vlan->dev);
1089 @@ -1103,6 +1107,7 @@ static int ieee80211_stop_ap(struct wiph
1090         kfree_rcu(old_beacon, rcu_head);
1091         if (old_probe_resp)
1092                 kfree_rcu(old_probe_resp, rcu_head);
1093 +       sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF;
1094  
1095         __sta_info_flush(sdata, true);
1096         ieee80211_free_keys(sdata, true);
1097 @@ -2638,6 +2643,24 @@ static int ieee80211_start_roc_work(stru
1098         INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
1099         INIT_LIST_HEAD(&roc->dependents);
1100  
1101 +       /*
1102 +        * cookie is either the roc cookie (for normal roc)
1103 +        * or the SKB (for mgmt TX)
1104 +        */
1105 +       if (!txskb) {
1106 +               /* local->mtx protects this */
1107 +               local->roc_cookie_counter++;
1108 +               roc->cookie = local->roc_cookie_counter;
1109 +               /* wow, you wrapped 64 bits ... more likely a bug */
1110 +               if (WARN_ON(roc->cookie == 0)) {
1111 +                       roc->cookie = 1;
1112 +                       local->roc_cookie_counter++;
1113 +               }
1114 +               *cookie = roc->cookie;
1115 +       } else {
1116 +               *cookie = (unsigned long)txskb;
1117 +       }
1118 +
1119         /* if there's one pending or we're scanning, queue this one */
1120         if (!list_empty(&local->roc_list) ||
1121             local->scanning || local->radar_detect_enabled)
1122 @@ -2772,24 +2795,6 @@ static int ieee80211_start_roc_work(stru
1123         if (!queued)
1124                 list_add_tail(&roc->list, &local->roc_list);
1125  
1126 -       /*
1127 -        * cookie is either the roc cookie (for normal roc)
1128 -        * or the SKB (for mgmt TX)
1129 -        */
1130 -       if (!txskb) {
1131 -               /* local->mtx protects this */
1132 -               local->roc_cookie_counter++;
1133 -               roc->cookie = local->roc_cookie_counter;
1134 -               /* wow, you wrapped 64 bits ... more likely a bug */
1135 -               if (WARN_ON(roc->cookie == 0)) {
1136 -                       roc->cookie = 1;
1137 -                       local->roc_cookie_counter++;
1138 -               }
1139 -               *cookie = roc->cookie;
1140 -       } else {
1141 -               *cookie = (unsigned long)txskb;
1142 -       }
1143 -
1144         return 0;
1145  }
1146  
1147 @@ -3004,8 +3009,10 @@ void ieee80211_csa_finalize_work(struct 
1148         if (!ieee80211_sdata_running(sdata))
1149                 goto unlock;
1150  
1151 -       sdata->radar_required = sdata->csa_radar_required;
1152 +       sdata_assert_lock(sdata);
1153 +
1154         mutex_lock(&local->mtx);
1155 +       sdata->radar_required = sdata->csa_radar_required;
1156         err = ieee80211_vif_change_channel(sdata, &changed);
1157         mutex_unlock(&local->mtx);
1158         if (WARN_ON(err < 0))
1159 @@ -3022,13 +3029,13 @@ void ieee80211_csa_finalize_work(struct 
1160         switch (sdata->vif.type) {
1161         case NL80211_IFTYPE_AP:
1162                 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon);
1163 +               kfree(sdata->u.ap.next_beacon);
1164 +               sdata->u.ap.next_beacon = NULL;
1165 +
1166                 if (err < 0)
1167                         goto unlock;
1168  
1169                 changed |= err;
1170 -               kfree(sdata->u.ap.next_beacon);
1171 -               sdata->u.ap.next_beacon = NULL;
1172 -
1173                 ieee80211_bss_info_change_notify(sdata, err);
1174                 break;
1175         case NL80211_IFTYPE_ADHOC:
1176 @@ -3066,7 +3073,7 @@ int ieee80211_channel_switch(struct wiph
1177         struct ieee80211_if_mesh __maybe_unused *ifmsh;
1178         int err, num_chanctx;
1179  
1180 -       lockdep_assert_held(&sdata->wdev.mtx);
1181 +       sdata_assert_lock(sdata);
1182  
1183         if (!list_empty(&local->roc_list) || local->scanning)
1184                 return -EBUSY;
1185 --- a/net/mac80211/ht.c
1186 +++ b/net/mac80211/ht.c
1187 @@ -375,7 +375,7 @@ void ieee80211_send_delba(struct ieee802
1188         mgmt->u.action.u.delba.params = cpu_to_le16(params);
1189         mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code);
1190  
1191 -       ieee80211_tx_skb_tid(sdata, skb, tid);
1192 +       ieee80211_tx_skb(sdata, skb);
1193  }
1194  
1195  void ieee80211_process_delba(struct ieee80211_sub_if_data *sdata,
1196 @@ -466,7 +466,9 @@ void ieee80211_request_smps_ap_work(stru
1197                              u.ap.request_smps_work);
1198  
1199         sdata_lock(sdata);
1200 -       __ieee80211_request_smps_ap(sdata, sdata->u.ap.driver_smps_mode);
1201 +       if (sdata_dereference(sdata->u.ap.beacon, sdata))
1202 +               __ieee80211_request_smps_ap(sdata,
1203 +                                           sdata->u.ap.driver_smps_mode);
1204         sdata_unlock(sdata);
1205  }
1206  
1207 --- a/net/mac80211/iface.c
1208 +++ b/net/mac80211/iface.c
1209 @@ -770,12 +770,19 @@ static void ieee80211_do_stop(struct iee
1210  
1211         ieee80211_roc_purge(local, sdata);
1212  
1213 -       if (sdata->vif.type == NL80211_IFTYPE_STATION)
1214 +       switch (sdata->vif.type) {
1215 +       case NL80211_IFTYPE_STATION:
1216                 ieee80211_mgd_stop(sdata);
1217 -
1218 -       if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
1219 +               break;
1220 +       case NL80211_IFTYPE_ADHOC:
1221                 ieee80211_ibss_stop(sdata);
1222 -
1223 +               break;
1224 +       case NL80211_IFTYPE_AP:
1225 +               cancel_work_sync(&sdata->u.ap.request_smps_work);
1226 +               break;
1227 +       default:
1228 +               break;
1229 +       }
1230  
1231         /*
1232          * Remove all stations associated with this interface.
1233 @@ -827,7 +834,9 @@ static void ieee80211_do_stop(struct iee
1234         cancel_work_sync(&local->dynamic_ps_enable_work);
1235  
1236         cancel_work_sync(&sdata->recalc_smps);
1237 +       sdata_lock(sdata);
1238         sdata->vif.csa_active = false;
1239 +       sdata_unlock(sdata);
1240         cancel_work_sync(&sdata->csa_finalize_work);
1241  
1242         cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
1243 --- a/net/mac80211/rx.c
1244 +++ b/net/mac80211/rx.c
1245 @@ -599,10 +599,10 @@ static int ieee80211_is_unicast_robust_m
1246  {
1247         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1248  
1249 -       if (skb->len < 24 || is_multicast_ether_addr(hdr->addr1))
1250 +       if (is_multicast_ether_addr(hdr->addr1))
1251                 return 0;
1252  
1253 -       return ieee80211_is_robust_mgmt_frame(hdr);
1254 +       return ieee80211_is_robust_mgmt_frame(skb);
1255  }
1256  
1257  
1258 @@ -610,10 +610,10 @@ static int ieee80211_is_multicast_robust
1259  {
1260         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1261  
1262 -       if (skb->len < 24 || !is_multicast_ether_addr(hdr->addr1))
1263 +       if (!is_multicast_ether_addr(hdr->addr1))
1264                 return 0;
1265  
1266 -       return ieee80211_is_robust_mgmt_frame(hdr);
1267 +       return ieee80211_is_robust_mgmt_frame(skb);
1268  }
1269  
1270  
1271 @@ -626,7 +626,7 @@ static int ieee80211_get_mmie_keyidx(str
1272         if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
1273                 return -1;
1274  
1275 -       if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *) hdr))
1276 +       if (!ieee80211_is_robust_mgmt_frame(skb))
1277                 return -1; /* not a robust management frame */
1278  
1279         mmie = (struct ieee80211_mmie *)
1280 @@ -1311,18 +1311,15 @@ ieee80211_rx_h_sta_process(struct ieee80
1281             !ieee80211_has_morefrags(hdr->frame_control) &&
1282             !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1283             (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1284 -            rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
1285 +            rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1286 +           /* PM bit is only checked in frames where it isn't reserved,
1287 +            * in AP mode it's reserved in non-bufferable management frames
1288 +            * (cf. IEEE 802.11-2012 8.2.4.1.7 Power Management field)
1289 +            */
1290 +           (!ieee80211_is_mgmt(hdr->frame_control) ||
1291 +            ieee80211_is_bufferable_mmpdu(hdr->frame_control))) {
1292                 if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
1293 -                       /*
1294 -                        * Ignore doze->wake transitions that are
1295 -                        * indicated by non-data frames, the standard
1296 -                        * is unclear here, but for example going to
1297 -                        * PS mode and then scanning would cause a
1298 -                        * doze->wake transition for the probe request,
1299 -                        * and that is clearly undesirable.
1300 -                        */
1301 -                       if (ieee80211_is_data(hdr->frame_control) &&
1302 -                           !ieee80211_has_pm(hdr->frame_control))
1303 +                       if (!ieee80211_has_pm(hdr->frame_control))
1304                                 sta_ps_end(sta);
1305                 } else {
1306                         if (ieee80211_has_pm(hdr->frame_control))
1307 @@ -1845,8 +1842,7 @@ static int ieee80211_drop_unencrypted_mg
1308                  * having configured keys.
1309                  */
1310                 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
1311 -                            ieee80211_is_robust_mgmt_frame(
1312 -                                    (struct ieee80211_hdr *) rx->skb->data)))
1313 +                            ieee80211_is_robust_mgmt_frame(rx->skb)))
1314                         return -EACCES;
1315         }
1316  
1317 --- a/net/mac80211/tx.c
1318 +++ b/net/mac80211/tx.c
1319 @@ -452,8 +452,7 @@ static int ieee80211_use_mfp(__le16 fc, 
1320         if (sta == NULL || !test_sta_flag(sta, WLAN_STA_MFP))
1321                 return 0;
1322  
1323 -       if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *)
1324 -                                           skb->data))
1325 +       if (!ieee80211_is_robust_mgmt_frame(skb))
1326                 return 0;
1327  
1328         return 1;
1329 @@ -525,9 +524,7 @@ ieee80211_tx_h_ps_buf(struct ieee80211_t
1330  
1331         /* only deauth, disassoc and action are bufferable MMPDUs */
1332         if (ieee80211_is_mgmt(hdr->frame_control) &&
1333 -           !ieee80211_is_deauth(hdr->frame_control) &&
1334 -           !ieee80211_is_disassoc(hdr->frame_control) &&
1335 -           !ieee80211_is_action(hdr->frame_control)) {
1336 +           !ieee80211_is_bufferable_mmpdu(hdr->frame_control)) {
1337                 if (tx->flags & IEEE80211_TX_UNICAST)
1338                         info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER;
1339                 return TX_CONTINUE;
1340 @@ -567,7 +564,7 @@ ieee80211_tx_h_select_key(struct ieee802
1341                 tx->key = key;
1342         else if (ieee80211_is_mgmt(hdr->frame_control) &&
1343                  is_multicast_ether_addr(hdr->addr1) &&
1344 -                ieee80211_is_robust_mgmt_frame(hdr) &&
1345 +                ieee80211_is_robust_mgmt_frame(tx->skb) &&
1346                  (key = rcu_dereference(tx->sdata->default_mgmt_key)))
1347                 tx->key = key;
1348         else if (is_multicast_ether_addr(hdr->addr1) &&
1349 @@ -582,12 +579,12 @@ ieee80211_tx_h_select_key(struct ieee802
1350                 tx->key = NULL;
1351         else if (tx->skb->protocol == tx->sdata->control_port_protocol)
1352                 tx->key = NULL;
1353 -       else if (ieee80211_is_robust_mgmt_frame(hdr) &&
1354 +       else if (ieee80211_is_robust_mgmt_frame(tx->skb) &&
1355                  !(ieee80211_is_action(hdr->frame_control) &&
1356                    tx->sta && test_sta_flag(tx->sta, WLAN_STA_MFP)))
1357                 tx->key = NULL;
1358         else if (ieee80211_is_mgmt(hdr->frame_control) &&
1359 -                !ieee80211_is_robust_mgmt_frame(hdr))
1360 +                !ieee80211_is_robust_mgmt_frame(tx->skb))
1361                 tx->key = NULL;
1362         else {
1363                 I802_DEBUG_INC(tx->local->tx_handlers_drop_unencrypted);
1364 @@ -878,7 +875,7 @@ static int ieee80211_fragment(struct iee
1365         }
1366  
1367         /* adjust first fragment's length */
1368 -       skb->len = hdrlen + per_fragm;
1369 +       skb_trim(skb, hdrlen + per_fragm);
1370         return 0;
1371  }
1372  
1373 --- a/net/mac80211/wpa.c
1374 +++ b/net/mac80211/wpa.c
1375 @@ -499,7 +499,7 @@ ieee80211_crypto_ccmp_decrypt(struct iee
1376         hdrlen = ieee80211_hdrlen(hdr->frame_control);
1377  
1378         if (!ieee80211_is_data(hdr->frame_control) &&
1379 -           !ieee80211_is_robust_mgmt_frame(hdr))
1380 +           !ieee80211_is_robust_mgmt_frame(skb))
1381                 return RX_CONTINUE;
1382  
1383         data_len = skb->len - hdrlen - IEEE80211_CCMP_HDR_LEN -
1384 --- a/net/wireless/ap.c
1385 +++ b/net/wireless/ap.c
1386 @@ -27,9 +27,10 @@ static int __cfg80211_stop_ap(struct cfg
1387         err = rdev_stop_ap(rdev, dev);
1388         if (!err) {
1389                 wdev->beacon_interval = 0;
1390 -               wdev->channel = NULL;
1391 +               memset(&wdev->chandef, 0, sizeof(wdev->chandef));
1392                 wdev->ssid_len = 0;
1393                 rdev_set_qos_map(rdev, dev, NULL);
1394 +               nl80211_send_ap_stopped(wdev);
1395         }
1396  
1397         return err;
1398 --- a/net/wireless/core.c
1399 +++ b/net/wireless/core.c
1400 @@ -203,8 +203,11 @@ void cfg80211_stop_p2p_device(struct cfg
1401  
1402         rdev->opencount--;
1403  
1404 -       WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev &&
1405 -               !rdev->scan_req->notified);
1406 +       if (rdev->scan_req && rdev->scan_req->wdev == wdev) {
1407 +               if (WARN_ON(!rdev->scan_req->notified))
1408 +                       rdev->scan_req->aborted = true;
1409 +               ___cfg80211_scan_done(rdev, false);
1410 +       }
1411  }
1412  
1413  static int cfg80211_rfkill_set_block(void *data, bool blocked)
1414 @@ -447,9 +450,6 @@ int wiphy_register(struct wiphy *wiphy)
1415         int i;
1416         u16 ifmodes = wiphy->interface_modes;
1417  
1418 -       /* support for 5/10 MHz is broken due to nl80211 API mess - disable */
1419 -       wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_5_10_MHZ;
1420 -
1421         /*
1422          * There are major locking problems in nl80211/mac80211 for CSA,
1423          * disable for all drivers until this has been reworked.
1424 @@ -875,8 +875,11 @@ static int cfg80211_netdev_notifier_call
1425                 break;
1426         case NETDEV_DOWN:
1427                 cfg80211_update_iface_num(rdev, wdev->iftype, -1);
1428 -               WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev &&
1429 -                       !rdev->scan_req->notified);
1430 +               if (rdev->scan_req && rdev->scan_req->wdev == wdev) {
1431 +                       if (WARN_ON(!rdev->scan_req->notified))
1432 +                               rdev->scan_req->aborted = true;
1433 +                       ___cfg80211_scan_done(rdev, false);
1434 +               }
1435  
1436                 if (WARN_ON(rdev->sched_scan_req &&
1437                             rdev->sched_scan_req->dev == wdev->netdev)) {
1438 --- a/net/wireless/core.h
1439 +++ b/net/wireless/core.h
1440 @@ -62,6 +62,7 @@ struct cfg80211_registered_device {
1441         struct rb_root bss_tree;
1442         u32 bss_generation;
1443         struct cfg80211_scan_request *scan_req; /* protected by RTNL */
1444 +       struct sk_buff *scan_msg;
1445         struct cfg80211_sched_scan_request *sched_scan_req;
1446         unsigned long suspend_at;
1447         struct work_struct scan_done_wk;
1448 @@ -210,6 +211,7 @@ struct cfg80211_event {
1449                 } dc;
1450                 struct {
1451                         u8 bssid[ETH_ALEN];
1452 +                       struct ieee80211_channel *channel;
1453                 } ij;
1454         };
1455  };
1456 @@ -257,7 +259,8 @@ int __cfg80211_leave_ibss(struct cfg8021
1457                           struct net_device *dev, bool nowext);
1458  int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
1459                         struct net_device *dev, bool nowext);
1460 -void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid);
1461 +void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid,
1462 +                           struct ieee80211_channel *channel);
1463  int cfg80211_ibss_wext_join(struct cfg80211_registered_device *rdev,
1464                             struct wireless_dev *wdev);
1465  
1466 @@ -361,7 +364,8 @@ int cfg80211_validate_key_settings(struc
1467                                    struct key_params *params, int key_idx,
1468                                    bool pairwise, const u8 *mac_addr);
1469  void __cfg80211_scan_done(struct work_struct *wk);
1470 -void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev);
1471 +void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev,
1472 +                          bool send_message);
1473  void __cfg80211_sched_scan_results(struct work_struct *wk);
1474  int __cfg80211_stop_sched_scan(struct cfg80211_registered_device *rdev,
1475                                bool driver_initiated);
1476 @@ -441,7 +445,8 @@ static inline unsigned int elapsed_jiffi
1477  void
1478  cfg80211_get_chan_state(struct wireless_dev *wdev,
1479                         struct ieee80211_channel **chan,
1480 -                       enum cfg80211_chan_mode *chanmode);
1481 +                       enum cfg80211_chan_mode *chanmode,
1482 +                       u8 *radar_detect);
1483  
1484  int cfg80211_set_monitor_channel(struct cfg80211_registered_device *rdev,
1485                                  struct cfg80211_chan_def *chandef);
1486 --- a/net/wireless/nl80211.c
1487 +++ b/net/wireless/nl80211.c
1488 @@ -1723,9 +1723,10 @@ static int nl80211_dump_wiphy(struct sk_
1489                                  * We can then retry with the larger buffer.
1490                                  */
1491                                 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1492 -                                   !skb->len &&
1493 +                                   !skb->len && !state->split &&
1494                                     cb->min_dump_alloc < 4096) {
1495                                         cb->min_dump_alloc = 4096;
1496 +                                       state->split_start = 0;
1497                                         rtnl_unlock();
1498                                         return 1;
1499                                 }
1500 @@ -2047,10 +2048,12 @@ static int nl80211_set_wiphy(struct sk_b
1501                 nla_for_each_nested(nl_txq_params,
1502                                     info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1503                                     rem_txq_params) {
1504 -                       nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1505 -                                 nla_data(nl_txq_params),
1506 -                                 nla_len(nl_txq_params),
1507 -                                 txq_params_policy);
1508 +                       result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1509 +                                          nla_data(nl_txq_params),
1510 +                                          nla_len(nl_txq_params),
1511 +                                          txq_params_policy);
1512 +                       if (result)
1513 +                               goto bad_res;
1514                         result = parse_txq_params(tb, &txq_params);
1515                         if (result)
1516                                 goto bad_res;
1517 @@ -3289,7 +3292,7 @@ static int nl80211_start_ap(struct sk_bu
1518         if (!err) {
1519                 wdev->preset_chandef = params.chandef;
1520                 wdev->beacon_interval = params.beacon_interval;
1521 -               wdev->channel = params.chandef.chan;
1522 +               wdev->chandef = params.chandef;
1523                 wdev->ssid_len = params.ssid_len;
1524                 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
1525         }
1526 @@ -5210,9 +5213,11 @@ static int nl80211_set_reg(struct sk_buf
1527  
1528         nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
1529                             rem_reg_rules) {
1530 -               nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
1531 -                         nla_data(nl_reg_rule), nla_len(nl_reg_rule),
1532 -                         reg_rule_policy);
1533 +               r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
1534 +                             nla_data(nl_reg_rule), nla_len(nl_reg_rule),
1535 +                             reg_rule_policy);
1536 +               if (r)
1537 +                       goto bad_reg;
1538                 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
1539                 if (r)
1540                         goto bad_reg;
1541 @@ -5277,7 +5282,7 @@ static int nl80211_trigger_scan(struct s
1542         if (!rdev->ops->scan)
1543                 return -EOPNOTSUPP;
1544  
1545 -       if (rdev->scan_req) {
1546 +       if (rdev->scan_req || rdev->scan_msg) {
1547                 err = -EBUSY;
1548                 goto unlock;
1549         }
1550 @@ -5475,6 +5480,7 @@ static int nl80211_start_sched_scan(stru
1551         enum ieee80211_band band;
1552         size_t ie_len;
1553         struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
1554 +       s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
1555  
1556         if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
1557             !rdev->ops->sched_scan_start)
1558 @@ -5509,11 +5515,40 @@ static int nl80211_start_sched_scan(stru
1559         if (n_ssids > wiphy->max_sched_scan_ssids)
1560                 return -EINVAL;
1561  
1562 -       if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
1563 +       /*
1564 +        * First, count the number of 'real' matchsets. Due to an issue with
1565 +        * the old implementation, matchsets containing only the RSSI attribute
1566 +        * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
1567 +        * RSSI for all matchsets, rather than their own matchset for reporting
1568 +        * all APs with a strong RSSI. This is needed to be compatible with
1569 +        * older userspace that treated a matchset with only the RSSI as the
1570 +        * global RSSI for all other matchsets - if there are other matchsets.
1571 +        */
1572 +       if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
1573                 nla_for_each_nested(attr,
1574                                     info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
1575 -                                   tmp)
1576 -                       n_match_sets++;
1577 +                                   tmp) {
1578 +                       struct nlattr *rssi;
1579 +
1580 +                       err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
1581 +                                       nla_data(attr), nla_len(attr),
1582 +                                       nl80211_match_policy);
1583 +                       if (err)
1584 +                               return err;
1585 +                       /* add other standalone attributes here */
1586 +                       if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
1587 +                               n_match_sets++;
1588 +                               continue;
1589 +                       }
1590 +                       rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
1591 +                       if (rssi)
1592 +                               default_match_rssi = nla_get_s32(rssi);
1593 +               }
1594 +       }
1595 +
1596 +       /* However, if there's no other matchset, add the RSSI one */
1597 +       if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
1598 +               n_match_sets = 1;
1599  
1600         if (n_match_sets > wiphy->max_match_sets)
1601                 return -EINVAL;
1602 @@ -5634,11 +5669,22 @@ static int nl80211_start_sched_scan(stru
1603                                     tmp) {
1604                         struct nlattr *ssid, *rssi;
1605  
1606 -                       nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
1607 -                                 nla_data(attr), nla_len(attr),
1608 -                                 nl80211_match_policy);
1609 +                       err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
1610 +                                       nla_data(attr), nla_len(attr),
1611 +                                       nl80211_match_policy);
1612 +                       if (err)
1613 +                               goto out_free;
1614                         ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
1615                         if (ssid) {
1616 +                               if (WARN_ON(i >= n_match_sets)) {
1617 +                                       /* this indicates a programming error,
1618 +                                        * the loop above should have verified
1619 +                                        * things properly
1620 +                                        */
1621 +                                       err = -EINVAL;
1622 +                                       goto out_free;
1623 +                               }
1624 +
1625                                 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
1626                                         err = -EINVAL;
1627                                         goto out_free;
1628 @@ -5647,15 +5693,28 @@ static int nl80211_start_sched_scan(stru
1629                                        nla_data(ssid), nla_len(ssid));
1630                                 request->match_sets[i].ssid.ssid_len =
1631                                         nla_len(ssid);
1632 +                               /* special attribute - old implemenation w/a */
1633 +                               request->match_sets[i].rssi_thold =
1634 +                                       default_match_rssi;
1635 +                               rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
1636 +                               if (rssi)
1637 +                                       request->match_sets[i].rssi_thold =
1638 +                                               nla_get_s32(rssi);
1639                         }
1640 -                       rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
1641 -                       if (rssi)
1642 -                               request->rssi_thold = nla_get_u32(rssi);
1643 -                       else
1644 -                               request->rssi_thold =
1645 -                                                  NL80211_SCAN_RSSI_THOLD_OFF;
1646                         i++;
1647                 }
1648 +
1649 +               /* there was no other matchset, so the RSSI one is alone */
1650 +               if (i == 0)
1651 +                       request->match_sets[0].rssi_thold = default_match_rssi;
1652 +
1653 +               request->min_rssi_thold = INT_MAX;
1654 +               for (i = 0; i < n_match_sets; i++)
1655 +                       request->min_rssi_thold =
1656 +                               min(request->match_sets[i].rssi_thold,
1657 +                                   request->min_rssi_thold);
1658 +       } else {
1659 +               request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
1660         }
1661  
1662         if (info->attrs[NL80211_ATTR_IE]) {
1663 @@ -5751,7 +5810,7 @@ static int nl80211_start_radar_detection
1664  
1665         err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
1666         if (!err) {
1667 -               wdev->channel = chandef.chan;
1668 +               wdev->chandef = chandef;
1669                 wdev->cac_started = true;
1670                 wdev->cac_start_time = jiffies;
1671         }
1672 @@ -7502,16 +7561,19 @@ static int nl80211_set_tx_bitrate_mask(s
1673          * directly to the enum ieee80211_band values used in cfg80211.
1674          */
1675         BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
1676 -       nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
1677 -       {
1678 +       nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
1679                 enum ieee80211_band band = nla_type(tx_rates);
1680 +               int err;
1681 +
1682                 if (band < 0 || band >= IEEE80211_NUM_BANDS)
1683                         return -EINVAL;
1684                 sband = rdev->wiphy.bands[band];
1685                 if (sband == NULL)
1686                         return -EINVAL;
1687 -               nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
1688 -                         nla_len(tx_rates), nl80211_txattr_policy);
1689 +               err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
1690 +                               nla_len(tx_rates), nl80211_txattr_policy);
1691 +               if (err)
1692 +                       return err;
1693                 if (tb[NL80211_TXRATE_LEGACY]) {
1694                         mask.control[band].legacy = rateset_to_mask(
1695                                 sband,
1696 @@ -10054,40 +10116,31 @@ void nl80211_send_scan_start(struct cfg8
1697                                 NL80211_MCGRP_SCAN, GFP_KERNEL);
1698  }
1699  
1700 -void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
1701 -                           struct wireless_dev *wdev)
1702 +struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
1703 +                                      struct wireless_dev *wdev, bool aborted)
1704  {
1705         struct sk_buff *msg;
1706  
1707         msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1708         if (!msg)
1709 -               return;
1710 +               return NULL;
1711  
1712         if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
1713 -                                 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
1714 +                                 aborted ? NL80211_CMD_SCAN_ABORTED :
1715 +                                           NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
1716                 nlmsg_free(msg);
1717 -               return;
1718 +               return NULL;
1719         }
1720  
1721 -       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
1722 -                               NL80211_MCGRP_SCAN, GFP_KERNEL);
1723 +       return msg;
1724  }
1725  
1726 -void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
1727 -                              struct wireless_dev *wdev)
1728 +void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
1729 +                             struct sk_buff *msg)
1730  {
1731 -       struct sk_buff *msg;
1732 -
1733 -       msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1734         if (!msg)
1735                 return;
1736  
1737 -       if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
1738 -                                 NL80211_CMD_SCAN_ABORTED) < 0) {
1739 -               nlmsg_free(msg);
1740 -               return;
1741 -       }
1742 -
1743         genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
1744                                 NL80211_MCGRP_SCAN, GFP_KERNEL);
1745  }
1746 @@ -11158,7 +11211,8 @@ void cfg80211_ch_switch_notify(struct ne
1747                     wdev->iftype != NL80211_IFTYPE_MESH_POINT))
1748                 return;
1749  
1750 -       wdev->channel = chandef->chan;
1751 +       wdev->chandef = *chandef;
1752 +       wdev->preset_chandef = *chandef;
1753         nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
1754  }
1755  EXPORT_SYMBOL(cfg80211_ch_switch_notify);
1756 @@ -11673,6 +11727,35 @@ void cfg80211_crit_proto_stopped(struct 
1757  }
1758  EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
1759  
1760 +void nl80211_send_ap_stopped(struct wireless_dev *wdev)
1761 +{
1762 +       struct wiphy *wiphy = wdev->wiphy;
1763 +       struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
1764 +       struct sk_buff *msg;
1765 +       void *hdr;
1766 +
1767 +       msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1768 +       if (!msg)
1769 +               return;
1770 +
1771 +       hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
1772 +       if (!hdr)
1773 +               goto out;
1774 +
1775 +       if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
1776 +           nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
1777 +           nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
1778 +               goto out;
1779 +
1780 +       genlmsg_end(msg, hdr);
1781 +
1782 +       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
1783 +                               NL80211_MCGRP_MLME, GFP_KERNEL);
1784 +       return;
1785 + out:
1786 +       nlmsg_free(msg);
1787 +}
1788 +
1789  /* initialisation/exit functions */
1790  
1791  int nl80211_init(void)
1792 --- a/net/wireless/nl80211.h
1793 +++ b/net/wireless/nl80211.h
1794 @@ -8,10 +8,10 @@ void nl80211_exit(void);
1795  void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev);
1796  void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
1797                              struct wireless_dev *wdev);
1798 -void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
1799 -                           struct wireless_dev *wdev);
1800 -void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
1801 -                              struct wireless_dev *wdev);
1802 +struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
1803 +                                      struct wireless_dev *wdev, bool aborted);
1804 +void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
1805 +                             struct sk_buff *msg);
1806  void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
1807                              struct net_device *netdev, u32 cmd);
1808  void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
1809 @@ -74,6 +74,8 @@ nl80211_radar_notify(struct cfg80211_reg
1810                      enum nl80211_radar_event event,
1811                      struct net_device *netdev, gfp_t gfp);
1812  
1813 +void nl80211_send_ap_stopped(struct wireless_dev *wdev);
1814 +
1815  void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev);
1816  
1817  #endif /* __NET_WIRELESS_NL80211_H */
1818 --- a/net/wireless/scan.c
1819 +++ b/net/wireless/scan.c
1820 @@ -161,18 +161,25 @@ static void __cfg80211_bss_expire(struct
1821                 dev->bss_generation++;
1822  }
1823  
1824 -void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev)
1825 +void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev,
1826 +                          bool send_message)
1827  {
1828         struct cfg80211_scan_request *request;
1829         struct wireless_dev *wdev;
1830 +       struct sk_buff *msg;
1831  #ifdef CPTCFG_CFG80211_WEXT
1832         union iwreq_data wrqu;
1833  #endif
1834  
1835         ASSERT_RTNL();
1836  
1837 -       request = rdev->scan_req;
1838 +       if (rdev->scan_msg) {
1839 +               nl80211_send_scan_result(rdev, rdev->scan_msg);
1840 +               rdev->scan_msg = NULL;
1841 +               return;
1842 +       }
1843  
1844 +       request = rdev->scan_req;
1845         if (!request)
1846                 return;
1847  
1848 @@ -186,18 +193,16 @@ void ___cfg80211_scan_done(struct cfg802
1849         if (wdev->netdev)
1850                 cfg80211_sme_scan_done(wdev->netdev);
1851  
1852 -       if (request->aborted) {
1853 -               nl80211_send_scan_aborted(rdev, wdev);
1854 -       } else {
1855 -               if (request->flags & NL80211_SCAN_FLAG_FLUSH) {
1856 -                       /* flush entries from previous scans */
1857 -                       spin_lock_bh(&rdev->bss_lock);
1858 -                       __cfg80211_bss_expire(rdev, request->scan_start);
1859 -                       spin_unlock_bh(&rdev->bss_lock);
1860 -               }
1861 -               nl80211_send_scan_done(rdev, wdev);
1862 +       if (!request->aborted &&
1863 +           request->flags & NL80211_SCAN_FLAG_FLUSH) {
1864 +               /* flush entries from previous scans */
1865 +               spin_lock_bh(&rdev->bss_lock);
1866 +               __cfg80211_bss_expire(rdev, request->scan_start);
1867 +               spin_unlock_bh(&rdev->bss_lock);
1868         }
1869  
1870 +       msg = nl80211_build_scan_msg(rdev, wdev, request->aborted);
1871 +
1872  #ifdef CPTCFG_CFG80211_WEXT
1873         if (wdev->netdev && !request->aborted) {
1874                 memset(&wrqu, 0, sizeof(wrqu));
1875 @@ -211,6 +216,11 @@ void ___cfg80211_scan_done(struct cfg802
1876  
1877         rdev->scan_req = NULL;
1878         kfree(request);
1879 +
1880 +       if (!send_message)
1881 +               rdev->scan_msg = msg;
1882 +       else
1883 +               nl80211_send_scan_result(rdev, msg);
1884  }
1885  
1886  void __cfg80211_scan_done(struct work_struct *wk)
1887 @@ -221,7 +231,7 @@ void __cfg80211_scan_done(struct work_st
1888                             scan_done_wk);
1889  
1890         rtnl_lock();
1891 -       ___cfg80211_scan_done(rdev);
1892 +       ___cfg80211_scan_done(rdev, true);
1893         rtnl_unlock();
1894  }
1895  
1896 @@ -1079,7 +1089,7 @@ int cfg80211_wext_siwscan(struct net_dev
1897         if (IS_ERR(rdev))
1898                 return PTR_ERR(rdev);
1899  
1900 -       if (rdev->scan_req) {
1901 +       if (rdev->scan_req || rdev->scan_msg) {
1902                 err = -EBUSY;
1903                 goto out;
1904         }
1905 @@ -1481,7 +1491,7 @@ int cfg80211_wext_giwscan(struct net_dev
1906         if (IS_ERR(rdev))
1907                 return PTR_ERR(rdev);
1908  
1909 -       if (rdev->scan_req)
1910 +       if (rdev->scan_req || rdev->scan_msg)
1911                 return -EAGAIN;
1912  
1913         res = ieee80211_scan_results(rdev, info, extra, data->length);
1914 --- a/net/wireless/sme.c
1915 +++ b/net/wireless/sme.c
1916 @@ -67,7 +67,7 @@ static int cfg80211_conn_scan(struct wir
1917         ASSERT_RDEV_LOCK(rdev);
1918         ASSERT_WDEV_LOCK(wdev);
1919  
1920 -       if (rdev->scan_req)
1921 +       if (rdev->scan_req || rdev->scan_msg)
1922                 return -EBUSY;
1923  
1924         if (wdev->conn->params.channel)
1925 --- a/net/mac80211/mlme.c
1926 +++ b/net/mac80211/mlme.c
1927 @@ -1001,7 +1001,6 @@ ieee80211_sta_process_chanswitch(struct 
1928         }
1929  
1930         ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
1931 -       sdata->vif.csa_active = true;
1932  
1933         mutex_lock(&local->chanctx_mtx);
1934         if (local->use_chanctx) {
1935 @@ -1039,6 +1038,7 @@ ieee80211_sta_process_chanswitch(struct 
1936         mutex_unlock(&local->chanctx_mtx);
1937  
1938         sdata->csa_chandef = csa_ie.chandef;
1939 +       sdata->vif.csa_active = true;
1940  
1941         if (csa_ie.mode)
1942                 ieee80211_stop_queues_by_reason(&local->hw,
1943 --- a/net/mac80211/chan.c
1944 +++ b/net/mac80211/chan.c
1945 @@ -196,6 +196,8 @@ static bool ieee80211_is_radar_required(
1946  {
1947         struct ieee80211_sub_if_data *sdata;
1948  
1949 +       lockdep_assert_held(&local->mtx);
1950 +
1951         rcu_read_lock();
1952         list_for_each_entry_rcu(sdata, &local->interfaces, list) {
1953                 if (sdata->radar_required) {
1954 --- a/net/mac80211/ibss.c
1955 +++ b/net/mac80211/ibss.c
1956 @@ -294,7 +294,6 @@ static void __ieee80211_sta_join_ibss(st
1957         }
1958  
1959         mutex_lock(&local->mtx);
1960 -       ieee80211_vif_release_channel(sdata);
1961         if (ieee80211_vif_use_channel(sdata, &chandef,
1962                                       ifibss->fixed_channel ?
1963                                         IEEE80211_CHANCTX_SHARED :
1964 @@ -303,6 +302,7 @@ static void __ieee80211_sta_join_ibss(st
1965                 mutex_unlock(&local->mtx);
1966                 return;
1967         }
1968 +       sdata->radar_required = radar_required;
1969         mutex_unlock(&local->mtx);
1970  
1971         memcpy(ifibss->bssid, bssid, ETH_ALEN);
1972 @@ -318,7 +318,6 @@ static void __ieee80211_sta_join_ibss(st
1973         rcu_assign_pointer(ifibss->presp, presp);
1974         mgmt = (void *)presp->head;
1975  
1976 -       sdata->radar_required = radar_required;
1977         sdata->vif.bss_conf.enable_beacon = true;
1978         sdata->vif.bss_conf.beacon_int = beacon_int;
1979         sdata->vif.bss_conf.basic_rates = basic_rates;
1980 @@ -386,7 +385,7 @@ static void __ieee80211_sta_join_ibss(st
1981                                               presp->head_len, 0, GFP_KERNEL);
1982         cfg80211_put_bss(local->hw.wiphy, bss);
1983         netif_carrier_on(sdata->dev);
1984 -       cfg80211_ibss_joined(sdata->dev, ifibss->bssid, GFP_KERNEL);
1985 +       cfg80211_ibss_joined(sdata->dev, ifibss->bssid, chan, GFP_KERNEL);
1986  }
1987  
1988  static void ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
1989 @@ -802,6 +801,8 @@ ieee80211_ibss_process_chanswitch(struct
1990         int err;
1991         u32 sta_flags;
1992  
1993 +       sdata_assert_lock(sdata);
1994 +
1995         sta_flags = IEEE80211_STA_DISABLE_VHT;
1996         switch (ifibss->chandef.width) {
1997         case NL80211_CHAN_WIDTH_5:
1998 @@ -1471,6 +1472,11 @@ static void ieee80211_rx_mgmt_probe_req(
1999         memcpy(((struct ieee80211_mgmt *) skb->data)->da, mgmt->sa, ETH_ALEN);
2000         ibss_dbg(sdata, "Sending ProbeResp to %pM\n", mgmt->sa);
2001         IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
2002 +
2003 +       /* avoid excessive retries for probe request to wildcard SSIDs */
2004 +       if (pos[1] == 0)
2005 +               IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_NO_ACK;
2006 +
2007         ieee80211_tx_skb(sdata, skb);
2008  }
2009  
2010 --- a/net/mac80211/mesh.c
2011 +++ b/net/mac80211/mesh.c
2012 @@ -872,6 +872,8 @@ ieee80211_mesh_process_chnswitch(struct 
2013         if (!ifmsh->mesh_id)
2014                 return false;
2015  
2016 +       sdata_assert_lock(sdata);
2017 +
2018         sta_flags = IEEE80211_STA_DISABLE_VHT;
2019         switch (sdata->vif.bss_conf.chandef.width) {
2020         case NL80211_CHAN_WIDTH_20_NOHT:
2021 --- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
2022 +++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
2023 @@ -4658,6 +4658,7 @@ brcmf_notify_connect_status(struct brcmf
2024         struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
2025         struct net_device *ndev = ifp->ndev;
2026         struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
2027 +       struct ieee80211_channel *chan;
2028         s32 err = 0;
2029  
2030         if (ifp->vif->mode == WL_MODE_AP) {
2031 @@ -4665,9 +4666,10 @@ brcmf_notify_connect_status(struct brcmf
2032         } else if (brcmf_is_linkup(e)) {
2033                 brcmf_dbg(CONN, "Linkup\n");
2034                 if (brcmf_is_ibssmode(ifp->vif)) {
2035 +                       chan = ieee80211_get_channel(cfg->wiphy, cfg->channel);
2036                         memcpy(profile->bssid, e->addr, ETH_ALEN);
2037                         wl_inform_ibss(cfg, ndev, e->addr);
2038 -                       cfg80211_ibss_joined(ndev, e->addr, GFP_KERNEL);
2039 +                       cfg80211_ibss_joined(ndev, e->addr, chan, GFP_KERNEL);
2040                         clear_bit(BRCMF_VIF_STATUS_CONNECTING,
2041                                   &ifp->vif->sme_state);
2042                         set_bit(BRCMF_VIF_STATUS_CONNECTED,
2043 --- a/drivers/net/wireless/libertas/cfg.c
2044 +++ b/drivers/net/wireless/libertas/cfg.c
2045 @@ -1766,7 +1766,8 @@ static void lbs_join_post(struct lbs_pri
2046         memcpy(priv->wdev->ssid, params->ssid, params->ssid_len);
2047         priv->wdev->ssid_len = params->ssid_len;
2048  
2049 -       cfg80211_ibss_joined(priv->dev, bssid, GFP_KERNEL);
2050 +       cfg80211_ibss_joined(priv->dev, bssid, params->chandef.chan,
2051 +                            GFP_KERNEL);
2052  
2053         /* TODO: consider doing this at MACREG_INT_CODE_LINK_SENSED time */
2054         priv->connect_status = LBS_CONNECTED;
2055 --- a/drivers/net/wireless/mwifiex/cfg80211.c
2056 +++ b/drivers/net/wireless/mwifiex/cfg80211.c
2057 @@ -1881,7 +1881,8 @@ mwifiex_cfg80211_join_ibss(struct wiphy 
2058                                      params->privacy);
2059  done:
2060         if (!ret) {
2061 -               cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid, GFP_KERNEL);
2062 +               cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid,
2063 +                                    params->chandef.chan, GFP_KERNEL);
2064                 dev_dbg(priv->adapter->dev,
2065                         "info: joined/created adhoc network with bssid"
2066                         " %pM successfully\n", priv->cfg_bssid);
2067 --- a/drivers/net/wireless/rndis_wlan.c
2068 +++ b/drivers/net/wireless/rndis_wlan.c
2069 @@ -2835,7 +2835,9 @@ static void rndis_wlan_do_link_up_work(s
2070                                         bssid, req_ie, req_ie_len,
2071                                         resp_ie, resp_ie_len, GFP_KERNEL);
2072         } else if (priv->infra_mode == NDIS_80211_INFRA_ADHOC)
2073 -               cfg80211_ibss_joined(usbdev->net, bssid, GFP_KERNEL);
2074 +               cfg80211_ibss_joined(usbdev->net, bssid,
2075 +                                    get_current_channel(usbdev, NULL),
2076 +                                    GFP_KERNEL);
2077  
2078         kfree(info);
2079  
2080 --- a/net/wireless/ibss.c
2081 +++ b/net/wireless/ibss.c
2082 @@ -14,7 +14,8 @@
2083  #include "rdev-ops.h"
2084  
2085  
2086 -void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid)
2087 +void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid,
2088 +                           struct ieee80211_channel *channel)
2089  {
2090         struct wireless_dev *wdev = dev->ieee80211_ptr;
2091         struct cfg80211_bss *bss;
2092 @@ -28,8 +29,7 @@ void __cfg80211_ibss_joined(struct net_d
2093         if (!wdev->ssid_len)
2094                 return;
2095  
2096 -       bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid,
2097 -                              wdev->ssid, wdev->ssid_len,
2098 +       bss = cfg80211_get_bss(wdev->wiphy, channel, bssid, NULL, 0,
2099                                WLAN_CAPABILITY_IBSS, WLAN_CAPABILITY_IBSS);
2100  
2101         if (WARN_ON(!bss))
2102 @@ -54,21 +54,26 @@ void __cfg80211_ibss_joined(struct net_d
2103  #endif
2104  }
2105  
2106 -void cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid, gfp_t gfp)
2107 +void cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid,
2108 +                         struct ieee80211_channel *channel, gfp_t gfp)
2109  {
2110         struct wireless_dev *wdev = dev->ieee80211_ptr;
2111         struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
2112         struct cfg80211_event *ev;
2113         unsigned long flags;
2114  
2115 -       trace_cfg80211_ibss_joined(dev, bssid);
2116 +       trace_cfg80211_ibss_joined(dev, bssid, channel);
2117 +
2118 +       if (WARN_ON(!channel))
2119 +               return;
2120  
2121         ev = kzalloc(sizeof(*ev), gfp);
2122         if (!ev)
2123                 return;
2124  
2125         ev->type = EVENT_IBSS_JOINED;
2126 -       memcpy(ev->cr.bssid, bssid, ETH_ALEN);
2127 +       memcpy(ev->ij.bssid, bssid, ETH_ALEN);
2128 +       ev->ij.channel = channel;
2129  
2130         spin_lock_irqsave(&wdev->event_lock, flags);
2131         list_add_tail(&ev->list, &wdev->event_list);
2132 @@ -117,6 +122,7 @@ int __cfg80211_join_ibss(struct cfg80211
2133  
2134         wdev->ibss_fixed = params->channel_fixed;
2135         wdev->ibss_dfs_possible = params->userspace_handles_dfs;
2136 +       wdev->chandef = params->chandef;
2137  #ifdef CPTCFG_CFG80211_WEXT
2138         wdev->wext.ibss.chandef = params->chandef;
2139  #endif
2140 @@ -200,6 +206,7 @@ static void __cfg80211_clear_ibss(struct
2141  
2142         wdev->current_bss = NULL;
2143         wdev->ssid_len = 0;
2144 +       memset(&wdev->chandef, 0, sizeof(wdev->chandef));
2145  #ifdef CPTCFG_CFG80211_WEXT
2146         if (!nowext)
2147                 wdev->wext.ibss.ssid_len = 0;
2148 --- a/net/wireless/trace.h
2149 +++ b/net/wireless/trace.h
2150 @@ -2278,11 +2278,6 @@ DECLARE_EVENT_CLASS(cfg80211_rx_evt,
2151         TP_printk(NETDEV_PR_FMT ", " MAC_PR_FMT, NETDEV_PR_ARG, MAC_PR_ARG(addr))
2152  );
2153  
2154 -DEFINE_EVENT(cfg80211_rx_evt, cfg80211_ibss_joined,
2155 -       TP_PROTO(struct net_device *netdev, const u8 *addr),
2156 -       TP_ARGS(netdev, addr)
2157 -);
2158 -
2159  DEFINE_EVENT(cfg80211_rx_evt, cfg80211_rx_spurious_frame,
2160         TP_PROTO(struct net_device *netdev, const u8 *addr),
2161         TP_ARGS(netdev, addr)
2162 @@ -2293,6 +2288,24 @@ DEFINE_EVENT(cfg80211_rx_evt, cfg80211_r
2163         TP_ARGS(netdev, addr)
2164  );
2165  
2166 +TRACE_EVENT(cfg80211_ibss_joined,
2167 +       TP_PROTO(struct net_device *netdev, const u8 *bssid,
2168 +                struct ieee80211_channel *channel),
2169 +       TP_ARGS(netdev, bssid, channel),
2170 +       TP_STRUCT__entry(
2171 +               NETDEV_ENTRY
2172 +               MAC_ENTRY(bssid)
2173 +               CHAN_ENTRY
2174 +       ),
2175 +       TP_fast_assign(
2176 +               NETDEV_ASSIGN;
2177 +               MAC_ASSIGN(bssid, bssid);
2178 +               CHAN_ASSIGN(channel);
2179 +       ),
2180 +       TP_printk(NETDEV_PR_FMT ", bssid: " MAC_PR_FMT ", " CHAN_PR_FMT,
2181 +                 NETDEV_PR_ARG, MAC_PR_ARG(bssid), CHAN_PR_ARG)
2182 +);
2183 +
2184  TRACE_EVENT(cfg80211_probe_status,
2185         TP_PROTO(struct net_device *netdev, const u8 *addr, u64 cookie,
2186                  bool acked),
2187 --- a/net/wireless/util.c
2188 +++ b/net/wireless/util.c
2189 @@ -820,7 +820,8 @@ void cfg80211_process_wdev_events(struct
2190                                                 ev->dc.reason, true);
2191                         break;
2192                 case EVENT_IBSS_JOINED:
2193 -                       __cfg80211_ibss_joined(wdev->netdev, ev->ij.bssid);
2194 +                       __cfg80211_ibss_joined(wdev->netdev, ev->ij.bssid,
2195 +                                              ev->ij.channel);
2196                         break;
2197                 }
2198                 wdev_unlock(wdev);
2199 @@ -1356,7 +1357,7 @@ int cfg80211_can_use_iftype_chan(struct 
2200                  */
2201                 mutex_lock_nested(&wdev_iter->mtx, 1);
2202                 __acquire(wdev_iter->mtx);
2203 -               cfg80211_get_chan_state(wdev_iter, &ch, &chmode);
2204 +               cfg80211_get_chan_state(wdev_iter, &ch, &chmode, &radar_detect);
2205                 wdev_unlock(wdev_iter);
2206  
2207                 switch (chmode) {
2208 --- a/net/wireless/chan.c
2209 +++ b/net/wireless/chan.c
2210 @@ -642,7 +642,8 @@ int cfg80211_set_monitor_channel(struct 
2211  void
2212  cfg80211_get_chan_state(struct wireless_dev *wdev,
2213                         struct ieee80211_channel **chan,
2214 -                       enum cfg80211_chan_mode *chanmode)
2215 +                       enum cfg80211_chan_mode *chanmode,
2216 +                       u8 *radar_detect)
2217  {
2218         *chan = NULL;
2219         *chanmode = CHAN_MODE_UNDEFINED;
2220 @@ -660,6 +661,11 @@ cfg80211_get_chan_state(struct wireless_
2221                                      !wdev->ibss_dfs_possible)
2222                                   ? CHAN_MODE_SHARED
2223                                   : CHAN_MODE_EXCLUSIVE;
2224 +
2225 +                       /* consider worst-case - IBSS can try to return to the
2226 +                        * original user-specified channel as creator */
2227 +                       if (wdev->ibss_dfs_possible)
2228 +                               *radar_detect |= BIT(wdev->chandef.width);
2229                         return;
2230                 }
2231                 break;
2232 @@ -674,17 +680,26 @@ cfg80211_get_chan_state(struct wireless_
2233         case NL80211_IFTYPE_AP:
2234         case NL80211_IFTYPE_P2P_GO:
2235                 if (wdev->cac_started) {
2236 -                       *chan = wdev->channel;
2237 +                       *chan = wdev->chandef.chan;
2238                         *chanmode = CHAN_MODE_SHARED;
2239 +                       *radar_detect |= BIT(wdev->chandef.width);
2240                 } else if (wdev->beacon_interval) {
2241 -                       *chan = wdev->channel;
2242 +                       *chan = wdev->chandef.chan;
2243                         *chanmode = CHAN_MODE_SHARED;
2244 +
2245 +                       if (cfg80211_chandef_dfs_required(wdev->wiphy,
2246 +                                                         &wdev->chandef))
2247 +                               *radar_detect |= BIT(wdev->chandef.width);
2248                 }
2249                 return;
2250         case NL80211_IFTYPE_MESH_POINT:
2251                 if (wdev->mesh_id_len) {
2252 -                       *chan = wdev->channel;
2253 +                       *chan = wdev->chandef.chan;
2254                         *chanmode = CHAN_MODE_SHARED;
2255 +
2256 +                       if (cfg80211_chandef_dfs_required(wdev->wiphy,
2257 +                                                         &wdev->chandef))
2258 +                               *radar_detect |= BIT(wdev->chandef.width);
2259                 }
2260                 return;
2261         case NL80211_IFTYPE_MONITOR:
2262 --- a/net/wireless/mesh.c
2263 +++ b/net/wireless/mesh.c
2264 @@ -195,7 +195,7 @@ int __cfg80211_join_mesh(struct cfg80211
2265         if (!err) {
2266                 memcpy(wdev->ssid, setup->mesh_id, setup->mesh_id_len);
2267                 wdev->mesh_id_len = setup->mesh_id_len;
2268 -               wdev->channel = setup->chandef.chan;
2269 +               wdev->chandef = setup->chandef;
2270         }
2271  
2272         return err;
2273 @@ -244,7 +244,7 @@ int cfg80211_set_mesh_channel(struct cfg
2274                 err = rdev_libertas_set_mesh_channel(rdev, wdev->netdev,
2275                                                      chandef->chan);
2276                 if (!err)
2277 -                       wdev->channel = chandef->chan;
2278 +                       wdev->chandef = *chandef;
2279  
2280                 return err;
2281         }
2282 @@ -276,7 +276,7 @@ static int __cfg80211_leave_mesh(struct 
2283         err = rdev_leave_mesh(rdev, dev);
2284         if (!err) {
2285                 wdev->mesh_id_len = 0;
2286 -               wdev->channel = NULL;
2287 +               memset(&wdev->chandef, 0, sizeof(wdev->chandef));
2288                 rdev_set_qos_map(rdev, dev, NULL);
2289         }
2290  
2291 --- a/net/wireless/mlme.c
2292 +++ b/net/wireless/mlme.c
2293 @@ -772,7 +772,7 @@ void cfg80211_cac_event(struct net_devic
2294         if (WARN_ON(!wdev->cac_started))
2295                 return;
2296  
2297 -       if (WARN_ON(!wdev->channel))
2298 +       if (WARN_ON(!wdev->chandef.chan))
2299                 return;
2300  
2301         switch (event) {
2302 --- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
2303 +++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
2304 @@ -5065,6 +5065,10 @@ static u16 ar9003_hw_get_max_edge_power(
2305                         break;
2306                 }
2307         }
2308 +
2309 +       if (is2GHz && !twiceMaxEdgePower)
2310 +               twiceMaxEdgePower = 60;
2311 +
2312         return twiceMaxEdgePower;
2313  }
2314  
2315 --- a/drivers/net/wireless/ath/ath9k/ar9003_calib.c
2316 +++ b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
2317 @@ -23,10 +23,11 @@
2318  #define MAX_MEASUREMENT        MAX_IQCAL_MEASUREMENT
2319  #define MAX_MAG_DELTA  11
2320  #define MAX_PHS_DELTA  10
2321 +#define MAXIQCAL        3
2322  
2323  struct coeff {
2324 -       int mag_coeff[AR9300_MAX_CHAINS][MAX_MEASUREMENT];
2325 -       int phs_coeff[AR9300_MAX_CHAINS][MAX_MEASUREMENT];
2326 +       int mag_coeff[AR9300_MAX_CHAINS][MAX_MEASUREMENT][MAXIQCAL];
2327 +       int phs_coeff[AR9300_MAX_CHAINS][MAX_MEASUREMENT][MAXIQCAL];
2328         int iqc_coeff[2];
2329  };
2330  
2331 @@ -800,7 +801,7 @@ static bool ar9003_hw_calc_iq_corr(struc
2332         if (q_q_coff > 63)
2333                 q_q_coff = 63;
2334  
2335 -       iqc_coeff[0] = (q_q_coff * 128) + q_i_coff;
2336 +       iqc_coeff[0] = (q_q_coff * 128) + (0x7f & q_i_coff);
2337  
2338         ath_dbg(common, CALIBRATE, "tx chain %d: iq corr coeff=%x\n",
2339                 chain_idx, iqc_coeff[0]);
2340 @@ -831,7 +832,7 @@ static bool ar9003_hw_calc_iq_corr(struc
2341         if (q_q_coff > 63)
2342                 q_q_coff = 63;
2343  
2344 -       iqc_coeff[1] = (q_q_coff * 128) + q_i_coff;
2345 +       iqc_coeff[1] = (q_q_coff * 128) + (0x7f & q_i_coff);
2346  
2347         ath_dbg(common, CALIBRATE, "rx chain %d: iq corr coeff=%x\n",
2348                 chain_idx, iqc_coeff[1]);
2349 @@ -839,7 +840,8 @@ static bool ar9003_hw_calc_iq_corr(struc
2350         return true;
2351  }
2352  
2353 -static void ar9003_hw_detect_outlier(int *mp_coeff, int nmeasurement,
2354 +static void ar9003_hw_detect_outlier(int mp_coeff[][MAXIQCAL],
2355 +                                    int nmeasurement,
2356                                      int max_delta)
2357  {
2358         int mp_max = -64, max_idx = 0;
2359 @@ -848,20 +850,20 @@ static void ar9003_hw_detect_outlier(int
2360  
2361         /* find min/max mismatch across all calibrated gains */
2362         for (i = 0; i < nmeasurement; i++) {
2363 -               if (mp_coeff[i] > mp_max) {
2364 -                       mp_max = mp_coeff[i];
2365 +               if (mp_coeff[i][0] > mp_max) {
2366 +                       mp_max = mp_coeff[i][0];
2367                         max_idx = i;
2368 -               } else if (mp_coeff[i] < mp_min) {
2369 -                       mp_min = mp_coeff[i];
2370 +               } else if (mp_coeff[i][0] < mp_min) {
2371 +                       mp_min = mp_coeff[i][0];
2372                         min_idx = i;
2373                 }
2374         }
2375  
2376         /* find average (exclude max abs value) */
2377         for (i = 0; i < nmeasurement; i++) {
2378 -               if ((abs(mp_coeff[i]) < abs(mp_max)) ||
2379 -                   (abs(mp_coeff[i]) < abs(mp_min))) {
2380 -                       mp_avg += mp_coeff[i];
2381 +               if ((abs(mp_coeff[i][0]) < abs(mp_max)) ||
2382 +                   (abs(mp_coeff[i][0]) < abs(mp_min))) {
2383 +                       mp_avg += mp_coeff[i][0];
2384                         mp_count++;
2385                 }
2386         }
2387 @@ -873,7 +875,7 @@ static void ar9003_hw_detect_outlier(int
2388         if (mp_count)
2389                 mp_avg /= mp_count;
2390         else
2391 -               mp_avg = mp_coeff[nmeasurement - 1];
2392 +               mp_avg = mp_coeff[nmeasurement - 1][0];
2393  
2394         /* detect outlier */
2395         if (abs(mp_max - mp_min) > max_delta) {
2396 @@ -882,15 +884,16 @@ static void ar9003_hw_detect_outlier(int
2397                 else
2398                         outlier_idx = min_idx;
2399  
2400 -               mp_coeff[outlier_idx] = mp_avg;
2401 +               mp_coeff[outlier_idx][0] = mp_avg;
2402         }
2403  }
2404  
2405 -static void ar9003_hw_tx_iqcal_load_avg_2_passes(struct ath_hw *ah,
2406 -                                                struct coeff *coeff,
2407 -                                                bool is_reusable)
2408 +static void ar9003_hw_tx_iq_cal_outlier_detection(struct ath_hw *ah,
2409 +                                                 struct coeff *coeff,
2410 +                                                 bool is_reusable)
2411  {
2412         int i, im, nmeasurement;
2413 +       int magnitude, phase;
2414         u32 tx_corr_coeff[MAX_MEASUREMENT][AR9300_MAX_CHAINS];
2415         struct ath9k_hw_cal_data *caldata = ah->caldata;
2416  
2417 @@ -920,21 +923,30 @@ static void ar9003_hw_tx_iqcal_load_avg_
2418                 if (nmeasurement > MAX_MEASUREMENT)
2419                         nmeasurement = MAX_MEASUREMENT;
2420  
2421 -               /* detect outlier only if nmeasurement > 1 */
2422 -               if (nmeasurement > 1) {
2423 -                       /* Detect magnitude outlier */
2424 -                       ar9003_hw_detect_outlier(coeff->mag_coeff[i],
2425 -                                       nmeasurement, MAX_MAG_DELTA);
2426 -
2427 -                       /* Detect phase outlier */
2428 -                       ar9003_hw_detect_outlier(coeff->phs_coeff[i],
2429 -                                       nmeasurement, MAX_PHS_DELTA);
2430 +               /*
2431 +                * Skip normal outlier detection for AR9550.
2432 +                */
2433 +               if (!AR_SREV_9550(ah)) {
2434 +                       /* detect outlier only if nmeasurement > 1 */
2435 +                       if (nmeasurement > 1) {
2436 +                               /* Detect magnitude outlier */
2437 +                               ar9003_hw_detect_outlier(coeff->mag_coeff[i],
2438 +                                                        nmeasurement,
2439 +                                                        MAX_MAG_DELTA);
2440 +
2441 +                               /* Detect phase outlier */
2442 +                               ar9003_hw_detect_outlier(coeff->phs_coeff[i],
2443 +                                                        nmeasurement,
2444 +                                                        MAX_PHS_DELTA);
2445 +                       }
2446                 }
2447  
2448                 for (im = 0; im < nmeasurement; im++) {
2449 +                       magnitude = coeff->mag_coeff[i][im][0];
2450 +                       phase = coeff->phs_coeff[i][im][0];
2451  
2452 -                       coeff->iqc_coeff[0] = (coeff->mag_coeff[i][im] & 0x7f) |
2453 -                               ((coeff->phs_coeff[i][im] & 0x7f) << 7);
2454 +                       coeff->iqc_coeff[0] =
2455 +                               (phase & 0x7f) | ((magnitude & 0x7f) << 7);
2456  
2457                         if ((im % 2) == 0)
2458                                 REG_RMW_FIELD(ah, tx_corr_coeff[im][i],
2459 @@ -991,7 +1003,63 @@ static bool ar9003_hw_tx_iq_cal_run(stru
2460         return true;
2461  }
2462  
2463 -static void ar9003_hw_tx_iq_cal_post_proc(struct ath_hw *ah, bool is_reusable)
2464 +static void __ar955x_tx_iq_cal_sort(struct ath_hw *ah,
2465 +                                   struct coeff *coeff,
2466 +                                   int i, int nmeasurement)
2467 +{
2468 +       struct ath_common *common = ath9k_hw_common(ah);
2469 +       int im, ix, iy, temp;
2470 +
2471 +       for (im = 0; im < nmeasurement; im++) {
2472 +               for (ix = 0; ix < MAXIQCAL - 1; ix++) {
2473 +                       for (iy = ix + 1; iy <= MAXIQCAL - 1; iy++) {
2474 +                               if (coeff->mag_coeff[i][im][iy] <
2475 +                                   coeff->mag_coeff[i][im][ix]) {
2476 +                                       temp = coeff->mag_coeff[i][im][ix];
2477 +                                       coeff->mag_coeff[i][im][ix] =
2478 +                                               coeff->mag_coeff[i][im][iy];
2479 +                                       coeff->mag_coeff[i][im][iy] = temp;
2480 +                               }
2481 +                               if (coeff->phs_coeff[i][im][iy] <
2482 +                                   coeff->phs_coeff[i][im][ix]) {
2483 +                                       temp = coeff->phs_coeff[i][im][ix];
2484 +                                       coeff->phs_coeff[i][im][ix] =
2485 +                                               coeff->phs_coeff[i][im][iy];
2486 +                                       coeff->phs_coeff[i][im][iy] = temp;
2487 +                               }
2488 +                       }
2489 +               }
2490 +               coeff->mag_coeff[i][im][0] = coeff->mag_coeff[i][im][MAXIQCAL / 2];
2491 +               coeff->phs_coeff[i][im][0] = coeff->phs_coeff[i][im][MAXIQCAL / 2];
2492 +
2493 +               ath_dbg(common, CALIBRATE,
2494 +                       "IQCAL: Median [ch%d][gain%d]: mag = %d phase = %d\n",
2495 +                       i, im,
2496 +                       coeff->mag_coeff[i][im][0],
2497 +                       coeff->phs_coeff[i][im][0]);
2498 +       }
2499 +}
2500 +
2501 +static bool ar955x_tx_iq_cal_median(struct ath_hw *ah,
2502 +                                   struct coeff *coeff,
2503 +                                   int iqcal_idx,
2504 +                                   int nmeasurement)
2505 +{
2506 +       int i;
2507 +
2508 +       if ((iqcal_idx + 1) != MAXIQCAL)
2509 +               return false;
2510 +
2511 +       for (i = 0; i < AR9300_MAX_CHAINS; i++) {
2512 +               __ar955x_tx_iq_cal_sort(ah, coeff, i, nmeasurement);
2513 +       }
2514 +
2515 +       return true;
2516 +}
2517 +
2518 +static void ar9003_hw_tx_iq_cal_post_proc(struct ath_hw *ah,
2519 +                                         int iqcal_idx,
2520 +                                         bool is_reusable)
2521  {
2522         struct ath_common *common = ath9k_hw_common(ah);
2523         const u32 txiqcal_status[AR9300_MAX_CHAINS] = {
2524 @@ -1004,10 +1072,11 @@ static void ar9003_hw_tx_iq_cal_post_pro
2525                 AR_PHY_CHAN_INFO_TAB_1,
2526                 AR_PHY_CHAN_INFO_TAB_2,
2527         };
2528 -       struct coeff coeff;
2529 +       static struct coeff coeff;
2530         s32 iq_res[6];
2531         int i, im, j;
2532 -       int nmeasurement;
2533 +       int nmeasurement = 0;
2534 +       bool outlier_detect = true;
2535  
2536         for (i = 0; i < AR9300_MAX_CHAINS; i++) {
2537                 if (!(ah->txchainmask & (1 << i)))
2538 @@ -1065,17 +1134,23 @@ static void ar9003_hw_tx_iq_cal_post_pro
2539                                 goto tx_iqcal_fail;
2540                         }
2541  
2542 -                       coeff.mag_coeff[i][im] = coeff.iqc_coeff[0] & 0x7f;
2543 -                       coeff.phs_coeff[i][im] =
2544 +                       coeff.phs_coeff[i][im][iqcal_idx] =
2545 +                               coeff.iqc_coeff[0] & 0x7f;
2546 +                       coeff.mag_coeff[i][im][iqcal_idx] =
2547                                 (coeff.iqc_coeff[0] >> 7) & 0x7f;
2548  
2549 -                       if (coeff.mag_coeff[i][im] > 63)
2550 -                               coeff.mag_coeff[i][im] -= 128;
2551 -                       if (coeff.phs_coeff[i][im] > 63)
2552 -                               coeff.phs_coeff[i][im] -= 128;
2553 +                       if (coeff.mag_coeff[i][im][iqcal_idx] > 63)
2554 +                               coeff.mag_coeff[i][im][iqcal_idx] -= 128;
2555 +                       if (coeff.phs_coeff[i][im][iqcal_idx] > 63)
2556 +                               coeff.phs_coeff[i][im][iqcal_idx] -= 128;
2557                 }
2558         }
2559 -       ar9003_hw_tx_iqcal_load_avg_2_passes(ah, &coeff, is_reusable);
2560 +
2561 +       if (AR_SREV_9550(ah))
2562 +               outlier_detect = ar955x_tx_iq_cal_median(ah, &coeff,
2563 +                                                        iqcal_idx, nmeasurement);
2564 +       if (outlier_detect)
2565 +               ar9003_hw_tx_iq_cal_outlier_detection(ah, &coeff, is_reusable);
2566  
2567         return;
2568  
2569 @@ -1409,7 +1484,7 @@ skip_tx_iqcal:
2570         }
2571  
2572         if (txiqcal_done)
2573 -               ar9003_hw_tx_iq_cal_post_proc(ah, is_reusable);
2574 +               ar9003_hw_tx_iq_cal_post_proc(ah, 0, is_reusable);
2575         else if (caldata && test_bit(TXIQCAL_DONE, &caldata->cal_flags))
2576                 ar9003_hw_tx_iq_cal_reload(ah);
2577  
2578 @@ -1455,14 +1530,38 @@ skip_tx_iqcal:
2579         return true;
2580  }
2581  
2582 +static bool do_ar9003_agc_cal(struct ath_hw *ah)
2583 +{
2584 +       struct ath_common *common = ath9k_hw_common(ah);
2585 +       bool status;
2586 +
2587 +       REG_WRITE(ah, AR_PHY_AGC_CONTROL,
2588 +                 REG_READ(ah, AR_PHY_AGC_CONTROL) |
2589 +                 AR_PHY_AGC_CONTROL_CAL);
2590 +
2591 +       status = ath9k_hw_wait(ah, AR_PHY_AGC_CONTROL,
2592 +                              AR_PHY_AGC_CONTROL_CAL,
2593 +                              0, AH_WAIT_TIMEOUT);
2594 +       if (!status) {
2595 +               ath_dbg(common, CALIBRATE,
2596 +                       "offset calibration failed to complete in %d ms,"
2597 +                       "noisy environment?\n",
2598 +                       AH_WAIT_TIMEOUT / 1000);
2599 +               return false;
2600 +       }
2601 +
2602 +       return true;
2603 +}
2604 +
2605  static bool ar9003_hw_init_cal_soc(struct ath_hw *ah,
2606                                    struct ath9k_channel *chan)
2607  {
2608         struct ath_common *common = ath9k_hw_common(ah);
2609         struct ath9k_hw_cal_data *caldata = ah->caldata;
2610         bool txiqcal_done = false;
2611 -       bool is_reusable = true, status = true;
2612 +       bool status = true;
2613         bool run_agc_cal = false, sep_iq_cal = false;
2614 +       int i = 0;
2615  
2616         /* Use chip chainmask only for calibration */
2617         ar9003_hw_set_chain_masks(ah, ah->caps.rx_chainmask, ah->caps.tx_chainmask);
2618 @@ -1485,7 +1584,12 @@ static bool ar9003_hw_init_cal_soc(struc
2619          * AGC calibration. Specifically, AR9550 in SoC chips.
2620          */
2621         if (ah->enabled_cals & TX_IQ_ON_AGC_CAL) {
2622 -               txiqcal_done = true;
2623 +               if (REG_READ_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_0,
2624 +                                  AR_PHY_TX_IQCAL_CONTROL_0_ENABLE_TXIQ_CAL)) {
2625 +                               txiqcal_done = true;
2626 +               } else {
2627 +                       txiqcal_done = false;
2628 +               }
2629                 run_agc_cal = true;
2630         } else {
2631                 sep_iq_cal = true;
2632 @@ -1512,27 +1616,37 @@ skip_tx_iqcal:
2633                 if (AR_SREV_9330_11(ah))
2634                         ar9003_hw_manual_peak_cal(ah, 0, IS_CHAN_2GHZ(chan));
2635  
2636 -               /* Calibrate the AGC */
2637 -               REG_WRITE(ah, AR_PHY_AGC_CONTROL,
2638 -                         REG_READ(ah, AR_PHY_AGC_CONTROL) |
2639 -                         AR_PHY_AGC_CONTROL_CAL);
2640 -
2641 -               /* Poll for offset calibration complete */
2642 -               status = ath9k_hw_wait(ah, AR_PHY_AGC_CONTROL,
2643 -                                      AR_PHY_AGC_CONTROL_CAL,
2644 -                                      0, AH_WAIT_TIMEOUT);
2645 -       }
2646 +               /*
2647 +                * For non-AR9550 chips, we just trigger AGC calibration
2648 +                * in the HW, poll for completion and then process
2649 +                * the results.
2650 +                *
2651 +                * For AR955x, we run it multiple times and use
2652 +                * median IQ correction.
2653 +                */
2654 +               if (!AR_SREV_9550(ah)) {
2655 +                       status = do_ar9003_agc_cal(ah);
2656 +                       if (!status)
2657 +                               return false;
2658  
2659 -       if (!status) {
2660 -               ath_dbg(common, CALIBRATE,
2661 -                       "offset calibration failed to complete in %d ms; noisy environment?\n",
2662 -                       AH_WAIT_TIMEOUT / 1000);
2663 -               return false;
2664 +                       if (txiqcal_done)
2665 +                               ar9003_hw_tx_iq_cal_post_proc(ah, 0, false);
2666 +               } else {
2667 +                       if (!txiqcal_done) {
2668 +                               status = do_ar9003_agc_cal(ah);
2669 +                               if (!status)
2670 +                                       return false;
2671 +                       } else {
2672 +                               for (i = 0; i < MAXIQCAL; i++) {
2673 +                                       status = do_ar9003_agc_cal(ah);
2674 +                                       if (!status)
2675 +                                               return false;
2676 +                                       ar9003_hw_tx_iq_cal_post_proc(ah, i, false);
2677 +                               }
2678 +                       }
2679 +               }
2680         }
2681  
2682 -       if (txiqcal_done)
2683 -               ar9003_hw_tx_iq_cal_post_proc(ah, is_reusable);
2684 -
2685         /* Revert chainmask to runtime parameters */
2686         ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
2687  
2688 --- a/drivers/net/wireless/rtl818x/rtl8187/rtl8187.h
2689 +++ b/drivers/net/wireless/rtl818x/rtl8187/rtl8187.h
2690 @@ -15,6 +15,8 @@
2691  #ifndef RTL8187_H
2692  #define RTL8187_H
2693  
2694 +#include <linux/cache.h>
2695 +
2696  #include "rtl818x.h"
2697  #include "leds.h"
2698  
2699 @@ -139,7 +141,10 @@ struct rtl8187_priv {
2700         u8 aifsn[4];
2701         u8 rfkill_mask;
2702         struct {
2703 -               __le64 buf;
2704 +               union {
2705 +                       __le64 buf;
2706 +                       u8 dummy1[L1_CACHE_BYTES];
2707 +               } ____cacheline_aligned;
2708                 struct sk_buff_head queue;
2709         } b_tx_status; /* This queue is used by both -b and non-b devices */
2710         struct mutex io_mutex;
2711 @@ -147,7 +152,8 @@ struct rtl8187_priv {
2712                 u8 bits8;
2713                 __le16 bits16;
2714                 __le32 bits32;
2715 -       } *io_dmabuf;
2716 +               u8 dummy2[L1_CACHE_BYTES];
2717 +       } *io_dmabuf ____cacheline_aligned;
2718         bool rfkill_off;
2719         u16 seqno;
2720  };
2721 --- a/net/mac80211/wme.c
2722 +++ b/net/mac80211/wme.c
2723 @@ -154,6 +154,11 @@ u16 ieee80211_select_queue(struct ieee80
2724                 return IEEE80211_AC_BE;
2725         }
2726  
2727 +       if (skb->protocol == sdata->control_port_protocol) {
2728 +               skb->priority = 7;
2729 +               return ieee80211_downgrade_queue(sdata, skb);
2730 +       }
2731 +
2732         /* use the data classifier to determine what 802.1d tag the
2733          * data frame has */
2734         rcu_read_lock();