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