xref: /dragonfly/sys/bus/u4b/wlan/if_runvar.h (revision 38b720cd)
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 296356 2016-03-03 20:06:16Z avos $
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 	uint64_t	wr_tsf;
49 	uint8_t		wr_flags;
50 	uint8_t		wr_rate;
51 	uint16_t	wr_chan_freq;
52 	uint16_t	wr_chan_flags;
53 	int8_t		wr_dbm_antsignal;
54 	uint8_t		wr_antenna;
55 	uint8_t		wr_antsignal;
56 } __packed __aligned(8);
57 
58 #define	RUN_RX_RADIOTAP_PRESENT				\
59 	(1 << IEEE80211_RADIOTAP_TSFT |			\
60 	 1 << IEEE80211_RADIOTAP_FLAGS |		\
61 	 1 << IEEE80211_RADIOTAP_RATE |			\
62 	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
63 	 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL |	\
64 	 1 << IEEE80211_RADIOTAP_ANTENNA |		\
65 	 1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL)
66 
67 struct run_tx_radiotap_header {
68 	struct ieee80211_radiotap_header wt_ihdr;
69 	uint64_t	wt_tsf;
70 	uint8_t		wt_flags;
71 	uint8_t		wt_rate;
72 	uint16_t	wt_chan_freq;
73 	uint16_t	wt_chan_flags;
74 	uint8_t		wt_hwqueue;
75 } __packed __aligned(8);
76 
77 #define IEEE80211_RADIOTAP_HWQUEUE 15
78 
79 #define	RUN_TX_RADIOTAP_PRESENT				\
80 	(1 << IEEE80211_RADIOTAP_TSFT |			\
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 	uint8_t			ridx;
97 };
98 STAILQ_HEAD(run_tx_data_head, run_tx_data);
99 
100 struct run_node {
101 	struct ieee80211_node	ni;
102 	uint8_t			ridx[IEEE80211_RATE_MAXSIZE];
103 	uint8_t			ctl_ridx[IEEE80211_RATE_MAXSIZE];
104 	uint8_t			amrr_ridx;
105 	uint8_t			mgt_ridx;
106 	uint8_t			fix_ridx;
107 };
108 #define RUN_NODE(ni)		((struct run_node *)(ni))
109 
110 struct run_cmdq {
111 	void			*arg0;
112 	void			*arg1;
113 	void			(*func)(void *);
114 	struct ieee80211_key	*k;
115 	struct ieee80211_key	key;
116 	uint8_t			mac[IEEE80211_ADDR_LEN];
117 	uint8_t			wcid;
118 };
119 
120 struct run_vap {
121 	struct ieee80211vap             vap;
122 	struct mbuf			*beacon_mbuf;
123 
124 	int                             (*newstate)(struct ieee80211vap *,
125                                             enum ieee80211_state, int);
126 	void				(*recv_mgmt)(struct ieee80211_node *,
127 					    struct mbuf *, int,
128 					    const struct ieee80211_rx_stats *,
129 					    int, int);
130 
131 	uint8_t				rvp_id;
132 };
133 #define	RUN_VAP(vap)	((struct run_vap *)(vap))
134 
135 /*
136  * There are 7 bulk endpoints: 1 for RX
137  * and 6 for TX (4 EDCAs + HCCA + Prio).
138  * Update 03-14-2009:  some devices like the Planex GW-US300MiniS
139  * seem to have only 4 TX bulk endpoints (Fukaumi Naoki).
140  */
141 enum {
142 	RUN_BULK_TX_BE,		/* = WME_AC_BE */
143 	RUN_BULK_TX_BK,		/* = WME_AC_BK */
144 	RUN_BULK_TX_VI,		/* = WME_AC_VI */
145 	RUN_BULK_TX_VO,		/* = WME_AC_VO */
146 	RUN_BULK_TX_HCCA,
147 	RUN_BULK_TX_PRIO,
148 	RUN_BULK_RX,
149 	RUN_N_XFER,
150 };
151 
152 #define	RUN_EP_QUEUES	RUN_BULK_RX
153 
154 struct run_endpoint_queue {
155 	struct run_tx_data		tx_data[RUN_TX_RING_COUNT];
156 	struct run_tx_data_head		tx_qh;
157 	struct run_tx_data_head		tx_fh;
158 	uint32_t			tx_nfree;
159 };
160 
161 struct run_softc {
162 	struct lock			sc_lock;
163 	struct ieee80211com		sc_ic;
164 	struct mbufq			sc_snd;
165 	device_t			sc_dev;
166 	struct usb_device		*sc_udev;
167 	int				sc_need_fwload;
168 
169 	int				sc_flags;
170 #define	RUN_FLAG_FWLOAD_NEEDED		0x01
171 #define	RUN_RUNNING			0x02
172 
173 	uint16_t			wcid_stats[RT2870_WCID_MAX + 1][3];
174 #define	RUN_TXCNT	0
175 #define	RUN_SUCCESS	1
176 #define	RUN_RETRY	2
177 
178 	int				(*sc_srom_read)(struct run_softc *,
179 					    uint16_t, uint16_t *);
180 
181 	uint16_t			mac_ver;
182 	uint16_t			mac_rev;
183 	uint16_t			rf_rev;
184 	uint8_t				freq;
185 	uint8_t				ntxchains;
186 	uint8_t				nrxchains;
187 
188 	uint8_t				bbp25;
189 	uint8_t				bbp26;
190 	uint8_t				rf24_20mhz;
191 	uint8_t				rf24_40mhz;
192 	uint8_t				patch_dac;
193 	uint8_t				rfswitch;
194 	uint8_t				ext_2ghz_lna;
195 	uint8_t				ext_5ghz_lna;
196 	uint8_t				calib_2ghz;
197 	uint8_t				calib_5ghz;
198 	uint8_t				txmixgain_2ghz;
199 	uint8_t				txmixgain_5ghz;
200 	int8_t				txpow1[54];
201 	int8_t				txpow2[54];
202 	int8_t				txpow3[54];
203 	int8_t				rssi_2ghz[3];
204 	int8_t				rssi_5ghz[3];
205 	uint8_t				lna[4];
206 
207 	struct {
208 		uint8_t	reg;
209 		uint8_t	val;
210 	}				bbp[10], rf[10];
211 	uint8_t				leds;
212 	uint16_t			led[3];
213 	uint32_t			txpow20mhz[5];
214 	uint32_t			txpow40mhz_2ghz[5];
215 	uint32_t			txpow40mhz_5ghz[5];
216 
217 	struct run_endpoint_queue	sc_epq[RUN_EP_QUEUES];
218 
219 	struct task                     ratectl_task;
220 	struct usb_callout              ratectl_ch;
221 	uint8_t				ratectl_run;
222 #define	RUN_RATECTL_OFF	0
223 
224 /* need to be power of 2, otherwise RUN_CMDQ_GET fails */
225 #define	RUN_CMDQ_MAX	16
226 #define	RUN_CMDQ_MASQ	(RUN_CMDQ_MAX - 1)
227 	struct run_cmdq			cmdq[RUN_CMDQ_MAX];
228 	struct task			cmdq_task;
229 	uint32_t			cmdq_store;
230 	uint8_t				cmdq_exec;
231 	uint8_t				cmdq_run;
232 	uint8_t				cmdq_key_set;
233 #define	RUN_CMDQ_ABORT	0
234 #define	RUN_CMDQ_GO	1
235 
236 	struct usb_xfer			*sc_xfer[RUN_N_XFER];
237 
238 	struct mbuf			*rx_m;
239 
240 	uint8_t				fifo_cnt;
241 
242 	uint8_t				running;
243 	uint8_t				runbmap;
244 	uint8_t				ap_running;
245 	uint8_t				adhoc_running;
246 	uint8_t				sta_running;
247 	uint8_t				rvp_cnt;
248 	uint8_t				rvp_bmap;
249 	uint8_t				sc_detached;
250 
251 	uint8_t				sc_bssid[IEEE80211_ADDR_LEN];
252 
253 	union {
254 		struct run_rx_radiotap_header th;
255 		uint8_t	pad[64];
256 	}				sc_rxtapu;
257 #define sc_rxtap	sc_rxtapu.th
258 
259 	union {
260 		struct run_tx_radiotap_header th;
261 		uint8_t	pad[64];
262 	}				sc_txtapu;
263 #define sc_txtap	sc_txtapu.th
264 };
265 
266 #define	RUN_LOCK(sc)		lockmgr(&(sc)->sc_lock, LK_EXCLUSIVE)
267 #define	RUN_UNLOCK(sc)		lockmgr(&(sc)->sc_lock, LK_RELEASE)
268 #define	RUN_LOCK_ASSERT(sc, t)	KKASSERT(lockstatus(&(sc)->sc_lock, curthread) != 0)
269 
270 #endif	/* _IF_RUNVAR_H_ */
271