xref: /freebsd/sys/dev/usb/wlan/if_uathvar.h (revision 924226fba12cc9a228c73b956e1b7fa24c60b055)
1 /*	$OpenBSD: if_uathvar.h,v 1.3 2006/09/20 19:47:17 damien Exp $	*/
2 /*	$FreeBSD$	*/
3 
4 /*-
5  * Copyright (c) 2006
6  *	Damien Bergamini <damien.bergamini@free.fr>
7  * Copyright (c) 2006 Sam Leffler, Errno Consulting
8  * Copyright (c) 2008-2009 Weongyo Jeong <weongyo@freebsd.org>
9  *
10  * Permission to use, copy, modify, and distribute this software for any
11  * purpose with or without fee is hereby granted, provided that the above
12  * copyright notice and this permission notice appear in all copies.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21  */
22 
23 enum {
24 	UATH_INTR_RX,
25 	UATH_INTR_TX,
26 	UATH_BULK_RX,
27 	UATH_BULK_TX,
28 	UATH_N_XFERS = 4,
29 };
30 
31 #define	UATH_ID_BSS		2	/* Connection ID  */
32 
33 #define	UATH_RX_DATA_LIST_COUNT	128
34 #define	UATH_TX_DATA_LIST_COUNT	16
35 #define	UATH_CMD_LIST_COUNT	60
36 
37 #define	UATH_DATA_TIMEOUT	10000
38 #define	UATH_CMD_TIMEOUT	1000
39 
40 /* flags for sending firmware commands */
41 #define	UATH_CMD_FLAG_ASYNC	(1 << 0)
42 #define	UATH_CMD_FLAG_READ	(1 << 1)
43 #define	UATH_CMD_FLAG_MAGIC	(1 << 2)
44 
45 struct uath_rx_radiotap_header {
46 	struct ieee80211_radiotap_header wr_ihdr;
47 	u_int64_t	wr_tsf;
48 	u_int8_t	wr_flags;
49 	u_int8_t	wr_rate;
50 	uint16_t	wr_chan_freq;
51 	uint16_t	wr_chan_flags;
52 	int8_t		wr_antsignal;
53 	int8_t		wr_antnoise;
54 	u_int8_t	wr_antenna;
55 } __packed __aligned(8);
56 
57 #define UATH_RX_RADIOTAP_PRESENT (		\
58 	(1 << IEEE80211_RADIOTAP_TSFT)		| \
59 	(1 << IEEE80211_RADIOTAP_FLAGS)		| \
60 	(1 << IEEE80211_RADIOTAP_RATE)		| \
61 	(1 << IEEE80211_RADIOTAP_ANTENNA)	| \
62 	(1 << IEEE80211_RADIOTAP_CHANNEL)	| \
63 	(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL)	| \
64 	(1 << IEEE80211_RADIOTAP_DBM_ANTNOISE)	| \
65 	0)
66 
67 struct uath_tx_radiotap_header {
68 	struct ieee80211_radiotap_header wt_ihdr;
69 	uint8_t		wt_flags;
70 	uint8_t		wt_pad;
71 	uint16_t	wt_chan_freq;
72 	uint16_t	wt_chan_flags;
73 } __packed;
74 
75 #define	UATH_TX_RADIOTAP_PRESENT					\
76 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
77 	 (1 << IEEE80211_RADIOTAP_CHANNEL))
78 
79 struct uath_data {
80 	struct uath_softc		*sc;
81 	uint8_t				*buf;
82 	uint16_t			buflen;
83 	struct mbuf			*m;
84 	struct ieee80211_node		*ni;		/* NB: tx only */
85 	STAILQ_ENTRY(uath_data)		next;
86 };
87 typedef STAILQ_HEAD(, uath_data) uath_datahead;
88 
89 struct uath_cmd {
90 	struct uath_softc		*sc;
91 	uint32_t			flags;
92 	uint32_t			msgid;
93 	uint8_t				*buf;
94 	uint16_t			buflen;
95 	void				*odata;		/* NB: tx only */
96 	int				olen;		/* space in odata */
97 	STAILQ_ENTRY(uath_cmd)		next;
98 };
99 typedef STAILQ_HEAD(, uath_cmd) uath_cmdhead;
100 
101 struct uath_wme_settings {
102 	uint8_t				aifsn;
103 	uint8_t				logcwmin;
104 	uint8_t				logcwmax;
105 	uint16_t			txop;
106 	uint8_t				acm;
107 };
108 
109 struct uath_devcap {
110 	uint32_t			targetVersion;
111 	uint32_t			targetRevision;
112 	uint32_t			macVersion;
113 	uint32_t			macRevision;
114 	uint32_t			phyRevision;
115 	uint32_t			analog5GhzRevision;
116 	uint32_t			analog2GhzRevision;
117 	uint32_t			regDomain;
118 	uint32_t			regCapBits;
119 	uint32_t			countryCode;
120 	uint32_t			keyCacheSize;
121 	uint32_t			numTxQueues;
122 	uint32_t			connectionIdMax;
123 	uint32_t			wirelessModes;
124 #define	UATH_WIRELESS_MODE_11A		0x01
125 #define	UATH_WIRELESS_MODE_TURBO	0x02
126 #define	UATH_WIRELESS_MODE_11B		0x04
127 #define	UATH_WIRELESS_MODE_11G		0x08
128 #define	UATH_WIRELESS_MODE_108G		0x10
129 	uint32_t			chanSpreadSupport;
130 	uint32_t			compressSupport;
131 	uint32_t			burstSupport;
132 	uint32_t			fastFramesSupport;
133 	uint32_t			chapTuningSupport;
134 	uint32_t			turboGSupport;
135 	uint32_t			turboPrimeSupport;
136 	uint32_t			deviceType;
137 	uint32_t			wmeSupport;
138 	uint32_t			low2GhzChan;
139 	uint32_t			high2GhzChan;
140 	uint32_t			low5GhzChan;
141 	uint32_t			high5GhzChan;
142 	uint32_t			supportCipherWEP;
143 	uint32_t			supportCipherAES_CCM;
144 	uint32_t			supportCipherTKIP;
145 	uint32_t			supportCipherMicAES_CCM;
146 	uint32_t			supportMicTKIP;
147 	uint32_t			twiceAntennaGain5G;
148 	uint32_t			twiceAntennaGain2G;
149 };
150 
151 struct uath_stat {
152 	uint32_t			st_badchunkseqnum;
153 	uint32_t			st_invalidlen;
154 	uint32_t			st_multichunk;
155 	uint32_t			st_toobigrxpkt;
156 	uint32_t			st_stopinprogress;
157 	uint32_t			st_crcerr;
158 	uint32_t			st_phyerr;
159 	uint32_t			st_decrypt_crcerr;
160 	uint32_t			st_decrypt_micerr;
161 	uint32_t			st_decomperr;
162 	uint32_t			st_keyerr;
163 	uint32_t			st_err;
164 	/* CMD/RX/TX queues */
165 	uint32_t			st_cmd_active;
166 	uint32_t			st_cmd_inactive;
167 	uint32_t			st_cmd_pending;
168 	uint32_t			st_cmd_waiting;
169 	uint32_t			st_rx_active;
170 	uint32_t			st_rx_inactive;
171 	uint32_t			st_tx_active;
172 	uint32_t			st_tx_inactive;
173 	uint32_t			st_tx_pending;
174 };
175 #define	UATH_STAT_INC(sc, var)		(sc)->sc_stat.var++
176 #define	UATH_STAT_DEC(sc, var)		(sc)->sc_stat.var--
177 
178 struct uath_vap {
179 	struct ieee80211vap		vap;
180 	int				(*newstate)(struct ieee80211vap *,
181 					    enum ieee80211_state, int);
182 };
183 #define	UATH_VAP(vap)			((struct uath_vap *)(vap))
184 
185 struct uath_softc {
186 	struct ieee80211com		sc_ic;
187 	struct mbufq			sc_snd;
188 	device_t			sc_dev;
189 	struct usb_device		*sc_udev;
190 	void				*sc_cmd_dma_buf;
191 	void				*sc_tx_dma_buf;
192 	struct mtx			sc_mtx;
193 	uint32_t			sc_debug;
194 
195 	struct uath_stat		sc_stat;
196 	int				(*sc_newstate)(struct ieee80211com *,
197 					    enum ieee80211_state, int);
198 
199 	struct usb_xfer		*sc_xfer[UATH_N_XFERS];
200 	struct uath_cmd			sc_cmd[UATH_CMD_LIST_COUNT];
201 	uath_cmdhead			sc_cmd_active;
202 	uath_cmdhead			sc_cmd_inactive;
203 	uath_cmdhead			sc_cmd_pending;
204 	uath_cmdhead			sc_cmd_waiting;
205 	struct uath_data		sc_rx[UATH_RX_DATA_LIST_COUNT];
206 	uath_datahead			sc_rx_active;
207 	uath_datahead			sc_rx_inactive;
208 	struct uath_data		sc_tx[UATH_TX_DATA_LIST_COUNT];
209 	uath_datahead			sc_tx_active;
210 	uath_datahead			sc_tx_inactive;
211 	uath_datahead			sc_tx_pending;
212 
213 	uint32_t			sc_msgid;
214 	uint32_t			sc_seqnum;
215 	int				sc_tx_timer;
216 	struct callout			watchdog_ch;
217 	struct callout			stat_ch;
218 	/* multi-chunked support  */
219 	struct mbuf			*sc_intrx_head;
220 	struct mbuf			*sc_intrx_tail;
221 	uint8_t				sc_intrx_nextnum;
222 	uint32_t			sc_intrx_len;
223 #define	UATH_MAX_INTRX_SIZE		3616
224 
225 	struct uath_devcap		sc_devcap;
226 	uint8_t				sc_serial[16];
227 
228 	/* unsorted  */
229 	uint32_t			sc_flags;
230 #define	UATH_FLAG_INVALID		(1 << 1)
231 #define	UATH_FLAG_INITDONE		(1 << 2)
232 
233 	struct	uath_rx_radiotap_header	sc_rxtap;
234 	struct	uath_tx_radiotap_header	sc_txtap;
235 };
236 
237 #define	UATH_LOCK(sc)			mtx_lock(&(sc)->sc_mtx)
238 #define	UATH_UNLOCK(sc)			mtx_unlock(&(sc)->sc_mtx)
239 #define	UATH_ASSERT_LOCKED(sc)		mtx_assert(&(sc)->sc_mtx, MA_OWNED)
240 
241 #define	UATH_RESET_INTRX(sc) do {		\
242 	(sc)->sc_intrx_head = NULL;		\
243 	(sc)->sc_intrx_tail = NULL;		\
244 	(sc)->sc_intrx_nextnum = 0;		\
245 	(sc)->sc_intrx_len = 0;			\
246 } while (0)
247