if_urtwnvar.h revision 292174
1/*-
2 * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 *
16 * $OpenBSD: if_urtwnreg.h,v 1.3 2010/11/16 18:02:59 damien Exp $
17 * $FreeBSD: head/sys/dev/usb/wlan/if_urtwnvar.h 292174 2015-12-13 21:50:38Z avos $
18 */
19
20#define URTWN_RX_LIST_COUNT		1
21#define URTWN_TX_LIST_COUNT		8
22#define URTWN_HOST_CMD_RING_COUNT	32
23
24#define URTWN_RXBUFSZ	(16 * 1024)
25#define URTWN_TXBUFSZ	(sizeof(struct r92c_tx_desc) + IEEE80211_MAX_LEN)
26#define	URTWN_RX_DESC_SIZE	(sizeof(struct r92c_rx_stat))
27#define	URTWN_TX_DESC_SIZE	(sizeof(struct r92c_tx_desc))
28
29#define URTWN_TX_TIMEOUT	5000	/* ms */
30
31#define URTWN_LED_LINK	0
32#define URTWN_LED_DATA	1
33
34struct urtwn_rx_radiotap_header {
35	struct ieee80211_radiotap_header wr_ihdr;
36	uint8_t		wr_flags;
37	uint8_t		wr_rate;
38	uint16_t	wr_chan_freq;
39	uint16_t	wr_chan_flags;
40	int8_t		wr_dbm_antsignal;
41	int8_t		wr_dbm_antnoise;
42} __packed __aligned(8);
43
44#define URTWN_RX_RADIOTAP_PRESENT			\
45	(1 << IEEE80211_RADIOTAP_FLAGS |		\
46	 1 << IEEE80211_RADIOTAP_RATE |			\
47	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
48	 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL |	\
49	 1 << IEEE80211_RADIOTAP_DBM_ANTNOISE)
50
51struct urtwn_tx_radiotap_header {
52	struct ieee80211_radiotap_header wt_ihdr;
53	uint8_t		wt_flags;
54	uint16_t	wt_chan_freq;
55	uint16_t	wt_chan_flags;
56} __packed __aligned(8);
57
58#define URTWN_TX_RADIOTAP_PRESENT			\
59	(1 << IEEE80211_RADIOTAP_FLAGS |		\
60	 1 << IEEE80211_RADIOTAP_CHANNEL)
61
62struct urtwn_softc;
63
64struct urtwn_data {
65	struct urtwn_softc		*sc;
66	uint8_t				*buf;
67	uint16_t			buflen;
68	struct mbuf			*m;
69	struct ieee80211_node		*ni;
70	STAILQ_ENTRY(urtwn_data)	next;
71};
72typedef STAILQ_HEAD(, urtwn_data) urtwn_datahead;
73
74union sec_param {
75	struct ieee80211_key		key;
76};
77
78#define CMD_FUNC_PROTO			void (*func)(struct urtwn_softc *, \
79					    union sec_param *)
80
81struct urtwn_cmdq {
82	union sec_param			data;
83	CMD_FUNC_PROTO;
84};
85#define URTWN_CMDQ_SIZE			16
86
87struct urtwn_fw_info {
88	const uint8_t		*data;
89	size_t			size;
90};
91
92struct urtwn_node {
93	struct ieee80211_node	ni;	/* must be the first */
94	uint8_t			id;
95};
96#define URTWN_NODE(ni)	((struct urtwn_node *)(ni))
97
98struct urtwn_vap {
99	struct ieee80211vap	vap;
100
101	struct r92c_tx_desc	bcn_desc;
102	struct mbuf		*bcn_mbuf;
103	struct task		tsf_task_adhoc;
104
105	int			(*newstate)(struct ieee80211vap *,
106				    enum ieee80211_state, int);
107	void			(*recv_mgmt)(struct ieee80211_node *,
108				    struct mbuf *, int,
109				    const struct ieee80211_rx_stats *,
110				    int, int);
111};
112#define	URTWN_VAP(vap)	((struct urtwn_vap *)(vap))
113
114struct urtwn_host_cmd {
115	void	(*cb)(struct urtwn_softc *, void *);
116	uint8_t	data[256];
117};
118
119struct urtwn_cmd_newstate {
120	enum ieee80211_state	state;
121	int			arg;
122};
123
124struct urtwn_cmd_key {
125	struct ieee80211_key	key;
126	uint16_t		associd;
127};
128
129enum {
130	URTWN_BULK_RX,
131	URTWN_BULK_TX_BE,	/* = WME_AC_BE */
132	URTWN_BULK_TX_BK,	/* = WME_AC_BK */
133	URTWN_BULK_TX_VI,	/* = WME_AC_VI */
134	URTWN_BULK_TX_VO,	/* = WME_AC_VI */
135	URTWN_N_TRANSFER = 5,
136};
137
138#define	URTWN_EP_QUEUES	URTWN_BULK_RX
139
140union urtwn_rom {
141	struct r92c_rom			r92c_rom;
142	uint8_t				r88e_rom[URTWN_EFUSE_MAX_LEN];
143};
144
145struct urtwn_softc {
146	struct ieee80211com		sc_ic;
147	struct mbufq			sc_snd;
148	device_t			sc_dev;
149	struct usb_device		*sc_udev;
150
151	uint8_t				sc_iface_index;
152	u_int				sc_flags;
153#define URTWN_FLAG_CCK_HIPWR	0x01
154#define URTWN_DETACHED		0x02
155#define	URTWN_RUNNING		0x04
156
157	u_int				chip;
158#define	URTWN_CHIP_92C		0x01
159#define	URTWN_CHIP_92C_1T2R	0x02
160#define	URTWN_CHIP_UMC		0x04
161#define	URTWN_CHIP_UMC_A_CUT	0x08
162#define	URTWN_CHIP_88E		0x10
163
164#define URTWN_CHIP_HAS_RATECTL(_sc)	(!!((_sc)->chip & URTWN_CHIP_88E))
165
166	void				(*sc_node_free)(struct ieee80211_node *);
167	void				(*sc_rf_write)(struct urtwn_softc *,
168					    int, uint8_t, uint32_t);
169	int				(*sc_power_on)(struct urtwn_softc *);
170
171	struct ieee80211_node		*node_list[R88E_MACID_MAX];
172	struct mtx			nt_mtx;
173
174	uint8_t				board_type;
175	uint8_t				regulatory;
176	uint8_t				pa_setting;
177	int				avg_pwdb;
178	int				thcal_state;
179	int				thcal_lctemp;
180	int				ntxchains;
181	int				nrxchains;
182	int				ledlink;
183	int				sc_txtimer;
184
185	int				fwcur;
186	struct urtwn_data		sc_rx[URTWN_RX_LIST_COUNT];
187	urtwn_datahead			sc_rx_active;
188	urtwn_datahead			sc_rx_inactive;
189	struct urtwn_data		sc_tx[URTWN_TX_LIST_COUNT];
190	urtwn_datahead			sc_tx_active;
191	urtwn_datahead			sc_tx_inactive;
192	urtwn_datahead			sc_tx_pending;
193
194	const char			*fwname;
195	const struct firmware		*fw_fp;
196	struct urtwn_fw_info		fw;
197	void				*fw_virtaddr;
198
199	union urtwn_rom			rom;
200	uint8_t				cck_tx_pwr[6];
201	uint8_t				ht40_tx_pwr[5];
202	int8_t				bw20_tx_pwr_diff;
203	int8_t				ofdm_tx_pwr_diff;
204	uint16_t			last_rom_addr;
205
206	struct callout			sc_watchdog_ch;
207	struct mtx			sc_mtx;
208
209	struct urtwn_cmdq		cmdq[URTWN_CMDQ_SIZE];
210	struct mtx			cmdq_mtx;
211	struct task			cmdq_task;
212	uint8_t				cmdq_first;
213	uint8_t				cmdq_last;
214
215	uint32_t			rf_chnlbw[R92C_MAX_CHAINS];
216	struct usb_xfer			*sc_xfer[URTWN_N_TRANSFER];
217
218	struct urtwn_rx_radiotap_header	sc_rxtap;
219	struct urtwn_tx_radiotap_header	sc_txtap;
220};
221
222#define	URTWN_LOCK(sc)			mtx_lock(&(sc)->sc_mtx)
223#define	URTWN_UNLOCK(sc)		mtx_unlock(&(sc)->sc_mtx)
224#define	URTWN_ASSERT_LOCKED(sc)		mtx_assert(&(sc)->sc_mtx, MA_OWNED)
225
226#define URTWN_CMDQ_LOCK_INIT(sc) \
227	mtx_init(&(sc)->cmdq_mtx, "cmdq lock", NULL, MTX_DEF)
228#define URTWN_CMDQ_LOCK(sc)		mtx_lock(&(sc)->cmdq_mtx)
229#define URTWN_CMDQ_UNLOCK(sc)		mtx_unlock(&(sc)->cmdq_mtx)
230#define URTWN_CMDQ_LOCK_DESTROY(sc)	mtx_destroy(&(sc)->cmdq_mtx)
231
232#define URTWN_NT_LOCK_INIT(sc) \
233	mtx_init(&(sc)->nt_mtx, "node table lock", NULL, MTX_DEF)
234#define URTWN_NT_LOCK(sc)		mtx_lock(&(sc)->nt_mtx)
235#define URTWN_NT_UNLOCK(sc)		mtx_unlock(&(sc)->nt_mtx)
236#define URTWN_NT_LOCK_DESTROY(sc)	mtx_destroy(&(sc)->nt_mtx)
237