if_runvar.h revision 205042
1203134Sthompsa/*	$OpenBSD: if_runvar.h,v 1.3 2009/03/26 20:17:27 damien Exp $	*/
2203134Sthompsa
3203134Sthompsa/*-
4203134Sthompsa * Copyright (c) 2008,2009 Damien Bergamini <damien.bergamini@free.fr>
5205042Sthompsa * ported to FreeBSD by Akinori Furukoshi <moonlightakkiy@yahoo.ca>
6205042Sthompsa * USB Consulting, Hans Petter Selasky <hselasky@freebsd.org>
7203134Sthompsa *
8203134Sthompsa * Permission to use, copy, modify, and distribute this software for any
9203134Sthompsa * purpose with or without fee is hereby granted, provided that the above
10203134Sthompsa * copyright notice and this permission notice appear in all copies.
11203134Sthompsa *
12203134Sthompsa * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13203134Sthompsa * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14203134Sthompsa * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15203134Sthompsa * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16203134Sthompsa * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17203134Sthompsa * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18203134Sthompsa * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19203134Sthompsa *
20203134Sthompsa * $FreeBSD: head/sys/dev/usb/wlan/if_runvar.h 205042 2010-03-11 22:05:12Z thompsa $
21203134Sthompsa */
22203134Sthompsa
23203134Sthompsa#ifndef _IF_RUNVAR_H_
24203134Sthompsa#define	_IF_RUNVAR_H_
25203134Sthompsa
26203134Sthompsa#define RUN_MAX_RXSZ			\
27203134Sthompsa	MIN(4096, MJUMPAGESIZE)
28203134Sthompsa#if 0
29203134Sthompsa	(sizeof (uint32_t) +		\
30203134Sthompsa	 sizeof (struct rt2860_rxwi) +	\
31203134Sthompsa	 sizeof (uint16_t) +		\
32203134Sthompsa	 MCLBYTES +			\
33203134Sthompsa	 sizeof (struct rt2870_rxd))
34203134Sthompsa#endif
35203134Sthompsa/* NB: "11" is the maximum number of padding bytes needed for Tx */
36203134Sthompsa#define RUN_MAX_TXSZ			\
37203134Sthompsa	(sizeof (struct rt2870_txd) +	\
38203134Sthompsa	 sizeof (struct rt2860_rxwi) +	\
39203134Sthompsa	 MCLBYTES + 11)
40203134Sthompsa
41203134Sthompsa#define RUN_TX_TIMEOUT	5000	/* ms */
42203134Sthompsa
43203134Sthompsa/* Tx ring count was 8/endpoint, now 32 for all 4 (or 6) endpoints. */
44203134Sthompsa#define RUN_TX_RING_COUNT	32
45203134Sthompsa#define RUN_RX_RING_COUNT	1
46203134Sthompsa
47203134Sthompsa#define RT2870_WCID_MAX		253
48203134Sthompsa#define RUN_AID2WCID(aid)	((aid) & 0xff)
49203134Sthompsa
50203134Sthompsastruct run_rx_radiotap_header {
51203134Sthompsa	struct ieee80211_radiotap_header wr_ihdr;
52203134Sthompsa	uint8_t		wr_flags;
53203134Sthompsa	uint8_t		wr_rate;
54203134Sthompsa	uint16_t	wr_chan_freq;
55203134Sthompsa	uint16_t	wr_chan_flags;
56203134Sthompsa	uint8_t		wr_dbm_antsignal;
57203134Sthompsa	uint8_t		wr_antenna;
58203134Sthompsa	uint8_t		wr_antsignal;
59203134Sthompsa} __packed;
60203134Sthompsa
61203134Sthompsa#define RUN_RX_RADIOTAP_PRESENT				\
62203134Sthompsa	(1 << IEEE80211_RADIOTAP_FLAGS |		\
63203134Sthompsa	 1 << IEEE80211_RADIOTAP_RATE |			\
64203134Sthompsa	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
65203134Sthompsa	 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL |	\
66203134Sthompsa	 1 << IEEE80211_RADIOTAP_ANTENNA |		\
67203134Sthompsa	 1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL)
68203134Sthompsa
69203134Sthompsastruct run_tx_radiotap_header {
70203134Sthompsa	struct ieee80211_radiotap_header wt_ihdr;
71203134Sthompsa	uint8_t		wt_flags;
72203134Sthompsa	uint8_t		wt_rate;
73203134Sthompsa	uint16_t	wt_chan_freq;
74203134Sthompsa	uint16_t	wt_chan_flags;
75203134Sthompsa	uint8_t		wt_hwqueue;
76203134Sthompsa} __packed;
77203134Sthompsa
78203134Sthompsa#define IEEE80211_RADIOTAP_HWQUEUE 15
79203134Sthompsa
80203134Sthompsa#define RUN_TX_RADIOTAP_PRESENT				\
81203134Sthompsa	(1 << IEEE80211_RADIOTAP_FLAGS |		\
82203134Sthompsa	 1 << IEEE80211_RADIOTAP_RATE |			\
83203134Sthompsa	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
84203134Sthompsa	 1 << IEEE80211_RADIOTAP_HWQUEUE)
85203134Sthompsa
86203134Sthompsastruct run_softc;
87203134Sthompsa
88203134Sthompsastruct run_tx_data {
89203134Sthompsa	STAILQ_ENTRY(run_tx_data)	next;
90203134Sthompsa	struct run_softc	*sc;
91203134Sthompsa	struct mbuf		*m;
92203134Sthompsa	struct ieee80211_node	*ni;
93203134Sthompsa	uint32_t align[0];	/* dummy field */
94203134Sthompsa	uint8_t	desc[sizeof(struct rt2870_txd) +
95203134Sthompsa		     sizeof(struct rt2860_txwi)];
96203134Sthompsa	int			ridx;
97203134Sthompsa	uint8_t			mcs;
98203134Sthompsa};
99203134SthompsaSTAILQ_HEAD(run_tx_data_head, run_tx_data);
100203134Sthompsa
101203134Sthompsastruct run_node {
102203134Sthompsa	struct ieee80211_node	ni;
103203134Sthompsa	uint8_t			ridx[IEEE80211_RATE_MAXSIZE];
104203134Sthompsa	uint8_t			ctl_ridx[IEEE80211_RATE_MAXSIZE];
105203134Sthompsa};
106203134Sthompsa
107203134Sthompsastruct run_vap {
108203134Sthompsa	struct ieee80211vap             vap;
109203134Sthompsa	struct ieee80211_beacon_offsets bo;
110203134Sthompsa	struct ieee80211_amrr           amrr;
111203134Sthompsa	struct ieee80211_amrr_node	amn[RT2870_WCID_MAX + 1];
112203134Sthompsa	struct usb_callout              amrr_ch;
113203134Sthompsa	struct task                     amrr_task;
114203134Sthompsa	uint8_t				amrr_run;
115203134Sthompsa#define RUN_AMRR_ON	1
116203134Sthompsa#define RUN_AMRR_OFF	0
117203134Sthompsa
118203134Sthompsa	int                             (*newstate)(struct ieee80211vap *,
119203134Sthompsa                                            enum ieee80211_state, int);
120203134Sthompsa};
121203134Sthompsa#define RUN_VAP(vap)    ((struct run_vap *)(vap))
122203134Sthompsa
123203134Sthompsa/*
124203134Sthompsa * There are 7 bulk endpoints: 1 for RX
125203134Sthompsa * and 6 for TX (4 EDCAs + HCCA + Prio).
126203134Sthompsa * Update 03-14-2009:  some devices like the Planex GW-US300MiniS
127203134Sthompsa * seem to have only 4 TX bulk endpoints (Fukaumi Naoki).
128203134Sthompsa */
129203134Sthompsaenum {
130203134Sthompsa	RUN_BULK_TX_BE,		/* = WME_AC_BE */
131203134Sthompsa	RUN_BULK_TX_BK,		/* = WME_AC_BK */
132203134Sthompsa	RUN_BULK_TX_VI,		/* = WME_AC_VI */
133203134Sthompsa	RUN_BULK_TX_VO,		/* = WME_AC_VO */
134203134Sthompsa	RUN_BULK_TX_HCCA,
135203134Sthompsa	RUN_BULK_TX_PRIO,
136203134Sthompsa	RUN_BULK_RX,
137203134Sthompsa	RUN_N_XFER,
138203134Sthompsa};
139203134Sthompsa
140203134Sthompsa#define	RUN_EP_QUEUES	RUN_BULK_RX
141203134Sthompsa
142203134Sthompsastruct run_endpoint_queue {
143203134Sthompsa	struct run_tx_data		tx_data[RUN_TX_RING_COUNT];
144203134Sthompsa	struct run_tx_data_head		tx_qh;
145203134Sthompsa	struct run_tx_data_head		tx_fh;
146203134Sthompsa	uint32_t			tx_nfree;
147203134Sthompsa};
148203134Sthompsa
149203134Sthompsastruct run_softc {
150203134Sthompsa	device_t			sc_dev;
151203134Sthompsa	struct usb_device		*sc_udev;
152203134Sthompsa	struct ifnet			*sc_ifp;
153203134Sthompsa	struct run_vap			*sc_rvp;
154203134Sthompsa
155203134Sthompsa	int				(*sc_srom_read)(struct run_softc *,
156203134Sthompsa					    uint16_t, uint16_t *);
157203134Sthompsa
158205042Sthompsa	uint16_t			mac_ver;
159205042Sthompsa	uint16_t			mac_rev;
160203134Sthompsa	uint8_t				rf_rev;
161203134Sthompsa	uint8_t				freq;
162203134Sthompsa	uint8_t				ntxchains;
163203134Sthompsa	uint8_t				nrxchains;
164203134Sthompsa	int				fixed_ridx;
165203134Sthompsa
166205042Sthompsa	uint8_t				bbp25;
167205042Sthompsa	uint8_t				bbp26;
168203134Sthompsa	uint8_t				rf24_20mhz;
169203134Sthompsa	uint8_t				rf24_40mhz;
170205042Sthompsa	uint8_t				patch_dac;
171205042Sthompsa	uint8_t				rfswitch;
172203134Sthompsa	uint8_t				ext_2ghz_lna;
173203134Sthompsa	uint8_t				ext_5ghz_lna;
174203134Sthompsa	uint8_t				calib_2ghz;
175203134Sthompsa	uint8_t				calib_5ghz;
176205042Sthompsa	uint8_t				txmixgain_2ghz;
177205042Sthompsa	uint8_t				txmixgain_5ghz;
178205042Sthompsa	int8_t				txpow1[54];
179205042Sthompsa	int8_t				txpow2[54];
180203134Sthompsa	int8_t				rssi_2ghz[3];
181203134Sthompsa	int8_t				rssi_5ghz[3];
182203134Sthompsa	uint8_t				lna[4];
183203134Sthompsa
184203134Sthompsa	struct {
185203134Sthompsa		uint8_t	reg;
186203134Sthompsa		uint8_t	val;
187205042Sthompsa	}				bbp[8], rf[10];
188203134Sthompsa	uint8_t				leds;
189203134Sthompsa	uint16_t			led[3];
190203134Sthompsa	uint32_t			txpow20mhz[5];
191203134Sthompsa	uint32_t			txpow40mhz_2ghz[5];
192203134Sthompsa	uint32_t			txpow40mhz_5ghz[5];
193203134Sthompsa
194203134Sthompsa	uint8_t				sc_bssid[6];
195203134Sthompsa
196203134Sthompsa	struct mtx			sc_mtx;
197203134Sthompsa
198203134Sthompsa	struct run_endpoint_queue	sc_epq[RUN_EP_QUEUES];
199203134Sthompsa
200203134Sthompsa	struct task			wme_task;
201203134Sthompsa	struct task			usb_timeout_task;
202203134Sthompsa
203203134Sthompsa	struct usb_xfer			*sc_xfer[RUN_N_XFER];
204203134Sthompsa
205203134Sthompsa	struct mbuf			*rx_m;
206203134Sthompsa
207203134Sthompsa	union {
208203134Sthompsa		struct run_rx_radiotap_header th;
209203134Sthompsa		uint8_t	pad[64];
210203134Sthompsa	}				sc_rxtapu;
211203134Sthompsa#define sc_rxtap	sc_rxtapu.th
212203134Sthompsa	int				sc_rxtap_len;
213203134Sthompsa
214203134Sthompsa	union {
215203134Sthompsa		struct run_tx_radiotap_header th;
216203134Sthompsa		uint8_t	pad[64];
217203134Sthompsa	}				sc_txtapu;
218203134Sthompsa#define sc_txtap	sc_txtapu.th
219203134Sthompsa	int				sc_txtap_len;
220203134Sthompsa};
221203134Sthompsa
222203134Sthompsa#define RUN_LOCK(sc)		mtx_lock(&(sc)->sc_mtx)
223203134Sthompsa#define RUN_UNLOCK(sc)		mtx_unlock(&(sc)->sc_mtx)
224203134Sthompsa#define RUN_LOCK_ASSERT(sc, t)	mtx_assert(&(sc)->sc_mtx, t)
225203134Sthompsa
226203134Sthompsa#endif	/* _IF_RUNVAR_H_ */
227