blob: d09325591de00d465c1faaea681e82a8fcfc5275 [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Reinette Chatre01f81622009-01-08 10:20:02 -08003 * Copyright(c) 2003 - 2009 Intel Corporation. All rights reserved.
Zhu Yib481de92007-09-25 17:54:57 -07004 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
Winkler, Tomas759ef892008-12-09 11:28:58 -080025 * Intel Linux Wireless <ilw@linux.intel.com>
Zhu Yib481de92007-09-25 17:54:57 -070026 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29
Zhu Yib481de92007-09-25 17:54:57 -070030#include <linux/kernel.h>
31#include <linux/module.h>
Zhu Yib481de92007-09-25 17:54:57 -070032#include <linux/init.h>
33#include <linux/pci.h>
34#include <linux/dma-mapping.h>
35#include <linux/delay.h>
36#include <linux/skbuff.h>
37#include <linux/netdevice.h>
38#include <linux/wireless.h>
39#include <linux/firmware.h>
Zhu Yib481de92007-09-25 17:54:57 -070040#include <linux/etherdevice.h>
41#include <linux/if_arp.h>
42
43#include <net/ieee80211_radiotap.h>
John W. Linville7e272fc2008-09-24 18:13:14 -040044#include <net/lib80211.h>
Zhu Yib481de92007-09-25 17:54:57 -070045#include <net/mac80211.h>
46
47#include <asm/div64.h>
48
Samuel Ortiza3139c52008-12-19 10:37:09 +080049#define DRV_NAME "iwl3945"
50
Winkler, Tomasdbb66542008-12-22 11:31:14 +080051#include "iwl-fh.h"
52#include "iwl-3945-fh.h"
Tomas Winkler600c0e12008-12-19 10:37:04 +080053#include "iwl-commands.h"
Samuel Ortiz17f841c2009-01-23 13:45:20 -080054#include "iwl-sta.h"
Zhu Yib481de92007-09-25 17:54:57 -070055#include "iwl-3945.h"
56#include "iwl-helpers.h"
Kolekar, Abhijeet5747d472008-12-19 10:37:18 +080057#include "iwl-core.h"
Samuel Ortizd20b3c62008-12-19 10:37:15 +080058#include "iwl-dev.h"
Zhu Yib481de92007-09-25 17:54:57 -070059
Zhu Yib481de92007-09-25 17:54:57 -070060/*
61 * module name, copyright, version, etc.
Zhu Yib481de92007-09-25 17:54:57 -070062 */
63
64#define DRV_DESCRIPTION \
65"Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
66
Samuel Ortizd08853a2009-01-23 13:45:17 -080067#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070068#define VD "d"
69#else
70#define VD
71#endif
72
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +080073#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -070074#define VS "s"
75#else
76#define VS
77#endif
78
Kolekar, Abhijeeteaa686c2008-12-19 10:37:17 +080079#define IWL39_VERSION "1.2.26k" VD VS
Reinette Chatre01f81622009-01-08 10:20:02 -080080#define DRV_COPYRIGHT "Copyright(c) 2003-2009 Intel Corporation"
Tomas Winklera7b75202008-12-11 10:33:41 -080081#define DRV_AUTHOR "<ilw@linux.intel.com>"
Kolekar, Abhijeeteaa686c2008-12-19 10:37:17 +080082#define DRV_VERSION IWL39_VERSION
Zhu Yib481de92007-09-25 17:54:57 -070083
Zhu Yib481de92007-09-25 17:54:57 -070084
85MODULE_DESCRIPTION(DRV_DESCRIPTION);
86MODULE_VERSION(DRV_VERSION);
Tomas Winklera7b75202008-12-11 10:33:41 -080087MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
Zhu Yib481de92007-09-25 17:54:57 -070088MODULE_LICENSE("GPL");
89
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080090 /* module parameters */
91struct iwl_mod_params iwl3945_mod_params = {
92 .num_of_queues = IWL39_MAX_NUM_QUEUES,
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -080093 .sw_crypto = 1,
Samuel Ortizaf48d042009-01-23 13:45:19 -080094 .restart_fw = 1,
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080095 /* the rest are 0 by default */
96};
97
Zhu Yib481de92007-09-25 17:54:57 -070098/*************** STATION TABLE MANAGEMENT ****
Ben Cahill9fbab512007-11-29 11:09:47 +080099 * mac80211 should be examined to determine if sta_info is duplicating
Zhu Yib481de92007-09-25 17:54:57 -0700100 * the functionality provided here
101 */
102
103/**************************************************************/
Ian Schram01ebd062007-10-25 17:15:22 +0800104#if 0 /* temporary disable till we add real remove station */
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800105/**
106 * iwl3945_remove_station - Remove driver's knowledge of station.
107 *
108 * NOTE: This does not remove station from device's station table.
109 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800110static u8 iwl3945_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
Zhu Yib481de92007-09-25 17:54:57 -0700111{
112 int index = IWL_INVALID_STATION;
113 int i;
114 unsigned long flags;
115
116 spin_lock_irqsave(&priv->sta_lock, flags);
117
118 if (is_ap)
119 index = IWL_AP_ID;
120 else if (is_broadcast_ether_addr(addr))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800121 index = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700122 else
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800123 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800124 if (priv->stations_39[i].used &&
125 !compare_ether_addr(priv->stations_39[i].sta.sta.addr,
Zhu Yib481de92007-09-25 17:54:57 -0700126 addr)) {
127 index = i;
128 break;
129 }
130
131 if (unlikely(index == IWL_INVALID_STATION))
132 goto out;
133
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800134 if (priv->stations_39[index].used) {
135 priv->stations_39[index].used = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700136 priv->num_stations--;
137 }
138
139 BUG_ON(priv->num_stations < 0);
140
141out:
142 spin_unlock_irqrestore(&priv->sta_lock, flags);
143 return 0;
144}
Zhu Yi556f8db2007-09-27 11:27:33 +0800145#endif
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800146
147/**
148 * iwl3945_clear_stations_table - Clear the driver's station table
149 *
150 * NOTE: This does not clear or otherwise alter the device's station table.
151 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800152static void iwl3945_clear_stations_table(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700153{
154 unsigned long flags;
155
156 spin_lock_irqsave(&priv->sta_lock, flags);
157
158 priv->num_stations = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800159 memset(priv->stations_39, 0, sizeof(priv->stations_39));
Zhu Yib481de92007-09-25 17:54:57 -0700160
161 spin_unlock_irqrestore(&priv->sta_lock, flags);
162}
163
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800164/**
165 * iwl3945_add_station - Add station to station tables in driver and device
166 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800167u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags)
Zhu Yib481de92007-09-25 17:54:57 -0700168{
169 int i;
170 int index = IWL_INVALID_STATION;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800171 struct iwl3945_station_entry *station;
Zhu Yib481de92007-09-25 17:54:57 -0700172 unsigned long flags_spin;
Zhu Yic14c5212007-09-27 11:27:35 +0800173 u8 rate;
Zhu Yib481de92007-09-25 17:54:57 -0700174
175 spin_lock_irqsave(&priv->sta_lock, flags_spin);
176 if (is_ap)
177 index = IWL_AP_ID;
178 else if (is_broadcast_ether_addr(addr))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800179 index = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700180 else
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800181 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800182 if (!compare_ether_addr(priv->stations_39[i].sta.sta.addr,
Zhu Yib481de92007-09-25 17:54:57 -0700183 addr)) {
184 index = i;
185 break;
186 }
187
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800188 if (!priv->stations_39[i].used &&
Zhu Yib481de92007-09-25 17:54:57 -0700189 index == IWL_INVALID_STATION)
190 index = i;
191 }
192
Ian Schram01ebd062007-10-25 17:15:22 +0800193 /* These two conditions has the same outcome but keep them separate
Zhu Yib481de92007-09-25 17:54:57 -0700194 since they have different meaning */
195 if (unlikely(index == IWL_INVALID_STATION)) {
196 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
197 return index;
198 }
199
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800200 if (priv->stations_39[index].used &&
201 !compare_ether_addr(priv->stations_39[index].sta.sta.addr, addr)) {
Zhu Yib481de92007-09-25 17:54:57 -0700202 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
203 return index;
204 }
205
Johannes Berge1749612008-10-27 15:59:26 -0700206 IWL_DEBUG_ASSOC("Add STA ID %d: %pM\n", index, addr);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800207 station = &priv->stations_39[index];
Zhu Yib481de92007-09-25 17:54:57 -0700208 station->used = 1;
209 priv->num_stations++;
210
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800211 /* Set up the REPLY_ADD_STA command to send to device */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800212 memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd));
Zhu Yib481de92007-09-25 17:54:57 -0700213 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
214 station->sta.mode = 0;
215 station->sta.sta.sta_id = index;
216 station->sta.station_flags = 0;
217
Johannes Berg8318d782008-01-24 19:38:38 +0100218 if (priv->band == IEEE80211_BAND_5GHZ)
Tomas Winkler69946332007-10-25 17:15:27 +0800219 rate = IWL_RATE_6M_PLCP;
220 else
221 rate = IWL_RATE_1M_PLCP;
Zhu Yic14c5212007-09-27 11:27:35 +0800222
223 /* Turn on both antennas for the station... */
224 station->sta.rate_n_flags =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800225 iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK);
Zhu Yic14c5212007-09-27 11:27:35 +0800226
Zhu Yib481de92007-09-25 17:54:57 -0700227 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800228
229 /* Add station to device's station table */
Samuel Ortiz17f841c2009-01-23 13:45:20 -0800230 iwl_send_add_sta(priv,
231 (struct iwl_addsta_cmd *)&station->sta, flags);
Zhu Yib481de92007-09-25 17:54:57 -0700232 return index;
233
234}
235
Zhu Yib481de92007-09-25 17:54:57 -0700236/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800237 * iwl3945_set_rxon_channel - Set the phymode and channel values in staging RXON
Johannes Berg8318d782008-01-24 19:38:38 +0100238 * @band: 2.4 or 5 GHz band
239 * @channel: Any channel valid for the requested band
Zhu Yib481de92007-09-25 17:54:57 -0700240
Johannes Berg8318d782008-01-24 19:38:38 +0100241 * In addition to setting the staging RXON, priv->band is also set.
Zhu Yib481de92007-09-25 17:54:57 -0700242 *
243 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
Johannes Berg8318d782008-01-24 19:38:38 +0100244 * in the staging RXON flag structure based on the band
Zhu Yib481de92007-09-25 17:54:57 -0700245 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800246static int iwl3945_set_rxon_channel(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +0100247 enum ieee80211_band band,
248 u16 channel)
Zhu Yib481de92007-09-25 17:54:57 -0700249{
Samuel Ortize6148912009-01-23 13:45:15 -0800250 if (!iwl_get_channel_info(priv, band, channel)) {
Zhu Yib481de92007-09-25 17:54:57 -0700251 IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
Johannes Berg8318d782008-01-24 19:38:38 +0100252 channel, band);
Zhu Yib481de92007-09-25 17:54:57 -0700253 return -EINVAL;
254 }
255
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800256 if ((le16_to_cpu(priv->staging39_rxon.channel) == channel) &&
Johannes Berg8318d782008-01-24 19:38:38 +0100257 (priv->band == band))
Zhu Yib481de92007-09-25 17:54:57 -0700258 return 0;
259
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800260 priv->staging39_rxon.channel = cpu_to_le16(channel);
Johannes Berg8318d782008-01-24 19:38:38 +0100261 if (band == IEEE80211_BAND_5GHZ)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800262 priv->staging39_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700263 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800264 priv->staging39_rxon.flags |= RXON_FLG_BAND_24G_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700265
Johannes Berg8318d782008-01-24 19:38:38 +0100266 priv->band = band;
Zhu Yib481de92007-09-25 17:54:57 -0700267
Johannes Berg8318d782008-01-24 19:38:38 +0100268 IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, band);
Zhu Yib481de92007-09-25 17:54:57 -0700269
270 return 0;
271}
272
273/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800274 * iwl3945_check_rxon_cmd - validate RXON structure is valid
Zhu Yib481de92007-09-25 17:54:57 -0700275 *
276 * NOTE: This is really only useful during development and can eventually
277 * be #ifdef'd out once the driver is stable and folks aren't actively
278 * making changes
279 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800280static int iwl3945_check_rxon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700281{
282 int error = 0;
283 int counter = 1;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800284 struct iwl3945_rxon_cmd *rxon = &priv->staging39_rxon;
Zhu Yib481de92007-09-25 17:54:57 -0700285
286 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
287 error |= le32_to_cpu(rxon->flags &
288 (RXON_FLG_TGJ_NARROW_BAND_MSK |
289 RXON_FLG_RADAR_DETECT_MSK));
290 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800291 IWL_WARN(priv, "check 24G fields %d | %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700292 counter++, error);
293 } else {
294 error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
295 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
296 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800297 IWL_WARN(priv, "check 52 fields %d | %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700298 counter++, error);
299 error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
300 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800301 IWL_WARN(priv, "check 52 CCK %d | %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700302 counter++, error);
303 }
304 error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
305 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800306 IWL_WARN(priv, "check mac addr %d | %d\n", counter++, error);
Zhu Yib481de92007-09-25 17:54:57 -0700307
308 /* make sure basic rates 6Mbps and 1Mbps are supported */
309 error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
310 ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
311 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800312 IWL_WARN(priv, "check basic rate %d | %d\n", counter++, error);
Zhu Yib481de92007-09-25 17:54:57 -0700313
314 error |= (le16_to_cpu(rxon->assoc_id) > 2007);
315 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800316 IWL_WARN(priv, "check assoc id %d | %d\n", counter++, error);
Zhu Yib481de92007-09-25 17:54:57 -0700317
318 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
319 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
320 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800321 IWL_WARN(priv, "check CCK and short slot %d | %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700322 counter++, error);
323
324 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
325 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
326 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800327 IWL_WARN(priv, "check CCK & auto detect %d | %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700328 counter++, error);
329
330 error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
331 RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
332 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800333 IWL_WARN(priv, "check TGG and auto detect %d | %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700334 counter++, error);
335
336 if ((rxon->flags & RXON_FLG_DIS_DIV_MSK))
337 error |= ((rxon->flags & (RXON_FLG_ANT_B_MSK |
338 RXON_FLG_ANT_A_MSK)) == 0);
339 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800340 IWL_WARN(priv, "check antenna %d %d\n", counter++, error);
Zhu Yib481de92007-09-25 17:54:57 -0700341
342 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800343 IWL_WARN(priv, "Tuning to channel %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700344 le16_to_cpu(rxon->channel));
345
346 if (error) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800347 IWL_ERR(priv, "Not a valid rxon_assoc_cmd field values\n");
Zhu Yib481de92007-09-25 17:54:57 -0700348 return -1;
349 }
350 return 0;
351}
352
353/**
Ben Cahill9fbab512007-11-29 11:09:47 +0800354 * iwl3945_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
Ian Schram01ebd062007-10-25 17:15:22 +0800355 * @priv: staging_rxon is compared to active_rxon
Zhu Yib481de92007-09-25 17:54:57 -0700356 *
Ben Cahill9fbab512007-11-29 11:09:47 +0800357 * If the RXON structure is changing enough to require a new tune,
358 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
359 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
Zhu Yib481de92007-09-25 17:54:57 -0700360 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800361static int iwl3945_full_rxon_required(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700362{
363
364 /* These items are only settable from the full RXON command */
Ron Rindjunsky5d1e2322008-06-30 17:23:04 +0800365 if (!(iwl3945_is_associated(priv)) ||
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800366 compare_ether_addr(priv->staging39_rxon.bssid_addr,
367 priv->active39_rxon.bssid_addr) ||
368 compare_ether_addr(priv->staging39_rxon.node_addr,
369 priv->active39_rxon.node_addr) ||
370 compare_ether_addr(priv->staging39_rxon.wlap_bssid_addr,
371 priv->active39_rxon.wlap_bssid_addr) ||
372 (priv->staging39_rxon.dev_type != priv->active39_rxon.dev_type) ||
373 (priv->staging39_rxon.channel != priv->active39_rxon.channel) ||
374 (priv->staging39_rxon.air_propagation !=
375 priv->active39_rxon.air_propagation) ||
376 (priv->staging39_rxon.assoc_id != priv->active39_rxon.assoc_id))
Zhu Yib481de92007-09-25 17:54:57 -0700377 return 1;
378
379 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
380 * be updated with the RXON_ASSOC command -- however only some
381 * flag transitions are allowed using RXON_ASSOC */
382
383 /* Check if we are not switching bands */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800384 if ((priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
385 (priv->active39_rxon.flags & RXON_FLG_BAND_24G_MSK))
Zhu Yib481de92007-09-25 17:54:57 -0700386 return 1;
387
388 /* Check if we are switching association toggle */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800389 if ((priv->staging39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
390 (priv->active39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
Zhu Yib481de92007-09-25 17:54:57 -0700391 return 1;
392
393 return 0;
394}
395
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800396static int iwl3945_send_rxon_assoc(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700397{
398 int rc = 0;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800399 struct iwl_rx_packet *res = NULL;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800400 struct iwl3945_rxon_assoc_cmd rxon_assoc;
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800401 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700402 .id = REPLY_RXON_ASSOC,
403 .len = sizeof(rxon_assoc),
404 .meta.flags = CMD_WANT_SKB,
405 .data = &rxon_assoc,
406 };
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800407 const struct iwl3945_rxon_cmd *rxon1 = &priv->staging39_rxon;
408 const struct iwl3945_rxon_cmd *rxon2 = &priv->active39_rxon;
Zhu Yib481de92007-09-25 17:54:57 -0700409
410 if ((rxon1->flags == rxon2->flags) &&
411 (rxon1->filter_flags == rxon2->filter_flags) &&
412 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
413 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
414 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
415 return 0;
416 }
417
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800418 rxon_assoc.flags = priv->staging39_rxon.flags;
419 rxon_assoc.filter_flags = priv->staging39_rxon.filter_flags;
420 rxon_assoc.ofdm_basic_rates = priv->staging39_rxon.ofdm_basic_rates;
421 rxon_assoc.cck_basic_rates = priv->staging39_rxon.cck_basic_rates;
Zhu Yib481de92007-09-25 17:54:57 -0700422 rxon_assoc.reserved = 0;
423
Samuel Ortiz518099a2009-01-19 15:30:27 -0800424 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700425 if (rc)
426 return rc;
427
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800428 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700429 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800430 IWL_ERR(priv, "Bad return from REPLY_RXON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -0700431 rc = -EIO;
432 }
433
434 priv->alloc_rxb_skb--;
435 dev_kfree_skb_any(cmd.meta.u.skb);
436
437 return rc;
438}
439
440/**
Samuel Ortiz7e4bca52009-01-23 13:45:18 -0800441 * iwl3945_get_antenna_flags - Get antenna flags for RXON command
442 * @priv: eeprom and antenna fields are used to determine antenna flags
443 *
444 * priv->eeprom39 is used to determine if antenna AUX/MAIN are reversed
445 * iwl3945_mod_params.antenna specifies the antenna diversity mode:
446 *
447 * IWL_ANTENNA_DIVERSITY - NIC selects best antenna by itself
448 * IWL_ANTENNA_MAIN - Force MAIN antenna
449 * IWL_ANTENNA_AUX - Force AUX antenna
450 */
451__le32 iwl3945_get_antenna_flags(const struct iwl_priv *priv)
452{
453 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
454
455 switch (iwl3945_mod_params.antenna) {
456 case IWL_ANTENNA_DIVERSITY:
457 return 0;
458
459 case IWL_ANTENNA_MAIN:
460 if (eeprom->antenna_switch_type)
461 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
462 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
463
464 case IWL_ANTENNA_AUX:
465 if (eeprom->antenna_switch_type)
466 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
467 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
468 }
469
470 /* bad antenna selector value */
471 IWL_ERR(priv, "Bad antenna selector value (0x%x)\n",
472 iwl3945_mod_params.antenna);
473
474 return 0; /* "diversity" is default if error */
475}
476
477/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800478 * iwl3945_commit_rxon - commit staging_rxon to hardware
Zhu Yib481de92007-09-25 17:54:57 -0700479 *
Ian Schram01ebd062007-10-25 17:15:22 +0800480 * The RXON command in staging_rxon is committed to the hardware and
Zhu Yib481de92007-09-25 17:54:57 -0700481 * the active_rxon structure is updated with the new data. This
482 * function correctly transitions out of the RXON_ASSOC_MSK state if
483 * a HW tune is required based on the RXON structure changes.
484 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800485static int iwl3945_commit_rxon(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700486{
487 /* cast away the const for active_rxon in this function */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800488 struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active39_rxon;
Zhu Yib481de92007-09-25 17:54:57 -0700489 int rc = 0;
490
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800491 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700492 return -1;
493
494 /* always get timestamp with Rx frame */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800495 priv->staging39_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700496
497 /* select antenna */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800498 priv->staging39_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -0700499 ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800500 priv->staging39_rxon.flags |= iwl3945_get_antenna_flags(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700501
Samuel Ortiza3139c52008-12-19 10:37:09 +0800502 rc = iwl3945_check_rxon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700503 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800504 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700505 return -EINVAL;
506 }
507
508 /* If we don't need to send a full RXON, we can use
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800509 * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
Zhu Yib481de92007-09-25 17:54:57 -0700510 * and other flags for the current radio configuration. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800511 if (!iwl3945_full_rxon_required(priv)) {
512 rc = iwl3945_send_rxon_assoc(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700513 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800514 IWL_ERR(priv, "Error setting RXON_ASSOC "
Zhu Yib481de92007-09-25 17:54:57 -0700515 "configuration (%d).\n", rc);
516 return rc;
517 }
518
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800519 memcpy(active_rxon, &priv->staging39_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700520
521 return 0;
522 }
523
524 /* If we are currently associated and the new config requires
525 * an RXON_ASSOC and the new config wants the associated mask enabled,
526 * we must clear the associated from the active configuration
527 * before we apply the new config */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800528 if (iwl3945_is_associated(priv) &&
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800529 (priv->staging39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) {
Zhu Yib481de92007-09-25 17:54:57 -0700530 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
531 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
532
Samuel Ortiz518099a2009-01-19 15:30:27 -0800533 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800534 sizeof(struct iwl3945_rxon_cmd),
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800535 &priv->active39_rxon);
Zhu Yib481de92007-09-25 17:54:57 -0700536
537 /* If the mask clearing failed then we set
538 * active_rxon back to what it was previously */
539 if (rc) {
540 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
Winkler, Tomas15b16872008-12-19 10:37:33 +0800541 IWL_ERR(priv, "Error clearing ASSOC_MSK on current "
Zhu Yib481de92007-09-25 17:54:57 -0700542 "configuration (%d).\n", rc);
543 return rc;
544 }
Zhu Yib481de92007-09-25 17:54:57 -0700545 }
546
547 IWL_DEBUG_INFO("Sending RXON\n"
548 "* with%s RXON_FILTER_ASSOC_MSK\n"
549 "* channel = %d\n"
Johannes Berge1749612008-10-27 15:59:26 -0700550 "* bssid = %pM\n",
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800551 ((priv->staging39_rxon.filter_flags &
Zhu Yib481de92007-09-25 17:54:57 -0700552 RXON_FILTER_ASSOC_MSK) ? "" : "out"),
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800553 le16_to_cpu(priv->staging39_rxon.channel),
Johannes Berge1749612008-10-27 15:59:26 -0700554 priv->staging_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -0700555
556 /* Apply the new configuration */
Samuel Ortiz518099a2009-01-19 15:30:27 -0800557 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800558 sizeof(struct iwl3945_rxon_cmd), &priv->staging39_rxon);
Zhu Yib481de92007-09-25 17:54:57 -0700559 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800560 IWL_ERR(priv, "Error setting new configuration (%d).\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700561 return rc;
562 }
563
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800564 memcpy(active_rxon, &priv->staging39_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700565
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800566 iwl3945_clear_stations_table(priv);
Zhu Yi556f8db2007-09-27 11:27:33 +0800567
Zhu Yib481de92007-09-25 17:54:57 -0700568 /* If we issue a new RXON command which required a tune then we must
569 * send a new TXPOWER command or we won't be able to Tx any frames */
Samuel Ortiz75bcfae2009-01-23 13:45:11 -0800570 rc = priv->cfg->ops->lib->send_tx_power(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700571 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800572 IWL_ERR(priv, "Error setting Tx power (%d).\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700573 return rc;
574 }
575
576 /* Add the broadcast address so we can send broadcast frames */
Kolekar, Abhijeetb5323d32008-12-19 10:37:22 +0800577 if (iwl3945_add_station(priv, iwl_bcast_addr, 0, 0) ==
Zhu Yib481de92007-09-25 17:54:57 -0700578 IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800579 IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700580 return -EIO;
581 }
582
583 /* If we have set the ASSOC_MSK and we are in BSS mode then
584 * add the IWL_AP_ID to the station rate table */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800585 if (iwl3945_is_associated(priv) &&
Johannes Berg05c914f2008-09-11 00:01:58 +0200586 (priv->iw_mode == NL80211_IFTYPE_STATION))
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800587 if (iwl3945_add_station(priv, priv->active39_rxon.bssid_addr, 1, 0)
Zhu Yib481de92007-09-25 17:54:57 -0700588 == IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800589 IWL_ERR(priv, "Error adding AP address for transmit\n");
Zhu Yib481de92007-09-25 17:54:57 -0700590 return -EIO;
591 }
592
Johannes Berg8318d782008-01-24 19:38:38 +0100593 /* Init the hardware's rate fallback order based on the band */
Zhu Yib481de92007-09-25 17:54:57 -0700594 rc = iwl3945_init_hw_rate_table(priv);
595 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800596 IWL_ERR(priv, "Error setting HW rate table: %02X\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700597 return -EIO;
598 }
599
600 return 0;
601}
602
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800603static int iwl3945_update_sta_key_info(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700604 struct ieee80211_key_conf *keyconf,
605 u8 sta_id)
606{
607 unsigned long flags;
608 __le16 key_flags = 0;
609
610 switch (keyconf->alg) {
611 case ALG_CCMP:
612 key_flags |= STA_KEY_FLG_CCMP;
613 key_flags |= cpu_to_le16(
614 keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
615 key_flags &= ~STA_KEY_FLG_INVALID;
616 break;
617 case ALG_TKIP:
618 case ALG_WEP:
Zhu Yib481de92007-09-25 17:54:57 -0700619 default:
620 return -EINVAL;
621 }
622 spin_lock_irqsave(&priv->sta_lock, flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800623 priv->stations_39[sta_id].keyinfo.alg = keyconf->alg;
624 priv->stations_39[sta_id].keyinfo.keylen = keyconf->keylen;
625 memcpy(priv->stations_39[sta_id].keyinfo.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700626 keyconf->keylen);
627
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800628 memcpy(priv->stations_39[sta_id].sta.key.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700629 keyconf->keylen);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800630 priv->stations_39[sta_id].sta.key.key_flags = key_flags;
631 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
632 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700633
634 spin_unlock_irqrestore(&priv->sta_lock, flags);
635
636 IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
Samuel Ortiz17f841c2009-01-23 13:45:20 -0800637 iwl_send_add_sta(priv,
638 (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700639 return 0;
640}
641
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800642static int iwl3945_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
Zhu Yib481de92007-09-25 17:54:57 -0700643{
644 unsigned long flags;
645
646 spin_lock_irqsave(&priv->sta_lock, flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800647 memset(&priv->stations_39[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key));
648 memset(&priv->stations_39[sta_id].sta.key, 0,
Tomas Winkler4c897252008-12-19 10:37:05 +0800649 sizeof(struct iwl4965_keyinfo));
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800650 priv->stations_39[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
651 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
652 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700653 spin_unlock_irqrestore(&priv->sta_lock, flags);
654
655 IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
Samuel Ortiz17f841c2009-01-23 13:45:20 -0800656 iwl_send_add_sta(priv,
657 (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700658 return 0;
659}
660
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800661static void iwl3945_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700662{
663 struct list_head *element;
664
665 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
666 priv->frames_count);
667
668 while (!list_empty(&priv->free_frames)) {
669 element = priv->free_frames.next;
670 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800671 kfree(list_entry(element, struct iwl3945_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700672 priv->frames_count--;
673 }
674
675 if (priv->frames_count) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800676 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
Zhu Yib481de92007-09-25 17:54:57 -0700677 priv->frames_count);
678 priv->frames_count = 0;
679 }
680}
681
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800682static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700683{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800684 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700685 struct list_head *element;
686 if (list_empty(&priv->free_frames)) {
687 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
688 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800689 IWL_ERR(priv, "Could not allocate frame!\n");
Zhu Yib481de92007-09-25 17:54:57 -0700690 return NULL;
691 }
692
693 priv->frames_count++;
694 return frame;
695 }
696
697 element = priv->free_frames.next;
698 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800699 return list_entry(element, struct iwl3945_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700700}
701
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800702static void iwl3945_free_frame(struct iwl_priv *priv, struct iwl3945_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700703{
704 memset(frame, 0, sizeof(*frame));
705 list_add(&frame->list, &priv->free_frames);
706}
707
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800708unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700709 struct ieee80211_hdr *hdr,
Rami Rosen73ec1cc2008-12-16 09:37:07 +0200710 int left)
Zhu Yib481de92007-09-25 17:54:57 -0700711{
712
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800713 if (!iwl3945_is_associated(priv) || !priv->ibss_beacon ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200714 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
715 (priv->iw_mode != NL80211_IFTYPE_AP)))
Zhu Yib481de92007-09-25 17:54:57 -0700716 return 0;
717
718 if (priv->ibss_beacon->len > left)
719 return 0;
720
721 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
722
723 return priv->ibss_beacon->len;
724}
725
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800726static u8 iwl3945_rate_get_lowest_plcp(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700727{
728 u8 i;
Kolekar, Abhijeetc24f0812008-11-07 09:58:44 -0800729 int rate_mask;
730
731 /* Set rate mask*/
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800732 if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK)
Chatre, Reinettedbce56a2008-11-12 13:14:07 -0800733 rate_mask = priv->active_rate_basic & IWL_CCK_RATES_MASK;
Kolekar, Abhijeetc24f0812008-11-07 09:58:44 -0800734 else
Chatre, Reinettedbce56a2008-11-12 13:14:07 -0800735 rate_mask = priv->active_rate_basic & IWL_OFDM_RATES_MASK;
Zhu Yib481de92007-09-25 17:54:57 -0700736
737 for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800738 i = iwl3945_rates[i].next_ieee) {
Zhu Yib481de92007-09-25 17:54:57 -0700739 if (rate_mask & (1 << i))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800740 return iwl3945_rates[i].plcp;
Zhu Yib481de92007-09-25 17:54:57 -0700741 }
742
Kolekar, Abhijeetc24f0812008-11-07 09:58:44 -0800743 /* No valid rate was found. Assign the lowest one */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800744 if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK)
Kolekar, Abhijeetc24f0812008-11-07 09:58:44 -0800745 return IWL_RATE_1M_PLCP;
746 else
747 return IWL_RATE_6M_PLCP;
Zhu Yib481de92007-09-25 17:54:57 -0700748}
749
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800750static int iwl3945_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700751{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800752 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700753 unsigned int frame_size;
754 int rc;
755 u8 rate;
756
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800757 frame = iwl3945_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700758
759 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800760 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
Zhu Yib481de92007-09-25 17:54:57 -0700761 "command.\n");
762 return -ENOMEM;
763 }
764
Kolekar, Abhijeetc24f0812008-11-07 09:58:44 -0800765 rate = iwl3945_rate_get_lowest_plcp(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700766
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800767 frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
Zhu Yib481de92007-09-25 17:54:57 -0700768
Samuel Ortiz518099a2009-01-19 15:30:27 -0800769 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -0700770 &frame->u.cmd[0]);
771
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800772 iwl3945_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -0700773
774 return rc;
775}
776
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800777static void iwl3945_unset_hw_params(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700778{
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800779 if (priv->shared_virt)
Zhu Yib481de92007-09-25 17:54:57 -0700780 pci_free_consistent(priv->pci_dev,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800781 sizeof(struct iwl3945_shared),
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800782 priv->shared_virt,
783 priv->shared_phys);
Zhu Yib481de92007-09-25 17:54:57 -0700784}
785
Zhu Yib481de92007-09-25 17:54:57 -0700786/*
787 * QoS support
788*/
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800789static int iwl3945_send_qos_params_command(struct iwl_priv *priv,
Tomas Winkler4c897252008-12-19 10:37:05 +0800790 struct iwl_qosparam_cmd *qos)
Zhu Yib481de92007-09-25 17:54:57 -0700791{
792
Samuel Ortiz518099a2009-01-19 15:30:27 -0800793 return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM,
Tomas Winkler4c897252008-12-19 10:37:05 +0800794 sizeof(struct iwl_qosparam_cmd), qos);
Zhu Yib481de92007-09-25 17:54:57 -0700795}
796
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800797static void iwl3945_activate_qos(struct iwl_priv *priv, u8 force)
Zhu Yib481de92007-09-25 17:54:57 -0700798{
799 unsigned long flags;
800
Zhu Yib481de92007-09-25 17:54:57 -0700801 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
802 return;
803
Zhu Yib481de92007-09-25 17:54:57 -0700804 spin_lock_irqsave(&priv->lock, flags);
805 priv->qos_data.def_qos_parm.qos_flags = 0;
806
807 if (priv->qos_data.qos_cap.q_AP.queue_request &&
808 !priv->qos_data.qos_cap.q_AP.txop_request)
809 priv->qos_data.def_qos_parm.qos_flags |=
810 QOS_PARAM_FLG_TXOP_TYPE_MSK;
811
812 if (priv->qos_data.qos_active)
813 priv->qos_data.def_qos_parm.qos_flags |=
814 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
815
816 spin_unlock_irqrestore(&priv->lock, flags);
817
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800818 if (force || iwl3945_is_associated(priv)) {
Tomas Winklera96a27f2008-10-23 23:48:56 -0700819 IWL_DEBUG_QOS("send QoS cmd with QoS active %d \n",
Zhu Yib481de92007-09-25 17:54:57 -0700820 priv->qos_data.qos_active);
821
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800822 iwl3945_send_qos_params_command(priv,
Zhu Yib481de92007-09-25 17:54:57 -0700823 &(priv->qos_data.def_qos_parm));
824 }
825}
826
Zhu Yib481de92007-09-25 17:54:57 -0700827/*
828 * Power management (not Tx power!) functions
829 */
830#define MSEC_TO_USEC 1024
831
Tomas Winkler600c0e12008-12-19 10:37:04 +0800832
Zhu Yib481de92007-09-25 17:54:57 -0700833/* default power management (not Tx power) table values */
Tomas Winklera96a27f2008-10-23 23:48:56 -0700834/* for TIM 0-10 */
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800835static struct iwl_power_vec_entry range_0[IWL_POWER_MAX] = {
836 {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
837 {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
838 {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
839 {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
840 {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
841 {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
Zhu Yib481de92007-09-25 17:54:57 -0700842};
843
Tomas Winklera96a27f2008-10-23 23:48:56 -0700844/* for TIM > 10 */
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800845static struct iwl_power_vec_entry range_1[IWL_POWER_MAX] = {
846 {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
847 {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
848 {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
849 {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
850 {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
851 {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
Zhu Yib481de92007-09-25 17:54:57 -0700852};
853
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800854int iwl3945_power_init_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700855{
856 int rc = 0, i;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800857 struct iwl_power_mgr *pow_data;
858 int size = sizeof(struct iwl_power_vec_entry) * IWL_POWER_MAX;
Zhu Yib481de92007-09-25 17:54:57 -0700859 u16 pci_pm;
860
861 IWL_DEBUG_POWER("Initialize power \n");
862
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800863 pow_data = &priv->power_data;
Zhu Yib481de92007-09-25 17:54:57 -0700864
865 memset(pow_data, 0, sizeof(*pow_data));
866
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800867 pow_data->dtim_period = 1;
Zhu Yib481de92007-09-25 17:54:57 -0700868
869 memcpy(&pow_data->pwr_range_0[0], &range_0[0], size);
870 memcpy(&pow_data->pwr_range_1[0], &range_1[0], size);
871
872 rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm);
873 if (rc != 0)
874 return 0;
875 else {
Tomas Winkler600c0e12008-12-19 10:37:04 +0800876 struct iwl_powertable_cmd *cmd;
Zhu Yib481de92007-09-25 17:54:57 -0700877
878 IWL_DEBUG_POWER("adjust power command flags\n");
879
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800880 for (i = 0; i < IWL_POWER_MAX; i++) {
Zhu Yib481de92007-09-25 17:54:57 -0700881 cmd = &pow_data->pwr_range_0[i].cmd;
882
883 if (pci_pm & 0x1)
884 cmd->flags &= ~IWL_POWER_PCI_PM_MSK;
885 else
886 cmd->flags |= IWL_POWER_PCI_PM_MSK;
887 }
888 }
889 return rc;
890}
891
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800892static int iwl3945_update_power_cmd(struct iwl_priv *priv,
Tomas Winkler600c0e12008-12-19 10:37:04 +0800893 struct iwl_powertable_cmd *cmd, u32 mode)
Zhu Yib481de92007-09-25 17:54:57 -0700894{
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800895 struct iwl_power_mgr *pow_data;
Samuel Ortiz1125eff2008-12-19 10:37:14 +0800896 struct iwl_power_vec_entry *range;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800897 u32 max_sleep = 0;
898 int i;
Zhu Yib481de92007-09-25 17:54:57 -0700899 u8 period = 0;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800900 bool skip;
Zhu Yib481de92007-09-25 17:54:57 -0700901
902 if (mode > IWL_POWER_INDEX_5) {
903 IWL_DEBUG_POWER("Error invalid power mode \n");
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800904 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -0700905 }
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800906 pow_data = &priv->power_data;
Zhu Yib481de92007-09-25 17:54:57 -0700907
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800908 if (pow_data->dtim_period < 10)
Zhu Yib481de92007-09-25 17:54:57 -0700909 range = &pow_data->pwr_range_0[0];
910 else
911 range = &pow_data->pwr_range_1[1];
912
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800913 memcpy(cmd, &range[mode].cmd, sizeof(struct iwl3945_powertable_cmd));
Zhu Yib481de92007-09-25 17:54:57 -0700914
Zhu Yib481de92007-09-25 17:54:57 -0700915
916 if (period == 0) {
917 period = 1;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800918 skip = false;
919 } else {
920 skip = !!range[mode].no_dtim;
Zhu Yib481de92007-09-25 17:54:57 -0700921 }
922
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800923 if (skip) {
Zhu Yib481de92007-09-25 17:54:57 -0700924 __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1];
925 max_sleep = (le32_to_cpu(slp_itrvl) / period) * period;
926 cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800927 } else {
928 max_sleep = period;
929 cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700930 }
931
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800932 for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
Zhu Yib481de92007-09-25 17:54:57 -0700933 if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep)
934 cmd->sleep_interval[i] = cpu_to_le32(max_sleep);
Zhu Yib481de92007-09-25 17:54:57 -0700935
936 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags);
937 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout));
938 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout));
939 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
940 le32_to_cpu(cmd->sleep_interval[0]),
941 le32_to_cpu(cmd->sleep_interval[1]),
942 le32_to_cpu(cmd->sleep_interval[2]),
943 le32_to_cpu(cmd->sleep_interval[3]),
944 le32_to_cpu(cmd->sleep_interval[4]));
945
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800946 return 0;
Zhu Yib481de92007-09-25 17:54:57 -0700947}
948
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800949static int iwl3945_send_power_mode(struct iwl_priv *priv, u32 mode)
Zhu Yib481de92007-09-25 17:54:57 -0700950{
John W. Linville9a62f732007-11-15 16:27:36 -0500951 u32 uninitialized_var(final_mode);
Zhu Yib481de92007-09-25 17:54:57 -0700952 int rc;
Tomas Winkler600c0e12008-12-19 10:37:04 +0800953 struct iwl_powertable_cmd cmd;
Zhu Yib481de92007-09-25 17:54:57 -0700954
955 /* If on battery, set to 3,
Ian Schram01ebd062007-10-25 17:15:22 +0800956 * if plugged into AC power, set to CAM ("continuously aware mode"),
Zhu Yib481de92007-09-25 17:54:57 -0700957 * else user level */
958 switch (mode) {
Samuel Ortiz1125eff2008-12-19 10:37:14 +0800959 case IWL39_POWER_BATTERY:
Zhu Yib481de92007-09-25 17:54:57 -0700960 final_mode = IWL_POWER_INDEX_3;
961 break;
Samuel Ortiz1125eff2008-12-19 10:37:14 +0800962 case IWL39_POWER_AC:
Zhu Yib481de92007-09-25 17:54:57 -0700963 final_mode = IWL_POWER_MODE_CAM;
964 break;
965 default:
966 final_mode = mode;
967 break;
968 }
969
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800970 iwl3945_update_power_cmd(priv, &cmd, final_mode);
Zhu Yib481de92007-09-25 17:54:57 -0700971
Tomas Winkler600c0e12008-12-19 10:37:04 +0800972 /* FIXME use get_hcmd_size 3945 command is 4 bytes shorter */
Samuel Ortiz518099a2009-01-19 15:30:27 -0800973 rc = iwl_send_cmd_pdu(priv, POWER_TABLE_CMD,
974 sizeof(struct iwl3945_powertable_cmd), &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700975
976 if (final_mode == IWL_POWER_MODE_CAM)
977 clear_bit(STATUS_POWER_PMI, &priv->status);
978 else
979 set_bit(STATUS_POWER_PMI, &priv->status);
980
981 return rc;
982}
983
Zhu Yib481de92007-09-25 17:54:57 -0700984#define MAX_UCODE_BEACON_INTERVAL 1024
985#define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
986
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800987static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val)
Zhu Yib481de92007-09-25 17:54:57 -0700988{
989 u16 new_val = 0;
990 u16 beacon_factor = 0;
991
992 beacon_factor =
993 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
994 / MAX_UCODE_BEACON_INTERVAL;
995 new_val = beacon_val / beacon_factor;
996
997 return cpu_to_le16(new_val);
998}
999
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001000static void iwl3945_setup_rxon_timing(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001001{
1002 u64 interval_tm_unit;
1003 u64 tsf, result;
1004 unsigned long flags;
1005 struct ieee80211_conf *conf = NULL;
1006 u16 beacon_int = 0;
1007
1008 conf = ieee80211_get_hw_conf(priv->hw);
1009
1010 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler28afaf92008-12-19 10:37:06 +08001011 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
Zhu Yib481de92007-09-25 17:54:57 -07001012 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
1013
Tomas Winkler28afaf92008-12-19 10:37:06 +08001014 tsf = priv->timestamp;
Zhu Yib481de92007-09-25 17:54:57 -07001015
1016 beacon_int = priv->beacon_int;
1017 spin_unlock_irqrestore(&priv->lock, flags);
1018
Johannes Berg05c914f2008-09-11 00:01:58 +02001019 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
Zhu Yib481de92007-09-25 17:54:57 -07001020 if (beacon_int == 0) {
1021 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
1022 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
1023 } else {
1024 priv->rxon_timing.beacon_interval =
1025 cpu_to_le16(beacon_int);
1026 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001027 iwl3945_adjust_beacon_interval(
Zhu Yib481de92007-09-25 17:54:57 -07001028 le16_to_cpu(priv->rxon_timing.beacon_interval));
1029 }
1030
1031 priv->rxon_timing.atim_window = 0;
1032 } else {
1033 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001034 iwl3945_adjust_beacon_interval(conf->beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -07001035 /* TODO: we need to get atim_window from upper stack
1036 * for now we set to 0 */
1037 priv->rxon_timing.atim_window = 0;
1038 }
1039
1040 interval_tm_unit =
1041 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
1042 result = do_div(tsf, interval_tm_unit);
1043 priv->rxon_timing.beacon_init_val =
1044 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
1045
1046 IWL_DEBUG_ASSOC
1047 ("beacon interval %d beacon timer %d beacon tim %d\n",
1048 le16_to_cpu(priv->rxon_timing.beacon_interval),
1049 le32_to_cpu(priv->rxon_timing.beacon_init_val),
1050 le16_to_cpu(priv->rxon_timing.atim_window));
1051}
1052
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001053static int iwl3945_scan_initiate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001054{
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08001055 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001056 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
1057 return -EIO;
1058 }
1059
1060 if (test_bit(STATUS_SCANNING, &priv->status)) {
1061 IWL_DEBUG_SCAN("Scan already in progress.\n");
1062 return -EAGAIN;
1063 }
1064
1065 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
1066 IWL_DEBUG_SCAN("Scan request while abort pending. "
1067 "Queuing.\n");
1068 return -EAGAIN;
1069 }
1070
1071 IWL_DEBUG_INFO("Starting scan...\n");
Ron Rindjunsky66b50042008-06-25 16:46:31 +08001072 if (priv->cfg->sku & IWL_SKU_G)
1073 priv->scan_bands |= BIT(IEEE80211_BAND_2GHZ);
1074 if (priv->cfg->sku & IWL_SKU_A)
1075 priv->scan_bands |= BIT(IEEE80211_BAND_5GHZ);
Zhu Yib481de92007-09-25 17:54:57 -07001076 set_bit(STATUS_SCANNING, &priv->status);
1077 priv->scan_start = jiffies;
1078 priv->scan_pass_start = priv->scan_start;
1079
1080 queue_work(priv->workqueue, &priv->request_scan);
1081
1082 return 0;
1083}
1084
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001085static int iwl3945_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
Zhu Yib481de92007-09-25 17:54:57 -07001086{
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001087 struct iwl3945_rxon_cmd *rxon = &priv->staging39_rxon;
Zhu Yib481de92007-09-25 17:54:57 -07001088
1089 if (hw_decrypt)
1090 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
1091 else
1092 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
1093
1094 return 0;
1095}
1096
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001097static void iwl3945_set_flags_for_phymode(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01001098 enum ieee80211_band band)
Zhu Yib481de92007-09-25 17:54:57 -07001099{
Johannes Berg8318d782008-01-24 19:38:38 +01001100 if (band == IEEE80211_BAND_5GHZ) {
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001101 priv->staging39_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07001102 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
1103 | RXON_FLG_CCK_MSK);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001104 priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001105 } else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001106 /* Copied from iwl3945_bg_post_associate() */
Zhu Yib481de92007-09-25 17:54:57 -07001107 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001108 priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001109 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001110 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001111
Johannes Berg05c914f2008-09-11 00:01:58 +02001112 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001113 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001114
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001115 priv->staging39_rxon.flags |= RXON_FLG_BAND_24G_MSK;
1116 priv->staging39_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
1117 priv->staging39_rxon.flags &= ~RXON_FLG_CCK_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001118 }
1119}
1120
1121/*
Ian Schram01ebd062007-10-25 17:15:22 +08001122 * initialize rxon structure with default values from eeprom
Zhu Yib481de92007-09-25 17:54:57 -07001123 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001124static void iwl3945_connection_init_rx_config(struct iwl_priv *priv,
Zhu, Yi60294de2008-10-29 14:05:45 -07001125 int mode)
Zhu Yib481de92007-09-25 17:54:57 -07001126{
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001127 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07001128
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001129 memset(&priv->staging39_rxon, 0, sizeof(priv->staging39_rxon));
Zhu Yib481de92007-09-25 17:54:57 -07001130
Zhu, Yi60294de2008-10-29 14:05:45 -07001131 switch (mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02001132 case NL80211_IFTYPE_AP:
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001133 priv->staging39_rxon.dev_type = RXON_DEV_TYPE_AP;
Zhu Yib481de92007-09-25 17:54:57 -07001134 break;
1135
Johannes Berg05c914f2008-09-11 00:01:58 +02001136 case NL80211_IFTYPE_STATION:
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001137 priv->staging39_rxon.dev_type = RXON_DEV_TYPE_ESS;
1138 priv->staging39_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001139 break;
1140
Johannes Berg05c914f2008-09-11 00:01:58 +02001141 case NL80211_IFTYPE_ADHOC:
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001142 priv->staging39_rxon.dev_type = RXON_DEV_TYPE_IBSS;
1143 priv->staging39_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
1144 priv->staging39_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
Zhu Yib481de92007-09-25 17:54:57 -07001145 RXON_FILTER_ACCEPT_GRP_MSK;
1146 break;
1147
Johannes Berg05c914f2008-09-11 00:01:58 +02001148 case NL80211_IFTYPE_MONITOR:
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001149 priv->staging39_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
1150 priv->staging39_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
Zhu Yib481de92007-09-25 17:54:57 -07001151 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
1152 break;
Tomas Winkler69dc5d92008-03-25 16:33:41 -07001153 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08001154 IWL_ERR(priv, "Unsupported interface type %d\n", mode);
Tomas Winkler69dc5d92008-03-25 16:33:41 -07001155 break;
Zhu Yib481de92007-09-25 17:54:57 -07001156 }
1157
1158#if 0
1159 /* TODO: Figure out when short_preamble would be set and cache from
1160 * that */
1161 if (!hw_to_local(priv->hw)->short_preamble)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001162 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001163 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001164 priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001165#endif
1166
Samuel Ortize6148912009-01-23 13:45:15 -08001167 ch_info = iwl_get_channel_info(priv, priv->band,
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001168 le16_to_cpu(priv->active39_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -07001169
1170 if (!ch_info)
1171 ch_info = &priv->channel_info[0];
1172
1173 /*
1174 * in some case A channels are all non IBSS
1175 * in this case force B/G channel
1176 */
Zhu, Yi60294de2008-10-29 14:05:45 -07001177 if ((mode == NL80211_IFTYPE_ADHOC) && !(is_channel_ibss(ch_info)))
Zhu Yib481de92007-09-25 17:54:57 -07001178 ch_info = &priv->channel_info[0];
1179
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001180 priv->staging39_rxon.channel = cpu_to_le16(ch_info->channel);
Zhu Yib481de92007-09-25 17:54:57 -07001181 if (is_channel_a_band(ch_info))
Johannes Berg8318d782008-01-24 19:38:38 +01001182 priv->band = IEEE80211_BAND_5GHZ;
Zhu Yib481de92007-09-25 17:54:57 -07001183 else
Johannes Berg8318d782008-01-24 19:38:38 +01001184 priv->band = IEEE80211_BAND_2GHZ;
Zhu Yib481de92007-09-25 17:54:57 -07001185
Johannes Berg8318d782008-01-24 19:38:38 +01001186 iwl3945_set_flags_for_phymode(priv, priv->band);
Zhu Yib481de92007-09-25 17:54:57 -07001187
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001188 priv->staging39_rxon.ofdm_basic_rates =
Zhu Yib481de92007-09-25 17:54:57 -07001189 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001190 priv->staging39_rxon.cck_basic_rates =
Zhu Yib481de92007-09-25 17:54:57 -07001191 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
1192}
1193
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001194static int iwl3945_set_mode(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -07001195{
Johannes Berg05c914f2008-09-11 00:01:58 +02001196 if (mode == NL80211_IFTYPE_ADHOC) {
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001197 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07001198
Samuel Ortize6148912009-01-23 13:45:15 -08001199 ch_info = iwl_get_channel_info(priv,
Johannes Berg8318d782008-01-24 19:38:38 +01001200 priv->band,
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001201 le16_to_cpu(priv->staging39_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -07001202
1203 if (!ch_info || !is_channel_ibss(ch_info)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001204 IWL_ERR(priv, "channel %d not IBSS channel\n",
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001205 le16_to_cpu(priv->staging39_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -07001206 return -EINVAL;
1207 }
1208 }
1209
Zhu, Yi60294de2008-10-29 14:05:45 -07001210 iwl3945_connection_init_rx_config(priv, mode);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001211 memcpy(priv->staging39_rxon.node_addr, priv->mac_addr, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07001212
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001213 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001214
Tomas Winklera96a27f2008-10-23 23:48:56 -07001215 /* don't commit rxon if rf-kill is on*/
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08001216 if (!iwl_is_ready_rf(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08001217 return -EAGAIN;
1218
1219 cancel_delayed_work(&priv->scan_check);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08001220 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001221 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +08001222 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
1223 return -EAGAIN;
1224 }
1225
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001226 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001227
1228 return 0;
1229}
1230
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001231static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
Johannes Berge039fa42008-05-15 12:55:29 +02001232 struct ieee80211_tx_info *info,
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08001233 struct iwl_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -07001234 struct sk_buff *skb_frag,
1235 int last_frag)
1236{
Winkler, Tomase52119c2008-12-22 11:31:19 +08001237 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
Ivo van Doorn1c014422008-04-17 19:41:02 +02001238 struct iwl3945_hw_key *keyinfo =
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001239 &priv->stations_39[info->control.hw_key->hw_key_idx].keyinfo;
Zhu Yib481de92007-09-25 17:54:57 -07001240
1241 switch (keyinfo->alg) {
1242 case ALG_CCMP:
Winkler, Tomase52119c2008-12-22 11:31:19 +08001243 tx->sec_ctl = TX_CMD_SEC_CCM;
1244 memcpy(tx->key, keyinfo->key, keyinfo->keylen);
Tomas Winklera96a27f2008-10-23 23:48:56 -07001245 IWL_DEBUG_TX("tx_cmd with AES hwcrypto\n");
Zhu Yib481de92007-09-25 17:54:57 -07001246 break;
1247
1248 case ALG_TKIP:
1249#if 0
Winkler, Tomase52119c2008-12-22 11:31:19 +08001250 tx->sec_ctl = TX_CMD_SEC_TKIP;
Zhu Yib481de92007-09-25 17:54:57 -07001251
1252 if (last_frag)
Winkler, Tomase52119c2008-12-22 11:31:19 +08001253 memcpy(tx->tkip_mic.byte, skb_frag->tail - 8,
Zhu Yib481de92007-09-25 17:54:57 -07001254 8);
1255 else
Winkler, Tomase52119c2008-12-22 11:31:19 +08001256 memset(tx->tkip_mic.byte, 0, 8);
Zhu Yib481de92007-09-25 17:54:57 -07001257#endif
1258 break;
1259
1260 case ALG_WEP:
Winkler, Tomase52119c2008-12-22 11:31:19 +08001261 tx->sec_ctl = TX_CMD_SEC_WEP |
Johannes Berge039fa42008-05-15 12:55:29 +02001262 (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
Zhu Yib481de92007-09-25 17:54:57 -07001263
1264 if (keyinfo->keylen == 13)
Winkler, Tomase52119c2008-12-22 11:31:19 +08001265 tx->sec_ctl |= TX_CMD_SEC_KEY128;
Zhu Yib481de92007-09-25 17:54:57 -07001266
Winkler, Tomase52119c2008-12-22 11:31:19 +08001267 memcpy(&tx->key[3], keyinfo->key, keyinfo->keylen);
Zhu Yib481de92007-09-25 17:54:57 -07001268
1269 IWL_DEBUG_TX("Configuring packet for WEP encryption "
Johannes Berge039fa42008-05-15 12:55:29 +02001270 "with key %d\n", info->control.hw_key->hw_key_idx);
Zhu Yib481de92007-09-25 17:54:57 -07001271 break;
1272
Zhu Yib481de92007-09-25 17:54:57 -07001273 default:
Tomas Winkler978785a2008-12-19 10:37:31 +08001274 IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg);
Zhu Yib481de92007-09-25 17:54:57 -07001275 break;
1276 }
1277}
1278
1279/*
1280 * handle build REPLY_TX command notification.
1281 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001282static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08001283 struct iwl_cmd *cmd,
Johannes Berge039fa42008-05-15 12:55:29 +02001284 struct ieee80211_tx_info *info,
Winkler, Tomase52119c2008-12-22 11:31:19 +08001285 struct ieee80211_hdr *hdr, u8 std_id)
Zhu Yib481de92007-09-25 17:54:57 -07001286{
Winkler, Tomase52119c2008-12-22 11:31:19 +08001287 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
1288 __le32 tx_flags = tx->tx_flags;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001289 __le16 fc = hdr->frame_control;
Johannes Berge6a98542008-10-21 12:40:02 +02001290 u8 rc_flags = info->control.rates[0].flags;
Zhu Yib481de92007-09-25 17:54:57 -07001291
Winkler, Tomase52119c2008-12-22 11:31:19 +08001292 tx->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
Johannes Berge039fa42008-05-15 12:55:29 +02001293 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
Zhu Yib481de92007-09-25 17:54:57 -07001294 tx_flags |= TX_CMD_FLG_ACK_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001295 if (ieee80211_is_mgmt(fc))
Zhu Yib481de92007-09-25 17:54:57 -07001296 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001297 if (ieee80211_is_probe_resp(fc) &&
Zhu Yib481de92007-09-25 17:54:57 -07001298 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
1299 tx_flags |= TX_CMD_FLG_TSF_MSK;
1300 } else {
1301 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
1302 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
1303 }
1304
Winkler, Tomase52119c2008-12-22 11:31:19 +08001305 tx->sta_id = std_id;
Harvey Harrison8b7b1e02008-06-11 14:21:56 -07001306 if (ieee80211_has_morefrags(fc))
Zhu Yib481de92007-09-25 17:54:57 -07001307 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
1308
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001309 if (ieee80211_is_data_qos(fc)) {
1310 u8 *qc = ieee80211_get_qos_ctl(hdr);
Winkler, Tomase52119c2008-12-22 11:31:19 +08001311 tx->tid_tspec = qc[0] & 0xf;
Zhu Yib481de92007-09-25 17:54:57 -07001312 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +08001313 } else {
Zhu Yib481de92007-09-25 17:54:57 -07001314 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +08001315 }
Zhu Yib481de92007-09-25 17:54:57 -07001316
Johannes Berge6a98542008-10-21 12:40:02 +02001317 if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
Zhu Yib481de92007-09-25 17:54:57 -07001318 tx_flags |= TX_CMD_FLG_RTS_MSK;
1319 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
Johannes Berge6a98542008-10-21 12:40:02 +02001320 } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
Zhu Yib481de92007-09-25 17:54:57 -07001321 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
1322 tx_flags |= TX_CMD_FLG_CTS_MSK;
1323 }
1324
1325 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
1326 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
1327
1328 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001329 if (ieee80211_is_mgmt(fc)) {
1330 if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
Winkler, Tomase52119c2008-12-22 11:31:19 +08001331 tx->timeout.pm_frame_timeout = cpu_to_le16(3);
Zhu Yib481de92007-09-25 17:54:57 -07001332 else
Winkler, Tomase52119c2008-12-22 11:31:19 +08001333 tx->timeout.pm_frame_timeout = cpu_to_le16(2);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07001334 } else {
Winkler, Tomase52119c2008-12-22 11:31:19 +08001335 tx->timeout.pm_frame_timeout = 0;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07001336#ifdef CONFIG_IWL3945_LEDS
1337 priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
1338#endif
1339 }
Zhu Yib481de92007-09-25 17:54:57 -07001340
Winkler, Tomase52119c2008-12-22 11:31:19 +08001341 tx->driver_txop = 0;
1342 tx->tx_flags = tx_flags;
1343 tx->next_frame_len = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001344}
1345
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001346/**
1347 * iwl3945_get_sta_id - Find station's index within station table
1348 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001349static int iwl3945_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
Zhu Yib481de92007-09-25 17:54:57 -07001350{
1351 int sta_id;
1352 u16 fc = le16_to_cpu(hdr->frame_control);
1353
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001354 /* If this frame is broadcast or management, use broadcast station id */
Zhu Yib481de92007-09-25 17:54:57 -07001355 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
1356 is_multicast_ether_addr(hdr->addr1))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001357 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07001358
1359 switch (priv->iw_mode) {
1360
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001361 /* If we are a client station in a BSS network, use the special
1362 * AP station entry (that's the only station we communicate with) */
Johannes Berg05c914f2008-09-11 00:01:58 +02001363 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -07001364 return IWL_AP_ID;
1365
1366 /* If we are an AP, then find the station, or use BCAST */
Johannes Berg05c914f2008-09-11 00:01:58 +02001367 case NL80211_IFTYPE_AP:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001368 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -07001369 if (sta_id != IWL_INVALID_STATION)
1370 return sta_id;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001371 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07001372
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001373 /* If this frame is going out to an IBSS network, find the station,
1374 * or create a new station table entry */
Johannes Berg05c914f2008-09-11 00:01:58 +02001375 case NL80211_IFTYPE_ADHOC: {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001376 /* Create new station table entry */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001377 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -07001378 if (sta_id != IWL_INVALID_STATION)
1379 return sta_id;
1380
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001381 sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
Zhu Yib481de92007-09-25 17:54:57 -07001382
1383 if (sta_id != IWL_INVALID_STATION)
1384 return sta_id;
1385
Johannes Berge1749612008-10-27 15:59:26 -07001386 IWL_DEBUG_DROP("Station %pM not in station map. "
Zhu Yib481de92007-09-25 17:54:57 -07001387 "Defaulting to broadcast...\n",
Johannes Berge1749612008-10-27 15:59:26 -07001388 hdr->addr1);
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08001389 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001390 return priv->hw_params.bcast_sta_id;
Joe Perches0795af52007-10-03 17:59:30 -07001391 }
Stefanik Gábor914233d2008-06-30 17:23:30 +08001392 /* If we are in monitor mode, use BCAST. This is required for
1393 * packet injection. */
Johannes Berg05c914f2008-09-11 00:01:58 +02001394 case NL80211_IFTYPE_MONITOR:
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001395 return priv->hw_params.bcast_sta_id;
Stefanik Gábor914233d2008-06-30 17:23:30 +08001396
Zhu Yib481de92007-09-25 17:54:57 -07001397 default:
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001398 IWL_WARN(priv, "Unknown mode of operation: %d\n",
1399 priv->iw_mode);
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001400 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07001401 }
1402}
1403
1404/*
1405 * start REPLY_TX command process
1406 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001407static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07001408{
1409 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berge039fa42008-05-15 12:55:29 +02001410 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Winkler, Tomase52119c2008-12-22 11:31:19 +08001411 struct iwl3945_tx_cmd *tx;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001412 struct iwl_tx_queue *txq = NULL;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001413 struct iwl_queue *q = NULL;
Winkler, Tomase52119c2008-12-22 11:31:19 +08001414 struct iwl_cmd *out_cmd = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07001415 dma_addr_t phys_addr;
1416 dma_addr_t txcmd_phys;
Winkler, Tomase52119c2008-12-22 11:31:19 +08001417 int txq_id = skb_get_queue_mapping(skb);
Tomas Winkler54dbb522008-05-15 13:54:06 +08001418 u16 len, idx, len_org, hdr_len;
1419 u8 id;
1420 u8 unicast;
Zhu Yib481de92007-09-25 17:54:57 -07001421 u8 sta_id;
Tomas Winkler54dbb522008-05-15 13:54:06 +08001422 u8 tid = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001423 u16 seq_number = 0;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001424 __le16 fc;
Zhu Yib481de92007-09-25 17:54:57 -07001425 u8 wait_write_ptr = 0;
Tomas Winkler54dbb522008-05-15 13:54:06 +08001426 u8 *qc = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07001427 unsigned long flags;
1428 int rc;
1429
1430 spin_lock_irqsave(&priv->lock, flags);
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08001431 if (iwl_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001432 IWL_DEBUG_DROP("Dropping - RF KILL\n");
1433 goto drop_unlock;
1434 }
1435
Johannes Berge039fa42008-05-15 12:55:29 +02001436 if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001437 IWL_ERR(priv, "ERROR: No TX rate available.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001438 goto drop_unlock;
1439 }
1440
1441 unicast = !is_multicast_ether_addr(hdr->addr1);
1442 id = 0;
1443
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001444 fc = hdr->frame_control;
Zhu Yib481de92007-09-25 17:54:57 -07001445
Samuel Ortizd08853a2009-01-23 13:45:17 -08001446#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001447 if (ieee80211_is_auth(fc))
1448 IWL_DEBUG_TX("Sending AUTH frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001449 else if (ieee80211_is_assoc_req(fc))
Zhu Yib481de92007-09-25 17:54:57 -07001450 IWL_DEBUG_TX("Sending ASSOC frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001451 else if (ieee80211_is_reassoc_req(fc))
Zhu Yib481de92007-09-25 17:54:57 -07001452 IWL_DEBUG_TX("Sending REASSOC frame\n");
1453#endif
1454
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08001455 /* drop all data frame if we are not associated */
Stefanik Gábor914233d2008-06-30 17:23:30 +08001456 if (ieee80211_is_data(fc) &&
Johannes Berg05c914f2008-09-11 00:01:58 +02001457 (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */
Stefanik Gábor914233d2008-06-30 17:23:30 +08001458 (!iwl3945_is_associated(priv) ||
Johannes Berg05c914f2008-09-11 00:01:58 +02001459 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001460 IWL_DEBUG_DROP("Dropping - !iwl3945_is_associated\n");
Zhu Yib481de92007-09-25 17:54:57 -07001461 goto drop_unlock;
1462 }
1463
1464 spin_unlock_irqrestore(&priv->lock, flags);
1465
Harvey Harrison7294ec92008-07-15 18:43:59 -07001466 hdr_len = ieee80211_hdrlen(fc);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001467
1468 /* Find (or create) index into station table for destination station */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001469 sta_id = iwl3945_get_sta_id(priv, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07001470 if (sta_id == IWL_INVALID_STATION) {
Johannes Berge1749612008-10-27 15:59:26 -07001471 IWL_DEBUG_DROP("Dropping - INVALID STATION: %pM\n",
1472 hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -07001473 goto drop;
1474 }
1475
1476 IWL_DEBUG_RATE("station Id %d\n", sta_id);
1477
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001478 if (ieee80211_is_data_qos(fc)) {
1479 qc = ieee80211_get_qos_ctl(hdr);
Harvey Harrison7294ec92008-07-15 18:43:59 -07001480 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001481 seq_number = priv->stations_39[sta_id].tid[tid].seq_number &
Zhu Yib481de92007-09-25 17:54:57 -07001482 IEEE80211_SCTL_SEQ;
1483 hdr->seq_ctrl = cpu_to_le16(seq_number) |
1484 (hdr->seq_ctrl &
1485 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG));
1486 seq_number += 0x10;
1487 }
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001488
1489 /* Descriptor for chosen Tx queue */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001490 txq = &priv->txq[txq_id];
Zhu Yib481de92007-09-25 17:54:57 -07001491 q = &txq->q;
1492
1493 spin_lock_irqsave(&priv->lock, flags);
1494
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001495 idx = get_cmd_index(q, q->write_ptr, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001496
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001497 /* Set up driver data for this TFD */
Winkler, Tomasdbb66542008-12-22 11:31:14 +08001498 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001499 txq->txb[q->write_ptr].skb[0] = skb;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001500
1501 /* Init first empty entry in queue's array of Tx/cmd buffers */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001502 out_cmd = txq->cmd[idx];
Winkler, Tomase52119c2008-12-22 11:31:19 +08001503 tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload;
Zhu Yib481de92007-09-25 17:54:57 -07001504 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
Winkler, Tomase52119c2008-12-22 11:31:19 +08001505 memset(tx, 0, sizeof(*tx));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001506
1507 /*
1508 * Set up the Tx-command (not MAC!) header.
1509 * Store the chosen Tx queue and TFD index within the sequence field;
1510 * after Tx, uCode's Tx response will return this value so driver can
1511 * locate the frame within the tx queue and do post-tx processing.
1512 */
Zhu Yib481de92007-09-25 17:54:57 -07001513 out_cmd->hdr.cmd = REPLY_TX;
1514 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001515 INDEX_TO_SEQ(q->write_ptr)));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001516
1517 /* Copy MAC header from skb into command buffer */
Winkler, Tomase52119c2008-12-22 11:31:19 +08001518 memcpy(tx->hdr, hdr, hdr_len);
Zhu Yib481de92007-09-25 17:54:57 -07001519
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001520 /*
1521 * Use the first empty entry in this queue's command buffer array
1522 * to contain the Tx command and MAC header concatenated together
1523 * (payload data will be in another buffer).
1524 * Size of this varies, due to varying MAC header length.
1525 * If end is not dword aligned, we'll have 2 extra bytes at the end
1526 * of the MAC header (device reads on dword boundaries).
1527 * We'll tell device about this padding later.
1528 */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001529 len = sizeof(struct iwl3945_tx_cmd) +
Tomas Winkler4c897252008-12-19 10:37:05 +08001530 sizeof(struct iwl_cmd_header) + hdr_len;
Zhu Yib481de92007-09-25 17:54:57 -07001531
1532 len_org = len;
1533 len = (len + 3) & ~3;
1534
1535 if (len_org != len)
1536 len_org = 1;
1537 else
1538 len_org = 0;
1539
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001540 /* Physical address of this Tx command's header (not MAC header!),
1541 * within command buffer array. */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001542 txcmd_phys = pci_map_single(priv->pci_dev,
1543 out_cmd, sizeof(struct iwl_cmd),
1544 PCI_DMA_TODEVICE);
1545 pci_unmap_addr_set(&out_cmd->meta, mapping, txcmd_phys);
1546 pci_unmap_len_set(&out_cmd->meta, len, sizeof(struct iwl_cmd));
1547 /* Add buffer containing Tx command and MAC(!) header to TFD's
1548 * first entry */
1549 txcmd_phys += offsetof(struct iwl_cmd, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07001550
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001551 /* Add buffer containing Tx command and MAC(!) header to TFD's
1552 * first entry */
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001553 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1554 txcmd_phys, len, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001555
Johannes Bergd0f09802008-07-29 11:32:07 +02001556 if (info->control.hw_key)
Johannes Berge039fa42008-05-15 12:55:29 +02001557 iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001558
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001559 /* Set up TFD's 2nd entry to point directly to remainder of skb,
1560 * if any (802.11 null frames have no payload). */
Zhu Yib481de92007-09-25 17:54:57 -07001561 len = skb->len - hdr_len;
1562 if (len) {
1563 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
1564 len, PCI_DMA_TODEVICE);
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001565 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1566 phys_addr, len,
1567 0, U32_PAD(len));
Zhu Yib481de92007-09-25 17:54:57 -07001568 }
1569
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001570 /* Total # bytes to be transmitted */
Zhu Yib481de92007-09-25 17:54:57 -07001571 len = (u16)skb->len;
Winkler, Tomase52119c2008-12-22 11:31:19 +08001572 tx->len = cpu_to_le16(len);
Zhu Yib481de92007-09-25 17:54:57 -07001573
1574 /* TODO need this for burst mode later on */
Winkler, Tomase52119c2008-12-22 11:31:19 +08001575 iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07001576
1577 /* set is_hcca to 0; it probably will never be implemented */
Johannes Berge039fa42008-05-15 12:55:29 +02001578 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001579
Winkler, Tomase52119c2008-12-22 11:31:19 +08001580 tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
1581 tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001582
Harvey Harrison8b7b1e02008-06-11 14:21:56 -07001583 if (!ieee80211_has_morefrags(hdr->frame_control)) {
Zhu Yib481de92007-09-25 17:54:57 -07001584 txq->need_update = 1;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001585 if (qc)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001586 priv->stations_39[sta_id].tid[tid].seq_number = seq_number;
Zhu Yib481de92007-09-25 17:54:57 -07001587 } else {
1588 wait_write_ptr = 1;
1589 txq->need_update = 0;
1590 }
1591
Winkler, Tomase52119c2008-12-22 11:31:19 +08001592 iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx));
Zhu Yib481de92007-09-25 17:54:57 -07001593
Winkler, Tomase52119c2008-12-22 11:31:19 +08001594 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr,
Harvey Harrison7294ec92008-07-15 18:43:59 -07001595 ieee80211_hdrlen(fc));
Zhu Yib481de92007-09-25 17:54:57 -07001596
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001597 /* Tell device the write index *just past* this latest filled TFD */
Tomas Winklerc54b6792008-03-06 17:36:53 -08001598 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001599 rc = iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001600 spin_unlock_irqrestore(&priv->lock, flags);
1601
1602 if (rc)
1603 return rc;
1604
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001605 if ((iwl_queue_space(q) < q->high_mark)
Zhu Yib481de92007-09-25 17:54:57 -07001606 && priv->mac80211_registered) {
1607 if (wait_write_ptr) {
1608 spin_lock_irqsave(&priv->lock, flags);
1609 txq->need_update = 1;
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001610 iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001611 spin_unlock_irqrestore(&priv->lock, flags);
1612 }
1613
Johannes Berge2530082008-05-17 00:57:14 +02001614 ieee80211_stop_queue(priv->hw, skb_get_queue_mapping(skb));
Zhu Yib481de92007-09-25 17:54:57 -07001615 }
1616
1617 return 0;
1618
1619drop_unlock:
1620 spin_unlock_irqrestore(&priv->lock, flags);
1621drop:
1622 return -1;
1623}
1624
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001625static void iwl3945_set_rate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001626{
Johannes Berg8318d782008-01-24 19:38:38 +01001627 const struct ieee80211_supported_band *sband = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07001628 struct ieee80211_rate *rate;
1629 int i;
1630
Kolekar, Abhijeetcbba18c2008-12-19 10:37:42 +08001631 sband = iwl_get_hw_mode(priv, priv->band);
Johannes Berg8318d782008-01-24 19:38:38 +01001632 if (!sband) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001633 IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n");
Saleem Abdulrasoolc4ba9622007-11-18 23:59:08 -08001634 return;
1635 }
Zhu Yib481de92007-09-25 17:54:57 -07001636
1637 priv->active_rate = 0;
1638 priv->active_rate_basic = 0;
1639
Johannes Berg8318d782008-01-24 19:38:38 +01001640 IWL_DEBUG_RATE("Setting rates for %s GHz\n",
1641 sband->band == IEEE80211_BAND_2GHZ ? "2.4" : "5");
Zhu Yib481de92007-09-25 17:54:57 -07001642
Johannes Berg8318d782008-01-24 19:38:38 +01001643 for (i = 0; i < sband->n_bitrates; i++) {
1644 rate = &sband->bitrates[i];
1645 if ((rate->hw_value < IWL_RATE_COUNT) &&
1646 !(rate->flags & IEEE80211_CHAN_DISABLED)) {
1647 IWL_DEBUG_RATE("Adding rate index %d (plcp %d)\n",
1648 rate->hw_value, iwl3945_rates[rate->hw_value].plcp);
1649 priv->active_rate |= (1 << rate->hw_value);
1650 }
Zhu Yib481de92007-09-25 17:54:57 -07001651 }
1652
1653 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
1654 priv->active_rate, priv->active_rate_basic);
1655
1656 /*
1657 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
1658 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
1659 * OFDM
1660 */
1661 if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001662 priv->staging39_rxon.cck_basic_rates =
Zhu Yib481de92007-09-25 17:54:57 -07001663 ((priv->active_rate_basic &
1664 IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
1665 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001666 priv->staging39_rxon.cck_basic_rates =
Zhu Yib481de92007-09-25 17:54:57 -07001667 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
1668
1669 if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001670 priv->staging39_rxon.ofdm_basic_rates =
Zhu Yib481de92007-09-25 17:54:57 -07001671 ((priv->active_rate_basic &
1672 (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
1673 IWL_FIRST_OFDM_RATE) & 0xFF;
1674 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001675 priv->staging39_rxon.ofdm_basic_rates =
Zhu Yib481de92007-09-25 17:54:57 -07001676 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
1677}
1678
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001679static void iwl3945_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
Zhu Yib481de92007-09-25 17:54:57 -07001680{
1681 unsigned long flags;
1682
1683 if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
1684 return;
1685
1686 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
1687 disable_radio ? "OFF" : "ON");
1688
1689 if (disable_radio) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08001690 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001691 /* FIXME: This is a workaround for AP */
Johannes Berg05c914f2008-09-11 00:01:58 +02001692 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07001693 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001694 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001695 CSR_UCODE_SW_BIT_RFKILL);
1696 spin_unlock_irqrestore(&priv->lock, flags);
Samuel Ortizc4962942008-12-22 11:31:18 +08001697 iwl_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001698 set_bit(STATUS_RF_KILL_SW, &priv->status);
1699 }
1700 return;
1701 }
1702
1703 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001704 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07001705
1706 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1707 spin_unlock_irqrestore(&priv->lock, flags);
1708
1709 /* wake up ucode */
1710 msleep(10);
1711
1712 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001713 iwl_read32(priv, CSR_UCODE_DRV_GP1);
1714 if (!iwl_grab_nic_access(priv))
1715 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001716 spin_unlock_irqrestore(&priv->lock, flags);
1717
1718 if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
1719 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
1720 "disabled by HW switch\n");
1721 return;
1722 }
1723
Zhu Yi808e72a2008-06-12 09:47:17 +08001724 if (priv->is_open)
1725 queue_work(priv->workqueue, &priv->restart);
Zhu Yib481de92007-09-25 17:54:57 -07001726 return;
1727}
1728
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001729void iwl3945_set_decrypted_flag(struct iwl_priv *priv, struct sk_buff *skb,
Zhu Yib481de92007-09-25 17:54:57 -07001730 u32 decrypt_res, struct ieee80211_rx_status *stats)
1731{
1732 u16 fc =
1733 le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control);
1734
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001735 if (priv->active39_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
Zhu Yib481de92007-09-25 17:54:57 -07001736 return;
1737
1738 if (!(fc & IEEE80211_FCTL_PROTECTED))
1739 return;
1740
1741 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
1742 switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
1743 case RX_RES_STATUS_SEC_TYPE_TKIP:
1744 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
1745 RX_RES_STATUS_BAD_ICV_MIC)
1746 stats->flag |= RX_FLAG_MMIC_ERROR;
1747 case RX_RES_STATUS_SEC_TYPE_WEP:
1748 case RX_RES_STATUS_SEC_TYPE_CCMP:
1749 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
1750 RX_RES_STATUS_DECRYPT_OK) {
1751 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
1752 stats->flag |= RX_FLAG_DECRYPTED;
1753 }
1754 break;
1755
1756 default:
1757 break;
1758 }
1759}
1760
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001761#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07001762
1763#include "iwl-spectrum.h"
1764
1765#define BEACON_TIME_MASK_LOW 0x00FFFFFF
1766#define BEACON_TIME_MASK_HIGH 0xFF000000
1767#define TIME_UNIT 1024
1768
1769/*
1770 * extended beacon time format
1771 * time in usec will be changed into a 32-bit value in 8:24 format
1772 * the high 1 byte is the beacon counts
1773 * the lower 3 bytes is the time in usec within one beacon interval
1774 */
1775
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001776static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001777{
1778 u32 quot;
1779 u32 rem;
1780 u32 interval = beacon_interval * 1024;
1781
1782 if (!interval || !usec)
1783 return 0;
1784
1785 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
1786 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
1787
1788 return (quot << 24) + rem;
1789}
1790
1791/* base is usually what we get from ucode with each received frame,
1792 * the same as HW timer counter counting down
1793 */
1794
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001795static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001796{
1797 u32 base_low = base & BEACON_TIME_MASK_LOW;
1798 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
1799 u32 interval = beacon_interval * TIME_UNIT;
1800 u32 res = (base & BEACON_TIME_MASK_HIGH) +
1801 (addon & BEACON_TIME_MASK_HIGH);
1802
1803 if (base_low > addon_low)
1804 res += base_low - addon_low;
1805 else if (base_low < addon_low) {
1806 res += interval + base_low - addon_low;
1807 res += (1 << 24);
1808 } else
1809 res += (1 << 24);
1810
1811 return cpu_to_le32(res);
1812}
1813
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001814static int iwl3945_get_measurement(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001815 struct ieee80211_measurement_params *params,
1816 u8 type)
1817{
Tomas Winkler600c0e12008-12-19 10:37:04 +08001818 struct iwl_spectrum_cmd spectrum;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001819 struct iwl_rx_packet *res;
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08001820 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001821 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
1822 .data = (void *)&spectrum,
1823 .meta.flags = CMD_WANT_SKB,
1824 };
1825 u32 add_time = le64_to_cpu(params->start_time);
1826 int rc;
1827 int spectrum_resp_status;
1828 int duration = le16_to_cpu(params->duration);
1829
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001830 if (iwl3945_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001831 add_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001832 iwl3945_usecs_to_beacons(
Zhu Yib481de92007-09-25 17:54:57 -07001833 le64_to_cpu(params->start_time) - priv->last_tsf,
1834 le16_to_cpu(priv->rxon_timing.beacon_interval));
1835
1836 memset(&spectrum, 0, sizeof(spectrum));
1837
1838 spectrum.channel_count = cpu_to_le16(1);
1839 spectrum.flags =
1840 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
1841 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
1842 cmd.len = sizeof(spectrum);
1843 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
1844
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001845 if (iwl3945_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001846 spectrum.start_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001847 iwl3945_add_beacon_time(priv->last_beacon_time,
Zhu Yib481de92007-09-25 17:54:57 -07001848 add_time,
1849 le16_to_cpu(priv->rxon_timing.beacon_interval));
1850 else
1851 spectrum.start_time = 0;
1852
1853 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
1854 spectrum.channels[0].channel = params->channel;
1855 spectrum.channels[0].type = type;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001856 if (priv->active39_rxon.flags & RXON_FLG_BAND_24G_MSK)
Zhu Yib481de92007-09-25 17:54:57 -07001857 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
1858 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
1859
Samuel Ortiz518099a2009-01-19 15:30:27 -08001860 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001861 if (rc)
1862 return rc;
1863
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001864 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001865 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001866 IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -07001867 rc = -EIO;
1868 }
1869
1870 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
1871 switch (spectrum_resp_status) {
1872 case 0: /* Command will be handled */
1873 if (res->u.spectrum.id != 0xff) {
Ian Schrambc434dd2007-10-25 17:15:29 +08001874 IWL_DEBUG_INFO("Replaced existing measurement: %d\n",
1875 res->u.spectrum.id);
Zhu Yib481de92007-09-25 17:54:57 -07001876 priv->measurement_status &= ~MEASUREMENT_READY;
1877 }
1878 priv->measurement_status |= MEASUREMENT_ACTIVE;
1879 rc = 0;
1880 break;
1881
1882 case 1: /* Command will not be handled */
1883 rc = -EAGAIN;
1884 break;
1885 }
1886
1887 dev_kfree_skb_any(cmd.meta.u.skb);
1888
1889 return rc;
1890}
1891#endif
1892
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001893static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001894 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001895{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001896 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
1897 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -07001898 struct delayed_work *pwork;
1899
1900 palive = &pkt->u.alive_frame;
1901
1902 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
1903 "0x%01X 0x%01X\n",
1904 palive->is_valid, palive->ver_type,
1905 palive->ver_subtype);
1906
1907 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
1908 IWL_DEBUG_INFO("Initialization Alive received.\n");
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001909 memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
1910 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001911 pwork = &priv->init_alive_start;
1912 } else {
1913 IWL_DEBUG_INFO("Runtime Alive received.\n");
1914 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001915 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001916 pwork = &priv->alive_start;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001917 iwl3945_disable_events(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001918 }
1919
1920 /* We delay the ALIVE response by 5ms to
1921 * give the HW RF Kill time to activate... */
1922 if (palive->is_valid == UCODE_VALID_OK)
1923 queue_delayed_work(priv->workqueue, pwork,
1924 msecs_to_jiffies(5));
1925 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001926 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001927}
1928
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001929static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001930 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001931{
Helmut Schaac7e035a2009-01-19 13:02:15 +01001932#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001933 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Helmut Schaac7e035a2009-01-19 13:02:15 +01001934#endif
Zhu Yib481de92007-09-25 17:54:57 -07001935
1936 IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
1937 return;
1938}
1939
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001940static void iwl3945_rx_reply_error(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001941 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001942{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001943 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001944
Winkler, Tomas15b16872008-12-19 10:37:33 +08001945 IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
Zhu Yib481de92007-09-25 17:54:57 -07001946 "seq 0x%04X ser 0x%08X\n",
1947 le32_to_cpu(pkt->u.err_resp.error_type),
1948 get_cmd_string(pkt->u.err_resp.cmd_id),
1949 pkt->u.err_resp.cmd_id,
1950 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
1951 le32_to_cpu(pkt->u.err_resp.error_info));
1952}
1953
1954#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1955
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001956static void iwl3945_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001957{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001958 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001959 struct iwl3945_rxon_cmd *rxon = (void *)&priv->active39_rxon;
Tomas Winkler600c0e12008-12-19 10:37:04 +08001960 struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001961 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
1962 le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
1963 rxon->channel = csa->channel;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001964 priv->staging39_rxon.channel = csa->channel;
Zhu Yib481de92007-09-25 17:54:57 -07001965}
1966
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001967static void iwl3945_rx_spectrum_measure_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001968 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001969{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001970#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001971 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler600c0e12008-12-19 10:37:04 +08001972 struct iwl_spectrum_notification *report = &(pkt->u.spectrum_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001973
1974 if (!report->state) {
1975 IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO,
1976 "Spectrum Measure Notification: Start\n");
1977 return;
1978 }
1979
1980 memcpy(&priv->measure_report, report, sizeof(*report));
1981 priv->measurement_status |= MEASUREMENT_READY;
1982#endif
1983}
1984
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001985static void iwl3945_rx_pm_sleep_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001986 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001987{
Samuel Ortizd08853a2009-01-23 13:45:17 -08001988#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001989 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler600c0e12008-12-19 10:37:04 +08001990 struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001991 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
1992 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
1993#endif
1994}
1995
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001996static void iwl3945_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001997 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001998{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001999 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002000 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
2001 "notification for %s:\n",
2002 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002003 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw,
2004 le32_to_cpu(pkt->len));
Zhu Yib481de92007-09-25 17:54:57 -07002005}
2006
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002007static void iwl3945_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07002008{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002009 struct iwl_priv *priv =
2010 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07002011 struct sk_buff *beacon;
2012
2013 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +02002014 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -07002015
2016 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002017 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07002018 return;
2019 }
2020
2021 mutex_lock(&priv->mutex);
2022 /* new beacon skb is allocated every time; dispose previous.*/
2023 if (priv->ibss_beacon)
2024 dev_kfree_skb(priv->ibss_beacon);
2025
2026 priv->ibss_beacon = beacon;
2027 mutex_unlock(&priv->mutex);
2028
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002029 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002030}
2031
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002032static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002033 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002034{
Samuel Ortizd08853a2009-01-23 13:45:17 -08002035#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002036 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002037 struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
Zhu Yib481de92007-09-25 17:54:57 -07002038 u8 rate = beacon->beacon_notify_hdr.rate;
2039
2040 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
2041 "tsf %d %d rate %d\n",
2042 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
2043 beacon->beacon_notify_hdr.failure_frame,
2044 le32_to_cpu(beacon->ibss_mgr_status),
2045 le32_to_cpu(beacon->high_tsf),
2046 le32_to_cpu(beacon->low_tsf), rate);
2047#endif
2048
Johannes Berg05c914f2008-09-11 00:01:58 +02002049 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -07002050 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
2051 queue_work(priv->workqueue, &priv->beacon_update);
2052}
2053
2054/* Service response to REPLY_SCAN_CMD (0x80) */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002055static void iwl3945_rx_reply_scan(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002056 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002057{
Samuel Ortizd08853a2009-01-23 13:45:17 -08002058#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002059 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler4c897252008-12-19 10:37:05 +08002060 struct iwl_scanreq_notification *notif =
2061 (struct iwl_scanreq_notification *)pkt->u.raw;
Zhu Yib481de92007-09-25 17:54:57 -07002062
2063 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status);
2064#endif
2065}
2066
2067/* Service SCAN_START_NOTIFICATION (0x82) */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002068static void iwl3945_rx_scan_start_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002069 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002070{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002071 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler4c897252008-12-19 10:37:05 +08002072 struct iwl_scanstart_notification *notif =
2073 (struct iwl_scanstart_notification *)pkt->u.raw;
Zhu Yib481de92007-09-25 17:54:57 -07002074 priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
2075 IWL_DEBUG_SCAN("Scan start: "
2076 "%d [802.11%s] "
2077 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
2078 notif->channel,
2079 notif->band ? "bg" : "a",
2080 notif->tsf_high,
2081 notif->tsf_low, notif->status, notif->beacon_timer);
2082}
2083
2084/* Service SCAN_RESULTS_NOTIFICATION (0x83) */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002085static void iwl3945_rx_scan_results_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002086 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002087{
Helmut Schaac7e035a2009-01-19 13:02:15 +01002088#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002089 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler4c897252008-12-19 10:37:05 +08002090 struct iwl_scanresults_notification *notif =
2091 (struct iwl_scanresults_notification *)pkt->u.raw;
Helmut Schaac7e035a2009-01-19 13:02:15 +01002092#endif
Zhu Yib481de92007-09-25 17:54:57 -07002093
2094 IWL_DEBUG_SCAN("Scan ch.res: "
2095 "%d [802.11%s] "
2096 "(TSF: 0x%08X:%08X) - %d "
2097 "elapsed=%lu usec (%dms since last)\n",
2098 notif->channel,
2099 notif->band ? "bg" : "a",
2100 le32_to_cpu(notif->tsf_high),
2101 le32_to_cpu(notif->tsf_low),
2102 le32_to_cpu(notif->statistics[0]),
2103 le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf,
2104 jiffies_to_msecs(elapsed_jiffies
2105 (priv->last_scan_jiffies, jiffies)));
2106
2107 priv->last_scan_jiffies = jiffies;
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08002108 priv->next_scan_jiffies = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002109}
2110
2111/* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002112static void iwl3945_rx_scan_complete_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002113 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002114{
Helmut Schaac7e035a2009-01-19 13:02:15 +01002115#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002116 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler4c897252008-12-19 10:37:05 +08002117 struct iwl_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
Helmut Schaac7e035a2009-01-19 13:02:15 +01002118#endif
Zhu Yib481de92007-09-25 17:54:57 -07002119
2120 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
2121 scan_notif->scanned_channels,
2122 scan_notif->tsf_low,
2123 scan_notif->tsf_high, scan_notif->status);
2124
2125 /* The HW is no longer scanning */
2126 clear_bit(STATUS_SCAN_HW, &priv->status);
2127
2128 /* The scan completion notification came in, so kill that timer... */
2129 cancel_delayed_work(&priv->scan_check);
2130
2131 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
Ron Rindjunsky66b50042008-06-25 16:46:31 +08002132 (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) ?
2133 "2.4" : "5.2",
Zhu Yib481de92007-09-25 17:54:57 -07002134 jiffies_to_msecs(elapsed_jiffies
2135 (priv->scan_pass_start, jiffies)));
2136
Ron Rindjunsky66b50042008-06-25 16:46:31 +08002137 /* Remove this scanned band from the list of pending
2138 * bands to scan, band G precedes A in order of scanning
2139 * as seen in iwl3945_bg_request_scan */
2140 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ))
2141 priv->scan_bands &= ~BIT(IEEE80211_BAND_2GHZ);
2142 else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ))
2143 priv->scan_bands &= ~BIT(IEEE80211_BAND_5GHZ);
Zhu Yib481de92007-09-25 17:54:57 -07002144
2145 /* If a request to abort was given, or the scan did not succeed
2146 * then we reset the scan state machine and terminate,
2147 * re-queuing another scan if one has been requested */
2148 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
2149 IWL_DEBUG_INFO("Aborted scan completed.\n");
2150 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
2151 } else {
2152 /* If there are more bands on this scan pass reschedule */
2153 if (priv->scan_bands > 0)
2154 goto reschedule;
2155 }
2156
2157 priv->last_scan_jiffies = jiffies;
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08002158 priv->next_scan_jiffies = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002159 IWL_DEBUG_INFO("Setting scan to off\n");
2160
2161 clear_bit(STATUS_SCANNING, &priv->status);
2162
2163 IWL_DEBUG_INFO("Scan took %dms\n",
2164 jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies)));
2165
2166 queue_work(priv->workqueue, &priv->scan_completed);
2167
2168 return;
2169
2170reschedule:
2171 priv->scan_pass_start = jiffies;
2172 queue_work(priv->workqueue, &priv->request_scan);
2173}
2174
2175/* Handle notification from uCode that card's power state is changing
2176 * due to software, hardware, or critical temperature RFKILL */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002177static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002178 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002179{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002180 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002181 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
2182 unsigned long status = priv->status;
2183
2184 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
2185 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
2186 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
2187
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002188 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07002189 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
2190
2191 if (flags & HW_CARD_DISABLED)
2192 set_bit(STATUS_RF_KILL_HW, &priv->status);
2193 else
2194 clear_bit(STATUS_RF_KILL_HW, &priv->status);
2195
2196
2197 if (flags & SW_CARD_DISABLED)
2198 set_bit(STATUS_RF_KILL_SW, &priv->status);
2199 else
2200 clear_bit(STATUS_RF_KILL_SW, &priv->status);
2201
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08002202 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002203
2204 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
2205 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
2206 (test_bit(STATUS_RF_KILL_SW, &status) !=
2207 test_bit(STATUS_RF_KILL_SW, &priv->status)))
2208 queue_work(priv->workqueue, &priv->rf_kill);
2209 else
2210 wake_up_interruptible(&priv->wait_command_queue);
2211}
2212
2213/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002214 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07002215 *
2216 * Setup the RX handlers for each of the reply types sent from the uCode
2217 * to the host.
2218 *
2219 * This function chains into the hardware specific files for them to setup
2220 * any hardware specific handlers as well.
2221 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002222static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002223{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002224 priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
2225 priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
2226 priv->rx_handlers[REPLY_ERROR] = iwl3945_rx_reply_error;
2227 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl3945_rx_csa;
Zhu Yib481de92007-09-25 17:54:57 -07002228 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002229 iwl3945_rx_spectrum_measure_notif;
2230 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl3945_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07002231 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002232 iwl3945_rx_pm_debug_statistics_notif;
2233 priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07002234
Ben Cahill9fbab512007-11-29 11:09:47 +08002235 /*
2236 * The same handler is used for both the REPLY to a discrete
2237 * statistics request from the host as well as for the periodic
2238 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07002239 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002240 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
2241 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
Zhu Yib481de92007-09-25 17:54:57 -07002242
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002243 priv->rx_handlers[REPLY_SCAN_CMD] = iwl3945_rx_reply_scan;
2244 priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl3945_rx_scan_start_notif;
Zhu Yib481de92007-09-25 17:54:57 -07002245 priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002246 iwl3945_rx_scan_results_notif;
Zhu Yib481de92007-09-25 17:54:57 -07002247 priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002248 iwl3945_rx_scan_complete_notif;
2249 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -07002250
Ben Cahill9fbab512007-11-29 11:09:47 +08002251 /* Set up hardware specific Rx handlers */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002252 iwl3945_hw_rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002253}
2254
2255/**
Tomas Winkler91c066f2008-03-06 17:36:55 -08002256 * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries
2257 * When FW advances 'R' index, all entries between old and new 'R' index
2258 * need to be reclaimed.
2259 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002260static void iwl3945_cmd_queue_reclaim(struct iwl_priv *priv,
Tomas Winkler91c066f2008-03-06 17:36:55 -08002261 int txq_id, int index)
2262{
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08002263 struct iwl_tx_queue *txq = &priv->txq[txq_id];
Samuel Ortizd20b3c62008-12-19 10:37:15 +08002264 struct iwl_queue *q = &txq->q;
Tomas Winkler91c066f2008-03-06 17:36:55 -08002265 int nfreed = 0;
2266
Winkler, Tomas625a3812009-01-08 10:19:55 -08002267 if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002268 IWL_ERR(priv, "Read index for DMA queue txq id (%d), index %d, "
Tomas Winkler91c066f2008-03-06 17:36:55 -08002269 "is out of range [0-%d] %d %d.\n", txq_id,
2270 index, q->n_bd, q->write_ptr, q->read_ptr);
2271 return;
2272 }
2273
2274 for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
2275 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
2276 if (nfreed > 1) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002277 IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", index,
Tomas Winkler91c066f2008-03-06 17:36:55 -08002278 q->write_ptr, q->read_ptr);
2279 queue_work(priv->workqueue, &priv->restart);
2280 break;
2281 }
2282 nfreed++;
2283 }
2284}
2285
2286
2287/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002288 * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
Zhu Yib481de92007-09-25 17:54:57 -07002289 * @rxb: Rx buffer to reclaim
2290 *
2291 * If an Rx buffer has an async callback associated with it the callback
2292 * will be executed. The attached skb (if present) will only be freed
2293 * if the callback returns 1
2294 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002295static void iwl3945_tx_cmd_complete(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002296 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002297{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002298 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002299 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
2300 int txq_id = SEQ_TO_QUEUE(sequence);
2301 int index = SEQ_TO_INDEX(sequence);
Tomas Winkler600c0e12008-12-19 10:37:04 +08002302 int huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME);
Zhu Yib481de92007-09-25 17:54:57 -07002303 int cmd_index;
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08002304 struct iwl_cmd *cmd;
Zhu Yib481de92007-09-25 17:54:57 -07002305
Chatre, Reinette638d0eb2009-01-19 15:30:24 -08002306 if (WARN(txq_id != IWL_CMD_QUEUE_NUM,
2307 "wrong command queue %d, sequence 0x%X readp=%d writep=%d\n",
2308 txq_id, sequence,
2309 priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr,
2310 priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) {
2311 iwl_print_hex_dump(priv, IWL_DL_INFO , rxb, 32);
2312 return;
2313 }
Zhu Yib481de92007-09-25 17:54:57 -07002314
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08002315 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
2316 cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
Zhu Yib481de92007-09-25 17:54:57 -07002317
2318 /* Input error checking is done when commands are added to queue. */
2319 if (cmd->meta.flags & CMD_WANT_SKB) {
2320 cmd->meta.source->u.skb = rxb->skb;
2321 rxb->skb = NULL;
2322 } else if (cmd->meta.u.callback &&
2323 !cmd->meta.u.callback(priv, cmd, rxb->skb))
2324 rxb->skb = NULL;
2325
Tomas Winkler91c066f2008-03-06 17:36:55 -08002326 iwl3945_cmd_queue_reclaim(priv, txq_id, index);
Zhu Yib481de92007-09-25 17:54:57 -07002327
2328 if (!(cmd->meta.flags & CMD_ASYNC)) {
2329 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
2330 wake_up_interruptible(&priv->wait_command_queue);
2331 }
2332}
2333
2334/************************** RX-FUNCTIONS ****************************/
2335/*
2336 * Rx theory of operation
2337 *
2338 * The host allocates 32 DMA target addresses and passes the host address
2339 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
2340 * 0 to 31
2341 *
2342 * Rx Queue Indexes
2343 * The host/firmware share two index registers for managing the Rx buffers.
2344 *
2345 * The READ index maps to the first position that the firmware may be writing
2346 * to -- the driver can read up to (but not including) this position and get
2347 * good data.
2348 * The READ index is managed by the firmware once the card is enabled.
2349 *
2350 * The WRITE index maps to the last position the driver has read from -- the
2351 * position preceding WRITE is the last slot the firmware can place a packet.
2352 *
2353 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
2354 * WRITE = READ.
2355 *
Ben Cahill9fbab512007-11-29 11:09:47 +08002356 * During initialization, the host sets up the READ queue position to the first
Zhu Yib481de92007-09-25 17:54:57 -07002357 * INDEX position, and WRITE to the last (READ - 1 wrapped)
2358 *
Ben Cahill9fbab512007-11-29 11:09:47 +08002359 * When the firmware places a packet in a buffer, it will advance the READ index
Zhu Yib481de92007-09-25 17:54:57 -07002360 * and fire the RX interrupt. The driver can then query the READ index and
2361 * process as many packets as possible, moving the WRITE index forward as it
2362 * resets the Rx queue buffers with new memory.
2363 *
2364 * The management in the driver is as follows:
2365 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
2366 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Ian Schram01ebd062007-10-25 17:15:22 +08002367 * to replenish the iwl->rxq->rx_free.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002368 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
Zhu Yib481de92007-09-25 17:54:57 -07002369 * iwl->rxq is replenished and the READ INDEX is updated (updating the
2370 * 'processed' and 'read' driver indexes as well)
2371 * + A received packet is processed and handed to the kernel network stack,
2372 * detached from the iwl->rxq. The driver 'processed' index is updated.
2373 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
2374 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
2375 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
2376 * were enough free buffers and RX_STALLED is set it is cleared.
2377 *
2378 *
2379 * Driver sequence:
2380 *
Ben Cahill9fbab512007-11-29 11:09:47 +08002381 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002382 * iwl3945_rx_queue_restock
Ben Cahill9fbab512007-11-29 11:09:47 +08002383 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
Zhu Yib481de92007-09-25 17:54:57 -07002384 * queue, updates firmware pointers, and updates
2385 * the WRITE index. If insufficient rx_free buffers
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002386 * are available, schedules iwl3945_rx_replenish
Zhu Yib481de92007-09-25 17:54:57 -07002387 *
2388 * -- enable interrupts --
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002389 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
Zhu Yib481de92007-09-25 17:54:57 -07002390 * READ INDEX, detaching the SKB from the pool.
2391 * Moves the packet buffer from queue to rx_used.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002392 * Calls iwl3945_rx_queue_restock to refill any empty
Zhu Yib481de92007-09-25 17:54:57 -07002393 * slots.
2394 * ...
2395 *
2396 */
2397
2398/**
Ben Cahill9fbab512007-11-29 11:09:47 +08002399 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
Zhu Yib481de92007-09-25 17:54:57 -07002400 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002401static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07002402 dma_addr_t dma_addr)
2403{
2404 return cpu_to_le32((u32)dma_addr);
2405}
2406
2407/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002408 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
Zhu Yib481de92007-09-25 17:54:57 -07002409 *
Ben Cahill9fbab512007-11-29 11:09:47 +08002410 * If there are slots in the RX queue that need to be restocked,
Zhu Yib481de92007-09-25 17:54:57 -07002411 * and we have free pre-allocated buffers, fill the ranks as much
Ben Cahill9fbab512007-11-29 11:09:47 +08002412 * as we can, pulling from rx_free.
Zhu Yib481de92007-09-25 17:54:57 -07002413 *
2414 * This moves the 'write' index forward to catch up with 'processed', and
2415 * also updates the memory address in the firmware to reference the new
2416 * target buffer.
2417 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002418static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002419{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08002420 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07002421 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002422 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07002423 unsigned long flags;
2424 int write, rc;
2425
2426 spin_lock_irqsave(&rxq->lock, flags);
2427 write = rxq->write & ~0x7;
Winkler, Tomas37d68312009-01-08 10:19:54 -08002428 while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002429 /* Get next free Rx buffer, remove from free list */
Zhu Yib481de92007-09-25 17:54:57 -07002430 element = rxq->rx_free.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002431 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Zhu Yib481de92007-09-25 17:54:57 -07002432 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002433
2434 /* Point to Rx buffer via next RBD in circular buffer */
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002435 rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr);
Zhu Yib481de92007-09-25 17:54:57 -07002436 rxq->queue[rxq->write] = rxb;
2437 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
2438 rxq->free_count--;
2439 }
2440 spin_unlock_irqrestore(&rxq->lock, flags);
2441 /* If the pre-allocated buffer pool is dropping low, schedule to
2442 * refill it */
2443 if (rxq->free_count <= RX_LOW_WATERMARK)
2444 queue_work(priv->workqueue, &priv->rx_replenish);
2445
2446
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002447 /* If we've added more space for the firmware to place data, tell it.
2448 * Increment device's write pointer in multiples of 8. */
Zhu Yib481de92007-09-25 17:54:57 -07002449 if ((write != (rxq->write & ~0x7))
2450 || (abs(rxq->write - rxq->read) > 7)) {
2451 spin_lock_irqsave(&rxq->lock, flags);
2452 rxq->need_update = 1;
2453 spin_unlock_irqrestore(&rxq->lock, flags);
Winkler, Tomas141c43a2009-01-08 10:19:53 -08002454 rc = iwl_rx_queue_update_write_ptr(priv, rxq);
Zhu Yib481de92007-09-25 17:54:57 -07002455 if (rc)
2456 return rc;
2457 }
2458
2459 return 0;
2460}
2461
2462/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002463 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
Zhu Yib481de92007-09-25 17:54:57 -07002464 *
2465 * When moving to rx_free an SKB is allocated for the slot.
2466 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002467 * Also restock the Rx queue via iwl3945_rx_queue_restock.
Ian Schram01ebd062007-10-25 17:15:22 +08002468 * This is called as a scheduled work item (except for during initialization)
Zhu Yib481de92007-09-25 17:54:57 -07002469 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002470static void iwl3945_rx_allocate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002471{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08002472 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07002473 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002474 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07002475 unsigned long flags;
2476 spin_lock_irqsave(&rxq->lock, flags);
2477 while (!list_empty(&rxq->rx_used)) {
2478 element = rxq->rx_used.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002479 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002480
2481 /* Alloc a new receive buffer */
Zhu Yib481de92007-09-25 17:54:57 -07002482 rxb->skb =
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08002483 alloc_skb(priv->hw_params.rx_buf_size,
2484 __GFP_NOWARN | GFP_ATOMIC);
Zhu Yib481de92007-09-25 17:54:57 -07002485 if (!rxb->skb) {
2486 if (net_ratelimit())
Tomas Winkler978785a2008-12-19 10:37:31 +08002487 IWL_CRIT(priv, ": Can not allocate SKB buffers\n");
Zhu Yib481de92007-09-25 17:54:57 -07002488 /* We don't reschedule replenish work here -- we will
2489 * call the restock method and if it still needs
2490 * more buffers it will schedule replenish */
2491 break;
2492 }
Zhu Yi12342c42007-12-20 11:27:32 +08002493
2494 /* If radiotap head is required, reserve some headroom here.
2495 * The physical head count is a variable rx_stats->phy_count.
2496 * We reserve 4 bytes here. Plus these extra bytes, the
2497 * headroom of the physical head should be enough for the
2498 * radiotap head that iwl3945 supported. See iwl3945_rt.
2499 */
2500 skb_reserve(rxb->skb, 4);
2501
Zhu Yib481de92007-09-25 17:54:57 -07002502 priv->alloc_rxb_skb++;
2503 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002504
2505 /* Get physical address of RB/SKB */
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08002506 rxb->real_dma_addr = pci_map_single(priv->pci_dev,
2507 rxb->skb->data,
2508 priv->hw_params.rx_buf_size,
2509 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07002510 list_add_tail(&rxb->list, &rxq->rx_free);
2511 rxq->free_count++;
2512 }
2513 spin_unlock_irqrestore(&rxq->lock, flags);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002514}
2515
2516/*
2517 * this should be called while priv->lock is locked
2518 */
Tomas Winkler4fd1f842007-12-05 20:59:58 +02002519static void __iwl3945_rx_replenish(void *data)
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002520{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002521 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002522
2523 iwl3945_rx_allocate(priv);
2524 iwl3945_rx_queue_restock(priv);
2525}
2526
2527
2528void iwl3945_rx_replenish(void *data)
2529{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002530 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002531 unsigned long flags;
2532
2533 iwl3945_rx_allocate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002534
2535 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002536 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002537 spin_unlock_irqrestore(&priv->lock, flags);
2538}
2539
Zhu Yib481de92007-09-25 17:54:57 -07002540/* Convert linear signal-to-noise ratio into dB */
2541static u8 ratio2dB[100] = {
2542/* 0 1 2 3 4 5 6 7 8 9 */
2543 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
2544 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
2545 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
2546 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
2547 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
2548 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
2549 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
2550 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
2551 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
2552 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
2553};
2554
2555/* Calculates a relative dB value from a ratio of linear
2556 * (i.e. not dB) signal levels.
2557 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002558int iwl3945_calc_db_from_ratio(int sig_ratio)
Zhu Yib481de92007-09-25 17:54:57 -07002559{
Adrian Bunk221c80c2008-02-02 23:19:01 +02002560 /* 1000:1 or higher just report as 60 dB */
2561 if (sig_ratio >= 1000)
Zhu Yib481de92007-09-25 17:54:57 -07002562 return 60;
2563
Adrian Bunk221c80c2008-02-02 23:19:01 +02002564 /* 100:1 or higher, divide by 10 and use table,
Zhu Yib481de92007-09-25 17:54:57 -07002565 * add 20 dB to make up for divide by 10 */
Adrian Bunk221c80c2008-02-02 23:19:01 +02002566 if (sig_ratio >= 100)
Tomas Winkler3ac7f142008-07-21 02:40:14 +03002567 return 20 + (int)ratio2dB[sig_ratio/10];
Zhu Yib481de92007-09-25 17:54:57 -07002568
2569 /* We shouldn't see this */
2570 if (sig_ratio < 1)
2571 return 0;
2572
2573 /* Use table for ratios 1:1 - 99:1 */
2574 return (int)ratio2dB[sig_ratio];
2575}
2576
2577#define PERFECT_RSSI (-20) /* dBm */
2578#define WORST_RSSI (-95) /* dBm */
2579#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
2580
2581/* Calculate an indication of rx signal quality (a percentage, not dBm!).
2582 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
2583 * about formulas used below. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002584int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
Zhu Yib481de92007-09-25 17:54:57 -07002585{
2586 int sig_qual;
2587 int degradation = PERFECT_RSSI - rssi_dbm;
2588
2589 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
2590 * as indicator; formula is (signal dbm - noise dbm).
2591 * SNR at or above 40 is a great signal (100%).
2592 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
2593 * Weakest usable signal is usually 10 - 15 dB SNR. */
2594 if (noise_dbm) {
2595 if (rssi_dbm - noise_dbm >= 40)
2596 return 100;
2597 else if (rssi_dbm < noise_dbm)
2598 return 0;
2599 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
2600
2601 /* Else use just the signal level.
2602 * This formula is a least squares fit of data points collected and
2603 * compared with a reference system that had a percentage (%) display
2604 * for signal quality. */
2605 } else
2606 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
2607 (15 * RSSI_RANGE + 62 * degradation)) /
2608 (RSSI_RANGE * RSSI_RANGE);
2609
2610 if (sig_qual > 100)
2611 sig_qual = 100;
2612 else if (sig_qual < 1)
2613 sig_qual = 0;
2614
2615 return sig_qual;
2616}
2617
2618/**
Ben Cahill9fbab512007-11-29 11:09:47 +08002619 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07002620 *
2621 * Uses the priv->rx_handlers callback function array to invoke
2622 * the appropriate handlers, including command responses,
2623 * frame-received notifications, and other notifications.
2624 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002625static void iwl3945_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002626{
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002627 struct iwl_rx_mem_buffer *rxb;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002628 struct iwl_rx_packet *pkt;
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08002629 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07002630 u32 r, i;
2631 int reclaim;
2632 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002633 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08002634 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07002635
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002636 /* uCode's read index (stored in shared DRAM) indicates the last Rx
2637 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8cd812b2008-12-19 10:37:43 +08002638 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -07002639 i = rxq->read;
2640
Winkler, Tomas37d68312009-01-08 10:19:54 -08002641 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002642 fill_rx = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002643 /* Rx interrupt, but nothing sent from uCode */
2644 if (i == r)
2645 IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
2646
2647 while (i != r) {
2648 rxb = rxq->queue[i];
2649
Ben Cahill9fbab512007-11-29 11:09:47 +08002650 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07002651 * then a bug has been introduced in the queue refilling
2652 * routines -- catch it here */
2653 BUG_ON(rxb == NULL);
2654
2655 rxq->queue[i] = NULL;
2656
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002657 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08002658 priv->hw_params.rx_buf_size,
Zhu Yib481de92007-09-25 17:54:57 -07002659 PCI_DMA_FROMDEVICE);
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002660 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002661
2662 /* Reclaim a command buffer only if this packet is a response
2663 * to a (driver-originated) command.
2664 * If the packet (e.g. Rx frame) originated from uCode,
2665 * there is no command buffer to reclaim.
2666 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
2667 * but apparently a few don't get set; catch them here. */
2668 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
2669 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
2670 (pkt->hdr.cmd != REPLY_TX);
2671
2672 /* Based on type of command response or notification,
2673 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002674 * rx_handlers table. See iwl3945_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07002675 if (priv->rx_handlers[pkt->hdr.cmd]) {
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002676 IWL_DEBUG(IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07002677 "r = %d, i = %d, %s, 0x%02x\n", r, i,
2678 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
2679 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
2680 } else {
2681 /* No handling needed */
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002682 IWL_DEBUG(IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07002683 "r %d i %d No handler needed for %s, 0x%02x\n",
2684 r, i, get_cmd_string(pkt->hdr.cmd),
2685 pkt->hdr.cmd);
2686 }
2687
2688 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08002689 /* Invoke any callbacks, transfer the skb to caller, and
Samuel Ortiz518099a2009-01-19 15:30:27 -08002690 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07002691 * as we reclaim the driver command queue */
2692 if (rxb && rxb->skb)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002693 iwl3945_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07002694 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002695 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07002696 }
2697
2698 /* For now we just don't re-use anything. We can tweak this
2699 * later to try and re-use notification packets and SKBs that
2700 * fail to Rx correctly */
2701 if (rxb->skb != NULL) {
2702 priv->alloc_rxb_skb--;
2703 dev_kfree_skb_any(rxb->skb);
2704 rxb->skb = NULL;
2705 }
2706
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002707 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08002708 priv->hw_params.rx_buf_size,
2709 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07002710 spin_lock_irqsave(&rxq->lock, flags);
2711 list_add_tail(&rxb->list, &priv->rxq.rx_used);
2712 spin_unlock_irqrestore(&rxq->lock, flags);
2713 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002714 /* If there are a lot of unused frames,
2715 * restock the Rx queue so ucode won't assert. */
2716 if (fill_rx) {
2717 count++;
2718 if (count >= 8) {
2719 priv->rxq.read = i;
2720 __iwl3945_rx_replenish(priv);
2721 count = 0;
2722 }
2723 }
Zhu Yib481de92007-09-25 17:54:57 -07002724 }
2725
2726 /* Backtrack one entry */
2727 priv->rxq.read = i;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002728 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002729}
2730
Samuel Ortizd08853a2009-01-23 13:45:17 -08002731#ifdef CONFIG_IWLWIFI_DEBUG
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002732static void iwl3945_print_rx_config_cmd(struct iwl_priv *priv,
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002733 struct iwl3945_rxon_cmd *rxon)
Zhu Yib481de92007-09-25 17:54:57 -07002734{
2735 IWL_DEBUG_RADIO("RX CONFIG:\n");
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002736 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
Zhu Yib481de92007-09-25 17:54:57 -07002737 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
2738 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
2739 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
2740 le32_to_cpu(rxon->filter_flags));
2741 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
2742 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
2743 rxon->ofdm_basic_rates);
2744 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
Johannes Berge1749612008-10-27 15:59:26 -07002745 IWL_DEBUG_RADIO("u8[6] node_addr: %pM\n", rxon->node_addr);
2746 IWL_DEBUG_RADIO("u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07002747 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
2748}
2749#endif
2750
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002751static void iwl3945_enable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002752{
2753 IWL_DEBUG_ISR("Enabling interrupts\n");
2754 set_bit(STATUS_INT_ENABLED, &priv->status);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002755 iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07002756}
2757
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002758
2759/* call this function to flush any scheduled tasklet */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002760static inline void iwl_synchronize_irq(struct iwl_priv *priv)
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002761{
Tomas Winklera96a27f2008-10-23 23:48:56 -07002762 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002763 synchronize_irq(priv->pci_dev->irq);
2764 tasklet_kill(&priv->irq_tasklet);
2765}
2766
2767
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002768static inline void iwl3945_disable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002769{
2770 clear_bit(STATUS_INT_ENABLED, &priv->status);
2771
2772 /* disable interrupts from uCode/NIC to host */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002773 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07002774
2775 /* acknowledge/clear/reset any interrupts still pending
2776 * from uCode or flow handler (Rx/Tx DMA) */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002777 iwl_write32(priv, CSR_INT, 0xffffffff);
2778 iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
Zhu Yib481de92007-09-25 17:54:57 -07002779 IWL_DEBUG_ISR("Disabled interrupts\n");
2780}
2781
2782static const char *desc_lookup(int i)
2783{
2784 switch (i) {
2785 case 1:
2786 return "FAIL";
2787 case 2:
2788 return "BAD_PARAM";
2789 case 3:
2790 return "BAD_CHECKSUM";
2791 case 4:
2792 return "NMI_INTERRUPT";
2793 case 5:
2794 return "SYSASSERT";
2795 case 6:
2796 return "FATAL_ERROR";
2797 }
2798
2799 return "UNKNOWN";
2800}
2801
2802#define ERROR_START_OFFSET (1 * sizeof(u32))
2803#define ERROR_ELEM_SIZE (7 * sizeof(u32))
2804
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002805static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002806{
2807 u32 i;
2808 u32 desc, time, count, base, data1;
2809 u32 blink1, blink2, ilink1, ilink2;
2810 int rc;
2811
2812 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
2813
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002814 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002815 IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07002816 return;
2817 }
2818
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002819 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002820 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002821 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002822 return;
2823 }
2824
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002825 count = iwl_read_targ_mem(priv, base);
Zhu Yib481de92007-09-25 17:54:57 -07002826
2827 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002828 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
2829 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
2830 priv->status, count);
Zhu Yib481de92007-09-25 17:54:57 -07002831 }
2832
Winkler, Tomas15b16872008-12-19 10:37:33 +08002833 IWL_ERR(priv, "Desc Time asrtPC blink2 "
Zhu Yib481de92007-09-25 17:54:57 -07002834 "ilink1 nmiPC Line\n");
2835 for (i = ERROR_START_OFFSET;
2836 i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
2837 i += ERROR_ELEM_SIZE) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002838 desc = iwl_read_targ_mem(priv, base + i);
Zhu Yib481de92007-09-25 17:54:57 -07002839 time =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002840 iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002841 blink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002842 iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002843 blink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002844 iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002845 ilink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002846 iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002847 ilink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002848 iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002849 data1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002850 iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002851
Winkler, Tomas15b16872008-12-19 10:37:33 +08002852 IWL_ERR(priv,
2853 "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
2854 desc_lookup(desc), desc, time, blink1, blink2,
2855 ilink1, ilink2, data1);
Zhu Yib481de92007-09-25 17:54:57 -07002856 }
2857
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002858 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002859
2860}
2861
Ben Cahillf58177b2007-11-29 11:09:43 +08002862#define EVENT_START_OFFSET (6 * sizeof(u32))
Zhu Yib481de92007-09-25 17:54:57 -07002863
2864/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002865 * iwl3945_print_event_log - Dump error event log to syslog
Zhu Yib481de92007-09-25 17:54:57 -07002866 *
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002867 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
Zhu Yib481de92007-09-25 17:54:57 -07002868 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002869static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
Zhu Yib481de92007-09-25 17:54:57 -07002870 u32 num_events, u32 mode)
2871{
2872 u32 i;
2873 u32 base; /* SRAM byte address of event log header */
2874 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
2875 u32 ptr; /* SRAM byte address of log data */
2876 u32 ev, time, data; /* event log data */
2877
2878 if (num_events == 0)
2879 return;
2880
2881 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
2882
2883 if (mode == 0)
2884 event_size = 2 * sizeof(u32);
2885 else
2886 event_size = 3 * sizeof(u32);
2887
2888 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
2889
2890 /* "time" is actually "data" for mode 0 (no timestamp).
2891 * place event id # at far right for easier visual parsing. */
2892 for (i = 0; i < num_events; i++) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002893 ev = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002894 ptr += sizeof(u32);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002895 time = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002896 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08002897 if (mode == 0) {
2898 /* data, ev */
2899 IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
2900 } else {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002901 data = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002902 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08002903 IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev);
Zhu Yib481de92007-09-25 17:54:57 -07002904 }
2905 }
2906}
2907
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002908static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002909{
2910 int rc;
2911 u32 base; /* SRAM byte address of event log header */
2912 u32 capacity; /* event log capacity in # entries */
2913 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
2914 u32 num_wraps; /* # times uCode wrapped to top of log */
2915 u32 next_entry; /* index of next entry to be written by uCode */
2916 u32 size; /* # entries that we'll print */
2917
2918 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002919 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002920 IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07002921 return;
2922 }
2923
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002924 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002925 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002926 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002927 return;
2928 }
2929
2930 /* event log header */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002931 capacity = iwl_read_targ_mem(priv, base);
2932 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
2933 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
2934 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
Zhu Yib481de92007-09-25 17:54:57 -07002935
2936 size = num_wraps ? capacity : next_entry;
2937
2938 /* bail out if nothing in log */
2939 if (size == 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002940 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002941 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002942 return;
2943 }
2944
Winkler, Tomas15b16872008-12-19 10:37:33 +08002945 IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07002946 size, num_wraps);
2947
2948 /* if uCode has wrapped back to top of log, start at the oldest entry,
2949 * i.e the next one that uCode would fill. */
2950 if (num_wraps)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002951 iwl3945_print_event_log(priv, next_entry,
Zhu Yib481de92007-09-25 17:54:57 -07002952 capacity - next_entry, mode);
2953
2954 /* (then/else) start at top of log */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002955 iwl3945_print_event_log(priv, 0, next_entry, mode);
Zhu Yib481de92007-09-25 17:54:57 -07002956
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002957 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002958}
2959
2960/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002961 * iwl3945_irq_handle_error - called for HW or SW error interrupt from card
Zhu Yib481de92007-09-25 17:54:57 -07002962 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002963static void iwl3945_irq_handle_error(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002964{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002965 /* Set the FW error flag -- cleared on iwl3945_down */
Zhu Yib481de92007-09-25 17:54:57 -07002966 set_bit(STATUS_FW_ERROR, &priv->status);
2967
2968 /* Cancel currently queued command. */
2969 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
2970
Samuel Ortizd08853a2009-01-23 13:45:17 -08002971#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002972 if (priv->debug_level & IWL_DL_FW_ERRORS) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002973 iwl3945_dump_nic_error_log(priv);
2974 iwl3945_dump_nic_event_log(priv);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08002975 iwl3945_print_rx_config_cmd(priv, &priv->staging39_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07002976 }
2977#endif
2978
2979 wake_up_interruptible(&priv->wait_command_queue);
2980
2981 /* Keep the restart process from trying to send host
2982 * commands by clearing the INIT status bit */
2983 clear_bit(STATUS_READY, &priv->status);
2984
2985 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
2986 IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS,
2987 "Restarting adapter due to uCode error.\n");
2988
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002989 if (iwl3945_is_associated(priv)) {
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08002990 memcpy(&priv->recovery39_rxon, &priv->active39_rxon,
2991 sizeof(priv->recovery39_rxon));
Zhu Yib481de92007-09-25 17:54:57 -07002992 priv->error_recovering = 1;
2993 }
Samuel Ortizaf48d042009-01-23 13:45:19 -08002994 if (priv->cfg->mod_params->restart_fw)
2995 queue_work(priv->workqueue, &priv->restart);
Zhu Yib481de92007-09-25 17:54:57 -07002996 }
2997}
2998
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002999static void iwl3945_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003000{
3001 unsigned long flags;
3002
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08003003 memcpy(&priv->staging39_rxon, &priv->recovery39_rxon,
3004 sizeof(priv->staging39_rxon));
3005 priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003006 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003007
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003008 iwl3945_add_station(priv, priv->bssid, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003009
3010 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08003011 priv->assoc_id = le16_to_cpu(priv->staging39_rxon.assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003012 priv->error_recovering = 0;
3013 spin_unlock_irqrestore(&priv->lock, flags);
3014}
3015
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003016static void iwl3945_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003017{
3018 u32 inta, handled = 0;
3019 u32 inta_fh;
3020 unsigned long flags;
Samuel Ortizd08853a2009-01-23 13:45:17 -08003021#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07003022 u32 inta_mask;
3023#endif
3024
3025 spin_lock_irqsave(&priv->lock, flags);
3026
3027 /* Ack/clear/reset pending uCode interrupts.
3028 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
3029 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003030 inta = iwl_read32(priv, CSR_INT);
3031 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07003032
3033 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
3034 * Any new interrupts that happen after this, either while we're
3035 * in this tasklet, or later, will show up in next ISR/tasklet. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003036 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
3037 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07003038
Samuel Ortizd08853a2009-01-23 13:45:17 -08003039#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003040 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08003041 /* just for debug */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003042 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07003043 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
3044 inta, inta_mask, inta_fh);
3045 }
3046#endif
3047
3048 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
3049 * atomic, make sure that inta covers all the interrupts that
3050 * we've discovered, even if FH interrupt came in just after
3051 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08003052 if (inta_fh & CSR39_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07003053 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08003054 if (inta_fh & CSR39_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07003055 inta |= CSR_INT_BIT_FH_TX;
3056
3057 /* Now service all interrupt bits discovered above. */
3058 if (inta & CSR_INT_BIT_HW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003059 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003060
3061 /* Tell the device to stop sending interrupts */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003062 iwl3945_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003063
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003064 iwl3945_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003065
3066 handled |= CSR_INT_BIT_HW_ERR;
3067
3068 spin_unlock_irqrestore(&priv->lock, flags);
3069
3070 return;
3071 }
3072
Samuel Ortizd08853a2009-01-23 13:45:17 -08003073#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003074 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07003075 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08003076 if (inta & CSR_INT_BIT_SCD)
3077 IWL_DEBUG_ISR("Scheduler finished to transmit "
3078 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003079
3080 /* Alive notification via Rx interrupt will do the real work */
3081 if (inta & CSR_INT_BIT_ALIVE)
3082 IWL_DEBUG_ISR("Alive interrupt\n");
3083 }
3084#endif
3085 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08003086 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07003087
Zhu Yib481de92007-09-25 17:54:57 -07003088 /* Error detected by uCode */
3089 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003090 IWL_ERR(priv, "Microcode SW error detected. "
3091 "Restarting 0x%X.\n", inta);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003092 iwl3945_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003093 handled |= CSR_INT_BIT_SW_ERR;
3094 }
3095
3096 /* uCode wakes up after power-down sleep */
3097 if (inta & CSR_INT_BIT_WAKEUP) {
3098 IWL_DEBUG_ISR("Wakeup interrupt\n");
Winkler, Tomas141c43a2009-01-08 10:19:53 -08003099 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08003100 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
3101 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
3102 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
3103 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
3104 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
3105 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07003106
3107 handled |= CSR_INT_BIT_WAKEUP;
3108 }
3109
3110 /* All uCode command responses, including Tx command responses,
3111 * Rx "responses" (frame-received notification), and other
3112 * notifications from uCode come through here*/
3113 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003114 iwl3945_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003115 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
3116 }
3117
3118 if (inta & CSR_INT_BIT_FH_TX) {
3119 IWL_DEBUG_ISR("Tx interrupt\n");
3120
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003121 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
3122 if (!iwl_grab_nic_access(priv)) {
3123 iwl_write_direct32(priv, FH39_TCSR_CREDIT
Tomas Winklerbddadf82008-12-19 10:37:01 +08003124 (FH39_SRVC_CHNL), 0x0);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003125 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003126 }
3127 handled |= CSR_INT_BIT_FH_TX;
3128 }
3129
3130 if (inta & ~handled)
Winkler, Tomas15b16872008-12-19 10:37:33 +08003131 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Zhu Yib481de92007-09-25 17:54:57 -07003132
3133 if (inta & ~CSR_INI_SET_MASK) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003134 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Zhu Yib481de92007-09-25 17:54:57 -07003135 inta & ~CSR_INI_SET_MASK);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003136 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07003137 }
3138
3139 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003140 /* only Re-enable if disabled by irq */
3141 if (test_bit(STATUS_INT_ENABLED, &priv->status))
3142 iwl3945_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003143
Samuel Ortizd08853a2009-01-23 13:45:17 -08003144#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003145 if (priv->debug_level & (IWL_DL_ISR)) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003146 inta = iwl_read32(priv, CSR_INT);
3147 inta_mask = iwl_read32(priv, CSR_INT_MASK);
3148 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07003149 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
3150 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
3151 }
3152#endif
3153 spin_unlock_irqrestore(&priv->lock, flags);
3154}
3155
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003156static irqreturn_t iwl3945_isr(int irq, void *data)
Zhu Yib481de92007-09-25 17:54:57 -07003157{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003158 struct iwl_priv *priv = data;
Zhu Yib481de92007-09-25 17:54:57 -07003159 u32 inta, inta_mask;
3160 u32 inta_fh;
3161 if (!priv)
3162 return IRQ_NONE;
3163
3164 spin_lock(&priv->lock);
3165
3166 /* Disable (but don't clear!) interrupts here to avoid
3167 * back-to-back ISRs and sporadic interrupts from our NIC.
3168 * If we have something to service, the tasklet will re-enable ints.
3169 * If we *don't* have something, we'll re-enable before leaving here. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003170 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
3171 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07003172
3173 /* Discover which interrupts are active/pending */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003174 inta = iwl_read32(priv, CSR_INT);
3175 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07003176
3177 /* Ignore interrupt if there's nothing in NIC to service.
3178 * This may be due to IRQ shared with another device,
3179 * or due to sporadic interrupts thrown from our NIC. */
3180 if (!inta && !inta_fh) {
3181 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
3182 goto none;
3183 }
3184
3185 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
3186 /* Hardware disappeared */
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003187 IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
Oliver Neukumcb4da1a2007-11-13 21:10:32 -08003188 goto unplugged;
Zhu Yib481de92007-09-25 17:54:57 -07003189 }
3190
3191 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
3192 inta, inta_mask, inta_fh);
3193
Joonwoo Park25c03d82008-01-23 10:15:20 -08003194 inta &= ~CSR_INT_BIT_SCD;
3195
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003196 /* iwl3945_irq_tasklet() will service interrupts and re-enable them */
Joonwoo Park25c03d82008-01-23 10:15:20 -08003197 if (likely(inta || inta_fh))
3198 tasklet_schedule(&priv->irq_tasklet);
Oliver Neukumcb4da1a2007-11-13 21:10:32 -08003199unplugged:
Zhu Yib481de92007-09-25 17:54:57 -07003200 spin_unlock(&priv->lock);
3201
3202 return IRQ_HANDLED;
3203
3204 none:
3205 /* re-enable interrupts here since we don't have anything to service. */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003206 /* only Re-enable if disabled by irq */
3207 if (test_bit(STATUS_INT_ENABLED, &priv->status))
3208 iwl3945_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003209 spin_unlock(&priv->lock);
3210 return IRQ_NONE;
3211}
3212
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003213static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01003214 enum ieee80211_band band,
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003215 u8 is_active, u8 n_probes,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003216 struct iwl3945_scan_channel *scan_ch)
Zhu Yib481de92007-09-25 17:54:57 -07003217{
3218 const struct ieee80211_channel *channels = NULL;
Johannes Berg8318d782008-01-24 19:38:38 +01003219 const struct ieee80211_supported_band *sband;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08003220 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07003221 u16 passive_dwell = 0;
3222 u16 active_dwell = 0;
3223 int added, i;
3224
Kolekar, Abhijeetcbba18c2008-12-19 10:37:42 +08003225 sband = iwl_get_hw_mode(priv, band);
Johannes Berg8318d782008-01-24 19:38:38 +01003226 if (!sband)
Zhu Yib481de92007-09-25 17:54:57 -07003227 return 0;
3228
Johannes Berg8318d782008-01-24 19:38:38 +01003229 channels = sband->channels;
Zhu Yib481de92007-09-25 17:54:57 -07003230
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08003231 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
3232 passive_dwell = iwl_get_passive_dwell_time(priv, band);
Zhu Yib481de92007-09-25 17:54:57 -07003233
Abhijeet Kolekar8f4807a2008-09-03 11:26:31 +08003234 if (passive_dwell <= active_dwell)
3235 passive_dwell = active_dwell + 1;
3236
Johannes Berg8318d782008-01-24 19:38:38 +01003237 for (i = 0, added = 0; i < sband->n_channels; i++) {
Johannes Berg182e2e62008-04-04 10:41:56 +02003238 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
3239 continue;
3240
Johannes Berg8318d782008-01-24 19:38:38 +01003241 scan_ch->channel = channels[i].hw_value;
Zhu Yib481de92007-09-25 17:54:57 -07003242
Samuel Ortize6148912009-01-23 13:45:15 -08003243 ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
Zhu Yib481de92007-09-25 17:54:57 -07003244 if (!is_channel_valid(ch_info)) {
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003245 IWL_DEBUG_SCAN("Channel %d is INVALID for this band.\n",
Zhu Yib481de92007-09-25 17:54:57 -07003246 scan_ch->channel);
3247 continue;
3248 }
3249
Zhu Yib481de92007-09-25 17:54:57 -07003250 scan_ch->active_dwell = cpu_to_le16(active_dwell);
3251 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08003252 /* If passive , set up for auto-switch
3253 * and use long active_dwell time.
3254 */
3255 if (!is_active || is_channel_passive(ch_info) ||
3256 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
3257 scan_ch->type = 0; /* passive */
3258 if (IWL_UCODE_API(priv->ucode_ver) == 1)
3259 scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
3260 } else {
3261 scan_ch->type = 1; /* active */
3262 }
3263
3264 /* Set direct probe bits. These may be used both for active
3265 * scan channels (probes gets sent right away),
3266 * or for passive channels (probes get se sent only after
3267 * hearing clear Rx packet).*/
3268 if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
3269 if (n_probes)
3270 scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes);
3271 } else {
3272 /* uCode v1 does not allow setting direct probe bits on
3273 * passive channel. */
3274 if ((scan_ch->type & 1) && n_probes)
3275 scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes);
3276 }
Zhu Yib481de92007-09-25 17:54:57 -07003277
Ben Cahill9fbab512007-11-29 11:09:47 +08003278 /* Set txpower levels to defaults */
Zhu Yib481de92007-09-25 17:54:57 -07003279 scan_ch->tpc.dsp_atten = 110;
3280 /* scan_pwr_info->tpc.dsp_atten; */
3281
3282 /*scan_pwr_info->tpc.tx_gain; */
Johannes Berg8318d782008-01-24 19:38:38 +01003283 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -07003284 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
3285 else {
3286 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
3287 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
Ben Cahill9fbab512007-11-29 11:09:47 +08003288 * power level:
Reinette Chatre8a1b0242008-01-14 17:46:25 -08003289 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
Zhu Yib481de92007-09-25 17:54:57 -07003290 */
3291 }
3292
3293 IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
3294 scan_ch->channel,
3295 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
3296 (scan_ch->type & 1) ?
3297 active_dwell : passive_dwell);
3298
3299 scan_ch++;
3300 added++;
3301 }
3302
3303 IWL_DEBUG_SCAN("total channels to scan %d \n", added);
3304 return added;
3305}
3306
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003307static void iwl3945_init_hw_rates(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07003308 struct ieee80211_rate *rates)
3309{
3310 int i;
3311
3312 for (i = 0; i < IWL_RATE_COUNT; i++) {
Johannes Berg8318d782008-01-24 19:38:38 +01003313 rates[i].bitrate = iwl3945_rates[i].ieee * 5;
3314 rates[i].hw_value = i; /* Rate scaling will work on indexes */
3315 rates[i].hw_value_short = i;
3316 rates[i].flags = 0;
Samuel Ortizd9829a62008-12-19 10:37:12 +08003317 if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
Zhu Yib481de92007-09-25 17:54:57 -07003318 /*
Johannes Berg8318d782008-01-24 19:38:38 +01003319 * If CCK != 1M then set short preamble rate flag.
Zhu Yib481de92007-09-25 17:54:57 -07003320 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003321 rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
Johannes Berg8318d782008-01-24 19:38:38 +01003322 0 : IEEE80211_RATE_SHORT_PREAMBLE;
Zhu Yib481de92007-09-25 17:54:57 -07003323 }
Zhu Yib481de92007-09-25 17:54:57 -07003324 }
3325}
3326
Zhu Yib481de92007-09-25 17:54:57 -07003327/******************************************************************************
3328 *
3329 * uCode download functions
3330 *
3331 ******************************************************************************/
3332
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003333static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003334{
Tomas Winkler98c92212008-01-14 17:46:20 -08003335 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
3336 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
3337 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
3338 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
3339 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
3340 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07003341}
3342
3343/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003344 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07003345 * looking at all data.
3346 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003347static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07003348{
3349 u32 val;
3350 u32 save_len = len;
3351 int rc = 0;
3352 u32 errcnt;
3353
3354 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
3355
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003356 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003357 if (rc)
3358 return rc;
3359
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003360 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08003361 IWL39_RTC_INST_LOWER_BOUND);
Zhu Yib481de92007-09-25 17:54:57 -07003362
3363 errcnt = 0;
3364 for (; len > 0; len -= sizeof(u32), image++) {
3365 /* read data comes through single port, auto-incr addr */
3366 /* NOTE: Use the debugless read so we don't flood kernel log
3367 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003368 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07003369 if (val != le32_to_cpu(*image)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003370 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07003371 "offset 0x%x, is 0x%x, s/b 0x%x\n",
3372 save_len - len, val, le32_to_cpu(*image));
3373 rc = -EIO;
3374 errcnt++;
3375 if (errcnt >= 20)
3376 break;
3377 }
3378 }
3379
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003380 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003381
3382 if (!errcnt)
Ian Schrambc434dd2007-10-25 17:15:29 +08003383 IWL_DEBUG_INFO("ucode image in INSTRUCTION memory is good\n");
Zhu Yib481de92007-09-25 17:54:57 -07003384
3385 return rc;
3386}
3387
3388
3389/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003390 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07003391 * using sample data 100 bytes apart. If these sample points are good,
3392 * it's a pretty good bet that everything between them is good, too.
3393 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003394static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07003395{
3396 u32 val;
3397 int rc = 0;
3398 u32 errcnt = 0;
3399 u32 i;
3400
3401 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
3402
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003403 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003404 if (rc)
3405 return rc;
3406
3407 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
3408 /* read data comes through single port, auto-incr addr */
3409 /* NOTE: Use the debugless read so we don't flood kernel log
3410 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003411 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08003412 i + IWL39_RTC_INST_LOWER_BOUND);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003413 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07003414 if (val != le32_to_cpu(*image)) {
3415#if 0 /* Enable this if you want to see details */
Winkler, Tomas15b16872008-12-19 10:37:33 +08003416 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07003417 "offset 0x%x, is 0x%x, s/b 0x%x\n",
3418 i, val, *image);
3419#endif
3420 rc = -EIO;
3421 errcnt++;
3422 if (errcnt >= 3)
3423 break;
3424 }
3425 }
3426
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003427 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003428
3429 return rc;
3430}
3431
3432
3433/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003434 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
Zhu Yib481de92007-09-25 17:54:57 -07003435 * and verify its contents
3436 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003437static int iwl3945_verify_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003438{
3439 __le32 *image;
3440 u32 len;
3441 int rc = 0;
3442
3443 /* Try bootstrap */
3444 image = (__le32 *)priv->ucode_boot.v_addr;
3445 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003446 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07003447 if (rc == 0) {
3448 IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
3449 return 0;
3450 }
3451
3452 /* Try initialize */
3453 image = (__le32 *)priv->ucode_init.v_addr;
3454 len = priv->ucode_init.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003455 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07003456 if (rc == 0) {
3457 IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
3458 return 0;
3459 }
3460
3461 /* Try runtime/protocol */
3462 image = (__le32 *)priv->ucode_code.v_addr;
3463 len = priv->ucode_code.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003464 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07003465 if (rc == 0) {
3466 IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
3467 return 0;
3468 }
3469
Winkler, Tomas15b16872008-12-19 10:37:33 +08003470 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
Zhu Yib481de92007-09-25 17:54:57 -07003471
Ben Cahill9fbab512007-11-29 11:09:47 +08003472 /* Since nothing seems to match, show first several data entries in
3473 * instruction SRAM, so maybe visual inspection will give a clue.
3474 * Selection of bootstrap image (vs. other images) is arbitrary. */
Zhu Yib481de92007-09-25 17:54:57 -07003475 image = (__le32 *)priv->ucode_boot.v_addr;
3476 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003477 rc = iwl3945_verify_inst_full(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07003478
3479 return rc;
3480}
3481
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003482static void iwl3945_nic_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003483{
3484 /* Remove all resets to allow NIC to operate */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003485 iwl_write32(priv, CSR_RESET, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003486}
3487
3488/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003489 * iwl3945_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07003490 *
3491 * Copy into buffers for card to fetch via bus-mastering
3492 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003493static int iwl3945_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003494{
Kolekar, Abhijeeta78fe752008-12-19 10:37:21 +08003495 struct iwl_ucode *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08003496 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07003497 const struct firmware *ucode_raw;
3498 /* firmware file name contains uCode/driver compatibility version */
Reinette Chatrea0987a82008-12-02 12:14:06 -08003499 const char *name_pre = priv->cfg->fw_name_pre;
3500 const unsigned int api_max = priv->cfg->ucode_api_max;
3501 const unsigned int api_min = priv->cfg->ucode_api_min;
3502 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07003503 u8 *src;
3504 size_t len;
Reinette Chatrea0987a82008-12-02 12:14:06 -08003505 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
Zhu Yib481de92007-09-25 17:54:57 -07003506
3507 /* Ask kernel firmware_class module to get the boot firmware off disk.
3508 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08003509 for (index = api_max; index >= api_min; index--) {
3510 sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
3511 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
3512 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003513 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08003514 buf, ret);
3515 if (ret == -ENOENT)
3516 continue;
3517 else
3518 goto error;
3519 } else {
3520 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08003521 IWL_ERR(priv, "Loaded firmware %s, "
3522 "which is deprecated. "
3523 " Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08003524 buf, api_max);
3525 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
3526 buf, ucode_raw->size);
3527 break;
3528 }
Zhu Yib481de92007-09-25 17:54:57 -07003529 }
3530
Reinette Chatrea0987a82008-12-02 12:14:06 -08003531 if (ret < 0)
3532 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07003533
3534 /* Make sure that we got at least our header! */
3535 if (ucode_raw->size < sizeof(*ucode)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003536 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08003537 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003538 goto err_release;
3539 }
3540
3541 /* Data from ucode file: header followed by uCode images */
3542 ucode = (void *)ucode_raw->data;
3543
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08003544 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08003545 api_ver = IWL_UCODE_API(priv->ucode_ver);
Zhu Yib481de92007-09-25 17:54:57 -07003546 inst_size = le32_to_cpu(ucode->inst_size);
3547 data_size = le32_to_cpu(ucode->data_size);
3548 init_size = le32_to_cpu(ucode->init_size);
3549 init_data_size = le32_to_cpu(ucode->init_data_size);
3550 boot_size = le32_to_cpu(ucode->boot_size);
3551
Reinette Chatrea0987a82008-12-02 12:14:06 -08003552 /* api_ver should match the api version forming part of the
3553 * firmware filename ... but we don't check for that and only rely
3554 * on the API version read from firware header from here on forward */
3555
3556 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003557 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08003558 "Driver supports v%u, firmware is v%u.\n",
3559 api_max, api_ver);
3560 priv->ucode_ver = 0;
3561 ret = -EINVAL;
3562 goto err_release;
3563 }
3564 if (api_ver != api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08003565 IWL_ERR(priv, "Firmware has old API version. Expected %u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08003566 "got %u. New firmware can be obtained "
3567 "from http://www.intellinuxwireless.org.\n",
3568 api_max, api_ver);
3569
Tomas Winkler978785a2008-12-19 10:37:31 +08003570 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
3571 IWL_UCODE_MAJOR(priv->ucode_ver),
3572 IWL_UCODE_MINOR(priv->ucode_ver),
3573 IWL_UCODE_API(priv->ucode_ver),
3574 IWL_UCODE_SERIAL(priv->ucode_ver));
3575
Reinette Chatrea0987a82008-12-02 12:14:06 -08003576 IWL_DEBUG_INFO("f/w package hdr ucode version raw = 0x%x\n",
3577 priv->ucode_ver);
Ian Schrambc434dd2007-10-25 17:15:29 +08003578 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", inst_size);
3579 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", data_size);
3580 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", init_size);
3581 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", init_data_size);
3582 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", boot_size);
Zhu Yib481de92007-09-25 17:54:57 -07003583
Reinette Chatrea0987a82008-12-02 12:14:06 -08003584
Zhu Yib481de92007-09-25 17:54:57 -07003585 /* Verify size of file vs. image size info in file's header */
3586 if (ucode_raw->size < sizeof(*ucode) +
3587 inst_size + data_size + init_size +
3588 init_data_size + boot_size) {
3589
3590 IWL_DEBUG_INFO("uCode file size %d too small\n",
3591 (int)ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08003592 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003593 goto err_release;
3594 }
3595
3596 /* Verify that uCode images will fit in card's SRAM */
Samuel Ortiz250bdd22008-12-19 10:37:11 +08003597 if (inst_size > IWL39_MAX_INST_SIZE) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08003598 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
3599 inst_size);
3600 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003601 goto err_release;
3602 }
3603
Samuel Ortiz250bdd22008-12-19 10:37:11 +08003604 if (data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08003605 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
3606 data_size);
3607 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003608 goto err_release;
3609 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08003610 if (init_size > IWL39_MAX_INST_SIZE) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08003611 IWL_DEBUG_INFO("uCode init instr len %d too large to fit in\n",
3612 init_size);
3613 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003614 goto err_release;
3615 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08003616 if (init_data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08003617 IWL_DEBUG_INFO("uCode init data len %d too large to fit in\n",
3618 init_data_size);
3619 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003620 goto err_release;
3621 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08003622 if (boot_size > IWL39_MAX_BSM_SIZE) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08003623 IWL_DEBUG_INFO("uCode boot instr len %d too large to fit in\n",
3624 boot_size);
3625 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003626 goto err_release;
3627 }
3628
3629 /* Allocate ucode buffers for card's bus-master loading ... */
3630
3631 /* Runtime instructions and 2 copies of data:
3632 * 1) unmodified from disk
3633 * 2) backup cache for save/restore during power-downs */
3634 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08003635 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07003636
3637 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08003638 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07003639
3640 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08003641 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07003642
3643 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
Tomas Winkler90e759d2007-11-29 11:09:41 +08003644 !priv->ucode_data_backup.v_addr)
Zhu Yib481de92007-09-25 17:54:57 -07003645 goto err_pci_alloc;
3646
Tomas Winkler90e759d2007-11-29 11:09:41 +08003647 /* Initialization instructions and data */
3648 if (init_size && init_data_size) {
3649 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08003650 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Tomas Winkler90e759d2007-11-29 11:09:41 +08003651
3652 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08003653 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08003654
3655 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
3656 goto err_pci_alloc;
3657 }
3658
3659 /* Bootstrap (instructions only, no data) */
3660 if (boot_size) {
3661 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08003662 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Tomas Winkler90e759d2007-11-29 11:09:41 +08003663
3664 if (!priv->ucode_boot.v_addr)
3665 goto err_pci_alloc;
3666 }
3667
Zhu Yib481de92007-09-25 17:54:57 -07003668 /* Copy images into buffers for card's bus-master reads ... */
3669
3670 /* Runtime instructions (first block of data in file) */
3671 src = &ucode->data[0];
3672 len = priv->ucode_code.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08003673 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07003674 memcpy(priv->ucode_code.v_addr, src, len);
3675 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
3676 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
3677
3678 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003679 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
Zhu Yib481de92007-09-25 17:54:57 -07003680 src = &ucode->data[inst_size];
3681 len = priv->ucode_data.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08003682 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07003683 memcpy(priv->ucode_data.v_addr, src, len);
3684 memcpy(priv->ucode_data_backup.v_addr, src, len);
3685
3686 /* Initialization instructions (3rd block) */
3687 if (init_size) {
3688 src = &ucode->data[inst_size + data_size];
3689 len = priv->ucode_init.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08003690 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
3691 len);
Zhu Yib481de92007-09-25 17:54:57 -07003692 memcpy(priv->ucode_init.v_addr, src, len);
3693 }
3694
3695 /* Initialization data (4th block) */
3696 if (init_data_size) {
3697 src = &ucode->data[inst_size + data_size + init_size];
3698 len = priv->ucode_init_data.len;
3699 IWL_DEBUG_INFO("Copying (but not loading) init data len %d\n",
3700 (int)len);
3701 memcpy(priv->ucode_init_data.v_addr, src, len);
3702 }
3703
3704 /* Bootstrap instructions (5th block) */
3705 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
3706 len = priv->ucode_boot.len;
3707 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %d\n",
3708 (int)len);
3709 memcpy(priv->ucode_boot.v_addr, src, len);
3710
3711 /* We have our copies now, allow OS release its copies */
3712 release_firmware(ucode_raw);
3713 return 0;
3714
3715 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08003716 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08003717 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003718 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003719
3720 err_release:
3721 release_firmware(ucode_raw);
3722
3723 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08003724 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003725}
3726
3727
3728/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003729 * iwl3945_set_ucode_ptrs - Set uCode address location
Zhu Yib481de92007-09-25 17:54:57 -07003730 *
3731 * Tell initialization uCode where to find runtime uCode.
3732 *
3733 * BSM registers initially contain pointers to initialization uCode.
3734 * We need to replace them to load runtime uCode inst and data,
3735 * and to save runtime data when powering down.
3736 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003737static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003738{
3739 dma_addr_t pinst;
3740 dma_addr_t pdata;
3741 int rc = 0;
3742 unsigned long flags;
3743
3744 /* bits 31:0 for 3945 */
3745 pinst = priv->ucode_code.p_addr;
3746 pdata = priv->ucode_data_backup.p_addr;
3747
3748 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003749 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003750 if (rc) {
3751 spin_unlock_irqrestore(&priv->lock, flags);
3752 return rc;
3753 }
3754
3755 /* Tell bootstrap uCode where to find image to load */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003756 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
3757 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
3758 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07003759 priv->ucode_data.len);
3760
Tomas Winklera96a27f2008-10-23 23:48:56 -07003761 /* Inst byte count must be last to set up, bit 31 signals uCode
Zhu Yib481de92007-09-25 17:54:57 -07003762 * that all new ptr/size info is in place */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003763 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07003764 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
3765
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003766 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003767
3768 spin_unlock_irqrestore(&priv->lock, flags);
3769
3770 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
3771
3772 return rc;
3773}
3774
3775/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003776 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07003777 *
3778 * Called after REPLY_ALIVE notification received from "initialize" uCode.
3779 *
Zhu Yib481de92007-09-25 17:54:57 -07003780 * Tell "initialize" uCode to go ahead and load the runtime uCode.
Ben Cahill9fbab512007-11-29 11:09:47 +08003781 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003782static void iwl3945_init_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003783{
3784 /* Check alive response for "valid" sign from uCode */
3785 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
3786 /* We had an error bringing up the hardware, so take it
3787 * all the way back down so we can try again */
3788 IWL_DEBUG_INFO("Initialize Alive failed.\n");
3789 goto restart;
3790 }
3791
3792 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
3793 * This is a paranoid check, because we would not have gotten the
3794 * "initialize" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003795 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003796 /* Runtime instruction load was bad;
3797 * take it all the way back down so we can try again */
3798 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
3799 goto restart;
3800 }
3801
3802 /* Send pointers to protocol/runtime uCode image ... init code will
3803 * load and launch runtime uCode, which will send us another "Alive"
3804 * notification. */
3805 IWL_DEBUG_INFO("Initialization Alive received.\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003806 if (iwl3945_set_ucode_ptrs(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003807 /* Runtime instruction load won't happen;
3808 * take it all the way back down so we can try again */
3809 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
3810 goto restart;
3811 }
3812 return;
3813
3814 restart:
3815 queue_work(priv->workqueue, &priv->restart);
3816}
3817
3818
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003819/* temporary */
3820static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw,
3821 struct sk_buff *skb);
3822
Zhu Yib481de92007-09-25 17:54:57 -07003823/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003824 * iwl3945_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07003825 * from protocol/runtime uCode (initialization uCode's
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003826 * Alive gets handled by iwl3945_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07003827 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003828static void iwl3945_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003829{
3830 int rc = 0;
3831 int thermal_spin = 0;
3832 u32 rfkill;
3833
3834 IWL_DEBUG_INFO("Runtime Alive received.\n");
3835
3836 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
3837 /* We had an error bringing up the hardware, so take it
3838 * all the way back down so we can try again */
3839 IWL_DEBUG_INFO("Alive failed.\n");
3840 goto restart;
3841 }
3842
3843 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
3844 * This is a paranoid check, because we would not have gotten the
3845 * "runtime" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003846 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003847 /* Runtime instruction load was bad;
3848 * take it all the way back down so we can try again */
3849 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
3850 goto restart;
3851 }
3852
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003853 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003854
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003855 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003856 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003857 IWL_WARN(priv, "Can not read RFKILL status from adapter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003858 return;
3859 }
3860
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003861 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
Zhu Yib481de92007-09-25 17:54:57 -07003862 IWL_DEBUG_INFO("RFKILL status: 0x%x\n", rfkill);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003863 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003864
3865 if (rfkill & 0x1) {
3866 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Tomas Winklera96a27f2008-10-23 23:48:56 -07003867 /* if RFKILL is not on, then wait for thermal
Zhu Yib481de92007-09-25 17:54:57 -07003868 * sensor in adapter to kick in */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003869 while (iwl3945_hw_get_temperature(priv) == 0) {
Zhu Yib481de92007-09-25 17:54:57 -07003870 thermal_spin++;
3871 udelay(10);
3872 }
3873
3874 if (thermal_spin)
3875 IWL_DEBUG_INFO("Thermal calibration took %dus\n",
3876 thermal_spin * 10);
3877 } else
3878 set_bit(STATUS_RF_KILL_HW, &priv->status);
3879
Ben Cahill9fbab512007-11-29 11:09:47 +08003880 /* After the ALIVE response, we can send commands to 3945 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07003881 set_bit(STATUS_ALIVE, &priv->status);
3882
3883 /* Clear out the uCode error bit if it is set */
3884 clear_bit(STATUS_FW_ERROR, &priv->status);
3885
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003886 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003887 return;
3888
Johannes Berg36d68252008-05-15 12:55:26 +02003889 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07003890
3891 priv->active_rate = priv->rates_mask;
3892 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
3893
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003894 iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode));
Zhu Yib481de92007-09-25 17:54:57 -07003895
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003896 if (iwl3945_is_associated(priv)) {
3897 struct iwl3945_rxon_cmd *active_rxon =
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08003898 (struct iwl3945_rxon_cmd *)(&priv->active39_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07003899
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08003900 memcpy(&priv->staging39_rxon, &priv->active39_rxon,
3901 sizeof(priv->staging39_rxon));
Zhu Yib481de92007-09-25 17:54:57 -07003902 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3903 } else {
3904 /* Initialize our rx_config data */
Zhu, Yi60294de2008-10-29 14:05:45 -07003905 iwl3945_connection_init_rx_config(priv, priv->iw_mode);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08003906 memcpy(priv->staging39_rxon.node_addr, priv->mac_addr, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07003907 }
3908
Ben Cahill9fbab512007-11-29 11:09:47 +08003909 /* Configure Bluetooth device coexistence support */
Samuel Ortiz17f841c2009-01-23 13:45:20 -08003910 iwl_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003911
3912 /* Configure the adapter for unassociated operation */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003913 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003914
Zhu Yib481de92007-09-25 17:54:57 -07003915 iwl3945_reg_txpower_periodic(priv);
3916
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07003917 iwl3945_led_register(priv);
3918
Zhu Yib481de92007-09-25 17:54:57 -07003919 IWL_DEBUG_INFO("ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07003920 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a669262008-01-14 17:46:18 -08003921 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07003922
3923 if (priv->error_recovering)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003924 iwl3945_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003925
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003926 /* reassociate for ADHOC mode */
3927 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
3928 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
3929 priv->vif);
3930 if (beacon)
3931 iwl3945_mac_beacon_update(priv->hw, beacon);
3932 }
3933
Zhu Yib481de92007-09-25 17:54:57 -07003934 return;
3935
3936 restart:
3937 queue_work(priv->workqueue, &priv->restart);
3938}
3939
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003940static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07003941
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003942static void __iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003943{
3944 unsigned long flags;
3945 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
3946 struct ieee80211_conf *conf = NULL;
3947
3948 IWL_DEBUG_INFO(DRV_NAME " is going down\n");
3949
3950 conf = ieee80211_get_hw_conf(priv->hw);
3951
3952 if (!exit_pending)
3953 set_bit(STATUS_EXIT_PENDING, &priv->status);
3954
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07003955 iwl3945_led_unregister(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003956 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003957
3958 /* Unblock any waiting calls */
3959 wake_up_interruptible_all(&priv->wait_command_queue);
3960
Zhu Yib481de92007-09-25 17:54:57 -07003961 /* Wipe out the EXIT_PENDING status bit if we are not actually
3962 * exiting the module */
3963 if (!exit_pending)
3964 clear_bit(STATUS_EXIT_PENDING, &priv->status);
3965
3966 /* stop and reset the on-board processor */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003967 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07003968
3969 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003970 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003971 iwl3945_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003972 spin_unlock_irqrestore(&priv->lock, flags);
3973 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003974
3975 if (priv->mac80211_registered)
3976 ieee80211_stop_queues(priv->hw);
3977
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003978 /* If we have not previously called iwl3945_init() then
Zhu Yib481de92007-09-25 17:54:57 -07003979 * clear all bits but the RF Kill and SUSPEND bits and return */
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003980 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003981 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3982 STATUS_RF_KILL_HW |
3983 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3984 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08003985 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3986 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07003987 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003988 STATUS_IN_SUSPEND |
3989 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3990 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07003991 goto exit;
3992 }
3993
3994 /* ...otherwise clear out all the status bits but the RF Kill and
3995 * SUSPEND bits and continue taking the NIC down. */
3996 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3997 STATUS_RF_KILL_HW |
3998 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3999 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08004000 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
4001 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07004002 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
4003 STATUS_IN_SUSPEND |
4004 test_bit(STATUS_FW_ERROR, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08004005 STATUS_FW_ERROR |
4006 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
4007 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07004008
Abbas, Mohamede9414b62009-01-20 21:33:55 -08004009 priv->cfg->ops->lib->apm_ops.reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004010 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004011 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07004012 spin_unlock_irqrestore(&priv->lock, flags);
4013
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004014 iwl3945_hw_txq_ctx_stop(priv);
4015 iwl3945_hw_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004016
4017 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004018 if (!iwl_grab_nic_access(priv)) {
4019 iwl_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07004020 APMG_CLK_VAL_DMA_CLK_RQT);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004021 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004022 }
4023 spin_unlock_irqrestore(&priv->lock, flags);
4024
4025 udelay(5);
4026
Abbas, Mohamede9414b62009-01-20 21:33:55 -08004027 if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status))
4028 priv->cfg->ops->lib->apm_ops.stop(priv);
4029 else
4030 priv->cfg->ops->lib->apm_ops.reset(priv);
4031
Zhu Yib481de92007-09-25 17:54:57 -07004032 exit:
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08004033 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07004034
4035 if (priv->ibss_beacon)
4036 dev_kfree_skb(priv->ibss_beacon);
4037 priv->ibss_beacon = NULL;
4038
4039 /* clear out any free frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004040 iwl3945_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004041}
4042
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004043static void iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004044{
4045 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004046 __iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004047 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08004048
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004049 iwl3945_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004050}
4051
4052#define MAX_HW_RESTARTS 5
4053
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004054static int __iwl3945_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004055{
4056 int rc, i;
4057
4058 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004059 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07004060 return -EIO;
4061 }
4062
4063 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004064 IWL_WARN(priv, "Radio disabled by SW RF kill (module "
Zhu Yib481de92007-09-25 17:54:57 -07004065 "parameter)\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08004066 return -ENODEV;
4067 }
4068
Reinette Chatree903fbd2008-01-30 22:05:15 -08004069 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004070 IWL_ERR(priv, "ucode not available for device bring up\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08004071 return -EIO;
4072 }
4073
Zhu Yie655b9f2008-01-24 02:19:38 -08004074 /* If platform's RF_KILL switch is NOT set to KILL */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004075 if (iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yie655b9f2008-01-24 02:19:38 -08004076 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
4077 clear_bit(STATUS_RF_KILL_HW, &priv->status);
4078 else {
4079 set_bit(STATUS_RF_KILL_HW, &priv->status);
4080 if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004081 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08004082 return -ENODEV;
4083 }
Zhu Yib481de92007-09-25 17:54:57 -07004084 }
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02004085
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004086 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07004087
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004088 rc = iwl3945_hw_nic_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004089 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004090 IWL_ERR(priv, "Unable to int nic\n");
Zhu Yib481de92007-09-25 17:54:57 -07004091 return rc;
4092 }
4093
4094 /* make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004095 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
4096 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07004097 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
4098
4099 /* clear (again), then enable host interrupts */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004100 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004101 iwl3945_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004102
4103 /* really make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004104 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
4105 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07004106
4107 /* Copy original ucode data image from disk into backup cache.
4108 * This will be used to initialize the on-board processor's
4109 * data SRAM for a clean start when the runtime program first loads. */
4110 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a669262008-01-14 17:46:18 -08004111 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07004112
Zhu Yie655b9f2008-01-24 02:19:38 -08004113 /* We return success when we resume from suspend and rf_kill is on. */
4114 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
4115 return 0;
4116
Zhu Yib481de92007-09-25 17:54:57 -07004117 for (i = 0; i < MAX_HW_RESTARTS; i++) {
4118
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004119 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004120
4121 /* load bootstrap state machine,
4122 * load bootstrap program into processor's memory,
4123 * prepare to load the "initialize" uCode */
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08004124 priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004125
4126 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004127 IWL_ERR(priv,
4128 "Unable to set up bootstrap uCode: %d\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -07004129 continue;
4130 }
4131
4132 /* start card; "initialize" will load runtime ucode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004133 iwl3945_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004134
Zhu Yib481de92007-09-25 17:54:57 -07004135 IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
4136
4137 return 0;
4138 }
4139
4140 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004141 __iwl3945_down(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08004142 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07004143
4144 /* tried to restart and config the device for as long as our
4145 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08004146 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07004147 return -EIO;
4148}
4149
4150
4151/*****************************************************************************
4152 *
4153 * Workqueue callbacks
4154 *
4155 *****************************************************************************/
4156
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004157static void iwl3945_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07004158{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004159 struct iwl_priv *priv =
4160 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07004161
4162 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
4163 return;
4164
4165 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004166 iwl3945_init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004167 mutex_unlock(&priv->mutex);
4168}
4169
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004170static void iwl3945_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07004171{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004172 struct iwl_priv *priv =
4173 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07004174
4175 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
4176 return;
4177
4178 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004179 iwl3945_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004180 mutex_unlock(&priv->mutex);
4181}
4182
Helmut Schaa26635162009-01-15 09:38:44 +01004183static void iwl3945_rfkill_poll(struct work_struct *data)
4184{
4185 struct iwl_priv *priv =
4186 container_of(data, struct iwl_priv, rfkill_poll.work);
4187 unsigned long status = priv->status;
4188
4189 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
4190 clear_bit(STATUS_RF_KILL_HW, &priv->status);
4191 else
4192 set_bit(STATUS_RF_KILL_HW, &priv->status);
4193
4194 if (test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status))
4195 queue_work(priv->workqueue, &priv->rf_kill);
4196
4197 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
4198 round_jiffies_relative(2 * HZ));
4199
4200}
4201
Zhu Yib481de92007-09-25 17:54:57 -07004202#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004203static void iwl3945_bg_request_scan(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07004204{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004205 struct iwl_priv *priv =
4206 container_of(data, struct iwl_priv, request_scan);
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08004207 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07004208 .id = REPLY_SCAN_CMD,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004209 .len = sizeof(struct iwl3945_scan_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07004210 .meta.flags = CMD_SIZE_HUGE,
4211 };
4212 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004213 struct iwl3945_scan_cmd *scan;
Zhu Yib481de92007-09-25 17:54:57 -07004214 struct ieee80211_conf *conf = NULL;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08004215 u8 n_probes = 2;
Johannes Berg8318d782008-01-24 19:38:38 +01004216 enum ieee80211_band band;
John W. Linville9387b7c2008-09-30 20:59:05 -04004217 DECLARE_SSID_BUF(ssid);
Zhu Yib481de92007-09-25 17:54:57 -07004218
4219 conf = ieee80211_get_hw_conf(priv->hw);
4220
4221 mutex_lock(&priv->mutex);
4222
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004223 if (!iwl_is_ready(priv)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004224 IWL_WARN(priv, "request scan called when driver not ready.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004225 goto done;
4226 }
4227
Tomas Winklera96a27f2008-10-23 23:48:56 -07004228 /* Make sure the scan wasn't canceled before this queued work
Zhu Yib481de92007-09-25 17:54:57 -07004229 * was given the chance to run... */
4230 if (!test_bit(STATUS_SCANNING, &priv->status))
4231 goto done;
4232
4233 /* This should never be called or scheduled if there is currently
4234 * a scan active in the hardware. */
4235 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
4236 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
4237 "Ignoring second request.\n");
4238 rc = -EIO;
4239 goto done;
4240 }
4241
4242 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
4243 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
4244 goto done;
4245 }
4246
4247 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
4248 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
4249 goto done;
4250 }
4251
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004252 if (iwl_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004253 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
4254 goto done;
4255 }
4256
4257 if (!test_bit(STATUS_READY, &priv->status)) {
4258 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
4259 goto done;
4260 }
4261
4262 if (!priv->scan_bands) {
4263 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
4264 goto done;
4265 }
4266
Winkler, Tomas805cee52009-01-19 15:30:28 -08004267 if (!priv->scan) {
4268 priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
Zhu Yib481de92007-09-25 17:54:57 -07004269 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
Winkler, Tomas805cee52009-01-19 15:30:28 -08004270 if (!priv->scan) {
Zhu Yib481de92007-09-25 17:54:57 -07004271 rc = -ENOMEM;
4272 goto done;
4273 }
4274 }
Winkler, Tomas805cee52009-01-19 15:30:28 -08004275 scan = priv->scan;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004276 memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07004277
4278 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
4279 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
4280
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004281 if (iwl3945_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004282 u16 interval = 0;
4283 u32 extra;
4284 u32 suspend_time = 100;
4285 u32 scan_suspend_time = 100;
4286 unsigned long flags;
4287
4288 IWL_DEBUG_INFO("Scanning while associated...\n");
4289
4290 spin_lock_irqsave(&priv->lock, flags);
4291 interval = priv->beacon_int;
4292 spin_unlock_irqrestore(&priv->lock, flags);
4293
4294 scan->suspend_time = 0;
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004295 scan->max_out_time = cpu_to_le32(200 * 1024);
Zhu Yib481de92007-09-25 17:54:57 -07004296 if (!interval)
4297 interval = suspend_time;
4298 /*
4299 * suspend time format:
4300 * 0-19: beacon interval in usec (time before exec.)
4301 * 20-23: 0
4302 * 24-31: number of beacons (suspend between channels)
4303 */
4304
4305 extra = (suspend_time / interval) << 24;
4306 scan_suspend_time = 0xFF0FFFFF &
4307 (extra | ((suspend_time % interval) * 1024));
4308
4309 scan->suspend_time = cpu_to_le32(scan_suspend_time);
4310 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
4311 scan_suspend_time, interval);
4312 }
4313
4314 /* We should add the ability for user to lock to PASSIVE ONLY */
4315 if (priv->one_direct_scan) {
4316 IWL_DEBUG_SCAN
4317 ("Kicking off one direct scan for '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004318 print_ssid(ssid, priv->direct_ssid,
4319 priv->direct_ssid_len));
Zhu Yib481de92007-09-25 17:54:57 -07004320 scan->direct_scan[0].id = WLAN_EID_SSID;
4321 scan->direct_scan[0].len = priv->direct_ssid_len;
4322 memcpy(scan->direct_scan[0].ssid,
4323 priv->direct_ssid, priv->direct_ssid_len);
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08004324 n_probes++;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08004325 } else
Bill Moss786b4552008-04-17 16:03:40 -07004326 IWL_DEBUG_SCAN("Kicking off one indirect scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004327
4328 /* We don't build a direct scan probe request; the uCode will do
4329 * that based on the direct_mask added to each channel entry */
Zhu Yib481de92007-09-25 17:54:57 -07004330 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08004331 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07004332 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
4333
4334 /* flags + rate selection */
4335
Ron Rindjunsky66b50042008-06-25 16:46:31 +08004336 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07004337 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
4338 scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
4339 scan->good_CRC_th = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01004340 band = IEEE80211_BAND_2GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08004341 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07004342 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
4343 scan->good_CRC_th = IWL_GOOD_CRC_TH;
Johannes Berg8318d782008-01-24 19:38:38 +01004344 band = IEEE80211_BAND_5GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08004345 } else {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004346 IWL_WARN(priv, "Invalid scan band count\n");
Zhu Yib481de92007-09-25 17:54:57 -07004347 goto done;
4348 }
4349
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08004350 scan->tx_cmd.len = cpu_to_le16(
4351 iwl_fill_probe_req(priv, band,
4352 (struct ieee80211_mgmt *)scan->data,
4353 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
4354
Zhu Yib481de92007-09-25 17:54:57 -07004355 /* select Rx antennas */
4356 scan->flags |= iwl3945_get_antenna_flags(priv);
4357
Johannes Berg05c914f2008-09-11 00:01:58 +02004358 if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
Zhu Yib481de92007-09-25 17:54:57 -07004359 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
4360
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08004361 scan->channel_count =
4362 iwl3945_get_channels_for_scan(priv, band, 1, /* active */
4363 n_probes,
4364 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
Zhu Yib481de92007-09-25 17:54:57 -07004365
Reinette Chatre14b54332008-11-04 12:21:35 -08004366 if (scan->channel_count == 0) {
4367 IWL_DEBUG_SCAN("channel count %d\n", scan->channel_count);
4368 goto done;
4369 }
4370
Zhu Yib481de92007-09-25 17:54:57 -07004371 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004372 scan->channel_count * sizeof(struct iwl3945_scan_channel);
Zhu Yib481de92007-09-25 17:54:57 -07004373 cmd.data = scan;
4374 scan->len = cpu_to_le16(cmd.len);
4375
4376 set_bit(STATUS_SCAN_HW, &priv->status);
Samuel Ortiz518099a2009-01-19 15:30:27 -08004377 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07004378 if (rc)
4379 goto done;
4380
4381 queue_delayed_work(priv->workqueue, &priv->scan_check,
4382 IWL_SCAN_CHECK_WATCHDOG);
4383
4384 mutex_unlock(&priv->mutex);
4385 return;
4386
4387 done:
Mohamed Abbas2420ebc2008-11-04 12:21:34 -08004388 /* can not perform scan make sure we clear scanning
4389 * bits from status so next scan request can be performed.
4390 * if we dont clear scanning status bit here all next scan
4391 * will fail
4392 */
4393 clear_bit(STATUS_SCAN_HW, &priv->status);
4394 clear_bit(STATUS_SCANNING, &priv->status);
4395
Ian Schram01ebd062007-10-25 17:15:22 +08004396 /* inform mac80211 scan aborted */
Zhu Yib481de92007-09-25 17:54:57 -07004397 queue_work(priv->workqueue, &priv->scan_completed);
4398 mutex_unlock(&priv->mutex);
4399}
4400
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004401static void iwl3945_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07004402{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004403 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07004404
4405 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
4406 return;
4407
4408 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004409 __iwl3945_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004410 mutex_unlock(&priv->mutex);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01004411 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004412}
4413
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004414static void iwl3945_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07004415{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004416 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07004417
4418 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
4419 return;
4420
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004421 iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004422 queue_work(priv->workqueue, &priv->up);
4423}
4424
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004425static void iwl3945_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07004426{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004427 struct iwl_priv *priv =
4428 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07004429
4430 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
4431 return;
4432
4433 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004434 iwl3945_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004435 mutex_unlock(&priv->mutex);
4436}
4437
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08004438#define IWL_DELAY_NEXT_SCAN (HZ*2)
4439
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004440static void iwl3945_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004441{
Zhu Yib481de92007-09-25 17:54:57 -07004442 int rc = 0;
4443 struct ieee80211_conf *conf = NULL;
4444
Johannes Berg05c914f2008-09-11 00:01:58 +02004445 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004446 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07004447 return;
4448 }
4449
4450
Johannes Berge1749612008-10-27 15:59:26 -07004451 IWL_DEBUG_ASSOC("Associated as %d to: %pM\n",
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004452 priv->assoc_id, priv->active39_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07004453
4454 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
4455 return;
4456
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08004457 if (!priv->vif || !priv->is_open)
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004458 return;
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08004459
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004460 iwl_scan_cancel_timeout(priv, 200);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004461
Zhu Yib481de92007-09-25 17:54:57 -07004462 conf = ieee80211_get_hw_conf(priv->hw);
4463
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004464 priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004465 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004466
Tomas Winkler28afaf92008-12-19 10:37:06 +08004467 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004468 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08004469 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07004470 sizeof(priv->rxon_timing), &priv->rxon_timing);
4471 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004472 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07004473 "Attempting to continue.\n");
4474
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004475 priv->staging39_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07004476
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004477 priv->staging39_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07004478
4479 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
4480 priv->assoc_id, priv->beacon_int);
4481
4482 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004483 priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07004484 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004485 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07004486
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004487 if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07004488 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004489 priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07004490 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004491 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07004492
Johannes Berg05c914f2008-09-11 00:01:58 +02004493 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004494 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07004495
4496 }
4497
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004498 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004499
4500 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02004501 case NL80211_IFTYPE_STATION:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004502 iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07004503 break;
4504
Johannes Berg05c914f2008-09-11 00:01:58 +02004505 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07004506
Abhijeet Kolekarce546fd2008-11-19 15:32:22 -08004507 priv->assoc_id = 1;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004508 iwl3945_add_station(priv, priv->bssid, 0, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004509 iwl3945_sync_sta(priv, IWL_STA_ID,
Johannes Berg8318d782008-01-24 19:38:38 +01004510 (priv->band == IEEE80211_BAND_5GHZ) ?
Zhu Yib481de92007-09-25 17:54:57 -07004511 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
4512 CMD_ASYNC);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004513 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
4514 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004515
4516 break;
4517
4518 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08004519 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03004520 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07004521 break;
4522 }
4523
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004524 iwl3945_activate_qos(priv, 0);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08004525
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08004526 /* we have just associated, don't start scan too early */
4527 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004528}
4529
Johannes Berge8975582008-10-09 12:18:51 +02004530static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed);
Zhu Yi76bb77e2007-11-22 10:53:22 +08004531
Zhu Yib481de92007-09-25 17:54:57 -07004532/*****************************************************************************
4533 *
4534 * mac80211 entry point functions
4535 *
4536 *****************************************************************************/
4537
Zhu Yi5a669262008-01-14 17:46:18 -08004538#define UCODE_READY_TIMEOUT (2 * HZ)
4539
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004540static int iwl3945_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07004541{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004542 struct iwl_priv *priv = hw->priv;
Zhu Yi5a669262008-01-14 17:46:18 -08004543 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07004544
4545 IWL_DEBUG_MAC80211("enter\n");
4546
4547 /* we should be verifying the device is ready to be opened */
4548 mutex_lock(&priv->mutex);
4549
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004550 memset(&priv->staging39_rxon, 0, sizeof(struct iwl3945_rxon_cmd));
Zhu Yi5a669262008-01-14 17:46:18 -08004551 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
4552 * ucode filename and max sizes are card-specific. */
4553
4554 if (!priv->ucode_code.len) {
4555 ret = iwl3945_read_ucode(priv);
4556 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004557 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a669262008-01-14 17:46:18 -08004558 mutex_unlock(&priv->mutex);
4559 goto out_release_irq;
4560 }
4561 }
4562
Zhu Yie655b9f2008-01-24 02:19:38 -08004563 ret = __iwl3945_up(priv);
Zhu Yi5a669262008-01-14 17:46:18 -08004564
Zhu Yib481de92007-09-25 17:54:57 -07004565 mutex_unlock(&priv->mutex);
Zhu Yi5a669262008-01-14 17:46:18 -08004566
Samuel Ortizc0af96a2009-01-21 18:27:54 +01004567 iwl_rfkill_set_hw_state(priv);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02004568
Zhu Yie655b9f2008-01-24 02:19:38 -08004569 if (ret)
4570 goto out_release_irq;
4571
4572 IWL_DEBUG_INFO("Start UP work.\n");
4573
4574 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
4575 return 0;
4576
Zhu Yi5a669262008-01-14 17:46:18 -08004577 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
4578 * mac80211 will not be run successfully. */
4579 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
4580 test_bit(STATUS_READY, &priv->status),
4581 UCODE_READY_TIMEOUT);
4582 if (!ret) {
4583 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004584 IWL_ERR(priv,
4585 "Wait for START_ALIVE timeout after %dms.\n",
4586 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Zhu Yi5a669262008-01-14 17:46:18 -08004587 ret = -ETIMEDOUT;
4588 goto out_release_irq;
4589 }
4590 }
4591
Helmut Schaa26635162009-01-15 09:38:44 +01004592 /* ucode is running and will send rfkill notifications,
4593 * no need to poll the killswitch state anymore */
4594 cancel_delayed_work(&priv->rfkill_poll);
4595
Zhu Yie655b9f2008-01-24 02:19:38 -08004596 priv->is_open = 1;
Zhu Yib481de92007-09-25 17:54:57 -07004597 IWL_DEBUG_MAC80211("leave\n");
4598 return 0;
Zhu Yi5a669262008-01-14 17:46:18 -08004599
4600out_release_irq:
Zhu Yie655b9f2008-01-24 02:19:38 -08004601 priv->is_open = 0;
4602 IWL_DEBUG_MAC80211("leave - failed\n");
Zhu Yi5a669262008-01-14 17:46:18 -08004603 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004604}
4605
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004606static void iwl3945_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07004607{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004608 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004609
4610 IWL_DEBUG_MAC80211("enter\n");
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004611
Zhu Yie655b9f2008-01-24 02:19:38 -08004612 if (!priv->is_open) {
4613 IWL_DEBUG_MAC80211("leave - skip\n");
4614 return;
4615 }
4616
Zhu Yib481de92007-09-25 17:54:57 -07004617 priv->is_open = 0;
Zhu Yi5a669262008-01-14 17:46:18 -08004618
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004619 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08004620 /* stop mac, cancel any scan request and clear
4621 * RXON_FILTER_ASSOC_MSK BIT
4622 */
Zhu Yi5a669262008-01-14 17:46:18 -08004623 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004624 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08004625 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08004626 }
4627
Zhu Yi5a669262008-01-14 17:46:18 -08004628 iwl3945_down(priv);
4629
4630 flush_workqueue(priv->workqueue);
Helmut Schaa26635162009-01-15 09:38:44 +01004631
4632 /* start polling the killswitch state again */
4633 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
4634 round_jiffies_relative(2 * HZ));
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004635
Zhu Yib481de92007-09-25 17:54:57 -07004636 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004637}
4638
Johannes Berge039fa42008-05-15 12:55:29 +02004639static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07004640{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004641 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004642
4643 IWL_DEBUG_MAC80211("enter\n");
4644
Zhu Yib481de92007-09-25 17:54:57 -07004645 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02004646 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07004647
Johannes Berge039fa42008-05-15 12:55:29 +02004648 if (iwl3945_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07004649 dev_kfree_skb_any(skb);
4650
4651 IWL_DEBUG_MAC80211("leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08004652 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07004653}
4654
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004655static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004656 struct ieee80211_if_init_conf *conf)
4657{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004658 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004659 unsigned long flags;
4660
Johannes Berg32bfd352007-12-19 01:31:26 +01004661 IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07004662
Johannes Berg32bfd352007-12-19 01:31:26 +01004663 if (priv->vif) {
4664 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
Tomas Winkler864792e2007-11-27 21:00:52 +02004665 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07004666 }
4667
4668 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01004669 priv->vif = conf->vif;
Zhu, Yi60294de2008-10-29 14:05:45 -07004670 priv->iw_mode = conf->type;
Zhu Yib481de92007-09-25 17:54:57 -07004671
4672 spin_unlock_irqrestore(&priv->lock, flags);
4673
4674 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02004675
4676 if (conf->mac_addr) {
Johannes Berge1749612008-10-27 15:59:26 -07004677 IWL_DEBUG_MAC80211("Set: %pM\n", conf->mac_addr);
Tomas Winkler864792e2007-11-27 21:00:52 +02004678 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
4679 }
4680
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004681 if (iwl_is_ready(priv))
Zhu Yi5a669262008-01-14 17:46:18 -08004682 iwl3945_set_mode(priv, conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07004683
Zhu Yib481de92007-09-25 17:54:57 -07004684 mutex_unlock(&priv->mutex);
4685
Zhu Yi5a669262008-01-14 17:46:18 -08004686 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004687 return 0;
4688}
4689
4690/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004691 * iwl3945_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07004692 *
4693 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
4694 * be set inappropriately and the driver currently sets the hardware up to
4695 * use it whenever needed.
4696 */
Johannes Berge8975582008-10-09 12:18:51 +02004697static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed)
Zhu Yib481de92007-09-25 17:54:57 -07004698{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004699 struct iwl_priv *priv = hw->priv;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08004700 const struct iwl_channel_info *ch_info;
Johannes Berge8975582008-10-09 12:18:51 +02004701 struct ieee80211_conf *conf = &hw->conf;
Zhu Yib481de92007-09-25 17:54:57 -07004702 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08004703 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07004704
4705 mutex_lock(&priv->mutex);
Johannes Berg8318d782008-01-24 19:38:38 +01004706 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07004707
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004708 if (!iwl_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004709 IWL_DEBUG_MAC80211("leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08004710 ret = -EIO;
4711 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004712 }
4713
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004714 if (unlikely(!iwl3945_mod_params.disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07004715 test_bit(STATUS_SCANNING, &priv->status))) {
Zhu Yia0646472007-12-20 14:10:01 +08004716 IWL_DEBUG_MAC80211("leave - scanning\n");
4717 set_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07004718 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08004719 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07004720 }
4721
4722 spin_lock_irqsave(&priv->lock, flags);
4723
Samuel Ortize6148912009-01-23 13:45:15 -08004724 ch_info = iwl_get_channel_info(priv, conf->channel->band,
4725 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07004726 if (!is_channel_valid(ch_info)) {
Ron Rindjunsky66b50042008-06-25 16:46:31 +08004727 IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this band.\n",
Johannes Berg8318d782008-01-24 19:38:38 +01004728 conf->channel->hw_value, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07004729 IWL_DEBUG_MAC80211("leave - invalid channel\n");
4730 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yi76bb77e2007-11-22 10:53:22 +08004731 ret = -EINVAL;
4732 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004733 }
4734
Johannes Berg8318d782008-01-24 19:38:38 +01004735 iwl3945_set_rxon_channel(priv, conf->channel->band, conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07004736
Johannes Berg8318d782008-01-24 19:38:38 +01004737 iwl3945_set_flags_for_phymode(priv, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07004738
4739 /* The list of supported rates and rate mask can be different
4740 * for each phymode; since the phymode may have changed, reset
4741 * the rate mask to what mac80211 lists */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004742 iwl3945_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004743
4744 spin_unlock_irqrestore(&priv->lock, flags);
4745
4746#ifdef IEEE80211_CONF_CHANNEL_SWITCH
4747 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004748 iwl3945_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08004749 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004750 }
4751#endif
4752
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004753 iwl3945_radio_kill_sw(priv, !conf->radio_enabled);
Zhu Yib481de92007-09-25 17:54:57 -07004754
4755 if (!conf->radio_enabled) {
4756 IWL_DEBUG_MAC80211("leave - radio disabled\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08004757 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004758 }
4759
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004760 if (iwl_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004761 IWL_DEBUG_MAC80211("leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08004762 ret = -EIO;
4763 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004764 }
4765
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004766 iwl3945_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004767
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004768 if (memcmp(&priv->active39_rxon,
4769 &priv->staging39_rxon, sizeof(priv->staging39_rxon)))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004770 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004771 else
4772 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
4773
4774 IWL_DEBUG_MAC80211("leave\n");
4775
Zhu Yi76bb77e2007-11-22 10:53:22 +08004776out:
Zhu Yia0646472007-12-20 14:10:01 +08004777 clear_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07004778 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08004779 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004780}
4781
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004782static void iwl3945_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004783{
4784 int rc = 0;
4785
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08004786 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07004787 return;
4788
4789 /* The following should be done only at AP bring up */
Ron Rindjunsky5d1e2322008-06-30 17:23:04 +08004790 if (!(iwl3945_is_associated(priv))) {
Zhu Yib481de92007-09-25 17:54:57 -07004791
4792 /* RXON - unassoc (to set timing command) */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004793 priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004794 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004795
4796 /* RXON Timing */
Tomas Winkler28afaf92008-12-19 10:37:06 +08004797 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004798 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08004799 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
4800 sizeof(priv->rxon_timing),
4801 &priv->rxon_timing);
Zhu Yib481de92007-09-25 17:54:57 -07004802 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004803 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07004804 "Attempting to continue.\n");
4805
4806 /* FIXME: what should be the assoc_id for AP? */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004807 priv->staging39_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07004808 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004809 priv->staging39_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07004810 RXON_FLG_SHORT_PREAMBLE_MSK;
4811 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004812 priv->staging39_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07004813 ~RXON_FLG_SHORT_PREAMBLE_MSK;
4814
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004815 if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07004816 if (priv->assoc_capability &
4817 WLAN_CAPABILITY_SHORT_SLOT_TIME)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004818 priv->staging39_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07004819 RXON_FLG_SHORT_SLOT_MSK;
4820 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004821 priv->staging39_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07004822 ~RXON_FLG_SHORT_SLOT_MSK;
4823
Johannes Berg05c914f2008-09-11 00:01:58 +02004824 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004825 priv->staging39_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07004826 ~RXON_FLG_SHORT_SLOT_MSK;
4827 }
4828 /* restore RXON assoc */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004829 priv->staging39_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004830 iwl3945_commit_rxon(priv);
Kolekar, Abhijeetb5323d32008-12-19 10:37:22 +08004831 iwl3945_add_station(priv, iwl_bcast_addr, 0, 0);
Zhu Yi556f8db2007-09-27 11:27:33 +08004832 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004833 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004834
4835 /* FIXME - we need to add code here to detect a totally new
4836 * configuration, reset the AP, unassoc, rxon timing, assoc,
4837 * clear sta table, add BCAST sta... */
4838}
4839
Johannes Berg32bfd352007-12-19 01:31:26 +01004840static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
4841 struct ieee80211_vif *vif,
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004842 struct ieee80211_if_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -07004843{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004844 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004845 int rc;
4846
4847 if (conf == NULL)
4848 return -EIO;
4849
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08004850 if (priv->vif != vif) {
4851 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08004852 return 0;
4853 }
4854
Johannes Berg9d139c82008-07-09 14:40:37 +02004855 /* handle this temporarily here */
Johannes Berg05c914f2008-09-11 00:01:58 +02004856 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Johannes Berg9d139c82008-07-09 14:40:37 +02004857 conf->changed & IEEE80211_IFCC_BEACON) {
4858 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
4859 if (!beacon)
4860 return -ENOMEM;
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08004861 mutex_lock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02004862 rc = iwl3945_mac_beacon_update(hw, beacon);
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08004863 mutex_unlock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02004864 if (rc)
4865 return rc;
4866 }
4867
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004868 if (!iwl_is_alive(priv))
Zhu Yi5a669262008-01-14 17:46:18 -08004869 return -EAGAIN;
4870
Zhu Yib481de92007-09-25 17:54:57 -07004871 mutex_lock(&priv->mutex);
4872
Zhu Yib481de92007-09-25 17:54:57 -07004873 if (conf->bssid)
Johannes Berge1749612008-10-27 15:59:26 -07004874 IWL_DEBUG_MAC80211("bssid: %pM\n", conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07004875
Johannes Berg4150c572007-09-17 01:29:23 -04004876/*
4877 * very dubious code was here; the probe filtering flag is never set:
4878 *
Zhu Yib481de92007-09-25 17:54:57 -07004879 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
4880 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04004881 */
Zhu Yib481de92007-09-25 17:54:57 -07004882
Johannes Berg05c914f2008-09-11 00:01:58 +02004883 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07004884 if (!conf->bssid) {
4885 conf->bssid = priv->mac_addr;
4886 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Johannes Berge1749612008-10-27 15:59:26 -07004887 IWL_DEBUG_MAC80211("bssid was set to: %pM\n",
4888 conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07004889 }
4890 if (priv->ibss_beacon)
4891 dev_kfree_skb(priv->ibss_beacon);
4892
Johannes Berg9d139c82008-07-09 14:40:37 +02004893 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
Zhu Yib481de92007-09-25 17:54:57 -07004894 }
4895
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004896 if (iwl_is_rfkill(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08004897 goto done;
4898
Zhu Yib481de92007-09-25 17:54:57 -07004899 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
4900 !is_multicast_ether_addr(conf->bssid)) {
4901 /* If there is currently a HW scan going on in the background
4902 * then we need to cancel it else the RXON below will fail. */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004903 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004904 IWL_WARN(priv, "Aborted scan still in progress "
Zhu Yib481de92007-09-25 17:54:57 -07004905 "after 100ms\n");
4906 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
4907 mutex_unlock(&priv->mutex);
4908 return -EAGAIN;
4909 }
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004910 memcpy(priv->staging39_rxon.bssid_addr, conf->bssid, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07004911
4912 /* TODO: Audit driver for usage of these members and see
4913 * if mac80211 deprecates them (priv->bssid looks like it
4914 * shouldn't be there, but I haven't scanned the IBSS code
4915 * to verify) - jpk */
4916 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
4917
Johannes Berg05c914f2008-09-11 00:01:58 +02004918 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004919 iwl3945_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004920 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004921 rc = iwl3945_commit_rxon(priv);
Johannes Berg05c914f2008-09-11 00:01:58 +02004922 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004923 iwl3945_add_station(priv,
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004924 priv->active39_rxon.bssid_addr, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004925 }
4926
4927 } else {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004928 iwl_scan_cancel_timeout(priv, 100);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004929 priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004930 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004931 }
4932
Mohamed Abbasfde35712007-11-29 11:10:15 +08004933 done:
Zhu Yib481de92007-09-25 17:54:57 -07004934 IWL_DEBUG_MAC80211("leave\n");
4935 mutex_unlock(&priv->mutex);
4936
4937 return 0;
4938}
4939
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004940static void iwl3945_configure_filter(struct ieee80211_hw *hw,
Johannes Berg4150c572007-09-17 01:29:23 -04004941 unsigned int changed_flags,
4942 unsigned int *total_flags,
4943 int mc_count, struct dev_addr_list *mc_list)
4944{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004945 struct iwl_priv *priv = hw->priv;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004946 __le32 *filter_flags = &priv->staging39_rxon.filter_flags;
Rick Farrington25b3f572008-06-30 17:23:28 +08004947
Zhu, Yi352bc8d2008-11-12 13:14:09 -08004948 IWL_DEBUG_MAC80211("Enter: changed: 0x%x, total: 0x%x\n",
4949 changed_flags, *total_flags);
4950
4951 if (changed_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) {
4952 if (*total_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS))
4953 *filter_flags |= RXON_FILTER_PROMISC_MSK;
4954 else
4955 *filter_flags &= ~RXON_FILTER_PROMISC_MSK;
Abhijeet Kolekar5ec03972008-05-05 10:22:48 +08004956 }
Zhu, Yi352bc8d2008-11-12 13:14:09 -08004957 if (changed_flags & FIF_ALLMULTI) {
4958 if (*total_flags & FIF_ALLMULTI)
4959 *filter_flags |= RXON_FILTER_ACCEPT_GRP_MSK;
4960 else
4961 *filter_flags &= ~RXON_FILTER_ACCEPT_GRP_MSK;
4962 }
4963 if (changed_flags & FIF_CONTROL) {
4964 if (*total_flags & FIF_CONTROL)
4965 *filter_flags |= RXON_FILTER_CTL2HOST_MSK;
4966 else
4967 *filter_flags &= ~RXON_FILTER_CTL2HOST_MSK;
4968 }
4969 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
4970 if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
4971 *filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
4972 else
4973 *filter_flags &= ~RXON_FILTER_BCON_AWARE_MSK;
4974 }
4975
4976 /* We avoid iwl_commit_rxon here to commit the new filter flags
4977 * since mac80211 will call ieee80211_hw_config immediately.
4978 * (mc_list is not supported at this time). Otherwise, we need to
4979 * queue a background iwl_commit_rxon work.
4980 */
4981
4982 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
Rick Farrington25b3f572008-06-30 17:23:28 +08004983 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
Johannes Berg4150c572007-09-17 01:29:23 -04004984}
4985
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004986static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004987 struct ieee80211_if_init_conf *conf)
4988{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004989 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004990
4991 IWL_DEBUG_MAC80211("enter\n");
4992
4993 mutex_lock(&priv->mutex);
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004994
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004995 if (iwl_is_ready_rf(priv)) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004996 iwl_scan_cancel_timeout(priv, 100);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004997 priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Mohamed Abbasfde35712007-11-29 11:10:15 +08004998 iwl3945_commit_rxon(priv);
4999 }
Johannes Berg32bfd352007-12-19 01:31:26 +01005000 if (priv->vif == conf->vif) {
5001 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07005002 memset(priv->bssid, 0, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07005003 }
5004 mutex_unlock(&priv->mutex);
5005
5006 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07005007}
5008
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005009#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
5010
5011static void iwl3945_bss_info_changed(struct ieee80211_hw *hw,
5012 struct ieee80211_vif *vif,
5013 struct ieee80211_bss_conf *bss_conf,
5014 u32 changes)
5015{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005016 struct iwl_priv *priv = hw->priv;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005017
5018 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes);
5019
5020 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
5021 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
5022 bss_conf->use_short_preamble);
5023 if (bss_conf->use_short_preamble)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005024 priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005025 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005026 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005027 }
5028
5029 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
5030 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot);
5031 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005032 priv->staging39_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005033 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005034 priv->staging39_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005035 }
5036
5037 if (changes & BSS_CHANGED_ASSOC) {
5038 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc);
5039 /* This should never happen as this function should
5040 * never be called from interrupt context. */
5041 if (WARN_ON_ONCE(in_interrupt()))
5042 return;
5043 if (bss_conf->assoc) {
5044 priv->assoc_id = bss_conf->aid;
5045 priv->beacon_int = bss_conf->beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08005046 priv->timestamp = bss_conf->timestamp;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005047 priv->assoc_capability = bss_conf->assoc_capability;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08005048 priv->power_data.dtim_period = bss_conf->dtim_period;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005049 priv->next_scan_jiffies = jiffies +
5050 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
5051 mutex_lock(&priv->mutex);
5052 iwl3945_post_associate(priv);
5053 mutex_unlock(&priv->mutex);
5054 } else {
5055 priv->assoc_id = 0;
5056 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc);
5057 }
5058 } else if (changes && iwl3945_is_associated(priv) && priv->assoc_id) {
5059 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes);
5060 iwl3945_send_rxon_assoc(priv);
5061 }
5062
5063}
5064
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005065static int iwl3945_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
Zhu Yib481de92007-09-25 17:54:57 -07005066{
5067 int rc = 0;
5068 unsigned long flags;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005069 struct iwl_priv *priv = hw->priv;
John W. Linville9387b7c2008-09-30 20:59:05 -04005070 DECLARE_SSID_BUF(ssid_buf);
Zhu Yib481de92007-09-25 17:54:57 -07005071
5072 IWL_DEBUG_MAC80211("enter\n");
5073
Mohamed Abbas15e869d2007-10-25 17:15:46 +08005074 mutex_lock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07005075 spin_lock_irqsave(&priv->lock, flags);
5076
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005077 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005078 rc = -EIO;
5079 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
5080 goto out_unlock;
5081 }
5082
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08005083 /* we don't schedule scan within next_scan_jiffies period */
5084 if (priv->next_scan_jiffies &&
5085 time_after(priv->next_scan_jiffies, jiffies)) {
5086 rc = -EAGAIN;
5087 goto out_unlock;
5088 }
Bill Moss15dbf1b2008-05-06 11:05:15 +08005089 /* if we just finished scan ask for delay for a broadcast scan */
5090 if ((len == 0) && priv->last_scan_jiffies &&
5091 time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN,
5092 jiffies)) {
Zhu Yib481de92007-09-25 17:54:57 -07005093 rc = -EAGAIN;
5094 goto out_unlock;
5095 }
5096 if (len) {
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08005097 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
John W. Linville9387b7c2008-09-30 20:59:05 -04005098 print_ssid(ssid_buf, ssid, len), (int)len);
Zhu Yib481de92007-09-25 17:54:57 -07005099
5100 priv->one_direct_scan = 1;
5101 priv->direct_ssid_len = (u8)
5102 min((u8) len, (u8) IW_ESSID_MAX_SIZE);
5103 memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08005104 } else
5105 priv->one_direct_scan = 0;
Zhu Yib481de92007-09-25 17:54:57 -07005106
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005107 rc = iwl3945_scan_initiate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005108
5109 IWL_DEBUG_MAC80211("leave\n");
5110
5111out_unlock:
5112 spin_unlock_irqrestore(&priv->lock, flags);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08005113 mutex_unlock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07005114
5115 return rc;
5116}
5117
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005118static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01005119 struct ieee80211_vif *vif,
5120 struct ieee80211_sta *sta,
5121 struct ieee80211_key_conf *key)
Zhu Yib481de92007-09-25 17:54:57 -07005122{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005123 struct iwl_priv *priv = hw->priv;
Johannes Bergdc822b52008-12-29 12:55:09 +01005124 const u8 *addr;
Winkler, Tomas42986792009-01-19 15:30:22 -08005125 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07005126 u8 sta_id;
5127
5128 IWL_DEBUG_MAC80211("enter\n");
5129
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005130 if (iwl3945_mod_params.sw_crypto) {
Zhu Yib481de92007-09-25 17:54:57 -07005131 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
5132 return -EOPNOTSUPP;
5133 }
5134
Winkler, Tomas42986792009-01-19 15:30:22 -08005135 addr = sta ? sta->addr : iwl_bcast_addr;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005136 sta_id = iwl3945_hw_find_station(priv, addr);
Zhu Yib481de92007-09-25 17:54:57 -07005137 if (sta_id == IWL_INVALID_STATION) {
Johannes Berge1749612008-10-27 15:59:26 -07005138 IWL_DEBUG_MAC80211("leave - %pM not in station map.\n",
5139 addr);
Zhu Yib481de92007-09-25 17:54:57 -07005140 return -EINVAL;
5141 }
5142
5143 mutex_lock(&priv->mutex);
5144
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08005145 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08005146
Zhu Yib481de92007-09-25 17:54:57 -07005147 switch (cmd) {
5148 case SET_KEY:
Winkler, Tomas42986792009-01-19 15:30:22 -08005149 ret = iwl3945_update_sta_key_info(priv, key, sta_id);
5150 if (!ret) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005151 iwl3945_set_rxon_hwcrypto(priv, 1);
5152 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005153 key->hw_key_idx = sta_id;
5154 IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n");
5155 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
5156 }
5157 break;
5158 case DISABLE_KEY:
Winkler, Tomas42986792009-01-19 15:30:22 -08005159 ret = iwl3945_clear_sta_key_info(priv, sta_id);
5160 if (!ret) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005161 iwl3945_set_rxon_hwcrypto(priv, 0);
5162 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005163 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
5164 }
5165 break;
5166 default:
Winkler, Tomas42986792009-01-19 15:30:22 -08005167 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07005168 }
5169
5170 IWL_DEBUG_MAC80211("leave\n");
5171 mutex_unlock(&priv->mutex);
5172
Winkler, Tomas42986792009-01-19 15:30:22 -08005173 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07005174}
5175
Johannes Berge100bb62008-04-30 18:51:21 +02005176static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
Zhu Yib481de92007-09-25 17:54:57 -07005177 const struct ieee80211_tx_queue_params *params)
5178{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005179 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07005180 unsigned long flags;
5181 int q;
Zhu Yib481de92007-09-25 17:54:57 -07005182
5183 IWL_DEBUG_MAC80211("enter\n");
5184
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005185 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005186 IWL_DEBUG_MAC80211("leave - RF not ready\n");
5187 return -EIO;
5188 }
5189
5190 if (queue >= AC_NUM) {
5191 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
5192 return 0;
5193 }
5194
Zhu Yib481de92007-09-25 17:54:57 -07005195 q = AC_NUM - 1 - queue;
5196
5197 spin_lock_irqsave(&priv->lock, flags);
5198
5199 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
5200 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
5201 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
5202 priv->qos_data.def_qos_parm.ac[q].edca_txop =
Johannes Berg3330d7be2008-02-10 16:49:38 +01005203 cpu_to_le16((params->txop * 32));
Zhu Yib481de92007-09-25 17:54:57 -07005204
5205 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
5206 priv->qos_data.qos_active = 1;
5207
5208 spin_unlock_irqrestore(&priv->lock, flags);
5209
5210 mutex_lock(&priv->mutex);
Johannes Berg05c914f2008-09-11 00:01:58 +02005211 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005212 iwl3945_activate_qos(priv, 1);
5213 else if (priv->assoc_id && iwl3945_is_associated(priv))
5214 iwl3945_activate_qos(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07005215
5216 mutex_unlock(&priv->mutex);
5217
Zhu Yib481de92007-09-25 17:54:57 -07005218 IWL_DEBUG_MAC80211("leave\n");
5219 return 0;
5220}
5221
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005222static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07005223 struct ieee80211_tx_queue_stats *stats)
5224{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005225 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07005226 int i, avail;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08005227 struct iwl_tx_queue *txq;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08005228 struct iwl_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07005229 unsigned long flags;
5230
5231 IWL_DEBUG_MAC80211("enter\n");
5232
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005233 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005234 IWL_DEBUG_MAC80211("leave - RF not ready\n");
5235 return -EIO;
5236 }
5237
5238 spin_lock_irqsave(&priv->lock, flags);
5239
5240 for (i = 0; i < AC_NUM; i++) {
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08005241 txq = &priv->txq[i];
Zhu Yib481de92007-09-25 17:54:57 -07005242 q = &txq->q;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08005243 avail = iwl_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07005244
Johannes Berg57ffc582008-04-29 17:18:59 +02005245 stats[i].len = q->n_window - avail;
5246 stats[i].limit = q->n_window - q->high_mark;
5247 stats[i].count = q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -07005248
5249 }
5250 spin_unlock_irqrestore(&priv->lock, flags);
5251
5252 IWL_DEBUG_MAC80211("leave\n");
5253
5254 return 0;
5255}
5256
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005257static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07005258{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005259 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07005260 unsigned long flags;
5261
5262 mutex_lock(&priv->mutex);
5263 IWL_DEBUG_MAC80211("enter\n");
5264
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005265 iwl_reset_qos(priv);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08005266
Zhu Yib481de92007-09-25 17:54:57 -07005267 spin_lock_irqsave(&priv->lock, flags);
5268 priv->assoc_id = 0;
5269 priv->assoc_capability = 0;
Zhu Yib481de92007-09-25 17:54:57 -07005270
5271 /* new association get rid of ibss beacon skb */
5272 if (priv->ibss_beacon)
5273 dev_kfree_skb(priv->ibss_beacon);
5274
5275 priv->ibss_beacon = NULL;
5276
5277 priv->beacon_int = priv->hw->conf.beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08005278 priv->timestamp = 0;
Johannes Berg05c914f2008-09-11 00:01:58 +02005279 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
Zhu Yib481de92007-09-25 17:54:57 -07005280 priv->beacon_int = 0;
5281
5282 spin_unlock_irqrestore(&priv->lock, flags);
5283
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005284 if (!iwl_is_ready_rf(priv)) {
Mohamed Abbasfde35712007-11-29 11:10:15 +08005285 IWL_DEBUG_MAC80211("leave - not ready\n");
5286 mutex_unlock(&priv->mutex);
5287 return;
5288 }
5289
Mohamed Abbas15e869d2007-10-25 17:15:46 +08005290 /* we are restarting association process
5291 * clear RXON_FILTER_ASSOC_MSK bit
5292 */
Johannes Berg05c914f2008-09-11 00:01:58 +02005293 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08005294 iwl_scan_cancel_timeout(priv, 100);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005295 priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005296 iwl3945_commit_rxon(priv);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08005297 }
5298
Zhu Yib481de92007-09-25 17:54:57 -07005299 /* Per mac80211.h: This is only used in IBSS mode... */
Johannes Berg05c914f2008-09-11 00:01:58 +02005300 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Mohamed Abbas15e869d2007-10-25 17:15:46 +08005301
Zhu Yib481de92007-09-25 17:54:57 -07005302 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
5303 mutex_unlock(&priv->mutex);
5304 return;
5305 }
5306
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005307 iwl3945_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005308
5309 mutex_unlock(&priv->mutex);
5310
5311 IWL_DEBUG_MAC80211("leave\n");
5312
5313}
5314
Johannes Berge039fa42008-05-15 12:55:29 +02005315static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07005316{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005317 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07005318 unsigned long flags;
5319
Zhu Yib481de92007-09-25 17:54:57 -07005320 IWL_DEBUG_MAC80211("enter\n");
5321
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005322 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005323 IWL_DEBUG_MAC80211("leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07005324 return -EIO;
5325 }
5326
Johannes Berg05c914f2008-09-11 00:01:58 +02005327 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Zhu Yib481de92007-09-25 17:54:57 -07005328 IWL_DEBUG_MAC80211("leave - not IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07005329 return -EIO;
5330 }
5331
5332 spin_lock_irqsave(&priv->lock, flags);
5333
5334 if (priv->ibss_beacon)
5335 dev_kfree_skb(priv->ibss_beacon);
5336
5337 priv->ibss_beacon = skb;
5338
5339 priv->assoc_id = 0;
5340
5341 IWL_DEBUG_MAC80211("leave\n");
5342 spin_unlock_irqrestore(&priv->lock, flags);
5343
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005344 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005345
Abhijeet Kolekardc4b1e72008-09-03 11:26:30 +08005346 iwl3945_post_associate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005347
Zhu Yib481de92007-09-25 17:54:57 -07005348
5349 return 0;
5350}
5351
5352/*****************************************************************************
5353 *
5354 * sysfs attributes
5355 *
5356 *****************************************************************************/
5357
Samuel Ortizd08853a2009-01-23 13:45:17 -08005358#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07005359
5360/*
5361 * The following adds a new attribute to the sysfs representation
5362 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
5363 * used for controlling the debug level.
5364 *
5365 * See the level definitions in iwl for details.
5366 */
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005367static ssize_t show_debug_level(struct device *d,
5368 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07005369{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005370 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005371
5372 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07005373}
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005374static ssize_t store_debug_level(struct device *d,
5375 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07005376 const char *buf, size_t count)
5377{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005378 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005379 unsigned long val;
5380 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07005381
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005382 ret = strict_strtoul(buf, 0, &val);
5383 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08005384 IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07005385 else
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005386 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07005387
5388 return strnlen(buf, count);
5389}
5390
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005391static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
5392 show_debug_level, store_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07005393
Samuel Ortizd08853a2009-01-23 13:45:17 -08005394#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07005395
Zhu Yib481de92007-09-25 17:54:57 -07005396static ssize_t show_temperature(struct device *d,
5397 struct device_attribute *attr, char *buf)
5398{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005399 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07005400
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005401 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07005402 return -EAGAIN;
5403
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005404 return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
Zhu Yib481de92007-09-25 17:54:57 -07005405}
5406
5407static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
5408
Zhu Yib481de92007-09-25 17:54:57 -07005409static ssize_t show_tx_power(struct device *d,
5410 struct device_attribute *attr, char *buf)
5411{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005412 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08005413 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07005414}
5415
5416static ssize_t store_tx_power(struct device *d,
5417 struct device_attribute *attr,
5418 const char *buf, size_t count)
5419{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005420 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07005421 char *p = (char *)buf;
5422 u32 val;
5423
5424 val = simple_strtoul(p, &p, 10);
5425 if (p == buf)
Tomas Winkler978785a2008-12-19 10:37:31 +08005426 IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07005427 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005428 iwl3945_hw_reg_set_txpower(priv, val);
Zhu Yib481de92007-09-25 17:54:57 -07005429
5430 return count;
5431}
5432
5433static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
5434
5435static ssize_t show_flags(struct device *d,
5436 struct device_attribute *attr, char *buf)
5437{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005438 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07005439
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005440 return sprintf(buf, "0x%04X\n", priv->active39_rxon.flags);
Zhu Yib481de92007-09-25 17:54:57 -07005441}
5442
5443static ssize_t store_flags(struct device *d,
5444 struct device_attribute *attr,
5445 const char *buf, size_t count)
5446{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005447 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07005448 u32 flags = simple_strtoul(buf, NULL, 0);
5449
5450 mutex_lock(&priv->mutex);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005451 if (le32_to_cpu(priv->staging39_rxon.flags) != flags) {
Zhu Yib481de92007-09-25 17:54:57 -07005452 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08005453 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08005454 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07005455 else {
5456 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
5457 flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005458 priv->staging39_rxon.flags = cpu_to_le32(flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005459 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005460 }
5461 }
5462 mutex_unlock(&priv->mutex);
5463
5464 return count;
5465}
5466
5467static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
5468
5469static ssize_t show_filter_flags(struct device *d,
5470 struct device_attribute *attr, char *buf)
5471{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005472 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07005473
5474 return sprintf(buf, "0x%04X\n",
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005475 le32_to_cpu(priv->active39_rxon.filter_flags));
Zhu Yib481de92007-09-25 17:54:57 -07005476}
5477
5478static ssize_t store_filter_flags(struct device *d,
5479 struct device_attribute *attr,
5480 const char *buf, size_t count)
5481{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005482 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07005483 u32 filter_flags = simple_strtoul(buf, NULL, 0);
5484
5485 mutex_lock(&priv->mutex);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005486 if (le32_to_cpu(priv->staging39_rxon.filter_flags) != filter_flags) {
Zhu Yib481de92007-09-25 17:54:57 -07005487 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08005488 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08005489 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07005490 else {
5491 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
5492 "0x%04X\n", filter_flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005493 priv->staging39_rxon.filter_flags =
Zhu Yib481de92007-09-25 17:54:57 -07005494 cpu_to_le32(filter_flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005495 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005496 }
5497 }
5498 mutex_unlock(&priv->mutex);
5499
5500 return count;
5501}
5502
5503static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
5504 store_filter_flags);
5505
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08005506#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07005507
5508static ssize_t show_measurement(struct device *d,
5509 struct device_attribute *attr, char *buf)
5510{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005511 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler600c0e12008-12-19 10:37:04 +08005512 struct iwl_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07005513 u32 size = sizeof(measure_report), len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03005514 u8 *data = (u8 *)&measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07005515 unsigned long flags;
5516
5517 spin_lock_irqsave(&priv->lock, flags);
5518 if (!(priv->measurement_status & MEASUREMENT_READY)) {
5519 spin_unlock_irqrestore(&priv->lock, flags);
5520 return 0;
5521 }
5522 memcpy(&measure_report, &priv->measure_report, size);
5523 priv->measurement_status = 0;
5524 spin_unlock_irqrestore(&priv->lock, flags);
5525
5526 while (size && (PAGE_SIZE - len)) {
5527 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
5528 PAGE_SIZE - len, 1);
5529 len = strlen(buf);
5530 if (PAGE_SIZE - len)
5531 buf[len++] = '\n';
5532
5533 ofs += 16;
5534 size -= min(size, 16U);
5535 }
5536
5537 return len;
5538}
5539
5540static ssize_t store_measurement(struct device *d,
5541 struct device_attribute *attr,
5542 const char *buf, size_t count)
5543{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005544 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07005545 struct ieee80211_measurement_params params = {
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005546 .channel = le16_to_cpu(priv->active39_rxon.channel),
Zhu Yib481de92007-09-25 17:54:57 -07005547 .start_time = cpu_to_le64(priv->last_tsf),
5548 .duration = cpu_to_le16(1),
5549 };
5550 u8 type = IWL_MEASURE_BASIC;
5551 u8 buffer[32];
5552 u8 channel;
5553
5554 if (count) {
5555 char *p = buffer;
5556 strncpy(buffer, buf, min(sizeof(buffer), count));
5557 channel = simple_strtoul(p, NULL, 0);
5558 if (channel)
5559 params.channel = channel;
5560
5561 p = buffer;
5562 while (*p && *p != ' ')
5563 p++;
5564 if (*p)
5565 type = simple_strtoul(p + 1, NULL, 0);
5566 }
5567
5568 IWL_DEBUG_INFO("Invoking measurement of type %d on "
5569 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005570 iwl3945_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07005571
5572 return count;
5573}
5574
5575static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
5576 show_measurement, store_measurement);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08005577#endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07005578
Zhu Yib481de92007-09-25 17:54:57 -07005579static ssize_t store_retry_rate(struct device *d,
5580 struct device_attribute *attr,
5581 const char *buf, size_t count)
5582{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005583 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07005584
5585 priv->retry_rate = simple_strtoul(buf, NULL, 0);
5586 if (priv->retry_rate <= 0)
5587 priv->retry_rate = 1;
5588
5589 return count;
5590}
5591
5592static ssize_t show_retry_rate(struct device *d,
5593 struct device_attribute *attr, char *buf)
5594{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005595 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07005596 return sprintf(buf, "%d", priv->retry_rate);
5597}
5598
5599static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
5600 store_retry_rate);
5601
5602static ssize_t store_power_level(struct device *d,
5603 struct device_attribute *attr,
5604 const char *buf, size_t count)
5605{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005606 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07005607 int rc;
5608 int mode;
5609
5610 mode = simple_strtoul(buf, NULL, 0);
5611 mutex_lock(&priv->mutex);
5612
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005613 if (!iwl_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005614 rc = -EAGAIN;
5615 goto out;
5616 }
5617
Samuel Ortiz1125eff2008-12-19 10:37:14 +08005618 if ((mode < 1) || (mode > IWL39_POWER_LIMIT) ||
5619 (mode == IWL39_POWER_AC))
5620 mode = IWL39_POWER_AC;
Zhu Yib481de92007-09-25 17:54:57 -07005621 else
5622 mode |= IWL_POWER_ENABLED;
5623
5624 if (mode != priv->power_mode) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005625 rc = iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(mode));
Zhu Yib481de92007-09-25 17:54:57 -07005626 if (rc) {
5627 IWL_DEBUG_MAC80211("failed setting power mode.\n");
5628 goto out;
5629 }
5630 priv->power_mode = mode;
5631 }
5632
5633 rc = count;
5634
5635 out:
5636 mutex_unlock(&priv->mutex);
5637 return rc;
5638}
5639
5640#define MAX_WX_STRING 80
5641
5642/* Values are in microsecond */
5643static const s32 timeout_duration[] = {
5644 350000,
5645 250000,
5646 75000,
5647 37000,
5648 25000,
5649};
5650static const s32 period_duration[] = {
5651 400000,
5652 700000,
5653 1000000,
5654 1000000,
5655 1000000
5656};
5657
5658static ssize_t show_power_level(struct device *d,
5659 struct device_attribute *attr, char *buf)
5660{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005661 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07005662 int level = IWL_POWER_LEVEL(priv->power_mode);
5663 char *p = buf;
5664
5665 p += sprintf(p, "%d ", level);
5666 switch (level) {
5667 case IWL_POWER_MODE_CAM:
Samuel Ortiz1125eff2008-12-19 10:37:14 +08005668 case IWL39_POWER_AC:
Zhu Yib481de92007-09-25 17:54:57 -07005669 p += sprintf(p, "(AC)");
5670 break;
Samuel Ortiz1125eff2008-12-19 10:37:14 +08005671 case IWL39_POWER_BATTERY:
Zhu Yib481de92007-09-25 17:54:57 -07005672 p += sprintf(p, "(BATTERY)");
5673 break;
5674 default:
5675 p += sprintf(p,
5676 "(Timeout %dms, Period %dms)",
5677 timeout_duration[level - 1] / 1000,
5678 period_duration[level - 1] / 1000);
5679 }
5680
5681 if (!(priv->power_mode & IWL_POWER_ENABLED))
5682 p += sprintf(p, " OFF\n");
5683 else
5684 p += sprintf(p, " \n");
5685
Tomas Winkler3ac7f142008-07-21 02:40:14 +03005686 return p - buf + 1;
Zhu Yib481de92007-09-25 17:54:57 -07005687
5688}
5689
5690static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
5691 store_power_level);
5692
5693static ssize_t show_channels(struct device *d,
5694 struct device_attribute *attr, char *buf)
5695{
Johannes Berg8318d782008-01-24 19:38:38 +01005696 /* all this shit doesn't belong into sysfs anyway */
5697 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07005698}
5699
5700static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
5701
5702static ssize_t show_statistics(struct device *d,
5703 struct device_attribute *attr, char *buf)
5704{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005705 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005706 u32 size = sizeof(struct iwl3945_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07005707 u32 len = 0, ofs = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005708 u8 *data = (u8 *)&priv->statistics_39;
Zhu Yib481de92007-09-25 17:54:57 -07005709 int rc = 0;
5710
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005711 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07005712 return -EAGAIN;
5713
5714 mutex_lock(&priv->mutex);
Samuel Ortiz17f841c2009-01-23 13:45:20 -08005715 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07005716 mutex_unlock(&priv->mutex);
5717
5718 if (rc) {
5719 len = sprintf(buf,
5720 "Error sending statistics request: 0x%08X\n", rc);
5721 return len;
5722 }
5723
5724 while (size && (PAGE_SIZE - len)) {
5725 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
5726 PAGE_SIZE - len, 1);
5727 len = strlen(buf);
5728 if (PAGE_SIZE - len)
5729 buf[len++] = '\n';
5730
5731 ofs += 16;
5732 size -= min(size, 16U);
5733 }
5734
5735 return len;
5736}
5737
5738static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
5739
5740static ssize_t show_antenna(struct device *d,
5741 struct device_attribute *attr, char *buf)
5742{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005743 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07005744
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005745 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07005746 return -EAGAIN;
5747
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08005748 return sprintf(buf, "%d\n", iwl3945_mod_params.antenna);
Zhu Yib481de92007-09-25 17:54:57 -07005749}
5750
5751static ssize_t store_antenna(struct device *d,
5752 struct device_attribute *attr,
5753 const char *buf, size_t count)
5754{
5755 int ant;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005756 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07005757
5758 if (count == 0)
5759 return 0;
5760
5761 if (sscanf(buf, "%1i", &ant) != 1) {
5762 IWL_DEBUG_INFO("not in hex or decimal form.\n");
5763 return count;
5764 }
5765
5766 if ((ant >= 0) && (ant <= 2)) {
5767 IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant);
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08005768 iwl3945_mod_params.antenna = (enum iwl3945_antenna)ant;
Zhu Yib481de92007-09-25 17:54:57 -07005769 } else
5770 IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant);
5771
5772
5773 return count;
5774}
5775
5776static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
5777
5778static ssize_t show_status(struct device *d,
5779 struct device_attribute *attr, char *buf)
5780{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005781 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005782 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07005783 return -EAGAIN;
5784 return sprintf(buf, "0x%08x\n", (int)priv->status);
5785}
5786
5787static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
5788
5789static ssize_t dump_error_log(struct device *d,
5790 struct device_attribute *attr,
5791 const char *buf, size_t count)
5792{
5793 char *p = (char *)buf;
5794
5795 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005796 iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07005797
5798 return strnlen(buf, count);
5799}
5800
5801static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
5802
5803static ssize_t dump_event_log(struct device *d,
5804 struct device_attribute *attr,
5805 const char *buf, size_t count)
5806{
5807 char *p = (char *)buf;
5808
5809 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005810 iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07005811
5812 return strnlen(buf, count);
5813}
5814
5815static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
5816
5817/*****************************************************************************
5818 *
Tomas Winklera96a27f2008-10-23 23:48:56 -07005819 * driver setup and tear down
Zhu Yib481de92007-09-25 17:54:57 -07005820 *
5821 *****************************************************************************/
5822
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005823static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005824{
5825 priv->workqueue = create_workqueue(DRV_NAME);
5826
5827 init_waitqueue_head(&priv->wait_command_queue);
5828
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005829 INIT_WORK(&priv->up, iwl3945_bg_up);
5830 INIT_WORK(&priv->restart, iwl3945_bg_restart);
5831 INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01005832 INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005833 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005834 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
5835 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
Helmut Schaa26635162009-01-15 09:38:44 +01005836 INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll);
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08005837 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
5838 INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
5839 INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
5840 INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
Zhu Yib481de92007-09-25 17:54:57 -07005841
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005842 iwl3945_hw_setup_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005843
5844 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005845 iwl3945_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07005846}
5847
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005848static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005849{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005850 iwl3945_hw_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005851
Joonwoo Parke47eb6a2007-11-29 10:42:49 +09005852 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07005853 cancel_delayed_work(&priv->scan_check);
5854 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07005855 cancel_work_sync(&priv->beacon_update);
5856}
5857
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005858static struct attribute *iwl3945_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07005859 &dev_attr_antenna.attr,
5860 &dev_attr_channels.attr,
5861 &dev_attr_dump_errors.attr,
5862 &dev_attr_dump_events.attr,
5863 &dev_attr_flags.attr,
5864 &dev_attr_filter_flags.attr,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08005865#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07005866 &dev_attr_measurement.attr,
5867#endif
5868 &dev_attr_power_level.attr,
Zhu Yib481de92007-09-25 17:54:57 -07005869 &dev_attr_retry_rate.attr,
Zhu Yib481de92007-09-25 17:54:57 -07005870 &dev_attr_statistics.attr,
5871 &dev_attr_status.attr,
5872 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07005873 &dev_attr_tx_power.attr,
Samuel Ortizd08853a2009-01-23 13:45:17 -08005874#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005875 &dev_attr_debug_level.attr,
5876#endif
Zhu Yib481de92007-09-25 17:54:57 -07005877 NULL
5878};
5879
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005880static struct attribute_group iwl3945_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07005881 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005882 .attrs = iwl3945_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07005883};
5884
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005885static struct ieee80211_ops iwl3945_hw_ops = {
5886 .tx = iwl3945_mac_tx,
5887 .start = iwl3945_mac_start,
5888 .stop = iwl3945_mac_stop,
5889 .add_interface = iwl3945_mac_add_interface,
5890 .remove_interface = iwl3945_mac_remove_interface,
5891 .config = iwl3945_mac_config,
5892 .config_interface = iwl3945_mac_config_interface,
5893 .configure_filter = iwl3945_configure_filter,
5894 .set_key = iwl3945_mac_set_key,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005895 .get_tx_stats = iwl3945_mac_get_tx_stats,
5896 .conf_tx = iwl3945_mac_conf_tx,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005897 .reset_tsf = iwl3945_mac_reset_tsf,
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005898 .bss_info_changed = iwl3945_bss_info_changed,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005899 .hw_scan = iwl3945_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07005900};
5901
Winkler, Tomase52119c2008-12-22 11:31:19 +08005902static int iwl3945_init_drv(struct iwl_priv *priv)
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005903{
5904 int ret;
Samuel Ortize6148912009-01-23 13:45:15 -08005905 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005906
5907 priv->retry_rate = 1;
5908 priv->ibss_beacon = NULL;
5909
5910 spin_lock_init(&priv->lock);
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08005911 spin_lock_init(&priv->power_data.lock);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005912 spin_lock_init(&priv->sta_lock);
5913 spin_lock_init(&priv->hcmd_lock);
5914
5915 INIT_LIST_HEAD(&priv->free_frames);
5916
5917 mutex_init(&priv->mutex);
5918
5919 /* Clear the driver's (not device's) station table */
5920 iwl3945_clear_stations_table(priv);
5921
5922 priv->data_retry_limit = -1;
5923 priv->ieee_channels = NULL;
5924 priv->ieee_rates = NULL;
5925 priv->band = IEEE80211_BAND_2GHZ;
5926
5927 priv->iw_mode = NL80211_IFTYPE_STATION;
5928
5929 iwl_reset_qos(priv);
5930
5931 priv->qos_data.qos_active = 0;
5932 priv->qos_data.qos_cap.val = 0;
5933
5934 priv->rates_mask = IWL_RATES_MASK;
5935 /* If power management is turned on, default to AC mode */
Samuel Ortizc7a7c8e2009-01-08 10:20:01 -08005936 priv->power_mode = IWL39_POWER_AC;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08005937 priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005938
Samuel Ortize6148912009-01-23 13:45:15 -08005939 if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
5940 IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
5941 eeprom->version);
5942 ret = -EINVAL;
5943 goto err;
5944 }
5945 ret = iwl_init_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005946 if (ret) {
5947 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
5948 goto err;
5949 }
5950
Samuel Ortize6148912009-01-23 13:45:15 -08005951 /* Set up txpower settings in driver for all channels */
5952 if (iwl3945_txpower_set_from_eeprom(priv)) {
5953 ret = -EIO;
5954 goto err_free_channel_map;
5955 }
5956
Samuel Ortiz534166d2009-01-23 13:45:16 -08005957 ret = iwlcore_init_geos(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005958 if (ret) {
5959 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
5960 goto err_free_channel_map;
5961 }
Samuel Ortiz534166d2009-01-23 13:45:16 -08005962 iwl3945_init_hw_rates(priv, priv->ieee_rates);
5963
5964 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
5965 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
5966 &priv->bands[IEEE80211_BAND_2GHZ];
5967 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
5968 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
5969 &priv->bands[IEEE80211_BAND_5GHZ];
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005970
5971 return 0;
5972
5973err_free_channel_map:
Samuel Ortize6148912009-01-23 13:45:15 -08005974 iwl_free_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005975err:
5976 return ret;
5977}
5978
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005979static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07005980{
5981 int err = 0;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005982 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07005983 struct ieee80211_hw *hw;
Kolekar, Abhijeetc0f20d92008-12-19 10:37:19 +08005984 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Samuel Ortize6148912009-01-23 13:45:15 -08005985 struct iwl3945_eeprom *eeprom;
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005986 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07005987
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005988 /***********************
5989 * 1. Allocating HW data
5990 * ********************/
5991
Zhu Yib481de92007-09-25 17:54:57 -07005992 /* mac80211 allocates memory for this device instance, including
5993 * space for this driver's private structure */
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005994 hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
Zhu Yib481de92007-09-25 17:54:57 -07005995 if (hw == NULL) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005996 printk(KERN_ERR DRV_NAME "Can not allocate network device\n");
Zhu Yib481de92007-09-25 17:54:57 -07005997 err = -ENOMEM;
5998 goto out;
5999 }
Zhu Yib481de92007-09-25 17:54:57 -07006000 priv = hw->priv;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006001 SET_IEEE80211_DEV(hw, &pdev->dev);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08006002
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08006003 if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) ||
6004 (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08006005 IWL_ERR(priv,
6006 "invalid queues_num, should be between %d and %d\n",
6007 IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES);
Samuel Ortiza3139c52008-12-19 10:37:09 +08006008 err = -EINVAL;
6009 goto out;
6010 }
6011
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006012 /*
6013 * Disabling hardware scan means that mac80211 will perform scans
6014 * "the hard way", rather than using device's scan.
6015 */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08006016 if (iwl3945_mod_params.disable_hw_scan) {
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08006017 IWL_DEBUG_INFO("Disabling hw_scan\n");
6018 iwl3945_hw_ops.hw_scan = NULL;
6019 }
6020
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006021
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006022 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006023 priv->cfg = cfg;
6024 priv->pci_dev = pdev;
6025
Samuel Ortizd08853a2009-01-23 13:45:17 -08006026#ifdef CONFIG_IWLWIFI_DEBUG
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006027 priv->debug_level = iwl3945_mod_params.debug;
6028 atomic_set(&priv->restrict_refcnt, 0);
6029#endif
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006030 hw->rate_control_algorithm = "iwl-3945-rs";
6031 hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
6032
Bruno Randolf566bfe52008-05-08 19:15:40 +02006033 /* Tell mac80211 our characteristics */
Johannes Berg605a0bd2008-07-15 10:10:01 +02006034 hw->flags = IEEE80211_HW_SIGNAL_DBM |
Bruno Randolf566bfe52008-05-08 19:15:40 +02006035 IEEE80211_HW_NOISE_DBM;
Zhu Yib481de92007-09-25 17:54:57 -07006036
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -07006037 hw->wiphy->interface_modes =
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -07006038 BIT(NL80211_IFTYPE_STATION) |
6039 BIT(NL80211_IFTYPE_ADHOC);
6040
Luis R. Rodriguez2a44f912009-01-22 15:05:49 -08006041 hw->wiphy->custom_regulatory = true;
Luis R. Rodriguezea4a82dc2008-11-12 14:22:04 -08006042
Cahill, Ben M6440adb2007-11-29 11:09:55 +08006043 /* 4 EDCA QOS priorities */
Zhu Yib481de92007-09-25 17:54:57 -07006044 hw->queues = 4;
6045
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006046 /***************************
6047 * 2. Initializing PCI bus
6048 * *************************/
Zhu Yib481de92007-09-25 17:54:57 -07006049 if (pci_enable_device(pdev)) {
6050 err = -ENODEV;
6051 goto out_ieee80211_free_hw;
6052 }
6053
6054 pci_set_master(pdev);
6055
Zhu Yib481de92007-09-25 17:54:57 -07006056 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
6057 if (!err)
6058 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
6059 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08006060 IWL_WARN(priv, "No suitable DMA available.\n");
Zhu Yib481de92007-09-25 17:54:57 -07006061 goto out_pci_disable_device;
6062 }
6063
6064 pci_set_drvdata(pdev, priv);
6065 err = pci_request_regions(pdev, DRV_NAME);
6066 if (err)
6067 goto out_pci_disable_device;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08006068
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006069 /***********************
6070 * 3. Read REV Register
6071 * ********************/
Zhu Yib481de92007-09-25 17:54:57 -07006072 priv->hw_base = pci_iomap(pdev, 0, 0);
6073 if (!priv->hw_base) {
6074 err = -ENODEV;
6075 goto out_pci_release_regions;
6076 }
6077
6078 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
6079 (unsigned long long) pci_resource_len(pdev, 0));
6080 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
6081
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006082 /* We disable the RETRY_TIMEOUT register (0x41) to keep
6083 * PCI Tx retries from interfering with C3 CPU state */
6084 pci_write_config_byte(pdev, 0x41, 0x00);
Zhu Yib481de92007-09-25 17:54:57 -07006085
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006086 /* amp init */
6087 err = priv->cfg->ops->lib->apm_ops.init(priv);
Tomas Winkler3ac7f142008-07-21 02:40:14 +03006088 if (err < 0) {
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006089 IWL_DEBUG_INFO("Failed to init APMG\n");
6090 goto out_iounmap;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03006091 }
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006092
6093 /***********************
6094 * 4. Read EEPROM
6095 * ********************/
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006096
Zhu Yi5a669262008-01-14 17:46:18 -08006097 /* Read the EEPROM */
Samuel Ortize6148912009-01-23 13:45:15 -08006098 err = iwl_eeprom_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006099 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08006100 IWL_ERR(priv, "Unable to init EEPROM\n");
Zhu Yi5a669262008-01-14 17:46:18 -08006101 goto out_remove_sysfs;
6102 }
6103 /* MAC Address location in EEPROM same for 3945/4965 */
Samuel Ortize6148912009-01-23 13:45:15 -08006104 eeprom = (struct iwl3945_eeprom *)priv->eeprom;
6105 memcpy(priv->mac_addr, eeprom->mac_address, ETH_ALEN);
Johannes Berge1749612008-10-27 15:59:26 -07006106 IWL_DEBUG_INFO("MAC address: %pM\n", priv->mac_addr);
Zhu Yi5a669262008-01-14 17:46:18 -08006107 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
6108
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006109 /***********************
6110 * 5. Setup HW Constants
6111 * ********************/
6112 /* Device-specific setup */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08006113 if (iwl3945_hw_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08006114 IWL_ERR(priv, "failed to set hw settings\n");
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006115 goto out_iounmap;
6116 }
6117
6118 /***********************
6119 * 6. Setup priv
6120 * ********************/
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006121
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006122 err = iwl3945_init_drv(priv);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08006123 if (err) {
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006124 IWL_ERR(priv, "initializing driver failed\n");
6125 goto out_free_geos;
Reinette Chatre849e0dc2008-01-23 10:15:18 -08006126 }
Reinette Chatre849e0dc2008-01-23 10:15:18 -08006127
Tomas Winkler978785a2008-12-19 10:37:31 +08006128 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
6129 priv->cfg->name);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006130
6131 /***********************************
6132 * 7. Initialize Module Parameters
6133 * **********************************/
6134
6135 /* Initialize module parameter values here */
6136 /* Disable radio (SW RF KILL) via parameter when loading driver */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08006137 if (iwl3945_mod_params.disable) {
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006138 set_bit(STATUS_RF_KILL_SW, &priv->status);
6139 IWL_DEBUG_INFO("Radio disabled.\n");
6140 }
6141
6142
6143 /***********************
6144 * 8. Setup Services
6145 * ********************/
6146
6147 spin_lock_irqsave(&priv->lock, flags);
6148 iwl3945_disable_interrupts(priv);
6149 spin_unlock_irqrestore(&priv->lock, flags);
6150
Helmut Schaa26635162009-01-15 09:38:44 +01006151 pci_enable_msi(priv->pci_dev);
6152
6153 err = request_irq(priv->pci_dev->irq, iwl3945_isr, IRQF_SHARED,
6154 DRV_NAME, priv);
6155 if (err) {
6156 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
6157 goto out_disable_msi;
6158 }
6159
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006160 err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
6161 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08006162 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006163 goto out_release_irq;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006164 }
6165
6166 iwl3945_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6);
6167 iwl3945_setup_deferred_work(priv);
6168 iwl3945_setup_rx_handlers(priv);
6169
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006170 /*********************************
Helmut Schaa26635162009-01-15 09:38:44 +01006171 * 9. Setup and Register mac80211
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006172 * *******************************/
6173
Zhu Yi5a669262008-01-14 17:46:18 -08006174 err = ieee80211_register_hw(priv->hw);
6175 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08006176 IWL_ERR(priv, "Failed to register network device: %d\n", err);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006177 goto out_remove_sysfs;
Zhu Yib481de92007-09-25 17:54:57 -07006178 }
6179
Zhu Yi5a669262008-01-14 17:46:18 -08006180 priv->hw->conf.beacon_int = 100;
6181 priv->mac80211_registered = 1;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006182
Samuel Ortizc0af96a2009-01-21 18:27:54 +01006183 err = iwl_rfkill_init(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08006184 if (err)
Winkler, Tomas15b16872008-12-19 10:37:33 +08006185 IWL_ERR(priv, "Unable to initialize RFKILL system. "
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08006186 "Ignoring error: %d\n", err);
6187
Helmut Schaa26635162009-01-15 09:38:44 +01006188 /* Start monitoring the killswitch */
6189 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
6190 2 * HZ);
6191
Zhu Yib481de92007-09-25 17:54:57 -07006192 return 0;
6193
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006194 out_remove_sysfs:
6195 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08006196 out_free_geos:
Samuel Ortiz534166d2009-01-23 13:45:16 -08006197 iwlcore_free_geos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006198
6199 out_release_irq:
Helmut Schaa26635162009-01-15 09:38:44 +01006200 free_irq(priv->pci_dev->irq, priv);
Zhu Yib481de92007-09-25 17:54:57 -07006201 destroy_workqueue(priv->workqueue);
6202 priv->workqueue = NULL;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08006203 iwl3945_unset_hw_params(priv);
Helmut Schaa26635162009-01-15 09:38:44 +01006204 out_disable_msi:
6205 pci_disable_msi(priv->pci_dev);
Zhu Yib481de92007-09-25 17:54:57 -07006206 out_iounmap:
6207 pci_iounmap(pdev, priv->hw_base);
6208 out_pci_release_regions:
6209 pci_release_regions(pdev);
6210 out_pci_disable_device:
6211 pci_disable_device(pdev);
6212 pci_set_drvdata(pdev, NULL);
6213 out_ieee80211_free_hw:
6214 ieee80211_free_hw(priv->hw);
6215 out:
6216 return err;
6217}
6218
Reinette Chatrec83dbf62008-03-21 13:53:41 -07006219static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07006220{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006221 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07006222 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07006223
6224 if (!priv)
6225 return;
6226
6227 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
6228
Zhu Yib481de92007-09-25 17:54:57 -07006229 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08006230
Kolekar, Abhijeetd552bfb2008-12-19 10:37:41 +08006231 if (priv->mac80211_registered) {
6232 ieee80211_unregister_hw(priv->hw);
6233 priv->mac80211_registered = 0;
6234 } else {
6235 iwl3945_down(priv);
6236 }
Zhu Yib481de92007-09-25 17:54:57 -07006237
Mohamed Abbas0359fac2008-03-28 16:21:08 -07006238 /* make sure we flush any pending irq or
6239 * tasklet for the driver
6240 */
6241 spin_lock_irqsave(&priv->lock, flags);
6242 iwl3945_disable_interrupts(priv);
6243 spin_unlock_irqrestore(&priv->lock, flags);
6244
6245 iwl_synchronize_irq(priv);
6246
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006247 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07006248
Samuel Ortizc0af96a2009-01-21 18:27:54 +01006249 iwl_rfkill_unregister(priv);
Helmut Schaa26635162009-01-15 09:38:44 +01006250 cancel_delayed_work(&priv->rfkill_poll);
6251
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006252 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006253
6254 if (priv->rxq.bd)
Winkler, Tomas51af3d32008-12-22 11:31:23 +08006255 iwl_rx_queue_free(priv, &priv->rxq);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006256 iwl3945_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006257
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08006258 iwl3945_unset_hw_params(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006259 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006260
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08006261 /*netif_stop_queue(dev); */
6262 flush_workqueue(priv->workqueue);
6263
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006264 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07006265 * priv->workqueue... so we can't take down the workqueue
6266 * until now... */
6267 destroy_workqueue(priv->workqueue);
6268 priv->workqueue = NULL;
6269
Helmut Schaa26635162009-01-15 09:38:44 +01006270 free_irq(pdev->irq, priv);
6271 pci_disable_msi(pdev);
6272
Zhu Yib481de92007-09-25 17:54:57 -07006273 pci_iounmap(pdev, priv->hw_base);
6274 pci_release_regions(pdev);
6275 pci_disable_device(pdev);
6276 pci_set_drvdata(pdev, NULL);
6277
Samuel Ortize6148912009-01-23 13:45:15 -08006278 iwl_free_channel_map(priv);
Samuel Ortiz534166d2009-01-23 13:45:16 -08006279 iwlcore_free_geos(priv);
Winkler, Tomas805cee52009-01-19 15:30:28 -08006280 kfree(priv->scan);
Zhu Yib481de92007-09-25 17:54:57 -07006281 if (priv->ibss_beacon)
6282 dev_kfree_skb(priv->ibss_beacon);
6283
6284 ieee80211_free_hw(priv->hw);
6285}
6286
6287#ifdef CONFIG_PM
6288
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006289static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Zhu Yib481de92007-09-25 17:54:57 -07006290{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006291 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07006292
Zhu Yie655b9f2008-01-24 02:19:38 -08006293 if (priv->is_open) {
6294 set_bit(STATUS_IN_SUSPEND, &priv->status);
6295 iwl3945_mac_stop(priv->hw);
6296 priv->is_open = 1;
6297 }
Helmut Schaa26635162009-01-15 09:38:44 +01006298 pci_save_state(pdev);
6299 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07006300 pci_set_power_state(pdev, PCI_D3hot);
6301
Zhu Yib481de92007-09-25 17:54:57 -07006302 return 0;
6303}
6304
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006305static int iwl3945_pci_resume(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07006306{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006307 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07006308
Zhu Yib481de92007-09-25 17:54:57 -07006309 pci_set_power_state(pdev, PCI_D0);
Helmut Schaa26635162009-01-15 09:38:44 +01006310 pci_enable_device(pdev);
6311 pci_restore_state(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07006312
Zhu Yie655b9f2008-01-24 02:19:38 -08006313 if (priv->is_open)
6314 iwl3945_mac_start(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07006315
Zhu Yie655b9f2008-01-24 02:19:38 -08006316 clear_bit(STATUS_IN_SUSPEND, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07006317 return 0;
6318}
6319
6320#endif /* CONFIG_PM */
6321
6322/*****************************************************************************
6323 *
6324 * driver and module entry point
6325 *
6326 *****************************************************************************/
6327
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006328static struct pci_driver iwl3945_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07006329 .name = DRV_NAME,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006330 .id_table = iwl3945_hw_card_ids,
6331 .probe = iwl3945_pci_probe,
6332 .remove = __devexit_p(iwl3945_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07006333#ifdef CONFIG_PM
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006334 .suspend = iwl3945_pci_suspend,
6335 .resume = iwl3945_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07006336#endif
6337};
6338
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006339static int __init iwl3945_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07006340{
6341
6342 int ret;
6343 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
6344 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07006345
6346 ret = iwl3945_rate_control_register();
6347 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08006348 printk(KERN_ERR DRV_NAME
6349 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07006350 return ret;
6351 }
6352
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006353 ret = pci_register_driver(&iwl3945_driver);
Zhu Yib481de92007-09-25 17:54:57 -07006354 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08006355 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07006356 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07006357 }
Zhu Yib481de92007-09-25 17:54:57 -07006358
6359 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07006360
Reinette Chatre897e1cf2008-03-28 16:21:09 -07006361error_register:
6362 iwl3945_rate_control_unregister();
6363 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07006364}
6365
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006366static void __exit iwl3945_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07006367{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006368 pci_unregister_driver(&iwl3945_driver);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07006369 iwl3945_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07006370}
6371
Reinette Chatrea0987a82008-12-02 12:14:06 -08006372MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
Zhu Yi25cb6ca2008-09-11 11:45:22 +08006373
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08006374module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07006375MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08006376module_param_named(disable, iwl3945_mod_params.disable, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07006377MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -08006378module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444);
6379MODULE_PARM_DESC(swcrypto,
6380 "using software crypto (default 1 [software])\n");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08006381module_param_named(debug, iwl3945_mod_params.debug, uint, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07006382MODULE_PARM_DESC(debug, "debug output mask");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08006383module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07006384MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
6385
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08006386module_param_named(queues_num, iwl3945_mod_params.num_of_queues, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07006387MODULE_PARM_DESC(queues_num, "number of hw queues.");
6388
Samuel Ortizaf48d042009-01-23 13:45:19 -08006389module_param_named(fw_restart3945, iwl3945_mod_params.restart_fw, int, 0444);
6390MODULE_PARM_DESC(fw_restart3945, "restart firmware in case of error");
6391
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006392module_exit(iwl3945_exit);
6393module_init(iwl3945_init);