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