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