ath9k: fix a long standing aggregation related tx lockup
[oweals/openwrt.git] / package / kernel / mac80211 / patches / 300-pending_work.patch
1 commit ff354dbdd743e5fe186df8cd17982db19f78231a
2 Author: Felix Fietkau <nbd@openwrt.org>
3 Date:   Wed Jul 23 15:33:26 2014 +0200
4
5     ath9k: fix aggregation session lockup
6     
7     If an aggregation session fails, frames still end up in the driver queue
8     with IEEE80211_TX_CTL_AMPDU set.
9     This causes tx for the affected station/tid to stall, since
10     ath_tx_get_tid_subframe returning packets to send.
11     
12     Fix this by clearing IEEE80211_TX_CTL_AMPDU as long as no aggregation
13     session is running.
14     
15     Cc: stable@vger.kernel.org
16     Reported-by: Antonio Quartulli <antonio@open-mesh.com>
17     Signed-off-by: Felix Fietkau <nbd@openwrt.org>
18
19 commit 38695a6e5a940e6a524523b88a33916b016fb2a1
20 Author: Felix Fietkau <nbd@openwrt.org>
21 Date:   Fri Jul 11 12:06:18 2014 +0200
22
23     mac80211: fix crash on getting sta info with uninitialized rate control
24     
25     If the expected throughput is queried before rate control has been
26     initialized, the minstrel op for it will crash while trying to access
27     the rate table.
28     Check for WLAN_STA_RATE_CONTROL before attempting to use the rate
29     control op.
30     
31     Reported-by: Jean-Pierre Tosoni <jp.tosoni@acksys.fr>
32     Signed-off-by: Felix Fietkau <nbd@openwrt.org>
33
34 commit c0ee7fa4c0da824ccccc172bf175fb1f86540921
35 Author: Felix Fietkau <nbd@openwrt.org>
36 Date:   Wed Jul 16 18:00:31 2014 +0200
37
38     ath9k: fix pending tx frames accounting
39     
40     Packets originally buffered for the regular hardware tx queues can end
41     up being transmitted through the U-APSD queue (via PS-Poll or U-APSD).
42     When packets are dropped due to retransmit failures, the pending frames
43     counter is not always updated properly.
44     Fix this by keeping track of the queue that a frame was accounted for in
45     the ath_frame_info struct, and using that on completion to decide
46     whether the counter should be updated.
47     This fixes some spurious transmit queue hangs.
48     
49     Cc: stable@vger.kernel.org
50     Signed-off-by: Felix Fietkau <nbd@openwrt.org>
51
52 commit edcdf0989410a05a6a4b8438df4010447eaa7d9a
53 Author: Felix Fietkau <nbd@openwrt.org>
54 Date:   Sun Jun 22 13:36:20 2014 +0200
55
56     Revert "cfg80211: Use 5MHz bandwidth by default when checking usable channels"
57     
58     It enables channels that are not supposed to be enabled according to the
59     regulatory rules.
60     
61     This reverts commit 8eca1fb692cc9557f386eddce75c300a3855d11a.
62
63 commit 6e7341074823d2a45b81f2742cbf75f1da790031
64 Author: Rafał Miłecki <zajec5@gmail.com>
65 Date:   Sat May 31 19:40:45 2014 +0200
66
67     b43: disable 5 GHz on G-PHY
68     
69     This fixes regression introduced by adding some G-PHY devices to the
70     list of dual band devices. There is simply no support for 5 GHz on
71     G-PHY devices in b43. It results in:
72     WARNING: CPU: 0 PID: 79 at drivers/net/wireless/b43/phy_g.c:75 b43_gphy_channel_switch+0x125/0x130 [b43]()
73     b43-phy1 ERROR: PHY init: Channel switch to default failed
74     
75     Regression was introduced by the following commit:
76     
77     commit 773cfc508f4d64c14547ff8751b5cbd473124364
78     Author: Rafał Miłecki <zajec5@gmail.com>
79     Date:   Mon May 19 23:18:55 2014 +0200
80     
81         b43: add more devices to the bands database
82     
83     Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
84     Signed-off-by: John W. Linville <linville@tuxdriver.com>
85
86 commit 1186edbef91f15722e5bdf56326ce0abc2935ce7
87 Author: Stanislaw Gruszka <sgruszka@redhat.com>
88 Date:   Tue Jun 10 12:51:06 2014 +0200
89
90     rt2x00: disable TKIP on USB
91     
92     On USB we can not get atomically TKIP key. We have to disable support
93     for TKIP acceleration on USB hardware to avoid bug as showed bellow.
94     
95     [  860.827243] BUG: scheduling while atomic: hostapd/3397/0x00000002
96     <snip>
97     [  860.827280] Call Trace:
98     [  860.827282]  [<ffffffff81682ea6>] dump_stack+0x4d/0x66
99     [  860.827284]  [<ffffffff8167eb9b>] __schedule_bug+0x47/0x55
100     [  860.827285]  [<ffffffff81685bb3>] __schedule+0x733/0x7b0
101     [  860.827287]  [<ffffffff81685c59>] schedule+0x29/0x70
102     [  860.827289]  [<ffffffff81684f8a>] schedule_timeout+0x15a/0x2b0
103     [  860.827291]  [<ffffffff8105ac50>] ? ftrace_raw_event_tick_stop+0xc0/0xc0
104     [  860.827294]  [<ffffffff810c13c2>] ? __module_text_address+0x12/0x70
105     [  860.827296]  [<ffffffff81686823>] wait_for_completion_timeout+0xb3/0x140
106     [  860.827298]  [<ffffffff81080fc0>] ? wake_up_state+0x20/0x20
107     [  860.827301]  [<ffffffff814d5b3d>] usb_start_wait_urb+0x7d/0x150
108     [  860.827303]  [<ffffffff814d5cd5>] usb_control_msg+0xc5/0x110
109     [  860.827305]  [<ffffffffa02fb0c6>] rt2x00usb_vendor_request+0xc6/0x160  [rt2x00usb]
110     [  860.827307]  [<ffffffffa02fb215>] rt2x00usb_vendor_req_buff_lock+0x75/0x150 [rt2x00usb]
111     [  860.827309]  [<ffffffffa02fb393>] rt2x00usb_vendor_request_buff+0xa3/0xe0 [rt2x00usb]
112     [  860.827311]  [<ffffffffa023d1a3>] rt2x00usb_register_multiread+0x33/0x40 [rt2800usb]
113     [  860.827314]  [<ffffffffa05805f9>] rt2800_get_tkip_seq+0x39/0x50  [rt2800lib]
114     [  860.827321]  [<ffffffffa0480f88>] ieee80211_get_key+0x218/0x2a0  [mac80211]
115     [  860.827322]  [<ffffffff815cc68c>] ? __nlmsg_put+0x6c/0x80
116     [  860.827329]  [<ffffffffa051b02e>] nl80211_get_key+0x22e/0x360 [cfg80211]
117     
118     Cc: stable@vger.kernel.org
119     Reported-and-tested-by: Peter Wu <lekensteyn@gmail.com>
120     Reported-and-tested-by: Pontus Fuchs <pontus.fuchs@gmail.com>
121     Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
122     Signed-off-by: John W. Linville <linville@tuxdriver.com>
123
124 commit 5f313a15da92dda80ac4c9a137bc42d7d0b49adf
125 Author: Rafał Miłecki <zajec5@gmail.com>
126 Date:   Thu Jun 12 09:28:38 2014 +0200
127
128     b43: fix frequency reported on G-PHY with /new/ firmware
129
130 commit d3a58df87a2e4c2301ac843604202d290a48440b
131 Author: Avraham Stern <avraham.stern@intel.com>
132 Date:   Thu May 22 12:17:47 2014 +0300
133
134     mac80211: set new interfaces as idle upon init
135     
136     Mark new interfaces as idle to allow operations that require that
137     interfaces are idle to take place. Interface types that are always
138     not idle (like AP interfaces) will be set as not idle when they are
139     assigned a channel context.
140     
141     Signed-off-by: Avraham Stern <avraham.stern@intel.com>
142     Signed-off-by: Emmanuel Grumbach<emmanuel.grumbach@intel.com>
143     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
144
145 commit 923eaf367206e01f22c97aee22300e332d071916
146 Author: Arik Nemtsov <arik@wizery.com>
147 Date:   Mon May 26 14:40:51 2014 +0300
148
149     mac80211: don't check netdev state for debugfs read/write
150     
151     Doing so will lead to an oops for a p2p-dev interface, since it has
152     no netdev.
153     
154     Cc: stable@vger.kernel.org
155     Signed-off-by: Arik Nemtsov <arikx.nemtsov@intel.com>
156     Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
157     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
158
159 commit a9fb54169b197f31aff24c8d6270dd1e56cde395
160 Author: chaitanya.mgit@gmail.com <chaitanya.mgit@gmail.com>
161 Date:   Mon May 26 18:01:44 2014 +0530
162
163     regdb: Generalize the mW to dBm power conversion
164     
165     Generalize the power conversion from mW to dBm
166     using log. This should fix the below compilation
167     error for country NO which adds a new power value
168     2000mW which is not handled earlier.
169     
170      CC [M]  net/wireless/wext-sme.o
171      CC [M]  net/wireless/regdb.o
172     net/wireless/regdb.c:1130:1: error: Unknown undeclared here (not in
173     a function)
174     net/wireless/regdb.c:1130:9: error: expected } before power
175     make[2]: *** [net/wireless/regdb.o] Error 1
176     make[1]: *** [net/wireless] Error 2
177     make: *** [net] Error 2
178     
179     Reported-By:  John Walker <john@x109.net>
180     Signed-off-by: Chaitanya T K <chaitanya.mgit@gmail.com>
181     Acked-by: John W. Linville <linville@tuxdriver.com>
182     [remove unneeded parentheses, fix rounding by using %.0f]
183     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
184
185 commit c7d37a66e345df2fdf1aa7b2c9a6d3d53846ca5b
186 Author: Krzysztof Hałasa <khalasa@piap.pl>
187 Date:   Mon May 26 14:14:46 2014 +0200
188
189     mac80211: fix IBSS join by initializing last_scan_completed
190     
191     Without this fix, freshly rebooted Linux creates a new IBSS
192     instead of joining an existing one. Only when jiffies counter
193     overflows after 5 minutes the IBSS can be successfully joined.
194     
195     Signed-off-by: Krzysztof Hałasa <khalasa@piap.pl>
196     [edit commit message slightly]
197     Cc: stable@vger.kernel.org
198     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
199
200 commit 34171dc0d623be2c1032416bf7d3819f388ed70d
201 Author: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
202 Date:   Sun May 25 15:35:41 2014 +0300
203
204     mac80211: fix virtual monitor interface addition
205     
206     Since the commit below, cfg80211_chandef_dfs_required()
207     will warn if it gets a an NL80211_IFTYPE_UNSPECIFIED iftype
208     as explicitely written in the commit log.
209     When an virtual monitor interface is added, its type is set
210     in ieee80211_sub_if_data.vif.type, but not in
211     ieee80211_sub_if_data.wdev.iftype which is passed to
212     cfg80211_chandef_dfs_required() hence resulting in the
213     following warning:
214     
215     WARNING: CPU: 1 PID: 21265 at net/wireless/chan.c:376 cfg80211_chandef_dfs_required+0xbc/0x130 [cfg80211]()
216     Modules linked in: [...]
217     CPU: 1 PID: 21265 Comm: ifconfig Tainted: G        W  O 3.13.11+ #12
218     Hardware name: Dell Inc. Latitude E6410/0667CC, BIOS A01 03/05/2010
219      0000000000000009 ffff88008f5fdb08 ffffffff817d4219 ffff88008f5fdb50
220      ffff88008f5fdb40 ffffffff8106f57d 0000000000000000 0000000000000000
221      ffff880081062fb8 ffff8800810604e0 0000000000000001 ffff88008f5fdba0
222     Call Trace:
223      [<ffffffff817d4219>] dump_stack+0x4d/0x66
224      [<ffffffff8106f57d>] warn_slowpath_common+0x7d/0xa0
225      [<ffffffff8106f5ec>] warn_slowpath_fmt+0x4c/0x50
226      [<ffffffffa04ea4ec>] cfg80211_chandef_dfs_required+0xbc/0x130 [cfg80211]
227      [<ffffffffa06b1024>] ieee80211_vif_use_channel+0x94/0x500 [mac80211]
228      [<ffffffffa0684e6b>] ieee80211_add_virtual_monitor+0x1ab/0x5c0 [mac80211]
229      [<ffffffffa0686ae5>] ieee80211_do_open+0xe75/0x1580 [mac80211]
230      [<ffffffffa0687259>] ieee80211_open+0x69/0x70 [mac80211]
231     [snip]
232     
233     Fixes: 00ec75fc5a64 ("cfg80211: pass the actual iftype when calling cfg80211_chandef_dfs_required()")
234     Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
235     Acked-by: Luciano Coelho <luciano.coelho@intel.com>
236     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
237
238 commit d93cc72b37b4e2c314e1c499e80e8801907c2fea
239 Author: Michal Kazior <michal.kazior@tieto.com>
240 Date:   Thu Jun 5 14:21:37 2014 +0200
241
242     mac80211: use csa counter offsets instead of csa_active
243     
244     vif->csa_active is protected by mutexes only. This
245     means it is unreliable to depend on it on codeflow
246     in non-sleepable beacon and CSA code. There was no
247     guarantee to have vif->csa_active update be
248     visible before beacons are updated on SMP systems.
249     
250     Using csa counter offsets which are embedded in
251     beacon struct (and thus are protected with single
252     RCU assignment) is much safer.
253     
254     Signed-off-by: Michal Kazior <michal.kazior@tieto.com>
255     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
256
257 commit d2746694fcdef24e0a7a1947d8c70082cde81a26
258 Author: Michal Kazior <michal.kazior@tieto.com>
259 Date:   Thu Jun 5 14:21:36 2014 +0200
260
261     mac80211: move csa counters from sdata to beacon/presp
262     
263     Having csa counters part of beacon and probe_resp
264     structures makes it easier to get rid of possible
265     races between setting a beacon and updating
266     counters on SMP systems by guaranteeing counters
267     are always consistent against given beacon struct.
268     
269     While at it relax WARN_ON into WARN_ON_ONCE to
270     prevent spamming logs and racing.
271     
272     Signed-off-by: Michal Kazior <michal.kazior@tieto.com>
273     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
274
275 commit 5dcb54f3a1a8cd7e0331e773487574f9743615db
276 Author: Janusz Dziedzic <janusz.dziedzic@tieto.com>
277 Date:   Thu Jun 5 08:12:57 2014 +0200
278
279     mac80211: allow tx via monitor iface when DFS
280     
281     Allow send frames using monitor interface
282     when DFS chandef and we pass CAC (beaconing
283     allowed).
284     
285     This fix problem when old kernel and new backports used,
286     in such case hostapd create/use also monitor interface.
287     Before this patch all frames hostapd send using monitor
288     iface were dropped when AP was configured on DFS channel.
289     
290     Signed-off-by: Janusz Dziedzic <janusz.dziedzic@tieto.com>
291     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
292
293 commit 6f09a1beb0d2007572248c986780562219bd206f
294 Author: Johannes Berg <johannes.berg@intel.com>
295 Date:   Wed Jun 4 17:31:56 2014 +0200
296
297     cfg80211: make ethtool the driver's responsibility
298     
299     Currently, cfg80211 tries to implement ethtool, but that doesn't
300     really scale well, with all the different operations. Make the
301     lower-level driver responsible for it, which currently only has
302     an effect on mac80211. It will similarly not scale well at that
303     level though, since mac80211 also has many drivers.
304     
305     To cleanly implement this in mac80211, introduce a new file and
306     move some code to appropriate places.
307     
308     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
309
310 commit 6b0c6f133de8f90caeb1c4a902e6140567c5bf96
311 Author: Johannes Berg <johannes.berg@intel.com>
312 Date:   Wed Jun 4 17:06:23 2014 +0200
313
314     mac80211: remove weak WEP IV accounting
315     
316     Since WEP is practically dead, there seems very little
317     point in keeping WEP weak IV accounting.
318     
319     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
320
321 commit aecdc89fb4664c76baa4bbd46008f220532309ff
322 Author: Luciano Coelho <luciano.coelho@intel.com>
323 Date:   Fri May 23 11:04:50 2014 +0300
324
325     ath9k/ath10k: remove unnecessary channel_switch_beacon callbacks
326     
327     The channel_switch_beacon callback is optional, so it doesn't have to
328     be defined if it's not going to do anything useful with it.  Both
329     ath9k and ath10k define the callback and just returns.  This commit
330     removes them.
331     
332     Cc: Michal Kazior <michal.kazior@tieto.com>
333     Signed-off-by: Luciano Coelho <luciano.coelho@intel.com>
334     Signed-off-by: Kalle Valo <kvalo@qca.qualcomm.com>
335
336 commit 60ccc107c9b9fb732fdee1f76bb2dad44f0e1798
337 Author: Rajkumar Manoharan <rmanohar@qti.qualcomm.com>
338 Date:   Tue May 27 16:58:02 2014 +0530
339
340     ath9k: Fix deadlock while updating p2p beacon timer
341     
342     pm_lock is taken twice while syncing HW TSF of p2p vif.
343     Fix this by taking the lock at caller side.
344     
345     Cc: Felix Fietkau <nbd@openwrt.org>
346     Signed-off-by: Rajkumar Manoharan <rmanohar@qti.qualcomm.com>
347     Signed-off-by: John W. Linville <linville@tuxdriver.com>
348
349 commit f3831a4e3903dbc1a57d5df56deb6a143fd001bc
350 Author: Stanislaw Gruszka <sgruszka@redhat.com>
351 Date:   Thu Jun 5 13:52:27 2014 +0200
352
353     rt2x00: do not initialize BCN_OFFSET registers
354     
355     We setup BCN_OFFSET{0,1} registers dynamically, don't have to
356     initialize them.
357     
358     Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
359
360 commit e5c58ca7a48d4c82f282749a978052c47fd95998
361 Author: Stanislaw Gruszka <sgruszka@redhat.com>
362 Date:   Thu Jun 5 13:52:26 2014 +0200
363
364     rt2x00: change order when stop beaconing
365     
366     When no beaconing is needed, first stop beacon queue (disable beaconing
367     globally) to avoid possible sending of not prepared beacon on short
368     period after clearing beacon and before stop of BCN queue.
369     
370     Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
371
372 commit 382c1b9e03f52d0cd741ef1d942cad0f649f0744
373 Author: Stanislaw Gruszka <sgruszka@redhat.com>
374 Date:   Thu Jun 5 13:52:25 2014 +0200
375
376     rt2x00: change default MAC_BSSID_DW1_BSS_BCN_NUM
377     
378     We setup MAC_BSSID_DW1_BSS_BCN_NUM dynamically when numbers of active
379     beacons increase. Change default to 0 to tell hardware that we want to
380     send only one beacon as default.
381     
382     Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
383
384 commit 3b400571dd033e46fa7e76c5bb92a3ce8198afa9
385 Author: Stanislaw Gruszka <sgruszka@redhat.com>
386 Date:   Thu Jun 5 13:52:24 2014 +0200
387
388     rt2x00: change beaconing setup on RT2800
389     
390     As reported by Matthias, on 5572 chip, even if we clear up TXWI
391     of corresponding beacon, hardware still try to send it or do other
392     action that increase power consumption peak up to 1A.
393     
394     To avoid the issue, setup beaconing dynamically by configuring offsets
395     of currently active beacons and MAC_BSSID_DW1_BSS_BCN_NUM variable,
396     which limit number of beacons that hardware will try to send.
397     
398     Reported-by: Matthias Fend <Matthias.Fend@wolfvision.net>
399     Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
400
401 commit 916e591b2cc41f7e572992175ca56d866d7bc958
402 Author: Stanislaw Gruszka <sgruszka@redhat.com>
403 Date:   Thu Jun 5 13:52:23 2014 +0200
404
405     rt2x00: change beaconing locking
406     
407     This patch is needed for further changes to keep global variables
408     consistent when changing beaconing on diffrent vif's.
409     
410     Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
411
412 commit 930b0dffd1731f3f418f9132faea720a23b7af61
413 Author: Johannes Berg <johannes.berg@intel.com>
414 Date:   Tue Jun 3 11:18:47 2014 +0200
415
416     mac80211: fix station/driver powersave race
417     
418     It is currently possible to have a race due to the station PS
419     unblock work like this:
420      * station goes to sleep with frames buffered in the driver
421      * driver blocks wakeup
422      * station wakes up again
423      * driver flushes/returns frames, and unblocks, which schedules
424        the unblock work
425      * unblock work starts to run, and checks that the station is
426        awake (i.e. that the WLAN_STA_PS_STA flag isn't set)
427      * we process a received frame with PM=1, setting the flag again
428      * ieee80211_sta_ps_deliver_wakeup() runs, delivering all frames
429        to the driver, and then clearing the WLAN_STA_PS_DRIVER and
430        WLAN_STA_PS_STA flags
431     
432     In this scenario, mac80211 will think that the station is awake,
433     while it really is asleep, and any TX'ed frames should be filtered
434     by the device (it will know that the station is sleeping) but then
435     passed to mac80211 again, which will not buffer it either as it
436     thinks the station is awake, and eventually the packets will be
437     dropped.
438     
439     Fix this by moving the clearing of the flags to exactly where we
440     learn about the situation. This creates a problem of reordering,
441     so introduce another flag indicating that delivery is being done,
442     this new flag also queues frames and is cleared only while the
443     spinlock is held (which the queuing code also holds) so that any
444     concurrent delivery/TX is handled correctly.
445     
446     Reported-by: Andrei Otcheretianski <andrei.otcheretianski@intel.com>
447     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
448
449 commit 6df35206bc6c1c6aad1d8077df5786b4a7f77873
450 Author: Felix Fietkau <nbd@openwrt.org>
451 Date:   Fri May 23 19:58:14 2014 +0200
452
453     mac80211: reduce packet loss notifications under load
454     
455     During strong signal fluctuations under high throughput, few consecutive
456     failed A-MPDU transmissions can easily trigger packet loss notification,
457     and thus (in AP mode) client disconnection.
458     
459     Reduce the number of false positives by checking the A-MPDU status flag
460     and treating a failed A-MPDU as a single packet.
461     
462     Signed-off-by: Felix Fietkau <nbd@openwrt.org>
463
464 commit 7b7843a36fbcc568834404c7430ff895d8502131
465 Author: Felix Fietkau <nbd@openwrt.org>
466 Date:   Fri May 23 19:26:32 2014 +0200
467
468     mac80211: fix a memory leak on sta rate selection table
469     
470     Cc: stable@vger.kernel.org
471     Reported-by: Christophe Prévotaux <cprevotaux@nltinc.com>
472     Signed-off-by: Felix Fietkau <nbd@openwrt.org>
473
474 commit 96892d6aa0a153423070addf3070bc79578b3897
475 Author: Felix Fietkau <nbd@openwrt.org>
476 Date:   Mon May 19 21:20:49 2014 +0200
477
478     ath9k: avoid passing buffers to the hardware during flush
479     
480     The commit "ath9k: fix possible hang on flush" changed the receive code
481     to always link rx descriptors of processed frames, even when flushing.
482     In some cases, this leads to flushed rx buffers being passed to the
483     hardware while rx is already stopped.
484     
485     Signed-off-by: Felix Fietkau <nbd@openwrt.org>
486
487 --- a/drivers/net/wireless/ath/ath9k/recv.c
488 +++ b/drivers/net/wireless/ath/ath9k/recv.c
489 @@ -34,7 +34,8 @@ static inline bool ath9k_check_auto_slee
490   * buffer (or rx fifo). This can incorrectly acknowledge packets
491   * to a sender if last desc is self-linked.
492   */
493 -static void ath_rx_buf_link(struct ath_softc *sc, struct ath_rxbuf *bf)
494 +static void ath_rx_buf_link(struct ath_softc *sc, struct ath_rxbuf *bf,
495 +                           bool flush)
496  {
497         struct ath_hw *ah = sc->sc_ah;
498         struct ath_common *common = ath9k_hw_common(ah);
499 @@ -59,18 +60,19 @@ static void ath_rx_buf_link(struct ath_s
500                              common->rx_bufsize,
501                              0);
502  
503 -       if (sc->rx.rxlink == NULL)
504 -               ath9k_hw_putrxbuf(ah, bf->bf_daddr);
505 -       else
506 +       if (sc->rx.rxlink)
507                 *sc->rx.rxlink = bf->bf_daddr;
508 +       else if (!flush)
509 +               ath9k_hw_putrxbuf(ah, bf->bf_daddr);
510  
511         sc->rx.rxlink = &ds->ds_link;
512  }
513  
514 -static void ath_rx_buf_relink(struct ath_softc *sc, struct ath_rxbuf *bf)
515 +static void ath_rx_buf_relink(struct ath_softc *sc, struct ath_rxbuf *bf,
516 +                             bool flush)
517  {
518         if (sc->rx.buf_hold)
519 -               ath_rx_buf_link(sc, sc->rx.buf_hold);
520 +               ath_rx_buf_link(sc, sc->rx.buf_hold, flush);
521  
522         sc->rx.buf_hold = bf;
523  }
524 @@ -442,7 +444,7 @@ int ath_startrecv(struct ath_softc *sc)
525         sc->rx.buf_hold = NULL;
526         sc->rx.rxlink = NULL;
527         list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) {
528 -               ath_rx_buf_link(sc, bf);
529 +               ath_rx_buf_link(sc, bf, false);
530         }
531  
532         /* We could have deleted elements so the list may be empty now */
533 @@ -1118,12 +1120,12 @@ requeue_drop_frag:
534  requeue:
535                 list_add_tail(&bf->list, &sc->rx.rxbuf);
536  
537 -               if (edma) {
538 -                       ath_rx_edma_buf_link(sc, qtype);
539 -               } else {
540 -                       ath_rx_buf_relink(sc, bf);
541 +               if (!edma) {
542 +                       ath_rx_buf_relink(sc, bf, flush);
543                         if (!flush)
544                                 ath9k_hw_rxena(ah);
545 +               } else if (!flush) {
546 +                       ath_rx_edma_buf_link(sc, qtype);
547                 }
548  
549                 if (!budget--)
550 --- a/net/mac80211/sta_info.c
551 +++ b/net/mac80211/sta_info.c
552 @@ -100,7 +100,8 @@ static void __cleanup_single_sta(struct 
553         struct ps_data *ps;
554  
555         if (test_sta_flag(sta, WLAN_STA_PS_STA) ||
556 -           test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
557 +           test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
558 +           test_sta_flag(sta, WLAN_STA_PS_DELIVER)) {
559                 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
560                     sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
561                         ps = &sdata->bss->ps;
562 @@ -111,6 +112,7 @@ static void __cleanup_single_sta(struct 
563  
564                 clear_sta_flag(sta, WLAN_STA_PS_STA);
565                 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
566 +               clear_sta_flag(sta, WLAN_STA_PS_DELIVER);
567  
568                 atomic_dec(&ps->num_sta_ps);
569                 sta_info_recalc_tim(sta);
570 @@ -125,7 +127,7 @@ static void __cleanup_single_sta(struct 
571         if (ieee80211_vif_is_mesh(&sdata->vif))
572                 mesh_sta_cleanup(sta);
573  
574 -       cancel_work_sync(&sta->drv_unblock_wk);
575 +       cancel_work_sync(&sta->drv_deliver_wk);
576  
577         /*
578          * Destroy aggregation state here. It would be nice to wait for the
579 @@ -227,6 +229,7 @@ struct sta_info *sta_info_get_by_idx(str
580   */
581  void sta_info_free(struct ieee80211_local *local, struct sta_info *sta)
582  {
583 +       struct ieee80211_sta_rates *rates;
584         int i;
585  
586         if (sta->rate_ctrl)
587 @@ -238,6 +241,10 @@ void sta_info_free(struct ieee80211_loca
588                 kfree(sta->tx_lat);
589         }
590  
591 +       rates = rcu_dereference_protected(sta->sta.rates, true);
592 +       if (rates)
593 +               kfree(rates);
594 +
595         sta_dbg(sta->sdata, "Destroyed STA %pM\n", sta->sta.addr);
596  
597         kfree(sta);
598 @@ -252,33 +259,23 @@ static void sta_info_hash_add(struct iee
599         rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)], sta);
600  }
601  
602 -static void sta_unblock(struct work_struct *wk)
603 +static void sta_deliver_ps_frames(struct work_struct *wk)
604  {
605         struct sta_info *sta;
606  
607 -       sta = container_of(wk, struct sta_info, drv_unblock_wk);
608 +       sta = container_of(wk, struct sta_info, drv_deliver_wk);
609  
610         if (sta->dead)
611                 return;
612  
613 -       if (!test_sta_flag(sta, WLAN_STA_PS_STA)) {
614 -               local_bh_disable();
615 +       local_bh_disable();
616 +       if (!test_sta_flag(sta, WLAN_STA_PS_STA))
617                 ieee80211_sta_ps_deliver_wakeup(sta);
618 -               local_bh_enable();
619 -       } else if (test_and_clear_sta_flag(sta, WLAN_STA_PSPOLL)) {
620 -               clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
621 -
622 -               local_bh_disable();
623 +       else if (test_and_clear_sta_flag(sta, WLAN_STA_PSPOLL))
624                 ieee80211_sta_ps_deliver_poll_response(sta);
625 -               local_bh_enable();
626 -       } else if (test_and_clear_sta_flag(sta, WLAN_STA_UAPSD)) {
627 -               clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
628 -
629 -               local_bh_disable();
630 +       else if (test_and_clear_sta_flag(sta, WLAN_STA_UAPSD))
631                 ieee80211_sta_ps_deliver_uapsd(sta);
632 -               local_bh_enable();
633 -       } else
634 -               clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
635 +       local_bh_enable();
636  }
637  
638  static int sta_prepare_rate_control(struct ieee80211_local *local,
639 @@ -340,7 +337,7 @@ struct sta_info *sta_info_alloc(struct i
640  
641         spin_lock_init(&sta->lock);
642         spin_lock_init(&sta->ps_lock);
643 -       INIT_WORK(&sta->drv_unblock_wk, sta_unblock);
644 +       INIT_WORK(&sta->drv_deliver_wk, sta_deliver_ps_frames);
645         INIT_WORK(&sta->ampdu_mlme.work, ieee80211_ba_session_work);
646         mutex_init(&sta->ampdu_mlme.mtx);
647  #ifdef CPTCFG_MAC80211_MESH
648 @@ -1140,8 +1137,15 @@ void ieee80211_sta_ps_deliver_wakeup(str
649         }
650  
651         ieee80211_add_pending_skbs(local, &pending);
652 -       clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
653 -       clear_sta_flag(sta, WLAN_STA_PS_STA);
654 +
655 +       /* now we're no longer in the deliver code */
656 +       clear_sta_flag(sta, WLAN_STA_PS_DELIVER);
657 +
658 +       /* The station might have polled and then woken up before we responded,
659 +        * so clear these flags now to avoid them sticking around.
660 +        */
661 +       clear_sta_flag(sta, WLAN_STA_PSPOLL);
662 +       clear_sta_flag(sta, WLAN_STA_UAPSD);
663         spin_unlock(&sta->ps_lock);
664  
665         atomic_dec(&ps->num_sta_ps);
666 @@ -1542,10 +1546,26 @@ void ieee80211_sta_block_awake(struct ie
667  
668         trace_api_sta_block_awake(sta->local, pubsta, block);
669  
670 -       if (block)
671 +       if (block) {
672                 set_sta_flag(sta, WLAN_STA_PS_DRIVER);
673 -       else if (test_sta_flag(sta, WLAN_STA_PS_DRIVER))
674 -               ieee80211_queue_work(hw, &sta->drv_unblock_wk);
675 +               return;
676 +       }
677 +
678 +       if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
679 +               return;
680 +
681 +       if (!test_sta_flag(sta, WLAN_STA_PS_STA)) {
682 +               set_sta_flag(sta, WLAN_STA_PS_DELIVER);
683 +               clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
684 +               ieee80211_queue_work(hw, &sta->drv_deliver_wk);
685 +       } else if (test_sta_flag(sta, WLAN_STA_PSPOLL) ||
686 +                  test_sta_flag(sta, WLAN_STA_UAPSD)) {
687 +               /* must be asleep in this case */
688 +               clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
689 +               ieee80211_queue_work(hw, &sta->drv_deliver_wk);
690 +       } else {
691 +               clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
692 +       }
693  }
694  EXPORT_SYMBOL(ieee80211_sta_block_awake);
695  
696 @@ -1703,3 +1723,140 @@ u8 sta_info_tx_streams(struct sta_info *
697         return ((ht_cap->mcs.tx_params & IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
698                         >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT) + 1;
699  }
700 +
701 +void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
702 +{
703 +       struct ieee80211_sub_if_data *sdata = sta->sdata;
704 +       struct ieee80211_local *local = sdata->local;
705 +       struct rate_control_ref *ref = NULL;
706 +       struct timespec uptime;
707 +       u64 packets = 0;
708 +       u32 thr = 0;
709 +       int i, ac;
710 +
711 +       if (test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
712 +               ref = local->rate_ctrl;
713 +
714 +       sinfo->generation = sdata->local->sta_generation;
715 +
716 +       sinfo->filled = STATION_INFO_INACTIVE_TIME |
717 +                       STATION_INFO_RX_BYTES64 |
718 +                       STATION_INFO_TX_BYTES64 |
719 +                       STATION_INFO_RX_PACKETS |
720 +                       STATION_INFO_TX_PACKETS |
721 +                       STATION_INFO_TX_RETRIES |
722 +                       STATION_INFO_TX_FAILED |
723 +                       STATION_INFO_TX_BITRATE |
724 +                       STATION_INFO_RX_BITRATE |
725 +                       STATION_INFO_RX_DROP_MISC |
726 +                       STATION_INFO_BSS_PARAM |
727 +                       STATION_INFO_CONNECTED_TIME |
728 +                       STATION_INFO_STA_FLAGS |
729 +                       STATION_INFO_BEACON_LOSS_COUNT;
730 +
731 +       do_posix_clock_monotonic_gettime(&uptime);
732 +       sinfo->connected_time = uptime.tv_sec - sta->last_connected;
733 +
734 +       sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
735 +       sinfo->tx_bytes = 0;
736 +       for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
737 +               sinfo->tx_bytes += sta->tx_bytes[ac];
738 +               packets += sta->tx_packets[ac];
739 +       }
740 +       sinfo->tx_packets = packets;
741 +       sinfo->rx_bytes = sta->rx_bytes;
742 +       sinfo->rx_packets = sta->rx_packets;
743 +       sinfo->tx_retries = sta->tx_retry_count;
744 +       sinfo->tx_failed = sta->tx_retry_failed;
745 +       sinfo->rx_dropped_misc = sta->rx_dropped;
746 +       sinfo->beacon_loss_count = sta->beacon_loss_count;
747 +
748 +       if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
749 +           (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
750 +               sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
751 +               if (!local->ops->get_rssi ||
752 +                   drv_get_rssi(local, sdata, &sta->sta, &sinfo->signal))
753 +                       sinfo->signal = (s8)sta->last_signal;
754 +               sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
755 +       }
756 +       if (sta->chains) {
757 +               sinfo->filled |= STATION_INFO_CHAIN_SIGNAL |
758 +                                STATION_INFO_CHAIN_SIGNAL_AVG;
759 +
760 +               sinfo->chains = sta->chains;
761 +               for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
762 +                       sinfo->chain_signal[i] = sta->chain_signal_last[i];
763 +                       sinfo->chain_signal_avg[i] =
764 +                               (s8) -ewma_read(&sta->chain_signal_avg[i]);
765 +               }
766 +       }
767 +
768 +       sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
769 +       sta_set_rate_info_rx(sta, &sinfo->rxrate);
770 +
771 +       if (ieee80211_vif_is_mesh(&sdata->vif)) {
772 +#ifdef CPTCFG_MAC80211_MESH
773 +               sinfo->filled |= STATION_INFO_LLID |
774 +                                STATION_INFO_PLID |
775 +                                STATION_INFO_PLINK_STATE |
776 +                                STATION_INFO_LOCAL_PM |
777 +                                STATION_INFO_PEER_PM |
778 +                                STATION_INFO_NONPEER_PM;
779 +
780 +               sinfo->llid = sta->llid;
781 +               sinfo->plid = sta->plid;
782 +               sinfo->plink_state = sta->plink_state;
783 +               if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
784 +                       sinfo->filled |= STATION_INFO_T_OFFSET;
785 +                       sinfo->t_offset = sta->t_offset;
786 +               }
787 +               sinfo->local_pm = sta->local_pm;
788 +               sinfo->peer_pm = sta->peer_pm;
789 +               sinfo->nonpeer_pm = sta->nonpeer_pm;
790 +#endif
791 +       }
792 +
793 +       sinfo->bss_param.flags = 0;
794 +       if (sdata->vif.bss_conf.use_cts_prot)
795 +               sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
796 +       if (sdata->vif.bss_conf.use_short_preamble)
797 +               sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
798 +       if (sdata->vif.bss_conf.use_short_slot)
799 +               sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
800 +       sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
801 +       sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
802 +
803 +       sinfo->sta_flags.set = 0;
804 +       sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
805 +                               BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
806 +                               BIT(NL80211_STA_FLAG_WME) |
807 +                               BIT(NL80211_STA_FLAG_MFP) |
808 +                               BIT(NL80211_STA_FLAG_AUTHENTICATED) |
809 +                               BIT(NL80211_STA_FLAG_ASSOCIATED) |
810 +                               BIT(NL80211_STA_FLAG_TDLS_PEER);
811 +       if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
812 +               sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
813 +       if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
814 +               sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
815 +       if (test_sta_flag(sta, WLAN_STA_WME))
816 +               sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
817 +       if (test_sta_flag(sta, WLAN_STA_MFP))
818 +               sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
819 +       if (test_sta_flag(sta, WLAN_STA_AUTH))
820 +               sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
821 +       if (test_sta_flag(sta, WLAN_STA_ASSOC))
822 +               sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
823 +       if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
824 +               sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
825 +
826 +       /* check if the driver has a SW RC implementation */
827 +       if (ref && ref->ops->get_expected_throughput)
828 +               thr = ref->ops->get_expected_throughput(sta->rate_ctrl_priv);
829 +       else
830 +               thr = drv_get_expected_throughput(local, &sta->sta);
831 +
832 +       if (thr != 0) {
833 +               sinfo->filled |= STATION_INFO_EXPECTED_THROUGHPUT;
834 +               sinfo->expected_throughput = thr;
835 +       }
836 +}
837 --- a/net/mac80211/status.c
838 +++ b/net/mac80211/status.c
839 @@ -541,6 +541,23 @@ static void ieee80211_tx_latency_end_msr
840   */
841  #define STA_LOST_PKT_THRESHOLD 50
842  
843 +static void ieee80211_lost_packet(struct sta_info *sta, struct sk_buff *skb)
844 +{
845 +       struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
846 +
847 +       /* This packet was aggregated but doesn't carry status info */
848 +       if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
849 +           !(info->flags & IEEE80211_TX_STAT_AMPDU))
850 +               return;
851 +
852 +       if (++sta->lost_packets < STA_LOST_PKT_THRESHOLD)
853 +               return;
854 +
855 +       cfg80211_cqm_pktloss_notify(sta->sdata->dev, sta->sta.addr,
856 +                                   sta->lost_packets, GFP_ATOMIC);
857 +       sta->lost_packets = 0;
858 +}
859 +
860  void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
861  {
862         struct sk_buff *skb2;
863 @@ -680,12 +697,8 @@ void ieee80211_tx_status(struct ieee8021
864                         if (info->flags & IEEE80211_TX_STAT_ACK) {
865                                 if (sta->lost_packets)
866                                         sta->lost_packets = 0;
867 -                       } else if (++sta->lost_packets >= STA_LOST_PKT_THRESHOLD) {
868 -                               cfg80211_cqm_pktloss_notify(sta->sdata->dev,
869 -                                                           sta->sta.addr,
870 -                                                           sta->lost_packets,
871 -                                                           GFP_ATOMIC);
872 -                               sta->lost_packets = 0;
873 +                       } else {
874 +                               ieee80211_lost_packet(sta, skb);
875                         }
876                 }
877  
878 --- a/net/mac80211/rx.c
879 +++ b/net/mac80211/rx.c
880 @@ -1107,6 +1107,8 @@ static void sta_ps_end(struct sta_info *
881                 return;
882         }
883  
884 +       set_sta_flag(sta, WLAN_STA_PS_DELIVER);
885 +       clear_sta_flag(sta, WLAN_STA_PS_STA);
886         ieee80211_sta_ps_deliver_wakeup(sta);
887  }
888  
889 --- a/net/mac80211/sta_info.h
890 +++ b/net/mac80211/sta_info.h
891 @@ -82,6 +82,7 @@ enum ieee80211_sta_info_flags {
892         WLAN_STA_TOFFSET_KNOWN,
893         WLAN_STA_MPSP_OWNER,
894         WLAN_STA_MPSP_RECIPIENT,
895 +       WLAN_STA_PS_DELIVER,
896  };
897  
898  #define ADDBA_RESP_INTERVAL HZ
899 @@ -265,7 +266,7 @@ struct ieee80211_tx_latency_stat {
900   * @last_rx_rate_vht_nss: rx status nss of last data packet
901   * @lock: used for locking all fields that require locking, see comments
902   *     in the header file.
903 - * @drv_unblock_wk: used for driver PS unblocking
904 + * @drv_deliver_wk: used for delivering frames after driver PS unblocking
905   * @listen_interval: listen interval of this station, when we're acting as AP
906   * @_flags: STA flags, see &enum ieee80211_sta_info_flags, do not use directly
907   * @ps_lock: used for powersave (when mac80211 is the AP) related locking
908 @@ -278,7 +279,6 @@ struct ieee80211_tx_latency_stat {
909   * @driver_buffered_tids: bitmap of TIDs the driver has data buffered on
910   * @rx_packets: Number of MSDUs received from this STA
911   * @rx_bytes: Number of bytes received from this STA
912 - * @wep_weak_iv_count: number of weak WEP IVs received from this station
913   * @last_rx: time (in jiffies) when last frame was received from this STA
914   * @last_connected: time (in seconds) when a station got connected
915   * @num_duplicates: number of duplicate frames received from this STA
916 @@ -345,7 +345,7 @@ struct sta_info {
917         void *rate_ctrl_priv;
918         spinlock_t lock;
919  
920 -       struct work_struct drv_unblock_wk;
921 +       struct work_struct drv_deliver_wk;
922  
923         u16 listen_interval;
924  
925 @@ -367,7 +367,6 @@ struct sta_info {
926         /* Updated from RX path only, no locking requirements */
927         unsigned long rx_packets;
928         u64 rx_bytes;
929 -       unsigned long wep_weak_iv_count;
930         unsigned long last_rx;
931         long last_connected;
932         unsigned long num_duplicates;
933 @@ -628,6 +627,8 @@ void sta_set_rate_info_tx(struct sta_inf
934                           struct rate_info *rinfo);
935  void sta_set_rate_info_rx(struct sta_info *sta,
936                           struct rate_info *rinfo);
937 +void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo);
938 +
939  void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
940                           unsigned long exp_time);
941  u8 sta_info_tx_streams(struct sta_info *sta);
942 --- a/net/mac80211/tx.c
943 +++ b/net/mac80211/tx.c
944 @@ -469,7 +469,8 @@ ieee80211_tx_h_unicast_ps_buf(struct iee
945                 return TX_CONTINUE;
946  
947         if (unlikely((test_sta_flag(sta, WLAN_STA_PS_STA) ||
948 -                     test_sta_flag(sta, WLAN_STA_PS_DRIVER)) &&
949 +                     test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
950 +                     test_sta_flag(sta, WLAN_STA_PS_DELIVER)) &&
951                      !(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER))) {
952                 int ac = skb_get_queue_mapping(tx->skb);
953  
954 @@ -486,7 +487,8 @@ ieee80211_tx_h_unicast_ps_buf(struct iee
955                  * ahead and Tx the packet.
956                  */
957                 if (!test_sta_flag(sta, WLAN_STA_PS_STA) &&
958 -                   !test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
959 +                   !test_sta_flag(sta, WLAN_STA_PS_DRIVER) &&
960 +                   !test_sta_flag(sta, WLAN_STA_PS_DELIVER)) {
961                         spin_unlock(&sta->ps_lock);
962                         return TX_CONTINUE;
963                 }
964 @@ -1618,12 +1620,12 @@ netdev_tx_t ieee80211_monitor_start_xmit
965  {
966         struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
967         struct ieee80211_chanctx_conf *chanctx_conf;
968 -       struct ieee80211_channel *chan;
969         struct ieee80211_radiotap_header *prthdr =
970                 (struct ieee80211_radiotap_header *)skb->data;
971         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
972         struct ieee80211_hdr *hdr;
973         struct ieee80211_sub_if_data *tmp_sdata, *sdata;
974 +       struct cfg80211_chan_def *chandef;
975         u16 len_rthdr;
976         int hdrlen;
977  
978 @@ -1721,9 +1723,9 @@ netdev_tx_t ieee80211_monitor_start_xmit
979         }
980  
981         if (chanctx_conf)
982 -               chan = chanctx_conf->def.chan;
983 +               chandef = &chanctx_conf->def;
984         else if (!local->use_chanctx)
985 -               chan = local->_oper_chandef.chan;
986 +               chandef = &local->_oper_chandef;
987         else
988                 goto fail_rcu;
989  
990 @@ -1743,10 +1745,11 @@ netdev_tx_t ieee80211_monitor_start_xmit
991          * radar detection by itself. We can do that later by adding a
992          * monitor flag interfaces used for AP support.
993          */
994 -       if ((chan->flags & (IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_RADAR)))
995 +       if (!cfg80211_reg_can_beacon(local->hw.wiphy, chandef,
996 +                                    sdata->vif.type))
997                 goto fail_rcu;
998  
999 -       ieee80211_xmit(sdata, skb, chan->band);
1000 +       ieee80211_xmit(sdata, skb, chandef->chan->band);
1001         rcu_read_unlock();
1002  
1003         return NETDEV_TX_OK;
1004 @@ -2425,7 +2428,7 @@ static void ieee80211_set_csa(struct iee
1005         u8 *beacon_data;
1006         size_t beacon_data_len;
1007         int i;
1008 -       u8 count = sdata->csa_current_counter;
1009 +       u8 count = beacon->csa_current_counter;
1010  
1011         switch (sdata->vif.type) {
1012         case NL80211_IFTYPE_AP:
1013 @@ -2444,46 +2447,54 @@ static void ieee80211_set_csa(struct iee
1014                 return;
1015         }
1016  
1017 +       rcu_read_lock();
1018         for (i = 0; i < IEEE80211_MAX_CSA_COUNTERS_NUM; ++i) {
1019 -               u16 counter_offset_beacon =
1020 -                       sdata->csa_counter_offset_beacon[i];
1021 -               u16 counter_offset_presp = sdata->csa_counter_offset_presp[i];
1022 -
1023 -               if (counter_offset_beacon) {
1024 -                       if (WARN_ON(counter_offset_beacon >= beacon_data_len))
1025 -                               return;
1026 -
1027 -                       beacon_data[counter_offset_beacon] = count;
1028 -               }
1029 -
1030 -               if (sdata->vif.type == NL80211_IFTYPE_AP &&
1031 -                   counter_offset_presp) {
1032 -                       rcu_read_lock();
1033 -                       resp = rcu_dereference(sdata->u.ap.probe_resp);
1034 +               resp = rcu_dereference(sdata->u.ap.probe_resp);
1035  
1036 -                       /* If nl80211 accepted the offset, this should
1037 -                        * not happen.
1038 -                        */
1039 -                       if (WARN_ON(!resp)) {
1040 +               if (beacon->csa_counter_offsets[i]) {
1041 +                       if (WARN_ON_ONCE(beacon->csa_counter_offsets[i] >=
1042 +                                        beacon_data_len)) {
1043                                 rcu_read_unlock();
1044                                 return;
1045                         }
1046 -                       resp->data[counter_offset_presp] = count;
1047 -                       rcu_read_unlock();
1048 +
1049 +                       beacon_data[beacon->csa_counter_offsets[i]] = count;
1050                 }
1051 +
1052 +               if (sdata->vif.type == NL80211_IFTYPE_AP && resp &&
1053 +                   resp->csa_counter_offsets)
1054 +                       resp->data[resp->csa_counter_offsets[i]] = count;
1055         }
1056 +       rcu_read_unlock();
1057  }
1058  
1059  u8 ieee80211_csa_update_counter(struct ieee80211_vif *vif)
1060  {
1061         struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1062 +       struct beacon_data *beacon = NULL;
1063 +       u8 count = 0;
1064 +
1065 +       rcu_read_lock();
1066 +
1067 +       if (sdata->vif.type == NL80211_IFTYPE_AP)
1068 +               beacon = rcu_dereference(sdata->u.ap.beacon);
1069 +       else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
1070 +               beacon = rcu_dereference(sdata->u.ibss.presp);
1071 +       else if (ieee80211_vif_is_mesh(&sdata->vif))
1072 +               beacon = rcu_dereference(sdata->u.mesh.beacon);
1073 +
1074 +       if (!beacon)
1075 +               goto unlock;
1076  
1077 -       sdata->csa_current_counter--;
1078 +       beacon->csa_current_counter--;
1079  
1080         /* the counter should never reach 0 */
1081 -       WARN_ON(!sdata->csa_current_counter);
1082 +       WARN_ON_ONCE(!beacon->csa_current_counter);
1083 +       count = beacon->csa_current_counter;
1084  
1085 -       return sdata->csa_current_counter;
1086 +unlock:
1087 +       rcu_read_unlock();
1088 +       return count;
1089  }
1090  EXPORT_SYMBOL(ieee80211_csa_update_counter);
1091  
1092 @@ -2493,7 +2504,6 @@ bool ieee80211_csa_is_complete(struct ie
1093         struct beacon_data *beacon = NULL;
1094         u8 *beacon_data;
1095         size_t beacon_data_len;
1096 -       int counter_beacon = sdata->csa_counter_offset_beacon[0];
1097         int ret = false;
1098  
1099         if (!ieee80211_sdata_running(sdata))
1100 @@ -2531,10 +2541,13 @@ bool ieee80211_csa_is_complete(struct ie
1101                 goto out;
1102         }
1103  
1104 -       if (WARN_ON(counter_beacon > beacon_data_len))
1105 +       if (!beacon->csa_counter_offsets[0])
1106 +               goto out;
1107 +
1108 +       if (WARN_ON_ONCE(beacon->csa_counter_offsets[0] > beacon_data_len))
1109                 goto out;
1110  
1111 -       if (beacon_data[counter_beacon] == 1)
1112 +       if (beacon_data[beacon->csa_counter_offsets[0]] == 1)
1113                 ret = true;
1114   out:
1115         rcu_read_unlock();
1116 @@ -2550,6 +2563,7 @@ __ieee80211_beacon_get(struct ieee80211_
1117                        bool is_template)
1118  {
1119         struct ieee80211_local *local = hw_to_local(hw);
1120 +       struct beacon_data *beacon = NULL;
1121         struct sk_buff *skb = NULL;
1122         struct ieee80211_tx_info *info;
1123         struct ieee80211_sub_if_data *sdata = NULL;
1124 @@ -2571,10 +2585,10 @@ __ieee80211_beacon_get(struct ieee80211_
1125  
1126         if (sdata->vif.type == NL80211_IFTYPE_AP) {
1127                 struct ieee80211_if_ap *ap = &sdata->u.ap;
1128 -               struct beacon_data *beacon = rcu_dereference(ap->beacon);
1129  
1130 +               beacon = rcu_dereference(ap->beacon);
1131                 if (beacon) {
1132 -                       if (sdata->vif.csa_active) {
1133 +                       if (beacon->csa_counter_offsets[0]) {
1134                                 if (!is_template)
1135                                         ieee80211_csa_update_counter(vif);
1136  
1137 @@ -2615,37 +2629,37 @@ __ieee80211_beacon_get(struct ieee80211_
1138         } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
1139                 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
1140                 struct ieee80211_hdr *hdr;
1141 -               struct beacon_data *presp = rcu_dereference(ifibss->presp);
1142  
1143 -               if (!presp)
1144 +               beacon = rcu_dereference(ifibss->presp);
1145 +               if (!beacon)
1146                         goto out;
1147  
1148 -               if (sdata->vif.csa_active) {
1149 +               if (beacon->csa_counter_offsets[0]) {
1150                         if (!is_template)
1151                                 ieee80211_csa_update_counter(vif);
1152  
1153 -                       ieee80211_set_csa(sdata, presp);
1154 +                       ieee80211_set_csa(sdata, beacon);
1155                 }
1156  
1157 -               skb = dev_alloc_skb(local->tx_headroom + presp->head_len +
1158 +               skb = dev_alloc_skb(local->tx_headroom + beacon->head_len +
1159                                     local->hw.extra_beacon_tailroom);
1160                 if (!skb)
1161                         goto out;
1162                 skb_reserve(skb, local->tx_headroom);
1163 -               memcpy(skb_put(skb, presp->head_len), presp->head,
1164 -                      presp->head_len);
1165 +               memcpy(skb_put(skb, beacon->head_len), beacon->head,
1166 +                      beacon->head_len);
1167  
1168                 hdr = (struct ieee80211_hdr *) skb->data;
1169                 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1170                                                  IEEE80211_STYPE_BEACON);
1171         } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
1172                 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1173 -               struct beacon_data *bcn = rcu_dereference(ifmsh->beacon);
1174  
1175 -               if (!bcn)
1176 +               beacon = rcu_dereference(ifmsh->beacon);
1177 +               if (!beacon)
1178                         goto out;
1179  
1180 -               if (sdata->vif.csa_active) {
1181 +               if (beacon->csa_counter_offsets[0]) {
1182                         if (!is_template)
1183                                 /* TODO: For mesh csa_counter is in TU, so
1184                                  * decrementing it by one isn't correct, but
1185 @@ -2654,40 +2668,42 @@ __ieee80211_beacon_get(struct ieee80211_
1186                                  */
1187                                 ieee80211_csa_update_counter(vif);
1188  
1189 -                       ieee80211_set_csa(sdata, bcn);
1190 +                       ieee80211_set_csa(sdata, beacon);
1191                 }
1192  
1193                 if (ifmsh->sync_ops)
1194 -                       ifmsh->sync_ops->adjust_tbtt(sdata, bcn);
1195 +                       ifmsh->sync_ops->adjust_tbtt(sdata, beacon);
1196  
1197                 skb = dev_alloc_skb(local->tx_headroom +
1198 -                                   bcn->head_len +
1199 +                                   beacon->head_len +
1200                                     256 + /* TIM IE */
1201 -                                   bcn->tail_len +
1202 +                                   beacon->tail_len +
1203                                     local->hw.extra_beacon_tailroom);
1204                 if (!skb)
1205                         goto out;
1206                 skb_reserve(skb, local->tx_headroom);
1207 -               memcpy(skb_put(skb, bcn->head_len), bcn->head, bcn->head_len);
1208 +               memcpy(skb_put(skb, beacon->head_len), beacon->head,
1209 +                      beacon->head_len);
1210                 ieee80211_beacon_add_tim(sdata, &ifmsh->ps, skb, is_template);
1211  
1212                 if (offs) {
1213 -                       offs->tim_offset = bcn->head_len;
1214 -                       offs->tim_length = skb->len - bcn->head_len;
1215 +                       offs->tim_offset = beacon->head_len;
1216 +                       offs->tim_length = skb->len - beacon->head_len;
1217                 }
1218  
1219 -               memcpy(skb_put(skb, bcn->tail_len), bcn->tail, bcn->tail_len);
1220 +               memcpy(skb_put(skb, beacon->tail_len), beacon->tail,
1221 +                      beacon->tail_len);
1222         } else {
1223                 WARN_ON(1);
1224                 goto out;
1225         }
1226  
1227         /* CSA offsets */
1228 -       if (offs) {
1229 +       if (offs && beacon) {
1230                 int i;
1231  
1232                 for (i = 0; i < IEEE80211_MAX_CSA_COUNTERS_NUM; i++) {
1233 -                       u16 csa_off = sdata->csa_counter_offset_beacon[i];
1234 +                       u16 csa_off = beacon->csa_counter_offsets[i];
1235  
1236                         if (!csa_off)
1237                                 continue;
1238 --- a/drivers/net/wireless/rt2x00/rt2800lib.c
1239 +++ b/drivers/net/wireless/rt2x00/rt2800lib.c
1240 @@ -947,6 +947,40 @@ static inline u8 rt2800_get_beacon_offse
1241         return BEACON_BASE_TO_OFFSET(rt2800_hw_beacon_base(rt2x00dev, index));
1242  }
1243  
1244 +static void rt2800_update_beacons_setup(struct rt2x00_dev *rt2x00dev)
1245 +{
1246 +       struct data_queue *queue = rt2x00dev->bcn;
1247 +       struct queue_entry *entry;
1248 +       int i, bcn_num = 0;
1249 +       u64 off, reg = 0;
1250 +       u32 bssid_dw1;
1251 +
1252 +       /*
1253 +        * Setup offsets of all active beacons in BCN_OFFSET{0,1} registers.
1254 +        */
1255 +       for (i = 0; i < queue->limit; i++) {
1256 +               entry = &queue->entries[i];
1257 +               if (!test_bit(ENTRY_BCN_ENABLED, &entry->flags))
1258 +                       continue;
1259 +               off = rt2800_get_beacon_offset(rt2x00dev, entry->entry_idx);
1260 +               reg |= off << (8 * bcn_num);
1261 +               bcn_num++;
1262 +       }
1263 +
1264 +       WARN_ON_ONCE(bcn_num != rt2x00dev->intf_beaconing);
1265 +
1266 +       rt2800_register_write(rt2x00dev, BCN_OFFSET0, (u32) reg);
1267 +       rt2800_register_write(rt2x00dev, BCN_OFFSET1, (u32) (reg >> 32));
1268 +
1269 +       /*
1270 +        * H/W sends up to MAC_BSSID_DW1_BSS_BCN_NUM + 1 consecutive beacons.
1271 +        */
1272 +       rt2800_register_read(rt2x00dev, MAC_BSSID_DW1, &bssid_dw1);
1273 +       rt2x00_set_field32(&bssid_dw1, MAC_BSSID_DW1_BSS_BCN_NUM,
1274 +                          bcn_num > 0 ? bcn_num - 1 : 0);
1275 +       rt2800_register_write(rt2x00dev, MAC_BSSID_DW1, bssid_dw1);
1276 +}
1277 +
1278  void rt2800_write_beacon(struct queue_entry *entry, struct txentry_desc *txdesc)
1279  {
1280         struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
1281 @@ -1003,6 +1037,12 @@ void rt2800_write_beacon(struct queue_en
1282  
1283         rt2800_register_multiwrite(rt2x00dev, beacon_base, entry->skb->data,
1284                                    entry->skb->len + padding_len);
1285 +       __set_bit(ENTRY_BCN_ENABLED, &entry->flags);
1286 +
1287 +       /*
1288 +        * Change global beacons settings.
1289 +        */
1290 +       rt2800_update_beacons_setup(rt2x00dev);
1291  
1292         /*
1293          * Restore beaconing state.
1294 @@ -1053,8 +1093,13 @@ void rt2800_clear_beacon(struct queue_en
1295          * Clear beacon.
1296          */
1297         rt2800_clear_beacon_register(rt2x00dev, entry->entry_idx);
1298 +       __clear_bit(ENTRY_BCN_ENABLED, &entry->flags);
1299  
1300         /*
1301 +        * Change global beacons settings.
1302 +        */
1303 +       rt2800_update_beacons_setup(rt2x00dev);
1304 +       /*
1305          * Restore beaconing state.
1306          */
1307         rt2800_register_write(rt2x00dev, BCN_TIME_CFG, orig_reg);
1308 @@ -1556,7 +1601,7 @@ void rt2800_config_intf(struct rt2x00_de
1309                 if (!is_zero_ether_addr((const u8 *)conf->bssid)) {
1310                         reg = le32_to_cpu(conf->bssid[1]);
1311                         rt2x00_set_field32(&reg, MAC_BSSID_DW1_BSS_ID_MASK, 3);
1312 -                       rt2x00_set_field32(&reg, MAC_BSSID_DW1_BSS_BCN_NUM, 7);
1313 +                       rt2x00_set_field32(&reg, MAC_BSSID_DW1_BSS_BCN_NUM, 0);
1314                         conf->bssid[1] = cpu_to_le32(reg);
1315                 }
1316  
1317 @@ -4517,28 +4562,6 @@ static int rt2800_init_registers(struct 
1318         if (ret)
1319                 return ret;
1320  
1321 -       rt2800_register_read(rt2x00dev, BCN_OFFSET0, &reg);
1322 -       rt2x00_set_field32(&reg, BCN_OFFSET0_BCN0,
1323 -                          rt2800_get_beacon_offset(rt2x00dev, 0));
1324 -       rt2x00_set_field32(&reg, BCN_OFFSET0_BCN1,
1325 -                          rt2800_get_beacon_offset(rt2x00dev, 1));
1326 -       rt2x00_set_field32(&reg, BCN_OFFSET0_BCN2,
1327 -                          rt2800_get_beacon_offset(rt2x00dev, 2));
1328 -       rt2x00_set_field32(&reg, BCN_OFFSET0_BCN3,
1329 -                          rt2800_get_beacon_offset(rt2x00dev, 3));
1330 -       rt2800_register_write(rt2x00dev, BCN_OFFSET0, reg);
1331 -
1332 -       rt2800_register_read(rt2x00dev, BCN_OFFSET1, &reg);
1333 -       rt2x00_set_field32(&reg, BCN_OFFSET1_BCN4,
1334 -                          rt2800_get_beacon_offset(rt2x00dev, 4));
1335 -       rt2x00_set_field32(&reg, BCN_OFFSET1_BCN5,
1336 -                          rt2800_get_beacon_offset(rt2x00dev, 5));
1337 -       rt2x00_set_field32(&reg, BCN_OFFSET1_BCN6,
1338 -                          rt2800_get_beacon_offset(rt2x00dev, 6));
1339 -       rt2x00_set_field32(&reg, BCN_OFFSET1_BCN7,
1340 -                          rt2800_get_beacon_offset(rt2x00dev, 7));
1341 -       rt2800_register_write(rt2x00dev, BCN_OFFSET1, reg);
1342 -
1343         rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE, 0x0000013f);
1344         rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
1345  
1346 --- a/drivers/net/wireless/rt2x00/rt2x00dev.c
1347 +++ b/drivers/net/wireless/rt2x00/rt2x00dev.c
1348 @@ -141,8 +141,11 @@ static void rt2x00lib_intf_scheduled_ite
1349         if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
1350                 return;
1351  
1352 -       if (test_and_clear_bit(DELAYED_UPDATE_BEACON, &intf->delayed_flags))
1353 +       if (test_and_clear_bit(DELAYED_UPDATE_BEACON, &intf->delayed_flags)) {
1354 +               mutex_lock(&intf->beacon_skb_mutex);
1355                 rt2x00queue_update_beacon(rt2x00dev, vif);
1356 +               mutex_unlock(&intf->beacon_skb_mutex);
1357 +       }
1358  }
1359  
1360  static void rt2x00lib_intf_scheduled(struct work_struct *work)
1361 @@ -216,7 +219,7 @@ static void rt2x00lib_beaconupdate_iter(
1362          * never be called for USB devices.
1363          */
1364         WARN_ON(rt2x00_is_usb(rt2x00dev));
1365 -       rt2x00queue_update_beacon_locked(rt2x00dev, vif);
1366 +       rt2x00queue_update_beacon(rt2x00dev, vif);
1367  }
1368  
1369  void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev)
1370 --- a/drivers/net/wireless/rt2x00/rt2x00mac.c
1371 +++ b/drivers/net/wireless/rt2x00/rt2x00mac.c
1372 @@ -487,6 +487,8 @@ int rt2x00mac_set_key(struct ieee80211_h
1373         crypto.cipher = rt2x00crypto_key_to_cipher(key);
1374         if (crypto.cipher == CIPHER_NONE)
1375                 return -EOPNOTSUPP;
1376 +       if (crypto.cipher == CIPHER_TKIP && rt2x00_is_usb(rt2x00dev))
1377 +               return -EOPNOTSUPP;
1378  
1379         crypto.cmd = cmd;
1380  
1381 @@ -624,25 +626,24 @@ void rt2x00mac_bss_info_changed(struct i
1382          * Start/stop beaconing.
1383          */
1384         if (changes & BSS_CHANGED_BEACON_ENABLED) {
1385 +               mutex_lock(&intf->beacon_skb_mutex);
1386                 if (!bss_conf->enable_beacon && intf->enable_beacon) {
1387                         rt2x00dev->intf_beaconing--;
1388                         intf->enable_beacon = false;
1389 -                       /*
1390 -                        * Clear beacon in the H/W for this vif. This is needed
1391 -                        * to disable beaconing on this particular interface
1392 -                        * and keep it running on other interfaces.
1393 -                        */
1394 -                       rt2x00queue_clear_beacon(rt2x00dev, vif);
1395  
1396                         if (rt2x00dev->intf_beaconing == 0) {
1397                                 /*
1398                                  * Last beaconing interface disabled
1399                                  * -> stop beacon queue.
1400                                  */
1401 -                               mutex_lock(&intf->beacon_skb_mutex);
1402                                 rt2x00queue_stop_queue(rt2x00dev->bcn);
1403 -                               mutex_unlock(&intf->beacon_skb_mutex);
1404                         }
1405 +                       /*
1406 +                        * Clear beacon in the H/W for this vif. This is needed
1407 +                        * to disable beaconing on this particular interface
1408 +                        * and keep it running on other interfaces.
1409 +                        */
1410 +                       rt2x00queue_clear_beacon(rt2x00dev, vif);
1411                 } else if (bss_conf->enable_beacon && !intf->enable_beacon) {
1412                         rt2x00dev->intf_beaconing++;
1413                         intf->enable_beacon = true;
1414 @@ -658,11 +659,10 @@ void rt2x00mac_bss_info_changed(struct i
1415                                  * First beaconing interface enabled
1416                                  * -> start beacon queue.
1417                                  */
1418 -                               mutex_lock(&intf->beacon_skb_mutex);
1419                                 rt2x00queue_start_queue(rt2x00dev->bcn);
1420 -                               mutex_unlock(&intf->beacon_skb_mutex);
1421                         }
1422                 }
1423 +               mutex_unlock(&intf->beacon_skb_mutex);
1424         }
1425  
1426         /*
1427 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
1428 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
1429 @@ -754,8 +754,6 @@ int rt2x00queue_clear_beacon(struct rt2x
1430         if (unlikely(!intf->beacon))
1431                 return -ENOBUFS;
1432  
1433 -       mutex_lock(&intf->beacon_skb_mutex);
1434 -
1435         /*
1436          * Clean up the beacon skb.
1437          */
1438 @@ -768,13 +766,11 @@ int rt2x00queue_clear_beacon(struct rt2x
1439         if (rt2x00dev->ops->lib->clear_beacon)
1440                 rt2x00dev->ops->lib->clear_beacon(intf->beacon);
1441  
1442 -       mutex_unlock(&intf->beacon_skb_mutex);
1443 -
1444         return 0;
1445  }
1446  
1447 -int rt2x00queue_update_beacon_locked(struct rt2x00_dev *rt2x00dev,
1448 -                                    struct ieee80211_vif *vif)
1449 +int rt2x00queue_update_beacon(struct rt2x00_dev *rt2x00dev,
1450 +                             struct ieee80211_vif *vif)
1451  {
1452         struct rt2x00_intf *intf = vif_to_intf(vif);
1453         struct skb_frame_desc *skbdesc;
1454 @@ -815,19 +811,6 @@ int rt2x00queue_update_beacon_locked(str
1455  
1456  }
1457  
1458 -int rt2x00queue_update_beacon(struct rt2x00_dev *rt2x00dev,
1459 -                             struct ieee80211_vif *vif)
1460 -{
1461 -       struct rt2x00_intf *intf = vif_to_intf(vif);
1462 -       int ret;
1463 -
1464 -       mutex_lock(&intf->beacon_skb_mutex);
1465 -       ret = rt2x00queue_update_beacon_locked(rt2x00dev, vif);
1466 -       mutex_unlock(&intf->beacon_skb_mutex);
1467 -
1468 -       return ret;
1469 -}
1470 -
1471  bool rt2x00queue_for_each_entry(struct data_queue *queue,
1472                                 enum queue_index start,
1473                                 enum queue_index end,
1474 --- a/drivers/net/wireless/rt2x00/rt2x00queue.h
1475 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.h
1476 @@ -353,6 +353,7 @@ struct txentry_desc {
1477   */
1478  enum queue_entry_flags {
1479         ENTRY_BCN_ASSIGNED,
1480 +       ENTRY_BCN_ENABLED,
1481         ENTRY_OWNER_DEVICE_DATA,
1482         ENTRY_DATA_PENDING,
1483         ENTRY_DATA_IO_FAILED,
1484 --- a/drivers/net/wireless/ath/ath9k/main.c
1485 +++ b/drivers/net/wireless/ath/ath9k/main.c
1486 @@ -1757,7 +1757,6 @@ out:
1487  void ath9k_update_p2p_ps(struct ath_softc *sc, struct ieee80211_vif *vif)
1488  {
1489         struct ath_vif *avp = (void *)vif->drv_priv;
1490 -       unsigned long flags;
1491         u32 tsf;
1492  
1493         if (!sc->p2p_ps_timer)
1494 @@ -1767,14 +1766,9 @@ void ath9k_update_p2p_ps(struct ath_soft
1495                 return;
1496  
1497         sc->p2p_ps_vif = avp;
1498 -
1499 -       spin_lock_irqsave(&sc->sc_pm_lock, flags);
1500 -       if (!(sc->ps_flags & PS_BEACON_SYNC)) {
1501 -               tsf = ath9k_hw_gettsf32(sc->sc_ah);
1502 -               ieee80211_parse_p2p_noa(&vif->bss_conf.p2p_noa_attr, &avp->noa, tsf);
1503 -               ath9k_update_p2p_ps_timer(sc, avp);
1504 -       }
1505 -       spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
1506 +       tsf = ath9k_hw_gettsf32(sc->sc_ah);
1507 +       ieee80211_parse_p2p_noa(&vif->bss_conf.p2p_noa_attr, &avp->noa, tsf);
1508 +       ath9k_update_p2p_ps_timer(sc, avp);
1509  }
1510  
1511  static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
1512 @@ -1791,6 +1785,7 @@ static void ath9k_bss_info_changed(struc
1513         struct ath_hw *ah = sc->sc_ah;
1514         struct ath_common *common = ath9k_hw_common(ah);
1515         struct ath_vif *avp = (void *)vif->drv_priv;
1516 +       unsigned long flags;
1517         int slottime;
1518  
1519         ath9k_ps_wakeup(sc);
1520 @@ -1853,7 +1848,10 @@ static void ath9k_bss_info_changed(struc
1521  
1522         if (changed & BSS_CHANGED_P2P_PS) {
1523                 spin_lock_bh(&sc->sc_pcu_lock);
1524 -               ath9k_update_p2p_ps(sc, vif);
1525 +               spin_lock_irqsave(&sc->sc_pm_lock, flags);
1526 +               if (!(sc->ps_flags & PS_BEACON_SYNC))
1527 +                       ath9k_update_p2p_ps(sc, vif);
1528 +               spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
1529                 spin_unlock_bh(&sc->sc_pcu_lock);
1530         }
1531  
1532 @@ -2232,14 +2230,6 @@ static void ath9k_sw_scan_complete(struc
1533         clear_bit(ATH_OP_SCANNING, &common->op_flags);
1534  }
1535  
1536 -static void ath9k_channel_switch_beacon(struct ieee80211_hw *hw,
1537 -                                       struct ieee80211_vif *vif,
1538 -                                       struct cfg80211_chan_def *chandef)
1539 -{
1540 -       /* depend on vif->csa_active only */
1541 -       return;
1542 -}
1543 -
1544  struct ieee80211_ops ath9k_ops = {
1545         .tx                 = ath9k_tx,
1546         .start              = ath9k_start,
1547 @@ -2287,5 +2277,4 @@ struct ieee80211_ops ath9k_ops = {
1548  #endif
1549         .sw_scan_start      = ath9k_sw_scan_start,
1550         .sw_scan_complete   = ath9k_sw_scan_complete,
1551 -       .channel_switch_beacon     = ath9k_channel_switch_beacon,
1552  };
1553 --- a/drivers/net/wireless/ath/ath10k/mac.c
1554 +++ b/drivers/net/wireless/ath/ath10k/mac.c
1555 @@ -4142,14 +4142,6 @@ static int ath10k_set_bitrate_mask(struc
1556                                            fixed_nss, force_sgi);
1557  }
1558  
1559 -static void ath10k_channel_switch_beacon(struct ieee80211_hw *hw,
1560 -                                        struct ieee80211_vif *vif,
1561 -                                        struct cfg80211_chan_def *chandef)
1562 -{
1563 -       /* there's no need to do anything here. vif->csa_active is enough */
1564 -       return;
1565 -}
1566 -
1567  static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
1568                                  struct ieee80211_vif *vif,
1569                                  struct ieee80211_sta *sta,
1570 @@ -4256,7 +4248,6 @@ static const struct ieee80211_ops ath10k
1571         .restart_complete               = ath10k_restart_complete,
1572         .get_survey                     = ath10k_get_survey,
1573         .set_bitrate_mask               = ath10k_set_bitrate_mask,
1574 -       .channel_switch_beacon          = ath10k_channel_switch_beacon,
1575         .sta_rc_update                  = ath10k_sta_rc_update,
1576         .get_tsf                        = ath10k_get_tsf,
1577  #ifdef CONFIG_PM
1578 --- a/net/mac80211/cfg.c
1579 +++ b/net/mac80211/cfg.c
1580 @@ -468,327 +468,6 @@ void sta_set_rate_info_rx(struct sta_inf
1581                 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
1582  }
1583  
1584 -static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
1585 -{
1586 -       struct ieee80211_sub_if_data *sdata = sta->sdata;
1587 -       struct ieee80211_local *local = sdata->local;
1588 -       struct rate_control_ref *ref = local->rate_ctrl;
1589 -       struct timespec uptime;
1590 -       u64 packets = 0;
1591 -       u32 thr = 0;
1592 -       int i, ac;
1593 -
1594 -       sinfo->generation = sdata->local->sta_generation;
1595 -
1596 -       sinfo->filled = STATION_INFO_INACTIVE_TIME |
1597 -                       STATION_INFO_RX_BYTES64 |
1598 -                       STATION_INFO_TX_BYTES64 |
1599 -                       STATION_INFO_RX_PACKETS |
1600 -                       STATION_INFO_TX_PACKETS |
1601 -                       STATION_INFO_TX_RETRIES |
1602 -                       STATION_INFO_TX_FAILED |
1603 -                       STATION_INFO_TX_BITRATE |
1604 -                       STATION_INFO_RX_BITRATE |
1605 -                       STATION_INFO_RX_DROP_MISC |
1606 -                       STATION_INFO_BSS_PARAM |
1607 -                       STATION_INFO_CONNECTED_TIME |
1608 -                       STATION_INFO_STA_FLAGS |
1609 -                       STATION_INFO_BEACON_LOSS_COUNT;
1610 -
1611 -       do_posix_clock_monotonic_gettime(&uptime);
1612 -       sinfo->connected_time = uptime.tv_sec - sta->last_connected;
1613 -
1614 -       sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
1615 -       sinfo->tx_bytes = 0;
1616 -       for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1617 -               sinfo->tx_bytes += sta->tx_bytes[ac];
1618 -               packets += sta->tx_packets[ac];
1619 -       }
1620 -       sinfo->tx_packets = packets;
1621 -       sinfo->rx_bytes = sta->rx_bytes;
1622 -       sinfo->rx_packets = sta->rx_packets;
1623 -       sinfo->tx_retries = sta->tx_retry_count;
1624 -       sinfo->tx_failed = sta->tx_retry_failed;
1625 -       sinfo->rx_dropped_misc = sta->rx_dropped;
1626 -       sinfo->beacon_loss_count = sta->beacon_loss_count;
1627 -
1628 -       if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
1629 -           (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
1630 -               sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
1631 -               if (!local->ops->get_rssi ||
1632 -                   drv_get_rssi(local, sdata, &sta->sta, &sinfo->signal))
1633 -                       sinfo->signal = (s8)sta->last_signal;
1634 -               sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
1635 -       }
1636 -       if (sta->chains) {
1637 -               sinfo->filled |= STATION_INFO_CHAIN_SIGNAL |
1638 -                                STATION_INFO_CHAIN_SIGNAL_AVG;
1639 -
1640 -               sinfo->chains = sta->chains;
1641 -               for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
1642 -                       sinfo->chain_signal[i] = sta->chain_signal_last[i];
1643 -                       sinfo->chain_signal_avg[i] =
1644 -                               (s8) -ewma_read(&sta->chain_signal_avg[i]);
1645 -               }
1646 -       }
1647 -
1648 -       sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
1649 -       sta_set_rate_info_rx(sta, &sinfo->rxrate);
1650 -
1651 -       if (ieee80211_vif_is_mesh(&sdata->vif)) {
1652 -#ifdef CPTCFG_MAC80211_MESH
1653 -               sinfo->filled |= STATION_INFO_LLID |
1654 -                                STATION_INFO_PLID |
1655 -                                STATION_INFO_PLINK_STATE |
1656 -                                STATION_INFO_LOCAL_PM |
1657 -                                STATION_INFO_PEER_PM |
1658 -                                STATION_INFO_NONPEER_PM;
1659 -
1660 -               sinfo->llid = sta->llid;
1661 -               sinfo->plid = sta->plid;
1662 -               sinfo->plink_state = sta->plink_state;
1663 -               if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
1664 -                       sinfo->filled |= STATION_INFO_T_OFFSET;
1665 -                       sinfo->t_offset = sta->t_offset;
1666 -               }
1667 -               sinfo->local_pm = sta->local_pm;
1668 -               sinfo->peer_pm = sta->peer_pm;
1669 -               sinfo->nonpeer_pm = sta->nonpeer_pm;
1670 -#endif
1671 -       }
1672 -
1673 -       sinfo->bss_param.flags = 0;
1674 -       if (sdata->vif.bss_conf.use_cts_prot)
1675 -               sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
1676 -       if (sdata->vif.bss_conf.use_short_preamble)
1677 -               sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
1678 -       if (sdata->vif.bss_conf.use_short_slot)
1679 -               sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
1680 -       sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
1681 -       sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
1682 -
1683 -       sinfo->sta_flags.set = 0;
1684 -       sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
1685 -                               BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
1686 -                               BIT(NL80211_STA_FLAG_WME) |
1687 -                               BIT(NL80211_STA_FLAG_MFP) |
1688 -                               BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1689 -                               BIT(NL80211_STA_FLAG_ASSOCIATED) |
1690 -                               BIT(NL80211_STA_FLAG_TDLS_PEER);
1691 -       if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1692 -               sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
1693 -       if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
1694 -               sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
1695 -       if (test_sta_flag(sta, WLAN_STA_WME))
1696 -               sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
1697 -       if (test_sta_flag(sta, WLAN_STA_MFP))
1698 -               sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
1699 -       if (test_sta_flag(sta, WLAN_STA_AUTH))
1700 -               sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
1701 -       if (test_sta_flag(sta, WLAN_STA_ASSOC))
1702 -               sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1703 -       if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1704 -               sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
1705 -
1706 -       /* check if the driver has a SW RC implementation */
1707 -       if (ref && ref->ops->get_expected_throughput)
1708 -               thr = ref->ops->get_expected_throughput(sta->rate_ctrl_priv);
1709 -       else
1710 -               thr = drv_get_expected_throughput(local, &sta->sta);
1711 -
1712 -       if (thr != 0) {
1713 -               sinfo->filled |= STATION_INFO_EXPECTED_THROUGHPUT;
1714 -               sinfo->expected_throughput = thr;
1715 -       }
1716 -}
1717 -
1718 -static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
1719 -       "rx_packets", "rx_bytes", "wep_weak_iv_count",
1720 -       "rx_duplicates", "rx_fragments", "rx_dropped",
1721 -       "tx_packets", "tx_bytes", "tx_fragments",
1722 -       "tx_filtered", "tx_retry_failed", "tx_retries",
1723 -       "beacon_loss", "sta_state", "txrate", "rxrate", "signal",
1724 -       "channel", "noise", "ch_time", "ch_time_busy",
1725 -       "ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
1726 -};
1727 -#define STA_STATS_LEN  ARRAY_SIZE(ieee80211_gstrings_sta_stats)
1728 -
1729 -static int ieee80211_get_et_sset_count(struct wiphy *wiphy,
1730 -                                      struct net_device *dev,
1731 -                                      int sset)
1732 -{
1733 -       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1734 -       int rv = 0;
1735 -
1736 -       if (sset == ETH_SS_STATS)
1737 -               rv += STA_STATS_LEN;
1738 -
1739 -       rv += drv_get_et_sset_count(sdata, sset);
1740 -
1741 -       if (rv == 0)
1742 -               return -EOPNOTSUPP;
1743 -       return rv;
1744 -}
1745 -
1746 -static void ieee80211_get_et_stats(struct wiphy *wiphy,
1747 -                                  struct net_device *dev,
1748 -                                  struct ethtool_stats *stats,
1749 -                                  u64 *data)
1750 -{
1751 -       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1752 -       struct ieee80211_chanctx_conf *chanctx_conf;
1753 -       struct ieee80211_channel *channel;
1754 -       struct sta_info *sta;
1755 -       struct ieee80211_local *local = sdata->local;
1756 -       struct station_info sinfo;
1757 -       struct survey_info survey;
1758 -       int i, q;
1759 -#define STA_STATS_SURVEY_LEN 7
1760 -
1761 -       memset(data, 0, sizeof(u64) * STA_STATS_LEN);
1762 -
1763 -#define ADD_STA_STATS(sta)                             \
1764 -       do {                                            \
1765 -               data[i++] += sta->rx_packets;           \
1766 -               data[i++] += sta->rx_bytes;             \
1767 -               data[i++] += sta->wep_weak_iv_count;    \
1768 -               data[i++] += sta->num_duplicates;       \
1769 -               data[i++] += sta->rx_fragments;         \
1770 -               data[i++] += sta->rx_dropped;           \
1771 -                                                       \
1772 -               data[i++] += sinfo.tx_packets;          \
1773 -               data[i++] += sinfo.tx_bytes;            \
1774 -               data[i++] += sta->tx_fragments;         \
1775 -               data[i++] += sta->tx_filtered_count;    \
1776 -               data[i++] += sta->tx_retry_failed;      \
1777 -               data[i++] += sta->tx_retry_count;       \
1778 -               data[i++] += sta->beacon_loss_count;    \
1779 -       } while (0)
1780 -
1781 -       /* For Managed stations, find the single station based on BSSID
1782 -        * and use that.  For interface types, iterate through all available
1783 -        * stations and add stats for any station that is assigned to this
1784 -        * network device.
1785 -        */
1786 -
1787 -       mutex_lock(&local->sta_mtx);
1788 -
1789 -       if (sdata->vif.type == NL80211_IFTYPE_STATION) {
1790 -               sta = sta_info_get_bss(sdata, sdata->u.mgd.bssid);
1791 -
1792 -               if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
1793 -                       goto do_survey;
1794 -
1795 -               sinfo.filled = 0;
1796 -               sta_set_sinfo(sta, &sinfo);
1797 -
1798 -               i = 0;
1799 -               ADD_STA_STATS(sta);
1800 -
1801 -               data[i++] = sta->sta_state;
1802 -
1803 -
1804 -               if (sinfo.filled & STATION_INFO_TX_BITRATE)
1805 -                       data[i] = 100000 *
1806 -                               cfg80211_calculate_bitrate(&sinfo.txrate);
1807 -               i++;
1808 -               if (sinfo.filled & STATION_INFO_RX_BITRATE)
1809 -                       data[i] = 100000 *
1810 -                               cfg80211_calculate_bitrate(&sinfo.rxrate);
1811 -               i++;
1812 -
1813 -               if (sinfo.filled & STATION_INFO_SIGNAL_AVG)
1814 -                       data[i] = (u8)sinfo.signal_avg;
1815 -               i++;
1816 -       } else {
1817 -               list_for_each_entry(sta, &local->sta_list, list) {
1818 -                       /* Make sure this station belongs to the proper dev */
1819 -                       if (sta->sdata->dev != dev)
1820 -                               continue;
1821 -
1822 -                       sinfo.filled = 0;
1823 -                       sta_set_sinfo(sta, &sinfo);
1824 -                       i = 0;
1825 -                       ADD_STA_STATS(sta);
1826 -               }
1827 -       }
1828 -
1829 -do_survey:
1830 -       i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
1831 -       /* Get survey stats for current channel */
1832 -       survey.filled = 0;
1833 -
1834 -       rcu_read_lock();
1835 -       chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
1836 -       if (chanctx_conf)
1837 -               channel = chanctx_conf->def.chan;
1838 -       else
1839 -               channel = NULL;
1840 -       rcu_read_unlock();
1841 -
1842 -       if (channel) {
1843 -               q = 0;
1844 -               do {
1845 -                       survey.filled = 0;
1846 -                       if (drv_get_survey(local, q, &survey) != 0) {
1847 -                               survey.filled = 0;
1848 -                               break;
1849 -                       }
1850 -                       q++;
1851 -               } while (channel != survey.channel);
1852 -       }
1853 -
1854 -       if (survey.filled)
1855 -               data[i++] = survey.channel->center_freq;
1856 -       else
1857 -               data[i++] = 0;
1858 -       if (survey.filled & SURVEY_INFO_NOISE_DBM)
1859 -               data[i++] = (u8)survey.noise;
1860 -       else
1861 -               data[i++] = -1LL;
1862 -       if (survey.filled & SURVEY_INFO_CHANNEL_TIME)
1863 -               data[i++] = survey.channel_time;
1864 -       else
1865 -               data[i++] = -1LL;
1866 -       if (survey.filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
1867 -               data[i++] = survey.channel_time_busy;
1868 -       else
1869 -               data[i++] = -1LL;
1870 -       if (survey.filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
1871 -               data[i++] = survey.channel_time_ext_busy;
1872 -       else
1873 -               data[i++] = -1LL;
1874 -       if (survey.filled & SURVEY_INFO_CHANNEL_TIME_RX)
1875 -               data[i++] = survey.channel_time_rx;
1876 -       else
1877 -               data[i++] = -1LL;
1878 -       if (survey.filled & SURVEY_INFO_CHANNEL_TIME_TX)
1879 -               data[i++] = survey.channel_time_tx;
1880 -       else
1881 -               data[i++] = -1LL;
1882 -
1883 -       mutex_unlock(&local->sta_mtx);
1884 -
1885 -       if (WARN_ON(i != STA_STATS_LEN))
1886 -               return;
1887 -
1888 -       drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
1889 -}
1890 -
1891 -static void ieee80211_get_et_strings(struct wiphy *wiphy,
1892 -                                    struct net_device *dev,
1893 -                                    u32 sset, u8 *data)
1894 -{
1895 -       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1896 -       int sz_sta_stats = 0;
1897 -
1898 -       if (sset == ETH_SS_STATS) {
1899 -               sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
1900 -               memcpy(data, ieee80211_gstrings_sta_stats, sz_sta_stats);
1901 -       }
1902 -       drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
1903 -}
1904 -
1905  static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
1906                                   int idx, u8 *mac, struct station_info *sinfo)
1907  {
1908 @@ -875,7 +554,8 @@ static int ieee80211_set_monitor_channel
1909  }
1910  
1911  static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
1912 -                                   const u8 *resp, size_t resp_len)
1913 +                                   const u8 *resp, size_t resp_len,
1914 +                                   const struct ieee80211_csa_settings *csa)
1915  {
1916         struct probe_resp *new, *old;
1917  
1918 @@ -891,6 +571,11 @@ static int ieee80211_set_probe_resp(stru
1919         new->len = resp_len;
1920         memcpy(new->data, resp, resp_len);
1921  
1922 +       if (csa)
1923 +               memcpy(new->csa_counter_offsets, csa->counter_offsets_presp,
1924 +                      csa->n_counter_offsets_presp *
1925 +                      sizeof(new->csa_counter_offsets[0]));
1926 +
1927         rcu_assign_pointer(sdata->u.ap.probe_resp, new);
1928         if (old)
1929                 kfree_rcu(old, rcu_head);
1930 @@ -899,7 +584,8 @@ static int ieee80211_set_probe_resp(stru
1931  }
1932  
1933  static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
1934 -                                  struct cfg80211_beacon_data *params)
1935 +                                  struct cfg80211_beacon_data *params,
1936 +                                  const struct ieee80211_csa_settings *csa)
1937  {
1938         struct beacon_data *new, *old;
1939         int new_head_len, new_tail_len;
1940 @@ -943,6 +629,13 @@ static int ieee80211_assign_beacon(struc
1941         new->head_len = new_head_len;
1942         new->tail_len = new_tail_len;
1943  
1944 +       if (csa) {
1945 +               new->csa_current_counter = csa->count;
1946 +               memcpy(new->csa_counter_offsets, csa->counter_offsets_beacon,
1947 +                      csa->n_counter_offsets_beacon *
1948 +                      sizeof(new->csa_counter_offsets[0]));
1949 +       }
1950 +
1951         /* copy in head */
1952         if (params->head)
1953                 memcpy(new->head, params->head, new_head_len);
1954 @@ -957,7 +650,7 @@ static int ieee80211_assign_beacon(struc
1955                         memcpy(new->tail, old->tail, new_tail_len);
1956  
1957         err = ieee80211_set_probe_resp(sdata, params->probe_resp,
1958 -                                      params->probe_resp_len);
1959 +                                      params->probe_resp_len, csa);
1960         if (err < 0)
1961                 return err;
1962         if (err == 0)
1963 @@ -1042,7 +735,7 @@ static int ieee80211_start_ap(struct wip
1964                 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1965                                         IEEE80211_P2P_OPPPS_ENABLE_BIT;
1966  
1967 -       err = ieee80211_assign_beacon(sdata, &params->beacon);
1968 +       err = ieee80211_assign_beacon(sdata, &params->beacon, NULL);
1969         if (err < 0) {
1970                 ieee80211_vif_release_channel(sdata);
1971                 return err;
1972 @@ -1090,7 +783,7 @@ static int ieee80211_change_beacon(struc
1973         if (!old)
1974                 return -ENOENT;
1975  
1976 -       err = ieee80211_assign_beacon(sdata, params);
1977 +       err = ieee80211_assign_beacon(sdata, params, NULL);
1978         if (err < 0)
1979                 return err;
1980         ieee80211_bss_info_change_notify(sdata, err);
1981 @@ -3073,7 +2766,8 @@ static int ieee80211_set_after_csa_beaco
1982  
1983         switch (sdata->vif.type) {
1984         case NL80211_IFTYPE_AP:
1985 -               err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon);
1986 +               err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
1987 +                                             NULL);
1988                 kfree(sdata->u.ap.next_beacon);
1989                 sdata->u.ap.next_beacon = NULL;
1990  
1991 @@ -3176,6 +2870,7 @@ static int ieee80211_set_csa_beacon(stru
1992                                     struct cfg80211_csa_settings *params,
1993                                     u32 *changed)
1994  {
1995 +       struct ieee80211_csa_settings csa = {};
1996         int err;
1997  
1998         switch (sdata->vif.type) {
1999 @@ -3210,20 +2905,13 @@ static int ieee80211_set_csa_beacon(stru
2000                      IEEE80211_MAX_CSA_COUNTERS_NUM))
2001                         return -EINVAL;
2002  
2003 -               /* make sure we don't have garbage in other counters */
2004 -               memset(sdata->csa_counter_offset_beacon, 0,
2005 -                      sizeof(sdata->csa_counter_offset_beacon));
2006 -               memset(sdata->csa_counter_offset_presp, 0,
2007 -                      sizeof(sdata->csa_counter_offset_presp));
2008 -
2009 -               memcpy(sdata->csa_counter_offset_beacon,
2010 -                      params->counter_offsets_beacon,
2011 -                      params->n_counter_offsets_beacon * sizeof(u16));
2012 -               memcpy(sdata->csa_counter_offset_presp,
2013 -                      params->counter_offsets_presp,
2014 -                      params->n_counter_offsets_presp * sizeof(u16));
2015 +               csa.counter_offsets_beacon = params->counter_offsets_beacon;
2016 +               csa.counter_offsets_presp = params->counter_offsets_presp;
2017 +               csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
2018 +               csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
2019 +               csa.count = params->count;
2020  
2021 -               err = ieee80211_assign_beacon(sdata, &params->beacon_csa);
2022 +               err = ieee80211_assign_beacon(sdata, &params->beacon_csa, &csa);
2023                 if (err < 0) {
2024                         kfree(sdata->u.ap.next_beacon);
2025                         return err;
2026 @@ -3367,7 +3055,6 @@ __ieee80211_channel_switch(struct wiphy 
2027         sdata->csa_radar_required = params->radar_required;
2028         sdata->csa_chandef = params->chandef;
2029         sdata->csa_block_tx = params->block_tx;
2030 -       sdata->csa_current_counter = params->count;
2031         sdata->vif.csa_active = true;
2032  
2033         if (sdata->csa_block_tx)
2034 @@ -3515,10 +3202,23 @@ static int ieee80211_mgmt_tx(struct wiph
2035              sdata->vif.type == NL80211_IFTYPE_ADHOC) &&
2036             params->n_csa_offsets) {
2037                 int i;
2038 -               u8 c = sdata->csa_current_counter;
2039 +               struct beacon_data *beacon = NULL;
2040 +
2041 +               rcu_read_lock();
2042  
2043 -               for (i = 0; i < params->n_csa_offsets; i++)
2044 -                       data[params->csa_offsets[i]] = c;
2045 +               if (sdata->vif.type == NL80211_IFTYPE_AP)
2046 +                       beacon = rcu_dereference(sdata->u.ap.beacon);
2047 +               else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
2048 +                       beacon = rcu_dereference(sdata->u.ibss.presp);
2049 +               else if (ieee80211_vif_is_mesh(&sdata->vif))
2050 +                       beacon = rcu_dereference(sdata->u.mesh.beacon);
2051 +
2052 +               if (beacon)
2053 +                       for (i = 0; i < params->n_csa_offsets; i++)
2054 +                               data[params->csa_offsets[i]] =
2055 +                                       beacon->csa_current_counter;
2056 +
2057 +               rcu_read_unlock();
2058         }
2059  
2060         IEEE80211_SKB_CB(skb)->flags = flags;
2061 @@ -3598,21 +3298,6 @@ static int ieee80211_get_antenna(struct 
2062         return drv_get_antenna(local, tx_ant, rx_ant);
2063  }
2064  
2065 -static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
2066 -{
2067 -       struct ieee80211_local *local = wiphy_priv(wiphy);
2068 -
2069 -       return drv_set_ringparam(local, tx, rx);
2070 -}
2071 -
2072 -static void ieee80211_get_ringparam(struct wiphy *wiphy,
2073 -                                   u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
2074 -{
2075 -       struct ieee80211_local *local = wiphy_priv(wiphy);
2076 -
2077 -       drv_get_ringparam(local, tx, tx_max, rx, rx_max);
2078 -}
2079 -
2080  static int ieee80211_set_rekey_data(struct wiphy *wiphy,
2081                                     struct net_device *dev,
2082                                     struct cfg80211_gtk_rekey_data *data)
2083 @@ -3844,8 +3529,6 @@ const struct cfg80211_ops mac80211_confi
2084         .mgmt_frame_register = ieee80211_mgmt_frame_register,
2085         .set_antenna = ieee80211_set_antenna,
2086         .get_antenna = ieee80211_get_antenna,
2087 -       .set_ringparam = ieee80211_set_ringparam,
2088 -       .get_ringparam = ieee80211_get_ringparam,
2089         .set_rekey_data = ieee80211_set_rekey_data,
2090         .tdls_oper = ieee80211_tdls_oper,
2091         .tdls_mgmt = ieee80211_tdls_mgmt,
2092 @@ -3854,9 +3537,6 @@ const struct cfg80211_ops mac80211_confi
2093  #ifdef CONFIG_PM
2094         .set_wakeup = ieee80211_set_wakeup,
2095  #endif
2096 -       .get_et_sset_count = ieee80211_get_et_sset_count,
2097 -       .get_et_stats = ieee80211_get_et_stats,
2098 -       .get_et_strings = ieee80211_get_et_strings,
2099         .get_channel = ieee80211_cfg_get_channel,
2100         .start_radar_detection = ieee80211_start_radar_detection,
2101         .channel_switch = ieee80211_channel_switch,
2102 --- a/net/mac80211/debugfs_sta.c
2103 +++ b/net/mac80211/debugfs_sta.c
2104 @@ -587,7 +587,6 @@ void ieee80211_sta_debugfs_add(struct st
2105         DEBUGFS_ADD_COUNTER(tx_filtered, tx_filtered_count);
2106         DEBUGFS_ADD_COUNTER(tx_retry_failed, tx_retry_failed);
2107         DEBUGFS_ADD_COUNTER(tx_retry_count, tx_retry_count);
2108 -       DEBUGFS_ADD_COUNTER(wep_weak_iv_count, wep_weak_iv_count);
2109  
2110         if (sizeof(sta->driver_buffered_tids) == sizeof(u32))
2111                 debugfs_create_x32("driver_buffered_tids", 0400,
2112 --- a/net/mac80211/wep.c
2113 +++ b/net/mac80211/wep.c
2114 @@ -271,22 +271,6 @@ static int ieee80211_wep_decrypt(struct 
2115         return ret;
2116  }
2117  
2118 -
2119 -static bool ieee80211_wep_is_weak_iv(struct sk_buff *skb,
2120 -                                    struct ieee80211_key *key)
2121 -{
2122 -       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2123 -       unsigned int hdrlen;
2124 -       u8 *ivpos;
2125 -       u32 iv;
2126 -
2127 -       hdrlen = ieee80211_hdrlen(hdr->frame_control);
2128 -       ivpos = skb->data + hdrlen;
2129 -       iv = (ivpos[0] << 16) | (ivpos[1] << 8) | ivpos[2];
2130 -
2131 -       return ieee80211_wep_weak_iv(iv, key->conf.keylen);
2132 -}
2133 -
2134  ieee80211_rx_result
2135  ieee80211_crypto_wep_decrypt(struct ieee80211_rx_data *rx)
2136  {
2137 @@ -301,16 +285,12 @@ ieee80211_crypto_wep_decrypt(struct ieee
2138         if (!(status->flag & RX_FLAG_DECRYPTED)) {
2139                 if (skb_linearize(rx->skb))
2140                         return RX_DROP_UNUSABLE;
2141 -               if (rx->sta && ieee80211_wep_is_weak_iv(rx->skb, rx->key))
2142 -                       rx->sta->wep_weak_iv_count++;
2143                 if (ieee80211_wep_decrypt(rx->local, rx->skb, rx->key))
2144                         return RX_DROP_UNUSABLE;
2145         } else if (!(status->flag & RX_FLAG_IV_STRIPPED)) {
2146                 if (!pskb_may_pull(rx->skb, ieee80211_hdrlen(fc) +
2147                                             IEEE80211_WEP_IV_LEN))
2148                         return RX_DROP_UNUSABLE;
2149 -               if (rx->sta && ieee80211_wep_is_weak_iv(rx->skb, rx->key))
2150 -                       rx->sta->wep_weak_iv_count++;
2151                 ieee80211_wep_remove_iv(rx->local, rx->skb, rx->key);
2152                 /* remove ICV */
2153                 if (pskb_trim(rx->skb, rx->skb->len - IEEE80211_WEP_ICV_LEN))
2154 --- a/include/net/cfg80211.h
2155 +++ b/include/net/cfg80211.h
2156 @@ -2278,16 +2278,6 @@ struct cfg80211_qos_map {
2157   *
2158   * @set_noack_map: Set the NoAck Map for the TIDs.
2159   *
2160 - * @get_et_sset_count:  Ethtool API to get string-set count.
2161 - *     See @ethtool_ops.get_sset_count
2162 - *
2163 - * @get_et_stats:  Ethtool API to get a set of u64 stats.
2164 - *     See @ethtool_ops.get_ethtool_stats
2165 - *
2166 - * @get_et_strings:  Ethtool API to get a set of strings to describe stats
2167 - *     and perhaps other supported types of ethtool data-sets.
2168 - *     See @ethtool_ops.get_strings
2169 - *
2170   * @get_channel: Get the current operating channel for the virtual interface.
2171   *     For monitor interfaces, it should return %NULL unless there's a single
2172   *     current monitoring channel.
2173 @@ -2529,13 +2519,6 @@ struct cfg80211_ops {
2174                                   struct net_device *dev,
2175                                   u16 noack_map);
2176  
2177 -       int     (*get_et_sset_count)(struct wiphy *wiphy,
2178 -                                    struct net_device *dev, int sset);
2179 -       void    (*get_et_stats)(struct wiphy *wiphy, struct net_device *dev,
2180 -                               struct ethtool_stats *stats, u64 *data);
2181 -       void    (*get_et_strings)(struct wiphy *wiphy, struct net_device *dev,
2182 -                                 u32 sset, u8 *data);
2183 -
2184         int     (*get_channel)(struct wiphy *wiphy,
2185                                struct wireless_dev *wdev,
2186                                struct cfg80211_chan_def *chandef);
2187 @@ -4846,6 +4829,10 @@ void cfg80211_stop_iface(struct wiphy *w
2188   */
2189  void cfg80211_shutdown_all_interfaces(struct wiphy *wiphy);
2190  
2191 +
2192 +/* ethtool helper */
2193 +void cfg80211_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info);
2194 +
2195  /* Logging, debugging and troubleshooting/diagnostic helpers. */
2196  
2197  /* wiphy_printk helpers, similar to dev_printk */
2198 --- a/net/mac80211/Makefile
2199 +++ b/net/mac80211/Makefile
2200 @@ -17,6 +17,7 @@ mac80211-y := \
2201         aes_ccm.o \
2202         aes_cmac.o \
2203         cfg.o \
2204 +       ethtool.o \
2205         rx.o \
2206         spectmgmt.o \
2207         tx.o \
2208 --- a/net/mac80211/ieee80211_i.h
2209 +++ b/net/mac80211/ieee80211_i.h
2210 @@ -229,16 +229,29 @@ struct ieee80211_rx_data {
2211         u16 tkip_iv16;
2212  };
2213  
2214 +struct ieee80211_csa_settings {
2215 +       const u16 *counter_offsets_beacon;
2216 +       const u16 *counter_offsets_presp;
2217 +
2218 +       int n_counter_offsets_beacon;
2219 +       int n_counter_offsets_presp;
2220 +
2221 +       u8 count;
2222 +};
2223 +
2224  struct beacon_data {
2225         u8 *head, *tail;
2226         int head_len, tail_len;
2227         struct ieee80211_meshconf_ie *meshconf;
2228 +       u16 csa_counter_offsets[IEEE80211_MAX_CSA_COUNTERS_NUM];
2229 +       u8 csa_current_counter;
2230         struct rcu_head rcu_head;
2231  };
2232  
2233  struct probe_resp {
2234         struct rcu_head rcu_head;
2235         int len;
2236 +       u16 csa_counter_offsets[IEEE80211_MAX_CSA_COUNTERS_NUM];
2237         u8 data[0];
2238  };
2239  
2240 @@ -754,8 +767,6 @@ struct ieee80211_sub_if_data {
2241         struct mac80211_qos_map __rcu *qos_map;
2242  
2243         struct work_struct csa_finalize_work;
2244 -       u16 csa_counter_offset_beacon[IEEE80211_MAX_CSA_COUNTERS_NUM];
2245 -       u16 csa_counter_offset_presp[IEEE80211_MAX_CSA_COUNTERS_NUM];
2246         bool csa_radar_required;
2247         bool csa_block_tx; /* write-protected by sdata_lock and local->mtx */
2248         struct cfg80211_chan_def csa_chandef;
2249 @@ -767,7 +778,6 @@ struct ieee80211_sub_if_data {
2250         struct ieee80211_chanctx *reserved_chanctx;
2251         struct cfg80211_chan_def reserved_chandef;
2252         bool reserved_radar_required;
2253 -       u8 csa_current_counter;
2254  
2255         /* used to reconfigure hardware SM PS */
2256         struct work_struct recalc_smps;
2257 @@ -1850,6 +1860,8 @@ int ieee80211_tdls_oper(struct wiphy *wi
2258                         const u8 *peer, enum nl80211_tdls_operation oper);
2259  
2260  
2261 +extern const struct ethtool_ops ieee80211_ethtool_ops;
2262 +
2263  #ifdef CPTCFG_MAC80211_NOINLINE
2264  #define debug_noinline noinline
2265  #else
2266 --- a/net/mac80211/iface.c
2267 +++ b/net/mac80211/iface.c
2268 @@ -399,6 +399,7 @@ int ieee80211_add_virtual_monitor(struct
2269         sdata->vif.type = NL80211_IFTYPE_MONITOR;
2270         snprintf(sdata->name, IFNAMSIZ, "%s-monitor",
2271                  wiphy_name(local->hw.wiphy));
2272 +       sdata->wdev.iftype = NL80211_IFTYPE_MONITOR;
2273  
2274         sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
2275  
2276 @@ -1303,6 +1304,7 @@ static void ieee80211_setup_sdata(struct
2277         sdata->control_port_protocol = cpu_to_be16(ETH_P_PAE);
2278         sdata->control_port_no_encrypt = false;
2279         sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
2280 +       sdata->vif.bss_conf.idle = true;
2281  
2282         sdata->noack_map = 0;
2283  
2284 @@ -1721,6 +1723,8 @@ int ieee80211_if_add(struct ieee80211_lo
2285  
2286                 ndev->features |= local->hw.netdev_features;
2287  
2288 +               netdev_set_default_ethtool_ops(ndev, &ieee80211_ethtool_ops);
2289 +
2290                 ret = register_netdevice(ndev);
2291                 if (ret) {
2292                         free_netdev(ndev);
2293 --- a/net/wireless/core.c
2294 +++ b/net/wireless/core.c
2295 @@ -25,7 +25,6 @@
2296  #include "sysfs.h"
2297  #include "debugfs.h"
2298  #include "wext-compat.h"
2299 -#include "ethtool.h"
2300  #include "rdev-ops.h"
2301  
2302  /* name for sysfs, %d is appended */
2303 @@ -940,8 +939,6 @@ static int cfg80211_netdev_notifier_call
2304                 /* allow mac80211 to determine the timeout */
2305                 wdev->ps_timeout = -1;
2306  
2307 -               netdev_set_default_ethtool_ops(dev, &cfg80211_ethtool_ops);
2308 -
2309                 if ((wdev->iftype == NL80211_IFTYPE_STATION ||
2310                      wdev->iftype == NL80211_IFTYPE_P2P_CLIENT ||
2311                      wdev->iftype == NL80211_IFTYPE_ADHOC) && !wdev->use_4addr)
2312 --- a/net/wireless/ethtool.c
2313 +++ b/net/wireless/ethtool.c
2314 @@ -1,11 +1,9 @@
2315  #include <linux/utsname.h>
2316  #include <net/cfg80211.h>
2317  #include "core.h"
2318 -#include "ethtool.h"
2319  #include "rdev-ops.h"
2320  
2321 -static void cfg80211_get_drvinfo(struct net_device *dev,
2322 -                                       struct ethtool_drvinfo *info)
2323 +void cfg80211_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
2324  {
2325         struct wireless_dev *wdev = dev->ieee80211_ptr;
2326  
2327 @@ -23,84 +21,4 @@ static void cfg80211_get_drvinfo(struct 
2328         strlcpy(info->bus_info, dev_name(wiphy_dev(wdev->wiphy)),
2329                 sizeof(info->bus_info));
2330  }
2331 -
2332 -static int cfg80211_get_regs_len(struct net_device *dev)
2333 -{
2334 -       /* For now, return 0... */
2335 -       return 0;
2336 -}
2337 -
2338 -static void cfg80211_get_regs(struct net_device *dev, struct ethtool_regs *regs,
2339 -                       void *data)
2340 -{
2341 -       struct wireless_dev *wdev = dev->ieee80211_ptr;
2342 -
2343 -       regs->version = wdev->wiphy->hw_version;
2344 -       regs->len = 0;
2345 -}
2346 -
2347 -static void cfg80211_get_ringparam(struct net_device *dev,
2348 -                                  struct ethtool_ringparam *rp)
2349 -{
2350 -       struct wireless_dev *wdev = dev->ieee80211_ptr;
2351 -       struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
2352 -
2353 -       memset(rp, 0, sizeof(*rp));
2354 -
2355 -       if (rdev->ops->get_ringparam)
2356 -               rdev_get_ringparam(rdev, &rp->tx_pending, &rp->tx_max_pending,
2357 -                                  &rp->rx_pending, &rp->rx_max_pending);
2358 -}
2359 -
2360 -static int cfg80211_set_ringparam(struct net_device *dev,
2361 -                                 struct ethtool_ringparam *rp)
2362 -{
2363 -       struct wireless_dev *wdev = dev->ieee80211_ptr;
2364 -       struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
2365 -
2366 -       if (rp->rx_mini_pending != 0 || rp->rx_jumbo_pending != 0)
2367 -               return -EINVAL;
2368 -
2369 -       if (rdev->ops->set_ringparam)
2370 -               return rdev_set_ringparam(rdev, rp->tx_pending, rp->rx_pending);
2371 -
2372 -       return -ENOTSUPP;
2373 -}
2374 -
2375 -static int cfg80211_get_sset_count(struct net_device *dev, int sset)
2376 -{
2377 -       struct wireless_dev *wdev = dev->ieee80211_ptr;
2378 -       struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
2379 -       if (rdev->ops->get_et_sset_count)
2380 -               return rdev_get_et_sset_count(rdev, dev, sset);
2381 -       return -EOPNOTSUPP;
2382 -}
2383 -
2384 -static void cfg80211_get_stats(struct net_device *dev,
2385 -                              struct ethtool_stats *stats, u64 *data)
2386 -{
2387 -       struct wireless_dev *wdev = dev->ieee80211_ptr;
2388 -       struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
2389 -       if (rdev->ops->get_et_stats)
2390 -               rdev_get_et_stats(rdev, dev, stats, data);
2391 -}
2392 -
2393 -static void cfg80211_get_strings(struct net_device *dev, u32 sset, u8 *data)
2394 -{
2395 -       struct wireless_dev *wdev = dev->ieee80211_ptr;
2396 -       struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
2397 -       if (rdev->ops->get_et_strings)
2398 -               rdev_get_et_strings(rdev, dev, sset, data);
2399 -}
2400 -
2401 -const struct ethtool_ops cfg80211_ethtool_ops = {
2402 -       .get_drvinfo = cfg80211_get_drvinfo,
2403 -       .get_regs_len = cfg80211_get_regs_len,
2404 -       .get_regs = cfg80211_get_regs,
2405 -       .get_link = ethtool_op_get_link,
2406 -       .get_ringparam = cfg80211_get_ringparam,
2407 -       .set_ringparam = cfg80211_set_ringparam,
2408 -       .get_strings = cfg80211_get_strings,
2409 -       .get_ethtool_stats = cfg80211_get_stats,
2410 -       .get_sset_count = cfg80211_get_sset_count,
2411 -};
2412 +EXPORT_SYMBOL(cfg80211_get_drvinfo);
2413 --- a/net/wireless/ethtool.h
2414 +++ /dev/null
2415 @@ -1,6 +0,0 @@
2416 -#ifndef __CFG80211_ETHTOOL__
2417 -#define __CFG80211_ETHTOOL__
2418 -
2419 -extern const struct ethtool_ops cfg80211_ethtool_ops;
2420 -
2421 -#endif /* __CFG80211_ETHTOOL__ */
2422 --- a/net/wireless/rdev-ops.h
2423 +++ b/net/wireless/rdev-ops.h
2424 @@ -714,25 +714,6 @@ static inline int rdev_get_antenna(struc
2425         return ret;
2426  }
2427  
2428 -static inline int rdev_set_ringparam(struct cfg80211_registered_device *rdev,
2429 -                                    u32 tx, u32 rx)
2430 -{
2431 -       int ret;
2432 -       trace_rdev_set_ringparam(&rdev->wiphy, tx, rx);
2433 -       ret = rdev->ops->set_ringparam(&rdev->wiphy, tx, rx);
2434 -       trace_rdev_return_int(&rdev->wiphy, ret);
2435 -       return ret;
2436 -}
2437 -
2438 -static inline void rdev_get_ringparam(struct cfg80211_registered_device *rdev,
2439 -                                     u32 *tx, u32 *tx_max, u32 *rx,
2440 -                                     u32 *rx_max)
2441 -{
2442 -       trace_rdev_get_ringparam(&rdev->wiphy);
2443 -       rdev->ops->get_ringparam(&rdev->wiphy, tx, tx_max, rx, rx_max);
2444 -       trace_rdev_return_void_tx_rx(&rdev->wiphy, *tx, *tx_max, *rx, *rx_max);
2445 -}
2446 -
2447  static inline int
2448  rdev_sched_scan_start(struct cfg80211_registered_device *rdev,
2449                       struct net_device *dev,
2450 @@ -816,35 +797,6 @@ static inline int rdev_set_noack_map(str
2451  }
2452  
2453  static inline int
2454 -rdev_get_et_sset_count(struct cfg80211_registered_device *rdev,
2455 -                      struct net_device *dev, int sset)
2456 -{
2457 -       int ret;
2458 -       trace_rdev_get_et_sset_count(&rdev->wiphy, dev, sset);
2459 -       ret = rdev->ops->get_et_sset_count(&rdev->wiphy, dev, sset);
2460 -       trace_rdev_return_int(&rdev->wiphy, ret);
2461 -       return ret;
2462 -}
2463 -
2464 -static inline void rdev_get_et_stats(struct cfg80211_registered_device *rdev,
2465 -                                    struct net_device *dev,
2466 -                                    struct ethtool_stats *stats, u64 *data)
2467 -{
2468 -       trace_rdev_get_et_stats(&rdev->wiphy, dev);
2469 -       rdev->ops->get_et_stats(&rdev->wiphy, dev, stats, data);
2470 -       trace_rdev_return_void(&rdev->wiphy);
2471 -}
2472 -
2473 -static inline void rdev_get_et_strings(struct cfg80211_registered_device *rdev,
2474 -                                      struct net_device *dev, u32 sset,
2475 -                                      u8 *data)
2476 -{
2477 -       trace_rdev_get_et_strings(&rdev->wiphy, dev, sset);
2478 -       rdev->ops->get_et_strings(&rdev->wiphy, dev, sset, data);
2479 -       trace_rdev_return_void(&rdev->wiphy);
2480 -}
2481 -
2482 -static inline int
2483  rdev_get_channel(struct cfg80211_registered_device *rdev,
2484                  struct wireless_dev *wdev,
2485                  struct cfg80211_chan_def *chandef)
2486 --- a/net/wireless/trace.h
2487 +++ b/net/wireless/trace.h
2488 @@ -298,11 +298,6 @@ DEFINE_EVENT(wiphy_only_evt, rdev_return
2489         TP_ARGS(wiphy)
2490  );
2491  
2492 -DEFINE_EVENT(wiphy_only_evt, rdev_get_ringparam,
2493 -       TP_PROTO(struct wiphy *wiphy),
2494 -       TP_ARGS(wiphy)
2495 -);
2496 -
2497  DEFINE_EVENT(wiphy_only_evt, rdev_get_antenna,
2498         TP_PROTO(struct wiphy *wiphy),
2499         TP_ARGS(wiphy)
2500 @@ -580,11 +575,6 @@ DEFINE_EVENT(wiphy_netdev_evt, rdev_stop
2501         TP_ARGS(wiphy, netdev)
2502  );
2503  
2504 -DEFINE_EVENT(wiphy_netdev_evt, rdev_get_et_stats,
2505 -       TP_PROTO(struct wiphy *wiphy, struct net_device *netdev),
2506 -       TP_ARGS(wiphy, netdev)
2507 -);
2508 -
2509  DEFINE_EVENT(wiphy_netdev_evt, rdev_sched_scan_stop,
2510         TP_PROTO(struct wiphy *wiphy, struct net_device *netdev),
2511         TP_ARGS(wiphy, netdev)
2512 @@ -1439,11 +1429,6 @@ DECLARE_EVENT_CLASS(tx_rx_evt,
2513                   WIPHY_PR_ARG, __entry->tx, __entry->rx)
2514  );
2515  
2516 -DEFINE_EVENT(tx_rx_evt, rdev_set_ringparam,
2517 -       TP_PROTO(struct wiphy *wiphy, u32 tx, u32 rx),
2518 -       TP_ARGS(wiphy, rx, tx)
2519 -);
2520 -
2521  DEFINE_EVENT(tx_rx_evt, rdev_set_antenna,
2522         TP_PROTO(struct wiphy *wiphy, u32 tx, u32 rx),
2523         TP_ARGS(wiphy, rx, tx)
2524 @@ -1725,40 +1710,6 @@ TRACE_EVENT(rdev_set_noack_map,
2525                   WIPHY_PR_ARG, NETDEV_PR_ARG, __entry->noack_map)
2526  );
2527  
2528 -TRACE_EVENT(rdev_get_et_sset_count,
2529 -       TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, int sset),
2530 -       TP_ARGS(wiphy, netdev, sset),
2531 -       TP_STRUCT__entry(
2532 -               WIPHY_ENTRY
2533 -               NETDEV_ENTRY
2534 -               __field(int, sset)
2535 -       ),
2536 -       TP_fast_assign(
2537 -               WIPHY_ASSIGN;
2538 -               NETDEV_ASSIGN;
2539 -               __entry->sset = sset;
2540 -       ),
2541 -       TP_printk(WIPHY_PR_FMT ", " NETDEV_PR_FMT ", sset: %d",
2542 -                 WIPHY_PR_ARG, NETDEV_PR_ARG, __entry->sset)
2543 -);
2544 -
2545 -TRACE_EVENT(rdev_get_et_strings,
2546 -       TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, u32 sset),
2547 -       TP_ARGS(wiphy, netdev, sset),
2548 -       TP_STRUCT__entry(
2549 -               WIPHY_ENTRY
2550 -               NETDEV_ENTRY
2551 -               __field(u32, sset)
2552 -       ),
2553 -       TP_fast_assign(
2554 -               WIPHY_ASSIGN;
2555 -               NETDEV_ASSIGN;
2556 -               __entry->sset = sset;
2557 -       ),
2558 -       TP_printk(WIPHY_PR_FMT ", " NETDEV_PR_FMT ", sset: %u",
2559 -                 WIPHY_PR_ARG, NETDEV_PR_ARG, __entry->sset)
2560 -);
2561 -
2562  DEFINE_EVENT(wiphy_wdev_evt, rdev_get_channel,
2563         TP_PROTO(struct wiphy *wiphy, struct wireless_dev *wdev),
2564         TP_ARGS(wiphy, wdev)
2565 --- /dev/null
2566 +++ b/net/mac80211/ethtool.c
2567 @@ -0,0 +1,244 @@
2568 +/*
2569 + * mac80211 ethtool hooks for cfg80211
2570 + *
2571 + * Copied from cfg.c - originally
2572 + * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
2573 + * Copyright 2014      Intel Corporation (Author: Johannes Berg)
2574 + *
2575 + * This file is GPLv2 as found in COPYING.
2576 + */
2577 +#include <linux/types.h>
2578 +#include <net/cfg80211.h>
2579 +#include "ieee80211_i.h"
2580 +#include "sta_info.h"
2581 +#include "driver-ops.h"
2582 +
2583 +static int ieee80211_set_ringparam(struct net_device *dev,
2584 +                                  struct ethtool_ringparam *rp)
2585 +{
2586 +       struct ieee80211_local *local = wiphy_priv(dev->ieee80211_ptr->wiphy);
2587 +
2588 +       if (rp->rx_mini_pending != 0 || rp->rx_jumbo_pending != 0)
2589 +               return -EINVAL;
2590 +
2591 +       return drv_set_ringparam(local, rp->tx_pending, rp->rx_pending);
2592 +}
2593 +
2594 +static void ieee80211_get_ringparam(struct net_device *dev,
2595 +                                   struct ethtool_ringparam *rp)
2596 +{
2597 +       struct ieee80211_local *local = wiphy_priv(dev->ieee80211_ptr->wiphy);
2598 +
2599 +       memset(rp, 0, sizeof(*rp));
2600 +
2601 +       drv_get_ringparam(local, &rp->tx_pending, &rp->tx_max_pending,
2602 +                         &rp->rx_pending, &rp->rx_max_pending);
2603 +}
2604 +
2605 +static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
2606 +       "rx_packets", "rx_bytes",
2607 +       "rx_duplicates", "rx_fragments", "rx_dropped",
2608 +       "tx_packets", "tx_bytes", "tx_fragments",
2609 +       "tx_filtered", "tx_retry_failed", "tx_retries",
2610 +       "beacon_loss", "sta_state", "txrate", "rxrate", "signal",
2611 +       "channel", "noise", "ch_time", "ch_time_busy",
2612 +       "ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
2613 +};
2614 +#define STA_STATS_LEN  ARRAY_SIZE(ieee80211_gstrings_sta_stats)
2615 +
2616 +static int ieee80211_get_sset_count(struct net_device *dev, int sset)
2617 +{
2618 +       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2619 +       int rv = 0;
2620 +
2621 +       if (sset == ETH_SS_STATS)
2622 +               rv += STA_STATS_LEN;
2623 +
2624 +       rv += drv_get_et_sset_count(sdata, sset);
2625 +
2626 +       if (rv == 0)
2627 +               return -EOPNOTSUPP;
2628 +       return rv;
2629 +}
2630 +
2631 +static void ieee80211_get_stats(struct net_device *dev,
2632 +                               struct ethtool_stats *stats,
2633 +                               u64 *data)
2634 +{
2635 +       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2636 +       struct ieee80211_chanctx_conf *chanctx_conf;
2637 +       struct ieee80211_channel *channel;
2638 +       struct sta_info *sta;
2639 +       struct ieee80211_local *local = sdata->local;
2640 +       struct station_info sinfo;
2641 +       struct survey_info survey;
2642 +       int i, q;
2643 +#define STA_STATS_SURVEY_LEN 7
2644 +
2645 +       memset(data, 0, sizeof(u64) * STA_STATS_LEN);
2646 +
2647 +#define ADD_STA_STATS(sta)                             \
2648 +       do {                                            \
2649 +               data[i++] += sta->rx_packets;           \
2650 +               data[i++] += sta->rx_bytes;             \
2651 +               data[i++] += sta->num_duplicates;       \
2652 +               data[i++] += sta->rx_fragments;         \
2653 +               data[i++] += sta->rx_dropped;           \
2654 +                                                       \
2655 +               data[i++] += sinfo.tx_packets;          \
2656 +               data[i++] += sinfo.tx_bytes;            \
2657 +               data[i++] += sta->tx_fragments;         \
2658 +               data[i++] += sta->tx_filtered_count;    \
2659 +               data[i++] += sta->tx_retry_failed;      \
2660 +               data[i++] += sta->tx_retry_count;       \
2661 +               data[i++] += sta->beacon_loss_count;    \
2662 +       } while (0)
2663 +
2664 +       /* For Managed stations, find the single station based on BSSID
2665 +        * and use that.  For interface types, iterate through all available
2666 +        * stations and add stats for any station that is assigned to this
2667 +        * network device.
2668 +        */
2669 +
2670 +       mutex_lock(&local->sta_mtx);
2671 +
2672 +       if (sdata->vif.type == NL80211_IFTYPE_STATION) {
2673 +               sta = sta_info_get_bss(sdata, sdata->u.mgd.bssid);
2674 +
2675 +               if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
2676 +                       goto do_survey;
2677 +
2678 +               sinfo.filled = 0;
2679 +               sta_set_sinfo(sta, &sinfo);
2680 +
2681 +               i = 0;
2682 +               ADD_STA_STATS(sta);
2683 +
2684 +               data[i++] = sta->sta_state;
2685 +
2686 +
2687 +               if (sinfo.filled & STATION_INFO_TX_BITRATE)
2688 +                       data[i] = 100000 *
2689 +                               cfg80211_calculate_bitrate(&sinfo.txrate);
2690 +               i++;
2691 +               if (sinfo.filled & STATION_INFO_RX_BITRATE)
2692 +                       data[i] = 100000 *
2693 +                               cfg80211_calculate_bitrate(&sinfo.rxrate);
2694 +               i++;
2695 +
2696 +               if (sinfo.filled & STATION_INFO_SIGNAL_AVG)
2697 +                       data[i] = (u8)sinfo.signal_avg;
2698 +               i++;
2699 +       } else {
2700 +               list_for_each_entry(sta, &local->sta_list, list) {
2701 +                       /* Make sure this station belongs to the proper dev */
2702 +                       if (sta->sdata->dev != dev)
2703 +                               continue;
2704 +
2705 +                       sinfo.filled = 0;
2706 +                       sta_set_sinfo(sta, &sinfo);
2707 +                       i = 0;
2708 +                       ADD_STA_STATS(sta);
2709 +               }
2710 +       }
2711 +
2712 +do_survey:
2713 +       i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
2714 +       /* Get survey stats for current channel */
2715 +       survey.filled = 0;
2716 +
2717 +       rcu_read_lock();
2718 +       chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2719 +       if (chanctx_conf)
2720 +               channel = chanctx_conf->def.chan;
2721 +       else
2722 +               channel = NULL;
2723 +       rcu_read_unlock();
2724 +
2725 +       if (channel) {
2726 +               q = 0;
2727 +               do {
2728 +                       survey.filled = 0;
2729 +                       if (drv_get_survey(local, q, &survey) != 0) {
2730 +                               survey.filled = 0;
2731 +                               break;
2732 +                       }
2733 +                       q++;
2734 +               } while (channel != survey.channel);
2735 +       }
2736 +
2737 +       if (survey.filled)
2738 +               data[i++] = survey.channel->center_freq;
2739 +       else
2740 +               data[i++] = 0;
2741 +       if (survey.filled & SURVEY_INFO_NOISE_DBM)
2742 +               data[i++] = (u8)survey.noise;
2743 +       else
2744 +               data[i++] = -1LL;
2745 +       if (survey.filled & SURVEY_INFO_CHANNEL_TIME)
2746 +               data[i++] = survey.channel_time;
2747 +       else
2748 +               data[i++] = -1LL;
2749 +       if (survey.filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
2750 +               data[i++] = survey.channel_time_busy;
2751 +       else
2752 +               data[i++] = -1LL;
2753 +       if (survey.filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
2754 +               data[i++] = survey.channel_time_ext_busy;
2755 +       else
2756 +               data[i++] = -1LL;
2757 +       if (survey.filled & SURVEY_INFO_CHANNEL_TIME_RX)
2758 +               data[i++] = survey.channel_time_rx;
2759 +       else
2760 +               data[i++] = -1LL;
2761 +       if (survey.filled & SURVEY_INFO_CHANNEL_TIME_TX)
2762 +               data[i++] = survey.channel_time_tx;
2763 +       else
2764 +               data[i++] = -1LL;
2765 +
2766 +       mutex_unlock(&local->sta_mtx);
2767 +
2768 +       if (WARN_ON(i != STA_STATS_LEN))
2769 +               return;
2770 +
2771 +       drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
2772 +}
2773 +
2774 +static void ieee80211_get_strings(struct net_device *dev, u32 sset, u8 *data)
2775 +{
2776 +       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2777 +       int sz_sta_stats = 0;
2778 +
2779 +       if (sset == ETH_SS_STATS) {
2780 +               sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
2781 +               memcpy(data, ieee80211_gstrings_sta_stats, sz_sta_stats);
2782 +       }
2783 +       drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
2784 +}
2785 +
2786 +static int ieee80211_get_regs_len(struct net_device *dev)
2787 +{
2788 +       return 0;
2789 +}
2790 +
2791 +static void ieee80211_get_regs(struct net_device *dev,
2792 +                              struct ethtool_regs *regs,
2793 +                              void *data)
2794 +{
2795 +       struct wireless_dev *wdev = dev->ieee80211_ptr;
2796 +
2797 +       regs->version = wdev->wiphy->hw_version;
2798 +       regs->len = 0;
2799 +}
2800 +
2801 +const struct ethtool_ops ieee80211_ethtool_ops = {
2802 +       .get_drvinfo = cfg80211_get_drvinfo,
2803 +       .get_regs_len = ieee80211_get_regs_len,
2804 +       .get_regs = ieee80211_get_regs,
2805 +       .get_link = ethtool_op_get_link,
2806 +       .get_ringparam = ieee80211_get_ringparam,
2807 +       .set_ringparam = ieee80211_set_ringparam,
2808 +       .get_strings = ieee80211_get_strings,
2809 +       .get_ethtool_stats = ieee80211_get_stats,
2810 +       .get_sset_count = ieee80211_get_sset_count,
2811 +};
2812 --- a/net/mac80211/ibss.c
2813 +++ b/net/mac80211/ibss.c
2814 @@ -143,7 +143,7 @@ ieee80211_ibss_build_presp(struct ieee80
2815                 *pos++ = csa_settings->block_tx ? 1 : 0;
2816                 *pos++ = ieee80211_frequency_to_channel(
2817                                 csa_settings->chandef.chan->center_freq);
2818 -               sdata->csa_counter_offset_beacon[0] = (pos - presp->head);
2819 +               presp->csa_counter_offsets[0] = (pos - presp->head);
2820                 *pos++ = csa_settings->count;
2821         }
2822  
2823 @@ -1677,6 +1677,7 @@ int ieee80211_ibss_join(struct ieee80211
2824         sdata->u.ibss.control_port = params->control_port;
2825         sdata->u.ibss.userspace_handles_dfs = params->userspace_handles_dfs;
2826         sdata->u.ibss.basic_rates = params->basic_rates;
2827 +       sdata->u.ibss.last_scan_completed = jiffies;
2828  
2829         /* fix basic_rates if channel does not support these rates */
2830         rate_flags = ieee80211_chandef_rate_flags(&params->chandef);
2831 --- a/net/mac80211/mesh.c
2832 +++ b/net/mac80211/mesh.c
2833 @@ -679,7 +679,7 @@ ieee80211_mesh_build_beacon(struct ieee8
2834                 *pos++ = 0x0;
2835                 *pos++ = ieee80211_frequency_to_channel(
2836                                 csa->settings.chandef.chan->center_freq);
2837 -               sdata->csa_counter_offset_beacon[0] = hdr_len + 6;
2838 +               bcn->csa_counter_offsets[0] = hdr_len + 6;
2839                 *pos++ = csa->settings.count;
2840                 *pos++ = WLAN_EID_CHAN_SWITCH_PARAM;
2841                 *pos++ = 6;
2842 --- a/net/wireless/genregdb.awk
2843 +++ b/net/wireless/genregdb.awk
2844 @@ -65,17 +65,7 @@ function parse_reg_rule()
2845         sub(/,/, "", units)
2846         dfs_cac = $9
2847         if (units == "mW") {
2848 -               if (power == 100) {
2849 -                       power = 20
2850 -               } else if (power == 200) {
2851 -                       power = 23
2852 -               } else if (power == 500) {
2853 -                       power = 27
2854 -               } else if (power == 1000) {
2855 -                       power = 30
2856 -               } else {
2857 -                       print "Unknown power value in database!"
2858 -               }
2859 +               power = 10 * log(power)/log(10)
2860         } else {
2861                 dfs_cac = $8
2862         }
2863 @@ -114,7 +104,7 @@ function parse_reg_rule()
2864  
2865         }
2866         flags = flags "0"
2867 -       printf "\t\tREG_RULE_EXT(%d, %d, %d, %d, %d, %d, %s),\n", start, end, bw, gain, power, dfs_cac, flags
2868 +       printf "\t\tREG_RULE_EXT(%d, %d, %d, %d, %.0f, %d, %s),\n", start, end, bw, gain, power, dfs_cac, flags
2869         rules++
2870  }
2871  
2872 --- a/net/mac80211/debugfs_netdev.c
2873 +++ b/net/mac80211/debugfs_netdev.c
2874 @@ -34,8 +34,7 @@ static ssize_t ieee80211_if_read(
2875         ssize_t ret = -EINVAL;
2876  
2877         read_lock(&dev_base_lock);
2878 -       if (sdata->dev->reg_state == NETREG_REGISTERED)
2879 -               ret = (*format)(sdata, buf, sizeof(buf));
2880 +       ret = (*format)(sdata, buf, sizeof(buf));
2881         read_unlock(&dev_base_lock);
2882  
2883         if (ret >= 0)
2884 @@ -62,8 +61,7 @@ static ssize_t ieee80211_if_write(
2885  
2886         ret = -ENODEV;
2887         rtnl_lock();
2888 -       if (sdata->dev->reg_state == NETREG_REGISTERED)
2889 -               ret = (*write)(sdata, buf, count);
2890 +       ret = (*write)(sdata, buf, count);
2891         rtnl_unlock();
2892  
2893         return ret;
2894 --- a/drivers/net/wireless/b43/xmit.c
2895 +++ b/drivers/net/wireless/b43/xmit.c
2896 @@ -811,9 +811,13 @@ void b43_rx(struct b43_wldev *dev, struc
2897                 break;
2898         case B43_PHYTYPE_G:
2899                 status.band = IEEE80211_BAND_2GHZ;
2900 -               /* chanid is the radio channel cookie value as used
2901 -                * to tune the radio. */
2902 -               status.freq = chanid + 2400;
2903 +               /* Somewhere between 478.104 and 508.1084 firmware for G-PHY
2904 +                * has been modified to be compatible with N-PHY and others.
2905 +                */
2906 +               if (dev->fw.rev >= 508)
2907 +                       status.freq = ieee80211_channel_to_frequency(chanid, status.band);
2908 +               else
2909 +                       status.freq = chanid + 2400;
2910                 break;
2911         case B43_PHYTYPE_N:
2912         case B43_PHYTYPE_LP:
2913 --- a/drivers/net/wireless/b43/main.c
2914 +++ b/drivers/net/wireless/b43/main.c
2915 @@ -5216,6 +5216,7 @@ static int b43_wireless_core_attach(stru
2916         /* We don't support 5 GHz on some PHYs yet */
2917         switch (dev->phy.type) {
2918         case B43_PHYTYPE_A:
2919 +       case B43_PHYTYPE_G:
2920         case B43_PHYTYPE_N:
2921         case B43_PHYTYPE_LP:
2922         case B43_PHYTYPE_HT:
2923 --- a/net/wireless/reg.c
2924 +++ b/net/wireless/reg.c
2925 @@ -935,7 +935,7 @@ freq_reg_info_regd(struct wiphy *wiphy, 
2926                 if (!band_rule_found)
2927                         band_rule_found = freq_in_rule_band(fr, center_freq);
2928  
2929 -               bw_fits = reg_does_bw_fit(fr, center_freq, MHZ_TO_KHZ(5));
2930 +               bw_fits = reg_does_bw_fit(fr, center_freq, MHZ_TO_KHZ(20));
2931  
2932                 if (band_rule_found && bw_fits)
2933                         return rr;
2934 @@ -1019,10 +1019,10 @@ static void chan_reg_rule_print_dbg(cons
2935  }
2936  #endif
2937  
2938 -/* Find an ieee80211_reg_rule such that a 5MHz channel with frequency
2939 - * chan->center_freq fits there.
2940 - * If there is no such reg_rule, disable the channel, otherwise set the
2941 - * flags corresponding to the bandwidths allowed in the particular reg_rule
2942 +/*
2943 + * Note that right now we assume the desired channel bandwidth
2944 + * is always 20 MHz for each individual channel (HT40 uses 20 MHz
2945 + * per channel, the primary and the extension channel).
2946   */
2947  static void handle_channel(struct wiphy *wiphy,
2948                            enum nl80211_reg_initiator initiator,
2949 @@ -1083,12 +1083,8 @@ static void handle_channel(struct wiphy 
2950         if (reg_rule->flags & NL80211_RRF_AUTO_BW)
2951                 max_bandwidth_khz = reg_get_max_bandwidth(regd, reg_rule);
2952  
2953 -       if (max_bandwidth_khz < MHZ_TO_KHZ(10))
2954 -               bw_flags = IEEE80211_CHAN_NO_10MHZ;
2955 -       if (max_bandwidth_khz < MHZ_TO_KHZ(20))
2956 -               bw_flags |= IEEE80211_CHAN_NO_20MHZ;
2957         if (max_bandwidth_khz < MHZ_TO_KHZ(40))
2958 -               bw_flags |= IEEE80211_CHAN_NO_HT40;
2959 +               bw_flags = IEEE80211_CHAN_NO_HT40;
2960         if (max_bandwidth_khz < MHZ_TO_KHZ(80))
2961                 bw_flags |= IEEE80211_CHAN_NO_80MHZ;
2962         if (max_bandwidth_khz < MHZ_TO_KHZ(160))
2963 @@ -1522,12 +1518,8 @@ static void handle_channel_custom(struct
2964         if (reg_rule->flags & NL80211_RRF_AUTO_BW)
2965                 max_bandwidth_khz = reg_get_max_bandwidth(regd, reg_rule);
2966  
2967 -       if (max_bandwidth_khz < MHZ_TO_KHZ(10))
2968 -               bw_flags = IEEE80211_CHAN_NO_10MHZ;
2969 -       if (max_bandwidth_khz < MHZ_TO_KHZ(20))
2970 -               bw_flags |= IEEE80211_CHAN_NO_20MHZ;
2971         if (max_bandwidth_khz < MHZ_TO_KHZ(40))
2972 -               bw_flags |= IEEE80211_CHAN_NO_HT40;
2973 +               bw_flags = IEEE80211_CHAN_NO_HT40;
2974         if (max_bandwidth_khz < MHZ_TO_KHZ(80))
2975                 bw_flags |= IEEE80211_CHAN_NO_80MHZ;
2976         if (max_bandwidth_khz < MHZ_TO_KHZ(160))
2977 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
2978 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
2979 @@ -185,7 +185,8 @@ struct ath_atx_ac {
2980  
2981  struct ath_frame_info {
2982         struct ath_buf *bf;
2983 -       int framelen;
2984 +       u16 framelen;
2985 +       s8 txq;
2986         enum ath9k_key_type keytype;
2987         u8 keyix;
2988         u8 rtscts_rate;
2989 --- a/drivers/net/wireless/ath/ath9k/xmit.c
2990 +++ b/drivers/net/wireless/ath/ath9k/xmit.c
2991 @@ -147,15 +147,13 @@ static void ath_set_rates(struct ieee802
2992  static void ath_txq_skb_done(struct ath_softc *sc, struct ath_txq *txq,
2993                              struct sk_buff *skb)
2994  {
2995 -       int q;
2996 -
2997 -       q = skb_get_queue_mapping(skb);
2998 -       if (txq == sc->tx.uapsdq)
2999 -               txq = sc->tx.txq_map[q];
3000 +       struct ath_frame_info *fi = get_frame_info(skb);
3001 +       int q = fi->txq;
3002  
3003 -       if (txq != sc->tx.txq_map[q])
3004 +       if (q < 0)
3005                 return;
3006  
3007 +       txq = sc->tx.txq_map[q];
3008         if (WARN_ON(--txq->pending_frames < 0))
3009                 txq->pending_frames = 0;
3010  
3011 @@ -887,6 +885,15 @@ ath_tx_get_tid_subframe(struct ath_softc
3012  
3013                 tx_info = IEEE80211_SKB_CB(skb);
3014                 tx_info->flags &= ~IEEE80211_TX_CTL_CLEAR_PS_FILT;
3015 +
3016 +               /*
3017 +                * No aggregation session is running, but there may be frames
3018 +                * from a previous session or a failed attempt in the queue.
3019 +                * Send them out as normal data frames
3020 +                */
3021 +               if (!tid->active)
3022 +                       tx_info->flags &= ~IEEE80211_TX_CTL_AMPDU;
3023 +
3024                 if (!(tx_info->flags & IEEE80211_TX_CTL_AMPDU)) {
3025                         bf->bf_state.bf_type = 0;
3026                         return bf;
3027 @@ -1999,6 +2006,7 @@ static void setup_frame_info(struct ieee
3028                 an = (struct ath_node *) sta->drv_priv;
3029  
3030         memset(fi, 0, sizeof(*fi));
3031 +       fi->txq = -1;
3032         if (hw_key)
3033                 fi->keyix = hw_key->hw_key_idx;
3034         else if (an && ieee80211_is_data(hdr->frame_control) && an->ps_key > 0)
3035 @@ -2150,6 +2158,7 @@ int ath_tx_start(struct ieee80211_hw *hw
3036         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3037         struct ieee80211_sta *sta = txctl->sta;
3038         struct ieee80211_vif *vif = info->control.vif;
3039 +       struct ath_frame_info *fi = get_frame_info(skb);
3040         struct ath_softc *sc = hw->priv;
3041         struct ath_txq *txq = txctl->txq;
3042         struct ath_atx_tid *tid = NULL;
3043 @@ -2170,11 +2179,13 @@ int ath_tx_start(struct ieee80211_hw *hw
3044         q = skb_get_queue_mapping(skb);
3045  
3046         ath_txq_lock(sc, txq);
3047 -       if (txq == sc->tx.txq_map[q] &&
3048 -           ++txq->pending_frames > sc->tx.txq_max_pending[q] &&
3049 -           !txq->stopped) {
3050 -               ieee80211_stop_queue(sc->hw, q);
3051 -               txq->stopped = true;
3052 +       if (txq == sc->tx.txq_map[q]) {
3053 +               fi->txq = q;
3054 +               if (++txq->pending_frames > sc->tx.txq_max_pending[q] &&
3055 +                   !txq->stopped) {
3056 +                       ieee80211_stop_queue(sc->hw, q);
3057 +                       txq->stopped = true;
3058 +               }
3059         }
3060  
3061         if (txctl->an && ieee80211_is_data_present(hdr->frame_control))