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