if_urtwvar.h revision 192984
1285SN/A/*	$FreeBSD: head/sys/dev/usb/wlan/if_urtwvar.h 192984 2009-05-28 17:36:36Z thompsa $	*/
2462SN/A
3285SN/A/*-
4285SN/A * Copyright (c) 2008 Weongyo Jeong <weongyo@FreeBSD.org>
5285SN/A *
6285SN/A * Permission to use, copy, modify, and distribute this software for any
7285SN/A * purpose with or without fee is hereby granted, provided that the above
8285SN/A * copyright notice and this permission notice appear in all copies.
9285SN/A *
10285SN/A * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11285SN/A * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12285SN/A * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13285SN/A * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14285SN/A * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15285SN/A * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16285SN/A * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17285SN/A */
18285SN/A
19285SN/Aenum {
20285SN/A	URTW_8187B_BULK_RX,
21285SN/A	URTW_8187B_BULK_TX_BE,
22285SN/A	URTW_8187B_BULK_TX_BK,
23285SN/A	URTW_8187B_BULK_TX_VI,
24285SN/A	URTW_8187B_BULK_TX_VO,
25285SN/A	URTW_8187B_BULK_TX_EP12,
26285SN/A	URTW_8187B_N_XFERS = 6
27285SN/A};
28396SN/A
29396SN/Aenum {
30396SN/A	URTW_8187L_BULK_RX,
31396SN/A	URTW_8187L_BULK_TX_LOW,
32285SN/A	URTW_8187L_BULK_TX_NORMAL,
33285SN/A	URTW_8187L_N_XFERS = 3
34285SN/A};
35285SN/A
36285SN/A/* XXX no definition at net80211?  */
37285SN/A#define URTW_MAX_CHANNELS		15
38285SN/A
39285SN/Astruct urtw_data {
40285SN/A	struct urtw_softc	*sc;
41285SN/A	uint8_t			*buf;
42285SN/A	uint16_t		buflen;
43285SN/A	struct mbuf		*m;
44285SN/A	struct ieee80211_node	*ni;		/* NB: tx only */
45285SN/A	STAILQ_ENTRY(urtw_data)	next;
46285SN/A};
47285SN/Atypedef STAILQ_HEAD(, urtw_data) urtw_datahead;
48285SN/A
49285SN/A/* XXX not correct..  */
50285SN/A#define	URTW_MIN_RXBUFSZ						\
51285SN/A	(sizeof(struct ieee80211_frame_min))
52285SN/A
53285SN/A#define URTW_RX_DATA_LIST_COUNT		4
54285SN/A#define URTW_TX_DATA_LIST_COUNT		16
55285SN/A#define URTW_RX_MAXSIZE			0x9c4
56285SN/A#define URTW_TX_MAXSIZE			0x9c4
57285SN/A
58285SN/Astruct urtw_rx_radiotap_header {
59285SN/A	struct ieee80211_radiotap_header wr_ihdr;
60285SN/A	uint8_t		wr_flags;
61285SN/A	uint16_t	wr_chan_freq;
62285SN/A	uint16_t	wr_chan_flags;
63285SN/A	int8_t		wr_dbm_antsignal;
64285SN/A} __packed;
65285SN/A
66285SN/A#define URTW_RX_RADIOTAP_PRESENT					\
67285SN/A	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
68285SN/A	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
69285SN/A	 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL))
70285SN/A
71285SN/Astruct urtw_tx_radiotap_header {
72285SN/A	struct ieee80211_radiotap_header wt_ihdr;
73285SN/A	uint8_t		wt_flags;
74285SN/A	uint16_t	wt_chan_freq;
75285SN/A	uint16_t	wt_chan_flags;
76285SN/A} __packed;
77
78#define URTW_TX_RADIOTAP_PRESENT					\
79	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
80	 (1 << IEEE80211_RADIOTAP_CHANNEL))
81
82struct urtw_vap {
83	struct ieee80211vap		vap;
84	int				(*newstate)(struct ieee80211vap *,
85					    enum ieee80211_state, int);
86};
87#define	URTW_VAP(vap)	((struct urtw_vap *)(vap))
88
89struct urtw_softc {
90	struct ifnet			*sc_ifp;
91	device_t			sc_dev;
92	struct usb_device		*sc_udev;
93	struct mtx			sc_mtx;
94
95	int				sc_debug;
96	int				sc_if_flags;
97	int				sc_flags;
98#define	URTW_INIT_ONCE			(1 << 1)
99#define	URTW_RTL8187B			(1 << 2)
100#define	URTW_RTL8187B_REV_B		(1 << 3)
101#define	URTW_RTL8187B_REV_D		(1 << 4)
102#define	URTW_RTL8187B_REV_E		(1 << 5)
103	enum ieee80211_state		sc_state;
104
105	int				sc_epromtype;
106#define URTW_EEPROM_93C46		0
107#define URTW_EEPROM_93C56		1
108	uint8_t				sc_crcmon;
109	uint8_t				sc_bssid[IEEE80211_ADDR_LEN];
110
111	struct ieee80211_channel	*sc_curchan;
112
113	/* for RF  */
114	usb2_error_t			(*sc_rf_init)(struct urtw_softc *);
115	usb2_error_t			(*sc_rf_set_chan)(struct urtw_softc *,
116					    int);
117	usb2_error_t			(*sc_rf_set_sens)(struct urtw_softc *,
118					    int);
119	usb2_error_t			(*sc_rf_stop)(struct urtw_softc *);
120	uint8_t				sc_rfchip;
121	uint32_t			sc_max_sens;
122	uint32_t			sc_sens;
123	/* for LED  */
124	struct usb_callout		sc_led_ch;
125	struct task			sc_led_task;
126	uint8_t				sc_psr;
127	uint8_t				sc_strategy;
128#define	URTW_LED_GPIO			1
129	uint8_t				sc_gpio_ledon;
130	uint8_t				sc_gpio_ledinprogress;
131	uint8_t				sc_gpio_ledstate;
132	uint8_t				sc_gpio_ledpin;
133	uint8_t				sc_gpio_blinktime;
134	uint8_t				sc_gpio_blinkstate;
135	/* RX/TX */
136	struct usb_xfer		*sc_xfer[URTW_8187B_N_XFERS];
137#define	URTW_PRIORITY_LOW		0
138#define	URTW_PRIORITY_NORMAL		1
139#define URTW_DATA_TIMEOUT		10000		/* 10 sec  */
140#define	URTW_8187B_TXPIPE_BE		0x6	/* best effort */
141#define	URTW_8187B_TXPIPE_BK		0x7	/* background */
142#define	URTW_8187B_TXPIPE_VI		0x5	/* video */
143#define	URTW_8187B_TXPIPE_VO		0x4	/* voice */
144#define	URTW_8187B_TXPIPE_MAX		4
145	struct urtw_data		sc_rx[URTW_RX_DATA_LIST_COUNT];
146	urtw_datahead			sc_rx_active;
147	urtw_datahead			sc_rx_inactive;
148	struct urtw_data		sc_tx[URTW_TX_DATA_LIST_COUNT];
149	urtw_datahead			sc_tx_active;
150	urtw_datahead			sc_tx_inactive;
151	urtw_datahead			sc_tx_pending;
152	uint8_t				sc_rts_retry;
153	uint8_t				sc_tx_retry;
154	uint8_t				sc_preamble_mode;
155#define	URTW_PREAMBLE_MODE_SHORT	1
156#define	URTW_PREAMBLE_MODE_LONG		2
157	struct callout			sc_watchdog_ch;
158	int				sc_txtimer;
159	int				sc_currate;
160	/* TX power  */
161	uint8_t				sc_txpwr_cck[URTW_MAX_CHANNELS];
162	uint8_t				sc_txpwr_cck_base;
163	uint8_t				sc_txpwr_ofdm[URTW_MAX_CHANNELS];
164	uint8_t				sc_txpwr_ofdm_base;
165
166	struct	urtw_rx_radiotap_header	sc_rxtap;
167	int				sc_rxtap_len;
168	struct	urtw_tx_radiotap_header	sc_txtap;
169	int				sc_txtap_len;
170};
171
172#define URTW_LOCK(sc)			mtx_lock(&(sc)->sc_mtx)
173#define URTW_UNLOCK(sc)			mtx_unlock(&(sc)->sc_mtx)
174#define URTW_ASSERT_LOCKED(sc)		mtx_assert(&(sc)->sc_mtx, MA_OWNED)
175