if_runvar.h revision 205042
1231200Smm/*	$OpenBSD: if_runvar.h,v 1.3 2009/03/26 20:17:27 damien Exp $	*/
2231200Smm
3231200Smm/*-
4231200Smm * Copyright (c) 2008,2009 Damien Bergamini <damien.bergamini@free.fr>
5231200Smm * ported to FreeBSD by Akinori Furukoshi <moonlightakkiy@yahoo.ca>
6231200Smm * USB Consulting, Hans Petter Selasky <hselasky@freebsd.org>
7231200Smm *
8231200Smm * Permission to use, copy, modify, and distribute this software for any
9231200Smm * purpose with or without fee is hereby granted, provided that the above
10231200Smm * copyright notice and this permission notice appear in all copies.
11231200Smm *
12231200Smm * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13231200Smm * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14231200Smm * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15231200Smm * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16231200Smm * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17231200Smm * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18231200Smm * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19231200Smm *
20231200Smm * $FreeBSD: head/sys/dev/usb/wlan/if_runvar.h 205042 2010-03-11 22:05:12Z thompsa $
21231200Smm */
22231200Smm
23231200Smm#ifndef _IF_RUNVAR_H_
24231200Smm#define	_IF_RUNVAR_H_
25231200Smm
26231200Smm#define RUN_MAX_RXSZ			\
27238856Smm	MIN(4096, MJUMPAGESIZE)
28231200Smm#if 0
29231200Smm	(sizeof (uint32_t) +		\
30231200Smm	 sizeof (struct rt2860_rxwi) +	\
31231200Smm	 sizeof (uint16_t) +		\
32231200Smm	 MCLBYTES +			\
33231200Smm	 sizeof (struct rt2870_rxd))
34238856Smm#endif
35238856Smm/* NB: "11" is the maximum number of padding bytes needed for Tx */
36231200Smm#define RUN_MAX_TXSZ			\
37231200Smm	(sizeof (struct rt2870_txd) +	\
38231200Smm	 sizeof (struct rt2860_rxwi) +	\
39231200Smm	 MCLBYTES + 11)
40231200Smm
41231200Smm#define RUN_TX_TIMEOUT	5000	/* ms */
42231200Smm
43231200Smm/* Tx ring count was 8/endpoint, now 32 for all 4 (or 6) endpoints. */
44231200Smm#define RUN_TX_RING_COUNT	32
45231200Smm#define RUN_RX_RING_COUNT	1
46231200Smm
47231200Smm#define RT2870_WCID_MAX		253
48231200Smm#define RUN_AID2WCID(aid)	((aid) & 0xff)
49231200Smm
50231200Smmstruct run_rx_radiotap_header {
51231200Smm	struct ieee80211_radiotap_header wr_ihdr;
52231200Smm	uint8_t		wr_flags;
53231200Smm	uint8_t		wr_rate;
54231200Smm	uint16_t	wr_chan_freq;
55231200Smm	uint16_t	wr_chan_flags;
56231200Smm	uint8_t		wr_dbm_antsignal;
57231200Smm	uint8_t		wr_antenna;
58231200Smm	uint8_t		wr_antsignal;
59231200Smm} __packed;
60231200Smm
61231200Smm#define RUN_RX_RADIOTAP_PRESENT				\
62231200Smm	(1 << IEEE80211_RADIOTAP_FLAGS |		\
63231200Smm	 1 << IEEE80211_RADIOTAP_RATE |			\
64231200Smm	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
65231200Smm	 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL |	\
66231200Smm	 1 << IEEE80211_RADIOTAP_ANTENNA |		\
67231200Smm	 1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL)
68231200Smm
69231200Smmstruct run_tx_radiotap_header {
70231200Smm	struct ieee80211_radiotap_header wt_ihdr;
71231200Smm	uint8_t		wt_flags;
72231200Smm	uint8_t		wt_rate;
73231200Smm	uint16_t	wt_chan_freq;
74231200Smm	uint16_t	wt_chan_flags;
75231200Smm	uint8_t		wt_hwqueue;
76231200Smm} __packed;
77231200Smm
78231200Smm#define IEEE80211_RADIOTAP_HWQUEUE 15
79231200Smm
80231200Smm#define RUN_TX_RADIOTAP_PRESENT				\
81231200Smm	(1 << IEEE80211_RADIOTAP_FLAGS |		\
82231200Smm	 1 << IEEE80211_RADIOTAP_RATE |			\
83231200Smm	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
84231200Smm	 1 << IEEE80211_RADIOTAP_HWQUEUE)
85231200Smm
86231200Smmstruct run_softc;
87231200Smm
88231200Smmstruct run_tx_data {
89231200Smm	STAILQ_ENTRY(run_tx_data)	next;
90353377Smm	struct run_softc	*sc;
91231200Smm	struct mbuf		*m;
92	struct ieee80211_node	*ni;
93	uint32_t align[0];	/* dummy field */
94	uint8_t	desc[sizeof(struct rt2870_txd) +
95		     sizeof(struct rt2860_txwi)];
96	int			ridx;
97	uint8_t			mcs;
98};
99STAILQ_HEAD(run_tx_data_head, run_tx_data);
100
101struct run_node {
102	struct ieee80211_node	ni;
103	uint8_t			ridx[IEEE80211_RATE_MAXSIZE];
104	uint8_t			ctl_ridx[IEEE80211_RATE_MAXSIZE];
105};
106
107struct run_vap {
108	struct ieee80211vap             vap;
109	struct ieee80211_beacon_offsets bo;
110	struct ieee80211_amrr           amrr;
111	struct ieee80211_amrr_node	amn[RT2870_WCID_MAX + 1];
112	struct usb_callout              amrr_ch;
113	struct task                     amrr_task;
114	uint8_t				amrr_run;
115#define RUN_AMRR_ON	1
116#define RUN_AMRR_OFF	0
117
118	int                             (*newstate)(struct ieee80211vap *,
119                                            enum ieee80211_state, int);
120};
121#define RUN_VAP(vap)    ((struct run_vap *)(vap))
122
123/*
124 * There are 7 bulk endpoints: 1 for RX
125 * and 6 for TX (4 EDCAs + HCCA + Prio).
126 * Update 03-14-2009:  some devices like the Planex GW-US300MiniS
127 * seem to have only 4 TX bulk endpoints (Fukaumi Naoki).
128 */
129enum {
130	RUN_BULK_TX_BE,		/* = WME_AC_BE */
131	RUN_BULK_TX_BK,		/* = WME_AC_BK */
132	RUN_BULK_TX_VI,		/* = WME_AC_VI */
133	RUN_BULK_TX_VO,		/* = WME_AC_VO */
134	RUN_BULK_TX_HCCA,
135	RUN_BULK_TX_PRIO,
136	RUN_BULK_RX,
137	RUN_N_XFER,
138};
139
140#define	RUN_EP_QUEUES	RUN_BULK_RX
141
142struct run_endpoint_queue {
143	struct run_tx_data		tx_data[RUN_TX_RING_COUNT];
144	struct run_tx_data_head		tx_qh;
145	struct run_tx_data_head		tx_fh;
146	uint32_t			tx_nfree;
147};
148
149struct run_softc {
150	device_t			sc_dev;
151	struct usb_device		*sc_udev;
152	struct ifnet			*sc_ifp;
153	struct run_vap			*sc_rvp;
154
155	int				(*sc_srom_read)(struct run_softc *,
156					    uint16_t, uint16_t *);
157
158	uint16_t			mac_ver;
159	uint16_t			mac_rev;
160	uint8_t				rf_rev;
161	uint8_t				freq;
162	uint8_t				ntxchains;
163	uint8_t				nrxchains;
164	int				fixed_ridx;
165
166	uint8_t				bbp25;
167	uint8_t				bbp26;
168	uint8_t				rf24_20mhz;
169	uint8_t				rf24_40mhz;
170	uint8_t				patch_dac;
171	uint8_t				rfswitch;
172	uint8_t				ext_2ghz_lna;
173	uint8_t				ext_5ghz_lna;
174	uint8_t				calib_2ghz;
175	uint8_t				calib_5ghz;
176	uint8_t				txmixgain_2ghz;
177	uint8_t				txmixgain_5ghz;
178	int8_t				txpow1[54];
179	int8_t				txpow2[54];
180	int8_t				rssi_2ghz[3];
181	int8_t				rssi_5ghz[3];
182	uint8_t				lna[4];
183
184	struct {
185		uint8_t	reg;
186		uint8_t	val;
187	}				bbp[8], rf[10];
188	uint8_t				leds;
189	uint16_t			led[3];
190	uint32_t			txpow20mhz[5];
191	uint32_t			txpow40mhz_2ghz[5];
192	uint32_t			txpow40mhz_5ghz[5];
193
194	uint8_t				sc_bssid[6];
195
196	struct mtx			sc_mtx;
197
198	struct run_endpoint_queue	sc_epq[RUN_EP_QUEUES];
199
200	struct task			wme_task;
201	struct task			usb_timeout_task;
202
203	struct usb_xfer			*sc_xfer[RUN_N_XFER];
204
205	struct mbuf			*rx_m;
206
207	union {
208		struct run_rx_radiotap_header th;
209		uint8_t	pad[64];
210	}				sc_rxtapu;
211#define sc_rxtap	sc_rxtapu.th
212	int				sc_rxtap_len;
213
214	union {
215		struct run_tx_radiotap_header th;
216		uint8_t	pad[64];
217	}				sc_txtapu;
218#define sc_txtap	sc_txtapu.th
219	int				sc_txtap_len;
220};
221
222#define RUN_LOCK(sc)		mtx_lock(&(sc)->sc_mtx)
223#define RUN_UNLOCK(sc)		mtx_unlock(&(sc)->sc_mtx)
224#define RUN_LOCK_ASSERT(sc, t)	mtx_assert(&(sc)->sc_mtx, t)
225
226#endif	/* _IF_RUNVAR_H_ */
227