1 /* $OpenBSD: if_iwmvar.h,v 1.7 2015/03/02 13:51:10 jsg 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 __aligned(8);
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
139 #define IWM_UCODE_SECTION_MAX 16
140
141 /**
142 * enum iwm_ucode_type
143 *
144 * The type of ucode.
145 *
146 * @IWM_UCODE_REGULAR: Normal runtime ucode
147 * @IWM_UCODE_INIT: Initial ucode
148 * @IWM_UCODE_WOWLAN: Wake on Wireless enabled ucode
149 * @IWM_UCODE_REGULAR_USNIFFER: Normal runtime ucode when using usniffer image
150 */
151 enum iwm_ucode_type {
152 IWM_UCODE_REGULAR,
153 IWM_UCODE_INIT,
154 IWM_UCODE_WOWLAN,
155 IWM_UCODE_REGULAR_USNIFFER,
156 IWM_UCODE_TYPE_MAX
157 };
158
159 struct iwm_ucode_capabilities {
160 uint32_t max_probe_length;
161 uint32_t n_scan_channels;
162 uint32_t flags;
163 uint8_t enabled_api[howmany(IWM_NUM_UCODE_TLV_API, NBBY)];
164 uint8_t enabled_capa[howmany(IWM_NUM_UCODE_TLV_CAPA, NBBY)];
165 };
166
167 /* one for each uCode image (inst/data, init/runtime/wowlan) */
168 struct iwm_fw_desc {
169 const void *data; /* vmalloc'ed data */
170 uint32_t len; /* size in bytes */
171 uint32_t offset; /* offset in the device */
172 };
173
174 struct iwm_fw_img {
175 struct iwm_fw_desc sec[IWM_UCODE_SECTION_MAX];
176 int fw_count;
177 int is_dual_cpus;
178 uint32_t paging_mem_size;
179 };
180
181 struct iwm_fw_info {
182 const struct firmware *fw_fp;
183
184 /* ucode images */
185 struct iwm_fw_img img[IWM_UCODE_TYPE_MAX];
186
187 struct iwm_ucode_capabilities ucode_capa;
188
189 uint32_t phy_config;
190 uint8_t valid_tx_ant;
191 uint8_t valid_rx_ant;
192 };
193
194 struct iwm_nvm_data {
195 int n_hw_addrs;
196 uint8_t hw_addr[IEEE80211_ADDR_LEN];
197
198 int sku_cap_band_24GHz_enable;
199 int sku_cap_band_52GHz_enable;
200 int sku_cap_11n_enable;
201 int sku_cap_amt_enable;
202 int sku_cap_ipan_enable;
203
204 uint8_t radio_cfg_type;
205 uint8_t radio_cfg_step;
206 uint8_t radio_cfg_dash;
207 uint8_t radio_cfg_pnum;
208 uint8_t valid_tx_ant, valid_rx_ant;
209 #define IWM_NUM_CHANNELS 39
210 #define IWM_NUM_CHANNELS_8000 51
211
212 uint16_t nvm_version;
213 uint8_t max_tx_pwr_half_dbm;
214
215 boolean_t lar_enabled;
216 uint16_t nvm_ch_flags[];
217 };
218
219 /* max bufs per tfd the driver will use */
220 #define IWM_MAX_CMD_TBS_PER_TFD 2
221
222 struct iwm_rx_packet;
223 struct iwm_host_cmd {
224 const void *data[IWM_MAX_CMD_TBS_PER_TFD];
225 struct iwm_rx_packet *resp_pkt;
226 unsigned long _rx_page_addr;
227 uint32_t _rx_page_order;
228 int handler_status;
229
230 uint32_t flags;
231 uint32_t id;
232 uint16_t len[IWM_MAX_CMD_TBS_PER_TFD];
233 uint8_t dataflags[IWM_MAX_CMD_TBS_PER_TFD];
234 };
235
236 /*
237 * DMA glue is from iwn
238 */
239
240 typedef caddr_t iwm_caddr_t;
241 typedef void *iwm_hookarg_t;
242
243 struct iwm_dma_info {
244 bus_dma_tag_t tag;
245 bus_dmamap_t map;
246 bus_dma_segment_t seg;
247 bus_addr_t paddr;
248 void *vaddr;
249 bus_size_t size;
250 };
251
252 /**
253 * struct iwm_fw_paging
254 * @fw_paging_block: dma memory info
255 * @fw_paging_size: page size
256 */
257 struct iwm_fw_paging {
258 struct iwm_dma_info fw_paging_block;
259 uint32_t fw_paging_size;
260 };
261
262 #define IWM_TX_RING_COUNT 256
263 #define IWM_TX_RING_LOMARK 192
264 #define IWM_TX_RING_HIMARK 224
265
266 struct iwm_tx_data {
267 bus_dmamap_t map;
268 bus_addr_t cmd_paddr;
269 bus_addr_t scratch_paddr;
270 struct mbuf *m;
271 struct iwm_node *in;
272 int done;
273 };
274
275 struct iwm_tx_ring {
276 struct iwm_dma_info desc_dma;
277 struct iwm_dma_info cmd_dma;
278 struct iwm_tfd *desc;
279 struct iwm_device_cmd *cmd;
280 bus_dma_tag_t data_dmat;
281 struct iwm_tx_data data[IWM_TX_RING_COUNT];
282 int qid;
283 int queued;
284 int cur;
285 };
286
287 #define IWM_RX_LEGACY_RING_COUNT 256
288 #define IWM_RX_MQ_RING_COUNT 512
289
290 #define IWM_RBUF_SIZE 4096
291
292 #define IWM_MAX_SCATTER 20
293
294 struct iwm_rx_data {
295 struct mbuf *m;
296 bus_dmamap_t map;
297 };
298
299 struct iwm_rx_ring {
300 struct iwm_dma_info free_desc_dma;
301 struct iwm_dma_info used_desc_dma;
302 struct iwm_dma_info stat_dma;
303 struct iwm_dma_info buf_dma;
304 void *desc;
305 struct iwm_rb_status *stat;
306 struct iwm_rx_data data[512];
307 bus_dmamap_t spare_map; /* for iwm_rx_addbuf() */
308 bus_dma_tag_t data_dmat;
309 int cur;
310 };
311
312 #define IWM_CMD_RESP_MAX PAGE_SIZE
313
314 #define IWM_TE_SESSION_PROTECTION_MAX_TIME_MS 500
315 #define IWM_TE_SESSION_PROTECTION_MIN_TIME_MS 400
316
317 /*
318 * Command headers are in iwl-trans.h, which is full of all
319 * kinds of other junk, so we just replicate the structures here.
320 * First the software bits:
321 */
322 enum IWM_CMD_MODE {
323 IWM_CMD_SYNC = 0,
324 IWM_CMD_ASYNC = (1 << 0),
325 IWM_CMD_WANT_SKB = (1 << 1),
326 IWM_CMD_SEND_IN_RFKILL = (1 << 2),
327 };
328 enum iwm_hcmd_dataflag {
329 IWM_HCMD_DFL_NOCOPY = (1 << 0),
330 IWM_HCMD_DFL_DUP = (1 << 1),
331 };
332
333 struct iwm_int_sta {
334 uint32_t sta_id;
335 uint32_t tfd_queue_msk;
336 };
337
338 struct iwm_phy_ctxt {
339 uint16_t id;
340 uint16_t color;
341 uint32_t ref;
342 struct ieee80211_channel *channel;
343 };
344
345 struct iwm_bf_data {
346 int bf_enabled; /* filtering */
347 int ba_enabled; /* abort */
348 int ave_beacon_signal;
349 int last_cqm_event;
350 };
351
352 struct iwm_vap {
353 struct ieee80211vap iv_vap;
354 int is_uploaded;
355 int iv_auth;
356
357 int (*iv_newstate)(struct ieee80211vap *,
358 enum ieee80211_state, int);
359
360 struct iwm_phy_ctxt *phy_ctxt;
361
362 uint16_t id;
363 uint16_t color;
364
365 boolean_t have_wme;
366 /*
367 * QoS data from net80211, need to store this here
368 * as net80211 has a separate callback but we need
369 * to have the data for the MAC context
370 */
371 struct {
372 uint16_t cw_min;
373 uint16_t cw_max;
374 uint16_t edca_txop;
375 uint8_t aifsn;
376 } queue_params[WME_NUM_AC];
377
378 /* indicates that this interface requires PS to be disabled */
379 boolean_t ps_disabled;
380 };
381 #define IWM_VAP(_vap) ((struct iwm_vap *)(_vap))
382
383 struct iwm_node {
384 struct ieee80211_node in_ni;
385
386 /* status "bits" */
387 int in_assoc;
388
389 struct iwm_lq_cmd in_lq;
390 };
391 #define IWM_NODE(_ni) ((struct iwm_node *)(_ni))
392
393 #define IWM_STATION_ID 0
394 #define IWM_AUX_STA_ID 1
395
396 #define IWM_DEFAULT_MACID 0
397 #define IWM_DEFAULT_COLOR 0
398 #define IWM_DEFAULT_TSFID 0
399
400 #define IWM_ICT_SIZE 4096
401 #define IWM_ICT_COUNT (IWM_ICT_SIZE / sizeof (uint32_t))
402 #define IWM_ICT_PADDR_SHIFT 12
403
404 struct iwm_cfg;
405
406 struct iwm_softc {
407 device_t sc_dev;
408 uint32_t sc_debug;
409 int sc_attached;
410
411 struct mtx sc_mtx;
412 struct mbufq sc_snd;
413 struct ieee80211com sc_ic;
414 struct ieee80211_ratectl_tx_status sc_txs;
415
416 int sc_flags;
417 #define IWM_FLAG_USE_ICT (1 << 0)
418 #define IWM_FLAG_HW_INITED (1 << 1)
419 #define IWM_FLAG_STOPPED (1 << 2)
420 #define IWM_FLAG_RFKILL (1 << 3)
421 #define IWM_FLAG_BUSY (1 << 4)
422 #define IWM_FLAG_SCANNING (1 << 5)
423 #define IWM_FLAG_SCAN_RUNNING (1 << 6)
424 #define IWM_FLAG_TE_ACTIVE (1 << 7)
425
426 struct intr_config_hook sc_preinit_hook;
427 struct callout sc_watchdog_to;
428 struct callout sc_led_blink_to;
429
430 struct task init_task;
431
432 struct resource *sc_irq;
433 struct resource *sc_mem;
434 bus_space_tag_t sc_st;
435 bus_space_handle_t sc_sh;
436 bus_size_t sc_sz;
437 bus_dma_tag_t sc_dmat;
438 void *sc_ih;
439
440 /* TX scheduler rings. */
441 struct iwm_dma_info sched_dma;
442 uint32_t scd_base_addr;
443
444 /* TX/RX rings. */
445 struct iwm_tx_ring txq[IWM_MAX_QUEUES];
446 struct iwm_rx_ring rxq;
447 int qfullmsk;
448
449 /* ICT table. */
450 struct iwm_dma_info ict_dma;
451 int ict_cur;
452
453 int sc_hw_rev;
454 int sc_hw_id;
455
456 struct iwm_dma_info kw_dma;
457 struct iwm_dma_info fw_dma;
458
459 int sc_fw_chunk_done;
460
461 enum iwm_ucode_type cur_ucode;
462 int ucode_loaded;
463 char sc_fwver[32];
464
465 char sc_fw_mcc[3];
466
467 int sc_intmask;
468
469 /*
470 * So why do we need a separate stopped flag and a generation?
471 * the former protects the device from issuing commands when it's
472 * stopped (duh). The latter protects against race from a very
473 * fast stop/unstop cycle where threads waiting for responses do
474 * not have a chance to run in between. Notably: we want to stop
475 * the device from interrupt context when it craps out, so we
476 * don't have the luxury of waiting for quiescense.
477 */
478 int sc_generation;
479
480 struct iwm_fw_info sc_fw;
481 struct iwm_tlv_calib_ctrl sc_default_calib[IWM_UCODE_TYPE_MAX];
482
483 const struct iwm_cfg *cfg;
484 struct iwm_nvm_data *nvm_data;
485 struct iwm_phy_db *sc_phy_db;
486
487 struct iwm_bf_data sc_bf;
488
489 int sc_tx_timer;
490
491 int sc_scan_last_antenna;
492
493 int sc_fixed_ridx;
494
495 int sc_staid;
496 int sc_nodecolor;
497
498 uint8_t sc_cmd_resp[IWM_CMD_RESP_MAX];
499 int sc_wantresp;
500
501 struct taskqueue *sc_tq;
502 struct task sc_es_task;
503 struct task sc_rftoggle_task;
504
505 struct iwm_rx_phy_info sc_last_phy_info;
506 int sc_ampdu_ref;
507
508 struct iwm_int_sta sc_aux_sta;
509
510 /* phy contexts. we only use the first one */
511 struct iwm_phy_ctxt sc_phyctxt[IWM_NUM_PHY_CTX];
512
513 struct iwm_notif_statistics sc_stats;
514 int sc_noise;
515
516 struct iwm_rx_radiotap_header sc_rxtap;
517 struct iwm_tx_radiotap_header sc_txtap;
518
519 int sc_max_rssi;
520
521 struct iwm_notif_wait_data *sc_notif_wait;
522
523 int cmd_hold_nic_awake;
524
525 /* Firmware status */
526 uint32_t error_event_table[2];
527 uint32_t log_event_table;
528 uint32_t umac_error_event_table;
529 int support_umac_log;
530
531 /*
532 * Paging parameters - All of the parameters should be set by the
533 * opmode when paging is enabled
534 */
535 struct iwm_fw_paging fw_paging_db[IWM_NUM_OF_FW_PAGING_BLOCKS];
536 uint16_t num_of_paging_blk;
537 uint16_t num_of_pages_in_last_blk;
538
539 boolean_t last_ebs_successful;
540
541 /* last smart fifo state that was successfully sent to firmware */
542 enum iwm_sf_state sf_state;
543
544 /* Indicate if device power save is allowed */
545 boolean_t sc_ps_disabled;
546
547 int sc_ltr_enabled;
548
549 /* Track firmware state for STA association. */
550 int sc_firmware_state;
551
552 /* Unique ID (assigned by the firmware) of the current Time Event. */
553 uint32_t sc_time_event_uid;
554
555 /* Duration of the Time Event in TU. */
556 uint32_t sc_time_event_duration;
557
558 /* Expected end of the Time Event in HZ ticks. */
559 int sc_time_event_end_ticks;
560 };
561
562 #define IWM_LOCK_INIT(_sc) \
563 mtx_init(&(_sc)->sc_mtx, device_get_nameunit((_sc)->sc_dev), \
564 MTX_NETWORK_LOCK, MTX_DEF);
565 #define IWM_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
566 #define IWM_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)
567 #define IWM_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->sc_mtx)
568
569 static inline bool
iwm_fw_has_api(struct iwm_softc * sc,unsigned int api)570 iwm_fw_has_api(struct iwm_softc *sc, unsigned int api)
571 {
572 return isset(sc->sc_fw.ucode_capa.enabled_api, api);
573 }
574
575 static inline bool
iwm_fw_has_capa(struct iwm_softc * sc,unsigned int capa)576 iwm_fw_has_capa(struct iwm_softc *sc, unsigned int capa)
577 {
578 return isset(sc->sc_fw.ucode_capa.enabled_capa, capa);
579 }
580