xref: /freebsd/sys/dev/iwm/if_iwmvar.h (revision bda54b8f964b4035dcf5aba394d14ed24370a6f2)
1 /*	$OpenBSD: if_iwmvar.h,v 1.7 2015/03/02 13:51:10 jsg Exp $	*/
2 /*	$FreeBSD$ */
3 
4 /*
5  * Copyright (c) 2014 genua mbh <info@genua.de>
6  * Copyright (c) 2014 Fixup Software Ltd.
7  *
8  * Permission to use, copy, modify, and distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 /*-
22  * Based on BSD-licensed source modules in the Linux iwlwifi driver,
23  * which were used as the reference documentation for this implementation.
24  *
25  * Driver version we are currently based off of is
26  * Linux 3.14.3 (tag id a2df521e42b1d9a23f620ac79dbfe8655a8391dd)
27  *
28  ***********************************************************************
29  *
30  * This file is provided under a dual BSD/GPLv2 license.  When using or
31  * redistributing this file, you may do so under either license.
32  *
33  * GPL LICENSE SUMMARY
34  *
35  * Copyright(c) 2007 - 2013 Intel Corporation. All rights reserved.
36  *
37  * This program is free software; you can redistribute it and/or modify
38  * it under the terms of version 2 of the GNU General Public License as
39  * published by the Free Software Foundation.
40  *
41  * This program is distributed in the hope that it will be useful, but
42  * WITHOUT ANY WARRANTY; without even the implied warranty of
43  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
44  * General Public License for more details.
45  *
46  * You should have received a copy of the GNU General Public License
47  * along with this program; if not, write to the Free Software
48  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
49  * USA
50  *
51  * The full GNU General Public License is included in this distribution
52  * in the file called COPYING.
53  *
54  * Contact Information:
55  *  Intel Linux Wireless <ilw@linux.intel.com>
56  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
57  *
58  *
59  * BSD LICENSE
60  *
61  * Copyright(c) 2005 - 2013 Intel Corporation. All rights reserved.
62  * All rights reserved.
63  *
64  * Redistribution and use in source and binary forms, with or without
65  * modification, are permitted provided that the following conditions
66  * are met:
67  *
68  *  * Redistributions of source code must retain the above copyright
69  *    notice, this list of conditions and the following disclaimer.
70  *  * Redistributions in binary form must reproduce the above copyright
71  *    notice, this list of conditions and the following disclaimer in
72  *    the documentation and/or other materials provided with the
73  *    distribution.
74  *  * Neither the name Intel Corporation nor the names of its
75  *    contributors may be used to endorse or promote products derived
76  *    from this software without specific prior written permission.
77  *
78  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
79  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
80  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
81  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
82  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
83  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
84  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
85  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
86  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
87  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
88  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
89  */
90 
91 /*-
92  * Copyright (c) 2007-2010 Damien Bergamini <damien.bergamini@free.fr>
93  *
94  * Permission to use, copy, modify, and distribute this software for any
95  * purpose with or without fee is hereby granted, provided that the above
96  * copyright notice and this permission notice appear in all copies.
97  *
98  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
99  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
100  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
101  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
102  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
103  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
104  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
105  */
106 
107 struct iwm_rx_radiotap_header {
108 	struct ieee80211_radiotap_header wr_ihdr;
109 	uint64_t	wr_tsft;
110 	uint8_t		wr_flags;
111 	uint8_t		wr_rate;
112 	uint16_t	wr_chan_freq;
113 	uint16_t	wr_chan_flags;
114 	int8_t		wr_dbm_antsignal;
115 	int8_t		wr_dbm_antnoise;
116 } __packed __aligned(8);
117 
118 #define IWM_RX_RADIOTAP_PRESENT						\
119 	((1 << IEEE80211_RADIOTAP_TSFT) |				\
120 	 (1 << IEEE80211_RADIOTAP_FLAGS) |				\
121 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
122 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
123 	 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |			\
124 	 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE))
125 
126 struct iwm_tx_radiotap_header {
127 	struct ieee80211_radiotap_header wt_ihdr;
128 	uint8_t		wt_flags;
129 	uint8_t		wt_rate;
130 	uint16_t	wt_chan_freq;
131 	uint16_t	wt_chan_flags;
132 } __packed;
133 
134 #define IWM_TX_RADIOTAP_PRESENT						\
135 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
136 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
137 	 (1 << IEEE80211_RADIOTAP_CHANNEL))
138 
139 
140 #define IWM_UCODE_SECTION_MAX 16
141 
142 /**
143  * enum iwm_ucode_type
144  *
145  * The type of ucode.
146  *
147  * @IWM_UCODE_REGULAR: Normal runtime ucode
148  * @IWM_UCODE_INIT: Initial ucode
149  * @IWM_UCODE_WOWLAN: Wake on Wireless enabled ucode
150  * @IWM_UCODE_REGULAR_USNIFFER: Normal runtime ucode when using usniffer image
151  */
152 enum iwm_ucode_type {
153 	IWM_UCODE_REGULAR,
154 	IWM_UCODE_INIT,
155 	IWM_UCODE_WOWLAN,
156 	IWM_UCODE_REGULAR_USNIFFER,
157 	IWM_UCODE_TYPE_MAX
158 };
159 
160 struct iwm_ucode_capabilities {
161 	uint32_t max_probe_length;
162 	uint32_t n_scan_channels;
163 	uint32_t flags;
164 	uint8_t enabled_api[howmany(IWM_NUM_UCODE_TLV_API, NBBY)];
165 	uint8_t enabled_capa[howmany(IWM_NUM_UCODE_TLV_CAPA, NBBY)];
166 };
167 
168 static inline int
169 fw_has_api(const struct iwm_ucode_capabilities *capabilities,
170 	   unsigned int api)
171 {
172 	return isset(capabilities->enabled_api, api);
173 }
174 
175 static inline int
176 fw_has_capa(const struct iwm_ucode_capabilities *capabilities,
177 	    unsigned int capa)
178 {
179 	return isset(capabilities->enabled_capa, capa);
180 }
181 
182 /* one for each uCode image (inst/data, init/runtime/wowlan) */
183 struct iwm_fw_desc {
184 	const void *data;	/* vmalloc'ed data */
185 	uint32_t len;		/* size in bytes */
186 	uint32_t offset;	/* offset in the device */
187 };
188 
189 struct iwm_fw_img {
190 	struct iwm_fw_desc sec[IWM_UCODE_SECTION_MAX];
191 	int fw_count;
192 	int is_dual_cpus;
193 	uint32_t paging_mem_size;
194 };
195 
196 struct iwm_fw_info {
197 	const struct firmware *fw_fp;
198 
199 	/* ucode images */
200 	struct iwm_fw_img img[IWM_UCODE_TYPE_MAX];
201 
202 	struct iwm_ucode_capabilities ucode_capa;
203 
204 	uint32_t phy_config;
205 	uint8_t valid_tx_ant;
206 	uint8_t valid_rx_ant;
207 };
208 
209 struct iwm_nvm_data {
210 	int n_hw_addrs;
211 	uint8_t hw_addr[IEEE80211_ADDR_LEN];
212 
213 	int sku_cap_band_24GHz_enable;
214 	int sku_cap_band_52GHz_enable;
215 	int sku_cap_11n_enable;
216 	int sku_cap_amt_enable;
217 	int sku_cap_ipan_enable;
218 
219 	uint8_t radio_cfg_type;
220 	uint8_t radio_cfg_step;
221 	uint8_t radio_cfg_dash;
222 	uint8_t radio_cfg_pnum;
223 	uint8_t valid_tx_ant, valid_rx_ant;
224 #define IWM_NUM_CHANNELS	39
225 #define IWM_NUM_CHANNELS_8000	51
226 
227 	uint16_t nvm_version;
228 	uint8_t max_tx_pwr_half_dbm;
229 
230 	boolean_t lar_enabled;
231 	uint16_t nvm_ch_flags[];
232 };
233 
234 /* max bufs per tfd the driver will use */
235 #define IWM_MAX_CMD_TBS_PER_TFD 2
236 
237 struct iwm_rx_packet;
238 struct iwm_host_cmd {
239 	const void *data[IWM_MAX_CMD_TBS_PER_TFD];
240 	struct iwm_rx_packet *resp_pkt;
241 	unsigned long _rx_page_addr;
242 	uint32_t _rx_page_order;
243 	int handler_status;
244 
245 	uint32_t flags;
246 	uint32_t id;
247 	uint16_t len[IWM_MAX_CMD_TBS_PER_TFD];
248 	uint8_t dataflags[IWM_MAX_CMD_TBS_PER_TFD];
249 };
250 
251 /*
252  * DMA glue is from iwn
253  */
254 
255 typedef caddr_t iwm_caddr_t;
256 typedef void *iwm_hookarg_t;
257 
258 struct iwm_dma_info {
259 	bus_dma_tag_t		tag;
260 	bus_dmamap_t		map;
261 	bus_dma_segment_t	seg;
262 	bus_addr_t		paddr;
263 	void 			*vaddr;
264 	bus_size_t		size;
265 };
266 
267 /**
268  * struct iwm_fw_paging
269  * @fw_paging_block: dma memory info
270  * @fw_paging_size: page size
271  */
272 struct iwm_fw_paging {
273 	struct iwm_dma_info fw_paging_block;
274 	uint32_t fw_paging_size;
275 };
276 
277 #define IWM_TX_RING_COUNT	256
278 #define IWM_TX_RING_LOMARK	192
279 #define IWM_TX_RING_HIMARK	224
280 
281 struct iwm_tx_data {
282 	bus_dmamap_t		map;
283 	bus_addr_t		cmd_paddr;
284 	bus_addr_t		scratch_paddr;
285 	struct mbuf		*m;
286 	struct iwm_node 	*in;
287 	int			done;
288 };
289 
290 struct iwm_tx_ring {
291 	struct iwm_dma_info	desc_dma;
292 	struct iwm_dma_info	cmd_dma;
293 	struct iwm_tfd		*desc;
294 	struct iwm_device_cmd	*cmd;
295 	bus_dma_tag_t		data_dmat;
296 	struct iwm_tx_data	data[IWM_TX_RING_COUNT];
297 	int			qid;
298 	int			queued;
299 	int			cur;
300 };
301 
302 #define IWM_RX_RING_COUNT	256
303 /* Linux driver optionally uses 8k buffer */
304 #define IWM_RBUF_SIZE		4096
305 
306 #define	IWM_MAX_SCATTER		20
307 
308 struct iwm_rx_data {
309 	struct mbuf	*m;
310 	bus_dmamap_t	map;
311 };
312 
313 struct iwm_rx_ring {
314 	struct iwm_dma_info	desc_dma;
315 	struct iwm_dma_info	stat_dma;
316 	struct iwm_dma_info	buf_dma;
317 	uint32_t		*desc;
318 	struct iwm_rb_status	*stat;
319 	struct iwm_rx_data	data[IWM_RX_RING_COUNT];
320 	bus_dmamap_t		spare_map;	/* for iwm_rx_addbuf() */
321 	bus_dma_tag_t           data_dmat;
322 	int			cur;
323 };
324 
325 #define IWM_CMD_RESP_MAX PAGE_SIZE
326 
327 #define IWM_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS 500
328 #define IWM_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS 400
329 
330 /*
331  * Command headers are in iwl-trans.h, which is full of all
332  * kinds of other junk, so we just replicate the structures here.
333  * First the software bits:
334  */
335 enum IWM_CMD_MODE {
336 	IWM_CMD_SYNC		= 0,
337 	IWM_CMD_ASYNC		= (1 << 0),
338 	IWM_CMD_WANT_SKB	= (1 << 1),
339 	IWM_CMD_SEND_IN_RFKILL	= (1 << 2),
340 };
341 enum iwm_hcmd_dataflag {
342 	IWM_HCMD_DFL_NOCOPY     = (1 << 0),
343 	IWM_HCMD_DFL_DUP        = (1 << 1),
344 };
345 
346 struct iwm_int_sta {
347 	uint32_t sta_id;
348 	uint32_t tfd_queue_msk;
349 };
350 
351 struct iwm_mvm_phy_ctxt {
352 	uint16_t id;
353 	uint16_t color;
354 	uint32_t ref;
355 	struct ieee80211_channel *channel;
356 };
357 
358 struct iwm_bf_data {
359 	int bf_enabled;		/* filtering	*/
360 	int ba_enabled;		/* abort	*/
361 	int ave_beacon_signal;
362 	int last_cqm_event;
363 };
364 
365 struct iwm_vap {
366 	struct ieee80211vap	iv_vap;
367 	int			is_uploaded;
368 	int			iv_auth;
369 
370 	int			(*iv_newstate)(struct ieee80211vap *,
371 				    enum ieee80211_state, int);
372 
373 	struct iwm_mvm_phy_ctxt	*phy_ctxt;
374 
375 	uint16_t		id;
376 	uint16_t		color;
377 
378 	boolean_t		have_wme;
379 	/*
380 	 * QoS data from net80211, need to store this here
381 	 * as net80211 has a separate callback but we need
382 	 * to have the data for the MAC context
383 	 */
384         struct {
385 		uint16_t cw_min;
386 		uint16_t cw_max;
387 		uint16_t edca_txop;
388 		uint8_t aifsn;
389 	} queue_params[WME_NUM_AC];
390 
391 	/* indicates that this interface requires PS to be disabled */
392 	boolean_t		ps_disabled;
393 };
394 #define IWM_VAP(_vap)		((struct iwm_vap *)(_vap))
395 
396 struct iwm_node {
397 	struct ieee80211_node	in_ni;
398 
399 	/* status "bits" */
400 	int			in_assoc;
401 
402 	struct iwm_lq_cmd	in_lq;
403 };
404 #define IWM_NODE(_ni)		((struct iwm_node *)(_ni))
405 
406 #define IWM_STATION_ID 0
407 #define IWM_AUX_STA_ID 1
408 
409 #define	IWM_DEFAULT_MACID	0
410 #define	IWM_DEFAULT_COLOR	0
411 #define	IWM_DEFAULT_TSFID	0
412 
413 #define IWM_ICT_SIZE		4096
414 #define IWM_ICT_COUNT		(IWM_ICT_SIZE / sizeof (uint32_t))
415 #define IWM_ICT_PADDR_SHIFT	12
416 
417 struct iwm_cfg;
418 
419 struct iwm_softc {
420 	device_t		sc_dev;
421 	uint32_t		sc_debug;
422 	int			sc_attached;
423 
424 	struct mtx		sc_mtx;
425 	struct mbufq		sc_snd;
426 	struct ieee80211com	sc_ic;
427 	struct ieee80211_ratectl_tx_status sc_txs;
428 
429 	int			sc_flags;
430 #define IWM_FLAG_USE_ICT	(1 << 0)
431 #define IWM_FLAG_HW_INITED	(1 << 1)
432 #define IWM_FLAG_STOPPED	(1 << 2)
433 #define IWM_FLAG_RFKILL		(1 << 3)
434 #define IWM_FLAG_BUSY		(1 << 4)
435 #define IWM_FLAG_SCANNING	(1 << 5)
436 #define IWM_FLAG_SCAN_RUNNING	(1 << 6)
437 #define IWM_FLAG_TE_ACTIVE	(1 << 7)
438 
439 	struct intr_config_hook sc_preinit_hook;
440 	struct callout		sc_watchdog_to;
441 	struct callout		sc_led_blink_to;
442 
443 	struct task		init_task;
444 
445 	struct resource		*sc_irq;
446 	struct resource		*sc_mem;
447 	bus_space_tag_t		sc_st;
448 	bus_space_handle_t	sc_sh;
449 	bus_size_t		sc_sz;
450 	bus_dma_tag_t		sc_dmat;
451 	void			*sc_ih;
452 
453 	/* TX scheduler rings. */
454 	struct iwm_dma_info	sched_dma;
455 	uint32_t		scd_base_addr;
456 
457 	/* TX/RX rings. */
458 	struct iwm_tx_ring	txq[IWM_MVM_MAX_QUEUES];
459 	struct iwm_rx_ring	rxq;
460 	int			qfullmsk;
461 
462 	int			sc_sf_state;
463 
464 	/* ICT table. */
465 	struct iwm_dma_info	ict_dma;
466 	int			ict_cur;
467 
468 	int			sc_hw_rev;
469 	int			sc_hw_id;
470 
471 	struct iwm_dma_info	kw_dma;
472 	struct iwm_dma_info	fw_dma;
473 
474 	int			sc_fw_chunk_done;
475 
476 	enum iwm_ucode_type	cur_ucode;
477 	int			ucode_loaded;
478 	char			sc_fwver[32];
479 
480 	char			sc_fw_mcc[3];
481 
482 	int			sc_intmask;
483 
484 	/*
485 	 * So why do we need a separate stopped flag and a generation?
486 	 * the former protects the device from issuing commands when it's
487 	 * stopped (duh).  The latter protects against race from a very
488 	 * fast stop/unstop cycle where threads waiting for responses do
489 	 * not have a chance to run in between.  Notably: we want to stop
490 	 * the device from interrupt context when it craps out, so we
491 	 * don't have the luxury of waiting for quiescense.
492 	 */
493 	int			sc_generation;
494 
495 	struct iwm_fw_info	sc_fw;
496 	struct iwm_tlv_calib_ctrl sc_default_calib[IWM_UCODE_TYPE_MAX];
497 
498 	const struct iwm_cfg	*cfg;
499 	struct iwm_nvm_data	*nvm_data;
500 	struct iwm_phy_db	*sc_phy_db;
501 
502 	struct iwm_bf_data	sc_bf;
503 
504 	int			sc_tx_timer;
505 
506 	int			sc_scan_last_antenna;
507 
508 	int			sc_fixed_ridx;
509 
510 	int			sc_staid;
511 	int			sc_nodecolor;
512 
513 	uint8_t			sc_cmd_resp[IWM_CMD_RESP_MAX];
514 	int			sc_wantresp;
515 
516 	struct task		sc_es_task;
517 
518 	struct iwm_rx_phy_info	sc_last_phy_info;
519 	int			sc_ampdu_ref;
520 
521 	struct iwm_int_sta	sc_aux_sta;
522 
523 	/* phy contexts.  we only use the first one */
524 	struct iwm_mvm_phy_ctxt	sc_phyctxt[IWM_NUM_PHY_CTX];
525 
526 	struct iwm_notif_statistics_v10 sc_stats;
527 	int			sc_noise;
528 
529 	caddr_t			sc_drvbpf;
530 
531 	struct iwm_rx_radiotap_header sc_rxtap;
532 	struct iwm_tx_radiotap_header sc_txtap;
533 
534 	int			sc_max_rssi;
535 
536 	struct iwm_notif_wait_data *sc_notif_wait;
537 
538 	int			cmd_hold_nic_awake;
539 
540 	/* Firmware status */
541 	uint32_t		error_event_table[2];
542 	uint32_t		log_event_table;
543 	uint32_t		umac_error_event_table;
544 	int			support_umac_log;
545 
546 	/*
547 	 * Paging parameters - All of the parameters should be set by the
548 	 * opmode when paging is enabled
549 	 */
550 	struct iwm_fw_paging	fw_paging_db[IWM_NUM_OF_FW_PAGING_BLOCKS];
551 	uint16_t		num_of_paging_blk;
552 	uint16_t		num_of_pages_in_last_blk;
553 
554 	boolean_t		last_ebs_successful;
555 
556 	/* last smart fifo state that was successfully sent to firmware */
557 	enum iwm_sf_state	sf_state;
558 
559 	/* Indicate if device power save is allowed */
560 	boolean_t		sc_ps_disabled;
561 
562 	int			sc_ltr_enabled;
563 
564 	/* Track firmware state for STA association. */
565 	int			sc_firmware_state;
566 
567 	/* Unique ID (assigned by the firmware) of the current Time Event. */
568 	uint32_t		sc_time_event_uid;
569 
570 	/* Duration of the Time Event in TU. */
571 	uint32_t		sc_time_event_duration;
572 
573 	/* Expected end of the Time Event in HZ ticks. */
574 	int			sc_time_event_end_ticks;
575 };
576 
577 #define IWM_LOCK_INIT(_sc) \
578 	mtx_init(&(_sc)->sc_mtx, device_get_nameunit((_sc)->sc_dev), \
579 	    MTX_NETWORK_LOCK, MTX_DEF);
580 #define	IWM_LOCK(_sc)		mtx_lock(&(_sc)->sc_mtx)
581 #define	IWM_UNLOCK(_sc)		mtx_unlock(&(_sc)->sc_mtx)
582 #define IWM_LOCK_DESTROY(_sc)	mtx_destroy(&(_sc)->sc_mtx)
583