1 // SPDX-License-Identifier: GPL-2.0-only 2 /****************************************************************************** 3 * 4 * Copyright(c) 2003 - 2014, 2018 - 2020 Intel Corporation. All rights reserved. 5 * Copyright(c) 2015 Intel Deutschland GmbH 6 * 7 * Portions of this file are derived from the ipw3945 project, as well 8 * as portions of the ieee80211 subsystem header files. 9 * 10 * Contact Information: 11 * Intel Linux Wireless <linuxwifi@intel.com> 12 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 13 * 14 *****************************************************************************/ 15 16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 17 18 #include <linux/kernel.h> 19 #include <linux/module.h> 20 #include <linux/init.h> 21 #include <linux/slab.h> 22 #include <linux/delay.h> 23 #include <linux/sched.h> 24 #include <linux/skbuff.h> 25 #include <linux/netdevice.h> 26 #include <linux/etherdevice.h> 27 #include <linux/if_arp.h> 28 29 #include <net/mac80211.h> 30 31 #include <asm/div64.h> 32 33 #include "iwl-eeprom-read.h" 34 #include "iwl-eeprom-parse.h" 35 #include "iwl-io.h" 36 #include "iwl-trans.h" 37 #include "iwl-op-mode.h" 38 #include "iwl-drv.h" 39 #include "iwl-modparams.h" 40 #include "iwl-prph.h" 41 42 #include "dev.h" 43 #include "calib.h" 44 #include "agn.h" 45 46 47 /****************************************************************************** 48 * 49 * module boiler plate 50 * 51 ******************************************************************************/ 52 53 #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux" 54 MODULE_DESCRIPTION(DRV_DESCRIPTION); 55 MODULE_AUTHOR(DRV_AUTHOR); 56 MODULE_LICENSE("GPL"); 57 58 /* Please keep this array *SORTED* by hex value. 59 * Access is done through binary search. 60 * A warning will be triggered on violation. 61 */ 62 static const struct iwl_hcmd_names iwl_dvm_cmd_names[] = { 63 HCMD_NAME(REPLY_ALIVE), 64 HCMD_NAME(REPLY_ERROR), 65 HCMD_NAME(REPLY_ECHO), 66 HCMD_NAME(REPLY_RXON), 67 HCMD_NAME(REPLY_RXON_ASSOC), 68 HCMD_NAME(REPLY_QOS_PARAM), 69 HCMD_NAME(REPLY_RXON_TIMING), 70 HCMD_NAME(REPLY_ADD_STA), 71 HCMD_NAME(REPLY_REMOVE_STA), 72 HCMD_NAME(REPLY_REMOVE_ALL_STA), 73 HCMD_NAME(REPLY_TX), 74 HCMD_NAME(REPLY_TXFIFO_FLUSH), 75 HCMD_NAME(REPLY_WEPKEY), 76 HCMD_NAME(REPLY_LEDS_CMD), 77 HCMD_NAME(REPLY_TX_LINK_QUALITY_CMD), 78 HCMD_NAME(COEX_PRIORITY_TABLE_CMD), 79 HCMD_NAME(COEX_MEDIUM_NOTIFICATION), 80 HCMD_NAME(COEX_EVENT_CMD), 81 HCMD_NAME(TEMPERATURE_NOTIFICATION), 82 HCMD_NAME(CALIBRATION_CFG_CMD), 83 HCMD_NAME(CALIBRATION_RES_NOTIFICATION), 84 HCMD_NAME(CALIBRATION_COMPLETE_NOTIFICATION), 85 HCMD_NAME(REPLY_QUIET_CMD), 86 HCMD_NAME(REPLY_CHANNEL_SWITCH), 87 HCMD_NAME(CHANNEL_SWITCH_NOTIFICATION), 88 HCMD_NAME(REPLY_SPECTRUM_MEASUREMENT_CMD), 89 HCMD_NAME(SPECTRUM_MEASURE_NOTIFICATION), 90 HCMD_NAME(POWER_TABLE_CMD), 91 HCMD_NAME(PM_SLEEP_NOTIFICATION), 92 HCMD_NAME(PM_DEBUG_STATISTIC_NOTIFIC), 93 HCMD_NAME(REPLY_SCAN_CMD), 94 HCMD_NAME(REPLY_SCAN_ABORT_CMD), 95 HCMD_NAME(SCAN_START_NOTIFICATION), 96 HCMD_NAME(SCAN_RESULTS_NOTIFICATION), 97 HCMD_NAME(SCAN_COMPLETE_NOTIFICATION), 98 HCMD_NAME(BEACON_NOTIFICATION), 99 HCMD_NAME(REPLY_TX_BEACON), 100 HCMD_NAME(WHO_IS_AWAKE_NOTIFICATION), 101 HCMD_NAME(REPLY_TX_POWER_DBM_CMD), 102 HCMD_NAME(QUIET_NOTIFICATION), 103 HCMD_NAME(REPLY_TX_PWR_TABLE_CMD), 104 HCMD_NAME(REPLY_TX_POWER_DBM_CMD_V1), 105 HCMD_NAME(TX_ANT_CONFIGURATION_CMD), 106 HCMD_NAME(MEASURE_ABORT_NOTIFICATION), 107 HCMD_NAME(REPLY_BT_CONFIG), 108 HCMD_NAME(REPLY_STATISTICS_CMD), 109 HCMD_NAME(STATISTICS_NOTIFICATION), 110 HCMD_NAME(REPLY_CARD_STATE_CMD), 111 HCMD_NAME(CARD_STATE_NOTIFICATION), 112 HCMD_NAME(MISSED_BEACONS_NOTIFICATION), 113 HCMD_NAME(REPLY_CT_KILL_CONFIG_CMD), 114 HCMD_NAME(SENSITIVITY_CMD), 115 HCMD_NAME(REPLY_PHY_CALIBRATION_CMD), 116 HCMD_NAME(REPLY_WIPAN_PARAMS), 117 HCMD_NAME(REPLY_WIPAN_RXON), 118 HCMD_NAME(REPLY_WIPAN_RXON_TIMING), 119 HCMD_NAME(REPLY_WIPAN_RXON_ASSOC), 120 HCMD_NAME(REPLY_WIPAN_QOS_PARAM), 121 HCMD_NAME(REPLY_WIPAN_WEPKEY), 122 HCMD_NAME(REPLY_WIPAN_P2P_CHANNEL_SWITCH), 123 HCMD_NAME(REPLY_WIPAN_NOA_NOTIFICATION), 124 HCMD_NAME(REPLY_WIPAN_DEACTIVATION_COMPLETE), 125 HCMD_NAME(REPLY_RX_PHY_CMD), 126 HCMD_NAME(REPLY_RX_MPDU_CMD), 127 HCMD_NAME(REPLY_RX), 128 HCMD_NAME(REPLY_COMPRESSED_BA), 129 HCMD_NAME(REPLY_BT_COEX_PRIO_TABLE), 130 HCMD_NAME(REPLY_BT_COEX_PROT_ENV), 131 HCMD_NAME(REPLY_BT_COEX_PROFILE_NOTIF), 132 HCMD_NAME(REPLY_D3_CONFIG), 133 HCMD_NAME(REPLY_WOWLAN_PATTERNS), 134 HCMD_NAME(REPLY_WOWLAN_WAKEUP_FILTER), 135 HCMD_NAME(REPLY_WOWLAN_TSC_RSC_PARAMS), 136 HCMD_NAME(REPLY_WOWLAN_TKIP_PARAMS), 137 HCMD_NAME(REPLY_WOWLAN_KEK_KCK_MATERIAL), 138 HCMD_NAME(REPLY_WOWLAN_GET_STATUS), 139 }; 140 141 static const struct iwl_hcmd_arr iwl_dvm_groups[] = { 142 [0x0] = HCMD_ARR(iwl_dvm_cmd_names), 143 }; 144 145 static const struct iwl_op_mode_ops iwl_dvm_ops; 146 147 void iwl_update_chain_flags(struct iwl_priv *priv) 148 { 149 struct iwl_rxon_context *ctx; 150 151 for_each_context(priv, ctx) { 152 iwlagn_set_rxon_chain(priv, ctx); 153 if (ctx->active.rx_chain != ctx->staging.rx_chain) 154 iwlagn_commit_rxon(priv, ctx); 155 } 156 } 157 158 /* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */ 159 static void iwl_set_beacon_tim(struct iwl_priv *priv, 160 struct iwl_tx_beacon_cmd *tx_beacon_cmd, 161 u8 *beacon, u32 frame_size) 162 { 163 u16 tim_idx; 164 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon; 165 166 /* 167 * The index is relative to frame start but we start looking at the 168 * variable-length part of the beacon. 169 */ 170 tim_idx = mgmt->u.beacon.variable - beacon; 171 172 /* Parse variable-length elements of beacon to find WLAN_EID_TIM */ 173 while ((tim_idx < (frame_size - 2)) && 174 (beacon[tim_idx] != WLAN_EID_TIM)) 175 tim_idx += beacon[tim_idx+1] + 2; 176 177 /* If TIM field was found, set variables */ 178 if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) { 179 tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx); 180 tx_beacon_cmd->tim_size = beacon[tim_idx+1]; 181 } else 182 IWL_WARN(priv, "Unable to find TIM Element in beacon\n"); 183 } 184 185 int iwlagn_send_beacon_cmd(struct iwl_priv *priv) 186 { 187 struct iwl_tx_beacon_cmd *tx_beacon_cmd; 188 struct iwl_host_cmd cmd = { 189 .id = REPLY_TX_BEACON, 190 }; 191 struct ieee80211_tx_info *info; 192 u32 frame_size; 193 u32 rate_flags; 194 u32 rate; 195 196 /* 197 * We have to set up the TX command, the TX Beacon command, and the 198 * beacon contents. 199 */ 200 201 lockdep_assert_held(&priv->mutex); 202 203 if (!priv->beacon_ctx) { 204 IWL_ERR(priv, "trying to build beacon w/o beacon context!\n"); 205 return 0; 206 } 207 208 if (WARN_ON(!priv->beacon_skb)) 209 return -EINVAL; 210 211 /* Allocate beacon command */ 212 if (!priv->beacon_cmd) 213 priv->beacon_cmd = kzalloc(sizeof(*tx_beacon_cmd), GFP_KERNEL); 214 tx_beacon_cmd = priv->beacon_cmd; 215 if (!tx_beacon_cmd) 216 return -ENOMEM; 217 218 frame_size = priv->beacon_skb->len; 219 220 /* Set up TX command fields */ 221 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size); 222 tx_beacon_cmd->tx.sta_id = priv->beacon_ctx->bcast_sta_id; 223 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; 224 tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK | 225 TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK; 226 227 /* Set up TX beacon command fields */ 228 iwl_set_beacon_tim(priv, tx_beacon_cmd, priv->beacon_skb->data, 229 frame_size); 230 231 /* Set up packet rate and flags */ 232 info = IEEE80211_SKB_CB(priv->beacon_skb); 233 234 /* 235 * Let's set up the rate at least somewhat correctly; 236 * it will currently not actually be used by the uCode, 237 * it uses the broadcast station's rate instead. 238 */ 239 if (info->control.rates[0].idx < 0 || 240 info->control.rates[0].flags & IEEE80211_TX_RC_MCS) 241 rate = 0; 242 else 243 rate = info->control.rates[0].idx; 244 245 priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant, 246 priv->nvm_data->valid_tx_ant); 247 rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant); 248 249 /* In mac80211, rates for 5 GHz start at 0 */ 250 if (info->band == NL80211_BAND_5GHZ) 251 rate += IWL_FIRST_OFDM_RATE; 252 else if (rate >= IWL_FIRST_CCK_RATE && rate <= IWL_LAST_CCK_RATE) 253 rate_flags |= RATE_MCS_CCK_MSK; 254 255 tx_beacon_cmd->tx.rate_n_flags = 256 iwl_hw_set_rate_n_flags(rate, rate_flags); 257 258 /* Submit command */ 259 cmd.len[0] = sizeof(*tx_beacon_cmd); 260 cmd.data[0] = tx_beacon_cmd; 261 cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY; 262 cmd.len[1] = frame_size; 263 cmd.data[1] = priv->beacon_skb->data; 264 cmd.dataflags[1] = IWL_HCMD_DFL_NOCOPY; 265 266 return iwl_dvm_send_cmd(priv, &cmd); 267 } 268 269 static void iwl_bg_beacon_update(struct work_struct *work) 270 { 271 struct iwl_priv *priv = 272 container_of(work, struct iwl_priv, beacon_update); 273 struct sk_buff *beacon; 274 275 mutex_lock(&priv->mutex); 276 if (!priv->beacon_ctx) { 277 IWL_ERR(priv, "updating beacon w/o beacon context!\n"); 278 goto out; 279 } 280 281 if (priv->beacon_ctx->vif->type != NL80211_IFTYPE_AP) { 282 /* 283 * The ucode will send beacon notifications even in 284 * IBSS mode, but we don't want to process them. But 285 * we need to defer the type check to here due to 286 * requiring locking around the beacon_ctx access. 287 */ 288 goto out; 289 } 290 291 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */ 292 beacon = ieee80211_beacon_get(priv->hw, priv->beacon_ctx->vif); 293 if (!beacon) { 294 IWL_ERR(priv, "update beacon failed -- keeping old\n"); 295 goto out; 296 } 297 298 /* new beacon skb is allocated every time; dispose previous.*/ 299 dev_kfree_skb(priv->beacon_skb); 300 301 priv->beacon_skb = beacon; 302 303 iwlagn_send_beacon_cmd(priv); 304 out: 305 mutex_unlock(&priv->mutex); 306 } 307 308 static void iwl_bg_bt_runtime_config(struct work_struct *work) 309 { 310 struct iwl_priv *priv = 311 container_of(work, struct iwl_priv, bt_runtime_config); 312 313 mutex_lock(&priv->mutex); 314 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 315 goto out; 316 317 /* dont send host command if rf-kill is on */ 318 if (!iwl_is_ready_rf(priv)) 319 goto out; 320 321 iwlagn_send_advance_bt_config(priv); 322 out: 323 mutex_unlock(&priv->mutex); 324 } 325 326 static void iwl_bg_bt_full_concurrency(struct work_struct *work) 327 { 328 struct iwl_priv *priv = 329 container_of(work, struct iwl_priv, bt_full_concurrency); 330 struct iwl_rxon_context *ctx; 331 332 mutex_lock(&priv->mutex); 333 334 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 335 goto out; 336 337 /* dont send host command if rf-kill is on */ 338 if (!iwl_is_ready_rf(priv)) 339 goto out; 340 341 IWL_DEBUG_INFO(priv, "BT coex in %s mode\n", 342 priv->bt_full_concurrent ? 343 "full concurrency" : "3-wire"); 344 345 /* 346 * LQ & RXON updated cmds must be sent before BT Config cmd 347 * to avoid 3-wire collisions 348 */ 349 for_each_context(priv, ctx) { 350 iwlagn_set_rxon_chain(priv, ctx); 351 iwlagn_commit_rxon(priv, ctx); 352 } 353 354 iwlagn_send_advance_bt_config(priv); 355 out: 356 mutex_unlock(&priv->mutex); 357 } 358 359 int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear) 360 { 361 struct iwl_statistics_cmd statistics_cmd = { 362 .configuration_flags = 363 clear ? IWL_STATS_CONF_CLEAR_STATS : 0, 364 }; 365 366 if (flags & CMD_ASYNC) 367 return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD, 368 CMD_ASYNC, 369 sizeof(struct iwl_statistics_cmd), 370 &statistics_cmd); 371 else 372 return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD, 0, 373 sizeof(struct iwl_statistics_cmd), 374 &statistics_cmd); 375 } 376 377 /* 378 * iwl_bg_statistics_periodic - Timer callback to queue statistics 379 * 380 * This callback is provided in order to send a statistics request. 381 * 382 * This timer function is continually reset to execute within 383 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION 384 * was received. We need to ensure we receive the statistics in order 385 * to update the temperature used for calibrating the TXPOWER. 386 */ 387 static void iwl_bg_statistics_periodic(struct timer_list *t) 388 { 389 struct iwl_priv *priv = from_timer(priv, t, statistics_periodic); 390 391 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 392 return; 393 394 /* dont send host command if rf-kill is on */ 395 if (!iwl_is_ready_rf(priv)) 396 return; 397 398 iwl_send_statistics_request(priv, CMD_ASYNC, false); 399 } 400 401 402 static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base, 403 u32 start_idx, u32 num_events, 404 u32 capacity, u32 mode) 405 { 406 u32 i; 407 u32 ptr; /* SRAM byte address of log data */ 408 u32 ev, time, data; /* event log data */ 409 unsigned long reg_flags; 410 411 if (mode == 0) 412 ptr = base + (4 * sizeof(u32)) + (start_idx * 2 * sizeof(u32)); 413 else 414 ptr = base + (4 * sizeof(u32)) + (start_idx * 3 * sizeof(u32)); 415 416 /* Make sure device is powered up for SRAM reads */ 417 if (!iwl_trans_grab_nic_access(priv->trans, ®_flags)) 418 return; 419 420 /* Set starting address; reads will auto-increment */ 421 iwl_write32(priv->trans, HBUS_TARG_MEM_RADDR, ptr); 422 423 /* 424 * Refuse to read more than would have fit into the log from 425 * the current start_idx. This used to happen due to the race 426 * described below, but now WARN because the code below should 427 * prevent it from happening here. 428 */ 429 if (WARN_ON(num_events > capacity - start_idx)) 430 num_events = capacity - start_idx; 431 432 /* 433 * "time" is actually "data" for mode 0 (no timestamp). 434 * place event id # at far right for easier visual parsing. 435 */ 436 for (i = 0; i < num_events; i++) { 437 ev = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT); 438 time = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT); 439 if (mode == 0) { 440 trace_iwlwifi_dev_ucode_cont_event( 441 priv->trans->dev, 0, time, ev); 442 } else { 443 data = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT); 444 trace_iwlwifi_dev_ucode_cont_event( 445 priv->trans->dev, time, data, ev); 446 } 447 } 448 /* Allow device to power down */ 449 iwl_trans_release_nic_access(priv->trans, ®_flags); 450 } 451 452 static void iwl_continuous_event_trace(struct iwl_priv *priv) 453 { 454 u32 capacity; /* event log capacity in # entries */ 455 struct { 456 u32 capacity; 457 u32 mode; 458 u32 wrap_counter; 459 u32 write_counter; 460 } __packed read; 461 u32 base; /* SRAM byte address of event log header */ 462 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ 463 u32 num_wraps; /* # times uCode wrapped to top of log */ 464 u32 next_entry; /* index of next entry to be written by uCode */ 465 466 base = priv->device_pointers.log_event_table; 467 if (iwlagn_hw_valid_rtc_data_addr(base)) { 468 iwl_trans_read_mem_bytes(priv->trans, base, 469 &read, sizeof(read)); 470 capacity = read.capacity; 471 mode = read.mode; 472 num_wraps = read.wrap_counter; 473 next_entry = read.write_counter; 474 } else 475 return; 476 477 /* 478 * Unfortunately, the uCode doesn't use temporary variables. 479 * Therefore, it can happen that we read next_entry == capacity, 480 * which really means next_entry == 0. 481 */ 482 if (unlikely(next_entry == capacity)) 483 next_entry = 0; 484 /* 485 * Additionally, the uCode increases the write pointer before 486 * the wraps counter, so if the write pointer is smaller than 487 * the old write pointer (wrap occurred) but we read that no 488 * wrap occurred, we actually read between the next_entry and 489 * num_wraps update (this does happen in practice!!) -- take 490 * that into account by increasing num_wraps. 491 */ 492 if (unlikely(next_entry < priv->event_log.next_entry && 493 num_wraps == priv->event_log.num_wraps)) 494 num_wraps++; 495 496 if (num_wraps == priv->event_log.num_wraps) { 497 iwl_print_cont_event_trace( 498 priv, base, priv->event_log.next_entry, 499 next_entry - priv->event_log.next_entry, 500 capacity, mode); 501 502 priv->event_log.non_wraps_count++; 503 } else { 504 if (num_wraps - priv->event_log.num_wraps > 1) 505 priv->event_log.wraps_more_count++; 506 else 507 priv->event_log.wraps_once_count++; 508 509 trace_iwlwifi_dev_ucode_wrap_event(priv->trans->dev, 510 num_wraps - priv->event_log.num_wraps, 511 next_entry, priv->event_log.next_entry); 512 513 if (next_entry < priv->event_log.next_entry) { 514 iwl_print_cont_event_trace( 515 priv, base, priv->event_log.next_entry, 516 capacity - priv->event_log.next_entry, 517 capacity, mode); 518 519 iwl_print_cont_event_trace( 520 priv, base, 0, next_entry, capacity, mode); 521 } else { 522 iwl_print_cont_event_trace( 523 priv, base, next_entry, 524 capacity - next_entry, 525 capacity, mode); 526 527 iwl_print_cont_event_trace( 528 priv, base, 0, next_entry, capacity, mode); 529 } 530 } 531 532 priv->event_log.num_wraps = num_wraps; 533 priv->event_log.next_entry = next_entry; 534 } 535 536 /* 537 * iwl_bg_ucode_trace - Timer callback to log ucode event 538 * 539 * The timer is continually set to execute every 540 * UCODE_TRACE_PERIOD milliseconds after the last timer expired 541 * this function is to perform continuous uCode event logging operation 542 * if enabled 543 */ 544 static void iwl_bg_ucode_trace(struct timer_list *t) 545 { 546 struct iwl_priv *priv = from_timer(priv, t, ucode_trace); 547 548 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 549 return; 550 551 if (priv->event_log.ucode_trace) { 552 iwl_continuous_event_trace(priv); 553 /* Reschedule the timer to occur in UCODE_TRACE_PERIOD */ 554 mod_timer(&priv->ucode_trace, 555 jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD)); 556 } 557 } 558 559 static void iwl_bg_tx_flush(struct work_struct *work) 560 { 561 struct iwl_priv *priv = 562 container_of(work, struct iwl_priv, tx_flush); 563 564 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 565 return; 566 567 /* do nothing if rf-kill is on */ 568 if (!iwl_is_ready_rf(priv)) 569 return; 570 571 IWL_DEBUG_INFO(priv, "device request: flush all tx frames\n"); 572 iwlagn_dev_txfifo_flush(priv); 573 } 574 575 /* 576 * queue/FIFO/AC mapping definitions 577 */ 578 579 static const u8 iwlagn_bss_ac_to_fifo[] = { 580 IWL_TX_FIFO_VO, 581 IWL_TX_FIFO_VI, 582 IWL_TX_FIFO_BE, 583 IWL_TX_FIFO_BK, 584 }; 585 586 static const u8 iwlagn_bss_ac_to_queue[] = { 587 0, 1, 2, 3, 588 }; 589 590 static const u8 iwlagn_pan_ac_to_fifo[] = { 591 IWL_TX_FIFO_VO_IPAN, 592 IWL_TX_FIFO_VI_IPAN, 593 IWL_TX_FIFO_BE_IPAN, 594 IWL_TX_FIFO_BK_IPAN, 595 }; 596 597 static const u8 iwlagn_pan_ac_to_queue[] = { 598 7, 6, 5, 4, 599 }; 600 601 static void iwl_init_context(struct iwl_priv *priv, u32 ucode_flags) 602 { 603 int i; 604 605 /* 606 * The default context is always valid, 607 * the PAN context depends on uCode. 608 */ 609 priv->valid_contexts = BIT(IWL_RXON_CTX_BSS); 610 if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN) 611 priv->valid_contexts |= BIT(IWL_RXON_CTX_PAN); 612 613 for (i = 0; i < NUM_IWL_RXON_CTX; i++) 614 priv->contexts[i].ctxid = i; 615 616 priv->contexts[IWL_RXON_CTX_BSS].always_active = true; 617 priv->contexts[IWL_RXON_CTX_BSS].is_active = true; 618 priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON; 619 priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING; 620 priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC; 621 priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM; 622 priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID; 623 priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY; 624 priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID; 625 priv->contexts[IWL_RXON_CTX_BSS].exclusive_interface_modes = 626 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_MONITOR); 627 priv->contexts[IWL_RXON_CTX_BSS].interface_modes = 628 BIT(NL80211_IFTYPE_STATION); 629 priv->contexts[IWL_RXON_CTX_BSS].ap_devtype = RXON_DEV_TYPE_AP; 630 priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS; 631 priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS; 632 priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS; 633 memcpy(priv->contexts[IWL_RXON_CTX_BSS].ac_to_queue, 634 iwlagn_bss_ac_to_queue, sizeof(iwlagn_bss_ac_to_queue)); 635 memcpy(priv->contexts[IWL_RXON_CTX_BSS].ac_to_fifo, 636 iwlagn_bss_ac_to_fifo, sizeof(iwlagn_bss_ac_to_fifo)); 637 638 priv->contexts[IWL_RXON_CTX_PAN].rxon_cmd = REPLY_WIPAN_RXON; 639 priv->contexts[IWL_RXON_CTX_PAN].rxon_timing_cmd = 640 REPLY_WIPAN_RXON_TIMING; 641 priv->contexts[IWL_RXON_CTX_PAN].rxon_assoc_cmd = 642 REPLY_WIPAN_RXON_ASSOC; 643 priv->contexts[IWL_RXON_CTX_PAN].qos_cmd = REPLY_WIPAN_QOS_PARAM; 644 priv->contexts[IWL_RXON_CTX_PAN].ap_sta_id = IWL_AP_ID_PAN; 645 priv->contexts[IWL_RXON_CTX_PAN].wep_key_cmd = REPLY_WIPAN_WEPKEY; 646 priv->contexts[IWL_RXON_CTX_PAN].bcast_sta_id = IWLAGN_PAN_BCAST_ID; 647 priv->contexts[IWL_RXON_CTX_PAN].station_flags = STA_FLG_PAN_STATION; 648 priv->contexts[IWL_RXON_CTX_PAN].interface_modes = 649 BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP); 650 651 priv->contexts[IWL_RXON_CTX_PAN].ap_devtype = RXON_DEV_TYPE_CP; 652 priv->contexts[IWL_RXON_CTX_PAN].station_devtype = RXON_DEV_TYPE_2STA; 653 priv->contexts[IWL_RXON_CTX_PAN].unused_devtype = RXON_DEV_TYPE_P2P; 654 memcpy(priv->contexts[IWL_RXON_CTX_PAN].ac_to_queue, 655 iwlagn_pan_ac_to_queue, sizeof(iwlagn_pan_ac_to_queue)); 656 memcpy(priv->contexts[IWL_RXON_CTX_PAN].ac_to_fifo, 657 iwlagn_pan_ac_to_fifo, sizeof(iwlagn_pan_ac_to_fifo)); 658 priv->contexts[IWL_RXON_CTX_PAN].mcast_queue = IWL_IPAN_MCAST_QUEUE; 659 660 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2); 661 } 662 663 static void iwl_rf_kill_ct_config(struct iwl_priv *priv) 664 { 665 struct iwl_ct_kill_config cmd; 666 struct iwl_ct_kill_throttling_config adv_cmd; 667 int ret = 0; 668 669 iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR, 670 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); 671 672 priv->thermal_throttle.ct_kill_toggle = false; 673 674 if (priv->lib->support_ct_kill_exit) { 675 adv_cmd.critical_temperature_enter = 676 cpu_to_le32(priv->hw_params.ct_kill_threshold); 677 adv_cmd.critical_temperature_exit = 678 cpu_to_le32(priv->hw_params.ct_kill_exit_threshold); 679 680 ret = iwl_dvm_send_cmd_pdu(priv, 681 REPLY_CT_KILL_CONFIG_CMD, 682 0, sizeof(adv_cmd), &adv_cmd); 683 if (ret) 684 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n"); 685 else 686 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD " 687 "succeeded, critical temperature enter is %d," 688 "exit is %d\n", 689 priv->hw_params.ct_kill_threshold, 690 priv->hw_params.ct_kill_exit_threshold); 691 } else { 692 cmd.critical_temperature_R = 693 cpu_to_le32(priv->hw_params.ct_kill_threshold); 694 695 ret = iwl_dvm_send_cmd_pdu(priv, 696 REPLY_CT_KILL_CONFIG_CMD, 697 0, sizeof(cmd), &cmd); 698 if (ret) 699 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n"); 700 else 701 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD " 702 "succeeded, " 703 "critical temperature is %d\n", 704 priv->hw_params.ct_kill_threshold); 705 } 706 } 707 708 static int iwlagn_send_calib_cfg_rt(struct iwl_priv *priv, u32 cfg) 709 { 710 struct iwl_calib_cfg_cmd calib_cfg_cmd; 711 struct iwl_host_cmd cmd = { 712 .id = CALIBRATION_CFG_CMD, 713 .len = { sizeof(struct iwl_calib_cfg_cmd), }, 714 .data = { &calib_cfg_cmd, }, 715 }; 716 717 memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd)); 718 calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_RT_CFG_ALL; 719 calib_cfg_cmd.ucd_calib_cfg.once.start = cpu_to_le32(cfg); 720 721 return iwl_dvm_send_cmd(priv, &cmd); 722 } 723 724 725 static int iwlagn_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant) 726 { 727 struct iwl_tx_ant_config_cmd tx_ant_cmd = { 728 .valid = cpu_to_le32(valid_tx_ant), 729 }; 730 731 if (IWL_UCODE_API(priv->fw->ucode_ver) > 1) { 732 IWL_DEBUG_HC(priv, "select valid tx ant: %u\n", valid_tx_ant); 733 return iwl_dvm_send_cmd_pdu(priv, TX_ANT_CONFIGURATION_CMD, 0, 734 sizeof(struct iwl_tx_ant_config_cmd), 735 &tx_ant_cmd); 736 } else { 737 IWL_DEBUG_HC(priv, "TX_ANT_CONFIGURATION_CMD not supported\n"); 738 return -EOPNOTSUPP; 739 } 740 } 741 742 static void iwl_send_bt_config(struct iwl_priv *priv) 743 { 744 struct iwl_bt_cmd bt_cmd = { 745 .lead_time = BT_LEAD_TIME_DEF, 746 .max_kill = BT_MAX_KILL_DEF, 747 .kill_ack_mask = 0, 748 .kill_cts_mask = 0, 749 }; 750 751 if (!iwlwifi_mod_params.bt_coex_active) 752 bt_cmd.flags = BT_COEX_DISABLE; 753 else 754 bt_cmd.flags = BT_COEX_ENABLE; 755 756 priv->bt_enable_flag = bt_cmd.flags; 757 IWL_DEBUG_INFO(priv, "BT coex %s\n", 758 (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active"); 759 760 if (iwl_dvm_send_cmd_pdu(priv, REPLY_BT_CONFIG, 761 0, sizeof(struct iwl_bt_cmd), &bt_cmd)) 762 IWL_ERR(priv, "failed to send BT Coex Config\n"); 763 } 764 765 /* 766 * iwl_alive_start - called after REPLY_ALIVE notification received 767 * from protocol/runtime uCode (initialization uCode's 768 * Alive gets handled by iwl_init_alive_start()). 769 */ 770 int iwl_alive_start(struct iwl_priv *priv) 771 { 772 int ret = 0; 773 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; 774 775 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n"); 776 777 /* After the ALIVE response, we can send host commands to the uCode */ 778 set_bit(STATUS_ALIVE, &priv->status); 779 780 if (iwl_is_rfkill(priv)) 781 return -ERFKILL; 782 783 if (priv->event_log.ucode_trace) { 784 /* start collecting data now */ 785 mod_timer(&priv->ucode_trace, jiffies); 786 } 787 788 /* download priority table before any calibration request */ 789 if (priv->lib->bt_params && 790 priv->lib->bt_params->advanced_bt_coexist) { 791 /* Configure Bluetooth device coexistence support */ 792 if (priv->lib->bt_params->bt_sco_disable) 793 priv->bt_enable_pspoll = false; 794 else 795 priv->bt_enable_pspoll = true; 796 797 priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK; 798 priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT; 799 priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT; 800 iwlagn_send_advance_bt_config(priv); 801 priv->bt_valid = IWLAGN_BT_VALID_ENABLE_FLAGS; 802 priv->cur_rssi_ctx = NULL; 803 804 iwl_send_prio_tbl(priv); 805 806 /* FIXME: w/a to force change uCode BT state machine */ 807 ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN, 808 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2); 809 if (ret) 810 return ret; 811 ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE, 812 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2); 813 if (ret) 814 return ret; 815 } else if (priv->lib->bt_params) { 816 /* 817 * default is 2-wire BT coexexistence support 818 */ 819 iwl_send_bt_config(priv); 820 } 821 822 /* 823 * Perform runtime calibrations, including DC calibration. 824 */ 825 iwlagn_send_calib_cfg_rt(priv, IWL_CALIB_CFG_DC_IDX); 826 827 ieee80211_wake_queues(priv->hw); 828 829 /* Configure Tx antenna selection based on H/W config */ 830 iwlagn_send_tx_ant_config(priv, priv->nvm_data->valid_tx_ant); 831 832 if (iwl_is_associated_ctx(ctx) && !priv->wowlan) { 833 struct iwl_rxon_cmd *active_rxon = 834 (struct iwl_rxon_cmd *)&ctx->active; 835 /* apply any changes in staging */ 836 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK; 837 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; 838 } else { 839 struct iwl_rxon_context *tmp; 840 /* Initialize our rx_config data */ 841 for_each_context(priv, tmp) 842 iwl_connection_init_rx_config(priv, tmp); 843 844 iwlagn_set_rxon_chain(priv, ctx); 845 } 846 847 if (!priv->wowlan) { 848 /* WoWLAN ucode will not reply in the same way, skip it */ 849 iwl_reset_run_time_calib(priv); 850 } 851 852 set_bit(STATUS_READY, &priv->status); 853 854 /* Configure the adapter for unassociated operation */ 855 ret = iwlagn_commit_rxon(priv, ctx); 856 if (ret) 857 return ret; 858 859 /* At this point, the NIC is initialized and operational */ 860 iwl_rf_kill_ct_config(priv); 861 862 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n"); 863 864 return iwl_power_update_mode(priv, true); 865 } 866 867 /** 868 * iwl_clear_driver_stations - clear knowledge of all stations from driver 869 * @priv: iwl priv struct 870 * 871 * This is called during iwl_down() to make sure that in the case 872 * we're coming there from a hardware restart mac80211 will be 873 * able to reconfigure stations -- if we're getting there in the 874 * normal down flow then the stations will already be cleared. 875 */ 876 static void iwl_clear_driver_stations(struct iwl_priv *priv) 877 { 878 struct iwl_rxon_context *ctx; 879 880 spin_lock_bh(&priv->sta_lock); 881 memset(priv->stations, 0, sizeof(priv->stations)); 882 priv->num_stations = 0; 883 884 priv->ucode_key_table = 0; 885 886 for_each_context(priv, ctx) { 887 /* 888 * Remove all key information that is not stored as part 889 * of station information since mac80211 may not have had 890 * a chance to remove all the keys. When device is 891 * reconfigured by mac80211 after an error all keys will 892 * be reconfigured. 893 */ 894 memset(ctx->wep_keys, 0, sizeof(ctx->wep_keys)); 895 ctx->key_mapping_keys = 0; 896 } 897 898 spin_unlock_bh(&priv->sta_lock); 899 } 900 901 void iwl_down(struct iwl_priv *priv) 902 { 903 int exit_pending; 904 905 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n"); 906 907 lockdep_assert_held(&priv->mutex); 908 909 iwl_scan_cancel_timeout(priv, 200); 910 911 exit_pending = 912 test_and_set_bit(STATUS_EXIT_PENDING, &priv->status); 913 914 iwl_clear_ucode_stations(priv, NULL); 915 iwl_dealloc_bcast_stations(priv); 916 iwl_clear_driver_stations(priv); 917 918 /* reset BT coex data */ 919 priv->bt_status = 0; 920 priv->cur_rssi_ctx = NULL; 921 priv->bt_is_sco = 0; 922 if (priv->lib->bt_params) 923 priv->bt_traffic_load = 924 priv->lib->bt_params->bt_init_traffic_load; 925 else 926 priv->bt_traffic_load = 0; 927 priv->bt_full_concurrent = false; 928 priv->bt_ci_compliance = 0; 929 930 /* Wipe out the EXIT_PENDING status bit if we are not actually 931 * exiting the module */ 932 if (!exit_pending) 933 clear_bit(STATUS_EXIT_PENDING, &priv->status); 934 935 if (priv->mac80211_registered) 936 ieee80211_stop_queues(priv->hw); 937 938 priv->ucode_loaded = false; 939 iwl_trans_stop_device(priv->trans); 940 941 /* Set num_aux_in_flight must be done after the transport is stopped */ 942 atomic_set(&priv->num_aux_in_flight, 0); 943 944 /* Clear out all status bits but a few that are stable across reset */ 945 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << 946 STATUS_RF_KILL_HW | 947 test_bit(STATUS_FW_ERROR, &priv->status) << 948 STATUS_FW_ERROR | 949 test_bit(STATUS_EXIT_PENDING, &priv->status) << 950 STATUS_EXIT_PENDING; 951 952 dev_kfree_skb(priv->beacon_skb); 953 priv->beacon_skb = NULL; 954 } 955 956 /***************************************************************************** 957 * 958 * Workqueue callbacks 959 * 960 *****************************************************************************/ 961 962 static void iwl_bg_run_time_calib_work(struct work_struct *work) 963 { 964 struct iwl_priv *priv = container_of(work, struct iwl_priv, 965 run_time_calib_work); 966 967 mutex_lock(&priv->mutex); 968 969 if (test_bit(STATUS_EXIT_PENDING, &priv->status) || 970 test_bit(STATUS_SCANNING, &priv->status)) { 971 mutex_unlock(&priv->mutex); 972 return; 973 } 974 975 if (priv->start_calib) { 976 iwl_chain_noise_calibration(priv); 977 iwl_sensitivity_calibration(priv); 978 } 979 980 mutex_unlock(&priv->mutex); 981 } 982 983 void iwlagn_prepare_restart(struct iwl_priv *priv) 984 { 985 bool bt_full_concurrent; 986 u8 bt_ci_compliance; 987 u8 bt_load; 988 u8 bt_status; 989 bool bt_is_sco; 990 int i; 991 992 lockdep_assert_held(&priv->mutex); 993 994 priv->is_open = 0; 995 996 /* 997 * __iwl_down() will clear the BT status variables, 998 * which is correct, but when we restart we really 999 * want to keep them so restore them afterwards. 1000 * 1001 * The restart process will later pick them up and 1002 * re-configure the hw when we reconfigure the BT 1003 * command. 1004 */ 1005 bt_full_concurrent = priv->bt_full_concurrent; 1006 bt_ci_compliance = priv->bt_ci_compliance; 1007 bt_load = priv->bt_traffic_load; 1008 bt_status = priv->bt_status; 1009 bt_is_sco = priv->bt_is_sco; 1010 1011 iwl_down(priv); 1012 1013 priv->bt_full_concurrent = bt_full_concurrent; 1014 priv->bt_ci_compliance = bt_ci_compliance; 1015 priv->bt_traffic_load = bt_load; 1016 priv->bt_status = bt_status; 1017 priv->bt_is_sco = bt_is_sco; 1018 1019 /* reset aggregation queues */ 1020 for (i = IWLAGN_FIRST_AMPDU_QUEUE; i < IWL_MAX_HW_QUEUES; i++) 1021 priv->queue_to_mac80211[i] = IWL_INVALID_MAC80211_QUEUE; 1022 /* and stop counts */ 1023 for (i = 0; i < IWL_MAX_HW_QUEUES; i++) 1024 atomic_set(&priv->queue_stop_count[i], 0); 1025 1026 memset(priv->agg_q_alloc, 0, sizeof(priv->agg_q_alloc)); 1027 } 1028 1029 static void iwl_bg_restart(struct work_struct *data) 1030 { 1031 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart); 1032 1033 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 1034 return; 1035 1036 if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) { 1037 mutex_lock(&priv->mutex); 1038 iwlagn_prepare_restart(priv); 1039 mutex_unlock(&priv->mutex); 1040 iwl_cancel_deferred_work(priv); 1041 if (priv->mac80211_registered) 1042 ieee80211_restart_hw(priv->hw); 1043 else 1044 IWL_ERR(priv, 1045 "Cannot request restart before registering with mac80211\n"); 1046 } else { 1047 WARN_ON(1); 1048 } 1049 } 1050 1051 /***************************************************************************** 1052 * 1053 * driver setup and teardown 1054 * 1055 *****************************************************************************/ 1056 1057 static void iwl_setup_deferred_work(struct iwl_priv *priv) 1058 { 1059 priv->workqueue = alloc_ordered_workqueue(DRV_NAME, 0); 1060 1061 INIT_WORK(&priv->restart, iwl_bg_restart); 1062 INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update); 1063 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work); 1064 INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush); 1065 INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency); 1066 INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config); 1067 1068 iwl_setup_scan_deferred_work(priv); 1069 1070 if (priv->lib->bt_params) 1071 iwlagn_bt_setup_deferred_work(priv); 1072 1073 timer_setup(&priv->statistics_periodic, iwl_bg_statistics_periodic, 0); 1074 1075 timer_setup(&priv->ucode_trace, iwl_bg_ucode_trace, 0); 1076 } 1077 1078 void iwl_cancel_deferred_work(struct iwl_priv *priv) 1079 { 1080 if (priv->lib->bt_params) 1081 iwlagn_bt_cancel_deferred_work(priv); 1082 1083 cancel_work_sync(&priv->run_time_calib_work); 1084 cancel_work_sync(&priv->beacon_update); 1085 1086 iwl_cancel_scan_deferred_work(priv); 1087 1088 cancel_work_sync(&priv->bt_full_concurrency); 1089 cancel_work_sync(&priv->bt_runtime_config); 1090 1091 del_timer_sync(&priv->statistics_periodic); 1092 del_timer_sync(&priv->ucode_trace); 1093 } 1094 1095 static int iwl_init_drv(struct iwl_priv *priv) 1096 { 1097 spin_lock_init(&priv->sta_lock); 1098 1099 mutex_init(&priv->mutex); 1100 1101 INIT_LIST_HEAD(&priv->calib_results); 1102 1103 priv->band = NL80211_BAND_2GHZ; 1104 1105 priv->plcp_delta_threshold = priv->lib->plcp_delta_threshold; 1106 1107 priv->iw_mode = NL80211_IFTYPE_STATION; 1108 priv->current_ht_config.smps = IEEE80211_SMPS_STATIC; 1109 priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF; 1110 priv->agg_tids_count = 0; 1111 1112 priv->rx_statistics_jiffies = jiffies; 1113 1114 /* Choose which receivers/antennas to use */ 1115 iwlagn_set_rxon_chain(priv, &priv->contexts[IWL_RXON_CTX_BSS]); 1116 1117 iwl_init_scan_params(priv); 1118 1119 /* init bt coex */ 1120 if (priv->lib->bt_params && 1121 priv->lib->bt_params->advanced_bt_coexist) { 1122 priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT; 1123 priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT; 1124 priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK; 1125 priv->bt_on_thresh = BT_ON_THRESHOLD_DEF; 1126 priv->bt_duration = BT_DURATION_LIMIT_DEF; 1127 priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF; 1128 } 1129 1130 return 0; 1131 } 1132 1133 static void iwl_uninit_drv(struct iwl_priv *priv) 1134 { 1135 kfree(priv->scan_cmd); 1136 kfree(priv->beacon_cmd); 1137 kfree(rcu_dereference_raw(priv->noa_data)); 1138 iwl_calib_free_results(priv); 1139 #ifdef CONFIG_IWLWIFI_DEBUGFS 1140 kfree(priv->wowlan_sram); 1141 #endif 1142 } 1143 1144 static void iwl_set_hw_params(struct iwl_priv *priv) 1145 { 1146 if (priv->cfg->ht_params) 1147 priv->hw_params.use_rts_for_aggregation = 1148 priv->cfg->ht_params->use_rts_for_aggregation; 1149 1150 /* Device-specific setup */ 1151 priv->lib->set_hw_params(priv); 1152 } 1153 1154 1155 1156 /* show what optional capabilities we have */ 1157 static void iwl_option_config(struct iwl_priv *priv) 1158 { 1159 #ifdef CONFIG_IWLWIFI_DEBUG 1160 IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUG enabled\n"); 1161 #else 1162 IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUG disabled\n"); 1163 #endif 1164 1165 #ifdef CONFIG_IWLWIFI_DEBUGFS 1166 IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUGFS enabled\n"); 1167 #else 1168 IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUGFS disabled\n"); 1169 #endif 1170 1171 #ifdef CONFIG_IWLWIFI_DEVICE_TRACING 1172 IWL_INFO(priv, "CONFIG_IWLWIFI_DEVICE_TRACING enabled\n"); 1173 #else 1174 IWL_INFO(priv, "CONFIG_IWLWIFI_DEVICE_TRACING disabled\n"); 1175 #endif 1176 } 1177 1178 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv) 1179 { 1180 struct iwl_nvm_data *data = priv->nvm_data; 1181 1182 if (data->sku_cap_11n_enable && 1183 !priv->cfg->ht_params) { 1184 IWL_ERR(priv, "Invalid 11n configuration\n"); 1185 return -EINVAL; 1186 } 1187 1188 if (!data->sku_cap_11n_enable && !data->sku_cap_band_24ghz_enable && 1189 !data->sku_cap_band_52ghz_enable) { 1190 IWL_ERR(priv, "Invalid device sku\n"); 1191 return -EINVAL; 1192 } 1193 1194 IWL_DEBUG_INFO(priv, 1195 "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n", 1196 data->sku_cap_band_24ghz_enable ? "" : "NOT", "enabled", 1197 data->sku_cap_band_52ghz_enable ? "" : "NOT", "enabled", 1198 data->sku_cap_11n_enable ? "" : "NOT", "enabled"); 1199 1200 priv->hw_params.tx_chains_num = 1201 num_of_ant(data->valid_tx_ant); 1202 if (priv->cfg->rx_with_siso_diversity) 1203 priv->hw_params.rx_chains_num = 1; 1204 else 1205 priv->hw_params.rx_chains_num = 1206 num_of_ant(data->valid_rx_ant); 1207 1208 IWL_DEBUG_INFO(priv, "Valid Tx ant: 0x%X, Valid Rx ant: 0x%X\n", 1209 data->valid_tx_ant, 1210 data->valid_rx_ant); 1211 1212 return 0; 1213 } 1214 1215 static int iwl_nvm_check_version(struct iwl_nvm_data *data, 1216 struct iwl_trans *trans) 1217 { 1218 if (data->nvm_version >= trans->cfg->nvm_ver || 1219 data->calib_version >= trans->cfg->nvm_calib_ver) { 1220 IWL_DEBUG_INFO(trans, "device EEPROM VER=0x%x, CALIB=0x%x\n", 1221 data->nvm_version, data->calib_version); 1222 return 0; 1223 } 1224 1225 IWL_ERR(trans, 1226 "Unsupported (too old) EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n", 1227 data->nvm_version, trans->cfg->nvm_ver, 1228 data->calib_version, trans->cfg->nvm_calib_ver); 1229 return -EINVAL; 1230 } 1231 1232 static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans, 1233 const struct iwl_cfg *cfg, 1234 const struct iwl_fw *fw, 1235 struct dentry *dbgfs_dir) 1236 { 1237 struct iwl_priv *priv; 1238 struct ieee80211_hw *hw; 1239 struct iwl_op_mode *op_mode; 1240 u16 num_mac; 1241 u32 ucode_flags; 1242 struct iwl_trans_config trans_cfg = {}; 1243 static const u8 no_reclaim_cmds[] = { 1244 REPLY_RX_PHY_CMD, 1245 REPLY_RX_MPDU_CMD, 1246 REPLY_COMPRESSED_BA, 1247 STATISTICS_NOTIFICATION, 1248 REPLY_TX, 1249 }; 1250 int i; 1251 1252 /************************ 1253 * 1. Allocating HW data 1254 ************************/ 1255 hw = iwl_alloc_all(); 1256 if (!hw) { 1257 pr_err("%s: Cannot allocate network device\n", trans->name); 1258 goto out; 1259 } 1260 1261 op_mode = hw->priv; 1262 op_mode->ops = &iwl_dvm_ops; 1263 priv = IWL_OP_MODE_GET_DVM(op_mode); 1264 priv->trans = trans; 1265 priv->dev = trans->dev; 1266 priv->cfg = cfg; 1267 priv->fw = fw; 1268 1269 switch (priv->trans->trans_cfg->device_family) { 1270 case IWL_DEVICE_FAMILY_1000: 1271 case IWL_DEVICE_FAMILY_100: 1272 priv->lib = &iwl_dvm_1000_cfg; 1273 break; 1274 case IWL_DEVICE_FAMILY_2000: 1275 priv->lib = &iwl_dvm_2000_cfg; 1276 break; 1277 case IWL_DEVICE_FAMILY_105: 1278 priv->lib = &iwl_dvm_105_cfg; 1279 break; 1280 case IWL_DEVICE_FAMILY_2030: 1281 case IWL_DEVICE_FAMILY_135: 1282 priv->lib = &iwl_dvm_2030_cfg; 1283 break; 1284 case IWL_DEVICE_FAMILY_5000: 1285 priv->lib = &iwl_dvm_5000_cfg; 1286 break; 1287 case IWL_DEVICE_FAMILY_5150: 1288 priv->lib = &iwl_dvm_5150_cfg; 1289 break; 1290 case IWL_DEVICE_FAMILY_6000: 1291 case IWL_DEVICE_FAMILY_6000i: 1292 priv->lib = &iwl_dvm_6000_cfg; 1293 break; 1294 case IWL_DEVICE_FAMILY_6005: 1295 priv->lib = &iwl_dvm_6005_cfg; 1296 break; 1297 case IWL_DEVICE_FAMILY_6050: 1298 case IWL_DEVICE_FAMILY_6150: 1299 priv->lib = &iwl_dvm_6050_cfg; 1300 break; 1301 case IWL_DEVICE_FAMILY_6030: 1302 priv->lib = &iwl_dvm_6030_cfg; 1303 break; 1304 default: 1305 break; 1306 } 1307 1308 if (WARN_ON(!priv->lib)) 1309 goto out_free_hw; 1310 1311 /* 1312 * Populate the state variables that the transport layer needs 1313 * to know about. 1314 */ 1315 trans_cfg.op_mode = op_mode; 1316 trans_cfg.no_reclaim_cmds = no_reclaim_cmds; 1317 trans_cfg.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds); 1318 1319 switch (iwlwifi_mod_params.amsdu_size) { 1320 case IWL_AMSDU_DEF: 1321 case IWL_AMSDU_4K: 1322 trans_cfg.rx_buf_size = IWL_AMSDU_4K; 1323 break; 1324 case IWL_AMSDU_8K: 1325 trans_cfg.rx_buf_size = IWL_AMSDU_8K; 1326 break; 1327 case IWL_AMSDU_12K: 1328 default: 1329 trans_cfg.rx_buf_size = IWL_AMSDU_4K; 1330 pr_err("Unsupported amsdu_size: %d\n", 1331 iwlwifi_mod_params.amsdu_size); 1332 } 1333 1334 trans_cfg.cmd_q_wdg_timeout = IWL_WATCHDOG_DISABLED; 1335 1336 trans_cfg.command_groups = iwl_dvm_groups; 1337 trans_cfg.command_groups_size = ARRAY_SIZE(iwl_dvm_groups); 1338 1339 trans_cfg.cmd_fifo = IWLAGN_CMD_FIFO_NUM; 1340 trans_cfg.cb_data_offs = offsetof(struct ieee80211_tx_info, 1341 driver_data[2]); 1342 1343 WARN_ON(sizeof(priv->transport_queue_stop) * BITS_PER_BYTE < 1344 priv->trans->trans_cfg->base_params->num_of_queues); 1345 1346 ucode_flags = fw->ucode_capa.flags; 1347 1348 if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN) { 1349 priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN; 1350 trans_cfg.cmd_queue = IWL_IPAN_CMD_QUEUE_NUM; 1351 } else { 1352 priv->sta_key_max_num = STA_KEY_MAX_NUM; 1353 trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM; 1354 } 1355 1356 /* Configure transport layer */ 1357 iwl_trans_configure(priv->trans, &trans_cfg); 1358 1359 trans->rx_mpdu_cmd = REPLY_RX_MPDU_CMD; 1360 trans->rx_mpdu_cmd_hdr_size = sizeof(struct iwl_rx_mpdu_res_start); 1361 trans->command_groups = trans_cfg.command_groups; 1362 trans->command_groups_size = trans_cfg.command_groups_size; 1363 1364 /* At this point both hw and priv are allocated. */ 1365 1366 SET_IEEE80211_DEV(priv->hw, priv->trans->dev); 1367 1368 iwl_option_config(priv); 1369 1370 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n"); 1371 1372 /* bt channel inhibition enabled*/ 1373 priv->bt_ch_announce = true; 1374 IWL_DEBUG_INFO(priv, "BT channel inhibition is %s\n", 1375 (priv->bt_ch_announce) ? "On" : "Off"); 1376 1377 /* these spin locks will be used in apm_ops.init and EEPROM access 1378 * we should init now 1379 */ 1380 spin_lock_init(&priv->statistics.lock); 1381 1382 /*********************** 1383 * 2. Read REV register 1384 ***********************/ 1385 IWL_INFO(priv, "Detected %s, REV=0x%X\n", 1386 priv->trans->name, priv->trans->hw_rev); 1387 1388 if (iwl_trans_start_hw(priv->trans)) 1389 goto out_free_hw; 1390 1391 /* Read the EEPROM */ 1392 if (iwl_read_eeprom(priv->trans, &priv->eeprom_blob, 1393 &priv->eeprom_blob_size)) { 1394 IWL_ERR(priv, "Unable to init EEPROM\n"); 1395 goto out_free_hw; 1396 } 1397 1398 /* Reset chip to save power until we load uCode during "up". */ 1399 iwl_trans_stop_device(priv->trans); 1400 1401 priv->nvm_data = iwl_parse_eeprom_data(priv->trans, priv->cfg, 1402 priv->eeprom_blob, 1403 priv->eeprom_blob_size); 1404 if (!priv->nvm_data) 1405 goto out_free_eeprom_blob; 1406 1407 if (iwl_nvm_check_version(priv->nvm_data, priv->trans)) 1408 goto out_free_eeprom; 1409 1410 if (iwl_eeprom_init_hw_params(priv)) 1411 goto out_free_eeprom; 1412 1413 /* extract MAC Address */ 1414 memcpy(priv->addresses[0].addr, priv->nvm_data->hw_addr, ETH_ALEN); 1415 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr); 1416 priv->hw->wiphy->addresses = priv->addresses; 1417 priv->hw->wiphy->n_addresses = 1; 1418 num_mac = priv->nvm_data->n_hw_addrs; 1419 if (num_mac > 1) { 1420 memcpy(priv->addresses[1].addr, priv->addresses[0].addr, 1421 ETH_ALEN); 1422 priv->addresses[1].addr[5]++; 1423 priv->hw->wiphy->n_addresses++; 1424 } 1425 1426 /************************ 1427 * 4. Setup HW constants 1428 ************************/ 1429 iwl_set_hw_params(priv); 1430 1431 if (!(priv->nvm_data->sku_cap_ipan_enable)) { 1432 IWL_DEBUG_INFO(priv, "Your EEPROM disabled PAN\n"); 1433 ucode_flags &= ~IWL_UCODE_TLV_FLAGS_PAN; 1434 /* 1435 * if not PAN, then don't support P2P -- might be a uCode 1436 * packaging bug or due to the eeprom check above 1437 */ 1438 priv->sta_key_max_num = STA_KEY_MAX_NUM; 1439 trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM; 1440 1441 /* Configure transport layer again*/ 1442 iwl_trans_configure(priv->trans, &trans_cfg); 1443 } 1444 1445 /******************* 1446 * 5. Setup priv 1447 *******************/ 1448 for (i = 0; i < IWL_MAX_HW_QUEUES; i++) { 1449 priv->queue_to_mac80211[i] = IWL_INVALID_MAC80211_QUEUE; 1450 if (i < IWLAGN_FIRST_AMPDU_QUEUE && 1451 i != IWL_DEFAULT_CMD_QUEUE_NUM && 1452 i != IWL_IPAN_CMD_QUEUE_NUM) 1453 priv->queue_to_mac80211[i] = i; 1454 atomic_set(&priv->queue_stop_count[i], 0); 1455 } 1456 1457 if (iwl_init_drv(priv)) 1458 goto out_free_eeprom; 1459 1460 /* At this point both hw and priv are initialized. */ 1461 1462 /******************** 1463 * 6. Setup services 1464 ********************/ 1465 iwl_setup_deferred_work(priv); 1466 iwl_setup_rx_handlers(priv); 1467 1468 iwl_power_initialize(priv); 1469 iwl_tt_initialize(priv); 1470 1471 snprintf(priv->hw->wiphy->fw_version, 1472 sizeof(priv->hw->wiphy->fw_version), 1473 "%s", fw->fw_version); 1474 1475 priv->new_scan_threshold_behaviour = 1476 !!(ucode_flags & IWL_UCODE_TLV_FLAGS_NEWSCAN); 1477 1478 priv->phy_calib_chain_noise_reset_cmd = 1479 fw->ucode_capa.standard_phy_calibration_size; 1480 priv->phy_calib_chain_noise_gain_cmd = 1481 fw->ucode_capa.standard_phy_calibration_size + 1; 1482 1483 /* initialize all valid contexts */ 1484 iwl_init_context(priv, ucode_flags); 1485 1486 /************************************************** 1487 * This is still part of probe() in a sense... 1488 * 1489 * 7. Setup and register with mac80211 and debugfs 1490 **************************************************/ 1491 if (iwlagn_mac_setup_register(priv, &fw->ucode_capa)) 1492 goto out_destroy_workqueue; 1493 1494 iwl_dbgfs_register(priv, dbgfs_dir); 1495 1496 return op_mode; 1497 1498 out_destroy_workqueue: 1499 iwl_tt_exit(priv); 1500 iwl_cancel_deferred_work(priv); 1501 destroy_workqueue(priv->workqueue); 1502 priv->workqueue = NULL; 1503 iwl_uninit_drv(priv); 1504 out_free_eeprom_blob: 1505 kfree(priv->eeprom_blob); 1506 out_free_eeprom: 1507 kfree(priv->nvm_data); 1508 out_free_hw: 1509 ieee80211_free_hw(priv->hw); 1510 out: 1511 op_mode = NULL; 1512 return op_mode; 1513 } 1514 1515 static void iwl_op_mode_dvm_stop(struct iwl_op_mode *op_mode) 1516 { 1517 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); 1518 1519 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n"); 1520 1521 iwlagn_mac_unregister(priv); 1522 1523 iwl_tt_exit(priv); 1524 1525 kfree(priv->eeprom_blob); 1526 kfree(priv->nvm_data); 1527 1528 /*netif_stop_queue(dev); */ 1529 flush_workqueue(priv->workqueue); 1530 1531 /* ieee80211_unregister_hw calls iwlagn_mac_stop, which flushes 1532 * priv->workqueue... so we can't take down the workqueue 1533 * until now... */ 1534 destroy_workqueue(priv->workqueue); 1535 priv->workqueue = NULL; 1536 1537 iwl_uninit_drv(priv); 1538 1539 dev_kfree_skb(priv->beacon_skb); 1540 1541 iwl_trans_op_mode_leave(priv->trans); 1542 ieee80211_free_hw(priv->hw); 1543 } 1544 1545 static const char * const desc_lookup_text[] = { 1546 "OK", 1547 "FAIL", 1548 "BAD_PARAM", 1549 "BAD_CHECKSUM", 1550 "NMI_INTERRUPT_WDG", 1551 "SYSASSERT", 1552 "FATAL_ERROR", 1553 "BAD_COMMAND", 1554 "HW_ERROR_TUNE_LOCK", 1555 "HW_ERROR_TEMPERATURE", 1556 "ILLEGAL_CHAN_FREQ", 1557 "VCC_NOT_STABLE", 1558 "FH_ERROR", 1559 "NMI_INTERRUPT_HOST", 1560 "NMI_INTERRUPT_ACTION_PT", 1561 "NMI_INTERRUPT_UNKNOWN", 1562 "UCODE_VERSION_MISMATCH", 1563 "HW_ERROR_ABS_LOCK", 1564 "HW_ERROR_CAL_LOCK_FAIL", 1565 "NMI_INTERRUPT_INST_ACTION_PT", 1566 "NMI_INTERRUPT_DATA_ACTION_PT", 1567 "NMI_TRM_HW_ER", 1568 "NMI_INTERRUPT_TRM", 1569 "NMI_INTERRUPT_BREAK_POINT", 1570 "DEBUG_0", 1571 "DEBUG_1", 1572 "DEBUG_2", 1573 "DEBUG_3", 1574 }; 1575 1576 static struct { char *name; u8 num; } advanced_lookup[] = { 1577 { "NMI_INTERRUPT_WDG", 0x34 }, 1578 { "SYSASSERT", 0x35 }, 1579 { "UCODE_VERSION_MISMATCH", 0x37 }, 1580 { "BAD_COMMAND", 0x38 }, 1581 { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C }, 1582 { "FATAL_ERROR", 0x3D }, 1583 { "NMI_TRM_HW_ERR", 0x46 }, 1584 { "NMI_INTERRUPT_TRM", 0x4C }, 1585 { "NMI_INTERRUPT_BREAK_POINT", 0x54 }, 1586 { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C }, 1587 { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 }, 1588 { "NMI_INTERRUPT_HOST", 0x66 }, 1589 { "NMI_INTERRUPT_ACTION_PT", 0x7C }, 1590 { "NMI_INTERRUPT_UNKNOWN", 0x84 }, 1591 { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 }, 1592 { "ADVANCED_SYSASSERT", 0 }, 1593 }; 1594 1595 static const char *desc_lookup(u32 num) 1596 { 1597 int i; 1598 int max = ARRAY_SIZE(desc_lookup_text); 1599 1600 if (num < max) 1601 return desc_lookup_text[num]; 1602 1603 max = ARRAY_SIZE(advanced_lookup) - 1; 1604 for (i = 0; i < max; i++) { 1605 if (advanced_lookup[i].num == num) 1606 break; 1607 } 1608 return advanced_lookup[i].name; 1609 } 1610 1611 #define ERROR_START_OFFSET (1 * sizeof(u32)) 1612 #define ERROR_ELEM_SIZE (7 * sizeof(u32)) 1613 1614 static void iwl_dump_nic_error_log(struct iwl_priv *priv) 1615 { 1616 struct iwl_trans *trans = priv->trans; 1617 u32 base; 1618 struct iwl_error_event_table table; 1619 1620 base = priv->device_pointers.error_event_table; 1621 if (priv->cur_ucode == IWL_UCODE_INIT) { 1622 if (!base) 1623 base = priv->fw->init_errlog_ptr; 1624 } else { 1625 if (!base) 1626 base = priv->fw->inst_errlog_ptr; 1627 } 1628 1629 if (!iwlagn_hw_valid_rtc_data_addr(base)) { 1630 IWL_ERR(priv, 1631 "Not valid error log pointer 0x%08X for %s uCode\n", 1632 base, 1633 (priv->cur_ucode == IWL_UCODE_INIT) 1634 ? "Init" : "RT"); 1635 return; 1636 } 1637 1638 /*TODO: Update dbgfs with ISR error stats obtained below */ 1639 iwl_trans_read_mem_bytes(trans, base, &table, sizeof(table)); 1640 1641 if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) { 1642 IWL_ERR(trans, "Start IWL Error Log Dump:\n"); 1643 IWL_ERR(trans, "Status: 0x%08lX, count: %d\n", 1644 priv->status, table.valid); 1645 } 1646 1647 IWL_ERR(priv, "0x%08X | %-28s\n", table.error_id, 1648 desc_lookup(table.error_id)); 1649 IWL_ERR(priv, "0x%08X | uPc\n", table.pc); 1650 IWL_ERR(priv, "0x%08X | branchlink1\n", table.blink1); 1651 IWL_ERR(priv, "0x%08X | branchlink2\n", table.blink2); 1652 IWL_ERR(priv, "0x%08X | interruptlink1\n", table.ilink1); 1653 IWL_ERR(priv, "0x%08X | interruptlink2\n", table.ilink2); 1654 IWL_ERR(priv, "0x%08X | data1\n", table.data1); 1655 IWL_ERR(priv, "0x%08X | data2\n", table.data2); 1656 IWL_ERR(priv, "0x%08X | line\n", table.line); 1657 IWL_ERR(priv, "0x%08X | beacon time\n", table.bcon_time); 1658 IWL_ERR(priv, "0x%08X | tsf low\n", table.tsf_low); 1659 IWL_ERR(priv, "0x%08X | tsf hi\n", table.tsf_hi); 1660 IWL_ERR(priv, "0x%08X | time gp1\n", table.gp1); 1661 IWL_ERR(priv, "0x%08X | time gp2\n", table.gp2); 1662 IWL_ERR(priv, "0x%08X | time gp3\n", table.gp3); 1663 IWL_ERR(priv, "0x%08X | uCode version\n", table.ucode_ver); 1664 IWL_ERR(priv, "0x%08X | hw version\n", table.hw_ver); 1665 IWL_ERR(priv, "0x%08X | board version\n", table.brd_ver); 1666 IWL_ERR(priv, "0x%08X | hcmd\n", table.hcmd); 1667 IWL_ERR(priv, "0x%08X | isr0\n", table.isr0); 1668 IWL_ERR(priv, "0x%08X | isr1\n", table.isr1); 1669 IWL_ERR(priv, "0x%08X | isr2\n", table.isr2); 1670 IWL_ERR(priv, "0x%08X | isr3\n", table.isr3); 1671 IWL_ERR(priv, "0x%08X | isr4\n", table.isr4); 1672 IWL_ERR(priv, "0x%08X | isr_pref\n", table.isr_pref); 1673 IWL_ERR(priv, "0x%08X | wait_event\n", table.wait_event); 1674 IWL_ERR(priv, "0x%08X | l2p_control\n", table.l2p_control); 1675 IWL_ERR(priv, "0x%08X | l2p_duration\n", table.l2p_duration); 1676 IWL_ERR(priv, "0x%08X | l2p_mhvalid\n", table.l2p_mhvalid); 1677 IWL_ERR(priv, "0x%08X | l2p_addr_match\n", table.l2p_addr_match); 1678 IWL_ERR(priv, "0x%08X | lmpm_pmg_sel\n", table.lmpm_pmg_sel); 1679 IWL_ERR(priv, "0x%08X | timestamp\n", table.u_timestamp); 1680 IWL_ERR(priv, "0x%08X | flow_handler\n", table.flow_handler); 1681 } 1682 1683 #define EVENT_START_OFFSET (4 * sizeof(u32)) 1684 1685 /* 1686 * iwl_print_event_log - Dump error event log to syslog 1687 */ 1688 static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx, 1689 u32 num_events, u32 mode, 1690 int pos, char **buf, size_t bufsz) 1691 { 1692 u32 i; 1693 u32 base; /* SRAM byte address of event log header */ 1694 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */ 1695 u32 ptr; /* SRAM byte address of log data */ 1696 u32 ev, time, data; /* event log data */ 1697 unsigned long reg_flags; 1698 1699 struct iwl_trans *trans = priv->trans; 1700 1701 if (num_events == 0) 1702 return pos; 1703 1704 base = priv->device_pointers.log_event_table; 1705 if (priv->cur_ucode == IWL_UCODE_INIT) { 1706 if (!base) 1707 base = priv->fw->init_evtlog_ptr; 1708 } else { 1709 if (!base) 1710 base = priv->fw->inst_evtlog_ptr; 1711 } 1712 1713 if (mode == 0) 1714 event_size = 2 * sizeof(u32); 1715 else 1716 event_size = 3 * sizeof(u32); 1717 1718 ptr = base + EVENT_START_OFFSET + (start_idx * event_size); 1719 1720 /* Make sure device is powered up for SRAM reads */ 1721 if (!iwl_trans_grab_nic_access(trans, ®_flags)) 1722 return pos; 1723 1724 /* Set starting address; reads will auto-increment */ 1725 iwl_write32(trans, HBUS_TARG_MEM_RADDR, ptr); 1726 1727 /* "time" is actually "data" for mode 0 (no timestamp). 1728 * place event id # at far right for easier visual parsing. */ 1729 for (i = 0; i < num_events; i++) { 1730 ev = iwl_read32(trans, HBUS_TARG_MEM_RDAT); 1731 time = iwl_read32(trans, HBUS_TARG_MEM_RDAT); 1732 if (mode == 0) { 1733 /* data, ev */ 1734 if (bufsz) { 1735 pos += scnprintf(*buf + pos, bufsz - pos, 1736 "EVT_LOG:0x%08x:%04u\n", 1737 time, ev); 1738 } else { 1739 trace_iwlwifi_dev_ucode_event(trans->dev, 0, 1740 time, ev); 1741 IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n", 1742 time, ev); 1743 } 1744 } else { 1745 data = iwl_read32(trans, HBUS_TARG_MEM_RDAT); 1746 if (bufsz) { 1747 pos += scnprintf(*buf + pos, bufsz - pos, 1748 "EVT_LOGT:%010u:0x%08x:%04u\n", 1749 time, data, ev); 1750 } else { 1751 IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n", 1752 time, data, ev); 1753 trace_iwlwifi_dev_ucode_event(trans->dev, time, 1754 data, ev); 1755 } 1756 } 1757 } 1758 1759 /* Allow device to power down */ 1760 iwl_trans_release_nic_access(trans, ®_flags); 1761 return pos; 1762 } 1763 1764 /* 1765 * iwl_print_last_event_logs - Dump the newest # of event log to syslog 1766 */ 1767 static int iwl_print_last_event_logs(struct iwl_priv *priv, u32 capacity, 1768 u32 num_wraps, u32 next_entry, 1769 u32 size, u32 mode, 1770 int pos, char **buf, size_t bufsz) 1771 { 1772 /* 1773 * display the newest DEFAULT_LOG_ENTRIES entries 1774 * i.e the entries just before the next ont that uCode would fill. 1775 */ 1776 if (num_wraps) { 1777 if (next_entry < size) { 1778 pos = iwl_print_event_log(priv, 1779 capacity - (size - next_entry), 1780 size - next_entry, mode, 1781 pos, buf, bufsz); 1782 pos = iwl_print_event_log(priv, 0, 1783 next_entry, mode, 1784 pos, buf, bufsz); 1785 } else 1786 pos = iwl_print_event_log(priv, next_entry - size, 1787 size, mode, pos, buf, bufsz); 1788 } else { 1789 if (next_entry < size) { 1790 pos = iwl_print_event_log(priv, 0, next_entry, 1791 mode, pos, buf, bufsz); 1792 } else { 1793 pos = iwl_print_event_log(priv, next_entry - size, 1794 size, mode, pos, buf, bufsz); 1795 } 1796 } 1797 return pos; 1798 } 1799 1800 #define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20) 1801 1802 int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log, 1803 char **buf) 1804 { 1805 u32 base; /* SRAM byte address of event log header */ 1806 u32 capacity; /* event log capacity in # entries */ 1807 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ 1808 u32 num_wraps; /* # times uCode wrapped to top of log */ 1809 u32 next_entry; /* index of next entry to be written by uCode */ 1810 u32 size; /* # entries that we'll print */ 1811 u32 logsize; 1812 int pos = 0; 1813 size_t bufsz = 0; 1814 struct iwl_trans *trans = priv->trans; 1815 1816 base = priv->device_pointers.log_event_table; 1817 if (priv->cur_ucode == IWL_UCODE_INIT) { 1818 logsize = priv->fw->init_evtlog_size; 1819 if (!base) 1820 base = priv->fw->init_evtlog_ptr; 1821 } else { 1822 logsize = priv->fw->inst_evtlog_size; 1823 if (!base) 1824 base = priv->fw->inst_evtlog_ptr; 1825 } 1826 1827 if (!iwlagn_hw_valid_rtc_data_addr(base)) { 1828 IWL_ERR(priv, 1829 "Invalid event log pointer 0x%08X for %s uCode\n", 1830 base, 1831 (priv->cur_ucode == IWL_UCODE_INIT) 1832 ? "Init" : "RT"); 1833 return -EINVAL; 1834 } 1835 1836 /* event log header */ 1837 capacity = iwl_trans_read_mem32(trans, base); 1838 mode = iwl_trans_read_mem32(trans, base + (1 * sizeof(u32))); 1839 num_wraps = iwl_trans_read_mem32(trans, base + (2 * sizeof(u32))); 1840 next_entry = iwl_trans_read_mem32(trans, base + (3 * sizeof(u32))); 1841 1842 if (capacity > logsize) { 1843 IWL_ERR(priv, "Log capacity %d is bogus, limit to %d " 1844 "entries\n", capacity, logsize); 1845 capacity = logsize; 1846 } 1847 1848 if (next_entry > logsize) { 1849 IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n", 1850 next_entry, logsize); 1851 next_entry = logsize; 1852 } 1853 1854 size = num_wraps ? capacity : next_entry; 1855 1856 /* bail out if nothing in log */ 1857 if (size == 0) { 1858 IWL_ERR(trans, "Start IWL Event Log Dump: nothing in log\n"); 1859 return pos; 1860 } 1861 1862 if (!(iwl_have_debug_level(IWL_DL_FW)) && !full_log) 1863 size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES) 1864 ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size; 1865 IWL_ERR(priv, "Start IWL Event Log Dump: display last %u entries\n", 1866 size); 1867 1868 #ifdef CONFIG_IWLWIFI_DEBUG 1869 if (buf) { 1870 if (full_log) 1871 bufsz = capacity * 48; 1872 else 1873 bufsz = size * 48; 1874 *buf = kmalloc(bufsz, GFP_KERNEL); 1875 if (!*buf) 1876 return -ENOMEM; 1877 } 1878 if (iwl_have_debug_level(IWL_DL_FW) || full_log) { 1879 /* 1880 * if uCode has wrapped back to top of log, 1881 * start at the oldest entry, 1882 * i.e the next one that uCode would fill. 1883 */ 1884 if (num_wraps) 1885 pos = iwl_print_event_log(priv, next_entry, 1886 capacity - next_entry, mode, 1887 pos, buf, bufsz); 1888 /* (then/else) start at top of log */ 1889 pos = iwl_print_event_log(priv, 0, 1890 next_entry, mode, pos, buf, bufsz); 1891 } else 1892 pos = iwl_print_last_event_logs(priv, capacity, num_wraps, 1893 next_entry, size, mode, 1894 pos, buf, bufsz); 1895 #else 1896 pos = iwl_print_last_event_logs(priv, capacity, num_wraps, 1897 next_entry, size, mode, 1898 pos, buf, bufsz); 1899 #endif 1900 return pos; 1901 } 1902 1903 static void iwlagn_fw_error(struct iwl_priv *priv, bool ondemand) 1904 { 1905 unsigned int reload_msec; 1906 unsigned long reload_jiffies; 1907 1908 if (iwl_have_debug_level(IWL_DL_FW)) 1909 iwl_print_rx_config_cmd(priv, IWL_RXON_CTX_BSS); 1910 1911 /* uCode is no longer loaded. */ 1912 priv->ucode_loaded = false; 1913 1914 /* Set the FW error flag -- cleared on iwl_down */ 1915 set_bit(STATUS_FW_ERROR, &priv->status); 1916 1917 iwl_abort_notification_waits(&priv->notif_wait); 1918 1919 /* Keep the restart process from trying to send host 1920 * commands by clearing the ready bit */ 1921 clear_bit(STATUS_READY, &priv->status); 1922 1923 if (!ondemand) { 1924 /* 1925 * If firmware keep reloading, then it indicate something 1926 * serious wrong and firmware having problem to recover 1927 * from it. Instead of keep trying which will fill the syslog 1928 * and hang the system, let's just stop it 1929 */ 1930 reload_jiffies = jiffies; 1931 reload_msec = jiffies_to_msecs((long) reload_jiffies - 1932 (long) priv->reload_jiffies); 1933 priv->reload_jiffies = reload_jiffies; 1934 if (reload_msec <= IWL_MIN_RELOAD_DURATION) { 1935 priv->reload_count++; 1936 if (priv->reload_count >= IWL_MAX_CONTINUE_RELOAD_CNT) { 1937 IWL_ERR(priv, "BUG_ON, Stop restarting\n"); 1938 return; 1939 } 1940 } else 1941 priv->reload_count = 0; 1942 } 1943 1944 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { 1945 if (iwlwifi_mod_params.fw_restart) { 1946 IWL_DEBUG_FW(priv, 1947 "Restarting adapter due to uCode error.\n"); 1948 queue_work(priv->workqueue, &priv->restart); 1949 } else 1950 IWL_DEBUG_FW(priv, 1951 "Detected FW error, but not restarting\n"); 1952 } 1953 } 1954 1955 static void iwl_nic_error(struct iwl_op_mode *op_mode) 1956 { 1957 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); 1958 1959 IWL_ERR(priv, "Loaded firmware version: %s\n", 1960 priv->fw->fw_version); 1961 1962 iwl_dump_nic_error_log(priv); 1963 iwl_dump_nic_event_log(priv, false, NULL); 1964 1965 iwlagn_fw_error(priv, false); 1966 } 1967 1968 static void iwl_cmd_queue_full(struct iwl_op_mode *op_mode) 1969 { 1970 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); 1971 1972 if (!iwl_check_for_ct_kill(priv)) { 1973 IWL_ERR(priv, "Restarting adapter queue is full\n"); 1974 iwlagn_fw_error(priv, false); 1975 } 1976 } 1977 1978 #define EEPROM_RF_CONFIG_TYPE_MAX 0x3 1979 1980 static void iwl_nic_config(struct iwl_op_mode *op_mode) 1981 { 1982 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); 1983 1984 /* SKU Control */ 1985 iwl_trans_set_bits_mask(priv->trans, CSR_HW_IF_CONFIG_REG, 1986 CSR_HW_IF_CONFIG_REG_MSK_MAC_DASH | 1987 CSR_HW_IF_CONFIG_REG_MSK_MAC_STEP, 1988 (CSR_HW_REV_STEP(priv->trans->hw_rev) << 1989 CSR_HW_IF_CONFIG_REG_POS_MAC_STEP) | 1990 (CSR_HW_REV_DASH(priv->trans->hw_rev) << 1991 CSR_HW_IF_CONFIG_REG_POS_MAC_DASH)); 1992 1993 /* write radio config values to register */ 1994 if (priv->nvm_data->radio_cfg_type <= EEPROM_RF_CONFIG_TYPE_MAX) { 1995 u32 reg_val = 1996 priv->nvm_data->radio_cfg_type << 1997 CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE | 1998 priv->nvm_data->radio_cfg_step << 1999 CSR_HW_IF_CONFIG_REG_POS_PHY_STEP | 2000 priv->nvm_data->radio_cfg_dash << 2001 CSR_HW_IF_CONFIG_REG_POS_PHY_DASH; 2002 2003 iwl_trans_set_bits_mask(priv->trans, CSR_HW_IF_CONFIG_REG, 2004 CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE | 2005 CSR_HW_IF_CONFIG_REG_MSK_PHY_STEP | 2006 CSR_HW_IF_CONFIG_REG_MSK_PHY_DASH, 2007 reg_val); 2008 2009 IWL_INFO(priv, "Radio type=0x%x-0x%x-0x%x\n", 2010 priv->nvm_data->radio_cfg_type, 2011 priv->nvm_data->radio_cfg_step, 2012 priv->nvm_data->radio_cfg_dash); 2013 } else { 2014 WARN_ON(1); 2015 } 2016 2017 /* set CSR_HW_CONFIG_REG for uCode use */ 2018 iwl_set_bit(priv->trans, CSR_HW_IF_CONFIG_REG, 2019 CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI | 2020 CSR_HW_IF_CONFIG_REG_BIT_MAC_SI); 2021 2022 /* W/A : NIC is stuck in a reset state after Early PCIe power off 2023 * (PCIe power is lost before PERST# is asserted), 2024 * causing ME FW to lose ownership and not being able to obtain it back. 2025 */ 2026 iwl_set_bits_mask_prph(priv->trans, APMG_PS_CTRL_REG, 2027 APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS, 2028 ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS); 2029 2030 if (priv->lib->nic_config) 2031 priv->lib->nic_config(priv); 2032 } 2033 2034 static void iwl_wimax_active(struct iwl_op_mode *op_mode) 2035 { 2036 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); 2037 2038 clear_bit(STATUS_READY, &priv->status); 2039 IWL_ERR(priv, "RF is used by WiMAX\n"); 2040 } 2041 2042 static void iwl_stop_sw_queue(struct iwl_op_mode *op_mode, int queue) 2043 { 2044 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); 2045 int mq = priv->queue_to_mac80211[queue]; 2046 2047 if (WARN_ON_ONCE(mq == IWL_INVALID_MAC80211_QUEUE)) 2048 return; 2049 2050 if (atomic_inc_return(&priv->queue_stop_count[mq]) > 1) { 2051 IWL_DEBUG_TX_QUEUES(priv, 2052 "queue %d (mac80211 %d) already stopped\n", 2053 queue, mq); 2054 return; 2055 } 2056 2057 set_bit(mq, &priv->transport_queue_stop); 2058 ieee80211_stop_queue(priv->hw, mq); 2059 } 2060 2061 static void iwl_wake_sw_queue(struct iwl_op_mode *op_mode, int queue) 2062 { 2063 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); 2064 int mq = priv->queue_to_mac80211[queue]; 2065 2066 if (WARN_ON_ONCE(mq == IWL_INVALID_MAC80211_QUEUE)) 2067 return; 2068 2069 if (atomic_dec_return(&priv->queue_stop_count[mq]) > 0) { 2070 IWL_DEBUG_TX_QUEUES(priv, 2071 "queue %d (mac80211 %d) already awake\n", 2072 queue, mq); 2073 return; 2074 } 2075 2076 clear_bit(mq, &priv->transport_queue_stop); 2077 2078 if (!priv->passive_no_rx) 2079 ieee80211_wake_queue(priv->hw, mq); 2080 } 2081 2082 void iwlagn_lift_passive_no_rx(struct iwl_priv *priv) 2083 { 2084 int mq; 2085 2086 if (!priv->passive_no_rx) 2087 return; 2088 2089 for (mq = 0; mq < IWLAGN_FIRST_AMPDU_QUEUE; mq++) { 2090 if (!test_bit(mq, &priv->transport_queue_stop)) { 2091 IWL_DEBUG_TX_QUEUES(priv, "Wake queue %d\n", mq); 2092 ieee80211_wake_queue(priv->hw, mq); 2093 } else { 2094 IWL_DEBUG_TX_QUEUES(priv, "Don't wake queue %d\n", mq); 2095 } 2096 } 2097 2098 priv->passive_no_rx = false; 2099 } 2100 2101 static void iwl_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb) 2102 { 2103 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); 2104 struct ieee80211_tx_info *info; 2105 2106 info = IEEE80211_SKB_CB(skb); 2107 iwl_trans_free_tx_cmd(priv->trans, info->driver_data[1]); 2108 ieee80211_free_txskb(priv->hw, skb); 2109 } 2110 2111 static bool iwl_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state) 2112 { 2113 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); 2114 2115 if (state) 2116 set_bit(STATUS_RF_KILL_HW, &priv->status); 2117 else 2118 clear_bit(STATUS_RF_KILL_HW, &priv->status); 2119 2120 wiphy_rfkill_set_hw_state(priv->hw->wiphy, state); 2121 2122 return false; 2123 } 2124 2125 static const struct iwl_op_mode_ops iwl_dvm_ops = { 2126 .start = iwl_op_mode_dvm_start, 2127 .stop = iwl_op_mode_dvm_stop, 2128 .rx = iwl_rx_dispatch, 2129 .queue_full = iwl_stop_sw_queue, 2130 .queue_not_full = iwl_wake_sw_queue, 2131 .hw_rf_kill = iwl_set_hw_rfkill_state, 2132 .free_skb = iwl_free_skb, 2133 .nic_error = iwl_nic_error, 2134 .cmd_queue_full = iwl_cmd_queue_full, 2135 .nic_config = iwl_nic_config, 2136 .wimax_active = iwl_wimax_active, 2137 }; 2138 2139 /***************************************************************************** 2140 * 2141 * driver and module entry point 2142 * 2143 *****************************************************************************/ 2144 static int __init iwl_init(void) 2145 { 2146 2147 int ret; 2148 2149 ret = iwlagn_rate_control_register(); 2150 if (ret) { 2151 pr_err("Unable to register rate control algorithm: %d\n", ret); 2152 return ret; 2153 } 2154 2155 ret = iwl_opmode_register("iwldvm", &iwl_dvm_ops); 2156 if (ret) { 2157 pr_err("Unable to register op_mode: %d\n", ret); 2158 iwlagn_rate_control_unregister(); 2159 } 2160 2161 return ret; 2162 } 2163 module_init(iwl_init); 2164 2165 static void __exit iwl_exit(void) 2166 { 2167 iwl_opmode_deregister("iwldvm"); 2168 iwlagn_rate_control_unregister(); 2169 } 2170 module_exit(iwl_exit); 2171