blob: 7f35017d9df28337432e0a2b0e4d2893922647b6 [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Reinette Chatre01f81622009-01-08 10:20:02 -08003 * Copyright(c) 2003 - 2009 Intel Corporation. All rights reserved.
Zhu Yib481de92007-09-25 17:54:57 -07004 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
Winkler, Tomas759ef892008-12-09 11:28:58 -080025 * Intel Linux Wireless <ilw@linux.intel.com>
Zhu Yib481de92007-09-25 17:54:57 -070026 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29
Zhu Yib481de92007-09-25 17:54:57 -070030#include <linux/kernel.h>
31#include <linux/module.h>
Zhu Yib481de92007-09-25 17:54:57 -070032#include <linux/init.h>
33#include <linux/pci.h>
34#include <linux/dma-mapping.h>
35#include <linux/delay.h>
36#include <linux/skbuff.h>
37#include <linux/netdevice.h>
38#include <linux/wireless.h>
39#include <linux/firmware.h>
Zhu Yib481de92007-09-25 17:54:57 -070040#include <linux/etherdevice.h>
41#include <linux/if_arp.h>
42
43#include <net/ieee80211_radiotap.h>
John W. Linville7e272fc2008-09-24 18:13:14 -040044#include <net/lib80211.h>
Zhu Yib481de92007-09-25 17:54:57 -070045#include <net/mac80211.h>
46
47#include <asm/div64.h>
48
Samuel Ortiza3139c52008-12-19 10:37:09 +080049#define DRV_NAME "iwl3945"
50
Winkler, Tomasdbb66542008-12-22 11:31:14 +080051#include "iwl-fh.h"
52#include "iwl-3945-fh.h"
Tomas Winkler600c0e12008-12-19 10:37:04 +080053#include "iwl-commands.h"
Samuel Ortiz17f841c2009-01-23 13:45:20 -080054#include "iwl-sta.h"
Zhu Yib481de92007-09-25 17:54:57 -070055#include "iwl-3945.h"
56#include "iwl-helpers.h"
Kolekar, Abhijeet5747d472008-12-19 10:37:18 +080057#include "iwl-core.h"
Samuel Ortizd20b3c62008-12-19 10:37:15 +080058#include "iwl-dev.h"
Zhu Yib481de92007-09-25 17:54:57 -070059
Zhu Yib481de92007-09-25 17:54:57 -070060/*
61 * module name, copyright, version, etc.
Zhu Yib481de92007-09-25 17:54:57 -070062 */
63
64#define DRV_DESCRIPTION \
65"Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
66
Samuel Ortizd08853a2009-01-23 13:45:17 -080067#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070068#define VD "d"
69#else
70#define VD
71#endif
72
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +080073#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -070074#define VS "s"
75#else
76#define VS
77#endif
78
Kolekar, Abhijeeteaa686c2008-12-19 10:37:17 +080079#define IWL39_VERSION "1.2.26k" VD VS
Reinette Chatre01f81622009-01-08 10:20:02 -080080#define DRV_COPYRIGHT "Copyright(c) 2003-2009 Intel Corporation"
Tomas Winklera7b75202008-12-11 10:33:41 -080081#define DRV_AUTHOR "<ilw@linux.intel.com>"
Kolekar, Abhijeeteaa686c2008-12-19 10:37:17 +080082#define DRV_VERSION IWL39_VERSION
Zhu Yib481de92007-09-25 17:54:57 -070083
Zhu Yib481de92007-09-25 17:54:57 -070084
85MODULE_DESCRIPTION(DRV_DESCRIPTION);
86MODULE_VERSION(DRV_VERSION);
Tomas Winklera7b75202008-12-11 10:33:41 -080087MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
Zhu Yib481de92007-09-25 17:54:57 -070088MODULE_LICENSE("GPL");
89
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080090 /* module parameters */
91struct iwl_mod_params iwl3945_mod_params = {
92 .num_of_queues = IWL39_MAX_NUM_QUEUES,
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -080093 .sw_crypto = 1,
Samuel Ortizaf48d042009-01-23 13:45:19 -080094 .restart_fw = 1,
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080095 /* the rest are 0 by default */
96};
97
Zhu Yib481de92007-09-25 17:54:57 -070098/*************** STATION TABLE MANAGEMENT ****
Ben Cahill9fbab512007-11-29 11:09:47 +080099 * mac80211 should be examined to determine if sta_info is duplicating
Zhu Yib481de92007-09-25 17:54:57 -0700100 * the functionality provided here
101 */
102
103/**************************************************************/
Ian Schram01ebd062007-10-25 17:15:22 +0800104#if 0 /* temporary disable till we add real remove station */
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800105/**
106 * iwl3945_remove_station - Remove driver's knowledge of station.
107 *
108 * NOTE: This does not remove station from device's station table.
109 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800110static u8 iwl3945_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
Zhu Yib481de92007-09-25 17:54:57 -0700111{
112 int index = IWL_INVALID_STATION;
113 int i;
114 unsigned long flags;
115
116 spin_lock_irqsave(&priv->sta_lock, flags);
117
118 if (is_ap)
119 index = IWL_AP_ID;
120 else if (is_broadcast_ether_addr(addr))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800121 index = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700122 else
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800123 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800124 if (priv->stations_39[i].used &&
125 !compare_ether_addr(priv->stations_39[i].sta.sta.addr,
Zhu Yib481de92007-09-25 17:54:57 -0700126 addr)) {
127 index = i;
128 break;
129 }
130
131 if (unlikely(index == IWL_INVALID_STATION))
132 goto out;
133
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800134 if (priv->stations_39[index].used) {
135 priv->stations_39[index].used = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700136 priv->num_stations--;
137 }
138
139 BUG_ON(priv->num_stations < 0);
140
141out:
142 spin_unlock_irqrestore(&priv->sta_lock, flags);
143 return 0;
144}
Zhu Yi556f8db2007-09-27 11:27:33 +0800145#endif
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800146
147/**
148 * iwl3945_clear_stations_table - Clear the driver's station table
149 *
150 * NOTE: This does not clear or otherwise alter the device's station table.
151 */
Abhijeet Kolekare0158e62009-04-08 11:26:37 -0700152void iwl3945_clear_stations_table(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700153{
154 unsigned long flags;
155
156 spin_lock_irqsave(&priv->sta_lock, flags);
157
158 priv->num_stations = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800159 memset(priv->stations_39, 0, sizeof(priv->stations_39));
Zhu Yib481de92007-09-25 17:54:57 -0700160
161 spin_unlock_irqrestore(&priv->sta_lock, flags);
162}
163
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800164/**
165 * iwl3945_add_station - Add station to station tables in driver and device
166 */
Abhijeet Kolekar06fd3d82009-04-08 11:26:42 -0700167u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags, struct ieee80211_sta_ht_cap *ht_info)
Zhu Yib481de92007-09-25 17:54:57 -0700168{
169 int i;
170 int index = IWL_INVALID_STATION;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800171 struct iwl3945_station_entry *station;
Zhu Yib481de92007-09-25 17:54:57 -0700172 unsigned long flags_spin;
Zhu Yic14c5212007-09-27 11:27:35 +0800173 u8 rate;
Zhu Yib481de92007-09-25 17:54:57 -0700174
175 spin_lock_irqsave(&priv->sta_lock, flags_spin);
176 if (is_ap)
177 index = IWL_AP_ID;
178 else if (is_broadcast_ether_addr(addr))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800179 index = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700180 else
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800181 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800182 if (!compare_ether_addr(priv->stations_39[i].sta.sta.addr,
Zhu Yib481de92007-09-25 17:54:57 -0700183 addr)) {
184 index = i;
185 break;
186 }
187
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800188 if (!priv->stations_39[i].used &&
Zhu Yib481de92007-09-25 17:54:57 -0700189 index == IWL_INVALID_STATION)
190 index = i;
191 }
192
Ian Schram01ebd062007-10-25 17:15:22 +0800193 /* These two conditions has the same outcome but keep them separate
Zhu Yib481de92007-09-25 17:54:57 -0700194 since they have different meaning */
195 if (unlikely(index == IWL_INVALID_STATION)) {
196 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
197 return index;
198 }
199
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800200 if (priv->stations_39[index].used &&
201 !compare_ether_addr(priv->stations_39[index].sta.sta.addr, addr)) {
Zhu Yib481de92007-09-25 17:54:57 -0700202 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
203 return index;
204 }
205
Tomas Winklere1623442009-01-27 14:27:56 -0800206 IWL_DEBUG_ASSOC(priv, "Add STA ID %d: %pM\n", index, addr);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800207 station = &priv->stations_39[index];
Zhu Yib481de92007-09-25 17:54:57 -0700208 station->used = 1;
209 priv->num_stations++;
210
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800211 /* Set up the REPLY_ADD_STA command to send to device */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800212 memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd));
Zhu Yib481de92007-09-25 17:54:57 -0700213 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
214 station->sta.mode = 0;
215 station->sta.sta.sta_id = index;
216 station->sta.station_flags = 0;
217
Johannes Berg8318d782008-01-24 19:38:38 +0100218 if (priv->band == IEEE80211_BAND_5GHZ)
Tomas Winkler69946332007-10-25 17:15:27 +0800219 rate = IWL_RATE_6M_PLCP;
220 else
221 rate = IWL_RATE_1M_PLCP;
Zhu Yic14c5212007-09-27 11:27:35 +0800222
223 /* Turn on both antennas for the station... */
224 station->sta.rate_n_flags =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800225 iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK);
Zhu Yic14c5212007-09-27 11:27:35 +0800226
Zhu Yib481de92007-09-25 17:54:57 -0700227 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800228
229 /* Add station to device's station table */
Samuel Ortiz17f841c2009-01-23 13:45:20 -0800230 iwl_send_add_sta(priv,
231 (struct iwl_addsta_cmd *)&station->sta, flags);
Zhu Yib481de92007-09-25 17:54:57 -0700232 return index;
233
234}
235
Zhu Yib481de92007-09-25 17:54:57 -0700236/**
Samuel Ortiz7e4bca52009-01-23 13:45:18 -0800237 * iwl3945_get_antenna_flags - Get antenna flags for RXON command
238 * @priv: eeprom and antenna fields are used to determine antenna flags
239 *
240 * priv->eeprom39 is used to determine if antenna AUX/MAIN are reversed
241 * iwl3945_mod_params.antenna specifies the antenna diversity mode:
242 *
243 * IWL_ANTENNA_DIVERSITY - NIC selects best antenna by itself
244 * IWL_ANTENNA_MAIN - Force MAIN antenna
245 * IWL_ANTENNA_AUX - Force AUX antenna
246 */
247__le32 iwl3945_get_antenna_flags(const struct iwl_priv *priv)
248{
249 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
250
251 switch (iwl3945_mod_params.antenna) {
252 case IWL_ANTENNA_DIVERSITY:
253 return 0;
254
255 case IWL_ANTENNA_MAIN:
256 if (eeprom->antenna_switch_type)
257 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
258 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
259
260 case IWL_ANTENNA_AUX:
261 if (eeprom->antenna_switch_type)
262 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
263 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
264 }
265
266 /* bad antenna selector value */
267 IWL_ERR(priv, "Bad antenna selector value (0x%x)\n",
268 iwl3945_mod_params.antenna);
269
270 return 0; /* "diversity" is default if error */
271}
272
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800273static int iwl3945_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700274 struct ieee80211_key_conf *keyconf,
275 u8 sta_id)
276{
277 unsigned long flags;
278 __le16 key_flags = 0;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800279 int ret;
Zhu Yib481de92007-09-25 17:54:57 -0700280
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800281 key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
282 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
283
284 if (sta_id == priv->hw_params.bcast_sta_id)
285 key_flags |= STA_KEY_MULTICAST_MSK;
286
287 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
288 keyconf->hw_key_idx = keyconf->keyidx;
289 key_flags &= ~STA_KEY_FLG_INVALID;
290
Zhu Yib481de92007-09-25 17:54:57 -0700291 spin_lock_irqsave(&priv->sta_lock, flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800292 priv->stations_39[sta_id].keyinfo.alg = keyconf->alg;
293 priv->stations_39[sta_id].keyinfo.keylen = keyconf->keylen;
294 memcpy(priv->stations_39[sta_id].keyinfo.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700295 keyconf->keylen);
296
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800297 memcpy(priv->stations_39[sta_id].sta.key.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700298 keyconf->keylen);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800299
Abhijeet Kolekar43da9192009-03-17 21:51:53 -0700300 if ((priv->stations_39[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800301 == STA_KEY_FLG_NO_ENC)
Abhijeet Kolekar43da9192009-03-17 21:51:53 -0700302 priv->stations_39[sta_id].sta.key.key_offset =
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800303 iwl_get_free_ucode_key_index(priv);
304 /* else, we are overriding an existing key => no need to allocated room
305 * in uCode. */
306
Abhijeet Kolekar43da9192009-03-17 21:51:53 -0700307 WARN(priv->stations_39[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800308 "no space for a new key");
309
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800310 priv->stations_39[sta_id].sta.key.key_flags = key_flags;
311 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
312 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700313
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800314 IWL_DEBUG_INFO(priv, "hwcrypto: modify ucode station key info\n");
315
316 ret = iwl_send_add_sta(priv,
317 (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, CMD_ASYNC);
318
Zhu Yib481de92007-09-25 17:54:57 -0700319 spin_unlock_irqrestore(&priv->sta_lock, flags);
320
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800321 return ret;
322}
323
324static int iwl3945_set_tkip_dynamic_key_info(struct iwl_priv *priv,
325 struct ieee80211_key_conf *keyconf,
326 u8 sta_id)
327{
328 return -EOPNOTSUPP;
329}
330
331static int iwl3945_set_wep_dynamic_key_info(struct iwl_priv *priv,
332 struct ieee80211_key_conf *keyconf,
333 u8 sta_id)
334{
335 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -0700336}
337
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800338static int iwl3945_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
Zhu Yib481de92007-09-25 17:54:57 -0700339{
340 unsigned long flags;
341
342 spin_lock_irqsave(&priv->sta_lock, flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800343 memset(&priv->stations_39[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key));
344 memset(&priv->stations_39[sta_id].sta.key, 0,
Tomas Winkler4c897252008-12-19 10:37:05 +0800345 sizeof(struct iwl4965_keyinfo));
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800346 priv->stations_39[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
347 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
348 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700349 spin_unlock_irqrestore(&priv->sta_lock, flags);
350
Tomas Winklere1623442009-01-27 14:27:56 -0800351 IWL_DEBUG_INFO(priv, "hwcrypto: clear ucode station key info\n");
Samuel Ortiz17f841c2009-01-23 13:45:20 -0800352 iwl_send_add_sta(priv,
353 (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700354 return 0;
355}
356
Abhijeet Kolekarfa11d522009-03-11 11:17:54 -0700357static int iwl3945_set_dynamic_key(struct iwl_priv *priv,
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800358 struct ieee80211_key_conf *keyconf, u8 sta_id)
359{
360 int ret = 0;
361
362 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
363
364 switch (keyconf->alg) {
365 case ALG_CCMP:
366 ret = iwl3945_set_ccmp_dynamic_key_info(priv, keyconf, sta_id);
367 break;
368 case ALG_TKIP:
369 ret = iwl3945_set_tkip_dynamic_key_info(priv, keyconf, sta_id);
370 break;
371 case ALG_WEP:
372 ret = iwl3945_set_wep_dynamic_key_info(priv, keyconf, sta_id);
373 break;
374 default:
Abhijeet Kolekar1e680232009-03-17 21:51:50 -0700375 IWL_ERR(priv, "Unknown alg: %s alg = %d\n", __func__, keyconf->alg);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800376 ret = -EINVAL;
377 }
378
379 IWL_DEBUG_WEP(priv, "Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n",
380 keyconf->alg, keyconf->keylen, keyconf->keyidx,
381 sta_id, ret);
382
383 return ret;
384}
385
386static int iwl3945_remove_static_key(struct iwl_priv *priv)
387{
388 int ret = -EOPNOTSUPP;
389
390 return ret;
391}
392
393static int iwl3945_set_static_key(struct iwl_priv *priv,
394 struct ieee80211_key_conf *key)
395{
396 if (key->alg == ALG_WEP)
397 return -EOPNOTSUPP;
398
399 IWL_ERR(priv, "Static key invalid: alg %d\n", key->alg);
400 return -EINVAL;
401}
402
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800403static void iwl3945_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700404{
405 struct list_head *element;
406
Tomas Winklere1623442009-01-27 14:27:56 -0800407 IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
Zhu Yib481de92007-09-25 17:54:57 -0700408 priv->frames_count);
409
410 while (!list_empty(&priv->free_frames)) {
411 element = priv->free_frames.next;
412 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800413 kfree(list_entry(element, struct iwl3945_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700414 priv->frames_count--;
415 }
416
417 if (priv->frames_count) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800418 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
Zhu Yib481de92007-09-25 17:54:57 -0700419 priv->frames_count);
420 priv->frames_count = 0;
421 }
422}
423
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800424static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700425{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800426 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700427 struct list_head *element;
428 if (list_empty(&priv->free_frames)) {
429 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
430 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800431 IWL_ERR(priv, "Could not allocate frame!\n");
Zhu Yib481de92007-09-25 17:54:57 -0700432 return NULL;
433 }
434
435 priv->frames_count++;
436 return frame;
437 }
438
439 element = priv->free_frames.next;
440 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800441 return list_entry(element, struct iwl3945_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700442}
443
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800444static void iwl3945_free_frame(struct iwl_priv *priv, struct iwl3945_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700445{
446 memset(frame, 0, sizeof(*frame));
447 list_add(&frame->list, &priv->free_frames);
448}
449
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800450unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700451 struct ieee80211_hdr *hdr,
Rami Rosen73ec1cc2008-12-16 09:37:07 +0200452 int left)
Zhu Yib481de92007-09-25 17:54:57 -0700453{
454
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800455 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200456 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
457 (priv->iw_mode != NL80211_IFTYPE_AP)))
Zhu Yib481de92007-09-25 17:54:57 -0700458 return 0;
459
460 if (priv->ibss_beacon->len > left)
461 return 0;
462
463 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
464
465 return priv->ibss_beacon->len;
466}
467
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800468static int iwl3945_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700469{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800470 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700471 unsigned int frame_size;
472 int rc;
473 u8 rate;
474
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800475 frame = iwl3945_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700476
477 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800478 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
Zhu Yib481de92007-09-25 17:54:57 -0700479 "command.\n");
480 return -ENOMEM;
481 }
482
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800483 rate = iwl_rate_get_lowest_plcp(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700484
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800485 frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
Zhu Yib481de92007-09-25 17:54:57 -0700486
Samuel Ortiz518099a2009-01-19 15:30:27 -0800487 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -0700488 &frame->u.cmd[0]);
489
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800490 iwl3945_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -0700491
492 return rc;
493}
494
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800495static void iwl3945_unset_hw_params(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700496{
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800497 if (priv->shared_virt)
Zhu Yib481de92007-09-25 17:54:57 -0700498 pci_free_consistent(priv->pci_dev,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800499 sizeof(struct iwl3945_shared),
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800500 priv->shared_virt,
501 priv->shared_phys);
Zhu Yib481de92007-09-25 17:54:57 -0700502}
503
Zhu Yib481de92007-09-25 17:54:57 -0700504#define MAX_UCODE_BEACON_INTERVAL 1024
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -0800505#define INTEL_CONN_LISTEN_INTERVAL cpu_to_le16(0xA)
Zhu Yib481de92007-09-25 17:54:57 -0700506
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800507static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val)
Zhu Yib481de92007-09-25 17:54:57 -0700508{
509 u16 new_val = 0;
510 u16 beacon_factor = 0;
511
512 beacon_factor =
513 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
514 / MAX_UCODE_BEACON_INTERVAL;
515 new_val = beacon_val / beacon_factor;
516
517 return cpu_to_le16(new_val);
518}
519
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800520static void iwl3945_setup_rxon_timing(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700521{
522 u64 interval_tm_unit;
523 u64 tsf, result;
524 unsigned long flags;
525 struct ieee80211_conf *conf = NULL;
526 u16 beacon_int = 0;
527
528 conf = ieee80211_get_hw_conf(priv->hw);
529
530 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler28afaf92008-12-19 10:37:06 +0800531 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
Zhu Yib481de92007-09-25 17:54:57 -0700532 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
533
Tomas Winkler28afaf92008-12-19 10:37:06 +0800534 tsf = priv->timestamp;
Zhu Yib481de92007-09-25 17:54:57 -0700535
536 beacon_int = priv->beacon_int;
537 spin_unlock_irqrestore(&priv->lock, flags);
538
Johannes Berg05c914f2008-09-11 00:01:58 +0200539 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
Zhu Yib481de92007-09-25 17:54:57 -0700540 if (beacon_int == 0) {
541 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
542 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
543 } else {
544 priv->rxon_timing.beacon_interval =
545 cpu_to_le16(beacon_int);
546 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800547 iwl3945_adjust_beacon_interval(
Zhu Yib481de92007-09-25 17:54:57 -0700548 le16_to_cpu(priv->rxon_timing.beacon_interval));
549 }
550
551 priv->rxon_timing.atim_window = 0;
552 } else {
553 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800554 iwl3945_adjust_beacon_interval(conf->beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -0700555 /* TODO: we need to get atim_window from upper stack
556 * for now we set to 0 */
557 priv->rxon_timing.atim_window = 0;
558 }
559
560 interval_tm_unit =
561 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
562 result = do_div(tsf, interval_tm_unit);
563 priv->rxon_timing.beacon_init_val =
564 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
565
Tomas Winklere1623442009-01-27 14:27:56 -0800566 IWL_DEBUG_ASSOC(priv,
567 "beacon interval %d beacon timer %d beacon tim %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700568 le16_to_cpu(priv->rxon_timing.beacon_interval),
569 le32_to_cpu(priv->rxon_timing.beacon_init_val),
570 le16_to_cpu(priv->rxon_timing.atim_window));
571}
572
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800573static int iwl3945_set_mode(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -0700574{
Johannes Berg05c914f2008-09-11 00:01:58 +0200575 if (mode == NL80211_IFTYPE_ADHOC) {
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800576 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -0700577
Samuel Ortize6148912009-01-23 13:45:15 -0800578 ch_info = iwl_get_channel_info(priv,
Johannes Berg8318d782008-01-24 19:38:38 +0100579 priv->band,
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800580 le16_to_cpu(priv->staging_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700581
582 if (!ch_info || !is_channel_ibss(ch_info)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800583 IWL_ERR(priv, "channel %d not IBSS channel\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800584 le16_to_cpu(priv->staging_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700585 return -EINVAL;
586 }
587 }
588
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800589 iwl_connection_init_rx_config(priv, mode);
Zhu Yib481de92007-09-25 17:54:57 -0700590
Abhijeet Kolekar40ace5b2009-04-08 11:26:40 -0700591 priv->cfg->ops->smgmt->clear_station_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700592
Tomas Winklera96a27f2008-10-23 23:48:56 -0700593 /* don't commit rxon if rf-kill is on*/
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800594 if (!iwl_is_ready_rf(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +0800595 return -EAGAIN;
596
597 cancel_delayed_work(&priv->scan_check);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -0800598 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800599 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
Tomas Winklere1623442009-01-27 14:27:56 -0800600 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +0800601 return -EAGAIN;
602 }
603
Abhijeet Kolekare0158e62009-04-08 11:26:37 -0700604 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700605
606 return 0;
607}
608
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800609static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
Johannes Berge039fa42008-05-15 12:55:29 +0200610 struct ieee80211_tx_info *info,
Winkler, Tomasc2d79b482008-12-19 10:37:34 +0800611 struct iwl_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -0700612 struct sk_buff *skb_frag,
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800613 int sta_id)
Zhu Yib481de92007-09-25 17:54:57 -0700614{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800615 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
Ivo van Doorn1c014422008-04-17 19:41:02 +0200616 struct iwl3945_hw_key *keyinfo =
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800617 &priv->stations_39[sta_id].keyinfo;
Zhu Yib481de92007-09-25 17:54:57 -0700618
619 switch (keyinfo->alg) {
620 case ALG_CCMP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800621 tx->sec_ctl = TX_CMD_SEC_CCM;
622 memcpy(tx->key, keyinfo->key, keyinfo->keylen);
Tomas Winklere1623442009-01-27 14:27:56 -0800623 IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
Zhu Yib481de92007-09-25 17:54:57 -0700624 break;
625
626 case ALG_TKIP:
Zhu Yib481de92007-09-25 17:54:57 -0700627 break;
628
629 case ALG_WEP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800630 tx->sec_ctl = TX_CMD_SEC_WEP |
Johannes Berge039fa42008-05-15 12:55:29 +0200631 (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
Zhu Yib481de92007-09-25 17:54:57 -0700632
633 if (keyinfo->keylen == 13)
Winkler, Tomase52119c2008-12-22 11:31:19 +0800634 tx->sec_ctl |= TX_CMD_SEC_KEY128;
Zhu Yib481de92007-09-25 17:54:57 -0700635
Winkler, Tomase52119c2008-12-22 11:31:19 +0800636 memcpy(&tx->key[3], keyinfo->key, keyinfo->keylen);
Zhu Yib481de92007-09-25 17:54:57 -0700637
Tomas Winklere1623442009-01-27 14:27:56 -0800638 IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
Johannes Berge039fa42008-05-15 12:55:29 +0200639 "with key %d\n", info->control.hw_key->hw_key_idx);
Zhu Yib481de92007-09-25 17:54:57 -0700640 break;
641
Zhu Yib481de92007-09-25 17:54:57 -0700642 default:
Tomas Winkler978785a2008-12-19 10:37:31 +0800643 IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg);
Zhu Yib481de92007-09-25 17:54:57 -0700644 break;
645 }
646}
647
648/*
649 * handle build REPLY_TX command notification.
650 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800651static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
Winkler, Tomasc2d79b482008-12-19 10:37:34 +0800652 struct iwl_cmd *cmd,
Johannes Berge039fa42008-05-15 12:55:29 +0200653 struct ieee80211_tx_info *info,
Winkler, Tomase52119c2008-12-22 11:31:19 +0800654 struct ieee80211_hdr *hdr, u8 std_id)
Zhu Yib481de92007-09-25 17:54:57 -0700655{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800656 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
657 __le32 tx_flags = tx->tx_flags;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700658 __le16 fc = hdr->frame_control;
Johannes Berge6a98542008-10-21 12:40:02 +0200659 u8 rc_flags = info->control.rates[0].flags;
Zhu Yib481de92007-09-25 17:54:57 -0700660
Winkler, Tomase52119c2008-12-22 11:31:19 +0800661 tx->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
Johannes Berge039fa42008-05-15 12:55:29 +0200662 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
Zhu Yib481de92007-09-25 17:54:57 -0700663 tx_flags |= TX_CMD_FLG_ACK_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700664 if (ieee80211_is_mgmt(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700665 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700666 if (ieee80211_is_probe_resp(fc) &&
Zhu Yib481de92007-09-25 17:54:57 -0700667 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
668 tx_flags |= TX_CMD_FLG_TSF_MSK;
669 } else {
670 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
671 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
672 }
673
Winkler, Tomase52119c2008-12-22 11:31:19 +0800674 tx->sta_id = std_id;
Harvey Harrison8b7b1e02008-06-11 14:21:56 -0700675 if (ieee80211_has_morefrags(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700676 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
677
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700678 if (ieee80211_is_data_qos(fc)) {
679 u8 *qc = ieee80211_get_qos_ctl(hdr);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800680 tx->tid_tspec = qc[0] & 0xf;
Zhu Yib481de92007-09-25 17:54:57 -0700681 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800682 } else {
Zhu Yib481de92007-09-25 17:54:57 -0700683 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800684 }
Zhu Yib481de92007-09-25 17:54:57 -0700685
Johannes Berge6a98542008-10-21 12:40:02 +0200686 if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
Zhu Yib481de92007-09-25 17:54:57 -0700687 tx_flags |= TX_CMD_FLG_RTS_MSK;
688 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
Johannes Berge6a98542008-10-21 12:40:02 +0200689 } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
Zhu Yib481de92007-09-25 17:54:57 -0700690 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
691 tx_flags |= TX_CMD_FLG_CTS_MSK;
692 }
693
694 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
695 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
696
697 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700698 if (ieee80211_is_mgmt(fc)) {
699 if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
Winkler, Tomase52119c2008-12-22 11:31:19 +0800700 tx->timeout.pm_frame_timeout = cpu_to_le16(3);
Zhu Yib481de92007-09-25 17:54:57 -0700701 else
Winkler, Tomase52119c2008-12-22 11:31:19 +0800702 tx->timeout.pm_frame_timeout = cpu_to_le16(2);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700703 } else {
Winkler, Tomase52119c2008-12-22 11:31:19 +0800704 tx->timeout.pm_frame_timeout = 0;
Abhijeet Kolekar5c8df2d2009-03-11 11:17:55 -0700705#ifdef CONFIG_IWLWIFI_LEDS
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700706 priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
707#endif
708 }
Zhu Yib481de92007-09-25 17:54:57 -0700709
Winkler, Tomase52119c2008-12-22 11:31:19 +0800710 tx->driver_txop = 0;
711 tx->tx_flags = tx_flags;
712 tx->next_frame_len = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700713}
714
Zhu Yib481de92007-09-25 17:54:57 -0700715/*
716 * start REPLY_TX command process
717 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800718static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -0700719{
720 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berge039fa42008-05-15 12:55:29 +0200721 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800722 struct iwl3945_tx_cmd *tx;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800723 struct iwl_tx_queue *txq = NULL;
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800724 struct iwl_queue *q = NULL;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800725 struct iwl_cmd *out_cmd = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700726 dma_addr_t phys_addr;
727 dma_addr_t txcmd_phys;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800728 int txq_id = skb_get_queue_mapping(skb);
Tomas Winkler54dbb522008-05-15 13:54:06 +0800729 u16 len, idx, len_org, hdr_len;
730 u8 id;
731 u8 unicast;
Zhu Yib481de92007-09-25 17:54:57 -0700732 u8 sta_id;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800733 u8 tid = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700734 u16 seq_number = 0;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700735 __le16 fc;
Zhu Yib481de92007-09-25 17:54:57 -0700736 u8 wait_write_ptr = 0;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800737 u8 *qc = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700738 unsigned long flags;
739 int rc;
740
741 spin_lock_irqsave(&priv->lock, flags);
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800742 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800743 IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
Zhu Yib481de92007-09-25 17:54:57 -0700744 goto drop_unlock;
745 }
746
Johannes Berge039fa42008-05-15 12:55:29 +0200747 if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800748 IWL_ERR(priv, "ERROR: No TX rate available.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700749 goto drop_unlock;
750 }
751
752 unicast = !is_multicast_ether_addr(hdr->addr1);
753 id = 0;
754
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700755 fc = hdr->frame_control;
Zhu Yib481de92007-09-25 17:54:57 -0700756
Samuel Ortizd08853a2009-01-23 13:45:17 -0800757#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -0700758 if (ieee80211_is_auth(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800759 IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700760 else if (ieee80211_is_assoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800761 IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700762 else if (ieee80211_is_reassoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800763 IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
Zhu Yib481de92007-09-25 17:54:57 -0700764#endif
765
Mohamed Abbas7878a5a2007-11-29 11:10:13 +0800766 /* drop all data frame if we are not associated */
Stefanik Gábor914233d2008-06-30 17:23:30 +0800767 if (ieee80211_is_data(fc) &&
Johannes Berg05c914f2008-09-11 00:01:58 +0200768 (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800769 (!iwl_is_associated(priv) ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200770 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
Tomas Winklere1623442009-01-27 14:27:56 -0800771 IWL_DEBUG_DROP(priv, "Dropping - !iwl_is_associated\n");
Zhu Yib481de92007-09-25 17:54:57 -0700772 goto drop_unlock;
773 }
774
775 spin_unlock_irqrestore(&priv->lock, flags);
776
Harvey Harrison7294ec92008-07-15 18:43:59 -0700777 hdr_len = ieee80211_hdrlen(fc);
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800778
779 /* Find (or create) index into station table for destination station */
Abhijeet Kolekarf5d30262009-04-08 11:26:43 -0700780 sta_id = iwl_get_sta_id(priv, hdr);
Zhu Yib481de92007-09-25 17:54:57 -0700781 if (sta_id == IWL_INVALID_STATION) {
Tomas Winklere1623442009-01-27 14:27:56 -0800782 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -0700783 hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700784 goto drop;
785 }
786
Tomas Winklere1623442009-01-27 14:27:56 -0800787 IWL_DEBUG_RATE(priv, "station Id %d\n", sta_id);
Zhu Yib481de92007-09-25 17:54:57 -0700788
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700789 if (ieee80211_is_data_qos(fc)) {
790 qc = ieee80211_get_qos_ctl(hdr);
Harvey Harrison7294ec92008-07-15 18:43:59 -0700791 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800792 seq_number = priv->stations_39[sta_id].tid[tid].seq_number &
Zhu Yib481de92007-09-25 17:54:57 -0700793 IEEE80211_SCTL_SEQ;
794 hdr->seq_ctrl = cpu_to_le16(seq_number) |
795 (hdr->seq_ctrl &
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -0800796 cpu_to_le16(IEEE80211_SCTL_FRAG));
Zhu Yib481de92007-09-25 17:54:57 -0700797 seq_number += 0x10;
798 }
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800799
800 /* Descriptor for chosen Tx queue */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800801 txq = &priv->txq[txq_id];
Zhu Yib481de92007-09-25 17:54:57 -0700802 q = &txq->q;
803
804 spin_lock_irqsave(&priv->lock, flags);
805
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800806 idx = get_cmd_index(q, q->write_ptr, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700807
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800808 /* Set up driver data for this TFD */
Winkler, Tomasdbb66542008-12-22 11:31:14 +0800809 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800810 txq->txb[q->write_ptr].skb[0] = skb;
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800811
812 /* Init first empty entry in queue's array of Tx/cmd buffers */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800813 out_cmd = txq->cmd[idx];
Winkler, Tomase52119c2008-12-22 11:31:19 +0800814 tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload;
Zhu Yib481de92007-09-25 17:54:57 -0700815 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
Winkler, Tomase52119c2008-12-22 11:31:19 +0800816 memset(tx, 0, sizeof(*tx));
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800817
818 /*
819 * Set up the Tx-command (not MAC!) header.
820 * Store the chosen Tx queue and TFD index within the sequence field;
821 * after Tx, uCode's Tx response will return this value so driver can
822 * locate the frame within the tx queue and do post-tx processing.
823 */
Zhu Yib481de92007-09-25 17:54:57 -0700824 out_cmd->hdr.cmd = REPLY_TX;
825 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800826 INDEX_TO_SEQ(q->write_ptr)));
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800827
828 /* Copy MAC header from skb into command buffer */
Winkler, Tomase52119c2008-12-22 11:31:19 +0800829 memcpy(tx->hdr, hdr, hdr_len);
Zhu Yib481de92007-09-25 17:54:57 -0700830
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800831 /*
832 * Use the first empty entry in this queue's command buffer array
833 * to contain the Tx command and MAC header concatenated together
834 * (payload data will be in another buffer).
835 * Size of this varies, due to varying MAC header length.
836 * If end is not dword aligned, we'll have 2 extra bytes at the end
837 * of the MAC header (device reads on dword boundaries).
838 * We'll tell device about this padding later.
839 */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800840 len = sizeof(struct iwl3945_tx_cmd) +
Tomas Winkler4c897252008-12-19 10:37:05 +0800841 sizeof(struct iwl_cmd_header) + hdr_len;
Zhu Yib481de92007-09-25 17:54:57 -0700842
843 len_org = len;
844 len = (len + 3) & ~3;
845
846 if (len_org != len)
847 len_org = 1;
848 else
849 len_org = 0;
850
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800851 /* Physical address of this Tx command's header (not MAC header!),
852 * within command buffer array. */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800853 txcmd_phys = pci_map_single(priv->pci_dev,
854 out_cmd, sizeof(struct iwl_cmd),
855 PCI_DMA_TODEVICE);
856 pci_unmap_addr_set(&out_cmd->meta, mapping, txcmd_phys);
857 pci_unmap_len_set(&out_cmd->meta, len, sizeof(struct iwl_cmd));
858 /* Add buffer containing Tx command and MAC(!) header to TFD's
859 * first entry */
860 txcmd_phys += offsetof(struct iwl_cmd, hdr);
Zhu Yib481de92007-09-25 17:54:57 -0700861
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800862 /* Add buffer containing Tx command and MAC(!) header to TFD's
863 * first entry */
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800864 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
865 txcmd_phys, len, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700866
Johannes Bergd0f09802008-07-29 11:32:07 +0200867 if (info->control.hw_key)
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800868 iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, sta_id);
Zhu Yib481de92007-09-25 17:54:57 -0700869
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800870 /* Set up TFD's 2nd entry to point directly to remainder of skb,
871 * if any (802.11 null frames have no payload). */
Zhu Yib481de92007-09-25 17:54:57 -0700872 len = skb->len - hdr_len;
873 if (len) {
874 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
875 len, PCI_DMA_TODEVICE);
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800876 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
877 phys_addr, len,
878 0, U32_PAD(len));
Zhu Yib481de92007-09-25 17:54:57 -0700879 }
880
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800881 /* Total # bytes to be transmitted */
Zhu Yib481de92007-09-25 17:54:57 -0700882 len = (u16)skb->len;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800883 tx->len = cpu_to_le16(len);
Zhu Yib481de92007-09-25 17:54:57 -0700884
885 /* TODO need this for burst mode later on */
Winkler, Tomase52119c2008-12-22 11:31:19 +0800886 iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id);
Zhu Yib481de92007-09-25 17:54:57 -0700887
888 /* set is_hcca to 0; it probably will never be implemented */
Johannes Berge039fa42008-05-15 12:55:29 +0200889 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700890
Winkler, Tomase52119c2008-12-22 11:31:19 +0800891 tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
892 tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700893
Harvey Harrison8b7b1e02008-06-11 14:21:56 -0700894 if (!ieee80211_has_morefrags(hdr->frame_control)) {
Zhu Yib481de92007-09-25 17:54:57 -0700895 txq->need_update = 1;
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300896 if (qc)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800897 priv->stations_39[sta_id].tid[tid].seq_number = seq_number;
Zhu Yib481de92007-09-25 17:54:57 -0700898 } else {
899 wait_write_ptr = 1;
900 txq->need_update = 0;
901 }
902
Winkler, Tomase52119c2008-12-22 11:31:19 +0800903 iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx));
Zhu Yib481de92007-09-25 17:54:57 -0700904
Winkler, Tomase52119c2008-12-22 11:31:19 +0800905 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr,
Harvey Harrison7294ec92008-07-15 18:43:59 -0700906 ieee80211_hdrlen(fc));
Zhu Yib481de92007-09-25 17:54:57 -0700907
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800908 /* Tell device the write index *just past* this latest filled TFD */
Tomas Winklerc54b6792008-03-06 17:36:53 -0800909 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -0800910 rc = iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -0700911 spin_unlock_irqrestore(&priv->lock, flags);
912
913 if (rc)
914 return rc;
915
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800916 if ((iwl_queue_space(q) < q->high_mark)
Zhu Yib481de92007-09-25 17:54:57 -0700917 && priv->mac80211_registered) {
918 if (wait_write_ptr) {
919 spin_lock_irqsave(&priv->lock, flags);
920 txq->need_update = 1;
Samuel Ortiz4f3602c2009-01-19 15:30:25 -0800921 iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -0700922 spin_unlock_irqrestore(&priv->lock, flags);
923 }
924
Johannes Berge4e72fb2009-03-23 17:28:42 +0100925 iwl_stop_queue(priv, skb_get_queue_mapping(skb));
Zhu Yib481de92007-09-25 17:54:57 -0700926 }
927
928 return 0;
929
930drop_unlock:
931 spin_unlock_irqrestore(&priv->lock, flags);
932drop:
933 return -1;
934}
935
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800936#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -0700937
938#include "iwl-spectrum.h"
939
940#define BEACON_TIME_MASK_LOW 0x00FFFFFF
941#define BEACON_TIME_MASK_HIGH 0xFF000000
942#define TIME_UNIT 1024
943
944/*
945 * extended beacon time format
946 * time in usec will be changed into a 32-bit value in 8:24 format
947 * the high 1 byte is the beacon counts
948 * the lower 3 bytes is the time in usec within one beacon interval
949 */
950
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800951static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -0700952{
953 u32 quot;
954 u32 rem;
955 u32 interval = beacon_interval * 1024;
956
957 if (!interval || !usec)
958 return 0;
959
960 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
961 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
962
963 return (quot << 24) + rem;
964}
965
966/* base is usually what we get from ucode with each received frame,
967 * the same as HW timer counter counting down
968 */
969
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800970static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -0700971{
972 u32 base_low = base & BEACON_TIME_MASK_LOW;
973 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
974 u32 interval = beacon_interval * TIME_UNIT;
975 u32 res = (base & BEACON_TIME_MASK_HIGH) +
976 (addon & BEACON_TIME_MASK_HIGH);
977
978 if (base_low > addon_low)
979 res += base_low - addon_low;
980 else if (base_low < addon_low) {
981 res += interval + base_low - addon_low;
982 res += (1 << 24);
983 } else
984 res += (1 << 24);
985
986 return cpu_to_le32(res);
987}
988
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800989static int iwl3945_get_measurement(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700990 struct ieee80211_measurement_params *params,
991 u8 type)
992{
Tomas Winkler600c0e12008-12-19 10:37:04 +0800993 struct iwl_spectrum_cmd spectrum;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800994 struct iwl_rx_packet *res;
Winkler, Tomasc2d79b482008-12-19 10:37:34 +0800995 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700996 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
997 .data = (void *)&spectrum,
998 .meta.flags = CMD_WANT_SKB,
999 };
1000 u32 add_time = le64_to_cpu(params->start_time);
1001 int rc;
1002 int spectrum_resp_status;
1003 int duration = le16_to_cpu(params->duration);
1004
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001005 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001006 add_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001007 iwl3945_usecs_to_beacons(
Zhu Yib481de92007-09-25 17:54:57 -07001008 le64_to_cpu(params->start_time) - priv->last_tsf,
1009 le16_to_cpu(priv->rxon_timing.beacon_interval));
1010
1011 memset(&spectrum, 0, sizeof(spectrum));
1012
1013 spectrum.channel_count = cpu_to_le16(1);
1014 spectrum.flags =
1015 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
1016 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
1017 cmd.len = sizeof(spectrum);
1018 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
1019
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001020 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001021 spectrum.start_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001022 iwl3945_add_beacon_time(priv->last_beacon_time,
Zhu Yib481de92007-09-25 17:54:57 -07001023 add_time,
1024 le16_to_cpu(priv->rxon_timing.beacon_interval));
1025 else
1026 spectrum.start_time = 0;
1027
1028 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
1029 spectrum.channels[0].channel = params->channel;
1030 spectrum.channels[0].type = type;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001031 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
Zhu Yib481de92007-09-25 17:54:57 -07001032 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
1033 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
1034
Samuel Ortiz518099a2009-01-19 15:30:27 -08001035 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001036 if (rc)
1037 return rc;
1038
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001039 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001040 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001041 IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -07001042 rc = -EIO;
1043 }
1044
1045 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
1046 switch (spectrum_resp_status) {
1047 case 0: /* Command will be handled */
1048 if (res->u.spectrum.id != 0xff) {
Tomas Winklere1623442009-01-27 14:27:56 -08001049 IWL_DEBUG_INFO(priv, "Replaced existing measurement: %d\n",
Ian Schrambc434dd2007-10-25 17:15:29 +08001050 res->u.spectrum.id);
Zhu Yib481de92007-09-25 17:54:57 -07001051 priv->measurement_status &= ~MEASUREMENT_READY;
1052 }
1053 priv->measurement_status |= MEASUREMENT_ACTIVE;
1054 rc = 0;
1055 break;
1056
1057 case 1: /* Command will not be handled */
1058 rc = -EAGAIN;
1059 break;
1060 }
1061
1062 dev_kfree_skb_any(cmd.meta.u.skb);
1063
1064 return rc;
1065}
1066#endif
1067
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001068static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001069 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001070{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001071 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
1072 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -07001073 struct delayed_work *pwork;
1074
1075 palive = &pkt->u.alive_frame;
1076
Tomas Winklere1623442009-01-27 14:27:56 -08001077 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
Zhu Yib481de92007-09-25 17:54:57 -07001078 "0x%01X 0x%01X\n",
1079 palive->is_valid, palive->ver_type,
1080 palive->ver_subtype);
1081
1082 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
Tomas Winklere1623442009-01-27 14:27:56 -08001083 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001084 memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
1085 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001086 pwork = &priv->init_alive_start;
1087 } else {
Tomas Winklere1623442009-01-27 14:27:56 -08001088 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001089 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001090 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001091 pwork = &priv->alive_start;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001092 iwl3945_disable_events(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001093 }
1094
1095 /* We delay the ALIVE response by 5ms to
1096 * give the HW RF Kill time to activate... */
1097 if (palive->is_valid == UCODE_VALID_OK)
1098 queue_delayed_work(priv->workqueue, pwork,
1099 msecs_to_jiffies(5));
1100 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001101 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001102}
1103
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001104static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001105 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001106{
Helmut Schaac7e035a2009-01-19 13:02:15 +01001107#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001108 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Helmut Schaac7e035a2009-01-19 13:02:15 +01001109#endif
Zhu Yib481de92007-09-25 17:54:57 -07001110
Tomas Winklere1623442009-01-27 14:27:56 -08001111 IWL_DEBUG_RX(priv, "Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
Zhu Yib481de92007-09-25 17:54:57 -07001112 return;
1113}
1114
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001115static void iwl3945_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07001116{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001117 struct iwl_priv *priv =
1118 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07001119 struct sk_buff *beacon;
1120
1121 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +02001122 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -07001123
1124 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001125 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07001126 return;
1127 }
1128
1129 mutex_lock(&priv->mutex);
1130 /* new beacon skb is allocated every time; dispose previous.*/
1131 if (priv->ibss_beacon)
1132 dev_kfree_skb(priv->ibss_beacon);
1133
1134 priv->ibss_beacon = beacon;
1135 mutex_unlock(&priv->mutex);
1136
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001137 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001138}
1139
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001140static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001141 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001142{
Samuel Ortizd08853a2009-01-23 13:45:17 -08001143#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001144 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001145 struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
Zhu Yib481de92007-09-25 17:54:57 -07001146 u8 rate = beacon->beacon_notify_hdr.rate;
1147
Tomas Winklere1623442009-01-27 14:27:56 -08001148 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
Zhu Yib481de92007-09-25 17:54:57 -07001149 "tsf %d %d rate %d\n",
1150 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
1151 beacon->beacon_notify_hdr.failure_frame,
1152 le32_to_cpu(beacon->ibss_mgr_status),
1153 le32_to_cpu(beacon->high_tsf),
1154 le32_to_cpu(beacon->low_tsf), rate);
1155#endif
1156
Johannes Berg05c914f2008-09-11 00:01:58 +02001157 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -07001158 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
1159 queue_work(priv->workqueue, &priv->beacon_update);
1160}
1161
Zhu Yib481de92007-09-25 17:54:57 -07001162/* Handle notification from uCode that card's power state is changing
1163 * due to software, hardware, or critical temperature RFKILL */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001164static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001165 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001166{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001167 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001168 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
1169 unsigned long status = priv->status;
1170
Tomas Winklere1623442009-01-27 14:27:56 -08001171 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s\n",
Zhu Yib481de92007-09-25 17:54:57 -07001172 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1173 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
1174
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001175 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001176 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1177
1178 if (flags & HW_CARD_DISABLED)
1179 set_bit(STATUS_RF_KILL_HW, &priv->status);
1180 else
1181 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1182
1183
1184 if (flags & SW_CARD_DISABLED)
1185 set_bit(STATUS_RF_KILL_SW, &priv->status);
1186 else
1187 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1188
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08001189 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001190
1191 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
1192 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
1193 (test_bit(STATUS_RF_KILL_SW, &status) !=
1194 test_bit(STATUS_RF_KILL_SW, &priv->status)))
1195 queue_work(priv->workqueue, &priv->rf_kill);
1196 else
1197 wake_up_interruptible(&priv->wait_command_queue);
1198}
1199
1200/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001201 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07001202 *
1203 * Setup the RX handlers for each of the reply types sent from the uCode
1204 * to the host.
1205 *
1206 * This function chains into the hardware specific files for them to setup
1207 * any hardware specific handlers as well.
1208 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001209static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001210{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001211 priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
1212 priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
Abhijeet Kolekar261b9c32009-02-18 15:54:29 -08001213 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001214 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -08001215 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001216 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -08001217 iwl_rx_pm_debug_statistics_notif;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001218 priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001219
Ben Cahill9fbab512007-11-29 11:09:47 +08001220 /*
1221 * The same handler is used for both the REPLY to a discrete
1222 * statistics request from the host as well as for the periodic
1223 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07001224 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001225 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
1226 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
Zhu Yib481de92007-09-25 17:54:57 -07001227
Abhijeet Kolekar261b9c32009-02-18 15:54:29 -08001228 iwl_setup_spectrum_handlers(priv);
Abhijeet Kolekarcade0eb2009-02-18 15:54:26 -08001229 iwl_setup_rx_scan_handlers(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001230 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001231
Ben Cahill9fbab512007-11-29 11:09:47 +08001232 /* Set up hardware specific Rx handlers */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001233 iwl3945_hw_rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001234}
1235
Zhu Yib481de92007-09-25 17:54:57 -07001236/************************** RX-FUNCTIONS ****************************/
1237/*
1238 * Rx theory of operation
1239 *
1240 * The host allocates 32 DMA target addresses and passes the host address
1241 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
1242 * 0 to 31
1243 *
1244 * Rx Queue Indexes
1245 * The host/firmware share two index registers for managing the Rx buffers.
1246 *
1247 * The READ index maps to the first position that the firmware may be writing
1248 * to -- the driver can read up to (but not including) this position and get
1249 * good data.
1250 * The READ index is managed by the firmware once the card is enabled.
1251 *
1252 * The WRITE index maps to the last position the driver has read from -- the
1253 * position preceding WRITE is the last slot the firmware can place a packet.
1254 *
1255 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
1256 * WRITE = READ.
1257 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001258 * During initialization, the host sets up the READ queue position to the first
Zhu Yib481de92007-09-25 17:54:57 -07001259 * INDEX position, and WRITE to the last (READ - 1 wrapped)
1260 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001261 * When the firmware places a packet in a buffer, it will advance the READ index
Zhu Yib481de92007-09-25 17:54:57 -07001262 * and fire the RX interrupt. The driver can then query the READ index and
1263 * process as many packets as possible, moving the WRITE index forward as it
1264 * resets the Rx queue buffers with new memory.
1265 *
1266 * The management in the driver is as follows:
1267 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
1268 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Ian Schram01ebd062007-10-25 17:15:22 +08001269 * to replenish the iwl->rxq->rx_free.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001270 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
Zhu Yib481de92007-09-25 17:54:57 -07001271 * iwl->rxq is replenished and the READ INDEX is updated (updating the
1272 * 'processed' and 'read' driver indexes as well)
1273 * + A received packet is processed and handed to the kernel network stack,
1274 * detached from the iwl->rxq. The driver 'processed' index is updated.
1275 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
1276 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
1277 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
1278 * were enough free buffers and RX_STALLED is set it is cleared.
1279 *
1280 *
1281 * Driver sequence:
1282 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001283 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001284 * iwl3945_rx_queue_restock
Ben Cahill9fbab512007-11-29 11:09:47 +08001285 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
Zhu Yib481de92007-09-25 17:54:57 -07001286 * queue, updates firmware pointers, and updates
1287 * the WRITE index. If insufficient rx_free buffers
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001288 * are available, schedules iwl3945_rx_replenish
Zhu Yib481de92007-09-25 17:54:57 -07001289 *
1290 * -- enable interrupts --
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001291 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
Zhu Yib481de92007-09-25 17:54:57 -07001292 * READ INDEX, detaching the SKB from the pool.
1293 * Moves the packet buffer from queue to rx_used.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001294 * Calls iwl3945_rx_queue_restock to refill any empty
Zhu Yib481de92007-09-25 17:54:57 -07001295 * slots.
1296 * ...
1297 *
1298 */
1299
1300/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001301 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
Zhu Yib481de92007-09-25 17:54:57 -07001302 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001303static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001304 dma_addr_t dma_addr)
1305{
1306 return cpu_to_le32((u32)dma_addr);
1307}
1308
1309/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001310 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
Zhu Yib481de92007-09-25 17:54:57 -07001311 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001312 * If there are slots in the RX queue that need to be restocked,
Zhu Yib481de92007-09-25 17:54:57 -07001313 * and we have free pre-allocated buffers, fill the ranks as much
Ben Cahill9fbab512007-11-29 11:09:47 +08001314 * as we can, pulling from rx_free.
Zhu Yib481de92007-09-25 17:54:57 -07001315 *
1316 * This moves the 'write' index forward to catch up with 'processed', and
1317 * also updates the memory address in the firmware to reference the new
1318 * target buffer.
1319 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001320static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001321{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001322 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001323 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001324 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001325 unsigned long flags;
1326 int write, rc;
1327
1328 spin_lock_irqsave(&rxq->lock, flags);
1329 write = rxq->write & ~0x7;
Winkler, Tomas37d68312009-01-08 10:19:54 -08001330 while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001331 /* Get next free Rx buffer, remove from free list */
Zhu Yib481de92007-09-25 17:54:57 -07001332 element = rxq->rx_free.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001333 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Zhu Yib481de92007-09-25 17:54:57 -07001334 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001335
1336 /* Point to Rx buffer via next RBD in circular buffer */
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001337 rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr);
Zhu Yib481de92007-09-25 17:54:57 -07001338 rxq->queue[rxq->write] = rxb;
1339 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
1340 rxq->free_count--;
1341 }
1342 spin_unlock_irqrestore(&rxq->lock, flags);
1343 /* If the pre-allocated buffer pool is dropping low, schedule to
1344 * refill it */
1345 if (rxq->free_count <= RX_LOW_WATERMARK)
1346 queue_work(priv->workqueue, &priv->rx_replenish);
1347
1348
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001349 /* If we've added more space for the firmware to place data, tell it.
1350 * Increment device's write pointer in multiples of 8. */
Zhu Yib481de92007-09-25 17:54:57 -07001351 if ((write != (rxq->write & ~0x7))
1352 || (abs(rxq->write - rxq->read) > 7)) {
1353 spin_lock_irqsave(&rxq->lock, flags);
1354 rxq->need_update = 1;
1355 spin_unlock_irqrestore(&rxq->lock, flags);
Winkler, Tomas141c43a2009-01-08 10:19:53 -08001356 rc = iwl_rx_queue_update_write_ptr(priv, rxq);
Zhu Yib481de92007-09-25 17:54:57 -07001357 if (rc)
1358 return rc;
1359 }
1360
1361 return 0;
1362}
1363
1364/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001365 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
Zhu Yib481de92007-09-25 17:54:57 -07001366 *
1367 * When moving to rx_free an SKB is allocated for the slot.
1368 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001369 * Also restock the Rx queue via iwl3945_rx_queue_restock.
Ian Schram01ebd062007-10-25 17:15:22 +08001370 * This is called as a scheduled work item (except for during initialization)
Zhu Yib481de92007-09-25 17:54:57 -07001371 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001372static void iwl3945_rx_allocate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001373{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001374 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001375 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001376 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001377 unsigned long flags;
1378 spin_lock_irqsave(&rxq->lock, flags);
1379 while (!list_empty(&rxq->rx_used)) {
1380 element = rxq->rx_used.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001381 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001382
1383 /* Alloc a new receive buffer */
Zhu Yib481de92007-09-25 17:54:57 -07001384 rxb->skb =
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001385 alloc_skb(priv->hw_params.rx_buf_size,
1386 __GFP_NOWARN | GFP_ATOMIC);
Zhu Yib481de92007-09-25 17:54:57 -07001387 if (!rxb->skb) {
1388 if (net_ratelimit())
Tomas Winkler978785a2008-12-19 10:37:31 +08001389 IWL_CRIT(priv, ": Can not allocate SKB buffers\n");
Zhu Yib481de92007-09-25 17:54:57 -07001390 /* We don't reschedule replenish work here -- we will
1391 * call the restock method and if it still needs
1392 * more buffers it will schedule replenish */
1393 break;
1394 }
Zhu Yi12342c42007-12-20 11:27:32 +08001395
1396 /* If radiotap head is required, reserve some headroom here.
1397 * The physical head count is a variable rx_stats->phy_count.
1398 * We reserve 4 bytes here. Plus these extra bytes, the
1399 * headroom of the physical head should be enough for the
1400 * radiotap head that iwl3945 supported. See iwl3945_rt.
1401 */
1402 skb_reserve(rxb->skb, 4);
1403
Zhu Yib481de92007-09-25 17:54:57 -07001404 priv->alloc_rxb_skb++;
1405 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001406
1407 /* Get physical address of RB/SKB */
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001408 rxb->real_dma_addr = pci_map_single(priv->pci_dev,
1409 rxb->skb->data,
1410 priv->hw_params.rx_buf_size,
1411 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001412 list_add_tail(&rxb->list, &rxq->rx_free);
1413 rxq->free_count++;
1414 }
1415 spin_unlock_irqrestore(&rxq->lock, flags);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001416}
1417
1418/*
1419 * this should be called while priv->lock is locked
1420 */
Tomas Winkler4fd1f842007-12-05 20:59:58 +02001421static void __iwl3945_rx_replenish(void *data)
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001422{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001423 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001424
1425 iwl3945_rx_allocate(priv);
1426 iwl3945_rx_queue_restock(priv);
1427}
1428
1429
1430void iwl3945_rx_replenish(void *data)
1431{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001432 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001433 unsigned long flags;
1434
1435 iwl3945_rx_allocate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001436
1437 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001438 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001439 spin_unlock_irqrestore(&priv->lock, flags);
1440}
1441
Zhu Yib481de92007-09-25 17:54:57 -07001442/* Convert linear signal-to-noise ratio into dB */
1443static u8 ratio2dB[100] = {
1444/* 0 1 2 3 4 5 6 7 8 9 */
1445 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
1446 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
1447 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
1448 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
1449 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
1450 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
1451 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
1452 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
1453 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
1454 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
1455};
1456
1457/* Calculates a relative dB value from a ratio of linear
1458 * (i.e. not dB) signal levels.
1459 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001460int iwl3945_calc_db_from_ratio(int sig_ratio)
Zhu Yib481de92007-09-25 17:54:57 -07001461{
Adrian Bunk221c80c2008-02-02 23:19:01 +02001462 /* 1000:1 or higher just report as 60 dB */
1463 if (sig_ratio >= 1000)
Zhu Yib481de92007-09-25 17:54:57 -07001464 return 60;
1465
Adrian Bunk221c80c2008-02-02 23:19:01 +02001466 /* 100:1 or higher, divide by 10 and use table,
Zhu Yib481de92007-09-25 17:54:57 -07001467 * add 20 dB to make up for divide by 10 */
Adrian Bunk221c80c2008-02-02 23:19:01 +02001468 if (sig_ratio >= 100)
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001469 return 20 + (int)ratio2dB[sig_ratio/10];
Zhu Yib481de92007-09-25 17:54:57 -07001470
1471 /* We shouldn't see this */
1472 if (sig_ratio < 1)
1473 return 0;
1474
1475 /* Use table for ratios 1:1 - 99:1 */
1476 return (int)ratio2dB[sig_ratio];
1477}
1478
1479#define PERFECT_RSSI (-20) /* dBm */
1480#define WORST_RSSI (-95) /* dBm */
1481#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
1482
1483/* Calculate an indication of rx signal quality (a percentage, not dBm!).
1484 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
1485 * about formulas used below. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001486int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
Zhu Yib481de92007-09-25 17:54:57 -07001487{
1488 int sig_qual;
1489 int degradation = PERFECT_RSSI - rssi_dbm;
1490
1491 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
1492 * as indicator; formula is (signal dbm - noise dbm).
1493 * SNR at or above 40 is a great signal (100%).
1494 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
1495 * Weakest usable signal is usually 10 - 15 dB SNR. */
1496 if (noise_dbm) {
1497 if (rssi_dbm - noise_dbm >= 40)
1498 return 100;
1499 else if (rssi_dbm < noise_dbm)
1500 return 0;
1501 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
1502
1503 /* Else use just the signal level.
1504 * This formula is a least squares fit of data points collected and
1505 * compared with a reference system that had a percentage (%) display
1506 * for signal quality. */
1507 } else
1508 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
1509 (15 * RSSI_RANGE + 62 * degradation)) /
1510 (RSSI_RANGE * RSSI_RANGE);
1511
1512 if (sig_qual > 100)
1513 sig_qual = 100;
1514 else if (sig_qual < 1)
1515 sig_qual = 0;
1516
1517 return sig_qual;
1518}
1519
1520/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001521 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07001522 *
1523 * Uses the priv->rx_handlers callback function array to invoke
1524 * the appropriate handlers, including command responses,
1525 * frame-received notifications, and other notifications.
1526 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001527static void iwl3945_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001528{
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001529 struct iwl_rx_mem_buffer *rxb;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001530 struct iwl_rx_packet *pkt;
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001531 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001532 u32 r, i;
1533 int reclaim;
1534 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001535 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08001536 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07001537
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001538 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1539 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8cd812b2008-12-19 10:37:43 +08001540 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -07001541 i = rxq->read;
1542
Winkler, Tomas37d68312009-01-08 10:19:54 -08001543 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001544 fill_rx = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001545 /* Rx interrupt, but nothing sent from uCode */
1546 if (i == r)
Tomas Winklere1623442009-01-27 14:27:56 -08001547 IWL_DEBUG(priv, IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07001548
1549 while (i != r) {
1550 rxb = rxq->queue[i];
1551
Ben Cahill9fbab512007-11-29 11:09:47 +08001552 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07001553 * then a bug has been introduced in the queue refilling
1554 * routines -- catch it here */
1555 BUG_ON(rxb == NULL);
1556
1557 rxq->queue[i] = NULL;
1558
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001559 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001560 priv->hw_params.rx_buf_size,
Zhu Yib481de92007-09-25 17:54:57 -07001561 PCI_DMA_FROMDEVICE);
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001562 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001563
1564 /* Reclaim a command buffer only if this packet is a response
1565 * to a (driver-originated) command.
1566 * If the packet (e.g. Rx frame) originated from uCode,
1567 * there is no command buffer to reclaim.
1568 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1569 * but apparently a few don't get set; catch them here. */
1570 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1571 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1572 (pkt->hdr.cmd != REPLY_TX);
1573
1574 /* Based on type of command response or notification,
1575 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001576 * rx_handlers table. See iwl3945_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07001577 if (priv->rx_handlers[pkt->hdr.cmd]) {
Tomas Winklere1623442009-01-27 14:27:56 -08001578 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07001579 "r = %d, i = %d, %s, 0x%02x\n", r, i,
1580 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
1581 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
1582 } else {
1583 /* No handling needed */
Tomas Winklere1623442009-01-27 14:27:56 -08001584 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07001585 "r %d i %d No handler needed for %s, 0x%02x\n",
1586 r, i, get_cmd_string(pkt->hdr.cmd),
1587 pkt->hdr.cmd);
1588 }
1589
1590 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001591 /* Invoke any callbacks, transfer the skb to caller, and
Samuel Ortiz518099a2009-01-19 15:30:27 -08001592 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07001593 * as we reclaim the driver command queue */
1594 if (rxb && rxb->skb)
Abhijeet Kolekar732587a2009-03-11 11:17:57 -07001595 iwl_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001596 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001597 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07001598 }
1599
1600 /* For now we just don't re-use anything. We can tweak this
1601 * later to try and re-use notification packets and SKBs that
1602 * fail to Rx correctly */
1603 if (rxb->skb != NULL) {
1604 priv->alloc_rxb_skb--;
1605 dev_kfree_skb_any(rxb->skb);
1606 rxb->skb = NULL;
1607 }
1608
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001609 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001610 priv->hw_params.rx_buf_size,
1611 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001612 spin_lock_irqsave(&rxq->lock, flags);
1613 list_add_tail(&rxb->list, &priv->rxq.rx_used);
1614 spin_unlock_irqrestore(&rxq->lock, flags);
1615 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001616 /* If there are a lot of unused frames,
1617 * restock the Rx queue so ucode won't assert. */
1618 if (fill_rx) {
1619 count++;
1620 if (count >= 8) {
1621 priv->rxq.read = i;
1622 __iwl3945_rx_replenish(priv);
1623 count = 0;
1624 }
1625 }
Zhu Yib481de92007-09-25 17:54:57 -07001626 }
1627
1628 /* Backtrack one entry */
1629 priv->rxq.read = i;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001630 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001631}
1632
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001633/* call this function to flush any scheduled tasklet */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001634static inline void iwl_synchronize_irq(struct iwl_priv *priv)
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001635{
Tomas Winklera96a27f2008-10-23 23:48:56 -07001636 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001637 synchronize_irq(priv->pci_dev->irq);
1638 tasklet_kill(&priv->irq_tasklet);
1639}
1640
Zhu Yib481de92007-09-25 17:54:57 -07001641static const char *desc_lookup(int i)
1642{
1643 switch (i) {
1644 case 1:
1645 return "FAIL";
1646 case 2:
1647 return "BAD_PARAM";
1648 case 3:
1649 return "BAD_CHECKSUM";
1650 case 4:
1651 return "NMI_INTERRUPT";
1652 case 5:
1653 return "SYSASSERT";
1654 case 6:
1655 return "FATAL_ERROR";
1656 }
1657
1658 return "UNKNOWN";
1659}
1660
1661#define ERROR_START_OFFSET (1 * sizeof(u32))
1662#define ERROR_ELEM_SIZE (7 * sizeof(u32))
1663
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001664static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001665{
1666 u32 i;
1667 u32 desc, time, count, base, data1;
1668 u32 blink1, blink2, ilink1, ilink2;
1669 int rc;
1670
1671 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
1672
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001673 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001674 IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07001675 return;
1676 }
1677
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001678 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001679 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001680 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001681 return;
1682 }
1683
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001684 count = iwl_read_targ_mem(priv, base);
Zhu Yib481de92007-09-25 17:54:57 -07001685
1686 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001687 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
1688 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
1689 priv->status, count);
Zhu Yib481de92007-09-25 17:54:57 -07001690 }
1691
Winkler, Tomas15b16872008-12-19 10:37:33 +08001692 IWL_ERR(priv, "Desc Time asrtPC blink2 "
Zhu Yib481de92007-09-25 17:54:57 -07001693 "ilink1 nmiPC Line\n");
1694 for (i = ERROR_START_OFFSET;
1695 i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
1696 i += ERROR_ELEM_SIZE) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001697 desc = iwl_read_targ_mem(priv, base + i);
Zhu Yib481de92007-09-25 17:54:57 -07001698 time =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001699 iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001700 blink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001701 iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001702 blink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001703 iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001704 ilink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001705 iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001706 ilink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001707 iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001708 data1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001709 iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001710
Winkler, Tomas15b16872008-12-19 10:37:33 +08001711 IWL_ERR(priv,
1712 "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
1713 desc_lookup(desc), desc, time, blink1, blink2,
1714 ilink1, ilink2, data1);
Zhu Yib481de92007-09-25 17:54:57 -07001715 }
1716
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001717 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001718
1719}
1720
Ben Cahillf58177b2007-11-29 11:09:43 +08001721#define EVENT_START_OFFSET (6 * sizeof(u32))
Zhu Yib481de92007-09-25 17:54:57 -07001722
1723/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001724 * iwl3945_print_event_log - Dump error event log to syslog
Zhu Yib481de92007-09-25 17:54:57 -07001725 *
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001726 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
Zhu Yib481de92007-09-25 17:54:57 -07001727 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001728static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
Zhu Yib481de92007-09-25 17:54:57 -07001729 u32 num_events, u32 mode)
1730{
1731 u32 i;
1732 u32 base; /* SRAM byte address of event log header */
1733 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
1734 u32 ptr; /* SRAM byte address of log data */
1735 u32 ev, time, data; /* event log data */
1736
1737 if (num_events == 0)
1738 return;
1739
1740 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
1741
1742 if (mode == 0)
1743 event_size = 2 * sizeof(u32);
1744 else
1745 event_size = 3 * sizeof(u32);
1746
1747 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
1748
1749 /* "time" is actually "data" for mode 0 (no timestamp).
1750 * place event id # at far right for easier visual parsing. */
1751 for (i = 0; i < num_events; i++) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001752 ev = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07001753 ptr += sizeof(u32);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001754 time = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07001755 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08001756 if (mode == 0) {
1757 /* data, ev */
1758 IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
1759 } else {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001760 data = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07001761 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08001762 IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev);
Zhu Yib481de92007-09-25 17:54:57 -07001763 }
1764 }
1765}
1766
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001767static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001768{
1769 int rc;
1770 u32 base; /* SRAM byte address of event log header */
1771 u32 capacity; /* event log capacity in # entries */
1772 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
1773 u32 num_wraps; /* # times uCode wrapped to top of log */
1774 u32 next_entry; /* index of next entry to be written by uCode */
1775 u32 size; /* # entries that we'll print */
1776
1777 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001778 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001779 IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07001780 return;
1781 }
1782
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001783 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001784 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001785 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001786 return;
1787 }
1788
1789 /* event log header */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001790 capacity = iwl_read_targ_mem(priv, base);
1791 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
1792 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
1793 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
Zhu Yib481de92007-09-25 17:54:57 -07001794
1795 size = num_wraps ? capacity : next_entry;
1796
1797 /* bail out if nothing in log */
1798 if (size == 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001799 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001800 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001801 return;
1802 }
1803
Winkler, Tomas15b16872008-12-19 10:37:33 +08001804 IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07001805 size, num_wraps);
1806
1807 /* if uCode has wrapped back to top of log, start at the oldest entry,
1808 * i.e the next one that uCode would fill. */
1809 if (num_wraps)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001810 iwl3945_print_event_log(priv, next_entry,
Zhu Yib481de92007-09-25 17:54:57 -07001811 capacity - next_entry, mode);
1812
1813 /* (then/else) start at top of log */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001814 iwl3945_print_event_log(priv, 0, next_entry, mode);
Zhu Yib481de92007-09-25 17:54:57 -07001815
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001816 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001817}
1818
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001819static void iwl3945_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001820{
1821 unsigned long flags;
1822
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001823 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
1824 sizeof(priv->staging_rxon));
1825 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001826 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001827
Abhijeet Kolekar06fd3d82009-04-08 11:26:42 -07001828 priv->cfg->ops->smgmt->add_station(priv, priv->bssid, 1, 0, NULL);
Zhu Yib481de92007-09-25 17:54:57 -07001829
1830 spin_lock_irqsave(&priv->lock, flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001831 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07001832 priv->error_recovering = 0;
1833 spin_unlock_irqrestore(&priv->lock, flags);
1834}
1835
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001836static void iwl3945_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001837{
1838 u32 inta, handled = 0;
1839 u32 inta_fh;
1840 unsigned long flags;
Samuel Ortizd08853a2009-01-23 13:45:17 -08001841#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001842 u32 inta_mask;
1843#endif
1844
1845 spin_lock_irqsave(&priv->lock, flags);
1846
1847 /* Ack/clear/reset pending uCode interrupts.
1848 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1849 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001850 inta = iwl_read32(priv, CSR_INT);
1851 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07001852
1853 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
1854 * Any new interrupts that happen after this, either while we're
1855 * in this tasklet, or later, will show up in next ISR/tasklet. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001856 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1857 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001858
Samuel Ortizd08853a2009-01-23 13:45:17 -08001859#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08001860 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001861 /* just for debug */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001862 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Tomas Winklere1623442009-01-27 14:27:56 -08001863 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07001864 inta, inta_mask, inta_fh);
1865 }
1866#endif
1867
1868 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
1869 * atomic, make sure that inta covers all the interrupts that
1870 * we've discovered, even if FH interrupt came in just after
1871 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001872 if (inta_fh & CSR39_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001873 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001874 if (inta_fh & CSR39_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001875 inta |= CSR_INT_BIT_FH_TX;
1876
1877 /* Now service all interrupt bits discovered above. */
1878 if (inta & CSR_INT_BIT_HW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001879 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001880
1881 /* Tell the device to stop sending interrupts */
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08001882 iwl_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001883
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001884 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001885
1886 handled |= CSR_INT_BIT_HW_ERR;
1887
1888 spin_unlock_irqrestore(&priv->lock, flags);
1889
1890 return;
1891 }
1892
Samuel Ortizd08853a2009-01-23 13:45:17 -08001893#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08001894 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07001895 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001896 if (inta & CSR_INT_BIT_SCD)
Tomas Winklere1623442009-01-27 14:27:56 -08001897 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
Joonwoo Park25c03d82008-01-23 10:15:20 -08001898 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001899
1900 /* Alive notification via Rx interrupt will do the real work */
1901 if (inta & CSR_INT_BIT_ALIVE)
Tomas Winklere1623442009-01-27 14:27:56 -08001902 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07001903 }
1904#endif
1905 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001906 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07001907
Zhu Yib481de92007-09-25 17:54:57 -07001908 /* Error detected by uCode */
1909 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001910 IWL_ERR(priv, "Microcode SW error detected. "
1911 "Restarting 0x%X.\n", inta);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001912 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001913 handled |= CSR_INT_BIT_SW_ERR;
1914 }
1915
1916 /* uCode wakes up after power-down sleep */
1917 if (inta & CSR_INT_BIT_WAKEUP) {
Tomas Winklere1623442009-01-27 14:27:56 -08001918 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
Winkler, Tomas141c43a2009-01-08 10:19:53 -08001919 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001920 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
1921 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
1922 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
1923 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
1924 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
1925 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07001926
1927 handled |= CSR_INT_BIT_WAKEUP;
1928 }
1929
1930 /* All uCode command responses, including Tx command responses,
1931 * Rx "responses" (frame-received notification), and other
1932 * notifications from uCode come through here*/
1933 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001934 iwl3945_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001935 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1936 }
1937
1938 if (inta & CSR_INT_BIT_FH_TX) {
Tomas Winklere1623442009-01-27 14:27:56 -08001939 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07001940
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001941 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
1942 if (!iwl_grab_nic_access(priv)) {
1943 iwl_write_direct32(priv, FH39_TCSR_CREDIT
Tomas Winklerbddadf82008-12-19 10:37:01 +08001944 (FH39_SRVC_CHNL), 0x0);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001945 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001946 }
1947 handled |= CSR_INT_BIT_FH_TX;
1948 }
1949
1950 if (inta & ~handled)
Winkler, Tomas15b16872008-12-19 10:37:33 +08001951 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Zhu Yib481de92007-09-25 17:54:57 -07001952
1953 if (inta & ~CSR_INI_SET_MASK) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001954 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Zhu Yib481de92007-09-25 17:54:57 -07001955 inta & ~CSR_INI_SET_MASK);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001956 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001957 }
1958
1959 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001960 /* only Re-enable if disabled by irq */
1961 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08001962 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001963
Samuel Ortizd08853a2009-01-23 13:45:17 -08001964#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08001965 if (priv->debug_level & (IWL_DL_ISR)) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001966 inta = iwl_read32(priv, CSR_INT);
1967 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1968 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Tomas Winklere1623442009-01-27 14:27:56 -08001969 IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
Zhu Yib481de92007-09-25 17:54:57 -07001970 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
1971 }
1972#endif
1973 spin_unlock_irqrestore(&priv->lock, flags);
1974}
1975
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001976static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01001977 enum ieee80211_band band,
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08001978 u8 is_active, u8 n_probes,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001979 struct iwl3945_scan_channel *scan_ch)
Zhu Yib481de92007-09-25 17:54:57 -07001980{
1981 const struct ieee80211_channel *channels = NULL;
Johannes Berg8318d782008-01-24 19:38:38 +01001982 const struct ieee80211_supported_band *sband;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001983 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07001984 u16 passive_dwell = 0;
1985 u16 active_dwell = 0;
1986 int added, i;
1987
Kolekar, Abhijeetcbba18c2008-12-19 10:37:42 +08001988 sband = iwl_get_hw_mode(priv, band);
Johannes Berg8318d782008-01-24 19:38:38 +01001989 if (!sband)
Zhu Yib481de92007-09-25 17:54:57 -07001990 return 0;
1991
Johannes Berg8318d782008-01-24 19:38:38 +01001992 channels = sband->channels;
Zhu Yib481de92007-09-25 17:54:57 -07001993
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08001994 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
1995 passive_dwell = iwl_get_passive_dwell_time(priv, band);
Zhu Yib481de92007-09-25 17:54:57 -07001996
Abhijeet Kolekar8f4807a2008-09-03 11:26:31 +08001997 if (passive_dwell <= active_dwell)
1998 passive_dwell = active_dwell + 1;
1999
Johannes Berg8318d782008-01-24 19:38:38 +01002000 for (i = 0, added = 0; i < sband->n_channels; i++) {
Johannes Berg182e2e62008-04-04 10:41:56 +02002001 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
2002 continue;
2003
Johannes Berg8318d782008-01-24 19:38:38 +01002004 scan_ch->channel = channels[i].hw_value;
Zhu Yib481de92007-09-25 17:54:57 -07002005
Samuel Ortize6148912009-01-23 13:45:15 -08002006 ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
Zhu Yib481de92007-09-25 17:54:57 -07002007 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002008 IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
Zhu Yib481de92007-09-25 17:54:57 -07002009 scan_ch->channel);
2010 continue;
2011 }
2012
Zhu Yib481de92007-09-25 17:54:57 -07002013 scan_ch->active_dwell = cpu_to_le16(active_dwell);
2014 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002015 /* If passive , set up for auto-switch
2016 * and use long active_dwell time.
2017 */
2018 if (!is_active || is_channel_passive(ch_info) ||
2019 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
2020 scan_ch->type = 0; /* passive */
2021 if (IWL_UCODE_API(priv->ucode_ver) == 1)
2022 scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
2023 } else {
2024 scan_ch->type = 1; /* active */
2025 }
2026
2027 /* Set direct probe bits. These may be used both for active
2028 * scan channels (probes gets sent right away),
2029 * or for passive channels (probes get se sent only after
2030 * hearing clear Rx packet).*/
2031 if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
2032 if (n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08002033 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002034 } else {
2035 /* uCode v1 does not allow setting direct probe bits on
2036 * passive channel. */
2037 if ((scan_ch->type & 1) && n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08002038 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002039 }
Zhu Yib481de92007-09-25 17:54:57 -07002040
Ben Cahill9fbab512007-11-29 11:09:47 +08002041 /* Set txpower levels to defaults */
Zhu Yib481de92007-09-25 17:54:57 -07002042 scan_ch->tpc.dsp_atten = 110;
2043 /* scan_pwr_info->tpc.dsp_atten; */
2044
2045 /*scan_pwr_info->tpc.tx_gain; */
Johannes Berg8318d782008-01-24 19:38:38 +01002046 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -07002047 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
2048 else {
2049 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
2050 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
Ben Cahill9fbab512007-11-29 11:09:47 +08002051 * power level:
Reinette Chatre8a1b0242008-01-14 17:46:25 -08002052 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
Zhu Yib481de92007-09-25 17:54:57 -07002053 */
2054 }
2055
Tomas Winklere1623442009-01-27 14:27:56 -08002056 IWL_DEBUG_SCAN(priv, "Scanning %d [%s %d]\n",
Zhu Yib481de92007-09-25 17:54:57 -07002057 scan_ch->channel,
2058 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
2059 (scan_ch->type & 1) ?
2060 active_dwell : passive_dwell);
2061
2062 scan_ch++;
2063 added++;
2064 }
2065
Tomas Winklere1623442009-01-27 14:27:56 -08002066 IWL_DEBUG_SCAN(priv, "total channels to scan %d \n", added);
Zhu Yib481de92007-09-25 17:54:57 -07002067 return added;
2068}
2069
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002070static void iwl3945_init_hw_rates(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07002071 struct ieee80211_rate *rates)
2072{
2073 int i;
2074
2075 for (i = 0; i < IWL_RATE_COUNT; i++) {
Johannes Berg8318d782008-01-24 19:38:38 +01002076 rates[i].bitrate = iwl3945_rates[i].ieee * 5;
2077 rates[i].hw_value = i; /* Rate scaling will work on indexes */
2078 rates[i].hw_value_short = i;
2079 rates[i].flags = 0;
Samuel Ortizd9829a62008-12-19 10:37:12 +08002080 if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
Zhu Yib481de92007-09-25 17:54:57 -07002081 /*
Johannes Berg8318d782008-01-24 19:38:38 +01002082 * If CCK != 1M then set short preamble rate flag.
Zhu Yib481de92007-09-25 17:54:57 -07002083 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002084 rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
Johannes Berg8318d782008-01-24 19:38:38 +01002085 0 : IEEE80211_RATE_SHORT_PREAMBLE;
Zhu Yib481de92007-09-25 17:54:57 -07002086 }
Zhu Yib481de92007-09-25 17:54:57 -07002087 }
2088}
2089
Zhu Yib481de92007-09-25 17:54:57 -07002090/******************************************************************************
2091 *
2092 * uCode download functions
2093 *
2094 ******************************************************************************/
2095
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002096static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002097{
Tomas Winkler98c92212008-01-14 17:46:20 -08002098 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
2099 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
2100 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
2101 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
2102 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
2103 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07002104}
2105
2106/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002107 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002108 * looking at all data.
2109 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002110static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002111{
2112 u32 val;
2113 u32 save_len = len;
2114 int rc = 0;
2115 u32 errcnt;
2116
Tomas Winklere1623442009-01-27 14:27:56 -08002117 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002118
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002119 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002120 if (rc)
2121 return rc;
2122
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002123 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002124 IWL39_RTC_INST_LOWER_BOUND);
Zhu Yib481de92007-09-25 17:54:57 -07002125
2126 errcnt = 0;
2127 for (; len > 0; len -= sizeof(u32), image++) {
2128 /* read data comes through single port, auto-incr addr */
2129 /* NOTE: Use the debugless read so we don't flood kernel log
2130 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002131 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002132 if (val != le32_to_cpu(*image)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002133 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002134 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2135 save_len - len, val, le32_to_cpu(*image));
2136 rc = -EIO;
2137 errcnt++;
2138 if (errcnt >= 20)
2139 break;
2140 }
2141 }
2142
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002143 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002144
2145 if (!errcnt)
Tomas Winklere1623442009-01-27 14:27:56 -08002146 IWL_DEBUG_INFO(priv,
2147 "ucode image in INSTRUCTION memory is good\n");
Zhu Yib481de92007-09-25 17:54:57 -07002148
2149 return rc;
2150}
2151
2152
2153/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002154 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002155 * using sample data 100 bytes apart. If these sample points are good,
2156 * it's a pretty good bet that everything between them is good, too.
2157 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002158static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002159{
2160 u32 val;
2161 int rc = 0;
2162 u32 errcnt = 0;
2163 u32 i;
2164
Tomas Winklere1623442009-01-27 14:27:56 -08002165 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002166
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002167 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002168 if (rc)
2169 return rc;
2170
2171 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
2172 /* read data comes through single port, auto-incr addr */
2173 /* NOTE: Use the debugless read so we don't flood kernel log
2174 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002175 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002176 i + IWL39_RTC_INST_LOWER_BOUND);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002177 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002178 if (val != le32_to_cpu(*image)) {
2179#if 0 /* Enable this if you want to see details */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002180 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002181 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2182 i, val, *image);
2183#endif
2184 rc = -EIO;
2185 errcnt++;
2186 if (errcnt >= 3)
2187 break;
2188 }
2189 }
2190
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002191 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002192
2193 return rc;
2194}
2195
2196
2197/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002198 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
Zhu Yib481de92007-09-25 17:54:57 -07002199 * and verify its contents
2200 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002201static int iwl3945_verify_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002202{
2203 __le32 *image;
2204 u32 len;
2205 int rc = 0;
2206
2207 /* Try bootstrap */
2208 image = (__le32 *)priv->ucode_boot.v_addr;
2209 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002210 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002211 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002212 IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002213 return 0;
2214 }
2215
2216 /* Try initialize */
2217 image = (__le32 *)priv->ucode_init.v_addr;
2218 len = priv->ucode_init.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002219 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002220 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002221 IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002222 return 0;
2223 }
2224
2225 /* Try runtime/protocol */
2226 image = (__le32 *)priv->ucode_code.v_addr;
2227 len = priv->ucode_code.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002228 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002229 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002230 IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002231 return 0;
2232 }
2233
Winkler, Tomas15b16872008-12-19 10:37:33 +08002234 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
Zhu Yib481de92007-09-25 17:54:57 -07002235
Ben Cahill9fbab512007-11-29 11:09:47 +08002236 /* Since nothing seems to match, show first several data entries in
2237 * instruction SRAM, so maybe visual inspection will give a clue.
2238 * Selection of bootstrap image (vs. other images) is arbitrary. */
Zhu Yib481de92007-09-25 17:54:57 -07002239 image = (__le32 *)priv->ucode_boot.v_addr;
2240 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002241 rc = iwl3945_verify_inst_full(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002242
2243 return rc;
2244}
2245
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002246static void iwl3945_nic_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002247{
2248 /* Remove all resets to allow NIC to operate */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002249 iwl_write32(priv, CSR_RESET, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002250}
2251
2252/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002253 * iwl3945_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07002254 *
2255 * Copy into buffers for card to fetch via bus-mastering
2256 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002257static int iwl3945_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002258{
Kolekar, Abhijeeta78fe752008-12-19 10:37:21 +08002259 struct iwl_ucode *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002260 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07002261 const struct firmware *ucode_raw;
2262 /* firmware file name contains uCode/driver compatibility version */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002263 const char *name_pre = priv->cfg->fw_name_pre;
2264 const unsigned int api_max = priv->cfg->ucode_api_max;
2265 const unsigned int api_min = priv->cfg->ucode_api_min;
2266 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07002267 u8 *src;
2268 size_t len;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002269 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
Zhu Yib481de92007-09-25 17:54:57 -07002270
2271 /* Ask kernel firmware_class module to get the boot firmware off disk.
2272 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002273 for (index = api_max; index >= api_min; index--) {
2274 sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
2275 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
2276 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002277 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002278 buf, ret);
2279 if (ret == -ENOENT)
2280 continue;
2281 else
2282 goto error;
2283 } else {
2284 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002285 IWL_ERR(priv, "Loaded firmware %s, "
2286 "which is deprecated. "
2287 " Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002288 buf, api_max);
Tomas Winklere1623442009-01-27 14:27:56 -08002289 IWL_DEBUG_INFO(priv, "Got firmware '%s' file "
2290 "(%zd bytes) from disk\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002291 buf, ucode_raw->size);
2292 break;
2293 }
Zhu Yib481de92007-09-25 17:54:57 -07002294 }
2295
Reinette Chatrea0987a82008-12-02 12:14:06 -08002296 if (ret < 0)
2297 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07002298
2299 /* Make sure that we got at least our header! */
2300 if (ucode_raw->size < sizeof(*ucode)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002301 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002302 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002303 goto err_release;
2304 }
2305
2306 /* Data from ucode file: header followed by uCode images */
2307 ucode = (void *)ucode_raw->data;
2308
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08002309 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08002310 api_ver = IWL_UCODE_API(priv->ucode_ver);
Zhu Yib481de92007-09-25 17:54:57 -07002311 inst_size = le32_to_cpu(ucode->inst_size);
2312 data_size = le32_to_cpu(ucode->data_size);
2313 init_size = le32_to_cpu(ucode->init_size);
2314 init_data_size = le32_to_cpu(ucode->init_data_size);
2315 boot_size = le32_to_cpu(ucode->boot_size);
2316
Reinette Chatrea0987a82008-12-02 12:14:06 -08002317 /* api_ver should match the api version forming part of the
2318 * firmware filename ... but we don't check for that and only rely
Nick Andrew877d0312009-01-26 11:06:57 +01002319 * on the API version read from firmware header from here on forward */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002320
2321 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002322 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002323 "Driver supports v%u, firmware is v%u.\n",
2324 api_max, api_ver);
2325 priv->ucode_ver = 0;
2326 ret = -EINVAL;
2327 goto err_release;
2328 }
2329 if (api_ver != api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002330 IWL_ERR(priv, "Firmware has old API version. Expected %u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002331 "got %u. New firmware can be obtained "
2332 "from http://www.intellinuxwireless.org.\n",
2333 api_max, api_ver);
2334
Tomas Winkler978785a2008-12-19 10:37:31 +08002335 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
2336 IWL_UCODE_MAJOR(priv->ucode_ver),
2337 IWL_UCODE_MINOR(priv->ucode_ver),
2338 IWL_UCODE_API(priv->ucode_ver),
2339 IWL_UCODE_SERIAL(priv->ucode_ver));
2340
Tomas Winklere1623442009-01-27 14:27:56 -08002341 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002342 priv->ucode_ver);
Tomas Winklere1623442009-01-27 14:27:56 -08002343 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
2344 inst_size);
2345 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
2346 data_size);
2347 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
2348 init_size);
2349 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
2350 init_data_size);
2351 IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
2352 boot_size);
Zhu Yib481de92007-09-25 17:54:57 -07002353
Reinette Chatrea0987a82008-12-02 12:14:06 -08002354
Zhu Yib481de92007-09-25 17:54:57 -07002355 /* Verify size of file vs. image size info in file's header */
2356 if (ucode_raw->size < sizeof(*ucode) +
2357 inst_size + data_size + init_size +
2358 init_data_size + boot_size) {
2359
Tomas Winklere1623442009-01-27 14:27:56 -08002360 IWL_DEBUG_INFO(priv, "uCode file size %zd too small\n",
2361 ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002362 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002363 goto err_release;
2364 }
2365
2366 /* Verify that uCode images will fit in card's SRAM */
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002367 if (inst_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002368 IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002369 inst_size);
2370 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002371 goto err_release;
2372 }
2373
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002374 if (data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002375 IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002376 data_size);
2377 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002378 goto err_release;
2379 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002380 if (init_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002381 IWL_DEBUG_INFO(priv,
2382 "uCode init instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002383 init_size);
2384 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002385 goto err_release;
2386 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002387 if (init_data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002388 IWL_DEBUG_INFO(priv,
2389 "uCode init data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002390 init_data_size);
2391 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002392 goto err_release;
2393 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002394 if (boot_size > IWL39_MAX_BSM_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002395 IWL_DEBUG_INFO(priv,
2396 "uCode boot instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002397 boot_size);
2398 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002399 goto err_release;
2400 }
2401
2402 /* Allocate ucode buffers for card's bus-master loading ... */
2403
2404 /* Runtime instructions and 2 copies of data:
2405 * 1) unmodified from disk
2406 * 2) backup cache for save/restore during power-downs */
2407 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002408 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07002409
2410 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002411 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07002412
2413 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002414 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07002415
2416 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
Tomas Winkler90e759d2007-11-29 11:09:41 +08002417 !priv->ucode_data_backup.v_addr)
Zhu Yib481de92007-09-25 17:54:57 -07002418 goto err_pci_alloc;
2419
Tomas Winkler90e759d2007-11-29 11:09:41 +08002420 /* Initialization instructions and data */
2421 if (init_size && init_data_size) {
2422 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002423 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002424
2425 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002426 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002427
2428 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
2429 goto err_pci_alloc;
2430 }
2431
2432 /* Bootstrap (instructions only, no data) */
2433 if (boot_size) {
2434 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002435 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002436
2437 if (!priv->ucode_boot.v_addr)
2438 goto err_pci_alloc;
2439 }
2440
Zhu Yib481de92007-09-25 17:54:57 -07002441 /* Copy images into buffers for card's bus-master reads ... */
2442
2443 /* Runtime instructions (first block of data in file) */
2444 src = &ucode->data[0];
2445 len = priv->ucode_code.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002446 IWL_DEBUG_INFO(priv,
2447 "Copying (but not loading) uCode instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002448 memcpy(priv->ucode_code.v_addr, src, len);
Tomas Winklere1623442009-01-27 14:27:56 -08002449 IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002450 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
2451
2452 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002453 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
Zhu Yib481de92007-09-25 17:54:57 -07002454 src = &ucode->data[inst_size];
2455 len = priv->ucode_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002456 IWL_DEBUG_INFO(priv,
2457 "Copying (but not loading) uCode data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002458 memcpy(priv->ucode_data.v_addr, src, len);
2459 memcpy(priv->ucode_data_backup.v_addr, src, len);
2460
2461 /* Initialization instructions (3rd block) */
2462 if (init_size) {
2463 src = &ucode->data[inst_size + data_size];
2464 len = priv->ucode_init.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002465 IWL_DEBUG_INFO(priv,
2466 "Copying (but not loading) init instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002467 memcpy(priv->ucode_init.v_addr, src, len);
2468 }
2469
2470 /* Initialization data (4th block) */
2471 if (init_data_size) {
2472 src = &ucode->data[inst_size + data_size + init_size];
2473 len = priv->ucode_init_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002474 IWL_DEBUG_INFO(priv,
2475 "Copying (but not loading) init data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002476 memcpy(priv->ucode_init_data.v_addr, src, len);
2477 }
2478
2479 /* Bootstrap instructions (5th block) */
2480 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
2481 len = priv->ucode_boot.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002482 IWL_DEBUG_INFO(priv,
2483 "Copying (but not loading) boot instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002484 memcpy(priv->ucode_boot.v_addr, src, len);
2485
2486 /* We have our copies now, allow OS release its copies */
2487 release_firmware(ucode_raw);
2488 return 0;
2489
2490 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08002491 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002492 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002493 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002494
2495 err_release:
2496 release_firmware(ucode_raw);
2497
2498 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08002499 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002500}
2501
2502
2503/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002504 * iwl3945_set_ucode_ptrs - Set uCode address location
Zhu Yib481de92007-09-25 17:54:57 -07002505 *
2506 * Tell initialization uCode where to find runtime uCode.
2507 *
2508 * BSM registers initially contain pointers to initialization uCode.
2509 * We need to replace them to load runtime uCode inst and data,
2510 * and to save runtime data when powering down.
2511 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002512static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002513{
2514 dma_addr_t pinst;
2515 dma_addr_t pdata;
2516 int rc = 0;
2517 unsigned long flags;
2518
2519 /* bits 31:0 for 3945 */
2520 pinst = priv->ucode_code.p_addr;
2521 pdata = priv->ucode_data_backup.p_addr;
2522
2523 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002524 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002525 if (rc) {
2526 spin_unlock_irqrestore(&priv->lock, flags);
2527 return rc;
2528 }
2529
2530 /* Tell bootstrap uCode where to find image to load */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002531 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
2532 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
2533 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002534 priv->ucode_data.len);
2535
Tomas Winklera96a27f2008-10-23 23:48:56 -07002536 /* Inst byte count must be last to set up, bit 31 signals uCode
Zhu Yib481de92007-09-25 17:54:57 -07002537 * that all new ptr/size info is in place */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002538 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002539 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
2540
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002541 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002542
2543 spin_unlock_irqrestore(&priv->lock, flags);
2544
Tomas Winklere1623442009-01-27 14:27:56 -08002545 IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002546
2547 return rc;
2548}
2549
2550/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002551 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002552 *
2553 * Called after REPLY_ALIVE notification received from "initialize" uCode.
2554 *
Zhu Yib481de92007-09-25 17:54:57 -07002555 * Tell "initialize" uCode to go ahead and load the runtime uCode.
Ben Cahill9fbab512007-11-29 11:09:47 +08002556 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002557static void iwl3945_init_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002558{
2559 /* Check alive response for "valid" sign from uCode */
2560 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
2561 /* We had an error bringing up the hardware, so take it
2562 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002563 IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002564 goto restart;
2565 }
2566
2567 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
2568 * This is a paranoid check, because we would not have gotten the
2569 * "initialize" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002570 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002571 /* Runtime instruction load was bad;
2572 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002573 IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002574 goto restart;
2575 }
2576
2577 /* Send pointers to protocol/runtime uCode image ... init code will
2578 * load and launch runtime uCode, which will send us another "Alive"
2579 * notification. */
Tomas Winklere1623442009-01-27 14:27:56 -08002580 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002581 if (iwl3945_set_ucode_ptrs(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002582 /* Runtime instruction load won't happen;
2583 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002584 IWL_DEBUG_INFO(priv, "Couldn't set up uCode pointers.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002585 goto restart;
2586 }
2587 return;
2588
2589 restart:
2590 queue_work(priv->workqueue, &priv->restart);
2591}
2592
Zhu Yib481de92007-09-25 17:54:57 -07002593/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002594 * iwl3945_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002595 * from protocol/runtime uCode (initialization uCode's
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002596 * Alive gets handled by iwl3945_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07002597 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002598static void iwl3945_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002599{
2600 int rc = 0;
2601 int thermal_spin = 0;
2602 u32 rfkill;
2603
Tomas Winklere1623442009-01-27 14:27:56 -08002604 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002605
2606 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
2607 /* We had an error bringing up the hardware, so take it
2608 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002609 IWL_DEBUG_INFO(priv, "Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002610 goto restart;
2611 }
2612
2613 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
2614 * This is a paranoid check, because we would not have gotten the
2615 * "runtime" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002616 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002617 /* Runtime instruction load was bad;
2618 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002619 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002620 goto restart;
2621 }
2622
Abhijeet Kolekar40ace5b2009-04-08 11:26:40 -07002623 priv->cfg->ops->smgmt->clear_station_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002624
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002625 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002626 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002627 IWL_WARN(priv, "Can not read RFKILL status from adapter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002628 return;
2629 }
2630
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002631 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
Tomas Winklere1623442009-01-27 14:27:56 -08002632 IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002633 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002634
2635 if (rfkill & 0x1) {
2636 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Tomas Winklera96a27f2008-10-23 23:48:56 -07002637 /* if RFKILL is not on, then wait for thermal
Zhu Yib481de92007-09-25 17:54:57 -07002638 * sensor in adapter to kick in */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002639 while (iwl3945_hw_get_temperature(priv) == 0) {
Zhu Yib481de92007-09-25 17:54:57 -07002640 thermal_spin++;
2641 udelay(10);
2642 }
2643
2644 if (thermal_spin)
Tomas Winklere1623442009-01-27 14:27:56 -08002645 IWL_DEBUG_INFO(priv, "Thermal calibration took %dus\n",
Zhu Yib481de92007-09-25 17:54:57 -07002646 thermal_spin * 10);
2647 } else
2648 set_bit(STATUS_RF_KILL_HW, &priv->status);
2649
Ben Cahill9fbab512007-11-29 11:09:47 +08002650 /* After the ALIVE response, we can send commands to 3945 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07002651 set_bit(STATUS_ALIVE, &priv->status);
2652
2653 /* Clear out the uCode error bit if it is set */
2654 clear_bit(STATUS_FW_ERROR, &priv->status);
2655
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08002656 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002657 return;
2658
Johannes Berg36d68252008-05-15 12:55:26 +02002659 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07002660
2661 priv->active_rate = priv->rates_mask;
2662 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
2663
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08002664 iwl_power_update_mode(priv, false);
Zhu Yib481de92007-09-25 17:54:57 -07002665
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002666 if (iwl_is_associated(priv)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002667 struct iwl3945_rxon_cmd *active_rxon =
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002668 (struct iwl3945_rxon_cmd *)(&priv->active_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07002669
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002670 memcpy(&priv->staging_rxon, &priv->active_rxon,
2671 sizeof(priv->staging_rxon));
Zhu Yib481de92007-09-25 17:54:57 -07002672 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2673 } else {
2674 /* Initialize our rx_config data */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002675 iwl_connection_init_rx_config(priv, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002676 }
2677
Ben Cahill9fbab512007-11-29 11:09:47 +08002678 /* Configure Bluetooth device coexistence support */
Samuel Ortiz17f841c2009-01-23 13:45:20 -08002679 iwl_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002680
2681 /* Configure the adapter for unassociated operation */
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002682 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002683
Zhu Yib481de92007-09-25 17:54:57 -07002684 iwl3945_reg_txpower_periodic(priv);
2685
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07002686 iwl3945_led_register(priv);
2687
Tomas Winklere1623442009-01-27 14:27:56 -08002688 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07002689 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002690 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07002691
2692 if (priv->error_recovering)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002693 iwl3945_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002694
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08002695 /* reassociate for ADHOC mode */
2696 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
2697 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
2698 priv->vif);
2699 if (beacon)
Abhijeet Kolekar9944b932009-04-08 11:26:36 -07002700 iwl_mac_beacon_update(priv->hw, beacon);
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08002701 }
2702
Abhijeet Kolekarf45c2712009-04-08 11:26:38 -07002703 if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
2704 iwl3945_set_mode(priv, priv->iw_mode);
2705
Zhu Yib481de92007-09-25 17:54:57 -07002706 return;
2707
2708 restart:
2709 queue_work(priv->workqueue, &priv->restart);
2710}
2711
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002712static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07002713
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002714static void __iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002715{
2716 unsigned long flags;
2717 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
2718 struct ieee80211_conf *conf = NULL;
2719
Tomas Winklere1623442009-01-27 14:27:56 -08002720 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -07002721
2722 conf = ieee80211_get_hw_conf(priv->hw);
2723
2724 if (!exit_pending)
2725 set_bit(STATUS_EXIT_PENDING, &priv->status);
2726
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07002727 iwl3945_led_unregister(priv);
Abhijeet Kolekar40ace5b2009-04-08 11:26:40 -07002728 priv->cfg->ops->smgmt->clear_station_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002729
2730 /* Unblock any waiting calls */
2731 wake_up_interruptible_all(&priv->wait_command_queue);
2732
Zhu Yib481de92007-09-25 17:54:57 -07002733 /* Wipe out the EXIT_PENDING status bit if we are not actually
2734 * exiting the module */
2735 if (!exit_pending)
2736 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2737
2738 /* stop and reset the on-board processor */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002739 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07002740
2741 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002742 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002743 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002744 spin_unlock_irqrestore(&priv->lock, flags);
2745 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002746
2747 if (priv->mac80211_registered)
2748 ieee80211_stop_queues(priv->hw);
2749
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002750 /* If we have not previously called iwl3945_init() then
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07002751 * clear all bits but the RF Kill bits and return */
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08002752 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002753 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2754 STATUS_RF_KILL_HW |
2755 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
2756 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08002757 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2758 STATUS_GEO_CONFIGURED |
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08002759 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2760 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002761 goto exit;
2762 }
2763
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07002764 /* ...otherwise clear out all the status bits but the RF Kill
2765 * bits and continue taking the NIC down. */
Zhu Yib481de92007-09-25 17:54:57 -07002766 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2767 STATUS_RF_KILL_HW |
2768 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
2769 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08002770 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2771 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002772 test_bit(STATUS_FW_ERROR, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08002773 STATUS_FW_ERROR |
2774 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2775 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002776
Abbas, Mohamede9414b62009-01-20 21:33:55 -08002777 priv->cfg->ops->lib->apm_ops.reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002778 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002779 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07002780 spin_unlock_irqrestore(&priv->lock, flags);
2781
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002782 iwl3945_hw_txq_ctx_stop(priv);
2783 iwl3945_hw_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002784
2785 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002786 if (!iwl_grab_nic_access(priv)) {
2787 iwl_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002788 APMG_CLK_VAL_DMA_CLK_RQT);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002789 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002790 }
2791 spin_unlock_irqrestore(&priv->lock, flags);
2792
2793 udelay(5);
2794
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07002795 if (exit_pending)
Abbas, Mohamede9414b62009-01-20 21:33:55 -08002796 priv->cfg->ops->lib->apm_ops.stop(priv);
2797 else
2798 priv->cfg->ops->lib->apm_ops.reset(priv);
2799
Zhu Yib481de92007-09-25 17:54:57 -07002800 exit:
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002801 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07002802
2803 if (priv->ibss_beacon)
2804 dev_kfree_skb(priv->ibss_beacon);
2805 priv->ibss_beacon = NULL;
2806
2807 /* clear out any free frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002808 iwl3945_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002809}
2810
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002811static void iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002812{
2813 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002814 __iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002815 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08002816
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002817 iwl3945_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002818}
2819
2820#define MAX_HW_RESTARTS 5
2821
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002822static int __iwl3945_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002823{
2824 int rc, i;
2825
2826 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002827 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07002828 return -EIO;
2829 }
2830
2831 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002832 IWL_WARN(priv, "Radio disabled by SW RF kill (module "
Zhu Yib481de92007-09-25 17:54:57 -07002833 "parameter)\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08002834 return -ENODEV;
2835 }
2836
Reinette Chatree903fbd2008-01-30 22:05:15 -08002837 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002838 IWL_ERR(priv, "ucode not available for device bring up\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08002839 return -EIO;
2840 }
2841
Zhu Yie655b9f2008-01-24 02:19:38 -08002842 /* If platform's RF_KILL switch is NOT set to KILL */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002843 if (iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yie655b9f2008-01-24 02:19:38 -08002844 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
2845 clear_bit(STATUS_RF_KILL_HW, &priv->status);
2846 else {
2847 set_bit(STATUS_RF_KILL_HW, &priv->status);
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07002848 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
2849 return -ENODEV;
Zhu Yib481de92007-09-25 17:54:57 -07002850 }
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02002851
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002852 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07002853
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002854 rc = iwl3945_hw_nic_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002855 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002856 IWL_ERR(priv, "Unable to int nic\n");
Zhu Yib481de92007-09-25 17:54:57 -07002857 return rc;
2858 }
2859
2860 /* make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002861 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2862 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07002863 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
2864
2865 /* clear (again), then enable host interrupts */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002866 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002867 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002868
2869 /* really make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002870 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2871 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07002872
2873 /* Copy original ucode data image from disk into backup cache.
2874 * This will be used to initialize the on-board processor's
2875 * data SRAM for a clean start when the runtime program first loads. */
2876 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a66926a2008-01-14 17:46:18 -08002877 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07002878
Zhu Yie655b9f2008-01-24 02:19:38 -08002879 /* We return success when we resume from suspend and rf_kill is on. */
2880 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
2881 return 0;
2882
Zhu Yib481de92007-09-25 17:54:57 -07002883 for (i = 0; i < MAX_HW_RESTARTS; i++) {
2884
Abhijeet Kolekar40ace5b2009-04-08 11:26:40 -07002885 priv->cfg->ops->smgmt->clear_station_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002886
2887 /* load bootstrap state machine,
2888 * load bootstrap program into processor's memory,
2889 * prepare to load the "initialize" uCode */
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002890 priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002891
2892 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002893 IWL_ERR(priv,
2894 "Unable to set up bootstrap uCode: %d\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -07002895 continue;
2896 }
2897
2898 /* start card; "initialize" will load runtime ucode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002899 iwl3945_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002900
Tomas Winklere1623442009-01-27 14:27:56 -08002901 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
Zhu Yib481de92007-09-25 17:54:57 -07002902
2903 return 0;
2904 }
2905
2906 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002907 __iwl3945_down(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08002908 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002909
2910 /* tried to restart and config the device for as long as our
2911 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002912 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07002913 return -EIO;
2914}
2915
2916
2917/*****************************************************************************
2918 *
2919 * Workqueue callbacks
2920 *
2921 *****************************************************************************/
2922
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002923static void iwl3945_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002924{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002925 struct iwl_priv *priv =
2926 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002927
2928 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2929 return;
2930
2931 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002932 iwl3945_init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002933 mutex_unlock(&priv->mutex);
2934}
2935
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002936static void iwl3945_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002937{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002938 struct iwl_priv *priv =
2939 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002940
2941 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2942 return;
2943
2944 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002945 iwl3945_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002946 mutex_unlock(&priv->mutex);
2947}
2948
Helmut Schaa26635162009-01-15 09:38:44 +01002949static void iwl3945_rfkill_poll(struct work_struct *data)
2950{
2951 struct iwl_priv *priv =
2952 container_of(data, struct iwl_priv, rfkill_poll.work);
2953 unsigned long status = priv->status;
2954
2955 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
2956 clear_bit(STATUS_RF_KILL_HW, &priv->status);
2957 else
2958 set_bit(STATUS_RF_KILL_HW, &priv->status);
2959
2960 if (test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status))
2961 queue_work(priv->workqueue, &priv->rf_kill);
2962
2963 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
2964 round_jiffies_relative(2 * HZ));
2965
2966}
2967
Zhu Yib481de92007-09-25 17:54:57 -07002968#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002969static void iwl3945_bg_request_scan(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002970{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002971 struct iwl_priv *priv =
2972 container_of(data, struct iwl_priv, request_scan);
Winkler, Tomasc2d79b482008-12-19 10:37:34 +08002973 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07002974 .id = REPLY_SCAN_CMD,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002975 .len = sizeof(struct iwl3945_scan_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07002976 .meta.flags = CMD_SIZE_HUGE,
2977 };
2978 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002979 struct iwl3945_scan_cmd *scan;
Zhu Yib481de92007-09-25 17:54:57 -07002980 struct ieee80211_conf *conf = NULL;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08002981 u8 n_probes = 2;
Johannes Berg8318d782008-01-24 19:38:38 +01002982 enum ieee80211_band band;
John W. Linville9387b7c2008-09-30 20:59:05 -04002983 DECLARE_SSID_BUF(ssid);
Zhu Yib481de92007-09-25 17:54:57 -07002984
2985 conf = ieee80211_get_hw_conf(priv->hw);
2986
2987 mutex_lock(&priv->mutex);
2988
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08002989 if (!iwl_is_ready(priv)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002990 IWL_WARN(priv, "request scan called when driver not ready.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002991 goto done;
2992 }
2993
Tomas Winklera96a27f2008-10-23 23:48:56 -07002994 /* Make sure the scan wasn't canceled before this queued work
Zhu Yib481de92007-09-25 17:54:57 -07002995 * was given the chance to run... */
2996 if (!test_bit(STATUS_SCANNING, &priv->status))
2997 goto done;
2998
2999 /* This should never be called or scheduled if there is currently
3000 * a scan active in the hardware. */
3001 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003002 IWL_DEBUG_INFO(priv, "Multiple concurrent scan requests "
3003 "Ignoring second request.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003004 rc = -EIO;
3005 goto done;
3006 }
3007
3008 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003009 IWL_DEBUG_SCAN(priv, "Aborting scan due to device shutdown\n");
Zhu Yib481de92007-09-25 17:54:57 -07003010 goto done;
3011 }
3012
3013 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003014 IWL_DEBUG_HC(priv,
3015 "Scan request while abort pending. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003016 goto done;
3017 }
3018
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003019 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003020 IWL_DEBUG_HC(priv, "Aborting scan due to RF Kill activation\n");
Zhu Yib481de92007-09-25 17:54:57 -07003021 goto done;
3022 }
3023
3024 if (!test_bit(STATUS_READY, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003025 IWL_DEBUG_HC(priv,
3026 "Scan request while uninitialized. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003027 goto done;
3028 }
3029
3030 if (!priv->scan_bands) {
Tomas Winklere1623442009-01-27 14:27:56 -08003031 IWL_DEBUG_HC(priv, "Aborting scan due to no requested bands\n");
Zhu Yib481de92007-09-25 17:54:57 -07003032 goto done;
3033 }
3034
Winkler, Tomas805cee52009-01-19 15:30:28 -08003035 if (!priv->scan) {
3036 priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
Zhu Yib481de92007-09-25 17:54:57 -07003037 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
Winkler, Tomas805cee52009-01-19 15:30:28 -08003038 if (!priv->scan) {
Zhu Yib481de92007-09-25 17:54:57 -07003039 rc = -ENOMEM;
3040 goto done;
3041 }
3042 }
Winkler, Tomas805cee52009-01-19 15:30:28 -08003043 scan = priv->scan;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003044 memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07003045
3046 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
3047 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
3048
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003049 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003050 u16 interval = 0;
3051 u32 extra;
3052 u32 suspend_time = 100;
3053 u32 scan_suspend_time = 100;
3054 unsigned long flags;
3055
Tomas Winklere1623442009-01-27 14:27:56 -08003056 IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
Zhu Yib481de92007-09-25 17:54:57 -07003057
3058 spin_lock_irqsave(&priv->lock, flags);
3059 interval = priv->beacon_int;
3060 spin_unlock_irqrestore(&priv->lock, flags);
3061
3062 scan->suspend_time = 0;
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003063 scan->max_out_time = cpu_to_le32(200 * 1024);
Zhu Yib481de92007-09-25 17:54:57 -07003064 if (!interval)
3065 interval = suspend_time;
3066 /*
3067 * suspend time format:
3068 * 0-19: beacon interval in usec (time before exec.)
3069 * 20-23: 0
3070 * 24-31: number of beacons (suspend between channels)
3071 */
3072
3073 extra = (suspend_time / interval) << 24;
3074 scan_suspend_time = 0xFF0FFFFF &
3075 (extra | ((suspend_time % interval) * 1024));
3076
3077 scan->suspend_time = cpu_to_le32(scan_suspend_time);
Tomas Winklere1623442009-01-27 14:27:56 -08003078 IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003079 scan_suspend_time, interval);
3080 }
3081
3082 /* We should add the ability for user to lock to PASSIVE ONLY */
3083 if (priv->one_direct_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08003084 IWL_DEBUG_SCAN(priv, "Kicking off one direct scan for '%s'\n",
3085 print_ssid(ssid, priv->direct_ssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04003086 priv->direct_ssid_len));
Zhu Yib481de92007-09-25 17:54:57 -07003087 scan->direct_scan[0].id = WLAN_EID_SSID;
3088 scan->direct_scan[0].len = priv->direct_ssid_len;
3089 memcpy(scan->direct_scan[0].ssid,
3090 priv->direct_ssid, priv->direct_ssid_len);
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003091 n_probes++;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003092 } else
Tomas Winklere1623442009-01-27 14:27:56 -08003093 IWL_DEBUG_SCAN(priv, "Kicking off one indirect scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003094
3095 /* We don't build a direct scan probe request; the uCode will do
3096 * that based on the direct_mask added to each channel entry */
Zhu Yib481de92007-09-25 17:54:57 -07003097 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08003098 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07003099 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
3100
3101 /* flags + rate selection */
3102
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003103 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07003104 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
3105 scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
3106 scan->good_CRC_th = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01003107 band = IEEE80211_BAND_2GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003108 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07003109 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
3110 scan->good_CRC_th = IWL_GOOD_CRC_TH;
Johannes Berg8318d782008-01-24 19:38:38 +01003111 band = IEEE80211_BAND_5GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003112 } else {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003113 IWL_WARN(priv, "Invalid scan band count\n");
Zhu Yib481de92007-09-25 17:54:57 -07003114 goto done;
3115 }
3116
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08003117 scan->tx_cmd.len = cpu_to_le16(
3118 iwl_fill_probe_req(priv, band,
3119 (struct ieee80211_mgmt *)scan->data,
3120 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
3121
Zhu Yib481de92007-09-25 17:54:57 -07003122 /* select Rx antennas */
3123 scan->flags |= iwl3945_get_antenna_flags(priv);
3124
Johannes Berg05c914f2008-09-11 00:01:58 +02003125 if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
Zhu Yib481de92007-09-25 17:54:57 -07003126 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
3127
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003128 scan->channel_count =
3129 iwl3945_get_channels_for_scan(priv, band, 1, /* active */
3130 n_probes,
3131 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
Zhu Yib481de92007-09-25 17:54:57 -07003132
Reinette Chatre14b54332008-11-04 12:21:35 -08003133 if (scan->channel_count == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08003134 IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
Reinette Chatre14b54332008-11-04 12:21:35 -08003135 goto done;
3136 }
3137
Zhu Yib481de92007-09-25 17:54:57 -07003138 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003139 scan->channel_count * sizeof(struct iwl3945_scan_channel);
Zhu Yib481de92007-09-25 17:54:57 -07003140 cmd.data = scan;
3141 scan->len = cpu_to_le16(cmd.len);
3142
3143 set_bit(STATUS_SCAN_HW, &priv->status);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003144 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07003145 if (rc)
3146 goto done;
3147
3148 queue_delayed_work(priv->workqueue, &priv->scan_check,
3149 IWL_SCAN_CHECK_WATCHDOG);
3150
3151 mutex_unlock(&priv->mutex);
3152 return;
3153
3154 done:
Mohamed Abbas2420ebc2008-11-04 12:21:34 -08003155 /* can not perform scan make sure we clear scanning
3156 * bits from status so next scan request can be performed.
3157 * if we dont clear scanning status bit here all next scan
3158 * will fail
3159 */
3160 clear_bit(STATUS_SCAN_HW, &priv->status);
3161 clear_bit(STATUS_SCANNING, &priv->status);
3162
Ian Schram01ebd062007-10-25 17:15:22 +08003163 /* inform mac80211 scan aborted */
Zhu Yib481de92007-09-25 17:54:57 -07003164 queue_work(priv->workqueue, &priv->scan_completed);
3165 mutex_unlock(&priv->mutex);
3166}
3167
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003168static void iwl3945_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003169{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003170 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07003171
3172 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3173 return;
3174
3175 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003176 __iwl3945_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003177 mutex_unlock(&priv->mutex);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01003178 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003179}
3180
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003181static void iwl3945_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003182{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003183 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07003184
3185 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3186 return;
3187
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003188 iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003189 queue_work(priv->workqueue, &priv->up);
3190}
3191
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003192static void iwl3945_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003193{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003194 struct iwl_priv *priv =
3195 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07003196
3197 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3198 return;
3199
3200 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003201 iwl3945_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003202 mutex_unlock(&priv->mutex);
3203}
3204
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07003205static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed);
3206
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003207#define IWL_DELAY_NEXT_SCAN (HZ*2)
3208
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07003209void iwl3945_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003210{
Zhu Yib481de92007-09-25 17:54:57 -07003211 int rc = 0;
3212 struct ieee80211_conf *conf = NULL;
3213
Johannes Berg05c914f2008-09-11 00:01:58 +02003214 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003215 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07003216 return;
3217 }
3218
3219
Tomas Winklere1623442009-01-27 14:27:56 -08003220 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003221 priv->assoc_id, priv->active_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07003222
3223 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3224 return;
3225
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003226 if (!priv->vif || !priv->is_open)
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003227 return;
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003228
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003229 iwl_scan_cancel_timeout(priv, 200);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003230
Zhu Yib481de92007-09-25 17:54:57 -07003231 conf = ieee80211_get_hw_conf(priv->hw);
3232
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003233 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003234 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003235
Tomas Winkler28afaf92008-12-19 10:37:06 +08003236 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003237 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003238 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07003239 sizeof(priv->rxon_timing), &priv->rxon_timing);
3240 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003241 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003242 "Attempting to continue.\n");
3243
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003244 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003245
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003246 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003247
Tomas Winklere1623442009-01-27 14:27:56 -08003248 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003249 priv->assoc_id, priv->beacon_int);
3250
3251 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003252 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003253 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003254 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003255
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003256 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07003257 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003258 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003259 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003260 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003261
Johannes Berg05c914f2008-09-11 00:01:58 +02003262 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003263 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003264
3265 }
3266
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003267 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003268
3269 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02003270 case NL80211_IFTYPE_STATION:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003271 iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07003272 break;
3273
Johannes Berg05c914f2008-09-11 00:01:58 +02003274 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07003275
Abhijeet Kolekarce546fd2008-11-19 15:32:22 -08003276 priv->assoc_id = 1;
Abhijeet Kolekar06fd3d82009-04-08 11:26:42 -07003277 priv->cfg->ops->smgmt->add_station(priv, priv->bssid, 0, 0, NULL);
Zhu Yib481de92007-09-25 17:54:57 -07003278 iwl3945_sync_sta(priv, IWL_STA_ID,
Johannes Berg8318d782008-01-24 19:38:38 +01003279 (priv->band == IEEE80211_BAND_5GHZ) ?
Zhu Yib481de92007-09-25 17:54:57 -07003280 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
3281 CMD_ASYNC);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003282 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
3283 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003284
3285 break;
3286
3287 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08003288 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003289 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07003290 break;
3291 }
3292
Abhijeet Kolekar14d2aac2009-02-27 16:21:24 -08003293 iwl_activate_qos(priv, 0);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08003294
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003295 /* we have just associated, don't start scan too early */
3296 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08003297}
3298
Zhu Yib481de92007-09-25 17:54:57 -07003299/*****************************************************************************
3300 *
3301 * mac80211 entry point functions
3302 *
3303 *****************************************************************************/
3304
Zhu Yi5a66926a2008-01-14 17:46:18 -08003305#define UCODE_READY_TIMEOUT (2 * HZ)
3306
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003307static int iwl3945_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003308{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003309 struct iwl_priv *priv = hw->priv;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003310 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003311
Tomas Winklere1623442009-01-27 14:27:56 -08003312 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003313
3314 /* we should be verifying the device is ready to be opened */
3315 mutex_lock(&priv->mutex);
3316
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003317 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
Zhu Yi5a66926a2008-01-14 17:46:18 -08003318 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
3319 * ucode filename and max sizes are card-specific. */
3320
3321 if (!priv->ucode_code.len) {
3322 ret = iwl3945_read_ucode(priv);
3323 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003324 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003325 mutex_unlock(&priv->mutex);
3326 goto out_release_irq;
3327 }
3328 }
3329
Zhu Yie655b9f2008-01-24 02:19:38 -08003330 ret = __iwl3945_up(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003331
Zhu Yib481de92007-09-25 17:54:57 -07003332 mutex_unlock(&priv->mutex);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003333
Samuel Ortizc0af96a2009-01-21 18:27:54 +01003334 iwl_rfkill_set_hw_state(priv);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02003335
Zhu Yie655b9f2008-01-24 02:19:38 -08003336 if (ret)
3337 goto out_release_irq;
3338
Tomas Winklere1623442009-01-27 14:27:56 -08003339 IWL_DEBUG_INFO(priv, "Start UP work.\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003340
Zhu Yi5a66926a2008-01-14 17:46:18 -08003341 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
3342 * mac80211 will not be run successfully. */
3343 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
3344 test_bit(STATUS_READY, &priv->status),
3345 UCODE_READY_TIMEOUT);
3346 if (!ret) {
3347 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003348 IWL_ERR(priv,
3349 "Wait for START_ALIVE timeout after %dms.\n",
3350 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Zhu Yi5a66926a2008-01-14 17:46:18 -08003351 ret = -ETIMEDOUT;
3352 goto out_release_irq;
3353 }
3354 }
3355
Helmut Schaa26635162009-01-15 09:38:44 +01003356 /* ucode is running and will send rfkill notifications,
3357 * no need to poll the killswitch state anymore */
3358 cancel_delayed_work(&priv->rfkill_poll);
3359
Zhu Yie655b9f2008-01-24 02:19:38 -08003360 priv->is_open = 1;
Tomas Winklere1623442009-01-27 14:27:56 -08003361 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003362 return 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003363
3364out_release_irq:
Zhu Yie655b9f2008-01-24 02:19:38 -08003365 priv->is_open = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08003366 IWL_DEBUG_MAC80211(priv, "leave - failed\n");
Zhu Yi5a66926a2008-01-14 17:46:18 -08003367 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003368}
3369
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003370static void iwl3945_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003371{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003372 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003373
Tomas Winklere1623442009-01-27 14:27:56 -08003374 IWL_DEBUG_MAC80211(priv, "enter\n");
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003375
Zhu Yie655b9f2008-01-24 02:19:38 -08003376 if (!priv->is_open) {
Tomas Winklere1623442009-01-27 14:27:56 -08003377 IWL_DEBUG_MAC80211(priv, "leave - skip\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003378 return;
3379 }
3380
Zhu Yib481de92007-09-25 17:54:57 -07003381 priv->is_open = 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003382
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003383 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08003384 /* stop mac, cancel any scan request and clear
3385 * RXON_FILTER_ASSOC_MSK BIT
3386 */
Zhu Yi5a66926a2008-01-14 17:46:18 -08003387 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003388 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003389 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003390 }
3391
Zhu Yi5a66926a2008-01-14 17:46:18 -08003392 iwl3945_down(priv);
3393
3394 flush_workqueue(priv->workqueue);
Helmut Schaa26635162009-01-15 09:38:44 +01003395
3396 /* start polling the killswitch state again */
3397 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3398 round_jiffies_relative(2 * HZ));
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003399
Tomas Winklere1623442009-01-27 14:27:56 -08003400 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003401}
3402
Johannes Berge039fa42008-05-15 12:55:29 +02003403static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07003404{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003405 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003406
Tomas Winklere1623442009-01-27 14:27:56 -08003407 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003408
Tomas Winklere1623442009-01-27 14:27:56 -08003409 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02003410 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07003411
Johannes Berge039fa42008-05-15 12:55:29 +02003412 if (iwl3945_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07003413 dev_kfree_skb_any(skb);
3414
Tomas Winklere1623442009-01-27 14:27:56 -08003415 IWL_DEBUG_MAC80211(priv, "leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08003416 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07003417}
3418
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003419static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003420 struct ieee80211_if_init_conf *conf)
3421{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003422 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003423 unsigned long flags;
3424
Tomas Winklere1623442009-01-27 14:27:56 -08003425 IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07003426
Johannes Berg32bfd352007-12-19 01:31:26 +01003427 if (priv->vif) {
Tomas Winklere1623442009-01-27 14:27:56 -08003428 IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
Tomas Winkler864792e2007-11-27 21:00:52 +02003429 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07003430 }
3431
3432 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01003433 priv->vif = conf->vif;
Zhu, Yi60294de2008-10-29 14:05:45 -07003434 priv->iw_mode = conf->type;
Zhu Yib481de92007-09-25 17:54:57 -07003435
3436 spin_unlock_irqrestore(&priv->lock, flags);
3437
3438 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02003439
3440 if (conf->mac_addr) {
Tomas Winklere1623442009-01-27 14:27:56 -08003441 IWL_DEBUG_MAC80211(priv, "Set: %pM\n", conf->mac_addr);
Tomas Winkler864792e2007-11-27 21:00:52 +02003442 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
3443 }
3444
Abhijeet Kolekarf45c2712009-04-08 11:26:38 -07003445 if (iwl3945_set_mode(priv, conf->type) == -EAGAIN)
3446 set_bit(STATUS_MODE_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003447
Zhu Yib481de92007-09-25 17:54:57 -07003448 mutex_unlock(&priv->mutex);
3449
Tomas Winklere1623442009-01-27 14:27:56 -08003450 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003451 return 0;
3452}
3453
3454/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003455 * iwl3945_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07003456 *
3457 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
3458 * be set inappropriately and the driver currently sets the hardware up to
3459 * use it whenever needed.
3460 */
Johannes Berge8975582008-10-09 12:18:51 +02003461static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed)
Zhu Yib481de92007-09-25 17:54:57 -07003462{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003463 struct iwl_priv *priv = hw->priv;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08003464 const struct iwl_channel_info *ch_info;
Johannes Berge8975582008-10-09 12:18:51 +02003465 struct ieee80211_conf *conf = &hw->conf;
Zhu Yib481de92007-09-25 17:54:57 -07003466 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08003467 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003468
3469 mutex_lock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08003470 IWL_DEBUG_MAC80211(priv, "enter to channel %d\n",
3471 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07003472
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003473 if (!iwl_is_ready(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003474 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08003475 ret = -EIO;
3476 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003477 }
3478
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08003479 if (unlikely(!iwl3945_mod_params.disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07003480 test_bit(STATUS_SCANNING, &priv->status))) {
Tomas Winklere1623442009-01-27 14:27:56 -08003481 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
Zhu Yia0646472007-12-20 14:10:01 +08003482 set_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003483 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08003484 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07003485 }
3486
3487 spin_lock_irqsave(&priv->lock, flags);
3488
Samuel Ortize6148912009-01-23 13:45:15 -08003489 ch_info = iwl_get_channel_info(priv, conf->channel->band,
3490 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07003491 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003492 IWL_DEBUG_SCAN(priv,
3493 "Channel %d [%d] is INVALID for this band.\n",
3494 conf->channel->hw_value, conf->channel->band);
3495 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
Zhu Yib481de92007-09-25 17:54:57 -07003496 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003497 ret = -EINVAL;
3498 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003499 }
3500
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003501 iwl_set_rxon_channel(priv, conf->channel);
Zhu Yib481de92007-09-25 17:54:57 -07003502
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003503 iwl_set_flags_for_band(priv, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07003504
3505 /* The list of supported rates and rate mask can be different
3506 * for each phymode; since the phymode may have changed, reset
3507 * the rate mask to what mac80211 lists */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003508 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003509
3510 spin_unlock_irqrestore(&priv->lock, flags);
3511
3512#ifdef IEEE80211_CONF_CHANNEL_SWITCH
3513 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003514 iwl3945_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003515 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003516 }
3517#endif
3518
Mohamed Abbas37fec382009-03-17 21:51:42 -07003519 if (changed & IEEE80211_CONF_CHANGE_RADIO_ENABLED) {
3520 if (conf->radio_enabled &&
3521 iwl_radio_kill_sw_enable_radio(priv)) {
3522 IWL_DEBUG_MAC80211(priv, "leave - RF-KILL - "
3523 "waiting for uCode\n");
3524 goto out;
3525 }
Zhu Yib481de92007-09-25 17:54:57 -07003526
Mohamed Abbas37fec382009-03-17 21:51:42 -07003527 if (!conf->radio_enabled) {
3528 iwl_radio_kill_sw_disable_radio(priv);
3529 IWL_DEBUG_MAC80211(priv, "leave - radio disabled\n");
3530 goto out;
3531 }
Zhu Yib481de92007-09-25 17:54:57 -07003532 }
3533
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003534 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003535 IWL_DEBUG_MAC80211(priv, "leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08003536 ret = -EIO;
3537 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003538 }
3539
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003540 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003541
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003542 if (memcmp(&priv->active_rxon,
3543 &priv->staging_rxon, sizeof(priv->staging_rxon)))
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003544 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003545 else
Tomas Winklere1623442009-01-27 14:27:56 -08003546 IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration\n");
Zhu Yib481de92007-09-25 17:54:57 -07003547
Tomas Winklere1623442009-01-27 14:27:56 -08003548 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003549
Zhu Yi76bb77e2007-11-22 10:53:22 +08003550out:
Zhu Yia0646472007-12-20 14:10:01 +08003551 clear_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003552 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003553 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003554}
3555
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003556static void iwl3945_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003557{
3558 int rc = 0;
3559
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08003560 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07003561 return;
3562
3563 /* The following should be done only at AP bring up */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003564 if (!(iwl_is_associated(priv))) {
Zhu Yib481de92007-09-25 17:54:57 -07003565
3566 /* RXON - unassoc (to set timing command) */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003567 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003568 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003569
3570 /* RXON Timing */
Tomas Winkler28afaf92008-12-19 10:37:06 +08003571 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003572 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003573 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
3574 sizeof(priv->rxon_timing),
3575 &priv->rxon_timing);
Zhu Yib481de92007-09-25 17:54:57 -07003576 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003577 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003578 "Attempting to continue.\n");
3579
3580 /* FIXME: what should be the assoc_id for AP? */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003581 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003582 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003583 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07003584 RXON_FLG_SHORT_PREAMBLE_MSK;
3585 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003586 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003587 ~RXON_FLG_SHORT_PREAMBLE_MSK;
3588
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003589 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07003590 if (priv->assoc_capability &
3591 WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003592 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07003593 RXON_FLG_SHORT_SLOT_MSK;
3594 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003595 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003596 ~RXON_FLG_SHORT_SLOT_MSK;
3597
Johannes Berg05c914f2008-09-11 00:01:58 +02003598 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003599 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003600 ~RXON_FLG_SHORT_SLOT_MSK;
3601 }
3602 /* restore RXON assoc */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003603 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003604 iwlcore_commit_rxon(priv);
Abhijeet Kolekar06fd3d82009-04-08 11:26:42 -07003605 priv->cfg->ops->smgmt->add_station(priv, iwl_bcast_addr, 0, 0, NULL);
Zhu Yi556f8db2007-09-27 11:27:33 +08003606 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003607 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003608
3609 /* FIXME - we need to add code here to detect a totally new
3610 * configuration, reset the AP, unassoc, rxon timing, assoc,
3611 * clear sta table, add BCAST sta... */
3612}
3613
Johannes Berg32bfd352007-12-19 01:31:26 +01003614static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
3615 struct ieee80211_vif *vif,
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003616 struct ieee80211_if_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -07003617{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003618 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003619 int rc;
3620
3621 if (conf == NULL)
3622 return -EIO;
3623
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08003624 if (priv->vif != vif) {
Tomas Winklere1623442009-01-27 14:27:56 -08003625 IWL_DEBUG_MAC80211(priv, "leave - priv->vif != vif\n");
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08003626 return 0;
3627 }
3628
Johannes Berg9d139c82008-07-09 14:40:37 +02003629 /* handle this temporarily here */
Johannes Berg05c914f2008-09-11 00:01:58 +02003630 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Johannes Berg9d139c82008-07-09 14:40:37 +02003631 conf->changed & IEEE80211_IFCC_BEACON) {
3632 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
3633 if (!beacon)
3634 return -ENOMEM;
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003635 mutex_lock(&priv->mutex);
Abhijeet Kolekar9944b932009-04-08 11:26:36 -07003636 rc = iwl_mac_beacon_update(hw, beacon);
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003637 mutex_unlock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02003638 if (rc)
3639 return rc;
3640 }
3641
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003642 if (!iwl_is_alive(priv))
Zhu Yi5a66926a2008-01-14 17:46:18 -08003643 return -EAGAIN;
3644
Zhu Yib481de92007-09-25 17:54:57 -07003645 mutex_lock(&priv->mutex);
3646
Zhu Yib481de92007-09-25 17:54:57 -07003647 if (conf->bssid)
Tomas Winklere1623442009-01-27 14:27:56 -08003648 IWL_DEBUG_MAC80211(priv, "bssid: %pM\n", conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07003649
Johannes Berg4150c572007-09-17 01:29:23 -04003650/*
3651 * very dubious code was here; the probe filtering flag is never set:
3652 *
Zhu Yib481de92007-09-25 17:54:57 -07003653 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
3654 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04003655 */
Zhu Yib481de92007-09-25 17:54:57 -07003656
Johannes Berg05c914f2008-09-11 00:01:58 +02003657 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07003658 if (!conf->bssid) {
3659 conf->bssid = priv->mac_addr;
3660 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08003661 IWL_DEBUG_MAC80211(priv, "bssid was set to: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07003662 conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07003663 }
3664 if (priv->ibss_beacon)
3665 dev_kfree_skb(priv->ibss_beacon);
3666
Johannes Berg9d139c82008-07-09 14:40:37 +02003667 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
Zhu Yib481de92007-09-25 17:54:57 -07003668 }
3669
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003670 if (iwl_is_rfkill(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08003671 goto done;
3672
Zhu Yib481de92007-09-25 17:54:57 -07003673 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
3674 !is_multicast_ether_addr(conf->bssid)) {
3675 /* If there is currently a HW scan going on in the background
3676 * then we need to cancel it else the RXON below will fail. */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003677 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003678 IWL_WARN(priv, "Aborted scan still in progress "
Zhu Yib481de92007-09-25 17:54:57 -07003679 "after 100ms\n");
Tomas Winklere1623442009-01-27 14:27:56 -08003680 IWL_DEBUG_MAC80211(priv, "leaving:scan abort failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07003681 mutex_unlock(&priv->mutex);
3682 return -EAGAIN;
3683 }
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003684 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07003685
3686 /* TODO: Audit driver for usage of these members and see
3687 * if mac80211 deprecates them (priv->bssid looks like it
3688 * shouldn't be there, but I haven't scanned the IBSS code
3689 * to verify) - jpk */
3690 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
3691
Johannes Berg05c914f2008-09-11 00:01:58 +02003692 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003693 iwl3945_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003694 else {
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003695 rc = iwlcore_commit_rxon(priv);
Johannes Berg05c914f2008-09-11 00:01:58 +02003696 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
Abhijeet Kolekar40ace5b2009-04-08 11:26:40 -07003697 priv->cfg->ops->smgmt->add_station(priv,
Abhijeet Kolekar06fd3d82009-04-08 11:26:42 -07003698 priv->active_rxon.bssid_addr, 1, 0, NULL);
Zhu Yib481de92007-09-25 17:54:57 -07003699 }
3700
3701 } else {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003702 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003703 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003704 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003705 }
3706
Mohamed Abbasfde35712007-11-29 11:10:15 +08003707 done:
Tomas Winklere1623442009-01-27 14:27:56 -08003708 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003709 mutex_unlock(&priv->mutex);
3710
3711 return 0;
3712}
3713
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003714static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003715 struct ieee80211_if_init_conf *conf)
3716{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003717 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003718
Tomas Winklere1623442009-01-27 14:27:56 -08003719 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003720
3721 mutex_lock(&priv->mutex);
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003722
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003723 if (iwl_is_ready_rf(priv)) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003724 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003725 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003726 iwlcore_commit_rxon(priv);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003727 }
Johannes Berg32bfd352007-12-19 01:31:26 +01003728 if (priv->vif == conf->vif) {
3729 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07003730 memset(priv->bssid, 0, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07003731 }
3732 mutex_unlock(&priv->mutex);
3733
Tomas Winklere1623442009-01-27 14:27:56 -08003734 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003735}
3736
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003737static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01003738 struct ieee80211_vif *vif,
3739 struct ieee80211_sta *sta,
3740 struct ieee80211_key_conf *key)
Zhu Yib481de92007-09-25 17:54:57 -07003741{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003742 struct iwl_priv *priv = hw->priv;
Johannes Bergdc822b52008-12-29 12:55:09 +01003743 const u8 *addr;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003744 int ret = 0;
3745 u8 sta_id = IWL_INVALID_STATION;
3746 u8 static_key;
Zhu Yib481de92007-09-25 17:54:57 -07003747
Tomas Winklere1623442009-01-27 14:27:56 -08003748 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003749
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08003750 if (iwl3945_mod_params.sw_crypto) {
Tomas Winklere1623442009-01-27 14:27:56 -08003751 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
Zhu Yib481de92007-09-25 17:54:57 -07003752 return -EOPNOTSUPP;
3753 }
3754
Winkler, Tomas42986792009-01-19 15:30:22 -08003755 addr = sta ? sta->addr : iwl_bcast_addr;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003756 static_key = !iwl_is_associated(priv);
3757
3758 if (!static_key) {
Abhijeet Kolekar40ace5b2009-04-08 11:26:40 -07003759 sta_id = priv->cfg->ops->smgmt->find_station(priv, addr);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003760 if (sta_id == IWL_INVALID_STATION) {
Joe Perches12514392009-04-16 16:23:26 -07003761 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003762 addr);
3763 return -EINVAL;
3764 }
Zhu Yib481de92007-09-25 17:54:57 -07003765 }
3766
3767 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003768 iwl_scan_cancel_timeout(priv, 100);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003769 mutex_unlock(&priv->mutex);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003770
Zhu Yib481de92007-09-25 17:54:57 -07003771 switch (cmd) {
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003772 case SET_KEY:
3773 if (static_key)
3774 ret = iwl3945_set_static_key(priv, key);
3775 else
3776 ret = iwl3945_set_dynamic_key(priv, key, sta_id);
3777 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003778 break;
3779 case DISABLE_KEY:
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003780 if (static_key)
3781 ret = iwl3945_remove_static_key(priv);
3782 else
3783 ret = iwl3945_clear_sta_key_info(priv, sta_id);
3784 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003785 break;
3786 default:
Winkler, Tomas42986792009-01-19 15:30:22 -08003787 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003788 }
3789
Tomas Winklere1623442009-01-27 14:27:56 -08003790 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003791
Winkler, Tomas42986792009-01-19 15:30:22 -08003792 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003793}
3794
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003795static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003796 struct ieee80211_tx_queue_stats *stats)
3797{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003798 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003799 int i, avail;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08003800 struct iwl_tx_queue *txq;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08003801 struct iwl_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07003802 unsigned long flags;
3803
Tomas Winklere1623442009-01-27 14:27:56 -08003804 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003805
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003806 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003807 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07003808 return -EIO;
3809 }
3810
3811 spin_lock_irqsave(&priv->lock, flags);
3812
3813 for (i = 0; i < AC_NUM; i++) {
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08003814 txq = &priv->txq[i];
Zhu Yib481de92007-09-25 17:54:57 -07003815 q = &txq->q;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08003816 avail = iwl_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07003817
Johannes Berg57ffc582008-04-29 17:18:59 +02003818 stats[i].len = q->n_window - avail;
3819 stats[i].limit = q->n_window - q->high_mark;
3820 stats[i].count = q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -07003821
3822 }
3823 spin_unlock_irqrestore(&priv->lock, flags);
3824
Tomas Winklere1623442009-01-27 14:27:56 -08003825 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003826
3827 return 0;
3828}
3829
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003830static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003831{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003832 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003833 unsigned long flags;
3834
3835 mutex_lock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08003836 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003837
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003838 iwl_reset_qos(priv);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08003839
Zhu Yib481de92007-09-25 17:54:57 -07003840 spin_lock_irqsave(&priv->lock, flags);
3841 priv->assoc_id = 0;
3842 priv->assoc_capability = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003843
3844 /* new association get rid of ibss beacon skb */
3845 if (priv->ibss_beacon)
3846 dev_kfree_skb(priv->ibss_beacon);
3847
3848 priv->ibss_beacon = NULL;
3849
3850 priv->beacon_int = priv->hw->conf.beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08003851 priv->timestamp = 0;
Johannes Berg05c914f2008-09-11 00:01:58 +02003852 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
Zhu Yib481de92007-09-25 17:54:57 -07003853 priv->beacon_int = 0;
3854
3855 spin_unlock_irqrestore(&priv->lock, flags);
3856
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003857 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003858 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +08003859 mutex_unlock(&priv->mutex);
3860 return;
3861 }
3862
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003863 /* we are restarting association process
3864 * clear RXON_FILTER_ASSOC_MSK bit
3865 */
Johannes Berg05c914f2008-09-11 00:01:58 +02003866 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003867 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003868 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003869 iwlcore_commit_rxon(priv);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003870 }
3871
Zhu Yib481de92007-09-25 17:54:57 -07003872 /* Per mac80211.h: This is only used in IBSS mode... */
Johannes Berg05c914f2008-09-11 00:01:58 +02003873 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003874
Tomas Winklere1623442009-01-27 14:27:56 -08003875 IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07003876 mutex_unlock(&priv->mutex);
3877 return;
3878 }
3879
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003880 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003881
3882 mutex_unlock(&priv->mutex);
3883
Tomas Winklere1623442009-01-27 14:27:56 -08003884 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003885
3886}
3887
Zhu Yib481de92007-09-25 17:54:57 -07003888/*****************************************************************************
3889 *
3890 * sysfs attributes
3891 *
3892 *****************************************************************************/
3893
Samuel Ortizd08853a2009-01-23 13:45:17 -08003894#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07003895
3896/*
3897 * The following adds a new attribute to the sysfs representation
3898 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
3899 * used for controlling the debug level.
3900 *
3901 * See the level definitions in iwl for details.
3902 */
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003903static ssize_t show_debug_level(struct device *d,
3904 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07003905{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003906 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003907
3908 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07003909}
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003910static ssize_t store_debug_level(struct device *d,
3911 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07003912 const char *buf, size_t count)
3913{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003914 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003915 unsigned long val;
3916 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003917
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003918 ret = strict_strtoul(buf, 0, &val);
3919 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08003920 IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07003921 else
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003922 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07003923
3924 return strnlen(buf, count);
3925}
3926
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003927static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
3928 show_debug_level, store_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07003929
Samuel Ortizd08853a2009-01-23 13:45:17 -08003930#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07003931
Zhu Yib481de92007-09-25 17:54:57 -07003932static ssize_t show_temperature(struct device *d,
3933 struct device_attribute *attr, char *buf)
3934{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003935 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003936
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003937 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003938 return -EAGAIN;
3939
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003940 return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
Zhu Yib481de92007-09-25 17:54:57 -07003941}
3942
3943static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
3944
Zhu Yib481de92007-09-25 17:54:57 -07003945static ssize_t show_tx_power(struct device *d,
3946 struct device_attribute *attr, char *buf)
3947{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003948 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08003949 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07003950}
3951
3952static ssize_t store_tx_power(struct device *d,
3953 struct device_attribute *attr,
3954 const char *buf, size_t count)
3955{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003956 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003957 char *p = (char *)buf;
3958 u32 val;
3959
3960 val = simple_strtoul(p, &p, 10);
3961 if (p == buf)
Tomas Winkler978785a2008-12-19 10:37:31 +08003962 IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07003963 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003964 iwl3945_hw_reg_set_txpower(priv, val);
Zhu Yib481de92007-09-25 17:54:57 -07003965
3966 return count;
3967}
3968
3969static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
3970
3971static ssize_t show_flags(struct device *d,
3972 struct device_attribute *attr, char *buf)
3973{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003974 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003975
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003976 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
Zhu Yib481de92007-09-25 17:54:57 -07003977}
3978
3979static ssize_t store_flags(struct device *d,
3980 struct device_attribute *attr,
3981 const char *buf, size_t count)
3982{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003983 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003984 u32 flags = simple_strtoul(buf, NULL, 0);
3985
3986 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003987 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
Zhu Yib481de92007-09-25 17:54:57 -07003988 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003989 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003990 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003991 else {
Tomas Winklere1623442009-01-27 14:27:56 -08003992 IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n",
Zhu Yib481de92007-09-25 17:54:57 -07003993 flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003994 priv->staging_rxon.flags = cpu_to_le32(flags);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003995 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003996 }
3997 }
3998 mutex_unlock(&priv->mutex);
3999
4000 return count;
4001}
4002
4003static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
4004
4005static ssize_t show_filter_flags(struct device *d,
4006 struct device_attribute *attr, char *buf)
4007{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004008 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004009
4010 return sprintf(buf, "0x%04X\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004011 le32_to_cpu(priv->active_rxon.filter_flags));
Zhu Yib481de92007-09-25 17:54:57 -07004012}
4013
4014static ssize_t store_filter_flags(struct device *d,
4015 struct device_attribute *attr,
4016 const char *buf, size_t count)
4017{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004018 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004019 u32 filter_flags = simple_strtoul(buf, NULL, 0);
4020
4021 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004022 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
Zhu Yib481de92007-09-25 17:54:57 -07004023 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004024 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004025 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004026 else {
Tomas Winklere1623442009-01-27 14:27:56 -08004027 IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
Zhu Yib481de92007-09-25 17:54:57 -07004028 "0x%04X\n", filter_flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004029 priv->staging_rxon.filter_flags =
Zhu Yib481de92007-09-25 17:54:57 -07004030 cpu_to_le32(filter_flags);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07004031 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004032 }
4033 }
4034 mutex_unlock(&priv->mutex);
4035
4036 return count;
4037}
4038
4039static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
4040 store_filter_flags);
4041
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004042#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07004043
4044static ssize_t show_measurement(struct device *d,
4045 struct device_attribute *attr, char *buf)
4046{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004047 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler600c0e12008-12-19 10:37:04 +08004048 struct iwl_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07004049 u32 size = sizeof(measure_report), len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03004050 u8 *data = (u8 *)&measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07004051 unsigned long flags;
4052
4053 spin_lock_irqsave(&priv->lock, flags);
4054 if (!(priv->measurement_status & MEASUREMENT_READY)) {
4055 spin_unlock_irqrestore(&priv->lock, flags);
4056 return 0;
4057 }
4058 memcpy(&measure_report, &priv->measure_report, size);
4059 priv->measurement_status = 0;
4060 spin_unlock_irqrestore(&priv->lock, flags);
4061
4062 while (size && (PAGE_SIZE - len)) {
4063 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4064 PAGE_SIZE - len, 1);
4065 len = strlen(buf);
4066 if (PAGE_SIZE - len)
4067 buf[len++] = '\n';
4068
4069 ofs += 16;
4070 size -= min(size, 16U);
4071 }
4072
4073 return len;
4074}
4075
4076static ssize_t store_measurement(struct device *d,
4077 struct device_attribute *attr,
4078 const char *buf, size_t count)
4079{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004080 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004081 struct ieee80211_measurement_params params = {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004082 .channel = le16_to_cpu(priv->active_rxon.channel),
Zhu Yib481de92007-09-25 17:54:57 -07004083 .start_time = cpu_to_le64(priv->last_tsf),
4084 .duration = cpu_to_le16(1),
4085 };
4086 u8 type = IWL_MEASURE_BASIC;
4087 u8 buffer[32];
4088 u8 channel;
4089
4090 if (count) {
4091 char *p = buffer;
4092 strncpy(buffer, buf, min(sizeof(buffer), count));
4093 channel = simple_strtoul(p, NULL, 0);
4094 if (channel)
4095 params.channel = channel;
4096
4097 p = buffer;
4098 while (*p && *p != ' ')
4099 p++;
4100 if (*p)
4101 type = simple_strtoul(p + 1, NULL, 0);
4102 }
4103
Tomas Winklere1623442009-01-27 14:27:56 -08004104 IWL_DEBUG_INFO(priv, "Invoking measurement of type %d on "
Zhu Yib481de92007-09-25 17:54:57 -07004105 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004106 iwl3945_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07004107
4108 return count;
4109}
4110
4111static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
4112 show_measurement, store_measurement);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004113#endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07004114
Zhu Yib481de92007-09-25 17:54:57 -07004115static ssize_t store_retry_rate(struct device *d,
4116 struct device_attribute *attr,
4117 const char *buf, size_t count)
4118{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004119 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004120
4121 priv->retry_rate = simple_strtoul(buf, NULL, 0);
4122 if (priv->retry_rate <= 0)
4123 priv->retry_rate = 1;
4124
4125 return count;
4126}
4127
4128static ssize_t show_retry_rate(struct device *d,
4129 struct device_attribute *attr, char *buf)
4130{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004131 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004132 return sprintf(buf, "%d", priv->retry_rate);
4133}
4134
4135static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
4136 store_retry_rate);
4137
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004138
Zhu Yib481de92007-09-25 17:54:57 -07004139static ssize_t store_power_level(struct device *d,
4140 struct device_attribute *attr,
4141 const char *buf, size_t count)
4142{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004143 struct iwl_priv *priv = dev_get_drvdata(d);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004144 int ret;
4145 unsigned long mode;
Zhu Yib481de92007-09-25 17:54:57 -07004146
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004147
Zhu Yib481de92007-09-25 17:54:57 -07004148 mutex_lock(&priv->mutex);
4149
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004150 ret = strict_strtoul(buf, 10, &mode);
4151 if (ret)
4152 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004153
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004154 ret = iwl_power_set_user_mode(priv, mode);
4155 if (ret) {
4156 IWL_DEBUG_MAC80211(priv, "failed setting power mode.\n");
4157 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004158 }
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004159 ret = count;
Zhu Yib481de92007-09-25 17:54:57 -07004160
4161 out:
4162 mutex_unlock(&priv->mutex);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004163 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004164}
4165
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004166static ssize_t show_power_level(struct device *d,
4167 struct device_attribute *attr, char *buf)
4168{
4169 struct iwl_priv *priv = dev_get_drvdata(d);
4170 int mode = priv->power_data.user_power_setting;
4171 int system = priv->power_data.system_power_setting;
4172 int level = priv->power_data.power_mode;
4173 char *p = buf;
4174
4175 switch (system) {
4176 case IWL_POWER_SYS_AUTO:
4177 p += sprintf(p, "SYSTEM:auto");
4178 break;
4179 case IWL_POWER_SYS_AC:
4180 p += sprintf(p, "SYSTEM:ac");
4181 break;
4182 case IWL_POWER_SYS_BATTERY:
4183 p += sprintf(p, "SYSTEM:battery");
4184 break;
4185 }
4186
4187 p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ?
4188 "fixed" : "auto");
4189 p += sprintf(p, "\tINDEX:%d", level);
4190 p += sprintf(p, "\n");
4191 return p - buf + 1;
4192}
4193
4194static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR,
4195 show_power_level, store_power_level);
4196
Zhu Yib481de92007-09-25 17:54:57 -07004197#define MAX_WX_STRING 80
4198
4199/* Values are in microsecond */
4200static const s32 timeout_duration[] = {
4201 350000,
4202 250000,
4203 75000,
4204 37000,
4205 25000,
4206};
4207static const s32 period_duration[] = {
4208 400000,
4209 700000,
4210 1000000,
4211 1000000,
4212 1000000
4213};
4214
Zhu Yib481de92007-09-25 17:54:57 -07004215static ssize_t show_channels(struct device *d,
4216 struct device_attribute *attr, char *buf)
4217{
Johannes Berg8318d782008-01-24 19:38:38 +01004218 /* all this shit doesn't belong into sysfs anyway */
4219 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07004220}
4221
4222static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
4223
4224static ssize_t show_statistics(struct device *d,
4225 struct device_attribute *attr, char *buf)
4226{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004227 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004228 u32 size = sizeof(struct iwl3945_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07004229 u32 len = 0, ofs = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004230 u8 *data = (u8 *)&priv->statistics_39;
Zhu Yib481de92007-09-25 17:54:57 -07004231 int rc = 0;
4232
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004233 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004234 return -EAGAIN;
4235
4236 mutex_lock(&priv->mutex);
Samuel Ortiz17f841c2009-01-23 13:45:20 -08004237 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004238 mutex_unlock(&priv->mutex);
4239
4240 if (rc) {
4241 len = sprintf(buf,
4242 "Error sending statistics request: 0x%08X\n", rc);
4243 return len;
4244 }
4245
4246 while (size && (PAGE_SIZE - len)) {
4247 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4248 PAGE_SIZE - len, 1);
4249 len = strlen(buf);
4250 if (PAGE_SIZE - len)
4251 buf[len++] = '\n';
4252
4253 ofs += 16;
4254 size -= min(size, 16U);
4255 }
4256
4257 return len;
4258}
4259
4260static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
4261
4262static ssize_t show_antenna(struct device *d,
4263 struct device_attribute *attr, char *buf)
4264{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004265 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004266
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004267 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004268 return -EAGAIN;
4269
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08004270 return sprintf(buf, "%d\n", iwl3945_mod_params.antenna);
Zhu Yib481de92007-09-25 17:54:57 -07004271}
4272
4273static ssize_t store_antenna(struct device *d,
4274 struct device_attribute *attr,
4275 const char *buf, size_t count)
4276{
Winkler, Tomas7530f852009-01-27 14:27:53 -08004277 struct iwl_priv *priv __maybe_unused = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004278 int ant;
Zhu Yib481de92007-09-25 17:54:57 -07004279
4280 if (count == 0)
4281 return 0;
4282
4283 if (sscanf(buf, "%1i", &ant) != 1) {
Tomas Winklere1623442009-01-27 14:27:56 -08004284 IWL_DEBUG_INFO(priv, "not in hex or decimal form.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004285 return count;
4286 }
4287
4288 if ((ant >= 0) && (ant <= 2)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004289 IWL_DEBUG_INFO(priv, "Setting antenna select to %d.\n", ant);
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08004290 iwl3945_mod_params.antenna = (enum iwl3945_antenna)ant;
Zhu Yib481de92007-09-25 17:54:57 -07004291 } else
Tomas Winklere1623442009-01-27 14:27:56 -08004292 IWL_DEBUG_INFO(priv, "Bad antenna select value %d.\n", ant);
Zhu Yib481de92007-09-25 17:54:57 -07004293
4294
4295 return count;
4296}
4297
4298static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
4299
4300static ssize_t show_status(struct device *d,
4301 struct device_attribute *attr, char *buf)
4302{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004303 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004304 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004305 return -EAGAIN;
4306 return sprintf(buf, "0x%08x\n", (int)priv->status);
4307}
4308
4309static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
4310
4311static ssize_t dump_error_log(struct device *d,
4312 struct device_attribute *attr,
4313 const char *buf, size_t count)
4314{
4315 char *p = (char *)buf;
4316
4317 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004318 iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07004319
4320 return strnlen(buf, count);
4321}
4322
4323static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
4324
4325static ssize_t dump_event_log(struct device *d,
4326 struct device_attribute *attr,
4327 const char *buf, size_t count)
4328{
4329 char *p = (char *)buf;
4330
4331 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004332 iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07004333
4334 return strnlen(buf, count);
4335}
4336
4337static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
4338
4339/*****************************************************************************
4340 *
Tomas Winklera96a27f2008-10-23 23:48:56 -07004341 * driver setup and tear down
Zhu Yib481de92007-09-25 17:54:57 -07004342 *
4343 *****************************************************************************/
4344
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004345static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004346{
Reinette Chatred21050c2009-02-13 11:51:18 -08004347 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
Zhu Yib481de92007-09-25 17:54:57 -07004348
4349 init_waitqueue_head(&priv->wait_command_queue);
4350
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004351 INIT_WORK(&priv->up, iwl3945_bg_up);
4352 INIT_WORK(&priv->restart, iwl3945_bg_restart);
4353 INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01004354 INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004355 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004356 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
4357 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
Helmut Schaa26635162009-01-15 09:38:44 +01004358 INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll);
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08004359 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
4360 INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
4361 INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
4362 INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
Zhu Yib481de92007-09-25 17:54:57 -07004363
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004364 iwl3945_hw_setup_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004365
4366 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004367 iwl3945_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07004368}
4369
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004370static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004371{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004372 iwl3945_hw_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004373
Joonwoo Parke47eb6a2007-11-29 10:42:49 +09004374 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07004375 cancel_delayed_work(&priv->scan_check);
4376 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07004377 cancel_work_sync(&priv->beacon_update);
4378}
4379
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004380static struct attribute *iwl3945_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07004381 &dev_attr_antenna.attr,
4382 &dev_attr_channels.attr,
4383 &dev_attr_dump_errors.attr,
4384 &dev_attr_dump_events.attr,
4385 &dev_attr_flags.attr,
4386 &dev_attr_filter_flags.attr,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004387#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07004388 &dev_attr_measurement.attr,
4389#endif
4390 &dev_attr_power_level.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004391 &dev_attr_retry_rate.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004392 &dev_attr_statistics.attr,
4393 &dev_attr_status.attr,
4394 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004395 &dev_attr_tx_power.attr,
Samuel Ortizd08853a2009-01-23 13:45:17 -08004396#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004397 &dev_attr_debug_level.attr,
4398#endif
Zhu Yib481de92007-09-25 17:54:57 -07004399 NULL
4400};
4401
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004402static struct attribute_group iwl3945_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07004403 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004404 .attrs = iwl3945_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07004405};
4406
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004407static struct ieee80211_ops iwl3945_hw_ops = {
4408 .tx = iwl3945_mac_tx,
4409 .start = iwl3945_mac_start,
4410 .stop = iwl3945_mac_stop,
4411 .add_interface = iwl3945_mac_add_interface,
4412 .remove_interface = iwl3945_mac_remove_interface,
4413 .config = iwl3945_mac_config,
4414 .config_interface = iwl3945_mac_config_interface,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004415 .configure_filter = iwl_configure_filter,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004416 .set_key = iwl3945_mac_set_key,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004417 .get_tx_stats = iwl3945_mac_get_tx_stats,
Abhijeet Kolekar488829f2009-03-26 10:14:10 -07004418 .conf_tx = iwl_mac_conf_tx,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004419 .reset_tsf = iwl3945_mac_reset_tsf,
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07004420 .bss_info_changed = iwl_bss_info_changed,
Abhijeet Kolekare9dde6f62009-02-18 15:54:27 -08004421 .hw_scan = iwl_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07004422};
4423
Winkler, Tomase52119c2008-12-22 11:31:19 +08004424static int iwl3945_init_drv(struct iwl_priv *priv)
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004425{
4426 int ret;
Samuel Ortize6148912009-01-23 13:45:15 -08004427 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004428
4429 priv->retry_rate = 1;
4430 priv->ibss_beacon = NULL;
4431
4432 spin_lock_init(&priv->lock);
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08004433 spin_lock_init(&priv->power_data.lock);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004434 spin_lock_init(&priv->sta_lock);
4435 spin_lock_init(&priv->hcmd_lock);
4436
4437 INIT_LIST_HEAD(&priv->free_frames);
4438
4439 mutex_init(&priv->mutex);
4440
4441 /* Clear the driver's (not device's) station table */
Abhijeet Kolekar40ace5b2009-04-08 11:26:40 -07004442 priv->cfg->ops->smgmt->clear_station_table(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004443
4444 priv->data_retry_limit = -1;
4445 priv->ieee_channels = NULL;
4446 priv->ieee_rates = NULL;
4447 priv->band = IEEE80211_BAND_2GHZ;
4448
4449 priv->iw_mode = NL80211_IFTYPE_STATION;
4450
4451 iwl_reset_qos(priv);
4452
4453 priv->qos_data.qos_active = 0;
4454 priv->qos_data.qos_cap.val = 0;
4455
4456 priv->rates_mask = IWL_RATES_MASK;
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004457 /* If power management is turned on, default to CAM mode */
4458 priv->power_mode = IWL_POWER_MODE_CAM;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08004459 priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004460
Samuel Ortize6148912009-01-23 13:45:15 -08004461 if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
4462 IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
4463 eeprom->version);
4464 ret = -EINVAL;
4465 goto err;
4466 }
4467 ret = iwl_init_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004468 if (ret) {
4469 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
4470 goto err;
4471 }
4472
Samuel Ortize6148912009-01-23 13:45:15 -08004473 /* Set up txpower settings in driver for all channels */
4474 if (iwl3945_txpower_set_from_eeprom(priv)) {
4475 ret = -EIO;
4476 goto err_free_channel_map;
4477 }
4478
Samuel Ortiz534166d2009-01-23 13:45:16 -08004479 ret = iwlcore_init_geos(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004480 if (ret) {
4481 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
4482 goto err_free_channel_map;
4483 }
Samuel Ortiz534166d2009-01-23 13:45:16 -08004484 iwl3945_init_hw_rates(priv, priv->ieee_rates);
4485
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004486 return 0;
4487
4488err_free_channel_map:
Samuel Ortize6148912009-01-23 13:45:15 -08004489 iwl_free_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004490err:
4491 return ret;
4492}
4493
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004494static int iwl3945_setup_mac(struct iwl_priv *priv)
4495{
4496 int ret;
4497 struct ieee80211_hw *hw = priv->hw;
4498
4499 hw->rate_control_algorithm = "iwl-3945-rs";
4500 hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
4501
4502 /* Tell mac80211 our characteristics */
4503 hw->flags = IEEE80211_HW_SIGNAL_DBM |
Mohamed Abbasb1c60192009-03-17 21:51:47 -07004504 IEEE80211_HW_NOISE_DBM |
4505 IEEE80211_HW_SPECTRUM_MGMT;
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004506
4507 hw->wiphy->interface_modes =
4508 BIT(NL80211_IFTYPE_STATION) |
4509 BIT(NL80211_IFTYPE_ADHOC);
4510
4511 hw->wiphy->custom_regulatory = true;
4512
Johannes Bergd60cc912009-04-09 09:56:02 +02004513 hw->wiphy->max_scan_ssids = 1; /* WILL FIX */
4514
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004515 /* Default value; 4 EDCA QOS priorities */
4516 hw->queues = 4;
4517
4518 hw->conf.beacon_int = 100;
4519
4520 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
4521 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
4522 &priv->bands[IEEE80211_BAND_2GHZ];
4523
4524 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
4525 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
4526 &priv->bands[IEEE80211_BAND_5GHZ];
4527
4528 ret = ieee80211_register_hw(priv->hw);
4529 if (ret) {
4530 IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
4531 return ret;
4532 }
4533 priv->mac80211_registered = 1;
4534
4535 return 0;
4536}
4537
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004538static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07004539{
4540 int err = 0;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004541 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07004542 struct ieee80211_hw *hw;
Kolekar, Abhijeetc0f20d92008-12-19 10:37:19 +08004543 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Samuel Ortize6148912009-01-23 13:45:15 -08004544 struct iwl3945_eeprom *eeprom;
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004545 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07004546
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004547 /***********************
4548 * 1. Allocating HW data
4549 * ********************/
4550
Zhu Yib481de92007-09-25 17:54:57 -07004551 /* mac80211 allocates memory for this device instance, including
4552 * space for this driver's private structure */
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004553 hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
Zhu Yib481de92007-09-25 17:54:57 -07004554 if (hw == NULL) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08004555 printk(KERN_ERR DRV_NAME "Can not allocate network device\n");
Zhu Yib481de92007-09-25 17:54:57 -07004556 err = -ENOMEM;
4557 goto out;
4558 }
Zhu Yib481de92007-09-25 17:54:57 -07004559 priv = hw->priv;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004560 SET_IEEE80211_DEV(hw, &pdev->dev);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004561
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004562 if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) ||
4563 (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004564 IWL_ERR(priv,
4565 "invalid queues_num, should be between %d and %d\n",
4566 IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES);
Samuel Ortiza3139c52008-12-19 10:37:09 +08004567 err = -EINVAL;
Reinette Chatrec8f16132009-02-27 16:21:22 -08004568 goto out_ieee80211_free_hw;
Samuel Ortiza3139c52008-12-19 10:37:09 +08004569 }
4570
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004571 /*
4572 * Disabling hardware scan means that mac80211 will perform scans
4573 * "the hard way", rather than using device's scan.
4574 */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004575 if (iwl3945_mod_params.disable_hw_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08004576 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004577 iwl3945_hw_ops.hw_scan = NULL;
4578 }
4579
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004580
Tomas Winklere1623442009-01-27 14:27:56 -08004581 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004582 priv->cfg = cfg;
4583 priv->pci_dev = pdev;
4584
Samuel Ortizd08853a2009-01-23 13:45:17 -08004585#ifdef CONFIG_IWLWIFI_DEBUG
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004586 priv->debug_level = iwl3945_mod_params.debug;
4587 atomic_set(&priv->restrict_refcnt, 0);
4588#endif
Zhu Yib481de92007-09-25 17:54:57 -07004589
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004590 /***************************
4591 * 2. Initializing PCI bus
4592 * *************************/
Zhu Yib481de92007-09-25 17:54:57 -07004593 if (pci_enable_device(pdev)) {
4594 err = -ENODEV;
4595 goto out_ieee80211_free_hw;
4596 }
4597
4598 pci_set_master(pdev);
4599
Yang Hongyang284901a2009-04-06 19:01:15 -07004600 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Zhu Yib481de92007-09-25 17:54:57 -07004601 if (!err)
Yang Hongyang284901a2009-04-06 19:01:15 -07004602 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Zhu Yib481de92007-09-25 17:54:57 -07004603 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08004604 IWL_WARN(priv, "No suitable DMA available.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004605 goto out_pci_disable_device;
4606 }
4607
4608 pci_set_drvdata(pdev, priv);
4609 err = pci_request_regions(pdev, DRV_NAME);
4610 if (err)
4611 goto out_pci_disable_device;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004612
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004613 /***********************
4614 * 3. Read REV Register
4615 * ********************/
Zhu Yib481de92007-09-25 17:54:57 -07004616 priv->hw_base = pci_iomap(pdev, 0, 0);
4617 if (!priv->hw_base) {
4618 err = -ENODEV;
4619 goto out_pci_release_regions;
4620 }
4621
Tomas Winklere1623442009-01-27 14:27:56 -08004622 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
Zhu Yib481de92007-09-25 17:54:57 -07004623 (unsigned long long) pci_resource_len(pdev, 0));
Tomas Winklere1623442009-01-27 14:27:56 -08004624 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
Zhu Yib481de92007-09-25 17:54:57 -07004625
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004626 /* We disable the RETRY_TIMEOUT register (0x41) to keep
4627 * PCI Tx retries from interfering with C3 CPU state */
4628 pci_write_config_byte(pdev, 0x41, 0x00);
Zhu Yib481de92007-09-25 17:54:57 -07004629
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004630 /* amp init */
4631 err = priv->cfg->ops->lib->apm_ops.init(priv);
Tomas Winkler3ac7f142008-07-21 02:40:14 +03004632 if (err < 0) {
David S. Millerd5df2a12009-03-10 05:04:16 -07004633 IWL_DEBUG_INFO(priv, "Failed to init the card\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004634 goto out_iounmap;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03004635 }
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004636
4637 /***********************
4638 * 4. Read EEPROM
4639 * ********************/
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004640
Zhu Yi5a66926a2008-01-14 17:46:18 -08004641 /* Read the EEPROM */
Samuel Ortize6148912009-01-23 13:45:15 -08004642 err = iwl_eeprom_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004643 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004644 IWL_ERR(priv, "Unable to init EEPROM\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08004645 goto out_iounmap;
Zhu Yi5a66926a2008-01-14 17:46:18 -08004646 }
4647 /* MAC Address location in EEPROM same for 3945/4965 */
Samuel Ortize6148912009-01-23 13:45:15 -08004648 eeprom = (struct iwl3945_eeprom *)priv->eeprom;
4649 memcpy(priv->mac_addr, eeprom->mac_address, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08004650 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr);
Zhu Yi5a66926a2008-01-14 17:46:18 -08004651 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
4652
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004653 /***********************
4654 * 5. Setup HW Constants
4655 * ********************/
4656 /* Device-specific setup */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08004657 if (iwl3945_hw_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004658 IWL_ERR(priv, "failed to set hw settings\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08004659 goto out_eeprom_free;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004660 }
4661
4662 /***********************
4663 * 6. Setup priv
4664 * ********************/
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004665
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004666 err = iwl3945_init_drv(priv);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08004667 if (err) {
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004668 IWL_ERR(priv, "initializing driver failed\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08004669 goto out_unset_hw_params;
Reinette Chatre849e0dc2008-01-23 10:15:18 -08004670 }
Reinette Chatre849e0dc2008-01-23 10:15:18 -08004671
Tomas Winkler978785a2008-12-19 10:37:31 +08004672 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
4673 priv->cfg->name);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004674
4675 /***********************************
4676 * 7. Initialize Module Parameters
4677 * **********************************/
4678
4679 /* Initialize module parameter values here */
4680 /* Disable radio (SW RF KILL) via parameter when loading driver */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004681 if (iwl3945_mod_params.disable) {
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004682 set_bit(STATUS_RF_KILL_SW, &priv->status);
Tomas Winklere1623442009-01-27 14:27:56 -08004683 IWL_DEBUG_INFO(priv, "Radio disabled.\n");
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004684 }
4685
4686
4687 /***********************
4688 * 8. Setup Services
4689 * ********************/
4690
4691 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08004692 iwl_disable_interrupts(priv);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004693 spin_unlock_irqrestore(&priv->lock, flags);
4694
Helmut Schaa26635162009-01-15 09:38:44 +01004695 pci_enable_msi(priv->pci_dev);
4696
Abhijeet Kolekarf17d08a2009-02-18 15:54:31 -08004697 err = request_irq(priv->pci_dev->irq, iwl_isr, IRQF_SHARED,
Helmut Schaa26635162009-01-15 09:38:44 +01004698 DRV_NAME, priv);
4699 if (err) {
4700 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
4701 goto out_disable_msi;
4702 }
4703
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004704 err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
4705 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004706 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004707 goto out_release_irq;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004708 }
4709
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004710 iwl_set_rxon_channel(priv,
4711 &priv->bands[IEEE80211_BAND_2GHZ].channels[5]);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004712 iwl3945_setup_deferred_work(priv);
4713 iwl3945_setup_rx_handlers(priv);
4714
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004715 /*********************************
Helmut Schaa26635162009-01-15 09:38:44 +01004716 * 9. Setup and Register mac80211
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004717 * *******************************/
4718
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004719 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004720
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004721 err = iwl3945_setup_mac(priv);
4722 if (err)
4723 goto out_remove_sysfs;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004724
Samuel Ortizc0af96a2009-01-21 18:27:54 +01004725 err = iwl_rfkill_init(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08004726 if (err)
Winkler, Tomas15b16872008-12-19 10:37:33 +08004727 IWL_ERR(priv, "Unable to initialize RFKILL system. "
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08004728 "Ignoring error: %d\n", err);
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004729 else
4730 iwl_rfkill_set_hw_state(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08004731
Helmut Schaa26635162009-01-15 09:38:44 +01004732 /* Start monitoring the killswitch */
4733 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
4734 2 * HZ);
4735
Zhu Yib481de92007-09-25 17:54:57 -07004736 return 0;
4737
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004738 out_remove_sysfs:
Zhu Yib481de92007-09-25 17:54:57 -07004739 destroy_workqueue(priv->workqueue);
4740 priv->workqueue = NULL;
Reinette Chatrec8f16132009-02-27 16:21:22 -08004741 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
4742 out_release_irq:
4743 free_irq(priv->pci_dev->irq, priv);
Helmut Schaa26635162009-01-15 09:38:44 +01004744 out_disable_msi:
4745 pci_disable_msi(priv->pci_dev);
Reinette Chatrec8f16132009-02-27 16:21:22 -08004746 iwlcore_free_geos(priv);
4747 iwl_free_channel_map(priv);
4748 out_unset_hw_params:
4749 iwl3945_unset_hw_params(priv);
4750 out_eeprom_free:
4751 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004752 out_iounmap:
4753 pci_iounmap(pdev, priv->hw_base);
4754 out_pci_release_regions:
4755 pci_release_regions(pdev);
4756 out_pci_disable_device:
Zhu Yib481de92007-09-25 17:54:57 -07004757 pci_set_drvdata(pdev, NULL);
Reinette Chatre623d5632009-03-03 11:37:04 -08004758 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004759 out_ieee80211_free_hw:
4760 ieee80211_free_hw(priv->hw);
4761 out:
4762 return err;
4763}
4764
Reinette Chatrec83dbf62008-03-21 13:53:41 -07004765static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07004766{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004767 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004768 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07004769
4770 if (!priv)
4771 return;
4772
Tomas Winklere1623442009-01-27 14:27:56 -08004773 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07004774
Zhu Yib481de92007-09-25 17:54:57 -07004775 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08004776
Kolekar, Abhijeetd552bfb2008-12-19 10:37:41 +08004777 if (priv->mac80211_registered) {
4778 ieee80211_unregister_hw(priv->hw);
4779 priv->mac80211_registered = 0;
4780 } else {
4781 iwl3945_down(priv);
4782 }
Zhu Yib481de92007-09-25 17:54:57 -07004783
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004784 /* make sure we flush any pending irq or
4785 * tasklet for the driver
4786 */
4787 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08004788 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004789 spin_unlock_irqrestore(&priv->lock, flags);
4790
4791 iwl_synchronize_irq(priv);
4792
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004793 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07004794
Samuel Ortizc0af96a2009-01-21 18:27:54 +01004795 iwl_rfkill_unregister(priv);
Helmut Schaa26635162009-01-15 09:38:44 +01004796 cancel_delayed_work(&priv->rfkill_poll);
4797
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004798 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004799
4800 if (priv->rxq.bd)
Winkler, Tomas51af3d32008-12-22 11:31:23 +08004801 iwl_rx_queue_free(priv, &priv->rxq);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004802 iwl3945_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004803
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08004804 iwl3945_unset_hw_params(priv);
Abhijeet Kolekar40ace5b2009-04-08 11:26:40 -07004805 priv->cfg->ops->smgmt->clear_station_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004806
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004807 /*netif_stop_queue(dev); */
4808 flush_workqueue(priv->workqueue);
4809
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004810 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07004811 * priv->workqueue... so we can't take down the workqueue
4812 * until now... */
4813 destroy_workqueue(priv->workqueue);
4814 priv->workqueue = NULL;
4815
Helmut Schaa26635162009-01-15 09:38:44 +01004816 free_irq(pdev->irq, priv);
4817 pci_disable_msi(pdev);
4818
Zhu Yib481de92007-09-25 17:54:57 -07004819 pci_iounmap(pdev, priv->hw_base);
4820 pci_release_regions(pdev);
4821 pci_disable_device(pdev);
4822 pci_set_drvdata(pdev, NULL);
4823
Samuel Ortize6148912009-01-23 13:45:15 -08004824 iwl_free_channel_map(priv);
Samuel Ortiz534166d2009-01-23 13:45:16 -08004825 iwlcore_free_geos(priv);
Winkler, Tomas805cee52009-01-19 15:30:28 -08004826 kfree(priv->scan);
Zhu Yib481de92007-09-25 17:54:57 -07004827 if (priv->ibss_beacon)
4828 dev_kfree_skb(priv->ibss_beacon);
4829
4830 ieee80211_free_hw(priv->hw);
4831}
4832
Zhu Yib481de92007-09-25 17:54:57 -07004833
4834/*****************************************************************************
4835 *
4836 * driver and module entry point
4837 *
4838 *****************************************************************************/
4839
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004840static struct pci_driver iwl3945_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07004841 .name = DRV_NAME,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004842 .id_table = iwl3945_hw_card_ids,
4843 .probe = iwl3945_pci_probe,
4844 .remove = __devexit_p(iwl3945_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07004845#ifdef CONFIG_PM
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07004846 .suspend = iwl_pci_suspend,
4847 .resume = iwl_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07004848#endif
4849};
4850
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004851static int __init iwl3945_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07004852{
4853
4854 int ret;
4855 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
4856 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004857
4858 ret = iwl3945_rate_control_register();
4859 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08004860 printk(KERN_ERR DRV_NAME
4861 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004862 return ret;
4863 }
4864
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004865 ret = pci_register_driver(&iwl3945_driver);
Zhu Yib481de92007-09-25 17:54:57 -07004866 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08004867 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004868 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07004869 }
Zhu Yib481de92007-09-25 17:54:57 -07004870
4871 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004872
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004873error_register:
4874 iwl3945_rate_control_unregister();
4875 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004876}
4877
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004878static void __exit iwl3945_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07004879{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004880 pci_unregister_driver(&iwl3945_driver);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004881 iwl3945_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07004882}
4883
Reinette Chatrea0987a82008-12-02 12:14:06 -08004884MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
Zhu Yi25cb6ca2008-09-11 11:45:22 +08004885
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004886module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07004887MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004888module_param_named(disable, iwl3945_mod_params.disable, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07004889MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -08004890module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444);
4891MODULE_PARM_DESC(swcrypto,
4892 "using software crypto (default 1 [software])\n");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004893module_param_named(debug, iwl3945_mod_params.debug, uint, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07004894MODULE_PARM_DESC(debug, "debug output mask");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004895module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07004896MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
4897
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004898module_param_named(queues_num, iwl3945_mod_params.num_of_queues, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07004899MODULE_PARM_DESC(queues_num, "number of hw queues.");
4900
Samuel Ortizaf48d042009-01-23 13:45:19 -08004901module_param_named(fw_restart3945, iwl3945_mod_params.restart_fw, int, 0444);
4902MODULE_PARM_DESC(fw_restart3945, "restart firmware in case of error");
4903
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004904module_exit(iwl3945_exit);
4905module_init(iwl3945_init);