3 Broadcom BCM43xx wireless driver
5 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
6 Stefano Brivio <st3@riseup.net>
7 Michael Buesch <mbuesch@freenet.de>
8 Danny van Dyk <kugelfang@gentoo.org>
9 Andreas Jaggi <andreas.jaggi@waterwave.ch>
11 Some parts of the code in this file are derived from the ipw2200
12 driver Copyright(c) 2003 - 2004 Intel Corporation.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; see the file COPYING. If not, write to
26 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
27 Boston, MA 02110-1301, USA.
31 #include <linux/delay.h>
32 #include <linux/init.h>
33 #include <linux/moduleparam.h>
34 #include <linux/if_arp.h>
35 #include <linux/etherdevice.h>
36 #include <linux/version.h>
37 #include <linux/firmware.h>
38 #include <linux/wireless.h>
39 #include <linux/workqueue.h>
40 #include <linux/skbuff.h>
41 #include <linux/dma-mapping.h>
42 #include <net/iw_handler.h>
45 #include "bcm43xx_main.h"
46 #include "bcm43xx_debugfs.h"
47 #include "bcm43xx_radio.h"
48 #include "bcm43xx_phy.h"
49 #include "bcm43xx_dma.h"
50 #include "bcm43xx_pio.h"
51 #include "bcm43xx_power.h"
52 #include "bcm43xx_wx.h"
53 #include "bcm43xx_ethtool.h"
54 #include "bcm43xx_xmit.h"
55 #include "bcm43xx_sysfs.h"
58 MODULE_DESCRIPTION("Broadcom BCM43xx wireless driver");
59 MODULE_AUTHOR("Martin Langer");
60 MODULE_AUTHOR("Stefano Brivio");
61 MODULE_AUTHOR("Michael Buesch");
62 MODULE_LICENSE("GPL");
64 #ifdef CONFIG_BCM947XX
65 extern char *nvram_get(char *name);
68 #if defined(CONFIG_BCM43XX_DMA) && defined(CONFIG_BCM43XX_PIO)
69 static int modparam_pio;
70 module_param_named(pio, modparam_pio, int, 0444);
71 MODULE_PARM_DESC(pio, "enable(1) / disable(0) PIO mode");
72 #elif defined(CONFIG_BCM43XX_DMA)
73 # define modparam_pio 0
74 #elif defined(CONFIG_BCM43XX_PIO)
75 # define modparam_pio 1
78 static int modparam_bad_frames_preempt;
79 module_param_named(bad_frames_preempt, modparam_bad_frames_preempt, int, 0444);
80 MODULE_PARM_DESC(bad_frames_preempt, "enable(1) / disable(0) Bad Frames Preemption");
82 static int modparam_short_retry = BCM43xx_DEFAULT_SHORT_RETRY_LIMIT;
83 module_param_named(short_retry, modparam_short_retry, int, 0444);
84 MODULE_PARM_DESC(short_retry, "Short-Retry-Limit (0 - 15)");
86 static int modparam_long_retry = BCM43xx_DEFAULT_LONG_RETRY_LIMIT;
87 module_param_named(long_retry, modparam_long_retry, int, 0444);
88 MODULE_PARM_DESC(long_retry, "Long-Retry-Limit (0 - 15)");
90 static int modparam_locale = -1;
91 module_param_named(locale, modparam_locale, int, 0444);
92 MODULE_PARM_DESC(country, "Select LocaleCode 0-11 (For travelers)");
94 static int modparam_noleds;
95 module_param_named(noleds, modparam_noleds, int, 0444);
96 MODULE_PARM_DESC(noleds, "Turn off all LED activity");
98 #ifdef CONFIG_BCM43XX_DEBUG
99 static char modparam_fwpostfix[64];
100 module_param_string(fwpostfix, modparam_fwpostfix, 64, 0444);
101 MODULE_PARM_DESC(fwpostfix, "Postfix for .fw files. Useful for debugging.");
103 # define modparam_fwpostfix ""
104 #endif /* CONFIG_BCM43XX_DEBUG*/
107 /* If you want to debug with just a single device, enable this,
108 * where the string is the pci device ID (as given by the kernel's
109 * pci_name function) of the device to be used.
111 //#define DEBUG_SINGLE_DEVICE_ONLY "0001:11:00.0"
113 /* If you want to enable printing of each MMIO access, enable this. */
114 //#define DEBUG_ENABLE_MMIO_PRINT
116 /* If you want to enable printing of MMIO access within
117 * ucode/pcm upload, initvals write, enable this.
119 //#define DEBUG_ENABLE_UCODE_MMIO_PRINT
121 /* If you want to enable printing of PCI Config Space access, enable this */
122 //#define DEBUG_ENABLE_PCILOG
125 /* Detailed list maintained at:
126 * http://openfacts.berlios.de/index-en.phtml?title=Bcm43xxDevices
128 static struct pci_device_id bcm43xx_pci_tbl[] = {
129 /* Broadcom 4303 802.11b */
130 { PCI_VENDOR_ID_BROADCOM, 0x4301, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
131 /* Broadcom 4307 802.11b */
132 { PCI_VENDOR_ID_BROADCOM, 0x4307, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
133 /* Broadcom 4311 802.11(a)/b/g */
134 { PCI_VENDOR_ID_BROADCOM, 0x4311, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
135 /* Broadcom 4312 802.11a/b/g */
136 { PCI_VENDOR_ID_BROADCOM, 0x4312, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
137 /* Broadcom 4318 802.11b/g */
138 { PCI_VENDOR_ID_BROADCOM, 0x4318, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
139 /* Broadcom 4319 802.11a/b/g */
140 { PCI_VENDOR_ID_BROADCOM, 0x4319, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
141 /* Broadcom 4306 802.11b/g */
142 { PCI_VENDOR_ID_BROADCOM, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
143 /* Broadcom 4306 802.11a */
144 // { PCI_VENDOR_ID_BROADCOM, 0x4321, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
145 /* Broadcom 4309 802.11a/b/g */
146 { PCI_VENDOR_ID_BROADCOM, 0x4324, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
147 /* Broadcom 43XG 802.11b/g */
148 { PCI_VENDOR_ID_BROADCOM, 0x4325, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
149 #ifdef CONFIG_BCM947XX
150 /* SB bus on BCM947xx */
151 { PCI_VENDOR_ID_BROADCOM, 0x0800, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
155 MODULE_DEVICE_TABLE(pci, bcm43xx_pci_tbl);
157 static void bcm43xx_ram_write(struct bcm43xx_private *bcm, u16 offset, u32 val)
161 status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
162 if (!(status & BCM43xx_SBF_XFER_REG_BYTESWAP))
165 bcm43xx_write32(bcm, BCM43xx_MMIO_RAM_CONTROL, offset);
167 bcm43xx_write32(bcm, BCM43xx_MMIO_RAM_DATA, val);
171 void bcm43xx_shm_control_word(struct bcm43xx_private *bcm,
172 u16 routing, u16 offset)
176 /* "offset" is the WORD offset. */
181 bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_CONTROL, control);
184 u32 bcm43xx_shm_read32(struct bcm43xx_private *bcm,
185 u16 routing, u16 offset)
189 if (routing == BCM43xx_SHM_SHARED) {
190 if (offset & 0x0003) {
191 /* Unaligned access */
192 bcm43xx_shm_control_word(bcm, routing, offset >> 2);
193 ret = bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED);
195 bcm43xx_shm_control_word(bcm, routing, (offset >> 2) + 1);
196 ret |= bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA);
202 bcm43xx_shm_control_word(bcm, routing, offset);
203 ret = bcm43xx_read32(bcm, BCM43xx_MMIO_SHM_DATA);
208 u16 bcm43xx_shm_read16(struct bcm43xx_private *bcm,
209 u16 routing, u16 offset)
213 if (routing == BCM43xx_SHM_SHARED) {
214 if (offset & 0x0003) {
215 /* Unaligned access */
216 bcm43xx_shm_control_word(bcm, routing, offset >> 2);
217 ret = bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED);
223 bcm43xx_shm_control_word(bcm, routing, offset);
224 ret = bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA);
229 void bcm43xx_shm_write32(struct bcm43xx_private *bcm,
230 u16 routing, u16 offset,
233 if (routing == BCM43xx_SHM_SHARED) {
234 if (offset & 0x0003) {
235 /* Unaligned access */
236 bcm43xx_shm_control_word(bcm, routing, offset >> 2);
238 bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED,
239 (value >> 16) & 0xffff);
241 bcm43xx_shm_control_word(bcm, routing, (offset >> 2) + 1);
243 bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA,
249 bcm43xx_shm_control_word(bcm, routing, offset);
251 bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA, value);
254 void bcm43xx_shm_write16(struct bcm43xx_private *bcm,
255 u16 routing, u16 offset,
258 if (routing == BCM43xx_SHM_SHARED) {
259 if (offset & 0x0003) {
260 /* Unaligned access */
261 bcm43xx_shm_control_word(bcm, routing, offset >> 2);
263 bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED,
269 bcm43xx_shm_control_word(bcm, routing, offset);
271 bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA, value);
274 void bcm43xx_tsf_read(struct bcm43xx_private *bcm, u64 *tsf)
276 /* We need to be careful. As we read the TSF from multiple
277 * registers, we should take care of register overflows.
278 * In theory, the whole tsf read process should be atomic.
279 * We try to be atomic here, by restaring the read process,
280 * if any of the high registers changed (overflew).
282 if (bcm->current_core->rev >= 3) {
283 u32 low, high, high2;
286 high = bcm43xx_read32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_HIGH);
287 low = bcm43xx_read32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_LOW);
288 high2 = bcm43xx_read32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_HIGH);
289 } while (unlikely(high != high2));
297 u16 test1, test2, test3;
300 v3 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_3);
301 v2 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_2);
302 v1 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_1);
303 v0 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_0);
305 test3 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_3);
306 test2 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_2);
307 test1 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_1);
308 } while (v3 != test3 || v2 != test2 || v1 != test1);
322 void bcm43xx_tsf_write(struct bcm43xx_private *bcm, u64 tsf)
326 status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
327 status |= BCM43xx_SBF_TIME_UPDATE;
328 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
331 /* Be careful with the in-progress timer.
332 * First zero out the low register, so we have a full
333 * register-overflow duration to complete the operation.
335 if (bcm->current_core->rev >= 3) {
336 u32 lo = (tsf & 0x00000000FFFFFFFFULL);
337 u32 hi = (tsf & 0xFFFFFFFF00000000ULL) >> 32;
339 bcm43xx_write32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_LOW, 0);
341 bcm43xx_write32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_HIGH, hi);
343 bcm43xx_write32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_LOW, lo);
345 u16 v0 = (tsf & 0x000000000000FFFFULL);
346 u16 v1 = (tsf & 0x00000000FFFF0000ULL) >> 16;
347 u16 v2 = (tsf & 0x0000FFFF00000000ULL) >> 32;
348 u16 v3 = (tsf & 0xFFFF000000000000ULL) >> 48;
350 bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_0, 0);
352 bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_3, v3);
354 bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_2, v2);
356 bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_1, v1);
358 bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_0, v0);
361 status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
362 status &= ~BCM43xx_SBF_TIME_UPDATE;
363 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
367 void bcm43xx_macfilter_set(struct bcm43xx_private *bcm,
374 bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_CONTROL, offset);
378 bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_DATA, data);
381 bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_DATA, data);
384 bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_DATA, data);
387 static void bcm43xx_macfilter_clear(struct bcm43xx_private *bcm,
390 const u8 zero_addr[ETH_ALEN] = { 0 };
392 bcm43xx_macfilter_set(bcm, offset, zero_addr);
395 static void bcm43xx_write_mac_bssid_templates(struct bcm43xx_private *bcm)
397 const u8 *mac = (const u8 *)(bcm->net_dev->dev_addr);
398 const u8 *bssid = (const u8 *)(bcm->ieee->bssid);
399 u8 mac_bssid[ETH_ALEN * 2];
402 memcpy(mac_bssid, mac, ETH_ALEN);
403 memcpy(mac_bssid + ETH_ALEN, bssid, ETH_ALEN);
405 /* Write our MAC address and BSSID to template ram */
406 for (i = 0; i < ARRAY_SIZE(mac_bssid); i += sizeof(u32))
407 bcm43xx_ram_write(bcm, 0x20 + i, *((u32 *)(mac_bssid + i)));
408 for (i = 0; i < ARRAY_SIZE(mac_bssid); i += sizeof(u32))
409 bcm43xx_ram_write(bcm, 0x78 + i, *((u32 *)(mac_bssid + i)));
410 for (i = 0; i < ARRAY_SIZE(mac_bssid); i += sizeof(u32))
411 bcm43xx_ram_write(bcm, 0x478 + i, *((u32 *)(mac_bssid + i)));
414 //FIXME: Well, we should probably call them from somewhere.
416 static void bcm43xx_set_slot_time(struct bcm43xx_private *bcm, u16 slot_time)
418 /* slot_time is in usec. */
419 if (bcm43xx_current_phy(bcm)->type != BCM43xx_PHYTYPE_G)
421 bcm43xx_write16(bcm, 0x684, 510 + slot_time);
422 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0010, slot_time);
425 static void bcm43xx_short_slot_timing_enable(struct bcm43xx_private *bcm)
427 bcm43xx_set_slot_time(bcm, 9);
430 static void bcm43xx_short_slot_timing_disable(struct bcm43xx_private *bcm)
432 bcm43xx_set_slot_time(bcm, 20);
436 /* FIXME: To get the MAC-filter working, we need to implement the
437 * following functions (and rename them :)
440 static void bcm43xx_disassociate(struct bcm43xx_private *bcm)
442 bcm43xx_mac_suspend(bcm);
443 bcm43xx_macfilter_clear(bcm, BCM43xx_MACFILTER_ASSOC);
445 bcm43xx_ram_write(bcm, 0x0026, 0x0000);
446 bcm43xx_ram_write(bcm, 0x0028, 0x0000);
447 bcm43xx_ram_write(bcm, 0x007E, 0x0000);
448 bcm43xx_ram_write(bcm, 0x0080, 0x0000);
449 bcm43xx_ram_write(bcm, 0x047E, 0x0000);
450 bcm43xx_ram_write(bcm, 0x0480, 0x0000);
452 if (bcm->current_core->rev < 3) {
453 bcm43xx_write16(bcm, 0x0610, 0x8000);
454 bcm43xx_write16(bcm, 0x060E, 0x0000);
456 bcm43xx_write32(bcm, 0x0188, 0x80000000);
458 bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0004, 0x000003ff);
460 if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_G &&
461 ieee80211_is_ofdm_rate(bcm->softmac->txrates.default_rate))
462 bcm43xx_short_slot_timing_enable(bcm);
464 bcm43xx_mac_enable(bcm);
467 static void bcm43xx_associate(struct bcm43xx_private *bcm,
470 memcpy(bcm->ieee->bssid, mac, ETH_ALEN);
472 bcm43xx_mac_suspend(bcm);
473 bcm43xx_macfilter_set(bcm, BCM43xx_MACFILTER_ASSOC, mac);
474 bcm43xx_write_mac_bssid_templates(bcm);
475 bcm43xx_mac_enable(bcm);
479 /* Enable a Generic IRQ. "mask" is the mask of which IRQs to enable.
480 * Returns the _previously_ enabled IRQ mask.
482 static inline u32 bcm43xx_interrupt_enable(struct bcm43xx_private *bcm, u32 mask)
486 old_mask = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK);
487 bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK, old_mask | mask);
492 /* Disable a Generic IRQ. "mask" is the mask of which IRQs to disable.
493 * Returns the _previously_ enabled IRQ mask.
495 static inline u32 bcm43xx_interrupt_disable(struct bcm43xx_private *bcm, u32 mask)
499 old_mask = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK);
500 bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK, old_mask & ~mask);
505 /* Synchronize IRQ top- and bottom-half.
506 * IRQs must be masked before calling this.
507 * This must not be called with the irq_lock held.
509 static void bcm43xx_synchronize_irq(struct bcm43xx_private *bcm)
511 synchronize_irq(bcm->irq);
512 tasklet_disable(&bcm->isr_tasklet);
515 /* Make sure we don't receive more data from the device. */
516 static int bcm43xx_disable_interrupts_sync(struct bcm43xx_private *bcm)
520 spin_lock_irqsave(&bcm->irq_lock, flags);
521 if (unlikely(bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED)) {
522 spin_unlock_irqrestore(&bcm->irq_lock, flags);
525 bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
526 bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK); /* flush */
527 spin_unlock_irqrestore(&bcm->irq_lock, flags);
528 bcm43xx_synchronize_irq(bcm);
533 static int bcm43xx_read_radioinfo(struct bcm43xx_private *bcm)
535 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
536 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
542 if (bcm->chip_id == 0x4317) {
543 if (bcm->chip_rev == 0x00)
544 radio_id = 0x3205017F;
545 else if (bcm->chip_rev == 0x01)
546 radio_id = 0x4205017F;
548 radio_id = 0x5205017F;
550 bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, BCM43xx_RADIOCTL_ID);
551 radio_id = bcm43xx_read16(bcm, BCM43xx_MMIO_RADIO_DATA_HIGH);
553 bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, BCM43xx_RADIOCTL_ID);
554 radio_id |= bcm43xx_read16(bcm, BCM43xx_MMIO_RADIO_DATA_LOW);
557 manufact = (radio_id & 0x00000FFF);
558 version = (radio_id & 0x0FFFF000) >> 12;
559 revision = (radio_id & 0xF0000000) >> 28;
561 dprintk(KERN_INFO PFX "Detected Radio: ID: %x (Manuf: %x Ver: %x Rev: %x)\n",
562 radio_id, manufact, version, revision);
565 case BCM43xx_PHYTYPE_A:
566 if ((version != 0x2060) || (revision != 1) || (manufact != 0x17f))
567 goto err_unsupported_radio;
569 case BCM43xx_PHYTYPE_B:
570 if ((version & 0xFFF0) != 0x2050)
571 goto err_unsupported_radio;
573 case BCM43xx_PHYTYPE_G:
574 if (version != 0x2050)
575 goto err_unsupported_radio;
579 radio->manufact = manufact;
580 radio->version = version;
581 radio->revision = revision;
583 if (phy->type == BCM43xx_PHYTYPE_A)
584 radio->txpower_desired = bcm->sprom.maxpower_aphy;
586 radio->txpower_desired = bcm->sprom.maxpower_bgphy;
590 err_unsupported_radio:
591 printk(KERN_ERR PFX "Unsupported Radio connected to the PHY!\n");
595 static const char * bcm43xx_locale_iso(u8 locale)
597 /* ISO 3166-1 country codes.
598 * Note that there aren't ISO 3166-1 codes for
599 * all or locales. (Not all locales are countries)
602 case BCM43xx_LOCALE_WORLD:
603 case BCM43xx_LOCALE_ALL:
605 case BCM43xx_LOCALE_THAILAND:
607 case BCM43xx_LOCALE_ISRAEL:
609 case BCM43xx_LOCALE_JORDAN:
611 case BCM43xx_LOCALE_CHINA:
613 case BCM43xx_LOCALE_JAPAN:
614 case BCM43xx_LOCALE_JAPAN_HIGH:
616 case BCM43xx_LOCALE_USA_CANADA_ANZ:
617 case BCM43xx_LOCALE_USA_LOW:
619 case BCM43xx_LOCALE_EUROPE:
621 case BCM43xx_LOCALE_NONE:
628 static const char * bcm43xx_locale_string(u8 locale)
631 case BCM43xx_LOCALE_WORLD:
633 case BCM43xx_LOCALE_THAILAND:
635 case BCM43xx_LOCALE_ISRAEL:
637 case BCM43xx_LOCALE_JORDAN:
639 case BCM43xx_LOCALE_CHINA:
641 case BCM43xx_LOCALE_JAPAN:
643 case BCM43xx_LOCALE_USA_CANADA_ANZ:
644 return "USA/Canada/ANZ";
645 case BCM43xx_LOCALE_EUROPE:
647 case BCM43xx_LOCALE_USA_LOW:
649 case BCM43xx_LOCALE_JAPAN_HIGH:
651 case BCM43xx_LOCALE_ALL:
653 case BCM43xx_LOCALE_NONE:
660 static inline u8 bcm43xx_crc8(u8 crc, u8 data)
662 static const u8 t[] = {
663 0x00, 0xF7, 0xB9, 0x4E, 0x25, 0xD2, 0x9C, 0x6B,
664 0x4A, 0xBD, 0xF3, 0x04, 0x6F, 0x98, 0xD6, 0x21,
665 0x94, 0x63, 0x2D, 0xDA, 0xB1, 0x46, 0x08, 0xFF,
666 0xDE, 0x29, 0x67, 0x90, 0xFB, 0x0C, 0x42, 0xB5,
667 0x7F, 0x88, 0xC6, 0x31, 0x5A, 0xAD, 0xE3, 0x14,
668 0x35, 0xC2, 0x8C, 0x7B, 0x10, 0xE7, 0xA9, 0x5E,
669 0xEB, 0x1C, 0x52, 0xA5, 0xCE, 0x39, 0x77, 0x80,
670 0xA1, 0x56, 0x18, 0xEF, 0x84, 0x73, 0x3D, 0xCA,
671 0xFE, 0x09, 0x47, 0xB0, 0xDB, 0x2C, 0x62, 0x95,
672 0xB4, 0x43, 0x0D, 0xFA, 0x91, 0x66, 0x28, 0xDF,
673 0x6A, 0x9D, 0xD3, 0x24, 0x4F, 0xB8, 0xF6, 0x01,
674 0x20, 0xD7, 0x99, 0x6E, 0x05, 0xF2, 0xBC, 0x4B,
675 0x81, 0x76, 0x38, 0xCF, 0xA4, 0x53, 0x1D, 0xEA,
676 0xCB, 0x3C, 0x72, 0x85, 0xEE, 0x19, 0x57, 0xA0,
677 0x15, 0xE2, 0xAC, 0x5B, 0x30, 0xC7, 0x89, 0x7E,
678 0x5F, 0xA8, 0xE6, 0x11, 0x7A, 0x8D, 0xC3, 0x34,
679 0xAB, 0x5C, 0x12, 0xE5, 0x8E, 0x79, 0x37, 0xC0,
680 0xE1, 0x16, 0x58, 0xAF, 0xC4, 0x33, 0x7D, 0x8A,
681 0x3F, 0xC8, 0x86, 0x71, 0x1A, 0xED, 0xA3, 0x54,
682 0x75, 0x82, 0xCC, 0x3B, 0x50, 0xA7, 0xE9, 0x1E,
683 0xD4, 0x23, 0x6D, 0x9A, 0xF1, 0x06, 0x48, 0xBF,
684 0x9E, 0x69, 0x27, 0xD0, 0xBB, 0x4C, 0x02, 0xF5,
685 0x40, 0xB7, 0xF9, 0x0E, 0x65, 0x92, 0xDC, 0x2B,
686 0x0A, 0xFD, 0xB3, 0x44, 0x2F, 0xD8, 0x96, 0x61,
687 0x55, 0xA2, 0xEC, 0x1B, 0x70, 0x87, 0xC9, 0x3E,
688 0x1F, 0xE8, 0xA6, 0x51, 0x3A, 0xCD, 0x83, 0x74,
689 0xC1, 0x36, 0x78, 0x8F, 0xE4, 0x13, 0x5D, 0xAA,
690 0x8B, 0x7C, 0x32, 0xC5, 0xAE, 0x59, 0x17, 0xE0,
691 0x2A, 0xDD, 0x93, 0x64, 0x0F, 0xF8, 0xB6, 0x41,
692 0x60, 0x97, 0xD9, 0x2E, 0x45, 0xB2, 0xFC, 0x0B,
693 0xBE, 0x49, 0x07, 0xF0, 0x9B, 0x6C, 0x22, 0xD5,
694 0xF4, 0x03, 0x4D, 0xBA, 0xD1, 0x26, 0x68, 0x9F,
696 return t[crc ^ data];
699 static u8 bcm43xx_sprom_crc(const u16 *sprom)
704 for (word = 0; word < BCM43xx_SPROM_SIZE - 1; word++) {
705 crc = bcm43xx_crc8(crc, sprom[word] & 0x00FF);
706 crc = bcm43xx_crc8(crc, (sprom[word] & 0xFF00) >> 8);
708 crc = bcm43xx_crc8(crc, sprom[BCM43xx_SPROM_VERSION] & 0x00FF);
714 int bcm43xx_sprom_read(struct bcm43xx_private *bcm, u16 *sprom)
717 u8 crc, expected_crc;
719 for (i = 0; i < BCM43xx_SPROM_SIZE; i++)
720 sprom[i] = bcm43xx_read16(bcm, BCM43xx_SPROM_BASE + (i * 2));
722 crc = bcm43xx_sprom_crc(sprom);
723 expected_crc = (sprom[BCM43xx_SPROM_VERSION] & 0xFF00) >> 8;
724 if (crc != expected_crc) {
725 printk(KERN_WARNING PFX "WARNING: Invalid SPROM checksum "
726 "(0x%02X, expected: 0x%02X)\n",
734 int bcm43xx_sprom_write(struct bcm43xx_private *bcm, const u16 *sprom)
737 u8 crc, expected_crc;
740 /* CRC-8 validation of the input data. */
741 crc = bcm43xx_sprom_crc(sprom);
742 expected_crc = (sprom[BCM43xx_SPROM_VERSION] & 0xFF00) >> 8;
743 if (crc != expected_crc) {
744 printk(KERN_ERR PFX "SPROM input data: Invalid CRC\n");
748 printk(KERN_INFO PFX "Writing SPROM. Do NOT turn off the power! Please stand by...\n");
749 err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCICFG_SPROMCTL, &spromctl);
752 spromctl |= 0x10; /* SPROM WRITE enable. */
753 err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_SPROMCTL, spromctl);
756 /* We must burn lots of CPU cycles here, but that does not
757 * really matter as one does not write the SPROM every other minute...
759 printk(KERN_INFO PFX "[ 0%%");
761 for (i = 0; i < BCM43xx_SPROM_SIZE; i++) {
770 bcm43xx_write16(bcm, BCM43xx_SPROM_BASE + (i * 2), sprom[i]);
774 spromctl &= ~0x10; /* SPROM WRITE enable. */
775 err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_SPROMCTL, spromctl);
780 printk(KERN_INFO PFX "SPROM written.\n");
781 bcm43xx_controller_restart(bcm, "SPROM update");
785 printk(KERN_ERR PFX "Could not access SPROM control register.\n");
789 static int bcm43xx_sprom_extract(struct bcm43xx_private *bcm)
793 #ifdef CONFIG_BCM947XX
797 sprom = kzalloc(BCM43xx_SPROM_SIZE * sizeof(u16),
800 printk(KERN_ERR PFX "sprom_extract OOM\n");
803 #ifdef CONFIG_BCM947XX
804 sprom[BCM43xx_SPROM_BOARDFLAGS2] = atoi(nvram_get("boardflags2"));
805 sprom[BCM43xx_SPROM_BOARDFLAGS] = atoi(nvram_get("boardflags"));
807 if ((c = nvram_get("il0macaddr")) != NULL)
808 e_aton(c, (char *) &(sprom[BCM43xx_SPROM_IL0MACADDR]));
810 if ((c = nvram_get("et1macaddr")) != NULL)
811 e_aton(c, (char *) &(sprom[BCM43xx_SPROM_ET1MACADDR]));
813 sprom[BCM43xx_SPROM_PA0B0] = atoi(nvram_get("pa0b0"));
814 sprom[BCM43xx_SPROM_PA0B1] = atoi(nvram_get("pa0b1"));
815 sprom[BCM43xx_SPROM_PA0B2] = atoi(nvram_get("pa0b2"));
817 sprom[BCM43xx_SPROM_PA1B0] = atoi(nvram_get("pa1b0"));
818 sprom[BCM43xx_SPROM_PA1B1] = atoi(nvram_get("pa1b1"));
819 sprom[BCM43xx_SPROM_PA1B2] = atoi(nvram_get("pa1b2"));
821 sprom[BCM43xx_SPROM_BOARDREV] = atoi(nvram_get("boardrev"));
823 bcm43xx_sprom_read(bcm, sprom);
827 value = sprom[BCM43xx_SPROM_BOARDFLAGS2];
828 bcm->sprom.boardflags2 = value;
831 value = sprom[BCM43xx_SPROM_IL0MACADDR + 0];
832 *(((u16 *)bcm->sprom.il0macaddr) + 0) = cpu_to_be16(value);
833 value = sprom[BCM43xx_SPROM_IL0MACADDR + 1];
834 *(((u16 *)bcm->sprom.il0macaddr) + 1) = cpu_to_be16(value);
835 value = sprom[BCM43xx_SPROM_IL0MACADDR + 2];
836 *(((u16 *)bcm->sprom.il0macaddr) + 2) = cpu_to_be16(value);
839 value = sprom[BCM43xx_SPROM_ET0MACADDR + 0];
840 *(((u16 *)bcm->sprom.et0macaddr) + 0) = cpu_to_be16(value);
841 value = sprom[BCM43xx_SPROM_ET0MACADDR + 1];
842 *(((u16 *)bcm->sprom.et0macaddr) + 1) = cpu_to_be16(value);
843 value = sprom[BCM43xx_SPROM_ET0MACADDR + 2];
844 *(((u16 *)bcm->sprom.et0macaddr) + 2) = cpu_to_be16(value);
847 value = sprom[BCM43xx_SPROM_ET1MACADDR + 0];
848 *(((u16 *)bcm->sprom.et1macaddr) + 0) = cpu_to_be16(value);
849 value = sprom[BCM43xx_SPROM_ET1MACADDR + 1];
850 *(((u16 *)bcm->sprom.et1macaddr) + 1) = cpu_to_be16(value);
851 value = sprom[BCM43xx_SPROM_ET1MACADDR + 2];
852 *(((u16 *)bcm->sprom.et1macaddr) + 2) = cpu_to_be16(value);
854 /* ethernet phy settings */
855 value = sprom[BCM43xx_SPROM_ETHPHY];
856 bcm->sprom.et0phyaddr = (value & 0x001F);
857 bcm->sprom.et1phyaddr = (value & 0x03E0) >> 5;
858 bcm->sprom.et0mdcport = (value & (1 << 14)) >> 14;
859 bcm->sprom.et1mdcport = (value & (1 << 15)) >> 15;
861 /* boardrev, antennas, locale */
862 value = sprom[BCM43xx_SPROM_BOARDREV];
863 bcm->sprom.boardrev = (value & 0x00FF);
864 bcm->sprom.locale = (value & 0x0F00) >> 8;
865 bcm->sprom.antennas_aphy = (value & 0x3000) >> 12;
866 bcm->sprom.antennas_bgphy = (value & 0xC000) >> 14;
867 if (modparam_locale != -1) {
868 if (modparam_locale >= 0 && modparam_locale <= 11) {
869 bcm->sprom.locale = modparam_locale;
870 printk(KERN_WARNING PFX "Operating with modified "
871 "LocaleCode %u (%s)\n",
873 bcm43xx_locale_string(bcm->sprom.locale));
875 printk(KERN_WARNING PFX "Module parameter \"locale\" "
876 "invalid value. (0 - 11)\n");
881 value = sprom[BCM43xx_SPROM_PA0B0];
882 bcm->sprom.pa0b0 = value;
883 value = sprom[BCM43xx_SPROM_PA0B1];
884 bcm->sprom.pa0b1 = value;
885 value = sprom[BCM43xx_SPROM_PA0B2];
886 bcm->sprom.pa0b2 = value;
889 value = sprom[BCM43xx_SPROM_WL0GPIO0];
892 bcm->sprom.wl0gpio0 = value & 0x00FF;
893 bcm->sprom.wl0gpio1 = (value & 0xFF00) >> 8;
894 value = sprom[BCM43xx_SPROM_WL0GPIO2];
897 bcm->sprom.wl0gpio2 = value & 0x00FF;
898 bcm->sprom.wl0gpio3 = (value & 0xFF00) >> 8;
901 value = sprom[BCM43xx_SPROM_MAXPWR];
902 bcm->sprom.maxpower_aphy = (value & 0xFF00) >> 8;
903 bcm->sprom.maxpower_bgphy = value & 0x00FF;
906 value = sprom[BCM43xx_SPROM_PA1B0];
907 bcm->sprom.pa1b0 = value;
908 value = sprom[BCM43xx_SPROM_PA1B1];
909 bcm->sprom.pa1b1 = value;
910 value = sprom[BCM43xx_SPROM_PA1B2];
911 bcm->sprom.pa1b2 = value;
913 /* idle tssi target */
914 value = sprom[BCM43xx_SPROM_IDL_TSSI_TGT];
915 bcm->sprom.idle_tssi_tgt_aphy = value & 0x00FF;
916 bcm->sprom.idle_tssi_tgt_bgphy = (value & 0xFF00) >> 8;
919 value = sprom[BCM43xx_SPROM_BOARDFLAGS];
922 bcm->sprom.boardflags = value;
923 /* boardflags workarounds */
924 if (bcm->board_vendor == PCI_VENDOR_ID_DELL &&
925 bcm->chip_id == 0x4301 &&
926 bcm->board_revision == 0x74)
927 bcm->sprom.boardflags |= BCM43xx_BFL_BTCOEXIST;
928 if (bcm->board_vendor == PCI_VENDOR_ID_APPLE &&
929 bcm->board_type == 0x4E &&
930 bcm->board_revision > 0x40)
931 bcm->sprom.boardflags |= BCM43xx_BFL_PACTRL;
934 value = sprom[BCM43xx_SPROM_ANTENNA_GAIN];
935 if (value == 0x0000 || value == 0xFFFF)
937 /* convert values to Q5.2 */
938 bcm->sprom.antennagain_aphy = ((value & 0xFF00) >> 8) * 4;
939 bcm->sprom.antennagain_bgphy = (value & 0x00FF) * 4;
946 static int bcm43xx_geo_init(struct bcm43xx_private *bcm)
948 struct ieee80211_geo *geo;
949 struct ieee80211_channel *chan;
950 int have_a = 0, have_bg = 0;
953 struct bcm43xx_phyinfo *phy;
954 const char *iso_country;
956 geo = kzalloc(sizeof(*geo), GFP_KERNEL);
960 for (i = 0; i < bcm->nr_80211_available; i++) {
961 phy = &(bcm->core_80211_ext[i].phy);
963 case BCM43xx_PHYTYPE_B:
964 case BCM43xx_PHYTYPE_G:
967 case BCM43xx_PHYTYPE_A:
974 iso_country = bcm43xx_locale_iso(bcm->sprom.locale);
977 for (i = 0, channel = IEEE80211_52GHZ_MIN_CHANNEL;
978 channel <= IEEE80211_52GHZ_MAX_CHANNEL; channel++) {
980 chan->freq = bcm43xx_channel_to_freq_a(channel);
981 chan->channel = channel;
986 for (i = 0, channel = IEEE80211_24GHZ_MIN_CHANNEL;
987 channel <= IEEE80211_24GHZ_MAX_CHANNEL; channel++) {
988 chan = &geo->bg[i++];
989 chan->freq = bcm43xx_channel_to_freq_bg(channel);
990 chan->channel = channel;
992 geo->bg_channels = i;
994 memcpy(geo->name, iso_country, 2);
995 if (0 /*TODO: Outdoor use only */)
997 else if (0 /*TODO: Indoor use only */)
1001 geo->name[3] = '\0';
1003 ieee80211_set_geo(bcm->ieee, geo);
1009 /* DummyTransmission function, as documented on
1010 * http://bcm-specs.sipsolutions.net/DummyTransmission
1012 void bcm43xx_dummy_transmission(struct bcm43xx_private *bcm)
1014 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1015 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1016 unsigned int i, max_loop;
1026 switch (phy->type) {
1027 case BCM43xx_PHYTYPE_A:
1029 buffer[0] = 0xCC010200;
1031 case BCM43xx_PHYTYPE_B:
1032 case BCM43xx_PHYTYPE_G:
1034 buffer[0] = 0x6E840B00;
1041 for (i = 0; i < 5; i++)
1042 bcm43xx_ram_write(bcm, i * 4, buffer[i]);
1044 bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* dummy read */
1046 bcm43xx_write16(bcm, 0x0568, 0x0000);
1047 bcm43xx_write16(bcm, 0x07C0, 0x0000);
1048 bcm43xx_write16(bcm, 0x050C, ((phy->type == BCM43xx_PHYTYPE_A) ? 1 : 0));
1049 bcm43xx_write16(bcm, 0x0508, 0x0000);
1050 bcm43xx_write16(bcm, 0x050A, 0x0000);
1051 bcm43xx_write16(bcm, 0x054C, 0x0000);
1052 bcm43xx_write16(bcm, 0x056A, 0x0014);
1053 bcm43xx_write16(bcm, 0x0568, 0x0826);
1054 bcm43xx_write16(bcm, 0x0500, 0x0000);
1055 bcm43xx_write16(bcm, 0x0502, 0x0030);
1057 if (radio->version == 0x2050 && radio->revision <= 0x5)
1058 bcm43xx_radio_write16(bcm, 0x0051, 0x0017);
1059 for (i = 0x00; i < max_loop; i++) {
1060 value = bcm43xx_read16(bcm, 0x050E);
1065 for (i = 0x00; i < 0x0A; i++) {
1066 value = bcm43xx_read16(bcm, 0x050E);
1071 for (i = 0x00; i < 0x0A; i++) {
1072 value = bcm43xx_read16(bcm, 0x0690);
1073 if (!(value & 0x0100))
1077 if (radio->version == 0x2050 && radio->revision <= 0x5)
1078 bcm43xx_radio_write16(bcm, 0x0051, 0x0037);
1081 static void key_write(struct bcm43xx_private *bcm,
1082 u8 index, u8 algorithm, const u16 *key)
1084 unsigned int i, basic_wep = 0;
1088 /* Write associated key information */
1089 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x100 + (index * 2),
1090 ((index << 4) | (algorithm & 0x0F)));
1092 /* The first 4 WEP keys need extra love */
1093 if (((algorithm == BCM43xx_SEC_ALGO_WEP) ||
1094 (algorithm == BCM43xx_SEC_ALGO_WEP104)) && (index < 4))
1097 /* Write key payload, 8 little endian words */
1098 offset = bcm->security_offset + (index * BCM43xx_SEC_KEYSIZE);
1099 for (i = 0; i < (BCM43xx_SEC_KEYSIZE / sizeof(u16)); i++) {
1100 value = cpu_to_le16(key[i]);
1101 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
1102 offset + (i * 2), value);
1107 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
1108 offset + (i * 2) + 4 * BCM43xx_SEC_KEYSIZE,
1113 static void keymac_write(struct bcm43xx_private *bcm,
1114 u8 index, const u32 *addr)
1116 /* for keys 0-3 there is no associated mac address */
1121 if (bcm->current_core->rev >= 5) {
1122 bcm43xx_shm_write32(bcm,
1125 cpu_to_be32(*addr));
1126 bcm43xx_shm_write16(bcm,
1129 cpu_to_be16(*((u16 *)(addr + 1))));
1132 TODO(); /* Put them in the macaddress filter */
1135 /* Put them BCM43xx_SHM_SHARED, stating index 0x0120.
1136 Keep in mind to update the count of keymacs in 0x003E as well! */
1141 static int bcm43xx_key_write(struct bcm43xx_private *bcm,
1142 u8 index, u8 algorithm,
1143 const u8 *_key, int key_len,
1146 u8 key[BCM43xx_SEC_KEYSIZE] = { 0 };
1148 if (index >= ARRAY_SIZE(bcm->key))
1150 if (key_len > ARRAY_SIZE(key))
1152 if (algorithm < 1 || algorithm > 5)
1155 memcpy(key, _key, key_len);
1156 key_write(bcm, index, algorithm, (const u16 *)key);
1157 keymac_write(bcm, index, (const u32 *)mac_addr);
1159 bcm->key[index].algorithm = algorithm;
1164 static void bcm43xx_clear_keys(struct bcm43xx_private *bcm)
1166 static const u32 zero_mac[2] = { 0 };
1167 unsigned int i,j, nr_keys = 54;
1170 if (bcm->current_core->rev < 5)
1172 assert(nr_keys <= ARRAY_SIZE(bcm->key));
1174 for (i = 0; i < nr_keys; i++) {
1175 bcm->key[i].enabled = 0;
1176 /* returns for i < 4 immediately */
1177 keymac_write(bcm, i, zero_mac);
1178 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
1179 0x100 + (i * 2), 0x0000);
1180 for (j = 0; j < 8; j++) {
1181 offset = bcm->security_offset + (j * 4) + (i * BCM43xx_SEC_KEYSIZE);
1182 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
1186 dprintk(KERN_INFO PFX "Keys cleared\n");
1189 /* Lowlevel core-switch function. This is only to be used in
1190 * bcm43xx_switch_core() and bcm43xx_probe_cores()
1192 static int _switch_core(struct bcm43xx_private *bcm, int core)
1200 err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_ACTIVE_CORE,
1201 (core * 0x1000) + 0x18000000);
1204 err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCICFG_ACTIVE_CORE,
1208 current_core = (current_core - 0x18000000) / 0x1000;
1209 if (current_core == core)
1212 if (unlikely(attempts++ > BCM43xx_SWITCH_CORE_MAX_RETRIES))
1216 #ifdef CONFIG_BCM947XX
1217 if (bcm->pci_dev->bus->number == 0)
1218 bcm->current_core_offset = 0x1000 * core;
1220 bcm->current_core_offset = 0;
1225 printk(KERN_ERR PFX "Failed to switch to core %d\n", core);
1229 int bcm43xx_switch_core(struct bcm43xx_private *bcm, struct bcm43xx_coreinfo *new_core)
1233 if (unlikely(!new_core))
1235 if (!new_core->available)
1237 if (bcm->current_core == new_core)
1239 err = _switch_core(bcm, new_core->index);
1243 bcm->current_core = new_core;
1248 static int bcm43xx_core_enabled(struct bcm43xx_private *bcm)
1252 value = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
1253 value &= BCM43xx_SBTMSTATELOW_CLOCK | BCM43xx_SBTMSTATELOW_RESET
1254 | BCM43xx_SBTMSTATELOW_REJECT;
1256 return (value == BCM43xx_SBTMSTATELOW_CLOCK);
1259 /* disable current core */
1260 static int bcm43xx_core_disable(struct bcm43xx_private *bcm, u32 core_flags)
1266 /* fetch sbtmstatelow from core information registers */
1267 sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
1269 /* core is already in reset */
1270 if (sbtmstatelow & BCM43xx_SBTMSTATELOW_RESET)
1273 if (sbtmstatelow & BCM43xx_SBTMSTATELOW_CLOCK) {
1274 sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK |
1275 BCM43xx_SBTMSTATELOW_REJECT;
1276 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
1278 for (i = 0; i < 1000; i++) {
1279 sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
1280 if (sbtmstatelow & BCM43xx_SBTMSTATELOW_REJECT) {
1287 printk(KERN_ERR PFX "Error: core_disable() REJECT timeout!\n");
1291 for (i = 0; i < 1000; i++) {
1292 sbtmstatehigh = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
1293 if (!(sbtmstatehigh & BCM43xx_SBTMSTATEHIGH_BUSY)) {
1300 printk(KERN_ERR PFX "Error: core_disable() BUSY timeout!\n");
1304 sbtmstatelow = BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK |
1305 BCM43xx_SBTMSTATELOW_REJECT |
1306 BCM43xx_SBTMSTATELOW_RESET |
1307 BCM43xx_SBTMSTATELOW_CLOCK |
1309 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
1313 sbtmstatelow = BCM43xx_SBTMSTATELOW_RESET |
1314 BCM43xx_SBTMSTATELOW_REJECT |
1316 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
1319 bcm->current_core->enabled = 0;
1324 /* enable (reset) current core */
1325 static int bcm43xx_core_enable(struct bcm43xx_private *bcm, u32 core_flags)
1332 err = bcm43xx_core_disable(bcm, core_flags);
1336 sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK |
1337 BCM43xx_SBTMSTATELOW_RESET |
1338 BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK |
1340 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
1343 sbtmstatehigh = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
1344 if (sbtmstatehigh & BCM43xx_SBTMSTATEHIGH_SERROR) {
1345 sbtmstatehigh = 0x00000000;
1346 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATEHIGH, sbtmstatehigh);
1349 sbimstate = bcm43xx_read32(bcm, BCM43xx_CIR_SBIMSTATE);
1350 if (sbimstate & (BCM43xx_SBIMSTATE_IB_ERROR | BCM43xx_SBIMSTATE_TIMEOUT)) {
1351 sbimstate &= ~(BCM43xx_SBIMSTATE_IB_ERROR | BCM43xx_SBIMSTATE_TIMEOUT);
1352 bcm43xx_write32(bcm, BCM43xx_CIR_SBIMSTATE, sbimstate);
1355 sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK |
1356 BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK |
1358 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
1361 sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK | core_flags;
1362 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
1365 bcm->current_core->enabled = 1;
1371 /* http://bcm-specs.sipsolutions.net/80211CoreReset */
1372 void bcm43xx_wireless_core_reset(struct bcm43xx_private *bcm, int connect_phy)
1374 u32 flags = 0x00040000;
1376 if ((bcm43xx_core_enabled(bcm)) &&
1377 !bcm43xx_using_pio(bcm)) {
1378 //FIXME: Do we _really_ want #ifndef CONFIG_BCM947XX here?
1380 #ifndef CONFIG_BCM947XX
1381 /* reset all used DMA controllers. */
1382 bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA1_BASE);
1383 bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA2_BASE);
1384 bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA3_BASE);
1385 bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA4_BASE);
1386 bcm43xx_dmacontroller_rx_reset(bcm, BCM43xx_MMIO_DMA1_BASE);
1387 if (bcm->current_core->rev < 5)
1388 bcm43xx_dmacontroller_rx_reset(bcm, BCM43xx_MMIO_DMA4_BASE);
1392 if (bcm43xx_status(bcm) == BCM43xx_STAT_SHUTTINGDOWN) {
1393 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
1394 bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
1395 & ~(BCM43xx_SBF_MAC_ENABLED | 0x00000002));
1398 flags |= 0x20000000;
1399 bcm43xx_phy_connect(bcm, connect_phy);
1400 bcm43xx_core_enable(bcm, flags);
1401 bcm43xx_write16(bcm, 0x03E6, 0x0000);
1402 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
1403 bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
1408 static void bcm43xx_wireless_core_disable(struct bcm43xx_private *bcm)
1410 bcm43xx_radio_turn_off(bcm);
1411 bcm43xx_write16(bcm, 0x03E6, 0x00F4);
1412 bcm43xx_core_disable(bcm, 0);
1415 /* Mark the current 80211 core inactive. */
1416 static void bcm43xx_wireless_core_mark_inactive(struct bcm43xx_private *bcm)
1420 bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
1421 bcm43xx_radio_turn_off(bcm);
1422 sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
1423 sbtmstatelow &= 0xDFF5FFFF;
1424 sbtmstatelow |= 0x000A0000;
1425 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
1427 sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
1428 sbtmstatelow &= 0xFFF5FFFF;
1429 sbtmstatelow |= 0x00080000;
1430 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
1434 static void handle_irq_transmit_status(struct bcm43xx_private *bcm)
1438 struct bcm43xx_xmitstatus stat;
1441 v0 = bcm43xx_read32(bcm, BCM43xx_MMIO_XMITSTAT_0);
1444 v1 = bcm43xx_read32(bcm, BCM43xx_MMIO_XMITSTAT_1);
1446 stat.cookie = (v0 >> 16) & 0x0000FFFF;
1447 tmp = (u16)((v0 & 0xFFF0) | ((v0 & 0xF) >> 1));
1448 stat.flags = tmp & 0xFF;
1449 stat.cnt1 = (tmp & 0x0F00) >> 8;
1450 stat.cnt2 = (tmp & 0xF000) >> 12;
1451 stat.seq = (u16)(v1 & 0xFFFF);
1452 stat.unknown = (u16)((v1 >> 16) & 0xFF);
1454 bcm43xx_debugfs_log_txstat(bcm, &stat);
1456 if (stat.flags & BCM43xx_TXSTAT_FLAG_IGNORE)
1458 if (!(stat.flags & BCM43xx_TXSTAT_FLAG_ACK)) {
1459 //TODO: packet was not acked (was lost)
1461 //TODO: There are more (unknown) flags to test. see bcm43xx_main.h
1463 if (bcm43xx_using_pio(bcm))
1464 bcm43xx_pio_handle_xmitstatus(bcm, &stat);
1466 bcm43xx_dma_handle_xmitstatus(bcm, &stat);
1470 static void drain_txstatus_queue(struct bcm43xx_private *bcm)
1474 if (bcm->current_core->rev < 5)
1476 /* Read all entries from the microcode TXstatus FIFO
1477 * and throw them away.
1480 dummy = bcm43xx_read32(bcm, BCM43xx_MMIO_XMITSTAT_0);
1483 dummy = bcm43xx_read32(bcm, BCM43xx_MMIO_XMITSTAT_1);
1487 static void bcm43xx_generate_noise_sample(struct bcm43xx_private *bcm)
1489 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x408, 0x7F7F);
1490 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x40A, 0x7F7F);
1491 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD,
1492 bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD) | (1 << 4));
1493 assert(bcm->noisecalc.core_at_start == bcm->current_core);
1494 assert(bcm->noisecalc.channel_at_start == bcm43xx_current_radio(bcm)->channel);
1497 static void bcm43xx_calculate_link_quality(struct bcm43xx_private *bcm)
1499 /* Top half of Link Quality calculation. */
1501 if (bcm->noisecalc.calculation_running)
1503 bcm->noisecalc.core_at_start = bcm->current_core;
1504 bcm->noisecalc.channel_at_start = bcm43xx_current_radio(bcm)->channel;
1505 bcm->noisecalc.calculation_running = 1;
1506 bcm->noisecalc.nr_samples = 0;
1508 bcm43xx_generate_noise_sample(bcm);
1511 static void handle_irq_noise(struct bcm43xx_private *bcm)
1513 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1519 /* Bottom half of Link Quality calculation. */
1521 assert(bcm->noisecalc.calculation_running);
1522 if (bcm->noisecalc.core_at_start != bcm->current_core ||
1523 bcm->noisecalc.channel_at_start != radio->channel)
1524 goto drop_calculation;
1525 tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x408);
1526 noise[0] = (tmp & 0x00FF);
1527 noise[1] = (tmp & 0xFF00) >> 8;
1528 tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x40A);
1529 noise[2] = (tmp & 0x00FF);
1530 noise[3] = (tmp & 0xFF00) >> 8;
1531 if (noise[0] == 0x7F || noise[1] == 0x7F ||
1532 noise[2] == 0x7F || noise[3] == 0x7F)
1535 /* Get the noise samples. */
1536 assert(bcm->noisecalc.nr_samples < 8);
1537 i = bcm->noisecalc.nr_samples;
1538 noise[0] = limit_value(noise[0], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
1539 noise[1] = limit_value(noise[1], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
1540 noise[2] = limit_value(noise[2], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
1541 noise[3] = limit_value(noise[3], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
1542 bcm->noisecalc.samples[i][0] = radio->nrssi_lt[noise[0]];
1543 bcm->noisecalc.samples[i][1] = radio->nrssi_lt[noise[1]];
1544 bcm->noisecalc.samples[i][2] = radio->nrssi_lt[noise[2]];
1545 bcm->noisecalc.samples[i][3] = radio->nrssi_lt[noise[3]];
1546 bcm->noisecalc.nr_samples++;
1547 if (bcm->noisecalc.nr_samples == 8) {
1548 /* Calculate the Link Quality by the noise samples. */
1550 for (i = 0; i < 8; i++) {
1551 for (j = 0; j < 4; j++)
1552 average += bcm->noisecalc.samples[i][j];
1559 tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x40C);
1560 tmp = (tmp / 128) & 0x1F;
1570 bcm->stats.noise = average;
1572 bcm->noisecalc.calculation_running = 0;
1576 bcm43xx_generate_noise_sample(bcm);
1579 static void handle_irq_ps(struct bcm43xx_private *bcm)
1581 if (bcm->ieee->iw_mode == IW_MODE_MASTER) {
1584 if (1/*FIXME: the last PSpoll frame was sent successfully */)
1585 bcm43xx_power_saving_ctl_bits(bcm, -1, -1);
1587 if (bcm->ieee->iw_mode == IW_MODE_ADHOC)
1588 bcm->reg124_set_0x4 = 1;
1589 //FIXME else set to false?
1592 static void handle_irq_reg124(struct bcm43xx_private *bcm)
1594 if (!bcm->reg124_set_0x4)
1596 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD,
1597 bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD)
1599 //FIXME: reset reg124_set_0x4 to false?
1602 static void handle_irq_pmq(struct bcm43xx_private *bcm)
1609 tmp = bcm43xx_read32(bcm, BCM43xx_MMIO_PS_STATUS);
1610 if (!(tmp & 0x00000008))
1613 /* 16bit write is odd, but correct. */
1614 bcm43xx_write16(bcm, BCM43xx_MMIO_PS_STATUS, 0x0002);
1617 static void bcm43xx_generate_beacon_template(struct bcm43xx_private *bcm,
1618 u16 ram_offset, u16 shm_size_offset)
1624 //FIXME: assumption: The chip sets the timestamp
1626 bcm43xx_ram_write(bcm, ram_offset++, value);
1627 bcm43xx_ram_write(bcm, ram_offset++, value);
1630 /* Beacon Interval / Capability Information */
1631 value = 0x0000;//FIXME: Which interval?
1632 value |= (1 << 0) << 16; /* ESS */
1633 value |= (1 << 2) << 16; /* CF Pollable */ //FIXME?
1634 value |= (1 << 3) << 16; /* CF Poll Request */ //FIXME?
1635 if (!bcm->ieee->open_wep)
1636 value |= (1 << 4) << 16; /* Privacy */
1637 bcm43xx_ram_write(bcm, ram_offset++, value);
1643 /* FH Parameter Set */
1646 /* DS Parameter Set */
1649 /* CF Parameter Set */
1655 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, shm_size_offset, size);
1658 static void handle_irq_beacon(struct bcm43xx_private *bcm)
1662 bcm->irq_savedstate &= ~BCM43xx_IRQ_BEACON;
1663 status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD);
1665 if ((status & 0x1) && (status & 0x2)) {
1666 /* ACK beacon IRQ. */
1667 bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON,
1668 BCM43xx_IRQ_BEACON);
1669 bcm->irq_savedstate |= BCM43xx_IRQ_BEACON;
1672 if (!(status & 0x1)) {
1673 bcm43xx_generate_beacon_template(bcm, 0x68, 0x18);
1675 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD, status);
1677 if (!(status & 0x2)) {
1678 bcm43xx_generate_beacon_template(bcm, 0x468, 0x1A);
1680 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD, status);
1684 /* Interrupt handler bottom-half */
1685 static void bcm43xx_interrupt_tasklet(struct bcm43xx_private *bcm)
1689 u32 merged_dma_reason = 0;
1690 int i, activity = 0;
1691 unsigned long flags;
1693 #ifdef CONFIG_BCM43XX_DEBUG
1694 u32 _handled = 0x00000000;
1695 # define bcmirq_handled(irq) do { _handled |= (irq); } while (0)
1697 # define bcmirq_handled(irq) do { /* nothing */ } while (0)
1698 #endif /* CONFIG_BCM43XX_DEBUG*/
1700 spin_lock_irqsave(&bcm->irq_lock, flags);
1701 reason = bcm->irq_reason;
1702 for (i = 5; i >= 0; i--) {
1703 dma_reason[i] = bcm->dma_reason[i];
1704 merged_dma_reason |= dma_reason[i];
1707 if (unlikely(reason & BCM43xx_IRQ_XMIT_ERROR)) {
1708 /* TX error. We get this when Template Ram is written in wrong endianess
1709 * in dummy_tx(). We also get this if something is wrong with the TX header
1710 * on DMA or PIO queues.
1711 * Maybe we get this in other error conditions, too.
1713 printkl(KERN_ERR PFX "FATAL ERROR: BCM43xx_IRQ_XMIT_ERROR\n");
1714 bcmirq_handled(BCM43xx_IRQ_XMIT_ERROR);
1716 if (unlikely(merged_dma_reason & BCM43xx_DMAIRQ_FATALMASK)) {
1717 printkl(KERN_ERR PFX "FATAL ERROR: Fatal DMA error: "
1718 "0x%08X, 0x%08X, 0x%08X, "
1719 "0x%08X, 0x%08X, 0x%08X\n",
1720 dma_reason[0], dma_reason[1],
1721 dma_reason[2], dma_reason[3],
1722 dma_reason[4], dma_reason[5]);
1723 bcm43xx_controller_restart(bcm, "DMA error");
1725 spin_unlock_irqrestore(&bcm->irq_lock, flags);
1728 if (unlikely(merged_dma_reason & BCM43xx_DMAIRQ_NONFATALMASK)) {
1729 printkl(KERN_ERR PFX "DMA error: "
1730 "0x%08X, 0x%08X, 0x%08X, "
1731 "0x%08X, 0x%08X, 0x%08X\n",
1732 dma_reason[0], dma_reason[1],
1733 dma_reason[2], dma_reason[3],
1734 dma_reason[4], dma_reason[5]);
1737 if (reason & BCM43xx_IRQ_PS) {
1739 bcmirq_handled(BCM43xx_IRQ_PS);
1742 if (reason & BCM43xx_IRQ_REG124) {
1743 handle_irq_reg124(bcm);
1744 bcmirq_handled(BCM43xx_IRQ_REG124);
1747 if (reason & BCM43xx_IRQ_BEACON) {
1748 if (bcm->ieee->iw_mode == IW_MODE_MASTER)
1749 handle_irq_beacon(bcm);
1750 bcmirq_handled(BCM43xx_IRQ_BEACON);
1753 if (reason & BCM43xx_IRQ_PMQ) {
1754 handle_irq_pmq(bcm);
1755 bcmirq_handled(BCM43xx_IRQ_PMQ);
1758 if (reason & BCM43xx_IRQ_SCAN) {
1760 //bcmirq_handled(BCM43xx_IRQ_SCAN);
1763 if (reason & BCM43xx_IRQ_NOISE) {
1764 handle_irq_noise(bcm);
1765 bcmirq_handled(BCM43xx_IRQ_NOISE);
1768 /* Check the DMA reason registers for received data. */
1769 if (dma_reason[0] & BCM43xx_DMAIRQ_RX_DONE) {
1770 if (bcm43xx_using_pio(bcm))
1771 bcm43xx_pio_rx(bcm43xx_current_pio(bcm)->queue0);
1773 bcm43xx_dma_rx(bcm43xx_current_dma(bcm)->rx_ring0);
1774 /* We intentionally don't set "activity" to 1, here. */
1776 assert(!(dma_reason[1] & BCM43xx_DMAIRQ_RX_DONE));
1777 assert(!(dma_reason[2] & BCM43xx_DMAIRQ_RX_DONE));
1778 if (dma_reason[3] & BCM43xx_DMAIRQ_RX_DONE) {
1779 if (bcm43xx_using_pio(bcm))
1780 bcm43xx_pio_rx(bcm43xx_current_pio(bcm)->queue3);
1782 bcm43xx_dma_rx(bcm43xx_current_dma(bcm)->rx_ring3);
1785 assert(!(dma_reason[4] & BCM43xx_DMAIRQ_RX_DONE));
1786 assert(!(dma_reason[5] & BCM43xx_DMAIRQ_RX_DONE));
1787 bcmirq_handled(BCM43xx_IRQ_RX);
1789 if (reason & BCM43xx_IRQ_XMIT_STATUS) {
1790 handle_irq_transmit_status(bcm);
1792 //TODO: In AP mode, this also causes sending of powersave responses.
1793 bcmirq_handled(BCM43xx_IRQ_XMIT_STATUS);
1796 /* IRQ_PIO_WORKAROUND is handled in the top-half. */
1797 bcmirq_handled(BCM43xx_IRQ_PIO_WORKAROUND);
1798 #ifdef CONFIG_BCM43XX_DEBUG
1799 if (unlikely(reason & ~_handled)) {
1800 printkl(KERN_WARNING PFX
1801 "Unhandled IRQ! Reason: 0x%08x, Unhandled: 0x%08x, "
1802 "DMA: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n",
1803 reason, (reason & ~_handled),
1804 dma_reason[0], dma_reason[1],
1805 dma_reason[2], dma_reason[3]);
1808 #undef bcmirq_handled
1810 if (!modparam_noleds)
1811 bcm43xx_leds_update(bcm, activity);
1812 bcm43xx_interrupt_enable(bcm, bcm->irq_savedstate);
1814 spin_unlock_irqrestore(&bcm->irq_lock, flags);
1817 static void pio_irq_workaround(struct bcm43xx_private *bcm,
1818 u16 base, int queueidx)
1822 rxctl = bcm43xx_read16(bcm, base + BCM43xx_PIO_RXCTL);
1823 if (rxctl & BCM43xx_PIO_RXCTL_DATAAVAILABLE)
1824 bcm->dma_reason[queueidx] |= BCM43xx_DMAIRQ_RX_DONE;
1826 bcm->dma_reason[queueidx] &= ~BCM43xx_DMAIRQ_RX_DONE;
1829 static void bcm43xx_interrupt_ack(struct bcm43xx_private *bcm, u32 reason)
1831 if (bcm43xx_using_pio(bcm) &&
1832 (bcm->current_core->rev < 3) &&
1833 (!(reason & BCM43xx_IRQ_PIO_WORKAROUND))) {
1834 /* Apply a PIO specific workaround to the dma_reasons */
1835 pio_irq_workaround(bcm, BCM43xx_MMIO_PIO1_BASE, 0);
1836 pio_irq_workaround(bcm, BCM43xx_MMIO_PIO2_BASE, 1);
1837 pio_irq_workaround(bcm, BCM43xx_MMIO_PIO3_BASE, 2);
1838 pio_irq_workaround(bcm, BCM43xx_MMIO_PIO4_BASE, 3);
1841 bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, reason);
1843 bcm43xx_write32(bcm, BCM43xx_MMIO_DMA0_REASON,
1844 bcm->dma_reason[0]);
1845 bcm43xx_write32(bcm, BCM43xx_MMIO_DMA1_REASON,
1846 bcm->dma_reason[1]);
1847 bcm43xx_write32(bcm, BCM43xx_MMIO_DMA2_REASON,
1848 bcm->dma_reason[2]);
1849 bcm43xx_write32(bcm, BCM43xx_MMIO_DMA3_REASON,
1850 bcm->dma_reason[3]);
1851 bcm43xx_write32(bcm, BCM43xx_MMIO_DMA4_REASON,
1852 bcm->dma_reason[4]);
1853 bcm43xx_write32(bcm, BCM43xx_MMIO_DMA5_REASON,
1854 bcm->dma_reason[5]);
1857 /* Interrupt handler top-half */
1858 static irqreturn_t bcm43xx_interrupt_handler(int irq, void *dev_id)
1860 irqreturn_t ret = IRQ_HANDLED;
1861 struct bcm43xx_private *bcm = dev_id;
1867 spin_lock(&bcm->irq_lock);
1869 assert(bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED);
1870 assert(bcm->current_core->id == BCM43xx_COREID_80211);
1872 reason = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
1873 if (reason == 0xffffffff) {
1874 /* irq not for us (shared irq) */
1878 reason &= bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK);
1882 bcm->dma_reason[0] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA0_REASON)
1884 bcm->dma_reason[1] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA1_REASON)
1886 bcm->dma_reason[2] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA2_REASON)
1888 bcm->dma_reason[3] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA3_REASON)
1890 bcm->dma_reason[4] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA4_REASON)
1892 bcm->dma_reason[5] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA5_REASON)
1895 bcm43xx_interrupt_ack(bcm, reason);
1897 /* disable all IRQs. They are enabled again in the bottom half. */
1898 bcm->irq_savedstate = bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
1899 /* save the reason code and call our bottom half. */
1900 bcm->irq_reason = reason;
1901 tasklet_schedule(&bcm->isr_tasklet);
1905 spin_unlock(&bcm->irq_lock);
1910 static void bcm43xx_release_firmware(struct bcm43xx_private *bcm, int force)
1912 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1914 if (bcm->firmware_norelease && !force)
1915 return; /* Suspending or controller reset. */
1916 release_firmware(phy->ucode);
1918 release_firmware(phy->pcm);
1920 release_firmware(phy->initvals0);
1921 phy->initvals0 = NULL;
1922 release_firmware(phy->initvals1);
1923 phy->initvals1 = NULL;
1926 static int bcm43xx_request_firmware(struct bcm43xx_private *bcm)
1928 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1929 u8 rev = bcm->current_core->rev;
1932 char buf[22 + sizeof(modparam_fwpostfix) - 1] = { 0 };
1935 snprintf(buf, ARRAY_SIZE(buf), "bcm43xx_microcode%d%s.fw",
1936 (rev >= 5 ? 5 : rev),
1937 modparam_fwpostfix);
1938 err = request_firmware(&phy->ucode, buf, &bcm->pci_dev->dev);
1941 "Error: Microcode \"%s\" not available or load failed.\n",
1948 snprintf(buf, ARRAY_SIZE(buf),
1949 "bcm43xx_pcm%d%s.fw",
1951 modparam_fwpostfix);
1952 err = request_firmware(&phy->pcm, buf, &bcm->pci_dev->dev);
1955 "Error: PCM \"%s\" not available or load failed.\n",
1961 if (!phy->initvals0) {
1962 if (rev == 2 || rev == 4) {
1963 switch (phy->type) {
1964 case BCM43xx_PHYTYPE_A:
1967 case BCM43xx_PHYTYPE_B:
1968 case BCM43xx_PHYTYPE_G:
1975 } else if (rev >= 5) {
1976 switch (phy->type) {
1977 case BCM43xx_PHYTYPE_A:
1980 case BCM43xx_PHYTYPE_B:
1981 case BCM43xx_PHYTYPE_G:
1989 snprintf(buf, ARRAY_SIZE(buf), "bcm43xx_initval%02d%s.fw",
1990 nr, modparam_fwpostfix);
1992 err = request_firmware(&phy->initvals0, buf, &bcm->pci_dev->dev);
1995 "Error: InitVals \"%s\" not available or load failed.\n",
1999 if (phy->initvals0->size % sizeof(struct bcm43xx_initval)) {
2000 printk(KERN_ERR PFX "InitVals fileformat error.\n");
2005 if (!phy->initvals1) {
2009 switch (phy->type) {
2010 case BCM43xx_PHYTYPE_A:
2011 sbtmstatehigh = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
2012 if (sbtmstatehigh & 0x00010000)
2017 case BCM43xx_PHYTYPE_B:
2018 case BCM43xx_PHYTYPE_G:
2024 snprintf(buf, ARRAY_SIZE(buf), "bcm43xx_initval%02d%s.fw",
2025 nr, modparam_fwpostfix);
2027 err = request_firmware(&phy->initvals1, buf, &bcm->pci_dev->dev);
2030 "Error: InitVals \"%s\" not available or load failed.\n",
2034 if (phy->initvals1->size % sizeof(struct bcm43xx_initval)) {
2035 printk(KERN_ERR PFX "InitVals fileformat error.\n");
2044 bcm43xx_release_firmware(bcm, 1);
2047 printk(KERN_ERR PFX "Error: No InitVals available!\n");
2052 static void bcm43xx_upload_microcode(struct bcm43xx_private *bcm)
2054 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
2056 unsigned int i, len;
2058 /* Upload Microcode. */
2059 data = (u32 *)(phy->ucode->data);
2060 len = phy->ucode->size / sizeof(u32);
2061 bcm43xx_shm_control_word(bcm, BCM43xx_SHM_UCODE, 0x0000);
2062 for (i = 0; i < len; i++) {
2063 bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA,
2064 be32_to_cpu(data[i]));
2068 /* Upload PCM data. */
2069 data = (u32 *)(phy->pcm->data);
2070 len = phy->pcm->size / sizeof(u32);
2071 bcm43xx_shm_control_word(bcm, BCM43xx_SHM_PCM, 0x01ea);
2072 bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA, 0x00004000);
2073 bcm43xx_shm_control_word(bcm, BCM43xx_SHM_PCM, 0x01eb);
2074 for (i = 0; i < len; i++) {
2075 bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA,
2076 be32_to_cpu(data[i]));
2081 static int bcm43xx_write_initvals(struct bcm43xx_private *bcm,
2082 const struct bcm43xx_initval *data,
2083 const unsigned int len)
2089 for (i = 0; i < len; i++) {
2090 offset = be16_to_cpu(data[i].offset);
2091 size = be16_to_cpu(data[i].size);
2092 value = be32_to_cpu(data[i].value);
2094 if (unlikely(offset >= 0x1000))
2097 if (unlikely(value & 0xFFFF0000))
2099 bcm43xx_write16(bcm, offset, (u16)value);
2100 } else if (size == 4) {
2101 bcm43xx_write32(bcm, offset, value);
2109 printk(KERN_ERR PFX "InitVals (bcm43xx_initvalXX.fw) file-format error. "
2110 "Please fix your bcm43xx firmware files.\n");
2114 static int bcm43xx_upload_initvals(struct bcm43xx_private *bcm)
2116 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
2119 err = bcm43xx_write_initvals(bcm, (struct bcm43xx_initval *)phy->initvals0->data,
2120 phy->initvals0->size / sizeof(struct bcm43xx_initval));
2123 if (phy->initvals1) {
2124 err = bcm43xx_write_initvals(bcm, (struct bcm43xx_initval *)phy->initvals1->data,
2125 phy->initvals1->size / sizeof(struct bcm43xx_initval));
2133 #ifdef CONFIG_BCM947XX
2134 static struct pci_device_id bcm43xx_47xx_ids[] = {
2135 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4324) },
2140 static int bcm43xx_initialize_irq(struct bcm43xx_private *bcm)
2144 bcm->irq = bcm->pci_dev->irq;
2145 #ifdef CONFIG_BCM947XX
2146 if (bcm->pci_dev->bus->number == 0) {
2148 struct pci_device_id *id;
2149 for (id = bcm43xx_47xx_ids; id->vendor; id++) {
2150 d = pci_get_device(id->vendor, id->device, NULL);
2159 err = request_irq(bcm->irq, bcm43xx_interrupt_handler,
2160 IRQF_SHARED, KBUILD_MODNAME, bcm);
2162 printk(KERN_ERR PFX "Cannot register IRQ%d\n", bcm->irq);
2167 /* Switch to the core used to write the GPIO register.
2168 * This is either the ChipCommon, or the PCI core.
2170 static int switch_to_gpio_core(struct bcm43xx_private *bcm)
2174 /* Where to find the GPIO register depends on the chipset.
2175 * If it has a ChipCommon, its register at offset 0x6c is the GPIO
2176 * control register. Otherwise the register at offset 0x6c in the
2177 * PCI core is the GPIO control register.
2179 err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
2180 if (err == -ENODEV) {
2181 err = bcm43xx_switch_core(bcm, &bcm->core_pci);
2182 if (unlikely(err == -ENODEV)) {
2183 printk(KERN_ERR PFX "gpio error: "
2184 "Neither ChipCommon nor PCI core available!\n");
2191 /* Initialize the GPIOs
2192 * http://bcm-specs.sipsolutions.net/GPIO
2194 static int bcm43xx_gpio_init(struct bcm43xx_private *bcm)
2196 struct bcm43xx_coreinfo *old_core;
2200 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
2201 bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
2204 bcm43xx_leds_switch_all(bcm, 0);
2205 bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_MASK,
2206 bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_MASK) | 0x000F);
2210 if (bcm->chip_id == 0x4301) {
2214 if (0 /* FIXME: conditional unknown */) {
2215 bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_MASK,
2216 bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_MASK)
2221 if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL) {
2222 bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_MASK,
2223 bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_MASK)
2228 if (bcm->current_core->rev >= 2)
2229 mask |= 0x0010; /* FIXME: This is redundant. */
2231 old_core = bcm->current_core;
2232 err = switch_to_gpio_core(bcm);
2235 bcm43xx_write32(bcm, BCM43xx_GPIO_CONTROL,
2236 (bcm43xx_read32(bcm, BCM43xx_GPIO_CONTROL) & mask) | set);
2237 err = bcm43xx_switch_core(bcm, old_core);
2242 /* Turn off all GPIO stuff. Call this on module unload, for example. */
2243 static int bcm43xx_gpio_cleanup(struct bcm43xx_private *bcm)
2245 struct bcm43xx_coreinfo *old_core;
2248 old_core = bcm->current_core;
2249 err = switch_to_gpio_core(bcm);
2252 bcm43xx_write32(bcm, BCM43xx_GPIO_CONTROL, 0x00000000);
2253 err = bcm43xx_switch_core(bcm, old_core);
2259 /* http://bcm-specs.sipsolutions.net/EnableMac */
2260 void bcm43xx_mac_enable(struct bcm43xx_private *bcm)
2262 bcm->mac_suspended--;
2263 assert(bcm->mac_suspended >= 0);
2264 if (bcm->mac_suspended == 0) {
2265 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
2266 bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
2267 | BCM43xx_SBF_MAC_ENABLED);
2268 bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, BCM43xx_IRQ_READY);
2269 bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* dummy read */
2270 bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON); /* dummy read */
2271 bcm43xx_power_saving_ctl_bits(bcm, -1, -1);
2275 /* http://bcm-specs.sipsolutions.net/SuspendMAC */
2276 void bcm43xx_mac_suspend(struct bcm43xx_private *bcm)
2281 assert(bcm->mac_suspended >= 0);
2282 if (bcm->mac_suspended == 0) {
2283 bcm43xx_power_saving_ctl_bits(bcm, -1, 1);
2284 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
2285 bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
2286 & ~BCM43xx_SBF_MAC_ENABLED);
2287 bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON); /* dummy read */
2288 for (i = 10000; i; i--) {
2289 tmp = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
2290 if (tmp & BCM43xx_IRQ_READY)
2294 printkl(KERN_ERR PFX "MAC suspend failed\n");
2297 bcm->mac_suspended++;
2300 void bcm43xx_set_iwmode(struct bcm43xx_private *bcm,
2303 unsigned long flags;
2304 struct net_device *net_dev = bcm->net_dev;
2308 spin_lock_irqsave(&bcm->ieee->lock, flags);
2309 bcm->ieee->iw_mode = iw_mode;
2310 spin_unlock_irqrestore(&bcm->ieee->lock, flags);
2311 if (iw_mode == IW_MODE_MONITOR)
2312 net_dev->type = ARPHRD_IEEE80211;
2314 net_dev->type = ARPHRD_ETHER;
2316 status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
2317 /* Reset status to infrastructured mode */
2318 status &= ~(BCM43xx_SBF_MODE_AP | BCM43xx_SBF_MODE_MONITOR);
2319 status &= ~BCM43xx_SBF_MODE_PROMISC;
2320 status |= BCM43xx_SBF_MODE_NOTADHOC;
2322 /* FIXME: Always enable promisc mode, until we get the MAC filters working correctly. */
2323 status |= BCM43xx_SBF_MODE_PROMISC;
2326 case IW_MODE_MONITOR:
2327 status |= BCM43xx_SBF_MODE_MONITOR;
2328 status |= BCM43xx_SBF_MODE_PROMISC;
2331 status &= ~BCM43xx_SBF_MODE_NOTADHOC;
2333 case IW_MODE_MASTER:
2334 status |= BCM43xx_SBF_MODE_AP;
2336 case IW_MODE_SECOND:
2337 case IW_MODE_REPEAT:
2341 /* nothing to be done here... */
2344 dprintk(KERN_ERR PFX "Unknown mode in set_iwmode: %d\n", iw_mode);
2346 if (net_dev->flags & IFF_PROMISC)
2347 status |= BCM43xx_SBF_MODE_PROMISC;
2348 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
2351 if (iw_mode != IW_MODE_ADHOC && iw_mode != IW_MODE_MASTER) {
2352 if (bcm->chip_id == 0x4306 && bcm->chip_rev == 3)
2357 bcm43xx_write16(bcm, 0x0612, value);
2360 /* This is the opposite of bcm43xx_chip_init() */
2361 static void bcm43xx_chip_cleanup(struct bcm43xx_private *bcm)
2363 bcm43xx_radio_turn_off(bcm);
2364 if (!modparam_noleds)
2365 bcm43xx_leds_exit(bcm);
2366 bcm43xx_gpio_cleanup(bcm);
2367 bcm43xx_release_firmware(bcm, 0);
2370 /* Initialize the chip
2371 * http://bcm-specs.sipsolutions.net/ChipInit
2373 static int bcm43xx_chip_init(struct bcm43xx_private *bcm)
2375 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
2376 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
2382 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
2383 BCM43xx_SBF_CORE_READY
2386 err = bcm43xx_request_firmware(bcm);
2389 bcm43xx_upload_microcode(bcm);
2391 bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, 0xFFFFFFFF);
2392 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, 0x00020402);
2395 value32 = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
2396 if (value32 == BCM43xx_IRQ_READY)
2399 if (i >= BCM43xx_IRQWAIT_MAX_RETRIES) {
2400 printk(KERN_ERR PFX "IRQ_READY timeout\n");
2402 goto err_release_fw;
2406 bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON); /* dummy read */
2408 value16 = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED,
2409 BCM43xx_UCODE_REVISION);
2411 dprintk(KERN_INFO PFX "Microcode rev 0x%x, pl 0x%x "
2412 "(20%.2i-%.2i-%.2i %.2i:%.2i:%.2i)\n", value16,
2413 bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED,
2414 BCM43xx_UCODE_PATCHLEVEL),
2415 (bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED,
2416 BCM43xx_UCODE_DATE) >> 12) & 0xf,
2417 (bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED,
2418 BCM43xx_UCODE_DATE) >> 8) & 0xf,
2419 bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED,
2420 BCM43xx_UCODE_DATE) & 0xff,
2421 (bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED,
2422 BCM43xx_UCODE_TIME) >> 11) & 0x1f,
2423 (bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED,
2424 BCM43xx_UCODE_TIME) >> 5) & 0x3f,
2425 bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED,
2426 BCM43xx_UCODE_TIME) & 0x1f);
2428 if ( value16 > 0x128 ) {
2430 "Firmware: no support for microcode extracted "
2431 "from version 4.x binary drivers.\n");
2433 goto err_release_fw;
2436 err = bcm43xx_gpio_init(bcm);
2438 goto err_release_fw;
2440 err = bcm43xx_upload_initvals(bcm);
2442 goto err_gpio_cleanup;
2443 bcm43xx_radio_turn_on(bcm);
2444 bcm->radio_hw_enable = bcm43xx_is_hw_radio_enabled(bcm);
2445 dprintk(KERN_INFO PFX "Radio %s by hardware\n",
2446 (bcm->radio_hw_enable == 0) ? "disabled" : "enabled");
2448 bcm43xx_write16(bcm, 0x03E6, 0x0000);
2449 err = bcm43xx_phy_init(bcm);
2453 /* Select initial Interference Mitigation. */
2454 tmp = radio->interfmode;
2455 radio->interfmode = BCM43xx_RADIO_INTERFMODE_NONE;
2456 bcm43xx_radio_set_interference_mitigation(bcm, tmp);
2458 bcm43xx_phy_set_antenna_diversity(bcm);
2459 bcm43xx_radio_set_txantenna(bcm, BCM43xx_RADIO_TXANTENNA_DEFAULT);
2460 if (phy->type == BCM43xx_PHYTYPE_B) {
2461 value16 = bcm43xx_read16(bcm, 0x005E);
2463 bcm43xx_write16(bcm, 0x005E, value16);
2465 bcm43xx_write32(bcm, 0x0100, 0x01000000);
2466 if (bcm->current_core->rev < 5)
2467 bcm43xx_write32(bcm, 0x010C, 0x01000000);
2469 value32 = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
2470 value32 &= ~ BCM43xx_SBF_MODE_NOTADHOC;
2471 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value32);
2472 value32 = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
2473 value32 |= BCM43xx_SBF_MODE_NOTADHOC;
2474 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value32);
2476 value32 = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
2477 value32 |= 0x100000;
2478 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value32);
2480 if (bcm43xx_using_pio(bcm)) {
2481 bcm43xx_write32(bcm, 0x0210, 0x00000100);
2482 bcm43xx_write32(bcm, 0x0230, 0x00000100);
2483 bcm43xx_write32(bcm, 0x0250, 0x00000100);
2484 bcm43xx_write32(bcm, 0x0270, 0x00000100);
2485 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0034, 0x0000);
2488 /* Probe Response Timeout value */
2489 /* FIXME: Default to 0, has to be set by ioctl probably... :-/ */
2490 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0074, 0x0000);
2492 /* Initially set the wireless operation mode. */
2493 bcm43xx_set_iwmode(bcm, bcm->ieee->iw_mode);
2495 if (bcm->current_core->rev < 3) {
2496 bcm43xx_write16(bcm, 0x060E, 0x0000);
2497 bcm43xx_write16(bcm, 0x0610, 0x8000);
2498 bcm43xx_write16(bcm, 0x0604, 0x0000);
2499 bcm43xx_write16(bcm, 0x0606, 0x0200);
2501 bcm43xx_write32(bcm, 0x0188, 0x80000000);
2502 bcm43xx_write32(bcm, 0x018C, 0x02000000);
2504 bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, 0x00004000);
2505 bcm43xx_write32(bcm, BCM43xx_MMIO_DMA0_IRQ_MASK, 0x0001DC00);
2506 bcm43xx_write32(bcm, BCM43xx_MMIO_DMA1_IRQ_MASK, 0x0000DC00);
2507 bcm43xx_write32(bcm, BCM43xx_MMIO_DMA2_IRQ_MASK, 0x0000DC00);
2508 bcm43xx_write32(bcm, BCM43xx_MMIO_DMA3_IRQ_MASK, 0x0001DC00);
2509 bcm43xx_write32(bcm, BCM43xx_MMIO_DMA4_IRQ_MASK, 0x0000DC00);
2510 bcm43xx_write32(bcm, BCM43xx_MMIO_DMA5_IRQ_MASK, 0x0000DC00);
2512 value32 = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
2513 value32 |= 0x00100000;
2514 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, value32);
2516 bcm43xx_write16(bcm, BCM43xx_MMIO_POWERUP_DELAY, bcm43xx_pctl_powerup_delay(bcm));
2519 dprintk(KERN_INFO PFX "Chip initialized\n");
2524 bcm43xx_radio_turn_off(bcm);
2526 bcm43xx_gpio_cleanup(bcm);
2528 bcm43xx_release_firmware(bcm, 1);
2532 /* Validate chip access
2533 * http://bcm-specs.sipsolutions.net/ValidateChipAccess */
2534 static int bcm43xx_validate_chip(struct bcm43xx_private *bcm)
2539 shm_backup = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, 0x0000);
2540 bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED, 0x0000, 0xAA5555AA);
2541 if (bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, 0x0000) != 0xAA5555AA)
2543 bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED, 0x0000, 0x55AAAA55);
2544 if (bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, 0x0000) != 0x55AAAA55)
2546 bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED, 0x0000, shm_backup);
2548 value = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
2549 if ((value | 0x80000000) != 0x80000400)
2552 value = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
2553 if (value != 0x00000000)
2558 printk(KERN_ERR PFX "Failed to validate the chipaccess\n");
2562 static void bcm43xx_init_struct_phyinfo(struct bcm43xx_phyinfo *phy)
2564 /* Initialize a "phyinfo" structure. The structure is already
2566 * This is called on insmod time to initialize members.
2568 phy->savedpctlreg = 0xFFFF;
2569 spin_lock_init(&phy->lock);
2572 static void bcm43xx_init_struct_radioinfo(struct bcm43xx_radioinfo *radio)
2574 /* Initialize a "radioinfo" structure. The structure is already
2576 * This is called on insmod time to initialize members.
2578 radio->interfmode = BCM43xx_RADIO_INTERFMODE_NONE;
2579 radio->channel = 0xFF;
2580 radio->initial_channel = 0xFF;
2583 static int bcm43xx_probe_cores(struct bcm43xx_private *bcm)
2587 u32 core_vendor, core_id, core_rev;
2588 u32 sb_id_hi, chip_id_32 = 0;
2589 u16 pci_device, chip_id_16;
2592 memset(&bcm->core_chipcommon, 0, sizeof(struct bcm43xx_coreinfo));
2593 memset(&bcm->core_pci, 0, sizeof(struct bcm43xx_coreinfo));
2594 memset(&bcm->core_80211, 0, sizeof(struct bcm43xx_coreinfo)
2595 * BCM43xx_MAX_80211_CORES);
2596 memset(&bcm->core_80211_ext, 0, sizeof(struct bcm43xx_coreinfo_80211)
2597 * BCM43xx_MAX_80211_CORES);
2598 bcm->nr_80211_available = 0;
2599 bcm->current_core = NULL;
2600 bcm->active_80211_core = NULL;
2603 err = _switch_core(bcm, 0);
2607 /* fetch sb_id_hi from core information registers */
2608 sb_id_hi = bcm43xx_read32(bcm, BCM43xx_CIR_SB_ID_HI);
2610 core_id = (sb_id_hi & 0x8FF0) >> 4;
2611 core_rev = (sb_id_hi & 0x7000) >> 8;
2612 core_rev |= (sb_id_hi & 0xF);
2613 core_vendor = (sb_id_hi & 0xFFFF0000) >> 16;
2615 /* if present, chipcommon is always core 0; read the chipid from it */
2616 if (core_id == BCM43xx_COREID_CHIPCOMMON) {
2617 chip_id_32 = bcm43xx_read32(bcm, 0);
2618 chip_id_16 = chip_id_32 & 0xFFFF;
2619 bcm->core_chipcommon.available = 1;
2620 bcm->core_chipcommon.id = core_id;
2621 bcm->core_chipcommon.rev = core_rev;
2622 bcm->core_chipcommon.index = 0;
2623 /* While we are at it, also read the capabilities. */
2624 bcm->chipcommon_capabilities = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_CAPABILITIES);
2626 /* without a chipCommon, use a hard coded table. */
2627 pci_device = bcm->pci_dev->device;
2628 if (pci_device == 0x4301)
2629 chip_id_16 = 0x4301;
2630 else if ((pci_device >= 0x4305) && (pci_device <= 0x4307))
2631 chip_id_16 = 0x4307;
2632 else if ((pci_device >= 0x4402) && (pci_device <= 0x4403))
2633 chip_id_16 = 0x4402;
2634 else if ((pci_device >= 0x4610) && (pci_device <= 0x4615))
2635 chip_id_16 = 0x4610;
2636 else if ((pci_device >= 0x4710) && (pci_device <= 0x4715))
2637 chip_id_16 = 0x4710;
2638 #ifdef CONFIG_BCM947XX
2639 else if ((pci_device >= 0x4320) && (pci_device <= 0x4325))
2640 chip_id_16 = 0x4309;
2643 printk(KERN_ERR PFX "Could not determine Chip ID\n");
2648 /* ChipCommon with Core Rev >=4 encodes number of cores,
2649 * otherwise consult hardcoded table */
2650 if ((core_id == BCM43xx_COREID_CHIPCOMMON) && (core_rev >= 4)) {
2651 core_count = (chip_id_32 & 0x0F000000) >> 24;
2653 switch (chip_id_16) {
2676 /* SOL if we get here */
2682 bcm->chip_id = chip_id_16;
2683 bcm->chip_rev = (chip_id_32 & 0x000F0000) >> 16;
2684 bcm->chip_package = (chip_id_32 & 0x00F00000) >> 20;
2686 dprintk(KERN_INFO PFX "Chip ID 0x%x, rev 0x%x\n",
2687 bcm->chip_id, bcm->chip_rev);
2688 dprintk(KERN_INFO PFX "Number of cores: %d\n", core_count);
2689 if (bcm->core_chipcommon.available) {
2690 dprintk(KERN_INFO PFX "Core 0: ID 0x%x, rev 0x%x, vendor 0x%x\n",
2691 core_id, core_rev, core_vendor);
2695 for ( ; current_core < core_count; current_core++) {
2696 struct bcm43xx_coreinfo *core;
2697 struct bcm43xx_coreinfo_80211 *ext_80211;
2699 err = _switch_core(bcm, current_core);
2702 /* Gather information */
2703 /* fetch sb_id_hi from core information registers */
2704 sb_id_hi = bcm43xx_read32(bcm, BCM43xx_CIR_SB_ID_HI);
2706 /* extract core_id, core_rev, core_vendor */
2707 core_id = (sb_id_hi & 0x8FF0) >> 4;
2708 core_rev = ((sb_id_hi & 0xF) | ((sb_id_hi & 0x7000) >> 8));
2709 core_vendor = (sb_id_hi & 0xFFFF0000) >> 16;
2711 dprintk(KERN_INFO PFX "Core %d: ID 0x%x, rev 0x%x, vendor 0x%x\n",
2712 current_core, core_id, core_rev, core_vendor);
2716 case BCM43xx_COREID_PCI:
2717 case BCM43xx_COREID_PCIE:
2718 core = &bcm->core_pci;
2719 if (core->available) {
2720 printk(KERN_WARNING PFX "Multiple PCI cores found.\n");
2724 case BCM43xx_COREID_80211:
2725 for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
2726 core = &(bcm->core_80211[i]);
2727 ext_80211 = &(bcm->core_80211_ext[i]);
2728 if (!core->available)
2733 printk(KERN_WARNING PFX "More than %d cores of type 802.11 found.\n",
2734 BCM43xx_MAX_80211_CORES);
2738 /* More than one 80211 core is only supported
2740 * There are chips with two 80211 cores, but with
2741 * dangling pins on the second core. Be careful
2742 * and ignore these cores here.
2744 if (bcm->pci_dev->device != 0x4324) {
2745 dprintk(KERN_INFO PFX "Ignoring additional 802.11 core.\n");
2759 printk(KERN_WARNING PFX
2760 "Unsupported 80211 core revision %u\n",
2763 bcm->nr_80211_available++;
2764 core->priv = ext_80211;
2765 bcm43xx_init_struct_phyinfo(&ext_80211->phy);
2766 bcm43xx_init_struct_radioinfo(&ext_80211->radio);
2768 case BCM43xx_COREID_CHIPCOMMON:
2769 printk(KERN_WARNING PFX "Multiple CHIPCOMMON cores found.\n");
2773 core->available = 1;
2775 core->rev = core_rev;
2776 core->index = current_core;
2780 if (!bcm->core_80211[0].available) {
2781 printk(KERN_ERR PFX "Error: No 80211 core found!\n");
2786 err = bcm43xx_switch_core(bcm, &bcm->core_80211[0]);
2793 static void bcm43xx_gen_bssid(struct bcm43xx_private *bcm)
2795 const u8 *mac = (const u8*)(bcm->net_dev->dev_addr);
2796 u8 *bssid = bcm->ieee->bssid;
2798 switch (bcm->ieee->iw_mode) {
2800 random_ether_addr(bssid);
2802 case IW_MODE_MASTER:
2804 case IW_MODE_REPEAT:
2805 case IW_MODE_SECOND:
2806 case IW_MODE_MONITOR:
2807 memcpy(bssid, mac, ETH_ALEN);
2814 static void bcm43xx_rate_memory_write(struct bcm43xx_private *bcm,
2822 offset += (bcm43xx_plcp_get_ratecode_ofdm(rate) & 0x000F) * 2;
2826 offset += (bcm43xx_plcp_get_ratecode_cck(rate) & 0x000F) * 2;
2828 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, offset + 0x20,
2829 bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, offset));
2832 static void bcm43xx_rate_memory_init(struct bcm43xx_private *bcm)
2834 switch (bcm43xx_current_phy(bcm)->type) {
2835 case BCM43xx_PHYTYPE_A:
2836 case BCM43xx_PHYTYPE_G:
2837 bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_6MB, 1);
2838 bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_12MB, 1);
2839 bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_18MB, 1);
2840 bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_24MB, 1);
2841 bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_36MB, 1);
2842 bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_48MB, 1);
2843 bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_54MB, 1);
2844 case BCM43xx_PHYTYPE_B:
2845 bcm43xx_rate_memory_write(bcm, IEEE80211_CCK_RATE_1MB, 0);
2846 bcm43xx_rate_memory_write(bcm, IEEE80211_CCK_RATE_2MB, 0);
2847 bcm43xx_rate_memory_write(bcm, IEEE80211_CCK_RATE_5MB, 0);
2848 bcm43xx_rate_memory_write(bcm, IEEE80211_CCK_RATE_11MB, 0);
2855 static void bcm43xx_wireless_core_cleanup(struct bcm43xx_private *bcm)
2857 bcm43xx_chip_cleanup(bcm);
2858 bcm43xx_pio_free(bcm);
2859 bcm43xx_dma_free(bcm);
2861 bcm->current_core->initialized = 0;
2864 /* http://bcm-specs.sipsolutions.net/80211Init */
2865 static int bcm43xx_wireless_core_init(struct bcm43xx_private *bcm,
2868 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
2869 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
2875 if (bcm->core_pci.rev <= 5 && bcm->core_pci.id != BCM43xx_COREID_PCIE) {
2876 sbimconfiglow = bcm43xx_read32(bcm, BCM43xx_CIR_SBIMCONFIGLOW);
2877 sbimconfiglow &= ~ BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_MASK;
2878 sbimconfiglow &= ~ BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_MASK;
2879 if (bcm->bustype == BCM43xx_BUSTYPE_PCI)
2880 sbimconfiglow |= 0x32;
2882 sbimconfiglow |= 0x53;
2883 bcm43xx_write32(bcm, BCM43xx_CIR_SBIMCONFIGLOW, sbimconfiglow);
2886 bcm43xx_phy_calibrate(bcm);
2887 err = bcm43xx_chip_init(bcm);
2891 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0016, bcm->current_core->rev);
2892 ucodeflags = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, BCM43xx_UCODEFLAGS_OFFSET);
2894 if (0 /*FIXME: which condition has to be used here? */)
2895 ucodeflags |= 0x00000010;
2897 /* HW decryption needs to be set now */
2898 ucodeflags |= 0x40000000;
2900 if (phy->type == BCM43xx_PHYTYPE_G) {
2901 ucodeflags |= BCM43xx_UCODEFLAG_UNKBGPHY;
2903 ucodeflags |= BCM43xx_UCODEFLAG_UNKGPHY;
2904 if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL)
2905 ucodeflags |= BCM43xx_UCODEFLAG_UNKPACTRL;
2906 } else if (phy->type == BCM43xx_PHYTYPE_B) {
2907 ucodeflags |= BCM43xx_UCODEFLAG_UNKBGPHY;
2908 if (phy->rev >= 2 && radio->version == 0x2050)
2909 ucodeflags &= ~BCM43xx_UCODEFLAG_UNKGPHY;
2912 if (ucodeflags != bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
2913 BCM43xx_UCODEFLAGS_OFFSET)) {
2914 bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
2915 BCM43xx_UCODEFLAGS_OFFSET, ucodeflags);
2918 /* Short/Long Retry Limit.
2919 * The retry-limit is a 4-bit counter. Enforce this to avoid overflowing
2920 * the chip-internal counter.
2922 limit = limit_value(modparam_short_retry, 0, 0xF);
2923 bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0006, limit);
2924 limit = limit_value(modparam_long_retry, 0, 0xF);
2925 bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0007, limit);
2927 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0044, 3);
2928 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0046, 2);
2930 bcm43xx_rate_memory_init(bcm);
2932 /* Minimum Contention Window */
2933 if (phy->type == BCM43xx_PHYTYPE_B)
2934 bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0003, 0x0000001f);
2936 bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0003, 0x0000000f);
2937 /* Maximum Contention Window */
2938 bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0004, 0x000003ff);
2940 bcm43xx_gen_bssid(bcm);
2941 bcm43xx_write_mac_bssid_templates(bcm);
2943 if (bcm->current_core->rev >= 5)
2944 bcm43xx_write16(bcm, 0x043C, 0x000C);
2946 if (active_wlcore) {
2947 if (bcm43xx_using_pio(bcm)) {
2948 err = bcm43xx_pio_init(bcm);
2950 err = bcm43xx_dma_init(bcm);
2952 err = bcm43xx_pio_init(bcm);
2955 goto err_chip_cleanup;
2957 bcm43xx_write16(bcm, 0x0612, 0x0050);
2958 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0416, 0x0050);
2959 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0414, 0x01F4);
2961 if (active_wlcore) {
2962 if (radio->initial_channel != 0xFF)
2963 bcm43xx_radio_selectchannel(bcm, radio->initial_channel, 0);
2966 /* Don't enable MAC/IRQ here, as it will race with the IRQ handler.
2967 * We enable it later.
2969 bcm->current_core->initialized = 1;
2974 bcm43xx_chip_cleanup(bcm);
2978 static int bcm43xx_chipset_attach(struct bcm43xx_private *bcm)
2983 err = bcm43xx_pctl_set_crystal(bcm, 1);
2986 bcm43xx_pci_read_config16(bcm, PCI_STATUS, &pci_status);
2987 bcm43xx_pci_write_config16(bcm, PCI_STATUS, pci_status & ~PCI_STATUS_SIG_TARGET_ABORT);
2993 static void bcm43xx_chipset_detach(struct bcm43xx_private *bcm)
2995 bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_SLOW);
2996 bcm43xx_pctl_set_crystal(bcm, 0);
2999 static void bcm43xx_pcicore_broadcast_value(struct bcm43xx_private *bcm,
3003 bcm43xx_write32(bcm, BCM43xx_PCICORE_BCAST_ADDR, address);
3004 bcm43xx_write32(bcm, BCM43xx_PCICORE_BCAST_DATA, data);
3007 static int bcm43xx_pcicore_commit_settings(struct bcm43xx_private *bcm)
3011 bcm->irq_savedstate = bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
3013 if (bcm->core_chipcommon.available) {
3014 err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
3018 bcm43xx_pcicore_broadcast_value(bcm, 0xfd8, 0x00000000);
3020 /* this function is always called when a PCI core is mapped */
3021 err = bcm43xx_switch_core(bcm, &bcm->core_pci);
3025 bcm43xx_pcicore_broadcast_value(bcm, 0xfd8, 0x00000000);
3027 bcm43xx_interrupt_enable(bcm, bcm->irq_savedstate);
3033 static u32 bcm43xx_pcie_reg_read(struct bcm43xx_private *bcm, u32 address)
3035 bcm43xx_write32(bcm, BCM43xx_PCIECORE_REG_ADDR, address);
3036 return bcm43xx_read32(bcm, BCM43xx_PCIECORE_REG_DATA);
3039 static void bcm43xx_pcie_reg_write(struct bcm43xx_private *bcm, u32 address,
3042 bcm43xx_write32(bcm, BCM43xx_PCIECORE_REG_ADDR, address);
3043 bcm43xx_write32(bcm, BCM43xx_PCIECORE_REG_DATA, data);
3046 static void bcm43xx_pcie_mdio_write(struct bcm43xx_private *bcm, u8 dev, u8 reg,
3051 bcm43xx_write32(bcm, BCM43xx_PCIECORE_MDIO_CTL, 0x0082);
3052 bcm43xx_write32(bcm, BCM43xx_PCIECORE_MDIO_DATA, BCM43xx_PCIE_MDIO_ST |
3053 BCM43xx_PCIE_MDIO_WT | (dev << BCM43xx_PCIE_MDIO_DEV) |
3054 (reg << BCM43xx_PCIE_MDIO_REG) | BCM43xx_PCIE_MDIO_TA |
3058 for (i = 0; i < 10; i++) {
3059 if (bcm43xx_read32(bcm, BCM43xx_PCIECORE_MDIO_CTL) &
3060 BCM43xx_PCIE_MDIO_TC)
3064 bcm43xx_write32(bcm, BCM43xx_PCIECORE_MDIO_CTL, 0);
3067 /* Make an I/O Core usable. "core_mask" is the bitmask of the cores to enable.
3068 * To enable core 0, pass a core_mask of 1<<0
3070 static int bcm43xx_setup_backplane_pci_connection(struct bcm43xx_private *bcm,
3073 u32 backplane_flag_nr;
3075 struct bcm43xx_coreinfo *old_core;
3078 value = bcm43xx_read32(bcm, BCM43xx_CIR_SBTPSFLAG);
3079 backplane_flag_nr = value & BCM43xx_BACKPLANE_FLAG_NR_MASK;
3081 old_core = bcm->current_core;
3082 err = bcm43xx_switch_core(bcm, &bcm->core_pci);
3086 if (bcm->current_core->rev < 6 &&
3087 bcm->current_core->id == BCM43xx_COREID_PCI) {
3088 value = bcm43xx_read32(bcm, BCM43xx_CIR_SBINTVEC);
3089 value |= (1 << backplane_flag_nr);
3090 bcm43xx_write32(bcm, BCM43xx_CIR_SBINTVEC, value);
3092 err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCICFG_ICR, &value);
3094 printk(KERN_ERR PFX "Error: ICR setup failure!\n");
3095 goto out_switch_back;
3097 value |= core_mask << 8;
3098 err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_ICR, value);
3100 printk(KERN_ERR PFX "Error: ICR setup failure!\n");
3101 goto out_switch_back;
3105 if (bcm->current_core->id == BCM43xx_COREID_PCI) {
3106 value = bcm43xx_read32(bcm, BCM43xx_PCICORE_SBTOPCI2);
3107 value |= BCM43xx_SBTOPCI2_PREFETCH | BCM43xx_SBTOPCI2_BURST;
3108 bcm43xx_write32(bcm, BCM43xx_PCICORE_SBTOPCI2, value);
3110 if (bcm->current_core->rev < 5) {
3111 value = bcm43xx_read32(bcm, BCM43xx_CIR_SBIMCONFIGLOW);
3112 value |= (2 << BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_SHIFT)
3113 & BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_MASK;
3114 value |= (3 << BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_SHIFT)
3115 & BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_MASK;
3116 bcm43xx_write32(bcm, BCM43xx_CIR_SBIMCONFIGLOW, value);
3117 err = bcm43xx_pcicore_commit_settings(bcm);
3119 } else if (bcm->current_core->rev >= 11) {
3120 value = bcm43xx_read32(bcm, BCM43xx_PCICORE_SBTOPCI2);
3121 value |= BCM43xx_SBTOPCI2_MEMREAD_MULTI;
3122 bcm43xx_write32(bcm, BCM43xx_PCICORE_SBTOPCI2, value);
3125 if (bcm->current_core->rev == 0 || bcm->current_core->rev == 1) {
3126 value = bcm43xx_pcie_reg_read(bcm, BCM43xx_PCIE_TLP_WORKAROUND);
3128 bcm43xx_pcie_reg_write(bcm, BCM43xx_PCIE_TLP_WORKAROUND,
3131 if (bcm->current_core->rev == 0) {
3132 bcm43xx_pcie_mdio_write(bcm, BCM43xx_MDIO_SERDES_RX,
3133 BCM43xx_SERDES_RXTIMER, 0x8128);
3134 bcm43xx_pcie_mdio_write(bcm, BCM43xx_MDIO_SERDES_RX,
3135 BCM43xx_SERDES_CDR, 0x0100);
3136 bcm43xx_pcie_mdio_write(bcm, BCM43xx_MDIO_SERDES_RX,
3137 BCM43xx_SERDES_CDR_BW, 0x1466);
3138 } else if (bcm->current_core->rev == 1) {
3139 value = bcm43xx_pcie_reg_read(bcm, BCM43xx_PCIE_DLLP_LINKCTL);
3141 bcm43xx_pcie_reg_write(bcm, BCM43xx_PCIE_DLLP_LINKCTL,
3146 err = bcm43xx_switch_core(bcm, old_core);
3151 static void bcm43xx_periodic_every120sec(struct bcm43xx_private *bcm)
3153 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
3155 if (phy->type != BCM43xx_PHYTYPE_G || phy->rev < 2)
3158 bcm43xx_mac_suspend(bcm);
3159 bcm43xx_phy_lo_g_measure(bcm);
3160 bcm43xx_mac_enable(bcm);
3163 static void bcm43xx_periodic_every60sec(struct bcm43xx_private *bcm)
3165 bcm43xx_phy_lo_mark_all_unused(bcm);
3166 if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) {
3167 bcm43xx_mac_suspend(bcm);
3168 bcm43xx_calc_nrssi_slope(bcm);
3169 bcm43xx_mac_enable(bcm);
3173 static void bcm43xx_periodic_every30sec(struct bcm43xx_private *bcm)
3175 /* Update device statistics. */
3176 bcm43xx_calculate_link_quality(bcm);
3179 static void bcm43xx_periodic_every15sec(struct bcm43xx_private *bcm)
3181 bcm43xx_phy_xmitpower(bcm); //FIXME: unless scanning?
3182 //TODO for APHY (temperature?)
3185 static void bcm43xx_periodic_every1sec(struct bcm43xx_private *bcm)
3187 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
3188 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
3189 int radio_hw_enable;
3191 /* check if radio hardware enabled status changed */
3192 radio_hw_enable = bcm43xx_is_hw_radio_enabled(bcm);
3193 if (unlikely(bcm->radio_hw_enable != radio_hw_enable)) {
3194 bcm->radio_hw_enable = radio_hw_enable;
3195 dprintk(KERN_INFO PFX "Radio hardware status changed to %s\n",
3196 (radio_hw_enable == 0) ? "disabled" : "enabled");
3197 bcm43xx_leds_update(bcm, 0);
3199 if (phy->type == BCM43xx_PHYTYPE_G) {
3200 //TODO: update_aci_moving_average
3201 if (radio->aci_enable && radio->aci_wlan_automatic) {
3202 bcm43xx_mac_suspend(bcm);
3203 if (!radio->aci_enable && 1 /*TODO: not scanning? */) {
3204 if (0 /*TODO: bunch of conditions*/) {
3205 bcm43xx_radio_set_interference_mitigation(bcm,
3206 BCM43xx_RADIO_INTERFMODE_MANUALWLAN);
3208 } else if (1/*TODO*/) {
3210 if ((aci_average > 1000) && !(bcm43xx_radio_aci_scan(bcm))) {
3211 bcm43xx_radio_set_interference_mitigation(bcm,
3212 BCM43xx_RADIO_INTERFMODE_NONE);
3216 bcm43xx_mac_enable(bcm);
3217 } else if (radio->interfmode == BCM43xx_RADIO_INTERFMODE_NONWLAN &&
3219 //TODO: implement rev1 workaround
3224 static void do_periodic_work(struct bcm43xx_private *bcm)
3226 if (bcm->periodic_state % 120 == 0)
3227 bcm43xx_periodic_every120sec(bcm);
3228 if (bcm->periodic_state % 60 == 0)
3229 bcm43xx_periodic_every60sec(bcm);
3230 if (bcm->periodic_state % 30 == 0)
3231 bcm43xx_periodic_every30sec(bcm);
3232 if (bcm->periodic_state % 15 == 0)
3233 bcm43xx_periodic_every15sec(bcm);
3234 bcm43xx_periodic_every1sec(bcm);
3236 schedule_delayed_work(&bcm->periodic_work, HZ);
3239 static void bcm43xx_periodic_work_handler(struct work_struct *work)
3241 struct bcm43xx_private *bcm =
3242 container_of(work, struct bcm43xx_private, periodic_work.work);
3243 struct net_device *net_dev = bcm->net_dev;
3244 unsigned long flags;
3246 unsigned long orig_trans_start = 0;
3248 mutex_lock(&bcm->mutex);
3249 if (unlikely(bcm->periodic_state % 60 == 0)) {
3250 /* Periodic work will take a long time, so we want it to
3254 netif_tx_lock_bh(net_dev);
3255 /* We must fake a started transmission here, as we are going to
3256 * disable TX. If we wouldn't fake a TX, it would be possible to
3257 * trigger the netdev watchdog, if the last real TX is already
3258 * some time on the past (slightly less than 5secs)
3260 orig_trans_start = net_dev->trans_start;
3261 net_dev->trans_start = jiffies;
3262 netif_stop_queue(net_dev);
3263 netif_tx_unlock_bh(net_dev);
3265 spin_lock_irqsave(&bcm->irq_lock, flags);
3266 bcm43xx_mac_suspend(bcm);
3267 if (bcm43xx_using_pio(bcm))
3268 bcm43xx_pio_freeze_txqueues(bcm);
3269 savedirqs = bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
3270 spin_unlock_irqrestore(&bcm->irq_lock, flags);
3271 bcm43xx_synchronize_irq(bcm);
3273 /* Periodic work should take short time, so we want low
3276 spin_lock_irqsave(&bcm->irq_lock, flags);
3279 do_periodic_work(bcm);
3281 if (unlikely(bcm->periodic_state % 60 == 0)) {
3282 spin_lock_irqsave(&bcm->irq_lock, flags);
3283 tasklet_enable(&bcm->isr_tasklet);
3284 bcm43xx_interrupt_enable(bcm, savedirqs);
3285 if (bcm43xx_using_pio(bcm))
3286 bcm43xx_pio_thaw_txqueues(bcm);
3287 bcm43xx_mac_enable(bcm);
3288 netif_wake_queue(bcm->net_dev);
3289 net_dev->trans_start = orig_trans_start;
3292 bcm->periodic_state++;
3293 spin_unlock_irqrestore(&bcm->irq_lock, flags);
3294 mutex_unlock(&bcm->mutex);
3297 void bcm43xx_periodic_tasks_delete(struct bcm43xx_private *bcm)
3299 cancel_rearming_delayed_work(&bcm->periodic_work);
3302 void bcm43xx_periodic_tasks_setup(struct bcm43xx_private *bcm)
3304 struct delayed_work *work = &bcm->periodic_work;
3306 assert(bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED);
3307 INIT_DELAYED_WORK(work, bcm43xx_periodic_work_handler);
3308 schedule_delayed_work(work, 0);
3311 static void bcm43xx_security_init(struct bcm43xx_private *bcm)
3313 bcm->security_offset = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED,
3315 bcm43xx_clear_keys(bcm);
3318 static int bcm43xx_rng_read(struct hwrng *rng, u32 *data)
3320 struct bcm43xx_private *bcm = (struct bcm43xx_private *)rng->priv;
3321 unsigned long flags;
3323 spin_lock_irqsave(&(bcm)->irq_lock, flags);
3324 *data = bcm43xx_read16(bcm, BCM43xx_MMIO_RNG);
3325 spin_unlock_irqrestore(&(bcm)->irq_lock, flags);
3327 return (sizeof(u16));
3330 static void bcm43xx_rng_exit(struct bcm43xx_private *bcm)
3332 hwrng_unregister(&bcm->rng);
3335 static int bcm43xx_rng_init(struct bcm43xx_private *bcm)
3339 snprintf(bcm->rng_name, ARRAY_SIZE(bcm->rng_name),
3340 "%s_%s", KBUILD_MODNAME, bcm->net_dev->name);
3341 bcm->rng.name = bcm->rng_name;
3342 bcm->rng.data_read = bcm43xx_rng_read;
3343 bcm->rng.priv = (unsigned long)bcm;
3344 err = hwrng_register(&bcm->rng);
3346 printk(KERN_ERR PFX "RNG init failed (%d)\n", err);
3351 static int bcm43xx_shutdown_all_wireless_cores(struct bcm43xx_private *bcm)
3355 struct bcm43xx_coreinfo *core;
3357 bcm43xx_set_status(bcm, BCM43xx_STAT_SHUTTINGDOWN);
3358 for (i = 0; i < bcm->nr_80211_available; i++) {
3359 core = &(bcm->core_80211[i]);
3360 assert(core->available);
3361 if (!core->initialized)
3363 err = bcm43xx_switch_core(bcm, core);
3365 dprintk(KERN_ERR PFX "shutdown_all_wireless_cores "
3366 "switch_core failed (%d)\n", err);
3370 bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
3371 bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON); /* dummy read */
3372 bcm43xx_wireless_core_cleanup(bcm);
3373 if (core == bcm->active_80211_core)
3374 bcm->active_80211_core = NULL;
3376 free_irq(bcm->irq, bcm);
3377 bcm43xx_set_status(bcm, BCM43xx_STAT_UNINIT);
3382 /* This is the opposite of bcm43xx_init_board() */
3383 static void bcm43xx_free_board(struct bcm43xx_private *bcm)
3385 bcm43xx_rng_exit(bcm);
3386 bcm43xx_sysfs_unregister(bcm);
3387 bcm43xx_periodic_tasks_delete(bcm);
3389 mutex_lock(&(bcm)->mutex);
3390 bcm43xx_shutdown_all_wireless_cores(bcm);
3391 bcm43xx_pctl_set_crystal(bcm, 0);
3392 mutex_unlock(&(bcm)->mutex);
3395 static void prepare_phydata_for_init(struct bcm43xx_phyinfo *phy)
3397 phy->antenna_diversity = 0xFFFF;
3398 memset(phy->minlowsig, 0xFF, sizeof(phy->minlowsig));
3399 memset(phy->minlowsigpos, 0, sizeof(phy->minlowsigpos));
3402 phy->calibrated = 0;
3405 if (phy->_lo_pairs) {
3406 memset(phy->_lo_pairs, 0,
3407 sizeof(struct bcm43xx_lopair) * BCM43xx_LO_COUNT);
3409 memset(phy->loopback_gain, 0, sizeof(phy->loopback_gain));
3412 static void prepare_radiodata_for_init(struct bcm43xx_private *bcm,
3413 struct bcm43xx_radioinfo *radio)
3417 /* Set default attenuation values. */
3418 radio->baseband_atten = bcm43xx_default_baseband_attenuation(bcm);
3419 radio->radio_atten = bcm43xx_default_radio_attenuation(bcm);
3420 radio->txctl1 = bcm43xx_default_txctl1(bcm);
3421 radio->txctl2 = 0xFFFF;
3422 radio->txpwr_offset = 0;
3425 radio->nrssislope = 0;
3426 for (i = 0; i < ARRAY_SIZE(radio->nrssi); i++)
3427 radio->nrssi[i] = -1000;
3428 for (i = 0; i < ARRAY_SIZE(radio->nrssi_lt); i++)
3429 radio->nrssi_lt[i] = i;
3431 radio->lofcal = 0xFFFF;
3432 radio->initval = 0xFFFF;
3434 radio->aci_enable = 0;
3435 radio->aci_wlan_automatic = 0;
3436 radio->aci_hw_rssi = 0;
3439 static void prepare_priv_for_init(struct bcm43xx_private *bcm)
3442 struct bcm43xx_coreinfo *core;
3443 struct bcm43xx_coreinfo_80211 *wlext;
3445 assert(!bcm->active_80211_core);
3447 bcm43xx_set_status(bcm, BCM43xx_STAT_INITIALIZING);
3450 bcm->was_initialized = 0;
3451 bcm->reg124_set_0x4 = 0;
3454 memset(&bcm->stats, 0, sizeof(bcm->stats));
3456 /* Wireless core data */
3457 for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
3458 core = &(bcm->core_80211[i]);
3461 if (!core->available)
3463 assert(wlext == &(bcm->core_80211_ext[i]));
3465 prepare_phydata_for_init(&wlext->phy);
3466 prepare_radiodata_for_init(bcm, &wlext->radio);
3469 /* IRQ related flags */
3470 bcm->irq_reason = 0;
3471 memset(bcm->dma_reason, 0, sizeof(bcm->dma_reason));
3472 bcm->irq_savedstate = BCM43xx_IRQ_INITIAL;
3474 bcm->mac_suspended = 1;
3476 /* Noise calculation context */
3477 memset(&bcm->noisecalc, 0, sizeof(bcm->noisecalc));
3479 /* Periodic work context */
3480 bcm->periodic_state = 0;
3483 static int wireless_core_up(struct bcm43xx_private *bcm,
3488 if (!bcm43xx_core_enabled(bcm))
3489 bcm43xx_wireless_core_reset(bcm, 1);
3491 bcm43xx_wireless_core_mark_inactive(bcm);
3492 err = bcm43xx_wireless_core_init(bcm, active_wlcore);
3496 bcm43xx_radio_turn_off(bcm);
3501 /* Select and enable the "to be used" wireless core.
3502 * Locking: bcm->mutex must be aquired before calling this.
3503 * bcm->irq_lock must not be aquired.
3505 int bcm43xx_select_wireless_core(struct bcm43xx_private *bcm,
3509 struct bcm43xx_coreinfo *active_core = NULL;
3510 struct bcm43xx_coreinfo_80211 *active_wlext = NULL;
3511 struct bcm43xx_coreinfo *core;
3512 struct bcm43xx_coreinfo_80211 *wlext;
3513 int adjust_active_sbtmstatelow = 0;
3518 /* If no phytype is requested, select the first core. */
3519 assert(bcm->core_80211[0].available);
3520 wlext = bcm->core_80211[0].priv;
3521 phytype = wlext->phy.type;
3523 /* Find the requested core. */
3524 for (i = 0; i < bcm->nr_80211_available; i++) {
3525 core = &(bcm->core_80211[i]);
3527 if (wlext->phy.type == phytype) {
3529 active_wlext = wlext;
3534 return -ESRCH; /* No such PHYTYPE on this board. */
3536 if (bcm->active_80211_core) {
3537 /* We already selected a wl core in the past.
3538 * So first clean up everything.
3540 dprintk(KERN_INFO PFX "select_wireless_core: cleanup\n");
3541 ieee80211softmac_stop(bcm->net_dev);
3542 bcm43xx_set_status(bcm, BCM43xx_STAT_INITIALIZED);
3543 err = bcm43xx_disable_interrupts_sync(bcm);
3545 tasklet_enable(&bcm->isr_tasklet);
3546 err = bcm43xx_shutdown_all_wireless_cores(bcm);
3549 /* Ok, everything down, continue to re-initialize. */
3550 bcm43xx_set_status(bcm, BCM43xx_STAT_INITIALIZING);
3553 /* Reset all data structures. */
3554 prepare_priv_for_init(bcm);
3556 err = bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_FAST);
3560 /* Mark all unused cores "inactive". */
3561 for (i = 0; i < bcm->nr_80211_available; i++) {
3562 core = &(bcm->core_80211[i]);
3565 if (core == active_core)
3567 err = bcm43xx_switch_core(bcm, core);
3569 dprintk(KERN_ERR PFX "Could not switch to inactive "
3570 "802.11 core (%d)\n", err);
3573 err = wireless_core_up(bcm, 0);
3575 dprintk(KERN_ERR PFX "core_up for inactive 802.11 core "
3576 "failed (%d)\n", err);
3579 adjust_active_sbtmstatelow = 1;
3582 /* Now initialize the active 802.11 core. */
3583 err = bcm43xx_switch_core(bcm, active_core);
3585 dprintk(KERN_ERR PFX "Could not switch to active "
3586 "802.11 core (%d)\n", err);
3589 if (adjust_active_sbtmstatelow &&
3590 active_wlext->phy.type == BCM43xx_PHYTYPE_G) {
3593 sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
3594 sbtmstatelow |= 0x20000000;
3595 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
3597 err = wireless_core_up(bcm, 1);
3599 dprintk(KERN_ERR PFX "core_up for active 802.11 core "
3600 "failed (%d)\n", err);
3603 err = bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_DYNAMIC);
3606 bcm->active_80211_core = active_core;
3608 bcm43xx_macfilter_clear(bcm, BCM43xx_MACFILTER_ASSOC);
3609 bcm43xx_macfilter_set(bcm, BCM43xx_MACFILTER_SELF, (u8 *)(bcm->net_dev->dev_addr));
3610 bcm43xx_security_init(bcm);
3611 drain_txstatus_queue(bcm);
3612 ieee80211softmac_start(bcm->net_dev);
3614 /* Let's go! Be careful after enabling the IRQs.
3615 * Don't switch cores, for example.
3617 bcm43xx_mac_enable(bcm);
3618 bcm43xx_set_status(bcm, BCM43xx_STAT_INITIALIZED);
3619 err = bcm43xx_initialize_irq(bcm);
3622 bcm43xx_interrupt_enable(bcm, bcm->irq_savedstate);
3624 dprintk(KERN_INFO PFX "Selected 802.11 core (phytype %d)\n",
3625 active_wlext->phy.type);
3630 bcm43xx_set_status(bcm, BCM43xx_STAT_UNINIT);
3631 bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_SLOW);
3635 static int bcm43xx_init_board(struct bcm43xx_private *bcm)
3639 mutex_lock(&(bcm)->mutex);
3641 tasklet_enable(&bcm->isr_tasklet);
3642 err = bcm43xx_pctl_set_crystal(bcm, 1);
3645 err = bcm43xx_pctl_init(bcm);
3647 goto err_crystal_off;
3648 err = bcm43xx_select_wireless_core(bcm, -1);
3650 goto err_crystal_off;
3651 err = bcm43xx_sysfs_register(bcm);
3653 goto err_wlshutdown;
3654 err = bcm43xx_rng_init(bcm);
3656 goto err_sysfs_unreg;
3657 bcm43xx_periodic_tasks_setup(bcm);
3659 /*FIXME: This should be handled by softmac instead. */
3660 schedule_delayed_work(&bcm->softmac->associnfo.work, 0);
3663 mutex_unlock(&(bcm)->mutex);
3668 bcm43xx_sysfs_unregister(bcm);
3670 bcm43xx_shutdown_all_wireless_cores(bcm);
3672 bcm43xx_pctl_set_crystal(bcm, 0);
3674 tasklet_disable(&bcm->isr_tasklet);
3678 static void bcm43xx_detach_board(struct bcm43xx_private *bcm)
3680 struct pci_dev *pci_dev = bcm->pci_dev;
3683 bcm43xx_chipset_detach(bcm);
3684 /* Do _not_ access the chip, after it is detached. */
3685 pci_iounmap(pci_dev, bcm->mmio_addr);
3686 pci_release_regions(pci_dev);
3687 pci_disable_device(pci_dev);
3689 /* Free allocated structures/fields */
3690 for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
3691 kfree(bcm->core_80211_ext[i].phy._lo_pairs);
3692 if (bcm->core_80211_ext[i].phy.dyn_tssi_tbl)
3693 kfree(bcm->core_80211_ext[i].phy.tssi2dbm);
3697 static int bcm43xx_read_phyinfo(struct bcm43xx_private *bcm)
3699 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
3707 value = bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_VER);
3709 phy_version = (value & 0xF000) >> 12;
3710 phy_type = (value & 0x0F00) >> 8;
3711 phy_rev = (value & 0x000F);
3713 dprintk(KERN_INFO PFX "Detected PHY: Version: %x, Type %x, Revision %x\n",
3714 phy_version, phy_type, phy_rev);
3717 case BCM43xx_PHYTYPE_A:
3720 /*FIXME: We need to switch the ieee->modulation, etc.. flags,
3721 * if we switch 80211 cores after init is done.
3722 * As we do not implement on the fly switching between
3723 * wireless cores, I will leave this as a future task.
3725 bcm->ieee->modulation = IEEE80211_OFDM_MODULATION;
3726 bcm->ieee->mode = IEEE_A;
3727 bcm->ieee->freq_band = IEEE80211_52GHZ_BAND |
3728 IEEE80211_24GHZ_BAND;
3730 case BCM43xx_PHYTYPE_B:
3731 if (phy_rev != 2 && phy_rev != 4 && phy_rev != 6 && phy_rev != 7)
3733 bcm->ieee->modulation = IEEE80211_CCK_MODULATION;
3734 bcm->ieee->mode = IEEE_B;
3735 bcm->ieee->freq_band = IEEE80211_24GHZ_BAND;
3737 case BCM43xx_PHYTYPE_G:
3740 bcm->ieee->modulation = IEEE80211_OFDM_MODULATION |
3741 IEEE80211_CCK_MODULATION;
3742 bcm->ieee->mode = IEEE_G;
3743 bcm->ieee->freq_band = IEEE80211_24GHZ_BAND;
3746 printk(KERN_ERR PFX "Error: Unknown PHY Type %x\n",
3750 bcm->ieee->perfect_rssi = RX_RSSI_MAX;
3751 bcm->ieee->worst_rssi = 0;
3753 printk(KERN_WARNING PFX "Invalid PHY Revision %x\n",
3757 phy->version = phy_version;
3758 phy->type = phy_type;
3760 if ((phy_type == BCM43xx_PHYTYPE_B) || (phy_type == BCM43xx_PHYTYPE_G)) {
3761 p = kzalloc(sizeof(struct bcm43xx_lopair) * BCM43xx_LO_COUNT,
3771 static int bcm43xx_attach_board(struct bcm43xx_private *bcm)
3773 struct pci_dev *pci_dev = bcm->pci_dev;
3774 struct net_device *net_dev = bcm->net_dev;
3779 err = pci_enable_device(pci_dev);
3781 printk(KERN_ERR PFX "pci_enable_device() failed\n");
3784 err = pci_request_regions(pci_dev, KBUILD_MODNAME);
3786 printk(KERN_ERR PFX "pci_request_regions() failed\n");
3787 goto err_pci_disable;
3789 /* enable PCI bus-mastering */
3790 pci_set_master(pci_dev);
3791 bcm->mmio_addr = pci_iomap(pci_dev, 0, ~0UL);
3792 if (!bcm->mmio_addr) {
3793 printk(KERN_ERR PFX "pci_iomap() failed\n");
3795 goto err_pci_release;
3797 net_dev->base_addr = (unsigned long)bcm->mmio_addr;
3799 bcm43xx_pci_read_config16(bcm, PCI_SUBSYSTEM_VENDOR_ID,
3800 &bcm->board_vendor);
3801 bcm43xx_pci_read_config16(bcm, PCI_SUBSYSTEM_ID,
3803 bcm43xx_pci_read_config16(bcm, PCI_REVISION_ID,
3804 &bcm->board_revision);
3806 err = bcm43xx_chipset_attach(bcm);
3809 err = bcm43xx_pctl_init(bcm);
3811 goto err_chipset_detach;
3812 err = bcm43xx_probe_cores(bcm);
3814 goto err_chipset_detach;
3816 /* Attach all IO cores to the backplane. */
3818 for (i = 0; i < bcm->nr_80211_available; i++)
3819 coremask |= (1 << bcm->core_80211[i].index);
3820 //FIXME: Also attach some non80211 cores?
3821 err = bcm43xx_setup_backplane_pci_connection(bcm, coremask);
3823 printk(KERN_ERR PFX "Backplane->PCI connection failed!\n");
3824 goto err_chipset_detach;
3827 err = bcm43xx_sprom_extract(bcm);
3829 goto err_chipset_detach;
3830 err = bcm43xx_leds_init(bcm);
3832 goto err_chipset_detach;
3834 for (i = 0; i < bcm->nr_80211_available; i++) {
3835 err = bcm43xx_switch_core(bcm, &bcm->core_80211[i]);
3836 assert(err != -ENODEV);
3838 goto err_80211_unwind;
3840 /* Enable the selected wireless core.
3841 * Connect PHY only on the first core.
3843 bcm43xx_wireless_core_reset(bcm, (i == 0));
3845 err = bcm43xx_read_phyinfo(bcm);
3846 if (err && (i == 0))
3847 goto err_80211_unwind;
3849 err = bcm43xx_read_radioinfo(bcm);
3850 if (err && (i == 0))
3851 goto err_80211_unwind;
3853 err = bcm43xx_validate_chip(bcm);
3854 if (err && (i == 0))
3855 goto err_80211_unwind;
3857 bcm43xx_radio_turn_off(bcm);
3858 err = bcm43xx_phy_init_tssi2dbm_table(bcm);
3860 goto err_80211_unwind;
3861 bcm43xx_wireless_core_disable(bcm);
3863 err = bcm43xx_geo_init(bcm);
3865 goto err_80211_unwind;
3866 bcm43xx_pctl_set_crystal(bcm, 0);
3868 /* Set the MAC address in the networking subsystem */
3869 if (is_valid_ether_addr(bcm->sprom.et1macaddr))
3870 memcpy(bcm->net_dev->dev_addr, bcm->sprom.et1macaddr, 6);
3872 memcpy(bcm->net_dev->dev_addr, bcm->sprom.il0macaddr, 6);
3874 snprintf(bcm->nick, IW_ESSID_MAX_SIZE,
3875 "Broadcom %04X", bcm->chip_id);
3882 for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
3883 kfree(bcm->core_80211_ext[i].phy._lo_pairs);
3884 if (bcm->core_80211_ext[i].phy.dyn_tssi_tbl)
3885 kfree(bcm->core_80211_ext[i].phy.tssi2dbm);
3888 bcm43xx_chipset_detach(bcm);
3890 pci_iounmap(pci_dev, bcm->mmio_addr);
3892 pci_release_regions(pci_dev);
3894 pci_disable_device(pci_dev);
3898 /* Do the Hardware IO operations to send the txb */
3899 static inline int bcm43xx_tx(struct bcm43xx_private *bcm,
3900 struct ieee80211_txb *txb)
3904 if (bcm43xx_using_pio(bcm))
3905 err = bcm43xx_pio_tx(bcm, txb);
3907 err = bcm43xx_dma_tx(bcm, txb);
3908 bcm->net_dev->trans_start = jiffies;
3913 static void bcm43xx_ieee80211_set_chan(struct net_device *net_dev,
3916 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
3917 struct bcm43xx_radioinfo *radio;
3918 unsigned long flags;
3920 mutex_lock(&bcm->mutex);
3921 spin_lock_irqsave(&bcm->irq_lock, flags);
3922 if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED) {
3923 bcm43xx_mac_suspend(bcm);
3924 bcm43xx_radio_selectchannel(bcm, channel, 0);
3925 bcm43xx_mac_enable(bcm);
3927 radio = bcm43xx_current_radio(bcm);
3928 radio->initial_channel = channel;
3930 spin_unlock_irqrestore(&bcm->irq_lock, flags);
3931 mutex_unlock(&bcm->mutex);
3934 /* set_security() callback in struct ieee80211_device */
3935 static void bcm43xx_ieee80211_set_security(struct net_device *net_dev,
3936 struct ieee80211_security *sec)
3938 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
3939 struct ieee80211_security *secinfo = &bcm->ieee->sec;
3940 unsigned long flags;
3943 dprintk(KERN_INFO PFX "set security called");
3945 mutex_lock(&bcm->mutex);
3946 spin_lock_irqsave(&bcm->irq_lock, flags);
3948 for (keyidx = 0; keyidx<WEP_KEYS; keyidx++)
3949 if (sec->flags & (1<<keyidx)) {
3950 secinfo->encode_alg[keyidx] = sec->encode_alg[keyidx];
3951 secinfo->key_sizes[keyidx] = sec->key_sizes[keyidx];
3952 memcpy(secinfo->keys[keyidx], sec->keys[keyidx], SCM_KEY_LEN);
3955 if (sec->flags & SEC_ACTIVE_KEY) {
3956 secinfo->active_key = sec->active_key;
3957 dprintk(", .active_key = %d", sec->active_key);
3959 if (sec->flags & SEC_UNICAST_GROUP) {
3960 secinfo->unicast_uses_group = sec->unicast_uses_group;
3961 dprintk(", .unicast_uses_group = %d", sec->unicast_uses_group);
3963 if (sec->flags & SEC_LEVEL) {
3964 secinfo->level = sec->level;
3965 dprintk(", .level = %d", sec->level);
3967 if (sec->flags & SEC_ENABLED) {
3968 secinfo->enabled = sec->enabled;
3969 dprintk(", .enabled = %d", sec->enabled);
3971 if (sec->flags & SEC_ENCRYPT) {
3972 secinfo->encrypt = sec->encrypt;
3973 dprintk(", .encrypt = %d", sec->encrypt);
3975 if (sec->flags & SEC_AUTH_MODE) {
3976 secinfo->auth_mode = sec->auth_mode;
3977 dprintk(", .auth_mode = %d", sec->auth_mode);
3980 if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED &&
3981 !bcm->ieee->host_encrypt) {
3982 if (secinfo->enabled) {
3983 /* upload WEP keys to hardware */
3984 char null_address[6] = { 0 };
3986 for (keyidx = 0; keyidx<WEP_KEYS; keyidx++) {
3987 if (!(sec->flags & (1<<keyidx)))
3989 switch (sec->encode_alg[keyidx]) {
3990 case SEC_ALG_NONE: algorithm = BCM43xx_SEC_ALGO_NONE; break;
3992 algorithm = BCM43xx_SEC_ALGO_WEP;
3993 if (secinfo->key_sizes[keyidx] == 13)
3994 algorithm = BCM43xx_SEC_ALGO_WEP104;
3998 algorithm = BCM43xx_SEC_ALGO_TKIP;
4002 algorithm = BCM43xx_SEC_ALGO_AES;
4008 bcm43xx_key_write(bcm, keyidx, algorithm, sec->keys[keyidx], secinfo->key_sizes[keyidx], &null_address[0]);
4009 bcm->key[keyidx].enabled = 1;
4010 bcm->key[keyidx].algorithm = algorithm;
4013 bcm43xx_clear_keys(bcm);
4015 spin_unlock_irqrestore(&bcm->irq_lock, flags);
4016 mutex_unlock(&bcm->mutex);
4019 /* hard_start_xmit() callback in struct ieee80211_device */
4020 static int bcm43xx_ieee80211_hard_start_xmit(struct ieee80211_txb *txb,
4021 struct net_device *net_dev,
4024 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
4026 unsigned long flags;
4028 spin_lock_irqsave(&bcm->irq_lock, flags);
4029 if (likely(bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED))
4030 err = bcm43xx_tx(bcm, txb);
4031 spin_unlock_irqrestore(&bcm->irq_lock, flags);
4034 return NETDEV_TX_BUSY;
4035 return NETDEV_TX_OK;
4038 static void bcm43xx_net_tx_timeout(struct net_device *net_dev)
4040 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
4041 unsigned long flags;
4043 spin_lock_irqsave(&bcm->irq_lock, flags);
4044 bcm43xx_controller_restart(bcm, "TX timeout");
4045 spin_unlock_irqrestore(&bcm->irq_lock, flags);
4048 #ifdef CONFIG_NET_POLL_CONTROLLER
4049 static void bcm43xx_net_poll_controller(struct net_device *net_dev)
4051 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
4052 unsigned long flags;
4054 local_irq_save(flags);
4055 if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED)
4056 bcm43xx_interrupt_handler(bcm->irq, bcm);
4057 local_irq_restore(flags);
4059 #endif /* CONFIG_NET_POLL_CONTROLLER */
4061 static int bcm43xx_net_open(struct net_device *net_dev)
4063 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
4065 return bcm43xx_init_board(bcm);
4068 static int bcm43xx_net_stop(struct net_device *net_dev)
4070 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
4073 ieee80211softmac_stop(net_dev);
4074 err = bcm43xx_disable_interrupts_sync(bcm);
4076 bcm43xx_free_board(bcm);
4077 flush_scheduled_work();
4082 static int bcm43xx_init_private(struct bcm43xx_private *bcm,
4083 struct net_device *net_dev,
4084 struct pci_dev *pci_dev)
4086 bcm43xx_set_status(bcm, BCM43xx_STAT_UNINIT);
4087 bcm->ieee = netdev_priv(net_dev);
4088 bcm->softmac = ieee80211_priv(net_dev);
4089 bcm->softmac->set_channel = bcm43xx_ieee80211_set_chan;
4091 bcm->irq_savedstate = BCM43xx_IRQ_INITIAL;
4092 bcm->mac_suspended = 1;
4093 bcm->pci_dev = pci_dev;
4094 bcm->net_dev = net_dev;
4095 bcm->bad_frames_preempt = modparam_bad_frames_preempt;
4096 spin_lock_init(&bcm->irq_lock);
4097 spin_lock_init(&bcm->leds_lock);
4098 mutex_init(&bcm->mutex);
4099 tasklet_init(&bcm->isr_tasklet,
4100 (void (*)(unsigned long))bcm43xx_interrupt_tasklet,
4101 (unsigned long)bcm);
4102 tasklet_disable_nosync(&bcm->isr_tasklet);
4104 bcm->__using_pio = 1;
4105 bcm->rts_threshold = BCM43xx_DEFAULT_RTS_THRESHOLD;
4107 /* default to sw encryption for now */
4108 bcm->ieee->host_build_iv = 0;
4109 bcm->ieee->host_encrypt = 1;
4110 bcm->ieee->host_decrypt = 1;
4112 bcm->ieee->iw_mode = BCM43xx_INITIAL_IWMODE;
4113 bcm->ieee->tx_headroom = sizeof(struct bcm43xx_txhdr);
4114 bcm->ieee->set_security = bcm43xx_ieee80211_set_security;
4115 bcm->ieee->hard_start_xmit = bcm43xx_ieee80211_hard_start_xmit;
4120 static int __devinit bcm43xx_init_one(struct pci_dev *pdev,
4121 const struct pci_device_id *ent)
4123 struct net_device *net_dev;
4124 struct bcm43xx_private *bcm;
4127 #ifdef CONFIG_BCM947XX
4128 if ((pdev->bus->number == 0) && (pdev->device != 0x0800))
4132 #ifdef DEBUG_SINGLE_DEVICE_ONLY
4133 if (strcmp(pci_name(pdev), DEBUG_SINGLE_DEVICE_ONLY))
4137 net_dev = alloc_ieee80211softmac(sizeof(*bcm));
4140 "could not allocate ieee80211 device %s\n",
4145 /* initialize the net_device struct */
4146 SET_MODULE_OWNER(net_dev);
4147 SET_NETDEV_DEV(net_dev, &pdev->dev);
4149 net_dev->open = bcm43xx_net_open;
4150 net_dev->stop = bcm43xx_net_stop;
4151 net_dev->tx_timeout = bcm43xx_net_tx_timeout;
4152 #ifdef CONFIG_NET_POLL_CONTROLLER
4153 net_dev->poll_controller = bcm43xx_net_poll_controller;
4155 net_dev->wireless_handlers = &bcm43xx_wx_handlers_def;
4156 net_dev->irq = pdev->irq;
4157 SET_ETHTOOL_OPS(net_dev, &bcm43xx_ethtool_ops);
4159 /* initialize the bcm43xx_private struct */
4160 bcm = bcm43xx_priv(net_dev);
4161 memset(bcm, 0, sizeof(*bcm));
4162 err = bcm43xx_init_private(bcm, net_dev, pdev);
4164 goto err_free_netdev;
4166 pci_set_drvdata(pdev, net_dev);
4168 err = bcm43xx_attach_board(bcm);
4170 goto err_free_netdev;
4172 err = register_netdev(net_dev);
4174 printk(KERN_ERR PFX "Cannot register net device, "
4177 goto err_detach_board;
4180 bcm43xx_debugfs_add_device(bcm);
4187 bcm43xx_detach_board(bcm);
4189 free_ieee80211softmac(net_dev);
4193 static void __devexit bcm43xx_remove_one(struct pci_dev *pdev)
4195 struct net_device *net_dev = pci_get_drvdata(pdev);
4196 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
4198 bcm43xx_debugfs_remove_device(bcm);
4199 unregister_netdev(net_dev);
4200 bcm43xx_detach_board(bcm);
4201 free_ieee80211softmac(net_dev);
4204 /* Hard-reset the chip. Do not call this directly.
4205 * Use bcm43xx_controller_restart()
4207 static void bcm43xx_chip_reset(struct work_struct *work)
4209 struct bcm43xx_private *bcm =
4210 container_of(work, struct bcm43xx_private, restart_work);
4211 struct bcm43xx_phyinfo *phy;
4214 mutex_lock(&(bcm)->mutex);
4215 if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED) {
4216 bcm43xx_periodic_tasks_delete(bcm);
4217 phy = bcm43xx_current_phy(bcm);
4218 err = bcm43xx_select_wireless_core(bcm, phy->type);
4220 bcm43xx_periodic_tasks_setup(bcm);
4222 mutex_unlock(&(bcm)->mutex);
4224 printk(KERN_ERR PFX "Controller restart%s\n",
4225 (err == 0) ? "ed" : " failed");
4228 /* Hard-reset the chip.
4229 * This can be called from interrupt or process context.
4230 * bcm->irq_lock must be locked.
4232 void bcm43xx_controller_restart(struct bcm43xx_private *bcm, const char *reason)
4234 if (bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED)
4236 printk(KERN_ERR PFX "Controller RESET (%s) ...\n", reason);
4237 INIT_WORK(&bcm->restart_work, bcm43xx_chip_reset);
4238 schedule_work(&bcm->restart_work);
4243 static int bcm43xx_suspend(struct pci_dev *pdev, pm_message_t state)
4245 struct net_device *net_dev = pci_get_drvdata(pdev);
4246 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
4249 dprintk(KERN_INFO PFX "Suspending...\n");
4251 netif_device_detach(net_dev);
4252 bcm->was_initialized = 0;
4253 if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED) {
4254 bcm->was_initialized = 1;
4255 ieee80211softmac_stop(net_dev);
4256 err = bcm43xx_disable_interrupts_sync(bcm);
4257 if (unlikely(err)) {
4258 dprintk(KERN_ERR PFX "Suspend failed.\n");
4261 bcm->firmware_norelease = 1;
4262 bcm43xx_free_board(bcm);
4263 bcm->firmware_norelease = 0;
4265 bcm43xx_chipset_detach(bcm);
4267 pci_save_state(pdev);
4268 pci_disable_device(pdev);
4269 pci_set_power_state(pdev, pci_choose_state(pdev, state));
4271 dprintk(KERN_INFO PFX "Device suspended.\n");
4276 static int bcm43xx_resume(struct pci_dev *pdev)
4278 struct net_device *net_dev = pci_get_drvdata(pdev);
4279 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
4282 dprintk(KERN_INFO PFX "Resuming...\n");
4284 pci_set_power_state(pdev, 0);
4285 err = pci_enable_device(pdev);
4287 printk(KERN_ERR PFX "Failure with pci_enable_device!\n");
4290 pci_restore_state(pdev);
4292 bcm43xx_chipset_attach(bcm);
4293 if (bcm->was_initialized)
4294 err = bcm43xx_init_board(bcm);
4296 printk(KERN_ERR PFX "Resume failed!\n");
4299 netif_device_attach(net_dev);
4301 dprintk(KERN_INFO PFX "Device resumed.\n");
4306 #endif /* CONFIG_PM */
4308 static struct pci_driver bcm43xx_pci_driver = {
4309 .name = KBUILD_MODNAME,
4310 .id_table = bcm43xx_pci_tbl,
4311 .probe = bcm43xx_init_one,
4312 .remove = __devexit_p(bcm43xx_remove_one),
4314 .suspend = bcm43xx_suspend,
4315 .resume = bcm43xx_resume,
4316 #endif /* CONFIG_PM */
4319 static int __init bcm43xx_init(void)
4321 printk(KERN_INFO KBUILD_MODNAME " driver\n");
4322 bcm43xx_debugfs_init();
4323 return pci_register_driver(&bcm43xx_pci_driver);
4326 static void __exit bcm43xx_exit(void)
4328 pci_unregister_driver(&bcm43xx_pci_driver);
4329 bcm43xx_debugfs_exit();
4332 module_init(bcm43xx_init)
4333 module_exit(bcm43xx_exit)