xref: /freebsd/sys/dev/usb/wlan/if_runvar.h (revision 9a14aa017b21c292740c00ee098195cd46642730)
1 /*	$OpenBSD: if_runvar.h,v 1.3 2009/03/26 20:17:27 damien Exp $	*/
2 
3 /*-
4  * Copyright (c) 2008,2009 Damien Bergamini <damien.bergamini@free.fr>
5  * ported to FreeBSD by Akinori Furukoshi <moonlightakkiy@yahoo.ca>
6  * USB Consulting, Hans Petter Selasky <hselasky@freebsd.org>
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  * $FreeBSD$
21  */
22 
23 #ifndef _IF_RUNVAR_H_
24 #define	_IF_RUNVAR_H_
25 
26 #define RUN_MAX_RXSZ			\
27 	MIN(4096, MJUMPAGESIZE)
28 #if 0
29 	(sizeof (uint32_t) +		\
30 	 sizeof (struct rt2860_rxwi) +	\
31 	 sizeof (uint16_t) +		\
32 	 MCLBYTES +			\
33 	 sizeof (struct rt2870_rxd))
34 #endif
35 /* NB: "11" is the maximum number of padding bytes needed for Tx */
36 #define RUN_MAX_TXSZ			\
37 	(sizeof (struct rt2870_txd) +	\
38 	 sizeof (struct rt2860_rxwi) +	\
39 	 MCLBYTES + 11)
40 
41 #define RUN_TX_TIMEOUT	5000	/* ms */
42 
43 /* Tx ring count was 8/endpoint, now 32 for all 4 (or 6) endpoints. */
44 #define RUN_TX_RING_COUNT	32
45 #define RUN_RX_RING_COUNT	1
46 
47 #define RT2870_WCID_MAX		64
48 #define RUN_AID2WCID(aid)	((aid) & 0xff)
49 
50 #define RUN_VAP_MAX		8
51 
52 struct run_rx_radiotap_header {
53 	struct ieee80211_radiotap_header wr_ihdr;
54 	uint8_t		wr_flags;
55 	uint8_t		wr_rate;
56 	uint16_t	wr_chan_freq;
57 	uint16_t	wr_chan_flags;
58 	int8_t		wr_dbm_antsignal;
59 	uint8_t		wr_antenna;
60 	uint8_t		wr_antsignal;
61 } __packed;
62 
63 #define RUN_RX_RADIOTAP_PRESENT				\
64 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
65 	 1 << IEEE80211_RADIOTAP_RATE |			\
66 	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
67 	 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL |	\
68 	 1 << IEEE80211_RADIOTAP_ANTENNA |		\
69 	 1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL)
70 
71 struct run_tx_radiotap_header {
72 	struct ieee80211_radiotap_header wt_ihdr;
73 	uint8_t		wt_flags;
74 	uint8_t		wt_rate;
75 	uint16_t	wt_chan_freq;
76 	uint16_t	wt_chan_flags;
77 	uint8_t		wt_hwqueue;
78 } __packed;
79 
80 #define IEEE80211_RADIOTAP_HWQUEUE 15
81 
82 #define RUN_TX_RADIOTAP_PRESENT				\
83 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
84 	 1 << IEEE80211_RADIOTAP_RATE |			\
85 	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
86 	 1 << IEEE80211_RADIOTAP_HWQUEUE)
87 
88 struct run_softc;
89 
90 struct run_tx_data {
91 	STAILQ_ENTRY(run_tx_data)	next;
92 	struct run_softc	*sc;
93 	struct mbuf		*m;
94 	struct ieee80211_node	*ni;
95 	uint32_t align[0];	/* dummy field */
96 	uint8_t	desc[sizeof(struct rt2870_txd) +
97 		     sizeof(struct rt2860_txwi)];
98 	uint8_t			ridx;
99 };
100 STAILQ_HEAD(run_tx_data_head, run_tx_data);
101 
102 struct run_node {
103 	struct ieee80211_node	ni;
104 	uint8_t			ridx[IEEE80211_RATE_MAXSIZE];
105 	uint8_t			ctl_ridx[IEEE80211_RATE_MAXSIZE];
106 	uint8_t			amrr_ridx;
107 	uint8_t			mgt_ridx;
108 	uint8_t			fix_ridx;
109 };
110 
111 struct run_cmdq {
112 	void			*arg0;
113 	void			*arg1;
114 	void			(*func)(void *);
115 	struct ieee80211_key	*k;
116 	struct ieee80211_key	key;
117 	uint8_t			mac[IEEE80211_ADDR_LEN];
118 	uint8_t			wcid;
119 };
120 
121 struct run_vap {
122 	struct ieee80211vap             vap;
123 	struct ieee80211_beacon_offsets bo;
124 	struct mbuf			*beacon_mbuf;
125 
126 	int                             (*newstate)(struct ieee80211vap *,
127                                             enum ieee80211_state, int);
128 
129 	uint8_t				rvp_id;
130 };
131 #define RUN_VAP(vap)    ((struct run_vap *)(vap))
132 
133 /*
134  * There are 7 bulk endpoints: 1 for RX
135  * and 6 for TX (4 EDCAs + HCCA + Prio).
136  * Update 03-14-2009:  some devices like the Planex GW-US300MiniS
137  * seem to have only 4 TX bulk endpoints (Fukaumi Naoki).
138  */
139 enum {
140 	RUN_BULK_TX_BE,		/* = WME_AC_BE */
141 	RUN_BULK_TX_BK,		/* = WME_AC_BK */
142 	RUN_BULK_TX_VI,		/* = WME_AC_VI */
143 	RUN_BULK_TX_VO,		/* = WME_AC_VO */
144 	RUN_BULK_TX_HCCA,
145 	RUN_BULK_TX_PRIO,
146 	RUN_BULK_RX,
147 	RUN_N_XFER,
148 };
149 
150 #define	RUN_EP_QUEUES	RUN_BULK_RX
151 
152 struct run_endpoint_queue {
153 	struct run_tx_data		tx_data[RUN_TX_RING_COUNT];
154 	struct run_tx_data_head		tx_qh;
155 	struct run_tx_data_head		tx_fh;
156 	uint32_t			tx_nfree;
157 };
158 
159 struct run_softc {
160 	device_t			sc_dev;
161 	struct usb_device		*sc_udev;
162 	struct ifnet			*sc_ifp;
163 	uint16_t			wcid_stats[RT2870_WCID_MAX + 1][3];
164 #define	RUN_TXCNT	0
165 #define	RUN_SUCCESS	1
166 #define	RUN_RETRY	2
167 
168 	int				(*sc_srom_read)(struct run_softc *,
169 					    uint16_t, uint16_t *);
170 
171 	uint16_t			mac_ver;
172 	uint16_t			mac_rev;
173 	uint8_t				rf_rev;
174 	uint8_t				freq;
175 	uint8_t				ntxchains;
176 	uint8_t				nrxchains;
177 
178 	uint8_t				bbp25;
179 	uint8_t				bbp26;
180 	uint8_t				rf24_20mhz;
181 	uint8_t				rf24_40mhz;
182 	uint8_t				patch_dac;
183 	uint8_t				rfswitch;
184 	uint8_t				ext_2ghz_lna;
185 	uint8_t				ext_5ghz_lna;
186 	uint8_t				calib_2ghz;
187 	uint8_t				calib_5ghz;
188 	uint8_t				txmixgain_2ghz;
189 	uint8_t				txmixgain_5ghz;
190 	int8_t				txpow1[54];
191 	int8_t				txpow2[54];
192 	int8_t				rssi_2ghz[3];
193 	int8_t				rssi_5ghz[3];
194 	uint8_t				lna[4];
195 
196 	struct {
197 		uint8_t	reg;
198 		uint8_t	val;
199 	}				bbp[10], rf[10];
200 	uint8_t				leds;
201 	uint16_t			led[3];
202 	uint32_t			txpow20mhz[5];
203 	uint32_t			txpow40mhz_2ghz[5];
204 	uint32_t			txpow40mhz_5ghz[5];
205 
206 	uint8_t				sc_bssid[6];
207 
208 	struct mtx			sc_mtx;
209 
210 	struct run_endpoint_queue	sc_epq[RUN_EP_QUEUES];
211 
212 	struct task                     ratectl_task;
213 	struct usb_callout              ratectl_ch;
214 	uint8_t				ratectl_run;
215 #define RUN_RATECTL_OFF	0
216 
217 /* need to be power of 2, otherwise RUN_CMDQ_GET fails */
218 #define RUN_CMDQ_MAX	16
219 #define RUN_CMDQ_MASQ	(RUN_CMDQ_MAX - 1)
220 	struct run_cmdq			cmdq[RUN_CMDQ_MAX];
221 	struct task			cmdq_task;
222 	uint32_t			cmdq_store;
223 	uint8_t				cmdq_exec;
224 	uint8_t				cmdq_run;
225 	uint8_t				cmdq_key_set;
226 #define RUN_CMDQ_ABORT	0
227 #define RUN_CMDQ_GO	1
228 
229 	struct usb_xfer			*sc_xfer[RUN_N_XFER];
230 
231 	struct mbuf			*rx_m;
232 
233 	uint8_t				fifo_cnt;
234 
235 	uint8_t				running;
236 	uint8_t				runbmap;
237 	uint8_t				ap_running;
238 	uint8_t				adhoc_running;
239 	uint8_t				sta_running;
240 	uint8_t				rvp_cnt;
241 	uint8_t				rvp_bmap;
242 
243 	union {
244 		struct run_rx_radiotap_header th;
245 		uint8_t	pad[64];
246 	}				sc_rxtapu;
247 #define sc_rxtap	sc_rxtapu.th
248 	int				sc_rxtap_len;
249 
250 	union {
251 		struct run_tx_radiotap_header th;
252 		uint8_t	pad[64];
253 	}				sc_txtapu;
254 #define sc_txtap	sc_txtapu.th
255 	int				sc_txtap_len;
256 };
257 
258 #define RUN_LOCK(sc)		mtx_lock(&(sc)->sc_mtx)
259 #define RUN_UNLOCK(sc)		mtx_unlock(&(sc)->sc_mtx)
260 #define RUN_LOCK_ASSERT(sc, t)	mtx_assert(&(sc)->sc_mtx, t)
261 
262 #endif	/* _IF_RUNVAR_H_ */
263