xref: /dragonfly/sys/dev/netif/iwn/if_iwnvar.h (revision e0ecab34)
1 /*	$FreeBSD$	*/
2 /*	$OpenBSD: if_iwnvar.h,v 1.17 2010/02/17 18:23:00 damien Exp $	*/
3 
4 /*-
5  * Copyright (c) 2007, 2008
6  *	Damien Bergamini <damien.bergamini@free.fr>
7  * Copyright (c) 2008 Sam Leffler, Errno Consulting
8  *
9  * Permission to use, copy, modify, and distribute this software for any
10  * purpose with or without fee is hereby granted, provided that the above
11  * copyright notice and this permission notice appear in all copies.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20  */
21 
22 #include <netproto/802_11/ieee80211_amrr.h>
23 
24 struct iwn_rx_radiotap_header {
25 	struct ieee80211_radiotap_header wr_ihdr;
26 	uint64_t	wr_tsft;
27 	uint8_t		wr_flags;
28 	uint8_t		wr_rate;
29 	uint16_t	wr_chan_freq;
30 	uint16_t	wr_chan_flags;
31 	int8_t		wr_dbm_antsignal;
32 	int8_t		wr_dbm_antnoise;
33 } __packed;
34 
35 #define IWN_RX_RADIOTAP_PRESENT						\
36 	((1 << IEEE80211_RADIOTAP_TSFT) |				\
37 	 (1 << IEEE80211_RADIOTAP_FLAGS) |				\
38 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
39 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
40 	 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |			\
41 	 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE))
42 
43 struct iwn_tx_radiotap_header {
44 	struct ieee80211_radiotap_header wt_ihdr;
45 	uint8_t		wt_flags;
46 	uint8_t		wt_rate;
47 	uint16_t	wt_chan_freq;
48 	uint16_t	wt_chan_flags;
49 } __packed;
50 
51 #define IWN_TX_RADIOTAP_PRESENT						\
52 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
53 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
54 	 (1 << IEEE80211_RADIOTAP_CHANNEL))
55 
56 struct iwn_dma_info {
57 	bus_dma_tag_t		tag;
58 	bus_dmamap_t		map;
59 	bus_dma_segment_t	seg;
60 	bus_addr_t		paddr;
61 	caddr_t			vaddr;
62 	bus_size_t		size;
63 };
64 
65 struct iwn_tx_data {
66 	bus_dmamap_t		map;
67 	bus_addr_t		cmd_paddr;
68 	bus_addr_t		scratch_paddr;
69 	struct mbuf		*m;
70 	struct ieee80211_node	*ni;
71 };
72 
73 struct iwn_tx_ring {
74 	struct iwn_dma_info	desc_dma;
75 	struct iwn_dma_info	cmd_dma;
76 	struct iwn_tx_desc	*desc;
77 	struct iwn_tx_cmd	*cmd;
78 	struct iwn_tx_data	data[IWN_TX_RING_COUNT];
79 	bus_dma_tag_t		data_dmat;
80 	int			qid;
81 	int			queued;
82 	int			cur;
83 };
84 
85 struct iwn_amrr {
86 	struct	ieee80211_node ni;	/* must be the first */
87 	int	txcnt;
88 	int	retrycnt;
89 	int	success;
90 	int	success_threshold;
91 	int	recovery;
92 };
93 
94 struct iwn_softc;
95 
96 struct iwn_rx_data {
97 	struct mbuf	*m;
98 	bus_dmamap_t	map;
99 };
100 
101 struct iwn_rx_ring {
102 	struct iwn_dma_info	desc_dma;
103 	struct iwn_dma_info	stat_dma;
104 	uint32_t		*desc;
105 	struct iwn_rx_status	*stat;
106 	struct iwn_rx_data	data[IWN_RX_RING_COUNT];
107 	bus_dma_tag_t		data_dmat;
108 	int			cur;
109 };
110 
111 struct iwn_node {
112 	struct	ieee80211_node		ni;	/* must be the first */
113 	uint16_t			disable_tid;
114 	uint8_t				id;
115 	uint8_t				ridx[IEEE80211_RATE_MAXSIZE];
116 	struct	ieee80211_amrr_node	amn;
117 };
118 
119 struct iwn_calib_state {
120 	uint8_t		state;
121 #define IWN_CALIB_STATE_INIT	0
122 #define IWN_CALIB_STATE_ASSOC	1
123 #define IWN_CALIB_STATE_RUN	2
124 
125 	u_int		nbeacons;
126 	uint32_t	noise[3];
127 	uint32_t	rssi[3];
128 	uint32_t	ofdm_x1;
129 	uint32_t	ofdm_mrc_x1;
130 	uint32_t	ofdm_x4;
131 	uint32_t	ofdm_mrc_x4;
132 	uint32_t	cck_x4;
133 	uint32_t	cck_mrc_x4;
134 	uint32_t	bad_plcp_ofdm;
135 	uint32_t	fa_ofdm;
136 	uint32_t	bad_plcp_cck;
137 	uint32_t	fa_cck;
138 	uint32_t	low_fa;
139 	uint8_t		cck_state;
140 #define IWN_CCK_STATE_INIT	0
141 #define IWN_CCK_STATE_LOFA	1
142 #define IWN_CCK_STATE_HIFA	2
143 
144 	uint8_t		noise_samples[20];
145 	u_int		cur_noise_sample;
146 	uint8_t		noise_ref;
147 	uint32_t	energy_samples[10];
148 	u_int		cur_energy_sample;
149 	uint32_t	energy_cck;
150 };
151 
152 struct iwn_calib_info {
153 	uint8_t		*buf;
154 	u_int		len;
155 };
156 
157 struct iwn_fw_part {
158 	const uint8_t	*text;
159 	uint32_t	textsz;
160 	const uint8_t	*data;
161 	uint32_t	datasz;
162 };
163 
164 struct iwn_fw_info {
165 	u_char			*data;
166 	struct iwn_fw_part	init;
167 	struct iwn_fw_part	main;
168 	struct iwn_fw_part	boot;
169 };
170 
171 struct iwn_hal {
172 	int		(*load_firmware)(struct iwn_softc *);
173 	void		(*read_eeprom)(struct iwn_softc *);
174 	int		(*post_alive)(struct iwn_softc *);
175 	int		(*nic_config)(struct iwn_softc *);
176 	void		(*update_sched)(struct iwn_softc *, int, int, uint8_t,
177 			    uint16_t);
178 	int		(*get_temperature)(struct iwn_softc *);
179 	int		(*get_rssi)(struct iwn_softc *, struct iwn_rx_stat *);
180 	int		(*set_txpower)(struct iwn_softc *,
181 			    struct ieee80211_channel *, int);
182 	int		(*init_gains)(struct iwn_softc *);
183 	int		(*set_gains)(struct iwn_softc *);
184 	int		(*add_node)(struct iwn_softc *, struct iwn_node_info *,
185 			    int);
186 	void		(*tx_done)(struct iwn_softc *, struct iwn_rx_desc *,
187 			    struct iwn_rx_data *);
188 #if 0	/* HT */
189 	void		(*ampdu_tx_start)(struct iwn_softc *,
190 			    struct ieee80211_node *, uint8_t, uint16_t);
191 	void		(*ampdu_tx_stop)(struct iwn_softc *, uint8_t,
192 			    uint16_t);
193 #endif
194 	int		ntxqs;
195 	int		ndmachnls;
196 	uint8_t		broadcast_id;
197 	int		rxonsz;
198 	int		schedsz;
199 	uint32_t	fw_text_maxsz;
200 	uint32_t	fw_data_maxsz;
201 	uint32_t	fwsz;
202 	bus_size_t	sched_txfact_addr;
203 };
204 
205 struct iwn_vap {
206 	struct ieee80211vap	iv_vap;
207 	uint8_t			iv_ridx;
208 
209 	int			(*iv_newstate)(struct ieee80211vap *,
210 				    enum ieee80211_state, int);
211 	struct ieee80211_amrr	iv_amrr;
212 };
213 #define	IWN_VAP(_vap)	((struct iwn_vap *)(_vap))
214 
215 struct iwn_softc {
216 	struct arpcom           arpcom;
217 	struct ifnet		*sc_ifp;
218 	int			sc_debug;
219 
220 	/* Locks */
221 	struct mtx		sc_mtx;
222 	struct lock		sc_lock;
223 
224 	/* Bus */
225 	device_t 		sc_dev;
226 	int			mem_rid;
227 	int			irq_rid;
228 	struct resource 	*mem;
229 	struct resource		*irq;
230 	bus_dma_tag_t		sc_dmat;
231 
232 	u_int			sc_flags;
233 #define IWN_FLAG_HAS_5GHZ	(1 << 0)
234 #define IWN_FLAG_HAS_OTPROM	(1 << 1)
235 #define IWN_FLAG_CALIB_DONE	(1 << 2)
236 #define IWN_FLAG_USE_ICT	(1 << 3)
237 #define IWN_FLAG_INTERNAL_PA	(1 << 4)
238 
239 	uint8_t 		hw_type;
240 	const struct iwn_hal	*sc_hal;
241 	const char		*fwname;
242 	const struct iwn_sensitivity_limits
243 				*limits;
244 
245 	/* TX scheduler rings. */
246 	struct iwn_dma_info	sched_dma;
247 	uint16_t		*sched;
248 	uint32_t		sched_base;
249 
250 	/* "Keep Warm" page. */
251 	struct iwn_dma_info	kw_dma;
252 
253 	/* Firmware image. */
254 	const struct firmware	*fw_fp;
255 
256 	/* Firmware DMA transfer. */
257 	struct iwn_dma_info	fw_dma;
258 
259 	/* ICT table. */
260 	struct iwn_dma_info	ict_dma;
261 	uint32_t		*ict;
262 	int			ict_cur;
263 
264 	/* TX/RX rings. */
265 	struct iwn_tx_ring	txq[IWN5000_NTXQUEUES];
266 	struct iwn_rx_ring	rxq;
267 
268 	bus_space_tag_t		sc_st;
269 	bus_space_handle_t	sc_sh;
270 	void 			*sc_ih;
271 	bus_size_t		sc_sz;
272 	int			sc_cap_off;	/* PCIe Capabilities. */
273 
274 	/* Tasks used by the driver */
275 	struct task             sc_reinit_task;
276 	struct task		sc_radioon_task;
277 	struct task		sc_radiooff_task;
278 
279 	int			calib_cnt;
280 	struct iwn_calib_state	calib;
281 
282 	struct iwn_fw_info	fw;
283 	struct iwn_calib_info	calibcmd[5];
284 	uint32_t		errptr;
285 
286 	struct iwn_rx_stat	last_rx_stat;
287 	int			last_rx_valid;
288 	struct iwn_ucode_info	ucode_info;
289 	struct iwn_rxon		rxon;
290 	uint32_t		rawtemp;
291 	int			temp;
292 	int			noise;
293 	uint32_t		qfullmsk;
294 
295 	uint32_t		prom_base;
296 	struct iwn4965_eeprom_band
297 				bands[IWN_NBANDS];
298 	struct iwn_eeprom_chan	eeprom_channels[IWN_NBANDS][IWN_MAX_CHAN_PER_BAND];
299 	uint16_t		rfcfg;
300 	uint8_t			calib_ver;
301 	char			eeprom_domain[4];
302 	uint32_t		eeprom_crystal;
303 	int16_t			eeprom_voltage;
304 	int8_t			maxpwr2GHz;
305 	int8_t			maxpwr5GHz;
306 	int8_t			maxpwr[IEEE80211_CHAN_MAX];
307 	int8_t			enh_maxpwr[35];
308 
309 	int32_t			temp_off;
310 	uint32_t		int_mask;
311 	uint8_t			ntxchains;
312 	uint8_t			nrxchains;
313 	uint8_t			txchainmask;
314 	uint8_t			rxchainmask;
315 	uint8_t			chainmask;
316 
317 	struct callout		sc_timer_to;
318 	int			sc_tx_timer;
319 
320 	struct iwn_rx_radiotap_header sc_rxtap;
321 	struct iwn_tx_radiotap_header sc_txtap;
322 
323 	struct sysctl_ctx_list	sc_sysctl_ctx;
324 	struct sysctl_oid	*sc_sysctl_tree;
325 };
326 
327 #if 0
328 #define IWN_LOCK_INIT(_sc)
329 #define IWN_LOCK(_sc)			lwkt_serialize_enter((_sc)->sc_ifp->if_serializer)
330 #define IWN_LOCK_ASSERT(_sc)		ASSERT_SERIALIZED((_sc)->sc_ifp->if_serializer)
331 #define IWN_UNLOCK(_sc)			lwkt_serialize_exit((_sc)->sc_ifp->if_serializer)
332 #define IWN_LOCK_DESTROY(_sc)
333 
334 #define IWN_LOCK_INIT(_sc) \
335 	lockinit(&(_sc)->sc_lock, \
336 		__DECONST(char *, device_get_nameunit((_sc)->sc_dev)), \
337 		0, LK_CANRECURSE)
338 #define IWN_LOCK(_sc)			lockmgr(&(_sc)->sc_lock, LK_EXCLUSIVE)
339 #define IWN_LOCK_ASSERT(_sc)		KKASSERT(lockstatus(&(sc)->sc_lock, curthread)  != 0)
340 #define IWN_UNLOCK(_sc)			lockmgr(&(_sc)->sc_lock, LK_RELEASE)
341 #define IWN_LOCK_DESTROY(_sc)		lockuninit(&(_sc)->sc_lock)
342 #endif
343 
344 #define IWN_LOCK_INIT(_sc)
345 #define IWN_LOCK(_sc) lwkt_gettoken(&wlan_token)
346 #define IWN_UNLOCK(_sc) lwkt_reltoken(&wlan_token)
347 #define IWN_LOCK_DESTROY(_sc)
348 #define IWN_LOCK_ASSERT(_sc) ASSERT_LWKT_TOKEN_HELD(&wlan_token)
349