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