blob: d0d1b7f4c3960ca3e4034779390333a15cedc404 [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>
44#include <net/mac80211.h>
45
46#include <asm/div64.h>
47
Samuel Ortiza3139c52008-12-19 10:37:09 +080048#define DRV_NAME "iwl3945"
49
Winkler, Tomasdbb66542008-12-22 11:31:14 +080050#include "iwl-fh.h"
51#include "iwl-3945-fh.h"
Tomas Winkler600c0e12008-12-19 10:37:04 +080052#include "iwl-commands.h"
Samuel Ortiz17f841c2009-01-23 13:45:20 -080053#include "iwl-sta.h"
Zhu Yib481de92007-09-25 17:54:57 -070054#include "iwl-3945.h"
55#include "iwl-helpers.h"
Kolekar, Abhijeet5747d472008-12-19 10:37:18 +080056#include "iwl-core.h"
Samuel Ortizd20b3c62008-12-19 10:37:15 +080057#include "iwl-dev.h"
Zhu Yib481de92007-09-25 17:54:57 -070058
Zhu Yib481de92007-09-25 17:54:57 -070059/*
60 * module name, copyright, version, etc.
Zhu Yib481de92007-09-25 17:54:57 -070061 */
62
63#define DRV_DESCRIPTION \
64"Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
65
Samuel Ortizd08853a2009-01-23 13:45:17 -080066#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070067#define VD "d"
68#else
69#define VD
70#endif
71
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +080072#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -070073#define VS "s"
74#else
75#define VS
76#endif
77
Kolekar, Abhijeeteaa686c2008-12-19 10:37:17 +080078#define IWL39_VERSION "1.2.26k" VD VS
Reinette Chatre01f81622009-01-08 10:20:02 -080079#define DRV_COPYRIGHT "Copyright(c) 2003-2009 Intel Corporation"
Tomas Winklera7b75202008-12-11 10:33:41 -080080#define DRV_AUTHOR "<ilw@linux.intel.com>"
Kolekar, Abhijeeteaa686c2008-12-19 10:37:17 +080081#define DRV_VERSION IWL39_VERSION
Zhu Yib481de92007-09-25 17:54:57 -070082
Zhu Yib481de92007-09-25 17:54:57 -070083
84MODULE_DESCRIPTION(DRV_DESCRIPTION);
85MODULE_VERSION(DRV_VERSION);
Tomas Winklera7b75202008-12-11 10:33:41 -080086MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
Zhu Yib481de92007-09-25 17:54:57 -070087MODULE_LICENSE("GPL");
88
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080089 /* module parameters */
90struct iwl_mod_params iwl3945_mod_params = {
Reinette Chatre5905a1a2009-07-09 10:33:40 -070091 .num_of_queues = IWL39_NUM_QUEUES, /* Not used */
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -080092 .sw_crypto = 1,
Samuel Ortizaf48d042009-01-23 13:45:19 -080093 .restart_fw = 1,
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080094 /* the rest are 0 by default */
95};
96
Zhu Yib481de92007-09-25 17:54:57 -070097/**
Samuel Ortiz7e4bca52009-01-23 13:45:18 -080098 * iwl3945_get_antenna_flags - Get antenna flags for RXON command
99 * @priv: eeprom and antenna fields are used to determine antenna flags
100 *
101 * priv->eeprom39 is used to determine if antenna AUX/MAIN are reversed
102 * iwl3945_mod_params.antenna specifies the antenna diversity mode:
103 *
104 * IWL_ANTENNA_DIVERSITY - NIC selects best antenna by itself
105 * IWL_ANTENNA_MAIN - Force MAIN antenna
106 * IWL_ANTENNA_AUX - Force AUX antenna
107 */
108__le32 iwl3945_get_antenna_flags(const struct iwl_priv *priv)
109{
110 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
111
112 switch (iwl3945_mod_params.antenna) {
113 case IWL_ANTENNA_DIVERSITY:
114 return 0;
115
116 case IWL_ANTENNA_MAIN:
117 if (eeprom->antenna_switch_type)
118 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
119 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
120
121 case IWL_ANTENNA_AUX:
122 if (eeprom->antenna_switch_type)
123 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
124 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
125 }
126
127 /* bad antenna selector value */
128 IWL_ERR(priv, "Bad antenna selector value (0x%x)\n",
129 iwl3945_mod_params.antenna);
130
131 return 0; /* "diversity" is default if error */
132}
133
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800134static int iwl3945_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700135 struct ieee80211_key_conf *keyconf,
136 u8 sta_id)
137{
138 unsigned long flags;
139 __le16 key_flags = 0;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800140 int ret;
Zhu Yib481de92007-09-25 17:54:57 -0700141
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800142 key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
143 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
144
145 if (sta_id == priv->hw_params.bcast_sta_id)
146 key_flags |= STA_KEY_MULTICAST_MSK;
147
148 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
149 keyconf->hw_key_idx = keyconf->keyidx;
150 key_flags &= ~STA_KEY_FLG_INVALID;
151
Zhu Yib481de92007-09-25 17:54:57 -0700152 spin_lock_irqsave(&priv->sta_lock, flags);
Tomas Winklerc587de02009-06-03 11:44:07 -0700153 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
154 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
155 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700156 keyconf->keylen);
157
Tomas Winklerc587de02009-06-03 11:44:07 -0700158 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700159 keyconf->keylen);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800160
Tomas Winklerc587de02009-06-03 11:44:07 -0700161 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800162 == STA_KEY_FLG_NO_ENC)
Tomas Winklerc587de02009-06-03 11:44:07 -0700163 priv->stations[sta_id].sta.key.key_offset =
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800164 iwl_get_free_ucode_key_index(priv);
165 /* else, we are overriding an existing key => no need to allocated room
166 * in uCode. */
167
Tomas Winklerc587de02009-06-03 11:44:07 -0700168 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800169 "no space for a new key");
170
Tomas Winklerc587de02009-06-03 11:44:07 -0700171 priv->stations[sta_id].sta.key.key_flags = key_flags;
172 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
173 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700174
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800175 IWL_DEBUG_INFO(priv, "hwcrypto: modify ucode station key info\n");
176
Tomas Winklerc587de02009-06-03 11:44:07 -0700177 ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800178
Zhu Yib481de92007-09-25 17:54:57 -0700179 spin_unlock_irqrestore(&priv->sta_lock, flags);
180
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800181 return ret;
182}
183
184static int iwl3945_set_tkip_dynamic_key_info(struct iwl_priv *priv,
185 struct ieee80211_key_conf *keyconf,
186 u8 sta_id)
187{
188 return -EOPNOTSUPP;
189}
190
191static int iwl3945_set_wep_dynamic_key_info(struct iwl_priv *priv,
192 struct ieee80211_key_conf *keyconf,
193 u8 sta_id)
194{
195 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -0700196}
197
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800198static int iwl3945_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
Zhu Yib481de92007-09-25 17:54:57 -0700199{
200 unsigned long flags;
201
202 spin_lock_irqsave(&priv->sta_lock, flags);
Tomas Winklerc587de02009-06-03 11:44:07 -0700203 memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl_hw_key));
204 memset(&priv->stations[sta_id].sta.key, 0,
Tomas Winkler4c897252008-12-19 10:37:05 +0800205 sizeof(struct iwl4965_keyinfo));
Tomas Winklerc587de02009-06-03 11:44:07 -0700206 priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
207 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
208 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700209 spin_unlock_irqrestore(&priv->sta_lock, flags);
210
Tomas Winklere1623442009-01-27 14:27:56 -0800211 IWL_DEBUG_INFO(priv, "hwcrypto: clear ucode station key info\n");
Tomas Winklerc587de02009-06-03 11:44:07 -0700212 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700213 return 0;
214}
215
Abhijeet Kolekarfa11d522009-03-11 11:17:54 -0700216static int iwl3945_set_dynamic_key(struct iwl_priv *priv,
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800217 struct ieee80211_key_conf *keyconf, u8 sta_id)
218{
219 int ret = 0;
220
221 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
222
223 switch (keyconf->alg) {
224 case ALG_CCMP:
225 ret = iwl3945_set_ccmp_dynamic_key_info(priv, keyconf, sta_id);
226 break;
227 case ALG_TKIP:
228 ret = iwl3945_set_tkip_dynamic_key_info(priv, keyconf, sta_id);
229 break;
230 case ALG_WEP:
231 ret = iwl3945_set_wep_dynamic_key_info(priv, keyconf, sta_id);
232 break;
233 default:
Abhijeet Kolekar1e680232009-03-17 21:51:50 -0700234 IWL_ERR(priv, "Unknown alg: %s alg = %d\n", __func__, keyconf->alg);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800235 ret = -EINVAL;
236 }
237
238 IWL_DEBUG_WEP(priv, "Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n",
239 keyconf->alg, keyconf->keylen, keyconf->keyidx,
240 sta_id, ret);
241
242 return ret;
243}
244
245static int iwl3945_remove_static_key(struct iwl_priv *priv)
246{
247 int ret = -EOPNOTSUPP;
248
249 return ret;
250}
251
252static int iwl3945_set_static_key(struct iwl_priv *priv,
253 struct ieee80211_key_conf *key)
254{
255 if (key->alg == ALG_WEP)
256 return -EOPNOTSUPP;
257
258 IWL_ERR(priv, "Static key invalid: alg %d\n", key->alg);
259 return -EINVAL;
260}
261
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800262static void iwl3945_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700263{
264 struct list_head *element;
265
Tomas Winklere1623442009-01-27 14:27:56 -0800266 IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
Zhu Yib481de92007-09-25 17:54:57 -0700267 priv->frames_count);
268
269 while (!list_empty(&priv->free_frames)) {
270 element = priv->free_frames.next;
271 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800272 kfree(list_entry(element, struct iwl3945_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700273 priv->frames_count--;
274 }
275
276 if (priv->frames_count) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800277 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
Zhu Yib481de92007-09-25 17:54:57 -0700278 priv->frames_count);
279 priv->frames_count = 0;
280 }
281}
282
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800283static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700284{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800285 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700286 struct list_head *element;
287 if (list_empty(&priv->free_frames)) {
288 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
289 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800290 IWL_ERR(priv, "Could not allocate frame!\n");
Zhu Yib481de92007-09-25 17:54:57 -0700291 return NULL;
292 }
293
294 priv->frames_count++;
295 return frame;
296 }
297
298 element = priv->free_frames.next;
299 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800300 return list_entry(element, struct iwl3945_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700301}
302
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800303static void iwl3945_free_frame(struct iwl_priv *priv, struct iwl3945_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700304{
305 memset(frame, 0, sizeof(*frame));
306 list_add(&frame->list, &priv->free_frames);
307}
308
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800309unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700310 struct ieee80211_hdr *hdr,
Rami Rosen73ec1cc2008-12-16 09:37:07 +0200311 int left)
Zhu Yib481de92007-09-25 17:54:57 -0700312{
313
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800314 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200315 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
316 (priv->iw_mode != NL80211_IFTYPE_AP)))
Zhu Yib481de92007-09-25 17:54:57 -0700317 return 0;
318
319 if (priv->ibss_beacon->len > left)
320 return 0;
321
322 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
323
324 return priv->ibss_beacon->len;
325}
326
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800327static int iwl3945_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700328{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800329 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700330 unsigned int frame_size;
331 int rc;
332 u8 rate;
333
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800334 frame = iwl3945_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700335
336 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800337 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
Zhu Yib481de92007-09-25 17:54:57 -0700338 "command.\n");
339 return -ENOMEM;
340 }
341
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800342 rate = iwl_rate_get_lowest_plcp(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700343
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800344 frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
Zhu Yib481de92007-09-25 17:54:57 -0700345
Samuel Ortiz518099a2009-01-19 15:30:27 -0800346 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -0700347 &frame->u.cmd[0]);
348
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800349 iwl3945_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -0700350
351 return rc;
352}
353
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800354static void iwl3945_unset_hw_params(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700355{
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800356 if (priv->shared_virt)
Zhu Yib481de92007-09-25 17:54:57 -0700357 pci_free_consistent(priv->pci_dev,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800358 sizeof(struct iwl3945_shared),
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800359 priv->shared_virt,
360 priv->shared_phys);
Zhu Yib481de92007-09-25 17:54:57 -0700361}
362
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800363static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
Johannes Berge039fa42008-05-15 12:55:29 +0200364 struct ieee80211_tx_info *info,
Johannes Bergc2acea82009-07-24 11:13:05 -0700365 struct iwl_device_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -0700366 struct sk_buff *skb_frag,
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800367 int sta_id)
Zhu Yib481de92007-09-25 17:54:57 -0700368{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800369 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
Tomas Winklerc587de02009-06-03 11:44:07 -0700370 struct iwl_hw_key *keyinfo = &priv->stations[sta_id].keyinfo;
Zhu Yib481de92007-09-25 17:54:57 -0700371
372 switch (keyinfo->alg) {
373 case ALG_CCMP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800374 tx->sec_ctl = TX_CMD_SEC_CCM;
375 memcpy(tx->key, keyinfo->key, keyinfo->keylen);
Tomas Winklere1623442009-01-27 14:27:56 -0800376 IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
Zhu Yib481de92007-09-25 17:54:57 -0700377 break;
378
379 case ALG_TKIP:
Zhu Yib481de92007-09-25 17:54:57 -0700380 break;
381
382 case ALG_WEP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800383 tx->sec_ctl = TX_CMD_SEC_WEP |
Johannes Berge039fa42008-05-15 12:55:29 +0200384 (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
Zhu Yib481de92007-09-25 17:54:57 -0700385
386 if (keyinfo->keylen == 13)
Winkler, Tomase52119c2008-12-22 11:31:19 +0800387 tx->sec_ctl |= TX_CMD_SEC_KEY128;
Zhu Yib481de92007-09-25 17:54:57 -0700388
Winkler, Tomase52119c2008-12-22 11:31:19 +0800389 memcpy(&tx->key[3], keyinfo->key, keyinfo->keylen);
Zhu Yib481de92007-09-25 17:54:57 -0700390
Tomas Winklere1623442009-01-27 14:27:56 -0800391 IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
Johannes Berge039fa42008-05-15 12:55:29 +0200392 "with key %d\n", info->control.hw_key->hw_key_idx);
Zhu Yib481de92007-09-25 17:54:57 -0700393 break;
394
Zhu Yib481de92007-09-25 17:54:57 -0700395 default:
Tomas Winkler978785a2008-12-19 10:37:31 +0800396 IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg);
Zhu Yib481de92007-09-25 17:54:57 -0700397 break;
398 }
399}
400
401/*
402 * handle build REPLY_TX command notification.
403 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800404static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
Johannes Bergc2acea82009-07-24 11:13:05 -0700405 struct iwl_device_cmd *cmd,
Johannes Berge039fa42008-05-15 12:55:29 +0200406 struct ieee80211_tx_info *info,
Winkler, Tomase52119c2008-12-22 11:31:19 +0800407 struct ieee80211_hdr *hdr, u8 std_id)
Zhu Yib481de92007-09-25 17:54:57 -0700408{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800409 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
410 __le32 tx_flags = tx->tx_flags;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700411 __le16 fc = hdr->frame_control;
Johannes Berge6a98542008-10-21 12:40:02 +0200412 u8 rc_flags = info->control.rates[0].flags;
Zhu Yib481de92007-09-25 17:54:57 -0700413
Winkler, Tomase52119c2008-12-22 11:31:19 +0800414 tx->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
Johannes Berge039fa42008-05-15 12:55:29 +0200415 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
Zhu Yib481de92007-09-25 17:54:57 -0700416 tx_flags |= TX_CMD_FLG_ACK_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700417 if (ieee80211_is_mgmt(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700418 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700419 if (ieee80211_is_probe_resp(fc) &&
Zhu Yib481de92007-09-25 17:54:57 -0700420 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
421 tx_flags |= TX_CMD_FLG_TSF_MSK;
422 } else {
423 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
424 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
425 }
426
Winkler, Tomase52119c2008-12-22 11:31:19 +0800427 tx->sta_id = std_id;
Harvey Harrison8b7b1e02008-06-11 14:21:56 -0700428 if (ieee80211_has_morefrags(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700429 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
430
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700431 if (ieee80211_is_data_qos(fc)) {
432 u8 *qc = ieee80211_get_qos_ctl(hdr);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800433 tx->tid_tspec = qc[0] & 0xf;
Zhu Yib481de92007-09-25 17:54:57 -0700434 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800435 } else {
Zhu Yib481de92007-09-25 17:54:57 -0700436 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800437 }
Zhu Yib481de92007-09-25 17:54:57 -0700438
Johannes Berge6a98542008-10-21 12:40:02 +0200439 if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
Zhu Yib481de92007-09-25 17:54:57 -0700440 tx_flags |= TX_CMD_FLG_RTS_MSK;
441 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
Johannes Berge6a98542008-10-21 12:40:02 +0200442 } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
Zhu Yib481de92007-09-25 17:54:57 -0700443 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
444 tx_flags |= TX_CMD_FLG_CTS_MSK;
445 }
446
447 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
448 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
449
450 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700451 if (ieee80211_is_mgmt(fc)) {
452 if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
Winkler, Tomase52119c2008-12-22 11:31:19 +0800453 tx->timeout.pm_frame_timeout = cpu_to_le16(3);
Zhu Yib481de92007-09-25 17:54:57 -0700454 else
Winkler, Tomase52119c2008-12-22 11:31:19 +0800455 tx->timeout.pm_frame_timeout = cpu_to_le16(2);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700456 } else {
Winkler, Tomase52119c2008-12-22 11:31:19 +0800457 tx->timeout.pm_frame_timeout = 0;
Abhijeet Kolekar5c8df2d2009-03-11 11:17:55 -0700458#ifdef CONFIG_IWLWIFI_LEDS
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700459 priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
460#endif
461 }
Zhu Yib481de92007-09-25 17:54:57 -0700462
Winkler, Tomase52119c2008-12-22 11:31:19 +0800463 tx->driver_txop = 0;
464 tx->tx_flags = tx_flags;
465 tx->next_frame_len = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700466}
467
Zhu Yib481de92007-09-25 17:54:57 -0700468/*
469 * start REPLY_TX command process
470 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800471static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -0700472{
473 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berge039fa42008-05-15 12:55:29 +0200474 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800475 struct iwl3945_tx_cmd *tx;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800476 struct iwl_tx_queue *txq = NULL;
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800477 struct iwl_queue *q = NULL;
Johannes Bergc2acea82009-07-24 11:13:05 -0700478 struct iwl_device_cmd *out_cmd;
479 struct iwl_cmd_meta *out_meta;
Zhu Yib481de92007-09-25 17:54:57 -0700480 dma_addr_t phys_addr;
481 dma_addr_t txcmd_phys;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800482 int txq_id = skb_get_queue_mapping(skb);
Reinette Chatredf833b12009-04-21 10:55:48 -0700483 u16 len, idx, len_org, hdr_len; /* TODO: len_org is not used */
Tomas Winkler54dbb522008-05-15 13:54:06 +0800484 u8 id;
485 u8 unicast;
Zhu Yib481de92007-09-25 17:54:57 -0700486 u8 sta_id;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800487 u8 tid = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700488 u16 seq_number = 0;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700489 __le16 fc;
Zhu Yib481de92007-09-25 17:54:57 -0700490 u8 wait_write_ptr = 0;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800491 u8 *qc = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700492 unsigned long flags;
493 int rc;
494
495 spin_lock_irqsave(&priv->lock, flags);
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800496 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800497 IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
Zhu Yib481de92007-09-25 17:54:57 -0700498 goto drop_unlock;
499 }
500
Johannes Berge039fa42008-05-15 12:55:29 +0200501 if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800502 IWL_ERR(priv, "ERROR: No TX rate available.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700503 goto drop_unlock;
504 }
505
506 unicast = !is_multicast_ether_addr(hdr->addr1);
507 id = 0;
508
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700509 fc = hdr->frame_control;
Zhu Yib481de92007-09-25 17:54:57 -0700510
Samuel Ortizd08853a2009-01-23 13:45:17 -0800511#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -0700512 if (ieee80211_is_auth(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800513 IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700514 else if (ieee80211_is_assoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800515 IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700516 else if (ieee80211_is_reassoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800517 IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
Zhu Yib481de92007-09-25 17:54:57 -0700518#endif
519
Gábor Stefanikaa065262009-08-21 20:44:09 +0200520 /* drop all non-injected data frame if we are not associated */
Stefanik Gábor914233d2008-06-30 17:23:30 +0800521 if (ieee80211_is_data(fc) &&
Gábor Stefanikaa065262009-08-21 20:44:09 +0200522 !(info->flags & IEEE80211_TX_CTL_INJECTED) &&
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800523 (!iwl_is_associated(priv) ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200524 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
Tomas Winklere1623442009-01-27 14:27:56 -0800525 IWL_DEBUG_DROP(priv, "Dropping - !iwl_is_associated\n");
Zhu Yib481de92007-09-25 17:54:57 -0700526 goto drop_unlock;
527 }
528
529 spin_unlock_irqrestore(&priv->lock, flags);
530
Harvey Harrison7294ec92008-07-15 18:43:59 -0700531 hdr_len = ieee80211_hdrlen(fc);
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800532
533 /* Find (or create) index into station table for destination station */
Gábor Stefanikaa065262009-08-21 20:44:09 +0200534 if (info->flags & IEEE80211_TX_CTL_INJECTED)
535 sta_id = priv->hw_params.bcast_sta_id;
536 else
537 sta_id = iwl_get_sta_id(priv, hdr);
Zhu Yib481de92007-09-25 17:54:57 -0700538 if (sta_id == IWL_INVALID_STATION) {
Tomas Winklere1623442009-01-27 14:27:56 -0800539 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -0700540 hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700541 goto drop;
542 }
543
Tomas Winklere1623442009-01-27 14:27:56 -0800544 IWL_DEBUG_RATE(priv, "station Id %d\n", sta_id);
Zhu Yib481de92007-09-25 17:54:57 -0700545
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700546 if (ieee80211_is_data_qos(fc)) {
547 qc = ieee80211_get_qos_ctl(hdr);
Harvey Harrison7294ec92008-07-15 18:43:59 -0700548 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
Reinette Chatree6a6cf42009-08-13 13:30:50 -0700549 if (unlikely(tid >= MAX_TID_COUNT))
550 goto drop;
Tomas Winklerc587de02009-06-03 11:44:07 -0700551 seq_number = priv->stations[sta_id].tid[tid].seq_number &
Zhu Yib481de92007-09-25 17:54:57 -0700552 IEEE80211_SCTL_SEQ;
553 hdr->seq_ctrl = cpu_to_le16(seq_number) |
554 (hdr->seq_ctrl &
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -0800555 cpu_to_le16(IEEE80211_SCTL_FRAG));
Zhu Yib481de92007-09-25 17:54:57 -0700556 seq_number += 0x10;
557 }
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800558
559 /* Descriptor for chosen Tx queue */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800560 txq = &priv->txq[txq_id];
Zhu Yib481de92007-09-25 17:54:57 -0700561 q = &txq->q;
562
563 spin_lock_irqsave(&priv->lock, flags);
564
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800565 idx = get_cmd_index(q, q->write_ptr, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700566
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800567 /* Set up driver data for this TFD */
Winkler, Tomasdbb66542008-12-22 11:31:14 +0800568 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800569 txq->txb[q->write_ptr].skb[0] = skb;
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800570
571 /* Init first empty entry in queue's array of Tx/cmd buffers */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800572 out_cmd = txq->cmd[idx];
Johannes Bergc2acea82009-07-24 11:13:05 -0700573 out_meta = &txq->meta[idx];
Winkler, Tomase52119c2008-12-22 11:31:19 +0800574 tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload;
Zhu Yib481de92007-09-25 17:54:57 -0700575 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
Winkler, Tomase52119c2008-12-22 11:31:19 +0800576 memset(tx, 0, sizeof(*tx));
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800577
578 /*
579 * Set up the Tx-command (not MAC!) header.
580 * Store the chosen Tx queue and TFD index within the sequence field;
581 * after Tx, uCode's Tx response will return this value so driver can
582 * locate the frame within the tx queue and do post-tx processing.
583 */
Zhu Yib481de92007-09-25 17:54:57 -0700584 out_cmd->hdr.cmd = REPLY_TX;
585 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800586 INDEX_TO_SEQ(q->write_ptr)));
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800587
588 /* Copy MAC header from skb into command buffer */
Winkler, Tomase52119c2008-12-22 11:31:19 +0800589 memcpy(tx->hdr, hdr, hdr_len);
Zhu Yib481de92007-09-25 17:54:57 -0700590
Reinette Chatredf833b12009-04-21 10:55:48 -0700591
592 if (info->control.hw_key)
593 iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, sta_id);
594
595 /* TODO need this for burst mode later on */
596 iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id);
597
598 /* set is_hcca to 0; it probably will never be implemented */
599 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
600
601 /* Total # bytes to be transmitted */
602 len = (u16)skb->len;
603 tx->len = cpu_to_le16(len);
604
Wey-Yi Guy20594eb2009-08-07 15:41:39 -0700605 iwl_dbg_log_tx_data_frame(priv, len, hdr);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700606 iwl_update_stats(priv, true, fc, len);
Reinette Chatredf833b12009-04-21 10:55:48 -0700607 tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
608 tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
609
610 if (!ieee80211_has_morefrags(hdr->frame_control)) {
611 txq->need_update = 1;
612 if (qc)
Tomas Winklerc587de02009-06-03 11:44:07 -0700613 priv->stations[sta_id].tid[tid].seq_number = seq_number;
Reinette Chatredf833b12009-04-21 10:55:48 -0700614 } else {
615 wait_write_ptr = 1;
616 txq->need_update = 0;
617 }
618
619 IWL_DEBUG_TX(priv, "sequence nr = 0X%x \n",
620 le16_to_cpu(out_cmd->hdr.sequence));
621 IWL_DEBUG_TX(priv, "tx_flags = 0X%x \n", le32_to_cpu(tx->tx_flags));
Reinette Chatre3d816c72009-08-07 15:41:37 -0700622 iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx));
623 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr,
Reinette Chatredf833b12009-04-21 10:55:48 -0700624 ieee80211_hdrlen(fc));
625
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800626 /*
627 * Use the first empty entry in this queue's command buffer array
628 * to contain the Tx command and MAC header concatenated together
629 * (payload data will be in another buffer).
630 * Size of this varies, due to varying MAC header length.
631 * If end is not dword aligned, we'll have 2 extra bytes at the end
632 * of the MAC header (device reads on dword boundaries).
633 * We'll tell device about this padding later.
634 */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800635 len = sizeof(struct iwl3945_tx_cmd) +
Tomas Winkler4c897252008-12-19 10:37:05 +0800636 sizeof(struct iwl_cmd_header) + hdr_len;
Zhu Yib481de92007-09-25 17:54:57 -0700637
638 len_org = len;
639 len = (len + 3) & ~3;
640
641 if (len_org != len)
642 len_org = 1;
643 else
644 len_org = 0;
645
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800646 /* Physical address of this Tx command's header (not MAC header!),
647 * within command buffer array. */
Reinette Chatredf833b12009-04-21 10:55:48 -0700648 txcmd_phys = pci_map_single(priv->pci_dev, &out_cmd->hdr,
649 len, PCI_DMA_TODEVICE);
650 /* we do not map meta data ... so we can safely access address to
651 * provide to unmap command*/
Johannes Bergc2acea82009-07-24 11:13:05 -0700652 pci_unmap_addr_set(out_meta, mapping, txcmd_phys);
653 pci_unmap_len_set(out_meta, len, len);
Zhu Yib481de92007-09-25 17:54:57 -0700654
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800655 /* Add buffer containing Tx command and MAC(!) header to TFD's
656 * first entry */
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800657 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
658 txcmd_phys, len, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700659
Zhu Yib481de92007-09-25 17:54:57 -0700660
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800661 /* Set up TFD's 2nd entry to point directly to remainder of skb,
662 * if any (802.11 null frames have no payload). */
Zhu Yib481de92007-09-25 17:54:57 -0700663 len = skb->len - hdr_len;
664 if (len) {
665 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
666 len, PCI_DMA_TODEVICE);
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800667 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
668 phys_addr, len,
669 0, U32_PAD(len));
Zhu Yib481de92007-09-25 17:54:57 -0700670 }
671
Zhu Yib481de92007-09-25 17:54:57 -0700672
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800673 /* Tell device the write index *just past* this latest filled TFD */
Tomas Winklerc54b6792008-03-06 17:36:53 -0800674 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -0800675 rc = iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -0700676 spin_unlock_irqrestore(&priv->lock, flags);
677
678 if (rc)
679 return rc;
680
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800681 if ((iwl_queue_space(q) < q->high_mark)
Zhu Yib481de92007-09-25 17:54:57 -0700682 && priv->mac80211_registered) {
683 if (wait_write_ptr) {
684 spin_lock_irqsave(&priv->lock, flags);
685 txq->need_update = 1;
Samuel Ortiz4f3602c2009-01-19 15:30:25 -0800686 iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -0700687 spin_unlock_irqrestore(&priv->lock, flags);
688 }
689
Johannes Berge4e72fb2009-03-23 17:28:42 +0100690 iwl_stop_queue(priv, skb_get_queue_mapping(skb));
Zhu Yib481de92007-09-25 17:54:57 -0700691 }
692
693 return 0;
694
695drop_unlock:
696 spin_unlock_irqrestore(&priv->lock, flags);
697drop:
698 return -1;
699}
700
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800701#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -0700702
703#include "iwl-spectrum.h"
704
705#define BEACON_TIME_MASK_LOW 0x00FFFFFF
706#define BEACON_TIME_MASK_HIGH 0xFF000000
707#define TIME_UNIT 1024
708
709/*
710 * extended beacon time format
711 * time in usec will be changed into a 32-bit value in 8:24 format
712 * the high 1 byte is the beacon counts
713 * the lower 3 bytes is the time in usec within one beacon interval
714 */
715
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800716static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -0700717{
718 u32 quot;
719 u32 rem;
720 u32 interval = beacon_interval * 1024;
721
722 if (!interval || !usec)
723 return 0;
724
725 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
726 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
727
728 return (quot << 24) + rem;
729}
730
731/* base is usually what we get from ucode with each received frame,
732 * the same as HW timer counter counting down
733 */
734
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800735static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -0700736{
737 u32 base_low = base & BEACON_TIME_MASK_LOW;
738 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
739 u32 interval = beacon_interval * TIME_UNIT;
740 u32 res = (base & BEACON_TIME_MASK_HIGH) +
741 (addon & BEACON_TIME_MASK_HIGH);
742
743 if (base_low > addon_low)
744 res += base_low - addon_low;
745 else if (base_low < addon_low) {
746 res += interval + base_low - addon_low;
747 res += (1 << 24);
748 } else
749 res += (1 << 24);
750
751 return cpu_to_le32(res);
752}
753
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800754static int iwl3945_get_measurement(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700755 struct ieee80211_measurement_params *params,
756 u8 type)
757{
Tomas Winkler600c0e12008-12-19 10:37:04 +0800758 struct iwl_spectrum_cmd spectrum;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800759 struct iwl_rx_packet *res;
Winkler, Tomasc2d79b482008-12-19 10:37:34 +0800760 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700761 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
762 .data = (void *)&spectrum,
Johannes Bergc2acea82009-07-24 11:13:05 -0700763 .flags = CMD_WANT_SKB,
Zhu Yib481de92007-09-25 17:54:57 -0700764 };
765 u32 add_time = le64_to_cpu(params->start_time);
766 int rc;
767 int spectrum_resp_status;
768 int duration = le16_to_cpu(params->duration);
769
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800770 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700771 add_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800772 iwl3945_usecs_to_beacons(
Zhu Yib481de92007-09-25 17:54:57 -0700773 le64_to_cpu(params->start_time) - priv->last_tsf,
774 le16_to_cpu(priv->rxon_timing.beacon_interval));
775
776 memset(&spectrum, 0, sizeof(spectrum));
777
778 spectrum.channel_count = cpu_to_le16(1);
779 spectrum.flags =
780 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
781 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
782 cmd.len = sizeof(spectrum);
783 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
784
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800785 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700786 spectrum.start_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800787 iwl3945_add_beacon_time(priv->last_beacon_time,
Zhu Yib481de92007-09-25 17:54:57 -0700788 add_time,
789 le16_to_cpu(priv->rxon_timing.beacon_interval));
790 else
791 spectrum.start_time = 0;
792
793 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
794 spectrum.channels[0].channel = params->channel;
795 spectrum.channels[0].type = type;
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800796 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
Zhu Yib481de92007-09-25 17:54:57 -0700797 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
798 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
799
Samuel Ortiz518099a2009-01-19 15:30:27 -0800800 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700801 if (rc)
802 return rc;
803
Johannes Bergc2acea82009-07-24 11:13:05 -0700804 res = (struct iwl_rx_packet *)cmd.reply_skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700805 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800806 IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -0700807 rc = -EIO;
808 }
809
810 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
811 switch (spectrum_resp_status) {
812 case 0: /* Command will be handled */
813 if (res->u.spectrum.id != 0xff) {
Tomas Winklere1623442009-01-27 14:27:56 -0800814 IWL_DEBUG_INFO(priv, "Replaced existing measurement: %d\n",
Ian Schrambc434dd2007-10-25 17:15:29 +0800815 res->u.spectrum.id);
Zhu Yib481de92007-09-25 17:54:57 -0700816 priv->measurement_status &= ~MEASUREMENT_READY;
817 }
818 priv->measurement_status |= MEASUREMENT_ACTIVE;
819 rc = 0;
820 break;
821
822 case 1: /* Command will not be handled */
823 rc = -EAGAIN;
824 break;
825 }
826
Johannes Bergc2acea82009-07-24 11:13:05 -0700827 dev_kfree_skb_any(cmd.reply_skb);
Zhu Yib481de92007-09-25 17:54:57 -0700828
829 return rc;
830}
831#endif
832
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800833static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +0800834 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700835{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800836 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
837 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -0700838 struct delayed_work *pwork;
839
840 palive = &pkt->u.alive_frame;
841
Tomas Winklere1623442009-01-27 14:27:56 -0800842 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
Zhu Yib481de92007-09-25 17:54:57 -0700843 "0x%01X 0x%01X\n",
844 palive->is_valid, palive->ver_type,
845 palive->ver_subtype);
846
847 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
Tomas Winklere1623442009-01-27 14:27:56 -0800848 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800849 memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
850 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700851 pwork = &priv->init_alive_start;
852 } else {
Tomas Winklere1623442009-01-27 14:27:56 -0800853 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700854 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800855 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700856 pwork = &priv->alive_start;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800857 iwl3945_disable_events(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700858 }
859
860 /* We delay the ALIVE response by 5ms to
861 * give the HW RF Kill time to activate... */
862 if (palive->is_valid == UCODE_VALID_OK)
863 queue_delayed_work(priv->workqueue, pwork,
864 msecs_to_jiffies(5));
865 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800866 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700867}
868
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800869static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +0800870 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700871{
Helmut Schaac7e035a2009-01-19 13:02:15 +0100872#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800873 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Helmut Schaac7e035a2009-01-19 13:02:15 +0100874#endif
Zhu Yib481de92007-09-25 17:54:57 -0700875
Tomas Winklere1623442009-01-27 14:27:56 -0800876 IWL_DEBUG_RX(priv, "Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
Zhu Yib481de92007-09-25 17:54:57 -0700877 return;
878}
879
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800880static void iwl3945_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -0700881{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800882 struct iwl_priv *priv =
883 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -0700884 struct sk_buff *beacon;
885
886 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +0200887 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -0700888
889 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800890 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -0700891 return;
892 }
893
894 mutex_lock(&priv->mutex);
895 /* new beacon skb is allocated every time; dispose previous.*/
896 if (priv->ibss_beacon)
897 dev_kfree_skb(priv->ibss_beacon);
898
899 priv->ibss_beacon = beacon;
900 mutex_unlock(&priv->mutex);
901
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800902 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700903}
904
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800905static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +0800906 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700907{
Samuel Ortizd08853a2009-01-23 13:45:17 -0800908#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800909 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800910 struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
Zhu Yib481de92007-09-25 17:54:57 -0700911 u8 rate = beacon->beacon_notify_hdr.rate;
912
Tomas Winklere1623442009-01-27 14:27:56 -0800913 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
Zhu Yib481de92007-09-25 17:54:57 -0700914 "tsf %d %d rate %d\n",
915 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
916 beacon->beacon_notify_hdr.failure_frame,
917 le32_to_cpu(beacon->ibss_mgr_status),
918 le32_to_cpu(beacon->high_tsf),
919 le32_to_cpu(beacon->low_tsf), rate);
920#endif
921
Johannes Berg05c914f2008-09-11 00:01:58 +0200922 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -0700923 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
924 queue_work(priv->workqueue, &priv->beacon_update);
925}
926
Zhu Yib481de92007-09-25 17:54:57 -0700927/* Handle notification from uCode that card's power state is changing
928 * due to software, hardware, or critical temperature RFKILL */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800929static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +0800930 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700931{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800932 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700933 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
934 unsigned long status = priv->status;
935
Reinette Chatre4c423a22009-07-17 09:30:26 -0700936 IWL_WARN(priv, "Card state received: HW:%s SW:%s\n",
Zhu Yib481de92007-09-25 17:54:57 -0700937 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
938 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
939
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +0800940 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -0700941 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
942
943 if (flags & HW_CARD_DISABLED)
944 set_bit(STATUS_RF_KILL_HW, &priv->status);
945 else
946 clear_bit(STATUS_RF_KILL_HW, &priv->status);
947
948
Winkler, Tomasaf0053d2009-01-19 15:30:23 -0800949 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700950
951 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
Johannes Berga60e77e2009-06-04 18:26:06 +0200952 test_bit(STATUS_RF_KILL_HW, &priv->status)))
953 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
954 test_bit(STATUS_RF_KILL_HW, &priv->status));
Zhu Yib481de92007-09-25 17:54:57 -0700955 else
956 wake_up_interruptible(&priv->wait_command_queue);
957}
958
959/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800960 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -0700961 *
962 * Setup the RX handlers for each of the reply types sent from the uCode
963 * to the host.
964 *
965 * This function chains into the hardware specific files for them to setup
966 * any hardware specific handlers as well.
967 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800968static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700969{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800970 priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
971 priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
Abhijeet Kolekar261b9c32009-02-18 15:54:29 -0800972 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800973 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -0800974 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700975 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -0800976 iwl_rx_pm_debug_statistics_notif;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800977 priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700978
Ben Cahill9fbab512007-11-29 11:09:47 +0800979 /*
980 * The same handler is used for both the REPLY to a discrete
981 * statistics request from the host as well as for the periodic
982 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -0700983 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800984 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
985 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
Zhu Yib481de92007-09-25 17:54:57 -0700986
Abhijeet Kolekar261b9c32009-02-18 15:54:29 -0800987 iwl_setup_spectrum_handlers(priv);
Abhijeet Kolekarcade0eb2009-02-18 15:54:26 -0800988 iwl_setup_rx_scan_handlers(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800989 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700990
Ben Cahill9fbab512007-11-29 11:09:47 +0800991 /* Set up hardware specific Rx handlers */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800992 iwl3945_hw_rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700993}
994
Zhu Yib481de92007-09-25 17:54:57 -0700995/************************** RX-FUNCTIONS ****************************/
996/*
997 * Rx theory of operation
998 *
999 * The host allocates 32 DMA target addresses and passes the host address
1000 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
1001 * 0 to 31
1002 *
1003 * Rx Queue Indexes
1004 * The host/firmware share two index registers for managing the Rx buffers.
1005 *
1006 * The READ index maps to the first position that the firmware may be writing
1007 * to -- the driver can read up to (but not including) this position and get
1008 * good data.
1009 * The READ index is managed by the firmware once the card is enabled.
1010 *
1011 * The WRITE index maps to the last position the driver has read from -- the
1012 * position preceding WRITE is the last slot the firmware can place a packet.
1013 *
1014 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
1015 * WRITE = READ.
1016 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001017 * During initialization, the host sets up the READ queue position to the first
Zhu Yib481de92007-09-25 17:54:57 -07001018 * INDEX position, and WRITE to the last (READ - 1 wrapped)
1019 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001020 * When the firmware places a packet in a buffer, it will advance the READ index
Zhu Yib481de92007-09-25 17:54:57 -07001021 * and fire the RX interrupt. The driver can then query the READ index and
1022 * process as many packets as possible, moving the WRITE index forward as it
1023 * resets the Rx queue buffers with new memory.
1024 *
1025 * The management in the driver is as follows:
1026 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
1027 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Ian Schram01ebd062007-10-25 17:15:22 +08001028 * to replenish the iwl->rxq->rx_free.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001029 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
Zhu Yib481de92007-09-25 17:54:57 -07001030 * iwl->rxq is replenished and the READ INDEX is updated (updating the
1031 * 'processed' and 'read' driver indexes as well)
1032 * + A received packet is processed and handed to the kernel network stack,
1033 * detached from the iwl->rxq. The driver 'processed' index is updated.
1034 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
1035 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
1036 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
1037 * were enough free buffers and RX_STALLED is set it is cleared.
1038 *
1039 *
1040 * Driver sequence:
1041 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001042 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001043 * iwl3945_rx_queue_restock
Ben Cahill9fbab512007-11-29 11:09:47 +08001044 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
Zhu Yib481de92007-09-25 17:54:57 -07001045 * queue, updates firmware pointers, and updates
1046 * the WRITE index. If insufficient rx_free buffers
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001047 * are available, schedules iwl3945_rx_replenish
Zhu Yib481de92007-09-25 17:54:57 -07001048 *
1049 * -- enable interrupts --
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001050 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
Zhu Yib481de92007-09-25 17:54:57 -07001051 * READ INDEX, detaching the SKB from the pool.
1052 * Moves the packet buffer from queue to rx_used.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001053 * Calls iwl3945_rx_queue_restock to refill any empty
Zhu Yib481de92007-09-25 17:54:57 -07001054 * slots.
1055 * ...
1056 *
1057 */
1058
1059/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001060 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
Zhu Yib481de92007-09-25 17:54:57 -07001061 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001062static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001063 dma_addr_t dma_addr)
1064{
1065 return cpu_to_le32((u32)dma_addr);
1066}
1067
1068/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001069 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
Zhu Yib481de92007-09-25 17:54:57 -07001070 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001071 * If there are slots in the RX queue that need to be restocked,
Zhu Yib481de92007-09-25 17:54:57 -07001072 * and we have free pre-allocated buffers, fill the ranks as much
Ben Cahill9fbab512007-11-29 11:09:47 +08001073 * as we can, pulling from rx_free.
Zhu Yib481de92007-09-25 17:54:57 -07001074 *
1075 * This moves the 'write' index forward to catch up with 'processed', and
1076 * also updates the memory address in the firmware to reference the new
1077 * target buffer.
1078 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001079static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001080{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001081 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001082 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001083 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001084 unsigned long flags;
1085 int write, rc;
1086
1087 spin_lock_irqsave(&rxq->lock, flags);
1088 write = rxq->write & ~0x7;
Winkler, Tomas37d68312009-01-08 10:19:54 -08001089 while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001090 /* Get next free Rx buffer, remove from free list */
Zhu Yib481de92007-09-25 17:54:57 -07001091 element = rxq->rx_free.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001092 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Zhu Yib481de92007-09-25 17:54:57 -07001093 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001094
1095 /* Point to Rx buffer via next RBD in circular buffer */
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001096 rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr);
Zhu Yib481de92007-09-25 17:54:57 -07001097 rxq->queue[rxq->write] = rxb;
1098 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
1099 rxq->free_count--;
1100 }
1101 spin_unlock_irqrestore(&rxq->lock, flags);
1102 /* If the pre-allocated buffer pool is dropping low, schedule to
1103 * refill it */
1104 if (rxq->free_count <= RX_LOW_WATERMARK)
1105 queue_work(priv->workqueue, &priv->rx_replenish);
1106
1107
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001108 /* If we've added more space for the firmware to place data, tell it.
1109 * Increment device's write pointer in multiples of 8. */
Abhijeet Kolekard14d44402009-06-03 11:44:08 -07001110 if ((rxq->write_actual != (rxq->write & ~0x7))
Zhu Yib481de92007-09-25 17:54:57 -07001111 || (abs(rxq->write - rxq->read) > 7)) {
1112 spin_lock_irqsave(&rxq->lock, flags);
1113 rxq->need_update = 1;
1114 spin_unlock_irqrestore(&rxq->lock, flags);
Winkler, Tomas141c43a2009-01-08 10:19:53 -08001115 rc = iwl_rx_queue_update_write_ptr(priv, rxq);
Zhu Yib481de92007-09-25 17:54:57 -07001116 if (rc)
1117 return rc;
1118 }
1119
1120 return 0;
1121}
1122
1123/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001124 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
Zhu Yib481de92007-09-25 17:54:57 -07001125 *
1126 * When moving to rx_free an SKB is allocated for the slot.
1127 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001128 * Also restock the Rx queue via iwl3945_rx_queue_restock.
Ian Schram01ebd062007-10-25 17:15:22 +08001129 * This is called as a scheduled work item (except for during initialization)
Zhu Yib481de92007-09-25 17:54:57 -07001130 */
Abhijeet Kolekard14d44402009-06-03 11:44:08 -07001131static void iwl3945_rx_allocate(struct iwl_priv *priv, gfp_t priority)
Zhu Yib481de92007-09-25 17:54:57 -07001132{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001133 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001134 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001135 struct iwl_rx_mem_buffer *rxb;
Reinette Chatrede0bd502009-09-11 10:38:12 -07001136 struct sk_buff *skb;
Zhu Yib481de92007-09-25 17:54:57 -07001137 unsigned long flags;
Abhijeet Kolekar72240492009-04-30 13:56:26 -07001138
1139 while (1) {
1140 spin_lock_irqsave(&rxq->lock, flags);
1141
1142 if (list_empty(&rxq->rx_used)) {
1143 spin_unlock_irqrestore(&rxq->lock, flags);
1144 return;
1145 }
Abhijeet Kolekar72240492009-04-30 13:56:26 -07001146 spin_unlock_irqrestore(&rxq->lock, flags);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001147
Reinette Chatref82a9242009-09-17 10:43:56 -07001148 if (rxq->free_count > RX_LOW_WATERMARK)
1149 priority |= __GFP_NOWARN;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001150 /* Alloc a new receive buffer */
Reinette Chatrede0bd502009-09-11 10:38:12 -07001151 skb = alloc_skb(priv->hw_params.rx_buf_size, priority);
1152 if (!skb) {
Zhu Yib481de92007-09-25 17:54:57 -07001153 if (net_ratelimit())
Reinette Chatref82a9242009-09-17 10:43:56 -07001154 IWL_DEBUG_INFO(priv, "Failed to allocate SKB buffer.\n");
1155 if ((rxq->free_count <= RX_LOW_WATERMARK) &&
1156 net_ratelimit())
1157 IWL_CRIT(priv, "Failed to allocate SKB buffer with %s. Only %u free buffers remaining.\n",
1158 priority == GFP_ATOMIC ? "GFP_ATOMIC" : "GFP_KERNEL",
1159 rxq->free_count);
Zhu Yib481de92007-09-25 17:54:57 -07001160 /* We don't reschedule replenish work here -- we will
1161 * call the restock method and if it still needs
1162 * more buffers it will schedule replenish */
1163 break;
1164 }
Zhu Yi12342c42007-12-20 11:27:32 +08001165
Reinette Chatrede0bd502009-09-11 10:38:12 -07001166 spin_lock_irqsave(&rxq->lock, flags);
1167 if (list_empty(&rxq->rx_used)) {
1168 spin_unlock_irqrestore(&rxq->lock, flags);
1169 dev_kfree_skb_any(skb);
1170 return;
1171 }
1172 element = rxq->rx_used.next;
1173 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
1174 list_del(element);
1175 spin_unlock_irqrestore(&rxq->lock, flags);
1176
1177 rxb->skb = skb;
1178
Zhu Yi12342c42007-12-20 11:27:32 +08001179 /* If radiotap head is required, reserve some headroom here.
1180 * The physical head count is a variable rx_stats->phy_count.
1181 * We reserve 4 bytes here. Plus these extra bytes, the
1182 * headroom of the physical head should be enough for the
1183 * radiotap head that iwl3945 supported. See iwl3945_rt.
1184 */
1185 skb_reserve(rxb->skb, 4);
1186
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001187 /* Get physical address of RB/SKB */
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001188 rxb->real_dma_addr = pci_map_single(priv->pci_dev,
1189 rxb->skb->data,
1190 priv->hw_params.rx_buf_size,
1191 PCI_DMA_FROMDEVICE);
Abhijeet Kolekar72240492009-04-30 13:56:26 -07001192
1193 spin_lock_irqsave(&rxq->lock, flags);
Zhu Yib481de92007-09-25 17:54:57 -07001194 list_add_tail(&rxb->list, &rxq->rx_free);
Abhijeet Kolekar72240492009-04-30 13:56:26 -07001195 priv->alloc_rxb_skb++;
Zhu Yib481de92007-09-25 17:54:57 -07001196 rxq->free_count++;
Abhijeet Kolekar72240492009-04-30 13:56:26 -07001197 spin_unlock_irqrestore(&rxq->lock, flags);
Zhu Yib481de92007-09-25 17:54:57 -07001198 }
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001199}
1200
Reinette Chatredf833b12009-04-21 10:55:48 -07001201void iwl3945_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
1202{
1203 unsigned long flags;
1204 int i;
1205 spin_lock_irqsave(&rxq->lock, flags);
1206 INIT_LIST_HEAD(&rxq->rx_free);
1207 INIT_LIST_HEAD(&rxq->rx_used);
1208 /* Fill the rx_used queue with _all_ of the Rx buffers */
1209 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
1210 /* In the reset function, these buffers may have been allocated
1211 * to an SKB, so we need to unmap and free potential storage */
1212 if (rxq->pool[i].skb != NULL) {
1213 pci_unmap_single(priv->pci_dev,
1214 rxq->pool[i].real_dma_addr,
1215 priv->hw_params.rx_buf_size,
1216 PCI_DMA_FROMDEVICE);
1217 priv->alloc_rxb_skb--;
1218 dev_kfree_skb(rxq->pool[i].skb);
1219 rxq->pool[i].skb = NULL;
1220 }
1221 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
1222 }
1223
1224 /* Set us so that we have processed and used all buffers, but have
1225 * not restocked the Rx queue with fresh buffers */
1226 rxq->read = rxq->write = 0;
1227 rxq->free_count = 0;
Abhijeet Kolekard14d44402009-06-03 11:44:08 -07001228 rxq->write_actual = 0;
Reinette Chatredf833b12009-04-21 10:55:48 -07001229 spin_unlock_irqrestore(&rxq->lock, flags);
1230}
Reinette Chatredf833b12009-04-21 10:55:48 -07001231
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001232void iwl3945_rx_replenish(void *data)
1233{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001234 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001235 unsigned long flags;
1236
Abhijeet Kolekard14d44402009-06-03 11:44:08 -07001237 iwl3945_rx_allocate(priv, GFP_KERNEL);
Zhu Yib481de92007-09-25 17:54:57 -07001238
1239 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001240 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001241 spin_unlock_irqrestore(&priv->lock, flags);
1242}
1243
Abhijeet Kolekard14d44402009-06-03 11:44:08 -07001244static void iwl3945_rx_replenish_now(struct iwl_priv *priv)
1245{
1246 iwl3945_rx_allocate(priv, GFP_ATOMIC);
1247
1248 iwl3945_rx_queue_restock(priv);
1249}
1250
1251
Reinette Chatredf833b12009-04-21 10:55:48 -07001252/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
1253 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
1254 * This free routine walks the list of POOL entries and if SKB is set to
1255 * non NULL it is unmapped and freed
1256 */
1257static void iwl3945_rx_queue_free(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
1258{
1259 int i;
1260 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
1261 if (rxq->pool[i].skb != NULL) {
1262 pci_unmap_single(priv->pci_dev,
1263 rxq->pool[i].real_dma_addr,
1264 priv->hw_params.rx_buf_size,
1265 PCI_DMA_FROMDEVICE);
1266 dev_kfree_skb(rxq->pool[i].skb);
1267 }
1268 }
1269
1270 pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd,
1271 rxq->dma_addr);
1272 pci_free_consistent(priv->pci_dev, sizeof(struct iwl_rb_status),
1273 rxq->rb_stts, rxq->rb_stts_dma);
1274 rxq->bd = NULL;
1275 rxq->rb_stts = NULL;
1276}
Reinette Chatredf833b12009-04-21 10:55:48 -07001277
1278
Zhu Yib481de92007-09-25 17:54:57 -07001279/* Convert linear signal-to-noise ratio into dB */
1280static u8 ratio2dB[100] = {
1281/* 0 1 2 3 4 5 6 7 8 9 */
1282 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
1283 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
1284 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
1285 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
1286 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
1287 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
1288 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
1289 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
1290 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
1291 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
1292};
1293
1294/* Calculates a relative dB value from a ratio of linear
1295 * (i.e. not dB) signal levels.
1296 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001297int iwl3945_calc_db_from_ratio(int sig_ratio)
Zhu Yib481de92007-09-25 17:54:57 -07001298{
Adrian Bunk221c80c2008-02-02 23:19:01 +02001299 /* 1000:1 or higher just report as 60 dB */
1300 if (sig_ratio >= 1000)
Zhu Yib481de92007-09-25 17:54:57 -07001301 return 60;
1302
Adrian Bunk221c80c2008-02-02 23:19:01 +02001303 /* 100:1 or higher, divide by 10 and use table,
Zhu Yib481de92007-09-25 17:54:57 -07001304 * add 20 dB to make up for divide by 10 */
Adrian Bunk221c80c2008-02-02 23:19:01 +02001305 if (sig_ratio >= 100)
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001306 return 20 + (int)ratio2dB[sig_ratio/10];
Zhu Yib481de92007-09-25 17:54:57 -07001307
1308 /* We shouldn't see this */
1309 if (sig_ratio < 1)
1310 return 0;
1311
1312 /* Use table for ratios 1:1 - 99:1 */
1313 return (int)ratio2dB[sig_ratio];
1314}
1315
1316#define PERFECT_RSSI (-20) /* dBm */
1317#define WORST_RSSI (-95) /* dBm */
1318#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
1319
1320/* Calculate an indication of rx signal quality (a percentage, not dBm!).
1321 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
1322 * about formulas used below. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001323int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
Zhu Yib481de92007-09-25 17:54:57 -07001324{
1325 int sig_qual;
1326 int degradation = PERFECT_RSSI - rssi_dbm;
1327
1328 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
1329 * as indicator; formula is (signal dbm - noise dbm).
1330 * SNR at or above 40 is a great signal (100%).
1331 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
1332 * Weakest usable signal is usually 10 - 15 dB SNR. */
1333 if (noise_dbm) {
1334 if (rssi_dbm - noise_dbm >= 40)
1335 return 100;
1336 else if (rssi_dbm < noise_dbm)
1337 return 0;
1338 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
1339
1340 /* Else use just the signal level.
1341 * This formula is a least squares fit of data points collected and
1342 * compared with a reference system that had a percentage (%) display
1343 * for signal quality. */
1344 } else
1345 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
1346 (15 * RSSI_RANGE + 62 * degradation)) /
1347 (RSSI_RANGE * RSSI_RANGE);
1348
1349 if (sig_qual > 100)
1350 sig_qual = 100;
1351 else if (sig_qual < 1)
1352 sig_qual = 0;
1353
1354 return sig_qual;
1355}
1356
1357/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001358 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07001359 *
1360 * Uses the priv->rx_handlers callback function array to invoke
1361 * the appropriate handlers, including command responses,
1362 * frame-received notifications, and other notifications.
1363 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001364static void iwl3945_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001365{
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001366 struct iwl_rx_mem_buffer *rxb;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001367 struct iwl_rx_packet *pkt;
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001368 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001369 u32 r, i;
1370 int reclaim;
1371 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001372 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08001373 u32 count = 8;
Abhijeet Kolekard14d44402009-06-03 11:44:08 -07001374 int total_empty = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001375
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001376 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1377 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8cd812b2008-12-19 10:37:43 +08001378 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -07001379 i = rxq->read;
1380
Abhijeet Kolekard14d44402009-06-03 11:44:08 -07001381 /* calculate total frames need to be restock after handling RX */
1382 total_empty = r - priv->rxq.write_actual;
1383 if (total_empty < 0)
1384 total_empty += RX_QUEUE_SIZE;
1385
1386 if (total_empty > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001387 fill_rx = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001388 /* Rx interrupt, but nothing sent from uCode */
1389 if (i == r)
Reinette Chatreaf472a952009-08-28 09:58:50 -07001390 IWL_DEBUG_RX(priv, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07001391
1392 while (i != r) {
1393 rxb = rxq->queue[i];
1394
Ben Cahill9fbab512007-11-29 11:09:47 +08001395 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07001396 * then a bug has been introduced in the queue refilling
1397 * routines -- catch it here */
1398 BUG_ON(rxb == NULL);
1399
1400 rxq->queue[i] = NULL;
1401
Reinette Chatredf833b12009-04-21 10:55:48 -07001402 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
1403 priv->hw_params.rx_buf_size,
1404 PCI_DMA_FROMDEVICE);
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001405 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001406
Johannes Bergbe1a71a2009-10-02 13:44:02 -07001407 trace_iwlwifi_dev_rx(priv, pkt,
1408 le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK);
1409
Zhu Yib481de92007-09-25 17:54:57 -07001410 /* Reclaim a command buffer only if this packet is a response
1411 * to a (driver-originated) command.
1412 * If the packet (e.g. Rx frame) originated from uCode,
1413 * there is no command buffer to reclaim.
1414 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1415 * but apparently a few don't get set; catch them here. */
1416 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1417 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1418 (pkt->hdr.cmd != REPLY_TX);
1419
1420 /* Based on type of command response or notification,
1421 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001422 * rx_handlers table. See iwl3945_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07001423 if (priv->rx_handlers[pkt->hdr.cmd]) {
Reinette Chatreaf472a952009-08-28 09:58:50 -07001424 IWL_DEBUG_RX(priv, "r = %d, i = %d, %s, 0x%02x\n", r, i,
Zhu Yib481de92007-09-25 17:54:57 -07001425 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
1426 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001427 priv->isr_stats.rx_handlers[pkt->hdr.cmd]++;
Zhu Yib481de92007-09-25 17:54:57 -07001428 } else {
1429 /* No handling needed */
Reinette Chatreaf472a952009-08-28 09:58:50 -07001430 IWL_DEBUG_RX(priv, "r %d i %d No handler needed for %s, 0x%02x\n",
Zhu Yib481de92007-09-25 17:54:57 -07001431 r, i, get_cmd_string(pkt->hdr.cmd),
1432 pkt->hdr.cmd);
1433 }
1434
1435 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001436 /* Invoke any callbacks, transfer the skb to caller, and
Samuel Ortiz518099a2009-01-19 15:30:27 -08001437 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07001438 * as we reclaim the driver command queue */
1439 if (rxb && rxb->skb)
Abhijeet Kolekar732587a2009-03-11 11:17:57 -07001440 iwl_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001441 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001442 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07001443 }
1444
1445 /* For now we just don't re-use anything. We can tweak this
1446 * later to try and re-use notification packets and SKBs that
1447 * fail to Rx correctly */
1448 if (rxb->skb != NULL) {
1449 priv->alloc_rxb_skb--;
1450 dev_kfree_skb_any(rxb->skb);
1451 rxb->skb = NULL;
1452 }
1453
Zhu Yib481de92007-09-25 17:54:57 -07001454 spin_lock_irqsave(&rxq->lock, flags);
1455 list_add_tail(&rxb->list, &priv->rxq.rx_used);
1456 spin_unlock_irqrestore(&rxq->lock, flags);
1457 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001458 /* If there are a lot of unused frames,
1459 * restock the Rx queue so ucode won't assert. */
1460 if (fill_rx) {
1461 count++;
1462 if (count >= 8) {
1463 priv->rxq.read = i;
Abhijeet Kolekard14d44402009-06-03 11:44:08 -07001464 iwl3945_rx_replenish_now(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001465 count = 0;
1466 }
1467 }
Zhu Yib481de92007-09-25 17:54:57 -07001468 }
1469
1470 /* Backtrack one entry */
1471 priv->rxq.read = i;
Abhijeet Kolekard14d44402009-06-03 11:44:08 -07001472 if (fill_rx)
1473 iwl3945_rx_replenish_now(priv);
1474 else
1475 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001476}
1477
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001478/* call this function to flush any scheduled tasklet */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001479static inline void iwl_synchronize_irq(struct iwl_priv *priv)
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001480{
Tomas Winklera96a27f2008-10-23 23:48:56 -07001481 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001482 synchronize_irq(priv->pci_dev->irq);
1483 tasklet_kill(&priv->irq_tasklet);
1484}
1485
Reinette Chatreb7a79402009-09-25 14:24:23 -07001486#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001487static const char *desc_lookup(int i)
1488{
1489 switch (i) {
1490 case 1:
1491 return "FAIL";
1492 case 2:
1493 return "BAD_PARAM";
1494 case 3:
1495 return "BAD_CHECKSUM";
1496 case 4:
1497 return "NMI_INTERRUPT";
1498 case 5:
1499 return "SYSASSERT";
1500 case 6:
1501 return "FATAL_ERROR";
1502 }
1503
1504 return "UNKNOWN";
1505}
1506
1507#define ERROR_START_OFFSET (1 * sizeof(u32))
1508#define ERROR_ELEM_SIZE (7 * sizeof(u32))
1509
Reinette Chatreb7a79402009-09-25 14:24:23 -07001510void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001511{
1512 u32 i;
1513 u32 desc, time, count, base, data1;
1514 u32 blink1, blink2, ilink1, ilink2;
Zhu Yib481de92007-09-25 17:54:57 -07001515
1516 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
1517
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001518 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001519 IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07001520 return;
1521 }
1522
Zhu Yib481de92007-09-25 17:54:57 -07001523
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001524 count = iwl_read_targ_mem(priv, base);
Zhu Yib481de92007-09-25 17:54:57 -07001525
1526 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001527 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
1528 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
1529 priv->status, count);
Zhu Yib481de92007-09-25 17:54:57 -07001530 }
1531
Winkler, Tomas15b16872008-12-19 10:37:33 +08001532 IWL_ERR(priv, "Desc Time asrtPC blink2 "
Zhu Yib481de92007-09-25 17:54:57 -07001533 "ilink1 nmiPC Line\n");
1534 for (i = ERROR_START_OFFSET;
1535 i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
1536 i += ERROR_ELEM_SIZE) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001537 desc = iwl_read_targ_mem(priv, base + i);
Zhu Yib481de92007-09-25 17:54:57 -07001538 time =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001539 iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001540 blink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001541 iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001542 blink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001543 iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001544 ilink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001545 iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001546 ilink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001547 iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001548 data1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001549 iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001550
Winkler, Tomas15b16872008-12-19 10:37:33 +08001551 IWL_ERR(priv,
1552 "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
1553 desc_lookup(desc), desc, time, blink1, blink2,
1554 ilink1, ilink2, data1);
Johannes Bergbe1a71a2009-10-02 13:44:02 -07001555 trace_iwlwifi_dev_ucode_error(priv, desc, time, data1, 0,
1556 0, blink1, blink2, ilink1, ilink2);
Zhu Yib481de92007-09-25 17:54:57 -07001557 }
Zhu Yib481de92007-09-25 17:54:57 -07001558}
1559
Ben Cahillf58177b2007-11-29 11:09:43 +08001560#define EVENT_START_OFFSET (6 * sizeof(u32))
Zhu Yib481de92007-09-25 17:54:57 -07001561
1562/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001563 * iwl3945_print_event_log - Dump error event log to syslog
Zhu Yib481de92007-09-25 17:54:57 -07001564 *
Zhu Yib481de92007-09-25 17:54:57 -07001565 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001566static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
Zhu Yib481de92007-09-25 17:54:57 -07001567 u32 num_events, u32 mode)
1568{
1569 u32 i;
1570 u32 base; /* SRAM byte address of event log header */
1571 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
1572 u32 ptr; /* SRAM byte address of log data */
1573 u32 ev, time, data; /* event log data */
1574
1575 if (num_events == 0)
1576 return;
1577
1578 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
1579
1580 if (mode == 0)
1581 event_size = 2 * sizeof(u32);
1582 else
1583 event_size = 3 * sizeof(u32);
1584
1585 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
1586
1587 /* "time" is actually "data" for mode 0 (no timestamp).
1588 * place event id # at far right for easier visual parsing. */
1589 for (i = 0; i < num_events; i++) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001590 ev = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07001591 ptr += sizeof(u32);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001592 time = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07001593 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08001594 if (mode == 0) {
1595 /* data, ev */
1596 IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
Johannes Bergbe1a71a2009-10-02 13:44:02 -07001597 trace_iwlwifi_dev_ucode_event(priv, 0, time, ev);
Winkler, Tomas15b16872008-12-19 10:37:33 +08001598 } else {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001599 data = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07001600 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08001601 IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev);
Johannes Bergbe1a71a2009-10-02 13:44:02 -07001602 trace_iwlwifi_dev_ucode_event(priv, time, data, ev);
Zhu Yib481de92007-09-25 17:54:57 -07001603 }
1604 }
1605}
1606
Reinette Chatreb7a79402009-09-25 14:24:23 -07001607void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001608{
Zhu Yib481de92007-09-25 17:54:57 -07001609 u32 base; /* SRAM byte address of event log header */
1610 u32 capacity; /* event log capacity in # entries */
1611 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
1612 u32 num_wraps; /* # times uCode wrapped to top of log */
1613 u32 next_entry; /* index of next entry to be written by uCode */
1614 u32 size; /* # entries that we'll print */
1615
1616 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001617 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001618 IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07001619 return;
1620 }
1621
Zhu Yib481de92007-09-25 17:54:57 -07001622 /* event log header */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001623 capacity = iwl_read_targ_mem(priv, base);
1624 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
1625 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
1626 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
Zhu Yib481de92007-09-25 17:54:57 -07001627
1628 size = num_wraps ? capacity : next_entry;
1629
1630 /* bail out if nothing in log */
1631 if (size == 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001632 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
Zhu Yib481de92007-09-25 17:54:57 -07001633 return;
1634 }
1635
Winkler, Tomas15b16872008-12-19 10:37:33 +08001636 IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07001637 size, num_wraps);
1638
1639 /* if uCode has wrapped back to top of log, start at the oldest entry,
1640 * i.e the next one that uCode would fill. */
1641 if (num_wraps)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001642 iwl3945_print_event_log(priv, next_entry,
Zhu Yib481de92007-09-25 17:54:57 -07001643 capacity - next_entry, mode);
1644
1645 /* (then/else) start at top of log */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001646 iwl3945_print_event_log(priv, 0, next_entry, mode);
Zhu Yib481de92007-09-25 17:54:57 -07001647
Zhu Yib481de92007-09-25 17:54:57 -07001648}
Reinette Chatreb7a79402009-09-25 14:24:23 -07001649#else
1650void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
1651{
1652}
1653
1654void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
1655{
1656}
1657
1658#endif
Zhu Yib481de92007-09-25 17:54:57 -07001659
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001660static void iwl3945_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001661{
1662 u32 inta, handled = 0;
1663 u32 inta_fh;
1664 unsigned long flags;
Samuel Ortizd08853a2009-01-23 13:45:17 -08001665#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001666 u32 inta_mask;
1667#endif
1668
1669 spin_lock_irqsave(&priv->lock, flags);
1670
1671 /* Ack/clear/reset pending uCode interrupts.
1672 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1673 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001674 inta = iwl_read32(priv, CSR_INT);
1675 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07001676
1677 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
1678 * Any new interrupts that happen after this, either while we're
1679 * in this tasklet, or later, will show up in next ISR/tasklet. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001680 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1681 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001682
Samuel Ortizd08853a2009-01-23 13:45:17 -08001683#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001684 if (iwl_get_debug_level(priv) & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001685 /* just for debug */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001686 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Tomas Winklere1623442009-01-27 14:27:56 -08001687 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07001688 inta, inta_mask, inta_fh);
1689 }
1690#endif
1691
1692 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
1693 * atomic, make sure that inta covers all the interrupts that
1694 * we've discovered, even if FH interrupt came in just after
1695 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001696 if (inta_fh & CSR39_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001697 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001698 if (inta_fh & CSR39_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001699 inta |= CSR_INT_BIT_FH_TX;
1700
1701 /* Now service all interrupt bits discovered above. */
1702 if (inta & CSR_INT_BIT_HW_ERR) {
Reinette Chatre58dba722009-07-17 09:30:25 -07001703 IWL_ERR(priv, "Hardware error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001704
1705 /* Tell the device to stop sending interrupts */
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08001706 iwl_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001707
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001708 priv->isr_stats.hw++;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001709 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001710
1711 handled |= CSR_INT_BIT_HW_ERR;
1712
1713 spin_unlock_irqrestore(&priv->lock, flags);
1714
1715 return;
1716 }
1717
Samuel Ortizd08853a2009-01-23 13:45:17 -08001718#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001719 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07001720 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001721 if (inta & CSR_INT_BIT_SCD) {
Tomas Winklere1623442009-01-27 14:27:56 -08001722 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
Joonwoo Park25c03d82008-01-23 10:15:20 -08001723 "the frame/frames.\n");
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001724 priv->isr_stats.sch++;
1725 }
Zhu Yib481de92007-09-25 17:54:57 -07001726
1727 /* Alive notification via Rx interrupt will do the real work */
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001728 if (inta & CSR_INT_BIT_ALIVE) {
Tomas Winklere1623442009-01-27 14:27:56 -08001729 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001730 priv->isr_stats.alive++;
1731 }
Zhu Yib481de92007-09-25 17:54:57 -07001732 }
1733#endif
1734 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001735 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07001736
Zhu Yib481de92007-09-25 17:54:57 -07001737 /* Error detected by uCode */
1738 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001739 IWL_ERR(priv, "Microcode SW error detected. "
1740 "Restarting 0x%X.\n", inta);
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001741 priv->isr_stats.sw++;
1742 priv->isr_stats.sw_err = inta;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001743 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001744 handled |= CSR_INT_BIT_SW_ERR;
1745 }
1746
1747 /* uCode wakes up after power-down sleep */
1748 if (inta & CSR_INT_BIT_WAKEUP) {
Tomas Winklere1623442009-01-27 14:27:56 -08001749 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
Winkler, Tomas141c43a2009-01-08 10:19:53 -08001750 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001751 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
1752 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
1753 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
1754 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
1755 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
1756 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07001757
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001758 priv->isr_stats.wakeup++;
Zhu Yib481de92007-09-25 17:54:57 -07001759 handled |= CSR_INT_BIT_WAKEUP;
1760 }
1761
1762 /* All uCode command responses, including Tx command responses,
1763 * Rx "responses" (frame-received notification), and other
1764 * notifications from uCode come through here*/
1765 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001766 iwl3945_rx_handle(priv);
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001767 priv->isr_stats.rx++;
Zhu Yib481de92007-09-25 17:54:57 -07001768 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1769 }
1770
1771 if (inta & CSR_INT_BIT_FH_TX) {
Tomas Winklere1623442009-01-27 14:27:56 -08001772 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001773 priv->isr_stats.tx++;
Zhu Yib481de92007-09-25 17:54:57 -07001774
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001775 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07001776 iwl_write_direct32(priv, FH39_TCSR_CREDIT
1777 (FH39_SRVC_CHNL), 0x0);
Zhu Yib481de92007-09-25 17:54:57 -07001778 handled |= CSR_INT_BIT_FH_TX;
1779 }
1780
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001781 if (inta & ~handled) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001782 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001783 priv->isr_stats.unhandled++;
1784 }
Zhu Yib481de92007-09-25 17:54:57 -07001785
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001786 if (inta & ~priv->inta_mask) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001787 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001788 inta & ~priv->inta_mask);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001789 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001790 }
1791
1792 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001793 /* only Re-enable if disabled by irq */
1794 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08001795 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001796
Samuel Ortizd08853a2009-01-23 13:45:17 -08001797#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001798 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001799 inta = iwl_read32(priv, CSR_INT);
1800 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1801 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Tomas Winklere1623442009-01-27 14:27:56 -08001802 IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
Zhu Yib481de92007-09-25 17:54:57 -07001803 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
1804 }
1805#endif
1806 spin_unlock_irqrestore(&priv->lock, flags);
1807}
1808
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001809static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01001810 enum ieee80211_band band,
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08001811 u8 is_active, u8 n_probes,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001812 struct iwl3945_scan_channel *scan_ch)
Zhu Yib481de92007-09-25 17:54:57 -07001813{
Johannes Berg4e05c232009-06-19 13:52:44 -07001814 struct ieee80211_channel *chan;
Johannes Berg8318d782008-01-24 19:38:38 +01001815 const struct ieee80211_supported_band *sband;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001816 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07001817 u16 passive_dwell = 0;
1818 u16 active_dwell = 0;
1819 int added, i;
1820
Kolekar, Abhijeetcbba18c2008-12-19 10:37:42 +08001821 sband = iwl_get_hw_mode(priv, band);
Johannes Berg8318d782008-01-24 19:38:38 +01001822 if (!sband)
Zhu Yib481de92007-09-25 17:54:57 -07001823 return 0;
1824
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08001825 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
1826 passive_dwell = iwl_get_passive_dwell_time(priv, band);
Zhu Yib481de92007-09-25 17:54:57 -07001827
Abhijeet Kolekar8f4807a2008-09-03 11:26:31 +08001828 if (passive_dwell <= active_dwell)
1829 passive_dwell = active_dwell + 1;
1830
Johannes Berg4e05c232009-06-19 13:52:44 -07001831 for (i = 0, added = 0; i < priv->scan_request->n_channels; i++) {
1832 chan = priv->scan_request->channels[i];
1833
1834 if (chan->band != band)
Johannes Berg182e2e62008-04-04 10:41:56 +02001835 continue;
1836
Johannes Berg4e05c232009-06-19 13:52:44 -07001837 scan_ch->channel = chan->hw_value;
Zhu Yib481de92007-09-25 17:54:57 -07001838
Samuel Ortize6148912009-01-23 13:45:15 -08001839 ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
Zhu Yib481de92007-09-25 17:54:57 -07001840 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08001841 IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
Zhu Yib481de92007-09-25 17:54:57 -07001842 scan_ch->channel);
1843 continue;
1844 }
1845
Zhu Yib481de92007-09-25 17:54:57 -07001846 scan_ch->active_dwell = cpu_to_le16(active_dwell);
1847 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08001848 /* If passive , set up for auto-switch
1849 * and use long active_dwell time.
1850 */
1851 if (!is_active || is_channel_passive(ch_info) ||
Johannes Berg4e05c232009-06-19 13:52:44 -07001852 (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08001853 scan_ch->type = 0; /* passive */
1854 if (IWL_UCODE_API(priv->ucode_ver) == 1)
1855 scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
1856 } else {
1857 scan_ch->type = 1; /* active */
1858 }
1859
1860 /* Set direct probe bits. These may be used both for active
1861 * scan channels (probes gets sent right away),
1862 * or for passive channels (probes get se sent only after
1863 * hearing clear Rx packet).*/
1864 if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
1865 if (n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08001866 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08001867 } else {
1868 /* uCode v1 does not allow setting direct probe bits on
1869 * passive channel. */
1870 if ((scan_ch->type & 1) && n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08001871 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08001872 }
Zhu Yib481de92007-09-25 17:54:57 -07001873
Ben Cahill9fbab512007-11-29 11:09:47 +08001874 /* Set txpower levels to defaults */
Zhu Yib481de92007-09-25 17:54:57 -07001875 scan_ch->tpc.dsp_atten = 110;
1876 /* scan_pwr_info->tpc.dsp_atten; */
1877
1878 /*scan_pwr_info->tpc.tx_gain; */
Johannes Berg8318d782008-01-24 19:38:38 +01001879 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -07001880 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
1881 else {
1882 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
1883 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
Ben Cahill9fbab512007-11-29 11:09:47 +08001884 * power level:
Reinette Chatre8a1b0242008-01-14 17:46:25 -08001885 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
Zhu Yib481de92007-09-25 17:54:57 -07001886 */
1887 }
1888
Tomas Winklere1623442009-01-27 14:27:56 -08001889 IWL_DEBUG_SCAN(priv, "Scanning %d [%s %d]\n",
Zhu Yib481de92007-09-25 17:54:57 -07001890 scan_ch->channel,
1891 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
1892 (scan_ch->type & 1) ?
1893 active_dwell : passive_dwell);
1894
1895 scan_ch++;
1896 added++;
1897 }
1898
Tomas Winklere1623442009-01-27 14:27:56 -08001899 IWL_DEBUG_SCAN(priv, "total channels to scan %d \n", added);
Zhu Yib481de92007-09-25 17:54:57 -07001900 return added;
1901}
1902
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001903static void iwl3945_init_hw_rates(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001904 struct ieee80211_rate *rates)
1905{
1906 int i;
1907
1908 for (i = 0; i < IWL_RATE_COUNT; i++) {
Johannes Berg8318d782008-01-24 19:38:38 +01001909 rates[i].bitrate = iwl3945_rates[i].ieee * 5;
1910 rates[i].hw_value = i; /* Rate scaling will work on indexes */
1911 rates[i].hw_value_short = i;
1912 rates[i].flags = 0;
Samuel Ortizd9829a62008-12-19 10:37:12 +08001913 if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
Zhu Yib481de92007-09-25 17:54:57 -07001914 /*
Johannes Berg8318d782008-01-24 19:38:38 +01001915 * If CCK != 1M then set short preamble rate flag.
Zhu Yib481de92007-09-25 17:54:57 -07001916 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001917 rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
Johannes Berg8318d782008-01-24 19:38:38 +01001918 0 : IEEE80211_RATE_SHORT_PREAMBLE;
Zhu Yib481de92007-09-25 17:54:57 -07001919 }
Zhu Yib481de92007-09-25 17:54:57 -07001920 }
1921}
1922
Zhu Yib481de92007-09-25 17:54:57 -07001923/******************************************************************************
1924 *
1925 * uCode download functions
1926 *
1927 ******************************************************************************/
1928
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001929static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001930{
Tomas Winkler98c92212008-01-14 17:46:20 -08001931 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
1932 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
1933 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
1934 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
1935 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
1936 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001937}
1938
1939/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001940 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07001941 * looking at all data.
1942 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001943static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07001944{
1945 u32 val;
1946 u32 save_len = len;
1947 int rc = 0;
1948 u32 errcnt;
1949
Tomas Winklere1623442009-01-27 14:27:56 -08001950 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001951
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001952 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08001953 IWL39_RTC_INST_LOWER_BOUND);
Zhu Yib481de92007-09-25 17:54:57 -07001954
1955 errcnt = 0;
1956 for (; len > 0; len -= sizeof(u32), image++) {
1957 /* read data comes through single port, auto-incr addr */
1958 /* NOTE: Use the debugless read so we don't flood kernel log
1959 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001960 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07001961 if (val != le32_to_cpu(*image)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001962 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07001963 "offset 0x%x, is 0x%x, s/b 0x%x\n",
1964 save_len - len, val, le32_to_cpu(*image));
1965 rc = -EIO;
1966 errcnt++;
1967 if (errcnt >= 20)
1968 break;
1969 }
1970 }
1971
Zhu Yib481de92007-09-25 17:54:57 -07001972
1973 if (!errcnt)
Tomas Winklere1623442009-01-27 14:27:56 -08001974 IWL_DEBUG_INFO(priv,
1975 "ucode image in INSTRUCTION memory is good\n");
Zhu Yib481de92007-09-25 17:54:57 -07001976
1977 return rc;
1978}
1979
1980
1981/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001982 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07001983 * using sample data 100 bytes apart. If these sample points are good,
1984 * it's a pretty good bet that everything between them is good, too.
1985 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001986static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07001987{
1988 u32 val;
1989 int rc = 0;
1990 u32 errcnt = 0;
1991 u32 i;
1992
Tomas Winklere1623442009-01-27 14:27:56 -08001993 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001994
Zhu Yib481de92007-09-25 17:54:57 -07001995 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
1996 /* read data comes through single port, auto-incr addr */
1997 /* NOTE: Use the debugless read so we don't flood kernel log
1998 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001999 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002000 i + IWL39_RTC_INST_LOWER_BOUND);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002001 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002002 if (val != le32_to_cpu(*image)) {
2003#if 0 /* Enable this if you want to see details */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002004 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002005 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2006 i, val, *image);
2007#endif
2008 rc = -EIO;
2009 errcnt++;
2010 if (errcnt >= 3)
2011 break;
2012 }
2013 }
2014
Zhu Yib481de92007-09-25 17:54:57 -07002015 return rc;
2016}
2017
2018
2019/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002020 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
Zhu Yib481de92007-09-25 17:54:57 -07002021 * and verify its contents
2022 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002023static int iwl3945_verify_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002024{
2025 __le32 *image;
2026 u32 len;
2027 int rc = 0;
2028
2029 /* Try bootstrap */
2030 image = (__le32 *)priv->ucode_boot.v_addr;
2031 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002032 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002033 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002034 IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002035 return 0;
2036 }
2037
2038 /* Try initialize */
2039 image = (__le32 *)priv->ucode_init.v_addr;
2040 len = priv->ucode_init.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002041 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002042 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002043 IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002044 return 0;
2045 }
2046
2047 /* Try runtime/protocol */
2048 image = (__le32 *)priv->ucode_code.v_addr;
2049 len = priv->ucode_code.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002050 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002051 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002052 IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002053 return 0;
2054 }
2055
Winkler, Tomas15b16872008-12-19 10:37:33 +08002056 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
Zhu Yib481de92007-09-25 17:54:57 -07002057
Ben Cahill9fbab512007-11-29 11:09:47 +08002058 /* Since nothing seems to match, show first several data entries in
2059 * instruction SRAM, so maybe visual inspection will give a clue.
2060 * Selection of bootstrap image (vs. other images) is arbitrary. */
Zhu Yib481de92007-09-25 17:54:57 -07002061 image = (__le32 *)priv->ucode_boot.v_addr;
2062 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002063 rc = iwl3945_verify_inst_full(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002064
2065 return rc;
2066}
2067
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002068static void iwl3945_nic_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002069{
2070 /* Remove all resets to allow NIC to operate */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002071 iwl_write32(priv, CSR_RESET, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002072}
2073
2074/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002075 * iwl3945_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07002076 *
2077 * Copy into buffers for card to fetch via bus-mastering
2078 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002079static int iwl3945_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002080{
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002081 const struct iwl_ucode_header *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002082 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07002083 const struct firmware *ucode_raw;
2084 /* firmware file name contains uCode/driver compatibility version */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002085 const char *name_pre = priv->cfg->fw_name_pre;
2086 const unsigned int api_max = priv->cfg->ucode_api_max;
2087 const unsigned int api_min = priv->cfg->ucode_api_min;
2088 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07002089 u8 *src;
2090 size_t len;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002091 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
Zhu Yib481de92007-09-25 17:54:57 -07002092
2093 /* Ask kernel firmware_class module to get the boot firmware off disk.
2094 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002095 for (index = api_max; index >= api_min; index--) {
2096 sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
2097 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
2098 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002099 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002100 buf, ret);
2101 if (ret == -ENOENT)
2102 continue;
2103 else
2104 goto error;
2105 } else {
2106 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002107 IWL_ERR(priv, "Loaded firmware %s, "
2108 "which is deprecated. "
2109 " Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002110 buf, api_max);
Tomas Winklere1623442009-01-27 14:27:56 -08002111 IWL_DEBUG_INFO(priv, "Got firmware '%s' file "
2112 "(%zd bytes) from disk\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002113 buf, ucode_raw->size);
2114 break;
2115 }
Zhu Yib481de92007-09-25 17:54:57 -07002116 }
2117
Reinette Chatrea0987a82008-12-02 12:14:06 -08002118 if (ret < 0)
2119 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07002120
2121 /* Make sure that we got at least our header! */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002122 if (ucode_raw->size < priv->cfg->ops->ucode->get_header_size(1)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002123 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002124 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002125 goto err_release;
2126 }
2127
2128 /* Data from ucode file: header followed by uCode images */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002129 ucode = (struct iwl_ucode_header *)ucode_raw->data;
Zhu Yib481de92007-09-25 17:54:57 -07002130
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08002131 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08002132 api_ver = IWL_UCODE_API(priv->ucode_ver);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002133 inst_size = priv->cfg->ops->ucode->get_inst_size(ucode, api_ver);
2134 data_size = priv->cfg->ops->ucode->get_data_size(ucode, api_ver);
2135 init_size = priv->cfg->ops->ucode->get_init_size(ucode, api_ver);
2136 init_data_size =
2137 priv->cfg->ops->ucode->get_init_data_size(ucode, api_ver);
2138 boot_size = priv->cfg->ops->ucode->get_boot_size(ucode, api_ver);
2139 src = priv->cfg->ops->ucode->get_data(ucode, api_ver);
Zhu Yib481de92007-09-25 17:54:57 -07002140
Reinette Chatrea0987a82008-12-02 12:14:06 -08002141 /* api_ver should match the api version forming part of the
2142 * firmware filename ... but we don't check for that and only rely
Nick Andrew877d0312009-01-26 11:06:57 +01002143 * on the API version read from firmware header from here on forward */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002144
2145 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002146 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002147 "Driver supports v%u, firmware is v%u.\n",
2148 api_max, api_ver);
2149 priv->ucode_ver = 0;
2150 ret = -EINVAL;
2151 goto err_release;
2152 }
2153 if (api_ver != api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002154 IWL_ERR(priv, "Firmware has old API version. Expected %u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002155 "got %u. New firmware can be obtained "
2156 "from http://www.intellinuxwireless.org.\n",
2157 api_max, api_ver);
2158
Tomas Winkler978785a2008-12-19 10:37:31 +08002159 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
2160 IWL_UCODE_MAJOR(priv->ucode_ver),
2161 IWL_UCODE_MINOR(priv->ucode_ver),
2162 IWL_UCODE_API(priv->ucode_ver),
2163 IWL_UCODE_SERIAL(priv->ucode_ver));
2164
Tomas Winklere1623442009-01-27 14:27:56 -08002165 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002166 priv->ucode_ver);
Tomas Winklere1623442009-01-27 14:27:56 -08002167 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
2168 inst_size);
2169 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
2170 data_size);
2171 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
2172 init_size);
2173 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
2174 init_data_size);
2175 IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
2176 boot_size);
Zhu Yib481de92007-09-25 17:54:57 -07002177
Reinette Chatrea0987a82008-12-02 12:14:06 -08002178
Zhu Yib481de92007-09-25 17:54:57 -07002179 /* Verify size of file vs. image size info in file's header */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002180 if (ucode_raw->size != priv->cfg->ops->ucode->get_header_size(api_ver) +
Zhu Yib481de92007-09-25 17:54:57 -07002181 inst_size + data_size + init_size +
2182 init_data_size + boot_size) {
2183
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002184 IWL_DEBUG_INFO(priv,
2185 "uCode file size %zd does not match expected size\n",
2186 ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002187 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002188 goto err_release;
2189 }
2190
2191 /* Verify that uCode images will fit in card's SRAM */
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002192 if (inst_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002193 IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002194 inst_size);
2195 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002196 goto err_release;
2197 }
2198
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002199 if (data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002200 IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002201 data_size);
2202 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002203 goto err_release;
2204 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002205 if (init_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002206 IWL_DEBUG_INFO(priv,
2207 "uCode init instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002208 init_size);
2209 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002210 goto err_release;
2211 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002212 if (init_data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002213 IWL_DEBUG_INFO(priv,
2214 "uCode init data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002215 init_data_size);
2216 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002217 goto err_release;
2218 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002219 if (boot_size > IWL39_MAX_BSM_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002220 IWL_DEBUG_INFO(priv,
2221 "uCode boot instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002222 boot_size);
2223 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002224 goto err_release;
2225 }
2226
2227 /* Allocate ucode buffers for card's bus-master loading ... */
2228
2229 /* Runtime instructions and 2 copies of data:
2230 * 1) unmodified from disk
2231 * 2) backup cache for save/restore during power-downs */
2232 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002233 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07002234
2235 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002236 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07002237
2238 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002239 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07002240
2241 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
Tomas Winkler90e759d2007-11-29 11:09:41 +08002242 !priv->ucode_data_backup.v_addr)
Zhu Yib481de92007-09-25 17:54:57 -07002243 goto err_pci_alloc;
2244
Tomas Winkler90e759d2007-11-29 11:09:41 +08002245 /* Initialization instructions and data */
2246 if (init_size && init_data_size) {
2247 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002248 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002249
2250 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002251 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002252
2253 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
2254 goto err_pci_alloc;
2255 }
2256
2257 /* Bootstrap (instructions only, no data) */
2258 if (boot_size) {
2259 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002260 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002261
2262 if (!priv->ucode_boot.v_addr)
2263 goto err_pci_alloc;
2264 }
2265
Zhu Yib481de92007-09-25 17:54:57 -07002266 /* Copy images into buffers for card's bus-master reads ... */
2267
2268 /* Runtime instructions (first block of data in file) */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002269 len = inst_size;
Tomas Winklere1623442009-01-27 14:27:56 -08002270 IWL_DEBUG_INFO(priv,
2271 "Copying (but not loading) uCode instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002272 memcpy(priv->ucode_code.v_addr, src, len);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002273 src += len;
2274
Tomas Winklere1623442009-01-27 14:27:56 -08002275 IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002276 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
2277
2278 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002279 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002280 len = data_size;
Tomas Winklere1623442009-01-27 14:27:56 -08002281 IWL_DEBUG_INFO(priv,
2282 "Copying (but not loading) uCode data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002283 memcpy(priv->ucode_data.v_addr, src, len);
2284 memcpy(priv->ucode_data_backup.v_addr, src, len);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002285 src += len;
Zhu Yib481de92007-09-25 17:54:57 -07002286
2287 /* Initialization instructions (3rd block) */
2288 if (init_size) {
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002289 len = init_size;
Tomas Winklere1623442009-01-27 14:27:56 -08002290 IWL_DEBUG_INFO(priv,
2291 "Copying (but not loading) init instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002292 memcpy(priv->ucode_init.v_addr, src, len);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002293 src += len;
Zhu Yib481de92007-09-25 17:54:57 -07002294 }
2295
2296 /* Initialization data (4th block) */
2297 if (init_data_size) {
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002298 len = init_data_size;
Tomas Winklere1623442009-01-27 14:27:56 -08002299 IWL_DEBUG_INFO(priv,
2300 "Copying (but not loading) init data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002301 memcpy(priv->ucode_init_data.v_addr, src, len);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002302 src += len;
Zhu Yib481de92007-09-25 17:54:57 -07002303 }
2304
2305 /* Bootstrap instructions (5th block) */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002306 len = boot_size;
Tomas Winklere1623442009-01-27 14:27:56 -08002307 IWL_DEBUG_INFO(priv,
2308 "Copying (but not loading) boot instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002309 memcpy(priv->ucode_boot.v_addr, src, len);
2310
2311 /* We have our copies now, allow OS release its copies */
2312 release_firmware(ucode_raw);
2313 return 0;
2314
2315 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08002316 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002317 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002318 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002319
2320 err_release:
2321 release_firmware(ucode_raw);
2322
2323 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08002324 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002325}
2326
2327
2328/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002329 * iwl3945_set_ucode_ptrs - Set uCode address location
Zhu Yib481de92007-09-25 17:54:57 -07002330 *
2331 * Tell initialization uCode where to find runtime uCode.
2332 *
2333 * BSM registers initially contain pointers to initialization uCode.
2334 * We need to replace them to load runtime uCode inst and data,
2335 * and to save runtime data when powering down.
2336 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002337static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002338{
2339 dma_addr_t pinst;
2340 dma_addr_t pdata;
Zhu Yib481de92007-09-25 17:54:57 -07002341
2342 /* bits 31:0 for 3945 */
2343 pinst = priv->ucode_code.p_addr;
2344 pdata = priv->ucode_data_backup.p_addr;
2345
Zhu Yib481de92007-09-25 17:54:57 -07002346 /* Tell bootstrap uCode where to find image to load */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002347 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
2348 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
2349 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002350 priv->ucode_data.len);
2351
Tomas Winklera96a27f2008-10-23 23:48:56 -07002352 /* Inst byte count must be last to set up, bit 31 signals uCode
Zhu Yib481de92007-09-25 17:54:57 -07002353 * that all new ptr/size info is in place */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002354 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002355 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
2356
Tomas Winklere1623442009-01-27 14:27:56 -08002357 IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002358
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07002359 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002360}
2361
2362/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002363 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002364 *
2365 * Called after REPLY_ALIVE notification received from "initialize" uCode.
2366 *
Zhu Yib481de92007-09-25 17:54:57 -07002367 * Tell "initialize" uCode to go ahead and load the runtime uCode.
Ben Cahill9fbab512007-11-29 11:09:47 +08002368 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002369static void iwl3945_init_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002370{
2371 /* Check alive response for "valid" sign from uCode */
2372 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
2373 /* We had an error bringing up the hardware, so take it
2374 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002375 IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002376 goto restart;
2377 }
2378
2379 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
2380 * This is a paranoid check, because we would not have gotten the
2381 * "initialize" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002382 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002383 /* Runtime instruction load was bad;
2384 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002385 IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002386 goto restart;
2387 }
2388
2389 /* Send pointers to protocol/runtime uCode image ... init code will
2390 * load and launch runtime uCode, which will send us another "Alive"
2391 * notification. */
Tomas Winklere1623442009-01-27 14:27:56 -08002392 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002393 if (iwl3945_set_ucode_ptrs(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002394 /* Runtime instruction load won't happen;
2395 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002396 IWL_DEBUG_INFO(priv, "Couldn't set up uCode pointers.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002397 goto restart;
2398 }
2399 return;
2400
2401 restart:
2402 queue_work(priv->workqueue, &priv->restart);
2403}
2404
Zhu Yib481de92007-09-25 17:54:57 -07002405/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002406 * iwl3945_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002407 * from protocol/runtime uCode (initialization uCode's
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002408 * Alive gets handled by iwl3945_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07002409 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002410static void iwl3945_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002411{
Zhu Yib481de92007-09-25 17:54:57 -07002412 int thermal_spin = 0;
2413 u32 rfkill;
2414
Tomas Winklere1623442009-01-27 14:27:56 -08002415 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002416
2417 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
2418 /* We had an error bringing up the hardware, so take it
2419 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002420 IWL_DEBUG_INFO(priv, "Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002421 goto restart;
2422 }
2423
2424 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
2425 * This is a paranoid check, because we would not have gotten the
2426 * "runtime" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002427 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002428 /* Runtime instruction load was bad;
2429 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002430 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002431 goto restart;
2432 }
2433
Tomas Winklerc587de02009-06-03 11:44:07 -07002434 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002435
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002436 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
Tomas Winklere1623442009-01-27 14:27:56 -08002437 IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill);
Zhu Yib481de92007-09-25 17:54:57 -07002438
2439 if (rfkill & 0x1) {
2440 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Tomas Winklera96a27f2008-10-23 23:48:56 -07002441 /* if RFKILL is not on, then wait for thermal
Zhu Yib481de92007-09-25 17:54:57 -07002442 * sensor in adapter to kick in */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002443 while (iwl3945_hw_get_temperature(priv) == 0) {
Zhu Yib481de92007-09-25 17:54:57 -07002444 thermal_spin++;
2445 udelay(10);
2446 }
2447
2448 if (thermal_spin)
Tomas Winklere1623442009-01-27 14:27:56 -08002449 IWL_DEBUG_INFO(priv, "Thermal calibration took %dus\n",
Zhu Yib481de92007-09-25 17:54:57 -07002450 thermal_spin * 10);
2451 } else
2452 set_bit(STATUS_RF_KILL_HW, &priv->status);
2453
Ben Cahill9fbab512007-11-29 11:09:47 +08002454 /* After the ALIVE response, we can send commands to 3945 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07002455 set_bit(STATUS_ALIVE, &priv->status);
2456
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08002457 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002458 return;
2459
Johannes Berg36d68252008-05-15 12:55:26 +02002460 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07002461
2462 priv->active_rate = priv->rates_mask;
2463 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
2464
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08002465 iwl_power_update_mode(priv, false);
Zhu Yib481de92007-09-25 17:54:57 -07002466
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002467 if (iwl_is_associated(priv)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002468 struct iwl3945_rxon_cmd *active_rxon =
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002469 (struct iwl3945_rxon_cmd *)(&priv->active_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07002470
Abhijeet Kolekar8a9b9922009-06-12 13:22:52 -07002471 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07002472 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2473 } else {
2474 /* Initialize our rx_config data */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002475 iwl_connection_init_rx_config(priv, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002476 }
2477
Ben Cahill9fbab512007-11-29 11:09:47 +08002478 /* Configure Bluetooth device coexistence support */
Samuel Ortiz17f841c2009-01-23 13:45:20 -08002479 iwl_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002480
2481 /* Configure the adapter for unassociated operation */
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002482 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002483
Zhu Yib481de92007-09-25 17:54:57 -07002484 iwl3945_reg_txpower_periodic(priv);
2485
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07002486 iwl3945_led_register(priv);
2487
Tomas Winklere1623442009-01-27 14:27:56 -08002488 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07002489 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002490 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07002491
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08002492 /* reassociate for ADHOC mode */
2493 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
2494 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
2495 priv->vif);
2496 if (beacon)
Abhijeet Kolekar9944b932009-04-08 11:26:36 -07002497 iwl_mac_beacon_update(priv->hw, beacon);
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08002498 }
2499
Abhijeet Kolekarf45c2712009-04-08 11:26:38 -07002500 if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
Abhijeet Kolekar727882d2009-04-08 11:26:45 -07002501 iwl_set_mode(priv, priv->iw_mode);
Abhijeet Kolekarf45c2712009-04-08 11:26:38 -07002502
Zhu Yib481de92007-09-25 17:54:57 -07002503 return;
2504
2505 restart:
2506 queue_work(priv->workqueue, &priv->restart);
2507}
2508
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002509static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07002510
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002511static void __iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002512{
2513 unsigned long flags;
2514 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
2515 struct ieee80211_conf *conf = NULL;
2516
Tomas Winklere1623442009-01-27 14:27:56 -08002517 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -07002518
2519 conf = ieee80211_get_hw_conf(priv->hw);
2520
2521 if (!exit_pending)
2522 set_bit(STATUS_EXIT_PENDING, &priv->status);
2523
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07002524 iwl3945_led_unregister(priv);
Tomas Winklerc587de02009-06-03 11:44:07 -07002525 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002526
2527 /* Unblock any waiting calls */
2528 wake_up_interruptible_all(&priv->wait_command_queue);
2529
Zhu Yib481de92007-09-25 17:54:57 -07002530 /* Wipe out the EXIT_PENDING status bit if we are not actually
2531 * exiting the module */
2532 if (!exit_pending)
2533 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2534
2535 /* stop and reset the on-board processor */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002536 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07002537
2538 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002539 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002540 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002541 spin_unlock_irqrestore(&priv->lock, flags);
2542 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002543
2544 if (priv->mac80211_registered)
2545 ieee80211_stop_queues(priv->hw);
2546
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002547 /* If we have not previously called iwl3945_init() then
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07002548 * clear all bits but the RF Kill bits and return */
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08002549 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002550 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2551 STATUS_RF_KILL_HW |
Reinette Chatre97888642008-02-06 11:20:38 -08002552 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2553 STATUS_GEO_CONFIGURED |
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08002554 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2555 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002556 goto exit;
2557 }
2558
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07002559 /* ...otherwise clear out all the status bits but the RF Kill
Johannes Berga60e77e2009-06-04 18:26:06 +02002560 * bit and continue taking the NIC down. */
Zhu Yib481de92007-09-25 17:54:57 -07002561 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2562 STATUS_RF_KILL_HW |
Reinette Chatre97888642008-02-06 11:20:38 -08002563 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2564 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002565 test_bit(STATUS_FW_ERROR, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08002566 STATUS_FW_ERROR |
2567 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2568 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002569
Abbas, Mohamede9414b62009-01-20 21:33:55 -08002570 priv->cfg->ops->lib->apm_ops.reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002571 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002572 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07002573 spin_unlock_irqrestore(&priv->lock, flags);
2574
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002575 iwl3945_hw_txq_ctx_stop(priv);
2576 iwl3945_hw_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002577
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07002578 iwl_write_prph(priv, APMG_CLK_DIS_REG,
2579 APMG_CLK_VAL_DMA_CLK_RQT);
Zhu Yib481de92007-09-25 17:54:57 -07002580
2581 udelay(5);
2582
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07002583 if (exit_pending)
Abbas, Mohamede9414b62009-01-20 21:33:55 -08002584 priv->cfg->ops->lib->apm_ops.stop(priv);
2585 else
2586 priv->cfg->ops->lib->apm_ops.reset(priv);
2587
Zhu Yib481de92007-09-25 17:54:57 -07002588 exit:
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002589 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07002590
2591 if (priv->ibss_beacon)
2592 dev_kfree_skb(priv->ibss_beacon);
2593 priv->ibss_beacon = NULL;
2594
2595 /* clear out any free frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002596 iwl3945_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002597}
2598
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002599static void iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002600{
2601 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002602 __iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002603 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08002604
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002605 iwl3945_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002606}
2607
2608#define MAX_HW_RESTARTS 5
2609
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002610static int __iwl3945_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002611{
2612 int rc, i;
2613
2614 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002615 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07002616 return -EIO;
2617 }
2618
Reinette Chatree903fbd2008-01-30 22:05:15 -08002619 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002620 IWL_ERR(priv, "ucode not available for device bring up\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08002621 return -EIO;
2622 }
2623
Zhu Yie655b9f2008-01-24 02:19:38 -08002624 /* If platform's RF_KILL switch is NOT set to KILL */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002625 if (iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yie655b9f2008-01-24 02:19:38 -08002626 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
2627 clear_bit(STATUS_RF_KILL_HW, &priv->status);
2628 else {
2629 set_bit(STATUS_RF_KILL_HW, &priv->status);
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07002630 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
2631 return -ENODEV;
Zhu Yib481de92007-09-25 17:54:57 -07002632 }
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02002633
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002634 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07002635
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002636 rc = iwl3945_hw_nic_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002637 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002638 IWL_ERR(priv, "Unable to int nic\n");
Zhu Yib481de92007-09-25 17:54:57 -07002639 return rc;
2640 }
2641
2642 /* make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002643 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2644 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07002645 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
2646
2647 /* clear (again), then enable host interrupts */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002648 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002649 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002650
2651 /* really make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002652 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2653 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07002654
2655 /* Copy original ucode data image from disk into backup cache.
2656 * This will be used to initialize the on-board processor's
2657 * data SRAM for a clean start when the runtime program first loads. */
2658 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a66926a2008-01-14 17:46:18 -08002659 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07002660
Zhu Yie655b9f2008-01-24 02:19:38 -08002661 /* We return success when we resume from suspend and rf_kill is on. */
2662 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
2663 return 0;
2664
Zhu Yib481de92007-09-25 17:54:57 -07002665 for (i = 0; i < MAX_HW_RESTARTS; i++) {
2666
Tomas Winklerc587de02009-06-03 11:44:07 -07002667 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002668
2669 /* load bootstrap state machine,
2670 * load bootstrap program into processor's memory,
2671 * prepare to load the "initialize" uCode */
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002672 priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002673
2674 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002675 IWL_ERR(priv,
2676 "Unable to set up bootstrap uCode: %d\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -07002677 continue;
2678 }
2679
2680 /* start card; "initialize" will load runtime ucode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002681 iwl3945_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002682
Tomas Winklere1623442009-01-27 14:27:56 -08002683 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
Zhu Yib481de92007-09-25 17:54:57 -07002684
2685 return 0;
2686 }
2687
2688 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002689 __iwl3945_down(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08002690 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002691
2692 /* tried to restart and config the device for as long as our
2693 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002694 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07002695 return -EIO;
2696}
2697
2698
2699/*****************************************************************************
2700 *
2701 * Workqueue callbacks
2702 *
2703 *****************************************************************************/
2704
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002705static void iwl3945_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002706{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002707 struct iwl_priv *priv =
2708 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002709
2710 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2711 return;
2712
2713 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002714 iwl3945_init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002715 mutex_unlock(&priv->mutex);
2716}
2717
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002718static void iwl3945_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002719{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002720 struct iwl_priv *priv =
2721 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002722
2723 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2724 return;
2725
2726 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002727 iwl3945_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002728 mutex_unlock(&priv->mutex);
2729}
2730
Helmut Schaa26635162009-01-15 09:38:44 +01002731static void iwl3945_rfkill_poll(struct work_struct *data)
2732{
2733 struct iwl_priv *priv =
2734 container_of(data, struct iwl_priv, rfkill_poll.work);
Helmut Schaa26635162009-01-15 09:38:44 +01002735
2736 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
2737 clear_bit(STATUS_RF_KILL_HW, &priv->status);
2738 else
2739 set_bit(STATUS_RF_KILL_HW, &priv->status);
2740
Johannes Berga60e77e2009-06-04 18:26:06 +02002741 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
2742 test_bit(STATUS_RF_KILL_HW, &priv->status));
Helmut Schaa26635162009-01-15 09:38:44 +01002743
2744 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
2745 round_jiffies_relative(2 * HZ));
2746
2747}
2748
Zhu Yib481de92007-09-25 17:54:57 -07002749#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002750static void iwl3945_bg_request_scan(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002751{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002752 struct iwl_priv *priv =
2753 container_of(data, struct iwl_priv, request_scan);
Winkler, Tomasc2d79b482008-12-19 10:37:34 +08002754 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07002755 .id = REPLY_SCAN_CMD,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002756 .len = sizeof(struct iwl3945_scan_cmd),
Johannes Bergc2acea82009-07-24 11:13:05 -07002757 .flags = CMD_SIZE_HUGE,
Zhu Yib481de92007-09-25 17:54:57 -07002758 };
2759 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002760 struct iwl3945_scan_cmd *scan;
Zhu Yib481de92007-09-25 17:54:57 -07002761 struct ieee80211_conf *conf = NULL;
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07002762 u8 n_probes = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01002763 enum ieee80211_band band;
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07002764 bool is_active = false;
Zhu Yib481de92007-09-25 17:54:57 -07002765
2766 conf = ieee80211_get_hw_conf(priv->hw);
2767
2768 mutex_lock(&priv->mutex);
2769
Reinette Chatrefbc9f972009-05-15 16:13:46 -07002770 cancel_delayed_work(&priv->scan_check);
2771
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08002772 if (!iwl_is_ready(priv)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002773 IWL_WARN(priv, "request scan called when driver not ready.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002774 goto done;
2775 }
2776
Tomas Winklera96a27f2008-10-23 23:48:56 -07002777 /* Make sure the scan wasn't canceled before this queued work
Zhu Yib481de92007-09-25 17:54:57 -07002778 * was given the chance to run... */
2779 if (!test_bit(STATUS_SCANNING, &priv->status))
2780 goto done;
2781
2782 /* This should never be called or scheduled if there is currently
2783 * a scan active in the hardware. */
2784 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002785 IWL_DEBUG_INFO(priv, "Multiple concurrent scan requests "
2786 "Ignoring second request.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002787 rc = -EIO;
2788 goto done;
2789 }
2790
2791 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002792 IWL_DEBUG_SCAN(priv, "Aborting scan due to device shutdown\n");
Zhu Yib481de92007-09-25 17:54:57 -07002793 goto done;
2794 }
2795
2796 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002797 IWL_DEBUG_HC(priv,
2798 "Scan request while abort pending. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002799 goto done;
2800 }
2801
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08002802 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002803 IWL_DEBUG_HC(priv, "Aborting scan due to RF Kill activation\n");
Zhu Yib481de92007-09-25 17:54:57 -07002804 goto done;
2805 }
2806
2807 if (!test_bit(STATUS_READY, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002808 IWL_DEBUG_HC(priv,
2809 "Scan request while uninitialized. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002810 goto done;
2811 }
2812
2813 if (!priv->scan_bands) {
Tomas Winklere1623442009-01-27 14:27:56 -08002814 IWL_DEBUG_HC(priv, "Aborting scan due to no requested bands\n");
Zhu Yib481de92007-09-25 17:54:57 -07002815 goto done;
2816 }
2817
Winkler, Tomas805cee52009-01-19 15:30:28 -08002818 if (!priv->scan) {
2819 priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
Zhu Yib481de92007-09-25 17:54:57 -07002820 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
Winkler, Tomas805cee52009-01-19 15:30:28 -08002821 if (!priv->scan) {
Zhu Yib481de92007-09-25 17:54:57 -07002822 rc = -ENOMEM;
2823 goto done;
2824 }
2825 }
Winkler, Tomas805cee52009-01-19 15:30:28 -08002826 scan = priv->scan;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002827 memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07002828
2829 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
2830 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
2831
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002832 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002833 u16 interval = 0;
2834 u32 extra;
2835 u32 suspend_time = 100;
2836 u32 scan_suspend_time = 100;
2837 unsigned long flags;
2838
Tomas Winklere1623442009-01-27 14:27:56 -08002839 IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
Zhu Yib481de92007-09-25 17:54:57 -07002840
2841 spin_lock_irqsave(&priv->lock, flags);
2842 interval = priv->beacon_int;
2843 spin_unlock_irqrestore(&priv->lock, flags);
2844
2845 scan->suspend_time = 0;
Mohamed Abbas15e869d2007-10-25 17:15:46 +08002846 scan->max_out_time = cpu_to_le32(200 * 1024);
Zhu Yib481de92007-09-25 17:54:57 -07002847 if (!interval)
2848 interval = suspend_time;
2849 /*
2850 * suspend time format:
2851 * 0-19: beacon interval in usec (time before exec.)
2852 * 20-23: 0
2853 * 24-31: number of beacons (suspend between channels)
2854 */
2855
2856 extra = (suspend_time / interval) << 24;
2857 scan_suspend_time = 0xFF0FFFFF &
2858 (extra | ((suspend_time % interval) * 1024));
2859
2860 scan->suspend_time = cpu_to_le32(scan_suspend_time);
Tomas Winklere1623442009-01-27 14:27:56 -08002861 IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07002862 scan_suspend_time, interval);
2863 }
2864
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07002865 if (priv->scan_request->n_ssids) {
2866 int i, p = 0;
2867 IWL_DEBUG_SCAN(priv, "Kicking off active scan\n");
2868 for (i = 0; i < priv->scan_request->n_ssids; i++) {
2869 /* always does wildcard anyway */
2870 if (!priv->scan_request->ssids[i].ssid_len)
2871 continue;
2872 scan->direct_scan[p].id = WLAN_EID_SSID;
2873 scan->direct_scan[p].len =
2874 priv->scan_request->ssids[i].ssid_len;
2875 memcpy(scan->direct_scan[p].ssid,
2876 priv->scan_request->ssids[i].ssid,
2877 priv->scan_request->ssids[i].ssid_len);
2878 n_probes++;
2879 p++;
2880 }
2881 is_active = true;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08002882 } else
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07002883 IWL_DEBUG_SCAN(priv, "Kicking off passive scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002884
2885 /* We don't build a direct scan probe request; the uCode will do
2886 * that based on the direct_mask added to each channel entry */
Zhu Yib481de92007-09-25 17:54:57 -07002887 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08002888 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07002889 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
2890
2891 /* flags + rate selection */
2892
Ron Rindjunsky66b50042008-06-25 16:46:31 +08002893 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07002894 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
2895 scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
2896 scan->good_CRC_th = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01002897 band = IEEE80211_BAND_2GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08002898 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07002899 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
Johannes Bergb097ad22009-04-20 14:36:57 -07002900 /*
2901 * If active scaning is requested but a certain channel
2902 * is marked passive, we can do active scanning if we
2903 * detect transmissions.
2904 */
2905 scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH : 0;
Johannes Berg8318d782008-01-24 19:38:38 +01002906 band = IEEE80211_BAND_5GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08002907 } else {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002908 IWL_WARN(priv, "Invalid scan band count\n");
Zhu Yib481de92007-09-25 17:54:57 -07002909 goto done;
2910 }
2911
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08002912 scan->tx_cmd.len = cpu_to_le16(
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07002913 iwl_fill_probe_req(priv,
2914 (struct ieee80211_mgmt *)scan->data,
2915 priv->scan_request->ie,
2916 priv->scan_request->ie_len,
2917 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08002918
Zhu Yib481de92007-09-25 17:54:57 -07002919 /* select Rx antennas */
2920 scan->flags |= iwl3945_get_antenna_flags(priv);
2921
Wey-Yi Guy279b05d2009-04-20 14:37:00 -07002922 if (iwl_is_monitor_mode(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002923 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
2924
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08002925 scan->channel_count =
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07002926 iwl3945_get_channels_for_scan(priv, band, is_active, n_probes,
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08002927 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
Zhu Yib481de92007-09-25 17:54:57 -07002928
Reinette Chatre14b54332008-11-04 12:21:35 -08002929 if (scan->channel_count == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002930 IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
Reinette Chatre14b54332008-11-04 12:21:35 -08002931 goto done;
2932 }
2933
Zhu Yib481de92007-09-25 17:54:57 -07002934 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002935 scan->channel_count * sizeof(struct iwl3945_scan_channel);
Zhu Yib481de92007-09-25 17:54:57 -07002936 cmd.data = scan;
2937 scan->len = cpu_to_le16(cmd.len);
2938
2939 set_bit(STATUS_SCAN_HW, &priv->status);
Samuel Ortiz518099a2009-01-19 15:30:27 -08002940 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07002941 if (rc)
2942 goto done;
2943
2944 queue_delayed_work(priv->workqueue, &priv->scan_check,
2945 IWL_SCAN_CHECK_WATCHDOG);
2946
2947 mutex_unlock(&priv->mutex);
2948 return;
2949
2950 done:
Mohamed Abbas2420ebc2008-11-04 12:21:34 -08002951 /* can not perform scan make sure we clear scanning
2952 * bits from status so next scan request can be performed.
2953 * if we dont clear scanning status bit here all next scan
2954 * will fail
2955 */
2956 clear_bit(STATUS_SCAN_HW, &priv->status);
2957 clear_bit(STATUS_SCANNING, &priv->status);
2958
Ian Schram01ebd062007-10-25 17:15:22 +08002959 /* inform mac80211 scan aborted */
Zhu Yib481de92007-09-25 17:54:57 -07002960 queue_work(priv->workqueue, &priv->scan_completed);
2961 mutex_unlock(&priv->mutex);
2962}
2963
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002964static void iwl3945_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002965{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002966 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07002967
2968 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2969 return;
2970
2971 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002972 __iwl3945_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002973 mutex_unlock(&priv->mutex);
2974}
2975
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002976static void iwl3945_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002977{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002978 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07002979
2980 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2981 return;
2982
Johannes Berg19cc1082009-05-08 13:44:36 -07002983 if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
2984 mutex_lock(&priv->mutex);
2985 priv->vif = NULL;
2986 priv->is_open = 0;
2987 mutex_unlock(&priv->mutex);
2988 iwl3945_down(priv);
2989 ieee80211_restart_hw(priv->hw);
2990 } else {
2991 iwl3945_down(priv);
2992 queue_work(priv->workqueue, &priv->up);
2993 }
Zhu Yib481de92007-09-25 17:54:57 -07002994}
2995
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002996static void iwl3945_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002997{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002998 struct iwl_priv *priv =
2999 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07003000
3001 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3002 return;
3003
3004 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003005 iwl3945_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003006 mutex_unlock(&priv->mutex);
3007}
3008
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003009#define IWL_DELAY_NEXT_SCAN (HZ*2)
3010
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07003011void iwl3945_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003012{
Zhu Yib481de92007-09-25 17:54:57 -07003013 int rc = 0;
3014 struct ieee80211_conf *conf = NULL;
3015
Johannes Berg05c914f2008-09-11 00:01:58 +02003016 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003017 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07003018 return;
3019 }
3020
3021
Tomas Winklere1623442009-01-27 14:27:56 -08003022 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003023 priv->assoc_id, priv->active_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07003024
3025 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3026 return;
3027
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003028 if (!priv->vif || !priv->is_open)
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003029 return;
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003030
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003031 iwl_scan_cancel_timeout(priv, 200);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003032
Zhu Yib481de92007-09-25 17:54:57 -07003033 conf = ieee80211_get_hw_conf(priv->hw);
3034
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003035 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003036 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003037
Tomas Winkler28afaf92008-12-19 10:37:06 +08003038 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Tomas Winkler2c2f3b32009-06-19 13:52:45 -07003039 iwl_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003040 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07003041 sizeof(priv->rxon_timing), &priv->rxon_timing);
3042 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003043 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003044 "Attempting to continue.\n");
3045
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003046 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003047
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003048 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003049
Tomas Winklere1623442009-01-27 14:27:56 -08003050 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003051 priv->assoc_id, priv->beacon_int);
3052
3053 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003054 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003055 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003056 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003057
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003058 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07003059 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003060 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003061 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003062 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003063
Johannes Berg05c914f2008-09-11 00:01:58 +02003064 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003065 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003066
3067 }
3068
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003069 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003070
3071 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02003072 case NL80211_IFTYPE_STATION:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003073 iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07003074 break;
3075
Johannes Berg05c914f2008-09-11 00:01:58 +02003076 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07003077
Abhijeet Kolekarce546fd2008-11-19 15:32:22 -08003078 priv->assoc_id = 1;
Tomas Winklerc587de02009-06-03 11:44:07 -07003079 iwl_add_station(priv, priv->bssid, 0, CMD_SYNC, NULL);
Zhu Yib481de92007-09-25 17:54:57 -07003080 iwl3945_sync_sta(priv, IWL_STA_ID,
Johannes Berg8318d782008-01-24 19:38:38 +01003081 (priv->band == IEEE80211_BAND_5GHZ) ?
Zhu Yib481de92007-09-25 17:54:57 -07003082 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
3083 CMD_ASYNC);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003084 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
3085 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003086
3087 break;
3088
3089 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08003090 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003091 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07003092 break;
3093 }
3094
Abhijeet Kolekar14d2aac2009-02-27 16:21:24 -08003095 iwl_activate_qos(priv, 0);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08003096
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003097 /* we have just associated, don't start scan too early */
3098 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08003099}
3100
Zhu Yib481de92007-09-25 17:54:57 -07003101/*****************************************************************************
3102 *
3103 * mac80211 entry point functions
3104 *
3105 *****************************************************************************/
3106
Zhu Yi5a66926a2008-01-14 17:46:18 -08003107#define UCODE_READY_TIMEOUT (2 * HZ)
3108
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003109static int iwl3945_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003110{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003111 struct iwl_priv *priv = hw->priv;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003112 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003113
Tomas Winklere1623442009-01-27 14:27:56 -08003114 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003115
3116 /* we should be verifying the device is ready to be opened */
3117 mutex_lock(&priv->mutex);
3118
Zhu Yi5a66926a2008-01-14 17:46:18 -08003119 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
3120 * ucode filename and max sizes are card-specific. */
3121
3122 if (!priv->ucode_code.len) {
3123 ret = iwl3945_read_ucode(priv);
3124 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003125 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003126 mutex_unlock(&priv->mutex);
3127 goto out_release_irq;
3128 }
3129 }
3130
Zhu Yie655b9f2008-01-24 02:19:38 -08003131 ret = __iwl3945_up(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003132
Zhu Yib481de92007-09-25 17:54:57 -07003133 mutex_unlock(&priv->mutex);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003134
Zhu Yie655b9f2008-01-24 02:19:38 -08003135 if (ret)
3136 goto out_release_irq;
3137
Tomas Winklere1623442009-01-27 14:27:56 -08003138 IWL_DEBUG_INFO(priv, "Start UP work.\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003139
Zhu Yi5a66926a2008-01-14 17:46:18 -08003140 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
3141 * mac80211 will not be run successfully. */
3142 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
3143 test_bit(STATUS_READY, &priv->status),
3144 UCODE_READY_TIMEOUT);
3145 if (!ret) {
3146 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003147 IWL_ERR(priv,
3148 "Wait for START_ALIVE timeout after %dms.\n",
3149 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Zhu Yi5a66926a2008-01-14 17:46:18 -08003150 ret = -ETIMEDOUT;
3151 goto out_release_irq;
3152 }
3153 }
3154
Helmut Schaa26635162009-01-15 09:38:44 +01003155 /* ucode is running and will send rfkill notifications,
3156 * no need to poll the killswitch state anymore */
3157 cancel_delayed_work(&priv->rfkill_poll);
3158
Zhu Yie655b9f2008-01-24 02:19:38 -08003159 priv->is_open = 1;
Tomas Winklere1623442009-01-27 14:27:56 -08003160 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003161 return 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003162
3163out_release_irq:
Zhu Yie655b9f2008-01-24 02:19:38 -08003164 priv->is_open = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08003165 IWL_DEBUG_MAC80211(priv, "leave - failed\n");
Zhu Yi5a66926a2008-01-14 17:46:18 -08003166 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003167}
3168
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003169static void iwl3945_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003170{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003171 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003172
Tomas Winklere1623442009-01-27 14:27:56 -08003173 IWL_DEBUG_MAC80211(priv, "enter\n");
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003174
Zhu Yie655b9f2008-01-24 02:19:38 -08003175 if (!priv->is_open) {
Tomas Winklere1623442009-01-27 14:27:56 -08003176 IWL_DEBUG_MAC80211(priv, "leave - skip\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003177 return;
3178 }
3179
Zhu Yib481de92007-09-25 17:54:57 -07003180 priv->is_open = 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003181
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003182 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08003183 /* stop mac, cancel any scan request and clear
3184 * RXON_FILTER_ASSOC_MSK BIT
3185 */
Zhu Yi5a66926a2008-01-14 17:46:18 -08003186 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003187 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003188 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003189 }
3190
Zhu Yi5a66926a2008-01-14 17:46:18 -08003191 iwl3945_down(priv);
3192
3193 flush_workqueue(priv->workqueue);
Helmut Schaa26635162009-01-15 09:38:44 +01003194
3195 /* start polling the killswitch state again */
3196 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3197 round_jiffies_relative(2 * HZ));
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003198
Tomas Winklere1623442009-01-27 14:27:56 -08003199 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003200}
3201
Johannes Berge039fa42008-05-15 12:55:29 +02003202static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07003203{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003204 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003205
Tomas Winklere1623442009-01-27 14:27:56 -08003206 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003207
Tomas Winklere1623442009-01-27 14:27:56 -08003208 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02003209 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07003210
Johannes Berge039fa42008-05-15 12:55:29 +02003211 if (iwl3945_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07003212 dev_kfree_skb_any(skb);
3213
Tomas Winklere1623442009-01-27 14:27:56 -08003214 IWL_DEBUG_MAC80211(priv, "leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08003215 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07003216}
3217
Abhijeet Kolekar60690a62009-04-08 11:26:49 -07003218void iwl3945_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003219{
3220 int rc = 0;
3221
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08003222 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07003223 return;
3224
3225 /* The following should be done only at AP bring up */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003226 if (!(iwl_is_associated(priv))) {
Zhu Yib481de92007-09-25 17:54:57 -07003227
3228 /* RXON - unassoc (to set timing command) */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003229 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003230 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003231
3232 /* RXON Timing */
Tomas Winkler28afaf92008-12-19 10:37:06 +08003233 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Tomas Winkler2c2f3b32009-06-19 13:52:45 -07003234 iwl_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003235 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
3236 sizeof(priv->rxon_timing),
3237 &priv->rxon_timing);
Zhu Yib481de92007-09-25 17:54:57 -07003238 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003239 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003240 "Attempting to continue.\n");
3241
3242 /* FIXME: what should be the assoc_id for AP? */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003243 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003244 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003245 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07003246 RXON_FLG_SHORT_PREAMBLE_MSK;
3247 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003248 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003249 ~RXON_FLG_SHORT_PREAMBLE_MSK;
3250
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003251 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07003252 if (priv->assoc_capability &
3253 WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003254 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07003255 RXON_FLG_SHORT_SLOT_MSK;
3256 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003257 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003258 ~RXON_FLG_SHORT_SLOT_MSK;
3259
Johannes Berg05c914f2008-09-11 00:01:58 +02003260 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003261 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003262 ~RXON_FLG_SHORT_SLOT_MSK;
3263 }
3264 /* restore RXON assoc */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003265 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003266 iwlcore_commit_rxon(priv);
Tomas Winklerc587de02009-06-03 11:44:07 -07003267 iwl_add_station(priv, iwl_bcast_addr, 0, CMD_SYNC, NULL);
Zhu Yi556f8db2007-09-27 11:27:33 +08003268 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003269 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003270
3271 /* FIXME - we need to add code here to detect a totally new
3272 * configuration, reset the AP, unassoc, rxon timing, assoc,
3273 * clear sta table, add BCAST sta... */
3274}
3275
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003276static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01003277 struct ieee80211_vif *vif,
3278 struct ieee80211_sta *sta,
3279 struct ieee80211_key_conf *key)
Zhu Yib481de92007-09-25 17:54:57 -07003280{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003281 struct iwl_priv *priv = hw->priv;
Johannes Bergdc822b52008-12-29 12:55:09 +01003282 const u8 *addr;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003283 int ret = 0;
3284 u8 sta_id = IWL_INVALID_STATION;
3285 u8 static_key;
Zhu Yib481de92007-09-25 17:54:57 -07003286
Tomas Winklere1623442009-01-27 14:27:56 -08003287 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003288
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08003289 if (iwl3945_mod_params.sw_crypto) {
Tomas Winklere1623442009-01-27 14:27:56 -08003290 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
Zhu Yib481de92007-09-25 17:54:57 -07003291 return -EOPNOTSUPP;
3292 }
3293
Winkler, Tomas42986792009-01-19 15:30:22 -08003294 addr = sta ? sta->addr : iwl_bcast_addr;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003295 static_key = !iwl_is_associated(priv);
3296
3297 if (!static_key) {
Tomas Winklerc587de02009-06-03 11:44:07 -07003298 sta_id = iwl_find_station(priv, addr);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003299 if (sta_id == IWL_INVALID_STATION) {
Joe Perches12514392009-04-16 16:23:26 -07003300 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003301 addr);
3302 return -EINVAL;
3303 }
Zhu Yib481de92007-09-25 17:54:57 -07003304 }
3305
3306 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003307 iwl_scan_cancel_timeout(priv, 100);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003308 mutex_unlock(&priv->mutex);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003309
Zhu Yib481de92007-09-25 17:54:57 -07003310 switch (cmd) {
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003311 case SET_KEY:
3312 if (static_key)
3313 ret = iwl3945_set_static_key(priv, key);
3314 else
3315 ret = iwl3945_set_dynamic_key(priv, key, sta_id);
3316 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003317 break;
3318 case DISABLE_KEY:
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003319 if (static_key)
3320 ret = iwl3945_remove_static_key(priv);
3321 else
3322 ret = iwl3945_clear_sta_key_info(priv, sta_id);
3323 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003324 break;
3325 default:
Winkler, Tomas42986792009-01-19 15:30:22 -08003326 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003327 }
3328
Tomas Winklere1623442009-01-27 14:27:56 -08003329 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003330
Winkler, Tomas42986792009-01-19 15:30:22 -08003331 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003332}
3333
Zhu Yib481de92007-09-25 17:54:57 -07003334/*****************************************************************************
3335 *
3336 * sysfs attributes
3337 *
3338 *****************************************************************************/
3339
Samuel Ortizd08853a2009-01-23 13:45:17 -08003340#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07003341
3342/*
3343 * The following adds a new attribute to the sysfs representation
3344 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
3345 * used for controlling the debug level.
3346 *
3347 * See the level definitions in iwl for details.
Reinette Chatrea562a9d2009-07-17 09:30:24 -07003348 *
Reinette Chatre3d816c72009-08-07 15:41:37 -07003349 * The debug_level being managed using sysfs below is a per device debug
3350 * level that is used instead of the global debug level if it (the per
3351 * device debug level) is set.
Zhu Yib481de92007-09-25 17:54:57 -07003352 */
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003353static ssize_t show_debug_level(struct device *d,
3354 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07003355{
Reinette Chatre3d816c72009-08-07 15:41:37 -07003356 struct iwl_priv *priv = dev_get_drvdata(d);
3357 return sprintf(buf, "0x%08X\n", iwl_get_debug_level(priv));
Zhu Yib481de92007-09-25 17:54:57 -07003358}
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003359static ssize_t store_debug_level(struct device *d,
3360 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07003361 const char *buf, size_t count)
3362{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003363 struct iwl_priv *priv = dev_get_drvdata(d);
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003364 unsigned long val;
3365 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003366
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003367 ret = strict_strtoul(buf, 0, &val);
3368 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08003369 IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003370 else {
Reinette Chatre3d816c72009-08-07 15:41:37 -07003371 priv->debug_level = val;
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003372 if (iwl_alloc_traffic_mem(priv))
3373 IWL_ERR(priv,
3374 "Not enough memory to generate traffic log\n");
3375 }
Zhu Yib481de92007-09-25 17:54:57 -07003376 return strnlen(buf, count);
3377}
3378
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003379static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
3380 show_debug_level, store_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07003381
Samuel Ortizd08853a2009-01-23 13:45:17 -08003382#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07003383
Zhu Yib481de92007-09-25 17:54:57 -07003384static ssize_t show_temperature(struct device *d,
3385 struct device_attribute *attr, char *buf)
3386{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003387 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003388
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003389 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003390 return -EAGAIN;
3391
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003392 return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
Zhu Yib481de92007-09-25 17:54:57 -07003393}
3394
3395static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
3396
Zhu Yib481de92007-09-25 17:54:57 -07003397static ssize_t show_tx_power(struct device *d,
3398 struct device_attribute *attr, char *buf)
3399{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003400 struct iwl_priv *priv = dev_get_drvdata(d);
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08003401 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07003402}
3403
3404static ssize_t store_tx_power(struct device *d,
3405 struct device_attribute *attr,
3406 const char *buf, size_t count)
3407{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003408 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003409 char *p = (char *)buf;
3410 u32 val;
3411
3412 val = simple_strtoul(p, &p, 10);
3413 if (p == buf)
Tomas Winkler978785a2008-12-19 10:37:31 +08003414 IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07003415 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003416 iwl3945_hw_reg_set_txpower(priv, val);
Zhu Yib481de92007-09-25 17:54:57 -07003417
3418 return count;
3419}
3420
3421static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
3422
3423static ssize_t show_flags(struct device *d,
3424 struct device_attribute *attr, char *buf)
3425{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003426 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003427
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003428 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
Zhu Yib481de92007-09-25 17:54:57 -07003429}
3430
3431static ssize_t store_flags(struct device *d,
3432 struct device_attribute *attr,
3433 const char *buf, size_t count)
3434{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003435 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003436 u32 flags = simple_strtoul(buf, NULL, 0);
3437
3438 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003439 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
Zhu Yib481de92007-09-25 17:54:57 -07003440 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003441 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003442 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003443 else {
Tomas Winklere1623442009-01-27 14:27:56 -08003444 IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n",
Zhu Yib481de92007-09-25 17:54:57 -07003445 flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003446 priv->staging_rxon.flags = cpu_to_le32(flags);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003447 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003448 }
3449 }
3450 mutex_unlock(&priv->mutex);
3451
3452 return count;
3453}
3454
3455static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
3456
3457static ssize_t show_filter_flags(struct device *d,
3458 struct device_attribute *attr, char *buf)
3459{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003460 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003461
3462 return sprintf(buf, "0x%04X\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003463 le32_to_cpu(priv->active_rxon.filter_flags));
Zhu Yib481de92007-09-25 17:54:57 -07003464}
3465
3466static ssize_t store_filter_flags(struct device *d,
3467 struct device_attribute *attr,
3468 const char *buf, size_t count)
3469{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003470 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003471 u32 filter_flags = simple_strtoul(buf, NULL, 0);
3472
3473 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003474 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
Zhu Yib481de92007-09-25 17:54:57 -07003475 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003476 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003477 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003478 else {
Tomas Winklere1623442009-01-27 14:27:56 -08003479 IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
Zhu Yib481de92007-09-25 17:54:57 -07003480 "0x%04X\n", filter_flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003481 priv->staging_rxon.filter_flags =
Zhu Yib481de92007-09-25 17:54:57 -07003482 cpu_to_le32(filter_flags);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003483 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003484 }
3485 }
3486 mutex_unlock(&priv->mutex);
3487
3488 return count;
3489}
3490
3491static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
3492 store_filter_flags);
3493
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003494#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07003495
3496static ssize_t show_measurement(struct device *d,
3497 struct device_attribute *attr, char *buf)
3498{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003499 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler600c0e12008-12-19 10:37:04 +08003500 struct iwl_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07003501 u32 size = sizeof(measure_report), len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003502 u8 *data = (u8 *)&measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07003503 unsigned long flags;
3504
3505 spin_lock_irqsave(&priv->lock, flags);
3506 if (!(priv->measurement_status & MEASUREMENT_READY)) {
3507 spin_unlock_irqrestore(&priv->lock, flags);
3508 return 0;
3509 }
3510 memcpy(&measure_report, &priv->measure_report, size);
3511 priv->measurement_status = 0;
3512 spin_unlock_irqrestore(&priv->lock, flags);
3513
3514 while (size && (PAGE_SIZE - len)) {
3515 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
3516 PAGE_SIZE - len, 1);
3517 len = strlen(buf);
3518 if (PAGE_SIZE - len)
3519 buf[len++] = '\n';
3520
3521 ofs += 16;
3522 size -= min(size, 16U);
3523 }
3524
3525 return len;
3526}
3527
3528static ssize_t store_measurement(struct device *d,
3529 struct device_attribute *attr,
3530 const char *buf, size_t count)
3531{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003532 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003533 struct ieee80211_measurement_params params = {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003534 .channel = le16_to_cpu(priv->active_rxon.channel),
Zhu Yib481de92007-09-25 17:54:57 -07003535 .start_time = cpu_to_le64(priv->last_tsf),
3536 .duration = cpu_to_le16(1),
3537 };
3538 u8 type = IWL_MEASURE_BASIC;
3539 u8 buffer[32];
3540 u8 channel;
3541
3542 if (count) {
3543 char *p = buffer;
3544 strncpy(buffer, buf, min(sizeof(buffer), count));
3545 channel = simple_strtoul(p, NULL, 0);
3546 if (channel)
3547 params.channel = channel;
3548
3549 p = buffer;
3550 while (*p && *p != ' ')
3551 p++;
3552 if (*p)
3553 type = simple_strtoul(p + 1, NULL, 0);
3554 }
3555
Tomas Winklere1623442009-01-27 14:27:56 -08003556 IWL_DEBUG_INFO(priv, "Invoking measurement of type %d on "
Zhu Yib481de92007-09-25 17:54:57 -07003557 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003558 iwl3945_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07003559
3560 return count;
3561}
3562
3563static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
3564 show_measurement, store_measurement);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003565#endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07003566
Zhu Yib481de92007-09-25 17:54:57 -07003567static ssize_t store_retry_rate(struct device *d,
3568 struct device_attribute *attr,
3569 const char *buf, size_t count)
3570{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003571 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003572
3573 priv->retry_rate = simple_strtoul(buf, NULL, 0);
3574 if (priv->retry_rate <= 0)
3575 priv->retry_rate = 1;
3576
3577 return count;
3578}
3579
3580static ssize_t show_retry_rate(struct device *d,
3581 struct device_attribute *attr, char *buf)
3582{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003583 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003584 return sprintf(buf, "%d", priv->retry_rate);
3585}
3586
3587static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
3588 store_retry_rate);
3589
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08003590
Zhu Yib481de92007-09-25 17:54:57 -07003591static ssize_t show_channels(struct device *d,
3592 struct device_attribute *attr, char *buf)
3593{
Johannes Berg8318d782008-01-24 19:38:38 +01003594 /* all this shit doesn't belong into sysfs anyway */
3595 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07003596}
3597
3598static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
3599
3600static ssize_t show_statistics(struct device *d,
3601 struct device_attribute *attr, char *buf)
3602{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003603 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003604 u32 size = sizeof(struct iwl3945_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07003605 u32 len = 0, ofs = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08003606 u8 *data = (u8 *)&priv->statistics_39;
Zhu Yib481de92007-09-25 17:54:57 -07003607 int rc = 0;
3608
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003609 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003610 return -EAGAIN;
3611
3612 mutex_lock(&priv->mutex);
Samuel Ortiz17f841c2009-01-23 13:45:20 -08003613 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003614 mutex_unlock(&priv->mutex);
3615
3616 if (rc) {
3617 len = sprintf(buf,
3618 "Error sending statistics request: 0x%08X\n", rc);
3619 return len;
3620 }
3621
3622 while (size && (PAGE_SIZE - len)) {
3623 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
3624 PAGE_SIZE - len, 1);
3625 len = strlen(buf);
3626 if (PAGE_SIZE - len)
3627 buf[len++] = '\n';
3628
3629 ofs += 16;
3630 size -= min(size, 16U);
3631 }
3632
3633 return len;
3634}
3635
3636static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
3637
3638static ssize_t show_antenna(struct device *d,
3639 struct device_attribute *attr, char *buf)
3640{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003641 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003642
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003643 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003644 return -EAGAIN;
3645
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08003646 return sprintf(buf, "%d\n", iwl3945_mod_params.antenna);
Zhu Yib481de92007-09-25 17:54:57 -07003647}
3648
3649static ssize_t store_antenna(struct device *d,
3650 struct device_attribute *attr,
3651 const char *buf, size_t count)
3652{
Winkler, Tomas7530f852009-01-27 14:27:53 -08003653 struct iwl_priv *priv __maybe_unused = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003654 int ant;
Zhu Yib481de92007-09-25 17:54:57 -07003655
3656 if (count == 0)
3657 return 0;
3658
3659 if (sscanf(buf, "%1i", &ant) != 1) {
Tomas Winklere1623442009-01-27 14:27:56 -08003660 IWL_DEBUG_INFO(priv, "not in hex or decimal form.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003661 return count;
3662 }
3663
3664 if ((ant >= 0) && (ant <= 2)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003665 IWL_DEBUG_INFO(priv, "Setting antenna select to %d.\n", ant);
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08003666 iwl3945_mod_params.antenna = (enum iwl3945_antenna)ant;
Zhu Yib481de92007-09-25 17:54:57 -07003667 } else
Tomas Winklere1623442009-01-27 14:27:56 -08003668 IWL_DEBUG_INFO(priv, "Bad antenna select value %d.\n", ant);
Zhu Yib481de92007-09-25 17:54:57 -07003669
3670
3671 return count;
3672}
3673
3674static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
3675
3676static ssize_t show_status(struct device *d,
3677 struct device_attribute *attr, char *buf)
3678{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003679 struct iwl_priv *priv = dev_get_drvdata(d);
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003680 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003681 return -EAGAIN;
3682 return sprintf(buf, "0x%08x\n", (int)priv->status);
3683}
3684
3685static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
3686
3687static ssize_t dump_error_log(struct device *d,
3688 struct device_attribute *attr,
3689 const char *buf, size_t count)
3690{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003691 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003692 char *p = (char *)buf;
3693
3694 if (p[0] == '1')
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003695 iwl3945_dump_nic_error_log(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003696
3697 return strnlen(buf, count);
3698}
3699
3700static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
3701
Zhu Yib481de92007-09-25 17:54:57 -07003702/*****************************************************************************
3703 *
Tomas Winklera96a27f2008-10-23 23:48:56 -07003704 * driver setup and tear down
Zhu Yib481de92007-09-25 17:54:57 -07003705 *
3706 *****************************************************************************/
3707
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003708static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003709{
Reinette Chatred21050c2009-02-13 11:51:18 -08003710 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
Zhu Yib481de92007-09-25 17:54:57 -07003711
3712 init_waitqueue_head(&priv->wait_command_queue);
3713
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003714 INIT_WORK(&priv->up, iwl3945_bg_up);
3715 INIT_WORK(&priv->restart, iwl3945_bg_restart);
3716 INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003717 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003718 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
3719 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
Helmut Schaa26635162009-01-15 09:38:44 +01003720 INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll);
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08003721 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
3722 INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
3723 INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
3724 INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
Zhu Yib481de92007-09-25 17:54:57 -07003725
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003726 iwl3945_hw_setup_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003727
3728 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003729 iwl3945_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07003730}
3731
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003732static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003733{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003734 iwl3945_hw_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003735
Joonwoo Parke47eb6a2007-11-29 10:42:49 +09003736 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07003737 cancel_delayed_work(&priv->scan_check);
3738 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07003739 cancel_work_sync(&priv->beacon_update);
3740}
3741
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003742static struct attribute *iwl3945_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07003743 &dev_attr_antenna.attr,
3744 &dev_attr_channels.attr,
3745 &dev_attr_dump_errors.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003746 &dev_attr_flags.attr,
3747 &dev_attr_filter_flags.attr,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003748#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07003749 &dev_attr_measurement.attr,
3750#endif
Zhu Yib481de92007-09-25 17:54:57 -07003751 &dev_attr_retry_rate.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003752 &dev_attr_statistics.attr,
3753 &dev_attr_status.attr,
3754 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003755 &dev_attr_tx_power.attr,
Samuel Ortizd08853a2009-01-23 13:45:17 -08003756#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003757 &dev_attr_debug_level.attr,
3758#endif
Zhu Yib481de92007-09-25 17:54:57 -07003759 NULL
3760};
3761
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003762static struct attribute_group iwl3945_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07003763 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003764 .attrs = iwl3945_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07003765};
3766
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003767static struct ieee80211_ops iwl3945_hw_ops = {
3768 .tx = iwl3945_mac_tx,
3769 .start = iwl3945_mac_start,
3770 .stop = iwl3945_mac_stop,
Abhijeet Kolekarcbb6ab92009-04-08 11:26:46 -07003771 .add_interface = iwl_mac_add_interface,
Abhijeet Kolekard8052312009-04-08 11:26:47 -07003772 .remove_interface = iwl_mac_remove_interface,
Abhijeet Kolekar48083682009-04-08 11:26:48 -07003773 .config = iwl_mac_config,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003774 .configure_filter = iwl_configure_filter,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003775 .set_key = iwl3945_mac_set_key,
Abhijeet Kolekaraa89f312009-04-08 11:26:51 -07003776 .get_tx_stats = iwl_mac_get_tx_stats,
Abhijeet Kolekar488829f2009-03-26 10:14:10 -07003777 .conf_tx = iwl_mac_conf_tx,
Abhijeet Kolekarbd564262009-04-08 11:26:52 -07003778 .reset_tsf = iwl_mac_reset_tsf,
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07003779 .bss_info_changed = iwl_bss_info_changed,
Abhijeet Kolekare9dde6f62009-02-18 15:54:27 -08003780 .hw_scan = iwl_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07003781};
3782
Winkler, Tomase52119c2008-12-22 11:31:19 +08003783static int iwl3945_init_drv(struct iwl_priv *priv)
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003784{
3785 int ret;
Samuel Ortize6148912009-01-23 13:45:15 -08003786 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003787
3788 priv->retry_rate = 1;
3789 priv->ibss_beacon = NULL;
3790
3791 spin_lock_init(&priv->lock);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003792 spin_lock_init(&priv->sta_lock);
3793 spin_lock_init(&priv->hcmd_lock);
3794
3795 INIT_LIST_HEAD(&priv->free_frames);
3796
3797 mutex_init(&priv->mutex);
3798
3799 /* Clear the driver's (not device's) station table */
Tomas Winklerc587de02009-06-03 11:44:07 -07003800 iwl_clear_stations_table(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003801
3802 priv->data_retry_limit = -1;
3803 priv->ieee_channels = NULL;
3804 priv->ieee_rates = NULL;
3805 priv->band = IEEE80211_BAND_2GHZ;
3806
3807 priv->iw_mode = NL80211_IFTYPE_STATION;
3808
3809 iwl_reset_qos(priv);
3810
3811 priv->qos_data.qos_active = 0;
3812 priv->qos_data.qos_cap.val = 0;
3813
3814 priv->rates_mask = IWL_RATES_MASK;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08003815 priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003816
Samuel Ortize6148912009-01-23 13:45:15 -08003817 if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
3818 IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
3819 eeprom->version);
3820 ret = -EINVAL;
3821 goto err;
3822 }
3823 ret = iwl_init_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003824 if (ret) {
3825 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
3826 goto err;
3827 }
3828
Samuel Ortize6148912009-01-23 13:45:15 -08003829 /* Set up txpower settings in driver for all channels */
3830 if (iwl3945_txpower_set_from_eeprom(priv)) {
3831 ret = -EIO;
3832 goto err_free_channel_map;
3833 }
3834
Samuel Ortiz534166d2009-01-23 13:45:16 -08003835 ret = iwlcore_init_geos(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003836 if (ret) {
3837 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
3838 goto err_free_channel_map;
3839 }
Samuel Ortiz534166d2009-01-23 13:45:16 -08003840 iwl3945_init_hw_rates(priv, priv->ieee_rates);
3841
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003842 return 0;
3843
3844err_free_channel_map:
Samuel Ortize6148912009-01-23 13:45:15 -08003845 iwl_free_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003846err:
3847 return ret;
3848}
3849
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08003850static int iwl3945_setup_mac(struct iwl_priv *priv)
3851{
3852 int ret;
3853 struct ieee80211_hw *hw = priv->hw;
3854
3855 hw->rate_control_algorithm = "iwl-3945-rs";
3856 hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
3857
3858 /* Tell mac80211 our characteristics */
3859 hw->flags = IEEE80211_HW_SIGNAL_DBM |
Mohamed Abbasb1c60192009-03-17 21:51:47 -07003860 IEEE80211_HW_NOISE_DBM |
Johannes Berge312c242009-08-07 15:41:51 -07003861 IEEE80211_HW_SPECTRUM_MGMT |
3862 IEEE80211_HW_SUPPORTS_PS |
3863 IEEE80211_HW_SUPPORTS_DYNAMIC_PS;
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08003864
3865 hw->wiphy->interface_modes =
3866 BIT(NL80211_IFTYPE_STATION) |
3867 BIT(NL80211_IFTYPE_ADHOC);
3868
3869 hw->wiphy->custom_regulatory = true;
3870
Luis R. Rodriguez37184242009-07-30 17:43:48 -07003871 /* Firmware does not support this */
3872 hw->wiphy->disable_beacon_hints = true;
3873
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07003874 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX_3945;
3875 /* we create the 802.11 header and a zero-length SSID element */
3876 hw->wiphy->max_scan_ie_len = IWL_MAX_PROBE_REQUEST - 24 - 2;
Johannes Bergd60cc912009-04-09 09:56:02 +02003877
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08003878 /* Default value; 4 EDCA QOS priorities */
3879 hw->queues = 4;
3880
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08003881 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
3882 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
3883 &priv->bands[IEEE80211_BAND_2GHZ];
3884
3885 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
3886 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
3887 &priv->bands[IEEE80211_BAND_5GHZ];
3888
3889 ret = ieee80211_register_hw(priv->hw);
3890 if (ret) {
3891 IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
3892 return ret;
3893 }
3894 priv->mac80211_registered = 1;
3895
3896 return 0;
3897}
3898
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003899static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07003900{
3901 int err = 0;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003902 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07003903 struct ieee80211_hw *hw;
Kolekar, Abhijeetc0f20d92008-12-19 10:37:19 +08003904 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Samuel Ortize6148912009-01-23 13:45:15 -08003905 struct iwl3945_eeprom *eeprom;
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003906 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07003907
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08003908 /***********************
3909 * 1. Allocating HW data
3910 * ********************/
3911
Zhu Yib481de92007-09-25 17:54:57 -07003912 /* mac80211 allocates memory for this device instance, including
3913 * space for this driver's private structure */
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003914 hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
Zhu Yib481de92007-09-25 17:54:57 -07003915 if (hw == NULL) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08003916 printk(KERN_ERR DRV_NAME "Can not allocate network device\n");
Zhu Yib481de92007-09-25 17:54:57 -07003917 err = -ENOMEM;
3918 goto out;
3919 }
Zhu Yib481de92007-09-25 17:54:57 -07003920 priv = hw->priv;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003921 SET_IEEE80211_DEV(hw, &pdev->dev);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003922
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003923 /*
3924 * Disabling hardware scan means that mac80211 will perform scans
3925 * "the hard way", rather than using device's scan.
3926 */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08003927 if (iwl3945_mod_params.disable_hw_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08003928 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003929 iwl3945_hw_ops.hw_scan = NULL;
3930 }
3931
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003932
Tomas Winklere1623442009-01-27 14:27:56 -08003933 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003934 priv->cfg = cfg;
3935 priv->pci_dev = pdev;
Mohamed Abbas40cefda2009-05-22 11:01:52 -07003936 priv->inta_mask = CSR_INI_SET_MASK;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003937
Samuel Ortizd08853a2009-01-23 13:45:17 -08003938#ifdef CONFIG_IWLWIFI_DEBUG
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003939 atomic_set(&priv->restrict_refcnt, 0);
3940#endif
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003941 if (iwl_alloc_traffic_mem(priv))
3942 IWL_ERR(priv, "Not enough memory to generate traffic log\n");
Zhu Yib481de92007-09-25 17:54:57 -07003943
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08003944 /***************************
3945 * 2. Initializing PCI bus
3946 * *************************/
Zhu Yib481de92007-09-25 17:54:57 -07003947 if (pci_enable_device(pdev)) {
3948 err = -ENODEV;
3949 goto out_ieee80211_free_hw;
3950 }
3951
3952 pci_set_master(pdev);
3953
Yang Hongyang284901a2009-04-06 19:01:15 -07003954 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Zhu Yib481de92007-09-25 17:54:57 -07003955 if (!err)
Yang Hongyang284901a2009-04-06 19:01:15 -07003956 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Zhu Yib481de92007-09-25 17:54:57 -07003957 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08003958 IWL_WARN(priv, "No suitable DMA available.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003959 goto out_pci_disable_device;
3960 }
3961
3962 pci_set_drvdata(pdev, priv);
3963 err = pci_request_regions(pdev, DRV_NAME);
3964 if (err)
3965 goto out_pci_disable_device;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003966
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08003967 /***********************
3968 * 3. Read REV Register
3969 * ********************/
Zhu Yib481de92007-09-25 17:54:57 -07003970 priv->hw_base = pci_iomap(pdev, 0, 0);
3971 if (!priv->hw_base) {
3972 err = -ENODEV;
3973 goto out_pci_release_regions;
3974 }
3975
Tomas Winklere1623442009-01-27 14:27:56 -08003976 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
Zhu Yib481de92007-09-25 17:54:57 -07003977 (unsigned long long) pci_resource_len(pdev, 0));
Tomas Winklere1623442009-01-27 14:27:56 -08003978 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
Zhu Yib481de92007-09-25 17:54:57 -07003979
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08003980 /* We disable the RETRY_TIMEOUT register (0x41) to keep
3981 * PCI Tx retries from interfering with C3 CPU state */
3982 pci_write_config_byte(pdev, 0x41, 0x00);
Zhu Yib481de92007-09-25 17:54:57 -07003983
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07003984 /* this spin lock will be used in apm_ops.init and EEPROM access
3985 * we should init now
3986 */
3987 spin_lock_init(&priv->reg_lock);
3988
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003989 /* amp init */
3990 err = priv->cfg->ops->lib->apm_ops.init(priv);
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003991 if (err < 0) {
David S. Millerd5df2a12009-03-10 05:04:16 -07003992 IWL_DEBUG_INFO(priv, "Failed to init the card\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003993 goto out_iounmap;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003994 }
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08003995
3996 /***********************
3997 * 4. Read EEPROM
3998 * ********************/
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003999
Zhu Yi5a66926a2008-01-14 17:46:18 -08004000 /* Read the EEPROM */
Samuel Ortize6148912009-01-23 13:45:15 -08004001 err = iwl_eeprom_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004002 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004003 IWL_ERR(priv, "Unable to init EEPROM\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08004004 goto out_iounmap;
Zhu Yi5a66926a2008-01-14 17:46:18 -08004005 }
4006 /* MAC Address location in EEPROM same for 3945/4965 */
Samuel Ortize6148912009-01-23 13:45:15 -08004007 eeprom = (struct iwl3945_eeprom *)priv->eeprom;
4008 memcpy(priv->mac_addr, eeprom->mac_address, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08004009 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr);
Zhu Yi5a66926a2008-01-14 17:46:18 -08004010 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
4011
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004012 /***********************
4013 * 5. Setup HW Constants
4014 * ********************/
4015 /* Device-specific setup */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08004016 if (iwl3945_hw_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004017 IWL_ERR(priv, "failed to set hw settings\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08004018 goto out_eeprom_free;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004019 }
4020
4021 /***********************
4022 * 6. Setup priv
4023 * ********************/
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004024
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004025 err = iwl3945_init_drv(priv);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08004026 if (err) {
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004027 IWL_ERR(priv, "initializing driver failed\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08004028 goto out_unset_hw_params;
Reinette Chatre849e0dc2008-01-23 10:15:18 -08004029 }
Reinette Chatre849e0dc2008-01-23 10:15:18 -08004030
Tomas Winkler978785a2008-12-19 10:37:31 +08004031 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
4032 priv->cfg->name);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004033
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004034 /***********************
Abhijeet Kolekar09f9bf72009-04-20 14:37:03 -07004035 * 7. Setup Services
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004036 * ********************/
4037
4038 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08004039 iwl_disable_interrupts(priv);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004040 spin_unlock_irqrestore(&priv->lock, flags);
4041
Helmut Schaa26635162009-01-15 09:38:44 +01004042 pci_enable_msi(priv->pci_dev);
4043
Mohamed Abbasef850d72009-05-22 11:01:50 -07004044 err = request_irq(priv->pci_dev->irq, priv->cfg->ops->lib->isr,
4045 IRQF_SHARED, DRV_NAME, priv);
Helmut Schaa26635162009-01-15 09:38:44 +01004046 if (err) {
4047 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
4048 goto out_disable_msi;
4049 }
4050
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004051 err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
4052 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004053 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004054 goto out_release_irq;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004055 }
4056
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004057 iwl_set_rxon_channel(priv,
4058 &priv->bands[IEEE80211_BAND_2GHZ].channels[5]);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004059 iwl3945_setup_deferred_work(priv);
4060 iwl3945_setup_rx_handlers(priv);
4061
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004062 /*********************************
Abhijeet Kolekar09f9bf72009-04-20 14:37:03 -07004063 * 8. Setup and Register mac80211
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004064 * *******************************/
4065
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004066 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004067
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004068 err = iwl3945_setup_mac(priv);
4069 if (err)
4070 goto out_remove_sysfs;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004071
Abhijeet Kolekara75fbe82009-04-20 14:36:58 -07004072 err = iwl_dbgfs_register(priv, DRV_NAME);
4073 if (err)
4074 IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
4075
Helmut Schaa26635162009-01-15 09:38:44 +01004076 /* Start monitoring the killswitch */
4077 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
4078 2 * HZ);
4079
Zhu Yib481de92007-09-25 17:54:57 -07004080 return 0;
4081
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004082 out_remove_sysfs:
Zhu Yib481de92007-09-25 17:54:57 -07004083 destroy_workqueue(priv->workqueue);
4084 priv->workqueue = NULL;
Reinette Chatrec8f16132009-02-27 16:21:22 -08004085 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
4086 out_release_irq:
4087 free_irq(priv->pci_dev->irq, priv);
Helmut Schaa26635162009-01-15 09:38:44 +01004088 out_disable_msi:
4089 pci_disable_msi(priv->pci_dev);
Reinette Chatrec8f16132009-02-27 16:21:22 -08004090 iwlcore_free_geos(priv);
4091 iwl_free_channel_map(priv);
4092 out_unset_hw_params:
4093 iwl3945_unset_hw_params(priv);
4094 out_eeprom_free:
4095 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004096 out_iounmap:
4097 pci_iounmap(pdev, priv->hw_base);
4098 out_pci_release_regions:
4099 pci_release_regions(pdev);
4100 out_pci_disable_device:
Zhu Yib481de92007-09-25 17:54:57 -07004101 pci_set_drvdata(pdev, NULL);
Reinette Chatre623d5632009-03-03 11:37:04 -08004102 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004103 out_ieee80211_free_hw:
4104 ieee80211_free_hw(priv->hw);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07004105 iwl_free_traffic_mem(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004106 out:
4107 return err;
4108}
4109
Reinette Chatrec83dbf62008-03-21 13:53:41 -07004110static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07004111{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004112 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004113 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07004114
4115 if (!priv)
4116 return;
4117
Tomas Winklere1623442009-01-27 14:27:56 -08004118 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07004119
Abhijeet Kolekara75fbe82009-04-20 14:36:58 -07004120 iwl_dbgfs_unregister(priv);
4121
Zhu Yib481de92007-09-25 17:54:57 -07004122 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08004123
Kolekar, Abhijeetd552bfb2008-12-19 10:37:41 +08004124 if (priv->mac80211_registered) {
4125 ieee80211_unregister_hw(priv->hw);
4126 priv->mac80211_registered = 0;
4127 } else {
4128 iwl3945_down(priv);
4129 }
Zhu Yib481de92007-09-25 17:54:57 -07004130
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004131 /* make sure we flush any pending irq or
4132 * tasklet for the driver
4133 */
4134 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08004135 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004136 spin_unlock_irqrestore(&priv->lock, flags);
4137
4138 iwl_synchronize_irq(priv);
4139
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004140 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07004141
Reinette Chatre71d449b2009-04-20 14:37:01 -07004142 cancel_delayed_work_sync(&priv->rfkill_poll);
Helmut Schaa26635162009-01-15 09:38:44 +01004143
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004144 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004145
4146 if (priv->rxq.bd)
Reinette Chatredf833b12009-04-21 10:55:48 -07004147 iwl3945_rx_queue_free(priv, &priv->rxq);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004148 iwl3945_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004149
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08004150 iwl3945_unset_hw_params(priv);
Tomas Winklerc587de02009-06-03 11:44:07 -07004151 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004152
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004153 /*netif_stop_queue(dev); */
4154 flush_workqueue(priv->workqueue);
4155
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004156 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07004157 * priv->workqueue... so we can't take down the workqueue
4158 * until now... */
4159 destroy_workqueue(priv->workqueue);
4160 priv->workqueue = NULL;
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07004161 iwl_free_traffic_mem(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004162
Helmut Schaa26635162009-01-15 09:38:44 +01004163 free_irq(pdev->irq, priv);
4164 pci_disable_msi(pdev);
4165
Zhu Yib481de92007-09-25 17:54:57 -07004166 pci_iounmap(pdev, priv->hw_base);
4167 pci_release_regions(pdev);
4168 pci_disable_device(pdev);
4169 pci_set_drvdata(pdev, NULL);
4170
Samuel Ortize6148912009-01-23 13:45:15 -08004171 iwl_free_channel_map(priv);
Samuel Ortiz534166d2009-01-23 13:45:16 -08004172 iwlcore_free_geos(priv);
Winkler, Tomas805cee52009-01-19 15:30:28 -08004173 kfree(priv->scan);
Zhu Yib481de92007-09-25 17:54:57 -07004174 if (priv->ibss_beacon)
4175 dev_kfree_skb(priv->ibss_beacon);
4176
4177 ieee80211_free_hw(priv->hw);
4178}
4179
Zhu Yib481de92007-09-25 17:54:57 -07004180
4181/*****************************************************************************
4182 *
4183 * driver and module entry point
4184 *
4185 *****************************************************************************/
4186
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004187static struct pci_driver iwl3945_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07004188 .name = DRV_NAME,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004189 .id_table = iwl3945_hw_card_ids,
4190 .probe = iwl3945_pci_probe,
4191 .remove = __devexit_p(iwl3945_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07004192#ifdef CONFIG_PM
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07004193 .suspend = iwl_pci_suspend,
4194 .resume = iwl_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07004195#endif
4196};
4197
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004198static int __init iwl3945_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07004199{
4200
4201 int ret;
4202 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
4203 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004204
4205 ret = iwl3945_rate_control_register();
4206 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08004207 printk(KERN_ERR DRV_NAME
4208 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004209 return ret;
4210 }
4211
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004212 ret = pci_register_driver(&iwl3945_driver);
Zhu Yib481de92007-09-25 17:54:57 -07004213 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08004214 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004215 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07004216 }
Zhu Yib481de92007-09-25 17:54:57 -07004217
4218 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004219
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004220error_register:
4221 iwl3945_rate_control_unregister();
4222 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004223}
4224
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004225static void __exit iwl3945_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07004226{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004227 pci_unregister_driver(&iwl3945_driver);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004228 iwl3945_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07004229}
4230
Reinette Chatrea0987a82008-12-02 12:14:06 -08004231MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
Zhu Yi25cb6ca2008-09-11 11:45:22 +08004232
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07004233module_param_named(antenna, iwl3945_mod_params.antenna, int, S_IRUGO);
Zhu Yib481de92007-09-25 17:54:57 -07004234MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07004235module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, S_IRUGO);
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -08004236MODULE_PARM_DESC(swcrypto,
4237 "using software crypto (default 1 [software])\n");
Reinette Chatrea562a9d2009-07-17 09:30:24 -07004238#ifdef CONFIG_IWLWIFI_DEBUG
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07004239module_param_named(debug, iwl_debug_level, uint, S_IRUGO | S_IWUSR);
Zhu Yib481de92007-09-25 17:54:57 -07004240MODULE_PARM_DESC(debug, "debug output mask");
Reinette Chatrea562a9d2009-07-17 09:30:24 -07004241#endif
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07004242module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan,
4243 int, S_IRUGO);
Zhu Yib481de92007-09-25 17:54:57 -07004244MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07004245module_param_named(fw_restart3945, iwl3945_mod_params.restart_fw, int, S_IRUGO);
Samuel Ortizaf48d042009-01-23 13:45:19 -08004246MODULE_PARM_DESC(fw_restart3945, "restart firmware in case of error");
4247
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004248module_exit(iwl3945_exit);
4249module_init(iwl3945_init);