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