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