3 Broadcom BCM43xx wireless driver
5 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>
6 Copyright (c) 2005 Stefano Brivio <st3@riseup.net>
7 Copyright (c) 2005, 2006 Michael Buesch <mb@bu3sch.de>
8 Copyright (c) 2005 Danny van Dyk <kugelfang@gentoo.org>
9 Copyright (c) 2005 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>
44 #include "bcm43xx_main.h"
45 #include "bcm43xx_debugfs.h"
46 #include "bcm43xx_phy.h"
47 #include "bcm43xx_dma.h"
48 #include "bcm43xx_pio.h"
49 #include "bcm43xx_power.h"
50 #include "bcm43xx_sysfs.h"
51 #include "bcm43xx_xmit.h"
52 #include "bcm43xx_sysfs.h"
53 #include "bcm43xx_lo.h"
54 #include "bcm43xx_pcmcia.h"
57 MODULE_DESCRIPTION("Broadcom BCM43xx wireless driver");
58 MODULE_AUTHOR("Martin Langer");
59 MODULE_AUTHOR("Stefano Brivio");
60 MODULE_AUTHOR("Michael Buesch");
61 MODULE_LICENSE("GPL");
64 extern char *nvram_get(char *name
);
67 #if defined(CONFIG_BCM43XX_MAC80211_DMA) && defined(CONFIG_BCM43XX_MAC80211_PIO)
68 static int modparam_pio
;
69 module_param_named(pio
, modparam_pio
, int, 0444);
70 MODULE_PARM_DESC(pio
, "enable(1) / disable(0) PIO mode");
71 #elif defined(CONFIG_BCM43XX_MAC80211_DMA)
72 # define modparam_pio 0
73 #elif defined(CONFIG_BCM43XX_MAC80211_PIO)
74 # define modparam_pio 1
77 static int modparam_bad_frames_preempt
;
78 module_param_named(bad_frames_preempt
, modparam_bad_frames_preempt
, int, 0444);
79 MODULE_PARM_DESC(bad_frames_preempt
, "enable(1) / disable(0) Bad Frames Preemption");
81 static int modparam_short_retry
= BCM43xx_DEFAULT_SHORT_RETRY_LIMIT
;
82 module_param_named(short_retry
, modparam_short_retry
, int, 0444);
83 MODULE_PARM_DESC(short_retry
, "Short-Retry-Limit (0 - 15)");
85 static int modparam_long_retry
= BCM43xx_DEFAULT_LONG_RETRY_LIMIT
;
86 module_param_named(long_retry
, modparam_long_retry
, int, 0444);
87 MODULE_PARM_DESC(long_retry
, "Long-Retry-Limit (0 - 15)");
89 static int modparam_noleds
;
90 module_param_named(noleds
, modparam_noleds
, int, 0444);
91 MODULE_PARM_DESC(noleds
, "Turn off all LED activity");
93 static char modparam_fwpostfix
[16];
94 module_param_string(fwpostfix
, modparam_fwpostfix
, 16, 0444);
95 MODULE_PARM_DESC(fwpostfix
, "Postfix for the .fw files to load.");
97 static int modparam_mon_keep_bad
;
98 module_param_named(mon_keep_bad
, modparam_mon_keep_bad
, int, 0444);
99 MODULE_PARM_DESC(mon_keep_bad
, "Keep bad frames in monitor mode");
101 static int modparam_mon_keep_badplcp
;
102 module_param_named(mon_keep_badplcp
, modparam_mon_keep_bad
, int, 0444);
103 MODULE_PARM_DESC(mon_keep_badplcp
, "Keep frames with bad PLCP in monitor mode");
106 static const struct ssb_device_id bcm43xx_ssb_tbl
[] = {
107 SSB_DEVICE(SSB_VENDOR_BROADCOM
, SSB_DEV_80211
, SSB_ANY_REV
),
110 MODULE_DEVICE_TABLE(ssb
, bcm43xx_ssb_tbl
);
113 /* Channel and ratetables are shared for all devices.
114 * They can't be const, because ieee80211 puts some precalculated
115 * data in there. This data is the same for all devices, so we don't
116 * get concurrency issues */
117 #define RATETAB_ENT(_rateid, _flags) \
119 .rate = BCM43xx_RATE_TO_BASE100KBPS(_rateid), \
124 static struct ieee80211_rate __bcm43xx_ratetable
[] = {
125 RATETAB_ENT(BCM43xx_CCK_RATE_1MB
, IEEE80211_RATE_CCK
),
126 RATETAB_ENT(BCM43xx_CCK_RATE_2MB
, IEEE80211_RATE_CCK_2
),
127 RATETAB_ENT(BCM43xx_CCK_RATE_5MB
, IEEE80211_RATE_CCK_2
),
128 RATETAB_ENT(BCM43xx_CCK_RATE_11MB
, IEEE80211_RATE_CCK_2
),
129 RATETAB_ENT(BCM43xx_OFDM_RATE_6MB
, IEEE80211_RATE_OFDM
),
130 RATETAB_ENT(BCM43xx_OFDM_RATE_9MB
, IEEE80211_RATE_OFDM
),
131 RATETAB_ENT(BCM43xx_OFDM_RATE_12MB
, IEEE80211_RATE_OFDM
),
132 RATETAB_ENT(BCM43xx_OFDM_RATE_18MB
, IEEE80211_RATE_OFDM
),
133 RATETAB_ENT(BCM43xx_OFDM_RATE_24MB
, IEEE80211_RATE_OFDM
),
134 RATETAB_ENT(BCM43xx_OFDM_RATE_36MB
, IEEE80211_RATE_OFDM
),
135 RATETAB_ENT(BCM43xx_OFDM_RATE_48MB
, IEEE80211_RATE_OFDM
),
136 RATETAB_ENT(BCM43xx_OFDM_RATE_54MB
, IEEE80211_RATE_OFDM
),
138 #define bcm43xx_a_ratetable (__bcm43xx_ratetable + 4)
139 #define bcm43xx_a_ratetable_size 8
140 #define bcm43xx_b_ratetable (__bcm43xx_ratetable + 0)
141 #define bcm43xx_b_ratetable_size 4
142 #define bcm43xx_g_ratetable (__bcm43xx_ratetable + 0)
143 #define bcm43xx_g_ratetable_size 12
145 #define CHANTAB_ENT(_chanid, _freq) \
150 .flag = IEEE80211_CHAN_W_SCAN | \
151 IEEE80211_CHAN_W_ACTIVE_SCAN | \
152 IEEE80211_CHAN_W_IBSS, \
153 .power_level = 0xFF, \
154 .antenna_max = 0xFF, \
156 static struct ieee80211_channel bcm43xx_bg_chantable
[] = {
157 CHANTAB_ENT(1, 2412),
158 CHANTAB_ENT(2, 2417),
159 CHANTAB_ENT(3, 2422),
160 CHANTAB_ENT(4, 2427),
161 CHANTAB_ENT(5, 2432),
162 CHANTAB_ENT(6, 2437),
163 CHANTAB_ENT(7, 2442),
164 CHANTAB_ENT(8, 2447),
165 CHANTAB_ENT(9, 2452),
166 CHANTAB_ENT(10, 2457),
167 CHANTAB_ENT(11, 2462),
168 CHANTAB_ENT(12, 2467),
169 CHANTAB_ENT(13, 2472),
170 CHANTAB_ENT(14, 2484),
172 #define bcm43xx_bg_chantable_size ARRAY_SIZE(bcm43xx_bg_chantable)
173 static struct ieee80211_channel bcm43xx_a_chantable
[] = {
174 CHANTAB_ENT(36, 5180),
175 CHANTAB_ENT(40, 5200),
176 CHANTAB_ENT(44, 5220),
177 CHANTAB_ENT(48, 5240),
178 CHANTAB_ENT(52, 5260),
179 CHANTAB_ENT(56, 5280),
180 CHANTAB_ENT(60, 5300),
181 CHANTAB_ENT(64, 5320),
182 CHANTAB_ENT(149, 5745),
183 CHANTAB_ENT(153, 5765),
184 CHANTAB_ENT(157, 5785),
185 CHANTAB_ENT(161, 5805),
186 CHANTAB_ENT(165, 5825),
188 #define bcm43xx_a_chantable_size ARRAY_SIZE(bcm43xx_a_chantable)
191 static void bcm43xx_wireless_core_exit(struct bcm43xx_wldev
*dev
);
192 static int bcm43xx_wireless_core_init(struct bcm43xx_wldev
*dev
);
193 static void bcm43xx_wireless_core_stop(struct bcm43xx_wldev
*dev
);
194 static int bcm43xx_wireless_core_start(struct bcm43xx_wldev
*dev
);
197 static void bcm43xx_ram_write(struct bcm43xx_wldev
*dev
, u16 offset
, u32 val
)
201 assert(offset
% 4 == 0);
203 status
= bcm43xx_read32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
);
204 if (status
& BCM43xx_SBF_XFER_REG_BYTESWAP
)
207 bcm43xx_write32(dev
, BCM43xx_MMIO_RAM_CONTROL
, offset
);
209 bcm43xx_write32(dev
, BCM43xx_MMIO_RAM_DATA
, val
);
213 void bcm43xx_shm_control_word(struct bcm43xx_wldev
*dev
,
214 u16 routing
, u16 offset
)
218 /* "offset" is the WORD offset. */
223 bcm43xx_write32(dev
, BCM43xx_MMIO_SHM_CONTROL
, control
);
226 u32
bcm43xx_shm_read32(struct bcm43xx_wldev
*dev
,
227 u16 routing
, u16 offset
)
231 if (routing
== BCM43xx_SHM_SHARED
) {
232 assert((offset
& 0x0001) == 0);
233 if (offset
& 0x0003) {
234 /* Unaligned access */
235 bcm43xx_shm_control_word(dev
, routing
, offset
>> 2);
236 ret
= bcm43xx_read16(dev
,
237 BCM43xx_MMIO_SHM_DATA_UNALIGNED
);
239 bcm43xx_shm_control_word(dev
, routing
, (offset
>> 2) + 1);
240 ret
|= bcm43xx_read16(dev
,
241 BCM43xx_MMIO_SHM_DATA
);
247 bcm43xx_shm_control_word(dev
, routing
, offset
);
248 ret
= bcm43xx_read32(dev
, BCM43xx_MMIO_SHM_DATA
);
253 u16
bcm43xx_shm_read16(struct bcm43xx_wldev
*dev
,
254 u16 routing
, u16 offset
)
258 if (routing
== BCM43xx_SHM_SHARED
) {
259 assert((offset
& 0x0001) == 0);
260 if (offset
& 0x0003) {
261 /* Unaligned access */
262 bcm43xx_shm_control_word(dev
, routing
, offset
>> 2);
263 ret
= bcm43xx_read16(dev
,
264 BCM43xx_MMIO_SHM_DATA_UNALIGNED
);
270 bcm43xx_shm_control_word(dev
, routing
, offset
);
271 ret
= bcm43xx_read16(dev
, BCM43xx_MMIO_SHM_DATA
);
276 void bcm43xx_shm_write32(struct bcm43xx_wldev
*dev
,
277 u16 routing
, u16 offset
,
280 if (routing
== BCM43xx_SHM_SHARED
) {
281 assert((offset
& 0x0001) == 0);
282 if (offset
& 0x0003) {
283 /* Unaligned access */
284 bcm43xx_shm_control_word(dev
, routing
, offset
>> 2);
286 bcm43xx_write16(dev
, BCM43xx_MMIO_SHM_DATA_UNALIGNED
,
287 (value
>> 16) & 0xffff);
289 bcm43xx_shm_control_word(dev
, routing
, (offset
>> 2) + 1);
291 bcm43xx_write16(dev
, BCM43xx_MMIO_SHM_DATA
,
297 bcm43xx_shm_control_word(dev
, routing
, offset
);
299 bcm43xx_write32(dev
, BCM43xx_MMIO_SHM_DATA
, value
);
302 void bcm43xx_shm_write16(struct bcm43xx_wldev
*dev
,
303 u16 routing
, u16 offset
,
306 if (routing
== BCM43xx_SHM_SHARED
) {
307 assert((offset
& 0x0001) == 0);
308 if (offset
& 0x0003) {
309 /* Unaligned access */
310 bcm43xx_shm_control_word(dev
, routing
, offset
>> 2);
312 bcm43xx_write16(dev
, BCM43xx_MMIO_SHM_DATA_UNALIGNED
,
318 bcm43xx_shm_control_word(dev
, routing
, offset
);
320 bcm43xx_write16(dev
, BCM43xx_MMIO_SHM_DATA
, value
);
324 u32
bcm43xx_hf_read(struct bcm43xx_wldev
*dev
)
328 ret
= bcm43xx_shm_read16(dev
, BCM43xx_SHM_SHARED
,
329 BCM43xx_SHM_SH_HOSTFHI
);
331 ret
|= bcm43xx_shm_read16(dev
, BCM43xx_SHM_SHARED
,
332 BCM43xx_SHM_SH_HOSTFLO
);
337 /* Write HostFlags */
338 void bcm43xx_hf_write(struct bcm43xx_wldev
*dev
, u32 value
)
340 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SHARED
,
341 BCM43xx_SHM_SH_HOSTFLO
,
342 (value
& 0x0000FFFF));
343 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SHARED
,
344 BCM43xx_SHM_SH_HOSTFHI
,
345 ((value
& 0xFFFF0000) >> 16));
348 void bcm43xx_tsf_read(struct bcm43xx_wldev
*dev
, u64
*tsf
)
350 /* We need to be careful. As we read the TSF from multiple
351 * registers, we should take care of register overflows.
352 * In theory, the whole tsf read process should be atomic.
353 * We try to be atomic here, by restaring the read process,
354 * if any of the high registers changed (overflew).
356 if (dev
->dev
->id
.revision
>= 3) {
357 u32 low
, high
, high2
;
360 high
= bcm43xx_read32(dev
, BCM43xx_MMIO_REV3PLUS_TSF_HIGH
);
361 low
= bcm43xx_read32(dev
, BCM43xx_MMIO_REV3PLUS_TSF_LOW
);
362 high2
= bcm43xx_read32(dev
, BCM43xx_MMIO_REV3PLUS_TSF_HIGH
);
363 } while (unlikely(high
!= high2
));
371 u16 test1
, test2
, test3
;
374 v3
= bcm43xx_read16(dev
, BCM43xx_MMIO_TSF_3
);
375 v2
= bcm43xx_read16(dev
, BCM43xx_MMIO_TSF_2
);
376 v1
= bcm43xx_read16(dev
, BCM43xx_MMIO_TSF_1
);
377 v0
= bcm43xx_read16(dev
, BCM43xx_MMIO_TSF_0
);
379 test3
= bcm43xx_read16(dev
, BCM43xx_MMIO_TSF_3
);
380 test2
= bcm43xx_read16(dev
, BCM43xx_MMIO_TSF_2
);
381 test1
= bcm43xx_read16(dev
, BCM43xx_MMIO_TSF_1
);
382 } while (v3
!= test3
|| v2
!= test2
|| v1
!= test1
);
396 static void bcm43xx_time_lock(struct bcm43xx_wldev
*dev
)
400 status
= bcm43xx_read32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
);
401 status
|= BCM43xx_SBF_TIME_UPDATE
;
402 bcm43xx_write32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
, status
);
406 static void bcm43xx_time_unlock(struct bcm43xx_wldev
*dev
)
410 status
= bcm43xx_read32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
);
411 status
&= ~BCM43xx_SBF_TIME_UPDATE
;
412 bcm43xx_write32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
, status
);
415 static void bcm43xx_tsf_write_locked(struct bcm43xx_wldev
*dev
, u64 tsf
)
417 /* Be careful with the in-progress timer.
418 * First zero out the low register, so we have a full
419 * register-overflow duration to complete the operation.
421 if (dev
->dev
->id
.revision
>= 3) {
422 u32 lo
= (tsf
& 0x00000000FFFFFFFFULL
);
423 u32 hi
= (tsf
& 0xFFFFFFFF00000000ULL
) >> 32;
425 bcm43xx_write32(dev
, BCM43xx_MMIO_REV3PLUS_TSF_LOW
, 0);
427 bcm43xx_write32(dev
, BCM43xx_MMIO_REV3PLUS_TSF_HIGH
, hi
);
429 bcm43xx_write32(dev
, BCM43xx_MMIO_REV3PLUS_TSF_LOW
, lo
);
431 u16 v0
= (tsf
& 0x000000000000FFFFULL
);
432 u16 v1
= (tsf
& 0x00000000FFFF0000ULL
) >> 16;
433 u16 v2
= (tsf
& 0x0000FFFF00000000ULL
) >> 32;
434 u16 v3
= (tsf
& 0xFFFF000000000000ULL
) >> 48;
436 bcm43xx_write16(dev
, BCM43xx_MMIO_TSF_0
, 0);
438 bcm43xx_write16(dev
, BCM43xx_MMIO_TSF_3
, v3
);
440 bcm43xx_write16(dev
, BCM43xx_MMIO_TSF_2
, v2
);
442 bcm43xx_write16(dev
, BCM43xx_MMIO_TSF_1
, v1
);
444 bcm43xx_write16(dev
, BCM43xx_MMIO_TSF_0
, v0
);
448 void bcm43xx_tsf_write(struct bcm43xx_wldev
*dev
, u64 tsf
)
450 bcm43xx_time_lock(dev
);
451 bcm43xx_tsf_write_locked(dev
, tsf
);
452 bcm43xx_time_unlock(dev
);
456 void bcm43xx_macfilter_set(struct bcm43xx_wldev
*dev
,
460 static const u8 zero_addr
[ETH_ALEN
] = { 0 };
467 bcm43xx_write16(dev
, BCM43xx_MMIO_MACFILTER_CONTROL
, offset
);
471 bcm43xx_write16(dev
, BCM43xx_MMIO_MACFILTER_DATA
, data
);
474 bcm43xx_write16(dev
, BCM43xx_MMIO_MACFILTER_DATA
, data
);
477 bcm43xx_write16(dev
, BCM43xx_MMIO_MACFILTER_DATA
, data
);
480 static void bcm43xx_write_mac_bssid_templates(struct bcm43xx_wldev
*dev
)
482 static const u8 zero_addr
[ETH_ALEN
] = { 0 };
485 u8 mac_bssid
[ETH_ALEN
* 2];
489 bssid
= dev
->wl
->bssid
;
492 mac
= dev
->wl
->mac_addr
;
496 bcm43xx_macfilter_set(dev
, BCM43xx_MACFILTER_BSSID
, bssid
);
498 memcpy(mac_bssid
, mac
, ETH_ALEN
);
499 memcpy(mac_bssid
+ ETH_ALEN
, bssid
, ETH_ALEN
);
501 /* Write our MAC address and BSSID to template ram */
502 for (i
= 0; i
< ARRAY_SIZE(mac_bssid
); i
+= sizeof(u32
)) {
503 tmp
= (u32
)(mac_bssid
[i
+ 0]);
504 tmp
|= (u32
)(mac_bssid
[i
+ 1]) << 8;
505 tmp
|= (u32
)(mac_bssid
[i
+ 2]) << 16;
506 tmp
|= (u32
)(mac_bssid
[i
+ 3]) << 24;
507 bcm43xx_ram_write(dev
, 0x20 + i
, tmp
);
511 static void bcm43xx_upload_card_macaddress(struct bcm43xx_wldev
*dev
,
514 dev
->wl
->mac_addr
= mac_addr
;
515 bcm43xx_write_mac_bssid_templates(dev
);
516 bcm43xx_macfilter_set(dev
, BCM43xx_MACFILTER_SELF
, mac_addr
);
519 static void bcm43xx_set_slot_time(struct bcm43xx_wldev
*dev
, u16 slot_time
)
521 /* slot_time is in usec. */
522 if (dev
->phy
.type
!= BCM43xx_PHYTYPE_G
)
524 bcm43xx_write16(dev
, 0x684, 510 + slot_time
);
525 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SHARED
, 0x0010, slot_time
);
528 static void bcm43xx_short_slot_timing_enable(struct bcm43xx_wldev
*dev
)
530 bcm43xx_set_slot_time(dev
, 9);
534 static void bcm43xx_short_slot_timing_disable(struct bcm43xx_wldev
*dev
)
536 bcm43xx_set_slot_time(dev
, 20);
540 /* Enable a Generic IRQ. "mask" is the mask of which IRQs to enable.
541 * Returns the _previously_ enabled IRQ mask.
543 static inline u32
bcm43xx_interrupt_enable(struct bcm43xx_wldev
*dev
, u32 mask
)
547 old_mask
= bcm43xx_read32(dev
, BCM43xx_MMIO_GEN_IRQ_MASK
);
548 bcm43xx_write32(dev
, BCM43xx_MMIO_GEN_IRQ_MASK
, old_mask
| mask
);
553 /* Disable a Generic IRQ. "mask" is the mask of which IRQs to disable.
554 * Returns the _previously_ enabled IRQ mask.
556 static inline u32
bcm43xx_interrupt_disable(struct bcm43xx_wldev
*dev
, u32 mask
)
560 old_mask
= bcm43xx_read32(dev
, BCM43xx_MMIO_GEN_IRQ_MASK
);
561 bcm43xx_write32(dev
, BCM43xx_MMIO_GEN_IRQ_MASK
, old_mask
& ~mask
);
566 /* Synchronize IRQ top- and bottom-half.
567 * IRQs must be masked before calling this.
568 * This must not be called with the irq_lock held.
570 static void bcm43xx_synchronize_irq(struct bcm43xx_wldev
*dev
)
572 synchronize_irq(dev
->dev
->irq
);
573 tasklet_kill(&dev
->isr_tasklet
);
576 /* DummyTransmission function, as documented on
577 * http://bcm-specs.sipsolutions.net/DummyTransmission
579 void bcm43xx_dummy_transmission(struct bcm43xx_wldev
*dev
)
581 struct bcm43xx_phy
*phy
= &dev
->phy
;
582 unsigned int i
, max_loop
;
593 case BCM43xx_PHYTYPE_A
:
595 buffer
[0] = 0x000201CC;
597 case BCM43xx_PHYTYPE_B
:
598 case BCM43xx_PHYTYPE_G
:
600 buffer
[0] = 0x000B846E;
607 for (i
= 0; i
< 5; i
++)
608 bcm43xx_ram_write(dev
, i
* 4, buffer
[i
]);
610 bcm43xx_read32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
); /* dummy read */
612 bcm43xx_write16(dev
, 0x0568, 0x0000);
613 bcm43xx_write16(dev
, 0x07C0, 0x0000);
614 value
= ((phy
->type
== BCM43xx_PHYTYPE_A
) ? 1 : 0);
615 bcm43xx_write16(dev
, 0x050C, value
);
616 bcm43xx_write16(dev
, 0x0508, 0x0000);
617 bcm43xx_write16(dev
, 0x050A, 0x0000);
618 bcm43xx_write16(dev
, 0x054C, 0x0000);
619 bcm43xx_write16(dev
, 0x056A, 0x0014);
620 bcm43xx_write16(dev
, 0x0568, 0x0826);
621 bcm43xx_write16(dev
, 0x0500, 0x0000);
622 bcm43xx_write16(dev
, 0x0502, 0x0030);
624 if (phy
->radio_ver
== 0x2050 && phy
->radio_rev
<= 0x5)
625 bcm43xx_radio_write16(dev
, 0x0051, 0x0017);
626 for (i
= 0x00; i
< max_loop
; i
++) {
627 value
= bcm43xx_read16(dev
, 0x050E);
632 for (i
= 0x00; i
< 0x0A; i
++) {
633 value
= bcm43xx_read16(dev
, 0x050E);
638 for (i
= 0x00; i
< 0x0A; i
++) {
639 value
= bcm43xx_read16(dev
, 0x0690);
640 if (!(value
& 0x0100))
644 if (phy
->radio_ver
== 0x2050 && phy
->radio_rev
<= 0x5)
645 bcm43xx_radio_write16(dev
, 0x0051, 0x0037);
648 static void key_write(struct bcm43xx_wldev
*dev
,
649 u8 index
, u8 algorithm
, const u8
*key
)
656 /* Key index/algo block */
657 kidx
= bcm43xx_kidx_to_fw(dev
, index
);
658 value
= ((kidx
<< 4) | algorithm
);
659 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SHARED
,
660 BCM43xx_SHM_SH_KEYIDXBLOCK
+
663 /* Write the key to the Key Table Pointer offset */
664 offset
= dev
->ktp
+ (index
* BCM43xx_SEC_KEYSIZE
);
665 for (i
= 0; i
< BCM43xx_SEC_KEYSIZE
; i
+= 2) {
667 value
|= (u16
)(key
[i
+ 1]) << 8;
668 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SHARED
,
673 static void keymac_write(struct bcm43xx_wldev
*dev
,
674 u8 index
, const u8
*addr
)
678 assert(index
>= 4 + 4);
679 memcpy(dev
->key
[index
].address
, addr
, 6);
680 /* We have two default TX keys and two default RX keys.
681 * Physical mac 0 is mapped to physical key 8.
682 * So we must adjust the index here.
686 addrtmp
[0] = addr
[0];
687 addrtmp
[0] |= ((u32
)(addr
[1]) << 8);
688 addrtmp
[0] |= ((u32
)(addr
[2]) << 16);
689 addrtmp
[0] |= ((u32
)(addr
[3]) << 24);
690 addrtmp
[1] = addr
[4];
691 addrtmp
[1] |= ((u32
)(addr
[5]) << 8);
693 if (dev
->dev
->id
.revision
>= 5) {
694 /* Receive match transmitter address mechanism */
695 bcm43xx_shm_write32(dev
, BCM43xx_SHM_RCMTA
,
696 (index
* 2) + 0, addrtmp
[0]);
697 bcm43xx_shm_write16(dev
, BCM43xx_SHM_RCMTA
,
698 (index
* 2) + 1, addrtmp
[1]);
700 /* RXE (Receive Engine) and
701 * PSM (Programmable State Machine) mechanism
704 /* TODO write to RCM 16, 19, 22 and 25 */
707 bcm43xx_shm_write32(dev
, BCM43xx_SHM_SHARED
,
708 BCM43xx_SHM_SH_PSM
+ (index
* 6) + 0,
710 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SHARED
,
711 BCM43xx_SHM_SH_PSM
+ (index
* 6) + 4,
717 static void do_key_write(struct bcm43xx_wldev
*dev
,
718 u8 index
, u8 algorithm
,
719 const u8
*key
, size_t key_len
,
722 u8 buf
[BCM43xx_SEC_KEYSIZE
];
724 assert(index
< dev
->max_nr_keys
);
725 assert(key_len
<= BCM43xx_SEC_KEYSIZE
);
727 memset(buf
, 0, sizeof(buf
));
729 keymac_write(dev
, index
, buf
); /* First zero out mac. */
730 memcpy(buf
, key
, key_len
);
731 key_write(dev
, index
, algorithm
, buf
);
733 keymac_write(dev
, index
, mac_addr
);
735 dev
->key
[index
].algorithm
= algorithm
;
738 static int bcm43xx_key_write(struct bcm43xx_wldev
*dev
,
739 int index
, u8 algorithm
,
740 const u8
*key
, size_t key_len
,
742 struct ieee80211_key_conf
*keyconf
)
747 if (key_len
> BCM43xx_SEC_KEYSIZE
)
750 /* Per station key with associated MAC address.
751 * Look if it already exists, if yes update, otherwise
752 * allocate a new key.
754 if (bcm43xx_new_kidx_api(dev
))
758 for (i
= sta_keys_start
; i
< dev
->max_nr_keys
; i
++) {
759 if (compare_ether_addr(dev
->key
[i
].address
, mac_addr
) == 0) {
766 for (i
= sta_keys_start
; i
< dev
->max_nr_keys
; i
++) {
767 if (!dev
->key
[i
].enabled
) {
775 dprintk(KERN_ERR PFX
"Out of hw key memory\n");
781 do_key_write(dev
, index
, algorithm
, key
, key_len
, mac_addr
);
782 if ((index
<= 3) && !bcm43xx_new_kidx_api(dev
)) {
784 assert(mac_addr
== NULL
);
785 do_key_write(dev
, index
+ 4, algorithm
, key
, key_len
, NULL
);
787 keyconf
->hw_key_idx
= index
;
792 static void bcm43xx_clear_keys(struct bcm43xx_wldev
*dev
)
794 static const u8 zero
[BCM43xx_SEC_KEYSIZE
] = { 0 };
797 BUILD_BUG_ON(BCM43xx_SEC_KEYSIZE
< ETH_ALEN
);
798 for (i
= 0; i
< dev
->max_nr_keys
; i
++) {
799 do_key_write(dev
, i
, BCM43xx_SEC_ALGO_NONE
,
800 zero
, BCM43xx_SEC_KEYSIZE
,
802 dev
->key
[i
].enabled
= 0;
806 /* Turn the Analog ON/OFF */
807 static void bcm43xx_switch_analog(struct bcm43xx_wldev
*dev
, int on
)
809 bcm43xx_write16(dev
, BCM43xx_MMIO_PHY0
, on
? 0 : 0xF4);
812 void bcm43xx_wireless_core_reset(struct bcm43xx_wldev
*dev
, u32 flags
)
817 flags
|= BCM43xx_TMSLOW_PHYCLKEN
;
818 flags
|= BCM43xx_TMSLOW_PHYRESET
;
819 ssb_device_enable(dev
->dev
, flags
);
820 msleep(2); /* Wait for the PLL to turn on. */
822 /* Now take the PHY out of Reset again */
823 tmslow
= ssb_read32(dev
->dev
, SSB_TMSLOW
);
824 tmslow
|= SSB_TMSLOW_FGC
;
825 tmslow
&= ~BCM43xx_TMSLOW_PHYRESET
;
826 ssb_write32(dev
->dev
, SSB_TMSLOW
, tmslow
);
827 ssb_read32(dev
->dev
, SSB_TMSLOW
); /* flush */
829 tmslow
&= ~SSB_TMSLOW_FGC
;
830 ssb_write32(dev
->dev
, SSB_TMSLOW
, tmslow
);
831 ssb_read32(dev
->dev
, SSB_TMSLOW
); /* flush */
835 bcm43xx_switch_analog(dev
, 1);
837 macctl
= bcm43xx_read32(dev
, BCM43xx_MMIO_MACCTL
);
838 macctl
&= ~BCM43xx_MACCTL_GMODE
;
839 if (flags
& BCM43xx_TMSLOW_GMODE
)
840 macctl
|= BCM43xx_MACCTL_GMODE
;
841 macctl
|= BCM43xx_MACCTL_IHR_ENABLED
;
842 bcm43xx_write32(dev
, BCM43xx_MMIO_MACCTL
, macctl
);
845 static void handle_irq_transmit_status(struct bcm43xx_wldev
*dev
)
849 struct bcm43xx_txstatus stat
;
852 v0
= bcm43xx_read32(dev
, BCM43xx_MMIO_XMITSTAT_0
);
853 if (!(v0
& 0x00000001))
855 v1
= bcm43xx_read32(dev
, BCM43xx_MMIO_XMITSTAT_1
);
857 stat
.cookie
= (v0
>> 16);
858 stat
.seq
= (v1
& 0x0000FFFF);
859 stat
.phy_stat
= ((v1
& 0x00FF0000) >> 16);
860 tmp
= (v0
& 0x0000FFFF);
861 stat
.frame_count
= ((tmp
& 0xF000) >> 12);
862 stat
.rts_count
= ((tmp
& 0x0F00) >> 8);
863 stat
.supp_reason
= ((tmp
& 0x001C) >> 2);
864 stat
.pm_indicated
= !!(tmp
& 0x0080);
865 stat
.intermediate
= !!(tmp
& 0x0040);
866 stat
.for_ampdu
= !!(tmp
& 0x0020);
867 stat
.acked
= !!(tmp
& 0x0002);
869 bcm43xx_handle_txstatus(dev
, &stat
);
873 static void drain_txstatus_queue(struct bcm43xx_wldev
*dev
)
877 if (dev
->dev
->id
.revision
< 5)
879 /* Read all entries from the microcode TXstatus FIFO
880 * and throw them away.
883 dummy
= bcm43xx_read32(dev
, BCM43xx_MMIO_XMITSTAT_0
);
884 if (!(dummy
& 0x00000001))
886 dummy
= bcm43xx_read32(dev
, BCM43xx_MMIO_XMITSTAT_1
);
890 static u32
bcm43xx_jssi_read(struct bcm43xx_wldev
*dev
)
894 val
= bcm43xx_shm_read16(dev
, BCM43xx_SHM_SHARED
, 0x08A);
896 val
|= bcm43xx_shm_read16(dev
, BCM43xx_SHM_SHARED
, 0x088);
901 static void bcm43xx_jssi_write(struct bcm43xx_wldev
*dev
, u32 jssi
)
903 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SHARED
, 0x088,
904 (jssi
& 0x0000FFFF));
905 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SHARED
, 0x08A,
906 (jssi
& 0xFFFF0000) >> 16);
909 static void bcm43xx_generate_noise_sample(struct bcm43xx_wldev
*dev
)
911 bcm43xx_jssi_write(dev
, 0x7F7F7F7F);
912 bcm43xx_write32(dev
, BCM43xx_MMIO_STATUS2_BITFIELD
,
913 bcm43xx_read32(dev
, BCM43xx_MMIO_STATUS2_BITFIELD
)
915 assert(dev
->noisecalc
.channel_at_start
== dev
->phy
.channel
);
918 static void bcm43xx_calculate_link_quality(struct bcm43xx_wldev
*dev
)
920 /* Top half of Link Quality calculation. */
922 if (dev
->noisecalc
.calculation_running
)
924 dev
->noisecalc
.channel_at_start
= dev
->phy
.channel
;
925 dev
->noisecalc
.calculation_running
= 1;
926 dev
->noisecalc
.nr_samples
= 0;
928 bcm43xx_generate_noise_sample(dev
);
931 static void handle_irq_noise(struct bcm43xx_wldev
*dev
)
933 struct bcm43xx_phy
*phy
= &dev
->phy
;
939 /* Bottom half of Link Quality calculation. */
941 assert(dev
->noisecalc
.calculation_running
);
942 if (dev
->noisecalc
.channel_at_start
!= phy
->channel
)
943 goto drop_calculation
;
944 *((u32
*)noise
) = cpu_to_le32(bcm43xx_jssi_read(dev
));
945 if (noise
[0] == 0x7F || noise
[1] == 0x7F ||
946 noise
[2] == 0x7F || noise
[3] == 0x7F)
949 /* Get the noise samples. */
950 assert(dev
->noisecalc
.nr_samples
< 8);
951 i
= dev
->noisecalc
.nr_samples
;
952 noise
[0] = limit_value(noise
[0], 0, ARRAY_SIZE(phy
->nrssi_lt
) - 1);
953 noise
[1] = limit_value(noise
[1], 0, ARRAY_SIZE(phy
->nrssi_lt
) - 1);
954 noise
[2] = limit_value(noise
[2], 0, ARRAY_SIZE(phy
->nrssi_lt
) - 1);
955 noise
[3] = limit_value(noise
[3], 0, ARRAY_SIZE(phy
->nrssi_lt
) - 1);
956 dev
->noisecalc
.samples
[i
][0] = phy
->nrssi_lt
[noise
[0]];
957 dev
->noisecalc
.samples
[i
][1] = phy
->nrssi_lt
[noise
[1]];
958 dev
->noisecalc
.samples
[i
][2] = phy
->nrssi_lt
[noise
[2]];
959 dev
->noisecalc
.samples
[i
][3] = phy
->nrssi_lt
[noise
[3]];
960 dev
->noisecalc
.nr_samples
++;
961 if (dev
->noisecalc
.nr_samples
== 8) {
962 /* Calculate the Link Quality by the noise samples. */
964 for (i
= 0; i
< 8; i
++) {
965 for (j
= 0; j
< 4; j
++)
966 average
+= dev
->noisecalc
.samples
[i
][j
];
972 tmp
= bcm43xx_shm_read16(dev
, BCM43xx_SHM_SHARED
, 0x40C);
973 tmp
= (tmp
/ 128) & 0x1F;
983 dev
->stats
.link_noise
= average
;
985 dev
->noisecalc
.calculation_running
= 0;
989 bcm43xx_generate_noise_sample(dev
);
992 static void handle_irq_tbtt_indication(struct bcm43xx_wldev
*dev
)
994 if (bcm43xx_is_mode(dev
->wl
, IEEE80211_IF_TYPE_AP
)) {
997 if (1/*FIXME: the last PSpoll frame was sent successfully */)
998 bcm43xx_power_saving_ctl_bits(dev
, -1, -1);
1000 dev
->reg124_set_0x4
= 0;
1001 if (bcm43xx_is_mode(dev
->wl
, IEEE80211_IF_TYPE_IBSS
))
1002 dev
->reg124_set_0x4
= 1;
1005 static void handle_irq_atim_end(struct bcm43xx_wldev
*dev
)
1007 if (!dev
->reg124_set_0x4
/*FIXME rename this variable*/)
1009 bcm43xx_write32(dev
, BCM43xx_MMIO_STATUS2_BITFIELD
,
1010 bcm43xx_read32(dev
, BCM43xx_MMIO_STATUS2_BITFIELD
)
1014 static void handle_irq_pmq(struct bcm43xx_wldev
*dev
)
1021 tmp
= bcm43xx_read32(dev
, BCM43xx_MMIO_PS_STATUS
);
1022 if (!(tmp
& 0x00000008))
1025 /* 16bit write is odd, but correct. */
1026 bcm43xx_write16(dev
, BCM43xx_MMIO_PS_STATUS
, 0x0002);
1029 static void bcm43xx_write_template_common(struct bcm43xx_wldev
*dev
,
1030 const u8
* data
, u16 size
,
1032 u16 shm_size_offset
, u8 rate
)
1035 struct bcm43xx_plcp_hdr4 plcp
;
1038 bcm43xx_generate_plcp_hdr(&plcp
, size
+ FCS_LEN
, rate
);
1039 bcm43xx_ram_write(dev
, ram_offset
, le32_to_cpu(plcp
.data
));
1040 ram_offset
+= sizeof(u32
);
1041 /* The PLCP is 6 bytes long, but we only wrote 4 bytes, yet.
1042 * So leave the first two bytes of the next write blank.
1044 tmp
= (u32
)(data
[0]) << 16;
1045 tmp
|= (u32
)(data
[1]) << 24;
1046 bcm43xx_ram_write(dev
, ram_offset
, tmp
);
1047 ram_offset
+= sizeof(u32
);
1048 for (i
= 2; i
< size
; i
+= sizeof(u32
)) {
1049 tmp
= (u32
)(data
[i
+ 0]);
1051 tmp
|= (u32
)(data
[i
+ 1]) << 8;
1053 tmp
|= (u32
)(data
[i
+ 2]) << 16;
1055 tmp
|= (u32
)(data
[i
+ 3]) << 24;
1056 bcm43xx_ram_write(dev
, ram_offset
+ i
- 2, tmp
);
1058 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SHARED
, shm_size_offset
,
1059 size
+ sizeof(struct bcm43xx_plcp_hdr6
));
1062 static void bcm43xx_write_beacon_template(struct bcm43xx_wldev
*dev
,
1064 u16 shm_size_offset
, u8 rate
)
1069 assert(dev
->cached_beacon
);
1070 len
= min((size_t)dev
->cached_beacon
->len
,
1071 0x200 - sizeof(struct bcm43xx_plcp_hdr6
));
1072 data
= (const u8
*)(dev
->cached_beacon
->data
);
1073 bcm43xx_write_template_common(dev
, data
,
1075 shm_size_offset
, rate
);
1078 static void bcm43xx_write_probe_resp_plcp(struct bcm43xx_wldev
*dev
,
1079 u16 shm_offset
, u16 size
, u8 rate
)
1081 struct bcm43xx_plcp_hdr4 plcp
;
1086 bcm43xx_generate_plcp_hdr(&plcp
, size
+ FCS_LEN
, rate
);
1087 dur
= ieee80211_generic_frame_duration(dev
->wl
->hw
,
1089 BCM43xx_RATE_TO_BASE100KBPS(rate
));
1090 /* Write PLCP in two parts and timing for packet transfer */
1091 tmp
= le32_to_cpu(plcp
.data
);
1092 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SHARED
, shm_offset
,
1094 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SHARED
, shm_offset
+ 2,
1096 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SHARED
, shm_offset
+ 6,
1100 /* Instead of using custom probe response template, this function
1101 * just patches custom beacon template by:
1102 * 1) Changing packet type
1103 * 2) Patching duration field
1106 static u8
* bcm43xx_generate_probe_resp(struct bcm43xx_wldev
*dev
,
1107 u16
* dest_size
, u8 rate
)
1111 u16 src_size
, elem_size
, src_pos
, dest_pos
;
1113 struct ieee80211_hdr
*hdr
;
1115 assert(dev
->cached_beacon
);
1116 src_size
= dev
->cached_beacon
->len
;
1117 src_data
= (const u8
*)dev
->cached_beacon
->data
;
1119 if (unlikely(src_size
< 0x24)) {
1120 dprintk(KERN_ERR PFX
"bcm43xx_generate_probe_resp: "
1121 "invalid beacon\n");
1125 dest_data
= kmalloc(src_size
, GFP_ATOMIC
);
1126 if (unlikely(!dest_data
))
1129 /* 0x24 is offset of first variable-len Information-Element
1132 memcpy(dest_data
, src_data
, 0x24);
1133 src_pos
= dest_pos
= 0x24;
1134 for ( ; src_pos
< src_size
- 2; src_pos
+= elem_size
) {
1135 elem_size
= src_data
[src_pos
+ 1] + 2;
1136 if (src_data
[src_pos
] != 0x05) { /* TIM */
1137 memcpy(dest_data
+ dest_pos
, src_data
+ src_pos
,
1139 dest_pos
+= elem_size
;
1142 *dest_size
= dest_pos
;
1143 hdr
= (struct ieee80211_hdr
*)dest_data
;
1145 /* Set the frame control. */
1146 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
1147 IEEE80211_STYPE_PROBE_RESP
);
1148 dur
= ieee80211_generic_frame_duration(dev
->wl
->hw
,
1150 BCM43xx_RATE_TO_BASE100KBPS(rate
));
1151 hdr
->duration_id
= dur
;
1156 static void bcm43xx_write_probe_resp_template(struct bcm43xx_wldev
*dev
,
1158 u16 shm_size_offset
, u8 rate
)
1160 u8
* probe_resp_data
;
1163 assert(dev
->cached_beacon
);
1164 size
= dev
->cached_beacon
->len
;
1165 probe_resp_data
= bcm43xx_generate_probe_resp(dev
, &size
, rate
);
1166 if (unlikely(!probe_resp_data
))
1169 /* Looks like PLCP headers plus packet timings are stored for
1170 * all possible basic rates
1172 bcm43xx_write_probe_resp_plcp(dev
, 0x31A, size
,
1173 BCM43xx_CCK_RATE_1MB
);
1174 bcm43xx_write_probe_resp_plcp(dev
, 0x32C, size
,
1175 BCM43xx_CCK_RATE_2MB
);
1176 bcm43xx_write_probe_resp_plcp(dev
, 0x33E, size
,
1177 BCM43xx_CCK_RATE_5MB
);
1178 bcm43xx_write_probe_resp_plcp(dev
, 0x350, size
,
1179 BCM43xx_CCK_RATE_11MB
);
1181 size
= min((size_t)size
,
1182 0x200 - sizeof(struct bcm43xx_plcp_hdr6
));
1183 bcm43xx_write_template_common(dev
, probe_resp_data
,
1185 shm_size_offset
, rate
);
1186 kfree(probe_resp_data
);
1189 static int bcm43xx_refresh_cached_beacon(struct bcm43xx_wldev
*dev
,
1190 struct sk_buff
*beacon
)
1192 if (dev
->cached_beacon
)
1193 kfree_skb(dev
->cached_beacon
);
1194 dev
->cached_beacon
= beacon
;
1199 static void bcm43xx_update_templates(struct bcm43xx_wldev
*dev
)
1203 assert(dev
->cached_beacon
);
1205 bcm43xx_write_beacon_template(dev
, 0x68, 0x18,
1206 BCM43xx_CCK_RATE_1MB
);
1207 bcm43xx_write_beacon_template(dev
, 0x468, 0x1A,
1208 BCM43xx_CCK_RATE_1MB
);
1209 bcm43xx_write_probe_resp_template(dev
, 0x268, 0x4A,
1210 BCM43xx_CCK_RATE_11MB
);
1212 status
= bcm43xx_read32(dev
, BCM43xx_MMIO_STATUS2_BITFIELD
);
1214 bcm43xx_write32(dev
, BCM43xx_MMIO_STATUS2_BITFIELD
, status
);
1217 static void bcm43xx_refresh_templates(struct bcm43xx_wldev
*dev
,
1218 struct sk_buff
*beacon
)
1222 err
= bcm43xx_refresh_cached_beacon(dev
, beacon
);
1225 bcm43xx_update_templates(dev
);
1228 static void bcm43xx_set_ssid(struct bcm43xx_wldev
*dev
,
1229 const u8
*ssid
, u8 ssid_len
)
1234 len
= min((u16
)ssid_len
, (u16
)0x100);
1235 for (i
= 0; i
< len
; i
+= sizeof(u32
)) {
1236 tmp
= (u32
)(ssid
[i
+ 0]);
1238 tmp
|= (u32
)(ssid
[i
+ 1]) << 8;
1240 tmp
|= (u32
)(ssid
[i
+ 2]) << 16;
1242 tmp
|= (u32
)(ssid
[i
+ 3]) << 24;
1243 bcm43xx_shm_write32(dev
, BCM43xx_SHM_SHARED
,
1246 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SHARED
,
1250 static void bcm43xx_set_beacon_int(struct bcm43xx_wldev
*dev
, u16 beacon_int
)
1252 bcm43xx_time_lock(dev
);
1253 if (dev
->dev
->id
.revision
>= 3) {
1254 bcm43xx_write32(dev
, 0x188, (beacon_int
<< 16));
1256 bcm43xx_write16(dev
, 0x606, (beacon_int
>> 6));
1257 bcm43xx_write16(dev
, 0x610, beacon_int
);
1259 bcm43xx_time_unlock(dev
);
1262 static void handle_irq_beacon(struct bcm43xx_wldev
*dev
)
1266 if (!bcm43xx_is_mode(dev
->wl
, IEEE80211_IF_TYPE_AP
))
1269 dev
->irq_savedstate
&= ~BCM43xx_IRQ_BEACON
;
1270 status
= bcm43xx_read32(dev
, BCM43xx_MMIO_STATUS2_BITFIELD
);
1272 if (!dev
->cached_beacon
|| ((status
& 0x1) && (status
& 0x2))) {
1273 /* ACK beacon IRQ. */
1274 bcm43xx_write32(dev
, BCM43xx_MMIO_GEN_IRQ_REASON
,
1275 BCM43xx_IRQ_BEACON
);
1276 dev
->irq_savedstate
|= BCM43xx_IRQ_BEACON
;
1277 if (dev
->cached_beacon
)
1278 kfree_skb(dev
->cached_beacon
);
1279 dev
->cached_beacon
= NULL
;
1282 if (!(status
& 0x1)) {
1283 bcm43xx_write_beacon_template(dev
, 0x68, 0x18,
1284 BCM43xx_CCK_RATE_1MB
);
1286 bcm43xx_write32(dev
, BCM43xx_MMIO_STATUS2_BITFIELD
,
1289 if (!(status
& 0x2)) {
1290 bcm43xx_write_beacon_template(dev
, 0x468, 0x1A,
1291 BCM43xx_CCK_RATE_1MB
);
1293 bcm43xx_write32(dev
, BCM43xx_MMIO_STATUS2_BITFIELD
,
1298 static void handle_irq_ucode_debug(struct bcm43xx_wldev
*dev
)
1303 /* Interrupt handler bottom-half */
1304 static void bcm43xx_interrupt_tasklet(struct bcm43xx_wldev
*dev
)
1307 u32 dma_reason
[ARRAY_SIZE(dev
->dma_reason
)];
1308 u32 merged_dma_reason
= 0;
1309 int i
, activity
= 0;
1310 unsigned long flags
;
1312 spin_lock_irqsave(&dev
->wl
->irq_lock
, flags
);
1314 assert(bcm43xx_status(dev
) == BCM43xx_STAT_INITIALIZED
);
1315 assert(dev
->started
);
1317 reason
= dev
->irq_reason
;
1318 for (i
= 0; i
< ARRAY_SIZE(dma_reason
); i
++) {
1319 dma_reason
[i
] = dev
->dma_reason
[i
];
1320 merged_dma_reason
|= dma_reason
[i
];
1323 if (unlikely(reason
& BCM43xx_IRQ_MAC_TXERR
))
1324 printkl(KERN_ERR PFX
"MAC transmission error\n");
1326 if (unlikely(reason
& BCM43xx_IRQ_PHY_TXERR
))
1327 printkl(KERN_ERR PFX
"PHY transmission error\n");
1329 if (unlikely(merged_dma_reason
& (BCM43xx_DMAIRQ_FATALMASK
|
1330 BCM43xx_DMAIRQ_NONFATALMASK
))) {
1331 if (merged_dma_reason
& BCM43xx_DMAIRQ_FATALMASK
) {
1332 printkl(KERN_ERR PFX
"FATAL ERROR: Fatal DMA error: "
1333 "0x%08X, 0x%08X, 0x%08X, "
1334 "0x%08X, 0x%08X, 0x%08X\n",
1335 dma_reason
[0], dma_reason
[1],
1336 dma_reason
[2], dma_reason
[3],
1337 dma_reason
[4], dma_reason
[5]);
1338 bcm43xx_controller_restart(dev
, "DMA error");
1340 spin_unlock_irqrestore(&dev
->wl
->irq_lock
, flags
);
1343 if (merged_dma_reason
& BCM43xx_DMAIRQ_NONFATALMASK
) {
1344 printkl(KERN_ERR PFX
"DMA error: "
1345 "0x%08X, 0x%08X, 0x%08X, "
1346 "0x%08X, 0x%08X, 0x%08X\n",
1347 dma_reason
[0], dma_reason
[1],
1348 dma_reason
[2], dma_reason
[3],
1349 dma_reason
[4], dma_reason
[5]);
1353 if (unlikely(reason
& BCM43xx_IRQ_UCODE_DEBUG
))
1354 handle_irq_ucode_debug(dev
);
1355 if (reason
& BCM43xx_IRQ_TBTT_INDI
)
1356 handle_irq_tbtt_indication(dev
);
1357 if (reason
& BCM43xx_IRQ_ATIM_END
)
1358 handle_irq_atim_end(dev
);
1359 if (reason
& BCM43xx_IRQ_BEACON
)
1360 handle_irq_beacon(dev
);
1361 if (reason
& BCM43xx_IRQ_PMQ
)
1362 handle_irq_pmq(dev
);
1363 if (reason
& BCM43xx_IRQ_TXFIFO_FLUSH_OK
)
1365 if (reason
& BCM43xx_IRQ_NOISESAMPLE_OK
)
1366 handle_irq_noise(dev
);
1368 /* Check the DMA reason registers for received data. */
1369 if (dma_reason
[0] & BCM43xx_DMAIRQ_RX_DONE
) {
1370 if (bcm43xx_using_pio(dev
))
1371 bcm43xx_pio_rx(dev
->pio
.queue0
);
1373 bcm43xx_dma_rx(dev
->dma
.rx_ring0
);
1374 /* We intentionally don't set "activity" to 1, here. */
1376 assert(!(dma_reason
[1] & BCM43xx_DMAIRQ_RX_DONE
));
1377 assert(!(dma_reason
[2] & BCM43xx_DMAIRQ_RX_DONE
));
1378 if (dma_reason
[3] & BCM43xx_DMAIRQ_RX_DONE
) {
1379 if (bcm43xx_using_pio(dev
))
1380 bcm43xx_pio_rx(dev
->pio
.queue3
);
1382 bcm43xx_dma_rx(dev
->dma
.rx_ring3
);
1385 assert(!(dma_reason
[4] & BCM43xx_DMAIRQ_RX_DONE
));
1386 assert(!(dma_reason
[5] & BCM43xx_DMAIRQ_RX_DONE
));
1388 if (reason
& BCM43xx_IRQ_TX_OK
) {
1389 handle_irq_transmit_status(dev
);
1391 //TODO: In AP mode, this also causes sending of powersave responses.
1394 if (!modparam_noleds
)
1395 bcm43xx_leds_update(dev
, activity
);
1396 bcm43xx_interrupt_enable(dev
, dev
->irq_savedstate
);
1398 spin_unlock_irqrestore(&dev
->wl
->irq_lock
, flags
);
1401 static void pio_irq_workaround(struct bcm43xx_wldev
*dev
,
1402 u16 base
, int queueidx
)
1406 rxctl
= bcm43xx_read16(dev
, base
+ BCM43xx_PIO_RXCTL
);
1407 if (rxctl
& BCM43xx_PIO_RXCTL_DATAAVAILABLE
)
1408 dev
->dma_reason
[queueidx
] |= BCM43xx_DMAIRQ_RX_DONE
;
1410 dev
->dma_reason
[queueidx
] &= ~BCM43xx_DMAIRQ_RX_DONE
;
1413 static void bcm43xx_interrupt_ack(struct bcm43xx_wldev
*dev
, u32 reason
)
1415 if (bcm43xx_using_pio(dev
) &&
1416 (dev
->dev
->id
.revision
< 3) &&
1417 (!(reason
& BCM43xx_IRQ_PIO_WORKAROUND
))) {
1418 /* Apply a PIO specific workaround to the dma_reasons */
1419 pio_irq_workaround(dev
, BCM43xx_MMIO_PIO1_BASE
, 0);
1420 pio_irq_workaround(dev
, BCM43xx_MMIO_PIO2_BASE
, 1);
1421 pio_irq_workaround(dev
, BCM43xx_MMIO_PIO3_BASE
, 2);
1422 pio_irq_workaround(dev
, BCM43xx_MMIO_PIO4_BASE
, 3);
1425 bcm43xx_write32(dev
, BCM43xx_MMIO_GEN_IRQ_REASON
, reason
);
1427 bcm43xx_write32(dev
, BCM43xx_MMIO_DMA0_REASON
,
1428 dev
->dma_reason
[0]);
1429 bcm43xx_write32(dev
, BCM43xx_MMIO_DMA1_REASON
,
1430 dev
->dma_reason
[1]);
1431 bcm43xx_write32(dev
, BCM43xx_MMIO_DMA2_REASON
,
1432 dev
->dma_reason
[2]);
1433 bcm43xx_write32(dev
, BCM43xx_MMIO_DMA3_REASON
,
1434 dev
->dma_reason
[3]);
1435 bcm43xx_write32(dev
, BCM43xx_MMIO_DMA4_REASON
,
1436 dev
->dma_reason
[4]);
1437 bcm43xx_write32(dev
, BCM43xx_MMIO_DMA5_REASON
,
1438 dev
->dma_reason
[5]);
1441 /* Interrupt handler top-half */
1442 static irqreturn_t
bcm43xx_interrupt_handler(int irq
, void *dev_id
)
1444 irqreturn_t ret
= IRQ_HANDLED
;
1445 struct bcm43xx_wldev
*dev
= dev_id
;
1451 spin_lock(&dev
->wl
->irq_lock
);
1453 reason
= bcm43xx_read32(dev
, BCM43xx_MMIO_GEN_IRQ_REASON
);
1454 if (reason
== 0xffffffff) {
1455 /* irq not for us (shared irq) */
1459 reason
&= bcm43xx_read32(dev
, BCM43xx_MMIO_GEN_IRQ_MASK
);
1463 assert(bcm43xx_status(dev
) == BCM43xx_STAT_INITIALIZED
);
1464 assert(dev
->started
);
1466 dev
->dma_reason
[0] = bcm43xx_read32(dev
, BCM43xx_MMIO_DMA0_REASON
)
1468 dev
->dma_reason
[1] = bcm43xx_read32(dev
, BCM43xx_MMIO_DMA1_REASON
)
1470 dev
->dma_reason
[2] = bcm43xx_read32(dev
, BCM43xx_MMIO_DMA2_REASON
)
1472 dev
->dma_reason
[3] = bcm43xx_read32(dev
, BCM43xx_MMIO_DMA3_REASON
)
1474 dev
->dma_reason
[4] = bcm43xx_read32(dev
, BCM43xx_MMIO_DMA4_REASON
)
1476 dev
->dma_reason
[5] = bcm43xx_read32(dev
, BCM43xx_MMIO_DMA5_REASON
)
1479 bcm43xx_interrupt_ack(dev
, reason
);
1480 /* disable all IRQs. They are enabled again in the bottom half. */
1481 dev
->irq_savedstate
= bcm43xx_interrupt_disable(dev
, BCM43xx_IRQ_ALL
);
1482 /* save the reason code and call our bottom half. */
1483 dev
->irq_reason
= reason
;
1484 tasklet_schedule(&dev
->isr_tasklet
);
1487 spin_unlock(&dev
->wl
->irq_lock
);
1492 static void bcm43xx_release_firmware(struct bcm43xx_wldev
*dev
)
1494 release_firmware(dev
->fw
.ucode
);
1495 dev
->fw
.ucode
= NULL
;
1496 release_firmware(dev
->fw
.pcm
);
1498 release_firmware(dev
->fw
.initvals0
);
1499 dev
->fw
.initvals0
= NULL
;
1500 release_firmware(dev
->fw
.initvals1
);
1501 dev
->fw
.initvals1
= NULL
;
1504 static int bcm43xx_request_firmware(struct bcm43xx_wldev
*dev
)
1506 u8 rev
= dev
->dev
->id
.revision
;
1509 char buf
[22 + sizeof(modparam_fwpostfix
) - 1] = { 0 };
1511 if (!dev
->fw
.ucode
) {
1512 snprintf(buf
, ARRAY_SIZE(buf
), "bcm43xx_microcode%d%s.fw",
1513 (rev
>= 5 ? 5 : rev
),
1514 modparam_fwpostfix
);
1515 err
= request_firmware(&dev
->fw
.ucode
, buf
, dev
->dev
->dev
);
1518 "Error: Microcode \"%s\" not available or load failed.\n",
1525 snprintf(buf
, ARRAY_SIZE(buf
),
1526 "bcm43xx_pcm%d%s.fw",
1528 modparam_fwpostfix
);
1529 err
= request_firmware(&dev
->fw
.pcm
, buf
, dev
->dev
->dev
);
1532 "Error: PCM \"%s\" not available or load failed.\n",
1538 if (!dev
->fw
.initvals0
) {
1539 if (rev
== 2 || rev
== 4) {
1540 switch (dev
->phy
.type
) {
1541 case BCM43xx_PHYTYPE_A
:
1544 case BCM43xx_PHYTYPE_B
:
1545 case BCM43xx_PHYTYPE_G
:
1552 } else if (rev
>= 5) {
1553 switch (dev
->phy
.type
) {
1554 case BCM43xx_PHYTYPE_A
:
1557 case BCM43xx_PHYTYPE_B
:
1558 case BCM43xx_PHYTYPE_G
:
1566 snprintf(buf
, ARRAY_SIZE(buf
), "bcm43xx_initval%02d%s.fw",
1567 nr
, modparam_fwpostfix
);
1569 err
= request_firmware(&dev
->fw
.initvals0
, buf
, dev
->dev
->dev
);
1572 "Error: InitVals \"%s\" not available or load failed.\n",
1576 if (dev
->fw
.initvals0
->size
% sizeof(struct bcm43xx_initval
)) {
1577 printk(KERN_ERR PFX
"InitVals fileformat error.\n");
1582 if (!dev
->fw
.initvals1
) {
1586 switch (dev
->phy
.type
) {
1587 case BCM43xx_PHYTYPE_A
:
1588 sbtmstatehigh
= ssb_read32(dev
->dev
, SSB_TMSHIGH
);
1589 if (sbtmstatehigh
& 0x00010000)
1594 case BCM43xx_PHYTYPE_B
:
1595 case BCM43xx_PHYTYPE_G
:
1601 snprintf(buf
, ARRAY_SIZE(buf
), "bcm43xx_initval%02d%s.fw",
1602 nr
, modparam_fwpostfix
);
1604 err
= request_firmware(&dev
->fw
.initvals1
, buf
, dev
->dev
->dev
);
1607 "Error: InitVals \"%s\" not available or load failed.\n",
1611 if (dev
->fw
.initvals1
->size
% sizeof(struct bcm43xx_initval
)) {
1612 printk(KERN_ERR PFX
"InitVals fileformat error.\n");
1621 bcm43xx_release_firmware(dev
);
1624 printk(KERN_ERR PFX
"Error: No InitVals available!\n");
1629 static int bcm43xx_upload_microcode(struct bcm43xx_wldev
*dev
)
1632 unsigned int i
, len
;
1633 u16 fwrev
, fwpatch
, fwdate
, fwtime
;
1637 /* Upload Microcode. */
1638 data
= (__be32
*)(dev
->fw
.ucode
->data
);
1639 len
= dev
->fw
.ucode
->size
/ sizeof(__be32
);
1640 bcm43xx_shm_control_word(dev
,
1641 BCM43xx_SHM_UCODE
| BCM43xx_SHM_AUTOINC_W
,
1643 for (i
= 0; i
< len
; i
++) {
1644 bcm43xx_write32(dev
, BCM43xx_MMIO_SHM_DATA
,
1645 be32_to_cpu(data
[i
]));
1649 /* Upload PCM data. */
1650 data
= (__be32
*)(dev
->fw
.pcm
->data
);
1651 len
= dev
->fw
.pcm
->size
/ sizeof(__be32
);
1652 bcm43xx_shm_control_word(dev
, BCM43xx_SHM_HW
, 0x01EA);
1653 bcm43xx_write32(dev
, BCM43xx_MMIO_SHM_DATA
, 0x00004000);
1654 /* No need for autoinc bit in SHM_HW */
1655 bcm43xx_shm_control_word(dev
, BCM43xx_SHM_HW
, 0x01EB);
1656 for (i
= 0; i
< len
; i
++) {
1657 bcm43xx_write32(dev
, BCM43xx_MMIO_SHM_DATA
,
1658 be32_to_cpu(data
[i
]));
1662 bcm43xx_write32(dev
, BCM43xx_MMIO_GEN_IRQ_REASON
, BCM43xx_IRQ_ALL
);
1663 bcm43xx_write32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
, 0x00020402);
1665 /* Wait for the microcode to load and respond */
1668 tmp
= bcm43xx_read32(dev
, BCM43xx_MMIO_GEN_IRQ_REASON
);
1669 if (tmp
== BCM43xx_IRQ_MAC_SUSPENDED
)
1672 if (i
>= BCM43xx_IRQWAIT_MAX_RETRIES
) {
1673 printk(KERN_ERR PFX
"Microcode not responding\n");
1679 bcm43xx_read32(dev
, BCM43xx_MMIO_GEN_IRQ_REASON
); /* dummy read */
1681 /* Get and check the revisions. */
1682 fwrev
= bcm43xx_shm_read16(dev
, BCM43xx_SHM_SHARED
,
1683 BCM43xx_SHM_SH_UCODEREV
);
1684 fwpatch
= bcm43xx_shm_read16(dev
, BCM43xx_SHM_SHARED
,
1685 BCM43xx_SHM_SH_UCODEPATCH
);
1686 fwdate
= bcm43xx_shm_read16(dev
, BCM43xx_SHM_SHARED
,
1687 BCM43xx_SHM_SH_UCODEDATE
);
1688 fwtime
= bcm43xx_shm_read16(dev
, BCM43xx_SHM_SHARED
,
1689 BCM43xx_SHM_SH_UCODETIME
);
1691 if (fwrev
<= 0x128) {
1692 printk(KERN_ERR PFX
"YOUR FIRMWARE IS TOO OLD. Firmware from "
1693 "binary drivers older than version 4.x is unsupported. "
1694 "You must upgrade your firmware files.\n");
1695 bcm43xx_write32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
, 0);
1699 printk(KERN_DEBUG PFX
"Loading firmware version %u.%u "
1700 "(20%.2i-%.2i-%.2i %.2i:%.2i:%.2i)\n",
1702 (fwdate
>> 12) & 0xF, (fwdate
>> 8) & 0xF, fwdate
& 0xFF,
1703 (fwtime
>> 11) & 0x1F, (fwtime
>> 5) & 0x3F, fwtime
& 0x1F);
1705 dev
->fw
.rev
= fwrev
;
1706 dev
->fw
.patch
= fwpatch
;
1712 static int bcm43xx_write_initvals(struct bcm43xx_wldev
*dev
,
1713 const struct bcm43xx_initval
*data
,
1714 const unsigned int len
)
1720 for (i
= 0; i
< len
; i
++) {
1721 offset
= be16_to_cpu(data
[i
].offset
);
1722 size
= be16_to_cpu(data
[i
].size
);
1723 value
= be32_to_cpu(data
[i
].value
);
1725 if (unlikely(offset
>= 0x1000))
1728 if (unlikely(value
& 0xFFFF0000))
1730 bcm43xx_write16(dev
, offset
, (u16
)value
);
1731 } else if (size
== 4) {
1732 bcm43xx_write32(dev
, offset
, value
);
1740 printk(KERN_ERR PFX
"InitVals (bcm43xx_initvalXX.fw) file-format error. "
1741 "Please fix your bcm43xx firmware files.\n");
1745 static int bcm43xx_upload_initvals(struct bcm43xx_wldev
*dev
)
1749 err
= bcm43xx_write_initvals(dev
, (struct bcm43xx_initval
*)dev
->fw
.initvals0
->data
,
1750 dev
->fw
.initvals0
->size
/ sizeof(struct bcm43xx_initval
));
1753 if (dev
->fw
.initvals1
) {
1754 err
= bcm43xx_write_initvals(dev
, (struct bcm43xx_initval
*)dev
->fw
.initvals1
->data
,
1755 dev
->fw
.initvals1
->size
/ sizeof(struct bcm43xx_initval
));
1763 /* Initialize the GPIOs
1764 * http://bcm-specs.sipsolutions.net/GPIO
1766 static int bcm43xx_gpio_init(struct bcm43xx_wldev
*dev
)
1768 struct ssb_bus
*bus
= dev
->dev
->bus
;
1769 struct ssb_device
*gpiodev
, *pcidev
= NULL
;
1772 bcm43xx_write32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
,
1773 bcm43xx_read32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
)
1776 bcm43xx_leds_switch_all(dev
, 0);
1777 bcm43xx_write16(dev
, BCM43xx_MMIO_GPIO_MASK
,
1778 bcm43xx_read16(dev
, BCM43xx_MMIO_GPIO_MASK
)
1783 if (dev
->dev
->bus
->chip_id
== 0x4301) {
1787 if (0 /* FIXME: conditional unknown */) {
1788 bcm43xx_write16(dev
, BCM43xx_MMIO_GPIO_MASK
,
1789 bcm43xx_read16(dev
, BCM43xx_MMIO_GPIO_MASK
)
1794 if (dev
->dev
->bus
->sprom
.r1
.boardflags_lo
& BCM43xx_BFL_PACTRL
) {
1795 bcm43xx_write16(dev
, BCM43xx_MMIO_GPIO_MASK
,
1796 bcm43xx_read16(dev
, BCM43xx_MMIO_GPIO_MASK
)
1801 if (dev
->dev
->id
.revision
>= 2)
1802 mask
|= 0x0010; /* FIXME: This is redundant. */
1804 #ifdef CONFIG_SSB_DRIVER_PCICORE
1805 pcidev
= bus
->pcicore
.dev
;
1807 gpiodev
= bus
->chipco
.dev
? : pcidev
;
1810 ssb_write32(gpiodev
, BCM43xx_GPIO_CONTROL
,
1811 (ssb_read32(gpiodev
, BCM43xx_GPIO_CONTROL
)
1817 /* Turn off all GPIO stuff. Call this on module unload, for example. */
1818 static void bcm43xx_gpio_cleanup(struct bcm43xx_wldev
*dev
)
1820 struct ssb_bus
*bus
= dev
->dev
->bus
;
1821 struct ssb_device
*gpiodev
, *pcidev
= NULL
;
1823 #ifdef CONFIG_SSB_DRIVER_PCICORE
1824 pcidev
= bus
->pcicore
.dev
;
1826 gpiodev
= bus
->chipco
.dev
? : pcidev
;
1829 ssb_write32(gpiodev
, BCM43xx_GPIO_CONTROL
, 0);
1832 /* http://bcm-specs.sipsolutions.net/EnableMac */
1833 void bcm43xx_mac_enable(struct bcm43xx_wldev
*dev
)
1835 dev
->mac_suspended
--;
1836 assert(dev
->mac_suspended
>= 0);
1837 if (dev
->mac_suspended
== 0) {
1838 bcm43xx_write32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
,
1839 bcm43xx_read32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
)
1840 | BCM43xx_SBF_MAC_ENABLED
);
1841 bcm43xx_write32(dev
, BCM43xx_MMIO_GEN_IRQ_REASON
,
1842 BCM43xx_IRQ_MAC_SUSPENDED
);
1843 bcm43xx_read32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
); /* dummy read */
1844 bcm43xx_read32(dev
, BCM43xx_MMIO_GEN_IRQ_REASON
); /* dummy read */
1845 bcm43xx_power_saving_ctl_bits(dev
, -1, -1);
1849 /* http://bcm-specs.sipsolutions.net/SuspendMAC */
1850 void bcm43xx_mac_suspend(struct bcm43xx_wldev
*dev
)
1855 assert(dev
->mac_suspended
>= 0);
1856 if (dev
->mac_suspended
== 0) {
1857 bcm43xx_power_saving_ctl_bits(dev
, -1, 1);
1858 bcm43xx_write32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
,
1859 bcm43xx_read32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
)
1860 & ~BCM43xx_SBF_MAC_ENABLED
);
1861 bcm43xx_read32(dev
, BCM43xx_MMIO_GEN_IRQ_REASON
); /* dummy read */
1862 for (i
= 10000; i
; i
--) {
1863 tmp
= bcm43xx_read32(dev
, BCM43xx_MMIO_GEN_IRQ_REASON
);
1864 if (tmp
& BCM43xx_IRQ_MAC_SUSPENDED
)
1868 printkl(KERN_ERR PFX
"MAC suspend failed\n");
1871 dev
->mac_suspended
++;
1874 static void bcm43xx_adjust_opmode(struct bcm43xx_wldev
*dev
)
1876 struct bcm43xx_wl
*wl
= dev
->wl
;
1880 ctl
= bcm43xx_read32(dev
, BCM43xx_MMIO_MACCTL
);
1881 /* Reset status to STA infrastructure mode. */
1882 ctl
&= ~BCM43xx_MACCTL_AP
;
1883 ctl
&= ~BCM43xx_MACCTL_KEEP_CTL
;
1884 ctl
&= ~BCM43xx_MACCTL_KEEP_BADPLCP
;
1885 ctl
&= ~BCM43xx_MACCTL_KEEP_BAD
;
1886 ctl
&= ~BCM43xx_MACCTL_PROMISC
;
1887 ctl
|= BCM43xx_MACCTL_INFRA
;
1889 if (wl
->operating
) {
1890 switch (wl
->if_type
) {
1891 case IEEE80211_IF_TYPE_AP
:
1892 ctl
|= BCM43xx_MACCTL_AP
;
1894 case IEEE80211_IF_TYPE_IBSS
:
1895 ctl
&= ~BCM43xx_MACCTL_INFRA
;
1897 case IEEE80211_IF_TYPE_STA
:
1898 case IEEE80211_IF_TYPE_MNTR
:
1899 case IEEE80211_IF_TYPE_WDS
:
1906 ctl
|= BCM43xx_MACCTL_KEEP_CTL
;
1907 if (modparam_mon_keep_bad
)
1908 ctl
|= BCM43xx_MACCTL_KEEP_BAD
;
1909 if (modparam_mon_keep_badplcp
)
1910 ctl
|= BCM43xx_MACCTL_KEEP_BADPLCP
;
1913 ctl
|= BCM43xx_MACCTL_PROMISC
;
1915 bcm43xx_write32(dev
, BCM43xx_MMIO_MACCTL
, ctl
);
1918 if ((ctl
& BCM43xx_MACCTL_INFRA
) &&
1919 !(ctl
& BCM43xx_MACCTL_AP
)) {
1920 if (dev
->dev
->bus
->chip_id
== 0x4306 &&
1921 dev
->dev
->bus
->chip_rev
== 3)
1926 bcm43xx_write16(dev
, 0x612, cfp_pretbtt
);
1929 static void bcm43xx_rate_memory_write(struct bcm43xx_wldev
*dev
,
1937 offset
+= (bcm43xx_plcp_get_ratecode_ofdm(rate
) & 0x000F) * 2;
1940 offset
+= (bcm43xx_plcp_get_ratecode_cck(rate
) & 0x000F) * 2;
1942 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SHARED
, offset
+ 0x20,
1943 bcm43xx_shm_read16(dev
, BCM43xx_SHM_SHARED
, offset
));
1946 static void bcm43xx_rate_memory_init(struct bcm43xx_wldev
*dev
)
1948 switch (dev
->phy
.type
) {
1949 case BCM43xx_PHYTYPE_A
:
1950 case BCM43xx_PHYTYPE_G
:
1951 bcm43xx_rate_memory_write(dev
, BCM43xx_OFDM_RATE_6MB
, 1);
1952 bcm43xx_rate_memory_write(dev
, BCM43xx_OFDM_RATE_12MB
, 1);
1953 bcm43xx_rate_memory_write(dev
, BCM43xx_OFDM_RATE_18MB
, 1);
1954 bcm43xx_rate_memory_write(dev
, BCM43xx_OFDM_RATE_24MB
, 1);
1955 bcm43xx_rate_memory_write(dev
, BCM43xx_OFDM_RATE_36MB
, 1);
1956 bcm43xx_rate_memory_write(dev
, BCM43xx_OFDM_RATE_48MB
, 1);
1957 bcm43xx_rate_memory_write(dev
, BCM43xx_OFDM_RATE_54MB
, 1);
1958 if (dev
->phy
.type
== BCM43xx_PHYTYPE_A
)
1961 case BCM43xx_PHYTYPE_B
:
1962 bcm43xx_rate_memory_write(dev
, BCM43xx_CCK_RATE_1MB
, 0);
1963 bcm43xx_rate_memory_write(dev
, BCM43xx_CCK_RATE_2MB
, 0);
1964 bcm43xx_rate_memory_write(dev
, BCM43xx_CCK_RATE_5MB
, 0);
1965 bcm43xx_rate_memory_write(dev
, BCM43xx_CCK_RATE_11MB
, 0);
1972 /* Set the TX-Antenna for management frames sent by firmware. */
1973 static void bcm43xx_mgmtframe_txantenna(struct bcm43xx_wldev
*dev
,
1980 case BCM43xx_ANTENNA0
:
1981 ant
|= BCM43xx_TX4_PHY_ANT0
;
1983 case BCM43xx_ANTENNA1
:
1984 ant
|= BCM43xx_TX4_PHY_ANT1
;
1986 case BCM43xx_ANTENNA_AUTO
:
1987 ant
|= BCM43xx_TX4_PHY_ANTLAST
;
1993 /* FIXME We also need to set the other flags of the PHY control field somewhere. */
1996 tmp
= bcm43xx_shm_read16(dev
, BCM43xx_SHM_SHARED
,
1997 BCM43xx_SHM_SH_BEACPHYCTL
);
1998 tmp
= (tmp
& ~BCM43xx_TX4_PHY_ANT
) | ant
;
1999 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SHARED
,
2000 BCM43xx_SHM_SH_BEACPHYCTL
, tmp
);
2002 tmp
= bcm43xx_shm_read16(dev
, BCM43xx_SHM_SHARED
,
2003 BCM43xx_SHM_SH_ACKCTSPHYCTL
);
2004 tmp
= (tmp
& ~BCM43xx_TX4_PHY_ANT
) | ant
;
2005 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SHARED
,
2006 BCM43xx_SHM_SH_ACKCTSPHYCTL
, tmp
);
2007 /* For Probe Resposes */
2008 tmp
= bcm43xx_shm_read16(dev
, BCM43xx_SHM_SHARED
,
2009 BCM43xx_SHM_SH_PRPHYCTL
);
2010 tmp
= (tmp
& ~BCM43xx_TX4_PHY_ANT
) | ant
;
2011 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SHARED
,
2012 BCM43xx_SHM_SH_PRPHYCTL
, tmp
);
2015 /* This is the opposite of bcm43xx_chip_init() */
2016 static void bcm43xx_chip_exit(struct bcm43xx_wldev
*dev
)
2018 bcm43xx_radio_turn_off(dev
);
2019 if (!modparam_noleds
)
2020 bcm43xx_leds_exit(dev
);
2021 bcm43xx_gpio_cleanup(dev
);
2022 /* firmware is released later */
2025 /* Initialize the chip
2026 * http://bcm-specs.sipsolutions.net/ChipInit
2028 static int bcm43xx_chip_init(struct bcm43xx_wldev
*dev
)
2030 struct bcm43xx_phy
*phy
= &dev
->phy
;
2035 bcm43xx_write32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
,
2036 BCM43xx_SBF_CORE_READY
2039 err
= bcm43xx_request_firmware(dev
);
2042 err
= bcm43xx_upload_microcode(dev
);
2044 goto out
; /* firmware is released later */
2046 err
= bcm43xx_gpio_init(dev
);
2048 goto out
; /* firmware is released later */
2049 err
= bcm43xx_upload_initvals(dev
);
2051 goto err_gpio_cleanup
;
2052 bcm43xx_radio_turn_on(dev
);
2053 dev
->radio_hw_enable
= bcm43xx_is_hw_radio_enabled(dev
);
2054 dprintk(KERN_INFO PFX
"Radio %s by hardware\n",
2055 (dev
->radio_hw_enable
== 0) ? "disabled" : "enabled");
2057 bcm43xx_write16(dev
, 0x03E6, 0x0000);
2058 err
= bcm43xx_phy_init(dev
);
2062 /* Select initial Interference Mitigation. */
2063 tmp
= phy
->interfmode
;
2064 phy
->interfmode
= BCM43xx_INTERFMODE_NONE
;
2065 bcm43xx_radio_set_interference_mitigation(dev
, tmp
);
2067 bcm43xx_set_rx_antenna(dev
, BCM43xx_ANTENNA_DEFAULT
);
2068 bcm43xx_mgmtframe_txantenna(dev
, BCM43xx_ANTENNA_DEFAULT
);
2070 if (phy
->type
== BCM43xx_PHYTYPE_B
) {
2071 value16
= bcm43xx_read16(dev
, 0x005E);
2073 bcm43xx_write16(dev
, 0x005E, value16
);
2075 bcm43xx_write32(dev
, 0x0100, 0x01000000);
2076 if (dev
->dev
->id
.revision
< 5)
2077 bcm43xx_write32(dev
, 0x010C, 0x01000000);
2079 value32
= bcm43xx_read32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
);
2080 value32
&= ~ BCM43xx_SBF_MODE_NOTADHOC
;
2081 bcm43xx_write32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
, value32
);
2082 value32
= bcm43xx_read32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
);
2083 value32
|= BCM43xx_SBF_MODE_NOTADHOC
;
2084 bcm43xx_write32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
, value32
);
2086 value32
= bcm43xx_read32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
);
2087 value32
|= 0x100000;
2088 bcm43xx_write32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
, value32
);
2090 if (bcm43xx_using_pio(dev
)) {
2091 bcm43xx_write32(dev
, 0x0210, 0x00000100);
2092 bcm43xx_write32(dev
, 0x0230, 0x00000100);
2093 bcm43xx_write32(dev
, 0x0250, 0x00000100);
2094 bcm43xx_write32(dev
, 0x0270, 0x00000100);
2095 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SHARED
, 0x0034, 0x0000);
2098 /* Probe Response Timeout value */
2099 /* FIXME: Default to 0, has to be set by ioctl probably... :-/ */
2100 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SHARED
, 0x0074, 0x0000);
2102 /* Initially set the wireless operation mode. */
2103 bcm43xx_adjust_opmode(dev
);
2105 if (dev
->dev
->id
.revision
< 3) {
2106 bcm43xx_write16(dev
, 0x060E, 0x0000);
2107 bcm43xx_write16(dev
, 0x0610, 0x8000);
2108 bcm43xx_write16(dev
, 0x0604, 0x0000);
2109 bcm43xx_write16(dev
, 0x0606, 0x0200);
2111 bcm43xx_write32(dev
, 0x0188, 0x80000000);
2112 bcm43xx_write32(dev
, 0x018C, 0x02000000);
2114 bcm43xx_write32(dev
, BCM43xx_MMIO_GEN_IRQ_REASON
, 0x00004000);
2115 bcm43xx_write32(dev
, BCM43xx_MMIO_DMA0_IRQ_MASK
, 0x0001DC00);
2116 bcm43xx_write32(dev
, BCM43xx_MMIO_DMA1_IRQ_MASK
, 0x0000DC00);
2117 bcm43xx_write32(dev
, BCM43xx_MMIO_DMA2_IRQ_MASK
, 0x0000DC00);
2118 bcm43xx_write32(dev
, BCM43xx_MMIO_DMA3_IRQ_MASK
, 0x0001DC00);
2119 bcm43xx_write32(dev
, BCM43xx_MMIO_DMA4_IRQ_MASK
, 0x0000DC00);
2120 bcm43xx_write32(dev
, BCM43xx_MMIO_DMA5_IRQ_MASK
, 0x0000DC00);
2122 value32
= ssb_read32(dev
->dev
, SSB_TMSLOW
);
2123 value32
|= 0x00100000;
2124 ssb_write32(dev
->dev
, SSB_TMSLOW
, value32
);
2126 bcm43xx_write16(dev
, BCM43xx_MMIO_POWERUP_DELAY
,
2127 dev
->dev
->bus
->chipco
.fast_pwrup_delay
);
2130 dprintk(KERN_INFO PFX
"Chip initialized\n");
2135 bcm43xx_radio_turn_off(dev
);
2137 bcm43xx_gpio_cleanup(dev
);
2141 static void bcm43xx_periodic_every120sec(struct bcm43xx_wldev
*dev
)
2143 struct bcm43xx_phy
*phy
= &dev
->phy
;
2145 if (phy
->type
!= BCM43xx_PHYTYPE_G
|| phy
->rev
< 2)
2148 bcm43xx_mac_suspend(dev
);
2149 bcm43xx_lo_g_measure(dev
);
2150 bcm43xx_mac_enable(dev
);
2153 static void bcm43xx_periodic_every60sec(struct bcm43xx_wldev
*dev
)
2155 bcm43xx_lo_g_ctl_mark_all_unused(dev
);
2156 if (dev
->dev
->bus
->sprom
.r1
.boardflags_lo
& BCM43xx_BFL_RSSI
) {
2157 bcm43xx_mac_suspend(dev
);
2158 bcm43xx_calc_nrssi_slope(dev
);
2159 bcm43xx_mac_enable(dev
);
2163 static void bcm43xx_periodic_every30sec(struct bcm43xx_wldev
*dev
)
2165 /* Update device statistics. */
2166 bcm43xx_calculate_link_quality(dev
);
2169 static void bcm43xx_periodic_every15sec(struct bcm43xx_wldev
*dev
)
2171 struct bcm43xx_phy
*phy
= &dev
->phy
;
2173 if (phy
->type
== BCM43xx_PHYTYPE_G
) {
2174 //TODO: update_aci_moving_average
2175 if (phy
->aci_enable
&& phy
->aci_wlan_automatic
) {
2176 bcm43xx_mac_suspend(dev
);
2177 if (!phy
->aci_enable
&& 1 /*TODO: not scanning? */) {
2178 if (0 /*TODO: bunch of conditions*/) {
2179 bcm43xx_radio_set_interference_mitigation(dev
,
2180 BCM43xx_INTERFMODE_MANUALWLAN
);
2182 } else if (1/*TODO*/) {
2184 if ((aci_average > 1000) && !(bcm43xx_radio_aci_scan(dev))) {
2185 bcm43xx_radio_set_interference_mitigation(dev,
2186 BCM43xx_INTERFMODE_NONE);
2190 bcm43xx_mac_enable(dev
);
2191 } else if (phy
->interfmode
== BCM43xx_INTERFMODE_NONWLAN
&&
2193 //TODO: implement rev1 workaround
2196 bcm43xx_phy_xmitpower(dev
); //FIXME: unless scanning?
2197 //TODO for APHY (temperature?)
2200 static void bcm43xx_periodic_every1sec(struct bcm43xx_wldev
*dev
)
2202 int radio_hw_enable
;
2204 /* check if radio hardware enabled status changed */
2205 radio_hw_enable
= bcm43xx_is_hw_radio_enabled(dev
);
2206 if (unlikely(dev
->radio_hw_enable
!= radio_hw_enable
)) {
2207 dev
->radio_hw_enable
= radio_hw_enable
;
2208 dprintk(KERN_INFO PFX
"Radio hardware status changed to %s\n",
2209 (radio_hw_enable
== 0) ? "disabled" : "enabled");
2210 bcm43xx_leds_update(dev
, 0);
2214 static void do_periodic_work(struct bcm43xx_wldev
*dev
)
2218 state
= dev
->periodic_state
;
2219 if (state
% 120 == 0)
2220 bcm43xx_periodic_every120sec(dev
);
2221 if (state
% 60 == 0)
2222 bcm43xx_periodic_every60sec(dev
);
2223 if (state
% 30 == 0)
2224 bcm43xx_periodic_every30sec(dev
);
2225 if (state
% 15 == 0)
2226 bcm43xx_periodic_every15sec(dev
);
2227 bcm43xx_periodic_every1sec(dev
);
2230 /* Estimate a "Badness" value based on the periodic work
2231 * state-machine state. "Badness" is worse (bigger), if the
2232 * periodic work will take longer.
2234 static int estimate_periodic_work_badness(unsigned int state
)
2238 if (state
% 120 == 0) /* every 120 sec */
2240 if (state
% 60 == 0) /* every 60 sec */
2242 if (state
% 30 == 0) /* every 30 sec */
2244 if (state
% 15 == 0) /* every 15 sec */
2247 #define BADNESS_LIMIT 4
2251 static void bcm43xx_periodic_work_handler(struct work_struct
*work
)
2253 struct bcm43xx_wldev
*dev
=
2254 container_of(work
, struct bcm43xx_wldev
, periodic_work
.work
);
2255 unsigned long flags
, delay
;
2259 mutex_lock(&dev
->wl
->mutex
);
2261 if (unlikely(bcm43xx_status(dev
) != BCM43xx_STAT_INITIALIZED
))
2263 if (unlikely(!dev
->started
))
2265 if (bcm43xx_debug(dev
, BCM43xx_DBG_PWORK_STOP
))
2268 badness
= estimate_periodic_work_badness(dev
->periodic_state
);
2269 if (badness
> BADNESS_LIMIT
) {
2270 spin_lock_irqsave(&dev
->wl
->irq_lock
, flags
);
2271 /* Suspend TX as we don't want to transmit packets while
2272 * we recalibrate the hardware. */
2273 bcm43xx_tx_suspend(dev
);
2274 savedirqs
= bcm43xx_interrupt_disable(dev
, BCM43xx_IRQ_ALL
);
2275 /* Periodic work will take a long time, so we want it to
2276 * be preemtible and release the spinlock. */
2277 spin_unlock_irqrestore(&dev
->wl
->irq_lock
, flags
);
2278 bcm43xx_synchronize_irq(dev
);
2280 do_periodic_work(dev
);
2282 spin_lock_irqsave(&dev
->wl
->irq_lock
, flags
);
2283 bcm43xx_interrupt_enable(dev
, savedirqs
);
2284 bcm43xx_tx_resume(dev
);
2286 spin_unlock_irqrestore(&dev
->wl
->irq_lock
, flags
);
2288 /* Take the global driver lock. This will lock any operation. */
2289 spin_lock_irqsave(&dev
->wl
->irq_lock
, flags
);
2291 do_periodic_work(dev
);
2294 spin_unlock_irqrestore(&dev
->wl
->irq_lock
, flags
);
2296 dev
->periodic_state
++;
2298 if (bcm43xx_debug(dev
, BCM43xx_DBG_PWORK_FAST
))
2299 delay
= msecs_to_jiffies(50);
2301 delay
= round_jiffies(HZ
);
2302 queue_delayed_work(dev
->wl
->hw
->workqueue
,
2303 &dev
->periodic_work
, delay
);
2305 mutex_unlock(&dev
->wl
->mutex
);
2308 static void bcm43xx_periodic_tasks_delete(struct bcm43xx_wldev
*dev
)
2310 cancel_rearming_delayed_work(&dev
->periodic_work
);
2313 static void bcm43xx_periodic_tasks_setup(struct bcm43xx_wldev
*dev
)
2315 struct delayed_work
*work
= &dev
->periodic_work
;
2317 assert(bcm43xx_status(dev
) == BCM43xx_STAT_INITIALIZED
);
2318 dev
->periodic_state
= 0;
2319 INIT_DELAYED_WORK(work
, bcm43xx_periodic_work_handler
);
2320 queue_delayed_work(dev
->wl
->hw
->workqueue
, work
, 0);
2323 /* Validate access to the chip (SHM) */
2324 static int bcm43xx_validate_chipaccess(struct bcm43xx_wldev
*dev
)
2329 shm_backup
= bcm43xx_shm_read32(dev
, BCM43xx_SHM_SHARED
, 0);
2330 bcm43xx_shm_write32(dev
, BCM43xx_SHM_SHARED
, 0, 0xAA5555AA);
2331 if (bcm43xx_shm_read32(dev
, BCM43xx_SHM_SHARED
, 0) != 0xAA5555AA)
2333 bcm43xx_shm_write32(dev
, BCM43xx_SHM_SHARED
, 0, 0x55AAAA55);
2334 if (bcm43xx_shm_read32(dev
, BCM43xx_SHM_SHARED
, 0) != 0x55AAAA55)
2336 bcm43xx_shm_write32(dev
, BCM43xx_SHM_SHARED
, 0, shm_backup
);
2338 value
= bcm43xx_read32(dev
, BCM43xx_MMIO_MACCTL
);
2339 if ((value
| BCM43xx_MACCTL_GMODE
) !=
2340 (BCM43xx_MACCTL_GMODE
| BCM43xx_MACCTL_IHR_ENABLED
))
2343 value
= bcm43xx_read32(dev
, BCM43xx_MMIO_GEN_IRQ_REASON
);
2349 printk(KERN_ERR PFX
"Failed to validate the chipaccess\n");
2353 static void bcm43xx_security_init(struct bcm43xx_wldev
*dev
)
2355 dev
->max_nr_keys
= (dev
->dev
->id
.revision
>= 5) ? 58 : 20;
2356 assert(dev
->max_nr_keys
<= ARRAY_SIZE(dev
->key
));
2357 dev
->ktp
= bcm43xx_shm_read16(dev
, BCM43xx_SHM_SHARED
,
2358 BCM43xx_SHM_SH_KTP
);
2359 /* KTP is a word address, but we address SHM bytewise.
2360 * So multiply by two.
2363 if (dev
->dev
->id
.revision
>= 5) {
2364 /* Number of RCMTA address slots */
2365 bcm43xx_write16(dev
, BCM43xx_MMIO_RCMTA_COUNT
,
2366 dev
->max_nr_keys
- 8);
2368 bcm43xx_clear_keys(dev
);
2371 static int bcm43xx_rng_read(struct hwrng
*rng
, u32
*data
)
2373 struct bcm43xx_wl
*wl
= (struct bcm43xx_wl
*)rng
->priv
;
2374 unsigned long flags
;
2376 /* Don't take wl->mutex here, as it could deadlock with
2377 * hwrng internal locking. It's not needed to take
2378 * wl->mutex here, anyway. */
2380 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2381 *data
= bcm43xx_read16(wl
->current_dev
, BCM43xx_MMIO_RNG
);
2382 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2384 return (sizeof(u16
));
2387 static void bcm43xx_rng_exit(struct bcm43xx_wl
*wl
)
2389 if (wl
->rng_initialized
)
2390 hwrng_unregister(&wl
->rng
);
2393 static int bcm43xx_rng_init(struct bcm43xx_wl
*wl
)
2397 snprintf(wl
->rng_name
, ARRAY_SIZE(wl
->rng_name
),
2398 "%s_%s", KBUILD_MODNAME
, wiphy_name(wl
->hw
->wiphy
));
2399 wl
->rng
.name
= wl
->rng_name
;
2400 wl
->rng
.data_read
= bcm43xx_rng_read
;
2401 wl
->rng
.priv
= (unsigned long)wl
;
2402 wl
->rng_initialized
= 1;
2403 err
= hwrng_register(&wl
->rng
);
2405 wl
->rng_initialized
= 0;
2406 printk(KERN_ERR PFX
"Failed to register the random "
2407 "number generator (%d)\n", err
);
2413 static int bcm43xx_tx(struct ieee80211_hw
*hw
,
2414 struct sk_buff
*skb
,
2415 struct ieee80211_tx_control
*ctl
)
2417 struct bcm43xx_wl
*wl
= hw_to_bcm43xx_wl(hw
);
2418 struct bcm43xx_wldev
*dev
= wl
->current_dev
;
2420 unsigned long flags
;
2422 /* DMA-TX is done without a global lock. */
2425 assert(bcm43xx_status(dev
) == BCM43xx_STAT_INITIALIZED
);
2426 assert(dev
->started
);
2427 if (bcm43xx_using_pio(dev
)) {
2428 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2429 err
= bcm43xx_pio_tx(dev
, skb
, ctl
);
2430 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2432 err
= bcm43xx_dma_tx(dev
, skb
, ctl
);
2435 return NETDEV_TX_BUSY
;
2436 return NETDEV_TX_OK
;
2439 static int bcm43xx_conf_tx(struct ieee80211_hw
*hw
,
2441 const struct ieee80211_tx_queue_params
*params
)
2446 static int bcm43xx_get_tx_stats(struct ieee80211_hw
*hw
,
2447 struct ieee80211_tx_queue_stats
*stats
)
2449 struct bcm43xx_wl
*wl
= hw_to_bcm43xx_wl(hw
);
2450 struct bcm43xx_wldev
*dev
= wl
->current_dev
;
2451 unsigned long flags
;
2456 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2457 if (likely(bcm43xx_status(dev
) == BCM43xx_STAT_INITIALIZED
)) {
2458 if (bcm43xx_using_pio(dev
))
2459 bcm43xx_pio_get_tx_stats(dev
, stats
);
2461 bcm43xx_dma_get_tx_stats(dev
, stats
);
2464 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2469 static int bcm43xx_get_stats(struct ieee80211_hw
*hw
,
2470 struct ieee80211_low_level_stats
*stats
)
2472 struct bcm43xx_wl
*wl
= hw_to_bcm43xx_wl(hw
);
2473 unsigned long flags
;
2475 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2476 memcpy(stats
, &wl
->ieee_stats
, sizeof(*stats
));
2477 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2482 static int bcm43xx_dev_reset(struct ieee80211_hw
*hw
)
2484 struct bcm43xx_wl
*wl
= hw_to_bcm43xx_wl(hw
);
2485 struct bcm43xx_wldev
*dev
= wl
->current_dev
;
2486 unsigned long flags
;
2490 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2491 bcm43xx_controller_restart(dev
, "Reset by ieee80211 subsystem");
2492 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2497 static const char * phymode_to_string(unsigned int phymode
)
2500 case BCM43xx_PHYMODE_A
:
2502 case BCM43xx_PHYMODE_B
:
2504 case BCM43xx_PHYMODE_G
:
2512 static int find_wldev_for_phymode(struct bcm43xx_wl
*wl
,
2513 unsigned int phymode
,
2514 struct bcm43xx_wldev
**dev
,
2517 struct bcm43xx_wldev
*d
;
2519 list_for_each_entry(d
, &wl
->devlist
, list
) {
2520 if (d
->phy
.possible_phymodes
& phymode
) {
2521 /* Ok, this device supports the PHY-mode.
2522 * Now figure out how the gmode bit has to be
2523 * set to support it. */
2524 if (phymode
== BCM43xx_PHYMODE_A
)
2537 static void bcm43xx_put_phy_into_reset(struct bcm43xx_wldev
*dev
)
2539 struct ssb_device
*sdev
= dev
->dev
;
2542 tmslow
= ssb_read32(sdev
, SSB_TMSLOW
);
2543 tmslow
&= ~BCM43xx_TMSLOW_GMODE
;
2544 tmslow
|= BCM43xx_TMSLOW_PHYRESET
;
2545 tmslow
|= SSB_TMSLOW_FGC
;
2546 ssb_write32(sdev
, SSB_TMSLOW
, tmslow
);
2549 tmslow
= ssb_read32(sdev
, SSB_TMSLOW
);
2550 tmslow
&= ~SSB_TMSLOW_FGC
;
2551 tmslow
|= BCM43xx_TMSLOW_PHYRESET
;
2552 ssb_write32(sdev
, SSB_TMSLOW
, tmslow
);
2556 static int bcm43xx_switch_phymode(struct bcm43xx_wl
*wl
,
2557 unsigned int new_mode
)
2559 struct bcm43xx_wldev
*up_dev
;
2560 struct bcm43xx_wldev
*down_dev
;
2563 int old_was_started
= 0;
2564 int old_was_inited
= 0;
2566 err
= find_wldev_for_phymode(wl
, new_mode
, &up_dev
, &gmode
);
2568 printk(KERN_INFO PFX
"Could not find a device for %s-PHY mode\n",
2569 phymode_to_string(new_mode
));
2572 assert(gmode
== 0 || gmode
== 1);
2573 if ((up_dev
== wl
->current_dev
) &&
2574 (wl
->current_dev
->phy
.gmode
== gmode
)) {
2575 /* This device is already running. */
2578 dprintk(KERN_INFO PFX
"Reconfiguring PHYmode to %s-PHY\n",
2579 phymode_to_string(new_mode
));
2580 down_dev
= wl
->current_dev
;
2582 /* Shutdown the currently running core. */
2583 if (down_dev
->started
) {
2584 old_was_started
= 1;
2585 bcm43xx_wireless_core_stop(down_dev
);
2587 if (bcm43xx_status(down_dev
) == BCM43xx_STAT_INITIALIZED
) {
2589 bcm43xx_wireless_core_exit(down_dev
);
2592 if (down_dev
!= up_dev
) {
2593 /* We switch to a different core, so we put PHY into
2594 * RESET on the old core. */
2595 bcm43xx_put_phy_into_reset(down_dev
);
2598 /* Now start the new core. */
2599 up_dev
->phy
.gmode
= gmode
;
2600 if (old_was_inited
) {
2601 err
= bcm43xx_wireless_core_init(up_dev
);
2603 printk(KERN_INFO PFX
"Fatal: Could not initialize device for "
2604 "new selected %s-PHY mode\n",
2605 phymode_to_string(new_mode
));
2609 if (old_was_started
) {
2610 assert(old_was_inited
);
2611 err
= bcm43xx_wireless_core_start(up_dev
);
2613 printk(KERN_INFO PFX
"Fatal: Coult not start device for "
2614 "new selected %s-PHY mode\n",
2615 phymode_to_string(new_mode
));
2616 bcm43xx_wireless_core_exit(up_dev
);
2621 wl
->current_dev
= up_dev
;
2626 static int bcm43xx_antenna_from_ieee80211(u8 antenna
)
2629 case 0: /* default/diversity */
2630 return BCM43xx_ANTENNA_DEFAULT
;
2631 case 1: /* Antenna 0 */
2632 return BCM43xx_ANTENNA0
;
2633 case 2: /* Antenna 1 */
2634 return BCM43xx_ANTENNA1
;
2636 return BCM43xx_ANTENNA_DEFAULT
;
2640 static int bcm43xx_dev_config(struct ieee80211_hw
*hw
,
2641 struct ieee80211_conf
*conf
)
2643 struct bcm43xx_wl
*wl
= hw_to_bcm43xx_wl(hw
);
2644 struct bcm43xx_wldev
*dev
;
2645 struct bcm43xx_phy
*phy
;
2646 unsigned long flags
;
2647 unsigned int new_phymode
= 0xFFFF;
2653 antenna_tx
= bcm43xx_antenna_from_ieee80211(conf
->antenna_sel_tx
);
2654 antenna_rx
= bcm43xx_antenna_from_ieee80211(conf
->antenna_sel_rx
);
2656 mutex_lock(&wl
->mutex
);
2658 /* Switch the PHY mode (if necessary). */
2659 switch (conf
->phymode
) {
2660 case MODE_IEEE80211A
:
2661 new_phymode
= BCM43xx_PHYMODE_A
;
2663 case MODE_IEEE80211B
:
2664 new_phymode
= BCM43xx_PHYMODE_B
;
2666 case MODE_IEEE80211G
:
2667 new_phymode
= BCM43xx_PHYMODE_G
;
2672 err
= bcm43xx_switch_phymode(wl
, new_phymode
);
2674 goto out_unlock_mutex
;
2675 dev
= wl
->current_dev
;
2678 /* Disable IRQs while reconfiguring the device.
2679 * This makes it possible to drop the spinlock throughout
2680 * the reconfiguration process. */
2681 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2682 if ((bcm43xx_status(dev
) != BCM43xx_STAT_INITIALIZED
) ||
2684 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2685 goto out_unlock_mutex
;
2687 savedirqs
= bcm43xx_interrupt_disable(dev
, BCM43xx_IRQ_ALL
);
2688 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2689 bcm43xx_synchronize_irq(dev
);
2691 /* Switch to the requested channel.
2692 * The firmware takes care of races with the TX handler. */
2693 if (conf
->channel_val
!= phy
->channel
)
2694 bcm43xx_radio_selectchannel(dev
, conf
->channel_val
, 0);
2696 /* Enable/Disable ShortSlot timing. */
2697 if ((!!(conf
->flags
& IEEE80211_CONF_SHORT_SLOT_TIME
)) != dev
->short_slot
) {
2698 assert(phy
->type
== BCM43xx_PHYTYPE_G
);
2699 if (conf
->flags
& IEEE80211_CONF_SHORT_SLOT_TIME
)
2700 bcm43xx_short_slot_timing_enable(dev
);
2702 bcm43xx_short_slot_timing_disable(dev
);
2705 /* Adjust the desired TX power level. */
2706 if (conf
->power_level
!= 0) {
2707 if (conf
->power_level
!= phy
->power_level
) {
2708 phy
->power_level
= conf
->power_level
;
2709 bcm43xx_phy_xmitpower(dev
);
2713 /* Hide/Show the SSID (AP mode only). */
2714 if (conf
->flags
& IEEE80211_CONF_SSID_HIDDEN
) {
2715 bcm43xx_write32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
,
2716 bcm43xx_read32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
)
2717 | BCM43xx_SBF_NO_SSID_BCAST
);
2719 bcm43xx_write32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
,
2720 bcm43xx_read32(dev
, BCM43xx_MMIO_STATUS_BITFIELD
)
2721 & ~BCM43xx_SBF_NO_SSID_BCAST
);
2724 /* Antennas for RX and management frame TX. */
2725 bcm43xx_mgmtframe_txantenna(dev
, antenna_tx
);
2726 bcm43xx_set_rx_antenna(dev
, antenna_rx
);
2728 /* Update templates for AP mode. */
2729 if (bcm43xx_is_mode(wl
, IEEE80211_IF_TYPE_AP
))
2730 bcm43xx_set_beacon_int(dev
, conf
->beacon_int
);
2733 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2734 bcm43xx_interrupt_enable(dev
, savedirqs
);
2736 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2738 mutex_unlock(&wl
->mutex
);
2743 static int bcm43xx_dev_set_key(struct ieee80211_hw
*hw
,
2746 struct ieee80211_key_conf
*key
,
2749 struct bcm43xx_wl
*wl
= hw_to_bcm43xx_wl(hw
);
2750 struct bcm43xx_wldev
*dev
= wl
->current_dev
;
2751 unsigned long flags
;
2761 algorithm
= BCM43xx_SEC_ALGO_NONE
;
2764 if (key
->keylen
== 5)
2765 algorithm
= BCM43xx_SEC_ALGO_WEP40
;
2767 algorithm
= BCM43xx_SEC_ALGO_WEP104
;
2770 algorithm
= BCM43xx_SEC_ALGO_TKIP
;
2773 algorithm
= BCM43xx_SEC_ALGO_AES
;
2780 index
= (u8
)(key
->keyidx
);
2784 mutex_lock(&wl
->mutex
);
2785 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2787 if (bcm43xx_status(dev
) != BCM43xx_STAT_INITIALIZED
) {
2794 key
->flags
&= ~IEEE80211_KEY_FORCE_SW_ENCRYPT
;
2796 if (algorithm
== BCM43xx_SEC_ALGO_TKIP
) {
2797 /* FIXME: No TKIP hardware encryption for now. */
2798 key
->flags
|= IEEE80211_KEY_FORCE_SW_ENCRYPT
;
2801 if (is_broadcast_ether_addr(addr
)) {
2802 /* addr is FF:FF:FF:FF:FF:FF for default keys */
2803 err
= bcm43xx_key_write(dev
, index
, algorithm
,
2804 key
->key
, key
->keylen
,
2807 err
= bcm43xx_key_write(dev
, -1, algorithm
,
2808 key
->key
, key
->keylen
,
2812 key
->flags
|= IEEE80211_KEY_FORCE_SW_ENCRYPT
;
2815 dev
->key
[key
->hw_key_idx
].enabled
= 1;
2817 if (algorithm
== BCM43xx_SEC_ALGO_WEP40
||
2818 algorithm
== BCM43xx_SEC_ALGO_WEP104
) {
2819 bcm43xx_hf_write(dev
,
2820 bcm43xx_hf_read(dev
) |
2821 BCM43xx_HF_USEDEFKEYS
);
2823 bcm43xx_hf_write(dev
,
2824 bcm43xx_hf_read(dev
) &
2825 ~BCM43xx_HF_USEDEFKEYS
);
2829 static const u8 zero
[BCM43xx_SEC_KEYSIZE
] = { 0 };
2831 algorithm
= BCM43xx_SEC_ALGO_NONE
;
2832 if (is_broadcast_ether_addr(addr
)) {
2833 err
= bcm43xx_key_write(dev
, index
, algorithm
,
2834 zero
, BCM43xx_SEC_KEYSIZE
,
2837 err
= bcm43xx_key_write(dev
, -1, algorithm
,
2838 zero
, BCM43xx_SEC_KEYSIZE
,
2841 dev
->key
[key
->hw_key_idx
].enabled
= 0;
2844 case REMOVE_ALL_KEYS
:
2845 bcm43xx_clear_keys(dev
);
2852 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2853 mutex_unlock(&wl
->mutex
);
2856 dprintk(KERN_DEBUG PFX
"Using %s based encryption for keyidx: %d, "
2857 "mac: " MAC_FMT
"\n",
2858 (key
->flags
& IEEE80211_KEY_FORCE_SW_ENCRYPT
) ?
2859 "software" : "hardware",
2860 key
->keyidx
, MAC_ARG(addr
));
2865 static void bcm43xx_set_multicast_list(struct ieee80211_hw
*hw
,
2866 unsigned short netflags
,
2869 struct bcm43xx_wl
*wl
= hw_to_bcm43xx_wl(hw
);
2870 struct bcm43xx_wldev
*dev
= wl
->current_dev
;
2871 unsigned long flags
;
2875 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2876 if (wl
->promisc
!= !!(netflags
& IFF_PROMISC
)) {
2877 wl
->promisc
= !!(netflags
& IFF_PROMISC
);
2878 if (bcm43xx_status(dev
) == BCM43xx_STAT_INITIALIZED
)
2879 bcm43xx_adjust_opmode(dev
);
2881 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2884 static int bcm43xx_config_interface(struct ieee80211_hw
*hw
,
2886 struct ieee80211_if_conf
*conf
)
2888 struct bcm43xx_wl
*wl
= hw_to_bcm43xx_wl(hw
);
2889 struct bcm43xx_wldev
*dev
= wl
->current_dev
;
2890 unsigned long flags
;
2894 mutex_lock(&wl
->mutex
);
2895 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2896 if (conf
->type
!= IEEE80211_IF_TYPE_MNTR
) {
2897 assert(wl
->if_id
== if_id
);
2898 wl
->bssid
= conf
->bssid
;
2899 if (bcm43xx_is_mode(wl
, IEEE80211_IF_TYPE_AP
)) {
2900 assert(conf
->type
== IEEE80211_IF_TYPE_AP
);
2901 bcm43xx_set_ssid(dev
, conf
->ssid
, conf
->ssid_len
);
2903 bcm43xx_refresh_templates(dev
, conf
->beacon
);
2905 bcm43xx_write_mac_bssid_templates(dev
);
2907 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2908 mutex_unlock(&wl
->mutex
);
2913 /* Locking: wl->mutex */
2914 static void bcm43xx_wireless_core_stop(struct bcm43xx_wldev
*dev
)
2916 struct bcm43xx_wl
*wl
= dev
->wl
;
2917 unsigned long flags
;
2923 mutex_unlock(&wl
->mutex
);
2924 /* Must unlock as it would otherwise deadlock. No races here. */
2925 bcm43xx_periodic_tasks_delete(dev
);
2926 flush_workqueue(dev
->wl
->hw
->workqueue
);
2927 mutex_lock(&wl
->mutex
);
2929 ieee80211_stop_queues(wl
->hw
); //FIXME this could cause a deadlock, as mac80211 seems buggy.
2931 /* Disable and sync interrupts. */
2932 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2933 dev
->irq_savedstate
= bcm43xx_interrupt_disable(dev
, BCM43xx_IRQ_ALL
);
2934 bcm43xx_read32(dev
, BCM43xx_MMIO_GEN_IRQ_MASK
); /* flush */
2935 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2936 bcm43xx_synchronize_irq(dev
);
2938 bcm43xx_mac_suspend(dev
);
2939 free_irq(dev
->dev
->irq
, dev
);
2940 dprintk(KERN_INFO PFX
"Wireless interface stopped\n");
2943 /* Locking: wl->mutex */
2944 static int bcm43xx_wireless_core_start(struct bcm43xx_wldev
*dev
)
2946 struct bcm43xx_wl
*wl
= dev
->wl
;
2949 assert(!dev
->started
);
2951 drain_txstatus_queue(dev
);
2952 err
= request_irq(dev
->dev
->irq
, bcm43xx_interrupt_handler
,
2953 IRQF_SHARED
, KBUILD_MODNAME
, dev
);
2955 printk(KERN_ERR PFX
"Cannot request IRQ-%d\n",
2960 bcm43xx_interrupt_enable(dev
, dev
->irq_savedstate
);
2961 bcm43xx_mac_enable(dev
);
2963 ieee80211_start_queues(wl
->hw
);
2964 bcm43xx_periodic_tasks_setup(dev
);
2965 dprintk(KERN_INFO PFX
"Wireless interface started\n");
2970 /* Get PHY and RADIO versioning numbers */
2971 static int bcm43xx_phy_versioning(struct bcm43xx_wldev
*dev
)
2973 struct bcm43xx_phy
*phy
= &dev
->phy
;
2981 int unsupported
= 0;
2983 /* Get PHY versioning */
2984 tmp
= bcm43xx_read16(dev
, BCM43xx_MMIO_PHY_VER
);
2985 analog_type
= (tmp
& BCM43xx_PHYVER_ANALOG
) >> BCM43xx_PHYVER_ANALOG_SHIFT
;
2986 phy_type
= (tmp
& BCM43xx_PHYVER_TYPE
) >> BCM43xx_PHYVER_TYPE_SHIFT
;
2987 phy_rev
= (tmp
& BCM43xx_PHYVER_VERSION
);
2989 case BCM43xx_PHYTYPE_A
:
2993 case BCM43xx_PHYTYPE_B
:
2994 if (phy_rev
!= 2 && phy_rev
!= 4 && phy_rev
!= 6 && phy_rev
!= 7)
2997 case BCM43xx_PHYTYPE_G
:
3005 printk(KERN_ERR PFX
"FOUND UNSUPPORTED PHY "
3006 "(Analog %u, Type %u, Revision %u)\n",
3007 analog_type
, phy_type
, phy_rev
);
3010 dprintk(KERN_INFO PFX
"Found PHY: Analog %u, Type %u, Revision %u\n",
3011 analog_type
, phy_type
, phy_rev
);
3014 /* Get RADIO versioning */
3015 if (dev
->dev
->bus
->chip_id
== 0x4317) {
3016 if (dev
->dev
->bus
->chip_rev
== 0)
3018 else if (dev
->dev
->bus
->chip_rev
== 1)
3023 bcm43xx_write16(dev
, BCM43xx_MMIO_RADIO_CONTROL
,
3024 BCM43xx_RADIOCTL_ID
);
3025 tmp
= bcm43xx_read16(dev
, BCM43xx_MMIO_RADIO_DATA_HIGH
);
3027 bcm43xx_write16(dev
, BCM43xx_MMIO_RADIO_CONTROL
,
3028 BCM43xx_RADIOCTL_ID
);
3029 tmp
|= bcm43xx_read16(dev
, BCM43xx_MMIO_RADIO_DATA_LOW
);
3031 radio_manuf
= (tmp
& 0x00000FFF);
3032 radio_ver
= (tmp
& 0x0FFFF000) >> 12;
3033 radio_rev
= (tmp
& 0xF0000000) >> 28;
3035 case BCM43xx_PHYTYPE_A
:
3036 if (radio_ver
!= 0x2060)
3040 if (radio_manuf
!= 0x17F)
3043 case BCM43xx_PHYTYPE_B
:
3044 if ((radio_ver
& 0xFFF0) != 0x2050)
3047 case BCM43xx_PHYTYPE_G
:
3048 if (radio_ver
!= 0x2050)
3055 printk(KERN_ERR PFX
"FOUND UNSUPPORTED RADIO "
3056 "(Manuf 0x%X, Version 0x%X, Revision %u)\n",
3057 radio_manuf
, radio_ver
, radio_rev
);
3060 dprintk(KERN_INFO PFX
"Found Radio: Manuf 0x%X, Version 0x%X, Revision %u\n",
3061 radio_manuf
, radio_ver
, radio_rev
);
3064 phy
->radio_manuf
= radio_manuf
;
3065 phy
->radio_ver
= radio_ver
;
3066 phy
->radio_rev
= radio_rev
;
3068 phy
->analog
= analog_type
;
3069 phy
->type
= phy_type
;
3075 static void setup_struct_phy_for_init(struct bcm43xx_wldev
*dev
,
3076 struct bcm43xx_phy
*phy
)
3078 struct bcm43xx_txpower_lo_control
*lo
;
3081 memset(phy
->minlowsig
, 0xFF, sizeof(phy
->minlowsig
));
3082 memset(phy
->minlowsigpos
, 0, sizeof(phy
->minlowsigpos
));
3087 phy
->aci_enable
= 0;
3088 phy
->aci_wlan_automatic
= 0;
3089 phy
->aci_hw_rssi
= 0;
3091 lo
= phy
->lo_control
;
3093 memset(lo
, 0, sizeof(*(phy
->lo_control
)));
3097 phy
->max_lb_gain
= 0;
3098 phy
->trsw_rx_gain
= 0;
3099 phy
->txpwr_offset
= 0;
3102 phy
->nrssislope
= 0;
3103 for (i
= 0; i
< ARRAY_SIZE(phy
->nrssi
); i
++)
3104 phy
->nrssi
[i
] = -1000;
3105 for (i
= 0; i
< ARRAY_SIZE(phy
->nrssi_lt
); i
++)
3106 phy
->nrssi_lt
[i
] = i
;
3108 phy
->lofcal
= 0xFFFF;
3109 phy
->initval
= 0xFFFF;
3111 spin_lock_init(&phy
->lock
);
3112 phy
->interfmode
= BCM43xx_INTERFMODE_NONE
;
3113 phy
->channel
= 0xFF;
3116 static void setup_struct_wldev_for_init(struct bcm43xx_wldev
*dev
)
3119 dev
->reg124_set_0x4
= 0;
3122 memset(&dev
->stats
, 0, sizeof(dev
->stats
));
3124 setup_struct_phy_for_init(dev
, &dev
->phy
);
3126 /* IRQ related flags */
3127 dev
->irq_reason
= 0;
3128 memset(dev
->dma_reason
, 0, sizeof(dev
->dma_reason
));
3129 dev
->irq_savedstate
= BCM43xx_IRQ_MASKTEMPLATE
;
3131 dev
->mac_suspended
= 1;
3133 /* Noise calculation context */
3134 memset(&dev
->noisecalc
, 0, sizeof(dev
->noisecalc
));
3137 static void bcm43xx_bluetooth_coext_enable(struct bcm43xx_wldev
*dev
)
3139 struct ssb_sprom
*sprom
= &dev
->dev
->bus
->sprom
;
3142 if (!(sprom
->r1
.boardflags_lo
& BCM43xx_BFL_BTCOEXIST
))
3144 if (dev
->phy
.type
!= BCM43xx_PHYTYPE_B
&& !dev
->phy
.gmode
)
3147 hf
= bcm43xx_hf_read(dev
);
3148 if (sprom
->r1
.boardflags_lo
& BCM43xx_BFL_BTCMOD
)
3149 hf
|= BCM43xx_HF_BTCOEXALT
;
3151 hf
|= BCM43xx_HF_BTCOEX
;
3152 bcm43xx_hf_write(dev
, hf
);
3156 static void bcm43xx_bluetooth_coext_disable(struct bcm43xx_wldev
*dev
)
3160 static void bcm43xx_imcfglo_timeouts_workaround(struct bcm43xx_wldev
*dev
)
3162 #ifdef CONFIG_SSB_DRIVER_PCICORE
3163 struct ssb_bus
*bus
= dev
->dev
->bus
;
3166 if (bus
->pcicore
.dev
&&
3167 bus
->pcicore
.dev
->id
.coreid
== SSB_DEV_PCI
&&
3168 bus
->pcicore
.dev
->id
.revision
<= 5) {
3169 /* IMCFGLO timeouts workaround. */
3170 tmp
= ssb_read32(dev
->dev
, SSB_IMCFGLO
);
3171 tmp
&= ~SSB_IMCFGLO_REQTO
;
3172 tmp
&= ~SSB_IMCFGLO_SERTO
;
3173 switch (bus
->bustype
) {
3174 case SSB_BUSTYPE_PCI
:
3175 case SSB_BUSTYPE_PCMCIA
:
3178 case SSB_BUSTYPE_SSB
:
3182 ssb_write32(dev
->dev
, SSB_IMCFGLO
, tmp
);
3184 #endif /* CONFIG_SSB_DRIVER_PCICORE */
3187 /* Shutdown a wireless core */
3188 static void bcm43xx_wireless_core_exit(struct bcm43xx_wldev
*dev
)
3190 struct bcm43xx_phy
*phy
= &dev
->phy
;
3192 if (bcm43xx_status(dev
) != BCM43xx_STAT_INITIALIZED
)
3195 bcm43xx_rng_exit(dev
->wl
);
3196 bcm43xx_pio_free(dev
);
3197 bcm43xx_dma_free(dev
);
3198 bcm43xx_chip_exit(dev
);
3199 bcm43xx_radio_turn_off(dev
);
3200 bcm43xx_switch_analog(dev
, 0);
3201 if (phy
->dyn_tssi_tbl
)
3202 kfree(phy
->tssi2dbm
);
3203 kfree(phy
->lo_control
);
3204 phy
->lo_control
= NULL
;
3205 ssb_device_disable(dev
->dev
, 0);
3206 ssb_bus_may_powerdown(dev
->dev
->bus
);
3207 bcm43xx_set_status(dev
, BCM43xx_STAT_UNINIT
);
3210 /* Initialize a wireless core */
3211 static int bcm43xx_wireless_core_init(struct bcm43xx_wldev
*dev
)
3213 struct bcm43xx_wl
*wl
= dev
->wl
;
3214 struct ssb_bus
*bus
= dev
->dev
->bus
;
3215 struct ssb_sprom
*sprom
= &bus
->sprom
;
3216 struct bcm43xx_phy
*phy
= &dev
->phy
;
3220 assert(bcm43xx_status(dev
) == BCM43xx_STAT_UNINIT
);
3221 bcm43xx_set_status(dev
, BCM43xx_STAT_INITIALIZING
);
3223 err
= ssb_bus_powerup(bus
, 0);
3226 if (!ssb_device_is_enabled(dev
->dev
)) {
3227 tmp
= phy
->gmode
? BCM43xx_TMSLOW_GMODE
: 0;
3228 bcm43xx_wireless_core_reset(dev
, tmp
);
3231 if ((phy
->type
== BCM43xx_PHYTYPE_B
) || (phy
->type
== BCM43xx_PHYTYPE_G
)) {
3232 phy
->lo_control
= kzalloc(sizeof(*(phy
->lo_control
)), GFP_KERNEL
);
3233 if (!phy
->lo_control
) {
3238 setup_struct_wldev_for_init(dev
);
3240 err
= bcm43xx_phy_init_tssi2dbm_table(dev
);
3242 goto err_kfree_lo_control
;
3244 /* Enable IRQ routing to this device. */
3245 ssb_pcicore_dev_irqvecs_enable(&bus
->pcicore
, dev
->dev
);
3247 bcm43xx_imcfglo_timeouts_workaround(dev
);
3248 bcm43xx_bluetooth_coext_disable(dev
);
3249 bcm43xx_phy_early_init(dev
);
3250 err
= bcm43xx_chip_init(dev
);
3252 goto err_kfree_tssitbl
;
3253 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SHARED
,
3254 BCM43xx_SHM_SH_WLCOREREV
,
3255 dev
->dev
->id
.revision
);
3256 hf
= bcm43xx_hf_read(dev
);
3257 if (phy
->type
== BCM43xx_PHYTYPE_G
) {
3258 hf
|= BCM43xx_HF_SYMW
;
3260 hf
|= BCM43xx_HF_GDCW
;
3261 if (sprom
->r1
.boardflags_lo
& BCM43xx_BFL_PACTRL
)
3262 hf
|= BCM43xx_HF_OFDMPABOOST
;
3263 } else if (phy
->type
== BCM43xx_PHYTYPE_B
) {
3264 hf
|= BCM43xx_HF_SYMW
;
3265 if (phy
->rev
>= 2 && phy
->radio_ver
== 0x2050)
3266 hf
&= ~BCM43xx_HF_GDCW
;
3268 bcm43xx_hf_write(dev
, hf
);
3270 /* Short/Long Retry Limit.
3271 * The retry-limit is a 4-bit counter. Enforce this to avoid overflowing
3272 * the chip-internal counter.
3274 tmp
= limit_value(modparam_short_retry
, 0, 0xF);
3275 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SCRATCH
,
3276 BCM43xx_SHM_SC_SRLIMIT
, tmp
);
3277 tmp
= limit_value(modparam_long_retry
, 0, 0xF);
3278 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SCRATCH
,
3279 BCM43xx_SHM_SC_LRLIMIT
, tmp
);
3281 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SHARED
,
3282 BCM43xx_SHM_SH_SFFBLIM
, 3);
3283 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SHARED
,
3284 BCM43xx_SHM_SH_LFFBLIM
, 2);
3286 bcm43xx_rate_memory_init(dev
);
3288 /* Minimum Contention Window */
3289 if (phy
->type
== BCM43xx_PHYTYPE_B
) {
3290 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SCRATCH
,
3291 BCM43xx_SHM_SC_MINCONT
, 0x1F);
3293 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SCRATCH
,
3294 BCM43xx_SHM_SC_MINCONT
, 0xF);
3296 /* Maximum Contention Window */
3297 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SCRATCH
,
3298 BCM43xx_SHM_SC_MAXCONT
, 0x3FF);
3301 if (bcm43xx_using_pio(dev
)) {
3302 err
= bcm43xx_pio_init(dev
);
3304 err
= bcm43xx_dma_init(dev
);
3306 bcm43xx_qos_init(dev
);
3308 } while (err
== -EAGAIN
);
3314 bcm43xx_write16(dev
, 0x0612, 0x0050);
3315 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SHARED
, 0x0416, 0x0050);
3316 bcm43xx_shm_write16(dev
, BCM43xx_SHM_SHARED
, 0x0414, 0x01F4);
3319 bcm43xx_bluetooth_coext_enable(dev
);
3321 ssb_bus_powerup(bus
, 1); /* Enable dynamic PCTL */
3323 bcm43xx_upload_card_macaddress(dev
, NULL
);
3324 bcm43xx_security_init(dev
);
3325 bcm43xx_rng_init(wl
);
3327 bcm43xx_set_status(dev
, BCM43xx_STAT_INITIALIZED
);
3333 bcm43xx_chip_exit(dev
);
3335 if (phy
->dyn_tssi_tbl
)
3336 kfree(phy
->tssi2dbm
);
3337 err_kfree_lo_control
:
3338 kfree(phy
->lo_control
);
3339 phy
->lo_control
= NULL
;
3341 ssb_bus_may_powerdown(bus
);
3342 bcm43xx_set_status(dev
, BCM43xx_STAT_UNINIT
);
3346 static int bcm43xx_add_interface(struct ieee80211_hw
*hw
,
3347 struct ieee80211_if_init_conf
*conf
)
3349 struct bcm43xx_wl
*wl
= hw_to_bcm43xx_wl(hw
);
3350 struct bcm43xx_wldev
*dev
;
3351 unsigned long flags
;
3352 int err
= -EOPNOTSUPP
;
3355 mutex_lock(&wl
->mutex
);
3356 if ((conf
->type
!= IEEE80211_IF_TYPE_MNTR
) &&
3358 goto out_mutex_unlock
;
3360 dprintk(KERN_INFO PFX
"Adding Interface type %d\n", conf
->type
);
3362 dev
= wl
->current_dev
;
3363 if (bcm43xx_status(dev
) == BCM43xx_STAT_UNINIT
) {
3364 err
= bcm43xx_wireless_core_init(dev
);
3366 goto out_mutex_unlock
;
3369 if (!dev
->started
) {
3370 err
= bcm43xx_wireless_core_start(dev
);
3373 bcm43xx_wireless_core_exit(dev
);
3374 goto out_mutex_unlock
;
3378 spin_lock_irqsave(&wl
->irq_lock
, flags
);
3379 switch (conf
->type
) {
3380 case IEEE80211_IF_TYPE_MNTR
:
3385 wl
->if_id
= conf
->if_id
;
3386 wl
->if_type
= conf
->type
;
3387 bcm43xx_upload_card_macaddress(dev
, conf
->mac_addr
);
3389 bcm43xx_adjust_opmode(dev
);
3390 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
3394 mutex_unlock(&wl
->mutex
);
3399 static void bcm43xx_remove_interface(struct ieee80211_hw
*hw
,
3400 struct ieee80211_if_init_conf
*conf
)
3402 struct bcm43xx_wl
*wl
= hw_to_bcm43xx_wl(hw
);
3403 struct bcm43xx_wldev
*dev
;
3404 unsigned long flags
;
3406 dprintk(KERN_INFO PFX
"Removing Interface type %d\n", conf
->type
);
3408 mutex_lock(&wl
->mutex
);
3409 if (conf
->type
== IEEE80211_IF_TYPE_MNTR
) {
3411 assert(wl
->monitor
>= 0);
3413 assert(wl
->operating
);
3417 dev
= wl
->current_dev
;
3418 if (!wl
->operating
&& wl
->monitor
== 0) {
3419 /* No interface left. */
3421 bcm43xx_wireless_core_stop(dev
);
3422 bcm43xx_wireless_core_exit(dev
);
3424 /* Just monitor interfaces left. */
3425 spin_lock_irqsave(&wl
->irq_lock
, flags
);
3426 bcm43xx_adjust_opmode(dev
);
3428 bcm43xx_upload_card_macaddress(dev
, NULL
);
3429 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
3431 mutex_unlock(&wl
->mutex
);
3435 static const struct ieee80211_ops bcm43xx_hw_ops
= {
3437 .conf_tx
= bcm43xx_conf_tx
,
3438 .add_interface
= bcm43xx_add_interface
,
3439 .remove_interface
= bcm43xx_remove_interface
,
3440 .reset
= bcm43xx_dev_reset
,
3441 .config
= bcm43xx_dev_config
,
3442 .config_interface
= bcm43xx_config_interface
,
3443 .set_multicast_list
= bcm43xx_set_multicast_list
,
3444 .set_key
= bcm43xx_dev_set_key
,
3445 .get_stats
= bcm43xx_get_stats
,
3446 .get_tx_stats
= bcm43xx_get_tx_stats
,
3449 /* Hard-reset the chip. Do not call this directly.
3450 * Use bcm43xx_controller_restart()
3452 static void bcm43xx_chip_reset(struct work_struct
*work
)
3454 struct bcm43xx_wldev
*dev
=
3455 container_of(work
, struct bcm43xx_wldev
, restart_work
);
3456 struct bcm43xx_wl
*wl
= dev
->wl
;
3458 int was_started
= 0;
3461 mutex_lock(&wl
->mutex
);
3463 /* Bring the device down... */
3466 bcm43xx_wireless_core_stop(dev
);
3468 if (bcm43xx_status(dev
) == BCM43xx_STAT_INITIALIZED
) {
3470 bcm43xx_wireless_core_exit(dev
);
3473 /* ...and up again. */
3475 err
= bcm43xx_wireless_core_init(dev
);
3481 err
= bcm43xx_wireless_core_start(dev
);
3483 bcm43xx_wireless_core_exit(dev
);
3488 mutex_unlock(&wl
->mutex
);
3490 printk(KERN_ERR PFX
"Controller restart FAILED\n");
3492 printk(KERN_INFO PFX
"Controller restarted\n");
3495 static int bcm43xx_setup_modes(struct bcm43xx_wldev
*dev
,
3500 struct ieee80211_hw
*hw
= dev
->wl
->hw
;
3501 struct ieee80211_hw_mode
*mode
;
3502 struct bcm43xx_phy
*phy
= &dev
->phy
;
3506 /*FIXME: Don't tell ieee80211 about an A-PHY, because we currently don't support A-PHY. */
3509 phy
->possible_phymodes
= 0;
3512 assert(cnt
< BCM43xx_MAX_PHYHWMODES
);
3513 mode
= &phy
->hwmodes
[cnt
];
3515 mode
->mode
= MODE_IEEE80211A
;
3516 mode
->num_channels
= bcm43xx_a_chantable_size
;
3517 mode
->channels
= bcm43xx_a_chantable
;
3518 mode
->num_rates
= bcm43xx_a_ratetable_size
;
3519 mode
->rates
= bcm43xx_a_ratetable
;
3520 err
= ieee80211_register_hwmode(hw
, mode
);
3524 phy
->possible_phymodes
|= BCM43xx_PHYMODE_A
;
3529 assert(cnt
< BCM43xx_MAX_PHYHWMODES
);
3530 mode
= &phy
->hwmodes
[cnt
];
3532 mode
->mode
= MODE_IEEE80211B
;
3533 mode
->num_channels
= bcm43xx_bg_chantable_size
;
3534 mode
->channels
= bcm43xx_bg_chantable
;
3535 mode
->num_rates
= bcm43xx_b_ratetable_size
;
3536 mode
->rates
= bcm43xx_b_ratetable
;
3537 err
= ieee80211_register_hwmode(hw
, mode
);
3541 phy
->possible_phymodes
|= BCM43xx_PHYMODE_B
;
3546 assert(cnt
< BCM43xx_MAX_PHYHWMODES
);
3547 mode
= &phy
->hwmodes
[cnt
];
3549 mode
->mode
= MODE_IEEE80211G
;
3550 mode
->num_channels
= bcm43xx_bg_chantable_size
;
3551 mode
->channels
= bcm43xx_bg_chantable
;
3552 mode
->num_rates
= bcm43xx_g_ratetable_size
;
3553 mode
->rates
= bcm43xx_g_ratetable
;
3554 err
= ieee80211_register_hwmode(hw
, mode
);
3558 phy
->possible_phymodes
|= BCM43xx_PHYMODE_G
;
3568 static void bcm43xx_wireless_core_detach(struct bcm43xx_wldev
*dev
)
3570 /* We release firmware that late to not be required to re-request
3571 * is all the time when we reinit the core. */
3572 bcm43xx_release_firmware(dev
);
3575 static int bcm43xx_wireless_core_attach(struct bcm43xx_wldev
*dev
)
3577 struct bcm43xx_wl
*wl
= dev
->wl
;
3578 struct ssb_bus
*bus
= dev
->dev
->bus
;
3579 struct pci_dev
*pdev
= bus
->host_pci
;
3581 int have_aphy
= 0, have_bphy
= 0, have_gphy
= 0;
3584 /* Do NOT do any device initialization here.
3585 * Do it in wireless_core_init() instead.
3586 * This function is for gathering basic information about the HW, only.
3587 * Also some structs may be set up here. But most likely you want to have
3588 * that in core_init(), too.
3591 /* Get the PHY type. */
3592 if (dev
->dev
->id
.revision
>= 5) {
3595 tmshigh
= ssb_read32(dev
->dev
, SSB_TMSHIGH
);
3596 have_aphy
= !!(tmshigh
& BCM43xx_TMSHIGH_APHY
);
3597 have_gphy
= !!(tmshigh
& BCM43xx_TMSHIGH_GPHY
);
3598 if (!have_aphy
&& !have_gphy
)
3600 } else if (dev
->dev
->id
.revision
== 4) {
3606 /* Initialize LEDs structs. */
3607 err
= bcm43xx_leds_init(dev
);
3611 dev
->phy
.gmode
= (have_gphy
|| have_bphy
);
3612 tmp
= dev
->phy
.gmode
? BCM43xx_TMSLOW_GMODE
: 0;
3613 bcm43xx_wireless_core_reset(dev
, tmp
);
3615 err
= bcm43xx_phy_versioning(dev
);
3618 /* Check if this device supports multiband. */
3620 (pdev
->device
!= 0x4312 &&
3621 pdev
->device
!= 0x4319 &&
3622 pdev
->device
!= 0x4324)) {
3623 /* No multiband support. */
3627 switch (dev
->phy
.type
) {
3628 case BCM43xx_PHYTYPE_A
:
3631 case BCM43xx_PHYTYPE_B
:
3634 case BCM43xx_PHYTYPE_G
:
3641 dev
->phy
.gmode
= (have_gphy
|| have_bphy
);
3642 tmp
= dev
->phy
.gmode
? BCM43xx_TMSLOW_GMODE
: 0;
3643 bcm43xx_wireless_core_reset(dev
, tmp
);
3645 err
= bcm43xx_validate_chipaccess(dev
);
3648 err
= bcm43xx_setup_modes(dev
, have_aphy
,
3649 have_bphy
, have_gphy
);
3653 /* Now set some default "current_dev" */
3654 if (!wl
->current_dev
)
3655 wl
->current_dev
= dev
;
3656 INIT_WORK(&dev
->restart_work
, bcm43xx_chip_reset
);
3658 bcm43xx_radio_turn_off(dev
);
3659 bcm43xx_switch_analog(dev
, 0);
3660 ssb_device_disable(dev
->dev
, 0);
3661 ssb_bus_may_powerdown(bus
);
3667 bcm43xx_leds_exit(dev
);
3671 static void bcm43xx_one_core_detach(struct ssb_device
*dev
)
3673 struct bcm43xx_wldev
*wldev
;
3674 struct bcm43xx_wl
*wl
;
3676 wldev
= ssb_get_drvdata(dev
);
3678 bcm43xx_debugfs_remove_device(wldev
);
3679 bcm43xx_wireless_core_detach(wldev
);
3680 list_del(&wldev
->list
);
3682 ssb_set_drvdata(dev
, NULL
);
3686 static int bcm43xx_one_core_attach(struct ssb_device
*dev
,
3687 struct bcm43xx_wl
*wl
)
3689 struct bcm43xx_wldev
*wldev
;
3690 struct pci_dev
*pdev
;
3693 if (!list_empty(&wl
->devlist
)) {
3694 /* We are not the first core on this chip. */
3695 pdev
= dev
->bus
->host_pci
;
3696 /* Only special chips support more than one wireless
3697 * core, although some of the other chips have more than
3698 * one wireless core as well. Check for this and
3702 ((pdev
->device
!= 0x4321) &&
3703 (pdev
->device
!= 0x4313) &&
3704 (pdev
->device
!= 0x431A))) {
3705 dprintk(KERN_INFO PFX
"Ignoring unconnected 802.11 core\n");
3710 wldev
= kzalloc(sizeof(*wldev
), GFP_KERNEL
);
3716 bcm43xx_set_status(wldev
, BCM43xx_STAT_UNINIT
);
3717 wldev
->bad_frames_preempt
= modparam_bad_frames_preempt
;
3718 tasklet_init(&wldev
->isr_tasklet
,
3719 (void (*)(unsigned long))bcm43xx_interrupt_tasklet
,
3720 (unsigned long)wldev
);
3722 wldev
->__using_pio
= 1;
3723 INIT_LIST_HEAD(&wldev
->list
);
3725 err
= bcm43xx_wireless_core_attach(wldev
);
3727 goto err_kfree_wldev
;
3729 list_add(&wldev
->list
, &wl
->devlist
);
3731 ssb_set_drvdata(dev
, wldev
);
3732 bcm43xx_debugfs_add_device(wldev
);
3742 static void bcm43xx_sprom_fixup(struct ssb_bus
*bus
)
3744 /* boardflags workarounds */
3745 if (bus
->boardinfo
.vendor
== SSB_BOARDVENDOR_DELL
&&
3746 bus
->chip_id
== 0x4301 &&
3747 bus
->boardinfo
.rev
== 0x74)
3748 bus
->sprom
.r1
.boardflags_lo
|= BCM43xx_BFL_BTCOEXIST
;
3749 if (bus
->boardinfo
.vendor
== PCI_VENDOR_ID_APPLE
&&
3750 bus
->boardinfo
.type
== 0x4E &&
3751 bus
->boardinfo
.rev
> 0x40)
3752 bus
->sprom
.r1
.boardflags_lo
|= BCM43xx_BFL_PACTRL
;
3754 /* Convert Antennagain values to Q5.2 */
3755 bus
->sprom
.r1
.antenna_gain_a
<<= 2;
3756 bus
->sprom
.r1
.antenna_gain_bg
<<= 2;
3759 static void bcm43xx_wireless_exit(struct ssb_device
*dev
,
3760 struct bcm43xx_wl
*wl
)
3762 struct ieee80211_hw
*hw
= wl
->hw
;
3764 ssb_set_devtypedata(dev
, NULL
);
3765 ieee80211_free_hw(hw
);
3768 static int bcm43xx_wireless_init(struct ssb_device
*dev
)
3770 struct ssb_sprom
*sprom
= &dev
->bus
->sprom
;
3771 struct ieee80211_hw
*hw
;
3772 struct bcm43xx_wl
*wl
;
3775 bcm43xx_sprom_fixup(dev
->bus
);
3777 hw
= ieee80211_alloc_hw(sizeof(*wl
), &bcm43xx_hw_ops
);
3779 printk(KERN_ERR PFX
"Could not allocate ieee80211 device\n");
3784 hw
->flags
= IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE
|
3785 IEEE80211_HW_MONITOR_DURING_OPER
|
3786 IEEE80211_HW_DEVICE_HIDES_WEP
|
3787 IEEE80211_HW_WEP_INCLUDE_IV
;
3788 hw
->max_signal
= 100;
3789 hw
->max_rssi
= -110;
3790 hw
->max_noise
= -110;
3791 hw
->queues
= 1; /* FIXME: hardware has more queues */
3792 SET_IEEE80211_DEV(hw
, dev
->dev
);
3793 if (is_valid_ether_addr(sprom
->r1
.et1mac
))
3794 SET_IEEE80211_PERM_ADDR(hw
, sprom
->r1
.et1mac
);
3796 SET_IEEE80211_PERM_ADDR(hw
, sprom
->r1
.il0mac
);
3798 /* Get and initialize struct bcm43xx_wl */
3799 wl
= hw_to_bcm43xx_wl(hw
);
3800 memset(wl
, 0, sizeof(*wl
));
3802 spin_lock_init(&wl
->irq_lock
);
3803 spin_lock_init(&wl
->leds_lock
);
3804 mutex_init(&wl
->mutex
);
3805 INIT_LIST_HEAD(&wl
->devlist
);
3807 ssb_set_devtypedata(dev
, wl
);
3808 printk(KERN_INFO PFX
"Broadcom %04X WLAN found\n", dev
->bus
->chip_id
);
3814 static int bcm43xx_probe(struct ssb_device
*dev
,
3815 const struct ssb_device_id
*id
)
3817 struct bcm43xx_wl
*wl
;
3821 wl
= ssb_get_devtypedata(dev
);
3823 /* Probing the first core. Must setup common struct bcm43xx_wl */
3825 err
= bcm43xx_wireless_init(dev
);
3828 wl
= ssb_get_devtypedata(dev
);
3831 err
= bcm43xx_one_core_attach(dev
, wl
);
3833 goto err_wireless_exit
;
3836 err
= ieee80211_register_hw(wl
->hw
);
3838 goto err_one_core_detach
;
3844 err_one_core_detach
:
3845 bcm43xx_one_core_detach(dev
);
3848 bcm43xx_wireless_exit(dev
, wl
);
3852 static void bcm43xx_remove(struct ssb_device
*dev
)
3854 struct bcm43xx_wl
*wl
= ssb_get_devtypedata(dev
);
3855 struct bcm43xx_wldev
*wldev
= ssb_get_drvdata(dev
);
3858 if (wl
->current_dev
== wldev
)
3859 ieee80211_unregister_hw(wl
->hw
);
3861 bcm43xx_one_core_detach(dev
);
3863 if (list_empty(&wl
->devlist
)) {
3864 /* Last core on the chip unregistered.
3865 * We can destroy common struct bcm43xx_wl.
3867 bcm43xx_wireless_exit(dev
, wl
);
3871 /* Hard-reset the chip.
3872 * This can be called from interrupt or process context.
3873 * dev->irq_lock must be locked.
3875 void bcm43xx_controller_restart(struct bcm43xx_wldev
*dev
, const char *reason
)
3877 if (bcm43xx_status(dev
) != BCM43xx_STAT_INITIALIZED
)
3879 printk(KERN_ERR PFX
"Controller RESET (%s) ...\n", reason
);
3880 queue_work(dev
->wl
->hw
->workqueue
, &dev
->restart_work
);
3885 static int bcm43xx_suspend(struct ssb_device
*dev
, pm_message_t state
)
3887 struct bcm43xx_wldev
*wldev
= ssb_get_drvdata(dev
);
3888 struct bcm43xx_wl
*wl
= wldev
->wl
;
3890 dprintk(KERN_INFO PFX
"Suspending...\n");
3892 mutex_lock(&wl
->mutex
);
3893 wldev
->was_started
= !!wldev
->started
;
3894 wldev
->was_initialized
= (bcm43xx_status(wldev
) == BCM43xx_STAT_INITIALIZED
);
3896 bcm43xx_wireless_core_stop(wldev
);
3897 if (bcm43xx_status(wldev
) == BCM43xx_STAT_INITIALIZED
)
3898 bcm43xx_wireless_core_exit(wldev
);
3900 mutex_unlock(&wl
->mutex
);
3902 dprintk(KERN_INFO PFX
"Device suspended.\n");
3907 static int bcm43xx_resume(struct ssb_device
*dev
)
3909 struct bcm43xx_wldev
*wldev
= ssb_get_drvdata(dev
);
3912 dprintk(KERN_INFO PFX
"Resuming...\n");
3914 if (wldev
->was_initialized
) {
3915 err
= bcm43xx_wireless_core_init(wldev
);
3917 printk(KERN_ERR PFX
"Resume failed at core init\n");
3921 if (wldev
->was_started
) {
3922 assert(wldev
->was_initialized
);
3923 err
= bcm43xx_wireless_core_start(wldev
);
3925 printk(KERN_ERR PFX
"Resume failed at core start\n");
3930 dprintk(KERN_INFO PFX
"Device resumed.\n");
3935 #else /* CONFIG_PM */
3936 # define bcm43xx_suspend NULL
3937 # define bcm43xx_resume NULL
3938 #endif /* CONFIG_PM */
3940 static struct ssb_driver bcm43xx_ssb_driver
= {
3941 .name
= KBUILD_MODNAME
,
3942 .id_table
= bcm43xx_ssb_tbl
,
3943 .probe
= bcm43xx_probe
,
3944 .remove
= bcm43xx_remove
,
3945 .suspend
= bcm43xx_suspend
,
3946 .resume
= bcm43xx_resume
,
3949 #ifdef CONFIG_BCM43XX_MAC80211_PCI
3950 /* The PCI frontend stub */
3951 static const struct pci_device_id bcm43xx_pci_tbl
[] = {
3952 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, 0x4307) },
3953 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, 0x4311) },
3954 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, 0x4312) },
3955 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, 0x4318) },
3956 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, 0x4319) },
3957 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, 0x4320) },
3958 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, 0x4321) },
3959 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, 0x4324) },
3960 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM
, 0x4325) },
3963 MODULE_DEVICE_TABLE(pci
, bcm43xx_pci_tbl
);
3965 static struct pci_driver bcm43xx_pci_driver
= {
3966 .name
= "bcm43xx-pci",
3967 .id_table
= bcm43xx_pci_tbl
,
3969 #endif /* CONFIG_BCM43XX_MAC80211_PCI */
3971 static int __init
bcm43xx_init(void)
3975 bcm43xx_debugfs_init();
3976 #ifdef CONFIG_BCM43XX_MAC80211_PCI
3977 err
= ssb_pcihost_register(&bcm43xx_pci_driver
);
3981 err
= bcm43xx_pcmcia_init();
3984 err
= ssb_driver_register(&bcm43xx_ssb_driver
);
3986 goto err_pcmcia_exit
;
3991 bcm43xx_pcmcia_exit();
3993 #ifdef CONFIG_BCM43XX_MAC80211_PCI
3994 ssb_pcihost_unregister(&bcm43xx_pci_driver
);
3997 bcm43xx_debugfs_exit();
4001 static void __exit
bcm43xx_exit(void)
4003 ssb_driver_unregister(&bcm43xx_ssb_driver
);
4004 bcm43xx_pcmcia_exit();
4005 #ifdef CONFIG_BCM43XX_MAC80211_PCI
4006 ssb_pcihost_unregister(&bcm43xx_pci_driver
);
4008 bcm43xx_debugfs_exit();
4011 module_init(bcm43xx_init
)
4012 module_exit(bcm43xx_exit
)