xref: /netbsd-src/sys/dev/usb/if_urtwnvar.h (revision 7788a0781fe6ff2cce37368b4578a7ade0850cb1)
1 /*	$NetBSD: if_urtwnvar.h,v 1.6 2013/03/16 15:48:21 skrll Exp $	*/
2 /*	$OpenBSD: if_urtwnreg.h,v 1.3 2010/11/16 18:02:59 damien Exp $	*/
3 
4 /*-
5  * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr>
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 #ifndef _IF_URTWNVAR_H_
20 #define _IF_URTWNVAR_H_
21 
22 /*
23  * Driver definitions.
24  */
25 #define URTWN_RX_LIST_COUNT		1
26 #ifndef URTWN_DOTG_WORKAROUND
27 #define URTWN_TX_LIST_COUNT		8
28 #else
29 #define URTWN_TX_LIST_COUNT		1
30 #endif
31 
32 #define URTWN_HOST_CMD_RING_COUNT	32
33 
34 #define URTWN_RXBUFSZ	(16 * 1024)
35 #define URTWN_TXBUFSZ	(sizeof(struct r92c_tx_desc) + IEEE80211_MAX_LEN + 8)
36 
37 #define URTWN_RIDX_COUNT	28
38 
39 #define URTWN_TX_TIMEOUT	5000	/* ms */
40 
41 #define URTWN_LED_LINK	0
42 #define URTWN_LED_DATA	1
43 
44 struct urtwn_rx_radiotap_header {
45 	struct ieee80211_radiotap_header wr_ihdr;
46 	uint8_t		wr_flags;
47 	uint8_t		wr_rate;
48 	uint16_t	wr_chan_freq;
49 	uint16_t	wr_chan_flags;
50 	uint8_t		wr_dbm_antsignal;
51 } __packed;
52 
53 #define URTWN_RX_RADIOTAP_PRESENT			\
54 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
55 	 1 << IEEE80211_RADIOTAP_RATE |			\
56 	 1 << IEEE80211_RADIOTAP_CHANNEL |		\
57 	 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL)
58 
59 struct urtwn_tx_radiotap_header {
60 	struct ieee80211_radiotap_header wt_ihdr;
61 	uint8_t		wt_flags;
62 	uint16_t	wt_chan_freq;
63 	uint16_t	wt_chan_flags;
64 } __packed;
65 
66 #define URTWN_TX_RADIOTAP_PRESENT			\
67 	(1 << IEEE80211_RADIOTAP_FLAGS |		\
68 	 1 << IEEE80211_RADIOTAP_CHANNEL)
69 
70 struct urtwn_softc;
71 
72 struct urtwn_rx_data {
73 	struct urtwn_softc	*sc;
74 	usbd_xfer_handle	xfer;
75 	uint8_t			*buf;
76 };
77 
78 struct urtwn_tx_data {
79 	struct urtwn_softc		*sc;
80 	usbd_pipe_handle		pipe;
81 	usbd_xfer_handle		xfer;
82 	uint8_t				*buf;
83 	TAILQ_ENTRY(urtwn_tx_data)	next;
84 };
85 
86 struct urtwn_host_cmd {
87 	void	(*cb)(struct urtwn_softc *, void *);
88 	uint8_t	data[256];
89 };
90 
91 struct urtwn_cmd_newstate {
92 	enum ieee80211_state	state;
93 	int			arg;
94 };
95 
96 struct urtwn_host_cmd_ring {
97 	struct urtwn_host_cmd	cmd[URTWN_HOST_CMD_RING_COUNT];
98 	int			cur;
99 	int			next;
100 	int			queued;
101 };
102 
103 #if 1	/* XXX: sys/net80211/ieee80211.h */
104 
105 #define	IEEE80211_HTINFO_2NDCHAN	0x03	/* secondary/ext chan offset */
106 #define	IEEE80211_HTINFO_2NDCHAN_S	0
107 #define	IEEE80211_HTINFO_2NDCHAN_NONE	0x00	/* no secondary/ext channel */
108 #define	IEEE80211_HTINFO_2NDCHAN_ABOVE	0x01	/* above private channel */
109 /* NB: 2 is reserved */
110 #define	IEEE80211_HTINFO_2NDCHAN_BELOW	0x03	/* below primary channel */
111 #endif	/* XXX: 1 */
112 
113 struct urtwn_softc {
114 	device_t			sc_dev;
115 	struct ieee80211com		sc_ic;
116 	struct ethercom			sc_ec;
117 #define sc_if   sc_ec.ec_if
118 	int				(*sc_newstate)(struct ieee80211com *,
119 					    enum ieee80211_state, int);
120 
121 	usbd_device_handle		sc_udev;
122 	usbd_interface_handle		sc_iface;
123 	u_int				sc_flags;
124 #define URTWN_FLAG_CCK_HIPWR	__BIT(0)
125 #define	URTWN_FLAG_ATTACHED	__BIT(1)
126 #define	URTWN_FLAG_FWREADY	__BIT(2)
127 	int				sc_dying;
128 
129 	struct usb_task			sc_task;
130 	callout_t			sc_scan_to;
131 	callout_t			sc_calib_to;
132 
133 	kmutex_t			sc_task_mtx;
134 	kmutex_t			sc_fwcmd_mtx;
135 	kmutex_t			sc_tx_mtx;
136 	kmutex_t			sc_write_mtx;
137 
138 	usbd_pipe_handle		rx_pipe;
139 	int				rx_npipe;
140 	usbd_pipe_handle		tx_pipe[R92C_MAX_EPOUT];
141 	int				tx_npipe;
142 	int				ac2idx[WME_NUM_AC];
143 
144 	u_int				chip;
145 #define URTWN_CHIP_92C		0x01
146 #define URTWN_CHIP_92C_1T2R	0x02
147 #define URTWN_CHIP_UMC		0x04
148 #define URTWN_CHIP_UMC_A_CUT	0x08
149 
150 	uint8_t				board_type;
151 	uint8_t				regulatory;
152 	uint8_t				pa_setting;
153 	int				avg_pwdb;
154 	int				thcal_state;
155 	int				thcal_lctemp;
156 	size_t				ntxchains;
157 	size_t				nrxchains;
158 	int				ledlink;
159 	bool				iqk_inited;
160 
161 	int				tx_timer;
162 
163 	struct urtwn_host_cmd_ring	cmdq;
164 	int				fwcur;
165 	struct urtwn_rx_data		rx_data[URTWN_RX_LIST_COUNT];
166 	struct urtwn_tx_data		tx_data[URTWN_TX_LIST_COUNT];
167 	TAILQ_HEAD(, urtwn_tx_data)	tx_free_list;
168 
169 	struct r92c_rom			rom;
170 
171 	uint32_t			rf_chnlbw[R92C_MAX_CHAINS];
172 
173 	struct bpf_if *			sc_drvbpf;
174 	union {
175 		struct urtwn_rx_radiotap_header th;
176 		uint8_t	pad[64];
177 	}				sc_rxtapu;
178 #define sc_rxtap	sc_rxtapu.th
179 	int				sc_rxtap_len;
180 	union {
181 		struct urtwn_tx_radiotap_header th;
182 		uint8_t	pad[64];
183 	}				sc_txtapu;
184 #define sc_txtap	sc_txtapu.th
185 	int				sc_txtap_len;
186 };
187 
188 #endif /* _IF_URTWNVAR_H_ */
189