xref: /netbsd-src/sys/dev/usb/if_runvar.h (revision 946379e7b37692fc43f68eb0d1c10daa0a7f3b6c)
1 /*	$NetBSD: if_runvar.h,v 1.1 2012/05/30 14:30:35 nonaka Exp $	*/
2 /*	$OpenBSD: if_runvar.h,v 1.8 2010/02/08 18:46:47 damien Exp $	*/
3 
4 /*-
5  * Copyright (c) 2008,2009 Damien Bergamini <damien.bergamini@free.fr>
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 
20 #define RUN_MAX_RXSZ			\
21 	4096
22 #if 0
23 	(sizeof (uint32_t) +		\
24 	 sizeof (struct rt2860_rxwi) +	\
25 	 sizeof (uint16_t) +		\
26 	 MCLBYTES +			\
27 	 sizeof (struct rt2870_rxd))
28 #endif
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_rxwi) +	\
33 	 MCLBYTES + 11)
34 
35 #define RUN_TX_TIMEOUT	5000	/* ms */
36 
37 #define RUN_RX_RING_COUNT	1
38 #define RUN_TX_RING_COUNT	8
39 
40 #define RT2870_WCID_MAX		253
41 #define RUN_AID2WCID(aid)	((aid) & 0xff)
42 
43 struct run_rx_radiotap_header {
44 	struct ieee80211_radiotap_header wr_ihdr;
45 	uint8_t		wr_flags;
46 	uint8_t		wr_rate;
47 	uint16_t	wr_chan_freq;
48 	uint16_t	wr_chan_flags;
49 	uint8_t		wr_dbm_antsignal;
50 	uint8_t		wr_antenna;
51 	uint8_t		wr_antsignal;
52 } __packed;
53 
54 #define RUN_RX_RADIOTAP_PRESENT				\
55 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
56 	 1 << IEEE80211_RADIOTAP_RATE |			\
57 	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
58 	 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL |	\
59 	 1 << IEEE80211_RADIOTAP_ANTENNA |		\
60 	 1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL)
61 
62 struct run_tx_radiotap_header {
63 	struct ieee80211_radiotap_header wt_ihdr;
64 	uint8_t		wt_flags;
65 	uint8_t		wt_rate;
66 	uint16_t	wt_chan_freq;
67 	uint16_t	wt_chan_flags;
68 	uint8_t		wt_hwqueue;
69 } __packed;
70 
71 #define RUN_TX_RADIOTAP_PRESENT				\
72 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
73 	 1 << IEEE80211_RADIOTAP_RATE |			\
74 	 1 << IEEE80211_RADIOTAP_CHANNEL/* |		\
75 	 1 << IEEE80211_RADIOTAP_HWQUEUE*/)
76 
77 struct run_softc;
78 
79 struct run_tx_data {
80 	struct run_softc	*sc;
81 	usbd_xfer_handle	xfer;
82 	uint8_t			*buf;
83 	uint8_t			qid;
84 };
85 
86 struct run_rx_data {
87 	struct run_softc	*sc;
88 	usbd_xfer_handle	xfer;
89 	uint8_t			*buf;
90 };
91 
92 struct run_tx_ring {
93 	struct run_tx_data	data[RUN_TX_RING_COUNT];
94 	usbd_pipe_handle	pipeh;
95 	int			cur;
96 	int			queued;
97 	uint8_t			pipe_no;
98 };
99 
100 struct run_rx_ring {
101 	struct run_rx_data	data[RUN_RX_RING_COUNT];
102 	usbd_pipe_handle	pipeh;
103 	uint8_t			pipe_no;
104 };
105 
106 struct run_host_cmd {
107 	void	(*cb)(struct run_softc *, void *);
108 	uint8_t	data[256];
109 };
110 
111 struct run_cmd_newstate {
112 	enum ieee80211_state	state;
113 	int			arg;
114 };
115 
116 struct run_cmd_key {
117 	struct ieee80211_key	key;
118 	uint16_t		associd;
119 };
120 
121 #define RUN_HOST_CMD_RING_COUNT	32
122 struct run_host_cmd_ring {
123 	struct run_host_cmd	cmd[RUN_HOST_CMD_RING_COUNT];
124 	int			cur;
125 	int			next;
126 	int			queued;
127 };
128 
129 struct run_node {
130 	struct ieee80211_node	ni;
131 	uint8_t			ridx[IEEE80211_RATE_MAXSIZE];
132 	uint8_t			ctl_ridx[IEEE80211_RATE_MAXSIZE];
133 };
134 
135 struct run_softc {
136 	device_t			sc_dev;
137 	struct ethercom			sc_ec;
138 #define sc_if	sc_ec.ec_if
139 	struct ieee80211com		sc_ic;
140 	int				(*sc_newstate)(struct ieee80211com *,
141 					    enum ieee80211_state, int);
142 	int				(*sc_srom_read)(struct run_softc *,
143 					    uint16_t, uint16_t *);
144 
145 	usbd_device_handle		sc_udev;
146 	usbd_interface_handle		sc_iface;
147 
148 	uint16_t			mac_ver;
149 	uint16_t			mac_rev;
150 	uint8_t				rf_rev;
151 	uint8_t				freq;
152 	uint8_t				ntxchains;
153 	uint8_t				nrxchains;
154 	int				fixed_ridx;
155 
156 	uint8_t				bbp25;
157 	uint8_t				bbp26;
158 	uint8_t				rf24_20mhz;
159 	uint8_t				rf24_40mhz;
160 	uint8_t				patch_dac;
161 	uint8_t				rfswitch;
162 	uint8_t				ext_2ghz_lna;
163 	uint8_t				ext_5ghz_lna;
164 	uint8_t				calib_2ghz;
165 	uint8_t				calib_5ghz;
166 	uint8_t				txmixgain_2ghz;
167 	uint8_t				txmixgain_5ghz;
168 	int8_t				txpow1[54];
169 	int8_t				txpow2[54];
170 	int8_t				rssi_2ghz[3];
171 	int8_t				rssi_5ghz[3];
172 	uint8_t				lna[4];
173 
174 	struct {
175 		uint8_t	reg;
176 		uint8_t	val;
177 	}				bbp[10], rf[10];
178 	uint8_t				leds;
179 	uint16_t			led[3];
180 	uint32_t			txpow20mhz[5];
181 	uint32_t			txpow40mhz_2ghz[5];
182 	uint32_t			txpow40mhz_5ghz[5];
183 
184 	struct usb_task			sc_task;
185 
186 	struct ieee80211_amrr		amrr;
187 	struct ieee80211_amrr_node	amn;
188 
189 	callout_t			scan_to;
190 	callout_t			calib_to;
191 
192 	struct run_rx_ring		rxq;
193 	struct run_tx_ring		txq[4];
194 	struct run_host_cmd_ring	cmdq;
195 	uint8_t				qfullmsk;
196 	int				sc_tx_timer;
197 	struct ieee80211_beacon_offsets	sc_bo;
198 	int				sc_flags;
199 #define RUN_FWLOADED	(1 << 0)
200 #define RUN_DETACHING	(1 << 1)
201 
202 	struct bpf_if *			sc_drvbpf;
203 
204 	union {
205 		struct run_rx_radiotap_header th;
206 		uint8_t	pad[64];
207 	}				sc_rxtapu;
208 #define sc_rxtap	sc_rxtapu.th
209 	int				sc_rxtap_len;
210 
211 	union {
212 		struct run_tx_radiotap_header th;
213 		uint8_t	pad[64];
214 	}				sc_txtapu;
215 #define sc_txtap	sc_txtapu.th
216 	int				sc_txtap_len;
217 };
218