if_uathvar.h revision 259454
1193326Sed/*	$OpenBSD: if_uathvar.h,v 1.3 2006/09/20 19:47:17 damien Exp $	*/
2193326Sed/*	$FreeBSD: stable/9/sys/dev/usb/wlan/if_uathvar.h 259454 2013-12-16 08:51:58Z hselasky $	*/
3193326Sed
4193326Sed/*-
5193326Sed * Copyright (c) 2006
6193326Sed *	Damien Bergamini <damien.bergamini@free.fr>
7193326Sed * Copyright (c) 2006 Sam Leffler, Errno Consulting
8193326Sed * Copyright (c) 2008-2009 Weongyo Jeong <weongyo@freebsd.org>
9193326Sed *
10193326Sed * Permission to use, copy, modify, and distribute this software for any
11193326Sed * purpose with or without fee is hereby granted, provided that the above
12193326Sed * copyright notice and this permission notice appear in all copies.
13193326Sed *
14193326Sed * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15202379Srdivacky * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16193326Sed * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17193326Sed * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18193326Sed * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19193326Sed * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20193326Sed * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21193326Sed */
22193326Sed
23193326Sedenum {
24193326Sed	UATH_INTR_RX,
25193326Sed	UATH_INTR_TX,
26193326Sed	UATH_BULK_RX,
27193326Sed	UATH_BULK_TX,
28198092Srdivacky	UATH_N_XFERS = 4,
29193326Sed};
30193326Sed
31193326Sed#define	UATH_ID_BSS		2	/* Connection ID  */
32193326Sed
33193326Sed#define	UATH_RX_DATA_LIST_COUNT	128
34193326Sed#define	UATH_TX_DATA_LIST_COUNT	16
35193326Sed#define	UATH_CMD_LIST_COUNT	60
36193326Sed
37193326Sed#define	UATH_DATA_TIMEOUT	10000
38198092Srdivacky#define	UATH_CMD_TIMEOUT	1000
39193326Sed
40193326Sed/* flags for sending firmware commands */
41204643Srdivacky#define	UATH_CMD_FLAG_ASYNC	(1 << 0)
42204643Srdivacky#define	UATH_CMD_FLAG_READ	(1 << 1)
43193326Sed#define	UATH_CMD_FLAG_MAGIC	(1 << 2)
44193326Sed
45193326Sedstruct uath_rx_radiotap_header {
46193326Sed	struct ieee80211_radiotap_header wr_ihdr;
47193326Sed	u_int64_t	wr_tsf;
48198092Srdivacky	u_int8_t	wr_flags;
49193326Sed	u_int8_t	wr_rate;
50193326Sed	uint16_t	wr_chan_freq;
51193326Sed	uint16_t	wr_chan_flags;
52193326Sed	int8_t		wr_antsignal;
53193326Sed	int8_t		wr_antnoise;
54193326Sed	u_int8_t	wr_antenna;
55193326Sed} __packed;
56193326Sed
57193326Sed#define UATH_RX_RADIOTAP_PRESENT (		\
58193326Sed	(1 << IEEE80211_RADIOTAP_TSFT)		| \
59193326Sed	(1 << IEEE80211_RADIOTAP_FLAGS)		| \
60193326Sed	(1 << IEEE80211_RADIOTAP_RATE)		| \
61193326Sed	(1 << IEEE80211_RADIOTAP_ANTENNA)	| \
62193326Sed	(1 << IEEE80211_RADIOTAP_CHANNEL)	| \
63193326Sed	(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL)	| \
64202879Srdivacky	(1 << IEEE80211_RADIOTAP_DBM_ANTNOISE)	| \
65193326Sed	0)
66193326Sed
67198092Srdivackystruct uath_tx_radiotap_header {
68193326Sed	struct ieee80211_radiotap_header wt_ihdr;
69207619Srdivacky	uint8_t		wt_flags;
70207619Srdivacky	uint16_t	wt_chan_freq;
71193326Sed	uint16_t	wt_chan_flags;
72193326Sed} __packed;
73193326Sed
74193326Sed#define	UATH_TX_RADIOTAP_PRESENT					\
75193326Sed	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
76198092Srdivacky	 (1 << IEEE80211_RADIOTAP_CHANNEL))
77193326Sed
78193326Sedstruct uath_data {
79193326Sed	struct uath_softc		*sc;
80193326Sed	uint8_t				*buf;
81193326Sed	uint16_t			buflen;
82193326Sed	struct mbuf			*m;
83193326Sed	struct ieee80211_node		*ni;		/* NB: tx only */
84193326Sed	STAILQ_ENTRY(uath_data)		next;
85193326Sed};
86193326Sedtypedef STAILQ_HEAD(, uath_data) uath_datahead;
87193326Sed
88193326Sedstruct uath_cmd {
89193326Sed	struct uath_softc		*sc;
90193326Sed	uint32_t			flags;
91198092Srdivacky	uint32_t			msgid;
92199482Srdivacky	uint8_t				*buf;
93199482Srdivacky	uint16_t			buflen;
94199482Srdivacky	void				*odata;		/* NB: tx only */
95199482Srdivacky	int				olen;		/* space in odata */
96207619Srdivacky	STAILQ_ENTRY(uath_cmd)		next;
97199482Srdivacky};
98199482Srdivackytypedef STAILQ_HEAD(, uath_cmd) uath_cmdhead;
99199482Srdivacky
100199482Srdivackystruct uath_wme_settings {
101193326Sed	uint8_t				aifsn;
102193326Sed	uint8_t				logcwmin;
103198092Srdivacky	uint8_t				logcwmax;
104193326Sed	uint16_t			txop;
105193326Sed#define	UATH_TXOP_TO_US(txop)		((txop) << 5)
106194613Sed	uint8_t				acm;
107198092Srdivacky};
108193326Sed
109193326Sedstruct uath_devcap {
110198092Srdivacky	uint32_t			targetVersion;
111193326Sed	uint32_t			targetRevision;
112193326Sed	uint32_t			macVersion;
113207619Srdivacky	uint32_t			macRevision;
114207619Srdivacky	uint32_t			phyRevision;
115202379Srdivacky	uint32_t			analog5GhzRevision;
116202379Srdivacky	uint32_t			analog2GhzRevision;
117202379Srdivacky	uint32_t			regDomain;
118202379Srdivacky	uint32_t			regCapBits;
119207619Srdivacky	uint32_t			countryCode;
120202379Srdivacky	uint32_t			keyCacheSize;
121202379Srdivacky	uint32_t			numTxQueues;
122202379Srdivacky	uint32_t			connectionIdMax;
123202379Srdivacky	uint32_t			wirelessModes;
124202379Srdivacky#define	UATH_WIRELESS_MODE_11A		0x01
125202379Srdivacky#define	UATH_WIRELESS_MODE_TURBO	0x02
126202379Srdivacky#define	UATH_WIRELESS_MODE_11B		0x04
127202379Srdivacky#define	UATH_WIRELESS_MODE_11G		0x08
128198092Srdivacky#define	UATH_WIRELESS_MODE_108G		0x10
129198092Srdivacky	uint32_t			chanSpreadSupport;
130198092Srdivacky	uint32_t			compressSupport;
131198092Srdivacky	uint32_t			burstSupport;
132198092Srdivacky	uint32_t			fastFramesSupport;
133198092Srdivacky	uint32_t			chapTuningSupport;
134198092Srdivacky	uint32_t			turboGSupport;
135193326Sed	uint32_t			turboPrimeSupport;
136198092Srdivacky	uint32_t			deviceType;
137198092Srdivacky	uint32_t			wmeSupport;
138198092Srdivacky	uint32_t			low2GhzChan;
139193326Sed	uint32_t			high2GhzChan;
140198092Srdivacky	uint32_t			low5GhzChan;
141198092Srdivacky	uint32_t			high5GhzChan;
142198092Srdivacky	uint32_t			supportCipherWEP;
143198092Srdivacky	uint32_t			supportCipherAES_CCM;
144198092Srdivacky	uint32_t			supportCipherTKIP;
145208600Srdivacky	uint32_t			supportCipherMicAES_CCM;
146208600Srdivacky	uint32_t			supportMicTKIP;
147198092Srdivacky	uint32_t			twiceAntennaGain5G;
148198092Srdivacky	uint32_t			twiceAntennaGain2G;
149193326Sed};
150198092Srdivacky
151198092Srdivackystruct uath_stat {
152198092Srdivacky	uint32_t			st_badchunkseqnum;
153198092Srdivacky	uint32_t			st_invalidlen;
154198092Srdivacky	uint32_t			st_multichunk;
155198092Srdivacky	uint32_t			st_toobigrxpkt;
156198092Srdivacky	uint32_t			st_stopinprogress;
157198092Srdivacky	uint32_t			st_crcerr;
158198092Srdivacky	uint32_t			st_phyerr;
159198092Srdivacky	uint32_t			st_decrypt_crcerr;
160193326Sed	uint32_t			st_decrypt_micerr;
161198092Srdivacky	uint32_t			st_decomperr;
162198092Srdivacky	uint32_t			st_keyerr;
163198092Srdivacky	uint32_t			st_err;
164198092Srdivacky	/* CMD/RX/TX queues */
165198092Srdivacky	uint32_t			st_cmd_active;
166198092Srdivacky	uint32_t			st_cmd_inactive;
167198092Srdivacky	uint32_t			st_cmd_pending;
168198092Srdivacky	uint32_t			st_cmd_waiting;
169198092Srdivacky	uint32_t			st_rx_active;
170193326Sed	uint32_t			st_rx_inactive;
171198092Srdivacky	uint32_t			st_tx_active;
172198092Srdivacky	uint32_t			st_tx_inactive;
173198092Srdivacky	uint32_t			st_tx_pending;
174193326Sed};
175193326Sed#define	UATH_STAT_INC(sc, var)		(sc)->sc_stat.var++
176193326Sed#define	UATH_STAT_DEC(sc, var)		(sc)->sc_stat.var--
177193326Sed
178198092Srdivackystruct uath_vap {
179193326Sed	struct ieee80211vap		vap;
180193326Sed	int				(*newstate)(struct ieee80211vap *,
181193326Sed					    enum ieee80211_state, int);
182202879Srdivacky};
183193326Sed#define	UATH_VAP(vap)			((struct uath_vap *)(vap))
184193326Sed
185198092Srdivackystruct uath_softc {
186193326Sed	struct ifnet			*sc_ifp;
187193326Sed	device_t			sc_dev;
188193326Sed	struct usb_device		*sc_udev;
189193326Sed	void				*sc_cmd_dma_buf;
190193326Sed	void				*sc_tx_dma_buf;
191193326Sed	struct mtx			sc_mtx;
192193326Sed	uint32_t			sc_debug;
193198092Srdivacky
194193326Sed	struct uath_stat		sc_stat;
195193326Sed	int				(*sc_newstate)(struct ieee80211com *,
196193326Sed					    enum ieee80211_state, int);
197193326Sed
198207619Srdivacky	struct usb_xfer		*sc_xfer[UATH_N_XFERS];
199207619Srdivacky	struct uath_cmd			sc_cmd[UATH_CMD_LIST_COUNT];
200193326Sed	uath_cmdhead			sc_cmd_active;
201193326Sed	uath_cmdhead			sc_cmd_inactive;
202193326Sed	uath_cmdhead			sc_cmd_pending;
203193326Sed	uath_cmdhead			sc_cmd_waiting;
204193326Sed	struct uath_data		sc_rx[UATH_RX_DATA_LIST_COUNT];
205193326Sed	uath_datahead			sc_rx_active;
206193326Sed	uath_datahead			sc_rx_inactive;
207193326Sed	struct uath_data		sc_tx[UATH_TX_DATA_LIST_COUNT];
208193326Sed	uath_datahead			sc_tx_active;
209207619Srdivacky	uath_datahead			sc_tx_inactive;
210207619Srdivacky	uath_datahead			sc_tx_pending;
211193326Sed
212193326Sed	uint32_t			sc_msgid;
213208600Srdivacky	uint32_t			sc_seqnum;
214208600Srdivacky	int				sc_tx_timer;
215193326Sed	struct callout			watchdog_ch;
216207619Srdivacky	struct callout			stat_ch;
217207619Srdivacky	/* multi-chunked support  */
218193326Sed	struct mbuf			*sc_intrx_head;
219193326Sed	struct mbuf			*sc_intrx_tail;
220193326Sed	uint8_t				sc_intrx_nextnum;
221193326Sed	uint32_t			sc_intrx_len;
222193326Sed#define	UATH_MAX_INTRX_SIZE		3616
223193326Sed
224193326Sed	struct uath_devcap		sc_devcap;
225193326Sed	uint8_t				sc_serial[16];
226193326Sed
227193326Sed	/* unsorted  */
228198092Srdivacky	uint32_t			sc_flags;
229193326Sed#define	UATH_FLAG_INVALID		(1 << 1)
230198092Srdivacky#define	UATH_FLAG_INITDONE		(1 << 2)
231193326Sed
232198092Srdivacky	struct	uath_rx_radiotap_header	sc_rxtap;
233193326Sed	int				sc_rxtap_len;
234193326Sed	struct	uath_tx_radiotap_header	sc_txtap;
235193326Sed	int				sc_txtap_len;
236193326Sed};
237193326Sed
238193326Sed#define	UATH_LOCK(sc)			mtx_lock(&(sc)->sc_mtx)
239193326Sed#define	UATH_UNLOCK(sc)			mtx_unlock(&(sc)->sc_mtx)
240193326Sed#define	UATH_ASSERT_LOCKED(sc)		mtx_assert(&(sc)->sc_mtx, MA_OWNED)
241193326Sed
242198092Srdivacky#define	UATH_RESET_INTRX(sc) do {		\
243193326Sed	(sc)->sc_intrx_head = NULL;		\
244193326Sed	(sc)->sc_intrx_tail = NULL;		\
245198092Srdivacky	(sc)->sc_intrx_nextnum = 0;		\
246207619Srdivacky	(sc)->sc_intrx_len = 0;			\
247207619Srdivacky} while (0)
248193326Sed