xref: /freebsd/sys/dev/iwm/if_iwmvar.h (revision 0b3105a37d7adcadcb720112fed4dc4e8040be99)
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;
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_SECT_MAX 6
141 #define IWM_FWDMASEGSZ (192*1024)
142 /* sanity check value */
143 #define IWM_FWMAXSIZE (2*1024*1024)
144 
145 /*
146  * fw_status is used to determine if we've already parsed the firmware file
147  *
148  * In addition to the following, status < 0 ==> -error
149  */
150 #define IWM_FW_STATUS_NONE		0
151 #define IWM_FW_STATUS_INPROGRESS	1
152 #define IWM_FW_STATUS_DONE		2
153 
154 enum iwm_ucode_type {
155 	IWM_UCODE_TYPE_INIT,
156 	IWM_UCODE_TYPE_REGULAR,
157 	IWM_UCODE_TYPE_WOW,
158 	IWM_UCODE_TYPE_MAX
159 };
160 
161 struct iwm_fw_info {
162 	const struct firmware *fw_fp;
163 	int fw_status;
164 
165 	struct iwm_fw_sects {
166 		struct iwm_fw_onesect {
167 			const void *fws_data;
168 			uint32_t fws_len;
169 			uint32_t fws_devoff;
170 		} fw_sect[IWM_UCODE_SECT_MAX];
171 		size_t fw_totlen;
172 		int fw_count;
173 	} fw_sects[IWM_UCODE_TYPE_MAX];
174 };
175 
176 struct iwm_nvm_data {
177 	int n_hw_addrs;
178 	uint8_t hw_addr[IEEE80211_ADDR_LEN];
179 
180 	uint8_t calib_version;
181 	uint16_t calib_voltage;
182 
183 	uint16_t raw_temperature;
184 	uint16_t kelvin_temperature;
185 	uint16_t kelvin_voltage;
186 	uint16_t xtal_calib[2];
187 
188 	int sku_cap_band_24GHz_enable;
189 	int sku_cap_band_52GHz_enable;
190 	int sku_cap_11n_enable;
191 	int sku_cap_amt_enable;
192 	int sku_cap_ipan_enable;
193 
194 	uint8_t radio_cfg_type;
195 	uint8_t radio_cfg_step;
196 	uint8_t radio_cfg_dash;
197 	uint8_t radio_cfg_pnum;
198 	uint8_t valid_tx_ant, valid_rx_ant;
199 
200 	uint16_t nvm_version;
201 	uint8_t max_tx_pwr_half_dbm;
202 };
203 
204 /* max bufs per tfd the driver will use */
205 #define IWM_MAX_CMD_TBS_PER_TFD 2
206 
207 struct iwm_rx_packet;
208 struct iwm_host_cmd {
209 	const void *data[IWM_MAX_CMD_TBS_PER_TFD];
210 	struct iwm_rx_packet *resp_pkt;
211 	unsigned long _rx_page_addr;
212 	uint32_t _rx_page_order;
213 	int handler_status;
214 
215 	uint32_t flags;
216 	uint16_t len[IWM_MAX_CMD_TBS_PER_TFD];
217 	uint8_t dataflags[IWM_MAX_CMD_TBS_PER_TFD];
218 	uint8_t id;
219 };
220 
221 /*
222  * DMA glue is from iwn
223  */
224 
225 typedef caddr_t iwm_caddr_t;
226 typedef void *iwm_hookarg_t;
227 
228 struct iwm_dma_info {
229 	bus_dma_tag_t		tag;
230 	bus_dmamap_t		map;
231 	bus_dma_segment_t	seg;
232 	bus_addr_t		paddr;
233 	void 			*vaddr;
234 	bus_size_t		size;
235 };
236 
237 #define IWM_TX_RING_COUNT	256
238 #define IWM_TX_RING_LOMARK	192
239 #define IWM_TX_RING_HIMARK	224
240 
241 struct iwm_tx_data {
242 	bus_dmamap_t		map;
243 	bus_addr_t		cmd_paddr;
244 	bus_addr_t		scratch_paddr;
245 	struct mbuf		*m;
246 	struct iwm_node 	*in;
247 	int			done;
248 };
249 
250 struct iwm_tx_ring {
251 	struct iwm_dma_info	desc_dma;
252 	struct iwm_dma_info	cmd_dma;
253 	struct iwm_tfd		*desc;
254 	struct iwm_device_cmd	*cmd;
255 	bus_dma_tag_t		data_dmat;
256 	struct iwm_tx_data	data[IWM_TX_RING_COUNT];
257 	int			qid;
258 	int			queued;
259 	int			cur;
260 };
261 
262 #define IWM_RX_RING_COUNT	256
263 #define IWM_RBUF_COUNT		(IWM_RX_RING_COUNT + 32)
264 /* Linux driver optionally uses 8k buffer */
265 #define IWM_RBUF_SIZE		4096
266 
267 #define	IWM_MAX_SCATTER		20
268 
269 struct iwm_softc;
270 struct iwm_rbuf {
271 	struct iwm_softc	*sc;
272 	void			*vaddr;
273 	bus_addr_t		paddr;
274 };
275 
276 struct iwm_rx_data {
277 	struct mbuf	*m;
278 	bus_dmamap_t	map;
279 	int		wantresp;
280 };
281 
282 struct iwm_rx_ring {
283 	struct iwm_dma_info	desc_dma;
284 	struct iwm_dma_info	stat_dma;
285 	struct iwm_dma_info	buf_dma;
286 	uint32_t		*desc;
287 	struct iwm_rb_status	*stat;
288 	struct iwm_rx_data	data[IWM_RX_RING_COUNT];
289 	bus_dma_tag_t           data_dmat;
290 	int			cur;
291 };
292 
293 struct iwm_ucode_status {
294 	uint32_t uc_error_event_table;
295 	uint32_t uc_log_event_table;
296 
297 	int uc_ok;
298 	int uc_intr;
299 };
300 
301 #define IWM_CMD_RESP_MAX PAGE_SIZE
302 
303 #define IWM_OTP_LOW_IMAGE_SIZE 2048
304 
305 #define IWM_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS 500
306 #define IWM_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS 400
307 
308 /*
309  * Command headers are in iwl-trans.h, which is full of all
310  * kinds of other junk, so we just replicate the structures here.
311  * First the software bits:
312  */
313 enum IWM_CMD_MODE {
314 	IWM_CMD_SYNC		= 0,
315 	IWM_CMD_ASYNC		= (1 << 0),
316 	IWM_CMD_WANT_SKB	= (1 << 1),
317 	IWM_CMD_SEND_IN_RFKILL	= (1 << 2),
318 };
319 enum iwm_hcmd_dataflag {
320 	IWM_HCMD_DFL_NOCOPY     = (1 << 0),
321 	IWM_HCMD_DFL_DUP        = (1 << 1),
322 };
323 
324 /*
325  * iwlwifi/iwl-phy-db
326  */
327 
328 #define IWM_NUM_PAPD_CH_GROUPS	4
329 #define IWM_NUM_TXP_CH_GROUPS	9
330 
331 struct iwm_phy_db_entry {
332 	uint16_t size;
333 	uint8_t *data;
334 };
335 
336 struct iwm_phy_db {
337 	struct iwm_phy_db_entry	cfg;
338 	struct iwm_phy_db_entry	calib_nch;
339 	struct iwm_phy_db_entry	calib_ch_group_papd[IWM_NUM_PAPD_CH_GROUPS];
340 	struct iwm_phy_db_entry	calib_ch_group_txp[IWM_NUM_TXP_CH_GROUPS];
341 };
342 
343 struct iwm_int_sta {
344 	uint32_t sta_id;
345 	uint32_t tfd_queue_msk;
346 };
347 
348 struct iwm_mvm_phy_ctxt {
349 	uint16_t id;
350 	uint16_t color;
351 	uint32_t ref;
352 	struct ieee80211_channel *channel;
353 };
354 
355 struct iwm_bf_data {
356 	int bf_enabled;		/* filtering	*/
357 	int ba_enabled;		/* abort	*/
358 	int ave_beacon_signal;
359 	int last_cqm_event;
360 };
361 
362 struct iwm_vap {
363 	struct ieee80211vap	iv_vap;
364 	int			is_uploaded;
365 
366 	int			(*iv_newstate)(struct ieee80211vap *,
367 				    enum ieee80211_state, int);
368 };
369 #define IWM_VAP(_vap)		((struct iwm_vap *)(_vap))
370 
371 struct iwm_node {
372 	struct ieee80211_node	in_ni;
373 	struct iwm_mvm_phy_ctxt	*in_phyctxt;
374 
375 	/* status "bits" */
376 	int			in_assoc;
377 
378 	struct iwm_lq_cmd	in_lq;
379 
380 	uint8_t			in_ridx[IEEE80211_RATE_MAXSIZE];
381 };
382 #define IWM_NODE(_ni)		((struct iwm_node *)(_ni))
383 
384 #define IWM_STATION_ID 0
385 
386 #define	IWM_DEFAULT_MACID	0
387 #define	IWM_DEFAULT_COLOR	0
388 #define	IWM_DEFAULT_TSFID	0
389 
390 #define IWM_ICT_SIZE		4096
391 #define IWM_ICT_COUNT		(IWM_ICT_SIZE / sizeof (uint32_t))
392 #define IWM_ICT_PADDR_SHIFT	12
393 
394 struct iwm_softc {
395 	device_t		sc_dev;
396 	uint32_t		sc_debug;
397 
398 	struct mtx		sc_mtx;
399 	struct mbufq		sc_snd;
400 	struct ieee80211com	sc_ic;
401 
402 	int			sc_flags;
403 #define IWM_FLAG_USE_ICT	(1 << 0)
404 #define IWM_FLAG_HW_INITED	(1 << 1)
405 #define IWM_FLAG_STOPPED	(1 << 2)
406 #define IWM_FLAG_RFKILL		(1 << 3)
407 #define IWM_FLAG_BUSY		(1 << 4)
408 
409 	struct intr_config_hook sc_preinit_hook;
410 	struct callout		sc_watchdog_to;
411 
412 	struct task		init_task;
413 
414 	struct resource		*sc_irq;
415 	struct resource		*sc_mem;
416 	bus_space_tag_t		sc_st;
417 	bus_space_handle_t	sc_sh;
418 	bus_size_t		sc_sz;
419 	bus_dma_tag_t		sc_dmat;
420 	void			*sc_ih;
421 
422 	/* TX scheduler rings. */
423 	struct iwm_dma_info	sched_dma;
424 	uint32_t		sched_base;
425 
426 	/* TX/RX rings. */
427 	struct iwm_tx_ring	txq[IWM_MVM_MAX_QUEUES];
428 	struct iwm_rx_ring	rxq;
429 	int			qfullmsk;
430 
431 	int			sc_sf_state;
432 
433 	/* ICT table. */
434 	struct iwm_dma_info	ict_dma;
435 	int			ict_cur;
436 
437 	int			sc_hw_rev;
438 	int			sc_hw_id;
439 
440 	struct iwm_dma_info	kw_dma;
441 	struct iwm_dma_info	fw_dma;
442 
443 	int			sc_fw_chunk_done;
444 	int			sc_init_complete;
445 
446 	struct iwm_ucode_status	sc_uc;
447 	enum iwm_ucode_type	sc_uc_current;
448 	int			sc_fwver;
449 
450 	int			sc_capaflags;
451 	int			sc_capa_max_probe_len;
452 
453 	int			sc_intmask;
454 
455 	/*
456 	 * So why do we need a separate stopped flag and a generation?
457 	 * the former protects the device from issueing commands when it's
458 	 * stopped (duh).  The latter protects against race from a very
459 	 * fast stop/unstop cycle where threads waiting for responses do
460 	 * not have a chance to run in between.  Notably: we want to stop
461 	 * the device from interrupt context when it craps out, so we
462 	 * don't have the luxury of waiting for quiescense.
463 	 */
464 	int			sc_generation;
465 
466 	const char		*sc_fwname;
467 	bus_size_t		sc_fwdmasegsz;
468 	struct iwm_fw_info	sc_fw;
469 	int			sc_fw_phy_config;
470 	struct iwm_tlv_calib_ctrl sc_default_calib[IWM_UCODE_TYPE_MAX];
471 
472 	struct iwm_nvm_data	sc_nvm;
473 	struct iwm_phy_db	sc_phy_db;
474 
475 	struct iwm_bf_data	sc_bf;
476 
477 	int			sc_tx_timer;
478 
479 	struct iwm_scan_cmd	*sc_scan_cmd;
480 	size_t			sc_scan_cmd_len;
481 	int			sc_scan_last_antenna;
482 	int			sc_scanband;
483 
484 	int			sc_auth_prot;
485 
486 	int			sc_fixed_ridx;
487 
488 	int			sc_staid;
489 	int			sc_nodecolor;
490 
491 	uint8_t			sc_cmd_resp[IWM_CMD_RESP_MAX];
492 	int			sc_wantresp;
493 
494 	struct taskqueue	*sc_tq;
495 	struct task		sc_es_task;
496 
497 	struct iwm_rx_phy_info	sc_last_phy_info;
498 	int			sc_ampdu_ref;
499 
500 	struct iwm_int_sta	sc_aux_sta;
501 
502 	/* phy contexts.  we only use the first one */
503 	struct iwm_mvm_phy_ctxt	sc_phyctxt[IWM_NUM_PHY_CTX];
504 
505 	struct iwm_notif_statistics sc_stats;
506 	int			sc_noise;
507 
508 	int			host_interrupt_operation_mode;
509 
510 	caddr_t			sc_drvbpf;
511 
512 	struct iwm_rx_radiotap_header sc_rxtap;
513 	struct iwm_tx_radiotap_header sc_txtap;
514 
515 	int			sc_max_rssi;
516 };
517 
518 #define IWM_LOCK_INIT(_sc) \
519 	mtx_init(&(_sc)->sc_mtx, device_get_nameunit((_sc)->sc_dev), \
520 	    MTX_NETWORK_LOCK, MTX_DEF);
521 #define	IWM_LOCK(_sc)		mtx_lock(&(_sc)->sc_mtx)
522 #define	IWM_UNLOCK(_sc)		mtx_unlock(&(_sc)->sc_mtx)
523 #define IWM_LOCK_DESTROY(_sc)	mtx_destroy(&(_sc)->sc_mtx)
524