xref: /dragonfly/sys/bus/u4b/wlan/if_runvar.h (revision cd1c6085)
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: head/sys/dev/usb/wlan/if_runvar.h 262465 2014-02-25 01:42:02Z kevlo $
21  */
22 
23 #ifndef _IF_RUNVAR_H_
24 #define	_IF_RUNVAR_H_
25 
26 #define	RUN_MAX_RXSZ			\
27 	MIN(4096, MJUMPAGESIZE)
28 
29 /* NB: "11" is the maximum number of padding bytes needed for Tx */
30 #define	RUN_MAX_TXSZ			\
31 	(sizeof (struct rt2870_txd) +	\
32 	 sizeof (struct rt2860_txwi) +	\
33 	 MCLBYTES + 11)
34 
35 #define	RUN_TX_TIMEOUT	5000	/* ms */
36 
37 /* Tx ring count was 8/endpoint, now 32 for all 4 (or 6) endpoints. */
38 #define	RUN_TX_RING_COUNT	32
39 #define	RUN_RX_RING_COUNT	1
40 
41 #define	RT2870_WCID_MAX		64
42 #define	RUN_AID2WCID(aid)	((aid) & 0xff)
43 
44 #define	RUN_VAP_MAX		8
45 
46 struct run_rx_radiotap_header {
47 	struct ieee80211_radiotap_header wr_ihdr;
48 	uint8_t		wr_flags;
49 	uint8_t		wr_rate;
50 	uint16_t	wr_chan_freq;
51 	uint16_t	wr_chan_flags;
52 	int8_t		wr_dbm_antsignal;
53 	uint8_t		wr_antenna;
54 	uint8_t		wr_antsignal;
55 } __packed __aligned(8);
56 
57 #define	RUN_RX_RADIOTAP_PRESENT				\
58 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
59 	 1 << IEEE80211_RADIOTAP_RATE |			\
60 	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
61 	 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL |	\
62 	 1 << IEEE80211_RADIOTAP_ANTENNA |		\
63 	 1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL)
64 
65 struct run_tx_radiotap_header {
66 	struct ieee80211_radiotap_header wt_ihdr;
67 	uint8_t		wt_flags;
68 	uint8_t		wt_rate;
69 	uint16_t	wt_chan_freq;
70 	uint16_t	wt_chan_flags;
71 	uint8_t		wt_hwqueue;
72 } __packed __aligned(8);
73 
74 #define IEEE80211_RADIOTAP_HWQUEUE 15
75 
76 #define	RUN_TX_RADIOTAP_PRESENT				\
77 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
78 	 1 << IEEE80211_RADIOTAP_RATE |			\
79 	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
80 	 1 << IEEE80211_RADIOTAP_HWQUEUE)
81 
82 struct run_softc;
83 
84 struct run_tx_data {
85 	STAILQ_ENTRY(run_tx_data)	next;
86 	struct run_softc	*sc;
87 	struct mbuf		*m;
88 	struct ieee80211_node	*ni;
89 	uint32_t align[0];	/* dummy field */
90 	uint8_t	desc[sizeof(struct rt2870_txd) +
91 		     sizeof(struct rt2860_txwi)];
92 	uint8_t			ridx;
93 };
94 STAILQ_HEAD(run_tx_data_head, run_tx_data);
95 
96 struct run_node {
97 	struct ieee80211_node	ni;
98 	uint8_t			ridx[IEEE80211_RATE_MAXSIZE];
99 	uint8_t			ctl_ridx[IEEE80211_RATE_MAXSIZE];
100 	uint8_t			amrr_ridx;
101 	uint8_t			mgt_ridx;
102 	uint8_t			fix_ridx;
103 };
104 
105 struct run_cmdq {
106 	void			*arg0;
107 	void			*arg1;
108 	void			(*func)(void *);
109 	struct ieee80211_key	*k;
110 	struct ieee80211_key	key;
111 	uint8_t			mac[IEEE80211_ADDR_LEN];
112 	uint8_t			wcid;
113 };
114 
115 struct run_vap {
116 	struct ieee80211vap             vap;
117 	struct ieee80211_beacon_offsets bo;
118 	struct mbuf			*beacon_mbuf;
119 
120 	int                             (*newstate)(struct ieee80211vap *,
121                                             enum ieee80211_state, int);
122 
123 	uint8_t				rvp_id;
124 };
125 #define	RUN_VAP(vap)	((struct run_vap *)(vap))
126 
127 /*
128  * There are 7 bulk endpoints: 1 for RX
129  * and 6 for TX (4 EDCAs + HCCA + Prio).
130  * Update 03-14-2009:  some devices like the Planex GW-US300MiniS
131  * seem to have only 4 TX bulk endpoints (Fukaumi Naoki).
132  */
133 enum {
134 	RUN_BULK_TX_BE,		/* = WME_AC_BE */
135 	RUN_BULK_TX_BK,		/* = WME_AC_BK */
136 	RUN_BULK_TX_VI,		/* = WME_AC_VI */
137 	RUN_BULK_TX_VO,		/* = WME_AC_VO */
138 	RUN_BULK_TX_HCCA,
139 	RUN_BULK_TX_PRIO,
140 	RUN_BULK_RX,
141 	RUN_N_XFER,
142 };
143 
144 #define	RUN_EP_QUEUES	RUN_BULK_RX
145 
146 struct run_endpoint_queue {
147 	struct run_tx_data		tx_data[RUN_TX_RING_COUNT];
148 	struct run_tx_data_head		tx_qh;
149 	struct run_tx_data_head		tx_fh;
150 	uint32_t			tx_nfree;
151 };
152 
153 struct run_softc {
154 	device_t			sc_dev;
155 	struct usb_device		*sc_udev;
156 	struct ifnet			*sc_ifp;
157 	int				sc_need_fwload;
158 
159 	int				sc_flags;
160 #define	RUN_FLAG_FWLOAD_NEEDED		0x01
161 
162 	uint16_t			wcid_stats[RT2870_WCID_MAX + 1][3];
163 #define	RUN_TXCNT	0
164 #define	RUN_SUCCESS	1
165 #define	RUN_RETRY	2
166 
167 	int				(*sc_srom_read)(struct run_softc *,
168 					    uint16_t, uint16_t *);
169 
170 	uint16_t			mac_ver;
171 	uint16_t			mac_rev;
172 	uint16_t			rf_rev;
173 	uint8_t				freq;
174 	uint8_t				ntxchains;
175 	uint8_t				nrxchains;
176 
177 	uint8_t				bbp25;
178 	uint8_t				bbp26;
179 	uint8_t				rf24_20mhz;
180 	uint8_t				rf24_40mhz;
181 	uint8_t				patch_dac;
182 	uint8_t				rfswitch;
183 	uint8_t				ext_2ghz_lna;
184 	uint8_t				ext_5ghz_lna;
185 	uint8_t				calib_2ghz;
186 	uint8_t				calib_5ghz;
187 	uint8_t				txmixgain_2ghz;
188 	uint8_t				txmixgain_5ghz;
189 	int8_t				txpow1[54];
190 	int8_t				txpow2[54];
191 	int8_t				txpow3[54];
192 	int8_t				rssi_2ghz[3];
193 	int8_t				rssi_5ghz[3];
194 	uint8_t				lna[4];
195 
196 	struct {
197 		uint8_t	reg;
198 		uint8_t	val;
199 	}				bbp[10], rf[10];
200 	uint8_t				leds;
201 	uint16_t			led[3];
202 	uint32_t			txpow20mhz[5];
203 	uint32_t			txpow40mhz_2ghz[5];
204 	uint32_t			txpow40mhz_5ghz[5];
205 
206 	uint8_t				sc_bssid[6];
207 
208 	struct lock			sc_lock;
209 
210 	struct run_endpoint_queue	sc_epq[RUN_EP_QUEUES];
211 
212 	struct task                     ratectl_task;
213 	struct usb_callout              ratectl_ch;
214 	uint8_t				ratectl_run;
215 #define	RUN_RATECTL_OFF	0
216 
217 /* need to be power of 2, otherwise RUN_CMDQ_GET fails */
218 #define	RUN_CMDQ_MAX	16
219 #define	RUN_CMDQ_MASQ	(RUN_CMDQ_MAX - 1)
220 	struct run_cmdq			cmdq[RUN_CMDQ_MAX];
221 	struct task			cmdq_task;
222 	uint32_t			cmdq_store;
223 	uint8_t				cmdq_exec;
224 	uint8_t				cmdq_run;
225 	uint8_t				cmdq_key_set;
226 #define	RUN_CMDQ_ABORT	0
227 #define	RUN_CMDQ_GO	1
228 
229 	struct usb_xfer			*sc_xfer[RUN_N_XFER];
230 
231 	struct mbuf			*rx_m;
232 
233 	uint8_t				fifo_cnt;
234 
235 	uint8_t				running;
236 	uint8_t				runbmap;
237 	uint8_t				ap_running;
238 	uint8_t				adhoc_running;
239 	uint8_t				sta_running;
240 	uint8_t				rvp_cnt;
241 	uint8_t				rvp_bmap;
242 	uint8_t				sc_detached;
243 
244 	union {
245 		struct run_rx_radiotap_header th;
246 		uint8_t	pad[64];
247 	}				sc_rxtapu;
248 #define sc_rxtap	sc_rxtapu.th
249 	int				sc_rxtap_len;
250 
251 	union {
252 		struct run_tx_radiotap_header th;
253 		uint8_t	pad[64];
254 	}				sc_txtapu;
255 #define sc_txtap	sc_txtapu.th
256 	int				sc_txtap_len;
257 };
258 
259 #define	RUN_LOCK(sc)		lockmgr(&(sc)->sc_lock, LK_EXCLUSIVE)
260 #define	RUN_UNLOCK(sc)		lockmgr(&(sc)->sc_lock, LK_RELEASE)
261 #define	RUN_LOCK_ASSERT(sc, t)	KKASSERT(lockstatus(&(sc)->sc_lock, curthread) != 0)
262 
263 #endif	/* _IF_RUNVAR_H_ */
264