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