summaryrefslogtreecommitdiffstats
path: root/sys/dev/urtwn/if_urtwnvar.h
blob: ba8ca813034420e1728110ef426eb71a6709647a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*-
 * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 * 
 * $OpenBSD: if_urtwnreg.h,v 1.3 2010/11/16 18:02:59 damien Exp $
 * $FreeBSD$
 */

#define URTWN_RX_LIST_COUNT		1
#define URTWN_TX_LIST_COUNT		8
#define URTWN_HOST_CMD_RING_COUNT	32

#define URTWN_RXBUFSZ	(16 * 1024)
#define URTWN_TXBUFSZ	(sizeof(struct r92c_tx_desc) + IEEE80211_MAX_LEN)
#define	URTWN_RX_DESC_SIZE	(sizeof(struct r92c_rx_stat))
#define	URTWN_TX_DESC_SIZE	(sizeof(struct r92c_tx_desc))

#define URTWN_TX_TIMEOUT	5000	/* ms */

#define URTWN_LED_LINK	0
#define URTWN_LED_DATA	1

struct urtwn_rx_radiotap_header {
	struct ieee80211_radiotap_header wr_ihdr;
	uint64_t	wr_tsft;
	uint8_t		wr_flags;
	uint8_t		wr_rate;
	uint16_t	wr_chan_freq;
	uint16_t	wr_chan_flags;
	int8_t		wr_dbm_antsignal;
	int8_t		wr_dbm_antnoise;
} __packed __aligned(8);

#define URTWN_RX_RADIOTAP_PRESENT			\
	(1 << IEEE80211_RADIOTAP_TSFT |			\
	 1 << IEEE80211_RADIOTAP_FLAGS |		\
	 1 << IEEE80211_RADIOTAP_RATE |			\
	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
	 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL |	\
	 1 << IEEE80211_RADIOTAP_DBM_ANTNOISE)

struct urtwn_tx_radiotap_header {
	struct ieee80211_radiotap_header wt_ihdr;
	uint8_t		wt_flags;
	uint16_t	wt_chan_freq;
	uint16_t	wt_chan_flags;
} __packed __aligned(8);

#define URTWN_TX_RADIOTAP_PRESENT			\
	(1 << IEEE80211_RADIOTAP_FLAGS |		\
	 1 << IEEE80211_RADIOTAP_CHANNEL)

struct urtwn_softc;

struct urtwn_data {
	struct urtwn_softc		*sc;
	uint8_t				*buf;
	uint16_t			buflen;
	struct mbuf			*m;
	struct ieee80211_node		*ni;
	STAILQ_ENTRY(urtwn_data)	next;
};
typedef STAILQ_HEAD(, urtwn_data) urtwn_datahead;

union sec_param {
	struct ieee80211_key		key;
};

#define CMD_FUNC_PROTO			void (*func)(struct urtwn_softc *, \
					    union sec_param *)

struct urtwn_cmdq {
	union sec_param			data;
	CMD_FUNC_PROTO;
};
#define URTWN_CMDQ_SIZE			16

struct urtwn_fw_info {
	const uint8_t		*data;
	size_t			size;
};

struct urtwn_node {
	struct ieee80211_node	ni;	/* must be the first */
	uint8_t			id;
};
#define URTWN_NODE(ni)	((struct urtwn_node *)(ni))

struct urtwn_vap {
	struct ieee80211vap	vap;

	struct r92c_tx_desc	bcn_desc;
	struct mbuf		*bcn_mbuf;
	struct task		tsf_task_adhoc;

	int			(*newstate)(struct ieee80211vap *,
				    enum ieee80211_state, int);
	void			(*recv_mgmt)(struct ieee80211_node *,
				    struct mbuf *, int,
				    const struct ieee80211_rx_stats *,
				    int, int);
};
#define	URTWN_VAP(vap)	((struct urtwn_vap *)(vap))

struct urtwn_host_cmd {
	void	(*cb)(struct urtwn_softc *, void *);
	uint8_t	data[256];
};

struct urtwn_cmd_newstate {
	enum ieee80211_state	state;
	int			arg;
};

struct urtwn_cmd_key {
	struct ieee80211_key	key;
	uint16_t		associd;
};

enum {
	URTWN_BULK_RX,
	URTWN_BULK_TX_BE,	/* = WME_AC_BE */
	URTWN_BULK_TX_BK,	/* = WME_AC_BK */
	URTWN_BULK_TX_VI,	/* = WME_AC_VI */
	URTWN_BULK_TX_VO,	/* = WME_AC_VI */
	URTWN_N_TRANSFER = 5,
};

#define	URTWN_EP_QUEUES	URTWN_BULK_RX

union urtwn_rom {
	struct r92c_rom			r92c_rom;
	struct r88e_rom			r88e_rom;
};

struct urtwn_softc {
	struct ieee80211com		sc_ic;
	struct mbufq			sc_snd;
	device_t			sc_dev;
	struct usb_device		*sc_udev;

	uint32_t			sc_debug;
	uint8_t				sc_iface_index;
	uint8_t				sc_flags;
#define URTWN_FLAG_CCK_HIPWR	0x01
#define URTWN_DETACHED		0x02
#define URTWN_RUNNING		0x04
#define URTWN_FW_LOADED		0x08
#define URTWN_TEMP_MEASURED	0x10

	u_int				chip;
#define	URTWN_CHIP_92C		0x01
#define	URTWN_CHIP_92C_1T2R	0x02
#define	URTWN_CHIP_UMC		0x04
#define	URTWN_CHIP_UMC_A_CUT	0x08
#define	URTWN_CHIP_88E		0x10

#define URTWN_CHIP_HAS_RATECTL(_sc)	(!!((_sc)->chip & URTWN_CHIP_88E))

	void				(*sc_node_free)(struct ieee80211_node *);
	void				(*sc_rf_write)(struct urtwn_softc *,
					    int, uint8_t, uint32_t);
	int				(*sc_power_on)(struct urtwn_softc *);
	void				(*sc_power_off)(struct urtwn_softc *);

	struct ieee80211_node		*node_list[R88E_MACID_MAX + 1];
	struct mtx			nt_mtx;

	uint8_t				board_type;
	uint8_t				regulatory;
	uint8_t				pa_setting;
	int8_t				ofdm_tx_pwr_diff;
	int8_t				bw20_tx_pwr_diff;
	int				avg_pwdb;
	uint8_t				thcal_lctemp;
	int				ntxchains;
	int				nrxchains;
	int				ledlink;
	int				sc_txtimer;

	int				fwcur;
	struct urtwn_data		sc_rx[URTWN_RX_LIST_COUNT];
	urtwn_datahead			sc_rx_active;
	urtwn_datahead			sc_rx_inactive;
	struct urtwn_data		sc_tx[URTWN_TX_LIST_COUNT];
	urtwn_datahead			sc_tx_active;
	urtwn_datahead			sc_tx_inactive;
	urtwn_datahead			sc_tx_pending;

	union urtwn_rom			rom;
	uint16_t			last_rom_addr;

	struct callout			sc_calib_to;
	struct callout			sc_watchdog_ch;
	struct mtx			sc_mtx;
	uint32_t			keys_bmap;

	struct urtwn_cmdq		cmdq[URTWN_CMDQ_SIZE];
	struct mtx			cmdq_mtx;
	struct task			cmdq_task;
	uint8_t				cmdq_first;
	uint8_t				cmdq_last;

	uint32_t			rf_chnlbw[R92C_MAX_CHAINS];
	struct usb_xfer			*sc_xfer[URTWN_N_TRANSFER];

	struct urtwn_rx_radiotap_header	sc_rxtap;
	struct urtwn_tx_radiotap_header	sc_txtap;
};

#define	URTWN_LOCK(sc)			mtx_lock(&(sc)->sc_mtx)
#define	URTWN_UNLOCK(sc)		mtx_unlock(&(sc)->sc_mtx)
#define	URTWN_ASSERT_LOCKED(sc)		mtx_assert(&(sc)->sc_mtx, MA_OWNED)

#define URTWN_CMDQ_LOCK_INIT(sc) \
	mtx_init(&(sc)->cmdq_mtx, "cmdq lock", NULL, MTX_DEF)
#define URTWN_CMDQ_LOCK(sc)		mtx_lock(&(sc)->cmdq_mtx)
#define URTWN_CMDQ_UNLOCK(sc)		mtx_unlock(&(sc)->cmdq_mtx)
#define URTWN_CMDQ_LOCK_DESTROY(sc)	mtx_destroy(&(sc)->cmdq_mtx)

#define URTWN_NT_LOCK_INIT(sc) \
	mtx_init(&(sc)->nt_mtx, "node table lock", NULL, MTX_DEF)
#define URTWN_NT_LOCK(sc)		mtx_lock(&(sc)->nt_mtx)
#define URTWN_NT_UNLOCK(sc)		mtx_unlock(&(sc)->nt_mtx)
#define URTWN_NT_LOCK_DESTROY(sc)	mtx_destroy(&(sc)->nt_mtx)
OpenPOWER on IntegriCloud