xref: /openbsd/sys/dev/usb/if_mtwvar.h (revision 57a8187d)
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 /* NB: "11" is the maximum number of padding bytes needed for Tx */
28 #define MTW_MAX_TXSZ			\
29 	(sizeof (struct mtw_txd) +	\
30 	 sizeof (struct mtw_txwi) +	\
31 	 MCLBYTES + 11)
32 
33 #define MTW_TX_TIMEOUT	5000	/* ms */
34 
35 #define MTW_RX_RING_COUNT	1
36 #define MTW_TX_RING_COUNT	8
37 
38 #define MTW_RXQ_COUNT		2
39 #define MTW_TXQ_COUNT		6
40 
41 #define MTW_WCID_MAX		8
42 #define MTW_AID2WCID(aid)	(1 + ((aid) & 0x7))
43 
44 struct mtw_rx_radiotap_header {
45 	struct ieee80211_radiotap_header wr_ihdr;
46 	uint8_t		wr_flags;
47 	uint8_t		wr_rate;
48 	uint16_t	wr_chan_freq;
49 	uint16_t	wr_chan_flags;
50 	uint8_t		wr_dbm_antsignal;
51 	uint8_t		wr_antenna;
52 	uint8_t		wr_antsignal;
53 } __packed;
54 
55 #define MTW_RX_RADIOTAP_PRESENT				\
56 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
57 	 1 << IEEE80211_RADIOTAP_RATE |			\
58 	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
59 	 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL |	\
60 	 1 << IEEE80211_RADIOTAP_ANTENNA |		\
61 	 1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL)
62 
63 struct mtw_tx_radiotap_header {
64 	struct ieee80211_radiotap_header wt_ihdr;
65 	uint8_t		wt_flags;
66 	uint8_t		wt_rate;
67 	uint16_t	wt_chan_freq;
68 	uint16_t	wt_chan_flags;
69 } __packed;
70 
71 #define MTW_TX_RADIOTAP_PRESENT				\
72 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
73 	 1 << IEEE80211_RADIOTAP_RATE |			\
74 	 1 << IEEE80211_RADIOTAP_CHANNEL)
75 
76 struct mtw_softc;
77 
78 struct mtw_tx_data {
79 	struct mtw_softc	*sc;
80 	struct usbd_xfer	*xfer;
81 	uint8_t			*buf;
82 	uint8_t			qid;
83 };
84 
85 struct mtw_rx_data {
86 	struct mtw_softc	*sc;
87 	struct usbd_xfer	*xfer;
88 	uint8_t			*buf;
89 };
90 
91 struct mtw_tx_ring {
92 	struct mtw_tx_data	data[MTW_TX_RING_COUNT];
93 	struct usbd_pipe	*pipeh;
94 	int			cur;
95 	int			queued;
96 	uint8_t			pipe_no;
97 };
98 
99 struct mtw_rx_ring {
100 	struct mtw_rx_data	data[MTW_RX_RING_COUNT];
101 	struct usbd_pipe	*pipeh;
102 	uint8_t			pipe_no;
103 };
104 
105 struct mtw_host_cmd {
106 	void	(*cb)(struct mtw_softc *, void *);
107 	uint8_t	data[256];
108 };
109 
110 struct mtw_cmd_newstate {
111 	enum ieee80211_state	state;
112 	int			arg;
113 };
114 
115 struct mtw_cmd_key {
116 	struct ieee80211_key	key;
117 	struct ieee80211_node	*ni;
118 };
119 
120 #define MTW_HOST_CMD_RING_COUNT	32
121 struct mtw_host_cmd_ring {
122 	struct mtw_host_cmd	cmd[MTW_HOST_CMD_RING_COUNT];
123 	int			cur;
124 	int			next;
125 	int			queued;
126 };
127 
128 struct mtw_node {
129 	struct ieee80211_node		ni;
130 	struct ieee80211_ra_node	rn;
131 	uint8_t				ridx[IEEE80211_RATE_MAXSIZE];
132 	uint8_t				ctl_ridx[IEEE80211_RATE_MAXSIZE];
133 };
134 
135 struct mtw_mcu_tx {
136 	struct mtw_softc	*sc;
137 	struct usbd_xfer	*xfer;
138 	struct usbd_pipe	*pipeh;
139 	uint8_t			 pipe_no;
140 	uint8_t			*buf;
141 	uint8_t			 seq;
142 };
143 
144 #define MTW_MCU_IVB_LEN		0x40
145 struct mtw_ucode_hdr {
146 	uint32_t		ilm_len;
147 	uint32_t		dlm_len;
148 	uint16_t		build_ver;
149 	uint16_t		fw_ver;
150 	uint8_t			pad[4];
151 	char			build_time[16];
152 } __packed;
153 
154 struct mtw_ucode {
155 	struct mtw_ucode_hdr	hdr;
156 	uint8_t			ivb[MTW_MCU_IVB_LEN];
157 	uint8_t			data[];
158 } __packed;
159 
160 struct mtw_softc {
161 	struct device			sc_dev;
162 	struct ieee80211com		sc_ic;
163 	int				(*sc_newstate)(struct ieee80211com *,
164 					    enum ieee80211_state, int);
165 	int				(*sc_srom_read)(struct mtw_softc *,
166 					    uint16_t, uint16_t *);
167 
168 	struct usbd_device		*sc_udev;
169 	struct usbd_interface		*sc_iface;
170 
171 	uint16_t			asic_ver;
172 	uint16_t			asic_rev;
173 	uint16_t			mac_ver;
174 	uint16_t			mac_rev;
175 	uint16_t			rf_rev;
176 	uint8_t				freq;
177 	uint8_t				ntxchains;
178 	uint8_t				nrxchains;
179 	int				fixed_ridx;
180 
181 	uint8_t				rfswitch;
182 	uint8_t				ext_2ghz_lna;
183 	uint8_t				ext_5ghz_lna;
184 	uint8_t				calib_2ghz;
185 	uint8_t				calib_5ghz;
186 	uint8_t				txmixgain_2ghz;
187 	uint8_t				txmixgain_5ghz;
188 	int8_t				txpow1[54];
189 	int8_t				txpow2[54];
190 	int8_t				txpow3[54];
191 	int8_t				rssi_2ghz[3];
192 	int8_t				rssi_5ghz[3];
193 	uint8_t				lna[4];
194 
195 	uint8_t				leds;
196 	uint16_t			led[3];
197 	uint32_t			txpow20mhz[5];
198 	uint32_t			txpow40mhz_2ghz[5];
199 	uint32_t			txpow40mhz_5ghz[5];
200 
201 	int8_t				bbp_temp;
202 	uint8_t				rf_freq_offset;
203 	uint32_t			rf_pa_mode[2];
204 	int				sc_rf_calibrated;
205 	int				sc_bw_calibrated;
206 	int				sc_chan_group;
207 
208 	struct usb_task			sc_task;
209 
210 	struct ieee80211_amrr		amrr;
211 	struct ieee80211_amrr_node	amn;
212 
213 	struct timeout			scan_to;
214 	struct timeout			calib_to;
215 
216 	uint8_t				cmd_seq;
217 
218 	struct mtw_tx_ring		sc_mcu;
219 	struct mtw_rx_ring		rxq[MTW_RXQ_COUNT];
220 	struct mtw_tx_ring		txq[MTW_TXQ_COUNT];
221 	struct mtw_host_cmd_ring	cmdq;
222 	uint8_t				qfullmsk;
223 	int				sc_tx_timer;
224 
225 #if NBPFILTER > 0
226 	caddr_t				sc_drvbpf;
227 
228 	union {
229 		struct mtw_rx_radiotap_header th;
230 		uint8_t	pad[64];
231 	}				sc_rxtapu;
232 #define sc_rxtap	sc_rxtapu.th
233 	int				sc_rxtap_len;
234 
235 	union {
236 		struct mtw_tx_radiotap_header th;
237 		uint8_t	pad[64];
238 	}				sc_txtapu;
239 #define sc_txtap	sc_txtapu.th
240 	int				sc_txtap_len;
241 #endif
242 	int				sc_key_tasks;
243 };
244