1 /* $OpenBSD: if_iwmvar.h,v 1.57 2020/10/11 07:05:28 mpi 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; 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 #define IWM_UCODE_SECT_MAX 16 139 #define IWM_FWDMASEGSZ (192*1024) 140 #define IWM_FWDMASEGSZ_8000 (320*1024) 141 /* sanity check value */ 142 #define IWM_FWMAXSIZE (2*1024*1024) 143 144 /* 145 * fw_status is used to determine if we've already parsed the firmware file 146 * 147 * In addition to the following, status < 0 ==> -error 148 */ 149 #define IWM_FW_STATUS_NONE 0 150 #define IWM_FW_STATUS_INPROGRESS 1 151 #define IWM_FW_STATUS_DONE 2 152 153 enum iwm_ucode_type { 154 IWM_UCODE_TYPE_REGULAR, 155 IWM_UCODE_TYPE_INIT, 156 IWM_UCODE_TYPE_WOW, 157 IWM_UCODE_TYPE_REGULAR_USNIFFER, 158 IWM_UCODE_TYPE_MAX 159 }; 160 161 struct iwm_fw_info { 162 void *fw_rawdata; 163 size_t fw_rawsize; 164 int fw_status; 165 166 struct iwm_fw_sects { 167 struct iwm_fw_onesect { 168 void *fws_data; 169 uint32_t fws_len; 170 uint32_t fws_devoff; 171 } fw_sect[IWM_UCODE_SECT_MAX]; 172 size_t fw_totlen; 173 int fw_count; 174 uint32_t paging_mem_size; 175 } fw_sects[IWM_UCODE_TYPE_MAX]; 176 }; 177 178 struct iwm_nvm_data { 179 int n_hw_addrs; 180 uint8_t hw_addr[ETHER_ADDR_LEN]; 181 182 uint8_t calib_version; 183 uint16_t calib_voltage; 184 185 uint16_t raw_temperature; 186 uint16_t kelvin_temperature; 187 uint16_t kelvin_voltage; 188 uint16_t xtal_calib[2]; 189 190 int sku_cap_band_24GHz_enable; 191 int sku_cap_band_52GHz_enable; 192 int sku_cap_11n_enable; 193 int sku_cap_amt_enable; 194 int sku_cap_ipan_enable; 195 int sku_cap_mimo_disable; 196 197 uint8_t radio_cfg_type; 198 uint8_t radio_cfg_step; 199 uint8_t radio_cfg_dash; 200 uint8_t radio_cfg_pnum; 201 uint8_t valid_tx_ant, valid_rx_ant; 202 203 uint16_t nvm_version; 204 uint8_t max_tx_pwr_half_dbm; 205 206 int lar_enabled; 207 }; 208 209 /* max bufs per tfd the driver will use */ 210 #define IWM_MAX_CMD_TBS_PER_TFD 2 211 212 struct iwm_host_cmd { 213 const void *data[IWM_MAX_CMD_TBS_PER_TFD]; 214 struct iwm_rx_packet *resp_pkt; 215 size_t resp_pkt_len; 216 unsigned long _rx_page_addr; 217 uint32_t _rx_page_order; 218 int handler_status; 219 220 uint32_t flags; 221 uint16_t len[IWM_MAX_CMD_TBS_PER_TFD]; 222 uint8_t dataflags[IWM_MAX_CMD_TBS_PER_TFD]; 223 uint32_t id; 224 }; 225 226 /* 227 * DMA glue is from iwn 228 */ 229 230 struct iwm_dma_info { 231 bus_dma_tag_t tag; 232 bus_dmamap_t map; 233 bus_dma_segment_t seg; 234 bus_addr_t paddr; 235 void *vaddr; 236 bus_size_t size; 237 }; 238 239 /** 240 * struct iwm_fw_paging 241 * @fw_paging_block: dma memory info 242 * @fw_paging_size: page size 243 */ 244 struct iwm_fw_paging { 245 struct iwm_dma_info fw_paging_block; 246 uint32_t fw_paging_size; 247 }; 248 249 #define IWM_TX_RING_COUNT 256 250 #define IWM_TX_RING_LOMARK 192 251 #define IWM_TX_RING_HIMARK 224 252 253 struct iwm_tx_data { 254 bus_dmamap_t map; 255 bus_addr_t cmd_paddr; 256 bus_addr_t scratch_paddr; 257 struct mbuf *m; 258 struct iwm_node *in; 259 int txmcs; 260 int txrate; 261 }; 262 263 struct iwm_tx_ring { 264 struct iwm_dma_info desc_dma; 265 struct iwm_dma_info cmd_dma; 266 struct iwm_tfd *desc; 267 struct iwm_device_cmd *cmd; 268 struct iwm_tx_data data[IWM_TX_RING_COUNT]; 269 int qid; 270 int queued; 271 int cur; 272 int tail; 273 }; 274 275 #define IWM_RX_MQ_RING_COUNT 512 276 #define IWM_RX_RING_COUNT 256 277 /* Linux driver optionally uses 8k buffer */ 278 #define IWM_RBUF_SIZE 4096 279 280 struct iwm_rx_data { 281 struct mbuf *m; 282 bus_dmamap_t map; 283 }; 284 285 struct iwm_rx_ring { 286 struct iwm_dma_info free_desc_dma; 287 struct iwm_dma_info stat_dma; 288 struct iwm_dma_info used_desc_dma; 289 struct iwm_dma_info buf_dma; 290 void *desc; 291 struct iwm_rb_status *stat; 292 struct iwm_rx_data data[IWM_RX_MQ_RING_COUNT]; 293 int cur; 294 }; 295 296 #define IWM_FLAG_USE_ICT 0x01 /* using Interrupt Cause Table */ 297 #define IWM_FLAG_RFKILL 0x02 /* radio kill switch is set */ 298 #define IWM_FLAG_SCANNING 0x04 /* scan in progress */ 299 #define IWM_FLAG_MAC_ACTIVE 0x08 /* MAC context added to firmware */ 300 #define IWM_FLAG_BINDING_ACTIVE 0x10 /* MAC->PHY binding added to firmware */ 301 #define IWM_FLAG_STA_ACTIVE 0x20 /* AP added to firmware station table */ 302 #define IWM_FLAG_TE_ACTIVE 0x40 /* time event is scheduled */ 303 #define IWM_FLAG_HW_ERR 0x80 /* hardware error occurred */ 304 #define IWM_FLAG_SHUTDOWN 0x100 /* shutting down; new tasks forbidden */ 305 #define IWM_FLAG_BGSCAN 0x200 /* background scan in progress */ 306 307 struct iwm_ucode_status { 308 uint32_t uc_error_event_table; 309 uint32_t uc_umac_error_event_table; 310 uint32_t uc_log_event_table; 311 312 int uc_ok; 313 int uc_intr; 314 }; 315 316 #define IWM_CMD_RESP_MAX PAGE_SIZE 317 318 /* lower blocks contain EEPROM image and calibration data */ 319 #define IWM_OTP_LOW_IMAGE_SIZE_FAMILY_7000 16384 320 #define IWM_OTP_LOW_IMAGE_SIZE_FAMILY_8000 32768 321 322 #define IWM_TE_SESSION_PROTECTION_MAX_TIME_MS 1000 323 #define IWM_TE_SESSION_PROTECTION_MIN_TIME_MS 400 324 325 enum IWM_CMD_MODE { 326 IWM_CMD_ASYNC = (1 << 0), 327 IWM_CMD_WANT_RESP = (1 << 1), 328 IWM_CMD_SEND_IN_RFKILL = (1 << 2), 329 }; 330 enum iwm_hcmd_dataflag { 331 IWM_HCMD_DFL_NOCOPY = (1 << 0), 332 IWM_HCMD_DFL_DUP = (1 << 1), 333 }; 334 335 #define IWM_NUM_PAPD_CH_GROUPS 9 336 #define IWM_NUM_TXP_CH_GROUPS 9 337 338 struct iwm_phy_db_entry { 339 uint16_t size; 340 uint8_t *data; 341 }; 342 343 struct iwm_phy_db { 344 struct iwm_phy_db_entry cfg; 345 struct iwm_phy_db_entry calib_nch; 346 struct iwm_phy_db_entry calib_ch_group_papd[IWM_NUM_PAPD_CH_GROUPS]; 347 struct iwm_phy_db_entry calib_ch_group_txp[IWM_NUM_TXP_CH_GROUPS]; 348 }; 349 350 struct iwm_phy_ctxt { 351 uint16_t id; 352 uint16_t color; 353 uint32_t ref; 354 struct ieee80211_channel *channel; 355 }; 356 357 struct iwm_bf_data { 358 int bf_enabled; /* filtering */ 359 int ba_enabled; /* abort */ 360 int ave_beacon_signal; 361 int last_cqm_event; 362 }; 363 364 struct iwm_softc { 365 struct device sc_dev; 366 struct ieee80211com sc_ic; 367 int (*sc_newstate)(struct ieee80211com *, enum ieee80211_state, int); 368 int sc_newstate_pending; 369 370 struct ieee80211_amrr sc_amrr; 371 struct timeout sc_calib_to; 372 struct timeout sc_led_blink_to; 373 374 struct task init_task; /* NB: not reference-counted */ 375 struct refcnt task_refs; 376 struct task newstate_task; 377 enum ieee80211_state ns_nstate; 378 int ns_arg; 379 380 /* Task for firmware BlockAck setup/teardown and its arguments. */ 381 struct task ba_task; 382 int ba_start; 383 int ba_tid; 384 uint16_t ba_ssn; 385 uint16_t ba_winsize; 386 387 /* Task for HT protection updates. */ 388 struct task htprot_task; 389 390 bus_space_tag_t sc_st; 391 bus_space_handle_t sc_sh; 392 bus_size_t sc_sz; 393 bus_dma_tag_t sc_dmat; 394 pci_chipset_tag_t sc_pct; 395 pcitag_t sc_pcitag; 396 const void *sc_ih; 397 int sc_msix; 398 399 /* TX scheduler rings. */ 400 struct iwm_dma_info sched_dma; 401 uint32_t sched_base; 402 403 /* TX/RX rings. */ 404 struct iwm_tx_ring txq[IWM_MAX_QUEUES]; 405 struct iwm_rx_ring rxq; 406 int qfullmsk; 407 int cmdqid; 408 409 int sc_sf_state; 410 411 /* ICT table. */ 412 struct iwm_dma_info ict_dma; 413 int ict_cur; 414 415 int sc_hw_rev; 416 #define IWM_SILICON_A_STEP 0 417 #define IWM_SILICON_B_STEP 1 418 #define IWM_SILICON_C_STEP 2 419 #define IWM_SILICON_D_STEP 3 420 int sc_hw_id; 421 int sc_device_family; 422 #define IWM_DEVICE_FAMILY_7000 1 423 #define IWM_DEVICE_FAMILY_8000 2 424 #define IWM_DEVICE_FAMILY_9000 3 425 426 struct iwm_dma_info kw_dma; 427 struct iwm_dma_info fw_dma; 428 429 int sc_fw_chunk_done; 430 int sc_init_complete; 431 #define IWM_INIT_COMPLETE 0x01 432 #define IWM_CALIB_COMPLETE 0x02 433 434 struct iwm_ucode_status sc_uc; 435 enum iwm_ucode_type sc_uc_current; 436 char sc_fwver[32]; 437 438 int sc_capaflags; 439 int sc_capa_max_probe_len; 440 int sc_capa_n_scan_channels; 441 uint8_t sc_ucode_api[howmany(IWM_NUM_UCODE_TLV_API, NBBY)]; 442 uint8_t sc_enabled_capa[howmany(IWM_NUM_UCODE_TLV_CAPA, NBBY)]; 443 char sc_fw_mcc[3]; 444 445 int sc_intmask; 446 int sc_flags; 447 448 uint32_t sc_fh_init_mask; 449 uint32_t sc_hw_init_mask; 450 uint32_t sc_fh_mask; 451 uint32_t sc_hw_mask; 452 453 /* 454 * So why do we need a separate stopped flag and a generation? 455 * the former protects the device from issueing commands when it's 456 * stopped (duh). The latter protects against race from a very 457 * fast stop/unstop cycle where threads waiting for responses do 458 * not have a chance to run in between. Notably: we want to stop 459 * the device from interrupt context when it craps out, so we 460 * don't have the luxury of waiting for quiescense. 461 */ 462 int sc_generation; 463 464 struct rwlock ioctl_rwl; 465 466 int sc_cap_off; /* PCIe caps */ 467 468 const char *sc_fwname; 469 bus_size_t sc_fwdmasegsz; 470 size_t sc_nvm_max_section_size; 471 struct iwm_fw_info sc_fw; 472 int sc_fw_phy_config; 473 struct iwm_tlv_calib_ctrl sc_default_calib[IWM_UCODE_TYPE_MAX]; 474 475 struct iwm_nvm_data sc_nvm; 476 struct iwm_phy_db sc_phy_db; 477 478 struct iwm_bf_data sc_bf; 479 480 int sc_tx_timer; 481 int sc_rx_ba_sessions; 482 483 int sc_scan_last_antenna; 484 485 int sc_fixed_ridx; 486 487 int sc_staid; 488 int sc_nodecolor; 489 490 uint8_t *sc_cmd_resp_pkt[IWM_TX_RING_COUNT]; 491 size_t sc_cmd_resp_len[IWM_TX_RING_COUNT]; 492 int sc_nic_locks; 493 494 struct taskq *sc_nswq; 495 496 struct iwm_rx_phy_info sc_last_phy_info; 497 int sc_ampdu_ref; 498 499 uint32_t sc_time_event_uid; 500 501 /* phy contexts. we only use the first one */ 502 struct iwm_phy_ctxt sc_phyctxt[IWM_NUM_PHY_CTX]; 503 504 struct iwm_notif_statistics sc_stats; 505 int sc_noise; 506 507 int host_interrupt_operation_mode; 508 int sc_ltr_enabled; 509 enum iwm_nvm_type nvm_type; 510 511 int sc_mqrx_supported; 512 int sc_integrated; 513 514 /* 515 * Paging parameters - All of the parameters should be set by the 516 * opmode when paging is enabled 517 */ 518 struct iwm_fw_paging fw_paging_db[IWM_NUM_OF_FW_PAGING_BLOCKS]; 519 uint16_t num_of_paging_blk; 520 uint16_t num_of_pages_in_last_blk; 521 522 #if NBPFILTER > 0 523 caddr_t sc_drvbpf; 524 525 union { 526 struct iwm_rx_radiotap_header th; 527 uint8_t pad[IEEE80211_RADIOTAP_HDRLEN]; 528 } sc_rxtapu; 529 #define sc_rxtap sc_rxtapu.th 530 int sc_rxtap_len; 531 532 union { 533 struct iwm_tx_radiotap_header th; 534 uint8_t pad[IEEE80211_RADIOTAP_HDRLEN]; 535 } sc_txtapu; 536 #define sc_txtap sc_txtapu.th 537 int sc_txtap_len; 538 #endif 539 }; 540 541 struct iwm_node { 542 struct ieee80211_node in_ni; 543 struct iwm_phy_ctxt *in_phyctxt; 544 545 uint16_t in_id; 546 uint16_t in_color; 547 548 struct ieee80211_amrr_node in_amn; 549 int chosen_txrate; 550 struct ieee80211_mira_node in_mn; 551 int chosen_txmcs; 552 }; 553 #define IWM_STATION_ID 0 554 #define IWM_AUX_STA_ID 1 555 #define IWM_MONITOR_STA_ID 2 556 557 #define IWM_ICT_SIZE 4096 558 #define IWM_ICT_COUNT (IWM_ICT_SIZE / sizeof (uint32_t)) 559 #define IWM_ICT_PADDR_SHIFT 12 560