Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef B43legacy_H_
0003 #define B43legacy_H_
0004 
0005 #include <linux/hw_random.h>
0006 #include <linux/kernel.h>
0007 #include <linux/spinlock.h>
0008 #include <linux/interrupt.h>
0009 #include <linux/stringify.h>
0010 #include <linux/netdevice.h>
0011 #include <linux/pci.h>
0012 #include <linux/atomic.h>
0013 #include <linux/io.h>
0014 
0015 #include <linux/ssb/ssb.h>
0016 #include <linux/ssb/ssb_driver_chipcommon.h>
0017 #include <linux/completion.h>
0018 
0019 #include <net/mac80211.h>
0020 
0021 #include "debugfs.h"
0022 #include "leds.h"
0023 #include "rfkill.h"
0024 #include "phy.h"
0025 
0026 
0027 #define B43legacy_IRQWAIT_MAX_RETRIES   20
0028 
0029 /* MMIO offsets */
0030 #define B43legacy_MMIO_DMA0_REASON  0x20
0031 #define B43legacy_MMIO_DMA0_IRQ_MASK    0x24
0032 #define B43legacy_MMIO_DMA1_REASON  0x28
0033 #define B43legacy_MMIO_DMA1_IRQ_MASK    0x2C
0034 #define B43legacy_MMIO_DMA2_REASON  0x30
0035 #define B43legacy_MMIO_DMA2_IRQ_MASK    0x34
0036 #define B43legacy_MMIO_DMA3_REASON  0x38
0037 #define B43legacy_MMIO_DMA3_IRQ_MASK    0x3C
0038 #define B43legacy_MMIO_DMA4_REASON  0x40
0039 #define B43legacy_MMIO_DMA4_IRQ_MASK    0x44
0040 #define B43legacy_MMIO_DMA5_REASON  0x48
0041 #define B43legacy_MMIO_DMA5_IRQ_MASK    0x4C
0042 #define B43legacy_MMIO_MACCTL       0x120   /* MAC control */
0043 #define B43legacy_MMIO_MACCMD       0x124   /* MAC command */
0044 #define B43legacy_MMIO_GEN_IRQ_REASON   0x128
0045 #define B43legacy_MMIO_GEN_IRQ_MASK 0x12C
0046 #define B43legacy_MMIO_RAM_CONTROL  0x130
0047 #define B43legacy_MMIO_RAM_DATA     0x134
0048 #define B43legacy_MMIO_PS_STATUS        0x140
0049 #define B43legacy_MMIO_RADIO_HWENABLED_HI   0x158
0050 #define B43legacy_MMIO_SHM_CONTROL  0x160
0051 #define B43legacy_MMIO_SHM_DATA     0x164
0052 #define B43legacy_MMIO_SHM_DATA_UNALIGNED   0x166
0053 #define B43legacy_MMIO_XMITSTAT_0       0x170
0054 #define B43legacy_MMIO_XMITSTAT_1       0x174
0055 #define B43legacy_MMIO_REV3PLUS_TSF_LOW 0x180 /* core rev >= 3 only */
0056 #define B43legacy_MMIO_REV3PLUS_TSF_HIGH    0x184 /* core rev >= 3 only */
0057 #define B43legacy_MMIO_TSF_CFP_REP  0x188
0058 #define B43legacy_MMIO_TSF_CFP_START    0x18C
0059 /* 32-bit DMA */
0060 #define B43legacy_MMIO_DMA32_BASE0  0x200
0061 #define B43legacy_MMIO_DMA32_BASE1  0x220
0062 #define B43legacy_MMIO_DMA32_BASE2  0x240
0063 #define B43legacy_MMIO_DMA32_BASE3  0x260
0064 #define B43legacy_MMIO_DMA32_BASE4  0x280
0065 #define B43legacy_MMIO_DMA32_BASE5  0x2A0
0066 /* 64-bit DMA */
0067 #define B43legacy_MMIO_DMA64_BASE0  0x200
0068 #define B43legacy_MMIO_DMA64_BASE1  0x240
0069 #define B43legacy_MMIO_DMA64_BASE2  0x280
0070 #define B43legacy_MMIO_DMA64_BASE3  0x2C0
0071 #define B43legacy_MMIO_DMA64_BASE4  0x300
0072 #define B43legacy_MMIO_DMA64_BASE5  0x340
0073 /* PIO */
0074 #define B43legacy_MMIO_PIO1_BASE        0x300
0075 #define B43legacy_MMIO_PIO2_BASE        0x310
0076 #define B43legacy_MMIO_PIO3_BASE        0x320
0077 #define B43legacy_MMIO_PIO4_BASE        0x330
0078 
0079 #define B43legacy_MMIO_PHY_VER      0x3E0
0080 #define B43legacy_MMIO_PHY_RADIO        0x3E2
0081 #define B43legacy_MMIO_PHY0     0x3E6
0082 #define B43legacy_MMIO_ANTENNA      0x3E8
0083 #define B43legacy_MMIO_CHANNEL      0x3F0
0084 #define B43legacy_MMIO_CHANNEL_EXT  0x3F4
0085 #define B43legacy_MMIO_RADIO_CONTROL    0x3F6
0086 #define B43legacy_MMIO_RADIO_DATA_HIGH  0x3F8
0087 #define B43legacy_MMIO_RADIO_DATA_LOW   0x3FA
0088 #define B43legacy_MMIO_PHY_CONTROL  0x3FC
0089 #define B43legacy_MMIO_PHY_DATA     0x3FE
0090 #define B43legacy_MMIO_MACFILTER_CONTROL    0x420
0091 #define B43legacy_MMIO_MACFILTER_DATA   0x422
0092 #define B43legacy_MMIO_RCMTA_COUNT  0x43C /* Receive Match Transmitter Addr */
0093 #define B43legacy_MMIO_RADIO_HWENABLED_LO   0x49A
0094 #define B43legacy_MMIO_GPIO_CONTROL 0x49C
0095 #define B43legacy_MMIO_GPIO_MASK        0x49E
0096 #define B43legacy_MMIO_TSF_CFP_PRETBTT  0x612
0097 #define B43legacy_MMIO_TSF_0        0x632 /* core rev < 3 only */
0098 #define B43legacy_MMIO_TSF_1        0x634 /* core rev < 3 only */
0099 #define B43legacy_MMIO_TSF_2        0x636 /* core rev < 3 only */
0100 #define B43legacy_MMIO_TSF_3        0x638 /* core rev < 3 only */
0101 #define B43legacy_MMIO_RNG      0x65A
0102 #define B43legacy_MMIO_POWERUP_DELAY    0x6A8
0103 
0104 /* SPROM boardflags_lo values */
0105 #define B43legacy_BFL_PACTRL        0x0002
0106 #define B43legacy_BFL_RSSI      0x0008
0107 #define B43legacy_BFL_EXTLNA        0x1000
0108 
0109 /* GPIO register offset, in both ChipCommon and PCI core. */
0110 #define B43legacy_GPIO_CONTROL      0x6c
0111 
0112 /* SHM Routing */
0113 #define B43legacy_SHM_SHARED        0x0001
0114 #define B43legacy_SHM_WIRELESS      0x0002
0115 #define B43legacy_SHM_HW        0x0004
0116 #define B43legacy_SHM_UCODE     0x0300
0117 
0118 /* SHM Routing modifiers */
0119 #define B43legacy_SHM_AUTOINC_R     0x0200 /* Read Auto-increment */
0120 #define B43legacy_SHM_AUTOINC_W     0x0100 /* Write Auto-increment */
0121 #define B43legacy_SHM_AUTOINC_RW    (B43legacy_SHM_AUTOINC_R | \
0122                      B43legacy_SHM_AUTOINC_W)
0123 
0124 /* Misc SHM_SHARED offsets */
0125 #define B43legacy_SHM_SH_WLCOREREV  0x0016 /* 802.11 core revision */
0126 #define B43legacy_SHM_SH_HOSTFLO    0x005E /* Hostflags ucode opts (low) */
0127 #define B43legacy_SHM_SH_HOSTFHI    0x0060 /* Hostflags ucode opts (high) */
0128 /* SHM_SHARED crypto engine */
0129 #define B43legacy_SHM_SH_KEYIDXBLOCK    0x05D4 /* Key index/algorithm block */
0130 /* SHM_SHARED beacon/AP variables */
0131 #define B43legacy_SHM_SH_DTIMP      0x0012 /* DTIM period */
0132 #define B43legacy_SHM_SH_BTL0       0x0018 /* Beacon template length 0 */
0133 #define B43legacy_SHM_SH_BTL1       0x001A /* Beacon template length 1 */
0134 #define B43legacy_SHM_SH_BTSFOFF    0x001C /* Beacon TSF offset */
0135 #define B43legacy_SHM_SH_TIMPOS     0x001E /* TIM position in beacon */
0136 #define B43legacy_SHM_SH_BEACPHYCTL 0x0054 /* Beacon PHY TX control word */
0137 /* SHM_SHARED ACK/CTS control */
0138 #define B43legacy_SHM_SH_ACKCTSPHYCTL   0x0022 /* ACK/CTS PHY control word */
0139 /* SHM_SHARED probe response variables */
0140 #define B43legacy_SHM_SH_PRTLEN     0x004A /* Probe Response template length */
0141 #define B43legacy_SHM_SH_PRMAXTIME  0x0074 /* Probe Response max time */
0142 #define B43legacy_SHM_SH_PRPHYCTL   0x0188 /* Probe Resp PHY TX control */
0143 /* SHM_SHARED rate tables */
0144 #define B43legacy_SHM_SH_OFDMDIRECT 0x0480 /* Pointer to OFDM direct map */
0145 #define B43legacy_SHM_SH_OFDMBASIC  0x04A0 /* Pointer to OFDM basic rate map */
0146 #define B43legacy_SHM_SH_CCKDIRECT  0x04C0 /* Pointer to CCK direct map */
0147 #define B43legacy_SHM_SH_CCKBASIC   0x04E0 /* Pointer to CCK basic rate map */
0148 /* SHM_SHARED microcode soft registers */
0149 #define B43legacy_SHM_SH_UCODEREV   0x0000 /* Microcode revision */
0150 #define B43legacy_SHM_SH_UCODEPATCH 0x0002 /* Microcode patchlevel */
0151 #define B43legacy_SHM_SH_UCODEDATE  0x0004 /* Microcode date */
0152 #define B43legacy_SHM_SH_UCODETIME  0x0006 /* Microcode time */
0153 #define B43legacy_SHM_SH_SPUWKUP    0x0094 /* pre-wakeup for synth PU in us */
0154 #define B43legacy_SHM_SH_PRETBTT    0x0096 /* pre-TBTT in us */
0155 
0156 #define B43legacy_UCODEFLAGS_OFFSET     0x005E
0157 
0158 /* Hardware Radio Enable masks */
0159 #define B43legacy_MMIO_RADIO_HWENABLED_HI_MASK (1 << 16)
0160 #define B43legacy_MMIO_RADIO_HWENABLED_LO_MASK (1 << 4)
0161 
0162 /* HostFlags. See b43legacy_hf_read/write() */
0163 #define B43legacy_HF_SYMW       0x00000002 /* G-PHY SYM workaround */
0164 #define B43legacy_HF_GDCW       0x00000020 /* G-PHY DV cancel filter */
0165 #define B43legacy_HF_OFDMPABOOST    0x00000040 /* Enable PA boost OFDM */
0166 #define B43legacy_HF_EDCF       0x00000100 /* on if WME/MAC suspended */
0167 
0168 /* MacFilter offsets. */
0169 #define B43legacy_MACFILTER_SELF    0x0000
0170 #define B43legacy_MACFILTER_BSSID   0x0003
0171 #define B43legacy_MACFILTER_MAC     0x0010
0172 
0173 /* PHYVersioning */
0174 #define B43legacy_PHYTYPE_B     0x01
0175 #define B43legacy_PHYTYPE_G     0x02
0176 
0177 /* PHYRegisters */
0178 #define B43legacy_PHY_G_LO_CONTROL  0x0810
0179 #define B43legacy_PHY_ILT_G_CTRL    0x0472
0180 #define B43legacy_PHY_ILT_G_DATA1   0x0473
0181 #define B43legacy_PHY_ILT_G_DATA2   0x0474
0182 #define B43legacy_PHY_G_PCTL        0x0029
0183 #define B43legacy_PHY_RADIO_BITFIELD    0x0401
0184 #define B43legacy_PHY_G_CRS     0x0429
0185 #define B43legacy_PHY_NRSSILT_CTRL  0x0803
0186 #define B43legacy_PHY_NRSSILT_DATA  0x0804
0187 
0188 /* RadioRegisters */
0189 #define B43legacy_RADIOCTL_ID       0x01
0190 
0191 /* MAC Control bitfield */
0192 #define B43legacy_MACCTL_ENABLED    0x00000001 /* MAC Enabled */
0193 #define B43legacy_MACCTL_PSM_RUN    0x00000002 /* Run Microcode */
0194 #define B43legacy_MACCTL_PSM_JMP0   0x00000004 /* Microcode jump to 0 */
0195 #define B43legacy_MACCTL_SHM_ENABLED    0x00000100 /* SHM Enabled */
0196 #define B43legacy_MACCTL_IHR_ENABLED    0x00000400 /* IHR Region Enabled */
0197 #define B43legacy_MACCTL_BE     0x00010000 /* Big Endian mode */
0198 #define B43legacy_MACCTL_INFRA      0x00020000 /* Infrastructure mode */
0199 #define B43legacy_MACCTL_AP     0x00040000 /* AccessPoint mode */
0200 #define B43legacy_MACCTL_RADIOLOCK  0x00080000 /* Radio lock */
0201 #define B43legacy_MACCTL_BEACPROMISC    0x00100000 /* Beacon Promiscuous */
0202 #define B43legacy_MACCTL_KEEP_BADPLCP   0x00200000 /* Keep bad PLCP frames */
0203 #define B43legacy_MACCTL_KEEP_CTL   0x00400000 /* Keep control frames */
0204 #define B43legacy_MACCTL_KEEP_BAD   0x00800000 /* Keep bad frames (FCS) */
0205 #define B43legacy_MACCTL_PROMISC    0x01000000 /* Promiscuous mode */
0206 #define B43legacy_MACCTL_HWPS       0x02000000 /* Hardware Power Saving */
0207 #define B43legacy_MACCTL_AWAKE      0x04000000 /* Device is awake */
0208 #define B43legacy_MACCTL_TBTTHOLD   0x10000000 /* TBTT Hold */
0209 #define B43legacy_MACCTL_GMODE      0x80000000 /* G Mode */
0210 
0211 /* MAC Command bitfield */
0212 #define B43legacy_MACCMD_BEACON0_VALID  0x00000001 /* Beacon 0 in template RAM is busy/valid */
0213 #define B43legacy_MACCMD_BEACON1_VALID  0x00000002 /* Beacon 1 in template RAM is busy/valid */
0214 #define B43legacy_MACCMD_DFQ_VALID  0x00000004 /* Directed frame queue valid (IBSS PS mode, ATIM) */
0215 #define B43legacy_MACCMD_CCA        0x00000008 /* Clear channel assessment */
0216 #define B43legacy_MACCMD_BGNOISE    0x00000010 /* Background noise */
0217 
0218 /* 802.11 core specific TM State Low flags */
0219 #define B43legacy_TMSLOW_GMODE      0x20000000 /* G Mode Enable */
0220 #define B43legacy_TMSLOW_PLLREFSEL  0x00200000 /* PLL Freq Ref Select */
0221 #define B43legacy_TMSLOW_MACPHYCLKEN    0x00100000 /* MAC PHY Clock Ctrl Enbl */
0222 #define B43legacy_TMSLOW_PHYRESET   0x00080000 /* PHY Reset */
0223 #define B43legacy_TMSLOW_PHYCLKEN   0x00040000 /* PHY Clock Enable */
0224 
0225 /* 802.11 core specific TM State High flags */
0226 #define B43legacy_TMSHIGH_FCLOCK    0x00040000 /* Fast Clock Available */
0227 #define B43legacy_TMSHIGH_GPHY      0x00010000 /* G-PHY avail (rev >= 5) */
0228 
0229 #define B43legacy_UCODEFLAG_AUTODIV       0x0001
0230 
0231 /* Generic-Interrupt reasons. */
0232 #define B43legacy_IRQ_MAC_SUSPENDED 0x00000001
0233 #define B43legacy_IRQ_BEACON        0x00000002
0234 #define B43legacy_IRQ_TBTT_INDI     0x00000004 /* Target Beacon Transmit Time */
0235 #define B43legacy_IRQ_BEACON_TX_OK  0x00000008
0236 #define B43legacy_IRQ_BEACON_CANCEL 0x00000010
0237 #define B43legacy_IRQ_ATIM_END      0x00000020
0238 #define B43legacy_IRQ_PMQ       0x00000040
0239 #define B43legacy_IRQ_PIO_WORKAROUND    0x00000100
0240 #define B43legacy_IRQ_MAC_TXERR     0x00000200
0241 #define B43legacy_IRQ_PHY_TXERR     0x00000800
0242 #define B43legacy_IRQ_PMEVENT       0x00001000
0243 #define B43legacy_IRQ_TIMER0        0x00002000
0244 #define B43legacy_IRQ_TIMER1        0x00004000
0245 #define B43legacy_IRQ_DMA       0x00008000
0246 #define B43legacy_IRQ_TXFIFO_FLUSH_OK   0x00010000
0247 #define B43legacy_IRQ_CCA_MEASURE_OK    0x00020000
0248 #define B43legacy_IRQ_NOISESAMPLE_OK    0x00040000
0249 #define B43legacy_IRQ_UCODE_DEBUG   0x08000000
0250 #define B43legacy_IRQ_RFKILL        0x10000000
0251 #define B43legacy_IRQ_TX_OK     0x20000000
0252 #define B43legacy_IRQ_PHY_G_CHANGED 0x40000000
0253 #define B43legacy_IRQ_TIMEOUT       0x80000000
0254 
0255 #define B43legacy_IRQ_ALL       0xFFFFFFFF
0256 #define B43legacy_IRQ_MASKTEMPLATE  (B43legacy_IRQ_MAC_SUSPENDED |  \
0257                      B43legacy_IRQ_TBTT_INDI |  \
0258                      B43legacy_IRQ_ATIM_END |   \
0259                      B43legacy_IRQ_PMQ |        \
0260                      B43legacy_IRQ_MAC_TXERR |  \
0261                      B43legacy_IRQ_PHY_TXERR |  \
0262                      B43legacy_IRQ_DMA |        \
0263                      B43legacy_IRQ_TXFIFO_FLUSH_OK | \
0264                      B43legacy_IRQ_NOISESAMPLE_OK | \
0265                      B43legacy_IRQ_UCODE_DEBUG |    \
0266                      B43legacy_IRQ_RFKILL |     \
0267                      B43legacy_IRQ_TX_OK)
0268 
0269 /* Device specific rate values.
0270  * The actual values defined here are (rate_in_mbps * 2).
0271  * Some code depends on this. Don't change it. */
0272 #define B43legacy_CCK_RATE_1MB      2
0273 #define B43legacy_CCK_RATE_2MB      4
0274 #define B43legacy_CCK_RATE_5MB      11
0275 #define B43legacy_CCK_RATE_11MB     22
0276 #define B43legacy_OFDM_RATE_6MB     12
0277 #define B43legacy_OFDM_RATE_9MB     18
0278 #define B43legacy_OFDM_RATE_12MB    24
0279 #define B43legacy_OFDM_RATE_18MB    36
0280 #define B43legacy_OFDM_RATE_24MB    48
0281 #define B43legacy_OFDM_RATE_36MB    72
0282 #define B43legacy_OFDM_RATE_48MB    96
0283 #define B43legacy_OFDM_RATE_54MB    108
0284 /* Convert a b43legacy rate value to a rate in 100kbps */
0285 #define B43legacy_RATE_TO_100KBPS(rate) (((rate) * 10) / 2)
0286 
0287 
0288 #define B43legacy_DEFAULT_SHORT_RETRY_LIMIT 7
0289 #define B43legacy_DEFAULT_LONG_RETRY_LIMIT  4
0290 
0291 #define B43legacy_PHY_TX_BADNESS_LIMIT      1000
0292 
0293 /* Max size of a security key */
0294 #define B43legacy_SEC_KEYSIZE       16
0295 /* Security algorithms. */
0296 enum {
0297     B43legacy_SEC_ALGO_NONE = 0, /* unencrypted, as of TX header. */
0298     B43legacy_SEC_ALGO_WEP40,
0299     B43legacy_SEC_ALGO_TKIP,
0300     B43legacy_SEC_ALGO_AES,
0301     B43legacy_SEC_ALGO_WEP104,
0302     B43legacy_SEC_ALGO_AES_LEGACY,
0303 };
0304 
0305 /* Core Information Registers */
0306 #define B43legacy_CIR_BASE                0xf00
0307 #define B43legacy_CIR_SBTPSFLAG           (B43legacy_CIR_BASE + 0x18)
0308 #define B43legacy_CIR_SBIMSTATE           (B43legacy_CIR_BASE + 0x90)
0309 #define B43legacy_CIR_SBINTVEC            (B43legacy_CIR_BASE + 0x94)
0310 #define B43legacy_CIR_SBTMSTATELOW        (B43legacy_CIR_BASE + 0x98)
0311 #define B43legacy_CIR_SBTMSTATEHIGH       (B43legacy_CIR_BASE + 0x9c)
0312 #define B43legacy_CIR_SBIMCONFIGLOW       (B43legacy_CIR_BASE + 0xa8)
0313 #define B43legacy_CIR_SB_ID_HI            (B43legacy_CIR_BASE + 0xfc)
0314 
0315 /* sbtmstatehigh state flags */
0316 #define B43legacy_SBTMSTATEHIGH_SERROR      0x00000001
0317 #define B43legacy_SBTMSTATEHIGH_BUSY        0x00000004
0318 #define B43legacy_SBTMSTATEHIGH_TIMEOUT     0x00000020
0319 #define B43legacy_SBTMSTATEHIGH_G_PHY_AVAIL 0x00010000
0320 #define B43legacy_SBTMSTATEHIGH_COREFLAGS   0x1FFF0000
0321 #define B43legacy_SBTMSTATEHIGH_DMA64BIT    0x10000000
0322 #define B43legacy_SBTMSTATEHIGH_GATEDCLK    0x20000000
0323 #define B43legacy_SBTMSTATEHIGH_BISTFAILED  0x40000000
0324 #define B43legacy_SBTMSTATEHIGH_BISTCOMPLETE    0x80000000
0325 
0326 /* sbimstate flags */
0327 #define B43legacy_SBIMSTATE_IB_ERROR        0x20000
0328 #define B43legacy_SBIMSTATE_TIMEOUT     0x40000
0329 
0330 #define PFX     KBUILD_MODNAME ": "
0331 #ifdef assert
0332 # undef assert
0333 #endif
0334 #ifdef CONFIG_B43LEGACY_DEBUG
0335 # define B43legacy_WARN_ON(x)   WARN_ON(x)
0336 # define B43legacy_BUG_ON(expr)                     \
0337     do {                                \
0338         if (unlikely((expr))) {                 \
0339             printk(KERN_INFO PFX "Test (%s) failed\n",  \
0340                           #expr);           \
0341             BUG_ON(expr);                   \
0342         }                           \
0343     } while (0)
0344 # define B43legacy_DEBUG    1
0345 #else
0346 /* This will evaluate the argument even if debugging is disabled. */
0347 static inline bool __b43legacy_warn_on_dummy(bool x) { return x; }
0348 # define B43legacy_WARN_ON(x)   __b43legacy_warn_on_dummy(unlikely(!!(x)))
0349 # define B43legacy_BUG_ON(x)    do { /* nothing */ } while (0)
0350 # define B43legacy_DEBUG    0
0351 #endif
0352 
0353 
0354 struct net_device;
0355 struct pci_dev;
0356 struct b43legacy_dmaring;
0357 struct b43legacy_pioqueue;
0358 
0359 /* The firmware file header */
0360 #define B43legacy_FW_TYPE_UCODE 'u'
0361 #define B43legacy_FW_TYPE_PCM   'p'
0362 #define B43legacy_FW_TYPE_IV    'i'
0363 struct b43legacy_fw_header {
0364     /* File type */
0365     u8 type;
0366     /* File format version */
0367     u8 ver;
0368     u8 __padding[2];
0369     /* Size of the data. For ucode and PCM this is in bytes.
0370      * For IV this is number-of-ivs. */
0371     __be32 size;
0372 } __packed;
0373 
0374 /* Initial Value file format */
0375 #define B43legacy_IV_OFFSET_MASK    0x7FFF
0376 #define B43legacy_IV_32BIT      0x8000
0377 struct b43legacy_iv {
0378     __be16 offset_size;
0379     union {
0380         __be16 d16;
0381         __be32 d32;
0382     } data __packed;
0383 } __packed;
0384 
0385 #define B43legacy_PHYMODE(phytype)  (1 << (phytype))
0386 #define B43legacy_PHYMODE_B     B43legacy_PHYMODE   \
0387                     ((B43legacy_PHYTYPE_B))
0388 #define B43legacy_PHYMODE_G     B43legacy_PHYMODE   \
0389                     ((B43legacy_PHYTYPE_G))
0390 
0391 /* Value pair to measure the LocalOscillator. */
0392 struct b43legacy_lopair {
0393     s8 low;
0394     s8 high;
0395     u8 used:1;
0396 };
0397 #define B43legacy_LO_COUNT  (14*4)
0398 
0399 struct b43legacy_phy {
0400     /* Possible PHYMODEs on this PHY */
0401     u8 possible_phymodes;
0402     /* GMODE bit enabled in MACCTL? */
0403     bool gmode;
0404 
0405     /* Analog Type */
0406     u8 analog;
0407     /* B43legacy_PHYTYPE_ */
0408     u8 type;
0409     /* PHY revision number. */
0410     u8 rev;
0411 
0412     u16 antenna_diversity;
0413     u16 savedpctlreg;
0414     /* Radio versioning */
0415     u16 radio_manuf;    /* Radio manufacturer */
0416     u16 radio_ver;      /* Radio version */
0417     u8 calibrated:1;
0418     u8 radio_rev;       /* Radio revision */
0419 
0420     bool dyn_tssi_tbl;  /* tssi2dbm is kmalloc()ed. */
0421 
0422     /* ACI (adjacent channel interference) flags. */
0423     bool aci_enable;
0424     bool aci_wlan_automatic;
0425     bool aci_hw_rssi;
0426 
0427     /* Radio switched on/off */
0428     bool radio_on;
0429     struct {
0430         /* Values saved when turning the radio off.
0431          * They are needed when turning it on again. */
0432         bool valid;
0433         u16 rfover;
0434         u16 rfoverval;
0435     } radio_off_context;
0436 
0437     u16 minlowsig[2];
0438     u16 minlowsigpos[2];
0439 
0440     /* LO Measurement Data.
0441      * Use b43legacy_get_lopair() to get a value.
0442      */
0443     struct b43legacy_lopair *_lo_pairs;
0444     /* TSSI to dBm table in use */
0445     const s8 *tssi2dbm;
0446     /* idle TSSI value */
0447     s8 idle_tssi;
0448     /* Target idle TSSI */
0449     int tgt_idle_tssi;
0450     /* Current idle TSSI */
0451     int cur_idle_tssi;
0452 
0453     /* LocalOscillator control values. */
0454     struct b43legacy_txpower_lo_control *lo_control;
0455     /* Values from b43legacy_calc_loopback_gain() */
0456     s16 max_lb_gain;    /* Maximum Loopback gain in hdB */
0457     s16 trsw_rx_gain;   /* TRSW RX gain in hdB */
0458     s16 lna_lod_gain;   /* LNA lod */
0459     s16 lna_gain;       /* LNA */
0460     s16 pga_gain;       /* PGA */
0461 
0462     /* Desired TX power level (in dBm). This is set by the user and
0463      * adjusted in b43legacy_phy_xmitpower(). */
0464     u8 power_level;
0465 
0466     /* Values from b43legacy_calc_loopback_gain() */
0467     u16 loopback_gain[2];
0468 
0469     /* TX Power control values. */
0470     /* B/G PHY */
0471     struct {
0472         /* Current Radio Attenuation for TXpower recalculation. */
0473         u16 rfatt;
0474         /* Current Baseband Attenuation for TXpower recalculation. */
0475         u16 bbatt;
0476         /* Current TXpower control value for TXpower recalculation. */
0477         u16 txctl1;
0478         u16 txctl2;
0479     };
0480     /* A PHY */
0481     struct {
0482         u16 txpwr_offset;
0483     };
0484 
0485     /* Current Interference Mitigation mode */
0486     int interfmode;
0487     /* Stack of saved values from the Interference Mitigation code.
0488      * Each value in the stack is laid out as follows:
0489      * bit 0-11:  offset
0490      * bit 12-15: register ID
0491      * bit 16-32: value
0492      * register ID is: 0x1 PHY, 0x2 Radio, 0x3 ILT
0493      */
0494 #define B43legacy_INTERFSTACK_SIZE  26
0495     u32 interfstack[B43legacy_INTERFSTACK_SIZE];
0496 
0497     /* Saved values from the NRSSI Slope calculation */
0498     s16 nrssi[2];
0499     s32 nrssislope;
0500     /* In memory nrssi lookup table. */
0501     s8 nrssi_lt[64];
0502 
0503     /* current channel */
0504     u8 channel;
0505 
0506     u16 lofcal;
0507 
0508     u16 initval;
0509 
0510     /* PHY TX errors counter. */
0511     atomic_t txerr_cnt;
0512 
0513 #if B43legacy_DEBUG
0514     /* Manual TX-power control enabled? */
0515     bool manual_txpower_control;
0516     /* PHY registers locked by b43legacy_phy_lock()? */
0517     bool phy_locked;
0518 #endif /* B43legacy_DEBUG */
0519 };
0520 
0521 /* Data structures for DMA transmission, per 80211 core. */
0522 struct b43legacy_dma {
0523     struct b43legacy_dmaring *tx_ring0;
0524     struct b43legacy_dmaring *tx_ring1;
0525     struct b43legacy_dmaring *tx_ring2;
0526     struct b43legacy_dmaring *tx_ring3;
0527     struct b43legacy_dmaring *tx_ring4;
0528     struct b43legacy_dmaring *tx_ring5;
0529 
0530     struct b43legacy_dmaring *rx_ring0;
0531     struct b43legacy_dmaring *rx_ring3; /* only on core.rev < 5 */
0532 
0533     u32 translation; /* Routing bits */
0534 };
0535 
0536 /* Data structures for PIO transmission, per 80211 core. */
0537 struct b43legacy_pio {
0538     struct b43legacy_pioqueue *queue0;
0539     struct b43legacy_pioqueue *queue1;
0540     struct b43legacy_pioqueue *queue2;
0541     struct b43legacy_pioqueue *queue3;
0542 };
0543 
0544 /* Context information for a noise calculation (Link Quality). */
0545 struct b43legacy_noise_calculation {
0546     u8 channel_at_start;
0547     bool calculation_running;
0548     u8 nr_samples;
0549     s8 samples[8][4];
0550 };
0551 
0552 struct b43legacy_stats {
0553     u8 link_noise;
0554     /* Store the last TX/RX times here for updating the leds. */
0555     unsigned long last_tx;
0556     unsigned long last_rx;
0557 };
0558 
0559 struct b43legacy_key {
0560     void *keyconf;
0561     bool enabled;
0562     u8 algorithm;
0563 };
0564 
0565 #define B43legacy_QOS_QUEUE_NUM 4
0566 
0567 struct b43legacy_wldev;
0568 
0569 /* QOS parameters for a queue. */
0570 struct b43legacy_qos_params {
0571     /* The QOS parameters */
0572     struct ieee80211_tx_queue_params p;
0573 };
0574 
0575 /* Data structure for the WLAN parts (802.11 cores) of the b43legacy chip. */
0576 struct b43legacy_wl {
0577     /* Pointer to the active wireless device on this chip */
0578     struct b43legacy_wldev *current_dev;
0579     /* Pointer to the ieee80211 hardware data structure */
0580     struct ieee80211_hw *hw;
0581 
0582     spinlock_t irq_lock;        /* locks IRQ */
0583     struct mutex mutex;     /* locks wireless core state */
0584     spinlock_t leds_lock;       /* lock for leds */
0585 
0586     /* firmware loading work */
0587     struct work_struct firmware_load;
0588 
0589     /* We can only have one operating interface (802.11 core)
0590      * at a time. General information about this interface follows.
0591      */
0592 
0593     struct ieee80211_vif *vif;
0594     /* MAC address (can be NULL). */
0595     u8 mac_addr[ETH_ALEN];
0596     /* Current BSSID (can be NULL). */
0597     u8 bssid[ETH_ALEN];
0598     /* Interface type. (IEEE80211_IF_TYPE_XXX) */
0599     int if_type;
0600     /* Is the card operating in AP, STA or IBSS mode? */
0601     bool operating;
0602     /* filter flags */
0603     unsigned int filter_flags;
0604     /* Stats about the wireless interface */
0605     struct ieee80211_low_level_stats ieee_stats;
0606 
0607 #ifdef CONFIG_B43LEGACY_HWRNG
0608     struct hwrng rng;
0609     u8 rng_initialized;
0610     char rng_name[30 + 1];
0611 #endif
0612 
0613     /* List of all wireless devices on this chip */
0614     struct list_head devlist;
0615     u8 nr_devs;
0616 
0617     bool radiotap_enabled;
0618     bool radio_enabled;
0619 
0620     /* The beacon we are currently using (AP or IBSS mode).
0621      * This beacon stuff is protected by the irq_lock. */
0622     struct sk_buff *current_beacon;
0623     bool beacon0_uploaded;
0624     bool beacon1_uploaded;
0625     bool beacon_templates_virgin; /* Never wrote the templates? */
0626     struct work_struct beacon_update_trigger;
0627     /* The current QOS parameters for the 4 queues. */
0628     struct b43legacy_qos_params qos_params[B43legacy_QOS_QUEUE_NUM];
0629 
0630     /* Packet transmit work */
0631     struct work_struct tx_work;
0632 
0633     /* Queue of packets to be transmitted. */
0634     struct sk_buff_head tx_queue[B43legacy_QOS_QUEUE_NUM];
0635 
0636     /* Flag that implement the queues stopping. */
0637     bool tx_queue_stopped[B43legacy_QOS_QUEUE_NUM];
0638 
0639 };
0640 
0641 /* Pointers to the firmware data and meta information about it. */
0642 struct b43legacy_firmware {
0643     /* Microcode */
0644     const struct firmware *ucode;
0645     /* PCM code */
0646     const struct firmware *pcm;
0647     /* Initial MMIO values for the firmware */
0648     const struct firmware *initvals;
0649     /* Initial MMIO values for the firmware, band-specific */
0650     const struct firmware *initvals_band;
0651     /* Firmware revision */
0652     u16 rev;
0653     /* Firmware patchlevel */
0654     u16 patch;
0655 };
0656 
0657 /* Device (802.11 core) initialization status. */
0658 enum {
0659     B43legacy_STAT_UNINIT       = 0, /* Uninitialized. */
0660     B43legacy_STAT_INITIALIZED  = 1, /* Initialized, not yet started. */
0661     B43legacy_STAT_STARTED  = 2, /* Up and running. */
0662 };
0663 #define b43legacy_status(wldev) atomic_read(&(wldev)->__init_status)
0664 #define b43legacy_set_status(wldev, stat)   do {        \
0665         atomic_set(&(wldev)->__init_status, (stat));    \
0666         smp_wmb();                  \
0667                     } while (0)
0668 
0669 /* *** ---   HOW LOCKING WORKS IN B43legacy   --- ***
0670  *
0671  * You should always acquire both, wl->mutex and wl->irq_lock unless:
0672  * - You don't need to acquire wl->irq_lock, if the interface is stopped.
0673  * - You don't need to acquire wl->mutex in the IRQ handler, IRQ tasklet
0674  *   and packet TX path (and _ONLY_ there.)
0675  */
0676 
0677 /* Data structure for one wireless device (802.11 core) */
0678 struct b43legacy_wldev {
0679     struct ssb_device *dev;
0680     struct b43legacy_wl *wl;
0681 
0682     /* The device initialization status.
0683      * Use b43legacy_status() to query. */
0684     atomic_t __init_status;
0685     /* Saved init status for handling suspend. */
0686     int suspend_init_status;
0687 
0688     bool __using_pio;   /* Using pio rather than dma. */
0689     bool bad_frames_preempt;/* Use "Bad Frames Preemption". */
0690     bool dfq_valid;     /* Directed frame queue valid (IBSS PS mode, ATIM). */
0691     bool short_preamble;    /* TRUE if using short preamble. */
0692     bool radio_hw_enable;   /* State of radio hardware enable bit. */
0693 
0694     /* PHY/Radio device. */
0695     struct b43legacy_phy phy;
0696     union {
0697         /* DMA engines. */
0698         struct b43legacy_dma dma;
0699         /* PIO engines. */
0700         struct b43legacy_pio pio;
0701     };
0702 
0703     /* Various statistics about the physical device. */
0704     struct b43legacy_stats stats;
0705 
0706     /* The device LEDs. */
0707     struct b43legacy_led led_tx;
0708     struct b43legacy_led led_rx;
0709     struct b43legacy_led led_assoc;
0710     struct b43legacy_led led_radio;
0711 
0712     /* Reason code of the last interrupt. */
0713     u32 irq_reason;
0714     u32 dma_reason[6];
0715     /* The currently active generic-interrupt mask. */
0716     u32 irq_mask;
0717     /* Link Quality calculation context. */
0718     struct b43legacy_noise_calculation noisecalc;
0719     /* if > 0 MAC is suspended. if == 0 MAC is enabled. */
0720     int mac_suspended;
0721 
0722     /* Interrupt Service Routine tasklet (bottom-half) */
0723     struct tasklet_struct isr_tasklet;
0724 
0725     /* Periodic tasks */
0726     struct delayed_work periodic_work;
0727     unsigned int periodic_state;
0728 
0729     struct work_struct restart_work;
0730 
0731     /* encryption/decryption */
0732     u16 ktp; /* Key table pointer */
0733     u8 max_nr_keys;
0734     struct b43legacy_key key[58];
0735 
0736     /* Firmware data */
0737     struct b43legacy_firmware fw;
0738     const struct firmware *fwp; /* needed to pass fw pointer */
0739 
0740     /* completion struct for firmware loading */
0741     struct completion fw_load_complete;
0742 
0743     /* Devicelist in struct b43legacy_wl (all 802.11 cores) */
0744     struct list_head list;
0745 
0746     /* Debugging stuff follows. */
0747 #ifdef CONFIG_B43LEGACY_DEBUG
0748     struct b43legacy_dfsentry *dfsentry;
0749 #endif
0750 };
0751 
0752 
0753 static inline
0754 struct b43legacy_wl *hw_to_b43legacy_wl(struct ieee80211_hw *hw)
0755 {
0756     return hw->priv;
0757 }
0758 
0759 /* Helper function, which returns a boolean.
0760  * TRUE, if PIO is used; FALSE, if DMA is used.
0761  */
0762 #if defined(CONFIG_B43LEGACY_DMA) && defined(CONFIG_B43LEGACY_PIO)
0763 static inline
0764 int b43legacy_using_pio(struct b43legacy_wldev *dev)
0765 {
0766     return dev->__using_pio;
0767 }
0768 #elif defined(CONFIG_B43LEGACY_DMA)
0769 static inline
0770 int b43legacy_using_pio(struct b43legacy_wldev *dev)
0771 {
0772     return 0;
0773 }
0774 #elif defined(CONFIG_B43LEGACY_PIO)
0775 static inline
0776 int b43legacy_using_pio(struct b43legacy_wldev *dev)
0777 {
0778     return 1;
0779 }
0780 #else
0781 # error "Using neither DMA nor PIO? Confused..."
0782 #endif
0783 
0784 
0785 static inline
0786 struct b43legacy_wldev *dev_to_b43legacy_wldev(struct device *dev)
0787 {
0788     struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
0789     return ssb_get_drvdata(ssb_dev);
0790 }
0791 
0792 /* Is the device operating in a specified mode (IEEE80211_IF_TYPE_XXX). */
0793 static inline
0794 int b43legacy_is_mode(struct b43legacy_wl *wl, int type)
0795 {
0796     return (wl->operating &&
0797         wl->if_type == type);
0798 }
0799 
0800 static inline
0801 bool is_bcm_board_vendor(struct b43legacy_wldev *dev)
0802 {
0803     return  (dev->dev->bus->boardinfo.vendor == PCI_VENDOR_ID_BROADCOM);
0804 }
0805 
0806 static inline
0807 u16 b43legacy_read16(struct b43legacy_wldev *dev, u16 offset)
0808 {
0809     return ssb_read16(dev->dev, offset);
0810 }
0811 
0812 static inline
0813 void b43legacy_write16(struct b43legacy_wldev *dev, u16 offset, u16 value)
0814 {
0815     ssb_write16(dev->dev, offset, value);
0816 }
0817 
0818 static inline
0819 u32 b43legacy_read32(struct b43legacy_wldev *dev, u16 offset)
0820 {
0821     return ssb_read32(dev->dev, offset);
0822 }
0823 
0824 static inline
0825 void b43legacy_write32(struct b43legacy_wldev *dev, u16 offset, u32 value)
0826 {
0827     ssb_write32(dev->dev, offset, value);
0828 }
0829 
0830 static inline
0831 struct b43legacy_lopair *b43legacy_get_lopair(struct b43legacy_phy *phy,
0832                           u16 radio_attenuation,
0833                           u16 baseband_attenuation)
0834 {
0835     return phy->_lo_pairs + (radio_attenuation
0836             + 14 * (baseband_attenuation / 2));
0837 }
0838 
0839 
0840 
0841 /* Message printing */
0842 __printf(2, 3)
0843 void b43legacyinfo(struct b43legacy_wl *wl, const char *fmt, ...);
0844 __printf(2, 3)
0845 void b43legacyerr(struct b43legacy_wl *wl, const char *fmt, ...);
0846 __printf(2, 3)
0847 void b43legacywarn(struct b43legacy_wl *wl, const char *fmt, ...);
0848 #if B43legacy_DEBUG
0849 __printf(2, 3)
0850 void b43legacydbg(struct b43legacy_wl *wl, const char *fmt, ...);
0851 #else /* DEBUG */
0852 # define b43legacydbg(wl, fmt...) do { /* nothing */ } while (0)
0853 #endif /* DEBUG */
0854 
0855 /* Macros for printing a value in Q5.2 format */
0856 #define Q52_FMT     "%u.%u"
0857 #define Q52_ARG(q52)    ((q52) / 4), (((q52) & 3) * 100 / 4)
0858 
0859 #endif /* B43legacy_H_ */