1190688Sweongyo/*	$OpenBSD: if_uathvar.h,v 1.3 2006/09/20 19:47:17 damien Exp $	*/
2190688Sweongyo/*	$FreeBSD: stable/11/sys/dev/usb/wlan/if_uathvar.h 345636 2019-03-28 09:50:25Z avos $	*/
3190688Sweongyo
4190688Sweongyo/*-
5190688Sweongyo * Copyright (c) 2006
6190688Sweongyo *	Damien Bergamini <damien.bergamini@free.fr>
7190688Sweongyo * Copyright (c) 2006 Sam Leffler, Errno Consulting
8190688Sweongyo * Copyright (c) 2008-2009 Weongyo Jeong <weongyo@freebsd.org>
9190688Sweongyo *
10190688Sweongyo * Permission to use, copy, modify, and distribute this software for any
11190688Sweongyo * purpose with or without fee is hereby granted, provided that the above
12190688Sweongyo * copyright notice and this permission notice appear in all copies.
13190688Sweongyo *
14190688Sweongyo * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15190688Sweongyo * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16190688Sweongyo * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17190688Sweongyo * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18190688Sweongyo * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19190688Sweongyo * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20190688Sweongyo * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21190688Sweongyo */
22190688Sweongyo
23190688Sweongyoenum {
24190688Sweongyo	UATH_INTR_RX,
25190688Sweongyo	UATH_INTR_TX,
26190688Sweongyo	UATH_BULK_RX,
27190688Sweongyo	UATH_BULK_TX,
28190688Sweongyo	UATH_N_XFERS = 4,
29190688Sweongyo};
30190688Sweongyo
31190688Sweongyo#define	UATH_ID_BSS		2	/* Connection ID  */
32190688Sweongyo
33190688Sweongyo#define	UATH_RX_DATA_LIST_COUNT	128
34190688Sweongyo#define	UATH_TX_DATA_LIST_COUNT	16
35190688Sweongyo#define	UATH_CMD_LIST_COUNT	60
36190688Sweongyo
37190688Sweongyo#define	UATH_DATA_TIMEOUT	10000
38190688Sweongyo#define	UATH_CMD_TIMEOUT	1000
39190688Sweongyo
40190688Sweongyo/* flags for sending firmware commands */
41190688Sweongyo#define	UATH_CMD_FLAG_ASYNC	(1 << 0)
42190688Sweongyo#define	UATH_CMD_FLAG_READ	(1 << 1)
43190688Sweongyo#define	UATH_CMD_FLAG_MAGIC	(1 << 2)
44190688Sweongyo
45190688Sweongyostruct uath_rx_radiotap_header {
46190688Sweongyo	struct ieee80211_radiotap_header wr_ihdr;
47192468Ssam	u_int64_t	wr_tsf;
48192468Ssam	u_int8_t	wr_flags;
49192468Ssam	u_int8_t	wr_rate;
50192468Ssam	uint16_t	wr_chan_freq;
51192468Ssam	uint16_t	wr_chan_flags;
52192468Ssam	int8_t		wr_antsignal;
53192468Ssam	int8_t		wr_antnoise;
54192468Ssam	u_int8_t	wr_antenna;
55253757Shselasky} __packed __aligned(8);
56190688Sweongyo
57192468Ssam#define UATH_RX_RADIOTAP_PRESENT (		\
58192468Ssam	(1 << IEEE80211_RADIOTAP_TSFT)		| \
59192468Ssam	(1 << IEEE80211_RADIOTAP_FLAGS)		| \
60192468Ssam	(1 << IEEE80211_RADIOTAP_RATE)		| \
61192468Ssam	(1 << IEEE80211_RADIOTAP_ANTENNA)	| \
62192468Ssam	(1 << IEEE80211_RADIOTAP_CHANNEL)	| \
63192468Ssam	(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL)	| \
64192468Ssam	(1 << IEEE80211_RADIOTAP_DBM_ANTNOISE)	| \
65192468Ssam	0)
66190688Sweongyo
67190688Sweongyostruct uath_tx_radiotap_header {
68190688Sweongyo	struct ieee80211_radiotap_header wt_ihdr;
69192468Ssam	uint8_t		wt_flags;
70345636Savos	uint8_t		wt_pad;
71192468Ssam	uint16_t	wt_chan_freq;
72192468Ssam	uint16_t	wt_chan_flags;
73345636Savos} __packed;
74190688Sweongyo
75190688Sweongyo#define	UATH_TX_RADIOTAP_PRESENT					\
76190688Sweongyo	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
77190688Sweongyo	 (1 << IEEE80211_RADIOTAP_CHANNEL))
78190688Sweongyo
79190688Sweongyostruct uath_data {
80190688Sweongyo	struct uath_softc		*sc;
81190688Sweongyo	uint8_t				*buf;
82190688Sweongyo	uint16_t			buflen;
83190688Sweongyo	struct mbuf			*m;
84190688Sweongyo	struct ieee80211_node		*ni;		/* NB: tx only */
85190688Sweongyo	STAILQ_ENTRY(uath_data)		next;
86190688Sweongyo};
87190688Sweongyotypedef STAILQ_HEAD(, uath_data) uath_datahead;
88190688Sweongyo
89190688Sweongyostruct uath_cmd {
90190688Sweongyo	struct uath_softc		*sc;
91190688Sweongyo	uint32_t			flags;
92190688Sweongyo	uint32_t			msgid;
93190688Sweongyo	uint8_t				*buf;
94190688Sweongyo	uint16_t			buflen;
95190688Sweongyo	void				*odata;		/* NB: tx only */
96190688Sweongyo	int				olen;		/* space in odata */
97190688Sweongyo	STAILQ_ENTRY(uath_cmd)		next;
98190688Sweongyo};
99190688Sweongyotypedef STAILQ_HEAD(, uath_cmd) uath_cmdhead;
100190688Sweongyo
101190688Sweongyostruct uath_wme_settings {
102190688Sweongyo	uint8_t				aifsn;
103190688Sweongyo	uint8_t				logcwmin;
104190688Sweongyo	uint8_t				logcwmax;
105190688Sweongyo	uint16_t			txop;
106190688Sweongyo	uint8_t				acm;
107190688Sweongyo};
108190688Sweongyo
109190688Sweongyostruct uath_devcap {
110190688Sweongyo	uint32_t			targetVersion;
111190688Sweongyo	uint32_t			targetRevision;
112190688Sweongyo	uint32_t			macVersion;
113190688Sweongyo	uint32_t			macRevision;
114190688Sweongyo	uint32_t			phyRevision;
115190688Sweongyo	uint32_t			analog5GhzRevision;
116190688Sweongyo	uint32_t			analog2GhzRevision;
117190688Sweongyo	uint32_t			regDomain;
118190688Sweongyo	uint32_t			regCapBits;
119190688Sweongyo	uint32_t			countryCode;
120190688Sweongyo	uint32_t			keyCacheSize;
121190688Sweongyo	uint32_t			numTxQueues;
122190688Sweongyo	uint32_t			connectionIdMax;
123190688Sweongyo	uint32_t			wirelessModes;
124190688Sweongyo#define	UATH_WIRELESS_MODE_11A		0x01
125190688Sweongyo#define	UATH_WIRELESS_MODE_TURBO	0x02
126190688Sweongyo#define	UATH_WIRELESS_MODE_11B		0x04
127190688Sweongyo#define	UATH_WIRELESS_MODE_11G		0x08
128190688Sweongyo#define	UATH_WIRELESS_MODE_108G		0x10
129190688Sweongyo	uint32_t			chanSpreadSupport;
130190688Sweongyo	uint32_t			compressSupport;
131190688Sweongyo	uint32_t			burstSupport;
132190688Sweongyo	uint32_t			fastFramesSupport;
133190688Sweongyo	uint32_t			chapTuningSupport;
134190688Sweongyo	uint32_t			turboGSupport;
135190688Sweongyo	uint32_t			turboPrimeSupport;
136190688Sweongyo	uint32_t			deviceType;
137190688Sweongyo	uint32_t			wmeSupport;
138190688Sweongyo	uint32_t			low2GhzChan;
139190688Sweongyo	uint32_t			high2GhzChan;
140190688Sweongyo	uint32_t			low5GhzChan;
141190688Sweongyo	uint32_t			high5GhzChan;
142190688Sweongyo	uint32_t			supportCipherWEP;
143190688Sweongyo	uint32_t			supportCipherAES_CCM;
144190688Sweongyo	uint32_t			supportCipherTKIP;
145190688Sweongyo	uint32_t			supportCipherMicAES_CCM;
146190688Sweongyo	uint32_t			supportMicTKIP;
147190688Sweongyo	uint32_t			twiceAntennaGain5G;
148190688Sweongyo	uint32_t			twiceAntennaGain2G;
149190688Sweongyo};
150190688Sweongyo
151190688Sweongyostruct uath_stat {
152190688Sweongyo	uint32_t			st_badchunkseqnum;
153190688Sweongyo	uint32_t			st_invalidlen;
154190688Sweongyo	uint32_t			st_multichunk;
155190688Sweongyo	uint32_t			st_toobigrxpkt;
156190688Sweongyo	uint32_t			st_stopinprogress;
157190688Sweongyo	uint32_t			st_crcerr;
158190688Sweongyo	uint32_t			st_phyerr;
159190688Sweongyo	uint32_t			st_decrypt_crcerr;
160190688Sweongyo	uint32_t			st_decrypt_micerr;
161190688Sweongyo	uint32_t			st_decomperr;
162190688Sweongyo	uint32_t			st_keyerr;
163190688Sweongyo	uint32_t			st_err;
164190688Sweongyo	/* CMD/RX/TX queues */
165190688Sweongyo	uint32_t			st_cmd_active;
166190688Sweongyo	uint32_t			st_cmd_inactive;
167190688Sweongyo	uint32_t			st_cmd_pending;
168190688Sweongyo	uint32_t			st_cmd_waiting;
169190688Sweongyo	uint32_t			st_rx_active;
170190688Sweongyo	uint32_t			st_rx_inactive;
171190688Sweongyo	uint32_t			st_tx_active;
172190688Sweongyo	uint32_t			st_tx_inactive;
173190688Sweongyo	uint32_t			st_tx_pending;
174190688Sweongyo};
175190688Sweongyo#define	UATH_STAT_INC(sc, var)		(sc)->sc_stat.var++
176190688Sweongyo#define	UATH_STAT_DEC(sc, var)		(sc)->sc_stat.var--
177190688Sweongyo
178190688Sweongyostruct uath_vap {
179190688Sweongyo	struct ieee80211vap		vap;
180190688Sweongyo	int				(*newstate)(struct ieee80211vap *,
181190688Sweongyo					    enum ieee80211_state, int);
182190688Sweongyo};
183190688Sweongyo#define	UATH_VAP(vap)			((struct uath_vap *)(vap))
184190688Sweongyo
185190688Sweongyostruct uath_softc {
186287197Sglebius	struct ieee80211com		sc_ic;
187287197Sglebius	struct mbufq			sc_snd;
188190688Sweongyo	device_t			sc_dev;
189192984Sthompsa	struct usb_device		*sc_udev;
190244503Shselasky	void				*sc_cmd_dma_buf;
191244503Shselasky	void				*sc_tx_dma_buf;
192190688Sweongyo	struct mtx			sc_mtx;
193190688Sweongyo	uint32_t			sc_debug;
194190688Sweongyo
195190688Sweongyo	struct uath_stat		sc_stat;
196190688Sweongyo	int				(*sc_newstate)(struct ieee80211com *,
197190688Sweongyo					    enum ieee80211_state, int);
198190688Sweongyo
199192984Sthompsa	struct usb_xfer		*sc_xfer[UATH_N_XFERS];
200190688Sweongyo	struct uath_cmd			sc_cmd[UATH_CMD_LIST_COUNT];
201190688Sweongyo	uath_cmdhead			sc_cmd_active;
202190688Sweongyo	uath_cmdhead			sc_cmd_inactive;
203190688Sweongyo	uath_cmdhead			sc_cmd_pending;
204190688Sweongyo	uath_cmdhead			sc_cmd_waiting;
205190688Sweongyo	struct uath_data		sc_rx[UATH_RX_DATA_LIST_COUNT];
206190688Sweongyo	uath_datahead			sc_rx_active;
207190688Sweongyo	uath_datahead			sc_rx_inactive;
208190688Sweongyo	struct uath_data		sc_tx[UATH_TX_DATA_LIST_COUNT];
209190688Sweongyo	uath_datahead			sc_tx_active;
210190688Sweongyo	uath_datahead			sc_tx_inactive;
211190688Sweongyo	uath_datahead			sc_tx_pending;
212190688Sweongyo
213190688Sweongyo	uint32_t			sc_msgid;
214190688Sweongyo	uint32_t			sc_seqnum;
215190688Sweongyo	int				sc_tx_timer;
216190688Sweongyo	struct callout			watchdog_ch;
217190688Sweongyo	struct callout			stat_ch;
218190688Sweongyo	/* multi-chunked support  */
219190688Sweongyo	struct mbuf			*sc_intrx_head;
220190688Sweongyo	struct mbuf			*sc_intrx_tail;
221190688Sweongyo	uint8_t				sc_intrx_nextnum;
222190688Sweongyo	uint32_t			sc_intrx_len;
223190688Sweongyo#define	UATH_MAX_INTRX_SIZE		3616
224190688Sweongyo
225190688Sweongyo	struct uath_devcap		sc_devcap;
226190688Sweongyo	uint8_t				sc_serial[16];
227190688Sweongyo
228190688Sweongyo	/* unsorted  */
229190688Sweongyo	uint32_t			sc_flags;
230190688Sweongyo#define	UATH_FLAG_INVALID		(1 << 1)
231190688Sweongyo#define	UATH_FLAG_INITDONE		(1 << 2)
232190688Sweongyo
233190688Sweongyo	struct	uath_rx_radiotap_header	sc_rxtap;
234190688Sweongyo	struct	uath_tx_radiotap_header	sc_txtap;
235190688Sweongyo};
236190688Sweongyo
237190688Sweongyo#define	UATH_LOCK(sc)			mtx_lock(&(sc)->sc_mtx)
238190688Sweongyo#define	UATH_UNLOCK(sc)			mtx_unlock(&(sc)->sc_mtx)
239190688Sweongyo#define	UATH_ASSERT_LOCKED(sc)		mtx_assert(&(sc)->sc_mtx, MA_OWNED)
240190688Sweongyo
241190688Sweongyo#define	UATH_RESET_INTRX(sc) do {		\
242190688Sweongyo	(sc)->sc_intrx_head = NULL;		\
243190688Sweongyo	(sc)->sc_intrx_tail = NULL;		\
244190688Sweongyo	(sc)->sc_intrx_nextnum = 0;		\
245190688Sweongyo	(sc)->sc_intrx_len = 0;			\
246190688Sweongyo} while (0)
247