Wey-Yi Guy | e04ed0a | 2010-03-16 17:47:58 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * GPL LICENSE SUMMARY |
| 4 | * |
Wey-Yi Guy | 901069c | 2011-04-05 09:42:00 -0700 | [diff] [blame] | 5 | * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. |
Wey-Yi Guy | e04ed0a | 2010-03-16 17:47:58 -0700 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of version 2 of the GNU General Public License as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 19 | * USA |
| 20 | * |
| 21 | * The full GNU General Public License is included in this distribution |
| 22 | * in the file called LICENSE.GPL. |
| 23 | * |
| 24 | * Contact Information: |
| 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | *****************************************************************************/ |
Wey-Yi Guy | 8d80108 | 2010-03-17 13:34:36 -0700 | [diff] [blame] | 29 | #include <linux/etherdevice.h> |
Wey-Yi Guy | e04ed0a | 2010-03-16 17:47:58 -0700 | [diff] [blame] | 30 | #include <linux/kernel.h> |
| 31 | #include <linux/module.h> |
| 32 | #include <linux/init.h> |
| 33 | #include <linux/sched.h> |
| 34 | |
| 35 | #include "iwl-dev.h" |
| 36 | #include "iwl-core.h" |
| 37 | #include "iwl-io.h" |
Wey-Yi Guy | e04ed0a | 2010-03-16 17:47:58 -0700 | [diff] [blame] | 38 | #include "iwl-agn-hw.h" |
| 39 | #include "iwl-agn.h" |
Emmanuel Grumbach | bdfbf09 | 2011-07-08 08:46:16 -0700 | [diff] [blame] | 40 | #include "iwl-trans.h" |
Emmanuel Grumbach | 48f20d3 | 2011-08-25 23:10:36 -0700 | [diff] [blame] | 41 | #include "iwl-shared.h" |
Wey-Yi Guy | e04ed0a | 2010-03-16 17:47:58 -0700 | [diff] [blame] | 42 | |
Wey-Yi Guy | e04ed0a | 2010-03-16 17:47:58 -0700 | [diff] [blame] | 43 | int iwlagn_hw_valid_rtc_data_addr(u32 addr) |
| 44 | { |
| 45 | return (addr >= IWLAGN_RTC_DATA_LOWER_BOUND) && |
| 46 | (addr < IWLAGN_RTC_DATA_UPPER_BOUND); |
| 47 | } |
| 48 | |
| 49 | int iwlagn_send_tx_power(struct iwl_priv *priv) |
| 50 | { |
Wey-Yi Guy | ab63c68 | 2010-09-20 09:12:31 -0700 | [diff] [blame] | 51 | struct iwlagn_tx_power_dbm_cmd tx_power_cmd; |
Wey-Yi Guy | e04ed0a | 2010-03-16 17:47:58 -0700 | [diff] [blame] | 52 | u8 tx_ant_cfg_cmd; |
| 53 | |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 54 | if (WARN_ONCE(test_bit(STATUS_SCAN_HW, &priv->shrd->status), |
Stanislaw Gruszka | 4beeba7 | 2010-10-25 10:34:50 +0200 | [diff] [blame] | 55 | "TX Power requested while scanning!\n")) |
| 56 | return -EAGAIN; |
| 57 | |
Wey-Yi Guy | e04ed0a | 2010-03-16 17:47:58 -0700 | [diff] [blame] | 58 | /* half dBm need to multiply */ |
| 59 | tx_power_cmd.global_lmt = (s8)(2 * priv->tx_power_user_lmt); |
| 60 | |
| 61 | if (priv->tx_power_lmt_in_half_dbm && |
| 62 | priv->tx_power_lmt_in_half_dbm < tx_power_cmd.global_lmt) { |
| 63 | /* |
| 64 | * For the newer devices which using enhanced/extend tx power |
| 65 | * table in EEPROM, the format is in half dBm. driver need to |
| 66 | * convert to dBm format before report to mac80211. |
| 67 | * By doing so, there is a possibility of 1/2 dBm resolution |
| 68 | * lost. driver will perform "round-up" operation before |
| 69 | * reporting, but it will cause 1/2 dBm tx power over the |
| 70 | * regulatory limit. Perform the checking here, if the |
| 71 | * "tx_power_user_lmt" is higher than EEPROM value (in |
| 72 | * half-dBm format), lower the tx power based on EEPROM |
| 73 | */ |
| 74 | tx_power_cmd.global_lmt = priv->tx_power_lmt_in_half_dbm; |
| 75 | } |
Wey-Yi Guy | ab63c68 | 2010-09-20 09:12:31 -0700 | [diff] [blame] | 76 | tx_power_cmd.flags = IWLAGN_TX_POWER_NO_CLOSED; |
| 77 | tx_power_cmd.srv_chan_lmt = IWLAGN_TX_POWER_AUTO; |
Wey-Yi Guy | e04ed0a | 2010-03-16 17:47:58 -0700 | [diff] [blame] | 78 | |
| 79 | if (IWL_UCODE_API(priv->ucode_ver) == 1) |
| 80 | tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD_V1; |
| 81 | else |
| 82 | tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD; |
| 83 | |
Emmanuel Grumbach | e6bb4c9 | 2011-08-25 23:10:48 -0700 | [diff] [blame] | 84 | return iwl_trans_send_cmd_pdu(trans(priv), tx_ant_cfg_cmd, CMD_SYNC, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 85 | sizeof(tx_power_cmd), &tx_power_cmd); |
Wey-Yi Guy | e04ed0a | 2010-03-16 17:47:58 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | void iwlagn_temperature(struct iwl_priv *priv) |
| 89 | { |
Fry, Donald H | f8f79a5 | 2011-02-25 09:44:48 -0800 | [diff] [blame] | 90 | /* store temperature from correct statistics (in Celsius) */ |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 91 | priv->temperature = le32_to_cpu(priv->statistics.common.temperature); |
Wey-Yi Guy | e04ed0a | 2010-03-16 17:47:58 -0700 | [diff] [blame] | 92 | iwl_tt_handler(priv); |
| 93 | } |
| 94 | |
| 95 | u16 iwlagn_eeprom_calib_version(struct iwl_priv *priv) |
| 96 | { |
Wey-Yi Guy | 7d8f2d5 | 2011-09-15 11:46:51 -0700 | [diff] [blame] | 97 | struct iwl_eeprom_calib_hdr *hdr; |
Wey-Yi Guy | e04ed0a | 2010-03-16 17:47:58 -0700 | [diff] [blame] | 98 | |
| 99 | hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv, |
Wey-Yi Guy | 7944f8e | 2010-04-06 21:10:33 -0700 | [diff] [blame] | 100 | EEPROM_CALIB_ALL); |
Wey-Yi Guy | e04ed0a | 2010-03-16 17:47:58 -0700 | [diff] [blame] | 101 | return hdr->version; |
| 102 | |
| 103 | } |
| 104 | |
| 105 | /* |
| 106 | * EEPROM |
| 107 | */ |
| 108 | static u32 eeprom_indirect_address(const struct iwl_priv *priv, u32 address) |
| 109 | { |
| 110 | u16 offset = 0; |
| 111 | |
| 112 | if ((address & INDIRECT_ADDRESS) == 0) |
| 113 | return address; |
| 114 | |
| 115 | switch (address & INDIRECT_TYPE_MSK) { |
| 116 | case INDIRECT_HOST: |
Wey-Yi Guy | 7944f8e | 2010-04-06 21:10:33 -0700 | [diff] [blame] | 117 | offset = iwl_eeprom_query16(priv, EEPROM_LINK_HOST); |
Wey-Yi Guy | e04ed0a | 2010-03-16 17:47:58 -0700 | [diff] [blame] | 118 | break; |
| 119 | case INDIRECT_GENERAL: |
Wey-Yi Guy | 7944f8e | 2010-04-06 21:10:33 -0700 | [diff] [blame] | 120 | offset = iwl_eeprom_query16(priv, EEPROM_LINK_GENERAL); |
Wey-Yi Guy | e04ed0a | 2010-03-16 17:47:58 -0700 | [diff] [blame] | 121 | break; |
| 122 | case INDIRECT_REGULATORY: |
Wey-Yi Guy | 7944f8e | 2010-04-06 21:10:33 -0700 | [diff] [blame] | 123 | offset = iwl_eeprom_query16(priv, EEPROM_LINK_REGULATORY); |
Wey-Yi Guy | e04ed0a | 2010-03-16 17:47:58 -0700 | [diff] [blame] | 124 | break; |
Johannes Berg | 8d6748c | 2010-12-09 09:30:14 -0800 | [diff] [blame] | 125 | case INDIRECT_TXP_LIMIT: |
| 126 | offset = iwl_eeprom_query16(priv, EEPROM_LINK_TXP_LIMIT); |
| 127 | break; |
| 128 | case INDIRECT_TXP_LIMIT_SIZE: |
| 129 | offset = iwl_eeprom_query16(priv, EEPROM_LINK_TXP_LIMIT_SIZE); |
| 130 | break; |
Wey-Yi Guy | e04ed0a | 2010-03-16 17:47:58 -0700 | [diff] [blame] | 131 | case INDIRECT_CALIBRATION: |
Wey-Yi Guy | 7944f8e | 2010-04-06 21:10:33 -0700 | [diff] [blame] | 132 | offset = iwl_eeprom_query16(priv, EEPROM_LINK_CALIBRATION); |
Wey-Yi Guy | e04ed0a | 2010-03-16 17:47:58 -0700 | [diff] [blame] | 133 | break; |
| 134 | case INDIRECT_PROCESS_ADJST: |
Wey-Yi Guy | 7944f8e | 2010-04-06 21:10:33 -0700 | [diff] [blame] | 135 | offset = iwl_eeprom_query16(priv, EEPROM_LINK_PROCESS_ADJST); |
Wey-Yi Guy | e04ed0a | 2010-03-16 17:47:58 -0700 | [diff] [blame] | 136 | break; |
| 137 | case INDIRECT_OTHERS: |
Wey-Yi Guy | 7944f8e | 2010-04-06 21:10:33 -0700 | [diff] [blame] | 138 | offset = iwl_eeprom_query16(priv, EEPROM_LINK_OTHERS); |
Wey-Yi Guy | e04ed0a | 2010-03-16 17:47:58 -0700 | [diff] [blame] | 139 | break; |
| 140 | default: |
| 141 | IWL_ERR(priv, "illegal indirect type: 0x%X\n", |
| 142 | address & INDIRECT_TYPE_MSK); |
| 143 | break; |
| 144 | } |
| 145 | |
| 146 | /* translate the offset from words to byte */ |
| 147 | return (address & ADDRESS_MSK) + (offset << 1); |
| 148 | } |
| 149 | |
Fry, Donald H | 70e3e8a | 2011-07-08 08:46:19 -0700 | [diff] [blame] | 150 | const u8 *iwl_eeprom_query_addr(const struct iwl_priv *priv, size_t offset) |
Wey-Yi Guy | e04ed0a | 2010-03-16 17:47:58 -0700 | [diff] [blame] | 151 | { |
| 152 | u32 address = eeprom_indirect_address(priv, offset); |
Wey-Yi Guy | 7cb1b08 | 2010-10-06 08:10:00 -0700 | [diff] [blame] | 153 | BUG_ON(address >= priv->cfg->base_params->eeprom_size); |
Wey-Yi Guy | e04ed0a | 2010-03-16 17:47:58 -0700 | [diff] [blame] | 154 | return &priv->eeprom[address]; |
| 155 | } |
Wey-Yi Guy | 348ee7cd | 2010-03-16 12:37:27 -0700 | [diff] [blame] | 156 | |
| 157 | struct iwl_mod_params iwlagn_mod_params = { |
| 158 | .amsdu_size_8K = 1, |
| 159 | .restart_fw = 1, |
Stanislaw Gruszka | b7977ff | 2011-02-28 14:33:15 +0100 | [diff] [blame] | 160 | .plcp_check = true, |
Wey-Yi Guy | b60eec9 | 2011-06-03 13:52:38 -0700 | [diff] [blame] | 161 | .bt_coex_active = true, |
Wey-Yi Guy | 3f1e5f4 | 2011-06-03 13:52:40 -0700 | [diff] [blame] | 162 | .no_sleep_autoadjust = true, |
Wey-Yi Guy | f753816 | 2011-06-11 10:00:06 -0700 | [diff] [blame] | 163 | .power_level = IWL_POWER_INDEX_1, |
Wey-Yi Guy | fee84f0d | 2011-08-25 23:10:57 -0700 | [diff] [blame] | 164 | .bt_ch_announce = true, |
Emmanuel Grumbach | 48f20d3 | 2011-08-25 23:10:36 -0700 | [diff] [blame] | 165 | .wanted_ucode_alternative = 1, |
Wey-Yi Guy | dd5b6d0 | 2011-08-25 23:10:55 -0700 | [diff] [blame] | 166 | .auto_agg = true, |
Wey-Yi Guy | 348ee7cd | 2010-03-16 12:37:27 -0700 | [diff] [blame] | 167 | /* the rest are 0 by default */ |
| 168 | }; |
Wey-Yi Guy | 74bcdb3 | 2010-03-17 13:34:34 -0700 | [diff] [blame] | 169 | |
Wey-Yi Guy | 8d80108 | 2010-03-17 13:34:36 -0700 | [diff] [blame] | 170 | int iwlagn_hwrate_to_mac80211_idx(u32 rate_n_flags, enum ieee80211_band band) |
| 171 | { |
| 172 | int idx = 0; |
| 173 | int band_offset = 0; |
| 174 | |
| 175 | /* HT rate format: mac80211 wants an MCS number, which is just LSB */ |
| 176 | if (rate_n_flags & RATE_MCS_HT_MSK) { |
| 177 | idx = (rate_n_flags & 0xff); |
| 178 | return idx; |
| 179 | /* Legacy rate format, search for match in table */ |
| 180 | } else { |
| 181 | if (band == IEEE80211_BAND_5GHZ) |
| 182 | band_offset = IWL_FIRST_OFDM_RATE; |
| 183 | for (idx = band_offset; idx < IWL_RATE_COUNT_LEGACY; idx++) |
| 184 | if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF)) |
| 185 | return idx - band_offset; |
| 186 | } |
| 187 | |
| 188 | return -1; |
| 189 | } |
| 190 | |
Johannes Berg | 1fa61b2 | 2010-04-28 08:44:52 -0700 | [diff] [blame] | 191 | int iwlagn_manage_ibss_station(struct iwl_priv *priv, |
| 192 | struct ieee80211_vif *vif, bool add) |
| 193 | { |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 194 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; |
| 195 | |
Johannes Berg | 1fa61b2 | 2010-04-28 08:44:52 -0700 | [diff] [blame] | 196 | if (add) |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 197 | return iwlagn_add_bssid_station(priv, vif_priv->ctx, |
| 198 | vif->bss_conf.bssid, |
| 199 | &vif_priv->ibss_bssid_sta_id); |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 200 | return iwl_remove_station(priv, vif_priv->ibss_bssid_sta_id, |
| 201 | vif->bss_conf.bssid); |
Johannes Berg | 1fa61b2 | 2010-04-28 08:44:52 -0700 | [diff] [blame] | 202 | } |
Johannes Berg | 1ff504e | 2010-05-03 01:22:42 -0700 | [diff] [blame] | 203 | |
Wey-Yi Guy | 716c74b | 2010-06-24 13:22:36 -0700 | [diff] [blame] | 204 | /** |
| 205 | * iwlagn_txfifo_flush: send REPLY_TXFIFO_FLUSH command to uCode |
| 206 | * |
| 207 | * pre-requirements: |
| 208 | * 1. acquire mutex before calling |
| 209 | * 2. make sure rf is on and not in exit state |
| 210 | */ |
| 211 | int iwlagn_txfifo_flush(struct iwl_priv *priv, u16 flush_control) |
| 212 | { |
| 213 | struct iwl_txfifo_flush_cmd flush_cmd; |
| 214 | struct iwl_host_cmd cmd = { |
| 215 | .id = REPLY_TXFIFO_FLUSH, |
Johannes Berg | 3fa5073 | 2011-05-04 07:50:38 -0700 | [diff] [blame] | 216 | .len = { sizeof(struct iwl_txfifo_flush_cmd), }, |
Wey-Yi Guy | 716c74b | 2010-06-24 13:22:36 -0700 | [diff] [blame] | 217 | .flags = CMD_SYNC, |
Johannes Berg | 3fa5073 | 2011-05-04 07:50:38 -0700 | [diff] [blame] | 218 | .data = { &flush_cmd, }, |
Wey-Yi Guy | 716c74b | 2010-06-24 13:22:36 -0700 | [diff] [blame] | 219 | }; |
| 220 | |
| 221 | might_sleep(); |
| 222 | |
| 223 | memset(&flush_cmd, 0, sizeof(flush_cmd)); |
Wey-Yi Guy | ecdbe86 | 2011-06-08 09:57:26 -0700 | [diff] [blame] | 224 | if (flush_control & BIT(IWL_RXON_CTX_BSS)) |
| 225 | flush_cmd.fifo_control = IWL_SCD_VO_MSK | IWL_SCD_VI_MSK | |
Wey-Yi Guy | f88e0ec | 2011-06-08 09:57:25 -0700 | [diff] [blame] | 226 | IWL_SCD_BE_MSK | IWL_SCD_BK_MSK | |
| 227 | IWL_SCD_MGMT_MSK; |
Wey-Yi Guy | ecdbe86 | 2011-06-08 09:57:26 -0700 | [diff] [blame] | 228 | if ((flush_control & BIT(IWL_RXON_CTX_PAN)) && |
Emmanuel Grumbach | 7a10e3e4 | 2011-09-06 09:31:21 -0700 | [diff] [blame] | 229 | (priv->shrd->valid_contexts != BIT(IWL_RXON_CTX_BSS))) |
Wey-Yi Guy | f88e0ec | 2011-06-08 09:57:25 -0700 | [diff] [blame] | 230 | flush_cmd.fifo_control |= IWL_PAN_SCD_VO_MSK | |
| 231 | IWL_PAN_SCD_VI_MSK | IWL_PAN_SCD_BE_MSK | |
| 232 | IWL_PAN_SCD_BK_MSK | IWL_PAN_SCD_MGMT_MSK | |
| 233 | IWL_PAN_SCD_MULTICAST_MSK; |
| 234 | |
Wey-Yi Guy | 8895075 | 2011-06-06 12:05:46 -0700 | [diff] [blame] | 235 | if (priv->cfg->sku & EEPROM_SKU_CAP_11N_ENABLE) |
Wey-Yi Guy | 716c74b | 2010-06-24 13:22:36 -0700 | [diff] [blame] | 236 | flush_cmd.fifo_control |= IWL_AGG_TX_QUEUE_MSK; |
| 237 | |
| 238 | IWL_DEBUG_INFO(priv, "fifo queue control: 0X%x\n", |
| 239 | flush_cmd.fifo_control); |
| 240 | flush_cmd.flush_control = cpu_to_le16(flush_control); |
| 241 | |
Emmanuel Grumbach | e6bb4c9 | 2011-08-25 23:10:48 -0700 | [diff] [blame] | 242 | return iwl_trans_send_cmd(trans(priv), &cmd); |
Wey-Yi Guy | 716c74b | 2010-06-24 13:22:36 -0700 | [diff] [blame] | 243 | } |
Wey-Yi Guy | 6555063 | 2010-06-24 13:18:35 -0700 | [diff] [blame] | 244 | |
| 245 | void iwlagn_dev_txfifo_flush(struct iwl_priv *priv, u16 flush_control) |
| 246 | { |
Emmanuel Grumbach | 6ac2f83 | 2011-08-25 23:10:44 -0700 | [diff] [blame] | 247 | mutex_lock(&priv->shrd->mutex); |
Wey-Yi Guy | 6555063 | 2010-06-24 13:18:35 -0700 | [diff] [blame] | 248 | ieee80211_stop_queues(priv->hw); |
Wey-Yi Guy | c68744f | 2011-06-18 08:03:18 -0700 | [diff] [blame] | 249 | if (iwlagn_txfifo_flush(priv, IWL_DROP_ALL)) { |
Wey-Yi Guy | 6555063 | 2010-06-24 13:18:35 -0700 | [diff] [blame] | 250 | IWL_ERR(priv, "flush request fail\n"); |
| 251 | goto done; |
| 252 | } |
| 253 | IWL_DEBUG_INFO(priv, "wait transmit/flush all frames\n"); |
Emmanuel Grumbach | 5f178cd | 2011-08-25 23:11:29 -0700 | [diff] [blame] | 254 | iwl_trans_wait_tx_queue_empty(trans(priv)); |
Wey-Yi Guy | 6555063 | 2010-06-24 13:18:35 -0700 | [diff] [blame] | 255 | done: |
| 256 | ieee80211_wake_queues(priv->hw); |
Emmanuel Grumbach | 6ac2f83 | 2011-08-25 23:10:44 -0700 | [diff] [blame] | 257 | mutex_unlock(&priv->shrd->mutex); |
Wey-Yi Guy | 6555063 | 2010-06-24 13:18:35 -0700 | [diff] [blame] | 258 | } |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 259 | |
| 260 | /* |
| 261 | * BT coex |
| 262 | */ |
| 263 | /* |
| 264 | * Macros to access the lookup table. |
| 265 | * |
| 266 | * The lookup table has 7 inputs: bt3_prio, bt3_txrx, bt_rf_act, wifi_req, |
| 267 | * wifi_prio, wifi_txrx and wifi_sh_ant_req. |
| 268 | * |
| 269 | * It has three outputs: WLAN_ACTIVE, WLAN_KILL and ANT_SWITCH |
| 270 | * |
| 271 | * The format is that "registers" 8 through 11 contain the WLAN_ACTIVE bits |
| 272 | * one after another in 32-bit registers, and "registers" 0 through 7 contain |
| 273 | * the WLAN_KILL and ANT_SWITCH bits interleaved (in that order). |
| 274 | * |
| 275 | * These macros encode that format. |
| 276 | */ |
| 277 | #define LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, wifi_req, wifi_prio, \ |
| 278 | wifi_txrx, wifi_sh_ant_req) \ |
| 279 | (bt3_prio | (bt3_txrx << 1) | (bt_rf_act << 2) | (wifi_req << 3) | \ |
| 280 | (wifi_prio << 4) | (wifi_txrx << 5) | (wifi_sh_ant_req << 6)) |
| 281 | |
| 282 | #define LUT_PTA_WLAN_ACTIVE_OP(lut, op, val) \ |
| 283 | lut[8 + ((val) >> 5)] op (cpu_to_le32(BIT((val) & 0x1f))) |
| 284 | #define LUT_TEST_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \ |
| 285 | wifi_prio, wifi_txrx, wifi_sh_ant_req) \ |
| 286 | (!!(LUT_PTA_WLAN_ACTIVE_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, \ |
| 287 | bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \ |
| 288 | wifi_sh_ant_req)))) |
| 289 | #define LUT_SET_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \ |
| 290 | wifi_prio, wifi_txrx, wifi_sh_ant_req) \ |
| 291 | LUT_PTA_WLAN_ACTIVE_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, \ |
| 292 | bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \ |
| 293 | wifi_sh_ant_req)) |
| 294 | #define LUT_CLEAR_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, \ |
| 295 | wifi_req, wifi_prio, wifi_txrx, \ |
| 296 | wifi_sh_ant_req) \ |
| 297 | LUT_PTA_WLAN_ACTIVE_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, \ |
| 298 | bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \ |
| 299 | wifi_sh_ant_req)) |
| 300 | |
| 301 | #define LUT_WLAN_KILL_OP(lut, op, val) \ |
| 302 | lut[(val) >> 4] op (cpu_to_le32(BIT(((val) << 1) & 0x1e))) |
| 303 | #define LUT_TEST_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \ |
| 304 | wifi_prio, wifi_txrx, wifi_sh_ant_req) \ |
| 305 | (!!(LUT_WLAN_KILL_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \ |
| 306 | wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req)))) |
| 307 | #define LUT_SET_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \ |
| 308 | wifi_prio, wifi_txrx, wifi_sh_ant_req) \ |
| 309 | LUT_WLAN_KILL_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \ |
| 310 | wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req)) |
| 311 | #define LUT_CLEAR_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \ |
| 312 | wifi_prio, wifi_txrx, wifi_sh_ant_req) \ |
| 313 | LUT_WLAN_KILL_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \ |
| 314 | wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req)) |
| 315 | |
| 316 | #define LUT_ANT_SWITCH_OP(lut, op, val) \ |
| 317 | lut[(val) >> 4] op (cpu_to_le32(BIT((((val) << 1) & 0x1e) + 1))) |
| 318 | #define LUT_TEST_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \ |
| 319 | wifi_prio, wifi_txrx, wifi_sh_ant_req) \ |
| 320 | (!!(LUT_ANT_SWITCH_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \ |
| 321 | wifi_req, wifi_prio, wifi_txrx, \ |
| 322 | wifi_sh_ant_req)))) |
| 323 | #define LUT_SET_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \ |
| 324 | wifi_prio, wifi_txrx, wifi_sh_ant_req) \ |
| 325 | LUT_ANT_SWITCH_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \ |
| 326 | wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req)) |
| 327 | #define LUT_CLEAR_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \ |
| 328 | wifi_prio, wifi_txrx, wifi_sh_ant_req) \ |
| 329 | LUT_ANT_SWITCH_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \ |
| 330 | wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req)) |
| 331 | |
| 332 | static const __le32 iwlagn_def_3w_lookup[12] = { |
| 333 | cpu_to_le32(0xaaaaaaaa), |
| 334 | cpu_to_le32(0xaaaaaaaa), |
| 335 | cpu_to_le32(0xaeaaaaaa), |
| 336 | cpu_to_le32(0xaaaaaaaa), |
| 337 | cpu_to_le32(0xcc00ff28), |
| 338 | cpu_to_le32(0x0000aaaa), |
| 339 | cpu_to_le32(0xcc00aaaa), |
| 340 | cpu_to_le32(0x0000aaaa), |
| 341 | cpu_to_le32(0xc0004000), |
| 342 | cpu_to_le32(0x00004000), |
| 343 | cpu_to_le32(0xf0005000), |
Wey-Yi Guy | 9a67d76 | 2010-11-18 10:40:03 -0800 | [diff] [blame] | 344 | cpu_to_le32(0xf0005000), |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 345 | }; |
| 346 | |
| 347 | static const __le32 iwlagn_concurrent_lookup[12] = { |
| 348 | cpu_to_le32(0xaaaaaaaa), |
| 349 | cpu_to_le32(0xaaaaaaaa), |
| 350 | cpu_to_le32(0xaaaaaaaa), |
| 351 | cpu_to_le32(0xaaaaaaaa), |
| 352 | cpu_to_le32(0xaaaaaaaa), |
| 353 | cpu_to_le32(0xaaaaaaaa), |
| 354 | cpu_to_le32(0xaaaaaaaa), |
| 355 | cpu_to_le32(0xaaaaaaaa), |
| 356 | cpu_to_le32(0x00000000), |
| 357 | cpu_to_le32(0x00000000), |
| 358 | cpu_to_le32(0x00000000), |
| 359 | cpu_to_le32(0x00000000), |
| 360 | }; |
| 361 | |
| 362 | void iwlagn_send_advance_bt_config(struct iwl_priv *priv) |
| 363 | { |
Wey-Yi Guy | 6013270 | 2011-02-18 17:23:54 -0800 | [diff] [blame] | 364 | struct iwl_basic_bt_cmd basic = { |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 365 | .max_kill = IWLAGN_BT_MAX_KILL_DEFAULT, |
| 366 | .bt3_timer_t7_value = IWLAGN_BT3_T7_DEFAULT, |
| 367 | .bt3_prio_sample_time = IWLAGN_BT3_PRIO_SAMPLE_DEFAULT, |
| 368 | .bt3_timer_t2_value = IWLAGN_BT3_T2_DEFAULT, |
| 369 | }; |
Wey-Yi Guy | 6013270 | 2011-02-18 17:23:54 -0800 | [diff] [blame] | 370 | struct iwl6000_bt_cmd bt_cmd_6000; |
| 371 | struct iwl2000_bt_cmd bt_cmd_2000; |
| 372 | int ret; |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 373 | |
| 374 | BUILD_BUG_ON(sizeof(iwlagn_def_3w_lookup) != |
Wey-Yi Guy | 6013270 | 2011-02-18 17:23:54 -0800 | [diff] [blame] | 375 | sizeof(basic.bt3_lookup_table)); |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 376 | |
Wey-Yi Guy | 6013270 | 2011-02-18 17:23:54 -0800 | [diff] [blame] | 377 | if (priv->cfg->bt_params) { |
| 378 | if (priv->cfg->bt_params->bt_session_2) { |
| 379 | bt_cmd_2000.prio_boost = cpu_to_le32( |
| 380 | priv->cfg->bt_params->bt_prio_boost); |
| 381 | bt_cmd_2000.tx_prio_boost = 0; |
| 382 | bt_cmd_2000.rx_prio_boost = 0; |
| 383 | } else { |
| 384 | bt_cmd_6000.prio_boost = |
| 385 | priv->cfg->bt_params->bt_prio_boost; |
| 386 | bt_cmd_6000.tx_prio_boost = 0; |
| 387 | bt_cmd_6000.rx_prio_boost = 0; |
| 388 | } |
| 389 | } else { |
| 390 | IWL_ERR(priv, "failed to construct BT Coex Config\n"); |
| 391 | return; |
| 392 | } |
Wey-Yi Guy | 506aa15 | 2010-11-24 17:25:03 -0800 | [diff] [blame] | 393 | |
Wey-Yi Guy | 6013270 | 2011-02-18 17:23:54 -0800 | [diff] [blame] | 394 | basic.kill_ack_mask = priv->kill_ack_mask; |
| 395 | basic.kill_cts_mask = priv->kill_cts_mask; |
| 396 | basic.valid = priv->bt_valid; |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 397 | |
| 398 | /* |
| 399 | * Configure BT coex mode to "no coexistence" when the |
| 400 | * user disabled BT coexistence, we have no interface |
| 401 | * (might be in monitor mode), or the interface is in |
| 402 | * IBSS mode (no proper uCode support for coex then). |
| 403 | */ |
Wey-Yi Guy | b60eec9 | 2011-06-03 13:52:38 -0700 | [diff] [blame] | 404 | if (!iwlagn_mod_params.bt_coex_active || |
| 405 | priv->iw_mode == NL80211_IFTYPE_ADHOC) { |
Wey-Yi Guy | 6013270 | 2011-02-18 17:23:54 -0800 | [diff] [blame] | 406 | basic.flags = IWLAGN_BT_FLAG_COEX_MODE_DISABLED; |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 407 | } else { |
Wey-Yi Guy | 6013270 | 2011-02-18 17:23:54 -0800 | [diff] [blame] | 408 | basic.flags = IWLAGN_BT_FLAG_COEX_MODE_3W << |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 409 | IWLAGN_BT_FLAG_COEX_MODE_SHIFT; |
Meenakshi Venkataraman | 207ecc5 | 2011-07-08 08:46:23 -0700 | [diff] [blame] | 410 | |
| 411 | if (!priv->bt_enable_pspoll) |
Wey-Yi Guy | 6013270 | 2011-02-18 17:23:54 -0800 | [diff] [blame] | 412 | basic.flags |= IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE; |
Meenakshi Venkataraman | 207ecc5 | 2011-07-08 08:46:23 -0700 | [diff] [blame] | 413 | else |
| 414 | basic.flags &= ~IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE; |
Wey-Yi Guy | e366176 | 2010-11-23 10:58:54 -0800 | [diff] [blame] | 415 | |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 416 | if (priv->bt_ch_announce) |
Wey-Yi Guy | 6013270 | 2011-02-18 17:23:54 -0800 | [diff] [blame] | 417 | basic.flags |= IWLAGN_BT_FLAG_CHANNEL_INHIBITION; |
Wey-Yi Guy | fa7f141 | 2011-06-06 12:49:25 -0700 | [diff] [blame] | 418 | IWL_DEBUG_COEX(priv, "BT coex flag: 0X%x\n", basic.flags); |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 419 | } |
Wey-Yi Guy | 6013270 | 2011-02-18 17:23:54 -0800 | [diff] [blame] | 420 | priv->bt_enable_flag = basic.flags; |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 421 | if (priv->bt_full_concurrent) |
Wey-Yi Guy | 6013270 | 2011-02-18 17:23:54 -0800 | [diff] [blame] | 422 | memcpy(basic.bt3_lookup_table, iwlagn_concurrent_lookup, |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 423 | sizeof(iwlagn_concurrent_lookup)); |
| 424 | else |
Wey-Yi Guy | 6013270 | 2011-02-18 17:23:54 -0800 | [diff] [blame] | 425 | memcpy(basic.bt3_lookup_table, iwlagn_def_3w_lookup, |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 426 | sizeof(iwlagn_def_3w_lookup)); |
| 427 | |
Wey-Yi Guy | fa7f141 | 2011-06-06 12:49:25 -0700 | [diff] [blame] | 428 | IWL_DEBUG_COEX(priv, "BT coex %s in %s mode\n", |
Wey-Yi Guy | 6013270 | 2011-02-18 17:23:54 -0800 | [diff] [blame] | 429 | basic.flags ? "active" : "disabled", |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 430 | priv->bt_full_concurrent ? |
| 431 | "full concurrency" : "3-wire"); |
| 432 | |
Wey-Yi Guy | 6013270 | 2011-02-18 17:23:54 -0800 | [diff] [blame] | 433 | if (priv->cfg->bt_params->bt_session_2) { |
| 434 | memcpy(&bt_cmd_2000.basic, &basic, |
| 435 | sizeof(basic)); |
Emmanuel Grumbach | e6bb4c9 | 2011-08-25 23:10:48 -0700 | [diff] [blame] | 436 | ret = iwl_trans_send_cmd_pdu(trans(priv), REPLY_BT_CONFIG, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 437 | CMD_SYNC, sizeof(bt_cmd_2000), &bt_cmd_2000); |
Wey-Yi Guy | 6013270 | 2011-02-18 17:23:54 -0800 | [diff] [blame] | 438 | } else { |
| 439 | memcpy(&bt_cmd_6000.basic, &basic, |
| 440 | sizeof(basic)); |
Emmanuel Grumbach | e6bb4c9 | 2011-08-25 23:10:48 -0700 | [diff] [blame] | 441 | ret = iwl_trans_send_cmd_pdu(trans(priv), REPLY_BT_CONFIG, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 442 | CMD_SYNC, sizeof(bt_cmd_6000), &bt_cmd_6000); |
Wey-Yi Guy | 6013270 | 2011-02-18 17:23:54 -0800 | [diff] [blame] | 443 | } |
| 444 | if (ret) |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 445 | IWL_ERR(priv, "failed to send BT Coex Config\n"); |
| 446 | |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Meenakshi Venkataraman | 207ecc5 | 2011-07-08 08:46:23 -0700 | [diff] [blame] | 449 | void iwlagn_bt_adjust_rssi_monitor(struct iwl_priv *priv, bool rssi_ena) |
| 450 | { |
| 451 | struct iwl_rxon_context *ctx, *found_ctx = NULL; |
| 452 | bool found_ap = false; |
| 453 | |
Emmanuel Grumbach | 6ac2f83 | 2011-08-25 23:10:44 -0700 | [diff] [blame] | 454 | lockdep_assert_held(&priv->shrd->mutex); |
Meenakshi Venkataraman | 207ecc5 | 2011-07-08 08:46:23 -0700 | [diff] [blame] | 455 | |
| 456 | /* Check whether AP or GO mode is active. */ |
| 457 | if (rssi_ena) { |
| 458 | for_each_context(priv, ctx) { |
| 459 | if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_AP && |
| 460 | iwl_is_associated_ctx(ctx)) { |
| 461 | found_ap = true; |
| 462 | break; |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | /* |
| 468 | * If disable was received or If GO/AP mode, disable RSSI |
| 469 | * measurements. |
| 470 | */ |
| 471 | if (!rssi_ena || found_ap) { |
| 472 | if (priv->cur_rssi_ctx) { |
| 473 | ctx = priv->cur_rssi_ctx; |
| 474 | ieee80211_disable_rssi_reports(ctx->vif); |
| 475 | priv->cur_rssi_ctx = NULL; |
| 476 | } |
| 477 | return; |
| 478 | } |
| 479 | |
| 480 | /* |
| 481 | * If rssi measurements need to be enabled, consider all cases now. |
| 482 | * Figure out how many contexts are active. |
| 483 | */ |
| 484 | for_each_context(priv, ctx) { |
| 485 | if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION && |
| 486 | iwl_is_associated_ctx(ctx)) { |
| 487 | found_ctx = ctx; |
| 488 | break; |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | /* |
| 493 | * rssi monitor already enabled for the correct interface...nothing |
| 494 | * to do. |
| 495 | */ |
| 496 | if (found_ctx == priv->cur_rssi_ctx) |
| 497 | return; |
| 498 | |
| 499 | /* |
| 500 | * Figure out if rssi monitor is currently enabled, and needs |
| 501 | * to be changed. If rssi monitor is already enabled, disable |
| 502 | * it first else just enable rssi measurements on the |
| 503 | * interface found above. |
| 504 | */ |
| 505 | if (priv->cur_rssi_ctx) { |
| 506 | ctx = priv->cur_rssi_ctx; |
| 507 | if (ctx->vif) |
| 508 | ieee80211_disable_rssi_reports(ctx->vif); |
| 509 | } |
| 510 | |
| 511 | priv->cur_rssi_ctx = found_ctx; |
| 512 | |
| 513 | if (!found_ctx) |
| 514 | return; |
| 515 | |
| 516 | ieee80211_enable_rssi_reports(found_ctx->vif, |
| 517 | IWLAGN_BT_PSP_MIN_RSSI_THRESHOLD, |
| 518 | IWLAGN_BT_PSP_MAX_RSSI_THRESHOLD); |
| 519 | } |
| 520 | |
| 521 | static bool iwlagn_bt_traffic_is_sco(struct iwl_bt_uart_msg *uart_msg) |
| 522 | { |
| 523 | return BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3 >> |
| 524 | BT_UART_MSG_FRAME3SCOESCO_POS; |
| 525 | } |
| 526 | |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 527 | static void iwlagn_bt_traffic_change_work(struct work_struct *work) |
| 528 | { |
| 529 | struct iwl_priv *priv = |
| 530 | container_of(work, struct iwl_priv, bt_traffic_change_work); |
Johannes Berg | 8bd413e | 2010-08-23 10:46:40 +0200 | [diff] [blame] | 531 | struct iwl_rxon_context *ctx; |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 532 | int smps_request = -1; |
| 533 | |
Wey-Yi Guy | c4197c6 | 2011-02-06 08:56:35 -0800 | [diff] [blame] | 534 | if (priv->bt_enable_flag == IWLAGN_BT_FLAG_COEX_MODE_DISABLED) { |
| 535 | /* bt coex disabled */ |
| 536 | return; |
| 537 | } |
| 538 | |
Stanislaw Gruszka | 5eda74a | 2010-10-22 17:04:28 +0200 | [diff] [blame] | 539 | /* |
| 540 | * Note: bt_traffic_load can be overridden by scan complete and |
| 541 | * coex profile notifications. Ignore that since only bad consequence |
| 542 | * can be not matching debug print with actual state. |
| 543 | */ |
Wey-Yi Guy | fa7f141 | 2011-06-06 12:49:25 -0700 | [diff] [blame] | 544 | IWL_DEBUG_COEX(priv, "BT traffic load changes: %d\n", |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 545 | priv->bt_traffic_load); |
| 546 | |
| 547 | switch (priv->bt_traffic_load) { |
| 548 | case IWL_BT_COEX_TRAFFIC_LOAD_NONE: |
Wey-Yi Guy | f5682c0 | 2010-10-23 09:15:44 -0700 | [diff] [blame] | 549 | if (priv->bt_status) |
| 550 | smps_request = IEEE80211_SMPS_DYNAMIC; |
| 551 | else |
| 552 | smps_request = IEEE80211_SMPS_AUTOMATIC; |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 553 | break; |
| 554 | case IWL_BT_COEX_TRAFFIC_LOAD_LOW: |
| 555 | smps_request = IEEE80211_SMPS_DYNAMIC; |
| 556 | break; |
| 557 | case IWL_BT_COEX_TRAFFIC_LOAD_HIGH: |
| 558 | case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS: |
| 559 | smps_request = IEEE80211_SMPS_STATIC; |
| 560 | break; |
| 561 | default: |
| 562 | IWL_ERR(priv, "Invalid BT traffic load: %d\n", |
| 563 | priv->bt_traffic_load); |
| 564 | break; |
| 565 | } |
| 566 | |
Emmanuel Grumbach | 6ac2f83 | 2011-08-25 23:10:44 -0700 | [diff] [blame] | 567 | mutex_lock(&priv->shrd->mutex); |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 568 | |
Stanislaw Gruszka | 5eda74a | 2010-10-22 17:04:28 +0200 | [diff] [blame] | 569 | /* |
| 570 | * We can not send command to firmware while scanning. When the scan |
| 571 | * complete we will schedule this work again. We do check with mutex |
| 572 | * locked to prevent new scan request to arrive. We do not check |
| 573 | * STATUS_SCANNING to avoid race when queue_work two times from |
| 574 | * different notifications, but quit and not perform any work at all. |
| 575 | */ |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 576 | if (test_bit(STATUS_SCAN_HW, &priv->shrd->status)) |
Stanislaw Gruszka | 5eda74a | 2010-10-22 17:04:28 +0200 | [diff] [blame] | 577 | goto out; |
| 578 | |
Fry, Donald H | 6b6db91 | 2011-07-08 08:46:17 -0700 | [diff] [blame] | 579 | iwl_update_chain_flags(priv); |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 580 | |
Johannes Berg | 8bd413e | 2010-08-23 10:46:40 +0200 | [diff] [blame] | 581 | if (smps_request != -1) { |
Wey-Yi Guy | 88e9ba7 | 2011-06-03 07:54:12 -0700 | [diff] [blame] | 582 | priv->current_ht_config.smps = smps_request; |
Johannes Berg | 8bd413e | 2010-08-23 10:46:40 +0200 | [diff] [blame] | 583 | for_each_context(priv, ctx) { |
| 584 | if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION) |
| 585 | ieee80211_request_smps(ctx->vif, smps_request); |
| 586 | } |
| 587 | } |
Meenakshi Venkataraman | 207ecc5 | 2011-07-08 08:46:23 -0700 | [diff] [blame] | 588 | |
| 589 | /* |
| 590 | * Dynamic PS poll related functionality. Adjust RSSI measurements if |
| 591 | * necessary. |
| 592 | */ |
| 593 | iwlagn_bt_coex_rssi_monitor(priv); |
Stanislaw Gruszka | 5eda74a | 2010-10-22 17:04:28 +0200 | [diff] [blame] | 594 | out: |
Emmanuel Grumbach | 6ac2f83 | 2011-08-25 23:10:44 -0700 | [diff] [blame] | 595 | mutex_unlock(&priv->shrd->mutex); |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Meenakshi Venkataraman | 207ecc5 | 2011-07-08 08:46:23 -0700 | [diff] [blame] | 598 | /* |
| 599 | * If BT sco traffic, and RSSI monitor is enabled, move measurements to the |
| 600 | * correct interface or disable it if this is the last interface to be |
| 601 | * removed. |
| 602 | */ |
| 603 | void iwlagn_bt_coex_rssi_monitor(struct iwl_priv *priv) |
| 604 | { |
| 605 | if (priv->bt_is_sco && |
| 606 | priv->bt_traffic_load == IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS) |
| 607 | iwlagn_bt_adjust_rssi_monitor(priv, true); |
| 608 | else |
| 609 | iwlagn_bt_adjust_rssi_monitor(priv, false); |
| 610 | } |
| 611 | |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 612 | static void iwlagn_print_uartmsg(struct iwl_priv *priv, |
| 613 | struct iwl_bt_uart_msg *uart_msg) |
| 614 | { |
Wey-Yi Guy | fa7f141 | 2011-06-06 12:49:25 -0700 | [diff] [blame] | 615 | IWL_DEBUG_COEX(priv, "Message Type = 0x%X, SSN = 0x%X, " |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 616 | "Update Req = 0x%X", |
| 617 | (BT_UART_MSG_FRAME1MSGTYPE_MSK & uart_msg->frame1) >> |
| 618 | BT_UART_MSG_FRAME1MSGTYPE_POS, |
| 619 | (BT_UART_MSG_FRAME1SSN_MSK & uart_msg->frame1) >> |
| 620 | BT_UART_MSG_FRAME1SSN_POS, |
| 621 | (BT_UART_MSG_FRAME1UPDATEREQ_MSK & uart_msg->frame1) >> |
| 622 | BT_UART_MSG_FRAME1UPDATEREQ_POS); |
| 623 | |
Wey-Yi Guy | fa7f141 | 2011-06-06 12:49:25 -0700 | [diff] [blame] | 624 | IWL_DEBUG_COEX(priv, "Open connections = 0x%X, Traffic load = 0x%X, " |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 625 | "Chl_SeqN = 0x%X, In band = 0x%X", |
| 626 | (BT_UART_MSG_FRAME2OPENCONNECTIONS_MSK & uart_msg->frame2) >> |
| 627 | BT_UART_MSG_FRAME2OPENCONNECTIONS_POS, |
| 628 | (BT_UART_MSG_FRAME2TRAFFICLOAD_MSK & uart_msg->frame2) >> |
| 629 | BT_UART_MSG_FRAME2TRAFFICLOAD_POS, |
| 630 | (BT_UART_MSG_FRAME2CHLSEQN_MSK & uart_msg->frame2) >> |
| 631 | BT_UART_MSG_FRAME2CHLSEQN_POS, |
| 632 | (BT_UART_MSG_FRAME2INBAND_MSK & uart_msg->frame2) >> |
| 633 | BT_UART_MSG_FRAME2INBAND_POS); |
| 634 | |
Wey-Yi Guy | fa7f141 | 2011-06-06 12:49:25 -0700 | [diff] [blame] | 635 | IWL_DEBUG_COEX(priv, "SCO/eSCO = 0x%X, Sniff = 0x%X, A2DP = 0x%X, " |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 636 | "ACL = 0x%X, Master = 0x%X, OBEX = 0x%X", |
| 637 | (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3) >> |
| 638 | BT_UART_MSG_FRAME3SCOESCO_POS, |
| 639 | (BT_UART_MSG_FRAME3SNIFF_MSK & uart_msg->frame3) >> |
| 640 | BT_UART_MSG_FRAME3SNIFF_POS, |
| 641 | (BT_UART_MSG_FRAME3A2DP_MSK & uart_msg->frame3) >> |
| 642 | BT_UART_MSG_FRAME3A2DP_POS, |
| 643 | (BT_UART_MSG_FRAME3ACL_MSK & uart_msg->frame3) >> |
| 644 | BT_UART_MSG_FRAME3ACL_POS, |
| 645 | (BT_UART_MSG_FRAME3MASTER_MSK & uart_msg->frame3) >> |
| 646 | BT_UART_MSG_FRAME3MASTER_POS, |
| 647 | (BT_UART_MSG_FRAME3OBEX_MSK & uart_msg->frame3) >> |
| 648 | BT_UART_MSG_FRAME3OBEX_POS); |
| 649 | |
Wey-Yi Guy | fa7f141 | 2011-06-06 12:49:25 -0700 | [diff] [blame] | 650 | IWL_DEBUG_COEX(priv, "Idle duration = 0x%X", |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 651 | (BT_UART_MSG_FRAME4IDLEDURATION_MSK & uart_msg->frame4) >> |
| 652 | BT_UART_MSG_FRAME4IDLEDURATION_POS); |
| 653 | |
Wey-Yi Guy | fa7f141 | 2011-06-06 12:49:25 -0700 | [diff] [blame] | 654 | IWL_DEBUG_COEX(priv, "Tx Activity = 0x%X, Rx Activity = 0x%X, " |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 655 | "eSCO Retransmissions = 0x%X", |
| 656 | (BT_UART_MSG_FRAME5TXACTIVITY_MSK & uart_msg->frame5) >> |
| 657 | BT_UART_MSG_FRAME5TXACTIVITY_POS, |
| 658 | (BT_UART_MSG_FRAME5RXACTIVITY_MSK & uart_msg->frame5) >> |
| 659 | BT_UART_MSG_FRAME5RXACTIVITY_POS, |
| 660 | (BT_UART_MSG_FRAME5ESCORETRANSMIT_MSK & uart_msg->frame5) >> |
| 661 | BT_UART_MSG_FRAME5ESCORETRANSMIT_POS); |
| 662 | |
Wey-Yi Guy | fa7f141 | 2011-06-06 12:49:25 -0700 | [diff] [blame] | 663 | IWL_DEBUG_COEX(priv, "Sniff Interval = 0x%X, Discoverable = 0x%X", |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 664 | (BT_UART_MSG_FRAME6SNIFFINTERVAL_MSK & uart_msg->frame6) >> |
| 665 | BT_UART_MSG_FRAME6SNIFFINTERVAL_POS, |
| 666 | (BT_UART_MSG_FRAME6DISCOVERABLE_MSK & uart_msg->frame6) >> |
| 667 | BT_UART_MSG_FRAME6DISCOVERABLE_POS); |
| 668 | |
Wey-Yi Guy | fa7f141 | 2011-06-06 12:49:25 -0700 | [diff] [blame] | 669 | IWL_DEBUG_COEX(priv, "Sniff Activity = 0x%X, Page = " |
Wey-Yi Guy | 399f66f | 2011-02-22 08:24:22 -0800 | [diff] [blame] | 670 | "0x%X, Inquiry = 0x%X, Connectable = 0x%X", |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 671 | (BT_UART_MSG_FRAME7SNIFFACTIVITY_MSK & uart_msg->frame7) >> |
| 672 | BT_UART_MSG_FRAME7SNIFFACTIVITY_POS, |
Wey-Yi Guy | 399f66f | 2011-02-22 08:24:22 -0800 | [diff] [blame] | 673 | (BT_UART_MSG_FRAME7PAGE_MSK & uart_msg->frame7) >> |
| 674 | BT_UART_MSG_FRAME7PAGE_POS, |
| 675 | (BT_UART_MSG_FRAME7INQUIRY_MSK & uart_msg->frame7) >> |
| 676 | BT_UART_MSG_FRAME7INQUIRY_POS, |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 677 | (BT_UART_MSG_FRAME7CONNECTABLE_MSK & uart_msg->frame7) >> |
| 678 | BT_UART_MSG_FRAME7CONNECTABLE_POS); |
| 679 | } |
| 680 | |
Wey-Yi Guy | 506aa15 | 2010-11-24 17:25:03 -0800 | [diff] [blame] | 681 | static void iwlagn_set_kill_msk(struct iwl_priv *priv, |
| 682 | struct iwl_bt_uart_msg *uart_msg) |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 683 | { |
Wey-Yi Guy | 506aa15 | 2010-11-24 17:25:03 -0800 | [diff] [blame] | 684 | u8 kill_msk; |
Joe Perches | 20407ed | 2010-11-20 18:38:57 -0800 | [diff] [blame] | 685 | static const __le32 bt_kill_ack_msg[2] = { |
Wey-Yi Guy | 506aa15 | 2010-11-24 17:25:03 -0800 | [diff] [blame] | 686 | IWLAGN_BT_KILL_ACK_MASK_DEFAULT, |
| 687 | IWLAGN_BT_KILL_ACK_CTS_MASK_SCO }; |
| 688 | static const __le32 bt_kill_cts_msg[2] = { |
| 689 | IWLAGN_BT_KILL_CTS_MASK_DEFAULT, |
| 690 | IWLAGN_BT_KILL_ACK_CTS_MASK_SCO }; |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 691 | |
Wey-Yi Guy | 506aa15 | 2010-11-24 17:25:03 -0800 | [diff] [blame] | 692 | kill_msk = (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3) |
| 693 | ? 1 : 0; |
| 694 | if (priv->kill_ack_mask != bt_kill_ack_msg[kill_msk] || |
| 695 | priv->kill_cts_mask != bt_kill_cts_msg[kill_msk]) { |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 696 | priv->bt_valid |= IWLAGN_BT_VALID_KILL_ACK_MASK; |
Wey-Yi Guy | 506aa15 | 2010-11-24 17:25:03 -0800 | [diff] [blame] | 697 | priv->kill_ack_mask = bt_kill_ack_msg[kill_msk]; |
| 698 | priv->bt_valid |= IWLAGN_BT_VALID_KILL_CTS_MASK; |
| 699 | priv->kill_cts_mask = bt_kill_cts_msg[kill_msk]; |
| 700 | |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 701 | /* schedule to send runtime bt_config */ |
Emmanuel Grumbach | 74e28e4 | 2011-08-25 23:10:41 -0700 | [diff] [blame] | 702 | queue_work(priv->shrd->workqueue, &priv->bt_runtime_config); |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 703 | } |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 704 | } |
| 705 | |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 706 | int iwlagn_bt_coex_profile_notif(struct iwl_priv *priv, |
| 707 | struct iwl_rx_mem_buffer *rxb, |
| 708 | struct iwl_device_cmd *cmd) |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 709 | { |
| 710 | unsigned long flags; |
| 711 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 712 | struct iwl_bt_coex_profile_notif *coex = &pkt->u.bt_coex_profile_notif; |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 713 | struct iwl_bt_uart_msg *uart_msg = &coex->last_bt_uart_msg; |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 714 | |
Wey-Yi Guy | c4197c6 | 2011-02-06 08:56:35 -0800 | [diff] [blame] | 715 | if (priv->bt_enable_flag == IWLAGN_BT_FLAG_COEX_MODE_DISABLED) { |
| 716 | /* bt coex disabled */ |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 717 | return 0; |
Wey-Yi Guy | c4197c6 | 2011-02-06 08:56:35 -0800 | [diff] [blame] | 718 | } |
| 719 | |
Wey-Yi Guy | fa7f141 | 2011-06-06 12:49:25 -0700 | [diff] [blame] | 720 | IWL_DEBUG_COEX(priv, "BT Coex notification:\n"); |
| 721 | IWL_DEBUG_COEX(priv, " status: %d\n", coex->bt_status); |
| 722 | IWL_DEBUG_COEX(priv, " traffic load: %d\n", coex->bt_traffic_load); |
| 723 | IWL_DEBUG_COEX(priv, " CI compliance: %d\n", |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 724 | coex->bt_ci_compliance); |
| 725 | iwlagn_print_uartmsg(priv, uart_msg); |
| 726 | |
Wey-Yi Guy | 66e863a5 | 2010-11-08 14:54:37 -0800 | [diff] [blame] | 727 | priv->last_bt_traffic_load = priv->bt_traffic_load; |
Meenakshi Venkataraman | 207ecc5 | 2011-07-08 08:46:23 -0700 | [diff] [blame] | 728 | priv->bt_is_sco = iwlagn_bt_traffic_is_sco(uart_msg); |
| 729 | |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 730 | if (priv->iw_mode != NL80211_IFTYPE_ADHOC) { |
| 731 | if (priv->bt_status != coex->bt_status || |
Wey-Yi Guy | 66e863a5 | 2010-11-08 14:54:37 -0800 | [diff] [blame] | 732 | priv->last_bt_traffic_load != coex->bt_traffic_load) { |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 733 | if (coex->bt_status) { |
| 734 | /* BT on */ |
| 735 | if (!priv->bt_ch_announce) |
| 736 | priv->bt_traffic_load = |
| 737 | IWL_BT_COEX_TRAFFIC_LOAD_HIGH; |
| 738 | else |
| 739 | priv->bt_traffic_load = |
| 740 | coex->bt_traffic_load; |
| 741 | } else { |
| 742 | /* BT off */ |
| 743 | priv->bt_traffic_load = |
| 744 | IWL_BT_COEX_TRAFFIC_LOAD_NONE; |
| 745 | } |
| 746 | priv->bt_status = coex->bt_status; |
Emmanuel Grumbach | 74e28e4 | 2011-08-25 23:10:41 -0700 | [diff] [blame] | 747 | queue_work(priv->shrd->workqueue, |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 748 | &priv->bt_traffic_change_work); |
| 749 | } |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 750 | } |
| 751 | |
Wey-Yi Guy | 506aa15 | 2010-11-24 17:25:03 -0800 | [diff] [blame] | 752 | iwlagn_set_kill_msk(priv, uart_msg); |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 753 | |
| 754 | /* FIXME: based on notification, adjust the prio_boost */ |
| 755 | |
Emmanuel Grumbach | 10b15e6 | 2011-08-25 23:10:43 -0700 | [diff] [blame] | 756 | spin_lock_irqsave(&priv->shrd->lock, flags); |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 757 | priv->bt_ci_compliance = coex->bt_ci_compliance; |
Emmanuel Grumbach | 10b15e6 | 2011-08-25 23:10:43 -0700 | [diff] [blame] | 758 | spin_unlock_irqrestore(&priv->shrd->lock, flags); |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 759 | return 0; |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | void iwlagn_bt_rx_handler_setup(struct iwl_priv *priv) |
| 763 | { |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 764 | priv->rx_handlers[REPLY_BT_COEX_PROFILE_NOTIF] = |
| 765 | iwlagn_bt_coex_profile_notif; |
| 766 | } |
| 767 | |
| 768 | void iwlagn_bt_setup_deferred_work(struct iwl_priv *priv) |
| 769 | { |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 770 | INIT_WORK(&priv->bt_traffic_change_work, |
| 771 | iwlagn_bt_traffic_change_work); |
| 772 | } |
| 773 | |
| 774 | void iwlagn_bt_cancel_deferred_work(struct iwl_priv *priv) |
| 775 | { |
| 776 | cancel_work_sync(&priv->bt_traffic_change_work); |
| 777 | } |
Johannes Berg | 5de3306 | 2010-09-22 18:01:58 +0200 | [diff] [blame] | 778 | |
| 779 | static bool is_single_rx_stream(struct iwl_priv *priv) |
| 780 | { |
| 781 | return priv->current_ht_config.smps == IEEE80211_SMPS_STATIC || |
| 782 | priv->current_ht_config.single_chain_sufficient; |
| 783 | } |
| 784 | |
| 785 | #define IWL_NUM_RX_CHAINS_MULTIPLE 3 |
| 786 | #define IWL_NUM_RX_CHAINS_SINGLE 2 |
| 787 | #define IWL_NUM_IDLE_CHAINS_DUAL 2 |
| 788 | #define IWL_NUM_IDLE_CHAINS_SINGLE 1 |
| 789 | |
| 790 | /* |
| 791 | * Determine how many receiver/antenna chains to use. |
| 792 | * |
| 793 | * More provides better reception via diversity. Fewer saves power |
| 794 | * at the expense of throughput, but only when not in powersave to |
| 795 | * start with. |
| 796 | * |
| 797 | * MIMO (dual stream) requires at least 2, but works better with 3. |
| 798 | * This does not determine *which* chains to use, just how many. |
| 799 | */ |
| 800 | static int iwl_get_active_rx_chain_count(struct iwl_priv *priv) |
| 801 | { |
| 802 | if (priv->cfg->bt_params && |
| 803 | priv->cfg->bt_params->advanced_bt_coexist && |
| 804 | (priv->bt_full_concurrent || |
| 805 | priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)) { |
| 806 | /* |
| 807 | * only use chain 'A' in bt high traffic load or |
| 808 | * full concurrency mode |
| 809 | */ |
| 810 | return IWL_NUM_RX_CHAINS_SINGLE; |
| 811 | } |
| 812 | /* # of Rx chains to use when expecting MIMO. */ |
| 813 | if (is_single_rx_stream(priv)) |
| 814 | return IWL_NUM_RX_CHAINS_SINGLE; |
| 815 | else |
| 816 | return IWL_NUM_RX_CHAINS_MULTIPLE; |
| 817 | } |
| 818 | |
| 819 | /* |
| 820 | * When we are in power saving mode, unless device support spatial |
| 821 | * multiplexing power save, use the active count for rx chain count. |
| 822 | */ |
| 823 | static int iwl_get_idle_rx_chain_count(struct iwl_priv *priv, int active_cnt) |
| 824 | { |
| 825 | /* # Rx chains when idling, depending on SMPS mode */ |
| 826 | switch (priv->current_ht_config.smps) { |
| 827 | case IEEE80211_SMPS_STATIC: |
| 828 | case IEEE80211_SMPS_DYNAMIC: |
| 829 | return IWL_NUM_IDLE_CHAINS_SINGLE; |
Wey-Yi Guy | b2ccccd | 2011-11-10 06:55:04 -0800 | [diff] [blame] | 830 | case IEEE80211_SMPS_AUTOMATIC: |
Johannes Berg | 5de3306 | 2010-09-22 18:01:58 +0200 | [diff] [blame] | 831 | case IEEE80211_SMPS_OFF: |
| 832 | return active_cnt; |
| 833 | default: |
| 834 | WARN(1, "invalid SMPS mode %d", |
| 835 | priv->current_ht_config.smps); |
| 836 | return active_cnt; |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | /* up to 4 chains */ |
| 841 | static u8 iwl_count_chain_bitmap(u32 chain_bitmap) |
| 842 | { |
| 843 | u8 res; |
| 844 | res = (chain_bitmap & BIT(0)) >> 0; |
| 845 | res += (chain_bitmap & BIT(1)) >> 1; |
| 846 | res += (chain_bitmap & BIT(2)) >> 2; |
| 847 | res += (chain_bitmap & BIT(3)) >> 3; |
| 848 | return res; |
| 849 | } |
| 850 | |
| 851 | /** |
| 852 | * iwlagn_set_rxon_chain - Set up Rx chain usage in "staging" RXON image |
| 853 | * |
| 854 | * Selects how many and which Rx receivers/antennas/chains to use. |
| 855 | * This should not be used for scan command ... it puts data in wrong place. |
| 856 | */ |
| 857 | void iwlagn_set_rxon_chain(struct iwl_priv *priv, struct iwl_rxon_context *ctx) |
| 858 | { |
| 859 | bool is_single = is_single_rx_stream(priv); |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 860 | bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->shrd->status); |
Johannes Berg | 5de3306 | 2010-09-22 18:01:58 +0200 | [diff] [blame] | 861 | u8 idle_rx_cnt, active_rx_cnt, valid_rx_cnt; |
| 862 | u32 active_chains; |
| 863 | u16 rx_chain; |
| 864 | |
| 865 | /* Tell uCode which antennas are actually connected. |
| 866 | * Before first association, we assume all antennas are connected. |
| 867 | * Just after first association, iwl_chain_noise_calibration() |
| 868 | * checks which antennas actually *are* connected. */ |
| 869 | if (priv->chain_noise_data.active_chains) |
| 870 | active_chains = priv->chain_noise_data.active_chains; |
| 871 | else |
Emmanuel Grumbach | d618912 | 2011-08-25 23:10:39 -0700 | [diff] [blame] | 872 | active_chains = hw_params(priv).valid_rx_ant; |
Johannes Berg | 5de3306 | 2010-09-22 18:01:58 +0200 | [diff] [blame] | 873 | |
| 874 | if (priv->cfg->bt_params && |
| 875 | priv->cfg->bt_params->advanced_bt_coexist && |
| 876 | (priv->bt_full_concurrent || |
| 877 | priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)) { |
| 878 | /* |
| 879 | * only use chain 'A' in bt high traffic load or |
| 880 | * full concurrency mode |
| 881 | */ |
| 882 | active_chains = first_antenna(active_chains); |
| 883 | } |
| 884 | |
| 885 | rx_chain = active_chains << RXON_RX_CHAIN_VALID_POS; |
| 886 | |
| 887 | /* How many receivers should we use? */ |
| 888 | active_rx_cnt = iwl_get_active_rx_chain_count(priv); |
| 889 | idle_rx_cnt = iwl_get_idle_rx_chain_count(priv, active_rx_cnt); |
| 890 | |
| 891 | |
| 892 | /* correct rx chain count according hw settings |
| 893 | * and chain noise calibration |
| 894 | */ |
| 895 | valid_rx_cnt = iwl_count_chain_bitmap(active_chains); |
| 896 | if (valid_rx_cnt < active_rx_cnt) |
| 897 | active_rx_cnt = valid_rx_cnt; |
| 898 | |
| 899 | if (valid_rx_cnt < idle_rx_cnt) |
| 900 | idle_rx_cnt = valid_rx_cnt; |
| 901 | |
| 902 | rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS; |
| 903 | rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS; |
| 904 | |
| 905 | ctx->staging.rx_chain = cpu_to_le16(rx_chain); |
| 906 | |
| 907 | if (!is_single && (active_rx_cnt >= IWL_NUM_RX_CHAINS_SINGLE) && is_cam) |
| 908 | ctx->staging.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK; |
| 909 | else |
| 910 | ctx->staging.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK; |
| 911 | |
| 912 | IWL_DEBUG_ASSOC(priv, "rx_chain=0x%X active=%d idle=%d\n", |
| 913 | ctx->staging.rx_chain, |
| 914 | active_rx_cnt, idle_rx_cnt); |
| 915 | |
| 916 | WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 || |
| 917 | active_rx_cnt < idle_rx_cnt); |
| 918 | } |
Johannes Berg | facd982 | 2010-09-22 18:02:05 +0200 | [diff] [blame] | 919 | |
| 920 | u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant, u8 valid) |
| 921 | { |
| 922 | int i; |
| 923 | u8 ind = ant; |
| 924 | |
| 925 | if (priv->band == IEEE80211_BAND_2GHZ && |
| 926 | priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH) |
| 927 | return 0; |
| 928 | |
| 929 | for (i = 0; i < RATE_ANT_NUM - 1; i++) { |
| 930 | ind = (ind + 1) < RATE_ANT_NUM ? ind + 1 : 0; |
| 931 | if (valid & BIT(ind)) |
| 932 | return ind; |
| 933 | } |
| 934 | return ant; |
| 935 | } |
Johannes Berg | fed7329 | 2010-09-22 18:02:06 +0200 | [diff] [blame] | 936 | |
Johannes Berg | 7194207c | 2011-01-04 16:22:00 -0800 | [diff] [blame] | 937 | /* notification wait support */ |
| 938 | void iwlagn_init_notification_wait(struct iwl_priv *priv, |
| 939 | struct iwl_notification_wait *wait_entry, |
Johannes Berg | 09f18af | 2011-04-13 03:14:47 -0700 | [diff] [blame] | 940 | u8 cmd, |
Johannes Berg | 7194207c | 2011-01-04 16:22:00 -0800 | [diff] [blame] | 941 | void (*fn)(struct iwl_priv *priv, |
Johannes Berg | 09f18af | 2011-04-13 03:14:47 -0700 | [diff] [blame] | 942 | struct iwl_rx_packet *pkt, |
| 943 | void *data), |
| 944 | void *fn_data) |
Johannes Berg | 7194207c | 2011-01-04 16:22:00 -0800 | [diff] [blame] | 945 | { |
| 946 | wait_entry->fn = fn; |
Johannes Berg | 09f18af | 2011-04-13 03:14:47 -0700 | [diff] [blame] | 947 | wait_entry->fn_data = fn_data; |
Johannes Berg | 7194207c | 2011-01-04 16:22:00 -0800 | [diff] [blame] | 948 | wait_entry->cmd = cmd; |
| 949 | wait_entry->triggered = false; |
Johannes Berg | e74fe23 | 2011-04-13 03:14:49 -0700 | [diff] [blame] | 950 | wait_entry->aborted = false; |
Johannes Berg | 7194207c | 2011-01-04 16:22:00 -0800 | [diff] [blame] | 951 | |
Wey-Yi Guy | 898ed67 | 2011-07-13 08:38:57 -0700 | [diff] [blame] | 952 | spin_lock_bh(&priv->notif_wait_lock); |
| 953 | list_add(&wait_entry->list, &priv->notif_waits); |
| 954 | spin_unlock_bh(&priv->notif_wait_lock); |
Johannes Berg | 7194207c | 2011-01-04 16:22:00 -0800 | [diff] [blame] | 955 | } |
| 956 | |
Johannes Berg | a8674a1 | 2011-04-13 03:14:48 -0700 | [diff] [blame] | 957 | int iwlagn_wait_notification(struct iwl_priv *priv, |
| 958 | struct iwl_notification_wait *wait_entry, |
| 959 | unsigned long timeout) |
Johannes Berg | 7194207c | 2011-01-04 16:22:00 -0800 | [diff] [blame] | 960 | { |
| 961 | int ret; |
| 962 | |
Wey-Yi Guy | 898ed67 | 2011-07-13 08:38:57 -0700 | [diff] [blame] | 963 | ret = wait_event_timeout(priv->notif_waitq, |
Johannes Berg | e74fe23 | 2011-04-13 03:14:49 -0700 | [diff] [blame] | 964 | wait_entry->triggered || wait_entry->aborted, |
Johannes Berg | 7194207c | 2011-01-04 16:22:00 -0800 | [diff] [blame] | 965 | timeout); |
| 966 | |
Wey-Yi Guy | 898ed67 | 2011-07-13 08:38:57 -0700 | [diff] [blame] | 967 | spin_lock_bh(&priv->notif_wait_lock); |
Johannes Berg | 7194207c | 2011-01-04 16:22:00 -0800 | [diff] [blame] | 968 | list_del(&wait_entry->list); |
Wey-Yi Guy | 898ed67 | 2011-07-13 08:38:57 -0700 | [diff] [blame] | 969 | spin_unlock_bh(&priv->notif_wait_lock); |
Johannes Berg | 7194207c | 2011-01-04 16:22:00 -0800 | [diff] [blame] | 970 | |
Johannes Berg | e74fe23 | 2011-04-13 03:14:49 -0700 | [diff] [blame] | 971 | if (wait_entry->aborted) |
| 972 | return -EIO; |
| 973 | |
Johannes Berg | a8674a1 | 2011-04-13 03:14:48 -0700 | [diff] [blame] | 974 | /* return value is always >= 0 */ |
| 975 | if (ret <= 0) |
| 976 | return -ETIMEDOUT; |
| 977 | return 0; |
Johannes Berg | 7194207c | 2011-01-04 16:22:00 -0800 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | void iwlagn_remove_notification(struct iwl_priv *priv, |
| 981 | struct iwl_notification_wait *wait_entry) |
| 982 | { |
Wey-Yi Guy | 898ed67 | 2011-07-13 08:38:57 -0700 | [diff] [blame] | 983 | spin_lock_bh(&priv->notif_wait_lock); |
Johannes Berg | 7194207c | 2011-01-04 16:22:00 -0800 | [diff] [blame] | 984 | list_del(&wait_entry->list); |
Wey-Yi Guy | 898ed67 | 2011-07-13 08:38:57 -0700 | [diff] [blame] | 985 | spin_unlock_bh(&priv->notif_wait_lock); |
Johannes Berg | 7194207c | 2011-01-04 16:22:00 -0800 | [diff] [blame] | 986 | } |
Wey-Yi Guy | 023ca58 | 2011-11-10 06:55:17 -0800 | [diff] [blame^] | 987 | |
| 988 | #ifdef CONFIG_PM_SLEEP |
| 989 | static void iwlagn_convert_p1k(u16 *p1k, __le16 *out) |
| 990 | { |
| 991 | int i; |
| 992 | |
| 993 | for (i = 0; i < IWLAGN_P1K_SIZE; i++) |
| 994 | out[i] = cpu_to_le16(p1k[i]); |
| 995 | } |
| 996 | |
| 997 | struct wowlan_key_data { |
| 998 | struct iwl_rxon_context *ctx; |
| 999 | struct iwlagn_wowlan_rsc_tsc_params_cmd *rsc_tsc; |
| 1000 | struct iwlagn_wowlan_tkip_params_cmd *tkip; |
| 1001 | const u8 *bssid; |
| 1002 | bool error, use_rsc_tsc, use_tkip; |
| 1003 | }; |
| 1004 | |
| 1005 | |
| 1006 | static void iwlagn_wowlan_program_keys(struct ieee80211_hw *hw, |
| 1007 | struct ieee80211_vif *vif, |
| 1008 | struct ieee80211_sta *sta, |
| 1009 | struct ieee80211_key_conf *key, |
| 1010 | void *_data) |
| 1011 | { |
| 1012 | struct iwl_priv *priv = hw->priv; |
| 1013 | struct wowlan_key_data *data = _data; |
| 1014 | struct iwl_rxon_context *ctx = data->ctx; |
| 1015 | struct aes_sc *aes_sc, *aes_tx_sc = NULL; |
| 1016 | struct tkip_sc *tkip_sc, *tkip_tx_sc = NULL; |
| 1017 | struct iwlagn_p1k_cache *rx_p1ks; |
| 1018 | u8 *rx_mic_key; |
| 1019 | struct ieee80211_key_seq seq; |
| 1020 | u32 cur_rx_iv32 = 0; |
| 1021 | u16 p1k[IWLAGN_P1K_SIZE]; |
| 1022 | int ret, i; |
| 1023 | |
| 1024 | mutex_lock(&priv->shrd->mutex); |
| 1025 | |
| 1026 | if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 1027 | key->cipher == WLAN_CIPHER_SUITE_WEP104) && |
| 1028 | !sta && !ctx->key_mapping_keys) |
| 1029 | ret = iwl_set_default_wep_key(priv, ctx, key); |
| 1030 | else |
| 1031 | ret = iwl_set_dynamic_key(priv, ctx, key, sta); |
| 1032 | |
| 1033 | if (ret) { |
| 1034 | IWL_ERR(priv, "Error setting key during suspend!\n"); |
| 1035 | data->error = true; |
| 1036 | } |
| 1037 | |
| 1038 | switch (key->cipher) { |
| 1039 | case WLAN_CIPHER_SUITE_TKIP: |
| 1040 | if (sta) { |
| 1041 | tkip_sc = data->rsc_tsc->all_tsc_rsc.tkip.unicast_rsc; |
| 1042 | tkip_tx_sc = &data->rsc_tsc->all_tsc_rsc.tkip.tsc; |
| 1043 | |
| 1044 | rx_p1ks = data->tkip->rx_uni; |
| 1045 | |
| 1046 | ieee80211_get_key_tx_seq(key, &seq); |
| 1047 | tkip_tx_sc->iv16 = cpu_to_le16(seq.tkip.iv16); |
| 1048 | tkip_tx_sc->iv32 = cpu_to_le32(seq.tkip.iv32); |
| 1049 | |
| 1050 | ieee80211_get_tkip_p1k_iv(key, seq.tkip.iv32, p1k); |
| 1051 | iwlagn_convert_p1k(p1k, data->tkip->tx.p1k); |
| 1052 | |
| 1053 | memcpy(data->tkip->mic_keys.tx, |
| 1054 | &key->key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY], |
| 1055 | IWLAGN_MIC_KEY_SIZE); |
| 1056 | |
| 1057 | rx_mic_key = data->tkip->mic_keys.rx_unicast; |
| 1058 | } else { |
| 1059 | tkip_sc = |
| 1060 | data->rsc_tsc->all_tsc_rsc.tkip.multicast_rsc; |
| 1061 | rx_p1ks = data->tkip->rx_multi; |
| 1062 | rx_mic_key = data->tkip->mic_keys.rx_mcast; |
| 1063 | } |
| 1064 | |
| 1065 | /* |
| 1066 | * For non-QoS this relies on the fact that both the uCode and |
| 1067 | * mac80211 use TID 0 (as they need to to avoid replay attacks) |
| 1068 | * for checking the IV in the frames. |
| 1069 | */ |
| 1070 | for (i = 0; i < IWLAGN_NUM_RSC; i++) { |
| 1071 | ieee80211_get_key_rx_seq(key, i, &seq); |
| 1072 | tkip_sc[i].iv16 = cpu_to_le16(seq.tkip.iv16); |
| 1073 | tkip_sc[i].iv32 = cpu_to_le32(seq.tkip.iv32); |
| 1074 | /* wrapping isn't allowed, AP must rekey */ |
| 1075 | if (seq.tkip.iv32 > cur_rx_iv32) |
| 1076 | cur_rx_iv32 = seq.tkip.iv32; |
| 1077 | } |
| 1078 | |
| 1079 | ieee80211_get_tkip_rx_p1k(key, data->bssid, cur_rx_iv32, p1k); |
| 1080 | iwlagn_convert_p1k(p1k, rx_p1ks[0].p1k); |
| 1081 | ieee80211_get_tkip_rx_p1k(key, data->bssid, |
| 1082 | cur_rx_iv32 + 1, p1k); |
| 1083 | iwlagn_convert_p1k(p1k, rx_p1ks[1].p1k); |
| 1084 | |
| 1085 | memcpy(rx_mic_key, |
| 1086 | &key->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY], |
| 1087 | IWLAGN_MIC_KEY_SIZE); |
| 1088 | |
| 1089 | data->use_tkip = true; |
| 1090 | data->use_rsc_tsc = true; |
| 1091 | break; |
| 1092 | case WLAN_CIPHER_SUITE_CCMP: |
| 1093 | if (sta) { |
| 1094 | u8 *pn = seq.ccmp.pn; |
| 1095 | |
| 1096 | aes_sc = data->rsc_tsc->all_tsc_rsc.aes.unicast_rsc; |
| 1097 | aes_tx_sc = &data->rsc_tsc->all_tsc_rsc.aes.tsc; |
| 1098 | |
| 1099 | ieee80211_get_key_tx_seq(key, &seq); |
| 1100 | aes_tx_sc->pn = cpu_to_le64( |
| 1101 | (u64)pn[5] | |
| 1102 | ((u64)pn[4] << 8) | |
| 1103 | ((u64)pn[3] << 16) | |
| 1104 | ((u64)pn[2] << 24) | |
| 1105 | ((u64)pn[1] << 32) | |
| 1106 | ((u64)pn[0] << 40)); |
| 1107 | } else |
| 1108 | aes_sc = data->rsc_tsc->all_tsc_rsc.aes.multicast_rsc; |
| 1109 | |
| 1110 | /* |
| 1111 | * For non-QoS this relies on the fact that both the uCode and |
| 1112 | * mac80211 use TID 0 for checking the IV in the frames. |
| 1113 | */ |
| 1114 | for (i = 0; i < IWLAGN_NUM_RSC; i++) { |
| 1115 | u8 *pn = seq.ccmp.pn; |
| 1116 | |
| 1117 | ieee80211_get_key_rx_seq(key, i, &seq); |
| 1118 | aes_sc->pn = cpu_to_le64( |
| 1119 | (u64)pn[5] | |
| 1120 | ((u64)pn[4] << 8) | |
| 1121 | ((u64)pn[3] << 16) | |
| 1122 | ((u64)pn[2] << 24) | |
| 1123 | ((u64)pn[1] << 32) | |
| 1124 | ((u64)pn[0] << 40)); |
| 1125 | } |
| 1126 | data->use_rsc_tsc = true; |
| 1127 | break; |
| 1128 | } |
| 1129 | |
| 1130 | mutex_unlock(&priv->shrd->mutex); |
| 1131 | } |
| 1132 | |
| 1133 | int iwlagn_send_patterns(struct iwl_priv *priv, |
| 1134 | struct cfg80211_wowlan *wowlan) |
| 1135 | { |
| 1136 | struct iwlagn_wowlan_patterns_cmd *pattern_cmd; |
| 1137 | struct iwl_host_cmd cmd = { |
| 1138 | .id = REPLY_WOWLAN_PATTERNS, |
| 1139 | .dataflags[0] = IWL_HCMD_DFL_NOCOPY, |
| 1140 | .flags = CMD_SYNC, |
| 1141 | }; |
| 1142 | int i, err; |
| 1143 | |
| 1144 | if (!wowlan->n_patterns) |
| 1145 | return 0; |
| 1146 | |
| 1147 | cmd.len[0] = sizeof(*pattern_cmd) + |
| 1148 | wowlan->n_patterns * sizeof(struct iwlagn_wowlan_pattern); |
| 1149 | |
| 1150 | pattern_cmd = kmalloc(cmd.len[0], GFP_KERNEL); |
| 1151 | if (!pattern_cmd) |
| 1152 | return -ENOMEM; |
| 1153 | |
| 1154 | pattern_cmd->n_patterns = cpu_to_le32(wowlan->n_patterns); |
| 1155 | |
| 1156 | for (i = 0; i < wowlan->n_patterns; i++) { |
| 1157 | int mask_len = DIV_ROUND_UP(wowlan->patterns[i].pattern_len, 8); |
| 1158 | |
| 1159 | memcpy(&pattern_cmd->patterns[i].mask, |
| 1160 | wowlan->patterns[i].mask, mask_len); |
| 1161 | memcpy(&pattern_cmd->patterns[i].pattern, |
| 1162 | wowlan->patterns[i].pattern, |
| 1163 | wowlan->patterns[i].pattern_len); |
| 1164 | pattern_cmd->patterns[i].mask_size = mask_len; |
| 1165 | pattern_cmd->patterns[i].pattern_size = |
| 1166 | wowlan->patterns[i].pattern_len; |
| 1167 | } |
| 1168 | |
| 1169 | cmd.data[0] = pattern_cmd; |
| 1170 | err = iwl_trans_send_cmd(trans(priv), &cmd); |
| 1171 | kfree(pattern_cmd); |
| 1172 | return err; |
| 1173 | } |
| 1174 | |
| 1175 | int iwlagn_suspend(struct iwl_priv *priv, |
| 1176 | struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan) |
| 1177 | { |
| 1178 | struct iwlagn_wowlan_wakeup_filter_cmd wakeup_filter_cmd; |
| 1179 | struct iwl_rxon_cmd rxon; |
| 1180 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; |
| 1181 | struct iwlagn_wowlan_kek_kck_material_cmd kek_kck_cmd; |
| 1182 | struct iwlagn_wowlan_tkip_params_cmd tkip_cmd = {}; |
| 1183 | struct iwlagn_d3_config_cmd d3_cfg_cmd = {}; |
| 1184 | struct wowlan_key_data key_data = { |
| 1185 | .ctx = ctx, |
| 1186 | .bssid = ctx->active.bssid_addr, |
| 1187 | .use_rsc_tsc = false, |
| 1188 | .tkip = &tkip_cmd, |
| 1189 | .use_tkip = false, |
| 1190 | }; |
| 1191 | int ret, i; |
| 1192 | u16 seq; |
| 1193 | |
| 1194 | key_data.rsc_tsc = kzalloc(sizeof(*key_data.rsc_tsc), GFP_KERNEL); |
| 1195 | if (!key_data.rsc_tsc) |
| 1196 | return -ENOMEM; |
| 1197 | |
| 1198 | memset(&wakeup_filter_cmd, 0, sizeof(wakeup_filter_cmd)); |
| 1199 | |
| 1200 | /* |
| 1201 | * We know the last used seqno, and the uCode expects to know that |
| 1202 | * one, it will increment before TX. |
| 1203 | */ |
| 1204 | seq = le16_to_cpu(priv->last_seq_ctl) & IEEE80211_SCTL_SEQ; |
| 1205 | wakeup_filter_cmd.non_qos_seq = cpu_to_le16(seq); |
| 1206 | |
| 1207 | /* |
| 1208 | * For QoS counters, we store the one to use next, so subtract 0x10 |
| 1209 | * since the uCode will add 0x10 before using the value. |
| 1210 | */ |
| 1211 | for (i = 0; i < 8; i++) { |
| 1212 | seq = priv->shrd->tid_data[IWL_AP_ID][i].seq_number; |
| 1213 | seq -= 0x10; |
| 1214 | wakeup_filter_cmd.qos_seq[i] = cpu_to_le16(seq); |
| 1215 | } |
| 1216 | |
| 1217 | if (wowlan->disconnect) |
| 1218 | wakeup_filter_cmd.enabled |= |
| 1219 | cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_BEACON_MISS | |
| 1220 | IWLAGN_WOWLAN_WAKEUP_LINK_CHANGE); |
| 1221 | if (wowlan->magic_pkt) |
| 1222 | wakeup_filter_cmd.enabled |= |
| 1223 | cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_MAGIC_PACKET); |
| 1224 | if (wowlan->gtk_rekey_failure) |
| 1225 | wakeup_filter_cmd.enabled |= |
| 1226 | cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_GTK_REKEY_FAIL); |
| 1227 | if (wowlan->eap_identity_req) |
| 1228 | wakeup_filter_cmd.enabled |= |
| 1229 | cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_EAP_IDENT_REQ); |
| 1230 | if (wowlan->four_way_handshake) |
| 1231 | wakeup_filter_cmd.enabled |= |
| 1232 | cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_4WAY_HANDSHAKE); |
| 1233 | if (wowlan->n_patterns) |
| 1234 | wakeup_filter_cmd.enabled |= |
| 1235 | cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_PATTERN_MATCH); |
| 1236 | |
| 1237 | if (wowlan->rfkill_release) |
| 1238 | d3_cfg_cmd.wakeup_flags |= |
| 1239 | cpu_to_le32(IWLAGN_D3_WAKEUP_RFKILL); |
| 1240 | |
| 1241 | iwl_scan_cancel_timeout(priv, 200); |
| 1242 | |
| 1243 | memcpy(&rxon, &ctx->active, sizeof(rxon)); |
| 1244 | |
| 1245 | iwl_trans_stop_device(trans(priv)); |
| 1246 | |
| 1247 | priv->shrd->wowlan = true; |
| 1248 | |
| 1249 | ret = iwlagn_load_ucode_wait_alive(priv, IWL_UCODE_WOWLAN); |
| 1250 | if (ret) |
| 1251 | goto out; |
| 1252 | |
| 1253 | /* now configure WoWLAN ucode */ |
| 1254 | ret = iwl_alive_start(priv); |
| 1255 | if (ret) |
| 1256 | goto out; |
| 1257 | |
| 1258 | memcpy(&ctx->staging, &rxon, sizeof(rxon)); |
| 1259 | ret = iwlagn_commit_rxon(priv, ctx); |
| 1260 | if (ret) |
| 1261 | goto out; |
| 1262 | |
| 1263 | ret = iwl_power_update_mode(priv, true); |
| 1264 | if (ret) |
| 1265 | goto out; |
| 1266 | |
| 1267 | if (!iwlagn_mod_params.sw_crypto) { |
| 1268 | /* mark all keys clear */ |
| 1269 | priv->ucode_key_table = 0; |
| 1270 | ctx->key_mapping_keys = 0; |
| 1271 | |
| 1272 | /* |
| 1273 | * This needs to be unlocked due to lock ordering |
| 1274 | * constraints. Since we're in the suspend path |
| 1275 | * that isn't really a problem though. |
| 1276 | */ |
| 1277 | mutex_unlock(&priv->shrd->mutex); |
| 1278 | ieee80211_iter_keys(priv->hw, ctx->vif, |
| 1279 | iwlagn_wowlan_program_keys, |
| 1280 | &key_data); |
| 1281 | mutex_lock(&priv->shrd->mutex); |
| 1282 | if (key_data.error) { |
| 1283 | ret = -EIO; |
| 1284 | goto out; |
| 1285 | } |
| 1286 | |
| 1287 | if (key_data.use_rsc_tsc) { |
| 1288 | struct iwl_host_cmd rsc_tsc_cmd = { |
| 1289 | .id = REPLY_WOWLAN_TSC_RSC_PARAMS, |
| 1290 | .flags = CMD_SYNC, |
| 1291 | .data[0] = key_data.rsc_tsc, |
| 1292 | .dataflags[0] = IWL_HCMD_DFL_NOCOPY, |
| 1293 | .len[0] = sizeof(key_data.rsc_tsc), |
| 1294 | }; |
| 1295 | |
| 1296 | ret = iwl_trans_send_cmd(trans(priv), &rsc_tsc_cmd); |
| 1297 | if (ret) |
| 1298 | goto out; |
| 1299 | } |
| 1300 | |
| 1301 | if (key_data.use_tkip) { |
| 1302 | ret = iwl_trans_send_cmd_pdu(trans(priv), |
| 1303 | REPLY_WOWLAN_TKIP_PARAMS, |
| 1304 | CMD_SYNC, sizeof(tkip_cmd), |
| 1305 | &tkip_cmd); |
| 1306 | if (ret) |
| 1307 | goto out; |
| 1308 | } |
| 1309 | |
| 1310 | if (priv->have_rekey_data) { |
| 1311 | memset(&kek_kck_cmd, 0, sizeof(kek_kck_cmd)); |
| 1312 | memcpy(kek_kck_cmd.kck, priv->kck, NL80211_KCK_LEN); |
| 1313 | kek_kck_cmd.kck_len = cpu_to_le16(NL80211_KCK_LEN); |
| 1314 | memcpy(kek_kck_cmd.kek, priv->kek, NL80211_KEK_LEN); |
| 1315 | kek_kck_cmd.kek_len = cpu_to_le16(NL80211_KEK_LEN); |
| 1316 | kek_kck_cmd.replay_ctr = priv->replay_ctr; |
| 1317 | |
| 1318 | ret = iwl_trans_send_cmd_pdu(trans(priv), |
| 1319 | REPLY_WOWLAN_KEK_KCK_MATERIAL, |
| 1320 | CMD_SYNC, sizeof(kek_kck_cmd), |
| 1321 | &kek_kck_cmd); |
| 1322 | if (ret) |
| 1323 | goto out; |
| 1324 | } |
| 1325 | } |
| 1326 | |
| 1327 | ret = iwl_trans_send_cmd_pdu(trans(priv), REPLY_D3_CONFIG, CMD_SYNC, |
| 1328 | sizeof(d3_cfg_cmd), &d3_cfg_cmd); |
| 1329 | if (ret) |
| 1330 | goto out; |
| 1331 | |
| 1332 | ret = iwl_trans_send_cmd_pdu(trans(priv), REPLY_WOWLAN_WAKEUP_FILTER, |
| 1333 | CMD_SYNC, sizeof(wakeup_filter_cmd), |
| 1334 | &wakeup_filter_cmd); |
| 1335 | if (ret) |
| 1336 | goto out; |
| 1337 | |
| 1338 | ret = iwlagn_send_patterns(priv, wowlan); |
| 1339 | out: |
| 1340 | kfree(key_data.rsc_tsc); |
| 1341 | return ret; |
| 1342 | } |
| 1343 | #endif |