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