xref: /freebsd/sys/dev/usb/wlan/if_mtwvar.h (revision b670c9bafc0e31c7609969bf374b2e80bdc00211)
1 /*	$OpenBSD: if_mtwvar.h,v 1.1 2021/12/20 13:59:02 hastings Exp $	*/
2 /*
3  * Copyright (c) 2008,2009 Damien Bergamini <damien.bergamini@free.fr>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #define MTW_MAX_RXSZ			\
19 	4096
20 #if 0
21 	(sizeof (uint32_t) +		\
22 	 sizeof (struct mtw_rxwi) +	\
23 	 sizeof (uint16_t) +		\
24 	 MCLBYTES +			\
25 	 sizeof (struct mtw_rxd))
26 #endif
27 
28 #define MTW_TX_TIMEOUT	5000	/* ms */
29 #define	MTW_VAP_MAX		8
30 #define MTW_RX_RING_COUNT	1
31 #define MTW_TX_RING_COUNT	32
32 
33 #define MTW_RXQ_COUNT		2
34 #define MTW_TXQ_COUNT		6
35 
36 #define MTW_WCID_MAX		64
37 #define MTW_AID2WCID(aid)	(1 + ((aid) & 0x7))
38 
39 struct mtw_rx_radiotap_header {
40 	struct ieee80211_radiotap_header wr_ihdr;
41         uint64_t	wr_tsf;
42         uint8_t		wr_flags;
43 	uint8_t		wr_rate;
44 	uint16_t	wr_chan_freq;
45 	uint16_t	wr_chan_flags;
46 	uint8_t		wr_dbm_antsignal;
47 	uint8_t		wr_antenna;
48 	uint8_t		wr_antsignal;
49 } __packed;
50 #define MTW_RATECTL_OFF 0
51 #define MTW_RX_RADIOTAP_PRESENT				\
52 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
53 	 1 << IEEE80211_RADIOTAP_RATE |			\
54 	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
55 	 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL |	\
56 	 1 << IEEE80211_RADIOTAP_ANTENNA |		\
57 	 1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL)
58 struct mtw_tx_radiotap_header {
59 	struct ieee80211_radiotap_header wt_ihdr;
60 	uint8_t		wt_flags;
61   uint8_t		wt_rate;
62 	uint16_t	wt_chan_freq;
63 	uint16_t	wt_chan_flags;
64   uint8_t		wt_hwqueue;
65 } __packed;
66 
67 #define MTW_TX_RADIOTAP_PRESENT				\
68 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
69 	 1 << IEEE80211_RADIOTAP_RATE |			\
70 	 1 << IEEE80211_RADIOTAP_CHANNEL)
71 
72 struct mtw_softc;
73 
74 struct mtw_fw_data {
75   	uint16_t	len;
76 	uint16_t	flags;
77 
78   uint8_t *buf;
79   uint32_t buflen;
80 
81 };
82 struct mtw_tx_desc {
83 	uint32_t	flags;
84 #define RT2573_TX_BURST			(1 << 0)
85 #define RT2573_TX_VALID			(1 << 1)
86 #define RT2573_TX_MORE_FRAG		(1 << 2)
87 #define RT2573_TX_NEED_ACK		(1 << 3)
88 #define RT2573_TX_TIMESTAMP		(1 << 4)
89 #define RT2573_TX_OFDM			(1 << 5)
90 #define RT2573_TX_IFS_SIFS		(1 << 6)
91 #define RT2573_TX_LONG_RETRY		(1 << 7)
92 #define RT2573_TX_TKIPMIC		(1 << 8)
93 #define RT2573_TX_KEY_PAIR		(1 << 9)
94 #define RT2573_TX_KEY_ID(id)		(((id) & 0x3f) << 10)
95 #define RT2573_TX_CIP_MODE(m)		((m) << 29)
96 
97 	uint16_t	wme;
98 #define RT2573_QID(v)		(v)
99 #define RT2573_AIFSN(v)		((v) << 4)
100 #define RT2573_LOGCWMIN(v)	((v) << 8)
101 #define RT2573_LOGCWMAX(v)	((v) << 12)
102 
103 	uint8_t		hdrlen;
104 	uint8_t		xflags;
105 #define RT2573_TX_HWSEQ		(1 << 4)
106 
107 	uint8_t		plcp_signal;
108 	uint8_t		plcp_service;
109 #define RT2573_PLCP_LENGEXT	0x80
110 
111 	uint8_t		plcp_length_lo;
112 	uint8_t		plcp_length_hi;
113 
114 	uint32_t	iv;
115 	uint32_t	eiv;
116 
117 	uint8_t		offset;
118 	uint8_t		qid;
119 	uint8_t		txpower;
120 #define RT2573_DEFAULT_TXPOWER	0
121 
122 	uint8_t		reserved;
123 } __packed;
124 
125 struct mtw_tx_data {
126 	STAILQ_ENTRY(mtw_tx_data)	next;
127 	struct mbuf		*m;
128 	struct mtw_softc	*sc;
129 	struct usbd_xfer	*xfer;
130 	uint8_t			qid;
131 	uint8_t			ridx;
132   uint32_t			buflen;
133   //struct mtw_tx_desc desc;
134 	struct ieee80211_node	*ni;
135   //struct mtw_txd desc;
136 	uint8_t	desc[sizeof(struct mtw_txd)+sizeof(struct mtw_txwi)];
137 
138 };
139 
140 struct mtw_rx_data {
141 	STAILQ_ENTRY(mtw_rx_data)	next;
142 	struct mtw_softc	*sc;
143 	struct usbd_xfer	*xfer;
144 
145 	uint8_t			*buf;
146 };
147 
148 struct mtw_tx_ring {
149 	struct mtw_tx_data	data[MTW_TX_RING_COUNT];
150 	struct usbd_pipe	*pipeh;
151 	int			cur;
152 	int			queued;
153 	uint8_t			pipe_no;
154 };
155 
156 struct mtw_rx_ring {
157 	struct mtw_rx_data	data[MTW_RX_RING_COUNT];
158 	struct usbd_pipe	*pipeh;
159 	uint8_t			pipe_no;
160 };
161 
162 struct mtw_vap {
163 	struct ieee80211vap             vap;
164 	struct mbuf			*beacon_mbuf;
165 
166 	int                             (*newstate)(struct ieee80211vap *,
167       enum ieee80211_state, int);
168 	void				(*recv_mgmt)(struct ieee80211_node *,
169 					    struct mbuf *, int,
170 					    const struct ieee80211_rx_stats *,
171 					    int, int);
172 
173 	uint8_t				rvp_id;
174 };
175 #define	MTW_VAP(vap)	((struct mtw_vap *)(vap))
176 struct mtw_host_cmd {
177 	void	(*cb)(struct mtw_softc *, void *);
178 	uint8_t	data[256];
179 };
180 
181 struct mtw_cmd_newstate {
182 	enum ieee80211_state	state;
183 	int			arg;
184 };
185 
186 struct mtw_cmd_key {
187 	struct ieee80211_key	key;
188 	struct ieee80211_node	*ni;
189 };
190 
191 #define MTW_HOST_CMD_RING_COUNT	32
192 struct mtw_host_cmd_ring {
193 	struct mtw_host_cmd	cmd[MTW_HOST_CMD_RING_COUNT];
194 	int			cur;
195 	int			next;
196 	int			queued;
197 };
198 
199 
200 
201 struct mtw_node {
202 	struct ieee80211_node	ni;
203        uint8_t			mgt_ridx;
204       uint8_t			amrr_ridx;
205 	uint8_t			fix_ridx;
206 
207 };
208 #define MTW_NODE(ni)		((struct mtw_node *)(ni))
209 
210 struct mtw_mcu_tx {
211 	struct mtw_softc	*sc;
212 	struct usbd_xfer	*xfer;
213 	struct usbd_pipe	*pipeh;
214 	uint8_t			 pipe_no;
215 	uint8_t			*buf;
216 	int8_t			 seq;
217 };
218 
219 #define MTW_MCU_IVB_LEN		0x40
220 struct mtw_ucode_hdr {
221 	uint32_t		ilm_len;
222 	uint32_t		dlm_len;
223 	uint16_t		build_ver;
224 	uint16_t		fw_ver;
225 	uint8_t			pad[4];
226 	char			build_time[16];
227 } __packed;
228 
229 struct mtw_ucode {
230 	struct mtw_ucode_hdr	hdr;
231 	uint8_t			ivb[MTW_MCU_IVB_LEN];
232 	uint8_t			data[];
233 } __packed;
234 
235 STAILQ_HEAD(mtw_tx_data_head, mtw_tx_data);
236 struct mtw_endpoint_queue {
237 	struct mtw_tx_data		tx_data[MTW_TX_RING_COUNT];
238 	struct mtw_tx_data_head		tx_qh;
239 	struct mtw_tx_data_head		tx_fh;
240 	uint32_t			tx_nfree;
241 };
242 
243 struct mtw_cmdq {
244 	void			*arg0;
245 	void			*arg1;
246 	void			(*func)(void *);
247 	struct ieee80211_key	*k;
248 	struct ieee80211_key	key;
249 	uint8_t			mac[IEEE80211_ADDR_LEN];
250 	uint8_t			wcid;
251 };
252 enum {
253 	MTW_BULK_RX,		/* = WME_AC_BK */
254 	//MTW_BULK_RX1,
255        MTW_BULK_TX_BE,		/* = WME_AC_BE */
256        MTW_BULK_TX_VI,		/* = WME_AC_VI */
257 	MTW_BULK_TX_VO,		/* = WME_AC_VO */
258 	MTW_BULK_TX_HCCA,
259 	MTW_BULK_TX_PRIO,
260 	MTW_BULK_TX_BK,
261 	MTW_BULK_FW_CMD,
262 	MTW_BULK_RAW_TX,
263 	MTW_N_XFER,
264 };
265 #define	MTW_TXCNT	0
266 #define	MTW_SUCCESS	1
267 #define	MTW_RETRY	2
268 #define	MTW_EP_QUEUES   6
269 #define	MTW_FLAG_FWLOAD_NEEDED		0x01
270 #define	MTW_RUNNING			0x02
271 struct mtw_softc {
272 	device_t			sc_dev;
273   int                             sc_idx;
274 	struct ieee80211com		sc_ic;
275         struct ieee80211_ratectl_tx_stats sc_txs;
276 	int				(*sc_newstate)(struct ieee80211com *,
277 					    enum ieee80211_state, int);
278 	int				(*sc_srom_read)(struct mtw_softc *,
279 	    uint16_t, uint16_t *);
280 #define	MTW_CMDQ_MAX	16
281 #define	MTW_CMDQ_MASQ	(MTW_CMDQ_MAX - 1)
282 #define	MTW_CMDQ_ABORT	0
283 #define	MTW_CMDQ_GO	1
284 	struct mbuf			*rx_m;
285         uint8_t				runbmap;
286         uint8_t				running;
287         uint8_t				ap_running;
288 	uint8_t				adhoc_running;
289         uint8_t				sta_running;
290 	uint8_t fwloading;
291         uint16_t			wcid_stats[MTW_WCID_MAX + 1][3];
292         struct mbufq			sc_snd;
293         uint8_t				cmdq_exec;
294         uint8_t				fifo_cnt;
295 	uint32_t                        sc_flags;
296         uint8_t				rvp_cnt;
297         uint8_t				cmdq_run;
298         uint8_t				rvp_bmap;
299         struct mtw_cmdq			cmdq[MTW_CMDQ_MAX];
300 	struct task			cmdq_task;
301 	uint8_t				cmdq_mtw;
302 	uint8_t				cmdq_key_set;
303 	struct usb_device		*sc_udev;
304 	struct usb_interface		*sc_iface;
305 	uint32_t			cmdq_store;
306 	struct mtx                      sc_mtx;
307   uint32_t                              sc_mcu_xferlen;
308         struct usb_xfer			*sc_xfer[MTW_N_XFER];
309 	uint16_t			asic_ver;
310 	uint16_t			asic_rev;
311 	uint16_t			mac_ver;
312 	uint16_t			mac_rev;
313 	uint16_t			rf_rev;
314         int ridx;
315   int amrr_ridx;
316 	uint8_t				freq;
317 	uint8_t				ntxchains;
318 	uint8_t				nrxchains;
319 
320   struct mtw_txd_fw *txd_fw[4];
321   int sc_sent;
322   uint8_t sc_ivb_1[MTW_MCU_IVB_LEN];
323 	struct mtw_endpoint_queue	sc_epq[MTW_BULK_RX];
324 	uint8_t				rfswitch;
325 	uint8_t				ext_2ghz_lna;
326 	uint8_t				ext_5ghz_lna;
327 	uint8_t				calib_2ghz;
328 	uint8_t				calib_5ghz;
329 	uint8_t				txmixgain_2ghz;
330 	uint8_t				txmixgain_5ghz;
331 	int8_t				txpow1[54];
332 	int8_t				txpow2[54];
333 	int8_t				txpow3[54];
334 	int8_t				rssi_2ghz[3];
335 	int8_t				rssi_5ghz[3];
336 	uint8_t				lna[4];
337 
338 	uint8_t				leds;
339 	uint16_t			led[3];
340 	uint32_t			txpow20mhz[5];
341 	uint32_t			txpow40mhz_2ghz[5];
342 	uint32_t			txpow40mhz_5ghz[5];
343 
344 	int8_t				bbp_temp;
345 	uint8_t				rf_freq_offset;
346 	uint32_t			rf_pa_mode[2];
347 	int				sc_rf_calibrated;
348 	int				sc_bw_calibrated;
349 	int				sc_chan_group;
350 
351 
352 
353 
354 	uint8_t				cmd_seq;
355 	uint8_t				sc_detached;
356 	struct mtw_tx_ring		sc_mcu;
357 	struct mtw_rx_ring		rxq[MTW_RXQ_COUNT];
358 	struct mtw_tx_ring		txq[MTW_TXQ_COUNT];
359 	struct task                     ratectl_task;
360 	struct usb_callout              ratectl_ch;
361 	uint8_t				ratectl_run;
362 	//struct mtw_host_cmd_ring	cmdq;
363 	uint8_t				qfullmsk;
364 	int				sc_tx_timer;
365 
366 	uint8_t				sc_bssid[IEEE80211_ADDR_LEN];
367 
368 	union {
369 		struct mtw_rx_radiotap_header th;
370 		uint8_t	pad[64];
371 	}				sc_rxtapu;
372 #define sc_rxtap	sc_rxtapu.th
373 	int				sc_rxtap_len;
374 
375 	union {
376 		struct mtw_tx_radiotap_header th;
377 		uint8_t	pad[64];
378 		uint8_t		wt_hwqueue;
379 
380 	}				sc_txtapu;
381 #define sc_txtap	sc_txtapu.th
382 	int				sc_txtap_len;
383 	int				sc_key_tasks;
384 };
385 #define	MTW_LOCK(sc)		mtx_lock(&(sc)->sc_mtx)
386 #define MTW_UNLOCK(sc)		mtx_unlock(&(sc)->sc_mtx)
387 #define	MTW_LOCK_ASSERT(sc, t)	mtx_assert(&(sc)->sc_mtx, t)
388