xref: /freebsd/sys/dev/usb/wlan/if_urtwvar.h (revision 0957b409)
1 /*	$FreeBSD$	*/
2 
3 /*-
4  * Copyright (c) 2008 Weongyo Jeong <weongyo@FreeBSD.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 enum {
20 	URTW_8187B_BULK_RX,
21 	URTW_8187B_BULK_TX_STATUS,
22 	URTW_8187B_BULK_TX_BE,
23 	URTW_8187B_BULK_TX_BK,
24 	URTW_8187B_BULK_TX_VI,
25 	URTW_8187B_BULK_TX_VO,
26 	URTW_8187B_BULK_TX_EP12,
27 	URTW_8187B_N_XFERS = 7
28 };
29 
30 enum {
31 	URTW_8187L_BULK_RX,
32 	URTW_8187L_BULK_TX_LOW,
33 	URTW_8187L_BULK_TX_NORMAL,
34 	URTW_8187L_N_XFERS = 3
35 };
36 
37 /* XXX no definition at net80211?  */
38 #define URTW_MAX_CHANNELS		15
39 
40 struct urtw_data {
41 	struct urtw_softc	*sc;
42 	uint8_t			*buf;
43 	uint16_t		buflen;
44 	struct mbuf		*m;
45 	struct ieee80211_node	*ni;		/* NB: tx only */
46 	STAILQ_ENTRY(urtw_data)	next;
47 };
48 typedef STAILQ_HEAD(, urtw_data) urtw_datahead;
49 
50 #define URTW_RX_DATA_LIST_COUNT		4
51 #define URTW_TX_DATA_LIST_COUNT		16
52 #define URTW_RX_MAXSIZE			0x9c4
53 #define URTW_TX_MAXSIZE			0x9c4
54 #define	URTW_TX_MAXRETRY		11
55 
56 struct urtw_rx_radiotap_header {
57 	struct ieee80211_radiotap_header wr_ihdr;
58 	uint8_t		wr_flags;
59 	uint16_t	wr_chan_freq;
60 	uint16_t	wr_chan_flags;
61 	int8_t		wr_dbm_antsignal;
62 } __packed __aligned(8);
63 
64 #define URTW_RX_RADIOTAP_PRESENT					\
65 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
66 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
67 	 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL))
68 
69 struct urtw_tx_radiotap_header {
70 	struct ieee80211_radiotap_header wt_ihdr;
71 	uint8_t		wt_flags;
72 	uint16_t	wt_chan_freq;
73 	uint16_t	wt_chan_flags;
74 } __packed __aligned(8);
75 
76 #define URTW_TX_RADIOTAP_PRESENT					\
77 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
78 	 (1 << IEEE80211_RADIOTAP_CHANNEL))
79 
80 struct urtw_stats {
81 	unsigned int			txrates[12];
82 };
83 
84 struct urtw_vap {
85 	struct ieee80211vap		vap;
86 	int				(*newstate)(struct ieee80211vap *,
87 					    enum ieee80211_state, int);
88 };
89 #define	URTW_VAP(vap)	((struct urtw_vap *)(vap))
90 
91 struct urtw_softc {
92 	struct ieee80211com		sc_ic;
93 	struct mbufq			sc_snd;
94 	device_t			sc_dev;
95 	struct usb_device		*sc_udev;
96 	struct mtx			sc_mtx;
97 	void				*sc_tx_dma_buf;
98 
99 	int				sc_debug;
100 	int				sc_flags;
101 #define	URTW_INIT_ONCE			(1 << 1)
102 #define	URTW_RTL8187B			(1 << 2)
103 #define	URTW_RTL8187B_REV_B		(1 << 3)
104 #define	URTW_RTL8187B_REV_D		(1 << 4)
105 #define	URTW_RTL8187B_REV_E		(1 << 5)
106 #define	URTW_DETACHED			(1 << 6)
107 #define	URTW_RUNNING			(1 << 7)
108 	enum ieee80211_state		sc_state;
109 
110 	int				sc_epromtype;
111 #define URTW_EEPROM_93C46		0
112 #define URTW_EEPROM_93C56		1
113 	uint8_t				sc_crcmon;
114 
115 	struct ieee80211_channel	*sc_curchan;
116 
117 	/* for RF  */
118 	usb_error_t			(*sc_rf_init)(struct urtw_softc *);
119 	usb_error_t			(*sc_rf_set_chan)(struct urtw_softc *,
120 					    int);
121 	usb_error_t			(*sc_rf_set_sens)(struct urtw_softc *,
122 					    int);
123 	usb_error_t			(*sc_rf_stop)(struct urtw_softc *);
124 	uint8_t				sc_rfchip;
125 	uint32_t			sc_max_sens;
126 	uint32_t			sc_sens;
127 	/* for LED  */
128 	struct usb_callout		sc_led_ch;
129 	struct task			sc_led_task;
130 	uint8_t				sc_psr;
131 	uint8_t				sc_strategy;
132 #define	URTW_LED_GPIO			1
133 	uint8_t				sc_gpio_ledon;
134 	uint8_t				sc_gpio_ledinprogress;
135 	uint8_t				sc_gpio_ledstate;
136 	uint8_t				sc_gpio_ledpin;
137 	uint8_t				sc_gpio_blinktime;
138 	uint8_t				sc_gpio_blinkstate;
139 	/* RX/TX */
140 	struct usb_xfer		*sc_xfer[URTW_8187B_N_XFERS];
141 #define	URTW_PRIORITY_LOW		0
142 #define	URTW_PRIORITY_NORMAL		1
143 #define URTW_DATA_TIMEOUT		10000		/* 10 sec  */
144 #define	URTW_8187B_TXPIPE_BE		0x6	/* best effort */
145 #define	URTW_8187B_TXPIPE_BK		0x7	/* background */
146 #define	URTW_8187B_TXPIPE_VI		0x5	/* video */
147 #define	URTW_8187B_TXPIPE_VO		0x4	/* voice */
148 #define	URTW_8187B_TXPIPE_MAX		4
149 	struct urtw_data		sc_rx[URTW_RX_DATA_LIST_COUNT];
150 	urtw_datahead			sc_rx_active;
151 	urtw_datahead			sc_rx_inactive;
152 	struct urtw_data		sc_tx[URTW_TX_DATA_LIST_COUNT];
153 	urtw_datahead			sc_tx_active;
154 	urtw_datahead			sc_tx_inactive;
155 	urtw_datahead			sc_tx_pending;
156 	uint8_t				sc_rts_retry;
157 	uint8_t				sc_tx_retry;
158 	uint8_t				sc_preamble_mode;
159 #define	URTW_PREAMBLE_MODE_SHORT	1
160 #define	URTW_PREAMBLE_MODE_LONG		2
161 	struct callout			sc_watchdog_ch;
162 	int				sc_txtimer;
163 	int				sc_currate;
164 	/* TX power  */
165 	uint8_t				sc_txpwr_cck[URTW_MAX_CHANNELS];
166 	uint8_t				sc_txpwr_cck_base;
167 	uint8_t				sc_txpwr_ofdm[URTW_MAX_CHANNELS];
168 	uint8_t				sc_txpwr_ofdm_base;
169 
170 	uint8_t				sc_acmctl;
171 	uint64_t			sc_txstatus;	/* only for 8187B */
172 	struct task			sc_updateslot_task;
173 
174 	struct urtw_stats		sc_stats;
175 
176 	struct	urtw_rx_radiotap_header	sc_rxtap;
177 	struct	urtw_tx_radiotap_header	sc_txtap;
178 };
179 
180 #define URTW_LOCK(sc)			mtx_lock(&(sc)->sc_mtx)
181 #define URTW_UNLOCK(sc)			mtx_unlock(&(sc)->sc_mtx)
182 #define URTW_ASSERT_LOCKED(sc)		mtx_assert(&(sc)->sc_mtx, MA_OWNED)
183