#ifndef _BIT_TWIDDLE
#define _BIT_TWIDDLE
#define LOWEST_SET_BIT(x) ((((x) - 1) & (x)) ^ (x))
#define GTEQ_POWER(x, p) (((u_long)(x) >> (p)) != 0)
#define MASK_TO_SHIFT2(m) (GTEQ_POWER(LOWEST_SET_BIT((m)), 1) ? 1 : 0)
#define MASK_TO_SHIFT4(m) \
(GTEQ_POWER(LOWEST_SET_BIT((m)), 2) \
? 2 + MASK_TO_SHIFT2((m) >> 2) \
: MASK_TO_SHIFT2((m)))
#define MASK_TO_SHIFT8(m) \
(GTEQ_POWER(LOWEST_SET_BIT((m)), 4) \
? 4 + MASK_TO_SHIFT4((m) >> 4) \
: MASK_TO_SHIFT4((m)))
#define MASK_TO_SHIFT16(m) \
(GTEQ_POWER(LOWEST_SET_BIT((m)), 8) \
? 8 + MASK_TO_SHIFT8((m) >> 8) \
: MASK_TO_SHIFT8((m)))
#define MASK_TO_SHIFT(m) \
(GTEQ_POWER(LOWEST_SET_BIT((m)), 16) \
? 16 + MASK_TO_SHIFT16((m) >> 16) \
: MASK_TO_SHIFT16((m)))
#define MASK_AND_RSHIFT(x, mask) (((x) & (mask)) >> MASK_TO_SHIFT(mask))
#define LSHIFT(x, mask) ((x) << MASK_TO_SHIFT(mask))
#define MASK_AND_REPLACE(reg, val, mask) ((reg & ~mask) | LSHIFT(val, mask))
#define PRESHIFT(m) MASK_AND_RSHIFT((m), (m))
#endif
#define RTW_IDR0 0x00
#define RTW_IDR1 0x04
#define RTW_MAR0 0x08
#define RTW_MAR1 0x0c
#define RTW_TSFTRL 0x18
#define RTW_TSFTRH 0x1c
#define RTW_TLPDA 0x20
#define RTW_TNPDA 0x24
#define RTW_THPDA 0x28
#define RTW_BRSR 0x2c
#define RTW8180_BRSR_BPLCP (1<<8)
#define RTW8180_BRSR_MBR_MASK 0x3
#define RTW8180_BRSR_MBR_1MBPS LSHIFT(0, RTW8180_BRSR_MBR_MASK)
#define RTW8180_BRSR_MBR_2MBPS LSHIFT(1, RTW8180_BRSR_MBR_MASK)
#define RTW8180_BRSR_MBR_5MBPS LSHIFT(2, RTW8180_BRSR_MBR_MASK)
#define RTW8180_BRSR_MBR_11MBPS LSHIFT(3, RTW8180_BRSR_MBR_MASK)
#define RTW8185_BRSR_MBR_MASK 0xfff
#define RTW8185_BRSR_MBR_1MBPS (1<<0)
#define RTW8185_BRSR_MBR_2MBPS (1<<1)
#define RTW8185_BRSR_MBR_5MBPS (1<<2)
#define RTW8185_BRSR_MBR_11MBPS (1<<3)
#define RTW8185_BRSR_MBR_6MBPS (1<<4)
#define RTW8185_BRSR_MBR_9MBPS (1<<5)
#define RTW8185_BRSR_MBR_12MBPS (1<<6)
#define RTW8185_BRSR_MBR_18MBPS (1<<7)
#define RTW8185_BRSR_MBR_24MBPS (1<<8)
#define RTW8185_BRSR_MBR_36MBPS (1<<9)
#define RTW8185_BRSR_MBR_48MBPS (1<<10)
#define RTW8185_BRSR_MBR_54MBPS (1<<11)
#define RTW_BSSID 0x2e
#define RTW_BSSID16 0x2e
#define RTW_BSSID32 (0x2e + 4)
#define RTW_BSSID0 RTW_BSSID16
#define RTW_BSSID1 (RTW_BSSID0 + 1)
#define RTW_BSSID2 (RTW_BSSID1 + 1)
#define RTW_BSSID3 (RTW_BSSID2 + 1)
#define RTW_BSSID4 (RTW_BSSID3 + 1)
#define RTW_BSSID5 (RTW_BSSID4 + 1)
#define RTW8185_RR 0x34
#define RTW8185_RR_MAX BIT(7, 4)
#define RTW8185_RR_MAX_1MPBS LSHIFT(0, RTW8185_RR_MAX_MASK)
#define RTW8185_RR_MAX_2MPBS LSHIFT(1, RTW8185_RR_MAX_MASK)
#define RTW8185_RR_MAX_5MPBS LSHIFT(2, RTW8185_RR_MAX_MASK)
#define RTW8185_RR_MAX_11MPBS LSHIFT(3, RTW8185_RR_MAX_MASK)
#define RTW8185_RR_MAX_6MPBS LSHIFT(4, RTW8185_RR_MAX_MASK)
#define RTW8185_RR_MAX_9MPBS LSHIFT(5, RTW8185_RR_MAX_MASK)
#define RTW8185_RR_MAX_12MPBS LSHIFT(6, RTW8185_RR_MAX_MASK)
#define RTW8185_RR_MAX_18MPBS LSHIFT(7, RTW8185_RR_MAX_MASK)
#define RTW8185_RR_MAX_24MPBS LSHIFT(8, RTW8185_RR_MAX_MASK)
#define RTW8185_RR_MAX_36MPBS LSHIFT(9, RTW8185_RR_MAX_MASK)
#define RTW8185_RR_MAX_48MPBS LSHIFT(10, RTW8185_RR_MAX_MASK)
#define RTW8185_RR_MAX_54MPBS LSHIFT(11, RTW8185_RR_MAX_MASK)
#define RTW8185_RR_MIN_MASK BIT(3, 0)
#define RTW8185_RR_MIN_1MPBS LSHIFT(0, RTW8185_RR_MIN_MASK)
#define RTW8185_RR_MIN_2MPBS LSHIFT(1, RTW8185_RR_MIN_MASK)
#define RTW8185_RR_MIN_5MPBS LSHIFT(2, RTW8185_RR_MIN_MASK)
#define RTW8185_RR_MIN_11MPBS LSHIFT(3, RTW8185_RR_MIN_MASK)
#define RTW8185_RR_MIN_6MPBS LSHIFT(4, RTW8185_RR_MIN_MASK)
#define RTW8185_RR_MIN_9MPBS LSHIFT(5, RTW8185_RR_MIN_MASK)
#define RTW8185_RR_MIN_12MPBS LSHIFT(6, RTW8185_RR_MIN_MASK)
#define RTW8185_RR_MIN_18MPBS LSHIFT(7, RTW8185_RR_MIN_MASK)
#define RTW8185_RR_MIN_24MPBS LSHIFT(8, RTW8185_RR_MIN_MASK)
#define RTW8185_RR_MIN_36MPBS LSHIFT(9, RTW8185_RR_MIN_MASK)
#define RTW8185_RR_MIN_48MPBS LSHIFT(10, RTW8185_RR_MIN_MASK)
#define RTW8185_RR_MIN_54MPBS LSHIFT(11, RTW8185_RR_MIN_MASK)
#define RTW8185_EIFS_TIMER 0x35
#define RTW_CR 0x37
#define RTW_CR_RST (1<<4)
#define RTW_CR_RE (1<<3)
#define RTW_CR_TE (1<<2)
#define RTW_CR_MULRW (1<<0)
#define RTW_IMR 0x3c
#define RTW_ISR 0x3e
#define RTW_INTR_TXFOVW (1<<15)
#define RTW_INTR_TIMEOUT (1<<14)
#define RTW_INTR_BCNINT (1<<13)
#define RTW_INTR_ATIMINT (1<<12)
#define RTW_INTR_TBDER (1<<11)
#define RTW_INTR_TBDOK (1<<10)
#define RTW_INTR_THPDER (1<<9)
#define RTW_INTR_THPDOK (1<<8)
#define RTW_INTR_TNPDER (1<<7)
#define RTW_INTR_TNPDOK (1<<6)
#define RTW_INTR_RXFOVW (1<<5)
#define RTW_INTR_RDU (1<<4)
#define RTW_INTR_TLPDER (1<<3)
#define RTW_INTR_TLPDOK (1<<2)
#define RTW_INTR_RER (1<<1)
#define RTW_INTR_ROK (1<<0)
#define RTW_INTR_RX (RTW_INTR_RER|RTW_INTR_ROK)
#define RTW_INTR_TX (RTW_INTR_TLPDER|RTW_INTR_TLPDOK|RTW_INTR_THPDER|\
RTW_INTR_THPDOK|RTW_INTR_TNPDER|RTW_INTR_TNPDOK|\
RTW_INTR_TBDER|RTW_INTR_TBDOK)
#define RTW_INTR_BEACON (RTW_INTR_BCNINT|RTW_INTR_TBDER|RTW_INTR_TBDOK)
#define RTW_INTR_IOERROR (RTW_INTR_TXFOVW|RTW_INTR_RXFOVW|RTW_INTR_RDU)
#define RTW_TCR 0x40
#define RTW_TCR_CWMIN (1<<31)
#define RTW_TCR_SWSEQ (1<<30)
#define RTW8185_TCR_NOPROBERSPTO (1<<29)
#define RTW_TCR_HWVERID_MASK 0xe000000
#define RTW_TCR_HWVERID_RTL8180D (1<<26)
#define RTW_TCR_HWVERID_RTL8180F 0x6000000
#define RTW_TCR_HWVERID_RTL8185 ((1<<27) | (1<<25))
#define RTW8180_TCR_SAT (1<<24)
#define RTW8185_TCR_PLCPLENGTH (1<<24)
#define RTW_TCR_MXDMA_MASK 0xe00000
#define RTW_TCR_MXDMA_16 LSHIFT(0, RTW_TCR_MXDMA_MASK)
#define RTW_TCR_MXDMA_32 LSHIFT(1, RTW_TCR_MXDMA_MASK)
#define RTW_TCR_MXDMA_64 LSHIFT(2, RTW_TCR_MXDMA_MASK)
#define RTW_TCR_MXDMA_128 LSHIFT(3, RTW_TCR_MXDMA_MASK)
#define RTW_TCR_MXDMA_256 LSHIFT(4, RTW_TCR_MXDMA_MASK)
#define RTW_TCR_MXDMA_512 LSHIFT(5, RTW_TCR_MXDMA_MASK)
#define RTW_TCR_MXDMA_1024 LSHIFT(6, RTW_TCR_MXDMA_MASK)
#define RTW_TCR_MXDMA_2048 LSHIFT(7, RTW_TCR_MXDMA_MASK)
#define RTW_TCR_DISCW (1<<20)
#define RTW_TCR_ICV (1<<19)
#define RTW_TCR_LBK_MASK 0x60000
#define RTW_TCR_LBK_NORMAL LSHIFT(0, RTW_TCR_LBK_MASK)
#define RTW_TCR_LBK_MAC LSHIFT(1, RTW_TCR_LBK_MASK)
#define RTW_TCR_LBK_BBP LSHIFT(2, RTW_TCR_LBK_MASK)
#define RTW_TCR_LBK_CONT LSHIFT(3, RTW_TCR_LBK_MASK)
#define RTW_TCR_CRC (1<<16)
#define RTW_TCR_SRL_MASK 0xff00
#define RTW_TCR_LRL_MASK 0xff
#define RTW_RCR 0x44
#define RTW_RCR_ONLYERLPKT (1<<31)
#define RTW_RCR_ENCS2 (1<<30)
#define RTW_RCR_ENCS1 (1<<29)
#define RTW_RCR_ENMARP (1<<28)
#define RTW_RCR_CBSSID (1<<23)
#define RTW_RCR_APWRMGT (1<<22)
#define RTW_RCR_ADD3 (1<<21)
#define RTW_RCR_AMF (1<<20)
#define RTW_RCR_ACF (1<<19)
#define RTW_RCR_ADF (1<<18)
#define RTW8180_RCR_RXFTH_MASK 0xe000
#define RTW8180_RCR_RXFTH_64 LSHIFT(2, RTW8180_RCR_RXFTH_MASK)
#define RTW8180_RCR_RXFTH_128 LSHIFT(3, RTW8180_RCR_RXFTH_MASK)
#define RTW8180_RCR_RXFTH_256 LSHIFT(4, RTW8180_RCR_RXFTH_MASK)
#define RTW8180_RCR_RXFTH_512 LSHIFT(5, RTW8180_RCR_RXFTH_MASK)
#define RTW8180_RCR_RXFTH_1024 LSHIFT(6, RTW8180_RCR_RXFTH_MASK)
#define RTW8180_RCR_RXFTH_WHOLE LSHIFT(7, RTW8180_RCR_RXFTH_MASK)
#define RTW_RCR_AICV (1<<12)
#define RTW_RCR_MXDMA_MASK 0x700
#define RTW_RCR_MXDMA_16 LSHIFT(0, RTW_RCR_MXDMA_MASK)
#define RTW_RCR_MXDMA_32 LSHIFT(1, RTW_RCR_MXDMA_MASK)
#define RTW_RCR_MXDMA_64 LSHIFT(2, RTW_RCR_MXDMA_MASK)
#define RTW_RCR_MXDMA_128 LSHIFT(3, RTW_RCR_MXDMA_MASK)
#define RTW_RCR_MXDMA_256 LSHIFT(4, RTW_RCR_MXDMA_MASK)
#define RTW_RCR_MXDMA_512 LSHIFT(5, RTW_RCR_MXDMA_MASK)
#define RTW_RCR_MXDMA_1024 LSHIFT(6, RTW_RCR_MXDMA_MASK)
#define RTW_RCR_MXDMA_UNLIMITED LSHIFT(7, RTW_RCR_MXDMA_MASK)
#define RTW_RCR_9356SEL (1<<6)
#define RTW_RCR_ACRC32 (1<<5)
#define RTW_RCR_AB (1<<3)
#define RTW_RCR_AM (1<<2)
#define RTW_RCR_APM (1<<1)
#define RTW_RCR_AAP (1<<0)
#define RTW_RCR_MONITOR ( \
RTW_RCR_AAP | \
RTW_RCR_ACF | \
RTW_RCR_ACRC32 | \
RTW_RCR_AICV | \
0)
#define RTW_RCR_PKTFILTER_MASK (\
RTW_RCR_AAP | \
RTW_RCR_AB | \
RTW_RCR_ACF | \
RTW_RCR_ACRC32 | \
RTW_RCR_ADD3 | \
RTW_RCR_ADF | \
RTW_RCR_AICV | \
RTW_RCR_AM | \
RTW_RCR_AMF | \
RTW_RCR_APM | \
RTW_RCR_APWRMGT | \
0)
#define RTW_RCR_PKTFILTER_DEFAULT ( \
RTW_RCR_ADF | \
RTW_RCR_AMF | \
RTW_RCR_APM | \
RTW_RCR_APWRMGT | \
0)
#define RTW_TINT 0x48
#define RTW_TBDA 0x4c
#define RTW_9346CR 0x50
#define RTW_9346CR_EEM_MASK 0xc0
#define RTW_9346CR_EEM_NORMAL LSHIFT(0, RTW_9346CR_EEM_MASK)
#define RTW_9346CR_EEM_AUTOLOAD LSHIFT(1, RTW_9346CR_EEM_MASK)
#define RTW_9346CR_EEM_PROGRAM LSHIFT(2, RTW_9346CR_EEM_MASK)
#define RTW_9346CR_EEM_CONFIG LSHIFT(3, RTW_9346CR_EEM_MASK)
#define RTW_9346CR_EECS (1<<3)
#define RTW_9346CR_EESK (1<<2)
#define RTW_9346CR_EEDI (1<<1)
#define RTW_9346CR_EEDO (1<<0)
#define RTW_CONFIG0 0x51
#define RTW8180_CONFIG0_WEP40 (1<<7)
#define RTW8180_CONFIG0_WEP104 (1<<6)
#define RTW8180_CONFIG0_LEDGPOEN (1<<4)
#define RTW_CONFIG0_AUXPWR (1<<3)
#define RTW8180_CONFIG0_GL_MASK 0x3
#define RTW8180_CONFIG0_GL_USA LSHIFT(3, RTW8180_CONFIG0_GL_MASK)
#define RTW8180_CONFIG0_GL_EUROPE LSHIFT(2, RTW8180_CONFIG0_GL_MASK)
#define RTW8180_CONFIG0_GL_JAPAN LSHIFT(1, RTW8180_CONFIG0_GL_MASK)
#define RTW8180_CONFIG0_GL_JAPAN2 LSHIFT(0, RTW8180_CONFIG0_GL_MASK)
#define RTW_CONFIG1 0x52
#define RTW_CONFIG1_LEDS_MASK 0xc0
#define RTW_CONFIG1_LEDS_ACT_INFRA LSHIFT(0, RTW_CONFIG1_LEDS_MASK)
#define RTW_CONFIG1_LEDS_ACT_LINK LSHIFT(1, RTW_CONFIG1_LEDS_MASK)
#define RTW_CONFIG1_LEDS_TX_RX LSHIFT(2, RTW_CONFIG1_LEDS_MASK)
#define RTW_CONFIG1_LEDS_LINKACT_INFRA LSHIFT(3, RTW_CONFIG1_LEDS_MASK)
#define RTW_CONFIG1_LWACT (1<<4)
#define RTW_CONFIG1_MEMMAP (1<<3)
#define RTW_CONFIG1_IOMAP (1<<2)
#define RTW_CONFIG1_VPD (1<<1)
#define RTW_CONFIG1_PMEN (1<<0)
#define RTW_CONFIG2 0x53
#define RTW_CONFIG2_LCK (1<<7)
#define RTW8180_CONFIG2_ANT (1<<6)
#define RTW_CONFIG2_DPS (1<<3)
#define RTW_CONFIG2_PAPESIGN (1<<2)
#define RTW_CONFIG2_PAPETIME_MASK 0x3
#define RTW_ANAPARM_0 0x54
#define RTW8185_ANAPARM_1 0x60
#define RTW_ANAPARM_RFPOW0_MASK 0x70000000
#define RTW_ANAPARM_RFPOW_MASK \
(RTW_ANAPARM_RFPOW0_MASK|RTW_ANAPARM_RFPOW1_MASK)
#define RTW_ANAPARM_TXDACOFF (1<<27)
#define RTW_ANAPARM_RFPOW1_MASK 0x7f00000
#define RTW_ANAPARM_RFPOW_MAXIM_ON LSHIFT(0x8, RTW_ANAPARM_RFPOW1_MASK)
#define RTW_ANAPARM_RFPOW_MAXIM_SLEEP LSHIFT(0x378, RTW_ANAPARM_RFPOW1_MASK)
#define RTW_ANAPARM_RFPOW_MAXIM_OFF LSHIFT(0x379, RTW_ANAPARM_RFPOW1_MASK)
#define RTW_ANAPARM_RFPOW_RFMD_ON LSHIFT(0x408, RTW_ANAPARM_RFPOW1_MASK)
#define RTW_ANAPARM_RFPOW_RFMD_SLEEP LSHIFT(0x378, RTW_ANAPARM_RFPOW1_MASK)
#define RTW_ANAPARM_RFPOW_RFMD_OFF LSHIFT(0x379, RTW_ANAPARM_RFPOW1_MASK)
#define RTW_ANAPARM_RFPOW_ANA_PHILIPS_ON \
LSHIFT(0x328, RTW_ANAPARM_RFPOW1_MASK)
#define RTW_ANAPARM_RFPOW_DIG_PHILIPS_ON \
LSHIFT(0x008, RTW_ANAPARM_RFPOW1_MASK)
#define RTW_ANAPARM_RFPOW_PHILIPS_SLEEP\
LSHIFT(0x378, RTW_ANAPARM_RFPOW1_MASK)
#define RTW_ANAPARM_RFPOW_PHILIPS_OFF\
LSHIFT(0x379, RTW_ANAPARM_RFPOW1_MASK)
#define RTW_ANAPARM_RFPOW_PHILIPS_ON LSHIFT(0x328, RTW_ANAPARM_RFPOW1_MASK)
#define RTW_ANAPARM_CARDSP_MASK 0xfffff
#define RTW_MSR 0x58
#define RTW_MSR_NETYPE_MASK 0xc
#define RTW_MSR_NETYPE_AP_OK LSHIFT(3, RTW_MSR_NETYPE_MASK)
#define RTW_MSR_NETYPE_INFRA_OK LSHIFT(2, RTW_MSR_NETYPE_MASK)
#define RTW_MSR_NETYPE_ADHOC_OK LSHIFT(1, RTW_MSR_NETYPE_MASK)
#define RTW_MSR_NETYPE_NOLINK LSHIFT(0, RTW_MSR_NETYPE_MASK)
#define RTW_CONFIG3 0x59
#define RTW_CONFIG3_GNTSEL (1<<7)
#define RTW_CONFIG3_PARMEN (1<<6)
#define RTW_CONFIG3_MAGIC (1<<5)
#define RTW_CONFIG3_CARDBEN (1<<3)
#define RTW_CONFIG3_CLKRUNEN (1<<2)
#define RTW_CONFIG3_FUNCREGEN (1<<1)
#define RTW_CONFIG3_FBTBEN (1<<0)
#define RTW_CONFIG4 0x5A
#define RTW_CONFIG4_VCOPDN (1<<7)
#define RTW_CONFIG4_PWROFF (1<<6)
#define RTW_CONFIG4_PWRMGT (1<<5)
#define RTW_CONFIG4_LWPME (1<<4)
#define RTW_CONFIG4_LWPTN (1<<2)
#define RTW_CONFIG4_RFTYPE_MASK 0x3
#define RTW_CONFIG4_RFTYPE_INTERSIL LSHIFT(1, RTW_CONFIG4_RFTYPE_MASK)
#define RTW_CONFIG4_RFTYPE_RFMD LSHIFT(2, RTW_CONFIG4_RFTYPE_MASK)
#define RTW_CONFIG4_RFTYPE_PHILIPS LSHIFT(3, RTW_CONFIG4_RFTYPE_MASK)
#define RTW_TESTR 0x5B
#define RTW_PSR 0x5e
#define RTW_PSR_GPO (1<<7)
#define RTW_PSR_GPI (1<<6)
#define RTW_PSR_LEDGPO1 (1<<5)
#define RTW_PSR_LEDGPO0 (1<<4)
#define RTW_PSR_UWF (1<<1)
#define RTW_PSR_PSEN (1<<0)
#define RTW8180_SCR 0x5f
#define RTW8180_SCR_KM_MASK 0x30
#define RTW8180_SCR_KM_WEP104 LSHIFT(1, RTW8180_SCR_KM_MASK)
#define RTW8180_SCR_KM_WEP40 LSHIFT(0, RTW8180_SCR_KM_MASK)
#define RTW8180_SCR_TXSECON (1<<1)
#define RTW8180_SCR_RXSECON (1<<0)
#define RTW8185_RFPARM 0x60
#define RTW_BCNITV 0x70
#define RTW_BCNITV_BCNITV_MASK 0x3ff
#define RTW_ATIMWND 0x72
#define RTW_ATIMWND_ATIMWND 0x3ff
#define RTW_BINTRITV 0x74
#define RTW_BINTRITV_BINTRITV 0x3ff
#define RTW_ATIMTRITV 0x76
#define RTW_ATIMTRITV_ATIMTRITV 0x3ff
#define RTW_PHYDELAY 0x78
#define RTW_PHYDELAY_REVC_MAGIC (1<<3)
#define RTW_PHYDELAY_PHYDELAY 0x7
#define RTW_CRCOUNT 0x79
#define RTW_CRCOUNT_MAGIC 0x4c
#define RTW_CRC16ERR 0x7a
#define RTW_BB 0x7c
#define RTW_BB_RD_MASK 0xff0000
#define RTW_BB_WR_MASK 0xff00
#define RTW_BB_WREN (1<<7)
#define RTW_BB_ADDR_MASK 0x7f
#define RTW_PHYADDR 0x7c
#define RTW_PHYDATAW 0x7d
#define RTW_PHYDATAR 0x7e
#define RTW8180_PHYCFG 0x80
#define RTW8180_PHYCFG_MAC_POLL (1<<31)
#define RTW8180_PHYCFG_HST (1<<30)
#define RTW8180_PHYCFG_MAC_RFTYPE_MASK 0x30000000
#define RTW8180_PHYCFG_MAC_RFTYPE_INTERSIL \
LSHIFT(0, RTW8180_PHYCFG_MAC_RFTYPE_MASK)
#define RTW8180_PHYCFG_MAC_RFTYPE_RFMD \
LSHIFT(1, RTW8180_PHYCFG_MAC_RFTYPE_MASK)
#define RTW8180_PHYCFG_MAC_RFTYPE_GCT \
RTW8180_PHYCFG_MAC_RFTYPE_RFMD
#define RTW8180_PHYCFG_MAC_RFTYPE_PHILIPS \
LSHIFT(3, RTW8180_PHYCFG_MAC_RFTYPE_MASK)
#define RTW8180_PHYCFG_MAC_PHILIPS_ADDR_MASK 0xf000000
#define RTW8180_PHYCFG_MAC_PHILIPS_DATA_MASK 0xffffff
#define RTW8180_PHYCFG_MAC_MAXIM_LODATA_MASK 0xf000000
#define RTW8180_PHYCFG_MAC_MAXIM_ADDR_MASK 0xf00
#define RTW8180_PHYCFG_MAC_MAXIM_HIDATA_MASK 0xff
#define RTW8180_PHYCFG_HST_EN (1<<2)
#define RTW8180_PHYCFG_HST_CLK (1<<1)
#define RTW8180_PHYCFG_HST_DATA (1<<0)
#define RTW8185_RFPINSOUTPUT 0x80
#define RTW8185_RFPINSOUTPUT_MASK 0xfff3
#define RTW8185_RFPINSENABLE 0x82
#define RTW8185_RFPINSENABLE_ENABLE 0x0007
#define RTW8185_INSSELECT 0x84
#define RTW8185_SW_GPIO 0x400
#define RTW_MAXIM_HIDATA_MASK 0xff0
#define RTW_MAXIM_LODATA_MASK 0xf
#define RTW_WAKEUP0L 0x84
#define RTW_WAKEUP0H 0x88
#define RTW_WAKEUP1L 0x8c
#define RTW_WAKEUP1H 0x90
#define RTW_WAKEUP2LL 0x94
#define RTW_WAKEUP2LH 0x98
#define RTW_WAKEUP2HL 0x9c
#define RTW_WAKEUP2HH 0xa0
#define RTW_WAKEUP3LL 0xa4
#define RTW_WAKEUP3LH 0xa8
#define RTW_WAKEUP3HL 0xac
#define RTW_WAKEUP3HH 0xb0
#define RTW_WAKEUP4LL 0xb4
#define RTW_WAKEUP4LH 0xb8
#define RTW_WAKEUP4HL 0xbc
#define RTW_WAKEUP4HH 0xc0
#define RTW_CRC0 0xc4
#define RTW_CRC1 0xc6
#define RTW_CRC2 0xc8
#define RTW_CRC3 0xca
#define RTW_CRC4 0xcc
#define RTW8180_DK0 0x90
#define RTW8180_DK1 0xa0
#define RTW8180_DK2 0xb0
#define RTW8180_DK3 0xc0
#define RTW8185_RFPINSSELECT 0x84
#define RTW8185_RFPINSSELECT_ENABLE 0x0007
#define RTW8185_RFPINSINPUT 0x86
#define RTW8185_RFPARA 0x88
#define RTW8185_RFTIMING 0x8c
#define RTW8185_GPO 0x90
#define RTW8185_GPE 0x91
#define RTW8185_GPI 0x92
#define RTW8185_TXAGCCTL 0x9c
#define RTW8185_CCKTXAGC 0x9d
#define RTW8185_OFDMTXAGC 0x9e
#define RTW8185_ANTSEL 0x9f
#define RTW8185_CAMRW 0xa0
#define RTW8185_CAMRW_POOLING (1<<31)
#define RTW8185_CAMRW_WRITE (1<<16)
#define RTW8185_CAMRW_ADDRESS 0x7f
#define RTW8185_CAMOUTPUT 0xa4
#define RTW8185_CAMINPUT 0xa8
#define RTW8185_CAMDEBUG 0xac
#define RTW8185_CAMDEBUG_SELTXRXINFO (1<<31)
#define RTW8185_CAMDEBUG_KEYFOUND (1<<30)
#define RTW8185_CAMDEBUG_WPACONFIG 0x3f000000
#define RTW8185_CAMDEBUG_CAMKEY 0xffffff
#define RTW8185_WPACONFIG 0xb0
#define RTW8185_WPACONFIG_RXWPADUMMY (1<<8)
#define RTW8185_WPACONFIG_DISRX_AESMIC (1<<3)
#define RTW8185_WPACONFIG_RXDECRYPT (1<<2)
#define RTW8185_WPACONFIG_TXENCRYPT (1<<1)
#define RTW8185_WPACONFIG_USEDEFAULTKEY (1<<0)
#define RTW8185_AESMASK 0xb2
#define RTW8185_SIFS 0xb4
#define RTW8185_DIFS 0xb5
#define RTW8185_SLOTTIME 0xb6
#define RTW8185_UTUNE 0xb7
#define RTW8185_CWCONFIG 0xbc
#define RTW8185_CWCONFIG_PPRETRYLIMIT (1<<1)
#define RTW8185_CWCONFIG_PPCW (1<<1)
#define RTW8185_CWVALUES 0xbd
#define RTW8185_CWVALUES_CWMAX 0xf0
#define RTW8185_CWVALUES_CWMIN 0xf
#define RTW8185_RATEFALLBACKCTL 0xbe
#define RTW8185_RATEFALLBACKCTL_ENABLE (1<<7)
#define RTW8185_RATEFALLBACKCTL_STEP 0x3
#define RTW_CONFIG5 0xd8
#define RTW_CONFIG5_TXFIFOOK (1<<7)
#define RTW_CONFIG5_RXFIFOOK (1<<6)
#define RTW_CONFIG5_CALON (1<<5)
#define RTW_CONFIG5_EACPI (1<<2)
#define RTW_CONFIG5_LANWAKE (1<<1)
#define RTW_CONFIG5_PMESTS (1<<0)
#define RTW_TPPOLL 0xd9
#define RTW_TPPOLL_BQ (1<<7)
#define RTW_TPPOLL_HPQ (1<<6)
#define RTW_TPPOLL_NPQ (1<<5)
#define RTW_TPPOLL_LPQ (1<<4)
#define RTW_TPPOLL_SBQ (1<<3)
#define RTW_TPPOLL_SHPQ (1<<2)
#define RTW_TPPOLL_SNPQ (1<<1)
#define RTW_TPPOLL_SLPQ (1<<0)
#define RTW_TPPOLL_ALL (RTW_TPPOLL_BQ | RTW_TPPOLL_HPQ | \
RTW_TPPOLL_NPQ | RTW_TPPOLL_LPQ)
#define RTW_TPPOLL_ACTIVE RTW_TPPOLL_ALL
#define RTW_TPPOLL_SALL (RTW_TPPOLL_SBQ | RTW_TPPOLL_SHPQ | \
RTW_TPPOLL_SNPQ | RTW_TPPOLL_SLPQ)
#define RTW_CWR 0xdc
#define RTW_CWR_CW 0x3ff
#define RTW_RETRYCTR 0xde
#define RTW_RETRYCTR_RETRYCT 0xff
#define RTW_RDSAR 0xe4
#define RTW_FER 0xf0
#define RTW_FER_INTR (1<<15)
#define RTW_FER_GWAKE (1<<4)
#define RTW_FEMR 0xf4
#define RTW_FEMR_INTR (1<<15)
#define RTW_FEMR_WKUP (1<<14)
#define RTW_FEMR_GWAKE (1<<4)
#define RTW_FPSR 0xf8
#define RTW_FPSR_INTR (1<<15)
#define RTW_FPSR_GWAKE (1<<4)
#define RTW_FFER 0xfc
#define RTW_FFER_INTR (1<<15)
#define RTW_FFER_GWAKE (1<<4)
#define RTW_SR_ID 0x00
#define RTW_SR_VID 0x02
#define RTW_SR_DID 0x04
#define RTW_SR_SVID 0x06
#define RTW_SR_SMID 0x08
#define RTW_SR_MNGNT 0x0a
#define RTW_SR_MXLAT 0x0b
#define RTW_SR_RFCHIPID 0x0c
#define RTW_SR_CONFIG3 0x0d
#define RTW_SR_MAC 0x0e
#define RTW_SR_CONFIG0 0x14
#define RTW_SR_CONFIG1 0x15
#define RTW_SR_PMC 0x16
#define RTW_SR_CONFIG2 0x18
#define RTW_SR_CONFIG4 0x19
#define RTW_SR_ANAPARM 0x1a
#define RTW_SR_TESTR 0x1e
#define RTW_SR_CONFIG5 0x1f
#define RTW_SR_TXPOWER1 0x20
#define RTW_SR_TXPOWER2 0x21
#define RTW_SR_TXPOWER3 0x22
#define RTW_SR_TXPOWER4 0x23
#define RTW_SR_TXPOWER5 0x24
#define RTW_SR_TXPOWER6 0x25
#define RTW_SR_TXPOWER7 0x26
#define RTW_SR_TXPOWER8 0x27
#define RTW_SR_TXPOWER9 0x28
#define RTW_SR_TXPOWER10 0x29
#define RTW_SR_TXPOWER11 0x2a
#define RTW_SR_TXPOWER12 0x2b
#define RTW_SR_TXPOWER13 0x2c
#define RTW_SR_TXPOWER14 0x2d
#define RTW_SR_CHANNELPLAN 0x2e
#define RTW_SR_ENERGYDETTHR 0x2f
#define RTW_SR_ENERGYDETTHR_DEFAULT 0x0c
#define RTW_SR_CISPOINTER 0x30
#define RTW_SR_RFPARM 0x32
#define RTW_SR_RFPARM_DIGPHY (1<<0)
#define RTW_SR_RFPARM_DFLANTB (1<<1)
#define RTW_SR_RFPARM_CS_MASK 0xc
#define RTW_SR_VERSION 0x3c
#define RTW_SR_CRC 0x3e
#define RTW_SR_VPD 0x40
#define RTW_SR_CIS 0x80
#define RTW_DESC_ALIGNMENT 256
struct rtw_txdesc {
u_int32_t td_ctl0;
u_int32_t td_ctl1;
u_int32_t td_buf;
u_int32_t td_len;
u_int32_t td_next;
u_int32_t td_rsvd[3];
};
#define td_stat td_ctl0
#define RTW_TXCTL0_OWN (1<<31)
#define RTW_TXCTL0_RSVD0 (1<<30)
#define RTW_TXCTL0_FS (1<<29)
#define RTW_TXCTL0_LS (1<<28)
#define RTW_TXCTL0_RATE_MASK 0xf000000
#define RTW_TXCTL0_RATE_1MBPS LSHIFT(0, RTW_TXCTL0_RATE_MASK)
#define RTW_TXCTL0_RATE_2MBPS LSHIFT(1, RTW_TXCTL0_RATE_MASK)
#define RTW_TXCTL0_RATE_5MBPS LSHIFT(2, RTW_TXCTL0_RATE_MASK)
#define RTW_TXCTL0_RATE_11MBPS LSHIFT(3, RTW_TXCTL0_RATE_MASK)
#define RTW_TXCTL0_RTSEN (1<<23)
#define RTW_TXCTL0_RTSRATE_MASK 0x780000
#define RTW_TXCTL0_RTSRATE_1MBPS LSHIFT(0, RTW_TXCTL0_RTSRATE_MASK)
#define RTW_TXCTL0_RTSRATE_2MBPS LSHIFT(1, RTW_TXCTL0_RTSRATE_MASK)
#define RTW_TXCTL0_RTSRATE_5MBPS LSHIFT(2, RTW_TXCTL0_RTSRATE_MASK)
#define RTW_TXCTL0_RTSRATE_11MBPS LSHIFT(3, RTW_TXCTL0_RTSRATE_MASK)
#define RTW_TXCTL0_BEACON (1<<18)
#define RTW_TXCTL0_MOREFRAG (1<<17)
#define RTW_TXCTL0_SPLCP (1<<16)
#define RTW_TXCTL0_KEYID_MASK 0xc000
#define RTW_TXCTL0_RSVD1_MASK 0x3000
#define RTW_TXCTL0_TPKTSIZE_MASK 0xfff
#define RTW_TXSTAT_OWN RTW_TXCTL0_OWN
#define RTW_TXSTAT_RSVD0 RTW_TXCTL0_RSVD0
#define RTW_TXSTAT_FS RTW_TXCTL0_FS
#define RTW_TXSTAT_LS RTW_TXCTL0_LS
#define RTW_TXSTAT_RSVD1_MASK 0xfff0000
#define RTW_TXSTAT_TOK (1<<15)
#define RTW_TXSTAT_RTSRETRY_MASK 0x7f00
#define RTW_TXSTAT_DRC_MASK 0xff
#define RTW_TXCTL1_LENGEXT (1<<31)
#define RTW_TXCTL1_LENGTH_MASK 0x7fff0000
#define RTW_TXCTL1_RTSDUR_MASK 0xffff
#define RTW_TXLEN_LENGTH_MASK 0xfff
struct rtw_rxdesc {
u_int32_t rd_ctl;
u_int32_t rd_rsvd0;
u_int32_t rd_buf;
u_int32_t rd_rsvd1;
};
#define rd_stat rd_ctl
#define rd_rssi rd_rsvd0
#define rd_tsftl rd_buf
#define rd_tsfth rd_rsvd1
#define RTW_RXCTL_OWN (1<<31)
#define RTW_RXCTL_EOR (1<<30)
#define RTW_RXCTL_FS (1<<29)
#define RTW_RXCTL_LS (1<<28)
#define RTW_RXCTL_RSVD0_MASK 0x3ffff000
#define RTW_RXCTL_LENGTH_MASK 0xfff
#define RTW_RXSTAT_OWN RTW_RXCTL_OWN
#define RTW_RXSTAT_EOR RTW_RXCTL_EOR
#define RTW_RXSTAT_FS RTW_RXCTL_FS
#define RTW_RXSTAT_LS RTW_RXCTL_LS
#define RTW_RXSTAT_DMAFAIL (1<<27)
#define RTW_RXSTAT_BOVF (1<<26)
#define RTW_RXSTAT_SPLCP (1<<25)
#define RTW_RXSTAT_RSVD1 (1<<24)
#define RTW_RXSTAT_RATE_MASK 0xf00000
#define RTW_RXSTAT_RATE_1MBPS LSHIFT(0, RTW_RXSTAT_RATE_MASK)
#define RTW_RXSTAT_RATE_2MBPS LSHIFT(1, RTW_RXSTAT_RATE_MASK)
#define RTW_RXSTAT_RATE_5MBPS LSHIFT(2, RTW_RXSTAT_RATE_MASK)
#define RTW_RXSTAT_RATE_11MBPS LSHIFT(3, RTW_RXSTAT_RATE_MASK)
#define RTW_RXSTAT_MIC (1<<19)
#define RTW_RXSTAT_MAR (1<<18)
#define RTW_RXSTAT_PAR (1<<17)
#define RTW_RXSTAT_BAR (1<<16)
#define RTW_RXSTAT_RES (1<<15)
#define RTW_RXSTAT_PWRMGT (1<<14)
#define RTW_RXSTAT_CRC16 (1<<14)
#define RTW_RXSTAT_CRC32 (1<<13)
#define RTW_RXSTAT_ICV (1<<12)
#define RTW_RXSTAT_LENGTH_MASK 0xfff
#define RTW_RXSTAT_ONESEG (RTW_RXSTAT_FS|RTW_RXSTAT_LS)
#define RTW_RXSTAT_IOERROR (RTW_RXSTAT_DMAFAIL|RTW_RXSTAT_BOVF)
#define RTW_RXSTAT_DEBUG (RTW_RXSTAT_SPLCP|RTW_RXSTAT_MAR|\
RTW_RXSTAT_PAR|RTW_RXSTAT_BAR|\
RTW_RXSTAT_PWRMGT|RTW_RXSTAT_CRC32|\
RTW_RXSTAT_ICV)
#define RTW_RXRSSI_VLAN 0xfffe
#define RTW_RXRSSI_RSSI 0xff00
#define RTW_RXRSSI_IMR_RSSI 0xfe00
#define RTW_RXRSSI_IMR_LNA (1<<8)
#define RTW_RXRSSI_SQ 0xff
#define RTW_READ8(regs, ofs) \
((*(regs)->r_read8)(regs, ofs))
#define RTW_READ16(regs, ofs) \
((*(regs)->r_read16)(regs, ofs))
#define RTW_READ(regs, ofs) \
((*(regs)->r_read32)(regs, ofs))
#define RTW_WRITE8(regs, ofs, val) \
((*(regs)->r_write8)(regs, ofs, val))
#define RTW_WRITE16(regs, ofs, val) \
((*(regs)->r_write16)(regs, ofs, val))
#define RTW_WRITE(regs, ofs, val) \
((*(regs)->r_write32)(regs, ofs, val))
#define RTW_ISSET(regs, reg, mask) \
(RTW_READ((regs), (reg)) & (mask))
#define RTW_CLR(regs, reg, mask) \
RTW_WRITE((regs), (reg), RTW_READ((regs), (reg)) & ~(mask))
#ifndef BUS_SPACE_BARRIER_SYNC
#define BUS_SPACE_BARRIER_SYNC (BUS_SPACE_BARRIER_READ|BUS_SPACE_BARRIER_WRITE)
#endif
#ifndef BUS_SPACE_BARRIER_READ_BEFORE_READ
#define BUS_SPACE_BARRIER_READ_BEFORE_READ BUS_SPACE_BARRIER_READ
#endif
#ifndef BUS_SPACE_BARRIER_READ_BEFORE_WRITE
#define BUS_SPACE_BARRIER_READ_BEFORE_WRITE BUS_SPACE_BARRIER_READ
#endif
#ifndef BUS_SPACE_BARRIER_WRITE_BEFORE_READ
#define BUS_SPACE_BARRIER_WRITE_BEFORE_READ BUS_SPACE_BARRIER_WRITE
#endif
#ifndef BUS_SPACE_BARRIER_WRITE_BEFORE_WRITE
#define BUS_SPACE_BARRIER_WRITE_BEFORE_WRITE BUS_SPACE_BARRIER_WRITE
#endif
#define RTW_BARRIER(regs, reg0, reg1, flags) \
((*(regs)->r_barrier)(regs, reg0, reg1, flags))
#define RTW_SYNC(regs, reg0, reg1) \
RTW_BARRIER(regs, reg0, reg1, BUS_SPACE_BARRIER_SYNC)
#define RTW_WBW(regs, reg0, reg1) \
RTW_BARRIER(regs, reg0, reg1, BUS_SPACE_BARRIER_WRITE_BEFORE_WRITE)
#define RTW_WBR(regs, reg0, reg1) \
RTW_BARRIER(regs, reg0, reg1, BUS_SPACE_BARRIER_WRITE_BEFORE_READ)
#define RTW_RBR(regs, reg0, reg1) \
RTW_BARRIER(regs, reg0, reg1, BUS_SPACE_BARRIER_READ_BEFORE_READ)
#define RTW_RBW(regs, reg0, reg1) \
RTW_BARRIER(regs, reg0, reg1, BUS_SPACE_BARRIER_READ_BEFORE_WRITE)
#define RTW_WBRW(regs, reg0, reg1) \
RTW_BARRIER(regs, reg0, reg1, \
BUS_SPACE_BARRIER_WRITE_BEFORE_READ | \
BUS_SPACE_BARRIER_WRITE_BEFORE_WRITE)
#define RTW_BBP_SYS1 0x00
#define RTW_BBP_TXAGC 0x03
#define RTW_BBP_LNADET 0x04
#define RTW_BBP_IFAGCINI 0x05
#define RTW_BBP_IFAGCLIMIT 0x06
#define RTW_BBP_IFAGCDET 0x07
#define RTW_BBP_ANTATTEN 0x10
#define RTW_BBP_ANTATTEN_PHILIPS_MAGIC 0x91
#define RTW_BBP_ANTATTEN_INTERSIL_MAGIC 0x92
#define RTW_BBP_ANTATTEN_RFMD_MAGIC 0x93
#define RTW_BBP_ANTATTEN_GCT_MAGIC 0xa3
#define RTW_BBP_ANTATTEN_MAXIM_MAGIC 0xb3
#define RTW_BBP_ANTATTEN_DFLANTB 0x40
#define RTW_BBP_ANTATTEN_CHAN14 0x0c
#define RTW_BBP_TRL 0x11
#define RTW_BBP_SYS2 0x12
#define RTW_BBP_SYS2_ANTDIV 0x80
#define RTW_BBP_SYS2_RATE_MASK 0x30
#define RTW_BBP_SYS3 0x13
#define RTW_BBP_SYS3_CSTHRESH_MASK 0xf
#define RTW_BBP_CHESTLIM 0x19
#define RTW_BBP_CHSQLIM 0x1a