blob: 21c75cae14bf1e86d9a0999aa00f1704a50e6425 [file] [log] [blame]
John W. Linvillef2223132006-01-23 16:59:58 -05001#ifndef BCM43xx_H_
2#define BCM43xx_H_
3
4#include <linux/version.h>
5#include <linux/kernel.h>
6#include <linux/spinlock.h>
7#include <linux/interrupt.h>
8#include <linux/stringify.h>
9#include <linux/pci.h>
10#include <net/ieee80211.h>
11#include <net/ieee80211softmac.h>
12#include <asm/atomic.h>
13#include <asm/io.h>
14
15
16#include "bcm43xx_debugfs.h"
17#include "bcm43xx_leds.h"
18
19
Michael Buesch65f3f192006-01-31 20:11:38 +010020#define PFX KBUILD_MODNAME ": "
John W. Linvillef2223132006-01-23 16:59:58 -050021
Michael Buesch489423c2006-02-13 00:11:07 +010022#define BCM43xx_SWITCH_CORE_MAX_RETRIES 50
John W. Linvillef2223132006-01-23 16:59:58 -050023#define BCM43xx_IRQWAIT_MAX_RETRIES 50
John W. Linvillef2223132006-01-23 16:59:58 -050024
25#define BCM43xx_IO_SIZE 8192
John W. Linvillef2223132006-01-23 16:59:58 -050026
Michael Buesch489423c2006-02-13 00:11:07 +010027/* Active Core PCI Configuration Register. */
28#define BCM43xx_PCICFG_ACTIVE_CORE 0x80
John W. Linvillef2223132006-01-23 16:59:58 -050029/* SPROM control register. */
30#define BCM43xx_PCICFG_SPROMCTL 0x88
Michael Buesch489423c2006-02-13 00:11:07 +010031/* Interrupt Control PCI Configuration Register. (Only on PCI cores with rev >= 6) */
32#define BCM43xx_PCICFG_ICR 0x94
John W. Linvillef2223132006-01-23 16:59:58 -050033
34/* MMIO offsets */
35#define BCM43xx_MMIO_DMA1_REASON 0x20
36#define BCM43xx_MMIO_DMA1_IRQ_MASK 0x24
37#define BCM43xx_MMIO_DMA2_REASON 0x28
38#define BCM43xx_MMIO_DMA2_IRQ_MASK 0x2C
39#define BCM43xx_MMIO_DMA3_REASON 0x30
40#define BCM43xx_MMIO_DMA3_IRQ_MASK 0x34
41#define BCM43xx_MMIO_DMA4_REASON 0x38
42#define BCM43xx_MMIO_DMA4_IRQ_MASK 0x3C
43#define BCM43xx_MMIO_STATUS_BITFIELD 0x120
44#define BCM43xx_MMIO_STATUS2_BITFIELD 0x124
45#define BCM43xx_MMIO_GEN_IRQ_REASON 0x128
46#define BCM43xx_MMIO_GEN_IRQ_MASK 0x12C
47#define BCM43xx_MMIO_RAM_CONTROL 0x130
48#define BCM43xx_MMIO_RAM_DATA 0x134
49#define BCM43xx_MMIO_PS_STATUS 0x140
50#define BCM43xx_MMIO_RADIO_HWENABLED_HI 0x158
51#define BCM43xx_MMIO_SHM_CONTROL 0x160
52#define BCM43xx_MMIO_SHM_DATA 0x164
53#define BCM43xx_MMIO_SHM_DATA_UNALIGNED 0x166
54#define BCM43xx_MMIO_XMITSTAT_0 0x170
55#define BCM43xx_MMIO_XMITSTAT_1 0x174
56#define BCM43xx_MMIO_REV3PLUS_TSF_LOW 0x180 /* core rev >= 3 only */
57#define BCM43xx_MMIO_REV3PLUS_TSF_HIGH 0x184 /* core rev >= 3 only */
58#define BCM43xx_MMIO_DMA1_BASE 0x200
59#define BCM43xx_MMIO_DMA2_BASE 0x220
60#define BCM43xx_MMIO_DMA3_BASE 0x240
61#define BCM43xx_MMIO_DMA4_BASE 0x260
62#define BCM43xx_MMIO_PIO1_BASE 0x300
63#define BCM43xx_MMIO_PIO2_BASE 0x310
64#define BCM43xx_MMIO_PIO3_BASE 0x320
65#define BCM43xx_MMIO_PIO4_BASE 0x330
66#define BCM43xx_MMIO_PHY_VER 0x3E0
67#define BCM43xx_MMIO_PHY_RADIO 0x3E2
68#define BCM43xx_MMIO_ANTENNA 0x3E8
69#define BCM43xx_MMIO_CHANNEL 0x3F0
70#define BCM43xx_MMIO_CHANNEL_EXT 0x3F4
71#define BCM43xx_MMIO_RADIO_CONTROL 0x3F6
72#define BCM43xx_MMIO_RADIO_DATA_HIGH 0x3F8
73#define BCM43xx_MMIO_RADIO_DATA_LOW 0x3FA
74#define BCM43xx_MMIO_PHY_CONTROL 0x3FC
75#define BCM43xx_MMIO_PHY_DATA 0x3FE
76#define BCM43xx_MMIO_MACFILTER_CONTROL 0x420
77#define BCM43xx_MMIO_MACFILTER_DATA 0x422
78#define BCM43xx_MMIO_RADIO_HWENABLED_LO 0x49A
79#define BCM43xx_MMIO_GPIO_CONTROL 0x49C
80#define BCM43xx_MMIO_GPIO_MASK 0x49E
81#define BCM43xx_MMIO_TSF_0 0x632 /* core rev < 3 only */
82#define BCM43xx_MMIO_TSF_1 0x634 /* core rev < 3 only */
83#define BCM43xx_MMIO_TSF_2 0x636 /* core rev < 3 only */
84#define BCM43xx_MMIO_TSF_3 0x638 /* core rev < 3 only */
85#define BCM43xx_MMIO_POWERUP_DELAY 0x6A8
86
87/* SPROM offsets. */
88#define BCM43xx_SPROM_BASE 0x1000
89#define BCM43xx_SPROM_BOARDFLAGS2 0x1c
90#define BCM43xx_SPROM_IL0MACADDR 0x24
91#define BCM43xx_SPROM_ET0MACADDR 0x27
92#define BCM43xx_SPROM_ET1MACADDR 0x2a
93#define BCM43xx_SPROM_ETHPHY 0x2d
94#define BCM43xx_SPROM_BOARDREV 0x2e
95#define BCM43xx_SPROM_PA0B0 0x2f
96#define BCM43xx_SPROM_PA0B1 0x30
97#define BCM43xx_SPROM_PA0B2 0x31
98#define BCM43xx_SPROM_WL0GPIO0 0x32
99#define BCM43xx_SPROM_WL0GPIO2 0x33
100#define BCM43xx_SPROM_MAXPWR 0x34
101#define BCM43xx_SPROM_PA1B0 0x35
102#define BCM43xx_SPROM_PA1B1 0x36
103#define BCM43xx_SPROM_PA1B2 0x37
104#define BCM43xx_SPROM_IDL_TSSI_TGT 0x38
105#define BCM43xx_SPROM_BOARDFLAGS 0x39
106#define BCM43xx_SPROM_ANTENNA_GAIN 0x3a
107#define BCM43xx_SPROM_VERSION 0x3f
108
109/* BCM43xx_SPROM_BOARDFLAGS values */
110#define BCM43xx_BFL_BTCOEXIST 0x0001 /* implements Bluetooth coexistance */
111#define BCM43xx_BFL_PACTRL 0x0002 /* GPIO 9 controlling the PA */
112#define BCM43xx_BFL_AIRLINEMODE 0x0004 /* implements GPIO 13 radio disable indication */
113#define BCM43xx_BFL_RSSI 0x0008 /* software calculates nrssi slope. */
114#define BCM43xx_BFL_ENETSPI 0x0010 /* has ephy roboswitch spi */
115#define BCM43xx_BFL_XTAL_NOSLOW 0x0020 /* no slow clock available */
116#define BCM43xx_BFL_CCKHIPWR 0x0040 /* can do high power CCK transmission */
117#define BCM43xx_BFL_ENETADM 0x0080 /* has ADMtek switch */
118#define BCM43xx_BFL_ENETVLAN 0x0100 /* can do vlan */
119#define BCM43xx_BFL_AFTERBURNER 0x0200 /* supports Afterburner mode */
120#define BCM43xx_BFL_NOPCI 0x0400 /* leaves PCI floating */
121#define BCM43xx_BFL_FEM 0x0800 /* supports the Front End Module */
122
123/* GPIO register offset, in both ChipCommon and PCI core. */
124#define BCM43xx_GPIO_CONTROL 0x6c
125
126/* SHM Routing */
127#define BCM43xx_SHM_SHARED 0x0001
128#define BCM43xx_SHM_WIRELESS 0x0002
129#define BCM43xx_SHM_PCM 0x0003
130#define BCM43xx_SHM_HWMAC 0x0004
131#define BCM43xx_SHM_UCODE 0x0300
132
133/* MacFilter offsets. */
134#define BCM43xx_MACFILTER_SELF 0x0000
135#define BCM43xx_MACFILTER_ASSOC 0x0003
136
137/* Chipcommon registers. */
138#define BCM43xx_CHIPCOMMON_CAPABILITIES 0x04
139#define BCM43xx_CHIPCOMMON_PLLONDELAY 0xB0
140#define BCM43xx_CHIPCOMMON_FREFSELDELAY 0xB4
141#define BCM43xx_CHIPCOMMON_SLOWCLKCTL 0xB8
142#define BCM43xx_CHIPCOMMON_SYSCLKCTL 0xC0
143
144/* PCI core specific registers. */
145#define BCM43xx_PCICORE_BCAST_ADDR 0x50
146#define BCM43xx_PCICORE_BCAST_DATA 0x54
147#define BCM43xx_PCICORE_SBTOPCI2 0x108
148
149/* SBTOPCI2 values. */
150#define BCM43xx_SBTOPCI2_PREFETCH 0x4
151#define BCM43xx_SBTOPCI2_BURST 0x8
152
153/* Chipcommon capabilities. */
154#define BCM43xx_CAPABILITIES_PCTL 0x00040000
155#define BCM43xx_CAPABILITIES_PLLMASK 0x00030000
156#define BCM43xx_CAPABILITIES_PLLSHIFT 16
157#define BCM43xx_CAPABILITIES_FLASHMASK 0x00000700
158#define BCM43xx_CAPABILITIES_FLASHSHIFT 8
159#define BCM43xx_CAPABILITIES_EXTBUSPRESENT 0x00000040
160#define BCM43xx_CAPABILITIES_UARTGPIO 0x00000020
161#define BCM43xx_CAPABILITIES_UARTCLOCKMASK 0x00000018
162#define BCM43xx_CAPABILITIES_UARTCLOCKSHIFT 3
163#define BCM43xx_CAPABILITIES_MIPSBIGENDIAN 0x00000004
164#define BCM43xx_CAPABILITIES_NRUARTSMASK 0x00000003
165
166/* PowerControl */
167#define BCM43xx_PCTL_IN 0xB0
168#define BCM43xx_PCTL_OUT 0xB4
169#define BCM43xx_PCTL_OUTENABLE 0xB8
170#define BCM43xx_PCTL_XTAL_POWERUP 0x40
171#define BCM43xx_PCTL_PLL_POWERDOWN 0x80
172
173/* PowerControl Clock Modes */
174#define BCM43xx_PCTL_CLK_FAST 0x00
175#define BCM43xx_PCTL_CLK_SLOW 0x01
176#define BCM43xx_PCTL_CLK_DYNAMIC 0x02
177
178#define BCM43xx_PCTL_FORCE_SLOW 0x0800
179#define BCM43xx_PCTL_FORCE_PLL 0x1000
180#define BCM43xx_PCTL_DYN_XTAL 0x2000
181
182/* COREIDs */
183#define BCM43xx_COREID_CHIPCOMMON 0x800
184#define BCM43xx_COREID_ILINE20 0x801
185#define BCM43xx_COREID_SDRAM 0x803
186#define BCM43xx_COREID_PCI 0x804
187#define BCM43xx_COREID_MIPS 0x805
188#define BCM43xx_COREID_ETHERNET 0x806
189#define BCM43xx_COREID_V90 0x807
190#define BCM43xx_COREID_USB11_HOSTDEV 0x80a
191#define BCM43xx_COREID_IPSEC 0x80b
192#define BCM43xx_COREID_PCMCIA 0x80d
193#define BCM43xx_COREID_EXT_IF 0x80f
194#define BCM43xx_COREID_80211 0x812
195#define BCM43xx_COREID_MIPS_3302 0x816
196#define BCM43xx_COREID_USB11_HOST 0x817
197#define BCM43xx_COREID_USB11_DEV 0x818
198#define BCM43xx_COREID_USB20_HOST 0x819
199#define BCM43xx_COREID_USB20_DEV 0x81a
200#define BCM43xx_COREID_SDIO_HOST 0x81b
201
202/* Core Information Registers */
203#define BCM43xx_CIR_BASE 0xf00
204#define BCM43xx_CIR_SBTPSFLAG (BCM43xx_CIR_BASE + 0x18)
205#define BCM43xx_CIR_SBIMSTATE (BCM43xx_CIR_BASE + 0x90)
206#define BCM43xx_CIR_SBINTVEC (BCM43xx_CIR_BASE + 0x94)
207#define BCM43xx_CIR_SBTMSTATELOW (BCM43xx_CIR_BASE + 0x98)
208#define BCM43xx_CIR_SBTMSTATEHIGH (BCM43xx_CIR_BASE + 0x9c)
209#define BCM43xx_CIR_SBIMCONFIGLOW (BCM43xx_CIR_BASE + 0xa8)
210#define BCM43xx_CIR_SB_ID_HI (BCM43xx_CIR_BASE + 0xfc)
211
212/* Mask to get the Backplane Flag Number from SBTPSFLAG. */
213#define BCM43xx_BACKPLANE_FLAG_NR_MASK 0x3f
214
215/* SBIMCONFIGLOW values/masks. */
216#define BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_MASK 0x00000007
217#define BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_SHIFT 0
218#define BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_MASK 0x00000070
219#define BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_SHIFT 4
220#define BCM43xx_SBIMCONFIGLOW_CONNID_MASK 0x00ff0000
221#define BCM43xx_SBIMCONFIGLOW_CONNID_SHIFT 16
222
223/* sbtmstatelow state flags */
224#define BCM43xx_SBTMSTATELOW_RESET 0x01
225#define BCM43xx_SBTMSTATELOW_REJECT 0x02
226#define BCM43xx_SBTMSTATELOW_CLOCK 0x10000
227#define BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK 0x20000
228
229/* sbtmstatehigh state flags */
230#define BCM43xx_SBTMSTATEHIGH_SERROR 0x1
231#define BCM43xx_SBTMSTATEHIGH_BUSY 0x4
232
233/* sbimstate flags */
234#define BCM43xx_SBIMSTATE_IB_ERROR 0x20000
235#define BCM43xx_SBIMSTATE_TIMEOUT 0x40000
236
237/* PHYVersioning */
238#define BCM43xx_PHYTYPE_A 0x00
239#define BCM43xx_PHYTYPE_B 0x01
240#define BCM43xx_PHYTYPE_G 0x02
241
242/* PHYRegisters */
243#define BCM43xx_PHY_ILT_A_CTRL 0x0072
244#define BCM43xx_PHY_ILT_A_DATA1 0x0073
245#define BCM43xx_PHY_ILT_A_DATA2 0x0074
246#define BCM43xx_PHY_G_LO_CONTROL 0x0810
247#define BCM43xx_PHY_ILT_G_CTRL 0x0472
248#define BCM43xx_PHY_ILT_G_DATA1 0x0473
249#define BCM43xx_PHY_ILT_G_DATA2 0x0474
250#define BCM43xx_PHY_A_PCTL 0x007B
251#define BCM43xx_PHY_G_PCTL 0x0029
252#define BCM43xx_PHY_A_CRS 0x0029
253#define BCM43xx_PHY_RADIO_BITFIELD 0x0401
254#define BCM43xx_PHY_G_CRS 0x0429
255#define BCM43xx_PHY_NRSSILT_CTRL 0x0803
256#define BCM43xx_PHY_NRSSILT_DATA 0x0804
257
258/* RadioRegisters */
259#define BCM43xx_RADIOCTL_ID 0x01
260
261/* StatusBitField */
262#define BCM43xx_SBF_MAC_ENABLED 0x00000001
263#define BCM43xx_SBF_2 0x00000002 /*FIXME: fix name*/
264#define BCM43xx_SBF_CORE_READY 0x00000004
265#define BCM43xx_SBF_400 0x00000400 /*FIXME: fix name*/
266#define BCM43xx_SBF_4000 0x00004000 /*FIXME: fix name*/
267#define BCM43xx_SBF_8000 0x00008000 /*FIXME: fix name*/
268#define BCM43xx_SBF_XFER_REG_BYTESWAP 0x00010000
269#define BCM43xx_SBF_MODE_NOTADHOC 0x00020000
270#define BCM43xx_SBF_MODE_AP 0x00040000
271#define BCM43xx_SBF_RADIOREG_LOCK 0x00080000
272#define BCM43xx_SBF_MODE_MONITOR 0x00400000
273#define BCM43xx_SBF_MODE_PROMISC 0x01000000
274#define BCM43xx_SBF_PS1 0x02000000
275#define BCM43xx_SBF_PS2 0x04000000
276#define BCM43xx_SBF_NO_SSID_BCAST 0x08000000
277#define BCM43xx_SBF_TIME_UPDATE 0x10000000
278#define BCM43xx_SBF_80000000 0x80000000 /*FIXME: fix name*/
279
280/* MicrocodeFlagsBitfield (addr + lo-word values?)*/
281#define BCM43xx_UCODEFLAGS_OFFSET 0x005E
282
283#define BCM43xx_UCODEFLAG_AUTODIV 0x0001
284#define BCM43xx_UCODEFLAG_UNKBGPHY 0x0002
285#define BCM43xx_UCODEFLAG_UNKBPHY 0x0004
286#define BCM43xx_UCODEFLAG_UNKGPHY 0x0020
287#define BCM43xx_UCODEFLAG_UNKPACTRL 0x0040
288#define BCM43xx_UCODEFLAG_JAPAN 0x0080
289
290/* Generic-Interrupt reasons. */
291#define BCM43xx_IRQ_READY (1 << 0)
292#define BCM43xx_IRQ_BEACON (1 << 1)
293#define BCM43xx_IRQ_PS (1 << 2)
294#define BCM43xx_IRQ_REG124 (1 << 5)
295#define BCM43xx_IRQ_PMQ (1 << 6)
296#define BCM43xx_IRQ_PIO_WORKAROUND (1 << 8)
297#define BCM43xx_IRQ_XMIT_ERROR (1 << 11)
298#define BCM43xx_IRQ_RX (1 << 15)
299#define BCM43xx_IRQ_SCAN (1 << 16)
300#define BCM43xx_IRQ_NOISE (1 << 18)
301#define BCM43xx_IRQ_XMIT_STATUS (1 << 29)
302
303#define BCM43xx_IRQ_ALL 0xffffffff
304#define BCM43xx_IRQ_INITIAL (BCM43xx_IRQ_PS | \
305 BCM43xx_IRQ_REG124 | \
306 BCM43xx_IRQ_PMQ | \
307 BCM43xx_IRQ_XMIT_ERROR | \
308 BCM43xx_IRQ_RX | \
309 BCM43xx_IRQ_SCAN | \
310 BCM43xx_IRQ_NOISE | \
311 BCM43xx_IRQ_XMIT_STATUS)
312
313
314/* Initial default iw_mode */
315#define BCM43xx_INITIAL_IWMODE IW_MODE_INFRA
316
John W. Linvillef2223132006-01-23 16:59:58 -0500317/* Bus type PCI. */
318#define BCM43xx_BUSTYPE_PCI 0
319/* Bus type Silicone Backplane Bus. */
320#define BCM43xx_BUSTYPE_SB 1
321/* Bus type PCMCIA. */
322#define BCM43xx_BUSTYPE_PCMCIA 2
323
324/* Threshold values. */
325#define BCM43xx_MIN_RTS_THRESHOLD 1U
326#define BCM43xx_MAX_RTS_THRESHOLD 2304U
327#define BCM43xx_DEFAULT_RTS_THRESHOLD BCM43xx_MAX_RTS_THRESHOLD
328
329#define BCM43xx_DEFAULT_SHORT_RETRY_LIMIT 7
330#define BCM43xx_DEFAULT_LONG_RETRY_LIMIT 4
331
332/* Max size of a security key */
333#define BCM43xx_SEC_KEYSIZE 16
334/* Security algorithms. */
335enum {
336 BCM43xx_SEC_ALGO_NONE = 0, /* unencrypted, as of TX header. */
337 BCM43xx_SEC_ALGO_WEP,
338 BCM43xx_SEC_ALGO_UNKNOWN,
339 BCM43xx_SEC_ALGO_AES,
340 BCM43xx_SEC_ALGO_WEP104,
341 BCM43xx_SEC_ALGO_TKIP,
342};
343
344#ifdef assert
345# undef assert
346#endif
347#ifdef CONFIG_BCM43XX_DEBUG
348#define assert(expr) \
349 do { \
350 if (unlikely(!(expr))) { \
351 printk(KERN_ERR PFX "ASSERTION FAILED (%s) at: %s:%d:%s()\n", \
352 #expr, __FILE__, __LINE__, __FUNCTION__); \
353 } \
354 } while (0)
355#else
356#define assert(expr) do { /* nothing */ } while (0)
357#endif
358
359/* rate limited printk(). */
360#ifdef printkl
361# undef printkl
362#endif
363#define printkl(f, x...) do { if (printk_ratelimit()) printk(f ,##x); } while (0)
364/* rate limited printk() for debugging */
365#ifdef dprintkl
366# undef dprintkl
367#endif
368#ifdef CONFIG_BCM43XX_DEBUG
369# define dprintkl printkl
370#else
371# define dprintkl(f, x...) do { /* nothing */ } while (0)
372#endif
373
374/* Helper macro for if branches.
375 * An if branch marked with this macro is only taken in DEBUG mode.
376 * Example:
377 * if (DEBUG_ONLY(foo == bar)) {
378 * do something
379 * }
380 * In DEBUG mode, the branch will be taken if (foo == bar).
381 * In non-DEBUG mode, the branch will never be taken.
382 */
383#ifdef DEBUG_ONLY
384# undef DEBUG_ONLY
385#endif
386#ifdef CONFIG_BCM43XX_DEBUG
387# define DEBUG_ONLY(x) (x)
388#else
389# define DEBUG_ONLY(x) 0
390#endif
391
392/* debugging printk() */
393#ifdef dprintk
394# undef dprintk
395#endif
396#ifdef CONFIG_BCM43XX_DEBUG
397# define dprintk(f, x...) do { printk(f ,##x); } while (0)
398#else
399# define dprintk(f, x...) do { /* nothing */ } while (0)
400#endif
401
402
403struct net_device;
404struct pci_dev;
John W. Linvillef2223132006-01-23 16:59:58 -0500405struct bcm43xx_dmaring;
406struct bcm43xx_pioqueue;
407
408struct bcm43xx_initval {
409 u16 offset;
410 u16 size;
411 u32 value;
412} __attribute__((__packed__));
413
414/* Values for bcm430x_sprominfo.locale */
415enum {
416 BCM43xx_LOCALE_WORLD = 0,
417 BCM43xx_LOCALE_THAILAND,
418 BCM43xx_LOCALE_ISRAEL,
419 BCM43xx_LOCALE_JORDAN,
420 BCM43xx_LOCALE_CHINA,
421 BCM43xx_LOCALE_JAPAN,
422 BCM43xx_LOCALE_USA_CANADA_ANZ,
423 BCM43xx_LOCALE_EUROPE,
424 BCM43xx_LOCALE_USA_LOW,
425 BCM43xx_LOCALE_JAPAN_HIGH,
426 BCM43xx_LOCALE_ALL,
427 BCM43xx_LOCALE_NONE,
428};
429
430#define BCM43xx_SPROM_SIZE 64 /* in 16-bit words. */
431struct bcm43xx_sprominfo {
432 u16 boardflags2;
433 u8 il0macaddr[6];
434 u8 et0macaddr[6];
435 u8 et1macaddr[6];
436 u8 et0phyaddr:5;
437 u8 et1phyaddr:5;
438 u8 et0mdcport:1;
439 u8 et1mdcport:1;
440 u8 boardrev;
441 u8 locale:4;
442 u8 antennas_aphy:2;
443 u8 antennas_bgphy:2;
444 u16 pa0b0;
445 u16 pa0b1;
446 u16 pa0b2;
447 u8 wl0gpio0;
448 u8 wl0gpio1;
449 u8 wl0gpio2;
450 u8 wl0gpio3;
451 u8 maxpower_aphy;
452 u8 maxpower_bgphy;
453 u16 pa1b0;
454 u16 pa1b1;
455 u16 pa1b2;
456 u8 idle_tssi_tgt_aphy;
457 u8 idle_tssi_tgt_bgphy;
458 u16 boardflags;
459 u16 antennagain_aphy;
460 u16 antennagain_bgphy;
461};
462
463/* Value pair to measure the LocalOscillator. */
464struct bcm43xx_lopair {
465 s8 low;
466 s8 high;
467 u8 used:1;
468};
469#define BCM43xx_LO_COUNT (14*4)
470
471struct bcm43xx_phyinfo {
472 /* Hardware Data */
473 u8 version;
474 u8 type;
475 u8 rev;
476 u16 antenna_diversity;
477 u16 savedpctlreg;
478 u16 minlowsig[2];
479 u16 minlowsigpos[2];
480 u8 connected:1,
481 calibrated:1,
482 is_locked:1, /* used in bcm43xx_phy_{un}lock() */
483 dyn_tssi_tbl:1; /* used in bcm43xx_phy_init_tssi2dbm_table() */
484 /* LO Measurement Data.
485 * Use bcm43xx_get_lopair() to get a value.
486 */
487 struct bcm43xx_lopair *_lo_pairs;
488
489 /* TSSI to dBm table in use */
490 const s8 *tssi2dbm;
491 /* idle TSSI value */
492 s8 idle_tssi;
493 /* PHY lock for core.rev < 3
494 * This lock is only used by bcm43xx_phy_{un}lock()
495 */
496 spinlock_t lock;
497};
498
499
500struct bcm43xx_radioinfo {
501 u16 manufact;
502 u16 version;
503 u8 revision;
504
505 /* 0: baseband attenuation,
506 * 1: radio attenuation,
507 * 2: tx_CTL1
508 * 3: tx_CTL2
509 */
510 u16 txpower[4];
Michael Buesch393344f2006-02-05 15:28:20 +0100511 /* Desired TX power in dBm Q5.2 */
512 u16 txpower_desired;
John W. Linvillef2223132006-01-23 16:59:58 -0500513 /* Current Interference Mitigation mode */
514 int interfmode;
515 /* Stack of saved values from the Interference Mitigation code */
516 u16 interfstack[20];
517 /* Saved values from the NRSSI Slope calculation */
518 s16 nrssi[2];
519 s32 nrssislope;
520 /* In memory nrssi lookup table. */
521 s8 nrssi_lt[64];
522
523 /* current channel */
524 u8 channel;
525 u8 initial_channel;
526
527 u16 lofcal;
528
529 u16 initval;
530
531 u8 enabled:1;
532 /* ACI (adjacent channel interference) flags. */
533 u8 aci_enable:1,
534 aci_wlan_automatic:1,
535 aci_hw_rssi:1;
536};
537
538/* Data structures for DMA transmission, per 80211 core. */
539struct bcm43xx_dma {
540 struct bcm43xx_dmaring *tx_ring0;
541 struct bcm43xx_dmaring *tx_ring1;
542 struct bcm43xx_dmaring *tx_ring2;
543 struct bcm43xx_dmaring *tx_ring3;
544 struct bcm43xx_dmaring *rx_ring0;
545 struct bcm43xx_dmaring *rx_ring1; /* only available on core.rev < 5 */
546};
547
548/* Data structures for PIO transmission, per 80211 core. */
549struct bcm43xx_pio {
550 struct bcm43xx_pioqueue *queue0;
551 struct bcm43xx_pioqueue *queue1;
552 struct bcm43xx_pioqueue *queue2;
553 struct bcm43xx_pioqueue *queue3;
554};
555
556#define BCM43xx_MAX_80211_CORES 2
557
558#define BCM43xx_COREFLAG_AVAILABLE (1 << 0)
559#define BCM43xx_COREFLAG_ENABLED (1 << 1)
560#define BCM43xx_COREFLAG_INITIALIZED (1 << 2)
561
562#ifdef CONFIG_BCM947XX
563#define core_offset(bcm) (bcm)->current_core_offset
564#else
565#define core_offset(bcm) 0
566#endif
567
568struct bcm43xx_coreinfo {
569 /** Driver internal flags. See BCM43xx_COREFLAG_* */
570 u32 flags;
571 /** core_id ID number */
572 u16 id;
573 /** core_rev revision number */
574 u8 rev;
575 /** Index number for _switch_core() */
576 u8 index;
577 /* Pointer to the PHYinfo, which belongs to this core (if 80211 core) */
578 struct bcm43xx_phyinfo *phy;
579 /* Pointer to the RadioInfo, which belongs to this core (if 80211 core) */
580 struct bcm43xx_radioinfo *radio;
581 /* Pointer to the DMA rings, which belong to this core (if 80211 core) */
582 struct bcm43xx_dma *dma;
583 /* Pointer to the PIO queues, which belong to this core (if 80211 core) */
584 struct bcm43xx_pio *pio;
585};
586
587/* Context information for a noise calculation (Link Quality). */
588struct bcm43xx_noise_calculation {
589 struct bcm43xx_coreinfo *core_at_start;
590 u8 channel_at_start;
591 u8 calculation_running:1;
592 u8 nr_samples;
593 s8 samples[8][4];
594};
595
596struct bcm43xx_stats {
597 u8 link_quality;
598 /* Store the last TX/RX times here for updating the leds. */
599 unsigned long last_tx;
600 unsigned long last_rx;
601};
602
603struct bcm43xx_key {
604 u8 enabled:1;
605 u8 algorithm;
606};
607
608struct bcm43xx_private {
609 struct ieee80211_device *ieee;
610 struct ieee80211softmac_device *softmac;
611
612 struct net_device *net_dev;
613 struct pci_dev *pci_dev;
614 unsigned int irq;
615
616 void __iomem *mmio_addr;
617 unsigned int mmio_len;
618
619 spinlock_t lock;
620
621 /* Driver status flags. */
622 u32 initialized:1, /* init_board() succeed */
623 was_initialized:1, /* for PCI suspend/resume. */
624 shutting_down:1, /* free_board() in progress */
Michael Buesch77db31e2006-02-12 16:47:44 +0100625 __using_pio:1, /* Internal, use bcm43xx_using_pio(). */
John W. Linvillef2223132006-01-23 16:59:58 -0500626 bad_frames_preempt:1, /* Use "Bad Frames Preemption" (default off) */
627 reg124_set_0x4:1, /* Some variable to keep track of IRQ stuff. */
628 powersaving:1, /* TRUE if we are in PowerSaving mode. FALSE otherwise. */
629 short_preamble:1, /* TRUE, if short preamble is enabled. */
630 firmware_norelease:1; /* Do not release the firmware. Used on suspend. */
631
632 struct bcm43xx_stats stats;
633
634 /* Bus type we are connected to.
635 * This is currently always BCM43xx_BUSTYPE_PCI
636 */
637 u8 bustype;
638
639 u16 board_vendor;
640 u16 board_type;
641 u16 board_revision;
642
643 u16 chip_id;
644 u8 chip_rev;
645
646 struct bcm43xx_sprominfo sprom;
647#define BCM43xx_NR_LEDS 4
648 struct bcm43xx_led leds[BCM43xx_NR_LEDS];
649
650 /* The currently active core. NULL if not initialized, yet. */
651 struct bcm43xx_coreinfo *current_core;
652#ifdef CONFIG_BCM947XX
653 /** current core memory offset */
654 u32 current_core_offset;
655#endif
656 struct bcm43xx_coreinfo *active_80211_core;
657 /* coreinfo structs for all possible cores follow.
658 * Note that a core might not exist.
659 * So check the coreinfo flags before using it.
660 */
661 struct bcm43xx_coreinfo core_chipcommon;
662 struct bcm43xx_coreinfo core_pci;
663 struct bcm43xx_coreinfo core_v90;
664 struct bcm43xx_coreinfo core_pcmcia;
665 struct bcm43xx_coreinfo core_ethernet;
666 struct bcm43xx_coreinfo core_80211[ BCM43xx_MAX_80211_CORES ];
667 /* Info about the PHY for each 80211 core. */
668 struct bcm43xx_phyinfo phy[ BCM43xx_MAX_80211_CORES ];
669 /* Info about the Radio for each 80211 core. */
670 struct bcm43xx_radioinfo radio[ BCM43xx_MAX_80211_CORES ];
671 /* DMA */
672 struct bcm43xx_dma dma[ BCM43xx_MAX_80211_CORES ];
673 /* PIO */
674 struct bcm43xx_pio pio[ BCM43xx_MAX_80211_CORES ];
675
676 u32 chipcommon_capabilities;
677
678 /* Reason code of the last interrupt. */
679 u32 irq_reason;
680 u32 dma_reason[4];
681 /* saved irq enable/disable state bitfield. */
682 u32 irq_savedstate;
683 /* Link Quality calculation context. */
684 struct bcm43xx_noise_calculation noisecalc;
685
686 /* Threshold values. */
687 //TODO: The RTS thr has to be _used_. Currently, it is only set via WX.
688 u32 rts_threshold;
689
690 /* Interrupt Service Routine tasklet (bottom-half) */
691 struct tasklet_struct isr_tasklet;
John W. Linvillef2223132006-01-23 16:59:58 -0500692
693 /* Periodic tasks */
Michael Bueschab4977f2006-02-12 22:40:39 +0100694 struct timer_list periodic_tasks;
695 unsigned int periodic_state;
John W. Linvillef2223132006-01-23 16:59:58 -0500696
697 struct work_struct restart_work;
698
699 /* Informational stuff. */
700 char nick[IW_ESSID_MAX_SIZE + 1];
701
702 /* encryption/decryption */
703 u16 security_offset;
704 struct bcm43xx_key key[54];
705 u8 default_key_idx;
706
707 /* Firmware. */
708 const struct firmware *ucode;
709 const struct firmware *pcm;
710 const struct firmware *initvals0;
711 const struct firmware *initvals1;
712
713 /* Debugging stuff follows. */
714#ifdef CONFIG_BCM43XX_DEBUG
715 struct bcm43xx_dfsentry *dfsentry;
716 atomic_t mmio_print_cnt;
717 atomic_t pcicfg_print_cnt;
718#endif
719};
720
721static inline
722struct bcm43xx_private * bcm43xx_priv(struct net_device *dev)
723{
724 return ieee80211softmac_priv(dev);
725}
726
Michael Buesch77db31e2006-02-12 16:47:44 +0100727
728/* Helper function, which returns a boolean.
729 * TRUE, if PIO is used; FALSE, if DMA is used.
730 */
731#if defined(CONFIG_BCM43XX_DMA) && defined(CONFIG_BCM43XX_PIO)
732static inline
733int bcm43xx_using_pio(struct bcm43xx_private *bcm)
734{
735 return bcm->__using_pio;
736}
737#elif defined(CONFIG_BCM43XX_DMA)
738static inline
739int bcm43xx_using_pio(struct bcm43xx_private *bcm)
740{
741 return 0;
742}
743#elif defined(CONFIG_BCM43XX_PIO)
744static inline
745int bcm43xx_using_pio(struct bcm43xx_private *bcm)
746{
747 return 1;
748}
749#else
750# error "Using neither DMA nor PIO? Confused..."
751#endif
752
753
John W. Linvillef2223132006-01-23 16:59:58 -0500754static inline
755int bcm43xx_num_80211_cores(struct bcm43xx_private *bcm)
756{
757 int i, cnt = 0;
758
759 for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
760 if (bcm->core_80211[i].flags & BCM43xx_COREFLAG_AVAILABLE)
761 cnt++;
762 }
763
764 return cnt;
765}
766
767/* Are we running in init_board() context? */
768static inline
769int bcm43xx_is_initializing(struct bcm43xx_private *bcm)
770{
771 if (bcm->initialized)
772 return 0;
773 if (bcm->shutting_down)
774 return 0;
775 return 1;
776}
777
778static inline
779struct bcm43xx_lopair * bcm43xx_get_lopair(struct bcm43xx_phyinfo *phy,
780 u16 radio_attenuation,
781 u16 baseband_attenuation)
782{
783 return phy->_lo_pairs + (radio_attenuation + 14 * (baseband_attenuation / 2));
784}
785
786
787/* MMIO read/write functions. Debug and non-debug variants. */
788#ifdef CONFIG_BCM43XX_DEBUG
789
790static inline
791u16 bcm43xx_read16(struct bcm43xx_private *bcm, u16 offset)
792{
793 u16 value;
794
795 value = ioread16(bcm->mmio_addr + core_offset(bcm) + offset);
796 if (unlikely(atomic_read(&bcm->mmio_print_cnt) > 0)) {
797 printk(KERN_INFO PFX "ioread16 offset: 0x%04x, value: 0x%04x\n",
798 offset, value);
799 }
800
801 return value;
802}
803
804static inline
805void bcm43xx_write16(struct bcm43xx_private *bcm, u16 offset, u16 value)
806{
807 iowrite16(value, bcm->mmio_addr + core_offset(bcm) + offset);
808 if (unlikely(atomic_read(&bcm->mmio_print_cnt) > 0)) {
809 printk(KERN_INFO PFX "iowrite16 offset: 0x%04x, value: 0x%04x\n",
810 offset, value);
811 }
812}
813
814static inline
815u32 bcm43xx_read32(struct bcm43xx_private *bcm, u16 offset)
816{
817 u32 value;
818
819 value = ioread32(bcm->mmio_addr + core_offset(bcm) + offset);
820 if (unlikely(atomic_read(&bcm->mmio_print_cnt) > 0)) {
821 printk(KERN_INFO PFX "ioread32 offset: 0x%04x, value: 0x%08x\n",
822 offset, value);
823 }
824
825 return value;
826}
827
828static inline
829void bcm43xx_write32(struct bcm43xx_private *bcm, u16 offset, u32 value)
830{
831 iowrite32(value, bcm->mmio_addr + core_offset(bcm) + offset);
832 if (unlikely(atomic_read(&bcm->mmio_print_cnt) > 0)) {
833 printk(KERN_INFO PFX "iowrite32 offset: 0x%04x, value: 0x%08x\n",
834 offset, value);
835 }
836}
837
838static inline
839int bcm43xx_pci_read_config16(struct bcm43xx_private *bcm, int offset, u16 *value)
840{
841 int err;
842
843 err = pci_read_config_word(bcm->pci_dev, offset, value);
844 if (unlikely(atomic_read(&bcm->pcicfg_print_cnt) > 0)) {
845 printk(KERN_INFO PFX "pciread16 offset: 0x%08x, value: 0x%04x, err: %d\n",
846 offset, *value, err);
847 }
848
849 return err;
850}
851
852static inline
853int bcm43xx_pci_read_config32(struct bcm43xx_private *bcm, int offset, u32 *value)
854{
855 int err;
856
857 err = pci_read_config_dword(bcm->pci_dev, offset, value);
858 if (unlikely(atomic_read(&bcm->pcicfg_print_cnt) > 0)) {
859 printk(KERN_INFO PFX "pciread32 offset: 0x%08x, value: 0x%08x, err: %d\n",
860 offset, *value, err);
861 }
862
863 return err;
864}
865
866static inline
867int bcm43xx_pci_write_config16(struct bcm43xx_private *bcm, int offset, u16 value)
868{
869 int err;
870
871 err = pci_write_config_word(bcm->pci_dev, offset, value);
872 if (unlikely(atomic_read(&bcm->pcicfg_print_cnt) > 0)) {
873 printk(KERN_INFO PFX "pciwrite16 offset: 0x%08x, value: 0x%04x, err: %d\n",
874 offset, value, err);
875 }
876
877 return err;
878}
879
880static inline
881int bcm43xx_pci_write_config32(struct bcm43xx_private *bcm, int offset, u32 value)
882{
883 int err;
884
885 err = pci_write_config_dword(bcm->pci_dev, offset, value);
886 if (unlikely(atomic_read(&bcm->pcicfg_print_cnt) > 0)) {
887 printk(KERN_INFO PFX "pciwrite32 offset: 0x%08x, value: 0x%08x, err: %d\n",
888 offset, value, err);
889 }
890
891 return err;
892}
893
894#define bcm43xx_mmioprint_initial(bcm, value) atomic_set(&(bcm)->mmio_print_cnt, (value))
895#define bcm43xx_mmioprint_enable(bcm) atomic_inc(&(bcm)->mmio_print_cnt)
896#define bcm43xx_mmioprint_disable(bcm) atomic_dec(&(bcm)->mmio_print_cnt)
897#define bcm43xx_pciprint_initial(bcm, value) atomic_set(&(bcm)->pcicfg_print_cnt, (value))
898#define bcm43xx_pciprint_enable(bcm) atomic_inc(&(bcm)->pcicfg_print_cnt)
899#define bcm43xx_pciprint_disable(bcm) atomic_dec(&(bcm)->pcicfg_print_cnt)
900
901#else /* CONFIG_BCM43XX_DEBUG*/
902
903#define bcm43xx_read16(bcm, offset) ioread16((bcm)->mmio_addr + core_offset(bcm) + (offset))
904#define bcm43xx_write16(bcm, offset, value) iowrite16((value), (bcm)->mmio_addr + core_offset(bcm) + (offset))
905#define bcm43xx_read32(bcm, offset) ioread32((bcm)->mmio_addr + core_offset(bcm) + (offset))
906#define bcm43xx_write32(bcm, offset, value) iowrite32((value), (bcm)->mmio_addr + core_offset(bcm) + (offset))
907#define bcm43xx_pci_read_config16(bcm, o, v) pci_read_config_word((bcm)->pci_dev, (o), (v))
908#define bcm43xx_pci_read_config32(bcm, o, v) pci_read_config_dword((bcm)->pci_dev, (o), (v))
909#define bcm43xx_pci_write_config16(bcm, o, v) pci_write_config_word((bcm)->pci_dev, (o), (v))
910#define bcm43xx_pci_write_config32(bcm, o, v) pci_write_config_dword((bcm)->pci_dev, (o), (v))
911
912#define bcm43xx_mmioprint_initial(x, y) do { /* nothing */ } while (0)
913#define bcm43xx_mmioprint_enable(x) do { /* nothing */ } while (0)
914#define bcm43xx_mmioprint_disable(x) do { /* nothing */ } while (0)
915#define bcm43xx_pciprint_initial(bcm, value) do { /* nothing */ } while (0)
916#define bcm43xx_pciprint_enable(bcm) do { /* nothing */ } while (0)
917#define bcm43xx_pciprint_disable(bcm) do { /* nothing */ } while (0)
918
919#endif /* CONFIG_BCM43XX_DEBUG*/
920
921
922/** Limit a value between two limits */
923#ifdef limit_value
924# undef limit_value
925#endif
926#define limit_value(value, min, max) \
927 ({ \
928 typeof(value) __value = (value); \
929 typeof(value) __min = (min); \
930 typeof(value) __max = (max); \
931 if (__value < __min) \
932 __value = __min; \
933 else if (__value > __max) \
934 __value = __max; \
935 __value; \
936 })
937
Michael Bueschf398f022006-02-23 21:15:39 +0100938/** Helpers to print MAC addresses. */
939#define BCM43xx_MACFMT "%02x:%02x:%02x:%02x:%02x:%02x"
940#define BCM43xx_MACARG(x) ((u8*)(x))[0], ((u8*)(x))[1], \
941 ((u8*)(x))[2], ((u8*)(x))[3], \
942 ((u8*)(x))[4], ((u8*)(x))[5]
943
John W. Linvillef2223132006-01-23 16:59:58 -0500944#endif /* BCM43xx_H_ */