1 /* $NetBSD: if_iwmvar.h,v 1.21 2025/12/01 16:02:42 mlelstv Exp $ */ 2 /* OpenBSD: if_iwmvar.h,v 1.24 2016/09/21 13:53:18 stsp Exp */ 3 4 /* 5 * Copyright (c) 2014 genua mbh <info (at) 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 (at) 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 (at) 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 }; 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 uint8_t wt_hwqueue; 133 }; 134 135 #define IWM_TX_RADIOTAP_PRESENT \ 136 ((1 << IEEE80211_RADIOTAP_FLAGS) | \ 137 (1 << IEEE80211_RADIOTAP_RATE) | \ 138 (1 << IEEE80211_RADIOTAP_CHANNEL)) 139 140 #define IWM_UCODE_SECT_MAX 16 141 #define IWM_FWDMASEGSZ (192*1024) 142 #define IWM_FWDMASEGSZ_8000 (320*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 172 void *fws_alloc; 173 size_t fws_allocsize; 174 } fw_sect[IWM_UCODE_SECT_MAX]; 175 size_t fw_totlen; 176 int fw_count; 177 uint32_t paging_mem_size; 178 } fw_sects[IWM_UCODE_TYPE_MAX]; 179 }; 180 181 struct iwm_nvm_data { 182 int n_hw_addrs; 183 uint8_t hw_addr[ETHER_ADDR_LEN]; 184 185 uint8_t calib_version; 186 uint16_t calib_voltage; 187 188 uint16_t raw_temperature; 189 uint16_t kelvin_temperature; 190 uint16_t kelvin_voltage; 191 uint16_t xtal_calib[2]; 192 193 int sku_cap_band_24GHz_enable; 194 int sku_cap_band_52GHz_enable; 195 int sku_cap_11n_enable; 196 int sku_cap_11ac_enable; 197 int sku_cap_amt_enable; 198 int sku_cap_ipan_enable; 199 int sku_cap_mimo_disable; 200 201 uint8_t radio_cfg_type; 202 uint8_t radio_cfg_step; 203 uint8_t radio_cfg_dash; 204 uint8_t radio_cfg_pnum; 205 uint8_t valid_tx_ant, valid_rx_ant; 206 207 uint16_t nvm_version; 208 uint8_t max_tx_pwr_half_dbm; 209 210 bool lar_enabled; 211 }; 212 213 /* max bufs per tfd the driver will use */ 214 #define IWM_MAX_CMD_TBS_PER_TFD 2 215 216 struct iwm_rx_packet; 217 struct iwm_host_cmd { 218 const void *data[IWM_MAX_CMD_TBS_PER_TFD]; 219 struct iwm_rx_packet *resp_pkt; 220 size_t resp_pkt_len; 221 unsigned long _rx_page_addr; 222 uint32_t _rx_page_order; 223 int handler_status; 224 225 uint32_t flags; 226 uint16_t len[IWM_MAX_CMD_TBS_PER_TFD]; 227 uint8_t dataflags[IWM_MAX_CMD_TBS_PER_TFD]; 228 uint32_t id; 229 }; 230 231 /* 232 * DMA glue is from iwn 233 */ 234 235 struct iwm_dma_info { 236 bus_dma_tag_t tag; 237 bus_dmamap_t map; 238 bus_dma_segment_t seg; 239 bus_addr_t paddr; 240 void *vaddr; 241 bus_size_t size; 242 }; 243 244 /** 245 * struct iwm_fw_paging 246 * @fw_paging_block: dma memory info 247 * @fw_paging_size: page size 248 */ 249 struct iwm_fw_paging { 250 struct iwm_dma_info fw_paging_block; 251 uint32_t fw_paging_size; 252 }; 253 254 #define IWM_TX_RING_COUNT 256 255 #define IWM_TX_RING_LOMARK 192 256 #define IWM_TX_RING_HIMARK 224 257 258 /* For aggregation queues, index must be aligned to frame sequence number. */ 259 #define IWM_AGG_SSN_TO_TXQ_IDX(x) ((x) & (IWM_TX_RING_COUNT - 1)) 260 261 struct iwm_tx_data { 262 bus_dmamap_t map; 263 bus_addr_t cmd_paddr; 264 bus_addr_t scratch_paddr; 265 struct mbuf *m; 266 struct iwm_node *in; 267 int done; 268 }; 269 270 struct iwm_tx_ring { 271 struct iwm_dma_info desc_dma; 272 struct iwm_dma_info cmd_dma; 273 struct iwm_tfd *desc; 274 struct iwm_device_cmd *cmd; 275 struct iwm_tx_data data[IWM_TX_RING_COUNT]; 276 int qid; 277 int queued; 278 int cur; 279 }; 280 281 #define IWM_RX_RING_COUNT 256 282 #define IWM_RBUF_COUNT (IWM_RX_RING_COUNT + 32) 283 /* Linux driver optionally uses 8k buffer */ 284 #define IWM_RBUF_SIZE 4096 285 286 struct iwm_rx_data { 287 struct mbuf *m; 288 bus_dmamap_t map; 289 }; 290 291 struct iwm_rx_ring { 292 struct iwm_dma_info desc_dma; 293 struct iwm_dma_info stat_dma; 294 struct iwm_dma_info buf_dma; 295 uint32_t *desc; 296 struct iwm_rb_status *stat; 297 struct iwm_rx_data data[IWM_RX_RING_COUNT]; 298 int cur; 299 }; 300 301 #define IWM_FLAG_USE_ICT __BIT(0) 302 #define IWM_FLAG_HW_INITED __BIT(1) 303 #define IWM_FLAG_STOPPED __BIT(2) 304 #define IWM_FLAG_RFKILL __BIT(3) 305 #define IWM_FLAG_SCANNING __BIT(4) 306 #define IWM_FLAG_ATTACHED __BIT(5) 307 #define IWM_FLAG_FW_LOADED __BIT(6) 308 #define IWM_FLAG_TE_ACTIVE __BIT(7) 309 #define IWM_FLAG_MAC_ACTIVE __BIT(8) 310 #define IWM_FLAG_BINDING_ACTIVE __BIT(9) 311 #define IWM_FLAG_STA_ACTIVE __BIT(10) 312 #define IWM_FLAG_BGSCAN __BIT(11) 313 #define IWM_FLAG_TXFLUSH __BIT(12) 314 315 struct iwm_ucode_status { 316 uint32_t uc_error_event_table; 317 uint32_t uc_umac_error_event_table; 318 uint32_t uc_log_event_table; 319 320 int uc_ok; 321 int uc_intr; 322 }; 323 324 /* sc_wantresp */ 325 #define IWM_CMD_RESP_IDLE -1 326 327 #define IWM_CMD_RESP_MAX PAGE_SIZE 328 329 /* lower blocks contain EEPROM image and calibration data */ 330 #define IWM_OTP_LOW_IMAGE_SIZE_FAMILY_7000 16384 331 #define IWM_OTP_LOW_IMAGE_SIZE_FAMILY_8000 32768 332 333 #define IWM_TE_SESSION_PROTECTION_MAX_TIME_MS 1000 334 #define IWM_TE_SESSION_PROTECTION_MIN_TIME_MS 400 335 336 enum IWM_CMD_MODE { 337 IWM_CMD_ASYNC = (1 << 0), 338 IWM_CMD_WANT_RESP = (1 << 1), 339 IWM_CMD_SEND_IN_RFKILL = (1 << 2), 340 }; 341 enum iwm_hcmd_dataflag { 342 IWM_HCMD_DFL_NOCOPY = (1 << 0), 343 IWM_HCMD_DFL_DUP = (1 << 1), 344 }; 345 346 #define IWM_NUM_PAPD_CH_GROUPS 9 347 #define IWM_NUM_TXP_CH_GROUPS 9 348 349 struct iwm_phy_db_entry { 350 uint16_t size; 351 uint8_t *data; 352 }; 353 354 struct iwm_phy_db { 355 struct iwm_phy_db_entry cfg; 356 struct iwm_phy_db_entry calib_nch; 357 struct iwm_phy_db_entry calib_ch_group_papd[IWM_NUM_PAPD_CH_GROUPS]; 358 struct iwm_phy_db_entry calib_ch_group_txp[IWM_NUM_TXP_CH_GROUPS]; 359 }; 360 361 struct iwm_phy_ctxt { 362 uint16_t id; 363 uint16_t color; 364 uint32_t ref; 365 struct ieee80211_channel *channel; 366 }; 367 368 struct iwm_bf_data { 369 int bf_enabled; /* filtering */ 370 int ba_enabled; /* abort */ 371 int ave_beacon_signal; 372 int last_cqm_event; 373 }; 374 375 struct iwm_softc { 376 device_t sc_dev; 377 struct ethercom sc_ec; 378 struct ieee80211com sc_ic; 379 int attached; 380 381 int (*sc_newstate)(struct ieee80211com *, enum ieee80211_state, int); 382 383 struct ieee80211_amrr sc_amrr; 384 struct callout sc_calib_to; 385 struct callout sc_led_blink_to; 386 387 bus_space_tag_t sc_st; 388 bus_space_handle_t sc_sh; 389 pci_intr_handle_t *sc_pihp; 390 391 bus_size_t sc_sz; 392 bus_dma_tag_t sc_dmat; 393 pci_chipset_tag_t sc_pct; 394 pcitag_t sc_pcitag; 395 pcireg_t sc_pciid; 396 const void *sc_ih; 397 void *sc_soft_ih; 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 425 struct iwm_dma_info kw_dma; 426 struct iwm_dma_info fw_dma; 427 428 int sc_fw_chunk_done; 429 int sc_init_complete; 430 #define IWM_INIT_COMPLETE 0x01 431 #define IWM_CALIB_COMPLETE 0x02 432 433 struct iwm_ucode_status sc_uc; 434 enum iwm_ucode_type sc_uc_current; 435 char sc_fwver[32]; 436 437 int sc_capaflags; 438 int sc_capa_max_probe_len; 439 int sc_capa_n_scan_channels; 440 uint8_t sc_ucode_api[howmany(IWM_NUM_UCODE_TLV_API, NBBY)]; 441 uint8_t sc_enabled_capa[howmany(IWM_NUM_UCODE_TLV_CAPA, NBBY)]; 442 #define IWM_MAX_FW_CMD_VERSIONS 64 443 struct iwm_fw_cmd_version cmd_versions[IWM_MAX_FW_CMD_VERSIONS]; 444 int n_cmd_versions; 445 446 int sc_intmask; 447 int sc_flags; 448 449 /* 450 * So why do we need a separate stopped flag and a generation? 451 * the former protects the device from issueing commands when it's 452 * stopped (duh). The latter protects against race from a very 453 * fast stop/unstop cycle where threads waiting for responses do 454 * not have a chance to run in between. Notably: we want to stop 455 * the device from interrupt context when it craps out, so we 456 * don't have the luxury of waiting for quiescense. 457 */ 458 int sc_generation; 459 460 int sc_cap_off; /* PCIe caps */ 461 462 const char *sc_fwname; 463 bus_size_t sc_fwdmasegsz; 464 struct iwm_fw_info sc_fw; 465 int sc_fw_phy_config; 466 struct iwm_tlv_calib_ctrl sc_default_calib[IWM_UCODE_TYPE_MAX]; 467 468 struct iwm_nvm_data sc_nvm; 469 struct iwm_phy_db sc_phy_db; 470 471 struct iwm_bf_data sc_bf; 472 473 int sc_tx_timer; 474 int sc_rx_ba_sessions; 475 476 int sc_scan_last_antenna; 477 int sc_mgmt_last_antenna; 478 479 int sc_fixed_ridx; 480 481 int sc_staid; 482 int sc_nodecolor; 483 484 uint8_t *sc_cmd_resp_pkt[IWM_TX_RING_COUNT]; 485 size_t sc_cmd_resp_len[IWM_TX_RING_COUNT]; 486 487 kmutex_t sc_nic_mtx; 488 int sc_nic_locks; 489 490 struct workqueue *sc_nswq; 491 struct workqueue *sc_setratewq; 492 493 struct iwm_rx_phy_info sc_last_phy_info; 494 int sc_ampdu_ref; 495 496 /* phy contexts. we only use the first one */ 497 struct iwm_phy_ctxt sc_phyctxt[IWM_NUM_PHY_CTX]; 498 499 uint32_t sc_time_event_uid; 500 501 struct iwm_notif_statistics sc_stats; 502 int sc_noise; 503 504 int sc_cmd_hold_nic_awake; 505 506 /* device needs host interrupt operation mode set */ 507 int host_interrupt_operation_mode; 508 int sc_ltr_enabled; 509 enum iwm_nvm_type nvm_type; 510 511 #ifdef notyet 512 int sc_mqrx_supported; 513 int sc_integrated; 514 int sc_ltr_delay; 515 int sc_xtal_latency; 516 int sc_low_latency_xtal; 517 #endif 518 519 /* should the MAC access REQ be asserted when a command is in flight. 520 * This is due to a HW bug in 7260, 3160 and 7265. */ 521 int apmg_wake_up_wa; 522 523 /* 524 * Paging parameters - All of the parameters should be set by the 525 * opmode when paging is enabled 526 */ 527 struct iwm_fw_paging fw_paging_db[IWM_NUM_OF_FW_PAGING_BLOCKS]; 528 uint16_t num_of_paging_blk; 529 uint16_t num_of_pages_in_last_blk; 530 531 struct sysctllog *sc_clog; 532 533 struct bpf_if *sc_drvbpf; 534 535 kmutex_t sc_media_mtx; /* XXX */ 536 537 union { 538 struct iwm_rx_radiotap_header th; 539 uint8_t pad[IEEE80211_RADIOTAP_HDRLEN]; 540 } sc_rxtapu; 541 #define sc_rxtap sc_rxtapu.th 542 int sc_rxtap_len; 543 544 union { 545 struct iwm_tx_radiotap_header th; 546 uint8_t pad[IEEE80211_RADIOTAP_HDRLEN]; 547 } sc_txtapu; 548 #define sc_txtap sc_txtapu.th 549 int sc_txtap_len; 550 }; 551 552 struct iwm_node { 553 struct ieee80211_node in_ni; 554 struct iwm_phy_ctxt *in_phyctxt; 555 uint8_t in_macaddr[ETHER_ADDR_LEN]; 556 557 uint16_t in_id; 558 uint16_t in_color; 559 560 struct iwm_lq_cmd in_lq; 561 struct ieee80211_amrr_node in_amn; 562 563 /* For use with the ADD_STA command. */ 564 uint32_t tfd_queue_msk; 565 uint16_t tid_disable_ampdu; 566 }; 567 #define IWM_STATION_ID 0 568 #define IWM_AUX_STA_ID 1 569 #define IWM_MONITOR_STA_ID 2 570 571 #define IWM_ICT_SIZE 4096 572 #define IWM_ICT_COUNT (IWM_ICT_SIZE / sizeof (uint32_t)) 573 #define IWM_ICT_PADDR_SHIFT 12 574