xref: /freebsd/sys/dev/usb/wlan/if_rumvar.h (revision b3aaa0cc21c63d388230c7ef2a80abd631ff20d5)
1 /*	$FreeBSD$	*/
2 
3 /*-
4  * Copyright (c) 2005, 2006 Damien Bergamini <damien.bergamini@free.fr>
5  * Copyright (c) 2006 Niall O'Higgins <niallo@openbsd.org>
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 RUM_TX_LIST_COUNT	8
21 #define RUM_TX_MINFREE		2
22 
23 struct rum_rx_radiotap_header {
24 	struct ieee80211_radiotap_header wr_ihdr;
25 	uint8_t		wr_flags;
26 	uint8_t		wr_rate;
27 	uint16_t	wr_chan_freq;
28 	uint16_t	wr_chan_flags;
29 	uint8_t		wr_antenna;
30 	uint8_t		wr_antsignal;
31 };
32 
33 #define RT2573_RX_RADIOTAP_PRESENT					\
34 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
35 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
36 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
37 	 (1 << IEEE80211_RADIOTAP_ANTENNA) |				\
38 	 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL))
39 
40 struct rum_tx_radiotap_header {
41 	struct ieee80211_radiotap_header wt_ihdr;
42 	uint8_t		wt_flags;
43 	uint8_t		wt_rate;
44 	uint16_t	wt_chan_freq;
45 	uint16_t	wt_chan_flags;
46 	uint8_t		wt_antenna;
47 };
48 
49 #define RT2573_TX_RADIOTAP_PRESENT					\
50 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
51 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
52 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
53 	 (1 << IEEE80211_RADIOTAP_ANTENNA))
54 
55 struct rum_softc;
56 
57 struct rum_task {
58 	struct usb2_proc_msg	hdr;
59 	struct rum_softc	*sc;
60 };
61 
62 struct rum_tx_data {
63 	STAILQ_ENTRY(rum_tx_data)	next;
64 	struct rum_softc		*sc;
65 	struct rum_tx_desc		desc;
66 	struct mbuf			*m;
67 	struct ieee80211_node		*ni;
68 	int				rate;
69 };
70 typedef STAILQ_HEAD(, rum_tx_data) rum_txdhead;
71 
72 struct rum_node {
73 	struct ieee80211_node	ni;
74 	struct ieee80211_amrr_node amn;
75 };
76 #define	RUM_NODE(ni)	((struct rum_node *)(ni))
77 
78 struct rum_vap {
79 	struct ieee80211vap		vap;
80 	struct rum_softc		*sc;
81 	struct ieee80211_beacon_offsets	bo;
82 	struct ieee80211_amrr		amrr;
83 	struct usb2_callout		amrr_ch;
84 	struct rum_task			amrr_task[2];
85 
86 	int				(*newstate)(struct ieee80211vap *,
87 					    enum ieee80211_state, int);
88 };
89 #define	RUM_VAP(vap)	((struct rum_vap *)(vap))
90 
91 enum {
92 	RUM_BULK_WR,
93 	RUM_BULK_RD,
94 	RUM_N_TRANSFER = 2,
95 };
96 
97 struct rum_softc {
98 	struct ifnet			*sc_ifp;
99 	device_t			sc_dev;
100 	struct usb2_device		*sc_udev;
101 	struct usb2_process		sc_tq;
102 
103 	const struct ieee80211_rate_table *sc_rates;
104 	struct usb2_xfer		*sc_xfer[RUM_N_TRANSFER];
105 
106 	uint8_t				rf_rev;
107 	uint8_t				rffreq;
108 
109 	enum ieee80211_state		sc_state;
110 	int				sc_arg;
111 	struct rum_task			sc_synctask[2];
112 	struct rum_task			sc_task[2];
113 	struct rum_task			sc_promisctask[2];
114 	struct rum_task			sc_scantask[2];
115 	int				sc_scan_action;
116 #define RUM_SCAN_START	0
117 #define RUM_SCAN_END	1
118 #define RUM_SET_CHANNEL	2
119 
120 	struct rum_tx_data		tx_data[RUM_TX_LIST_COUNT];
121 	rum_txdhead			tx_q;
122 	rum_txdhead			tx_free;
123 	int				tx_nfree;
124 	struct rum_rx_desc		sc_rx_desc;
125 
126 	struct mtx			sc_mtx;
127 
128 	uint32_t			sta[6];
129 	uint32_t			rf_regs[4];
130 	uint8_t				txpow[44];
131 	uint8_t				sc_bssid[6];
132 
133 	struct {
134 		uint8_t	val;
135 		uint8_t	reg;
136 	} __packed			bbp_prom[16];
137 
138 	int				hw_radio;
139 	int				rx_ant;
140 	int				tx_ant;
141 	int				nb_ant;
142 	int				ext_2ghz_lna;
143 	int				ext_5ghz_lna;
144 	int				rssi_2ghz_corr;
145 	int				rssi_5ghz_corr;
146 	uint8_t				bbp17;
147 
148 	struct rum_rx_radiotap_header	sc_rxtap;
149 	int				sc_rxtap_len;
150 
151 	struct rum_tx_radiotap_header	sc_txtap;
152 	int				sc_txtap_len;
153 };
154 
155 #define RUM_LOCK(sc)		mtx_lock(&(sc)->sc_mtx)
156 #define RUM_UNLOCK(sc)		mtx_unlock(&(sc)->sc_mtx)
157 #define RUM_LOCK_ASSERT(sc, t)	mtx_assert(&(sc)->sc_mtx, t)
158