Merge branch 'akpm'
[linux-2.6/next.git] / drivers / net / wireless / b43legacy / b43legacy.h
blobad4e743e476586554a25d523c7055bb78eab3499
1 #ifndef B43legacy_H_
2 #define B43legacy_H_
4 #include <linux/hw_random.h>
5 #include <linux/kernel.h>
6 #include <linux/spinlock.h>
7 #include <linux/interrupt.h>
8 #include <linux/stringify.h>
9 #include <linux/netdevice.h>
10 #include <linux/pci.h>
11 #include <linux/atomic.h>
12 #include <linux/io.h>
14 #include <linux/ssb/ssb.h>
15 #include <linux/ssb/ssb_driver_chipcommon.h>
17 #include <net/mac80211.h>
19 #include "debugfs.h"
20 #include "leds.h"
21 #include "rfkill.h"
22 #include "phy.h"
25 /* The unique identifier of the firmware that's officially supported by this
26 * driver version. */
27 #define B43legacy_SUPPORTED_FIRMWARE_ID "FW10"
29 #define B43legacy_IRQWAIT_MAX_RETRIES 20
31 /* MMIO offsets */
32 #define B43legacy_MMIO_DMA0_REASON 0x20
33 #define B43legacy_MMIO_DMA0_IRQ_MASK 0x24
34 #define B43legacy_MMIO_DMA1_REASON 0x28
35 #define B43legacy_MMIO_DMA1_IRQ_MASK 0x2C
36 #define B43legacy_MMIO_DMA2_REASON 0x30
37 #define B43legacy_MMIO_DMA2_IRQ_MASK 0x34
38 #define B43legacy_MMIO_DMA3_REASON 0x38
39 #define B43legacy_MMIO_DMA3_IRQ_MASK 0x3C
40 #define B43legacy_MMIO_DMA4_REASON 0x40
41 #define B43legacy_MMIO_DMA4_IRQ_MASK 0x44
42 #define B43legacy_MMIO_DMA5_REASON 0x48
43 #define B43legacy_MMIO_DMA5_IRQ_MASK 0x4C
44 #define B43legacy_MMIO_MACCTL 0x120 /* MAC control */
45 #define B43legacy_MMIO_MACCMD 0x124 /* MAC command */
46 #define B43legacy_MMIO_GEN_IRQ_REASON 0x128
47 #define B43legacy_MMIO_GEN_IRQ_MASK 0x12C
48 #define B43legacy_MMIO_RAM_CONTROL 0x130
49 #define B43legacy_MMIO_RAM_DATA 0x134
50 #define B43legacy_MMIO_PS_STATUS 0x140
51 #define B43legacy_MMIO_RADIO_HWENABLED_HI 0x158
52 #define B43legacy_MMIO_SHM_CONTROL 0x160
53 #define B43legacy_MMIO_SHM_DATA 0x164
54 #define B43legacy_MMIO_SHM_DATA_UNALIGNED 0x166
55 #define B43legacy_MMIO_XMITSTAT_0 0x170
56 #define B43legacy_MMIO_XMITSTAT_1 0x174
57 #define B43legacy_MMIO_REV3PLUS_TSF_LOW 0x180 /* core rev >= 3 only */
58 #define B43legacy_MMIO_REV3PLUS_TSF_HIGH 0x184 /* core rev >= 3 only */
59 #define B43legacy_MMIO_TSF_CFP_REP 0x188
60 #define B43legacy_MMIO_TSF_CFP_START 0x18C
61 /* 32-bit DMA */
62 #define B43legacy_MMIO_DMA32_BASE0 0x200
63 #define B43legacy_MMIO_DMA32_BASE1 0x220
64 #define B43legacy_MMIO_DMA32_BASE2 0x240
65 #define B43legacy_MMIO_DMA32_BASE3 0x260
66 #define B43legacy_MMIO_DMA32_BASE4 0x280
67 #define B43legacy_MMIO_DMA32_BASE5 0x2A0
68 /* 64-bit DMA */
69 #define B43legacy_MMIO_DMA64_BASE0 0x200
70 #define B43legacy_MMIO_DMA64_BASE1 0x240
71 #define B43legacy_MMIO_DMA64_BASE2 0x280
72 #define B43legacy_MMIO_DMA64_BASE3 0x2C0
73 #define B43legacy_MMIO_DMA64_BASE4 0x300
74 #define B43legacy_MMIO_DMA64_BASE5 0x340
75 /* PIO */
76 #define B43legacy_MMIO_PIO1_BASE 0x300
77 #define B43legacy_MMIO_PIO2_BASE 0x310
78 #define B43legacy_MMIO_PIO3_BASE 0x320
79 #define B43legacy_MMIO_PIO4_BASE 0x330
81 #define B43legacy_MMIO_PHY_VER 0x3E0
82 #define B43legacy_MMIO_PHY_RADIO 0x3E2
83 #define B43legacy_MMIO_PHY0 0x3E6
84 #define B43legacy_MMIO_ANTENNA 0x3E8
85 #define B43legacy_MMIO_CHANNEL 0x3F0
86 #define B43legacy_MMIO_CHANNEL_EXT 0x3F4
87 #define B43legacy_MMIO_RADIO_CONTROL 0x3F6
88 #define B43legacy_MMIO_RADIO_DATA_HIGH 0x3F8
89 #define B43legacy_MMIO_RADIO_DATA_LOW 0x3FA
90 #define B43legacy_MMIO_PHY_CONTROL 0x3FC
91 #define B43legacy_MMIO_PHY_DATA 0x3FE
92 #define B43legacy_MMIO_MACFILTER_CONTROL 0x420
93 #define B43legacy_MMIO_MACFILTER_DATA 0x422
94 #define B43legacy_MMIO_RCMTA_COUNT 0x43C /* Receive Match Transmitter Addr */
95 #define B43legacy_MMIO_RADIO_HWENABLED_LO 0x49A
96 #define B43legacy_MMIO_GPIO_CONTROL 0x49C
97 #define B43legacy_MMIO_GPIO_MASK 0x49E
98 #define B43legacy_MMIO_TSF_CFP_PRETBTT 0x612
99 #define B43legacy_MMIO_TSF_0 0x632 /* core rev < 3 only */
100 #define B43legacy_MMIO_TSF_1 0x634 /* core rev < 3 only */
101 #define B43legacy_MMIO_TSF_2 0x636 /* core rev < 3 only */
102 #define B43legacy_MMIO_TSF_3 0x638 /* core rev < 3 only */
103 #define B43legacy_MMIO_RNG 0x65A
104 #define B43legacy_MMIO_POWERUP_DELAY 0x6A8
106 /* SPROM boardflags_lo values */
107 #define B43legacy_BFL_PACTRL 0x0002
108 #define B43legacy_BFL_RSSI 0x0008
109 #define B43legacy_BFL_EXTLNA 0x1000
111 /* GPIO register offset, in both ChipCommon and PCI core. */
112 #define B43legacy_GPIO_CONTROL 0x6c
114 /* SHM Routing */
115 #define B43legacy_SHM_SHARED 0x0001
116 #define B43legacy_SHM_WIRELESS 0x0002
117 #define B43legacy_SHM_HW 0x0004
118 #define B43legacy_SHM_UCODE 0x0300
120 /* SHM Routing modifiers */
121 #define B43legacy_SHM_AUTOINC_R 0x0200 /* Read Auto-increment */
122 #define B43legacy_SHM_AUTOINC_W 0x0100 /* Write Auto-increment */
123 #define B43legacy_SHM_AUTOINC_RW (B43legacy_SHM_AUTOINC_R | \
124 B43legacy_SHM_AUTOINC_W)
126 /* Misc SHM_SHARED offsets */
127 #define B43legacy_SHM_SH_WLCOREREV 0x0016 /* 802.11 core revision */
128 #define B43legacy_SHM_SH_HOSTFLO 0x005E /* Hostflags ucode opts (low) */
129 #define B43legacy_SHM_SH_HOSTFHI 0x0060 /* Hostflags ucode opts (high) */
130 /* SHM_SHARED crypto engine */
131 #define B43legacy_SHM_SH_KEYIDXBLOCK 0x05D4 /* Key index/algorithm block */
132 /* SHM_SHARED beacon/AP variables */
133 #define B43legacy_SHM_SH_DTIMP 0x0012 /* DTIM period */
134 #define B43legacy_SHM_SH_BTL0 0x0018 /* Beacon template length 0 */
135 #define B43legacy_SHM_SH_BTL1 0x001A /* Beacon template length 1 */
136 #define B43legacy_SHM_SH_BTSFOFF 0x001C /* Beacon TSF offset */
137 #define B43legacy_SHM_SH_TIMPOS 0x001E /* TIM position in beacon */
138 #define B43legacy_SHM_SH_BEACPHYCTL 0x0054 /* Beacon PHY TX control word */
139 /* SHM_SHARED ACK/CTS control */
140 #define B43legacy_SHM_SH_ACKCTSPHYCTL 0x0022 /* ACK/CTS PHY control word */
141 /* SHM_SHARED probe response variables */
142 #define B43legacy_SHM_SH_PRTLEN 0x004A /* Probe Response template length */
143 #define B43legacy_SHM_SH_PRMAXTIME 0x0074 /* Probe Response max time */
144 #define B43legacy_SHM_SH_PRPHYCTL 0x0188 /* Probe Resp PHY TX control */
145 /* SHM_SHARED rate tables */
146 #define B43legacy_SHM_SH_OFDMDIRECT 0x0480 /* Pointer to OFDM direct map */
147 #define B43legacy_SHM_SH_OFDMBASIC 0x04A0 /* Pointer to OFDM basic rate map */
148 #define B43legacy_SHM_SH_CCKDIRECT 0x04C0 /* Pointer to CCK direct map */
149 #define B43legacy_SHM_SH_CCKBASIC 0x04E0 /* Pointer to CCK basic rate map */
150 /* SHM_SHARED microcode soft registers */
151 #define B43legacy_SHM_SH_UCODEREV 0x0000 /* Microcode revision */
152 #define B43legacy_SHM_SH_UCODEPATCH 0x0002 /* Microcode patchlevel */
153 #define B43legacy_SHM_SH_UCODEDATE 0x0004 /* Microcode date */
154 #define B43legacy_SHM_SH_UCODETIME 0x0006 /* Microcode time */
155 #define B43legacy_SHM_SH_SPUWKUP 0x0094 /* pre-wakeup for synth PU in us */
156 #define B43legacy_SHM_SH_PRETBTT 0x0096 /* pre-TBTT in us */
158 #define B43legacy_UCODEFLAGS_OFFSET 0x005E
160 /* Hardware Radio Enable masks */
161 #define B43legacy_MMIO_RADIO_HWENABLED_HI_MASK (1 << 16)
162 #define B43legacy_MMIO_RADIO_HWENABLED_LO_MASK (1 << 4)
164 /* HostFlags. See b43legacy_hf_read/write() */
165 #define B43legacy_HF_SYMW 0x00000002 /* G-PHY SYM workaround */
166 #define B43legacy_HF_GDCW 0x00000020 /* G-PHY DV cancel filter */
167 #define B43legacy_HF_OFDMPABOOST 0x00000040 /* Enable PA boost OFDM */
168 #define B43legacy_HF_EDCF 0x00000100 /* on if WME/MAC suspended */
170 /* MacFilter offsets. */
171 #define B43legacy_MACFILTER_SELF 0x0000
172 #define B43legacy_MACFILTER_BSSID 0x0003
173 #define B43legacy_MACFILTER_MAC 0x0010
175 /* PHYVersioning */
176 #define B43legacy_PHYTYPE_B 0x01
177 #define B43legacy_PHYTYPE_G 0x02
179 /* PHYRegisters */
180 #define B43legacy_PHY_G_LO_CONTROL 0x0810
181 #define B43legacy_PHY_ILT_G_CTRL 0x0472
182 #define B43legacy_PHY_ILT_G_DATA1 0x0473
183 #define B43legacy_PHY_ILT_G_DATA2 0x0474
184 #define B43legacy_PHY_G_PCTL 0x0029
185 #define B43legacy_PHY_RADIO_BITFIELD 0x0401
186 #define B43legacy_PHY_G_CRS 0x0429
187 #define B43legacy_PHY_NRSSILT_CTRL 0x0803
188 #define B43legacy_PHY_NRSSILT_DATA 0x0804
190 /* RadioRegisters */
191 #define B43legacy_RADIOCTL_ID 0x01
193 /* MAC Control bitfield */
194 #define B43legacy_MACCTL_ENABLED 0x00000001 /* MAC Enabled */
195 #define B43legacy_MACCTL_PSM_RUN 0x00000002 /* Run Microcode */
196 #define B43legacy_MACCTL_PSM_JMP0 0x00000004 /* Microcode jump to 0 */
197 #define B43legacy_MACCTL_SHM_ENABLED 0x00000100 /* SHM Enabled */
198 #define B43legacy_MACCTL_IHR_ENABLED 0x00000400 /* IHR Region Enabled */
199 #define B43legacy_MACCTL_BE 0x00010000 /* Big Endian mode */
200 #define B43legacy_MACCTL_INFRA 0x00020000 /* Infrastructure mode */
201 #define B43legacy_MACCTL_AP 0x00040000 /* AccessPoint mode */
202 #define B43legacy_MACCTL_RADIOLOCK 0x00080000 /* Radio lock */
203 #define B43legacy_MACCTL_BEACPROMISC 0x00100000 /* Beacon Promiscuous */
204 #define B43legacy_MACCTL_KEEP_BADPLCP 0x00200000 /* Keep bad PLCP frames */
205 #define B43legacy_MACCTL_KEEP_CTL 0x00400000 /* Keep control frames */
206 #define B43legacy_MACCTL_KEEP_BAD 0x00800000 /* Keep bad frames (FCS) */
207 #define B43legacy_MACCTL_PROMISC 0x01000000 /* Promiscuous mode */
208 #define B43legacy_MACCTL_HWPS 0x02000000 /* Hardware Power Saving */
209 #define B43legacy_MACCTL_AWAKE 0x04000000 /* Device is awake */
210 #define B43legacy_MACCTL_TBTTHOLD 0x10000000 /* TBTT Hold */
211 #define B43legacy_MACCTL_GMODE 0x80000000 /* G Mode */
213 /* MAC Command bitfield */
214 #define B43legacy_MACCMD_BEACON0_VALID 0x00000001 /* Beacon 0 in template RAM is busy/valid */
215 #define B43legacy_MACCMD_BEACON1_VALID 0x00000002 /* Beacon 1 in template RAM is busy/valid */
216 #define B43legacy_MACCMD_DFQ_VALID 0x00000004 /* Directed frame queue valid (IBSS PS mode, ATIM) */
217 #define B43legacy_MACCMD_CCA 0x00000008 /* Clear channel assessment */
218 #define B43legacy_MACCMD_BGNOISE 0x00000010 /* Background noise */
220 /* 802.11 core specific TM State Low flags */
221 #define B43legacy_TMSLOW_GMODE 0x20000000 /* G Mode Enable */
222 #define B43legacy_TMSLOW_PLLREFSEL 0x00200000 /* PLL Freq Ref Select */
223 #define B43legacy_TMSLOW_MACPHYCLKEN 0x00100000 /* MAC PHY Clock Ctrl Enbl */
224 #define B43legacy_TMSLOW_PHYRESET 0x00080000 /* PHY Reset */
225 #define B43legacy_TMSLOW_PHYCLKEN 0x00040000 /* PHY Clock Enable */
227 /* 802.11 core specific TM State High flags */
228 #define B43legacy_TMSHIGH_FCLOCK 0x00040000 /* Fast Clock Available */
229 #define B43legacy_TMSHIGH_GPHY 0x00010000 /* G-PHY avail (rev >= 5) */
231 #define B43legacy_UCODEFLAG_AUTODIV 0x0001
233 /* Generic-Interrupt reasons. */
234 #define B43legacy_IRQ_MAC_SUSPENDED 0x00000001
235 #define B43legacy_IRQ_BEACON 0x00000002
236 #define B43legacy_IRQ_TBTT_INDI 0x00000004 /* Target Beacon Transmit Time */
237 #define B43legacy_IRQ_BEACON_TX_OK 0x00000008
238 #define B43legacy_IRQ_BEACON_CANCEL 0x00000010
239 #define B43legacy_IRQ_ATIM_END 0x00000020
240 #define B43legacy_IRQ_PMQ 0x00000040
241 #define B43legacy_IRQ_PIO_WORKAROUND 0x00000100
242 #define B43legacy_IRQ_MAC_TXERR 0x00000200
243 #define B43legacy_IRQ_PHY_TXERR 0x00000800
244 #define B43legacy_IRQ_PMEVENT 0x00001000
245 #define B43legacy_IRQ_TIMER0 0x00002000
246 #define B43legacy_IRQ_TIMER1 0x00004000
247 #define B43legacy_IRQ_DMA 0x00008000
248 #define B43legacy_IRQ_TXFIFO_FLUSH_OK 0x00010000
249 #define B43legacy_IRQ_CCA_MEASURE_OK 0x00020000
250 #define B43legacy_IRQ_NOISESAMPLE_OK 0x00040000
251 #define B43legacy_IRQ_UCODE_DEBUG 0x08000000
252 #define B43legacy_IRQ_RFKILL 0x10000000
253 #define B43legacy_IRQ_TX_OK 0x20000000
254 #define B43legacy_IRQ_PHY_G_CHANGED 0x40000000
255 #define B43legacy_IRQ_TIMEOUT 0x80000000
257 #define B43legacy_IRQ_ALL 0xFFFFFFFF
258 #define B43legacy_IRQ_MASKTEMPLATE (B43legacy_IRQ_MAC_SUSPENDED | \
259 B43legacy_IRQ_TBTT_INDI | \
260 B43legacy_IRQ_ATIM_END | \
261 B43legacy_IRQ_PMQ | \
262 B43legacy_IRQ_MAC_TXERR | \
263 B43legacy_IRQ_PHY_TXERR | \
264 B43legacy_IRQ_DMA | \
265 B43legacy_IRQ_TXFIFO_FLUSH_OK | \
266 B43legacy_IRQ_NOISESAMPLE_OK | \
267 B43legacy_IRQ_UCODE_DEBUG | \
268 B43legacy_IRQ_RFKILL | \
269 B43legacy_IRQ_TX_OK)
271 /* Device specific rate values.
272 * The actual values defined here are (rate_in_mbps * 2).
273 * Some code depends on this. Don't change it. */
274 #define B43legacy_CCK_RATE_1MB 2
275 #define B43legacy_CCK_RATE_2MB 4
276 #define B43legacy_CCK_RATE_5MB 11
277 #define B43legacy_CCK_RATE_11MB 22
278 #define B43legacy_OFDM_RATE_6MB 12
279 #define B43legacy_OFDM_RATE_9MB 18
280 #define B43legacy_OFDM_RATE_12MB 24
281 #define B43legacy_OFDM_RATE_18MB 36
282 #define B43legacy_OFDM_RATE_24MB 48
283 #define B43legacy_OFDM_RATE_36MB 72
284 #define B43legacy_OFDM_RATE_48MB 96
285 #define B43legacy_OFDM_RATE_54MB 108
286 /* Convert a b43legacy rate value to a rate in 100kbps */
287 #define B43legacy_RATE_TO_100KBPS(rate) (((rate) * 10) / 2)
290 #define B43legacy_DEFAULT_SHORT_RETRY_LIMIT 7
291 #define B43legacy_DEFAULT_LONG_RETRY_LIMIT 4
293 #define B43legacy_PHY_TX_BADNESS_LIMIT 1000
295 /* Max size of a security key */
296 #define B43legacy_SEC_KEYSIZE 16
297 /* Security algorithms. */
298 enum {
299 B43legacy_SEC_ALGO_NONE = 0, /* unencrypted, as of TX header. */
300 B43legacy_SEC_ALGO_WEP40,
301 B43legacy_SEC_ALGO_TKIP,
302 B43legacy_SEC_ALGO_AES,
303 B43legacy_SEC_ALGO_WEP104,
304 B43legacy_SEC_ALGO_AES_LEGACY,
307 /* Core Information Registers */
308 #define B43legacy_CIR_BASE 0xf00
309 #define B43legacy_CIR_SBTPSFLAG (B43legacy_CIR_BASE + 0x18)
310 #define B43legacy_CIR_SBIMSTATE (B43legacy_CIR_BASE + 0x90)
311 #define B43legacy_CIR_SBINTVEC (B43legacy_CIR_BASE + 0x94)
312 #define B43legacy_CIR_SBTMSTATELOW (B43legacy_CIR_BASE + 0x98)
313 #define B43legacy_CIR_SBTMSTATEHIGH (B43legacy_CIR_BASE + 0x9c)
314 #define B43legacy_CIR_SBIMCONFIGLOW (B43legacy_CIR_BASE + 0xa8)
315 #define B43legacy_CIR_SB_ID_HI (B43legacy_CIR_BASE + 0xfc)
317 /* sbtmstatehigh state flags */
318 #define B43legacy_SBTMSTATEHIGH_SERROR 0x00000001
319 #define B43legacy_SBTMSTATEHIGH_BUSY 0x00000004
320 #define B43legacy_SBTMSTATEHIGH_TIMEOUT 0x00000020
321 #define B43legacy_SBTMSTATEHIGH_G_PHY_AVAIL 0x00010000
322 #define B43legacy_SBTMSTATEHIGH_COREFLAGS 0x1FFF0000
323 #define B43legacy_SBTMSTATEHIGH_DMA64BIT 0x10000000
324 #define B43legacy_SBTMSTATEHIGH_GATEDCLK 0x20000000
325 #define B43legacy_SBTMSTATEHIGH_BISTFAILED 0x40000000
326 #define B43legacy_SBTMSTATEHIGH_BISTCOMPLETE 0x80000000
328 /* sbimstate flags */
329 #define B43legacy_SBIMSTATE_IB_ERROR 0x20000
330 #define B43legacy_SBIMSTATE_TIMEOUT 0x40000
332 #define PFX KBUILD_MODNAME ": "
333 #ifdef assert
334 # undef assert
335 #endif
336 #ifdef CONFIG_B43LEGACY_DEBUG
337 # define B43legacy_WARN_ON(x) WARN_ON(x)
338 # define B43legacy_BUG_ON(expr) \
339 do { \
340 if (unlikely((expr))) { \
341 printk(KERN_INFO PFX "Test (%s) failed\n", \
342 #expr); \
343 BUG_ON(expr); \
345 } while (0)
346 # define B43legacy_DEBUG 1
347 #else
348 /* This will evaluate the argument even if debugging is disabled. */
349 static inline bool __b43legacy_warn_on_dummy(bool x) { return x; }
350 # define B43legacy_WARN_ON(x) __b43legacy_warn_on_dummy(unlikely(!!(x)))
351 # define B43legacy_BUG_ON(x) do { /* nothing */ } while (0)
352 # define B43legacy_DEBUG 0
353 #endif
356 struct net_device;
357 struct pci_dev;
358 struct b43legacy_dmaring;
359 struct b43legacy_pioqueue;
361 /* The firmware file header */
362 #define B43legacy_FW_TYPE_UCODE 'u'
363 #define B43legacy_FW_TYPE_PCM 'p'
364 #define B43legacy_FW_TYPE_IV 'i'
365 struct b43legacy_fw_header {
366 /* File type */
367 u8 type;
368 /* File format version */
369 u8 ver;
370 u8 __padding[2];
371 /* Size of the data. For ucode and PCM this is in bytes.
372 * For IV this is number-of-ivs. */
373 __be32 size;
374 } __packed;
376 /* Initial Value file format */
377 #define B43legacy_IV_OFFSET_MASK 0x7FFF
378 #define B43legacy_IV_32BIT 0x8000
379 struct b43legacy_iv {
380 __be16 offset_size;
381 union {
382 __be16 d16;
383 __be32 d32;
384 } data __packed;
385 } __packed;
387 #define B43legacy_PHYMODE(phytype) (1 << (phytype))
388 #define B43legacy_PHYMODE_B B43legacy_PHYMODE \
389 ((B43legacy_PHYTYPE_B))
390 #define B43legacy_PHYMODE_G B43legacy_PHYMODE \
391 ((B43legacy_PHYTYPE_G))
393 /* Value pair to measure the LocalOscillator. */
394 struct b43legacy_lopair {
395 s8 low;
396 s8 high;
397 u8 used:1;
399 #define B43legacy_LO_COUNT (14*4)
401 struct b43legacy_phy {
402 /* Possible PHYMODEs on this PHY */
403 u8 possible_phymodes;
404 /* GMODE bit enabled in MACCTL? */
405 bool gmode;
407 /* Analog Type */
408 u8 analog;
409 /* B43legacy_PHYTYPE_ */
410 u8 type;
411 /* PHY revision number. */
412 u8 rev;
414 u16 antenna_diversity;
415 u16 savedpctlreg;
416 /* Radio versioning */
417 u16 radio_manuf; /* Radio manufacturer */
418 u16 radio_ver; /* Radio version */
419 u8 calibrated:1;
420 u8 radio_rev; /* Radio revision */
422 bool dyn_tssi_tbl; /* tssi2dbm is kmalloc()ed. */
424 /* ACI (adjacent channel interference) flags. */
425 bool aci_enable;
426 bool aci_wlan_automatic;
427 bool aci_hw_rssi;
429 /* Radio switched on/off */
430 bool radio_on;
431 struct {
432 /* Values saved when turning the radio off.
433 * They are needed when turning it on again. */
434 bool valid;
435 u16 rfover;
436 u16 rfoverval;
437 } radio_off_context;
439 u16 minlowsig[2];
440 u16 minlowsigpos[2];
442 /* LO Measurement Data.
443 * Use b43legacy_get_lopair() to get a value.
445 struct b43legacy_lopair *_lo_pairs;
446 /* TSSI to dBm table in use */
447 const s8 *tssi2dbm;
448 /* idle TSSI value */
449 s8 idle_tssi;
450 /* Target idle TSSI */
451 int tgt_idle_tssi;
452 /* Current idle TSSI */
453 int cur_idle_tssi;
455 /* LocalOscillator control values. */
456 struct b43legacy_txpower_lo_control *lo_control;
457 /* Values from b43legacy_calc_loopback_gain() */
458 s16 max_lb_gain; /* Maximum Loopback gain in hdB */
459 s16 trsw_rx_gain; /* TRSW RX gain in hdB */
460 s16 lna_lod_gain; /* LNA lod */
461 s16 lna_gain; /* LNA */
462 s16 pga_gain; /* PGA */
464 /* Desired TX power level (in dBm). This is set by the user and
465 * adjusted in b43legacy_phy_xmitpower(). */
466 u8 power_level;
468 /* Values from b43legacy_calc_loopback_gain() */
469 u16 loopback_gain[2];
471 /* TX Power control values. */
472 /* B/G PHY */
473 struct {
474 /* Current Radio Attenuation for TXpower recalculation. */
475 u16 rfatt;
476 /* Current Baseband Attenuation for TXpower recalculation. */
477 u16 bbatt;
478 /* Current TXpower control value for TXpower recalculation. */
479 u16 txctl1;
480 u16 txctl2;
482 /* A PHY */
483 struct {
484 u16 txpwr_offset;
487 /* Current Interference Mitigation mode */
488 int interfmode;
489 /* Stack of saved values from the Interference Mitigation code.
490 * Each value in the stack is laid out as follows:
491 * bit 0-11: offset
492 * bit 12-15: register ID
493 * bit 16-32: value
494 * register ID is: 0x1 PHY, 0x2 Radio, 0x3 ILT
496 #define B43legacy_INTERFSTACK_SIZE 26
497 u32 interfstack[B43legacy_INTERFSTACK_SIZE];
499 /* Saved values from the NRSSI Slope calculation */
500 s16 nrssi[2];
501 s32 nrssislope;
502 /* In memory nrssi lookup table. */
503 s8 nrssi_lt[64];
505 /* current channel */
506 u8 channel;
508 u16 lofcal;
510 u16 initval;
512 /* PHY TX errors counter. */
513 atomic_t txerr_cnt;
515 #if B43legacy_DEBUG
516 /* Manual TX-power control enabled? */
517 bool manual_txpower_control;
518 /* PHY registers locked by b43legacy_phy_lock()? */
519 bool phy_locked;
520 #endif /* B43legacy_DEBUG */
523 /* Data structures for DMA transmission, per 80211 core. */
524 struct b43legacy_dma {
525 struct b43legacy_dmaring *tx_ring0;
526 struct b43legacy_dmaring *tx_ring1;
527 struct b43legacy_dmaring *tx_ring2;
528 struct b43legacy_dmaring *tx_ring3;
529 struct b43legacy_dmaring *tx_ring4;
530 struct b43legacy_dmaring *tx_ring5;
532 struct b43legacy_dmaring *rx_ring0;
533 struct b43legacy_dmaring *rx_ring3; /* only on core.rev < 5 */
535 u32 translation; /* Routing bits */
538 /* Data structures for PIO transmission, per 80211 core. */
539 struct b43legacy_pio {
540 struct b43legacy_pioqueue *queue0;
541 struct b43legacy_pioqueue *queue1;
542 struct b43legacy_pioqueue *queue2;
543 struct b43legacy_pioqueue *queue3;
546 /* Context information for a noise calculation (Link Quality). */
547 struct b43legacy_noise_calculation {
548 u8 channel_at_start;
549 bool calculation_running;
550 u8 nr_samples;
551 s8 samples[8][4];
554 struct b43legacy_stats {
555 u8 link_noise;
556 /* Store the last TX/RX times here for updating the leds. */
557 unsigned long last_tx;
558 unsigned long last_rx;
561 struct b43legacy_key {
562 void *keyconf;
563 bool enabled;
564 u8 algorithm;
567 struct b43legacy_wldev;
569 /* Data structure for the WLAN parts (802.11 cores) of the b43legacy chip. */
570 struct b43legacy_wl {
571 /* Pointer to the active wireless device on this chip */
572 struct b43legacy_wldev *current_dev;
573 /* Pointer to the ieee80211 hardware data structure */
574 struct ieee80211_hw *hw;
576 spinlock_t irq_lock; /* locks IRQ */
577 struct mutex mutex; /* locks wireless core state */
578 spinlock_t leds_lock; /* lock for leds */
580 /* We can only have one operating interface (802.11 core)
581 * at a time. General information about this interface follows.
584 struct ieee80211_vif *vif;
585 /* MAC address (can be NULL). */
586 u8 mac_addr[ETH_ALEN];
587 /* Current BSSID (can be NULL). */
588 u8 bssid[ETH_ALEN];
589 /* Interface type. (IEEE80211_IF_TYPE_XXX) */
590 int if_type;
591 /* Is the card operating in AP, STA or IBSS mode? */
592 bool operating;
593 /* filter flags */
594 unsigned int filter_flags;
595 /* Stats about the wireless interface */
596 struct ieee80211_low_level_stats ieee_stats;
598 #ifdef CONFIG_B43LEGACY_HWRNG
599 struct hwrng rng;
600 u8 rng_initialized;
601 char rng_name[30 + 1];
602 #endif
604 /* List of all wireless devices on this chip */
605 struct list_head devlist;
606 u8 nr_devs;
608 bool radiotap_enabled;
609 bool radio_enabled;
611 /* The beacon we are currently using (AP or IBSS mode).
612 * This beacon stuff is protected by the irq_lock. */
613 struct sk_buff *current_beacon;
614 bool beacon0_uploaded;
615 bool beacon1_uploaded;
616 bool beacon_templates_virgin; /* Never wrote the templates? */
617 struct work_struct beacon_update_trigger;
620 /* Pointers to the firmware data and meta information about it. */
621 struct b43legacy_firmware {
622 /* Microcode */
623 const struct firmware *ucode;
624 /* PCM code */
625 const struct firmware *pcm;
626 /* Initial MMIO values for the firmware */
627 const struct firmware *initvals;
628 /* Initial MMIO values for the firmware, band-specific */
629 const struct firmware *initvals_band;
630 /* Firmware revision */
631 u16 rev;
632 /* Firmware patchlevel */
633 u16 patch;
636 /* Device (802.11 core) initialization status. */
637 enum {
638 B43legacy_STAT_UNINIT = 0, /* Uninitialized. */
639 B43legacy_STAT_INITIALIZED = 1, /* Initialized, not yet started. */
640 B43legacy_STAT_STARTED = 2, /* Up and running. */
642 #define b43legacy_status(wldev) atomic_read(&(wldev)->__init_status)
643 #define b43legacy_set_status(wldev, stat) do { \
644 atomic_set(&(wldev)->__init_status, (stat)); \
645 smp_wmb(); \
646 } while (0)
648 /* *** --- HOW LOCKING WORKS IN B43legacy --- ***
650 * You should always acquire both, wl->mutex and wl->irq_lock unless:
651 * - You don't need to acquire wl->irq_lock, if the interface is stopped.
652 * - You don't need to acquire wl->mutex in the IRQ handler, IRQ tasklet
653 * and packet TX path (and _ONLY_ there.)
656 /* Data structure for one wireless device (802.11 core) */
657 struct b43legacy_wldev {
658 struct ssb_device *dev;
659 struct b43legacy_wl *wl;
661 /* The device initialization status.
662 * Use b43legacy_status() to query. */
663 atomic_t __init_status;
664 /* Saved init status for handling suspend. */
665 int suspend_init_status;
667 bool __using_pio; /* Using pio rather than dma. */
668 bool bad_frames_preempt;/* Use "Bad Frames Preemption". */
669 bool dfq_valid; /* Directed frame queue valid (IBSS PS mode, ATIM). */
670 bool short_preamble; /* TRUE if using short preamble. */
671 bool radio_hw_enable; /* State of radio hardware enable bit. */
673 /* PHY/Radio device. */
674 struct b43legacy_phy phy;
675 union {
676 /* DMA engines. */
677 struct b43legacy_dma dma;
678 /* PIO engines. */
679 struct b43legacy_pio pio;
682 /* Various statistics about the physical device. */
683 struct b43legacy_stats stats;
685 /* The device LEDs. */
686 struct b43legacy_led led_tx;
687 struct b43legacy_led led_rx;
688 struct b43legacy_led led_assoc;
689 struct b43legacy_led led_radio;
691 /* Reason code of the last interrupt. */
692 u32 irq_reason;
693 u32 dma_reason[6];
694 /* The currently active generic-interrupt mask. */
695 u32 irq_mask;
696 /* Link Quality calculation context. */
697 struct b43legacy_noise_calculation noisecalc;
698 /* if > 0 MAC is suspended. if == 0 MAC is enabled. */
699 int mac_suspended;
701 /* Interrupt Service Routine tasklet (bottom-half) */
702 struct tasklet_struct isr_tasklet;
704 /* Periodic tasks */
705 struct delayed_work periodic_work;
706 unsigned int periodic_state;
708 struct work_struct restart_work;
710 /* encryption/decryption */
711 u16 ktp; /* Key table pointer */
712 u8 max_nr_keys;
713 struct b43legacy_key key[58];
715 /* Firmware data */
716 struct b43legacy_firmware fw;
718 /* Devicelist in struct b43legacy_wl (all 802.11 cores) */
719 struct list_head list;
721 /* Debugging stuff follows. */
722 #ifdef CONFIG_B43LEGACY_DEBUG
723 struct b43legacy_dfsentry *dfsentry;
724 #endif
728 static inline
729 struct b43legacy_wl *hw_to_b43legacy_wl(struct ieee80211_hw *hw)
731 return hw->priv;
734 /* Helper function, which returns a boolean.
735 * TRUE, if PIO is used; FALSE, if DMA is used.
737 #if defined(CONFIG_B43LEGACY_DMA) && defined(CONFIG_B43LEGACY_PIO)
738 static inline
739 int b43legacy_using_pio(struct b43legacy_wldev *dev)
741 return dev->__using_pio;
743 #elif defined(CONFIG_B43LEGACY_DMA)
744 static inline
745 int b43legacy_using_pio(struct b43legacy_wldev *dev)
747 return 0;
749 #elif defined(CONFIG_B43LEGACY_PIO)
750 static inline
751 int b43legacy_using_pio(struct b43legacy_wldev *dev)
753 return 1;
755 #else
756 # error "Using neither DMA nor PIO? Confused..."
757 #endif
760 static inline
761 struct b43legacy_wldev *dev_to_b43legacy_wldev(struct device *dev)
763 struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
764 return ssb_get_drvdata(ssb_dev);
767 /* Is the device operating in a specified mode (IEEE80211_IF_TYPE_XXX). */
768 static inline
769 int b43legacy_is_mode(struct b43legacy_wl *wl, int type)
771 return (wl->operating &&
772 wl->if_type == type);
775 static inline
776 bool is_bcm_board_vendor(struct b43legacy_wldev *dev)
778 return (dev->dev->bus->boardinfo.vendor == PCI_VENDOR_ID_BROADCOM);
781 static inline
782 u16 b43legacy_read16(struct b43legacy_wldev *dev, u16 offset)
784 return ssb_read16(dev->dev, offset);
787 static inline
788 void b43legacy_write16(struct b43legacy_wldev *dev, u16 offset, u16 value)
790 ssb_write16(dev->dev, offset, value);
793 static inline
794 u32 b43legacy_read32(struct b43legacy_wldev *dev, u16 offset)
796 return ssb_read32(dev->dev, offset);
799 static inline
800 void b43legacy_write32(struct b43legacy_wldev *dev, u16 offset, u32 value)
802 ssb_write32(dev->dev, offset, value);
805 static inline
806 struct b43legacy_lopair *b43legacy_get_lopair(struct b43legacy_phy *phy,
807 u16 radio_attenuation,
808 u16 baseband_attenuation)
810 return phy->_lo_pairs + (radio_attenuation
811 + 14 * (baseband_attenuation / 2));
816 /* Message printing */
817 void b43legacyinfo(struct b43legacy_wl *wl, const char *fmt, ...)
818 __attribute__((format(printf, 2, 3)));
819 void b43legacyerr(struct b43legacy_wl *wl, const char *fmt, ...)
820 __attribute__((format(printf, 2, 3)));
821 void b43legacywarn(struct b43legacy_wl *wl, const char *fmt, ...)
822 __attribute__((format(printf, 2, 3)));
823 #if B43legacy_DEBUG
824 void b43legacydbg(struct b43legacy_wl *wl, const char *fmt, ...)
825 __attribute__((format(printf, 2, 3)));
826 #else /* DEBUG */
827 # define b43legacydbg(wl, fmt...) do { /* nothing */ } while (0)
828 #endif /* DEBUG */
830 /* Macros for printing a value in Q5.2 format */
831 #define Q52_FMT "%u.%u"
832 #define Q52_ARG(q52) ((q52) / 4), (((q52) & 3) * 100 / 4)
834 #endif /* B43legacy_H_ */