Tomas Winkler | df48c32 | 2008-03-06 10:40:19 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Tomas Winkler | df48c32 | 2008-03-06 10:40:19 -0800 | [diff] [blame] | 3 | * GPL LICENSE SUMMARY |
| 4 | * |
Wey-Yi Guy | 4e31826 | 2011-12-27 11:21:32 -0800 | [diff] [blame] | 5 | * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved. |
Tomas Winkler | df48c32 | 2008-03-06 10:40:19 -0800 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of version 2 of the GNU General Public License as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 19 | * USA |
| 20 | * |
| 21 | * The full GNU General Public License is included in this distribution |
| 22 | * in the file called LICENSE.GPL. |
| 23 | * |
| 24 | * Contact Information: |
Winkler, Tomas | 759ef89 | 2008-12-09 11:28:58 -0800 | [diff] [blame] | 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
Tomas Winkler | df48c32 | 2008-03-06 10:40:19 -0800 | [diff] [blame] | 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | *****************************************************************************/ |
| 28 | |
| 29 | #include <linux/kernel.h> |
| 30 | #include <linux/module.h> |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 31 | #include <linux/etherdevice.h> |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 32 | #include <linux/sched.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 33 | #include <linux/slab.h> |
Assaf Krauss | 1d0a082 | 2008-03-14 10:38:48 -0700 | [diff] [blame] | 34 | #include <net/mac80211.h> |
Tomas Winkler | df48c32 | 2008-03-06 10:40:19 -0800 | [diff] [blame] | 35 | |
Assaf Krauss | 6bc913b | 2008-03-11 16:17:18 -0700 | [diff] [blame] | 36 | #include "iwl-eeprom.h" |
Winkler, Tomas | 19335774 | 2008-11-07 09:58:36 -0800 | [diff] [blame] | 37 | #include "iwl-debug.h" |
Tomas Winkler | df48c32 | 2008-03-06 10:40:19 -0800 | [diff] [blame] | 38 | #include "iwl-core.h" |
Tomas Winkler | b661c81 | 2008-04-23 17:14:54 -0700 | [diff] [blame] | 39 | #include "iwl-io.h" |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 40 | #include "iwl-power.h" |
Emmanuel Grumbach | 48f20d3 | 2011-08-25 23:10:36 -0700 | [diff] [blame] | 41 | #include "iwl-shared.h" |
Don Fry | 9d143e9 | 2011-04-20 15:23:57 -0700 | [diff] [blame] | 42 | #include "iwl-agn.h" |
Emmanuel Grumbach | bdfbf09 | 2011-07-08 08:46:16 -0700 | [diff] [blame] | 43 | #include "iwl-trans.h" |
Tomas Winkler | df48c32 | 2008-03-06 10:40:19 -0800 | [diff] [blame] | 44 | |
Tomas Winkler | 57bd1be | 2008-05-15 13:54:03 +0800 | [diff] [blame] | 45 | const u8 iwl_bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; |
Tomas Winkler | 57bd1be | 2008-05-15 13:54:03 +0800 | [diff] [blame] | 46 | |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 47 | #define MAX_BIT_RATE_40_MHZ 150 /* Mbps */ |
| 48 | #define MAX_BIT_RATE_20_MHZ 72 /* Mbps */ |
Wey-Yi Guy | b39488a | 2011-08-25 23:10:33 -0700 | [diff] [blame] | 49 | static void iwl_init_ht_hw_capab(const struct iwl_priv *priv, |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 50 | struct ieee80211_sta_ht_cap *ht_info, |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 51 | enum ieee80211_band band) |
| 52 | { |
Ron Rindjunsky | 39130df | 2008-05-15 13:53:56 +0800 | [diff] [blame] | 53 | u16 max_bit_rate = 0; |
Emmanuel Grumbach | d618912 | 2011-08-25 23:10:39 -0700 | [diff] [blame] | 54 | u8 rx_chains_num = hw_params(priv).rx_chains_num; |
| 55 | u8 tx_chains_num = hw_params(priv).tx_chains_num; |
Ron Rindjunsky | 39130df | 2008-05-15 13:53:56 +0800 | [diff] [blame] | 56 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 57 | ht_info->cap = 0; |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 58 | memset(&ht_info->mcs, 0, sizeof(ht_info->mcs)); |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 59 | |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 60 | ht_info->ht_supported = true; |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 61 | |
Don Fry | 3862241 | 2011-12-16 07:07:36 -0800 | [diff] [blame] | 62 | if (cfg(priv)->ht_params && |
| 63 | cfg(priv)->ht_params->ht_greenfield_support) |
Daniel C Halperin | b261793 | 2009-08-13 13:30:59 -0700 | [diff] [blame] | 64 | ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD; |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 65 | ht_info->cap |= IEEE80211_HT_CAP_SGI_20; |
Ron Rindjunsky | 39130df | 2008-05-15 13:53:56 +0800 | [diff] [blame] | 66 | max_bit_rate = MAX_BIT_RATE_20_MHZ; |
Emmanuel Grumbach | d618912 | 2011-08-25 23:10:39 -0700 | [diff] [blame] | 67 | if (hw_params(priv).ht40_channel & BIT(band)) { |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 68 | ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 69 | ht_info->cap |= IEEE80211_HT_CAP_SGI_40; |
| 70 | ht_info->mcs.rx_mask[4] = 0x01; |
Ron Rindjunsky | 39130df | 2008-05-15 13:53:56 +0800 | [diff] [blame] | 71 | max_bit_rate = MAX_BIT_RATE_40_MHZ; |
| 72 | } |
| 73 | |
Don Fry | 9d143e9 | 2011-04-20 15:23:57 -0700 | [diff] [blame] | 74 | if (iwlagn_mod_params.amsdu_size_8K) |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 75 | ht_info->cap |= IEEE80211_HT_CAP_MAX_AMSDU; |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 76 | |
| 77 | ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF; |
| 78 | ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF; |
| 79 | |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 80 | ht_info->mcs.rx_mask[0] = 0xFF; |
Ron Rindjunsky | 39130df | 2008-05-15 13:53:56 +0800 | [diff] [blame] | 81 | if (rx_chains_num >= 2) |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 82 | ht_info->mcs.rx_mask[1] = 0xFF; |
Ron Rindjunsky | 39130df | 2008-05-15 13:53:56 +0800 | [diff] [blame] | 83 | if (rx_chains_num >= 3) |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 84 | ht_info->mcs.rx_mask[2] = 0xFF; |
Ron Rindjunsky | 39130df | 2008-05-15 13:53:56 +0800 | [diff] [blame] | 85 | |
| 86 | /* Highest supported Rx data rate */ |
| 87 | max_bit_rate *= rx_chains_num; |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 88 | WARN_ON(max_bit_rate & ~IEEE80211_HT_MCS_RX_HIGHEST_MASK); |
| 89 | ht_info->mcs.rx_highest = cpu_to_le16(max_bit_rate); |
Ron Rindjunsky | 39130df | 2008-05-15 13:53:56 +0800 | [diff] [blame] | 90 | |
| 91 | /* Tx MCS capabilities */ |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 92 | ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; |
Ron Rindjunsky | 39130df | 2008-05-15 13:53:56 +0800 | [diff] [blame] | 93 | if (tx_chains_num != rx_chains_num) { |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 94 | ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF; |
| 95 | ht_info->mcs.tx_params |= ((tx_chains_num - 1) << |
| 96 | IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT); |
Ron Rindjunsky | 39130df | 2008-05-15 13:53:56 +0800 | [diff] [blame] | 97 | } |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 98 | } |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 99 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 100 | /** |
Wey-Yi Guy | b39488a | 2011-08-25 23:10:33 -0700 | [diff] [blame] | 101 | * iwl_init_geos - Initialize mac80211's geo/channel info based from eeprom |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 102 | */ |
Wey-Yi Guy | b39488a | 2011-08-25 23:10:33 -0700 | [diff] [blame] | 103 | int iwl_init_geos(struct iwl_priv *priv) |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 104 | { |
| 105 | struct iwl_channel_info *ch; |
| 106 | struct ieee80211_supported_band *sband; |
| 107 | struct ieee80211_channel *channels; |
| 108 | struct ieee80211_channel *geo_ch; |
| 109 | struct ieee80211_rate *rates; |
| 110 | int i = 0; |
Stanislaw Gruszka | 75d80ca | 2011-04-28 11:12:10 +0200 | [diff] [blame] | 111 | s8 max_tx_power = IWLAGN_TX_POWER_TARGET_POWER_MIN; |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 112 | |
| 113 | if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates || |
| 114 | priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 115 | IWL_DEBUG_INFO(priv, "Geography modes already initialized.\n"); |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 116 | set_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status); |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 117 | return 0; |
| 118 | } |
| 119 | |
Emmanuel Grumbach | 7f90dce | 2011-09-22 15:14:53 -0700 | [diff] [blame] | 120 | channels = kcalloc(priv->channel_count, |
| 121 | sizeof(struct ieee80211_channel), GFP_KERNEL); |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 122 | if (!channels) |
| 123 | return -ENOMEM; |
| 124 | |
Emmanuel Grumbach | 7f90dce | 2011-09-22 15:14:53 -0700 | [diff] [blame] | 125 | rates = kcalloc(IWL_RATE_COUNT_LEGACY, sizeof(struct ieee80211_rate), |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 126 | GFP_KERNEL); |
| 127 | if (!rates) { |
| 128 | kfree(channels); |
| 129 | return -ENOMEM; |
| 130 | } |
| 131 | |
| 132 | /* 5.2GHz channels start after the 2.4GHz channels */ |
| 133 | sband = &priv->bands[IEEE80211_BAND_5GHZ]; |
| 134 | sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)]; |
| 135 | /* just OFDM */ |
| 136 | sband->bitrates = &rates[IWL_FIRST_OFDM_RATE]; |
Daniel C Halperin | 5027309 | 2009-08-28 09:44:45 -0700 | [diff] [blame] | 137 | sband->n_bitrates = IWL_RATE_COUNT_LEGACY - IWL_FIRST_OFDM_RATE; |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 138 | |
Johannes Berg | 54708d8 | 2012-03-05 11:24:31 -0800 | [diff] [blame] | 139 | if (hw_params(priv).sku & EEPROM_SKU_CAP_11N_ENABLE) |
Wey-Yi Guy | b39488a | 2011-08-25 23:10:33 -0700 | [diff] [blame] | 140 | iwl_init_ht_hw_capab(priv, &sband->ht_cap, |
Ron Rindjunsky | 4977929 | 2008-06-30 17:23:21 +0800 | [diff] [blame] | 141 | IEEE80211_BAND_5GHZ); |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 142 | |
| 143 | sband = &priv->bands[IEEE80211_BAND_2GHZ]; |
| 144 | sband->channels = channels; |
| 145 | /* OFDM & CCK */ |
| 146 | sband->bitrates = rates; |
Daniel C Halperin | 5027309 | 2009-08-28 09:44:45 -0700 | [diff] [blame] | 147 | sband->n_bitrates = IWL_RATE_COUNT_LEGACY; |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 148 | |
Johannes Berg | 54708d8 | 2012-03-05 11:24:31 -0800 | [diff] [blame] | 149 | if (hw_params(priv).sku & EEPROM_SKU_CAP_11N_ENABLE) |
Wey-Yi Guy | b39488a | 2011-08-25 23:10:33 -0700 | [diff] [blame] | 150 | iwl_init_ht_hw_capab(priv, &sband->ht_cap, |
Ron Rindjunsky | 4977929 | 2008-06-30 17:23:21 +0800 | [diff] [blame] | 151 | IEEE80211_BAND_2GHZ); |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 152 | |
| 153 | priv->ieee_channels = channels; |
| 154 | priv->ieee_rates = rates; |
| 155 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 156 | for (i = 0; i < priv->channel_count; i++) { |
| 157 | ch = &priv->channel_info[i]; |
| 158 | |
| 159 | /* FIXME: might be removed if scan is OK */ |
| 160 | if (!is_channel_valid(ch)) |
| 161 | continue; |
| 162 | |
Stanislaw Gruszka | 5a3a035 | 2011-01-31 13:01:35 +0100 | [diff] [blame] | 163 | sband = &priv->bands[ch->band]; |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 164 | |
| 165 | geo_ch = &sband->channels[sband->n_channels++]; |
| 166 | |
| 167 | geo_ch->center_freq = |
Stanislaw Gruszka | 5a3a035 | 2011-01-31 13:01:35 +0100 | [diff] [blame] | 168 | ieee80211_channel_to_frequency(ch->channel, ch->band); |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 169 | geo_ch->max_power = ch->max_power_avg; |
| 170 | geo_ch->max_antenna_gain = 0xff; |
| 171 | geo_ch->hw_value = ch->channel; |
| 172 | |
| 173 | if (is_channel_valid(ch)) { |
| 174 | if (!(ch->flags & EEPROM_CHANNEL_IBSS)) |
| 175 | geo_ch->flags |= IEEE80211_CHAN_NO_IBSS; |
| 176 | |
| 177 | if (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) |
| 178 | geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN; |
| 179 | |
| 180 | if (ch->flags & EEPROM_CHANNEL_RADAR) |
| 181 | geo_ch->flags |= IEEE80211_CHAN_RADAR; |
| 182 | |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 183 | geo_ch->flags |= ch->ht40_extension_channel; |
Emmanuel Grumbach | 4d38c2e | 2008-05-29 16:35:24 +0800 | [diff] [blame] | 184 | |
Stanislaw Gruszka | 75d80ca | 2011-04-28 11:12:10 +0200 | [diff] [blame] | 185 | if (ch->max_power_avg > max_tx_power) |
| 186 | max_tx_power = ch->max_power_avg; |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 187 | } else { |
| 188 | geo_ch->flags |= IEEE80211_CHAN_DISABLED; |
| 189 | } |
| 190 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 191 | IWL_DEBUG_INFO(priv, "Channel %d Freq=%d[%sGHz] %s flag=0x%X\n", |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 192 | ch->channel, geo_ch->center_freq, |
| 193 | is_channel_a_band(ch) ? "5.2" : "2.4", |
| 194 | geo_ch->flags & IEEE80211_CHAN_DISABLED ? |
| 195 | "restricted" : "valid", |
| 196 | geo_ch->flags); |
| 197 | } |
| 198 | |
Stanislaw Gruszka | 75d80ca | 2011-04-28 11:12:10 +0200 | [diff] [blame] | 199 | priv->tx_power_device_lmt = max_tx_power; |
| 200 | priv->tx_power_user_lmt = max_tx_power; |
| 201 | priv->tx_power_next = max_tx_power; |
| 202 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 203 | if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) && |
Johannes Berg | 54708d8 | 2012-03-05 11:24:31 -0800 | [diff] [blame] | 204 | hw_params(priv).sku & EEPROM_SKU_CAP_BAND_52GHZ) { |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 205 | IWL_INFO(priv, "Incorrectly detected BG card as ABG. " |
Emmanuel Grumbach | 9ca8596 | 2012-01-08 21:19:45 +0200 | [diff] [blame] | 206 | "Please send your %s to maintainer.\n", |
| 207 | trans(priv)->hw_id_str); |
Johannes Berg | 54708d8 | 2012-03-05 11:24:31 -0800 | [diff] [blame] | 208 | hw_params(priv).sku &= ~EEPROM_SKU_CAP_BAND_52GHZ; |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 211 | IWL_INFO(priv, "Tunable channels: %d 802.11bg, %d 802.11a channels\n", |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 212 | priv->bands[IEEE80211_BAND_2GHZ].n_channels, |
| 213 | priv->bands[IEEE80211_BAND_5GHZ].n_channels); |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 214 | |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 215 | set_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status); |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | /* |
Wey-Yi Guy | b39488a | 2011-08-25 23:10:33 -0700 | [diff] [blame] | 221 | * iwl_free_geos - undo allocations in iwl_init_geos |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 222 | */ |
Wey-Yi Guy | b39488a | 2011-08-25 23:10:33 -0700 | [diff] [blame] | 223 | void iwl_free_geos(struct iwl_priv *priv) |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 224 | { |
| 225 | kfree(priv->ieee_channels); |
| 226 | kfree(priv->ieee_rates); |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 227 | clear_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status); |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 228 | } |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 229 | |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 230 | static bool iwl_is_channel_extension(struct iwl_priv *priv, |
| 231 | enum ieee80211_band band, |
| 232 | u16 channel, u8 extension_chan_offset) |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 233 | { |
| 234 | const struct iwl_channel_info *ch_info; |
| 235 | |
| 236 | ch_info = iwl_get_channel_info(priv, band, channel); |
| 237 | if (!is_channel_valid(ch_info)) |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 238 | return false; |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 239 | |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 240 | if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE) |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 241 | return !(ch_info->ht40_extension_channel & |
Luis R. Rodriguez | 689da1b | 2009-05-02 00:37:18 -0400 | [diff] [blame] | 242 | IEEE80211_CHAN_NO_HT40PLUS); |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 243 | else if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_BELOW) |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 244 | return !(ch_info->ht40_extension_channel & |
Luis R. Rodriguez | 689da1b | 2009-05-02 00:37:18 -0400 | [diff] [blame] | 245 | IEEE80211_CHAN_NO_HT40MINUS); |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 246 | |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 247 | return false; |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 248 | } |
| 249 | |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 250 | bool iwl_is_ht40_tx_allowed(struct iwl_priv *priv, |
| 251 | struct iwl_rxon_context *ctx, |
| 252 | struct ieee80211_sta_ht_cap *ht_cap) |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 253 | { |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 254 | if (!ctx->ht.enabled || !ctx->ht.is_40mhz) |
| 255 | return false; |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 256 | |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 257 | /* |
| 258 | * We do not check for IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
Wey-Yi Guy | a2b0f02 | 2009-05-22 11:01:49 -0700 | [diff] [blame] | 259 | * the bit will not set if it is pure 40MHz case |
| 260 | */ |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 261 | if (ht_cap && !ht_cap->ht_supported) |
| 262 | return false; |
| 263 | |
Johannes Berg | d73e492 | 2010-05-06 12:18:41 -0700 | [diff] [blame] | 264 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
Wey-Yi Guy | 1e4247d | 2009-07-27 13:50:15 -0700 | [diff] [blame] | 265 | if (priv->disable_ht40) |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 266 | return false; |
Wey-Yi Guy | 1e4247d | 2009-07-27 13:50:15 -0700 | [diff] [blame] | 267 | #endif |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 268 | |
Wey-Yi Guy | 611d3eb | 2009-06-12 13:22:51 -0700 | [diff] [blame] | 269 | return iwl_is_channel_extension(priv, priv->band, |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 270 | le16_to_cpu(ctx->staging.channel), |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 271 | ctx->ht.extension_chan_offset); |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 272 | } |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 273 | |
Tomas Winkler | 2c2f3b3 | 2009-06-19 13:52:45 -0700 | [diff] [blame] | 274 | static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val) |
| 275 | { |
Johannes Berg | ea196fd | 2010-09-03 06:30:55 -0700 | [diff] [blame] | 276 | u16 new_val; |
| 277 | u16 beacon_factor; |
| 278 | |
| 279 | /* |
| 280 | * If mac80211 hasn't given us a beacon interval, program |
| 281 | * the default into the device (not checking this here |
| 282 | * would cause the adjustment below to return the maximum |
| 283 | * value, which may break PAN.) |
| 284 | */ |
| 285 | if (!beacon_val) |
| 286 | return DEFAULT_BEACON_INTERVAL; |
| 287 | |
| 288 | /* |
| 289 | * If the beacon interval we obtained from the peer |
| 290 | * is too large, we'll have to wake up more often |
| 291 | * (and in IBSS case, we'll beacon too much) |
| 292 | * |
| 293 | * For example, if max_beacon_val is 4096, and the |
| 294 | * requested beacon interval is 7000, we'll have to |
| 295 | * use 3500 to be able to wake up on the beacons. |
| 296 | * |
| 297 | * This could badly influence beacon detection stats. |
| 298 | */ |
Tomas Winkler | 2c2f3b3 | 2009-06-19 13:52:45 -0700 | [diff] [blame] | 299 | |
| 300 | beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val; |
| 301 | new_val = beacon_val / beacon_factor; |
| 302 | |
| 303 | if (!new_val) |
| 304 | new_val = max_beacon_val; |
| 305 | |
| 306 | return new_val; |
| 307 | } |
| 308 | |
Johannes Berg | 47313e3 | 2010-08-23 10:46:55 +0200 | [diff] [blame] | 309 | int iwl_send_rxon_timing(struct iwl_priv *priv, struct iwl_rxon_context *ctx) |
Tomas Winkler | 2c2f3b3 | 2009-06-19 13:52:45 -0700 | [diff] [blame] | 310 | { |
| 311 | u64 tsf; |
| 312 | s32 interval_tm, rem; |
Tomas Winkler | 2c2f3b3 | 2009-06-19 13:52:45 -0700 | [diff] [blame] | 313 | struct ieee80211_conf *conf = NULL; |
| 314 | u16 beacon_int; |
Johannes Berg | 47313e3 | 2010-08-23 10:46:55 +0200 | [diff] [blame] | 315 | struct ieee80211_vif *vif = ctx->vif; |
Tomas Winkler | 2c2f3b3 | 2009-06-19 13:52:45 -0700 | [diff] [blame] | 316 | |
Emmanuel Grumbach | 8c22254 | 2011-10-10 07:27:16 -0700 | [diff] [blame] | 317 | conf = &priv->hw->conf; |
Tomas Winkler | 2c2f3b3 | 2009-06-19 13:52:45 -0700 | [diff] [blame] | 318 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 319 | lockdep_assert_held(&priv->mutex); |
Johannes Berg | 948f5a2 | 2010-07-29 07:07:51 -0700 | [diff] [blame] | 320 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 321 | memset(&ctx->timing, 0, sizeof(struct iwl_rxon_time_cmd)); |
Johannes Berg | 948f5a2 | 2010-07-29 07:07:51 -0700 | [diff] [blame] | 322 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 323 | ctx->timing.timestamp = cpu_to_le64(priv->timestamp); |
| 324 | ctx->timing.listen_interval = cpu_to_le16(conf->listen_interval); |
Tomas Winkler | 2c2f3b3 | 2009-06-19 13:52:45 -0700 | [diff] [blame] | 325 | |
Johannes Berg | 47313e3 | 2010-08-23 10:46:55 +0200 | [diff] [blame] | 326 | beacon_int = vif ? vif->bss_conf.beacon_int : 0; |
Tomas Winkler | 2c2f3b3 | 2009-06-19 13:52:45 -0700 | [diff] [blame] | 327 | |
Johannes Berg | 47313e3 | 2010-08-23 10:46:55 +0200 | [diff] [blame] | 328 | /* |
| 329 | * TODO: For IBSS we need to get atim_window from mac80211, |
| 330 | * for now just always use 0 |
| 331 | */ |
| 332 | ctx->timing.atim_window = 0; |
Tomas Winkler | 2c2f3b3 | 2009-06-19 13:52:45 -0700 | [diff] [blame] | 333 | |
Johannes Berg | bde4530 | 2010-08-23 10:46:57 +0200 | [diff] [blame] | 334 | if (ctx->ctxid == IWL_RXON_CTX_PAN && |
Johannes Berg | f1f270b | 2010-09-03 06:31:26 -0700 | [diff] [blame] | 335 | (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION) && |
| 336 | iwl_is_associated(priv, IWL_RXON_CTX_BSS) && |
| 337 | priv->contexts[IWL_RXON_CTX_BSS].vif && |
| 338 | priv->contexts[IWL_RXON_CTX_BSS].vif->bss_conf.beacon_int) { |
Johannes Berg | bde4530 | 2010-08-23 10:46:57 +0200 | [diff] [blame] | 339 | ctx->timing.beacon_interval = |
| 340 | priv->contexts[IWL_RXON_CTX_BSS].timing.beacon_interval; |
| 341 | beacon_int = le16_to_cpu(ctx->timing.beacon_interval); |
Johannes Berg | f1f270b | 2010-09-03 06:31:26 -0700 | [diff] [blame] | 342 | } else if (ctx->ctxid == IWL_RXON_CTX_BSS && |
| 343 | iwl_is_associated(priv, IWL_RXON_CTX_PAN) && |
| 344 | priv->contexts[IWL_RXON_CTX_PAN].vif && |
| 345 | priv->contexts[IWL_RXON_CTX_PAN].vif->bss_conf.beacon_int && |
| 346 | (!iwl_is_associated_ctx(ctx) || !ctx->vif || |
| 347 | !ctx->vif->bss_conf.beacon_int)) { |
| 348 | ctx->timing.beacon_interval = |
| 349 | priv->contexts[IWL_RXON_CTX_PAN].timing.beacon_interval; |
| 350 | beacon_int = le16_to_cpu(ctx->timing.beacon_interval); |
Johannes Berg | bde4530 | 2010-08-23 10:46:57 +0200 | [diff] [blame] | 351 | } else { |
| 352 | beacon_int = iwl_adjust_beacon_interval(beacon_int, |
Emmanuel Grumbach | ab9e212 | 2011-08-25 23:11:10 -0700 | [diff] [blame] | 353 | IWL_MAX_UCODE_BEACON_INTERVAL * TIME_UNIT); |
Johannes Berg | bde4530 | 2010-08-23 10:46:57 +0200 | [diff] [blame] | 354 | ctx->timing.beacon_interval = cpu_to_le16(beacon_int); |
| 355 | } |
Tomas Winkler | 2c2f3b3 | 2009-06-19 13:52:45 -0700 | [diff] [blame] | 356 | |
Johannes Berg | bbb05cb | 2011-07-18 01:59:22 -0700 | [diff] [blame] | 357 | ctx->beacon_int = beacon_int; |
| 358 | |
Tomas Winkler | 2c2f3b3 | 2009-06-19 13:52:45 -0700 | [diff] [blame] | 359 | tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */ |
Wey-Yi Guy | f8525e5 | 2010-05-05 11:31:38 -0700 | [diff] [blame] | 360 | interval_tm = beacon_int * TIME_UNIT; |
Tomas Winkler | 2c2f3b3 | 2009-06-19 13:52:45 -0700 | [diff] [blame] | 361 | rem = do_div(tsf, interval_tm); |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 362 | ctx->timing.beacon_init_val = cpu_to_le32(interval_tm - rem); |
Tomas Winkler | 2c2f3b3 | 2009-06-19 13:52:45 -0700 | [diff] [blame] | 363 | |
Johannes Berg | 47313e3 | 2010-08-23 10:46:55 +0200 | [diff] [blame] | 364 | ctx->timing.dtim_period = vif ? (vif->bss_conf.dtim_period ?: 1) : 1; |
Johannes Berg | 2491fa4 | 2010-08-23 10:46:52 +0200 | [diff] [blame] | 365 | |
Tomas Winkler | 2c2f3b3 | 2009-06-19 13:52:45 -0700 | [diff] [blame] | 366 | IWL_DEBUG_ASSOC(priv, |
| 367 | "beacon interval %d beacon timer %d beacon tim %d\n", |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 368 | le16_to_cpu(ctx->timing.beacon_interval), |
| 369 | le32_to_cpu(ctx->timing.beacon_init_val), |
| 370 | le16_to_cpu(ctx->timing.atim_window)); |
Johannes Berg | 948f5a2 | 2010-07-29 07:07:51 -0700 | [diff] [blame] | 371 | |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 372 | return iwl_dvm_send_cmd_pdu(priv, ctx->rxon_timing_cmd, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 373 | CMD_SYNC, sizeof(ctx->timing), &ctx->timing); |
Tomas Winkler | 2c2f3b3 | 2009-06-19 13:52:45 -0700 | [diff] [blame] | 374 | } |
Tomas Winkler | 2c2f3b3 | 2009-06-19 13:52:45 -0700 | [diff] [blame] | 375 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 376 | void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, struct iwl_rxon_context *ctx, |
| 377 | int hw_decrypt) |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 378 | { |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 379 | struct iwl_rxon_cmd *rxon = &ctx->staging; |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 380 | |
| 381 | if (hw_decrypt) |
| 382 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; |
| 383 | else |
| 384 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; |
| 385 | |
| 386 | } |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 387 | |
Johannes Berg | dacefed | 2010-10-07 04:02:03 -0700 | [diff] [blame] | 388 | /* validate RXON structure is valid */ |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 389 | int iwl_check_rxon_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx) |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 390 | { |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 391 | struct iwl_rxon_cmd *rxon = &ctx->staging; |
Johannes Berg | c914ac2 | 2011-04-21 10:57:23 -0700 | [diff] [blame] | 392 | u32 errors = 0; |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 393 | |
| 394 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { |
Johannes Berg | dacefed | 2010-10-07 04:02:03 -0700 | [diff] [blame] | 395 | if (rxon->flags & RXON_FLG_TGJ_NARROW_BAND_MSK) { |
| 396 | IWL_WARN(priv, "check 2.4G: wrong narrow\n"); |
Johannes Berg | c914ac2 | 2011-04-21 10:57:23 -0700 | [diff] [blame] | 397 | errors |= BIT(0); |
Johannes Berg | dacefed | 2010-10-07 04:02:03 -0700 | [diff] [blame] | 398 | } |
| 399 | if (rxon->flags & RXON_FLG_RADAR_DETECT_MSK) { |
| 400 | IWL_WARN(priv, "check 2.4G: wrong radar\n"); |
Johannes Berg | c914ac2 | 2011-04-21 10:57:23 -0700 | [diff] [blame] | 401 | errors |= BIT(1); |
Johannes Berg | dacefed | 2010-10-07 04:02:03 -0700 | [diff] [blame] | 402 | } |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 403 | } else { |
Johannes Berg | dacefed | 2010-10-07 04:02:03 -0700 | [diff] [blame] | 404 | if (!(rxon->flags & RXON_FLG_SHORT_SLOT_MSK)) { |
| 405 | IWL_WARN(priv, "check 5.2G: not short slot!\n"); |
Johannes Berg | c914ac2 | 2011-04-21 10:57:23 -0700 | [diff] [blame] | 406 | errors |= BIT(2); |
Johannes Berg | dacefed | 2010-10-07 04:02:03 -0700 | [diff] [blame] | 407 | } |
| 408 | if (rxon->flags & RXON_FLG_CCK_MSK) { |
| 409 | IWL_WARN(priv, "check 5.2G: CCK!\n"); |
Johannes Berg | c914ac2 | 2011-04-21 10:57:23 -0700 | [diff] [blame] | 410 | errors |= BIT(3); |
Johannes Berg | dacefed | 2010-10-07 04:02:03 -0700 | [diff] [blame] | 411 | } |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 412 | } |
Johannes Berg | dacefed | 2010-10-07 04:02:03 -0700 | [diff] [blame] | 413 | if ((rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1) { |
| 414 | IWL_WARN(priv, "mac/bssid mcast!\n"); |
Johannes Berg | c914ac2 | 2011-04-21 10:57:23 -0700 | [diff] [blame] | 415 | errors |= BIT(4); |
Johannes Berg | dacefed | 2010-10-07 04:02:03 -0700 | [diff] [blame] | 416 | } |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 417 | |
| 418 | /* make sure basic rates 6Mbps and 1Mbps are supported */ |
Johannes Berg | dacefed | 2010-10-07 04:02:03 -0700 | [diff] [blame] | 419 | if ((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0 && |
| 420 | (rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0) { |
| 421 | IWL_WARN(priv, "neither 1 nor 6 are basic\n"); |
Johannes Berg | c914ac2 | 2011-04-21 10:57:23 -0700 | [diff] [blame] | 422 | errors |= BIT(5); |
Johannes Berg | dacefed | 2010-10-07 04:02:03 -0700 | [diff] [blame] | 423 | } |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 424 | |
Johannes Berg | dacefed | 2010-10-07 04:02:03 -0700 | [diff] [blame] | 425 | if (le16_to_cpu(rxon->assoc_id) > 2007) { |
| 426 | IWL_WARN(priv, "aid > 2007\n"); |
Johannes Berg | c914ac2 | 2011-04-21 10:57:23 -0700 | [diff] [blame] | 427 | errors |= BIT(6); |
Johannes Berg | dacefed | 2010-10-07 04:02:03 -0700 | [diff] [blame] | 428 | } |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 429 | |
Johannes Berg | dacefed | 2010-10-07 04:02:03 -0700 | [diff] [blame] | 430 | if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) |
| 431 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) { |
| 432 | IWL_WARN(priv, "CCK and short slot\n"); |
Johannes Berg | c914ac2 | 2011-04-21 10:57:23 -0700 | [diff] [blame] | 433 | errors |= BIT(7); |
Johannes Berg | dacefed | 2010-10-07 04:02:03 -0700 | [diff] [blame] | 434 | } |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 435 | |
Johannes Berg | dacefed | 2010-10-07 04:02:03 -0700 | [diff] [blame] | 436 | if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) |
| 437 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) { |
| 438 | IWL_WARN(priv, "CCK and auto detect"); |
Johannes Berg | c914ac2 | 2011-04-21 10:57:23 -0700 | [diff] [blame] | 439 | errors |= BIT(8); |
Johannes Berg | dacefed | 2010-10-07 04:02:03 -0700 | [diff] [blame] | 440 | } |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 441 | |
Johannes Berg | dacefed | 2010-10-07 04:02:03 -0700 | [diff] [blame] | 442 | if ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | |
| 443 | RXON_FLG_TGG_PROTECT_MSK)) == |
| 444 | RXON_FLG_TGG_PROTECT_MSK) { |
| 445 | IWL_WARN(priv, "TGg but no auto-detect\n"); |
Johannes Berg | c914ac2 | 2011-04-21 10:57:23 -0700 | [diff] [blame] | 446 | errors |= BIT(9); |
Johannes Berg | dacefed | 2010-10-07 04:02:03 -0700 | [diff] [blame] | 447 | } |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 448 | |
Johannes Berg | c914ac2 | 2011-04-21 10:57:23 -0700 | [diff] [blame] | 449 | if (rxon->channel == 0) { |
| 450 | IWL_WARN(priv, "zero channel is invalid\n"); |
| 451 | errors |= BIT(10); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 452 | } |
Johannes Berg | c914ac2 | 2011-04-21 10:57:23 -0700 | [diff] [blame] | 453 | |
| 454 | WARN(errors, "Invalid RXON (%#x), channel %d", |
| 455 | errors, le16_to_cpu(rxon->channel)); |
| 456 | |
| 457 | return errors ? -EINVAL : 0; |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 458 | } |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 459 | |
| 460 | /** |
| 461 | * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed |
| 462 | * @priv: staging_rxon is compared to active_rxon |
| 463 | * |
| 464 | * If the RXON structure is changing enough to require a new tune, |
| 465 | * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that |
| 466 | * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required. |
| 467 | */ |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 468 | int iwl_full_rxon_required(struct iwl_priv *priv, |
| 469 | struct iwl_rxon_context *ctx) |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 470 | { |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 471 | const struct iwl_rxon_cmd *staging = &ctx->staging; |
| 472 | const struct iwl_rxon_cmd *active = &ctx->active; |
| 473 | |
| 474 | #define CHK(cond) \ |
| 475 | if ((cond)) { \ |
| 476 | IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \ |
| 477 | return 1; \ |
| 478 | } |
| 479 | |
| 480 | #define CHK_NEQ(c1, c2) \ |
| 481 | if ((c1) != (c2)) { \ |
| 482 | IWL_DEBUG_INFO(priv, "need full RXON - " \ |
| 483 | #c1 " != " #c2 " - %d != %d\n", \ |
| 484 | (c1), (c2)); \ |
| 485 | return 1; \ |
| 486 | } |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 487 | |
| 488 | /* These items are only settable from the full RXON command */ |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 489 | CHK(!iwl_is_associated_ctx(ctx)); |
| 490 | CHK(compare_ether_addr(staging->bssid_addr, active->bssid_addr)); |
| 491 | CHK(compare_ether_addr(staging->node_addr, active->node_addr)); |
| 492 | CHK(compare_ether_addr(staging->wlap_bssid_addr, |
| 493 | active->wlap_bssid_addr)); |
| 494 | CHK_NEQ(staging->dev_type, active->dev_type); |
| 495 | CHK_NEQ(staging->channel, active->channel); |
| 496 | CHK_NEQ(staging->air_propagation, active->air_propagation); |
| 497 | CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates, |
| 498 | active->ofdm_ht_single_stream_basic_rates); |
| 499 | CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates, |
| 500 | active->ofdm_ht_dual_stream_basic_rates); |
| 501 | CHK_NEQ(staging->ofdm_ht_triple_stream_basic_rates, |
| 502 | active->ofdm_ht_triple_stream_basic_rates); |
| 503 | CHK_NEQ(staging->assoc_id, active->assoc_id); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 504 | |
| 505 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can |
| 506 | * be updated with the RXON_ASSOC command -- however only some |
| 507 | * flag transitions are allowed using RXON_ASSOC */ |
| 508 | |
| 509 | /* Check if we are not switching bands */ |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 510 | CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK, |
| 511 | active->flags & RXON_FLG_BAND_24G_MSK); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 512 | |
| 513 | /* Check if we are switching association toggle */ |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 514 | CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK, |
| 515 | active->filter_flags & RXON_FILTER_ASSOC_MSK); |
| 516 | |
| 517 | #undef CHK |
| 518 | #undef CHK_NEQ |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 519 | |
| 520 | return 0; |
| 521 | } |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 522 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 523 | static void _iwl_set_rxon_ht(struct iwl_priv *priv, |
| 524 | struct iwl_ht_config *ht_conf, |
| 525 | struct iwl_rxon_context *ctx) |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 526 | { |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 527 | struct iwl_rxon_cmd *rxon = &ctx->staging; |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 528 | |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 529 | if (!ctx->ht.enabled) { |
Wey-Yi Guy | a2b0f02 | 2009-05-22 11:01:49 -0700 | [diff] [blame] | 530 | rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK | |
Emmanuel Grumbach | 42eb7c6 | 2008-09-17 10:10:05 +0800 | [diff] [blame] | 531 | RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK | |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 532 | RXON_FLG_HT40_PROT_MSK | |
Emmanuel Grumbach | 42eb7c6 | 2008-09-17 10:10:05 +0800 | [diff] [blame] | 533 | RXON_FLG_HT_PROT_MSK); |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 534 | return; |
Emmanuel Grumbach | 42eb7c6 | 2008-09-17 10:10:05 +0800 | [diff] [blame] | 535 | } |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 536 | |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 537 | /* FIXME: if the definition of ht.protection changed, the "translation" |
Wey-Yi Guy | a2b0f02 | 2009-05-22 11:01:49 -0700 | [diff] [blame] | 538 | * will be needed for rxon->flags |
| 539 | */ |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 540 | rxon->flags |= cpu_to_le32(ctx->ht.protection << RXON_FLG_HT_OPERATING_MODE_POS); |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 541 | |
Wey-Yi Guy | a2b0f02 | 2009-05-22 11:01:49 -0700 | [diff] [blame] | 542 | /* Set up channel bandwidth: |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 543 | * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */ |
Wey-Yi Guy | a2b0f02 | 2009-05-22 11:01:49 -0700 | [diff] [blame] | 544 | /* clear the HT channel mode before set the mode */ |
| 545 | rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK | |
| 546 | RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK); |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 547 | if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) { |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 548 | /* pure ht40 */ |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 549 | if (ctx->ht.protection == IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) { |
Wey-Yi Guy | a2b0f02 | 2009-05-22 11:01:49 -0700 | [diff] [blame] | 550 | rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40; |
Wey-Yi Guy | 508b08e | 2009-06-12 13:22:50 -0700 | [diff] [blame] | 551 | /* Note: control channel is opposite of extension channel */ |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 552 | switch (ctx->ht.extension_chan_offset) { |
Wey-Yi Guy | 508b08e | 2009-06-12 13:22:50 -0700 | [diff] [blame] | 553 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: |
| 554 | rxon->flags &= ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK; |
| 555 | break; |
| 556 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: |
| 557 | rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK; |
| 558 | break; |
| 559 | } |
| 560 | } else { |
Wey-Yi Guy | a2b0f02 | 2009-05-22 11:01:49 -0700 | [diff] [blame] | 561 | /* Note: control channel is opposite of extension channel */ |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 562 | switch (ctx->ht.extension_chan_offset) { |
Wey-Yi Guy | a2b0f02 | 2009-05-22 11:01:49 -0700 | [diff] [blame] | 563 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: |
| 564 | rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK); |
| 565 | rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED; |
| 566 | break; |
| 567 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: |
| 568 | rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK; |
| 569 | rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED; |
| 570 | break; |
| 571 | case IEEE80211_HT_PARAM_CHA_SEC_NONE: |
| 572 | default: |
| 573 | /* channel location only valid if in Mixed mode */ |
| 574 | IWL_ERR(priv, "invalid extension channel offset\n"); |
| 575 | break; |
| 576 | } |
| 577 | } |
| 578 | } else { |
| 579 | rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY; |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 580 | } |
| 581 | |
Wey-Yi Guy | e3f10ce | 2011-07-01 07:59:26 -0700 | [diff] [blame] | 582 | iwlagn_set_rxon_chain(priv, ctx); |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 583 | |
Johannes Berg | 02bb1be | 2009-09-11 10:38:17 -0700 | [diff] [blame] | 584 | IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X " |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 585 | "extension channel offset 0x%x\n", |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 586 | le32_to_cpu(rxon->flags), ctx->ht.protection, |
| 587 | ctx->ht.extension_chan_offset); |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 588 | } |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 589 | |
| 590 | void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf) |
| 591 | { |
| 592 | struct iwl_rxon_context *ctx; |
| 593 | |
| 594 | for_each_context(priv, ctx) |
| 595 | _iwl_set_rxon_ht(priv, ht_conf, ctx); |
| 596 | } |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 597 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 598 | /* Return valid, unused, channel for a passive scan to reset the RF */ |
Abhijeet Kolekar | 1402364 | 2010-06-02 21:15:10 -0700 | [diff] [blame] | 599 | u8 iwl_get_single_channel_number(struct iwl_priv *priv, |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 600 | enum ieee80211_band band) |
Abhijeet Kolekar | 1402364 | 2010-06-02 21:15:10 -0700 | [diff] [blame] | 601 | { |
| 602 | const struct iwl_channel_info *ch_info; |
| 603 | int i; |
| 604 | u8 channel = 0; |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 605 | u8 min, max; |
| 606 | struct iwl_rxon_context *ctx; |
Abhijeet Kolekar | 1402364 | 2010-06-02 21:15:10 -0700 | [diff] [blame] | 607 | |
Abhijeet Kolekar | 1402364 | 2010-06-02 21:15:10 -0700 | [diff] [blame] | 608 | if (band == IEEE80211_BAND_5GHZ) { |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 609 | min = 14; |
| 610 | max = priv->channel_count; |
Abhijeet Kolekar | 1402364 | 2010-06-02 21:15:10 -0700 | [diff] [blame] | 611 | } else { |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 612 | min = 0; |
| 613 | max = 14; |
| 614 | } |
| 615 | |
| 616 | for (i = min; i < max; i++) { |
| 617 | bool busy = false; |
| 618 | |
| 619 | for_each_context(priv, ctx) { |
| 620 | busy = priv->channel_info[i].channel == |
| 621 | le16_to_cpu(ctx->staging.channel); |
| 622 | if (busy) |
| 623 | break; |
Abhijeet Kolekar | 1402364 | 2010-06-02 21:15:10 -0700 | [diff] [blame] | 624 | } |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 625 | |
| 626 | if (busy) |
| 627 | continue; |
| 628 | |
| 629 | channel = priv->channel_info[i].channel; |
| 630 | ch_info = iwl_get_channel_info(priv, band, channel); |
| 631 | if (is_channel_valid(ch_info)) |
| 632 | break; |
Abhijeet Kolekar | 1402364 | 2010-06-02 21:15:10 -0700 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | return channel; |
| 636 | } |
Abhijeet Kolekar | 1402364 | 2010-06-02 21:15:10 -0700 | [diff] [blame] | 637 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 638 | /** |
Shanyu Zhao | 3edb5fd | 2010-07-27 20:45:15 -0700 | [diff] [blame] | 639 | * iwl_set_rxon_channel - Set the band and channel values in staging RXON |
| 640 | * @ch: requested channel as a pointer to struct ieee80211_channel |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 641 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 642 | * NOTE: Does not commit to the hardware; it sets appropriate bit fields |
Shanyu Zhao | 3edb5fd | 2010-07-27 20:45:15 -0700 | [diff] [blame] | 643 | * in the staging RXON flag structure based on the ch->band |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 644 | */ |
Wey-Yi Guy | dd63b84 | 2012-02-08 15:57:39 -0800 | [diff] [blame] | 645 | void iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch, |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 646 | struct iwl_rxon_context *ctx) |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 647 | { |
Tomas Winkler | 17e7278 | 2008-09-03 11:26:26 +0800 | [diff] [blame] | 648 | enum ieee80211_band band = ch->band; |
Shanyu Zhao | 81e9543 | 2010-07-28 13:40:27 -0700 | [diff] [blame] | 649 | u16 channel = ch->hw_value; |
Tomas Winkler | 17e7278 | 2008-09-03 11:26:26 +0800 | [diff] [blame] | 650 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 651 | if ((le16_to_cpu(ctx->staging.channel) == channel) && |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 652 | (priv->band == band)) |
Wey-Yi Guy | dd63b84 | 2012-02-08 15:57:39 -0800 | [diff] [blame] | 653 | return; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 654 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 655 | ctx->staging.channel = cpu_to_le16(channel); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 656 | if (band == IEEE80211_BAND_5GHZ) |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 657 | ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 658 | else |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 659 | ctx->staging.flags |= RXON_FLG_BAND_24G_MSK; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 660 | |
| 661 | priv->band = band; |
| 662 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 663 | IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 664 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 665 | } |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 666 | |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 667 | void iwl_set_flags_for_band(struct iwl_priv *priv, |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 668 | struct iwl_rxon_context *ctx, |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 669 | enum ieee80211_band band, |
| 670 | struct ieee80211_vif *vif) |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 671 | { |
| 672 | if (band == IEEE80211_BAND_5GHZ) { |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 673 | ctx->staging.flags &= |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 674 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
| 675 | | RXON_FLG_CCK_MSK); |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 676 | ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK; |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 677 | } else { |
| 678 | /* Copied from iwl_post_associate() */ |
Johannes Berg | c213d74 | 2010-05-06 12:21:40 -0700 | [diff] [blame] | 679 | if (vif && vif->bss_conf.use_short_slot) |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 680 | ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK; |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 681 | else |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 682 | ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 683 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 684 | ctx->staging.flags |= RXON_FLG_BAND_24G_MSK; |
| 685 | ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK; |
| 686 | ctx->staging.flags &= ~RXON_FLG_CCK_MSK; |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 687 | } |
| 688 | } |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 689 | |
| 690 | /* |
| 691 | * initialize rxon structure with default values from eeprom |
| 692 | */ |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 693 | void iwl_connection_init_rx_config(struct iwl_priv *priv, |
Johannes Berg | d0fe478 | 2010-08-23 10:46:58 +0200 | [diff] [blame] | 694 | struct iwl_rxon_context *ctx) |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 695 | { |
| 696 | const struct iwl_channel_info *ch_info; |
| 697 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 698 | memset(&ctx->staging, 0, sizeof(ctx->staging)); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 699 | |
Johannes Berg | d0fe478 | 2010-08-23 10:46:58 +0200 | [diff] [blame] | 700 | if (!ctx->vif) { |
| 701 | ctx->staging.dev_type = ctx->unused_devtype; |
| 702 | } else switch (ctx->vif->type) { |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 703 | case NL80211_IFTYPE_AP: |
Johannes Berg | d0fe478 | 2010-08-23 10:46:58 +0200 | [diff] [blame] | 704 | ctx->staging.dev_type = ctx->ap_devtype; |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 705 | break; |
| 706 | |
| 707 | case NL80211_IFTYPE_STATION: |
Johannes Berg | d0fe478 | 2010-08-23 10:46:58 +0200 | [diff] [blame] | 708 | ctx->staging.dev_type = ctx->station_devtype; |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 709 | ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 710 | break; |
| 711 | |
| 712 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | d0fe478 | 2010-08-23 10:46:58 +0200 | [diff] [blame] | 713 | ctx->staging.dev_type = ctx->ibss_devtype; |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 714 | ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
| 715 | ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 716 | RXON_FILTER_ACCEPT_GRP_MSK; |
| 717 | break; |
| 718 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 719 | default: |
Johannes Berg | d0fe478 | 2010-08-23 10:46:58 +0200 | [diff] [blame] | 720 | IWL_ERR(priv, "Unsupported interface type %d\n", |
| 721 | ctx->vif->type); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 722 | break; |
| 723 | } |
| 724 | |
| 725 | #if 0 |
| 726 | /* TODO: Figure out when short_preamble would be set and cache from |
| 727 | * that */ |
| 728 | if (!hw_to_local(priv->hw)->short_preamble) |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 729 | ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 730 | else |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 731 | ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 732 | #endif |
| 733 | |
| 734 | ch_info = iwl_get_channel_info(priv, priv->band, |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 735 | le16_to_cpu(ctx->active.channel)); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 736 | |
| 737 | if (!ch_info) |
| 738 | ch_info = &priv->channel_info[0]; |
| 739 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 740 | ctx->staging.channel = cpu_to_le16(ch_info->channel); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 741 | priv->band = ch_info->band; |
| 742 | |
Johannes Berg | d0fe478 | 2010-08-23 10:46:58 +0200 | [diff] [blame] | 743 | iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 744 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 745 | ctx->staging.ofdm_basic_rates = |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 746 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 747 | ctx->staging.cck_basic_rates = |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 748 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 749 | |
Wey-Yi Guy | a2b0f02 | 2009-05-22 11:01:49 -0700 | [diff] [blame] | 750 | /* clear both MIX and PURE40 mode flag */ |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 751 | ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED | |
Wey-Yi Guy | a2b0f02 | 2009-05-22 11:01:49 -0700 | [diff] [blame] | 752 | RXON_FLG_CHANNEL_MODE_PURE_40); |
Johannes Berg | d0fe478 | 2010-08-23 10:46:58 +0200 | [diff] [blame] | 753 | if (ctx->vif) |
| 754 | memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN); |
Johannes Berg | 7684c40 | 2010-05-12 03:33:11 -0700 | [diff] [blame] | 755 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 756 | ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff; |
| 757 | ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff; |
| 758 | ctx->staging.ofdm_ht_triple_stream_basic_rates = 0xff; |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 759 | } |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 760 | |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 761 | void iwl_set_rate(struct iwl_priv *priv) |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 762 | { |
| 763 | const struct ieee80211_supported_band *hw = NULL; |
| 764 | struct ieee80211_rate *rate; |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 765 | struct iwl_rxon_context *ctx; |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 766 | int i; |
| 767 | |
| 768 | hw = iwl_get_hw_mode(priv, priv->band); |
| 769 | if (!hw) { |
| 770 | IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n"); |
| 771 | return; |
| 772 | } |
| 773 | |
| 774 | priv->active_rate = 0; |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 775 | |
| 776 | for (i = 0; i < hw->n_bitrates; i++) { |
| 777 | rate = &(hw->bitrates[i]); |
Daniel C Halperin | 5027309 | 2009-08-28 09:44:45 -0700 | [diff] [blame] | 778 | if (rate->hw_value < IWL_RATE_COUNT_LEGACY) |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 779 | priv->active_rate |= (1 << rate->hw_value); |
| 780 | } |
| 781 | |
Johannes Berg | 4a02886 | 2010-01-21 11:33:19 -0800 | [diff] [blame] | 782 | IWL_DEBUG_RATE(priv, "Set active_rate = %0x\n", priv->active_rate); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 783 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 784 | for_each_context(priv, ctx) { |
| 785 | ctx->staging.cck_basic_rates = |
| 786 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 787 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 788 | ctx->staging.ofdm_basic_rates = |
| 789 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 790 | } |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 791 | } |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 792 | |
| 793 | void iwl_chswitch_done(struct iwl_priv *priv, bool is_success) |
| 794 | { |
Johannes Berg | 8bd413e | 2010-08-23 10:46:40 +0200 | [diff] [blame] | 795 | /* |
| 796 | * MULTI-FIXME |
Wey-Yi Guy | ade4c64 | 2011-10-10 07:27:11 -0700 | [diff] [blame] | 797 | * See iwlagn_mac_channel_switch. |
Johannes Berg | 8bd413e | 2010-08-23 10:46:40 +0200 | [diff] [blame] | 798 | */ |
| 799 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; |
| 800 | |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 801 | if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status)) |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 802 | return; |
| 803 | |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 804 | if (test_and_clear_bit(STATUS_CHANNEL_SWITCH_PENDING, |
| 805 | &priv->shrd->status)) |
Johannes Berg | 8bd413e | 2010-08-23 10:46:40 +0200 | [diff] [blame] | 806 | ieee80211_chswitch_done(ctx->vif, is_success); |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 807 | } |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 808 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 809 | #ifdef CONFIG_IWLWIFI_DEBUG |
Emmanuel Grumbach | 14991a9 | 2011-09-15 11:46:32 -0700 | [diff] [blame] | 810 | void iwl_print_rx_config_cmd(struct iwl_priv *priv, |
| 811 | enum iwl_rxon_context_id ctxid) |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 812 | { |
Emmanuel Grumbach | 522376d | 2011-09-06 09:31:19 -0700 | [diff] [blame] | 813 | struct iwl_rxon_context *ctx = &priv->contexts[ctxid]; |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 814 | struct iwl_rxon_cmd *rxon = &ctx->staging; |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 815 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 816 | IWL_DEBUG_RADIO(priv, "RX CONFIG:\n"); |
Reinette Chatre | 3d816c7 | 2009-08-07 15:41:37 -0700 | [diff] [blame] | 817 | iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 818 | IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); |
| 819 | IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); |
| 820 | IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n", |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 821 | le32_to_cpu(rxon->filter_flags)); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 822 | IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type); |
| 823 | IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n", |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 824 | rxon->ofdm_basic_rates); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 825 | IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates); |
| 826 | IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr); |
| 827 | IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr); |
| 828 | IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id)); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 829 | } |
Reinette Chatre | 6686d17 | 2009-07-24 11:13:13 -0700 | [diff] [blame] | 830 | #endif |
Johannes Berg | e649437 | 2011-04-05 09:41:58 -0700 | [diff] [blame] | 831 | |
Emmanuel Grumbach | bcb9321 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 832 | static void iwlagn_fw_error(struct iwl_priv *priv, bool ondemand) |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 833 | { |
Wey-Yi Guy | 491bc29 | 2011-02-09 09:37:46 -0800 | [diff] [blame] | 834 | unsigned int reload_msec; |
| 835 | unsigned long reload_jiffies; |
| 836 | |
Emmanuel Grumbach | 3e6895c | 2012-02-15 12:48:04 +0200 | [diff] [blame] | 837 | #ifdef CONFIG_IWLWIFI_DEBUG |
Johannes Berg | a8bceb3 | 2012-03-05 11:24:30 -0800 | [diff] [blame] | 838 | if (iwl_have_debug_level(IWL_DL_FW_ERRORS)) |
Emmanuel Grumbach | 3e6895c | 2012-02-15 12:48:04 +0200 | [diff] [blame] | 839 | iwl_print_rx_config_cmd(priv, IWL_RXON_CTX_BSS); |
| 840 | #endif |
| 841 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 842 | /* Set the FW error flag -- cleared on iwl_down */ |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 843 | set_bit(STATUS_FW_ERROR, &priv->shrd->status); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 844 | |
| 845 | /* Cancel currently queued command. */ |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 846 | clear_bit(STATUS_HCMD_ACTIVE, &priv->shrd->status); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 847 | |
Johannes Berg | 4bd14dd | 2012-03-06 13:30:58 -0800 | [diff] [blame] | 848 | iwl_abort_notification_waits(&priv->notif_wait); |
Johannes Berg | e74fe23 | 2011-04-13 03:14:49 -0700 | [diff] [blame] | 849 | |
Johannes Berg | e649437 | 2011-04-05 09:41:58 -0700 | [diff] [blame] | 850 | /* Keep the restart process from trying to send host |
| 851 | * commands by clearing the ready bit */ |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 852 | clear_bit(STATUS_READY, &priv->shrd->status); |
Johannes Berg | e649437 | 2011-04-05 09:41:58 -0700 | [diff] [blame] | 853 | |
Johannes Berg | effd4d9 | 2011-09-15 11:46:52 -0700 | [diff] [blame] | 854 | wake_up(&priv->shrd->wait_command_queue); |
Johannes Berg | e649437 | 2011-04-05 09:41:58 -0700 | [diff] [blame] | 855 | |
| 856 | if (!ondemand) { |
| 857 | /* |
| 858 | * If firmware keep reloading, then it indicate something |
| 859 | * serious wrong and firmware having problem to recover |
| 860 | * from it. Instead of keep trying which will fill the syslog |
| 861 | * and hang the system, let's just stop it |
| 862 | */ |
| 863 | reload_jiffies = jiffies; |
| 864 | reload_msec = jiffies_to_msecs((long) reload_jiffies - |
| 865 | (long) priv->reload_jiffies); |
| 866 | priv->reload_jiffies = reload_jiffies; |
| 867 | if (reload_msec <= IWL_MIN_RELOAD_DURATION) { |
| 868 | priv->reload_count++; |
| 869 | if (priv->reload_count >= IWL_MAX_CONTINUE_RELOAD_CNT) { |
| 870 | IWL_ERR(priv, "BUG_ON, Stop restarting\n"); |
| 871 | return; |
| 872 | } |
| 873 | } else |
| 874 | priv->reload_count = 0; |
| 875 | } |
| 876 | |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 877 | if (!test_bit(STATUS_EXIT_PENDING, &priv->shrd->status)) { |
Don Fry | 9d143e9 | 2011-04-20 15:23:57 -0700 | [diff] [blame] | 878 | if (iwlagn_mod_params.restart_fw) { |
Emmanuel Grumbach | 9ca06f0 | 2011-08-25 23:10:46 -0700 | [diff] [blame] | 879 | IWL_DEBUG_FW_ERRORS(priv, |
Johannes Berg | e649437 | 2011-04-05 09:41:58 -0700 | [diff] [blame] | 880 | "Restarting adapter due to uCode error.\n"); |
Johannes Berg | 1ee158d | 2012-02-17 10:07:44 -0800 | [diff] [blame] | 881 | queue_work(priv->workqueue, &priv->restart); |
Johannes Berg | e649437 | 2011-04-05 09:41:58 -0700 | [diff] [blame] | 882 | } else |
Emmanuel Grumbach | 9ca06f0 | 2011-08-25 23:10:46 -0700 | [diff] [blame] | 883 | IWL_DEBUG_FW_ERRORS(priv, |
Johannes Berg | e649437 | 2011-04-05 09:41:58 -0700 | [diff] [blame] | 884 | "Detected FW error, but not restarting\n"); |
| 885 | } |
| 886 | } |
| 887 | |
Tomas Winkler | 630fe9b | 2008-06-12 09:47:08 +0800 | [diff] [blame] | 888 | int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force) |
| 889 | { |
Stanislaw Gruszka | a25a66a | 2010-10-22 17:04:26 +0200 | [diff] [blame] | 890 | int ret; |
| 891 | s8 prev_tx_power; |
Stanislaw Gruszka | f844a70 | 2011-01-28 16:47:44 +0100 | [diff] [blame] | 892 | bool defer; |
| 893 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; |
Stanislaw Gruszka | a25a66a | 2010-10-22 17:04:26 +0200 | [diff] [blame] | 894 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 895 | lockdep_assert_held(&priv->mutex); |
Stanislaw Gruszka | a25a66a | 2010-10-22 17:04:26 +0200 | [diff] [blame] | 896 | |
| 897 | if (priv->tx_power_user_lmt == tx_power && !force) |
| 898 | return 0; |
| 899 | |
Wey-Yi Guy | b744cb7 | 2010-03-23 11:37:59 -0700 | [diff] [blame] | 900 | if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) { |
| 901 | IWL_WARN(priv, |
| 902 | "Requested user TXPOWER %d below lower limit %d.\n", |
Wu, Fengguang | daf518d | 2009-02-13 11:51:17 -0800 | [diff] [blame] | 903 | tx_power, |
Wey-Yi Guy | b744cb7 | 2010-03-23 11:37:59 -0700 | [diff] [blame] | 904 | IWLAGN_TX_POWER_TARGET_POWER_MIN); |
Tomas Winkler | 630fe9b | 2008-06-12 09:47:08 +0800 | [diff] [blame] | 905 | return -EINVAL; |
| 906 | } |
| 907 | |
Wey-Yi Guy | dc1b097 | 2009-08-21 13:34:16 -0700 | [diff] [blame] | 908 | if (tx_power > priv->tx_power_device_lmt) { |
Wey-Yi Guy | 08f2d58 | 2009-08-21 13:34:15 -0700 | [diff] [blame] | 909 | IWL_WARN(priv, |
| 910 | "Requested user TXPOWER %d above upper limit %d.\n", |
Wey-Yi Guy | dc1b097 | 2009-08-21 13:34:16 -0700 | [diff] [blame] | 911 | tx_power, priv->tx_power_device_lmt); |
Tomas Winkler | 630fe9b | 2008-06-12 09:47:08 +0800 | [diff] [blame] | 912 | return -EINVAL; |
| 913 | } |
| 914 | |
Emmanuel Grumbach | 845a9c0 | 2011-08-25 23:11:04 -0700 | [diff] [blame] | 915 | if (!iwl_is_ready_rf(priv->shrd)) |
Stanislaw Gruszka | a25a66a | 2010-10-22 17:04:26 +0200 | [diff] [blame] | 916 | return -EIO; |
Tomas Winkler | 630fe9b | 2008-06-12 09:47:08 +0800 | [diff] [blame] | 917 | |
Stanislaw Gruszka | f844a70 | 2011-01-28 16:47:44 +0100 | [diff] [blame] | 918 | /* scan complete and commit_rxon use tx_power_next value, |
| 919 | * it always need to be updated for newest request */ |
Stanislaw Gruszka | a25a66a | 2010-10-22 17:04:26 +0200 | [diff] [blame] | 920 | priv->tx_power_next = tx_power; |
Stanislaw Gruszka | f844a70 | 2011-01-28 16:47:44 +0100 | [diff] [blame] | 921 | |
| 922 | /* do not set tx power when scanning or channel changing */ |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 923 | defer = test_bit(STATUS_SCANNING, &priv->shrd->status) || |
Stanislaw Gruszka | f844a70 | 2011-01-28 16:47:44 +0100 | [diff] [blame] | 924 | memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging)); |
| 925 | if (defer && !force) { |
| 926 | IWL_DEBUG_INFO(priv, "Deferring tx power set\n"); |
Stanislaw Gruszka | a25a66a | 2010-10-22 17:04:26 +0200 | [diff] [blame] | 927 | return 0; |
Wey-Yi Guy | 5eadd94 | 2009-08-21 13:34:17 -0700 | [diff] [blame] | 928 | } |
Mohamed Abbas | 019fb97 | 2009-03-17 21:59:18 -0700 | [diff] [blame] | 929 | |
Stanislaw Gruszka | a25a66a | 2010-10-22 17:04:26 +0200 | [diff] [blame] | 930 | prev_tx_power = priv->tx_power_user_lmt; |
| 931 | priv->tx_power_user_lmt = tx_power; |
| 932 | |
Wey-Yi Guy | 5beaaf3 | 2011-05-27 08:40:25 -0700 | [diff] [blame] | 933 | ret = iwlagn_send_tx_power(priv); |
Stanislaw Gruszka | a25a66a | 2010-10-22 17:04:26 +0200 | [diff] [blame] | 934 | |
| 935 | /* if fail to set tx_power, restore the orig. tx power */ |
| 936 | if (ret) { |
| 937 | priv->tx_power_user_lmt = prev_tx_power; |
| 938 | priv->tx_power_next = prev_tx_power; |
| 939 | } |
Tomas Winkler | 630fe9b | 2008-06-12 09:47:08 +0800 | [diff] [blame] | 940 | return ret; |
| 941 | } |
Tomas Winkler | 630fe9b | 2008-06-12 09:47:08 +0800 | [diff] [blame] | 942 | |
Johannes Berg | 65b52bd | 2010-04-13 01:04:31 -0700 | [diff] [blame] | 943 | void iwl_send_bt_config(struct iwl_priv *priv) |
Samuel Ortiz | 17f841c | 2009-01-23 13:45:20 -0800 | [diff] [blame] | 944 | { |
| 945 | struct iwl_bt_cmd bt_cmd = { |
Wey-Yi Guy | 456d0f7 | 2009-10-23 13:42:23 -0700 | [diff] [blame] | 946 | .lead_time = BT_LEAD_TIME_DEF, |
| 947 | .max_kill = BT_MAX_KILL_DEF, |
Samuel Ortiz | 17f841c | 2009-01-23 13:45:20 -0800 | [diff] [blame] | 948 | .kill_ack_mask = 0, |
| 949 | .kill_cts_mask = 0, |
| 950 | }; |
| 951 | |
Wey-Yi Guy | b60eec9 | 2011-06-03 13:52:38 -0700 | [diff] [blame] | 952 | if (!iwlagn_mod_params.bt_coex_active) |
Wey-Yi Guy | 06702a7 | 2010-01-22 14:22:51 -0800 | [diff] [blame] | 953 | bt_cmd.flags = BT_COEX_DISABLE; |
| 954 | else |
| 955 | bt_cmd.flags = BT_COEX_ENABLE; |
| 956 | |
Wey-Yi Guy | f21dd00 | 2010-12-08 15:34:52 -0800 | [diff] [blame] | 957 | priv->bt_enable_flag = bt_cmd.flags; |
Wey-Yi Guy | 06702a7 | 2010-01-22 14:22:51 -0800 | [diff] [blame] | 958 | IWL_DEBUG_INFO(priv, "BT coex %s\n", |
| 959 | (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active"); |
| 960 | |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 961 | if (iwl_dvm_send_cmd_pdu(priv, REPLY_BT_CONFIG, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 962 | CMD_SYNC, sizeof(struct iwl_bt_cmd), &bt_cmd)) |
Johannes Berg | 65b52bd | 2010-04-13 01:04:31 -0700 | [diff] [blame] | 963 | IWL_ERR(priv, "failed to send BT Coex Config\n"); |
Samuel Ortiz | 17f841c | 2009-01-23 13:45:20 -0800 | [diff] [blame] | 964 | } |
Samuel Ortiz | 17f841c | 2009-01-23 13:45:20 -0800 | [diff] [blame] | 965 | |
Wey-Yi Guy | ef8d552 | 2009-11-13 11:56:28 -0800 | [diff] [blame] | 966 | int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear) |
Emmanuel Grumbach | 49ea859 | 2008-04-15 16:01:37 -0700 | [diff] [blame] | 967 | { |
Wey-Yi Guy | ef8d552 | 2009-11-13 11:56:28 -0800 | [diff] [blame] | 968 | struct iwl_statistics_cmd statistics_cmd = { |
| 969 | .configuration_flags = |
| 970 | clear ? IWL_STATS_CONF_CLEAR_STATS : 0, |
Emmanuel Grumbach | 49ea859 | 2008-04-15 16:01:37 -0700 | [diff] [blame] | 971 | }; |
Wey-Yi Guy | ef8d552 | 2009-11-13 11:56:28 -0800 | [diff] [blame] | 972 | |
| 973 | if (flags & CMD_ASYNC) |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 974 | return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 975 | CMD_ASYNC, |
Wey-Yi Guy | ef8d552 | 2009-11-13 11:56:28 -0800 | [diff] [blame] | 976 | sizeof(struct iwl_statistics_cmd), |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 977 | &statistics_cmd); |
Wey-Yi Guy | ef8d552 | 2009-11-13 11:56:28 -0800 | [diff] [blame] | 978 | else |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 979 | return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 980 | CMD_SYNC, |
Wey-Yi Guy | ef8d552 | 2009-11-13 11:56:28 -0800 | [diff] [blame] | 981 | sizeof(struct iwl_statistics_cmd), |
| 982 | &statistics_cmd); |
Emmanuel Grumbach | 49ea859 | 2008-04-15 16:01:37 -0700 | [diff] [blame] | 983 | } |
Tomas Winkler | 7e8c519 | 2008-04-15 16:01:43 -0700 | [diff] [blame] | 984 | |
Abhijeet Kolekar | 488829f | 2009-03-26 10:14:10 -0700 | [diff] [blame] | 985 | |
Johannes Berg | df912e5 | 2011-11-10 06:55:12 -0800 | [diff] [blame] | 986 | |
Abhijeet Kolekar | d805231 | 2009-04-08 11:26:47 -0700 | [diff] [blame] | 987 | |
Wey-Yi Guy | 20594eb | 2009-08-07 15:41:39 -0700 | [diff] [blame] | 988 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 989 | |
| 990 | #define IWL_TRAFFIC_DUMP_SIZE (IWL_TRAFFIC_ENTRY_SIZE * IWL_TRAFFIC_ENTRIES) |
| 991 | |
| 992 | void iwl_reset_traffic_log(struct iwl_priv *priv) |
| 993 | { |
| 994 | priv->tx_traffic_idx = 0; |
| 995 | priv->rx_traffic_idx = 0; |
| 996 | if (priv->tx_traffic) |
| 997 | memset(priv->tx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE); |
| 998 | if (priv->rx_traffic) |
| 999 | memset(priv->rx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE); |
| 1000 | } |
| 1001 | |
| 1002 | int iwl_alloc_traffic_mem(struct iwl_priv *priv) |
| 1003 | { |
| 1004 | u32 traffic_size = IWL_TRAFFIC_DUMP_SIZE; |
| 1005 | |
Johannes Berg | a8bceb3 | 2012-03-05 11:24:30 -0800 | [diff] [blame] | 1006 | if (iwl_have_debug_level(IWL_DL_TX)) { |
Wey-Yi Guy | 20594eb | 2009-08-07 15:41:39 -0700 | [diff] [blame] | 1007 | if (!priv->tx_traffic) { |
| 1008 | priv->tx_traffic = |
| 1009 | kzalloc(traffic_size, GFP_KERNEL); |
| 1010 | if (!priv->tx_traffic) |
| 1011 | return -ENOMEM; |
| 1012 | } |
| 1013 | } |
Johannes Berg | a8bceb3 | 2012-03-05 11:24:30 -0800 | [diff] [blame] | 1014 | if (iwl_have_debug_level(IWL_DL_RX)) { |
Wey-Yi Guy | 20594eb | 2009-08-07 15:41:39 -0700 | [diff] [blame] | 1015 | if (!priv->rx_traffic) { |
| 1016 | priv->rx_traffic = |
| 1017 | kzalloc(traffic_size, GFP_KERNEL); |
| 1018 | if (!priv->rx_traffic) |
| 1019 | return -ENOMEM; |
| 1020 | } |
| 1021 | } |
| 1022 | iwl_reset_traffic_log(priv); |
| 1023 | return 0; |
| 1024 | } |
Wey-Yi Guy | 20594eb | 2009-08-07 15:41:39 -0700 | [diff] [blame] | 1025 | |
| 1026 | void iwl_free_traffic_mem(struct iwl_priv *priv) |
| 1027 | { |
| 1028 | kfree(priv->tx_traffic); |
| 1029 | priv->tx_traffic = NULL; |
| 1030 | |
| 1031 | kfree(priv->rx_traffic); |
| 1032 | priv->rx_traffic = NULL; |
| 1033 | } |
Wey-Yi Guy | 20594eb | 2009-08-07 15:41:39 -0700 | [diff] [blame] | 1034 | |
| 1035 | void iwl_dbg_log_tx_data_frame(struct iwl_priv *priv, |
| 1036 | u16 length, struct ieee80211_hdr *header) |
| 1037 | { |
| 1038 | __le16 fc; |
| 1039 | u16 len; |
| 1040 | |
Johannes Berg | a8bceb3 | 2012-03-05 11:24:30 -0800 | [diff] [blame] | 1041 | if (likely(!iwl_have_debug_level(IWL_DL_TX))) |
Wey-Yi Guy | 20594eb | 2009-08-07 15:41:39 -0700 | [diff] [blame] | 1042 | return; |
| 1043 | |
| 1044 | if (!priv->tx_traffic) |
| 1045 | return; |
| 1046 | |
| 1047 | fc = header->frame_control; |
| 1048 | if (ieee80211_is_data(fc)) { |
| 1049 | len = (length > IWL_TRAFFIC_ENTRY_SIZE) |
| 1050 | ? IWL_TRAFFIC_ENTRY_SIZE : length; |
| 1051 | memcpy((priv->tx_traffic + |
| 1052 | (priv->tx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)), |
| 1053 | header, len); |
| 1054 | priv->tx_traffic_idx = |
| 1055 | (priv->tx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES; |
| 1056 | } |
| 1057 | } |
Wey-Yi Guy | 20594eb | 2009-08-07 15:41:39 -0700 | [diff] [blame] | 1058 | |
| 1059 | void iwl_dbg_log_rx_data_frame(struct iwl_priv *priv, |
| 1060 | u16 length, struct ieee80211_hdr *header) |
| 1061 | { |
| 1062 | __le16 fc; |
| 1063 | u16 len; |
| 1064 | |
Johannes Berg | a8bceb3 | 2012-03-05 11:24:30 -0800 | [diff] [blame] | 1065 | if (likely(!iwl_have_debug_level(IWL_DL_RX))) |
Wey-Yi Guy | 20594eb | 2009-08-07 15:41:39 -0700 | [diff] [blame] | 1066 | return; |
| 1067 | |
| 1068 | if (!priv->rx_traffic) |
| 1069 | return; |
| 1070 | |
| 1071 | fc = header->frame_control; |
| 1072 | if (ieee80211_is_data(fc)) { |
| 1073 | len = (length > IWL_TRAFFIC_ENTRY_SIZE) |
| 1074 | ? IWL_TRAFFIC_ENTRY_SIZE : length; |
| 1075 | memcpy((priv->rx_traffic + |
| 1076 | (priv->rx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)), |
| 1077 | header, len); |
| 1078 | priv->rx_traffic_idx = |
| 1079 | (priv->rx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES; |
| 1080 | } |
| 1081 | } |
Wey-Yi Guy | 22fdf3c | 2009-08-07 15:41:40 -0700 | [diff] [blame] | 1082 | |
| 1083 | const char *get_mgmt_string(int cmd) |
| 1084 | { |
| 1085 | switch (cmd) { |
| 1086 | IWL_CMD(MANAGEMENT_ASSOC_REQ); |
| 1087 | IWL_CMD(MANAGEMENT_ASSOC_RESP); |
| 1088 | IWL_CMD(MANAGEMENT_REASSOC_REQ); |
| 1089 | IWL_CMD(MANAGEMENT_REASSOC_RESP); |
| 1090 | IWL_CMD(MANAGEMENT_PROBE_REQ); |
| 1091 | IWL_CMD(MANAGEMENT_PROBE_RESP); |
| 1092 | IWL_CMD(MANAGEMENT_BEACON); |
| 1093 | IWL_CMD(MANAGEMENT_ATIM); |
| 1094 | IWL_CMD(MANAGEMENT_DISASSOC); |
| 1095 | IWL_CMD(MANAGEMENT_AUTH); |
| 1096 | IWL_CMD(MANAGEMENT_DEAUTH); |
| 1097 | IWL_CMD(MANAGEMENT_ACTION); |
| 1098 | default: |
| 1099 | return "UNKNOWN"; |
| 1100 | |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | const char *get_ctrl_string(int cmd) |
| 1105 | { |
| 1106 | switch (cmd) { |
| 1107 | IWL_CMD(CONTROL_BACK_REQ); |
| 1108 | IWL_CMD(CONTROL_BACK); |
| 1109 | IWL_CMD(CONTROL_PSPOLL); |
| 1110 | IWL_CMD(CONTROL_RTS); |
| 1111 | IWL_CMD(CONTROL_CTS); |
| 1112 | IWL_CMD(CONTROL_ACK); |
| 1113 | IWL_CMD(CONTROL_CFEND); |
| 1114 | IWL_CMD(CONTROL_CFENDACK); |
| 1115 | default: |
| 1116 | return "UNKNOWN"; |
| 1117 | |
| 1118 | } |
| 1119 | } |
| 1120 | |
Wey-Yi Guy | 7163b8a | 2009-11-20 12:04:56 -0800 | [diff] [blame] | 1121 | void iwl_clear_traffic_stats(struct iwl_priv *priv) |
Wey-Yi Guy | 22fdf3c | 2009-08-07 15:41:40 -0700 | [diff] [blame] | 1122 | { |
| 1123 | memset(&priv->tx_stats, 0, sizeof(struct traffic_stats)); |
Wey-Yi Guy | 22fdf3c | 2009-08-07 15:41:40 -0700 | [diff] [blame] | 1124 | memset(&priv->rx_stats, 0, sizeof(struct traffic_stats)); |
| 1125 | } |
| 1126 | |
| 1127 | /* |
| 1128 | * if CONFIG_IWLWIFI_DEBUGFS defined, iwl_update_stats function will |
| 1129 | * record all the MGMT, CTRL and DATA pkt for both TX and Rx pass. |
| 1130 | * Use debugFs to display the rx/rx_statistics |
| 1131 | * if CONFIG_IWLWIFI_DEBUGFS not being defined, then no MGMT and CTRL |
| 1132 | * information will be recorded, but DATA pkt still will be recorded |
| 1133 | * for the reason of iwl_led.c need to control the led blinking based on |
| 1134 | * number of tx and rx data. |
| 1135 | * |
| 1136 | */ |
| 1137 | void iwl_update_stats(struct iwl_priv *priv, bool is_tx, __le16 fc, u16 len) |
| 1138 | { |
| 1139 | struct traffic_stats *stats; |
| 1140 | |
| 1141 | if (is_tx) |
| 1142 | stats = &priv->tx_stats; |
| 1143 | else |
| 1144 | stats = &priv->rx_stats; |
| 1145 | |
| 1146 | if (ieee80211_is_mgmt(fc)) { |
| 1147 | switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) { |
| 1148 | case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ): |
| 1149 | stats->mgmt[MANAGEMENT_ASSOC_REQ]++; |
| 1150 | break; |
| 1151 | case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP): |
| 1152 | stats->mgmt[MANAGEMENT_ASSOC_RESP]++; |
| 1153 | break; |
| 1154 | case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ): |
| 1155 | stats->mgmt[MANAGEMENT_REASSOC_REQ]++; |
| 1156 | break; |
| 1157 | case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP): |
| 1158 | stats->mgmt[MANAGEMENT_REASSOC_RESP]++; |
| 1159 | break; |
| 1160 | case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ): |
| 1161 | stats->mgmt[MANAGEMENT_PROBE_REQ]++; |
| 1162 | break; |
| 1163 | case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP): |
| 1164 | stats->mgmt[MANAGEMENT_PROBE_RESP]++; |
| 1165 | break; |
| 1166 | case cpu_to_le16(IEEE80211_STYPE_BEACON): |
| 1167 | stats->mgmt[MANAGEMENT_BEACON]++; |
| 1168 | break; |
| 1169 | case cpu_to_le16(IEEE80211_STYPE_ATIM): |
| 1170 | stats->mgmt[MANAGEMENT_ATIM]++; |
| 1171 | break; |
| 1172 | case cpu_to_le16(IEEE80211_STYPE_DISASSOC): |
| 1173 | stats->mgmt[MANAGEMENT_DISASSOC]++; |
| 1174 | break; |
| 1175 | case cpu_to_le16(IEEE80211_STYPE_AUTH): |
| 1176 | stats->mgmt[MANAGEMENT_AUTH]++; |
| 1177 | break; |
| 1178 | case cpu_to_le16(IEEE80211_STYPE_DEAUTH): |
| 1179 | stats->mgmt[MANAGEMENT_DEAUTH]++; |
| 1180 | break; |
| 1181 | case cpu_to_le16(IEEE80211_STYPE_ACTION): |
| 1182 | stats->mgmt[MANAGEMENT_ACTION]++; |
| 1183 | break; |
| 1184 | } |
| 1185 | } else if (ieee80211_is_ctl(fc)) { |
| 1186 | switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) { |
| 1187 | case cpu_to_le16(IEEE80211_STYPE_BACK_REQ): |
| 1188 | stats->ctrl[CONTROL_BACK_REQ]++; |
| 1189 | break; |
| 1190 | case cpu_to_le16(IEEE80211_STYPE_BACK): |
| 1191 | stats->ctrl[CONTROL_BACK]++; |
| 1192 | break; |
| 1193 | case cpu_to_le16(IEEE80211_STYPE_PSPOLL): |
| 1194 | stats->ctrl[CONTROL_PSPOLL]++; |
| 1195 | break; |
| 1196 | case cpu_to_le16(IEEE80211_STYPE_RTS): |
| 1197 | stats->ctrl[CONTROL_RTS]++; |
| 1198 | break; |
| 1199 | case cpu_to_le16(IEEE80211_STYPE_CTS): |
| 1200 | stats->ctrl[CONTROL_CTS]++; |
| 1201 | break; |
| 1202 | case cpu_to_le16(IEEE80211_STYPE_ACK): |
| 1203 | stats->ctrl[CONTROL_ACK]++; |
| 1204 | break; |
| 1205 | case cpu_to_le16(IEEE80211_STYPE_CFEND): |
| 1206 | stats->ctrl[CONTROL_CFEND]++; |
| 1207 | break; |
| 1208 | case cpu_to_le16(IEEE80211_STYPE_CFENDACK): |
| 1209 | stats->ctrl[CONTROL_CFENDACK]++; |
| 1210 | break; |
| 1211 | } |
| 1212 | } else { |
| 1213 | /* data */ |
| 1214 | stats->data_cnt++; |
| 1215 | stats->data_bytes += len; |
| 1216 | } |
| 1217 | } |
Wey-Yi Guy | 20594eb | 2009-08-07 15:41:39 -0700 | [diff] [blame] | 1218 | #endif |
| 1219 | |
Wey-Yi Guy | a93e797 | 2010-02-03 11:47:19 -0800 | [diff] [blame] | 1220 | static void iwl_force_rf_reset(struct iwl_priv *priv) |
Wey-Yi Guy | afbdd69 | 2010-01-22 14:22:43 -0800 | [diff] [blame] | 1221 | { |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 1222 | if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status)) |
Wey-Yi Guy | afbdd69 | 2010-01-22 14:22:43 -0800 | [diff] [blame] | 1223 | return; |
| 1224 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 1225 | if (!iwl_is_any_associated(priv)) { |
Wey-Yi Guy | afbdd69 | 2010-01-22 14:22:43 -0800 | [diff] [blame] | 1226 | IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n"); |
| 1227 | return; |
| 1228 | } |
| 1229 | /* |
| 1230 | * There is no easy and better way to force reset the radio, |
| 1231 | * the only known method is switching channel which will force to |
| 1232 | * reset and tune the radio. |
| 1233 | * Use internal short scan (single channel) operation to should |
| 1234 | * achieve this objective. |
| 1235 | * Driver should reset the radio when number of consecutive missed |
| 1236 | * beacon, or any other uCode error condition detected. |
| 1237 | */ |
| 1238 | IWL_DEBUG_INFO(priv, "perform radio reset.\n"); |
| 1239 | iwl_internal_short_hw_scan(priv); |
Wey-Yi Guy | afbdd69 | 2010-01-22 14:22:43 -0800 | [diff] [blame] | 1240 | } |
Wey-Yi Guy | a93e797 | 2010-02-03 11:47:19 -0800 | [diff] [blame] | 1241 | |
Wey-Yi Guy | a93e797 | 2010-02-03 11:47:19 -0800 | [diff] [blame] | 1242 | |
Wey-Yi Guy | c04f9f2 | 2010-06-21 16:52:55 -0700 | [diff] [blame] | 1243 | int iwl_force_reset(struct iwl_priv *priv, int mode, bool external) |
Wey-Yi Guy | a93e797 | 2010-02-03 11:47:19 -0800 | [diff] [blame] | 1244 | { |
Wey-Yi Guy | 8a472da | 2010-02-18 22:03:06 -0800 | [diff] [blame] | 1245 | struct iwl_force_reset *force_reset; |
| 1246 | |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 1247 | if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status)) |
Wey-Yi Guy | a93e797 | 2010-02-03 11:47:19 -0800 | [diff] [blame] | 1248 | return -EINVAL; |
| 1249 | |
Wey-Yi Guy | 8a472da | 2010-02-18 22:03:06 -0800 | [diff] [blame] | 1250 | if (mode >= IWL_MAX_FORCE_RESET) { |
| 1251 | IWL_DEBUG_INFO(priv, "invalid reset request.\n"); |
| 1252 | return -EINVAL; |
| 1253 | } |
| 1254 | force_reset = &priv->force_reset[mode]; |
| 1255 | force_reset->reset_request_count++; |
Wey-Yi Guy | c04f9f2 | 2010-06-21 16:52:55 -0700 | [diff] [blame] | 1256 | if (!external) { |
| 1257 | if (force_reset->last_force_reset_jiffies && |
| 1258 | time_after(force_reset->last_force_reset_jiffies + |
| 1259 | force_reset->reset_duration, jiffies)) { |
| 1260 | IWL_DEBUG_INFO(priv, "force reset rejected\n"); |
| 1261 | force_reset->reset_reject_count++; |
| 1262 | return -EAGAIN; |
| 1263 | } |
Wey-Yi Guy | a93e797 | 2010-02-03 11:47:19 -0800 | [diff] [blame] | 1264 | } |
Wey-Yi Guy | 8a472da | 2010-02-18 22:03:06 -0800 | [diff] [blame] | 1265 | force_reset->reset_success_count++; |
| 1266 | force_reset->last_force_reset_jiffies = jiffies; |
Wey-Yi Guy | a93e797 | 2010-02-03 11:47:19 -0800 | [diff] [blame] | 1267 | IWL_DEBUG_INFO(priv, "perform force reset (%d)\n", mode); |
Wey-Yi Guy | a93e797 | 2010-02-03 11:47:19 -0800 | [diff] [blame] | 1268 | switch (mode) { |
| 1269 | case IWL_RF_RESET: |
| 1270 | iwl_force_rf_reset(priv); |
| 1271 | break; |
| 1272 | case IWL_FW_RESET: |
Wey-Yi Guy | c04f9f2 | 2010-06-21 16:52:55 -0700 | [diff] [blame] | 1273 | /* |
| 1274 | * if the request is from external(ex: debugfs), |
| 1275 | * then always perform the request in regardless the module |
| 1276 | * parameter setting |
| 1277 | * if the request is from internal (uCode error or driver |
| 1278 | * detect failure), then fw_restart module parameter |
| 1279 | * need to be check before performing firmware reload |
| 1280 | */ |
Don Fry | 9d143e9 | 2011-04-20 15:23:57 -0700 | [diff] [blame] | 1281 | if (!external && !iwlagn_mod_params.restart_fw) { |
Wey-Yi Guy | c04f9f2 | 2010-06-21 16:52:55 -0700 | [diff] [blame] | 1282 | IWL_DEBUG_INFO(priv, "Cancel firmware reload based on " |
| 1283 | "module parameter setting\n"); |
| 1284 | break; |
| 1285 | } |
Wey-Yi Guy | a93e797 | 2010-02-03 11:47:19 -0800 | [diff] [blame] | 1286 | IWL_ERR(priv, "On demand firmware reload\n"); |
Johannes Berg | e649437 | 2011-04-05 09:41:58 -0700 | [diff] [blame] | 1287 | iwlagn_fw_error(priv, true); |
Wey-Yi Guy | a93e797 | 2010-02-03 11:47:19 -0800 | [diff] [blame] | 1288 | break; |
Wey-Yi Guy | a93e797 | 2010-02-03 11:47:19 -0800 | [diff] [blame] | 1289 | } |
Wey-Yi Guy | a93e797 | 2010-02-03 11:47:19 -0800 | [diff] [blame] | 1290 | return 0; |
| 1291 | } |
Wey-Yi Guy | b74e31a | 2010-03-01 17:23:50 -0800 | [diff] [blame] | 1292 | |
Johannes Berg | d4daaea | 2010-10-23 09:15:43 -0700 | [diff] [blame] | 1293 | |
Wey-Yi Guy | 317d09f | 2011-10-10 07:26:49 -0700 | [diff] [blame] | 1294 | int iwl_cmd_echo_test(struct iwl_priv *priv) |
| 1295 | { |
Wey-Yi Guy | 7e4005c | 2011-10-10 07:26:51 -0700 | [diff] [blame] | 1296 | int ret; |
Wey-Yi Guy | 317d09f | 2011-10-10 07:26:49 -0700 | [diff] [blame] | 1297 | struct iwl_host_cmd cmd = { |
| 1298 | .id = REPLY_ECHO, |
Wey-Yi Guy | 89db3b9 | 2011-11-10 06:55:18 -0800 | [diff] [blame] | 1299 | .len = { 0 }, |
Wey-Yi Guy | 317d09f | 2011-10-10 07:26:49 -0700 | [diff] [blame] | 1300 | .flags = CMD_SYNC, |
| 1301 | }; |
| 1302 | |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 1303 | ret = iwl_dvm_send_cmd(priv, &cmd); |
Wey-Yi Guy | 7e4005c | 2011-10-10 07:26:51 -0700 | [diff] [blame] | 1304 | if (ret) |
| 1305 | IWL_ERR(priv, "echo testing fail: 0X%x\n", ret); |
| 1306 | else |
| 1307 | IWL_DEBUG_INFO(priv, "echo testing pass\n"); |
| 1308 | return ret; |
Wey-Yi Guy | 317d09f | 2011-10-10 07:26:49 -0700 | [diff] [blame] | 1309 | } |
| 1310 | |
Emmanuel Grumbach | f22be62 | 2011-08-25 23:11:30 -0700 | [diff] [blame] | 1311 | static inline int iwl_check_stuck_queue(struct iwl_priv *priv, int txq) |
Wey-Yi Guy | b74e31a | 2010-03-01 17:23:50 -0800 | [diff] [blame] | 1312 | { |
Emmanuel Grumbach | f22be62 | 2011-08-25 23:11:30 -0700 | [diff] [blame] | 1313 | if (iwl_trans_check_stuck_queue(trans(priv), txq)) { |
Wey-Yi Guy | 317d09f | 2011-10-10 07:26:49 -0700 | [diff] [blame] | 1314 | int ret; |
Wey-Yi Guy | 317d09f | 2011-10-10 07:26:49 -0700 | [diff] [blame] | 1315 | ret = iwl_force_reset(priv, IWL_FW_RESET, false); |
Stanislaw Gruszka | 22de94d | 2010-12-03 15:41:48 +0100 | [diff] [blame] | 1316 | return (ret == -EAGAIN) ? 0 : 1; |
| 1317 | } |
Wey-Yi Guy | b74e31a | 2010-03-01 17:23:50 -0800 | [diff] [blame] | 1318 | return 0; |
| 1319 | } |
| 1320 | |
Stanislaw Gruszka | 22de94d | 2010-12-03 15:41:48 +0100 | [diff] [blame] | 1321 | /* |
| 1322 | * Making watchdog tick be a quarter of timeout assure we will |
| 1323 | * discover the queue hung between timeout and 1.25*timeout |
| 1324 | */ |
| 1325 | #define IWL_WD_TICK(timeout) ((timeout) / 4) |
| 1326 | |
| 1327 | /* |
| 1328 | * Watchdog timer callback, we check each tx queue for stuck, if if hung |
| 1329 | * we reset the firmware. If everything is fine just rearm the timer. |
| 1330 | */ |
| 1331 | void iwl_bg_watchdog(unsigned long data) |
Wey-Yi Guy | b74e31a | 2010-03-01 17:23:50 -0800 | [diff] [blame] | 1332 | { |
| 1333 | struct iwl_priv *priv = (struct iwl_priv *)data; |
| 1334 | int cnt; |
Stanislaw Gruszka | 22de94d | 2010-12-03 15:41:48 +0100 | [diff] [blame] | 1335 | unsigned long timeout; |
Wey-Yi Guy | b74e31a | 2010-03-01 17:23:50 -0800 | [diff] [blame] | 1336 | |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 1337 | if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status)) |
Wey-Yi Guy | b74e31a | 2010-03-01 17:23:50 -0800 | [diff] [blame] | 1338 | return; |
| 1339 | |
Wey-Yi Guy | 46e7741 | 2011-10-10 07:26:50 -0700 | [diff] [blame] | 1340 | if (iwl_is_rfkill(priv->shrd)) |
| 1341 | return; |
| 1342 | |
Johannes Berg | e7a0943 | 2012-03-06 13:30:54 -0800 | [diff] [blame] | 1343 | timeout = hw_params(priv).wd_timeout; |
Stanislaw Gruszka | 22de94d | 2010-12-03 15:41:48 +0100 | [diff] [blame] | 1344 | if (timeout == 0) |
| 1345 | return; |
| 1346 | |
Johannes Berg | 342bbf3 | 2012-03-04 08:50:46 -0800 | [diff] [blame] | 1347 | /* monitor and check for stuck queues */ |
Johannes Berg | 3cc241a | 2012-03-06 13:30:52 -0800 | [diff] [blame] | 1348 | for (cnt = 0; cnt < cfg(priv)->base_params->num_of_queues; cnt++) |
Johannes Berg | 342bbf3 | 2012-03-04 08:50:46 -0800 | [diff] [blame] | 1349 | if (iwl_check_stuck_queue(priv, cnt)) |
| 1350 | return; |
Wey-Yi Guy | afbdd69 | 2010-01-22 14:22:43 -0800 | [diff] [blame] | 1351 | |
Stanislaw Gruszka | 22de94d | 2010-12-03 15:41:48 +0100 | [diff] [blame] | 1352 | mod_timer(&priv->watchdog, jiffies + |
| 1353 | msecs_to_jiffies(IWL_WD_TICK(timeout))); |
| 1354 | } |
Stanislaw Gruszka | 22de94d | 2010-12-03 15:41:48 +0100 | [diff] [blame] | 1355 | |
| 1356 | void iwl_setup_watchdog(struct iwl_priv *priv) |
| 1357 | { |
Johannes Berg | e7a0943 | 2012-03-06 13:30:54 -0800 | [diff] [blame] | 1358 | unsigned int timeout = hw_params(priv).wd_timeout; |
Stanislaw Gruszka | 22de94d | 2010-12-03 15:41:48 +0100 | [diff] [blame] | 1359 | |
Wey-Yi Guy | 9995ffe | 2011-12-02 08:19:19 -0800 | [diff] [blame] | 1360 | if (!iwlagn_mod_params.wd_disable) { |
| 1361 | /* use system default */ |
Don Fry | 3862241 | 2011-12-16 07:07:36 -0800 | [diff] [blame] | 1362 | if (timeout && !cfg(priv)->base_params->wd_disable) |
Wey-Yi Guy | 9995ffe | 2011-12-02 08:19:19 -0800 | [diff] [blame] | 1363 | mod_timer(&priv->watchdog, |
| 1364 | jiffies + |
| 1365 | msecs_to_jiffies(IWL_WD_TICK(timeout))); |
| 1366 | else |
| 1367 | del_timer(&priv->watchdog); |
| 1368 | } else { |
| 1369 | /* module parameter overwrite default configuration */ |
| 1370 | if (timeout && iwlagn_mod_params.wd_disable == 2) |
| 1371 | mod_timer(&priv->watchdog, |
| 1372 | jiffies + |
| 1373 | msecs_to_jiffies(IWL_WD_TICK(timeout))); |
| 1374 | else |
| 1375 | del_timer(&priv->watchdog); |
| 1376 | } |
Stanislaw Gruszka | 22de94d | 2010-12-03 15:41:48 +0100 | [diff] [blame] | 1377 | } |
Wey-Yi Guy | a0ee74c | 2010-05-06 08:54:10 -0700 | [diff] [blame] | 1378 | |
Emmanuel Grumbach | 8c22254 | 2011-10-10 07:27:16 -0700 | [diff] [blame] | 1379 | /** |
| 1380 | * iwl_beacon_time_mask_low - mask of lower 32 bit of beacon time |
| 1381 | * @priv -- pointer to iwl_priv data structure |
| 1382 | * @tsf_bits -- number of bits need to shift for masking) |
| 1383 | */ |
| 1384 | static inline u32 iwl_beacon_time_mask_low(struct iwl_priv *priv, |
| 1385 | u16 tsf_bits) |
| 1386 | { |
| 1387 | return (1 << tsf_bits) - 1; |
| 1388 | } |
| 1389 | |
| 1390 | /** |
| 1391 | * iwl_beacon_time_mask_high - mask of higher 32 bit of beacon time |
| 1392 | * @priv -- pointer to iwl_priv data structure |
| 1393 | * @tsf_bits -- number of bits need to shift for masking) |
| 1394 | */ |
| 1395 | static inline u32 iwl_beacon_time_mask_high(struct iwl_priv *priv, |
| 1396 | u16 tsf_bits) |
| 1397 | { |
| 1398 | return ((1 << (32 - tsf_bits)) - 1) << tsf_bits; |
| 1399 | } |
| 1400 | |
Wey-Yi Guy | a0ee74c | 2010-05-06 08:54:10 -0700 | [diff] [blame] | 1401 | /* |
| 1402 | * extended beacon time format |
| 1403 | * time in usec will be changed into a 32-bit value in extended:internal format |
| 1404 | * the extended part is the beacon counts |
| 1405 | * the internal part is the time in usec within one beacon interval |
| 1406 | */ |
| 1407 | u32 iwl_usecs_to_beacons(struct iwl_priv *priv, u32 usec, u32 beacon_interval) |
| 1408 | { |
| 1409 | u32 quot; |
| 1410 | u32 rem; |
| 1411 | u32 interval = beacon_interval * TIME_UNIT; |
| 1412 | |
| 1413 | if (!interval || !usec) |
| 1414 | return 0; |
| 1415 | |
| 1416 | quot = (usec / interval) & |
Don Fry | 403ba56 | 2011-09-15 11:46:39 -0700 | [diff] [blame] | 1417 | (iwl_beacon_time_mask_high(priv, IWLAGN_EXT_BEACON_TIME_POS) >> |
| 1418 | IWLAGN_EXT_BEACON_TIME_POS); |
Wey-Yi Guy | a0ee74c | 2010-05-06 08:54:10 -0700 | [diff] [blame] | 1419 | rem = (usec % interval) & iwl_beacon_time_mask_low(priv, |
Don Fry | 403ba56 | 2011-09-15 11:46:39 -0700 | [diff] [blame] | 1420 | IWLAGN_EXT_BEACON_TIME_POS); |
Wey-Yi Guy | a0ee74c | 2010-05-06 08:54:10 -0700 | [diff] [blame] | 1421 | |
Don Fry | 403ba56 | 2011-09-15 11:46:39 -0700 | [diff] [blame] | 1422 | return (quot << IWLAGN_EXT_BEACON_TIME_POS) + rem; |
Wey-Yi Guy | a0ee74c | 2010-05-06 08:54:10 -0700 | [diff] [blame] | 1423 | } |
Wey-Yi Guy | a0ee74c | 2010-05-06 08:54:10 -0700 | [diff] [blame] | 1424 | |
| 1425 | /* base is usually what we get from ucode with each received frame, |
| 1426 | * the same as HW timer counter counting down |
| 1427 | */ |
| 1428 | __le32 iwl_add_beacon_time(struct iwl_priv *priv, u32 base, |
| 1429 | u32 addon, u32 beacon_interval) |
| 1430 | { |
| 1431 | u32 base_low = base & iwl_beacon_time_mask_low(priv, |
Don Fry | 403ba56 | 2011-09-15 11:46:39 -0700 | [diff] [blame] | 1432 | IWLAGN_EXT_BEACON_TIME_POS); |
Wey-Yi Guy | a0ee74c | 2010-05-06 08:54:10 -0700 | [diff] [blame] | 1433 | u32 addon_low = addon & iwl_beacon_time_mask_low(priv, |
Don Fry | 403ba56 | 2011-09-15 11:46:39 -0700 | [diff] [blame] | 1434 | IWLAGN_EXT_BEACON_TIME_POS); |
Wey-Yi Guy | a0ee74c | 2010-05-06 08:54:10 -0700 | [diff] [blame] | 1435 | u32 interval = beacon_interval * TIME_UNIT; |
| 1436 | u32 res = (base & iwl_beacon_time_mask_high(priv, |
Don Fry | 403ba56 | 2011-09-15 11:46:39 -0700 | [diff] [blame] | 1437 | IWLAGN_EXT_BEACON_TIME_POS)) + |
Wey-Yi Guy | a0ee74c | 2010-05-06 08:54:10 -0700 | [diff] [blame] | 1438 | (addon & iwl_beacon_time_mask_high(priv, |
Don Fry | 403ba56 | 2011-09-15 11:46:39 -0700 | [diff] [blame] | 1439 | IWLAGN_EXT_BEACON_TIME_POS)); |
Wey-Yi Guy | a0ee74c | 2010-05-06 08:54:10 -0700 | [diff] [blame] | 1440 | |
| 1441 | if (base_low > addon_low) |
| 1442 | res += base_low - addon_low; |
| 1443 | else if (base_low < addon_low) { |
| 1444 | res += interval + base_low - addon_low; |
Don Fry | 403ba56 | 2011-09-15 11:46:39 -0700 | [diff] [blame] | 1445 | res += (1 << IWLAGN_EXT_BEACON_TIME_POS); |
Wey-Yi Guy | a0ee74c | 2010-05-06 08:54:10 -0700 | [diff] [blame] | 1446 | } else |
Don Fry | 403ba56 | 2011-09-15 11:46:39 -0700 | [diff] [blame] | 1447 | res += (1 << IWLAGN_EXT_BEACON_TIME_POS); |
Wey-Yi Guy | a0ee74c | 2010-05-06 08:54:10 -0700 | [diff] [blame] | 1448 | |
| 1449 | return cpu_to_le32(res); |
| 1450 | } |
Wey-Yi Guy | a0ee74c | 2010-05-06 08:54:10 -0700 | [diff] [blame] | 1451 | |
Emmanuel Grumbach | bcb9321 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1452 | void iwl_nic_error(struct iwl_op_mode *op_mode) |
| 1453 | { |
| 1454 | struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); |
| 1455 | |
| 1456 | iwlagn_fw_error(priv, false); |
| 1457 | } |
| 1458 | |
Emmanuel Grumbach | 7120d98 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1459 | void iwl_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state) |
Emmanuel Grumbach | 3e10cae | 2011-09-06 09:31:18 -0700 | [diff] [blame] | 1460 | { |
Emmanuel Grumbach | 7120d98 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1461 | struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); |
| 1462 | |
Johannes Berg | c9eec95 | 2012-03-06 13:30:43 -0800 | [diff] [blame] | 1463 | if (state) |
| 1464 | set_bit(STATUS_RF_KILL_HW, &priv->shrd->status); |
| 1465 | else |
| 1466 | clear_bit(STATUS_RF_KILL_HW, &priv->shrd->status); |
| 1467 | |
Emmanuel Grumbach | 3e10cae | 2011-09-06 09:31:18 -0700 | [diff] [blame] | 1468 | wiphy_rfkill_set_hw_state(priv->hw->wiphy, state); |
| 1469 | } |
Emmanuel Grumbach | 7a10e3e4 | 2011-09-06 09:31:21 -0700 | [diff] [blame] | 1470 | |
| 1471 | void iwl_nic_config(struct iwl_priv *priv) |
| 1472 | { |
Don Fry | 3862241 | 2011-12-16 07:07:36 -0800 | [diff] [blame] | 1473 | cfg(priv)->lib->nic_config(priv); |
Emmanuel Grumbach | 7a10e3e4 | 2011-09-06 09:31:21 -0700 | [diff] [blame] | 1474 | } |
Emmanuel Grumbach | 909e9b2 | 2011-09-15 11:46:30 -0700 | [diff] [blame] | 1475 | |
Emmanuel Grumbach | ed277c9 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1476 | void iwl_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb) |
Emmanuel Grumbach | 909e9b2 | 2011-09-15 11:46:30 -0700 | [diff] [blame] | 1477 | { |
Emmanuel Grumbach | ed277c9 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1478 | struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); |
Emmanuel Grumbach | 909e9b2 | 2011-09-15 11:46:30 -0700 | [diff] [blame] | 1479 | struct ieee80211_tx_info *info; |
| 1480 | |
| 1481 | info = IEEE80211_SKB_CB(skb); |
| 1482 | kmem_cache_free(priv->tx_cmd_pool, (info->driver_data[1])); |
| 1483 | dev_kfree_skb_any(skb); |
| 1484 | } |
Emmanuel Grumbach | 859cfb0 | 2011-09-15 11:46:31 -0700 | [diff] [blame] | 1485 | |
Emmanuel Grumbach | 02e3835 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1486 | void iwl_stop_sw_queue(struct iwl_op_mode *op_mode, u8 ac) |
Emmanuel Grumbach | 859cfb0 | 2011-09-15 11:46:31 -0700 | [diff] [blame] | 1487 | { |
Emmanuel Grumbach | 02e3835 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1488 | struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); |
| 1489 | |
Emmanuel Grumbach | 859cfb0 | 2011-09-15 11:46:31 -0700 | [diff] [blame] | 1490 | ieee80211_stop_queue(priv->hw, ac); |
| 1491 | } |
| 1492 | |
Emmanuel Grumbach | 02e3835 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1493 | void iwl_wake_sw_queue(struct iwl_op_mode *op_mode, u8 ac) |
Emmanuel Grumbach | 859cfb0 | 2011-09-15 11:46:31 -0700 | [diff] [blame] | 1494 | { |
Emmanuel Grumbach | 02e3835 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1495 | struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); |
| 1496 | |
Emmanuel Grumbach | 859cfb0 | 2011-09-15 11:46:31 -0700 | [diff] [blame] | 1497 | ieee80211_wake_queue(priv->hw, ac); |
| 1498 | } |