xref: /freebsd/sys/dev/usb/wlan/if_urtwvar.h (revision 9768746b)
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 	uint64_t	wr_tsf;
59 	uint8_t		wr_flags;
60 	uint8_t		wr_pad;
61 	uint16_t	wr_chan_freq;
62 	uint16_t	wr_chan_flags;
63 	int8_t		wr_dbm_antsignal;
64 } __packed __aligned(8);
65 
66 #define URTW_RX_RADIOTAP_PRESENT					\
67 	((1 << IEEE80211_RADIOTAP_TSFT) |				\
68 	 (1 << IEEE80211_RADIOTAP_FLAGS) |				\
69 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
70 	 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL))
71 
72 struct urtw_tx_radiotap_header {
73 	struct ieee80211_radiotap_header wt_ihdr;
74 	uint8_t		wt_flags;
75 	uint8_t		wt_pad;
76 	uint16_t	wt_chan_freq;
77 	uint16_t	wt_chan_flags;
78 } __packed;
79 
80 #define URTW_TX_RADIOTAP_PRESENT					\
81 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
82 	 (1 << IEEE80211_RADIOTAP_CHANNEL))
83 
84 struct urtw_stats {
85 	unsigned			txrates[12];
86 };
87 
88 struct urtw_vap {
89 	struct ieee80211vap		vap;
90 	int				(*newstate)(struct ieee80211vap *,
91 					    enum ieee80211_state, int);
92 };
93 #define	URTW_VAP(vap)	((struct urtw_vap *)(vap))
94 
95 struct urtw_softc {
96 	struct ieee80211com		sc_ic;
97 	struct mbufq			sc_snd;
98 	device_t			sc_dev;
99 	struct usb_device		*sc_udev;
100 	struct mtx			sc_mtx;
101 	void				*sc_tx_dma_buf;
102 
103 	int				sc_debug;
104 	int				sc_flags;
105 #define	URTW_INIT_ONCE			(1 << 1)
106 #define	URTW_RTL8187B			(1 << 2)
107 #define	URTW_RTL8187B_REV_B		(1 << 3)
108 #define	URTW_RTL8187B_REV_D		(1 << 4)
109 #define	URTW_RTL8187B_REV_E		(1 << 5)
110 #define	URTW_DETACHED			(1 << 6)
111 #define	URTW_RUNNING			(1 << 7)
112 	enum ieee80211_state		sc_state;
113 
114 	int				sc_epromtype;
115 #define URTW_EEPROM_93C46		0
116 #define URTW_EEPROM_93C56		1
117 	uint8_t				sc_crcmon;
118 
119 	struct ieee80211_channel	*sc_curchan;
120 
121 	/* for RF  */
122 	usb_error_t			(*sc_rf_init)(struct urtw_softc *);
123 	usb_error_t			(*sc_rf_set_chan)(struct urtw_softc *,
124 					    int);
125 	usb_error_t			(*sc_rf_set_sens)(struct urtw_softc *,
126 					    int);
127 	usb_error_t			(*sc_rf_stop)(struct urtw_softc *);
128 	uint8_t				sc_rfchip;
129 	uint32_t			sc_max_sens;
130 	uint32_t			sc_sens;
131 	/* for LED  */
132 	struct usb_callout		sc_led_ch;
133 	struct task			sc_led_task;
134 	uint8_t				sc_psr;
135 	uint8_t				sc_strategy;
136 #define	URTW_LED_GPIO			1
137 	uint8_t				sc_gpio_ledon;
138 	uint8_t				sc_gpio_ledinprogress;
139 	uint8_t				sc_gpio_ledstate;
140 	uint8_t				sc_gpio_ledpin;
141 	uint8_t				sc_gpio_blinktime;
142 	uint8_t				sc_gpio_blinkstate;
143 	/* RX/TX */
144 	struct usb_xfer		*sc_xfer[URTW_8187B_N_XFERS];
145 #define	URTW_PRIORITY_LOW		0
146 #define	URTW_PRIORITY_NORMAL		1
147 #define URTW_DATA_TIMEOUT		10000		/* 10 sec  */
148 #define	URTW_8187B_TXPIPE_BE		0x6	/* best effort */
149 #define	URTW_8187B_TXPIPE_BK		0x7	/* background */
150 #define	URTW_8187B_TXPIPE_VI		0x5	/* video */
151 #define	URTW_8187B_TXPIPE_VO		0x4	/* voice */
152 #define	URTW_8187B_TXPIPE_MAX		4
153 	struct urtw_data		sc_rx[URTW_RX_DATA_LIST_COUNT];
154 	urtw_datahead			sc_rx_active;
155 	urtw_datahead			sc_rx_inactive;
156 	struct urtw_data		sc_tx[URTW_TX_DATA_LIST_COUNT];
157 	urtw_datahead			sc_tx_active;
158 	urtw_datahead			sc_tx_inactive;
159 	urtw_datahead			sc_tx_pending;
160 	uint8_t				sc_rts_retry;
161 	uint8_t				sc_tx_retry;
162 	uint8_t				sc_preamble_mode;
163 #define	URTW_PREAMBLE_MODE_SHORT	1
164 #define	URTW_PREAMBLE_MODE_LONG		2
165 	struct callout			sc_watchdog_ch;
166 	int				sc_txtimer;
167 	int				sc_currate;
168 	/* TX power  */
169 	uint8_t				sc_txpwr_cck[URTW_MAX_CHANNELS];
170 	uint8_t				sc_txpwr_cck_base;
171 	uint8_t				sc_txpwr_ofdm[URTW_MAX_CHANNELS];
172 	uint8_t				sc_txpwr_ofdm_base;
173 
174 	uint8_t				sc_acmctl;
175 	uint64_t			sc_txstatus;	/* only for 8187B */
176 	struct task			sc_updateslot_task;
177 
178 	struct urtw_stats		sc_stats;
179 
180 	struct	urtw_rx_radiotap_header	sc_rxtap;
181 	struct	urtw_tx_radiotap_header	sc_txtap;
182 };
183 
184 #define URTW_LOCK(sc)			mtx_lock(&(sc)->sc_mtx)
185 #define URTW_UNLOCK(sc)			mtx_unlock(&(sc)->sc_mtx)
186 #define URTW_ASSERT_LOCKED(sc)		mtx_assert(&(sc)->sc_mtx, MA_OWNED)
187