Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Wey-Yi Guy | fb4961d | 2012-01-06 13:16:33 -0800 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved. |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of version 2 of the GNU General Public License as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in the |
| 19 | * file called LICENSE. |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 24 | * |
| 25 | *****************************************************************************/ |
| 26 | |
Meenakshi Venkataraman | 5562092 | 2012-03-15 13:27:02 -0700 | [diff] [blame] | 27 | #include <linux/etherdevice.h> |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 28 | #include "iwl-dev.h" |
| 29 | #include "iwl-agn.h" |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 30 | #include "iwl-core.h" |
| 31 | #include "iwl-agn-calib.h" |
Emmanuel Grumbach | bdfbf09 | 2011-07-08 08:46:16 -0700 | [diff] [blame] | 32 | #include "iwl-trans.h" |
Emmanuel Grumbach | 48f20d3 | 2011-08-25 23:10:36 -0700 | [diff] [blame] | 33 | #include "iwl-shared.h" |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 34 | |
Meenakshi Venkataraman | 47042ac | 2012-03-13 17:07:48 -0700 | [diff] [blame] | 35 | /* |
| 36 | * initialize rxon structure with default values from eeprom |
| 37 | */ |
| 38 | void iwl_connection_init_rx_config(struct iwl_priv *priv, |
| 39 | struct iwl_rxon_context *ctx) |
| 40 | { |
| 41 | const struct iwl_channel_info *ch_info; |
| 42 | |
| 43 | memset(&ctx->staging, 0, sizeof(ctx->staging)); |
| 44 | |
| 45 | if (!ctx->vif) { |
| 46 | ctx->staging.dev_type = ctx->unused_devtype; |
| 47 | } else |
| 48 | switch (ctx->vif->type) { |
| 49 | case NL80211_IFTYPE_AP: |
| 50 | ctx->staging.dev_type = ctx->ap_devtype; |
| 51 | break; |
| 52 | |
| 53 | case NL80211_IFTYPE_STATION: |
| 54 | ctx->staging.dev_type = ctx->station_devtype; |
| 55 | ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
| 56 | break; |
| 57 | |
| 58 | case NL80211_IFTYPE_ADHOC: |
| 59 | ctx->staging.dev_type = ctx->ibss_devtype; |
| 60 | ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
| 61 | ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK | |
| 62 | RXON_FILTER_ACCEPT_GRP_MSK; |
| 63 | break; |
| 64 | |
| 65 | default: |
| 66 | IWL_ERR(priv, "Unsupported interface type %d\n", |
| 67 | ctx->vif->type); |
| 68 | break; |
| 69 | } |
| 70 | |
| 71 | #if 0 |
| 72 | /* TODO: Figure out when short_preamble would be set and cache from |
| 73 | * that */ |
| 74 | if (!hw_to_local(priv->hw)->short_preamble) |
| 75 | ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 76 | else |
| 77 | ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 78 | #endif |
| 79 | |
| 80 | ch_info = iwl_get_channel_info(priv, priv->band, |
| 81 | le16_to_cpu(ctx->active.channel)); |
| 82 | |
| 83 | if (!ch_info) |
| 84 | ch_info = &priv->channel_info[0]; |
| 85 | |
| 86 | ctx->staging.channel = cpu_to_le16(ch_info->channel); |
| 87 | priv->band = ch_info->band; |
| 88 | |
| 89 | iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif); |
| 90 | |
| 91 | ctx->staging.ofdm_basic_rates = |
| 92 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 93 | ctx->staging.cck_basic_rates = |
| 94 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 95 | |
| 96 | /* clear both MIX and PURE40 mode flag */ |
| 97 | ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED | |
| 98 | RXON_FLG_CHANNEL_MODE_PURE_40); |
| 99 | if (ctx->vif) |
| 100 | memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN); |
| 101 | |
| 102 | ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff; |
| 103 | ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff; |
| 104 | ctx->staging.ofdm_ht_triple_stream_basic_rates = 0xff; |
| 105 | } |
| 106 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 107 | static int iwlagn_disable_bss(struct iwl_priv *priv, |
| 108 | struct iwl_rxon_context *ctx, |
| 109 | struct iwl_rxon_cmd *send) |
| 110 | { |
| 111 | __le32 old_filter = send->filter_flags; |
| 112 | int ret; |
| 113 | |
| 114 | send->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 115 | ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 116 | CMD_SYNC, sizeof(*send), send); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 117 | |
| 118 | send->filter_flags = old_filter; |
| 119 | |
| 120 | if (ret) |
Todd Previte | b36b110 | 2011-11-10 06:55:02 -0800 | [diff] [blame] | 121 | IWL_DEBUG_QUIET_RFKILL(priv, |
| 122 | "Error clearing ASSOC_MSK on BSS (%d)\n", ret); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 123 | |
| 124 | return ret; |
| 125 | } |
| 126 | |
| 127 | static int iwlagn_disable_pan(struct iwl_priv *priv, |
| 128 | struct iwl_rxon_context *ctx, |
| 129 | struct iwl_rxon_cmd *send) |
| 130 | { |
Johannes Berg | 311dce7 | 2011-01-04 16:22:01 -0800 | [diff] [blame] | 131 | struct iwl_notification_wait disable_wait; |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 132 | __le32 old_filter = send->filter_flags; |
| 133 | u8 old_dev_type = send->dev_type; |
| 134 | int ret; |
Johannes Berg | db662d4 | 2012-03-15 13:26:44 -0700 | [diff] [blame] | 135 | static const u8 deactivate_cmd[] = { |
| 136 | REPLY_WIPAN_DEACTIVATION_COMPLETE |
| 137 | }; |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 138 | |
Johannes Berg | 4bd14dd | 2012-03-06 13:30:58 -0800 | [diff] [blame] | 139 | iwl_init_notification_wait(&priv->notif_wait, &disable_wait, |
Johannes Berg | db662d4 | 2012-03-15 13:26:44 -0700 | [diff] [blame] | 140 | deactivate_cmd, ARRAY_SIZE(deactivate_cmd), |
Johannes Berg | 4bd14dd | 2012-03-06 13:30:58 -0800 | [diff] [blame] | 141 | NULL, NULL); |
Johannes Berg | 311dce7 | 2011-01-04 16:22:01 -0800 | [diff] [blame] | 142 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 143 | send->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 144 | send->dev_type = RXON_DEV_TYPE_P2P; |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 145 | ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 146 | CMD_SYNC, sizeof(*send), send); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 147 | |
| 148 | send->filter_flags = old_filter; |
| 149 | send->dev_type = old_dev_type; |
| 150 | |
Johannes Berg | 311dce7 | 2011-01-04 16:22:01 -0800 | [diff] [blame] | 151 | if (ret) { |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 152 | IWL_ERR(priv, "Error disabling PAN (%d)\n", ret); |
Johannes Berg | 4bd14dd | 2012-03-06 13:30:58 -0800 | [diff] [blame] | 153 | iwl_remove_notification(&priv->notif_wait, &disable_wait); |
Johannes Berg | 311dce7 | 2011-01-04 16:22:01 -0800 | [diff] [blame] | 154 | } else { |
Johannes Berg | 4bd14dd | 2012-03-06 13:30:58 -0800 | [diff] [blame] | 155 | ret = iwl_wait_notification(&priv->notif_wait, |
| 156 | &disable_wait, HZ); |
Johannes Berg | a8674a1 | 2011-04-13 03:14:48 -0700 | [diff] [blame] | 157 | if (ret) |
Johannes Berg | 311dce7 | 2011-01-04 16:22:01 -0800 | [diff] [blame] | 158 | IWL_ERR(priv, "Timed out waiting for PAN disable\n"); |
| 159 | } |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 160 | |
| 161 | return ret; |
| 162 | } |
| 163 | |
Johannes Berg | 2b9253d | 2011-05-27 08:40:26 -0700 | [diff] [blame] | 164 | static int iwlagn_disconn_pan(struct iwl_priv *priv, |
| 165 | struct iwl_rxon_context *ctx, |
| 166 | struct iwl_rxon_cmd *send) |
| 167 | { |
| 168 | __le32 old_filter = send->filter_flags; |
| 169 | int ret; |
| 170 | |
| 171 | send->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 172 | ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 173 | sizeof(*send), send); |
Johannes Berg | 2b9253d | 2011-05-27 08:40:26 -0700 | [diff] [blame] | 174 | |
| 175 | send->filter_flags = old_filter; |
| 176 | |
| 177 | return ret; |
| 178 | } |
| 179 | |
Shanyu Zhao | f4115d4 | 2010-11-10 18:25:58 -0800 | [diff] [blame] | 180 | static void iwlagn_update_qos(struct iwl_priv *priv, |
| 181 | struct iwl_rxon_context *ctx) |
| 182 | { |
| 183 | int ret; |
| 184 | |
| 185 | if (!ctx->is_active) |
| 186 | return; |
| 187 | |
| 188 | ctx->qos_data.def_qos_parm.qos_flags = 0; |
| 189 | |
| 190 | if (ctx->qos_data.qos_active) |
| 191 | ctx->qos_data.def_qos_parm.qos_flags |= |
| 192 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; |
| 193 | |
| 194 | if (ctx->ht.enabled) |
| 195 | ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK; |
| 196 | |
Emmanuel Grumbach | 0dcf50c | 2011-11-10 06:55:23 -0800 | [diff] [blame] | 197 | IWL_DEBUG_INFO(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n", |
Shanyu Zhao | f4115d4 | 2010-11-10 18:25:58 -0800 | [diff] [blame] | 198 | ctx->qos_data.qos_active, |
| 199 | ctx->qos_data.def_qos_parm.qos_flags); |
| 200 | |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 201 | ret = iwl_dvm_send_cmd_pdu(priv, ctx->qos_cmd, CMD_SYNC, |
Shanyu Zhao | f4115d4 | 2010-11-10 18:25:58 -0800 | [diff] [blame] | 202 | sizeof(struct iwl_qosparam_cmd), |
| 203 | &ctx->qos_data.def_qos_parm); |
| 204 | if (ret) |
Todd Previte | b36b110 | 2011-11-10 06:55:02 -0800 | [diff] [blame] | 205 | IWL_DEBUG_QUIET_RFKILL(priv, "Failed to update QoS\n"); |
Shanyu Zhao | f4115d4 | 2010-11-10 18:25:58 -0800 | [diff] [blame] | 206 | } |
| 207 | |
Johannes Berg | bd50a8ab | 2010-10-23 09:15:42 -0700 | [diff] [blame] | 208 | static int iwlagn_update_beacon(struct iwl_priv *priv, |
| 209 | struct ieee80211_vif *vif) |
| 210 | { |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 211 | lockdep_assert_held(&priv->mutex); |
Johannes Berg | bd50a8ab | 2010-10-23 09:15:42 -0700 | [diff] [blame] | 212 | |
| 213 | dev_kfree_skb(priv->beacon_skb); |
| 214 | priv->beacon_skb = ieee80211_beacon_get(priv->hw, vif); |
| 215 | if (!priv->beacon_skb) |
| 216 | return -ENOMEM; |
| 217 | return iwlagn_send_beacon_cmd(priv); |
| 218 | } |
| 219 | |
Wey-Yi Guy | c3f6e9c | 2011-04-19 16:52:57 -0700 | [diff] [blame] | 220 | static int iwlagn_send_rxon_assoc(struct iwl_priv *priv, |
| 221 | struct iwl_rxon_context *ctx) |
| 222 | { |
| 223 | int ret = 0; |
Wey-Yi Guy | 89e746b | 2011-04-19 16:52:58 -0700 | [diff] [blame] | 224 | struct iwl_rxon_assoc_cmd rxon_assoc; |
Wey-Yi Guy | c3f6e9c | 2011-04-19 16:52:57 -0700 | [diff] [blame] | 225 | const struct iwl_rxon_cmd *rxon1 = &ctx->staging; |
| 226 | const struct iwl_rxon_cmd *rxon2 = &ctx->active; |
| 227 | |
| 228 | if ((rxon1->flags == rxon2->flags) && |
| 229 | (rxon1->filter_flags == rxon2->filter_flags) && |
| 230 | (rxon1->cck_basic_rates == rxon2->cck_basic_rates) && |
| 231 | (rxon1->ofdm_ht_single_stream_basic_rates == |
| 232 | rxon2->ofdm_ht_single_stream_basic_rates) && |
| 233 | (rxon1->ofdm_ht_dual_stream_basic_rates == |
| 234 | rxon2->ofdm_ht_dual_stream_basic_rates) && |
| 235 | (rxon1->ofdm_ht_triple_stream_basic_rates == |
| 236 | rxon2->ofdm_ht_triple_stream_basic_rates) && |
| 237 | (rxon1->acquisition_data == rxon2->acquisition_data) && |
| 238 | (rxon1->rx_chain == rxon2->rx_chain) && |
| 239 | (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) { |
| 240 | IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n"); |
| 241 | return 0; |
| 242 | } |
| 243 | |
| 244 | rxon_assoc.flags = ctx->staging.flags; |
| 245 | rxon_assoc.filter_flags = ctx->staging.filter_flags; |
| 246 | rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates; |
| 247 | rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates; |
| 248 | rxon_assoc.reserved1 = 0; |
| 249 | rxon_assoc.reserved2 = 0; |
| 250 | rxon_assoc.reserved3 = 0; |
| 251 | rxon_assoc.ofdm_ht_single_stream_basic_rates = |
| 252 | ctx->staging.ofdm_ht_single_stream_basic_rates; |
| 253 | rxon_assoc.ofdm_ht_dual_stream_basic_rates = |
| 254 | ctx->staging.ofdm_ht_dual_stream_basic_rates; |
| 255 | rxon_assoc.rx_chain_select_flags = ctx->staging.rx_chain; |
| 256 | rxon_assoc.ofdm_ht_triple_stream_basic_rates = |
| 257 | ctx->staging.ofdm_ht_triple_stream_basic_rates; |
| 258 | rxon_assoc.acquisition_data = ctx->staging.acquisition_data; |
| 259 | |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 260 | ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_assoc_cmd, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 261 | CMD_ASYNC, sizeof(rxon_assoc), &rxon_assoc); |
Wey-Yi Guy | c3f6e9c | 2011-04-19 16:52:57 -0700 | [diff] [blame] | 262 | return ret; |
| 263 | } |
| 264 | |
Meenakshi Venkataraman | dff96c1 | 2012-03-15 13:26:59 -0700 | [diff] [blame] | 265 | static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val) |
| 266 | { |
| 267 | u16 new_val; |
| 268 | u16 beacon_factor; |
| 269 | |
| 270 | /* |
| 271 | * If mac80211 hasn't given us a beacon interval, program |
| 272 | * the default into the device (not checking this here |
| 273 | * would cause the adjustment below to return the maximum |
| 274 | * value, which may break PAN.) |
| 275 | */ |
| 276 | if (!beacon_val) |
| 277 | return DEFAULT_BEACON_INTERVAL; |
| 278 | |
| 279 | /* |
| 280 | * If the beacon interval we obtained from the peer |
| 281 | * is too large, we'll have to wake up more often |
| 282 | * (and in IBSS case, we'll beacon too much) |
| 283 | * |
| 284 | * For example, if max_beacon_val is 4096, and the |
| 285 | * requested beacon interval is 7000, we'll have to |
| 286 | * use 3500 to be able to wake up on the beacons. |
| 287 | * |
| 288 | * This could badly influence beacon detection stats. |
| 289 | */ |
| 290 | |
| 291 | beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val; |
| 292 | new_val = beacon_val / beacon_factor; |
| 293 | |
| 294 | if (!new_val) |
| 295 | new_val = max_beacon_val; |
| 296 | |
| 297 | return new_val; |
| 298 | } |
| 299 | |
| 300 | static int iwl_send_rxon_timing(struct iwl_priv *priv, |
| 301 | struct iwl_rxon_context *ctx) |
| 302 | { |
| 303 | u64 tsf; |
| 304 | s32 interval_tm, rem; |
| 305 | struct ieee80211_conf *conf = NULL; |
| 306 | u16 beacon_int; |
| 307 | struct ieee80211_vif *vif = ctx->vif; |
| 308 | |
| 309 | conf = &priv->hw->conf; |
| 310 | |
| 311 | lockdep_assert_held(&priv->mutex); |
| 312 | |
| 313 | memset(&ctx->timing, 0, sizeof(struct iwl_rxon_time_cmd)); |
| 314 | |
| 315 | ctx->timing.timestamp = cpu_to_le64(priv->timestamp); |
| 316 | ctx->timing.listen_interval = cpu_to_le16(conf->listen_interval); |
| 317 | |
| 318 | beacon_int = vif ? vif->bss_conf.beacon_int : 0; |
| 319 | |
| 320 | /* |
| 321 | * TODO: For IBSS we need to get atim_window from mac80211, |
| 322 | * for now just always use 0 |
| 323 | */ |
| 324 | ctx->timing.atim_window = 0; |
| 325 | |
| 326 | if (ctx->ctxid == IWL_RXON_CTX_PAN && |
| 327 | (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION) && |
| 328 | iwl_is_associated(priv, IWL_RXON_CTX_BSS) && |
| 329 | priv->contexts[IWL_RXON_CTX_BSS].vif && |
| 330 | priv->contexts[IWL_RXON_CTX_BSS].vif->bss_conf.beacon_int) { |
| 331 | ctx->timing.beacon_interval = |
| 332 | priv->contexts[IWL_RXON_CTX_BSS].timing.beacon_interval; |
| 333 | beacon_int = le16_to_cpu(ctx->timing.beacon_interval); |
| 334 | } else if (ctx->ctxid == IWL_RXON_CTX_BSS && |
| 335 | iwl_is_associated(priv, IWL_RXON_CTX_PAN) && |
| 336 | priv->contexts[IWL_RXON_CTX_PAN].vif && |
| 337 | priv->contexts[IWL_RXON_CTX_PAN].vif->bss_conf.beacon_int && |
| 338 | (!iwl_is_associated_ctx(ctx) || !ctx->vif || |
| 339 | !ctx->vif->bss_conf.beacon_int)) { |
| 340 | ctx->timing.beacon_interval = |
| 341 | priv->contexts[IWL_RXON_CTX_PAN].timing.beacon_interval; |
| 342 | beacon_int = le16_to_cpu(ctx->timing.beacon_interval); |
| 343 | } else { |
| 344 | beacon_int = iwl_adjust_beacon_interval(beacon_int, |
| 345 | IWL_MAX_UCODE_BEACON_INTERVAL * TIME_UNIT); |
| 346 | ctx->timing.beacon_interval = cpu_to_le16(beacon_int); |
| 347 | } |
| 348 | |
| 349 | ctx->beacon_int = beacon_int; |
| 350 | |
| 351 | tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */ |
| 352 | interval_tm = beacon_int * TIME_UNIT; |
| 353 | rem = do_div(tsf, interval_tm); |
| 354 | ctx->timing.beacon_init_val = cpu_to_le32(interval_tm - rem); |
| 355 | |
| 356 | ctx->timing.dtim_period = vif ? (vif->bss_conf.dtim_period ?: 1) : 1; |
| 357 | |
| 358 | IWL_DEBUG_ASSOC(priv, |
| 359 | "beacon interval %d beacon timer %d beacon tim %d\n", |
| 360 | le16_to_cpu(ctx->timing.beacon_interval), |
| 361 | le32_to_cpu(ctx->timing.beacon_init_val), |
| 362 | le16_to_cpu(ctx->timing.atim_window)); |
| 363 | |
| 364 | return iwl_dvm_send_cmd_pdu(priv, ctx->rxon_timing_cmd, |
| 365 | CMD_SYNC, sizeof(ctx->timing), &ctx->timing); |
| 366 | } |
| 367 | |
Wey-Yi Guy | c1821c9 | 2011-04-19 16:52:59 -0700 | [diff] [blame] | 368 | static int iwlagn_rxon_disconn(struct iwl_priv *priv, |
| 369 | struct iwl_rxon_context *ctx) |
| 370 | { |
| 371 | int ret; |
| 372 | struct iwl_rxon_cmd *active = (void *)&ctx->active; |
| 373 | |
Johannes Berg | 2b9253d | 2011-05-27 08:40:26 -0700 | [diff] [blame] | 374 | if (ctx->ctxid == IWL_RXON_CTX_BSS) { |
Wey-Yi Guy | c1821c9 | 2011-04-19 16:52:59 -0700 | [diff] [blame] | 375 | ret = iwlagn_disable_bss(priv, ctx, &ctx->staging); |
Johannes Berg | 2b9253d | 2011-05-27 08:40:26 -0700 | [diff] [blame] | 376 | } else { |
Wey-Yi Guy | c1821c9 | 2011-04-19 16:52:59 -0700 | [diff] [blame] | 377 | ret = iwlagn_disable_pan(priv, ctx, &ctx->staging); |
Johannes Berg | 2b9253d | 2011-05-27 08:40:26 -0700 | [diff] [blame] | 378 | if (ret) |
| 379 | return ret; |
| 380 | if (ctx->vif) { |
| 381 | ret = iwl_send_rxon_timing(priv, ctx); |
| 382 | if (ret) { |
| 383 | IWL_ERR(priv, "Failed to send timing (%d)!\n", ret); |
| 384 | return ret; |
| 385 | } |
| 386 | ret = iwlagn_disconn_pan(priv, ctx, &ctx->staging); |
| 387 | } |
| 388 | } |
Wey-Yi Guy | c1821c9 | 2011-04-19 16:52:59 -0700 | [diff] [blame] | 389 | if (ret) |
| 390 | return ret; |
| 391 | |
| 392 | /* |
| 393 | * Un-assoc RXON clears the station table and WEP |
| 394 | * keys, so we have to restore those afterwards. |
| 395 | */ |
| 396 | iwl_clear_ucode_stations(priv, ctx); |
Johannes Berg | f775aa06d | 2011-06-22 06:34:09 -0700 | [diff] [blame] | 397 | /* update -- might need P2P now */ |
| 398 | iwl_update_bcast_station(priv, ctx); |
Wey-Yi Guy | c1821c9 | 2011-04-19 16:52:59 -0700 | [diff] [blame] | 399 | iwl_restore_stations(priv, ctx); |
| 400 | ret = iwl_restore_default_wep_keys(priv, ctx); |
| 401 | if (ret) { |
| 402 | IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret); |
| 403 | return ret; |
| 404 | } |
| 405 | |
| 406 | memcpy(active, &ctx->staging, sizeof(*active)); |
| 407 | return 0; |
| 408 | } |
| 409 | |
Meenakshi Venkataraman | e6a62a6 | 2012-03-13 18:10:19 -0700 | [diff] [blame] | 410 | static int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force) |
| 411 | { |
| 412 | int ret; |
| 413 | s8 prev_tx_power; |
| 414 | bool defer; |
| 415 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; |
| 416 | |
| 417 | lockdep_assert_held(&priv->mutex); |
| 418 | |
| 419 | if (priv->tx_power_user_lmt == tx_power && !force) |
| 420 | return 0; |
| 421 | |
| 422 | if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) { |
| 423 | IWL_WARN(priv, |
| 424 | "Requested user TXPOWER %d below lower limit %d.\n", |
| 425 | tx_power, |
| 426 | IWLAGN_TX_POWER_TARGET_POWER_MIN); |
| 427 | return -EINVAL; |
| 428 | } |
| 429 | |
| 430 | if (tx_power > priv->tx_power_device_lmt) { |
| 431 | IWL_WARN(priv, |
| 432 | "Requested user TXPOWER %d above upper limit %d.\n", |
| 433 | tx_power, priv->tx_power_device_lmt); |
| 434 | return -EINVAL; |
| 435 | } |
| 436 | |
| 437 | if (!iwl_is_ready_rf(priv)) |
| 438 | return -EIO; |
| 439 | |
| 440 | /* scan complete and commit_rxon use tx_power_next value, |
| 441 | * it always need to be updated for newest request */ |
| 442 | priv->tx_power_next = tx_power; |
| 443 | |
| 444 | /* do not set tx power when scanning or channel changing */ |
| 445 | defer = test_bit(STATUS_SCANNING, &priv->status) || |
| 446 | memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging)); |
| 447 | if (defer && !force) { |
| 448 | IWL_DEBUG_INFO(priv, "Deferring tx power set\n"); |
| 449 | return 0; |
| 450 | } |
| 451 | |
| 452 | prev_tx_power = priv->tx_power_user_lmt; |
| 453 | priv->tx_power_user_lmt = tx_power; |
| 454 | |
| 455 | ret = iwlagn_send_tx_power(priv); |
| 456 | |
| 457 | /* if fail to set tx_power, restore the orig. tx power */ |
| 458 | if (ret) { |
| 459 | priv->tx_power_user_lmt = prev_tx_power; |
| 460 | priv->tx_power_next = prev_tx_power; |
| 461 | } |
| 462 | return ret; |
| 463 | } |
| 464 | |
Wey-Yi Guy | c1821c9 | 2011-04-19 16:52:59 -0700 | [diff] [blame] | 465 | static int iwlagn_rxon_connect(struct iwl_priv *priv, |
| 466 | struct iwl_rxon_context *ctx) |
| 467 | { |
| 468 | int ret; |
| 469 | struct iwl_rxon_cmd *active = (void *)&ctx->active; |
| 470 | |
| 471 | /* RXON timing must be before associated RXON */ |
Johannes Berg | 2b9253d | 2011-05-27 08:40:26 -0700 | [diff] [blame] | 472 | if (ctx->ctxid == IWL_RXON_CTX_BSS) { |
| 473 | ret = iwl_send_rxon_timing(priv, ctx); |
| 474 | if (ret) { |
| 475 | IWL_ERR(priv, "Failed to send timing (%d)!\n", ret); |
| 476 | return ret; |
| 477 | } |
Wey-Yi Guy | c1821c9 | 2011-04-19 16:52:59 -0700 | [diff] [blame] | 478 | } |
| 479 | /* QoS info may be cleared by previous un-assoc RXON */ |
| 480 | iwlagn_update_qos(priv, ctx); |
| 481 | |
| 482 | /* |
| 483 | * We'll run into this code path when beaconing is |
| 484 | * enabled, but then we also need to send the beacon |
| 485 | * to the device. |
| 486 | */ |
| 487 | if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_AP)) { |
| 488 | ret = iwlagn_update_beacon(priv, ctx->vif); |
| 489 | if (ret) { |
| 490 | IWL_ERR(priv, |
| 491 | "Error sending required beacon (%d)!\n", |
| 492 | ret); |
| 493 | return ret; |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | priv->start_calib = 0; |
| 498 | /* |
| 499 | * Apply the new configuration. |
| 500 | * |
| 501 | * Associated RXON doesn't clear the station table in uCode, |
| 502 | * so we don't need to restore stations etc. after this. |
| 503 | */ |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 504 | ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC, |
Wey-Yi Guy | c1821c9 | 2011-04-19 16:52:59 -0700 | [diff] [blame] | 505 | sizeof(struct iwl_rxon_cmd), &ctx->staging); |
| 506 | if (ret) { |
| 507 | IWL_ERR(priv, "Error setting new RXON (%d)\n", ret); |
| 508 | return ret; |
| 509 | } |
| 510 | memcpy(active, &ctx->staging, sizeof(*active)); |
| 511 | |
Wey-Yi Guy | c1821c9 | 2011-04-19 16:52:59 -0700 | [diff] [blame] | 512 | /* IBSS beacon needs to be sent after setting assoc */ |
| 513 | if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_ADHOC)) |
| 514 | if (iwlagn_update_beacon(priv, ctx->vif)) |
| 515 | IWL_ERR(priv, "Error sending IBSS beacon\n"); |
| 516 | iwl_init_sensitivity(priv); |
| 517 | |
| 518 | /* |
| 519 | * If we issue a new RXON command which required a tune then |
| 520 | * we must send a new TXPOWER command or we won't be able to |
| 521 | * Tx any frames. |
| 522 | * |
| 523 | * It's expected we set power here if channel is changing. |
| 524 | */ |
| 525 | ret = iwl_set_tx_power(priv, priv->tx_power_next, true); |
| 526 | if (ret) { |
| 527 | IWL_ERR(priv, "Error sending TX power (%d)\n", ret); |
| 528 | return ret; |
| 529 | } |
Wey-Yi Guy | 15b3f3b | 2011-06-03 07:54:13 -0700 | [diff] [blame] | 530 | |
Stanislaw Gruszka | 107ef97 | 2011-10-12 10:16:35 +0200 | [diff] [blame] | 531 | if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION && |
Don Fry | 3862241 | 2011-12-16 07:07:36 -0800 | [diff] [blame] | 532 | cfg(priv)->ht_params && cfg(priv)->ht_params->smps_mode) |
Wey-Yi Guy | 15b3f3b | 2011-06-03 07:54:13 -0700 | [diff] [blame] | 533 | ieee80211_request_smps(ctx->vif, |
Don Fry | 3862241 | 2011-12-16 07:07:36 -0800 | [diff] [blame] | 534 | cfg(priv)->ht_params->smps_mode); |
Wey-Yi Guy | 15b3f3b | 2011-06-03 07:54:13 -0700 | [diff] [blame] | 535 | |
Wey-Yi Guy | c1821c9 | 2011-04-19 16:52:59 -0700 | [diff] [blame] | 536 | return 0; |
| 537 | } |
| 538 | |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 539 | int iwlagn_set_pan_params(struct iwl_priv *priv) |
| 540 | { |
| 541 | struct iwl_wipan_params_cmd cmd; |
| 542 | struct iwl_rxon_context *ctx_bss, *ctx_pan; |
| 543 | int slot0 = 300, slot1 = 0; |
| 544 | int ret; |
| 545 | |
Johannes Berg | a18f61b | 2012-03-15 13:26:53 -0700 | [diff] [blame] | 546 | if (priv->valid_contexts == BIT(IWL_RXON_CTX_BSS)) |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 547 | return 0; |
| 548 | |
| 549 | BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2); |
| 550 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 551 | lockdep_assert_held(&priv->mutex); |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 552 | |
| 553 | ctx_bss = &priv->contexts[IWL_RXON_CTX_BSS]; |
| 554 | ctx_pan = &priv->contexts[IWL_RXON_CTX_PAN]; |
| 555 | |
| 556 | /* |
| 557 | * If the PAN context is inactive, then we don't need |
| 558 | * to update the PAN parameters, the last thing we'll |
| 559 | * have done before it goes inactive is making the PAN |
| 560 | * parameters be WLAN-only. |
| 561 | */ |
| 562 | if (!ctx_pan->is_active) |
| 563 | return 0; |
| 564 | |
| 565 | memset(&cmd, 0, sizeof(cmd)); |
| 566 | |
| 567 | /* only 2 slots are currently allowed */ |
| 568 | cmd.num_slots = 2; |
| 569 | |
| 570 | cmd.slots[0].type = 0; /* BSS */ |
| 571 | cmd.slots[1].type = 1; /* PAN */ |
| 572 | |
Johannes Berg | c6baf7f | 2011-07-23 10:24:47 -0700 | [diff] [blame] | 573 | if (priv->hw_roc_setup) { |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 574 | /* both contexts must be used for this to happen */ |
Johannes Berg | c6baf7f | 2011-07-23 10:24:47 -0700 | [diff] [blame] | 575 | slot1 = IWL_MIN_SLOT_TIME; |
| 576 | slot0 = 3000; |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 577 | } else if (ctx_bss->vif && ctx_pan->vif) { |
Johannes Berg | bbb05cb | 2011-07-18 01:59:22 -0700 | [diff] [blame] | 578 | int bcnint = ctx_pan->beacon_int; |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 579 | int dtim = ctx_pan->vif->bss_conf.dtim_period ?: 1; |
| 580 | |
| 581 | /* should be set, but seems unused?? */ |
| 582 | cmd.flags |= cpu_to_le16(IWL_WIPAN_PARAMS_FLG_SLOTTED_MODE); |
| 583 | |
| 584 | if (ctx_pan->vif->type == NL80211_IFTYPE_AP && |
| 585 | bcnint && |
Johannes Berg | bbb05cb | 2011-07-18 01:59:22 -0700 | [diff] [blame] | 586 | bcnint != ctx_bss->beacon_int) { |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 587 | IWL_ERR(priv, |
| 588 | "beacon intervals don't match (%d, %d)\n", |
Johannes Berg | bbb05cb | 2011-07-18 01:59:22 -0700 | [diff] [blame] | 589 | ctx_bss->beacon_int, ctx_pan->beacon_int); |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 590 | } else |
| 591 | bcnint = max_t(int, bcnint, |
Johannes Berg | bbb05cb | 2011-07-18 01:59:22 -0700 | [diff] [blame] | 592 | ctx_bss->beacon_int); |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 593 | if (!bcnint) |
| 594 | bcnint = DEFAULT_BEACON_INTERVAL; |
| 595 | slot0 = bcnint / 2; |
| 596 | slot1 = bcnint - slot0; |
| 597 | |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 598 | if (test_bit(STATUS_SCAN_HW, &priv->status) || |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 599 | (!ctx_bss->vif->bss_conf.idle && |
| 600 | !ctx_bss->vif->bss_conf.assoc)) { |
| 601 | slot0 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME; |
| 602 | slot1 = IWL_MIN_SLOT_TIME; |
| 603 | } else if (!ctx_pan->vif->bss_conf.idle && |
| 604 | !ctx_pan->vif->bss_conf.assoc) { |
Johannes Berg | 325a7dd | 2011-09-22 15:14:55 -0700 | [diff] [blame] | 605 | slot1 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME; |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 606 | slot0 = IWL_MIN_SLOT_TIME; |
| 607 | } |
| 608 | } else if (ctx_pan->vif) { |
| 609 | slot0 = 0; |
| 610 | slot1 = max_t(int, 1, ctx_pan->vif->bss_conf.dtim_period) * |
Johannes Berg | bbb05cb | 2011-07-18 01:59:22 -0700 | [diff] [blame] | 611 | ctx_pan->beacon_int; |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 612 | slot1 = max_t(int, DEFAULT_BEACON_INTERVAL, slot1); |
| 613 | |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 614 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 615 | slot0 = slot1 * 3 - IWL_MIN_SLOT_TIME; |
| 616 | slot1 = IWL_MIN_SLOT_TIME; |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | cmd.slots[0].width = cpu_to_le16(slot0); |
| 621 | cmd.slots[1].width = cpu_to_le16(slot1); |
| 622 | |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 623 | ret = iwl_dvm_send_cmd_pdu(priv, REPLY_WIPAN_PARAMS, CMD_SYNC, |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 624 | sizeof(cmd), &cmd); |
| 625 | if (ret) |
| 626 | IWL_ERR(priv, "Error setting PAN parameters (%d)\n", ret); |
| 627 | |
| 628 | return ret; |
| 629 | } |
| 630 | |
Meenakshi Venkataraman | dd64173 | 2012-03-13 16:25:38 -0700 | [diff] [blame] | 631 | static void _iwl_set_rxon_ht(struct iwl_priv *priv, |
| 632 | struct iwl_ht_config *ht_conf, |
| 633 | struct iwl_rxon_context *ctx) |
| 634 | { |
| 635 | struct iwl_rxon_cmd *rxon = &ctx->staging; |
| 636 | |
| 637 | if (!ctx->ht.enabled) { |
| 638 | rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK | |
| 639 | RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK | |
| 640 | RXON_FLG_HT40_PROT_MSK | |
| 641 | RXON_FLG_HT_PROT_MSK); |
| 642 | return; |
| 643 | } |
| 644 | |
| 645 | /* FIXME: if the definition of ht.protection changed, the "translation" |
| 646 | * will be needed for rxon->flags |
| 647 | */ |
| 648 | rxon->flags |= cpu_to_le32(ctx->ht.protection << |
| 649 | RXON_FLG_HT_OPERATING_MODE_POS); |
| 650 | |
| 651 | /* Set up channel bandwidth: |
| 652 | * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */ |
| 653 | /* clear the HT channel mode before set the mode */ |
| 654 | rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK | |
| 655 | RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK); |
| 656 | if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) { |
| 657 | /* pure ht40 */ |
| 658 | if (ctx->ht.protection == |
| 659 | IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) { |
| 660 | rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40; |
| 661 | /* |
| 662 | * Note: control channel is opposite of extension |
| 663 | * channel |
| 664 | */ |
| 665 | switch (ctx->ht.extension_chan_offset) { |
| 666 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: |
| 667 | rxon->flags &= |
| 668 | ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK; |
| 669 | break; |
| 670 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: |
| 671 | rxon->flags |= |
| 672 | RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK; |
| 673 | break; |
| 674 | } |
| 675 | } else { |
| 676 | /* |
| 677 | * Note: control channel is opposite of extension |
| 678 | * channel |
| 679 | */ |
| 680 | switch (ctx->ht.extension_chan_offset) { |
| 681 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: |
| 682 | rxon->flags &= |
| 683 | ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK); |
| 684 | rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED; |
| 685 | break; |
| 686 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: |
| 687 | rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK; |
| 688 | rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED; |
| 689 | break; |
| 690 | case IEEE80211_HT_PARAM_CHA_SEC_NONE: |
| 691 | default: |
| 692 | /* |
| 693 | * channel location only valid if in Mixed |
| 694 | * mode |
| 695 | */ |
| 696 | IWL_ERR(priv, |
| 697 | "invalid extension channel offset\n"); |
| 698 | break; |
| 699 | } |
| 700 | } |
| 701 | } else { |
| 702 | rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY; |
| 703 | } |
| 704 | |
| 705 | iwlagn_set_rxon_chain(priv, ctx); |
| 706 | |
| 707 | IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X " |
| 708 | "extension channel offset 0x%x\n", |
| 709 | le32_to_cpu(rxon->flags), ctx->ht.protection, |
| 710 | ctx->ht.extension_chan_offset); |
| 711 | } |
| 712 | |
| 713 | void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf) |
| 714 | { |
| 715 | struct iwl_rxon_context *ctx; |
| 716 | |
| 717 | for_each_context(priv, ctx) |
| 718 | _iwl_set_rxon_ht(priv, ht_conf, ctx); |
| 719 | } |
| 720 | |
Meenakshi Venkataraman | fedfa87 | 2012-03-13 16:31:34 -0700 | [diff] [blame] | 721 | /** |
| 722 | * iwl_set_rxon_channel - Set the band and channel values in staging RXON |
| 723 | * @ch: requested channel as a pointer to struct ieee80211_channel |
| 724 | |
| 725 | * NOTE: Does not commit to the hardware; it sets appropriate bit fields |
| 726 | * in the staging RXON flag structure based on the ch->band |
| 727 | */ |
| 728 | void iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch, |
| 729 | struct iwl_rxon_context *ctx) |
| 730 | { |
| 731 | enum ieee80211_band band = ch->band; |
| 732 | u16 channel = ch->hw_value; |
| 733 | |
| 734 | if ((le16_to_cpu(ctx->staging.channel) == channel) && |
| 735 | (priv->band == band)) |
| 736 | return; |
| 737 | |
| 738 | ctx->staging.channel = cpu_to_le16(channel); |
| 739 | if (band == IEEE80211_BAND_5GHZ) |
| 740 | ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK; |
| 741 | else |
| 742 | ctx->staging.flags |= RXON_FLG_BAND_24G_MSK; |
| 743 | |
| 744 | priv->band = band; |
| 745 | |
| 746 | IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band); |
| 747 | |
| 748 | } |
| 749 | |
Meenakshi Venkataraman | 50319f7 | 2012-03-13 16:45:00 -0700 | [diff] [blame] | 750 | void iwl_set_flags_for_band(struct iwl_priv *priv, |
| 751 | struct iwl_rxon_context *ctx, |
| 752 | enum ieee80211_band band, |
| 753 | struct ieee80211_vif *vif) |
| 754 | { |
| 755 | if (band == IEEE80211_BAND_5GHZ) { |
| 756 | ctx->staging.flags &= |
| 757 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
| 758 | | RXON_FLG_CCK_MSK); |
| 759 | ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 760 | } else { |
| 761 | /* Copied from iwl_post_associate() */ |
| 762 | if (vif && vif->bss_conf.use_short_slot) |
| 763 | ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 764 | else |
| 765 | ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 766 | |
| 767 | ctx->staging.flags |= RXON_FLG_BAND_24G_MSK; |
| 768 | ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK; |
| 769 | ctx->staging.flags &= ~RXON_FLG_CCK_MSK; |
| 770 | } |
| 771 | } |
| 772 | |
Meenakshi Venkataraman | aecd44f | 2012-03-13 17:16:07 -0700 | [diff] [blame] | 773 | void iwl_set_rate(struct iwl_priv *priv) |
| 774 | { |
| 775 | struct iwl_rxon_context *ctx; |
| 776 | |
| 777 | for_each_context(priv, ctx) { |
| 778 | ctx->staging.cck_basic_rates = |
| 779 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 780 | |
| 781 | ctx->staging.ofdm_basic_rates = |
| 782 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 783 | } |
| 784 | } |
| 785 | |
Meenakshi Venkataraman | 354a453 | 2012-03-15 13:27:00 -0700 | [diff] [blame] | 786 | static void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, |
| 787 | struct iwl_rxon_context *ctx, int hw_decrypt) |
| 788 | { |
| 789 | struct iwl_rxon_cmd *rxon = &ctx->staging; |
| 790 | |
| 791 | if (hw_decrypt) |
| 792 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; |
| 793 | else |
| 794 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; |
| 795 | |
| 796 | } |
| 797 | |
Meenakshi Venkataraman | 8931b57 | 2012-03-15 13:27:01 -0700 | [diff] [blame] | 798 | /* validate RXON structure is valid */ |
| 799 | static int iwl_check_rxon_cmd(struct iwl_priv *priv, |
| 800 | struct iwl_rxon_context *ctx) |
| 801 | { |
| 802 | struct iwl_rxon_cmd *rxon = &ctx->staging; |
| 803 | u32 errors = 0; |
| 804 | |
| 805 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { |
| 806 | if (rxon->flags & RXON_FLG_TGJ_NARROW_BAND_MSK) { |
| 807 | IWL_WARN(priv, "check 2.4G: wrong narrow\n"); |
| 808 | errors |= BIT(0); |
| 809 | } |
| 810 | if (rxon->flags & RXON_FLG_RADAR_DETECT_MSK) { |
| 811 | IWL_WARN(priv, "check 2.4G: wrong radar\n"); |
| 812 | errors |= BIT(1); |
| 813 | } |
| 814 | } else { |
| 815 | if (!(rxon->flags & RXON_FLG_SHORT_SLOT_MSK)) { |
| 816 | IWL_WARN(priv, "check 5.2G: not short slot!\n"); |
| 817 | errors |= BIT(2); |
| 818 | } |
| 819 | if (rxon->flags & RXON_FLG_CCK_MSK) { |
| 820 | IWL_WARN(priv, "check 5.2G: CCK!\n"); |
| 821 | errors |= BIT(3); |
| 822 | } |
| 823 | } |
| 824 | if ((rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1) { |
| 825 | IWL_WARN(priv, "mac/bssid mcast!\n"); |
| 826 | errors |= BIT(4); |
| 827 | } |
| 828 | |
| 829 | /* make sure basic rates 6Mbps and 1Mbps are supported */ |
| 830 | if ((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0 && |
| 831 | (rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0) { |
| 832 | IWL_WARN(priv, "neither 1 nor 6 are basic\n"); |
| 833 | errors |= BIT(5); |
| 834 | } |
| 835 | |
| 836 | if (le16_to_cpu(rxon->assoc_id) > 2007) { |
| 837 | IWL_WARN(priv, "aid > 2007\n"); |
| 838 | errors |= BIT(6); |
| 839 | } |
| 840 | |
| 841 | if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) |
| 842 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) { |
| 843 | IWL_WARN(priv, "CCK and short slot\n"); |
| 844 | errors |= BIT(7); |
| 845 | } |
| 846 | |
| 847 | if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) |
| 848 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) { |
| 849 | IWL_WARN(priv, "CCK and auto detect"); |
| 850 | errors |= BIT(8); |
| 851 | } |
| 852 | |
| 853 | if ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | |
| 854 | RXON_FLG_TGG_PROTECT_MSK)) == |
| 855 | RXON_FLG_TGG_PROTECT_MSK) { |
| 856 | IWL_WARN(priv, "TGg but no auto-detect\n"); |
| 857 | errors |= BIT(9); |
| 858 | } |
| 859 | |
| 860 | if (rxon->channel == 0) { |
| 861 | IWL_WARN(priv, "zero channel is invalid\n"); |
| 862 | errors |= BIT(10); |
| 863 | } |
| 864 | |
| 865 | WARN(errors, "Invalid RXON (%#x), channel %d", |
| 866 | errors, le16_to_cpu(rxon->channel)); |
| 867 | |
| 868 | return errors ? -EINVAL : 0; |
| 869 | } |
| 870 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 871 | /** |
Meenakshi Venkataraman | 5562092 | 2012-03-15 13:27:02 -0700 | [diff] [blame] | 872 | * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed |
| 873 | * @priv: staging_rxon is compared to active_rxon |
| 874 | * |
| 875 | * If the RXON structure is changing enough to require a new tune, |
| 876 | * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that |
| 877 | * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required. |
| 878 | */ |
| 879 | static int iwl_full_rxon_required(struct iwl_priv *priv, |
| 880 | struct iwl_rxon_context *ctx) |
| 881 | { |
| 882 | const struct iwl_rxon_cmd *staging = &ctx->staging; |
| 883 | const struct iwl_rxon_cmd *active = &ctx->active; |
| 884 | |
| 885 | #define CHK(cond) \ |
| 886 | if ((cond)) { \ |
| 887 | IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \ |
| 888 | return 1; \ |
| 889 | } |
| 890 | |
| 891 | #define CHK_NEQ(c1, c2) \ |
| 892 | if ((c1) != (c2)) { \ |
| 893 | IWL_DEBUG_INFO(priv, "need full RXON - " \ |
| 894 | #c1 " != " #c2 " - %d != %d\n", \ |
| 895 | (c1), (c2)); \ |
| 896 | return 1; \ |
| 897 | } |
| 898 | |
| 899 | /* These items are only settable from the full RXON command */ |
| 900 | CHK(!iwl_is_associated_ctx(ctx)); |
| 901 | CHK(compare_ether_addr(staging->bssid_addr, active->bssid_addr)); |
| 902 | CHK(compare_ether_addr(staging->node_addr, active->node_addr)); |
| 903 | CHK(compare_ether_addr(staging->wlap_bssid_addr, |
| 904 | active->wlap_bssid_addr)); |
| 905 | CHK_NEQ(staging->dev_type, active->dev_type); |
| 906 | CHK_NEQ(staging->channel, active->channel); |
| 907 | CHK_NEQ(staging->air_propagation, active->air_propagation); |
| 908 | CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates, |
| 909 | active->ofdm_ht_single_stream_basic_rates); |
| 910 | CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates, |
| 911 | active->ofdm_ht_dual_stream_basic_rates); |
| 912 | CHK_NEQ(staging->ofdm_ht_triple_stream_basic_rates, |
| 913 | active->ofdm_ht_triple_stream_basic_rates); |
| 914 | CHK_NEQ(staging->assoc_id, active->assoc_id); |
| 915 | |
| 916 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can |
| 917 | * be updated with the RXON_ASSOC command -- however only some |
| 918 | * flag transitions are allowed using RXON_ASSOC */ |
| 919 | |
| 920 | /* Check if we are not switching bands */ |
| 921 | CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK, |
| 922 | active->flags & RXON_FLG_BAND_24G_MSK); |
| 923 | |
| 924 | /* Check if we are switching association toggle */ |
| 925 | CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK, |
| 926 | active->filter_flags & RXON_FILTER_ASSOC_MSK); |
| 927 | |
| 928 | #undef CHK |
| 929 | #undef CHK_NEQ |
| 930 | |
| 931 | return 0; |
| 932 | } |
| 933 | |
Meenakshi Venkataraman | 4d323ac | 2012-03-14 15:15:33 -0700 | [diff] [blame^] | 934 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 935 | void iwl_print_rx_config_cmd(struct iwl_priv *priv, |
| 936 | enum iwl_rxon_context_id ctxid) |
| 937 | { |
| 938 | struct iwl_rxon_context *ctx = &priv->contexts[ctxid]; |
| 939 | struct iwl_rxon_cmd *rxon = &ctx->staging; |
| 940 | |
| 941 | IWL_DEBUG_RADIO(priv, "RX CONFIG:\n"); |
| 942 | iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
| 943 | IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n", |
| 944 | le16_to_cpu(rxon->channel)); |
| 945 | IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n", |
| 946 | le32_to_cpu(rxon->flags)); |
| 947 | IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n", |
| 948 | le32_to_cpu(rxon->filter_flags)); |
| 949 | IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type); |
| 950 | IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n", |
| 951 | rxon->ofdm_basic_rates); |
| 952 | IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n", |
| 953 | rxon->cck_basic_rates); |
| 954 | IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr); |
| 955 | IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr); |
| 956 | IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n", |
| 957 | le16_to_cpu(rxon->assoc_id)); |
| 958 | } |
| 959 | #endif |
| 960 | |
Meenakshi Venkataraman | 5562092 | 2012-03-15 13:27:02 -0700 | [diff] [blame] | 961 | /** |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 962 | * iwlagn_commit_rxon - commit staging_rxon to hardware |
| 963 | * |
| 964 | * The RXON command in staging_rxon is committed to the hardware and |
| 965 | * the active_rxon structure is updated with the new data. This |
| 966 | * function correctly transitions out of the RXON_ASSOC_MSK state if |
| 967 | * a HW tune is required based on the RXON structure changes. |
Wey-Yi Guy | c1821c9 | 2011-04-19 16:52:59 -0700 | [diff] [blame] | 968 | * |
| 969 | * The connect/disconnect flow should be as the following: |
| 970 | * |
| 971 | * 1. make sure send RXON command with association bit unset if not connect |
| 972 | * this should include the channel and the band for the candidate |
| 973 | * to be connected to |
| 974 | * 2. Add Station before RXON association with the AP |
| 975 | * 3. RXON_timing has to send before RXON for connection |
| 976 | * 4. full RXON command - associated bit set |
| 977 | * 5. use RXON_ASSOC command to update any flags changes |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 978 | */ |
| 979 | int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx) |
| 980 | { |
| 981 | /* cast away the const for active_rxon in this function */ |
| 982 | struct iwl_rxon_cmd *active = (void *)&ctx->active; |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 983 | bool new_assoc = !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK); |
| 984 | int ret; |
| 985 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 986 | lockdep_assert_held(&priv->mutex); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 987 | |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 988 | if (!iwl_is_alive(priv)) |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 989 | return -EBUSY; |
| 990 | |
| 991 | /* This function hardcodes a bunch of dual-mode assumptions */ |
| 992 | BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2); |
| 993 | |
| 994 | if (!ctx->is_active) |
| 995 | return 0; |
| 996 | |
| 997 | /* always get timestamp with Rx frame */ |
| 998 | ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK; |
| 999 | |
Stanislaw Gruszka | 42b70a5 | 2011-05-26 17:14:22 +0200 | [diff] [blame] | 1000 | /* |
| 1001 | * force CTS-to-self frames protection if RTS-CTS is not preferred |
| 1002 | * one aggregation protection method |
| 1003 | */ |
Johannes Berg | 9e29511 | 2012-04-09 17:46:55 -0700 | [diff] [blame] | 1004 | if (!priv->hw_params.use_rts_for_aggregation) |
Stanislaw Gruszka | 42b70a5 | 2011-05-26 17:14:22 +0200 | [diff] [blame] | 1005 | ctx->staging.flags |= RXON_FLG_SELF_CTS_EN; |
| 1006 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1007 | if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) || |
| 1008 | !(ctx->staging.flags & RXON_FLG_BAND_24G_MSK)) |
| 1009 | ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 1010 | else |
| 1011 | ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 1012 | |
Emmanuel Grumbach | 522376d | 2011-09-06 09:31:19 -0700 | [diff] [blame] | 1013 | iwl_print_rx_config_cmd(priv, ctx->ctxid); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1014 | ret = iwl_check_rxon_cmd(priv, ctx); |
| 1015 | if (ret) { |
| 1016 | IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n"); |
| 1017 | return -EINVAL; |
| 1018 | } |
| 1019 | |
| 1020 | /* |
| 1021 | * receive commit_rxon request |
| 1022 | * abort any previous channel switch if still in process |
| 1023 | */ |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 1024 | if (test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status) && |
Stanislaw Gruszka | 6f213ff | 2011-06-02 18:17:15 +0200 | [diff] [blame] | 1025 | (priv->switch_channel != ctx->staging.channel)) { |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1026 | IWL_DEBUG_11H(priv, "abort channel switch on %d\n", |
Stanislaw Gruszka | 6f213ff | 2011-06-02 18:17:15 +0200 | [diff] [blame] | 1027 | le16_to_cpu(priv->switch_channel)); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1028 | iwl_chswitch_done(priv, false); |
| 1029 | } |
| 1030 | |
| 1031 | /* |
| 1032 | * If we don't need to send a full RXON, we can use |
| 1033 | * iwl_rxon_assoc_cmd which is used to reconfigure filter |
| 1034 | * and other flags for the current radio configuration. |
| 1035 | */ |
| 1036 | if (!iwl_full_rxon_required(priv, ctx)) { |
Wey-Yi Guy | c3f6e9c | 2011-04-19 16:52:57 -0700 | [diff] [blame] | 1037 | ret = iwlagn_send_rxon_assoc(priv, ctx); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1038 | if (ret) { |
| 1039 | IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret); |
| 1040 | return ret; |
| 1041 | } |
| 1042 | |
| 1043 | memcpy(active, &ctx->staging, sizeof(*active)); |
Wey-Yi Guy | 891db88 | 2011-05-27 08:40:24 -0700 | [diff] [blame] | 1044 | /* |
| 1045 | * We do not commit tx power settings while channel changing, |
| 1046 | * do it now if after settings changed. |
| 1047 | */ |
| 1048 | iwl_set_tx_power(priv, priv->tx_power_next, false); |
Wey-Yi Guy | 15b3f3b | 2011-06-03 07:54:13 -0700 | [diff] [blame] | 1049 | |
| 1050 | /* make sure we are in the right PS state */ |
| 1051 | iwl_power_update_mode(priv, true); |
| 1052 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1053 | return 0; |
| 1054 | } |
| 1055 | |
Don Fry | 9d143e9 | 2011-04-20 15:23:57 -0700 | [diff] [blame] | 1056 | iwl_set_rxon_hwcrypto(priv, ctx, !iwlagn_mod_params.sw_crypto); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1057 | |
| 1058 | IWL_DEBUG_INFO(priv, |
| 1059 | "Going to commit RXON\n" |
| 1060 | " * with%s RXON_FILTER_ASSOC_MSK\n" |
| 1061 | " * channel = %d\n" |
| 1062 | " * bssid = %pM\n", |
| 1063 | (new_assoc ? "" : "out"), |
| 1064 | le16_to_cpu(ctx->staging.channel), |
| 1065 | ctx->staging.bssid_addr); |
| 1066 | |
| 1067 | /* |
Johannes Berg | 52d980c | 2010-11-10 09:56:45 -0800 | [diff] [blame] | 1068 | * Always clear associated first, but with the correct config. |
| 1069 | * This is required as for example station addition for the |
| 1070 | * AP station must be done after the BSSID is set to correctly |
| 1071 | * set up filters in the device. |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1072 | */ |
Wey-Yi Guy | 3083d03 | 2011-05-06 17:06:44 -0700 | [diff] [blame] | 1073 | ret = iwlagn_rxon_disconn(priv, ctx); |
| 1074 | if (ret) |
| 1075 | return ret; |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1076 | |
Wey-Yi Guy | e3f10ce | 2011-07-01 07:59:26 -0700 | [diff] [blame] | 1077 | ret = iwlagn_set_pan_params(priv); |
| 1078 | if (ret) |
| 1079 | return ret; |
Johannes Berg | 2b9253d | 2011-05-27 08:40:26 -0700 | [diff] [blame] | 1080 | |
Wey-Yi Guy | c1821c9 | 2011-04-19 16:52:59 -0700 | [diff] [blame] | 1081 | if (new_assoc) |
| 1082 | return iwlagn_rxon_connect(priv, ctx); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1083 | |
| 1084 | return 0; |
| 1085 | } |
| 1086 | |
Wey-Yi Guy | 34a5b4b | 2011-12-02 08:19:18 -0800 | [diff] [blame] | 1087 | void iwlagn_config_ht40(struct ieee80211_conf *conf, |
| 1088 | struct iwl_rxon_context *ctx) |
| 1089 | { |
| 1090 | if (conf_is_ht40_minus(conf)) { |
| 1091 | ctx->ht.extension_chan_offset = |
| 1092 | IEEE80211_HT_PARAM_CHA_SEC_BELOW; |
| 1093 | ctx->ht.is_40mhz = true; |
| 1094 | } else if (conf_is_ht40_plus(conf)) { |
| 1095 | ctx->ht.extension_chan_offset = |
| 1096 | IEEE80211_HT_PARAM_CHA_SEC_ABOVE; |
| 1097 | ctx->ht.is_40mhz = true; |
| 1098 | } else { |
| 1099 | ctx->ht.extension_chan_offset = |
| 1100 | IEEE80211_HT_PARAM_CHA_SEC_NONE; |
| 1101 | ctx->ht.is_40mhz = false; |
| 1102 | } |
| 1103 | } |
| 1104 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1105 | int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed) |
| 1106 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1107 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1108 | struct iwl_rxon_context *ctx; |
| 1109 | struct ieee80211_conf *conf = &hw->conf; |
| 1110 | struct ieee80211_channel *channel = conf->channel; |
| 1111 | const struct iwl_channel_info *ch_info; |
| 1112 | int ret = 0; |
| 1113 | |
Johannes Berg | 0ca24da | 2012-03-15 13:26:46 -0700 | [diff] [blame] | 1114 | IWL_DEBUG_MAC80211(priv, "enter: changed %#x\n", changed); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1115 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1116 | mutex_lock(&priv->mutex); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1117 | |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 1118 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) { |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1119 | IWL_DEBUG_MAC80211(priv, "leave - scanning\n"); |
| 1120 | goto out; |
| 1121 | } |
| 1122 | |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 1123 | if (!iwl_is_ready(priv)) { |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1124 | IWL_DEBUG_MAC80211(priv, "leave - not ready\n"); |
| 1125 | goto out; |
| 1126 | } |
| 1127 | |
| 1128 | if (changed & (IEEE80211_CONF_CHANGE_SMPS | |
| 1129 | IEEE80211_CONF_CHANGE_CHANNEL)) { |
| 1130 | /* mac80211 uses static for non-HT which is what we want */ |
| 1131 | priv->current_ht_config.smps = conf->smps_mode; |
| 1132 | |
| 1133 | /* |
| 1134 | * Recalculate chain counts. |
| 1135 | * |
| 1136 | * If monitor mode is enabled then mac80211 will |
| 1137 | * set up the SM PS mode to OFF if an HT channel is |
| 1138 | * configured. |
| 1139 | */ |
Wey-Yi Guy | e3f10ce | 2011-07-01 07:59:26 -0700 | [diff] [blame] | 1140 | for_each_context(priv, ctx) |
| 1141 | iwlagn_set_rxon_chain(priv, ctx); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1145 | ch_info = iwl_get_channel_info(priv, channel->band, |
| 1146 | channel->hw_value); |
| 1147 | if (!is_channel_valid(ch_info)) { |
| 1148 | IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n"); |
| 1149 | ret = -EINVAL; |
| 1150 | goto out; |
| 1151 | } |
| 1152 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1153 | for_each_context(priv, ctx) { |
| 1154 | /* Configure HT40 channels */ |
Daniel Halperin | 7caa231 | 2011-04-06 12:47:25 -0700 | [diff] [blame] | 1155 | if (ctx->ht.enabled != conf_is_ht(conf)) |
Wey-Yi Guy | 35a6eb3 | 2010-11-10 09:56:43 -0800 | [diff] [blame] | 1156 | ctx->ht.enabled = conf_is_ht(conf); |
Wey-Yi Guy | 35a6eb3 | 2010-11-10 09:56:43 -0800 | [diff] [blame] | 1157 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1158 | if (ctx->ht.enabled) { |
Wey-Yi Guy | 34a5b4b | 2011-12-02 08:19:18 -0800 | [diff] [blame] | 1159 | /* if HT40 is used, it should not change |
| 1160 | * after associated except channel switch */ |
Wey-Yi Guy | 78feb35 | 2011-12-14 08:22:36 -0800 | [diff] [blame] | 1161 | if (!ctx->ht.is_40mhz || |
| 1162 | !iwl_is_associated_ctx(ctx)) |
Wey-Yi Guy | 34a5b4b | 2011-12-02 08:19:18 -0800 | [diff] [blame] | 1163 | iwlagn_config_ht40(conf, ctx); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1164 | } else |
| 1165 | ctx->ht.is_40mhz = false; |
| 1166 | |
| 1167 | /* |
| 1168 | * Default to no protection. Protection mode will |
| 1169 | * later be set from BSS config in iwl_ht_conf |
| 1170 | */ |
| 1171 | ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE; |
| 1172 | |
| 1173 | /* if we are switching from ht to 2.4 clear flags |
| 1174 | * from any ht related info since 2.4 does not |
| 1175 | * support ht */ |
| 1176 | if (le16_to_cpu(ctx->staging.channel) != |
| 1177 | channel->hw_value) |
| 1178 | ctx->staging.flags = 0; |
| 1179 | |
| 1180 | iwl_set_rxon_channel(priv, channel, ctx); |
| 1181 | iwl_set_rxon_ht(priv, &priv->current_ht_config); |
| 1182 | |
| 1183 | iwl_set_flags_for_band(priv, ctx, channel->band, |
| 1184 | ctx->vif); |
| 1185 | } |
| 1186 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1187 | iwl_update_bcast_stations(priv); |
| 1188 | |
| 1189 | /* |
| 1190 | * The list of supported rates and rate mask can be different |
| 1191 | * for each band; since the band may have changed, reset |
| 1192 | * the rate mask to what mac80211 lists. |
| 1193 | */ |
| 1194 | iwl_set_rate(priv); |
| 1195 | } |
| 1196 | |
| 1197 | if (changed & (IEEE80211_CONF_CHANGE_PS | |
| 1198 | IEEE80211_CONF_CHANGE_IDLE)) { |
| 1199 | ret = iwl_power_update_mode(priv, false); |
| 1200 | if (ret) |
| 1201 | IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n"); |
| 1202 | } |
| 1203 | |
| 1204 | if (changed & IEEE80211_CONF_CHANGE_POWER) { |
| 1205 | IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n", |
| 1206 | priv->tx_power_user_lmt, conf->power_level); |
| 1207 | |
| 1208 | iwl_set_tx_power(priv, conf->power_level, false); |
| 1209 | } |
| 1210 | |
| 1211 | for_each_context(priv, ctx) { |
| 1212 | if (!memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging))) |
| 1213 | continue; |
| 1214 | iwlagn_commit_rxon(priv, ctx); |
| 1215 | } |
| 1216 | out: |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1217 | mutex_unlock(&priv->mutex); |
Wey-Yi Guy | 770c72c | 2011-10-10 07:27:10 -0700 | [diff] [blame] | 1218 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
| 1219 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1220 | return ret; |
| 1221 | } |
| 1222 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1223 | static void iwlagn_check_needed_chains(struct iwl_priv *priv, |
| 1224 | struct iwl_rxon_context *ctx, |
| 1225 | struct ieee80211_bss_conf *bss_conf) |
| 1226 | { |
| 1227 | struct ieee80211_vif *vif = ctx->vif; |
| 1228 | struct iwl_rxon_context *tmp; |
| 1229 | struct ieee80211_sta *sta; |
| 1230 | struct iwl_ht_config *ht_conf = &priv->current_ht_config; |
Johannes Berg | 850bedc | 2011-02-25 12:24:11 +0100 | [diff] [blame] | 1231 | struct ieee80211_sta_ht_cap *ht_cap; |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1232 | bool need_multiple; |
| 1233 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1234 | lockdep_assert_held(&priv->mutex); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1235 | |
| 1236 | switch (vif->type) { |
| 1237 | case NL80211_IFTYPE_STATION: |
| 1238 | rcu_read_lock(); |
| 1239 | sta = ieee80211_find_sta(vif, bss_conf->bssid); |
Johannes Berg | 850bedc | 2011-02-25 12:24:11 +0100 | [diff] [blame] | 1240 | if (!sta) { |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1241 | /* |
| 1242 | * If at all, this can only happen through a race |
| 1243 | * when the AP disconnects us while we're still |
| 1244 | * setting up the connection, in that case mac80211 |
| 1245 | * will soon tell us about that. |
| 1246 | */ |
| 1247 | need_multiple = false; |
Johannes Berg | 850bedc | 2011-02-25 12:24:11 +0100 | [diff] [blame] | 1248 | rcu_read_unlock(); |
| 1249 | break; |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1250 | } |
Johannes Berg | 850bedc | 2011-02-25 12:24:11 +0100 | [diff] [blame] | 1251 | |
| 1252 | ht_cap = &sta->ht_cap; |
| 1253 | |
| 1254 | need_multiple = true; |
| 1255 | |
| 1256 | /* |
| 1257 | * If the peer advertises no support for receiving 2 and 3 |
| 1258 | * stream MCS rates, it can't be transmitting them either. |
| 1259 | */ |
| 1260 | if (ht_cap->mcs.rx_mask[1] == 0 && |
| 1261 | ht_cap->mcs.rx_mask[2] == 0) { |
| 1262 | need_multiple = false; |
| 1263 | } else if (!(ht_cap->mcs.tx_params & |
| 1264 | IEEE80211_HT_MCS_TX_DEFINED)) { |
| 1265 | /* If it can't TX MCS at all ... */ |
| 1266 | need_multiple = false; |
| 1267 | } else if (ht_cap->mcs.tx_params & |
| 1268 | IEEE80211_HT_MCS_TX_RX_DIFF) { |
| 1269 | int maxstreams; |
| 1270 | |
| 1271 | /* |
| 1272 | * But if it can receive them, it might still not |
| 1273 | * be able to transmit them, which is what we need |
| 1274 | * to check here -- so check the number of streams |
| 1275 | * it advertises for TX (if different from RX). |
| 1276 | */ |
| 1277 | |
| 1278 | maxstreams = (ht_cap->mcs.tx_params & |
| 1279 | IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK); |
| 1280 | maxstreams >>= |
| 1281 | IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT; |
| 1282 | maxstreams += 1; |
| 1283 | |
| 1284 | if (maxstreams <= 1) |
| 1285 | need_multiple = false; |
| 1286 | } |
| 1287 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1288 | rcu_read_unlock(); |
| 1289 | break; |
| 1290 | case NL80211_IFTYPE_ADHOC: |
| 1291 | /* currently */ |
| 1292 | need_multiple = false; |
| 1293 | break; |
| 1294 | default: |
| 1295 | /* only AP really */ |
| 1296 | need_multiple = true; |
| 1297 | break; |
| 1298 | } |
| 1299 | |
| 1300 | ctx->ht_need_multiple_chains = need_multiple; |
| 1301 | |
| 1302 | if (!need_multiple) { |
| 1303 | /* check all contexts */ |
| 1304 | for_each_context(priv, tmp) { |
| 1305 | if (!tmp->vif) |
| 1306 | continue; |
| 1307 | if (tmp->ht_need_multiple_chains) { |
| 1308 | need_multiple = true; |
| 1309 | break; |
| 1310 | } |
| 1311 | } |
| 1312 | } |
| 1313 | |
| 1314 | ht_conf->single_chain_sufficient = !need_multiple; |
| 1315 | } |
| 1316 | |
Don Fry | 5c3d29f | 2011-07-08 08:46:29 -0700 | [diff] [blame] | 1317 | static void iwlagn_chain_noise_reset(struct iwl_priv *priv) |
| 1318 | { |
| 1319 | struct iwl_chain_noise_data *data = &priv->chain_noise_data; |
| 1320 | int ret; |
| 1321 | |
| 1322 | if ((data->state == IWL_CHAIN_NOISE_ALIVE) && |
| 1323 | iwl_is_any_associated(priv)) { |
| 1324 | struct iwl_calib_chain_noise_reset_cmd cmd; |
| 1325 | |
| 1326 | /* clear data for chain noise calibration algorithm */ |
| 1327 | data->chain_noise_a = 0; |
| 1328 | data->chain_noise_b = 0; |
| 1329 | data->chain_noise_c = 0; |
| 1330 | data->chain_signal_a = 0; |
| 1331 | data->chain_signal_b = 0; |
| 1332 | data->chain_signal_c = 0; |
| 1333 | data->beacon_count = 0; |
| 1334 | |
| 1335 | memset(&cmd, 0, sizeof(cmd)); |
| 1336 | iwl_set_calib_hdr(&cmd.hdr, |
Wey-Yi Guy | 898ed67 | 2011-07-13 08:38:57 -0700 | [diff] [blame] | 1337 | priv->phy_calib_chain_noise_reset_cmd); |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 1338 | ret = iwl_dvm_send_cmd_pdu(priv, |
Don Fry | 5c3d29f | 2011-07-08 08:46:29 -0700 | [diff] [blame] | 1339 | REPLY_PHY_CALIBRATION_CMD, |
| 1340 | CMD_SYNC, sizeof(cmd), &cmd); |
| 1341 | if (ret) |
| 1342 | IWL_ERR(priv, |
| 1343 | "Could not send REPLY_PHY_CALIBRATION_CMD\n"); |
| 1344 | data->state = IWL_CHAIN_NOISE_ACCUMULATE; |
| 1345 | IWL_DEBUG_CALIB(priv, "Run chain_noise_calibrate\n"); |
| 1346 | } |
| 1347 | } |
| 1348 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1349 | void iwlagn_bss_info_changed(struct ieee80211_hw *hw, |
| 1350 | struct ieee80211_vif *vif, |
| 1351 | struct ieee80211_bss_conf *bss_conf, |
| 1352 | u32 changes) |
| 1353 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1354 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1355 | struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif); |
| 1356 | int ret; |
| 1357 | bool force = false; |
| 1358 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1359 | mutex_lock(&priv->mutex); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1360 | |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 1361 | if (unlikely(!iwl_is_ready(priv))) { |
Wey-Yi Guy | 14a085e | 2010-12-14 07:38:58 -0800 | [diff] [blame] | 1362 | IWL_DEBUG_MAC80211(priv, "leave - not ready\n"); |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1363 | mutex_unlock(&priv->mutex); |
Shanyu Zhao | ae0b693 | 2010-12-02 11:02:28 -0800 | [diff] [blame] | 1364 | return; |
| 1365 | } |
| 1366 | |
| 1367 | if (unlikely(!ctx->vif)) { |
| 1368 | IWL_DEBUG_MAC80211(priv, "leave - vif is NULL\n"); |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1369 | mutex_unlock(&priv->mutex); |
Johannes Berg | 893654d | 2010-11-10 18:25:47 -0800 | [diff] [blame] | 1370 | return; |
| 1371 | } |
| 1372 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1373 | if (changes & BSS_CHANGED_BEACON_INT) |
| 1374 | force = true; |
| 1375 | |
| 1376 | if (changes & BSS_CHANGED_QOS) { |
| 1377 | ctx->qos_data.qos_active = bss_conf->qos; |
| 1378 | iwlagn_update_qos(priv, ctx); |
| 1379 | } |
| 1380 | |
| 1381 | ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid); |
| 1382 | if (vif->bss_conf.use_short_preamble) |
| 1383 | ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1384 | else |
| 1385 | ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1386 | |
| 1387 | if (changes & BSS_CHANGED_ASSOC) { |
| 1388 | if (bss_conf->assoc) { |
Johannes Berg | e9ac074 | 2012-03-13 14:29:30 +0100 | [diff] [blame] | 1389 | priv->timestamp = bss_conf->last_tsf; |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1390 | ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 1391 | } else { |
Garen Tamrazian | 68b9931 | 2011-03-30 02:29:32 -0700 | [diff] [blame] | 1392 | /* |
| 1393 | * If we disassociate while there are pending |
| 1394 | * frames, just wake up the queues and let the |
| 1395 | * frames "escape" ... This shouldn't really |
| 1396 | * be happening to start with, but we should |
| 1397 | * not get stuck in this case either since it |
| 1398 | * can happen if userspace gets confused. |
| 1399 | */ |
Johannes Berg | e755f88 | 2012-03-07 09:52:16 -0800 | [diff] [blame] | 1400 | iwlagn_lift_passive_no_rx(priv); |
| 1401 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1402 | ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Johannes Berg | c8ac61c | 2011-07-15 13:23:45 -0700 | [diff] [blame] | 1403 | |
| 1404 | if (ctx->ctxid == IWL_RXON_CTX_BSS) |
| 1405 | priv->have_rekey_data = false; |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1406 | } |
Meenakshi Venkataraman | 207ecc5 | 2011-07-08 08:46:23 -0700 | [diff] [blame] | 1407 | |
| 1408 | iwlagn_bt_coex_rssi_monitor(priv); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1409 | } |
| 1410 | |
| 1411 | if (ctx->ht.enabled) { |
| 1412 | ctx->ht.protection = bss_conf->ht_operation_mode & |
| 1413 | IEEE80211_HT_OP_MODE_PROTECTION; |
| 1414 | ctx->ht.non_gf_sta_present = !!(bss_conf->ht_operation_mode & |
| 1415 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT); |
| 1416 | iwlagn_check_needed_chains(priv, ctx, bss_conf); |
Johannes Berg | b2769b8 | 2010-11-10 09:56:47 -0800 | [diff] [blame] | 1417 | iwl_set_rxon_ht(priv, &priv->current_ht_config); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1418 | } |
| 1419 | |
Wey-Yi Guy | e3f10ce | 2011-07-01 07:59:26 -0700 | [diff] [blame] | 1420 | iwlagn_set_rxon_chain(priv, ctx); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1421 | |
| 1422 | if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ)) |
| 1423 | ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK; |
| 1424 | else |
| 1425 | ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK; |
| 1426 | |
| 1427 | if (bss_conf->use_cts_prot) |
| 1428 | ctx->staging.flags |= RXON_FLG_SELF_CTS_EN; |
| 1429 | else |
| 1430 | ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN; |
| 1431 | |
| 1432 | memcpy(ctx->staging.bssid_addr, bss_conf->bssid, ETH_ALEN); |
| 1433 | |
| 1434 | if (vif->type == NL80211_IFTYPE_AP || |
| 1435 | vif->type == NL80211_IFTYPE_ADHOC) { |
| 1436 | if (vif->bss_conf.enable_beacon) { |
| 1437 | ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 1438 | priv->beacon_ctx = ctx; |
| 1439 | } else { |
| 1440 | ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 1441 | priv->beacon_ctx = NULL; |
| 1442 | } |
| 1443 | } |
| 1444 | |
Meenakshi Venkataraman | 758f555 | 2012-02-08 12:04:41 -0800 | [diff] [blame] | 1445 | /* |
| 1446 | * If the ucode decides to do beacon filtering before |
| 1447 | * association, it will lose beacons that are needed |
| 1448 | * before sending frames out on passive channels. This |
| 1449 | * causes association failures on those channels. Enable |
| 1450 | * receiving beacons in such cases. |
| 1451 | */ |
| 1452 | |
| 1453 | if (vif->type == NL80211_IFTYPE_STATION) { |
| 1454 | if (!bss_conf->assoc) |
| 1455 | ctx->staging.filter_flags |= RXON_FILTER_BCON_AWARE_MSK; |
| 1456 | else |
| 1457 | ctx->staging.filter_flags &= |
| 1458 | ~RXON_FILTER_BCON_AWARE_MSK; |
| 1459 | } |
| 1460 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1461 | if (force || memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging))) |
| 1462 | iwlagn_commit_rxon(priv, ctx); |
| 1463 | |
Johannes Berg | 8da8e62 | 2010-11-10 09:56:46 -0800 | [diff] [blame] | 1464 | if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) { |
| 1465 | /* |
| 1466 | * The chain noise calibration will enable PM upon |
| 1467 | * completion. If calibration has already been run |
| 1468 | * then we need to enable power management here. |
| 1469 | */ |
| 1470 | if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE) |
| 1471 | iwl_power_update_mode(priv, false); |
| 1472 | |
| 1473 | /* Enable RX differential gain and sensitivity calibrations */ |
Don Fry | 5c3d29f | 2011-07-08 08:46:29 -0700 | [diff] [blame] | 1474 | if (!priv->disable_chain_noise_cal) |
| 1475 | iwlagn_chain_noise_reset(priv); |
Johannes Berg | 8da8e62 | 2010-11-10 09:56:46 -0800 | [diff] [blame] | 1476 | priv->start_calib = 1; |
| 1477 | } |
| 1478 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1479 | if (changes & BSS_CHANGED_IBSS) { |
| 1480 | ret = iwlagn_manage_ibss_station(priv, vif, |
| 1481 | bss_conf->ibss_joined); |
| 1482 | if (ret) |
| 1483 | IWL_ERR(priv, "failed to %s IBSS station %pM\n", |
| 1484 | bss_conf->ibss_joined ? "add" : "remove", |
| 1485 | bss_conf->bssid); |
| 1486 | } |
| 1487 | |
Johannes Berg | bd50a8ab | 2010-10-23 09:15:42 -0700 | [diff] [blame] | 1488 | if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_ADHOC && |
| 1489 | priv->beacon_ctx) { |
| 1490 | if (iwlagn_update_beacon(priv, vif)) |
| 1491 | IWL_ERR(priv, "Error sending IBSS beacon\n"); |
| 1492 | } |
| 1493 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1494 | mutex_unlock(&priv->mutex); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1495 | } |
Johannes Berg | ae79d23 | 2010-11-10 09:56:38 -0800 | [diff] [blame] | 1496 | |
| 1497 | void iwlagn_post_scan(struct iwl_priv *priv) |
| 1498 | { |
| 1499 | struct iwl_rxon_context *ctx; |
| 1500 | |
| 1501 | /* |
Wey-Yi Guy | c2b821d | 2011-06-03 07:54:14 -0700 | [diff] [blame] | 1502 | * We do not commit power settings while scan is pending, |
| 1503 | * do it now if the settings changed. |
| 1504 | */ |
| 1505 | iwl_power_set_mode(priv, &priv->power_data.sleep_cmd_next, false); |
| 1506 | iwl_set_tx_power(priv, priv->tx_power_next, false); |
| 1507 | |
| 1508 | /* |
Johannes Berg | ae79d23 | 2010-11-10 09:56:38 -0800 | [diff] [blame] | 1509 | * Since setting the RXON may have been deferred while |
| 1510 | * performing the scan, fire one off if needed |
| 1511 | */ |
| 1512 | for_each_context(priv, ctx) |
| 1513 | if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging))) |
| 1514 | iwlagn_commit_rxon(priv, ctx); |
| 1515 | |
Wey-Yi Guy | e3f10ce | 2011-07-01 07:59:26 -0700 | [diff] [blame] | 1516 | iwlagn_set_pan_params(priv); |
Johannes Berg | ae79d23 | 2010-11-10 09:56:38 -0800 | [diff] [blame] | 1517 | } |