xref: /freebsd/sys/dev/usb/wlan/if_runvar.h (revision 70ed590b393173d4ea697be2a27054ed171f0c1a)
1 /*	$OpenBSD: if_runvar.h,v 1.3 2009/03/26 20:17:27 damien Exp $	*/
2 
3 /*-
4  * Copyright (c) 2008,2009 Damien Bergamini <damien.bergamini@free.fr>
5  * ported to FreeBSD by Akinori Furukoshi <moonlightakkiy@yahoo.ca>
6  * USB Consulting, Hans Petter Selasky <hselasky@freebsd.org>
7  *
8  * Permission to use, copy, modify, and distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  *
20  * $FreeBSD$
21  */
22 
23 #ifndef _IF_RUNVAR_H_
24 #define	_IF_RUNVAR_H_
25 
26 #define RUN_MAX_RXSZ			\
27 	MIN(4096, MJUMPAGESIZE)
28 #if 0
29 	(sizeof (uint32_t) +		\
30 	 sizeof (struct rt2860_rxwi) +	\
31 	 sizeof (uint16_t) +		\
32 	 MCLBYTES +			\
33 	 sizeof (struct rt2870_rxd))
34 #endif
35 /* NB: "11" is the maximum number of padding bytes needed for Tx */
36 #define RUN_MAX_TXSZ			\
37 	(sizeof (struct rt2870_txd) +	\
38 	 sizeof (struct rt2860_rxwi) +	\
39 	 MCLBYTES + 11)
40 
41 #define RUN_TX_TIMEOUT	5000	/* ms */
42 
43 /* Tx ring count was 8/endpoint, now 32 for all 4 (or 6) endpoints. */
44 #define RUN_TX_RING_COUNT	32
45 #define RUN_RX_RING_COUNT	1
46 
47 #define RT2870_WCID_MAX		253
48 #define RUN_AID2WCID(aid)	((aid) & 0xff)
49 
50 struct run_rx_radiotap_header {
51 	struct ieee80211_radiotap_header wr_ihdr;
52 	uint8_t		wr_flags;
53 	uint8_t		wr_rate;
54 	uint16_t	wr_chan_freq;
55 	uint16_t	wr_chan_flags;
56 	uint8_t		wr_dbm_antsignal;
57 	uint8_t		wr_antenna;
58 	uint8_t		wr_antsignal;
59 } __packed;
60 
61 #define RUN_RX_RADIOTAP_PRESENT				\
62 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
63 	 1 << IEEE80211_RADIOTAP_RATE |			\
64 	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
65 	 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL |	\
66 	 1 << IEEE80211_RADIOTAP_ANTENNA |		\
67 	 1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL)
68 
69 struct run_tx_radiotap_header {
70 	struct ieee80211_radiotap_header wt_ihdr;
71 	uint8_t		wt_flags;
72 	uint8_t		wt_rate;
73 	uint16_t	wt_chan_freq;
74 	uint16_t	wt_chan_flags;
75 	uint8_t		wt_hwqueue;
76 } __packed;
77 
78 #define IEEE80211_RADIOTAP_HWQUEUE 15
79 
80 #define RUN_TX_RADIOTAP_PRESENT				\
81 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
82 	 1 << IEEE80211_RADIOTAP_RATE |			\
83 	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
84 	 1 << IEEE80211_RADIOTAP_HWQUEUE)
85 
86 struct run_softc;
87 
88 struct run_tx_data {
89 	STAILQ_ENTRY(run_tx_data)	next;
90 	struct run_softc	*sc;
91 	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 };
99 STAILQ_HEAD(run_tx_data_head, run_tx_data);
100 
101 struct run_node {
102 	struct ieee80211_node	ni;
103 	uint8_t			ridx[IEEE80211_RATE_MAXSIZE];
104 	uint8_t			ctl_ridx[IEEE80211_RATE_MAXSIZE];
105 };
106 
107 struct run_vap {
108 	struct ieee80211vap             vap;
109 	struct ieee80211_beacon_offsets bo;
110 	struct usb_callout              ratectl_ch;
111 	struct task                     ratectl_task;
112 	uint8_t				ratectl_run;
113 #define RUN_RATECTL_ON	1
114 #define RUN_RATECTL_OFF	0
115 
116 	int                             (*newstate)(struct ieee80211vap *,
117                                             enum ieee80211_state, int);
118 };
119 #define RUN_VAP(vap)    ((struct run_vap *)(vap))
120 
121 /*
122  * There are 7 bulk endpoints: 1 for RX
123  * and 6 for TX (4 EDCAs + HCCA + Prio).
124  * Update 03-14-2009:  some devices like the Planex GW-US300MiniS
125  * seem to have only 4 TX bulk endpoints (Fukaumi Naoki).
126  */
127 enum {
128 	RUN_BULK_TX_BE,		/* = WME_AC_BE */
129 	RUN_BULK_TX_BK,		/* = WME_AC_BK */
130 	RUN_BULK_TX_VI,		/* = WME_AC_VI */
131 	RUN_BULK_TX_VO,		/* = WME_AC_VO */
132 	RUN_BULK_TX_HCCA,
133 	RUN_BULK_TX_PRIO,
134 	RUN_BULK_RX,
135 	RUN_N_XFER,
136 };
137 
138 #define	RUN_EP_QUEUES	RUN_BULK_RX
139 
140 struct run_endpoint_queue {
141 	struct run_tx_data		tx_data[RUN_TX_RING_COUNT];
142 	struct run_tx_data_head		tx_qh;
143 	struct run_tx_data_head		tx_fh;
144 	uint32_t			tx_nfree;
145 };
146 
147 struct run_softc {
148 	device_t			sc_dev;
149 	struct usb_device		*sc_udev;
150 	struct ifnet			*sc_ifp;
151 	struct run_vap			*sc_rvp;
152 
153 	int				(*sc_srom_read)(struct run_softc *,
154 					    uint16_t, uint16_t *);
155 
156 	uint16_t			mac_ver;
157 	uint16_t			mac_rev;
158 	uint8_t				rf_rev;
159 	uint8_t				freq;
160 	uint8_t				ntxchains;
161 	uint8_t				nrxchains;
162 	int				fixed_ridx;
163 
164 	uint8_t				bbp25;
165 	uint8_t				bbp26;
166 	uint8_t				rf24_20mhz;
167 	uint8_t				rf24_40mhz;
168 	uint8_t				patch_dac;
169 	uint8_t				rfswitch;
170 	uint8_t				ext_2ghz_lna;
171 	uint8_t				ext_5ghz_lna;
172 	uint8_t				calib_2ghz;
173 	uint8_t				calib_5ghz;
174 	uint8_t				txmixgain_2ghz;
175 	uint8_t				txmixgain_5ghz;
176 	int8_t				txpow1[54];
177 	int8_t				txpow2[54];
178 	int8_t				rssi_2ghz[3];
179 	int8_t				rssi_5ghz[3];
180 	uint8_t				lna[4];
181 
182 	struct {
183 		uint8_t	reg;
184 		uint8_t	val;
185 	}				bbp[8], rf[10];
186 	uint8_t				leds;
187 	uint16_t			led[3];
188 	uint32_t			txpow20mhz[5];
189 	uint32_t			txpow40mhz_2ghz[5];
190 	uint32_t			txpow40mhz_5ghz[5];
191 
192 	uint8_t				sc_bssid[6];
193 
194 	struct mtx			sc_mtx;
195 
196 	struct run_endpoint_queue	sc_epq[RUN_EP_QUEUES];
197 
198 	struct task			wme_task;
199 	struct task			usb_timeout_task;
200 
201 	struct usb_xfer			*sc_xfer[RUN_N_XFER];
202 
203 	struct mbuf			*rx_m;
204 
205 	union {
206 		struct run_rx_radiotap_header th;
207 		uint8_t	pad[64];
208 	}				sc_rxtapu;
209 #define sc_rxtap	sc_rxtapu.th
210 	int				sc_rxtap_len;
211 
212 	union {
213 		struct run_tx_radiotap_header th;
214 		uint8_t	pad[64];
215 	}				sc_txtapu;
216 #define sc_txtap	sc_txtapu.th
217 	int				sc_txtap_len;
218 };
219 
220 #define RUN_LOCK(sc)		mtx_lock(&(sc)->sc_mtx)
221 #define RUN_UNLOCK(sc)		mtx_unlock(&(sc)->sc_mtx)
222 #define RUN_LOCK_ASSERT(sc, t)	mtx_assert(&(sc)->sc_mtx, t)
223 
224 #endif	/* _IF_RUNVAR_H_ */
225