xref: /freebsd/sys/dev/iwn/if_iwnvar.h (revision a64729f5077d77e13b9497cb33ecb3c82e606ee8)
1 /*	$OpenBSD: if_iwnvar.h,v 1.18 2010/04/30 16:06:46 damien Exp $	*/
2 
3 /*-
4  * Copyright (c) 2013 Cedric GROSS <cg@cgross.info>
5  * Copyright (c) 2011 Intel Corporation
6  * Copyright (c) 2007, 2008
7  *	Damien Bergamini <damien.bergamini@free.fr>
8  * Copyright (c) 2008 Sam Leffler, Errno Consulting
9  *
10  * Permission to use, copy, modify, and distribute this software for any
11  * purpose with or without fee is hereby granted, provided that the above
12  * copyright notice and this permission notice appear in all copies.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21  */
22 enum iwn_rxon_ctx_id {
23 		IWN_RXON_BSS_CTX,
24 		IWN_RXON_PAN_CTX,
25 		IWN_NUM_RXON_CTX
26 };
27 
28 struct iwn_pan_slot {
29 	uint16_t	time;
30 	uint8_t		type;
31 	uint8_t		reserved;
32 } __packed;
33 
34 struct iwn_pan_params_cmd {
35 	uint16_t flags;
36 #define	IWN_PAN_PARAMS_FLG_SLOTTED_MODE	(1 << 3)
37 
38 	uint8_t reserved;
39 	uint8_t num_slots;
40 	struct iwn_pan_slot slots[10];
41 } __packed;
42 
43 struct iwn_led_mode
44 {
45 	uint8_t		led_cur_mode;
46 	uint64_t	led_cur_bt;
47 	uint64_t	led_last_bt;
48 	uint64_t	led_cur_tpt;
49 	uint64_t	led_last_tpt;
50 	uint64_t	led_bt_diff;
51 	int		led_cur_time;
52 	int		led_last_time;
53 };
54 
55 struct iwn_rx_radiotap_header {
56 	struct ieee80211_radiotap_header wr_ihdr;
57 	uint64_t	wr_tsft;
58 	uint8_t		wr_flags;
59 	uint8_t		wr_rate;
60 	uint16_t	wr_chan_freq;
61 	uint16_t	wr_chan_flags;
62 	int8_t		wr_dbm_antsignal;
63 	int8_t		wr_dbm_antnoise;
64 } __packed __aligned(8);
65 
66 #define IWN_RX_RADIOTAP_PRESENT						\
67 	((1 << IEEE80211_RADIOTAP_TSFT) |				\
68 	 (1 << IEEE80211_RADIOTAP_FLAGS) |				\
69 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
70 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
71 	 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |			\
72 	 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE))
73 
74 struct iwn_tx_radiotap_header {
75 	struct ieee80211_radiotap_header wt_ihdr;
76 	uint8_t		wt_flags;
77 	uint8_t		wt_rate;
78 	uint16_t	wt_chan_freq;
79 	uint16_t	wt_chan_flags;
80 } __packed;
81 
82 #define IWN_TX_RADIOTAP_PRESENT						\
83 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
84 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
85 	 (1 << IEEE80211_RADIOTAP_CHANNEL))
86 
87 struct iwn_dma_info {
88 	bus_dma_tag_t		tag;
89 	bus_dmamap_t		map;
90 	bus_dma_segment_t	seg;
91 	bus_addr_t		paddr;
92 	caddr_t			vaddr;
93 	bus_size_t		size;
94 };
95 
96 struct iwn_tx_data {
97 	bus_dmamap_t		map;
98 	bus_addr_t		cmd_paddr;
99 	bus_addr_t		scratch_paddr;
100 	struct mbuf		*m;
101 	struct ieee80211_node	*ni;
102 	unsigned int		remapped:1;
103 	unsigned int		long_retries:7;
104 #define IWN_LONG_RETRY_FW_OVERFLOW	0x10
105 #define IWN_LONG_RETRY_LIMIT_LOG	7
106 #define IWN_LONG_RETRY_LIMIT		((1 << IWN_LONG_RETRY_LIMIT_LOG) - 3)
107 };
108 
109 struct iwn_tx_ring {
110 	struct iwn_dma_info	desc_dma;
111 	struct iwn_dma_info	cmd_dma;
112 	struct iwn_tx_desc	*desc;
113 	struct iwn_tx_cmd	*cmd;
114 	struct iwn_tx_data	data[IWN_TX_RING_COUNT];
115 	bus_dma_tag_t		data_dmat;
116 	int			qid;
117 	int			queued;
118 	int			cur;
119 	int			read;
120 };
121 
122 struct iwn_softc;
123 
124 struct iwn_rx_data {
125 	struct mbuf	*m;
126 	bus_dmamap_t	map;
127 };
128 
129 struct iwn_rx_ring {
130 	struct iwn_dma_info	desc_dma;
131 	struct iwn_dma_info	stat_dma;
132 	uint32_t		*desc;
133 	struct iwn_rx_status	*stat;
134 	struct iwn_rx_data	data[IWN_RX_RING_COUNT];
135 	bus_dma_tag_t		data_dmat;
136 	int			cur;
137 };
138 
139 struct iwn_node {
140 	struct	ieee80211_node		ni;	/* must be the first */
141 	uint16_t			disable_tid;
142 	uint8_t				id;
143 	struct {
144 		uint64_t		bitmap;
145 		int			short_retries;
146 		int			startidx;
147 	} agg[IEEE80211_TID_SIZE];
148 };
149 
150 struct iwn_calib_state {
151 	uint8_t		state;
152 #define IWN_CALIB_STATE_INIT	0
153 #define IWN_CALIB_STATE_ASSOC	1
154 #define IWN_CALIB_STATE_RUN	2
155 
156 	u_int		nbeacons;
157 	uint32_t	noise[3];
158 	uint32_t	rssi[3];
159 	uint32_t	ofdm_x1;
160 	uint32_t	ofdm_mrc_x1;
161 	uint32_t	ofdm_x4;
162 	uint32_t	ofdm_mrc_x4;
163 	uint32_t	cck_x4;
164 	uint32_t	cck_mrc_x4;
165 	uint32_t	bad_plcp_ofdm;
166 	uint32_t	fa_ofdm;
167 	uint32_t	bad_plcp_cck;
168 	uint32_t	fa_cck;
169 	uint32_t	low_fa;
170 	uint32_t	bad_plcp_ht;
171 	uint8_t		cck_state;
172 #define IWN_CCK_STATE_INIT	0
173 #define IWN_CCK_STATE_LOFA	1
174 #define IWN_CCK_STATE_HIFA	2
175 
176 	uint8_t		noise_samples[20];
177 	u_int		cur_noise_sample;
178 	uint8_t		noise_ref;
179 	uint32_t	energy_samples[10];
180 	u_int		cur_energy_sample;
181 	uint32_t	energy_cck;
182 };
183 
184 struct iwn_calib_info {
185 	uint8_t		*buf;
186 	u_int		len;
187 };
188 
189 struct iwn_fw_part {
190 	const uint8_t	*text;
191 	uint32_t	textsz;
192 	const uint8_t	*data;
193 	uint32_t	datasz;
194 };
195 
196 struct iwn_fw_info {
197 	const uint8_t		*data;
198 	size_t			size;
199 	struct iwn_fw_part	init;
200 	struct iwn_fw_part	main;
201 	struct iwn_fw_part	boot;
202 };
203 
204 struct iwn_ops {
205 	int		(*load_firmware)(struct iwn_softc *);
206 	void		(*read_eeprom)(struct iwn_softc *);
207 	int		(*post_alive)(struct iwn_softc *);
208 	int		(*nic_config)(struct iwn_softc *);
209 	void		(*update_sched)(struct iwn_softc *, int, int, uint8_t,
210 			    uint16_t);
211 	int		(*get_temperature)(struct iwn_softc *);
212 	int		(*get_rssi)(struct iwn_softc *, struct iwn_rx_stat *);
213 	int		(*set_txpower)(struct iwn_softc *, int);
214 	int		(*init_gains)(struct iwn_softc *);
215 	int		(*set_gains)(struct iwn_softc *);
216 	int		(*rxon_assoc)(struct iwn_softc *, int);
217 	int		(*add_node)(struct iwn_softc *, struct iwn_node_info *,
218 			    int);
219 	void		(*tx_done)(struct iwn_softc *, struct iwn_rx_desc *,
220 			    struct iwn_rx_data *);
221 	void		(*ampdu_tx_start)(struct iwn_softc *,
222 			    struct ieee80211_node *, int, uint8_t, uint16_t);
223 	void		(*ampdu_tx_stop)(struct iwn_softc *, int, uint8_t,
224 			    uint16_t);
225 };
226 
227 struct iwn_vap {
228 	struct ieee80211vap	iv_vap;
229 	uint8_t			iv_ridx;
230 
231 	int			(*iv_newstate)(struct ieee80211vap *,
232 				    enum ieee80211_state, int);
233 	int			ctx;
234 	int			beacon_int;
235 
236 };
237 #define	IWN_VAP(_vap)	((struct iwn_vap *)(_vap))
238 
239 struct iwn_softc {
240 	device_t		sc_dev;
241 	int			sc_debug;
242 	struct cdev		*sc_cdev;
243 	struct mtx		sc_mtx;
244 	struct ieee80211com	sc_ic;
245 	struct ieee80211_ratectl_tx_status sc_txs;
246 
247 	u_int			sc_flags;
248 #define IWN_FLAG_HAS_OTPROM	(1 << 1)
249 #define IWN_FLAG_CALIB_DONE	(1 << 2)
250 #define IWN_FLAG_USE_ICT	(1 << 3)
251 #define IWN_FLAG_INTERNAL_PA	(1 << 4)
252 #define IWN_FLAG_HAS_11N	(1 << 6)
253 #define IWN_FLAG_ENH_SENS	(1 << 7)
254 #define IWN_FLAG_ADV_BTCOEX	(1 << 8)
255 #define IWN_FLAG_PAN_SUPPORT	(1 << 9)
256 #define IWN_FLAG_BTCOEX		(1 << 10)
257 #define	IWN_FLAG_RUNNING	(1 << 11)
258 
259 	uint8_t 		hw_type;
260 	/* subdevice_id used to adjust configuration */
261 	uint16_t		subdevice_id;
262 
263 	struct iwn_ops		ops;
264 	const char		*fwname;
265 	const struct iwn_sensitivity_limits
266 				*limits;
267 	int			ntxqs;
268 	int			firstaggqueue;
269 	int			ndmachnls;
270 	uint8_t			broadcast_id;
271 	int			rxonsz;
272 	int			schedsz;
273 	uint32_t		fw_text_maxsz;
274 	uint32_t		fw_data_maxsz;
275 	uint32_t		fwsz;
276 	bus_size_t		sched_txfact_addr;
277 	uint32_t		reset_noise_gain;
278 	uint32_t		noise_gain;
279 
280 	/* TX scheduler rings. */
281 	struct iwn_dma_info	sched_dma;
282 	uint16_t		*sched;
283 	uint32_t		sched_base;
284 
285 	/* "Keep Warm" page. */
286 	struct iwn_dma_info	kw_dma;
287 
288 	/* Firmware image. */
289 	const struct firmware	*fw_fp;
290 
291 	/* Firmware DMA transfer. */
292 	struct iwn_dma_info	fw_dma;
293 
294 	/* ICT table. */
295 	struct iwn_dma_info	ict_dma;
296 	uint32_t		*ict;
297 	int			ict_cur;
298 
299 	/* TX/RX rings. */
300 	struct iwn_tx_ring	txq[IWN5000_NTXQUEUES];
301 	struct iwn_rx_ring	rxq;
302 
303 	struct resource		*mem;
304 	bus_space_tag_t		sc_st;
305 	bus_space_handle_t	sc_sh;
306 	struct resource		*irq;
307 	void 			*sc_ih;
308 	bus_size_t		sc_sz;
309 	int			sc_cap_off;	/* PCIe Capabilities. */
310 
311 	/* Tasks used by the driver */
312 	struct task		sc_rftoggle_task;
313 	struct task		sc_panic_task;
314 	struct task		sc_xmit_task;
315 
316 	/* Taskqueue */
317 	struct taskqueue	*sc_tq;
318 
319 	/* Calibration information */
320 	struct callout		calib_to;
321 	int			calib_cnt;
322 	struct iwn_calib_state	calib;
323 	int			last_calib_ticks;
324 	struct callout		scan_timeout;
325 	struct callout		watchdog_to;
326 	struct iwn_fw_info	fw;
327 	struct iwn_calib_info	calibcmd[IWN5000_PHY_CALIB_MAX_RESULT];
328 	uint32_t		errptr;
329 
330 	struct iwn_rx_stat	last_rx_stat;
331 	int			last_rx_valid;
332 	struct iwn_ucode_info	ucode_info;
333 	struct iwn_rxon		rx_on[IWN_NUM_RXON_CTX];
334 	struct iwn_rxon		*rxon;
335 	int			ctx;
336 	struct ieee80211vap	*ivap[IWN_NUM_RXON_CTX];
337 
338 	/* General statistics */
339 	/*
340 	 * The statistics are reset after each channel
341 	 * change.  So it may be zeroed after things like
342 	 * a background scan.
343 	 *
344 	 * So for now, this is just a cheap hack to
345 	 * expose the last received statistics dump
346 	 * via an ioctl().  Later versions of this
347 	 * could expose the last 'n' messages, or just
348 	 * provide a pipeline for the firmware responses
349 	 * via something like BPF.
350 	 */
351 	struct iwn_stats	last_stat;
352 	int			last_stat_valid;
353 
354 	uint8_t			uc_scan_progress;
355 	uint32_t		rawtemp;
356 	int			temp;
357 	int			noise;
358 	uint32_t		qfullmsk;
359 
360 	uint32_t		prom_base;
361 	struct iwn4965_eeprom_band
362 				bands[IWN_NBANDS];
363 	struct iwn_eeprom_chan	eeprom_channels[IWN_NBANDS][IWN_MAX_CHAN_PER_BAND];
364 	uint16_t		rfcfg;
365 	uint8_t			calib_ver;
366 	char			eeprom_domain[4];
367 	uint32_t		eeprom_crystal;
368 	int16_t			eeprom_temp;
369 	int16_t			eeprom_temp_high;
370 	int16_t			eeprom_voltage;
371 	int8_t			maxpwr2GHz;
372 	int8_t			maxpwr5GHz;
373 	int8_t			maxpwr[IEEE80211_CHAN_MAX];
374 
375 	uint32_t		tlv_feature_flags;
376 
377 	int32_t			temp_off;
378 	uint32_t		int_mask;
379 	uint8_t			ntxchains;
380 	uint8_t			nrxchains;
381 	uint8_t			txchainmask;
382 	uint8_t			rxchainmask;
383 	uint8_t			chainmask;
384 
385 	int			sc_tx_timer;
386 
387 	/* Are we doing a scan? */
388 	int			sc_is_scanning;
389 
390 	/* Are we waiting for a beacon before xmit? */
391 	int			sc_beacon_wait;
392 
393 	struct ieee80211_tx_ampdu *qid2tap[IWN5000_NTXQUEUES];
394 
395 	int			(*sc_ampdu_rx_start)(struct ieee80211_node *,
396 				    struct ieee80211_rx_ampdu *, int, int, int);
397 	void			(*sc_ampdu_rx_stop)(struct ieee80211_node *,
398 				    struct ieee80211_rx_ampdu *);
399 	int			(*sc_addba_request)(struct ieee80211_node *,
400 				    struct ieee80211_tx_ampdu *, int, int, int);
401 	int			(*sc_addba_response)(struct ieee80211_node *,
402 				    struct ieee80211_tx_ampdu *, int, int, int);
403 	void			(*sc_addba_stop)(struct ieee80211_node *,
404 				    struct ieee80211_tx_ampdu *);
405 
406 	struct	iwn_led_mode sc_led;
407 
408 	struct iwn_rx_radiotap_header sc_rxtap;
409 	struct iwn_tx_radiotap_header sc_txtap;
410 
411 	/* The power save level originally configured by user */
412 	int			desired_pwrsave_level;
413 
414 	/*
415 	 * The current power save level, this may differ from the
416 	 * configured value due to thermal throttling etc.
417 	 */
418 	int			current_pwrsave_level;
419 
420 	/* For specific params */
421 	const struct iwn_base_params *base_params;
422 
423 #define	IWN_UCODE_API(ver)	(((ver) & 0x0000FF00) >> 8)
424 	uint32_t		ucode_rev;
425 
426 	/*
427 	 * Global queue for queuing xmit frames
428 	 * when we can't yet transmit (eg raw
429 	 * frames whilst waiting for beacons.)
430 	 */
431 	struct mbufq		sc_xmit_queue;
432 };
433 
434 #define IWN_LOCK_INIT(_sc) \
435 	mtx_init(&(_sc)->sc_mtx, device_get_nameunit((_sc)->sc_dev), \
436 	    MTX_NETWORK_LOCK, MTX_DEF)
437 #define IWN_LOCK(_sc)			mtx_lock(&(_sc)->sc_mtx)
438 #define IWN_LOCK_ASSERT(_sc)		mtx_assert(&(_sc)->sc_mtx, MA_OWNED)
439 #define IWN_UNLOCK(_sc)			mtx_unlock(&(_sc)->sc_mtx)
440 #define IWN_LOCK_DESTROY(_sc)		mtx_destroy(&(_sc)->sc_mtx)
441