odhcpd: fix regression in dhcpv6 t1 and t2 calculation
[librecmc/librecmc.git] / package / kernel / mac80211 / patches / 300-pending_work.patch
1 commit 6fb7eefaa4d8377e6b124435059656dd6f643e91
2 Author: Karl Beldan <karl.beldan@rivierawaves.com>
3 Date:   Tue Oct 7 15:53:38 2014 +0200
4
5     mac80211/trivial: fix typo in starting baserate for rts_cts_rate_idx
6     
7     Fixes: 5253ffb8 ("mac80211: always pick a basic rate to tx RTS/CTS for pre-HT rates")
8     Signed-off-by: Karl Beldan <karl.beldan@rivierawaves.com>
9
10 commit b18111d911980af52bead74ee45250cc96ad5108
11 Author: Sujith Manoharan <c_manoha@qca.qualcomm.com>
12 Date:   Tue Oct 7 10:14:37 2014 +0530
13
14     ath9k: Fix crash in MCC mode
15     
16     When a channel context is removed, the hw_queue_base
17     is set to -1, this will result in a panic because
18     ath9k_chanctx_stop_queues() can be called on an interface
19     that is not assigned to any context yet - for example,
20     when trying to scan.
21     
22     Fix this issue by setting the hw_queue_base to zero
23     when a channel context is removed.
24     
25     Signed-off-by: Sujith Manoharan <c_manoha@qca.qualcomm.com>
26     Signed-off-by: John W. Linville <linville@tuxdriver.com>
27
28 commit e2cba8d7590e76661e86f1f0987ef9f8c13c9a6d
29 Author: Sujith Manoharan <c_manoha@qca.qualcomm.com>
30 Date:   Thu Oct 2 06:33:20 2014 +0530
31
32     ath9k: Fix flushing in MCC mode
33     
34     When we are attempting to switch to a new
35     channel context, the TX queues are flushed, but
36     the mac80211 queues are not stopped and traffic
37     can still come down to the driver.
38     
39     This patch fixes it by stopping the queues
40     assigned to the current context/vif before
41     trying to flush.
42     
43     Signed-off-by: Sujith Manoharan <c_manoha@qca.qualcomm.com>
44     Signed-off-by: John W. Linville <linville@tuxdriver.com>
45
46 commit 5ba8d9d2f018f2c4e23f9e68b90ca5b9d5470457
47 Author: Sujith Manoharan <c_manoha@qca.qualcomm.com>
48 Date:   Thu Oct 2 06:33:19 2014 +0530
49
50     ath9k: Fix queue handling for channel contexts
51     
52     When a full chip reset is done, all the queues
53     across all VIFs are stopped, but if MCC is enabled,
54     only the queues of the current context is awakened,
55     when we complete the reset.
56     
57     This results in unfairness for the inactive context.
58     Since frames are queued internally in the driver if
59     there is a context mismatch, we can awaken all the
60     queues when coming out of a reset.
61     
62     The VIF-specific queues are still used in flow control,
63     to ensure fairness when traffic is high.
64     
65     Signed-off-by: Sujith Manoharan <c_manoha@qca.qualcomm.com>
66     Signed-off-by: John W. Linville <linville@tuxdriver.com>
67
68 commit a064eaa10ca4ec58d5a405c9a7f87efc6d2fa423
69 Author: Sujith Manoharan <c_manoha@qca.qualcomm.com>
70 Date:   Thu Oct 2 06:33:18 2014 +0530
71
72     ath9k: Add ath9k_chanctx_stop_queues()
73     
74     This can be used when the queues of a context
75     needs to be stopped.
76     
77     Signed-off-by: Sujith Manoharan <c_manoha@qca.qualcomm.com>
78     Signed-off-by: John W. Linville <linville@tuxdriver.com>
79
80 commit b39031536aab9cb1324328cf46fa4ef940bd975f
81 Author: Sujith Manoharan <c_manoha@qca.qualcomm.com>
82 Date:   Thu Oct 2 06:33:17 2014 +0530
83
84     ath9k: Pass context to ath9k_chanctx_wake_queues()
85     
86     Change the ath9k_chanctx_wake_queues() API so
87     that we can pass the channel context that needs its
88     queues to be stopped.
89     
90     Signed-off-by: Sujith Manoharan <c_manoha@qca.qualcomm.com>
91     Signed-off-by: John W. Linville <linville@tuxdriver.com>
92
93 commit 4f82eecf73019c27537f65c160e90385e159afd8
94 Author: Sujith Manoharan <c_manoha@qca.qualcomm.com>
95 Date:   Thu Oct 2 06:33:16 2014 +0530
96
97     ath9k: Fix queue handling in flush()
98     
99     When draining of the TX queues fails, a
100     full HW reset is done. ath_reset() makes sure
101     that the queues in mac80211 are restarted,
102     so there is no need to wake them up again.
103     
104     Signed-off-by: Sujith Manoharan <c_manoha@qca.qualcomm.com>
105     Signed-off-by: John W. Linville <linville@tuxdriver.com>
106
107 commit 60913f4d2951f6410eed969aae4717c7ced37044
108 Author: Sujith Manoharan <c_manoha@qca.qualcomm.com>
109 Date:   Thu Oct 2 06:33:15 2014 +0530
110
111     ath9k: Remove duplicate code
112     
113     ath9k_has_tx_pending() can be used to
114     check if there are pending frames instead
115     of having duplicate code.
116     
117     Signed-off-by: Sujith Manoharan <c_manoha@qca.qualcomm.com>
118     Signed-off-by: John W. Linville <linville@tuxdriver.com>
119
120 commit fc1314c75e0558c03cb434e2af2c257caa201e76
121 Author: Sujith Manoharan <c_manoha@qca.qualcomm.com>
122 Date:   Thu Oct 2 06:33:14 2014 +0530
123
124     ath9k: Fix pending frame check
125     
126     Checking for the queue depth outside of
127     the TX queue lock is incorrect and in this
128     case, is not required since it is done inside
129     ath9k_has_pending_frames().
130     
131     Signed-off-by: Sujith Manoharan <c_manoha@qca.qualcomm.com>
132     Signed-off-by: John W. Linville <linville@tuxdriver.com>
133
134 commit b736728575af03488388e84fceac7bf0eac5dbb6
135 Author: Sujith Manoharan <c_manoha@qca.qualcomm.com>
136 Date:   Thu Oct 2 06:33:13 2014 +0530
137
138     ath9k: Check pending frames properly
139     
140     There is no need to check if the current
141     channel context has active ACs queued up
142     if the TX queue is not empty.
143     
144     Signed-off-by: Sujith Manoharan <c_manoha@qca.qualcomm.com>
145     Signed-off-by: John W. Linville <linville@tuxdriver.com>
146
147 commit 4b60af4ab4363bd79eeba94bb6bed396cf2aaf62
148 Author: Sujith Manoharan <c_manoha@qca.qualcomm.com>
149 Date:   Thu Oct 2 06:33:12 2014 +0530
150
151     ath9k: Print RoC expiration
152     
153     Signed-off-by: Sujith Manoharan <c_manoha@qca.qualcomm.com>
154     Signed-off-by: John W. Linville <linville@tuxdriver.com>
155
156 commit 4d9f634b02e4240f86719f30e4c9e62f6a4c4d36
157 Author: Sujith Manoharan <c_manoha@qca.qualcomm.com>
158 Date:   Tue Sep 30 14:15:23 2014 +0530
159
160     ath9k: Check early for HW reset
161     
162     chan_lock is not required for checking if
163     we are in the middle of a HW reset, so do it
164     early. This also removes the small window
165     where the lock is dropped and reacquired.
166     
167     Signed-off-by: Sujith Manoharan <c_manoha@qca.qualcomm.com>
168     Signed-off-by: John W. Linville <linville@tuxdriver.com>
169
170 commit c393d179924685d5c8c72446c5b6401f25fdb2a0
171 Author: Marek Puzyniak <marek.puzyniak@tieto.com>
172 Date:   Tue Oct 7 17:04:30 2014 +0200
173
174     ath9k_htc: avoid kernel panic in ath9k_hw_reset
175     
176     hw pointer of ath_hw is not assigned to proper value
177     in function ath9k_hw_reset what finally causes kernel panic.
178     This can be solved by proper initialization of ath_hw in
179     ath9k_init_priv.
180     
181     Signed-off-by: Marek Puzyniak <marek.puzyniak@tieto.com>
182     Acked-by: Oleksij Rempel <linux@rempel-privat.de>
183     Signed-off-by: John W. Linville <linville@tuxdriver.com>
184
185 commit 065e0b64f71632f5ad7f00c102fde09c534cfbf0
186 Author: Felix Fietkau <nbd@openwrt.org>
187 Date:   Tue Sep 30 11:00:33 2014 +0200
188
189     ath9k: fix getting tx duration for dynack
190     
191     On AR9003, tx control and tx status are in separate descriptor rings.
192     Tx duration is extracted from the tx control descriptor data, which
193     ar9003_hw_proc_txdesc cannot access.
194     
195     Fix getting the duration by adding a separate callback for it.
196     
197     Acked-by: Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
198     Signed-off-by: Felix Fietkau <nbd@openwrt.org>
199
200 commit fdf9a4517b60d847b9bc0a30249efd96559fa450
201 Author: Felix Fietkau <nbd@openwrt.org>
202 Date:   Tue Sep 9 09:48:30 2014 +0200
203
204     ath9k_hw: fix PLL clock initialization for newer SoC
205     
206     On AR934x and newer SoC devices, the layout of the AR_RTC_PLL_CONTROL
207     register changed. This currently breaks at least 5/10 MHz operation.
208     AR933x uses the old layout.
209     
210     It might also have been causing other stability issues because of the
211     different location of the PLL_BYPASS bit which needs to be set during
212     PLL clock initialization.
213     
214     This patch also removes more instances of hardcoded register values in
215     favor of properly computed ones with the PLL_BYPASS bit added.
216     
217     Reported-by: Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
218     Signed-off-by: Felix Fietkau <nbd@openwrt.org>
219
220 commit b6d1f51cd8bdc9d952147a960fbf1f261d8e4188
221 Author: Felix Fietkau <nbd@openwrt.org>
222 Date:   Mon Sep 8 18:35:08 2014 +0200
223
224     ath9k_hw: reduce ANI spur immunity setting on HT40 extension channel
225     
226     The cycpwr_thr1 value needs to be lower on the extension channel than on
227     the control channel, similar to how the register settings are programmed
228     in the initvals.
229     
230     Also drop the unnecessary check for HT40 - this register can always be
231     written. This patch has been reported to improve HT40 stability and
232     throughput in some environments.
233     
234     Signed-off-by: Felix Fietkau <nbd@openwrt.org>
235
236 commit 5ad2dfbaa19aa45d29184d30c8c5dae0e110074a
237 Author: Felix Fietkau <nbd@openwrt.org>
238 Date:   Mon Sep 8 18:31:26 2014 +0200
239
240     Revert "ath9k_hw: reduce ANI firstep range for older chips"
241     
242     This reverts commit 09efc56345be4146ab9fc87a55c837ed5d6ea1ab
243     
244     I've received reports that this change is decreasing throughput in some
245     rare conditions on an AR9280 based device
246     
247     Cc: stable@vger.kernel.org
248     Signed-off-by: Felix Fietkau <nbd@openwrt.org>
249
250 commit 4c82fc569cf2f29e6c66d98ef4a1b0f3b6a98e9d
251 Author: Felix Fietkau <nbd@openwrt.org>
252 Date:   Sat Sep 27 22:39:27 2014 +0200
253
254     ath9k_hw: disable hardware ad-hoc flag on ar934x rev 3
255     
256     On AR934x rev 3, settin the ad-hoc flag completely messes up hardware
257     state - beacons get stuck, almost no packets make it out, hardware is
258     constantly reset.
259     
260     When leaving out that flag and setting up the hw like in AP mode, TSF
261     timers won't be automatically synced, but at least the rest works.
262     
263     AR934x rev 2 and older are not affected by this bug
264     
265     Signed-off-by: Felix Fietkau <nbd@openwrt.org>
266
267 commit ecfb4b3fff006372ac5c40871f9bb182fd00444f
268 Author: Felix Fietkau <nbd@openwrt.org>
269 Date:   Sat Sep 27 22:15:43 2014 +0200
270
271     ath9k: use ah->get_mac_revision for all SoC devices if available
272     
273     It is needed for AR934x as well
274     
275     Signed-off-by: Felix Fietkau <nbd@openwrt.org>
276
277 commit c11113bc25df22898fb995d3205bdc4f27c98073
278 Author: Felix Fietkau <nbd@openwrt.org>
279 Date:   Sat Sep 27 18:04:58 2014 +0200
280
281     ath5k: add missing include for debug code
282     
283     Needed for calling vmalloc()/vfree()
284     
285     Signed-off-by: Felix Fietkau <nbd@openwrt.org>
286
287 commit 83f76a9f9a42773c7eef90bb86b4b2c16b0b3755
288 Author: Felix Fietkau <nbd@openwrt.org>
289 Date:   Sat Sep 27 15:58:51 2014 +0200
290
291     ath5k: fix AHB kconfig dependency
292     
293     Signed-off-by: Felix Fietkau <nbd@openwrt.org>
294
295 commit ddd67f2a5cfd73fad4b78190025402d419b9f0a9
296 Author: Felix Fietkau <nbd@openwrt.org>
297 Date:   Sat Sep 27 15:57:09 2014 +0200
298
299     Revert "ath5k: Remove AHB bus support"
300     
301     This reverts commit 093ec3c5337434f40d77c1af06c139da3e5ba6dc.
302
303 --- a/drivers/net/wireless/ath/ath5k/Kconfig
304 +++ b/drivers/net/wireless/ath/ath5k/Kconfig
305 @@ -2,12 +2,14 @@ config ATH5K
306         tristate "Atheros 5xxx wireless cards support"
307         depends on m
308         depends on PCI && MAC80211
309 +       depends on (PCI || ATHEROS_AR231X) && MAC80211
310         select ATH_COMMON
311         select MAC80211_LEDS
312         select BACKPORT_LEDS_CLASS
313         select BACKPORT_NEW_LEDS
314         select BACKPORT_AVERAGE
315 -       select ATH5K_PCI
316 +       select ATH5K_AHB if ATHEROS_AR231X
317 +       select ATH5K_PCI if !ATHEROS_AR231X
318         ---help---
319           This module adds support for wireless adapters based on
320           Atheros 5xxx chipset.
321 @@ -52,9 +54,16 @@ config ATH5K_TRACER
322  
323           If unsure, say N.
324  
325 +config ATH5K_AHB
326 +       bool "Atheros 5xxx AHB bus support"
327 +       depends on ATHEROS_AR231X
328 +       ---help---
329 +         This adds support for WiSoC type chipsets of the 5xxx Atheros
330 +         family.
331 +
332  config ATH5K_PCI
333         bool "Atheros 5xxx PCI bus support"
334 -       depends on PCI
335 +       depends on !ATHEROS_AR231X
336         ---help---
337           This adds support for PCI type chipsets of the 5xxx Atheros
338           family.
339 --- /dev/null
340 +++ b/drivers/net/wireless/ath/ath5k/ahb.c
341 @@ -0,0 +1,234 @@
342 +/*
343 + * Copyright (c) 2008-2009 Atheros Communications Inc.
344 + * Copyright (c) 2009 Gabor Juhos <juhosg@openwrt.org>
345 + * Copyright (c) 2009 Imre Kaloz <kaloz@openwrt.org>
346 + *
347 + * Permission to use, copy, modify, and/or distribute this software for any
348 + * purpose with or without fee is hereby granted, provided that the above
349 + * copyright notice and this permission notice appear in all copies.
350 + *
351 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
352 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
353 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
354 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
355 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
356 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
357 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
358 + */
359 +
360 +#include <linux/nl80211.h>
361 +#include <linux/platform_device.h>
362 +#include <linux/etherdevice.h>
363 +#include <linux/export.h>
364 +#include <ar231x_platform.h>
365 +#include "ath5k.h"
366 +#include "debug.h"
367 +#include "base.h"
368 +#include "reg.h"
369 +
370 +/* return bus cachesize in 4B word units */
371 +static void ath5k_ahb_read_cachesize(struct ath_common *common, int *csz)
372 +{
373 +       *csz = L1_CACHE_BYTES >> 2;
374 +}
375 +
376 +static bool
377 +ath5k_ahb_eeprom_read(struct ath_common *common, u32 off, u16 *data)
378 +{
379 +       struct ath5k_hw *ah = common->priv;
380 +       struct platform_device *pdev = to_platform_device(ah->dev);
381 +       struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
382 +       u16 *eeprom, *eeprom_end;
383 +
384 +       eeprom = (u16 *) bcfg->radio;
385 +       eeprom_end = ((void *) bcfg->config) + BOARD_CONFIG_BUFSZ;
386 +
387 +       eeprom += off;
388 +       if (eeprom > eeprom_end)
389 +               return false;
390 +
391 +       *data = *eeprom;
392 +       return true;
393 +}
394 +
395 +int ath5k_hw_read_srev(struct ath5k_hw *ah)
396 +{
397 +       struct platform_device *pdev = to_platform_device(ah->dev);
398 +       struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
399 +       ah->ah_mac_srev = bcfg->devid;
400 +       return 0;
401 +}
402 +
403 +static int ath5k_ahb_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
404 +{
405 +       struct platform_device *pdev = to_platform_device(ah->dev);
406 +       struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
407 +       u8 *cfg_mac;
408 +
409 +       if (to_platform_device(ah->dev)->id == 0)
410 +               cfg_mac = bcfg->config->wlan0_mac;
411 +       else
412 +               cfg_mac = bcfg->config->wlan1_mac;
413 +
414 +       memcpy(mac, cfg_mac, ETH_ALEN);
415 +       return 0;
416 +}
417 +
418 +static const struct ath_bus_ops ath_ahb_bus_ops = {
419 +       .ath_bus_type = ATH_AHB,
420 +       .read_cachesize = ath5k_ahb_read_cachesize,
421 +       .eeprom_read = ath5k_ahb_eeprom_read,
422 +       .eeprom_read_mac = ath5k_ahb_eeprom_read_mac,
423 +};
424 +
425 +/*Initialization*/
426 +static int ath_ahb_probe(struct platform_device *pdev)
427 +{
428 +       struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
429 +       struct ath5k_hw *ah;
430 +       struct ieee80211_hw *hw;
431 +       struct resource *res;
432 +       void __iomem *mem;
433 +       int irq;
434 +       int ret = 0;
435 +       u32 reg;
436 +
437 +       if (!dev_get_platdata(&pdev->dev)) {
438 +               dev_err(&pdev->dev, "no platform data specified\n");
439 +               ret = -EINVAL;
440 +               goto err_out;
441 +       }
442 +
443 +       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
444 +       if (res == NULL) {
445 +               dev_err(&pdev->dev, "no memory resource found\n");
446 +               ret = -ENXIO;
447 +               goto err_out;
448 +       }
449 +
450 +       mem = ioremap_nocache(res->start, resource_size(res));
451 +       if (mem == NULL) {
452 +               dev_err(&pdev->dev, "ioremap failed\n");
453 +               ret = -ENOMEM;
454 +               goto err_out;
455 +       }
456 +
457 +       res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
458 +       if (res == NULL) {
459 +               dev_err(&pdev->dev, "no IRQ resource found\n");
460 +               ret = -ENXIO;
461 +               goto err_iounmap;
462 +       }
463 +
464 +       irq = res->start;
465 +
466 +       hw = ieee80211_alloc_hw(sizeof(struct ath5k_hw), &ath5k_hw_ops);
467 +       if (hw == NULL) {
468 +               dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
469 +               ret = -ENOMEM;
470 +               goto err_iounmap;
471 +       }
472 +
473 +       ah = hw->priv;
474 +       ah->hw = hw;
475 +       ah->dev = &pdev->dev;
476 +       ah->iobase = mem;
477 +       ah->irq = irq;
478 +       ah->devid = bcfg->devid;
479 +
480 +       if (bcfg->devid >= AR5K_SREV_AR2315_R6) {
481 +               /* Enable WMAC AHB arbitration */
482 +               reg = ioread32((void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
483 +               reg |= AR5K_AR2315_AHB_ARB_CTL_WLAN;
484 +               iowrite32(reg, (void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
485 +
486 +               /* Enable global WMAC swapping */
487 +               reg = ioread32((void __iomem *) AR5K_AR2315_BYTESWAP);
488 +               reg |= AR5K_AR2315_BYTESWAP_WMAC;
489 +               iowrite32(reg, (void __iomem *) AR5K_AR2315_BYTESWAP);
490 +       } else {
491 +               /* Enable WMAC DMA access (assuming 5312 or 231x*/
492 +               /* TODO: check other platforms */
493 +               reg = ioread32((void __iomem *) AR5K_AR5312_ENABLE);
494 +               if (to_platform_device(ah->dev)->id == 0)
495 +                       reg |= AR5K_AR5312_ENABLE_WLAN0;
496 +               else
497 +                       reg |= AR5K_AR5312_ENABLE_WLAN1;
498 +               iowrite32(reg, (void __iomem *) AR5K_AR5312_ENABLE);
499 +
500 +               /*
501 +                * On a dual-band AR5312, the multiband radio is only
502 +                * used as pass-through. Disable 2 GHz support in the
503 +                * driver for it
504 +                */
505 +               if (to_platform_device(ah->dev)->id == 0 &&
506 +                   (bcfg->config->flags & (BD_WLAN0 | BD_WLAN1)) ==
507 +                    (BD_WLAN1 | BD_WLAN0))
508 +                       ah->ah_capabilities.cap_needs_2GHz_ovr = true;
509 +               else
510 +                       ah->ah_capabilities.cap_needs_2GHz_ovr = false;
511 +       }
512 +
513 +       ret = ath5k_init_ah(ah, &ath_ahb_bus_ops);
514 +       if (ret != 0) {
515 +               dev_err(&pdev->dev, "failed to attach device, err=%d\n", ret);
516 +               ret = -ENODEV;
517 +               goto err_free_hw;
518 +       }
519 +
520 +       platform_set_drvdata(pdev, hw);
521 +
522 +       return 0;
523 +
524 + err_free_hw:
525 +       ieee80211_free_hw(hw);
526 + err_iounmap:
527 +        iounmap(mem);
528 + err_out:
529 +       return ret;
530 +}
531 +
532 +static int ath_ahb_remove(struct platform_device *pdev)
533 +{
534 +       struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
535 +       struct ieee80211_hw *hw = platform_get_drvdata(pdev);
536 +       struct ath5k_hw *ah;
537 +       u32 reg;
538 +
539 +       if (!hw)
540 +               return 0;
541 +
542 +       ah = hw->priv;
543 +
544 +       if (bcfg->devid >= AR5K_SREV_AR2315_R6) {
545 +               /* Disable WMAC AHB arbitration */
546 +               reg = ioread32((void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
547 +               reg &= ~AR5K_AR2315_AHB_ARB_CTL_WLAN;
548 +               iowrite32(reg, (void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
549 +       } else {
550 +               /*Stop DMA access */
551 +               reg = ioread32((void __iomem *) AR5K_AR5312_ENABLE);
552 +               if (to_platform_device(ah->dev)->id == 0)
553 +                       reg &= ~AR5K_AR5312_ENABLE_WLAN0;
554 +               else
555 +                       reg &= ~AR5K_AR5312_ENABLE_WLAN1;
556 +               iowrite32(reg, (void __iomem *) AR5K_AR5312_ENABLE);
557 +       }
558 +
559 +       ath5k_deinit_ah(ah);
560 +       iounmap(ah->iobase);
561 +       ieee80211_free_hw(hw);
562 +
563 +       return 0;
564 +}
565 +
566 +static struct platform_driver ath_ahb_driver = {
567 +       .probe      = ath_ahb_probe,
568 +       .remove     = ath_ahb_remove,
569 +       .driver         = {
570 +               .name   = "ar231x-wmac",
571 +               .owner  = THIS_MODULE,
572 +       },
573 +};
574 +
575 +module_platform_driver(ath_ahb_driver);
576 --- a/drivers/net/wireless/ath/ath5k/ath5k.h
577 +++ b/drivers/net/wireless/ath/ath5k/ath5k.h
578 @@ -1647,6 +1647,32 @@ static inline struct ath_regulatory *ath
579         return &(ath5k_hw_common(ah)->regulatory);
580  }
581  
582 +#ifdef CONFIG_ATHEROS_AR231X
583 +#define AR5K_AR2315_PCI_BASE   ((void __iomem *)0xb0100000)
584 +
585 +static inline void __iomem *ath5k_ahb_reg(struct ath5k_hw *ah, u16 reg)
586 +{
587 +       /* On AR2315 and AR2317 the PCI clock domain registers
588 +        * are outside of the WMAC register space */
589 +       if (unlikely((reg >= 0x4000) && (reg < 0x5000) &&
590 +           (ah->ah_mac_srev >= AR5K_SREV_AR2315_R6)))
591 +               return AR5K_AR2315_PCI_BASE + reg;
592 +
593 +       return ah->iobase + reg;
594 +}
595 +
596 +static inline u32 ath5k_hw_reg_read(struct ath5k_hw *ah, u16 reg)
597 +{
598 +       return ioread32(ath5k_ahb_reg(ah, reg));
599 +}
600 +
601 +static inline void ath5k_hw_reg_write(struct ath5k_hw *ah, u32 val, u16 reg)
602 +{
603 +       iowrite32(val, ath5k_ahb_reg(ah, reg));
604 +}
605 +
606 +#else
607 +
608  static inline u32 ath5k_hw_reg_read(struct ath5k_hw *ah, u16 reg)
609  {
610         return ioread32(ah->iobase + reg);
611 @@ -1657,6 +1683,8 @@ static inline void ath5k_hw_reg_write(st
612         iowrite32(val, ah->iobase + reg);
613  }
614  
615 +#endif
616 +
617  static inline enum ath_bus_type ath5k_get_bus_type(struct ath5k_hw *ah)
618  {
619         return ath5k_hw_common(ah)->bus_ops->ath_bus_type;
620 --- a/drivers/net/wireless/ath/ath5k/base.c
621 +++ b/drivers/net/wireless/ath/ath5k/base.c
622 @@ -99,6 +99,15 @@ static int ath5k_reset(struct ath5k_hw *
623  
624  /* Known SREVs */
625  static const struct ath5k_srev_name srev_names[] = {
626 +#ifdef CONFIG_ATHEROS_AR231X
627 +       { "5312",       AR5K_VERSION_MAC,       AR5K_SREV_AR5312_R2 },
628 +       { "5312",       AR5K_VERSION_MAC,       AR5K_SREV_AR5312_R7 },
629 +       { "2313",       AR5K_VERSION_MAC,       AR5K_SREV_AR2313_R8 },
630 +       { "2315",       AR5K_VERSION_MAC,       AR5K_SREV_AR2315_R6 },
631 +       { "2315",       AR5K_VERSION_MAC,       AR5K_SREV_AR2315_R7 },
632 +       { "2317",       AR5K_VERSION_MAC,       AR5K_SREV_AR2317_R1 },
633 +       { "2317",       AR5K_VERSION_MAC,       AR5K_SREV_AR2317_R2 },
634 +#else
635         { "5210",       AR5K_VERSION_MAC,       AR5K_SREV_AR5210 },
636         { "5311",       AR5K_VERSION_MAC,       AR5K_SREV_AR5311 },
637         { "5311A",      AR5K_VERSION_MAC,       AR5K_SREV_AR5311A },
638 @@ -117,6 +126,7 @@ static const struct ath5k_srev_name srev
639         { "5418",       AR5K_VERSION_MAC,       AR5K_SREV_AR5418 },
640         { "2425",       AR5K_VERSION_MAC,       AR5K_SREV_AR2425 },
641         { "2417",       AR5K_VERSION_MAC,       AR5K_SREV_AR2417 },
642 +#endif
643         { "xxxxx",      AR5K_VERSION_MAC,       AR5K_SREV_UNKNOWN },
644         { "5110",       AR5K_VERSION_RAD,       AR5K_SREV_RAD_5110 },
645         { "5111",       AR5K_VERSION_RAD,       AR5K_SREV_RAD_5111 },
646 @@ -132,6 +142,10 @@ static const struct ath5k_srev_name srev
647         { "5413",       AR5K_VERSION_RAD,       AR5K_SREV_RAD_5413 },
648         { "5424",       AR5K_VERSION_RAD,       AR5K_SREV_RAD_5424 },
649         { "5133",       AR5K_VERSION_RAD,       AR5K_SREV_RAD_5133 },
650 +#ifdef CONFIG_ATHEROS_AR231X
651 +       { "2316",       AR5K_VERSION_RAD,       AR5K_SREV_RAD_2316 },
652 +       { "2317",       AR5K_VERSION_RAD,       AR5K_SREV_RAD_2317 },
653 +#endif
654         { "xxxxx",      AR5K_VERSION_RAD,       AR5K_SREV_UNKNOWN },
655  };
656  
657 --- a/drivers/net/wireless/ath/ath5k/led.c
658 +++ b/drivers/net/wireless/ath/ath5k/led.c
659 @@ -163,14 +163,20 @@ int ath5k_init_leds(struct ath5k_hw *ah)
660  {
661         int ret = 0;
662         struct ieee80211_hw *hw = ah->hw;
663 +#ifndef CONFIG_ATHEROS_AR231X
664         struct pci_dev *pdev = ah->pdev;
665 +#endif
666         char name[ATH5K_LED_MAX_NAME_LEN + 1];
667         const struct pci_device_id *match;
668  
669         if (!ah->pdev)
670                 return 0;
671  
672 +#ifdef CONFIG_ATHEROS_AR231X
673 +       match = NULL;
674 +#else
675         match = pci_match_id(&ath5k_led_devices[0], pdev);
676 +#endif
677         if (match) {
678                 __set_bit(ATH_STAT_LEDSOFT, ah->status);
679                 ah->led_pin = ATH_PIN(match->driver_data);
680 --- a/drivers/net/wireless/ath/ath5k/debug.c
681 +++ b/drivers/net/wireless/ath/ath5k/debug.c
682 @@ -65,6 +65,7 @@
683  
684  #include <linux/seq_file.h>
685  #include <linux/list.h>
686 +#include <linux/vmalloc.h>
687  #include "debug.h"
688  #include "ath5k.h"
689  #include "reg.h"
690 --- a/drivers/net/wireless/ath/ath9k/hw.c
691 +++ b/drivers/net/wireless/ath/ath9k/hw.c
692 @@ -222,31 +222,28 @@ static void ath9k_hw_read_revisions(stru
693  {
694         u32 val;
695  
696 +       if (ah->get_mac_revision)
697 +               ah->hw_version.macRev = ah->get_mac_revision();
698 +
699         switch (ah->hw_version.devid) {
700         case AR5416_AR9100_DEVID:
701                 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
702                 break;
703         case AR9300_DEVID_AR9330:
704                 ah->hw_version.macVersion = AR_SREV_VERSION_9330;
705 -               if (ah->get_mac_revision) {
706 -                       ah->hw_version.macRev = ah->get_mac_revision();
707 -               } else {
708 +               if (!ah->get_mac_revision) {
709                         val = REG_READ(ah, AR_SREV);
710                         ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
711                 }
712                 return;
713         case AR9300_DEVID_AR9340:
714                 ah->hw_version.macVersion = AR_SREV_VERSION_9340;
715 -               val = REG_READ(ah, AR_SREV);
716 -               ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
717                 return;
718         case AR9300_DEVID_QCA955X:
719                 ah->hw_version.macVersion = AR_SREV_VERSION_9550;
720                 return;
721         case AR9300_DEVID_AR953X:
722                 ah->hw_version.macVersion = AR_SREV_VERSION_9531;
723 -               if (ah->get_mac_revision)
724 -                       ah->hw_version.macRev = ah->get_mac_revision();
725                 return;
726         }
727  
728 @@ -704,6 +701,8 @@ static void ath9k_hw_init_pll(struct ath
729  {
730         u32 pll;
731  
732 +       pll = ath9k_hw_compute_pll_control(ah, chan);
733 +
734         if (AR_SREV_9485(ah) || AR_SREV_9565(ah)) {
735                 /* program BB PLL ki and kd value, ki=0x4, kd=0x40 */
736                 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
737 @@ -754,7 +753,8 @@ static void ath9k_hw_init_pll(struct ath
738                 REG_RMW_FIELD(ah, AR_CH0_DDR_DPLL3,
739                               AR_CH0_DPLL3_PHASE_SHIFT, 0x1);
740  
741 -               REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c);
742 +               REG_WRITE(ah, AR_RTC_PLL_CONTROL,
743 +                         pll | AR_RTC_9300_PLL_BYPASS);
744                 udelay(1000);
745  
746                 /* program refdiv, nint, frac to RTC register */
747 @@ -770,7 +770,8 @@ static void ath9k_hw_init_pll(struct ath
748         } else if (AR_SREV_9340(ah) || AR_SREV_9550(ah) || AR_SREV_9531(ah)) {
749                 u32 regval, pll2_divint, pll2_divfrac, refdiv;
750  
751 -               REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c);
752 +               REG_WRITE(ah, AR_RTC_PLL_CONTROL,
753 +                         pll | AR_RTC_9300_SOC_PLL_BYPASS);
754                 udelay(1000);
755  
756                 REG_SET_BIT(ah, AR_PHY_PLL_MODE, 0x1 << 16);
757 @@ -843,7 +844,6 @@ static void ath9k_hw_init_pll(struct ath
758                 udelay(1000);
759         }
760  
761 -       pll = ath9k_hw_compute_pll_control(ah, chan);
762         if (AR_SREV_9565(ah))
763                 pll |= 0x40000;
764         REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
765 @@ -1192,9 +1192,12 @@ static void ath9k_hw_set_operating_mode(
766  
767         switch (opmode) {
768         case NL80211_IFTYPE_ADHOC:
769 -               set |= AR_STA_ID1_ADHOC;
770 -               REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
771 -               break;
772 +               if (!AR_SREV_9340_13(ah)) {
773 +                       set |= AR_STA_ID1_ADHOC;
774 +                       REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
775 +                       break;
776 +               }
777 +               /* fall through */
778         case NL80211_IFTYPE_MESH_POINT:
779         case NL80211_IFTYPE_AP:
780                 set |= AR_STA_ID1_STA_AP;
781 --- a/drivers/net/wireless/ath/ath9k/reg.h
782 +++ b/drivers/net/wireless/ath/ath9k/reg.h
783 @@ -903,6 +903,10 @@
784  #define AR_SREV_9340(_ah) \
785         (((_ah)->hw_version.macVersion == AR_SREV_VERSION_9340))
786  
787 +#define AR_SREV_9340_13(_ah) \
788 +       (AR_SREV_9340((_ah)) && \
789 +        ((_ah)->hw_version.macRev == AR_SREV_REVISION_9340_13))
790 +
791  #define AR_SREV_9340_13_OR_LATER(_ah) \
792         (AR_SREV_9340((_ah)) && \
793          ((_ah)->hw_version.macRev >= AR_SREV_REVISION_9340_13))
794 @@ -1240,12 +1244,23 @@ enum {
795  #define AR_CH0_DPLL3_PHASE_SHIFT_S   23
796  #define AR_PHY_CCA_NOM_VAL_2GHZ      -118
797  
798 +#define AR_RTC_9300_SOC_PLL_DIV_INT          0x0000003f
799 +#define AR_RTC_9300_SOC_PLL_DIV_INT_S        0
800 +#define AR_RTC_9300_SOC_PLL_DIV_FRAC         0x000fffc0
801 +#define AR_RTC_9300_SOC_PLL_DIV_FRAC_S       6
802 +#define AR_RTC_9300_SOC_PLL_REFDIV           0x01f00000
803 +#define AR_RTC_9300_SOC_PLL_REFDIV_S         20
804 +#define AR_RTC_9300_SOC_PLL_CLKSEL           0x06000000
805 +#define AR_RTC_9300_SOC_PLL_CLKSEL_S         25
806 +#define AR_RTC_9300_SOC_PLL_BYPASS           0x08000000
807 +
808  #define AR_RTC_9300_PLL_DIV          0x000003ff
809  #define AR_RTC_9300_PLL_DIV_S        0
810  #define AR_RTC_9300_PLL_REFDIV       0x00003C00
811  #define AR_RTC_9300_PLL_REFDIV_S     10
812  #define AR_RTC_9300_PLL_CLKSEL       0x0000C000
813  #define AR_RTC_9300_PLL_CLKSEL_S     14
814 +#define AR_RTC_9300_PLL_BYPASS       0x00010000
815  
816  #define AR_RTC_9160_PLL_DIV    0x000003ff
817  #define AR_RTC_9160_PLL_DIV_S   0
818 --- a/drivers/net/wireless/ath/ath9k/ar5008_phy.c
819 +++ b/drivers/net/wireless/ath/ath9k/ar5008_phy.c
820 @@ -1004,9 +1004,11 @@ static bool ar5008_hw_ani_control_new(st
821         case ATH9K_ANI_FIRSTEP_LEVEL:{
822                 u32 level = param;
823  
824 -               value = level;
825 +               value = level * 2;
826                 REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
827                               AR_PHY_FIND_SIG_FIRSTEP, value);
828 +               REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW,
829 +                             AR_PHY_FIND_SIG_FIRSTEP_LOW, value);
830  
831                 if (level != aniState->firstepLevel) {
832                         ath_dbg(common, ANI,
833 @@ -1040,9 +1042,8 @@ static bool ar5008_hw_ani_control_new(st
834                 REG_RMW_FIELD(ah, AR_PHY_TIMING5,
835                               AR_PHY_TIMING5_CYCPWR_THR1, value);
836  
837 -               if (IS_CHAN_HT40(ah->curchan))
838 -                       REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
839 -                                     AR_PHY_EXT_TIMING5_CYCPWR_THR1, value);
840 +               REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
841 +                                 AR_PHY_EXT_TIMING5_CYCPWR_THR1, value - 1);
842  
843                 if (level != aniState->spurImmunityLevel) {
844                         ath_dbg(common, ANI,
845 --- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
846 +++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
847 @@ -517,6 +517,23 @@ static void ar9003_hw_spur_mitigate(stru
848         ar9003_hw_spur_mitigate_ofdm(ah, chan);
849  }
850  
851 +static u32 ar9003_hw_compute_pll_control_soc(struct ath_hw *ah,
852 +                                            struct ath9k_channel *chan)
853 +{
854 +       u32 pll;
855 +
856 +       pll = SM(0x5, AR_RTC_9300_SOC_PLL_REFDIV);
857 +
858 +       if (chan && IS_CHAN_HALF_RATE(chan))
859 +               pll |= SM(0x1, AR_RTC_9300_SOC_PLL_CLKSEL);
860 +       else if (chan && IS_CHAN_QUARTER_RATE(chan))
861 +               pll |= SM(0x2, AR_RTC_9300_SOC_PLL_CLKSEL);
862 +
863 +       pll |= SM(0x2c, AR_RTC_9300_SOC_PLL_DIV_INT);
864 +
865 +       return pll;
866 +}
867 +
868  static u32 ar9003_hw_compute_pll_control(struct ath_hw *ah,
869                                          struct ath9k_channel *chan)
870  {
871 @@ -1781,7 +1798,12 @@ void ar9003_hw_attach_phy_ops(struct ath
872  
873         priv_ops->rf_set_freq = ar9003_hw_set_channel;
874         priv_ops->spur_mitigate_freq = ar9003_hw_spur_mitigate;
875 -       priv_ops->compute_pll_control = ar9003_hw_compute_pll_control;
876 +
877 +       if (AR_SREV_9340(ah) || AR_SREV_9550(ah) || AR_SREV_9531(ah))
878 +               priv_ops->compute_pll_control = ar9003_hw_compute_pll_control_soc;
879 +       else
880 +               priv_ops->compute_pll_control = ar9003_hw_compute_pll_control;
881 +
882         priv_ops->set_channel_regs = ar9003_hw_set_channel_regs;
883         priv_ops->init_bb = ar9003_hw_init_bb;
884         priv_ops->process_ini = ar9003_hw_process_ini;
885 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
886 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
887 @@ -381,16 +381,27 @@ static int ar9002_hw_proc_txdesc(struct 
888         ts->evm1 = ads->AR_TxEVM1;
889         ts->evm2 = ads->AR_TxEVM2;
890  
891 -       status = ACCESS_ONCE(ads->ds_ctl4);
892 -       ts->duration[0] = MS(status, AR_PacketDur0);
893 -       ts->duration[1] = MS(status, AR_PacketDur1);
894 -       status = ACCESS_ONCE(ads->ds_ctl5);
895 -       ts->duration[2] = MS(status, AR_PacketDur2);
896 -       ts->duration[3] = MS(status, AR_PacketDur3);
897 -
898         return 0;
899  }
900  
901 +static int ar9002_hw_get_duration(struct ath_hw *ah, const void *ds, int index)
902 +{
903 +       struct ar5416_desc *ads = AR5416DESC(ds);
904 +
905 +       switch (index) {
906 +       case 0:
907 +               return MS(ACCESS_ONCE(ads->ds_ctl4), AR_PacketDur0);
908 +       case 1:
909 +               return MS(ACCESS_ONCE(ads->ds_ctl4), AR_PacketDur1);
910 +       case 2:
911 +               return MS(ACCESS_ONCE(ads->ds_ctl5), AR_PacketDur2);
912 +       case 3:
913 +               return MS(ACCESS_ONCE(ads->ds_ctl5), AR_PacketDur3);
914 +       default:
915 +               return -1;
916 +       }
917 +}
918 +
919  void ath9k_hw_setuprxdesc(struct ath_hw *ah, struct ath_desc *ds,
920                           u32 size, u32 flags)
921  {
922 @@ -413,4 +424,5 @@ void ar9002_hw_attach_mac_ops(struct ath
923         ops->get_isr = ar9002_hw_get_isr;
924         ops->set_txdesc = ar9002_set_txdesc;
925         ops->proc_txdesc = ar9002_hw_proc_txdesc;
926 +       ops->get_duration = ar9002_hw_get_duration;
927  }
928 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
929 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
930 @@ -355,11 +355,9 @@ static int ar9003_hw_proc_txdesc(struct 
931                                  struct ath_tx_status *ts)
932  {
933         struct ar9003_txs *ads;
934 -       struct ar9003_txc *adc;
935         u32 status;
936  
937         ads = &ah->ts_ring[ah->ts_tail];
938 -       adc = (struct ar9003_txc *)ads;
939  
940         status = ACCESS_ONCE(ads->status8);
941         if ((status & AR_TxDone) == 0)
942 @@ -428,18 +426,29 @@ static int ar9003_hw_proc_txdesc(struct 
943         ts->ts_rssi_ext1 = MS(status, AR_TxRSSIAnt11);
944         ts->ts_rssi_ext2 = MS(status, AR_TxRSSIAnt12);
945  
946 -       status = ACCESS_ONCE(adc->ctl15);
947 -       ts->duration[0] = MS(status, AR_PacketDur0);
948 -       ts->duration[1] = MS(status, AR_PacketDur1);
949 -       status = ACCESS_ONCE(adc->ctl16);
950 -       ts->duration[2] = MS(status, AR_PacketDur2);
951 -       ts->duration[3] = MS(status, AR_PacketDur3);
952 -
953         memset(ads, 0, sizeof(*ads));
954  
955         return 0;
956  }
957  
958 +static int ar9003_hw_get_duration(struct ath_hw *ah, const void *ds, int index)
959 +{
960 +       const struct ar9003_txc *adc = ds;
961 +
962 +       switch (index) {
963 +       case 0:
964 +               return MS(ACCESS_ONCE(adc->ctl15), AR_PacketDur0);
965 +       case 1:
966 +               return MS(ACCESS_ONCE(adc->ctl15), AR_PacketDur1);
967 +       case 2:
968 +               return MS(ACCESS_ONCE(adc->ctl16), AR_PacketDur2);
969 +       case 3:
970 +               return MS(ACCESS_ONCE(adc->ctl16), AR_PacketDur3);
971 +       default:
972 +               return 0;
973 +       }
974 +}
975 +
976  void ar9003_hw_attach_mac_ops(struct ath_hw *hw)
977  {
978         struct ath_hw_ops *ops = ath9k_hw_ops(hw);
979 @@ -449,6 +458,7 @@ void ar9003_hw_attach_mac_ops(struct ath
980         ops->get_isr = ar9003_hw_get_isr;
981         ops->set_txdesc = ar9003_set_txdesc;
982         ops->proc_txdesc = ar9003_hw_proc_txdesc;
983 +       ops->get_duration = ar9003_hw_get_duration;
984  }
985  
986  void ath9k_hw_set_rx_bufsize(struct ath_hw *ah, u16 buf_size)
987 --- a/drivers/net/wireless/ath/ath9k/dynack.c
988 +++ b/drivers/net/wireless/ath/ath9k/dynack.c
989 @@ -202,7 +202,7 @@ void ath_dynack_sample_tx_ts(struct ath_
990         ridx = ts->ts_rateindex;
991  
992         da->st_rbf.ts[da->st_rbf.t_rb].tstamp = ts->ts_tstamp;
993 -       da->st_rbf.ts[da->st_rbf.t_rb].dur = ts->duration[ts->ts_rateindex];
994 +       da->st_rbf.ts[da->st_rbf.t_rb].dur = ts->duration;
995         ether_addr_copy(da->st_rbf.addr[da->st_rbf.t_rb].h_dest, hdr->addr1);
996         ether_addr_copy(da->st_rbf.addr[da->st_rbf.t_rb].h_src, hdr->addr2);
997  
998 --- a/drivers/net/wireless/ath/ath9k/hw-ops.h
999 +++ b/drivers/net/wireless/ath/ath9k/hw-ops.h
1000 @@ -67,6 +67,12 @@ static inline int ath9k_hw_txprocdesc(st
1001         return ath9k_hw_ops(ah)->proc_txdesc(ah, ds, ts);
1002  }
1003  
1004 +static inline int ath9k_hw_get_duration(struct ath_hw *ah, const void *ds,
1005 +                                       int index)
1006 +{
1007 +       return ath9k_hw_ops(ah)->get_duration(ah, ds, index);
1008 +}
1009 +
1010  static inline void ath9k_hw_antdiv_comb_conf_get(struct ath_hw *ah,
1011                 struct ath_hw_antcomb_conf *antconf)
1012  {
1013 --- a/drivers/net/wireless/ath/ath9k/hw.h
1014 +++ b/drivers/net/wireless/ath/ath9k/hw.h
1015 @@ -691,6 +691,7 @@ struct ath_hw_ops {
1016                            struct ath_tx_info *i);
1017         int (*proc_txdesc)(struct ath_hw *ah, void *ds,
1018                            struct ath_tx_status *ts);
1019 +       int (*get_duration)(struct ath_hw *ah, const void *ds, int index);
1020         void (*antdiv_comb_conf_get)(struct ath_hw *ah,
1021                         struct ath_hw_antcomb_conf *antconf);
1022         void (*antdiv_comb_conf_set)(struct ath_hw *ah,
1023 --- a/drivers/net/wireless/ath/ath9k/mac.h
1024 +++ b/drivers/net/wireless/ath/ath9k/mac.h
1025 @@ -121,7 +121,7 @@ struct ath_tx_status {
1026         u32 evm0;
1027         u32 evm1;
1028         u32 evm2;
1029 -       u32 duration[4];
1030 +       u32 duration;
1031  };
1032  
1033  struct ath_rx_status {
1034 --- a/drivers/net/wireless/ath/ath9k/xmit.c
1035 +++ b/drivers/net/wireless/ath/ath9k/xmit.c
1036 @@ -683,6 +683,8 @@ static void ath_tx_process_buffer(struct
1037         if (bf_is_ampdu_not_probing(bf))
1038                 txq->axq_ampdu_depth--;
1039  
1040 +       ts->duration = ath9k_hw_get_duration(sc->sc_ah, bf->bf_desc,
1041 +                                            ts->ts_rateindex);
1042         if (!bf_isampdu(bf)) {
1043                 if (!flush) {
1044                         info = IEEE80211_SKB_CB(bf->bf_mpdu);
1045 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
1046 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
1047 @@ -455,7 +455,8 @@ void ath9k_p2p_bss_info_changed(struct a
1048  void ath9k_beacon_add_noa(struct ath_softc *sc, struct ath_vif *avp,
1049                           struct sk_buff *skb);
1050  void ath9k_p2p_ps_timer(void *priv);
1051 -void ath9k_chanctx_wake_queues(struct ath_softc *sc);
1052 +void ath9k_chanctx_wake_queues(struct ath_softc *sc, struct ath_chanctx *ctx);
1053 +void ath9k_chanctx_stop_queues(struct ath_softc *sc, struct ath_chanctx *ctx);
1054  void ath_chanctx_check_active(struct ath_softc *sc, struct ath_chanctx *ctx);
1055  
1056  void ath_chanctx_beacon_recv_ev(struct ath_softc *sc,
1057 @@ -525,7 +526,12 @@ static inline void ath9k_beacon_add_noa(
1058  static inline void ath9k_p2p_ps_timer(struct ath_softc *sc)
1059  {
1060  }
1061 -static inline void ath9k_chanctx_wake_queues(struct ath_softc *sc)
1062 +static inline void ath9k_chanctx_wake_queues(struct ath_softc *sc,
1063 +                                            struct ath_chanctx *ctx)
1064 +{
1065 +}
1066 +static inline void ath9k_chanctx_stop_queues(struct ath_softc *sc,
1067 +                                            struct ath_chanctx *ctx)
1068  {
1069  }
1070  static inline void ath_chanctx_check_active(struct ath_softc *sc,
1071 --- a/drivers/net/wireless/ath/ath9k/channel.c
1072 +++ b/drivers/net/wireless/ath/ath9k/channel.c
1073 @@ -761,6 +761,13 @@ void ath_offchannel_next(struct ath_soft
1074  
1075  void ath_roc_complete(struct ath_softc *sc, bool abort)
1076  {
1077 +       struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1078 +
1079 +       if (abort)
1080 +               ath_dbg(common, CHAN_CTX, "RoC aborted\n");
1081 +       else
1082 +               ath_dbg(common, CHAN_CTX, "RoC expired\n");
1083 +
1084         sc->offchannel.roc_vif = NULL;
1085         sc->offchannel.roc_chan = NULL;
1086         if (!abort)
1087 @@ -1037,9 +1044,11 @@ static void ath_offchannel_channel_chang
1088  void ath_chanctx_set_next(struct ath_softc *sc, bool force)
1089  {
1090         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1091 +       struct ath_chanctx *old_ctx;
1092         struct timespec ts;
1093         bool measure_time = false;
1094         bool send_ps = false;
1095 +       bool queues_stopped = false;
1096  
1097         spin_lock_bh(&sc->chan_lock);
1098         if (!sc->next_chan) {
1099 @@ -1069,6 +1078,10 @@ void ath_chanctx_set_next(struct ath_sof
1100                         getrawmonotonic(&ts);
1101                         measure_time = true;
1102                 }
1103 +
1104 +               ath9k_chanctx_stop_queues(sc, sc->cur_chan);
1105 +               queues_stopped = true;
1106 +
1107                 __ath9k_flush(sc->hw, ~0, true);
1108  
1109                 if (ath_chanctx_send_ps_frame(sc, true))
1110 @@ -1082,6 +1095,7 @@ void ath_chanctx_set_next(struct ath_sof
1111                         sc->cur_chan->tsf_val = ath9k_hw_gettsf64(sc->sc_ah);
1112                 }
1113         }
1114 +       old_ctx = sc->cur_chan;
1115         sc->cur_chan = sc->next_chan;
1116         sc->cur_chan->stopped = false;
1117         sc->next_chan = NULL;
1118 @@ -1104,7 +1118,16 @@ void ath_chanctx_set_next(struct ath_sof
1119                 if (measure_time)
1120                         sc->sched.channel_switch_time =
1121                                 ath9k_hw_get_tsf_offset(&ts, NULL);
1122 +               /*
1123 +                * A reset will ensure that all queues are woken up,
1124 +                * so there is no need to awaken them again.
1125 +                */
1126 +               goto out;
1127         }
1128 +
1129 +       if (queues_stopped)
1130 +               ath9k_chanctx_wake_queues(sc, old_ctx);
1131 +out:
1132         if (send_ps)
1133                 ath_chanctx_send_ps_frame(sc, false);
1134  
1135 @@ -1170,18 +1193,37 @@ bool ath9k_is_chanctx_enabled(void)
1136  /* Queue management */
1137  /********************/
1138  
1139 -void ath9k_chanctx_wake_queues(struct ath_softc *sc)
1140 +void ath9k_chanctx_stop_queues(struct ath_softc *sc, struct ath_chanctx *ctx)
1141 +{
1142 +       struct ath_hw *ah = sc->sc_ah;
1143 +       int i;
1144 +
1145 +       if (ctx == &sc->offchannel.chan) {
1146 +               ieee80211_stop_queue(sc->hw,
1147 +                                    sc->hw->offchannel_tx_hw_queue);
1148 +       } else {
1149 +               for (i = 0; i < IEEE80211_NUM_ACS; i++)
1150 +                       ieee80211_stop_queue(sc->hw,
1151 +                                            ctx->hw_queue_base + i);
1152 +       }
1153 +
1154 +       if (ah->opmode == NL80211_IFTYPE_AP)
1155 +               ieee80211_stop_queue(sc->hw, sc->hw->queues - 2);
1156 +}
1157 +
1158 +
1159 +void ath9k_chanctx_wake_queues(struct ath_softc *sc, struct ath_chanctx *ctx)
1160  {
1161         struct ath_hw *ah = sc->sc_ah;
1162         int i;
1163  
1164 -       if (sc->cur_chan == &sc->offchannel.chan) {
1165 +       if (ctx == &sc->offchannel.chan) {
1166                 ieee80211_wake_queue(sc->hw,
1167                                      sc->hw->offchannel_tx_hw_queue);
1168         } else {
1169                 for (i = 0; i < IEEE80211_NUM_ACS; i++)
1170                         ieee80211_wake_queue(sc->hw,
1171 -                                            sc->cur_chan->hw_queue_base + i);
1172 +                                            ctx->hw_queue_base + i);
1173         }
1174  
1175         if (ah->opmode == NL80211_IFTYPE_AP)
1176 --- a/drivers/net/wireless/ath/ath9k/htc_drv_init.c
1177 +++ b/drivers/net/wireless/ath/ath9k/htc_drv_init.c
1178 @@ -464,6 +464,7 @@ static int ath9k_init_priv(struct ath9k_
1179                 return -ENOMEM;
1180  
1181         ah->dev = priv->dev;
1182 +       ah->hw = priv->hw;
1183         ah->hw_version.devid = devid;
1184         ah->hw_version.usbdev = drv_info;
1185         ah->ah_flags |= AH_USE_EEPROM;
1186 --- a/drivers/net/wireless/ath/ath9k/main.c
1187 +++ b/drivers/net/wireless/ath/ath9k/main.c
1188 @@ -60,8 +60,10 @@ static bool ath9k_has_pending_frames(str
1189  
1190         spin_lock_bh(&txq->axq_lock);
1191  
1192 -       if (txq->axq_depth)
1193 +       if (txq->axq_depth) {
1194                 pending = true;
1195 +               goto out;
1196 +       }
1197  
1198         if (txq->mac80211_qnum >= 0) {
1199                 struct list_head *list;
1200 @@ -70,6 +72,7 @@ static bool ath9k_has_pending_frames(str
1201                 if (!list_empty(list))
1202                         pending = true;
1203         }
1204 +out:
1205         spin_unlock_bh(&txq->axq_lock);
1206         return pending;
1207  }
1208 @@ -261,12 +264,7 @@ static bool ath_complete_reset(struct at
1209  
1210         ath9k_hw_set_interrupts(ah);
1211         ath9k_hw_enable_interrupts(ah);
1212 -
1213 -       if (!ath9k_is_chanctx_enabled())
1214 -               ieee80211_wake_queues(sc->hw);
1215 -       else
1216 -               ath9k_chanctx_wake_queues(sc);
1217 -
1218 +       ieee80211_wake_queues(sc->hw);
1219         ath9k_p2p_ps_timer(sc);
1220  
1221         return true;
1222 @@ -1971,9 +1969,6 @@ static bool ath9k_has_tx_pending(struct 
1223                 if (!ATH_TXQ_SETUP(sc, i))
1224                         continue;
1225  
1226 -               if (!sc->tx.txq[i].axq_depth)
1227 -                       continue;
1228 -
1229                 npend = ath9k_has_pending_frames(sc, &sc->tx.txq[i]);
1230                 if (npend)
1231                         break;
1232 @@ -1999,7 +1994,6 @@ void __ath9k_flush(struct ieee80211_hw *
1233         struct ath_common *common = ath9k_hw_common(ah);
1234         int timeout = HZ / 5; /* 200 ms */
1235         bool drain_txq;
1236 -       int i;
1237  
1238         cancel_delayed_work_sync(&sc->tx_complete_work);
1239  
1240 @@ -2027,10 +2021,6 @@ void __ath9k_flush(struct ieee80211_hw *
1241                         ath_reset(sc);
1242  
1243                 ath9k_ps_restore(sc);
1244 -               for (i = 0; i < IEEE80211_NUM_ACS; i++) {
1245 -                       ieee80211_wake_queue(sc->hw,
1246 -                                            sc->cur_chan->hw_queue_base + i);
1247 -               }
1248         }
1249  
1250         ieee80211_queue_delayed_work(hw, &sc->tx_complete_work, 0);
1251 @@ -2039,16 +2029,8 @@ void __ath9k_flush(struct ieee80211_hw *
1252  static bool ath9k_tx_frames_pending(struct ieee80211_hw *hw)
1253  {
1254         struct ath_softc *sc = hw->priv;
1255 -       int i;
1256 -
1257 -       for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
1258 -               if (!ATH_TXQ_SETUP(sc, i))
1259 -                       continue;
1260  
1261 -               if (ath9k_has_pending_frames(sc, &sc->tx.txq[i]))
1262 -                       return true;
1263 -       }
1264 -       return false;
1265 +       return ath9k_has_tx_pending(sc);
1266  }
1267  
1268  static int ath9k_tx_last_beacon(struct ieee80211_hw *hw)
1269 @@ -2350,7 +2332,7 @@ static void ath9k_remove_chanctx(struct 
1270                 conf->def.chan->center_freq);
1271  
1272         ctx->assigned = false;
1273 -       ctx->hw_queue_base = -1;
1274 +       ctx->hw_queue_base = 0;
1275         ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_UNASSIGN);
1276  
1277         mutex_unlock(&sc->mutex);
1278 --- a/net/mac80211/rate.c
1279 +++ b/net/mac80211/rate.c
1280 @@ -448,7 +448,7 @@ static void rate_fixup_ratelist(struct i
1281          */
1282         if (!(rates[0].flags & IEEE80211_TX_RC_MCS)) {
1283                 u32 basic_rates = vif->bss_conf.basic_rates;
1284 -               s8 baserate = basic_rates ? ffs(basic_rates - 1) : 0;
1285 +               s8 baserate = basic_rates ? ffs(basic_rates) - 1 : 0;
1286  
1287                 rate = &sband->bitrates[rates[0].idx];
1288