Home | History | Annotate | Line # | Download | only in ic
      1  1.11  jmcneill /*	$NetBSD: bwivar.h,v 1.11 2025/01/19 00:29:28 jmcneill Exp $	*/
      2   1.1  macallan /*	$OpenBSD: bwivar.h,v 1.23 2008/02/25 20:36:54 mglocker Exp $	*/
      3   1.1  macallan 
      4   1.1  macallan /*
      5   1.1  macallan  * Copyright (c) 2007 The DragonFly Project.  All rights reserved.
      6   1.1  macallan  *
      7   1.1  macallan  * This code is derived from software contributed to The DragonFly Project
      8   1.1  macallan  * by Sepherosa Ziehau <sepherosa (at) gmail.com>
      9   1.1  macallan  *
     10   1.1  macallan  * Redistribution and use in source and binary forms, with or without
     11   1.1  macallan  * modification, are permitted provided that the following conditions
     12   1.1  macallan  * are met:
     13   1.1  macallan  *
     14   1.1  macallan  * 1. Redistributions of source code must retain the above copyright
     15   1.1  macallan  *    notice, this list of conditions and the following disclaimer.
     16   1.1  macallan  * 2. Redistributions in binary form must reproduce the above copyright
     17   1.1  macallan  *    notice, this list of conditions and the following disclaimer in
     18   1.1  macallan  *    the documentation and/or other materials provided with the
     19   1.1  macallan  *    distribution.
     20   1.1  macallan  * 3. Neither the name of The DragonFly Project nor the names of its
     21   1.1  macallan  *    contributors may be used to endorse or promote products derived
     22   1.1  macallan  *    from this software without specific, prior written permission.
     23   1.1  macallan  *
     24   1.1  macallan  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     25   1.1  macallan  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     26   1.1  macallan  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     27   1.1  macallan  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
     28   1.1  macallan  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     29   1.1  macallan  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
     30   1.1  macallan  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     31   1.1  macallan  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     32   1.1  macallan  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     33   1.1  macallan  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     34   1.1  macallan  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35   1.1  macallan  * SUCH DAMAGE.
     36   1.1  macallan  *
     37   1.1  macallan  * $DragonFly: src/sys/dev/netif/bwi/if_bwivar.h,v 1.1 2007/09/08 06:15:54 sephe Exp $
     38   1.1  macallan  */
     39   1.1  macallan 
     40   1.2  macallan #ifndef _DEV_IC_BWIVAR_H
     41   1.2  macallan #define _DEV_IC_BWIVAR_H
     42   1.1  macallan 
     43   1.1  macallan #define BWI_ALIGN		0x1000
     44   1.1  macallan #define BWI_RING_ALIGN		BWI_ALIGN
     45   1.1  macallan #define BWI_BUS_SPACE_MAXADDR	0x3fffffff
     46   1.1  macallan 
     47   1.1  macallan #define BWI_TX_NRING		6
     48   1.1  macallan #define BWI_TXRX_NRING		6
     49   1.1  macallan #define BWI_TX_NDESC		128
     50   1.1  macallan #define BWI_RX_NDESC		64
     51   1.1  macallan #define BWI_TXSTATS_NDESC	64
     52   1.1  macallan #define BWI_TX_NSPRDESC		2
     53   1.1  macallan #define BWI_TX_DATA_RING	1
     54   1.1  macallan 
     55   1.1  macallan /* XXX Onoe/Sample/AMRR probably need different configuration */
     56   1.1  macallan #define BWI_SHRETRY		7
     57   1.1  macallan #define BWI_LGRETRY		4
     58   1.1  macallan #define BWI_SHRETRY_FB		3
     59   1.1  macallan #define BWI_LGRETRY_FB		2
     60   1.1  macallan 
     61   1.1  macallan #define BWI_LED_EVENT_NONE	-1
     62   1.1  macallan #define BWI_LED_EVENT_POLL	0
     63   1.1  macallan #define BWI_LED_EVENT_TX	1
     64   1.1  macallan #define BWI_LED_EVENT_RX	2
     65   1.1  macallan #define BWI_LED_SLOWDOWN(dur)	(dur) = (((dur) * 3) / 2)
     66   1.1  macallan 
     67   1.1  macallan enum bwi_txpwrcb_type {
     68   1.1  macallan 	BWI_TXPWR_INIT = 0,
     69   1.1  macallan 	BWI_TXPWR_FORCE = 1,
     70   1.1  macallan 	BWI_TXPWR_CALIB = 2
     71   1.1  macallan };
     72   1.1  macallan 
     73   1.1  macallan #define BWI_NOISE_FLOOR		-95	/* TODO: noise floor calc */
     74   1.1  macallan 
     75   1.2  macallan /* [TRC: Bizarreness.  Cf. bwi_rxeof in OpenBSD's if_bwi.c and
     76   1.2  macallan    DragonFlyBSD's bwi.c.] */
     77   1.2  macallan #define BWI_FRAME_MIN_LEN(hdr)	\
     78   1.2  macallan 	((hdr) + sizeof(struct ieee80211_frame_ack) + IEEE80211_CRC_LEN)
     79   1.2  macallan 
     80   1.1  macallan #define CSR_READ_4(sc, reg)			\
     81  1.11  jmcneill 	_bwi_read_4(sc, reg)
     82   1.1  macallan #define CSR_READ_2(sc, reg)			\
     83  1.11  jmcneill 	_bwi_read_2(sc, reg)
     84  1.11  jmcneill #define CSR_READ_MULTI_4(sc, reg, datap, count)	\
     85  1.11  jmcneill 	_bwi_read_multi_4(sc, reg, datap, count)
     86   1.1  macallan 
     87   1.1  macallan #define CSR_WRITE_4(sc, reg, val)		\
     88  1.11  jmcneill 	_bwi_write_4(sc, reg, val)
     89   1.1  macallan #define CSR_WRITE_2(sc, reg, val)		\
     90  1.11  jmcneill 	_bwi_write_2(sc, reg, val)
     91  1.11  jmcneill #define CSR_WRITE_MULTI_4(sc, reg, datap, count) \
     92  1.11  jmcneill 	_bwi_write_multi_4(sc, reg, datap, count)
     93   1.1  macallan 
     94   1.1  macallan #define CSR_SETBITS_4(sc, reg, bits)		\
     95   1.1  macallan 	CSR_WRITE_4((sc), (reg), CSR_READ_4((sc), (reg)) | (bits))
     96   1.1  macallan #define CSR_SETBITS_2(sc, reg, bits)		\
     97   1.1  macallan 	CSR_WRITE_2((sc), (reg), CSR_READ_2((sc), (reg)) | (bits))
     98   1.1  macallan 
     99   1.1  macallan #define CSR_FILT_SETBITS_4(sc, reg, filt, bits) \
    100   1.1  macallan 	CSR_WRITE_4((sc), (reg), (CSR_READ_4((sc), (reg)) & (filt)) | (bits))
    101   1.1  macallan #define CSR_FILT_SETBITS_2(sc, reg, filt, bits)	\
    102   1.1  macallan 	CSR_WRITE_2((sc), (reg), (CSR_READ_2((sc), (reg)) & (filt)) | (bits))
    103   1.1  macallan 
    104   1.1  macallan #define CSR_CLRBITS_4(sc, reg, bits)		\
    105   1.1  macallan 	CSR_WRITE_4((sc), (reg), CSR_READ_4((sc), (reg)) & ~(bits))
    106   1.1  macallan #define CSR_CLRBITS_2(sc, reg, bits)		\
    107   1.1  macallan 	CSR_WRITE_2((sc), (reg), CSR_READ_2((sc), (reg)) & ~(bits))
    108   1.1  macallan 
    109  1.11  jmcneill struct pool_cache;
    110  1.11  jmcneill struct workqueue;
    111  1.11  jmcneill 
    112   1.1  macallan struct bwi_desc32 {
    113   1.1  macallan 	/* Little endian */
    114   1.1  macallan 	uint32_t	ctrl;
    115   1.1  macallan 	uint32_t	addr;	/* BWI_DESC32_A_ */
    116   1.1  macallan } __packed;
    117   1.1  macallan 
    118   1.1  macallan #define BWI_DESC32_A_FUNC_TXRX		0x1
    119   1.1  macallan #define BWI_DESC32_A_FUNC_MASK		0xc0000000
    120   1.1  macallan #define BWI_DESC32_A_ADDR_MASK		0x3fffffff
    121   1.1  macallan 
    122   1.1  macallan #define BWI_DESC32_C_BUFLEN_MASK	0x00001fff
    123   1.1  macallan #define BWI_DESC32_C_ADDRHI_MASK	0x00030000
    124   1.1  macallan #define BWI_DESC32_C_EOR		(1 << 28)
    125   1.1  macallan #define BWI_DESC32_C_INTR		(1 << 29)
    126   1.1  macallan #define BWI_DESC32_C_FRAME_END		(1 << 30)
    127   1.1  macallan #define BWI_DESC32_C_FRAME_START	(1 << 31)
    128   1.1  macallan 
    129   1.1  macallan struct bwi_desc64 {
    130   1.1  macallan 	/* Little endian */
    131   1.1  macallan 	uint32_t	ctrl0;
    132   1.1  macallan 	uint32_t	ctrl1;
    133   1.1  macallan 	uint32_t	addr_lo;
    134   1.1  macallan 	uint32_t	addr_hi;
    135   1.1  macallan } __packed;
    136   1.1  macallan 
    137   1.1  macallan struct bwi_rxbuf_hdr {
    138   1.1  macallan 	/* Little endian */
    139   1.1  macallan 	uint16_t	rxh_buflen;	/* exclude bwi_rxbuf_hdr */
    140   1.1  macallan 	uint8_t		rxh_pad1[2];
    141   1.1  macallan 	uint16_t	rxh_flags1;
    142   1.1  macallan 	uint8_t		rxh_rssi;
    143   1.1  macallan 	uint8_t		rxh_sq;
    144   1.1  macallan 	uint16_t	rxh_phyinfo;	/* BWI_RXH_PHYINFO_ */
    145   1.1  macallan 	uint16_t	rxh_flags3;
    146   1.1  macallan 	uint16_t	rxh_flags2;	/* BWI_RXH_F2_ */
    147   1.1  macallan 	uint16_t	rxh_tsf;
    148   1.1  macallan 	uint8_t		rxh_pad3[14];	/* Padded to 30bytes */
    149   1.1  macallan } __packed;
    150   1.1  macallan 
    151   1.1  macallan #define BWI_RXH_F1_BCM2053_RSSI (1 << 14)
    152   1.1  macallan #define BWI_RXH_F1_OFDM		(1 << 0)
    153   1.1  macallan 
    154   1.1  macallan #define BWI_RXH_F2_TYPE2FRAME	(1 << 2)
    155  1.11  jmcneill #define BWI_RXH_F2_INVALID	(1 << 0)
    156   1.1  macallan 
    157   1.1  macallan #define BWI_RXH_F3_BCM2050_RSSI	(1 << 10)
    158   1.1  macallan 
    159   1.1  macallan #define BWI_RXH_PHYINFO_LNAGAIN	(3 << 14)
    160   1.1  macallan 
    161   1.1  macallan struct bwi_txbuf_hdr {
    162   1.1  macallan 	/* Little endian */
    163   1.1  macallan 	uint32_t	txh_mac_ctrl;	/* BWI_TXH_MAC_C_ */
    164   1.1  macallan 	uint8_t		txh_fc[2];
    165   1.1  macallan 	uint16_t	txh_unknown1;
    166   1.1  macallan 	uint16_t	txh_phy_ctrl;	/* BWI_TXH_PHY_C_ */
    167   1.1  macallan 	uint8_t		txh_ivs[16];
    168   1.1  macallan 	uint8_t		txh_addr1[IEEE80211_ADDR_LEN];
    169   1.1  macallan 	uint16_t	txh_unknown2;
    170   1.1  macallan 	uint8_t		txh_rts_fb_plcp[4];
    171   1.1  macallan 	uint16_t	txh_rts_fb_duration;
    172   1.1  macallan 	uint8_t		txh_fb_plcp[4];
    173   1.1  macallan 	uint16_t	txh_fb_duration;
    174   1.1  macallan 	uint8_t		txh_pad2[2];
    175   1.1  macallan 	uint16_t	txh_id;		/* BWI_TXH_ID_ */
    176   1.1  macallan 	uint16_t	txh_unknown3;
    177   1.1  macallan 	uint8_t		txh_rts_plcp[6];
    178   1.1  macallan 	uint8_t		txh_rts_fc[2];
    179   1.1  macallan 	uint16_t	txh_rts_duration;
    180   1.1  macallan 	uint8_t		txh_rts_ra[IEEE80211_ADDR_LEN];
    181   1.1  macallan 	uint8_t		txh_rts_ta[IEEE80211_ADDR_LEN];
    182   1.1  macallan 	uint8_t		txh_pad3[2];
    183   1.1  macallan 	uint8_t		txh_plcp[6];
    184   1.1  macallan } __packed;
    185   1.1  macallan 
    186   1.1  macallan #define BWI_TXH_ID_RING_MASK		0xe000
    187   1.1  macallan #define BWI_TXH_ID_IDX_MASK		0x1fff
    188   1.1  macallan 
    189   1.1  macallan #define BWI_TXH_PHY_C_OFDM		(1 << 0)
    190   1.1  macallan #define BWI_TXH_PHY_C_SHPREAMBLE	(1 << 4)
    191   1.1  macallan #define BWI_TXH_PHY_C_ANTMODE_MASK	0x0300
    192   1.1  macallan 
    193   1.1  macallan #define BWI_TXH_MAC_C_ACK		(1 << 0)
    194   1.1  macallan #define BWI_TXH_MAC_C_FIRST_FRAG	(1 << 3)
    195   1.1  macallan #define BWI_TXH_MAC_C_HWSEQ		(1 << 4)
    196   1.1  macallan #define BWI_TXH_MAC_C_FB_OFDM		(1 << 8)
    197   1.1  macallan 
    198   1.1  macallan struct bwi_txstats {
    199   1.1  macallan 	/* Little endian */
    200   1.1  macallan 	uint8_t		txs_pad1[4];
    201   1.1  macallan 	uint16_t	txs_id;
    202   1.1  macallan 	uint8_t		txs_flags;
    203   1.1  macallan 	uint8_t		txs_retry_cnt;
    204   1.1  macallan 	uint8_t		txs_pad2[2];
    205   1.1  macallan 	uint16_t	txs_seq;
    206   1.1  macallan 	uint16_t	txs_unknown;
    207   1.1  macallan 	uint8_t		txs_pad3[2];	/* Padded to 16bytes */
    208   1.1  macallan } __packed;
    209   1.1  macallan 
    210   1.1  macallan struct bwi_ring_data {
    211   1.1  macallan 	uint32_t		 rdata_txrx_ctrl;
    212   1.1  macallan 	bus_dma_segment_t	 rdata_seg;
    213   1.1  macallan 	bus_dmamap_t		 rdata_dmap;
    214   1.1  macallan 	bus_addr_t		 rdata_paddr;
    215   1.1  macallan 	void			*rdata_desc;
    216   1.1  macallan };
    217   1.1  macallan 
    218  1.11  jmcneill struct bwi_txbuf_data;
    219  1.11  jmcneill 
    220   1.1  macallan struct bwi_txbuf {
    221   1.1  macallan 	struct mbuf		*tb_mbuf;
    222   1.1  macallan 	bus_dmamap_t		 tb_dmap;
    223   1.1  macallan 
    224   1.1  macallan 	struct ieee80211_node	*tb_ni;
    225   1.1  macallan 	int			 tb_rate_idx[2];
    226  1.11  jmcneill 
    227  1.11  jmcneill 	struct bwi_txbuf_data	*tb_data;
    228  1.11  jmcneill 	STAILQ_ENTRY(bwi_txbuf)	 tb_entry;
    229   1.1  macallan };
    230   1.1  macallan 
    231   1.1  macallan struct bwi_txbuf_data {
    232   1.1  macallan 	struct bwi_txbuf	tbd_buf[BWI_TX_NDESC];
    233   1.1  macallan 	int			tbd_used;
    234   1.1  macallan 	int			tbd_idx;
    235   1.1  macallan };
    236   1.1  macallan 
    237   1.1  macallan struct bwi_rxbuf {
    238   1.1  macallan 	struct mbuf		*rb_mbuf;
    239   1.1  macallan 	bus_addr_t		 rb_paddr;
    240   1.1  macallan 	bus_dmamap_t		 rb_dmap;
    241   1.1  macallan };
    242   1.1  macallan 
    243   1.1  macallan struct bwi_rxbuf_data {
    244   1.1  macallan 	struct bwi_rxbuf	rbd_buf[BWI_RX_NDESC];
    245   1.1  macallan 	bus_dmamap_t		rbd_tmp_dmap;
    246   1.1  macallan 	int			rbd_idx;
    247   1.1  macallan };
    248   1.1  macallan 
    249   1.1  macallan struct bwi_txstats_data {
    250   1.1  macallan 	bus_dma_segment_t	 stats_ring_seg;
    251   1.1  macallan 	bus_dmamap_t		 stats_ring_dmap;
    252   1.1  macallan 	bus_addr_t		 stats_ring_paddr;
    253   1.1  macallan 	void			*stats_ring;
    254   1.1  macallan 
    255   1.1  macallan 	bus_dma_segment_t	 stats_seg;
    256   1.1  macallan 	bus_dmamap_t		 stats_dmap;
    257   1.1  macallan 	bus_addr_t		 stats_paddr;
    258   1.1  macallan 	struct bwi_txstats	*stats;
    259   1.1  macallan 
    260   1.1  macallan 	uint32_t		 stats_ctrl_base;
    261   1.1  macallan 	int			 stats_idx;
    262   1.1  macallan };
    263   1.1  macallan 
    264   1.1  macallan struct bwi_fwhdr {
    265   1.1  macallan 	/* Big endian */
    266   1.1  macallan 	uint8_t		fw_type;	/* BWI_FW_T_ */
    267   1.1  macallan 	uint8_t		fw_gen;		/* BWI_FW_GEN */
    268   1.1  macallan 	uint8_t		fw_pad[2];
    269   1.1  macallan 	uint32_t	fw_size;
    270   1.1  macallan #define fw_iv_cnt	fw_size
    271   1.1  macallan } __packed;
    272   1.1  macallan 
    273   1.1  macallan #define BWI_FWHDR_SZ		sizeof(struct bwi_fwhdr)
    274   1.1  macallan #define BWI_FW_VERSION3		3
    275   1.1  macallan #define BWI_FW_VERSION4		4
    276   1.1  macallan #define BWI_FW_VERSION3_REVMAX	0x128
    277   1.1  macallan #define BWI_FW_T_UCODE          'u'
    278   1.1  macallan #define BWI_FW_T_PCM            'p'
    279   1.1  macallan #define BWI_FW_T_IV             'i'
    280   1.1  macallan #define BWI_FW_GEN_1            1
    281   1.1  macallan #define BWI_FW_IV_OFS_MASK	0x7fff
    282   1.1  macallan #define BWI_FW_IV_IS_32BIT	(1 << 15)
    283   1.1  macallan 
    284   1.2  macallan #define BWI_FW_NAME_FORMAT	"v%d/%s%d.fw"
    285   1.2  macallan #define BWI_FW_UCODE_PREFIX	"ucode"
    286   1.2  macallan #define BWI_FW_PCM_PREFIX	"pcm"
    287   1.2  macallan #define BWI_FW_IV_PREFIX	"b0g0initvals"
    288   1.2  macallan #define BWI_FW_IV_EXT_PREFIX	"b0g0bsinitvals"
    289   1.2  macallan 
    290   1.2  macallan struct bwi_fw_image {
    291   1.2  macallan 	char	 fwi_name[64];
    292   1.2  macallan 	uint8_t	*fwi_data;
    293   1.2  macallan 	size_t	 fwi_size;
    294   1.1  macallan };
    295   1.1  macallan 
    296   1.1  macallan struct bwi_fw_iv {
    297   1.1  macallan 	/* Big endian */
    298   1.1  macallan 	uint16_t		iv_ofs;
    299   1.1  macallan 	union {
    300   1.1  macallan 		uint32_t	val32;
    301   1.1  macallan 		uint16_t	val16;
    302   1.1  macallan 	}			iv_val;
    303   1.1  macallan } __packed;
    304   1.1  macallan 
    305   1.1  macallan struct bwi_led {
    306   1.1  macallan 	uint8_t			l_flags;	/* BWI_LED_F_ */
    307   1.1  macallan 	uint8_t			l_act;		/* BWI_LED_ACT_ */
    308   1.1  macallan 	uint8_t			l_mask;
    309   1.1  macallan };
    310   1.1  macallan 
    311   1.1  macallan #define BWI_LED_F_ACTLOW	0x1
    312   1.1  macallan #define BWI_LED_F_BLINK		0x2
    313   1.1  macallan #define BWI_LED_F_POLLABLE	0x4
    314   1.1  macallan #define BWI_LED_F_SLOW		0x8
    315   1.1  macallan 
    316   1.1  macallan enum bwi_clock_mode {
    317   1.1  macallan 	BWI_CLOCK_MODE_SLOW,
    318   1.1  macallan 	BWI_CLOCK_MODE_FAST,
    319   1.1  macallan 	BWI_CLOCK_MODE_DYN
    320   1.1  macallan };
    321   1.1  macallan 
    322   1.1  macallan struct bwi_regwin {
    323   1.1  macallan 	uint32_t		rw_flags;	/* BWI_REGWIN_F_ */
    324   1.1  macallan 	uint16_t		rw_type;	/* BWI_REGWIN_T_ */
    325   1.1  macallan 	uint8_t			rw_id;
    326   1.1  macallan 	uint8_t			rw_rev;
    327   1.1  macallan };
    328   1.1  macallan 
    329   1.1  macallan #define BWI_REGWIN_F_EXIST	0x1
    330   1.1  macallan 
    331   1.1  macallan #define BWI_CREATE_REGWIN(rw, id, type, rev)	\
    332   1.1  macallan do {						\
    333   1.1  macallan 	(rw)->rw_flags = BWI_REGWIN_F_EXIST;	\
    334   1.1  macallan 	(rw)->rw_type = (type);			\
    335   1.1  macallan 	(rw)->rw_id = (id);			\
    336   1.1  macallan 	(rw)->rw_rev = (rev);			\
    337   1.1  macallan } while (0)
    338   1.1  macallan 
    339   1.1  macallan #define BWI_REGWIN_EXIST(rw)	((rw)->rw_flags & BWI_REGWIN_F_EXIST)
    340   1.1  macallan #define BWI_GPIO_REGWIN(sc)				\
    341   1.1  macallan 	(BWI_REGWIN_EXIST(&(sc)->sc_com_regwin) ?	\
    342   1.1  macallan 	&(sc)->sc_com_regwin : &(sc)->sc_bus_regwin)
    343   1.1  macallan 
    344   1.1  macallan struct bwi_mac;
    345   1.1  macallan 
    346   1.1  macallan struct bwi_phy {
    347   1.1  macallan 	enum ieee80211_phymode	phy_mode;
    348   1.1  macallan 	int			phy_rev;
    349   1.1  macallan 	int			phy_version;
    350   1.1  macallan 
    351   1.1  macallan 	uint32_t		phy_flags;		/* BWI_PHY_F_ */
    352   1.1  macallan 	uint16_t		phy_tbl_ctrl;
    353   1.1  macallan 	uint16_t		phy_tbl_data_lo;
    354   1.1  macallan 	uint16_t		phy_tbl_data_hi;
    355   1.1  macallan 
    356   1.1  macallan 	void			(*phy_init)(struct bwi_mac *);
    357   1.1  macallan };
    358   1.1  macallan 
    359   1.1  macallan #define BWI_PHY_F_CALIBRATED	0x1
    360   1.1  macallan #define BWI_PHY_F_LINKED	0x2
    361   1.1  macallan #define BWI_CLEAR_PHY_FLAGS	(BWI_PHY_F_CALIBRATED)
    362   1.1  macallan 
    363   1.1  macallan /* TX power control */
    364   1.1  macallan struct bwi_tpctl {
    365   1.1  macallan 	uint16_t		bbp_atten;	/* BBP attenuation: 4bits */
    366   1.1  macallan 	uint16_t		rf_atten;	/* RF attenuation */
    367   1.1  macallan 	uint16_t		tp_ctrl1;	/* ??: 3bits */
    368   1.1  macallan 	uint16_t		tp_ctrl2;	/* ??: 4bits */
    369   1.1  macallan };
    370   1.1  macallan 
    371   1.1  macallan #define BWI_RF_ATTEN_FACTOR	4
    372   1.1  macallan #define BWI_RF_ATTEN_MAX0	9
    373   1.1  macallan #define BWI_RF_ATTEN_MAX1	31
    374   1.1  macallan #define BWI_BBP_ATTEN_MAX	11
    375   1.1  macallan #define BWI_TPCTL1_MAX		7
    376   1.1  macallan 
    377   1.1  macallan struct bwi_rf_lo {
    378   1.1  macallan 	int8_t			ctrl_lo;
    379   1.1  macallan 	int8_t			ctrl_hi;
    380   1.1  macallan };
    381   1.1  macallan 
    382   1.1  macallan struct bwi_rf {
    383   1.1  macallan 	uint16_t		rf_type;	/* BWI_RF_T_ */
    384   1.1  macallan 	uint16_t		rf_manu;
    385   1.1  macallan 	int			rf_rev;
    386   1.1  macallan 
    387   1.1  macallan 	uint32_t		rf_flags;	/* BWI_RF_F_ */
    388   1.1  macallan 
    389   1.1  macallan #define BWI_RFLO_MAX		56
    390   1.1  macallan 	struct bwi_rf_lo	rf_lo[BWI_RFLO_MAX];
    391   1.1  macallan 	uint8_t			rf_lo_used[8];
    392   1.1  macallan 
    393   1.1  macallan #define BWI_INVALID_NRSSI	-1000
    394   1.1  macallan 	int16_t			rf_nrssi[2];	/* Narrow RSSI */
    395   1.1  macallan 	int32_t			rf_nrssi_slope;
    396   1.1  macallan 
    397   1.1  macallan #define BWI_NRSSI_TBLSZ		64
    398   1.1  macallan 	int8_t			rf_nrssi_table[BWI_NRSSI_TBLSZ];
    399   1.1  macallan 
    400   1.1  macallan 	uint16_t		rf_lo_gain;	/* loopback gain */
    401   1.1  macallan 	uint16_t		rf_rx_gain;	/* TRSW RX gain */
    402   1.1  macallan 
    403   1.1  macallan 	uint16_t		rf_calib;	/* RF calibration value */
    404   1.1  macallan 	uint			rf_curchan;	/* current channel */
    405   1.1  macallan 
    406   1.1  macallan 	uint16_t		rf_ctrl_rd;
    407   1.1  macallan 	int			rf_ctrl_adj;
    408   1.1  macallan 	void			(*rf_off)(struct bwi_mac *);
    409   1.1  macallan 	void			(*rf_on)(struct bwi_mac *);
    410   1.1  macallan 
    411   1.1  macallan 	void			(*rf_set_nrssi_thr)(struct bwi_mac *);
    412   1.1  macallan 	void			(*rf_calc_nrssi_slope)(struct bwi_mac *);
    413   1.1  macallan 	int			(*rf_calc_rssi)
    414   1.1  macallan 				(struct bwi_mac *,
    415   1.1  macallan 				 const struct bwi_rxbuf_hdr *);
    416   1.1  macallan 
    417   1.1  macallan 	void			(*rf_lo_update)(struct bwi_mac *);
    418   1.1  macallan 
    419   1.1  macallan #define BWI_TSSI_MAX		64
    420   1.1  macallan 	int8_t			rf_txpower_map0[BWI_TSSI_MAX];
    421   1.1  macallan 						/* Indexed by TSSI */
    422   1.1  macallan 	int			rf_idle_tssi0;
    423   1.1  macallan 
    424   1.1  macallan 	int8_t			rf_txpower_map[BWI_TSSI_MAX];
    425   1.1  macallan 	int			rf_idle_tssi;
    426   1.1  macallan 
    427   1.1  macallan 	int			rf_base_tssi;
    428   1.1  macallan 
    429   1.1  macallan 	int			rf_txpower_max;	/* dBm */
    430   1.1  macallan 
    431   1.1  macallan 	int			rf_ant_mode;	/* BWI_ANT_MODE_ */
    432   1.1  macallan };
    433   1.1  macallan 
    434   1.1  macallan #define BWI_RF_F_INITED		0x1
    435   1.1  macallan #define BWI_RF_F_ON		0x2
    436   1.1  macallan #define BWI_RF_CLEAR_FLAGS	(BWI_RF_F_INITED)
    437   1.1  macallan 
    438   1.1  macallan #define BWI_ANT_MODE_0		0
    439   1.1  macallan #define BWI_ANT_MODE_1		1
    440   1.1  macallan #define BWI_ANT_MODE_UNKN	2
    441   1.1  macallan #define BWI_ANT_MODE_AUTO	3
    442   1.1  macallan 
    443   1.1  macallan struct fw_image;
    444   1.1  macallan 
    445   1.1  macallan struct bwi_mac {
    446   1.1  macallan 	struct bwi_regwin	 mac_regwin;	/* MUST be first field */
    447   1.1  macallan #define mac_rw_flags		 mac_regwin.rw_flags
    448   1.1  macallan #define mac_type		 mac_regwin.rw_type
    449   1.1  macallan #define mac_id			 mac_regwin.rw_id
    450   1.1  macallan #define mac_rev			 mac_regwin.rw_rev
    451   1.1  macallan 	struct bwi_softc	*mac_sc;
    452   1.1  macallan 
    453   1.1  macallan 	struct bwi_phy		 mac_phy;	/* PHY I/F */
    454   1.1  macallan 	struct bwi_rf		 mac_rf;	/* RF I/F */
    455   1.1  macallan 
    456   1.1  macallan 	struct bwi_tpctl	 mac_tpctl;	/* TX power control */
    457   1.1  macallan 	uint32_t		 mac_flags;	/* BWI_MAC_F_ */
    458   1.1  macallan 
    459   1.2  macallan 	struct bwi_fw_image	 mac_ucode_fwi;
    460   1.2  macallan 	struct bwi_fw_image	 mac_pcm_fwi;
    461   1.2  macallan 	struct bwi_fw_image	 mac_iv_fwi;
    462   1.2  macallan 	struct bwi_fw_image	 mac_iv_ext_fwi;
    463   1.1  macallan };
    464   1.1  macallan 
    465   1.2  macallan #define mac_ucode mac_ucode_fwi.fwi_data
    466   1.2  macallan #define mac_ucode_size mac_ucode_fwi.fwi_size
    467   1.2  macallan #define mac_pcm mac_pcm_fwi.fwi_data
    468   1.2  macallan #define mac_pcm_size mac_pcm_fwi.fwi_size
    469   1.2  macallan #define mac_iv mac_iv_fwi.fwi_data
    470   1.2  macallan #define mac_iv_size mac_iv_fwi.fwi_size
    471   1.2  macallan #define mac_iv_ext mac_iv_ext_fwi.fwi_data
    472   1.2  macallan #define mac_iv_ext_size mac_iv_ext_fwi.fwi_size
    473   1.2  macallan 
    474   1.1  macallan #define BWI_MAC_F_BSWAP		0x1
    475   1.1  macallan #define BWI_MAC_F_TPCTL_INITED	0x2
    476   1.1  macallan #define BWI_MAC_F_HAS_TXSTATS	0x4
    477   1.1  macallan #define BWI_MAC_F_INITED	0x8
    478   1.1  macallan #define BWI_MAC_F_ENABLED	0x10
    479   1.1  macallan #define BWI_MAC_F_LOCKED	0x20	/* for debug */
    480   1.1  macallan #define BWI_MAC_F_TPCTL_ERROR	0x40
    481   1.1  macallan #define BWI_MAC_F_PHYE_RESET	0x80
    482   1.1  macallan 
    483   1.1  macallan #define BWI_CREATE_MAC(mac, sc, id, rev)	\
    484   1.1  macallan do {						\
    485   1.1  macallan 	BWI_CREATE_REGWIN(&(mac)->mac_regwin,	\
    486   1.1  macallan 	    (id), BWI_REGWIN_T_MAC, (rev));	\
    487   1.1  macallan 	(mac)->mac_sc = (sc);			\
    488   1.1  macallan } while (0)
    489   1.1  macallan 
    490   1.1  macallan #define BWI_MAC_MAX		2
    491   1.1  macallan #define BWI_LED_MAX		4
    492   1.1  macallan 
    493   1.1  macallan enum bwi_bus_space {
    494   1.1  macallan 	BWI_BUS_SPACE_30BIT = 1,
    495   1.1  macallan 	BWI_BUS_SPACE_32BIT,
    496   1.1  macallan 	BWI_BUS_SPACE_64BIT
    497   1.1  macallan };
    498   1.1  macallan 
    499   1.1  macallan #define BWI_TX_RADIOTAP_PRESENT 		\
    500   1.1  macallan 	((1 << IEEE80211_RADIOTAP_FLAGS) |	\
    501   1.1  macallan 	 (1 << IEEE80211_RADIOTAP_RATE) |	\
    502   1.1  macallan 	 (1 << IEEE80211_RADIOTAP_CHANNEL))
    503   1.1  macallan 
    504   1.1  macallan struct bwi_tx_radiotap_hdr {
    505   1.1  macallan 	struct ieee80211_radiotap_header wt_ihdr;
    506   1.1  macallan 	uint8_t		wt_flags;
    507   1.1  macallan 	uint8_t		wt_rate;
    508   1.1  macallan 	uint16_t	wt_chan_freq;
    509   1.1  macallan 	uint16_t	wt_chan_flags;
    510   1.1  macallan };
    511   1.1  macallan 
    512   1.1  macallan #define BWI_RX_RADIOTAP_PRESENT				\
    513   1.1  macallan 	((1 << IEEE80211_RADIOTAP_TSFT) |		\
    514   1.1  macallan 	 (1 << IEEE80211_RADIOTAP_FLAGS) |		\
    515   1.1  macallan 	 (1 << IEEE80211_RADIOTAP_RATE) |		\
    516   1.1  macallan 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |		\
    517   1.1  macallan 	 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |	\
    518   1.1  macallan 	 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE))
    519   1.1  macallan 
    520   1.1  macallan struct bwi_rx_radiotap_hdr {
    521   1.1  macallan 	struct ieee80211_radiotap_header wr_ihdr;
    522   1.1  macallan 	uint64_t	wr_tsf;
    523   1.1  macallan 	uint8_t		wr_flags;
    524   1.1  macallan 	uint8_t		wr_rate;
    525   1.1  macallan 	uint16_t	wr_chan_freq;
    526   1.1  macallan 	uint16_t	wr_chan_flags;
    527   1.1  macallan 	int8_t		wr_antsignal;
    528   1.1  macallan 	int8_t		wr_antnoise;
    529   1.1  macallan 	/* TODO: sq */
    530   1.1  macallan };
    531   1.1  macallan 
    532   1.2  macallan /* [TRC: XXX amrr] */
    533   1.1  macallan struct bwi_node {
    534   1.1  macallan 	struct ieee80211_node		ni;
    535   1.1  macallan 	struct ieee80211_amrr_node	amn;
    536   1.1  macallan };
    537   1.1  macallan 
    538  1.11  jmcneill enum bwi_task_cmd {
    539  1.11  jmcneill 	BWI_TASK_NEWSTATE,
    540  1.11  jmcneill 	BWI_TASK_UPDATESLOT,
    541  1.11  jmcneill 	BWI_TASK_TX,
    542  1.11  jmcneill 	BWI_TASK_INIT,
    543  1.11  jmcneill 	BWI_TASK_CALIBRATE,
    544  1.11  jmcneill };
    545  1.11  jmcneill 
    546  1.11  jmcneill #define BWI_TASK_COUNT		64
    547  1.11  jmcneill 
    548  1.11  jmcneill struct bwi_task {
    549  1.11  jmcneill 	struct work		 t_work;
    550  1.11  jmcneill 	struct ieee80211com	*t_ic;
    551  1.11  jmcneill 	enum bwi_task_cmd	 t_cmd;
    552  1.11  jmcneill 	union {
    553  1.11  jmcneill 		struct {
    554  1.11  jmcneill 			enum ieee80211_state state;
    555  1.11  jmcneill 			int	 arg;
    556  1.11  jmcneill 		} t_newstate;
    557  1.11  jmcneill 	};
    558  1.11  jmcneill };
    559  1.11  jmcneill 
    560   1.1  macallan struct bwi_softc {
    561   1.4    cegger 	device_t		 sc_dev;
    562   1.2  macallan 	struct ethercom		 sc_ec;
    563   1.1  macallan 	struct ieee80211com	 sc_ic;
    564   1.2  macallan #define sc_if sc_ec.ec_if
    565   1.1  macallan 	uint32_t		 sc_flags;	/* BWI_F_ */
    566   1.2  macallan 	void			*sc_ih;		/* [TRC: interrupt handler] */
    567  1.10    nonaka 	void			*sc_soft_ih;
    568   1.1  macallan 
    569   1.1  macallan 	uint32_t		 sc_cap;	/* BWI_CAP_ */
    570   1.1  macallan 	uint16_t		 sc_bbp_id;	/* BWI_BBPID_ */
    571   1.1  macallan 	uint8_t			 sc_bbp_rev;
    572   1.1  macallan 	uint8_t			 sc_bbp_pkg;
    573   1.1  macallan 
    574   1.1  macallan 	uint8_t			 sc_pci_revid;
    575   1.1  macallan 	uint16_t		 sc_pci_did;
    576   1.1  macallan 	uint16_t		 sc_pci_subvid;
    577   1.1  macallan 	uint16_t		 sc_pci_subdid;
    578   1.1  macallan 
    579   1.1  macallan 	uint16_t		 sc_card_flags;	/* BWI_CARD_F_ */
    580   1.1  macallan 	uint16_t		 sc_pwron_delay;
    581   1.1  macallan 	int			 sc_locale;
    582   1.1  macallan 
    583   1.2  macallan 	/* [TRC: No clue what these are for.]
    584   1.1  macallan 	int			 sc_irq_rid;
    585   1.1  macallan 	struct resource		*sc_irq_res;
    586   1.1  macallan 	void			*sc_irq_handle;
    587   1.2  macallan 	*/
    588   1.1  macallan 
    589   1.2  macallan 	/* [TRC: Likewise.]
    590   1.1  macallan 	int			 sc_mem_rid;
    591   1.1  macallan 	struct resource		*sc_mem_res;
    592   1.2  macallan 	*/
    593   1.1  macallan 	bus_dma_tag_t		 sc_dmat;
    594   1.1  macallan 	bus_space_tag_t		 sc_mem_bt;
    595   1.1  macallan 	bus_space_handle_t	 sc_mem_bh;
    596   1.1  macallan 
    597   1.2  macallan 	struct callout		 sc_scan_ch;
    598   1.2  macallan 	struct callout		 sc_calib_ch;
    599   1.1  macallan 
    600   1.2  macallan 	/* [TRC: XXX amrr] */
    601   1.2  macallan 	struct callout		 sc_amrr_ch;
    602   1.1  macallan 	struct ieee80211_amrr	 sc_amrr;
    603   1.1  macallan 
    604   1.1  macallan 	struct bwi_regwin	*sc_cur_regwin;
    605   1.1  macallan 	struct bwi_regwin	 sc_com_regwin;
    606   1.1  macallan 	struct bwi_regwin	 sc_bus_regwin;
    607   1.1  macallan 
    608   1.1  macallan 	int			 sc_nmac;
    609   1.1  macallan 	struct bwi_mac		 sc_mac[BWI_MAC_MAX];
    610   1.1  macallan 
    611   1.1  macallan 	int			 sc_rx_rate;
    612   1.1  macallan 	int			 sc_tx_rate;
    613   1.1  macallan 	enum bwi_txpwrcb_type	 sc_txpwrcb_type;
    614   1.1  macallan 
    615   1.1  macallan 	int			 sc_led_blinking;
    616   1.1  macallan 	int			 sc_led_ticks;
    617   1.1  macallan 	struct bwi_led		*sc_blink_led;
    618   1.2  macallan 	struct callout		 sc_led_blink_ch;
    619   1.1  macallan 	int			 sc_led_blink_offdur;
    620   1.1  macallan 	struct bwi_led		 sc_leds[BWI_LED_MAX];
    621   1.1  macallan 
    622   1.1  macallan 	enum bwi_bus_space	 sc_bus_space;
    623   1.1  macallan 
    624   1.1  macallan 	struct bwi_txbuf_data	 sc_tx_bdata[BWI_TX_NRING];
    625   1.1  macallan 	struct bwi_rxbuf_data	 sc_rx_bdata;
    626   1.1  macallan 
    627   1.1  macallan 	struct bwi_ring_data	 sc_tx_rdata[BWI_TX_NRING];
    628   1.1  macallan 	struct bwi_ring_data	 sc_rx_rdata;
    629   1.1  macallan 
    630   1.1  macallan 	struct bwi_txstats_data	*sc_txstats;
    631   1.1  macallan 
    632   1.1  macallan 	int			 sc_tx_timer;
    633   1.1  macallan 
    634   1.1  macallan 	int			 (*sc_newstate)
    635   1.1  macallan 				 (struct ieee80211com *,
    636   1.1  macallan 				     enum ieee80211_state, int);
    637   1.1  macallan 
    638   1.1  macallan 	int			 (*sc_init_tx_ring)(struct bwi_softc *, int);
    639   1.1  macallan 	void			 (*sc_free_tx_ring)(struct bwi_softc *, int);
    640   1.1  macallan 
    641   1.1  macallan 	int			 (*sc_init_rx_ring)(struct bwi_softc *);
    642   1.1  macallan 	void			 (*sc_free_rx_ring)(struct bwi_softc *);
    643   1.1  macallan 
    644   1.1  macallan 	int			 (*sc_init_txstats)(struct bwi_softc *);
    645   1.1  macallan 	void			 (*sc_free_txstats)(struct bwi_softc *);
    646   1.1  macallan 
    647   1.1  macallan 	void			 (*sc_setup_rxdesc)
    648   1.1  macallan 				 (struct bwi_softc *, int, bus_addr_t, int);
    649   1.1  macallan 	int			 (*sc_rxeof)(struct bwi_softc *);
    650   1.1  macallan 
    651   1.1  macallan 	void			 (*sc_setup_txdesc)
    652   1.1  macallan 				 (struct bwi_softc *, struct bwi_ring_data *,
    653   1.1  macallan 				     int, bus_addr_t, int);
    654   1.1  macallan 	void			 (*sc_start_tx)
    655   1.1  macallan 				 (struct bwi_softc *, uint32_t, int);
    656   1.1  macallan 
    657   1.1  macallan 	void			 (*sc_txeof_status)(struct bwi_softc *);
    658   1.1  macallan 
    659   1.9  nakayama 	int			 (*sc_enable)(struct bwi_softc *, int);
    660   1.9  nakayama 	void			 (*sc_disable)(struct bwi_softc *, int);
    661   1.1  macallan 
    662   1.1  macallan 	void			 (*sc_conf_write)(void *, uint32_t, uint32_t);
    663   1.1  macallan 	uint32_t		 (*sc_conf_read)(void *, uint32_t);
    664   1.1  macallan 
    665  1.11  jmcneill 	void			 (*sc_reg_write_2)(void *, uint32_t, uint16_t);
    666  1.11  jmcneill 	uint16_t		 (*sc_reg_read_2)(void *, uint32_t);
    667  1.11  jmcneill 	void			 (*sc_reg_write_4)(void *, uint32_t, uint32_t);
    668  1.11  jmcneill 	uint32_t		 (*sc_reg_read_4)(void *, uint32_t);
    669  1.11  jmcneill 
    670  1.11  jmcneill 	void			 (*sc_reg_write_multi_4)(void *, uint32_t,
    671  1.11  jmcneill 				     const uint32_t *, size_t);
    672  1.11  jmcneill 	void			 (*sc_reg_read_multi_4)(void *, uint32_t,
    673  1.11  jmcneill 				     uint32_t *, size_t);
    674  1.11  jmcneill 
    675  1.11  jmcneill 	struct pool_cache	*sc_freetask;
    676  1.11  jmcneill 	struct workqueue	*sc_taskq;
    677  1.11  jmcneill 	uint8_t			*sc_pio_databuf;
    678  1.11  jmcneill 	kmutex_t		 sc_pio_txlock;
    679  1.11  jmcneill 	STAILQ_HEAD(, bwi_txbuf) sc_pio_txpend;
    680  1.11  jmcneill 	size_t			 sc_pio_fifolen;
    681  1.11  jmcneill 	size_t			 sc_pio_fifoavail;
    682  1.11  jmcneill 
    683   1.2  macallan 	struct sysctllog	*sc_sysctllog;
    684   1.2  macallan 
    685   1.1  macallan 	/* Sysctl variables */
    686   1.1  macallan 	int			 sc_fw_version;	/* BWI_FW_VERSION[34] */
    687   1.1  macallan 	int			 sc_dwell_time;	/* milliseconds */
    688   1.1  macallan 	int			 sc_led_idle;
    689   1.1  macallan 	int			 sc_led_blink;
    690   1.2  macallan 	int			 sc_txpwr_calib;
    691   1.2  macallan 	int			 sc_debug;	/* BWI_DBG_ */
    692   1.1  macallan 
    693   1.2  macallan 	struct bpf_if		*sc_drvbpf;
    694   1.1  macallan 
    695   1.2  macallan 	union {
    696   1.2  macallan 		struct bwi_rx_radiotap_hdr th;
    697   1.2  macallan 		uint8_t pad[64];
    698   1.2  macallan 	}			 sc_rxtapu;
    699   1.2  macallan #define sc_rxtap		 sc_rxtapu.th
    700   1.2  macallan 	int			 sc_rxtap_len;
    701   1.1  macallan 
    702   1.2  macallan 	union {
    703   1.2  macallan 		struct bwi_tx_radiotap_hdr th;
    704   1.2  macallan 		uint8_t pad[64];
    705   1.2  macallan 	}			 sc_txtapu;
    706   1.2  macallan #define sc_txtap		 sc_txtapu.th
    707   1.2  macallan 	int			 sc_txtap_len;
    708   1.1  macallan };
    709   1.1  macallan 
    710  1.11  jmcneill static inline void
    711  1.11  jmcneill _bwi_read_multi_4(struct bwi_softc *sc, bus_size_t reg, uint32_t *datap,
    712  1.11  jmcneill     bus_size_t count)
    713  1.11  jmcneill {
    714  1.11  jmcneill 	if (sc->sc_reg_read_multi_4 != NULL) {
    715  1.11  jmcneill 		return sc->sc_reg_read_multi_4(sc, reg, datap, count);
    716  1.11  jmcneill 	} else {
    717  1.11  jmcneill 		return bus_space_read_multi_4(sc->sc_mem_bt, sc->sc_mem_bh,
    718  1.11  jmcneill 		    reg, datap, count);
    719  1.11  jmcneill 	}
    720  1.11  jmcneill }
    721  1.11  jmcneill 
    722  1.11  jmcneill static inline uint16_t
    723  1.11  jmcneill _bwi_read_2(struct bwi_softc *sc, bus_size_t reg)
    724  1.11  jmcneill {
    725  1.11  jmcneill 	if (sc->sc_reg_read_2 != NULL) {
    726  1.11  jmcneill 		return sc->sc_reg_read_2(sc, reg);
    727  1.11  jmcneill 	} else {
    728  1.11  jmcneill 		return bus_space_read_2(sc->sc_mem_bt, sc->sc_mem_bh, reg);
    729  1.11  jmcneill 	}
    730  1.11  jmcneill }
    731  1.11  jmcneill 
    732  1.11  jmcneill static inline uint32_t
    733  1.11  jmcneill _bwi_read_4(struct bwi_softc *sc, bus_size_t reg)
    734  1.11  jmcneill {
    735  1.11  jmcneill 	if (sc->sc_reg_read_4 != NULL) {
    736  1.11  jmcneill 		return sc->sc_reg_read_4(sc, reg);
    737  1.11  jmcneill 	} else {
    738  1.11  jmcneill 		return bus_space_read_4(sc->sc_mem_bt, sc->sc_mem_bh, reg);
    739  1.11  jmcneill 	}
    740  1.11  jmcneill }
    741  1.11  jmcneill 
    742  1.11  jmcneill static inline void
    743  1.11  jmcneill _bwi_write_multi_4(struct bwi_softc *sc, bus_size_t reg, const uint32_t *datap,
    744  1.11  jmcneill     bus_size_t count)
    745  1.11  jmcneill {
    746  1.11  jmcneill 	if (sc->sc_reg_read_multi_4 != NULL) {
    747  1.11  jmcneill 		return sc->sc_reg_write_multi_4(sc, reg, datap, count);
    748  1.11  jmcneill 	} else {
    749  1.11  jmcneill 		return bus_space_write_multi_4(sc->sc_mem_bt, sc->sc_mem_bh,
    750  1.11  jmcneill 		    reg, datap, count);
    751  1.11  jmcneill 	}
    752  1.11  jmcneill }
    753  1.11  jmcneill 
    754  1.11  jmcneill static inline void
    755  1.11  jmcneill _bwi_write_2(struct bwi_softc *sc, bus_size_t reg, uint16_t val)
    756  1.11  jmcneill {
    757  1.11  jmcneill 	if (sc->sc_reg_write_2 != NULL) {
    758  1.11  jmcneill 		sc->sc_reg_write_2(sc, reg, val);
    759  1.11  jmcneill 	} else {
    760  1.11  jmcneill 		bus_space_write_2(sc->sc_mem_bt, sc->sc_mem_bh, reg, val);
    761  1.11  jmcneill 	}
    762  1.11  jmcneill }
    763  1.11  jmcneill 
    764  1.11  jmcneill static inline void
    765  1.11  jmcneill _bwi_write_4(struct bwi_softc *sc, bus_size_t reg, uint32_t val)
    766  1.11  jmcneill {
    767  1.11  jmcneill 	if (sc->sc_reg_write_4 != NULL) {
    768  1.11  jmcneill 		sc->sc_reg_write_4(sc, reg, val);
    769  1.11  jmcneill 	} else {
    770  1.11  jmcneill 		bus_space_write_4(sc->sc_mem_bt, sc->sc_mem_bh, reg, val);
    771  1.11  jmcneill 	}
    772  1.11  jmcneill }
    773  1.11  jmcneill 
    774   1.1  macallan #define BWI_F_BUS_INITED	0x1
    775   1.1  macallan #define BWI_F_PROMISC		0x2
    776  1.11  jmcneill #define BWI_F_SDIO		0x4
    777  1.11  jmcneill #define BWI_F_PIO		0x8
    778  1.11  jmcneill 
    779  1.11  jmcneill #define BWI_IS_SDIO(sc)		ISSET((sc)->sc_flags, BWI_F_SDIO)
    780  1.11  jmcneill #define BWI_IS_PIO(sc)		ISSET((sc)->sc_flags, BWI_F_PIO)
    781   1.1  macallan 
    782   1.2  macallan #define BWI_DBG_MAC		0x00000001
    783   1.2  macallan #define BWI_DBG_RF		0x00000002
    784   1.2  macallan #define BWI_DBG_PHY		0x00000004
    785   1.2  macallan #define BWI_DBG_MISC		0x00000008
    786   1.2  macallan 
    787   1.2  macallan #define BWI_DBG_ATTACH		0x00000010
    788   1.2  macallan #define BWI_DBG_INIT		0x00000020
    789   1.2  macallan #define BWI_DBG_FIRMWARE	0x00000040
    790   1.2  macallan #define BWI_DBG_80211		0x00000080
    791   1.2  macallan #define BWI_DBG_TXPOWER		0x00000100
    792   1.2  macallan #define BWI_DBG_INTR		0x00000200
    793   1.2  macallan #define BWI_DBG_RX		0x00000400
    794   1.2  macallan #define BWI_DBG_TX		0x00000800
    795   1.2  macallan #define BWI_DBG_TXEOF		0x00001000
    796   1.2  macallan #define BWI_DBG_LED		0x00002000
    797   1.2  macallan #define BWI_DBG_STATION		0x00004000
    798   1.2  macallan 
    799   1.1  macallan #define abs(a)	__builtin_abs(a)
    800   1.1  macallan 
    801   1.1  macallan #define MOBJ_WRITE_2(mac, objid, ofs, val)			\
    802   1.1  macallan 	bwi_memobj_write_2((mac), (objid), (ofs), (val))
    803   1.1  macallan #define MOBJ_WRITE_4(mac, objid, ofs, val)			\
    804   1.1  macallan 	bwi_memobj_write_4((mac), (objid), (ofs), (val))
    805   1.1  macallan #define MOBJ_READ_2(mac, objid, ofs)				\
    806   1.1  macallan 	bwi_memobj_read_2((mac), (objid), (ofs))
    807   1.1  macallan #define MOBJ_READ_4(mac, objid, ofs)				\
    808   1.1  macallan 	bwi_memobj_read_4((mac), (objid), (ofs))
    809   1.1  macallan 
    810   1.1  macallan #define MOBJ_SETBITS_4(mac, objid, ofs, bits)			\
    811   1.1  macallan 	MOBJ_WRITE_4((mac), (objid), (ofs),			\
    812   1.1  macallan 	MOBJ_READ_4((mac), (objid), (ofs)) | (bits))
    813   1.1  macallan #define MOBJ_CLRBITS_4(mac, objid, ofs, bits)			\
    814   1.1  macallan 	MOBJ_WRITE_4((mac), (objid), (ofs),			\
    815   1.1  macallan 	MOBJ_READ_4((mac), (objid), (ofs)) & ~(bits))
    816   1.1  macallan 
    817   1.1  macallan #define MOBJ_FILT_SETBITS_2(mac, objid, ofs, filt, bits)	\
    818   1.1  macallan 	MOBJ_WRITE_2((mac), (objid), (ofs),			\
    819   1.1  macallan 	(MOBJ_READ_2((mac), (objid), (ofs)) & (filt)) | (bits))
    820   1.1  macallan 
    821   1.1  macallan #define TMPLT_WRITE_4(mac, ofs, val)	bwi_tmplt_write_4((mac), (ofs), (val))
    822   1.1  macallan 
    823   1.1  macallan #define HFLAGS_WRITE(mac, flags)	bwi_hostflags_write((mac), (flags))
    824   1.1  macallan #define HFLAGS_READ(mac)		bwi_hostflags_read((mac))
    825   1.1  macallan #define HFLAGS_CLRBITS(mac, bits)				\
    826   1.1  macallan 	HFLAGS_WRITE((mac), HFLAGS_READ((mac)) | (bits))
    827   1.1  macallan #define HFLAGS_SETBITS(mac, bits)				\
    828   1.1  macallan 	HFLAGS_WRITE((mac), HFLAGS_READ((mac)) & ~(bits))
    829   1.1  macallan 
    830   1.1  macallan /* PHY */
    831   1.1  macallan 
    832   1.1  macallan struct bwi_gains {
    833   1.1  macallan 	int16_t	tbl_gain1;
    834   1.1  macallan 	int16_t	tbl_gain2;
    835   1.1  macallan 	int16_t	phy_gain;
    836   1.1  macallan };
    837   1.1  macallan 
    838   1.1  macallan static __inline void
    839   1.1  macallan bwi_phy_init(struct bwi_mac *_mac)
    840   1.1  macallan {
    841   1.1  macallan 	_mac->mac_phy.phy_init(_mac);
    842   1.1  macallan }
    843   1.1  macallan 
    844   1.1  macallan #define PHY_WRITE(mac, ctrl, val)	bwi_phy_write((mac), (ctrl), (val))
    845   1.1  macallan #define PHY_READ(mac, ctrl)		bwi_phy_read((mac), (ctrl))
    846   1.1  macallan 
    847   1.1  macallan #define PHY_SETBITS(mac, ctrl, bits)		\
    848   1.1  macallan 	PHY_WRITE((mac), (ctrl), PHY_READ((mac), (ctrl)) | (bits))
    849   1.1  macallan #define PHY_CLRBITS(mac, ctrl, bits)		\
    850   1.1  macallan 	PHY_WRITE((mac), (ctrl), PHY_READ((mac), (ctrl)) & ~(bits))
    851   1.1  macallan #define PHY_FILT_SETBITS(mac, ctrl, filt, bits)	\
    852   1.1  macallan 	PHY_WRITE((mac), (ctrl), (PHY_READ((mac), (ctrl)) & (filt)) | (bits))
    853   1.1  macallan 
    854   1.1  macallan static __inline void
    855   1.1  macallan bwi_rf_off(struct bwi_mac *_mac)
    856   1.1  macallan {
    857   1.1  macallan 	_mac->mac_rf.rf_off(_mac);
    858   1.1  macallan 	/* TODO: LED */
    859   1.1  macallan 
    860   1.1  macallan 	_mac->mac_rf.rf_flags &= ~BWI_RF_F_ON;
    861   1.1  macallan }
    862   1.1  macallan 
    863   1.1  macallan static __inline void
    864   1.1  macallan bwi_rf_on(struct bwi_mac *_mac)
    865   1.1  macallan {
    866   1.1  macallan 	if (_mac->mac_rf.rf_flags & BWI_RF_F_ON)
    867   1.1  macallan 		return;
    868   1.1  macallan 
    869   1.1  macallan 	_mac->mac_rf.rf_on(_mac);
    870   1.1  macallan 	/* TODO: LED */
    871   1.1  macallan 
    872   1.1  macallan 	_mac->mac_rf.rf_flags |= BWI_RF_F_ON;
    873   1.1  macallan }
    874   1.1  macallan 
    875   1.1  macallan static __inline void
    876   1.1  macallan bwi_rf_calc_nrssi_slope(struct bwi_mac *_mac)
    877   1.1  macallan {
    878   1.1  macallan 	_mac->mac_rf.rf_calc_nrssi_slope(_mac);
    879   1.1  macallan }
    880   1.1  macallan 
    881   1.1  macallan static __inline void
    882   1.1  macallan bwi_rf_set_nrssi_thr(struct bwi_mac *_mac)
    883   1.1  macallan {
    884   1.1  macallan 	_mac->mac_rf.rf_set_nrssi_thr(_mac);
    885   1.1  macallan }
    886   1.1  macallan 
    887   1.1  macallan static __inline int
    888   1.1  macallan bwi_rf_calc_rssi(struct bwi_mac *_mac, const struct bwi_rxbuf_hdr *_hdr)
    889   1.1  macallan {
    890   1.1  macallan 	return (_mac->mac_rf.rf_calc_rssi(_mac, _hdr));
    891   1.1  macallan }
    892   1.1  macallan 
    893   1.1  macallan static __inline void
    894   1.1  macallan bwi_rf_lo_update(struct bwi_mac *_mac)
    895   1.1  macallan {
    896   1.8  dholland 	_mac->mac_rf.rf_lo_update(_mac);
    897   1.1  macallan }
    898   1.1  macallan 
    899   1.1  macallan #define RF_WRITE(mac, ofs, val)		bwi_rf_write((mac), (ofs), (val))
    900   1.1  macallan #define RF_READ(mac, ofs)		bwi_rf_read((mac), (ofs))
    901   1.1  macallan 
    902   1.1  macallan #define RF_SETBITS(mac, ofs, bits)		\
    903   1.1  macallan 	RF_WRITE((mac), (ofs), RF_READ((mac), (ofs)) | (bits))
    904   1.1  macallan #define RF_CLRBITS(mac, ofs, bits)		\
    905   1.1  macallan 	RF_WRITE((mac), (ofs), RF_READ((mac), (ofs)) & ~(bits))
    906   1.1  macallan #define RF_FILT_SETBITS(mac, ofs, filt, bits)	\
    907   1.1  macallan 	RF_WRITE((mac), (ofs), (RF_READ((mac), (ofs)) & (filt)) | (bits))
    908   1.1  macallan 
    909   1.2  macallan /* [TRC: XXX Why are these visible at all externally?] */
    910   1.1  macallan 
    911   1.1  macallan int		bwi_intr(void *);
    912   1.1  macallan int		bwi_attach(struct bwi_softc *);
    913   1.2  macallan void		bwi_detach(struct bwi_softc *);
    914   1.2  macallan 
    915   1.3    kefren /* Power Management Framework */
    916   1.7    dyoung bool		bwi_suspend(device_t, const pmf_qual_t *);
    917   1.7    dyoung bool		bwi_resume(device_t, const pmf_qual_t *);
    918   1.3    kefren 
    919   1.2  macallan #endif	/* !_DEV_IC_BWIVAR_H */
    920