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