Commit | Line | Data |
---|---|---|
df48c323 | 1 | /****************************************************************************** |
df48c323 TW |
2 | * |
3 | * GPL LICENSE SUMMARY | |
4 | * | |
1f447808 | 5 | * Copyright(c) 2008 - 2010 Intel Corporation. All rights reserved. |
df48c323 TW |
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: | |
759ef89f | 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
df48c323 TW |
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> | |
8ccde88a | 31 | #include <linux/etherdevice.h> |
d43c36dc | 32 | #include <linux/sched.h> |
5a0e3ad6 | 33 | #include <linux/slab.h> |
1d0a082d | 34 | #include <net/mac80211.h> |
df48c323 | 35 | |
6bc913bd | 36 | #include "iwl-eeprom.h" |
3e0d4cb1 | 37 | #include "iwl-dev.h" /* FIXME: remove */ |
19335774 | 38 | #include "iwl-debug.h" |
df48c323 | 39 | #include "iwl-core.h" |
b661c819 | 40 | #include "iwl-io.h" |
5da4b55f | 41 | #include "iwl-power.h" |
83dde8c9 | 42 | #include "iwl-sta.h" |
ef850d7c | 43 | #include "iwl-helpers.h" |
df48c323 | 44 | |
1d0a082d | 45 | |
df48c323 TW |
46 | MODULE_DESCRIPTION("iwl core"); |
47 | MODULE_VERSION(IWLWIFI_VERSION); | |
a7b75207 | 48 | MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR); |
712b6cf5 | 49 | MODULE_LICENSE("GPL"); |
df48c323 | 50 | |
06702a73 WYG |
51 | /* |
52 | * set bt_coex_active to true, uCode will do kill/defer | |
53 | * every time the priority line is asserted (BT is sending signals on the | |
54 | * priority line in the PCIx). | |
55 | * set bt_coex_active to false, uCode will ignore the BT activity and | |
56 | * perform the normal operation | |
57 | * | |
58 | * User might experience transmit issue on some platform due to WiFi/BT | |
59 | * co-exist problem. The possible behaviors are: | |
60 | * Able to scan and finding all the available AP | |
61 | * Not able to associate with any AP | |
62 | * On those platforms, WiFi communication can be restored by set | |
63 | * "bt_coex_active" module parameter to "false" | |
64 | * | |
65 | * default: bt_coex_active = true (BT_COEX_ENABLE) | |
66 | */ | |
670245ed JB |
67 | bool bt_coex_active = true; |
68 | EXPORT_SYMBOL_GPL(bt_coex_active); | |
06702a73 | 69 | module_param(bt_coex_active, bool, S_IRUGO); |
6c69d121 | 70 | MODULE_PARM_DESC(bt_coex_active, "enable wifi/bluetooth co-exist"); |
06702a73 | 71 | |
a562a9dd RC |
72 | u32 iwl_debug_level; |
73 | EXPORT_SYMBOL(iwl_debug_level); | |
74 | ||
57bd1bea TW |
75 | const u8 iwl_bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; |
76 | EXPORT_SYMBOL(iwl_bcast_addr); | |
77 | ||
78 | ||
1d0a082d | 79 | /* This function both allocates and initializes hw and priv. */ |
dc21b545 | 80 | struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg) |
1d0a082d AK |
81 | { |
82 | struct iwl_priv *priv; | |
1d0a082d AK |
83 | /* mac80211 allocates memory for this device instance, including |
84 | * space for this driver's private structure */ | |
dc21b545 JB |
85 | struct ieee80211_hw *hw; |
86 | ||
87 | hw = ieee80211_alloc_hw(sizeof(struct iwl_priv), | |
88 | cfg->ops->ieee80211_ops); | |
1d0a082d | 89 | if (hw == NULL) { |
c96c31e4 | 90 | pr_err("%s: Can not allocate network device\n", |
a3139c59 | 91 | cfg->name); |
1d0a082d AK |
92 | goto out; |
93 | } | |
94 | ||
95 | priv = hw->priv; | |
96 | priv->hw = hw; | |
97 | ||
98 | out: | |
99 | return hw; | |
100 | } | |
101 | EXPORT_SYMBOL(iwl_alloc_all); | |
102 | ||
d9fe60de JB |
103 | #define MAX_BIT_RATE_40_MHZ 150 /* Mbps */ |
104 | #define MAX_BIT_RATE_20_MHZ 72 /* Mbps */ | |
c7de35cd | 105 | static void iwlcore_init_ht_hw_capab(const struct iwl_priv *priv, |
d9fe60de | 106 | struct ieee80211_sta_ht_cap *ht_info, |
c7de35cd RR |
107 | enum ieee80211_band band) |
108 | { | |
39130df3 RR |
109 | u16 max_bit_rate = 0; |
110 | u8 rx_chains_num = priv->hw_params.rx_chains_num; | |
111 | u8 tx_chains_num = priv->hw_params.tx_chains_num; | |
112 | ||
c7de35cd | 113 | ht_info->cap = 0; |
d9fe60de | 114 | memset(&ht_info->mcs, 0, sizeof(ht_info->mcs)); |
c7de35cd | 115 | |
d9fe60de | 116 | ht_info->ht_supported = true; |
c7de35cd | 117 | |
7cb1b088 WYG |
118 | if (priv->cfg->ht_params && |
119 | priv->cfg->ht_params->ht_greenfield_support) | |
b261793d | 120 | ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD; |
d9fe60de | 121 | ht_info->cap |= IEEE80211_HT_CAP_SGI_20; |
39130df3 | 122 | max_bit_rate = MAX_BIT_RATE_20_MHZ; |
7aafef1c | 123 | if (priv->hw_params.ht40_channel & BIT(band)) { |
d9fe60de JB |
124 | ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
125 | ht_info->cap |= IEEE80211_HT_CAP_SGI_40; | |
126 | ht_info->mcs.rx_mask[4] = 0x01; | |
39130df3 | 127 | max_bit_rate = MAX_BIT_RATE_40_MHZ; |
c7de35cd | 128 | } |
c7de35cd RR |
129 | |
130 | if (priv->cfg->mod_params->amsdu_size_8K) | |
d9fe60de | 131 | ht_info->cap |= IEEE80211_HT_CAP_MAX_AMSDU; |
c7de35cd RR |
132 | |
133 | ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF; | |
7cb1b088 WYG |
134 | if (priv->cfg->bt_params && priv->cfg->bt_params->ampdu_factor) |
135 | ht_info->ampdu_factor = priv->cfg->bt_params->ampdu_factor; | |
c7de35cd | 136 | ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF; |
7cb1b088 WYG |
137 | if (priv->cfg->bt_params && priv->cfg->bt_params->ampdu_density) |
138 | ht_info->ampdu_density = priv->cfg->bt_params->ampdu_density; | |
c7de35cd | 139 | |
d9fe60de | 140 | ht_info->mcs.rx_mask[0] = 0xFF; |
39130df3 | 141 | if (rx_chains_num >= 2) |
d9fe60de | 142 | ht_info->mcs.rx_mask[1] = 0xFF; |
39130df3 | 143 | if (rx_chains_num >= 3) |
d9fe60de | 144 | ht_info->mcs.rx_mask[2] = 0xFF; |
39130df3 RR |
145 | |
146 | /* Highest supported Rx data rate */ | |
147 | max_bit_rate *= rx_chains_num; | |
d9fe60de JB |
148 | WARN_ON(max_bit_rate & ~IEEE80211_HT_MCS_RX_HIGHEST_MASK); |
149 | ht_info->mcs.rx_highest = cpu_to_le16(max_bit_rate); | |
39130df3 RR |
150 | |
151 | /* Tx MCS capabilities */ | |
d9fe60de | 152 | ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; |
39130df3 | 153 | if (tx_chains_num != rx_chains_num) { |
d9fe60de JB |
154 | ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF; |
155 | ht_info->mcs.tx_params |= ((tx_chains_num - 1) << | |
156 | IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT); | |
39130df3 | 157 | } |
c7de35cd | 158 | } |
c7de35cd | 159 | |
c7de35cd RR |
160 | /** |
161 | * iwlcore_init_geos - Initialize mac80211's geo/channel info based from eeprom | |
162 | */ | |
534166de | 163 | int iwlcore_init_geos(struct iwl_priv *priv) |
c7de35cd RR |
164 | { |
165 | struct iwl_channel_info *ch; | |
166 | struct ieee80211_supported_band *sband; | |
167 | struct ieee80211_channel *channels; | |
168 | struct ieee80211_channel *geo_ch; | |
169 | struct ieee80211_rate *rates; | |
170 | int i = 0; | |
171 | ||
172 | if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates || | |
173 | priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) { | |
e1623446 | 174 | IWL_DEBUG_INFO(priv, "Geography modes already initialized.\n"); |
c7de35cd RR |
175 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
176 | return 0; | |
177 | } | |
178 | ||
179 | channels = kzalloc(sizeof(struct ieee80211_channel) * | |
180 | priv->channel_count, GFP_KERNEL); | |
181 | if (!channels) | |
182 | return -ENOMEM; | |
183 | ||
5027309b | 184 | rates = kzalloc((sizeof(struct ieee80211_rate) * IWL_RATE_COUNT_LEGACY), |
c7de35cd RR |
185 | GFP_KERNEL); |
186 | if (!rates) { | |
187 | kfree(channels); | |
188 | return -ENOMEM; | |
189 | } | |
190 | ||
191 | /* 5.2GHz channels start after the 2.4GHz channels */ | |
192 | sband = &priv->bands[IEEE80211_BAND_5GHZ]; | |
193 | sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)]; | |
194 | /* just OFDM */ | |
195 | sband->bitrates = &rates[IWL_FIRST_OFDM_RATE]; | |
5027309b | 196 | sband->n_bitrates = IWL_RATE_COUNT_LEGACY - IWL_FIRST_OFDM_RATE; |
c7de35cd | 197 | |
49779293 | 198 | if (priv->cfg->sku & IWL_SKU_N) |
d9fe60de | 199 | iwlcore_init_ht_hw_capab(priv, &sband->ht_cap, |
49779293 | 200 | IEEE80211_BAND_5GHZ); |
c7de35cd RR |
201 | |
202 | sband = &priv->bands[IEEE80211_BAND_2GHZ]; | |
203 | sband->channels = channels; | |
204 | /* OFDM & CCK */ | |
205 | sband->bitrates = rates; | |
5027309b | 206 | sband->n_bitrates = IWL_RATE_COUNT_LEGACY; |
c7de35cd | 207 | |
49779293 | 208 | if (priv->cfg->sku & IWL_SKU_N) |
d9fe60de | 209 | iwlcore_init_ht_hw_capab(priv, &sband->ht_cap, |
49779293 | 210 | IEEE80211_BAND_2GHZ); |
c7de35cd RR |
211 | |
212 | priv->ieee_channels = channels; | |
213 | priv->ieee_rates = rates; | |
214 | ||
c7de35cd RR |
215 | for (i = 0; i < priv->channel_count; i++) { |
216 | ch = &priv->channel_info[i]; | |
217 | ||
218 | /* FIXME: might be removed if scan is OK */ | |
219 | if (!is_channel_valid(ch)) | |
220 | continue; | |
221 | ||
222 | if (is_channel_a_band(ch)) | |
223 | sband = &priv->bands[IEEE80211_BAND_5GHZ]; | |
224 | else | |
225 | sband = &priv->bands[IEEE80211_BAND_2GHZ]; | |
226 | ||
227 | geo_ch = &sband->channels[sband->n_channels++]; | |
228 | ||
229 | geo_ch->center_freq = | |
230 | ieee80211_channel_to_frequency(ch->channel); | |
231 | geo_ch->max_power = ch->max_power_avg; | |
232 | geo_ch->max_antenna_gain = 0xff; | |
233 | geo_ch->hw_value = ch->channel; | |
234 | ||
235 | if (is_channel_valid(ch)) { | |
236 | if (!(ch->flags & EEPROM_CHANNEL_IBSS)) | |
237 | geo_ch->flags |= IEEE80211_CHAN_NO_IBSS; | |
238 | ||
239 | if (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) | |
240 | geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN; | |
241 | ||
242 | if (ch->flags & EEPROM_CHANNEL_RADAR) | |
243 | geo_ch->flags |= IEEE80211_CHAN_RADAR; | |
244 | ||
7aafef1c | 245 | geo_ch->flags |= ch->ht40_extension_channel; |
4d38c2e8 | 246 | |
dc1b0973 WYG |
247 | if (ch->max_power_avg > priv->tx_power_device_lmt) |
248 | priv->tx_power_device_lmt = ch->max_power_avg; | |
c7de35cd RR |
249 | } else { |
250 | geo_ch->flags |= IEEE80211_CHAN_DISABLED; | |
251 | } | |
252 | ||
e1623446 | 253 | IWL_DEBUG_INFO(priv, "Channel %d Freq=%d[%sGHz] %s flag=0x%X\n", |
c7de35cd RR |
254 | ch->channel, geo_ch->center_freq, |
255 | is_channel_a_band(ch) ? "5.2" : "2.4", | |
256 | geo_ch->flags & IEEE80211_CHAN_DISABLED ? | |
257 | "restricted" : "valid", | |
258 | geo_ch->flags); | |
259 | } | |
260 | ||
261 | if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) && | |
262 | priv->cfg->sku & IWL_SKU_A) { | |
978785a3 TW |
263 | IWL_INFO(priv, "Incorrectly detected BG card as ABG. " |
264 | "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n", | |
a3139c59 SO |
265 | priv->pci_dev->device, |
266 | priv->pci_dev->subsystem_device); | |
c7de35cd RR |
267 | priv->cfg->sku &= ~IWL_SKU_A; |
268 | } | |
269 | ||
978785a3 | 270 | IWL_INFO(priv, "Tunable channels: %d 802.11bg, %d 802.11a channels\n", |
a3139c59 SO |
271 | priv->bands[IEEE80211_BAND_2GHZ].n_channels, |
272 | priv->bands[IEEE80211_BAND_5GHZ].n_channels); | |
c7de35cd RR |
273 | |
274 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); | |
275 | ||
276 | return 0; | |
277 | } | |
534166de | 278 | EXPORT_SYMBOL(iwlcore_init_geos); |
c7de35cd RR |
279 | |
280 | /* | |
281 | * iwlcore_free_geos - undo allocations in iwlcore_init_geos | |
282 | */ | |
534166de | 283 | void iwlcore_free_geos(struct iwl_priv *priv) |
c7de35cd RR |
284 | { |
285 | kfree(priv->ieee_channels); | |
286 | kfree(priv->ieee_rates); | |
287 | clear_bit(STATUS_GEO_CONFIGURED, &priv->status); | |
288 | } | |
534166de | 289 | EXPORT_SYMBOL(iwlcore_free_geos); |
c7de35cd | 290 | |
7e6a5886 JB |
291 | static bool iwl_is_channel_extension(struct iwl_priv *priv, |
292 | enum ieee80211_band band, | |
293 | u16 channel, u8 extension_chan_offset) | |
47c5196e TW |
294 | { |
295 | const struct iwl_channel_info *ch_info; | |
296 | ||
297 | ch_info = iwl_get_channel_info(priv, band, channel); | |
298 | if (!is_channel_valid(ch_info)) | |
7e6a5886 | 299 | return false; |
47c5196e | 300 | |
d9fe60de | 301 | if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE) |
7aafef1c | 302 | return !(ch_info->ht40_extension_channel & |
689da1b3 | 303 | IEEE80211_CHAN_NO_HT40PLUS); |
d9fe60de | 304 | else if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_BELOW) |
7aafef1c | 305 | return !(ch_info->ht40_extension_channel & |
689da1b3 | 306 | IEEE80211_CHAN_NO_HT40MINUS); |
47c5196e | 307 | |
7e6a5886 | 308 | return false; |
47c5196e TW |
309 | } |
310 | ||
7e6a5886 JB |
311 | bool iwl_is_ht40_tx_allowed(struct iwl_priv *priv, |
312 | struct iwl_rxon_context *ctx, | |
313 | struct ieee80211_sta_ht_cap *ht_cap) | |
47c5196e | 314 | { |
7e6a5886 JB |
315 | if (!ctx->ht.enabled || !ctx->ht.is_40mhz) |
316 | return false; | |
47c5196e | 317 | |
7e6a5886 JB |
318 | /* |
319 | * We do not check for IEEE80211_HT_CAP_SUP_WIDTH_20_40 | |
a2b0f02e WYG |
320 | * the bit will not set if it is pure 40MHz case |
321 | */ | |
7e6a5886 JB |
322 | if (ht_cap && !ht_cap->ht_supported) |
323 | return false; | |
324 | ||
d73e4923 | 325 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
1e4247d4 | 326 | if (priv->disable_ht40) |
7e6a5886 | 327 | return false; |
1e4247d4 | 328 | #endif |
7e6a5886 | 329 | |
611d3eb7 | 330 | return iwl_is_channel_extension(priv, priv->band, |
246ed355 | 331 | le16_to_cpu(ctx->staging.channel), |
7e6a5886 | 332 | ctx->ht.extension_chan_offset); |
47c5196e | 333 | } |
7aafef1c | 334 | EXPORT_SYMBOL(iwl_is_ht40_tx_allowed); |
47c5196e | 335 | |
2c2f3b33 TW |
336 | static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val) |
337 | { | |
ea196fdb JB |
338 | u16 new_val; |
339 | u16 beacon_factor; | |
340 | ||
341 | /* | |
342 | * If mac80211 hasn't given us a beacon interval, program | |
343 | * the default into the device (not checking this here | |
344 | * would cause the adjustment below to return the maximum | |
345 | * value, which may break PAN.) | |
346 | */ | |
347 | if (!beacon_val) | |
348 | return DEFAULT_BEACON_INTERVAL; | |
349 | ||
350 | /* | |
351 | * If the beacon interval we obtained from the peer | |
352 | * is too large, we'll have to wake up more often | |
353 | * (and in IBSS case, we'll beacon too much) | |
354 | * | |
355 | * For example, if max_beacon_val is 4096, and the | |
356 | * requested beacon interval is 7000, we'll have to | |
357 | * use 3500 to be able to wake up on the beacons. | |
358 | * | |
359 | * This could badly influence beacon detection stats. | |
360 | */ | |
2c2f3b33 TW |
361 | |
362 | beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val; | |
363 | new_val = beacon_val / beacon_factor; | |
364 | ||
365 | if (!new_val) | |
366 | new_val = max_beacon_val; | |
367 | ||
368 | return new_val; | |
369 | } | |
370 | ||
47313e34 | 371 | int iwl_send_rxon_timing(struct iwl_priv *priv, struct iwl_rxon_context *ctx) |
2c2f3b33 TW |
372 | { |
373 | u64 tsf; | |
374 | s32 interval_tm, rem; | |
2c2f3b33 TW |
375 | struct ieee80211_conf *conf = NULL; |
376 | u16 beacon_int; | |
47313e34 | 377 | struct ieee80211_vif *vif = ctx->vif; |
2c2f3b33 TW |
378 | |
379 | conf = ieee80211_get_hw_conf(priv->hw); | |
380 | ||
948f5a2f JB |
381 | lockdep_assert_held(&priv->mutex); |
382 | ||
246ed355 | 383 | memset(&ctx->timing, 0, sizeof(struct iwl_rxon_time_cmd)); |
948f5a2f | 384 | |
246ed355 JB |
385 | ctx->timing.timestamp = cpu_to_le64(priv->timestamp); |
386 | ctx->timing.listen_interval = cpu_to_le16(conf->listen_interval); | |
2c2f3b33 | 387 | |
47313e34 | 388 | beacon_int = vif ? vif->bss_conf.beacon_int : 0; |
2c2f3b33 | 389 | |
47313e34 JB |
390 | /* |
391 | * TODO: For IBSS we need to get atim_window from mac80211, | |
392 | * for now just always use 0 | |
393 | */ | |
394 | ctx->timing.atim_window = 0; | |
2c2f3b33 | 395 | |
bde4530e | 396 | if (ctx->ctxid == IWL_RXON_CTX_PAN && |
f1f270b2 JB |
397 | (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION) && |
398 | iwl_is_associated(priv, IWL_RXON_CTX_BSS) && | |
399 | priv->contexts[IWL_RXON_CTX_BSS].vif && | |
400 | priv->contexts[IWL_RXON_CTX_BSS].vif->bss_conf.beacon_int) { | |
bde4530e JB |
401 | ctx->timing.beacon_interval = |
402 | priv->contexts[IWL_RXON_CTX_BSS].timing.beacon_interval; | |
403 | beacon_int = le16_to_cpu(ctx->timing.beacon_interval); | |
f1f270b2 JB |
404 | } else if (ctx->ctxid == IWL_RXON_CTX_BSS && |
405 | iwl_is_associated(priv, IWL_RXON_CTX_PAN) && | |
406 | priv->contexts[IWL_RXON_CTX_PAN].vif && | |
407 | priv->contexts[IWL_RXON_CTX_PAN].vif->bss_conf.beacon_int && | |
408 | (!iwl_is_associated_ctx(ctx) || !ctx->vif || | |
409 | !ctx->vif->bss_conf.beacon_int)) { | |
410 | ctx->timing.beacon_interval = | |
411 | priv->contexts[IWL_RXON_CTX_PAN].timing.beacon_interval; | |
412 | beacon_int = le16_to_cpu(ctx->timing.beacon_interval); | |
bde4530e JB |
413 | } else { |
414 | beacon_int = iwl_adjust_beacon_interval(beacon_int, | |
f8525e55 | 415 | priv->hw_params.max_beacon_itrvl * TIME_UNIT); |
bde4530e JB |
416 | ctx->timing.beacon_interval = cpu_to_le16(beacon_int); |
417 | } | |
2c2f3b33 TW |
418 | |
419 | tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */ | |
f8525e55 | 420 | interval_tm = beacon_int * TIME_UNIT; |
2c2f3b33 | 421 | rem = do_div(tsf, interval_tm); |
246ed355 | 422 | ctx->timing.beacon_init_val = cpu_to_le32(interval_tm - rem); |
2c2f3b33 | 423 | |
47313e34 | 424 | ctx->timing.dtim_period = vif ? (vif->bss_conf.dtim_period ?: 1) : 1; |
2491fa42 | 425 | |
2c2f3b33 TW |
426 | IWL_DEBUG_ASSOC(priv, |
427 | "beacon interval %d beacon timer %d beacon tim %d\n", | |
246ed355 JB |
428 | le16_to_cpu(ctx->timing.beacon_interval), |
429 | le32_to_cpu(ctx->timing.beacon_init_val), | |
430 | le16_to_cpu(ctx->timing.atim_window)); | |
948f5a2f | 431 | |
8f2d3d2a | 432 | return iwl_send_cmd_pdu(priv, ctx->rxon_timing_cmd, |
246ed355 | 433 | sizeof(ctx->timing), &ctx->timing); |
2c2f3b33 | 434 | } |
948f5a2f | 435 | EXPORT_SYMBOL(iwl_send_rxon_timing); |
2c2f3b33 | 436 | |
246ed355 JB |
437 | void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, struct iwl_rxon_context *ctx, |
438 | int hw_decrypt) | |
8ccde88a | 439 | { |
246ed355 | 440 | struct iwl_rxon_cmd *rxon = &ctx->staging; |
8ccde88a SO |
441 | |
442 | if (hw_decrypt) | |
443 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; | |
444 | else | |
445 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; | |
446 | ||
447 | } | |
448 | EXPORT_SYMBOL(iwl_set_rxon_hwcrypto); | |
449 | ||
dacefedb | 450 | /* validate RXON structure is valid */ |
246ed355 | 451 | int iwl_check_rxon_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx) |
8ccde88a | 452 | { |
246ed355 | 453 | struct iwl_rxon_cmd *rxon = &ctx->staging; |
dacefedb | 454 | bool error = false; |
8ccde88a SO |
455 | |
456 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { | |
dacefedb JB |
457 | if (rxon->flags & RXON_FLG_TGJ_NARROW_BAND_MSK) { |
458 | IWL_WARN(priv, "check 2.4G: wrong narrow\n"); | |
459 | error = true; | |
460 | } | |
461 | if (rxon->flags & RXON_FLG_RADAR_DETECT_MSK) { | |
462 | IWL_WARN(priv, "check 2.4G: wrong radar\n"); | |
463 | error = true; | |
464 | } | |
8ccde88a | 465 | } else { |
dacefedb JB |
466 | if (!(rxon->flags & RXON_FLG_SHORT_SLOT_MSK)) { |
467 | IWL_WARN(priv, "check 5.2G: not short slot!\n"); | |
468 | error = true; | |
469 | } | |
470 | if (rxon->flags & RXON_FLG_CCK_MSK) { | |
471 | IWL_WARN(priv, "check 5.2G: CCK!\n"); | |
472 | error = true; | |
473 | } | |
474 | } | |
475 | if ((rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1) { | |
476 | IWL_WARN(priv, "mac/bssid mcast!\n"); | |
477 | error = true; | |
8ccde88a | 478 | } |
8ccde88a SO |
479 | |
480 | /* make sure basic rates 6Mbps and 1Mbps are supported */ | |
dacefedb JB |
481 | if ((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0 && |
482 | (rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0) { | |
483 | IWL_WARN(priv, "neither 1 nor 6 are basic\n"); | |
484 | error = true; | |
485 | } | |
8ccde88a | 486 | |
dacefedb JB |
487 | if (le16_to_cpu(rxon->assoc_id) > 2007) { |
488 | IWL_WARN(priv, "aid > 2007\n"); | |
489 | error = true; | |
490 | } | |
8ccde88a | 491 | |
dacefedb JB |
492 | if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) |
493 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) { | |
494 | IWL_WARN(priv, "CCK and short slot\n"); | |
495 | error = true; | |
496 | } | |
8ccde88a | 497 | |
dacefedb JB |
498 | if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) |
499 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) { | |
500 | IWL_WARN(priv, "CCK and auto detect"); | |
501 | error = true; | |
502 | } | |
8ccde88a | 503 | |
dacefedb JB |
504 | if ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | |
505 | RXON_FLG_TGG_PROTECT_MSK)) == | |
506 | RXON_FLG_TGG_PROTECT_MSK) { | |
507 | IWL_WARN(priv, "TGg but no auto-detect\n"); | |
508 | error = true; | |
509 | } | |
8ccde88a SO |
510 | |
511 | if (error) | |
512 | IWL_WARN(priv, "Tuning to channel %d\n", | |
513 | le16_to_cpu(rxon->channel)); | |
514 | ||
515 | if (error) { | |
dacefedb JB |
516 | IWL_ERR(priv, "Invalid RXON\n"); |
517 | return -EINVAL; | |
8ccde88a SO |
518 | } |
519 | return 0; | |
520 | } | |
521 | EXPORT_SYMBOL(iwl_check_rxon_cmd); | |
522 | ||
523 | /** | |
524 | * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed | |
525 | * @priv: staging_rxon is compared to active_rxon | |
526 | * | |
527 | * If the RXON structure is changing enough to require a new tune, | |
528 | * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that | |
529 | * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required. | |
530 | */ | |
246ed355 JB |
531 | int iwl_full_rxon_required(struct iwl_priv *priv, |
532 | struct iwl_rxon_context *ctx) | |
8ccde88a | 533 | { |
246ed355 JB |
534 | const struct iwl_rxon_cmd *staging = &ctx->staging; |
535 | const struct iwl_rxon_cmd *active = &ctx->active; | |
536 | ||
537 | #define CHK(cond) \ | |
538 | if ((cond)) { \ | |
539 | IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \ | |
540 | return 1; \ | |
541 | } | |
542 | ||
543 | #define CHK_NEQ(c1, c2) \ | |
544 | if ((c1) != (c2)) { \ | |
545 | IWL_DEBUG_INFO(priv, "need full RXON - " \ | |
546 | #c1 " != " #c2 " - %d != %d\n", \ | |
547 | (c1), (c2)); \ | |
548 | return 1; \ | |
549 | } | |
8ccde88a SO |
550 | |
551 | /* These items are only settable from the full RXON command */ | |
246ed355 JB |
552 | CHK(!iwl_is_associated_ctx(ctx)); |
553 | CHK(compare_ether_addr(staging->bssid_addr, active->bssid_addr)); | |
554 | CHK(compare_ether_addr(staging->node_addr, active->node_addr)); | |
555 | CHK(compare_ether_addr(staging->wlap_bssid_addr, | |
556 | active->wlap_bssid_addr)); | |
557 | CHK_NEQ(staging->dev_type, active->dev_type); | |
558 | CHK_NEQ(staging->channel, active->channel); | |
559 | CHK_NEQ(staging->air_propagation, active->air_propagation); | |
560 | CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates, | |
561 | active->ofdm_ht_single_stream_basic_rates); | |
562 | CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates, | |
563 | active->ofdm_ht_dual_stream_basic_rates); | |
564 | CHK_NEQ(staging->ofdm_ht_triple_stream_basic_rates, | |
565 | active->ofdm_ht_triple_stream_basic_rates); | |
566 | CHK_NEQ(staging->assoc_id, active->assoc_id); | |
8ccde88a SO |
567 | |
568 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can | |
569 | * be updated with the RXON_ASSOC command -- however only some | |
570 | * flag transitions are allowed using RXON_ASSOC */ | |
571 | ||
572 | /* Check if we are not switching bands */ | |
246ed355 JB |
573 | CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK, |
574 | active->flags & RXON_FLG_BAND_24G_MSK); | |
8ccde88a SO |
575 | |
576 | /* Check if we are switching association toggle */ | |
246ed355 JB |
577 | CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK, |
578 | active->filter_flags & RXON_FILTER_ASSOC_MSK); | |
579 | ||
580 | #undef CHK | |
581 | #undef CHK_NEQ | |
8ccde88a SO |
582 | |
583 | return 0; | |
584 | } | |
585 | EXPORT_SYMBOL(iwl_full_rxon_required); | |
586 | ||
76d04815 JB |
587 | u8 iwl_rate_get_lowest_plcp(struct iwl_priv *priv, |
588 | struct iwl_rxon_context *ctx) | |
8ccde88a | 589 | { |
4a02886b JB |
590 | /* |
591 | * Assign the lowest rate -- should really get this from | |
592 | * the beacon skb from mac80211. | |
593 | */ | |
246ed355 | 594 | if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK) |
8ccde88a SO |
595 | return IWL_RATE_1M_PLCP; |
596 | else | |
597 | return IWL_RATE_6M_PLCP; | |
598 | } | |
599 | EXPORT_SYMBOL(iwl_rate_get_lowest_plcp); | |
600 | ||
246ed355 JB |
601 | static void _iwl_set_rxon_ht(struct iwl_priv *priv, |
602 | struct iwl_ht_config *ht_conf, | |
603 | struct iwl_rxon_context *ctx) | |
47c5196e | 604 | { |
246ed355 | 605 | struct iwl_rxon_cmd *rxon = &ctx->staging; |
47c5196e | 606 | |
7e6a5886 | 607 | if (!ctx->ht.enabled) { |
a2b0f02e | 608 | rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK | |
42eb7c64 | 609 | RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK | |
7aafef1c | 610 | RXON_FLG_HT40_PROT_MSK | |
42eb7c64 | 611 | RXON_FLG_HT_PROT_MSK); |
47c5196e | 612 | return; |
42eb7c64 | 613 | } |
47c5196e | 614 | |
7e6a5886 | 615 | /* FIXME: if the definition of ht.protection changed, the "translation" |
a2b0f02e WYG |
616 | * will be needed for rxon->flags |
617 | */ | |
7e6a5886 | 618 | rxon->flags |= cpu_to_le32(ctx->ht.protection << RXON_FLG_HT_OPERATING_MODE_POS); |
a2b0f02e WYG |
619 | |
620 | /* Set up channel bandwidth: | |
7aafef1c | 621 | * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */ |
a2b0f02e WYG |
622 | /* clear the HT channel mode before set the mode */ |
623 | rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK | | |
624 | RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK); | |
7e6a5886 | 625 | if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) { |
7aafef1c | 626 | /* pure ht40 */ |
7e6a5886 | 627 | if (ctx->ht.protection == IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) { |
a2b0f02e | 628 | rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40; |
508b08e7 | 629 | /* Note: control channel is opposite of extension channel */ |
7e6a5886 | 630 | switch (ctx->ht.extension_chan_offset) { |
508b08e7 WYG |
631 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: |
632 | rxon->flags &= ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK; | |
633 | break; | |
634 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: | |
635 | rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK; | |
636 | break; | |
637 | } | |
638 | } else { | |
a2b0f02e | 639 | /* Note: control channel is opposite of extension channel */ |
7e6a5886 | 640 | switch (ctx->ht.extension_chan_offset) { |
a2b0f02e WYG |
641 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: |
642 | rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK); | |
643 | rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED; | |
644 | break; | |
645 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: | |
646 | rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK; | |
647 | rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED; | |
648 | break; | |
649 | case IEEE80211_HT_PARAM_CHA_SEC_NONE: | |
650 | default: | |
651 | /* channel location only valid if in Mixed mode */ | |
652 | IWL_ERR(priv, "invalid extension channel offset\n"); | |
653 | break; | |
654 | } | |
655 | } | |
656 | } else { | |
657 | rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY; | |
47c5196e TW |
658 | } |
659 | ||
45823531 | 660 | if (priv->cfg->ops->hcmd->set_rxon_chain) |
246ed355 | 661 | priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx); |
47c5196e | 662 | |
02bb1bea | 663 | IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X " |
ae5eb026 | 664 | "extension channel offset 0x%x\n", |
7e6a5886 JB |
665 | le32_to_cpu(rxon->flags), ctx->ht.protection, |
666 | ctx->ht.extension_chan_offset); | |
47c5196e | 667 | } |
246ed355 JB |
668 | |
669 | void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf) | |
670 | { | |
671 | struct iwl_rxon_context *ctx; | |
672 | ||
673 | for_each_context(priv, ctx) | |
674 | _iwl_set_rxon_ht(priv, ht_conf, ctx); | |
675 | } | |
47c5196e TW |
676 | EXPORT_SYMBOL(iwl_set_rxon_ht); |
677 | ||
246ed355 | 678 | /* Return valid, unused, channel for a passive scan to reset the RF */ |
14023641 | 679 | u8 iwl_get_single_channel_number(struct iwl_priv *priv, |
246ed355 | 680 | enum ieee80211_band band) |
14023641 AK |
681 | { |
682 | const struct iwl_channel_info *ch_info; | |
683 | int i; | |
684 | u8 channel = 0; | |
246ed355 JB |
685 | u8 min, max; |
686 | struct iwl_rxon_context *ctx; | |
14023641 | 687 | |
14023641 | 688 | if (band == IEEE80211_BAND_5GHZ) { |
246ed355 JB |
689 | min = 14; |
690 | max = priv->channel_count; | |
14023641 | 691 | } else { |
246ed355 JB |
692 | min = 0; |
693 | max = 14; | |
694 | } | |
695 | ||
696 | for (i = min; i < max; i++) { | |
697 | bool busy = false; | |
698 | ||
699 | for_each_context(priv, ctx) { | |
700 | busy = priv->channel_info[i].channel == | |
701 | le16_to_cpu(ctx->staging.channel); | |
702 | if (busy) | |
703 | break; | |
14023641 | 704 | } |
246ed355 JB |
705 | |
706 | if (busy) | |
707 | continue; | |
708 | ||
709 | channel = priv->channel_info[i].channel; | |
710 | ch_info = iwl_get_channel_info(priv, band, channel); | |
711 | if (is_channel_valid(ch_info)) | |
712 | break; | |
14023641 AK |
713 | } |
714 | ||
715 | return channel; | |
716 | } | |
717 | EXPORT_SYMBOL(iwl_get_single_channel_number); | |
718 | ||
bf85ea4f | 719 | /** |
3edb5fd6 SZ |
720 | * iwl_set_rxon_channel - Set the band and channel values in staging RXON |
721 | * @ch: requested channel as a pointer to struct ieee80211_channel | |
bf85ea4f | 722 | |
bf85ea4f | 723 | * NOTE: Does not commit to the hardware; it sets appropriate bit fields |
3edb5fd6 | 724 | * in the staging RXON flag structure based on the ch->band |
bf85ea4f | 725 | */ |
246ed355 JB |
726 | int iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch, |
727 | struct iwl_rxon_context *ctx) | |
bf85ea4f | 728 | { |
17e72782 | 729 | enum ieee80211_band band = ch->band; |
81e95430 | 730 | u16 channel = ch->hw_value; |
17e72782 | 731 | |
246ed355 | 732 | if ((le16_to_cpu(ctx->staging.channel) == channel) && |
bf85ea4f AK |
733 | (priv->band == band)) |
734 | return 0; | |
735 | ||
246ed355 | 736 | ctx->staging.channel = cpu_to_le16(channel); |
bf85ea4f | 737 | if (band == IEEE80211_BAND_5GHZ) |
246ed355 | 738 | ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK; |
bf85ea4f | 739 | else |
246ed355 | 740 | ctx->staging.flags |= RXON_FLG_BAND_24G_MSK; |
bf85ea4f AK |
741 | |
742 | priv->band = band; | |
743 | ||
e1623446 | 744 | IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band); |
bf85ea4f AK |
745 | |
746 | return 0; | |
747 | } | |
c7de35cd | 748 | EXPORT_SYMBOL(iwl_set_rxon_channel); |
bf85ea4f | 749 | |
79d07325 | 750 | void iwl_set_flags_for_band(struct iwl_priv *priv, |
246ed355 | 751 | struct iwl_rxon_context *ctx, |
79d07325 WYG |
752 | enum ieee80211_band band, |
753 | struct ieee80211_vif *vif) | |
8ccde88a SO |
754 | { |
755 | if (band == IEEE80211_BAND_5GHZ) { | |
246ed355 | 756 | ctx->staging.flags &= |
8ccde88a SO |
757 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
758 | | RXON_FLG_CCK_MSK); | |
246ed355 | 759 | ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK; |
8ccde88a SO |
760 | } else { |
761 | /* Copied from iwl_post_associate() */ | |
c213d745 | 762 | if (vif && vif->bss_conf.use_short_slot) |
246ed355 | 763 | ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK; |
8ccde88a | 764 | else |
246ed355 | 765 | ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
8ccde88a | 766 | |
246ed355 JB |
767 | ctx->staging.flags |= RXON_FLG_BAND_24G_MSK; |
768 | ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK; | |
769 | ctx->staging.flags &= ~RXON_FLG_CCK_MSK; | |
8ccde88a SO |
770 | } |
771 | } | |
79d07325 | 772 | EXPORT_SYMBOL(iwl_set_flags_for_band); |
8ccde88a SO |
773 | |
774 | /* | |
775 | * initialize rxon structure with default values from eeprom | |
776 | */ | |
1dda6d28 | 777 | void iwl_connection_init_rx_config(struct iwl_priv *priv, |
d0fe478c | 778 | struct iwl_rxon_context *ctx) |
8ccde88a SO |
779 | { |
780 | const struct iwl_channel_info *ch_info; | |
781 | ||
246ed355 | 782 | memset(&ctx->staging, 0, sizeof(ctx->staging)); |
8ccde88a | 783 | |
d0fe478c JB |
784 | if (!ctx->vif) { |
785 | ctx->staging.dev_type = ctx->unused_devtype; | |
786 | } else switch (ctx->vif->type) { | |
8ccde88a | 787 | case NL80211_IFTYPE_AP: |
d0fe478c | 788 | ctx->staging.dev_type = ctx->ap_devtype; |
8ccde88a SO |
789 | break; |
790 | ||
791 | case NL80211_IFTYPE_STATION: | |
d0fe478c | 792 | ctx->staging.dev_type = ctx->station_devtype; |
246ed355 | 793 | ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
8ccde88a SO |
794 | break; |
795 | ||
796 | case NL80211_IFTYPE_ADHOC: | |
d0fe478c | 797 | ctx->staging.dev_type = ctx->ibss_devtype; |
246ed355 JB |
798 | ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
799 | ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK | | |
8ccde88a SO |
800 | RXON_FILTER_ACCEPT_GRP_MSK; |
801 | break; | |
802 | ||
8ccde88a | 803 | default: |
d0fe478c JB |
804 | IWL_ERR(priv, "Unsupported interface type %d\n", |
805 | ctx->vif->type); | |
8ccde88a SO |
806 | break; |
807 | } | |
808 | ||
809 | #if 0 | |
810 | /* TODO: Figure out when short_preamble would be set and cache from | |
811 | * that */ | |
812 | if (!hw_to_local(priv->hw)->short_preamble) | |
246ed355 | 813 | ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
8ccde88a | 814 | else |
246ed355 | 815 | ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
8ccde88a SO |
816 | #endif |
817 | ||
818 | ch_info = iwl_get_channel_info(priv, priv->band, | |
246ed355 | 819 | le16_to_cpu(ctx->active.channel)); |
8ccde88a SO |
820 | |
821 | if (!ch_info) | |
822 | ch_info = &priv->channel_info[0]; | |
823 | ||
246ed355 | 824 | ctx->staging.channel = cpu_to_le16(ch_info->channel); |
8ccde88a SO |
825 | priv->band = ch_info->band; |
826 | ||
d0fe478c | 827 | iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif); |
8ccde88a | 828 | |
246ed355 | 829 | ctx->staging.ofdm_basic_rates = |
8ccde88a | 830 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
246ed355 | 831 | ctx->staging.cck_basic_rates = |
8ccde88a SO |
832 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
833 | ||
a2b0f02e | 834 | /* clear both MIX and PURE40 mode flag */ |
246ed355 | 835 | ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED | |
a2b0f02e | 836 | RXON_FLG_CHANNEL_MODE_PURE_40); |
d0fe478c JB |
837 | if (ctx->vif) |
838 | memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN); | |
7684c408 | 839 | |
246ed355 JB |
840 | ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff; |
841 | ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff; | |
842 | ctx->staging.ofdm_ht_triple_stream_basic_rates = 0xff; | |
8ccde88a SO |
843 | } |
844 | EXPORT_SYMBOL(iwl_connection_init_rx_config); | |
845 | ||
79d07325 | 846 | void iwl_set_rate(struct iwl_priv *priv) |
8ccde88a SO |
847 | { |
848 | const struct ieee80211_supported_band *hw = NULL; | |
849 | struct ieee80211_rate *rate; | |
246ed355 | 850 | struct iwl_rxon_context *ctx; |
8ccde88a SO |
851 | int i; |
852 | ||
853 | hw = iwl_get_hw_mode(priv, priv->band); | |
854 | if (!hw) { | |
855 | IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n"); | |
856 | return; | |
857 | } | |
858 | ||
859 | priv->active_rate = 0; | |
8ccde88a SO |
860 | |
861 | for (i = 0; i < hw->n_bitrates; i++) { | |
862 | rate = &(hw->bitrates[i]); | |
5027309b | 863 | if (rate->hw_value < IWL_RATE_COUNT_LEGACY) |
8ccde88a SO |
864 | priv->active_rate |= (1 << rate->hw_value); |
865 | } | |
866 | ||
4a02886b | 867 | IWL_DEBUG_RATE(priv, "Set active_rate = %0x\n", priv->active_rate); |
8ccde88a | 868 | |
246ed355 JB |
869 | for_each_context(priv, ctx) { |
870 | ctx->staging.cck_basic_rates = | |
871 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; | |
4a02886b | 872 | |
246ed355 JB |
873 | ctx->staging.ofdm_basic_rates = |
874 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; | |
875 | } | |
8ccde88a | 876 | } |
79d07325 WYG |
877 | EXPORT_SYMBOL(iwl_set_rate); |
878 | ||
879 | void iwl_chswitch_done(struct iwl_priv *priv, bool is_success) | |
880 | { | |
8bd413e6 JB |
881 | /* |
882 | * MULTI-FIXME | |
883 | * See iwl_mac_channel_switch. | |
884 | */ | |
885 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; | |
886 | ||
79d07325 WYG |
887 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
888 | return; | |
889 | ||
890 | if (priv->switch_rxon.switch_in_progress) { | |
8bd413e6 | 891 | ieee80211_chswitch_done(ctx->vif, is_success); |
79d07325 WYG |
892 | mutex_lock(&priv->mutex); |
893 | priv->switch_rxon.switch_in_progress = false; | |
894 | mutex_unlock(&priv->mutex); | |
895 | } | |
896 | } | |
897 | EXPORT_SYMBOL(iwl_chswitch_done); | |
8ccde88a SO |
898 | |
899 | void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb) | |
900 | { | |
2f301227 | 901 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
8ccde88a | 902 | struct iwl_csa_notification *csa = &(pkt->u.csa_notif); |
8bd413e6 JB |
903 | /* |
904 | * MULTI-FIXME | |
905 | * See iwl_mac_channel_switch. | |
906 | */ | |
246ed355 | 907 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; |
246ed355 | 908 | struct iwl_rxon_cmd *rxon = (void *)&ctx->active; |
4a56e965 | 909 | |
0924e519 WYG |
910 | if (priv->switch_rxon.switch_in_progress) { |
911 | if (!le32_to_cpu(csa->status) && | |
912 | (csa->channel == priv->switch_rxon.channel)) { | |
913 | rxon->channel = csa->channel; | |
246ed355 | 914 | ctx->staging.channel = csa->channel; |
0924e519 WYG |
915 | IWL_DEBUG_11H(priv, "CSA notif: channel %d\n", |
916 | le16_to_cpu(csa->channel)); | |
79d07325 WYG |
917 | iwl_chswitch_done(priv, true); |
918 | } else { | |
0924e519 WYG |
919 | IWL_ERR(priv, "CSA notif (fail) : channel %d\n", |
920 | le16_to_cpu(csa->channel)); | |
79d07325 WYG |
921 | iwl_chswitch_done(priv, false); |
922 | } | |
0924e519 | 923 | } |
8ccde88a SO |
924 | } |
925 | EXPORT_SYMBOL(iwl_rx_csa); | |
926 | ||
927 | #ifdef CONFIG_IWLWIFI_DEBUG | |
246ed355 JB |
928 | void iwl_print_rx_config_cmd(struct iwl_priv *priv, |
929 | struct iwl_rxon_context *ctx) | |
8ccde88a | 930 | { |
246ed355 | 931 | struct iwl_rxon_cmd *rxon = &ctx->staging; |
8ccde88a | 932 | |
e1623446 | 933 | IWL_DEBUG_RADIO(priv, "RX CONFIG:\n"); |
3d816c77 | 934 | iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
e1623446 TW |
935 | IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); |
936 | IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); | |
937 | IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n", | |
8ccde88a | 938 | le32_to_cpu(rxon->filter_flags)); |
e1623446 TW |
939 | IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type); |
940 | IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n", | |
8ccde88a | 941 | rxon->ofdm_basic_rates); |
e1623446 TW |
942 | IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates); |
943 | IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr); | |
944 | IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr); | |
945 | IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id)); | |
8ccde88a | 946 | } |
a643565e | 947 | EXPORT_SYMBOL(iwl_print_rx_config_cmd); |
6686d17e | 948 | #endif |
8ccde88a SO |
949 | /** |
950 | * iwl_irq_handle_error - called for HW or SW error interrupt from card | |
951 | */ | |
952 | void iwl_irq_handle_error(struct iwl_priv *priv) | |
953 | { | |
954 | /* Set the FW error flag -- cleared on iwl_down */ | |
955 | set_bit(STATUS_FW_ERROR, &priv->status); | |
956 | ||
957 | /* Cancel currently queued command. */ | |
958 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); | |
959 | ||
50619ac9 WYG |
960 | /* W/A for WiFi/WiMAX coex and WiMAX own the RF */ |
961 | if (priv->cfg->internal_wimax_coex && | |
962 | (!(iwl_read_prph(priv, APMG_CLK_CTRL_REG) & | |
963 | APMS_CLK_VAL_MRB_FUNC_MODE) || | |
964 | (iwl_read_prph(priv, APMG_PS_CTRL_REG) & | |
965 | APMG_PS_CTRL_VAL_RESET_REQ))) { | |
966 | wake_up_interruptible(&priv->wait_command_queue); | |
967 | /* | |
968 | *Keep the restart process from trying to send host | |
969 | * commands by clearing the INIT status bit | |
970 | */ | |
971 | clear_bit(STATUS_READY, &priv->status); | |
972 | IWL_ERR(priv, "RF is used by WiMAX\n"); | |
973 | return; | |
974 | } | |
975 | ||
459bc732 SZ |
976 | IWL_ERR(priv, "Loaded firmware version: %s\n", |
977 | priv->hw->wiphy->fw_version); | |
978 | ||
3a3ff72c | 979 | priv->cfg->ops->lib->dump_nic_error_log(priv); |
696bdee3 WYG |
980 | if (priv->cfg->ops->lib->dump_csr) |
981 | priv->cfg->ops->lib->dump_csr(priv); | |
1b3eb823 WYG |
982 | if (priv->cfg->ops->lib->dump_fh) |
983 | priv->cfg->ops->lib->dump_fh(priv, NULL, false); | |
b03d7d0f | 984 | priv->cfg->ops->lib->dump_nic_event_log(priv, false, NULL, false); |
8ccde88a | 985 | #ifdef CONFIG_IWLWIFI_DEBUG |
c341ddb2 | 986 | if (iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) |
246ed355 JB |
987 | iwl_print_rx_config_cmd(priv, |
988 | &priv->contexts[IWL_RXON_CTX_BSS]); | |
8ccde88a SO |
989 | #endif |
990 | ||
991 | wake_up_interruptible(&priv->wait_command_queue); | |
992 | ||
993 | /* Keep the restart process from trying to send host | |
994 | * commands by clearing the INIT status bit */ | |
995 | clear_bit(STATUS_READY, &priv->status); | |
996 | ||
997 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { | |
e1623446 | 998 | IWL_DEBUG(priv, IWL_DL_FW_ERRORS, |
8ccde88a SO |
999 | "Restarting adapter due to uCode error.\n"); |
1000 | ||
8ccde88a SO |
1001 | if (priv->cfg->mod_params->restart_fw) |
1002 | queue_work(priv->workqueue, &priv->restart); | |
1003 | } | |
1004 | } | |
1005 | EXPORT_SYMBOL(iwl_irq_handle_error); | |
1006 | ||
f8e200de | 1007 | static int iwl_apm_stop_master(struct iwl_priv *priv) |
d68b603c | 1008 | { |
5220af0c | 1009 | int ret = 0; |
d68b603c | 1010 | |
5220af0c | 1011 | /* stop device's busmaster DMA activity */ |
d68b603c AK |
1012 | iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER); |
1013 | ||
5220af0c | 1014 | ret = iwl_poll_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_MASTER_DISABLED, |
d68b603c | 1015 | CSR_RESET_REG_FLAG_MASTER_DISABLED, 100); |
5220af0c BC |
1016 | if (ret) |
1017 | IWL_WARN(priv, "Master Disable Timed Out, 100 usec\n"); | |
d68b603c | 1018 | |
d68b603c AK |
1019 | IWL_DEBUG_INFO(priv, "stop master\n"); |
1020 | ||
5220af0c | 1021 | return ret; |
d68b603c | 1022 | } |
d68b603c AK |
1023 | |
1024 | void iwl_apm_stop(struct iwl_priv *priv) | |
1025 | { | |
fadb3582 BC |
1026 | IWL_DEBUG_INFO(priv, "Stop card, put in low power state\n"); |
1027 | ||
5220af0c | 1028 | /* Stop device's DMA activity */ |
d68b603c AK |
1029 | iwl_apm_stop_master(priv); |
1030 | ||
5220af0c | 1031 | /* Reset the entire device */ |
d68b603c AK |
1032 | iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); |
1033 | ||
1034 | udelay(10); | |
5220af0c BC |
1035 | |
1036 | /* | |
1037 | * Clear "initialization complete" bit to move adapter from | |
1038 | * D0A* (powered-up Active) --> D0U* (Uninitialized) state. | |
1039 | */ | |
d68b603c | 1040 | iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); |
d68b603c AK |
1041 | } |
1042 | EXPORT_SYMBOL(iwl_apm_stop); | |
1043 | ||
fadb3582 BC |
1044 | |
1045 | /* | |
1046 | * Start up NIC's basic functionality after it has been reset | |
1047 | * (e.g. after platform boot, or shutdown via iwl_apm_stop()) | |
1048 | * NOTE: This does not load uCode nor start the embedded processor | |
1049 | */ | |
1050 | int iwl_apm_init(struct iwl_priv *priv) | |
1051 | { | |
1052 | int ret = 0; | |
1053 | u16 lctl; | |
1054 | ||
1055 | IWL_DEBUG_INFO(priv, "Init card's basic functions\n"); | |
1056 | ||
1057 | /* | |
1058 | * Use "set_bit" below rather than "write", to preserve any hardware | |
1059 | * bits already set by default after reset. | |
1060 | */ | |
1061 | ||
1062 | /* Disable L0S exit timer (platform NMI Work/Around) */ | |
1063 | iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS, | |
1064 | CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER); | |
1065 | ||
1066 | /* | |
1067 | * Disable L0s without affecting L1; | |
1068 | * don't wait for ICH L0s (ICH bug W/A) | |
1069 | */ | |
1070 | iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS, | |
1071 | CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX); | |
1072 | ||
1073 | /* Set FH wait threshold to maximum (HW error during stress W/A) */ | |
1074 | iwl_set_bit(priv, CSR_DBG_HPET_MEM_REG, CSR_DBG_HPET_MEM_REG_VAL); | |
1075 | ||
1076 | /* | |
1077 | * Enable HAP INTA (interrupt from management bus) to | |
1078 | * wake device's PCI Express link L1a -> L0s | |
1079 | * NOTE: This is no-op for 3945 (non-existant bit) | |
1080 | */ | |
1081 | iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG, | |
1082 | CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A); | |
1083 | ||
1084 | /* | |
a6c5c731 BC |
1085 | * HW bug W/A for instability in PCIe bus L0->L0S->L1 transition. |
1086 | * Check if BIOS (or OS) enabled L1-ASPM on this device. | |
1087 | * If so (likely), disable L0S, so device moves directly L0->L1; | |
1088 | * costs negligible amount of power savings. | |
1089 | * If not (unlikely), enable L0S, so there is at least some | |
1090 | * power savings, even without L1. | |
fadb3582 | 1091 | */ |
7cb1b088 | 1092 | if (priv->cfg->base_params->set_l0s) { |
fadb3582 BC |
1093 | lctl = iwl_pcie_link_ctl(priv); |
1094 | if ((lctl & PCI_CFG_LINK_CTRL_VAL_L1_EN) == | |
1095 | PCI_CFG_LINK_CTRL_VAL_L1_EN) { | |
1096 | /* L1-ASPM enabled; disable(!) L0S */ | |
1097 | iwl_set_bit(priv, CSR_GIO_REG, | |
1098 | CSR_GIO_REG_VAL_L0S_ENABLED); | |
1099 | IWL_DEBUG_POWER(priv, "L1 Enabled; Disabling L0S\n"); | |
1100 | } else { | |
1101 | /* L1-ASPM disabled; enable(!) L0S */ | |
1102 | iwl_clear_bit(priv, CSR_GIO_REG, | |
1103 | CSR_GIO_REG_VAL_L0S_ENABLED); | |
1104 | IWL_DEBUG_POWER(priv, "L1 Disabled; Enabling L0S\n"); | |
1105 | } | |
1106 | } | |
1107 | ||
1108 | /* Configure analog phase-lock-loop before activating to D0A */ | |
7cb1b088 WYG |
1109 | if (priv->cfg->base_params->pll_cfg_val) |
1110 | iwl_set_bit(priv, CSR_ANA_PLL_CFG, | |
1111 | priv->cfg->base_params->pll_cfg_val); | |
fadb3582 BC |
1112 | |
1113 | /* | |
1114 | * Set "initialization complete" bit to move adapter from | |
1115 | * D0U* --> D0A* (powered-up active) state. | |
1116 | */ | |
1117 | iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); | |
1118 | ||
1119 | /* | |
1120 | * Wait for clock stabilization; once stabilized, access to | |
1121 | * device-internal resources is supported, e.g. iwl_write_prph() | |
1122 | * and accesses to uCode SRAM. | |
1123 | */ | |
1124 | ret = iwl_poll_bit(priv, CSR_GP_CNTRL, | |
1125 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, | |
1126 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000); | |
1127 | if (ret < 0) { | |
1128 | IWL_DEBUG_INFO(priv, "Failed to init the card\n"); | |
1129 | goto out; | |
1130 | } | |
1131 | ||
1132 | /* | |
1133 | * Enable DMA and BSM (if used) clocks, wait for them to stabilize. | |
1134 | * BSM (Boostrap State Machine) is only in 3945 and 4965; | |
1135 | * later devices (i.e. 5000 and later) have non-volatile SRAM, | |
1136 | * and don't need BSM to restore data after power-saving sleep. | |
1137 | * | |
1138 | * Write to "CLK_EN_REG"; "1" bits enable clocks, while "0" bits | |
1139 | * do not disable clocks. This preserves any hardware bits already | |
1140 | * set by default in "CLK_CTRL_REG" after reset. | |
1141 | */ | |
7cb1b088 | 1142 | if (priv->cfg->base_params->use_bsm) |
fadb3582 BC |
1143 | iwl_write_prph(priv, APMG_CLK_EN_REG, |
1144 | APMG_CLK_VAL_DMA_CLK_RQT | APMG_CLK_VAL_BSM_CLK_RQT); | |
1145 | else | |
1146 | iwl_write_prph(priv, APMG_CLK_EN_REG, | |
1147 | APMG_CLK_VAL_DMA_CLK_RQT); | |
1148 | udelay(20); | |
1149 | ||
1150 | /* Disable L1-Active */ | |
1151 | iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG, | |
1152 | APMG_PCIDEV_STT_VAL_L1_ACT_DIS); | |
1153 | ||
1154 | out: | |
1155 | return ret; | |
1156 | } | |
1157 | EXPORT_SYMBOL(iwl_apm_init); | |
1158 | ||
1159 | ||
630fe9b6 TW |
1160 | int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force) |
1161 | { | |
a25a66ac SG |
1162 | int ret; |
1163 | s8 prev_tx_power; | |
1164 | ||
1165 | lockdep_assert_held(&priv->mutex); | |
1166 | ||
1167 | if (priv->tx_power_user_lmt == tx_power && !force) | |
1168 | return 0; | |
1169 | ||
1170 | if (!priv->cfg->ops->lib->send_tx_power) | |
1171 | return -EOPNOTSUPP; | |
5eadd94b | 1172 | |
b744cb79 WYG |
1173 | if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) { |
1174 | IWL_WARN(priv, | |
1175 | "Requested user TXPOWER %d below lower limit %d.\n", | |
daf518de | 1176 | tx_power, |
b744cb79 | 1177 | IWLAGN_TX_POWER_TARGET_POWER_MIN); |
630fe9b6 TW |
1178 | return -EINVAL; |
1179 | } | |
1180 | ||
dc1b0973 | 1181 | if (tx_power > priv->tx_power_device_lmt) { |
08f2d58d WYG |
1182 | IWL_WARN(priv, |
1183 | "Requested user TXPOWER %d above upper limit %d.\n", | |
dc1b0973 | 1184 | tx_power, priv->tx_power_device_lmt); |
630fe9b6 TW |
1185 | return -EINVAL; |
1186 | } | |
1187 | ||
a25a66ac SG |
1188 | if (!iwl_is_ready_rf(priv)) |
1189 | return -EIO; | |
630fe9b6 | 1190 | |
a25a66ac SG |
1191 | /* scan complete use tx_power_next, need to be updated */ |
1192 | priv->tx_power_next = tx_power; | |
1193 | if (test_bit(STATUS_SCANNING, &priv->status) && !force) { | |
1194 | IWL_DEBUG_INFO(priv, "Deferring tx power set while scanning\n"); | |
1195 | return 0; | |
5eadd94b | 1196 | } |
630fe9b6 | 1197 | |
a25a66ac SG |
1198 | prev_tx_power = priv->tx_power_user_lmt; |
1199 | priv->tx_power_user_lmt = tx_power; | |
1200 | ||
1201 | ret = priv->cfg->ops->lib->send_tx_power(priv); | |
1202 | ||
1203 | /* if fail to set tx_power, restore the orig. tx power */ | |
1204 | if (ret) { | |
1205 | priv->tx_power_user_lmt = prev_tx_power; | |
1206 | priv->tx_power_next = prev_tx_power; | |
1207 | } | |
630fe9b6 TW |
1208 | return ret; |
1209 | } | |
1210 | EXPORT_SYMBOL(iwl_set_tx_power); | |
1211 | ||
65b52bde | 1212 | void iwl_send_bt_config(struct iwl_priv *priv) |
17f841cd SO |
1213 | { |
1214 | struct iwl_bt_cmd bt_cmd = { | |
456d0f76 WYG |
1215 | .lead_time = BT_LEAD_TIME_DEF, |
1216 | .max_kill = BT_MAX_KILL_DEF, | |
17f841cd SO |
1217 | .kill_ack_mask = 0, |
1218 | .kill_cts_mask = 0, | |
1219 | }; | |
1220 | ||
06702a73 WYG |
1221 | if (!bt_coex_active) |
1222 | bt_cmd.flags = BT_COEX_DISABLE; | |
1223 | else | |
1224 | bt_cmd.flags = BT_COEX_ENABLE; | |
1225 | ||
1226 | IWL_DEBUG_INFO(priv, "BT coex %s\n", | |
1227 | (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active"); | |
1228 | ||
65b52bde JB |
1229 | if (iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG, |
1230 | sizeof(struct iwl_bt_cmd), &bt_cmd)) | |
1231 | IWL_ERR(priv, "failed to send BT Coex Config\n"); | |
17f841cd SO |
1232 | } |
1233 | EXPORT_SYMBOL(iwl_send_bt_config); | |
1234 | ||
ef8d5529 | 1235 | int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear) |
49ea8596 | 1236 | { |
ef8d5529 WYG |
1237 | struct iwl_statistics_cmd statistics_cmd = { |
1238 | .configuration_flags = | |
1239 | clear ? IWL_STATS_CONF_CLEAR_STATS : 0, | |
49ea8596 | 1240 | }; |
ef8d5529 WYG |
1241 | |
1242 | if (flags & CMD_ASYNC) | |
1243 | return iwl_send_cmd_pdu_async(priv, REPLY_STATISTICS_CMD, | |
1244 | sizeof(struct iwl_statistics_cmd), | |
1245 | &statistics_cmd, NULL); | |
1246 | else | |
1247 | return iwl_send_cmd_pdu(priv, REPLY_STATISTICS_CMD, | |
1248 | sizeof(struct iwl_statistics_cmd), | |
1249 | &statistics_cmd); | |
49ea8596 EG |
1250 | } |
1251 | EXPORT_SYMBOL(iwl_send_statistics_request); | |
7e8c519e | 1252 | |
030f05ed AK |
1253 | void iwl_rx_pm_sleep_notif(struct iwl_priv *priv, |
1254 | struct iwl_rx_mem_buffer *rxb) | |
1255 | { | |
1256 | #ifdef CONFIG_IWLWIFI_DEBUG | |
2f301227 | 1257 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
030f05ed AK |
1258 | struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif); |
1259 | IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n", | |
1260 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); | |
1261 | #endif | |
1262 | } | |
1263 | EXPORT_SYMBOL(iwl_rx_pm_sleep_notif); | |
1264 | ||
1265 | void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv, | |
1266 | struct iwl_rx_mem_buffer *rxb) | |
1267 | { | |
2f301227 | 1268 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
396887a2 | 1269 | u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; |
030f05ed | 1270 | IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled " |
396887a2 DH |
1271 | "notification for %s:\n", len, |
1272 | get_cmd_string(pkt->hdr.cmd)); | |
1273 | iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, len); | |
030f05ed AK |
1274 | } |
1275 | EXPORT_SYMBOL(iwl_rx_pm_debug_statistics_notif); | |
261b9c33 AK |
1276 | |
1277 | void iwl_rx_reply_error(struct iwl_priv *priv, | |
1278 | struct iwl_rx_mem_buffer *rxb) | |
1279 | { | |
2f301227 | 1280 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
261b9c33 AK |
1281 | |
1282 | IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) " | |
1283 | "seq 0x%04X ser 0x%08X\n", | |
1284 | le32_to_cpu(pkt->u.err_resp.error_type), | |
1285 | get_cmd_string(pkt->u.err_resp.cmd_id), | |
1286 | pkt->u.err_resp.cmd_id, | |
1287 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), | |
1288 | le32_to_cpu(pkt->u.err_resp.error_info)); | |
1289 | } | |
1290 | EXPORT_SYMBOL(iwl_rx_reply_error); | |
1291 | ||
a83b9141 WYG |
1292 | void iwl_clear_isr_stats(struct iwl_priv *priv) |
1293 | { | |
1294 | memset(&priv->isr_stats, 0, sizeof(priv->isr_stats)); | |
1295 | } | |
a83b9141 | 1296 | |
488829f1 AK |
1297 | int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue, |
1298 | const struct ieee80211_tx_queue_params *params) | |
1299 | { | |
1300 | struct iwl_priv *priv = hw->priv; | |
8dfdb9d5 | 1301 | struct iwl_rxon_context *ctx; |
488829f1 AK |
1302 | unsigned long flags; |
1303 | int q; | |
1304 | ||
1305 | IWL_DEBUG_MAC80211(priv, "enter\n"); | |
1306 | ||
1307 | if (!iwl_is_ready_rf(priv)) { | |
1308 | IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n"); | |
1309 | return -EIO; | |
1310 | } | |
1311 | ||
1312 | if (queue >= AC_NUM) { | |
1313 | IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue); | |
1314 | return 0; | |
1315 | } | |
1316 | ||
1317 | q = AC_NUM - 1 - queue; | |
1318 | ||
1319 | spin_lock_irqsave(&priv->lock, flags); | |
1320 | ||
8dfdb9d5 JB |
1321 | /* |
1322 | * MULTI-FIXME | |
1323 | * This may need to be done per interface in nl80211/cfg80211/mac80211. | |
1324 | */ | |
1325 | for_each_context(priv, ctx) { | |
1326 | ctx->qos_data.def_qos_parm.ac[q].cw_min = | |
1327 | cpu_to_le16(params->cw_min); | |
1328 | ctx->qos_data.def_qos_parm.ac[q].cw_max = | |
1329 | cpu_to_le16(params->cw_max); | |
1330 | ctx->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; | |
1331 | ctx->qos_data.def_qos_parm.ac[q].edca_txop = | |
1332 | cpu_to_le16((params->txop * 32)); | |
1333 | ||
1334 | ctx->qos_data.def_qos_parm.ac[q].reserved1 = 0; | |
1335 | } | |
488829f1 AK |
1336 | |
1337 | spin_unlock_irqrestore(&priv->lock, flags); | |
1338 | ||
1339 | IWL_DEBUG_MAC80211(priv, "leave\n"); | |
1340 | return 0; | |
1341 | } | |
1342 | EXPORT_SYMBOL(iwl_mac_conf_tx); | |
5bbe233b | 1343 | |
a85d7cca JB |
1344 | int iwl_mac_tx_last_beacon(struct ieee80211_hw *hw) |
1345 | { | |
1346 | struct iwl_priv *priv = hw->priv; | |
1347 | ||
1348 | return priv->ibss_manager == IWL_IBSS_MANAGER; | |
1349 | } | |
1350 | EXPORT_SYMBOL_GPL(iwl_mac_tx_last_beacon); | |
1351 | ||
d4daaea6 | 1352 | static int iwl_set_mode(struct iwl_priv *priv, struct iwl_rxon_context *ctx) |
727882d6 | 1353 | { |
d0fe478c | 1354 | iwl_connection_init_rx_config(priv, ctx); |
727882d6 AK |
1355 | |
1356 | if (priv->cfg->ops->hcmd->set_rxon_chain) | |
246ed355 | 1357 | priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx); |
727882d6 | 1358 | |
246ed355 | 1359 | return iwlcore_commit_rxon(priv, ctx); |
727882d6 | 1360 | } |
727882d6 | 1361 | |
d4daaea6 JB |
1362 | static int iwl_setup_interface(struct iwl_priv *priv, |
1363 | struct iwl_rxon_context *ctx) | |
1364 | { | |
1365 | struct ieee80211_vif *vif = ctx->vif; | |
1366 | int err; | |
1367 | ||
1368 | lockdep_assert_held(&priv->mutex); | |
1369 | ||
1370 | /* | |
1371 | * This variable will be correct only when there's just | |
1372 | * a single context, but all code using it is for hardware | |
1373 | * that supports only one context. | |
1374 | */ | |
1375 | priv->iw_mode = vif->type; | |
1376 | ||
1377 | ctx->is_active = true; | |
1378 | ||
1379 | err = iwl_set_mode(priv, ctx); | |
1380 | if (err) { | |
1381 | if (!ctx->always_active) | |
1382 | ctx->is_active = false; | |
1383 | return err; | |
1384 | } | |
1385 | ||
1386 | if (priv->cfg->bt_params && priv->cfg->bt_params->advanced_bt_coexist && | |
1387 | vif->type == NL80211_IFTYPE_ADHOC) { | |
1388 | /* | |
1389 | * pretend to have high BT traffic as long as we | |
1390 | * are operating in IBSS mode, as this will cause | |
1391 | * the rate scaling etc. to behave as intended. | |
1392 | */ | |
1393 | priv->bt_traffic_load = IWL_BT_COEX_TRAFFIC_LOAD_HIGH; | |
1394 | } | |
1395 | ||
1396 | return 0; | |
1397 | } | |
1398 | ||
b55e75ed | 1399 | int iwl_mac_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
cbb6ab94 AK |
1400 | { |
1401 | struct iwl_priv *priv = hw->priv; | |
246ed355 | 1402 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; |
d0fe478c | 1403 | struct iwl_rxon_context *tmp, *ctx = NULL; |
d4daaea6 | 1404 | int err; |
cbb6ab94 | 1405 | |
3779db10 JB |
1406 | IWL_DEBUG_MAC80211(priv, "enter: type %d, addr %pM\n", |
1407 | vif->type, vif->addr); | |
cbb6ab94 | 1408 | |
47e28f41 JB |
1409 | mutex_lock(&priv->mutex); |
1410 | ||
4bd530f3 SG |
1411 | if (!iwl_is_ready_rf(priv)) { |
1412 | IWL_WARN(priv, "Try to add interface when device not ready\n"); | |
b55e75ed JB |
1413 | err = -EINVAL; |
1414 | goto out; | |
1415 | } | |
1416 | ||
d0fe478c JB |
1417 | for_each_context(priv, tmp) { |
1418 | u32 possible_modes = | |
1419 | tmp->interface_modes | tmp->exclusive_interface_modes; | |
1420 | ||
1421 | if (tmp->vif) { | |
1422 | /* check if this busy context is exclusive */ | |
1423 | if (tmp->exclusive_interface_modes & | |
1424 | BIT(tmp->vif->type)) { | |
1425 | err = -EINVAL; | |
1426 | goto out; | |
1427 | } | |
1428 | continue; | |
1429 | } | |
1430 | ||
1431 | if (!(possible_modes & BIT(vif->type))) | |
1432 | continue; | |
1433 | ||
1434 | /* have maybe usable context w/o interface */ | |
1435 | ctx = tmp; | |
1436 | break; | |
1437 | } | |
1438 | ||
1439 | if (!ctx) { | |
47e28f41 JB |
1440 | err = -EOPNOTSUPP; |
1441 | goto out; | |
cbb6ab94 AK |
1442 | } |
1443 | ||
d0fe478c | 1444 | vif_priv->ctx = ctx; |
8bd413e6 | 1445 | ctx->vif = vif; |
59079949 | 1446 | |
d4daaea6 JB |
1447 | err = iwl_setup_interface(priv, ctx); |
1448 | if (!err) | |
1449 | goto out; | |
cbb6ab94 | 1450 | |
8bd413e6 | 1451 | ctx->vif = NULL; |
b55e75ed | 1452 | priv->iw_mode = NL80211_IFTYPE_STATION; |
47e28f41 | 1453 | out: |
cbb6ab94 AK |
1454 | mutex_unlock(&priv->mutex); |
1455 | ||
1456 | IWL_DEBUG_MAC80211(priv, "leave\n"); | |
47e28f41 | 1457 | return err; |
cbb6ab94 AK |
1458 | } |
1459 | EXPORT_SYMBOL(iwl_mac_add_interface); | |
1460 | ||
d4daaea6 JB |
1461 | static void iwl_teardown_interface(struct iwl_priv *priv, |
1462 | struct ieee80211_vif *vif, | |
1463 | bool mode_change) | |
d8052319 | 1464 | { |
246ed355 | 1465 | struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif); |
d8052319 | 1466 | |
d4daaea6 | 1467 | lockdep_assert_held(&priv->mutex); |
d0fe478c | 1468 | |
e7e16b90 SG |
1469 | if (priv->scan_vif == vif) { |
1470 | iwl_scan_cancel_timeout(priv, 200); | |
1471 | iwl_force_scan_end(priv); | |
1472 | } | |
8bd413e6 | 1473 | |
d4daaea6 JB |
1474 | if (!mode_change) { |
1475 | iwl_set_mode(priv, ctx); | |
1476 | if (!ctx->always_active) | |
1477 | ctx->is_active = false; | |
1478 | } | |
763cc3bf | 1479 | |
59079949 JB |
1480 | /* |
1481 | * When removing the IBSS interface, overwrite the | |
1482 | * BT traffic load with the stored one from the last | |
1483 | * notification, if any. If this is a device that | |
1484 | * doesn't implement this, this has no effect since | |
1485 | * both values are the same and zero. | |
1486 | */ | |
1487 | if (vif->type == NL80211_IFTYPE_ADHOC) | |
66e863a5 | 1488 | priv->bt_traffic_load = priv->last_bt_traffic_load; |
d4daaea6 JB |
1489 | } |
1490 | ||
1491 | void iwl_mac_remove_interface(struct ieee80211_hw *hw, | |
1492 | struct ieee80211_vif *vif) | |
1493 | { | |
1494 | struct iwl_priv *priv = hw->priv; | |
1495 | struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif); | |
1496 | ||
1497 | IWL_DEBUG_MAC80211(priv, "enter\n"); | |
1498 | ||
1499 | mutex_lock(&priv->mutex); | |
1500 | ||
1501 | WARN_ON(ctx->vif != vif); | |
1502 | ctx->vif = NULL; | |
1503 | ||
1504 | iwl_teardown_interface(priv, vif, false); | |
59079949 | 1505 | |
8bd413e6 | 1506 | memset(priv->bssid, 0, ETH_ALEN); |
d8052319 AK |
1507 | mutex_unlock(&priv->mutex); |
1508 | ||
1509 | IWL_DEBUG_MAC80211(priv, "leave\n"); | |
1510 | ||
1511 | } | |
1512 | EXPORT_SYMBOL(iwl_mac_remove_interface); | |
1513 | ||
88804e2b WYG |
1514 | int iwl_alloc_txq_mem(struct iwl_priv *priv) |
1515 | { | |
1516 | if (!priv->txq) | |
1517 | priv->txq = kzalloc( | |
7cb1b088 WYG |
1518 | sizeof(struct iwl_tx_queue) * |
1519 | priv->cfg->base_params->num_of_queues, | |
88804e2b WYG |
1520 | GFP_KERNEL); |
1521 | if (!priv->txq) { | |
91dd6c27 | 1522 | IWL_ERR(priv, "Not enough memory for txq\n"); |
88804e2b WYG |
1523 | return -ENOMEM; |
1524 | } | |
1525 | return 0; | |
1526 | } | |
1527 | EXPORT_SYMBOL(iwl_alloc_txq_mem); | |
1528 | ||
1529 | void iwl_free_txq_mem(struct iwl_priv *priv) | |
1530 | { | |
1531 | kfree(priv->txq); | |
1532 | priv->txq = NULL; | |
1533 | } | |
1534 | EXPORT_SYMBOL(iwl_free_txq_mem); | |
1535 | ||
20594eb0 WYG |
1536 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
1537 | ||
1538 | #define IWL_TRAFFIC_DUMP_SIZE (IWL_TRAFFIC_ENTRY_SIZE * IWL_TRAFFIC_ENTRIES) | |
1539 | ||
1540 | void iwl_reset_traffic_log(struct iwl_priv *priv) | |
1541 | { | |
1542 | priv->tx_traffic_idx = 0; | |
1543 | priv->rx_traffic_idx = 0; | |
1544 | if (priv->tx_traffic) | |
1545 | memset(priv->tx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE); | |
1546 | if (priv->rx_traffic) | |
1547 | memset(priv->rx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE); | |
1548 | } | |
1549 | ||
1550 | int iwl_alloc_traffic_mem(struct iwl_priv *priv) | |
1551 | { | |
1552 | u32 traffic_size = IWL_TRAFFIC_DUMP_SIZE; | |
1553 | ||
1554 | if (iwl_debug_level & IWL_DL_TX) { | |
1555 | if (!priv->tx_traffic) { | |
1556 | priv->tx_traffic = | |
1557 | kzalloc(traffic_size, GFP_KERNEL); | |
1558 | if (!priv->tx_traffic) | |
1559 | return -ENOMEM; | |
1560 | } | |
1561 | } | |
1562 | if (iwl_debug_level & IWL_DL_RX) { | |
1563 | if (!priv->rx_traffic) { | |
1564 | priv->rx_traffic = | |
1565 | kzalloc(traffic_size, GFP_KERNEL); | |
1566 | if (!priv->rx_traffic) | |
1567 | return -ENOMEM; | |
1568 | } | |
1569 | } | |
1570 | iwl_reset_traffic_log(priv); | |
1571 | return 0; | |
1572 | } | |
1573 | EXPORT_SYMBOL(iwl_alloc_traffic_mem); | |
1574 | ||
1575 | void iwl_free_traffic_mem(struct iwl_priv *priv) | |
1576 | { | |
1577 | kfree(priv->tx_traffic); | |
1578 | priv->tx_traffic = NULL; | |
1579 | ||
1580 | kfree(priv->rx_traffic); | |
1581 | priv->rx_traffic = NULL; | |
1582 | } | |
1583 | EXPORT_SYMBOL(iwl_free_traffic_mem); | |
1584 | ||
1585 | void iwl_dbg_log_tx_data_frame(struct iwl_priv *priv, | |
1586 | u16 length, struct ieee80211_hdr *header) | |
1587 | { | |
1588 | __le16 fc; | |
1589 | u16 len; | |
1590 | ||
1591 | if (likely(!(iwl_debug_level & IWL_DL_TX))) | |
1592 | return; | |
1593 | ||
1594 | if (!priv->tx_traffic) | |
1595 | return; | |
1596 | ||
1597 | fc = header->frame_control; | |
1598 | if (ieee80211_is_data(fc)) { | |
1599 | len = (length > IWL_TRAFFIC_ENTRY_SIZE) | |
1600 | ? IWL_TRAFFIC_ENTRY_SIZE : length; | |
1601 | memcpy((priv->tx_traffic + | |
1602 | (priv->tx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)), | |
1603 | header, len); | |
1604 | priv->tx_traffic_idx = | |
1605 | (priv->tx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES; | |
1606 | } | |
1607 | } | |
1608 | EXPORT_SYMBOL(iwl_dbg_log_tx_data_frame); | |
1609 | ||
1610 | void iwl_dbg_log_rx_data_frame(struct iwl_priv *priv, | |
1611 | u16 length, struct ieee80211_hdr *header) | |
1612 | { | |
1613 | __le16 fc; | |
1614 | u16 len; | |
1615 | ||
1616 | if (likely(!(iwl_debug_level & IWL_DL_RX))) | |
1617 | return; | |
1618 | ||
1619 | if (!priv->rx_traffic) | |
1620 | return; | |
1621 | ||
1622 | fc = header->frame_control; | |
1623 | if (ieee80211_is_data(fc)) { | |
1624 | len = (length > IWL_TRAFFIC_ENTRY_SIZE) | |
1625 | ? IWL_TRAFFIC_ENTRY_SIZE : length; | |
1626 | memcpy((priv->rx_traffic + | |
1627 | (priv->rx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)), | |
1628 | header, len); | |
1629 | priv->rx_traffic_idx = | |
1630 | (priv->rx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES; | |
1631 | } | |
1632 | } | |
1633 | EXPORT_SYMBOL(iwl_dbg_log_rx_data_frame); | |
22fdf3c9 WYG |
1634 | |
1635 | const char *get_mgmt_string(int cmd) | |
1636 | { | |
1637 | switch (cmd) { | |
1638 | IWL_CMD(MANAGEMENT_ASSOC_REQ); | |
1639 | IWL_CMD(MANAGEMENT_ASSOC_RESP); | |
1640 | IWL_CMD(MANAGEMENT_REASSOC_REQ); | |
1641 | IWL_CMD(MANAGEMENT_REASSOC_RESP); | |
1642 | IWL_CMD(MANAGEMENT_PROBE_REQ); | |
1643 | IWL_CMD(MANAGEMENT_PROBE_RESP); | |
1644 | IWL_CMD(MANAGEMENT_BEACON); | |
1645 | IWL_CMD(MANAGEMENT_ATIM); | |
1646 | IWL_CMD(MANAGEMENT_DISASSOC); | |
1647 | IWL_CMD(MANAGEMENT_AUTH); | |
1648 | IWL_CMD(MANAGEMENT_DEAUTH); | |
1649 | IWL_CMD(MANAGEMENT_ACTION); | |
1650 | default: | |
1651 | return "UNKNOWN"; | |
1652 | ||
1653 | } | |
1654 | } | |
1655 | ||
1656 | const char *get_ctrl_string(int cmd) | |
1657 | { | |
1658 | switch (cmd) { | |
1659 | IWL_CMD(CONTROL_BACK_REQ); | |
1660 | IWL_CMD(CONTROL_BACK); | |
1661 | IWL_CMD(CONTROL_PSPOLL); | |
1662 | IWL_CMD(CONTROL_RTS); | |
1663 | IWL_CMD(CONTROL_CTS); | |
1664 | IWL_CMD(CONTROL_ACK); | |
1665 | IWL_CMD(CONTROL_CFEND); | |
1666 | IWL_CMD(CONTROL_CFENDACK); | |
1667 | default: | |
1668 | return "UNKNOWN"; | |
1669 | ||
1670 | } | |
1671 | } | |
1672 | ||
7163b8a4 | 1673 | void iwl_clear_traffic_stats(struct iwl_priv *priv) |
22fdf3c9 WYG |
1674 | { |
1675 | memset(&priv->tx_stats, 0, sizeof(struct traffic_stats)); | |
22fdf3c9 | 1676 | memset(&priv->rx_stats, 0, sizeof(struct traffic_stats)); |
7163b8a4 | 1677 | priv->led_tpt = 0; |
22fdf3c9 WYG |
1678 | } |
1679 | ||
1680 | /* | |
1681 | * if CONFIG_IWLWIFI_DEBUGFS defined, iwl_update_stats function will | |
1682 | * record all the MGMT, CTRL and DATA pkt for both TX and Rx pass. | |
1683 | * Use debugFs to display the rx/rx_statistics | |
1684 | * if CONFIG_IWLWIFI_DEBUGFS not being defined, then no MGMT and CTRL | |
1685 | * information will be recorded, but DATA pkt still will be recorded | |
1686 | * for the reason of iwl_led.c need to control the led blinking based on | |
1687 | * number of tx and rx data. | |
1688 | * | |
1689 | */ | |
1690 | void iwl_update_stats(struct iwl_priv *priv, bool is_tx, __le16 fc, u16 len) | |
1691 | { | |
1692 | struct traffic_stats *stats; | |
1693 | ||
1694 | if (is_tx) | |
1695 | stats = &priv->tx_stats; | |
1696 | else | |
1697 | stats = &priv->rx_stats; | |
1698 | ||
1699 | if (ieee80211_is_mgmt(fc)) { | |
1700 | switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) { | |
1701 | case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ): | |
1702 | stats->mgmt[MANAGEMENT_ASSOC_REQ]++; | |
1703 | break; | |
1704 | case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP): | |
1705 | stats->mgmt[MANAGEMENT_ASSOC_RESP]++; | |
1706 | break; | |
1707 | case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ): | |
1708 | stats->mgmt[MANAGEMENT_REASSOC_REQ]++; | |
1709 | break; | |
1710 | case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP): | |
1711 | stats->mgmt[MANAGEMENT_REASSOC_RESP]++; | |
1712 | break; | |
1713 | case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ): | |
1714 | stats->mgmt[MANAGEMENT_PROBE_REQ]++; | |
1715 | break; | |
1716 | case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP): | |
1717 | stats->mgmt[MANAGEMENT_PROBE_RESP]++; | |
1718 | break; | |
1719 | case cpu_to_le16(IEEE80211_STYPE_BEACON): | |
1720 | stats->mgmt[MANAGEMENT_BEACON]++; | |
1721 | break; | |
1722 | case cpu_to_le16(IEEE80211_STYPE_ATIM): | |
1723 | stats->mgmt[MANAGEMENT_ATIM]++; | |
1724 | break; | |
1725 | case cpu_to_le16(IEEE80211_STYPE_DISASSOC): | |
1726 | stats->mgmt[MANAGEMENT_DISASSOC]++; | |
1727 | break; | |
1728 | case cpu_to_le16(IEEE80211_STYPE_AUTH): | |
1729 | stats->mgmt[MANAGEMENT_AUTH]++; | |
1730 | break; | |
1731 | case cpu_to_le16(IEEE80211_STYPE_DEAUTH): | |
1732 | stats->mgmt[MANAGEMENT_DEAUTH]++; | |
1733 | break; | |
1734 | case cpu_to_le16(IEEE80211_STYPE_ACTION): | |
1735 | stats->mgmt[MANAGEMENT_ACTION]++; | |
1736 | break; | |
1737 | } | |
1738 | } else if (ieee80211_is_ctl(fc)) { | |
1739 | switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) { | |
1740 | case cpu_to_le16(IEEE80211_STYPE_BACK_REQ): | |
1741 | stats->ctrl[CONTROL_BACK_REQ]++; | |
1742 | break; | |
1743 | case cpu_to_le16(IEEE80211_STYPE_BACK): | |
1744 | stats->ctrl[CONTROL_BACK]++; | |
1745 | break; | |
1746 | case cpu_to_le16(IEEE80211_STYPE_PSPOLL): | |
1747 | stats->ctrl[CONTROL_PSPOLL]++; | |
1748 | break; | |
1749 | case cpu_to_le16(IEEE80211_STYPE_RTS): | |
1750 | stats->ctrl[CONTROL_RTS]++; | |
1751 | break; | |
1752 | case cpu_to_le16(IEEE80211_STYPE_CTS): | |
1753 | stats->ctrl[CONTROL_CTS]++; | |
1754 | break; | |
1755 | case cpu_to_le16(IEEE80211_STYPE_ACK): | |
1756 | stats->ctrl[CONTROL_ACK]++; | |
1757 | break; | |
1758 | case cpu_to_le16(IEEE80211_STYPE_CFEND): | |
1759 | stats->ctrl[CONTROL_CFEND]++; | |
1760 | break; | |
1761 | case cpu_to_le16(IEEE80211_STYPE_CFENDACK): | |
1762 | stats->ctrl[CONTROL_CFENDACK]++; | |
1763 | break; | |
1764 | } | |
1765 | } else { | |
1766 | /* data */ | |
1767 | stats->data_cnt++; | |
1768 | stats->data_bytes += len; | |
1769 | } | |
d5f4cf71 | 1770 | iwl_leds_background(priv); |
22fdf3c9 WYG |
1771 | } |
1772 | EXPORT_SYMBOL(iwl_update_stats); | |
20594eb0 WYG |
1773 | #endif |
1774 | ||
a93e7973 | 1775 | static void iwl_force_rf_reset(struct iwl_priv *priv) |
afbdd69a WYG |
1776 | { |
1777 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | |
1778 | return; | |
1779 | ||
246ed355 | 1780 | if (!iwl_is_any_associated(priv)) { |
afbdd69a WYG |
1781 | IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n"); |
1782 | return; | |
1783 | } | |
1784 | /* | |
1785 | * There is no easy and better way to force reset the radio, | |
1786 | * the only known method is switching channel which will force to | |
1787 | * reset and tune the radio. | |
1788 | * Use internal short scan (single channel) operation to should | |
1789 | * achieve this objective. | |
1790 | * Driver should reset the radio when number of consecutive missed | |
1791 | * beacon, or any other uCode error condition detected. | |
1792 | */ | |
1793 | IWL_DEBUG_INFO(priv, "perform radio reset.\n"); | |
1794 | iwl_internal_short_hw_scan(priv); | |
afbdd69a | 1795 | } |
a93e7973 | 1796 | |
a93e7973 | 1797 | |
c04f9f22 | 1798 | int iwl_force_reset(struct iwl_priv *priv, int mode, bool external) |
a93e7973 | 1799 | { |
8a472da4 WYG |
1800 | struct iwl_force_reset *force_reset; |
1801 | ||
a93e7973 WYG |
1802 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
1803 | return -EINVAL; | |
1804 | ||
8a472da4 WYG |
1805 | if (mode >= IWL_MAX_FORCE_RESET) { |
1806 | IWL_DEBUG_INFO(priv, "invalid reset request.\n"); | |
1807 | return -EINVAL; | |
1808 | } | |
1809 | force_reset = &priv->force_reset[mode]; | |
1810 | force_reset->reset_request_count++; | |
c04f9f22 WYG |
1811 | if (!external) { |
1812 | if (force_reset->last_force_reset_jiffies && | |
1813 | time_after(force_reset->last_force_reset_jiffies + | |
1814 | force_reset->reset_duration, jiffies)) { | |
1815 | IWL_DEBUG_INFO(priv, "force reset rejected\n"); | |
1816 | force_reset->reset_reject_count++; | |
1817 | return -EAGAIN; | |
1818 | } | |
a93e7973 | 1819 | } |
8a472da4 WYG |
1820 | force_reset->reset_success_count++; |
1821 | force_reset->last_force_reset_jiffies = jiffies; | |
a93e7973 | 1822 | IWL_DEBUG_INFO(priv, "perform force reset (%d)\n", mode); |
a93e7973 WYG |
1823 | switch (mode) { |
1824 | case IWL_RF_RESET: | |
1825 | iwl_force_rf_reset(priv); | |
1826 | break; | |
1827 | case IWL_FW_RESET: | |
c04f9f22 WYG |
1828 | /* |
1829 | * if the request is from external(ex: debugfs), | |
1830 | * then always perform the request in regardless the module | |
1831 | * parameter setting | |
1832 | * if the request is from internal (uCode error or driver | |
1833 | * detect failure), then fw_restart module parameter | |
1834 | * need to be check before performing firmware reload | |
1835 | */ | |
1836 | if (!external && !priv->cfg->mod_params->restart_fw) { | |
1837 | IWL_DEBUG_INFO(priv, "Cancel firmware reload based on " | |
1838 | "module parameter setting\n"); | |
1839 | break; | |
1840 | } | |
a93e7973 WYG |
1841 | IWL_ERR(priv, "On demand firmware reload\n"); |
1842 | /* Set the FW error flag -- cleared on iwl_down */ | |
1843 | set_bit(STATUS_FW_ERROR, &priv->status); | |
1844 | wake_up_interruptible(&priv->wait_command_queue); | |
1845 | /* | |
1846 | * Keep the restart process from trying to send host | |
1847 | * commands by clearing the INIT status bit | |
1848 | */ | |
1849 | clear_bit(STATUS_READY, &priv->status); | |
1850 | queue_work(priv->workqueue, &priv->restart); | |
1851 | break; | |
a93e7973 | 1852 | } |
a93e7973 WYG |
1853 | return 0; |
1854 | } | |
b74e31a9 | 1855 | |
d4daaea6 JB |
1856 | int iwl_mac_change_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
1857 | enum nl80211_iftype newtype, bool newp2p) | |
1858 | { | |
1859 | struct iwl_priv *priv = hw->priv; | |
1860 | struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif); | |
1861 | struct iwl_rxon_context *tmp; | |
1862 | u32 interface_modes; | |
1863 | int err; | |
1864 | ||
1865 | newtype = ieee80211_iftype_p2p(newtype, newp2p); | |
1866 | ||
1867 | mutex_lock(&priv->mutex); | |
1868 | ||
1869 | interface_modes = ctx->interface_modes | ctx->exclusive_interface_modes; | |
1870 | ||
1871 | if (!(interface_modes & BIT(newtype))) { | |
1872 | err = -EBUSY; | |
1873 | goto out; | |
1874 | } | |
1875 | ||
1876 | if (ctx->exclusive_interface_modes & BIT(newtype)) { | |
1877 | for_each_context(priv, tmp) { | |
1878 | if (ctx == tmp) | |
1879 | continue; | |
1880 | ||
1881 | if (!tmp->vif) | |
1882 | continue; | |
1883 | ||
1884 | /* | |
1885 | * The current mode switch would be exclusive, but | |
1886 | * another context is active ... refuse the switch. | |
1887 | */ | |
1888 | err = -EBUSY; | |
1889 | goto out; | |
1890 | } | |
1891 | } | |
1892 | ||
1893 | /* success */ | |
1894 | iwl_teardown_interface(priv, vif, true); | |
1895 | vif->type = newtype; | |
1896 | err = iwl_setup_interface(priv, ctx); | |
1897 | WARN_ON(err); | |
1898 | /* | |
1899 | * We've switched internally, but submitting to the | |
1900 | * device may have failed for some reason. Mask this | |
1901 | * error, because otherwise mac80211 will not switch | |
1902 | * (and set the interface type back) and we'll be | |
1903 | * out of sync with it. | |
1904 | */ | |
1905 | err = 0; | |
1906 | ||
1907 | out: | |
1908 | mutex_unlock(&priv->mutex); | |
1909 | return err; | |
1910 | } | |
1911 | EXPORT_SYMBOL(iwl_mac_change_interface); | |
1912 | ||
b74e31a9 | 1913 | /* |
22de94de SG |
1914 | * On every watchdog tick we check (latest) time stamp. If it does not |
1915 | * change during timeout period and queue is not empty we reset firmware. | |
b74e31a9 | 1916 | */ |
b74e31a9 WYG |
1917 | static int iwl_check_stuck_queue(struct iwl_priv *priv, int cnt) |
1918 | { | |
22de94de SG |
1919 | struct iwl_tx_queue *txq = &priv->txq[cnt]; |
1920 | struct iwl_queue *q = &txq->q; | |
1921 | unsigned long timeout; | |
1922 | int ret; | |
b74e31a9 | 1923 | |
22de94de SG |
1924 | if (q->read_ptr == q->write_ptr) { |
1925 | txq->time_stamp = jiffies; | |
7cb1b088 | 1926 | return 0; |
22de94de | 1927 | } |
7cb1b088 | 1928 | |
22de94de SG |
1929 | timeout = txq->time_stamp + |
1930 | msecs_to_jiffies(priv->cfg->base_params->wd_timeout); | |
1931 | ||
1932 | if (time_after(jiffies, timeout)) { | |
1933 | IWL_ERR(priv, "Queue %d stuck for %u ms.\n", | |
1934 | q->id, priv->cfg->base_params->wd_timeout); | |
1935 | ret = iwl_force_reset(priv, IWL_FW_RESET, false); | |
1936 | return (ret == -EAGAIN) ? 0 : 1; | |
b74e31a9 | 1937 | } |
22de94de | 1938 | |
b74e31a9 WYG |
1939 | return 0; |
1940 | } | |
1941 | ||
22de94de SG |
1942 | /* |
1943 | * Making watchdog tick be a quarter of timeout assure we will | |
1944 | * discover the queue hung between timeout and 1.25*timeout | |
1945 | */ | |
1946 | #define IWL_WD_TICK(timeout) ((timeout) / 4) | |
1947 | ||
1948 | /* | |
1949 | * Watchdog timer callback, we check each tx queue for stuck, if if hung | |
1950 | * we reset the firmware. If everything is fine just rearm the timer. | |
1951 | */ | |
1952 | void iwl_bg_watchdog(unsigned long data) | |
b74e31a9 WYG |
1953 | { |
1954 | struct iwl_priv *priv = (struct iwl_priv *)data; | |
1955 | int cnt; | |
22de94de | 1956 | unsigned long timeout; |
b74e31a9 WYG |
1957 | |
1958 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | |
1959 | return; | |
1960 | ||
22de94de SG |
1961 | timeout = priv->cfg->base_params->wd_timeout; |
1962 | if (timeout == 0) | |
1963 | return; | |
1964 | ||
b74e31a9 | 1965 | /* monitor and check for stuck cmd queue */ |
13bb9483 | 1966 | if (iwl_check_stuck_queue(priv, priv->cmd_queue)) |
b74e31a9 WYG |
1967 | return; |
1968 | ||
1969 | /* monitor and check for other stuck queues */ | |
246ed355 | 1970 | if (iwl_is_any_associated(priv)) { |
b74e31a9 WYG |
1971 | for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) { |
1972 | /* skip as we already checked the command queue */ | |
13bb9483 | 1973 | if (cnt == priv->cmd_queue) |
b74e31a9 WYG |
1974 | continue; |
1975 | if (iwl_check_stuck_queue(priv, cnt)) | |
1976 | return; | |
1977 | } | |
1978 | } | |
22de94de SG |
1979 | |
1980 | mod_timer(&priv->watchdog, jiffies + | |
1981 | msecs_to_jiffies(IWL_WD_TICK(timeout))); | |
b74e31a9 | 1982 | } |
22de94de SG |
1983 | EXPORT_SYMBOL(iwl_bg_watchdog); |
1984 | ||
1985 | void iwl_setup_watchdog(struct iwl_priv *priv) | |
1986 | { | |
1987 | unsigned int timeout = priv->cfg->base_params->wd_timeout; | |
afbdd69a | 1988 | |
22de94de SG |
1989 | if (timeout) |
1990 | mod_timer(&priv->watchdog, | |
1991 | jiffies + msecs_to_jiffies(IWL_WD_TICK(timeout))); | |
1992 | else | |
1993 | del_timer(&priv->watchdog); | |
1994 | } | |
1995 | EXPORT_SYMBOL(iwl_setup_watchdog); | |
a0ee74cf WYG |
1996 | |
1997 | /* | |
1998 | * extended beacon time format | |
1999 | * time in usec will be changed into a 32-bit value in extended:internal format | |
2000 | * the extended part is the beacon counts | |
2001 | * the internal part is the time in usec within one beacon interval | |
2002 | */ | |
2003 | u32 iwl_usecs_to_beacons(struct iwl_priv *priv, u32 usec, u32 beacon_interval) | |
2004 | { | |
2005 | u32 quot; | |
2006 | u32 rem; | |
2007 | u32 interval = beacon_interval * TIME_UNIT; | |
2008 | ||
2009 | if (!interval || !usec) | |
2010 | return 0; | |
2011 | ||
2012 | quot = (usec / interval) & | |
2013 | (iwl_beacon_time_mask_high(priv, | |
2014 | priv->hw_params.beacon_time_tsf_bits) >> | |
2015 | priv->hw_params.beacon_time_tsf_bits); | |
2016 | rem = (usec % interval) & iwl_beacon_time_mask_low(priv, | |
2017 | priv->hw_params.beacon_time_tsf_bits); | |
2018 | ||
2019 | return (quot << priv->hw_params.beacon_time_tsf_bits) + rem; | |
2020 | } | |
2021 | EXPORT_SYMBOL(iwl_usecs_to_beacons); | |
2022 | ||
2023 | /* base is usually what we get from ucode with each received frame, | |
2024 | * the same as HW timer counter counting down | |
2025 | */ | |
2026 | __le32 iwl_add_beacon_time(struct iwl_priv *priv, u32 base, | |
2027 | u32 addon, u32 beacon_interval) | |
2028 | { | |
2029 | u32 base_low = base & iwl_beacon_time_mask_low(priv, | |
2030 | priv->hw_params.beacon_time_tsf_bits); | |
2031 | u32 addon_low = addon & iwl_beacon_time_mask_low(priv, | |
2032 | priv->hw_params.beacon_time_tsf_bits); | |
2033 | u32 interval = beacon_interval * TIME_UNIT; | |
2034 | u32 res = (base & iwl_beacon_time_mask_high(priv, | |
2035 | priv->hw_params.beacon_time_tsf_bits)) + | |
2036 | (addon & iwl_beacon_time_mask_high(priv, | |
2037 | priv->hw_params.beacon_time_tsf_bits)); | |
2038 | ||
2039 | if (base_low > addon_low) | |
2040 | res += base_low - addon_low; | |
2041 | else if (base_low < addon_low) { | |
2042 | res += interval + base_low - addon_low; | |
2043 | res += (1 << priv->hw_params.beacon_time_tsf_bits); | |
2044 | } else | |
2045 | res += (1 << priv->hw_params.beacon_time_tsf_bits); | |
2046 | ||
2047 | return cpu_to_le32(res); | |
2048 | } | |
2049 | EXPORT_SYMBOL(iwl_add_beacon_time); | |
2050 | ||
6da3a13e WYG |
2051 | #ifdef CONFIG_PM |
2052 | ||
f60dc013 | 2053 | int iwl_pci_suspend(struct device *device) |
6da3a13e | 2054 | { |
f60dc013 | 2055 | struct pci_dev *pdev = to_pci_dev(device); |
6da3a13e WYG |
2056 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
2057 | ||
2058 | /* | |
2059 | * This function is called when system goes into suspend state | |
2060 | * mac80211 will call iwl_mac_stop() from the mac80211 suspend function | |
2061 | * first but since iwl_mac_stop() has no knowledge of who the caller is, | |
2062 | * it will not call apm_ops.stop() to stop the DMA operation. | |
2063 | * Calling apm_ops.stop here to make sure we stop the DMA. | |
2064 | */ | |
14e8e4af | 2065 | iwl_apm_stop(priv); |
6da3a13e | 2066 | |
6da3a13e WYG |
2067 | return 0; |
2068 | } | |
2069 | EXPORT_SYMBOL(iwl_pci_suspend); | |
2070 | ||
f60dc013 | 2071 | int iwl_pci_resume(struct device *device) |
6da3a13e | 2072 | { |
f60dc013 | 2073 | struct pci_dev *pdev = to_pci_dev(device); |
6da3a13e | 2074 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
0ab84cff | 2075 | bool hw_rfkill = false; |
6da3a13e | 2076 | |
cd398c31 AK |
2077 | /* |
2078 | * We disable the RETRY_TIMEOUT register (0x41) to keep | |
2079 | * PCI Tx retries from interfering with C3 CPU state. | |
2080 | */ | |
2081 | pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00); | |
2082 | ||
6da3a13e WYG |
2083 | iwl_enable_interrupts(priv); |
2084 | ||
0ab84cff JB |
2085 | if (!(iwl_read32(priv, CSR_GP_CNTRL) & |
2086 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) | |
2087 | hw_rfkill = true; | |
2088 | ||
2089 | if (hw_rfkill) | |
2090 | set_bit(STATUS_RF_KILL_HW, &priv->status); | |
2091 | else | |
2092 | clear_bit(STATUS_RF_KILL_HW, &priv->status); | |
2093 | ||
2094 | wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rfkill); | |
2095 | ||
6da3a13e WYG |
2096 | return 0; |
2097 | } | |
2098 | EXPORT_SYMBOL(iwl_pci_resume); | |
2099 | ||
f60dc013 JL |
2100 | const struct dev_pm_ops iwl_pm_ops = { |
2101 | .suspend = iwl_pci_suspend, | |
2102 | .resume = iwl_pci_resume, | |
2103 | .freeze = iwl_pci_suspend, | |
2104 | .thaw = iwl_pci_resume, | |
2105 | .poweroff = iwl_pci_suspend, | |
2106 | .restore = iwl_pci_resume, | |
2107 | }; | |
2108 | EXPORT_SYMBOL(iwl_pm_ops); | |
2109 | ||
6da3a13e | 2110 | #endif /* CONFIG_PM */ |