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 uint8_t wt_hwqueue; 133 } __packed; 134 135 #define IWM_TX_RADIOTAP_PRESENT \ 136 ((1 << IEEE80211_RADIOTAP_FLAGS) | \ 137 (1 << IEEE80211_RADIOTAP_RATE) | \ 138 (1 << IEEE80211_RADIOTAP_CHANNEL)) 139 140 141 #define IWM_UCODE_SECT_MAX 6 142 #define IWM_FWDMASEGSZ (192*1024) 143 /* sanity check value */ 144 #define IWM_FWMAXSIZE (2*1024*1024) 145 146 /* 147 * fw_status is used to determine if we've already parsed the firmware file 148 * 149 * In addition to the following, status < 0 ==> -error 150 */ 151 #define IWM_FW_STATUS_NONE 0 152 #define IWM_FW_STATUS_INPROGRESS 1 153 #define IWM_FW_STATUS_DONE 2 154 155 #define IWM_LOCK(_sc) lockmgr(&sc->sc_lk, LK_EXCLUSIVE) 156 #define IWM_UNLOCK(_sc) lockmgr(&sc->sc_lk, LK_RELEASE) 157 158 enum iwm_ucode_type { 159 IWM_UCODE_TYPE_INIT, 160 IWM_UCODE_TYPE_REGULAR, 161 IWM_UCODE_TYPE_WOW, 162 IWM_UCODE_TYPE_MAX 163 }; 164 165 struct iwm_fw_info { 166 const struct firmware *fw_fp; 167 int fw_status; 168 169 struct iwm_fw_sects { 170 struct iwm_fw_onesect { 171 const void *fws_data; 172 uint32_t fws_len; 173 uint32_t fws_devoff; 174 } fw_sect[IWM_UCODE_SECT_MAX]; 175 size_t fw_totlen; 176 int fw_count; 177 } fw_sects[IWM_UCODE_TYPE_MAX]; 178 }; 179 180 struct iwm_nvm_data { 181 int n_hw_addrs; 182 uint8_t hw_addr[IEEE80211_ADDR_LEN]; 183 184 uint8_t calib_version; 185 uint16_t calib_voltage; 186 187 uint16_t raw_temperature; 188 uint16_t kelvin_temperature; 189 uint16_t kelvin_voltage; 190 uint16_t xtal_calib[2]; 191 192 int sku_cap_band_24GHz_enable; 193 int sku_cap_band_52GHz_enable; 194 int sku_cap_11n_enable; 195 int sku_cap_amt_enable; 196 int sku_cap_ipan_enable; 197 198 uint8_t radio_cfg_type; 199 uint8_t radio_cfg_step; 200 uint8_t radio_cfg_dash; 201 uint8_t radio_cfg_pnum; 202 uint8_t valid_tx_ant, valid_rx_ant; 203 204 uint16_t nvm_version; 205 uint8_t max_tx_pwr_half_dbm; 206 }; 207 208 /* max bufs per tfd the driver will use */ 209 #define IWM_MAX_CMD_TBS_PER_TFD 2 210 211 struct iwm_rx_packet; 212 struct iwm_host_cmd { 213 const void *data[IWM_MAX_CMD_TBS_PER_TFD]; 214 struct iwm_rx_packet *resp_pkt; 215 unsigned long _rx_page_addr; 216 uint32_t _rx_page_order; 217 int handler_status; 218 219 uint32_t flags; 220 uint16_t len[IWM_MAX_CMD_TBS_PER_TFD]; 221 uint8_t dataflags[IWM_MAX_CMD_TBS_PER_TFD]; 222 uint8_t id; 223 }; 224 225 /* 226 * DMA glue is from iwn 227 */ 228 229 typedef caddr_t iwm_caddr_t; 230 typedef void *iwm_hookarg_t; 231 232 struct iwm_dma_info { 233 bus_dma_tag_t tag; 234 bus_dmamap_t map; 235 bus_dma_segment_t seg; 236 bus_addr_t paddr; 237 void *vaddr; 238 bus_size_t size; 239 }; 240 241 #define IWM_TX_RING_COUNT 256 242 #define IWM_TX_RING_LOMARK 192 243 #define IWM_TX_RING_HIMARK 224 244 245 struct iwm_tx_data { 246 bus_dmamap_t map; 247 bus_addr_t cmd_paddr; 248 bus_addr_t scratch_paddr; 249 struct mbuf *m; 250 struct iwm_node *in; 251 int done; 252 }; 253 254 struct iwm_tx_ring { 255 struct iwm_dma_info desc_dma; 256 struct iwm_dma_info cmd_dma; 257 struct iwm_tfd *desc; 258 struct iwm_device_cmd *cmd; 259 bus_dma_tag_t data_dmat; 260 struct iwm_tx_data data[IWM_TX_RING_COUNT]; 261 int qid; 262 int queued; 263 int cur; 264 }; 265 266 #define IWM_RX_RING_COUNT 256 267 #define IWM_RBUF_COUNT (IWM_RX_RING_COUNT + 32) 268 /* Linux driver optionally uses 8k buffer */ 269 #define IWM_RBUF_SIZE 4096 270 271 #define IWM_MAX_SCATTER 20 272 273 struct iwm_softc; 274 struct iwm_rbuf { 275 struct iwm_softc *sc; 276 void *vaddr; 277 bus_addr_t paddr; 278 }; 279 280 struct iwm_rx_data { 281 struct mbuf *m; 282 bus_dmamap_t map; 283 int wantresp; 284 }; 285 286 struct iwm_rx_ring { 287 struct iwm_dma_info desc_dma; 288 struct iwm_dma_info stat_dma; 289 struct iwm_dma_info buf_dma; 290 uint32_t *desc; 291 struct iwm_rb_status *stat; 292 struct iwm_rx_data data[IWM_RX_RING_COUNT]; 293 bus_dma_tag_t data_dmat; 294 int cur; 295 }; 296 297 #define IWM_FLAG_USE_ICT 0x01 298 #define IWM_FLAG_HW_INITED 0x02 299 #define IWM_FLAG_STOPPED 0x04 300 #define IWM_FLAG_RFKILL 0x08 301 #define IWM_FLAG_BUSY 0x10 302 303 struct iwm_ucode_status { 304 uint32_t uc_error_event_table; 305 uint32_t uc_log_event_table; 306 307 int uc_ok; 308 int uc_intr; 309 }; 310 311 #define IWM_CMD_RESP_MAX PAGE_SIZE 312 313 #define IWM_OTP_LOW_IMAGE_SIZE 2048 314 315 #define IWM_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS 500 316 #define IWM_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS 400 317 318 /* 319 * Command headers are in iwl-trans.h, which is full of all 320 * kinds of other junk, so we just replicate the structures here. 321 * First the software bits: 322 */ 323 enum IWM_CMD_MODE { 324 IWM_CMD_SYNC = 0, 325 IWM_CMD_ASYNC = (1 << 0), 326 IWM_CMD_WANT_SKB = (1 << 1), 327 IWM_CMD_SEND_IN_RFKILL = (1 << 2), 328 }; 329 enum iwm_hcmd_dataflag { 330 IWM_HCMD_DFL_NOCOPY = (1 << 0), 331 IWM_HCMD_DFL_DUP = (1 << 1), 332 }; 333 334 /* 335 * iwlwifi/iwl-phy-db 336 */ 337 338 #define IWM_NUM_PAPD_CH_GROUPS 4 339 #define IWM_NUM_TXP_CH_GROUPS 9 340 341 struct iwm_phy_db_entry { 342 uint16_t size; 343 uint8_t *data; 344 }; 345 346 struct iwm_phy_db { 347 struct iwm_phy_db_entry cfg; 348 struct iwm_phy_db_entry calib_nch; 349 struct iwm_phy_db_entry calib_ch_group_papd[IWM_NUM_PAPD_CH_GROUPS]; 350 struct iwm_phy_db_entry calib_ch_group_txp[IWM_NUM_TXP_CH_GROUPS]; 351 }; 352 353 struct iwm_int_sta { 354 uint32_t sta_id; 355 uint32_t tfd_queue_msk; 356 }; 357 358 struct iwm_mvm_phy_ctxt { 359 uint16_t id; 360 uint16_t color; 361 uint32_t ref; 362 struct ieee80211_channel *channel; 363 }; 364 365 struct iwm_bf_data { 366 int bf_enabled; /* filtering */ 367 int ba_enabled; /* abort */ 368 int ave_beacon_signal; 369 int last_cqm_event; 370 }; 371 372 struct iwm_vap { 373 struct ieee80211vap iv_vap; 374 uint8_t macaddr[IEEE80211_ADDR_LEN]; 375 int is_uploaded; 376 377 int (*iv_newstate)(struct ieee80211vap *, enum ieee80211_state, int); 378 }; 379 380 #define IWM_VAP(_vap) ((struct iwm_vap *)(_vap)) 381 382 struct iwm_softc { 383 struct lock sc_lk; 384 struct ifnet *sc_ifp; 385 device_t sc_dev; 386 struct ieee80211com *sc_ic; 387 388 int sc_newstate_pending; 389 390 uint8_t sc_bssid[IEEE80211_ADDR_LEN]; 391 392 struct intr_config_hook sc_preinit_hook; 393 struct callout sc_watchdog_to; 394 struct callout sc_led_blink_to; 395 396 struct task init_task; 397 uint8_t sc_macaddr[IEEE80211_ADDR_LEN]; 398 399 struct resource *sc_irq; 400 struct resource *sc_mem; 401 bus_space_tag_t sc_st; 402 bus_space_handle_t sc_sh; 403 bus_size_t sc_sz; 404 bus_dma_tag_t sc_dmat; 405 void *sc_ih; 406 407 /* TX scheduler rings. */ 408 struct iwm_dma_info sched_dma; 409 uint32_t sched_base; 410 411 /* TX/RX rings. */ 412 struct iwm_tx_ring txq[IWM_MVM_MAX_QUEUES]; 413 struct iwm_rx_ring rxq; 414 int qfullmsk; 415 416 int sc_sf_state; 417 418 /* ICT table. */ 419 struct iwm_dma_info ict_dma; 420 int ict_cur; 421 422 int sc_hw_rev; 423 int sc_hw_id; 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 431 struct iwm_ucode_status sc_uc; 432 enum iwm_ucode_type sc_uc_current; 433 int sc_fwver; 434 435 int sc_capaflags; 436 int sc_capa_max_probe_len; 437 438 int sc_intmask; 439 int sc_flags; 440 uint32_t sc_debug; 441 442 /* 443 * So why do we need a separate stopped flag and a generation? 444 * the former protects the device from issueing commands when it's 445 * stopped (duh). The latter protects against race from a very 446 * fast stop/unstop cycle where threads waiting for responses do 447 * not have a chance to run in between. Notably: we want to stop 448 * the device from interrupt context when it craps out, so we 449 * don't have the luxury of waiting for quiescense. 450 */ 451 int sc_generation; 452 453 const char *sc_fwname; 454 bus_size_t sc_fwdmasegsz; 455 struct iwm_fw_info sc_fw; 456 int sc_fw_phy_config; 457 struct iwm_tlv_calib_ctrl sc_default_calib[IWM_UCODE_TYPE_MAX]; 458 459 struct iwm_nvm_data sc_nvm; 460 struct iwm_phy_db sc_phy_db; 461 462 struct iwm_bf_data sc_bf; 463 464 int sc_tx_timer; 465 466 struct iwm_scan_cmd *sc_scan_cmd; 467 size_t sc_scan_cmd_len; 468 int sc_scan_last_antenna; 469 int sc_scanband; 470 471 int sc_auth_prot; 472 473 int sc_fixed_ridx; 474 475 int sc_staid; 476 int sc_nodecolor; 477 478 uint8_t sc_cmd_resp[IWM_CMD_RESP_MAX]; 479 int sc_wantresp; 480 481 struct taskqueue *sc_tq; 482 struct task sc_es_task; 483 484 struct iwm_rx_phy_info sc_last_phy_info; 485 int sc_ampdu_ref; 486 487 struct iwm_int_sta sc_aux_sta; 488 489 /* phy contexts. we only use the first one */ 490 struct iwm_mvm_phy_ctxt sc_phyctxt[IWM_NUM_PHY_CTX]; 491 492 struct iwm_notif_statistics sc_stats; 493 int sc_noise; 494 495 int host_interrupt_operation_mode; 496 497 caddr_t sc_drvbpf; 498 499 union { 500 struct iwm_rx_radiotap_header th; 501 uint8_t pad[IEEE80211_RADIOTAP_HDRLEN]; 502 } sc_rxtapu; 503 #define sc_rxtap sc_rxtapu.th 504 int sc_rxtap_len; 505 506 union { 507 struct iwm_tx_radiotap_header th; 508 uint8_t pad[IEEE80211_RADIOTAP_HDRLEN]; 509 } sc_txtapu; 510 #define sc_txtap sc_txtapu.th 511 int sc_txtap_len; 512 513 int sc_max_rssi; 514 }; 515 516 #define IWM_DEFAULT_MACID 0 517 #define IWM_DEFAULT_COLOR 0 518 #define IWM_DEFAULT_TSFID 0 519 520 struct iwm_node { 521 struct ieee80211_node in_ni; 522 struct iwm_mvm_phy_ctxt *in_phyctxt; 523 524 /* status "bits" */ 525 int in_assoc; 526 527 struct iwm_lq_cmd in_lq; 528 529 uint8_t in_ridx[IEEE80211_RATE_MAXSIZE]; 530 }; 531 #define IWM_STATION_ID 0 532 533 #define IWM_ICT_SIZE 4096 534 #define IWM_ICT_COUNT (IWM_ICT_SIZE / sizeof (uint32_t)) 535 #define IWM_ICT_PADDR_SHIFT 12 536