blob: ed4415988e97c1289e0a0e421955a5c6abeaee4e [file] [log] [blame]
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001/******************************************************************************
2 *
3 * GPL LICENSE SUMMARY
4 *
5 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
19 * USA
20 *
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
23 *
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
28
29#include <linux/kernel.h>
30#include <linux/module.h>
31#include <linux/etherdevice.h>
32#include <linux/sched.h>
33#include <linux/slab.h>
34#include <net/mac80211.h>
35
36#include "iwl-eeprom.h"
37#include "iwl-dev.h"
38#include "iwl-debug.h"
39#include "iwl-core.h"
40#include "iwl-io.h"
41#include "iwl-power.h"
42#include "iwl-sta.h"
43#include "iwl-helpers.h"
44
45
46MODULE_DESCRIPTION("iwl-legacy: common functions for 3945 and 4965");
47MODULE_VERSION(IWLWIFI_VERSION);
48MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
49MODULE_LICENSE("GPL");
50
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 */
John W. Linvilleef334172011-02-25 15:51:01 -050067static bool bt_coex_active = true;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080068module_param(bt_coex_active, bool, S_IRUGO);
69MODULE_PARM_DESC(bt_coex_active, "enable wifi/bluetooth co-exist");
70
Stanislaw Gruszkad2ddf622011-08-16 14:17:04 +020071u32 il_debug_level;
72EXPORT_SYMBOL(il_debug_level);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080073
Stanislaw Gruszkad2ddf622011-08-16 14:17:04 +020074const u8 il_bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
75EXPORT_SYMBOL(il_bcast_addr);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080076
77
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +020078/* This function both allocates and initializes hw and il. */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +020079struct ieee80211_hw *il_alloc_all(struct il_cfg *cfg)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080080{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +020081 struct il_priv *il;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080082 /* mac80211 allocates memory for this device instance, including
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +020083 * space for this driver's ilate structure */
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080084 struct ieee80211_hw *hw;
85
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +020086 hw = ieee80211_alloc_hw(sizeof(struct il_priv),
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080087 cfg->ops->ieee80211_ops);
88 if (hw == NULL) {
89 pr_err("%s: Can not allocate network device\n",
90 cfg->name);
91 goto out;
92 }
93
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +020094 il = hw->priv;
95 il->hw = hw;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080096
97out:
98 return hw;
99}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200100EXPORT_SYMBOL(il_alloc_all);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800101
102#define MAX_BIT_RATE_40_MHZ 150 /* Mbps */
103#define MAX_BIT_RATE_20_MHZ 72 /* Mbps */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200104static void il_init_ht_hw_capab(const struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800105 struct ieee80211_sta_ht_cap *ht_info,
106 enum ieee80211_band band)
107{
108 u16 max_bit_rate = 0;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200109 u8 rx_chains_num = il->hw_params.rx_chains_num;
110 u8 tx_chains_num = il->hw_params.tx_chains_num;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800111
112 ht_info->cap = 0;
113 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
114
115 ht_info->ht_supported = true;
116
117 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
118 max_bit_rate = MAX_BIT_RATE_20_MHZ;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200119 if (il->hw_params.ht40_channel & BIT(band)) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800120 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
121 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
122 ht_info->mcs.rx_mask[4] = 0x01;
123 max_bit_rate = MAX_BIT_RATE_40_MHZ;
124 }
125
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200126 if (il->cfg->mod_params->amsdu_size_8K)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800127 ht_info->cap |= IEEE80211_HT_CAP_MAX_AMSDU;
128
129 ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
130 ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
131
132 ht_info->mcs.rx_mask[0] = 0xFF;
133 if (rx_chains_num >= 2)
134 ht_info->mcs.rx_mask[1] = 0xFF;
135 if (rx_chains_num >= 3)
136 ht_info->mcs.rx_mask[2] = 0xFF;
137
138 /* Highest supported Rx data rate */
139 max_bit_rate *= rx_chains_num;
140 WARN_ON(max_bit_rate & ~IEEE80211_HT_MCS_RX_HIGHEST_MASK);
141 ht_info->mcs.rx_highest = cpu_to_le16(max_bit_rate);
142
143 /* Tx MCS capabilities */
144 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
145 if (tx_chains_num != rx_chains_num) {
146 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
147 ht_info->mcs.tx_params |= ((tx_chains_num - 1) <<
148 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
149 }
150}
151
152/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200153 * il_init_geos - Initialize mac80211's geo/channel info based from eeprom
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800154 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200155int il_init_geos(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800156{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200157 struct il_channel_info *ch;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800158 struct ieee80211_supported_band *sband;
159 struct ieee80211_channel *channels;
160 struct ieee80211_channel *geo_ch;
161 struct ieee80211_rate *rates;
162 int i = 0;
Stanislaw Gruszka332704a2011-04-13 10:56:51 +0200163 s8 max_tx_power = 0;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800164
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200165 if (il->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
166 il->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100167 D_INFO("Geography modes already initialized.\n");
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200168 set_bit(STATUS_GEO_CONFIGURED, &il->status);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800169 return 0;
170 }
171
172 channels = kzalloc(sizeof(struct ieee80211_channel) *
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200173 il->channel_count, GFP_KERNEL);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800174 if (!channels)
175 return -ENOMEM;
176
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200177 rates = kzalloc((sizeof(struct ieee80211_rate) * IL_RATE_COUNT_LEGACY),
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800178 GFP_KERNEL);
179 if (!rates) {
180 kfree(channels);
181 return -ENOMEM;
182 }
183
184 /* 5.2GHz channels start after the 2.4GHz channels */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200185 sband = &il->bands[IEEE80211_BAND_5GHZ];
Stanislaw Gruszkad2ddf622011-08-16 14:17:04 +0200186 sband->channels = &channels[ARRAY_SIZE(il_eeprom_band_1)];
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800187 /* just OFDM */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200188 sband->bitrates = &rates[IL_FIRST_OFDM_RATE];
189 sband->n_bitrates = IL_RATE_COUNT_LEGACY - IL_FIRST_OFDM_RATE;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800190
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200191 if (il->cfg->sku & IL_SKU_N)
192 il_init_ht_hw_capab(il, &sband->ht_cap,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800193 IEEE80211_BAND_5GHZ);
194
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200195 sband = &il->bands[IEEE80211_BAND_2GHZ];
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800196 sband->channels = channels;
197 /* OFDM & CCK */
198 sband->bitrates = rates;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200199 sband->n_bitrates = IL_RATE_COUNT_LEGACY;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800200
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200201 if (il->cfg->sku & IL_SKU_N)
202 il_init_ht_hw_capab(il, &sband->ht_cap,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800203 IEEE80211_BAND_2GHZ);
204
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200205 il->ieee_channels = channels;
206 il->ieee_rates = rates;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800207
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200208 for (i = 0; i < il->channel_count; i++) {
209 ch = &il->channel_info[i];
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800210
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200211 if (!il_is_channel_valid(ch))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800212 continue;
213
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200214 sband = &il->bands[ch->band];
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800215
216 geo_ch = &sband->channels[sband->n_channels++];
217
218 geo_ch->center_freq =
219 ieee80211_channel_to_frequency(ch->channel, ch->band);
220 geo_ch->max_power = ch->max_power_avg;
221 geo_ch->max_antenna_gain = 0xff;
222 geo_ch->hw_value = ch->channel;
223
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200224 if (il_is_channel_valid(ch)) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800225 if (!(ch->flags & EEPROM_CHANNEL_IBSS))
226 geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
227
228 if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
229 geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
230
231 if (ch->flags & EEPROM_CHANNEL_RADAR)
232 geo_ch->flags |= IEEE80211_CHAN_RADAR;
233
234 geo_ch->flags |= ch->ht40_extension_channel;
235
Stanislaw Gruszka332704a2011-04-13 10:56:51 +0200236 if (ch->max_power_avg > max_tx_power)
237 max_tx_power = ch->max_power_avg;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800238 } else {
239 geo_ch->flags |= IEEE80211_CHAN_DISABLED;
240 }
241
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100242 D_INFO("Channel %d Freq=%d[%sGHz] %s flag=0x%X\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800243 ch->channel, geo_ch->center_freq,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200244 il_is_channel_a_band(ch) ? "5.2" : "2.4",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800245 geo_ch->flags & IEEE80211_CHAN_DISABLED ?
246 "restricted" : "valid",
247 geo_ch->flags);
248 }
249
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200250 il->tx_power_device_lmt = max_tx_power;
251 il->tx_power_user_lmt = max_tx_power;
252 il->tx_power_next = max_tx_power;
Stanislaw Gruszka332704a2011-04-13 10:56:51 +0200253
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200254 if ((il->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
255 il->cfg->sku & IL_SKU_A) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200256 IL_INFO("Incorrectly detected BG card as ABG. "
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800257 "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n",
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200258 il->pci_dev->device,
259 il->pci_dev->subsystem_device);
260 il->cfg->sku &= ~IL_SKU_A;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800261 }
262
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200263 IL_INFO("Tunable channels: %d 802.11bg, %d 802.11a channels\n",
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200264 il->bands[IEEE80211_BAND_2GHZ].n_channels,
265 il->bands[IEEE80211_BAND_5GHZ].n_channels);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800266
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200267 set_bit(STATUS_GEO_CONFIGURED, &il->status);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800268
269 return 0;
270}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200271EXPORT_SYMBOL(il_init_geos);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800272
273/*
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200274 * il_free_geos - undo allocations in il_init_geos
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800275 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200276void il_free_geos(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800277{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200278 kfree(il->ieee_channels);
279 kfree(il->ieee_rates);
280 clear_bit(STATUS_GEO_CONFIGURED, &il->status);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800281}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200282EXPORT_SYMBOL(il_free_geos);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800283
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200284static bool il_is_channel_extension(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800285 enum ieee80211_band band,
286 u16 channel, u8 extension_chan_offset)
287{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200288 const struct il_channel_info *ch_info;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800289
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200290 ch_info = il_get_channel_info(il, band, channel);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200291 if (!il_is_channel_valid(ch_info))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800292 return false;
293
294 if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
295 return !(ch_info->ht40_extension_channel &
296 IEEE80211_CHAN_NO_HT40PLUS);
297 else if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_BELOW)
298 return !(ch_info->ht40_extension_channel &
299 IEEE80211_CHAN_NO_HT40MINUS);
300
301 return false;
302}
303
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200304bool il_is_ht40_tx_allowed(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200305 struct il_rxon_context *ctx,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800306 struct ieee80211_sta_ht_cap *ht_cap)
307{
308 if (!ctx->ht.enabled || !ctx->ht.is_40mhz)
309 return false;
310
311 /*
312 * We do not check for IEEE80211_HT_CAP_SUP_WIDTH_20_40
313 * the bit will not set if it is pure 40MHz case
314 */
315 if (ht_cap && !ht_cap->ht_supported)
316 return false;
317
318#ifdef CONFIG_IWLWIFI_LEGACY_DEBUGFS
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200319 if (il->disable_ht40)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800320 return false;
321#endif
322
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200323 return il_is_channel_extension(il, il->band,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800324 le16_to_cpu(ctx->staging.channel),
325 ctx->ht.extension_chan_offset);
326}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200327EXPORT_SYMBOL(il_is_ht40_tx_allowed);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800328
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200329static u16 il_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800330{
331 u16 new_val;
332 u16 beacon_factor;
333
334 /*
335 * If mac80211 hasn't given us a beacon interval, program
336 * the default into the device.
337 */
338 if (!beacon_val)
339 return DEFAULT_BEACON_INTERVAL;
340
341 /*
342 * If the beacon interval we obtained from the peer
343 * is too large, we'll have to wake up more often
344 * (and in IBSS case, we'll beacon too much)
345 *
346 * For example, if max_beacon_val is 4096, and the
347 * requested beacon interval is 7000, we'll have to
348 * use 3500 to be able to wake up on the beacons.
349 *
350 * This could badly influence beacon detection stats.
351 */
352
353 beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val;
354 new_val = beacon_val / beacon_factor;
355
356 if (!new_val)
357 new_val = max_beacon_val;
358
359 return new_val;
360}
361
362int
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200363il_send_rxon_timing(struct il_priv *il, struct il_rxon_context *ctx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800364{
365 u64 tsf;
366 s32 interval_tm, rem;
367 struct ieee80211_conf *conf = NULL;
368 u16 beacon_int;
369 struct ieee80211_vif *vif = ctx->vif;
370
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200371 conf = il_ieee80211_get_hw_conf(il->hw);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800372
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200373 lockdep_assert_held(&il->mutex);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800374
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200375 memset(&ctx->timing, 0, sizeof(struct il_rxon_time_cmd));
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800376
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200377 ctx->timing.timestamp = cpu_to_le64(il->timestamp);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800378 ctx->timing.listen_interval = cpu_to_le16(conf->listen_interval);
379
380 beacon_int = vif ? vif->bss_conf.beacon_int : 0;
381
382 /*
383 * TODO: For IBSS we need to get atim_window from mac80211,
384 * for now just always use 0
385 */
386 ctx->timing.atim_window = 0;
387
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200388 beacon_int = il_adjust_beacon_interval(beacon_int,
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200389 il->hw_params.max_beacon_itrvl * TIME_UNIT);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800390 ctx->timing.beacon_interval = cpu_to_le16(beacon_int);
391
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200392 tsf = il->timestamp; /* tsf is modifed by do_div: copy it */
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800393 interval_tm = beacon_int * TIME_UNIT;
394 rem = do_div(tsf, interval_tm);
395 ctx->timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
396
397 ctx->timing.dtim_period = vif ? (vif->bss_conf.dtim_period ?: 1) : 1;
398
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100399 D_ASSOC(
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800400 "beacon interval %d beacon timer %d beacon tim %d\n",
401 le16_to_cpu(ctx->timing.beacon_interval),
402 le32_to_cpu(ctx->timing.beacon_init_val),
403 le16_to_cpu(ctx->timing.atim_window));
404
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200405 return il_send_cmd_pdu(il, ctx->rxon_timing_cmd,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800406 sizeof(ctx->timing), &ctx->timing);
407}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200408EXPORT_SYMBOL(il_send_rxon_timing);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800409
410void
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200411il_set_rxon_hwcrypto(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200412 struct il_rxon_context *ctx,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800413 int hw_decrypt)
414{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200415 struct il_rxon_cmd *rxon = &ctx->staging;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800416
417 if (hw_decrypt)
418 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
419 else
420 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
421
422}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200423EXPORT_SYMBOL(il_set_rxon_hwcrypto);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800424
425/* validate RXON structure is valid */
426int
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200427il_check_rxon_cmd(struct il_priv *il, struct il_rxon_context *ctx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800428{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200429 struct il_rxon_cmd *rxon = &ctx->staging;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800430 bool error = false;
431
432 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
433 if (rxon->flags & RXON_FLG_TGJ_NARROW_BAND_MSK) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200434 IL_WARN("check 2.4G: wrong narrow\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800435 error = true;
436 }
437 if (rxon->flags & RXON_FLG_RADAR_DETECT_MSK) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200438 IL_WARN("check 2.4G: wrong radar\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800439 error = true;
440 }
441 } else {
442 if (!(rxon->flags & RXON_FLG_SHORT_SLOT_MSK)) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200443 IL_WARN("check 5.2G: not short slot!\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800444 error = true;
445 }
446 if (rxon->flags & RXON_FLG_CCK_MSK) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200447 IL_WARN("check 5.2G: CCK!\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800448 error = true;
449 }
450 }
451 if ((rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200452 IL_WARN("mac/bssid mcast!\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800453 error = true;
454 }
455
456 /* make sure basic rates 6Mbps and 1Mbps are supported */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200457 if ((rxon->ofdm_basic_rates & IL_RATE_6M_MASK) == 0 &&
458 (rxon->cck_basic_rates & IL_RATE_1M_MASK) == 0) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200459 IL_WARN("neither 1 nor 6 are basic\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800460 error = true;
461 }
462
463 if (le16_to_cpu(rxon->assoc_id) > 2007) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200464 IL_WARN("aid > 2007\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800465 error = true;
466 }
467
468 if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
469 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200470 IL_WARN("CCK and short slot\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800471 error = true;
472 }
473
474 if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
475 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200476 IL_WARN("CCK and auto detect");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800477 error = true;
478 }
479
480 if ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
481 RXON_FLG_TGG_PROTECT_MSK)) ==
482 RXON_FLG_TGG_PROTECT_MSK) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200483 IL_WARN("TGg but no auto-detect\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800484 error = true;
485 }
486
487 if (error)
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200488 IL_WARN("Tuning to channel %d\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800489 le16_to_cpu(rxon->channel));
490
491 if (error) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200492 IL_ERR("Invalid RXON\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800493 return -EINVAL;
494 }
495 return 0;
496}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200497EXPORT_SYMBOL(il_check_rxon_cmd);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800498
499/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200500 * il_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200501 * @il: staging_rxon is compared to active_rxon
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800502 *
503 * If the RXON structure is changing enough to require a new tune,
504 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
505 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
506 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200507int il_full_rxon_required(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200508 struct il_rxon_context *ctx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800509{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200510 const struct il_rxon_cmd *staging = &ctx->staging;
511 const struct il_rxon_cmd *active = &ctx->active;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800512
513#define CHK(cond) \
514 if ((cond)) { \
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100515 D_INFO("need full RXON - " #cond "\n"); \
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800516 return 1; \
517 }
518
519#define CHK_NEQ(c1, c2) \
520 if ((c1) != (c2)) { \
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100521 D_INFO("need full RXON - " \
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800522 #c1 " != " #c2 " - %d != %d\n", \
523 (c1), (c2)); \
524 return 1; \
525 }
526
527 /* These items are only settable from the full RXON command */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200528 CHK(!il_is_associated_ctx(ctx));
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800529 CHK(compare_ether_addr(staging->bssid_addr, active->bssid_addr));
530 CHK(compare_ether_addr(staging->node_addr, active->node_addr));
531 CHK(compare_ether_addr(staging->wlap_bssid_addr,
532 active->wlap_bssid_addr));
533 CHK_NEQ(staging->dev_type, active->dev_type);
534 CHK_NEQ(staging->channel, active->channel);
535 CHK_NEQ(staging->air_propagation, active->air_propagation);
536 CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates,
537 active->ofdm_ht_single_stream_basic_rates);
538 CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates,
539 active->ofdm_ht_dual_stream_basic_rates);
540 CHK_NEQ(staging->assoc_id, active->assoc_id);
541
542 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
543 * be updated with the RXON_ASSOC command -- however only some
544 * flag transitions are allowed using RXON_ASSOC */
545
546 /* Check if we are not switching bands */
547 CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK,
548 active->flags & RXON_FLG_BAND_24G_MSK);
549
550 /* Check if we are switching association toggle */
551 CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK,
552 active->filter_flags & RXON_FILTER_ASSOC_MSK);
553
554#undef CHK
555#undef CHK_NEQ
556
557 return 0;
558}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200559EXPORT_SYMBOL(il_full_rxon_required);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800560
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200561u8 il_get_lowest_plcp(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200562 struct il_rxon_context *ctx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800563{
564 /*
565 * Assign the lowest rate -- should really get this from
566 * the beacon skb from mac80211.
567 */
568 if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK)
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200569 return IL_RATE_1M_PLCP;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800570 else
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200571 return IL_RATE_6M_PLCP;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800572}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200573EXPORT_SYMBOL(il_get_lowest_plcp);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800574
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200575static void _il_set_rxon_ht(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200576 struct il_ht_config *ht_conf,
577 struct il_rxon_context *ctx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800578{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200579 struct il_rxon_cmd *rxon = &ctx->staging;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800580
581 if (!ctx->ht.enabled) {
582 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
583 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
584 RXON_FLG_HT40_PROT_MSK |
585 RXON_FLG_HT_PROT_MSK);
586 return;
587 }
588
589 rxon->flags |= cpu_to_le32(ctx->ht.protection <<
590 RXON_FLG_HT_OPERATING_MODE_POS);
591
592 /* Set up channel bandwidth:
593 * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
594 /* clear the HT channel mode before set the mode */
595 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
596 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200597 if (il_is_ht40_tx_allowed(il, ctx, NULL)) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800598 /* pure ht40 */
599 if (ctx->ht.protection ==
600 IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
601 rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
602 /* Note: control channel is opposite of extension channel */
603 switch (ctx->ht.extension_chan_offset) {
604 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
605 rxon->flags &=
606 ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
607 break;
608 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
609 rxon->flags |=
610 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
611 break;
612 }
613 } else {
614 /* Note: control channel is opposite of extension channel */
615 switch (ctx->ht.extension_chan_offset) {
616 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
617 rxon->flags &=
618 ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
619 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
620 break;
621 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
622 rxon->flags |=
623 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
624 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
625 break;
626 case IEEE80211_HT_PARAM_CHA_SEC_NONE:
627 default:
628 /* channel location only valid if in Mixed mode */
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200629 IL_ERR(
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800630 "invalid extension channel offset\n");
631 break;
632 }
633 }
634 } else {
635 rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
636 }
637
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200638 if (il->cfg->ops->hcmd->set_rxon_chain)
639 il->cfg->ops->hcmd->set_rxon_chain(il, ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800640
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100641 D_ASSOC("rxon flags 0x%X operation mode :0x%X "
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800642 "extension channel offset 0x%x\n",
643 le32_to_cpu(rxon->flags), ctx->ht.protection,
644 ctx->ht.extension_chan_offset);
645}
646
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200647void il_set_rxon_ht(struct il_priv *il, struct il_ht_config *ht_conf)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800648{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200649 struct il_rxon_context *ctx;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800650
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200651 for_each_context(il, ctx)
652 _il_set_rxon_ht(il, ht_conf, ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800653}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200654EXPORT_SYMBOL(il_set_rxon_ht);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800655
656/* Return valid, unused, channel for a passive scan to reset the RF */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200657u8 il_get_single_channel_number(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800658 enum ieee80211_band band)
659{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200660 const struct il_channel_info *ch_info;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800661 int i;
662 u8 channel = 0;
663 u8 min, max;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200664 struct il_rxon_context *ctx;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800665
666 if (band == IEEE80211_BAND_5GHZ) {
667 min = 14;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200668 max = il->channel_count;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800669 } else {
670 min = 0;
671 max = 14;
672 }
673
674 for (i = min; i < max; i++) {
675 bool busy = false;
676
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200677 for_each_context(il, ctx) {
678 busy = il->channel_info[i].channel ==
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800679 le16_to_cpu(ctx->staging.channel);
680 if (busy)
681 break;
682 }
683
684 if (busy)
685 continue;
686
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200687 channel = il->channel_info[i].channel;
688 ch_info = il_get_channel_info(il, band, channel);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200689 if (il_is_channel_valid(ch_info))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800690 break;
691 }
692
693 return channel;
694}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200695EXPORT_SYMBOL(il_get_single_channel_number);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800696
697/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200698 * il_set_rxon_channel - Set the band and channel values in staging RXON
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800699 * @ch: requested channel as a pointer to struct ieee80211_channel
700
701 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
702 * in the staging RXON flag structure based on the ch->band
703 */
704int
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200705il_set_rxon_channel(struct il_priv *il, struct ieee80211_channel *ch,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200706 struct il_rxon_context *ctx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800707{
708 enum ieee80211_band band = ch->band;
709 u16 channel = ch->hw_value;
710
711 if ((le16_to_cpu(ctx->staging.channel) == channel) &&
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200712 (il->band == band))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800713 return 0;
714
715 ctx->staging.channel = cpu_to_le16(channel);
716 if (band == IEEE80211_BAND_5GHZ)
717 ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK;
718 else
719 ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
720
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200721 il->band = band;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800722
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100723 D_INFO("Staging channel set to %d [%d]\n", channel, band);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800724
725 return 0;
726}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200727EXPORT_SYMBOL(il_set_rxon_channel);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800728
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200729void il_set_flags_for_band(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200730 struct il_rxon_context *ctx,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800731 enum ieee80211_band band,
732 struct ieee80211_vif *vif)
733{
734 if (band == IEEE80211_BAND_5GHZ) {
735 ctx->staging.flags &=
736 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
737 | RXON_FLG_CCK_MSK);
738 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
739 } else {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200740 /* Copied from il_post_associate() */
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800741 if (vif && vif->bss_conf.use_short_slot)
742 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
743 else
744 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
745
746 ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
747 ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK;
748 ctx->staging.flags &= ~RXON_FLG_CCK_MSK;
749 }
750}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200751EXPORT_SYMBOL(il_set_flags_for_band);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800752
753/*
754 * initialize rxon structure with default values from eeprom
755 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200756void il_connection_init_rx_config(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200757 struct il_rxon_context *ctx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800758{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200759 const struct il_channel_info *ch_info;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800760
761 memset(&ctx->staging, 0, sizeof(ctx->staging));
762
763 if (!ctx->vif) {
764 ctx->staging.dev_type = ctx->unused_devtype;
765 } else
766 switch (ctx->vif->type) {
767
768 case NL80211_IFTYPE_STATION:
769 ctx->staging.dev_type = ctx->station_devtype;
770 ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
771 break;
772
773 case NL80211_IFTYPE_ADHOC:
774 ctx->staging.dev_type = ctx->ibss_devtype;
775 ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
776 ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
777 RXON_FILTER_ACCEPT_GRP_MSK;
778 break;
779
780 default:
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200781 IL_ERR("Unsupported interface type %d\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800782 ctx->vif->type);
783 break;
784 }
785
786#if 0
787 /* TODO: Figure out when short_preamble would be set and cache from
788 * that */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200789 if (!hw_to_local(il->hw)->short_preamble)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800790 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
791 else
792 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
793#endif
794
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200795 ch_info = il_get_channel_info(il, il->band,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800796 le16_to_cpu(ctx->active.channel));
797
798 if (!ch_info)
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200799 ch_info = &il->channel_info[0];
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800800
801 ctx->staging.channel = cpu_to_le16(ch_info->channel);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200802 il->band = ch_info->band;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800803
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200804 il_set_flags_for_band(il, ctx, il->band, ctx->vif);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800805
806 ctx->staging.ofdm_basic_rates =
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200807 (IL_OFDM_RATES_MASK >> IL_FIRST_OFDM_RATE) & 0xFF;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800808 ctx->staging.cck_basic_rates =
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200809 (IL_CCK_RATES_MASK >> IL_FIRST_CCK_RATE) & 0xF;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800810
811 /* clear both MIX and PURE40 mode flag */
812 ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
813 RXON_FLG_CHANNEL_MODE_PURE_40);
814 if (ctx->vif)
815 memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN);
816
817 ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff;
818 ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff;
819}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200820EXPORT_SYMBOL(il_connection_init_rx_config);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800821
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200822void il_set_rate(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800823{
824 const struct ieee80211_supported_band *hw = NULL;
825 struct ieee80211_rate *rate;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200826 struct il_rxon_context *ctx;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800827 int i;
828
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200829 hw = il_get_hw_mode(il, il->band);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800830 if (!hw) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200831 IL_ERR("Failed to set rate: unable to get hw mode\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800832 return;
833 }
834
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200835 il->active_rate = 0;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800836
837 for (i = 0; i < hw->n_bitrates; i++) {
838 rate = &(hw->bitrates[i]);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200839 if (rate->hw_value < IL_RATE_COUNT_LEGACY)
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200840 il->active_rate |= (1 << rate->hw_value);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800841 }
842
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100843 D_RATE("Set active_rate = %0x\n", il->active_rate);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800844
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200845 for_each_context(il, ctx) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800846 ctx->staging.cck_basic_rates =
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200847 (IL_CCK_BASIC_RATES_MASK >> IL_FIRST_CCK_RATE) & 0xF;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800848
849 ctx->staging.ofdm_basic_rates =
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200850 (IL_OFDM_BASIC_RATES_MASK >> IL_FIRST_OFDM_RATE) & 0xFF;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800851 }
852}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200853EXPORT_SYMBOL(il_set_rate);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800854
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200855void il_chswitch_done(struct il_priv *il, bool is_success)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800856{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200857 struct il_rxon_context *ctx = &il->contexts[IL_RXON_CTX_BSS];
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800858
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200859 if (test_bit(STATUS_EXIT_PENDING, &il->status))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800860 return;
861
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200862 if (test_and_clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &il->status))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800863 ieee80211_chswitch_done(ctx->vif, is_success);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800864}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200865EXPORT_SYMBOL(il_chswitch_done);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800866
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200867void il_rx_csa(struct il_priv *il, struct il_rx_mem_buffer *rxb)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800868{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200869 struct il_rx_packet *pkt = rxb_addr(rxb);
870 struct il_csa_notification *csa = &(pkt->u.csa_notif);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800871
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200872 struct il_rxon_context *ctx = &il->contexts[IL_RXON_CTX_BSS];
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200873 struct il_rxon_cmd *rxon = (void *)&ctx->active;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800874
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200875 if (!test_bit(STATUS_CHANNEL_SWITCH_PENDING, &il->status))
Stanislaw Gruszka51e65252011-06-08 15:26:31 +0200876 return;
877
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200878 if (!le32_to_cpu(csa->status) && csa->channel == il->switch_channel) {
Stanislaw Gruszka51e65252011-06-08 15:26:31 +0200879 rxon->channel = csa->channel;
880 ctx->staging.channel = csa->channel;
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100881 D_11H("CSA notif: channel %d\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800882 le16_to_cpu(csa->channel));
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200883 il_chswitch_done(il, true);
Stanislaw Gruszka51e65252011-06-08 15:26:31 +0200884 } else {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200885 IL_ERR("CSA notif (fail) : channel %d\n",
Stanislaw Gruszka51e65252011-06-08 15:26:31 +0200886 le16_to_cpu(csa->channel));
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200887 il_chswitch_done(il, false);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800888 }
889}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200890EXPORT_SYMBOL(il_rx_csa);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800891
892#ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200893void il_print_rx_config_cmd(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200894 struct il_rxon_context *ctx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800895{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200896 struct il_rxon_cmd *rxon = &ctx->staging;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800897
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100898 D_RADIO("RX CONFIG:\n");
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200899 il_print_hex_dump(il, IL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100900 D_RADIO("u16 channel: 0x%x\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800901 le16_to_cpu(rxon->channel));
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100902 D_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
903 D_RADIO("u32 filter_flags: 0x%08x\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800904 le32_to_cpu(rxon->filter_flags));
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100905 D_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
906 D_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800907 rxon->ofdm_basic_rates);
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100908 D_RADIO("u8 cck_basic_rates: 0x%02x\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800909 rxon->cck_basic_rates);
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100910 D_RADIO("u8[6] node_addr: %pM\n", rxon->node_addr);
911 D_RADIO("u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
912 D_RADIO("u16 assoc_id: 0x%x\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800913 le16_to_cpu(rxon->assoc_id));
914}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200915EXPORT_SYMBOL(il_print_rx_config_cmd);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800916#endif
917/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200918 * il_irq_handle_error - called for HW or SW error interrupt from card
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800919 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200920void il_irq_handle_error(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800921{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200922 /* Set the FW error flag -- cleared on il_down */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200923 set_bit(STATUS_FW_ERROR, &il->status);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800924
925 /* Cancel currently queued command. */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200926 clear_bit(STATUS_HCMD_ACTIVE, &il->status);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800927
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200928 IL_ERR("Loaded firmware version: %s\n",
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200929 il->hw->wiphy->fw_version);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800930
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200931 il->cfg->ops->lib->dump_nic_error_log(il);
932 if (il->cfg->ops->lib->dump_fh)
933 il->cfg->ops->lib->dump_fh(il, NULL, false);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800934#ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200935 if (il_get_debug_level(il) & IL_DL_FW_ERRORS)
936 il_print_rx_config_cmd(il,
937 &il->contexts[IL_RXON_CTX_BSS]);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800938#endif
939
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200940 wake_up(&il->wait_command_queue);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800941
942 /* Keep the restart process from trying to send host
943 * commands by clearing the INIT status bit */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200944 clear_bit(STATUS_READY, &il->status);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800945
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200946 if (!test_bit(STATUS_EXIT_PENDING, &il->status)) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100947 IL_DBG(IL_DL_FW_ERRORS,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800948 "Restarting adapter due to uCode error.\n");
949
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200950 if (il->cfg->mod_params->restart_fw)
951 queue_work(il->workqueue, &il->restart);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800952 }
953}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200954EXPORT_SYMBOL(il_irq_handle_error);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800955
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200956static int il_apm_stop_master(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800957{
958 int ret = 0;
959
960 /* stop device's busmaster DMA activity */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200961 il_set_bit(il, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800962
Stanislaw Gruszka142b3432011-08-24 15:22:57 +0200963 ret = _il_poll_bit(il, CSR_RESET, CSR_RESET_REG_FLAG_MASTER_DISABLED,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800964 CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
965 if (ret)
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200966 IL_WARN("Master Disable Timed Out, 100 usec\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800967
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100968 D_INFO("stop master\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800969
970 return ret;
971}
972
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200973void il_apm_stop(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800974{
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100975 D_INFO("Stop card, put in low power state\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800976
977 /* Stop device's DMA activity */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200978 il_apm_stop_master(il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800979
980 /* Reset the entire device */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200981 il_set_bit(il, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800982
983 udelay(10);
984
985 /*
986 * Clear "initialization complete" bit to move adapter from
987 * D0A* (powered-up Active) --> D0U* (Uninitialized) state.
988 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200989 il_clear_bit(il, CSR_GP_CNTRL,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800990 CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
991}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200992EXPORT_SYMBOL(il_apm_stop);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800993
994
995/*
996 * Start up NIC's basic functionality after it has been reset
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200997 * (e.g. after platform boot, or shutdown via il_apm_stop())
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800998 * NOTE: This does not load uCode nor start the embedded processor
999 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001000int il_apm_init(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001001{
1002 int ret = 0;
1003 u16 lctl;
1004
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001005 D_INFO("Init card's basic functions\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001006
1007 /*
1008 * Use "set_bit" below rather than "write", to preserve any hardware
1009 * bits already set by default after reset.
1010 */
1011
1012 /* Disable L0S exit timer (platform NMI Work/Around) */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001013 il_set_bit(il, CSR_GIO_CHICKEN_BITS,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001014 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
1015
1016 /*
1017 * Disable L0s without affecting L1;
1018 * don't wait for ICH L0s (ICH bug W/A)
1019 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001020 il_set_bit(il, CSR_GIO_CHICKEN_BITS,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001021 CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
1022
1023 /* Set FH wait threshold to maximum (HW error during stress W/A) */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001024 il_set_bit(il, CSR_DBG_HPET_MEM_REG,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001025 CSR_DBG_HPET_MEM_REG_VAL);
1026
1027 /*
1028 * Enable HAP INTA (interrupt from management bus) to
1029 * wake device's PCI Express link L1a -> L0s
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001030 * NOTE: This is no-op for 3945 (non-existent bit)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001031 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001032 il_set_bit(il, CSR_HW_IF_CONFIG_REG,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001033 CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A);
1034
1035 /*
1036 * HW bug W/A for instability in PCIe bus L0->L0S->L1 transition.
1037 * Check if BIOS (or OS) enabled L1-ASPM on this device.
1038 * If so (likely), disable L0S, so device moves directly L0->L1;
1039 * costs negligible amount of power savings.
1040 * If not (unlikely), enable L0S, so there is at least some
1041 * power savings, even without L1.
1042 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001043 if (il->cfg->base_params->set_l0s) {
1044 lctl = il_pcie_link_ctl(il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001045 if ((lctl & PCI_CFG_LINK_CTRL_VAL_L1_EN) ==
1046 PCI_CFG_LINK_CTRL_VAL_L1_EN) {
1047 /* L1-ASPM enabled; disable(!) L0S */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001048 il_set_bit(il, CSR_GIO_REG,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001049 CSR_GIO_REG_VAL_L0S_ENABLED);
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001050 D_POWER("L1 Enabled; Disabling L0S\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001051 } else {
1052 /* L1-ASPM disabled; enable(!) L0S */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001053 il_clear_bit(il, CSR_GIO_REG,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001054 CSR_GIO_REG_VAL_L0S_ENABLED);
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001055 D_POWER("L1 Disabled; Enabling L0S\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001056 }
1057 }
1058
1059 /* Configure analog phase-lock-loop before activating to D0A */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001060 if (il->cfg->base_params->pll_cfg_val)
1061 il_set_bit(il, CSR_ANA_PLL_CFG,
1062 il->cfg->base_params->pll_cfg_val);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001063
1064 /*
1065 * Set "initialization complete" bit to move adapter from
1066 * D0U* --> D0A* (powered-up active) state.
1067 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001068 il_set_bit(il, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001069
1070 /*
1071 * Wait for clock stabilization; once stabilized, access to
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +02001072 * device-internal resources is supported, e.g. il_wr_prph()
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001073 * and accesses to uCode SRAM.
1074 */
Stanislaw Gruszka142b3432011-08-24 15:22:57 +02001075 ret = _il_poll_bit(il, CSR_GP_CNTRL,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001076 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
1077 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
1078 if (ret < 0) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001079 D_INFO("Failed to init the card\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001080 goto out;
1081 }
1082
1083 /*
1084 * Enable DMA and BSM (if used) clocks, wait for them to stabilize.
1085 * BSM (Boostrap State Machine) is only in 3945 and 4965.
1086 *
1087 * Write to "CLK_EN_REG"; "1" bits enable clocks, while "0" bits
1088 * do not disable clocks. This preserves any hardware bits already
1089 * set by default in "CLK_CTRL_REG" after reset.
1090 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001091 if (il->cfg->base_params->use_bsm)
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +02001092 il_wr_prph(il, APMG_CLK_EN_REG,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001093 APMG_CLK_VAL_DMA_CLK_RQT | APMG_CLK_VAL_BSM_CLK_RQT);
1094 else
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +02001095 il_wr_prph(il, APMG_CLK_EN_REG,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001096 APMG_CLK_VAL_DMA_CLK_RQT);
1097 udelay(20);
1098
1099 /* Disable L1-Active */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001100 il_set_bits_prph(il, APMG_PCIDEV_STT_REG,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001101 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
1102
1103out:
1104 return ret;
1105}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001106EXPORT_SYMBOL(il_apm_init);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001107
1108
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001109int il_set_tx_power(struct il_priv *il, s8 tx_power, bool force)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001110{
1111 int ret;
1112 s8 prev_tx_power;
Stanislaw Gruszka43f12d42011-02-24 14:23:55 +01001113 bool defer;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001114 struct il_rxon_context *ctx = &il->contexts[IL_RXON_CTX_BSS];
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001115
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001116 lockdep_assert_held(&il->mutex);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001117
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001118 if (il->tx_power_user_lmt == tx_power && !force)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001119 return 0;
1120
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001121 if (!il->cfg->ops->lib->send_tx_power)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001122 return -EOPNOTSUPP;
1123
Stanislaw Gruszka332704a2011-04-13 10:56:51 +02001124 /* 0 dBm mean 1 milliwatt */
1125 if (tx_power < 0) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001126 IL_WARN(
Stanislaw Gruszka332704a2011-04-13 10:56:51 +02001127 "Requested user TXPOWER %d below 1 mW.\n",
1128 tx_power);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001129 return -EINVAL;
1130 }
1131
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001132 if (tx_power > il->tx_power_device_lmt) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001133 IL_WARN(
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001134 "Requested user TXPOWER %d above upper limit %d.\n",
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001135 tx_power, il->tx_power_device_lmt);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001136 return -EINVAL;
1137 }
1138
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001139 if (!il_is_ready_rf(il))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001140 return -EIO;
1141
Stanislaw Gruszka43f12d42011-02-24 14:23:55 +01001142 /* scan complete and commit_rxon use tx_power_next value,
1143 * it always need to be updated for newest request */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001144 il->tx_power_next = tx_power;
Stanislaw Gruszka43f12d42011-02-24 14:23:55 +01001145
1146 /* do not set tx power when scanning or channel changing */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001147 defer = test_bit(STATUS_SCANNING, &il->status) ||
Stanislaw Gruszka43f12d42011-02-24 14:23:55 +01001148 memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging));
1149 if (defer && !force) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001150 D_INFO("Deferring tx power set\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001151 return 0;
1152 }
1153
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001154 prev_tx_power = il->tx_power_user_lmt;
1155 il->tx_power_user_lmt = tx_power;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001156
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001157 ret = il->cfg->ops->lib->send_tx_power(il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001158
1159 /* if fail to set tx_power, restore the orig. tx power */
1160 if (ret) {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001161 il->tx_power_user_lmt = prev_tx_power;
1162 il->tx_power_next = prev_tx_power;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001163 }
1164 return ret;
1165}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001166EXPORT_SYMBOL(il_set_tx_power);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001167
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001168void il_send_bt_config(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001169{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001170 struct il_bt_cmd bt_cmd = {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001171 .lead_time = BT_LEAD_TIME_DEF,
1172 .max_kill = BT_MAX_KILL_DEF,
1173 .kill_ack_mask = 0,
1174 .kill_cts_mask = 0,
1175 };
1176
1177 if (!bt_coex_active)
1178 bt_cmd.flags = BT_COEX_DISABLE;
1179 else
1180 bt_cmd.flags = BT_COEX_ENABLE;
1181
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001182 D_INFO("BT coex %s\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001183 (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active");
1184
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001185 if (il_send_cmd_pdu(il, REPLY_BT_CONFIG,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001186 sizeof(struct il_bt_cmd), &bt_cmd))
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001187 IL_ERR("failed to send BT Coex Config\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001188}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001189EXPORT_SYMBOL(il_send_bt_config);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001190
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001191int il_send_statistics_request(struct il_priv *il, u8 flags, bool clear)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001192{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001193 struct il_statistics_cmd statistics_cmd = {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001194 .configuration_flags =
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001195 clear ? IL_STATS_CONF_CLEAR_STATS : 0,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001196 };
1197
1198 if (flags & CMD_ASYNC)
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001199 return il_send_cmd_pdu_async(il, REPLY_STATISTICS_CMD,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001200 sizeof(struct il_statistics_cmd),
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001201 &statistics_cmd, NULL);
1202 else
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001203 return il_send_cmd_pdu(il, REPLY_STATISTICS_CMD,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001204 sizeof(struct il_statistics_cmd),
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001205 &statistics_cmd);
1206}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001207EXPORT_SYMBOL(il_send_statistics_request);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001208
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001209void il_rx_pm_sleep_notif(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001210 struct il_rx_mem_buffer *rxb)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001211{
1212#ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001213 struct il_rx_packet *pkt = rxb_addr(rxb);
1214 struct il_sleep_notification *sleep = &(pkt->u.sleep_notif);
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001215 D_RX("sleep mode: %d, src: %d\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001216 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
1217#endif
1218}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001219EXPORT_SYMBOL(il_rx_pm_sleep_notif);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001220
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001221void il_rx_pm_debug_statistics_notif(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001222 struct il_rx_mem_buffer *rxb)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001223{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001224 struct il_rx_packet *pkt = rxb_addr(rxb);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001225 u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001226 D_RADIO("Dumping %d bytes of unhandled "
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001227 "notification for %s:\n", len,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001228 il_get_cmd_string(pkt->hdr.cmd));
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001229 il_print_hex_dump(il, IL_DL_RADIO, pkt->u.raw, len);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001230}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001231EXPORT_SYMBOL(il_rx_pm_debug_statistics_notif);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001232
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001233void il_rx_reply_error(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001234 struct il_rx_mem_buffer *rxb)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001235{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001236 struct il_rx_packet *pkt = rxb_addr(rxb);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001237
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001238 IL_ERR("Error Reply type 0x%08X cmd %s (0x%02X) "
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001239 "seq 0x%04X ser 0x%08X\n",
1240 le32_to_cpu(pkt->u.err_resp.error_type),
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001241 il_get_cmd_string(pkt->u.err_resp.cmd_id),
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001242 pkt->u.err_resp.cmd_id,
1243 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
1244 le32_to_cpu(pkt->u.err_resp.error_info));
1245}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001246EXPORT_SYMBOL(il_rx_reply_error);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001247
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001248void il_clear_isr_stats(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001249{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001250 memset(&il->isr_stats, 0, sizeof(il->isr_stats));
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001251}
1252
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001253int il_mac_conf_tx(struct ieee80211_hw *hw,
Eliad Peller8a3a3c82011-10-02 10:15:52 +02001254 struct ieee80211_vif *vif, u16 queue,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001255 const struct ieee80211_tx_queue_params *params)
1256{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001257 struct il_priv *il = hw->priv;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001258 struct il_rxon_context *ctx;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001259 unsigned long flags;
1260 int q;
1261
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001262 D_MAC80211("enter\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001263
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001264 if (!il_is_ready_rf(il)) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001265 D_MAC80211("leave - RF not ready\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001266 return -EIO;
1267 }
1268
1269 if (queue >= AC_NUM) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001270 D_MAC80211("leave - queue >= AC_NUM %d\n", queue);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001271 return 0;
1272 }
1273
1274 q = AC_NUM - 1 - queue;
1275
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001276 spin_lock_irqsave(&il->lock, flags);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001277
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001278 for_each_context(il, ctx) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001279 ctx->qos_data.def_qos_parm.ac[q].cw_min =
1280 cpu_to_le16(params->cw_min);
1281 ctx->qos_data.def_qos_parm.ac[q].cw_max =
1282 cpu_to_le16(params->cw_max);
1283 ctx->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
1284 ctx->qos_data.def_qos_parm.ac[q].edca_txop =
1285 cpu_to_le16((params->txop * 32));
1286
1287 ctx->qos_data.def_qos_parm.ac[q].reserved1 = 0;
1288 }
1289
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001290 spin_unlock_irqrestore(&il->lock, flags);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001291
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001292 D_MAC80211("leave\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001293 return 0;
1294}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001295EXPORT_SYMBOL(il_mac_conf_tx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001296
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001297int il_mac_tx_last_beacon(struct ieee80211_hw *hw)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001298{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001299 struct il_priv *il = hw->priv;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001300
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001301 return il->ibss_manager == IL_IBSS_MANAGER;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001302}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001303EXPORT_SYMBOL_GPL(il_mac_tx_last_beacon);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001304
1305static int
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001306il_set_mode(struct il_priv *il, struct il_rxon_context *ctx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001307{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001308 il_connection_init_rx_config(il, ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001309
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001310 if (il->cfg->ops->hcmd->set_rxon_chain)
1311 il->cfg->ops->hcmd->set_rxon_chain(il, ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001312
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001313 return il_commit_rxon(il, ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001314}
1315
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001316static int il_setup_interface(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001317 struct il_rxon_context *ctx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001318{
1319 struct ieee80211_vif *vif = ctx->vif;
1320 int err;
1321
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001322 lockdep_assert_held(&il->mutex);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001323
1324 /*
1325 * This variable will be correct only when there's just
1326 * a single context, but all code using it is for hardware
1327 * that supports only one context.
1328 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001329 il->iw_mode = vif->type;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001330
1331 ctx->is_active = true;
1332
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001333 err = il_set_mode(il, ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001334 if (err) {
1335 if (!ctx->always_active)
1336 ctx->is_active = false;
1337 return err;
1338 }
1339
1340 return 0;
1341}
1342
1343int
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001344il_mac_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001345{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001346 struct il_priv *il = hw->priv;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001347 struct il_vif_priv *vif_priv = (void *)vif->drv_priv;
1348 struct il_rxon_context *tmp, *ctx = NULL;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001349 int err;
1350
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001351 D_MAC80211("enter: type %d, addr %pM\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001352 vif->type, vif->addr);
1353
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001354 mutex_lock(&il->mutex);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001355
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001356 if (!il_is_ready_rf(il)) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001357 IL_WARN("Try to add interface when device not ready\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001358 err = -EINVAL;
1359 goto out;
1360 }
1361
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001362 for_each_context(il, tmp) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001363 u32 possible_modes =
1364 tmp->interface_modes | tmp->exclusive_interface_modes;
1365
1366 if (tmp->vif) {
1367 /* check if this busy context is exclusive */
1368 if (tmp->exclusive_interface_modes &
1369 BIT(tmp->vif->type)) {
1370 err = -EINVAL;
1371 goto out;
1372 }
1373 continue;
1374 }
1375
1376 if (!(possible_modes & BIT(vif->type)))
1377 continue;
1378
1379 /* have maybe usable context w/o interface */
1380 ctx = tmp;
1381 break;
1382 }
1383
1384 if (!ctx) {
1385 err = -EOPNOTSUPP;
1386 goto out;
1387 }
1388
1389 vif_priv->ctx = ctx;
1390 ctx->vif = vif;
1391
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001392 err = il_setup_interface(il, ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001393 if (!err)
1394 goto out;
1395
1396 ctx->vif = NULL;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001397 il->iw_mode = NL80211_IFTYPE_STATION;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001398 out:
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001399 mutex_unlock(&il->mutex);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001400
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001401 D_MAC80211("leave\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001402 return err;
1403}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001404EXPORT_SYMBOL(il_mac_add_interface);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001405
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001406static void il_teardown_interface(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001407 struct ieee80211_vif *vif,
1408 bool mode_change)
1409{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001410 struct il_rxon_context *ctx = il_rxon_ctx_from_vif(vif);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001411
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001412 lockdep_assert_held(&il->mutex);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001413
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001414 if (il->scan_vif == vif) {
1415 il_scan_cancel_timeout(il, 200);
1416 il_force_scan_end(il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001417 }
1418
1419 if (!mode_change) {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001420 il_set_mode(il, ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001421 if (!ctx->always_active)
1422 ctx->is_active = false;
1423 }
1424}
1425
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001426void il_mac_remove_interface(struct ieee80211_hw *hw,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001427 struct ieee80211_vif *vif)
1428{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001429 struct il_priv *il = hw->priv;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001430 struct il_rxon_context *ctx = il_rxon_ctx_from_vif(vif);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001431
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001432 D_MAC80211("enter\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001433
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001434 mutex_lock(&il->mutex);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001435
1436 WARN_ON(ctx->vif != vif);
1437 ctx->vif = NULL;
1438
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001439 il_teardown_interface(il, vif, false);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001440
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001441 memset(il->bssid, 0, ETH_ALEN);
1442 mutex_unlock(&il->mutex);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001443
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001444 D_MAC80211("leave\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001445
1446}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001447EXPORT_SYMBOL(il_mac_remove_interface);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001448
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001449int il_alloc_txq_mem(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001450{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001451 if (!il->txq)
1452 il->txq = kzalloc(
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001453 sizeof(struct il_tx_queue) *
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001454 il->cfg->base_params->num_of_queues,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001455 GFP_KERNEL);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001456 if (!il->txq) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001457 IL_ERR("Not enough memory for txq\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001458 return -ENOMEM;
1459 }
1460 return 0;
1461}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001462EXPORT_SYMBOL(il_alloc_txq_mem);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001463
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001464void il_txq_mem(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001465{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001466 kfree(il->txq);
1467 il->txq = NULL;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001468}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001469EXPORT_SYMBOL(il_txq_mem);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001470
1471#ifdef CONFIG_IWLWIFI_LEGACY_DEBUGFS
1472
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001473#define IL_TRAFFIC_DUMP_SIZE (IL_TRAFFIC_ENTRY_SIZE * IL_TRAFFIC_ENTRIES)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001474
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001475void il_reset_traffic_log(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001476{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001477 il->tx_traffic_idx = 0;
1478 il->rx_traffic_idx = 0;
1479 if (il->tx_traffic)
1480 memset(il->tx_traffic, 0, IL_TRAFFIC_DUMP_SIZE);
1481 if (il->rx_traffic)
1482 memset(il->rx_traffic, 0, IL_TRAFFIC_DUMP_SIZE);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001483}
1484
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001485int il_alloc_traffic_mem(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001486{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001487 u32 traffic_size = IL_TRAFFIC_DUMP_SIZE;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001488
Stanislaw Gruszkad2ddf622011-08-16 14:17:04 +02001489 if (il_debug_level & IL_DL_TX) {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001490 if (!il->tx_traffic) {
1491 il->tx_traffic =
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001492 kzalloc(traffic_size, GFP_KERNEL);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001493 if (!il->tx_traffic)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001494 return -ENOMEM;
1495 }
1496 }
Stanislaw Gruszkad2ddf622011-08-16 14:17:04 +02001497 if (il_debug_level & IL_DL_RX) {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001498 if (!il->rx_traffic) {
1499 il->rx_traffic =
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001500 kzalloc(traffic_size, GFP_KERNEL);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001501 if (!il->rx_traffic)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001502 return -ENOMEM;
1503 }
1504 }
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001505 il_reset_traffic_log(il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001506 return 0;
1507}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001508EXPORT_SYMBOL(il_alloc_traffic_mem);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001509
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001510void il_free_traffic_mem(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001511{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001512 kfree(il->tx_traffic);
1513 il->tx_traffic = NULL;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001514
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001515 kfree(il->rx_traffic);
1516 il->rx_traffic = NULL;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001517}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001518EXPORT_SYMBOL(il_free_traffic_mem);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001519
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001520void il_dbg_log_tx_data_frame(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001521 u16 length, struct ieee80211_hdr *header)
1522{
1523 __le16 fc;
1524 u16 len;
1525
Stanislaw Gruszkad2ddf622011-08-16 14:17:04 +02001526 if (likely(!(il_debug_level & IL_DL_TX)))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001527 return;
1528
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001529 if (!il->tx_traffic)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001530 return;
1531
1532 fc = header->frame_control;
1533 if (ieee80211_is_data(fc)) {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001534 len = (length > IL_TRAFFIC_ENTRY_SIZE)
1535 ? IL_TRAFFIC_ENTRY_SIZE : length;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001536 memcpy((il->tx_traffic +
1537 (il->tx_traffic_idx * IL_TRAFFIC_ENTRY_SIZE)),
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001538 header, len);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001539 il->tx_traffic_idx =
1540 (il->tx_traffic_idx + 1) % IL_TRAFFIC_ENTRIES;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001541 }
1542}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001543EXPORT_SYMBOL(il_dbg_log_tx_data_frame);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001544
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001545void il_dbg_log_rx_data_frame(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001546 u16 length, struct ieee80211_hdr *header)
1547{
1548 __le16 fc;
1549 u16 len;
1550
Stanislaw Gruszkad2ddf622011-08-16 14:17:04 +02001551 if (likely(!(il_debug_level & IL_DL_RX)))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001552 return;
1553
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001554 if (!il->rx_traffic)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001555 return;
1556
1557 fc = header->frame_control;
1558 if (ieee80211_is_data(fc)) {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001559 len = (length > IL_TRAFFIC_ENTRY_SIZE)
1560 ? IL_TRAFFIC_ENTRY_SIZE : length;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001561 memcpy((il->rx_traffic +
1562 (il->rx_traffic_idx * IL_TRAFFIC_ENTRY_SIZE)),
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001563 header, len);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001564 il->rx_traffic_idx =
1565 (il->rx_traffic_idx + 1) % IL_TRAFFIC_ENTRIES;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001566 }
1567}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001568EXPORT_SYMBOL(il_dbg_log_rx_data_frame);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001569
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001570const char *il_get_mgmt_string(int cmd)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001571{
1572 switch (cmd) {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001573 IL_CMD(MANAGEMENT_ASSOC_REQ);
1574 IL_CMD(MANAGEMENT_ASSOC_RESP);
1575 IL_CMD(MANAGEMENT_REASSOC_REQ);
1576 IL_CMD(MANAGEMENT_REASSOC_RESP);
1577 IL_CMD(MANAGEMENT_PROBE_REQ);
1578 IL_CMD(MANAGEMENT_PROBE_RESP);
1579 IL_CMD(MANAGEMENT_BEACON);
1580 IL_CMD(MANAGEMENT_ATIM);
1581 IL_CMD(MANAGEMENT_DISASSOC);
1582 IL_CMD(MANAGEMENT_AUTH);
1583 IL_CMD(MANAGEMENT_DEAUTH);
1584 IL_CMD(MANAGEMENT_ACTION);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001585 default:
1586 return "UNKNOWN";
1587
1588 }
1589}
1590
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001591const char *il_get_ctrl_string(int cmd)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001592{
1593 switch (cmd) {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001594 IL_CMD(CONTROL_BACK_REQ);
1595 IL_CMD(CONTROL_BACK);
1596 IL_CMD(CONTROL_PSPOLL);
1597 IL_CMD(CONTROL_RTS);
1598 IL_CMD(CONTROL_CTS);
1599 IL_CMD(CONTROL_ACK);
1600 IL_CMD(CONTROL_CFEND);
1601 IL_CMD(CONTROL_CFENDACK);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001602 default:
1603 return "UNKNOWN";
1604
1605 }
1606}
1607
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001608void il_clear_traffic_stats(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001609{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001610 memset(&il->tx_stats, 0, sizeof(struct traffic_stats));
1611 memset(&il->rx_stats, 0, sizeof(struct traffic_stats));
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001612}
1613
1614/*
1615 * if CONFIG_IWLWIFI_LEGACY_DEBUGFS defined,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001616 * il_update_stats function will
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001617 * record all the MGMT, CTRL and DATA pkt for both TX and Rx pass
1618 * Use debugFs to display the rx/rx_statistics
1619 * if CONFIG_IWLWIFI_LEGACY_DEBUGFS not being defined, then no MGMT and CTRL
1620 * information will be recorded, but DATA pkt still will be recorded
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001621 * for the reason of il_led.c need to control the led blinking based on
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001622 * number of tx and rx data.
1623 *
1624 */
1625void
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001626il_update_stats(struct il_priv *il, bool is_tx, __le16 fc, u16 len)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001627{
1628 struct traffic_stats *stats;
1629
1630 if (is_tx)
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001631 stats = &il->tx_stats;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001632 else
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001633 stats = &il->rx_stats;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001634
1635 if (ieee80211_is_mgmt(fc)) {
1636 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
1637 case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
1638 stats->mgmt[MANAGEMENT_ASSOC_REQ]++;
1639 break;
1640 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
1641 stats->mgmt[MANAGEMENT_ASSOC_RESP]++;
1642 break;
1643 case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
1644 stats->mgmt[MANAGEMENT_REASSOC_REQ]++;
1645 break;
1646 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
1647 stats->mgmt[MANAGEMENT_REASSOC_RESP]++;
1648 break;
1649 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
1650 stats->mgmt[MANAGEMENT_PROBE_REQ]++;
1651 break;
1652 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
1653 stats->mgmt[MANAGEMENT_PROBE_RESP]++;
1654 break;
1655 case cpu_to_le16(IEEE80211_STYPE_BEACON):
1656 stats->mgmt[MANAGEMENT_BEACON]++;
1657 break;
1658 case cpu_to_le16(IEEE80211_STYPE_ATIM):
1659 stats->mgmt[MANAGEMENT_ATIM]++;
1660 break;
1661 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
1662 stats->mgmt[MANAGEMENT_DISASSOC]++;
1663 break;
1664 case cpu_to_le16(IEEE80211_STYPE_AUTH):
1665 stats->mgmt[MANAGEMENT_AUTH]++;
1666 break;
1667 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
1668 stats->mgmt[MANAGEMENT_DEAUTH]++;
1669 break;
1670 case cpu_to_le16(IEEE80211_STYPE_ACTION):
1671 stats->mgmt[MANAGEMENT_ACTION]++;
1672 break;
1673 }
1674 } else if (ieee80211_is_ctl(fc)) {
1675 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
1676 case cpu_to_le16(IEEE80211_STYPE_BACK_REQ):
1677 stats->ctrl[CONTROL_BACK_REQ]++;
1678 break;
1679 case cpu_to_le16(IEEE80211_STYPE_BACK):
1680 stats->ctrl[CONTROL_BACK]++;
1681 break;
1682 case cpu_to_le16(IEEE80211_STYPE_PSPOLL):
1683 stats->ctrl[CONTROL_PSPOLL]++;
1684 break;
1685 case cpu_to_le16(IEEE80211_STYPE_RTS):
1686 stats->ctrl[CONTROL_RTS]++;
1687 break;
1688 case cpu_to_le16(IEEE80211_STYPE_CTS):
1689 stats->ctrl[CONTROL_CTS]++;
1690 break;
1691 case cpu_to_le16(IEEE80211_STYPE_ACK):
1692 stats->ctrl[CONTROL_ACK]++;
1693 break;
1694 case cpu_to_le16(IEEE80211_STYPE_CFEND):
1695 stats->ctrl[CONTROL_CFEND]++;
1696 break;
1697 case cpu_to_le16(IEEE80211_STYPE_CFENDACK):
1698 stats->ctrl[CONTROL_CFENDACK]++;
1699 break;
1700 }
1701 } else {
1702 /* data */
1703 stats->data_cnt++;
1704 stats->data_bytes += len;
1705 }
1706}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001707EXPORT_SYMBOL(il_update_stats);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001708#endif
1709
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001710int il_force_reset(struct il_priv *il, bool external)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001711{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001712 struct il_force_reset *force_reset;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001713
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001714 if (test_bit(STATUS_EXIT_PENDING, &il->status))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001715 return -EINVAL;
1716
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001717 force_reset = &il->force_reset;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001718 force_reset->reset_request_count++;
1719 if (!external) {
1720 if (force_reset->last_force_reset_jiffies &&
1721 time_after(force_reset->last_force_reset_jiffies +
1722 force_reset->reset_duration, jiffies)) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001723 D_INFO("force reset rejected\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001724 force_reset->reset_reject_count++;
1725 return -EAGAIN;
1726 }
1727 }
1728 force_reset->reset_success_count++;
1729 force_reset->last_force_reset_jiffies = jiffies;
Stanislaw Gruszkadd6d2a82011-06-08 15:28:26 +02001730
1731 /*
1732 * if the request is from external(ex: debugfs),
1733 * then always perform the request in regardless the module
1734 * parameter setting
1735 * if the request is from internal (uCode error or driver
1736 * detect failure), then fw_restart module parameter
1737 * need to be check before performing firmware reload
1738 */
1739
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001740 if (!external && !il->cfg->mod_params->restart_fw) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001741 D_INFO("Cancel firmware reload based on "
Stanislaw Gruszkadd6d2a82011-06-08 15:28:26 +02001742 "module parameter setting\n");
1743 return 0;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001744 }
Stanislaw Gruszkadd6d2a82011-06-08 15:28:26 +02001745
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001746 IL_ERR("On demand firmware reload\n");
Stanislaw Gruszkadd6d2a82011-06-08 15:28:26 +02001747
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001748 /* Set the FW error flag -- cleared on il_down */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001749 set_bit(STATUS_FW_ERROR, &il->status);
1750 wake_up(&il->wait_command_queue);
Stanislaw Gruszkadd6d2a82011-06-08 15:28:26 +02001751 /*
1752 * Keep the restart process from trying to send host
1753 * commands by clearing the INIT status bit
1754 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001755 clear_bit(STATUS_READY, &il->status);
1756 queue_work(il->workqueue, &il->restart);
Stanislaw Gruszkadd6d2a82011-06-08 15:28:26 +02001757
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001758 return 0;
1759}
1760
1761int
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001762il_mac_change_interface(struct ieee80211_hw *hw,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001763 struct ieee80211_vif *vif,
1764 enum nl80211_iftype newtype, bool newp2p)
1765{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001766 struct il_priv *il = hw->priv;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001767 struct il_rxon_context *ctx = il_rxon_ctx_from_vif(vif);
1768 struct il_rxon_context *tmp;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001769 u32 interface_modes;
1770 int err;
1771
1772 newtype = ieee80211_iftype_p2p(newtype, newp2p);
1773
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001774 mutex_lock(&il->mutex);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001775
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001776 if (!ctx->vif || !il_is_ready_rf(il)) {
Johannes Bergffd8c742011-03-29 15:28:11 +02001777 /*
1778 * Huh? But wait ... this can maybe happen when
1779 * we're in the middle of a firmware restart!
1780 */
1781 err = -EBUSY;
1782 goto out;
1783 }
1784
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001785 interface_modes = ctx->interface_modes | ctx->exclusive_interface_modes;
1786
1787 if (!(interface_modes & BIT(newtype))) {
1788 err = -EBUSY;
1789 goto out;
1790 }
1791
1792 if (ctx->exclusive_interface_modes & BIT(newtype)) {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001793 for_each_context(il, tmp) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001794 if (ctx == tmp)
1795 continue;
1796
1797 if (!tmp->vif)
1798 continue;
1799
1800 /*
1801 * The current mode switch would be exclusive, but
1802 * another context is active ... refuse the switch.
1803 */
1804 err = -EBUSY;
1805 goto out;
1806 }
1807 }
1808
1809 /* success */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001810 il_teardown_interface(il, vif, true);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001811 vif->type = newtype;
Johannes Bergffd8c742011-03-29 15:28:11 +02001812 vif->p2p = newp2p;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001813 err = il_setup_interface(il, ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001814 WARN_ON(err);
1815 /*
1816 * We've switched internally, but submitting to the
1817 * device may have failed for some reason. Mask this
1818 * error, because otherwise mac80211 will not switch
1819 * (and set the interface type back) and we'll be
1820 * out of sync with it.
1821 */
1822 err = 0;
1823
1824 out:
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001825 mutex_unlock(&il->mutex);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001826 return err;
1827}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001828EXPORT_SYMBOL(il_mac_change_interface);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001829
1830/*
1831 * On every watchdog tick we check (latest) time stamp. If it does not
1832 * change during timeout period and queue is not empty we reset firmware.
1833 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001834static int il_check_stuck_queue(struct il_priv *il, int cnt)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001835{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001836 struct il_tx_queue *txq = &il->txq[cnt];
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001837 struct il_queue *q = &txq->q;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001838 unsigned long timeout;
1839 int ret;
1840
1841 if (q->read_ptr == q->write_ptr) {
1842 txq->time_stamp = jiffies;
1843 return 0;
1844 }
1845
1846 timeout = txq->time_stamp +
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001847 msecs_to_jiffies(il->cfg->base_params->wd_timeout);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001848
1849 if (time_after(jiffies, timeout)) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001850 IL_ERR("Queue %d stuck for %u ms.\n",
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001851 q->id, il->cfg->base_params->wd_timeout);
1852 ret = il_force_reset(il, false);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001853 return (ret == -EAGAIN) ? 0 : 1;
1854 }
1855
1856 return 0;
1857}
1858
1859/*
1860 * Making watchdog tick be a quarter of timeout assure we will
1861 * discover the queue hung between timeout and 1.25*timeout
1862 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001863#define IL_WD_TICK(timeout) ((timeout) / 4)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001864
1865/*
1866 * Watchdog timer callback, we check each tx queue for stuck, if if hung
1867 * we reset the firmware. If everything is fine just rearm the timer.
1868 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001869void il_bg_watchdog(unsigned long data)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001870{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001871 struct il_priv *il = (struct il_priv *)data;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001872 int cnt;
1873 unsigned long timeout;
1874
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001875 if (test_bit(STATUS_EXIT_PENDING, &il->status))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001876 return;
1877
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001878 timeout = il->cfg->base_params->wd_timeout;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001879 if (timeout == 0)
1880 return;
1881
1882 /* monitor and check for stuck cmd queue */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001883 if (il_check_stuck_queue(il, il->cmd_queue))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001884 return;
1885
1886 /* monitor and check for other stuck queues */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001887 if (il_is_any_associated(il)) {
1888 for (cnt = 0; cnt < il->hw_params.max_txq_num; cnt++) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001889 /* skip as we already checked the command queue */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001890 if (cnt == il->cmd_queue)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001891 continue;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001892 if (il_check_stuck_queue(il, cnt))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001893 return;
1894 }
1895 }
1896
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001897 mod_timer(&il->watchdog, jiffies +
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001898 msecs_to_jiffies(IL_WD_TICK(timeout)));
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001899}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001900EXPORT_SYMBOL(il_bg_watchdog);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001901
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001902void il_setup_watchdog(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001903{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001904 unsigned int timeout = il->cfg->base_params->wd_timeout;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001905
1906 if (timeout)
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001907 mod_timer(&il->watchdog,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001908 jiffies + msecs_to_jiffies(IL_WD_TICK(timeout)));
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001909 else
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001910 del_timer(&il->watchdog);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001911}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001912EXPORT_SYMBOL(il_setup_watchdog);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001913
1914/*
1915 * extended beacon time format
1916 * time in usec will be changed into a 32-bit value in extended:internal format
1917 * the extended part is the beacon counts
1918 * the internal part is the time in usec within one beacon interval
1919 */
1920u32
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001921il_usecs_to_beacons(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001922 u32 usec, u32 beacon_interval)
1923{
1924 u32 quot;
1925 u32 rem;
1926 u32 interval = beacon_interval * TIME_UNIT;
1927
1928 if (!interval || !usec)
1929 return 0;
1930
1931 quot = (usec / interval) &
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001932 (il_beacon_time_mask_high(il,
1933 il->hw_params.beacon_time_tsf_bits) >>
1934 il->hw_params.beacon_time_tsf_bits);
1935 rem = (usec % interval) & il_beacon_time_mask_low(il,
1936 il->hw_params.beacon_time_tsf_bits);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001937
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001938 return (quot << il->hw_params.beacon_time_tsf_bits) + rem;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001939}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001940EXPORT_SYMBOL(il_usecs_to_beacons);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001941
1942/* base is usually what we get from ucode with each received frame,
1943 * the same as HW timer counter counting down
1944 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001945__le32 il_add_beacon_time(struct il_priv *il, u32 base,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001946 u32 addon, u32 beacon_interval)
1947{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001948 u32 base_low = base & il_beacon_time_mask_low(il,
1949 il->hw_params.beacon_time_tsf_bits);
1950 u32 addon_low = addon & il_beacon_time_mask_low(il,
1951 il->hw_params.beacon_time_tsf_bits);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001952 u32 interval = beacon_interval * TIME_UNIT;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001953 u32 res = (base & il_beacon_time_mask_high(il,
1954 il->hw_params.beacon_time_tsf_bits)) +
1955 (addon & il_beacon_time_mask_high(il,
1956 il->hw_params.beacon_time_tsf_bits));
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001957
1958 if (base_low > addon_low)
1959 res += base_low - addon_low;
1960 else if (base_low < addon_low) {
1961 res += interval + base_low - addon_low;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001962 res += (1 << il->hw_params.beacon_time_tsf_bits);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001963 } else
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001964 res += (1 << il->hw_params.beacon_time_tsf_bits);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001965
1966 return cpu_to_le32(res);
1967}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001968EXPORT_SYMBOL(il_add_beacon_time);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001969
1970#ifdef CONFIG_PM
1971
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001972int il_pci_suspend(struct device *device)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001973{
1974 struct pci_dev *pdev = to_pci_dev(device);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001975 struct il_priv *il = pci_get_drvdata(pdev);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001976
1977 /*
1978 * This function is called when system goes into suspend state
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001979 * mac80211 will call il_mac_stop() from the mac80211 suspend function
1980 * first but since il_mac_stop() has no knowledge of who the caller is,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001981 * it will not call apm_ops.stop() to stop the DMA operation.
1982 * Calling apm_ops.stop here to make sure we stop the DMA.
1983 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001984 il_apm_stop(il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001985
1986 return 0;
1987}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001988EXPORT_SYMBOL(il_pci_suspend);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001989
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001990int il_pci_resume(struct device *device)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001991{
1992 struct pci_dev *pdev = to_pci_dev(device);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001993 struct il_priv *il = pci_get_drvdata(pdev);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001994 bool hw_rfkill = false;
1995
1996 /*
1997 * We disable the RETRY_TIMEOUT register (0x41) to keep
1998 * PCI Tx retries from interfering with C3 CPU state.
1999 */
2000 pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
2001
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002002 il_enable_interrupts(il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002003
Stanislaw Gruszka841b2cc2011-08-24 15:14:03 +02002004 if (!(_il_rd(il, CSR_GP_CNTRL) &
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002005 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
2006 hw_rfkill = true;
2007
2008 if (hw_rfkill)
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002009 set_bit(STATUS_RF_KILL_HW, &il->status);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002010 else
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002011 clear_bit(STATUS_RF_KILL_HW, &il->status);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002012
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002013 wiphy_rfkill_set_hw_state(il->hw->wiphy, hw_rfkill);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002014
2015 return 0;
2016}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002017EXPORT_SYMBOL(il_pci_resume);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002018
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002019const struct dev_pm_ops il_pm_ops = {
2020 .suspend = il_pci_suspend,
2021 .resume = il_pci_resume,
2022 .freeze = il_pci_suspend,
2023 .thaw = il_pci_resume,
2024 .poweroff = il_pci_suspend,
2025 .restore = il_pci_resume,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002026};
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002027EXPORT_SYMBOL(il_pm_ops);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002028
2029#endif /* CONFIG_PM */
2030
2031static void
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002032il_update_qos(struct il_priv *il, struct il_rxon_context *ctx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002033{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002034 if (test_bit(STATUS_EXIT_PENDING, &il->status))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002035 return;
2036
2037 if (!ctx->is_active)
2038 return;
2039
2040 ctx->qos_data.def_qos_parm.qos_flags = 0;
2041
2042 if (ctx->qos_data.qos_active)
2043 ctx->qos_data.def_qos_parm.qos_flags |=
2044 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
2045
2046 if (ctx->ht.enabled)
2047 ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
2048
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002049 D_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002050 ctx->qos_data.qos_active,
2051 ctx->qos_data.def_qos_parm.qos_flags);
2052
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002053 il_send_cmd_pdu_async(il, ctx->qos_cmd,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002054 sizeof(struct il_qosparam_cmd),
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002055 &ctx->qos_data.def_qos_parm, NULL);
2056}
2057
2058/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002059 * il_mac_config - mac80211 config callback
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002060 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002061int il_mac_config(struct ieee80211_hw *hw, u32 changed)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002062{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002063 struct il_priv *il = hw->priv;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002064 const struct il_channel_info *ch_info;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002065 struct ieee80211_conf *conf = &hw->conf;
2066 struct ieee80211_channel *channel = conf->channel;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002067 struct il_ht_config *ht_conf = &il->current_ht_config;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002068 struct il_rxon_context *ctx;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002069 unsigned long flags = 0;
2070 int ret = 0;
2071 u16 ch;
2072 int scan_active = 0;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002073 bool ht_changed[NUM_IL_RXON_CTX] = {};
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002074
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002075 if (WARN_ON(!il->cfg->ops->legacy))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002076 return -EOPNOTSUPP;
2077
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002078 mutex_lock(&il->mutex);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002079
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002080 D_MAC80211("enter to channel %d changed 0x%X\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002081 channel->hw_value, changed);
2082
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002083 if (unlikely(test_bit(STATUS_SCANNING, &il->status))) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002084 scan_active = 1;
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002085 D_MAC80211("scan active\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002086 }
2087
2088 if (changed & (IEEE80211_CONF_CHANGE_SMPS |
2089 IEEE80211_CONF_CHANGE_CHANNEL)) {
2090 /* mac80211 uses static for non-HT which is what we want */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002091 il->current_ht_config.smps = conf->smps_mode;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002092
2093 /*
2094 * Recalculate chain counts.
2095 *
2096 * If monitor mode is enabled then mac80211 will
2097 * set up the SM PS mode to OFF if an HT channel is
2098 * configured.
2099 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002100 if (il->cfg->ops->hcmd->set_rxon_chain)
2101 for_each_context(il, ctx)
2102 il->cfg->ops->hcmd->set_rxon_chain(il, ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002103 }
2104
2105 /* during scanning mac80211 will delay channel setting until
2106 * scan finish with changed = 0
2107 */
2108 if (!changed || (changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
2109 if (scan_active)
2110 goto set_ch_out;
2111
2112 ch = channel->hw_value;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002113 ch_info = il_get_channel_info(il, channel->band, ch);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002114 if (!il_is_channel_valid(ch_info)) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002115 D_MAC80211("leave - invalid channel\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002116 ret = -EINVAL;
2117 goto set_ch_out;
2118 }
2119
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002120 if (il->iw_mode == NL80211_IFTYPE_ADHOC &&
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002121 !il_is_channel_ibss(ch_info)) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002122 D_MAC80211("leave - not IBSS channel\n");
Stanislaw Gruszkaeb85de32011-05-07 17:46:21 +02002123 ret = -EINVAL;
2124 goto set_ch_out;
2125 }
2126
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002127 spin_lock_irqsave(&il->lock, flags);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002128
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002129 for_each_context(il, ctx) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002130 /* Configure HT40 channels */
2131 if (ctx->ht.enabled != conf_is_ht(conf)) {
2132 ctx->ht.enabled = conf_is_ht(conf);
2133 ht_changed[ctx->ctxid] = true;
2134 }
2135 if (ctx->ht.enabled) {
2136 if (conf_is_ht40_minus(conf)) {
2137 ctx->ht.extension_chan_offset =
2138 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
2139 ctx->ht.is_40mhz = true;
2140 } else if (conf_is_ht40_plus(conf)) {
2141 ctx->ht.extension_chan_offset =
2142 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
2143 ctx->ht.is_40mhz = true;
2144 } else {
2145 ctx->ht.extension_chan_offset =
2146 IEEE80211_HT_PARAM_CHA_SEC_NONE;
2147 ctx->ht.is_40mhz = false;
2148 }
2149 } else
2150 ctx->ht.is_40mhz = false;
2151
2152 /*
2153 * Default to no protection. Protection mode will
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002154 * later be set from BSS config in il_ht_conf
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002155 */
2156 ctx->ht.protection =
2157 IEEE80211_HT_OP_MODE_PROTECTION_NONE;
2158
2159 /* if we are switching from ht to 2.4 clear flags
2160 * from any ht related info since 2.4 does not
2161 * support ht */
2162 if ((le16_to_cpu(ctx->staging.channel) != ch))
2163 ctx->staging.flags = 0;
2164
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002165 il_set_rxon_channel(il, channel, ctx);
2166 il_set_rxon_ht(il, ht_conf);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002167
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002168 il_set_flags_for_band(il, ctx, channel->band,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002169 ctx->vif);
2170 }
2171
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002172 spin_unlock_irqrestore(&il->lock, flags);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002173
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002174 if (il->cfg->ops->legacy->update_bcast_stations)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002175 ret =
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002176 il->cfg->ops->legacy->update_bcast_stations(il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002177
2178 set_ch_out:
2179 /* The list of supported rates and rate mask can be different
2180 * for each band; since the band may have changed, reset
2181 * the rate mask to what mac80211 lists */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002182 il_set_rate(il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002183 }
2184
2185 if (changed & (IEEE80211_CONF_CHANGE_PS |
2186 IEEE80211_CONF_CHANGE_IDLE)) {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002187 ret = il_power_update_mode(il, false);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002188 if (ret)
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002189 D_MAC80211("Error setting sleep level\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002190 }
2191
2192 if (changed & IEEE80211_CONF_CHANGE_POWER) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002193 D_MAC80211("TX Power old=%d new=%d\n",
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002194 il->tx_power_user_lmt, conf->power_level);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002195
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002196 il_set_tx_power(il, conf->power_level, false);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002197 }
2198
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002199 if (!il_is_ready(il)) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002200 D_MAC80211("leave - not ready\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002201 goto out;
2202 }
2203
2204 if (scan_active)
2205 goto out;
2206
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002207 for_each_context(il, ctx) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002208 if (memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging)))
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002209 il_commit_rxon(il, ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002210 else
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002211 D_INFO(
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002212 "Not re-sending same RXON configuration.\n");
2213 if (ht_changed[ctx->ctxid])
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002214 il_update_qos(il, ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002215 }
2216
2217out:
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002218 D_MAC80211("leave\n");
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002219 mutex_unlock(&il->mutex);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002220 return ret;
2221}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002222EXPORT_SYMBOL(il_mac_config);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002223
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002224void il_mac_reset_tsf(struct ieee80211_hw *hw,
Eliad Peller37a41b42011-09-21 14:06:11 +03002225 struct ieee80211_vif *vif)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002226{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002227 struct il_priv *il = hw->priv;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002228 unsigned long flags;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002229 /* IBSS can only be the IL_RXON_CTX_BSS context */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002230 struct il_rxon_context *ctx = &il->contexts[IL_RXON_CTX_BSS];
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002231
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002232 if (WARN_ON(!il->cfg->ops->legacy))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002233 return;
2234
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002235 mutex_lock(&il->mutex);
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002236 D_MAC80211("enter\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002237
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002238 spin_lock_irqsave(&il->lock, flags);
2239 memset(&il->current_ht_config, 0, sizeof(struct il_ht_config));
2240 spin_unlock_irqrestore(&il->lock, flags);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002241
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002242 spin_lock_irqsave(&il->lock, flags);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002243
2244 /* new association get rid of ibss beacon skb */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002245 if (il->beacon_skb)
2246 dev_kfree_skb(il->beacon_skb);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002247
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002248 il->beacon_skb = NULL;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002249
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002250 il->timestamp = 0;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002251
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002252 spin_unlock_irqrestore(&il->lock, flags);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002253
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002254 il_scan_cancel_timeout(il, 100);
2255 if (!il_is_ready_rf(il)) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002256 D_MAC80211("leave - not ready\n");
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002257 mutex_unlock(&il->mutex);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002258 return;
2259 }
2260
2261 /* we are restarting association process
2262 * clear RXON_FILTER_ASSOC_MSK bit
2263 */
2264 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002265 il_commit_rxon(il, ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002266
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002267 il_set_rate(il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002268
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002269 mutex_unlock(&il->mutex);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002270
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002271 D_MAC80211("leave\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002272}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002273EXPORT_SYMBOL(il_mac_reset_tsf);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002274
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002275static void il_ht_conf(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002276 struct ieee80211_vif *vif)
2277{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002278 struct il_ht_config *ht_conf = &il->current_ht_config;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002279 struct ieee80211_sta *sta;
2280 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002281 struct il_rxon_context *ctx = il_rxon_ctx_from_vif(vif);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002282
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002283 D_ASSOC("enter:\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002284
2285 if (!ctx->ht.enabled)
2286 return;
2287
2288 ctx->ht.protection =
2289 bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION;
2290 ctx->ht.non_gf_sta_present =
2291 !!(bss_conf->ht_operation_mode &
2292 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
2293
2294 ht_conf->single_chain_sufficient = false;
2295
2296 switch (vif->type) {
2297 case NL80211_IFTYPE_STATION:
2298 rcu_read_lock();
2299 sta = ieee80211_find_sta(vif, bss_conf->bssid);
2300 if (sta) {
2301 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2302 int maxstreams;
2303
2304 maxstreams = (ht_cap->mcs.tx_params &
2305 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
2306 >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
2307 maxstreams += 1;
2308
2309 if ((ht_cap->mcs.rx_mask[1] == 0) &&
2310 (ht_cap->mcs.rx_mask[2] == 0))
2311 ht_conf->single_chain_sufficient = true;
2312 if (maxstreams <= 1)
2313 ht_conf->single_chain_sufficient = true;
2314 } else {
2315 /*
2316 * If at all, this can only happen through a race
2317 * when the AP disconnects us while we're still
2318 * setting up the connection, in that case mac80211
2319 * will soon tell us about that.
2320 */
2321 ht_conf->single_chain_sufficient = true;
2322 }
2323 rcu_read_unlock();
2324 break;
2325 case NL80211_IFTYPE_ADHOC:
2326 ht_conf->single_chain_sufficient = true;
2327 break;
2328 default:
2329 break;
2330 }
2331
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002332 D_ASSOC("leave\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002333}
2334
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002335static inline void il_set_no_assoc(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002336 struct ieee80211_vif *vif)
2337{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002338 struct il_rxon_context *ctx = il_rxon_ctx_from_vif(vif);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002339
2340 /*
2341 * inform the ucode that there is no longer an
2342 * association and that no more packets should be
2343 * sent
2344 */
2345 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2346 ctx->staging.assoc_id = 0;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002347 il_commit_rxon(il, ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002348}
2349
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002350static void il_beacon_update(struct ieee80211_hw *hw,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002351 struct ieee80211_vif *vif)
2352{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002353 struct il_priv *il = hw->priv;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002354 unsigned long flags;
2355 __le64 timestamp;
2356 struct sk_buff *skb = ieee80211_beacon_get(hw, vif);
2357
2358 if (!skb)
2359 return;
2360
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002361 D_MAC80211("enter\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002362
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002363 lockdep_assert_held(&il->mutex);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002364
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002365 if (!il->beacon_ctx) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02002366 IL_ERR("update beacon but no beacon context!\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002367 dev_kfree_skb(skb);
2368 return;
2369 }
2370
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002371 spin_lock_irqsave(&il->lock, flags);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002372
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002373 if (il->beacon_skb)
2374 dev_kfree_skb(il->beacon_skb);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002375
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002376 il->beacon_skb = skb;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002377
2378 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002379 il->timestamp = le64_to_cpu(timestamp);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002380
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002381 D_MAC80211("leave\n");
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002382 spin_unlock_irqrestore(&il->lock, flags);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002383
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002384 if (!il_is_ready_rf(il)) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002385 D_MAC80211("leave - RF not ready\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002386 return;
2387 }
2388
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002389 il->cfg->ops->legacy->post_associate(il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002390}
2391
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002392void il_mac_bss_info_changed(struct ieee80211_hw *hw,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002393 struct ieee80211_vif *vif,
2394 struct ieee80211_bss_conf *bss_conf,
2395 u32 changes)
2396{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002397 struct il_priv *il = hw->priv;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002398 struct il_rxon_context *ctx = il_rxon_ctx_from_vif(vif);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002399 int ret;
2400
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002401 if (WARN_ON(!il->cfg->ops->legacy))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002402 return;
2403
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002404 D_MAC80211("changes = 0x%X\n", changes);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002405
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002406 mutex_lock(&il->mutex);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002407
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002408 if (!il_is_alive(il)) {
2409 mutex_unlock(&il->mutex);
Stanislaw Gruszka28a6e572011-04-28 11:51:32 +02002410 return;
2411 }
2412
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002413 if (changes & BSS_CHANGED_QOS) {
2414 unsigned long flags;
2415
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002416 spin_lock_irqsave(&il->lock, flags);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002417 ctx->qos_data.qos_active = bss_conf->qos;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002418 il_update_qos(il, ctx);
2419 spin_unlock_irqrestore(&il->lock, flags);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002420 }
2421
2422 if (changes & BSS_CHANGED_BEACON_ENABLED) {
2423 /*
2424 * the add_interface code must make sure we only ever
2425 * have a single interface that could be beaconing at
2426 * any time.
2427 */
2428 if (vif->bss_conf.enable_beacon)
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002429 il->beacon_ctx = ctx;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002430 else
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002431 il->beacon_ctx = NULL;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002432 }
2433
2434 if (changes & BSS_CHANGED_BSSID) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002435 D_MAC80211("BSSID %pM\n", bss_conf->bssid);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002436
2437 /*
2438 * If there is currently a HW scan going on in the
2439 * background then we need to cancel it else the RXON
2440 * below/in post_associate will fail.
2441 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002442 if (il_scan_cancel_timeout(il, 100)) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02002443 IL_WARN(
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002444 "Aborted scan still in progress after 100ms\n");
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002445 D_MAC80211(
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002446 "leaving - scan abort failed.\n");
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002447 mutex_unlock(&il->mutex);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002448 return;
2449 }
2450
2451 /* mac80211 only sets assoc when in STATION mode */
2452 if (vif->type == NL80211_IFTYPE_ADHOC || bss_conf->assoc) {
2453 memcpy(ctx->staging.bssid_addr,
2454 bss_conf->bssid, ETH_ALEN);
2455
2456 /* currently needed in a few places */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002457 memcpy(il->bssid, bss_conf->bssid, ETH_ALEN);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002458 } else {
2459 ctx->staging.filter_flags &=
2460 ~RXON_FILTER_ASSOC_MSK;
2461 }
2462
2463 }
2464
2465 /*
2466 * This needs to be after setting the BSSID in case
2467 * mac80211 decides to do both changes at once because
2468 * it will invoke post_associate.
2469 */
2470 if (vif->type == NL80211_IFTYPE_ADHOC && changes & BSS_CHANGED_BEACON)
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002471 il_beacon_update(hw, vif);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002472
2473 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002474 D_MAC80211("ERP_PREAMBLE %d\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002475 bss_conf->use_short_preamble);
2476 if (bss_conf->use_short_preamble)
2477 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2478 else
2479 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2480 }
2481
2482 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002483 D_MAC80211(
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002484 "ERP_CTS %d\n", bss_conf->use_cts_prot);
2485 if (bss_conf->use_cts_prot &&
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002486 (il->band != IEEE80211_BAND_5GHZ))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002487 ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
2488 else
2489 ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
2490 if (bss_conf->use_cts_prot)
2491 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
2492 else
2493 ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
2494 }
2495
2496 if (changes & BSS_CHANGED_BASIC_RATES) {
2497 /* XXX use this information
2498 *
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002499 * To do that, remove code from il_set_rate() and put something
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002500 * like this here:
2501 *
2502 if (A-band)
2503 ctx->staging.ofdm_basic_rates =
2504 bss_conf->basic_rates;
2505 else
2506 ctx->staging.ofdm_basic_rates =
2507 bss_conf->basic_rates >> 4;
2508 ctx->staging.cck_basic_rates =
2509 bss_conf->basic_rates & 0xF;
2510 */
2511 }
2512
2513 if (changes & BSS_CHANGED_HT) {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002514 il_ht_conf(il, vif);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002515
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002516 if (il->cfg->ops->hcmd->set_rxon_chain)
2517 il->cfg->ops->hcmd->set_rxon_chain(il, ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002518 }
2519
2520 if (changes & BSS_CHANGED_ASSOC) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002521 D_MAC80211("ASSOC %d\n", bss_conf->assoc);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002522 if (bss_conf->assoc) {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002523 il->timestamp = bss_conf->timestamp;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002524
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002525 if (!il_is_rfkill(il))
2526 il->cfg->ops->legacy->post_associate(il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002527 } else
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002528 il_set_no_assoc(il, vif);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002529 }
2530
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002531 if (changes && il_is_associated_ctx(ctx) && bss_conf->aid) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002532 D_MAC80211("Changes (%#x) while associated\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002533 changes);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002534 ret = il_send_rxon_assoc(il, ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002535 if (!ret) {
2536 /* Sync active_rxon with latest change. */
2537 memcpy((void *)&ctx->active,
2538 &ctx->staging,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002539 sizeof(struct il_rxon_cmd));
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002540 }
2541 }
2542
2543 if (changes & BSS_CHANGED_BEACON_ENABLED) {
2544 if (vif->bss_conf.enable_beacon) {
2545 memcpy(ctx->staging.bssid_addr,
2546 bss_conf->bssid, ETH_ALEN);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002547 memcpy(il->bssid, bss_conf->bssid, ETH_ALEN);
2548 il->cfg->ops->legacy->config_ap(il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002549 } else
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002550 il_set_no_assoc(il, vif);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002551 }
2552
2553 if (changes & BSS_CHANGED_IBSS) {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002554 ret = il->cfg->ops->legacy->manage_ibss_station(il, vif,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002555 bss_conf->ibss_joined);
2556 if (ret)
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02002557 IL_ERR("failed to %s IBSS station %pM\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002558 bss_conf->ibss_joined ? "add" : "remove",
2559 bss_conf->bssid);
2560 }
2561
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002562 mutex_unlock(&il->mutex);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002563
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002564 D_MAC80211("leave\n");
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002565}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002566EXPORT_SYMBOL(il_mac_bss_info_changed);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002567
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002568irqreturn_t il_isr(int irq, void *data)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002569{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002570 struct il_priv *il = data;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002571 u32 inta, inta_mask;
2572 u32 inta_fh;
2573 unsigned long flags;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002574 if (!il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002575 return IRQ_NONE;
2576
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002577 spin_lock_irqsave(&il->lock, flags);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002578
2579 /* Disable (but don't clear!) interrupts here to avoid
2580 * back-to-back ISRs and sporadic interrupts from our NIC.
2581 * If we have something to service, the tasklet will re-enable ints.
2582 * If we *don't* have something, we'll re-enable before leaving here. */
Stanislaw Gruszka841b2cc2011-08-24 15:14:03 +02002583 inta_mask = _il_rd(il, CSR_INT_MASK); /* just for debug */
2584 _il_wr(il, CSR_INT_MASK, 0x00000000);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002585
2586 /* Discover which interrupts are active/pending */
Stanislaw Gruszka841b2cc2011-08-24 15:14:03 +02002587 inta = _il_rd(il, CSR_INT);
2588 inta_fh = _il_rd(il, CSR_FH_INT_STATUS);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002589
2590 /* Ignore interrupt if there's nothing in NIC to service.
2591 * This may be due to IRQ shared with another device,
2592 * or due to sporadic interrupts thrown from our NIC. */
2593 if (!inta && !inta_fh) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002594 D_ISR(
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002595 "Ignore interrupt, inta == 0, inta_fh == 0\n");
2596 goto none;
2597 }
2598
2599 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
2600 /* Hardware disappeared. It might have already raised
2601 * an interrupt */
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02002602 IL_WARN("HARDWARE GONE?? INTA == 0x%08x\n", inta);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002603 goto unplugged;
2604 }
2605
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002606 D_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002607 inta, inta_mask, inta_fh);
2608
2609 inta &= ~CSR_INT_BIT_SCD;
2610
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002611 /* il_irq_tasklet() will service interrupts and re-enable them */
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002612 if (likely(inta || inta_fh))
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002613 tasklet_schedule(&il->irq_tasklet);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002614
2615unplugged:
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002616 spin_unlock_irqrestore(&il->lock, flags);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002617 return IRQ_HANDLED;
2618
2619none:
2620 /* re-enable interrupts here since we don't have anything to service. */
Stanislaw Gruszka93fd74e2011-04-28 11:51:30 +02002621 /* only Re-enable if disabled by irq */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002622 if (test_bit(STATUS_INT_ENABLED, &il->status))
2623 il_enable_interrupts(il);
2624 spin_unlock_irqrestore(&il->lock, flags);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002625 return IRQ_NONE;
2626}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002627EXPORT_SYMBOL(il_isr);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002628
2629/*
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002630 * il_tx_cmd_protection: Set rts/cts. 3945 and 4965 only share this
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002631 * function.
2632 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002633void il_tx_cmd_protection(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002634 struct ieee80211_tx_info *info,
2635 __le16 fc, __le32 *tx_flags)
2636{
2637 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) {
2638 *tx_flags |= TX_CMD_FLG_RTS_MSK;
2639 *tx_flags &= ~TX_CMD_FLG_CTS_MSK;
2640 *tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
2641
2642 if (!ieee80211_is_mgmt(fc))
2643 return;
2644
2645 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
2646 case cpu_to_le16(IEEE80211_STYPE_AUTH):
2647 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
2648 case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
2649 case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
2650 *tx_flags &= ~TX_CMD_FLG_RTS_MSK;
2651 *tx_flags |= TX_CMD_FLG_CTS_MSK;
2652 break;
2653 }
2654 } else if (info->control.rates[0].flags &
2655 IEEE80211_TX_RC_USE_CTS_PROTECT) {
2656 *tx_flags &= ~TX_CMD_FLG_RTS_MSK;
2657 *tx_flags |= TX_CMD_FLG_CTS_MSK;
2658 *tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
2659 }
2660}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002661EXPORT_SYMBOL(il_tx_cmd_protection);