xref: /netbsd/sys/dev/pci/if_iwmvar.h (revision 466f7f76)
1 /*	$NetBSD: if_iwmvar.h,v 1.4 2015/02/16 13:22:19 nonaka Exp $	*/
2 /*	OpenBSD: if_iwmvar.h,v 1.3 2015/02/07 07:10:44 phessler Exp 	*/
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 	uint8_t		wt_hwqueue;
133 } __packed;
134 
135 #define IWM_TX_RADIOTAP_PRESENT						\
136 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
137 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
138 	 (1 << IEEE80211_RADIOTAP_CHANNEL))
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 	void *fw_rawdata;
163 	size_t fw_rawsize;
164 	int fw_status;
165 
166 	struct iwm_fw_sects {
167 		struct iwm_fw_onesect {
168 			void *fws_data;
169 			uint32_t fws_len;
170 			uint32_t fws_devoff;
171 
172 			void *fws_alloc;
173 			size_t fws_allocsize;
174 		} fw_sect[IWM_UCODE_SECT_MAX];
175 		size_t fw_totlen;
176 		int fw_count;
177 	} fw_sects[IWM_UCODE_TYPE_MAX];
178 };
179 
180 struct iwm_nvm_data {
181 	int n_hw_addrs;
182 	uint8_t hw_addr[ETHER_ADDR_LEN];
183 
184 	uint8_t calib_version;
185 	uint16_t calib_voltage;
186 
187 	uint16_t raw_temperature;
188 	uint16_t kelvin_temperature;
189 	uint16_t kelvin_voltage;
190 	uint16_t xtal_calib[2];
191 
192 	int sku_cap_band_24GHz_enable;
193 	int sku_cap_band_52GHz_enable;
194 	int sku_cap_11n_enable;
195 	int sku_cap_amt_enable;
196 	int sku_cap_ipan_enable;
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 	uint8_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_softc;
268 struct iwm_rbuf {
269 	struct iwm_softc	*sc;
270 	void			*vaddr;
271 	bus_addr_t		paddr;
272 };
273 
274 struct iwm_rx_data {
275 	struct mbuf	*m;
276 	bus_dmamap_t	map;
277 	int		wantresp;
278 };
279 
280 struct iwm_rx_ring {
281 	struct iwm_dma_info	desc_dma;
282 	struct iwm_dma_info	stat_dma;
283 	struct iwm_dma_info	buf_dma;
284 	uint32_t		*desc;
285 	struct iwm_rb_status	*stat;
286 	struct iwm_rx_data	data[IWM_RX_RING_COUNT];
287 	int			cur;
288 };
289 
290 #define IWM_FLAG_USE_ICT	0x01
291 #define IWM_FLAG_HW_INITED	0x02
292 #define IWM_FLAG_STOPPED	0x04
293 #define IWM_FLAG_RFKILL		0x08
294 #define IWM_FLAG_BUSY		0x10
295 #define IWM_FLAG_ATTACHED	0x20
296 
297 struct iwm_ucode_status {
298 	uint32_t uc_error_event_table;
299 	uint32_t uc_log_event_table;
300 
301 	int uc_ok;
302 	int uc_intr;
303 };
304 
305 #define IWM_CMD_RESP_MAX PAGE_SIZE
306 
307 #define IWM_OTP_LOW_IMAGE_SIZE 2048
308 
309 #define IWM_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS 500
310 #define IWM_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS 400
311 
312 /*
313  * Command headers are in iwl-trans.h, which is full of all
314  * kinds of other junk, so we just replicate the structures here.
315  * First the software bits:
316  */
317 enum IWM_CMD_MODE {
318 	IWM_CMD_SYNC		= 0,
319 	IWM_CMD_ASYNC		= (1 << 0),
320 	IWM_CMD_WANT_SKB	= (1 << 1),
321 	IWM_CMD_SEND_IN_RFKILL	= (1 << 2),
322 };
323 enum iwm_hcmd_dataflag {
324 	IWM_HCMD_DFL_NOCOPY     = (1 << 0),
325 	IWM_HCMD_DFL_DUP        = (1 << 1),
326 };
327 
328 /*
329  * iwlwifi/iwl-phy-db
330  */
331 
332 #define IWM_NUM_PAPD_CH_GROUPS	4
333 #define IWM_NUM_TXP_CH_GROUPS	9
334 
335 struct iwm_phy_db_entry {
336 	uint16_t size;
337 	uint8_t *data;
338 };
339 
340 struct iwm_phy_db {
341 	struct iwm_phy_db_entry	cfg;
342 	struct iwm_phy_db_entry	calib_nch;
343 	struct iwm_phy_db_entry	calib_ch_group_papd[IWM_NUM_PAPD_CH_GROUPS];
344 	struct iwm_phy_db_entry	calib_ch_group_txp[IWM_NUM_TXP_CH_GROUPS];
345 };
346 
347 struct iwm_int_sta {
348 	uint32_t sta_id;
349 	uint32_t tfd_queue_msk;
350 };
351 
352 struct iwm_mvm_phy_ctxt {
353 	uint16_t id;
354 	uint16_t color;
355 	uint32_t ref;
356 	struct ieee80211_channel *channel;
357 };
358 
359 struct iwm_bf_data {
360 	int bf_enabled;		/* filtering	*/
361 	int ba_enabled;		/* abort	*/
362 	int ave_beacon_signal;
363 	int last_cqm_event;
364 };
365 
366 struct iwm_softc {
367 	device_t sc_dev;
368 	struct ethercom sc_ec;
369 	struct ieee80211com sc_ic;
370 
371 	int (*sc_newstate)(struct ieee80211com *, enum ieee80211_state, int);
372 	int sc_newstate_pending;
373 
374 	struct ieee80211_amrr sc_amrr;
375 	struct callout sc_calib_to;
376 
377 	bus_space_tag_t sc_st;
378 	bus_space_handle_t sc_sh;
379 
380 	bus_size_t sc_sz;
381 	bus_dma_tag_t sc_dmat;
382 	pci_chipset_tag_t sc_pct;
383 	pcitag_t sc_pcitag;
384 	pcireg_t sc_pciid;
385 	const void *sc_ih;
386 
387 	/* TX scheduler rings. */
388 	struct iwm_dma_info		sched_dma;
389 	uint32_t			sched_base;
390 
391 	/* TX/RX rings. */
392 	struct iwm_tx_ring txq[IWM_MVM_MAX_QUEUES];
393 	struct iwm_rx_ring rxq;
394 	int qfullmsk;
395 
396 	int sc_sf_state;
397 
398 	/* ICT table. */
399 	struct iwm_dma_info	ict_dma;
400 	int			ict_cur;
401 
402 	int sc_hw_rev;
403 	int sc_hw_id;
404 
405 	struct iwm_dma_info kw_dma;
406 	struct iwm_dma_info fw_dma;
407 
408 	int sc_fw_chunk_done;
409 	int sc_init_complete;
410 
411 	struct iwm_ucode_status sc_uc;
412 	enum iwm_ucode_type sc_uc_current;
413 	int sc_fwver;
414 
415 	int sc_capaflags;
416 	int sc_capa_max_probe_len;
417 
418 	int sc_intmask;
419 	int sc_flags;
420 
421 	/*
422 	 * So why do we need a separate stopped flag and a generation?
423 	 * the former protects the device from issueing commands when it's
424 	 * stopped (duh).  The latter protects against race from a very
425 	 * fast stop/unstop cycle where threads waiting for responses do
426 	 * not have a chance to run in between.  Notably: we want to stop
427 	 * the device from interrupt context when it craps out, so we
428 	 * don't have the luxury of waiting for quiescense.
429 	 */
430 	int sc_generation;
431 
432 	int sc_cap_off; /* PCIe caps */
433 
434 	const char *sc_fwname;
435 	bus_size_t sc_fwdmasegsz;
436 	struct iwm_fw_info sc_fw;
437 	int sc_fw_phy_config;
438 	struct iwm_tlv_calib_ctrl sc_default_calib[IWM_UCODE_TYPE_MAX];
439 
440 	struct iwm_nvm_data sc_nvm;
441 	struct iwm_phy_db sc_phy_db;
442 
443 	struct iwm_bf_data sc_bf;
444 
445 	int sc_tx_timer;
446 
447 	struct iwm_scan_cmd *sc_scan_cmd;
448 	size_t sc_scan_cmd_len;
449 	int sc_scan_last_antenna;
450 	int sc_scanband;
451 
452 	int sc_auth_prot;
453 
454 	int sc_fixed_ridx;
455 
456 	int sc_staid;
457 	int sc_nodecolor;
458 
459 	uint8_t sc_cmd_resp[IWM_CMD_RESP_MAX];
460 	int sc_wantresp;
461 
462 	struct workqueue *sc_nswq, *sc_eswq;
463 	struct work sc_eswk;
464 
465 	struct iwm_rx_phy_info sc_last_phy_info;
466 	int sc_ampdu_ref;
467 
468 	struct iwm_int_sta sc_aux_sta;
469 
470 	/* phy contexts.  we only use the first one */
471 	struct iwm_mvm_phy_ctxt sc_phyctxt[IWM_NUM_PHY_CTX];
472 
473 	struct iwm_notif_statistics sc_stats;
474 	int sc_noise;
475 
476 	struct bpf_if *		sc_drvbpf;
477 
478 	union {
479 		struct iwm_rx_radiotap_header th;
480 		uint8_t	pad[IEEE80211_RADIOTAP_HDRLEN];
481 	} sc_rxtapu;
482 #define sc_rxtap	sc_rxtapu.th
483 	int			sc_rxtap_len;
484 
485 	union {
486 		struct iwm_tx_radiotap_header th;
487 		uint8_t	pad[IEEE80211_RADIOTAP_HDRLEN];
488 	} sc_txtapu;
489 #define sc_txtap	sc_txtapu.th
490 	int			sc_txtap_len;
491 };
492 
493 struct iwm_node {
494 	struct ieee80211_node in_ni;
495 	struct iwm_mvm_phy_ctxt *in_phyctxt;
496 
497 	uint16_t in_id;
498 	uint16_t in_color;
499 	int in_tsfid;
500 
501 	/* status "bits" */
502 	int in_assoc;
503 
504 	struct iwm_lq_cmd in_lq;
505 	struct ieee80211_amrr_node in_amn;
506 
507 	uint8_t in_ridx[IEEE80211_RATE_MAXSIZE];
508 };
509 #define IWM_STATION_ID 0
510 
511 #define IWM_ICT_SIZE		4096
512 #define IWM_ICT_COUNT		(IWM_ICT_SIZE / sizeof (uint32_t))
513 #define IWM_ICT_PADDR_SHIFT	12
514