xref: /openbsd-src/sys/dev/pci/if_iwmvar.h (revision f1dd7b858388b4a23f4f67a4957ec5ff656ebbe8)
1 /*	$OpenBSD: if_iwmvar.h,v 1.62 2021/05/10 08:28:00 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 } __packed;
132 
133 #define IWM_TX_RADIOTAP_PRESENT						\
134 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
135 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
136 	 (1 << IEEE80211_RADIOTAP_CHANNEL))
137 
138 #define IWM_UCODE_SECT_MAX 16
139 #define IWM_FWDMASEGSZ (192*1024)
140 #define IWM_FWDMASEGSZ_8000 (320*1024)
141 /* sanity check value */
142 #define IWM_FWMAXSIZE (2*1024*1024)
143 
144 /*
145  * fw_status is used to determine if we've already parsed the firmware file
146  *
147  * In addition to the following, status < 0 ==> -error
148  */
149 #define IWM_FW_STATUS_NONE		0
150 #define IWM_FW_STATUS_INPROGRESS	1
151 #define IWM_FW_STATUS_DONE		2
152 
153 enum iwm_ucode_type {
154 	IWM_UCODE_TYPE_REGULAR,
155 	IWM_UCODE_TYPE_INIT,
156 	IWM_UCODE_TYPE_WOW,
157 	IWM_UCODE_TYPE_REGULAR_USNIFFER,
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 		} fw_sect[IWM_UCODE_SECT_MAX];
172 		size_t fw_totlen;
173 		int fw_count;
174 		uint32_t paging_mem_size;
175 	} fw_sects[IWM_UCODE_TYPE_MAX];
176 };
177 
178 struct iwm_nvm_data {
179 	int n_hw_addrs;
180 	uint8_t hw_addr[ETHER_ADDR_LEN];
181 
182 	uint8_t calib_version;
183 	uint16_t calib_voltage;
184 
185 	uint16_t raw_temperature;
186 	uint16_t kelvin_temperature;
187 	uint16_t kelvin_voltage;
188 	uint16_t xtal_calib[2];
189 
190 	int sku_cap_band_24GHz_enable;
191 	int sku_cap_band_52GHz_enable;
192 	int sku_cap_11n_enable;
193 	int sku_cap_amt_enable;
194 	int sku_cap_ipan_enable;
195 	int sku_cap_mimo_disable;
196 
197 	uint8_t radio_cfg_type;
198 	uint8_t radio_cfg_step;
199 	uint8_t radio_cfg_dash;
200 	uint8_t radio_cfg_pnum;
201 	uint8_t valid_tx_ant, valid_rx_ant;
202 
203 	uint16_t nvm_version;
204 	uint8_t max_tx_pwr_half_dbm;
205 
206 	int lar_enabled;
207 };
208 
209 /* max bufs per tfd the driver will use */
210 #define IWM_MAX_CMD_TBS_PER_TFD 2
211 
212 struct iwm_host_cmd {
213 	const void *data[IWM_MAX_CMD_TBS_PER_TFD];
214 	struct iwm_rx_packet *resp_pkt;
215 	size_t resp_pkt_len;
216 	unsigned long _rx_page_addr;
217 	uint32_t _rx_page_order;
218 	int handler_status;
219 
220 	uint32_t flags;
221 	uint16_t len[IWM_MAX_CMD_TBS_PER_TFD];
222 	uint8_t dataflags[IWM_MAX_CMD_TBS_PER_TFD];
223 	uint32_t id;
224 };
225 
226 /*
227  * DMA glue is from iwn
228  */
229 
230 struct iwm_dma_info {
231 	bus_dma_tag_t		tag;
232 	bus_dmamap_t		map;
233 	bus_dma_segment_t	seg;
234 	bus_addr_t		paddr;
235 	void 			*vaddr;
236 	bus_size_t		size;
237 };
238 
239 /**
240  * struct iwm_fw_paging
241  * @fw_paging_block: dma memory info
242  * @fw_paging_size: page size
243  */
244 struct iwm_fw_paging {
245 	struct iwm_dma_info fw_paging_block;
246 	uint32_t fw_paging_size;
247 };
248 
249 #define IWM_TX_RING_COUNT	256
250 #define IWM_TX_RING_LOMARK	192
251 #define IWM_TX_RING_HIMARK	224
252 
253 /* For aggregation queues, index must be aligned to frame sequence number. */
254 #define IWM_AGG_SSN_TO_TXQ_IDX(x)	((x) & (IWM_TX_RING_COUNT - 1))
255 
256 struct iwm_tx_data {
257 	bus_dmamap_t	map;
258 	bus_addr_t	cmd_paddr;
259 	bus_addr_t	scratch_paddr;
260 	struct mbuf	*m;
261 	struct iwm_node *in;
262 	int txmcs;
263 	int txrate;
264 
265 	/* A-MPDU subframes */
266 	int ampdu_txmcs;
267 	int ampdu_nframes;
268 };
269 
270 struct iwm_tx_ring {
271 	struct iwm_dma_info	desc_dma;
272 	struct iwm_dma_info	cmd_dma;
273 	struct iwm_tfd		*desc;
274 	struct iwm_device_cmd	*cmd;
275 	struct iwm_tx_data	data[IWM_TX_RING_COUNT];
276 	int			qid;
277 	int			queued;
278 	int			cur;
279 	int			tail;
280 };
281 
282 #define IWM_RX_MQ_RING_COUNT	512
283 #define IWM_RX_RING_COUNT	256
284 /* Linux driver optionally uses 8k buffer */
285 #define IWM_RBUF_SIZE		4096
286 
287 struct iwm_rx_data {
288 	struct mbuf	*m;
289 	bus_dmamap_t	map;
290 };
291 
292 struct iwm_rx_ring {
293 	struct iwm_dma_info	free_desc_dma;
294 	struct iwm_dma_info	stat_dma;
295 	struct iwm_dma_info	used_desc_dma;
296 	struct iwm_dma_info	buf_dma;
297 	void			*desc;
298 	struct iwm_rb_status	*stat;
299 	struct iwm_rx_data	data[IWM_RX_MQ_RING_COUNT];
300 	int			cur;
301 };
302 
303 #define IWM_FLAG_USE_ICT	0x01	/* using Interrupt Cause Table */
304 #define IWM_FLAG_RFKILL		0x02	/* radio kill switch is set */
305 #define IWM_FLAG_SCANNING	0x04	/* scan in progress */
306 #define IWM_FLAG_MAC_ACTIVE	0x08	/* MAC context added to firmware */
307 #define IWM_FLAG_BINDING_ACTIVE	0x10	/* MAC->PHY binding added to firmware */
308 #define IWM_FLAG_STA_ACTIVE	0x20	/* AP added to firmware station table */
309 #define IWM_FLAG_TE_ACTIVE	0x40	/* time event is scheduled */
310 #define IWM_FLAG_HW_ERR		0x80	/* hardware error occurred */
311 #define IWM_FLAG_SHUTDOWN	0x100	/* shutting down; new tasks forbidden */
312 #define IWM_FLAG_BGSCAN		0x200	/* background scan in progress */
313 #define IWM_FLAG_TXFLUSH	0x400	/* Tx queue flushing in progress */
314 
315 struct iwm_ucode_status {
316 	uint32_t uc_error_event_table;
317 	uint32_t uc_umac_error_event_table;
318 	uint32_t uc_log_event_table;
319 
320 	int uc_ok;
321 	int uc_intr;
322 };
323 
324 #define IWM_CMD_RESP_MAX PAGE_SIZE
325 
326 /* lower blocks contain EEPROM image and calibration data */
327 #define IWM_OTP_LOW_IMAGE_SIZE_FAMILY_7000 	16384
328 #define IWM_OTP_LOW_IMAGE_SIZE_FAMILY_8000	32768
329 
330 #define IWM_TE_SESSION_PROTECTION_MAX_TIME_MS 1000
331 #define IWM_TE_SESSION_PROTECTION_MIN_TIME_MS 400
332 
333 enum IWM_CMD_MODE {
334 	IWM_CMD_ASYNC		= (1 << 0),
335 	IWM_CMD_WANT_RESP	= (1 << 1),
336 	IWM_CMD_SEND_IN_RFKILL	= (1 << 2),
337 };
338 enum iwm_hcmd_dataflag {
339 	IWM_HCMD_DFL_NOCOPY     = (1 << 0),
340 	IWM_HCMD_DFL_DUP        = (1 << 1),
341 };
342 
343 #define IWM_NUM_PAPD_CH_GROUPS	9
344 #define IWM_NUM_TXP_CH_GROUPS	9
345 
346 struct iwm_phy_db_entry {
347 	uint16_t size;
348 	uint8_t *data;
349 };
350 
351 struct iwm_phy_db {
352 	struct iwm_phy_db_entry	cfg;
353 	struct iwm_phy_db_entry	calib_nch;
354 	struct iwm_phy_db_entry	calib_ch_group_papd[IWM_NUM_PAPD_CH_GROUPS];
355 	struct iwm_phy_db_entry	calib_ch_group_txp[IWM_NUM_TXP_CH_GROUPS];
356 };
357 
358 struct iwm_phy_ctxt {
359 	uint16_t id;
360 	uint16_t color;
361 	uint32_t ref;
362 	struct ieee80211_channel *channel;
363 };
364 
365 struct iwm_bf_data {
366 	int bf_enabled;		/* filtering	*/
367 	int ba_enabled;		/* abort	*/
368 	int ave_beacon_signal;
369 	int last_cqm_event;
370 };
371 
372 /**
373  * struct iwm_reorder_buffer - per ra/tid/queue reorder buffer
374  * @head_sn: reorder window head sn
375  * @num_stored: number of mpdus stored in the buffer
376  * @buf_size: the reorder buffer size as set by the last addba request
377  * @queue: queue of this reorder buffer
378  * @last_amsdu: track last ASMDU SN for duplication detection
379  * @last_sub_index: track ASMDU sub frame index for duplication detection
380  * @reorder_timer: timer for frames are in the reorder buffer. For AMSDU
381  *	it is the time of last received sub-frame
382  * @removed: prevent timer re-arming
383  * @valid: reordering is valid for this queue
384  * @consec_oldsn_drops: consecutive drops due to old SN
385  * @consec_oldsn_ampdu_gp2: A-MPDU GP2 timestamp to track
386  *	when to apply old SN consecutive drop workaround
387  * @consec_oldsn_prev_drop: track whether or not an MPDU
388  *	that was single/part of the previous A-MPDU was
389  *	dropped due to old SN
390  */
391 struct iwm_reorder_buffer {
392 	uint16_t head_sn;
393 	uint16_t num_stored;
394 	uint16_t buf_size;
395 	uint16_t last_amsdu;
396 	uint8_t last_sub_index;
397 	struct timeout reorder_timer;
398 	int removed;
399 	int valid;
400 	unsigned int consec_oldsn_drops;
401 	uint32_t consec_oldsn_ampdu_gp2;
402 	unsigned int consec_oldsn_prev_drop;
403 #define IWM_AMPDU_CONSEC_DROPS_DELBA	10
404 };
405 
406 /**
407  * struct iwm_reorder_buf_entry - reorder buffer entry per frame sequence number
408  * @frames: list of mbufs stored (A-MSDU subframes share a sequence number)
409  * @reorder_time: time the packet was stored in the reorder buffer
410  */
411 struct iwm_reorder_buf_entry {
412 	struct mbuf_list frames;
413 	struct timeval reorder_time;
414 	uint32_t rx_pkt_status;
415 	int chanidx;
416 	int is_shortpre;
417 	uint32_t rate_n_flags;
418 	uint32_t device_timestamp;
419 	struct ieee80211_rxinfo rxi;
420 };
421 
422 /**
423  * struct iwm_rxba_data - BA session data
424  * @sta_id: station id
425  * @tid: tid of the session
426  * @baid: baid of the session
427  * @timeout: the timeout set in the addba request
428  * @entries_per_queue: # of buffers per queue
429  * @last_rx: last rx timestamp, updated only if timeout passed from last update
430  * @session_timer: timer to check if BA session expired, runs at 2 * timeout
431  * @sc: softc pointer, needed for timer context
432  * @reorder_buf: reorder buffer
433  * @reorder_buf_data: buffered frames, one entry per sequence number
434  */
435 struct iwm_rxba_data {
436 	uint8_t sta_id;
437 	uint8_t tid;
438 	uint8_t baid;
439 	uint16_t timeout;
440 	uint16_t entries_per_queue;
441 	struct timeval last_rx;
442 	struct timeout session_timer;
443 	struct iwm_softc *sc;
444 	struct iwm_reorder_buffer reorder_buf;
445 	struct iwm_reorder_buf_entry entries[IEEE80211_BA_MAX_WINSZ];
446 };
447 
448 static inline struct iwm_rxba_data *
449 iwm_rxba_data_from_reorder_buf(struct iwm_reorder_buffer *buf)
450 {
451 	return (void *)((uint8_t *)buf -
452 			offsetof(struct iwm_rxba_data, reorder_buf));
453 }
454 
455 /**
456  * struct iwm_rxq_dup_data - per station per rx queue data
457  * @last_seq: last sequence per tid for duplicate packet detection
458  * @last_sub_frame: last subframe packet
459  */
460 struct iwm_rxq_dup_data {
461 	uint16_t last_seq[IWM_MAX_TID_COUNT + 1];
462 	uint8_t last_sub_frame[IWM_MAX_TID_COUNT + 1];
463 };
464 
465 struct iwm_ba_task_data {
466 	uint32_t		start_tidmask;
467 	uint32_t		stop_tidmask;
468 };
469 
470 struct iwm_softc {
471 	struct device sc_dev;
472 	struct ieee80211com sc_ic;
473 	int (*sc_newstate)(struct ieee80211com *, enum ieee80211_state, int);
474 	int sc_newstate_pending;
475 
476 	struct ieee80211_amrr sc_amrr;
477 	struct timeout sc_calib_to;
478 	struct timeout sc_led_blink_to;
479 
480 	struct task		init_task; /* NB: not reference-counted */
481 	struct refcnt		task_refs;
482 	struct task		newstate_task;
483 	enum ieee80211_state	ns_nstate;
484 	int			ns_arg;
485 
486 	/* Task for firmware BlockAck setup/teardown and its arguments. */
487 	struct task		ba_task;
488 	struct iwm_ba_task_data	ba_rx;
489 	struct iwm_ba_task_data	ba_tx;
490 
491 	/* Task for ERP/HT prot/slot-time/EDCA updates. */
492 	struct task		mac_ctxt_task;
493 
494 	bus_space_tag_t sc_st;
495 	bus_space_handle_t sc_sh;
496 	bus_size_t sc_sz;
497 	bus_dma_tag_t sc_dmat;
498 	pci_chipset_tag_t sc_pct;
499 	pcitag_t sc_pcitag;
500 	const void *sc_ih;
501 	int sc_msix;
502 
503 	/* TX scheduler rings. */
504 	struct iwm_dma_info		sched_dma;
505 	uint32_t			sched_base;
506 
507 	/* TX/RX rings. */
508 	struct iwm_tx_ring txq[IWM_MAX_QUEUES];
509 	struct iwm_rx_ring rxq;
510 	int qfullmsk;
511 	int qenablemsk;
512 	int cmdqid;
513 
514 	int sc_sf_state;
515 
516 	/* ICT table. */
517 	struct iwm_dma_info	ict_dma;
518 	int			ict_cur;
519 
520 	int sc_hw_rev;
521 #define IWM_SILICON_A_STEP	0
522 #define IWM_SILICON_B_STEP	1
523 #define IWM_SILICON_C_STEP	2
524 #define IWM_SILICON_D_STEP	3
525 	int sc_hw_id;
526 	int sc_device_family;
527 #define IWM_DEVICE_FAMILY_7000	1
528 #define IWM_DEVICE_FAMILY_8000	2
529 #define IWM_DEVICE_FAMILY_9000	3
530 
531 	struct iwm_dma_info kw_dma;
532 	struct iwm_dma_info fw_dma;
533 
534 	int sc_fw_chunk_done;
535 	int sc_init_complete;
536 #define IWM_INIT_COMPLETE	0x01
537 #define IWM_CALIB_COMPLETE	0x02
538 
539 	struct iwm_ucode_status sc_uc;
540 	enum iwm_ucode_type sc_uc_current;
541 	char sc_fwver[32];
542 
543 	int sc_capaflags;
544 	int sc_capa_max_probe_len;
545 	int sc_capa_n_scan_channels;
546 	uint8_t sc_ucode_api[howmany(IWM_NUM_UCODE_TLV_API, NBBY)];
547 	uint8_t sc_enabled_capa[howmany(IWM_NUM_UCODE_TLV_CAPA, NBBY)];
548 	char sc_fw_mcc[3];
549 
550 	int sc_intmask;
551 	int sc_flags;
552 
553 	uint32_t sc_fh_init_mask;
554 	uint32_t sc_hw_init_mask;
555 	uint32_t sc_fh_mask;
556 	uint32_t sc_hw_mask;
557 
558 	/*
559 	 * So why do we need a separate stopped flag and a generation?
560 	 * the former protects the device from issueing commands when it's
561 	 * stopped (duh).  The latter protects against race from a very
562 	 * fast stop/unstop cycle where threads waiting for responses do
563 	 * not have a chance to run in between.  Notably: we want to stop
564 	 * the device from interrupt context when it craps out, so we
565 	 * don't have the luxury of waiting for quiescense.
566 	 */
567 	int sc_generation;
568 
569 	struct rwlock ioctl_rwl;
570 
571 	int sc_cap_off; /* PCIe caps */
572 
573 	const char *sc_fwname;
574 	bus_size_t sc_fwdmasegsz;
575 	size_t sc_nvm_max_section_size;
576 	struct iwm_fw_info sc_fw;
577 	int sc_fw_phy_config;
578 	struct iwm_tlv_calib_ctrl sc_default_calib[IWM_UCODE_TYPE_MAX];
579 
580 	struct iwm_nvm_data sc_nvm;
581 	struct iwm_phy_db sc_phy_db;
582 
583 	struct iwm_bf_data sc_bf;
584 
585 	int sc_tx_timer;
586 	int sc_rx_ba_sessions;
587 	int tx_ba_queue_mask;
588 
589 	int sc_scan_last_antenna;
590 
591 	int sc_fixed_ridx;
592 
593 	int sc_staid;
594 	int sc_nodecolor;
595 
596 	uint8_t *sc_cmd_resp_pkt[IWM_TX_RING_COUNT];
597 	size_t sc_cmd_resp_len[IWM_TX_RING_COUNT];
598 	int sc_nic_locks;
599 
600 	struct taskq *sc_nswq;
601 
602 	struct iwm_rx_phy_info sc_last_phy_info;
603 	int sc_ampdu_ref;
604 #define IWM_MAX_BAID	32
605 	struct iwm_rxba_data sc_rxba_data[IWM_MAX_BAID];
606 
607 	uint32_t sc_time_event_uid;
608 
609 	/* phy contexts.  we only use the first one */
610 	struct iwm_phy_ctxt sc_phyctxt[IWM_NUM_PHY_CTX];
611 
612 	struct iwm_notif_statistics sc_stats;
613 	int sc_noise;
614 
615 	int host_interrupt_operation_mode;
616 	int sc_ltr_enabled;
617 	enum iwm_nvm_type nvm_type;
618 
619 	int sc_mqrx_supported;
620 	int sc_integrated;
621 
622 	/*
623 	 * Paging parameters - All of the parameters should be set by the
624 	 * opmode when paging is enabled
625 	 */
626 	struct iwm_fw_paging fw_paging_db[IWM_NUM_OF_FW_PAGING_BLOCKS];
627 	uint16_t num_of_paging_blk;
628 	uint16_t num_of_pages_in_last_blk;
629 
630 #if NBPFILTER > 0
631 	caddr_t			sc_drvbpf;
632 
633 	union {
634 		struct iwm_rx_radiotap_header th;
635 		uint8_t	pad[IEEE80211_RADIOTAP_HDRLEN];
636 	} sc_rxtapu;
637 #define sc_rxtap	sc_rxtapu.th
638 	int			sc_rxtap_len;
639 
640 	union {
641 		struct iwm_tx_radiotap_header th;
642 		uint8_t	pad[IEEE80211_RADIOTAP_HDRLEN];
643 	} sc_txtapu;
644 #define sc_txtap	sc_txtapu.th
645 	int			sc_txtap_len;
646 #endif
647 };
648 
649 struct iwm_node {
650 	struct ieee80211_node in_ni;
651 	struct iwm_phy_ctxt *in_phyctxt;
652 
653 	uint16_t in_id;
654 	uint16_t in_color;
655 
656 	struct ieee80211_amrr_node in_amn;
657 	struct ieee80211_ra_node in_rn;
658 	int lq_rate_mismatch;
659 
660 	struct iwm_rxq_dup_data dup_data;
661 
662 	/* For use with the ADD_STA command. */
663 	uint32_t tfd_queue_msk;
664 	uint16_t tid_disable_ampdu;
665 };
666 #define IWM_STATION_ID 0
667 #define IWM_AUX_STA_ID 1
668 #define IWM_MONITOR_STA_ID 2
669 
670 #define IWM_ICT_SIZE		4096
671 #define IWM_ICT_COUNT		(IWM_ICT_SIZE / sizeof (uint32_t))
672 #define IWM_ICT_PADDR_SHIFT	12
673