xref: /netbsd-src/sys/dev/ic/rt2860var.h (revision a24efa7dea9f1f56c3bdb15a927d3516792ace1c)
1 /*	$NetBSD: rt2860var.h,v 1.2 2016/04/27 19:49:26 christos Exp $	*/
2 /*	$OpenBSD: rt2860var.h,v 1.23 2016/03/21 21:16:30 stsp Exp $	*/
3 
4 /*-
5  * Copyright (c) 2007
6  *	Damien Bergamini <damien.bergamini@free.fr>
7  *
8  * Permission to use, copy, modify, and distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 #define RT2860_MAX_SCATTER	15
22 #define RT2860_MAX_SCATTER_TXD	(1 + (RT2860_MAX_SCATTER / 2))
23 
24 #define RT2860_RX_RING_COUNT	128
25 #define RT2860_TX_RING_COUNT	64
26 #define RT2860_TX_RING_MAX	(RT2860_TX_RING_COUNT - 1)
27 #define RT2860_TX_RING_ONEMORE	(RT2860_TX_RING_MAX - RT2860_MAX_SCATTER_TXD)
28 #define RT2860_TX_POOL_COUNT	(RT2860_TX_RING_COUNT * 2)
29 
30 /* HW supports up to 255 STAs */
31 #define RT2860_WCID_MAX		254
32 #define RT2860_AID2WCID(aid)	((aid) & 0xff)
33 
34 #define IEEE80211_NO_HT
35 
36 struct rt2860_rx_radiotap_header {
37 	struct ieee80211_radiotap_header wr_ihdr;
38 	uint8_t		wr_flags;
39 	uint8_t		wr_rate;
40 	uint16_t	wr_chan_freq;
41 	uint16_t	wr_chan_flags;
42 	uint8_t		wr_dbm_antsignal;
43 	uint8_t		wr_antenna;
44 	uint8_t		wr_antsignal;
45 } __packed;
46 
47 #define RT2860_RX_RADIOTAP_PRESENT			\
48 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
49 	 1 << IEEE80211_RADIOTAP_RATE |			\
50 	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
51 	 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL |	\
52 	 1 << IEEE80211_RADIOTAP_ANTENNA |		\
53 	 1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL)
54 
55 struct rt2860_tx_radiotap_header {
56 	struct ieee80211_radiotap_header wt_ihdr;
57 	uint8_t		wt_flags;
58 	uint8_t		wt_rate;
59 	uint16_t	wt_chan_freq;
60 	uint16_t	wt_chan_flags;
61 	uint8_t		wt_hwqueue;
62 } __packed;
63 
64 #define RT2860_TX_RADIOTAP_PRESENT			\
65 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
66 	 1 << IEEE80211_RADIOTAP_RATE |			\
67 	 1 << IEEE80211_RADIOTAP_CHANNEL)
68 
69 struct rt2860_tx_data {
70 	struct rt2860_txwi		*txwi;
71 	struct mbuf			*m;
72 	struct ieee80211_node		*ni;
73 	bus_dmamap_t			map;
74 	bus_addr_t			paddr;
75 	SLIST_ENTRY(rt2860_tx_data)	next;
76 };
77 
78 struct rt2860_tx_ring {
79 	struct rt2860_txd	*txd;
80 	bus_addr_t		paddr;
81 	bus_dmamap_t		map;
82 	bus_dma_segment_t	seg;
83 	struct rt2860_tx_data	*data[RT2860_TX_RING_COUNT];
84 	int			cur;
85 	int			next;
86 	int			queued;
87 };
88 
89 struct rt2860_rx_data {
90 	struct mbuf	*m;
91 	bus_dmamap_t	map;
92 };
93 
94 struct rt2860_rx_ring {
95 	struct rt2860_rxd	*rxd;
96 	bus_addr_t		paddr;
97 	bus_dmamap_t		map;
98 	bus_dma_segment_t	seg;
99 	unsigned int		cur;	/* must be unsigned */
100 	struct rt2860_rx_data	data[RT2860_RX_RING_COUNT];
101 };
102 
103 struct rt2860_node {
104 	struct ieee80211_node	ni;
105 	uint8_t			wcid;
106 	uint8_t			ridx[IEEE80211_RATE_MAXSIZE];
107 	uint8_t			ctl_ridx[IEEE80211_RATE_MAXSIZE];
108 };
109 
110 struct rt2860_softc {
111 	device_t			sc_dev;
112 
113 	struct ieee80211com		sc_ic;
114 	int				(*sc_newstate)(struct ieee80211com *,
115 					    enum ieee80211_state, int);
116 
117 	int				(*sc_enable)(struct rt2860_softc *);
118 	void				(*sc_disable)(struct rt2860_softc *);
119 
120 	bus_dma_tag_t			sc_dmat;
121 	bus_space_tag_t			sc_st;
122 	bus_space_handle_t		sc_sh;
123 
124 	struct ethercom			sc_ec;
125 #define sc_if  sc_ec.ec_if
126 
127 	uint16_t			(*sc_srom_read)(struct rt2860_softc *,
128 					    uint16_t);
129 
130 	int				sc_flags;
131 #define RT2860_ENABLED		(1 << 0)
132 #define RT2860_ADVANCED_PS	(1 << 1)
133 #define RT2860_PCIE		(1 << 2)
134 
135 	struct ieee80211_amrr		amrr;
136 
137 	uint32_t			sc_ic_flags;
138 	int				fixed_ridx;
139 
140 	u_char				*ucode;
141 	size_t				ucsize;
142 
143 	struct rt2860_tx_ring		txq[6];
144 	struct rt2860_rx_ring		rxq;
145 
146 	SLIST_HEAD(, rt2860_tx_data)	data_pool;
147 	struct rt2860_tx_data		data[RT2860_TX_POOL_COUNT];
148 	bus_dmamap_t			txwi_map;
149 	bus_dma_segment_t		txwi_seg;
150 	void				*txwi_vaddr;
151 
152 	int				sc_tx_timer;
153 	struct ieee80211_beacon_offsets	sc_bo;
154 	int				mgtqid;
155 	uint8_t				qfullmsk;
156 
157 	uint16_t			mac_ver;
158 	uint16_t			mac_rev;
159 	uint8_t				rf_rev;
160 	uint8_t				freq;
161 	uint8_t				ntxchains;
162 	uint8_t				nrxchains;
163 	uint8_t				pslevel;
164 	int8_t				txpow1[54];
165 	int8_t				txpow2[54];
166 	int8_t				rssi_2ghz[3];
167 	int8_t				rssi_5ghz[3];
168 	uint8_t				lna[4];
169 	uint8_t				rf24_20mhz;
170 	uint8_t				rf24_40mhz;
171 	uint8_t				patch_dac;
172 	uint8_t				rfswitch;
173 	uint8_t				ext_2ghz_lna;
174 	uint8_t				ext_5ghz_lna;
175 	uint8_t				calib_2ghz;
176 	uint8_t				calib_5ghz;
177 	uint8_t				txmixgain_2ghz;
178 	uint8_t				txmixgain_5ghz;
179 	uint8_t				tssi_2ghz[9];
180 	uint8_t				tssi_5ghz[9];
181 	uint8_t				step_2ghz;
182 	uint8_t				step_5ghz;
183 	struct {
184 		uint8_t	reg;
185 		uint8_t	val;
186 	}				bbp[8], rf[10];
187 	uint8_t				leds;
188 	uint16_t			led[3];
189 	uint32_t			txpow20mhz[5];
190 	uint32_t			txpow40mhz_2ghz[5];
191 	uint32_t			txpow40mhz_5ghz[5];
192 
193 	struct ieee80211_amrr_node	amn[RT2860_WCID_MAX + 1];
194 
195 	struct bpf_if			*sc_drvbpf;
196 	union {
197 		struct rt2860_rx_radiotap_header th;
198 		uint8_t pad[64];
199 	}				sc_rxtapu;
200 #define sc_rxtap			sc_rxtapu.th
201 	int				sc_rxtap_len;
202 
203 	union {
204 		struct rt2860_tx_radiotap_header th;
205 		uint8_t pad[64];
206 	}				sc_txtapu;
207 #define sc_txtap			sc_txtapu.th
208 	int				sc_txtap_len;
209 };
210 
211 int	rt2860_attach(void *, int);
212 int	rt2860_detach(void *);
213 void	rt2860_suspend(void *);
214 void	rt2860_wakeup(void *);
215 int	rt2860_intr(void *);
216