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 <m@bues.ch>
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/module.h>
35 #include <linux/if_arp.h>
36 #include <linux/etherdevice.h>
37 #include <linux/firmware.h>
38 #include <linux/workqueue.h>
39 #include <linux/sched.h>
40 #include <linux/skbuff.h>
41 #include <linux/dma-mapping.h>
42 #include <linux/slab.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/ucode2.fw");
64 MODULE_FIRMWARE("b43legacy/ucode4.fw");
66 #if defined(CONFIG_B43LEGACY_DMA) && defined(CONFIG_B43LEGACY_PIO)
67 static int modparam_pio
;
68 module_param_named(pio
, modparam_pio
, int, 0444);
69 MODULE_PARM_DESC(pio
, "enable(1) / disable(0) PIO mode");
70 #elif defined(CONFIG_B43LEGACY_DMA)
71 # define modparam_pio 0
72 #elif defined(CONFIG_B43LEGACY_PIO)
73 # define modparam_pio 1
76 static int modparam_bad_frames_preempt
;
77 module_param_named(bad_frames_preempt
, modparam_bad_frames_preempt
, int, 0444);
78 MODULE_PARM_DESC(bad_frames_preempt
, "enable(1) / disable(0) Bad Frames"
81 static char modparam_fwpostfix
[16];
82 module_param_string(fwpostfix
, modparam_fwpostfix
, 16, 0444);
83 MODULE_PARM_DESC(fwpostfix
, "Postfix for the firmware files to load.");
85 /* The following table supports BCM4301, BCM4303 and BCM4306/2 devices. */
86 static const struct ssb_device_id b43legacy_ssb_tbl
[] = {
87 SSB_DEVICE(SSB_VENDOR_BROADCOM
, SSB_DEV_80211
, 2),
88 SSB_DEVICE(SSB_VENDOR_BROADCOM
, SSB_DEV_80211
, 4),
91 MODULE_DEVICE_TABLE(ssb
, b43legacy_ssb_tbl
);
94 /* Channel and ratetables are shared for all devices.
95 * They can't be const, because ieee80211 puts some precalculated
96 * data in there. This data is the same for all devices, so we don't
97 * get concurrency issues */
98 #define RATETAB_ENT(_rateid, _flags) \
100 .bitrate = B43legacy_RATE_TO_100KBPS(_rateid), \
101 .hw_value = (_rateid), \
105 * NOTE: When changing this, sync with xmit.c's
106 * b43legacy_plcp_get_bitrate_idx_* functions!
108 static struct ieee80211_rate __b43legacy_ratetable
[] = {
109 RATETAB_ENT(B43legacy_CCK_RATE_1MB
, 0),
110 RATETAB_ENT(B43legacy_CCK_RATE_2MB
, IEEE80211_RATE_SHORT_PREAMBLE
),
111 RATETAB_ENT(B43legacy_CCK_RATE_5MB
, IEEE80211_RATE_SHORT_PREAMBLE
),
112 RATETAB_ENT(B43legacy_CCK_RATE_11MB
, IEEE80211_RATE_SHORT_PREAMBLE
),
113 RATETAB_ENT(B43legacy_OFDM_RATE_6MB
, 0),
114 RATETAB_ENT(B43legacy_OFDM_RATE_9MB
, 0),
115 RATETAB_ENT(B43legacy_OFDM_RATE_12MB
, 0),
116 RATETAB_ENT(B43legacy_OFDM_RATE_18MB
, 0),
117 RATETAB_ENT(B43legacy_OFDM_RATE_24MB
, 0),
118 RATETAB_ENT(B43legacy_OFDM_RATE_36MB
, 0),
119 RATETAB_ENT(B43legacy_OFDM_RATE_48MB
, 0),
120 RATETAB_ENT(B43legacy_OFDM_RATE_54MB
, 0),
122 #define b43legacy_b_ratetable (__b43legacy_ratetable + 0)
123 #define b43legacy_b_ratetable_size 4
124 #define b43legacy_g_ratetable (__b43legacy_ratetable + 0)
125 #define b43legacy_g_ratetable_size 12
127 #define CHANTAB_ENT(_chanid, _freq) \
129 .center_freq = (_freq), \
130 .hw_value = (_chanid), \
132 static struct ieee80211_channel b43legacy_bg_chantable
[] = {
133 CHANTAB_ENT(1, 2412),
134 CHANTAB_ENT(2, 2417),
135 CHANTAB_ENT(3, 2422),
136 CHANTAB_ENT(4, 2427),
137 CHANTAB_ENT(5, 2432),
138 CHANTAB_ENT(6, 2437),
139 CHANTAB_ENT(7, 2442),
140 CHANTAB_ENT(8, 2447),
141 CHANTAB_ENT(9, 2452),
142 CHANTAB_ENT(10, 2457),
143 CHANTAB_ENT(11, 2462),
144 CHANTAB_ENT(12, 2467),
145 CHANTAB_ENT(13, 2472),
146 CHANTAB_ENT(14, 2484),
149 static struct ieee80211_supported_band b43legacy_band_2GHz_BPHY
= {
150 .channels
= b43legacy_bg_chantable
,
151 .n_channels
= ARRAY_SIZE(b43legacy_bg_chantable
),
152 .bitrates
= b43legacy_b_ratetable
,
153 .n_bitrates
= b43legacy_b_ratetable_size
,
156 static struct ieee80211_supported_band b43legacy_band_2GHz_GPHY
= {
157 .channels
= b43legacy_bg_chantable
,
158 .n_channels
= ARRAY_SIZE(b43legacy_bg_chantable
),
159 .bitrates
= b43legacy_g_ratetable
,
160 .n_bitrates
= b43legacy_g_ratetable_size
,
163 static void b43legacy_wireless_core_exit(struct b43legacy_wldev
*dev
);
164 static int b43legacy_wireless_core_init(struct b43legacy_wldev
*dev
);
165 static void b43legacy_wireless_core_stop(struct b43legacy_wldev
*dev
);
166 static int b43legacy_wireless_core_start(struct b43legacy_wldev
*dev
);
169 static int b43legacy_ratelimit(struct b43legacy_wl
*wl
)
171 if (!wl
|| !wl
->current_dev
)
173 if (b43legacy_status(wl
->current_dev
) < B43legacy_STAT_STARTED
)
175 /* We are up and running.
176 * Ratelimit the messages to avoid DoS over the net. */
177 return net_ratelimit();
180 void b43legacyinfo(struct b43legacy_wl
*wl
, const char *fmt
, ...)
182 struct va_format vaf
;
185 if (!b43legacy_ratelimit(wl
))
193 printk(KERN_INFO
"b43legacy-%s: %pV",
194 (wl
&& wl
->hw
) ? wiphy_name(wl
->hw
->wiphy
) : "wlan", &vaf
);
199 void b43legacyerr(struct b43legacy_wl
*wl
, const char *fmt
, ...)
201 struct va_format vaf
;
204 if (!b43legacy_ratelimit(wl
))
212 printk(KERN_ERR
"b43legacy-%s ERROR: %pV",
213 (wl
&& wl
->hw
) ? wiphy_name(wl
->hw
->wiphy
) : "wlan", &vaf
);
218 void b43legacywarn(struct b43legacy_wl
*wl
, const char *fmt
, ...)
220 struct va_format vaf
;
223 if (!b43legacy_ratelimit(wl
))
231 printk(KERN_WARNING
"b43legacy-%s warning: %pV",
232 (wl
&& wl
->hw
) ? wiphy_name(wl
->hw
->wiphy
) : "wlan", &vaf
);
238 void b43legacydbg(struct b43legacy_wl
*wl
, const char *fmt
, ...)
240 struct va_format vaf
;
248 printk(KERN_DEBUG
"b43legacy-%s debug: %pV",
249 (wl
&& wl
->hw
) ? wiphy_name(wl
->hw
->wiphy
) : "wlan", &vaf
);
255 static void b43legacy_ram_write(struct b43legacy_wldev
*dev
, u16 offset
,
260 B43legacy_WARN_ON(offset
% 4 != 0);
262 status
= b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
263 if (status
& B43legacy_MACCTL_BE
)
266 b43legacy_write32(dev
, B43legacy_MMIO_RAM_CONTROL
, offset
);
268 b43legacy_write32(dev
, B43legacy_MMIO_RAM_DATA
, val
);
272 void b43legacy_shm_control_word(struct b43legacy_wldev
*dev
,
273 u16 routing
, u16 offset
)
277 /* "offset" is the WORD offset. */
282 b43legacy_write32(dev
, B43legacy_MMIO_SHM_CONTROL
, control
);
285 u32
b43legacy_shm_read32(struct b43legacy_wldev
*dev
,
286 u16 routing
, u16 offset
)
290 if (routing
== B43legacy_SHM_SHARED
) {
291 B43legacy_WARN_ON((offset
& 0x0001) != 0);
292 if (offset
& 0x0003) {
293 /* Unaligned access */
294 b43legacy_shm_control_word(dev
, routing
, offset
>> 2);
295 ret
= b43legacy_read16(dev
,
296 B43legacy_MMIO_SHM_DATA_UNALIGNED
);
298 b43legacy_shm_control_word(dev
, routing
,
300 ret
|= b43legacy_read16(dev
, B43legacy_MMIO_SHM_DATA
);
306 b43legacy_shm_control_word(dev
, routing
, offset
);
307 ret
= b43legacy_read32(dev
, B43legacy_MMIO_SHM_DATA
);
312 u16
b43legacy_shm_read16(struct b43legacy_wldev
*dev
,
313 u16 routing
, u16 offset
)
317 if (routing
== B43legacy_SHM_SHARED
) {
318 B43legacy_WARN_ON((offset
& 0x0001) != 0);
319 if (offset
& 0x0003) {
320 /* Unaligned access */
321 b43legacy_shm_control_word(dev
, routing
, offset
>> 2);
322 ret
= b43legacy_read16(dev
,
323 B43legacy_MMIO_SHM_DATA_UNALIGNED
);
329 b43legacy_shm_control_word(dev
, routing
, offset
);
330 ret
= b43legacy_read16(dev
, B43legacy_MMIO_SHM_DATA
);
335 void b43legacy_shm_write32(struct b43legacy_wldev
*dev
,
336 u16 routing
, u16 offset
,
339 if (routing
== B43legacy_SHM_SHARED
) {
340 B43legacy_WARN_ON((offset
& 0x0001) != 0);
341 if (offset
& 0x0003) {
342 /* Unaligned access */
343 b43legacy_shm_control_word(dev
, routing
, offset
>> 2);
345 b43legacy_write16(dev
,
346 B43legacy_MMIO_SHM_DATA_UNALIGNED
,
347 (value
>> 16) & 0xffff);
349 b43legacy_shm_control_word(dev
, routing
,
352 b43legacy_write16(dev
, B43legacy_MMIO_SHM_DATA
,
358 b43legacy_shm_control_word(dev
, routing
, offset
);
360 b43legacy_write32(dev
, B43legacy_MMIO_SHM_DATA
, value
);
363 void b43legacy_shm_write16(struct b43legacy_wldev
*dev
, u16 routing
, u16 offset
,
366 if (routing
== B43legacy_SHM_SHARED
) {
367 B43legacy_WARN_ON((offset
& 0x0001) != 0);
368 if (offset
& 0x0003) {
369 /* Unaligned access */
370 b43legacy_shm_control_word(dev
, routing
, offset
>> 2);
372 b43legacy_write16(dev
,
373 B43legacy_MMIO_SHM_DATA_UNALIGNED
,
379 b43legacy_shm_control_word(dev
, routing
, offset
);
381 b43legacy_write16(dev
, B43legacy_MMIO_SHM_DATA
, value
);
385 u32
b43legacy_hf_read(struct b43legacy_wldev
*dev
)
389 ret
= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
,
390 B43legacy_SHM_SH_HOSTFHI
);
392 ret
|= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
,
393 B43legacy_SHM_SH_HOSTFLO
);
398 /* Write HostFlags */
399 void b43legacy_hf_write(struct b43legacy_wldev
*dev
, u32 value
)
401 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
,
402 B43legacy_SHM_SH_HOSTFLO
,
403 (value
& 0x0000FFFF));
404 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
,
405 B43legacy_SHM_SH_HOSTFHI
,
406 ((value
& 0xFFFF0000) >> 16));
409 void b43legacy_tsf_read(struct b43legacy_wldev
*dev
, u64
*tsf
)
411 /* We need to be careful. As we read the TSF from multiple
412 * registers, we should take care of register overflows.
413 * In theory, the whole tsf read process should be atomic.
414 * We try to be atomic here, by restaring the read process,
415 * if any of the high registers changed (overflew).
417 if (dev
->dev
->id
.revision
>= 3) {
423 high
= b43legacy_read32(dev
,
424 B43legacy_MMIO_REV3PLUS_TSF_HIGH
);
425 low
= b43legacy_read32(dev
,
426 B43legacy_MMIO_REV3PLUS_TSF_LOW
);
427 high2
= b43legacy_read32(dev
,
428 B43legacy_MMIO_REV3PLUS_TSF_HIGH
);
429 } while (unlikely(high
!= high2
));
445 v3
= b43legacy_read16(dev
, B43legacy_MMIO_TSF_3
);
446 v2
= b43legacy_read16(dev
, B43legacy_MMIO_TSF_2
);
447 v1
= b43legacy_read16(dev
, B43legacy_MMIO_TSF_1
);
448 v0
= b43legacy_read16(dev
, B43legacy_MMIO_TSF_0
);
450 test3
= b43legacy_read16(dev
, B43legacy_MMIO_TSF_3
);
451 test2
= b43legacy_read16(dev
, B43legacy_MMIO_TSF_2
);
452 test1
= b43legacy_read16(dev
, B43legacy_MMIO_TSF_1
);
453 } while (v3
!= test3
|| v2
!= test2
|| v1
!= test1
);
467 static void b43legacy_time_lock(struct b43legacy_wldev
*dev
)
471 status
= b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
472 status
|= B43legacy_MACCTL_TBTTHOLD
;
473 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
, status
);
477 static void b43legacy_time_unlock(struct b43legacy_wldev
*dev
)
481 status
= b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
482 status
&= ~B43legacy_MACCTL_TBTTHOLD
;
483 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
, status
);
486 static void b43legacy_tsf_write_locked(struct b43legacy_wldev
*dev
, u64 tsf
)
488 /* Be careful with the in-progress timer.
489 * First zero out the low register, so we have a full
490 * register-overflow duration to complete the operation.
492 if (dev
->dev
->id
.revision
>= 3) {
493 u32 lo
= (tsf
& 0x00000000FFFFFFFFULL
);
494 u32 hi
= (tsf
& 0xFFFFFFFF00000000ULL
) >> 32;
496 b43legacy_write32(dev
, B43legacy_MMIO_REV3PLUS_TSF_LOW
, 0);
498 b43legacy_write32(dev
, B43legacy_MMIO_REV3PLUS_TSF_HIGH
,
501 b43legacy_write32(dev
, B43legacy_MMIO_REV3PLUS_TSF_LOW
,
504 u16 v0
= (tsf
& 0x000000000000FFFFULL
);
505 u16 v1
= (tsf
& 0x00000000FFFF0000ULL
) >> 16;
506 u16 v2
= (tsf
& 0x0000FFFF00000000ULL
) >> 32;
507 u16 v3
= (tsf
& 0xFFFF000000000000ULL
) >> 48;
509 b43legacy_write16(dev
, B43legacy_MMIO_TSF_0
, 0);
511 b43legacy_write16(dev
, B43legacy_MMIO_TSF_3
, v3
);
513 b43legacy_write16(dev
, B43legacy_MMIO_TSF_2
, v2
);
515 b43legacy_write16(dev
, B43legacy_MMIO_TSF_1
, v1
);
517 b43legacy_write16(dev
, B43legacy_MMIO_TSF_0
, v0
);
521 void b43legacy_tsf_write(struct b43legacy_wldev
*dev
, u64 tsf
)
523 b43legacy_time_lock(dev
);
524 b43legacy_tsf_write_locked(dev
, tsf
);
525 b43legacy_time_unlock(dev
);
529 void b43legacy_macfilter_set(struct b43legacy_wldev
*dev
,
530 u16 offset
, const u8
*mac
)
532 static const u8 zero_addr
[ETH_ALEN
] = { 0 };
539 b43legacy_write16(dev
, B43legacy_MMIO_MACFILTER_CONTROL
, offset
);
543 b43legacy_write16(dev
, B43legacy_MMIO_MACFILTER_DATA
, data
);
546 b43legacy_write16(dev
, B43legacy_MMIO_MACFILTER_DATA
, data
);
549 b43legacy_write16(dev
, B43legacy_MMIO_MACFILTER_DATA
, data
);
552 static void b43legacy_write_mac_bssid_templates(struct b43legacy_wldev
*dev
)
554 static const u8 zero_addr
[ETH_ALEN
] = { 0 };
555 const u8
*mac
= dev
->wl
->mac_addr
;
556 const u8
*bssid
= dev
->wl
->bssid
;
557 u8 mac_bssid
[ETH_ALEN
* 2];
566 b43legacy_macfilter_set(dev
, B43legacy_MACFILTER_BSSID
, bssid
);
568 memcpy(mac_bssid
, mac
, ETH_ALEN
);
569 memcpy(mac_bssid
+ ETH_ALEN
, bssid
, ETH_ALEN
);
571 /* Write our MAC address and BSSID to template ram */
572 for (i
= 0; i
< ARRAY_SIZE(mac_bssid
); i
+= sizeof(u32
)) {
573 tmp
= (u32
)(mac_bssid
[i
+ 0]);
574 tmp
|= (u32
)(mac_bssid
[i
+ 1]) << 8;
575 tmp
|= (u32
)(mac_bssid
[i
+ 2]) << 16;
576 tmp
|= (u32
)(mac_bssid
[i
+ 3]) << 24;
577 b43legacy_ram_write(dev
, 0x20 + i
, tmp
);
578 b43legacy_ram_write(dev
, 0x78 + i
, tmp
);
579 b43legacy_ram_write(dev
, 0x478 + i
, tmp
);
583 static void b43legacy_upload_card_macaddress(struct b43legacy_wldev
*dev
)
585 b43legacy_write_mac_bssid_templates(dev
);
586 b43legacy_macfilter_set(dev
, B43legacy_MACFILTER_SELF
,
590 static void b43legacy_set_slot_time(struct b43legacy_wldev
*dev
,
593 /* slot_time is in usec. */
594 if (dev
->phy
.type
!= B43legacy_PHYTYPE_G
)
596 b43legacy_write16(dev
, 0x684, 510 + slot_time
);
597 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
, 0x0010,
601 static void b43legacy_short_slot_timing_enable(struct b43legacy_wldev
*dev
)
603 b43legacy_set_slot_time(dev
, 9);
606 static void b43legacy_short_slot_timing_disable(struct b43legacy_wldev
*dev
)
608 b43legacy_set_slot_time(dev
, 20);
611 /* Synchronize IRQ top- and bottom-half.
612 * IRQs must be masked before calling this.
613 * This must not be called with the irq_lock held.
615 static void b43legacy_synchronize_irq(struct b43legacy_wldev
*dev
)
617 synchronize_irq(dev
->dev
->irq
);
618 tasklet_kill(&dev
->isr_tasklet
);
621 /* DummyTransmission function, as documented on
622 * http://bcm-specs.sipsolutions.net/DummyTransmission
624 void b43legacy_dummy_transmission(struct b43legacy_wldev
*dev
)
626 struct b43legacy_phy
*phy
= &dev
->phy
;
628 unsigned int max_loop
;
639 case B43legacy_PHYTYPE_B
:
640 case B43legacy_PHYTYPE_G
:
642 buffer
[0] = 0x000B846E;
649 for (i
= 0; i
< 5; i
++)
650 b43legacy_ram_write(dev
, i
* 4, buffer
[i
]);
652 /* dummy read follows */
653 b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
655 b43legacy_write16(dev
, 0x0568, 0x0000);
656 b43legacy_write16(dev
, 0x07C0, 0x0000);
657 b43legacy_write16(dev
, 0x050C, 0x0000);
658 b43legacy_write16(dev
, 0x0508, 0x0000);
659 b43legacy_write16(dev
, 0x050A, 0x0000);
660 b43legacy_write16(dev
, 0x054C, 0x0000);
661 b43legacy_write16(dev
, 0x056A, 0x0014);
662 b43legacy_write16(dev
, 0x0568, 0x0826);
663 b43legacy_write16(dev
, 0x0500, 0x0000);
664 b43legacy_write16(dev
, 0x0502, 0x0030);
666 if (phy
->radio_ver
== 0x2050 && phy
->radio_rev
<= 0x5)
667 b43legacy_radio_write16(dev
, 0x0051, 0x0017);
668 for (i
= 0x00; i
< max_loop
; i
++) {
669 value
= b43legacy_read16(dev
, 0x050E);
674 for (i
= 0x00; i
< 0x0A; i
++) {
675 value
= b43legacy_read16(dev
, 0x050E);
680 for (i
= 0x00; i
< 0x0A; i
++) {
681 value
= b43legacy_read16(dev
, 0x0690);
682 if (!(value
& 0x0100))
686 if (phy
->radio_ver
== 0x2050 && phy
->radio_rev
<= 0x5)
687 b43legacy_radio_write16(dev
, 0x0051, 0x0037);
690 /* Turn the Analog ON/OFF */
691 static void b43legacy_switch_analog(struct b43legacy_wldev
*dev
, int on
)
693 b43legacy_write16(dev
, B43legacy_MMIO_PHY0
, on
? 0 : 0xF4);
696 void b43legacy_wireless_core_reset(struct b43legacy_wldev
*dev
, u32 flags
)
701 flags
|= B43legacy_TMSLOW_PHYCLKEN
;
702 flags
|= B43legacy_TMSLOW_PHYRESET
;
703 ssb_device_enable(dev
->dev
, flags
);
704 msleep(2); /* Wait for the PLL to turn on. */
706 /* Now take the PHY out of Reset again */
707 tmslow
= ssb_read32(dev
->dev
, SSB_TMSLOW
);
708 tmslow
|= SSB_TMSLOW_FGC
;
709 tmslow
&= ~B43legacy_TMSLOW_PHYRESET
;
710 ssb_write32(dev
->dev
, SSB_TMSLOW
, tmslow
);
711 ssb_read32(dev
->dev
, SSB_TMSLOW
); /* flush */
713 tmslow
&= ~SSB_TMSLOW_FGC
;
714 ssb_write32(dev
->dev
, SSB_TMSLOW
, tmslow
);
715 ssb_read32(dev
->dev
, SSB_TMSLOW
); /* flush */
719 b43legacy_switch_analog(dev
, 1);
721 macctl
= b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
722 macctl
&= ~B43legacy_MACCTL_GMODE
;
723 if (flags
& B43legacy_TMSLOW_GMODE
) {
724 macctl
|= B43legacy_MACCTL_GMODE
;
725 dev
->phy
.gmode
= true;
727 dev
->phy
.gmode
= false;
728 macctl
|= B43legacy_MACCTL_IHR_ENABLED
;
729 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
, macctl
);
732 static void handle_irq_transmit_status(struct b43legacy_wldev
*dev
)
737 struct b43legacy_txstatus stat
;
740 v0
= b43legacy_read32(dev
, B43legacy_MMIO_XMITSTAT_0
);
741 if (!(v0
& 0x00000001))
743 v1
= b43legacy_read32(dev
, B43legacy_MMIO_XMITSTAT_1
);
745 stat
.cookie
= (v0
>> 16);
746 stat
.seq
= (v1
& 0x0000FFFF);
747 stat
.phy_stat
= ((v1
& 0x00FF0000) >> 16);
748 tmp
= (v0
& 0x0000FFFF);
749 stat
.frame_count
= ((tmp
& 0xF000) >> 12);
750 stat
.rts_count
= ((tmp
& 0x0F00) >> 8);
751 stat
.supp_reason
= ((tmp
& 0x001C) >> 2);
752 stat
.pm_indicated
= !!(tmp
& 0x0080);
753 stat
.intermediate
= !!(tmp
& 0x0040);
754 stat
.for_ampdu
= !!(tmp
& 0x0020);
755 stat
.acked
= !!(tmp
& 0x0002);
757 b43legacy_handle_txstatus(dev
, &stat
);
761 static void drain_txstatus_queue(struct b43legacy_wldev
*dev
)
765 if (dev
->dev
->id
.revision
< 5)
767 /* Read all entries from the microcode TXstatus FIFO
768 * and throw them away.
771 dummy
= b43legacy_read32(dev
, B43legacy_MMIO_XMITSTAT_0
);
772 if (!(dummy
& 0x00000001))
774 dummy
= b43legacy_read32(dev
, B43legacy_MMIO_XMITSTAT_1
);
778 static u32
b43legacy_jssi_read(struct b43legacy_wldev
*dev
)
782 val
= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
, 0x40A);
784 val
|= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
, 0x408);
789 static void b43legacy_jssi_write(struct b43legacy_wldev
*dev
, u32 jssi
)
791 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
, 0x408,
792 (jssi
& 0x0000FFFF));
793 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
, 0x40A,
794 (jssi
& 0xFFFF0000) >> 16);
797 static void b43legacy_generate_noise_sample(struct b43legacy_wldev
*dev
)
799 b43legacy_jssi_write(dev
, 0x7F7F7F7F);
800 b43legacy_write32(dev
, B43legacy_MMIO_MACCMD
,
801 b43legacy_read32(dev
, B43legacy_MMIO_MACCMD
)
802 | B43legacy_MACCMD_BGNOISE
);
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
= true;
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] = clamp_val(noise
[0], 0, ARRAY_SIZE(phy
->nrssi_lt
) - 1);
843 noise
[1] = clamp_val(noise
[1], 0, ARRAY_SIZE(phy
->nrssi_lt
) - 1);
844 noise
[2] = clamp_val(noise
[2], 0, ARRAY_SIZE(phy
->nrssi_lt
) - 1);
845 noise
[3] = clamp_val(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
= false;
880 b43legacy_generate_noise_sample(dev
);
883 static void handle_irq_tbtt_indication(struct b43legacy_wldev
*dev
)
885 if (b43legacy_is_mode(dev
->wl
, NL80211_IFTYPE_AP
)) {
888 if (1/*FIXME: the last PSpoll frame was sent successfully */)
889 b43legacy_power_saving_ctl_bits(dev
, -1, -1);
891 if (b43legacy_is_mode(dev
->wl
, NL80211_IFTYPE_ADHOC
))
892 dev
->dfq_valid
= true;
895 static void handle_irq_atim_end(struct b43legacy_wldev
*dev
)
897 if (dev
->dfq_valid
) {
898 b43legacy_write32(dev
, B43legacy_MMIO_MACCMD
,
899 b43legacy_read32(dev
, B43legacy_MMIO_MACCMD
)
900 | B43legacy_MACCMD_DFQ_VALID
);
901 dev
->dfq_valid
= false;
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 /* Convert a b43legacy antenna number value to the PHY TX control value. */
955 static u16
b43legacy_antenna_to_phyctl(int antenna
)
958 case B43legacy_ANTENNA0
:
959 return B43legacy_TX4_PHY_ANT0
;
960 case B43legacy_ANTENNA1
:
961 return B43legacy_TX4_PHY_ANT1
;
963 return B43legacy_TX4_PHY_ANTLAST
;
966 static void b43legacy_write_beacon_template(struct b43legacy_wldev
*dev
,
971 unsigned int i
, len
, variable_len
;
972 const struct ieee80211_mgmt
*bcn
;
974 bool tim_found
= false;
978 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(dev
->wl
->current_beacon
);
980 bcn
= (const struct ieee80211_mgmt
*)(dev
->wl
->current_beacon
->data
);
981 len
= min((size_t)dev
->wl
->current_beacon
->len
,
982 0x200 - sizeof(struct b43legacy_plcp_hdr6
));
983 rate
= ieee80211_get_tx_rate(dev
->wl
->hw
, info
)->hw_value
;
985 b43legacy_write_template_common(dev
, (const u8
*)bcn
, len
, ram_offset
,
986 shm_size_offset
, rate
);
988 /* Write the PHY TX control parameters. */
989 antenna
= B43legacy_ANTENNA_DEFAULT
;
990 antenna
= b43legacy_antenna_to_phyctl(antenna
);
991 ctl
= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
,
992 B43legacy_SHM_SH_BEACPHYCTL
);
993 /* We can't send beacons with short preamble. Would get PHY errors. */
994 ctl
&= ~B43legacy_TX4_PHY_SHORTPRMBL
;
995 ctl
&= ~B43legacy_TX4_PHY_ANT
;
996 ctl
&= ~B43legacy_TX4_PHY_ENC
;
998 ctl
|= B43legacy_TX4_PHY_ENC_CCK
;
999 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
,
1000 B43legacy_SHM_SH_BEACPHYCTL
, ctl
);
1002 /* Find the position of the TIM and the DTIM_period value
1003 * and write them to SHM. */
1004 ie
= bcn
->u
.beacon
.variable
;
1005 variable_len
= len
- offsetof(struct ieee80211_mgmt
, u
.beacon
.variable
);
1006 for (i
= 0; i
< variable_len
- 2; ) {
1007 uint8_t ie_id
, ie_len
;
1014 /* This is the TIM Information Element */
1016 /* Check whether the ie_len is in the beacon data range. */
1017 if (variable_len
< ie_len
+ 2 + i
)
1019 /* A valid TIM is at least 4 bytes long. */
1024 tim_position
= sizeof(struct b43legacy_plcp_hdr6
);
1025 tim_position
+= offsetof(struct ieee80211_mgmt
,
1029 dtim_period
= ie
[i
+ 3];
1031 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
,
1032 B43legacy_SHM_SH_TIMPOS
, tim_position
);
1033 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
,
1034 B43legacy_SHM_SH_DTIMP
, dtim_period
);
1040 b43legacywarn(dev
->wl
, "Did not find a valid TIM IE in the "
1041 "beacon template packet. AP or IBSS operation "
1042 "may be broken.\n");
1044 b43legacydbg(dev
->wl
, "Updated beacon template\n");
1047 static void b43legacy_write_probe_resp_plcp(struct b43legacy_wldev
*dev
,
1048 u16 shm_offset
, u16 size
,
1049 struct ieee80211_rate
*rate
)
1051 struct b43legacy_plcp_hdr4 plcp
;
1056 b43legacy_generate_plcp_hdr(&plcp
, size
+ FCS_LEN
, rate
->hw_value
);
1057 dur
= ieee80211_generic_frame_duration(dev
->wl
->hw
,
1059 IEEE80211_BAND_2GHZ
,
1062 /* Write PLCP in two parts and timing for packet transfer */
1063 tmp
= le32_to_cpu(plcp
.data
);
1064 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
, shm_offset
,
1066 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
, shm_offset
+ 2,
1068 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
, shm_offset
+ 6,
1072 /* Instead of using custom probe response template, this function
1073 * just patches custom beacon template by:
1074 * 1) Changing packet type
1075 * 2) Patching duration field
1078 static const u8
*b43legacy_generate_probe_resp(struct b43legacy_wldev
*dev
,
1080 struct ieee80211_rate
*rate
)
1084 u16 src_size
, elem_size
, src_pos
, dest_pos
;
1086 struct ieee80211_hdr
*hdr
;
1089 src_size
= dev
->wl
->current_beacon
->len
;
1090 src_data
= (const u8
*)dev
->wl
->current_beacon
->data
;
1092 /* Get the start offset of the variable IEs in the packet. */
1093 ie_start
= offsetof(struct ieee80211_mgmt
, u
.probe_resp
.variable
);
1094 B43legacy_WARN_ON(ie_start
!= offsetof(struct ieee80211_mgmt
,
1095 u
.beacon
.variable
));
1097 if (B43legacy_WARN_ON(src_size
< ie_start
))
1100 dest_data
= kmalloc(src_size
, GFP_ATOMIC
);
1101 if (unlikely(!dest_data
))
1104 /* Copy the static data and all Information Elements, except the TIM. */
1105 memcpy(dest_data
, src_data
, ie_start
);
1107 dest_pos
= ie_start
;
1108 for ( ; src_pos
< src_size
- 2; src_pos
+= elem_size
) {
1109 elem_size
= src_data
[src_pos
+ 1] + 2;
1110 if (src_data
[src_pos
] == 5) {
1111 /* This is the TIM. */
1114 memcpy(dest_data
+ dest_pos
, src_data
+ src_pos
, elem_size
);
1115 dest_pos
+= elem_size
;
1117 *dest_size
= dest_pos
;
1118 hdr
= (struct ieee80211_hdr
*)dest_data
;
1120 /* Set the frame control. */
1121 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
1122 IEEE80211_STYPE_PROBE_RESP
);
1123 dur
= ieee80211_generic_frame_duration(dev
->wl
->hw
,
1125 IEEE80211_BAND_2GHZ
,
1128 hdr
->duration_id
= dur
;
1133 static void b43legacy_write_probe_resp_template(struct b43legacy_wldev
*dev
,
1135 u16 shm_size_offset
,
1136 struct ieee80211_rate
*rate
)
1138 const u8
*probe_resp_data
;
1141 size
= dev
->wl
->current_beacon
->len
;
1142 probe_resp_data
= b43legacy_generate_probe_resp(dev
, &size
, rate
);
1143 if (unlikely(!probe_resp_data
))
1146 /* Looks like PLCP headers plus packet timings are stored for
1147 * all possible basic rates
1149 b43legacy_write_probe_resp_plcp(dev
, 0x31A, size
,
1150 &b43legacy_b_ratetable
[0]);
1151 b43legacy_write_probe_resp_plcp(dev
, 0x32C, size
,
1152 &b43legacy_b_ratetable
[1]);
1153 b43legacy_write_probe_resp_plcp(dev
, 0x33E, size
,
1154 &b43legacy_b_ratetable
[2]);
1155 b43legacy_write_probe_resp_plcp(dev
, 0x350, size
,
1156 &b43legacy_b_ratetable
[3]);
1158 size
= min((size_t)size
,
1159 0x200 - sizeof(struct b43legacy_plcp_hdr6
));
1160 b43legacy_write_template_common(dev
, probe_resp_data
,
1162 shm_size_offset
, rate
->hw_value
);
1163 kfree(probe_resp_data
);
1166 static void b43legacy_upload_beacon0(struct b43legacy_wldev
*dev
)
1168 struct b43legacy_wl
*wl
= dev
->wl
;
1170 if (wl
->beacon0_uploaded
)
1172 b43legacy_write_beacon_template(dev
, 0x68, 0x18);
1173 /* FIXME: Probe resp upload doesn't really belong here,
1174 * but we don't use that feature anyway. */
1175 b43legacy_write_probe_resp_template(dev
, 0x268, 0x4A,
1176 &__b43legacy_ratetable
[3]);
1177 wl
->beacon0_uploaded
= true;
1180 static void b43legacy_upload_beacon1(struct b43legacy_wldev
*dev
)
1182 struct b43legacy_wl
*wl
= dev
->wl
;
1184 if (wl
->beacon1_uploaded
)
1186 b43legacy_write_beacon_template(dev
, 0x468, 0x1A);
1187 wl
->beacon1_uploaded
= true;
1190 static void handle_irq_beacon(struct b43legacy_wldev
*dev
)
1192 struct b43legacy_wl
*wl
= dev
->wl
;
1193 u32 cmd
, beacon0_valid
, beacon1_valid
;
1195 if (!b43legacy_is_mode(wl
, NL80211_IFTYPE_AP
))
1198 /* This is the bottom half of the asynchronous beacon update. */
1200 /* Ignore interrupt in the future. */
1201 dev
->irq_mask
&= ~B43legacy_IRQ_BEACON
;
1203 cmd
= b43legacy_read32(dev
, B43legacy_MMIO_MACCMD
);
1204 beacon0_valid
= (cmd
& B43legacy_MACCMD_BEACON0_VALID
);
1205 beacon1_valid
= (cmd
& B43legacy_MACCMD_BEACON1_VALID
);
1207 /* Schedule interrupt manually, if busy. */
1208 if (beacon0_valid
&& beacon1_valid
) {
1209 b43legacy_write32(dev
, B43legacy_MMIO_GEN_IRQ_REASON
, B43legacy_IRQ_BEACON
);
1210 dev
->irq_mask
|= B43legacy_IRQ_BEACON
;
1214 if (unlikely(wl
->beacon_templates_virgin
)) {
1215 /* We never uploaded a beacon before.
1216 * Upload both templates now, but only mark one valid. */
1217 wl
->beacon_templates_virgin
= false;
1218 b43legacy_upload_beacon0(dev
);
1219 b43legacy_upload_beacon1(dev
);
1220 cmd
= b43legacy_read32(dev
, B43legacy_MMIO_MACCMD
);
1221 cmd
|= B43legacy_MACCMD_BEACON0_VALID
;
1222 b43legacy_write32(dev
, B43legacy_MMIO_MACCMD
, cmd
);
1224 if (!beacon0_valid
) {
1225 b43legacy_upload_beacon0(dev
);
1226 cmd
= b43legacy_read32(dev
, B43legacy_MMIO_MACCMD
);
1227 cmd
|= B43legacy_MACCMD_BEACON0_VALID
;
1228 b43legacy_write32(dev
, B43legacy_MMIO_MACCMD
, cmd
);
1229 } else if (!beacon1_valid
) {
1230 b43legacy_upload_beacon1(dev
);
1231 cmd
= b43legacy_read32(dev
, B43legacy_MMIO_MACCMD
);
1232 cmd
|= B43legacy_MACCMD_BEACON1_VALID
;
1233 b43legacy_write32(dev
, B43legacy_MMIO_MACCMD
, cmd
);
1238 static void b43legacy_beacon_update_trigger_work(struct work_struct
*work
)
1240 struct b43legacy_wl
*wl
= container_of(work
, struct b43legacy_wl
,
1241 beacon_update_trigger
);
1242 struct b43legacy_wldev
*dev
;
1244 mutex_lock(&wl
->mutex
);
1245 dev
= wl
->current_dev
;
1246 if (likely(dev
&& (b43legacy_status(dev
) >= B43legacy_STAT_INITIALIZED
))) {
1247 spin_lock_irq(&wl
->irq_lock
);
1248 /* Update beacon right away or defer to IRQ. */
1249 handle_irq_beacon(dev
);
1250 /* The handler might have updated the IRQ mask. */
1251 b43legacy_write32(dev
, B43legacy_MMIO_GEN_IRQ_MASK
,
1254 spin_unlock_irq(&wl
->irq_lock
);
1256 mutex_unlock(&wl
->mutex
);
1259 /* Asynchronously update the packet templates in template RAM.
1260 * Locking: Requires wl->irq_lock to be locked. */
1261 static void b43legacy_update_templates(struct b43legacy_wl
*wl
)
1263 struct sk_buff
*beacon
;
1264 /* This is the top half of the ansynchronous beacon update. The bottom
1265 * half is the beacon IRQ. Beacon update must be asynchronous to avoid
1266 * sending an invalid beacon. This can happen for example, if the
1267 * firmware transmits a beacon while we are updating it. */
1269 /* We could modify the existing beacon and set the aid bit in the TIM
1270 * field, but that would probably require resizing and moving of data
1271 * within the beacon template. Simply request a new beacon and let
1272 * mac80211 do the hard work. */
1273 beacon
= ieee80211_beacon_get(wl
->hw
, wl
->vif
);
1274 if (unlikely(!beacon
))
1277 if (wl
->current_beacon
)
1278 dev_kfree_skb_any(wl
->current_beacon
);
1279 wl
->current_beacon
= beacon
;
1280 wl
->beacon0_uploaded
= false;
1281 wl
->beacon1_uploaded
= false;
1282 ieee80211_queue_work(wl
->hw
, &wl
->beacon_update_trigger
);
1285 static void b43legacy_set_beacon_int(struct b43legacy_wldev
*dev
,
1288 b43legacy_time_lock(dev
);
1289 if (dev
->dev
->id
.revision
>= 3) {
1290 b43legacy_write32(dev
, B43legacy_MMIO_TSF_CFP_REP
,
1291 (beacon_int
<< 16));
1292 b43legacy_write32(dev
, B43legacy_MMIO_TSF_CFP_START
,
1293 (beacon_int
<< 10));
1295 b43legacy_write16(dev
, 0x606, (beacon_int
>> 6));
1296 b43legacy_write16(dev
, 0x610, beacon_int
);
1298 b43legacy_time_unlock(dev
);
1299 b43legacydbg(dev
->wl
, "Set beacon interval to %u\n", beacon_int
);
1302 static void handle_irq_ucode_debug(struct b43legacy_wldev
*dev
)
1306 /* Interrupt handler bottom-half */
1307 static void b43legacy_interrupt_tasklet(struct b43legacy_wldev
*dev
)
1310 u32 dma_reason
[ARRAY_SIZE(dev
->dma_reason
)];
1311 u32 merged_dma_reason
= 0;
1313 unsigned long flags
;
1315 spin_lock_irqsave(&dev
->wl
->irq_lock
, flags
);
1317 B43legacy_WARN_ON(b43legacy_status(dev
) <
1318 B43legacy_STAT_INITIALIZED
);
1320 reason
= dev
->irq_reason
;
1321 for (i
= 0; i
< ARRAY_SIZE(dma_reason
); i
++) {
1322 dma_reason
[i
] = dev
->dma_reason
[i
];
1323 merged_dma_reason
|= dma_reason
[i
];
1326 if (unlikely(reason
& B43legacy_IRQ_MAC_TXERR
))
1327 b43legacyerr(dev
->wl
, "MAC transmission error\n");
1329 if (unlikely(reason
& B43legacy_IRQ_PHY_TXERR
)) {
1330 b43legacyerr(dev
->wl
, "PHY transmission error\n");
1332 if (unlikely(atomic_dec_and_test(&dev
->phy
.txerr_cnt
))) {
1333 b43legacyerr(dev
->wl
, "Too many PHY TX errors, "
1334 "restarting the controller\n");
1335 b43legacy_controller_restart(dev
, "PHY TX errors");
1339 if (unlikely(merged_dma_reason
& (B43legacy_DMAIRQ_FATALMASK
|
1340 B43legacy_DMAIRQ_NONFATALMASK
))) {
1341 if (merged_dma_reason
& B43legacy_DMAIRQ_FATALMASK
) {
1342 b43legacyerr(dev
->wl
, "Fatal DMA error: "
1343 "0x%08X, 0x%08X, 0x%08X, "
1344 "0x%08X, 0x%08X, 0x%08X\n",
1345 dma_reason
[0], dma_reason
[1],
1346 dma_reason
[2], dma_reason
[3],
1347 dma_reason
[4], dma_reason
[5]);
1348 b43legacy_controller_restart(dev
, "DMA error");
1350 spin_unlock_irqrestore(&dev
->wl
->irq_lock
, flags
);
1353 if (merged_dma_reason
& B43legacy_DMAIRQ_NONFATALMASK
)
1354 b43legacyerr(dev
->wl
, "DMA error: "
1355 "0x%08X, 0x%08X, 0x%08X, "
1356 "0x%08X, 0x%08X, 0x%08X\n",
1357 dma_reason
[0], dma_reason
[1],
1358 dma_reason
[2], dma_reason
[3],
1359 dma_reason
[4], dma_reason
[5]);
1362 if (unlikely(reason
& B43legacy_IRQ_UCODE_DEBUG
))
1363 handle_irq_ucode_debug(dev
);
1364 if (reason
& B43legacy_IRQ_TBTT_INDI
)
1365 handle_irq_tbtt_indication(dev
);
1366 if (reason
& B43legacy_IRQ_ATIM_END
)
1367 handle_irq_atim_end(dev
);
1368 if (reason
& B43legacy_IRQ_BEACON
)
1369 handle_irq_beacon(dev
);
1370 if (reason
& B43legacy_IRQ_PMQ
)
1371 handle_irq_pmq(dev
);
1372 if (reason
& B43legacy_IRQ_TXFIFO_FLUSH_OK
)
1374 if (reason
& B43legacy_IRQ_NOISESAMPLE_OK
)
1375 handle_irq_noise(dev
);
1377 /* Check the DMA reason registers for received data. */
1378 if (dma_reason
[0] & B43legacy_DMAIRQ_RX_DONE
) {
1379 if (b43legacy_using_pio(dev
))
1380 b43legacy_pio_rx(dev
->pio
.queue0
);
1382 b43legacy_dma_rx(dev
->dma
.rx_ring0
);
1384 B43legacy_WARN_ON(dma_reason
[1] & B43legacy_DMAIRQ_RX_DONE
);
1385 B43legacy_WARN_ON(dma_reason
[2] & B43legacy_DMAIRQ_RX_DONE
);
1386 if (dma_reason
[3] & B43legacy_DMAIRQ_RX_DONE
) {
1387 if (b43legacy_using_pio(dev
))
1388 b43legacy_pio_rx(dev
->pio
.queue3
);
1390 b43legacy_dma_rx(dev
->dma
.rx_ring3
);
1392 B43legacy_WARN_ON(dma_reason
[4] & B43legacy_DMAIRQ_RX_DONE
);
1393 B43legacy_WARN_ON(dma_reason
[5] & B43legacy_DMAIRQ_RX_DONE
);
1395 if (reason
& B43legacy_IRQ_TX_OK
)
1396 handle_irq_transmit_status(dev
);
1398 b43legacy_write32(dev
, B43legacy_MMIO_GEN_IRQ_MASK
, dev
->irq_mask
);
1400 spin_unlock_irqrestore(&dev
->wl
->irq_lock
, flags
);
1403 static void pio_irq_workaround(struct b43legacy_wldev
*dev
,
1404 u16 base
, int queueidx
)
1408 rxctl
= b43legacy_read16(dev
, base
+ B43legacy_PIO_RXCTL
);
1409 if (rxctl
& B43legacy_PIO_RXCTL_DATAAVAILABLE
)
1410 dev
->dma_reason
[queueidx
] |= B43legacy_DMAIRQ_RX_DONE
;
1412 dev
->dma_reason
[queueidx
] &= ~B43legacy_DMAIRQ_RX_DONE
;
1415 static void b43legacy_interrupt_ack(struct b43legacy_wldev
*dev
, u32 reason
)
1417 if (b43legacy_using_pio(dev
) &&
1418 (dev
->dev
->id
.revision
< 3) &&
1419 (!(reason
& B43legacy_IRQ_PIO_WORKAROUND
))) {
1420 /* Apply a PIO specific workaround to the dma_reasons */
1421 pio_irq_workaround(dev
, B43legacy_MMIO_PIO1_BASE
, 0);
1422 pio_irq_workaround(dev
, B43legacy_MMIO_PIO2_BASE
, 1);
1423 pio_irq_workaround(dev
, B43legacy_MMIO_PIO3_BASE
, 2);
1424 pio_irq_workaround(dev
, B43legacy_MMIO_PIO4_BASE
, 3);
1427 b43legacy_write32(dev
, B43legacy_MMIO_GEN_IRQ_REASON
, reason
);
1429 b43legacy_write32(dev
, B43legacy_MMIO_DMA0_REASON
,
1430 dev
->dma_reason
[0]);
1431 b43legacy_write32(dev
, B43legacy_MMIO_DMA1_REASON
,
1432 dev
->dma_reason
[1]);
1433 b43legacy_write32(dev
, B43legacy_MMIO_DMA2_REASON
,
1434 dev
->dma_reason
[2]);
1435 b43legacy_write32(dev
, B43legacy_MMIO_DMA3_REASON
,
1436 dev
->dma_reason
[3]);
1437 b43legacy_write32(dev
, B43legacy_MMIO_DMA4_REASON
,
1438 dev
->dma_reason
[4]);
1439 b43legacy_write32(dev
, B43legacy_MMIO_DMA5_REASON
,
1440 dev
->dma_reason
[5]);
1443 /* Interrupt handler top-half */
1444 static irqreturn_t
b43legacy_interrupt_handler(int irq
, void *dev_id
)
1446 irqreturn_t ret
= IRQ_NONE
;
1447 struct b43legacy_wldev
*dev
= dev_id
;
1450 B43legacy_WARN_ON(!dev
);
1452 spin_lock(&dev
->wl
->irq_lock
);
1454 if (unlikely(b43legacy_status(dev
) < B43legacy_STAT_STARTED
))
1455 /* This can only happen on shared IRQ lines. */
1457 reason
= b43legacy_read32(dev
, B43legacy_MMIO_GEN_IRQ_REASON
);
1458 if (reason
== 0xffffffff) /* shared IRQ */
1461 reason
&= dev
->irq_mask
;
1465 dev
->dma_reason
[0] = b43legacy_read32(dev
,
1466 B43legacy_MMIO_DMA0_REASON
)
1468 dev
->dma_reason
[1] = b43legacy_read32(dev
,
1469 B43legacy_MMIO_DMA1_REASON
)
1471 dev
->dma_reason
[2] = b43legacy_read32(dev
,
1472 B43legacy_MMIO_DMA2_REASON
)
1474 dev
->dma_reason
[3] = b43legacy_read32(dev
,
1475 B43legacy_MMIO_DMA3_REASON
)
1477 dev
->dma_reason
[4] = b43legacy_read32(dev
,
1478 B43legacy_MMIO_DMA4_REASON
)
1480 dev
->dma_reason
[5] = b43legacy_read32(dev
,
1481 B43legacy_MMIO_DMA5_REASON
)
1484 b43legacy_interrupt_ack(dev
, reason
);
1485 /* Disable all IRQs. They are enabled again in the bottom half. */
1486 b43legacy_write32(dev
, B43legacy_MMIO_GEN_IRQ_MASK
, 0);
1487 /* Save the reason code and call our bottom half. */
1488 dev
->irq_reason
= reason
;
1489 tasklet_schedule(&dev
->isr_tasklet
);
1492 spin_unlock(&dev
->wl
->irq_lock
);
1497 static void b43legacy_release_firmware(struct b43legacy_wldev
*dev
)
1499 release_firmware(dev
->fw
.ucode
);
1500 dev
->fw
.ucode
= NULL
;
1501 release_firmware(dev
->fw
.pcm
);
1503 release_firmware(dev
->fw
.initvals
);
1504 dev
->fw
.initvals
= NULL
;
1505 release_firmware(dev
->fw
.initvals_band
);
1506 dev
->fw
.initvals_band
= NULL
;
1509 static void b43legacy_print_fw_helptext(struct b43legacy_wl
*wl
)
1511 b43legacyerr(wl
, "You must go to http://linuxwireless.org/en/users/"
1512 "Drivers/b43#devicefirmware "
1513 "and download the correct firmware (version 3).\n");
1516 static int do_request_fw(struct b43legacy_wldev
*dev
,
1518 const struct firmware
**fw
)
1520 char path
[sizeof(modparam_fwpostfix
) + 32];
1521 struct b43legacy_fw_header
*hdr
;
1528 snprintf(path
, ARRAY_SIZE(path
),
1529 "b43legacy%s/%s.fw",
1530 modparam_fwpostfix
, name
);
1531 err
= request_firmware(fw
, path
, dev
->dev
->dev
);
1533 b43legacyerr(dev
->wl
, "Firmware file \"%s\" not found "
1534 "or load failed.\n", path
);
1537 if ((*fw
)->size
< sizeof(struct b43legacy_fw_header
))
1539 hdr
= (struct b43legacy_fw_header
*)((*fw
)->data
);
1540 switch (hdr
->type
) {
1541 case B43legacy_FW_TYPE_UCODE
:
1542 case B43legacy_FW_TYPE_PCM
:
1543 size
= be32_to_cpu(hdr
->size
);
1544 if (size
!= (*fw
)->size
- sizeof(struct b43legacy_fw_header
))
1547 case B43legacy_FW_TYPE_IV
:
1558 b43legacyerr(dev
->wl
, "Firmware file \"%s\" format error.\n", path
);
1562 static int b43legacy_one_core_attach(struct ssb_device
*dev
,
1563 struct b43legacy_wl
*wl
);
1564 static void b43legacy_one_core_detach(struct ssb_device
*dev
);
1566 static void b43legacy_request_firmware(struct work_struct
*work
)
1568 struct b43legacy_wl
*wl
= container_of(work
,
1569 struct b43legacy_wl
, firmware_load
);
1570 struct b43legacy_wldev
*dev
= wl
->current_dev
;
1571 struct b43legacy_firmware
*fw
= &dev
->fw
;
1572 const u8 rev
= dev
->dev
->id
.revision
;
1573 const char *filename
;
1577 ssb_read32(dev
->dev
, SSB_TMSHIGH
);
1580 filename
= "ucode2";
1582 filename
= "ucode4";
1584 filename
= "ucode5";
1585 err
= do_request_fw(dev
, filename
, &fw
->ucode
);
1594 err
= do_request_fw(dev
, filename
, &fw
->pcm
);
1598 if (!fw
->initvals
) {
1599 switch (dev
->phy
.type
) {
1600 case B43legacy_PHYTYPE_B
:
1601 case B43legacy_PHYTYPE_G
:
1602 if ((rev
>= 5) && (rev
<= 10))
1603 filename
= "b0g0initvals5";
1604 else if (rev
== 2 || rev
== 4)
1605 filename
= "b0g0initvals2";
1607 goto err_no_initvals
;
1610 goto err_no_initvals
;
1612 err
= do_request_fw(dev
, filename
, &fw
->initvals
);
1616 if (!fw
->initvals_band
) {
1617 switch (dev
->phy
.type
) {
1618 case B43legacy_PHYTYPE_B
:
1619 case B43legacy_PHYTYPE_G
:
1620 if ((rev
>= 5) && (rev
<= 10))
1621 filename
= "b0g0bsinitvals5";
1624 else if (rev
== 2 || rev
== 4)
1627 goto err_no_initvals
;
1630 goto err_no_initvals
;
1632 err
= do_request_fw(dev
, filename
, &fw
->initvals_band
);
1636 err
= ieee80211_register_hw(wl
->hw
);
1638 goto err_one_core_detach
;
1641 err_one_core_detach
:
1642 b43legacy_one_core_detach(dev
->dev
);
1646 b43legacy_print_fw_helptext(dev
->wl
);
1651 b43legacyerr(dev
->wl
, "No Initial Values firmware file for PHY %u, "
1652 "core rev %u\n", dev
->phy
.type
, rev
);
1656 b43legacy_release_firmware(dev
);
1660 static int b43legacy_upload_microcode(struct b43legacy_wldev
*dev
)
1662 struct wiphy
*wiphy
= dev
->wl
->hw
->wiphy
;
1663 const size_t hdr_len
= sizeof(struct b43legacy_fw_header
);
1674 /* Jump the microcode PSM to offset 0 */
1675 macctl
= b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
1676 B43legacy_WARN_ON(macctl
& B43legacy_MACCTL_PSM_RUN
);
1677 macctl
|= B43legacy_MACCTL_PSM_JMP0
;
1678 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
, macctl
);
1679 /* Zero out all microcode PSM registers and shared memory. */
1680 for (i
= 0; i
< 64; i
++)
1681 b43legacy_shm_write16(dev
, B43legacy_SHM_WIRELESS
, i
, 0);
1682 for (i
= 0; i
< 4096; i
+= 2)
1683 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
, i
, 0);
1685 /* Upload Microcode. */
1686 data
= (__be32
*) (dev
->fw
.ucode
->data
+ hdr_len
);
1687 len
= (dev
->fw
.ucode
->size
- hdr_len
) / sizeof(__be32
);
1688 b43legacy_shm_control_word(dev
,
1689 B43legacy_SHM_UCODE
|
1690 B43legacy_SHM_AUTOINC_W
,
1692 for (i
= 0; i
< len
; i
++) {
1693 b43legacy_write32(dev
, B43legacy_MMIO_SHM_DATA
,
1694 be32_to_cpu(data
[i
]));
1699 /* Upload PCM data. */
1700 data
= (__be32
*) (dev
->fw
.pcm
->data
+ hdr_len
);
1701 len
= (dev
->fw
.pcm
->size
- hdr_len
) / sizeof(__be32
);
1702 b43legacy_shm_control_word(dev
, B43legacy_SHM_HW
, 0x01EA);
1703 b43legacy_write32(dev
, B43legacy_MMIO_SHM_DATA
, 0x00004000);
1704 /* No need for autoinc bit in SHM_HW */
1705 b43legacy_shm_control_word(dev
, B43legacy_SHM_HW
, 0x01EB);
1706 for (i
= 0; i
< len
; i
++) {
1707 b43legacy_write32(dev
, B43legacy_MMIO_SHM_DATA
,
1708 be32_to_cpu(data
[i
]));
1713 b43legacy_write32(dev
, B43legacy_MMIO_GEN_IRQ_REASON
,
1716 /* Start the microcode PSM */
1717 macctl
= b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
1718 macctl
&= ~B43legacy_MACCTL_PSM_JMP0
;
1719 macctl
|= B43legacy_MACCTL_PSM_RUN
;
1720 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
, macctl
);
1722 /* Wait for the microcode to load and respond */
1725 tmp
= b43legacy_read32(dev
, B43legacy_MMIO_GEN_IRQ_REASON
);
1726 if (tmp
== B43legacy_IRQ_MAC_SUSPENDED
)
1729 if (i
>= B43legacy_IRQWAIT_MAX_RETRIES
) {
1730 b43legacyerr(dev
->wl
, "Microcode not responding\n");
1731 b43legacy_print_fw_helptext(dev
->wl
);
1735 msleep_interruptible(50);
1736 if (signal_pending(current
)) {
1741 /* dummy read follows */
1742 b43legacy_read32(dev
, B43legacy_MMIO_GEN_IRQ_REASON
);
1744 /* Get and check the revisions. */
1745 fwrev
= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
,
1746 B43legacy_SHM_SH_UCODEREV
);
1747 fwpatch
= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
,
1748 B43legacy_SHM_SH_UCODEPATCH
);
1749 fwdate
= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
,
1750 B43legacy_SHM_SH_UCODEDATE
);
1751 fwtime
= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
,
1752 B43legacy_SHM_SH_UCODETIME
);
1754 if (fwrev
> 0x128) {
1755 b43legacyerr(dev
->wl
, "YOU ARE TRYING TO LOAD V4 FIRMWARE."
1756 " Only firmware from binary drivers version 3.x"
1757 " is supported. You must change your firmware"
1759 b43legacy_print_fw_helptext(dev
->wl
);
1763 b43legacyinfo(dev
->wl
, "Loading firmware version 0x%X, patch level %u "
1764 "(20%.2i-%.2i-%.2i %.2i:%.2i:%.2i)\n", fwrev
, fwpatch
,
1765 (fwdate
>> 12) & 0xF, (fwdate
>> 8) & 0xF, fwdate
& 0xFF,
1766 (fwtime
>> 11) & 0x1F, (fwtime
>> 5) & 0x3F,
1769 dev
->fw
.rev
= fwrev
;
1770 dev
->fw
.patch
= fwpatch
;
1772 snprintf(wiphy
->fw_version
, sizeof(wiphy
->fw_version
), "%u.%u",
1773 dev
->fw
.rev
, dev
->fw
.patch
);
1774 wiphy
->hw_version
= dev
->dev
->id
.coreid
;
1779 macctl
= b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
1780 macctl
&= ~B43legacy_MACCTL_PSM_RUN
;
1781 macctl
|= B43legacy_MACCTL_PSM_JMP0
;
1782 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
, macctl
);
1787 static int b43legacy_write_initvals(struct b43legacy_wldev
*dev
,
1788 const struct b43legacy_iv
*ivals
,
1792 const struct b43legacy_iv
*iv
;
1797 BUILD_BUG_ON(sizeof(struct b43legacy_iv
) != 6);
1799 for (i
= 0; i
< count
; i
++) {
1800 if (array_size
< sizeof(iv
->offset_size
))
1802 array_size
-= sizeof(iv
->offset_size
);
1803 offset
= be16_to_cpu(iv
->offset_size
);
1804 bit32
= !!(offset
& B43legacy_IV_32BIT
);
1805 offset
&= B43legacy_IV_OFFSET_MASK
;
1806 if (offset
>= 0x1000)
1811 if (array_size
< sizeof(iv
->data
.d32
))
1813 array_size
-= sizeof(iv
->data
.d32
);
1815 value
= get_unaligned_be32(&iv
->data
.d32
);
1816 b43legacy_write32(dev
, offset
, value
);
1818 iv
= (const struct b43legacy_iv
*)((const uint8_t *)iv
+
1824 if (array_size
< sizeof(iv
->data
.d16
))
1826 array_size
-= sizeof(iv
->data
.d16
);
1828 value
= be16_to_cpu(iv
->data
.d16
);
1829 b43legacy_write16(dev
, offset
, value
);
1831 iv
= (const struct b43legacy_iv
*)((const uint8_t *)iv
+
1842 b43legacyerr(dev
->wl
, "Initial Values Firmware file-format error.\n");
1843 b43legacy_print_fw_helptext(dev
->wl
);
1848 static int b43legacy_upload_initvals(struct b43legacy_wldev
*dev
)
1850 const size_t hdr_len
= sizeof(struct b43legacy_fw_header
);
1851 const struct b43legacy_fw_header
*hdr
;
1852 struct b43legacy_firmware
*fw
= &dev
->fw
;
1853 const struct b43legacy_iv
*ivals
;
1857 hdr
= (const struct b43legacy_fw_header
*)(fw
->initvals
->data
);
1858 ivals
= (const struct b43legacy_iv
*)(fw
->initvals
->data
+ hdr_len
);
1859 count
= be32_to_cpu(hdr
->size
);
1860 err
= b43legacy_write_initvals(dev
, ivals
, count
,
1861 fw
->initvals
->size
- hdr_len
);
1864 if (fw
->initvals_band
) {
1865 hdr
= (const struct b43legacy_fw_header
*)
1866 (fw
->initvals_band
->data
);
1867 ivals
= (const struct b43legacy_iv
*)(fw
->initvals_band
->data
1869 count
= be32_to_cpu(hdr
->size
);
1870 err
= b43legacy_write_initvals(dev
, ivals
, count
,
1871 fw
->initvals_band
->size
- hdr_len
);
1880 /* Initialize the GPIOs
1881 * http://bcm-specs.sipsolutions.net/GPIO
1883 static int b43legacy_gpio_init(struct b43legacy_wldev
*dev
)
1885 struct ssb_bus
*bus
= dev
->dev
->bus
;
1886 struct ssb_device
*gpiodev
, *pcidev
= NULL
;
1890 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
,
1891 b43legacy_read32(dev
,
1892 B43legacy_MMIO_MACCTL
)
1895 b43legacy_write16(dev
, B43legacy_MMIO_GPIO_MASK
,
1896 b43legacy_read16(dev
,
1897 B43legacy_MMIO_GPIO_MASK
)
1902 if (dev
->dev
->bus
->chip_id
== 0x4301) {
1906 if (dev
->dev
->bus
->sprom
.boardflags_lo
& B43legacy_BFL_PACTRL
) {
1907 b43legacy_write16(dev
, B43legacy_MMIO_GPIO_MASK
,
1908 b43legacy_read16(dev
,
1909 B43legacy_MMIO_GPIO_MASK
)
1914 if (dev
->dev
->id
.revision
>= 2)
1915 mask
|= 0x0010; /* FIXME: This is redundant. */
1917 #ifdef CONFIG_SSB_DRIVER_PCICORE
1918 pcidev
= bus
->pcicore
.dev
;
1920 gpiodev
= bus
->chipco
.dev
? : pcidev
;
1923 ssb_write32(gpiodev
, B43legacy_GPIO_CONTROL
,
1924 (ssb_read32(gpiodev
, B43legacy_GPIO_CONTROL
)
1930 /* Turn off all GPIO stuff. Call this on module unload, for example. */
1931 static void b43legacy_gpio_cleanup(struct b43legacy_wldev
*dev
)
1933 struct ssb_bus
*bus
= dev
->dev
->bus
;
1934 struct ssb_device
*gpiodev
, *pcidev
= NULL
;
1936 #ifdef CONFIG_SSB_DRIVER_PCICORE
1937 pcidev
= bus
->pcicore
.dev
;
1939 gpiodev
= bus
->chipco
.dev
? : pcidev
;
1942 ssb_write32(gpiodev
, B43legacy_GPIO_CONTROL
, 0);
1945 /* http://bcm-specs.sipsolutions.net/EnableMac */
1946 void b43legacy_mac_enable(struct b43legacy_wldev
*dev
)
1948 dev
->mac_suspended
--;
1949 B43legacy_WARN_ON(dev
->mac_suspended
< 0);
1950 B43legacy_WARN_ON(irqs_disabled());
1951 if (dev
->mac_suspended
== 0) {
1952 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
,
1953 b43legacy_read32(dev
,
1954 B43legacy_MMIO_MACCTL
)
1955 | B43legacy_MACCTL_ENABLED
);
1956 b43legacy_write32(dev
, B43legacy_MMIO_GEN_IRQ_REASON
,
1957 B43legacy_IRQ_MAC_SUSPENDED
);
1958 /* the next two are dummy reads */
1959 b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
1960 b43legacy_read32(dev
, B43legacy_MMIO_GEN_IRQ_REASON
);
1961 b43legacy_power_saving_ctl_bits(dev
, -1, -1);
1963 /* Re-enable IRQs. */
1964 spin_lock_irq(&dev
->wl
->irq_lock
);
1965 b43legacy_write32(dev
, B43legacy_MMIO_GEN_IRQ_MASK
,
1967 spin_unlock_irq(&dev
->wl
->irq_lock
);
1971 /* http://bcm-specs.sipsolutions.net/SuspendMAC */
1972 void b43legacy_mac_suspend(struct b43legacy_wldev
*dev
)
1978 B43legacy_WARN_ON(irqs_disabled());
1979 B43legacy_WARN_ON(dev
->mac_suspended
< 0);
1981 if (dev
->mac_suspended
== 0) {
1982 /* Mask IRQs before suspending MAC. Otherwise
1983 * the MAC stays busy and won't suspend. */
1984 spin_lock_irq(&dev
->wl
->irq_lock
);
1985 b43legacy_write32(dev
, B43legacy_MMIO_GEN_IRQ_MASK
, 0);
1986 spin_unlock_irq(&dev
->wl
->irq_lock
);
1987 b43legacy_synchronize_irq(dev
);
1989 b43legacy_power_saving_ctl_bits(dev
, -1, 1);
1990 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
,
1991 b43legacy_read32(dev
,
1992 B43legacy_MMIO_MACCTL
)
1993 & ~B43legacy_MACCTL_ENABLED
);
1994 b43legacy_read32(dev
, B43legacy_MMIO_GEN_IRQ_REASON
);
1995 for (i
= 40; i
; i
--) {
1996 tmp
= b43legacy_read32(dev
,
1997 B43legacy_MMIO_GEN_IRQ_REASON
);
1998 if (tmp
& B43legacy_IRQ_MAC_SUSPENDED
)
2002 b43legacyerr(dev
->wl
, "MAC suspend failed\n");
2005 dev
->mac_suspended
++;
2008 static void b43legacy_adjust_opmode(struct b43legacy_wldev
*dev
)
2010 struct b43legacy_wl
*wl
= dev
->wl
;
2014 ctl
= b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
2015 /* Reset status to STA infrastructure mode. */
2016 ctl
&= ~B43legacy_MACCTL_AP
;
2017 ctl
&= ~B43legacy_MACCTL_KEEP_CTL
;
2018 ctl
&= ~B43legacy_MACCTL_KEEP_BADPLCP
;
2019 ctl
&= ~B43legacy_MACCTL_KEEP_BAD
;
2020 ctl
&= ~B43legacy_MACCTL_PROMISC
;
2021 ctl
&= ~B43legacy_MACCTL_BEACPROMISC
;
2022 ctl
|= B43legacy_MACCTL_INFRA
;
2024 if (b43legacy_is_mode(wl
, NL80211_IFTYPE_AP
))
2025 ctl
|= B43legacy_MACCTL_AP
;
2026 else if (b43legacy_is_mode(wl
, NL80211_IFTYPE_ADHOC
))
2027 ctl
&= ~B43legacy_MACCTL_INFRA
;
2029 if (wl
->filter_flags
& FIF_CONTROL
)
2030 ctl
|= B43legacy_MACCTL_KEEP_CTL
;
2031 if (wl
->filter_flags
& FIF_FCSFAIL
)
2032 ctl
|= B43legacy_MACCTL_KEEP_BAD
;
2033 if (wl
->filter_flags
& FIF_PLCPFAIL
)
2034 ctl
|= B43legacy_MACCTL_KEEP_BADPLCP
;
2035 if (wl
->filter_flags
& FIF_PROMISC_IN_BSS
)
2036 ctl
|= B43legacy_MACCTL_PROMISC
;
2037 if (wl
->filter_flags
& FIF_BCN_PRBRESP_PROMISC
)
2038 ctl
|= B43legacy_MACCTL_BEACPROMISC
;
2040 /* Workaround: On old hardware the HW-MAC-address-filter
2041 * doesn't work properly, so always run promisc in filter
2042 * it in software. */
2043 if (dev
->dev
->id
.revision
<= 4)
2044 ctl
|= B43legacy_MACCTL_PROMISC
;
2046 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
, ctl
);
2049 if ((ctl
& B43legacy_MACCTL_INFRA
) &&
2050 !(ctl
& B43legacy_MACCTL_AP
)) {
2051 if (dev
->dev
->bus
->chip_id
== 0x4306 &&
2052 dev
->dev
->bus
->chip_rev
== 3)
2057 b43legacy_write16(dev
, 0x612, cfp_pretbtt
);
2060 static void b43legacy_rate_memory_write(struct b43legacy_wldev
*dev
,
2068 offset
+= (b43legacy_plcp_get_ratecode_ofdm(rate
) & 0x000F) * 2;
2071 offset
+= (b43legacy_plcp_get_ratecode_cck(rate
) & 0x000F) * 2;
2073 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
, offset
+ 0x20,
2074 b43legacy_shm_read16(dev
,
2075 B43legacy_SHM_SHARED
, offset
));
2078 static void b43legacy_rate_memory_init(struct b43legacy_wldev
*dev
)
2080 switch (dev
->phy
.type
) {
2081 case B43legacy_PHYTYPE_G
:
2082 b43legacy_rate_memory_write(dev
, B43legacy_OFDM_RATE_6MB
, 1);
2083 b43legacy_rate_memory_write(dev
, B43legacy_OFDM_RATE_12MB
, 1);
2084 b43legacy_rate_memory_write(dev
, B43legacy_OFDM_RATE_18MB
, 1);
2085 b43legacy_rate_memory_write(dev
, B43legacy_OFDM_RATE_24MB
, 1);
2086 b43legacy_rate_memory_write(dev
, B43legacy_OFDM_RATE_36MB
, 1);
2087 b43legacy_rate_memory_write(dev
, B43legacy_OFDM_RATE_48MB
, 1);
2088 b43legacy_rate_memory_write(dev
, B43legacy_OFDM_RATE_54MB
, 1);
2090 case B43legacy_PHYTYPE_B
:
2091 b43legacy_rate_memory_write(dev
, B43legacy_CCK_RATE_1MB
, 0);
2092 b43legacy_rate_memory_write(dev
, B43legacy_CCK_RATE_2MB
, 0);
2093 b43legacy_rate_memory_write(dev
, B43legacy_CCK_RATE_5MB
, 0);
2094 b43legacy_rate_memory_write(dev
, B43legacy_CCK_RATE_11MB
, 0);
2097 B43legacy_BUG_ON(1);
2101 /* Set the TX-Antenna for management frames sent by firmware. */
2102 static void b43legacy_mgmtframe_txantenna(struct b43legacy_wldev
*dev
,
2109 case B43legacy_ANTENNA0
:
2110 ant
|= B43legacy_TX4_PHY_ANT0
;
2112 case B43legacy_ANTENNA1
:
2113 ant
|= B43legacy_TX4_PHY_ANT1
;
2115 case B43legacy_ANTENNA_AUTO
:
2116 ant
|= B43legacy_TX4_PHY_ANTLAST
;
2119 B43legacy_BUG_ON(1);
2122 /* FIXME We also need to set the other flags of the PHY control
2123 * field somewhere. */
2126 tmp
= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
,
2127 B43legacy_SHM_SH_BEACPHYCTL
);
2128 tmp
= (tmp
& ~B43legacy_TX4_PHY_ANT
) | ant
;
2129 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
,
2130 B43legacy_SHM_SH_BEACPHYCTL
, tmp
);
2132 tmp
= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
,
2133 B43legacy_SHM_SH_ACKCTSPHYCTL
);
2134 tmp
= (tmp
& ~B43legacy_TX4_PHY_ANT
) | ant
;
2135 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
,
2136 B43legacy_SHM_SH_ACKCTSPHYCTL
, tmp
);
2137 /* For Probe Resposes */
2138 tmp
= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
,
2139 B43legacy_SHM_SH_PRPHYCTL
);
2140 tmp
= (tmp
& ~B43legacy_TX4_PHY_ANT
) | ant
;
2141 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
,
2142 B43legacy_SHM_SH_PRPHYCTL
, tmp
);
2145 /* This is the opposite of b43legacy_chip_init() */
2146 static void b43legacy_chip_exit(struct b43legacy_wldev
*dev
)
2148 b43legacy_radio_turn_off(dev
, 1);
2149 b43legacy_gpio_cleanup(dev
);
2150 /* firmware is released later */
2153 /* Initialize the chip
2154 * http://bcm-specs.sipsolutions.net/ChipInit
2156 static int b43legacy_chip_init(struct b43legacy_wldev
*dev
)
2158 struct b43legacy_phy
*phy
= &dev
->phy
;
2161 u32 value32
, macctl
;
2164 /* Initialize the MAC control */
2165 macctl
= B43legacy_MACCTL_IHR_ENABLED
| B43legacy_MACCTL_SHM_ENABLED
;
2167 macctl
|= B43legacy_MACCTL_GMODE
;
2168 macctl
|= B43legacy_MACCTL_INFRA
;
2169 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
, macctl
);
2171 err
= b43legacy_upload_microcode(dev
);
2173 goto out
; /* firmware is released later */
2175 err
= b43legacy_gpio_init(dev
);
2177 goto out
; /* firmware is released later */
2179 err
= b43legacy_upload_initvals(dev
);
2181 goto err_gpio_clean
;
2182 b43legacy_radio_turn_on(dev
);
2184 b43legacy_write16(dev
, 0x03E6, 0x0000);
2185 err
= b43legacy_phy_init(dev
);
2189 /* Select initial Interference Mitigation. */
2190 tmp
= phy
->interfmode
;
2191 phy
->interfmode
= B43legacy_INTERFMODE_NONE
;
2192 b43legacy_radio_set_interference_mitigation(dev
, tmp
);
2194 b43legacy_phy_set_antenna_diversity(dev
);
2195 b43legacy_mgmtframe_txantenna(dev
, B43legacy_ANTENNA_DEFAULT
);
2197 if (phy
->type
== B43legacy_PHYTYPE_B
) {
2198 value16
= b43legacy_read16(dev
, 0x005E);
2200 b43legacy_write16(dev
, 0x005E, value16
);
2202 b43legacy_write32(dev
, 0x0100, 0x01000000);
2203 if (dev
->dev
->id
.revision
< 5)
2204 b43legacy_write32(dev
, 0x010C, 0x01000000);
2206 value32
= b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
2207 value32
&= ~B43legacy_MACCTL_INFRA
;
2208 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
, value32
);
2209 value32
= b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
2210 value32
|= B43legacy_MACCTL_INFRA
;
2211 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
, value32
);
2213 if (b43legacy_using_pio(dev
)) {
2214 b43legacy_write32(dev
, 0x0210, 0x00000100);
2215 b43legacy_write32(dev
, 0x0230, 0x00000100);
2216 b43legacy_write32(dev
, 0x0250, 0x00000100);
2217 b43legacy_write32(dev
, 0x0270, 0x00000100);
2218 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
, 0x0034,
2222 /* Probe Response Timeout value */
2223 /* FIXME: Default to 0, has to be set by ioctl probably... :-/ */
2224 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
, 0x0074, 0x0000);
2226 /* Initially set the wireless operation mode. */
2227 b43legacy_adjust_opmode(dev
);
2229 if (dev
->dev
->id
.revision
< 3) {
2230 b43legacy_write16(dev
, 0x060E, 0x0000);
2231 b43legacy_write16(dev
, 0x0610, 0x8000);
2232 b43legacy_write16(dev
, 0x0604, 0x0000);
2233 b43legacy_write16(dev
, 0x0606, 0x0200);
2235 b43legacy_write32(dev
, 0x0188, 0x80000000);
2236 b43legacy_write32(dev
, 0x018C, 0x02000000);
2238 b43legacy_write32(dev
, B43legacy_MMIO_GEN_IRQ_REASON
, 0x00004000);
2239 b43legacy_write32(dev
, B43legacy_MMIO_DMA0_IRQ_MASK
, 0x0001DC00);
2240 b43legacy_write32(dev
, B43legacy_MMIO_DMA1_IRQ_MASK
, 0x0000DC00);
2241 b43legacy_write32(dev
, B43legacy_MMIO_DMA2_IRQ_MASK
, 0x0000DC00);
2242 b43legacy_write32(dev
, B43legacy_MMIO_DMA3_IRQ_MASK
, 0x0001DC00);
2243 b43legacy_write32(dev
, B43legacy_MMIO_DMA4_IRQ_MASK
, 0x0000DC00);
2244 b43legacy_write32(dev
, B43legacy_MMIO_DMA5_IRQ_MASK
, 0x0000DC00);
2246 value32
= ssb_read32(dev
->dev
, SSB_TMSLOW
);
2247 value32
|= B43legacy_TMSLOW_MACPHYCLKEN
;
2248 ssb_write32(dev
->dev
, SSB_TMSLOW
, value32
);
2250 b43legacy_write16(dev
, B43legacy_MMIO_POWERUP_DELAY
,
2251 dev
->dev
->bus
->chipco
.fast_pwrup_delay
);
2253 /* PHY TX errors counter. */
2254 atomic_set(&phy
->txerr_cnt
, B43legacy_PHY_TX_BADNESS_LIMIT
);
2256 B43legacy_WARN_ON(err
!= 0);
2257 b43legacydbg(dev
->wl
, "Chip initialized\n");
2262 b43legacy_radio_turn_off(dev
, 1);
2264 b43legacy_gpio_cleanup(dev
);
2268 static void b43legacy_periodic_every120sec(struct b43legacy_wldev
*dev
)
2270 struct b43legacy_phy
*phy
= &dev
->phy
;
2272 if (phy
->type
!= B43legacy_PHYTYPE_G
|| phy
->rev
< 2)
2275 b43legacy_mac_suspend(dev
);
2276 b43legacy_phy_lo_g_measure(dev
);
2277 b43legacy_mac_enable(dev
);
2280 static void b43legacy_periodic_every60sec(struct b43legacy_wldev
*dev
)
2282 b43legacy_phy_lo_mark_all_unused(dev
);
2283 if (dev
->dev
->bus
->sprom
.boardflags_lo
& B43legacy_BFL_RSSI
) {
2284 b43legacy_mac_suspend(dev
);
2285 b43legacy_calc_nrssi_slope(dev
);
2286 b43legacy_mac_enable(dev
);
2290 static void b43legacy_periodic_every30sec(struct b43legacy_wldev
*dev
)
2292 /* Update device statistics. */
2293 b43legacy_calculate_link_quality(dev
);
2296 static void b43legacy_periodic_every15sec(struct b43legacy_wldev
*dev
)
2298 b43legacy_phy_xmitpower(dev
); /* FIXME: unless scanning? */
2300 atomic_set(&dev
->phy
.txerr_cnt
, B43legacy_PHY_TX_BADNESS_LIMIT
);
2304 static void do_periodic_work(struct b43legacy_wldev
*dev
)
2308 state
= dev
->periodic_state
;
2310 b43legacy_periodic_every120sec(dev
);
2312 b43legacy_periodic_every60sec(dev
);
2314 b43legacy_periodic_every30sec(dev
);
2315 b43legacy_periodic_every15sec(dev
);
2318 /* Periodic work locking policy:
2319 * The whole periodic work handler is protected by
2320 * wl->mutex. If another lock is needed somewhere in the
2321 * pwork callchain, it's acquired in-place, where it's needed.
2323 static void b43legacy_periodic_work_handler(struct work_struct
*work
)
2325 struct b43legacy_wldev
*dev
= container_of(work
, struct b43legacy_wldev
,
2326 periodic_work
.work
);
2327 struct b43legacy_wl
*wl
= dev
->wl
;
2328 unsigned long delay
;
2330 mutex_lock(&wl
->mutex
);
2332 if (unlikely(b43legacy_status(dev
) != B43legacy_STAT_STARTED
))
2334 if (b43legacy_debug(dev
, B43legacy_DBG_PWORK_STOP
))
2337 do_periodic_work(dev
);
2339 dev
->periodic_state
++;
2341 if (b43legacy_debug(dev
, B43legacy_DBG_PWORK_FAST
))
2342 delay
= msecs_to_jiffies(50);
2344 delay
= round_jiffies_relative(HZ
* 15);
2345 ieee80211_queue_delayed_work(wl
->hw
, &dev
->periodic_work
, delay
);
2347 mutex_unlock(&wl
->mutex
);
2350 static void b43legacy_periodic_tasks_setup(struct b43legacy_wldev
*dev
)
2352 struct delayed_work
*work
= &dev
->periodic_work
;
2354 dev
->periodic_state
= 0;
2355 INIT_DELAYED_WORK(work
, b43legacy_periodic_work_handler
);
2356 ieee80211_queue_delayed_work(dev
->wl
->hw
, work
, 0);
2359 /* Validate access to the chip (SHM) */
2360 static int b43legacy_validate_chipaccess(struct b43legacy_wldev
*dev
)
2365 shm_backup
= b43legacy_shm_read32(dev
, B43legacy_SHM_SHARED
, 0);
2366 b43legacy_shm_write32(dev
, B43legacy_SHM_SHARED
, 0, 0xAA5555AA);
2367 if (b43legacy_shm_read32(dev
, B43legacy_SHM_SHARED
, 0) !=
2370 b43legacy_shm_write32(dev
, B43legacy_SHM_SHARED
, 0, 0x55AAAA55);
2371 if (b43legacy_shm_read32(dev
, B43legacy_SHM_SHARED
, 0) !=
2374 b43legacy_shm_write32(dev
, B43legacy_SHM_SHARED
, 0, shm_backup
);
2376 value
= b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
2377 if ((value
| B43legacy_MACCTL_GMODE
) !=
2378 (B43legacy_MACCTL_GMODE
| B43legacy_MACCTL_IHR_ENABLED
))
2381 value
= b43legacy_read32(dev
, B43legacy_MMIO_GEN_IRQ_REASON
);
2387 b43legacyerr(dev
->wl
, "Failed to validate the chipaccess\n");
2391 static void b43legacy_security_init(struct b43legacy_wldev
*dev
)
2393 dev
->max_nr_keys
= (dev
->dev
->id
.revision
>= 5) ? 58 : 20;
2394 B43legacy_WARN_ON(dev
->max_nr_keys
> ARRAY_SIZE(dev
->key
));
2395 dev
->ktp
= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
,
2397 /* KTP is a word address, but we address SHM bytewise.
2398 * So multiply by two.
2401 if (dev
->dev
->id
.revision
>= 5)
2402 /* Number of RCMTA address slots */
2403 b43legacy_write16(dev
, B43legacy_MMIO_RCMTA_COUNT
,
2404 dev
->max_nr_keys
- 8);
2407 #ifdef CONFIG_B43LEGACY_HWRNG
2408 static int b43legacy_rng_read(struct hwrng
*rng
, u32
*data
)
2410 struct b43legacy_wl
*wl
= (struct b43legacy_wl
*)rng
->priv
;
2411 unsigned long flags
;
2413 /* Don't take wl->mutex here, as it could deadlock with
2414 * hwrng internal locking. It's not needed to take
2415 * wl->mutex here, anyway. */
2417 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2418 *data
= b43legacy_read16(wl
->current_dev
, B43legacy_MMIO_RNG
);
2419 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2421 return (sizeof(u16
));
2425 static void b43legacy_rng_exit(struct b43legacy_wl
*wl
)
2427 #ifdef CONFIG_B43LEGACY_HWRNG
2428 if (wl
->rng_initialized
)
2429 hwrng_unregister(&wl
->rng
);
2433 static int b43legacy_rng_init(struct b43legacy_wl
*wl
)
2437 #ifdef CONFIG_B43LEGACY_HWRNG
2438 snprintf(wl
->rng_name
, ARRAY_SIZE(wl
->rng_name
),
2439 "%s_%s", KBUILD_MODNAME
, wiphy_name(wl
->hw
->wiphy
));
2440 wl
->rng
.name
= wl
->rng_name
;
2441 wl
->rng
.data_read
= b43legacy_rng_read
;
2442 wl
->rng
.priv
= (unsigned long)wl
;
2443 wl
->rng_initialized
= 1;
2444 err
= hwrng_register(&wl
->rng
);
2446 wl
->rng_initialized
= 0;
2447 b43legacyerr(wl
, "Failed to register the random "
2448 "number generator (%d)\n", err
);
2455 static void b43legacy_tx_work(struct work_struct
*work
)
2457 struct b43legacy_wl
*wl
= container_of(work
, struct b43legacy_wl
,
2459 struct b43legacy_wldev
*dev
;
2460 struct sk_buff
*skb
;
2464 mutex_lock(&wl
->mutex
);
2465 dev
= wl
->current_dev
;
2466 if (unlikely(!dev
|| b43legacy_status(dev
) < B43legacy_STAT_STARTED
)) {
2467 mutex_unlock(&wl
->mutex
);
2471 for (queue_num
= 0; queue_num
< B43legacy_QOS_QUEUE_NUM
; queue_num
++) {
2472 while (skb_queue_len(&wl
->tx_queue
[queue_num
])) {
2473 skb
= skb_dequeue(&wl
->tx_queue
[queue_num
]);
2474 if (b43legacy_using_pio(dev
))
2475 err
= b43legacy_pio_tx(dev
, skb
);
2477 err
= b43legacy_dma_tx(dev
, skb
);
2478 if (err
== -ENOSPC
) {
2479 wl
->tx_queue_stopped
[queue_num
] = 1;
2480 ieee80211_stop_queue(wl
->hw
, queue_num
);
2481 skb_queue_head(&wl
->tx_queue
[queue_num
], skb
);
2485 dev_kfree_skb(skb
); /* Drop it */
2490 wl
->tx_queue_stopped
[queue_num
] = 0;
2493 mutex_unlock(&wl
->mutex
);
2496 static void b43legacy_op_tx(struct ieee80211_hw
*hw
,
2497 struct sk_buff
*skb
)
2499 struct b43legacy_wl
*wl
= hw_to_b43legacy_wl(hw
);
2501 if (unlikely(skb
->len
< 2 + 2 + 6)) {
2502 /* Too short, this can't be a valid frame. */
2503 dev_kfree_skb_any(skb
);
2506 B43legacy_WARN_ON(skb_shinfo(skb
)->nr_frags
);
2508 skb_queue_tail(&wl
->tx_queue
[skb
->queue_mapping
], skb
);
2509 if (!wl
->tx_queue_stopped
[skb
->queue_mapping
])
2510 ieee80211_queue_work(wl
->hw
, &wl
->tx_work
);
2512 ieee80211_stop_queue(wl
->hw
, skb
->queue_mapping
);
2515 static int b43legacy_op_conf_tx(struct ieee80211_hw
*hw
,
2516 struct ieee80211_vif
*vif
, u16 queue
,
2517 const struct ieee80211_tx_queue_params
*params
)
2522 static int b43legacy_op_get_stats(struct ieee80211_hw
*hw
,
2523 struct ieee80211_low_level_stats
*stats
)
2525 struct b43legacy_wl
*wl
= hw_to_b43legacy_wl(hw
);
2526 unsigned long flags
;
2528 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2529 memcpy(stats
, &wl
->ieee_stats
, sizeof(*stats
));
2530 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2535 static const char *phymode_to_string(unsigned int phymode
)
2538 case B43legacy_PHYMODE_B
:
2540 case B43legacy_PHYMODE_G
:
2543 B43legacy_BUG_ON(1);
2548 static int find_wldev_for_phymode(struct b43legacy_wl
*wl
,
2549 unsigned int phymode
,
2550 struct b43legacy_wldev
**dev
,
2553 struct b43legacy_wldev
*d
;
2555 list_for_each_entry(d
, &wl
->devlist
, list
) {
2556 if (d
->phy
.possible_phymodes
& phymode
) {
2557 /* Ok, this device supports the PHY-mode.
2558 * Set the gmode bit. */
2569 static void b43legacy_put_phy_into_reset(struct b43legacy_wldev
*dev
)
2571 struct ssb_device
*sdev
= dev
->dev
;
2574 tmslow
= ssb_read32(sdev
, SSB_TMSLOW
);
2575 tmslow
&= ~B43legacy_TMSLOW_GMODE
;
2576 tmslow
|= B43legacy_TMSLOW_PHYRESET
;
2577 tmslow
|= SSB_TMSLOW_FGC
;
2578 ssb_write32(sdev
, SSB_TMSLOW
, tmslow
);
2581 tmslow
= ssb_read32(sdev
, SSB_TMSLOW
);
2582 tmslow
&= ~SSB_TMSLOW_FGC
;
2583 tmslow
|= B43legacy_TMSLOW_PHYRESET
;
2584 ssb_write32(sdev
, SSB_TMSLOW
, tmslow
);
2588 /* Expects wl->mutex locked */
2589 static int b43legacy_switch_phymode(struct b43legacy_wl
*wl
,
2590 unsigned int new_mode
)
2592 struct b43legacy_wldev
*uninitialized_var(up_dev
);
2593 struct b43legacy_wldev
*down_dev
;
2598 err
= find_wldev_for_phymode(wl
, new_mode
, &up_dev
, &gmode
);
2600 b43legacyerr(wl
, "Could not find a device for %s-PHY mode\n",
2601 phymode_to_string(new_mode
));
2604 if ((up_dev
== wl
->current_dev
) &&
2605 (!!wl
->current_dev
->phy
.gmode
== !!gmode
))
2606 /* This device is already running. */
2608 b43legacydbg(wl
, "Reconfiguring PHYmode to %s-PHY\n",
2609 phymode_to_string(new_mode
));
2610 down_dev
= wl
->current_dev
;
2612 prev_status
= b43legacy_status(down_dev
);
2613 /* Shutdown the currently running core. */
2614 if (prev_status
>= B43legacy_STAT_STARTED
)
2615 b43legacy_wireless_core_stop(down_dev
);
2616 if (prev_status
>= B43legacy_STAT_INITIALIZED
)
2617 b43legacy_wireless_core_exit(down_dev
);
2619 if (down_dev
!= up_dev
)
2620 /* We switch to a different core, so we put PHY into
2621 * RESET on the old core. */
2622 b43legacy_put_phy_into_reset(down_dev
);
2624 /* Now start the new core. */
2625 up_dev
->phy
.gmode
= gmode
;
2626 if (prev_status
>= B43legacy_STAT_INITIALIZED
) {
2627 err
= b43legacy_wireless_core_init(up_dev
);
2629 b43legacyerr(wl
, "Fatal: Could not initialize device"
2630 " for newly selected %s-PHY mode\n",
2631 phymode_to_string(new_mode
));
2635 if (prev_status
>= B43legacy_STAT_STARTED
) {
2636 err
= b43legacy_wireless_core_start(up_dev
);
2638 b43legacyerr(wl
, "Fatal: Coult not start device for "
2639 "newly selected %s-PHY mode\n",
2640 phymode_to_string(new_mode
));
2641 b43legacy_wireless_core_exit(up_dev
);
2645 B43legacy_WARN_ON(b43legacy_status(up_dev
) != prev_status
);
2647 b43legacy_shm_write32(up_dev
, B43legacy_SHM_SHARED
, 0x003E, 0);
2649 wl
->current_dev
= up_dev
;
2653 /* Whoops, failed to init the new core. No core is operating now. */
2654 wl
->current_dev
= NULL
;
2658 /* Write the short and long frame retry limit values. */
2659 static void b43legacy_set_retry_limits(struct b43legacy_wldev
*dev
,
2660 unsigned int short_retry
,
2661 unsigned int long_retry
)
2663 /* The retry limit is a 4-bit counter. Enforce this to avoid overflowing
2664 * the chip-internal counter. */
2665 short_retry
= min(short_retry
, (unsigned int)0xF);
2666 long_retry
= min(long_retry
, (unsigned int)0xF);
2668 b43legacy_shm_write16(dev
, B43legacy_SHM_WIRELESS
, 0x0006, short_retry
);
2669 b43legacy_shm_write16(dev
, B43legacy_SHM_WIRELESS
, 0x0007, long_retry
);
2672 static int b43legacy_op_dev_config(struct ieee80211_hw
*hw
,
2675 struct b43legacy_wl
*wl
= hw_to_b43legacy_wl(hw
);
2676 struct b43legacy_wldev
*dev
;
2677 struct b43legacy_phy
*phy
;
2678 struct ieee80211_conf
*conf
= &hw
->conf
;
2679 unsigned long flags
;
2680 unsigned int new_phymode
= 0xFFFF;
2684 antenna_tx
= B43legacy_ANTENNA_DEFAULT
;
2686 mutex_lock(&wl
->mutex
);
2687 dev
= wl
->current_dev
;
2690 if (changed
& IEEE80211_CONF_CHANGE_RETRY_LIMITS
)
2691 b43legacy_set_retry_limits(dev
,
2692 conf
->short_frame_max_tx_count
,
2693 conf
->long_frame_max_tx_count
);
2694 changed
&= ~IEEE80211_CONF_CHANGE_RETRY_LIMITS
;
2696 goto out_unlock_mutex
;
2698 /* Switch the PHY mode (if necessary). */
2699 switch (conf
->channel
->band
) {
2700 case IEEE80211_BAND_2GHZ
:
2701 if (phy
->type
== B43legacy_PHYTYPE_B
)
2702 new_phymode
= B43legacy_PHYMODE_B
;
2704 new_phymode
= B43legacy_PHYMODE_G
;
2707 B43legacy_WARN_ON(1);
2709 err
= b43legacy_switch_phymode(wl
, new_phymode
);
2711 goto out_unlock_mutex
;
2713 /* Disable IRQs while reconfiguring the device.
2714 * This makes it possible to drop the spinlock throughout
2715 * the reconfiguration process. */
2716 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2717 if (b43legacy_status(dev
) < B43legacy_STAT_STARTED
) {
2718 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2719 goto out_unlock_mutex
;
2721 b43legacy_write32(dev
, B43legacy_MMIO_GEN_IRQ_MASK
, 0);
2722 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2723 b43legacy_synchronize_irq(dev
);
2725 /* Switch to the requested channel.
2726 * The firmware takes care of races with the TX handler. */
2727 if (conf
->channel
->hw_value
!= phy
->channel
)
2728 b43legacy_radio_selectchannel(dev
, conf
->channel
->hw_value
, 0);
2730 dev
->wl
->radiotap_enabled
= !!(conf
->flags
& IEEE80211_CONF_MONITOR
);
2732 /* Adjust the desired TX power level. */
2733 if (conf
->power_level
!= 0) {
2734 if (conf
->power_level
!= phy
->power_level
) {
2735 phy
->power_level
= conf
->power_level
;
2736 b43legacy_phy_xmitpower(dev
);
2740 /* Antennas for RX and management frame TX. */
2741 b43legacy_mgmtframe_txantenna(dev
, antenna_tx
);
2743 if (wl
->radio_enabled
!= phy
->radio_on
) {
2744 if (wl
->radio_enabled
) {
2745 b43legacy_radio_turn_on(dev
);
2746 b43legacyinfo(dev
->wl
, "Radio turned on by software\n");
2747 if (!dev
->radio_hw_enable
)
2748 b43legacyinfo(dev
->wl
, "The hardware RF-kill"
2749 " button still turns the radio"
2750 " physically off. Press the"
2751 " button to turn it on.\n");
2753 b43legacy_radio_turn_off(dev
, 0);
2754 b43legacyinfo(dev
->wl
, "Radio turned off by"
2759 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2760 b43legacy_write32(dev
, B43legacy_MMIO_GEN_IRQ_MASK
, dev
->irq_mask
);
2762 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2764 mutex_unlock(&wl
->mutex
);
2769 static void b43legacy_update_basic_rates(struct b43legacy_wldev
*dev
, u32 brates
)
2771 struct ieee80211_supported_band
*sband
=
2772 dev
->wl
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
];
2773 struct ieee80211_rate
*rate
;
2775 u16 basic
, direct
, offset
, basic_offset
, rateptr
;
2777 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
2778 rate
= &sband
->bitrates
[i
];
2780 if (b43legacy_is_cck_rate(rate
->hw_value
)) {
2781 direct
= B43legacy_SHM_SH_CCKDIRECT
;
2782 basic
= B43legacy_SHM_SH_CCKBASIC
;
2783 offset
= b43legacy_plcp_get_ratecode_cck(rate
->hw_value
);
2786 direct
= B43legacy_SHM_SH_OFDMDIRECT
;
2787 basic
= B43legacy_SHM_SH_OFDMBASIC
;
2788 offset
= b43legacy_plcp_get_ratecode_ofdm(rate
->hw_value
);
2792 rate
= ieee80211_get_response_rate(sband
, brates
, rate
->bitrate
);
2794 if (b43legacy_is_cck_rate(rate
->hw_value
)) {
2795 basic_offset
= b43legacy_plcp_get_ratecode_cck(rate
->hw_value
);
2796 basic_offset
&= 0xF;
2798 basic_offset
= b43legacy_plcp_get_ratecode_ofdm(rate
->hw_value
);
2799 basic_offset
&= 0xF;
2803 * Get the pointer that we need to point to
2804 * from the direct map
2806 rateptr
= b43legacy_shm_read16(dev
, B43legacy_SHM_SHARED
,
2807 direct
+ 2 * basic_offset
);
2808 /* and write it to the basic map */
2809 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
,
2810 basic
+ 2 * offset
, rateptr
);
2814 static void b43legacy_op_bss_info_changed(struct ieee80211_hw
*hw
,
2815 struct ieee80211_vif
*vif
,
2816 struct ieee80211_bss_conf
*conf
,
2819 struct b43legacy_wl
*wl
= hw_to_b43legacy_wl(hw
);
2820 struct b43legacy_wldev
*dev
;
2821 unsigned long flags
;
2823 mutex_lock(&wl
->mutex
);
2824 B43legacy_WARN_ON(wl
->vif
!= vif
);
2826 dev
= wl
->current_dev
;
2828 /* Disable IRQs while reconfiguring the device.
2829 * This makes it possible to drop the spinlock throughout
2830 * the reconfiguration process. */
2831 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2832 if (b43legacy_status(dev
) < B43legacy_STAT_STARTED
) {
2833 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2834 goto out_unlock_mutex
;
2836 b43legacy_write32(dev
, B43legacy_MMIO_GEN_IRQ_MASK
, 0);
2838 if (changed
& BSS_CHANGED_BSSID
) {
2839 b43legacy_synchronize_irq(dev
);
2842 memcpy(wl
->bssid
, conf
->bssid
, ETH_ALEN
);
2844 memset(wl
->bssid
, 0, ETH_ALEN
);
2847 if (b43legacy_status(dev
) >= B43legacy_STAT_INITIALIZED
) {
2848 if (changed
& BSS_CHANGED_BEACON
&&
2849 (b43legacy_is_mode(wl
, NL80211_IFTYPE_AP
) ||
2850 b43legacy_is_mode(wl
, NL80211_IFTYPE_ADHOC
)))
2851 b43legacy_update_templates(wl
);
2853 if (changed
& BSS_CHANGED_BSSID
)
2854 b43legacy_write_mac_bssid_templates(dev
);
2856 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2858 b43legacy_mac_suspend(dev
);
2860 if (changed
& BSS_CHANGED_BEACON_INT
&&
2861 (b43legacy_is_mode(wl
, NL80211_IFTYPE_AP
) ||
2862 b43legacy_is_mode(wl
, NL80211_IFTYPE_ADHOC
)))
2863 b43legacy_set_beacon_int(dev
, conf
->beacon_int
);
2865 if (changed
& BSS_CHANGED_BASIC_RATES
)
2866 b43legacy_update_basic_rates(dev
, conf
->basic_rates
);
2868 if (changed
& BSS_CHANGED_ERP_SLOT
) {
2869 if (conf
->use_short_slot
)
2870 b43legacy_short_slot_timing_enable(dev
);
2872 b43legacy_short_slot_timing_disable(dev
);
2875 b43legacy_mac_enable(dev
);
2877 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2878 b43legacy_write32(dev
, B43legacy_MMIO_GEN_IRQ_MASK
, dev
->irq_mask
);
2881 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2883 mutex_unlock(&wl
->mutex
);
2886 static void b43legacy_op_configure_filter(struct ieee80211_hw
*hw
,
2887 unsigned int changed
,
2888 unsigned int *fflags
,u64 multicast
)
2890 struct b43legacy_wl
*wl
= hw_to_b43legacy_wl(hw
);
2891 struct b43legacy_wldev
*dev
= wl
->current_dev
;
2892 unsigned long flags
;
2899 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2900 *fflags
&= FIF_PROMISC_IN_BSS
|
2906 FIF_BCN_PRBRESP_PROMISC
;
2908 changed
&= FIF_PROMISC_IN_BSS
|
2914 FIF_BCN_PRBRESP_PROMISC
;
2916 wl
->filter_flags
= *fflags
;
2918 if (changed
&& b43legacy_status(dev
) >= B43legacy_STAT_INITIALIZED
)
2919 b43legacy_adjust_opmode(dev
);
2920 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2923 /* Locking: wl->mutex */
2924 static void b43legacy_wireless_core_stop(struct b43legacy_wldev
*dev
)
2926 struct b43legacy_wl
*wl
= dev
->wl
;
2927 unsigned long flags
;
2930 if (b43legacy_status(dev
) < B43legacy_STAT_STARTED
)
2933 /* Disable and sync interrupts. We must do this before than
2934 * setting the status to INITIALIZED, as the interrupt handler
2935 * won't care about IRQs then. */
2936 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2937 b43legacy_write32(dev
, B43legacy_MMIO_GEN_IRQ_MASK
, 0);
2938 b43legacy_read32(dev
, B43legacy_MMIO_GEN_IRQ_MASK
); /* flush */
2939 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2940 b43legacy_synchronize_irq(dev
);
2942 b43legacy_set_status(dev
, B43legacy_STAT_INITIALIZED
);
2944 mutex_unlock(&wl
->mutex
);
2945 /* Must unlock as it would otherwise deadlock. No races here.
2946 * Cancel the possibly running self-rearming periodic work. */
2947 cancel_delayed_work_sync(&dev
->periodic_work
);
2948 cancel_work_sync(&wl
->tx_work
);
2949 mutex_lock(&wl
->mutex
);
2951 /* Drain all TX queues. */
2952 for (queue_num
= 0; queue_num
< B43legacy_QOS_QUEUE_NUM
; queue_num
++) {
2953 while (skb_queue_len(&wl
->tx_queue
[queue_num
]))
2954 dev_kfree_skb(skb_dequeue(&wl
->tx_queue
[queue_num
]));
2957 b43legacy_mac_suspend(dev
);
2958 free_irq(dev
->dev
->irq
, dev
);
2959 b43legacydbg(wl
, "Wireless interface stopped\n");
2962 /* Locking: wl->mutex */
2963 static int b43legacy_wireless_core_start(struct b43legacy_wldev
*dev
)
2967 B43legacy_WARN_ON(b43legacy_status(dev
) != B43legacy_STAT_INITIALIZED
);
2969 drain_txstatus_queue(dev
);
2970 err
= request_irq(dev
->dev
->irq
, b43legacy_interrupt_handler
,
2971 IRQF_SHARED
, KBUILD_MODNAME
, dev
);
2973 b43legacyerr(dev
->wl
, "Cannot request IRQ-%d\n",
2977 /* We are ready to run. */
2978 ieee80211_wake_queues(dev
->wl
->hw
);
2979 b43legacy_set_status(dev
, B43legacy_STAT_STARTED
);
2981 /* Start data flow (TX/RX) */
2982 b43legacy_mac_enable(dev
);
2983 b43legacy_write32(dev
, B43legacy_MMIO_GEN_IRQ_MASK
, dev
->irq_mask
);
2985 /* Start maintenance work */
2986 b43legacy_periodic_tasks_setup(dev
);
2988 b43legacydbg(dev
->wl
, "Wireless interface started\n");
2993 /* Get PHY and RADIO versioning numbers */
2994 static int b43legacy_phy_versioning(struct b43legacy_wldev
*dev
)
2996 struct b43legacy_phy
*phy
= &dev
->phy
;
3004 int unsupported
= 0;
3006 /* Get PHY versioning */
3007 tmp
= b43legacy_read16(dev
, B43legacy_MMIO_PHY_VER
);
3008 analog_type
= (tmp
& B43legacy_PHYVER_ANALOG
)
3009 >> B43legacy_PHYVER_ANALOG_SHIFT
;
3010 phy_type
= (tmp
& B43legacy_PHYVER_TYPE
) >> B43legacy_PHYVER_TYPE_SHIFT
;
3011 phy_rev
= (tmp
& B43legacy_PHYVER_VERSION
);
3013 case B43legacy_PHYTYPE_B
:
3014 if (phy_rev
!= 2 && phy_rev
!= 4
3015 && phy_rev
!= 6 && phy_rev
!= 7)
3018 case B43legacy_PHYTYPE_G
:
3026 b43legacyerr(dev
->wl
, "FOUND UNSUPPORTED PHY "
3027 "(Analog %u, Type %u, Revision %u)\n",
3028 analog_type
, phy_type
, phy_rev
);
3031 b43legacydbg(dev
->wl
, "Found PHY: Analog %u, Type %u, Revision %u\n",
3032 analog_type
, phy_type
, phy_rev
);
3035 /* Get RADIO versioning */
3036 if (dev
->dev
->bus
->chip_id
== 0x4317) {
3037 if (dev
->dev
->bus
->chip_rev
== 0)
3039 else if (dev
->dev
->bus
->chip_rev
== 1)
3044 b43legacy_write16(dev
, B43legacy_MMIO_RADIO_CONTROL
,
3045 B43legacy_RADIOCTL_ID
);
3046 tmp
= b43legacy_read16(dev
, B43legacy_MMIO_RADIO_DATA_HIGH
);
3048 b43legacy_write16(dev
, B43legacy_MMIO_RADIO_CONTROL
,
3049 B43legacy_RADIOCTL_ID
);
3050 tmp
|= b43legacy_read16(dev
, B43legacy_MMIO_RADIO_DATA_LOW
);
3052 radio_manuf
= (tmp
& 0x00000FFF);
3053 radio_ver
= (tmp
& 0x0FFFF000) >> 12;
3054 radio_rev
= (tmp
& 0xF0000000) >> 28;
3056 case B43legacy_PHYTYPE_B
:
3057 if ((radio_ver
& 0xFFF0) != 0x2050)
3060 case B43legacy_PHYTYPE_G
:
3061 if (radio_ver
!= 0x2050)
3065 B43legacy_BUG_ON(1);
3068 b43legacyerr(dev
->wl
, "FOUND UNSUPPORTED RADIO "
3069 "(Manuf 0x%X, Version 0x%X, Revision %u)\n",
3070 radio_manuf
, radio_ver
, radio_rev
);
3073 b43legacydbg(dev
->wl
, "Found Radio: Manuf 0x%X, Version 0x%X,"
3074 " Revision %u\n", radio_manuf
, radio_ver
, radio_rev
);
3077 phy
->radio_manuf
= radio_manuf
;
3078 phy
->radio_ver
= radio_ver
;
3079 phy
->radio_rev
= radio_rev
;
3081 phy
->analog
= analog_type
;
3082 phy
->type
= phy_type
;
3088 static void setup_struct_phy_for_init(struct b43legacy_wldev
*dev
,
3089 struct b43legacy_phy
*phy
)
3091 struct b43legacy_lopair
*lo
;
3094 memset(phy
->minlowsig
, 0xFF, sizeof(phy
->minlowsig
));
3095 memset(phy
->minlowsigpos
, 0, sizeof(phy
->minlowsigpos
));
3097 /* Assume the radio is enabled. If it's not enabled, the state will
3098 * immediately get fixed on the first periodic work run. */
3099 dev
->radio_hw_enable
= true;
3101 phy
->savedpctlreg
= 0xFFFF;
3102 phy
->aci_enable
= false;
3103 phy
->aci_wlan_automatic
= false;
3104 phy
->aci_hw_rssi
= false;
3106 lo
= phy
->_lo_pairs
;
3108 memset(lo
, 0, sizeof(struct b43legacy_lopair
) *
3109 B43legacy_LO_COUNT
);
3110 phy
->max_lb_gain
= 0;
3111 phy
->trsw_rx_gain
= 0;
3113 /* Set default attenuation values. */
3114 phy
->bbatt
= b43legacy_default_baseband_attenuation(dev
);
3115 phy
->rfatt
= b43legacy_default_radio_attenuation(dev
);
3116 phy
->txctl1
= b43legacy_default_txctl1(dev
);
3117 phy
->txpwr_offset
= 0;
3120 phy
->nrssislope
= 0;
3121 for (i
= 0; i
< ARRAY_SIZE(phy
->nrssi
); i
++)
3122 phy
->nrssi
[i
] = -1000;
3123 for (i
= 0; i
< ARRAY_SIZE(phy
->nrssi_lt
); i
++)
3124 phy
->nrssi_lt
[i
] = i
;
3126 phy
->lofcal
= 0xFFFF;
3127 phy
->initval
= 0xFFFF;
3129 phy
->interfmode
= B43legacy_INTERFMODE_NONE
;
3130 phy
->channel
= 0xFF;
3133 static void setup_struct_wldev_for_init(struct b43legacy_wldev
*dev
)
3136 dev
->dfq_valid
= false;
3139 memset(&dev
->stats
, 0, sizeof(dev
->stats
));
3141 setup_struct_phy_for_init(dev
, &dev
->phy
);
3143 /* IRQ related flags */
3144 dev
->irq_reason
= 0;
3145 memset(dev
->dma_reason
, 0, sizeof(dev
->dma_reason
));
3146 dev
->irq_mask
= B43legacy_IRQ_MASKTEMPLATE
;
3148 dev
->mac_suspended
= 1;
3150 /* Noise calculation context */
3151 memset(&dev
->noisecalc
, 0, sizeof(dev
->noisecalc
));
3154 static void b43legacy_set_synth_pu_delay(struct b43legacy_wldev
*dev
,
3156 u16 pu_delay
= 1050;
3158 if (b43legacy_is_mode(dev
->wl
, NL80211_IFTYPE_ADHOC
) || idle
)
3160 if ((dev
->phy
.radio_ver
== 0x2050) && (dev
->phy
.radio_rev
== 8))
3161 pu_delay
= max(pu_delay
, (u16
)2400);
3163 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
,
3164 B43legacy_SHM_SH_SPUWKUP
, pu_delay
);
3167 /* Set the TSF CFP pre-TargetBeaconTransmissionTime. */
3168 static void b43legacy_set_pretbtt(struct b43legacy_wldev
*dev
)
3172 /* The time value is in microseconds. */
3173 if (b43legacy_is_mode(dev
->wl
, NL80211_IFTYPE_ADHOC
))
3177 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
,
3178 B43legacy_SHM_SH_PRETBTT
, pretbtt
);
3179 b43legacy_write16(dev
, B43legacy_MMIO_TSF_CFP_PRETBTT
, pretbtt
);
3182 /* Shutdown a wireless core */
3183 /* Locking: wl->mutex */
3184 static void b43legacy_wireless_core_exit(struct b43legacy_wldev
*dev
)
3186 struct b43legacy_phy
*phy
= &dev
->phy
;
3189 B43legacy_WARN_ON(b43legacy_status(dev
) > B43legacy_STAT_INITIALIZED
);
3190 if (b43legacy_status(dev
) != B43legacy_STAT_INITIALIZED
)
3192 b43legacy_set_status(dev
, B43legacy_STAT_UNINIT
);
3194 /* Stop the microcode PSM. */
3195 macctl
= b43legacy_read32(dev
, B43legacy_MMIO_MACCTL
);
3196 macctl
&= ~B43legacy_MACCTL_PSM_RUN
;
3197 macctl
|= B43legacy_MACCTL_PSM_JMP0
;
3198 b43legacy_write32(dev
, B43legacy_MMIO_MACCTL
, macctl
);
3200 b43legacy_leds_exit(dev
);
3201 b43legacy_rng_exit(dev
->wl
);
3202 b43legacy_pio_free(dev
);
3203 b43legacy_dma_free(dev
);
3204 b43legacy_chip_exit(dev
);
3205 b43legacy_radio_turn_off(dev
, 1);
3206 b43legacy_switch_analog(dev
, 0);
3207 if (phy
->dyn_tssi_tbl
)
3208 kfree(phy
->tssi2dbm
);
3209 kfree(phy
->lo_control
);
3210 phy
->lo_control
= NULL
;
3211 if (dev
->wl
->current_beacon
) {
3212 dev_kfree_skb_any(dev
->wl
->current_beacon
);
3213 dev
->wl
->current_beacon
= NULL
;
3216 ssb_device_disable(dev
->dev
, 0);
3217 ssb_bus_may_powerdown(dev
->dev
->bus
);
3220 static void prepare_phy_data_for_init(struct b43legacy_wldev
*dev
)
3222 struct b43legacy_phy
*phy
= &dev
->phy
;
3225 /* Set default attenuation values. */
3226 phy
->bbatt
= b43legacy_default_baseband_attenuation(dev
);
3227 phy
->rfatt
= b43legacy_default_radio_attenuation(dev
);
3228 phy
->txctl1
= b43legacy_default_txctl1(dev
);
3229 phy
->txctl2
= 0xFFFF;
3230 phy
->txpwr_offset
= 0;
3233 phy
->nrssislope
= 0;
3234 for (i
= 0; i
< ARRAY_SIZE(phy
->nrssi
); i
++)
3235 phy
->nrssi
[i
] = -1000;
3236 for (i
= 0; i
< ARRAY_SIZE(phy
->nrssi_lt
); i
++)
3237 phy
->nrssi_lt
[i
] = i
;
3239 phy
->lofcal
= 0xFFFF;
3240 phy
->initval
= 0xFFFF;
3242 phy
->aci_enable
= false;
3243 phy
->aci_wlan_automatic
= false;
3244 phy
->aci_hw_rssi
= false;
3246 phy
->antenna_diversity
= 0xFFFF;
3247 memset(phy
->minlowsig
, 0xFF, sizeof(phy
->minlowsig
));
3248 memset(phy
->minlowsigpos
, 0, sizeof(phy
->minlowsigpos
));
3251 phy
->calibrated
= 0;
3254 memset(phy
->_lo_pairs
, 0,
3255 sizeof(struct b43legacy_lopair
) * B43legacy_LO_COUNT
);
3256 memset(phy
->loopback_gain
, 0, sizeof(phy
->loopback_gain
));
3259 /* Initialize a wireless core */
3260 static int b43legacy_wireless_core_init(struct b43legacy_wldev
*dev
)
3262 struct b43legacy_wl
*wl
= dev
->wl
;
3263 struct ssb_bus
*bus
= dev
->dev
->bus
;
3264 struct b43legacy_phy
*phy
= &dev
->phy
;
3265 struct ssb_sprom
*sprom
= &dev
->dev
->bus
->sprom
;
3270 B43legacy_WARN_ON(b43legacy_status(dev
) != B43legacy_STAT_UNINIT
);
3272 err
= ssb_bus_powerup(bus
, 0);
3275 if (!ssb_device_is_enabled(dev
->dev
)) {
3276 tmp
= phy
->gmode
? B43legacy_TMSLOW_GMODE
: 0;
3277 b43legacy_wireless_core_reset(dev
, tmp
);
3280 if ((phy
->type
== B43legacy_PHYTYPE_B
) ||
3281 (phy
->type
== B43legacy_PHYTYPE_G
)) {
3282 phy
->_lo_pairs
= kzalloc(sizeof(struct b43legacy_lopair
)
3283 * B43legacy_LO_COUNT
,
3285 if (!phy
->_lo_pairs
)
3288 setup_struct_wldev_for_init(dev
);
3290 err
= b43legacy_phy_init_tssi2dbm_table(dev
);
3292 goto err_kfree_lo_control
;
3294 /* Enable IRQ routing to this device. */
3295 ssb_pcicore_dev_irqvecs_enable(&bus
->pcicore
, dev
->dev
);
3297 prepare_phy_data_for_init(dev
);
3298 b43legacy_phy_calibrate(dev
);
3299 err
= b43legacy_chip_init(dev
);
3301 goto err_kfree_tssitbl
;
3302 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
,
3303 B43legacy_SHM_SH_WLCOREREV
,
3304 dev
->dev
->id
.revision
);
3305 hf
= b43legacy_hf_read(dev
);
3306 if (phy
->type
== B43legacy_PHYTYPE_G
) {
3307 hf
|= B43legacy_HF_SYMW
;
3309 hf
|= B43legacy_HF_GDCW
;
3310 if (sprom
->boardflags_lo
& B43legacy_BFL_PACTRL
)
3311 hf
|= B43legacy_HF_OFDMPABOOST
;
3312 } else if (phy
->type
== B43legacy_PHYTYPE_B
) {
3313 hf
|= B43legacy_HF_SYMW
;
3314 if (phy
->rev
>= 2 && phy
->radio_ver
== 0x2050)
3315 hf
&= ~B43legacy_HF_GDCW
;
3317 b43legacy_hf_write(dev
, hf
);
3319 b43legacy_set_retry_limits(dev
,
3320 B43legacy_DEFAULT_SHORT_RETRY_LIMIT
,
3321 B43legacy_DEFAULT_LONG_RETRY_LIMIT
);
3323 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
,
3325 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
,
3328 /* Disable sending probe responses from firmware.
3329 * Setting the MaxTime to one usec will always trigger
3330 * a timeout, so we never send any probe resp.
3331 * A timeout of zero is infinite. */
3332 b43legacy_shm_write16(dev
, B43legacy_SHM_SHARED
,
3333 B43legacy_SHM_SH_PRMAXTIME
, 1);
3335 b43legacy_rate_memory_init(dev
);
3337 /* Minimum Contention Window */
3338 if (phy
->type
== B43legacy_PHYTYPE_B
)
3339 b43legacy_shm_write16(dev
, B43legacy_SHM_WIRELESS
,
3342 b43legacy_shm_write16(dev
, B43legacy_SHM_WIRELESS
,
3344 /* Maximum Contention Window */
3345 b43legacy_shm_write16(dev
, B43legacy_SHM_WIRELESS
,
3349 if (b43legacy_using_pio(dev
))
3350 err
= b43legacy_pio_init(dev
);
3352 err
= b43legacy_dma_init(dev
);
3354 b43legacy_qos_init(dev
);
3356 } while (err
== -EAGAIN
);
3360 b43legacy_set_synth_pu_delay(dev
, 1);
3362 ssb_bus_powerup(bus
, 1); /* Enable dynamic PCTL */
3363 b43legacy_upload_card_macaddress(dev
);
3364 b43legacy_security_init(dev
);
3365 b43legacy_rng_init(wl
);
3367 ieee80211_wake_queues(dev
->wl
->hw
);
3368 b43legacy_set_status(dev
, B43legacy_STAT_INITIALIZED
);
3370 b43legacy_leds_init(dev
);
3375 b43legacy_chip_exit(dev
);
3377 if (phy
->dyn_tssi_tbl
)
3378 kfree(phy
->tssi2dbm
);
3379 err_kfree_lo_control
:
3380 kfree(phy
->lo_control
);
3381 phy
->lo_control
= NULL
;
3382 ssb_bus_may_powerdown(bus
);
3383 B43legacy_WARN_ON(b43legacy_status(dev
) != B43legacy_STAT_UNINIT
);
3387 static int b43legacy_op_add_interface(struct ieee80211_hw
*hw
,
3388 struct ieee80211_vif
*vif
)
3390 struct b43legacy_wl
*wl
= hw_to_b43legacy_wl(hw
);
3391 struct b43legacy_wldev
*dev
;
3392 unsigned long flags
;
3393 int err
= -EOPNOTSUPP
;
3395 /* TODO: allow WDS/AP devices to coexist */
3397 if (vif
->type
!= NL80211_IFTYPE_AP
&&
3398 vif
->type
!= NL80211_IFTYPE_STATION
&&
3399 vif
->type
!= NL80211_IFTYPE_WDS
&&
3400 vif
->type
!= NL80211_IFTYPE_ADHOC
)
3403 mutex_lock(&wl
->mutex
);
3405 goto out_mutex_unlock
;
3407 b43legacydbg(wl
, "Adding Interface type %d\n", vif
->type
);
3409 dev
= wl
->current_dev
;
3410 wl
->operating
= true;
3412 wl
->if_type
= vif
->type
;
3413 memcpy(wl
->mac_addr
, vif
->addr
, ETH_ALEN
);
3415 spin_lock_irqsave(&wl
->irq_lock
, flags
);
3416 b43legacy_adjust_opmode(dev
);
3417 b43legacy_set_pretbtt(dev
);
3418 b43legacy_set_synth_pu_delay(dev
, 0);
3419 b43legacy_upload_card_macaddress(dev
);
3420 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
3424 mutex_unlock(&wl
->mutex
);
3429 static void b43legacy_op_remove_interface(struct ieee80211_hw
*hw
,
3430 struct ieee80211_vif
*vif
)
3432 struct b43legacy_wl
*wl
= hw_to_b43legacy_wl(hw
);
3433 struct b43legacy_wldev
*dev
= wl
->current_dev
;
3434 unsigned long flags
;
3436 b43legacydbg(wl
, "Removing Interface type %d\n", vif
->type
);
3438 mutex_lock(&wl
->mutex
);
3440 B43legacy_WARN_ON(!wl
->operating
);
3441 B43legacy_WARN_ON(wl
->vif
!= vif
);
3444 wl
->operating
= false;
3446 spin_lock_irqsave(&wl
->irq_lock
, flags
);
3447 b43legacy_adjust_opmode(dev
);
3448 memset(wl
->mac_addr
, 0, ETH_ALEN
);
3449 b43legacy_upload_card_macaddress(dev
);
3450 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
3452 mutex_unlock(&wl
->mutex
);
3455 static int b43legacy_op_start(struct ieee80211_hw
*hw
)
3457 struct b43legacy_wl
*wl
= hw_to_b43legacy_wl(hw
);
3458 struct b43legacy_wldev
*dev
= wl
->current_dev
;
3462 /* Kill all old instance specific information to make sure
3463 * the card won't use it in the short timeframe between start
3464 * and mac80211 reconfiguring it. */
3465 memset(wl
->bssid
, 0, ETH_ALEN
);
3466 memset(wl
->mac_addr
, 0, ETH_ALEN
);
3467 wl
->filter_flags
= 0;
3468 wl
->beacon0_uploaded
= false;
3469 wl
->beacon1_uploaded
= false;
3470 wl
->beacon_templates_virgin
= true;
3471 wl
->radio_enabled
= true;
3473 mutex_lock(&wl
->mutex
);
3475 if (b43legacy_status(dev
) < B43legacy_STAT_INITIALIZED
) {
3476 err
= b43legacy_wireless_core_init(dev
);
3478 goto out_mutex_unlock
;
3482 if (b43legacy_status(dev
) < B43legacy_STAT_STARTED
) {
3483 err
= b43legacy_wireless_core_start(dev
);
3486 b43legacy_wireless_core_exit(dev
);
3487 goto out_mutex_unlock
;
3491 wiphy_rfkill_start_polling(hw
->wiphy
);
3494 mutex_unlock(&wl
->mutex
);
3499 static void b43legacy_op_stop(struct ieee80211_hw
*hw
)
3501 struct b43legacy_wl
*wl
= hw_to_b43legacy_wl(hw
);
3502 struct b43legacy_wldev
*dev
= wl
->current_dev
;
3504 cancel_work_sync(&(wl
->beacon_update_trigger
));
3506 mutex_lock(&wl
->mutex
);
3507 if (b43legacy_status(dev
) >= B43legacy_STAT_STARTED
)
3508 b43legacy_wireless_core_stop(dev
);
3509 b43legacy_wireless_core_exit(dev
);
3510 wl
->radio_enabled
= false;
3511 mutex_unlock(&wl
->mutex
);
3514 static int b43legacy_op_beacon_set_tim(struct ieee80211_hw
*hw
,
3515 struct ieee80211_sta
*sta
, bool set
)
3517 struct b43legacy_wl
*wl
= hw_to_b43legacy_wl(hw
);
3518 unsigned long flags
;
3520 spin_lock_irqsave(&wl
->irq_lock
, flags
);
3521 b43legacy_update_templates(wl
);
3522 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
3527 static int b43legacy_op_get_survey(struct ieee80211_hw
*hw
, int idx
,
3528 struct survey_info
*survey
)
3530 struct b43legacy_wl
*wl
= hw_to_b43legacy_wl(hw
);
3531 struct b43legacy_wldev
*dev
= wl
->current_dev
;
3532 struct ieee80211_conf
*conf
= &hw
->conf
;
3537 survey
->channel
= conf
->channel
;
3538 survey
->filled
= SURVEY_INFO_NOISE_DBM
;
3539 survey
->noise
= dev
->stats
.link_noise
;
3544 static const struct ieee80211_ops b43legacy_hw_ops
= {
3545 .tx
= b43legacy_op_tx
,
3546 .conf_tx
= b43legacy_op_conf_tx
,
3547 .add_interface
= b43legacy_op_add_interface
,
3548 .remove_interface
= b43legacy_op_remove_interface
,
3549 .config
= b43legacy_op_dev_config
,
3550 .bss_info_changed
= b43legacy_op_bss_info_changed
,
3551 .configure_filter
= b43legacy_op_configure_filter
,
3552 .get_stats
= b43legacy_op_get_stats
,
3553 .start
= b43legacy_op_start
,
3554 .stop
= b43legacy_op_stop
,
3555 .set_tim
= b43legacy_op_beacon_set_tim
,
3556 .get_survey
= b43legacy_op_get_survey
,
3557 .rfkill_poll
= b43legacy_rfkill_poll
,
3560 /* Hard-reset the chip. Do not call this directly.
3561 * Use b43legacy_controller_restart()
3563 static void b43legacy_chip_reset(struct work_struct
*work
)
3565 struct b43legacy_wldev
*dev
=
3566 container_of(work
, struct b43legacy_wldev
, restart_work
);
3567 struct b43legacy_wl
*wl
= dev
->wl
;
3571 mutex_lock(&wl
->mutex
);
3573 prev_status
= b43legacy_status(dev
);
3574 /* Bring the device down... */
3575 if (prev_status
>= B43legacy_STAT_STARTED
)
3576 b43legacy_wireless_core_stop(dev
);
3577 if (prev_status
>= B43legacy_STAT_INITIALIZED
)
3578 b43legacy_wireless_core_exit(dev
);
3580 /* ...and up again. */
3581 if (prev_status
>= B43legacy_STAT_INITIALIZED
) {
3582 err
= b43legacy_wireless_core_init(dev
);
3586 if (prev_status
>= B43legacy_STAT_STARTED
) {
3587 err
= b43legacy_wireless_core_start(dev
);
3589 b43legacy_wireless_core_exit(dev
);
3595 wl
->current_dev
= NULL
; /* Failed to init the dev. */
3596 mutex_unlock(&wl
->mutex
);
3598 b43legacyerr(wl
, "Controller restart FAILED\n");
3600 b43legacyinfo(wl
, "Controller restarted\n");
3603 static int b43legacy_setup_modes(struct b43legacy_wldev
*dev
,
3607 struct ieee80211_hw
*hw
= dev
->wl
->hw
;
3608 struct b43legacy_phy
*phy
= &dev
->phy
;
3610 phy
->possible_phymodes
= 0;
3612 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
3613 &b43legacy_band_2GHz_BPHY
;
3614 phy
->possible_phymodes
|= B43legacy_PHYMODE_B
;
3618 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
3619 &b43legacy_band_2GHz_GPHY
;
3620 phy
->possible_phymodes
|= B43legacy_PHYMODE_G
;
3626 static void b43legacy_wireless_core_detach(struct b43legacy_wldev
*dev
)
3628 /* We release firmware that late to not be required to re-request
3629 * is all the time when we reinit the core. */
3630 b43legacy_release_firmware(dev
);
3633 static int b43legacy_wireless_core_attach(struct b43legacy_wldev
*dev
)
3635 struct b43legacy_wl
*wl
= dev
->wl
;
3636 struct ssb_bus
*bus
= dev
->dev
->bus
;
3637 struct pci_dev
*pdev
= (bus
->bustype
== SSB_BUSTYPE_PCI
) ? bus
->host_pci
: NULL
;
3643 /* Do NOT do any device initialization here.
3644 * Do it in wireless_core_init() instead.
3645 * This function is for gathering basic information about the HW, only.
3646 * Also some structs may be set up here. But most likely you want to
3647 * have that in core_init(), too.
3650 err
= ssb_bus_powerup(bus
, 0);
3652 b43legacyerr(wl
, "Bus powerup failed\n");
3655 /* Get the PHY type. */
3656 if (dev
->dev
->id
.revision
>= 5) {
3659 tmshigh
= ssb_read32(dev
->dev
, SSB_TMSHIGH
);
3660 have_gphy
= !!(tmshigh
& B43legacy_TMSHIGH_GPHY
);
3663 } else if (dev
->dev
->id
.revision
== 4)
3668 dev
->phy
.gmode
= (have_gphy
|| have_bphy
);
3669 dev
->phy
.radio_on
= true;
3670 tmp
= dev
->phy
.gmode
? B43legacy_TMSLOW_GMODE
: 0;
3671 b43legacy_wireless_core_reset(dev
, tmp
);
3673 err
= b43legacy_phy_versioning(dev
);
3676 /* Check if this device supports multiband. */
3678 (pdev
->device
!= 0x4312 &&
3679 pdev
->device
!= 0x4319 &&
3680 pdev
->device
!= 0x4324)) {
3681 /* No multiband support. */
3684 switch (dev
->phy
.type
) {
3685 case B43legacy_PHYTYPE_B
:
3688 case B43legacy_PHYTYPE_G
:
3692 B43legacy_BUG_ON(1);
3695 dev
->phy
.gmode
= (have_gphy
|| have_bphy
);
3696 tmp
= dev
->phy
.gmode
? B43legacy_TMSLOW_GMODE
: 0;
3697 b43legacy_wireless_core_reset(dev
, tmp
);
3699 err
= b43legacy_validate_chipaccess(dev
);
3702 err
= b43legacy_setup_modes(dev
, have_bphy
, have_gphy
);
3706 /* Now set some default "current_dev" */
3707 if (!wl
->current_dev
)
3708 wl
->current_dev
= dev
;
3709 INIT_WORK(&dev
->restart_work
, b43legacy_chip_reset
);
3711 b43legacy_radio_turn_off(dev
, 1);
3712 b43legacy_switch_analog(dev
, 0);
3713 ssb_device_disable(dev
->dev
, 0);
3714 ssb_bus_may_powerdown(bus
);
3720 ssb_bus_may_powerdown(bus
);
3724 static void b43legacy_one_core_detach(struct ssb_device
*dev
)
3726 struct b43legacy_wldev
*wldev
;
3727 struct b43legacy_wl
*wl
;
3729 /* Do not cancel ieee80211-workqueue based work here.
3730 * See comment in b43legacy_remove(). */
3732 wldev
= ssb_get_drvdata(dev
);
3734 b43legacy_debugfs_remove_device(wldev
);
3735 b43legacy_wireless_core_detach(wldev
);
3736 list_del(&wldev
->list
);
3738 ssb_set_drvdata(dev
, NULL
);
3742 static int b43legacy_one_core_attach(struct ssb_device
*dev
,
3743 struct b43legacy_wl
*wl
)
3745 struct b43legacy_wldev
*wldev
;
3748 wldev
= kzalloc(sizeof(*wldev
), GFP_KERNEL
);
3754 b43legacy_set_status(wldev
, B43legacy_STAT_UNINIT
);
3755 wldev
->bad_frames_preempt
= modparam_bad_frames_preempt
;
3756 tasklet_init(&wldev
->isr_tasklet
,
3757 (void (*)(unsigned long))b43legacy_interrupt_tasklet
,
3758 (unsigned long)wldev
);
3760 wldev
->__using_pio
= true;
3761 INIT_LIST_HEAD(&wldev
->list
);
3763 err
= b43legacy_wireless_core_attach(wldev
);
3765 goto err_kfree_wldev
;
3767 list_add(&wldev
->list
, &wl
->devlist
);
3769 ssb_set_drvdata(dev
, wldev
);
3770 b43legacy_debugfs_add_device(wldev
);
3779 static void b43legacy_sprom_fixup(struct ssb_bus
*bus
)
3781 /* boardflags workarounds */
3782 if (bus
->boardinfo
.vendor
== PCI_VENDOR_ID_APPLE
&&
3783 bus
->boardinfo
.type
== 0x4E &&
3784 bus
->boardinfo
.rev
> 0x40)
3785 bus
->sprom
.boardflags_lo
|= B43legacy_BFL_PACTRL
;
3788 static void b43legacy_wireless_exit(struct ssb_device
*dev
,
3789 struct b43legacy_wl
*wl
)
3791 struct ieee80211_hw
*hw
= wl
->hw
;
3793 ssb_set_devtypedata(dev
, NULL
);
3794 ieee80211_free_hw(hw
);
3797 static int b43legacy_wireless_init(struct ssb_device
*dev
)
3799 struct ssb_sprom
*sprom
= &dev
->bus
->sprom
;
3800 struct ieee80211_hw
*hw
;
3801 struct b43legacy_wl
*wl
;
3805 b43legacy_sprom_fixup(dev
->bus
);
3807 hw
= ieee80211_alloc_hw(sizeof(*wl
), &b43legacy_hw_ops
);
3809 b43legacyerr(NULL
, "Could not allocate ieee80211 device\n");
3814 hw
->flags
= IEEE80211_HW_RX_INCLUDES_FCS
|
3815 IEEE80211_HW_SIGNAL_DBM
;
3816 hw
->wiphy
->interface_modes
=
3817 BIT(NL80211_IFTYPE_AP
) |
3818 BIT(NL80211_IFTYPE_STATION
) |
3819 BIT(NL80211_IFTYPE_WDS
) |
3820 BIT(NL80211_IFTYPE_ADHOC
);
3821 hw
->queues
= 1; /* FIXME: hardware has more queues */
3823 SET_IEEE80211_DEV(hw
, dev
->dev
);
3824 if (is_valid_ether_addr(sprom
->et1mac
))
3825 SET_IEEE80211_PERM_ADDR(hw
, sprom
->et1mac
);
3827 SET_IEEE80211_PERM_ADDR(hw
, sprom
->il0mac
);
3829 /* Get and initialize struct b43legacy_wl */
3830 wl
= hw_to_b43legacy_wl(hw
);
3831 memset(wl
, 0, sizeof(*wl
));
3833 spin_lock_init(&wl
->irq_lock
);
3834 spin_lock_init(&wl
->leds_lock
);
3835 mutex_init(&wl
->mutex
);
3836 INIT_LIST_HEAD(&wl
->devlist
);
3837 INIT_WORK(&wl
->beacon_update_trigger
, b43legacy_beacon_update_trigger_work
);
3838 INIT_WORK(&wl
->tx_work
, b43legacy_tx_work
);
3840 /* Initialize queues and flags. */
3841 for (queue_num
= 0; queue_num
< B43legacy_QOS_QUEUE_NUM
; queue_num
++) {
3842 skb_queue_head_init(&wl
->tx_queue
[queue_num
]);
3843 wl
->tx_queue_stopped
[queue_num
] = 0;
3846 ssb_set_devtypedata(dev
, wl
);
3847 b43legacyinfo(wl
, "Broadcom %04X WLAN found (core revision %u)\n",
3848 dev
->bus
->chip_id
, dev
->id
.revision
);
3854 static int b43legacy_probe(struct ssb_device
*dev
,
3855 const struct ssb_device_id
*id
)
3857 struct b43legacy_wl
*wl
;
3861 wl
= ssb_get_devtypedata(dev
);
3863 /* Probing the first core - setup common struct b43legacy_wl */
3865 err
= b43legacy_wireless_init(dev
);
3868 wl
= ssb_get_devtypedata(dev
);
3869 B43legacy_WARN_ON(!wl
);
3871 err
= b43legacy_one_core_attach(dev
, wl
);
3873 goto err_wireless_exit
;
3875 /* setup and start work to load firmware */
3876 INIT_WORK(&wl
->firmware_load
, b43legacy_request_firmware
);
3877 schedule_work(&wl
->firmware_load
);
3884 b43legacy_wireless_exit(dev
, wl
);
3888 static void b43legacy_remove(struct ssb_device
*dev
)
3890 struct b43legacy_wl
*wl
= ssb_get_devtypedata(dev
);
3891 struct b43legacy_wldev
*wldev
= ssb_get_drvdata(dev
);
3893 /* We must cancel any work here before unregistering from ieee80211,
3894 * as the ieee80211 unreg will destroy the workqueue. */
3895 cancel_work_sync(&wldev
->restart_work
);
3896 cancel_work_sync(&wl
->firmware_load
);
3898 B43legacy_WARN_ON(!wl
);
3899 if (wl
->current_dev
== wldev
)
3900 ieee80211_unregister_hw(wl
->hw
);
3902 b43legacy_one_core_detach(dev
);
3904 if (list_empty(&wl
->devlist
))
3905 /* Last core on the chip unregistered.
3906 * We can destroy common struct b43legacy_wl.
3908 b43legacy_wireless_exit(dev
, wl
);
3911 /* Perform a hardware reset. This can be called from any context. */
3912 void b43legacy_controller_restart(struct b43legacy_wldev
*dev
,
3915 /* Must avoid requeueing, if we are in shutdown. */
3916 if (b43legacy_status(dev
) < B43legacy_STAT_INITIALIZED
)
3918 b43legacyinfo(dev
->wl
, "Controller RESET (%s) ...\n", reason
);
3919 ieee80211_queue_work(dev
->wl
->hw
, &dev
->restart_work
);
3924 static int b43legacy_suspend(struct ssb_device
*dev
, pm_message_t state
)
3926 struct b43legacy_wldev
*wldev
= ssb_get_drvdata(dev
);
3927 struct b43legacy_wl
*wl
= wldev
->wl
;
3929 b43legacydbg(wl
, "Suspending...\n");
3931 mutex_lock(&wl
->mutex
);
3932 wldev
->suspend_init_status
= b43legacy_status(wldev
);
3933 if (wldev
->suspend_init_status
>= B43legacy_STAT_STARTED
)
3934 b43legacy_wireless_core_stop(wldev
);
3935 if (wldev
->suspend_init_status
>= B43legacy_STAT_INITIALIZED
)
3936 b43legacy_wireless_core_exit(wldev
);
3937 mutex_unlock(&wl
->mutex
);
3939 b43legacydbg(wl
, "Device suspended.\n");
3944 static int b43legacy_resume(struct ssb_device
*dev
)
3946 struct b43legacy_wldev
*wldev
= ssb_get_drvdata(dev
);
3947 struct b43legacy_wl
*wl
= wldev
->wl
;
3950 b43legacydbg(wl
, "Resuming...\n");
3952 mutex_lock(&wl
->mutex
);
3953 if (wldev
->suspend_init_status
>= B43legacy_STAT_INITIALIZED
) {
3954 err
= b43legacy_wireless_core_init(wldev
);
3956 b43legacyerr(wl
, "Resume failed at core init\n");
3960 if (wldev
->suspend_init_status
>= B43legacy_STAT_STARTED
) {
3961 err
= b43legacy_wireless_core_start(wldev
);
3963 b43legacy_wireless_core_exit(wldev
);
3964 b43legacyerr(wl
, "Resume failed at core start\n");
3969 b43legacydbg(wl
, "Device resumed.\n");
3971 mutex_unlock(&wl
->mutex
);
3975 #else /* CONFIG_PM */
3976 # define b43legacy_suspend NULL
3977 # define b43legacy_resume NULL
3978 #endif /* CONFIG_PM */
3980 static struct ssb_driver b43legacy_ssb_driver
= {
3981 .name
= KBUILD_MODNAME
,
3982 .id_table
= b43legacy_ssb_tbl
,
3983 .probe
= b43legacy_probe
,
3984 .remove
= b43legacy_remove
,
3985 .suspend
= b43legacy_suspend
,
3986 .resume
= b43legacy_resume
,
3989 static void b43legacy_print_driverinfo(void)
3991 const char *feat_pci
= "", *feat_leds
= "",
3992 *feat_pio
= "", *feat_dma
= "";
3994 #ifdef CONFIG_B43LEGACY_PCI_AUTOSELECT
3997 #ifdef CONFIG_B43LEGACY_LEDS
4000 #ifdef CONFIG_B43LEGACY_PIO
4003 #ifdef CONFIG_B43LEGACY_DMA
4006 printk(KERN_INFO
"Broadcom 43xx-legacy driver loaded "
4007 "[ Features: %s%s%s%s ]\n",
4008 feat_pci
, feat_leds
, feat_pio
, feat_dma
);
4011 static int __init
b43legacy_init(void)
4015 b43legacy_debugfs_init();
4017 err
= ssb_driver_register(&b43legacy_ssb_driver
);
4021 b43legacy_print_driverinfo();
4026 b43legacy_debugfs_exit();
4030 static void __exit
b43legacy_exit(void)
4032 ssb_driver_unregister(&b43legacy_ssb_driver
);
4033 b43legacy_debugfs_exit();
4036 module_init(b43legacy_init
)
4037 module_exit(b43legacy_exit
)