blob: b57c2b8c8dcf3b8dcd73696b4448aa856406b740 [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"
Zhu Yib481de92007-09-25 17:54:57 -070054#include "iwl-3945.h"
55#include "iwl-helpers.h"
Kolekar, Abhijeet5747d472008-12-19 10:37:18 +080056#include "iwl-core.h"
Samuel Ortizd20b3c62008-12-19 10:37:15 +080057#include "iwl-dev.h"
Zhu Yib481de92007-09-25 17:54:57 -070058
Zhu Yib481de92007-09-25 17:54:57 -070059/*
60 * module name, copyright, version, etc.
Zhu Yib481de92007-09-25 17:54:57 -070061 */
62
63#define DRV_DESCRIPTION \
64"Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
65
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +080066#ifdef CONFIG_IWL3945_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070067#define VD "d"
68#else
69#define VD
70#endif
71
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +080072#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -070073#define VS "s"
74#else
75#define VS
76#endif
77
Kolekar, Abhijeeteaa686c2008-12-19 10:37:17 +080078#define IWL39_VERSION "1.2.26k" VD VS
Reinette Chatre01f81622009-01-08 10:20:02 -080079#define DRV_COPYRIGHT "Copyright(c) 2003-2009 Intel Corporation"
Tomas Winklera7b75202008-12-11 10:33:41 -080080#define DRV_AUTHOR "<ilw@linux.intel.com>"
Kolekar, Abhijeeteaa686c2008-12-19 10:37:17 +080081#define DRV_VERSION IWL39_VERSION
Zhu Yib481de92007-09-25 17:54:57 -070082
Zhu Yib481de92007-09-25 17:54:57 -070083
84MODULE_DESCRIPTION(DRV_DESCRIPTION);
85MODULE_VERSION(DRV_VERSION);
Tomas Winklera7b75202008-12-11 10:33:41 -080086MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
Zhu Yib481de92007-09-25 17:54:57 -070087MODULE_LICENSE("GPL");
88
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080089 /* module parameters */
90struct iwl_mod_params iwl3945_mod_params = {
91 .num_of_queues = IWL39_MAX_NUM_QUEUES,
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -080092 .sw_crypto = 1,
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080093 /* the rest are 0 by default */
94};
95
Zhu Yib481de92007-09-25 17:54:57 -070096/*************** STATION TABLE MANAGEMENT ****
Ben Cahill9fbab512007-11-29 11:09:47 +080097 * mac80211 should be examined to determine if sta_info is duplicating
Zhu Yib481de92007-09-25 17:54:57 -070098 * the functionality provided here
99 */
100
101/**************************************************************/
Ian Schram01ebd062007-10-25 17:15:22 +0800102#if 0 /* temporary disable till we add real remove station */
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800103/**
104 * iwl3945_remove_station - Remove driver's knowledge of station.
105 *
106 * NOTE: This does not remove station from device's station table.
107 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800108static u8 iwl3945_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
Zhu Yib481de92007-09-25 17:54:57 -0700109{
110 int index = IWL_INVALID_STATION;
111 int i;
112 unsigned long flags;
113
114 spin_lock_irqsave(&priv->sta_lock, flags);
115
116 if (is_ap)
117 index = IWL_AP_ID;
118 else if (is_broadcast_ether_addr(addr))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800119 index = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700120 else
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800121 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800122 if (priv->stations_39[i].used &&
123 !compare_ether_addr(priv->stations_39[i].sta.sta.addr,
Zhu Yib481de92007-09-25 17:54:57 -0700124 addr)) {
125 index = i;
126 break;
127 }
128
129 if (unlikely(index == IWL_INVALID_STATION))
130 goto out;
131
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800132 if (priv->stations_39[index].used) {
133 priv->stations_39[index].used = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700134 priv->num_stations--;
135 }
136
137 BUG_ON(priv->num_stations < 0);
138
139out:
140 spin_unlock_irqrestore(&priv->sta_lock, flags);
141 return 0;
142}
Zhu Yi556f8db2007-09-27 11:27:33 +0800143#endif
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800144
145/**
146 * iwl3945_clear_stations_table - Clear the driver's station table
147 *
148 * NOTE: This does not clear or otherwise alter the device's station table.
149 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800150static void iwl3945_clear_stations_table(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700151{
152 unsigned long flags;
153
154 spin_lock_irqsave(&priv->sta_lock, flags);
155
156 priv->num_stations = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800157 memset(priv->stations_39, 0, sizeof(priv->stations_39));
Zhu Yib481de92007-09-25 17:54:57 -0700158
159 spin_unlock_irqrestore(&priv->sta_lock, flags);
160}
161
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800162/**
163 * iwl3945_add_station - Add station to station tables in driver and device
164 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800165u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags)
Zhu Yib481de92007-09-25 17:54:57 -0700166{
167 int i;
168 int index = IWL_INVALID_STATION;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800169 struct iwl3945_station_entry *station;
Zhu Yib481de92007-09-25 17:54:57 -0700170 unsigned long flags_spin;
Zhu Yic14c5212007-09-27 11:27:35 +0800171 u8 rate;
Zhu Yib481de92007-09-25 17:54:57 -0700172
173 spin_lock_irqsave(&priv->sta_lock, flags_spin);
174 if (is_ap)
175 index = IWL_AP_ID;
176 else if (is_broadcast_ether_addr(addr))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800177 index = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700178 else
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800179 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800180 if (!compare_ether_addr(priv->stations_39[i].sta.sta.addr,
Zhu Yib481de92007-09-25 17:54:57 -0700181 addr)) {
182 index = i;
183 break;
184 }
185
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800186 if (!priv->stations_39[i].used &&
Zhu Yib481de92007-09-25 17:54:57 -0700187 index == IWL_INVALID_STATION)
188 index = i;
189 }
190
Ian Schram01ebd062007-10-25 17:15:22 +0800191 /* These two conditions has the same outcome but keep them separate
Zhu Yib481de92007-09-25 17:54:57 -0700192 since they have different meaning */
193 if (unlikely(index == IWL_INVALID_STATION)) {
194 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
195 return index;
196 }
197
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800198 if (priv->stations_39[index].used &&
199 !compare_ether_addr(priv->stations_39[index].sta.sta.addr, addr)) {
Zhu Yib481de92007-09-25 17:54:57 -0700200 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
201 return index;
202 }
203
Johannes Berge1749612008-10-27 15:59:26 -0700204 IWL_DEBUG_ASSOC("Add STA ID %d: %pM\n", index, addr);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800205 station = &priv->stations_39[index];
Zhu Yib481de92007-09-25 17:54:57 -0700206 station->used = 1;
207 priv->num_stations++;
208
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800209 /* Set up the REPLY_ADD_STA command to send to device */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800210 memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd));
Zhu Yib481de92007-09-25 17:54:57 -0700211 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
212 station->sta.mode = 0;
213 station->sta.sta.sta_id = index;
214 station->sta.station_flags = 0;
215
Johannes Berg8318d782008-01-24 19:38:38 +0100216 if (priv->band == IEEE80211_BAND_5GHZ)
Tomas Winkler69946332007-10-25 17:15:27 +0800217 rate = IWL_RATE_6M_PLCP;
218 else
219 rate = IWL_RATE_1M_PLCP;
Zhu Yic14c5212007-09-27 11:27:35 +0800220
221 /* Turn on both antennas for the station... */
222 station->sta.rate_n_flags =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800223 iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK);
Zhu Yic14c5212007-09-27 11:27:35 +0800224
Zhu Yib481de92007-09-25 17:54:57 -0700225 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800226
227 /* Add station to device's station table */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800228 iwl3945_send_add_station(priv, &station->sta, flags);
Zhu Yib481de92007-09-25 17:54:57 -0700229 return index;
230
231}
232
Samuel Ortiz518099a2009-01-19 15:30:27 -0800233int iwl3945_send_statistics_request(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700234{
Samuel Ortiz518099a2009-01-19 15:30:27 -0800235 u32 val = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700236
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800237 struct iwl_host_cmd cmd = {
Samuel Ortiz518099a2009-01-19 15:30:27 -0800238 .id = REPLY_STATISTICS_CMD,
Zhu Yib481de92007-09-25 17:54:57 -0700239 .len = sizeof(val),
240 .data = &val,
241 };
242
Samuel Ortiz518099a2009-01-19 15:30:27 -0800243 return iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700244}
245
246/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800247 * iwl3945_set_rxon_channel - Set the phymode and channel values in staging RXON
Johannes Berg8318d782008-01-24 19:38:38 +0100248 * @band: 2.4 or 5 GHz band
249 * @channel: Any channel valid for the requested band
Zhu Yib481de92007-09-25 17:54:57 -0700250
Johannes Berg8318d782008-01-24 19:38:38 +0100251 * In addition to setting the staging RXON, priv->band is also set.
Zhu Yib481de92007-09-25 17:54:57 -0700252 *
253 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
Johannes Berg8318d782008-01-24 19:38:38 +0100254 * in the staging RXON flag structure based on the band
Zhu Yib481de92007-09-25 17:54:57 -0700255 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800256static int iwl3945_set_rxon_channel(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +0100257 enum ieee80211_band band,
258 u16 channel)
Zhu Yib481de92007-09-25 17:54:57 -0700259{
Samuel Ortize6148912009-01-23 13:45:15 -0800260 if (!iwl_get_channel_info(priv, band, channel)) {
Zhu Yib481de92007-09-25 17:54:57 -0700261 IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
Johannes Berg8318d782008-01-24 19:38:38 +0100262 channel, band);
Zhu Yib481de92007-09-25 17:54:57 -0700263 return -EINVAL;
264 }
265
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800266 if ((le16_to_cpu(priv->staging39_rxon.channel) == channel) &&
Johannes Berg8318d782008-01-24 19:38:38 +0100267 (priv->band == band))
Zhu Yib481de92007-09-25 17:54:57 -0700268 return 0;
269
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800270 priv->staging39_rxon.channel = cpu_to_le16(channel);
Johannes Berg8318d782008-01-24 19:38:38 +0100271 if (band == IEEE80211_BAND_5GHZ)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800272 priv->staging39_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700273 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800274 priv->staging39_rxon.flags |= RXON_FLG_BAND_24G_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700275
Johannes Berg8318d782008-01-24 19:38:38 +0100276 priv->band = band;
Zhu Yib481de92007-09-25 17:54:57 -0700277
Johannes Berg8318d782008-01-24 19:38:38 +0100278 IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, band);
Zhu Yib481de92007-09-25 17:54:57 -0700279
280 return 0;
281}
282
283/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800284 * iwl3945_check_rxon_cmd - validate RXON structure is valid
Zhu Yib481de92007-09-25 17:54:57 -0700285 *
286 * NOTE: This is really only useful during development and can eventually
287 * be #ifdef'd out once the driver is stable and folks aren't actively
288 * making changes
289 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800290static int iwl3945_check_rxon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700291{
292 int error = 0;
293 int counter = 1;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800294 struct iwl3945_rxon_cmd *rxon = &priv->staging39_rxon;
Zhu Yib481de92007-09-25 17:54:57 -0700295
296 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
297 error |= le32_to_cpu(rxon->flags &
298 (RXON_FLG_TGJ_NARROW_BAND_MSK |
299 RXON_FLG_RADAR_DETECT_MSK));
300 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800301 IWL_WARN(priv, "check 24G fields %d | %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700302 counter++, error);
303 } else {
304 error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
305 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
306 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800307 IWL_WARN(priv, "check 52 fields %d | %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700308 counter++, error);
309 error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
310 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800311 IWL_WARN(priv, "check 52 CCK %d | %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700312 counter++, error);
313 }
314 error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
315 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800316 IWL_WARN(priv, "check mac addr %d | %d\n", counter++, error);
Zhu Yib481de92007-09-25 17:54:57 -0700317
318 /* make sure basic rates 6Mbps and 1Mbps are supported */
319 error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
320 ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
321 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800322 IWL_WARN(priv, "check basic rate %d | %d\n", counter++, error);
Zhu Yib481de92007-09-25 17:54:57 -0700323
324 error |= (le16_to_cpu(rxon->assoc_id) > 2007);
325 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800326 IWL_WARN(priv, "check assoc id %d | %d\n", counter++, error);
Zhu Yib481de92007-09-25 17:54:57 -0700327
328 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
329 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
330 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800331 IWL_WARN(priv, "check CCK and short slot %d | %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700332 counter++, error);
333
334 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
335 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
336 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800337 IWL_WARN(priv, "check CCK & auto detect %d | %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700338 counter++, error);
339
340 error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
341 RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
342 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800343 IWL_WARN(priv, "check TGG and auto detect %d | %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700344 counter++, error);
345
346 if ((rxon->flags & RXON_FLG_DIS_DIV_MSK))
347 error |= ((rxon->flags & (RXON_FLG_ANT_B_MSK |
348 RXON_FLG_ANT_A_MSK)) == 0);
349 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800350 IWL_WARN(priv, "check antenna %d %d\n", counter++, error);
Zhu Yib481de92007-09-25 17:54:57 -0700351
352 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800353 IWL_WARN(priv, "Tuning to channel %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700354 le16_to_cpu(rxon->channel));
355
356 if (error) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800357 IWL_ERR(priv, "Not a valid rxon_assoc_cmd field values\n");
Zhu Yib481de92007-09-25 17:54:57 -0700358 return -1;
359 }
360 return 0;
361}
362
363/**
Ben Cahill9fbab512007-11-29 11:09:47 +0800364 * iwl3945_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
Ian Schram01ebd062007-10-25 17:15:22 +0800365 * @priv: staging_rxon is compared to active_rxon
Zhu Yib481de92007-09-25 17:54:57 -0700366 *
Ben Cahill9fbab512007-11-29 11:09:47 +0800367 * If the RXON structure is changing enough to require a new tune,
368 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
369 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
Zhu Yib481de92007-09-25 17:54:57 -0700370 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800371static int iwl3945_full_rxon_required(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700372{
373
374 /* These items are only settable from the full RXON command */
Ron Rindjunsky5d1e2322008-06-30 17:23:04 +0800375 if (!(iwl3945_is_associated(priv)) ||
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800376 compare_ether_addr(priv->staging39_rxon.bssid_addr,
377 priv->active39_rxon.bssid_addr) ||
378 compare_ether_addr(priv->staging39_rxon.node_addr,
379 priv->active39_rxon.node_addr) ||
380 compare_ether_addr(priv->staging39_rxon.wlap_bssid_addr,
381 priv->active39_rxon.wlap_bssid_addr) ||
382 (priv->staging39_rxon.dev_type != priv->active39_rxon.dev_type) ||
383 (priv->staging39_rxon.channel != priv->active39_rxon.channel) ||
384 (priv->staging39_rxon.air_propagation !=
385 priv->active39_rxon.air_propagation) ||
386 (priv->staging39_rxon.assoc_id != priv->active39_rxon.assoc_id))
Zhu Yib481de92007-09-25 17:54:57 -0700387 return 1;
388
389 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
390 * be updated with the RXON_ASSOC command -- however only some
391 * flag transitions are allowed using RXON_ASSOC */
392
393 /* Check if we are not switching bands */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800394 if ((priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
395 (priv->active39_rxon.flags & RXON_FLG_BAND_24G_MSK))
Zhu Yib481de92007-09-25 17:54:57 -0700396 return 1;
397
398 /* Check if we are switching association toggle */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800399 if ((priv->staging39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
400 (priv->active39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
Zhu Yib481de92007-09-25 17:54:57 -0700401 return 1;
402
403 return 0;
404}
405
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800406static int iwl3945_send_rxon_assoc(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700407{
408 int rc = 0;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800409 struct iwl_rx_packet *res = NULL;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800410 struct iwl3945_rxon_assoc_cmd rxon_assoc;
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800411 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700412 .id = REPLY_RXON_ASSOC,
413 .len = sizeof(rxon_assoc),
414 .meta.flags = CMD_WANT_SKB,
415 .data = &rxon_assoc,
416 };
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800417 const struct iwl3945_rxon_cmd *rxon1 = &priv->staging39_rxon;
418 const struct iwl3945_rxon_cmd *rxon2 = &priv->active39_rxon;
Zhu Yib481de92007-09-25 17:54:57 -0700419
420 if ((rxon1->flags == rxon2->flags) &&
421 (rxon1->filter_flags == rxon2->filter_flags) &&
422 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
423 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
424 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
425 return 0;
426 }
427
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800428 rxon_assoc.flags = priv->staging39_rxon.flags;
429 rxon_assoc.filter_flags = priv->staging39_rxon.filter_flags;
430 rxon_assoc.ofdm_basic_rates = priv->staging39_rxon.ofdm_basic_rates;
431 rxon_assoc.cck_basic_rates = priv->staging39_rxon.cck_basic_rates;
Zhu Yib481de92007-09-25 17:54:57 -0700432 rxon_assoc.reserved = 0;
433
Samuel Ortiz518099a2009-01-19 15:30:27 -0800434 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700435 if (rc)
436 return rc;
437
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800438 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700439 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800440 IWL_ERR(priv, "Bad return from REPLY_RXON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -0700441 rc = -EIO;
442 }
443
444 priv->alloc_rxb_skb--;
445 dev_kfree_skb_any(cmd.meta.u.skb);
446
447 return rc;
448}
449
450/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800451 * iwl3945_commit_rxon - commit staging_rxon to hardware
Zhu Yib481de92007-09-25 17:54:57 -0700452 *
Ian Schram01ebd062007-10-25 17:15:22 +0800453 * The RXON command in staging_rxon is committed to the hardware and
Zhu Yib481de92007-09-25 17:54:57 -0700454 * the active_rxon structure is updated with the new data. This
455 * function correctly transitions out of the RXON_ASSOC_MSK state if
456 * a HW tune is required based on the RXON structure changes.
457 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800458static int iwl3945_commit_rxon(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700459{
460 /* cast away the const for active_rxon in this function */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800461 struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active39_rxon;
Zhu Yib481de92007-09-25 17:54:57 -0700462 int rc = 0;
463
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800464 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700465 return -1;
466
467 /* always get timestamp with Rx frame */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800468 priv->staging39_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700469
470 /* select antenna */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800471 priv->staging39_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -0700472 ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800473 priv->staging39_rxon.flags |= iwl3945_get_antenna_flags(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700474
Samuel Ortiza3139c52008-12-19 10:37:09 +0800475 rc = iwl3945_check_rxon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700476 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800477 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700478 return -EINVAL;
479 }
480
481 /* If we don't need to send a full RXON, we can use
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800482 * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
Zhu Yib481de92007-09-25 17:54:57 -0700483 * and other flags for the current radio configuration. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800484 if (!iwl3945_full_rxon_required(priv)) {
485 rc = iwl3945_send_rxon_assoc(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700486 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800487 IWL_ERR(priv, "Error setting RXON_ASSOC "
Zhu Yib481de92007-09-25 17:54:57 -0700488 "configuration (%d).\n", rc);
489 return rc;
490 }
491
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800492 memcpy(active_rxon, &priv->staging39_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700493
494 return 0;
495 }
496
497 /* If we are currently associated and the new config requires
498 * an RXON_ASSOC and the new config wants the associated mask enabled,
499 * we must clear the associated from the active configuration
500 * before we apply the new config */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800501 if (iwl3945_is_associated(priv) &&
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800502 (priv->staging39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) {
Zhu Yib481de92007-09-25 17:54:57 -0700503 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
504 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
505
Samuel Ortiz518099a2009-01-19 15:30:27 -0800506 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800507 sizeof(struct iwl3945_rxon_cmd),
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800508 &priv->active39_rxon);
Zhu Yib481de92007-09-25 17:54:57 -0700509
510 /* If the mask clearing failed then we set
511 * active_rxon back to what it was previously */
512 if (rc) {
513 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
Winkler, Tomas15b16872008-12-19 10:37:33 +0800514 IWL_ERR(priv, "Error clearing ASSOC_MSK on current "
Zhu Yib481de92007-09-25 17:54:57 -0700515 "configuration (%d).\n", rc);
516 return rc;
517 }
Zhu Yib481de92007-09-25 17:54:57 -0700518 }
519
520 IWL_DEBUG_INFO("Sending RXON\n"
521 "* with%s RXON_FILTER_ASSOC_MSK\n"
522 "* channel = %d\n"
Johannes Berge1749612008-10-27 15:59:26 -0700523 "* bssid = %pM\n",
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800524 ((priv->staging39_rxon.filter_flags &
Zhu Yib481de92007-09-25 17:54:57 -0700525 RXON_FILTER_ASSOC_MSK) ? "" : "out"),
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800526 le16_to_cpu(priv->staging39_rxon.channel),
Johannes Berge1749612008-10-27 15:59:26 -0700527 priv->staging_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -0700528
529 /* Apply the new configuration */
Samuel Ortiz518099a2009-01-19 15:30:27 -0800530 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800531 sizeof(struct iwl3945_rxon_cmd), &priv->staging39_rxon);
Zhu Yib481de92007-09-25 17:54:57 -0700532 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800533 IWL_ERR(priv, "Error setting new configuration (%d).\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700534 return rc;
535 }
536
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800537 memcpy(active_rxon, &priv->staging39_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700538
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800539 iwl3945_clear_stations_table(priv);
Zhu Yi556f8db2007-09-27 11:27:33 +0800540
Zhu Yib481de92007-09-25 17:54:57 -0700541 /* If we issue a new RXON command which required a tune then we must
542 * send a new TXPOWER command or we won't be able to Tx any frames */
Samuel Ortiz75bcfae2009-01-23 13:45:11 -0800543 rc = priv->cfg->ops->lib->send_tx_power(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700544 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800545 IWL_ERR(priv, "Error setting Tx power (%d).\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700546 return rc;
547 }
548
549 /* Add the broadcast address so we can send broadcast frames */
Kolekar, Abhijeetb5323d32008-12-19 10:37:22 +0800550 if (iwl3945_add_station(priv, iwl_bcast_addr, 0, 0) ==
Zhu Yib481de92007-09-25 17:54:57 -0700551 IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800552 IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700553 return -EIO;
554 }
555
556 /* If we have set the ASSOC_MSK and we are in BSS mode then
557 * add the IWL_AP_ID to the station rate table */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800558 if (iwl3945_is_associated(priv) &&
Johannes Berg05c914f2008-09-11 00:01:58 +0200559 (priv->iw_mode == NL80211_IFTYPE_STATION))
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800560 if (iwl3945_add_station(priv, priv->active39_rxon.bssid_addr, 1, 0)
Zhu Yib481de92007-09-25 17:54:57 -0700561 == IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800562 IWL_ERR(priv, "Error adding AP address for transmit\n");
Zhu Yib481de92007-09-25 17:54:57 -0700563 return -EIO;
564 }
565
Johannes Berg8318d782008-01-24 19:38:38 +0100566 /* Init the hardware's rate fallback order based on the band */
Zhu Yib481de92007-09-25 17:54:57 -0700567 rc = iwl3945_init_hw_rate_table(priv);
568 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800569 IWL_ERR(priv, "Error setting HW rate table: %02X\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700570 return -EIO;
571 }
572
573 return 0;
574}
575
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800576static int iwl3945_send_bt_config(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700577{
Tomas Winkler4c897252008-12-19 10:37:05 +0800578 struct iwl_bt_cmd bt_cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700579 .flags = 3,
580 .lead_time = 0xAA,
581 .max_kill = 1,
582 .kill_ack_mask = 0,
583 .kill_cts_mask = 0,
584 };
585
Samuel Ortiz518099a2009-01-19 15:30:27 -0800586 return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
Tomas Winkler4c897252008-12-19 10:37:05 +0800587 sizeof(bt_cmd), &bt_cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700588}
589
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800590static int iwl3945_add_sta_sync_callback(struct iwl_priv *priv,
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800591 struct iwl_cmd *cmd, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -0700592{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800593 struct iwl_rx_packet *res = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700594
595 if (!skb) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800596 IWL_ERR(priv, "Error: Response NULL in REPLY_ADD_STA.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700597 return 1;
598 }
599
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800600 res = (struct iwl_rx_packet *)skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700601 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800602 IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n",
Zhu Yib481de92007-09-25 17:54:57 -0700603 res->hdr.flags);
604 return 1;
605 }
606
607 switch (res->u.add_sta.status) {
608 case ADD_STA_SUCCESS_MSK:
609 break;
610 default:
611 break;
612 }
613
614 /* We didn't cache the SKB; let the caller free it */
615 return 1;
616}
617
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800618int iwl3945_send_add_station(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800619 struct iwl3945_addsta_cmd *sta, u8 flags)
Zhu Yib481de92007-09-25 17:54:57 -0700620{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800621 struct iwl_rx_packet *res = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700622 int rc = 0;
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800623 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700624 .id = REPLY_ADD_STA,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800625 .len = sizeof(struct iwl3945_addsta_cmd),
Zhu Yib481de92007-09-25 17:54:57 -0700626 .meta.flags = flags,
627 .data = sta,
628 };
629
630 if (flags & CMD_ASYNC)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800631 cmd.meta.u.callback = iwl3945_add_sta_sync_callback;
Zhu Yib481de92007-09-25 17:54:57 -0700632 else
633 cmd.meta.flags |= CMD_WANT_SKB;
634
Samuel Ortiz518099a2009-01-19 15:30:27 -0800635 rc = iwl_send_cmd(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700636
637 if (rc || (flags & CMD_ASYNC))
638 return rc;
639
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800640 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700641 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800642 IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n",
Zhu Yib481de92007-09-25 17:54:57 -0700643 res->hdr.flags);
644 rc = -EIO;
645 }
646
647 if (rc == 0) {
648 switch (res->u.add_sta.status) {
649 case ADD_STA_SUCCESS_MSK:
650 IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
651 break;
652 default:
653 rc = -EIO;
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800654 IWL_WARN(priv, "REPLY_ADD_STA failed\n");
Zhu Yib481de92007-09-25 17:54:57 -0700655 break;
656 }
657 }
658
659 priv->alloc_rxb_skb--;
660 dev_kfree_skb_any(cmd.meta.u.skb);
661
662 return rc;
663}
664
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800665static int iwl3945_update_sta_key_info(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700666 struct ieee80211_key_conf *keyconf,
667 u8 sta_id)
668{
669 unsigned long flags;
670 __le16 key_flags = 0;
671
672 switch (keyconf->alg) {
673 case ALG_CCMP:
674 key_flags |= STA_KEY_FLG_CCMP;
675 key_flags |= cpu_to_le16(
676 keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
677 key_flags &= ~STA_KEY_FLG_INVALID;
678 break;
679 case ALG_TKIP:
680 case ALG_WEP:
Zhu Yib481de92007-09-25 17:54:57 -0700681 default:
682 return -EINVAL;
683 }
684 spin_lock_irqsave(&priv->sta_lock, flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800685 priv->stations_39[sta_id].keyinfo.alg = keyconf->alg;
686 priv->stations_39[sta_id].keyinfo.keylen = keyconf->keylen;
687 memcpy(priv->stations_39[sta_id].keyinfo.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700688 keyconf->keylen);
689
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800690 memcpy(priv->stations_39[sta_id].sta.key.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700691 keyconf->keylen);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800692 priv->stations_39[sta_id].sta.key.key_flags = key_flags;
693 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
694 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700695
696 spin_unlock_irqrestore(&priv->sta_lock, flags);
697
698 IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800699 iwl3945_send_add_station(priv, &priv->stations_39[sta_id].sta, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700700 return 0;
701}
702
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800703static int iwl3945_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
Zhu Yib481de92007-09-25 17:54:57 -0700704{
705 unsigned long flags;
706
707 spin_lock_irqsave(&priv->sta_lock, flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800708 memset(&priv->stations_39[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key));
709 memset(&priv->stations_39[sta_id].sta.key, 0,
Tomas Winkler4c897252008-12-19 10:37:05 +0800710 sizeof(struct iwl4965_keyinfo));
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800711 priv->stations_39[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
712 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
713 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700714 spin_unlock_irqrestore(&priv->sta_lock, flags);
715
716 IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800717 iwl3945_send_add_station(priv, &priv->stations_39[sta_id].sta, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700718 return 0;
719}
720
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800721static void iwl3945_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700722{
723 struct list_head *element;
724
725 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
726 priv->frames_count);
727
728 while (!list_empty(&priv->free_frames)) {
729 element = priv->free_frames.next;
730 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800731 kfree(list_entry(element, struct iwl3945_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700732 priv->frames_count--;
733 }
734
735 if (priv->frames_count) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800736 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
Zhu Yib481de92007-09-25 17:54:57 -0700737 priv->frames_count);
738 priv->frames_count = 0;
739 }
740}
741
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800742static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700743{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800744 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700745 struct list_head *element;
746 if (list_empty(&priv->free_frames)) {
747 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
748 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800749 IWL_ERR(priv, "Could not allocate frame!\n");
Zhu Yib481de92007-09-25 17:54:57 -0700750 return NULL;
751 }
752
753 priv->frames_count++;
754 return frame;
755 }
756
757 element = priv->free_frames.next;
758 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800759 return list_entry(element, struct iwl3945_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700760}
761
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800762static void iwl3945_free_frame(struct iwl_priv *priv, struct iwl3945_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700763{
764 memset(frame, 0, sizeof(*frame));
765 list_add(&frame->list, &priv->free_frames);
766}
767
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800768unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700769 struct ieee80211_hdr *hdr,
Rami Rosen73ec1cc2008-12-16 09:37:07 +0200770 int left)
Zhu Yib481de92007-09-25 17:54:57 -0700771{
772
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800773 if (!iwl3945_is_associated(priv) || !priv->ibss_beacon ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200774 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
775 (priv->iw_mode != NL80211_IFTYPE_AP)))
Zhu Yib481de92007-09-25 17:54:57 -0700776 return 0;
777
778 if (priv->ibss_beacon->len > left)
779 return 0;
780
781 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
782
783 return priv->ibss_beacon->len;
784}
785
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800786static u8 iwl3945_rate_get_lowest_plcp(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700787{
788 u8 i;
Kolekar, Abhijeetc24f0812008-11-07 09:58:44 -0800789 int rate_mask;
790
791 /* Set rate mask*/
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800792 if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK)
Chatre, Reinettedbce56a2008-11-12 13:14:07 -0800793 rate_mask = priv->active_rate_basic & IWL_CCK_RATES_MASK;
Kolekar, Abhijeetc24f0812008-11-07 09:58:44 -0800794 else
Chatre, Reinettedbce56a2008-11-12 13:14:07 -0800795 rate_mask = priv->active_rate_basic & IWL_OFDM_RATES_MASK;
Zhu Yib481de92007-09-25 17:54:57 -0700796
797 for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800798 i = iwl3945_rates[i].next_ieee) {
Zhu Yib481de92007-09-25 17:54:57 -0700799 if (rate_mask & (1 << i))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800800 return iwl3945_rates[i].plcp;
Zhu Yib481de92007-09-25 17:54:57 -0700801 }
802
Kolekar, Abhijeetc24f0812008-11-07 09:58:44 -0800803 /* No valid rate was found. Assign the lowest one */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800804 if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK)
Kolekar, Abhijeetc24f0812008-11-07 09:58:44 -0800805 return IWL_RATE_1M_PLCP;
806 else
807 return IWL_RATE_6M_PLCP;
Zhu Yib481de92007-09-25 17:54:57 -0700808}
809
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800810static int iwl3945_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700811{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800812 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700813 unsigned int frame_size;
814 int rc;
815 u8 rate;
816
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800817 frame = iwl3945_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700818
819 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800820 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
Zhu Yib481de92007-09-25 17:54:57 -0700821 "command.\n");
822 return -ENOMEM;
823 }
824
Kolekar, Abhijeetc24f0812008-11-07 09:58:44 -0800825 rate = iwl3945_rate_get_lowest_plcp(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700826
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800827 frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
Zhu Yib481de92007-09-25 17:54:57 -0700828
Samuel Ortiz518099a2009-01-19 15:30:27 -0800829 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -0700830 &frame->u.cmd[0]);
831
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800832 iwl3945_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -0700833
834 return rc;
835}
836
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800837static void iwl3945_unset_hw_params(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700838{
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800839 if (priv->shared_virt)
Zhu Yib481de92007-09-25 17:54:57 -0700840 pci_free_consistent(priv->pci_dev,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800841 sizeof(struct iwl3945_shared),
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800842 priv->shared_virt,
843 priv->shared_phys);
Zhu Yib481de92007-09-25 17:54:57 -0700844}
845
Zhu Yib481de92007-09-25 17:54:57 -0700846/*
847 * QoS support
848*/
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800849static int iwl3945_send_qos_params_command(struct iwl_priv *priv,
Tomas Winkler4c897252008-12-19 10:37:05 +0800850 struct iwl_qosparam_cmd *qos)
Zhu Yib481de92007-09-25 17:54:57 -0700851{
852
Samuel Ortiz518099a2009-01-19 15:30:27 -0800853 return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM,
Tomas Winkler4c897252008-12-19 10:37:05 +0800854 sizeof(struct iwl_qosparam_cmd), qos);
Zhu Yib481de92007-09-25 17:54:57 -0700855}
856
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800857static void iwl3945_activate_qos(struct iwl_priv *priv, u8 force)
Zhu Yib481de92007-09-25 17:54:57 -0700858{
859 unsigned long flags;
860
Zhu Yib481de92007-09-25 17:54:57 -0700861 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
862 return;
863
Zhu Yib481de92007-09-25 17:54:57 -0700864 spin_lock_irqsave(&priv->lock, flags);
865 priv->qos_data.def_qos_parm.qos_flags = 0;
866
867 if (priv->qos_data.qos_cap.q_AP.queue_request &&
868 !priv->qos_data.qos_cap.q_AP.txop_request)
869 priv->qos_data.def_qos_parm.qos_flags |=
870 QOS_PARAM_FLG_TXOP_TYPE_MSK;
871
872 if (priv->qos_data.qos_active)
873 priv->qos_data.def_qos_parm.qos_flags |=
874 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
875
876 spin_unlock_irqrestore(&priv->lock, flags);
877
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800878 if (force || iwl3945_is_associated(priv)) {
Tomas Winklera96a27f2008-10-23 23:48:56 -0700879 IWL_DEBUG_QOS("send QoS cmd with QoS active %d \n",
Zhu Yib481de92007-09-25 17:54:57 -0700880 priv->qos_data.qos_active);
881
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800882 iwl3945_send_qos_params_command(priv,
Zhu Yib481de92007-09-25 17:54:57 -0700883 &(priv->qos_data.def_qos_parm));
884 }
885}
886
Zhu Yib481de92007-09-25 17:54:57 -0700887/*
888 * Power management (not Tx power!) functions
889 */
890#define MSEC_TO_USEC 1024
891
Tomas Winkler600c0e12008-12-19 10:37:04 +0800892
Zhu Yib481de92007-09-25 17:54:57 -0700893/* default power management (not Tx power) table values */
Tomas Winklera96a27f2008-10-23 23:48:56 -0700894/* for TIM 0-10 */
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800895static struct iwl_power_vec_entry range_0[IWL_POWER_MAX] = {
896 {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
897 {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
898 {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
899 {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
900 {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
901 {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
Zhu Yib481de92007-09-25 17:54:57 -0700902};
903
Tomas Winklera96a27f2008-10-23 23:48:56 -0700904/* for TIM > 10 */
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800905static struct iwl_power_vec_entry range_1[IWL_POWER_MAX] = {
906 {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
907 {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
908 {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
909 {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
910 {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
911 {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
Zhu Yib481de92007-09-25 17:54:57 -0700912};
913
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800914int iwl3945_power_init_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700915{
916 int rc = 0, i;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800917 struct iwl_power_mgr *pow_data;
918 int size = sizeof(struct iwl_power_vec_entry) * IWL_POWER_MAX;
Zhu Yib481de92007-09-25 17:54:57 -0700919 u16 pci_pm;
920
921 IWL_DEBUG_POWER("Initialize power \n");
922
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800923 pow_data = &priv->power_data;
Zhu Yib481de92007-09-25 17:54:57 -0700924
925 memset(pow_data, 0, sizeof(*pow_data));
926
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800927 pow_data->dtim_period = 1;
Zhu Yib481de92007-09-25 17:54:57 -0700928
929 memcpy(&pow_data->pwr_range_0[0], &range_0[0], size);
930 memcpy(&pow_data->pwr_range_1[0], &range_1[0], size);
931
932 rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm);
933 if (rc != 0)
934 return 0;
935 else {
Tomas Winkler600c0e12008-12-19 10:37:04 +0800936 struct iwl_powertable_cmd *cmd;
Zhu Yib481de92007-09-25 17:54:57 -0700937
938 IWL_DEBUG_POWER("adjust power command flags\n");
939
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800940 for (i = 0; i < IWL_POWER_MAX; i++) {
Zhu Yib481de92007-09-25 17:54:57 -0700941 cmd = &pow_data->pwr_range_0[i].cmd;
942
943 if (pci_pm & 0x1)
944 cmd->flags &= ~IWL_POWER_PCI_PM_MSK;
945 else
946 cmd->flags |= IWL_POWER_PCI_PM_MSK;
947 }
948 }
949 return rc;
950}
951
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800952static int iwl3945_update_power_cmd(struct iwl_priv *priv,
Tomas Winkler600c0e12008-12-19 10:37:04 +0800953 struct iwl_powertable_cmd *cmd, u32 mode)
Zhu Yib481de92007-09-25 17:54:57 -0700954{
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800955 struct iwl_power_mgr *pow_data;
Samuel Ortiz1125eff2008-12-19 10:37:14 +0800956 struct iwl_power_vec_entry *range;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800957 u32 max_sleep = 0;
958 int i;
Zhu Yib481de92007-09-25 17:54:57 -0700959 u8 period = 0;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800960 bool skip;
Zhu Yib481de92007-09-25 17:54:57 -0700961
962 if (mode > IWL_POWER_INDEX_5) {
963 IWL_DEBUG_POWER("Error invalid power mode \n");
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800964 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -0700965 }
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800966 pow_data = &priv->power_data;
Zhu Yib481de92007-09-25 17:54:57 -0700967
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800968 if (pow_data->dtim_period < 10)
Zhu Yib481de92007-09-25 17:54:57 -0700969 range = &pow_data->pwr_range_0[0];
970 else
971 range = &pow_data->pwr_range_1[1];
972
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800973 memcpy(cmd, &range[mode].cmd, sizeof(struct iwl3945_powertable_cmd));
Zhu Yib481de92007-09-25 17:54:57 -0700974
Zhu Yib481de92007-09-25 17:54:57 -0700975
976 if (period == 0) {
977 period = 1;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800978 skip = false;
979 } else {
980 skip = !!range[mode].no_dtim;
Zhu Yib481de92007-09-25 17:54:57 -0700981 }
982
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800983 if (skip) {
Zhu Yib481de92007-09-25 17:54:57 -0700984 __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1];
985 max_sleep = (le32_to_cpu(slp_itrvl) / period) * period;
986 cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800987 } else {
988 max_sleep = period;
989 cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700990 }
991
Winkler, Tomas3dae0c42009-01-19 15:30:30 -0800992 for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
Zhu Yib481de92007-09-25 17:54:57 -0700993 if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep)
994 cmd->sleep_interval[i] = cpu_to_le32(max_sleep);
Zhu Yib481de92007-09-25 17:54:57 -0700995
996 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags);
997 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout));
998 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout));
999 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
1000 le32_to_cpu(cmd->sleep_interval[0]),
1001 le32_to_cpu(cmd->sleep_interval[1]),
1002 le32_to_cpu(cmd->sleep_interval[2]),
1003 le32_to_cpu(cmd->sleep_interval[3]),
1004 le32_to_cpu(cmd->sleep_interval[4]));
1005
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08001006 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07001007}
1008
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001009static int iwl3945_send_power_mode(struct iwl_priv *priv, u32 mode)
Zhu Yib481de92007-09-25 17:54:57 -07001010{
John W. Linville9a62f732007-11-15 16:27:36 -05001011 u32 uninitialized_var(final_mode);
Zhu Yib481de92007-09-25 17:54:57 -07001012 int rc;
Tomas Winkler600c0e12008-12-19 10:37:04 +08001013 struct iwl_powertable_cmd cmd;
Zhu Yib481de92007-09-25 17:54:57 -07001014
1015 /* If on battery, set to 3,
Ian Schram01ebd062007-10-25 17:15:22 +08001016 * if plugged into AC power, set to CAM ("continuously aware mode"),
Zhu Yib481de92007-09-25 17:54:57 -07001017 * else user level */
1018 switch (mode) {
Samuel Ortiz1125eff2008-12-19 10:37:14 +08001019 case IWL39_POWER_BATTERY:
Zhu Yib481de92007-09-25 17:54:57 -07001020 final_mode = IWL_POWER_INDEX_3;
1021 break;
Samuel Ortiz1125eff2008-12-19 10:37:14 +08001022 case IWL39_POWER_AC:
Zhu Yib481de92007-09-25 17:54:57 -07001023 final_mode = IWL_POWER_MODE_CAM;
1024 break;
1025 default:
1026 final_mode = mode;
1027 break;
1028 }
1029
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001030 iwl3945_update_power_cmd(priv, &cmd, final_mode);
Zhu Yib481de92007-09-25 17:54:57 -07001031
Tomas Winkler600c0e12008-12-19 10:37:04 +08001032 /* FIXME use get_hcmd_size 3945 command is 4 bytes shorter */
Samuel Ortiz518099a2009-01-19 15:30:27 -08001033 rc = iwl_send_cmd_pdu(priv, POWER_TABLE_CMD,
1034 sizeof(struct iwl3945_powertable_cmd), &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001035
1036 if (final_mode == IWL_POWER_MODE_CAM)
1037 clear_bit(STATUS_POWER_PMI, &priv->status);
1038 else
1039 set_bit(STATUS_POWER_PMI, &priv->status);
1040
1041 return rc;
1042}
1043
Zhu Yib481de92007-09-25 17:54:57 -07001044#define MAX_UCODE_BEACON_INTERVAL 1024
1045#define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
1046
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001047static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val)
Zhu Yib481de92007-09-25 17:54:57 -07001048{
1049 u16 new_val = 0;
1050 u16 beacon_factor = 0;
1051
1052 beacon_factor =
1053 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
1054 / MAX_UCODE_BEACON_INTERVAL;
1055 new_val = beacon_val / beacon_factor;
1056
1057 return cpu_to_le16(new_val);
1058}
1059
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001060static void iwl3945_setup_rxon_timing(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001061{
1062 u64 interval_tm_unit;
1063 u64 tsf, result;
1064 unsigned long flags;
1065 struct ieee80211_conf *conf = NULL;
1066 u16 beacon_int = 0;
1067
1068 conf = ieee80211_get_hw_conf(priv->hw);
1069
1070 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler28afaf92008-12-19 10:37:06 +08001071 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
Zhu Yib481de92007-09-25 17:54:57 -07001072 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
1073
Tomas Winkler28afaf92008-12-19 10:37:06 +08001074 tsf = priv->timestamp;
Zhu Yib481de92007-09-25 17:54:57 -07001075
1076 beacon_int = priv->beacon_int;
1077 spin_unlock_irqrestore(&priv->lock, flags);
1078
Johannes Berg05c914f2008-09-11 00:01:58 +02001079 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
Zhu Yib481de92007-09-25 17:54:57 -07001080 if (beacon_int == 0) {
1081 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
1082 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
1083 } else {
1084 priv->rxon_timing.beacon_interval =
1085 cpu_to_le16(beacon_int);
1086 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001087 iwl3945_adjust_beacon_interval(
Zhu Yib481de92007-09-25 17:54:57 -07001088 le16_to_cpu(priv->rxon_timing.beacon_interval));
1089 }
1090
1091 priv->rxon_timing.atim_window = 0;
1092 } else {
1093 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001094 iwl3945_adjust_beacon_interval(conf->beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -07001095 /* TODO: we need to get atim_window from upper stack
1096 * for now we set to 0 */
1097 priv->rxon_timing.atim_window = 0;
1098 }
1099
1100 interval_tm_unit =
1101 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
1102 result = do_div(tsf, interval_tm_unit);
1103 priv->rxon_timing.beacon_init_val =
1104 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
1105
1106 IWL_DEBUG_ASSOC
1107 ("beacon interval %d beacon timer %d beacon tim %d\n",
1108 le16_to_cpu(priv->rxon_timing.beacon_interval),
1109 le32_to_cpu(priv->rxon_timing.beacon_init_val),
1110 le16_to_cpu(priv->rxon_timing.atim_window));
1111}
1112
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001113static int iwl3945_scan_initiate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001114{
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08001115 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001116 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
1117 return -EIO;
1118 }
1119
1120 if (test_bit(STATUS_SCANNING, &priv->status)) {
1121 IWL_DEBUG_SCAN("Scan already in progress.\n");
1122 return -EAGAIN;
1123 }
1124
1125 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
1126 IWL_DEBUG_SCAN("Scan request while abort pending. "
1127 "Queuing.\n");
1128 return -EAGAIN;
1129 }
1130
1131 IWL_DEBUG_INFO("Starting scan...\n");
Ron Rindjunsky66b50042008-06-25 16:46:31 +08001132 if (priv->cfg->sku & IWL_SKU_G)
1133 priv->scan_bands |= BIT(IEEE80211_BAND_2GHZ);
1134 if (priv->cfg->sku & IWL_SKU_A)
1135 priv->scan_bands |= BIT(IEEE80211_BAND_5GHZ);
Zhu Yib481de92007-09-25 17:54:57 -07001136 set_bit(STATUS_SCANNING, &priv->status);
1137 priv->scan_start = jiffies;
1138 priv->scan_pass_start = priv->scan_start;
1139
1140 queue_work(priv->workqueue, &priv->request_scan);
1141
1142 return 0;
1143}
1144
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001145static int iwl3945_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
Zhu Yib481de92007-09-25 17:54:57 -07001146{
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001147 struct iwl3945_rxon_cmd *rxon = &priv->staging39_rxon;
Zhu Yib481de92007-09-25 17:54:57 -07001148
1149 if (hw_decrypt)
1150 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
1151 else
1152 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
1153
1154 return 0;
1155}
1156
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001157static void iwl3945_set_flags_for_phymode(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01001158 enum ieee80211_band band)
Zhu Yib481de92007-09-25 17:54:57 -07001159{
Johannes Berg8318d782008-01-24 19:38:38 +01001160 if (band == IEEE80211_BAND_5GHZ) {
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001161 priv->staging39_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07001162 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
1163 | RXON_FLG_CCK_MSK);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001164 priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001165 } else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001166 /* Copied from iwl3945_bg_post_associate() */
Zhu Yib481de92007-09-25 17:54:57 -07001167 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001168 priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001169 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001170 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001171
Johannes Berg05c914f2008-09-11 00:01:58 +02001172 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001173 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001174
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001175 priv->staging39_rxon.flags |= RXON_FLG_BAND_24G_MSK;
1176 priv->staging39_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
1177 priv->staging39_rxon.flags &= ~RXON_FLG_CCK_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001178 }
1179}
1180
1181/*
Ian Schram01ebd062007-10-25 17:15:22 +08001182 * initialize rxon structure with default values from eeprom
Zhu Yib481de92007-09-25 17:54:57 -07001183 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001184static void iwl3945_connection_init_rx_config(struct iwl_priv *priv,
Zhu, Yi60294de2008-10-29 14:05:45 -07001185 int mode)
Zhu Yib481de92007-09-25 17:54:57 -07001186{
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001187 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07001188
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001189 memset(&priv->staging39_rxon, 0, sizeof(priv->staging39_rxon));
Zhu Yib481de92007-09-25 17:54:57 -07001190
Zhu, Yi60294de2008-10-29 14:05:45 -07001191 switch (mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02001192 case NL80211_IFTYPE_AP:
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001193 priv->staging39_rxon.dev_type = RXON_DEV_TYPE_AP;
Zhu Yib481de92007-09-25 17:54:57 -07001194 break;
1195
Johannes Berg05c914f2008-09-11 00:01:58 +02001196 case NL80211_IFTYPE_STATION:
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001197 priv->staging39_rxon.dev_type = RXON_DEV_TYPE_ESS;
1198 priv->staging39_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001199 break;
1200
Johannes Berg05c914f2008-09-11 00:01:58 +02001201 case NL80211_IFTYPE_ADHOC:
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001202 priv->staging39_rxon.dev_type = RXON_DEV_TYPE_IBSS;
1203 priv->staging39_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
1204 priv->staging39_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
Zhu Yib481de92007-09-25 17:54:57 -07001205 RXON_FILTER_ACCEPT_GRP_MSK;
1206 break;
1207
Johannes Berg05c914f2008-09-11 00:01:58 +02001208 case NL80211_IFTYPE_MONITOR:
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001209 priv->staging39_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
1210 priv->staging39_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
Zhu Yib481de92007-09-25 17:54:57 -07001211 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
1212 break;
Tomas Winkler69dc5d92008-03-25 16:33:41 -07001213 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08001214 IWL_ERR(priv, "Unsupported interface type %d\n", mode);
Tomas Winkler69dc5d92008-03-25 16:33:41 -07001215 break;
Zhu Yib481de92007-09-25 17:54:57 -07001216 }
1217
1218#if 0
1219 /* TODO: Figure out when short_preamble would be set and cache from
1220 * that */
1221 if (!hw_to_local(priv->hw)->short_preamble)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001222 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001223 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001224 priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001225#endif
1226
Samuel Ortize6148912009-01-23 13:45:15 -08001227 ch_info = iwl_get_channel_info(priv, priv->band,
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001228 le16_to_cpu(priv->active39_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -07001229
1230 if (!ch_info)
1231 ch_info = &priv->channel_info[0];
1232
1233 /*
1234 * in some case A channels are all non IBSS
1235 * in this case force B/G channel
1236 */
Zhu, Yi60294de2008-10-29 14:05:45 -07001237 if ((mode == NL80211_IFTYPE_ADHOC) && !(is_channel_ibss(ch_info)))
Zhu Yib481de92007-09-25 17:54:57 -07001238 ch_info = &priv->channel_info[0];
1239
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001240 priv->staging39_rxon.channel = cpu_to_le16(ch_info->channel);
Zhu Yib481de92007-09-25 17:54:57 -07001241 if (is_channel_a_band(ch_info))
Johannes Berg8318d782008-01-24 19:38:38 +01001242 priv->band = IEEE80211_BAND_5GHZ;
Zhu Yib481de92007-09-25 17:54:57 -07001243 else
Johannes Berg8318d782008-01-24 19:38:38 +01001244 priv->band = IEEE80211_BAND_2GHZ;
Zhu Yib481de92007-09-25 17:54:57 -07001245
Johannes Berg8318d782008-01-24 19:38:38 +01001246 iwl3945_set_flags_for_phymode(priv, priv->band);
Zhu Yib481de92007-09-25 17:54:57 -07001247
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001248 priv->staging39_rxon.ofdm_basic_rates =
Zhu Yib481de92007-09-25 17:54:57 -07001249 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001250 priv->staging39_rxon.cck_basic_rates =
Zhu Yib481de92007-09-25 17:54:57 -07001251 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
1252}
1253
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001254static int iwl3945_set_mode(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -07001255{
Johannes Berg05c914f2008-09-11 00:01:58 +02001256 if (mode == NL80211_IFTYPE_ADHOC) {
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001257 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07001258
Samuel Ortize6148912009-01-23 13:45:15 -08001259 ch_info = iwl_get_channel_info(priv,
Johannes Berg8318d782008-01-24 19:38:38 +01001260 priv->band,
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001261 le16_to_cpu(priv->staging39_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -07001262
1263 if (!ch_info || !is_channel_ibss(ch_info)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001264 IWL_ERR(priv, "channel %d not IBSS channel\n",
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001265 le16_to_cpu(priv->staging39_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -07001266 return -EINVAL;
1267 }
1268 }
1269
Zhu, Yi60294de2008-10-29 14:05:45 -07001270 iwl3945_connection_init_rx_config(priv, mode);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001271 memcpy(priv->staging39_rxon.node_addr, priv->mac_addr, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07001272
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001273 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001274
Tomas Winklera96a27f2008-10-23 23:48:56 -07001275 /* don't commit rxon if rf-kill is on*/
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08001276 if (!iwl_is_ready_rf(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08001277 return -EAGAIN;
1278
1279 cancel_delayed_work(&priv->scan_check);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08001280 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001281 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +08001282 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
1283 return -EAGAIN;
1284 }
1285
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001286 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001287
1288 return 0;
1289}
1290
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001291static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
Johannes Berge039fa42008-05-15 12:55:29 +02001292 struct ieee80211_tx_info *info,
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08001293 struct iwl_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -07001294 struct sk_buff *skb_frag,
1295 int last_frag)
1296{
Winkler, Tomase52119c2008-12-22 11:31:19 +08001297 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
Ivo van Doorn1c014422008-04-17 19:41:02 +02001298 struct iwl3945_hw_key *keyinfo =
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001299 &priv->stations_39[info->control.hw_key->hw_key_idx].keyinfo;
Zhu Yib481de92007-09-25 17:54:57 -07001300
1301 switch (keyinfo->alg) {
1302 case ALG_CCMP:
Winkler, Tomase52119c2008-12-22 11:31:19 +08001303 tx->sec_ctl = TX_CMD_SEC_CCM;
1304 memcpy(tx->key, keyinfo->key, keyinfo->keylen);
Tomas Winklera96a27f2008-10-23 23:48:56 -07001305 IWL_DEBUG_TX("tx_cmd with AES hwcrypto\n");
Zhu Yib481de92007-09-25 17:54:57 -07001306 break;
1307
1308 case ALG_TKIP:
1309#if 0
Winkler, Tomase52119c2008-12-22 11:31:19 +08001310 tx->sec_ctl = TX_CMD_SEC_TKIP;
Zhu Yib481de92007-09-25 17:54:57 -07001311
1312 if (last_frag)
Winkler, Tomase52119c2008-12-22 11:31:19 +08001313 memcpy(tx->tkip_mic.byte, skb_frag->tail - 8,
Zhu Yib481de92007-09-25 17:54:57 -07001314 8);
1315 else
Winkler, Tomase52119c2008-12-22 11:31:19 +08001316 memset(tx->tkip_mic.byte, 0, 8);
Zhu Yib481de92007-09-25 17:54:57 -07001317#endif
1318 break;
1319
1320 case ALG_WEP:
Winkler, Tomase52119c2008-12-22 11:31:19 +08001321 tx->sec_ctl = TX_CMD_SEC_WEP |
Johannes Berge039fa42008-05-15 12:55:29 +02001322 (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
Zhu Yib481de92007-09-25 17:54:57 -07001323
1324 if (keyinfo->keylen == 13)
Winkler, Tomase52119c2008-12-22 11:31:19 +08001325 tx->sec_ctl |= TX_CMD_SEC_KEY128;
Zhu Yib481de92007-09-25 17:54:57 -07001326
Winkler, Tomase52119c2008-12-22 11:31:19 +08001327 memcpy(&tx->key[3], keyinfo->key, keyinfo->keylen);
Zhu Yib481de92007-09-25 17:54:57 -07001328
1329 IWL_DEBUG_TX("Configuring packet for WEP encryption "
Johannes Berge039fa42008-05-15 12:55:29 +02001330 "with key %d\n", info->control.hw_key->hw_key_idx);
Zhu Yib481de92007-09-25 17:54:57 -07001331 break;
1332
Zhu Yib481de92007-09-25 17:54:57 -07001333 default:
Tomas Winkler978785a2008-12-19 10:37:31 +08001334 IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg);
Zhu Yib481de92007-09-25 17:54:57 -07001335 break;
1336 }
1337}
1338
1339/*
1340 * handle build REPLY_TX command notification.
1341 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001342static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08001343 struct iwl_cmd *cmd,
Johannes Berge039fa42008-05-15 12:55:29 +02001344 struct ieee80211_tx_info *info,
Winkler, Tomase52119c2008-12-22 11:31:19 +08001345 struct ieee80211_hdr *hdr, u8 std_id)
Zhu Yib481de92007-09-25 17:54:57 -07001346{
Winkler, Tomase52119c2008-12-22 11:31:19 +08001347 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
1348 __le32 tx_flags = tx->tx_flags;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001349 __le16 fc = hdr->frame_control;
Johannes Berge6a98542008-10-21 12:40:02 +02001350 u8 rc_flags = info->control.rates[0].flags;
Zhu Yib481de92007-09-25 17:54:57 -07001351
Winkler, Tomase52119c2008-12-22 11:31:19 +08001352 tx->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
Johannes Berge039fa42008-05-15 12:55:29 +02001353 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
Zhu Yib481de92007-09-25 17:54:57 -07001354 tx_flags |= TX_CMD_FLG_ACK_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001355 if (ieee80211_is_mgmt(fc))
Zhu Yib481de92007-09-25 17:54:57 -07001356 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001357 if (ieee80211_is_probe_resp(fc) &&
Zhu Yib481de92007-09-25 17:54:57 -07001358 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
1359 tx_flags |= TX_CMD_FLG_TSF_MSK;
1360 } else {
1361 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
1362 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
1363 }
1364
Winkler, Tomase52119c2008-12-22 11:31:19 +08001365 tx->sta_id = std_id;
Harvey Harrison8b7b1e02008-06-11 14:21:56 -07001366 if (ieee80211_has_morefrags(fc))
Zhu Yib481de92007-09-25 17:54:57 -07001367 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
1368
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001369 if (ieee80211_is_data_qos(fc)) {
1370 u8 *qc = ieee80211_get_qos_ctl(hdr);
Winkler, Tomase52119c2008-12-22 11:31:19 +08001371 tx->tid_tspec = qc[0] & 0xf;
Zhu Yib481de92007-09-25 17:54:57 -07001372 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +08001373 } else {
Zhu Yib481de92007-09-25 17:54:57 -07001374 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +08001375 }
Zhu Yib481de92007-09-25 17:54:57 -07001376
Johannes Berge6a98542008-10-21 12:40:02 +02001377 if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
Zhu Yib481de92007-09-25 17:54:57 -07001378 tx_flags |= TX_CMD_FLG_RTS_MSK;
1379 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
Johannes Berge6a98542008-10-21 12:40:02 +02001380 } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
Zhu Yib481de92007-09-25 17:54:57 -07001381 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
1382 tx_flags |= TX_CMD_FLG_CTS_MSK;
1383 }
1384
1385 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
1386 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
1387
1388 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001389 if (ieee80211_is_mgmt(fc)) {
1390 if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
Winkler, Tomase52119c2008-12-22 11:31:19 +08001391 tx->timeout.pm_frame_timeout = cpu_to_le16(3);
Zhu Yib481de92007-09-25 17:54:57 -07001392 else
Winkler, Tomase52119c2008-12-22 11:31:19 +08001393 tx->timeout.pm_frame_timeout = cpu_to_le16(2);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07001394 } else {
Winkler, Tomase52119c2008-12-22 11:31:19 +08001395 tx->timeout.pm_frame_timeout = 0;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07001396#ifdef CONFIG_IWL3945_LEDS
1397 priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
1398#endif
1399 }
Zhu Yib481de92007-09-25 17:54:57 -07001400
Winkler, Tomase52119c2008-12-22 11:31:19 +08001401 tx->driver_txop = 0;
1402 tx->tx_flags = tx_flags;
1403 tx->next_frame_len = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001404}
1405
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001406/**
1407 * iwl3945_get_sta_id - Find station's index within station table
1408 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001409static int iwl3945_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
Zhu Yib481de92007-09-25 17:54:57 -07001410{
1411 int sta_id;
1412 u16 fc = le16_to_cpu(hdr->frame_control);
1413
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001414 /* If this frame is broadcast or management, use broadcast station id */
Zhu Yib481de92007-09-25 17:54:57 -07001415 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
1416 is_multicast_ether_addr(hdr->addr1))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001417 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07001418
1419 switch (priv->iw_mode) {
1420
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001421 /* If we are a client station in a BSS network, use the special
1422 * AP station entry (that's the only station we communicate with) */
Johannes Berg05c914f2008-09-11 00:01:58 +02001423 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -07001424 return IWL_AP_ID;
1425
1426 /* If we are an AP, then find the station, or use BCAST */
Johannes Berg05c914f2008-09-11 00:01:58 +02001427 case NL80211_IFTYPE_AP:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001428 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -07001429 if (sta_id != IWL_INVALID_STATION)
1430 return sta_id;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001431 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07001432
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001433 /* If this frame is going out to an IBSS network, find the station,
1434 * or create a new station table entry */
Johannes Berg05c914f2008-09-11 00:01:58 +02001435 case NL80211_IFTYPE_ADHOC: {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001436 /* Create new station table entry */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001437 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -07001438 if (sta_id != IWL_INVALID_STATION)
1439 return sta_id;
1440
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001441 sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
Zhu Yib481de92007-09-25 17:54:57 -07001442
1443 if (sta_id != IWL_INVALID_STATION)
1444 return sta_id;
1445
Johannes Berge1749612008-10-27 15:59:26 -07001446 IWL_DEBUG_DROP("Station %pM not in station map. "
Zhu Yib481de92007-09-25 17:54:57 -07001447 "Defaulting to broadcast...\n",
Johannes Berge1749612008-10-27 15:59:26 -07001448 hdr->addr1);
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08001449 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001450 return priv->hw_params.bcast_sta_id;
Joe Perches0795af52007-10-03 17:59:30 -07001451 }
Stefanik Gábor914233d2008-06-30 17:23:30 +08001452 /* If we are in monitor mode, use BCAST. This is required for
1453 * packet injection. */
Johannes Berg05c914f2008-09-11 00:01:58 +02001454 case NL80211_IFTYPE_MONITOR:
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001455 return priv->hw_params.bcast_sta_id;
Stefanik Gábor914233d2008-06-30 17:23:30 +08001456
Zhu Yib481de92007-09-25 17:54:57 -07001457 default:
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001458 IWL_WARN(priv, "Unknown mode of operation: %d\n",
1459 priv->iw_mode);
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001460 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07001461 }
1462}
1463
1464/*
1465 * start REPLY_TX command process
1466 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001467static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07001468{
1469 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berge039fa42008-05-15 12:55:29 +02001470 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Winkler, Tomase52119c2008-12-22 11:31:19 +08001471 struct iwl3945_tx_cmd *tx;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001472 struct iwl_tx_queue *txq = NULL;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001473 struct iwl_queue *q = NULL;
Winkler, Tomase52119c2008-12-22 11:31:19 +08001474 struct iwl_cmd *out_cmd = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07001475 dma_addr_t phys_addr;
1476 dma_addr_t txcmd_phys;
Winkler, Tomase52119c2008-12-22 11:31:19 +08001477 int txq_id = skb_get_queue_mapping(skb);
Tomas Winkler54dbb522008-05-15 13:54:06 +08001478 u16 len, idx, len_org, hdr_len;
1479 u8 id;
1480 u8 unicast;
Zhu Yib481de92007-09-25 17:54:57 -07001481 u8 sta_id;
Tomas Winkler54dbb522008-05-15 13:54:06 +08001482 u8 tid = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001483 u16 seq_number = 0;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001484 __le16 fc;
Zhu Yib481de92007-09-25 17:54:57 -07001485 u8 wait_write_ptr = 0;
Tomas Winkler54dbb522008-05-15 13:54:06 +08001486 u8 *qc = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07001487 unsigned long flags;
1488 int rc;
1489
1490 spin_lock_irqsave(&priv->lock, flags);
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08001491 if (iwl_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001492 IWL_DEBUG_DROP("Dropping - RF KILL\n");
1493 goto drop_unlock;
1494 }
1495
Johannes Berge039fa42008-05-15 12:55:29 +02001496 if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001497 IWL_ERR(priv, "ERROR: No TX rate available.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001498 goto drop_unlock;
1499 }
1500
1501 unicast = !is_multicast_ether_addr(hdr->addr1);
1502 id = 0;
1503
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001504 fc = hdr->frame_control;
Zhu Yib481de92007-09-25 17:54:57 -07001505
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001506#ifdef CONFIG_IWL3945_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001507 if (ieee80211_is_auth(fc))
1508 IWL_DEBUG_TX("Sending AUTH frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001509 else if (ieee80211_is_assoc_req(fc))
Zhu Yib481de92007-09-25 17:54:57 -07001510 IWL_DEBUG_TX("Sending ASSOC frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001511 else if (ieee80211_is_reassoc_req(fc))
Zhu Yib481de92007-09-25 17:54:57 -07001512 IWL_DEBUG_TX("Sending REASSOC frame\n");
1513#endif
1514
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08001515 /* drop all data frame if we are not associated */
Stefanik Gábor914233d2008-06-30 17:23:30 +08001516 if (ieee80211_is_data(fc) &&
Johannes Berg05c914f2008-09-11 00:01:58 +02001517 (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */
Stefanik Gábor914233d2008-06-30 17:23:30 +08001518 (!iwl3945_is_associated(priv) ||
Johannes Berg05c914f2008-09-11 00:01:58 +02001519 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001520 IWL_DEBUG_DROP("Dropping - !iwl3945_is_associated\n");
Zhu Yib481de92007-09-25 17:54:57 -07001521 goto drop_unlock;
1522 }
1523
1524 spin_unlock_irqrestore(&priv->lock, flags);
1525
Harvey Harrison7294ec92008-07-15 18:43:59 -07001526 hdr_len = ieee80211_hdrlen(fc);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001527
1528 /* Find (or create) index into station table for destination station */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001529 sta_id = iwl3945_get_sta_id(priv, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07001530 if (sta_id == IWL_INVALID_STATION) {
Johannes Berge1749612008-10-27 15:59:26 -07001531 IWL_DEBUG_DROP("Dropping - INVALID STATION: %pM\n",
1532 hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -07001533 goto drop;
1534 }
1535
1536 IWL_DEBUG_RATE("station Id %d\n", sta_id);
1537
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001538 if (ieee80211_is_data_qos(fc)) {
1539 qc = ieee80211_get_qos_ctl(hdr);
Harvey Harrison7294ec92008-07-15 18:43:59 -07001540 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001541 seq_number = priv->stations_39[sta_id].tid[tid].seq_number &
Zhu Yib481de92007-09-25 17:54:57 -07001542 IEEE80211_SCTL_SEQ;
1543 hdr->seq_ctrl = cpu_to_le16(seq_number) |
1544 (hdr->seq_ctrl &
1545 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG));
1546 seq_number += 0x10;
1547 }
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001548
1549 /* Descriptor for chosen Tx queue */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001550 txq = &priv->txq[txq_id];
Zhu Yib481de92007-09-25 17:54:57 -07001551 q = &txq->q;
1552
1553 spin_lock_irqsave(&priv->lock, flags);
1554
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001555 idx = get_cmd_index(q, q->write_ptr, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001556
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001557 /* Set up driver data for this TFD */
Winkler, Tomasdbb66542008-12-22 11:31:14 +08001558 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001559 txq->txb[q->write_ptr].skb[0] = skb;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001560
1561 /* Init first empty entry in queue's array of Tx/cmd buffers */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001562 out_cmd = txq->cmd[idx];
Winkler, Tomase52119c2008-12-22 11:31:19 +08001563 tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload;
Zhu Yib481de92007-09-25 17:54:57 -07001564 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
Winkler, Tomase52119c2008-12-22 11:31:19 +08001565 memset(tx, 0, sizeof(*tx));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001566
1567 /*
1568 * Set up the Tx-command (not MAC!) header.
1569 * Store the chosen Tx queue and TFD index within the sequence field;
1570 * after Tx, uCode's Tx response will return this value so driver can
1571 * locate the frame within the tx queue and do post-tx processing.
1572 */
Zhu Yib481de92007-09-25 17:54:57 -07001573 out_cmd->hdr.cmd = REPLY_TX;
1574 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001575 INDEX_TO_SEQ(q->write_ptr)));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001576
1577 /* Copy MAC header from skb into command buffer */
Winkler, Tomase52119c2008-12-22 11:31:19 +08001578 memcpy(tx->hdr, hdr, hdr_len);
Zhu Yib481de92007-09-25 17:54:57 -07001579
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001580 /*
1581 * Use the first empty entry in this queue's command buffer array
1582 * to contain the Tx command and MAC header concatenated together
1583 * (payload data will be in another buffer).
1584 * Size of this varies, due to varying MAC header length.
1585 * If end is not dword aligned, we'll have 2 extra bytes at the end
1586 * of the MAC header (device reads on dword boundaries).
1587 * We'll tell device about this padding later.
1588 */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001589 len = sizeof(struct iwl3945_tx_cmd) +
Tomas Winkler4c897252008-12-19 10:37:05 +08001590 sizeof(struct iwl_cmd_header) + hdr_len;
Zhu Yib481de92007-09-25 17:54:57 -07001591
1592 len_org = len;
1593 len = (len + 3) & ~3;
1594
1595 if (len_org != len)
1596 len_org = 1;
1597 else
1598 len_org = 0;
1599
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001600 /* Physical address of this Tx command's header (not MAC header!),
1601 * within command buffer array. */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001602 txcmd_phys = pci_map_single(priv->pci_dev,
1603 out_cmd, sizeof(struct iwl_cmd),
1604 PCI_DMA_TODEVICE);
1605 pci_unmap_addr_set(&out_cmd->meta, mapping, txcmd_phys);
1606 pci_unmap_len_set(&out_cmd->meta, len, sizeof(struct iwl_cmd));
1607 /* Add buffer containing Tx command and MAC(!) header to TFD's
1608 * first entry */
1609 txcmd_phys += offsetof(struct iwl_cmd, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07001610
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001611 /* Add buffer containing Tx command and MAC(!) header to TFD's
1612 * first entry */
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001613 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1614 txcmd_phys, len, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001615
Johannes Bergd0f09802008-07-29 11:32:07 +02001616 if (info->control.hw_key)
Johannes Berge039fa42008-05-15 12:55:29 +02001617 iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001618
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001619 /* Set up TFD's 2nd entry to point directly to remainder of skb,
1620 * if any (802.11 null frames have no payload). */
Zhu Yib481de92007-09-25 17:54:57 -07001621 len = skb->len - hdr_len;
1622 if (len) {
1623 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
1624 len, PCI_DMA_TODEVICE);
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001625 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1626 phys_addr, len,
1627 0, U32_PAD(len));
Zhu Yib481de92007-09-25 17:54:57 -07001628 }
1629
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001630 /* Total # bytes to be transmitted */
Zhu Yib481de92007-09-25 17:54:57 -07001631 len = (u16)skb->len;
Winkler, Tomase52119c2008-12-22 11:31:19 +08001632 tx->len = cpu_to_le16(len);
Zhu Yib481de92007-09-25 17:54:57 -07001633
1634 /* TODO need this for burst mode later on */
Winkler, Tomase52119c2008-12-22 11:31:19 +08001635 iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07001636
1637 /* set is_hcca to 0; it probably will never be implemented */
Johannes Berge039fa42008-05-15 12:55:29 +02001638 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001639
Winkler, Tomase52119c2008-12-22 11:31:19 +08001640 tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
1641 tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001642
Harvey Harrison8b7b1e02008-06-11 14:21:56 -07001643 if (!ieee80211_has_morefrags(hdr->frame_control)) {
Zhu Yib481de92007-09-25 17:54:57 -07001644 txq->need_update = 1;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001645 if (qc)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001646 priv->stations_39[sta_id].tid[tid].seq_number = seq_number;
Zhu Yib481de92007-09-25 17:54:57 -07001647 } else {
1648 wait_write_ptr = 1;
1649 txq->need_update = 0;
1650 }
1651
Winkler, Tomase52119c2008-12-22 11:31:19 +08001652 iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx));
Zhu Yib481de92007-09-25 17:54:57 -07001653
Winkler, Tomase52119c2008-12-22 11:31:19 +08001654 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr,
Harvey Harrison7294ec92008-07-15 18:43:59 -07001655 ieee80211_hdrlen(fc));
Zhu Yib481de92007-09-25 17:54:57 -07001656
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001657 /* Tell device the write index *just past* this latest filled TFD */
Tomas Winklerc54b6792008-03-06 17:36:53 -08001658 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001659 rc = iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001660 spin_unlock_irqrestore(&priv->lock, flags);
1661
1662 if (rc)
1663 return rc;
1664
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001665 if ((iwl_queue_space(q) < q->high_mark)
Zhu Yib481de92007-09-25 17:54:57 -07001666 && priv->mac80211_registered) {
1667 if (wait_write_ptr) {
1668 spin_lock_irqsave(&priv->lock, flags);
1669 txq->need_update = 1;
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001670 iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001671 spin_unlock_irqrestore(&priv->lock, flags);
1672 }
1673
Johannes Berge2530082008-05-17 00:57:14 +02001674 ieee80211_stop_queue(priv->hw, skb_get_queue_mapping(skb));
Zhu Yib481de92007-09-25 17:54:57 -07001675 }
1676
1677 return 0;
1678
1679drop_unlock:
1680 spin_unlock_irqrestore(&priv->lock, flags);
1681drop:
1682 return -1;
1683}
1684
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001685static void iwl3945_set_rate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001686{
Johannes Berg8318d782008-01-24 19:38:38 +01001687 const struct ieee80211_supported_band *sband = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07001688 struct ieee80211_rate *rate;
1689 int i;
1690
Kolekar, Abhijeetcbba18c2008-12-19 10:37:42 +08001691 sband = iwl_get_hw_mode(priv, priv->band);
Johannes Berg8318d782008-01-24 19:38:38 +01001692 if (!sband) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001693 IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n");
Saleem Abdulrasoolc4ba9622007-11-18 23:59:08 -08001694 return;
1695 }
Zhu Yib481de92007-09-25 17:54:57 -07001696
1697 priv->active_rate = 0;
1698 priv->active_rate_basic = 0;
1699
Johannes Berg8318d782008-01-24 19:38:38 +01001700 IWL_DEBUG_RATE("Setting rates for %s GHz\n",
1701 sband->band == IEEE80211_BAND_2GHZ ? "2.4" : "5");
Zhu Yib481de92007-09-25 17:54:57 -07001702
Johannes Berg8318d782008-01-24 19:38:38 +01001703 for (i = 0; i < sband->n_bitrates; i++) {
1704 rate = &sband->bitrates[i];
1705 if ((rate->hw_value < IWL_RATE_COUNT) &&
1706 !(rate->flags & IEEE80211_CHAN_DISABLED)) {
1707 IWL_DEBUG_RATE("Adding rate index %d (plcp %d)\n",
1708 rate->hw_value, iwl3945_rates[rate->hw_value].plcp);
1709 priv->active_rate |= (1 << rate->hw_value);
1710 }
Zhu Yib481de92007-09-25 17:54:57 -07001711 }
1712
1713 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
1714 priv->active_rate, priv->active_rate_basic);
1715
1716 /*
1717 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
1718 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
1719 * OFDM
1720 */
1721 if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001722 priv->staging39_rxon.cck_basic_rates =
Zhu Yib481de92007-09-25 17:54:57 -07001723 ((priv->active_rate_basic &
1724 IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
1725 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001726 priv->staging39_rxon.cck_basic_rates =
Zhu Yib481de92007-09-25 17:54:57 -07001727 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
1728
1729 if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001730 priv->staging39_rxon.ofdm_basic_rates =
Zhu Yib481de92007-09-25 17:54:57 -07001731 ((priv->active_rate_basic &
1732 (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
1733 IWL_FIRST_OFDM_RATE) & 0xFF;
1734 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001735 priv->staging39_rxon.ofdm_basic_rates =
Zhu Yib481de92007-09-25 17:54:57 -07001736 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
1737}
1738
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001739static void iwl3945_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
Zhu Yib481de92007-09-25 17:54:57 -07001740{
1741 unsigned long flags;
1742
1743 if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
1744 return;
1745
1746 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
1747 disable_radio ? "OFF" : "ON");
1748
1749 if (disable_radio) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08001750 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001751 /* FIXME: This is a workaround for AP */
Johannes Berg05c914f2008-09-11 00:01:58 +02001752 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07001753 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001754 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001755 CSR_UCODE_SW_BIT_RFKILL);
1756 spin_unlock_irqrestore(&priv->lock, flags);
Samuel Ortizc4962942008-12-22 11:31:18 +08001757 iwl_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001758 set_bit(STATUS_RF_KILL_SW, &priv->status);
1759 }
1760 return;
1761 }
1762
1763 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001764 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07001765
1766 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1767 spin_unlock_irqrestore(&priv->lock, flags);
1768
1769 /* wake up ucode */
1770 msleep(10);
1771
1772 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001773 iwl_read32(priv, CSR_UCODE_DRV_GP1);
1774 if (!iwl_grab_nic_access(priv))
1775 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001776 spin_unlock_irqrestore(&priv->lock, flags);
1777
1778 if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
1779 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
1780 "disabled by HW switch\n");
1781 return;
1782 }
1783
Zhu Yi808e72a2008-06-12 09:47:17 +08001784 if (priv->is_open)
1785 queue_work(priv->workqueue, &priv->restart);
Zhu Yib481de92007-09-25 17:54:57 -07001786 return;
1787}
1788
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001789void iwl3945_set_decrypted_flag(struct iwl_priv *priv, struct sk_buff *skb,
Zhu Yib481de92007-09-25 17:54:57 -07001790 u32 decrypt_res, struct ieee80211_rx_status *stats)
1791{
1792 u16 fc =
1793 le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control);
1794
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001795 if (priv->active39_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
Zhu Yib481de92007-09-25 17:54:57 -07001796 return;
1797
1798 if (!(fc & IEEE80211_FCTL_PROTECTED))
1799 return;
1800
1801 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
1802 switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
1803 case RX_RES_STATUS_SEC_TYPE_TKIP:
1804 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
1805 RX_RES_STATUS_BAD_ICV_MIC)
1806 stats->flag |= RX_FLAG_MMIC_ERROR;
1807 case RX_RES_STATUS_SEC_TYPE_WEP:
1808 case RX_RES_STATUS_SEC_TYPE_CCMP:
1809 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
1810 RX_RES_STATUS_DECRYPT_OK) {
1811 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
1812 stats->flag |= RX_FLAG_DECRYPTED;
1813 }
1814 break;
1815
1816 default:
1817 break;
1818 }
1819}
1820
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001821#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07001822
1823#include "iwl-spectrum.h"
1824
1825#define BEACON_TIME_MASK_LOW 0x00FFFFFF
1826#define BEACON_TIME_MASK_HIGH 0xFF000000
1827#define TIME_UNIT 1024
1828
1829/*
1830 * extended beacon time format
1831 * time in usec will be changed into a 32-bit value in 8:24 format
1832 * the high 1 byte is the beacon counts
1833 * the lower 3 bytes is the time in usec within one beacon interval
1834 */
1835
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001836static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001837{
1838 u32 quot;
1839 u32 rem;
1840 u32 interval = beacon_interval * 1024;
1841
1842 if (!interval || !usec)
1843 return 0;
1844
1845 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
1846 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
1847
1848 return (quot << 24) + rem;
1849}
1850
1851/* base is usually what we get from ucode with each received frame,
1852 * the same as HW timer counter counting down
1853 */
1854
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001855static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001856{
1857 u32 base_low = base & BEACON_TIME_MASK_LOW;
1858 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
1859 u32 interval = beacon_interval * TIME_UNIT;
1860 u32 res = (base & BEACON_TIME_MASK_HIGH) +
1861 (addon & BEACON_TIME_MASK_HIGH);
1862
1863 if (base_low > addon_low)
1864 res += base_low - addon_low;
1865 else if (base_low < addon_low) {
1866 res += interval + base_low - addon_low;
1867 res += (1 << 24);
1868 } else
1869 res += (1 << 24);
1870
1871 return cpu_to_le32(res);
1872}
1873
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001874static int iwl3945_get_measurement(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001875 struct ieee80211_measurement_params *params,
1876 u8 type)
1877{
Tomas Winkler600c0e12008-12-19 10:37:04 +08001878 struct iwl_spectrum_cmd spectrum;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001879 struct iwl_rx_packet *res;
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08001880 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001881 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
1882 .data = (void *)&spectrum,
1883 .meta.flags = CMD_WANT_SKB,
1884 };
1885 u32 add_time = le64_to_cpu(params->start_time);
1886 int rc;
1887 int spectrum_resp_status;
1888 int duration = le16_to_cpu(params->duration);
1889
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001890 if (iwl3945_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001891 add_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001892 iwl3945_usecs_to_beacons(
Zhu Yib481de92007-09-25 17:54:57 -07001893 le64_to_cpu(params->start_time) - priv->last_tsf,
1894 le16_to_cpu(priv->rxon_timing.beacon_interval));
1895
1896 memset(&spectrum, 0, sizeof(spectrum));
1897
1898 spectrum.channel_count = cpu_to_le16(1);
1899 spectrum.flags =
1900 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
1901 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
1902 cmd.len = sizeof(spectrum);
1903 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
1904
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001905 if (iwl3945_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001906 spectrum.start_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001907 iwl3945_add_beacon_time(priv->last_beacon_time,
Zhu Yib481de92007-09-25 17:54:57 -07001908 add_time,
1909 le16_to_cpu(priv->rxon_timing.beacon_interval));
1910 else
1911 spectrum.start_time = 0;
1912
1913 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
1914 spectrum.channels[0].channel = params->channel;
1915 spectrum.channels[0].type = type;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001916 if (priv->active39_rxon.flags & RXON_FLG_BAND_24G_MSK)
Zhu Yib481de92007-09-25 17:54:57 -07001917 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
1918 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
1919
Samuel Ortiz518099a2009-01-19 15:30:27 -08001920 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001921 if (rc)
1922 return rc;
1923
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001924 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001925 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001926 IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -07001927 rc = -EIO;
1928 }
1929
1930 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
1931 switch (spectrum_resp_status) {
1932 case 0: /* Command will be handled */
1933 if (res->u.spectrum.id != 0xff) {
Ian Schrambc434dd2007-10-25 17:15:29 +08001934 IWL_DEBUG_INFO("Replaced existing measurement: %d\n",
1935 res->u.spectrum.id);
Zhu Yib481de92007-09-25 17:54:57 -07001936 priv->measurement_status &= ~MEASUREMENT_READY;
1937 }
1938 priv->measurement_status |= MEASUREMENT_ACTIVE;
1939 rc = 0;
1940 break;
1941
1942 case 1: /* Command will not be handled */
1943 rc = -EAGAIN;
1944 break;
1945 }
1946
1947 dev_kfree_skb_any(cmd.meta.u.skb);
1948
1949 return rc;
1950}
1951#endif
1952
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001953static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001954 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001955{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001956 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
1957 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -07001958 struct delayed_work *pwork;
1959
1960 palive = &pkt->u.alive_frame;
1961
1962 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
1963 "0x%01X 0x%01X\n",
1964 palive->is_valid, palive->ver_type,
1965 palive->ver_subtype);
1966
1967 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
1968 IWL_DEBUG_INFO("Initialization Alive received.\n");
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001969 memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
1970 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001971 pwork = &priv->init_alive_start;
1972 } else {
1973 IWL_DEBUG_INFO("Runtime Alive received.\n");
1974 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001975 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001976 pwork = &priv->alive_start;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001977 iwl3945_disable_events(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001978 }
1979
1980 /* We delay the ALIVE response by 5ms to
1981 * give the HW RF Kill time to activate... */
1982 if (palive->is_valid == UCODE_VALID_OK)
1983 queue_delayed_work(priv->workqueue, pwork,
1984 msecs_to_jiffies(5));
1985 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001986 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001987}
1988
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001989static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001990 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001991{
Helmut Schaac7e035a2009-01-19 13:02:15 +01001992#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001993 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Helmut Schaac7e035a2009-01-19 13:02:15 +01001994#endif
Zhu Yib481de92007-09-25 17:54:57 -07001995
1996 IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
1997 return;
1998}
1999
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002000static void iwl3945_rx_reply_error(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002001 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002002{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002003 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002004
Winkler, Tomas15b16872008-12-19 10:37:33 +08002005 IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
Zhu Yib481de92007-09-25 17:54:57 -07002006 "seq 0x%04X ser 0x%08X\n",
2007 le32_to_cpu(pkt->u.err_resp.error_type),
2008 get_cmd_string(pkt->u.err_resp.cmd_id),
2009 pkt->u.err_resp.cmd_id,
2010 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
2011 le32_to_cpu(pkt->u.err_resp.error_info));
2012}
2013
2014#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
2015
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002016static void iwl3945_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002017{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002018 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08002019 struct iwl3945_rxon_cmd *rxon = (void *)&priv->active39_rxon;
Tomas Winkler600c0e12008-12-19 10:37:04 +08002020 struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
Zhu Yib481de92007-09-25 17:54:57 -07002021 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
2022 le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
2023 rxon->channel = csa->channel;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08002024 priv->staging39_rxon.channel = csa->channel;
Zhu Yib481de92007-09-25 17:54:57 -07002025}
2026
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002027static void iwl3945_rx_spectrum_measure_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002028 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002029{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002030#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002031 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler600c0e12008-12-19 10:37:04 +08002032 struct iwl_spectrum_notification *report = &(pkt->u.spectrum_notif);
Zhu Yib481de92007-09-25 17:54:57 -07002033
2034 if (!report->state) {
2035 IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO,
2036 "Spectrum Measure Notification: Start\n");
2037 return;
2038 }
2039
2040 memcpy(&priv->measure_report, report, sizeof(*report));
2041 priv->measurement_status |= MEASUREMENT_READY;
2042#endif
2043}
2044
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002045static void iwl3945_rx_pm_sleep_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002046 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002047{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002048#ifdef CONFIG_IWL3945_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002049 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler600c0e12008-12-19 10:37:04 +08002050 struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
Zhu Yib481de92007-09-25 17:54:57 -07002051 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
2052 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
2053#endif
2054}
2055
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002056static void iwl3945_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002057 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002058{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002059 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002060 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
2061 "notification for %s:\n",
2062 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002063 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw,
2064 le32_to_cpu(pkt->len));
Zhu Yib481de92007-09-25 17:54:57 -07002065}
2066
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002067static void iwl3945_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07002068{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002069 struct iwl_priv *priv =
2070 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07002071 struct sk_buff *beacon;
2072
2073 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +02002074 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -07002075
2076 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002077 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07002078 return;
2079 }
2080
2081 mutex_lock(&priv->mutex);
2082 /* new beacon skb is allocated every time; dispose previous.*/
2083 if (priv->ibss_beacon)
2084 dev_kfree_skb(priv->ibss_beacon);
2085
2086 priv->ibss_beacon = beacon;
2087 mutex_unlock(&priv->mutex);
2088
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002089 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002090}
2091
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002092static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002093 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002094{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002095#ifdef CONFIG_IWL3945_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002096 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002097 struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
Zhu Yib481de92007-09-25 17:54:57 -07002098 u8 rate = beacon->beacon_notify_hdr.rate;
2099
2100 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
2101 "tsf %d %d rate %d\n",
2102 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
2103 beacon->beacon_notify_hdr.failure_frame,
2104 le32_to_cpu(beacon->ibss_mgr_status),
2105 le32_to_cpu(beacon->high_tsf),
2106 le32_to_cpu(beacon->low_tsf), rate);
2107#endif
2108
Johannes Berg05c914f2008-09-11 00:01:58 +02002109 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -07002110 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
2111 queue_work(priv->workqueue, &priv->beacon_update);
2112}
2113
2114/* Service response to REPLY_SCAN_CMD (0x80) */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002115static void iwl3945_rx_reply_scan(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002116 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002117{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002118#ifdef CONFIG_IWL3945_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002119 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler4c897252008-12-19 10:37:05 +08002120 struct iwl_scanreq_notification *notif =
2121 (struct iwl_scanreq_notification *)pkt->u.raw;
Zhu Yib481de92007-09-25 17:54:57 -07002122
2123 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status);
2124#endif
2125}
2126
2127/* Service SCAN_START_NOTIFICATION (0x82) */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002128static void iwl3945_rx_scan_start_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002129 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002130{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002131 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler4c897252008-12-19 10:37:05 +08002132 struct iwl_scanstart_notification *notif =
2133 (struct iwl_scanstart_notification *)pkt->u.raw;
Zhu Yib481de92007-09-25 17:54:57 -07002134 priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
2135 IWL_DEBUG_SCAN("Scan start: "
2136 "%d [802.11%s] "
2137 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
2138 notif->channel,
2139 notif->band ? "bg" : "a",
2140 notif->tsf_high,
2141 notif->tsf_low, notif->status, notif->beacon_timer);
2142}
2143
2144/* Service SCAN_RESULTS_NOTIFICATION (0x83) */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002145static void iwl3945_rx_scan_results_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002146 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002147{
Helmut Schaac7e035a2009-01-19 13:02:15 +01002148#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002149 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler4c897252008-12-19 10:37:05 +08002150 struct iwl_scanresults_notification *notif =
2151 (struct iwl_scanresults_notification *)pkt->u.raw;
Helmut Schaac7e035a2009-01-19 13:02:15 +01002152#endif
Zhu Yib481de92007-09-25 17:54:57 -07002153
2154 IWL_DEBUG_SCAN("Scan ch.res: "
2155 "%d [802.11%s] "
2156 "(TSF: 0x%08X:%08X) - %d "
2157 "elapsed=%lu usec (%dms since last)\n",
2158 notif->channel,
2159 notif->band ? "bg" : "a",
2160 le32_to_cpu(notif->tsf_high),
2161 le32_to_cpu(notif->tsf_low),
2162 le32_to_cpu(notif->statistics[0]),
2163 le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf,
2164 jiffies_to_msecs(elapsed_jiffies
2165 (priv->last_scan_jiffies, jiffies)));
2166
2167 priv->last_scan_jiffies = jiffies;
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08002168 priv->next_scan_jiffies = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002169}
2170
2171/* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002172static void iwl3945_rx_scan_complete_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002173 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002174{
Helmut Schaac7e035a2009-01-19 13:02:15 +01002175#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002176 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler4c897252008-12-19 10:37:05 +08002177 struct iwl_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
Helmut Schaac7e035a2009-01-19 13:02:15 +01002178#endif
Zhu Yib481de92007-09-25 17:54:57 -07002179
2180 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
2181 scan_notif->scanned_channels,
2182 scan_notif->tsf_low,
2183 scan_notif->tsf_high, scan_notif->status);
2184
2185 /* The HW is no longer scanning */
2186 clear_bit(STATUS_SCAN_HW, &priv->status);
2187
2188 /* The scan completion notification came in, so kill that timer... */
2189 cancel_delayed_work(&priv->scan_check);
2190
2191 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
Ron Rindjunsky66b50042008-06-25 16:46:31 +08002192 (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) ?
2193 "2.4" : "5.2",
Zhu Yib481de92007-09-25 17:54:57 -07002194 jiffies_to_msecs(elapsed_jiffies
2195 (priv->scan_pass_start, jiffies)));
2196
Ron Rindjunsky66b50042008-06-25 16:46:31 +08002197 /* Remove this scanned band from the list of pending
2198 * bands to scan, band G precedes A in order of scanning
2199 * as seen in iwl3945_bg_request_scan */
2200 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ))
2201 priv->scan_bands &= ~BIT(IEEE80211_BAND_2GHZ);
2202 else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ))
2203 priv->scan_bands &= ~BIT(IEEE80211_BAND_5GHZ);
Zhu Yib481de92007-09-25 17:54:57 -07002204
2205 /* If a request to abort was given, or the scan did not succeed
2206 * then we reset the scan state machine and terminate,
2207 * re-queuing another scan if one has been requested */
2208 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
2209 IWL_DEBUG_INFO("Aborted scan completed.\n");
2210 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
2211 } else {
2212 /* If there are more bands on this scan pass reschedule */
2213 if (priv->scan_bands > 0)
2214 goto reschedule;
2215 }
2216
2217 priv->last_scan_jiffies = jiffies;
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08002218 priv->next_scan_jiffies = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002219 IWL_DEBUG_INFO("Setting scan to off\n");
2220
2221 clear_bit(STATUS_SCANNING, &priv->status);
2222
2223 IWL_DEBUG_INFO("Scan took %dms\n",
2224 jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies)));
2225
2226 queue_work(priv->workqueue, &priv->scan_completed);
2227
2228 return;
2229
2230reschedule:
2231 priv->scan_pass_start = jiffies;
2232 queue_work(priv->workqueue, &priv->request_scan);
2233}
2234
2235/* Handle notification from uCode that card's power state is changing
2236 * due to software, hardware, or critical temperature RFKILL */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002237static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002238 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002239{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002240 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002241 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
2242 unsigned long status = priv->status;
2243
2244 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
2245 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
2246 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
2247
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002248 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07002249 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
2250
2251 if (flags & HW_CARD_DISABLED)
2252 set_bit(STATUS_RF_KILL_HW, &priv->status);
2253 else
2254 clear_bit(STATUS_RF_KILL_HW, &priv->status);
2255
2256
2257 if (flags & SW_CARD_DISABLED)
2258 set_bit(STATUS_RF_KILL_SW, &priv->status);
2259 else
2260 clear_bit(STATUS_RF_KILL_SW, &priv->status);
2261
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08002262 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002263
2264 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
2265 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
2266 (test_bit(STATUS_RF_KILL_SW, &status) !=
2267 test_bit(STATUS_RF_KILL_SW, &priv->status)))
2268 queue_work(priv->workqueue, &priv->rf_kill);
2269 else
2270 wake_up_interruptible(&priv->wait_command_queue);
2271}
2272
2273/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002274 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07002275 *
2276 * Setup the RX handlers for each of the reply types sent from the uCode
2277 * to the host.
2278 *
2279 * This function chains into the hardware specific files for them to setup
2280 * any hardware specific handlers as well.
2281 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002282static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002283{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002284 priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
2285 priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
2286 priv->rx_handlers[REPLY_ERROR] = iwl3945_rx_reply_error;
2287 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl3945_rx_csa;
Zhu Yib481de92007-09-25 17:54:57 -07002288 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002289 iwl3945_rx_spectrum_measure_notif;
2290 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl3945_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07002291 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002292 iwl3945_rx_pm_debug_statistics_notif;
2293 priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07002294
Ben Cahill9fbab512007-11-29 11:09:47 +08002295 /*
2296 * The same handler is used for both the REPLY to a discrete
2297 * statistics request from the host as well as for the periodic
2298 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07002299 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002300 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
2301 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
Zhu Yib481de92007-09-25 17:54:57 -07002302
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002303 priv->rx_handlers[REPLY_SCAN_CMD] = iwl3945_rx_reply_scan;
2304 priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl3945_rx_scan_start_notif;
Zhu Yib481de92007-09-25 17:54:57 -07002305 priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002306 iwl3945_rx_scan_results_notif;
Zhu Yib481de92007-09-25 17:54:57 -07002307 priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002308 iwl3945_rx_scan_complete_notif;
2309 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -07002310
Ben Cahill9fbab512007-11-29 11:09:47 +08002311 /* Set up hardware specific Rx handlers */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002312 iwl3945_hw_rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002313}
2314
2315/**
Tomas Winkler91c066f2008-03-06 17:36:55 -08002316 * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries
2317 * When FW advances 'R' index, all entries between old and new 'R' index
2318 * need to be reclaimed.
2319 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002320static void iwl3945_cmd_queue_reclaim(struct iwl_priv *priv,
Tomas Winkler91c066f2008-03-06 17:36:55 -08002321 int txq_id, int index)
2322{
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08002323 struct iwl_tx_queue *txq = &priv->txq[txq_id];
Samuel Ortizd20b3c62008-12-19 10:37:15 +08002324 struct iwl_queue *q = &txq->q;
Tomas Winkler91c066f2008-03-06 17:36:55 -08002325 int nfreed = 0;
2326
Winkler, Tomas625a3812009-01-08 10:19:55 -08002327 if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002328 IWL_ERR(priv, "Read index for DMA queue txq id (%d), index %d, "
Tomas Winkler91c066f2008-03-06 17:36:55 -08002329 "is out of range [0-%d] %d %d.\n", txq_id,
2330 index, q->n_bd, q->write_ptr, q->read_ptr);
2331 return;
2332 }
2333
2334 for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
2335 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
2336 if (nfreed > 1) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002337 IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", index,
Tomas Winkler91c066f2008-03-06 17:36:55 -08002338 q->write_ptr, q->read_ptr);
2339 queue_work(priv->workqueue, &priv->restart);
2340 break;
2341 }
2342 nfreed++;
2343 }
2344}
2345
2346
2347/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002348 * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
Zhu Yib481de92007-09-25 17:54:57 -07002349 * @rxb: Rx buffer to reclaim
2350 *
2351 * If an Rx buffer has an async callback associated with it the callback
2352 * will be executed. The attached skb (if present) will only be freed
2353 * if the callback returns 1
2354 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002355static void iwl3945_tx_cmd_complete(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002356 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002357{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002358 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002359 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
2360 int txq_id = SEQ_TO_QUEUE(sequence);
2361 int index = SEQ_TO_INDEX(sequence);
Tomas Winkler600c0e12008-12-19 10:37:04 +08002362 int huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME);
Zhu Yib481de92007-09-25 17:54:57 -07002363 int cmd_index;
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08002364 struct iwl_cmd *cmd;
Zhu Yib481de92007-09-25 17:54:57 -07002365
Chatre, Reinette638d0eb2009-01-19 15:30:24 -08002366 if (WARN(txq_id != IWL_CMD_QUEUE_NUM,
2367 "wrong command queue %d, sequence 0x%X readp=%d writep=%d\n",
2368 txq_id, sequence,
2369 priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr,
2370 priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) {
2371 iwl_print_hex_dump(priv, IWL_DL_INFO , rxb, 32);
2372 return;
2373 }
Zhu Yib481de92007-09-25 17:54:57 -07002374
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08002375 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
2376 cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
Zhu Yib481de92007-09-25 17:54:57 -07002377
2378 /* Input error checking is done when commands are added to queue. */
2379 if (cmd->meta.flags & CMD_WANT_SKB) {
2380 cmd->meta.source->u.skb = rxb->skb;
2381 rxb->skb = NULL;
2382 } else if (cmd->meta.u.callback &&
2383 !cmd->meta.u.callback(priv, cmd, rxb->skb))
2384 rxb->skb = NULL;
2385
Tomas Winkler91c066f2008-03-06 17:36:55 -08002386 iwl3945_cmd_queue_reclaim(priv, txq_id, index);
Zhu Yib481de92007-09-25 17:54:57 -07002387
2388 if (!(cmd->meta.flags & CMD_ASYNC)) {
2389 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
2390 wake_up_interruptible(&priv->wait_command_queue);
2391 }
2392}
2393
2394/************************** RX-FUNCTIONS ****************************/
2395/*
2396 * Rx theory of operation
2397 *
2398 * The host allocates 32 DMA target addresses and passes the host address
2399 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
2400 * 0 to 31
2401 *
2402 * Rx Queue Indexes
2403 * The host/firmware share two index registers for managing the Rx buffers.
2404 *
2405 * The READ index maps to the first position that the firmware may be writing
2406 * to -- the driver can read up to (but not including) this position and get
2407 * good data.
2408 * The READ index is managed by the firmware once the card is enabled.
2409 *
2410 * The WRITE index maps to the last position the driver has read from -- the
2411 * position preceding WRITE is the last slot the firmware can place a packet.
2412 *
2413 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
2414 * WRITE = READ.
2415 *
Ben Cahill9fbab512007-11-29 11:09:47 +08002416 * During initialization, the host sets up the READ queue position to the first
Zhu Yib481de92007-09-25 17:54:57 -07002417 * INDEX position, and WRITE to the last (READ - 1 wrapped)
2418 *
Ben Cahill9fbab512007-11-29 11:09:47 +08002419 * When the firmware places a packet in a buffer, it will advance the READ index
Zhu Yib481de92007-09-25 17:54:57 -07002420 * and fire the RX interrupt. The driver can then query the READ index and
2421 * process as many packets as possible, moving the WRITE index forward as it
2422 * resets the Rx queue buffers with new memory.
2423 *
2424 * The management in the driver is as follows:
2425 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
2426 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Ian Schram01ebd062007-10-25 17:15:22 +08002427 * to replenish the iwl->rxq->rx_free.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002428 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
Zhu Yib481de92007-09-25 17:54:57 -07002429 * iwl->rxq is replenished and the READ INDEX is updated (updating the
2430 * 'processed' and 'read' driver indexes as well)
2431 * + A received packet is processed and handed to the kernel network stack,
2432 * detached from the iwl->rxq. The driver 'processed' index is updated.
2433 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
2434 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
2435 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
2436 * were enough free buffers and RX_STALLED is set it is cleared.
2437 *
2438 *
2439 * Driver sequence:
2440 *
Ben Cahill9fbab512007-11-29 11:09:47 +08002441 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002442 * iwl3945_rx_queue_restock
Ben Cahill9fbab512007-11-29 11:09:47 +08002443 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
Zhu Yib481de92007-09-25 17:54:57 -07002444 * queue, updates firmware pointers, and updates
2445 * the WRITE index. If insufficient rx_free buffers
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002446 * are available, schedules iwl3945_rx_replenish
Zhu Yib481de92007-09-25 17:54:57 -07002447 *
2448 * -- enable interrupts --
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002449 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
Zhu Yib481de92007-09-25 17:54:57 -07002450 * READ INDEX, detaching the SKB from the pool.
2451 * Moves the packet buffer from queue to rx_used.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002452 * Calls iwl3945_rx_queue_restock to refill any empty
Zhu Yib481de92007-09-25 17:54:57 -07002453 * slots.
2454 * ...
2455 *
2456 */
2457
2458/**
Ben Cahill9fbab512007-11-29 11:09:47 +08002459 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
Zhu Yib481de92007-09-25 17:54:57 -07002460 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002461static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07002462 dma_addr_t dma_addr)
2463{
2464 return cpu_to_le32((u32)dma_addr);
2465}
2466
2467/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002468 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
Zhu Yib481de92007-09-25 17:54:57 -07002469 *
Ben Cahill9fbab512007-11-29 11:09:47 +08002470 * If there are slots in the RX queue that need to be restocked,
Zhu Yib481de92007-09-25 17:54:57 -07002471 * and we have free pre-allocated buffers, fill the ranks as much
Ben Cahill9fbab512007-11-29 11:09:47 +08002472 * as we can, pulling from rx_free.
Zhu Yib481de92007-09-25 17:54:57 -07002473 *
2474 * This moves the 'write' index forward to catch up with 'processed', and
2475 * also updates the memory address in the firmware to reference the new
2476 * target buffer.
2477 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002478static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002479{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08002480 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07002481 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002482 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07002483 unsigned long flags;
2484 int write, rc;
2485
2486 spin_lock_irqsave(&rxq->lock, flags);
2487 write = rxq->write & ~0x7;
Winkler, Tomas37d68312009-01-08 10:19:54 -08002488 while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002489 /* Get next free Rx buffer, remove from free list */
Zhu Yib481de92007-09-25 17:54:57 -07002490 element = rxq->rx_free.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002491 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Zhu Yib481de92007-09-25 17:54:57 -07002492 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002493
2494 /* Point to Rx buffer via next RBD in circular buffer */
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002495 rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr);
Zhu Yib481de92007-09-25 17:54:57 -07002496 rxq->queue[rxq->write] = rxb;
2497 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
2498 rxq->free_count--;
2499 }
2500 spin_unlock_irqrestore(&rxq->lock, flags);
2501 /* If the pre-allocated buffer pool is dropping low, schedule to
2502 * refill it */
2503 if (rxq->free_count <= RX_LOW_WATERMARK)
2504 queue_work(priv->workqueue, &priv->rx_replenish);
2505
2506
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002507 /* If we've added more space for the firmware to place data, tell it.
2508 * Increment device's write pointer in multiples of 8. */
Zhu Yib481de92007-09-25 17:54:57 -07002509 if ((write != (rxq->write & ~0x7))
2510 || (abs(rxq->write - rxq->read) > 7)) {
2511 spin_lock_irqsave(&rxq->lock, flags);
2512 rxq->need_update = 1;
2513 spin_unlock_irqrestore(&rxq->lock, flags);
Winkler, Tomas141c43a2009-01-08 10:19:53 -08002514 rc = iwl_rx_queue_update_write_ptr(priv, rxq);
Zhu Yib481de92007-09-25 17:54:57 -07002515 if (rc)
2516 return rc;
2517 }
2518
2519 return 0;
2520}
2521
2522/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002523 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
Zhu Yib481de92007-09-25 17:54:57 -07002524 *
2525 * When moving to rx_free an SKB is allocated for the slot.
2526 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002527 * Also restock the Rx queue via iwl3945_rx_queue_restock.
Ian Schram01ebd062007-10-25 17:15:22 +08002528 * This is called as a scheduled work item (except for during initialization)
Zhu Yib481de92007-09-25 17:54:57 -07002529 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002530static void iwl3945_rx_allocate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002531{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08002532 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07002533 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002534 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07002535 unsigned long flags;
2536 spin_lock_irqsave(&rxq->lock, flags);
2537 while (!list_empty(&rxq->rx_used)) {
2538 element = rxq->rx_used.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002539 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002540
2541 /* Alloc a new receive buffer */
Zhu Yib481de92007-09-25 17:54:57 -07002542 rxb->skb =
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08002543 alloc_skb(priv->hw_params.rx_buf_size,
2544 __GFP_NOWARN | GFP_ATOMIC);
Zhu Yib481de92007-09-25 17:54:57 -07002545 if (!rxb->skb) {
2546 if (net_ratelimit())
Tomas Winkler978785a2008-12-19 10:37:31 +08002547 IWL_CRIT(priv, ": Can not allocate SKB buffers\n");
Zhu Yib481de92007-09-25 17:54:57 -07002548 /* We don't reschedule replenish work here -- we will
2549 * call the restock method and if it still needs
2550 * more buffers it will schedule replenish */
2551 break;
2552 }
Zhu Yi12342c42007-12-20 11:27:32 +08002553
2554 /* If radiotap head is required, reserve some headroom here.
2555 * The physical head count is a variable rx_stats->phy_count.
2556 * We reserve 4 bytes here. Plus these extra bytes, the
2557 * headroom of the physical head should be enough for the
2558 * radiotap head that iwl3945 supported. See iwl3945_rt.
2559 */
2560 skb_reserve(rxb->skb, 4);
2561
Zhu Yib481de92007-09-25 17:54:57 -07002562 priv->alloc_rxb_skb++;
2563 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002564
2565 /* Get physical address of RB/SKB */
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08002566 rxb->real_dma_addr = pci_map_single(priv->pci_dev,
2567 rxb->skb->data,
2568 priv->hw_params.rx_buf_size,
2569 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07002570 list_add_tail(&rxb->list, &rxq->rx_free);
2571 rxq->free_count++;
2572 }
2573 spin_unlock_irqrestore(&rxq->lock, flags);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002574}
2575
2576/*
2577 * this should be called while priv->lock is locked
2578 */
Tomas Winkler4fd1f842007-12-05 20:59:58 +02002579static void __iwl3945_rx_replenish(void *data)
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002580{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002581 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002582
2583 iwl3945_rx_allocate(priv);
2584 iwl3945_rx_queue_restock(priv);
2585}
2586
2587
2588void iwl3945_rx_replenish(void *data)
2589{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002590 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002591 unsigned long flags;
2592
2593 iwl3945_rx_allocate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002594
2595 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002596 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002597 spin_unlock_irqrestore(&priv->lock, flags);
2598}
2599
Zhu Yib481de92007-09-25 17:54:57 -07002600/* Convert linear signal-to-noise ratio into dB */
2601static u8 ratio2dB[100] = {
2602/* 0 1 2 3 4 5 6 7 8 9 */
2603 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
2604 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
2605 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
2606 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
2607 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
2608 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
2609 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
2610 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
2611 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
2612 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
2613};
2614
2615/* Calculates a relative dB value from a ratio of linear
2616 * (i.e. not dB) signal levels.
2617 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002618int iwl3945_calc_db_from_ratio(int sig_ratio)
Zhu Yib481de92007-09-25 17:54:57 -07002619{
Adrian Bunk221c80c2008-02-02 23:19:01 +02002620 /* 1000:1 or higher just report as 60 dB */
2621 if (sig_ratio >= 1000)
Zhu Yib481de92007-09-25 17:54:57 -07002622 return 60;
2623
Adrian Bunk221c80c2008-02-02 23:19:01 +02002624 /* 100:1 or higher, divide by 10 and use table,
Zhu Yib481de92007-09-25 17:54:57 -07002625 * add 20 dB to make up for divide by 10 */
Adrian Bunk221c80c2008-02-02 23:19:01 +02002626 if (sig_ratio >= 100)
Tomas Winkler3ac7f142008-07-21 02:40:14 +03002627 return 20 + (int)ratio2dB[sig_ratio/10];
Zhu Yib481de92007-09-25 17:54:57 -07002628
2629 /* We shouldn't see this */
2630 if (sig_ratio < 1)
2631 return 0;
2632
2633 /* Use table for ratios 1:1 - 99:1 */
2634 return (int)ratio2dB[sig_ratio];
2635}
2636
2637#define PERFECT_RSSI (-20) /* dBm */
2638#define WORST_RSSI (-95) /* dBm */
2639#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
2640
2641/* Calculate an indication of rx signal quality (a percentage, not dBm!).
2642 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
2643 * about formulas used below. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002644int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
Zhu Yib481de92007-09-25 17:54:57 -07002645{
2646 int sig_qual;
2647 int degradation = PERFECT_RSSI - rssi_dbm;
2648
2649 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
2650 * as indicator; formula is (signal dbm - noise dbm).
2651 * SNR at or above 40 is a great signal (100%).
2652 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
2653 * Weakest usable signal is usually 10 - 15 dB SNR. */
2654 if (noise_dbm) {
2655 if (rssi_dbm - noise_dbm >= 40)
2656 return 100;
2657 else if (rssi_dbm < noise_dbm)
2658 return 0;
2659 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
2660
2661 /* Else use just the signal level.
2662 * This formula is a least squares fit of data points collected and
2663 * compared with a reference system that had a percentage (%) display
2664 * for signal quality. */
2665 } else
2666 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
2667 (15 * RSSI_RANGE + 62 * degradation)) /
2668 (RSSI_RANGE * RSSI_RANGE);
2669
2670 if (sig_qual > 100)
2671 sig_qual = 100;
2672 else if (sig_qual < 1)
2673 sig_qual = 0;
2674
2675 return sig_qual;
2676}
2677
2678/**
Ben Cahill9fbab512007-11-29 11:09:47 +08002679 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07002680 *
2681 * Uses the priv->rx_handlers callback function array to invoke
2682 * the appropriate handlers, including command responses,
2683 * frame-received notifications, and other notifications.
2684 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002685static void iwl3945_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002686{
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002687 struct iwl_rx_mem_buffer *rxb;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002688 struct iwl_rx_packet *pkt;
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08002689 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07002690 u32 r, i;
2691 int reclaim;
2692 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002693 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08002694 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07002695
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002696 /* uCode's read index (stored in shared DRAM) indicates the last Rx
2697 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8cd812b2008-12-19 10:37:43 +08002698 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -07002699 i = rxq->read;
2700
Winkler, Tomas37d68312009-01-08 10:19:54 -08002701 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002702 fill_rx = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002703 /* Rx interrupt, but nothing sent from uCode */
2704 if (i == r)
2705 IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
2706
2707 while (i != r) {
2708 rxb = rxq->queue[i];
2709
Ben Cahill9fbab512007-11-29 11:09:47 +08002710 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07002711 * then a bug has been introduced in the queue refilling
2712 * routines -- catch it here */
2713 BUG_ON(rxb == NULL);
2714
2715 rxq->queue[i] = NULL;
2716
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002717 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08002718 priv->hw_params.rx_buf_size,
Zhu Yib481de92007-09-25 17:54:57 -07002719 PCI_DMA_FROMDEVICE);
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002720 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002721
2722 /* Reclaim a command buffer only if this packet is a response
2723 * to a (driver-originated) command.
2724 * If the packet (e.g. Rx frame) originated from uCode,
2725 * there is no command buffer to reclaim.
2726 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
2727 * but apparently a few don't get set; catch them here. */
2728 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
2729 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
2730 (pkt->hdr.cmd != REPLY_TX);
2731
2732 /* Based on type of command response or notification,
2733 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002734 * rx_handlers table. See iwl3945_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07002735 if (priv->rx_handlers[pkt->hdr.cmd]) {
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002736 IWL_DEBUG(IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07002737 "r = %d, i = %d, %s, 0x%02x\n", r, i,
2738 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
2739 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
2740 } else {
2741 /* No handling needed */
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002742 IWL_DEBUG(IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07002743 "r %d i %d No handler needed for %s, 0x%02x\n",
2744 r, i, get_cmd_string(pkt->hdr.cmd),
2745 pkt->hdr.cmd);
2746 }
2747
2748 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08002749 /* Invoke any callbacks, transfer the skb to caller, and
Samuel Ortiz518099a2009-01-19 15:30:27 -08002750 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07002751 * as we reclaim the driver command queue */
2752 if (rxb && rxb->skb)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002753 iwl3945_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07002754 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002755 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07002756 }
2757
2758 /* For now we just don't re-use anything. We can tweak this
2759 * later to try and re-use notification packets and SKBs that
2760 * fail to Rx correctly */
2761 if (rxb->skb != NULL) {
2762 priv->alloc_rxb_skb--;
2763 dev_kfree_skb_any(rxb->skb);
2764 rxb->skb = NULL;
2765 }
2766
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002767 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08002768 priv->hw_params.rx_buf_size,
2769 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07002770 spin_lock_irqsave(&rxq->lock, flags);
2771 list_add_tail(&rxb->list, &priv->rxq.rx_used);
2772 spin_unlock_irqrestore(&rxq->lock, flags);
2773 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002774 /* If there are a lot of unused frames,
2775 * restock the Rx queue so ucode won't assert. */
2776 if (fill_rx) {
2777 count++;
2778 if (count >= 8) {
2779 priv->rxq.read = i;
2780 __iwl3945_rx_replenish(priv);
2781 count = 0;
2782 }
2783 }
Zhu Yib481de92007-09-25 17:54:57 -07002784 }
2785
2786 /* Backtrack one entry */
2787 priv->rxq.read = i;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002788 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002789}
2790
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002791#ifdef CONFIG_IWL3945_DEBUG
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002792static void iwl3945_print_rx_config_cmd(struct iwl_priv *priv,
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002793 struct iwl3945_rxon_cmd *rxon)
Zhu Yib481de92007-09-25 17:54:57 -07002794{
2795 IWL_DEBUG_RADIO("RX CONFIG:\n");
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002796 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
Zhu Yib481de92007-09-25 17:54:57 -07002797 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
2798 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
2799 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
2800 le32_to_cpu(rxon->filter_flags));
2801 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
2802 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
2803 rxon->ofdm_basic_rates);
2804 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
Johannes Berge1749612008-10-27 15:59:26 -07002805 IWL_DEBUG_RADIO("u8[6] node_addr: %pM\n", rxon->node_addr);
2806 IWL_DEBUG_RADIO("u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07002807 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
2808}
2809#endif
2810
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002811static void iwl3945_enable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002812{
2813 IWL_DEBUG_ISR("Enabling interrupts\n");
2814 set_bit(STATUS_INT_ENABLED, &priv->status);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002815 iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07002816}
2817
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002818
2819/* call this function to flush any scheduled tasklet */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002820static inline void iwl_synchronize_irq(struct iwl_priv *priv)
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002821{
Tomas Winklera96a27f2008-10-23 23:48:56 -07002822 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002823 synchronize_irq(priv->pci_dev->irq);
2824 tasklet_kill(&priv->irq_tasklet);
2825}
2826
2827
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002828static inline void iwl3945_disable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002829{
2830 clear_bit(STATUS_INT_ENABLED, &priv->status);
2831
2832 /* disable interrupts from uCode/NIC to host */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002833 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07002834
2835 /* acknowledge/clear/reset any interrupts still pending
2836 * from uCode or flow handler (Rx/Tx DMA) */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002837 iwl_write32(priv, CSR_INT, 0xffffffff);
2838 iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
Zhu Yib481de92007-09-25 17:54:57 -07002839 IWL_DEBUG_ISR("Disabled interrupts\n");
2840}
2841
2842static const char *desc_lookup(int i)
2843{
2844 switch (i) {
2845 case 1:
2846 return "FAIL";
2847 case 2:
2848 return "BAD_PARAM";
2849 case 3:
2850 return "BAD_CHECKSUM";
2851 case 4:
2852 return "NMI_INTERRUPT";
2853 case 5:
2854 return "SYSASSERT";
2855 case 6:
2856 return "FATAL_ERROR";
2857 }
2858
2859 return "UNKNOWN";
2860}
2861
2862#define ERROR_START_OFFSET (1 * sizeof(u32))
2863#define ERROR_ELEM_SIZE (7 * sizeof(u32))
2864
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002865static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002866{
2867 u32 i;
2868 u32 desc, time, count, base, data1;
2869 u32 blink1, blink2, ilink1, ilink2;
2870 int rc;
2871
2872 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
2873
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002874 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002875 IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07002876 return;
2877 }
2878
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002879 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002880 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002881 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002882 return;
2883 }
2884
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002885 count = iwl_read_targ_mem(priv, base);
Zhu Yib481de92007-09-25 17:54:57 -07002886
2887 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002888 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
2889 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
2890 priv->status, count);
Zhu Yib481de92007-09-25 17:54:57 -07002891 }
2892
Winkler, Tomas15b16872008-12-19 10:37:33 +08002893 IWL_ERR(priv, "Desc Time asrtPC blink2 "
Zhu Yib481de92007-09-25 17:54:57 -07002894 "ilink1 nmiPC Line\n");
2895 for (i = ERROR_START_OFFSET;
2896 i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
2897 i += ERROR_ELEM_SIZE) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002898 desc = iwl_read_targ_mem(priv, base + i);
Zhu Yib481de92007-09-25 17:54:57 -07002899 time =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002900 iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002901 blink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002902 iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002903 blink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002904 iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002905 ilink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002906 iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002907 ilink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002908 iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002909 data1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002910 iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002911
Winkler, Tomas15b16872008-12-19 10:37:33 +08002912 IWL_ERR(priv,
2913 "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
2914 desc_lookup(desc), desc, time, blink1, blink2,
2915 ilink1, ilink2, data1);
Zhu Yib481de92007-09-25 17:54:57 -07002916 }
2917
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002918 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002919
2920}
2921
Ben Cahillf58177b2007-11-29 11:09:43 +08002922#define EVENT_START_OFFSET (6 * sizeof(u32))
Zhu Yib481de92007-09-25 17:54:57 -07002923
2924/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002925 * iwl3945_print_event_log - Dump error event log to syslog
Zhu Yib481de92007-09-25 17:54:57 -07002926 *
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002927 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
Zhu Yib481de92007-09-25 17:54:57 -07002928 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002929static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
Zhu Yib481de92007-09-25 17:54:57 -07002930 u32 num_events, u32 mode)
2931{
2932 u32 i;
2933 u32 base; /* SRAM byte address of event log header */
2934 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
2935 u32 ptr; /* SRAM byte address of log data */
2936 u32 ev, time, data; /* event log data */
2937
2938 if (num_events == 0)
2939 return;
2940
2941 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
2942
2943 if (mode == 0)
2944 event_size = 2 * sizeof(u32);
2945 else
2946 event_size = 3 * sizeof(u32);
2947
2948 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
2949
2950 /* "time" is actually "data" for mode 0 (no timestamp).
2951 * place event id # at far right for easier visual parsing. */
2952 for (i = 0; i < num_events; i++) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002953 ev = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002954 ptr += sizeof(u32);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002955 time = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002956 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08002957 if (mode == 0) {
2958 /* data, ev */
2959 IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
2960 } else {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002961 data = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002962 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08002963 IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev);
Zhu Yib481de92007-09-25 17:54:57 -07002964 }
2965 }
2966}
2967
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002968static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002969{
2970 int rc;
2971 u32 base; /* SRAM byte address of event log header */
2972 u32 capacity; /* event log capacity in # entries */
2973 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
2974 u32 num_wraps; /* # times uCode wrapped to top of log */
2975 u32 next_entry; /* index of next entry to be written by uCode */
2976 u32 size; /* # entries that we'll print */
2977
2978 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002979 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002980 IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07002981 return;
2982 }
2983
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002984 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002985 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002986 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002987 return;
2988 }
2989
2990 /* event log header */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002991 capacity = iwl_read_targ_mem(priv, base);
2992 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
2993 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
2994 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
Zhu Yib481de92007-09-25 17:54:57 -07002995
2996 size = num_wraps ? capacity : next_entry;
2997
2998 /* bail out if nothing in log */
2999 if (size == 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003000 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003001 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003002 return;
3003 }
3004
Winkler, Tomas15b16872008-12-19 10:37:33 +08003005 IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003006 size, num_wraps);
3007
3008 /* if uCode has wrapped back to top of log, start at the oldest entry,
3009 * i.e the next one that uCode would fill. */
3010 if (num_wraps)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003011 iwl3945_print_event_log(priv, next_entry,
Zhu Yib481de92007-09-25 17:54:57 -07003012 capacity - next_entry, mode);
3013
3014 /* (then/else) start at top of log */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003015 iwl3945_print_event_log(priv, 0, next_entry, mode);
Zhu Yib481de92007-09-25 17:54:57 -07003016
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003017 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003018}
3019
3020/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003021 * iwl3945_irq_handle_error - called for HW or SW error interrupt from card
Zhu Yib481de92007-09-25 17:54:57 -07003022 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003023static void iwl3945_irq_handle_error(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003024{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003025 /* Set the FW error flag -- cleared on iwl3945_down */
Zhu Yib481de92007-09-25 17:54:57 -07003026 set_bit(STATUS_FW_ERROR, &priv->status);
3027
3028 /* Cancel currently queued command. */
3029 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
3030
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003031#ifdef CONFIG_IWL3945_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003032 if (priv->debug_level & IWL_DL_FW_ERRORS) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003033 iwl3945_dump_nic_error_log(priv);
3034 iwl3945_dump_nic_event_log(priv);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08003035 iwl3945_print_rx_config_cmd(priv, &priv->staging39_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07003036 }
3037#endif
3038
3039 wake_up_interruptible(&priv->wait_command_queue);
3040
3041 /* Keep the restart process from trying to send host
3042 * commands by clearing the INIT status bit */
3043 clear_bit(STATUS_READY, &priv->status);
3044
3045 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
3046 IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS,
3047 "Restarting adapter due to uCode error.\n");
3048
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003049 if (iwl3945_is_associated(priv)) {
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08003050 memcpy(&priv->recovery39_rxon, &priv->active39_rxon,
3051 sizeof(priv->recovery39_rxon));
Zhu Yib481de92007-09-25 17:54:57 -07003052 priv->error_recovering = 1;
3053 }
3054 queue_work(priv->workqueue, &priv->restart);
3055 }
3056}
3057
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003058static void iwl3945_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003059{
3060 unsigned long flags;
3061
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08003062 memcpy(&priv->staging39_rxon, &priv->recovery39_rxon,
3063 sizeof(priv->staging39_rxon));
3064 priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003065 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003066
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003067 iwl3945_add_station(priv, priv->bssid, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003068
3069 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08003070 priv->assoc_id = le16_to_cpu(priv->staging39_rxon.assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003071 priv->error_recovering = 0;
3072 spin_unlock_irqrestore(&priv->lock, flags);
3073}
3074
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003075static void iwl3945_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003076{
3077 u32 inta, handled = 0;
3078 u32 inta_fh;
3079 unsigned long flags;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003080#ifdef CONFIG_IWL3945_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07003081 u32 inta_mask;
3082#endif
3083
3084 spin_lock_irqsave(&priv->lock, flags);
3085
3086 /* Ack/clear/reset pending uCode interrupts.
3087 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
3088 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003089 inta = iwl_read32(priv, CSR_INT);
3090 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07003091
3092 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
3093 * Any new interrupts that happen after this, either while we're
3094 * in this tasklet, or later, will show up in next ISR/tasklet. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003095 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
3096 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07003097
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003098#ifdef CONFIG_IWL3945_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003099 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08003100 /* just for debug */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003101 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07003102 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
3103 inta, inta_mask, inta_fh);
3104 }
3105#endif
3106
3107 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
3108 * atomic, make sure that inta covers all the interrupts that
3109 * we've discovered, even if FH interrupt came in just after
3110 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08003111 if (inta_fh & CSR39_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07003112 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08003113 if (inta_fh & CSR39_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07003114 inta |= CSR_INT_BIT_FH_TX;
3115
3116 /* Now service all interrupt bits discovered above. */
3117 if (inta & CSR_INT_BIT_HW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003118 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003119
3120 /* Tell the device to stop sending interrupts */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003121 iwl3945_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003122
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003123 iwl3945_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003124
3125 handled |= CSR_INT_BIT_HW_ERR;
3126
3127 spin_unlock_irqrestore(&priv->lock, flags);
3128
3129 return;
3130 }
3131
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003132#ifdef CONFIG_IWL3945_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003133 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07003134 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08003135 if (inta & CSR_INT_BIT_SCD)
3136 IWL_DEBUG_ISR("Scheduler finished to transmit "
3137 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003138
3139 /* Alive notification via Rx interrupt will do the real work */
3140 if (inta & CSR_INT_BIT_ALIVE)
3141 IWL_DEBUG_ISR("Alive interrupt\n");
3142 }
3143#endif
3144 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08003145 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07003146
Zhu Yib481de92007-09-25 17:54:57 -07003147 /* Error detected by uCode */
3148 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003149 IWL_ERR(priv, "Microcode SW error detected. "
3150 "Restarting 0x%X.\n", inta);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003151 iwl3945_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003152 handled |= CSR_INT_BIT_SW_ERR;
3153 }
3154
3155 /* uCode wakes up after power-down sleep */
3156 if (inta & CSR_INT_BIT_WAKEUP) {
3157 IWL_DEBUG_ISR("Wakeup interrupt\n");
Winkler, Tomas141c43a2009-01-08 10:19:53 -08003158 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08003159 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
3160 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
3161 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
3162 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
3163 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
3164 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07003165
3166 handled |= CSR_INT_BIT_WAKEUP;
3167 }
3168
3169 /* All uCode command responses, including Tx command responses,
3170 * Rx "responses" (frame-received notification), and other
3171 * notifications from uCode come through here*/
3172 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003173 iwl3945_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003174 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
3175 }
3176
3177 if (inta & CSR_INT_BIT_FH_TX) {
3178 IWL_DEBUG_ISR("Tx interrupt\n");
3179
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003180 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
3181 if (!iwl_grab_nic_access(priv)) {
3182 iwl_write_direct32(priv, FH39_TCSR_CREDIT
Tomas Winklerbddadf82008-12-19 10:37:01 +08003183 (FH39_SRVC_CHNL), 0x0);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003184 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003185 }
3186 handled |= CSR_INT_BIT_FH_TX;
3187 }
3188
3189 if (inta & ~handled)
Winkler, Tomas15b16872008-12-19 10:37:33 +08003190 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Zhu Yib481de92007-09-25 17:54:57 -07003191
3192 if (inta & ~CSR_INI_SET_MASK) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003193 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Zhu Yib481de92007-09-25 17:54:57 -07003194 inta & ~CSR_INI_SET_MASK);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003195 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07003196 }
3197
3198 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003199 /* only Re-enable if disabled by irq */
3200 if (test_bit(STATUS_INT_ENABLED, &priv->status))
3201 iwl3945_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003202
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003203#ifdef CONFIG_IWL3945_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003204 if (priv->debug_level & (IWL_DL_ISR)) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003205 inta = iwl_read32(priv, CSR_INT);
3206 inta_mask = iwl_read32(priv, CSR_INT_MASK);
3207 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07003208 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
3209 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
3210 }
3211#endif
3212 spin_unlock_irqrestore(&priv->lock, flags);
3213}
3214
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003215static irqreturn_t iwl3945_isr(int irq, void *data)
Zhu Yib481de92007-09-25 17:54:57 -07003216{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003217 struct iwl_priv *priv = data;
Zhu Yib481de92007-09-25 17:54:57 -07003218 u32 inta, inta_mask;
3219 u32 inta_fh;
3220 if (!priv)
3221 return IRQ_NONE;
3222
3223 spin_lock(&priv->lock);
3224
3225 /* Disable (but don't clear!) interrupts here to avoid
3226 * back-to-back ISRs and sporadic interrupts from our NIC.
3227 * If we have something to service, the tasklet will re-enable ints.
3228 * If we *don't* have something, we'll re-enable before leaving here. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003229 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
3230 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07003231
3232 /* Discover which interrupts are active/pending */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003233 inta = iwl_read32(priv, CSR_INT);
3234 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07003235
3236 /* Ignore interrupt if there's nothing in NIC to service.
3237 * This may be due to IRQ shared with another device,
3238 * or due to sporadic interrupts thrown from our NIC. */
3239 if (!inta && !inta_fh) {
3240 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
3241 goto none;
3242 }
3243
3244 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
3245 /* Hardware disappeared */
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003246 IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
Oliver Neukumcb4da1a2007-11-13 21:10:32 -08003247 goto unplugged;
Zhu Yib481de92007-09-25 17:54:57 -07003248 }
3249
3250 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
3251 inta, inta_mask, inta_fh);
3252
Joonwoo Park25c03d82008-01-23 10:15:20 -08003253 inta &= ~CSR_INT_BIT_SCD;
3254
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003255 /* iwl3945_irq_tasklet() will service interrupts and re-enable them */
Joonwoo Park25c03d82008-01-23 10:15:20 -08003256 if (likely(inta || inta_fh))
3257 tasklet_schedule(&priv->irq_tasklet);
Oliver Neukumcb4da1a2007-11-13 21:10:32 -08003258unplugged:
Zhu Yib481de92007-09-25 17:54:57 -07003259 spin_unlock(&priv->lock);
3260
3261 return IRQ_HANDLED;
3262
3263 none:
3264 /* re-enable interrupts here since we don't have anything to service. */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003265 /* only Re-enable if disabled by irq */
3266 if (test_bit(STATUS_INT_ENABLED, &priv->status))
3267 iwl3945_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003268 spin_unlock(&priv->lock);
3269 return IRQ_NONE;
3270}
3271
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003272static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01003273 enum ieee80211_band band,
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003274 u8 is_active, u8 n_probes,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003275 struct iwl3945_scan_channel *scan_ch)
Zhu Yib481de92007-09-25 17:54:57 -07003276{
3277 const struct ieee80211_channel *channels = NULL;
Johannes Berg8318d782008-01-24 19:38:38 +01003278 const struct ieee80211_supported_band *sband;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08003279 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07003280 u16 passive_dwell = 0;
3281 u16 active_dwell = 0;
3282 int added, i;
3283
Kolekar, Abhijeetcbba18c2008-12-19 10:37:42 +08003284 sband = iwl_get_hw_mode(priv, band);
Johannes Berg8318d782008-01-24 19:38:38 +01003285 if (!sband)
Zhu Yib481de92007-09-25 17:54:57 -07003286 return 0;
3287
Johannes Berg8318d782008-01-24 19:38:38 +01003288 channels = sband->channels;
Zhu Yib481de92007-09-25 17:54:57 -07003289
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08003290 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
3291 passive_dwell = iwl_get_passive_dwell_time(priv, band);
Zhu Yib481de92007-09-25 17:54:57 -07003292
Abhijeet Kolekar8f4807a2008-09-03 11:26:31 +08003293 if (passive_dwell <= active_dwell)
3294 passive_dwell = active_dwell + 1;
3295
Johannes Berg8318d782008-01-24 19:38:38 +01003296 for (i = 0, added = 0; i < sband->n_channels; i++) {
Johannes Berg182e2e62008-04-04 10:41:56 +02003297 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
3298 continue;
3299
Johannes Berg8318d782008-01-24 19:38:38 +01003300 scan_ch->channel = channels[i].hw_value;
Zhu Yib481de92007-09-25 17:54:57 -07003301
Samuel Ortize6148912009-01-23 13:45:15 -08003302 ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
Zhu Yib481de92007-09-25 17:54:57 -07003303 if (!is_channel_valid(ch_info)) {
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003304 IWL_DEBUG_SCAN("Channel %d is INVALID for this band.\n",
Zhu Yib481de92007-09-25 17:54:57 -07003305 scan_ch->channel);
3306 continue;
3307 }
3308
Zhu Yib481de92007-09-25 17:54:57 -07003309 scan_ch->active_dwell = cpu_to_le16(active_dwell);
3310 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08003311 /* If passive , set up for auto-switch
3312 * and use long active_dwell time.
3313 */
3314 if (!is_active || is_channel_passive(ch_info) ||
3315 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
3316 scan_ch->type = 0; /* passive */
3317 if (IWL_UCODE_API(priv->ucode_ver) == 1)
3318 scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
3319 } else {
3320 scan_ch->type = 1; /* active */
3321 }
3322
3323 /* Set direct probe bits. These may be used both for active
3324 * scan channels (probes gets sent right away),
3325 * or for passive channels (probes get se sent only after
3326 * hearing clear Rx packet).*/
3327 if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
3328 if (n_probes)
3329 scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes);
3330 } else {
3331 /* uCode v1 does not allow setting direct probe bits on
3332 * passive channel. */
3333 if ((scan_ch->type & 1) && n_probes)
3334 scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes);
3335 }
Zhu Yib481de92007-09-25 17:54:57 -07003336
Ben Cahill9fbab512007-11-29 11:09:47 +08003337 /* Set txpower levels to defaults */
Zhu Yib481de92007-09-25 17:54:57 -07003338 scan_ch->tpc.dsp_atten = 110;
3339 /* scan_pwr_info->tpc.dsp_atten; */
3340
3341 /*scan_pwr_info->tpc.tx_gain; */
Johannes Berg8318d782008-01-24 19:38:38 +01003342 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -07003343 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
3344 else {
3345 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
3346 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
Ben Cahill9fbab512007-11-29 11:09:47 +08003347 * power level:
Reinette Chatre8a1b0242008-01-14 17:46:25 -08003348 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
Zhu Yib481de92007-09-25 17:54:57 -07003349 */
3350 }
3351
3352 IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
3353 scan_ch->channel,
3354 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
3355 (scan_ch->type & 1) ?
3356 active_dwell : passive_dwell);
3357
3358 scan_ch++;
3359 added++;
3360 }
3361
3362 IWL_DEBUG_SCAN("total channels to scan %d \n", added);
3363 return added;
3364}
3365
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003366static void iwl3945_init_hw_rates(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07003367 struct ieee80211_rate *rates)
3368{
3369 int i;
3370
3371 for (i = 0; i < IWL_RATE_COUNT; i++) {
Johannes Berg8318d782008-01-24 19:38:38 +01003372 rates[i].bitrate = iwl3945_rates[i].ieee * 5;
3373 rates[i].hw_value = i; /* Rate scaling will work on indexes */
3374 rates[i].hw_value_short = i;
3375 rates[i].flags = 0;
Samuel Ortizd9829a62008-12-19 10:37:12 +08003376 if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
Zhu Yib481de92007-09-25 17:54:57 -07003377 /*
Johannes Berg8318d782008-01-24 19:38:38 +01003378 * If CCK != 1M then set short preamble rate flag.
Zhu Yib481de92007-09-25 17:54:57 -07003379 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003380 rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
Johannes Berg8318d782008-01-24 19:38:38 +01003381 0 : IEEE80211_RATE_SHORT_PREAMBLE;
Zhu Yib481de92007-09-25 17:54:57 -07003382 }
Zhu Yib481de92007-09-25 17:54:57 -07003383 }
3384}
3385
3386/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003387 * iwl3945_init_geos - Initialize mac80211's geo/channel info based from eeprom
Zhu Yib481de92007-09-25 17:54:57 -07003388 */
Samuel Ortize6148912009-01-23 13:45:15 -08003389#define IEEE80211_24GHZ_MAX_CHANNEL 14
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003390static int iwl3945_init_geos(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003391{
Samuel Ortizd20b3c62008-12-19 10:37:15 +08003392 struct iwl_channel_info *ch;
Tomas Winkler8211ef72008-03-02 01:36:04 +02003393 struct ieee80211_supported_band *sband;
Zhu Yib481de92007-09-25 17:54:57 -07003394 struct ieee80211_channel *channels;
3395 struct ieee80211_channel *geo_ch;
3396 struct ieee80211_rate *rates;
3397 int i = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003398
Johannes Berg8318d782008-01-24 19:38:38 +01003399 if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
3400 priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
Zhu Yib481de92007-09-25 17:54:57 -07003401 IWL_DEBUG_INFO("Geography modes already initialized.\n");
3402 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
3403 return 0;
3404 }
3405
Zhu Yib481de92007-09-25 17:54:57 -07003406 channels = kzalloc(sizeof(struct ieee80211_channel) *
3407 priv->channel_count, GFP_KERNEL);
Johannes Berg8318d782008-01-24 19:38:38 +01003408 if (!channels)
Zhu Yib481de92007-09-25 17:54:57 -07003409 return -ENOMEM;
Zhu Yib481de92007-09-25 17:54:57 -07003410
Tomas Winkler8211ef72008-03-02 01:36:04 +02003411 rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)),
Zhu Yib481de92007-09-25 17:54:57 -07003412 GFP_KERNEL);
3413 if (!rates) {
Zhu Yib481de92007-09-25 17:54:57 -07003414 kfree(channels);
3415 return -ENOMEM;
3416 }
3417
Zhu Yib481de92007-09-25 17:54:57 -07003418 /* 5.2GHz channels start after the 2.4GHz channels */
Tomas Winkler8211ef72008-03-02 01:36:04 +02003419 sband = &priv->bands[IEEE80211_BAND_5GHZ];
Samuel Ortize6148912009-01-23 13:45:15 -08003420 sband->channels = &channels[IEEE80211_24GHZ_MAX_CHANNEL];
Tomas Winkler8211ef72008-03-02 01:36:04 +02003421 /* just OFDM */
3422 sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
3423 sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE;
Zhu Yib481de92007-09-25 17:54:57 -07003424
Tomas Winkler8211ef72008-03-02 01:36:04 +02003425 sband = &priv->bands[IEEE80211_BAND_2GHZ];
3426 sband->channels = channels;
3427 /* OFDM & CCK */
3428 sband->bitrates = rates;
3429 sband->n_bitrates = IWL_RATE_COUNT;
Zhu Yib481de92007-09-25 17:54:57 -07003430
3431 priv->ieee_channels = channels;
3432 priv->ieee_rates = rates;
3433
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003434 iwl3945_init_hw_rates(priv, rates);
Zhu Yib481de92007-09-25 17:54:57 -07003435
Tomas Winkler8211ef72008-03-02 01:36:04 +02003436 for (i = 0; i < priv->channel_count; i++) {
Zhu Yib481de92007-09-25 17:54:57 -07003437 ch = &priv->channel_info[i];
3438
Tomas Winkler8211ef72008-03-02 01:36:04 +02003439 /* FIXME: might be removed if scan is OK*/
3440 if (!is_channel_valid(ch))
Zhu Yib481de92007-09-25 17:54:57 -07003441 continue;
Zhu Yib481de92007-09-25 17:54:57 -07003442
3443 if (is_channel_a_band(ch))
Tomas Winkler8211ef72008-03-02 01:36:04 +02003444 sband = &priv->bands[IEEE80211_BAND_5GHZ];
Johannes Berg8318d782008-01-24 19:38:38 +01003445 else
Tomas Winkler8211ef72008-03-02 01:36:04 +02003446 sband = &priv->bands[IEEE80211_BAND_2GHZ];
Zhu Yib481de92007-09-25 17:54:57 -07003447
Tomas Winkler8211ef72008-03-02 01:36:04 +02003448 geo_ch = &sband->channels[sband->n_channels++];
3449
3450 geo_ch->center_freq = ieee80211_channel_to_frequency(ch->channel);
Johannes Berg8318d782008-01-24 19:38:38 +01003451 geo_ch->max_power = ch->max_power_avg;
3452 geo_ch->max_antenna_gain = 0xff;
Mohamed Abbas7b723042008-01-31 21:46:40 -08003453 geo_ch->hw_value = ch->channel;
Zhu Yib481de92007-09-25 17:54:57 -07003454
3455 if (is_channel_valid(ch)) {
Johannes Berg8318d782008-01-24 19:38:38 +01003456 if (!(ch->flags & EEPROM_CHANNEL_IBSS))
3457 geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
Zhu Yib481de92007-09-25 17:54:57 -07003458
Johannes Berg8318d782008-01-24 19:38:38 +01003459 if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
3460 geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
Zhu Yib481de92007-09-25 17:54:57 -07003461
3462 if (ch->flags & EEPROM_CHANNEL_RADAR)
Johannes Berg8318d782008-01-24 19:38:38 +01003463 geo_ch->flags |= IEEE80211_CHAN_RADAR;
Zhu Yib481de92007-09-25 17:54:57 -07003464
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08003465 if (ch->max_power_avg > priv->tx_power_channel_lmt)
3466 priv->tx_power_channel_lmt =
Zhu Yib481de92007-09-25 17:54:57 -07003467 ch->max_power_avg;
Tomas Winkler8211ef72008-03-02 01:36:04 +02003468 } else {
Johannes Berg8318d782008-01-24 19:38:38 +01003469 geo_ch->flags |= IEEE80211_CHAN_DISABLED;
Tomas Winkler8211ef72008-03-02 01:36:04 +02003470 }
3471
3472 /* Save flags for reg domain usage */
3473 geo_ch->orig_flags = geo_ch->flags;
3474
3475 IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n",
3476 ch->channel, geo_ch->center_freq,
3477 is_channel_a_band(ch) ? "5.2" : "2.4",
3478 geo_ch->flags & IEEE80211_CHAN_DISABLED ?
3479 "restricted" : "valid",
3480 geo_ch->flags);
Zhu Yib481de92007-09-25 17:54:57 -07003481 }
3482
Tomas Winkler82b9a122008-03-04 18:09:30 -08003483 if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
3484 priv->cfg->sku & IWL_SKU_A) {
Tomas Winkler978785a2008-12-19 10:37:31 +08003485 IWL_INFO(priv, "Incorrectly detected BG card as ABG. "
3486 "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n",
3487 priv->pci_dev->device, priv->pci_dev->subsystem_device);
Tomas Winkler82b9a122008-03-04 18:09:30 -08003488 priv->cfg->sku &= ~IWL_SKU_A;
Zhu Yib481de92007-09-25 17:54:57 -07003489 }
3490
Tomas Winkler978785a2008-12-19 10:37:31 +08003491 IWL_INFO(priv, "Tunable channels: %d 802.11bg, %d 802.11a channels\n",
Johannes Berg8318d782008-01-24 19:38:38 +01003492 priv->bands[IEEE80211_BAND_2GHZ].n_channels,
3493 priv->bands[IEEE80211_BAND_5GHZ].n_channels);
Zhu Yib481de92007-09-25 17:54:57 -07003494
John W. Linvillee0e0a672008-03-25 15:58:40 -04003495 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
3496 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
3497 &priv->bands[IEEE80211_BAND_2GHZ];
3498 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
3499 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
3500 &priv->bands[IEEE80211_BAND_5GHZ];
Zhu Yib481de92007-09-25 17:54:57 -07003501
Zhu Yib481de92007-09-25 17:54:57 -07003502 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
3503
3504 return 0;
3505}
3506
Reinette Chatre849e0dc2008-01-23 10:15:18 -08003507/*
3508 * iwl3945_free_geos - undo allocations in iwl3945_init_geos
3509 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003510static void iwl3945_free_geos(struct iwl_priv *priv)
Reinette Chatre849e0dc2008-01-23 10:15:18 -08003511{
Reinette Chatre849e0dc2008-01-23 10:15:18 -08003512 kfree(priv->ieee_channels);
3513 kfree(priv->ieee_rates);
3514 clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
3515}
3516
Zhu Yib481de92007-09-25 17:54:57 -07003517/******************************************************************************
3518 *
3519 * uCode download functions
3520 *
3521 ******************************************************************************/
3522
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003523static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003524{
Tomas Winkler98c92212008-01-14 17:46:20 -08003525 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
3526 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
3527 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
3528 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
3529 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
3530 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07003531}
3532
3533/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003534 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07003535 * looking at all data.
3536 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003537static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07003538{
3539 u32 val;
3540 u32 save_len = len;
3541 int rc = 0;
3542 u32 errcnt;
3543
3544 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
3545
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003546 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003547 if (rc)
3548 return rc;
3549
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003550 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08003551 IWL39_RTC_INST_LOWER_BOUND);
Zhu Yib481de92007-09-25 17:54:57 -07003552
3553 errcnt = 0;
3554 for (; len > 0; len -= sizeof(u32), image++) {
3555 /* read data comes through single port, auto-incr addr */
3556 /* NOTE: Use the debugless read so we don't flood kernel log
3557 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003558 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07003559 if (val != le32_to_cpu(*image)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003560 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07003561 "offset 0x%x, is 0x%x, s/b 0x%x\n",
3562 save_len - len, val, le32_to_cpu(*image));
3563 rc = -EIO;
3564 errcnt++;
3565 if (errcnt >= 20)
3566 break;
3567 }
3568 }
3569
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003570 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003571
3572 if (!errcnt)
Ian Schrambc434dd2007-10-25 17:15:29 +08003573 IWL_DEBUG_INFO("ucode image in INSTRUCTION memory is good\n");
Zhu Yib481de92007-09-25 17:54:57 -07003574
3575 return rc;
3576}
3577
3578
3579/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003580 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07003581 * using sample data 100 bytes apart. If these sample points are good,
3582 * it's a pretty good bet that everything between them is good, too.
3583 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003584static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07003585{
3586 u32 val;
3587 int rc = 0;
3588 u32 errcnt = 0;
3589 u32 i;
3590
3591 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
3592
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003593 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003594 if (rc)
3595 return rc;
3596
3597 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
3598 /* read data comes through single port, auto-incr addr */
3599 /* NOTE: Use the debugless read so we don't flood kernel log
3600 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003601 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08003602 i + IWL39_RTC_INST_LOWER_BOUND);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003603 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07003604 if (val != le32_to_cpu(*image)) {
3605#if 0 /* Enable this if you want to see details */
Winkler, Tomas15b16872008-12-19 10:37:33 +08003606 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07003607 "offset 0x%x, is 0x%x, s/b 0x%x\n",
3608 i, val, *image);
3609#endif
3610 rc = -EIO;
3611 errcnt++;
3612 if (errcnt >= 3)
3613 break;
3614 }
3615 }
3616
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003617 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003618
3619 return rc;
3620}
3621
3622
3623/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003624 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
Zhu Yib481de92007-09-25 17:54:57 -07003625 * and verify its contents
3626 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003627static int iwl3945_verify_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003628{
3629 __le32 *image;
3630 u32 len;
3631 int rc = 0;
3632
3633 /* Try bootstrap */
3634 image = (__le32 *)priv->ucode_boot.v_addr;
3635 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003636 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07003637 if (rc == 0) {
3638 IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
3639 return 0;
3640 }
3641
3642 /* Try initialize */
3643 image = (__le32 *)priv->ucode_init.v_addr;
3644 len = priv->ucode_init.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003645 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07003646 if (rc == 0) {
3647 IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
3648 return 0;
3649 }
3650
3651 /* Try runtime/protocol */
3652 image = (__le32 *)priv->ucode_code.v_addr;
3653 len = priv->ucode_code.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003654 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07003655 if (rc == 0) {
3656 IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
3657 return 0;
3658 }
3659
Winkler, Tomas15b16872008-12-19 10:37:33 +08003660 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
Zhu Yib481de92007-09-25 17:54:57 -07003661
Ben Cahill9fbab512007-11-29 11:09:47 +08003662 /* Since nothing seems to match, show first several data entries in
3663 * instruction SRAM, so maybe visual inspection will give a clue.
3664 * Selection of bootstrap image (vs. other images) is arbitrary. */
Zhu Yib481de92007-09-25 17:54:57 -07003665 image = (__le32 *)priv->ucode_boot.v_addr;
3666 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003667 rc = iwl3945_verify_inst_full(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07003668
3669 return rc;
3670}
3671
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003672static void iwl3945_nic_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003673{
3674 /* Remove all resets to allow NIC to operate */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003675 iwl_write32(priv, CSR_RESET, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003676}
3677
3678/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003679 * iwl3945_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07003680 *
3681 * Copy into buffers for card to fetch via bus-mastering
3682 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003683static int iwl3945_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003684{
Kolekar, Abhijeeta78fe752008-12-19 10:37:21 +08003685 struct iwl_ucode *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08003686 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07003687 const struct firmware *ucode_raw;
3688 /* firmware file name contains uCode/driver compatibility version */
Reinette Chatrea0987a82008-12-02 12:14:06 -08003689 const char *name_pre = priv->cfg->fw_name_pre;
3690 const unsigned int api_max = priv->cfg->ucode_api_max;
3691 const unsigned int api_min = priv->cfg->ucode_api_min;
3692 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07003693 u8 *src;
3694 size_t len;
Reinette Chatrea0987a82008-12-02 12:14:06 -08003695 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
Zhu Yib481de92007-09-25 17:54:57 -07003696
3697 /* Ask kernel firmware_class module to get the boot firmware off disk.
3698 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08003699 for (index = api_max; index >= api_min; index--) {
3700 sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
3701 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
3702 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003703 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08003704 buf, ret);
3705 if (ret == -ENOENT)
3706 continue;
3707 else
3708 goto error;
3709 } else {
3710 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08003711 IWL_ERR(priv, "Loaded firmware %s, "
3712 "which is deprecated. "
3713 " Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08003714 buf, api_max);
3715 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
3716 buf, ucode_raw->size);
3717 break;
3718 }
Zhu Yib481de92007-09-25 17:54:57 -07003719 }
3720
Reinette Chatrea0987a82008-12-02 12:14:06 -08003721 if (ret < 0)
3722 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07003723
3724 /* Make sure that we got at least our header! */
3725 if (ucode_raw->size < sizeof(*ucode)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003726 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08003727 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003728 goto err_release;
3729 }
3730
3731 /* Data from ucode file: header followed by uCode images */
3732 ucode = (void *)ucode_raw->data;
3733
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08003734 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08003735 api_ver = IWL_UCODE_API(priv->ucode_ver);
Zhu Yib481de92007-09-25 17:54:57 -07003736 inst_size = le32_to_cpu(ucode->inst_size);
3737 data_size = le32_to_cpu(ucode->data_size);
3738 init_size = le32_to_cpu(ucode->init_size);
3739 init_data_size = le32_to_cpu(ucode->init_data_size);
3740 boot_size = le32_to_cpu(ucode->boot_size);
3741
Reinette Chatrea0987a82008-12-02 12:14:06 -08003742 /* api_ver should match the api version forming part of the
3743 * firmware filename ... but we don't check for that and only rely
3744 * on the API version read from firware header from here on forward */
3745
3746 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003747 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08003748 "Driver supports v%u, firmware is v%u.\n",
3749 api_max, api_ver);
3750 priv->ucode_ver = 0;
3751 ret = -EINVAL;
3752 goto err_release;
3753 }
3754 if (api_ver != api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08003755 IWL_ERR(priv, "Firmware has old API version. Expected %u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08003756 "got %u. New firmware can be obtained "
3757 "from http://www.intellinuxwireless.org.\n",
3758 api_max, api_ver);
3759
Tomas Winkler978785a2008-12-19 10:37:31 +08003760 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
3761 IWL_UCODE_MAJOR(priv->ucode_ver),
3762 IWL_UCODE_MINOR(priv->ucode_ver),
3763 IWL_UCODE_API(priv->ucode_ver),
3764 IWL_UCODE_SERIAL(priv->ucode_ver));
3765
Reinette Chatrea0987a82008-12-02 12:14:06 -08003766 IWL_DEBUG_INFO("f/w package hdr ucode version raw = 0x%x\n",
3767 priv->ucode_ver);
Ian Schrambc434dd2007-10-25 17:15:29 +08003768 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", inst_size);
3769 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", data_size);
3770 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", init_size);
3771 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", init_data_size);
3772 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", boot_size);
Zhu Yib481de92007-09-25 17:54:57 -07003773
Reinette Chatrea0987a82008-12-02 12:14:06 -08003774
Zhu Yib481de92007-09-25 17:54:57 -07003775 /* Verify size of file vs. image size info in file's header */
3776 if (ucode_raw->size < sizeof(*ucode) +
3777 inst_size + data_size + init_size +
3778 init_data_size + boot_size) {
3779
3780 IWL_DEBUG_INFO("uCode file size %d too small\n",
3781 (int)ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08003782 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003783 goto err_release;
3784 }
3785
3786 /* Verify that uCode images will fit in card's SRAM */
Samuel Ortiz250bdd22008-12-19 10:37:11 +08003787 if (inst_size > IWL39_MAX_INST_SIZE) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08003788 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
3789 inst_size);
3790 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003791 goto err_release;
3792 }
3793
Samuel Ortiz250bdd22008-12-19 10:37:11 +08003794 if (data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08003795 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
3796 data_size);
3797 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003798 goto err_release;
3799 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08003800 if (init_size > IWL39_MAX_INST_SIZE) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08003801 IWL_DEBUG_INFO("uCode init instr len %d too large to fit in\n",
3802 init_size);
3803 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003804 goto err_release;
3805 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08003806 if (init_data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08003807 IWL_DEBUG_INFO("uCode init data len %d too large to fit in\n",
3808 init_data_size);
3809 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003810 goto err_release;
3811 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08003812 if (boot_size > IWL39_MAX_BSM_SIZE) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08003813 IWL_DEBUG_INFO("uCode boot instr len %d too large to fit in\n",
3814 boot_size);
3815 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003816 goto err_release;
3817 }
3818
3819 /* Allocate ucode buffers for card's bus-master loading ... */
3820
3821 /* Runtime instructions and 2 copies of data:
3822 * 1) unmodified from disk
3823 * 2) backup cache for save/restore during power-downs */
3824 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08003825 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07003826
3827 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08003828 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07003829
3830 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08003831 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07003832
3833 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
Tomas Winkler90e759d2007-11-29 11:09:41 +08003834 !priv->ucode_data_backup.v_addr)
Zhu Yib481de92007-09-25 17:54:57 -07003835 goto err_pci_alloc;
3836
Tomas Winkler90e759d2007-11-29 11:09:41 +08003837 /* Initialization instructions and data */
3838 if (init_size && init_data_size) {
3839 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08003840 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Tomas Winkler90e759d2007-11-29 11:09:41 +08003841
3842 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08003843 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08003844
3845 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
3846 goto err_pci_alloc;
3847 }
3848
3849 /* Bootstrap (instructions only, no data) */
3850 if (boot_size) {
3851 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08003852 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Tomas Winkler90e759d2007-11-29 11:09:41 +08003853
3854 if (!priv->ucode_boot.v_addr)
3855 goto err_pci_alloc;
3856 }
3857
Zhu Yib481de92007-09-25 17:54:57 -07003858 /* Copy images into buffers for card's bus-master reads ... */
3859
3860 /* Runtime instructions (first block of data in file) */
3861 src = &ucode->data[0];
3862 len = priv->ucode_code.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08003863 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07003864 memcpy(priv->ucode_code.v_addr, src, len);
3865 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
3866 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
3867
3868 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003869 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
Zhu Yib481de92007-09-25 17:54:57 -07003870 src = &ucode->data[inst_size];
3871 len = priv->ucode_data.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08003872 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07003873 memcpy(priv->ucode_data.v_addr, src, len);
3874 memcpy(priv->ucode_data_backup.v_addr, src, len);
3875
3876 /* Initialization instructions (3rd block) */
3877 if (init_size) {
3878 src = &ucode->data[inst_size + data_size];
3879 len = priv->ucode_init.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08003880 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
3881 len);
Zhu Yib481de92007-09-25 17:54:57 -07003882 memcpy(priv->ucode_init.v_addr, src, len);
3883 }
3884
3885 /* Initialization data (4th block) */
3886 if (init_data_size) {
3887 src = &ucode->data[inst_size + data_size + init_size];
3888 len = priv->ucode_init_data.len;
3889 IWL_DEBUG_INFO("Copying (but not loading) init data len %d\n",
3890 (int)len);
3891 memcpy(priv->ucode_init_data.v_addr, src, len);
3892 }
3893
3894 /* Bootstrap instructions (5th block) */
3895 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
3896 len = priv->ucode_boot.len;
3897 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %d\n",
3898 (int)len);
3899 memcpy(priv->ucode_boot.v_addr, src, len);
3900
3901 /* We have our copies now, allow OS release its copies */
3902 release_firmware(ucode_raw);
3903 return 0;
3904
3905 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08003906 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08003907 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003908 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003909
3910 err_release:
3911 release_firmware(ucode_raw);
3912
3913 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08003914 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003915}
3916
3917
3918/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003919 * iwl3945_set_ucode_ptrs - Set uCode address location
Zhu Yib481de92007-09-25 17:54:57 -07003920 *
3921 * Tell initialization uCode where to find runtime uCode.
3922 *
3923 * BSM registers initially contain pointers to initialization uCode.
3924 * We need to replace them to load runtime uCode inst and data,
3925 * and to save runtime data when powering down.
3926 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003927static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003928{
3929 dma_addr_t pinst;
3930 dma_addr_t pdata;
3931 int rc = 0;
3932 unsigned long flags;
3933
3934 /* bits 31:0 for 3945 */
3935 pinst = priv->ucode_code.p_addr;
3936 pdata = priv->ucode_data_backup.p_addr;
3937
3938 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003939 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003940 if (rc) {
3941 spin_unlock_irqrestore(&priv->lock, flags);
3942 return rc;
3943 }
3944
3945 /* Tell bootstrap uCode where to find image to load */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003946 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
3947 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
3948 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07003949 priv->ucode_data.len);
3950
Tomas Winklera96a27f2008-10-23 23:48:56 -07003951 /* Inst byte count must be last to set up, bit 31 signals uCode
Zhu Yib481de92007-09-25 17:54:57 -07003952 * that all new ptr/size info is in place */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003953 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07003954 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
3955
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003956 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003957
3958 spin_unlock_irqrestore(&priv->lock, flags);
3959
3960 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
3961
3962 return rc;
3963}
3964
3965/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003966 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07003967 *
3968 * Called after REPLY_ALIVE notification received from "initialize" uCode.
3969 *
Zhu Yib481de92007-09-25 17:54:57 -07003970 * Tell "initialize" uCode to go ahead and load the runtime uCode.
Ben Cahill9fbab512007-11-29 11:09:47 +08003971 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003972static void iwl3945_init_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003973{
3974 /* Check alive response for "valid" sign from uCode */
3975 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
3976 /* We had an error bringing up the hardware, so take it
3977 * all the way back down so we can try again */
3978 IWL_DEBUG_INFO("Initialize Alive failed.\n");
3979 goto restart;
3980 }
3981
3982 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
3983 * This is a paranoid check, because we would not have gotten the
3984 * "initialize" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003985 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003986 /* Runtime instruction load was bad;
3987 * take it all the way back down so we can try again */
3988 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
3989 goto restart;
3990 }
3991
3992 /* Send pointers to protocol/runtime uCode image ... init code will
3993 * load and launch runtime uCode, which will send us another "Alive"
3994 * notification. */
3995 IWL_DEBUG_INFO("Initialization Alive received.\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003996 if (iwl3945_set_ucode_ptrs(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003997 /* Runtime instruction load won't happen;
3998 * take it all the way back down so we can try again */
3999 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
4000 goto restart;
4001 }
4002 return;
4003
4004 restart:
4005 queue_work(priv->workqueue, &priv->restart);
4006}
4007
4008
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08004009/* temporary */
4010static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw,
4011 struct sk_buff *skb);
4012
Zhu Yib481de92007-09-25 17:54:57 -07004013/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004014 * iwl3945_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07004015 * from protocol/runtime uCode (initialization uCode's
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004016 * Alive gets handled by iwl3945_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07004017 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004018static void iwl3945_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004019{
4020 int rc = 0;
4021 int thermal_spin = 0;
4022 u32 rfkill;
4023
4024 IWL_DEBUG_INFO("Runtime Alive received.\n");
4025
4026 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
4027 /* We had an error bringing up the hardware, so take it
4028 * all the way back down so we can try again */
4029 IWL_DEBUG_INFO("Alive failed.\n");
4030 goto restart;
4031 }
4032
4033 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
4034 * This is a paranoid check, because we would not have gotten the
4035 * "runtime" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004036 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004037 /* Runtime instruction load was bad;
4038 * take it all the way back down so we can try again */
4039 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
4040 goto restart;
4041 }
4042
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004043 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004044
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004045 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004046 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004047 IWL_WARN(priv, "Can not read RFKILL status from adapter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004048 return;
4049 }
4050
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004051 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
Zhu Yib481de92007-09-25 17:54:57 -07004052 IWL_DEBUG_INFO("RFKILL status: 0x%x\n", rfkill);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004053 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004054
4055 if (rfkill & 0x1) {
4056 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Tomas Winklera96a27f2008-10-23 23:48:56 -07004057 /* if RFKILL is not on, then wait for thermal
Zhu Yib481de92007-09-25 17:54:57 -07004058 * sensor in adapter to kick in */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004059 while (iwl3945_hw_get_temperature(priv) == 0) {
Zhu Yib481de92007-09-25 17:54:57 -07004060 thermal_spin++;
4061 udelay(10);
4062 }
4063
4064 if (thermal_spin)
4065 IWL_DEBUG_INFO("Thermal calibration took %dus\n",
4066 thermal_spin * 10);
4067 } else
4068 set_bit(STATUS_RF_KILL_HW, &priv->status);
4069
Ben Cahill9fbab512007-11-29 11:09:47 +08004070 /* After the ALIVE response, we can send commands to 3945 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07004071 set_bit(STATUS_ALIVE, &priv->status);
4072
4073 /* Clear out the uCode error bit if it is set */
4074 clear_bit(STATUS_FW_ERROR, &priv->status);
4075
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004076 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004077 return;
4078
Johannes Berg36d68252008-05-15 12:55:26 +02004079 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07004080
4081 priv->active_rate = priv->rates_mask;
4082 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
4083
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004084 iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode));
Zhu Yib481de92007-09-25 17:54:57 -07004085
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004086 if (iwl3945_is_associated(priv)) {
4087 struct iwl3945_rxon_cmd *active_rxon =
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004088 (struct iwl3945_rxon_cmd *)(&priv->active39_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07004089
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004090 memcpy(&priv->staging39_rxon, &priv->active39_rxon,
4091 sizeof(priv->staging39_rxon));
Zhu Yib481de92007-09-25 17:54:57 -07004092 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
4093 } else {
4094 /* Initialize our rx_config data */
Zhu, Yi60294de2008-10-29 14:05:45 -07004095 iwl3945_connection_init_rx_config(priv, priv->iw_mode);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004096 memcpy(priv->staging39_rxon.node_addr, priv->mac_addr, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07004097 }
4098
Ben Cahill9fbab512007-11-29 11:09:47 +08004099 /* Configure Bluetooth device coexistence support */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004100 iwl3945_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004101
4102 /* Configure the adapter for unassociated operation */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004103 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004104
Zhu Yib481de92007-09-25 17:54:57 -07004105 iwl3945_reg_txpower_periodic(priv);
4106
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07004107 iwl3945_led_register(priv);
4108
Zhu Yib481de92007-09-25 17:54:57 -07004109 IWL_DEBUG_INFO("ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07004110 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a669262008-01-14 17:46:18 -08004111 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07004112
4113 if (priv->error_recovering)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004114 iwl3945_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004115
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08004116 /* reassociate for ADHOC mode */
4117 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
4118 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
4119 priv->vif);
4120 if (beacon)
4121 iwl3945_mac_beacon_update(priv->hw, beacon);
4122 }
4123
Zhu Yib481de92007-09-25 17:54:57 -07004124 return;
4125
4126 restart:
4127 queue_work(priv->workqueue, &priv->restart);
4128}
4129
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004130static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07004131
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004132static void __iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004133{
4134 unsigned long flags;
4135 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
4136 struct ieee80211_conf *conf = NULL;
4137
4138 IWL_DEBUG_INFO(DRV_NAME " is going down\n");
4139
4140 conf = ieee80211_get_hw_conf(priv->hw);
4141
4142 if (!exit_pending)
4143 set_bit(STATUS_EXIT_PENDING, &priv->status);
4144
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07004145 iwl3945_led_unregister(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004146 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004147
4148 /* Unblock any waiting calls */
4149 wake_up_interruptible_all(&priv->wait_command_queue);
4150
Zhu Yib481de92007-09-25 17:54:57 -07004151 /* Wipe out the EXIT_PENDING status bit if we are not actually
4152 * exiting the module */
4153 if (!exit_pending)
4154 clear_bit(STATUS_EXIT_PENDING, &priv->status);
4155
4156 /* stop and reset the on-board processor */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004157 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07004158
4159 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004160 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004161 iwl3945_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004162 spin_unlock_irqrestore(&priv->lock, flags);
4163 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004164
4165 if (priv->mac80211_registered)
4166 ieee80211_stop_queues(priv->hw);
4167
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004168 /* If we have not previously called iwl3945_init() then
Zhu Yib481de92007-09-25 17:54:57 -07004169 * clear all bits but the RF Kill and SUSPEND bits and return */
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004170 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004171 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
4172 STATUS_RF_KILL_HW |
4173 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
4174 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08004175 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
4176 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07004177 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08004178 STATUS_IN_SUSPEND |
4179 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
4180 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07004181 goto exit;
4182 }
4183
4184 /* ...otherwise clear out all the status bits but the RF Kill and
4185 * SUSPEND bits and continue taking the NIC down. */
4186 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
4187 STATUS_RF_KILL_HW |
4188 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
4189 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08004190 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
4191 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07004192 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
4193 STATUS_IN_SUSPEND |
4194 test_bit(STATUS_FW_ERROR, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08004195 STATUS_FW_ERROR |
4196 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
4197 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07004198
Abbas, Mohamede9414b62009-01-20 21:33:55 -08004199 priv->cfg->ops->lib->apm_ops.reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004200 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004201 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07004202 spin_unlock_irqrestore(&priv->lock, flags);
4203
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004204 iwl3945_hw_txq_ctx_stop(priv);
4205 iwl3945_hw_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004206
4207 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004208 if (!iwl_grab_nic_access(priv)) {
4209 iwl_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07004210 APMG_CLK_VAL_DMA_CLK_RQT);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004211 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004212 }
4213 spin_unlock_irqrestore(&priv->lock, flags);
4214
4215 udelay(5);
4216
Abbas, Mohamede9414b62009-01-20 21:33:55 -08004217 if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status))
4218 priv->cfg->ops->lib->apm_ops.stop(priv);
4219 else
4220 priv->cfg->ops->lib->apm_ops.reset(priv);
4221
Zhu Yib481de92007-09-25 17:54:57 -07004222 exit:
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08004223 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07004224
4225 if (priv->ibss_beacon)
4226 dev_kfree_skb(priv->ibss_beacon);
4227 priv->ibss_beacon = NULL;
4228
4229 /* clear out any free frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004230 iwl3945_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004231}
4232
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004233static void iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004234{
4235 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004236 __iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004237 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08004238
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004239 iwl3945_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004240}
4241
4242#define MAX_HW_RESTARTS 5
4243
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004244static int __iwl3945_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004245{
4246 int rc, i;
4247
4248 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004249 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07004250 return -EIO;
4251 }
4252
4253 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004254 IWL_WARN(priv, "Radio disabled by SW RF kill (module "
Zhu Yib481de92007-09-25 17:54:57 -07004255 "parameter)\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08004256 return -ENODEV;
4257 }
4258
Reinette Chatree903fbd2008-01-30 22:05:15 -08004259 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004260 IWL_ERR(priv, "ucode not available for device bring up\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08004261 return -EIO;
4262 }
4263
Zhu Yie655b9f2008-01-24 02:19:38 -08004264 /* If platform's RF_KILL switch is NOT set to KILL */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004265 if (iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yie655b9f2008-01-24 02:19:38 -08004266 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
4267 clear_bit(STATUS_RF_KILL_HW, &priv->status);
4268 else {
4269 set_bit(STATUS_RF_KILL_HW, &priv->status);
4270 if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004271 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08004272 return -ENODEV;
4273 }
Zhu Yib481de92007-09-25 17:54:57 -07004274 }
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02004275
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004276 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07004277
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004278 rc = iwl3945_hw_nic_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004279 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004280 IWL_ERR(priv, "Unable to int nic\n");
Zhu Yib481de92007-09-25 17:54:57 -07004281 return rc;
4282 }
4283
4284 /* make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004285 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
4286 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07004287 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
4288
4289 /* clear (again), then enable host interrupts */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004290 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004291 iwl3945_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004292
4293 /* really make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004294 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
4295 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07004296
4297 /* Copy original ucode data image from disk into backup cache.
4298 * This will be used to initialize the on-board processor's
4299 * data SRAM for a clean start when the runtime program first loads. */
4300 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a669262008-01-14 17:46:18 -08004301 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07004302
Zhu Yie655b9f2008-01-24 02:19:38 -08004303 /* We return success when we resume from suspend and rf_kill is on. */
4304 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
4305 return 0;
4306
Zhu Yib481de92007-09-25 17:54:57 -07004307 for (i = 0; i < MAX_HW_RESTARTS; i++) {
4308
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004309 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004310
4311 /* load bootstrap state machine,
4312 * load bootstrap program into processor's memory,
4313 * prepare to load the "initialize" uCode */
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08004314 priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004315
4316 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004317 IWL_ERR(priv,
4318 "Unable to set up bootstrap uCode: %d\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -07004319 continue;
4320 }
4321
4322 /* start card; "initialize" will load runtime ucode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004323 iwl3945_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004324
Zhu Yib481de92007-09-25 17:54:57 -07004325 IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
4326
4327 return 0;
4328 }
4329
4330 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004331 __iwl3945_down(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08004332 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07004333
4334 /* tried to restart and config the device for as long as our
4335 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08004336 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07004337 return -EIO;
4338}
4339
4340
4341/*****************************************************************************
4342 *
4343 * Workqueue callbacks
4344 *
4345 *****************************************************************************/
4346
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004347static void iwl3945_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07004348{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004349 struct iwl_priv *priv =
4350 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07004351
4352 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
4353 return;
4354
4355 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004356 iwl3945_init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004357 mutex_unlock(&priv->mutex);
4358}
4359
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004360static void iwl3945_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07004361{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004362 struct iwl_priv *priv =
4363 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07004364
4365 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
4366 return;
4367
4368 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004369 iwl3945_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004370 mutex_unlock(&priv->mutex);
4371}
4372
Helmut Schaa26635162009-01-15 09:38:44 +01004373static void iwl3945_rfkill_poll(struct work_struct *data)
4374{
4375 struct iwl_priv *priv =
4376 container_of(data, struct iwl_priv, rfkill_poll.work);
4377 unsigned long status = priv->status;
4378
4379 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
4380 clear_bit(STATUS_RF_KILL_HW, &priv->status);
4381 else
4382 set_bit(STATUS_RF_KILL_HW, &priv->status);
4383
4384 if (test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status))
4385 queue_work(priv->workqueue, &priv->rf_kill);
4386
4387 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
4388 round_jiffies_relative(2 * HZ));
4389
4390}
4391
Zhu Yib481de92007-09-25 17:54:57 -07004392#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004393static void iwl3945_bg_request_scan(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07004394{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004395 struct iwl_priv *priv =
4396 container_of(data, struct iwl_priv, request_scan);
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08004397 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07004398 .id = REPLY_SCAN_CMD,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004399 .len = sizeof(struct iwl3945_scan_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07004400 .meta.flags = CMD_SIZE_HUGE,
4401 };
4402 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004403 struct iwl3945_scan_cmd *scan;
Zhu Yib481de92007-09-25 17:54:57 -07004404 struct ieee80211_conf *conf = NULL;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08004405 u8 n_probes = 2;
Johannes Berg8318d782008-01-24 19:38:38 +01004406 enum ieee80211_band band;
John W. Linville9387b7c2008-09-30 20:59:05 -04004407 DECLARE_SSID_BUF(ssid);
Zhu Yib481de92007-09-25 17:54:57 -07004408
4409 conf = ieee80211_get_hw_conf(priv->hw);
4410
4411 mutex_lock(&priv->mutex);
4412
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004413 if (!iwl_is_ready(priv)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004414 IWL_WARN(priv, "request scan called when driver not ready.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004415 goto done;
4416 }
4417
Tomas Winklera96a27f2008-10-23 23:48:56 -07004418 /* Make sure the scan wasn't canceled before this queued work
Zhu Yib481de92007-09-25 17:54:57 -07004419 * was given the chance to run... */
4420 if (!test_bit(STATUS_SCANNING, &priv->status))
4421 goto done;
4422
4423 /* This should never be called or scheduled if there is currently
4424 * a scan active in the hardware. */
4425 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
4426 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
4427 "Ignoring second request.\n");
4428 rc = -EIO;
4429 goto done;
4430 }
4431
4432 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
4433 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
4434 goto done;
4435 }
4436
4437 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
4438 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
4439 goto done;
4440 }
4441
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004442 if (iwl_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004443 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
4444 goto done;
4445 }
4446
4447 if (!test_bit(STATUS_READY, &priv->status)) {
4448 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
4449 goto done;
4450 }
4451
4452 if (!priv->scan_bands) {
4453 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
4454 goto done;
4455 }
4456
Winkler, Tomas805cee52009-01-19 15:30:28 -08004457 if (!priv->scan) {
4458 priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
Zhu Yib481de92007-09-25 17:54:57 -07004459 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
Winkler, Tomas805cee52009-01-19 15:30:28 -08004460 if (!priv->scan) {
Zhu Yib481de92007-09-25 17:54:57 -07004461 rc = -ENOMEM;
4462 goto done;
4463 }
4464 }
Winkler, Tomas805cee52009-01-19 15:30:28 -08004465 scan = priv->scan;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004466 memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07004467
4468 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
4469 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
4470
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004471 if (iwl3945_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004472 u16 interval = 0;
4473 u32 extra;
4474 u32 suspend_time = 100;
4475 u32 scan_suspend_time = 100;
4476 unsigned long flags;
4477
4478 IWL_DEBUG_INFO("Scanning while associated...\n");
4479
4480 spin_lock_irqsave(&priv->lock, flags);
4481 interval = priv->beacon_int;
4482 spin_unlock_irqrestore(&priv->lock, flags);
4483
4484 scan->suspend_time = 0;
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004485 scan->max_out_time = cpu_to_le32(200 * 1024);
Zhu Yib481de92007-09-25 17:54:57 -07004486 if (!interval)
4487 interval = suspend_time;
4488 /*
4489 * suspend time format:
4490 * 0-19: beacon interval in usec (time before exec.)
4491 * 20-23: 0
4492 * 24-31: number of beacons (suspend between channels)
4493 */
4494
4495 extra = (suspend_time / interval) << 24;
4496 scan_suspend_time = 0xFF0FFFFF &
4497 (extra | ((suspend_time % interval) * 1024));
4498
4499 scan->suspend_time = cpu_to_le32(scan_suspend_time);
4500 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
4501 scan_suspend_time, interval);
4502 }
4503
4504 /* We should add the ability for user to lock to PASSIVE ONLY */
4505 if (priv->one_direct_scan) {
4506 IWL_DEBUG_SCAN
4507 ("Kicking off one direct scan for '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04004508 print_ssid(ssid, priv->direct_ssid,
4509 priv->direct_ssid_len));
Zhu Yib481de92007-09-25 17:54:57 -07004510 scan->direct_scan[0].id = WLAN_EID_SSID;
4511 scan->direct_scan[0].len = priv->direct_ssid_len;
4512 memcpy(scan->direct_scan[0].ssid,
4513 priv->direct_ssid, priv->direct_ssid_len);
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08004514 n_probes++;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08004515 } else
Bill Moss786b4552008-04-17 16:03:40 -07004516 IWL_DEBUG_SCAN("Kicking off one indirect scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004517
4518 /* We don't build a direct scan probe request; the uCode will do
4519 * that based on the direct_mask added to each channel entry */
Zhu Yib481de92007-09-25 17:54:57 -07004520 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08004521 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07004522 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
4523
4524 /* flags + rate selection */
4525
Ron Rindjunsky66b50042008-06-25 16:46:31 +08004526 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07004527 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
4528 scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
4529 scan->good_CRC_th = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01004530 band = IEEE80211_BAND_2GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08004531 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07004532 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
4533 scan->good_CRC_th = IWL_GOOD_CRC_TH;
Johannes Berg8318d782008-01-24 19:38:38 +01004534 band = IEEE80211_BAND_5GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08004535 } else {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004536 IWL_WARN(priv, "Invalid scan band count\n");
Zhu Yib481de92007-09-25 17:54:57 -07004537 goto done;
4538 }
4539
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08004540 scan->tx_cmd.len = cpu_to_le16(
4541 iwl_fill_probe_req(priv, band,
4542 (struct ieee80211_mgmt *)scan->data,
4543 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
4544
Zhu Yib481de92007-09-25 17:54:57 -07004545 /* select Rx antennas */
4546 scan->flags |= iwl3945_get_antenna_flags(priv);
4547
Johannes Berg05c914f2008-09-11 00:01:58 +02004548 if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
Zhu Yib481de92007-09-25 17:54:57 -07004549 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
4550
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08004551 scan->channel_count =
4552 iwl3945_get_channels_for_scan(priv, band, 1, /* active */
4553 n_probes,
4554 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
Zhu Yib481de92007-09-25 17:54:57 -07004555
Reinette Chatre14b54332008-11-04 12:21:35 -08004556 if (scan->channel_count == 0) {
4557 IWL_DEBUG_SCAN("channel count %d\n", scan->channel_count);
4558 goto done;
4559 }
4560
Zhu Yib481de92007-09-25 17:54:57 -07004561 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004562 scan->channel_count * sizeof(struct iwl3945_scan_channel);
Zhu Yib481de92007-09-25 17:54:57 -07004563 cmd.data = scan;
4564 scan->len = cpu_to_le16(cmd.len);
4565
4566 set_bit(STATUS_SCAN_HW, &priv->status);
Samuel Ortiz518099a2009-01-19 15:30:27 -08004567 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07004568 if (rc)
4569 goto done;
4570
4571 queue_delayed_work(priv->workqueue, &priv->scan_check,
4572 IWL_SCAN_CHECK_WATCHDOG);
4573
4574 mutex_unlock(&priv->mutex);
4575 return;
4576
4577 done:
Mohamed Abbas2420ebc2008-11-04 12:21:34 -08004578 /* can not perform scan make sure we clear scanning
4579 * bits from status so next scan request can be performed.
4580 * if we dont clear scanning status bit here all next scan
4581 * will fail
4582 */
4583 clear_bit(STATUS_SCAN_HW, &priv->status);
4584 clear_bit(STATUS_SCANNING, &priv->status);
4585
Ian Schram01ebd062007-10-25 17:15:22 +08004586 /* inform mac80211 scan aborted */
Zhu Yib481de92007-09-25 17:54:57 -07004587 queue_work(priv->workqueue, &priv->scan_completed);
4588 mutex_unlock(&priv->mutex);
4589}
4590
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004591static void iwl3945_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07004592{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004593 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07004594
4595 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
4596 return;
4597
4598 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004599 __iwl3945_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004600 mutex_unlock(&priv->mutex);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01004601 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004602}
4603
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004604static void iwl3945_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07004605{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004606 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07004607
4608 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
4609 return;
4610
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004611 iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004612 queue_work(priv->workqueue, &priv->up);
4613}
4614
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004615static void iwl3945_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07004616{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004617 struct iwl_priv *priv =
4618 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07004619
4620 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
4621 return;
4622
4623 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004624 iwl3945_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004625 mutex_unlock(&priv->mutex);
4626}
4627
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08004628#define IWL_DELAY_NEXT_SCAN (HZ*2)
4629
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004630static void iwl3945_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004631{
Zhu Yib481de92007-09-25 17:54:57 -07004632 int rc = 0;
4633 struct ieee80211_conf *conf = NULL;
4634
Johannes Berg05c914f2008-09-11 00:01:58 +02004635 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004636 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07004637 return;
4638 }
4639
4640
Johannes Berge1749612008-10-27 15:59:26 -07004641 IWL_DEBUG_ASSOC("Associated as %d to: %pM\n",
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004642 priv->assoc_id, priv->active39_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07004643
4644 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
4645 return;
4646
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08004647 if (!priv->vif || !priv->is_open)
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004648 return;
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08004649
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004650 iwl_scan_cancel_timeout(priv, 200);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004651
Zhu Yib481de92007-09-25 17:54:57 -07004652 conf = ieee80211_get_hw_conf(priv->hw);
4653
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004654 priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004655 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004656
Tomas Winkler28afaf92008-12-19 10:37:06 +08004657 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004658 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08004659 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07004660 sizeof(priv->rxon_timing), &priv->rxon_timing);
4661 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004662 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07004663 "Attempting to continue.\n");
4664
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004665 priv->staging39_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07004666
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004667 priv->staging39_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07004668
4669 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
4670 priv->assoc_id, priv->beacon_int);
4671
4672 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004673 priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07004674 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004675 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07004676
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004677 if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07004678 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004679 priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07004680 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004681 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07004682
Johannes Berg05c914f2008-09-11 00:01:58 +02004683 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004684 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07004685
4686 }
4687
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004688 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004689
4690 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02004691 case NL80211_IFTYPE_STATION:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004692 iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07004693 break;
4694
Johannes Berg05c914f2008-09-11 00:01:58 +02004695 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07004696
Abhijeet Kolekarce546fd2008-11-19 15:32:22 -08004697 priv->assoc_id = 1;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004698 iwl3945_add_station(priv, priv->bssid, 0, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004699 iwl3945_sync_sta(priv, IWL_STA_ID,
Johannes Berg8318d782008-01-24 19:38:38 +01004700 (priv->band == IEEE80211_BAND_5GHZ) ?
Zhu Yib481de92007-09-25 17:54:57 -07004701 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
4702 CMD_ASYNC);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004703 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
4704 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004705
4706 break;
4707
4708 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08004709 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03004710 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07004711 break;
4712 }
4713
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004714 iwl3945_activate_qos(priv, 0);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08004715
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08004716 /* we have just associated, don't start scan too early */
4717 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004718}
4719
Johannes Berge8975582008-10-09 12:18:51 +02004720static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed);
Zhu Yi76bb77e2007-11-22 10:53:22 +08004721
Zhu Yib481de92007-09-25 17:54:57 -07004722/*****************************************************************************
4723 *
4724 * mac80211 entry point functions
4725 *
4726 *****************************************************************************/
4727
Zhu Yi5a669262008-01-14 17:46:18 -08004728#define UCODE_READY_TIMEOUT (2 * HZ)
4729
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004730static int iwl3945_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07004731{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004732 struct iwl_priv *priv = hw->priv;
Zhu Yi5a669262008-01-14 17:46:18 -08004733 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07004734
4735 IWL_DEBUG_MAC80211("enter\n");
4736
4737 /* we should be verifying the device is ready to be opened */
4738 mutex_lock(&priv->mutex);
4739
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004740 memset(&priv->staging39_rxon, 0, sizeof(struct iwl3945_rxon_cmd));
Zhu Yi5a669262008-01-14 17:46:18 -08004741 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
4742 * ucode filename and max sizes are card-specific. */
4743
4744 if (!priv->ucode_code.len) {
4745 ret = iwl3945_read_ucode(priv);
4746 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004747 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a669262008-01-14 17:46:18 -08004748 mutex_unlock(&priv->mutex);
4749 goto out_release_irq;
4750 }
4751 }
4752
Zhu Yie655b9f2008-01-24 02:19:38 -08004753 ret = __iwl3945_up(priv);
Zhu Yi5a669262008-01-14 17:46:18 -08004754
Zhu Yib481de92007-09-25 17:54:57 -07004755 mutex_unlock(&priv->mutex);
Zhu Yi5a669262008-01-14 17:46:18 -08004756
Samuel Ortizc0af96a2009-01-21 18:27:54 +01004757 iwl_rfkill_set_hw_state(priv);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02004758
Zhu Yie655b9f2008-01-24 02:19:38 -08004759 if (ret)
4760 goto out_release_irq;
4761
4762 IWL_DEBUG_INFO("Start UP work.\n");
4763
4764 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
4765 return 0;
4766
Zhu Yi5a669262008-01-14 17:46:18 -08004767 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
4768 * mac80211 will not be run successfully. */
4769 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
4770 test_bit(STATUS_READY, &priv->status),
4771 UCODE_READY_TIMEOUT);
4772 if (!ret) {
4773 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004774 IWL_ERR(priv,
4775 "Wait for START_ALIVE timeout after %dms.\n",
4776 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Zhu Yi5a669262008-01-14 17:46:18 -08004777 ret = -ETIMEDOUT;
4778 goto out_release_irq;
4779 }
4780 }
4781
Helmut Schaa26635162009-01-15 09:38:44 +01004782 /* ucode is running and will send rfkill notifications,
4783 * no need to poll the killswitch state anymore */
4784 cancel_delayed_work(&priv->rfkill_poll);
4785
Zhu Yie655b9f2008-01-24 02:19:38 -08004786 priv->is_open = 1;
Zhu Yib481de92007-09-25 17:54:57 -07004787 IWL_DEBUG_MAC80211("leave\n");
4788 return 0;
Zhu Yi5a669262008-01-14 17:46:18 -08004789
4790out_release_irq:
Zhu Yie655b9f2008-01-24 02:19:38 -08004791 priv->is_open = 0;
4792 IWL_DEBUG_MAC80211("leave - failed\n");
Zhu Yi5a669262008-01-14 17:46:18 -08004793 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004794}
4795
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004796static void iwl3945_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07004797{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004798 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004799
4800 IWL_DEBUG_MAC80211("enter\n");
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004801
Zhu Yie655b9f2008-01-24 02:19:38 -08004802 if (!priv->is_open) {
4803 IWL_DEBUG_MAC80211("leave - skip\n");
4804 return;
4805 }
4806
Zhu Yib481de92007-09-25 17:54:57 -07004807 priv->is_open = 0;
Zhu Yi5a669262008-01-14 17:46:18 -08004808
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004809 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08004810 /* stop mac, cancel any scan request and clear
4811 * RXON_FILTER_ASSOC_MSK BIT
4812 */
Zhu Yi5a669262008-01-14 17:46:18 -08004813 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004814 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08004815 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08004816 }
4817
Zhu Yi5a669262008-01-14 17:46:18 -08004818 iwl3945_down(priv);
4819
4820 flush_workqueue(priv->workqueue);
Helmut Schaa26635162009-01-15 09:38:44 +01004821
4822 /* start polling the killswitch state again */
4823 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
4824 round_jiffies_relative(2 * HZ));
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004825
Zhu Yib481de92007-09-25 17:54:57 -07004826 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004827}
4828
Johannes Berge039fa42008-05-15 12:55:29 +02004829static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07004830{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004831 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004832
4833 IWL_DEBUG_MAC80211("enter\n");
4834
Zhu Yib481de92007-09-25 17:54:57 -07004835 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02004836 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07004837
Johannes Berge039fa42008-05-15 12:55:29 +02004838 if (iwl3945_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07004839 dev_kfree_skb_any(skb);
4840
4841 IWL_DEBUG_MAC80211("leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08004842 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07004843}
4844
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004845static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004846 struct ieee80211_if_init_conf *conf)
4847{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004848 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004849 unsigned long flags;
4850
Johannes Berg32bfd352007-12-19 01:31:26 +01004851 IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07004852
Johannes Berg32bfd352007-12-19 01:31:26 +01004853 if (priv->vif) {
4854 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
Tomas Winkler864792e2007-11-27 21:00:52 +02004855 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07004856 }
4857
4858 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01004859 priv->vif = conf->vif;
Zhu, Yi60294de2008-10-29 14:05:45 -07004860 priv->iw_mode = conf->type;
Zhu Yib481de92007-09-25 17:54:57 -07004861
4862 spin_unlock_irqrestore(&priv->lock, flags);
4863
4864 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02004865
4866 if (conf->mac_addr) {
Johannes Berge1749612008-10-27 15:59:26 -07004867 IWL_DEBUG_MAC80211("Set: %pM\n", conf->mac_addr);
Tomas Winkler864792e2007-11-27 21:00:52 +02004868 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
4869 }
4870
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004871 if (iwl_is_ready(priv))
Zhu Yi5a669262008-01-14 17:46:18 -08004872 iwl3945_set_mode(priv, conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07004873
Zhu Yib481de92007-09-25 17:54:57 -07004874 mutex_unlock(&priv->mutex);
4875
Zhu Yi5a669262008-01-14 17:46:18 -08004876 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004877 return 0;
4878}
4879
4880/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004881 * iwl3945_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07004882 *
4883 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
4884 * be set inappropriately and the driver currently sets the hardware up to
4885 * use it whenever needed.
4886 */
Johannes Berge8975582008-10-09 12:18:51 +02004887static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed)
Zhu Yib481de92007-09-25 17:54:57 -07004888{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004889 struct iwl_priv *priv = hw->priv;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08004890 const struct iwl_channel_info *ch_info;
Johannes Berge8975582008-10-09 12:18:51 +02004891 struct ieee80211_conf *conf = &hw->conf;
Zhu Yib481de92007-09-25 17:54:57 -07004892 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08004893 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07004894
4895 mutex_lock(&priv->mutex);
Johannes Berg8318d782008-01-24 19:38:38 +01004896 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07004897
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004898 if (!iwl_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004899 IWL_DEBUG_MAC80211("leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08004900 ret = -EIO;
4901 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004902 }
4903
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004904 if (unlikely(!iwl3945_mod_params.disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07004905 test_bit(STATUS_SCANNING, &priv->status))) {
Zhu Yia0646472007-12-20 14:10:01 +08004906 IWL_DEBUG_MAC80211("leave - scanning\n");
4907 set_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07004908 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08004909 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07004910 }
4911
4912 spin_lock_irqsave(&priv->lock, flags);
4913
Samuel Ortize6148912009-01-23 13:45:15 -08004914 ch_info = iwl_get_channel_info(priv, conf->channel->band,
4915 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07004916 if (!is_channel_valid(ch_info)) {
Ron Rindjunsky66b50042008-06-25 16:46:31 +08004917 IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this band.\n",
Johannes Berg8318d782008-01-24 19:38:38 +01004918 conf->channel->hw_value, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07004919 IWL_DEBUG_MAC80211("leave - invalid channel\n");
4920 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yi76bb77e2007-11-22 10:53:22 +08004921 ret = -EINVAL;
4922 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004923 }
4924
Johannes Berg8318d782008-01-24 19:38:38 +01004925 iwl3945_set_rxon_channel(priv, conf->channel->band, conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07004926
Johannes Berg8318d782008-01-24 19:38:38 +01004927 iwl3945_set_flags_for_phymode(priv, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07004928
4929 /* The list of supported rates and rate mask can be different
4930 * for each phymode; since the phymode may have changed, reset
4931 * the rate mask to what mac80211 lists */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004932 iwl3945_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004933
4934 spin_unlock_irqrestore(&priv->lock, flags);
4935
4936#ifdef IEEE80211_CONF_CHANNEL_SWITCH
4937 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004938 iwl3945_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08004939 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004940 }
4941#endif
4942
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004943 iwl3945_radio_kill_sw(priv, !conf->radio_enabled);
Zhu Yib481de92007-09-25 17:54:57 -07004944
4945 if (!conf->radio_enabled) {
4946 IWL_DEBUG_MAC80211("leave - radio disabled\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08004947 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004948 }
4949
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004950 if (iwl_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004951 IWL_DEBUG_MAC80211("leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08004952 ret = -EIO;
4953 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004954 }
4955
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004956 iwl3945_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004957
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004958 if (memcmp(&priv->active39_rxon,
4959 &priv->staging39_rxon, sizeof(priv->staging39_rxon)))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004960 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004961 else
4962 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
4963
4964 IWL_DEBUG_MAC80211("leave\n");
4965
Zhu Yi76bb77e2007-11-22 10:53:22 +08004966out:
Zhu Yia0646472007-12-20 14:10:01 +08004967 clear_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07004968 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08004969 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004970}
4971
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004972static void iwl3945_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004973{
4974 int rc = 0;
4975
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08004976 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07004977 return;
4978
4979 /* The following should be done only at AP bring up */
Ron Rindjunsky5d1e2322008-06-30 17:23:04 +08004980 if (!(iwl3945_is_associated(priv))) {
Zhu Yib481de92007-09-25 17:54:57 -07004981
4982 /* RXON - unassoc (to set timing command) */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004983 priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004984 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004985
4986 /* RXON Timing */
Tomas Winkler28afaf92008-12-19 10:37:06 +08004987 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004988 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08004989 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
4990 sizeof(priv->rxon_timing),
4991 &priv->rxon_timing);
Zhu Yib481de92007-09-25 17:54:57 -07004992 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004993 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07004994 "Attempting to continue.\n");
4995
4996 /* FIXME: what should be the assoc_id for AP? */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004997 priv->staging39_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07004998 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004999 priv->staging39_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07005000 RXON_FLG_SHORT_PREAMBLE_MSK;
5001 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005002 priv->staging39_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07005003 ~RXON_FLG_SHORT_PREAMBLE_MSK;
5004
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005005 if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07005006 if (priv->assoc_capability &
5007 WLAN_CAPABILITY_SHORT_SLOT_TIME)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005008 priv->staging39_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07005009 RXON_FLG_SHORT_SLOT_MSK;
5010 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005011 priv->staging39_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07005012 ~RXON_FLG_SHORT_SLOT_MSK;
5013
Johannes Berg05c914f2008-09-11 00:01:58 +02005014 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005015 priv->staging39_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07005016 ~RXON_FLG_SHORT_SLOT_MSK;
5017 }
5018 /* restore RXON assoc */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005019 priv->staging39_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005020 iwl3945_commit_rxon(priv);
Kolekar, Abhijeetb5323d32008-12-19 10:37:22 +08005021 iwl3945_add_station(priv, iwl_bcast_addr, 0, 0);
Zhu Yi556f8db2007-09-27 11:27:33 +08005022 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005023 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005024
5025 /* FIXME - we need to add code here to detect a totally new
5026 * configuration, reset the AP, unassoc, rxon timing, assoc,
5027 * clear sta table, add BCAST sta... */
5028}
5029
Johannes Berg32bfd352007-12-19 01:31:26 +01005030static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
5031 struct ieee80211_vif *vif,
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005032 struct ieee80211_if_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -07005033{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005034 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07005035 int rc;
5036
5037 if (conf == NULL)
5038 return -EIO;
5039
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08005040 if (priv->vif != vif) {
5041 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08005042 return 0;
5043 }
5044
Johannes Berg9d139c82008-07-09 14:40:37 +02005045 /* handle this temporarily here */
Johannes Berg05c914f2008-09-11 00:01:58 +02005046 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Johannes Berg9d139c82008-07-09 14:40:37 +02005047 conf->changed & IEEE80211_IFCC_BEACON) {
5048 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
5049 if (!beacon)
5050 return -ENOMEM;
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08005051 mutex_lock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02005052 rc = iwl3945_mac_beacon_update(hw, beacon);
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08005053 mutex_unlock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02005054 if (rc)
5055 return rc;
5056 }
5057
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005058 if (!iwl_is_alive(priv))
Zhu Yi5a669262008-01-14 17:46:18 -08005059 return -EAGAIN;
5060
Zhu Yib481de92007-09-25 17:54:57 -07005061 mutex_lock(&priv->mutex);
5062
Zhu Yib481de92007-09-25 17:54:57 -07005063 if (conf->bssid)
Johannes Berge1749612008-10-27 15:59:26 -07005064 IWL_DEBUG_MAC80211("bssid: %pM\n", conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07005065
Johannes Berg4150c572007-09-17 01:29:23 -04005066/*
5067 * very dubious code was here; the probe filtering flag is never set:
5068 *
Zhu Yib481de92007-09-25 17:54:57 -07005069 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
5070 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04005071 */
Zhu Yib481de92007-09-25 17:54:57 -07005072
Johannes Berg05c914f2008-09-11 00:01:58 +02005073 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07005074 if (!conf->bssid) {
5075 conf->bssid = priv->mac_addr;
5076 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Johannes Berge1749612008-10-27 15:59:26 -07005077 IWL_DEBUG_MAC80211("bssid was set to: %pM\n",
5078 conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07005079 }
5080 if (priv->ibss_beacon)
5081 dev_kfree_skb(priv->ibss_beacon);
5082
Johannes Berg9d139c82008-07-09 14:40:37 +02005083 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
Zhu Yib481de92007-09-25 17:54:57 -07005084 }
5085
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005086 if (iwl_is_rfkill(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08005087 goto done;
5088
Zhu Yib481de92007-09-25 17:54:57 -07005089 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
5090 !is_multicast_ether_addr(conf->bssid)) {
5091 /* If there is currently a HW scan going on in the background
5092 * then we need to cancel it else the RXON below will fail. */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08005093 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08005094 IWL_WARN(priv, "Aborted scan still in progress "
Zhu Yib481de92007-09-25 17:54:57 -07005095 "after 100ms\n");
5096 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
5097 mutex_unlock(&priv->mutex);
5098 return -EAGAIN;
5099 }
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005100 memcpy(priv->staging39_rxon.bssid_addr, conf->bssid, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07005101
5102 /* TODO: Audit driver for usage of these members and see
5103 * if mac80211 deprecates them (priv->bssid looks like it
5104 * shouldn't be there, but I haven't scanned the IBSS code
5105 * to verify) - jpk */
5106 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
5107
Johannes Berg05c914f2008-09-11 00:01:58 +02005108 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005109 iwl3945_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005110 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005111 rc = iwl3945_commit_rxon(priv);
Johannes Berg05c914f2008-09-11 00:01:58 +02005112 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005113 iwl3945_add_station(priv,
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005114 priv->active39_rxon.bssid_addr, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07005115 }
5116
5117 } else {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08005118 iwl_scan_cancel_timeout(priv, 100);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005119 priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005120 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005121 }
5122
Mohamed Abbasfde35712007-11-29 11:10:15 +08005123 done:
Zhu Yib481de92007-09-25 17:54:57 -07005124 IWL_DEBUG_MAC80211("leave\n");
5125 mutex_unlock(&priv->mutex);
5126
5127 return 0;
5128}
5129
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005130static void iwl3945_configure_filter(struct ieee80211_hw *hw,
Johannes Berg4150c572007-09-17 01:29:23 -04005131 unsigned int changed_flags,
5132 unsigned int *total_flags,
5133 int mc_count, struct dev_addr_list *mc_list)
5134{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005135 struct iwl_priv *priv = hw->priv;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005136 __le32 *filter_flags = &priv->staging39_rxon.filter_flags;
Rick Farrington25b3f572008-06-30 17:23:28 +08005137
Zhu, Yi352bc8d2008-11-12 13:14:09 -08005138 IWL_DEBUG_MAC80211("Enter: changed: 0x%x, total: 0x%x\n",
5139 changed_flags, *total_flags);
5140
5141 if (changed_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) {
5142 if (*total_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS))
5143 *filter_flags |= RXON_FILTER_PROMISC_MSK;
5144 else
5145 *filter_flags &= ~RXON_FILTER_PROMISC_MSK;
Abhijeet Kolekar5ec03972008-05-05 10:22:48 +08005146 }
Zhu, Yi352bc8d2008-11-12 13:14:09 -08005147 if (changed_flags & FIF_ALLMULTI) {
5148 if (*total_flags & FIF_ALLMULTI)
5149 *filter_flags |= RXON_FILTER_ACCEPT_GRP_MSK;
5150 else
5151 *filter_flags &= ~RXON_FILTER_ACCEPT_GRP_MSK;
5152 }
5153 if (changed_flags & FIF_CONTROL) {
5154 if (*total_flags & FIF_CONTROL)
5155 *filter_flags |= RXON_FILTER_CTL2HOST_MSK;
5156 else
5157 *filter_flags &= ~RXON_FILTER_CTL2HOST_MSK;
5158 }
5159 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
5160 if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
5161 *filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
5162 else
5163 *filter_flags &= ~RXON_FILTER_BCON_AWARE_MSK;
5164 }
5165
5166 /* We avoid iwl_commit_rxon here to commit the new filter flags
5167 * since mac80211 will call ieee80211_hw_config immediately.
5168 * (mc_list is not supported at this time). Otherwise, we need to
5169 * queue a background iwl_commit_rxon work.
5170 */
5171
5172 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
Rick Farrington25b3f572008-06-30 17:23:28 +08005173 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
Johannes Berg4150c572007-09-17 01:29:23 -04005174}
5175
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005176static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07005177 struct ieee80211_if_init_conf *conf)
5178{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005179 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07005180
5181 IWL_DEBUG_MAC80211("enter\n");
5182
5183 mutex_lock(&priv->mutex);
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08005184
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005185 if (iwl_is_ready_rf(priv)) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08005186 iwl_scan_cancel_timeout(priv, 100);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005187 priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Mohamed Abbasfde35712007-11-29 11:10:15 +08005188 iwl3945_commit_rxon(priv);
5189 }
Johannes Berg32bfd352007-12-19 01:31:26 +01005190 if (priv->vif == conf->vif) {
5191 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07005192 memset(priv->bssid, 0, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07005193 }
5194 mutex_unlock(&priv->mutex);
5195
5196 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07005197}
5198
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005199#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
5200
5201static void iwl3945_bss_info_changed(struct ieee80211_hw *hw,
5202 struct ieee80211_vif *vif,
5203 struct ieee80211_bss_conf *bss_conf,
5204 u32 changes)
5205{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005206 struct iwl_priv *priv = hw->priv;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005207
5208 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes);
5209
5210 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
5211 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
5212 bss_conf->use_short_preamble);
5213 if (bss_conf->use_short_preamble)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005214 priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005215 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005216 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005217 }
5218
5219 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
5220 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot);
5221 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005222 priv->staging39_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005223 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005224 priv->staging39_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005225 }
5226
5227 if (changes & BSS_CHANGED_ASSOC) {
5228 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc);
5229 /* This should never happen as this function should
5230 * never be called from interrupt context. */
5231 if (WARN_ON_ONCE(in_interrupt()))
5232 return;
5233 if (bss_conf->assoc) {
5234 priv->assoc_id = bss_conf->aid;
5235 priv->beacon_int = bss_conf->beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08005236 priv->timestamp = bss_conf->timestamp;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005237 priv->assoc_capability = bss_conf->assoc_capability;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08005238 priv->power_data.dtim_period = bss_conf->dtim_period;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005239 priv->next_scan_jiffies = jiffies +
5240 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
5241 mutex_lock(&priv->mutex);
5242 iwl3945_post_associate(priv);
5243 mutex_unlock(&priv->mutex);
5244 } else {
5245 priv->assoc_id = 0;
5246 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc);
5247 }
5248 } else if (changes && iwl3945_is_associated(priv) && priv->assoc_id) {
5249 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes);
5250 iwl3945_send_rxon_assoc(priv);
5251 }
5252
5253}
5254
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005255static int iwl3945_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
Zhu Yib481de92007-09-25 17:54:57 -07005256{
5257 int rc = 0;
5258 unsigned long flags;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005259 struct iwl_priv *priv = hw->priv;
John W. Linville9387b7c2008-09-30 20:59:05 -04005260 DECLARE_SSID_BUF(ssid_buf);
Zhu Yib481de92007-09-25 17:54:57 -07005261
5262 IWL_DEBUG_MAC80211("enter\n");
5263
Mohamed Abbas15e869d2007-10-25 17:15:46 +08005264 mutex_lock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07005265 spin_lock_irqsave(&priv->lock, flags);
5266
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005267 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005268 rc = -EIO;
5269 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
5270 goto out_unlock;
5271 }
5272
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08005273 /* we don't schedule scan within next_scan_jiffies period */
5274 if (priv->next_scan_jiffies &&
5275 time_after(priv->next_scan_jiffies, jiffies)) {
5276 rc = -EAGAIN;
5277 goto out_unlock;
5278 }
Bill Moss15dbf1b2008-05-06 11:05:15 +08005279 /* if we just finished scan ask for delay for a broadcast scan */
5280 if ((len == 0) && priv->last_scan_jiffies &&
5281 time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN,
5282 jiffies)) {
Zhu Yib481de92007-09-25 17:54:57 -07005283 rc = -EAGAIN;
5284 goto out_unlock;
5285 }
5286 if (len) {
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08005287 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
John W. Linville9387b7c2008-09-30 20:59:05 -04005288 print_ssid(ssid_buf, ssid, len), (int)len);
Zhu Yib481de92007-09-25 17:54:57 -07005289
5290 priv->one_direct_scan = 1;
5291 priv->direct_ssid_len = (u8)
5292 min((u8) len, (u8) IW_ESSID_MAX_SIZE);
5293 memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08005294 } else
5295 priv->one_direct_scan = 0;
Zhu Yib481de92007-09-25 17:54:57 -07005296
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005297 rc = iwl3945_scan_initiate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005298
5299 IWL_DEBUG_MAC80211("leave\n");
5300
5301out_unlock:
5302 spin_unlock_irqrestore(&priv->lock, flags);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08005303 mutex_unlock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07005304
5305 return rc;
5306}
5307
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005308static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01005309 struct ieee80211_vif *vif,
5310 struct ieee80211_sta *sta,
5311 struct ieee80211_key_conf *key)
Zhu Yib481de92007-09-25 17:54:57 -07005312{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005313 struct iwl_priv *priv = hw->priv;
Johannes Bergdc822b52008-12-29 12:55:09 +01005314 const u8 *addr;
Winkler, Tomas42986792009-01-19 15:30:22 -08005315 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07005316 u8 sta_id;
5317
5318 IWL_DEBUG_MAC80211("enter\n");
5319
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005320 if (iwl3945_mod_params.sw_crypto) {
Zhu Yib481de92007-09-25 17:54:57 -07005321 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
5322 return -EOPNOTSUPP;
5323 }
5324
Winkler, Tomas42986792009-01-19 15:30:22 -08005325 addr = sta ? sta->addr : iwl_bcast_addr;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005326 sta_id = iwl3945_hw_find_station(priv, addr);
Zhu Yib481de92007-09-25 17:54:57 -07005327 if (sta_id == IWL_INVALID_STATION) {
Johannes Berge1749612008-10-27 15:59:26 -07005328 IWL_DEBUG_MAC80211("leave - %pM not in station map.\n",
5329 addr);
Zhu Yib481de92007-09-25 17:54:57 -07005330 return -EINVAL;
5331 }
5332
5333 mutex_lock(&priv->mutex);
5334
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08005335 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08005336
Zhu Yib481de92007-09-25 17:54:57 -07005337 switch (cmd) {
5338 case SET_KEY:
Winkler, Tomas42986792009-01-19 15:30:22 -08005339 ret = iwl3945_update_sta_key_info(priv, key, sta_id);
5340 if (!ret) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005341 iwl3945_set_rxon_hwcrypto(priv, 1);
5342 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005343 key->hw_key_idx = sta_id;
5344 IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n");
5345 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
5346 }
5347 break;
5348 case DISABLE_KEY:
Winkler, Tomas42986792009-01-19 15:30:22 -08005349 ret = iwl3945_clear_sta_key_info(priv, sta_id);
5350 if (!ret) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005351 iwl3945_set_rxon_hwcrypto(priv, 0);
5352 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005353 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
5354 }
5355 break;
5356 default:
Winkler, Tomas42986792009-01-19 15:30:22 -08005357 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07005358 }
5359
5360 IWL_DEBUG_MAC80211("leave\n");
5361 mutex_unlock(&priv->mutex);
5362
Winkler, Tomas42986792009-01-19 15:30:22 -08005363 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07005364}
5365
Johannes Berge100bb62008-04-30 18:51:21 +02005366static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
Zhu Yib481de92007-09-25 17:54:57 -07005367 const struct ieee80211_tx_queue_params *params)
5368{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005369 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07005370 unsigned long flags;
5371 int q;
Zhu Yib481de92007-09-25 17:54:57 -07005372
5373 IWL_DEBUG_MAC80211("enter\n");
5374
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005375 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005376 IWL_DEBUG_MAC80211("leave - RF not ready\n");
5377 return -EIO;
5378 }
5379
5380 if (queue >= AC_NUM) {
5381 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
5382 return 0;
5383 }
5384
Zhu Yib481de92007-09-25 17:54:57 -07005385 q = AC_NUM - 1 - queue;
5386
5387 spin_lock_irqsave(&priv->lock, flags);
5388
5389 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
5390 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
5391 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
5392 priv->qos_data.def_qos_parm.ac[q].edca_txop =
Johannes Berg3330d7be2008-02-10 16:49:38 +01005393 cpu_to_le16((params->txop * 32));
Zhu Yib481de92007-09-25 17:54:57 -07005394
5395 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
5396 priv->qos_data.qos_active = 1;
5397
5398 spin_unlock_irqrestore(&priv->lock, flags);
5399
5400 mutex_lock(&priv->mutex);
Johannes Berg05c914f2008-09-11 00:01:58 +02005401 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005402 iwl3945_activate_qos(priv, 1);
5403 else if (priv->assoc_id && iwl3945_is_associated(priv))
5404 iwl3945_activate_qos(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07005405
5406 mutex_unlock(&priv->mutex);
5407
Zhu Yib481de92007-09-25 17:54:57 -07005408 IWL_DEBUG_MAC80211("leave\n");
5409 return 0;
5410}
5411
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005412static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07005413 struct ieee80211_tx_queue_stats *stats)
5414{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005415 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07005416 int i, avail;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08005417 struct iwl_tx_queue *txq;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08005418 struct iwl_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07005419 unsigned long flags;
5420
5421 IWL_DEBUG_MAC80211("enter\n");
5422
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005423 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005424 IWL_DEBUG_MAC80211("leave - RF not ready\n");
5425 return -EIO;
5426 }
5427
5428 spin_lock_irqsave(&priv->lock, flags);
5429
5430 for (i = 0; i < AC_NUM; i++) {
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08005431 txq = &priv->txq[i];
Zhu Yib481de92007-09-25 17:54:57 -07005432 q = &txq->q;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08005433 avail = iwl_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07005434
Johannes Berg57ffc582008-04-29 17:18:59 +02005435 stats[i].len = q->n_window - avail;
5436 stats[i].limit = q->n_window - q->high_mark;
5437 stats[i].count = q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -07005438
5439 }
5440 spin_unlock_irqrestore(&priv->lock, flags);
5441
5442 IWL_DEBUG_MAC80211("leave\n");
5443
5444 return 0;
5445}
5446
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005447static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07005448{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005449 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07005450 unsigned long flags;
5451
5452 mutex_lock(&priv->mutex);
5453 IWL_DEBUG_MAC80211("enter\n");
5454
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005455 iwl_reset_qos(priv);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08005456
Zhu Yib481de92007-09-25 17:54:57 -07005457 spin_lock_irqsave(&priv->lock, flags);
5458 priv->assoc_id = 0;
5459 priv->assoc_capability = 0;
Zhu Yib481de92007-09-25 17:54:57 -07005460
5461 /* new association get rid of ibss beacon skb */
5462 if (priv->ibss_beacon)
5463 dev_kfree_skb(priv->ibss_beacon);
5464
5465 priv->ibss_beacon = NULL;
5466
5467 priv->beacon_int = priv->hw->conf.beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08005468 priv->timestamp = 0;
Johannes Berg05c914f2008-09-11 00:01:58 +02005469 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
Zhu Yib481de92007-09-25 17:54:57 -07005470 priv->beacon_int = 0;
5471
5472 spin_unlock_irqrestore(&priv->lock, flags);
5473
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005474 if (!iwl_is_ready_rf(priv)) {
Mohamed Abbasfde35712007-11-29 11:10:15 +08005475 IWL_DEBUG_MAC80211("leave - not ready\n");
5476 mutex_unlock(&priv->mutex);
5477 return;
5478 }
5479
Mohamed Abbas15e869d2007-10-25 17:15:46 +08005480 /* we are restarting association process
5481 * clear RXON_FILTER_ASSOC_MSK bit
5482 */
Johannes Berg05c914f2008-09-11 00:01:58 +02005483 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08005484 iwl_scan_cancel_timeout(priv, 100);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005485 priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005486 iwl3945_commit_rxon(priv);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08005487 }
5488
Zhu Yib481de92007-09-25 17:54:57 -07005489 /* Per mac80211.h: This is only used in IBSS mode... */
Johannes Berg05c914f2008-09-11 00:01:58 +02005490 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Mohamed Abbas15e869d2007-10-25 17:15:46 +08005491
Zhu Yib481de92007-09-25 17:54:57 -07005492 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
5493 mutex_unlock(&priv->mutex);
5494 return;
5495 }
5496
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005497 iwl3945_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005498
5499 mutex_unlock(&priv->mutex);
5500
5501 IWL_DEBUG_MAC80211("leave\n");
5502
5503}
5504
Johannes Berge039fa42008-05-15 12:55:29 +02005505static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07005506{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005507 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07005508 unsigned long flags;
5509
Zhu Yib481de92007-09-25 17:54:57 -07005510 IWL_DEBUG_MAC80211("enter\n");
5511
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005512 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005513 IWL_DEBUG_MAC80211("leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07005514 return -EIO;
5515 }
5516
Johannes Berg05c914f2008-09-11 00:01:58 +02005517 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Zhu Yib481de92007-09-25 17:54:57 -07005518 IWL_DEBUG_MAC80211("leave - not IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07005519 return -EIO;
5520 }
5521
5522 spin_lock_irqsave(&priv->lock, flags);
5523
5524 if (priv->ibss_beacon)
5525 dev_kfree_skb(priv->ibss_beacon);
5526
5527 priv->ibss_beacon = skb;
5528
5529 priv->assoc_id = 0;
5530
5531 IWL_DEBUG_MAC80211("leave\n");
5532 spin_unlock_irqrestore(&priv->lock, flags);
5533
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005534 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005535
Abhijeet Kolekardc4b1e72008-09-03 11:26:30 +08005536 iwl3945_post_associate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005537
Zhu Yib481de92007-09-25 17:54:57 -07005538
5539 return 0;
5540}
5541
5542/*****************************************************************************
5543 *
5544 * sysfs attributes
5545 *
5546 *****************************************************************************/
5547
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08005548#ifdef CONFIG_IWL3945_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07005549
5550/*
5551 * The following adds a new attribute to the sysfs representation
5552 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
5553 * used for controlling the debug level.
5554 *
5555 * See the level definitions in iwl for details.
5556 */
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005557static ssize_t show_debug_level(struct device *d,
5558 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07005559{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005560 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005561
5562 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07005563}
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005564static ssize_t store_debug_level(struct device *d,
5565 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07005566 const char *buf, size_t count)
5567{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005568 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005569 unsigned long val;
5570 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07005571
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005572 ret = strict_strtoul(buf, 0, &val);
5573 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08005574 IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07005575 else
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005576 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07005577
5578 return strnlen(buf, count);
5579}
5580
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005581static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
5582 show_debug_level, store_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07005583
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08005584#endif /* CONFIG_IWL3945_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07005585
Zhu Yib481de92007-09-25 17:54:57 -07005586static ssize_t show_temperature(struct device *d,
5587 struct device_attribute *attr, char *buf)
5588{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005589 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07005590
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005591 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07005592 return -EAGAIN;
5593
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005594 return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
Zhu Yib481de92007-09-25 17:54:57 -07005595}
5596
5597static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
5598
Zhu Yib481de92007-09-25 17:54:57 -07005599static ssize_t show_tx_power(struct device *d,
5600 struct device_attribute *attr, char *buf)
5601{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005602 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08005603 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07005604}
5605
5606static ssize_t store_tx_power(struct device *d,
5607 struct device_attribute *attr,
5608 const char *buf, size_t count)
5609{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005610 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07005611 char *p = (char *)buf;
5612 u32 val;
5613
5614 val = simple_strtoul(p, &p, 10);
5615 if (p == buf)
Tomas Winkler978785a2008-12-19 10:37:31 +08005616 IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07005617 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005618 iwl3945_hw_reg_set_txpower(priv, val);
Zhu Yib481de92007-09-25 17:54:57 -07005619
5620 return count;
5621}
5622
5623static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
5624
5625static ssize_t show_flags(struct device *d,
5626 struct device_attribute *attr, char *buf)
5627{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005628 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07005629
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005630 return sprintf(buf, "0x%04X\n", priv->active39_rxon.flags);
Zhu Yib481de92007-09-25 17:54:57 -07005631}
5632
5633static ssize_t store_flags(struct device *d,
5634 struct device_attribute *attr,
5635 const char *buf, size_t count)
5636{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005637 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07005638 u32 flags = simple_strtoul(buf, NULL, 0);
5639
5640 mutex_lock(&priv->mutex);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005641 if (le32_to_cpu(priv->staging39_rxon.flags) != flags) {
Zhu Yib481de92007-09-25 17:54:57 -07005642 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08005643 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08005644 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07005645 else {
5646 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
5647 flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005648 priv->staging39_rxon.flags = cpu_to_le32(flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005649 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005650 }
5651 }
5652 mutex_unlock(&priv->mutex);
5653
5654 return count;
5655}
5656
5657static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
5658
5659static ssize_t show_filter_flags(struct device *d,
5660 struct device_attribute *attr, char *buf)
5661{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005662 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07005663
5664 return sprintf(buf, "0x%04X\n",
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005665 le32_to_cpu(priv->active39_rxon.filter_flags));
Zhu Yib481de92007-09-25 17:54:57 -07005666}
5667
5668static ssize_t store_filter_flags(struct device *d,
5669 struct device_attribute *attr,
5670 const char *buf, size_t count)
5671{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005672 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07005673 u32 filter_flags = simple_strtoul(buf, NULL, 0);
5674
5675 mutex_lock(&priv->mutex);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005676 if (le32_to_cpu(priv->staging39_rxon.filter_flags) != filter_flags) {
Zhu Yib481de92007-09-25 17:54:57 -07005677 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08005678 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08005679 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07005680 else {
5681 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
5682 "0x%04X\n", filter_flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005683 priv->staging39_rxon.filter_flags =
Zhu Yib481de92007-09-25 17:54:57 -07005684 cpu_to_le32(filter_flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005685 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005686 }
5687 }
5688 mutex_unlock(&priv->mutex);
5689
5690 return count;
5691}
5692
5693static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
5694 store_filter_flags);
5695
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08005696#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07005697
5698static ssize_t show_measurement(struct device *d,
5699 struct device_attribute *attr, char *buf)
5700{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005701 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler600c0e12008-12-19 10:37:04 +08005702 struct iwl_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07005703 u32 size = sizeof(measure_report), len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03005704 u8 *data = (u8 *)&measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07005705 unsigned long flags;
5706
5707 spin_lock_irqsave(&priv->lock, flags);
5708 if (!(priv->measurement_status & MEASUREMENT_READY)) {
5709 spin_unlock_irqrestore(&priv->lock, flags);
5710 return 0;
5711 }
5712 memcpy(&measure_report, &priv->measure_report, size);
5713 priv->measurement_status = 0;
5714 spin_unlock_irqrestore(&priv->lock, flags);
5715
5716 while (size && (PAGE_SIZE - len)) {
5717 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
5718 PAGE_SIZE - len, 1);
5719 len = strlen(buf);
5720 if (PAGE_SIZE - len)
5721 buf[len++] = '\n';
5722
5723 ofs += 16;
5724 size -= min(size, 16U);
5725 }
5726
5727 return len;
5728}
5729
5730static ssize_t store_measurement(struct device *d,
5731 struct device_attribute *attr,
5732 const char *buf, size_t count)
5733{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005734 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07005735 struct ieee80211_measurement_params params = {
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005736 .channel = le16_to_cpu(priv->active39_rxon.channel),
Zhu Yib481de92007-09-25 17:54:57 -07005737 .start_time = cpu_to_le64(priv->last_tsf),
5738 .duration = cpu_to_le16(1),
5739 };
5740 u8 type = IWL_MEASURE_BASIC;
5741 u8 buffer[32];
5742 u8 channel;
5743
5744 if (count) {
5745 char *p = buffer;
5746 strncpy(buffer, buf, min(sizeof(buffer), count));
5747 channel = simple_strtoul(p, NULL, 0);
5748 if (channel)
5749 params.channel = channel;
5750
5751 p = buffer;
5752 while (*p && *p != ' ')
5753 p++;
5754 if (*p)
5755 type = simple_strtoul(p + 1, NULL, 0);
5756 }
5757
5758 IWL_DEBUG_INFO("Invoking measurement of type %d on "
5759 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005760 iwl3945_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07005761
5762 return count;
5763}
5764
5765static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
5766 show_measurement, store_measurement);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08005767#endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07005768
Zhu Yib481de92007-09-25 17:54:57 -07005769static ssize_t store_retry_rate(struct device *d,
5770 struct device_attribute *attr,
5771 const char *buf, size_t count)
5772{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005773 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07005774
5775 priv->retry_rate = simple_strtoul(buf, NULL, 0);
5776 if (priv->retry_rate <= 0)
5777 priv->retry_rate = 1;
5778
5779 return count;
5780}
5781
5782static ssize_t show_retry_rate(struct device *d,
5783 struct device_attribute *attr, char *buf)
5784{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005785 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07005786 return sprintf(buf, "%d", priv->retry_rate);
5787}
5788
5789static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
5790 store_retry_rate);
5791
5792static ssize_t store_power_level(struct device *d,
5793 struct device_attribute *attr,
5794 const char *buf, size_t count)
5795{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005796 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07005797 int rc;
5798 int mode;
5799
5800 mode = simple_strtoul(buf, NULL, 0);
5801 mutex_lock(&priv->mutex);
5802
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005803 if (!iwl_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005804 rc = -EAGAIN;
5805 goto out;
5806 }
5807
Samuel Ortiz1125eff2008-12-19 10:37:14 +08005808 if ((mode < 1) || (mode > IWL39_POWER_LIMIT) ||
5809 (mode == IWL39_POWER_AC))
5810 mode = IWL39_POWER_AC;
Zhu Yib481de92007-09-25 17:54:57 -07005811 else
5812 mode |= IWL_POWER_ENABLED;
5813
5814 if (mode != priv->power_mode) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005815 rc = iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(mode));
Zhu Yib481de92007-09-25 17:54:57 -07005816 if (rc) {
5817 IWL_DEBUG_MAC80211("failed setting power mode.\n");
5818 goto out;
5819 }
5820 priv->power_mode = mode;
5821 }
5822
5823 rc = count;
5824
5825 out:
5826 mutex_unlock(&priv->mutex);
5827 return rc;
5828}
5829
5830#define MAX_WX_STRING 80
5831
5832/* Values are in microsecond */
5833static const s32 timeout_duration[] = {
5834 350000,
5835 250000,
5836 75000,
5837 37000,
5838 25000,
5839};
5840static const s32 period_duration[] = {
5841 400000,
5842 700000,
5843 1000000,
5844 1000000,
5845 1000000
5846};
5847
5848static ssize_t show_power_level(struct device *d,
5849 struct device_attribute *attr, char *buf)
5850{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005851 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07005852 int level = IWL_POWER_LEVEL(priv->power_mode);
5853 char *p = buf;
5854
5855 p += sprintf(p, "%d ", level);
5856 switch (level) {
5857 case IWL_POWER_MODE_CAM:
Samuel Ortiz1125eff2008-12-19 10:37:14 +08005858 case IWL39_POWER_AC:
Zhu Yib481de92007-09-25 17:54:57 -07005859 p += sprintf(p, "(AC)");
5860 break;
Samuel Ortiz1125eff2008-12-19 10:37:14 +08005861 case IWL39_POWER_BATTERY:
Zhu Yib481de92007-09-25 17:54:57 -07005862 p += sprintf(p, "(BATTERY)");
5863 break;
5864 default:
5865 p += sprintf(p,
5866 "(Timeout %dms, Period %dms)",
5867 timeout_duration[level - 1] / 1000,
5868 period_duration[level - 1] / 1000);
5869 }
5870
5871 if (!(priv->power_mode & IWL_POWER_ENABLED))
5872 p += sprintf(p, " OFF\n");
5873 else
5874 p += sprintf(p, " \n");
5875
Tomas Winkler3ac7f142008-07-21 02:40:14 +03005876 return p - buf + 1;
Zhu Yib481de92007-09-25 17:54:57 -07005877
5878}
5879
5880static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
5881 store_power_level);
5882
5883static ssize_t show_channels(struct device *d,
5884 struct device_attribute *attr, char *buf)
5885{
Johannes Berg8318d782008-01-24 19:38:38 +01005886 /* all this shit doesn't belong into sysfs anyway */
5887 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07005888}
5889
5890static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
5891
5892static ssize_t show_statistics(struct device *d,
5893 struct device_attribute *attr, char *buf)
5894{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005895 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005896 u32 size = sizeof(struct iwl3945_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07005897 u32 len = 0, ofs = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005898 u8 *data = (u8 *)&priv->statistics_39;
Zhu Yib481de92007-09-25 17:54:57 -07005899 int rc = 0;
5900
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005901 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07005902 return -EAGAIN;
5903
5904 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005905 rc = iwl3945_send_statistics_request(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005906 mutex_unlock(&priv->mutex);
5907
5908 if (rc) {
5909 len = sprintf(buf,
5910 "Error sending statistics request: 0x%08X\n", rc);
5911 return len;
5912 }
5913
5914 while (size && (PAGE_SIZE - len)) {
5915 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
5916 PAGE_SIZE - len, 1);
5917 len = strlen(buf);
5918 if (PAGE_SIZE - len)
5919 buf[len++] = '\n';
5920
5921 ofs += 16;
5922 size -= min(size, 16U);
5923 }
5924
5925 return len;
5926}
5927
5928static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
5929
5930static ssize_t show_antenna(struct device *d,
5931 struct device_attribute *attr, char *buf)
5932{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005933 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07005934
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005935 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07005936 return -EAGAIN;
5937
5938 return sprintf(buf, "%d\n", priv->antenna);
5939}
5940
5941static ssize_t store_antenna(struct device *d,
5942 struct device_attribute *attr,
5943 const char *buf, size_t count)
5944{
5945 int ant;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005946 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07005947
5948 if (count == 0)
5949 return 0;
5950
5951 if (sscanf(buf, "%1i", &ant) != 1) {
5952 IWL_DEBUG_INFO("not in hex or decimal form.\n");
5953 return count;
5954 }
5955
5956 if ((ant >= 0) && (ant <= 2)) {
5957 IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005958 priv->antenna = (enum iwl3945_antenna)ant;
Zhu Yib481de92007-09-25 17:54:57 -07005959 } else
5960 IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant);
5961
5962
5963 return count;
5964}
5965
5966static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
5967
5968static ssize_t show_status(struct device *d,
5969 struct device_attribute *attr, char *buf)
5970{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005971 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005972 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07005973 return -EAGAIN;
5974 return sprintf(buf, "0x%08x\n", (int)priv->status);
5975}
5976
5977static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
5978
5979static ssize_t dump_error_log(struct device *d,
5980 struct device_attribute *attr,
5981 const char *buf, size_t count)
5982{
5983 char *p = (char *)buf;
5984
5985 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005986 iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07005987
5988 return strnlen(buf, count);
5989}
5990
5991static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
5992
5993static ssize_t dump_event_log(struct device *d,
5994 struct device_attribute *attr,
5995 const char *buf, size_t count)
5996{
5997 char *p = (char *)buf;
5998
5999 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006000 iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07006001
6002 return strnlen(buf, count);
6003}
6004
6005static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
6006
6007/*****************************************************************************
6008 *
Tomas Winklera96a27f2008-10-23 23:48:56 -07006009 * driver setup and tear down
Zhu Yib481de92007-09-25 17:54:57 -07006010 *
6011 *****************************************************************************/
6012
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006013static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07006014{
6015 priv->workqueue = create_workqueue(DRV_NAME);
6016
6017 init_waitqueue_head(&priv->wait_command_queue);
6018
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006019 INIT_WORK(&priv->up, iwl3945_bg_up);
6020 INIT_WORK(&priv->restart, iwl3945_bg_restart);
6021 INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01006022 INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006023 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006024 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
6025 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
Helmut Schaa26635162009-01-15 09:38:44 +01006026 INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll);
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08006027 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
6028 INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
6029 INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
6030 INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
Zhu Yib481de92007-09-25 17:54:57 -07006031
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006032 iwl3945_hw_setup_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006033
6034 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006035 iwl3945_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07006036}
6037
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006038static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07006039{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006040 iwl3945_hw_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006041
Joonwoo Parke47eb6a2007-11-29 10:42:49 +09006042 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07006043 cancel_delayed_work(&priv->scan_check);
6044 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07006045 cancel_work_sync(&priv->beacon_update);
6046}
6047
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006048static struct attribute *iwl3945_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07006049 &dev_attr_antenna.attr,
6050 &dev_attr_channels.attr,
6051 &dev_attr_dump_errors.attr,
6052 &dev_attr_dump_events.attr,
6053 &dev_attr_flags.attr,
6054 &dev_attr_filter_flags.attr,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08006055#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07006056 &dev_attr_measurement.attr,
6057#endif
6058 &dev_attr_power_level.attr,
Zhu Yib481de92007-09-25 17:54:57 -07006059 &dev_attr_retry_rate.attr,
Zhu Yib481de92007-09-25 17:54:57 -07006060 &dev_attr_statistics.attr,
6061 &dev_attr_status.attr,
6062 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07006063 &dev_attr_tx_power.attr,
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08006064#ifdef CONFIG_IWL3945_DEBUG
6065 &dev_attr_debug_level.attr,
6066#endif
Zhu Yib481de92007-09-25 17:54:57 -07006067 NULL
6068};
6069
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006070static struct attribute_group iwl3945_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07006071 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006072 .attrs = iwl3945_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07006073};
6074
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006075static struct ieee80211_ops iwl3945_hw_ops = {
6076 .tx = iwl3945_mac_tx,
6077 .start = iwl3945_mac_start,
6078 .stop = iwl3945_mac_stop,
6079 .add_interface = iwl3945_mac_add_interface,
6080 .remove_interface = iwl3945_mac_remove_interface,
6081 .config = iwl3945_mac_config,
6082 .config_interface = iwl3945_mac_config_interface,
6083 .configure_filter = iwl3945_configure_filter,
6084 .set_key = iwl3945_mac_set_key,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006085 .get_tx_stats = iwl3945_mac_get_tx_stats,
6086 .conf_tx = iwl3945_mac_conf_tx,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006087 .reset_tsf = iwl3945_mac_reset_tsf,
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08006088 .bss_info_changed = iwl3945_bss_info_changed,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006089 .hw_scan = iwl3945_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07006090};
6091
Winkler, Tomase52119c2008-12-22 11:31:19 +08006092static int iwl3945_init_drv(struct iwl_priv *priv)
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006093{
6094 int ret;
Samuel Ortize6148912009-01-23 13:45:15 -08006095 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006096
6097 priv->retry_rate = 1;
6098 priv->ibss_beacon = NULL;
6099
6100 spin_lock_init(&priv->lock);
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08006101 spin_lock_init(&priv->power_data.lock);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006102 spin_lock_init(&priv->sta_lock);
6103 spin_lock_init(&priv->hcmd_lock);
6104
6105 INIT_LIST_HEAD(&priv->free_frames);
6106
6107 mutex_init(&priv->mutex);
6108
6109 /* Clear the driver's (not device's) station table */
6110 iwl3945_clear_stations_table(priv);
6111
6112 priv->data_retry_limit = -1;
6113 priv->ieee_channels = NULL;
6114 priv->ieee_rates = NULL;
6115 priv->band = IEEE80211_BAND_2GHZ;
6116
6117 priv->iw_mode = NL80211_IFTYPE_STATION;
6118
6119 iwl_reset_qos(priv);
6120
6121 priv->qos_data.qos_active = 0;
6122 priv->qos_data.qos_cap.val = 0;
6123
6124 priv->rates_mask = IWL_RATES_MASK;
6125 /* If power management is turned on, default to AC mode */
Samuel Ortizc7a7c8e2009-01-08 10:20:01 -08006126 priv->power_mode = IWL39_POWER_AC;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08006127 priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006128
Samuel Ortize6148912009-01-23 13:45:15 -08006129 if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
6130 IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
6131 eeprom->version);
6132 ret = -EINVAL;
6133 goto err;
6134 }
6135 ret = iwl_init_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006136 if (ret) {
6137 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
6138 goto err;
6139 }
6140
Samuel Ortize6148912009-01-23 13:45:15 -08006141 /* Set up txpower settings in driver for all channels */
6142 if (iwl3945_txpower_set_from_eeprom(priv)) {
6143 ret = -EIO;
6144 goto err_free_channel_map;
6145 }
6146
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006147 ret = iwl3945_init_geos(priv);
6148 if (ret) {
6149 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
6150 goto err_free_channel_map;
6151 }
6152
6153 return 0;
6154
6155err_free_channel_map:
Samuel Ortize6148912009-01-23 13:45:15 -08006156 iwl_free_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006157err:
6158 return ret;
6159}
6160
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006161static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07006162{
6163 int err = 0;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006164 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07006165 struct ieee80211_hw *hw;
Kolekar, Abhijeetc0f20d92008-12-19 10:37:19 +08006166 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Samuel Ortize6148912009-01-23 13:45:15 -08006167 struct iwl3945_eeprom *eeprom;
Mohamed Abbas0359fac2008-03-28 16:21:08 -07006168 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07006169
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006170 /***********************
6171 * 1. Allocating HW data
6172 * ********************/
6173
Zhu Yib481de92007-09-25 17:54:57 -07006174 /* mac80211 allocates memory for this device instance, including
6175 * space for this driver's private structure */
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006176 hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
Zhu Yib481de92007-09-25 17:54:57 -07006177 if (hw == NULL) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08006178 printk(KERN_ERR DRV_NAME "Can not allocate network device\n");
Zhu Yib481de92007-09-25 17:54:57 -07006179 err = -ENOMEM;
6180 goto out;
6181 }
Zhu Yib481de92007-09-25 17:54:57 -07006182 priv = hw->priv;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006183 SET_IEEE80211_DEV(hw, &pdev->dev);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08006184
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08006185 if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) ||
6186 (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08006187 IWL_ERR(priv,
6188 "invalid queues_num, should be between %d and %d\n",
6189 IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES);
Samuel Ortiza3139c52008-12-19 10:37:09 +08006190 err = -EINVAL;
6191 goto out;
6192 }
6193
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006194 /*
6195 * Disabling hardware scan means that mac80211 will perform scans
6196 * "the hard way", rather than using device's scan.
6197 */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08006198 if (iwl3945_mod_params.disable_hw_scan) {
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08006199 IWL_DEBUG_INFO("Disabling hw_scan\n");
6200 iwl3945_hw_ops.hw_scan = NULL;
6201 }
6202
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006203
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006204 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006205 priv->cfg = cfg;
6206 priv->pci_dev = pdev;
6207
6208#ifdef CONFIG_IWL3945_DEBUG
6209 priv->debug_level = iwl3945_mod_params.debug;
6210 atomic_set(&priv->restrict_refcnt, 0);
6211#endif
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006212 hw->rate_control_algorithm = "iwl-3945-rs";
6213 hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
6214
Cahill, Ben M6440adb2007-11-29 11:09:55 +08006215 /* Select antenna (may be helpful if only one antenna is connected) */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08006216 priv->antenna = (enum iwl3945_antenna)iwl3945_mod_params.antenna;
Zhu Yib481de92007-09-25 17:54:57 -07006217
Bruno Randolf566bfe52008-05-08 19:15:40 +02006218 /* Tell mac80211 our characteristics */
Johannes Berg605a0bd2008-07-15 10:10:01 +02006219 hw->flags = IEEE80211_HW_SIGNAL_DBM |
Bruno Randolf566bfe52008-05-08 19:15:40 +02006220 IEEE80211_HW_NOISE_DBM;
Zhu Yib481de92007-09-25 17:54:57 -07006221
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -07006222 hw->wiphy->interface_modes =
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -07006223 BIT(NL80211_IFTYPE_STATION) |
6224 BIT(NL80211_IFTYPE_ADHOC);
6225
Luis R. Rodriguez2a44f912009-01-22 15:05:49 -08006226 hw->wiphy->custom_regulatory = true;
Luis R. Rodriguezea4a82dc2008-11-12 14:22:04 -08006227
Cahill, Ben M6440adb2007-11-29 11:09:55 +08006228 /* 4 EDCA QOS priorities */
Zhu Yib481de92007-09-25 17:54:57 -07006229 hw->queues = 4;
6230
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006231 /***************************
6232 * 2. Initializing PCI bus
6233 * *************************/
Zhu Yib481de92007-09-25 17:54:57 -07006234 if (pci_enable_device(pdev)) {
6235 err = -ENODEV;
6236 goto out_ieee80211_free_hw;
6237 }
6238
6239 pci_set_master(pdev);
6240
Zhu Yib481de92007-09-25 17:54:57 -07006241 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
6242 if (!err)
6243 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
6244 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08006245 IWL_WARN(priv, "No suitable DMA available.\n");
Zhu Yib481de92007-09-25 17:54:57 -07006246 goto out_pci_disable_device;
6247 }
6248
6249 pci_set_drvdata(pdev, priv);
6250 err = pci_request_regions(pdev, DRV_NAME);
6251 if (err)
6252 goto out_pci_disable_device;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08006253
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006254 /***********************
6255 * 3. Read REV Register
6256 * ********************/
Zhu Yib481de92007-09-25 17:54:57 -07006257 priv->hw_base = pci_iomap(pdev, 0, 0);
6258 if (!priv->hw_base) {
6259 err = -ENODEV;
6260 goto out_pci_release_regions;
6261 }
6262
6263 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
6264 (unsigned long long) pci_resource_len(pdev, 0));
6265 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
6266
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006267 /* We disable the RETRY_TIMEOUT register (0x41) to keep
6268 * PCI Tx retries from interfering with C3 CPU state */
6269 pci_write_config_byte(pdev, 0x41, 0x00);
Zhu Yib481de92007-09-25 17:54:57 -07006270
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006271 /* amp init */
6272 err = priv->cfg->ops->lib->apm_ops.init(priv);
Tomas Winkler3ac7f142008-07-21 02:40:14 +03006273 if (err < 0) {
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006274 IWL_DEBUG_INFO("Failed to init APMG\n");
6275 goto out_iounmap;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03006276 }
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006277
6278 /***********************
6279 * 4. Read EEPROM
6280 * ********************/
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006281
Zhu Yi5a669262008-01-14 17:46:18 -08006282 /* Read the EEPROM */
Samuel Ortize6148912009-01-23 13:45:15 -08006283 err = iwl_eeprom_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006284 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08006285 IWL_ERR(priv, "Unable to init EEPROM\n");
Zhu Yi5a669262008-01-14 17:46:18 -08006286 goto out_remove_sysfs;
6287 }
6288 /* MAC Address location in EEPROM same for 3945/4965 */
Samuel Ortize6148912009-01-23 13:45:15 -08006289 eeprom = (struct iwl3945_eeprom *)priv->eeprom;
6290 memcpy(priv->mac_addr, eeprom->mac_address, ETH_ALEN);
Johannes Berge1749612008-10-27 15:59:26 -07006291 IWL_DEBUG_INFO("MAC address: %pM\n", priv->mac_addr);
Zhu Yi5a669262008-01-14 17:46:18 -08006292 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
6293
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006294 /***********************
6295 * 5. Setup HW Constants
6296 * ********************/
6297 /* Device-specific setup */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08006298 if (iwl3945_hw_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08006299 IWL_ERR(priv, "failed to set hw settings\n");
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006300 goto out_iounmap;
6301 }
6302
6303 /***********************
6304 * 6. Setup priv
6305 * ********************/
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006306
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006307 err = iwl3945_init_drv(priv);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08006308 if (err) {
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006309 IWL_ERR(priv, "initializing driver failed\n");
6310 goto out_free_geos;
Reinette Chatre849e0dc2008-01-23 10:15:18 -08006311 }
Reinette Chatre849e0dc2008-01-23 10:15:18 -08006312
Tomas Winkler978785a2008-12-19 10:37:31 +08006313 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
6314 priv->cfg->name);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006315
6316 /***********************************
6317 * 7. Initialize Module Parameters
6318 * **********************************/
6319
6320 /* Initialize module parameter values here */
6321 /* Disable radio (SW RF KILL) via parameter when loading driver */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08006322 if (iwl3945_mod_params.disable) {
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006323 set_bit(STATUS_RF_KILL_SW, &priv->status);
6324 IWL_DEBUG_INFO("Radio disabled.\n");
6325 }
6326
6327
6328 /***********************
6329 * 8. Setup Services
6330 * ********************/
6331
6332 spin_lock_irqsave(&priv->lock, flags);
6333 iwl3945_disable_interrupts(priv);
6334 spin_unlock_irqrestore(&priv->lock, flags);
6335
Helmut Schaa26635162009-01-15 09:38:44 +01006336 pci_enable_msi(priv->pci_dev);
6337
6338 err = request_irq(priv->pci_dev->irq, iwl3945_isr, IRQF_SHARED,
6339 DRV_NAME, priv);
6340 if (err) {
6341 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
6342 goto out_disable_msi;
6343 }
6344
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006345 err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
6346 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08006347 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006348 goto out_release_irq;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006349 }
6350
6351 iwl3945_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6);
6352 iwl3945_setup_deferred_work(priv);
6353 iwl3945_setup_rx_handlers(priv);
6354
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006355 /*********************************
Helmut Schaa26635162009-01-15 09:38:44 +01006356 * 9. Setup and Register mac80211
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006357 * *******************************/
6358
Zhu Yi5a669262008-01-14 17:46:18 -08006359 err = ieee80211_register_hw(priv->hw);
6360 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08006361 IWL_ERR(priv, "Failed to register network device: %d\n", err);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006362 goto out_remove_sysfs;
Zhu Yib481de92007-09-25 17:54:57 -07006363 }
6364
Zhu Yi5a669262008-01-14 17:46:18 -08006365 priv->hw->conf.beacon_int = 100;
6366 priv->mac80211_registered = 1;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006367
Samuel Ortizc0af96a2009-01-21 18:27:54 +01006368 err = iwl_rfkill_init(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08006369 if (err)
Winkler, Tomas15b16872008-12-19 10:37:33 +08006370 IWL_ERR(priv, "Unable to initialize RFKILL system. "
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08006371 "Ignoring error: %d\n", err);
6372
Helmut Schaa26635162009-01-15 09:38:44 +01006373 /* Start monitoring the killswitch */
6374 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
6375 2 * HZ);
6376
Zhu Yib481de92007-09-25 17:54:57 -07006377 return 0;
6378
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006379 out_remove_sysfs:
6380 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08006381 out_free_geos:
6382 iwl3945_free_geos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006383
6384 out_release_irq:
Helmut Schaa26635162009-01-15 09:38:44 +01006385 free_irq(priv->pci_dev->irq, priv);
Zhu Yib481de92007-09-25 17:54:57 -07006386 destroy_workqueue(priv->workqueue);
6387 priv->workqueue = NULL;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08006388 iwl3945_unset_hw_params(priv);
Helmut Schaa26635162009-01-15 09:38:44 +01006389 out_disable_msi:
6390 pci_disable_msi(priv->pci_dev);
Zhu Yib481de92007-09-25 17:54:57 -07006391 out_iounmap:
6392 pci_iounmap(pdev, priv->hw_base);
6393 out_pci_release_regions:
6394 pci_release_regions(pdev);
6395 out_pci_disable_device:
6396 pci_disable_device(pdev);
6397 pci_set_drvdata(pdev, NULL);
6398 out_ieee80211_free_hw:
6399 ieee80211_free_hw(priv->hw);
6400 out:
6401 return err;
6402}
6403
Reinette Chatrec83dbf62008-03-21 13:53:41 -07006404static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07006405{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006406 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07006407 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07006408
6409 if (!priv)
6410 return;
6411
6412 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
6413
Zhu Yib481de92007-09-25 17:54:57 -07006414 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08006415
Kolekar, Abhijeetd552bfb2008-12-19 10:37:41 +08006416 if (priv->mac80211_registered) {
6417 ieee80211_unregister_hw(priv->hw);
6418 priv->mac80211_registered = 0;
6419 } else {
6420 iwl3945_down(priv);
6421 }
Zhu Yib481de92007-09-25 17:54:57 -07006422
Mohamed Abbas0359fac2008-03-28 16:21:08 -07006423 /* make sure we flush any pending irq or
6424 * tasklet for the driver
6425 */
6426 spin_lock_irqsave(&priv->lock, flags);
6427 iwl3945_disable_interrupts(priv);
6428 spin_unlock_irqrestore(&priv->lock, flags);
6429
6430 iwl_synchronize_irq(priv);
6431
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006432 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07006433
Samuel Ortizc0af96a2009-01-21 18:27:54 +01006434 iwl_rfkill_unregister(priv);
Helmut Schaa26635162009-01-15 09:38:44 +01006435 cancel_delayed_work(&priv->rfkill_poll);
6436
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006437 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006438
6439 if (priv->rxq.bd)
Winkler, Tomas51af3d32008-12-22 11:31:23 +08006440 iwl_rx_queue_free(priv, &priv->rxq);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006441 iwl3945_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006442
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08006443 iwl3945_unset_hw_params(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006444 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006445
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08006446 /*netif_stop_queue(dev); */
6447 flush_workqueue(priv->workqueue);
6448
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006449 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07006450 * priv->workqueue... so we can't take down the workqueue
6451 * until now... */
6452 destroy_workqueue(priv->workqueue);
6453 priv->workqueue = NULL;
6454
Helmut Schaa26635162009-01-15 09:38:44 +01006455 free_irq(pdev->irq, priv);
6456 pci_disable_msi(pdev);
6457
Zhu Yib481de92007-09-25 17:54:57 -07006458 pci_iounmap(pdev, priv->hw_base);
6459 pci_release_regions(pdev);
6460 pci_disable_device(pdev);
6461 pci_set_drvdata(pdev, NULL);
6462
Samuel Ortize6148912009-01-23 13:45:15 -08006463 iwl_free_channel_map(priv);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08006464 iwl3945_free_geos(priv);
Winkler, Tomas805cee52009-01-19 15:30:28 -08006465 kfree(priv->scan);
Zhu Yib481de92007-09-25 17:54:57 -07006466 if (priv->ibss_beacon)
6467 dev_kfree_skb(priv->ibss_beacon);
6468
6469 ieee80211_free_hw(priv->hw);
6470}
6471
6472#ifdef CONFIG_PM
6473
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006474static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Zhu Yib481de92007-09-25 17:54:57 -07006475{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006476 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07006477
Zhu Yie655b9f2008-01-24 02:19:38 -08006478 if (priv->is_open) {
6479 set_bit(STATUS_IN_SUSPEND, &priv->status);
6480 iwl3945_mac_stop(priv->hw);
6481 priv->is_open = 1;
6482 }
Helmut Schaa26635162009-01-15 09:38:44 +01006483 pci_save_state(pdev);
6484 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07006485 pci_set_power_state(pdev, PCI_D3hot);
6486
Zhu Yib481de92007-09-25 17:54:57 -07006487 return 0;
6488}
6489
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006490static int iwl3945_pci_resume(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07006491{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006492 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07006493
Zhu Yib481de92007-09-25 17:54:57 -07006494 pci_set_power_state(pdev, PCI_D0);
Helmut Schaa26635162009-01-15 09:38:44 +01006495 pci_enable_device(pdev);
6496 pci_restore_state(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07006497
Zhu Yie655b9f2008-01-24 02:19:38 -08006498 if (priv->is_open)
6499 iwl3945_mac_start(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07006500
Zhu Yie655b9f2008-01-24 02:19:38 -08006501 clear_bit(STATUS_IN_SUSPEND, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07006502 return 0;
6503}
6504
6505#endif /* CONFIG_PM */
6506
6507/*****************************************************************************
6508 *
6509 * driver and module entry point
6510 *
6511 *****************************************************************************/
6512
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006513static struct pci_driver iwl3945_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07006514 .name = DRV_NAME,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006515 .id_table = iwl3945_hw_card_ids,
6516 .probe = iwl3945_pci_probe,
6517 .remove = __devexit_p(iwl3945_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07006518#ifdef CONFIG_PM
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006519 .suspend = iwl3945_pci_suspend,
6520 .resume = iwl3945_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07006521#endif
6522};
6523
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006524static int __init iwl3945_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07006525{
6526
6527 int ret;
6528 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
6529 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07006530
6531 ret = iwl3945_rate_control_register();
6532 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08006533 printk(KERN_ERR DRV_NAME
6534 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07006535 return ret;
6536 }
6537
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006538 ret = pci_register_driver(&iwl3945_driver);
Zhu Yib481de92007-09-25 17:54:57 -07006539 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08006540 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07006541 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07006542 }
Zhu Yib481de92007-09-25 17:54:57 -07006543
6544 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07006545
Reinette Chatre897e1cf2008-03-28 16:21:09 -07006546error_register:
6547 iwl3945_rate_control_unregister();
6548 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07006549}
6550
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006551static void __exit iwl3945_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07006552{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006553 pci_unregister_driver(&iwl3945_driver);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07006554 iwl3945_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07006555}
6556
Reinette Chatrea0987a82008-12-02 12:14:06 -08006557MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
Zhu Yi25cb6ca2008-09-11 11:45:22 +08006558
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08006559module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07006560MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08006561module_param_named(disable, iwl3945_mod_params.disable, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07006562MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -08006563module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444);
6564MODULE_PARM_DESC(swcrypto,
6565 "using software crypto (default 1 [software])\n");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08006566module_param_named(debug, iwl3945_mod_params.debug, uint, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07006567MODULE_PARM_DESC(debug, "debug output mask");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08006568module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07006569MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
6570
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08006571module_param_named(queues_num, iwl3945_mod_params.num_of_queues, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07006572MODULE_PARM_DESC(queues_num, "number of hw queues.");
6573
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006574module_exit(iwl3945_exit);
6575module_init(iwl3945_init);