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