cc97be89958447df13cb1c7958f8dea1e382910e
[librecmc/librecmc.git] / package / kernel / mac80211 / patches / 300-pending_work.patch
1 commit 065e0b64f71632f5ad7f00c102fde09c534cfbf0
2 Author: Felix Fietkau <nbd@openwrt.org>
3 Date:   Tue Sep 30 11:00:33 2014 +0200
4
5     ath9k: fix getting tx duration for dynack
6     
7     On AR9003, tx control and tx status are in separate descriptor rings.
8     Tx duration is extracted from the tx control descriptor data, which
9     ar9003_hw_proc_txdesc cannot access.
10     
11     Fix getting the duration by adding a separate callback for it.
12     
13     Acked-by: Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
14     Signed-off-by: Felix Fietkau <nbd@openwrt.org>
15
16 commit fdf9a4517b60d847b9bc0a30249efd96559fa450
17 Author: Felix Fietkau <nbd@openwrt.org>
18 Date:   Tue Sep 9 09:48:30 2014 +0200
19
20     ath9k_hw: fix PLL clock initialization for newer SoC
21     
22     On AR934x and newer SoC devices, the layout of the AR_RTC_PLL_CONTROL
23     register changed. This currently breaks at least 5/10 MHz operation.
24     AR933x uses the old layout.
25     
26     It might also have been causing other stability issues because of the
27     different location of the PLL_BYPASS bit which needs to be set during
28     PLL clock initialization.
29     
30     This patch also removes more instances of hardcoded register values in
31     favor of properly computed ones with the PLL_BYPASS bit added.
32     
33     Reported-by: Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
34     Signed-off-by: Felix Fietkau <nbd@openwrt.org>
35
36 commit b6d1f51cd8bdc9d952147a960fbf1f261d8e4188
37 Author: Felix Fietkau <nbd@openwrt.org>
38 Date:   Mon Sep 8 18:35:08 2014 +0200
39
40     ath9k_hw: reduce ANI spur immunity setting on HT40 extension channel
41     
42     The cycpwr_thr1 value needs to be lower on the extension channel than on
43     the control channel, similar to how the register settings are programmed
44     in the initvals.
45     
46     Also drop the unnecessary check for HT40 - this register can always be
47     written. This patch has been reported to improve HT40 stability and
48     throughput in some environments.
49     
50     Signed-off-by: Felix Fietkau <nbd@openwrt.org>
51
52 commit 5ad2dfbaa19aa45d29184d30c8c5dae0e110074a
53 Author: Felix Fietkau <nbd@openwrt.org>
54 Date:   Mon Sep 8 18:31:26 2014 +0200
55
56     Revert "ath9k_hw: reduce ANI firstep range for older chips"
57     
58     This reverts commit 09efc56345be4146ab9fc87a55c837ed5d6ea1ab
59     
60     I've received reports that this change is decreasing throughput in some
61     rare conditions on an AR9280 based device
62     
63     Cc: stable@vger.kernel.org
64     Signed-off-by: Felix Fietkau <nbd@openwrt.org>
65
66 commit 4c82fc569cf2f29e6c66d98ef4a1b0f3b6a98e9d
67 Author: Felix Fietkau <nbd@openwrt.org>
68 Date:   Sat Sep 27 22:39:27 2014 +0200
69
70     ath9k_hw: disable hardware ad-hoc flag on ar934x rev 3
71     
72     On AR934x rev 3, settin the ad-hoc flag completely messes up hardware
73     state - beacons get stuck, almost no packets make it out, hardware is
74     constantly reset.
75     
76     When leaving out that flag and setting up the hw like in AP mode, TSF
77     timers won't be automatically synced, but at least the rest works.
78     
79     AR934x rev 2 and older are not affected by this bug
80     
81     Signed-off-by: Felix Fietkau <nbd@openwrt.org>
82
83 commit ecfb4b3fff006372ac5c40871f9bb182fd00444f
84 Author: Felix Fietkau <nbd@openwrt.org>
85 Date:   Sat Sep 27 22:15:43 2014 +0200
86
87     ath9k: use ah->get_mac_revision for all SoC devices if available
88     
89     It is needed for AR934x as well
90     
91     Signed-off-by: Felix Fietkau <nbd@openwrt.org>
92
93 commit c11113bc25df22898fb995d3205bdc4f27c98073
94 Author: Felix Fietkau <nbd@openwrt.org>
95 Date:   Sat Sep 27 18:04:58 2014 +0200
96
97     ath5k: add missing include for debug code
98     
99     Needed for calling vmalloc()/vfree()
100     
101     Signed-off-by: Felix Fietkau <nbd@openwrt.org>
102
103 commit 83f76a9f9a42773c7eef90bb86b4b2c16b0b3755
104 Author: Felix Fietkau <nbd@openwrt.org>
105 Date:   Sat Sep 27 15:58:51 2014 +0200
106
107     ath5k: fix AHB kconfig dependency
108     
109     Signed-off-by: Felix Fietkau <nbd@openwrt.org>
110
111 commit ddd67f2a5cfd73fad4b78190025402d419b9f0a9
112 Author: Felix Fietkau <nbd@openwrt.org>
113 Date:   Sat Sep 27 15:57:09 2014 +0200
114
115     Revert "ath5k: Remove AHB bus support"
116     
117     This reverts commit 093ec3c5337434f40d77c1af06c139da3e5ba6dc.
118
119 --- a/drivers/net/wireless/ath/ath5k/Kconfig
120 +++ b/drivers/net/wireless/ath/ath5k/Kconfig
121 @@ -2,12 +2,14 @@ config ATH5K
122         tristate "Atheros 5xxx wireless cards support"
123         depends on m
124         depends on PCI && MAC80211
125 +       depends on (PCI || ATHEROS_AR231X) && MAC80211
126         select ATH_COMMON
127         select MAC80211_LEDS
128         select BACKPORT_LEDS_CLASS
129         select BACKPORT_NEW_LEDS
130         select BACKPORT_AVERAGE
131 -       select ATH5K_PCI
132 +       select ATH5K_AHB if ATHEROS_AR231X
133 +       select ATH5K_PCI if !ATHEROS_AR231X
134         ---help---
135           This module adds support for wireless adapters based on
136           Atheros 5xxx chipset.
137 @@ -52,9 +54,16 @@ config ATH5K_TRACER
138  
139           If unsure, say N.
140  
141 +config ATH5K_AHB
142 +       bool "Atheros 5xxx AHB bus support"
143 +       depends on ATHEROS_AR231X
144 +       ---help---
145 +         This adds support for WiSoC type chipsets of the 5xxx Atheros
146 +         family.
147 +
148  config ATH5K_PCI
149         bool "Atheros 5xxx PCI bus support"
150 -       depends on PCI
151 +       depends on !ATHEROS_AR231X
152         ---help---
153           This adds support for PCI type chipsets of the 5xxx Atheros
154           family.
155 --- /dev/null
156 +++ b/drivers/net/wireless/ath/ath5k/ahb.c
157 @@ -0,0 +1,234 @@
158 +/*
159 + * Copyright (c) 2008-2009 Atheros Communications Inc.
160 + * Copyright (c) 2009 Gabor Juhos <juhosg@openwrt.org>
161 + * Copyright (c) 2009 Imre Kaloz <kaloz@openwrt.org>
162 + *
163 + * Permission to use, copy, modify, and/or distribute this software for any
164 + * purpose with or without fee is hereby granted, provided that the above
165 + * copyright notice and this permission notice appear in all copies.
166 + *
167 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
168 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
169 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
170 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
171 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
172 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
173 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
174 + */
175 +
176 +#include <linux/nl80211.h>
177 +#include <linux/platform_device.h>
178 +#include <linux/etherdevice.h>
179 +#include <linux/export.h>
180 +#include <ar231x_platform.h>
181 +#include "ath5k.h"
182 +#include "debug.h"
183 +#include "base.h"
184 +#include "reg.h"
185 +
186 +/* return bus cachesize in 4B word units */
187 +static void ath5k_ahb_read_cachesize(struct ath_common *common, int *csz)
188 +{
189 +       *csz = L1_CACHE_BYTES >> 2;
190 +}
191 +
192 +static bool
193 +ath5k_ahb_eeprom_read(struct ath_common *common, u32 off, u16 *data)
194 +{
195 +       struct ath5k_hw *ah = common->priv;
196 +       struct platform_device *pdev = to_platform_device(ah->dev);
197 +       struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
198 +       u16 *eeprom, *eeprom_end;
199 +
200 +       eeprom = (u16 *) bcfg->radio;
201 +       eeprom_end = ((void *) bcfg->config) + BOARD_CONFIG_BUFSZ;
202 +
203 +       eeprom += off;
204 +       if (eeprom > eeprom_end)
205 +               return false;
206 +
207 +       *data = *eeprom;
208 +       return true;
209 +}
210 +
211 +int ath5k_hw_read_srev(struct ath5k_hw *ah)
212 +{
213 +       struct platform_device *pdev = to_platform_device(ah->dev);
214 +       struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
215 +       ah->ah_mac_srev = bcfg->devid;
216 +       return 0;
217 +}
218 +
219 +static int ath5k_ahb_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
220 +{
221 +       struct platform_device *pdev = to_platform_device(ah->dev);
222 +       struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
223 +       u8 *cfg_mac;
224 +
225 +       if (to_platform_device(ah->dev)->id == 0)
226 +               cfg_mac = bcfg->config->wlan0_mac;
227 +       else
228 +               cfg_mac = bcfg->config->wlan1_mac;
229 +
230 +       memcpy(mac, cfg_mac, ETH_ALEN);
231 +       return 0;
232 +}
233 +
234 +static const struct ath_bus_ops ath_ahb_bus_ops = {
235 +       .ath_bus_type = ATH_AHB,
236 +       .read_cachesize = ath5k_ahb_read_cachesize,
237 +       .eeprom_read = ath5k_ahb_eeprom_read,
238 +       .eeprom_read_mac = ath5k_ahb_eeprom_read_mac,
239 +};
240 +
241 +/*Initialization*/
242 +static int ath_ahb_probe(struct platform_device *pdev)
243 +{
244 +       struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
245 +       struct ath5k_hw *ah;
246 +       struct ieee80211_hw *hw;
247 +       struct resource *res;
248 +       void __iomem *mem;
249 +       int irq;
250 +       int ret = 0;
251 +       u32 reg;
252 +
253 +       if (!dev_get_platdata(&pdev->dev)) {
254 +               dev_err(&pdev->dev, "no platform data specified\n");
255 +               ret = -EINVAL;
256 +               goto err_out;
257 +       }
258 +
259 +       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
260 +       if (res == NULL) {
261 +               dev_err(&pdev->dev, "no memory resource found\n");
262 +               ret = -ENXIO;
263 +               goto err_out;
264 +       }
265 +
266 +       mem = ioremap_nocache(res->start, resource_size(res));
267 +       if (mem == NULL) {
268 +               dev_err(&pdev->dev, "ioremap failed\n");
269 +               ret = -ENOMEM;
270 +               goto err_out;
271 +       }
272 +
273 +       res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
274 +       if (res == NULL) {
275 +               dev_err(&pdev->dev, "no IRQ resource found\n");
276 +               ret = -ENXIO;
277 +               goto err_iounmap;
278 +       }
279 +
280 +       irq = res->start;
281 +
282 +       hw = ieee80211_alloc_hw(sizeof(struct ath5k_hw), &ath5k_hw_ops);
283 +       if (hw == NULL) {
284 +               dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
285 +               ret = -ENOMEM;
286 +               goto err_iounmap;
287 +       }
288 +
289 +       ah = hw->priv;
290 +       ah->hw = hw;
291 +       ah->dev = &pdev->dev;
292 +       ah->iobase = mem;
293 +       ah->irq = irq;
294 +       ah->devid = bcfg->devid;
295 +
296 +       if (bcfg->devid >= AR5K_SREV_AR2315_R6) {
297 +               /* Enable WMAC AHB arbitration */
298 +               reg = ioread32((void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
299 +               reg |= AR5K_AR2315_AHB_ARB_CTL_WLAN;
300 +               iowrite32(reg, (void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
301 +
302 +               /* Enable global WMAC swapping */
303 +               reg = ioread32((void __iomem *) AR5K_AR2315_BYTESWAP);
304 +               reg |= AR5K_AR2315_BYTESWAP_WMAC;
305 +               iowrite32(reg, (void __iomem *) AR5K_AR2315_BYTESWAP);
306 +       } else {
307 +               /* Enable WMAC DMA access (assuming 5312 or 231x*/
308 +               /* TODO: check other platforms */
309 +               reg = ioread32((void __iomem *) AR5K_AR5312_ENABLE);
310 +               if (to_platform_device(ah->dev)->id == 0)
311 +                       reg |= AR5K_AR5312_ENABLE_WLAN0;
312 +               else
313 +                       reg |= AR5K_AR5312_ENABLE_WLAN1;
314 +               iowrite32(reg, (void __iomem *) AR5K_AR5312_ENABLE);
315 +
316 +               /*
317 +                * On a dual-band AR5312, the multiband radio is only
318 +                * used as pass-through. Disable 2 GHz support in the
319 +                * driver for it
320 +                */
321 +               if (to_platform_device(ah->dev)->id == 0 &&
322 +                   (bcfg->config->flags & (BD_WLAN0 | BD_WLAN1)) ==
323 +                    (BD_WLAN1 | BD_WLAN0))
324 +                       ah->ah_capabilities.cap_needs_2GHz_ovr = true;
325 +               else
326 +                       ah->ah_capabilities.cap_needs_2GHz_ovr = false;
327 +       }
328 +
329 +       ret = ath5k_init_ah(ah, &ath_ahb_bus_ops);
330 +       if (ret != 0) {
331 +               dev_err(&pdev->dev, "failed to attach device, err=%d\n", ret);
332 +               ret = -ENODEV;
333 +               goto err_free_hw;
334 +       }
335 +
336 +       platform_set_drvdata(pdev, hw);
337 +
338 +       return 0;
339 +
340 + err_free_hw:
341 +       ieee80211_free_hw(hw);
342 + err_iounmap:
343 +        iounmap(mem);
344 + err_out:
345 +       return ret;
346 +}
347 +
348 +static int ath_ahb_remove(struct platform_device *pdev)
349 +{
350 +       struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
351 +       struct ieee80211_hw *hw = platform_get_drvdata(pdev);
352 +       struct ath5k_hw *ah;
353 +       u32 reg;
354 +
355 +       if (!hw)
356 +               return 0;
357 +
358 +       ah = hw->priv;
359 +
360 +       if (bcfg->devid >= AR5K_SREV_AR2315_R6) {
361 +               /* Disable WMAC AHB arbitration */
362 +               reg = ioread32((void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
363 +               reg &= ~AR5K_AR2315_AHB_ARB_CTL_WLAN;
364 +               iowrite32(reg, (void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
365 +       } else {
366 +               /*Stop DMA access */
367 +               reg = ioread32((void __iomem *) AR5K_AR5312_ENABLE);
368 +               if (to_platform_device(ah->dev)->id == 0)
369 +                       reg &= ~AR5K_AR5312_ENABLE_WLAN0;
370 +               else
371 +                       reg &= ~AR5K_AR5312_ENABLE_WLAN1;
372 +               iowrite32(reg, (void __iomem *) AR5K_AR5312_ENABLE);
373 +       }
374 +
375 +       ath5k_deinit_ah(ah);
376 +       iounmap(ah->iobase);
377 +       ieee80211_free_hw(hw);
378 +
379 +       return 0;
380 +}
381 +
382 +static struct platform_driver ath_ahb_driver = {
383 +       .probe      = ath_ahb_probe,
384 +       .remove     = ath_ahb_remove,
385 +       .driver         = {
386 +               .name   = "ar231x-wmac",
387 +               .owner  = THIS_MODULE,
388 +       },
389 +};
390 +
391 +module_platform_driver(ath_ahb_driver);
392 --- a/drivers/net/wireless/ath/ath5k/ath5k.h
393 +++ b/drivers/net/wireless/ath/ath5k/ath5k.h
394 @@ -1647,6 +1647,32 @@ static inline struct ath_regulatory *ath
395         return &(ath5k_hw_common(ah)->regulatory);
396  }
397  
398 +#ifdef CONFIG_ATHEROS_AR231X
399 +#define AR5K_AR2315_PCI_BASE   ((void __iomem *)0xb0100000)
400 +
401 +static inline void __iomem *ath5k_ahb_reg(struct ath5k_hw *ah, u16 reg)
402 +{
403 +       /* On AR2315 and AR2317 the PCI clock domain registers
404 +        * are outside of the WMAC register space */
405 +       if (unlikely((reg >= 0x4000) && (reg < 0x5000) &&
406 +           (ah->ah_mac_srev >= AR5K_SREV_AR2315_R6)))
407 +               return AR5K_AR2315_PCI_BASE + reg;
408 +
409 +       return ah->iobase + reg;
410 +}
411 +
412 +static inline u32 ath5k_hw_reg_read(struct ath5k_hw *ah, u16 reg)
413 +{
414 +       return ioread32(ath5k_ahb_reg(ah, reg));
415 +}
416 +
417 +static inline void ath5k_hw_reg_write(struct ath5k_hw *ah, u32 val, u16 reg)
418 +{
419 +       iowrite32(val, ath5k_ahb_reg(ah, reg));
420 +}
421 +
422 +#else
423 +
424  static inline u32 ath5k_hw_reg_read(struct ath5k_hw *ah, u16 reg)
425  {
426         return ioread32(ah->iobase + reg);
427 @@ -1657,6 +1683,8 @@ static inline void ath5k_hw_reg_write(st
428         iowrite32(val, ah->iobase + reg);
429  }
430  
431 +#endif
432 +
433  static inline enum ath_bus_type ath5k_get_bus_type(struct ath5k_hw *ah)
434  {
435         return ath5k_hw_common(ah)->bus_ops->ath_bus_type;
436 --- a/drivers/net/wireless/ath/ath5k/base.c
437 +++ b/drivers/net/wireless/ath/ath5k/base.c
438 @@ -99,6 +99,15 @@ static int ath5k_reset(struct ath5k_hw *
439  
440  /* Known SREVs */
441  static const struct ath5k_srev_name srev_names[] = {
442 +#ifdef CONFIG_ATHEROS_AR231X
443 +       { "5312",       AR5K_VERSION_MAC,       AR5K_SREV_AR5312_R2 },
444 +       { "5312",       AR5K_VERSION_MAC,       AR5K_SREV_AR5312_R7 },
445 +       { "2313",       AR5K_VERSION_MAC,       AR5K_SREV_AR2313_R8 },
446 +       { "2315",       AR5K_VERSION_MAC,       AR5K_SREV_AR2315_R6 },
447 +       { "2315",       AR5K_VERSION_MAC,       AR5K_SREV_AR2315_R7 },
448 +       { "2317",       AR5K_VERSION_MAC,       AR5K_SREV_AR2317_R1 },
449 +       { "2317",       AR5K_VERSION_MAC,       AR5K_SREV_AR2317_R2 },
450 +#else
451         { "5210",       AR5K_VERSION_MAC,       AR5K_SREV_AR5210 },
452         { "5311",       AR5K_VERSION_MAC,       AR5K_SREV_AR5311 },
453         { "5311A",      AR5K_VERSION_MAC,       AR5K_SREV_AR5311A },
454 @@ -117,6 +126,7 @@ static const struct ath5k_srev_name srev
455         { "5418",       AR5K_VERSION_MAC,       AR5K_SREV_AR5418 },
456         { "2425",       AR5K_VERSION_MAC,       AR5K_SREV_AR2425 },
457         { "2417",       AR5K_VERSION_MAC,       AR5K_SREV_AR2417 },
458 +#endif
459         { "xxxxx",      AR5K_VERSION_MAC,       AR5K_SREV_UNKNOWN },
460         { "5110",       AR5K_VERSION_RAD,       AR5K_SREV_RAD_5110 },
461         { "5111",       AR5K_VERSION_RAD,       AR5K_SREV_RAD_5111 },
462 @@ -132,6 +142,10 @@ static const struct ath5k_srev_name srev
463         { "5413",       AR5K_VERSION_RAD,       AR5K_SREV_RAD_5413 },
464         { "5424",       AR5K_VERSION_RAD,       AR5K_SREV_RAD_5424 },
465         { "5133",       AR5K_VERSION_RAD,       AR5K_SREV_RAD_5133 },
466 +#ifdef CONFIG_ATHEROS_AR231X
467 +       { "2316",       AR5K_VERSION_RAD,       AR5K_SREV_RAD_2316 },
468 +       { "2317",       AR5K_VERSION_RAD,       AR5K_SREV_RAD_2317 },
469 +#endif
470         { "xxxxx",      AR5K_VERSION_RAD,       AR5K_SREV_UNKNOWN },
471  };
472  
473 --- a/drivers/net/wireless/ath/ath5k/led.c
474 +++ b/drivers/net/wireless/ath/ath5k/led.c
475 @@ -163,14 +163,20 @@ int ath5k_init_leds(struct ath5k_hw *ah)
476  {
477         int ret = 0;
478         struct ieee80211_hw *hw = ah->hw;
479 +#ifndef CONFIG_ATHEROS_AR231X
480         struct pci_dev *pdev = ah->pdev;
481 +#endif
482         char name[ATH5K_LED_MAX_NAME_LEN + 1];
483         const struct pci_device_id *match;
484  
485         if (!ah->pdev)
486                 return 0;
487  
488 +#ifdef CONFIG_ATHEROS_AR231X
489 +       match = NULL;
490 +#else
491         match = pci_match_id(&ath5k_led_devices[0], pdev);
492 +#endif
493         if (match) {
494                 __set_bit(ATH_STAT_LEDSOFT, ah->status);
495                 ah->led_pin = ATH_PIN(match->driver_data);
496 --- a/drivers/net/wireless/ath/ath5k/debug.c
497 +++ b/drivers/net/wireless/ath/ath5k/debug.c
498 @@ -65,6 +65,7 @@
499  
500  #include <linux/seq_file.h>
501  #include <linux/list.h>
502 +#include <linux/vmalloc.h>
503  #include "debug.h"
504  #include "ath5k.h"
505  #include "reg.h"
506 --- a/drivers/net/wireless/ath/ath9k/hw.c
507 +++ b/drivers/net/wireless/ath/ath9k/hw.c
508 @@ -222,31 +222,28 @@ static void ath9k_hw_read_revisions(stru
509  {
510         u32 val;
511  
512 +       if (ah->get_mac_revision)
513 +               ah->hw_version.macRev = ah->get_mac_revision();
514 +
515         switch (ah->hw_version.devid) {
516         case AR5416_AR9100_DEVID:
517                 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
518                 break;
519         case AR9300_DEVID_AR9330:
520                 ah->hw_version.macVersion = AR_SREV_VERSION_9330;
521 -               if (ah->get_mac_revision) {
522 -                       ah->hw_version.macRev = ah->get_mac_revision();
523 -               } else {
524 +               if (!ah->get_mac_revision) {
525                         val = REG_READ(ah, AR_SREV);
526                         ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
527                 }
528                 return;
529         case AR9300_DEVID_AR9340:
530                 ah->hw_version.macVersion = AR_SREV_VERSION_9340;
531 -               val = REG_READ(ah, AR_SREV);
532 -               ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
533                 return;
534         case AR9300_DEVID_QCA955X:
535                 ah->hw_version.macVersion = AR_SREV_VERSION_9550;
536                 return;
537         case AR9300_DEVID_AR953X:
538                 ah->hw_version.macVersion = AR_SREV_VERSION_9531;
539 -               if (ah->get_mac_revision)
540 -                       ah->hw_version.macRev = ah->get_mac_revision();
541                 return;
542         }
543  
544 @@ -704,6 +701,8 @@ static void ath9k_hw_init_pll(struct ath
545  {
546         u32 pll;
547  
548 +       pll = ath9k_hw_compute_pll_control(ah, chan);
549 +
550         if (AR_SREV_9485(ah) || AR_SREV_9565(ah)) {
551                 /* program BB PLL ki and kd value, ki=0x4, kd=0x40 */
552                 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
553 @@ -754,7 +753,8 @@ static void ath9k_hw_init_pll(struct ath
554                 REG_RMW_FIELD(ah, AR_CH0_DDR_DPLL3,
555                               AR_CH0_DPLL3_PHASE_SHIFT, 0x1);
556  
557 -               REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c);
558 +               REG_WRITE(ah, AR_RTC_PLL_CONTROL,
559 +                         pll | AR_RTC_9300_PLL_BYPASS);
560                 udelay(1000);
561  
562                 /* program refdiv, nint, frac to RTC register */
563 @@ -770,7 +770,8 @@ static void ath9k_hw_init_pll(struct ath
564         } else if (AR_SREV_9340(ah) || AR_SREV_9550(ah) || AR_SREV_9531(ah)) {
565                 u32 regval, pll2_divint, pll2_divfrac, refdiv;
566  
567 -               REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c);
568 +               REG_WRITE(ah, AR_RTC_PLL_CONTROL,
569 +                         pll | AR_RTC_9300_SOC_PLL_BYPASS);
570                 udelay(1000);
571  
572                 REG_SET_BIT(ah, AR_PHY_PLL_MODE, 0x1 << 16);
573 @@ -843,7 +844,6 @@ static void ath9k_hw_init_pll(struct ath
574                 udelay(1000);
575         }
576  
577 -       pll = ath9k_hw_compute_pll_control(ah, chan);
578         if (AR_SREV_9565(ah))
579                 pll |= 0x40000;
580         REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
581 @@ -1192,9 +1192,12 @@ static void ath9k_hw_set_operating_mode(
582  
583         switch (opmode) {
584         case NL80211_IFTYPE_ADHOC:
585 -               set |= AR_STA_ID1_ADHOC;
586 -               REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
587 -               break;
588 +               if (!AR_SREV_9340_13(ah)) {
589 +                       set |= AR_STA_ID1_ADHOC;
590 +                       REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
591 +                       break;
592 +               }
593 +               /* fall through */
594         case NL80211_IFTYPE_MESH_POINT:
595         case NL80211_IFTYPE_AP:
596                 set |= AR_STA_ID1_STA_AP;
597 --- a/drivers/net/wireless/ath/ath9k/reg.h
598 +++ b/drivers/net/wireless/ath/ath9k/reg.h
599 @@ -903,6 +903,10 @@
600  #define AR_SREV_9340(_ah) \
601         (((_ah)->hw_version.macVersion == AR_SREV_VERSION_9340))
602  
603 +#define AR_SREV_9340_13(_ah) \
604 +       (AR_SREV_9340((_ah)) && \
605 +        ((_ah)->hw_version.macRev == AR_SREV_REVISION_9340_13))
606 +
607  #define AR_SREV_9340_13_OR_LATER(_ah) \
608         (AR_SREV_9340((_ah)) && \
609          ((_ah)->hw_version.macRev >= AR_SREV_REVISION_9340_13))
610 @@ -1240,12 +1244,23 @@ enum {
611  #define AR_CH0_DPLL3_PHASE_SHIFT_S   23
612  #define AR_PHY_CCA_NOM_VAL_2GHZ      -118
613  
614 +#define AR_RTC_9300_SOC_PLL_DIV_INT          0x0000003f
615 +#define AR_RTC_9300_SOC_PLL_DIV_INT_S        0
616 +#define AR_RTC_9300_SOC_PLL_DIV_FRAC         0x000fffc0
617 +#define AR_RTC_9300_SOC_PLL_DIV_FRAC_S       6
618 +#define AR_RTC_9300_SOC_PLL_REFDIV           0x01f00000
619 +#define AR_RTC_9300_SOC_PLL_REFDIV_S         20
620 +#define AR_RTC_9300_SOC_PLL_CLKSEL           0x06000000
621 +#define AR_RTC_9300_SOC_PLL_CLKSEL_S         25
622 +#define AR_RTC_9300_SOC_PLL_BYPASS           0x08000000
623 +
624  #define AR_RTC_9300_PLL_DIV          0x000003ff
625  #define AR_RTC_9300_PLL_DIV_S        0
626  #define AR_RTC_9300_PLL_REFDIV       0x00003C00
627  #define AR_RTC_9300_PLL_REFDIV_S     10
628  #define AR_RTC_9300_PLL_CLKSEL       0x0000C000
629  #define AR_RTC_9300_PLL_CLKSEL_S     14
630 +#define AR_RTC_9300_PLL_BYPASS       0x00010000
631  
632  #define AR_RTC_9160_PLL_DIV    0x000003ff
633  #define AR_RTC_9160_PLL_DIV_S   0
634 --- a/drivers/net/wireless/ath/ath9k/ar5008_phy.c
635 +++ b/drivers/net/wireless/ath/ath9k/ar5008_phy.c
636 @@ -1004,9 +1004,11 @@ static bool ar5008_hw_ani_control_new(st
637         case ATH9K_ANI_FIRSTEP_LEVEL:{
638                 u32 level = param;
639  
640 -               value = level;
641 +               value = level * 2;
642                 REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
643                               AR_PHY_FIND_SIG_FIRSTEP, value);
644 +               REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW,
645 +                             AR_PHY_FIND_SIG_FIRSTEP_LOW, value);
646  
647                 if (level != aniState->firstepLevel) {
648                         ath_dbg(common, ANI,
649 @@ -1040,9 +1042,8 @@ static bool ar5008_hw_ani_control_new(st
650                 REG_RMW_FIELD(ah, AR_PHY_TIMING5,
651                               AR_PHY_TIMING5_CYCPWR_THR1, value);
652  
653 -               if (IS_CHAN_HT40(ah->curchan))
654 -                       REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
655 -                                     AR_PHY_EXT_TIMING5_CYCPWR_THR1, value);
656 +               REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
657 +                                 AR_PHY_EXT_TIMING5_CYCPWR_THR1, value - 1);
658  
659                 if (level != aniState->spurImmunityLevel) {
660                         ath_dbg(common, ANI,
661 --- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
662 +++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
663 @@ -517,6 +517,23 @@ static void ar9003_hw_spur_mitigate(stru
664         ar9003_hw_spur_mitigate_ofdm(ah, chan);
665  }
666  
667 +static u32 ar9003_hw_compute_pll_control_soc(struct ath_hw *ah,
668 +                                            struct ath9k_channel *chan)
669 +{
670 +       u32 pll;
671 +
672 +       pll = SM(0x5, AR_RTC_9300_SOC_PLL_REFDIV);
673 +
674 +       if (chan && IS_CHAN_HALF_RATE(chan))
675 +               pll |= SM(0x1, AR_RTC_9300_SOC_PLL_CLKSEL);
676 +       else if (chan && IS_CHAN_QUARTER_RATE(chan))
677 +               pll |= SM(0x2, AR_RTC_9300_SOC_PLL_CLKSEL);
678 +
679 +       pll |= SM(0x2c, AR_RTC_9300_SOC_PLL_DIV_INT);
680 +
681 +       return pll;
682 +}
683 +
684  static u32 ar9003_hw_compute_pll_control(struct ath_hw *ah,
685                                          struct ath9k_channel *chan)
686  {
687 @@ -1781,7 +1798,12 @@ void ar9003_hw_attach_phy_ops(struct ath
688  
689         priv_ops->rf_set_freq = ar9003_hw_set_channel;
690         priv_ops->spur_mitigate_freq = ar9003_hw_spur_mitigate;
691 -       priv_ops->compute_pll_control = ar9003_hw_compute_pll_control;
692 +
693 +       if (AR_SREV_9340(ah) || AR_SREV_9550(ah) || AR_SREV_9531(ah))
694 +               priv_ops->compute_pll_control = ar9003_hw_compute_pll_control_soc;
695 +       else
696 +               priv_ops->compute_pll_control = ar9003_hw_compute_pll_control;
697 +
698         priv_ops->set_channel_regs = ar9003_hw_set_channel_regs;
699         priv_ops->init_bb = ar9003_hw_init_bb;
700         priv_ops->process_ini = ar9003_hw_process_ini;
701 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
702 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
703 @@ -381,16 +381,27 @@ static int ar9002_hw_proc_txdesc(struct 
704         ts->evm1 = ads->AR_TxEVM1;
705         ts->evm2 = ads->AR_TxEVM2;
706  
707 -       status = ACCESS_ONCE(ads->ds_ctl4);
708 -       ts->duration[0] = MS(status, AR_PacketDur0);
709 -       ts->duration[1] = MS(status, AR_PacketDur1);
710 -       status = ACCESS_ONCE(ads->ds_ctl5);
711 -       ts->duration[2] = MS(status, AR_PacketDur2);
712 -       ts->duration[3] = MS(status, AR_PacketDur3);
713 -
714         return 0;
715  }
716  
717 +static int ar9002_hw_get_duration(struct ath_hw *ah, const void *ds, int index)
718 +{
719 +       struct ar5416_desc *ads = AR5416DESC(ds);
720 +
721 +       switch (index) {
722 +       case 0:
723 +               return MS(ACCESS_ONCE(ads->ds_ctl4), AR_PacketDur0);
724 +       case 1:
725 +               return MS(ACCESS_ONCE(ads->ds_ctl4), AR_PacketDur1);
726 +       case 2:
727 +               return MS(ACCESS_ONCE(ads->ds_ctl5), AR_PacketDur2);
728 +       case 3:
729 +               return MS(ACCESS_ONCE(ads->ds_ctl5), AR_PacketDur3);
730 +       default:
731 +               return -1;
732 +       }
733 +}
734 +
735  void ath9k_hw_setuprxdesc(struct ath_hw *ah, struct ath_desc *ds,
736                           u32 size, u32 flags)
737  {
738 @@ -413,4 +424,5 @@ void ar9002_hw_attach_mac_ops(struct ath
739         ops->get_isr = ar9002_hw_get_isr;
740         ops->set_txdesc = ar9002_set_txdesc;
741         ops->proc_txdesc = ar9002_hw_proc_txdesc;
742 +       ops->get_duration = ar9002_hw_get_duration;
743  }
744 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
745 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
746 @@ -355,11 +355,9 @@ static int ar9003_hw_proc_txdesc(struct 
747                                  struct ath_tx_status *ts)
748  {
749         struct ar9003_txs *ads;
750 -       struct ar9003_txc *adc;
751         u32 status;
752  
753         ads = &ah->ts_ring[ah->ts_tail];
754 -       adc = (struct ar9003_txc *)ads;
755  
756         status = ACCESS_ONCE(ads->status8);
757         if ((status & AR_TxDone) == 0)
758 @@ -428,18 +426,29 @@ static int ar9003_hw_proc_txdesc(struct 
759         ts->ts_rssi_ext1 = MS(status, AR_TxRSSIAnt11);
760         ts->ts_rssi_ext2 = MS(status, AR_TxRSSIAnt12);
761  
762 -       status = ACCESS_ONCE(adc->ctl15);
763 -       ts->duration[0] = MS(status, AR_PacketDur0);
764 -       ts->duration[1] = MS(status, AR_PacketDur1);
765 -       status = ACCESS_ONCE(adc->ctl16);
766 -       ts->duration[2] = MS(status, AR_PacketDur2);
767 -       ts->duration[3] = MS(status, AR_PacketDur3);
768 -
769         memset(ads, 0, sizeof(*ads));
770  
771         return 0;
772  }
773  
774 +static int ar9003_hw_get_duration(struct ath_hw *ah, const void *ds, int index)
775 +{
776 +       const struct ar9003_txc *adc = ds;
777 +
778 +       switch (index) {
779 +       case 0:
780 +               return MS(ACCESS_ONCE(adc->ctl15), AR_PacketDur0);
781 +       case 1:
782 +               return MS(ACCESS_ONCE(adc->ctl15), AR_PacketDur1);
783 +       case 2:
784 +               return MS(ACCESS_ONCE(adc->ctl16), AR_PacketDur2);
785 +       case 3:
786 +               return MS(ACCESS_ONCE(adc->ctl16), AR_PacketDur3);
787 +       default:
788 +               return 0;
789 +       }
790 +}
791 +
792  void ar9003_hw_attach_mac_ops(struct ath_hw *hw)
793  {
794         struct ath_hw_ops *ops = ath9k_hw_ops(hw);
795 @@ -449,6 +458,7 @@ void ar9003_hw_attach_mac_ops(struct ath
796         ops->get_isr = ar9003_hw_get_isr;
797         ops->set_txdesc = ar9003_set_txdesc;
798         ops->proc_txdesc = ar9003_hw_proc_txdesc;
799 +       ops->get_duration = ar9003_hw_get_duration;
800  }
801  
802  void ath9k_hw_set_rx_bufsize(struct ath_hw *ah, u16 buf_size)
803 --- a/drivers/net/wireless/ath/ath9k/dynack.c
804 +++ b/drivers/net/wireless/ath/ath9k/dynack.c
805 @@ -202,7 +202,7 @@ void ath_dynack_sample_tx_ts(struct ath_
806         ridx = ts->ts_rateindex;
807  
808         da->st_rbf.ts[da->st_rbf.t_rb].tstamp = ts->ts_tstamp;
809 -       da->st_rbf.ts[da->st_rbf.t_rb].dur = ts->duration[ts->ts_rateindex];
810 +       da->st_rbf.ts[da->st_rbf.t_rb].dur = ts->duration;
811         ether_addr_copy(da->st_rbf.addr[da->st_rbf.t_rb].h_dest, hdr->addr1);
812         ether_addr_copy(da->st_rbf.addr[da->st_rbf.t_rb].h_src, hdr->addr2);
813  
814 --- a/drivers/net/wireless/ath/ath9k/hw-ops.h
815 +++ b/drivers/net/wireless/ath/ath9k/hw-ops.h
816 @@ -67,6 +67,12 @@ static inline int ath9k_hw_txprocdesc(st
817         return ath9k_hw_ops(ah)->proc_txdesc(ah, ds, ts);
818  }
819  
820 +static inline int ath9k_hw_get_duration(struct ath_hw *ah, const void *ds,
821 +                                       int index)
822 +{
823 +       return ath9k_hw_ops(ah)->get_duration(ah, ds, index);
824 +}
825 +
826  static inline void ath9k_hw_antdiv_comb_conf_get(struct ath_hw *ah,
827                 struct ath_hw_antcomb_conf *antconf)
828  {
829 --- a/drivers/net/wireless/ath/ath9k/hw.h
830 +++ b/drivers/net/wireless/ath/ath9k/hw.h
831 @@ -691,6 +691,7 @@ struct ath_hw_ops {
832                            struct ath_tx_info *i);
833         int (*proc_txdesc)(struct ath_hw *ah, void *ds,
834                            struct ath_tx_status *ts);
835 +       int (*get_duration)(struct ath_hw *ah, const void *ds, int index);
836         void (*antdiv_comb_conf_get)(struct ath_hw *ah,
837                         struct ath_hw_antcomb_conf *antconf);
838         void (*antdiv_comb_conf_set)(struct ath_hw *ah,
839 --- a/drivers/net/wireless/ath/ath9k/mac.h
840 +++ b/drivers/net/wireless/ath/ath9k/mac.h
841 @@ -121,7 +121,7 @@ struct ath_tx_status {
842         u32 evm0;
843         u32 evm1;
844         u32 evm2;
845 -       u32 duration[4];
846 +       u32 duration;
847  };
848  
849  struct ath_rx_status {
850 --- a/drivers/net/wireless/ath/ath9k/xmit.c
851 +++ b/drivers/net/wireless/ath/ath9k/xmit.c
852 @@ -683,6 +683,8 @@ static void ath_tx_process_buffer(struct
853         if (bf_is_ampdu_not_probing(bf))
854                 txq->axq_ampdu_depth--;
855  
856 +       ts->duration = ath9k_hw_get_duration(sc->sc_ah, bf->bf_desc,
857 +                                            ts->ts_rateindex);
858         if (!bf_isampdu(bf)) {
859                 if (!flush) {
860                         info = IEEE80211_SKB_CB(bf->bf_mpdu);