1188417Sthompsa/*	$FreeBSD$	*/
2184610Salfred
3184610Salfred/*-
4184610Salfred * Copyright (c) 2005, 2006 Damien Bergamini <damien.bergamini@free.fr>
5184610Salfred * Copyright (c) 2006 Niall O'Higgins <niallo@openbsd.org>
6184610Salfred *
7184610Salfred * Permission to use, copy, modify, and distribute this software for any
8184610Salfred * purpose with or without fee is hereby granted, provided that the above
9184610Salfred * copyright notice and this permission notice appear in all copies.
10184610Salfred *
11184610Salfred * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12184610Salfred * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13184610Salfred * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14184610Salfred * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15184610Salfred * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16184610Salfred * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17184610Salfred * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18184610Salfred */
19184610Salfred
20188417Sthompsa#define RUM_TX_LIST_COUNT	8
21188969Sthompsa#define RUM_TX_MINFREE		2
22184610Salfred
23184610Salfredstruct rum_rx_radiotap_header {
24184610Salfred	struct ieee80211_radiotap_header wr_ihdr;
25188417Sthompsa	uint8_t		wr_flags;
26188417Sthompsa	uint8_t		wr_rate;
27188417Sthompsa	uint16_t	wr_chan_freq;
28188417Sthompsa	uint16_t	wr_chan_flags;
29192468Ssam	int8_t		wr_antsignal;
30192468Ssam	int8_t		wr_antnoise;
31188417Sthompsa	uint8_t		wr_antenna;
32259460Shselasky} __packed __aligned(8);
33184610Salfred
34188417Sthompsa#define RT2573_RX_RADIOTAP_PRESENT					\
35184610Salfred	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
36184610Salfred	 (1 << IEEE80211_RADIOTAP_RATE) |				\
37184610Salfred	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
38192468Ssam	 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |			\
39192468Ssam	 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |			\
40184610Salfred	 (1 << IEEE80211_RADIOTAP_ANTENNA) |				\
41192468Ssam	 0)
42184610Salfred
43184610Salfredstruct rum_tx_radiotap_header {
44184610Salfred	struct ieee80211_radiotap_header wt_ihdr;
45188417Sthompsa	uint8_t		wt_flags;
46188417Sthompsa	uint8_t		wt_rate;
47188417Sthompsa	uint16_t	wt_chan_freq;
48188417Sthompsa	uint16_t	wt_chan_flags;
49188417Sthompsa	uint8_t		wt_antenna;
50259460Shselasky} __packed __aligned(8);
51184610Salfred
52188417Sthompsa#define RT2573_TX_RADIOTAP_PRESENT					\
53184610Salfred	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
54184610Salfred	 (1 << IEEE80211_RADIOTAP_RATE) |				\
55184610Salfred	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
56184610Salfred	 (1 << IEEE80211_RADIOTAP_ANTENNA))
57184610Salfred
58188417Sthompsastruct rum_softc;
59184610Salfred
60188417Sthompsastruct rum_tx_data {
61188417Sthompsa	STAILQ_ENTRY(rum_tx_data)	next;
62188417Sthompsa	struct rum_softc		*sc;
63188417Sthompsa	struct rum_tx_desc		desc;
64188417Sthompsa	struct mbuf			*m;
65188417Sthompsa	struct ieee80211_node		*ni;
66188417Sthompsa	int				rate;
67188417Sthompsa};
68188417Sthompsatypedef STAILQ_HEAD(, rum_tx_data) rum_txdhead;
69188417Sthompsa
70188417Sthompsastruct rum_vap {
71188417Sthompsa	struct ieee80211vap		vap;
72188417Sthompsa	struct ieee80211_beacon_offsets	bo;
73206358Srpaulo	struct usb_callout		ratectl_ch;
74206358Srpaulo	struct task			ratectl_task;
75188417Sthompsa
76188417Sthompsa	int				(*newstate)(struct ieee80211vap *,
77188417Sthompsa					    enum ieee80211_state, int);
78188417Sthompsa};
79188417Sthompsa#define	RUM_VAP(vap)	((struct rum_vap *)(vap))
80188417Sthompsa
81187259Sthompsaenum {
82188417Sthompsa	RUM_BULK_WR,
83188417Sthompsa	RUM_BULK_RD,
84188417Sthompsa	RUM_N_TRANSFER = 2,
85187259Sthompsa};
86187259Sthompsa
87184610Salfredstruct rum_softc {
88188417Sthompsa	struct ifnet			*sc_ifp;
89188417Sthompsa	device_t			sc_dev;
90192984Sthompsa	struct usb_device		*sc_udev;
91184610Salfred
92192984Sthompsa	struct usb_xfer		*sc_xfer[RUM_N_TRANSFER];
93184610Salfred
94188417Sthompsa	uint8_t				rf_rev;
95188417Sthompsa	uint8_t				rffreq;
96184610Salfred
97188419Sthompsa	struct rum_tx_data		tx_data[RUM_TX_LIST_COUNT];
98188417Sthompsa	rum_txdhead			tx_q;
99188417Sthompsa	rum_txdhead			tx_free;
100188417Sthompsa	int				tx_nfree;
101188417Sthompsa	struct rum_rx_desc		sc_rx_desc;
102184610Salfred
103188417Sthompsa	struct mtx			sc_mtx;
104184610Salfred
105188417Sthompsa	uint32_t			sta[6];
106188417Sthompsa	uint32_t			rf_regs[4];
107188417Sthompsa	uint8_t				txpow[44];
108188419Sthompsa	uint8_t				sc_bssid[6];
109259456Shselasky	uint8_t				sc_detached;
110184610Salfred
111188417Sthompsa	struct {
112188417Sthompsa		uint8_t	val;
113188417Sthompsa		uint8_t	reg;
114188417Sthompsa	} __packed			bbp_prom[16];
115188417Sthompsa
116188417Sthompsa	int				hw_radio;
117188417Sthompsa	int				rx_ant;
118188417Sthompsa	int				tx_ant;
119188417Sthompsa	int				nb_ant;
120188417Sthompsa	int				ext_2ghz_lna;
121188417Sthompsa	int				ext_5ghz_lna;
122188417Sthompsa	int				rssi_2ghz_corr;
123188417Sthompsa	int				rssi_5ghz_corr;
124188417Sthompsa	uint8_t				bbp17;
125188417Sthompsa
126188417Sthompsa	struct rum_rx_radiotap_header	sc_rxtap;
127188417Sthompsa	int				sc_rxtap_len;
128188417Sthompsa
129188417Sthompsa	struct rum_tx_radiotap_header	sc_txtap;
130188417Sthompsa	int				sc_txtap_len;
131184610Salfred};
132188417Sthompsa
133188417Sthompsa#define RUM_LOCK(sc)		mtx_lock(&(sc)->sc_mtx)
134188417Sthompsa#define RUM_UNLOCK(sc)		mtx_unlock(&(sc)->sc_mtx)
135188417Sthompsa#define RUM_LOCK_ASSERT(sc, t)	mtx_assert(&(sc)->sc_mtx, t)
136