3 * Broadcom B43legacy wireless driver
5 * Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>
6 * Copyright (c) 2005-2008 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>
10 * Copyright (c) 2007 Larry Finger <Larry.Finger@lwfinger.net>
12 * Some parts of the code in this file are derived from the ipw2200
13 * driver Copyright(c) 2003 - 2004 Intel Corporation.
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; see the file COPYING. If not, write to
27 * the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
28 * Boston, MA 02110-1301, USA.
32 #include <linux/delay.h>
33 #include <linux/init.h>
34 #include <linux/moduleparam.h>
35 #include <linux/if_arp.h>
36 #include <linux/etherdevice.h>
37 #include <linux/version.h>
38 #include <linux/firmware.h>
39 #include <linux/wireless.h>
40 #include <linux/workqueue.h>
41 #include <linux/skbuff.h>
42 #include <linux/dma-mapping.h>
44 #include <asm/unaligned.h>
46 #include "b43legacy.h"
57 MODULE_DESCRIPTION("Broadcom B43legacy wireless driver");
58 MODULE_AUTHOR("Martin Langer");
59 MODULE_AUTHOR("Stefano Brivio");
60 MODULE_AUTHOR("Michael Buesch");
61 MODULE_LICENSE("GPL");
63 MODULE_FIRMWARE(B43legacy_SUPPORTED_FIRMWARE_ID
);
65 #if defined(CONFIG_B43LEGACY_DMA) && defined(CONFIG_B43LEGACY_PIO)
66 static int modparam_pio
;
67 module_param_named(pio
, modparam_pio
, int, 0444);
68 MODULE_PARM_DESC(pio
, "enable(1) / disable(0) PIO mode");
69 #elif defined(CONFIG_B43LEGACY_DMA)
70 # define modparam_pio 0
71 #elif defined(CONFIG_B43LEGACY_PIO)
72 # define modparam_pio 1
75 static int modparam_bad_frames_preempt
;
76 module_param_named(bad_frames_preempt
, modparam_bad_frames_preempt
, int, 0444);
77 MODULE_PARM_DESC(bad_frames_preempt
, "enable(1) / disable(0) Bad Frames"
80 static char modparam_fwpostfix
[16];
81 module_param_string(fwpostfix
, modparam_fwpostfix
, 16, 0444);
82 MODULE_PARM_DESC(fwpostfix
, "Postfix for the firmware files to load.");
84 /* The following table supports BCM4301, BCM4303 and BCM4306/2 devices. */
85 static const struct ssb_device_id b43legacy_ssb_tbl
[] = {
86 SSB_DEVICE(SSB_VENDOR_BROADCOM
, SSB_DEV_80211
, 2),
87 SSB_DEVICE(SSB_VENDOR_BROADCOM
, SSB_DEV_80211
, 4),
90 MODULE_DEVICE_TABLE(ssb
, b43legacy_ssb_tbl
);
93 /* Channel and ratetables are shared for all devices.
94 * They can't be const, because ieee80211 puts some precalculated
95 * data in there. This data is the same for all devices, so we don't
96 * get concurrency issues */
97 #define RATETAB_ENT(_rateid, _flags) \
99 .rate = B43legacy_RATE_TO_100KBPS(_rateid), \
104 static struct ieee80211_rate __b43legacy_ratetable
[] = {
105 RATETAB_ENT(B43legacy_CCK_RATE_1MB
, IEEE80211_RATE_CCK
),
106 RATETAB_ENT(B43legacy_CCK_RATE_2MB
, IEEE80211_RATE_CCK_2
),
107 RATETAB_ENT(B43legacy_CCK_RATE_5MB
, IEEE80211_RATE_CCK_2
),
108 RATETAB_ENT(B43legacy_CCK_RATE_11MB
, IEEE80211_RATE_CCK_2
),
109 RATETAB_ENT(B43legacy_OFDM_RATE_6MB
, IEEE80211_RATE_OFDM
),
110 RATETAB_ENT(B43legacy_OFDM_RATE_9MB
, IEEE80211_RATE_OFDM
),
111 RATETAB_ENT(B43legacy_OFDM_RATE_12MB
, IEEE80211_RATE_OFDM
),
112 RATETAB_ENT(B43legacy_OFDM_RATE_18MB
, IEEE80211_RATE_OFDM
),
113 RATETAB_ENT(B43legacy_OFDM_RATE_24MB
, IEEE80211_RATE_OFDM
),
114 RATETAB_ENT(B43legacy_OFDM_RATE_36MB
, IEEE80211_RATE_OFDM
),
115 RATETAB_ENT(B43legacy_OFDM_RATE_48MB
, IEEE80211_RATE_OFDM
),
116 RATETAB_ENT(B43legacy_OFDM_RATE_54MB
, IEEE80211_RATE_OFDM
),
118 #define b43legacy_a_ratetable (__b43legacy_ratetable + 4)
119 #define b43legacy_a_ratetable_size 8
120 #define b43legacy_b_ratetable (__b43legacy_ratetable + 0)
121 #define b43legacy_b_ratetable_size 4
122 #define b43legacy_g_ratetable (__b43legacy_ratetable + 0)
123 #define b43legacy_g_ratetable_size 12
125 #define CHANTAB_ENT(_chanid, _freq) \
130 .flag = IEEE80211_CHAN_W_SCAN | \
131 IEEE80211_CHAN_W_ACTIVE_SCAN | \
132 IEEE80211_CHAN_W_IBSS, \
133 .power_level = 0x0A, \
134 .antenna_max = 0xFF, \
136 static struct ieee80211_channel b43legacy_bg_chantable
[] = {
137 CHANTAB_ENT(1, 2412),
138 CHANTAB_ENT(2, 2417),
139 CHANTAB_ENT(3, 2422),
140 CHANTAB_ENT(4, 2427),
141 CHANTAB_ENT(5, 2432),
142 CHANTAB_ENT(6, 2437),
143 CHANTAB_ENT(7, 2442),
144 CHANTAB_ENT(8, 2447),
145 CHANTAB_ENT(9, 2452),
146 CHANTAB_ENT(10, 2457),
147 CHANTAB_ENT(11, 2462),
148 CHANTAB_ENT(12, 2467),
149 CHANTAB_ENT(13, 2472),
150 CHANTAB_ENT(14, 2484),
152 #define b43legacy_bg_chantable_size ARRAY_SIZE(b43legacy_bg_chantable)
154 static void b43legacy_wireless_core_exit(struct b43legacy_wldev
*dev
);
155 static int b43legacy_wireless_core_init(struct b43legacy_wldev
*dev
);
156 static void b43legacy_wireless_core_stop(struct b43legacy_wldev
*dev
);
157 static int b43legacy_wireless_core_start(struct b43legacy_wldev
*dev
);
160 static int b43legacy_ratelimit(struct b43legacy_wl
*wl
)
162 if (!wl
|| !wl
->current_dev
)
164 if (b43legacy_status(wl
->current_dev
) < B43legacy_STAT_STARTED
)
166 /* We are up and running.
167 * Ratelimit the messages to avoid DoS over the net. */
168 return net_ratelimit();
171 void b43legacyinfo(struct b43legacy_wl
*wl
, const char *fmt
, ...)
175 if (!b43legacy_ratelimit(wl
))
178 printk(KERN_INFO
"b43legacy-%s: ",
179 (wl
&& wl
->hw
) ? wiphy_name(wl
->hw
->wiphy
) : "wlan");
184 void b43legacyerr(struct b43legacy_wl
*wl
, const char *fmt
, ...)
188 if (!b43legacy_ratelimit(wl
))
191 printk(KERN_ERR
"b43legacy-%s ERROR: ",
192 (wl
&& wl
->hw
) ? wiphy_name(wl
->hw
->wiphy
) : "wlan");
197 void b43legacywarn(struct b43legacy_wl
*wl
, const char *fmt
, ...)
201 if (!b43legacy_ratelimit(wl
))
204 printk(KERN_WARNING
"b43legacy-%s warning: ",
205 (wl
&& wl
->hw
) ? wiphy_name(wl
->hw
->wiphy
) : "wlan");
211 void b43legacydbg(struct b43legacy_wl
*wl
, const char *fmt
, ...)
216 printk(KERN_DEBUG
"b43legacy-%s debug: ",
217 (wl
&& wl
->hw
) ? wiphy_name(wl
->hw
->wiphy
) : "wlan");
223 static void b43legacy_ram_write(struct b43legacy_wldev
*dev
, u16 offset
,
228 B43legacy_WARN_ON(offset
% 4 != 0);
230 status
= b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
231 if (status
& B43legacy_MACCTL_BE
)
234 b43legacy_write32(dev
, B43legacy_MMIO_RAM_CONTROL
, offset
);
236 b43legacy_write32(dev
, B43legacy_MMIO_RAM_DATA
, val
);
240 void b43legacy_shm_control_word(struct b43legacy_wldev
*dev
,
241 u16 routing
, u16 offset
)
245 /* "offset" is the WORD offset. */
250 b43legacy_write32(dev
, B43legacy_MMIO_SHM_CONTROL
, control
);
253 u32
b43legacy_shm_read32(struct b43legacy_wldev
*dev
,
254 u16 routing
, u16 offset
)
258 if (routing
== B43legacy_SHM_SHARED
) {
259 B43legacy_WARN_ON((offset
& 0x0001) != 0);
260 if (offset
& 0x0003) {
261 /* Unaligned access */
262 b43legacy_shm_control_word(dev
, routing
, offset
>> 2);
263 ret
= b43legacy_read16(dev
,
264 B43legacy_MMIO_SHM_DATA_UNALIGNED
);
266 b43legacy_shm_control_word(dev
, routing
,
268 ret
|= b43legacy_read16(dev
, B43legacy_MMIO_SHM_DATA
);
274 b43legacy_shm_control_word(dev
, routing
, offset
);
275 ret
= b43legacy_read32(dev
, B43legacy_MMIO_SHM_DATA
);
280 u16
b43legacy_shm_read16(struct b43legacy_wldev
*dev
,
281 u16 routing
, u16 offset
)
285 if (routing
== B43legacy_SHM_SHARED
) {
286 B43legacy_WARN_ON((offset
& 0x0001) != 0);
287 if (offset
& 0x0003) {
288 /* Unaligned access */
289 b43legacy_shm_control_word(dev
, routing
, offset
>> 2);
290 ret
= b43legacy_read16(dev
,
291 B43legacy_MMIO_SHM_DATA_UNALIGNED
);
297 b43legacy_shm_control_word(dev
, routing
, offset
);
298 ret
= b43legacy_read16(dev
, B43legacy_MMIO_SHM_DATA
);
303 void b43legacy_shm_write32(struct b43legacy_wldev
*dev
,
304 u16 routing
, u16 offset
,
307 if (routing
== B43legacy_SHM_SHARED
) {
308 B43legacy_WARN_ON((offset
& 0x0001) != 0);
309 if (offset
& 0x0003) {
310 /* Unaligned access */
311 b43legacy_shm_control_word(dev
, routing
, offset
>> 2);
313 b43legacy_write16(dev
,
314 B43legacy_MMIO_SHM_DATA_UNALIGNED
,
315 (value
>> 16) & 0xffff);
317 b43legacy_shm_control_word(dev
, routing
,
320 b43legacy_write16(dev
, B43legacy_MMIO_SHM_DATA
,
326 b43legacy_shm_control_word(dev
, routing
, offset
);
328 b43legacy_write32(dev
, B43legacy_MMIO_SHM_DATA
, value
);
331 void b43legacy_shm_write16(struct b43legacy_wldev
*dev
, u16 routing
, u16 offset
,
334 if (routing
== B43legacy_SHM_SHARED
) {
335 B43legacy_WARN_ON((offset
& 0x0001) != 0);
336 if (offset
& 0x0003) {
337 /* Unaligned access */
338 b43legacy_shm_control_word(dev
, routing
, offset
>> 2);
340 b43legacy_write16(dev
,
341 B43legacy_MMIO_SHM_DATA_UNALIGNED
,
347 b43legacy_shm_control_word(dev
, routing
, offset
);
349 b43legacy_write16(dev
, B43legacy_MMIO_SHM_DATA
, value
);
353 u32
b43legacy_hf_read(struct b43legacy_wldev
*dev
)
357 ret
= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
,
358 B43legacy_SHM_SH_HOSTFHI
);
360 ret
|= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
,
361 B43legacy_SHM_SH_HOSTFLO
);
366 /* Write HostFlags */
367 void b43legacy_hf_write(struct b43legacy_wldev
*dev
, u32 value
)
369 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
,
370 B43legacy_SHM_SH_HOSTFLO
,
371 (value
& 0x0000FFFF));
372 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
,
373 B43legacy_SHM_SH_HOSTFHI
,
374 ((value
& 0xFFFF0000) >> 16));
377 void b43legacy_tsf_read(struct b43legacy_wldev
*dev
, u64
*tsf
)
379 /* We need to be careful. As we read the TSF from multiple
380 * registers, we should take care of register overflows.
381 * In theory, the whole tsf read process should be atomic.
382 * We try to be atomic here, by restaring the read process,
383 * if any of the high registers changed (overflew).
385 if (dev
->dev
->id
.revision
>= 3) {
391 high
= b43legacy_read32(dev
,
392 B43legacy_MMIO_REV3PLUS_TSF_HIGH
);
393 low
= b43legacy_read32(dev
,
394 B43legacy_MMIO_REV3PLUS_TSF_LOW
);
395 high2
= b43legacy_read32(dev
,
396 B43legacy_MMIO_REV3PLUS_TSF_HIGH
);
397 } while (unlikely(high
!= high2
));
413 v3
= b43legacy_read16(dev
, B43legacy_MMIO_TSF_3
);
414 v2
= b43legacy_read16(dev
, B43legacy_MMIO_TSF_2
);
415 v1
= b43legacy_read16(dev
, B43legacy_MMIO_TSF_1
);
416 v0
= b43legacy_read16(dev
, B43legacy_MMIO_TSF_0
);
418 test3
= b43legacy_read16(dev
, B43legacy_MMIO_TSF_3
);
419 test2
= b43legacy_read16(dev
, B43legacy_MMIO_TSF_2
);
420 test1
= b43legacy_read16(dev
, B43legacy_MMIO_TSF_1
);
421 } while (v3
!= test3
|| v2
!= test2
|| v1
!= test1
);
435 static void b43legacy_time_lock(struct b43legacy_wldev
*dev
)
439 status
= b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
440 status
|= B43legacy_MACCTL_TBTTHOLD
;
441 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
, status
);
445 static void b43legacy_time_unlock(struct b43legacy_wldev
*dev
)
449 status
= b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
450 status
&= ~B43legacy_MACCTL_TBTTHOLD
;
451 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
, status
);
454 static void b43legacy_tsf_write_locked(struct b43legacy_wldev
*dev
, u64 tsf
)
456 /* Be careful with the in-progress timer.
457 * First zero out the low register, so we have a full
458 * register-overflow duration to complete the operation.
460 if (dev
->dev
->id
.revision
>= 3) {
461 u32 lo
= (tsf
& 0x00000000FFFFFFFFULL
);
462 u32 hi
= (tsf
& 0xFFFFFFFF00000000ULL
) >> 32;
464 b43legacy_write32(dev
, B43legacy_MMIO_REV3PLUS_TSF_LOW
, 0);
466 b43legacy_write32(dev
, B43legacy_MMIO_REV3PLUS_TSF_HIGH
,
469 b43legacy_write32(dev
, B43legacy_MMIO_REV3PLUS_TSF_LOW
,
472 u16 v0
= (tsf
& 0x000000000000FFFFULL
);
473 u16 v1
= (tsf
& 0x00000000FFFF0000ULL
) >> 16;
474 u16 v2
= (tsf
& 0x0000FFFF00000000ULL
) >> 32;
475 u16 v3
= (tsf
& 0xFFFF000000000000ULL
) >> 48;
477 b43legacy_write16(dev
, B43legacy_MMIO_TSF_0
, 0);
479 b43legacy_write16(dev
, B43legacy_MMIO_TSF_3
, v3
);
481 b43legacy_write16(dev
, B43legacy_MMIO_TSF_2
, v2
);
483 b43legacy_write16(dev
, B43legacy_MMIO_TSF_1
, v1
);
485 b43legacy_write16(dev
, B43legacy_MMIO_TSF_0
, v0
);
489 void b43legacy_tsf_write(struct b43legacy_wldev
*dev
, u64 tsf
)
491 b43legacy_time_lock(dev
);
492 b43legacy_tsf_write_locked(dev
, tsf
);
493 b43legacy_time_unlock(dev
);
497 void b43legacy_macfilter_set(struct b43legacy_wldev
*dev
,
498 u16 offset
, const u8
*mac
)
500 static const u8 zero_addr
[ETH_ALEN
] = { 0 };
507 b43legacy_write16(dev
, B43legacy_MMIO_MACFILTER_CONTROL
, offset
);
511 b43legacy_write16(dev
, B43legacy_MMIO_MACFILTER_DATA
, data
);
514 b43legacy_write16(dev
, B43legacy_MMIO_MACFILTER_DATA
, data
);
517 b43legacy_write16(dev
, B43legacy_MMIO_MACFILTER_DATA
, data
);
520 static void b43legacy_write_mac_bssid_templates(struct b43legacy_wldev
*dev
)
522 static const u8 zero_addr
[ETH_ALEN
] = { 0 };
523 const u8
*mac
= dev
->wl
->mac_addr
;
524 const u8
*bssid
= dev
->wl
->bssid
;
525 u8 mac_bssid
[ETH_ALEN
* 2];
534 b43legacy_macfilter_set(dev
, B43legacy_MACFILTER_BSSID
, bssid
);
536 memcpy(mac_bssid
, mac
, ETH_ALEN
);
537 memcpy(mac_bssid
+ ETH_ALEN
, bssid
, ETH_ALEN
);
539 /* Write our MAC address and BSSID to template ram */
540 for (i
= 0; i
< ARRAY_SIZE(mac_bssid
); i
+= sizeof(u32
)) {
541 tmp
= (u32
)(mac_bssid
[i
+ 0]);
542 tmp
|= (u32
)(mac_bssid
[i
+ 1]) << 8;
543 tmp
|= (u32
)(mac_bssid
[i
+ 2]) << 16;
544 tmp
|= (u32
)(mac_bssid
[i
+ 3]) << 24;
545 b43legacy_ram_write(dev
, 0x20 + i
, tmp
);
546 b43legacy_ram_write(dev
, 0x78 + i
, tmp
);
547 b43legacy_ram_write(dev
, 0x478 + i
, tmp
);
551 static void b43legacy_upload_card_macaddress(struct b43legacy_wldev
*dev
)
553 b43legacy_write_mac_bssid_templates(dev
);
554 b43legacy_macfilter_set(dev
, B43legacy_MACFILTER_SELF
,
558 static void b43legacy_set_slot_time(struct b43legacy_wldev
*dev
,
561 /* slot_time is in usec. */
562 if (dev
->phy
.type
!= B43legacy_PHYTYPE_G
)
564 b43legacy_write16(dev
, 0x684, 510 + slot_time
);
565 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
, 0x0010,
569 static void b43legacy_short_slot_timing_enable(struct b43legacy_wldev
*dev
)
571 b43legacy_set_slot_time(dev
, 9);
575 static void b43legacy_short_slot_timing_disable(struct b43legacy_wldev
*dev
)
577 b43legacy_set_slot_time(dev
, 20);
581 /* Enable a Generic IRQ. "mask" is the mask of which IRQs to enable.
582 * Returns the _previously_ enabled IRQ mask.
584 static inline u32
b43legacy_interrupt_enable(struct b43legacy_wldev
*dev
,
589 old_mask
= b43legacy_read32(dev
, B43legacy_MMIO_GEN_IRQ_MASK
);
590 b43legacy_write32(dev
, B43legacy_MMIO_GEN_IRQ_MASK
, old_mask
|
596 /* Disable a Generic IRQ. "mask" is the mask of which IRQs to disable.
597 * Returns the _previously_ enabled IRQ mask.
599 static inline u32
b43legacy_interrupt_disable(struct b43legacy_wldev
*dev
,
604 old_mask
= b43legacy_read32(dev
, B43legacy_MMIO_GEN_IRQ_MASK
);
605 b43legacy_write32(dev
, B43legacy_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 b43legacy_synchronize_irq(struct b43legacy_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 b43legacy_dummy_transmission(struct b43legacy_wldev
*dev
)
625 struct b43legacy_phy
*phy
= &dev
->phy
;
627 unsigned int max_loop
;
638 case B43legacy_PHYTYPE_B
:
639 case B43legacy_PHYTYPE_G
:
641 buffer
[0] = 0x000B846E;
648 for (i
= 0; i
< 5; i
++)
649 b43legacy_ram_write(dev
, i
* 4, buffer
[i
]);
651 /* dummy read follows */
652 b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
654 b43legacy_write16(dev
, 0x0568, 0x0000);
655 b43legacy_write16(dev
, 0x07C0, 0x0000);
656 b43legacy_write16(dev
, 0x050C, 0x0000);
657 b43legacy_write16(dev
, 0x0508, 0x0000);
658 b43legacy_write16(dev
, 0x050A, 0x0000);
659 b43legacy_write16(dev
, 0x054C, 0x0000);
660 b43legacy_write16(dev
, 0x056A, 0x0014);
661 b43legacy_write16(dev
, 0x0568, 0x0826);
662 b43legacy_write16(dev
, 0x0500, 0x0000);
663 b43legacy_write16(dev
, 0x0502, 0x0030);
665 if (phy
->radio_ver
== 0x2050 && phy
->radio_rev
<= 0x5)
666 b43legacy_radio_write16(dev
, 0x0051, 0x0017);
667 for (i
= 0x00; i
< max_loop
; i
++) {
668 value
= b43legacy_read16(dev
, 0x050E);
673 for (i
= 0x00; i
< 0x0A; i
++) {
674 value
= b43legacy_read16(dev
, 0x050E);
679 for (i
= 0x00; i
< 0x0A; i
++) {
680 value
= b43legacy_read16(dev
, 0x0690);
681 if (!(value
& 0x0100))
685 if (phy
->radio_ver
== 0x2050 && phy
->radio_rev
<= 0x5)
686 b43legacy_radio_write16(dev
, 0x0051, 0x0037);
689 /* Turn the Analog ON/OFF */
690 static void b43legacy_switch_analog(struct b43legacy_wldev
*dev
, int on
)
692 b43legacy_write16(dev
, B43legacy_MMIO_PHY0
, on
? 0 : 0xF4);
695 void b43legacy_wireless_core_reset(struct b43legacy_wldev
*dev
, u32 flags
)
700 flags
|= B43legacy_TMSLOW_PHYCLKEN
;
701 flags
|= B43legacy_TMSLOW_PHYRESET
;
702 ssb_device_enable(dev
->dev
, flags
);
703 msleep(2); /* Wait for the PLL to turn on. */
705 /* Now take the PHY out of Reset again */
706 tmslow
= ssb_read32(dev
->dev
, SSB_TMSLOW
);
707 tmslow
|= SSB_TMSLOW_FGC
;
708 tmslow
&= ~B43legacy_TMSLOW_PHYRESET
;
709 ssb_write32(dev
->dev
, SSB_TMSLOW
, tmslow
);
710 ssb_read32(dev
->dev
, SSB_TMSLOW
); /* flush */
712 tmslow
&= ~SSB_TMSLOW_FGC
;
713 ssb_write32(dev
->dev
, SSB_TMSLOW
, tmslow
);
714 ssb_read32(dev
->dev
, SSB_TMSLOW
); /* flush */
718 b43legacy_switch_analog(dev
, 1);
720 macctl
= b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
721 macctl
&= ~B43legacy_MACCTL_GMODE
;
722 if (flags
& B43legacy_TMSLOW_GMODE
) {
723 macctl
|= B43legacy_MACCTL_GMODE
;
727 macctl
|= B43legacy_MACCTL_IHR_ENABLED
;
728 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
, macctl
);
731 static void handle_irq_transmit_status(struct b43legacy_wldev
*dev
)
736 struct b43legacy_txstatus stat
;
739 v0
= b43legacy_read32(dev
, B43legacy_MMIO_XMITSTAT_0
);
740 if (!(v0
& 0x00000001))
742 v1
= b43legacy_read32(dev
, B43legacy_MMIO_XMITSTAT_1
);
744 stat
.cookie
= (v0
>> 16);
745 stat
.seq
= (v1
& 0x0000FFFF);
746 stat
.phy_stat
= ((v1
& 0x00FF0000) >> 16);
747 tmp
= (v0
& 0x0000FFFF);
748 stat
.frame_count
= ((tmp
& 0xF000) >> 12);
749 stat
.rts_count
= ((tmp
& 0x0F00) >> 8);
750 stat
.supp_reason
= ((tmp
& 0x001C) >> 2);
751 stat
.pm_indicated
= !!(tmp
& 0x0080);
752 stat
.intermediate
= !!(tmp
& 0x0040);
753 stat
.for_ampdu
= !!(tmp
& 0x0020);
754 stat
.acked
= !!(tmp
& 0x0002);
756 b43legacy_handle_txstatus(dev
, &stat
);
760 static void drain_txstatus_queue(struct b43legacy_wldev
*dev
)
764 if (dev
->dev
->id
.revision
< 5)
766 /* Read all entries from the microcode TXstatus FIFO
767 * and throw them away.
770 dummy
= b43legacy_read32(dev
, B43legacy_MMIO_XMITSTAT_0
);
771 if (!(dummy
& 0x00000001))
773 dummy
= b43legacy_read32(dev
, B43legacy_MMIO_XMITSTAT_1
);
777 static u32
b43legacy_jssi_read(struct b43legacy_wldev
*dev
)
781 val
= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
, 0x40A);
783 val
|= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
, 0x408);
788 static void b43legacy_jssi_write(struct b43legacy_wldev
*dev
, u32 jssi
)
790 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
, 0x408,
791 (jssi
& 0x0000FFFF));
792 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
, 0x40A,
793 (jssi
& 0xFFFF0000) >> 16);
796 static void b43legacy_generate_noise_sample(struct b43legacy_wldev
*dev
)
798 b43legacy_jssi_write(dev
, 0x7F7F7F7F);
799 b43legacy_write32(dev
, B43legacy_MMIO_MACCMD
,
800 b43legacy_read32(dev
,
801 B43legacy_MMIO_MACCMD
)
803 B43legacy_WARN_ON(dev
->noisecalc
.channel_at_start
!=
807 static void b43legacy_calculate_link_quality(struct b43legacy_wldev
*dev
)
809 /* Top half of Link Quality calculation. */
811 if (dev
->noisecalc
.calculation_running
)
813 dev
->noisecalc
.channel_at_start
= dev
->phy
.channel
;
814 dev
->noisecalc
.calculation_running
= 1;
815 dev
->noisecalc
.nr_samples
= 0;
817 b43legacy_generate_noise_sample(dev
);
820 static void handle_irq_noise(struct b43legacy_wldev
*dev
)
822 struct b43legacy_phy
*phy
= &dev
->phy
;
829 /* Bottom half of Link Quality calculation. */
831 B43legacy_WARN_ON(!dev
->noisecalc
.calculation_running
);
832 if (dev
->noisecalc
.channel_at_start
!= phy
->channel
)
833 goto drop_calculation
;
834 *((__le32
*)noise
) = cpu_to_le32(b43legacy_jssi_read(dev
));
835 if (noise
[0] == 0x7F || noise
[1] == 0x7F ||
836 noise
[2] == 0x7F || noise
[3] == 0x7F)
839 /* Get the noise samples. */
840 B43legacy_WARN_ON(dev
->noisecalc
.nr_samples
>= 8);
841 i
= dev
->noisecalc
.nr_samples
;
842 noise
[0] = limit_value(noise
[0], 0, ARRAY_SIZE(phy
->nrssi_lt
) - 1);
843 noise
[1] = limit_value(noise
[1], 0, ARRAY_SIZE(phy
->nrssi_lt
) - 1);
844 noise
[2] = limit_value(noise
[2], 0, ARRAY_SIZE(phy
->nrssi_lt
) - 1);
845 noise
[3] = limit_value(noise
[3], 0, ARRAY_SIZE(phy
->nrssi_lt
) - 1);
846 dev
->noisecalc
.samples
[i
][0] = phy
->nrssi_lt
[noise
[0]];
847 dev
->noisecalc
.samples
[i
][1] = phy
->nrssi_lt
[noise
[1]];
848 dev
->noisecalc
.samples
[i
][2] = phy
->nrssi_lt
[noise
[2]];
849 dev
->noisecalc
.samples
[i
][3] = phy
->nrssi_lt
[noise
[3]];
850 dev
->noisecalc
.nr_samples
++;
851 if (dev
->noisecalc
.nr_samples
== 8) {
852 /* Calculate the Link Quality by the noise samples. */
854 for (i
= 0; i
< 8; i
++) {
855 for (j
= 0; j
< 4; j
++)
856 average
+= dev
->noisecalc
.samples
[i
][j
];
862 tmp
= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
,
864 tmp
= (tmp
/ 128) & 0x1F;
874 dev
->stats
.link_noise
= average
;
876 dev
->noisecalc
.calculation_running
= 0;
880 b43legacy_generate_noise_sample(dev
);
883 static void handle_irq_tbtt_indication(struct b43legacy_wldev
*dev
)
885 if (b43legacy_is_mode(dev
->wl
, IEEE80211_IF_TYPE_AP
)) {
888 if (1/*FIXME: the last PSpoll frame was sent successfully */)
889 b43legacy_power_saving_ctl_bits(dev
, -1, -1);
891 dev
->reg124_set_0x4
= 0;
892 if (b43legacy_is_mode(dev
->wl
, IEEE80211_IF_TYPE_IBSS
))
893 dev
->reg124_set_0x4
= 1;
896 static void handle_irq_atim_end(struct b43legacy_wldev
*dev
)
898 if (!dev
->reg124_set_0x4
) /*FIXME rename this variable*/
900 b43legacy_write32(dev
, B43legacy_MMIO_MACCMD
,
901 b43legacy_read32(dev
, B43legacy_MMIO_MACCMD
)
905 static void handle_irq_pmq(struct b43legacy_wldev
*dev
)
912 tmp
= b43legacy_read32(dev
, B43legacy_MMIO_PS_STATUS
);
913 if (!(tmp
& 0x00000008))
916 /* 16bit write is odd, but correct. */
917 b43legacy_write16(dev
, B43legacy_MMIO_PS_STATUS
, 0x0002);
920 static void b43legacy_write_template_common(struct b43legacy_wldev
*dev
,
921 const u8
*data
, u16 size
,
923 u16 shm_size_offset
, u8 rate
)
927 struct b43legacy_plcp_hdr4 plcp
;
930 b43legacy_generate_plcp_hdr(&plcp
, size
+ FCS_LEN
, rate
);
931 b43legacy_ram_write(dev
, ram_offset
, le32_to_cpu(plcp
.data
));
932 ram_offset
+= sizeof(u32
);
933 /* The PLCP is 6 bytes long, but we only wrote 4 bytes, yet.
934 * So leave the first two bytes of the next write blank.
936 tmp
= (u32
)(data
[0]) << 16;
937 tmp
|= (u32
)(data
[1]) << 24;
938 b43legacy_ram_write(dev
, ram_offset
, tmp
);
939 ram_offset
+= sizeof(u32
);
940 for (i
= 2; i
< size
; i
+= sizeof(u32
)) {
941 tmp
= (u32
)(data
[i
+ 0]);
943 tmp
|= (u32
)(data
[i
+ 1]) << 8;
945 tmp
|= (u32
)(data
[i
+ 2]) << 16;
947 tmp
|= (u32
)(data
[i
+ 3]) << 24;
948 b43legacy_ram_write(dev
, ram_offset
+ i
- 2, tmp
);
950 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
, shm_size_offset
,
951 size
+ sizeof(struct b43legacy_plcp_hdr6
));
954 static void b43legacy_write_beacon_template(struct b43legacy_wldev
*dev
,
956 u16 shm_size_offset
, u8 rate
)
961 B43legacy_WARN_ON(!dev
->cached_beacon
);
962 len
= min((size_t)dev
->cached_beacon
->len
,
963 0x200 - sizeof(struct b43legacy_plcp_hdr6
));
964 data
= (const u8
*)(dev
->cached_beacon
->data
);
965 b43legacy_write_template_common(dev
, data
,
967 shm_size_offset
, rate
);
970 static void b43legacy_write_probe_resp_plcp(struct b43legacy_wldev
*dev
,
971 u16 shm_offset
, u16 size
,
974 struct b43legacy_plcp_hdr4 plcp
;
979 b43legacy_generate_plcp_hdr(&plcp
, size
+ FCS_LEN
, rate
);
980 dur
= ieee80211_generic_frame_duration(dev
->wl
->hw
,
983 B43legacy_RATE_TO_100KBPS(rate
));
984 /* Write PLCP in two parts and timing for packet transfer */
985 tmp
= le32_to_cpu(plcp
.data
);
986 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
, shm_offset
,
988 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
, shm_offset
+ 2,
990 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
, shm_offset
+ 6,
994 /* Instead of using custom probe response template, this function
995 * just patches custom beacon template by:
996 * 1) Changing packet type
997 * 2) Patching duration field
1000 static u8
*b43legacy_generate_probe_resp(struct b43legacy_wldev
*dev
,
1001 u16
*dest_size
, u8 rate
)
1010 struct ieee80211_hdr
*hdr
;
1012 B43legacy_WARN_ON(!dev
->cached_beacon
);
1013 src_size
= dev
->cached_beacon
->len
;
1014 src_data
= (const u8
*)dev
->cached_beacon
->data
;
1016 if (unlikely(src_size
< 0x24)) {
1017 b43legacydbg(dev
->wl
, "b43legacy_generate_probe_resp: "
1018 "invalid beacon\n");
1022 dest_data
= kmalloc(src_size
, GFP_ATOMIC
);
1023 if (unlikely(!dest_data
))
1026 /* 0x24 is offset of first variable-len Information-Element
1029 memcpy(dest_data
, src_data
, 0x24);
1032 for (; src_pos
< src_size
- 2; src_pos
+= elem_size
) {
1033 elem_size
= src_data
[src_pos
+ 1] + 2;
1034 if (src_data
[src_pos
] != 0x05) { /* TIM */
1035 memcpy(dest_data
+ dest_pos
, src_data
+ src_pos
,
1037 dest_pos
+= elem_size
;
1040 *dest_size
= dest_pos
;
1041 hdr
= (struct ieee80211_hdr
*)dest_data
;
1043 /* Set the frame control. */
1044 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
1045 IEEE80211_STYPE_PROBE_RESP
);
1046 dur
= ieee80211_generic_frame_duration(dev
->wl
->hw
,
1049 B43legacy_RATE_TO_100KBPS(rate
));
1050 hdr
->duration_id
= dur
;
1055 static void b43legacy_write_probe_resp_template(struct b43legacy_wldev
*dev
,
1057 u16 shm_size_offset
, u8 rate
)
1059 u8
*probe_resp_data
;
1062 B43legacy_WARN_ON(!dev
->cached_beacon
);
1063 size
= dev
->cached_beacon
->len
;
1064 probe_resp_data
= b43legacy_generate_probe_resp(dev
, &size
, rate
);
1065 if (unlikely(!probe_resp_data
))
1068 /* Looks like PLCP headers plus packet timings are stored for
1069 * all possible basic rates
1071 b43legacy_write_probe_resp_plcp(dev
, 0x31A, size
,
1072 B43legacy_CCK_RATE_1MB
);
1073 b43legacy_write_probe_resp_plcp(dev
, 0x32C, size
,
1074 B43legacy_CCK_RATE_2MB
);
1075 b43legacy_write_probe_resp_plcp(dev
, 0x33E, size
,
1076 B43legacy_CCK_RATE_5MB
);
1077 b43legacy_write_probe_resp_plcp(dev
, 0x350, size
,
1078 B43legacy_CCK_RATE_11MB
);
1080 size
= min((size_t)size
,
1081 0x200 - sizeof(struct b43legacy_plcp_hdr6
));
1082 b43legacy_write_template_common(dev
, probe_resp_data
,
1084 shm_size_offset
, rate
);
1085 kfree(probe_resp_data
);
1088 static int b43legacy_refresh_cached_beacon(struct b43legacy_wldev
*dev
,
1089 struct sk_buff
*beacon
)
1091 if (dev
->cached_beacon
)
1092 kfree_skb(dev
->cached_beacon
);
1093 dev
->cached_beacon
= beacon
;
1098 static void b43legacy_update_templates(struct b43legacy_wldev
*dev
)
1102 B43legacy_WARN_ON(!dev
->cached_beacon
);
1104 b43legacy_write_beacon_template(dev
, 0x68, 0x18,
1105 B43legacy_CCK_RATE_1MB
);
1106 b43legacy_write_beacon_template(dev
, 0x468, 0x1A,
1107 B43legacy_CCK_RATE_1MB
);
1108 b43legacy_write_probe_resp_template(dev
, 0x268, 0x4A,
1109 B43legacy_CCK_RATE_11MB
);
1111 status
= b43legacy_read32(dev
, B43legacy_MMIO_MACCMD
);
1113 b43legacy_write32(dev
, B43legacy_MMIO_MACCMD
, status
);
1116 static void b43legacy_refresh_templates(struct b43legacy_wldev
*dev
,
1117 struct sk_buff
*beacon
)
1121 err
= b43legacy_refresh_cached_beacon(dev
, beacon
);
1124 b43legacy_update_templates(dev
);
1127 static void b43legacy_set_ssid(struct b43legacy_wldev
*dev
,
1128 const u8
*ssid
, u8 ssid_len
)
1134 len
= min((u16
)ssid_len
, (u16
)0x100);
1135 for (i
= 0; i
< len
; i
+= sizeof(u32
)) {
1136 tmp
= (u32
)(ssid
[i
+ 0]);
1138 tmp
|= (u32
)(ssid
[i
+ 1]) << 8;
1140 tmp
|= (u32
)(ssid
[i
+ 2]) << 16;
1142 tmp
|= (u32
)(ssid
[i
+ 3]) << 24;
1143 b43legacy_shm_write32(dev
, B43legacy_SHM_SHARED
,
1146 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
,
1150 static void b43legacy_set_beacon_int(struct b43legacy_wldev
*dev
,
1153 b43legacy_time_lock(dev
);
1154 if (dev
->dev
->id
.revision
>= 3)
1155 b43legacy_write32(dev
, 0x188, (beacon_int
<< 16));
1157 b43legacy_write16(dev
, 0x606, (beacon_int
>> 6));
1158 b43legacy_write16(dev
, 0x610, beacon_int
);
1160 b43legacy_time_unlock(dev
);
1163 static void handle_irq_beacon(struct b43legacy_wldev
*dev
)
1167 if (!b43legacy_is_mode(dev
->wl
, IEEE80211_IF_TYPE_AP
))
1170 dev
->irq_savedstate
&= ~B43legacy_IRQ_BEACON
;
1171 status
= b43legacy_read32(dev
, B43legacy_MMIO_MACCMD
);
1173 if (!dev
->cached_beacon
|| ((status
& 0x1) && (status
& 0x2))) {
1174 /* ACK beacon IRQ. */
1175 b43legacy_write32(dev
, B43legacy_MMIO_GEN_IRQ_REASON
,
1176 B43legacy_IRQ_BEACON
);
1177 dev
->irq_savedstate
|= B43legacy_IRQ_BEACON
;
1178 if (dev
->cached_beacon
)
1179 kfree_skb(dev
->cached_beacon
);
1180 dev
->cached_beacon
= NULL
;
1183 if (!(status
& 0x1)) {
1184 b43legacy_write_beacon_template(dev
, 0x68, 0x18,
1185 B43legacy_CCK_RATE_1MB
);
1187 b43legacy_write32(dev
, B43legacy_MMIO_MACCMD
,
1190 if (!(status
& 0x2)) {
1191 b43legacy_write_beacon_template(dev
, 0x468, 0x1A,
1192 B43legacy_CCK_RATE_1MB
);
1194 b43legacy_write32(dev
, B43legacy_MMIO_MACCMD
,
1199 static void handle_irq_ucode_debug(struct b43legacy_wldev
*dev
)
1203 /* Interrupt handler bottom-half */
1204 static void b43legacy_interrupt_tasklet(struct b43legacy_wldev
*dev
)
1207 u32 dma_reason
[ARRAY_SIZE(dev
->dma_reason
)];
1208 u32 merged_dma_reason
= 0;
1210 unsigned long flags
;
1212 spin_lock_irqsave(&dev
->wl
->irq_lock
, flags
);
1214 B43legacy_WARN_ON(b43legacy_status(dev
) <
1215 B43legacy_STAT_INITIALIZED
);
1217 reason
= dev
->irq_reason
;
1218 for (i
= 0; i
< ARRAY_SIZE(dma_reason
); i
++) {
1219 dma_reason
[i
] = dev
->dma_reason
[i
];
1220 merged_dma_reason
|= dma_reason
[i
];
1223 if (unlikely(reason
& B43legacy_IRQ_MAC_TXERR
))
1224 b43legacyerr(dev
->wl
, "MAC transmission error\n");
1226 if (unlikely(reason
& B43legacy_IRQ_PHY_TXERR
)) {
1227 b43legacyerr(dev
->wl
, "PHY transmission error\n");
1229 if (unlikely(atomic_dec_and_test(&dev
->phy
.txerr_cnt
))) {
1230 b43legacyerr(dev
->wl
, "Too many PHY TX errors, "
1231 "restarting the controller\n");
1232 b43legacy_controller_restart(dev
, "PHY TX errors");
1236 if (unlikely(merged_dma_reason
& (B43legacy_DMAIRQ_FATALMASK
|
1237 B43legacy_DMAIRQ_NONFATALMASK
))) {
1238 if (merged_dma_reason
& B43legacy_DMAIRQ_FATALMASK
) {
1239 b43legacyerr(dev
->wl
, "Fatal DMA error: "
1240 "0x%08X, 0x%08X, 0x%08X, "
1241 "0x%08X, 0x%08X, 0x%08X\n",
1242 dma_reason
[0], dma_reason
[1],
1243 dma_reason
[2], dma_reason
[3],
1244 dma_reason
[4], dma_reason
[5]);
1245 b43legacy_controller_restart(dev
, "DMA error");
1247 spin_unlock_irqrestore(&dev
->wl
->irq_lock
, flags
);
1250 if (merged_dma_reason
& B43legacy_DMAIRQ_NONFATALMASK
)
1251 b43legacyerr(dev
->wl
, "DMA error: "
1252 "0x%08X, 0x%08X, 0x%08X, "
1253 "0x%08X, 0x%08X, 0x%08X\n",
1254 dma_reason
[0], dma_reason
[1],
1255 dma_reason
[2], dma_reason
[3],
1256 dma_reason
[4], dma_reason
[5]);
1259 if (unlikely(reason
& B43legacy_IRQ_UCODE_DEBUG
))
1260 handle_irq_ucode_debug(dev
);
1261 if (reason
& B43legacy_IRQ_TBTT_INDI
)
1262 handle_irq_tbtt_indication(dev
);
1263 if (reason
& B43legacy_IRQ_ATIM_END
)
1264 handle_irq_atim_end(dev
);
1265 if (reason
& B43legacy_IRQ_BEACON
)
1266 handle_irq_beacon(dev
);
1267 if (reason
& B43legacy_IRQ_PMQ
)
1268 handle_irq_pmq(dev
);
1269 if (reason
& B43legacy_IRQ_TXFIFO_FLUSH_OK
)
1271 if (reason
& B43legacy_IRQ_NOISESAMPLE_OK
)
1272 handle_irq_noise(dev
);
1274 /* Check the DMA reason registers for received data. */
1275 if (dma_reason
[0] & B43legacy_DMAIRQ_RX_DONE
) {
1276 if (b43legacy_using_pio(dev
))
1277 b43legacy_pio_rx(dev
->pio
.queue0
);
1279 b43legacy_dma_rx(dev
->dma
.rx_ring0
);
1281 B43legacy_WARN_ON(dma_reason
[1] & B43legacy_DMAIRQ_RX_DONE
);
1282 B43legacy_WARN_ON(dma_reason
[2] & B43legacy_DMAIRQ_RX_DONE
);
1283 if (dma_reason
[3] & B43legacy_DMAIRQ_RX_DONE
) {
1284 if (b43legacy_using_pio(dev
))
1285 b43legacy_pio_rx(dev
->pio
.queue3
);
1287 b43legacy_dma_rx(dev
->dma
.rx_ring3
);
1289 B43legacy_WARN_ON(dma_reason
[4] & B43legacy_DMAIRQ_RX_DONE
);
1290 B43legacy_WARN_ON(dma_reason
[5] & B43legacy_DMAIRQ_RX_DONE
);
1292 if (reason
& B43legacy_IRQ_TX_OK
)
1293 handle_irq_transmit_status(dev
);
1295 b43legacy_interrupt_enable(dev
, dev
->irq_savedstate
);
1297 spin_unlock_irqrestore(&dev
->wl
->irq_lock
, flags
);
1300 static void pio_irq_workaround(struct b43legacy_wldev
*dev
,
1301 u16 base
, int queueidx
)
1305 rxctl
= b43legacy_read16(dev
, base
+ B43legacy_PIO_RXCTL
);
1306 if (rxctl
& B43legacy_PIO_RXCTL_DATAAVAILABLE
)
1307 dev
->dma_reason
[queueidx
] |= B43legacy_DMAIRQ_RX_DONE
;
1309 dev
->dma_reason
[queueidx
] &= ~B43legacy_DMAIRQ_RX_DONE
;
1312 static void b43legacy_interrupt_ack(struct b43legacy_wldev
*dev
, u32 reason
)
1314 if (b43legacy_using_pio(dev
) &&
1315 (dev
->dev
->id
.revision
< 3) &&
1316 (!(reason
& B43legacy_IRQ_PIO_WORKAROUND
))) {
1317 /* Apply a PIO specific workaround to the dma_reasons */
1318 pio_irq_workaround(dev
, B43legacy_MMIO_PIO1_BASE
, 0);
1319 pio_irq_workaround(dev
, B43legacy_MMIO_PIO2_BASE
, 1);
1320 pio_irq_workaround(dev
, B43legacy_MMIO_PIO3_BASE
, 2);
1321 pio_irq_workaround(dev
, B43legacy_MMIO_PIO4_BASE
, 3);
1324 b43legacy_write32(dev
, B43legacy_MMIO_GEN_IRQ_REASON
, reason
);
1326 b43legacy_write32(dev
, B43legacy_MMIO_DMA0_REASON
,
1327 dev
->dma_reason
[0]);
1328 b43legacy_write32(dev
, B43legacy_MMIO_DMA1_REASON
,
1329 dev
->dma_reason
[1]);
1330 b43legacy_write32(dev
, B43legacy_MMIO_DMA2_REASON
,
1331 dev
->dma_reason
[2]);
1332 b43legacy_write32(dev
, B43legacy_MMIO_DMA3_REASON
,
1333 dev
->dma_reason
[3]);
1334 b43legacy_write32(dev
, B43legacy_MMIO_DMA4_REASON
,
1335 dev
->dma_reason
[4]);
1336 b43legacy_write32(dev
, B43legacy_MMIO_DMA5_REASON
,
1337 dev
->dma_reason
[5]);
1340 /* Interrupt handler top-half */
1341 static irqreturn_t
b43legacy_interrupt_handler(int irq
, void *dev_id
)
1343 irqreturn_t ret
= IRQ_NONE
;
1344 struct b43legacy_wldev
*dev
= dev_id
;
1350 spin_lock(&dev
->wl
->irq_lock
);
1352 if (b43legacy_status(dev
) < B43legacy_STAT_STARTED
)
1354 reason
= b43legacy_read32(dev
, B43legacy_MMIO_GEN_IRQ_REASON
);
1355 if (reason
== 0xffffffff) /* shared IRQ */
1358 reason
&= b43legacy_read32(dev
, B43legacy_MMIO_GEN_IRQ_MASK
);
1362 dev
->dma_reason
[0] = b43legacy_read32(dev
,
1363 B43legacy_MMIO_DMA0_REASON
)
1365 dev
->dma_reason
[1] = b43legacy_read32(dev
,
1366 B43legacy_MMIO_DMA1_REASON
)
1368 dev
->dma_reason
[2] = b43legacy_read32(dev
,
1369 B43legacy_MMIO_DMA2_REASON
)
1371 dev
->dma_reason
[3] = b43legacy_read32(dev
,
1372 B43legacy_MMIO_DMA3_REASON
)
1374 dev
->dma_reason
[4] = b43legacy_read32(dev
,
1375 B43legacy_MMIO_DMA4_REASON
)
1377 dev
->dma_reason
[5] = b43legacy_read32(dev
,
1378 B43legacy_MMIO_DMA5_REASON
)
1381 b43legacy_interrupt_ack(dev
, reason
);
1382 /* disable all IRQs. They are enabled again in the bottom half. */
1383 dev
->irq_savedstate
= b43legacy_interrupt_disable(dev
,
1385 /* save the reason code and call our bottom half. */
1386 dev
->irq_reason
= reason
;
1387 tasklet_schedule(&dev
->isr_tasklet
);
1390 spin_unlock(&dev
->wl
->irq_lock
);
1395 static void b43legacy_release_firmware(struct b43legacy_wldev
*dev
)
1397 release_firmware(dev
->fw
.ucode
);
1398 dev
->fw
.ucode
= NULL
;
1399 release_firmware(dev
->fw
.pcm
);
1401 release_firmware(dev
->fw
.initvals
);
1402 dev
->fw
.initvals
= NULL
;
1403 release_firmware(dev
->fw
.initvals_band
);
1404 dev
->fw
.initvals_band
= NULL
;
1407 static void b43legacy_print_fw_helptext(struct b43legacy_wl
*wl
)
1409 b43legacyerr(wl
, "You must go to http://linuxwireless.org/en/users/"
1410 "Drivers/b43#devicefirmware "
1411 "and download the correct firmware (version 3).\n");
1414 static int do_request_fw(struct b43legacy_wldev
*dev
,
1416 const struct firmware
**fw
)
1418 char path
[sizeof(modparam_fwpostfix
) + 32];
1419 struct b43legacy_fw_header
*hdr
;
1426 snprintf(path
, ARRAY_SIZE(path
),
1427 "b43legacy%s/%s.fw",
1428 modparam_fwpostfix
, name
);
1429 err
= request_firmware(fw
, path
, dev
->dev
->dev
);
1431 b43legacyerr(dev
->wl
, "Firmware file \"%s\" not found "
1432 "or load failed.\n", path
);
1435 if ((*fw
)->size
< sizeof(struct b43legacy_fw_header
))
1437 hdr
= (struct b43legacy_fw_header
*)((*fw
)->data
);
1438 switch (hdr
->type
) {
1439 case B43legacy_FW_TYPE_UCODE
:
1440 case B43legacy_FW_TYPE_PCM
:
1441 size
= be32_to_cpu(hdr
->size
);
1442 if (size
!= (*fw
)->size
- sizeof(struct b43legacy_fw_header
))
1445 case B43legacy_FW_TYPE_IV
:
1456 b43legacyerr(dev
->wl
, "Firmware file \"%s\" format error.\n", path
);
1460 static int b43legacy_request_firmware(struct b43legacy_wldev
*dev
)
1462 struct b43legacy_firmware
*fw
= &dev
->fw
;
1463 const u8 rev
= dev
->dev
->id
.revision
;
1464 const char *filename
;
1468 tmshigh
= ssb_read32(dev
->dev
, SSB_TMSHIGH
);
1471 filename
= "ucode2";
1473 filename
= "ucode4";
1475 filename
= "ucode5";
1476 err
= do_request_fw(dev
, filename
, &fw
->ucode
);
1485 err
= do_request_fw(dev
, filename
, &fw
->pcm
);
1489 if (!fw
->initvals
) {
1490 switch (dev
->phy
.type
) {
1491 case B43legacy_PHYTYPE_G
:
1492 if ((rev
>= 5) && (rev
<= 10))
1493 filename
= "b0g0initvals5";
1494 else if (rev
== 2 || rev
== 4)
1495 filename
= "b0g0initvals2";
1497 goto err_no_initvals
;
1500 goto err_no_initvals
;
1502 err
= do_request_fw(dev
, filename
, &fw
->initvals
);
1506 if (!fw
->initvals_band
) {
1507 switch (dev
->phy
.type
) {
1508 case B43legacy_PHYTYPE_G
:
1509 if ((rev
>= 5) && (rev
<= 10))
1510 filename
= "b0g0bsinitvals5";
1513 else if (rev
== 2 || rev
== 4)
1516 goto err_no_initvals
;
1519 goto err_no_initvals
;
1521 err
= do_request_fw(dev
, filename
, &fw
->initvals_band
);
1529 b43legacy_print_fw_helptext(dev
->wl
);
1534 b43legacyerr(dev
->wl
, "No Initial Values firmware file for PHY %u, "
1535 "core rev %u\n", dev
->phy
.type
, rev
);
1539 b43legacy_release_firmware(dev
);
1543 static int b43legacy_upload_microcode(struct b43legacy_wldev
*dev
)
1545 const size_t hdr_len
= sizeof(struct b43legacy_fw_header
);
1556 /* Jump the microcode PSM to offset 0 */
1557 macctl
= b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
1558 B43legacy_WARN_ON(macctl
& B43legacy_MACCTL_PSM_RUN
);
1559 macctl
|= B43legacy_MACCTL_PSM_JMP0
;
1560 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
, macctl
);
1561 /* Zero out all microcode PSM registers and shared memory. */
1562 for (i
= 0; i
< 64; i
++)
1563 b43legacy_shm_write16(dev
, B43legacy_SHM_WIRELESS
, i
, 0);
1564 for (i
= 0; i
< 4096; i
+= 2)
1565 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
, i
, 0);
1567 /* Upload Microcode. */
1568 data
= (__be32
*) (dev
->fw
.ucode
->data
+ hdr_len
);
1569 len
= (dev
->fw
.ucode
->size
- hdr_len
) / sizeof(__be32
);
1570 b43legacy_shm_control_word(dev
,
1571 B43legacy_SHM_UCODE
|
1572 B43legacy_SHM_AUTOINC_W
,
1574 for (i
= 0; i
< len
; i
++) {
1575 b43legacy_write32(dev
, B43legacy_MMIO_SHM_DATA
,
1576 be32_to_cpu(data
[i
]));
1581 /* Upload PCM data. */
1582 data
= (__be32
*) (dev
->fw
.pcm
->data
+ hdr_len
);
1583 len
= (dev
->fw
.pcm
->size
- hdr_len
) / sizeof(__be32
);
1584 b43legacy_shm_control_word(dev
, B43legacy_SHM_HW
, 0x01EA);
1585 b43legacy_write32(dev
, B43legacy_MMIO_SHM_DATA
, 0x00004000);
1586 /* No need for autoinc bit in SHM_HW */
1587 b43legacy_shm_control_word(dev
, B43legacy_SHM_HW
, 0x01EB);
1588 for (i
= 0; i
< len
; i
++) {
1589 b43legacy_write32(dev
, B43legacy_MMIO_SHM_DATA
,
1590 be32_to_cpu(data
[i
]));
1595 b43legacy_write32(dev
, B43legacy_MMIO_GEN_IRQ_REASON
,
1598 /* Start the microcode PSM */
1599 macctl
= b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
1600 macctl
&= ~B43legacy_MACCTL_PSM_JMP0
;
1601 macctl
|= B43legacy_MACCTL_PSM_RUN
;
1602 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
, macctl
);
1604 /* Wait for the microcode to load and respond */
1607 tmp
= b43legacy_read32(dev
, B43legacy_MMIO_GEN_IRQ_REASON
);
1608 if (tmp
== B43legacy_IRQ_MAC_SUSPENDED
)
1611 if (i
>= B43legacy_IRQWAIT_MAX_RETRIES
) {
1612 b43legacyerr(dev
->wl
, "Microcode not responding\n");
1613 b43legacy_print_fw_helptext(dev
->wl
);
1617 msleep_interruptible(50);
1618 if (signal_pending(current
)) {
1623 /* dummy read follows */
1624 b43legacy_read32(dev
, B43legacy_MMIO_GEN_IRQ_REASON
);
1626 /* Get and check the revisions. */
1627 fwrev
= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
,
1628 B43legacy_SHM_SH_UCODEREV
);
1629 fwpatch
= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
,
1630 B43legacy_SHM_SH_UCODEPATCH
);
1631 fwdate
= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
,
1632 B43legacy_SHM_SH_UCODEDATE
);
1633 fwtime
= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
,
1634 B43legacy_SHM_SH_UCODETIME
);
1636 if (fwrev
> 0x128) {
1637 b43legacyerr(dev
->wl
, "YOU ARE TRYING TO LOAD V4 FIRMWARE."
1638 " Only firmware from binary drivers version 3.x"
1639 " is supported. You must change your firmware"
1641 b43legacy_print_fw_helptext(dev
->wl
);
1645 b43legacyinfo(dev
->wl
, "Loading firmware version 0x%X, patch level %u "
1646 "(20%.2i-%.2i-%.2i %.2i:%.2i:%.2i)\n", fwrev
, fwpatch
,
1647 (fwdate
>> 12) & 0xF, (fwdate
>> 8) & 0xF, fwdate
& 0xFF,
1648 (fwtime
>> 11) & 0x1F, (fwtime
>> 5) & 0x3F,
1651 dev
->fw
.rev
= fwrev
;
1652 dev
->fw
.patch
= fwpatch
;
1657 macctl
= b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
1658 macctl
&= ~B43legacy_MACCTL_PSM_RUN
;
1659 macctl
|= B43legacy_MACCTL_PSM_JMP0
;
1660 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
, macctl
);
1665 static int b43legacy_write_initvals(struct b43legacy_wldev
*dev
,
1666 const struct b43legacy_iv
*ivals
,
1670 const struct b43legacy_iv
*iv
;
1675 BUILD_BUG_ON(sizeof(struct b43legacy_iv
) != 6);
1677 for (i
= 0; i
< count
; i
++) {
1678 if (array_size
< sizeof(iv
->offset_size
))
1680 array_size
-= sizeof(iv
->offset_size
);
1681 offset
= be16_to_cpu(iv
->offset_size
);
1682 bit32
= !!(offset
& B43legacy_IV_32BIT
);
1683 offset
&= B43legacy_IV_OFFSET_MASK
;
1684 if (offset
>= 0x1000)
1689 if (array_size
< sizeof(iv
->data
.d32
))
1691 array_size
-= sizeof(iv
->data
.d32
);
1693 value
= be32_to_cpu(get_unaligned(&iv
->data
.d32
));
1694 b43legacy_write32(dev
, offset
, value
);
1696 iv
= (const struct b43legacy_iv
*)((const uint8_t *)iv
+
1702 if (array_size
< sizeof(iv
->data
.d16
))
1704 array_size
-= sizeof(iv
->data
.d16
);
1706 value
= be16_to_cpu(iv
->data
.d16
);
1707 b43legacy_write16(dev
, offset
, value
);
1709 iv
= (const struct b43legacy_iv
*)((const uint8_t *)iv
+
1720 b43legacyerr(dev
->wl
, "Initial Values Firmware file-format error.\n");
1721 b43legacy_print_fw_helptext(dev
->wl
);
1726 static int b43legacy_upload_initvals(struct b43legacy_wldev
*dev
)
1728 const size_t hdr_len
= sizeof(struct b43legacy_fw_header
);
1729 const struct b43legacy_fw_header
*hdr
;
1730 struct b43legacy_firmware
*fw
= &dev
->fw
;
1731 const struct b43legacy_iv
*ivals
;
1735 hdr
= (const struct b43legacy_fw_header
*)(fw
->initvals
->data
);
1736 ivals
= (const struct b43legacy_iv
*)(fw
->initvals
->data
+ hdr_len
);
1737 count
= be32_to_cpu(hdr
->size
);
1738 err
= b43legacy_write_initvals(dev
, ivals
, count
,
1739 fw
->initvals
->size
- hdr_len
);
1742 if (fw
->initvals_band
) {
1743 hdr
= (const struct b43legacy_fw_header
*)
1744 (fw
->initvals_band
->data
);
1745 ivals
= (const struct b43legacy_iv
*)(fw
->initvals_band
->data
1747 count
= be32_to_cpu(hdr
->size
);
1748 err
= b43legacy_write_initvals(dev
, ivals
, count
,
1749 fw
->initvals_band
->size
- hdr_len
);
1758 /* Initialize the GPIOs
1759 * http://bcm-specs.sipsolutions.net/GPIO
1761 static int b43legacy_gpio_init(struct b43legacy_wldev
*dev
)
1763 struct ssb_bus
*bus
= dev
->dev
->bus
;
1764 struct ssb_device
*gpiodev
, *pcidev
= NULL
;
1768 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
,
1769 b43legacy_read32(dev
,
1770 B43legacy_MMIO_MACCTL
)
1773 b43legacy_write16(dev
, B43legacy_MMIO_GPIO_MASK
,
1774 b43legacy_read16(dev
,
1775 B43legacy_MMIO_GPIO_MASK
)
1780 if (dev
->dev
->bus
->chip_id
== 0x4301) {
1784 if (dev
->dev
->bus
->sprom
.boardflags_lo
& B43legacy_BFL_PACTRL
) {
1785 b43legacy_write16(dev
, B43legacy_MMIO_GPIO_MASK
,
1786 b43legacy_read16(dev
,
1787 B43legacy_MMIO_GPIO_MASK
)
1792 if (dev
->dev
->id
.revision
>= 2)
1793 mask
|= 0x0010; /* FIXME: This is redundant. */
1795 #ifdef CONFIG_SSB_DRIVER_PCICORE
1796 pcidev
= bus
->pcicore
.dev
;
1798 gpiodev
= bus
->chipco
.dev
? : pcidev
;
1801 ssb_write32(gpiodev
, B43legacy_GPIO_CONTROL
,
1802 (ssb_read32(gpiodev
, B43legacy_GPIO_CONTROL
)
1808 /* Turn off all GPIO stuff. Call this on module unload, for example. */
1809 static void b43legacy_gpio_cleanup(struct b43legacy_wldev
*dev
)
1811 struct ssb_bus
*bus
= dev
->dev
->bus
;
1812 struct ssb_device
*gpiodev
, *pcidev
= NULL
;
1814 #ifdef CONFIG_SSB_DRIVER_PCICORE
1815 pcidev
= bus
->pcicore
.dev
;
1817 gpiodev
= bus
->chipco
.dev
? : pcidev
;
1820 ssb_write32(gpiodev
, B43legacy_GPIO_CONTROL
, 0);
1823 /* http://bcm-specs.sipsolutions.net/EnableMac */
1824 void b43legacy_mac_enable(struct b43legacy_wldev
*dev
)
1826 dev
->mac_suspended
--;
1827 B43legacy_WARN_ON(dev
->mac_suspended
< 0);
1828 B43legacy_WARN_ON(irqs_disabled());
1829 if (dev
->mac_suspended
== 0) {
1830 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
,
1831 b43legacy_read32(dev
,
1832 B43legacy_MMIO_MACCTL
)
1833 | B43legacy_MACCTL_ENABLED
);
1834 b43legacy_write32(dev
, B43legacy_MMIO_GEN_IRQ_REASON
,
1835 B43legacy_IRQ_MAC_SUSPENDED
);
1836 /* the next two are dummy reads */
1837 b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
1838 b43legacy_read32(dev
, B43legacy_MMIO_GEN_IRQ_REASON
);
1839 b43legacy_power_saving_ctl_bits(dev
, -1, -1);
1841 /* Re-enable IRQs. */
1842 spin_lock_irq(&dev
->wl
->irq_lock
);
1843 b43legacy_interrupt_enable(dev
, dev
->irq_savedstate
);
1844 spin_unlock_irq(&dev
->wl
->irq_lock
);
1848 /* http://bcm-specs.sipsolutions.net/SuspendMAC */
1849 void b43legacy_mac_suspend(struct b43legacy_wldev
*dev
)
1855 B43legacy_WARN_ON(irqs_disabled());
1856 B43legacy_WARN_ON(dev
->mac_suspended
< 0);
1858 if (dev
->mac_suspended
== 0) {
1859 /* Mask IRQs before suspending MAC. Otherwise
1860 * the MAC stays busy and won't suspend. */
1861 spin_lock_irq(&dev
->wl
->irq_lock
);
1862 tmp
= b43legacy_interrupt_disable(dev
, B43legacy_IRQ_ALL
);
1863 spin_unlock_irq(&dev
->wl
->irq_lock
);
1864 b43legacy_synchronize_irq(dev
);
1865 dev
->irq_savedstate
= tmp
;
1867 b43legacy_power_saving_ctl_bits(dev
, -1, 1);
1868 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
,
1869 b43legacy_read32(dev
,
1870 B43legacy_MMIO_MACCTL
)
1871 & ~B43legacy_MACCTL_ENABLED
);
1872 b43legacy_read32(dev
, B43legacy_MMIO_GEN_IRQ_REASON
);
1873 for (i
= 40; i
; i
--) {
1874 tmp
= b43legacy_read32(dev
,
1875 B43legacy_MMIO_GEN_IRQ_REASON
);
1876 if (tmp
& B43legacy_IRQ_MAC_SUSPENDED
)
1880 b43legacyerr(dev
->wl
, "MAC suspend failed\n");
1883 dev
->mac_suspended
++;
1886 static void b43legacy_adjust_opmode(struct b43legacy_wldev
*dev
)
1888 struct b43legacy_wl
*wl
= dev
->wl
;
1892 ctl
= b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
1893 /* Reset status to STA infrastructure mode. */
1894 ctl
&= ~B43legacy_MACCTL_AP
;
1895 ctl
&= ~B43legacy_MACCTL_KEEP_CTL
;
1896 ctl
&= ~B43legacy_MACCTL_KEEP_BADPLCP
;
1897 ctl
&= ~B43legacy_MACCTL_KEEP_BAD
;
1898 ctl
&= ~B43legacy_MACCTL_PROMISC
;
1899 ctl
&= ~B43legacy_MACCTL_BEACPROMISC
;
1900 ctl
|= B43legacy_MACCTL_INFRA
;
1902 if (b43legacy_is_mode(wl
, IEEE80211_IF_TYPE_AP
))
1903 ctl
|= B43legacy_MACCTL_AP
;
1904 else if (b43legacy_is_mode(wl
, IEEE80211_IF_TYPE_IBSS
))
1905 ctl
&= ~B43legacy_MACCTL_INFRA
;
1907 if (wl
->filter_flags
& FIF_CONTROL
)
1908 ctl
|= B43legacy_MACCTL_KEEP_CTL
;
1909 if (wl
->filter_flags
& FIF_FCSFAIL
)
1910 ctl
|= B43legacy_MACCTL_KEEP_BAD
;
1911 if (wl
->filter_flags
& FIF_PLCPFAIL
)
1912 ctl
|= B43legacy_MACCTL_KEEP_BADPLCP
;
1913 if (wl
->filter_flags
& FIF_PROMISC_IN_BSS
)
1914 ctl
|= B43legacy_MACCTL_PROMISC
;
1915 if (wl
->filter_flags
& FIF_BCN_PRBRESP_PROMISC
)
1916 ctl
|= B43legacy_MACCTL_BEACPROMISC
;
1918 /* Workaround: On old hardware the HW-MAC-address-filter
1919 * doesn't work properly, so always run promisc in filter
1920 * it in software. */
1921 if (dev
->dev
->id
.revision
<= 4)
1922 ctl
|= B43legacy_MACCTL_PROMISC
;
1924 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
, ctl
);
1927 if ((ctl
& B43legacy_MACCTL_INFRA
) &&
1928 !(ctl
& B43legacy_MACCTL_AP
)) {
1929 if (dev
->dev
->bus
->chip_id
== 0x4306 &&
1930 dev
->dev
->bus
->chip_rev
== 3)
1935 b43legacy_write16(dev
, 0x612, cfp_pretbtt
);
1938 static void b43legacy_rate_memory_write(struct b43legacy_wldev
*dev
,
1946 offset
+= (b43legacy_plcp_get_ratecode_ofdm(rate
) & 0x000F) * 2;
1949 offset
+= (b43legacy_plcp_get_ratecode_cck(rate
) & 0x000F) * 2;
1951 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
, offset
+ 0x20,
1952 b43legacy_shm_read16(dev
,
1953 B43legacy_SHM_SHARED
, offset
));
1956 static void b43legacy_rate_memory_init(struct b43legacy_wldev
*dev
)
1958 switch (dev
->phy
.type
) {
1959 case B43legacy_PHYTYPE_G
:
1960 b43legacy_rate_memory_write(dev
, B43legacy_OFDM_RATE_6MB
, 1);
1961 b43legacy_rate_memory_write(dev
, B43legacy_OFDM_RATE_12MB
, 1);
1962 b43legacy_rate_memory_write(dev
, B43legacy_OFDM_RATE_18MB
, 1);
1963 b43legacy_rate_memory_write(dev
, B43legacy_OFDM_RATE_24MB
, 1);
1964 b43legacy_rate_memory_write(dev
, B43legacy_OFDM_RATE_36MB
, 1);
1965 b43legacy_rate_memory_write(dev
, B43legacy_OFDM_RATE_48MB
, 1);
1966 b43legacy_rate_memory_write(dev
, B43legacy_OFDM_RATE_54MB
, 1);
1968 case B43legacy_PHYTYPE_B
:
1969 b43legacy_rate_memory_write(dev
, B43legacy_CCK_RATE_1MB
, 0);
1970 b43legacy_rate_memory_write(dev
, B43legacy_CCK_RATE_2MB
, 0);
1971 b43legacy_rate_memory_write(dev
, B43legacy_CCK_RATE_5MB
, 0);
1972 b43legacy_rate_memory_write(dev
, B43legacy_CCK_RATE_11MB
, 0);
1975 B43legacy_BUG_ON(1);
1979 /* Set the TX-Antenna for management frames sent by firmware. */
1980 static void b43legacy_mgmtframe_txantenna(struct b43legacy_wldev
*dev
,
1987 case B43legacy_ANTENNA0
:
1988 ant
|= B43legacy_TX4_PHY_ANT0
;
1990 case B43legacy_ANTENNA1
:
1991 ant
|= B43legacy_TX4_PHY_ANT1
;
1993 case B43legacy_ANTENNA_AUTO
:
1994 ant
|= B43legacy_TX4_PHY_ANTLAST
;
1997 B43legacy_BUG_ON(1);
2000 /* FIXME We also need to set the other flags of the PHY control
2001 * field somewhere. */
2004 tmp
= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
,
2005 B43legacy_SHM_SH_BEACPHYCTL
);
2006 tmp
= (tmp
& ~B43legacy_TX4_PHY_ANT
) | ant
;
2007 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
,
2008 B43legacy_SHM_SH_BEACPHYCTL
, tmp
);
2010 tmp
= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
,
2011 B43legacy_SHM_SH_ACKCTSPHYCTL
);
2012 tmp
= (tmp
& ~B43legacy_TX4_PHY_ANT
) | ant
;
2013 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
,
2014 B43legacy_SHM_SH_ACKCTSPHYCTL
, tmp
);
2015 /* For Probe Resposes */
2016 tmp
= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
,
2017 B43legacy_SHM_SH_PRPHYCTL
);
2018 tmp
= (tmp
& ~B43legacy_TX4_PHY_ANT
) | ant
;
2019 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
,
2020 B43legacy_SHM_SH_PRPHYCTL
, tmp
);
2023 /* This is the opposite of b43legacy_chip_init() */
2024 static void b43legacy_chip_exit(struct b43legacy_wldev
*dev
)
2026 b43legacy_radio_turn_off(dev
, 1);
2027 b43legacy_gpio_cleanup(dev
);
2028 /* firmware is released later */
2031 /* Initialize the chip
2032 * http://bcm-specs.sipsolutions.net/ChipInit
2034 static int b43legacy_chip_init(struct b43legacy_wldev
*dev
)
2036 struct b43legacy_phy
*phy
= &dev
->phy
;
2039 u32 value32
, macctl
;
2042 /* Initialize the MAC control */
2043 macctl
= B43legacy_MACCTL_IHR_ENABLED
| B43legacy_MACCTL_SHM_ENABLED
;
2045 macctl
|= B43legacy_MACCTL_GMODE
;
2046 macctl
|= B43legacy_MACCTL_INFRA
;
2047 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
, macctl
);
2049 err
= b43legacy_request_firmware(dev
);
2052 err
= b43legacy_upload_microcode(dev
);
2054 goto out
; /* firmware is released later */
2056 err
= b43legacy_gpio_init(dev
);
2058 goto out
; /* firmware is released later */
2060 err
= b43legacy_upload_initvals(dev
);
2062 goto err_gpio_clean
;
2063 b43legacy_radio_turn_on(dev
);
2065 b43legacy_write16(dev
, 0x03E6, 0x0000);
2066 err
= b43legacy_phy_init(dev
);
2070 /* Select initial Interference Mitigation. */
2071 tmp
= phy
->interfmode
;
2072 phy
->interfmode
= B43legacy_INTERFMODE_NONE
;
2073 b43legacy_radio_set_interference_mitigation(dev
, tmp
);
2075 b43legacy_phy_set_antenna_diversity(dev
);
2076 b43legacy_mgmtframe_txantenna(dev
, B43legacy_ANTENNA_DEFAULT
);
2078 if (phy
->type
== B43legacy_PHYTYPE_B
) {
2079 value16
= b43legacy_read16(dev
, 0x005E);
2081 b43legacy_write16(dev
, 0x005E, value16
);
2083 b43legacy_write32(dev
, 0x0100, 0x01000000);
2084 if (dev
->dev
->id
.revision
< 5)
2085 b43legacy_write32(dev
, 0x010C, 0x01000000);
2087 value32
= b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
2088 value32
&= ~B43legacy_MACCTL_INFRA
;
2089 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
, value32
);
2090 value32
= b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
2091 value32
|= B43legacy_MACCTL_INFRA
;
2092 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
, value32
);
2094 if (b43legacy_using_pio(dev
)) {
2095 b43legacy_write32(dev
, 0x0210, 0x00000100);
2096 b43legacy_write32(dev
, 0x0230, 0x00000100);
2097 b43legacy_write32(dev
, 0x0250, 0x00000100);
2098 b43legacy_write32(dev
, 0x0270, 0x00000100);
2099 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
, 0x0034,
2103 /* Probe Response Timeout value */
2104 /* FIXME: Default to 0, has to be set by ioctl probably... :-/ */
2105 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
, 0x0074, 0x0000);
2107 /* Initially set the wireless operation mode. */
2108 b43legacy_adjust_opmode(dev
);
2110 if (dev
->dev
->id
.revision
< 3) {
2111 b43legacy_write16(dev
, 0x060E, 0x0000);
2112 b43legacy_write16(dev
, 0x0610, 0x8000);
2113 b43legacy_write16(dev
, 0x0604, 0x0000);
2114 b43legacy_write16(dev
, 0x0606, 0x0200);
2116 b43legacy_write32(dev
, 0x0188, 0x80000000);
2117 b43legacy_write32(dev
, 0x018C, 0x02000000);
2119 b43legacy_write32(dev
, B43legacy_MMIO_GEN_IRQ_REASON
, 0x00004000);
2120 b43legacy_write32(dev
, B43legacy_MMIO_DMA0_IRQ_MASK
, 0x0001DC00);
2121 b43legacy_write32(dev
, B43legacy_MMIO_DMA1_IRQ_MASK
, 0x0000DC00);
2122 b43legacy_write32(dev
, B43legacy_MMIO_DMA2_IRQ_MASK
, 0x0000DC00);
2123 b43legacy_write32(dev
, B43legacy_MMIO_DMA3_IRQ_MASK
, 0x0001DC00);
2124 b43legacy_write32(dev
, B43legacy_MMIO_DMA4_IRQ_MASK
, 0x0000DC00);
2125 b43legacy_write32(dev
, B43legacy_MMIO_DMA5_IRQ_MASK
, 0x0000DC00);
2127 value32
= ssb_read32(dev
->dev
, SSB_TMSLOW
);
2128 value32
|= 0x00100000;
2129 ssb_write32(dev
->dev
, SSB_TMSLOW
, value32
);
2131 b43legacy_write16(dev
, B43legacy_MMIO_POWERUP_DELAY
,
2132 dev
->dev
->bus
->chipco
.fast_pwrup_delay
);
2134 /* PHY TX errors counter. */
2135 atomic_set(&phy
->txerr_cnt
, B43legacy_PHY_TX_BADNESS_LIMIT
);
2137 B43legacy_WARN_ON(err
!= 0);
2138 b43legacydbg(dev
->wl
, "Chip initialized\n");
2143 b43legacy_radio_turn_off(dev
, 1);
2145 b43legacy_gpio_cleanup(dev
);
2149 static void b43legacy_periodic_every120sec(struct b43legacy_wldev
*dev
)
2151 struct b43legacy_phy
*phy
= &dev
->phy
;
2153 if (phy
->type
!= B43legacy_PHYTYPE_G
|| phy
->rev
< 2)
2156 b43legacy_mac_suspend(dev
);
2157 b43legacy_phy_lo_g_measure(dev
);
2158 b43legacy_mac_enable(dev
);
2161 static void b43legacy_periodic_every60sec(struct b43legacy_wldev
*dev
)
2163 b43legacy_phy_lo_mark_all_unused(dev
);
2164 if (dev
->dev
->bus
->sprom
.boardflags_lo
& B43legacy_BFL_RSSI
) {
2165 b43legacy_mac_suspend(dev
);
2166 b43legacy_calc_nrssi_slope(dev
);
2167 b43legacy_mac_enable(dev
);
2171 static void b43legacy_periodic_every30sec(struct b43legacy_wldev
*dev
)
2173 /* Update device statistics. */
2174 b43legacy_calculate_link_quality(dev
);
2177 static void b43legacy_periodic_every15sec(struct b43legacy_wldev
*dev
)
2179 b43legacy_phy_xmitpower(dev
); /* FIXME: unless scanning? */
2181 atomic_set(&dev
->phy
.txerr_cnt
, B43legacy_PHY_TX_BADNESS_LIMIT
);
2185 static void do_periodic_work(struct b43legacy_wldev
*dev
)
2189 state
= dev
->periodic_state
;
2191 b43legacy_periodic_every120sec(dev
);
2193 b43legacy_periodic_every60sec(dev
);
2195 b43legacy_periodic_every30sec(dev
);
2196 b43legacy_periodic_every15sec(dev
);
2199 /* Periodic work locking policy:
2200 * The whole periodic work handler is protected by
2201 * wl->mutex. If another lock is needed somewhere in the
2202 * pwork callchain, it's aquired in-place, where it's needed.
2204 static void b43legacy_periodic_work_handler(struct work_struct
*work
)
2206 struct b43legacy_wldev
*dev
= container_of(work
, struct b43legacy_wldev
,
2207 periodic_work
.work
);
2208 struct b43legacy_wl
*wl
= dev
->wl
;
2209 unsigned long delay
;
2211 mutex_lock(&wl
->mutex
);
2213 if (unlikely(b43legacy_status(dev
) != B43legacy_STAT_STARTED
))
2215 if (b43legacy_debug(dev
, B43legacy_DBG_PWORK_STOP
))
2218 do_periodic_work(dev
);
2220 dev
->periodic_state
++;
2222 if (b43legacy_debug(dev
, B43legacy_DBG_PWORK_FAST
))
2223 delay
= msecs_to_jiffies(50);
2225 delay
= round_jiffies_relative(HZ
* 15);
2226 queue_delayed_work(wl
->hw
->workqueue
, &dev
->periodic_work
, delay
);
2228 mutex_unlock(&wl
->mutex
);
2231 static void b43legacy_periodic_tasks_setup(struct b43legacy_wldev
*dev
)
2233 struct delayed_work
*work
= &dev
->periodic_work
;
2235 dev
->periodic_state
= 0;
2236 INIT_DELAYED_WORK(work
, b43legacy_periodic_work_handler
);
2237 queue_delayed_work(dev
->wl
->hw
->workqueue
, work
, 0);
2240 /* Validate access to the chip (SHM) */
2241 static int b43legacy_validate_chipaccess(struct b43legacy_wldev
*dev
)
2246 shm_backup
= b43legacy_shm_read32(dev
, B43legacy_SHM_SHARED
, 0);
2247 b43legacy_shm_write32(dev
, B43legacy_SHM_SHARED
, 0, 0xAA5555AA);
2248 if (b43legacy_shm_read32(dev
, B43legacy_SHM_SHARED
, 0) !=
2251 b43legacy_shm_write32(dev
, B43legacy_SHM_SHARED
, 0, 0x55AAAA55);
2252 if (b43legacy_shm_read32(dev
, B43legacy_SHM_SHARED
, 0) !=
2255 b43legacy_shm_write32(dev
, B43legacy_SHM_SHARED
, 0, shm_backup
);
2257 value
= b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
2258 if ((value
| B43legacy_MACCTL_GMODE
) !=
2259 (B43legacy_MACCTL_GMODE
| B43legacy_MACCTL_IHR_ENABLED
))
2262 value
= b43legacy_read32(dev
, B43legacy_MMIO_GEN_IRQ_REASON
);
2268 b43legacyerr(dev
->wl
, "Failed to validate the chipaccess\n");
2272 static void b43legacy_security_init(struct b43legacy_wldev
*dev
)
2274 dev
->max_nr_keys
= (dev
->dev
->id
.revision
>= 5) ? 58 : 20;
2275 B43legacy_WARN_ON(dev
->max_nr_keys
> ARRAY_SIZE(dev
->key
));
2276 dev
->ktp
= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
,
2278 /* KTP is a word address, but we address SHM bytewise.
2279 * So multiply by two.
2282 if (dev
->dev
->id
.revision
>= 5)
2283 /* Number of RCMTA address slots */
2284 b43legacy_write16(dev
, B43legacy_MMIO_RCMTA_COUNT
,
2285 dev
->max_nr_keys
- 8);
2288 static int b43legacy_rng_read(struct hwrng
*rng
, u32
*data
)
2290 struct b43legacy_wl
*wl
= (struct b43legacy_wl
*)rng
->priv
;
2291 unsigned long flags
;
2293 /* Don't take wl->mutex here, as it could deadlock with
2294 * hwrng internal locking. It's not needed to take
2295 * wl->mutex here, anyway. */
2297 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2298 *data
= b43legacy_read16(wl
->current_dev
, B43legacy_MMIO_RNG
);
2299 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2301 return (sizeof(u16
));
2304 static void b43legacy_rng_exit(struct b43legacy_wl
*wl
)
2306 if (wl
->rng_initialized
)
2307 hwrng_unregister(&wl
->rng
);
2310 static int b43legacy_rng_init(struct b43legacy_wl
*wl
)
2314 snprintf(wl
->rng_name
, ARRAY_SIZE(wl
->rng_name
),
2315 "%s_%s", KBUILD_MODNAME
, wiphy_name(wl
->hw
->wiphy
));
2316 wl
->rng
.name
= wl
->rng_name
;
2317 wl
->rng
.data_read
= b43legacy_rng_read
;
2318 wl
->rng
.priv
= (unsigned long)wl
;
2319 wl
->rng_initialized
= 1;
2320 err
= hwrng_register(&wl
->rng
);
2322 wl
->rng_initialized
= 0;
2323 b43legacyerr(wl
, "Failed to register the random "
2324 "number generator (%d)\n", err
);
2330 static int b43legacy_op_tx(struct ieee80211_hw
*hw
,
2331 struct sk_buff
*skb
,
2332 struct ieee80211_tx_control
*ctl
)
2334 struct b43legacy_wl
*wl
= hw_to_b43legacy_wl(hw
);
2335 struct b43legacy_wldev
*dev
= wl
->current_dev
;
2337 unsigned long flags
;
2341 if (unlikely(b43legacy_status(dev
) < B43legacy_STAT_STARTED
))
2343 /* DMA-TX is done without a global lock. */
2344 if (b43legacy_using_pio(dev
)) {
2345 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2346 err
= b43legacy_pio_tx(dev
, skb
, ctl
);
2347 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2349 err
= b43legacy_dma_tx(dev
, skb
, ctl
);
2352 return NETDEV_TX_BUSY
;
2353 return NETDEV_TX_OK
;
2356 static int b43legacy_op_conf_tx(struct ieee80211_hw
*hw
,
2358 const struct ieee80211_tx_queue_params
*params
)
2363 static int b43legacy_op_get_tx_stats(struct ieee80211_hw
*hw
,
2364 struct ieee80211_tx_queue_stats
*stats
)
2366 struct b43legacy_wl
*wl
= hw_to_b43legacy_wl(hw
);
2367 struct b43legacy_wldev
*dev
= wl
->current_dev
;
2368 unsigned long flags
;
2373 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2374 if (likely(b43legacy_status(dev
) >= B43legacy_STAT_STARTED
)) {
2375 if (b43legacy_using_pio(dev
))
2376 b43legacy_pio_get_tx_stats(dev
, stats
);
2378 b43legacy_dma_get_tx_stats(dev
, stats
);
2381 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2386 static int b43legacy_op_get_stats(struct ieee80211_hw
*hw
,
2387 struct ieee80211_low_level_stats
*stats
)
2389 struct b43legacy_wl
*wl
= hw_to_b43legacy_wl(hw
);
2390 unsigned long flags
;
2392 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2393 memcpy(stats
, &wl
->ieee_stats
, sizeof(*stats
));
2394 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2399 static const char *phymode_to_string(unsigned int phymode
)
2402 case B43legacy_PHYMODE_B
:
2404 case B43legacy_PHYMODE_G
:
2407 B43legacy_BUG_ON(1);
2412 static int find_wldev_for_phymode(struct b43legacy_wl
*wl
,
2413 unsigned int phymode
,
2414 struct b43legacy_wldev
**dev
,
2417 struct b43legacy_wldev
*d
;
2419 list_for_each_entry(d
, &wl
->devlist
, list
) {
2420 if (d
->phy
.possible_phymodes
& phymode
) {
2421 /* Ok, this device supports the PHY-mode.
2422 * Set the gmode bit. */
2433 static void b43legacy_put_phy_into_reset(struct b43legacy_wldev
*dev
)
2435 struct ssb_device
*sdev
= dev
->dev
;
2438 tmslow
= ssb_read32(sdev
, SSB_TMSLOW
);
2439 tmslow
&= ~B43legacy_TMSLOW_GMODE
;
2440 tmslow
|= B43legacy_TMSLOW_PHYRESET
;
2441 tmslow
|= SSB_TMSLOW_FGC
;
2442 ssb_write32(sdev
, SSB_TMSLOW
, tmslow
);
2445 tmslow
= ssb_read32(sdev
, SSB_TMSLOW
);
2446 tmslow
&= ~SSB_TMSLOW_FGC
;
2447 tmslow
|= B43legacy_TMSLOW_PHYRESET
;
2448 ssb_write32(sdev
, SSB_TMSLOW
, tmslow
);
2452 /* Expects wl->mutex locked */
2453 static int b43legacy_switch_phymode(struct b43legacy_wl
*wl
,
2454 unsigned int new_mode
)
2456 struct b43legacy_wldev
*up_dev
;
2457 struct b43legacy_wldev
*down_dev
;
2462 err
= find_wldev_for_phymode(wl
, new_mode
, &up_dev
, &gmode
);
2464 b43legacyerr(wl
, "Could not find a device for %s-PHY mode\n",
2465 phymode_to_string(new_mode
));
2468 if ((up_dev
== wl
->current_dev
) &&
2469 (!!wl
->current_dev
->phy
.gmode
== !!gmode
))
2470 /* This device is already running. */
2472 b43legacydbg(wl
, "Reconfiguring PHYmode to %s-PHY\n",
2473 phymode_to_string(new_mode
));
2474 down_dev
= wl
->current_dev
;
2476 prev_status
= b43legacy_status(down_dev
);
2477 /* Shutdown the currently running core. */
2478 if (prev_status
>= B43legacy_STAT_STARTED
)
2479 b43legacy_wireless_core_stop(down_dev
);
2480 if (prev_status
>= B43legacy_STAT_INITIALIZED
)
2481 b43legacy_wireless_core_exit(down_dev
);
2483 if (down_dev
!= up_dev
)
2484 /* We switch to a different core, so we put PHY into
2485 * RESET on the old core. */
2486 b43legacy_put_phy_into_reset(down_dev
);
2488 /* Now start the new core. */
2489 up_dev
->phy
.gmode
= gmode
;
2490 if (prev_status
>= B43legacy_STAT_INITIALIZED
) {
2491 err
= b43legacy_wireless_core_init(up_dev
);
2493 b43legacyerr(wl
, "Fatal: Could not initialize device"
2494 " for newly selected %s-PHY mode\n",
2495 phymode_to_string(new_mode
));
2499 if (prev_status
>= B43legacy_STAT_STARTED
) {
2500 err
= b43legacy_wireless_core_start(up_dev
);
2502 b43legacyerr(wl
, "Fatal: Coult not start device for "
2503 "newly selected %s-PHY mode\n",
2504 phymode_to_string(new_mode
));
2505 b43legacy_wireless_core_exit(up_dev
);
2509 B43legacy_WARN_ON(b43legacy_status(up_dev
) != prev_status
);
2511 b43legacy_shm_write32(up_dev
, B43legacy_SHM_SHARED
, 0x003E, 0);
2513 wl
->current_dev
= up_dev
;
2517 /* Whoops, failed to init the new core. No core is operating now. */
2518 wl
->current_dev
= NULL
;
2522 static int b43legacy_antenna_from_ieee80211(u8 antenna
)
2525 case 0: /* default/diversity */
2526 return B43legacy_ANTENNA_DEFAULT
;
2527 case 1: /* Antenna 0 */
2528 return B43legacy_ANTENNA0
;
2529 case 2: /* Antenna 1 */
2530 return B43legacy_ANTENNA1
;
2532 return B43legacy_ANTENNA_DEFAULT
;
2536 static int b43legacy_op_dev_config(struct ieee80211_hw
*hw
,
2537 struct ieee80211_conf
*conf
)
2539 struct b43legacy_wl
*wl
= hw_to_b43legacy_wl(hw
);
2540 struct b43legacy_wldev
*dev
;
2541 struct b43legacy_phy
*phy
;
2542 unsigned long flags
;
2543 unsigned int new_phymode
= 0xFFFF;
2549 antenna_tx
= b43legacy_antenna_from_ieee80211(conf
->antenna_sel_tx
);
2550 antenna_rx
= b43legacy_antenna_from_ieee80211(conf
->antenna_sel_rx
);
2552 mutex_lock(&wl
->mutex
);
2554 /* Switch the PHY mode (if necessary). */
2555 switch (conf
->phymode
) {
2556 case MODE_IEEE80211B
:
2557 new_phymode
= B43legacy_PHYMODE_B
;
2559 case MODE_IEEE80211G
:
2560 new_phymode
= B43legacy_PHYMODE_G
;
2563 B43legacy_WARN_ON(1);
2565 err
= b43legacy_switch_phymode(wl
, new_phymode
);
2567 goto out_unlock_mutex
;
2568 dev
= wl
->current_dev
;
2571 /* Disable IRQs while reconfiguring the device.
2572 * This makes it possible to drop the spinlock throughout
2573 * the reconfiguration process. */
2574 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2575 if (b43legacy_status(dev
) < B43legacy_STAT_STARTED
) {
2576 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2577 goto out_unlock_mutex
;
2579 savedirqs
= b43legacy_interrupt_disable(dev
, B43legacy_IRQ_ALL
);
2580 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2581 b43legacy_synchronize_irq(dev
);
2583 /* Switch to the requested channel.
2584 * The firmware takes care of races with the TX handler. */
2585 if (conf
->channel_val
!= phy
->channel
)
2586 b43legacy_radio_selectchannel(dev
, conf
->channel_val
, 0);
2588 /* Enable/Disable ShortSlot timing. */
2589 if ((!!(conf
->flags
& IEEE80211_CONF_SHORT_SLOT_TIME
))
2590 != dev
->short_slot
) {
2591 B43legacy_WARN_ON(phy
->type
!= B43legacy_PHYTYPE_G
);
2592 if (conf
->flags
& IEEE80211_CONF_SHORT_SLOT_TIME
)
2593 b43legacy_short_slot_timing_enable(dev
);
2595 b43legacy_short_slot_timing_disable(dev
);
2598 dev
->wl
->radiotap_enabled
= !!(conf
->flags
& IEEE80211_CONF_RADIOTAP
);
2600 /* Adjust the desired TX power level. */
2601 if (conf
->power_level
!= 0) {
2602 if (conf
->power_level
!= phy
->power_level
) {
2603 phy
->power_level
= conf
->power_level
;
2604 b43legacy_phy_xmitpower(dev
);
2608 /* Antennas for RX and management frame TX. */
2609 b43legacy_mgmtframe_txantenna(dev
, antenna_tx
);
2611 /* Update templates for AP mode. */
2612 if (b43legacy_is_mode(wl
, IEEE80211_IF_TYPE_AP
))
2613 b43legacy_set_beacon_int(dev
, conf
->beacon_int
);
2616 if (!!conf
->radio_enabled
!= phy
->radio_on
) {
2617 if (conf
->radio_enabled
) {
2618 b43legacy_radio_turn_on(dev
);
2619 b43legacyinfo(dev
->wl
, "Radio turned on by software\n");
2620 if (!dev
->radio_hw_enable
)
2621 b43legacyinfo(dev
->wl
, "The hardware RF-kill"
2622 " button still turns the radio"
2623 " physically off. Press the"
2624 " button to turn it on.\n");
2626 b43legacy_radio_turn_off(dev
, 0);
2627 b43legacyinfo(dev
->wl
, "Radio turned off by"
2632 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2633 b43legacy_interrupt_enable(dev
, savedirqs
);
2635 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2637 mutex_unlock(&wl
->mutex
);
2642 static void b43legacy_op_configure_filter(struct ieee80211_hw
*hw
,
2643 unsigned int changed
,
2644 unsigned int *fflags
,
2646 struct dev_addr_list
*mc_list
)
2648 struct b43legacy_wl
*wl
= hw_to_b43legacy_wl(hw
);
2649 struct b43legacy_wldev
*dev
= wl
->current_dev
;
2650 unsigned long flags
;
2657 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2658 *fflags
&= FIF_PROMISC_IN_BSS
|
2664 FIF_BCN_PRBRESP_PROMISC
;
2666 changed
&= FIF_PROMISC_IN_BSS
|
2672 FIF_BCN_PRBRESP_PROMISC
;
2674 wl
->filter_flags
= *fflags
;
2676 if (changed
&& b43legacy_status(dev
) >= B43legacy_STAT_INITIALIZED
)
2677 b43legacy_adjust_opmode(dev
);
2678 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2681 static int b43legacy_op_config_interface(struct ieee80211_hw
*hw
,
2682 struct ieee80211_vif
*vif
,
2683 struct ieee80211_if_conf
*conf
)
2685 struct b43legacy_wl
*wl
= hw_to_b43legacy_wl(hw
);
2686 struct b43legacy_wldev
*dev
= wl
->current_dev
;
2687 unsigned long flags
;
2691 mutex_lock(&wl
->mutex
);
2692 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2693 B43legacy_WARN_ON(wl
->vif
!= vif
);
2695 memcpy(wl
->bssid
, conf
->bssid
, ETH_ALEN
);
2697 memset(wl
->bssid
, 0, ETH_ALEN
);
2698 if (b43legacy_status(dev
) >= B43legacy_STAT_INITIALIZED
) {
2699 if (b43legacy_is_mode(wl
, IEEE80211_IF_TYPE_AP
)) {
2700 B43legacy_WARN_ON(conf
->type
!= IEEE80211_IF_TYPE_AP
);
2701 b43legacy_set_ssid(dev
, conf
->ssid
, conf
->ssid_len
);
2703 b43legacy_refresh_templates(dev
, conf
->beacon
);
2705 b43legacy_write_mac_bssid_templates(dev
);
2707 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2708 mutex_unlock(&wl
->mutex
);
2713 /* Locking: wl->mutex */
2714 static void b43legacy_wireless_core_stop(struct b43legacy_wldev
*dev
)
2716 struct b43legacy_wl
*wl
= dev
->wl
;
2717 unsigned long flags
;
2719 if (b43legacy_status(dev
) < B43legacy_STAT_STARTED
)
2722 /* Disable and sync interrupts. We must do this before than
2723 * setting the status to INITIALIZED, as the interrupt handler
2724 * won't care about IRQs then. */
2725 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2726 dev
->irq_savedstate
= b43legacy_interrupt_disable(dev
,
2728 b43legacy_read32(dev
, B43legacy_MMIO_GEN_IRQ_MASK
); /* flush */
2729 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2730 b43legacy_synchronize_irq(dev
);
2732 b43legacy_set_status(dev
, B43legacy_STAT_INITIALIZED
);
2734 mutex_unlock(&wl
->mutex
);
2735 /* Must unlock as it would otherwise deadlock. No races here.
2736 * Cancel the possibly running self-rearming periodic work. */
2737 cancel_delayed_work_sync(&dev
->periodic_work
);
2738 mutex_lock(&wl
->mutex
);
2740 ieee80211_stop_queues(wl
->hw
); /* FIXME this could cause a deadlock */
2742 b43legacy_mac_suspend(dev
);
2743 free_irq(dev
->dev
->irq
, dev
);
2744 b43legacydbg(wl
, "Wireless interface stopped\n");
2747 /* Locking: wl->mutex */
2748 static int b43legacy_wireless_core_start(struct b43legacy_wldev
*dev
)
2752 B43legacy_WARN_ON(b43legacy_status(dev
) != B43legacy_STAT_INITIALIZED
);
2754 drain_txstatus_queue(dev
);
2755 err
= request_irq(dev
->dev
->irq
, b43legacy_interrupt_handler
,
2756 IRQF_SHARED
, KBUILD_MODNAME
, dev
);
2758 b43legacyerr(dev
->wl
, "Cannot request IRQ-%d\n",
2762 /* We are ready to run. */
2763 b43legacy_set_status(dev
, B43legacy_STAT_STARTED
);
2765 /* Start data flow (TX/RX) */
2766 b43legacy_mac_enable(dev
);
2767 b43legacy_interrupt_enable(dev
, dev
->irq_savedstate
);
2768 ieee80211_start_queues(dev
->wl
->hw
);
2770 /* Start maintenance work */
2771 b43legacy_periodic_tasks_setup(dev
);
2773 b43legacydbg(dev
->wl
, "Wireless interface started\n");
2778 /* Get PHY and RADIO versioning numbers */
2779 static int b43legacy_phy_versioning(struct b43legacy_wldev
*dev
)
2781 struct b43legacy_phy
*phy
= &dev
->phy
;
2789 int unsupported
= 0;
2791 /* Get PHY versioning */
2792 tmp
= b43legacy_read16(dev
, B43legacy_MMIO_PHY_VER
);
2793 analog_type
= (tmp
& B43legacy_PHYVER_ANALOG
)
2794 >> B43legacy_PHYVER_ANALOG_SHIFT
;
2795 phy_type
= (tmp
& B43legacy_PHYVER_TYPE
) >> B43legacy_PHYVER_TYPE_SHIFT
;
2796 phy_rev
= (tmp
& B43legacy_PHYVER_VERSION
);
2798 case B43legacy_PHYTYPE_B
:
2799 if (phy_rev
!= 2 && phy_rev
!= 4
2800 && phy_rev
!= 6 && phy_rev
!= 7)
2803 case B43legacy_PHYTYPE_G
:
2811 b43legacyerr(dev
->wl
, "FOUND UNSUPPORTED PHY "
2812 "(Analog %u, Type %u, Revision %u)\n",
2813 analog_type
, phy_type
, phy_rev
);
2816 b43legacydbg(dev
->wl
, "Found PHY: Analog %u, Type %u, Revision %u\n",
2817 analog_type
, phy_type
, phy_rev
);
2820 /* Get RADIO versioning */
2821 if (dev
->dev
->bus
->chip_id
== 0x4317) {
2822 if (dev
->dev
->bus
->chip_rev
== 0)
2824 else if (dev
->dev
->bus
->chip_rev
== 1)
2829 b43legacy_write16(dev
, B43legacy_MMIO_RADIO_CONTROL
,
2830 B43legacy_RADIOCTL_ID
);
2831 tmp
= b43legacy_read16(dev
, B43legacy_MMIO_RADIO_DATA_HIGH
);
2833 b43legacy_write16(dev
, B43legacy_MMIO_RADIO_CONTROL
,
2834 B43legacy_RADIOCTL_ID
);
2835 tmp
|= b43legacy_read16(dev
, B43legacy_MMIO_RADIO_DATA_LOW
);
2837 radio_manuf
= (tmp
& 0x00000FFF);
2838 radio_ver
= (tmp
& 0x0FFFF000) >> 12;
2839 radio_rev
= (tmp
& 0xF0000000) >> 28;
2841 case B43legacy_PHYTYPE_B
:
2842 if ((radio_ver
& 0xFFF0) != 0x2050)
2845 case B43legacy_PHYTYPE_G
:
2846 if (radio_ver
!= 0x2050)
2850 B43legacy_BUG_ON(1);
2853 b43legacyerr(dev
->wl
, "FOUND UNSUPPORTED RADIO "
2854 "(Manuf 0x%X, Version 0x%X, Revision %u)\n",
2855 radio_manuf
, radio_ver
, radio_rev
);
2858 b43legacydbg(dev
->wl
, "Found Radio: Manuf 0x%X, Version 0x%X,"
2859 " Revision %u\n", radio_manuf
, radio_ver
, radio_rev
);
2862 phy
->radio_manuf
= radio_manuf
;
2863 phy
->radio_ver
= radio_ver
;
2864 phy
->radio_rev
= radio_rev
;
2866 phy
->analog
= analog_type
;
2867 phy
->type
= phy_type
;
2873 static void setup_struct_phy_for_init(struct b43legacy_wldev
*dev
,
2874 struct b43legacy_phy
*phy
)
2876 struct b43legacy_lopair
*lo
;
2879 memset(phy
->minlowsig
, 0xFF, sizeof(phy
->minlowsig
));
2880 memset(phy
->minlowsigpos
, 0, sizeof(phy
->minlowsigpos
));
2882 /* Assume the radio is enabled. If it's not enabled, the state will
2883 * immediately get fixed on the first periodic work run. */
2884 dev
->radio_hw_enable
= 1;
2886 phy
->savedpctlreg
= 0xFFFF;
2887 phy
->aci_enable
= 0;
2888 phy
->aci_wlan_automatic
= 0;
2889 phy
->aci_hw_rssi
= 0;
2891 lo
= phy
->_lo_pairs
;
2893 memset(lo
, 0, sizeof(struct b43legacy_lopair
) *
2894 B43legacy_LO_COUNT
);
2895 phy
->max_lb_gain
= 0;
2896 phy
->trsw_rx_gain
= 0;
2898 /* Set default attenuation values. */
2899 phy
->bbatt
= b43legacy_default_baseband_attenuation(dev
);
2900 phy
->rfatt
= b43legacy_default_radio_attenuation(dev
);
2901 phy
->txctl1
= b43legacy_default_txctl1(dev
);
2902 phy
->txpwr_offset
= 0;
2905 phy
->nrssislope
= 0;
2906 for (i
= 0; i
< ARRAY_SIZE(phy
->nrssi
); i
++)
2907 phy
->nrssi
[i
] = -1000;
2908 for (i
= 0; i
< ARRAY_SIZE(phy
->nrssi_lt
); i
++)
2909 phy
->nrssi_lt
[i
] = i
;
2911 phy
->lofcal
= 0xFFFF;
2912 phy
->initval
= 0xFFFF;
2914 phy
->interfmode
= B43legacy_INTERFMODE_NONE
;
2915 phy
->channel
= 0xFF;
2918 static void setup_struct_wldev_for_init(struct b43legacy_wldev
*dev
)
2921 dev
->reg124_set_0x4
= 0;
2924 memset(&dev
->stats
, 0, sizeof(dev
->stats
));
2926 setup_struct_phy_for_init(dev
, &dev
->phy
);
2928 /* IRQ related flags */
2929 dev
->irq_reason
= 0;
2930 memset(dev
->dma_reason
, 0, sizeof(dev
->dma_reason
));
2931 dev
->irq_savedstate
= B43legacy_IRQ_MASKTEMPLATE
;
2933 dev
->mac_suspended
= 1;
2935 /* Noise calculation context */
2936 memset(&dev
->noisecalc
, 0, sizeof(dev
->noisecalc
));
2939 static void b43legacy_imcfglo_timeouts_workaround(struct b43legacy_wldev
*dev
)
2941 #ifdef CONFIG_SSB_DRIVER_PCICORE
2942 struct ssb_bus
*bus
= dev
->dev
->bus
;
2945 if (bus
->pcicore
.dev
&&
2946 bus
->pcicore
.dev
->id
.coreid
== SSB_DEV_PCI
&&
2947 bus
->pcicore
.dev
->id
.revision
<= 5) {
2948 /* IMCFGLO timeouts workaround. */
2949 tmp
= ssb_read32(dev
->dev
, SSB_IMCFGLO
);
2950 tmp
&= ~SSB_IMCFGLO_REQTO
;
2951 tmp
&= ~SSB_IMCFGLO_SERTO
;
2952 switch (bus
->bustype
) {
2953 case SSB_BUSTYPE_PCI
:
2954 case SSB_BUSTYPE_PCMCIA
:
2957 case SSB_BUSTYPE_SSB
:
2961 ssb_write32(dev
->dev
, SSB_IMCFGLO
, tmp
);
2963 #endif /* CONFIG_SSB_DRIVER_PCICORE */
2966 /* Write the short and long frame retry limit values. */
2967 static void b43legacy_set_retry_limits(struct b43legacy_wldev
*dev
,
2968 unsigned int short_retry
,
2969 unsigned int long_retry
)
2971 /* The retry limit is a 4-bit counter. Enforce this to avoid overflowing
2972 * the chip-internal counter. */
2973 short_retry
= min(short_retry
, (unsigned int)0xF);
2974 long_retry
= min(long_retry
, (unsigned int)0xF);
2976 b43legacy_shm_write16(dev
, B43legacy_SHM_WIRELESS
, 0x0006, short_retry
);
2977 b43legacy_shm_write16(dev
, B43legacy_SHM_WIRELESS
, 0x0007, long_retry
);
2980 /* Shutdown a wireless core */
2981 /* Locking: wl->mutex */
2982 static void b43legacy_wireless_core_exit(struct b43legacy_wldev
*dev
)
2984 struct b43legacy_wl
*wl
= dev
->wl
;
2985 struct b43legacy_phy
*phy
= &dev
->phy
;
2988 B43legacy_WARN_ON(b43legacy_status(dev
) > B43legacy_STAT_INITIALIZED
);
2989 if (b43legacy_status(dev
) != B43legacy_STAT_INITIALIZED
)
2991 b43legacy_set_status(dev
, B43legacy_STAT_UNINIT
);
2993 /* Stop the microcode PSM. */
2994 macctl
= b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
2995 macctl
&= ~B43legacy_MACCTL_PSM_RUN
;
2996 macctl
|= B43legacy_MACCTL_PSM_JMP0
;
2997 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
, macctl
);
2999 mutex_unlock(&wl
->mutex
);
3000 /* Must unlock as it would otherwise deadlock. No races here.
3001 * Cancel possibly pending workqueues. */
3002 cancel_work_sync(&dev
->restart_work
);
3003 mutex_lock(&wl
->mutex
);
3005 b43legacy_leds_exit(dev
);
3006 b43legacy_rng_exit(dev
->wl
);
3007 b43legacy_pio_free(dev
);
3008 b43legacy_dma_free(dev
);
3009 b43legacy_chip_exit(dev
);
3010 b43legacy_radio_turn_off(dev
, 1);
3011 b43legacy_switch_analog(dev
, 0);
3012 if (phy
->dyn_tssi_tbl
)
3013 kfree(phy
->tssi2dbm
);
3014 kfree(phy
->lo_control
);
3015 phy
->lo_control
= NULL
;
3016 ssb_device_disable(dev
->dev
, 0);
3017 ssb_bus_may_powerdown(dev
->dev
->bus
);
3020 static void prepare_phy_data_for_init(struct b43legacy_wldev
*dev
)
3022 struct b43legacy_phy
*phy
= &dev
->phy
;
3025 /* Set default attenuation values. */
3026 phy
->bbatt
= b43legacy_default_baseband_attenuation(dev
);
3027 phy
->rfatt
= b43legacy_default_radio_attenuation(dev
);
3028 phy
->txctl1
= b43legacy_default_txctl1(dev
);
3029 phy
->txctl2
= 0xFFFF;
3030 phy
->txpwr_offset
= 0;
3033 phy
->nrssislope
= 0;
3034 for (i
= 0; i
< ARRAY_SIZE(phy
->nrssi
); i
++)
3035 phy
->nrssi
[i
] = -1000;
3036 for (i
= 0; i
< ARRAY_SIZE(phy
->nrssi_lt
); i
++)
3037 phy
->nrssi_lt
[i
] = i
;
3039 phy
->lofcal
= 0xFFFF;
3040 phy
->initval
= 0xFFFF;
3042 phy
->aci_enable
= 0;
3043 phy
->aci_wlan_automatic
= 0;
3044 phy
->aci_hw_rssi
= 0;
3046 phy
->antenna_diversity
= 0xFFFF;
3047 memset(phy
->minlowsig
, 0xFF, sizeof(phy
->minlowsig
));
3048 memset(phy
->minlowsigpos
, 0, sizeof(phy
->minlowsigpos
));
3051 phy
->calibrated
= 0;
3054 memset(phy
->_lo_pairs
, 0,
3055 sizeof(struct b43legacy_lopair
) * B43legacy_LO_COUNT
);
3056 memset(phy
->loopback_gain
, 0, sizeof(phy
->loopback_gain
));
3059 /* Initialize a wireless core */
3060 static int b43legacy_wireless_core_init(struct b43legacy_wldev
*dev
)
3062 struct b43legacy_wl
*wl
= dev
->wl
;
3063 struct ssb_bus
*bus
= dev
->dev
->bus
;
3064 struct b43legacy_phy
*phy
= &dev
->phy
;
3065 struct ssb_sprom
*sprom
= &dev
->dev
->bus
->sprom
;
3070 B43legacy_WARN_ON(b43legacy_status(dev
) != B43legacy_STAT_UNINIT
);
3072 err
= ssb_bus_powerup(bus
, 0);
3075 if (!ssb_device_is_enabled(dev
->dev
)) {
3076 tmp
= phy
->gmode
? B43legacy_TMSLOW_GMODE
: 0;
3077 b43legacy_wireless_core_reset(dev
, tmp
);
3080 if ((phy
->type
== B43legacy_PHYTYPE_B
) ||
3081 (phy
->type
== B43legacy_PHYTYPE_G
)) {
3082 phy
->_lo_pairs
= kzalloc(sizeof(struct b43legacy_lopair
)
3083 * B43legacy_LO_COUNT
,
3085 if (!phy
->_lo_pairs
)
3088 setup_struct_wldev_for_init(dev
);
3090 err
= b43legacy_phy_init_tssi2dbm_table(dev
);
3092 goto err_kfree_lo_control
;
3094 /* Enable IRQ routing to this device. */
3095 ssb_pcicore_dev_irqvecs_enable(&bus
->pcicore
, dev
->dev
);
3097 b43legacy_imcfglo_timeouts_workaround(dev
);
3098 prepare_phy_data_for_init(dev
);
3099 b43legacy_phy_calibrate(dev
);
3100 err
= b43legacy_chip_init(dev
);
3102 goto err_kfree_tssitbl
;
3103 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
,
3104 B43legacy_SHM_SH_WLCOREREV
,
3105 dev
->dev
->id
.revision
);
3106 hf
= b43legacy_hf_read(dev
);
3107 if (phy
->type
== B43legacy_PHYTYPE_G
) {
3108 hf
|= B43legacy_HF_SYMW
;
3110 hf
|= B43legacy_HF_GDCW
;
3111 if (sprom
->boardflags_lo
& B43legacy_BFL_PACTRL
)
3112 hf
|= B43legacy_HF_OFDMPABOOST
;
3113 } else if (phy
->type
== B43legacy_PHYTYPE_B
) {
3114 hf
|= B43legacy_HF_SYMW
;
3115 if (phy
->rev
>= 2 && phy
->radio_ver
== 0x2050)
3116 hf
&= ~B43legacy_HF_GDCW
;
3118 b43legacy_hf_write(dev
, hf
);
3120 b43legacy_set_retry_limits(dev
,
3121 B43legacy_DEFAULT_SHORT_RETRY_LIMIT
,
3122 B43legacy_DEFAULT_LONG_RETRY_LIMIT
);
3124 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
,
3126 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
,
3129 /* Disable sending probe responses from firmware.
3130 * Setting the MaxTime to one usec will always trigger
3131 * a timeout, so we never send any probe resp.
3132 * A timeout of zero is infinite. */
3133 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
,
3134 B43legacy_SHM_SH_PRMAXTIME
, 1);
3136 b43legacy_rate_memory_init(dev
);
3138 /* Minimum Contention Window */
3139 if (phy
->type
== B43legacy_PHYTYPE_B
)
3140 b43legacy_shm_write16(dev
, B43legacy_SHM_WIRELESS
,
3143 b43legacy_shm_write16(dev
, B43legacy_SHM_WIRELESS
,
3145 /* Maximum Contention Window */
3146 b43legacy_shm_write16(dev
, B43legacy_SHM_WIRELESS
,
3150 if (b43legacy_using_pio(dev
))
3151 err
= b43legacy_pio_init(dev
);
3153 err
= b43legacy_dma_init(dev
);
3155 b43legacy_qos_init(dev
);
3157 } while (err
== -EAGAIN
);
3161 b43legacy_write16(dev
, 0x0612, 0x0050);
3162 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
, 0x0416, 0x0050);
3163 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
, 0x0414, 0x01F4);
3165 ssb_bus_powerup(bus
, 1); /* Enable dynamic PCTL */
3166 b43legacy_upload_card_macaddress(dev
);
3167 b43legacy_security_init(dev
);
3168 b43legacy_rng_init(wl
);
3170 b43legacy_set_status(dev
, B43legacy_STAT_INITIALIZED
);
3172 b43legacy_leds_init(dev
);
3177 b43legacy_chip_exit(dev
);
3179 if (phy
->dyn_tssi_tbl
)
3180 kfree(phy
->tssi2dbm
);
3181 err_kfree_lo_control
:
3182 kfree(phy
->lo_control
);
3183 phy
->lo_control
= NULL
;
3184 ssb_bus_may_powerdown(bus
);
3185 B43legacy_WARN_ON(b43legacy_status(dev
) != B43legacy_STAT_UNINIT
);
3189 static int b43legacy_op_add_interface(struct ieee80211_hw
*hw
,
3190 struct ieee80211_if_init_conf
*conf
)
3192 struct b43legacy_wl
*wl
= hw_to_b43legacy_wl(hw
);
3193 struct b43legacy_wldev
*dev
;
3194 unsigned long flags
;
3195 int err
= -EOPNOTSUPP
;
3197 /* TODO: allow WDS/AP devices to coexist */
3199 if (conf
->type
!= IEEE80211_IF_TYPE_AP
&&
3200 conf
->type
!= IEEE80211_IF_TYPE_STA
&&
3201 conf
->type
!= IEEE80211_IF_TYPE_WDS
&&
3202 conf
->type
!= IEEE80211_IF_TYPE_IBSS
)
3205 mutex_lock(&wl
->mutex
);
3207 goto out_mutex_unlock
;
3209 b43legacydbg(wl
, "Adding Interface type %d\n", conf
->type
);
3211 dev
= wl
->current_dev
;
3213 wl
->vif
= conf
->vif
;
3214 wl
->if_type
= conf
->type
;
3215 memcpy(wl
->mac_addr
, conf
->mac_addr
, ETH_ALEN
);
3217 spin_lock_irqsave(&wl
->irq_lock
, flags
);
3218 b43legacy_adjust_opmode(dev
);
3219 b43legacy_upload_card_macaddress(dev
);
3220 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
3224 mutex_unlock(&wl
->mutex
);
3229 static void b43legacy_op_remove_interface(struct ieee80211_hw
*hw
,
3230 struct ieee80211_if_init_conf
*conf
)
3232 struct b43legacy_wl
*wl
= hw_to_b43legacy_wl(hw
);
3233 struct b43legacy_wldev
*dev
= wl
->current_dev
;
3234 unsigned long flags
;
3236 b43legacydbg(wl
, "Removing Interface type %d\n", conf
->type
);
3238 mutex_lock(&wl
->mutex
);
3240 B43legacy_WARN_ON(!wl
->operating
);
3241 B43legacy_WARN_ON(wl
->vif
!= conf
->vif
);
3246 spin_lock_irqsave(&wl
->irq_lock
, flags
);
3247 b43legacy_adjust_opmode(dev
);
3248 memset(wl
->mac_addr
, 0, ETH_ALEN
);
3249 b43legacy_upload_card_macaddress(dev
);
3250 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
3252 mutex_unlock(&wl
->mutex
);
3255 static int b43legacy_op_start(struct ieee80211_hw
*hw
)
3257 struct b43legacy_wl
*wl
= hw_to_b43legacy_wl(hw
);
3258 struct b43legacy_wldev
*dev
= wl
->current_dev
;
3261 bool do_rfkill_exit
= 0;
3263 /* First register RFkill.
3264 * LEDs that are registered later depend on it. */
3265 b43legacy_rfkill_init(dev
);
3267 /* Kill all old instance specific information to make sure
3268 * the card won't use it in the short timeframe between start
3269 * and mac80211 reconfiguring it. */
3270 memset(wl
->bssid
, 0, ETH_ALEN
);
3271 memset(wl
->mac_addr
, 0, ETH_ALEN
);
3272 wl
->filter_flags
= 0;
3274 mutex_lock(&wl
->mutex
);
3276 if (b43legacy_status(dev
) < B43legacy_STAT_INITIALIZED
) {
3277 err
= b43legacy_wireless_core_init(dev
);
3280 goto out_mutex_unlock
;
3285 if (b43legacy_status(dev
) < B43legacy_STAT_STARTED
) {
3286 err
= b43legacy_wireless_core_start(dev
);
3289 b43legacy_wireless_core_exit(dev
);
3291 goto out_mutex_unlock
;
3296 mutex_unlock(&wl
->mutex
);
3299 b43legacy_rfkill_exit(dev
);
3304 static void b43legacy_op_stop(struct ieee80211_hw
*hw
)
3306 struct b43legacy_wl
*wl
= hw_to_b43legacy_wl(hw
);
3307 struct b43legacy_wldev
*dev
= wl
->current_dev
;
3309 b43legacy_rfkill_exit(dev
);
3311 mutex_lock(&wl
->mutex
);
3312 if (b43legacy_status(dev
) >= B43legacy_STAT_STARTED
)
3313 b43legacy_wireless_core_stop(dev
);
3314 b43legacy_wireless_core_exit(dev
);
3315 mutex_unlock(&wl
->mutex
);
3318 static int b43legacy_op_set_retry_limit(struct ieee80211_hw
*hw
,
3319 u32 short_retry_limit
,
3320 u32 long_retry_limit
)
3322 struct b43legacy_wl
*wl
= hw_to_b43legacy_wl(hw
);
3323 struct b43legacy_wldev
*dev
;
3326 mutex_lock(&wl
->mutex
);
3327 dev
= wl
->current_dev
;
3328 if (unlikely(!dev
||
3329 (b43legacy_status(dev
) < B43legacy_STAT_INITIALIZED
))) {
3333 b43legacy_set_retry_limits(dev
, short_retry_limit
, long_retry_limit
);
3335 mutex_unlock(&wl
->mutex
);
3340 static const struct ieee80211_ops b43legacy_hw_ops
= {
3341 .tx
= b43legacy_op_tx
,
3342 .conf_tx
= b43legacy_op_conf_tx
,
3343 .add_interface
= b43legacy_op_add_interface
,
3344 .remove_interface
= b43legacy_op_remove_interface
,
3345 .config
= b43legacy_op_dev_config
,
3346 .config_interface
= b43legacy_op_config_interface
,
3347 .configure_filter
= b43legacy_op_configure_filter
,
3348 .get_stats
= b43legacy_op_get_stats
,
3349 .get_tx_stats
= b43legacy_op_get_tx_stats
,
3350 .start
= b43legacy_op_start
,
3351 .stop
= b43legacy_op_stop
,
3352 .set_retry_limit
= b43legacy_op_set_retry_limit
,
3355 /* Hard-reset the chip. Do not call this directly.
3356 * Use b43legacy_controller_restart()
3358 static void b43legacy_chip_reset(struct work_struct
*work
)
3360 struct b43legacy_wldev
*dev
=
3361 container_of(work
, struct b43legacy_wldev
, restart_work
);
3362 struct b43legacy_wl
*wl
= dev
->wl
;
3366 mutex_lock(&wl
->mutex
);
3368 prev_status
= b43legacy_status(dev
);
3369 /* Bring the device down... */
3370 if (prev_status
>= B43legacy_STAT_STARTED
)
3371 b43legacy_wireless_core_stop(dev
);
3372 if (prev_status
>= B43legacy_STAT_INITIALIZED
)
3373 b43legacy_wireless_core_exit(dev
);
3375 /* ...and up again. */
3376 if (prev_status
>= B43legacy_STAT_INITIALIZED
) {
3377 err
= b43legacy_wireless_core_init(dev
);
3381 if (prev_status
>= B43legacy_STAT_STARTED
) {
3382 err
= b43legacy_wireless_core_start(dev
);
3384 b43legacy_wireless_core_exit(dev
);
3389 mutex_unlock(&wl
->mutex
);
3391 b43legacyerr(wl
, "Controller restart FAILED\n");
3393 b43legacyinfo(wl
, "Controller restarted\n");
3396 static int b43legacy_setup_modes(struct b43legacy_wldev
*dev
,
3400 struct ieee80211_hw
*hw
= dev
->wl
->hw
;
3401 struct ieee80211_hw_mode
*mode
;
3402 struct b43legacy_phy
*phy
= &dev
->phy
;
3406 phy
->possible_phymodes
= 0;
3409 B43legacy_WARN_ON(cnt
>= B43legacy_MAX_PHYHWMODES
);
3410 mode
= &phy
->hwmodes
[cnt
];
3412 mode
->mode
= MODE_IEEE80211B
;
3413 mode
->num_channels
= b43legacy_bg_chantable_size
;
3414 mode
->channels
= b43legacy_bg_chantable
;
3415 mode
->num_rates
= b43legacy_b_ratetable_size
;
3416 mode
->rates
= b43legacy_b_ratetable
;
3417 err
= ieee80211_register_hwmode(hw
, mode
);
3421 phy
->possible_phymodes
|= B43legacy_PHYMODE_B
;
3426 B43legacy_WARN_ON(cnt
>= B43legacy_MAX_PHYHWMODES
);
3427 mode
= &phy
->hwmodes
[cnt
];
3429 mode
->mode
= MODE_IEEE80211G
;
3430 mode
->num_channels
= b43legacy_bg_chantable_size
;
3431 mode
->channels
= b43legacy_bg_chantable
;
3432 mode
->num_rates
= b43legacy_g_ratetable_size
;
3433 mode
->rates
= b43legacy_g_ratetable
;
3434 err
= ieee80211_register_hwmode(hw
, mode
);
3438 phy
->possible_phymodes
|= B43legacy_PHYMODE_G
;
3448 static void b43legacy_wireless_core_detach(struct b43legacy_wldev
*dev
)
3450 /* We release firmware that late to not be required to re-request
3451 * is all the time when we reinit the core. */
3452 b43legacy_release_firmware(dev
);
3455 static int b43legacy_wireless_core_attach(struct b43legacy_wldev
*dev
)
3457 struct b43legacy_wl
*wl
= dev
->wl
;
3458 struct ssb_bus
*bus
= dev
->dev
->bus
;
3459 struct pci_dev
*pdev
= bus
->host_pci
;
3465 /* Do NOT do any device initialization here.
3466 * Do it in wireless_core_init() instead.
3467 * This function is for gathering basic information about the HW, only.
3468 * Also some structs may be set up here. But most likely you want to
3469 * have that in core_init(), too.
3472 err
= ssb_bus_powerup(bus
, 0);
3474 b43legacyerr(wl
, "Bus powerup failed\n");
3477 /* Get the PHY type. */
3478 if (dev
->dev
->id
.revision
>= 5) {
3481 tmshigh
= ssb_read32(dev
->dev
, SSB_TMSHIGH
);
3482 have_gphy
= !!(tmshigh
& B43legacy_TMSHIGH_GPHY
);
3485 } else if (dev
->dev
->id
.revision
== 4)
3490 dev
->phy
.gmode
= (have_gphy
|| have_bphy
);
3491 tmp
= dev
->phy
.gmode
? B43legacy_TMSLOW_GMODE
: 0;
3492 b43legacy_wireless_core_reset(dev
, tmp
);
3494 err
= b43legacy_phy_versioning(dev
);
3497 /* Check if this device supports multiband. */
3499 (pdev
->device
!= 0x4312 &&
3500 pdev
->device
!= 0x4319 &&
3501 pdev
->device
!= 0x4324)) {
3502 /* No multiband support. */
3505 switch (dev
->phy
.type
) {
3506 case B43legacy_PHYTYPE_B
:
3509 case B43legacy_PHYTYPE_G
:
3513 B43legacy_BUG_ON(1);
3516 dev
->phy
.gmode
= (have_gphy
|| have_bphy
);
3517 tmp
= dev
->phy
.gmode
? B43legacy_TMSLOW_GMODE
: 0;
3518 b43legacy_wireless_core_reset(dev
, tmp
);
3520 err
= b43legacy_validate_chipaccess(dev
);
3523 err
= b43legacy_setup_modes(dev
, have_bphy
, have_gphy
);
3527 /* Now set some default "current_dev" */
3528 if (!wl
->current_dev
)
3529 wl
->current_dev
= dev
;
3530 INIT_WORK(&dev
->restart_work
, b43legacy_chip_reset
);
3532 b43legacy_radio_turn_off(dev
, 1);
3533 b43legacy_switch_analog(dev
, 0);
3534 ssb_device_disable(dev
->dev
, 0);
3535 ssb_bus_may_powerdown(bus
);
3541 ssb_bus_may_powerdown(bus
);
3545 static void b43legacy_one_core_detach(struct ssb_device
*dev
)
3547 struct b43legacy_wldev
*wldev
;
3548 struct b43legacy_wl
*wl
;
3550 wldev
= ssb_get_drvdata(dev
);
3552 cancel_work_sync(&wldev
->restart_work
);
3553 b43legacy_debugfs_remove_device(wldev
);
3554 b43legacy_wireless_core_detach(wldev
);
3555 list_del(&wldev
->list
);
3557 ssb_set_drvdata(dev
, NULL
);
3561 static int b43legacy_one_core_attach(struct ssb_device
*dev
,
3562 struct b43legacy_wl
*wl
)
3564 struct b43legacy_wldev
*wldev
;
3565 struct pci_dev
*pdev
;
3568 if (!list_empty(&wl
->devlist
)) {
3569 /* We are not the first core on this chip. */
3570 pdev
= dev
->bus
->host_pci
;
3571 /* Only special chips support more than one wireless
3572 * core, although some of the other chips have more than
3573 * one wireless core as well. Check for this and
3577 ((pdev
->device
!= 0x4321) &&
3578 (pdev
->device
!= 0x4313) &&
3579 (pdev
->device
!= 0x431A))) {
3580 b43legacydbg(wl
, "Ignoring unconnected 802.11 core\n");
3585 wldev
= kzalloc(sizeof(*wldev
), GFP_KERNEL
);
3591 b43legacy_set_status(wldev
, B43legacy_STAT_UNINIT
);
3592 wldev
->bad_frames_preempt
= modparam_bad_frames_preempt
;
3593 tasklet_init(&wldev
->isr_tasklet
,
3594 (void (*)(unsigned long))b43legacy_interrupt_tasklet
,
3595 (unsigned long)wldev
);
3597 wldev
->__using_pio
= 1;
3598 INIT_LIST_HEAD(&wldev
->list
);
3600 err
= b43legacy_wireless_core_attach(wldev
);
3602 goto err_kfree_wldev
;
3604 list_add(&wldev
->list
, &wl
->devlist
);
3606 ssb_set_drvdata(dev
, wldev
);
3607 b43legacy_debugfs_add_device(wldev
);
3616 static void b43legacy_sprom_fixup(struct ssb_bus
*bus
)
3618 /* boardflags workarounds */
3619 if (bus
->boardinfo
.vendor
== PCI_VENDOR_ID_APPLE
&&
3620 bus
->boardinfo
.type
== 0x4E &&
3621 bus
->boardinfo
.rev
> 0x40)
3622 bus
->sprom
.boardflags_lo
|= B43legacy_BFL_PACTRL
;
3625 static void b43legacy_wireless_exit(struct ssb_device
*dev
,
3626 struct b43legacy_wl
*wl
)
3628 struct ieee80211_hw
*hw
= wl
->hw
;
3630 ssb_set_devtypedata(dev
, NULL
);
3631 ieee80211_free_hw(hw
);
3634 static int b43legacy_wireless_init(struct ssb_device
*dev
)
3636 struct ssb_sprom
*sprom
= &dev
->bus
->sprom
;
3637 struct ieee80211_hw
*hw
;
3638 struct b43legacy_wl
*wl
;
3641 b43legacy_sprom_fixup(dev
->bus
);
3643 hw
= ieee80211_alloc_hw(sizeof(*wl
), &b43legacy_hw_ops
);
3645 b43legacyerr(NULL
, "Could not allocate ieee80211 device\n");
3650 hw
->flags
= IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE
|
3651 IEEE80211_HW_RX_INCLUDES_FCS
;
3652 hw
->max_signal
= 100;
3653 hw
->max_rssi
= -110;
3654 hw
->max_noise
= -110;
3655 hw
->queues
= 1; /* FIXME: hardware has more queues */
3656 SET_IEEE80211_DEV(hw
, dev
->dev
);
3657 if (is_valid_ether_addr(sprom
->et1mac
))
3658 SET_IEEE80211_PERM_ADDR(hw
, sprom
->et1mac
);
3660 SET_IEEE80211_PERM_ADDR(hw
, sprom
->il0mac
);
3662 /* Get and initialize struct b43legacy_wl */
3663 wl
= hw_to_b43legacy_wl(hw
);
3664 memset(wl
, 0, sizeof(*wl
));
3666 spin_lock_init(&wl
->irq_lock
);
3667 spin_lock_init(&wl
->leds_lock
);
3668 mutex_init(&wl
->mutex
);
3669 INIT_LIST_HEAD(&wl
->devlist
);
3671 ssb_set_devtypedata(dev
, wl
);
3672 b43legacyinfo(wl
, "Broadcom %04X WLAN found\n", dev
->bus
->chip_id
);
3678 static int b43legacy_probe(struct ssb_device
*dev
,
3679 const struct ssb_device_id
*id
)
3681 struct b43legacy_wl
*wl
;
3685 wl
= ssb_get_devtypedata(dev
);
3687 /* Probing the first core - setup common struct b43legacy_wl */
3689 err
= b43legacy_wireless_init(dev
);
3692 wl
= ssb_get_devtypedata(dev
);
3693 B43legacy_WARN_ON(!wl
);
3695 err
= b43legacy_one_core_attach(dev
, wl
);
3697 goto err_wireless_exit
;
3700 err
= ieee80211_register_hw(wl
->hw
);
3702 goto err_one_core_detach
;
3708 err_one_core_detach
:
3709 b43legacy_one_core_detach(dev
);
3712 b43legacy_wireless_exit(dev
, wl
);
3716 static void b43legacy_remove(struct ssb_device
*dev
)
3718 struct b43legacy_wl
*wl
= ssb_get_devtypedata(dev
);
3719 struct b43legacy_wldev
*wldev
= ssb_get_drvdata(dev
);
3721 B43legacy_WARN_ON(!wl
);
3722 if (wl
->current_dev
== wldev
)
3723 ieee80211_unregister_hw(wl
->hw
);
3725 b43legacy_one_core_detach(dev
);
3727 if (list_empty(&wl
->devlist
))
3728 /* Last core on the chip unregistered.
3729 * We can destroy common struct b43legacy_wl.
3731 b43legacy_wireless_exit(dev
, wl
);
3734 /* Perform a hardware reset. This can be called from any context. */
3735 void b43legacy_controller_restart(struct b43legacy_wldev
*dev
,
3738 /* Must avoid requeueing, if we are in shutdown. */
3739 if (b43legacy_status(dev
) < B43legacy_STAT_INITIALIZED
)
3741 b43legacyinfo(dev
->wl
, "Controller RESET (%s) ...\n", reason
);
3742 queue_work(dev
->wl
->hw
->workqueue
, &dev
->restart_work
);
3747 static int b43legacy_suspend(struct ssb_device
*dev
, pm_message_t state
)
3749 struct b43legacy_wldev
*wldev
= ssb_get_drvdata(dev
);
3750 struct b43legacy_wl
*wl
= wldev
->wl
;
3752 b43legacydbg(wl
, "Suspending...\n");
3754 mutex_lock(&wl
->mutex
);
3755 wldev
->suspend_init_status
= b43legacy_status(wldev
);
3756 if (wldev
->suspend_init_status
>= B43legacy_STAT_STARTED
)
3757 b43legacy_wireless_core_stop(wldev
);
3758 if (wldev
->suspend_init_status
>= B43legacy_STAT_INITIALIZED
)
3759 b43legacy_wireless_core_exit(wldev
);
3760 mutex_unlock(&wl
->mutex
);
3762 b43legacydbg(wl
, "Device suspended.\n");
3767 static int b43legacy_resume(struct ssb_device
*dev
)
3769 struct b43legacy_wldev
*wldev
= ssb_get_drvdata(dev
);
3770 struct b43legacy_wl
*wl
= wldev
->wl
;
3773 b43legacydbg(wl
, "Resuming...\n");
3775 mutex_lock(&wl
->mutex
);
3776 if (wldev
->suspend_init_status
>= B43legacy_STAT_INITIALIZED
) {
3777 err
= b43legacy_wireless_core_init(wldev
);
3779 b43legacyerr(wl
, "Resume failed at core init\n");
3783 if (wldev
->suspend_init_status
>= B43legacy_STAT_STARTED
) {
3784 err
= b43legacy_wireless_core_start(wldev
);
3786 b43legacy_wireless_core_exit(wldev
);
3787 b43legacyerr(wl
, "Resume failed at core start\n");
3791 mutex_unlock(&wl
->mutex
);
3793 b43legacydbg(wl
, "Device resumed.\n");
3798 #else /* CONFIG_PM */
3799 # define b43legacy_suspend NULL
3800 # define b43legacy_resume NULL
3801 #endif /* CONFIG_PM */
3803 static struct ssb_driver b43legacy_ssb_driver
= {
3804 .name
= KBUILD_MODNAME
,
3805 .id_table
= b43legacy_ssb_tbl
,
3806 .probe
= b43legacy_probe
,
3807 .remove
= b43legacy_remove
,
3808 .suspend
= b43legacy_suspend
,
3809 .resume
= b43legacy_resume
,
3812 static void b43legacy_print_driverinfo(void)
3814 const char *feat_pci
= "", *feat_leds
= "", *feat_rfkill
= "",
3815 *feat_pio
= "", *feat_dma
= "";
3817 #ifdef CONFIG_B43LEGACY_PCI_AUTOSELECT
3820 #ifdef CONFIG_B43LEGACY_LEDS
3823 #ifdef CONFIG_B43LEGACY_RFKILL
3826 #ifdef CONFIG_B43LEGACY_PIO
3829 #ifdef CONFIG_B43LEGACY_DMA
3832 printk(KERN_INFO
"Broadcom 43xx-legacy driver loaded "
3833 "[ Features: %s%s%s%s%s, Firmware-ID: "
3834 B43legacy_SUPPORTED_FIRMWARE_ID
" ]\n",
3835 feat_pci
, feat_leds
, feat_rfkill
, feat_pio
, feat_dma
);
3838 static int __init
b43legacy_init(void)
3842 b43legacy_debugfs_init();
3844 err
= ssb_driver_register(&b43legacy_ssb_driver
);
3848 b43legacy_print_driverinfo();
3853 b43legacy_debugfs_exit();
3857 static void __exit
b43legacy_exit(void)
3859 ssb_driver_unregister(&b43legacy_ssb_driver
);
3860 b43legacy_debugfs_exit();
3863 module_init(b43legacy_init
)
3864 module_exit(b43legacy_exit
)