Home | History | Annotate | Line # | Download | only in ic
atwvar.h revision 1.9
      1  1.9  dyoung /*	$NetBSD: atwvar.h,v 1.9 2004/06/23 08:13:29 dyoung Exp $	*/
      2  1.1  dyoung 
      3  1.1  dyoung /*
      4  1.1  dyoung  * Copyright (c) 2003, 2004 The NetBSD Foundation, Inc.  All rights reserved.
      5  1.1  dyoung  *
      6  1.1  dyoung  * This code is derived from software contributed to The NetBSD Foundation
      7  1.1  dyoung  * by David Young.
      8  1.1  dyoung  *
      9  1.1  dyoung  * Redistribution and use in source and binary forms, with or without
     10  1.1  dyoung  * modification, are permitted provided that the following conditions
     11  1.1  dyoung  * are met:
     12  1.1  dyoung  * 1. Redistributions of source code must retain the above copyright
     13  1.1  dyoung  *    notice, this list of conditions and the following disclaimer.
     14  1.1  dyoung  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1  dyoung  *    notice, this list of conditions and the following disclaimer in the
     16  1.1  dyoung  *    documentation and/or other materials provided with the distribution.
     17  1.1  dyoung  * 3. All advertising materials mentioning features or use of this software
     18  1.1  dyoung  *    must display the following acknowledgement:
     19  1.1  dyoung  *	This product includes software developed by the NetBSD
     20  1.1  dyoung  *	Foundation, Inc. and its contributors.
     21  1.1  dyoung  * 4. Neither the name of the author nor the names of any co-contributors
     22  1.1  dyoung  *    may be used to endorse or promote products derived from this software
     23  1.1  dyoung  *    without specific prior written permission.
     24  1.1  dyoung  *
     25  1.1  dyoung  * THIS SOFTWARE IS PROVIDED BY David Young AND CONTRIBUTORS ``AS IS'' AND
     26  1.1  dyoung  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27  1.1  dyoung  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28  1.1  dyoung  * ARE DISCLAIMED.  IN NO EVENT SHALL David Young
     29  1.1  dyoung  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.1  dyoung  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.1  dyoung  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.1  dyoung  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.1  dyoung  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.1  dyoung  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     35  1.1  dyoung  * THE POSSIBILITY OF SUCH DAMAGE.
     36  1.1  dyoung  */
     37  1.1  dyoung 
     38  1.1  dyoung #ifndef _DEV_IC_ATWVAR_H_
     39  1.1  dyoung #define	_DEV_IC_ATWVAR_H_
     40  1.1  dyoung 
     41  1.1  dyoung #include <sys/queue.h>
     42  1.1  dyoung #include <sys/callout.h>
     43  1.1  dyoung #include <sys/time.h>
     44  1.1  dyoung 
     45  1.1  dyoung /*
     46  1.1  dyoung  * Some misc. statics, useful for debugging.
     47  1.1  dyoung  */
     48  1.1  dyoung struct atw_stats {
     49  1.1  dyoung 	u_long		ts_tx_tuf;	/* transmit underflow errors */
     50  1.1  dyoung 	u_long		ts_tx_tro;	/* transmit jabber timeouts */
     51  1.1  dyoung 	u_long		ts_tx_trt;	/* retry count exceeded */
     52  1.1  dyoung 	u_long		ts_tx_tlt;	/* lifetime exceeded */
     53  1.1  dyoung 	u_long		ts_tx_sofbr;	/* packet size mismatch */
     54  1.1  dyoung };
     55  1.1  dyoung 
     56  1.1  dyoung /*
     57  1.1  dyoung  * Transmit descriptor list size.  This is arbitrary, but allocate
     58  1.1  dyoung  * enough descriptors for 64 pending transmissions and 16 segments
     59  1.1  dyoung  * per packet.  Since a descriptor holds 2 buffer addresses, that's
     60  1.1  dyoung  * 8 descriptors per packet.  This MUST work out to a power of 2.
     61  1.1  dyoung  */
     62  1.1  dyoung #define	ATW_NTXSEGS		16
     63  1.1  dyoung 
     64  1.1  dyoung #define	ATW_TXQUEUELEN	64
     65  1.1  dyoung #define	ATW_NTXDESC		(ATW_TXQUEUELEN * ATW_NTXSEGS)
     66  1.1  dyoung #define	ATW_NTXDESC_MASK	(ATW_NTXDESC - 1)
     67  1.1  dyoung #define	ATW_NEXTTX(x)		((x + 1) & ATW_NTXDESC_MASK)
     68  1.1  dyoung 
     69  1.1  dyoung /*
     70  1.1  dyoung  * Receive descriptor list size.  We have one Rx buffer per incoming
     71  1.1  dyoung  * packet, so this logic is a little simpler.
     72  1.1  dyoung  */
     73  1.1  dyoung #define	ATW_NRXDESC		64
     74  1.1  dyoung #define	ATW_NRXDESC_MASK	(ATW_NRXDESC - 1)
     75  1.1  dyoung #define	ATW_NEXTRX(x)		((x + 1) & ATW_NRXDESC_MASK)
     76  1.1  dyoung 
     77  1.1  dyoung /*
     78  1.1  dyoung  * Control structures are DMA'd to the ADM8211 chip.  We allocate them in
     79  1.1  dyoung  * a single clump that maps to a single DMA segment to make several things
     80  1.1  dyoung  * easier.
     81  1.1  dyoung  */
     82  1.1  dyoung struct atw_control_data {
     83  1.1  dyoung 	/*
     84  1.1  dyoung 	 * The transmit descriptors.
     85  1.1  dyoung 	 */
     86  1.1  dyoung 	struct atw_txdesc acd_txdescs[ATW_NTXDESC];
     87  1.1  dyoung 
     88  1.1  dyoung 	/*
     89  1.1  dyoung 	 * The receive descriptors.
     90  1.1  dyoung 	 */
     91  1.1  dyoung 	struct atw_rxdesc acd_rxdescs[ATW_NRXDESC];
     92  1.1  dyoung };
     93  1.1  dyoung 
     94  1.1  dyoung #define	ATW_CDOFF(x)		offsetof(struct atw_control_data, x)
     95  1.1  dyoung #define	ATW_CDTXOFF(x)	ATW_CDOFF(acd_txdescs[(x)])
     96  1.1  dyoung #define	ATW_CDRXOFF(x)	ATW_CDOFF(acd_rxdescs[(x)])
     97  1.1  dyoung /*
     98  1.1  dyoung  * Software state for transmit jobs.
     99  1.1  dyoung  */
    100  1.1  dyoung struct atw_txsoft {
    101  1.1  dyoung 	struct mbuf *txs_mbuf;		/* head of our mbuf chain */
    102  1.1  dyoung 	bus_dmamap_t txs_dmamap;	/* our DMA map */
    103  1.1  dyoung 	int txs_firstdesc;		/* first descriptor in packet */
    104  1.1  dyoung 	int txs_lastdesc;		/* last descriptor in packet */
    105  1.1  dyoung 	int txs_ndescs;			/* number of descriptors */
    106  1.1  dyoung 	SIMPLEQ_ENTRY(atw_txsoft) txs_q;
    107  1.1  dyoung };
    108  1.1  dyoung 
    109  1.1  dyoung SIMPLEQ_HEAD(atw_txsq, atw_txsoft);
    110  1.1  dyoung 
    111  1.1  dyoung /*
    112  1.1  dyoung  * Software state for receive jobs.
    113  1.1  dyoung  */
    114  1.1  dyoung struct atw_rxsoft {
    115  1.1  dyoung 	struct mbuf *rxs_mbuf;		/* head of our mbuf chain */
    116  1.1  dyoung 	bus_dmamap_t rxs_dmamap;	/* our DMA map */
    117  1.1  dyoung };
    118  1.1  dyoung 
    119  1.1  dyoung /*
    120  1.1  dyoung  * Table which describes the transmit threshold mode.  We generally
    121  1.1  dyoung  * start at index 0.  Whenever we get a transmit underrun, we increment
    122  1.1  dyoung  * our index, falling back if we encounter the NULL terminator.
    123  1.1  dyoung  */
    124  1.1  dyoung struct atw_txthresh_tab {
    125  1.1  dyoung 	u_int32_t txth_opmode;		/* OPMODE bits */
    126  1.1  dyoung 	const char *txth_name;		/* name of mode */
    127  1.1  dyoung };
    128  1.1  dyoung 
    129  1.1  dyoung #define	ATW_TXTHRESH_TAB_LO_RATE {					\
    130  1.1  dyoung 	{ ATW_NAR_TR_L64,	"64 bytes" },				\
    131  1.1  dyoung 	{ ATW_NAR_TR_L160,	"160 bytes" },				\
    132  1.1  dyoung 	{ ATW_NAR_TR_L192,	"192 bytes" },				\
    133  1.1  dyoung 	{ ATW_NAR_SF,		"store and forward" },			\
    134  1.1  dyoung 	{ 0,			NULL },					\
    135  1.1  dyoung }
    136  1.1  dyoung 
    137  1.1  dyoung #define	ATW_TXTHRESH_TAB_HI_RATE {					\
    138  1.1  dyoung 	{ ATW_NAR_TR_H96,	"96 bytes" },				\
    139  1.1  dyoung 	{ ATW_NAR_TR_H288,	"288 bytes" },				\
    140  1.1  dyoung 	{ ATW_NAR_TR_H544,	"544 bytes" },				\
    141  1.1  dyoung 	{ ATW_NAR_SF,		"store and forward" },			\
    142  1.1  dyoung 	{ 0,			NULL },					\
    143  1.1  dyoung }
    144  1.1  dyoung 
    145  1.1  dyoung enum atw_rftype { ATW_RFTYPE_INTERSIL = 0, ATW_RFTYPE_RFMD  = 1,
    146  1.1  dyoung        ATW_RFTYPE_MARVEL = 2 };
    147  1.1  dyoung 
    148  1.1  dyoung enum atw_bbptype { ATW_BBPTYPE_INTERSIL = 0, ATW_BBPTYPE_RFMD  = 1,
    149  1.9  dyoung        ATW_BBPTYPE_MARVEL = 2, ATW_C_BBPTYPE_RFMD  = 5 };
    150  1.1  dyoung 
    151  1.3  dyoung /* Radio capture format for ADMtek. */
    152  1.3  dyoung 
    153  1.3  dyoung #define ATW_RX_RADIOTAP_PRESENT	\
    154  1.3  dyoung 	((1 << IEEE80211_RADIOTAP_FLAGS) | (1 << IEEE80211_RADIOTAP_RATE) | \
    155  1.3  dyoung 	 (1 << IEEE80211_RADIOTAP_CHANNEL) | \
    156  1.3  dyoung 	 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL))
    157  1.3  dyoung 
    158  1.3  dyoung struct atw_rx_radiotap_header {
    159  1.3  dyoung 	struct ieee80211_radiotap_header	ar_ihdr;
    160  1.3  dyoung 	u_int8_t				ar_flags;
    161  1.3  dyoung 	u_int8_t				ar_rate;
    162  1.3  dyoung 	u_int16_t				ar_chan_freq;
    163  1.3  dyoung 	u_int16_t				ar_chan_flags;
    164  1.5  dyoung 	u_int8_t				ar_antsignal;
    165  1.3  dyoung } __attribute__((__packed__));
    166  1.3  dyoung 
    167  1.3  dyoung #define ATW_TX_RADIOTAP_PRESENT	((1 << IEEE80211_RADIOTAP_FLAGS) | \
    168  1.3  dyoung 				 (1 << IEEE80211_RADIOTAP_RATE) | \
    169  1.3  dyoung 				 (1 << IEEE80211_RADIOTAP_CHANNEL))
    170  1.3  dyoung 
    171  1.3  dyoung struct atw_tx_radiotap_header {
    172  1.3  dyoung 	struct ieee80211_radiotap_header	at_ihdr;
    173  1.3  dyoung 	u_int8_t				at_flags;
    174  1.3  dyoung 	u_int8_t				at_rate;
    175  1.3  dyoung 	u_int16_t				at_chan_freq;
    176  1.3  dyoung 	u_int16_t				at_chan_flags;
    177  1.3  dyoung } __attribute__((__packed__));
    178  1.4  dyoung 
    179  1.1  dyoung struct atw_softc {
    180  1.1  dyoung 	struct device		sc_dev;
    181  1.1  dyoung 	struct ieee80211com	sc_ic;
    182  1.1  dyoung 	int			(*sc_enable)(struct atw_softc *);
    183  1.1  dyoung 	void			(*sc_disable)(struct atw_softc *);
    184  1.1  dyoung 	void			(*sc_power)(struct atw_softc *, int);
    185  1.2  dyoung 	int			(*sc_newstate)(struct ieee80211com *,
    186  1.2  dyoung 					enum ieee80211_state, int);
    187  1.2  dyoung 	void			(*sc_recv_mgmt)(struct ieee80211com *,
    188  1.2  dyoung 				    struct mbuf *, struct ieee80211_node *,
    189  1.2  dyoung 				    int, int, u_int32_t);
    190  1.2  dyoung 	struct ieee80211_node	*(*sc_node_alloc)(struct ieee80211com *);
    191  1.2  dyoung 	void			(*sc_node_free)(struct ieee80211com *,
    192  1.2  dyoung 					struct ieee80211_node *);
    193  1.1  dyoung 
    194  1.1  dyoung 	struct atw_stats sc_stats;	/* debugging stats */
    195  1.1  dyoung 
    196  1.1  dyoung 	int			sc_tx_timer;
    197  1.1  dyoung 	int			sc_rescan_timer;
    198  1.1  dyoung 
    199  1.1  dyoung 	bus_space_tag_t		sc_st;		/* bus space tag */
    200  1.1  dyoung 	bus_space_handle_t	sc_sh;		/* bus space handle */
    201  1.1  dyoung 	bus_dma_tag_t		sc_dmat;	/* bus dma tag */
    202  1.1  dyoung 	void			*sc_sdhook;	/* shutdown hook */
    203  1.1  dyoung 	void			*sc_powerhook;	/* power management hook */
    204  1.1  dyoung 	u_int32_t		sc_cacheline;	/* cache line size */
    205  1.1  dyoung 	u_int32_t		sc_maxburst;	/* maximum burst length */
    206  1.1  dyoung 
    207  1.1  dyoung 	const struct atw_txthresh_tab	*sc_txth;
    208  1.1  dyoung 	int				sc_txthresh; /* current tx threshold */
    209  1.1  dyoung 
    210  1.1  dyoung 	u_int			sc_cur_chan;	/* current channel */
    211  1.1  dyoung 
    212  1.1  dyoung 	int			sc_flags;
    213  1.1  dyoung 
    214  1.1  dyoung 	u_int16_t		*sc_srom;
    215  1.1  dyoung 	u_int16_t		sc_sromsz;
    216  1.1  dyoung 
    217  1.1  dyoung 	caddr_t			sc_radiobpf;
    218  1.1  dyoung 
    219  1.1  dyoung 	bus_dma_segment_t	sc_cdseg;	/* control data memory */
    220  1.1  dyoung 	int			sc_cdnseg;	/* number of segments */
    221  1.1  dyoung 	bus_dmamap_t		sc_cddmamap;	/* control data DMA map */
    222  1.1  dyoung #define	sc_cddma	sc_cddmamap->dm_segs[0].ds_addr
    223  1.1  dyoung 
    224  1.1  dyoung 	/*
    225  1.1  dyoung 	 * Software state for transmit and receive descriptors.
    226  1.1  dyoung 	 */
    227  1.1  dyoung 	struct atw_txsoft sc_txsoft[ATW_TXQUEUELEN];
    228  1.1  dyoung 	struct atw_rxsoft sc_rxsoft[ATW_NRXDESC];
    229  1.1  dyoung 
    230  1.1  dyoung 	/*
    231  1.1  dyoung 	 * Control data structures.
    232  1.1  dyoung 	 */
    233  1.1  dyoung 	struct atw_control_data *sc_control_data;
    234  1.1  dyoung #define	sc_txdescs	sc_control_data->acd_txdescs
    235  1.1  dyoung #define	sc_rxdescs	sc_control_data->acd_rxdescs
    236  1.1  dyoung #define	sc_setup_desc	sc_control_data->acd_setup_desc
    237  1.1  dyoung 
    238  1.1  dyoung 	int	sc_txfree;		/* number of free Tx descriptors */
    239  1.1  dyoung 	int	sc_txnext;		/* next ready Tx descriptor */
    240  1.1  dyoung 	int	sc_ntxsegs;		/* number of transmit segs per pkt */
    241  1.1  dyoung 
    242  1.1  dyoung 	struct atw_txsq sc_txfreeq;	/* free Tx descsofts */
    243  1.1  dyoung 	struct atw_txsq sc_txdirtyq;	/* dirty Tx descsofts */
    244  1.1  dyoung 
    245  1.1  dyoung 	int	sc_rxptr;		/* next ready RX descriptor/descsoft */
    246  1.1  dyoung 
    247  1.1  dyoung 	u_int32_t	sc_busmode;	/* copy of ATW_PAR */
    248  1.1  dyoung 	u_int32_t	sc_opmode;	/* copy of ATW_NAR */
    249  1.1  dyoung 	u_int32_t	sc_inten;	/* copy of ATW_IER */
    250  1.1  dyoung 	u_int32_t	sc_wepctl;	/* copy of ATW_WEPCTL */
    251  1.1  dyoung 
    252  1.1  dyoung 	u_int32_t	sc_rxint_mask;	/* mask of Rx interrupts we want */
    253  1.1  dyoung 	u_int32_t	sc_txint_mask;	/* mask of Tx interrupts we want */
    254  1.1  dyoung 	u_int32_t	sc_linkint_mask;/* link-state interrupts mask */
    255  1.1  dyoung 
    256  1.1  dyoung 	/* interrupt acknowledge hook */
    257  1.8  dyoung 	void (*sc_intr_ack)(struct atw_softc *);
    258  1.1  dyoung 
    259  1.1  dyoung 	enum atw_rftype		sc_rftype;
    260  1.1  dyoung 	enum atw_bbptype	sc_bbptype;
    261  1.1  dyoung 	u_int32_t	sc_synctl_rd;
    262  1.1  dyoung 	u_int32_t	sc_synctl_wr;
    263  1.1  dyoung 	u_int32_t	sc_bbpctl_rd;
    264  1.1  dyoung 	u_int32_t	sc_bbpctl_wr;
    265  1.1  dyoung 
    266  1.1  dyoung 	void		(*sc_recv_beacon)(struct ieee80211com *, struct mbuf *,
    267  1.1  dyoung 			    int, u_int32_t);
    268  1.1  dyoung 	void		(*sc_recv_prresp)(struct ieee80211com *, struct mbuf *,
    269  1.1  dyoung 			    int, u_int32_t);
    270  1.1  dyoung 
    271  1.1  dyoung 	/* ADM8211 state variables. */
    272  1.1  dyoung 	u_int8_t	sc_sram[ATW_SRAM_SIZE];
    273  1.1  dyoung 	u_int8_t	sc_bssid[IEEE80211_ADDR_LEN];
    274  1.1  dyoung 	u_int8_t	sc_lost_bcn_thresh;
    275  1.1  dyoung 
    276  1.1  dyoung 	struct timeval	sc_last_beacon;
    277  1.2  dyoung 	struct callout	sc_scan_ch;
    278  1.3  dyoung 	union {
    279  1.3  dyoung 		struct atw_rx_radiotap_header	tap;
    280  1.3  dyoung 		u_int8_t			pad[64];
    281  1.3  dyoung 	} sc_rxtapu;
    282  1.3  dyoung 	union {
    283  1.3  dyoung 		struct atw_tx_radiotap_header	tap;
    284  1.3  dyoung 		u_int8_t			pad[64];
    285  1.3  dyoung 	} sc_txtapu;
    286  1.1  dyoung };
    287  1.3  dyoung 
    288  1.3  dyoung #define sc_rxtap	sc_rxtapu.tap
    289  1.3  dyoung #define sc_txtap	sc_txtapu.tap
    290  1.1  dyoung 
    291  1.1  dyoung #define	sc_if			sc_ic.ic_if
    292  1.1  dyoung 
    293  1.1  dyoung /* XXX this is fragile. try not to introduce any u_int32_t's. */
    294  1.1  dyoung struct atw_frame {
    295  1.1  dyoung /*00*/	u_int8_t			atw_dst[IEEE80211_ADDR_LEN];
    296  1.1  dyoung /*06*/	u_int8_t			atw_rate;	/* TX rate in 100Kbps */
    297  1.1  dyoung /*07*/	u_int8_t			atw_service;	/* 0 */
    298  1.1  dyoung /*08*/	u_int16_t			atw_paylen;	/* payload length */
    299  1.1  dyoung /*0a*/	u_int8_t			atw_fc[2];	/* 802.11 Frame
    300  1.1  dyoung 							 * Control
    301  1.1  dyoung 							 */
    302  1.1  dyoung 	/* 802.11 PLCP Length for first & last fragment */
    303  1.1  dyoung /*0c*/	u_int16_t			atw_tail_plcplen;
    304  1.1  dyoung /*0e*/	u_int16_t			atw_head_plcplen;
    305  1.1  dyoung 	/* 802.11 Duration for first & last fragment */
    306  1.1  dyoung /*10*/	u_int16_t			atw_tail_dur;
    307  1.1  dyoung /*12*/	u_int16_t			atw_head_dur;
    308  1.1  dyoung /*14*/	u_int8_t			atw_addr4[IEEE80211_ADDR_LEN];
    309  1.1  dyoung 	union {
    310  1.1  dyoung 		struct {
    311  1.1  dyoung /*1a*/			u_int16_t	hdrctl;	/*transmission control*/
    312  1.1  dyoung /*1c*/			u_int16_t	fragthr;/* fragmentation threshold
    313  1.1  dyoung 						 * [0:11], zero [12:15].
    314  1.1  dyoung 						 */
    315  1.1  dyoung /*1e*/			u_int8_t	fragnum;/* fragment number [4:7],
    316  1.1  dyoung 						 * zero [0:3].
    317  1.1  dyoung 						 */
    318  1.1  dyoung /*1f*/			u_int8_t	rtylmt;	/* retry limit */
    319  1.1  dyoung /*20*/			u_int8_t	wepkey0[4];/* ??? */
    320  1.1  dyoung /*24*/			u_int8_t	wepkey1[4];/* ??? */
    321  1.1  dyoung /*28*/			u_int8_t	wepkey2[4];/* ??? */
    322  1.1  dyoung /*2c*/			u_int8_t	wepkey3[4];/* ??? */
    323  1.1  dyoung /*30*/			u_int8_t	keyid;
    324  1.1  dyoung /*31*/			u_int8_t	reserved0[7];
    325  1.2  dyoung 		} s1;
    326  1.2  dyoung 		struct {
    327  1.2  dyoung 			u_int8_t		pad[6];
    328  1.2  dyoung 			struct ieee80211_frame	ihdr;
    329  1.2  dyoung 		} s2;
    330  1.1  dyoung 	} u;
    331  1.1  dyoung } __attribute__((__packed__));
    332  1.1  dyoung 
    333  1.2  dyoung #define atw_hdrctl	u.s1.hdrctl
    334  1.2  dyoung #define atw_fragthr	u.s1.fragthr
    335  1.2  dyoung #define atw_fragnum	u.s1.fragnum
    336  1.2  dyoung #define atw_rtylmt	u.s1.rtylmt
    337  1.2  dyoung #define atw_keyid	u.s1.keyid
    338  1.2  dyoung #define atw_ihdr	u.s2.ihdr
    339  1.1  dyoung 
    340  1.1  dyoung #define ATW_HDRCTL_SHORT_PREAMBLE	BIT(0)	/* use short preamble */
    341  1.1  dyoung #define ATW_HDRCTL_RTSCTS		BIT(4)	/* send RTS */
    342  1.1  dyoung #define ATW_HDRCTL_WEP			BIT(5)
    343  1.1  dyoung #define ATW_HDRCTL_UNKNOWN1		BIT(15) /* MAC adds FCS? */
    344  1.1  dyoung #define ATW_HDRCTL_UNKNOWN2		BIT(8)
    345  1.1  dyoung 
    346  1.1  dyoung #define ATW_FRAGTHR_FRAGTHR_MASK	BITS(0, 11)
    347  1.1  dyoung #define ATW_FRAGNUM_FRAGNUM_MASK	BITS(4, 7)
    348  1.1  dyoung 
    349  1.1  dyoung /* Values for sc_flags. */
    350  1.1  dyoung #define	ATWF_MRL		0x00000010	/* memory read line okay */
    351  1.1  dyoung #define	ATWF_MRM		0x00000020	/* memory read multi okay */
    352  1.1  dyoung #define	ATWF_MWI		0x00000040	/* memory write inval okay */
    353  1.1  dyoung #define	ATWF_SHORT_PREAMBLE	0x00000080	/* short preamble enabled */
    354  1.1  dyoung #define	ATWF_RTSCTS		0x00000100	/* RTS/CTS enabled */
    355  1.1  dyoung #define	ATWF_ATTACHED		0x00000800	/* attach has succeeded */
    356  1.1  dyoung #define	ATWF_ENABLED		0x00001000	/* chip is enabled */
    357  1.1  dyoung 
    358  1.1  dyoung #define	ATW_IS_ENABLED(sc)	((sc)->sc_flags & ATWF_ENABLED)
    359  1.1  dyoung 
    360  1.1  dyoung #define	ATW_CDTXADDR(sc, x)	((sc)->sc_cddma + ATW_CDTXOFF((x)))
    361  1.1  dyoung #define	ATW_CDRXADDR(sc, x)	((sc)->sc_cddma + ATW_CDRXOFF((x)))
    362  1.1  dyoung 
    363  1.1  dyoung #define	ATW_CDTXSYNC(sc, x, n, ops)					\
    364  1.1  dyoung do {									\
    365  1.1  dyoung 	int __x, __n;							\
    366  1.1  dyoung 									\
    367  1.1  dyoung 	__x = (x);							\
    368  1.1  dyoung 	__n = (n);							\
    369  1.1  dyoung 									\
    370  1.1  dyoung 	/* If it will wrap around, sync to the end of the ring. */	\
    371  1.1  dyoung 	if ((__x + __n) > ATW_NTXDESC) {				\
    372  1.1  dyoung 		bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap,	\
    373  1.1  dyoung 		    ATW_CDTXOFF(__x), sizeof(struct atw_txdesc) *	\
    374  1.1  dyoung 		    (ATW_NTXDESC - __x), (ops));			\
    375  1.1  dyoung 		__n -= (ATW_NTXDESC - __x);				\
    376  1.1  dyoung 		__x = 0;						\
    377  1.1  dyoung 	}								\
    378  1.1  dyoung 									\
    379  1.1  dyoung 	/* Now sync whatever is left. */				\
    380  1.1  dyoung 	bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap,		\
    381  1.1  dyoung 	    ATW_CDTXOFF(__x), sizeof(struct atw_txdesc) * __n, (ops)); \
    382  1.1  dyoung } while (0)
    383  1.1  dyoung 
    384  1.1  dyoung #define	ATW_CDRXSYNC(sc, x, ops)					\
    385  1.1  dyoung 	bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap,		\
    386  1.1  dyoung 	    ATW_CDRXOFF((x)), sizeof(struct atw_rxdesc), (ops))
    387  1.1  dyoung 
    388  1.1  dyoung /*
    389  1.1  dyoung  * Note we rely on MCLBYTES being a power of two.  Because the `length'
    390  1.1  dyoung  * field is only 11 bits, we must subtract 1 from the length to avoid
    391  1.1  dyoung  * having it truncated to 0!
    392  1.1  dyoung  *
    393  1.1  dyoung  * Apparently we have to set ATW_RXSTAT_SQL to make the ADM8211 tell
    394  1.1  dyoung  * us RSSI.
    395  1.1  dyoung  */
    396  1.1  dyoung #define	ATW_INIT_RXDESC(sc, x)						\
    397  1.1  dyoung do {									\
    398  1.1  dyoung 	struct atw_rxsoft *__rxs = &sc->sc_rxsoft[(x)];			\
    399  1.1  dyoung 	struct atw_rxdesc *__rxd = &sc->sc_rxdescs[(x)];		\
    400  1.1  dyoung 	struct mbuf *__m = __rxs->rxs_mbuf;				\
    401  1.1  dyoung 									\
    402  1.1  dyoung 	__m->m_data = __m->m_ext.ext_buf;				\
    403  1.1  dyoung 	__rxd->ar_buf1 =						\
    404  1.1  dyoung 	    htole32(__rxs->rxs_dmamap->dm_segs[0].ds_addr);		\
    405  1.1  dyoung 	__rxd->ar_buf2 =	/* for descriptor chaining */		\
    406  1.1  dyoung 	    htole32(ATW_CDRXADDR((sc), ATW_NEXTRX((x))));		\
    407  1.1  dyoung 	__rxd->ar_ctl =							\
    408  1.1  dyoung 	    htole32(LSHIFT(((__m->m_ext.ext_size - 1) & ~0x3U),		\
    409  1.1  dyoung 	                   ATW_RXCTL_RBS1_MASK) |			\
    410  1.1  dyoung 		    0 /* ATW_RXCTL_RCH */ |				\
    411  1.1  dyoung 	    ((x) == (ATW_NRXDESC - 1) ? ATW_RXCTL_RER : 0));		\
    412  1.1  dyoung 	__rxd->ar_stat =						\
    413  1.1  dyoung 	    htole32(ATW_RXSTAT_OWN|ATW_RXSTAT_SQL|ATW_RXSTAT_FS|	\
    414  1.1  dyoung 	            ATW_RXSTAT_LS);					\
    415  1.1  dyoung 	ATW_CDRXSYNC((sc), (x),						\
    416  1.1  dyoung 	    BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);			\
    417  1.1  dyoung } while (0)
    418  1.1  dyoung 
    419  1.1  dyoung /* country codes from ADM8211 SROM */
    420  1.1  dyoung #define	ATW_COUNTRY_FCC 0		/* USA 1-11 */
    421  1.1  dyoung #define	ATW_COUNTRY_IC 1		/* Canada 1-11 */
    422  1.1  dyoung #define	ATW_COUNTRY_ETSI 2		/* European Union (?) 1-13 */
    423  1.1  dyoung #define	ATW_COUNTRY_SPAIN 3		/* 10-11 */
    424  1.1  dyoung #define	ATW_COUNTRY_FRANCE 4		/* 10-13 */
    425  1.1  dyoung #define	ATW_COUNTRY_MKK 5		/* Japan: 14 */
    426  1.1  dyoung #define	ATW_COUNTRY_MKK2 6		/* Japan: 1-14 */
    427  1.2  dyoung 
    428  1.2  dyoung /* One Time Unit (TU) is 1Kus = 1024 microseconds. */
    429  1.2  dyoung #define IEEE80211_DUR_TU		1024
    430  1.2  dyoung 
    431  1.2  dyoung /* IEEE 802.11b durations for DSSS PHY in microseconds */
    432  1.2  dyoung #define IEEE80211_DUR_DS_LONG_PREAMBLE	144
    433  1.2  dyoung #define IEEE80211_DUR_DS_SHORT_PREAMBLE	72
    434  1.2  dyoung #define IEEE80211_DUR_DS_FAST_PLCPHDR	24
    435  1.2  dyoung #define IEEE80211_DUR_DS_SLOW_PLCPHDR	48
    436  1.2  dyoung #define IEEE80211_DUR_DS_SLOW_ACK	112
    437  1.2  dyoung #define IEEE80211_DUR_DS_FAST_ACK	56
    438  1.2  dyoung #define IEEE80211_DUR_DS_SLOW_CTS	112
    439  1.2  dyoung #define IEEE80211_DUR_DS_FAST_CTS	56
    440  1.2  dyoung #define IEEE80211_DUR_DS_SLOT		20
    441  1.2  dyoung #define IEEE80211_DUR_DS_SIFS		10
    442  1.2  dyoung #define IEEE80211_DUR_DS_PIFS	(IEEE80211_DUR_DS_SIFS + IEEE80211_DUR_DS_SLOT)
    443  1.2  dyoung #define IEEE80211_DUR_DS_DIFS	(IEEE80211_DUR_DS_SIFS + \
    444  1.2  dyoung 				 2 * IEEE80211_DUR_DS_SLOT)
    445  1.2  dyoung #define IEEE80211_DUR_DS_EIFS	(IEEE80211_DUR_DS_SIFS + \
    446  1.2  dyoung 				 IEEE80211_DUR_DS_SLOW_ACK + \
    447  1.2  dyoung 				 IEEE80211_DUR_DS_LONG_PREAMBLE + \
    448  1.2  dyoung 				 IEEE80211_DUR_DS_SLOW_PLCPHDR + \
    449  1.2  dyoung 				 IEEE80211_DUR_DIFS)
    450  1.1  dyoung 
    451  1.1  dyoung /*
    452  1.1  dyoung  * register space access macros
    453  1.1  dyoung  */
    454  1.1  dyoung #define	ATW_READ(sc, reg)						\
    455  1.1  dyoung 	bus_space_read_4((sc)->sc_st, (sc)->sc_sh, (reg))
    456  1.1  dyoung 
    457  1.1  dyoung #define	ATW_WRITE(sc, reg, val)					\
    458  1.1  dyoung 	bus_space_write_4((sc)->sc_st, (sc)->sc_sh, (reg), (val))
    459  1.1  dyoung 
    460  1.1  dyoung #define	ATW_SET(sc, reg, mask)					\
    461  1.1  dyoung 	ATW_WRITE((sc), (reg), ATW_READ((sc), (reg)) | (mask))
    462  1.1  dyoung 
    463  1.1  dyoung #define	ATW_CLR(sc, reg, mask)					\
    464  1.1  dyoung 	ATW_WRITE((sc), (reg), ATW_READ((sc), (reg)) & ~(mask))
    465  1.1  dyoung 
    466  1.1  dyoung #define	ATW_ISSET(sc, reg, mask)					\
    467  1.1  dyoung 	(ATW_READ((sc), (reg)) & (mask))
    468  1.1  dyoung 
    469  1.8  dyoung void	atw_attach(struct atw_softc *);
    470  1.8  dyoung int	atw_detach(struct atw_softc *);
    471  1.8  dyoung int	atw_activate(struct device *, enum devact);
    472  1.8  dyoung int	atw_intr(void *arg);
    473  1.8  dyoung void	atw_power(int, void *);
    474  1.8  dyoung void	atw_shutdown(void *);
    475  1.1  dyoung 
    476  1.1  dyoung #endif /* _DEV_IC_ATWVAR_H_ */
    477