3 Broadcom B43 wireless driver
5 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>
6 Copyright (c) 2005 Stefano Brivio <stefano.brivio@polimi.it>
7 Copyright (c) 2005, 2006 Michael Buesch <mb@bu3sch.de>
8 Copyright (c) 2005 Danny van Dyk <kugelfang@gentoo.org>
9 Copyright (c) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch>
11 Some parts of the code in this file are derived from the ipw2200
12 driver Copyright(c) 2003 - 2004 Intel Corporation.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; see the file COPYING. If not, write to
26 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
27 Boston, MA 02110-1301, USA.
31 #include <linux/delay.h>
32 #include <linux/init.h>
33 #include <linux/moduleparam.h>
34 #include <linux/if_arp.h>
35 #include <linux/etherdevice.h>
36 #include <linux/version.h>
37 #include <linux/firmware.h>
38 #include <linux/wireless.h>
39 #include <linux/workqueue.h>
40 #include <linux/skbuff.h>
42 #include <linux/dma-mapping.h>
43 #include <asm/unaligned.h>
55 MODULE_DESCRIPTION("Broadcom B43 wireless driver");
56 MODULE_AUTHOR("Martin Langer");
57 MODULE_AUTHOR("Stefano Brivio");
58 MODULE_AUTHOR("Michael Buesch");
59 MODULE_LICENSE("GPL");
61 MODULE_FIRMWARE(B43_SUPPORTED_FIRMWARE_ID
);
64 static int modparam_bad_frames_preempt
;
65 module_param_named(bad_frames_preempt
, modparam_bad_frames_preempt
, int, 0444);
66 MODULE_PARM_DESC(bad_frames_preempt
,
67 "enable(1) / disable(0) Bad Frames Preemption");
69 static char modparam_fwpostfix
[16];
70 module_param_string(fwpostfix
, modparam_fwpostfix
, 16, 0444);
71 MODULE_PARM_DESC(fwpostfix
, "Postfix for the .fw files to load.");
73 static int modparam_hwpctl
;
74 module_param_named(hwpctl
, modparam_hwpctl
, int, 0444);
75 MODULE_PARM_DESC(hwpctl
, "Enable hardware-side power control (default off)");
77 static int modparam_nohwcrypt
;
78 module_param_named(nohwcrypt
, modparam_nohwcrypt
, int, 0444);
79 MODULE_PARM_DESC(nohwcrypt
, "Disable hardware encryption.");
81 static const struct ssb_device_id b43_ssb_tbl
[] = {
82 SSB_DEVICE(SSB_VENDOR_BROADCOM
, SSB_DEV_80211
, 5),
83 SSB_DEVICE(SSB_VENDOR_BROADCOM
, SSB_DEV_80211
, 6),
84 SSB_DEVICE(SSB_VENDOR_BROADCOM
, SSB_DEV_80211
, 7),
85 SSB_DEVICE(SSB_VENDOR_BROADCOM
, SSB_DEV_80211
, 9),
86 SSB_DEVICE(SSB_VENDOR_BROADCOM
, SSB_DEV_80211
, 10),
87 SSB_DEVICE(SSB_VENDOR_BROADCOM
, SSB_DEV_80211
, 11),
88 SSB_DEVICE(SSB_VENDOR_BROADCOM
, SSB_DEV_80211
, 13),
92 MODULE_DEVICE_TABLE(ssb
, b43_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 = B43_RATE_TO_BASE100KBPS(_rateid), \
101 .hw_value = (_rateid), \
106 * NOTE: When changing this, sync with xmit.c's
107 * b43_plcp_get_bitrate_idx_* functions!
109 static struct ieee80211_rate __b43_ratetable
[] = {
110 RATETAB_ENT(B43_CCK_RATE_1MB
, 0),
111 RATETAB_ENT(B43_CCK_RATE_2MB
, IEEE80211_RATE_SHORT_PREAMBLE
),
112 RATETAB_ENT(B43_CCK_RATE_5MB
, IEEE80211_RATE_SHORT_PREAMBLE
),
113 RATETAB_ENT(B43_CCK_RATE_11MB
, IEEE80211_RATE_SHORT_PREAMBLE
),
114 RATETAB_ENT(B43_OFDM_RATE_6MB
, 0),
115 RATETAB_ENT(B43_OFDM_RATE_9MB
, 0),
116 RATETAB_ENT(B43_OFDM_RATE_12MB
, 0),
117 RATETAB_ENT(B43_OFDM_RATE_18MB
, 0),
118 RATETAB_ENT(B43_OFDM_RATE_24MB
, 0),
119 RATETAB_ENT(B43_OFDM_RATE_36MB
, 0),
120 RATETAB_ENT(B43_OFDM_RATE_48MB
, 0),
121 RATETAB_ENT(B43_OFDM_RATE_54MB
, 0),
124 #define b43_a_ratetable (__b43_ratetable + 4)
125 #define b43_a_ratetable_size 8
126 #define b43_b_ratetable (__b43_ratetable + 0)
127 #define b43_b_ratetable_size 4
128 #define b43_g_ratetable (__b43_ratetable + 0)
129 #define b43_g_ratetable_size 12
131 #define CHAN4G(_channel, _freq, _flags) { \
132 .band = IEEE80211_BAND_2GHZ, \
133 .center_freq = (_freq), \
134 .hw_value = (_channel), \
136 .max_antenna_gain = 0, \
139 static struct ieee80211_channel b43_2ghz_chantable
[] = {
157 #define CHAN5G(_channel, _flags) { \
158 .band = IEEE80211_BAND_5GHZ, \
159 .center_freq = 5000 + (5 * (_channel)), \
160 .hw_value = (_channel), \
162 .max_antenna_gain = 0, \
165 static struct ieee80211_channel b43_5ghz_nphy_chantable
[] = {
166 CHAN5G(32, 0), CHAN5G(34, 0),
167 CHAN5G(36, 0), CHAN5G(38, 0),
168 CHAN5G(40, 0), CHAN5G(42, 0),
169 CHAN5G(44, 0), CHAN5G(46, 0),
170 CHAN5G(48, 0), CHAN5G(50, 0),
171 CHAN5G(52, 0), CHAN5G(54, 0),
172 CHAN5G(56, 0), CHAN5G(58, 0),
173 CHAN5G(60, 0), CHAN5G(62, 0),
174 CHAN5G(64, 0), CHAN5G(66, 0),
175 CHAN5G(68, 0), CHAN5G(70, 0),
176 CHAN5G(72, 0), CHAN5G(74, 0),
177 CHAN5G(76, 0), CHAN5G(78, 0),
178 CHAN5G(80, 0), CHAN5G(82, 0),
179 CHAN5G(84, 0), CHAN5G(86, 0),
180 CHAN5G(88, 0), CHAN5G(90, 0),
181 CHAN5G(92, 0), CHAN5G(94, 0),
182 CHAN5G(96, 0), CHAN5G(98, 0),
183 CHAN5G(100, 0), CHAN5G(102, 0),
184 CHAN5G(104, 0), CHAN5G(106, 0),
185 CHAN5G(108, 0), CHAN5G(110, 0),
186 CHAN5G(112, 0), CHAN5G(114, 0),
187 CHAN5G(116, 0), CHAN5G(118, 0),
188 CHAN5G(120, 0), CHAN5G(122, 0),
189 CHAN5G(124, 0), CHAN5G(126, 0),
190 CHAN5G(128, 0), CHAN5G(130, 0),
191 CHAN5G(132, 0), CHAN5G(134, 0),
192 CHAN5G(136, 0), CHAN5G(138, 0),
193 CHAN5G(140, 0), CHAN5G(142, 0),
194 CHAN5G(144, 0), CHAN5G(145, 0),
195 CHAN5G(146, 0), CHAN5G(147, 0),
196 CHAN5G(148, 0), CHAN5G(149, 0),
197 CHAN5G(150, 0), CHAN5G(151, 0),
198 CHAN5G(152, 0), CHAN5G(153, 0),
199 CHAN5G(154, 0), CHAN5G(155, 0),
200 CHAN5G(156, 0), CHAN5G(157, 0),
201 CHAN5G(158, 0), CHAN5G(159, 0),
202 CHAN5G(160, 0), CHAN5G(161, 0),
203 CHAN5G(162, 0), CHAN5G(163, 0),
204 CHAN5G(164, 0), CHAN5G(165, 0),
205 CHAN5G(166, 0), CHAN5G(168, 0),
206 CHAN5G(170, 0), CHAN5G(172, 0),
207 CHAN5G(174, 0), CHAN5G(176, 0),
208 CHAN5G(178, 0), CHAN5G(180, 0),
209 CHAN5G(182, 0), CHAN5G(184, 0),
210 CHAN5G(186, 0), CHAN5G(188, 0),
211 CHAN5G(190, 0), CHAN5G(192, 0),
212 CHAN5G(194, 0), CHAN5G(196, 0),
213 CHAN5G(198, 0), CHAN5G(200, 0),
214 CHAN5G(202, 0), CHAN5G(204, 0),
215 CHAN5G(206, 0), CHAN5G(208, 0),
216 CHAN5G(210, 0), CHAN5G(212, 0),
217 CHAN5G(214, 0), CHAN5G(216, 0),
218 CHAN5G(218, 0), CHAN5G(220, 0),
219 CHAN5G(222, 0), CHAN5G(224, 0),
220 CHAN5G(226, 0), CHAN5G(228, 0),
223 static struct ieee80211_channel b43_5ghz_aphy_chantable
[] = {
224 CHAN5G(34, 0), CHAN5G(36, 0),
225 CHAN5G(38, 0), CHAN5G(40, 0),
226 CHAN5G(42, 0), CHAN5G(44, 0),
227 CHAN5G(46, 0), CHAN5G(48, 0),
228 CHAN5G(52, 0), CHAN5G(56, 0),
229 CHAN5G(60, 0), CHAN5G(64, 0),
230 CHAN5G(100, 0), CHAN5G(104, 0),
231 CHAN5G(108, 0), CHAN5G(112, 0),
232 CHAN5G(116, 0), CHAN5G(120, 0),
233 CHAN5G(124, 0), CHAN5G(128, 0),
234 CHAN5G(132, 0), CHAN5G(136, 0),
235 CHAN5G(140, 0), CHAN5G(149, 0),
236 CHAN5G(153, 0), CHAN5G(157, 0),
237 CHAN5G(161, 0), CHAN5G(165, 0),
238 CHAN5G(184, 0), CHAN5G(188, 0),
239 CHAN5G(192, 0), CHAN5G(196, 0),
240 CHAN5G(200, 0), CHAN5G(204, 0),
241 CHAN5G(208, 0), CHAN5G(212, 0),
246 static struct ieee80211_supported_band b43_band_5GHz_nphy
= {
247 .band
= IEEE80211_BAND_5GHZ
,
248 .channels
= b43_5ghz_nphy_chantable
,
249 .n_channels
= ARRAY_SIZE(b43_5ghz_nphy_chantable
),
250 .bitrates
= b43_a_ratetable
,
251 .n_bitrates
= b43_a_ratetable_size
,
254 static struct ieee80211_supported_band b43_band_5GHz_aphy
= {
255 .band
= IEEE80211_BAND_5GHZ
,
256 .channels
= b43_5ghz_aphy_chantable
,
257 .n_channels
= ARRAY_SIZE(b43_5ghz_aphy_chantable
),
258 .bitrates
= b43_a_ratetable
,
259 .n_bitrates
= b43_a_ratetable_size
,
262 static struct ieee80211_supported_band b43_band_2GHz
= {
263 .band
= IEEE80211_BAND_2GHZ
,
264 .channels
= b43_2ghz_chantable
,
265 .n_channels
= ARRAY_SIZE(b43_2ghz_chantable
),
266 .bitrates
= b43_g_ratetable
,
267 .n_bitrates
= b43_g_ratetable_size
,
270 static void b43_wireless_core_exit(struct b43_wldev
*dev
);
271 static int b43_wireless_core_init(struct b43_wldev
*dev
);
272 static void b43_wireless_core_stop(struct b43_wldev
*dev
);
273 static int b43_wireless_core_start(struct b43_wldev
*dev
);
275 static int b43_ratelimit(struct b43_wl
*wl
)
277 if (!wl
|| !wl
->current_dev
)
279 if (b43_status(wl
->current_dev
) < B43_STAT_STARTED
)
281 /* We are up and running.
282 * Ratelimit the messages to avoid DoS over the net. */
283 return net_ratelimit();
286 void b43info(struct b43_wl
*wl
, const char *fmt
, ...)
290 if (!b43_ratelimit(wl
))
293 printk(KERN_INFO
"b43-%s: ",
294 (wl
&& wl
->hw
) ? wiphy_name(wl
->hw
->wiphy
) : "wlan");
299 void b43err(struct b43_wl
*wl
, const char *fmt
, ...)
303 if (!b43_ratelimit(wl
))
306 printk(KERN_ERR
"b43-%s ERROR: ",
307 (wl
&& wl
->hw
) ? wiphy_name(wl
->hw
->wiphy
) : "wlan");
312 void b43warn(struct b43_wl
*wl
, const char *fmt
, ...)
316 if (!b43_ratelimit(wl
))
319 printk(KERN_WARNING
"b43-%s warning: ",
320 (wl
&& wl
->hw
) ? wiphy_name(wl
->hw
->wiphy
) : "wlan");
326 void b43dbg(struct b43_wl
*wl
, const char *fmt
, ...)
331 printk(KERN_DEBUG
"b43-%s debug: ",
332 (wl
&& wl
->hw
) ? wiphy_name(wl
->hw
->wiphy
) : "wlan");
338 static void b43_ram_write(struct b43_wldev
*dev
, u16 offset
, u32 val
)
342 B43_WARN_ON(offset
% 4 != 0);
344 macctl
= b43_read32(dev
, B43_MMIO_MACCTL
);
345 if (macctl
& B43_MACCTL_BE
)
348 b43_write32(dev
, B43_MMIO_RAM_CONTROL
, offset
);
350 b43_write32(dev
, B43_MMIO_RAM_DATA
, val
);
353 static inline void b43_shm_control_word(struct b43_wldev
*dev
,
354 u16 routing
, u16 offset
)
358 /* "offset" is the WORD offset. */
362 b43_write32(dev
, B43_MMIO_SHM_CONTROL
, control
);
365 u32
b43_shm_read32(struct b43_wldev
*dev
, u16 routing
, u16 offset
)
367 struct b43_wl
*wl
= dev
->wl
;
371 spin_lock_irqsave(&wl
->shm_lock
, flags
);
372 if (routing
== B43_SHM_SHARED
) {
373 B43_WARN_ON(offset
& 0x0001);
374 if (offset
& 0x0003) {
375 /* Unaligned access */
376 b43_shm_control_word(dev
, routing
, offset
>> 2);
377 ret
= b43_read16(dev
, B43_MMIO_SHM_DATA_UNALIGNED
);
379 b43_shm_control_word(dev
, routing
, (offset
>> 2) + 1);
380 ret
|= b43_read16(dev
, B43_MMIO_SHM_DATA
);
386 b43_shm_control_word(dev
, routing
, offset
);
387 ret
= b43_read32(dev
, B43_MMIO_SHM_DATA
);
389 spin_unlock_irqrestore(&wl
->shm_lock
, flags
);
394 u16
b43_shm_read16(struct b43_wldev
* dev
, u16 routing
, u16 offset
)
396 struct b43_wl
*wl
= dev
->wl
;
400 spin_lock_irqsave(&wl
->shm_lock
, flags
);
401 if (routing
== B43_SHM_SHARED
) {
402 B43_WARN_ON(offset
& 0x0001);
403 if (offset
& 0x0003) {
404 /* Unaligned access */
405 b43_shm_control_word(dev
, routing
, offset
>> 2);
406 ret
= b43_read16(dev
, B43_MMIO_SHM_DATA_UNALIGNED
);
412 b43_shm_control_word(dev
, routing
, offset
);
413 ret
= b43_read16(dev
, B43_MMIO_SHM_DATA
);
415 spin_unlock_irqrestore(&wl
->shm_lock
, flags
);
420 void b43_shm_write32(struct b43_wldev
*dev
, u16 routing
, u16 offset
, u32 value
)
422 struct b43_wl
*wl
= dev
->wl
;
425 spin_lock_irqsave(&wl
->shm_lock
, flags
);
426 if (routing
== B43_SHM_SHARED
) {
427 B43_WARN_ON(offset
& 0x0001);
428 if (offset
& 0x0003) {
429 /* Unaligned access */
430 b43_shm_control_word(dev
, routing
, offset
>> 2);
431 b43_write16(dev
, B43_MMIO_SHM_DATA_UNALIGNED
,
432 (value
>> 16) & 0xffff);
433 b43_shm_control_word(dev
, routing
, (offset
>> 2) + 1);
434 b43_write16(dev
, B43_MMIO_SHM_DATA
, value
& 0xffff);
439 b43_shm_control_word(dev
, routing
, offset
);
440 b43_write32(dev
, B43_MMIO_SHM_DATA
, value
);
442 spin_unlock_irqrestore(&wl
->shm_lock
, flags
);
445 void b43_shm_write16(struct b43_wldev
*dev
, u16 routing
, u16 offset
, u16 value
)
447 struct b43_wl
*wl
= dev
->wl
;
450 spin_lock_irqsave(&wl
->shm_lock
, flags
);
451 if (routing
== B43_SHM_SHARED
) {
452 B43_WARN_ON(offset
& 0x0001);
453 if (offset
& 0x0003) {
454 /* Unaligned access */
455 b43_shm_control_word(dev
, routing
, offset
>> 2);
456 b43_write16(dev
, B43_MMIO_SHM_DATA_UNALIGNED
, value
);
461 b43_shm_control_word(dev
, routing
, offset
);
462 b43_write16(dev
, B43_MMIO_SHM_DATA
, value
);
464 spin_unlock_irqrestore(&wl
->shm_lock
, flags
);
468 u64
b43_hf_read(struct b43_wldev
* dev
)
472 ret
= b43_shm_read16(dev
, B43_SHM_SHARED
, B43_SHM_SH_HOSTFHI
);
474 ret
|= b43_shm_read16(dev
, B43_SHM_SHARED
, B43_SHM_SH_HOSTFMI
);
476 ret
|= b43_shm_read16(dev
, B43_SHM_SHARED
, B43_SHM_SH_HOSTFLO
);
481 /* Write HostFlags */
482 void b43_hf_write(struct b43_wldev
*dev
, u64 value
)
486 lo
= (value
& 0x00000000FFFFULL
);
487 mi
= (value
& 0x0000FFFF0000ULL
) >> 16;
488 hi
= (value
& 0xFFFF00000000ULL
) >> 32;
489 b43_shm_write16(dev
, B43_SHM_SHARED
, B43_SHM_SH_HOSTFLO
, lo
);
490 b43_shm_write16(dev
, B43_SHM_SHARED
, B43_SHM_SH_HOSTFMI
, mi
);
491 b43_shm_write16(dev
, B43_SHM_SHARED
, B43_SHM_SH_HOSTFHI
, hi
);
494 void b43_tsf_read(struct b43_wldev
*dev
, u64
* tsf
)
496 /* We need to be careful. As we read the TSF from multiple
497 * registers, we should take care of register overflows.
498 * In theory, the whole tsf read process should be atomic.
499 * We try to be atomic here, by restaring the read process,
500 * if any of the high registers changed (overflew).
502 if (dev
->dev
->id
.revision
>= 3) {
503 u32 low
, high
, high2
;
506 high
= b43_read32(dev
, B43_MMIO_REV3PLUS_TSF_HIGH
);
507 low
= b43_read32(dev
, B43_MMIO_REV3PLUS_TSF_LOW
);
508 high2
= b43_read32(dev
, B43_MMIO_REV3PLUS_TSF_HIGH
);
509 } while (unlikely(high
!= high2
));
517 u16 test1
, test2
, test3
;
520 v3
= b43_read16(dev
, B43_MMIO_TSF_3
);
521 v2
= b43_read16(dev
, B43_MMIO_TSF_2
);
522 v1
= b43_read16(dev
, B43_MMIO_TSF_1
);
523 v0
= b43_read16(dev
, B43_MMIO_TSF_0
);
525 test3
= b43_read16(dev
, B43_MMIO_TSF_3
);
526 test2
= b43_read16(dev
, B43_MMIO_TSF_2
);
527 test1
= b43_read16(dev
, B43_MMIO_TSF_1
);
528 } while (v3
!= test3
|| v2
!= test2
|| v1
!= test1
);
542 static void b43_time_lock(struct b43_wldev
*dev
)
546 macctl
= b43_read32(dev
, B43_MMIO_MACCTL
);
547 macctl
|= B43_MACCTL_TBTTHOLD
;
548 b43_write32(dev
, B43_MMIO_MACCTL
, macctl
);
549 /* Commit the write */
550 b43_read32(dev
, B43_MMIO_MACCTL
);
553 static void b43_time_unlock(struct b43_wldev
*dev
)
557 macctl
= b43_read32(dev
, B43_MMIO_MACCTL
);
558 macctl
&= ~B43_MACCTL_TBTTHOLD
;
559 b43_write32(dev
, B43_MMIO_MACCTL
, macctl
);
560 /* Commit the write */
561 b43_read32(dev
, B43_MMIO_MACCTL
);
564 static void b43_tsf_write_locked(struct b43_wldev
*dev
, u64 tsf
)
566 /* Be careful with the in-progress timer.
567 * First zero out the low register, so we have a full
568 * register-overflow duration to complete the operation.
570 if (dev
->dev
->id
.revision
>= 3) {
571 u32 lo
= (tsf
& 0x00000000FFFFFFFFULL
);
572 u32 hi
= (tsf
& 0xFFFFFFFF00000000ULL
) >> 32;
574 b43_write32(dev
, B43_MMIO_REV3PLUS_TSF_LOW
, 0);
576 b43_write32(dev
, B43_MMIO_REV3PLUS_TSF_HIGH
, hi
);
578 b43_write32(dev
, B43_MMIO_REV3PLUS_TSF_LOW
, lo
);
580 u16 v0
= (tsf
& 0x000000000000FFFFULL
);
581 u16 v1
= (tsf
& 0x00000000FFFF0000ULL
) >> 16;
582 u16 v2
= (tsf
& 0x0000FFFF00000000ULL
) >> 32;
583 u16 v3
= (tsf
& 0xFFFF000000000000ULL
) >> 48;
585 b43_write16(dev
, B43_MMIO_TSF_0
, 0);
587 b43_write16(dev
, B43_MMIO_TSF_3
, v3
);
589 b43_write16(dev
, B43_MMIO_TSF_2
, v2
);
591 b43_write16(dev
, B43_MMIO_TSF_1
, v1
);
593 b43_write16(dev
, B43_MMIO_TSF_0
, v0
);
597 void b43_tsf_write(struct b43_wldev
*dev
, u64 tsf
)
600 b43_tsf_write_locked(dev
, tsf
);
601 b43_time_unlock(dev
);
605 void b43_macfilter_set(struct b43_wldev
*dev
, u16 offset
, const u8
* mac
)
607 static const u8 zero_addr
[ETH_ALEN
] = { 0 };
614 b43_write16(dev
, B43_MMIO_MACFILTER_CONTROL
, offset
);
618 b43_write16(dev
, B43_MMIO_MACFILTER_DATA
, data
);
621 b43_write16(dev
, B43_MMIO_MACFILTER_DATA
, data
);
624 b43_write16(dev
, B43_MMIO_MACFILTER_DATA
, data
);
627 static void b43_write_mac_bssid_templates(struct b43_wldev
*dev
)
631 u8 mac_bssid
[ETH_ALEN
* 2];
635 bssid
= dev
->wl
->bssid
;
636 mac
= dev
->wl
->mac_addr
;
638 b43_macfilter_set(dev
, B43_MACFILTER_BSSID
, bssid
);
640 memcpy(mac_bssid
, mac
, ETH_ALEN
);
641 memcpy(mac_bssid
+ ETH_ALEN
, bssid
, ETH_ALEN
);
643 /* Write our MAC address and BSSID to template ram */
644 for (i
= 0; i
< ARRAY_SIZE(mac_bssid
); i
+= sizeof(u32
)) {
645 tmp
= (u32
) (mac_bssid
[i
+ 0]);
646 tmp
|= (u32
) (mac_bssid
[i
+ 1]) << 8;
647 tmp
|= (u32
) (mac_bssid
[i
+ 2]) << 16;
648 tmp
|= (u32
) (mac_bssid
[i
+ 3]) << 24;
649 b43_ram_write(dev
, 0x20 + i
, tmp
);
653 static void b43_upload_card_macaddress(struct b43_wldev
*dev
)
655 b43_write_mac_bssid_templates(dev
);
656 b43_macfilter_set(dev
, B43_MACFILTER_SELF
, dev
->wl
->mac_addr
);
659 static void b43_set_slot_time(struct b43_wldev
*dev
, u16 slot_time
)
661 /* slot_time is in usec. */
662 if (dev
->phy
.type
!= B43_PHYTYPE_G
)
664 b43_write16(dev
, 0x684, 510 + slot_time
);
665 b43_shm_write16(dev
, B43_SHM_SHARED
, 0x0010, slot_time
);
668 static void b43_short_slot_timing_enable(struct b43_wldev
*dev
)
670 b43_set_slot_time(dev
, 9);
674 static void b43_short_slot_timing_disable(struct b43_wldev
*dev
)
676 b43_set_slot_time(dev
, 20);
680 /* Enable a Generic IRQ. "mask" is the mask of which IRQs to enable.
681 * Returns the _previously_ enabled IRQ mask.
683 static inline u32
b43_interrupt_enable(struct b43_wldev
*dev
, u32 mask
)
687 old_mask
= b43_read32(dev
, B43_MMIO_GEN_IRQ_MASK
);
688 b43_write32(dev
, B43_MMIO_GEN_IRQ_MASK
, old_mask
| mask
);
693 /* Disable a Generic IRQ. "mask" is the mask of which IRQs to disable.
694 * Returns the _previously_ enabled IRQ mask.
696 static inline u32
b43_interrupt_disable(struct b43_wldev
*dev
, u32 mask
)
700 old_mask
= b43_read32(dev
, B43_MMIO_GEN_IRQ_MASK
);
701 b43_write32(dev
, B43_MMIO_GEN_IRQ_MASK
, old_mask
& ~mask
);
706 /* Synchronize IRQ top- and bottom-half.
707 * IRQs must be masked before calling this.
708 * This must not be called with the irq_lock held.
710 static void b43_synchronize_irq(struct b43_wldev
*dev
)
712 synchronize_irq(dev
->dev
->irq
);
713 tasklet_kill(&dev
->isr_tasklet
);
716 /* DummyTransmission function, as documented on
717 * http://bcm-specs.sipsolutions.net/DummyTransmission
719 void b43_dummy_transmission(struct b43_wldev
*dev
)
721 struct b43_phy
*phy
= &dev
->phy
;
722 unsigned int i
, max_loop
;
735 buffer
[0] = 0x000201CC;
740 buffer
[0] = 0x000B846E;
747 for (i
= 0; i
< 5; i
++)
748 b43_ram_write(dev
, i
* 4, buffer
[i
]);
751 b43_read32(dev
, B43_MMIO_MACCTL
);
753 b43_write16(dev
, 0x0568, 0x0000);
754 b43_write16(dev
, 0x07C0, 0x0000);
755 value
= ((phy
->type
== B43_PHYTYPE_A
) ? 1 : 0);
756 b43_write16(dev
, 0x050C, value
);
757 b43_write16(dev
, 0x0508, 0x0000);
758 b43_write16(dev
, 0x050A, 0x0000);
759 b43_write16(dev
, 0x054C, 0x0000);
760 b43_write16(dev
, 0x056A, 0x0014);
761 b43_write16(dev
, 0x0568, 0x0826);
762 b43_write16(dev
, 0x0500, 0x0000);
763 b43_write16(dev
, 0x0502, 0x0030);
765 if (phy
->radio_ver
== 0x2050 && phy
->radio_rev
<= 0x5)
766 b43_radio_write16(dev
, 0x0051, 0x0017);
767 for (i
= 0x00; i
< max_loop
; i
++) {
768 value
= b43_read16(dev
, 0x050E);
773 for (i
= 0x00; i
< 0x0A; i
++) {
774 value
= b43_read16(dev
, 0x050E);
779 for (i
= 0x00; i
< 0x0A; i
++) {
780 value
= b43_read16(dev
, 0x0690);
781 if (!(value
& 0x0100))
785 if (phy
->radio_ver
== 0x2050 && phy
->radio_rev
<= 0x5)
786 b43_radio_write16(dev
, 0x0051, 0x0037);
789 static void key_write(struct b43_wldev
*dev
,
790 u8 index
, u8 algorithm
, const u8
* key
)
797 /* Key index/algo block */
798 kidx
= b43_kidx_to_fw(dev
, index
);
799 value
= ((kidx
<< 4) | algorithm
);
800 b43_shm_write16(dev
, B43_SHM_SHARED
,
801 B43_SHM_SH_KEYIDXBLOCK
+ (kidx
* 2), value
);
803 /* Write the key to the Key Table Pointer offset */
804 offset
= dev
->ktp
+ (index
* B43_SEC_KEYSIZE
);
805 for (i
= 0; i
< B43_SEC_KEYSIZE
; i
+= 2) {
807 value
|= (u16
) (key
[i
+ 1]) << 8;
808 b43_shm_write16(dev
, B43_SHM_SHARED
, offset
+ i
, value
);
812 static void keymac_write(struct b43_wldev
*dev
, u8 index
, const u8
* addr
)
814 u32 addrtmp
[2] = { 0, 0, };
815 u8 per_sta_keys_start
= 8;
817 if (b43_new_kidx_api(dev
))
818 per_sta_keys_start
= 4;
820 B43_WARN_ON(index
< per_sta_keys_start
);
821 /* We have two default TX keys and possibly two default RX keys.
822 * Physical mac 0 is mapped to physical key 4 or 8, depending
823 * on the firmware version.
824 * So we must adjust the index here.
826 index
-= per_sta_keys_start
;
829 addrtmp
[0] = addr
[0];
830 addrtmp
[0] |= ((u32
) (addr
[1]) << 8);
831 addrtmp
[0] |= ((u32
) (addr
[2]) << 16);
832 addrtmp
[0] |= ((u32
) (addr
[3]) << 24);
833 addrtmp
[1] = addr
[4];
834 addrtmp
[1] |= ((u32
) (addr
[5]) << 8);
837 if (dev
->dev
->id
.revision
>= 5) {
838 /* Receive match transmitter address mechanism */
839 b43_shm_write32(dev
, B43_SHM_RCMTA
,
840 (index
* 2) + 0, addrtmp
[0]);
841 b43_shm_write16(dev
, B43_SHM_RCMTA
,
842 (index
* 2) + 1, addrtmp
[1]);
844 /* RXE (Receive Engine) and
845 * PSM (Programmable State Machine) mechanism
848 /* TODO write to RCM 16, 19, 22 and 25 */
850 b43_shm_write32(dev
, B43_SHM_SHARED
,
851 B43_SHM_SH_PSM
+ (index
* 6) + 0,
853 b43_shm_write16(dev
, B43_SHM_SHARED
,
854 B43_SHM_SH_PSM
+ (index
* 6) + 4,
860 static void do_key_write(struct b43_wldev
*dev
,
861 u8 index
, u8 algorithm
,
862 const u8
* key
, size_t key_len
, const u8
* mac_addr
)
864 u8 buf
[B43_SEC_KEYSIZE
] = { 0, };
865 u8 per_sta_keys_start
= 8;
867 if (b43_new_kidx_api(dev
))
868 per_sta_keys_start
= 4;
870 B43_WARN_ON(index
>= dev
->max_nr_keys
);
871 B43_WARN_ON(key_len
> B43_SEC_KEYSIZE
);
873 if (index
>= per_sta_keys_start
)
874 keymac_write(dev
, index
, NULL
); /* First zero out mac. */
876 memcpy(buf
, key
, key_len
);
877 key_write(dev
, index
, algorithm
, buf
);
878 if (index
>= per_sta_keys_start
)
879 keymac_write(dev
, index
, mac_addr
);
881 dev
->key
[index
].algorithm
= algorithm
;
884 static int b43_key_write(struct b43_wldev
*dev
,
885 int index
, u8 algorithm
,
886 const u8
* key
, size_t key_len
,
888 struct ieee80211_key_conf
*keyconf
)
893 if (key_len
> B43_SEC_KEYSIZE
)
895 for (i
= 0; i
< dev
->max_nr_keys
; i
++) {
896 /* Check that we don't already have this key. */
897 B43_WARN_ON(dev
->key
[i
].keyconf
== keyconf
);
900 /* Either pairwise key or address is 00:00:00:00:00:00
901 * for transmit-only keys. Search the index. */
902 if (b43_new_kidx_api(dev
))
906 for (i
= sta_keys_start
; i
< dev
->max_nr_keys
; i
++) {
907 if (!dev
->key
[i
].keyconf
) {
914 b43err(dev
->wl
, "Out of hardware key memory\n");
918 B43_WARN_ON(index
> 3);
920 do_key_write(dev
, index
, algorithm
, key
, key_len
, mac_addr
);
921 if ((index
<= 3) && !b43_new_kidx_api(dev
)) {
923 B43_WARN_ON(mac_addr
);
924 do_key_write(dev
, index
+ 4, algorithm
, key
, key_len
, NULL
);
926 keyconf
->hw_key_idx
= index
;
927 dev
->key
[index
].keyconf
= keyconf
;
932 static int b43_key_clear(struct b43_wldev
*dev
, int index
)
934 if (B43_WARN_ON((index
< 0) || (index
>= dev
->max_nr_keys
)))
936 do_key_write(dev
, index
, B43_SEC_ALGO_NONE
,
937 NULL
, B43_SEC_KEYSIZE
, NULL
);
938 if ((index
<= 3) && !b43_new_kidx_api(dev
)) {
939 do_key_write(dev
, index
+ 4, B43_SEC_ALGO_NONE
,
940 NULL
, B43_SEC_KEYSIZE
, NULL
);
942 dev
->key
[index
].keyconf
= NULL
;
947 static void b43_clear_keys(struct b43_wldev
*dev
)
951 for (i
= 0; i
< dev
->max_nr_keys
; i
++)
952 b43_key_clear(dev
, i
);
955 void b43_power_saving_ctl_bits(struct b43_wldev
*dev
, unsigned int ps_flags
)
963 B43_WARN_ON((ps_flags
& B43_PS_ENABLED
) &&
964 (ps_flags
& B43_PS_DISABLED
));
965 B43_WARN_ON((ps_flags
& B43_PS_AWAKE
) && (ps_flags
& B43_PS_ASLEEP
));
967 if (ps_flags
& B43_PS_ENABLED
) {
969 } else if (ps_flags
& B43_PS_DISABLED
) {
972 //TODO: If powersave is not off and FIXME is not set and we are not in adhoc
973 // and thus is not an AP and we are associated, set bit 25
975 if (ps_flags
& B43_PS_AWAKE
) {
977 } else if (ps_flags
& B43_PS_ASLEEP
) {
980 //TODO: If the device is awake or this is an AP, or we are scanning, or FIXME,
981 // or we are associated, or FIXME, or the latest PS-Poll packet sent was
982 // successful, set bit26
985 /* FIXME: For now we force awake-on and hwps-off */
989 macctl
= b43_read32(dev
, B43_MMIO_MACCTL
);
991 macctl
|= B43_MACCTL_HWPS
;
993 macctl
&= ~B43_MACCTL_HWPS
;
995 macctl
|= B43_MACCTL_AWAKE
;
997 macctl
&= ~B43_MACCTL_AWAKE
;
998 b43_write32(dev
, B43_MMIO_MACCTL
, macctl
);
1000 b43_read32(dev
, B43_MMIO_MACCTL
);
1001 if (awake
&& dev
->dev
->id
.revision
>= 5) {
1002 /* Wait for the microcode to wake up. */
1003 for (i
= 0; i
< 100; i
++) {
1004 ucstat
= b43_shm_read16(dev
, B43_SHM_SHARED
,
1005 B43_SHM_SH_UCODESTAT
);
1006 if (ucstat
!= B43_SHM_SH_UCODESTAT_SLEEP
)
1013 /* Turn the Analog ON/OFF */
1014 static void b43_switch_analog(struct b43_wldev
*dev
, int on
)
1016 b43_write16(dev
, B43_MMIO_PHY0
, on
? 0 : 0xF4);
1019 void b43_wireless_core_reset(struct b43_wldev
*dev
, u32 flags
)
1024 flags
|= B43_TMSLOW_PHYCLKEN
;
1025 flags
|= B43_TMSLOW_PHYRESET
;
1026 ssb_device_enable(dev
->dev
, flags
);
1027 msleep(2); /* Wait for the PLL to turn on. */
1029 /* Now take the PHY out of Reset again */
1030 tmslow
= ssb_read32(dev
->dev
, SSB_TMSLOW
);
1031 tmslow
|= SSB_TMSLOW_FGC
;
1032 tmslow
&= ~B43_TMSLOW_PHYRESET
;
1033 ssb_write32(dev
->dev
, SSB_TMSLOW
, tmslow
);
1034 ssb_read32(dev
->dev
, SSB_TMSLOW
); /* flush */
1036 tmslow
&= ~SSB_TMSLOW_FGC
;
1037 ssb_write32(dev
->dev
, SSB_TMSLOW
, tmslow
);
1038 ssb_read32(dev
->dev
, SSB_TMSLOW
); /* flush */
1041 /* Turn Analog ON */
1042 b43_switch_analog(dev
, 1);
1044 macctl
= b43_read32(dev
, B43_MMIO_MACCTL
);
1045 macctl
&= ~B43_MACCTL_GMODE
;
1046 if (flags
& B43_TMSLOW_GMODE
)
1047 macctl
|= B43_MACCTL_GMODE
;
1048 macctl
|= B43_MACCTL_IHR_ENABLED
;
1049 b43_write32(dev
, B43_MMIO_MACCTL
, macctl
);
1052 static void handle_irq_transmit_status(struct b43_wldev
*dev
)
1056 struct b43_txstatus stat
;
1059 v0
= b43_read32(dev
, B43_MMIO_XMITSTAT_0
);
1060 if (!(v0
& 0x00000001))
1062 v1
= b43_read32(dev
, B43_MMIO_XMITSTAT_1
);
1064 stat
.cookie
= (v0
>> 16);
1065 stat
.seq
= (v1
& 0x0000FFFF);
1066 stat
.phy_stat
= ((v1
& 0x00FF0000) >> 16);
1067 tmp
= (v0
& 0x0000FFFF);
1068 stat
.frame_count
= ((tmp
& 0xF000) >> 12);
1069 stat
.rts_count
= ((tmp
& 0x0F00) >> 8);
1070 stat
.supp_reason
= ((tmp
& 0x001C) >> 2);
1071 stat
.pm_indicated
= !!(tmp
& 0x0080);
1072 stat
.intermediate
= !!(tmp
& 0x0040);
1073 stat
.for_ampdu
= !!(tmp
& 0x0020);
1074 stat
.acked
= !!(tmp
& 0x0002);
1076 b43_handle_txstatus(dev
, &stat
);
1080 static void drain_txstatus_queue(struct b43_wldev
*dev
)
1084 if (dev
->dev
->id
.revision
< 5)
1086 /* Read all entries from the microcode TXstatus FIFO
1087 * and throw them away.
1090 dummy
= b43_read32(dev
, B43_MMIO_XMITSTAT_0
);
1091 if (!(dummy
& 0x00000001))
1093 dummy
= b43_read32(dev
, B43_MMIO_XMITSTAT_1
);
1097 static u32
b43_jssi_read(struct b43_wldev
*dev
)
1101 val
= b43_shm_read16(dev
, B43_SHM_SHARED
, 0x08A);
1103 val
|= b43_shm_read16(dev
, B43_SHM_SHARED
, 0x088);
1108 static void b43_jssi_write(struct b43_wldev
*dev
, u32 jssi
)
1110 b43_shm_write16(dev
, B43_SHM_SHARED
, 0x088, (jssi
& 0x0000FFFF));
1111 b43_shm_write16(dev
, B43_SHM_SHARED
, 0x08A, (jssi
& 0xFFFF0000) >> 16);
1114 static void b43_generate_noise_sample(struct b43_wldev
*dev
)
1116 b43_jssi_write(dev
, 0x7F7F7F7F);
1117 b43_write32(dev
, B43_MMIO_MACCMD
,
1118 b43_read32(dev
, B43_MMIO_MACCMD
) | B43_MACCMD_BGNOISE
);
1119 B43_WARN_ON(dev
->noisecalc
.channel_at_start
!= dev
->phy
.channel
);
1122 static void b43_calculate_link_quality(struct b43_wldev
*dev
)
1124 /* Top half of Link Quality calculation. */
1126 if (dev
->noisecalc
.calculation_running
)
1128 dev
->noisecalc
.channel_at_start
= dev
->phy
.channel
;
1129 dev
->noisecalc
.calculation_running
= 1;
1130 dev
->noisecalc
.nr_samples
= 0;
1132 b43_generate_noise_sample(dev
);
1135 static void handle_irq_noise(struct b43_wldev
*dev
)
1137 struct b43_phy
*phy
= &dev
->phy
;
1143 /* Bottom half of Link Quality calculation. */
1145 B43_WARN_ON(!dev
->noisecalc
.calculation_running
);
1146 if (dev
->noisecalc
.channel_at_start
!= phy
->channel
)
1147 goto drop_calculation
;
1148 *((__le32
*)noise
) = cpu_to_le32(b43_jssi_read(dev
));
1149 if (noise
[0] == 0x7F || noise
[1] == 0x7F ||
1150 noise
[2] == 0x7F || noise
[3] == 0x7F)
1153 /* Get the noise samples. */
1154 B43_WARN_ON(dev
->noisecalc
.nr_samples
>= 8);
1155 i
= dev
->noisecalc
.nr_samples
;
1156 noise
[0] = limit_value(noise
[0], 0, ARRAY_SIZE(phy
->nrssi_lt
) - 1);
1157 noise
[1] = limit_value(noise
[1], 0, ARRAY_SIZE(phy
->nrssi_lt
) - 1);
1158 noise
[2] = limit_value(noise
[2], 0, ARRAY_SIZE(phy
->nrssi_lt
) - 1);
1159 noise
[3] = limit_value(noise
[3], 0, ARRAY_SIZE(phy
->nrssi_lt
) - 1);
1160 dev
->noisecalc
.samples
[i
][0] = phy
->nrssi_lt
[noise
[0]];
1161 dev
->noisecalc
.samples
[i
][1] = phy
->nrssi_lt
[noise
[1]];
1162 dev
->noisecalc
.samples
[i
][2] = phy
->nrssi_lt
[noise
[2]];
1163 dev
->noisecalc
.samples
[i
][3] = phy
->nrssi_lt
[noise
[3]];
1164 dev
->noisecalc
.nr_samples
++;
1165 if (dev
->noisecalc
.nr_samples
== 8) {
1166 /* Calculate the Link Quality by the noise samples. */
1168 for (i
= 0; i
< 8; i
++) {
1169 for (j
= 0; j
< 4; j
++)
1170 average
+= dev
->noisecalc
.samples
[i
][j
];
1176 tmp
= b43_shm_read16(dev
, B43_SHM_SHARED
, 0x40C);
1177 tmp
= (tmp
/ 128) & 0x1F;
1187 dev
->stats
.link_noise
= average
;
1189 dev
->noisecalc
.calculation_running
= 0;
1193 b43_generate_noise_sample(dev
);
1196 static void handle_irq_tbtt_indication(struct b43_wldev
*dev
)
1198 if (b43_is_mode(dev
->wl
, IEEE80211_IF_TYPE_AP
)) {
1201 if (1 /*FIXME: the last PSpoll frame was sent successfully */ )
1202 b43_power_saving_ctl_bits(dev
, 0);
1204 if (b43_is_mode(dev
->wl
, IEEE80211_IF_TYPE_IBSS
))
1208 static void handle_irq_atim_end(struct b43_wldev
*dev
)
1210 if (dev
->dfq_valid
) {
1211 b43_write32(dev
, B43_MMIO_MACCMD
,
1212 b43_read32(dev
, B43_MMIO_MACCMD
)
1213 | B43_MACCMD_DFQ_VALID
);
1218 static void handle_irq_pmq(struct b43_wldev
*dev
)
1225 tmp
= b43_read32(dev
, B43_MMIO_PS_STATUS
);
1226 if (!(tmp
& 0x00000008))
1229 /* 16bit write is odd, but correct. */
1230 b43_write16(dev
, B43_MMIO_PS_STATUS
, 0x0002);
1233 static void b43_write_template_common(struct b43_wldev
*dev
,
1234 const u8
* data
, u16 size
,
1236 u16 shm_size_offset
, u8 rate
)
1239 struct b43_plcp_hdr4 plcp
;
1242 b43_generate_plcp_hdr(&plcp
, size
+ FCS_LEN
, rate
);
1243 b43_ram_write(dev
, ram_offset
, le32_to_cpu(plcp
.data
));
1244 ram_offset
+= sizeof(u32
);
1245 /* The PLCP is 6 bytes long, but we only wrote 4 bytes, yet.
1246 * So leave the first two bytes of the next write blank.
1248 tmp
= (u32
) (data
[0]) << 16;
1249 tmp
|= (u32
) (data
[1]) << 24;
1250 b43_ram_write(dev
, ram_offset
, tmp
);
1251 ram_offset
+= sizeof(u32
);
1252 for (i
= 2; i
< size
; i
+= sizeof(u32
)) {
1253 tmp
= (u32
) (data
[i
+ 0]);
1255 tmp
|= (u32
) (data
[i
+ 1]) << 8;
1257 tmp
|= (u32
) (data
[i
+ 2]) << 16;
1259 tmp
|= (u32
) (data
[i
+ 3]) << 24;
1260 b43_ram_write(dev
, ram_offset
+ i
- 2, tmp
);
1262 b43_shm_write16(dev
, B43_SHM_SHARED
, shm_size_offset
,
1263 size
+ sizeof(struct b43_plcp_hdr6
));
1266 static void b43_write_beacon_template(struct b43_wldev
*dev
,
1268 u16 shm_size_offset
, u8 rate
)
1270 unsigned int i
, len
, variable_len
;
1271 const struct ieee80211_mgmt
*bcn
;
1275 bcn
= (const struct ieee80211_mgmt
*)(dev
->wl
->current_beacon
->data
);
1276 len
= min((size_t) dev
->wl
->current_beacon
->len
,
1277 0x200 - sizeof(struct b43_plcp_hdr6
));
1279 b43_write_template_common(dev
, (const u8
*)bcn
,
1280 len
, ram_offset
, shm_size_offset
, rate
);
1282 /* Find the position of the TIM and the DTIM_period value
1283 * and write them to SHM. */
1284 ie
= bcn
->u
.beacon
.variable
;
1285 variable_len
= len
- offsetof(struct ieee80211_mgmt
, u
.beacon
.variable
);
1286 for (i
= 0; i
< variable_len
- 2; ) {
1287 uint8_t ie_id
, ie_len
;
1294 /* This is the TIM Information Element */
1296 /* Check whether the ie_len is in the beacon data range. */
1297 if (variable_len
< ie_len
+ 2 + i
)
1299 /* A valid TIM is at least 4 bytes long. */
1304 tim_position
= sizeof(struct b43_plcp_hdr6
);
1305 tim_position
+= offsetof(struct ieee80211_mgmt
, u
.beacon
.variable
);
1308 dtim_period
= ie
[i
+ 3];
1310 b43_shm_write16(dev
, B43_SHM_SHARED
,
1311 B43_SHM_SH_TIMBPOS
, tim_position
);
1312 b43_shm_write16(dev
, B43_SHM_SHARED
,
1313 B43_SHM_SH_DTIMPER
, dtim_period
);
1319 b43warn(dev
->wl
, "Did not find a valid TIM IE in "
1320 "the beacon template packet. AP or IBSS operation "
1321 "may be broken.\n");
1325 static void b43_write_probe_resp_plcp(struct b43_wldev
*dev
,
1326 u16 shm_offset
, u16 size
,
1327 struct ieee80211_rate
*rate
)
1329 struct b43_plcp_hdr4 plcp
;
1334 b43_generate_plcp_hdr(&plcp
, size
+ FCS_LEN
, rate
->hw_value
);
1335 dur
= ieee80211_generic_frame_duration(dev
->wl
->hw
,
1338 /* Write PLCP in two parts and timing for packet transfer */
1339 tmp
= le32_to_cpu(plcp
.data
);
1340 b43_shm_write16(dev
, B43_SHM_SHARED
, shm_offset
, tmp
& 0xFFFF);
1341 b43_shm_write16(dev
, B43_SHM_SHARED
, shm_offset
+ 2, tmp
>> 16);
1342 b43_shm_write16(dev
, B43_SHM_SHARED
, shm_offset
+ 6, le16_to_cpu(dur
));
1345 /* Instead of using custom probe response template, this function
1346 * just patches custom beacon template by:
1347 * 1) Changing packet type
1348 * 2) Patching duration field
1351 static const u8
* b43_generate_probe_resp(struct b43_wldev
*dev
,
1353 struct ieee80211_rate
*rate
)
1357 u16 src_size
, elem_size
, src_pos
, dest_pos
;
1359 struct ieee80211_hdr
*hdr
;
1362 src_size
= dev
->wl
->current_beacon
->len
;
1363 src_data
= (const u8
*)dev
->wl
->current_beacon
->data
;
1365 /* Get the start offset of the variable IEs in the packet. */
1366 ie_start
= offsetof(struct ieee80211_mgmt
, u
.probe_resp
.variable
);
1367 B43_WARN_ON(ie_start
!= offsetof(struct ieee80211_mgmt
, u
.beacon
.variable
));
1369 if (B43_WARN_ON(src_size
< ie_start
))
1372 dest_data
= kmalloc(src_size
, GFP_ATOMIC
);
1373 if (unlikely(!dest_data
))
1376 /* Copy the static data and all Information Elements, except the TIM. */
1377 memcpy(dest_data
, src_data
, ie_start
);
1379 dest_pos
= ie_start
;
1380 for ( ; src_pos
< src_size
- 2; src_pos
+= elem_size
) {
1381 elem_size
= src_data
[src_pos
+ 1] + 2;
1382 if (src_data
[src_pos
] == 5) {
1383 /* This is the TIM. */
1386 memcpy(dest_data
+ dest_pos
, src_data
+ src_pos
,
1388 dest_pos
+= elem_size
;
1390 *dest_size
= dest_pos
;
1391 hdr
= (struct ieee80211_hdr
*)dest_data
;
1393 /* Set the frame control. */
1394 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
1395 IEEE80211_STYPE_PROBE_RESP
);
1396 dur
= ieee80211_generic_frame_duration(dev
->wl
->hw
,
1397 dev
->wl
->vif
, *dest_size
,
1399 hdr
->duration_id
= dur
;
1404 static void b43_write_probe_resp_template(struct b43_wldev
*dev
,
1406 u16 shm_size_offset
,
1407 struct ieee80211_rate
*rate
)
1409 const u8
*probe_resp_data
;
1412 size
= dev
->wl
->current_beacon
->len
;
1413 probe_resp_data
= b43_generate_probe_resp(dev
, &size
, rate
);
1414 if (unlikely(!probe_resp_data
))
1417 /* Looks like PLCP headers plus packet timings are stored for
1418 * all possible basic rates
1420 b43_write_probe_resp_plcp(dev
, 0x31A, size
, &b43_b_ratetable
[0]);
1421 b43_write_probe_resp_plcp(dev
, 0x32C, size
, &b43_b_ratetable
[1]);
1422 b43_write_probe_resp_plcp(dev
, 0x33E, size
, &b43_b_ratetable
[2]);
1423 b43_write_probe_resp_plcp(dev
, 0x350, size
, &b43_b_ratetable
[3]);
1425 size
= min((size_t) size
, 0x200 - sizeof(struct b43_plcp_hdr6
));
1426 b43_write_template_common(dev
, probe_resp_data
,
1427 size
, ram_offset
, shm_size_offset
,
1429 kfree(probe_resp_data
);
1432 /* Asynchronously update the packet templates in template RAM.
1433 * Locking: Requires wl->irq_lock to be locked. */
1434 static void b43_update_templates(struct b43_wl
*wl
, struct sk_buff
*beacon
)
1436 /* This is the top half of the ansynchronous beacon update.
1437 * The bottom half is the beacon IRQ.
1438 * Beacon update must be asynchronous to avoid sending an
1439 * invalid beacon. This can happen for example, if the firmware
1440 * transmits a beacon while we are updating it. */
1442 if (wl
->current_beacon
)
1443 dev_kfree_skb_any(wl
->current_beacon
);
1444 wl
->current_beacon
= beacon
;
1445 wl
->beacon0_uploaded
= 0;
1446 wl
->beacon1_uploaded
= 0;
1449 static void b43_set_ssid(struct b43_wldev
*dev
, const u8
* ssid
, u8 ssid_len
)
1454 len
= min((u16
) ssid_len
, (u16
) 0x100);
1455 for (i
= 0; i
< len
; i
+= sizeof(u32
)) {
1456 tmp
= (u32
) (ssid
[i
+ 0]);
1458 tmp
|= (u32
) (ssid
[i
+ 1]) << 8;
1460 tmp
|= (u32
) (ssid
[i
+ 2]) << 16;
1462 tmp
|= (u32
) (ssid
[i
+ 3]) << 24;
1463 b43_shm_write32(dev
, B43_SHM_SHARED
, 0x380 + i
, tmp
);
1465 b43_shm_write16(dev
, B43_SHM_SHARED
, 0x48, len
);
1468 static void b43_set_beacon_int(struct b43_wldev
*dev
, u16 beacon_int
)
1471 if (dev
->dev
->id
.revision
>= 3) {
1472 b43_write32(dev
, 0x188, (beacon_int
<< 16));
1474 b43_write16(dev
, 0x606, (beacon_int
>> 6));
1475 b43_write16(dev
, 0x610, beacon_int
);
1477 b43_time_unlock(dev
);
1480 static void handle_irq_beacon(struct b43_wldev
*dev
)
1482 struct b43_wl
*wl
= dev
->wl
;
1485 if (!b43_is_mode(wl
, IEEE80211_IF_TYPE_AP
))
1488 /* This is the bottom half of the asynchronous beacon update. */
1490 cmd
= b43_read32(dev
, B43_MMIO_MACCMD
);
1491 if (!(cmd
& B43_MACCMD_BEACON0_VALID
)) {
1492 if (!wl
->beacon0_uploaded
) {
1493 b43_write_beacon_template(dev
, 0x68, 0x18,
1495 b43_write_probe_resp_template(dev
, 0x268, 0x4A,
1496 &__b43_ratetable
[3]);
1497 wl
->beacon0_uploaded
= 1;
1499 cmd
|= B43_MACCMD_BEACON0_VALID
;
1501 if (!(cmd
& B43_MACCMD_BEACON1_VALID
)) {
1502 if (!wl
->beacon1_uploaded
) {
1503 b43_write_beacon_template(dev
, 0x468, 0x1A,
1505 wl
->beacon1_uploaded
= 1;
1507 cmd
|= B43_MACCMD_BEACON1_VALID
;
1509 b43_write32(dev
, B43_MMIO_MACCMD
, cmd
);
1512 static void handle_irq_ucode_debug(struct b43_wldev
*dev
)
1517 /* Interrupt handler bottom-half */
1518 static void b43_interrupt_tasklet(struct b43_wldev
*dev
)
1521 u32 dma_reason
[ARRAY_SIZE(dev
->dma_reason
)];
1522 u32 merged_dma_reason
= 0;
1524 unsigned long flags
;
1526 spin_lock_irqsave(&dev
->wl
->irq_lock
, flags
);
1528 B43_WARN_ON(b43_status(dev
) != B43_STAT_STARTED
);
1530 reason
= dev
->irq_reason
;
1531 for (i
= 0; i
< ARRAY_SIZE(dma_reason
); i
++) {
1532 dma_reason
[i
] = dev
->dma_reason
[i
];
1533 merged_dma_reason
|= dma_reason
[i
];
1536 if (unlikely(reason
& B43_IRQ_MAC_TXERR
))
1537 b43err(dev
->wl
, "MAC transmission error\n");
1539 if (unlikely(reason
& B43_IRQ_PHY_TXERR
)) {
1540 b43err(dev
->wl
, "PHY transmission error\n");
1542 if (unlikely(atomic_dec_and_test(&dev
->phy
.txerr_cnt
))) {
1543 atomic_set(&dev
->phy
.txerr_cnt
,
1544 B43_PHY_TX_BADNESS_LIMIT
);
1545 b43err(dev
->wl
, "Too many PHY TX errors, "
1546 "restarting the controller\n");
1547 b43_controller_restart(dev
, "PHY TX errors");
1551 if (unlikely(merged_dma_reason
& (B43_DMAIRQ_FATALMASK
|
1552 B43_DMAIRQ_NONFATALMASK
))) {
1553 if (merged_dma_reason
& B43_DMAIRQ_FATALMASK
) {
1554 b43err(dev
->wl
, "Fatal DMA error: "
1555 "0x%08X, 0x%08X, 0x%08X, "
1556 "0x%08X, 0x%08X, 0x%08X\n",
1557 dma_reason
[0], dma_reason
[1],
1558 dma_reason
[2], dma_reason
[3],
1559 dma_reason
[4], dma_reason
[5]);
1560 b43_controller_restart(dev
, "DMA error");
1562 spin_unlock_irqrestore(&dev
->wl
->irq_lock
, flags
);
1565 if (merged_dma_reason
& B43_DMAIRQ_NONFATALMASK
) {
1566 b43err(dev
->wl
, "DMA error: "
1567 "0x%08X, 0x%08X, 0x%08X, "
1568 "0x%08X, 0x%08X, 0x%08X\n",
1569 dma_reason
[0], dma_reason
[1],
1570 dma_reason
[2], dma_reason
[3],
1571 dma_reason
[4], dma_reason
[5]);
1575 if (unlikely(reason
& B43_IRQ_UCODE_DEBUG
))
1576 handle_irq_ucode_debug(dev
);
1577 if (reason
& B43_IRQ_TBTT_INDI
)
1578 handle_irq_tbtt_indication(dev
);
1579 if (reason
& B43_IRQ_ATIM_END
)
1580 handle_irq_atim_end(dev
);
1581 if (reason
& B43_IRQ_BEACON
)
1582 handle_irq_beacon(dev
);
1583 if (reason
& B43_IRQ_PMQ
)
1584 handle_irq_pmq(dev
);
1585 if (reason
& B43_IRQ_TXFIFO_FLUSH_OK
)
1587 if (reason
& B43_IRQ_NOISESAMPLE_OK
)
1588 handle_irq_noise(dev
);
1590 /* Check the DMA reason registers for received data. */
1591 if (dma_reason
[0] & B43_DMAIRQ_RX_DONE
)
1592 b43_dma_rx(dev
->dma
.rx_ring0
);
1593 if (dma_reason
[3] & B43_DMAIRQ_RX_DONE
)
1594 b43_dma_rx(dev
->dma
.rx_ring3
);
1595 B43_WARN_ON(dma_reason
[1] & B43_DMAIRQ_RX_DONE
);
1596 B43_WARN_ON(dma_reason
[2] & B43_DMAIRQ_RX_DONE
);
1597 B43_WARN_ON(dma_reason
[4] & B43_DMAIRQ_RX_DONE
);
1598 B43_WARN_ON(dma_reason
[5] & B43_DMAIRQ_RX_DONE
);
1600 if (reason
& B43_IRQ_TX_OK
)
1601 handle_irq_transmit_status(dev
);
1603 b43_interrupt_enable(dev
, dev
->irq_savedstate
);
1605 spin_unlock_irqrestore(&dev
->wl
->irq_lock
, flags
);
1608 static void b43_interrupt_ack(struct b43_wldev
*dev
, u32 reason
)
1610 b43_write32(dev
, B43_MMIO_GEN_IRQ_REASON
, reason
);
1612 b43_write32(dev
, B43_MMIO_DMA0_REASON
, dev
->dma_reason
[0]);
1613 b43_write32(dev
, B43_MMIO_DMA1_REASON
, dev
->dma_reason
[1]);
1614 b43_write32(dev
, B43_MMIO_DMA2_REASON
, dev
->dma_reason
[2]);
1615 b43_write32(dev
, B43_MMIO_DMA3_REASON
, dev
->dma_reason
[3]);
1616 b43_write32(dev
, B43_MMIO_DMA4_REASON
, dev
->dma_reason
[4]);
1617 b43_write32(dev
, B43_MMIO_DMA5_REASON
, dev
->dma_reason
[5]);
1620 /* Interrupt handler top-half */
1621 static irqreturn_t
b43_interrupt_handler(int irq
, void *dev_id
)
1623 irqreturn_t ret
= IRQ_NONE
;
1624 struct b43_wldev
*dev
= dev_id
;
1630 spin_lock(&dev
->wl
->irq_lock
);
1632 if (b43_status(dev
) < B43_STAT_STARTED
)
1634 reason
= b43_read32(dev
, B43_MMIO_GEN_IRQ_REASON
);
1635 if (reason
== 0xffffffff) /* shared IRQ */
1638 reason
&= b43_read32(dev
, B43_MMIO_GEN_IRQ_MASK
);
1642 dev
->dma_reason
[0] = b43_read32(dev
, B43_MMIO_DMA0_REASON
)
1644 dev
->dma_reason
[1] = b43_read32(dev
, B43_MMIO_DMA1_REASON
)
1646 dev
->dma_reason
[2] = b43_read32(dev
, B43_MMIO_DMA2_REASON
)
1648 dev
->dma_reason
[3] = b43_read32(dev
, B43_MMIO_DMA3_REASON
)
1650 dev
->dma_reason
[4] = b43_read32(dev
, B43_MMIO_DMA4_REASON
)
1652 dev
->dma_reason
[5] = b43_read32(dev
, B43_MMIO_DMA5_REASON
)
1655 b43_interrupt_ack(dev
, reason
);
1656 /* disable all IRQs. They are enabled again in the bottom half. */
1657 dev
->irq_savedstate
= b43_interrupt_disable(dev
, B43_IRQ_ALL
);
1658 /* save the reason code and call our bottom half. */
1659 dev
->irq_reason
= reason
;
1660 tasklet_schedule(&dev
->isr_tasklet
);
1663 spin_unlock(&dev
->wl
->irq_lock
);
1668 static void do_release_fw(struct b43_firmware_file
*fw
)
1670 release_firmware(fw
->data
);
1672 fw
->filename
= NULL
;
1675 static void b43_release_firmware(struct b43_wldev
*dev
)
1677 do_release_fw(&dev
->fw
.ucode
);
1678 do_release_fw(&dev
->fw
.pcm
);
1679 do_release_fw(&dev
->fw
.initvals
);
1680 do_release_fw(&dev
->fw
.initvals_band
);
1683 static void b43_print_fw_helptext(struct b43_wl
*wl
, bool error
)
1687 text
= "You must go to "
1688 "http://linuxwireless.org/en/users/Drivers/b43#devicefirmware "
1689 "and download the latest firmware (version 4).\n";
1696 static int do_request_fw(struct b43_wldev
*dev
,
1698 struct b43_firmware_file
*fw
)
1700 char path
[sizeof(modparam_fwpostfix
) + 32];
1701 const struct firmware
*blob
;
1702 struct b43_fw_header
*hdr
;
1707 /* Don't fetch anything. Free possibly cached firmware. */
1712 if (strcmp(fw
->filename
, name
) == 0)
1713 return 0; /* Already have this fw. */
1714 /* Free the cached firmware first. */
1718 snprintf(path
, ARRAY_SIZE(path
),
1720 modparam_fwpostfix
, name
);
1721 err
= request_firmware(&blob
, path
, dev
->dev
->dev
);
1723 b43err(dev
->wl
, "Firmware file \"%s\" not found "
1724 "or load failed.\n", path
);
1727 if (blob
->size
< sizeof(struct b43_fw_header
))
1729 hdr
= (struct b43_fw_header
*)(blob
->data
);
1730 switch (hdr
->type
) {
1731 case B43_FW_TYPE_UCODE
:
1732 case B43_FW_TYPE_PCM
:
1733 size
= be32_to_cpu(hdr
->size
);
1734 if (size
!= blob
->size
- sizeof(struct b43_fw_header
))
1737 case B43_FW_TYPE_IV
:
1746 fw
->filename
= name
;
1751 b43err(dev
->wl
, "Firmware file \"%s\" format error.\n", path
);
1752 release_firmware(blob
);
1757 static int b43_request_firmware(struct b43_wldev
*dev
)
1759 struct b43_firmware
*fw
= &dev
->fw
;
1760 const u8 rev
= dev
->dev
->id
.revision
;
1761 const char *filename
;
1766 tmshigh
= ssb_read32(dev
->dev
, SSB_TMSHIGH
);
1767 if ((rev
>= 5) && (rev
<= 10))
1768 filename
= "ucode5";
1769 else if ((rev
>= 11) && (rev
<= 12))
1770 filename
= "ucode11";
1772 filename
= "ucode13";
1775 err
= do_request_fw(dev
, filename
, &fw
->ucode
);
1780 if ((rev
>= 5) && (rev
<= 10))
1786 err
= do_request_fw(dev
, filename
, &fw
->pcm
);
1791 switch (dev
->phy
.type
) {
1793 if ((rev
>= 5) && (rev
<= 10)) {
1794 if (tmshigh
& B43_TMSHIGH_HAVE_2GHZ_PHY
)
1795 filename
= "a0g1initvals5";
1797 filename
= "a0g0initvals5";
1799 goto err_no_initvals
;
1802 if ((rev
>= 5) && (rev
<= 10))
1803 filename
= "b0g0initvals5";
1805 filename
= "lp0initvals13";
1807 goto err_no_initvals
;
1810 if ((rev
>= 11) && (rev
<= 12))
1811 filename
= "n0initvals11";
1813 goto err_no_initvals
;
1816 goto err_no_initvals
;
1818 err
= do_request_fw(dev
, filename
, &fw
->initvals
);
1822 /* Get bandswitch initvals */
1823 switch (dev
->phy
.type
) {
1825 if ((rev
>= 5) && (rev
<= 10)) {
1826 if (tmshigh
& B43_TMSHIGH_HAVE_2GHZ_PHY
)
1827 filename
= "a0g1bsinitvals5";
1829 filename
= "a0g0bsinitvals5";
1830 } else if (rev
>= 11)
1833 goto err_no_initvals
;
1836 if ((rev
>= 5) && (rev
<= 10))
1837 filename
= "b0g0bsinitvals5";
1841 goto err_no_initvals
;
1844 if ((rev
>= 11) && (rev
<= 12))
1845 filename
= "n0bsinitvals11";
1847 goto err_no_initvals
;
1850 goto err_no_initvals
;
1852 err
= do_request_fw(dev
, filename
, &fw
->initvals_band
);
1859 b43_print_fw_helptext(dev
->wl
, 1);
1864 b43err(dev
->wl
, "No microcode available for core rev %u\n", rev
);
1869 b43err(dev
->wl
, "No PCM available for core rev %u\n", rev
);
1874 b43err(dev
->wl
, "No Initial Values firmware file for PHY %u, "
1875 "core rev %u\n", dev
->phy
.type
, rev
);
1879 b43_release_firmware(dev
);
1883 static int b43_upload_microcode(struct b43_wldev
*dev
)
1885 const size_t hdr_len
= sizeof(struct b43_fw_header
);
1887 unsigned int i
, len
;
1888 u16 fwrev
, fwpatch
, fwdate
, fwtime
;
1892 /* Jump the microcode PSM to offset 0 */
1893 macctl
= b43_read32(dev
, B43_MMIO_MACCTL
);
1894 B43_WARN_ON(macctl
& B43_MACCTL_PSM_RUN
);
1895 macctl
|= B43_MACCTL_PSM_JMP0
;
1896 b43_write32(dev
, B43_MMIO_MACCTL
, macctl
);
1897 /* Zero out all microcode PSM registers and shared memory. */
1898 for (i
= 0; i
< 64; i
++)
1899 b43_shm_write16(dev
, B43_SHM_SCRATCH
, i
, 0);
1900 for (i
= 0; i
< 4096; i
+= 2)
1901 b43_shm_write16(dev
, B43_SHM_SHARED
, i
, 0);
1903 /* Upload Microcode. */
1904 data
= (__be32
*) (dev
->fw
.ucode
.data
->data
+ hdr_len
);
1905 len
= (dev
->fw
.ucode
.data
->size
- hdr_len
) / sizeof(__be32
);
1906 b43_shm_control_word(dev
, B43_SHM_UCODE
| B43_SHM_AUTOINC_W
, 0x0000);
1907 for (i
= 0; i
< len
; i
++) {
1908 b43_write32(dev
, B43_MMIO_SHM_DATA
, be32_to_cpu(data
[i
]));
1912 if (dev
->fw
.pcm
.data
) {
1913 /* Upload PCM data. */
1914 data
= (__be32
*) (dev
->fw
.pcm
.data
->data
+ hdr_len
);
1915 len
= (dev
->fw
.pcm
.data
->size
- hdr_len
) / sizeof(__be32
);
1916 b43_shm_control_word(dev
, B43_SHM_HW
, 0x01EA);
1917 b43_write32(dev
, B43_MMIO_SHM_DATA
, 0x00004000);
1918 /* No need for autoinc bit in SHM_HW */
1919 b43_shm_control_word(dev
, B43_SHM_HW
, 0x01EB);
1920 for (i
= 0; i
< len
; i
++) {
1921 b43_write32(dev
, B43_MMIO_SHM_DATA
, be32_to_cpu(data
[i
]));
1926 b43_write32(dev
, B43_MMIO_GEN_IRQ_REASON
, B43_IRQ_ALL
);
1928 /* Start the microcode PSM */
1929 macctl
= b43_read32(dev
, B43_MMIO_MACCTL
);
1930 macctl
&= ~B43_MACCTL_PSM_JMP0
;
1931 macctl
|= B43_MACCTL_PSM_RUN
;
1932 b43_write32(dev
, B43_MMIO_MACCTL
, macctl
);
1934 /* Wait for the microcode to load and respond */
1937 tmp
= b43_read32(dev
, B43_MMIO_GEN_IRQ_REASON
);
1938 if (tmp
== B43_IRQ_MAC_SUSPENDED
)
1942 b43err(dev
->wl
, "Microcode not responding\n");
1943 b43_print_fw_helptext(dev
->wl
, 1);
1947 msleep_interruptible(50);
1948 if (signal_pending(current
)) {
1953 b43_read32(dev
, B43_MMIO_GEN_IRQ_REASON
); /* dummy read */
1955 /* Get and check the revisions. */
1956 fwrev
= b43_shm_read16(dev
, B43_SHM_SHARED
, B43_SHM_SH_UCODEREV
);
1957 fwpatch
= b43_shm_read16(dev
, B43_SHM_SHARED
, B43_SHM_SH_UCODEPATCH
);
1958 fwdate
= b43_shm_read16(dev
, B43_SHM_SHARED
, B43_SHM_SH_UCODEDATE
);
1959 fwtime
= b43_shm_read16(dev
, B43_SHM_SHARED
, B43_SHM_SH_UCODETIME
);
1961 if (fwrev
<= 0x128) {
1962 b43err(dev
->wl
, "YOUR FIRMWARE IS TOO OLD. Firmware from "
1963 "binary drivers older than version 4.x is unsupported. "
1964 "You must upgrade your firmware files.\n");
1965 b43_print_fw_helptext(dev
->wl
, 1);
1969 b43info(dev
->wl
, "Loading firmware version %u.%u "
1970 "(20%.2i-%.2i-%.2i %.2i:%.2i:%.2i)\n",
1972 (fwdate
>> 12) & 0xF, (fwdate
>> 8) & 0xF, fwdate
& 0xFF,
1973 (fwtime
>> 11) & 0x1F, (fwtime
>> 5) & 0x3F, fwtime
& 0x1F);
1975 dev
->fw
.rev
= fwrev
;
1976 dev
->fw
.patch
= fwpatch
;
1978 if (b43_is_old_txhdr_format(dev
)) {
1979 b43warn(dev
->wl
, "You are using an old firmware image. "
1980 "Support for old firmware will be removed in July 2008.\n");
1981 b43_print_fw_helptext(dev
->wl
, 0);
1987 macctl
= b43_read32(dev
, B43_MMIO_MACCTL
);
1988 macctl
&= ~B43_MACCTL_PSM_RUN
;
1989 macctl
|= B43_MACCTL_PSM_JMP0
;
1990 b43_write32(dev
, B43_MMIO_MACCTL
, macctl
);
1995 static int b43_write_initvals(struct b43_wldev
*dev
,
1996 const struct b43_iv
*ivals
,
2000 const struct b43_iv
*iv
;
2005 BUILD_BUG_ON(sizeof(struct b43_iv
) != 6);
2007 for (i
= 0; i
< count
; i
++) {
2008 if (array_size
< sizeof(iv
->offset_size
))
2010 array_size
-= sizeof(iv
->offset_size
);
2011 offset
= be16_to_cpu(iv
->offset_size
);
2012 bit32
= !!(offset
& B43_IV_32BIT
);
2013 offset
&= B43_IV_OFFSET_MASK
;
2014 if (offset
>= 0x1000)
2019 if (array_size
< sizeof(iv
->data
.d32
))
2021 array_size
-= sizeof(iv
->data
.d32
);
2023 value
= be32_to_cpu(get_unaligned(&iv
->data
.d32
));
2024 b43_write32(dev
, offset
, value
);
2026 iv
= (const struct b43_iv
*)((const uint8_t *)iv
+
2032 if (array_size
< sizeof(iv
->data
.d16
))
2034 array_size
-= sizeof(iv
->data
.d16
);
2036 value
= be16_to_cpu(iv
->data
.d16
);
2037 b43_write16(dev
, offset
, value
);
2039 iv
= (const struct b43_iv
*)((const uint8_t *)iv
+
2050 b43err(dev
->wl
, "Initial Values Firmware file-format error.\n");
2051 b43_print_fw_helptext(dev
->wl
, 1);
2056 static int b43_upload_initvals(struct b43_wldev
*dev
)
2058 const size_t hdr_len
= sizeof(struct b43_fw_header
);
2059 const struct b43_fw_header
*hdr
;
2060 struct b43_firmware
*fw
= &dev
->fw
;
2061 const struct b43_iv
*ivals
;
2065 hdr
= (const struct b43_fw_header
*)(fw
->initvals
.data
->data
);
2066 ivals
= (const struct b43_iv
*)(fw
->initvals
.data
->data
+ hdr_len
);
2067 count
= be32_to_cpu(hdr
->size
);
2068 err
= b43_write_initvals(dev
, ivals
, count
,
2069 fw
->initvals
.data
->size
- hdr_len
);
2072 if (fw
->initvals_band
.data
) {
2073 hdr
= (const struct b43_fw_header
*)(fw
->initvals_band
.data
->data
);
2074 ivals
= (const struct b43_iv
*)(fw
->initvals_band
.data
->data
+ hdr_len
);
2075 count
= be32_to_cpu(hdr
->size
);
2076 err
= b43_write_initvals(dev
, ivals
, count
,
2077 fw
->initvals_band
.data
->size
- hdr_len
);
2086 /* Initialize the GPIOs
2087 * http://bcm-specs.sipsolutions.net/GPIO
2089 static int b43_gpio_init(struct b43_wldev
*dev
)
2091 struct ssb_bus
*bus
= dev
->dev
->bus
;
2092 struct ssb_device
*gpiodev
, *pcidev
= NULL
;
2095 b43_write32(dev
, B43_MMIO_MACCTL
, b43_read32(dev
, B43_MMIO_MACCTL
)
2096 & ~B43_MACCTL_GPOUTSMSK
);
2098 b43_write16(dev
, B43_MMIO_GPIO_MASK
, b43_read16(dev
, B43_MMIO_GPIO_MASK
)
2103 if (dev
->dev
->bus
->chip_id
== 0x4301) {
2107 if (0 /* FIXME: conditional unknown */ ) {
2108 b43_write16(dev
, B43_MMIO_GPIO_MASK
,
2109 b43_read16(dev
, B43_MMIO_GPIO_MASK
)
2114 if (dev
->dev
->bus
->sprom
.boardflags_lo
& B43_BFL_PACTRL
) {
2115 b43_write16(dev
, B43_MMIO_GPIO_MASK
,
2116 b43_read16(dev
, B43_MMIO_GPIO_MASK
)
2121 if (dev
->dev
->id
.revision
>= 2)
2122 mask
|= 0x0010; /* FIXME: This is redundant. */
2124 #ifdef CONFIG_SSB_DRIVER_PCICORE
2125 pcidev
= bus
->pcicore
.dev
;
2127 gpiodev
= bus
->chipco
.dev
? : pcidev
;
2130 ssb_write32(gpiodev
, B43_GPIO_CONTROL
,
2131 (ssb_read32(gpiodev
, B43_GPIO_CONTROL
)
2137 /* Turn off all GPIO stuff. Call this on module unload, for example. */
2138 static void b43_gpio_cleanup(struct b43_wldev
*dev
)
2140 struct ssb_bus
*bus
= dev
->dev
->bus
;
2141 struct ssb_device
*gpiodev
, *pcidev
= NULL
;
2143 #ifdef CONFIG_SSB_DRIVER_PCICORE
2144 pcidev
= bus
->pcicore
.dev
;
2146 gpiodev
= bus
->chipco
.dev
? : pcidev
;
2149 ssb_write32(gpiodev
, B43_GPIO_CONTROL
, 0);
2152 /* http://bcm-specs.sipsolutions.net/EnableMac */
2153 void b43_mac_enable(struct b43_wldev
*dev
)
2155 dev
->mac_suspended
--;
2156 B43_WARN_ON(dev
->mac_suspended
< 0);
2157 B43_WARN_ON(irqs_disabled());
2158 if (dev
->mac_suspended
== 0) {
2159 b43_write32(dev
, B43_MMIO_MACCTL
,
2160 b43_read32(dev
, B43_MMIO_MACCTL
)
2161 | B43_MACCTL_ENABLED
);
2162 b43_write32(dev
, B43_MMIO_GEN_IRQ_REASON
,
2163 B43_IRQ_MAC_SUSPENDED
);
2165 b43_read32(dev
, B43_MMIO_MACCTL
);
2166 b43_read32(dev
, B43_MMIO_GEN_IRQ_REASON
);
2167 b43_power_saving_ctl_bits(dev
, 0);
2169 /* Re-enable IRQs. */
2170 spin_lock_irq(&dev
->wl
->irq_lock
);
2171 b43_interrupt_enable(dev
, dev
->irq_savedstate
);
2172 spin_unlock_irq(&dev
->wl
->irq_lock
);
2176 /* http://bcm-specs.sipsolutions.net/SuspendMAC */
2177 void b43_mac_suspend(struct b43_wldev
*dev
)
2183 B43_WARN_ON(irqs_disabled());
2184 B43_WARN_ON(dev
->mac_suspended
< 0);
2186 if (dev
->mac_suspended
== 0) {
2187 /* Mask IRQs before suspending MAC. Otherwise
2188 * the MAC stays busy and won't suspend. */
2189 spin_lock_irq(&dev
->wl
->irq_lock
);
2190 tmp
= b43_interrupt_disable(dev
, B43_IRQ_ALL
);
2191 spin_unlock_irq(&dev
->wl
->irq_lock
);
2192 b43_synchronize_irq(dev
);
2193 dev
->irq_savedstate
= tmp
;
2195 b43_power_saving_ctl_bits(dev
, B43_PS_AWAKE
);
2196 b43_write32(dev
, B43_MMIO_MACCTL
,
2197 b43_read32(dev
, B43_MMIO_MACCTL
)
2198 & ~B43_MACCTL_ENABLED
);
2199 /* force pci to flush the write */
2200 b43_read32(dev
, B43_MMIO_MACCTL
);
2201 for (i
= 40; i
; i
--) {
2202 tmp
= b43_read32(dev
, B43_MMIO_GEN_IRQ_REASON
);
2203 if (tmp
& B43_IRQ_MAC_SUSPENDED
)
2207 b43err(dev
->wl
, "MAC suspend failed\n");
2210 dev
->mac_suspended
++;
2213 static void b43_adjust_opmode(struct b43_wldev
*dev
)
2215 struct b43_wl
*wl
= dev
->wl
;
2219 ctl
= b43_read32(dev
, B43_MMIO_MACCTL
);
2220 /* Reset status to STA infrastructure mode. */
2221 ctl
&= ~B43_MACCTL_AP
;
2222 ctl
&= ~B43_MACCTL_KEEP_CTL
;
2223 ctl
&= ~B43_MACCTL_KEEP_BADPLCP
;
2224 ctl
&= ~B43_MACCTL_KEEP_BAD
;
2225 ctl
&= ~B43_MACCTL_PROMISC
;
2226 ctl
&= ~B43_MACCTL_BEACPROMISC
;
2227 ctl
|= B43_MACCTL_INFRA
;
2229 if (b43_is_mode(wl
, IEEE80211_IF_TYPE_AP
))
2230 ctl
|= B43_MACCTL_AP
;
2231 else if (b43_is_mode(wl
, IEEE80211_IF_TYPE_IBSS
))
2232 ctl
&= ~B43_MACCTL_INFRA
;
2234 if (wl
->filter_flags
& FIF_CONTROL
)
2235 ctl
|= B43_MACCTL_KEEP_CTL
;
2236 if (wl
->filter_flags
& FIF_FCSFAIL
)
2237 ctl
|= B43_MACCTL_KEEP_BAD
;
2238 if (wl
->filter_flags
& FIF_PLCPFAIL
)
2239 ctl
|= B43_MACCTL_KEEP_BADPLCP
;
2240 if (wl
->filter_flags
& FIF_PROMISC_IN_BSS
)
2241 ctl
|= B43_MACCTL_PROMISC
;
2242 if (wl
->filter_flags
& FIF_BCN_PRBRESP_PROMISC
)
2243 ctl
|= B43_MACCTL_BEACPROMISC
;
2245 /* Workaround: On old hardware the HW-MAC-address-filter
2246 * doesn't work properly, so always run promisc in filter
2247 * it in software. */
2248 if (dev
->dev
->id
.revision
<= 4)
2249 ctl
|= B43_MACCTL_PROMISC
;
2251 b43_write32(dev
, B43_MMIO_MACCTL
, ctl
);
2254 if ((ctl
& B43_MACCTL_INFRA
) && !(ctl
& B43_MACCTL_AP
)) {
2255 if (dev
->dev
->bus
->chip_id
== 0x4306 &&
2256 dev
->dev
->bus
->chip_rev
== 3)
2261 b43_write16(dev
, 0x612, cfp_pretbtt
);
2264 static void b43_rate_memory_write(struct b43_wldev
*dev
, u16 rate
, int is_ofdm
)
2270 offset
+= (b43_plcp_get_ratecode_ofdm(rate
) & 0x000F) * 2;
2273 offset
+= (b43_plcp_get_ratecode_cck(rate
) & 0x000F) * 2;
2275 b43_shm_write16(dev
, B43_SHM_SHARED
, offset
+ 0x20,
2276 b43_shm_read16(dev
, B43_SHM_SHARED
, offset
));
2279 static void b43_rate_memory_init(struct b43_wldev
*dev
)
2281 switch (dev
->phy
.type
) {
2285 b43_rate_memory_write(dev
, B43_OFDM_RATE_6MB
, 1);
2286 b43_rate_memory_write(dev
, B43_OFDM_RATE_12MB
, 1);
2287 b43_rate_memory_write(dev
, B43_OFDM_RATE_18MB
, 1);
2288 b43_rate_memory_write(dev
, B43_OFDM_RATE_24MB
, 1);
2289 b43_rate_memory_write(dev
, B43_OFDM_RATE_36MB
, 1);
2290 b43_rate_memory_write(dev
, B43_OFDM_RATE_48MB
, 1);
2291 b43_rate_memory_write(dev
, B43_OFDM_RATE_54MB
, 1);
2292 if (dev
->phy
.type
== B43_PHYTYPE_A
)
2296 b43_rate_memory_write(dev
, B43_CCK_RATE_1MB
, 0);
2297 b43_rate_memory_write(dev
, B43_CCK_RATE_2MB
, 0);
2298 b43_rate_memory_write(dev
, B43_CCK_RATE_5MB
, 0);
2299 b43_rate_memory_write(dev
, B43_CCK_RATE_11MB
, 0);
2306 /* Set the TX-Antenna for management frames sent by firmware. */
2307 static void b43_mgmtframe_txantenna(struct b43_wldev
*dev
, int antenna
)
2314 ant
|= B43_TXH_PHY_ANT0
;
2317 ant
|= B43_TXH_PHY_ANT1
;
2320 ant
|= B43_TXH_PHY_ANT2
;
2323 ant
|= B43_TXH_PHY_ANT3
;
2325 case B43_ANTENNA_AUTO
:
2326 ant
|= B43_TXH_PHY_ANT01AUTO
;
2332 /* FIXME We also need to set the other flags of the PHY control field somewhere. */
2335 tmp
= b43_shm_read16(dev
, B43_SHM_SHARED
, B43_SHM_SH_BEACPHYCTL
);
2336 tmp
= (tmp
& ~B43_TXH_PHY_ANT
) | ant
;
2337 b43_shm_write16(dev
, B43_SHM_SHARED
, B43_SHM_SH_BEACPHYCTL
, tmp
);
2339 tmp
= b43_shm_read16(dev
, B43_SHM_SHARED
, B43_SHM_SH_ACKCTSPHYCTL
);
2340 tmp
= (tmp
& ~B43_TXH_PHY_ANT
) | ant
;
2341 b43_shm_write16(dev
, B43_SHM_SHARED
, B43_SHM_SH_ACKCTSPHYCTL
, tmp
);
2342 /* For Probe Resposes */
2343 tmp
= b43_shm_read16(dev
, B43_SHM_SHARED
, B43_SHM_SH_PRPHYCTL
);
2344 tmp
= (tmp
& ~B43_TXH_PHY_ANT
) | ant
;
2345 b43_shm_write16(dev
, B43_SHM_SHARED
, B43_SHM_SH_PRPHYCTL
, tmp
);
2348 /* This is the opposite of b43_chip_init() */
2349 static void b43_chip_exit(struct b43_wldev
*dev
)
2351 b43_radio_turn_off(dev
, 1);
2352 b43_gpio_cleanup(dev
);
2353 /* firmware is released later */
2356 /* Initialize the chip
2357 * http://bcm-specs.sipsolutions.net/ChipInit
2359 static int b43_chip_init(struct b43_wldev
*dev
)
2361 struct b43_phy
*phy
= &dev
->phy
;
2363 u32 value32
, macctl
;
2366 /* Initialize the MAC control */
2367 macctl
= B43_MACCTL_IHR_ENABLED
| B43_MACCTL_SHM_ENABLED
;
2369 macctl
|= B43_MACCTL_GMODE
;
2370 macctl
|= B43_MACCTL_INFRA
;
2371 b43_write32(dev
, B43_MMIO_MACCTL
, macctl
);
2373 err
= b43_request_firmware(dev
);
2376 err
= b43_upload_microcode(dev
);
2378 goto out
; /* firmware is released later */
2380 err
= b43_gpio_init(dev
);
2382 goto out
; /* firmware is released later */
2384 err
= b43_upload_initvals(dev
);
2386 goto err_gpio_clean
;
2387 b43_radio_turn_on(dev
);
2389 b43_write16(dev
, 0x03E6, 0x0000);
2390 err
= b43_phy_init(dev
);
2394 /* Select initial Interference Mitigation. */
2395 tmp
= phy
->interfmode
;
2396 phy
->interfmode
= B43_INTERFMODE_NONE
;
2397 b43_radio_set_interference_mitigation(dev
, tmp
);
2399 b43_set_rx_antenna(dev
, B43_ANTENNA_DEFAULT
);
2400 b43_mgmtframe_txantenna(dev
, B43_ANTENNA_DEFAULT
);
2402 if (phy
->type
== B43_PHYTYPE_B
) {
2403 value16
= b43_read16(dev
, 0x005E);
2405 b43_write16(dev
, 0x005E, value16
);
2407 b43_write32(dev
, 0x0100, 0x01000000);
2408 if (dev
->dev
->id
.revision
< 5)
2409 b43_write32(dev
, 0x010C, 0x01000000);
2411 b43_write32(dev
, B43_MMIO_MACCTL
, b43_read32(dev
, B43_MMIO_MACCTL
)
2412 & ~B43_MACCTL_INFRA
);
2413 b43_write32(dev
, B43_MMIO_MACCTL
, b43_read32(dev
, B43_MMIO_MACCTL
)
2414 | B43_MACCTL_INFRA
);
2416 /* Probe Response Timeout value */
2417 /* FIXME: Default to 0, has to be set by ioctl probably... :-/ */
2418 b43_shm_write16(dev
, B43_SHM_SHARED
, 0x0074, 0x0000);
2420 /* Initially set the wireless operation mode. */
2421 b43_adjust_opmode(dev
);
2423 if (dev
->dev
->id
.revision
< 3) {
2424 b43_write16(dev
, 0x060E, 0x0000);
2425 b43_write16(dev
, 0x0610, 0x8000);
2426 b43_write16(dev
, 0x0604, 0x0000);
2427 b43_write16(dev
, 0x0606, 0x0200);
2429 b43_write32(dev
, 0x0188, 0x80000000);
2430 b43_write32(dev
, 0x018C, 0x02000000);
2432 b43_write32(dev
, B43_MMIO_GEN_IRQ_REASON
, 0x00004000);
2433 b43_write32(dev
, B43_MMIO_DMA0_IRQ_MASK
, 0x0001DC00);
2434 b43_write32(dev
, B43_MMIO_DMA1_IRQ_MASK
, 0x0000DC00);
2435 b43_write32(dev
, B43_MMIO_DMA2_IRQ_MASK
, 0x0000DC00);
2436 b43_write32(dev
, B43_MMIO_DMA3_IRQ_MASK
, 0x0001DC00);
2437 b43_write32(dev
, B43_MMIO_DMA4_IRQ_MASK
, 0x0000DC00);
2438 b43_write32(dev
, B43_MMIO_DMA5_IRQ_MASK
, 0x0000DC00);
2440 value32
= ssb_read32(dev
->dev
, SSB_TMSLOW
);
2441 value32
|= 0x00100000;
2442 ssb_write32(dev
->dev
, SSB_TMSLOW
, value32
);
2444 b43_write16(dev
, B43_MMIO_POWERUP_DELAY
,
2445 dev
->dev
->bus
->chipco
.fast_pwrup_delay
);
2448 b43dbg(dev
->wl
, "Chip initialized\n");
2453 b43_radio_turn_off(dev
, 1);
2455 b43_gpio_cleanup(dev
);
2459 static void b43_periodic_every120sec(struct b43_wldev
*dev
)
2461 struct b43_phy
*phy
= &dev
->phy
;
2463 if (phy
->type
!= B43_PHYTYPE_G
|| phy
->rev
< 2)
2466 b43_mac_suspend(dev
);
2467 b43_lo_g_measure(dev
);
2468 b43_mac_enable(dev
);
2469 if (b43_has_hardware_pctl(phy
))
2470 b43_lo_g_ctl_mark_all_unused(dev
);
2473 static void b43_periodic_every60sec(struct b43_wldev
*dev
)
2475 struct b43_phy
*phy
= &dev
->phy
;
2477 if (phy
->type
!= B43_PHYTYPE_G
)
2479 if (!b43_has_hardware_pctl(phy
))
2480 b43_lo_g_ctl_mark_all_unused(dev
);
2481 if (dev
->dev
->bus
->sprom
.boardflags_lo
& B43_BFL_RSSI
) {
2482 b43_mac_suspend(dev
);
2483 b43_calc_nrssi_slope(dev
);
2484 if ((phy
->radio_ver
== 0x2050) && (phy
->radio_rev
== 8)) {
2485 u8 old_chan
= phy
->channel
;
2487 /* VCO Calibration */
2489 b43_radio_selectchannel(dev
, 1, 0);
2491 b43_radio_selectchannel(dev
, 13, 0);
2492 b43_radio_selectchannel(dev
, old_chan
, 0);
2494 b43_mac_enable(dev
);
2498 static void b43_periodic_every30sec(struct b43_wldev
*dev
)
2500 /* Update device statistics. */
2501 b43_calculate_link_quality(dev
);
2504 static void b43_periodic_every15sec(struct b43_wldev
*dev
)
2506 struct b43_phy
*phy
= &dev
->phy
;
2508 if (phy
->type
== B43_PHYTYPE_G
) {
2509 //TODO: update_aci_moving_average
2510 if (phy
->aci_enable
&& phy
->aci_wlan_automatic
) {
2511 b43_mac_suspend(dev
);
2512 if (!phy
->aci_enable
&& 1 /*TODO: not scanning? */ ) {
2513 if (0 /*TODO: bunch of conditions */ ) {
2514 b43_radio_set_interference_mitigation
2515 (dev
, B43_INTERFMODE_MANUALWLAN
);
2517 } else if (1 /*TODO*/) {
2519 if ((aci_average > 1000) && !(b43_radio_aci_scan(dev))) {
2520 b43_radio_set_interference_mitigation(dev,
2521 B43_INTERFMODE_NONE);
2525 b43_mac_enable(dev
);
2526 } else if (phy
->interfmode
== B43_INTERFMODE_NONWLAN
&&
2528 //TODO: implement rev1 workaround
2531 b43_phy_xmitpower(dev
); //FIXME: unless scanning?
2532 //TODO for APHY (temperature?)
2534 atomic_set(&phy
->txerr_cnt
, B43_PHY_TX_BADNESS_LIMIT
);
2538 static void do_periodic_work(struct b43_wldev
*dev
)
2542 state
= dev
->periodic_state
;
2544 b43_periodic_every120sec(dev
);
2546 b43_periodic_every60sec(dev
);
2548 b43_periodic_every30sec(dev
);
2549 b43_periodic_every15sec(dev
);
2552 /* Periodic work locking policy:
2553 * The whole periodic work handler is protected by
2554 * wl->mutex. If another lock is needed somewhere in the
2555 * pwork callchain, it's aquired in-place, where it's needed.
2557 static void b43_periodic_work_handler(struct work_struct
*work
)
2559 struct b43_wldev
*dev
= container_of(work
, struct b43_wldev
,
2560 periodic_work
.work
);
2561 struct b43_wl
*wl
= dev
->wl
;
2562 unsigned long delay
;
2564 mutex_lock(&wl
->mutex
);
2566 if (unlikely(b43_status(dev
) != B43_STAT_STARTED
))
2568 if (b43_debug(dev
, B43_DBG_PWORK_STOP
))
2571 do_periodic_work(dev
);
2573 dev
->periodic_state
++;
2575 if (b43_debug(dev
, B43_DBG_PWORK_FAST
))
2576 delay
= msecs_to_jiffies(50);
2578 delay
= round_jiffies_relative(HZ
* 15);
2579 queue_delayed_work(wl
->hw
->workqueue
, &dev
->periodic_work
, delay
);
2581 mutex_unlock(&wl
->mutex
);
2584 static void b43_periodic_tasks_setup(struct b43_wldev
*dev
)
2586 struct delayed_work
*work
= &dev
->periodic_work
;
2588 dev
->periodic_state
= 0;
2589 INIT_DELAYED_WORK(work
, b43_periodic_work_handler
);
2590 queue_delayed_work(dev
->wl
->hw
->workqueue
, work
, 0);
2593 /* Check if communication with the device works correctly. */
2594 static int b43_validate_chipaccess(struct b43_wldev
*dev
)
2598 backup
= b43_shm_read32(dev
, B43_SHM_SHARED
, 0);
2600 /* Check for read/write and endianness problems. */
2601 b43_shm_write32(dev
, B43_SHM_SHARED
, 0, 0x55AAAA55);
2602 if (b43_shm_read32(dev
, B43_SHM_SHARED
, 0) != 0x55AAAA55)
2604 b43_shm_write32(dev
, B43_SHM_SHARED
, 0, 0xAA5555AA);
2605 if (b43_shm_read32(dev
, B43_SHM_SHARED
, 0) != 0xAA5555AA)
2608 b43_shm_write32(dev
, B43_SHM_SHARED
, 0, backup
);
2610 if ((dev
->dev
->id
.revision
>= 3) && (dev
->dev
->id
.revision
<= 10)) {
2611 /* The 32bit register shadows the two 16bit registers
2612 * with update sideeffects. Validate this. */
2613 b43_write16(dev
, B43_MMIO_TSF_CFP_START
, 0xAAAA);
2614 b43_write32(dev
, B43_MMIO_TSF_CFP_START
, 0xCCCCBBBB);
2615 if (b43_read16(dev
, B43_MMIO_TSF_CFP_START_LOW
) != 0xBBBB)
2617 if (b43_read16(dev
, B43_MMIO_TSF_CFP_START_HIGH
) != 0xCCCC)
2620 b43_write32(dev
, B43_MMIO_TSF_CFP_START
, 0);
2622 v
= b43_read32(dev
, B43_MMIO_MACCTL
);
2623 v
|= B43_MACCTL_GMODE
;
2624 if (v
!= (B43_MACCTL_GMODE
| B43_MACCTL_IHR_ENABLED
))
2629 b43err(dev
->wl
, "Failed to validate the chipaccess\n");
2633 static void b43_security_init(struct b43_wldev
*dev
)
2635 dev
->max_nr_keys
= (dev
->dev
->id
.revision
>= 5) ? 58 : 20;
2636 B43_WARN_ON(dev
->max_nr_keys
> ARRAY_SIZE(dev
->key
));
2637 dev
->ktp
= b43_shm_read16(dev
, B43_SHM_SHARED
, B43_SHM_SH_KTP
);
2638 /* KTP is a word address, but we address SHM bytewise.
2639 * So multiply by two.
2642 if (dev
->dev
->id
.revision
>= 5) {
2643 /* Number of RCMTA address slots */
2644 b43_write16(dev
, B43_MMIO_RCMTA_COUNT
, dev
->max_nr_keys
- 8);
2646 b43_clear_keys(dev
);
2649 static int b43_rng_read(struct hwrng
*rng
, u32
* data
)
2651 struct b43_wl
*wl
= (struct b43_wl
*)rng
->priv
;
2652 unsigned long flags
;
2654 /* Don't take wl->mutex here, as it could deadlock with
2655 * hwrng internal locking. It's not needed to take
2656 * wl->mutex here, anyway. */
2658 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2659 *data
= b43_read16(wl
->current_dev
, B43_MMIO_RNG
);
2660 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2662 return (sizeof(u16
));
2665 static void b43_rng_exit(struct b43_wl
*wl
, bool suspended
)
2667 if (wl
->rng_initialized
)
2668 __hwrng_unregister(&wl
->rng
, suspended
);
2671 static int b43_rng_init(struct b43_wl
*wl
)
2675 snprintf(wl
->rng_name
, ARRAY_SIZE(wl
->rng_name
),
2676 "%s_%s", KBUILD_MODNAME
, wiphy_name(wl
->hw
->wiphy
));
2677 wl
->rng
.name
= wl
->rng_name
;
2678 wl
->rng
.data_read
= b43_rng_read
;
2679 wl
->rng
.priv
= (unsigned long)wl
;
2680 wl
->rng_initialized
= 1;
2681 err
= hwrng_register(&wl
->rng
);
2683 wl
->rng_initialized
= 0;
2684 b43err(wl
, "Failed to register the random "
2685 "number generator (%d)\n", err
);
2691 static int b43_op_tx(struct ieee80211_hw
*hw
,
2692 struct sk_buff
*skb
,
2693 struct ieee80211_tx_control
*ctl
)
2695 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
2696 struct b43_wldev
*dev
= wl
->current_dev
;
2701 if (unlikely(b43_status(dev
) < B43_STAT_STARTED
))
2703 /* DMA-TX is done without a global lock. */
2704 err
= b43_dma_tx(dev
, skb
, ctl
);
2707 return NETDEV_TX_BUSY
;
2708 return NETDEV_TX_OK
;
2711 static int b43_op_conf_tx(struct ieee80211_hw
*hw
,
2713 const struct ieee80211_tx_queue_params
*params
)
2718 static int b43_op_get_tx_stats(struct ieee80211_hw
*hw
,
2719 struct ieee80211_tx_queue_stats
*stats
)
2721 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
2722 struct b43_wldev
*dev
= wl
->current_dev
;
2723 unsigned long flags
;
2728 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2729 if (likely(b43_status(dev
) >= B43_STAT_STARTED
)) {
2730 b43_dma_get_tx_stats(dev
, stats
);
2733 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2738 static int b43_op_get_stats(struct ieee80211_hw
*hw
,
2739 struct ieee80211_low_level_stats
*stats
)
2741 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
2742 unsigned long flags
;
2744 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2745 memcpy(stats
, &wl
->ieee_stats
, sizeof(*stats
));
2746 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2751 static void b43_put_phy_into_reset(struct b43_wldev
*dev
)
2753 struct ssb_device
*sdev
= dev
->dev
;
2756 tmslow
= ssb_read32(sdev
, SSB_TMSLOW
);
2757 tmslow
&= ~B43_TMSLOW_GMODE
;
2758 tmslow
|= B43_TMSLOW_PHYRESET
;
2759 tmslow
|= SSB_TMSLOW_FGC
;
2760 ssb_write32(sdev
, SSB_TMSLOW
, tmslow
);
2763 tmslow
= ssb_read32(sdev
, SSB_TMSLOW
);
2764 tmslow
&= ~SSB_TMSLOW_FGC
;
2765 tmslow
|= B43_TMSLOW_PHYRESET
;
2766 ssb_write32(sdev
, SSB_TMSLOW
, tmslow
);
2770 static const char * band_to_string(enum ieee80211_band band
)
2773 case IEEE80211_BAND_5GHZ
:
2775 case IEEE80211_BAND_2GHZ
:
2784 /* Expects wl->mutex locked */
2785 static int b43_switch_band(struct b43_wl
*wl
, struct ieee80211_channel
*chan
)
2787 struct b43_wldev
*up_dev
= NULL
;
2788 struct b43_wldev
*down_dev
;
2789 struct b43_wldev
*d
;
2794 /* Find a device and PHY which supports the band. */
2795 list_for_each_entry(d
, &wl
->devlist
, list
) {
2796 switch (chan
->band
) {
2797 case IEEE80211_BAND_5GHZ
:
2798 if (d
->phy
.supports_5ghz
) {
2803 case IEEE80211_BAND_2GHZ
:
2804 if (d
->phy
.supports_2ghz
) {
2817 b43err(wl
, "Could not find a device for %s-GHz band operation\n",
2818 band_to_string(chan
->band
));
2821 if ((up_dev
== wl
->current_dev
) &&
2822 (!!wl
->current_dev
->phy
.gmode
== !!gmode
)) {
2823 /* This device is already running. */
2826 b43dbg(wl
, "Switching to %s-GHz band\n",
2827 band_to_string(chan
->band
));
2828 down_dev
= wl
->current_dev
;
2830 prev_status
= b43_status(down_dev
);
2831 /* Shutdown the currently running core. */
2832 if (prev_status
>= B43_STAT_STARTED
)
2833 b43_wireless_core_stop(down_dev
);
2834 if (prev_status
>= B43_STAT_INITIALIZED
)
2835 b43_wireless_core_exit(down_dev
);
2837 if (down_dev
!= up_dev
) {
2838 /* We switch to a different core, so we put PHY into
2839 * RESET on the old core. */
2840 b43_put_phy_into_reset(down_dev
);
2843 /* Now start the new core. */
2844 up_dev
->phy
.gmode
= gmode
;
2845 if (prev_status
>= B43_STAT_INITIALIZED
) {
2846 err
= b43_wireless_core_init(up_dev
);
2848 b43err(wl
, "Fatal: Could not initialize device for "
2849 "selected %s-GHz band\n",
2850 band_to_string(chan
->band
));
2854 if (prev_status
>= B43_STAT_STARTED
) {
2855 err
= b43_wireless_core_start(up_dev
);
2857 b43err(wl
, "Fatal: Coult not start device for "
2858 "selected %s-GHz band\n",
2859 band_to_string(chan
->band
));
2860 b43_wireless_core_exit(up_dev
);
2864 B43_WARN_ON(b43_status(up_dev
) != prev_status
);
2866 wl
->current_dev
= up_dev
;
2870 /* Whoops, failed to init the new core. No core is operating now. */
2871 wl
->current_dev
= NULL
;
2875 /* Check if the use of the antenna that ieee80211 told us to
2876 * use is possible. This will fall back to DEFAULT.
2877 * "antenna_nr" is the antenna identifier we got from ieee80211. */
2878 u8
b43_ieee80211_antenna_sanitize(struct b43_wldev
*dev
,
2883 if (antenna_nr
== 0) {
2884 /* Zero means "use default antenna". That's always OK. */
2888 /* Get the mask of available antennas. */
2890 antenna_mask
= dev
->dev
->bus
->sprom
.ant_available_bg
;
2892 antenna_mask
= dev
->dev
->bus
->sprom
.ant_available_a
;
2894 if (!(antenna_mask
& (1 << (antenna_nr
- 1)))) {
2895 /* This antenna is not available. Fall back to default. */
2902 static int b43_antenna_from_ieee80211(struct b43_wldev
*dev
, u8 antenna
)
2904 antenna
= b43_ieee80211_antenna_sanitize(dev
, antenna
);
2906 case 0: /* default/diversity */
2907 return B43_ANTENNA_DEFAULT
;
2908 case 1: /* Antenna 0 */
2909 return B43_ANTENNA0
;
2910 case 2: /* Antenna 1 */
2911 return B43_ANTENNA1
;
2912 case 3: /* Antenna 2 */
2913 return B43_ANTENNA2
;
2914 case 4: /* Antenna 3 */
2915 return B43_ANTENNA3
;
2917 return B43_ANTENNA_DEFAULT
;
2921 static int b43_op_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
)
2923 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
2924 struct b43_wldev
*dev
;
2925 struct b43_phy
*phy
;
2926 unsigned long flags
;
2931 mutex_lock(&wl
->mutex
);
2933 /* Switch the band (if necessary). This might change the active core. */
2934 err
= b43_switch_band(wl
, conf
->channel
);
2936 goto out_unlock_mutex
;
2937 dev
= wl
->current_dev
;
2940 /* Disable IRQs while reconfiguring the device.
2941 * This makes it possible to drop the spinlock throughout
2942 * the reconfiguration process. */
2943 spin_lock_irqsave(&wl
->irq_lock
, flags
);
2944 if (b43_status(dev
) < B43_STAT_STARTED
) {
2945 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2946 goto out_unlock_mutex
;
2948 savedirqs
= b43_interrupt_disable(dev
, B43_IRQ_ALL
);
2949 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
2950 b43_synchronize_irq(dev
);
2952 /* Switch to the requested channel.
2953 * The firmware takes care of races with the TX handler. */
2954 if (conf
->channel
->hw_value
!= phy
->channel
)
2955 b43_radio_selectchannel(dev
, conf
->channel
->hw_value
, 0);
2957 /* Enable/Disable ShortSlot timing. */
2958 if ((!!(conf
->flags
& IEEE80211_CONF_SHORT_SLOT_TIME
)) !=
2960 B43_WARN_ON(phy
->type
!= B43_PHYTYPE_G
);
2961 if (conf
->flags
& IEEE80211_CONF_SHORT_SLOT_TIME
)
2962 b43_short_slot_timing_enable(dev
);
2964 b43_short_slot_timing_disable(dev
);
2967 dev
->wl
->radiotap_enabled
= !!(conf
->flags
& IEEE80211_CONF_RADIOTAP
);
2969 /* Adjust the desired TX power level. */
2970 if (conf
->power_level
!= 0) {
2971 if (conf
->power_level
!= phy
->power_level
) {
2972 phy
->power_level
= conf
->power_level
;
2973 b43_phy_xmitpower(dev
);
2977 /* Antennas for RX and management frame TX. */
2978 antenna
= b43_antenna_from_ieee80211(dev
, conf
->antenna_sel_tx
);
2979 b43_mgmtframe_txantenna(dev
, antenna
);
2980 antenna
= b43_antenna_from_ieee80211(dev
, conf
->antenna_sel_rx
);
2981 b43_set_rx_antenna(dev
, antenna
);
2983 /* Update templates for AP mode. */
2984 if (b43_is_mode(wl
, IEEE80211_IF_TYPE_AP
))
2985 b43_set_beacon_int(dev
, conf
->beacon_int
);
2987 if (!!conf
->radio_enabled
!= phy
->radio_on
) {
2988 if (conf
->radio_enabled
) {
2989 b43_radio_turn_on(dev
);
2990 b43info(dev
->wl
, "Radio turned on by software\n");
2991 if (!dev
->radio_hw_enable
) {
2992 b43info(dev
->wl
, "The hardware RF-kill button "
2993 "still turns the radio physically off. "
2994 "Press the button to turn it on.\n");
2997 b43_radio_turn_off(dev
, 0);
2998 b43info(dev
->wl
, "Radio turned off by software\n");
3002 spin_lock_irqsave(&wl
->irq_lock
, flags
);
3003 b43_interrupt_enable(dev
, savedirqs
);
3005 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
3007 mutex_unlock(&wl
->mutex
);
3012 static int b43_op_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
3013 const u8
*local_addr
, const u8
*addr
,
3014 struct ieee80211_key_conf
*key
)
3016 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
3017 struct b43_wldev
*dev
;
3018 unsigned long flags
;
3022 DECLARE_MAC_BUF(mac
);
3024 if (modparam_nohwcrypt
)
3025 return -ENOSPC
; /* User disabled HW-crypto */
3027 mutex_lock(&wl
->mutex
);
3028 spin_lock_irqsave(&wl
->irq_lock
, flags
);
3030 dev
= wl
->current_dev
;
3032 if (!dev
|| b43_status(dev
) < B43_STAT_INITIALIZED
)
3038 if (key
->keylen
== 5)
3039 algorithm
= B43_SEC_ALGO_WEP40
;
3041 algorithm
= B43_SEC_ALGO_WEP104
;
3044 algorithm
= B43_SEC_ALGO_TKIP
;
3047 algorithm
= B43_SEC_ALGO_AES
;
3053 index
= (u8
) (key
->keyidx
);
3059 if (algorithm
== B43_SEC_ALGO_TKIP
) {
3060 /* FIXME: No TKIP hardware encryption for now. */
3065 if (is_broadcast_ether_addr(addr
)) {
3066 /* addr is FF:FF:FF:FF:FF:FF for default keys */
3067 err
= b43_key_write(dev
, index
, algorithm
,
3068 key
->key
, key
->keylen
, NULL
, key
);
3071 * either pairwise key or address is 00:00:00:00:00:00
3072 * for transmit-only keys
3074 err
= b43_key_write(dev
, -1, algorithm
,
3075 key
->key
, key
->keylen
, addr
, key
);
3080 if (algorithm
== B43_SEC_ALGO_WEP40
||
3081 algorithm
== B43_SEC_ALGO_WEP104
) {
3082 b43_hf_write(dev
, b43_hf_read(dev
) | B43_HF_USEDEFKEYS
);
3085 b43_hf_read(dev
) & ~B43_HF_USEDEFKEYS
);
3087 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
3090 err
= b43_key_clear(dev
, key
->hw_key_idx
);
3099 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
3100 mutex_unlock(&wl
->mutex
);
3102 b43dbg(wl
, "%s hardware based encryption for keyidx: %d, "
3104 cmd
== SET_KEY
? "Using" : "Disabling", key
->keyidx
,
3105 print_mac(mac
, addr
));
3110 static void b43_op_configure_filter(struct ieee80211_hw
*hw
,
3111 unsigned int changed
, unsigned int *fflags
,
3112 int mc_count
, struct dev_addr_list
*mc_list
)
3114 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
3115 struct b43_wldev
*dev
= wl
->current_dev
;
3116 unsigned long flags
;
3123 spin_lock_irqsave(&wl
->irq_lock
, flags
);
3124 *fflags
&= FIF_PROMISC_IN_BSS
|
3130 FIF_BCN_PRBRESP_PROMISC
;
3132 changed
&= FIF_PROMISC_IN_BSS
|
3138 FIF_BCN_PRBRESP_PROMISC
;
3140 wl
->filter_flags
= *fflags
;
3142 if (changed
&& b43_status(dev
) >= B43_STAT_INITIALIZED
)
3143 b43_adjust_opmode(dev
);
3144 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
3147 static int b43_op_config_interface(struct ieee80211_hw
*hw
,
3148 struct ieee80211_vif
*vif
,
3149 struct ieee80211_if_conf
*conf
)
3151 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
3152 struct b43_wldev
*dev
= wl
->current_dev
;
3153 unsigned long flags
;
3157 mutex_lock(&wl
->mutex
);
3158 spin_lock_irqsave(&wl
->irq_lock
, flags
);
3159 B43_WARN_ON(wl
->vif
!= vif
);
3161 memcpy(wl
->bssid
, conf
->bssid
, ETH_ALEN
);
3163 memset(wl
->bssid
, 0, ETH_ALEN
);
3164 if (b43_status(dev
) >= B43_STAT_INITIALIZED
) {
3165 if (b43_is_mode(wl
, IEEE80211_IF_TYPE_AP
)) {
3166 B43_WARN_ON(conf
->type
!= IEEE80211_IF_TYPE_AP
);
3167 b43_set_ssid(dev
, conf
->ssid
, conf
->ssid_len
);
3169 b43_update_templates(wl
, conf
->beacon
);
3171 b43_write_mac_bssid_templates(dev
);
3173 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
3174 mutex_unlock(&wl
->mutex
);
3179 /* Locking: wl->mutex */
3180 static void b43_wireless_core_stop(struct b43_wldev
*dev
)
3182 struct b43_wl
*wl
= dev
->wl
;
3183 unsigned long flags
;
3185 if (b43_status(dev
) < B43_STAT_STARTED
)
3188 /* Disable and sync interrupts. We must do this before than
3189 * setting the status to INITIALIZED, as the interrupt handler
3190 * won't care about IRQs then. */
3191 spin_lock_irqsave(&wl
->irq_lock
, flags
);
3192 dev
->irq_savedstate
= b43_interrupt_disable(dev
, B43_IRQ_ALL
);
3193 b43_read32(dev
, B43_MMIO_GEN_IRQ_MASK
); /* flush */
3194 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
3195 b43_synchronize_irq(dev
);
3197 b43_set_status(dev
, B43_STAT_INITIALIZED
);
3199 mutex_unlock(&wl
->mutex
);
3200 /* Must unlock as it would otherwise deadlock. No races here.
3201 * Cancel the possibly running self-rearming periodic work. */
3202 cancel_delayed_work_sync(&dev
->periodic_work
);
3203 mutex_lock(&wl
->mutex
);
3205 ieee80211_stop_queues(wl
->hw
); //FIXME this could cause a deadlock, as mac80211 seems buggy.
3207 b43_mac_suspend(dev
);
3208 free_irq(dev
->dev
->irq
, dev
);
3209 b43dbg(wl
, "Wireless interface stopped\n");
3212 /* Locking: wl->mutex */
3213 static int b43_wireless_core_start(struct b43_wldev
*dev
)
3217 B43_WARN_ON(b43_status(dev
) != B43_STAT_INITIALIZED
);
3219 drain_txstatus_queue(dev
);
3220 err
= request_irq(dev
->dev
->irq
, b43_interrupt_handler
,
3221 IRQF_SHARED
, KBUILD_MODNAME
, dev
);
3223 b43err(dev
->wl
, "Cannot request IRQ-%d\n", dev
->dev
->irq
);
3227 /* We are ready to run. */
3228 b43_set_status(dev
, B43_STAT_STARTED
);
3230 /* Start data flow (TX/RX). */
3231 b43_mac_enable(dev
);
3232 b43_interrupt_enable(dev
, dev
->irq_savedstate
);
3233 ieee80211_start_queues(dev
->wl
->hw
);
3235 /* Start maintainance work */
3236 b43_periodic_tasks_setup(dev
);
3238 b43dbg(dev
->wl
, "Wireless interface started\n");
3243 /* Get PHY and RADIO versioning numbers */
3244 static int b43_phy_versioning(struct b43_wldev
*dev
)
3246 struct b43_phy
*phy
= &dev
->phy
;
3254 int unsupported
= 0;
3256 /* Get PHY versioning */
3257 tmp
= b43_read16(dev
, B43_MMIO_PHY_VER
);
3258 analog_type
= (tmp
& B43_PHYVER_ANALOG
) >> B43_PHYVER_ANALOG_SHIFT
;
3259 phy_type
= (tmp
& B43_PHYVER_TYPE
) >> B43_PHYVER_TYPE_SHIFT
;
3260 phy_rev
= (tmp
& B43_PHYVER_VERSION
);
3267 if (phy_rev
!= 2 && phy_rev
!= 4 && phy_rev
!= 6
3275 #ifdef CONFIG_B43_NPHY
3285 b43err(dev
->wl
, "FOUND UNSUPPORTED PHY "
3286 "(Analog %u, Type %u, Revision %u)\n",
3287 analog_type
, phy_type
, phy_rev
);
3290 b43dbg(dev
->wl
, "Found PHY: Analog %u, Type %u, Revision %u\n",
3291 analog_type
, phy_type
, phy_rev
);
3293 /* Get RADIO versioning */
3294 if (dev
->dev
->bus
->chip_id
== 0x4317) {
3295 if (dev
->dev
->bus
->chip_rev
== 0)
3297 else if (dev
->dev
->bus
->chip_rev
== 1)
3302 b43_write16(dev
, B43_MMIO_RADIO_CONTROL
, B43_RADIOCTL_ID
);
3303 tmp
= b43_read16(dev
, B43_MMIO_RADIO_DATA_LOW
);
3304 b43_write16(dev
, B43_MMIO_RADIO_CONTROL
, B43_RADIOCTL_ID
);
3305 tmp
|= (u32
)b43_read16(dev
, B43_MMIO_RADIO_DATA_HIGH
) << 16;
3307 radio_manuf
= (tmp
& 0x00000FFF);
3308 radio_ver
= (tmp
& 0x0FFFF000) >> 12;
3309 radio_rev
= (tmp
& 0xF0000000) >> 28;
3310 if (radio_manuf
!= 0x17F /* Broadcom */)
3314 if (radio_ver
!= 0x2060)
3318 if (radio_manuf
!= 0x17F)
3322 if ((radio_ver
& 0xFFF0) != 0x2050)
3326 if (radio_ver
!= 0x2050)
3330 if (radio_ver
!= 0x2055)
3337 b43err(dev
->wl
, "FOUND UNSUPPORTED RADIO "
3338 "(Manuf 0x%X, Version 0x%X, Revision %u)\n",
3339 radio_manuf
, radio_ver
, radio_rev
);
3342 b43dbg(dev
->wl
, "Found Radio: Manuf 0x%X, Version 0x%X, Revision %u\n",
3343 radio_manuf
, radio_ver
, radio_rev
);
3345 phy
->radio_manuf
= radio_manuf
;
3346 phy
->radio_ver
= radio_ver
;
3347 phy
->radio_rev
= radio_rev
;
3349 phy
->analog
= analog_type
;
3350 phy
->type
= phy_type
;
3356 static void setup_struct_phy_for_init(struct b43_wldev
*dev
,
3357 struct b43_phy
*phy
)
3359 struct b43_txpower_lo_control
*lo
;
3362 memset(phy
->minlowsig
, 0xFF, sizeof(phy
->minlowsig
));
3363 memset(phy
->minlowsigpos
, 0, sizeof(phy
->minlowsigpos
));
3365 phy
->aci_enable
= 0;
3366 phy
->aci_wlan_automatic
= 0;
3367 phy
->aci_hw_rssi
= 0;
3369 phy
->radio_off_context
.valid
= 0;
3371 lo
= phy
->lo_control
;
3373 memset(lo
, 0, sizeof(*(phy
->lo_control
)));
3377 phy
->max_lb_gain
= 0;
3378 phy
->trsw_rx_gain
= 0;
3379 phy
->txpwr_offset
= 0;
3382 phy
->nrssislope
= 0;
3383 for (i
= 0; i
< ARRAY_SIZE(phy
->nrssi
); i
++)
3384 phy
->nrssi
[i
] = -1000;
3385 for (i
= 0; i
< ARRAY_SIZE(phy
->nrssi_lt
); i
++)
3386 phy
->nrssi_lt
[i
] = i
;
3388 phy
->lofcal
= 0xFFFF;
3389 phy
->initval
= 0xFFFF;
3391 phy
->interfmode
= B43_INTERFMODE_NONE
;
3392 phy
->channel
= 0xFF;
3394 phy
->hardware_power_control
= !!modparam_hwpctl
;
3396 /* PHY TX errors counter. */
3397 atomic_set(&phy
->txerr_cnt
, B43_PHY_TX_BADNESS_LIMIT
);
3399 /* OFDM-table address caching. */
3400 phy
->ofdmtab_addr_direction
= B43_OFDMTAB_DIRECTION_UNKNOWN
;
3403 static void setup_struct_wldev_for_init(struct b43_wldev
*dev
)
3407 /* Assume the radio is enabled. If it's not enabled, the state will
3408 * immediately get fixed on the first periodic work run. */
3409 dev
->radio_hw_enable
= 1;
3412 memset(&dev
->stats
, 0, sizeof(dev
->stats
));
3414 setup_struct_phy_for_init(dev
, &dev
->phy
);
3416 /* IRQ related flags */
3417 dev
->irq_reason
= 0;
3418 memset(dev
->dma_reason
, 0, sizeof(dev
->dma_reason
));
3419 dev
->irq_savedstate
= B43_IRQ_MASKTEMPLATE
;
3421 dev
->mac_suspended
= 1;
3423 /* Noise calculation context */
3424 memset(&dev
->noisecalc
, 0, sizeof(dev
->noisecalc
));
3427 static void b43_bluetooth_coext_enable(struct b43_wldev
*dev
)
3429 struct ssb_sprom
*sprom
= &dev
->dev
->bus
->sprom
;
3432 if (!(sprom
->boardflags_lo
& B43_BFL_BTCOEXIST
))
3434 if (dev
->phy
.type
!= B43_PHYTYPE_B
&& !dev
->phy
.gmode
)
3437 hf
= b43_hf_read(dev
);
3438 if (sprom
->boardflags_lo
& B43_BFL_BTCMOD
)
3439 hf
|= B43_HF_BTCOEXALT
;
3441 hf
|= B43_HF_BTCOEX
;
3442 b43_hf_write(dev
, hf
);
3446 static void b43_bluetooth_coext_disable(struct b43_wldev
*dev
)
3450 static void b43_imcfglo_timeouts_workaround(struct b43_wldev
*dev
)
3452 #ifdef CONFIG_SSB_DRIVER_PCICORE
3453 struct ssb_bus
*bus
= dev
->dev
->bus
;
3456 if (bus
->pcicore
.dev
&&
3457 bus
->pcicore
.dev
->id
.coreid
== SSB_DEV_PCI
&&
3458 bus
->pcicore
.dev
->id
.revision
<= 5) {
3459 /* IMCFGLO timeouts workaround. */
3460 tmp
= ssb_read32(dev
->dev
, SSB_IMCFGLO
);
3461 tmp
&= ~SSB_IMCFGLO_REQTO
;
3462 tmp
&= ~SSB_IMCFGLO_SERTO
;
3463 switch (bus
->bustype
) {
3464 case SSB_BUSTYPE_PCI
:
3465 case SSB_BUSTYPE_PCMCIA
:
3468 case SSB_BUSTYPE_SSB
:
3472 ssb_write32(dev
->dev
, SSB_IMCFGLO
, tmp
);
3474 #endif /* CONFIG_SSB_DRIVER_PCICORE */
3477 /* Write the short and long frame retry limit values. */
3478 static void b43_set_retry_limits(struct b43_wldev
*dev
,
3479 unsigned int short_retry
,
3480 unsigned int long_retry
)
3482 /* The retry limit is a 4-bit counter. Enforce this to avoid overflowing
3483 * the chip-internal counter. */
3484 short_retry
= min(short_retry
, (unsigned int)0xF);
3485 long_retry
= min(long_retry
, (unsigned int)0xF);
3487 b43_shm_write16(dev
, B43_SHM_SCRATCH
, B43_SHM_SC_SRLIMIT
,
3489 b43_shm_write16(dev
, B43_SHM_SCRATCH
, B43_SHM_SC_LRLIMIT
,
3493 /* Shutdown a wireless core */
3494 /* Locking: wl->mutex */
3495 static void b43_wireless_core_exit(struct b43_wldev
*dev
)
3497 struct b43_phy
*phy
= &dev
->phy
;
3500 B43_WARN_ON(b43_status(dev
) > B43_STAT_INITIALIZED
);
3501 if (b43_status(dev
) != B43_STAT_INITIALIZED
)
3503 b43_set_status(dev
, B43_STAT_UNINIT
);
3505 /* Stop the microcode PSM. */
3506 macctl
= b43_read32(dev
, B43_MMIO_MACCTL
);
3507 macctl
&= ~B43_MACCTL_PSM_RUN
;
3508 macctl
|= B43_MACCTL_PSM_JMP0
;
3509 b43_write32(dev
, B43_MMIO_MACCTL
, macctl
);
3511 if (!dev
->suspend_in_progress
) {
3513 b43_rng_exit(dev
->wl
, false);
3517 b43_radio_turn_off(dev
, 1);
3518 b43_switch_analog(dev
, 0);
3519 if (phy
->dyn_tssi_tbl
)
3520 kfree(phy
->tssi2dbm
);
3521 kfree(phy
->lo_control
);
3522 phy
->lo_control
= NULL
;
3523 if (dev
->wl
->current_beacon
) {
3524 dev_kfree_skb_any(dev
->wl
->current_beacon
);
3525 dev
->wl
->current_beacon
= NULL
;
3528 ssb_device_disable(dev
->dev
, 0);
3529 ssb_bus_may_powerdown(dev
->dev
->bus
);
3532 /* Initialize a wireless core */
3533 static int b43_wireless_core_init(struct b43_wldev
*dev
)
3535 struct b43_wl
*wl
= dev
->wl
;
3536 struct ssb_bus
*bus
= dev
->dev
->bus
;
3537 struct ssb_sprom
*sprom
= &bus
->sprom
;
3538 struct b43_phy
*phy
= &dev
->phy
;
3542 B43_WARN_ON(b43_status(dev
) != B43_STAT_UNINIT
);
3544 err
= ssb_bus_powerup(bus
, 0);
3547 if (!ssb_device_is_enabled(dev
->dev
)) {
3548 tmp
= phy
->gmode
? B43_TMSLOW_GMODE
: 0;
3549 b43_wireless_core_reset(dev
, tmp
);
3552 if ((phy
->type
== B43_PHYTYPE_B
) || (phy
->type
== B43_PHYTYPE_G
)) {
3554 kzalloc(sizeof(*(phy
->lo_control
)), GFP_KERNEL
);
3555 if (!phy
->lo_control
) {
3560 setup_struct_wldev_for_init(dev
);
3562 err
= b43_phy_init_tssi2dbm_table(dev
);
3564 goto err_kfree_lo_control
;
3566 /* Enable IRQ routing to this device. */
3567 ssb_pcicore_dev_irqvecs_enable(&bus
->pcicore
, dev
->dev
);
3569 b43_imcfglo_timeouts_workaround(dev
);
3570 b43_bluetooth_coext_disable(dev
);
3571 b43_phy_early_init(dev
);
3572 err
= b43_chip_init(dev
);
3574 goto err_kfree_tssitbl
;
3575 b43_shm_write16(dev
, B43_SHM_SHARED
,
3576 B43_SHM_SH_WLCOREREV
, dev
->dev
->id
.revision
);
3577 hf
= b43_hf_read(dev
);
3578 if (phy
->type
== B43_PHYTYPE_G
) {
3582 if (sprom
->boardflags_lo
& B43_BFL_PACTRL
)
3583 hf
|= B43_HF_OFDMPABOOST
;
3584 } else if (phy
->type
== B43_PHYTYPE_B
) {
3586 if (phy
->rev
>= 2 && phy
->radio_ver
== 0x2050)
3589 b43_hf_write(dev
, hf
);
3591 b43_set_retry_limits(dev
, B43_DEFAULT_SHORT_RETRY_LIMIT
,
3592 B43_DEFAULT_LONG_RETRY_LIMIT
);
3593 b43_shm_write16(dev
, B43_SHM_SHARED
, B43_SHM_SH_SFFBLIM
, 3);
3594 b43_shm_write16(dev
, B43_SHM_SHARED
, B43_SHM_SH_LFFBLIM
, 2);
3596 /* Disable sending probe responses from firmware.
3597 * Setting the MaxTime to one usec will always trigger
3598 * a timeout, so we never send any probe resp.
3599 * A timeout of zero is infinite. */
3600 b43_shm_write16(dev
, B43_SHM_SHARED
, B43_SHM_SH_PRMAXTIME
, 1);
3602 b43_rate_memory_init(dev
);
3604 /* Minimum Contention Window */
3605 if (phy
->type
== B43_PHYTYPE_B
) {
3606 b43_shm_write16(dev
, B43_SHM_SCRATCH
, B43_SHM_SC_MINCONT
, 0x1F);
3608 b43_shm_write16(dev
, B43_SHM_SCRATCH
, B43_SHM_SC_MINCONT
, 0xF);
3610 /* Maximum Contention Window */
3611 b43_shm_write16(dev
, B43_SHM_SCRATCH
, B43_SHM_SC_MAXCONT
, 0x3FF);
3613 err
= b43_dma_init(dev
);
3620 b43_write16(dev
, 0x0612, 0x0050);
3621 b43_shm_write16(dev
, B43_SHM_SHARED
, 0x0416, 0x0050);
3622 b43_shm_write16(dev
, B43_SHM_SHARED
, 0x0414, 0x01F4);
3625 b43_bluetooth_coext_enable(dev
);
3627 ssb_bus_powerup(bus
, 1); /* Enable dynamic PCTL */
3628 b43_upload_card_macaddress(dev
);
3629 b43_security_init(dev
);
3630 if (!dev
->suspend_in_progress
)
3633 b43_set_status(dev
, B43_STAT_INITIALIZED
);
3635 if (!dev
->suspend_in_progress
)
3643 if (phy
->dyn_tssi_tbl
)
3644 kfree(phy
->tssi2dbm
);
3645 err_kfree_lo_control
:
3646 kfree(phy
->lo_control
);
3647 phy
->lo_control
= NULL
;
3649 ssb_bus_may_powerdown(bus
);
3650 B43_WARN_ON(b43_status(dev
) != B43_STAT_UNINIT
);
3654 static int b43_op_add_interface(struct ieee80211_hw
*hw
,
3655 struct ieee80211_if_init_conf
*conf
)
3657 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
3658 struct b43_wldev
*dev
;
3659 unsigned long flags
;
3660 int err
= -EOPNOTSUPP
;
3662 /* TODO: allow WDS/AP devices to coexist */
3664 if (conf
->type
!= IEEE80211_IF_TYPE_AP
&&
3665 conf
->type
!= IEEE80211_IF_TYPE_STA
&&
3666 conf
->type
!= IEEE80211_IF_TYPE_WDS
&&
3667 conf
->type
!= IEEE80211_IF_TYPE_IBSS
)
3670 mutex_lock(&wl
->mutex
);
3672 goto out_mutex_unlock
;
3674 b43dbg(wl
, "Adding Interface type %d\n", conf
->type
);
3676 dev
= wl
->current_dev
;
3678 wl
->vif
= conf
->vif
;
3679 wl
->if_type
= conf
->type
;
3680 memcpy(wl
->mac_addr
, conf
->mac_addr
, ETH_ALEN
);
3682 spin_lock_irqsave(&wl
->irq_lock
, flags
);
3683 b43_adjust_opmode(dev
);
3684 b43_upload_card_macaddress(dev
);
3685 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
3689 mutex_unlock(&wl
->mutex
);
3694 static void b43_op_remove_interface(struct ieee80211_hw
*hw
,
3695 struct ieee80211_if_init_conf
*conf
)
3697 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
3698 struct b43_wldev
*dev
= wl
->current_dev
;
3699 unsigned long flags
;
3701 b43dbg(wl
, "Removing Interface type %d\n", conf
->type
);
3703 mutex_lock(&wl
->mutex
);
3705 B43_WARN_ON(!wl
->operating
);
3706 B43_WARN_ON(wl
->vif
!= conf
->vif
);
3711 spin_lock_irqsave(&wl
->irq_lock
, flags
);
3712 b43_adjust_opmode(dev
);
3713 memset(wl
->mac_addr
, 0, ETH_ALEN
);
3714 b43_upload_card_macaddress(dev
);
3715 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
3717 mutex_unlock(&wl
->mutex
);
3720 static int b43_op_start(struct ieee80211_hw
*hw
)
3722 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
3723 struct b43_wldev
*dev
= wl
->current_dev
;
3726 bool do_rfkill_exit
= 0;
3728 /* Kill all old instance specific information to make sure
3729 * the card won't use it in the short timeframe between start
3730 * and mac80211 reconfiguring it. */
3731 memset(wl
->bssid
, 0, ETH_ALEN
);
3732 memset(wl
->mac_addr
, 0, ETH_ALEN
);
3733 wl
->filter_flags
= 0;
3734 wl
->radiotap_enabled
= 0;
3736 /* First register RFkill.
3737 * LEDs that are registered later depend on it. */
3738 b43_rfkill_init(dev
);
3740 mutex_lock(&wl
->mutex
);
3742 if (b43_status(dev
) < B43_STAT_INITIALIZED
) {
3743 err
= b43_wireless_core_init(dev
);
3746 goto out_mutex_unlock
;
3751 if (b43_status(dev
) < B43_STAT_STARTED
) {
3752 err
= b43_wireless_core_start(dev
);
3755 b43_wireless_core_exit(dev
);
3757 goto out_mutex_unlock
;
3762 mutex_unlock(&wl
->mutex
);
3765 b43_rfkill_exit(dev
);
3770 static void b43_op_stop(struct ieee80211_hw
*hw
)
3772 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
3773 struct b43_wldev
*dev
= wl
->current_dev
;
3775 b43_rfkill_exit(dev
);
3777 mutex_lock(&wl
->mutex
);
3778 if (b43_status(dev
) >= B43_STAT_STARTED
)
3779 b43_wireless_core_stop(dev
);
3780 b43_wireless_core_exit(dev
);
3781 mutex_unlock(&wl
->mutex
);
3784 static int b43_op_set_retry_limit(struct ieee80211_hw
*hw
,
3785 u32 short_retry_limit
, u32 long_retry_limit
)
3787 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
3788 struct b43_wldev
*dev
;
3791 mutex_lock(&wl
->mutex
);
3792 dev
= wl
->current_dev
;
3793 if (unlikely(!dev
|| (b43_status(dev
) < B43_STAT_INITIALIZED
))) {
3797 b43_set_retry_limits(dev
, short_retry_limit
, long_retry_limit
);
3799 mutex_unlock(&wl
->mutex
);
3804 static int b43_op_beacon_set_tim(struct ieee80211_hw
*hw
, int aid
, int set
)
3806 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
3807 struct sk_buff
*beacon
;
3808 unsigned long flags
;
3810 /* We could modify the existing beacon and set the aid bit in
3811 * the TIM field, but that would probably require resizing and
3812 * moving of data within the beacon template.
3813 * Simply request a new beacon and let mac80211 do the hard work. */
3814 beacon
= ieee80211_beacon_get(hw
, wl
->vif
, NULL
);
3815 if (unlikely(!beacon
))
3817 spin_lock_irqsave(&wl
->irq_lock
, flags
);
3818 b43_update_templates(wl
, beacon
);
3819 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
3824 static int b43_op_ibss_beacon_update(struct ieee80211_hw
*hw
,
3825 struct sk_buff
*beacon
,
3826 struct ieee80211_tx_control
*ctl
)
3828 struct b43_wl
*wl
= hw_to_b43_wl(hw
);
3829 unsigned long flags
;
3831 spin_lock_irqsave(&wl
->irq_lock
, flags
);
3832 b43_update_templates(wl
, beacon
);
3833 spin_unlock_irqrestore(&wl
->irq_lock
, flags
);
3838 static const struct ieee80211_ops b43_hw_ops
= {
3840 .conf_tx
= b43_op_conf_tx
,
3841 .add_interface
= b43_op_add_interface
,
3842 .remove_interface
= b43_op_remove_interface
,
3843 .config
= b43_op_config
,
3844 .config_interface
= b43_op_config_interface
,
3845 .configure_filter
= b43_op_configure_filter
,
3846 .set_key
= b43_op_set_key
,
3847 .get_stats
= b43_op_get_stats
,
3848 .get_tx_stats
= b43_op_get_tx_stats
,
3849 .start
= b43_op_start
,
3850 .stop
= b43_op_stop
,
3851 .set_retry_limit
= b43_op_set_retry_limit
,
3852 .set_tim
= b43_op_beacon_set_tim
,
3853 .beacon_update
= b43_op_ibss_beacon_update
,
3856 /* Hard-reset the chip. Do not call this directly.
3857 * Use b43_controller_restart()
3859 static void b43_chip_reset(struct work_struct
*work
)
3861 struct b43_wldev
*dev
=
3862 container_of(work
, struct b43_wldev
, restart_work
);
3863 struct b43_wl
*wl
= dev
->wl
;
3867 mutex_lock(&wl
->mutex
);
3869 prev_status
= b43_status(dev
);
3870 /* Bring the device down... */
3871 if (prev_status
>= B43_STAT_STARTED
)
3872 b43_wireless_core_stop(dev
);
3873 if (prev_status
>= B43_STAT_INITIALIZED
)
3874 b43_wireless_core_exit(dev
);
3876 /* ...and up again. */
3877 if (prev_status
>= B43_STAT_INITIALIZED
) {
3878 err
= b43_wireless_core_init(dev
);
3882 if (prev_status
>= B43_STAT_STARTED
) {
3883 err
= b43_wireless_core_start(dev
);
3885 b43_wireless_core_exit(dev
);
3890 mutex_unlock(&wl
->mutex
);
3892 b43err(wl
, "Controller restart FAILED\n");
3894 b43info(wl
, "Controller restarted\n");
3897 static int b43_setup_bands(struct b43_wldev
*dev
,
3898 bool have_2ghz_phy
, bool have_5ghz_phy
)
3900 struct ieee80211_hw
*hw
= dev
->wl
->hw
;
3903 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &b43_band_2GHz
;
3904 if (dev
->phy
.type
== B43_PHYTYPE_N
) {
3906 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = &b43_band_5GHz_nphy
;
3909 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = &b43_band_5GHz_aphy
;
3912 dev
->phy
.supports_2ghz
= have_2ghz_phy
;
3913 dev
->phy
.supports_5ghz
= have_5ghz_phy
;
3918 static void b43_wireless_core_detach(struct b43_wldev
*dev
)
3920 /* We release firmware that late to not be required to re-request
3921 * is all the time when we reinit the core. */
3922 b43_release_firmware(dev
);
3925 static int b43_wireless_core_attach(struct b43_wldev
*dev
)
3927 struct b43_wl
*wl
= dev
->wl
;
3928 struct ssb_bus
*bus
= dev
->dev
->bus
;
3929 struct pci_dev
*pdev
= bus
->host_pci
;
3931 bool have_2ghz_phy
= 0, have_5ghz_phy
= 0;
3934 /* Do NOT do any device initialization here.
3935 * Do it in wireless_core_init() instead.
3936 * This function is for gathering basic information about the HW, only.
3937 * Also some structs may be set up here. But most likely you want to have
3938 * that in core_init(), too.
3941 err
= ssb_bus_powerup(bus
, 0);
3943 b43err(wl
, "Bus powerup failed\n");
3946 /* Get the PHY type. */
3947 if (dev
->dev
->id
.revision
>= 5) {
3950 tmshigh
= ssb_read32(dev
->dev
, SSB_TMSHIGH
);
3951 have_2ghz_phy
= !!(tmshigh
& B43_TMSHIGH_HAVE_2GHZ_PHY
);
3952 have_5ghz_phy
= !!(tmshigh
& B43_TMSHIGH_HAVE_5GHZ_PHY
);
3956 dev
->phy
.gmode
= have_2ghz_phy
;
3957 tmp
= dev
->phy
.gmode
? B43_TMSLOW_GMODE
: 0;
3958 b43_wireless_core_reset(dev
, tmp
);
3960 err
= b43_phy_versioning(dev
);
3963 /* Check if this device supports multiband. */
3965 (pdev
->device
!= 0x4312 &&
3966 pdev
->device
!= 0x4319 && pdev
->device
!= 0x4324)) {
3967 /* No multiband support. */
3970 switch (dev
->phy
.type
) {
3982 if (dev
->phy
.type
== B43_PHYTYPE_A
) {
3984 b43err(wl
, "IEEE 802.11a devices are unsupported\n");
3988 dev
->phy
.gmode
= have_2ghz_phy
;
3989 tmp
= dev
->phy
.gmode
? B43_TMSLOW_GMODE
: 0;
3990 b43_wireless_core_reset(dev
, tmp
);
3992 err
= b43_validate_chipaccess(dev
);
3995 err
= b43_setup_bands(dev
, have_2ghz_phy
, have_5ghz_phy
);
3999 /* Now set some default "current_dev" */
4000 if (!wl
->current_dev
)
4001 wl
->current_dev
= dev
;
4002 INIT_WORK(&dev
->restart_work
, b43_chip_reset
);
4004 b43_radio_turn_off(dev
, 1);
4005 b43_switch_analog(dev
, 0);
4006 ssb_device_disable(dev
->dev
, 0);
4007 ssb_bus_may_powerdown(bus
);
4013 ssb_bus_may_powerdown(bus
);
4017 static void b43_one_core_detach(struct ssb_device
*dev
)
4019 struct b43_wldev
*wldev
;
4022 wldev
= ssb_get_drvdata(dev
);
4024 cancel_work_sync(&wldev
->restart_work
);
4025 b43_debugfs_remove_device(wldev
);
4026 b43_wireless_core_detach(wldev
);
4027 list_del(&wldev
->list
);
4029 ssb_set_drvdata(dev
, NULL
);
4033 static int b43_one_core_attach(struct ssb_device
*dev
, struct b43_wl
*wl
)
4035 struct b43_wldev
*wldev
;
4036 struct pci_dev
*pdev
;
4039 if (!list_empty(&wl
->devlist
)) {
4040 /* We are not the first core on this chip. */
4041 pdev
= dev
->bus
->host_pci
;
4042 /* Only special chips support more than one wireless
4043 * core, although some of the other chips have more than
4044 * one wireless core as well. Check for this and
4048 ((pdev
->device
!= 0x4321) &&
4049 (pdev
->device
!= 0x4313) && (pdev
->device
!= 0x431A))) {
4050 b43dbg(wl
, "Ignoring unconnected 802.11 core\n");
4055 wldev
= kzalloc(sizeof(*wldev
), GFP_KERNEL
);
4061 b43_set_status(wldev
, B43_STAT_UNINIT
);
4062 wldev
->bad_frames_preempt
= modparam_bad_frames_preempt
;
4063 tasklet_init(&wldev
->isr_tasklet
,
4064 (void (*)(unsigned long))b43_interrupt_tasklet
,
4065 (unsigned long)wldev
);
4066 INIT_LIST_HEAD(&wldev
->list
);
4068 err
= b43_wireless_core_attach(wldev
);
4070 goto err_kfree_wldev
;
4072 list_add(&wldev
->list
, &wl
->devlist
);
4074 ssb_set_drvdata(dev
, wldev
);
4075 b43_debugfs_add_device(wldev
);
4085 static void b43_sprom_fixup(struct ssb_bus
*bus
)
4087 /* boardflags workarounds */
4088 if (bus
->boardinfo
.vendor
== SSB_BOARDVENDOR_DELL
&&
4089 bus
->chip_id
== 0x4301 && bus
->boardinfo
.rev
== 0x74)
4090 bus
->sprom
.boardflags_lo
|= B43_BFL_BTCOEXIST
;
4091 if (bus
->boardinfo
.vendor
== PCI_VENDOR_ID_APPLE
&&
4092 bus
->boardinfo
.type
== 0x4E && bus
->boardinfo
.rev
> 0x40)
4093 bus
->sprom
.boardflags_lo
|= B43_BFL_PACTRL
;
4096 static void b43_wireless_exit(struct ssb_device
*dev
, struct b43_wl
*wl
)
4098 struct ieee80211_hw
*hw
= wl
->hw
;
4100 ssb_set_devtypedata(dev
, NULL
);
4101 ieee80211_free_hw(hw
);
4104 static int b43_wireless_init(struct ssb_device
*dev
)
4106 struct ssb_sprom
*sprom
= &dev
->bus
->sprom
;
4107 struct ieee80211_hw
*hw
;
4111 b43_sprom_fixup(dev
->bus
);
4113 hw
= ieee80211_alloc_hw(sizeof(*wl
), &b43_hw_ops
);
4115 b43err(NULL
, "Could not allocate ieee80211 device\n");
4120 hw
->flags
= IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE
|
4121 IEEE80211_HW_RX_INCLUDES_FCS
;
4122 hw
->max_signal
= 100;
4123 hw
->max_rssi
= -110;
4124 hw
->max_noise
= -110;
4125 hw
->queues
= 1; /* FIXME: hardware has more queues */
4126 SET_IEEE80211_DEV(hw
, dev
->dev
);
4127 if (is_valid_ether_addr(sprom
->et1mac
))
4128 SET_IEEE80211_PERM_ADDR(hw
, sprom
->et1mac
);
4130 SET_IEEE80211_PERM_ADDR(hw
, sprom
->il0mac
);
4132 /* Get and initialize struct b43_wl */
4133 wl
= hw_to_b43_wl(hw
);
4134 memset(wl
, 0, sizeof(*wl
));
4136 spin_lock_init(&wl
->irq_lock
);
4137 spin_lock_init(&wl
->leds_lock
);
4138 spin_lock_init(&wl
->shm_lock
);
4139 mutex_init(&wl
->mutex
);
4140 INIT_LIST_HEAD(&wl
->devlist
);
4142 ssb_set_devtypedata(dev
, wl
);
4143 b43info(wl
, "Broadcom %04X WLAN found\n", dev
->bus
->chip_id
);
4149 static int b43_probe(struct ssb_device
*dev
, const struct ssb_device_id
*id
)
4155 wl
= ssb_get_devtypedata(dev
);
4157 /* Probing the first core. Must setup common struct b43_wl */
4159 err
= b43_wireless_init(dev
);
4162 wl
= ssb_get_devtypedata(dev
);
4165 err
= b43_one_core_attach(dev
, wl
);
4167 goto err_wireless_exit
;
4170 err
= ieee80211_register_hw(wl
->hw
);
4172 goto err_one_core_detach
;
4178 err_one_core_detach
:
4179 b43_one_core_detach(dev
);
4182 b43_wireless_exit(dev
, wl
);
4186 static void b43_remove(struct ssb_device
*dev
)
4188 struct b43_wl
*wl
= ssb_get_devtypedata(dev
);
4189 struct b43_wldev
*wldev
= ssb_get_drvdata(dev
);
4192 if (wl
->current_dev
== wldev
)
4193 ieee80211_unregister_hw(wl
->hw
);
4195 b43_one_core_detach(dev
);
4197 if (list_empty(&wl
->devlist
)) {
4198 /* Last core on the chip unregistered.
4199 * We can destroy common struct b43_wl.
4201 b43_wireless_exit(dev
, wl
);
4205 /* Perform a hardware reset. This can be called from any context. */
4206 void b43_controller_restart(struct b43_wldev
*dev
, const char *reason
)
4208 /* Must avoid requeueing, if we are in shutdown. */
4209 if (b43_status(dev
) < B43_STAT_INITIALIZED
)
4211 b43info(dev
->wl
, "Controller RESET (%s) ...\n", reason
);
4212 queue_work(dev
->wl
->hw
->workqueue
, &dev
->restart_work
);
4217 static int b43_suspend(struct ssb_device
*dev
, pm_message_t state
)
4219 struct b43_wldev
*wldev
= ssb_get_drvdata(dev
);
4220 struct b43_wl
*wl
= wldev
->wl
;
4222 b43dbg(wl
, "Suspending...\n");
4224 mutex_lock(&wl
->mutex
);
4225 wldev
->suspend_in_progress
= true;
4226 wldev
->suspend_init_status
= b43_status(wldev
);
4227 if (wldev
->suspend_init_status
>= B43_STAT_STARTED
)
4228 b43_wireless_core_stop(wldev
);
4229 if (wldev
->suspend_init_status
>= B43_STAT_INITIALIZED
)
4230 b43_wireless_core_exit(wldev
);
4231 mutex_unlock(&wl
->mutex
);
4233 b43dbg(wl
, "Device suspended.\n");
4238 static int b43_resume(struct ssb_device
*dev
)
4240 struct b43_wldev
*wldev
= ssb_get_drvdata(dev
);
4241 struct b43_wl
*wl
= wldev
->wl
;
4244 b43dbg(wl
, "Resuming...\n");
4246 mutex_lock(&wl
->mutex
);
4247 if (wldev
->suspend_init_status
>= B43_STAT_INITIALIZED
) {
4248 err
= b43_wireless_core_init(wldev
);
4250 b43err(wl
, "Resume failed at core init\n");
4254 if (wldev
->suspend_init_status
>= B43_STAT_STARTED
) {
4255 err
= b43_wireless_core_start(wldev
);
4257 b43_leds_exit(wldev
);
4258 b43_rng_exit(wldev
->wl
, true);
4259 b43_wireless_core_exit(wldev
);
4260 b43err(wl
, "Resume failed at core start\n");
4264 b43dbg(wl
, "Device resumed.\n");
4266 wldev
->suspend_in_progress
= false;
4267 mutex_unlock(&wl
->mutex
);
4271 #else /* CONFIG_PM */
4272 # define b43_suspend NULL
4273 # define b43_resume NULL
4274 #endif /* CONFIG_PM */
4276 static struct ssb_driver b43_ssb_driver
= {
4277 .name
= KBUILD_MODNAME
,
4278 .id_table
= b43_ssb_tbl
,
4280 .remove
= b43_remove
,
4281 .suspend
= b43_suspend
,
4282 .resume
= b43_resume
,
4285 static void b43_print_driverinfo(void)
4287 const char *feat_pci
= "", *feat_pcmcia
= "", *feat_nphy
= "",
4288 *feat_leds
= "", *feat_rfkill
= "";
4290 #ifdef CONFIG_B43_PCI_AUTOSELECT
4293 #ifdef CONFIG_B43_PCMCIA
4296 #ifdef CONFIG_B43_NPHY
4299 #ifdef CONFIG_B43_LEDS
4302 #ifdef CONFIG_B43_RFKILL
4305 printk(KERN_INFO
"Broadcom 43xx driver loaded "
4306 "[ Features: %s%s%s%s%s, Firmware-ID: "
4307 B43_SUPPORTED_FIRMWARE_ID
" ]\n",
4308 feat_pci
, feat_pcmcia
, feat_nphy
,
4309 feat_leds
, feat_rfkill
);
4312 static int __init
b43_init(void)
4317 err
= b43_pcmcia_init();
4320 err
= ssb_driver_register(&b43_ssb_driver
);
4322 goto err_pcmcia_exit
;
4323 b43_print_driverinfo();
4334 static void __exit
b43_exit(void)
4336 ssb_driver_unregister(&b43_ssb_driver
);
4341 module_init(b43_init
)
4342 module_exit(b43_exit
)