ath9k: fix some issues with ar934x rev 3 (especially ad-hoc mode)
[openwrt/staging/wigyori.git] / package / kernel / mac80211 / patches / 300-pending_work.patch
1 commit 4c82fc569cf2f29e6c66d98ef4a1b0f3b6a98e9d
2 Author: Felix Fietkau <nbd@openwrt.org>
3 Date: Sat Sep 27 22:39:27 2014 +0200
4
5 ath9k_hw: disable hardware ad-hoc flag on ar934x rev 3
6
7 On AR934x rev 3, settin the ad-hoc flag completely messes up hardware
8 state - beacons get stuck, almost no packets make it out, hardware is
9 constantly reset.
10
11 When leaving out that flag and setting up the hw like in AP mode, TSF
12 timers won't be automatically synced, but at least the rest works.
13
14 AR934x rev 2 and older are not affected by this bug
15
16 Signed-off-by: Felix Fietkau <nbd@openwrt.org>
17
18 commit ecfb4b3fff006372ac5c40871f9bb182fd00444f
19 Author: Felix Fietkau <nbd@openwrt.org>
20 Date: Sat Sep 27 22:15:43 2014 +0200
21
22 ath9k: use ah->get_mac_revision for all SoC devices if available
23
24 It is needed for AR934x as well
25
26 Signed-off-by: Felix Fietkau <nbd@openwrt.org>
27
28 commit c11113bc25df22898fb995d3205bdc4f27c98073
29 Author: Felix Fietkau <nbd@openwrt.org>
30 Date: Sat Sep 27 18:04:58 2014 +0200
31
32 ath5k: add missing include for debug code
33
34 Needed for calling vmalloc()/vfree()
35
36 Signed-off-by: Felix Fietkau <nbd@openwrt.org>
37
38 commit 83f76a9f9a42773c7eef90bb86b4b2c16b0b3755
39 Author: Felix Fietkau <nbd@openwrt.org>
40 Date: Sat Sep 27 15:58:51 2014 +0200
41
42 ath5k: fix AHB kconfig dependency
43
44 Signed-off-by: Felix Fietkau <nbd@openwrt.org>
45
46 commit ddd67f2a5cfd73fad4b78190025402d419b9f0a9
47 Author: Felix Fietkau <nbd@openwrt.org>
48 Date: Sat Sep 27 15:57:09 2014 +0200
49
50 Revert "ath5k: Remove AHB bus support"
51
52 This reverts commit 093ec3c5337434f40d77c1af06c139da3e5ba6dc.
53
54 --- a/drivers/net/wireless/ath/ath5k/Kconfig
55 +++ b/drivers/net/wireless/ath/ath5k/Kconfig
56 @@ -2,12 +2,14 @@ config ATH5K
57 tristate "Atheros 5xxx wireless cards support"
58 depends on m
59 depends on PCI && MAC80211
60 + depends on (PCI || ATHEROS_AR231X) && MAC80211
61 select ATH_COMMON
62 select MAC80211_LEDS
63 select BACKPORT_LEDS_CLASS
64 select BACKPORT_NEW_LEDS
65 select BACKPORT_AVERAGE
66 - select ATH5K_PCI
67 + select ATH5K_AHB if ATHEROS_AR231X
68 + select ATH5K_PCI if !ATHEROS_AR231X
69 ---help---
70 This module adds support for wireless adapters based on
71 Atheros 5xxx chipset.
72 @@ -52,9 +54,16 @@ config ATH5K_TRACER
73
74 If unsure, say N.
75
76 +config ATH5K_AHB
77 + bool "Atheros 5xxx AHB bus support"
78 + depends on ATHEROS_AR231X
79 + ---help---
80 + This adds support for WiSoC type chipsets of the 5xxx Atheros
81 + family.
82 +
83 config ATH5K_PCI
84 bool "Atheros 5xxx PCI bus support"
85 - depends on PCI
86 + depends on !ATHEROS_AR231X
87 ---help---
88 This adds support for PCI type chipsets of the 5xxx Atheros
89 family.
90 --- /dev/null
91 +++ b/drivers/net/wireless/ath/ath5k/ahb.c
92 @@ -0,0 +1,234 @@
93 +/*
94 + * Copyright (c) 2008-2009 Atheros Communications Inc.
95 + * Copyright (c) 2009 Gabor Juhos <juhosg@openwrt.org>
96 + * Copyright (c) 2009 Imre Kaloz <kaloz@openwrt.org>
97 + *
98 + * Permission to use, copy, modify, and/or distribute this software for any
99 + * purpose with or without fee is hereby granted, provided that the above
100 + * copyright notice and this permission notice appear in all copies.
101 + *
102 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
103 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
104 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
105 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
106 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
107 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
108 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
109 + */
110 +
111 +#include <linux/nl80211.h>
112 +#include <linux/platform_device.h>
113 +#include <linux/etherdevice.h>
114 +#include <linux/export.h>
115 +#include <ar231x_platform.h>
116 +#include "ath5k.h"
117 +#include "debug.h"
118 +#include "base.h"
119 +#include "reg.h"
120 +
121 +/* return bus cachesize in 4B word units */
122 +static void ath5k_ahb_read_cachesize(struct ath_common *common, int *csz)
123 +{
124 + *csz = L1_CACHE_BYTES >> 2;
125 +}
126 +
127 +static bool
128 +ath5k_ahb_eeprom_read(struct ath_common *common, u32 off, u16 *data)
129 +{
130 + struct ath5k_hw *ah = common->priv;
131 + struct platform_device *pdev = to_platform_device(ah->dev);
132 + struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
133 + u16 *eeprom, *eeprom_end;
134 +
135 + eeprom = (u16 *) bcfg->radio;
136 + eeprom_end = ((void *) bcfg->config) + BOARD_CONFIG_BUFSZ;
137 +
138 + eeprom += off;
139 + if (eeprom > eeprom_end)
140 + return false;
141 +
142 + *data = *eeprom;
143 + return true;
144 +}
145 +
146 +int ath5k_hw_read_srev(struct ath5k_hw *ah)
147 +{
148 + struct platform_device *pdev = to_platform_device(ah->dev);
149 + struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
150 + ah->ah_mac_srev = bcfg->devid;
151 + return 0;
152 +}
153 +
154 +static int ath5k_ahb_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
155 +{
156 + struct platform_device *pdev = to_platform_device(ah->dev);
157 + struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
158 + u8 *cfg_mac;
159 +
160 + if (to_platform_device(ah->dev)->id == 0)
161 + cfg_mac = bcfg->config->wlan0_mac;
162 + else
163 + cfg_mac = bcfg->config->wlan1_mac;
164 +
165 + memcpy(mac, cfg_mac, ETH_ALEN);
166 + return 0;
167 +}
168 +
169 +static const struct ath_bus_ops ath_ahb_bus_ops = {
170 + .ath_bus_type = ATH_AHB,
171 + .read_cachesize = ath5k_ahb_read_cachesize,
172 + .eeprom_read = ath5k_ahb_eeprom_read,
173 + .eeprom_read_mac = ath5k_ahb_eeprom_read_mac,
174 +};
175 +
176 +/*Initialization*/
177 +static int ath_ahb_probe(struct platform_device *pdev)
178 +{
179 + struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
180 + struct ath5k_hw *ah;
181 + struct ieee80211_hw *hw;
182 + struct resource *res;
183 + void __iomem *mem;
184 + int irq;
185 + int ret = 0;
186 + u32 reg;
187 +
188 + if (!dev_get_platdata(&pdev->dev)) {
189 + dev_err(&pdev->dev, "no platform data specified\n");
190 + ret = -EINVAL;
191 + goto err_out;
192 + }
193 +
194 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
195 + if (res == NULL) {
196 + dev_err(&pdev->dev, "no memory resource found\n");
197 + ret = -ENXIO;
198 + goto err_out;
199 + }
200 +
201 + mem = ioremap_nocache(res->start, resource_size(res));
202 + if (mem == NULL) {
203 + dev_err(&pdev->dev, "ioremap failed\n");
204 + ret = -ENOMEM;
205 + goto err_out;
206 + }
207 +
208 + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
209 + if (res == NULL) {
210 + dev_err(&pdev->dev, "no IRQ resource found\n");
211 + ret = -ENXIO;
212 + goto err_iounmap;
213 + }
214 +
215 + irq = res->start;
216 +
217 + hw = ieee80211_alloc_hw(sizeof(struct ath5k_hw), &ath5k_hw_ops);
218 + if (hw == NULL) {
219 + dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
220 + ret = -ENOMEM;
221 + goto err_iounmap;
222 + }
223 +
224 + ah = hw->priv;
225 + ah->hw = hw;
226 + ah->dev = &pdev->dev;
227 + ah->iobase = mem;
228 + ah->irq = irq;
229 + ah->devid = bcfg->devid;
230 +
231 + if (bcfg->devid >= AR5K_SREV_AR2315_R6) {
232 + /* Enable WMAC AHB arbitration */
233 + reg = ioread32((void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
234 + reg |= AR5K_AR2315_AHB_ARB_CTL_WLAN;
235 + iowrite32(reg, (void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
236 +
237 + /* Enable global WMAC swapping */
238 + reg = ioread32((void __iomem *) AR5K_AR2315_BYTESWAP);
239 + reg |= AR5K_AR2315_BYTESWAP_WMAC;
240 + iowrite32(reg, (void __iomem *) AR5K_AR2315_BYTESWAP);
241 + } else {
242 + /* Enable WMAC DMA access (assuming 5312 or 231x*/
243 + /* TODO: check other platforms */
244 + reg = ioread32((void __iomem *) AR5K_AR5312_ENABLE);
245 + if (to_platform_device(ah->dev)->id == 0)
246 + reg |= AR5K_AR5312_ENABLE_WLAN0;
247 + else
248 + reg |= AR5K_AR5312_ENABLE_WLAN1;
249 + iowrite32(reg, (void __iomem *) AR5K_AR5312_ENABLE);
250 +
251 + /*
252 + * On a dual-band AR5312, the multiband radio is only
253 + * used as pass-through. Disable 2 GHz support in the
254 + * driver for it
255 + */
256 + if (to_platform_device(ah->dev)->id == 0 &&
257 + (bcfg->config->flags & (BD_WLAN0 | BD_WLAN1)) ==
258 + (BD_WLAN1 | BD_WLAN0))
259 + ah->ah_capabilities.cap_needs_2GHz_ovr = true;
260 + else
261 + ah->ah_capabilities.cap_needs_2GHz_ovr = false;
262 + }
263 +
264 + ret = ath5k_init_ah(ah, &ath_ahb_bus_ops);
265 + if (ret != 0) {
266 + dev_err(&pdev->dev, "failed to attach device, err=%d\n", ret);
267 + ret = -ENODEV;
268 + goto err_free_hw;
269 + }
270 +
271 + platform_set_drvdata(pdev, hw);
272 +
273 + return 0;
274 +
275 + err_free_hw:
276 + ieee80211_free_hw(hw);
277 + err_iounmap:
278 + iounmap(mem);
279 + err_out:
280 + return ret;
281 +}
282 +
283 +static int ath_ahb_remove(struct platform_device *pdev)
284 +{
285 + struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
286 + struct ieee80211_hw *hw = platform_get_drvdata(pdev);
287 + struct ath5k_hw *ah;
288 + u32 reg;
289 +
290 + if (!hw)
291 + return 0;
292 +
293 + ah = hw->priv;
294 +
295 + if (bcfg->devid >= AR5K_SREV_AR2315_R6) {
296 + /* Disable WMAC AHB arbitration */
297 + reg = ioread32((void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
298 + reg &= ~AR5K_AR2315_AHB_ARB_CTL_WLAN;
299 + iowrite32(reg, (void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
300 + } else {
301 + /*Stop DMA access */
302 + reg = ioread32((void __iomem *) AR5K_AR5312_ENABLE);
303 + if (to_platform_device(ah->dev)->id == 0)
304 + reg &= ~AR5K_AR5312_ENABLE_WLAN0;
305 + else
306 + reg &= ~AR5K_AR5312_ENABLE_WLAN1;
307 + iowrite32(reg, (void __iomem *) AR5K_AR5312_ENABLE);
308 + }
309 +
310 + ath5k_deinit_ah(ah);
311 + iounmap(ah->iobase);
312 + ieee80211_free_hw(hw);
313 +
314 + return 0;
315 +}
316 +
317 +static struct platform_driver ath_ahb_driver = {
318 + .probe = ath_ahb_probe,
319 + .remove = ath_ahb_remove,
320 + .driver = {
321 + .name = "ar231x-wmac",
322 + .owner = THIS_MODULE,
323 + },
324 +};
325 +
326 +module_platform_driver(ath_ahb_driver);
327 --- a/drivers/net/wireless/ath/ath5k/ath5k.h
328 +++ b/drivers/net/wireless/ath/ath5k/ath5k.h
329 @@ -1647,6 +1647,32 @@ static inline struct ath_regulatory *ath
330 return &(ath5k_hw_common(ah)->regulatory);
331 }
332
333 +#ifdef CONFIG_ATHEROS_AR231X
334 +#define AR5K_AR2315_PCI_BASE ((void __iomem *)0xb0100000)
335 +
336 +static inline void __iomem *ath5k_ahb_reg(struct ath5k_hw *ah, u16 reg)
337 +{
338 + /* On AR2315 and AR2317 the PCI clock domain registers
339 + * are outside of the WMAC register space */
340 + if (unlikely((reg >= 0x4000) && (reg < 0x5000) &&
341 + (ah->ah_mac_srev >= AR5K_SREV_AR2315_R6)))
342 + return AR5K_AR2315_PCI_BASE + reg;
343 +
344 + return ah->iobase + reg;
345 +}
346 +
347 +static inline u32 ath5k_hw_reg_read(struct ath5k_hw *ah, u16 reg)
348 +{
349 + return ioread32(ath5k_ahb_reg(ah, reg));
350 +}
351 +
352 +static inline void ath5k_hw_reg_write(struct ath5k_hw *ah, u32 val, u16 reg)
353 +{
354 + iowrite32(val, ath5k_ahb_reg(ah, reg));
355 +}
356 +
357 +#else
358 +
359 static inline u32 ath5k_hw_reg_read(struct ath5k_hw *ah, u16 reg)
360 {
361 return ioread32(ah->iobase + reg);
362 @@ -1657,6 +1683,8 @@ static inline void ath5k_hw_reg_write(st
363 iowrite32(val, ah->iobase + reg);
364 }
365
366 +#endif
367 +
368 static inline enum ath_bus_type ath5k_get_bus_type(struct ath5k_hw *ah)
369 {
370 return ath5k_hw_common(ah)->bus_ops->ath_bus_type;
371 --- a/drivers/net/wireless/ath/ath5k/base.c
372 +++ b/drivers/net/wireless/ath/ath5k/base.c
373 @@ -99,6 +99,15 @@ static int ath5k_reset(struct ath5k_hw *
374
375 /* Known SREVs */
376 static const struct ath5k_srev_name srev_names[] = {
377 +#ifdef CONFIG_ATHEROS_AR231X
378 + { "5312", AR5K_VERSION_MAC, AR5K_SREV_AR5312_R2 },
379 + { "5312", AR5K_VERSION_MAC, AR5K_SREV_AR5312_R7 },
380 + { "2313", AR5K_VERSION_MAC, AR5K_SREV_AR2313_R8 },
381 + { "2315", AR5K_VERSION_MAC, AR5K_SREV_AR2315_R6 },
382 + { "2315", AR5K_VERSION_MAC, AR5K_SREV_AR2315_R7 },
383 + { "2317", AR5K_VERSION_MAC, AR5K_SREV_AR2317_R1 },
384 + { "2317", AR5K_VERSION_MAC, AR5K_SREV_AR2317_R2 },
385 +#else
386 { "5210", AR5K_VERSION_MAC, AR5K_SREV_AR5210 },
387 { "5311", AR5K_VERSION_MAC, AR5K_SREV_AR5311 },
388 { "5311A", AR5K_VERSION_MAC, AR5K_SREV_AR5311A },
389 @@ -117,6 +126,7 @@ static const struct ath5k_srev_name srev
390 { "5418", AR5K_VERSION_MAC, AR5K_SREV_AR5418 },
391 { "2425", AR5K_VERSION_MAC, AR5K_SREV_AR2425 },
392 { "2417", AR5K_VERSION_MAC, AR5K_SREV_AR2417 },
393 +#endif
394 { "xxxxx", AR5K_VERSION_MAC, AR5K_SREV_UNKNOWN },
395 { "5110", AR5K_VERSION_RAD, AR5K_SREV_RAD_5110 },
396 { "5111", AR5K_VERSION_RAD, AR5K_SREV_RAD_5111 },
397 @@ -132,6 +142,10 @@ static const struct ath5k_srev_name srev
398 { "5413", AR5K_VERSION_RAD, AR5K_SREV_RAD_5413 },
399 { "5424", AR5K_VERSION_RAD, AR5K_SREV_RAD_5424 },
400 { "5133", AR5K_VERSION_RAD, AR5K_SREV_RAD_5133 },
401 +#ifdef CONFIG_ATHEROS_AR231X
402 + { "2316", AR5K_VERSION_RAD, AR5K_SREV_RAD_2316 },
403 + { "2317", AR5K_VERSION_RAD, AR5K_SREV_RAD_2317 },
404 +#endif
405 { "xxxxx", AR5K_VERSION_RAD, AR5K_SREV_UNKNOWN },
406 };
407
408 --- a/drivers/net/wireless/ath/ath5k/led.c
409 +++ b/drivers/net/wireless/ath/ath5k/led.c
410 @@ -163,14 +163,20 @@ int ath5k_init_leds(struct ath5k_hw *ah)
411 {
412 int ret = 0;
413 struct ieee80211_hw *hw = ah->hw;
414 +#ifndef CONFIG_ATHEROS_AR231X
415 struct pci_dev *pdev = ah->pdev;
416 +#endif
417 char name[ATH5K_LED_MAX_NAME_LEN + 1];
418 const struct pci_device_id *match;
419
420 if (!ah->pdev)
421 return 0;
422
423 +#ifdef CONFIG_ATHEROS_AR231X
424 + match = NULL;
425 +#else
426 match = pci_match_id(&ath5k_led_devices[0], pdev);
427 +#endif
428 if (match) {
429 __set_bit(ATH_STAT_LEDSOFT, ah->status);
430 ah->led_pin = ATH_PIN(match->driver_data);
431 --- a/drivers/net/wireless/ath/ath5k/debug.c
432 +++ b/drivers/net/wireless/ath/ath5k/debug.c
433 @@ -65,6 +65,7 @@
434
435 #include <linux/seq_file.h>
436 #include <linux/list.h>
437 +#include <linux/vmalloc.h>
438 #include "debug.h"
439 #include "ath5k.h"
440 #include "reg.h"
441 --- a/drivers/net/wireless/ath/ath9k/hw.c
442 +++ b/drivers/net/wireless/ath/ath9k/hw.c
443 @@ -222,31 +222,28 @@ static void ath9k_hw_read_revisions(stru
444 {
445 u32 val;
446
447 + if (ah->get_mac_revision)
448 + ah->hw_version.macRev = ah->get_mac_revision();
449 +
450 switch (ah->hw_version.devid) {
451 case AR5416_AR9100_DEVID:
452 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
453 break;
454 case AR9300_DEVID_AR9330:
455 ah->hw_version.macVersion = AR_SREV_VERSION_9330;
456 - if (ah->get_mac_revision) {
457 - ah->hw_version.macRev = ah->get_mac_revision();
458 - } else {
459 + if (!ah->get_mac_revision) {
460 val = REG_READ(ah, AR_SREV);
461 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
462 }
463 return;
464 case AR9300_DEVID_AR9340:
465 ah->hw_version.macVersion = AR_SREV_VERSION_9340;
466 - val = REG_READ(ah, AR_SREV);
467 - ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
468 return;
469 case AR9300_DEVID_QCA955X:
470 ah->hw_version.macVersion = AR_SREV_VERSION_9550;
471 return;
472 case AR9300_DEVID_AR953X:
473 ah->hw_version.macVersion = AR_SREV_VERSION_9531;
474 - if (ah->get_mac_revision)
475 - ah->hw_version.macRev = ah->get_mac_revision();
476 return;
477 }
478
479 @@ -1192,9 +1189,12 @@ static void ath9k_hw_set_operating_mode(
480
481 switch (opmode) {
482 case NL80211_IFTYPE_ADHOC:
483 - set |= AR_STA_ID1_ADHOC;
484 - REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
485 - break;
486 + if (!AR_SREV_9340_13(ah)) {
487 + set |= AR_STA_ID1_ADHOC;
488 + REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
489 + break;
490 + }
491 + /* fall through */
492 case NL80211_IFTYPE_MESH_POINT:
493 case NL80211_IFTYPE_AP:
494 set |= AR_STA_ID1_STA_AP;
495 --- a/drivers/net/wireless/ath/ath9k/reg.h
496 +++ b/drivers/net/wireless/ath/ath9k/reg.h
497 @@ -903,6 +903,10 @@
498 #define AR_SREV_9340(_ah) \
499 (((_ah)->hw_version.macVersion == AR_SREV_VERSION_9340))
500
501 +#define AR_SREV_9340_13(_ah) \
502 + (AR_SREV_9340((_ah)) && \
503 + ((_ah)->hw_version.macRev == AR_SREV_REVISION_9340_13))
504 +
505 #define AR_SREV_9340_13_OR_LATER(_ah) \
506 (AR_SREV_9340((_ah)) && \
507 ((_ah)->hw_version.macRev >= AR_SREV_REVISION_9340_13))