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