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
21#ifndef _IF_RUNVAR_H_
22#define	_IF_RUNVAR_H_
23
24/* Support up to 4KB frames - useful for A-MSDU/FF. */
25#define	RUN_MAX_RXSZ			\
26	MIN(4096, MJUMPAGESIZE)
27
28/* Support up to 8KB frames - useful for A-MSDU/FF. */
29#define	RUN_MAX_TXSZ			\
30	(sizeof (struct rt2870_txd) +	\
31	 sizeof (struct rt2860_txwi) +	\
32	 8192 + 11)
33
34#define	RUN_TX_TIMEOUT	5000	/* ms */
35
36/* Tx ring count was 8/endpoint, now 32 for all 4 (or 6) endpoints. */
37#define	RUN_TX_RING_COUNT	32
38#define	RUN_RX_RING_COUNT	1
39
40#define	RT2870_WCID_MAX		64
41#define	RUN_AID2WCID(aid)	((aid) & 0xff)
42
43#define	RUN_VAP_MAX		8
44
45struct run_rx_radiotap_header {
46	struct ieee80211_radiotap_header wr_ihdr;
47	uint64_t	wr_tsf;
48	uint8_t		wr_flags;
49	uint8_t		wr_rate;
50	uint16_t	wr_chan_freq;
51	uint16_t	wr_chan_flags;
52	int8_t		wr_dbm_antsignal;
53	uint8_t		wr_antenna;
54	uint8_t		wr_antsignal;
55} __packed __aligned(8);
56
57#define	RUN_RX_RADIOTAP_PRESENT				\
58	(1 << IEEE80211_RADIOTAP_TSFT |			\
59	 1 << IEEE80211_RADIOTAP_FLAGS |		\
60	 1 << IEEE80211_RADIOTAP_RATE |			\
61	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
62	 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL |	\
63	 1 << IEEE80211_RADIOTAP_ANTENNA |		\
64	 1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL)
65
66struct run_tx_radiotap_header {
67	struct ieee80211_radiotap_header wt_ihdr;
68	uint8_t		wt_flags;
69	uint8_t		wt_rate;
70	uint16_t	wt_chan_freq;
71	uint16_t	wt_chan_flags;
72	uint8_t		wt_hwqueue;
73} __packed;
74
75#define IEEE80211_RADIOTAP_HWQUEUE 15
76
77#define	RUN_TX_RADIOTAP_PRESENT				\
78	(1 << IEEE80211_RADIOTAP_FLAGS |		\
79	 1 << IEEE80211_RADIOTAP_RATE |			\
80	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
81	 1 << IEEE80211_RADIOTAP_HWQUEUE)
82
83struct run_softc;
84
85struct run_tx_data {
86	STAILQ_ENTRY(run_tx_data)	next;
87	struct run_softc	*sc;
88	struct mbuf		*m;
89	struct ieee80211_node	*ni;
90	uint32_t align[0];	/* dummy field */
91	uint8_t	desc[sizeof(struct rt2870_txd) +
92		     sizeof(struct rt2860_txwi)];
93	uint8_t			ridx;
94};
95STAILQ_HEAD(run_tx_data_head, run_tx_data);
96
97struct run_node {
98	struct ieee80211_node	ni;
99	uint8_t			amrr_ridx;
100	uint8_t			mgt_ridx;
101	uint8_t			fix_ridx;
102};
103#define RUN_NODE(ni)		((struct run_node *)(ni))
104
105struct run_cmdq {
106	void			*arg0;
107	void			*arg1;
108	void			(*func)(void *);
109	struct ieee80211_key	*k;
110	struct ieee80211_key	key;
111	uint8_t			mac[IEEE80211_ADDR_LEN];
112	uint8_t			wcid;
113};
114
115struct run_vap {
116	struct ieee80211vap             vap;
117	struct mbuf			*beacon_mbuf;
118
119	int                             (*newstate)(struct ieee80211vap *,
120                                            enum ieee80211_state, int);
121	void				(*recv_mgmt)(struct ieee80211_node *,
122					    struct mbuf *, int,
123					    const struct ieee80211_rx_stats *,
124					    int, int);
125
126	uint8_t				rvp_id;
127};
128#define	RUN_VAP(vap)	((struct run_vap *)(vap))
129
130/*
131 * There are 7 bulk endpoints: 1 for RX
132 * and 6 for TX (4 EDCAs + HCCA + Prio).
133 * Update 03-14-2009:  some devices like the Planex GW-US300MiniS
134 * seem to have only 4 TX bulk endpoints (Fukaumi Naoki).
135 */
136enum {
137	RUN_BULK_TX_BE,		/* = WME_AC_BE */
138	RUN_BULK_TX_BK,		/* = WME_AC_BK */
139	RUN_BULK_TX_VI,		/* = WME_AC_VI */
140	RUN_BULK_TX_VO,		/* = WME_AC_VO */
141	RUN_BULK_TX_HCCA,
142	RUN_BULK_TX_PRIO,
143	RUN_BULK_RX,
144	RUN_N_XFER,
145};
146
147#define	RUN_EP_QUEUES	RUN_BULK_RX
148
149struct run_endpoint_queue {
150	struct run_tx_data		tx_data[RUN_TX_RING_COUNT];
151	struct run_tx_data_head		tx_qh;
152	struct run_tx_data_head		tx_fh;
153	uint32_t			tx_nfree;
154};
155
156struct run_softc {
157	struct mtx			sc_mtx;
158	struct ieee80211com		sc_ic;
159	struct ieee80211_ratectl_tx_stats sc_txs;
160	struct mbufq			sc_snd;
161	device_t			sc_dev;
162	struct usb_device		*sc_udev;
163	int				sc_need_fwload;
164
165	int				sc_flags;
166#define	RUN_FLAG_FWLOAD_NEEDED		0x01
167#define	RUN_RUNNING			0x02
168
169	uint16_t			wcid_stats[RT2870_WCID_MAX + 1][3];
170#define	RUN_TXCNT	0
171#define	RUN_SUCCESS	1
172#define	RUN_RETRY	2
173
174	int				(*sc_srom_read)(struct run_softc *,
175					    uint16_t, uint16_t *);
176
177	uint16_t			mac_ver;
178	uint16_t			mac_rev;
179	uint16_t			rf_rev;
180	uint8_t				freq;
181	uint8_t				ntxchains;
182	uint8_t				nrxchains;
183
184	uint8_t				bbp25;
185	uint8_t				bbp26;
186	uint8_t				rf24_20mhz;
187	uint8_t				rf24_40mhz;
188	uint8_t				patch_dac;
189	uint8_t				rfswitch;
190	uint8_t				ext_2ghz_lna;
191	uint8_t				ext_5ghz_lna;
192	uint8_t				calib_2ghz;
193	uint8_t				calib_5ghz;
194	uint8_t				txmixgain_2ghz;
195	uint8_t				txmixgain_5ghz;
196	int8_t				txpow1[54];
197	int8_t				txpow2[54];
198	int8_t				txpow3[54];
199	int8_t				rssi_2ghz[3];
200	int8_t				rssi_5ghz[3];
201	uint8_t				lna[4];
202
203	struct {
204		uint8_t	reg;
205		uint8_t	val;
206	}				bbp[10], rf[10];
207	uint8_t				leds;
208	uint16_t			led[3];
209	uint32_t			txpow20mhz[5];
210	uint32_t			txpow40mhz_2ghz[5];
211	uint32_t			txpow40mhz_5ghz[5];
212
213	struct run_endpoint_queue	sc_epq[RUN_EP_QUEUES];
214
215	struct task                     ratectl_task;
216	struct usb_callout              ratectl_ch;
217	uint8_t				ratectl_run;
218#define	RUN_RATECTL_OFF	0
219
220/* need to be power of 2, otherwise RUN_CMDQ_GET fails */
221#define	RUN_CMDQ_MAX	16
222#define	RUN_CMDQ_MASQ	(RUN_CMDQ_MAX - 1)
223	struct run_cmdq			cmdq[RUN_CMDQ_MAX];
224	struct task			cmdq_task;
225	uint32_t			cmdq_store;
226	uint8_t				cmdq_exec;
227	uint8_t				cmdq_run;
228	uint8_t				cmdq_key_set;
229#define	RUN_CMDQ_ABORT	0
230#define	RUN_CMDQ_GO	1
231
232	struct usb_xfer			*sc_xfer[RUN_N_XFER];
233
234	struct mbuf			*rx_m;
235
236	uint8_t				fifo_cnt;
237
238	uint8_t				running;
239	uint8_t				runbmap;
240	uint8_t				ap_running;
241	uint8_t				adhoc_running;
242	uint8_t				sta_running;
243	uint8_t				rvp_cnt;
244	uint8_t				rvp_bmap;
245	uint8_t				sc_detached;
246
247	uint8_t				sc_bssid[IEEE80211_ADDR_LEN];
248
249	union {
250		struct run_rx_radiotap_header th;
251		uint8_t	pad[64];
252	}				sc_rxtapu;
253#define sc_rxtap	sc_rxtapu.th
254
255	union {
256		struct run_tx_radiotap_header th;
257		uint8_t	pad[64];
258	}				sc_txtapu;
259#define sc_txtap	sc_txtapu.th
260};
261
262#define	RUN_LOCK(sc)		mtx_lock(&(sc)->sc_mtx)
263#define	RUN_UNLOCK(sc)		mtx_unlock(&(sc)->sc_mtx)
264#define	RUN_LOCK_ASSERT(sc, t)	mtx_assert(&(sc)->sc_mtx, t)
265
266#endif	/* _IF_RUNVAR_H_ */
267