xref: /freebsd/sys/dev/usb/wlan/if_uathvar.h (revision f4f8f02054f3abb6ceb84aefcdecc78d5c8b462f)
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 	uint8_t				wr_flags;
48 	uint16_t			wr_chan_freq;
49 	uint16_t			wr_chan_flags;
50 	int8_t				wr_dbm_antsignal;
51 } __packed;
52 
53 #define	UATH_RX_RADIOTAP_PRESENT					\
54 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
55 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
56 	 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL))
57 
58 struct uath_tx_radiotap_header {
59 	struct ieee80211_radiotap_header wt_ihdr;
60 	uint8_t				wt_flags;
61 	uint16_t			wt_chan_freq;
62 	uint16_t			wt_chan_flags;
63 } __packed;
64 
65 #define	UATH_TX_RADIOTAP_PRESENT					\
66 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
67 	 (1 << IEEE80211_RADIOTAP_CHANNEL))
68 
69 struct uath_data {
70 	struct uath_softc		*sc;
71 	uint8_t				*buf;
72 	uint16_t			buflen;
73 	struct mbuf			*m;
74 	struct ieee80211_node		*ni;		/* NB: tx only */
75 	STAILQ_ENTRY(uath_data)		next;
76 };
77 typedef STAILQ_HEAD(, uath_data) uath_datahead;
78 
79 struct uath_cmd {
80 	struct uath_softc		*sc;
81 	uint32_t			flags;
82 	uint32_t			msgid;
83 	uint8_t				*buf;
84 	uint16_t			buflen;
85 	void				*odata;		/* NB: tx only */
86 	int				olen;		/* space in odata */
87 	STAILQ_ENTRY(uath_cmd)		next;
88 };
89 typedef STAILQ_HEAD(, uath_cmd) uath_cmdhead;
90 
91 struct uath_wme_settings {
92 	uint8_t				aifsn;
93 	uint8_t				logcwmin;
94 	uint8_t				logcwmax;
95 	uint16_t			txop;
96 #define	UATH_TXOP_TO_US(txop)		((txop) << 5)
97 	uint8_t				acm;
98 };
99 
100 struct uath_devcap {
101 	uint32_t			targetVersion;
102 	uint32_t			targetRevision;
103 	uint32_t			macVersion;
104 	uint32_t			macRevision;
105 	uint32_t			phyRevision;
106 	uint32_t			analog5GhzRevision;
107 	uint32_t			analog2GhzRevision;
108 	uint32_t			regDomain;
109 	uint32_t			regCapBits;
110 	uint32_t			countryCode;
111 	uint32_t			keyCacheSize;
112 	uint32_t			numTxQueues;
113 	uint32_t			connectionIdMax;
114 	uint32_t			wirelessModes;
115 #define	UATH_WIRELESS_MODE_11A		0x01
116 #define	UATH_WIRELESS_MODE_TURBO	0x02
117 #define	UATH_WIRELESS_MODE_11B		0x04
118 #define	UATH_WIRELESS_MODE_11G		0x08
119 #define	UATH_WIRELESS_MODE_108G		0x10
120 	uint32_t			chanSpreadSupport;
121 	uint32_t			compressSupport;
122 	uint32_t			burstSupport;
123 	uint32_t			fastFramesSupport;
124 	uint32_t			chapTuningSupport;
125 	uint32_t			turboGSupport;
126 	uint32_t			turboPrimeSupport;
127 	uint32_t			deviceType;
128 	uint32_t			wmeSupport;
129 	uint32_t			low2GhzChan;
130 	uint32_t			high2GhzChan;
131 	uint32_t			low5GhzChan;
132 	uint32_t			high5GhzChan;
133 	uint32_t			supportCipherWEP;
134 	uint32_t			supportCipherAES_CCM;
135 	uint32_t			supportCipherTKIP;
136 	uint32_t			supportCipherMicAES_CCM;
137 	uint32_t			supportMicTKIP;
138 	uint32_t			twiceAntennaGain5G;
139 	uint32_t			twiceAntennaGain2G;
140 };
141 
142 struct uath_stat {
143 	uint32_t			st_badchunkseqnum;
144 	uint32_t			st_invalidlen;
145 	uint32_t			st_multichunk;
146 	uint32_t			st_toobigrxpkt;
147 	uint32_t			st_stopinprogress;
148 	uint32_t			st_crcerr;
149 	uint32_t			st_phyerr;
150 	uint32_t			st_decrypt_crcerr;
151 	uint32_t			st_decrypt_micerr;
152 	uint32_t			st_decomperr;
153 	uint32_t			st_keyerr;
154 	uint32_t			st_err;
155 	/* CMD/RX/TX queues */
156 	uint32_t			st_cmd_active;
157 	uint32_t			st_cmd_inactive;
158 	uint32_t			st_cmd_pending;
159 	uint32_t			st_cmd_waiting;
160 	uint32_t			st_rx_active;
161 	uint32_t			st_rx_inactive;
162 	uint32_t			st_tx_active;
163 	uint32_t			st_tx_inactive;
164 	uint32_t			st_tx_pending;
165 };
166 #define	UATH_STAT_INC(sc, var)		(sc)->sc_stat.var++
167 #define	UATH_STAT_DEC(sc, var)		(sc)->sc_stat.var--
168 
169 struct uath_vap {
170 	struct ieee80211vap		vap;
171 	int				(*newstate)(struct ieee80211vap *,
172 					    enum ieee80211_state, int);
173 };
174 #define	UATH_VAP(vap)			((struct uath_vap *)(vap))
175 
176 struct uath_softc {
177 	struct ifnet			*sc_ifp;
178 	device_t			sc_dev;
179 	struct usb2_device		*sc_udev;
180 	struct mtx			sc_mtx;
181 	uint32_t			sc_debug;
182 
183 	struct uath_stat		sc_stat;
184 	int				(*sc_newstate)(struct ieee80211com *,
185 					    enum ieee80211_state, int);
186 
187 	struct usb2_xfer		*sc_xfer[UATH_N_XFERS];
188 	struct uath_cmd			sc_cmd[UATH_CMD_LIST_COUNT];
189 	uath_cmdhead			sc_cmd_active;
190 	uath_cmdhead			sc_cmd_inactive;
191 	uath_cmdhead			sc_cmd_pending;
192 	uath_cmdhead			sc_cmd_waiting;
193 	struct uath_data		sc_rx[UATH_RX_DATA_LIST_COUNT];
194 	uath_datahead			sc_rx_active;
195 	uath_datahead			sc_rx_inactive;
196 	struct uath_data		sc_tx[UATH_TX_DATA_LIST_COUNT];
197 	uath_datahead			sc_tx_active;
198 	uath_datahead			sc_tx_inactive;
199 	uath_datahead			sc_tx_pending;
200 
201 	uint32_t			sc_msgid;
202 	uint32_t			sc_seqnum;
203 	int				sc_tx_timer;
204 	struct callout			watchdog_ch;
205 	struct callout			stat_ch;
206 	/* multi-chunked support  */
207 	struct mbuf			*sc_intrx_head;
208 	struct mbuf			*sc_intrx_tail;
209 	uint8_t				sc_intrx_nextnum;
210 	uint32_t			sc_intrx_len;
211 #define	UATH_MAX_INTRX_SIZE		3616
212 
213 	struct uath_devcap		sc_devcap;
214 	uint8_t				sc_serial[16];
215 
216 	/* unsorted  */
217 	uint32_t			sc_flags;
218 #define	UATH_FLAG_INVALID		(1 << 1)
219 #define	UATH_FLAG_INITDONE		(1 << 2)
220 
221 	struct	uath_rx_radiotap_header	sc_rxtap;
222 	int				sc_rxtap_len;
223 	struct	uath_tx_radiotap_header	sc_txtap;
224 	int				sc_txtap_len;
225 };
226 
227 #define	UATH_LOCK(sc)			mtx_lock(&(sc)->sc_mtx)
228 #define	UATH_UNLOCK(sc)			mtx_unlock(&(sc)->sc_mtx)
229 #define	UATH_ASSERT_LOCKED(sc)		mtx_assert(&(sc)->sc_mtx, MA_OWNED)
230 
231 #define	UATH_RESET_INTRX(sc) do {		\
232 	(sc)->sc_intrx_head = NULL;		\
233 	(sc)->sc_intrx_tail = NULL;		\
234 	(sc)->sc_intrx_nextnum = 0;		\
235 	(sc)->sc_intrx_len = 0;			\
236 } while (0)
237