3 Broadcom B43 wireless driver
5 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>
6 Copyright (c) 2005 Stefano Brivio <stefano.brivio@polimi.it>
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>
42 #include <linux/dma-mapping.h>
43 #include <asm/unaligned.h>
55 MODULE_DESCRIPTION("Broadcom B43 wireless driver");
56 MODULE_AUTHOR("Martin Langer");
57 MODULE_AUTHOR("Stefano Brivio");
58 MODULE_AUTHOR("Michael Buesch");
59 MODULE_LICENSE("GPL");
61 MODULE_FIRMWARE(B43_SUPPORTED_FIRMWARE_ID
);
64 static int modparam_bad_frames_preempt
;
65 module_param_named(bad_frames_preempt
, modparam_bad_frames_preempt
, int, 0444);
66 MODULE_PARM_DESC(bad_frames_preempt
,
67 "enable(1) / disable(0) Bad Frames Preemption");
69 static char modparam_fwpostfix
[16];
70 module_param_string(fwpostfix
, modparam_fwpostfix
, 16, 0444);
71 MODULE_PARM_DESC(fwpostfix
, "Postfix for the .fw files to load.");
73 static int modparam_hwpctl
;
74 module_param_named(hwpctl
, modparam_hwpctl
, int, 0444);
75 MODULE_PARM_DESC(hwpctl
, "Enable hardware-side power control (default off)");
77 static int modparam_nohwcrypt
;
78 module_param_named(nohwcrypt
, modparam_nohwcrypt
, int, 0444);
79 MODULE_PARM_DESC(nohwcrypt
, "Disable hardware encryption.");
81 static int modparam_btcoex
= 1;
82 module_param_named(btcoex
, modparam_btcoex
, int, 0444);
83 MODULE_PARM_DESC(btcoex
, "Enable Bluetooth coexistance (default on)");
86 static const struct ssb_device_id b43_ssb_tbl
[] = {
87 SSB_DEVICE(SSB_VENDOR_BROADCOM
, SSB_DEV_80211
, 5),
88 SSB_DEVICE(SSB_VENDOR_BROADCOM
, SSB_DEV_80211
, 6),
89 SSB_DEVICE(SSB_VENDOR_BROADCOM
, SSB_DEV_80211
, 7),
90 SSB_DEVICE(SSB_VENDOR_BROADCOM
, SSB_DEV_80211
, 9),
91 SSB_DEVICE(SSB_VENDOR_BROADCOM
, SSB_DEV_80211
, 10),
92 SSB_DEVICE(SSB_VENDOR_BROADCOM
, SSB_DEV_80211
, 11),
93 SSB_DEVICE(SSB_VENDOR_BROADCOM
, SSB_DEV_80211
, 13),
97 MODULE_DEVICE_TABLE(ssb
, b43_ssb_tbl
);
99 /* Channel and ratetables are shared for all devices.
100 * They can't be const, because ieee80211 puts some precalculated
101 * data in there. This data is the same for all devices, so we don't
102 * get concurrency issues */
103 #define RATETAB_ENT(_rateid, _flags) \
105 .rate = B43_RATE_TO_BASE100KBPS(_rateid), \
110 static struct ieee80211_rate __b43_ratetable
[] = {
111 RATETAB_ENT(B43_CCK_RATE_1MB
, IEEE80211_RATE_CCK
),
112 RATETAB_ENT(B43_CCK_RATE_2MB
, IEEE80211_RATE_CCK_2
),
113 RATETAB_ENT(B43_CCK_RATE_5MB
, IEEE80211_RATE_CCK_2
),
114 RATETAB_ENT(B43_CCK_RATE_11MB
, IEEE80211_RATE_CCK_2
),
115 RATETAB_ENT(B43_OFDM_RATE_6MB
, IEEE80211_RATE_OFDM
),
116 RATETAB_ENT(B43_OFDM_RATE_9MB
, IEEE80211_RATE_OFDM
),
117 RATETAB_ENT(B43_OFDM_RATE_12MB
, IEEE80211_RATE_OFDM
),
118 RATETAB_ENT(B43_OFDM_RATE_18MB
, IEEE80211_RATE_OFDM
),
119 RATETAB_ENT(B43_OFDM_RATE_24MB
, IEEE80211_RATE_OFDM
),
120 RATETAB_ENT(B43_OFDM_RATE_36MB
, IEEE80211_RATE_OFDM
),
121 RATETAB_ENT(B43_OFDM_RATE_48MB
, IEEE80211_RATE_OFDM
),
122 RATETAB_ENT(B43_OFDM_RATE_54MB
, IEEE80211_RATE_OFDM
),
125 #define b43_a_ratetable (__b43_ratetable + 4)
126 #define b43_a_ratetable_size 8
127 #define b43_b_ratetable (__b43_ratetable + 0)
128 #define b43_b_ratetable_size 4
129 #define b43_g_ratetable (__b43_ratetable + 0)
130 #define b43_g_ratetable_size 12
132 #define CHANTAB_ENT(_chanid, _freq) \
137 .flag = IEEE80211_CHAN_W_SCAN | \
138 IEEE80211_CHAN_W_ACTIVE_SCAN | \
139 IEEE80211_CHAN_W_IBSS, \
140 .power_level = 0xFF, \
141 .antenna_max = 0xFF, \
143 static struct ieee80211_channel b43_2ghz_chantable
[] = {
144 CHANTAB_ENT(1, 2412),
145 CHANTAB_ENT(2, 2417),
146 CHANTAB_ENT(3, 2422),
147 CHANTAB_ENT(4, 2427),
148 CHANTAB_ENT(5, 2432),
149 CHANTAB_ENT(6, 2437),
150 CHANTAB_ENT(7, 2442),
151 CHANTAB_ENT(8, 2447),
152 CHANTAB_ENT(9, 2452),
153 CHANTAB_ENT(10, 2457),
154 CHANTAB_ENT(11, 2462),
155 CHANTAB_ENT(12, 2467),
156 CHANTAB_ENT(13, 2472),
157 CHANTAB_ENT(14, 2484),
159 #define b43_2ghz_chantable_size ARRAY_SIZE(b43_2ghz_chantable)
162 static struct ieee80211_channel b43_5ghz_chantable
[] = {
163 CHANTAB_ENT(36, 5180),
164 CHANTAB_ENT(40, 5200),
165 CHANTAB_ENT(44, 5220),
166 CHANTAB_ENT(48, 5240),
167 CHANTAB_ENT(52, 5260),
168 CHANTAB_ENT(56, 5280),
169 CHANTAB_ENT(60, 5300),
170 CHANTAB_ENT(64, 5320),
171 CHANTAB_ENT(149, 5745),
172 CHANTAB_ENT(153, 5765),
173 CHANTAB_ENT(157, 5785),
174 CHANTAB_ENT(161, 5805),
175 CHANTAB_ENT(165, 5825),
177 #define b43_5ghz_chantable_size ARRAY_SIZE(b43_5ghz_chantable)
180 static void b43_wireless_core_exit(struct b43_wldev
*dev
);
181 static int b43_wireless_core_init(struct b43_wldev
*dev
);
182 static void b43_wireless_core_stop(struct b43_wldev
*dev
);
183 static int b43_wireless_core_start(struct b43_wldev
*dev
);
185 static int b43_ratelimit(struct b43_wl
*wl
)
187 if (!wl
|| !wl
->current_dev
)
189 if (b43_status(wl
->current_dev
) < B43_STAT_STARTED
)
191 /* We are up and running.
192 * Ratelimit the messages to avoid DoS over the net. */
193 return net_ratelimit();
196 void b43info(struct b43_wl
*wl
, const char *fmt
, ...)
200 if (!b43_ratelimit(wl
))
203 printk(KERN_INFO
"b43-%s: ",
204 (wl
&& wl
->hw
) ? wiphy_name(wl
->hw
->wiphy
) : "wlan");
209 void b43err(struct b43_wl
*wl
, const char *fmt
, ...)
213 if (!b43_ratelimit(wl
))
216 printk(KERN_ERR
"b43-%s ERROR: ",
217 (wl
&& wl
->hw
) ? wiphy_name(wl
->hw
->wiphy
) : "wlan");
222 void b43warn(struct b43_wl
*wl
, const char *fmt
, ...)
226 if (!b43_ratelimit(wl
))
229 printk(KERN_WARNING
"b43-%s warning: ",
230 (wl
&& wl
->hw
) ? wiphy_name(wl
->hw
->wiphy
) : "wlan");
236 void b43dbg(struct b43_wl
*wl
, const char *fmt
, ...)
241 printk(KERN_DEBUG
"b43-%s debug: ",
242 (wl
&& wl
->hw
) ? wiphy_name(wl
->hw
->wiphy
) : "wlan");
248 static void b43_ram_write(struct b43_wldev
*dev
, u16 offset
, u32 val
)
252 B43_WARN_ON(offset
% 4 != 0);
254 macctl
= b43_read32(dev
, B43_MMIO_MACCTL
);
255 if (macctl
& B43_MACCTL_BE
)
258 b43_write32(dev
, B43_MMIO_RAM_CONTROL
, offset
);
260 b43_write32(dev
, B43_MMIO_RAM_DATA
, val
);
263 static inline void b43_shm_control_word(struct b43_wldev
*dev
,
264 u16 routing
, u16 offset
)
268 /* "offset" is the WORD offset. */
272 b43_write32(dev
, B43_MMIO_SHM_CONTROL
, control
);
275 u32
b43_shm_read32(struct b43_wldev
*dev
, u16 routing
, u16 offset
)
277 struct b43_wl
*wl
= dev
->wl
;
281 spin_lock_irqsave(&wl
->shm_lock
, flags
);
282 if (routing
== B43_SHM_SHARED
) {
283 B43_WARN_ON(offset
& 0x0001);
284 if (offset
& 0x0003) {
285 /* Unaligned access */
286 b43_shm_control_word(dev
, routing
, offset
>> 2);
287 ret
= b43_read16(dev
, B43_MMIO_SHM_DATA_UNALIGNED
);
289 b43_shm_control_word(dev
, routing
, (offset
>> 2) + 1);
290 ret
|= b43_read16(dev
, B43_MMIO_SHM_DATA
);
296 b43_shm_control_word(dev
, routing
, offset
);
297 ret
= b43_read32(dev
, B43_MMIO_SHM_DATA
);
299 spin_unlock_irqrestore(&wl
->shm_lock
, flags
);
304 u16
b43_shm_read16(struct b43_wldev
* dev
, u16 routing
, u16 offset
)
306 struct b43_wl
*wl
= dev
->wl
;
310 spin_lock_irqsave(&wl
->shm_lock
, flags
);
311 if (routing
== B43_SHM_SHARED
) {
312 B43_WARN_ON(offset
& 0x0001);
313 if (offset
& 0x0003) {
314 /* Unaligned access */
315 b43_shm_control_word(dev
, routing
, offset
>> 2);
316 ret
= b43_read16(dev
, B43_MMIO_SHM_DATA_UNALIGNED
);
322 b43_shm_control_word(dev
, routing
, offset
);
323 ret
= b43_read16(dev
, B43_MMIO_SHM_DATA
);
325 spin_unlock_irqrestore(&wl
->shm_lock
, flags
);
330 void b43_shm_write32(struct b43_wldev
*dev
, u16 routing
, u16 offset
, u32 value
)
332 struct b43_wl
*wl
= dev
->wl
;
335 spin_lock_irqsave(&wl
->shm_lock
, flags
);
336 if (routing
== B43_SHM_SHARED
) {
337 B43_WARN_ON(offset
& 0x0001);
338 if (offset
& 0x0003) {
339 /* Unaligned access */
340 b43_shm_control_word(dev
, routing
, offset
>> 2);
341 b43_write16(dev
, B43_MMIO_SHM_DATA_UNALIGNED
,
342 (value
>> 16) & 0xffff);
343 b43_shm_control_word(dev
, routing
, (offset
>> 2) + 1);
344 b43_write16(dev
, B43_MMIO_SHM_DATA
, value
& 0xffff);
349 b43_shm_control_word(dev
, routing
, offset
);
350 b43_write32(dev
, B43_MMIO_SHM_DATA
, value
);
352 spin_unlock_irqrestore(&wl
->shm_lock
, flags
);
355 void b43_shm_write16(struct b43_wldev
*dev
, u16 routing
, u16 offset
, u16 value
)
357 struct b43_wl
*wl
= dev
->wl
;
360 spin_lock_irqsave(&wl
->shm_lock
, flags
);
361 if (routing
== B43_SHM_SHARED
) {
362 B43_WARN_ON(offset
& 0x0001);
363 if (offset
& 0x0003) {
364 /* Unaligned access */
365 b43_shm_control_word(dev
, routing
, offset
>> 2);
366 b43_write16(dev
, B43_MMIO_SHM_DATA_UNALIGNED
, value
);
371 b43_shm_control_word(dev
, routing
, offset
);
372 b43_write16(dev
, B43_MMIO_SHM_DATA
, value
);
374 spin_unlock_irqrestore(&wl
->shm_lock
, flags
);
378 u32
b43_hf_read(struct b43_wldev
* dev
)
382 ret
= b43_shm_read16(dev
, B43_SHM_SHARED
, B43_SHM_SH_HOSTFHI
);
384 ret
|= b43_shm_read16(dev
, B43_SHM_SHARED
, B43_SHM_SH_HOSTFLO
);
389 /* Write HostFlags */
390 void b43_hf_write(struct b43_wldev
*dev
, u32 value
)
392 b43_shm_write16(dev
, B43_SHM_SHARED
,
393 B43_SHM_SH_HOSTFLO
, (value
& 0x0000FFFF));
394 b43_shm_write16(dev
, B43_SHM_SHARED
,
395 B43_SHM_SH_HOSTFHI
, ((value
& 0xFFFF0000) >> 16));
398 void b43_tsf_read(struct b43_wldev
*dev
, u64
* tsf
)
400 /* We need to be careful. As we read the TSF from multiple
401 * registers, we should take care of register overflows.
402 * In theory, the whole tsf read process should be atomic.
403 * We try to be atomic here, by restaring the read process,
404 * if any of the high registers changed (overflew).
406 if (dev
->dev
->id
.revision
>= 3) {
407 u32 low
, high
, high2
;
410 high
= b43_read32(dev
, B43_MMIO_REV3PLUS_TSF_HIGH
);
411 low
= b43_read32(dev
, B43_MMIO_REV3PLUS_TSF_LOW
);
412 high2
= b43_read32(dev
, B43_MMIO_REV3PLUS_TSF_HIGH
);
413 } while (unlikely(high
!= high2
));
421 u16 test1
, test2
, test3
;
424 v3
= b43_read16(dev
, B43_MMIO_TSF_3
);
425 v2
= b43_read16(dev
, B43_MMIO_TSF_2
);
426 v1
= b43_read16(dev
, B43_MMIO_TSF_1
);
427 v0
= b43_read16(dev
, B43_MMIO_TSF_0
);
429 test3
= b43_read16(dev
, B43_MMIO_TSF_3
);
430 test2
= b43_read16(dev
, B43_MMIO_TSF_2
);
431 test1
= b43_read16(dev
, B43_MMIO_TSF_1
);
432 } while (v3
!= test3
|| v2
!= test2
|| v1
!= test1
);
446 static void b43_time_lock(struct b43_wldev
*dev
)
450 macctl
= b43_read32(dev
, B43_MMIO_MACCTL
);
451 macctl
|= B43_MACCTL_TBTTHOLD
;
452 b43_write32(dev
, B43_MMIO_MACCTL
, macctl
);
453 /* Commit the write */
454 b43_read32(dev
, B43_MMIO_MACCTL
);
457 static void b43_time_unlock(struct b43_wldev
*dev
)
461 macctl
= b43_read32(dev
, B43_MMIO_MACCTL
);
462 macctl
&= ~B43_MACCTL_TBTTHOLD
;
463 b43_write32(dev
, B43_MMIO_MACCTL
, macctl
);
464 /* Commit the write */
465 b43_read32(dev
, B43_MMIO_MACCTL
);
468 static void b43_tsf_write_locked(struct b43_wldev
*dev
, u64 tsf
)
470 /* Be careful with the in-progress timer.
471 * First zero out the low register, so we have a full
472 * register-overflow duration to complete the operation.
474 if (dev
->dev
->id
.revision
>= 3) {
475 u32 lo
= (tsf
& 0x00000000FFFFFFFFULL
);
476 u32 hi
= (tsf
& 0xFFFFFFFF00000000ULL
) >> 32;
478 b43_write32(dev
, B43_MMIO_REV3PLUS_TSF_LOW
, 0);
480 b43_write32(dev
, B43_MMIO_REV3PLUS_TSF_HIGH
, hi
);
482 b43_write32(dev
, B43_MMIO_REV3PLUS_TSF_LOW
, lo
);
484 u16 v0
= (tsf
& 0x000000000000FFFFULL
);
485 u16 v1
= (tsf
& 0x00000000FFFF0000ULL
) >> 16;
486 u16 v2
= (tsf
& 0x0000FFFF00000000ULL
) >> 32;
487 u16 v3
= (tsf
& 0xFFFF000000000000ULL
) >> 48;
489 b43_write16(dev
, B43_MMIO_TSF_0
, 0);
491 b43_write16(dev
, B43_MMIO_TSF_3
, v3
);
493 b43_write16(dev
, B43_MMIO_TSF_2
, v2
);
495 b43_write16(dev
, B43_MMIO_TSF_1
, v1
);
497 b43_write16(dev
, B43_MMIO_TSF_0
, v0
);
501 void b43_tsf_write(struct b43_wldev
*dev
, u64 tsf
)
504 b43_tsf_write_locked(dev
, tsf
);
505 b43_time_unlock(dev
);
509 void b43_macfilter_set(struct b43_wldev
*dev
, u16 offset
, const u8
* mac
)
511 static const u8 zero_addr
[ETH_ALEN
] = { 0 };
518 b43_write16(dev
, B43_MMIO_MACFILTER_CONTROL
, offset
);
522 b43_write16(dev
, B43_MMIO_MACFILTER_DATA
, data
);
525 b43_write16(dev
, B43_MMIO_MACFILTER_DATA
, data
);
528 b43_write16(dev
, B43_MMIO_MACFILTER_DATA
, data
);
531 static void b43_write_mac_bssid_templates(struct b43_wldev
*dev
)
535 u8 mac_bssid
[ETH_ALEN
* 2];
539 bssid
= dev
->wl
->bssid
;
540 mac
= dev
->wl
->mac_addr
;
542 b43_macfilter_set(dev
, B43_MACFILTER_BSSID
, bssid
);
544 memcpy(mac_bssid
, mac
, ETH_ALEN
);
545 memcpy(mac_bssid
+ ETH_ALEN
, bssid
, ETH_ALEN
);
547 /* Write our MAC address and BSSID to template ram */
548 for (i
= 0; i
< ARRAY_SIZE(mac_bssid
); i
+= sizeof(u32
)) {
549 tmp
= (u32
) (mac_bssid
[i
+ 0]);
550 tmp
|= (u32
) (mac_bssid
[i
+ 1]) << 8;
551 tmp
|= (u32
) (mac_bssid
[i
+ 2]) << 16;
552 tmp
|= (u32
) (mac_bssid
[i
+ 3]) << 24;
553 b43_ram_write(dev
, 0x20 + i
, tmp
);
557 static void b43_upload_card_macaddress(struct b43_wldev
*dev
)
559 b43_write_mac_bssid_templates(dev
);
560 b43_macfilter_set(dev
, B43_MACFILTER_SELF
, dev
->wl
->mac_addr
);
563 static void b43_set_slot_time(struct b43_wldev
*dev
, u16 slot_time
)
565 /* slot_time is in usec. */
566 if (dev
->phy
.type
!= B43_PHYTYPE_G
)
568 b43_write16(dev
, 0x684, 510 + slot_time
);
569 b43_shm_write16(dev
, B43_SHM_SHARED
, 0x0010, slot_time
);
572 static void b43_short_slot_timing_enable(struct b43_wldev
*dev
)
574 b43_set_slot_time(dev
, 9);
578 static void b43_short_slot_timing_disable(struct b43_wldev
*dev
)
580 b43_set_slot_time(dev
, 20);
584 /* Enable a Generic IRQ. "mask" is the mask of which IRQs to enable.
585 * Returns the _previously_ enabled IRQ mask.
587 static inline u32
b43_interrupt_enable(struct b43_wldev
*dev
, u32 mask
)
591 old_mask
= b43_read32(dev
, B43_MMIO_GEN_IRQ_MASK
);
592 b43_write32(dev
, B43_MMIO_GEN_IRQ_MASK
, old_mask
| mask
);
597 /* Disable a Generic IRQ. "mask" is the mask of which IRQs to disable.
598 * Returns the _previously_ enabled IRQ mask.
600 static inline u32
b43_interrupt_disable(struct b43_wldev
*dev
, u32 mask
)
604 old_mask
= b43_read32(dev
, B43_MMIO_GEN_IRQ_MASK
);
605 b43_write32(dev
, B43_MMIO_GEN_IRQ_MASK
, old_mask
& ~mask
);
610 /* Synchronize IRQ top- and bottom-half.
611 * IRQs must be masked before calling this.
612 * This must not be called with the irq_lock held.
614 static void b43_synchronize_irq(struct b43_wldev
*dev
)
616 synchronize_irq(dev
->dev
->irq
);
617 tasklet_kill(&dev
->isr_tasklet
);
620 /* DummyTransmission function, as documented on
621 * http://bcm-specs.sipsolutions.net/DummyTransmission
623 void b43_dummy_transmission(struct b43_wldev
*dev
)
625 struct b43_wl
*wl
= dev
->wl
;
626 struct b43_phy
*phy
= &dev
->phy
;
627 unsigned int i
, max_loop
;
640 buffer
[0] = 0x000201CC;
645 buffer
[0] = 0x000B846E;
652 spin_lock_irq(&wl
->irq_lock
);
653 write_lock(&wl
->tx_lock
);
655 for (i
= 0; i
< 5; i
++)
656 b43_ram_write(dev
, i
* 4, buffer
[i
]);
659 b43_read32(dev
, B43_MMIO_MACCTL
);
661 b43_write16(dev
, 0x0568, 0x0000);
662 b43_write16(dev
, 0x07C0, 0x0000);
663 value
= ((phy
->type
== B43_PHYTYPE_A
) ? 1 : 0);
664 b43_write16(dev
, 0x050C, value
);
665 b43_write16(dev
, 0x0508, 0x0000);
666 b43_write16(dev
, 0x050A, 0x0000);
667 b43_write16(dev
, 0x054C, 0x0000);
668 b43_write16(dev
, 0x056A, 0x0014);
669 b43_write16(dev
, 0x0568, 0x0826);
670 b43_write16(dev
, 0x0500, 0x0000);
671 b43_write16(dev
, 0x0502, 0x0030);
673 if (phy
->radio_ver
== 0x2050 && phy
->radio_rev
<= 0x5)
674 b43_radio_write16(dev
, 0x0051, 0x0017);
675 for (i
= 0x00; i
< max_loop
; i
++) {
676 value
= b43_read16(dev
, 0x050E);
681 for (i
= 0x00; i
< 0x0A; i
++) {
682 value
= b43_read16(dev
, 0x050E);
687 for (i
= 0x00; i
< 0x0A; i
++) {
688 value
= b43_read16(dev
, 0x0690);
689 if (!(value
& 0x0100))
693 if (phy
->radio_ver
== 0x2050 && phy
->radio_rev
<= 0x5)
694 b43_radio_write16(dev
, 0x0051, 0x0037);
696 write_unlock(&wl
->tx_lock
);
697 spin_unlock_irq(&wl
->irq_lock
);
700 static void key_write(struct b43_wldev
*dev
,
701 u8 index
, u8 algorithm
, const u8
* key
)
708 /* Key index/algo block */
709 kidx
= b43_kidx_to_fw(dev
, index
);
710 value
= ((kidx
<< 4) | algorithm
);
711 b43_shm_write16(dev
, B43_SHM_SHARED
,
712 B43_SHM_SH_KEYIDXBLOCK
+ (kidx
* 2), value
);
714 /* Write the key to the Key Table Pointer offset */
715 offset
= dev
->ktp
+ (index
* B43_SEC_KEYSIZE
);
716 for (i
= 0; i
< B43_SEC_KEYSIZE
; i
+= 2) {
718 value
|= (u16
) (key
[i
+ 1]) << 8;
719 b43_shm_write16(dev
, B43_SHM_SHARED
, offset
+ i
, value
);
723 static void keymac_write(struct b43_wldev
*dev
, u8 index
, const u8
* addr
)
725 u32 addrtmp
[2] = { 0, 0, };
726 u8 per_sta_keys_start
= 8;
728 if (b43_new_kidx_api(dev
))
729 per_sta_keys_start
= 4;
731 B43_WARN_ON(index
< per_sta_keys_start
);
732 /* We have two default TX keys and possibly two default RX keys.
733 * Physical mac 0 is mapped to physical key 4 or 8, depending
734 * on the firmware version.
735 * So we must adjust the index here.
737 index
-= per_sta_keys_start
;
740 addrtmp
[0] = addr
[0];
741 addrtmp
[0] |= ((u32
) (addr
[1]) << 8);
742 addrtmp
[0] |= ((u32
) (addr
[2]) << 16);
743 addrtmp
[0] |= ((u32
) (addr
[3]) << 24);
744 addrtmp
[1] = addr
[4];
745 addrtmp
[1] |= ((u32
) (addr
[5]) << 8);
748 if (dev
->dev
->id
.revision
>= 5) {
749 /* Receive match transmitter address mechanism */
750 b43_shm_write32(dev
, B43_SHM_RCMTA
,
751 (index
* 2) + 0, addrtmp
[0]);
752 b43_shm_write16(dev
, B43_SHM_RCMTA
,
753 (index
* 2) + 1, addrtmp
[1]);
755 /* RXE (Receive Engine) and
756 * PSM (Programmable State Machine) mechanism
759 /* TODO write to RCM 16, 19, 22 and 25 */
761 b43_shm_write32(dev
, B43_SHM_SHARED
,
762 B43_SHM_SH_PSM
+ (index
* 6) + 0,
764 b43_shm_write16(dev
, B43_SHM_SHARED
,
765 B43_SHM_SH_PSM
+ (index
* 6) + 4,
771 static void do_key_write(struct b43_wldev
*dev
,
772 u8 index
, u8 algorithm
,
773 const u8
* key
, size_t key_len
, const u8
* mac_addr
)
775 u8 buf
[B43_SEC_KEYSIZE
] = { 0, };
776 u8 per_sta_keys_start
= 8;
778 if (b43_new_kidx_api(dev
))
779 per_sta_keys_start
= 4;
781 B43_WARN_ON(index
>= dev
->max_nr_keys
);
782 B43_WARN_ON(key_len
> B43_SEC_KEYSIZE
);
784 if (index
>= per_sta_keys_start
)
785 keymac_write(dev
, index
, NULL
); /* First zero out mac. */
787 memcpy(buf
, key
, key_len
);
788 key_write(dev
, index
, algorithm
, buf
);
789 if (index
>= per_sta_keys_start
)
790 keymac_write(dev
, index
, mac_addr
);
792 dev
->key
[index
].algorithm
= algorithm
;
795 static int b43_key_write(struct b43_wldev
*dev
,
796 int index
, u8 algorithm
,
797 const u8
* key
, size_t key_len
,
799 struct ieee80211_key_conf
*keyconf
)
804 if (key_len
> B43_SEC_KEYSIZE
)
806 for (i
= 0; i
< dev
->max_nr_keys
; i
++) {
807 /* Check that we don't already have this key. */
808 B43_WARN_ON(dev
->key
[i
].keyconf
== keyconf
);
811 /* Either pairwise key or address is 00:00:00:00:00:00
812 * for transmit-only keys. Search the index. */
813 if (b43_new_kidx_api(dev
))
817 for (i
= sta_keys_start
; i
< dev
->max_nr_keys
; i
++) {
818 if (!dev
->key
[i
].keyconf
) {
825 b43err(dev
->wl
, "Out of hardware key memory\n");
829 B43_WARN_ON(index
> 3);
831 do_key_write(dev
, index
, algorithm
, key
, key_len
, mac_addr
);
832 if ((index
<= 3) && !b43_new_kidx_api(dev
)) {
834 B43_WARN_ON(mac_addr
);
835 do_key_write(dev
, index
+ 4, algorithm
, key
, key_len
, NULL
);
837 keyconf
->hw_key_idx
= index
;
838 dev
->key
[index
].keyconf
= keyconf
;
843 static int b43_key_clear(struct b43_wldev
*dev
, int index
)
845 if (B43_WARN_ON((index
< 0) || (index
>= dev
->max_nr_keys
)))
847 do_key_write(dev
, index
, B43_SEC_ALGO_NONE
,
848 NULL
, B43_SEC_KEYSIZE
, NULL
);
849 if ((index
<= 3) && !b43_new_kidx_api(dev
)) {
850 do_key_write(dev
, index
+ 4, B43_SEC_ALGO_NONE
,
851 NULL
, B43_SEC_KEYSIZE
, NULL
);
853 dev
->key
[index
].keyconf
= NULL
;
858 static void b43_clear_keys(struct b43_wldev
*dev
)
862 for (i
= 0; i
< dev
->max_nr_keys
; i
++)
863 b43_key_clear(dev
, i
);
866 void b43_power_saving_ctl_bits(struct b43_wldev
*dev
, unsigned int ps_flags
)
874 B43_WARN_ON((ps_flags
& B43_PS_ENABLED
) &&
875 (ps_flags
& B43_PS_DISABLED
));
876 B43_WARN_ON((ps_flags
& B43_PS_AWAKE
) && (ps_flags
& B43_PS_ASLEEP
));
878 if (ps_flags
& B43_PS_ENABLED
) {
880 } else if (ps_flags
& B43_PS_DISABLED
) {
883 //TODO: If powersave is not off and FIXME is not set and we are not in adhoc
884 // and thus is not an AP and we are associated, set bit 25
886 if (ps_flags
& B43_PS_AWAKE
) {
888 } else if (ps_flags
& B43_PS_ASLEEP
) {
891 //TODO: If the device is awake or this is an AP, or we are scanning, or FIXME,
892 // or we are associated, or FIXME, or the latest PS-Poll packet sent was
893 // successful, set bit26
896 /* FIXME: For now we force awake-on and hwps-off */
900 macctl
= b43_read32(dev
, B43_MMIO_MACCTL
);
902 macctl
|= B43_MACCTL_HWPS
;
904 macctl
&= ~B43_MACCTL_HWPS
;
906 macctl
|= B43_MACCTL_AWAKE
;
908 macctl
&= ~B43_MACCTL_AWAKE
;
909 b43_write32(dev
, B43_MMIO_MACCTL
, macctl
);
911 b43_read32(dev
, B43_MMIO_MACCTL
);
912 if (awake
&& dev
->dev
->id
.revision
>= 5) {
913 /* Wait for the microcode to wake up. */
914 for (i
= 0; i
< 100; i
++) {
915 ucstat
= b43_shm_read16(dev
, B43_SHM_SHARED
,
916 B43_SHM_SH_UCODESTAT
);
917 if (ucstat
!= B43_SHM_SH_UCODESTAT_SLEEP
)
924 /* Turn the Analog ON/OFF */
925 static void b43_switch_analog(struct b43_wldev
*dev
, int on
)
927 b43_write16(dev
, B43_MMIO_PHY0
, on
? 0 : 0xF4);
930 void b43_wireless_core_reset(struct b43_wldev
*dev
, u32 flags
)
935 flags
|= B43_TMSLOW_PHYCLKEN
;
936 flags
|= B43_TMSLOW_PHYRESET
;
937 ssb_device_enable(dev
->dev
, flags
);
938 msleep(2); /* Wait for the PLL to turn on. */
940 /* Now take the PHY out of Reset again */
941 tmslow
= ssb_read32(dev
->dev
, SSB_TMSLOW
);
942 tmslow
|= SSB_TMSLOW_FGC
;
943 tmslow
&= ~B43_TMSLOW_PHYRESET
;
944 ssb_write32(dev
->dev
, SSB_TMSLOW
, tmslow
);
945 ssb_read32(dev
->dev
, SSB_TMSLOW
); /* flush */
947 tmslow
&= ~SSB_TMSLOW_FGC
;
948 ssb_write32(dev
->dev
, SSB_TMSLOW
, tmslow
);
949 ssb_read32(dev
->dev
, SSB_TMSLOW
); /* flush */
953 b43_switch_analog(dev
, 1);
955 macctl
= b43_read32(dev
, B43_MMIO_MACCTL
);
956 macctl
&= ~B43_MACCTL_GMODE
;
957 if (flags
& B43_TMSLOW_GMODE
)
958 macctl
|= B43_MACCTL_GMODE
;
959 macctl
|= B43_MACCTL_IHR_ENABLED
;
960 b43_write32(dev
, B43_MMIO_MACCTL
, macctl
);
963 static void handle_irq_transmit_status(struct b43_wldev
*dev
)
967 struct b43_txstatus stat
;
970 v0
= b43_read32(dev
, B43_MMIO_XMITSTAT_0
);
971 if (!(v0
& 0x00000001))
973 v1
= b43_read32(dev
, B43_MMIO_XMITSTAT_1
);
975 stat
.cookie
= (v0
>> 16);
976 stat
.seq
= (v1
& 0x0000FFFF);
977 stat
.phy_stat
= ((v1
& 0x00FF0000) >> 16);
978 tmp
= (v0
& 0x0000FFFF);
979 stat
.frame_count
= ((tmp
& 0xF000) >> 12);
980 stat
.rts_count
= ((tmp
& 0x0F00) >> 8);
981 stat
.supp_reason
= ((tmp
& 0x001C) >> 2);
982 stat
.pm_indicated
= !!(tmp
& 0x0080);
983 stat
.intermediate
= !!(tmp
& 0x0040);
984 stat
.for_ampdu
= !!(tmp
& 0x0020);
985 stat
.acked
= !!(tmp
& 0x0002);
987 b43_handle_txstatus(dev
, &stat
);
991 static void drain_txstatus_queue(struct b43_wldev
*dev
)
995 if (dev
->dev
->id
.revision
< 5)
997 /* Read all entries from the microcode TXstatus FIFO
998 * and throw them away.
1001 dummy
= b43_read32(dev
, B43_MMIO_XMITSTAT_0
);
1002 if (!(dummy
& 0x00000001))
1004 dummy
= b43_read32(dev
, B43_MMIO_XMITSTAT_1
);
1008 static u32
b43_jssi_read(struct b43_wldev
*dev
)
1012 val
= b43_shm_read16(dev
, B43_SHM_SHARED
, 0x08A);
1014 val
|= b43_shm_read16(dev
, B43_SHM_SHARED
, 0x088);
1019 static void b43_jssi_write(struct b43_wldev
*dev
, u32 jssi
)
1021 b43_shm_write16(dev
, B43_SHM_SHARED
, 0x088, (jssi
& 0x0000FFFF));
1022 b43_shm_write16(dev
, B43_SHM_SHARED
, 0x08A, (jssi
& 0xFFFF0000) >> 16);
1025 static void b43_generate_noise_sample(struct b43_wldev
*dev
)
1027 b43_jssi_write(dev
, 0x7F7F7F7F);
1028 b43_write32(dev
, B43_MMIO_MACCMD
,
1029 b43_read32(dev
, B43_MMIO_MACCMD
) | B43_MACCMD_BGNOISE
);
1030 B43_WARN_ON(dev
->noisecalc
.channel_at_start
!= dev
->phy
.channel
);
1033 static void b43_calculate_link_quality(struct b43_wldev
*dev
)
1035 /* Top half of Link Quality calculation. */
1037 if (dev
->noisecalc
.calculation_running
)
1039 dev
->noisecalc
.channel_at_start
= dev
->phy
.channel
;
1040 dev
->noisecalc
.calculation_running
= 1;
1041 dev
->noisecalc
.nr_samples
= 0;
1043 b43_generate_noise_sample(dev
);
1046 static void handle_irq_noise(struct b43_wldev
*dev
)
1048 struct b43_phy
*phy
= &dev
->phy
;
1054 /* Bottom half of Link Quality calculation. */
1056 B43_WARN_ON(!dev
->noisecalc
.calculation_running
);
1057 if (dev
->noisecalc
.channel_at_start
!= phy
->channel
)
1058 goto drop_calculation
;
1059 *((__le32
*)noise
) = cpu_to_le32(b43_jssi_read(dev
));
1060 if (noise
[0] == 0x7F || noise
[1] == 0x7F ||
1061 noise
[2] == 0x7F || noise
[3] == 0x7F)
1064 /* Get the noise samples. */
1065 B43_WARN_ON(dev
->noisecalc
.nr_samples
>= 8);
1066 i
= dev
->noisecalc
.nr_samples
;
1067 noise
[0] = limit_value(noise
[0], 0, ARRAY_SIZE(phy
->nrssi_lt
) - 1);
1068 noise
[1] = limit_value(noise
[1], 0, ARRAY_SIZE(phy
->nrssi_lt
) - 1);
1069 noise
[2] = limit_value(noise
[2], 0, ARRAY_SIZE(phy
->nrssi_lt
) - 1);
1070 noise
[3] = limit_value(noise
[3], 0, ARRAY_SIZE(phy
->nrssi_lt
) - 1);
1071 dev
->noisecalc
.samples
[i
][0] = phy
->nrssi_lt
[noise
[0]];
1072 dev
->noisecalc
.samples
[i
][1] = phy
->nrssi_lt
[noise
[1]];
1073 dev
->noisecalc
.samples
[i
][2] = phy
->nrssi_lt
[noise
[2]];
1074 dev
->noisecalc
.samples
[i
][3] = phy
->nrssi_lt
[noise
[3]];
1075 dev
->noisecalc
.nr_samples
++;
1076 if (dev
->noisecalc
.nr_samples
== 8) {
1077 /* Calculate the Link Quality by the noise samples. */
1079 for (i
= 0; i
< 8; i
++) {
1080 for (j
= 0; j
< 4; j
++)
1081 average
+= dev
->noisecalc
.samples
[i
][j
];
1087 tmp
= b43_shm_read16(dev
, B43_SHM_SHARED
, 0x40C);
1088 tmp
= (tmp
/ 128) & 0x1F;
1098 dev
->stats
.link_noise
= average
;
1100 dev
->noisecalc
.calculation_running
= 0;
1104 b43_generate_noise_sample(dev
);
1107 static void handle_irq_tbtt_indication(struct b43_wldev
*dev
)
1109 if (b43_is_mode(dev
->wl
, IEEE80211_IF_TYPE_AP
)) {
1112 if (1 /*FIXME: the last PSpoll frame was sent successfully */ )
1113 b43_power_saving_ctl_bits(dev
, 0);
1115 if (b43_is_mode(dev
->wl
, IEEE80211_IF_TYPE_IBSS
))
1119 static void handle_irq_atim_end(struct b43_wldev
*dev
)
1121 if (dev
->dfq_valid
) {
1122 b43_write32(dev
, B43_MMIO_MACCMD
,
1123 b43_read32(dev
, B43_MMIO_MACCMD
)
1124 | B43_MACCMD_DFQ_VALID
);
1129 static void handle_irq_pmq(struct b43_wldev
*dev
)
1136 tmp
= b43_read32(dev
, B43_MMIO_PS_STATUS
);
1137 if (!(tmp
& 0x00000008))
1140 /* 16bit write is odd, but correct. */
1141 b43_write16(dev
, B43_MMIO_PS_STATUS
, 0x0002);
1144 static void b43_write_template_common(struct b43_wldev
*dev
,
1145 const u8
* data
, u16 size
,
1147 u16 shm_size_offset
, u8 rate
)
1150 struct b43_plcp_hdr4 plcp
;
1153 b43_generate_plcp_hdr(&plcp
, size
+ FCS_LEN
, rate
);
1154 b43_ram_write(dev
, ram_offset
, le32_to_cpu(plcp
.data
));
1155 ram_offset
+= sizeof(u32
);
1156 /* The PLCP is 6 bytes long, but we only wrote 4 bytes, yet.
1157 * So leave the first two bytes of the next write blank.
1159 tmp
= (u32
) (data
[0]) << 16;
1160 tmp
|= (u32
) (data
[1]) << 24;
1161 b43_ram_write(dev
, ram_offset
, tmp
);
1162 ram_offset
+= sizeof(u32
);
1163 for (i
= 2; i
< size
; i
+= sizeof(u32
)) {
1164 tmp
= (u32
) (data
[i
+ 0]);
1166 tmp
|= (u32
) (data
[i
+ 1]) << 8;
1168 tmp
|= (u32
) (data
[i
+ 2]) << 16;
1170 tmp
|= (u32
) (data
[i
+ 3]) << 24;
1171 b43_ram_write(dev
, ram_offset
+ i
- 2, tmp
);
1173 b43_shm_write16(dev
, B43_SHM_SHARED
, shm_size_offset
,
1174 size
+ sizeof(struct b43_plcp_hdr6
));
1177 static void b43_write_beacon_template(struct b43_wldev
*dev
,
1179 u16 shm_size_offset
, u8 rate
)
1181 unsigned int i
, len
, variable_len
;
1182 const struct ieee80211_mgmt
*bcn
;
1186 bcn
= (const struct ieee80211_mgmt
*)(dev
->wl
->current_beacon
->data
);
1187 len
= min((size_t) dev
->wl
->current_beacon
->len
,
1188 0x200 - sizeof(struct b43_plcp_hdr6
));
1190 b43_write_template_common(dev
, (const u8
*)bcn
,
1191 len
, ram_offset
, shm_size_offset
, rate
);
1193 /* Find the position of the TIM and the DTIM_period value
1194 * and write them to SHM. */
1195 ie
= bcn
->u
.beacon
.variable
;
1196 variable_len
= len
- offsetof(struct ieee80211_mgmt
, u
.beacon
.variable
);
1197 for (i
= 0; i
< variable_len
- 2; ) {
1198 uint8_t ie_id
, ie_len
;
1205 /* This is the TIM Information Element */
1207 /* Check whether the ie_len is in the beacon data range. */
1208 if (variable_len
< ie_len
+ 2 + i
)
1210 /* A valid TIM is at least 4 bytes long. */
1215 tim_position
= sizeof(struct b43_plcp_hdr6
);
1216 tim_position
+= offsetof(struct ieee80211_mgmt
, u
.beacon
.variable
);
1219 dtim_period
= ie
[i
+ 3];
1221 b43_shm_write16(dev
, B43_SHM_SHARED
,
1222 B43_SHM_SH_TIMBPOS
, tim_position
);
1223 b43_shm_write16(dev
, B43_SHM_SHARED
,
1224 B43_SHM_SH_DTIMPER
, dtim_period
);
1230 b43warn(dev
->wl
, "Did not find a valid TIM IE in "
1231 "the beacon template packet. AP or IBSS operation "
1232 "may be broken.\n");
1236 static void b43_write_probe_resp_plcp(struct b43_wldev
*dev
,
1237 u16 shm_offset
, u16 size
, u8 rate
)
1239 struct b43_plcp_hdr4 plcp
;
1244 b43_generate_plcp_hdr(&plcp
, size
+ FCS_LEN
, rate
);
1245 dur
= ieee80211_generic_frame_duration(dev
->wl
->hw
,
1247 B43_RATE_TO_BASE100KBPS(rate
));
1248 /* Write PLCP in two parts and timing for packet transfer */
1249 tmp
= le32_to_cpu(plcp
.data
);
1250 b43_shm_write16(dev
, B43_SHM_SHARED
, shm_offset
, tmp
& 0xFFFF);
1251 b43_shm_write16(dev
, B43_SHM_SHARED
, shm_offset
+ 2, tmp
>> 16);
1252 b43_shm_write16(dev
, B43_SHM_SHARED
, shm_offset
+ 6, le16_to_cpu(dur
));
1255 /* Instead of using custom probe response template, this function
1256 * just patches custom beacon template by:
1257 * 1) Changing packet type
1258 * 2) Patching duration field
1261 static const u8
* b43_generate_probe_resp(struct b43_wldev
*dev
,
1262 u16
*dest_size
, u8 rate
)
1266 u16 src_size
, elem_size
, src_pos
, dest_pos
;
1268 struct ieee80211_hdr
*hdr
;
1271 src_size
= dev
->wl
->current_beacon
->len
;
1272 src_data
= (const u8
*)dev
->wl
->current_beacon
->data
;
1274 /* Get the start offset of the variable IEs in the packet. */
1275 ie_start
= offsetof(struct ieee80211_mgmt
, u
.probe_resp
.variable
);
1276 B43_WARN_ON(ie_start
!= offsetof(struct ieee80211_mgmt
, u
.beacon
.variable
));
1278 if (B43_WARN_ON(src_size
< ie_start
))
1281 dest_data
= kmalloc(src_size
, GFP_ATOMIC
);
1282 if (unlikely(!dest_data
))
1285 /* Copy the static data and all Information Elements, except the TIM. */
1286 memcpy(dest_data
, src_data
, ie_start
);
1288 dest_pos
= ie_start
;
1289 for ( ; src_pos
< src_size
- 2; src_pos
+= elem_size
) {
1290 elem_size
= src_data
[src_pos
+ 1] + 2;
1291 if (src_data
[src_pos
] == 5) {
1292 /* This is the TIM. */
1295 memcpy(dest_data
+ dest_pos
, src_data
+ src_pos
,
1297 dest_pos
+= elem_size
;
1299 *dest_size
= dest_pos
;
1300 hdr
= (struct ieee80211_hdr
*)dest_data
;
1302 /* Set the frame control. */
1303 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
1304 IEEE80211_STYPE_PROBE_RESP
);
1305 dur
= ieee80211_generic_frame_duration(dev
->wl
->hw
,
1306 dev
->wl
->vif
, *dest_size
,
1307 B43_RATE_TO_BASE100KBPS(rate
));
1308 hdr
->duration_id
= dur
;
1313 static void b43_write_probe_resp_template(struct b43_wldev
*dev
,
1315 u16 shm_size_offset
, u8 rate
)
1317 const u8
*probe_resp_data
;
1320 size
= dev
->wl
->current_beacon
->len
;
1321 probe_resp_data
= b43_generate_probe_resp(dev
, &size
, rate
);
1322 if (unlikely(!probe_resp_data
))
1325 /* Looks like PLCP headers plus packet timings are stored for
1326 * all possible basic rates
1328 b43_write_probe_resp_plcp(dev
, 0x31A, size
, B43_CCK_RATE_1MB
);
1329 b43_write_probe_resp_plcp(dev
, 0x32C, size
, B43_CCK_RATE_2MB
);
1330 b43_write_probe_resp_plcp(dev
, 0x33E, size
, B43_CCK_RATE_5MB
);
1331 b43_write_probe_resp_plcp(dev
, 0x350, size
, B43_CCK_RATE_11MB
);
1333 size
= min((size_t) size
, 0x200 - sizeof(struct b43_plcp_hdr6
));
1334 b43_write_template_common(dev
, probe_resp_data
,
1335 size
, ram_offset
, shm_size_offset
, rate
);
1336 kfree(probe_resp_data
);
1339 /* Asynchronously update the packet templates in template RAM.
1340 * Locking: Requires wl->irq_lock to be locked. */
1341 static void b43_update_templates(struct b43_wl
*wl
, struct sk_buff
*beacon
)
1343 /* This is the top half of the ansynchronous beacon update.
1344 * The bottom half is the beacon IRQ.
1345 * Beacon update must be asynchronous to avoid sending an
1346 * invalid beacon. This can happen for example, if the firmware
1347 * transmits a beacon while we are updating it. */
1349 if (wl
->current_beacon
)
1350 dev_kfree_skb_any(wl
->current_beacon
);
1351 wl
->current_beacon
= beacon
;
1352 wl
->beacon0_uploaded
= 0;
1353 wl
->beacon1_uploaded
= 0;
1356 static void b43_set_ssid(struct b43_wldev
*dev
, const u8
* ssid
, u8 ssid_len
)
1361 len
= min((u16
) ssid_len
, (u16
) 0x100);
1362 for (i
= 0; i
< len
; i
+= sizeof(u32
)) {
1363 tmp
= (u32
) (ssid
[i
+ 0]);
1365 tmp
|= (u32
) (ssid
[i
+ 1]) << 8;
1367 tmp
|= (u32
) (ssid
[i
+ 2]) << 16;
1369 tmp
|= (u32
) (ssid
[i
+ 3]) << 24;
1370 b43_shm_write32(dev
, B43_SHM_SHARED
, 0x380 + i
, tmp
);
1372 b43_shm_write16(dev
, B43_SHM_SHARED
, 0x48, len
);
1375 static void b43_set_beacon_int(struct b43_wldev
*dev
, u16 beacon_int
)
1378 if (dev
->dev
->id
.revision
>= 3) {
1379 b43_write32(dev
, 0x188, (beacon_int
<< 16));
1381 b43_write16(dev
, 0x606, (beacon_int
>> 6));
1382 b43_write16(dev
, 0x610, beacon_int
);
1384 b43_time_unlock(dev
);
1387 static void handle_irq_beacon(struct b43_wldev
*dev
)
1389 struct b43_wl
*wl
= dev
->wl
;
1392 if (!b43_is_mode(wl
, IEEE80211_IF_TYPE_AP
))
1395 /* This is the bottom half of the asynchronous beacon update. */
1397 cmd
= b43_read32(dev
, B43_MMIO_MACCMD
);
1398 if (!(cmd
& B43_MACCMD_BEACON0_VALID
)) {
1399 if (!wl
->beacon0_uploaded
) {
1400 b43_write_beacon_template(dev
, 0x68, 0x18,
1402 b43_write_probe_resp_template(dev
, 0x268, 0x4A,
1404 wl
->beacon0_uploaded
= 1;
1406 cmd
|= B43_MACCMD_BEACON0_VALID
;
1408 if (!(cmd
& B43_MACCMD_BEACON1_VALID
)) {
1409 if (!wl
->beacon1_uploaded
) {
1410 b43_write_beacon_template(dev
, 0x468, 0x1A,
1412 wl
->beacon1_uploaded
= 1;
1414 cmd
|= B43_MACCMD_BEACON1_VALID
;
1416 b43_write32(dev
, B43_MMIO_MACCMD
, cmd
);
1419 static void handle_irq_ucode_debug(struct b43_wldev
*dev
)
1424 /* Interrupt handler bottom-half */
1425 static void b43_interrupt_tasklet(struct b43_wldev
*dev
)
1428 u32 dma_reason
[ARRAY_SIZE(dev
->dma_reason
)];
1429 u32 merged_dma_reason
= 0;
1431 unsigned long flags
;
1433 spin_lock_irqsave(&dev
->wl
->irq_lock
, flags
);
1435 B43_WARN_ON(b43_status(dev
) != B43_STAT_STARTED
);
1437 reason
= dev
->irq_reason
;
1438 for (i
= 0; i
< ARRAY_SIZE(dma_reason
); i
++) {
1439 dma_reason
[i
] = dev
->dma_reason
[i
];
1440 merged_dma_reason
|= dma_reason
[i
];
1443 if (unlikely(reason
& B43_IRQ_MAC_TXERR
))
1444 b43err(dev
->wl
, "MAC transmission error\n");
1446 if (unlikely(reason
& B43_IRQ_PHY_TXERR
)) {
1447 b43err(dev
->wl
, "PHY transmission error\n");
1449 if (unlikely(atomic_dec_and_test(&dev
->phy
.txerr_cnt
))) {
1450 atomic_set(&dev
->phy
.txerr_cnt
,
1451 B43_PHY_TX_BADNESS_LIMIT
);
1452 b43err(dev
->wl
, "Too many PHY TX errors, "
1453 "restarting the controller\n");
1454 b43_controller_restart(dev
, "PHY TX errors");
1458 if (unlikely(merged_dma_reason
& (B43_DMAIRQ_FATALMASK
|
1459 B43_DMAIRQ_NONFATALMASK
))) {
1460 if (merged_dma_reason
& B43_DMAIRQ_FATALMASK
) {
1461 b43err(dev
->wl
, "Fatal DMA error: "
1462 "0x%08X, 0x%08X, 0x%08X, "
1463 "0x%08X, 0x%08X, 0x%08X\n",
1464 dma_reason
[0], dma_reason
[1],
1465 dma_reason
[2], dma_reason
[3],
1466 dma_reason
[4], dma_reason
[5]);
1467 b43_controller_restart(dev
, "DMA error");
1469 spin_unlock_irqrestore(&dev
->wl
->irq_lock
, flags
);
1472 if (merged_dma_reason
& B43_DMAIRQ_NONFATALMASK
) {
1473 b43err(dev
->wl
, "DMA error: "
1474 "0x%08X, 0x%08X, 0x%08X, "
1475 "0x%08X, 0x%08X, 0x%08X\n",
1476 dma_reason
[0], dma_reason
[1],
1477 dma_reason
[2], dma_reason
[3],
1478 dma_reason
[4], dma_reason
[5]);
1482 if (unlikely(reason
& B43_IRQ_UCODE_DEBUG
))
1483 handle_irq_ucode_debug(dev
);
1484 if (reason
& B43_IRQ_TBTT_INDI
)
1485 handle_irq_tbtt_indication(dev
);
1486 if (reason
& B43_IRQ_ATIM_END
)
1487 handle_irq_atim_end(dev
);
1488 if (reason
& B43_IRQ_BEACON
)
1489 handle_irq_beacon(dev
);
1490 if (reason
& B43_IRQ_PMQ
)
1491 handle_irq_pmq(dev
);
1492 if (reason
& B43_IRQ_TXFIFO_FLUSH_OK
)
1494 if (reason
& B43_IRQ_NOISESAMPLE_OK
)
1495 handle_irq_noise(dev
);
1497 /* Check the DMA reason registers for received data. */
1498 if (dma_reason
[0] & B43_DMAIRQ_RX_DONE
)
1499 b43_dma_rx(dev
->dma
.rx_ring0
);
1500 if (dma_reason
[3] & B43_DMAIRQ_RX_DONE
)
1501 b43_dma_rx(dev
->dma
.rx_ring3
);
1502 B43_WARN_ON(dma_reason
[1] & B43_DMAIRQ_RX_DONE
);
1503 B43_WARN_ON(dma_reason
[2] & B43_DMAIRQ_RX_DONE
);
1504 B43_WARN_ON(dma_reason
[4] & B43_DMAIRQ_RX_DONE
);
1505 B43_WARN_ON(dma_reason
[5] & B43_DMAIRQ_RX_DONE
);
1507 if (reason
& B43_IRQ_TX_OK
)
1508 handle_irq_transmit_status(dev
);
1510 b43_interrupt_enable(dev
, dev
->irq_savedstate
);
1512 spin_unlock_irqrestore(&dev
->wl
->irq_lock
, flags
);
1515 static void b43_interrupt_ack(struct b43_wldev
*dev
, u32 reason
)
1517 b43_write32(dev
, B43_MMIO_GEN_IRQ_REASON
, reason
);
1519 b43_write32(dev
, B43_MMIO_DMA0_REASON
, dev
->dma_reason
[0]);
1520 b43_write32(dev
, B43_MMIO_DMA1_REASON
, dev
->dma_reason
[1]);
1521 b43_write32(dev
, B43_MMIO_DMA2_REASON
, dev
->dma_reason
[2]);
1522 b43_write32(dev
, B43_MMIO_DMA3_REASON
, dev
->dma_reason
[3]);
1523 b43_write32(dev
, B43_MMIO_DMA4_REASON
, dev
->dma_reason
[4]);
1524 b43_write32(dev
, B43_MMIO_DMA5_REASON
, dev
->dma_reason
[5]);
1527 /* Interrupt handler top-half */
1528 static irqreturn_t
b43_interrupt_handler(int irq
, void *dev_id
)
1530 irqreturn_t ret
= IRQ_NONE
;
1531 struct b43_wldev
*dev
= dev_id
;
1537 spin_lock(&dev
->wl
->irq_lock
);
1539 if (b43_status(dev
) < B43_STAT_STARTED
)
1541 reason
= b43_read32(dev
, B43_MMIO_GEN_IRQ_REASON
);
1542 if (reason
== 0xffffffff) /* shared IRQ */
1545 reason
&= b43_read32(dev
, B43_MMIO_GEN_IRQ_MASK
);
1549 dev
->dma_reason
[0] = b43_read32(dev
, B43_MMIO_DMA0_REASON
)
1551 dev
->dma_reason
[1] = b43_read32(dev
, B43_MMIO_DMA1_REASON
)
1553 dev
->dma_reason
[2] = b43_read32(dev
, B43_MMIO_DMA2_REASON
)
1555 dev
->dma_reason
[3] = b43_read32(dev
, B43_MMIO_DMA3_REASON
)
1557 dev
->dma_reason
[4] = b43_read32(dev
, B43_MMIO_DMA4_REASON
)
1559 dev
->dma_reason
[5] = b43_read32(dev
, B43_MMIO_DMA5_REASON
)
1562 b43_interrupt_ack(dev
, reason
);
1563 /* disable all IRQs. They are enabled again in the bottom half. */
1564 dev
->irq_savedstate
= b43_interrupt_disable(dev
, B43_IRQ_ALL
);
1565 /* save the reason code and call our bottom half. */
1566 dev
->irq_reason
= reason
;
1567 tasklet_schedule(&dev
->isr_tasklet
);
1570 spin_unlock(&dev
->wl
->irq_lock
);
1575 static void do_release_fw(struct b43_firmware_file
*fw
)
1577 release_firmware(fw
->data
);
1579 fw
->filename
= NULL
;
1582 static void b43_release_firmware(struct b43_wldev
*dev
)
1584 do_release_fw(&dev
->fw
.ucode
);
1585 do_release_fw(&dev
->fw
.pcm
);
1586 do_release_fw(&dev
->fw
.initvals
);
1587 do_release_fw(&dev
->fw
.initvals_band
);
1590 static void b43_print_fw_helptext(struct b43_wl
*wl
, bool error
)
1594 text
= "You must go to "
1595 "http://linuxwireless.org/en/users/Drivers/b43#devicefirmware "
1596 "and download the latest firmware (version 4).\n";
1603 static int do_request_fw(struct b43_wldev
*dev
,
1605 struct b43_firmware_file
*fw
)
1607 char path
[sizeof(modparam_fwpostfix
) + 32];
1608 const struct firmware
*blob
;
1609 struct b43_fw_header
*hdr
;
1614 /* Don't fetch anything. Free possibly cached firmware. */
1619 if (strcmp(fw
->filename
, name
) == 0)
1620 return 0; /* Already have this fw. */
1621 /* Free the cached firmware first. */
1625 snprintf(path
, ARRAY_SIZE(path
),
1627 modparam_fwpostfix
, name
);
1628 err
= request_firmware(&blob
, path
, dev
->dev
->dev
);
1630 b43err(dev
->wl
, "Firmware file \"%s\" not found "
1631 "or load failed.\n", path
);
1634 if (blob
->size
< sizeof(struct b43_fw_header
))
1636 hdr
= (struct b43_fw_header
*)(blob
->data
);
1637 switch (hdr
->type
) {
1638 case B43_FW_TYPE_UCODE
:
1639 case B43_FW_TYPE_PCM
:
1640 size
= be32_to_cpu(hdr
->size
);
1641 if (size
!= blob
->size
- sizeof(struct b43_fw_header
))
1644 case B43_FW_TYPE_IV
:
1653 fw
->filename
= name
;
1658 b43err(dev
->wl
, "Firmware file \"%s\" format error.\n", path
);
1659 release_firmware(blob
);
1664 static int b43_request_firmware(struct b43_wldev
*dev
)
1666 struct b43_firmware
*fw
= &dev
->fw
;
1667 const u8 rev
= dev
->dev
->id
.revision
;
1668 const char *filename
;
1673 tmshigh
= ssb_read32(dev
->dev
, SSB_TMSHIGH
);
1674 if ((rev
>= 5) && (rev
<= 10))
1675 filename
= "ucode5";
1676 else if ((rev
>= 11) && (rev
<= 12))
1677 filename
= "ucode11";
1679 filename
= "ucode13";
1682 err
= do_request_fw(dev
, filename
, &fw
->ucode
);
1687 if ((rev
>= 5) && (rev
<= 10))
1693 err
= do_request_fw(dev
, filename
, &fw
->pcm
);
1698 switch (dev
->phy
.type
) {
1700 if ((rev
>= 5) && (rev
<= 10)) {
1701 if (tmshigh
& B43_TMSHIGH_HAVE_2GHZ_PHY
)
1702 filename
= "a0g1initvals5";
1704 filename
= "a0g0initvals5";
1706 goto err_no_initvals
;
1709 if ((rev
>= 5) && (rev
<= 10))
1710 filename
= "b0g0initvals5";
1712 filename
= "lp0initvals13";
1714 goto err_no_initvals
;
1717 if ((rev
>= 11) && (rev
<= 12))
1718 filename
= "n0initvals11";
1720 goto err_no_initvals
;
1723 goto err_no_initvals
;
1725 err
= do_request_fw(dev
, filename
, &fw
->initvals
);
1729 /* Get bandswitch initvals */
1730 switch (dev
->phy
.type
) {
1732 if ((rev
>= 5) && (rev
<= 10)) {
1733 if (tmshigh
& B43_TMSHIGH_HAVE_2GHZ_PHY
)
1734 filename
= "a0g1bsinitvals5";
1736 filename
= "a0g0bsinitvals5";
1737 } else if (rev
>= 11)
1740 goto err_no_initvals
;
1743 if ((rev
>= 5) && (rev
<= 10))
1744 filename
= "b0g0bsinitvals5";
1748 goto err_no_initvals
;
1751 if ((rev
>= 11) && (rev
<= 12))
1752 filename
= "n0bsinitvals11";
1754 goto err_no_initvals
;
1757 goto err_no_initvals
;
1759 err
= do_request_fw(dev
, filename
, &fw
->initvals_band
);
1766 b43_print_fw_helptext(dev
->wl
, 1);
1771 b43err(dev
->wl
, "No microcode available for core rev %u\n", rev
);
1776 b43err(dev
->wl
, "No PCM available for core rev %u\n", rev
);
1781 b43err(dev
->wl
, "No Initial Values firmware file for PHY %u, "
1782 "core rev %u\n", dev
->phy
.type
, rev
);
1786 b43_release_firmware(dev
);
1790 static int b43_upload_microcode(struct b43_wldev
*dev
)
1792 const size_t hdr_len
= sizeof(struct b43_fw_header
);
1794 unsigned int i
, len
;
1795 u16 fwrev
, fwpatch
, fwdate
, fwtime
;
1799 /* Jump the microcode PSM to offset 0 */
1800 macctl
= b43_read32(dev
, B43_MMIO_MACCTL
);
1801 B43_WARN_ON(macctl
& B43_MACCTL_PSM_RUN
);
1802 macctl
|= B43_MACCTL_PSM_JMP0
;
1803 b43_write32(dev
, B43_MMIO_MACCTL
, macctl
);
1804 /* Zero out all microcode PSM registers and shared memory. */
1805 for (i
= 0; i
< 64; i
++)
1806 b43_shm_write16(dev
, B43_SHM_SCRATCH
, i
, 0);
1807 for (i
= 0; i
< 4096; i
+= 2)
1808 b43_shm_write16(dev
, B43_SHM_SHARED
, i
, 0);
1810 /* Upload Microcode. */
1811 data
= (__be32
*) (dev
->fw
.ucode
.data
->data
+ hdr_len
);
1812 len
= (dev
->fw
.ucode
.data
->size
- hdr_len
) / sizeof(__be32
);
1813 b43_shm_control_word(dev
, B43_SHM_UCODE
| B43_SHM_AUTOINC_W
, 0x0000);
1814 for (i
= 0; i
< len
; i
++) {
1815 b43_write32(dev
, B43_MMIO_SHM_DATA
, be32_to_cpu(data
[i
]));
1819 if (dev
->fw
.pcm
.data
) {
1820 /* Upload PCM data. */
1821 data
= (__be32
*) (dev
->fw
.pcm
.data
->data
+ hdr_len
);
1822 len
= (dev
->fw
.pcm
.data
->size
- hdr_len
) / sizeof(__be32
);
1823 b43_shm_control_word(dev
, B43_SHM_HW
, 0x01EA);
1824 b43_write32(dev
, B43_MMIO_SHM_DATA
, 0x00004000);
1825 /* No need for autoinc bit in SHM_HW */
1826 b43_shm_control_word(dev
, B43_SHM_HW
, 0x01EB);
1827 for (i
= 0; i
< len
; i
++) {
1828 b43_write32(dev
, B43_MMIO_SHM_DATA
, be32_to_cpu(data
[i
]));
1833 b43_write32(dev
, B43_MMIO_GEN_IRQ_REASON
, B43_IRQ_ALL
);
1835 /* Start the microcode PSM */
1836 macctl
= b43_read32(dev
, B43_MMIO_MACCTL
);
1837 macctl
&= ~B43_MACCTL_PSM_JMP0
;
1838 macctl
|= B43_MACCTL_PSM_RUN
;
1839 b43_write32(dev
, B43_MMIO_MACCTL
, macctl
);
1841 /* Wait for the microcode to load and respond */
1844 tmp
= b43_read32(dev
, B43_MMIO_GEN_IRQ_REASON
);
1845 if (tmp
== B43_IRQ_MAC_SUSPENDED
)
1849 b43err(dev
->wl
, "Microcode not responding\n");
1850 b43_print_fw_helptext(dev
->wl
, 1);
1854 msleep_interruptible(50);
1855 if (signal_pending(current
)) {
1860 b43_read32(dev
, B43_MMIO_GEN_IRQ_REASON
); /* dummy read */
1862 /* Get and check the revisions. */
1863 fwrev
= b43_shm_read16(dev
, B43_SHM_SHARED
, B43_SHM_SH_UCODEREV
);
1864 fwpatch
= b43_shm_read16(dev
, B43_SHM_SHARED
, B43_SHM_SH_UCODEPATCH
);
1865 fwdate
= b43_shm_read16(dev
, B43_SHM_SHARED
, B43_SHM_SH_UCODEDATE
);
1866 fwtime
= b43_shm_read16(dev
, B43_SHM_SHARED
, B43_SHM_SH_UCODETIME
);
1868 if (fwrev
<= 0x128) {
1869 b43err(dev
->wl
, "YOUR FIRMWARE IS TOO OLD. Firmware from "
1870 "binary drivers older than version 4.x is unsupported. "
1871 "You must upgrade your firmware files.\n");
1872 b43_print_fw_helptext(dev
->wl
, 1);
1876 b43info(dev
->wl
, "Loading firmware version %u.%u "
1877 "(20%.2i-%.2i-%.2i %.2i:%.2i:%.2i)\n",
1879 (fwdate
>> 12) & 0xF, (fwdate
>> 8) & 0xF, fwdate
& 0xFF,
1880 (fwtime
>> 11) & 0x1F, (fwtime
>> 5) & 0x3F, fwtime
& 0x1F);
1882 dev
->fw
.rev
= fwrev
;
1883 dev
->fw
.patch
= fwpatch
;
1885 if (b43_is_old_txhdr_format(dev
)) {
1886 b43warn(dev
->wl
, "You are using an old firmware image. "
1887 "Support for old firmware will be removed in July 2008.\n");
1888 b43_print_fw_helptext(dev
->wl
, 0);
1894 macctl
= b43_read32(dev
, B43_MMIO_MACCTL
);
1895 macctl
&= ~B43_MACCTL_PSM_RUN
;
1896 macctl
|= B43_MACCTL_PSM_JMP0
;
1897 b43_write32(dev
, B43_MMIO_MACCTL
, macctl
);
1902 static int b43_write_initvals(struct b43_wldev
*dev
,
1903 const struct b43_iv
*ivals
,
1907 const struct b43_iv
*iv
;
1912 BUILD_BUG_ON(sizeof(struct b43_iv
) != 6);
1914 for (i
= 0; i
< count
; i
++) {
1915 if (array_size
< sizeof(iv
->offset_size
))
1917 array_size
-= sizeof(iv
->offset_size
);
1918 offset
= be16_to_cpu(iv
->offset_size
);
1919 bit32
= !!(offset
& B43_IV_32BIT
);
1920 offset
&= B43_IV_OFFSET_MASK
;
1921 if (offset
>= 0x1000)
1926 if (array_size
< sizeof(iv
->data
.d32
))
1928 array_size
-= sizeof(iv
->data
.d32
);
1930 value
= be32_to_cpu(get_unaligned(&iv
->data
.d32
));
1931 b43_write32(dev
, offset
, value
);
1933 iv
= (const struct b43_iv
*)((const uint8_t *)iv
+
1939 if (array_size
< sizeof(iv
->data
.d16
))
1941 array_size
-= sizeof(iv
->data
.d16
);
1943 value
= be16_to_cpu(iv
->data
.d16
);
1944 b43_write16(dev
, offset
, value
);
1946 iv
= (const struct b43_iv
*)((const uint8_t *)iv
+
1957 b43err(dev
->wl
, "Initial Values Firmware file-format error.\n");
1958 b43_print_fw_helptext(dev
->wl
, 1);
1963 static int b43_upload_initvals(struct b43_wldev
*dev
)
1965 const size_t hdr_len
= sizeof(struct b43_fw_header
);
1966 const struct b43_fw_header
*hdr
;
1967 struct b43_firmware
*fw
= &dev
->fw
;
1968 const struct b43_iv
*ivals
;
1972 hdr
= (const struct b43_fw_header
*)(fw
->initvals
.data
->data
);
1973 ivals
= (const struct b43_iv
*)(fw
->initvals
.data
->data
+ hdr_len
);
1974 count
= be32_to_cpu(hdr
->size
);
1975 err
= b43_write_initvals(dev
, ivals
, count
,
1976 fw
->initvals
.data
->size
- hdr_len
);
1979 if (fw
->initvals_band
.data
) {
1980 hdr
= (const struct b43_fw_header
*)(fw
->initvals_band
.data
->data
);
1981 ivals
= (const struct b43_iv
*)(fw
->initvals_band
.data
->data
+ hdr_len
);
1982 count
= be32_to_cpu(hdr
->size
);
1983 err
= b43_write_initvals(dev
, ivals
, count
,
1984 fw
->initvals_band
.data
->size
- hdr_len
);
1993 /* Initialize the GPIOs
1994 * http://bcm-specs.sipsolutions.net/GPIO
1996 static int b43_gpio_init(struct b43_wldev
*dev
)
1998 struct ssb_bus
*bus
= dev
->dev
->bus
;
1999 struct ssb_device
*gpiodev
, *pcidev
= NULL
;
2002 b43_write32(dev
, B43_MMIO_MACCTL
, b43_read32(dev
, B43_MMIO_MACCTL
)
2003 & ~B43_MACCTL_GPOUTSMSK
);
2005 b43_write16(dev
, B43_MMIO_GPIO_MASK
, b43_read16(dev
, B43_MMIO_GPIO_MASK
)
2010 if (dev
->dev
->bus
->chip_id
== 0x4301) {
2014 if (0 /* FIXME: conditional unknown */ ) {
2015 b43_write16(dev
, B43_MMIO_GPIO_MASK
,
2016 b43_read16(dev
, B43_MMIO_GPIO_MASK
)
2021 if (dev
->dev
->bus
->sprom
.boardflags_lo
& B43_BFL_PACTRL
) {
2022 b43_write16(dev
, B43_MMIO_GPIO_MASK
,
2023 b43_read16(dev
, B43_MMIO_GPIO_MASK
)
2028 if (dev
->dev
->id
.revision
>= 2)
2029 mask
|= 0x0010; /* FIXME: This is redundant. */
2031 #ifdef CONFIG_SSB_DRIVER_PCICORE
2032 pcidev
= bus
->pcicore
.dev
;
2034 gpiodev
= bus
->chipco
.dev
? : pcidev
;
2037 ssb_write32(gpiodev
, B43_GPIO_CONTROL
,
2038 (ssb_read32(gpiodev
, B43_GPIO_CONTROL
)
2044 /* Turn off all GPIO stuff. Call this on module unload, for example. */
2045 static void b43_gpio_cleanup(struct b43_wldev
*dev
)
2047 struct ssb_bus
*bus
= dev
->dev
->bus
;
2048 struct ssb_device
*gpiodev
, *pcidev
= NULL
;
2050 #ifdef CONFIG_SSB_DRIVER_PCICORE
2051 pcidev
= bus
->pcicore
.dev
;
2053 gpiodev
= bus
->chipco
.dev
? : pcidev
;
2056 ssb_write32(gpiodev
, B43_GPIO_CONTROL
, 0);
2059 /* http://bcm-specs.sipsolutions.net/EnableMac */
2060 void b43_mac_enable(struct b43_wldev
*dev
)
2062 dev
->mac_suspended
--;
2063 B43_WARN_ON(dev
->mac_suspended
< 0);
2064 if (dev
->mac_suspended
== 0) {
2065 b43_write32(dev
, B43_MMIO_MACCTL
,
2066 b43_read32(dev
, B43_MMIO_MACCTL
)
2067 | B43_MACCTL_ENABLED
);
2068 b43_write32(dev
, B43_MMIO_GEN_IRQ_REASON
,
2069 B43_IRQ_MAC_SUSPENDED
);
2071 b43_read32(dev
, B43_MMIO_MACCTL
);
2072 b43_read32(dev
, B43_MMIO_GEN_IRQ_REASON
);
2073 b43_power_saving_ctl_bits(dev
, 0);
2075 /* Re-enable IRQs. */
2076 spin_lock_irq(&dev
->wl
->irq_lock
);
2077 b43_interrupt_enable(dev
, dev
->irq_savedstate
);
2078 spin_unlock_irq(&dev
->wl
->irq_lock
);
2082 /* http://bcm-specs.sipsolutions.net/SuspendMAC */
2083 void b43_mac_suspend(struct b43_wldev
*dev
)
2089 B43_WARN_ON(dev
->mac_suspended
< 0);
2091 if (dev
->mac_suspended
== 0) {
2092 /* Mask IRQs before suspending MAC. Otherwise
2093 * the MAC stays busy and won't suspend. */
2094 spin_lock_irq(&dev
->wl
->irq_lock
);
2095 tmp
= b43_interrupt_disable(dev
, B43_IRQ_ALL
);
2096 spin_unlock_irq(&dev
->wl
->irq_lock
);
2097 b43_synchronize_irq(dev
);
2098 dev
->irq_savedstate
= tmp
;
2100 b43_power_saving_ctl_bits(dev
, B43_PS_AWAKE
);
2101 b43_write32(dev
, B43_MMIO_MACCTL
,
2102 b43_read32(dev
, B43_MMIO_MACCTL
)
2103 & ~B43_MACCTL_ENABLED
);
2104 /* force pci to flush the write */
2105 b43_read32(dev
, B43_MMIO_MACCTL
);
2106 for (i
= 40; i
; i
--) {
2107 tmp
= b43_read32(dev
, B43_MMIO_GEN_IRQ_REASON
);
2108 if (tmp
& B43_IRQ_MAC_SUSPENDED
)
2112 b43err(dev
->wl
, "MAC suspend failed\n");
2115 dev
->mac_suspended
++;
2118 static void b43_adjust_opmode(struct b43_wldev
*dev
)
2120 struct b43_wl
*wl
= dev
->wl
;
2124 ctl
= b43_read32(dev
, B43_MMIO_MACCTL
);
2125 /* Reset status to STA infrastructure mode. */
2126 ctl
&= ~B43_MACCTL_AP
;
2127 ctl
&= ~B43_MACCTL_KEEP_CTL
;
2128 ctl
&= ~B43_MACCTL_KEEP_BADPLCP
;
2129 ctl
&= ~B43_MACCTL_KEEP_BAD
;
2130 ctl
&= ~B43_MACCTL_PROMISC
;
2131 ctl
&= ~B43_MACCTL_BEACPROMISC
;
2132 ctl
|= B43_MACCTL_INFRA
;
2134 if (b43_is_mode(wl
, IEEE80211_IF_TYPE_AP
))
2135 ctl
|= B43_MACCTL_AP
;
2136 else if (b43_is_mode(wl
, IEEE80211_IF_TYPE_IBSS
))
2137 ctl
&= ~B43_MACCTL_INFRA
;
2139 if (wl
->filter_flags
& FIF_CONTROL
)
2140 ctl
|= B43_MACCTL_KEEP_CTL
;
2141 if (wl
->filter_flags
& FIF_FCSFAIL
)
2142 ctl
|= B43_MACCTL_KEEP_BAD
;
2143 if (wl
->filter_flags
& FIF_PLCPFAIL
)
2144 ctl
|= B43_MACCTL_KEEP_BADPLCP
;
2145 if (wl
->filter_flags
& FIF_PROMISC_IN_BSS
)
2146 ctl
|= B43_MACCTL_PROMISC
;
2147 if (wl
->filter_flags
& FIF_BCN_PRBRESP_PROMISC
)
2148 ctl
|= B43_MACCTL_BEACPROMISC
;
2150 /* Workaround: On old hardware the HW-MAC-address-filter
2151 * doesn't work properly, so always run promisc in filter
2152 * it in software. */
2153 if (dev
->dev
->id
.revision
<= 4)
2154 ctl
|= B43_MACCTL_PROMISC
;
2156 b43_write32(dev
, B43_MMIO_MACCTL
, ctl
);
2159 if ((ctl
& B43_MACCTL_INFRA
) && !(ctl
& B43_MACCTL_AP
)) {
2160 if (dev
->dev
->bus
->chip_id
== 0x4306 &&
2161 dev
->dev
->bus
->chip_rev
== 3)
2166 b43_write16(dev
, 0x612, cfp_pretbtt
);
2169 static void b43_rate_memory_write(struct b43_wldev
*dev
, u16 rate
, int is_ofdm
)
2175 offset
+= (b43_plcp_get_ratecode_ofdm(rate
) & 0x000F) * 2;
2178 offset
+= (b43_plcp_get_ratecode_cck(rate
) & 0x000F) * 2;
2180 b43_shm_write16(dev
, B43_SHM_SHARED
, offset
+ 0x20,
2181 b43_shm_read16(dev
, B43_SHM_SHARED
, offset
));
2184 static void b43_rate_memory_init(struct b43_wldev
*dev
)
2186 switch (dev
->phy
.type
) {
2190 b43_rate_memory_write(dev
, B43_OFDM_RATE_6MB
, 1);
2191 b43_rate_memory_write(dev
, B43_OFDM_RATE_12MB
, 1);
2192 b43_rate_memory_write(dev
, B43_OFDM_RATE_18MB
, 1);
2193 b43_rate_memory_write(dev
, B43_OFDM_RATE_24MB
, 1);
2194 b43_rate_memory_write(dev
, B43_OFDM_RATE_36MB
, 1);
2195 b43_rate_memory_write(dev
, B43_OFDM_RATE_48MB
, 1);
2196 b43_rate_memory_write(dev
, B43_OFDM_RATE_54MB
, 1);
2197 if (dev
->phy
.type
== B43_PHYTYPE_A
)
2201 b43_rate_memory_write(dev
, B43_CCK_RATE_1MB
, 0);
2202 b43_rate_memory_write(dev
, B43_CCK_RATE_2MB
, 0);
2203 b43_rate_memory_write(dev
, B43_CCK_RATE_5MB
, 0);
2204 b43_rate_memory_write(dev
, B43_CCK_RATE_11MB
, 0);
2211 /* Set the TX-Antenna for management frames sent by firmware. */
2212 static void b43_mgmtframe_txantenna(struct b43_wldev
*dev
, int antenna
)
2219 ant
|= B43_TXH_PHY_ANT0
;
2222 ant
|= B43_TXH_PHY_ANT1
;
2225 ant
|= B43_TXH_PHY_ANT2
;
2228 ant
|= B43_TXH_PHY_ANT3
;
2230 case B43_ANTENNA_AUTO
:
2231 ant
|= B43_TXH_PHY_ANT01AUTO
;
2237 /* FIXME We also need to set the other flags of the PHY control field somewhere. */
2240 tmp
= b43_shm_read16(dev
, B43_SHM_SHARED
, B43_SHM_SH_BEACPHYCTL
);
2241 tmp
= (tmp
& ~B43_TXH_PHY_ANT
) | ant
;
2242 b43_shm_write16(dev
, B43_SHM_SHARED
, B43_SHM_SH_BEACPHYCTL
, tmp
);
2244 tmp
= b43_shm_read16(dev
, B43_SHM_SHARED
, B43_SHM_SH_ACKCTSPHYCTL
);
2245 tmp
= (tmp
& ~B43_TXH_PHY_ANT
) | ant
;
2246 b43_shm_write16(dev
, B43_SHM_SHARED
, B43_SHM_SH_ACKCTSPHYCTL
, tmp
);
2247 /* For Probe Resposes */
2248 tmp
= b43_shm_read16(dev
, B43_SHM_SHARED
, B43_SHM_SH_PRPHYCTL
);
2249 tmp
= (tmp
& ~B43_TXH_PHY_ANT
) | ant
;
2250 b43_shm_write16(dev
, B43_SHM_SHARED
, B43_SHM_SH_PRPHYCTL
, tmp
);
2253 /* This is the opposite of b43_chip_init() */
2254 static void b43_chip_exit(struct b43_wldev
*dev
)
2256 b43_radio_turn_off(dev
, 1);
2257 b43_gpio_cleanup(dev
);
2258 /* firmware is released later */
2261 /* Initialize the chip
2262 * http://bcm-specs.sipsolutions.net/ChipInit
2264 static int b43_chip_init(struct b43_wldev
*dev
)
2266 struct b43_phy
*phy
= &dev
->phy
;
2268 u32 value32
, macctl
;
2271 /* Initialize the MAC control */
2272 macctl
= B43_MACCTL_IHR_ENABLED
| B43_MACCTL_SHM_ENABLED
;
2274 macctl
|= B43_MACCTL_GMODE
;
2275 macctl
|= B43_MACCTL_INFRA
;
2276 b43_write32(dev
, B43_MMIO_MACCTL
, macctl
);
2278 err
= b43_request_firmware(dev
);
2281 err
= b43_upload_microcode(dev
);
2283 goto out
; /* firmware is released later */
2285 err
= b43_gpio_init(dev
);
2287 goto out
; /* firmware is released later */
2289 err
= b43_upload_initvals(dev
);
2291 goto err_gpio_clean
;
2292 b43_radio_turn_on(dev
);
2294 b43_write16(dev
, 0x03E6, 0x0000);
2295 err
= b43_phy_init(dev
);
2299 /* Select initial Interference Mitigation. */
2300 tmp
= phy
->interfmode
;
2301 phy
->interfmode
= B43_INTERFMODE_NONE
;
2302 b43_radio_set_interference_mitigation(dev
, tmp
);
2304 b43_set_rx_antenna(dev
, B43_ANTENNA_DEFAULT
);
2305 b43_mgmtframe_txantenna(dev
, B43_ANTENNA_DEFAULT
);
2307 if (phy
->type
== B43_PHYTYPE_B
) {
2308 value16
= b43_read16(dev
, 0x005E);
2310 b43_write16(dev
, 0x005E, value16
);
2312 b43_write32(dev
, 0x0100, 0x01000000);
2313 if (dev
->dev
->id
.revision
< 5)
2314 b43_write32(dev
, 0x010C, 0x01000000);
2316 b43_write32(dev
, B43_MMIO_MACCTL
, b43_read32(dev
, B43_MMIO_MACCTL
)
2317 & ~B43_MACCTL_INFRA
);
2318 b43_write32(dev
, B43_MMIO_MACCTL
, b43_read32(dev
, B43_MMIO_MACCTL
)
2319 | B43_MACCTL_INFRA
);
2321 /* Probe Response Timeout value */
2322 /* FIXME: Default to 0, has to be set by ioctl probably... :-/ */
2323 b43_shm_write16(dev
, B43_SHM_SHARED
, 0x0074, 0x0000);
2325 /* Initially set the wireless operation mode. */
2326 b43_adjust_opmode(dev
);
2328 if (dev
->dev
->id
.revision
< 3) {
2329 b43_write16(dev
, 0x060E, 0x0000);
2330 b43_write16(dev
, 0x0610, 0x8000);
2331 b43_write16(dev
, 0x0604, 0x0000);
2332 b43_write16(dev
, 0x0606, 0x0200);
2334 b43_write32(dev
, 0x0188, 0x80000000);
2335 b43_write32(dev
, 0x018C, 0x02000000);
2337 b43_write32(dev
, B43_MMIO_GEN_IRQ_REASON
, 0x00004000);
2338 b43_write32(dev
, B43_MMIO_DMA0_IRQ_MASK
, 0x0001DC00);
2339 b43_write32(dev
, B43_MMIO_DMA1_IRQ_MASK
, 0x0000DC00);
2340 b43_write32(dev
, B43_MMIO_DMA2_IRQ_MASK
, 0x0000DC00);
2341 b43_write32(dev
, B43_MMIO_DMA3_IRQ_MASK
, 0x0001DC00);
2342 b43_write32(dev
, B43_MMIO_DMA4_IRQ_MASK
, 0x0000DC00);
2343 b43_write32(dev
, B43_MMIO_DMA5_IRQ_MASK
, 0x0000DC00);
2345 value32
= ssb_read32(dev
->dev
, SSB_TMSLOW
);
2346 value32
|= 0x00100000;
2347 ssb_write32(dev
->dev
, SSB_TMSLOW
, value32
);
2349 b43_write16(dev
, B43_MMIO_POWERUP_DELAY
,
2350 dev
->dev
->bus
->chipco
.fast_pwrup_delay
);
2353 b43dbg(dev
->wl
, "Chip initialized\n");
2358 b43_radio_turn_off(dev
, 1);
2360 b43_gpio_cleanup(dev
);
2364 static void b43_periodic_every120sec(struct b43_wldev
*dev
)
2366 struct b43_phy
*phy
= &dev
->phy
;
2368 if (phy
->type
!= B43_PHYTYPE_G
|| phy
->rev
< 2)
2371 b43_mac_suspend(dev
);
2372 b43_lo_g_measure(dev
);
2373 b43_mac_enable(dev
);
2374 if (b43_has_hardware_pctl(phy
))
2375 b43_lo_g_ctl_mark_all_unused(dev
);
2378 static void b43_periodic_every60sec(struct b43_wldev
*dev
)
2380 struct b43_phy
*phy
= &dev
->phy
;
2382 if (phy
->type
!= B43_PHYTYPE_G
)
2384 if (!b43_has_hardware_pctl(phy
))
2385 b43_lo_g_ctl_mark_all_unused(dev
);
2386 if (dev
->dev
->bus
->sprom
.boardflags_lo
& B43_BFL_RSSI
) {
2387 b43_mac_suspend(dev
);
2388 b43_calc_nrssi_slope(dev
);
2389 if ((phy
->radio_ver
== 0x2050) && (phy
->radio_rev
== 8)) {
2390 u8 old_chan
= phy
->channel
;
2392 /* VCO Calibration */
2394 b43_radio_selectchannel(dev
, 1, 0);
2396 b43_radio_selectchannel(dev
, 13, 0);
2397 b43_radio_selectchannel(dev
, old_chan
, 0);
2399 b43_mac_enable(dev
);
2403 static void b43_periodic_every30sec(struct b43_wldev
*dev
)
2405 /* Update device statistics. */
2406 b43_calculate_link_quality(dev
);
2409 static void b43_periodic_every15sec(struct b43_wldev
*dev
)
2411 struct b43_phy
*phy
= &dev
->phy
;
2413 if (phy
->type
== B43_PHYTYPE_G
) {
2414 //TODO: update_aci_moving_average
2415 if (phy
->aci_enable
&& phy
->aci_wlan_automatic
) {
2416 b43_mac_suspend(dev
);
2417 if (!phy
->aci_enable
&& 1 /*TODO: not scanning? */ ) {
2418 if (0 /*TODO: bunch of conditions */ ) {
2419 b43_radio_set_interference_mitigation
2420 (dev
, B43_INTERFMODE_MANUALWLAN
);
2422 } else if (1 /*TODO*/) {
2424 if ((aci_average > 1000) && !(b43_radio_aci_scan(dev))) {
2425 b43_radio_set_interference_mitigation(dev,
2426 B43_INTERFMODE_NONE);
2430 b43_mac_enable(dev
);
2431 } else if (phy
->interfmode
== B43_INTERFMODE_NONWLAN
&&
2433 //TODO: implement rev1 workaround
2436 b43_phy_xmitpower(dev
); //FIXME: unless scanning?
2437 //TODO for APHY (temperature?)
2439 atomic_set(&phy
->txerr_cnt
, B43_PHY_TX_BADNESS_LIMIT
);
2443 static void do_periodic_work(struct b43_wldev
*dev
)
2447 state
= dev
->periodic_state
;
2449 b43_periodic_every120sec(dev
);
2451 b43_periodic_every60sec(dev
);
2453 b43_periodic_every30sec(dev
);
2454 b43_periodic_every15sec(dev
);
2457 /* Periodic work locking policy:
2458 * The whole periodic work handler is protected by
2459 * wl->mutex. If another lock is needed somewhere in the
2460 * pwork callchain, it's aquired in-place, where it's needed.
2462 static void b43_periodic_work_handler(struct work_struct
*work
)
2464 struct b43_wldev
*dev
= container_of(work
, struct b43_wldev
,
2465 periodic_work
.work
);
2466 struct b43_wl
*wl
= dev
->wl
;
2467 unsigned long delay
;
2469 mutex_lock(&wl
->mutex
);
2471 if (unlikely(b43_status(dev
) != B43_STAT_STARTED
))
2473 if (b43_debug(dev
, B43_DBG_PWORK_STOP
))
2476 do_periodic_work(dev
);
2478 dev
->periodic_state
++;
2480 if (b43_debug(dev
, B43_DBG_PWORK_FAST
))
2481 delay
= msecs_to_jiffies(50);
2483 delay
= round_jiffies_relative(HZ
* 15);
2484 queue_delayed_work(wl
->hw
->workqueue
, &dev
->periodic_work
, delay
);
2486 mutex_unlock(&wl
->mutex
);
2489 static void b43_periodic_tasks_setup(struct b43_wldev
*dev
)
2491 struct delayed_work
*work
= &dev
->periodic_work
;
2493 dev
->periodic_state
= 0;
2494 INIT_DELAYED_WORK(work
, b43_periodic_work_handler
);
2495 queue_delayed_work(dev
->wl
->hw
->workqueue
, work
, 0);
2498 /* Check if communication with the device works correctly. */
2499 static int b43_validate_chipaccess(struct b43_wldev
*dev
)
2503 backup
= b43_shm_read32(dev
, B43_SHM_SHARED
, 0);
2505 /* Check for read/write and endianness problems. */
2506 b43_shm_write32(dev
, B43_SHM_SHARED
, 0, 0x55AAAA55);
2507 if (b43_shm_read32(dev
, B43_SHM_SHARED
, 0) != 0x55AAAA55)
2509 b43_shm_write32(dev
, B43_SHM_SHARED
, 0, 0xAA5555AA);
2510 if (b43_shm_read32(dev
, B43_SHM_SHARED
, 0) != 0xAA5555AA)
2513 b43_shm_write32(dev
, B43_SHM_SHARED
, 0, backup
);
2515 if ((dev
->dev
->id
.revision
>= 3) && (dev
->dev
->id
.revision
<= 10)) {
2516 /* The 32bit register shadows the two 16bit registers
2517 * with update sideeffects. Validate this. */
2518 b43_write16(dev
, B43_MMIO_TSF_CFP_START
, 0xAAAA);
2519 b43_write32(dev
, B43_MMIO_TSF_CFP_START
, 0xCCCCBBBB);
2520 if (b43_read16(dev
, B43_MMIO_TSF_CFP_START_LOW
) != 0xBBBB)
2522 if (b43_read16(dev
, B43_MMIO_TSF_CFP_START_HIGH
) != 0xCCCC)
2525 b43_write32(dev
, B43_MMIO_TSF_CFP_START
, 0);
2527 v
= b43_read32(dev
, B43_MMIO_MACCTL
);
2528 v
|= B43_MACCTL_GMODE
;
2529 if (v
!= (B43_MACCTL_GMODE
| B43_MACCTL_IHR_ENABLED
))
2534 b43err(dev
->wl
, "Failed to validate the chipaccess\n");
2538 static void b43_security_init(struct b43_wldev
*dev
)
2540 dev
->max_nr_keys
= (dev
->dev
->id
.revision
>= 5) ? 58 : 20;
2541 B43_WARN_ON(dev
->max_nr_keys
> ARRAY_SIZE(dev
->key
));
2542 dev
->ktp
= b43_shm_read16(dev
, B43_SHM_SHARED
, B43_SHM_SH_KTP
);
2543 /* KTP is a word address, but we address SHM bytewise.
2544 * So multiply by two.
2547 if (dev
->dev
->id
.revision
>= 5) {
2548 /* Number of RCMTA address slots */
2549 b43_write16(dev
, B43_MMIO_RCMTA_COUNT
, dev
->max_nr_keys
- 8);
2551 b43_clear_keys(dev
);
2554 static int b43_rng_read(struct hwrng
*rng
, u32
* data
)
2556 struct b43_wl
*wl
= (struct b43_wl
*)rng
->priv
;
2557 unsigned long flags
;
2559 /* Don't take wl->mutex here, as it could deadlock with
2560 * hwrng internal locking. It's not needed to take
2561 * wl->mutex here, anyway. */
2563 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2564 *data
= b43_read16(wl
->current_dev
, B43_MMIO_RNG
);
2565 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2567 return (sizeof(u16
));
2570 static void b43_rng_exit(struct b43_wl
*wl
, bool suspended
)
2572 if (wl
->rng_initialized
)
2573 __hwrng_unregister(&wl
->rng
, suspended
);
2576 static int b43_rng_init(struct b43_wl
*wl
)
2580 snprintf(wl
->rng_name
, ARRAY_SIZE(wl
->rng_name
),
2581 "%s_%s", KBUILD_MODNAME
, wiphy_name(wl
->hw
->wiphy
));
2582 wl
->rng
.name
= wl
->rng_name
;
2583 wl
->rng
.data_read
= b43_rng_read
;
2584 wl
->rng
.priv
= (unsigned long)wl
;
2585 wl
->rng_initialized
= 1;
2586 err
= hwrng_register(&wl
->rng
);
2588 wl
->rng_initialized
= 0;
2589 b43err(wl
, "Failed to register the random "
2590 "number generator (%d)\n", err
);
2596 static int b43_op_tx(struct ieee80211_hw
*hw
,
2597 struct sk_buff
*skb
,
2598 struct ieee80211_tx_control
*ctl
)
2600 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
2601 struct b43_wldev
*dev
= wl
->current_dev
;
2602 unsigned long flags
;
2606 return NETDEV_TX_BUSY
;
2608 /* Transmissions on seperate queues can run concurrently. */
2609 read_lock_irqsave(&wl
->tx_lock
, flags
);
2612 if (likely(b43_status(dev
) >= B43_STAT_STARTED
))
2613 err
= b43_dma_tx(dev
, skb
, ctl
);
2615 read_unlock_irqrestore(&wl
->tx_lock
, flags
);
2618 return NETDEV_TX_BUSY
;
2619 return NETDEV_TX_OK
;
2622 static int b43_op_conf_tx(struct ieee80211_hw
*hw
,
2624 const struct ieee80211_tx_queue_params
*params
)
2629 static int b43_op_get_tx_stats(struct ieee80211_hw
*hw
,
2630 struct ieee80211_tx_queue_stats
*stats
)
2632 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
2633 struct b43_wldev
*dev
= wl
->current_dev
;
2634 unsigned long flags
;
2639 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2640 if (likely(b43_status(dev
) >= B43_STAT_STARTED
)) {
2641 b43_dma_get_tx_stats(dev
, stats
);
2644 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2649 static int b43_op_get_stats(struct ieee80211_hw
*hw
,
2650 struct ieee80211_low_level_stats
*stats
)
2652 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
2653 unsigned long flags
;
2655 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2656 memcpy(stats
, &wl
->ieee_stats
, sizeof(*stats
));
2657 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2662 static const char *phymode_to_string(unsigned int phymode
)
2677 static int find_wldev_for_phymode(struct b43_wl
*wl
,
2678 unsigned int phymode
,
2679 struct b43_wldev
**dev
, bool * gmode
)
2681 struct b43_wldev
*d
;
2683 list_for_each_entry(d
, &wl
->devlist
, list
) {
2684 if (d
->phy
.possible_phymodes
& phymode
) {
2685 /* Ok, this device supports the PHY-mode.
2686 * Now figure out how the gmode bit has to be
2687 * set to support it. */
2688 if (phymode
== B43_PHYMODE_A
)
2701 static void b43_put_phy_into_reset(struct b43_wldev
*dev
)
2703 struct ssb_device
*sdev
= dev
->dev
;
2706 tmslow
= ssb_read32(sdev
, SSB_TMSLOW
);
2707 tmslow
&= ~B43_TMSLOW_GMODE
;
2708 tmslow
|= B43_TMSLOW_PHYRESET
;
2709 tmslow
|= SSB_TMSLOW_FGC
;
2710 ssb_write32(sdev
, SSB_TMSLOW
, tmslow
);
2713 tmslow
= ssb_read32(sdev
, SSB_TMSLOW
);
2714 tmslow
&= ~SSB_TMSLOW_FGC
;
2715 tmslow
|= B43_TMSLOW_PHYRESET
;
2716 ssb_write32(sdev
, SSB_TMSLOW
, tmslow
);
2720 /* Expects wl->mutex locked */
2721 static int b43_switch_phymode(struct b43_wl
*wl
, unsigned int new_mode
)
2723 struct b43_wldev
*up_dev
;
2724 struct b43_wldev
*down_dev
;
2729 err
= find_wldev_for_phymode(wl
, new_mode
, &up_dev
, &gmode
);
2731 b43err(wl
, "Could not find a device for %s-PHY mode\n",
2732 phymode_to_string(new_mode
));
2735 if ((up_dev
== wl
->current_dev
) &&
2736 (!!wl
->current_dev
->phy
.gmode
== !!gmode
)) {
2737 /* This device is already running. */
2740 b43dbg(wl
, "Reconfiguring PHYmode to %s-PHY\n",
2741 phymode_to_string(new_mode
));
2742 down_dev
= wl
->current_dev
;
2744 prev_status
= b43_status(down_dev
);
2745 /* Shutdown the currently running core. */
2746 if (prev_status
>= B43_STAT_STARTED
)
2747 b43_wireless_core_stop(down_dev
);
2748 if (prev_status
>= B43_STAT_INITIALIZED
)
2749 b43_wireless_core_exit(down_dev
);
2751 if (down_dev
!= up_dev
) {
2752 /* We switch to a different core, so we put PHY into
2753 * RESET on the old core. */
2754 b43_put_phy_into_reset(down_dev
);
2757 /* Now start the new core. */
2758 up_dev
->phy
.gmode
= gmode
;
2759 if (prev_status
>= B43_STAT_INITIALIZED
) {
2760 err
= b43_wireless_core_init(up_dev
);
2762 b43err(wl
, "Fatal: Could not initialize device for "
2763 "newly selected %s-PHY mode\n",
2764 phymode_to_string(new_mode
));
2768 if (prev_status
>= B43_STAT_STARTED
) {
2769 err
= b43_wireless_core_start(up_dev
);
2771 b43err(wl
, "Fatal: Coult not start device for "
2772 "newly selected %s-PHY mode\n",
2773 phymode_to_string(new_mode
));
2774 b43_wireless_core_exit(up_dev
);
2778 B43_WARN_ON(b43_status(up_dev
) != prev_status
);
2780 wl
->current_dev
= up_dev
;
2784 /* Whoops, failed to init the new core. No core is operating now. */
2785 wl
->current_dev
= NULL
;
2789 /* Check if the use of the antenna that ieee80211 told us to
2790 * use is possible. This will fall back to DEFAULT.
2791 * "antenna_nr" is the antenna identifier we got from ieee80211. */
2792 u8
b43_ieee80211_antenna_sanitize(struct b43_wldev
*dev
,
2797 if (antenna_nr
== 0) {
2798 /* Zero means "use default antenna". That's always OK. */
2802 /* Get the mask of available antennas. */
2804 antenna_mask
= dev
->dev
->bus
->sprom
.ant_available_bg
;
2806 antenna_mask
= dev
->dev
->bus
->sprom
.ant_available_a
;
2808 if (!(antenna_mask
& (1 << (antenna_nr
- 1)))) {
2809 /* This antenna is not available. Fall back to default. */
2816 static int b43_antenna_from_ieee80211(struct b43_wldev
*dev
, u8 antenna
)
2818 antenna
= b43_ieee80211_antenna_sanitize(dev
, antenna
);
2820 case 0: /* default/diversity */
2821 return B43_ANTENNA_DEFAULT
;
2822 case 1: /* Antenna 0 */
2823 return B43_ANTENNA0
;
2824 case 2: /* Antenna 1 */
2825 return B43_ANTENNA1
;
2826 case 3: /* Antenna 2 */
2827 return B43_ANTENNA2
;
2828 case 4: /* Antenna 3 */
2829 return B43_ANTENNA3
;
2831 return B43_ANTENNA_DEFAULT
;
2835 static int b43_op_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
)
2837 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
2838 struct b43_wldev
*dev
;
2839 struct b43_phy
*phy
;
2840 unsigned long flags
;
2841 unsigned int new_phymode
= 0xFFFF;
2846 mutex_lock(&wl
->mutex
);
2848 /* Switch the PHY mode (if necessary). */
2849 switch (conf
->phymode
) {
2850 case MODE_IEEE80211A
:
2851 new_phymode
= B43_PHYMODE_A
;
2853 case MODE_IEEE80211B
:
2854 new_phymode
= B43_PHYMODE_B
;
2856 case MODE_IEEE80211G
:
2857 new_phymode
= B43_PHYMODE_G
;
2862 err
= b43_switch_phymode(wl
, new_phymode
);
2864 goto out_unlock_mutex
;
2865 dev
= wl
->current_dev
;
2868 /* Disable IRQs while reconfiguring the device.
2869 * This makes it possible to drop the spinlock throughout
2870 * the reconfiguration process. */
2871 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2872 if (b43_status(dev
) < B43_STAT_STARTED
) {
2873 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2874 goto out_unlock_mutex
;
2876 savedirqs
= b43_interrupt_disable(dev
, B43_IRQ_ALL
);
2877 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2878 b43_synchronize_irq(dev
);
2880 /* Switch to the requested channel.
2881 * The firmware takes care of races with the TX handler. */
2882 if (conf
->channel_val
!= phy
->channel
)
2883 b43_radio_selectchannel(dev
, conf
->channel_val
, 0);
2885 /* Enable/Disable ShortSlot timing. */
2886 if ((!!(conf
->flags
& IEEE80211_CONF_SHORT_SLOT_TIME
)) !=
2888 B43_WARN_ON(phy
->type
!= B43_PHYTYPE_G
);
2889 if (conf
->flags
& IEEE80211_CONF_SHORT_SLOT_TIME
)
2890 b43_short_slot_timing_enable(dev
);
2892 b43_short_slot_timing_disable(dev
);
2895 dev
->wl
->radiotap_enabled
= !!(conf
->flags
& IEEE80211_CONF_RADIOTAP
);
2897 /* Adjust the desired TX power level. */
2898 if (conf
->power_level
!= 0) {
2899 if (conf
->power_level
!= phy
->power_level
) {
2900 phy
->power_level
= conf
->power_level
;
2901 b43_phy_xmitpower(dev
);
2905 /* Antennas for RX and management frame TX. */
2906 antenna
= b43_antenna_from_ieee80211(dev
, conf
->antenna_sel_tx
);
2907 b43_mgmtframe_txantenna(dev
, antenna
);
2908 antenna
= b43_antenna_from_ieee80211(dev
, conf
->antenna_sel_rx
);
2909 b43_set_rx_antenna(dev
, antenna
);
2911 /* Update templates for AP mode. */
2912 if (b43_is_mode(wl
, IEEE80211_IF_TYPE_AP
))
2913 b43_set_beacon_int(dev
, conf
->beacon_int
);
2915 if (!!conf
->radio_enabled
!= phy
->radio_on
) {
2916 if (conf
->radio_enabled
) {
2917 b43_radio_turn_on(dev
);
2918 b43info(dev
->wl
, "Radio turned on by software\n");
2919 if (!dev
->radio_hw_enable
) {
2920 b43info(dev
->wl
, "The hardware RF-kill button "
2921 "still turns the radio physically off. "
2922 "Press the button to turn it on.\n");
2925 b43_radio_turn_off(dev
, 0);
2926 b43info(dev
->wl
, "Radio turned off by software\n");
2930 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2931 b43_interrupt_enable(dev
, savedirqs
);
2933 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2935 mutex_unlock(&wl
->mutex
);
2940 static int b43_op_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
2941 const u8
*local_addr
, const u8
*addr
,
2942 struct ieee80211_key_conf
*key
)
2944 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
2945 struct b43_wldev
*dev
;
2946 unsigned long flags
;
2950 DECLARE_MAC_BUF(mac
);
2952 if (modparam_nohwcrypt
)
2953 return -ENOSPC
; /* User disabled HW-crypto */
2955 mutex_lock(&wl
->mutex
);
2956 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2958 dev
= wl
->current_dev
;
2960 if (!dev
|| b43_status(dev
) < B43_STAT_INITIALIZED
)
2966 if (key
->keylen
== 5)
2967 algorithm
= B43_SEC_ALGO_WEP40
;
2969 algorithm
= B43_SEC_ALGO_WEP104
;
2972 algorithm
= B43_SEC_ALGO_TKIP
;
2975 algorithm
= B43_SEC_ALGO_AES
;
2981 index
= (u8
) (key
->keyidx
);
2987 if (algorithm
== B43_SEC_ALGO_TKIP
) {
2988 /* FIXME: No TKIP hardware encryption for now. */
2993 if (is_broadcast_ether_addr(addr
)) {
2994 /* addr is FF:FF:FF:FF:FF:FF for default keys */
2995 err
= b43_key_write(dev
, index
, algorithm
,
2996 key
->key
, key
->keylen
, NULL
, key
);
2999 * either pairwise key or address is 00:00:00:00:00:00
3000 * for transmit-only keys
3002 err
= b43_key_write(dev
, -1, algorithm
,
3003 key
->key
, key
->keylen
, addr
, key
);
3008 if (algorithm
== B43_SEC_ALGO_WEP40
||
3009 algorithm
== B43_SEC_ALGO_WEP104
) {
3010 b43_hf_write(dev
, b43_hf_read(dev
) | B43_HF_USEDEFKEYS
);
3013 b43_hf_read(dev
) & ~B43_HF_USEDEFKEYS
);
3015 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
3018 err
= b43_key_clear(dev
, key
->hw_key_idx
);
3027 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
3028 mutex_unlock(&wl
->mutex
);
3030 b43dbg(wl
, "%s hardware based encryption for keyidx: %d, "
3032 cmd
== SET_KEY
? "Using" : "Disabling", key
->keyidx
,
3033 print_mac(mac
, addr
));
3038 static void b43_op_configure_filter(struct ieee80211_hw
*hw
,
3039 unsigned int changed
, unsigned int *fflags
,
3040 int mc_count
, struct dev_addr_list
*mc_list
)
3042 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
3043 struct b43_wldev
*dev
= wl
->current_dev
;
3044 unsigned long flags
;
3051 spin_lock_irqsave(&wl
->irq_lock
, flags
);
3052 *fflags
&= FIF_PROMISC_IN_BSS
|
3058 FIF_BCN_PRBRESP_PROMISC
;
3060 changed
&= FIF_PROMISC_IN_BSS
|
3066 FIF_BCN_PRBRESP_PROMISC
;
3068 wl
->filter_flags
= *fflags
;
3070 if (changed
&& b43_status(dev
) >= B43_STAT_INITIALIZED
)
3071 b43_adjust_opmode(dev
);
3072 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
3075 static int b43_op_config_interface(struct ieee80211_hw
*hw
,
3076 struct ieee80211_vif
*vif
,
3077 struct ieee80211_if_conf
*conf
)
3079 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
3080 struct b43_wldev
*dev
= wl
->current_dev
;
3081 unsigned long flags
;
3085 mutex_lock(&wl
->mutex
);
3086 spin_lock_irqsave(&wl
->irq_lock
, flags
);
3087 B43_WARN_ON(wl
->vif
!= vif
);
3089 memcpy(wl
->bssid
, conf
->bssid
, ETH_ALEN
);
3091 memset(wl
->bssid
, 0, ETH_ALEN
);
3092 if (b43_status(dev
) >= B43_STAT_INITIALIZED
) {
3093 if (b43_is_mode(wl
, IEEE80211_IF_TYPE_AP
)) {
3094 B43_WARN_ON(conf
->type
!= IEEE80211_IF_TYPE_AP
);
3095 b43_set_ssid(dev
, conf
->ssid
, conf
->ssid_len
);
3097 b43_update_templates(wl
, conf
->beacon
);
3099 b43_write_mac_bssid_templates(dev
);
3101 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
3102 mutex_unlock(&wl
->mutex
);
3107 /* Locking: wl->mutex */
3108 static void b43_wireless_core_stop(struct b43_wldev
*dev
)
3110 struct b43_wl
*wl
= dev
->wl
;
3111 unsigned long flags
;
3113 if (b43_status(dev
) < B43_STAT_STARTED
)
3116 /* Disable and sync interrupts. We must do this before than
3117 * setting the status to INITIALIZED, as the interrupt handler
3118 * won't care about IRQs then. */
3119 spin_lock_irqsave(&wl
->irq_lock
, flags
);
3120 dev
->irq_savedstate
= b43_interrupt_disable(dev
, B43_IRQ_ALL
);
3121 b43_read32(dev
, B43_MMIO_GEN_IRQ_MASK
); /* flush */
3122 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
3123 b43_synchronize_irq(dev
);
3125 write_lock_irqsave(&wl
->tx_lock
, flags
);
3126 b43_set_status(dev
, B43_STAT_INITIALIZED
);
3127 write_unlock_irqrestore(&wl
->tx_lock
, flags
);
3129 mutex_unlock(&wl
->mutex
);
3130 /* Must unlock as it would otherwise deadlock. No races here.
3131 * Cancel the possibly running self-rearming periodic work. */
3132 cancel_delayed_work_sync(&dev
->periodic_work
);
3133 mutex_lock(&wl
->mutex
);
3135 b43_mac_suspend(dev
);
3136 free_irq(dev
->dev
->irq
, dev
);
3137 b43dbg(wl
, "Wireless interface stopped\n");
3140 /* Locking: wl->mutex */
3141 static int b43_wireless_core_start(struct b43_wldev
*dev
)
3145 B43_WARN_ON(b43_status(dev
) != B43_STAT_INITIALIZED
);
3147 drain_txstatus_queue(dev
);
3148 err
= request_irq(dev
->dev
->irq
, b43_interrupt_handler
,
3149 IRQF_SHARED
, KBUILD_MODNAME
, dev
);
3151 b43err(dev
->wl
, "Cannot request IRQ-%d\n", dev
->dev
->irq
);
3155 /* We are ready to run. */
3156 b43_set_status(dev
, B43_STAT_STARTED
);
3158 /* Start data flow (TX/RX). */
3159 b43_mac_enable(dev
);
3160 b43_interrupt_enable(dev
, dev
->irq_savedstate
);
3161 ieee80211_start_queues(dev
->wl
->hw
);
3163 /* Start maintainance work */
3164 b43_periodic_tasks_setup(dev
);
3166 b43dbg(dev
->wl
, "Wireless interface started\n");
3171 /* Get PHY and RADIO versioning numbers */
3172 static int b43_phy_versioning(struct b43_wldev
*dev
)
3174 struct b43_phy
*phy
= &dev
->phy
;
3182 int unsupported
= 0;
3184 /* Get PHY versioning */
3185 tmp
= b43_read16(dev
, B43_MMIO_PHY_VER
);
3186 analog_type
= (tmp
& B43_PHYVER_ANALOG
) >> B43_PHYVER_ANALOG_SHIFT
;
3187 phy_type
= (tmp
& B43_PHYVER_TYPE
) >> B43_PHYVER_TYPE_SHIFT
;
3188 phy_rev
= (tmp
& B43_PHYVER_VERSION
);
3195 if (phy_rev
!= 2 && phy_rev
!= 4 && phy_rev
!= 6
3203 #ifdef CONFIG_B43_NPHY
3213 b43err(dev
->wl
, "FOUND UNSUPPORTED PHY "
3214 "(Analog %u, Type %u, Revision %u)\n",
3215 analog_type
, phy_type
, phy_rev
);
3218 b43dbg(dev
->wl
, "Found PHY: Analog %u, Type %u, Revision %u\n",
3219 analog_type
, phy_type
, phy_rev
);
3221 /* Get RADIO versioning */
3222 if (dev
->dev
->bus
->chip_id
== 0x4317) {
3223 if (dev
->dev
->bus
->chip_rev
== 0)
3225 else if (dev
->dev
->bus
->chip_rev
== 1)
3230 b43_write16(dev
, B43_MMIO_RADIO_CONTROL
, B43_RADIOCTL_ID
);
3231 tmp
= b43_read16(dev
, B43_MMIO_RADIO_DATA_LOW
);
3232 b43_write16(dev
, B43_MMIO_RADIO_CONTROL
, B43_RADIOCTL_ID
);
3233 tmp
|= (u32
)b43_read16(dev
, B43_MMIO_RADIO_DATA_HIGH
) << 16;
3235 radio_manuf
= (tmp
& 0x00000FFF);
3236 radio_ver
= (tmp
& 0x0FFFF000) >> 12;
3237 radio_rev
= (tmp
& 0xF0000000) >> 28;
3238 if (radio_manuf
!= 0x17F /* Broadcom */)
3242 if (radio_ver
!= 0x2060)
3246 if (radio_manuf
!= 0x17F)
3250 if ((radio_ver
& 0xFFF0) != 0x2050)
3254 if (radio_ver
!= 0x2050)
3258 if (radio_ver
!= 0x2055)
3265 b43err(dev
->wl
, "FOUND UNSUPPORTED RADIO "
3266 "(Manuf 0x%X, Version 0x%X, Revision %u)\n",
3267 radio_manuf
, radio_ver
, radio_rev
);
3270 b43dbg(dev
->wl
, "Found Radio: Manuf 0x%X, Version 0x%X, Revision %u\n",
3271 radio_manuf
, radio_ver
, radio_rev
);
3273 phy
->radio_manuf
= radio_manuf
;
3274 phy
->radio_ver
= radio_ver
;
3275 phy
->radio_rev
= radio_rev
;
3277 phy
->analog
= analog_type
;
3278 phy
->type
= phy_type
;
3284 static void setup_struct_phy_for_init(struct b43_wldev
*dev
,
3285 struct b43_phy
*phy
)
3287 struct b43_txpower_lo_control
*lo
;
3290 memset(phy
->minlowsig
, 0xFF, sizeof(phy
->minlowsig
));
3291 memset(phy
->minlowsigpos
, 0, sizeof(phy
->minlowsigpos
));
3293 phy
->aci_enable
= 0;
3294 phy
->aci_wlan_automatic
= 0;
3295 phy
->aci_hw_rssi
= 0;
3297 phy
->radio_off_context
.valid
= 0;
3299 lo
= phy
->lo_control
;
3301 memset(lo
, 0, sizeof(*(phy
->lo_control
)));
3305 phy
->max_lb_gain
= 0;
3306 phy
->trsw_rx_gain
= 0;
3307 phy
->txpwr_offset
= 0;
3310 phy
->nrssislope
= 0;
3311 for (i
= 0; i
< ARRAY_SIZE(phy
->nrssi
); i
++)
3312 phy
->nrssi
[i
] = -1000;
3313 for (i
= 0; i
< ARRAY_SIZE(phy
->nrssi_lt
); i
++)
3314 phy
->nrssi_lt
[i
] = i
;
3316 phy
->lofcal
= 0xFFFF;
3317 phy
->initval
= 0xFFFF;
3319 phy
->interfmode
= B43_INTERFMODE_NONE
;
3320 phy
->channel
= 0xFF;
3322 phy
->hardware_power_control
= !!modparam_hwpctl
;
3324 /* PHY TX errors counter. */
3325 atomic_set(&phy
->txerr_cnt
, B43_PHY_TX_BADNESS_LIMIT
);
3327 /* OFDM-table address caching. */
3328 phy
->ofdmtab_addr_direction
= B43_OFDMTAB_DIRECTION_UNKNOWN
;
3331 static void setup_struct_wldev_for_init(struct b43_wldev
*dev
)
3335 /* Assume the radio is enabled. If it's not enabled, the state will
3336 * immediately get fixed on the first periodic work run. */
3337 dev
->radio_hw_enable
= 1;
3340 memset(&dev
->stats
, 0, sizeof(dev
->stats
));
3342 setup_struct_phy_for_init(dev
, &dev
->phy
);
3344 /* IRQ related flags */
3345 dev
->irq_reason
= 0;
3346 memset(dev
->dma_reason
, 0, sizeof(dev
->dma_reason
));
3347 dev
->irq_savedstate
= B43_IRQ_MASKTEMPLATE
;
3349 dev
->mac_suspended
= 1;
3351 /* Noise calculation context */
3352 memset(&dev
->noisecalc
, 0, sizeof(dev
->noisecalc
));
3355 static void b43_bluetooth_coext_enable(struct b43_wldev
*dev
)
3357 struct ssb_sprom
*sprom
= &dev
->dev
->bus
->sprom
;
3360 if (!modparam_btcoex
)
3362 if (!(sprom
->boardflags_lo
& B43_BFL_BTCOEXIST
))
3364 if (dev
->phy
.type
!= B43_PHYTYPE_B
&& !dev
->phy
.gmode
)
3367 hf
= b43_hf_read(dev
);
3368 if (sprom
->boardflags_lo
& B43_BFL_BTCMOD
)
3369 hf
|= B43_HF_BTCOEXALT
;
3371 hf
|= B43_HF_BTCOEX
;
3372 b43_hf_write(dev
, hf
);
3375 static void b43_bluetooth_coext_disable(struct b43_wldev
*dev
)
3377 if (!modparam_btcoex
)
3382 static void b43_imcfglo_timeouts_workaround(struct b43_wldev
*dev
)
3384 #ifdef CONFIG_SSB_DRIVER_PCICORE
3385 struct ssb_bus
*bus
= dev
->dev
->bus
;
3388 if (bus
->pcicore
.dev
&&
3389 bus
->pcicore
.dev
->id
.coreid
== SSB_DEV_PCI
&&
3390 bus
->pcicore
.dev
->id
.revision
<= 5) {
3391 /* IMCFGLO timeouts workaround. */
3392 tmp
= ssb_read32(dev
->dev
, SSB_IMCFGLO
);
3393 tmp
&= ~SSB_IMCFGLO_REQTO
;
3394 tmp
&= ~SSB_IMCFGLO_SERTO
;
3395 switch (bus
->bustype
) {
3396 case SSB_BUSTYPE_PCI
:
3397 case SSB_BUSTYPE_PCMCIA
:
3400 case SSB_BUSTYPE_SSB
:
3404 ssb_write32(dev
->dev
, SSB_IMCFGLO
, tmp
);
3406 #endif /* CONFIG_SSB_DRIVER_PCICORE */
3409 /* Write the short and long frame retry limit values. */
3410 static void b43_set_retry_limits(struct b43_wldev
*dev
,
3411 unsigned int short_retry
,
3412 unsigned int long_retry
)
3414 /* The retry limit is a 4-bit counter. Enforce this to avoid overflowing
3415 * the chip-internal counter. */
3416 short_retry
= min(short_retry
, (unsigned int)0xF);
3417 long_retry
= min(long_retry
, (unsigned int)0xF);
3419 b43_shm_write16(dev
, B43_SHM_SCRATCH
, B43_SHM_SC_SRLIMIT
,
3421 b43_shm_write16(dev
, B43_SHM_SCRATCH
, B43_SHM_SC_LRLIMIT
,
3425 /* Shutdown a wireless core */
3426 /* Locking: wl->mutex */
3427 static void b43_wireless_core_exit(struct b43_wldev
*dev
)
3429 struct b43_phy
*phy
= &dev
->phy
;
3432 B43_WARN_ON(b43_status(dev
) > B43_STAT_INITIALIZED
);
3433 if (b43_status(dev
) != B43_STAT_INITIALIZED
)
3435 b43_set_status(dev
, B43_STAT_UNINIT
);
3437 /* Stop the microcode PSM. */
3438 macctl
= b43_read32(dev
, B43_MMIO_MACCTL
);
3439 macctl
&= ~B43_MACCTL_PSM_RUN
;
3440 macctl
|= B43_MACCTL_PSM_JMP0
;
3441 b43_write32(dev
, B43_MMIO_MACCTL
, macctl
);
3443 if (!dev
->suspend_in_progress
) {
3445 b43_rng_exit(dev
->wl
, false);
3449 b43_radio_turn_off(dev
, 1);
3450 b43_switch_analog(dev
, 0);
3451 if (phy
->dyn_tssi_tbl
)
3452 kfree(phy
->tssi2dbm
);
3453 kfree(phy
->lo_control
);
3454 phy
->lo_control
= NULL
;
3455 if (dev
->wl
->current_beacon
) {
3456 dev_kfree_skb_any(dev
->wl
->current_beacon
);
3457 dev
->wl
->current_beacon
= NULL
;
3460 ssb_device_disable(dev
->dev
, 0);
3461 ssb_bus_may_powerdown(dev
->dev
->bus
);
3464 /* Initialize a wireless core */
3465 static int b43_wireless_core_init(struct b43_wldev
*dev
)
3467 struct b43_wl
*wl
= dev
->wl
;
3468 struct ssb_bus
*bus
= dev
->dev
->bus
;
3469 struct ssb_sprom
*sprom
= &bus
->sprom
;
3470 struct b43_phy
*phy
= &dev
->phy
;
3474 B43_WARN_ON(b43_status(dev
) != B43_STAT_UNINIT
);
3476 err
= ssb_bus_powerup(bus
, 0);
3479 if (!ssb_device_is_enabled(dev
->dev
)) {
3480 tmp
= phy
->gmode
? B43_TMSLOW_GMODE
: 0;
3481 b43_wireless_core_reset(dev
, tmp
);
3484 if ((phy
->type
== B43_PHYTYPE_B
) || (phy
->type
== B43_PHYTYPE_G
)) {
3486 kzalloc(sizeof(*(phy
->lo_control
)), GFP_KERNEL
);
3487 if (!phy
->lo_control
) {
3492 setup_struct_wldev_for_init(dev
);
3494 err
= b43_phy_init_tssi2dbm_table(dev
);
3496 goto err_kfree_lo_control
;
3498 /* Enable IRQ routing to this device. */
3499 ssb_pcicore_dev_irqvecs_enable(&bus
->pcicore
, dev
->dev
);
3501 b43_imcfglo_timeouts_workaround(dev
);
3502 b43_bluetooth_coext_disable(dev
);
3503 b43_phy_early_init(dev
);
3504 err
= b43_chip_init(dev
);
3506 goto err_kfree_tssitbl
;
3507 b43_shm_write16(dev
, B43_SHM_SHARED
,
3508 B43_SHM_SH_WLCOREREV
, dev
->dev
->id
.revision
);
3509 hf
= b43_hf_read(dev
);
3510 if (phy
->type
== B43_PHYTYPE_G
) {
3514 if (sprom
->boardflags_lo
& B43_BFL_PACTRL
)
3515 hf
|= B43_HF_OFDMPABOOST
;
3516 } else if (phy
->type
== B43_PHYTYPE_B
) {
3518 if (phy
->rev
>= 2 && phy
->radio_ver
== 0x2050)
3521 b43_hf_write(dev
, hf
);
3523 b43_set_retry_limits(dev
, B43_DEFAULT_SHORT_RETRY_LIMIT
,
3524 B43_DEFAULT_LONG_RETRY_LIMIT
);
3525 b43_shm_write16(dev
, B43_SHM_SHARED
, B43_SHM_SH_SFFBLIM
, 3);
3526 b43_shm_write16(dev
, B43_SHM_SHARED
, B43_SHM_SH_LFFBLIM
, 2);
3528 /* Disable sending probe responses from firmware.
3529 * Setting the MaxTime to one usec will always trigger
3530 * a timeout, so we never send any probe resp.
3531 * A timeout of zero is infinite. */
3532 b43_shm_write16(dev
, B43_SHM_SHARED
, B43_SHM_SH_PRMAXTIME
, 1);
3534 b43_rate_memory_init(dev
);
3536 /* Minimum Contention Window */
3537 if (phy
->type
== B43_PHYTYPE_B
) {
3538 b43_shm_write16(dev
, B43_SHM_SCRATCH
, B43_SHM_SC_MINCONT
, 0x1F);
3540 b43_shm_write16(dev
, B43_SHM_SCRATCH
, B43_SHM_SC_MINCONT
, 0xF);
3542 /* Maximum Contention Window */
3543 b43_shm_write16(dev
, B43_SHM_SCRATCH
, B43_SHM_SC_MAXCONT
, 0x3FF);
3545 err
= b43_dma_init(dev
);
3552 b43_write16(dev
, 0x0612, 0x0050);
3553 b43_shm_write16(dev
, B43_SHM_SHARED
, 0x0416, 0x0050);
3554 b43_shm_write16(dev
, B43_SHM_SHARED
, 0x0414, 0x01F4);
3557 b43_bluetooth_coext_enable(dev
);
3559 ssb_bus_powerup(bus
, 1); /* Enable dynamic PCTL */
3560 b43_upload_card_macaddress(dev
);
3561 b43_security_init(dev
);
3562 if (!dev
->suspend_in_progress
)
3565 b43_set_status(dev
, B43_STAT_INITIALIZED
);
3567 if (!dev
->suspend_in_progress
)
3575 if (phy
->dyn_tssi_tbl
)
3576 kfree(phy
->tssi2dbm
);
3577 err_kfree_lo_control
:
3578 kfree(phy
->lo_control
);
3579 phy
->lo_control
= NULL
;
3581 ssb_bus_may_powerdown(bus
);
3582 B43_WARN_ON(b43_status(dev
) != B43_STAT_UNINIT
);
3586 static int b43_op_add_interface(struct ieee80211_hw
*hw
,
3587 struct ieee80211_if_init_conf
*conf
)
3589 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
3590 struct b43_wldev
*dev
;
3591 unsigned long flags
;
3592 int err
= -EOPNOTSUPP
;
3594 /* TODO: allow WDS/AP devices to coexist */
3596 if (conf
->type
!= IEEE80211_IF_TYPE_AP
&&
3597 conf
->type
!= IEEE80211_IF_TYPE_STA
&&
3598 conf
->type
!= IEEE80211_IF_TYPE_WDS
&&
3599 conf
->type
!= IEEE80211_IF_TYPE_IBSS
)
3602 mutex_lock(&wl
->mutex
);
3604 goto out_mutex_unlock
;
3606 b43dbg(wl
, "Adding Interface type %d\n", conf
->type
);
3608 dev
= wl
->current_dev
;
3610 wl
->vif
= conf
->vif
;
3611 wl
->if_type
= conf
->type
;
3612 memcpy(wl
->mac_addr
, conf
->mac_addr
, ETH_ALEN
);
3614 spin_lock_irqsave(&wl
->irq_lock
, flags
);
3615 b43_adjust_opmode(dev
);
3616 b43_upload_card_macaddress(dev
);
3617 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
3621 mutex_unlock(&wl
->mutex
);
3626 static void b43_op_remove_interface(struct ieee80211_hw
*hw
,
3627 struct ieee80211_if_init_conf
*conf
)
3629 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
3630 struct b43_wldev
*dev
= wl
->current_dev
;
3631 unsigned long flags
;
3633 b43dbg(wl
, "Removing Interface type %d\n", conf
->type
);
3635 mutex_lock(&wl
->mutex
);
3637 B43_WARN_ON(!wl
->operating
);
3638 B43_WARN_ON(wl
->vif
!= conf
->vif
);
3643 spin_lock_irqsave(&wl
->irq_lock
, flags
);
3644 b43_adjust_opmode(dev
);
3645 memset(wl
->mac_addr
, 0, ETH_ALEN
);
3646 b43_upload_card_macaddress(dev
);
3647 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
3649 mutex_unlock(&wl
->mutex
);
3652 static int b43_op_start(struct ieee80211_hw
*hw
)
3654 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
3655 struct b43_wldev
*dev
= wl
->current_dev
;
3658 bool do_rfkill_exit
= 0;
3660 /* Kill all old instance specific information to make sure
3661 * the card won't use it in the short timeframe between start
3662 * and mac80211 reconfiguring it. */
3663 memset(wl
->bssid
, 0, ETH_ALEN
);
3664 memset(wl
->mac_addr
, 0, ETH_ALEN
);
3665 wl
->filter_flags
= 0;
3666 wl
->radiotap_enabled
= 0;
3668 /* First register RFkill.
3669 * LEDs that are registered later depend on it. */
3670 b43_rfkill_init(dev
);
3672 mutex_lock(&wl
->mutex
);
3674 if (b43_status(dev
) < B43_STAT_INITIALIZED
) {
3675 err
= b43_wireless_core_init(dev
);
3678 goto out_mutex_unlock
;
3683 if (b43_status(dev
) < B43_STAT_STARTED
) {
3684 err
= b43_wireless_core_start(dev
);
3687 b43_wireless_core_exit(dev
);
3689 goto out_mutex_unlock
;
3694 mutex_unlock(&wl
->mutex
);
3697 b43_rfkill_exit(dev
);
3702 static void b43_op_stop(struct ieee80211_hw
*hw
)
3704 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
3705 struct b43_wldev
*dev
= wl
->current_dev
;
3707 b43_rfkill_exit(dev
);
3709 mutex_lock(&wl
->mutex
);
3710 if (b43_status(dev
) >= B43_STAT_STARTED
)
3711 b43_wireless_core_stop(dev
);
3712 b43_wireless_core_exit(dev
);
3713 mutex_unlock(&wl
->mutex
);
3716 static int b43_op_set_retry_limit(struct ieee80211_hw
*hw
,
3717 u32 short_retry_limit
, u32 long_retry_limit
)
3719 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
3720 struct b43_wldev
*dev
;
3723 mutex_lock(&wl
->mutex
);
3724 dev
= wl
->current_dev
;
3725 if (unlikely(!dev
|| (b43_status(dev
) < B43_STAT_INITIALIZED
))) {
3729 b43_set_retry_limits(dev
, short_retry_limit
, long_retry_limit
);
3731 mutex_unlock(&wl
->mutex
);
3736 static int b43_op_beacon_set_tim(struct ieee80211_hw
*hw
, int aid
, int set
)
3738 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
3739 struct sk_buff
*beacon
;
3740 unsigned long flags
;
3742 /* We could modify the existing beacon and set the aid bit in
3743 * the TIM field, but that would probably require resizing and
3744 * moving of data within the beacon template.
3745 * Simply request a new beacon and let mac80211 do the hard work. */
3746 beacon
= ieee80211_beacon_get(hw
, wl
->vif
, NULL
);
3747 if (unlikely(!beacon
))
3749 spin_lock_irqsave(&wl
->irq_lock
, flags
);
3750 b43_update_templates(wl
, beacon
);
3751 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
3756 static int b43_op_ibss_beacon_update(struct ieee80211_hw
*hw
,
3757 struct sk_buff
*beacon
,
3758 struct ieee80211_tx_control
*ctl
)
3760 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
3761 unsigned long flags
;
3763 spin_lock_irqsave(&wl
->irq_lock
, flags
);
3764 b43_update_templates(wl
, beacon
);
3765 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
3770 static const struct ieee80211_ops b43_hw_ops
= {
3772 .conf_tx
= b43_op_conf_tx
,
3773 .add_interface
= b43_op_add_interface
,
3774 .remove_interface
= b43_op_remove_interface
,
3775 .config
= b43_op_config
,
3776 .config_interface
= b43_op_config_interface
,
3777 .configure_filter
= b43_op_configure_filter
,
3778 .set_key
= b43_op_set_key
,
3779 .get_stats
= b43_op_get_stats
,
3780 .get_tx_stats
= b43_op_get_tx_stats
,
3781 .start
= b43_op_start
,
3782 .stop
= b43_op_stop
,
3783 .set_retry_limit
= b43_op_set_retry_limit
,
3784 .set_tim
= b43_op_beacon_set_tim
,
3785 .beacon_update
= b43_op_ibss_beacon_update
,
3788 /* Hard-reset the chip. Do not call this directly.
3789 * Use b43_controller_restart()
3791 static void b43_chip_reset(struct work_struct
*work
)
3793 struct b43_wldev
*dev
=
3794 container_of(work
, struct b43_wldev
, restart_work
);
3795 struct b43_wl
*wl
= dev
->wl
;
3799 mutex_lock(&wl
->mutex
);
3801 prev_status
= b43_status(dev
);
3802 /* Bring the device down... */
3803 if (prev_status
>= B43_STAT_STARTED
)
3804 b43_wireless_core_stop(dev
);
3805 if (prev_status
>= B43_STAT_INITIALIZED
)
3806 b43_wireless_core_exit(dev
);
3808 /* ...and up again. */
3809 if (prev_status
>= B43_STAT_INITIALIZED
) {
3810 err
= b43_wireless_core_init(dev
);
3814 if (prev_status
>= B43_STAT_STARTED
) {
3815 err
= b43_wireless_core_start(dev
);
3817 b43_wireless_core_exit(dev
);
3822 mutex_unlock(&wl
->mutex
);
3824 b43err(wl
, "Controller restart FAILED\n");
3826 b43info(wl
, "Controller restarted\n");
3829 static int b43_setup_modes(struct b43_wldev
*dev
,
3830 bool have_2ghz_phy
, bool have_5ghz_phy
)
3832 struct ieee80211_hw
*hw
= dev
->wl
->hw
;
3833 struct ieee80211_hw_mode
*mode
;
3834 struct b43_phy
*phy
= &dev
->phy
;
3837 /* XXX: This function will go away soon, when mac80211
3838 * band stuff is rewritten. So this is just a hack.
3839 * For now we always claim GPHY mode, as there is no
3840 * support for NPHY and APHY in the device, yet.
3841 * This assumption is OK, as any B, N or A PHY will already
3842 * have died a horrible sanity check death earlier. */
3844 mode
= &phy
->hwmodes
[0];
3845 mode
->mode
= MODE_IEEE80211G
;
3846 mode
->num_channels
= b43_2ghz_chantable_size
;
3847 mode
->channels
= b43_2ghz_chantable
;
3848 mode
->num_rates
= b43_g_ratetable_size
;
3849 mode
->rates
= b43_g_ratetable
;
3850 err
= ieee80211_register_hwmode(hw
, mode
);
3853 phy
->possible_phymodes
|= B43_PHYMODE_G
;
3858 static void b43_wireless_core_detach(struct b43_wldev
*dev
)
3860 /* We release firmware that late to not be required to re-request
3861 * is all the time when we reinit the core. */
3862 b43_release_firmware(dev
);
3865 static int b43_wireless_core_attach(struct b43_wldev
*dev
)
3867 struct b43_wl
*wl
= dev
->wl
;
3868 struct ssb_bus
*bus
= dev
->dev
->bus
;
3869 struct pci_dev
*pdev
= bus
->host_pci
;
3871 bool have_2ghz_phy
= 0, have_5ghz_phy
= 0;
3874 /* Do NOT do any device initialization here.
3875 * Do it in wireless_core_init() instead.
3876 * This function is for gathering basic information about the HW, only.
3877 * Also some structs may be set up here. But most likely you want to have
3878 * that in core_init(), too.
3881 err
= ssb_bus_powerup(bus
, 0);
3883 b43err(wl
, "Bus powerup failed\n");
3886 /* Get the PHY type. */
3887 if (dev
->dev
->id
.revision
>= 5) {
3890 tmshigh
= ssb_read32(dev
->dev
, SSB_TMSHIGH
);
3891 have_2ghz_phy
= !!(tmshigh
& B43_TMSHIGH_HAVE_2GHZ_PHY
);
3892 have_5ghz_phy
= !!(tmshigh
& B43_TMSHIGH_HAVE_5GHZ_PHY
);
3896 dev
->phy
.gmode
= have_2ghz_phy
;
3897 tmp
= dev
->phy
.gmode
? B43_TMSLOW_GMODE
: 0;
3898 b43_wireless_core_reset(dev
, tmp
);
3900 err
= b43_phy_versioning(dev
);
3903 /* Check if this device supports multiband. */
3905 (pdev
->device
!= 0x4312 &&
3906 pdev
->device
!= 0x4319 && pdev
->device
!= 0x4324)) {
3907 /* No multiband support. */
3910 switch (dev
->phy
.type
) {
3922 if (dev
->phy
.type
== B43_PHYTYPE_A
) {
3924 b43err(wl
, "IEEE 802.11a devices are unsupported\n");
3928 if (1 /* disable A-PHY */) {
3929 /* FIXME: For now we disable the A-PHY on multi-PHY devices. */
3930 if (dev
->phy
.type
!= B43_PHYTYPE_N
) {
3936 dev
->phy
.gmode
= have_2ghz_phy
;
3937 tmp
= dev
->phy
.gmode
? B43_TMSLOW_GMODE
: 0;
3938 b43_wireless_core_reset(dev
, tmp
);
3940 err
= b43_validate_chipaccess(dev
);
3943 err
= b43_setup_modes(dev
, have_2ghz_phy
, have_5ghz_phy
);
3947 /* Now set some default "current_dev" */
3948 if (!wl
->current_dev
)
3949 wl
->current_dev
= dev
;
3950 INIT_WORK(&dev
->restart_work
, b43_chip_reset
);
3952 b43_radio_turn_off(dev
, 1);
3953 b43_switch_analog(dev
, 0);
3954 ssb_device_disable(dev
->dev
, 0);
3955 ssb_bus_may_powerdown(bus
);
3961 ssb_bus_may_powerdown(bus
);
3965 static void b43_one_core_detach(struct ssb_device
*dev
)
3967 struct b43_wldev
*wldev
;
3970 wldev
= ssb_get_drvdata(dev
);
3972 cancel_work_sync(&wldev
->restart_work
);
3973 b43_debugfs_remove_device(wldev
);
3974 b43_wireless_core_detach(wldev
);
3975 list_del(&wldev
->list
);
3977 ssb_set_drvdata(dev
, NULL
);
3981 static int b43_one_core_attach(struct ssb_device
*dev
, struct b43_wl
*wl
)
3983 struct b43_wldev
*wldev
;
3984 struct pci_dev
*pdev
;
3987 if (!list_empty(&wl
->devlist
)) {
3988 /* We are not the first core on this chip. */
3989 pdev
= dev
->bus
->host_pci
;
3990 /* Only special chips support more than one wireless
3991 * core, although some of the other chips have more than
3992 * one wireless core as well. Check for this and
3996 ((pdev
->device
!= 0x4321) &&
3997 (pdev
->device
!= 0x4313) && (pdev
->device
!= 0x431A))) {
3998 b43dbg(wl
, "Ignoring unconnected 802.11 core\n");
4003 wldev
= kzalloc(sizeof(*wldev
), GFP_KERNEL
);
4009 b43_set_status(wldev
, B43_STAT_UNINIT
);
4010 wldev
->bad_frames_preempt
= modparam_bad_frames_preempt
;
4011 tasklet_init(&wldev
->isr_tasklet
,
4012 (void (*)(unsigned long))b43_interrupt_tasklet
,
4013 (unsigned long)wldev
);
4014 INIT_LIST_HEAD(&wldev
->list
);
4016 err
= b43_wireless_core_attach(wldev
);
4018 goto err_kfree_wldev
;
4020 list_add(&wldev
->list
, &wl
->devlist
);
4022 ssb_set_drvdata(dev
, wldev
);
4023 b43_debugfs_add_device(wldev
);
4033 #define IS_PDEV(pdev, _vendor, _device, _subvendor, _subdevice) ( \
4034 (pdev->vendor == PCI_VENDOR_ID_##_vendor) && \
4035 (pdev->device == _device) && \
4036 (pdev->subsystem_vendor == PCI_VENDOR_ID_##_subvendor) && \
4037 (pdev->subsystem_device == _subdevice) )
4039 static void b43_sprom_fixup(struct ssb_bus
*bus
)
4041 struct pci_dev
*pdev
;
4043 /* boardflags workarounds */
4044 if (bus
->boardinfo
.vendor
== SSB_BOARDVENDOR_DELL
&&
4045 bus
->chip_id
== 0x4301 && bus
->boardinfo
.rev
== 0x74)
4046 bus
->sprom
.boardflags_lo
|= B43_BFL_BTCOEXIST
;
4047 if (bus
->boardinfo
.vendor
== PCI_VENDOR_ID_APPLE
&&
4048 bus
->boardinfo
.type
== 0x4E && bus
->boardinfo
.rev
> 0x40)
4049 bus
->sprom
.boardflags_lo
|= B43_BFL_PACTRL
;
4050 if (bus
->bustype
== SSB_BUSTYPE_PCI
) {
4051 pdev
= bus
->host_pci
;
4052 if (IS_PDEV(pdev
, BROADCOM
, 0x4318, ASUSTEK
, 0x100F) ||
4053 IS_PDEV(pdev
, BROADCOM
, 0x4320, LINKSYS
, 0x0015) ||
4054 IS_PDEV(pdev
, BROADCOM
, 0x4320, LINKSYS
, 0x0013))
4055 bus
->sprom
.boardflags_lo
&= ~B43_BFL_BTCOEXIST
;
4059 static void b43_wireless_exit(struct ssb_device
*dev
, struct b43_wl
*wl
)
4061 struct ieee80211_hw
*hw
= wl
->hw
;
4063 ssb_set_devtypedata(dev
, NULL
);
4064 ieee80211_free_hw(hw
);
4067 static int b43_wireless_init(struct ssb_device
*dev
)
4069 struct ssb_sprom
*sprom
= &dev
->bus
->sprom
;
4070 struct ieee80211_hw
*hw
;
4074 b43_sprom_fixup(dev
->bus
);
4076 hw
= ieee80211_alloc_hw(sizeof(*wl
), &b43_hw_ops
);
4078 b43err(NULL
, "Could not allocate ieee80211 device\n");
4083 hw
->flags
= IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE
|
4084 IEEE80211_HW_RX_INCLUDES_FCS
;
4085 hw
->max_signal
= 100;
4086 hw
->max_rssi
= -110;
4087 hw
->max_noise
= -110;
4088 hw
->queues
= 1; /* FIXME: hardware has more queues */
4089 SET_IEEE80211_DEV(hw
, dev
->dev
);
4090 if (is_valid_ether_addr(sprom
->et1mac
))
4091 SET_IEEE80211_PERM_ADDR(hw
, sprom
->et1mac
);
4093 SET_IEEE80211_PERM_ADDR(hw
, sprom
->il0mac
);
4095 /* Get and initialize struct b43_wl */
4096 wl
= hw_to_b43_wl(hw
);
4097 memset(wl
, 0, sizeof(*wl
));
4099 spin_lock_init(&wl
->irq_lock
);
4100 rwlock_init(&wl
->tx_lock
);
4101 spin_lock_init(&wl
->leds_lock
);
4102 spin_lock_init(&wl
->shm_lock
);
4103 mutex_init(&wl
->mutex
);
4104 INIT_LIST_HEAD(&wl
->devlist
);
4106 ssb_set_devtypedata(dev
, wl
);
4107 b43info(wl
, "Broadcom %04X WLAN found\n", dev
->bus
->chip_id
);
4113 static int b43_probe(struct ssb_device
*dev
, const struct ssb_device_id
*id
)
4119 wl
= ssb_get_devtypedata(dev
);
4121 /* Probing the first core. Must setup common struct b43_wl */
4123 err
= b43_wireless_init(dev
);
4126 wl
= ssb_get_devtypedata(dev
);
4129 err
= b43_one_core_attach(dev
, wl
);
4131 goto err_wireless_exit
;
4134 err
= ieee80211_register_hw(wl
->hw
);
4136 goto err_one_core_detach
;
4142 err_one_core_detach
:
4143 b43_one_core_detach(dev
);
4146 b43_wireless_exit(dev
, wl
);
4150 static void b43_remove(struct ssb_device
*dev
)
4152 struct b43_wl
*wl
= ssb_get_devtypedata(dev
);
4153 struct b43_wldev
*wldev
= ssb_get_drvdata(dev
);
4156 if (wl
->current_dev
== wldev
)
4157 ieee80211_unregister_hw(wl
->hw
);
4159 b43_one_core_detach(dev
);
4161 if (list_empty(&wl
->devlist
)) {
4162 /* Last core on the chip unregistered.
4163 * We can destroy common struct b43_wl.
4165 b43_wireless_exit(dev
, wl
);
4169 /* Perform a hardware reset. This can be called from any context. */
4170 void b43_controller_restart(struct b43_wldev
*dev
, const char *reason
)
4172 /* Must avoid requeueing, if we are in shutdown. */
4173 if (b43_status(dev
) < B43_STAT_INITIALIZED
)
4175 b43info(dev
->wl
, "Controller RESET (%s) ...\n", reason
);
4176 queue_work(dev
->wl
->hw
->workqueue
, &dev
->restart_work
);
4181 static int b43_suspend(struct ssb_device
*dev
, pm_message_t state
)
4183 struct b43_wldev
*wldev
= ssb_get_drvdata(dev
);
4184 struct b43_wl
*wl
= wldev
->wl
;
4186 b43dbg(wl
, "Suspending...\n");
4188 mutex_lock(&wl
->mutex
);
4189 wldev
->suspend_in_progress
= true;
4190 wldev
->suspend_init_status
= b43_status(wldev
);
4191 if (wldev
->suspend_init_status
>= B43_STAT_STARTED
)
4192 b43_wireless_core_stop(wldev
);
4193 if (wldev
->suspend_init_status
>= B43_STAT_INITIALIZED
)
4194 b43_wireless_core_exit(wldev
);
4195 mutex_unlock(&wl
->mutex
);
4197 b43dbg(wl
, "Device suspended.\n");
4202 static int b43_resume(struct ssb_device
*dev
)
4204 struct b43_wldev
*wldev
= ssb_get_drvdata(dev
);
4205 struct b43_wl
*wl
= wldev
->wl
;
4208 b43dbg(wl
, "Resuming...\n");
4210 mutex_lock(&wl
->mutex
);
4211 if (wldev
->suspend_init_status
>= B43_STAT_INITIALIZED
) {
4212 err
= b43_wireless_core_init(wldev
);
4214 b43err(wl
, "Resume failed at core init\n");
4218 if (wldev
->suspend_init_status
>= B43_STAT_STARTED
) {
4219 err
= b43_wireless_core_start(wldev
);
4221 b43_leds_exit(wldev
);
4222 b43_rng_exit(wldev
->wl
, true);
4223 b43_wireless_core_exit(wldev
);
4224 b43err(wl
, "Resume failed at core start\n");
4228 b43dbg(wl
, "Device resumed.\n");
4230 wldev
->suspend_in_progress
= false;
4231 mutex_unlock(&wl
->mutex
);
4235 #else /* CONFIG_PM */
4236 # define b43_suspend NULL
4237 # define b43_resume NULL
4238 #endif /* CONFIG_PM */
4240 static struct ssb_driver b43_ssb_driver
= {
4241 .name
= KBUILD_MODNAME
,
4242 .id_table
= b43_ssb_tbl
,
4244 .remove
= b43_remove
,
4245 .suspend
= b43_suspend
,
4246 .resume
= b43_resume
,
4249 static void b43_print_driverinfo(void)
4251 const char *feat_pci
= "", *feat_pcmcia
= "", *feat_nphy
= "",
4252 *feat_leds
= "", *feat_rfkill
= "";
4254 #ifdef CONFIG_B43_PCI_AUTOSELECT
4257 #ifdef CONFIG_B43_PCMCIA
4260 #ifdef CONFIG_B43_NPHY
4263 #ifdef CONFIG_B43_LEDS
4266 #ifdef CONFIG_B43_RFKILL
4269 printk(KERN_INFO
"Broadcom 43xx driver loaded "
4270 "[ Features: %s%s%s%s%s, Firmware-ID: "
4271 B43_SUPPORTED_FIRMWARE_ID
" ]\n",
4272 feat_pci
, feat_pcmcia
, feat_nphy
,
4273 feat_leds
, feat_rfkill
);
4276 static int __init
b43_init(void)
4281 err
= b43_pcmcia_init();
4284 err
= ssb_driver_register(&b43_ssb_driver
);
4286 goto err_pcmcia_exit
;
4287 b43_print_driverinfo();
4298 static void __exit
b43_exit(void)
4300 ssb_driver_unregister(&b43_ssb_driver
);
4305 module_init(b43_init
)
4306 module_exit(b43_exit
)