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