xref: /freebsd/sys/dev/usb/wlan/if_rumvar.h (revision 1251590741d28695f233a1798cfc8428e78ff991)
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 	uint64_t	wr_tsf;
26 	uint8_t		wr_flags;
27 	uint8_t		wr_rate;
28 	uint16_t	wr_chan_freq;
29 	uint16_t	wr_chan_flags;
30 	int8_t		wr_antsignal;
31 	int8_t		wr_antnoise;
32 	uint8_t		wr_antenna;
33 } __packed __aligned(8);
34 
35 #define RT2573_RX_RADIOTAP_PRESENT					\
36 	((1 << IEEE80211_RADIOTAP_TSFT) |				\
37 	 (1 << IEEE80211_RADIOTAP_FLAGS) |				\
38 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
39 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
40 	 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |			\
41 	 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |			\
42 	 (1 << IEEE80211_RADIOTAP_ANTENNA) |				\
43 	 0)
44 
45 struct rum_tx_radiotap_header {
46 	struct ieee80211_radiotap_header wt_ihdr;
47 	uint8_t		wt_flags;
48 	uint8_t		wt_rate;
49 	uint16_t	wt_chan_freq;
50 	uint16_t	wt_chan_flags;
51 	uint8_t		wt_antenna;
52 } __packed __aligned(8);
53 
54 #define RT2573_TX_RADIOTAP_PRESENT					\
55 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
56 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
57 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
58 	 (1 << IEEE80211_RADIOTAP_ANTENNA))
59 
60 struct rum_softc;
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 union sec_param {
73 	struct ieee80211_key		key;
74 	uint8_t				macaddr[IEEE80211_ADDR_LEN];
75 	struct ieee80211vap		*vap;
76 };
77 #define CMD_FUNC_PROTO			void (*func)(struct rum_softc *, \
78 					    union sec_param *, uint8_t)
79 
80 struct rum_cmdq {
81 	union sec_param			data;
82 	uint8_t				rvp_id;
83 
84 	CMD_FUNC_PROTO;
85 };
86 #define RUM_CMDQ_SIZE			16
87 
88 struct rum_vap {
89 	struct ieee80211vap		vap;
90 	struct mbuf			*bcn_mbuf;
91 	struct usb_callout		ratectl_ch;
92 	struct task			ratectl_task;
93 	uint8_t				maxretry;
94 
95 	int				(*newstate)(struct ieee80211vap *,
96 					    enum ieee80211_state, int);
97 	void				(*bmiss)(struct ieee80211vap *);
98 	void				(*recv_mgmt)(struct ieee80211_node *,
99 					    struct mbuf *, int,
100 					    const struct ieee80211_rx_stats *,
101 					    int, int);
102 };
103 #define	RUM_VAP(vap)	((struct rum_vap *)(vap))
104 
105 enum {
106 	RUM_BULK_WR,
107 	RUM_BULK_RD,
108 	RUM_N_TRANSFER = 2,
109 };
110 
111 struct rum_softc {
112 	struct ieee80211com		sc_ic;
113 	struct ieee80211_ratectl_tx_stats sc_txs;
114 	struct mbufq			sc_snd;
115 	device_t			sc_dev;
116 	struct usb_device		*sc_udev;
117 
118 	struct usb_xfer			*sc_xfer[RUM_N_TRANSFER];
119 
120 	uint8_t				rf_rev;
121 	uint8_t				rffreq;
122 
123 	struct rum_tx_data		tx_data[RUM_TX_LIST_COUNT];
124 	rum_txdhead			tx_q;
125 	rum_txdhead			tx_free;
126 	int				tx_nfree;
127 	struct rum_rx_desc		sc_rx_desc;
128 
129 	struct mtx			sc_mtx;
130 
131 	int				sc_sleep_end;
132 	int				sc_sleep_time;
133 	uint8_t				last_rx_flags;
134 
135 	struct rum_cmdq			cmdq[RUM_CMDQ_SIZE];
136 	struct mtx			cmdq_mtx;
137 	struct task			cmdq_task;
138 	uint8_t				cmdq_first;
139 	uint8_t				cmdq_last;
140 
141 	uint32_t			sta[6];
142 	uint32_t			rf_regs[4];
143 	uint8_t				txpow[44];
144 	u_int				sc_detached:1,
145 					sc_running:1,
146 					sc_sleeping:1,
147 					sc_clr_shkeys:1;
148 
149 	uint8_t				sc_bssid[IEEE80211_ADDR_LEN];
150 	struct wmeParams		wme_params[WME_NUM_AC];
151 
152 	uint8_t				vap_key_count[1];
153 	uint64_t			keys_bmap;
154 
155 	struct {
156 		uint8_t	val;
157 		uint8_t	reg;
158 	} __packed			bbp_prom[16];
159 
160 	int				hw_radio;
161 	int				rx_ant;
162 	int				tx_ant;
163 	int				nb_ant;
164 	int				ext_2ghz_lna;
165 	int				ext_5ghz_lna;
166 	int				rssi_2ghz_corr;
167 	int				rssi_5ghz_corr;
168 	uint8_t				bbp17;
169 
170 	struct rum_rx_radiotap_header	sc_rxtap;
171 	struct rum_tx_radiotap_header	sc_txtap;
172 };
173 
174 #define RUM_LOCK_INIT(sc) \
175 	mtx_init(&(sc)->sc_mtx, device_get_nameunit((sc)->sc_dev), \
176 	    MTX_NETWORK_LOCK, MTX_DEF);
177 #define RUM_LOCK(sc)			mtx_lock(&(sc)->sc_mtx)
178 #define RUM_UNLOCK(sc)			mtx_unlock(&(sc)->sc_mtx)
179 #define RUM_LOCK_ASSERT(sc)		mtx_assert(&(sc)->sc_mtx, MA_OWNED)
180 #define RUM_LOCK_DESTROY(sc)		mtx_destroy(&(sc)->sc_mtx)
181 
182 #define RUM_CMDQ_LOCK_INIT(sc) \
183 	mtx_init(&(sc)->cmdq_mtx, "cmdq lock", NULL, MTX_DEF)
184 #define RUM_CMDQ_LOCK(sc)		mtx_lock(&(sc)->cmdq_mtx)
185 #define RUM_CMDQ_UNLOCK(sc)		mtx_unlock(&(sc)->cmdq_mtx)
186 #define RUM_CMDQ_LOCK_DESTROY(sc)	mtx_destroy(&(sc)->cmdq_mtx)
187