xref: /openbsd-src/sys/dev/pci/if_iwmvar.h (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1 /*	$OpenBSD: if_iwmvar.h,v 1.23 2016/09/12 10:18:26 stsp Exp $	*/
2 
3 /*
4  * Copyright (c) 2014 genua mbh <info@genua.de>
5  * Copyright (c) 2014 Fixup Software Ltd.
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 
20 /*-
21  * Based on BSD-licensed source modules in the Linux iwlwifi driver,
22  * which were used as the reference documentation for this implementation.
23  *
24  * Driver version we are currently based off of is
25  * Linux 3.14.3 (tag id a2df521e42b1d9a23f620ac79dbfe8655a8391dd)
26  *
27  ***********************************************************************
28  *
29  * This file is provided under a dual BSD/GPLv2 license.  When using or
30  * redistributing this file, you may do so under either license.
31  *
32  * GPL LICENSE SUMMARY
33  *
34  * Copyright(c) 2007 - 2013 Intel Corporation. All rights reserved.
35  *
36  * This program is free software; you can redistribute it and/or modify
37  * it under the terms of version 2 of the GNU General Public License as
38  * published by the Free Software Foundation.
39  *
40  * This program is distributed in the hope that it will be useful, but
41  * WITHOUT ANY WARRANTY; without even the implied warranty of
42  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
43  * General Public License for more details.
44  *
45  * You should have received a copy of the GNU General Public License
46  * along with this program; if not, write to the Free Software
47  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
48  * USA
49  *
50  * The full GNU General Public License is included in this distribution
51  * in the file called COPYING.
52  *
53  * Contact Information:
54  *  Intel Linux Wireless <ilw@linux.intel.com>
55  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
56  *
57  *
58  * BSD LICENSE
59  *
60  * Copyright(c) 2005 - 2013 Intel Corporation. All rights reserved.
61  * All rights reserved.
62  *
63  * Redistribution and use in source and binary forms, with or without
64  * modification, are permitted provided that the following conditions
65  * are met:
66  *
67  *  * Redistributions of source code must retain the above copyright
68  *    notice, this list of conditions and the following disclaimer.
69  *  * Redistributions in binary form must reproduce the above copyright
70  *    notice, this list of conditions and the following disclaimer in
71  *    the documentation and/or other materials provided with the
72  *    distribution.
73  *  * Neither the name Intel Corporation nor the names of its
74  *    contributors may be used to endorse or promote products derived
75  *    from this software without specific prior written permission.
76  *
77  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
78  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
79  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
80  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
81  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
82  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
83  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
84  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
85  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
86  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
87  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
88  */
89 
90 /*-
91  * Copyright (c) 2007-2010 Damien Bergamini <damien.bergamini@free.fr>
92  *
93  * Permission to use, copy, modify, and distribute this software for any
94  * purpose with or without fee is hereby granted, provided that the above
95  * copyright notice and this permission notice appear in all copies.
96  *
97  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
98  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
99  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
100  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
101  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
102  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
103  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
104  */
105 
106 struct iwm_rx_radiotap_header {
107 	struct ieee80211_radiotap_header wr_ihdr;
108 	uint64_t	wr_tsft;
109 	uint8_t		wr_flags;
110 	uint8_t		wr_rate;
111 	uint16_t	wr_chan_freq;
112 	uint16_t	wr_chan_flags;
113 	int8_t		wr_dbm_antsignal;
114 	int8_t		wr_dbm_antnoise;
115 } __packed;
116 
117 #define IWM_RX_RADIOTAP_PRESENT						\
118 	((1 << IEEE80211_RADIOTAP_TSFT) |				\
119 	 (1 << IEEE80211_RADIOTAP_FLAGS) |				\
120 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
121 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
122 	 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |			\
123 	 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE))
124 
125 struct iwm_tx_radiotap_header {
126 	struct ieee80211_radiotap_header wt_ihdr;
127 	uint8_t		wt_flags;
128 	uint8_t		wt_rate;
129 	uint16_t	wt_chan_freq;
130 	uint16_t	wt_chan_flags;
131 	uint8_t		wt_hwqueue;
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 	 (1 << IEEE80211_RADIOTAP_HWQUEUE))
139 
140 #define IWM_UCODE_SECT_MAX 16
141 #define IWM_FWDMASEGSZ (192*1024)
142 #define IWM_FWDMASEGSZ_8000 (320*1024)
143 /* sanity check value */
144 #define IWM_FWMAXSIZE (2*1024*1024)
145 
146 /*
147  * fw_status is used to determine if we've already parsed the firmware file
148  *
149  * In addition to the following, status < 0 ==> -error
150  */
151 #define IWM_FW_STATUS_NONE		0
152 #define IWM_FW_STATUS_INPROGRESS	1
153 #define IWM_FW_STATUS_DONE		2
154 
155 enum iwm_ucode_type {
156 	IWM_UCODE_TYPE_REGULAR,
157 	IWM_UCODE_TYPE_INIT,
158 	IWM_UCODE_TYPE_WOW,
159 	IWM_UCODE_TYPE_REGULAR_USNIFFER,
160 	IWM_UCODE_TYPE_MAX
161 };
162 
163 struct iwm_fw_info {
164 	void *fw_rawdata;
165 	size_t fw_rawsize;
166 	int fw_status;
167 
168 	struct iwm_fw_sects {
169 		struct iwm_fw_onesect {
170 			void *fws_data;
171 			uint32_t fws_len;
172 			uint32_t fws_devoff;
173 		} fw_sect[IWM_UCODE_SECT_MAX];
174 		size_t fw_totlen;
175 		int fw_count;
176 	} fw_sects[IWM_UCODE_TYPE_MAX];
177 };
178 
179 struct iwm_nvm_data {
180 	int n_hw_addrs;
181 	uint8_t hw_addr[ETHER_ADDR_LEN];
182 
183 	uint8_t calib_version;
184 	uint16_t calib_voltage;
185 
186 	uint16_t raw_temperature;
187 	uint16_t kelvin_temperature;
188 	uint16_t kelvin_voltage;
189 	uint16_t xtal_calib[2];
190 
191 	int sku_cap_band_24GHz_enable;
192 	int sku_cap_band_52GHz_enable;
193 	int sku_cap_11n_enable;
194 	int sku_cap_amt_enable;
195 	int sku_cap_ipan_enable;
196 	int sku_cap_mimo_disable;
197 
198 	uint8_t radio_cfg_type;
199 	uint8_t radio_cfg_step;
200 	uint8_t radio_cfg_dash;
201 	uint8_t radio_cfg_pnum;
202 	uint8_t valid_tx_ant, valid_rx_ant;
203 
204 	uint16_t nvm_version;
205 	uint8_t max_tx_pwr_half_dbm;
206 };
207 
208 /* max bufs per tfd the driver will use */
209 #define IWM_MAX_CMD_TBS_PER_TFD 2
210 
211 struct iwm_rx_packet;
212 struct iwm_host_cmd {
213 	const void *data[IWM_MAX_CMD_TBS_PER_TFD];
214 	struct iwm_rx_packet *resp_pkt;
215 	unsigned long _rx_page_addr;
216 	uint32_t _rx_page_order;
217 	int handler_status;
218 
219 	uint32_t flags;
220 	uint16_t len[IWM_MAX_CMD_TBS_PER_TFD];
221 	uint8_t dataflags[IWM_MAX_CMD_TBS_PER_TFD];
222 	uint32_t id;
223 };
224 
225 /*
226  * DMA glue is from iwn
227  */
228 
229 struct iwm_dma_info {
230 	bus_dma_tag_t		tag;
231 	bus_dmamap_t		map;
232 	bus_dma_segment_t	seg;
233 	bus_addr_t		paddr;
234 	void 			*vaddr;
235 	bus_size_t		size;
236 };
237 
238 #define IWM_TX_RING_COUNT	256
239 #define IWM_TX_RING_LOMARK	192
240 #define IWM_TX_RING_HIMARK	224
241 
242 struct iwm_tx_data {
243 	bus_dmamap_t	map;
244 	bus_addr_t	cmd_paddr;
245 	bus_addr_t	scratch_paddr;
246 	struct mbuf	*m;
247 	struct iwm_node *in;
248 	int done;
249 };
250 
251 struct iwm_tx_ring {
252 	struct iwm_dma_info	desc_dma;
253 	struct iwm_dma_info	cmd_dma;
254 	struct iwm_tfd		*desc;
255 	struct iwm_device_cmd	*cmd;
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 struct iwm_rx_data {
268 	struct mbuf	*m;
269 	bus_dmamap_t	map;
270 };
271 
272 struct iwm_rx_ring {
273 	struct iwm_dma_info	desc_dma;
274 	struct iwm_dma_info	stat_dma;
275 	struct iwm_dma_info	buf_dma;
276 	uint32_t		*desc;
277 	struct iwm_rb_status	*stat;
278 	struct iwm_rx_data	data[IWM_RX_RING_COUNT];
279 	int			cur;
280 };
281 
282 #define IWM_FLAG_USE_ICT	0x01
283 #define IWM_FLAG_HW_INITED	0x02
284 #define IWM_FLAG_STOPPED	0x04
285 #define IWM_FLAG_RFKILL		0x08
286 #define IWM_FLAG_SCANNING	0x10
287 
288 struct iwm_ucode_status {
289 	uint32_t uc_error_event_table;
290 	uint32_t uc_umac_error_event_table;
291 	uint32_t uc_log_event_table;
292 
293 	int uc_ok;
294 	int uc_intr;
295 };
296 
297 /* sc_wantresp */
298 #define IWM_CMD_RESP_IDLE	-1
299 
300 #define IWM_CMD_RESP_MAX PAGE_SIZE
301 
302 /* lower blocks contain EEPROM image and calibration data */
303 #define IWM_OTP_LOW_IMAGE_SIZE_FAMILY_7000 	16384
304 #define IWM_OTP_LOW_IMAGE_SIZE_FAMILY_8000	32768
305 
306 #define IWM_TE_SESSION_PROTECTION_MAX_TIME_MS 1000
307 #define IWM_TE_SESSION_PROTECTION_MIN_TIME_MS 400
308 
309 enum IWM_CMD_MODE {
310 	IWM_CMD_ASYNC		= (1 << 0),
311 	IWM_CMD_WANT_SKB	= (1 << 1),
312 	IWM_CMD_SEND_IN_RFKILL	= (1 << 2),
313 };
314 enum iwm_hcmd_dataflag {
315 	IWM_HCMD_DFL_NOCOPY     = (1 << 0),
316 	IWM_HCMD_DFL_DUP        = (1 << 1),
317 };
318 
319 #define IWM_NUM_PAPD_CH_GROUPS	9
320 #define IWM_NUM_TXP_CH_GROUPS	9
321 
322 struct iwm_phy_db_entry {
323 	uint16_t size;
324 	uint8_t *data;
325 };
326 
327 struct iwm_phy_db {
328 	struct iwm_phy_db_entry	cfg;
329 	struct iwm_phy_db_entry	calib_nch;
330 	struct iwm_phy_db_entry	calib_ch_group_papd[IWM_NUM_PAPD_CH_GROUPS];
331 	struct iwm_phy_db_entry	calib_ch_group_txp[IWM_NUM_TXP_CH_GROUPS];
332 };
333 
334 struct iwm_phy_ctxt {
335 	uint16_t id;
336 	uint16_t color;
337 	uint32_t ref;
338 	struct ieee80211_channel *channel;
339 };
340 
341 struct iwm_bf_data {
342 	int bf_enabled;		/* filtering	*/
343 	int ba_enabled;		/* abort	*/
344 	int ave_beacon_signal;
345 	int last_cqm_event;
346 };
347 
348 struct iwm_softc {
349 	struct device sc_dev;
350 	struct ieee80211com sc_ic;
351 	int (*sc_newstate)(struct ieee80211com *, enum ieee80211_state, int);
352 	int sc_newstate_pending;
353 
354 	struct ieee80211_amrr sc_amrr;
355 	struct timeout sc_calib_to;
356 	struct timeout sc_led_blink_to;
357 
358 	struct task		init_task;
359 	struct task		newstate_task;
360 	struct task		setrates_task;
361 	enum ieee80211_state	ns_nstate;
362 	int			ns_arg;
363 
364 	/* Task for firmware BlockAck setup/teardown and its arguments. */
365 	struct task		ba_task;
366 	int			ba_start;
367 	int			ba_tid;
368 	uint16_t		ba_ssn;
369 
370 	/* Task for HT protection updates. */
371 	struct task		htprot_task;
372 
373 	bus_space_tag_t sc_st;
374 	bus_space_handle_t sc_sh;
375 	bus_size_t sc_sz;
376 	bus_dma_tag_t sc_dmat;
377 	pci_chipset_tag_t sc_pct;
378 	pcitag_t sc_pcitag;
379 	const void *sc_ih;
380 
381 	/* TX scheduler rings. */
382 	struct iwm_dma_info		sched_dma;
383 	uint32_t			sched_base;
384 
385 	/* TX/RX rings. */
386 	struct iwm_tx_ring txq[IWM_MAX_QUEUES];
387 	struct iwm_rx_ring rxq;
388 	int qfullmsk;
389 
390 	int sc_sf_state;
391 
392 	/* ICT table. */
393 	struct iwm_dma_info	ict_dma;
394 	int			ict_cur;
395 
396 	int sc_hw_rev;
397 #define IWM_SILICON_A_STEP	0
398 #define IWM_SILICON_B_STEP	1
399 #define IWM_SILICON_C_STEP	2
400 #define IWM_SILICON_D_STEP	3
401 	int sc_hw_id;
402 	int sc_device_family;
403 #define IWM_DEVICE_FAMILY_7000	1
404 #define IWM_DEVICE_FAMILY_8000	2
405 
406 	struct iwm_dma_info kw_dma;
407 	struct iwm_dma_info fw_dma;
408 
409 	int sc_fw_chunk_done;
410 	int sc_init_complete;
411 
412 	struct iwm_ucode_status sc_uc;
413 	enum iwm_ucode_type sc_uc_current;
414 	char sc_fwver[32];
415 
416 	int sc_capaflags;
417 	int sc_capa_max_probe_len;
418 	int sc_capa_n_scan_channels;
419 	uint32_t sc_ucode_api;
420 	uint8_t sc_enabled_capa[howmany(IWM_NUM_UCODE_TLV_CAPA, NBBY)];
421 	char sc_fw_mcc[3];
422 
423 	int sc_intmask;
424 	int sc_flags;
425 
426 	/*
427 	 * So why do we need a separate stopped flag and a generation?
428 	 * the former protects the device from issueing commands when it's
429 	 * stopped (duh).  The latter protects against race from a very
430 	 * fast stop/unstop cycle where threads waiting for responses do
431 	 * not have a chance to run in between.  Notably: we want to stop
432 	 * the device from interrupt context when it craps out, so we
433 	 * don't have the luxury of waiting for quiescense.
434 	 */
435 	int sc_generation;
436 
437 	struct rwlock ioctl_rwl;
438 
439 	int sc_cap_off; /* PCIe caps */
440 
441 	const char *sc_fwname;
442 	bus_size_t sc_fwdmasegsz;
443 	struct iwm_fw_info sc_fw;
444 	int sc_fw_phy_config;
445 	struct iwm_tlv_calib_ctrl sc_default_calib[IWM_UCODE_TYPE_MAX];
446 
447 	struct iwm_nvm_data sc_nvm;
448 	struct iwm_phy_db sc_phy_db;
449 
450 	struct iwm_bf_data sc_bf;
451 
452 	int sc_tx_timer;
453 	int sc_rx_ba_sessions;
454 
455 	int sc_scan_last_antenna;
456 
457 	int sc_fixed_ridx;
458 
459 	int sc_staid;
460 	int sc_nodecolor;
461 
462 	uint8_t sc_cmd_resp[IWM_CMD_RESP_MAX];
463 	int sc_wantresp;
464 
465 	struct taskq *sc_nswq, *sc_eswq;
466 	struct task sc_eswk;
467 
468 	struct iwm_rx_phy_info sc_last_phy_info;
469 	int sc_ampdu_ref;
470 
471 	/* phy contexts.  we only use the first one */
472 	struct iwm_phy_ctxt sc_phyctxt[IWM_NUM_PHY_CTX];
473 
474 	struct iwm_notif_statistics sc_stats;
475 	int sc_noise;
476 
477 	int host_interrupt_operation_mode;
478 
479 #if NBPFILTER > 0
480 	caddr_t			sc_drvbpf;
481 
482 	union {
483 		struct iwm_rx_radiotap_header th;
484 		uint8_t	pad[IEEE80211_RADIOTAP_HDRLEN];
485 	} sc_rxtapu;
486 #define sc_rxtap	sc_rxtapu.th
487 	int			sc_rxtap_len;
488 
489 	union {
490 		struct iwm_tx_radiotap_header th;
491 		uint8_t	pad[IEEE80211_RADIOTAP_HDRLEN];
492 	} sc_txtapu;
493 #define sc_txtap	sc_txtapu.th
494 	int			sc_txtap_len;
495 #endif
496 };
497 
498 struct iwm_node {
499 	struct ieee80211_node in_ni;
500 	struct iwm_phy_ctxt *in_phyctxt;
501 
502 	uint16_t in_id;
503 	uint16_t in_color;
504 	int in_tsfid;
505 
506 	/* status "bits" */
507 	int in_assoc;
508 
509 	struct iwm_lq_cmd in_lq;
510 	struct ieee80211_amrr_node in_amn;
511 };
512 #define IWM_STATION_ID 0
513 #define IWM_AUX_STA_ID 1
514 
515 #define IWM_ICT_SIZE		4096
516 #define IWM_ICT_COUNT		(IWM_ICT_SIZE / sizeof (uint32_t))
517 #define IWM_ICT_PADDR_SHIFT	12
518